feat: structured agent monitoring with status persistence and graceful UX#7
Merged
feat: structured agent monitoring with status persistence and graceful UX#7
Conversation
Extract linear entrypoint.sh into discrete functions (parse_args, copy_credentials, create_worktree, setup_agent_perms, run_agent, run_interactive) called from a main() entry point. Prepares for adding monitoring logic without growing an unmaintainable script. Zero behavior change — all 49 shellspec tests pass unchanged. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ecycle markers Add structured monitoring to the entrypoint agent mode: - Create .agent/ dir in worktree with status.json (phase, branch, task, timestamps, exit code, commit count) - Persist full agent output to .agent/agent.log via tee - Emit [agent:status] tagged markers at lifecycle transitions (starting → working → completed/errored) - Capture post-run metrics (commit count, duration, last commit) - Add .agent/ to worktree .gitignore automatically The su-exec call no longer uses exec, allowing post-processing to run after claude exits. Test mocks updated accordingly with 6 new test cases. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add new targets and enhance existing ones: - status-agent: reads status.json from worktree (works post-exit) - summary-agent: extracts [agent:status] markers from logs - list-agents: now shows phase from each worktree's status.json - logs-agent: falls back to .agent/agent.log when container is gone - follow-agent: same fallback behavior All fallback paths return exit 0 with contextual messages instead of silent failures, fixing the UX issue where finished agents appeared as errors. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add new commands to the q CLI: - q agents status --branch X: reads status.json directly from filesystem (no container needed, works post-exit) - q agents summary --branch X: shows structured lifecycle events The logs and follow commands now delegate to Makefile targets that include graceful fallback to persisted .agent/agent.log when the container no longer exists. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Update spawn-agent skill with decision flow for monitoring: status.json → agent.log → container logs. Add guidance for post-exit scenarios where container is gone. Update docs: - spawn-agent-skill.md: new monitoring commands and post-exit status - cli.md: document q agents status/summary and log fallback behavior Update evals: - list_and_monitor.md: add part 3 for status post-exit scenario - evals.json: update eval 4 to prefer status.json, add evals 7 (status post-exit) and 8 (logs fallback) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
entrypoint.shinto discrete functions (parse_args,copy_credentials,create_worktree,setup_agent_perms,run_agent,run_interactive) with amain()entry point for maintainabilitystatus.json(phase, timestamps, exit code, commit count) andagent.login the worktree at.agent/, emit[agent:status]lifecycle markers to stdoutlogs-agentandfollow-agentfall back to persisted.agent/agent.logwith contextual messages instead of silent exit code 1 when the container is gonemake status-agent,make summary-agent,q agents status,q agents summary— all work post-exit without needing the containerDevEx improvements
logs,follow)container logs→ read raw → interpretstatus.json→ 1 stepTest plan
cd config && shellspec --shell bash— 55 examples, 0 failures (49 original + 6 new)cd app/cli && uv run pytest -v— 46 passedcd app/cli && uv run ruff check .— all checks passedmake build— verify image builds with new entrypointmake spawn BRANCH=test/monitor TASK="create a hello.txt"— verify status.json + agent.log createdmake status-agent BRANCH=test/monitor— verify JSON output post-exitmake logs-agent BRANCH=test/monitor(after exit) — verify fallback message/skill-creator:skill-creator run evals for the spawn-agent skill🤖 Generated with Claude Code