From 2751fbfd222f87797329f22966cabf5cb8403931 Mon Sep 17 00:00:00 2001 From: Bryant Derosier Date: Tue, 27 Oct 2026 20:38:26 -0400 Subject: [PATCH 1/9] test(j5): a Captain's ask is answered once from either view and withdrawn from both Co-Authored-By: Claude Sonnet 5.5 --- .../src/j5/a2a/HumanInboxService.test.ts | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/apps/server/src/j5/a2a/HumanInboxService.test.ts b/apps/server/src/j5/a2a/HumanInboxService.test.ts index bfef5a5068529..c2aeae057d1e2 100644 --- a/apps/server/src/j5/a2a/HumanInboxService.test.ts +++ b/apps/server/src/j5/a2a/HumanInboxService.test.ts @@ -439,3 +439,117 @@ it.effect( }).pipe(Effect.provide(makeTestLayer(deliveries))); }), ); + +// A Captain's adjudication ask is an ordinary ask to the person, so the one answer path serves the +// Inbox and the Captain's thread alike: the thread finds its asks by `senderThreadId`. +it.effect("answers a Captain's ask once from either view and drops a withdrawn ask from both", () => + Effect.gen(function* () { + const deliveries = yield* Ref.make>([]); + yield* Effect.gen(function* () { + yield* runMigrations(); + yield* runJ5A2AMigrations(); + const ledger = yield* A2ALedger; + const send = yield* A2ASendService; + const inbox = yield* A2AHumanInbox; + const worker = yield* A2ADeliveryWorker; + const sql = yield* SqlClient.SqlClient; + const at = "2026-10-27T10:00:00.000Z"; + yield* sql` + INSERT INTO j5_a2a_human_person (person_id, is_local_operator, created_at) + VALUES (${firstPerson.id}, 1, ${at}) + `; + yield* sql` + INSERT INTO j5_a2a_person_level (person_id, scope_kind, scope_id, level, created_at, updated_at) + VALUES (${firstPerson.id}, 'server', '', 'owner', ${at}, ${at}) + `; + const projectId = LedgerProjectId.make("project:captain-ask"); + const captain: AgentParticipant = { + kind: "agent", + id: ParticipantId.make("agent:captain-ask"), + threadId: ThreadId.make("thread:captain-ask"), + }; + yield* ledger.ensureProject({ projectId, createdAt: at }); + yield* ledger.appendEvents({ + commandId: CommCommandId.make("command:captain-ask:join"), + projectId, + acceptedAt: at, + events: [ + { + kind: "participant.joined", + sender: null, + receiver: captain.id, + exchangeId: null, + correlationId: null, + payload: { participant: captain }, + createdAt: at, + }, + ], + }); + const ask = Effect.fn("test.j5.a2a.captainAsk.ask")(function* (suffix: string) { + const sent = yield* send.send({ + commandId: CommCommandId.make(`command:captain-ask:${suffix}`), + senderThreadId: captain.threadId, + to: firstPerson.id, + message: `Which option? ${suffix}`, + expectReply: true, + intent: `Decide ${suffix}`, + urgency: "blocking", + acceptedAt: at, + }); + yield* worker.drain; + return sent.exchangeId!; + }); + const captainThreadAsks = (status?: "answered") => + inbox + .list(firstPerson.id, status) + .pipe( + Effect.map((items) => + items + .filter((item) => item.senderThreadId === captain.threadId) + .map((item) => item.exchangeId), + ), + ); + + const answeredAsk = yield* ask("answered"); + assert.deepStrictEqual(yield* captainThreadAsks(), [answeredAsk]); + + const answered = yield* inbox.answer({ + commandId: CommCommandId.make("command:captain-ask:reply:thread"), + personId: firstPerson.id, + exchangeId: answeredAsk, + message: "Option B", + acceptedAt: at, + }); + const secondView = yield* Effect.flip( + inbox.answer({ + commandId: CommCommandId.make("command:captain-ask:reply:inbox"), + personId: firstPerson.id, + exchangeId: answeredAsk, + message: "Option A", + acceptedAt: at, + }), + ); + assert.equal(secondView._tag, "A2AExchangeNotOpenError"); + + const withdrawnAsk = yield* ask("withdrawn"); + assert.deepStrictEqual(yield* captainThreadAsks(), [withdrawnAsk]); + yield* send.clearOwnAsk({ + commandId: CommCommandId.make("command:captain-ask:clear"), + senderThreadId: captain.threadId, + exchangeId: withdrawnAsk, + acceptedAt: at, + }); + yield* worker.drain; + + assert.deepStrictEqual(yield* captainThreadAsks(), []); + assert.deepStrictEqual(yield* captainThreadAsks("answered"), [answeredAsk]); + const replies = (yield* Ref.get(deliveries)).filter( + (delivery) => delivery.exchangeRole === "reply", + ); + assert.deepStrictEqual( + replies.map((delivery) => [delivery.messageId, delivery.receiverId, delivery.message]), + [[answered.messageId, captain.id, "Option B"]], + ); + }).pipe(Effect.provide(makeTestLayer(deliveries))); + }), +); From e5dab73a4cff5a546d9877fbd9716968022cc3da Mon Sep 17 00:00:00 2001 From: Bryant Derosier Date: Tue, 27 Oct 2026 20:38:54 -0400 Subject: [PATCH 2/9] docs(j5): a Captain asks the person with one Exchange, answerable in the Inbox and its thread Co-Authored-By: Claude Sonnet 5.5 --- docs/j5/product/features/crews.md | 4 ++-- docs/j5/product/features/inbox.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/j5/product/features/crews.md b/docs/j5/product/features/crews.md index 3bb6c9cb93c96..7a402d279995c 100644 --- a/docs/j5/product/features/crews.md +++ b/docs/j5/product/features/crews.md @@ -11,7 +11,7 @@ Complex work needs a group of agents with defined jobs working together with a h ## Definition -A **Crew** is a group of agents formed as a unit from a **roster its Captain proposes, approved by the person by default**, composed for the brief in front of it. Nobody writes a Crew file in advance. An agent chooses a Crew when the work needs workers who must respond to each other, and the person can ask for one in an ordinary conversation (web and desktop); the word "crew" in a message does not decide it, because the agent weighs the work (AC1). Once it chooses a Crew, the agent uses the conversation as context, keeps its current persona, model, and policy, and proposes the team before starting its work. There is no Crew slash command. No dedicated Captain agent exists; the agent that proposes becomes the Captain. It proposes a roster — a name, the brief every seat will start on, and a responsibility with a reason and instructions for each member. Saved personas are optional templates; a roster can mix them with custom members. A seat may name no persona at all: a **custom seat**, named and briefed by the Captain or the person, defaults to the Captain's provider, model, and reasoning, where the project's models for custom members allow that model, but to Full access, with harness, model, reasoning, and access editable before approval, so a Crew need not fit a mold anyone saved before (Jackson and Bryant, 2026-09-17). The Captain's access is never carried: a seat nobody configured would otherwise stop for approvals in a thread the person is not watching (Jackson, 2026-09-26). Its instructions are required at every door, since nothing else defines it. By default the proposal is a **human gate**, answered inline above the Captain's composer and never on the Inbox bell. **Settings → Agent Setup → Crews → Auto-approve new Crews** skips that gate when enabled for the Captain's project; it is off by default with project overrides. The setting is read for each new request, and changes leave existing Crews and open proposals alone. The Captain is the thread the person watches, so its own tool approvals and questions are answered inline there too. A seat runs out of view, so its provider tool approvals are answered from the Inbox (Jackson, 2026-09-26). A seat has no native question tool: when it needs a decision it asks its Captain with `j5_send_message`, and the Captain answers, or asks the person with its own question tool, inline in the Captain thread (Jackson, 2026-09-26). Claude seats run without `AskUserQuestion` and Codex seats without `request_user_input`; Cursor exposes no structured native question tool. Other harnesses keep their native tools and the standing rule to ask the Captain. If a seat still raises a native question, its Captain receives a queued notice naming the question and its thread. The person also sees a link in the Inbox to answer in the seat's original question form (Bryant, 2026-10-19). The person may drop seats, select personas from the library, or create custom seats with names, instructions, and runtime settings. Every proposed or manually added member uses the same editor before approval. Saved personas supply defaults; the person may override harness, model, reasoning, and access for this member without changing the saved definition. Approval creates every seat as a Peer Agent placed under the Captain, with a persona assignment only when the seat names a saved definition, and records the roster snapshot (the _Manifest_ in implementation vocabulary: name, brief, members with each one's reason and version). It starts no provider turns. The Captain receives a creation report naming what the person changed and which seats were created or failed. A decline is told at once. Each seat's first delivered assignment carries the platform's identity facts, the current Crew context and roster, any seat instructions, a handoff artifact obligation when its definition declares one, and the approved brief. +A **Crew** is a group of agents formed as a unit from a **roster its Captain proposes, approved by the person by default**, composed for the brief in front of it. Nobody writes a Crew file in advance. An agent chooses a Crew when the work needs workers who must respond to each other, and the person can ask for one in an ordinary conversation (web and desktop); the word "crew" in a message does not decide it, because the agent weighs the work (AC1). Once it chooses a Crew, the agent uses the conversation as context, keeps its current persona, model, and policy, and proposes the team before starting its work. There is no Crew slash command. No dedicated Captain agent exists; the agent that proposes becomes the Captain. It proposes a roster — a name, the brief every seat will start on, and a responsibility with a reason and instructions for each member. Saved personas are optional templates; a roster can mix them with custom members. A seat may name no persona at all: a **custom seat**, named and briefed by the Captain or the person, defaults to the Captain's provider, model, and reasoning, where the project's models for custom members allow that model, but to Full access, with harness, model, reasoning, and access editable before approval, so a Crew need not fit a mold anyone saved before (Jackson and Bryant, 2026-09-17). The Captain's access is never carried: a seat nobody configured would otherwise stop for approvals in a thread the person is not watching (Jackson, 2026-09-26). Its instructions are required at every door, since nothing else defines it. By default the proposal is a **human gate**, answered inline above the Captain's composer and never on the Inbox bell. **Settings → Agent Setup → Crews → Auto-approve new Crews** skips that gate when enabled for the Captain's project; it is off by default with project overrides. The setting is read for each new request, and changes leave existing Crews and open proposals alone. The Captain is the thread the person watches, so its own tool approvals and questions are answered inline there too. A seat runs out of view, so its provider tool approvals are answered from the Inbox (Jackson, 2026-09-26). A seat has no native question tool: when it needs a decision it asks its Captain with `j5_send_message`, and the Captain answers, or asks the person with `j5_send_message`, an ask that is listed in the Inbox and shown as an answerable card in the Captain thread, where answering in either place closes it (Jackson, 2026-09-26; Bryant, 2026-10-27). Claude seats run without `AskUserQuestion` and Codex seats without `request_user_input`; Cursor exposes no structured native question tool. Other harnesses keep their native tools and the standing rule to ask the Captain. If a seat still raises a native question, its Captain receives a queued notice naming the question and its thread. The person also sees a link in the Inbox to answer in the seat's original question form (Bryant, 2026-10-19). The person may drop seats, select personas from the library, or create custom seats with names, instructions, and runtime settings. Every proposed or manually added member uses the same editor before approval. Saved personas supply defaults; the person may override harness, model, reasoning, and access for this member without changing the saved definition. Approval creates every seat as a Peer Agent placed under the Captain, with a persona assignment only when the seat names a saved definition, and records the roster snapshot (the _Manifest_ in implementation vocabulary: name, brief, members with each one's reason and version). It starts no provider turns. The Captain receives a creation report naming what the person changed and which seats were created or failed. A decline is told at once. Each seat's first delivered assignment carries the platform's identity facts, the current Crew context and roster, any seat instructions, a handoff artifact obligation when its definition declares one, and the approved brief. **Captains add members directly.** When the work needs expertise the roster lacks, the Captain adds one seat with a reason and optional brief. No human approval is needed, regardless of the auto-approval setting. The same launch checks apply; the tool returns the updated roster or a refusal naming the member and reason, and the launch report follows. A Crew holds at most **twelve seats**, counting open legacy requests. Members escalate staffing needs to their Captain. Pending addition requests from before this change remain approvable or declinable above their Captain's composer and stay off the Inbox and its bell. @@ -76,7 +76,7 @@ A steer that races a Stop is a known case ([FORK.md](../../../FORK.md) case 26). 6. Approval creates every seat as a Peer Agent placed under the Captain and records the roster snapshot with each member's reason (human or automatic approval is recorded); it starts no turns. A proposal resolves once, so a second approval creates nothing and a decision racing another device's answer is refused. The Captain receives one launch report immediately after creation, naming the person's changes, each created seat as waiting for work, and any creation failures. A seat whose provider is signed out is refused before creation. The first participant message, direct chat message, or playbook step activates a waiting seat with its approved instructions and shared brief, the roster at activation including responsibilities and participant ids, and the assignment with its envelope and reply obligation intact. 7. An approval launches once. A failure before any seat spawns (the Crew or the approval could not be recorded) leaves the gate open to approve again; once seats start spawning, a seat that fails does not stop the others, and the launch report names every approved seat, including one whose thread was never created. A seat that was never created is not on the roster; the Captain asks for it again with `j5_request_crew_member`. 8. A Crew lives in exactly one project and renders as one node under its Captain with its members beneath it. -9. Every member can message any participant, and members run their own review loops. A reviewer sends findings straight to the teammate who owns the work, the owner sends the fix straight back, and they repeat until no finding is unresolved; a loop with no clean pass after three rounds (a round is one findings message and the fix that answers it) goes to the Captain as a blocker or a disagreement. A member messages its Captain only for a review pass that names the commit or change reviewed, a blocker that names what is needed, a disagreement it could not settle, and its final result when it finishes; it sends no acknowledgments or progress updates. The Captain owns the outcome: it settles technical disagreements within the agreed scope itself and asks the person only when product intent or judgment is needed. Playbook step hand-offs are unchanged. How each message reaches a running turn is in Messages and steering. The Crew's contact with the person goes through the inbox or its Captain rather than chat — a plain send to the person is refused by the [human-ask rule](../a2a/agent-tools.md), so a seat reaches the person only with an ask that lands in the Inbox or a reply on an open Exchange. A live Crew seat's pending provider approvals that the provider can still take are listed in the Inbox with their Crew and seat, counted on the bell, and answerable there; the seat's own thread still shows them too, so either place may answer. The Captain's approvals and questions, and approvals a seat can no longer take, are not listed. A live seat's pending native question that can still take an answer is listed as an Inbox link and counted on the bell; it is answered in the original thread, and the link disappears when resolved. A seat asks its Captain rather than the person: Claude and Codex seats have no native question tool, and every seat is told to ask its Captain with `j5_send_message`; a harness that still lets a seat ask natively shows the question in the seat's thread and notifies its Captain. The Captain may answer through upstream's pending-request tools when its modes allow and the answer follows the brief or the person's instructions; otherwise it asks the person to answer in the seat's thread. Native questions are not Inbox Exchanges. An answer to a request already resolved elsewhere is refused and changes nothing. +9. Every member can message any participant, and members run their own review loops. A reviewer sends findings straight to the teammate who owns the work, the owner sends the fix straight back, and they repeat until no finding is unresolved; a loop with no clean pass after three rounds (a round is one findings message and the fix that answers it) goes to the Captain as a blocker or a disagreement. A member messages its Captain only for a review pass that names the commit or change reviewed, a blocker that names what is needed, a disagreement it could not settle, and its final result when it finishes; it sends no acknowledgments or progress updates. The Captain owns the outcome: it settles technical disagreements within the agreed scope itself and asks the person only when product intent or judgment is needed, with `j5_send_message` rather than a native question so the request reaches the Inbox, giving the disagreement, the options and its recommendation while it keeps working on what does not depend on the answer. Playbook step hand-offs are unchanged. How each message reaches a running turn is in Messages and steering. The Crew's contact with the person goes through the inbox or its Captain rather than chat — a plain send to the person is refused by the [human-ask rule](../a2a/agent-tools.md), so a seat reaches the person only with an ask that lands in the Inbox or a reply on an open Exchange. A live Crew seat's pending provider approvals that the provider can still take are listed in the Inbox with their Crew and seat, counted on the bell, and answerable there; the seat's own thread still shows them too, so either place may answer. The Captain's native approvals and questions, and approvals a seat can no longer take, are not listed; the Captain's ask to the person is an ordinary ask and is listed. A live seat's pending native question that can still take an answer is listed as an Inbox link and counted on the bell; it is answered in the original thread, and the link disappears when resolved. A seat asks its Captain rather than the person: Claude and Codex seats have no native question tool, and every seat is told to ask its Captain with `j5_send_message`; a harness that still lets a seat ask natively shows the question in the seat's thread and notifies its Captain. The Captain may answer through upstream's pending-request tools when its modes allow and the answer follows the brief or the person's instructions; otherwise it asks the person to answer in the seat's thread. Native questions are not Inbox Exchanges. An answer to a request already resolved elsewhere is refused and changes nothing. ### Growing diff --git a/docs/j5/product/features/inbox.md b/docs/j5/product/features/inbox.md index 7434abe3f57b8..996acfcaf5e2c 100644 --- a/docs/j5/product/features/inbox.md +++ b/docs/j5/product/features/inbox.md @@ -15,7 +15,7 @@ The inbox is the one place a person looks to find everything that is waiting on The **inbox** is a person's queue of open asks, live Crew-seat provider approvals, and placed agents' pending native questions. It is **person-scoped, not project-scoped**: a person has one inbox across every environment the client connects to, every item wears the project it came from and, when more than one environment is connected, its environment, and no project selection elsewhere in the app hides an item. -The Inbox holds requests the person can act on: agent-addressed Exchanges, live Crew-seat provider approvals, and native questions on J5-spawned Peer Agents and live Crew seats. Native questions are links to the agent's original question form, not Exchanges or another answering form. A pending question counts whether it blocks the agent or the provider lets it continue working. Resolved, expired or cancelled questions leave the list as the server reports the change. Captains' own requests and Crew roster approvals stay inline in the thread the person watches, and native or delegated Subagents use upstream's parent routing. +The Inbox holds requests the person can act on: agent-addressed Exchanges, live Crew-seat provider approvals, and native questions on J5-spawned Peer Agents and live Crew seats. Native questions are links to the agent's original question form, not Exchanges or another answering form. A pending question counts whether it blocks the agent or the provider lets it continue working. Resolved, expired or cancelled questions leave the list as the server reports the change. A Captain's own native questions and approvals, and Crew roster approvals, stay inline in the thread the person watches. When a Captain needs the person's decision it asks with an Exchange, which is listed here and shown in its thread as a card that can be answered there too; answering in either place closes the one ask. Native or delegated Subagents use upstream's parent routing. A plain message to a person is refused; agents send an ask when a reply is owed. The person never opens an ask through the platform: their channel to an agent is its thread, and their only act on the ledger is the answer that closes an Exchange. From 1bae7a0af64fe0619ef00021bb2f909aa9480704 Mon Sep 17 00:00:00 2001 From: Bryant Derosier Date: Tue, 27 Oct 2026 20:47:30 -0400 Subject: [PATCH 3/9] feat(j5): a Captain asks the person with j5_send_message and brings options and a recommendation Co-Authored-By: Claude Sonnet 5.5 --- apps/server/src/j5/a2a/crewGateNotice.test.ts | 4 ++++ apps/server/src/j5/a2a/crewGateNotice.ts | 4 ++-- .../provider-core/src/j5/orchestrationInstructions.test.ts | 4 ++++ packages/provider-core/src/j5/orchestrationInstructions.ts | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/apps/server/src/j5/a2a/crewGateNotice.test.ts b/apps/server/src/j5/a2a/crewGateNotice.test.ts index 4a6dd6640a15d..41ab7909aba5b 100644 --- a/apps/server/src/j5/a2a/crewGateNotice.test.ts +++ b/apps/server/src/j5/a2a/crewGateNotice.test.ts @@ -286,6 +286,10 @@ describe("crew launch report", () => { text, "resolve technical disagreements within the agreed scope yourself, and ask the user only when product intent or their judgment is needed", ); + assert.include( + text, + "ask with j5_send_message to the user with expect_reply=true, not a native question tool, so the request reaches their Inbox, state the disagreement, the options as a list and your recommendation, and keep working on what does not depend on the answer", + ); assert.notInclude(text, "seat_failed"); }); it("identifies automatic approval without attributing it to a person", () => { diff --git a/apps/server/src/j5/a2a/crewGateNotice.ts b/apps/server/src/j5/a2a/crewGateNotice.ts index 4fb6b35ef5467..70cf87d6b58bb 100644 --- a/apps/server/src/j5/a2a/crewGateNotice.ts +++ b/apps/server/src/j5/a2a/crewGateNotice.ts @@ -212,14 +212,14 @@ export const crewLaunchReportText = (input: { ); if (waiting === 0 && failed.length === 0 && notCreated.length === 0 && pending.length === 0) prose.push( - "Your crew is running. Each seat has your brief and this roster; coordinate with j5_send_message, and ask the user through the inbox for decisions you cannot make from the brief.", + "Your crew is running. Each seat has your brief and this roster; coordinate with j5_send_message, and ask the user with j5_send_message (expect_reply=true) for decisions you cannot make from the brief.", ); if (playbook !== null && proposal.kind === "roster") prose.push( `This Crew follows playbook ${playbook.name}. Start it with j5_playbook_start(name: "${playbook.name}", client_request_id, crew_instance_id: "${instance.id}"). The platform hands each step to the seat that owns it; unowned steps are yours.`, ); prose.push( - "Seats are told to message you with their results; do not ask for the same results again. Members run their own review loops and message you only for a review pass, a blocker, a disagreement they could not settle, or their final result or step report: you resolve technical disagreements within the agreed scope yourself, and ask the user only when product intent or their judgment is needed. End your turn and read their messages as they arrive.", + "Seats are told to message you with their results; do not ask for the same results again. Members run their own review loops and message you only for a review pass, a blocker, a disagreement they could not settle, or their final result or step report: you resolve technical disagreements within the agreed scope yourself, and ask the user only when product intent or their judgment is needed; when you do, ask with j5_send_message to the user with expect_reply=true, not a native question tool, so the request reaches their Inbox, state the disagreement, the options as a list and your recommendation, and keep working on what does not depend on the answer. End your turn and read their messages as they arrive.", ); return `${block}\n\n${prose.join(" ")}`; }; diff --git a/packages/provider-core/src/j5/orchestrationInstructions.test.ts b/packages/provider-core/src/j5/orchestrationInstructions.test.ts index 550c605ea3d0b..e21771ecf43b3 100644 --- a/packages/provider-core/src/j5/orchestrationInstructions.test.ts +++ b/packages/provider-core/src/j5/orchestrationInstructions.test.ts @@ -171,6 +171,10 @@ describe("J5 orchestration instructions", () => { J5_ORCHESTRATION_INSTRUCTIONS, "settle technical disagreements within the agreed scope yourself, and ask the user only when product intent or their judgment is needed", ); + assert.include( + J5_ORCHESTRATION_INSTRUCTIONS, + "ask with `j5_send_message` to the user with `expect_reply=true`, not a native question tool, so the request reaches their Inbox, state the disagreement, the options as a list and your recommendation, and keep working on what does not depend on the answer", + ); assert.include(J5_ORCHESTRATION_INSTRUCTIONS, "`deliveryOutcome`"); }); diff --git a/packages/provider-core/src/j5/orchestrationInstructions.ts b/packages/provider-core/src/j5/orchestrationInstructions.ts index c9314c17bda9a..e13f626f0c5da 100644 --- a/packages/provider-core/src/j5/orchestrationInstructions.ts +++ b/packages/provider-core/src/j5/orchestrationInstructions.ts @@ -27,7 +27,7 @@ ${AGENT_INVOCATION_INSTRUCTIONS} - For every delegated review round, call \`delegate_task\` again. Include the original brief, prior findings, responses, and unresolved objections in each new task prompt. Track each round by its own \`taskId\`. Use a distinct \`clientRequestId\` per round, stable across retries of that round. - Way two, a Crew: a Crew is a group of Peer Agents you command as Captain for one bounded task. Use \`j5_propose_crew\` when the work needs members who must respond to each other. Mix saved personas from \`j5_list_personas\` with custom seats: set persona for a saved persona, or omit it and provide task-specific instructions for a custom seat. Custom seats inherit your harness, model, and reasoning by default and run with full access unless you set \`runtime_mode\`; you can select their harness, model, reasoning, and access with \`model_selection\` (instanceId, model, options) and \`runtime_mode\` from \`orchestrator_capabilities\`. Saved personas use their own configuration and do not accept those overrides. The app shows the roster in your thread, with each seat's resolved provider, model, reasoning, and access, and it is approved, edited, or declined there. Approval creates the seats without starting turns: send each member its first assignment when it has work, or hand it its first playbook step. Reuse finished members for follow-up work in the same thread; each seat's finish reaches you as a message. Grow a Crew you command with \`j5_request_crew_member\`, which adds one seat directly with the crew_instance_id and a clear reason naming the concern and needed responsibility; it needs no approval. - A Peer Agent is a full participant with its own top-level thread that the user can open and message. Use \`j5_spawn_agent\` only when the user explicitly asks for a standalone agent they will talk to, or when a skill you are following names it; it is not a third way to get help with your own work. Its brief states the task and whether a reply is expected; when you need a reply, include what should come back in that brief instead of sending a follow-up ask. -- Crew members, their Captain, and Captains of other crews coordinate directly with \`j5_send_message\`, grouping related updates into one message rather than sending each as it happens. Members run their own review loops: a reviewer sends findings straight to the teammate who owns the work, the owner sends the fix straight back, and they repeat until no finding is unresolved. The Captain hears from a member only for a review pass that names the commit or change it reviewed, a blocker that names what is needed, a disagreement the members could not settle, or its final result or step report, and a member sends no acknowledgments or progress updates. As Captain you own the outcome: settle technical disagreements within the agreed scope yourself, and ask the user only when product intent or their judgment is needed. The send result's \`deliveryOutcome\` says whether the message was steered into the receiver's running turn, is queued for its next turn, or is starting one; a busy receiver that cannot take it mid-turn handles each message as its own turn after its current one ends. Do not wait for an artifact or a separate coordination approval. Return results in messages unless the user or a selected persona explicitly requires an artifact; that output requirement never blocks conversation. If a concern needs expertise missing from the roster, the member tells its Captain, and the Captain adds a seat with \`j5_request_crew_member\`; continue the already-approved work and coordination meanwhile. +- Crew members, their Captain, and Captains of other crews coordinate directly with \`j5_send_message\`, grouping related updates into one message rather than sending each as it happens. Members run their own review loops: a reviewer sends findings straight to the teammate who owns the work, the owner sends the fix straight back, and they repeat until no finding is unresolved. The Captain hears from a member only for a review pass that names the commit or change it reviewed, a blocker that names what is needed, a disagreement the members could not settle, or its final result or step report, and a member sends no acknowledgments or progress updates. As Captain you own the outcome: settle technical disagreements within the agreed scope yourself, and ask the user only when product intent or their judgment is needed; when you do, ask with \`j5_send_message\` to the user with \`expect_reply=true\`, not a native question tool, so the request reaches their Inbox, state the disagreement, the options as a list and your recommendation, and keep working on what does not depend on the answer. The send result's \`deliveryOutcome\` says whether the message was steered into the receiver's running turn, is queued for its next turn, or is starting one; a busy receiver that cannot take it mid-turn handles each message as its own turn after its current one ends. Do not wait for an artifact or a separate coordination approval. Return results in messages unless the user or a selected persona explicitly requires an artifact; that output requirement never blocks conversation. If a concern needs expertise missing from the roster, the member tells its Captain, and the Captain adds a seat with \`j5_request_crew_member\`; continue the already-approved work and coordination meanwhile. - Use \`j5_list_participants\` to resolve an already-addressable agent or a person. It lists the people who can write to your thread; where more than one can, it also lists everyone here, and an ask to everyone here reaches all of them and is closed by the first reply. Use \`j5_send_message\` without expect_reply for updates or results that need no response. Only for later work owed by an existing participant, use \`j5_send_message(..., expect_reply=true, intent="...")\` to open an Exchange. The reply arrives later as an incoming message; continue with other work instead of polling or holding a turn open to wait. Messages reach a supported active turn through provider steering; otherwise they queue for its next turn. - \`schedule_task\` creates persistent recurring work in the app scheduler. Pass \`schedule\` as a structured object, never as JSON text: \`{"type":"interval","everyMs":3600000}\` for an interval, or \`{"type":"fixed_time","timeOfDay":"09:00","weekdays":[1,2,3,4,5]}\` for a wall-clock schedule, or \`{"type":"webhook"}\` to run on each request to the returned \`webhookUrl\` (the run sees the request only through \`{{body.path}}\`-style placeholders in the prompt). By default runs return to the current thread, which suits orchestrating: each trigger arrives here and you delegate or dedupe; set \`bindToCurrentThread=false\` only when the user wants a fresh thread for every run. After scheduling a timer, report the returned cadence and next run time; for a webhook, report its \`webhookUrl\`, or say T3 Connect remote access is needed if it is missing. - When you need a secret from the user (a token, API key, or webhook signing secret), call \`request_secret\` so they enter it privately, then pass the returned \`secretRef\` to the tool that needs it, e.g. \`signature.secretRef\` on a webhook task for a sender that signs requests such as GitHub. A \`secretRef\` works once. Never ask for a secret in chat, never invent one, and never repeat one. From 8a3d8a59f026ced50742c6367adc0fd1fb859c53 Mon Sep 17 00:00:00 2001 From: Bryant Derosier Date: Tue, 27 Oct 2026 21:18:08 -0400 Subject: [PATCH 4/9] feat(web): a Captain's open ask to you is pinned above its composer and answerable there Co-Authored-By: Claude Sonnet 5.5 --- FORK.md | 1 + apps/web/src/components/ChatView.tsx | 6 + apps/web/src/j5/a2a/AdjudicationDock.tsx | 191 ++++++++++++++++++ .../src/j5/a2a/adjudicationDock.logic.test.ts | 82 ++++++++ apps/web/src/j5/a2a/adjudicationDock.logic.ts | 66 ++++++ 5 files changed, 346 insertions(+) create mode 100644 apps/web/src/j5/a2a/AdjudicationDock.tsx create mode 100644 apps/web/src/j5/a2a/adjudicationDock.logic.test.ts create mode 100644 apps/web/src/j5/a2a/adjudicationDock.logic.ts diff --git a/FORK.md b/FORK.md index 01d917e8041e9..99077d4bfe751 100644 --- a/FORK.md +++ b/FORK.md @@ -294,6 +294,7 @@ Revision scope approved by Bryant on 2026-09-08 following Jacksondr5's PR #75 re | `apps/web/src/routes/settings.personas.tsx` (was `settings.agents.tsx` until the 2026-09-17 persona rename; the route is `/settings/personas` and the search entry keeps "agents" as a term), `components/settings/AgentSettingsPanel.tsx`, `SettingsSidebarNav.tsx`, `settingsSearch.ts` | Settings navigation/search registrations and the added environment-aware library view. | Keep the panel a thin mount of J5-owned `j5/agents/AgentLibrarySettings.tsx`, which owns folder/file picking and library actions. No editor or composer activation is introduced. Catalog error, empty, blocked, and available states must remain visible. Desktop inherits this web surface. The search-entry test lives in `apps/web/src/j5/agents/settingsSearch.test.ts`. | | `apps/mobile/src/Stack.tsx`, `features/settings/SettingsRouteScreen.tsx`, `SettingsAgentsRouteScreen.tsx`, `components/settings-sheet-targets.ts` | Mount J5-owned `j5/agents/AgentLibrarySettingsScreen.tsx` on iOS and Android at `/settings/personas`; `SettingsRouteScreen.tsx` appends one Agent Setup row (titled Personas before #743) to upstream's Automations section; `pickAgentDefinitions.ts` handles native folder/file access and foreground handoff. `SettingsSection.tsx` is unchanged; the library screen renders its own header row. | Preserve existing navigation and selected-environment routing; no separate persona catalog or policy logic. | | `apps/web/src/components/ChatView.tsx`, `components/chat/ChatComposer.tsx`, `apps/mobile/src/features/threads/ThreadComposer.tsx` | Pass the durable assignment to the composers; each composer renders the J5-owned `AgentPersonaAssignmentControl(s)` from `src/j5/agents/` in place of its model controls when an assignment exists. The web composer's `selectedModelSelection` also passes through J5-owned `composerModelSelectionForThread` (`src/j5/agents/personaComposerSelection.ts`, 2026-09-10) so a persona thread always sends its launch route: without it a remembered draft pick made every human message to a Captain fail with "has an immutable model route". | Ordinary tasks retain existing controls. Labels use the launch snapshot, never today's definition name; server enforcement remains authoritative. Keep the composer edit to the prop and the one conditional render. | +| `apps/web/src/components/ChatView.tsx` | One import and one element in the `threadProgressControl` fragment, beside `CrewRosterGate`: J5-owned `AdjudicationDock` (`src/j5/a2a/`) pins a Captain's open asks to the person above the composer (#747). It reads the Inbox's own list and answers with the Inbox's own command. | Keep the element beside `CrewRosterGate` in the same fragment. | | `components/chat/ThreadRelationshipsControl.tsx`, `components/chat/V2LifecycleRow.tsx` | Stack #84/#86 normalizes runtime-child labels separately from reusable Role definitions. Upstream deleted `AgentsPanel` (#12835); the concern now lives in lineage rows and subagent cards (`AgentRowIdentity`, mounted beside the row button). | Keep this concern separate from catalog loading. Preserve provider-native activity semantics, focused label/panel tests, and no continuous animation. | | `apps/web/src/routeTree.gen.ts`, `pnpm-lock.yaml` | Generated route registration and dependency resolution carried by the original stack. | Regenerate only with the normal tooling when inputs change. The library revision adds no dependency and does not hand-edit either file. | | `docs/README.md` | Navigation to the J5 persona guide, `docs/j5/user/personas.md`. | User docs describe product behavior; source paths and operational configuration are in `docs/j5/runbooks/persona-library.md`. | diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 9b6f38e252b45..234b5405858d9 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -48,6 +48,7 @@ import { TYPE_TO_FOCUS_EDITABLE_SELECTOR, TYPE_TO_FOCUS_FLOATING_LAYER_SELECTOR, } from "./chat/composerFocusRedirect"; +import { AdjudicationDock } from "../j5/a2a/AdjudicationDock"; import { CrewRosterGate } from "../j5/crew/CrewRosterGate"; import { useCanOperateThread } from "../j5/sharing/access"; import { sharedMessageTypedText } from "../j5/sharing/sharedTimeline"; @@ -8399,6 +8400,11 @@ export default function ChatView(props: ChatViewProps) { environmentId={activeThread.environmentId} threadId={activeThread.id} /> + >>({}); + const [expanded, setExpanded] = useState>(new Set()); + const [picked, setPicked] = useState(null); + const [pending, setPending] = useState(false); + const [error, setError] = useState(null); + const [refused, setRefused] = useState>([]); + const attempt = useRef<{ exchangeId: string; message: string; clientRequestId: string } | null>( + null, + ); + + const asks = adjudicationAsks({ + items: query.data?.items ?? [], + refused, + threadId, + hasWords: (exchangeId) => (answers[exchangeId] ?? "") !== "", + }); + const view = pickShownAsk(asks, picked); + if (!mayAnswer || environmentId === undefined || view === null) return null; + const { shown, others } = view; + const isOpen = (query.data?.items ?? []).some((item) => item.exchangeId === shown.exchangeId); + const message = answers[shown.exchangeId] ?? ""; + const urgency = urgencyBadge[shown.urgency]; + const openFor = formatElapsedDurationLabel(shown.openedAt); + const threadRef = threadId == null ? undefined : scopeThreadRef(environmentId, threadId); + + const answer = async () => { + if (message === "") return; + // A retry of the same words reuses its request id, so a lost reply cannot answer twice. + const request = + attempt.current?.exchangeId === shown.exchangeId && attempt.current.message === message + ? attempt.current + : { exchangeId: shown.exchangeId, message, clientRequestId: randomUUID() }; + attempt.current = request; + setPending(true); + setError(null); + try { + await answerHumanExchange(environmentId, request); + attempt.current = null; + notifyHumanInboxChanged(environmentId); + setAnswers(({ [shown.exchangeId]: _sent, ...rest }) => rest); + query.refresh(); + } catch (cause) { + if (isAskAlreadyClosed(cause)) { + setRefused((current) => [...current, shown]); + query.refresh(); + } else { + setError(cause instanceof Error ? cause.message : "Could not deliver the answer."); + } + } finally { + setPending(false); + } + }; + + return ( + + +
+
+ Question for you + {openFor ? · open {openFor} : null} + + {urgency.label} + +
+

{shown.intent}

+
+ +
+ {hasMoreThanExcerpt(shown.message) ? ( + + ) : null} +