diff --git a/FORK.md b/FORK.md index 8b844153ab48f..c095f397d2608 100644 --- a/FORK.md +++ b/FORK.md @@ -251,7 +251,7 @@ Upstream settings sections no longer accept a `description` prop; J5 library pan `apps/server/src/orchestration-v2/ThreadMessageIntake.ts` treats the J5 `resolve-agent-persona` launch refusal as pre-dispatch failure and releases claimed uploads; the pending upload remains available for retry. -Bryant requested a shared agent picker for Codex and Claude, invoking a saved agent as a subagent within the current conversation. This is a narrow exception to the earlier native-only Subagent steering: the child uses the existing delegated-child engine with `lineage.relationshipToParent = subagent`. Its child thread is backing storage, not a top-level Peer Agent. Ordinary native subagent requests and `j5_spawn_agent` retain their existing meanings; `j5_spawn_agent`'s optional `agent` input (2026-09-09) resolves a saved agent into a Peer Agent's immutable assignment entirely inside `apps/server/src/j5/agents/agentPersonaSpawn.ts` and the J5 toolkit handlers, with no further upstream hook. Proposal-driven Crews use ordinary conversation. The former `/crew` send-path wrapper in `ChatView.tsx` and slash-menu spread in `ChatComposer.tsx` are removed; case 8's standing instructions guide the agent to propose a roster, including custom members, and wait for the person's decision before launching. The platform's `` decisions render as notices through case 7's `renderThreadA2ADelivery` call: J5-owned `apps/web/src/j5/crew/CrewNoticeRenderer.tsx` draws them, the shared parser in `packages/client-runtime/src/j5/crewNotices.ts` recognizes the tagged blocks strictly (anything unparsed stays raw), and the call passes the thread and markdown folder from `TimelineRowCtx`, so a seat opens its thread and the brief renders as markdown (2026-09-16). Mobile has no delivery seam and shows these notices in upstream's rows, as it does A2A deliveries. `ChatView.tsx` passes J5-owned `CrewRosterGate` (`apps/web/src/j5/crew/CrewRosterGate.tsx`) through the existing `ChatComposer.threadProgressControl` slot alongside Playbooks. It uses upstream’s `ComposerBanner` attachment and expands from a compact strip above the Captain’s composer; Add/Edit member dialogs stay outside the composer’s focus flow. The slot is hidden while a blocking tool approval or question is open, so the proposal disappears meanwhile; the person's saved roster edits live in J5-owned `apps/web/src/j5/crew/crewProposalDraftStore.ts` (keyed by environment and proposal, cleared when the proposal is approved or declined) and are restored when the gate returns. Mid-run seat additions stay on the inbox bell (`crewProposals.logic.ts` decides which is which). The human gate (open proposals, approve with edited seats, decline) lives entirely in J5 files: `apps/web/src/j5/crew/`, the J5 inbox page and bell, and the list, preview and resolve RPCs (case 64). One adapter append makes the gate reachable from Claude: `claudeMcpQueryOverrides` in `apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts` spreads J5-owned `J5_CLAUDE_MCP_ALLOWED_TOOLS` (`apps/server/src/j5/a2a/mcp/claudeAllowedTools.ts`) into the read-only pre-approval list, because Claude runs read-only personas in `dontAsk` mode and would otherwise deny every J5 coordination tool; the upstream `CLAUDE_READ_ONLY_T3_MCP_ALLOWED_TOOLS` constant and its toolkit cross-check stay untouched, and the two exact-allowlist assertions in `ClaudeAdapterV2.test.ts` include the J5 spread. The Codex counterpart is one spread in `codexThreadRuntimeParams` (`apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts`, private to that file since the 2026-10-24 advance): upstream's injected `"mcp_servers.t3-code"` entry gains J5-owned `J5_CODEX_T3_MCP_SERVER_CONFIG` (`apps/server/src/j5/a2a/mcp/codexToolApproval.ts`; since 2026-09-14 a per-tool `tools..approval_mode = "approve"` map naming the J5 verbs plus `j5_write_artifact` (a saved agent's declared handoff artifact lives in application storage, never the workspace) and, since 2026-09-15, the provider-native Subagent verbs `delegate_task`, `task_status`, and `task_cancel` (a Crew member refused `j5_spawn_agent` is sent there), never a server-wide default, so worktree handoff, browser preview, and scheduling keep Codex's own verdict for read-only personas), because Codex 0.153+ rejects every non-read-only MCP tool under approval policy `never` with "MCP tool call requires approval, but approval policy is never"; that policy is what full-access mode and every saved-agent runtime policy send, so without the spread `j5_send_message`, `j5_spawn_agent`, and `j5_propose_crew` all fail on Codex. The full spread applies when the thread's resolved approval policy is `never` (`j5ApprovalPolicyIsNever`). Since 2026-09-24 both appends draw their names from one J5 leaf module, `apps/server/src/j5/a2a/mcp/j5ToolPreapproval.ts` (`J5_PREAPPROVED_TOOLS`, the interactive-mode `J5_COORDINATION_TOOLS`, and `j5PreapprovedTools(runtimePolicy)`), so Codex and Claude, the two harnesses J5 pre-approves its tools on (Jackson's ruling on #233), pre-approve the same set. Interactive modes pre-approve only routine messaging and the crew proposal/request tools. Pre-approval is the Captain's own staffing decision: a roster waits for the person unless the project's Crew approval is automatic (#743), and a Captain's addition (`j5_request_crew_member`) is automatic. A member's access defaults to Full access unless the Captain sets one, so a Supervised Captain can start a Full-access custom member without review; Jackson accepted that (2026-10-31). The Agent Setup approval setting governs rosters only; additions are always automatic. Other tools retain Codex's prompting. The ten upstream tools admitted on 2026-10-08 (case 4) are not in J5's pre-approval lists; they keep each harness's own verdict, and upstream's Claude read-only list already carries `html_preview` and `html_render`. The expected thread config in `CodexAdapterV2.test.ts` includes the spread. +Bryant requested a shared agent picker for Codex and Claude, invoking a saved agent as a subagent within the current conversation. This is a narrow exception to the earlier native-only Subagent steering: the child uses the existing delegated-child engine with `lineage.relationshipToParent = subagent`. Its child thread is backing storage, not a top-level Peer Agent. Ordinary native subagent requests and `j5_spawn_agent` retain their existing meanings; `j5_spawn_agent`'s optional `agent` input (2026-09-09) resolves a saved agent into a Peer Agent's immutable assignment entirely inside `apps/server/src/j5/agents/agentPersonaSpawn.ts` and the J5 toolkit handlers, with no further upstream hook. Proposal-driven Crews use ordinary conversation. The former `/crew` send-path wrapper in `ChatView.tsx` and slash-menu spread in `ChatComposer.tsx` are removed; case 8's standing instructions guide the agent to propose a roster, including custom members, and wait for the person's decision before launching. The platform's `` decisions render as notices through case 7's `renderThreadA2ADelivery` call: J5-owned `apps/web/src/j5/crew/CrewNoticeRenderer.tsx` draws them, the shared parser in `packages/client-runtime/src/j5/crewNotices.ts` recognizes the tagged blocks strictly (anything unparsed stays raw), and the call passes the thread and markdown folder from `TimelineRowCtx`, so a seat opens its thread and the brief renders as markdown (2026-09-16). Mobile has no delivery seam and shows these notices in upstream's rows, as it does A2A deliveries. `ChatView.tsx` passes J5-owned `CrewRosterGate` (`apps/web/src/j5/crew/CrewRosterGate.tsx`) through the existing `ChatComposer.threadProgressControl` slot alongside Playbooks. It uses upstream’s `ComposerBanner` attachment and expands from a compact strip above the Captain’s composer; Add/Edit member dialogs stay outside the composer’s focus flow. The slot is hidden while a blocking tool approval or question is open, so the proposal disappears meanwhile; the person's saved roster edits live in J5-owned `apps/web/src/j5/crew/crewProposalDraftStore.ts` (keyed by environment and proposal, cleared when the proposal is approved or declined) and are restored when the gate returns. Mid-run seat additions stay on the inbox bell (`crewProposals.logic.ts` decides which is which). The same fragment mounts J5-owned `AdjudicationDock` (`apps/web/src/j5/a2a/AdjudicationDock.tsx`) beside it: a Captain's open ask to the person, pinned above its composer, shown only for a thread that commands a Crew and answered with the Inbox's own command (#747). It changes nothing about what the composer does. The human gate (open proposals, approve with edited seats, decline) lives entirely in J5 files: `apps/web/src/j5/crew/`, the J5 inbox page and bell, and the list, preview and resolve RPCs (case 64). One adapter append makes the gate reachable from Claude: `claudeMcpQueryOverrides` in `apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts` spreads J5-owned `J5_CLAUDE_MCP_ALLOWED_TOOLS` (`apps/server/src/j5/a2a/mcp/claudeAllowedTools.ts`) into the read-only pre-approval list, because Claude runs read-only personas in `dontAsk` mode and would otherwise deny every J5 coordination tool; the upstream `CLAUDE_READ_ONLY_T3_MCP_ALLOWED_TOOLS` constant and its toolkit cross-check stay untouched, and the two exact-allowlist assertions in `ClaudeAdapterV2.test.ts` include the J5 spread. The Codex counterpart is one spread in `codexThreadRuntimeParams` (`apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts`, private to that file since the 2026-10-24 advance): upstream's injected `"mcp_servers.t3-code"` entry gains J5-owned `J5_CODEX_T3_MCP_SERVER_CONFIG` (`apps/server/src/j5/a2a/mcp/codexToolApproval.ts`; since 2026-09-14 a per-tool `tools..approval_mode = "approve"` map naming the J5 verbs plus `j5_write_artifact` (a saved agent's declared handoff artifact lives in application storage, never the workspace) and, since 2026-09-15, the provider-native Subagent verbs `delegate_task`, `task_status`, and `task_cancel` (a Crew member refused `j5_spawn_agent` is sent there), never a server-wide default, so worktree handoff, browser preview, and scheduling keep Codex's own verdict for read-only personas), because Codex 0.153+ rejects every non-read-only MCP tool under approval policy `never` with "MCP tool call requires approval, but approval policy is never"; that policy is what full-access mode and every saved-agent runtime policy send, so without the spread `j5_send_message`, `j5_spawn_agent`, and `j5_propose_crew` all fail on Codex. The full spread applies when the thread's resolved approval policy is `never` (`j5ApprovalPolicyIsNever`). Since 2026-09-24 both appends draw their names from one J5 leaf module, `apps/server/src/j5/a2a/mcp/j5ToolPreapproval.ts` (`J5_PREAPPROVED_TOOLS`, the interactive-mode `J5_COORDINATION_TOOLS`, and `j5PreapprovedTools(runtimePolicy)`), so Codex and Claude, the two harnesses J5 pre-approves its tools on (Jackson's ruling on #233), pre-approve the same set. Interactive modes pre-approve only routine messaging and the crew proposal/request tools. Pre-approval is the Captain's own staffing decision: a roster waits for the person unless the project's Crew approval is automatic (#743), and a Captain's addition (`j5_request_crew_member`) is automatic. A member's access defaults to Full access unless the Captain sets one, so a Supervised Captain can start a Full-access custom member without review; Jackson accepted that (2026-10-31). The Agent Setup approval setting governs rosters only; additions are always automatic. Other tools retain Codex's prompting. The ten upstream tools admitted on 2026-10-08 (case 4) are not in J5's pre-approval lists; they keep each harness's own verdict, and upstream's Claude read-only list already carries `html_preview` and `html_render`. The expected thread config in `CodexAdapterV2.test.ts` includes the spread. `packages/client-runtime/src/state/models.ts` accepts a status-only runtime in `threadRuntimeIsActive`; J5 crew state reuses that exported predicate without importing the upstream-private status helper. Preserve this narrow input contract when carrying crew reads forward. 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))); + }), +); diff --git a/apps/server/src/j5/a2a/crewGateNotice.test.ts b/apps/server/src/j5/a2a/crewGateNotice.test.ts index 4a4c3c4a715e2..b0cc00fd1ecb4 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 63d67a7c31f93..3742fd93e35a6 100644 --- a/apps/server/src/j5/a2a/crewGateNotice.ts +++ b/apps/server/src/j5/a2a/crewGateNotice.ts @@ -211,14 +211,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/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 22a35480b98cc..f22d7ed9a0902 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -356,6 +356,7 @@ import { observeResize } from "~/lib/observeResize"; import { ThreadVisitWatermark } from "./chat/ThreadVisitWatermark"; import { ChatTerminalDrawers } from "./chat/ChatTerminalDrawers"; import { ChatRightPanel } from "./chat/ChatRightPanel"; +import { AdjudicationDock } from "../j5/a2a/AdjudicationDock"; import { CrewRosterGate } from "../j5/crew/CrewRosterGate"; import { composerProviderCandidates } from "../j5/agents/personaComposerSelection"; import { useDraftAgentAssignment } from "../j5/agents/useDraftAgentAssignment"; @@ -3552,6 +3553,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 (!captain || !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((current) => + Object.fromEntries(Object.entries(current).filter(([id]) => id !== shown.exchangeId)), + ); + 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."); + } + } + setPending(false); + }; + + return ( + + +
+
+ Question for you + {openFor ? · open {openFor} : null} + + {urgency.label} + +
+

{shown.intent}

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