Add handoffs: resumable working state for named agents #4

Merged
kerryhatcher merged 4 commits from handoffs into main 2026-11-05 14:34:21 +00:00
Owner

Summary

Adds handoffs: resumable working-state snapshots for a named agent, so a session that crashes, is cleared with /clear, or is restarted can carry on.

  • Each handoff has a UUID, the agent name it was saved under, a title, a markdown body, and created_at / updated_at. One agent can own several; the most recently updated is the one to resume.
  • MCP tools: save_handoff (create, or update by id), get_handoff (by id, or by agent_name with that agent's other handoffs listed), list_handoffs, delete_handoff.
  • peachmem handoff-context is a SessionStart hook. It looks up the latest handoff for the session's name and adds a pointer to the session context. It only reads.
  • The plugin adds hooks/handoff-start.sh (registered for startup|resume|clear|compact) and skills/handoff/SKILL.md, which covers when to save and how to keep a handoff lean.
  • Bodies are capped at 8000 characters, so handoffs stay pointer documents that reference the issue log, note slugs, file paths, and commits rather than copying them.
  • Merging projects moves their handoffs.
  • Version bumped to 0.5.0.

Decisions

  • Separate table, not notes. Handoffs have no slug, wikilinks, or kind, and stay out of search_notes and list_notes.
  • Name matching is exact and case-insensitive, not fuzzy.
  • Name source for the hook: the payload's session_title (set by claude --name), falling back to the transcript's last agent-name entry for resumes. A fresh session's transcript doesn't exist yet at SessionStart, so the fallback only helps resumes.
  • Failure is silent. The hook exits 0 in every case. Its lookup is capped at 5s, because sqlx would otherwise retry a refused connection for 30s and stall session start.
  • No status field. Finished work is recorded as a final handoff titled DONE:, and delete_handoff removes abandoned ones.

Schema

Migration 0005_handoffs.sql adds the handoffs table. It's additive, so existing data is untouched. Running this binary against the real database migrates it to schema v5. A binary older than 0.5.0 then refuses writes until restarted, which is the existing schema-guard behaviour.

Tests

cargo test --features db-tests against the dev database:

  • 69 unit tests
  • 5 CLI tests, including the hook's silent and fail-open cases
  • 13 handoff integration tests, covering create/update, name lookup and siblings, project filtering, validation, delete, the schema guard, and project merge
  • 45 knowledge tests and 29 schema-guard tests, both passing

cargo clippy --all-targets --features db-tests is clean.

tests/schema_guard.rs changed in one place: the in-flight migration test hard-coded version 5, which is now a real migration. It now uses known_version() + 1.

Not verified

  • A live Claude Code session receiving the hook's injected context. This needs a manual check: start an agent with claude --name <name> after a handoff has been saved under that name.
  • Whether /clear preserves the session name. If it doesn't, a cleared session has no name for the hook to use.

The deskwork incident team's spawn-team.sh now passes --name "$name" to claude, so a restarted dw-* agent has its name at startup. That change lives in the deskwork repo.

🤖 Generated with Claude Code

## Summary Adds **handoffs**: resumable working-state snapshots for a named agent, so a session that crashes, is cleared with `/clear`, or is restarted can carry on. - Each handoff has a UUID, the agent name it was saved under, a title, a markdown body, and `created_at` / `updated_at`. One agent can own several; the most recently updated is the one to resume. - MCP tools: `save_handoff` (create, or update by `id`), `get_handoff` (by `id`, or by `agent_name` with that agent's other handoffs listed), `list_handoffs`, `delete_handoff`. - `peachmem handoff-context` is a SessionStart hook. It looks up the latest handoff for the session's name and adds a pointer to the session context. It only reads. - The plugin adds `hooks/handoff-start.sh` (registered for `startup|resume|clear|compact`) and `skills/handoff/SKILL.md`, which covers when to save and how to keep a handoff lean. - Bodies are capped at 8000 characters, so handoffs stay pointer documents that reference the issue log, note slugs, file paths, and commits rather than copying them. - Merging projects moves their handoffs. - Version bumped to 0.5.0. ## Decisions - **Separate table, not notes.** Handoffs have no slug, wikilinks, or kind, and stay out of `search_notes` and `list_notes`. - **Name matching is exact and case-insensitive**, not fuzzy. - **Name source for the hook:** the payload's `session_title` (set by `claude --name`), falling back to the transcript's last `agent-name` entry for resumes. A fresh session's transcript doesn't exist yet at SessionStart, so the fallback only helps resumes. - **Failure is silent.** The hook exits 0 in every case. Its lookup is capped at 5s, because sqlx would otherwise retry a refused connection for 30s and stall session start. - **No status field.** Finished work is recorded as a final handoff titled `DONE:`, and `delete_handoff` removes abandoned ones. ## Schema Migration `0005_handoffs.sql` adds the `handoffs` table. It's additive, so existing data is untouched. Running this binary against the real database migrates it to schema v5. A binary older than 0.5.0 then refuses writes until restarted, which is the existing schema-guard behaviour. ## Tests `cargo test --features db-tests` against the dev database: - 69 unit tests - 5 CLI tests, including the hook's silent and fail-open cases - 13 handoff integration tests, covering create/update, name lookup and siblings, project filtering, validation, delete, the schema guard, and project merge - 45 knowledge tests and 29 schema-guard tests, both passing `cargo clippy --all-targets --features db-tests` is clean. `tests/schema_guard.rs` changed in one place: the in-flight migration test hard-coded version 5, which is now a real migration. It now uses `known_version() + 1`. ## Not verified - A live Claude Code session receiving the hook's injected context. This needs a manual check: start an agent with `claude --name <name>` after a handoff has been saved under that name. - Whether `/clear` preserves the session name. If it doesn't, a cleared session has no name for the hook to use. ## Related The deskwork incident team's `spawn-team.sh` now passes `--name "$name"` to `claude`, so a restarted `dw-*` agent has its name at startup. That change lives in the deskwork repo. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A handoff is a snapshot of one named agent's working state (goal, state,
next steps, decisions, references). Agents save one as they work and update
it in place, so a session that crashes, is cleared, or is restarted can
carry on. Each handoff has a UUID, the agent name it was saved under, and
created/updated timestamps. One agent may own several; the most recently
updated is the one to resume.

- Migration 0005 adds a separate `handoffs` table, not notes.
- MCP tools: save_handoff, get_handoff (by id, or by agent name with the
  agent's other handoffs), list_handoffs, delete_handoff. Bodies are capped
  at 8000 characters so handoffs stay pointer documents.
- `peachmem handoff-context` is a SessionStart hook that adds a pointer to
  the latest handoff for the session's name. The name comes from
  session_title (claude --name) or the transcript's agent-name entry. The
  lookup is capped at 5s and always exits 0.
- Plugin: hooks/handoff-start.sh registered on startup/resume/clear/compact,
  and skills/handoff/SKILL.md for when to save and how to keep it lean.
- Merging projects moves their handoffs.
- schema_guard's in-flight migration test uses known_version() + 1 rather
  than a hard-coded version 5, which is now a real migration.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
kerryhatcher/peachmem!4
No description provided.