Skip to content

feat: structured agent monitoring with status persistence and graceful UX#7

Merged
deimagjas merged 5 commits intomainfrom
feat/agent-monitoring
Apr 5, 2026
Merged

feat: structured agent monitoring with status persistence and graceful UX#7
deimagjas merged 5 commits intomainfrom
feat/agent-monitoring

Conversation

@deimagjas
Copy link
Copy Markdown
Owner

Summary

  • Refactor entrypoint into functions: Extract linear entrypoint.sh into discrete functions (parse_args, copy_credentials, create_worktree, setup_agent_perms, run_agent, run_interactive) with a main() entry point for maintainability
  • Add structured monitoring: Agents now persist status.json (phase, timestamps, exit code, commit count) and agent.log in the worktree at .agent/, emit [agent:status] lifecycle markers to stdout
  • Graceful UX for finished agents: logs-agent and follow-agent fall back to persisted .agent/agent.log with contextual messages instead of silent exit code 1 when the container is gone
  • New commands: make status-agent, make summary-agent, q agents status, q agents summary — all work post-exit without needing the container
  • Updated skill, docs, and evals: Decision flow (status.json → agent.log → container logs), 2 new eval scenarios for post-exit UX (8 total)

DevEx improvements

Metric Before After
Silently failing commands 2/5 (logs, follow) 0/5
Info available post-exit Only worktree files status.json + agent.log + worktree
Steps to know agent status container logs → read raw → interpret status.json → 1 step
Confusing errors for user Exit code 1 with no message Contextual message + fallback

Test plan

  • cd config && shellspec --shell bash — 55 examples, 0 failures (49 original + 6 new)
  • cd app/cli && uv run pytest -v — 46 passed
  • cd app/cli && uv run ruff check . — all checks passed
  • make build — verify image builds with new entrypoint
  • make spawn BRANCH=test/monitor TASK="create a hello.txt" — verify status.json + agent.log created
  • make status-agent BRANCH=test/monitor — verify JSON output post-exit
  • make logs-agent BRANCH=test/monitor (after exit) — verify fallback message
  • Run spawn-agent evals: /skill-creator:skill-creator run evals for the spawn-agent skill

🤖 Generated with Claude Code

deimagjas and others added 5 commits March 31, 2026 23:52
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>
@deimagjas deimagjas self-assigned this Apr 1, 2026
@deimagjas deimagjas merged commit 71f66ed into main Apr 5, 2026
8 checks 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