feat: per-agent status tracking with Python watcher daemon#57
Open
feat: per-agent status tracking with Python watcher daemon#57
Conversation
88925b7 to
a5e72b2
Compare
c4f423e to
b8bf7ca
Compare
Per-agent fact files replace the single session status field:
- Hook writes {session_id}.agent.{key}.json per agent (main + subagents)
- File locking (fcntl.flock) prevents concurrent hook races
- Session-level status derived from agent priorities: needs_approval > working > waiting
Python watcher daemon (--watch mode) resolves hook blind spots:
- Transcript resolution: detects tool completion/rejection when no hook fires
- Process inspection: flips needs_approval→working when command is already running
- Interruption detection: sets all agents to waiting on user interrupt
- PID liveness cleanup: removes dead sessions
- Single process for all sessions, self-terminates after 60s idle
- ensure_watcher() called on every hook invocation
Swift side simplified to pure file reader:
- SessionProcessor: only deriveStatus, isGhost, abandoned detection (65 lines)
- SessionStateWatcher: DispatchSource only, no timer, no PID checks
- Watcher writes to fact files trigger DispatchSource automatically
Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Radek Ježek <radek.jezek@ibm.com>
b8bf7ca to
4ed534f
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
{session_id}.agent.{key}.jsonfile. File locking (fcntl.flock) prevents concurrent hook races. Session-level status is derived from agent priorities:needs_approval > working > waiting.--watchmode): Single background process polls every 1.5s, resolving hook blind spots:needs_approval → workingwhen a command is already running as a child processwaitingon user interruptensure_watcher()on every hook invocation restarts it if needed.SessionProcessorstripped from 273 → 65 lines (onlyderiveStatus,isGhost, abandoned detection).SessionStateWatcheruses DispatchSource only — no timer, no PID checks, no transcript parsing. All resolution state is persisted to disk..lockfiles.derive_agent_statusreturned stale status when tools dict was empty instead of"waiting".Test plan
swift buildpassesuv run pytest Tests/python/ -v— 61/61 tests pass (28 new tests for agent facts, watcher resolution, lifecycle simulation)sleep 20) — should transition to "working" immediately (watcher process inspection)