Skip to content

feat: rich terminal context, editor enrichment, and multi-window fix#48

Open
kepptic wants to merge 4 commits intoActivityWatch:masterfrom
kepptic:feat/rich-terminal-context
Open

feat: rich terminal context, editor enrichment, and multi-window fix#48
kepptic wants to merge 4 commits intoActivityWatch:masterfrom
kepptic:feat/rich-terminal-context

Conversation

@kepptic
Copy link
Copy Markdown

@kepptic kepptic commented Mar 6, 2026

Summary

Comprehensive enhancement to the VS Code watcher — adds terminal tracking, git enrichment, multi-window safety, and incorporates community PRs #36, #39, #40.

Terminal Context

  • Active terminal name & cwd: Reports the focused terminal's working directory via shellIntegration API with lsof PID-based fallback (for terminals like Claude Code that lack shell integration)
  • Terminal switch detection: Distinguishes same-named terminals using array-index identity
  • All terminal enumeration: Reports all open terminal sessions with resolved project names
  • 500ms timeout on terminal.processId (Thenable) to prevent hung heartbeats

Editor Enrichment

  • Git dirty count & remote URL — per-file repository resolution (not just repositories[0])
  • Cursor position — line and column
  • Debug session tracking — active session type
  • Relative file paths — cleaner than absolute
  • Open editor tabs — filenames and count
  • Window focus state (is_focused)
  • Multi-root workspace folders

Multi-Window Fix

  • Only the focused VS Code window sends heartbeats. Multiple windows share the same bucket — unfocused windows were interleaving different project data, breaking aw-server's pulse merge and producing 0-duration events. One final heartbeat fires on blur to properly close the current event.

Community PRs Merged

New Heartbeat Fields

Field Description
editor Editor app name (VS Code, Cursor, etc.)
workspace Workspace name from .code-workspace
active_terminal Active terminal name
active_terminal_label Terminal name + project directory
terminal_cwd Terminal working directory
terminal_description Project directory name
terminal_names All terminals with project names (; separated)
terminal_count Number of open terminals
git_dirty_count Uncommitted changes count
git_remote Git remote URL (cleaned)
is_debugging / debug_type Active debug session
cursor_line / cursor_col Cursor position
lines_in_file Total lines in file
relative_path File path relative to workspace
open_files / open_file_count Open editor tabs
is_focused Window focus state
workspace_folders Multi-root workspace folder names

Test plan

  • Terminal switches fire heartbeats with correct active terminal
  • PID-based lsof resolves cwd for terminals without shellIntegration
  • Multiple terminals with same name are distinguished by index
  • 500ms timeout prevents hung processId promises
  • All terminal sessions enumerated with project names
  • Git, cursor, debug, and focus data included in heartbeats
  • Only focused window sends heartbeats (multi-window)
  • One final heartbeat on blur to close event properly
  • editor field dynamically detects Cursor/Windsurf/VS Code
  • workspace field populated from .code-workspace name
  • Extension works in untrusted workspaces

Note: We also maintain an enhanced fork at kepptic/aw-watcher-vscode-enhanced with modernized build tooling (TypeScript 5.x, ESLint, updated deps) for users who want these features now.

kepptic and others added 3 commits March 6, 2026 01:49
…ichment

Track active terminal with working directory resolution via lsof fallback
for terminals without shellIntegration (e.g., Claude Code sessions). Detect
terminal switches using array index for terminals sharing the same name.

New event fields: terminal_cwd, terminal_description, active_terminal_label,
terminal_names, terminal_count, git_dirty_count, git_remote, is_debugging,
debug_type, cursor_line, cursor_col, lines_in_file, relative_path,
open_files, open_file_count, is_focused, workspace_folders.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Multiple VS Code windows share the same bucket. Unfocused windows
were interleaving different project data, breaking pulse merge and
causing 0-duration events. Now only the focused window heartbeats;
unfocused windows get one final heartbeat on blur to close the event.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…yWatch#40 + multi-window fix

- PR ActivityWatch#36: workspace name field (workspace.name)
- PR ActivityWatch#39: editor identification (dynamic via env.appName — supports
  Cursor, Windsurf, and other VS Code forks)
- PR ActivityWatch#40: untrusted workspace support (capabilities declaration)
- Fix: only focused window sends heartbeats, preventing interleaved
  project data from breaking pulse merge in multi-window setups

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@kepptic kepptic changed the title feat: rich terminal context and editor enrichment feat: rich terminal context, editor enrichment, and multi-window fix Mar 10, 2026
- Add 5s periodic heartbeat timer so pulse merge builds proper event
  durations (previously only fired on change events, leaving 0s gaps)
- Show project name + "(terminal)" for file field when terminal is
  focused instead of "unknown"; language shows "terminal"

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant