Skip to content

Add SessionReconciler, who-am-i command, and harden worktree creation#3

Merged
mgreau merged 7 commits intomainfrom
mgreau/enhance-dashboard-and-commands
Apr 15, 2026
Merged

Add SessionReconciler, who-am-i command, and harden worktree creation#3
mgreau merged 7 commits intomainfrom
mgreau/enhance-dashboard-and-commands

Conversation

@mgreau
Copy link
Copy Markdown
Owner

@mgreau mgreau commented Mar 13, 2026

Summary

  • SessionReconciler: Background daemon now scans Claude sessions every 10s and writes cached state to ~/.zen/state/sessions.json. Sessions are classified as running, waiting (idle ≥10s, needs user input), or stopped. Dashboard and agent status read from cache — near-instant instead of scanning every worktree.

  • zen who-am-i: New command showing a summary of your work across worktrees for a given time period. Three sections:

    • Merged & Deployed — PRs merged to origin/main by you, with PR numbers
    • In Progress — feature branches with commits or active Claude sessions
    • PR Reviews — review worktrees with commit counts and session indicators
    • --merged flag shows full commit descriptions for merged PRs
    • --period / --repo flags for filtering
    • Also available as zen_who_am_i MCP tool for Claude to query directly
  • Worktree creation hardened:

    • Two-step creation (--no-checkout + separate git checkout) fixes recurring "Could not write new index file" on large repos (13K+ files)
    • CleanupFailedAdd automatically removes orphaned branches and partial worktree directories on failure

New files

  • internal/reconciler/session.goScanSessions() periodic scanner
  • internal/reconciler/session_state.go — State types + snapshot read/write
  • cmd/whoami.gozen who-am-i command

Modified files

  • cmd/watch.go — Wire session ticker into daemon loop
  • cmd/status.go — Read cached sessions, yellow dot for "waiting" state
  • cmd/agent.go — Read cached sessions, show "waiting" status
  • cmd/work.go — Two-step worktree creation + cleanup on failure
  • internal/reconciler/setup.go — Two-step worktree creation + cleanup on failure
  • internal/worktree/lock.goCleanupFailedAdd() helper
  • internal/config/config.goSessionScanInterval config + AllBasePaths()
  • internal/mcp/server.go — Register zen_who_am_i tool
  • internal/mcp/tools.gohandleWhoAmI + handleAgentStatus reads cache
  • README.md — who-am-i docs, session_scan_interval, sessions.json, MCP tool

Test plan

  • go build ./... and go test ./... pass
  • zen watch stop && zen watch startsessions.json appears in ~/.zen/state/
  • zen agent status shows waiting state for idle sessions (yellow)
  • zen status shows yellow dot for waiting sessions
  • zen who-am-i -r mono -p 7d shows merged PRs, in-progress, and reviews
  • zen who-am-i --merged shows full commit descriptions
  • zen work new succeeds on large repos (previously failing with "Could not write new index file")
  • Failed zen work new cleans up orphaned branch automatically

🤖 Generated with Claude Code

mgreau and others added 7 commits April 15, 2026 19:51
…eation

Background daemon now scans sessions every 10s and writes cached state to
~/.zen/state/sessions.json, making dashboard and agent status near-instant.
Sessions are classified as running/waiting/stopped, where "waiting" means
the process is alive but idle ≥10s (needs user input).

Also adds CleanupFailedAdd to recover from partial git worktree add failures
that leave orphaned branches behind, preventing the need for manual cleanup.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…epos

- zen who-am-i: shows merged PRs, in-progress branches, and PR reviews
  for a configurable time period. --merged flag shows full descriptions.
- zen_who_am_i MCP tool: same data available to Claude sessions.
- Fix "Could not write new index file" on large repos by using
  --no-checkout + separate git checkout (two-step worktree creation).
- Update README with who-am-i docs, session_scan_interval config,
  sessions.json state file, and zen_who_am_i MCP tool.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Detect the moment a Claude session goes idle and send a macOS
notification so you know to check back without watching a dashboard.

- Add notify.SessionWaiting(worktreeName, model) using osascript
- Track per-session previous status with sync.Map in ScanSessions
- Detect running → waiting transition on each 10s tick
- Debounce: re-notify same session at most once every 5 minutes
If terminal-notifier is installed, clicking the "Claude is waiting"
notification opens a new terminal tab directly in the worktree.
Falls back to osascript with the resume command in the subtitle.

- Add SendWithAction() with terminal-notifier / osascript fallback
- SessionWaiting now accepts a resumeCmd for the click handler
- Compute resume command: "zen review resume N" or "zen work resume name"
  based on worktree type (TypePRReview vs TypeFeature)
Add a configurable digest ticker that sends a compact macOS notification
summarizing waiting sessions, pending PR reviews, and active feature work.
Silent when everything is quiet.

- notify.Digest(waitingSessions, pendingReviews, featureWork)
- reconciler.SendDigest(cfg) reads sessions.json + lists worktrees
- WatchConfig.DigestInterval + DigestIntervalDuration() getter
- digestTicker in daemon (nil channel = disabled by default)
- Enable with: watch: { digest_interval: "2h" } in ~/.zen/config.yaml
All notifications now use SendWithAction so clicking them does something
useful when terminal-notifier is installed:

- PRReview → zen review resume <number>
- WorktreeReady → zen review resume <number>
- PRMerged → zen cleanup
- StaleWorktrees → zen cleanup

Falls back to osascript with the command in the subtitle when
terminal-notifier is not installed.
WorktreeReady is the most actionable notification — clicking it opens
the worktree for review. All others revert to osascript to reduce noise.
@mgreau mgreau force-pushed the mgreau/enhance-dashboard-and-commands branch from aa7dff0 to 2a1443d Compare April 15, 2026 23:56
@mgreau mgreau merged commit 7c873e3 into main Apr 15, 2026
1 check passed
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