Add SessionReconciler, who-am-i command, and harden worktree creation#3
Merged
Add SessionReconciler, who-am-i command, and harden worktree creation#3
Conversation
…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.
aa7dff0 to
2a1443d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SessionReconciler: Background daemon now scans Claude sessions every 10s and writes cached state to
~/.zen/state/sessions.json. Sessions are classified asrunning,waiting(idle ≥10s, needs user input), orstopped. 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:origin/mainby you, with PR numbers--mergedflag shows full commit descriptions for merged PRs--period/--repoflags for filteringzen_who_am_iMCP tool for Claude to query directlyWorktree creation hardened:
--no-checkout+ separategit checkout) fixes recurring "Could not write new index file" on large repos (13K+ files)CleanupFailedAddautomatically removes orphaned branches and partial worktree directories on failureNew files
internal/reconciler/session.go—ScanSessions()periodic scannerinternal/reconciler/session_state.go— State types + snapshot read/writecmd/whoami.go—zen who-am-icommandModified files
cmd/watch.go— Wire session ticker into daemon loopcmd/status.go— Read cached sessions, yellow dot for "waiting" statecmd/agent.go— Read cached sessions, show "waiting" statuscmd/work.go— Two-step worktree creation + cleanup on failureinternal/reconciler/setup.go— Two-step worktree creation + cleanup on failureinternal/worktree/lock.go—CleanupFailedAdd()helperinternal/config/config.go—SessionScanIntervalconfig +AllBasePaths()internal/mcp/server.go— Registerzen_who_am_itoolinternal/mcp/tools.go—handleWhoAmI+handleAgentStatusreads cacheREADME.md— who-am-i docs, session_scan_interval, sessions.json, MCP toolTest plan
go build ./...andgo test ./...passzen watch stop && zen watch start—sessions.jsonappears in~/.zen/state/zen agent statusshowswaitingstate for idle sessions (yellow)zen statusshows yellow dot for waiting sessionszen who-am-i -r mono -p 7dshows merged PRs, in-progress, and reviewszen who-am-i --mergedshows full commit descriptionszen work newsucceeds on large repos (previously failing with "Could not write new index file")zen work newcleans up orphaned branch automatically🤖 Generated with Claude Code