Skip to content

feat(crews): a Crew proposal records the playbook it follows - #383

Merged
bryantderosier merged 9 commits into
j5/319-playbook-step-personasfrom
j5/321-crew-playbook-plan
Sep 30, 2026
Merged

bryantderosier merged 9 commits into
j5/319-playbook-step-personasfrom
j5/321-crew-playbook-plan

Conversation

@bryantderosier

@bryantderosier bryantderosier commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A Crew had no way to say which playbook it follows or which seat owns which step, so "create a crew that uses this playbook" could only produce a roster with no plan behind it (#321). This PR lets propose_crew name a playbook and give each seat its steps, records that plan on the Crew, and shows it on the roster card before anyone approves.

This PR is stacked on #380 (#319, which adds playbook_read, per-step persona, and personaCatalogProblem). #384 (#322) is stacked on this one and reads the storage it adds.

What I changed

  • packages/contracts/src/j5.ts → optional CrewProposalSeat.steps and personaSwaps, CrewPersonaSwap, CrewProposalPlaybook, CrewProposal.playbook, preview playbook and unownedSteps, FleetCrew.playbook, and roster steps. All additive and optional.
  • apps/server/src/j5/a2a/migrations/028_CrewPlaybooks.ts → playbook_name and playbook_definition_path on the proposal and instance tables, playbook_step_ids on members. Registered in Migrations.ts.
  • New apps/server/src/j5/a2a/crewPlaybookPlan.ts → planCrewPlaybook, one pure check called from CrewProposalService.validateSeats. It refuses an unknown playbook, an invalid definition, an unknown step id, a step claimed twice (or already owned by a live member, for additions), and steps without a playbook, each with a next step. It computes persona swaps and unowned steps.
  • CrewProposalService.ts → propose, requestMember, preview, and resolve all run that check against the live YAML. A Crew's playbook is read for an addition only when the joining seat claims steps, so a stepless seat can still join after the playbook file is gone. resolve re-reads the definition, carries steps into the launch seats, and maps CrewStepAlreadyOwnedError to a refusal that leaves the proposal open.
  • crewRuntimePreview.ts → crewPlaybookPlanDigest, a hash of what the card shows (definition path, title, each step's id, title, and persona, the swaps, unowned steps). It goes into the approval token, so a same-id title or persona edit, or a persona being turned off between preview and approve, makes the token stale. Prompts are left out. A proposal without a playbook gets the same token as before.
  • AgentCrewInstanceService.ts → record and addMembers enforce step ownership inside the Crew's serialized member transaction and fail with the tagged CrewStepAlreadyOwnedError, writing nothing. record checks over the roster as it will stand after the write, and a re-approval replay updates a same-named seat's playbook_step_ids with ON CONFLICT DO UPDATE on that column only.
  • CrewLaunchService.ts → steps rides CrewLaunchSeat through launch, record, and addSeats. Both error wrappers pass CrewStepAlreadyOwnedError through unwrapped.
  • spawnIds.ts → each seat's first turn gets a <seat_playbook> block with the playbook and its steps (or your_steps: none), between <j5_crew_context> and <spawner_brief>. Titles and ids go through briefLine, so a newline or </seat_playbook> can't break the block.
  • apps/server/src/j5/playbooks/workspace.ts → playbookWorkspaceRoot(threadId), moved out of playbooks/mcp.ts so the playbook tools and propose_crew resolve the same root. PlaybookStore gains readPath.
  • MCP mcp/tools.ts and mcp/handlers.ts → propose_crew.playbook, seat steps, request_crew_member.steps, and a playbook block on the result (unowned_steps, persona_swaps).
  • CrewProposalsHttp.ts and FleetReadsHttp.ts → the list and preview return the playbook projection (a read error becomes issue, never a failed list); Fleet returns the playbook name and each seat's steps.
  • Web CrewProposalCard.tsx and new crewPlaybookPlan.ts → "Follows playbook", each seat's steps, a swap line per swapped step, "Unowned steps, done by the Captain", and "Removing leaves unowned". The card renders from the preview response, the same values the token binds. crewProposalDraft.ts and crewSeatRuntime.ts keep steps when a seat is edited. FleetPage.tsx shows "Playbook: " and each seat's steps.
  • Docs: docs/user/personas.md, docs/j5/product/features/crews.md, docs/j5/product/a2a/agent-tools.md.

Before (no playbook: the roster card as it was):

Roster card before

After (the Crew follows "Release review": each seat's steps, a persona swap because builder-bot is turned off, and the two steps the Captain does):

Roster card after

Why this shape

  • The definition path is the identity; only ids are stored. Titles, prompts, and personas are read live from the YAML whenever they're shown or delivered. What the person approved is bound by the plan digest in the approval token, not by a stored copy that could drift from the file.
  • Ownership is enforced where members are written. The pure check gives early, specific messages, but two open additions can both pass preview. The authoritative check runs in the member transaction under crews.serialize, so the first approval wins and the second is refused with nothing written. The tagged error has to survive CrewLaunchService's wrapping, or the person gets a generic launch failure and the proposal closes.
  • A re-approval replay follows the latest approval. After a failed link the same instance is recorded again. I check ownership over the roster as it will stand after the write and update a same-named seat's steps, so a step moved to a new seat or left unowned is stored as approved, while a kept seat's step still refuses a new claimant.
  • Stored step ids follow PlaybookStep.id: non-empty, no length cap. Only their count is bounded. An earlier cap at the seat-name length let a valid long id pass every check and then fail to encode.
  • Swaps are recorded, not refused. A missing or turned-off persona is a warning in Playbook steps name the persona that does them #319, so a Crew can still staff that step with another seat; the card says why.
  • The card can't reassign steps. Removing a seat leaves its steps unowned, and the card says so before Approve. Reassignment is a Captain re-propose.

Invariants

  • A step id is owned by at most one member of a Crew, enforced in the member transaction.
  • AgentCrewInstance.playbook is set at approval and never changes.
  • One active playbook run per Captain thread is enforced only by playbook_start (already_active), when the run starts. Proposing a playbook Crew isn't gated on run state. I dropped the propose-time refusal after review, so the original plan's version of this rule no longer applies.
  • An addition that claims no steps never reads the playbook file; one that claims steps against a missing or broken file is refused.
  • A proposal without a playbook produces the same approval token, card, brief, and rows as before.
  • Any change to what the card showed, between preview and approve, makes the approval stale. A prompt-only edit doesn't.
  • CrewStepAlreadyOwnedError reaches resolve unwrapped, and the proposal stays open.

Surfaces

Surface Decision
Entry points (chat, Settings, command palette, keybinding) changed: the Captain's propose_crew and request_crew_member, the roster card in the Captain's thread, and the Inbox addition card (it reuses the same card); no Settings, palette, or keybinding surface
Clients (web, desktop, mobile) changed: web and desktop card and Fleet; mobile unaffected because it has no Crew roster card or Fleet page
Providers unaffected: tool inputs are provider-neutral and the brief is text
Contracts (packages/contracts) changed, additive and optional, in the J5-owned src/j5.ts
Reverse states removing a seat unowns its steps; declining discards the plan; a Crew's playbook is fixed after approval by design
Connection modes (local, remote, tunnel) unaffected: existing J5 routes and MCP tools with additive fields
Upstream files / FORK.md none: every changed file is J5-owned; no FORK.md edit
Docs changed: docs/user/personas.md, docs/j5/product/features/crews.md, docs/j5/product/a2a/agent-tools.md

Out of scope

Upgrade and data

Migration 028 adds five nullable columns. Existing proposals, Crews, and members read back with playbook: null and no steps and behave exactly as before. Older clients ignore the new optional fields. Rolling back leaves the columns unused. Numbering: j5/main's peering work took J5 migrations 23–27, so this is now migration 028. A dev database that ran an earlier build of this stack already recorded 23 as ours and would skip the peering migration with that number, so reset or re-copy such a database before testing. Real installs never ran the old number.

Verification

  • vp test run apps/server/src/j5/a2a/crewPlaybookPlan.test.ts apps/server/src/j5/a2a/CrewProposalService.test.ts apps/server/src/j5/a2a/AgentCrewProposalService.test.ts apps/server/src/j5/a2a/AgentCrewInstanceService.test.ts apps/server/src/j5/a2a/CrewLaunchService.test.ts apps/server/src/j5/a2a/CrewLaunchReporter.test.ts apps/server/src/j5/a2a/CrewProposalsHttp.test.ts apps/server/src/j5/a2a/FleetReadsHttp.test.ts apps/server/src/j5/a2a/Migrations.test.ts apps/server/src/j5/a2a/spawnIds.test.ts apps/server/src/j5/a2a/mcp/tools.test.ts apps/server/src/j5/a2a/mcp/handlers.test.ts apps/server/src/j5/playbooks/PlaybookStore.test.ts apps/server/src/j5/playbooks/mcp.test.ts apps/web/src/j5/crew/crewPlaybookPlan.test.ts apps/web/src/j5/crew/crewProposalDraft.test.ts: 16 files, 153 tests pass.
  • New tests cover:
    • propose, approve, and read back the playbook on the proposal, instance, and members;
    • each refusal with its next step, and the active-run refusal naming the run;
    • two open additions racing for one step through the real resolve → CrewLaunchService → AgentCrewInstanceService: the second gets the "already owned" refusal, not a launch error, with no member row and the proposal still open;
    • the approval token going stale on a same-id title edit, a persona edit, and a persona being turned off, and staying the same on a prompt-only edit;
    • a re-approval replay after a failed link, with a moved step, an unowned step, and a kept seat's step;
    • a 121-character step id stored and read back, and a newline and </seat_playbook> inside an id escaped in the brief;
    • migration 028 on existing rows.
  • vp exec tsc --noEmit -p . in packages/contracts, packages/client-runtime, apps/server, and apps/web: clean. vp lint on the touched files: clean.
  • Screenshots come from an isolated dev server with a sample playbook (four steps, two with personas, one of them turned off). Web only.

Review focus

  • AgentCrewInstanceService.record and addMembers: the post-write ownership check and the ON CONFLICT DO UPDATE on playbook_step_ids. I most want the replay cases challenged.
  • crewPlaybookPlanDigest and where preview and resolve compute it: whether anything the card shows is missing from the digest.

Closes #321 (stacked on #380)

Claude Opus 5.5 via J5 Code (crew: planner, builder, and two reviewers on Claude and Codex)

🤖 Generated with Claude Code

bryantderosier and others added 4 commits September 29, 2026 17:41
propose_crew can name a playbook and give each seat the step ids it owns;
request_crew_member can claim steps no seat owns yet. The server checks
every claim against the live YAML at propose, preview, and approve, and
refuses a playbook proposal while the Captain's thread runs a playbook.
The proposal and instance record the playbook's definition path and each
member its step ids (migration 023); ownership is enforced again inside
the member store's serialized reservation, and that refusal reaches the
gate unwrapped, so of two additions racing for one step the second is
refused and stays open. Persona swaps are computed by the server and
bound, with the card-visible plan, into the approval token. Each seat's
first turn lists its steps, and the roster card and Fleet show the plan.

Closes #321

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A retried record keeps the stored row of every seat already on the roster,
so that seat's stored steps stay owned; the ownership check now counts
them instead of skipping the seat, and a new seat claiming one is refused
with nothing written.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A seat's stored step ids were capped at the seat-name length, so a valid
playbook step id over 100 characters passed every door and then failed to
encode when the proposal was written. Stored step ids now follow
PlaybookStep.id: non-empty with no length cap; only their count is bounded.
A step id also sits on the same line of the <seat_playbook> block as its
title, so it gets the same one-line, close-tag-safe treatment.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A re-approval after a failed link replays record under the same instance
id. Ownership is now checked over the roster as it will stand (rows no
incoming seat replaces, plus every incoming seat with its incoming steps),
and the member write takes a same-named seat's newly approved steps with
ON CONFLICT DO UPDATE on playbook_step_ids only. A step moved to a new seat
or left unowned is stored as approved; a kept row's step still refuses a
new claimant, with nothing written.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@bryantderosier bryantderosier added enhancement New feature or request size:XL 500-999 effective changed lines (test files excluded in mixed PRs). labels Sep 29, 2026
@bryantderosier bryantderosier self-assigned this Sep 29, 2026
@github-actions github-actions Bot added size:XXL 1,000+ effective changed lines (test files excluded in mixed PRs). and removed size:XL 500-999 effective changed lines (test files excluded in mixed PRs). labels Sep 29, 2026
@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Repository: Jacksondr5/j5code/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 1f12c97f-0a4b-4892-af12-9e9c368d41fb

  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the vouch:trusted Author is trusted by repo permissions or the VOUCHED list. label Sep 29, 2026

@Jacksondr5 Jacksondr5 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Review panel: Opus 5.5, Astra, Sonnet 5.5, Sol 6.1]

Two findings the whole panel agrees on are inline. Product questions about where a Crew's playbook link lives go to Jackson separately.

@bryantderosier

Copy link
Copy Markdown
Collaborator Author

@Jacksondr5 thanks for the thorough pass on the stack. We're taking all the fixes: dropping the crew clause from the mention instructions (#387 owns that now), hiding the misnamed rows, keeping trailing punctuation, fixing the FORK.md rows, letting a Crew add stepless seats after its playbook file is gone, removing the active-run guard at propose time, removing the boot sweep, showing an unreadable run as "needs attention" on Fleet, rewriting the playbooks definition, and fixing case 45. Fix commits are on the way and I'll reply on each thread as they land.

One thing I want to flag, though. A few of the comments lean on a standing decision from 2026-09-18: that playbooks are step tracking only and never affect spawn-time choices, and that there's no crash-recovery machinery. I can't find either of those written down anywhere in the repo, not in docs/j5/product, the principles, or the feature docs.

The first one is a bigger deal than a single comment, because it conflicts with this whole milestone. #319 through #323 are about building a Crew from a playbook: steps name the persona that does them, and #323 (#387) has the Captain staff the roster from those personas. The playbooks definition also says the opposite today. AC2 reads "A Role or a Crew can be spawned with a Playbook and told to follow it."

None of the fixes above depend on settling this, so they're going ahead either way. But #387's premise does. Can we talk it through before #387 merges, and get whichever way we land written into the product docs so it's not a hallway ruling?

bryantderosier and others added 3 commits September 29, 2026 23:09
A Captain already running a playbook could not propose a Crew that
follows one. playbook_start's one-active-run refusal already governs when
the Crew's run can start, so propose_crew no longer duplicates it, and
PlaybookStore.activeRunFor, which only that guard used, is removed.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ss seat

Every seat joining a playbook Crew re-read its YAML, so once the file was
gone or broken the Crew could add no seat at all, and the refusal said
"No playbook named ...". The definition is now needed only when a joining
seat claims steps: a missing or broken file refuses just that seat, saying
the Crew's playbook can no longer be read, and a stepless seat launches
with your_steps: none. A roster still records its playbook without it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ered to 28

Merges origin/j5/319-playbook-step-personas, which carries j5/main's
peering PRs and J5 migrations 23–27. CrewPlaybooks moves from 023 to 028
(migrations/028_CrewPlaybooks.ts, [28, "CrewPlaybooks", Migration0028]); the
pinned lists and the upgrade test (now through 27, then 28) follow.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@vercel

vercel Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
j5-code Ready Ready Preview Sep 30, 2026 5:37pm UTC

Request Review

bryantderosier added a commit that referenced this pull request Sep 30, 2026
…bered to 29

j5/main's peering migrations take J5 ids 23-27 and #383 moves
CrewPlaybooks to 28, so CrewPlaybookRuns becomes 29. The upgrade test
now runs through 28 before 29 and keeps its named-columns read. The
playbooks definition keeps its rewrite and gains main's pre-approval
sentence.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@Jacksondr5

Copy link
Copy Markdown
Owner

[Coordinator notes for discussion: D1 and D2 across #383 and #384]

@bryantderosier, Jackson wants to talk these two through with you before ruling. They are open questions, not decisions. The review panel split on both, and these are my recommendations. The example throughout is a Playbook review with steps Inspect (persona inspector), Verify (verifier), and Report (no persona).

D1: when does a Crew get its step assignments?

Today (#383, following the #319–#323 plan)

  1. The Captain calls propose_crew with playbook: review and gives each seat its steps: inspector-seat owns Inspect, and verifier-seat owns Verify.
  2. The roster card shows the plan: the Playbook, each seat's steps, the unowned Report falling to the Captain, and warnings where a seat's persona doesn't match its step's persona. The approval token fingerprints that plan.
  3. The seats spawn, and each one's startup instructions list its steps.
  4. The Captain calls playbook_start(review, crew_instance_id), and the relay hands each step to its owner.

This makes the Playbook part of the Crew's identity. The Crew stores the Playbook, each seat stores the steps it owns, and every roster path (propose, member addition, approval) has to re-read the YAML to validate ownership. The posted findings come from that:

  • A Crew whose YAML is gone can't add any seat (F1).
  • A Captain with an active run can't propose a new Playbook Crew (F4).
  • The approval token has to carry the plan fingerprint.

Alternative: bind when the run starts

  1. The Captain proposes a plain Crew (inspector-seat, verifier-seat), and the person approves the people on the normal roster card.
  2. The Captain calls playbook_start(review, crew_instance_id, owners: { inspect: inspector-seat, verify: verifier-seat }). The owner map is checked against the live Crew and YAML at that moment and stored on the run. Persona-mismatch warnings go back to the Captain in the response.
  3. Hand-offs work as they do now.

The Crew knows nothing about Playbooks. That removes:

  • the Playbook columns on the Crew instance and its members;
  • step validation in the roster paths, and with it F1 and F4;
  • the plan fingerprint;
  • the plan section of the roster card;
  • the <seat_playbook> startup block, since the step notice already carries the prompt.

A Crew could also run one Playbook and then another. This matches Jackson's 2026-09-18 ruling that Playbooks are step tracking added onto existing agents or Crews.

What the alternative gives up

  • The person no longer sees or approves the step assignment before anything spawns. They see it afterwards in the Captain's playbook_start result and on Fleet ("Step 2 of 3 · verifier-seat").
  • The Captain assigns steps without a separate check. The Captain is the thread the person watches, and it already chooses the seats' personas.

My recommendation: the alternative. Approving the assignment up front is the one real benefit of binding at proposal, and every roster operation has to know about Playbooks to provide it. The person approves the people either way. I know this is a substantial rework of #383 against the milestone plan, which is why Jackson wants to discuss it rather than just rule.

D2: how much machinery surrounds a step hand-off (#384)?

What has to happen: when the run lands on Verify, a message with Verify's prompt is posted to verifier-seat's thread, which starts its turn. If there's no live owner, the Captain does the step, and its own tool response already carries the prompt.

Today, PlaybookCrewRelay adds

  1. The j5_playbook_step_delivery table: one row per landing, holding the target seat and thread, the outcome (delivered, captain, or skipped), and when it resolved.
  2. A recorded target: it's saved before the send, so a retry goes to the same seat.
  3. A pending state: a transient send failure leaves the row pending and returns delivery_pending.
  4. A drain gate: every later next, back, or reselect first retries the pending rows, so the run is stuck until the send succeeds. An unreadable YAML also leaves rows pending, and then only playbook_cancel works.
  5. The boot reconcile sweep: the panel agreed this goes (F2).
  6. PERMANENT_REJECTIONS: a rejected notice is quietly recorded as the Captain's, and Fleet then shows "· Captain" for a step a seat owns.
  7. Status reads: Fleet and playbook_current read the latest row for the owner and the delivered, pending, or Captain state.
  8. Deterministic command and message IDs, so a retry never posts twice.

Smaller design (Opus and Sonnet on the panel, and me)

  • Move the run, work out the owner (a live seat or the Captain), and dispatch with the same deterministic IDs.
  • If the dispatch fails, the call returns an error. For example: "Moved to Verify, but verifier-seat wasn't notified: <reason>. Retry this call, or message the seat yourself." Retrying the same request is safe, because the run doesn't move twice and the message ID stops a second copy.
  • Fleet shows the owner from the ownership map, with no pending or delivered state.

That removes the table, the pending state, the drain gate, the sweep, and the rejection fallback. The relay goes from about 390 lines to about 120, and the migration shrinks to the run's Crew link, plus the owner map under the D1 alternative.

The case for keeping it (Astra and Sol on the panel)

  • The recorded target means a retry can't land on a different seat after the roster changes.
  • Fleet can tell "sent" from "pending".
  • The rows leave an audit trail.

All three are true, but they cover rare cases. A retry after a roster change that reaches the Captain instead is acceptable, and a failed send is already visible to the Captain as an error. That fits "error out instead of building machinery for rare cases" in AGENTS.md.

How D2 relates to D1: under today's D1, ownership lives on Crew members and can change as seats are added, so the recorded target matters a little. Under the alternative, the owner map is fixed on the run, so "who holds this step" comes straight from the run and the table has nothing left to do. The smaller design works with either choice.

My recommendation: the smaller design, whichever way D1 goes.


Coordinator: Claude Opus 5.5 (Claude Code)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@Jacksondr5

Jacksondr5 commented Sep 30, 2026 •

Copy link
Copy Markdown
Owner

[Coordinator: outcome of the D1/D2 discussion]

  • D1: Jackson and Bryant agreed to keep the current design. The Crew binds its Playbook at proposal, and the person approves the per-seat plan on the roster card. The plan fingerprint and the <seat_playbook> startup block stay with it.
  • D2: deferred until after the stack merges, as part of a playbooks refactor. Tracked in Revisit Crew playbook step-delivery machinery after #384 merges #389.

Correction: an earlier version of this comment said F1 still applies. Bryant fixed it in 446b911, which the panel is verifying.

Coordinator: Claude Opus 5.5 (Claude Code)

@Jacksondr5 Jacksondr5 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Review panel: Opus 5.5, Astra, Sonnet 5.5, Sol 6.1]

Approving at 5e5e717. The panel checked both fixes against the source:

  • F1: a Crew whose Playbook file is gone can still add a seat that claims no steps.
  • F4: the propose-time guard is removed.

Migrations 28 and 29 are clean after the peering merge.

D1 stays as implemented. D2, the delivery machinery, is tracked in #389.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@bryantderosier
bryantderosier merged commit a6fe6c3 into j5/main Sep 30, 2026
37 checks passed
@bryantderosier
bryantderosier deleted the j5/321-crew-playbook-plan branch September 30, 2026 18:19

This branch was successfully deployed

1 active deployment
Preview — c3ede388 Deployed Sep 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:XXL 1,000+ effective changed lines (test files excluded in mixed PRs). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A Crew proposal records the playbook it follows

2 participants