From a4ef0a92d2e42b247cc8d9d6d01faf53c406affd Mon Sep 17 00:00:00 2001 From: Jackson Miller Date: Sun, 8 Nov 2026 23:36:03 -0500 Subject: [PATCH 1/3] feat(mobile): a Captain's questions for you pin above its composer web's adjudication dock does: the Inbox's own asks from this thread, answered through the Inbox's answer flow, shown only for a thread that commands a Crew. Membership is read through a mobile store over listCrewMemberships, re-read when the server's Crew revision moves; the dock's logic and the membership replace move to client-runtime, shared with web. Co-Authored-By: Claude Opus 5.5 --- FORK.md | 2 +- apps/mobile/src/j5/a2a/AdjudicationDock.tsx | 216 ++++++++++++++++++ .../src/j5/composer/J5ComposerControls.tsx | 8 +- apps/mobile/src/j5/crew/crewMemberships.ts | 54 +++++ apps/mobile/src/j5/crew/spawnedChildren.ts | 4 +- apps/web/src/j5/a2a/AdjudicationDock.tsx | 2 +- .../src/j5/crew/CrewMembershipsClient.test.ts | 34 +-- apps/web/src/j5/crew/CrewMembershipsClient.ts | 20 +- packages/client-runtime/package.json | 8 + .../src/j5/adjudicationDock.test.ts | 2 +- .../client-runtime/src/j5/adjudicationDock.ts | 3 +- .../src/j5/crewMemberships.test.ts | 34 +++ .../client-runtime/src/j5/crewMemberships.ts | 19 ++ 13 files changed, 349 insertions(+), 57 deletions(-) create mode 100644 apps/mobile/src/j5/a2a/AdjudicationDock.tsx create mode 100644 apps/mobile/src/j5/crew/crewMemberships.ts rename apps/web/src/j5/a2a/adjudicationDock.logic.test.ts => packages/client-runtime/src/j5/adjudicationDock.test.ts (98%) rename apps/web/src/j5/a2a/adjudicationDock.logic.ts => packages/client-runtime/src/j5/adjudicationDock.ts (96%) create mode 100644 packages/client-runtime/src/j5/crewMemberships.test.ts create mode 100644 packages/client-runtime/src/j5/crewMemberships.ts diff --git a/FORK.md b/FORK.md index 4b54e57b7140d..c9df6efaf7c74 100644 --- a/FORK.md +++ b/FORK.md @@ -549,7 +549,7 @@ migrations after upstream migrations. 113. Metro doesn't watch a worktree's `.j5code` folder ([#964](https://github.com/Jacksondr5/j5code/issues/964)). `apps/mobile/metro.config.js` watches the whole workspace and blocks only upstream's `.t3` state folder. J5's dev and test homes live in `.j5code`, so every server write there reached Metro's watcher and showed React Native's "Refreshing…" banner. One more `blockList` entry, beside upstream's, blocks it. Release bundles also go through Metro, but nothing the app imports lives in `.j5code`, so the entry only changes what the dev watcher reacts to. On a pin advance: if upstream moves or renames its `.t3` entry, keep `.j5code` beside it. -114. Mobile roster review for a Captain's Crew proposal ([#836](https://github.com/Jacksondr5/j5code/issues/836), Jackson's decisions 1 and 2 of 2026-11-07/08: a phone approves, declines and removes seats, showing each seat's access; other edits stay on web). `apps/mobile/src/features/threads/ThreadDetailScreen.tsx` mounts J5-owned `J5ComposerControls` (`apps/mobile/src/j5/composer/`) beside case 49's `PlaybookComposerControl`, under the same conditions; every J5 row above the composer joins there, not as another seam. Its first row, `CrewRosterStrip` (`apps/mobile/src/j5/crew/`), shows one row per open, human-approved proposal for the thread and opens the `ThreadCrewProposal` screen, which case 98's `j5ThreadRoutes` spread registers. The gate filter, seat lines, playbook notes and preview binding live in `packages/client-runtime/src/j5/crewProposals.ts` (a new `./j5/crew-proposals` export in `packages/client-runtime/package.json`), shared with web's card; approval sends only the token from a complete preview of the seats on screen. +114. Mobile roster review for a Captain's Crew proposal ([#836](https://github.com/Jacksondr5/j5code/issues/836), Jackson's decisions 1 and 2 of 2026-11-07/08: a phone approves, declines and removes seats, showing each seat's access; other edits stay on web). `apps/mobile/src/features/threads/ThreadDetailScreen.tsx` mounts J5-owned `J5ComposerControls` (`apps/mobile/src/j5/composer/`) beside case 49's `PlaybookComposerControl`, under the same conditions; every J5 row above the composer joins there, not as another seam. Its first row, `CrewRosterStrip` (`apps/mobile/src/j5/crew/`), shows one row per open, human-approved proposal for the thread and opens the `ThreadCrewProposal` screen, which case 98's `j5ThreadRoutes` spread registers. The gate filter, seat lines, playbook notes and preview binding live in `packages/client-runtime/src/j5/crewProposals.ts` (a new `./j5/crew-proposals` export in `packages/client-runtime/package.json`), shared with web's card; approval sends only the token from a complete preview of the seats on screen. Its second row, `AdjudicationDock` (`apps/mobile/src/j5/a2a/`), pins a Captain's open asks to the person, as web's dock does (#836 piece 6): the Inbox's own asks from this thread, answered through the Inbox's `useInboxAnswers`, shown only when `useCrewMembership` (`apps/mobile/src/j5/crew/crewMemberships.ts`, over case 115's `threadReadConnectionsAtom`, re-read whenever the server's Crew revision moves) says the thread commands a Crew. It has no attachments and no owner's clear action, since the mobile Inbox has neither. The dock's logic is `packages/client-runtime/src/j5/adjudicationDock.ts` and the membership replace is `crewMemberships.ts`, both shared with web and reached through the `./j5/adjudication-dock` and `./j5/crew-memberships` exports this case appends to upstream-owned `packages/client-runtime/package.json`. 115. Mobile lists a spawner's agents under its row (register D22, the mobile half of case 23; [#836](https://github.com/Jacksondr5/j5code/issues/836) decisions 3 and 4). `apps/mobile/src/features/threads/useThreadListV2.ts` passes its threads through J5-owned `useCrewListedThreads` (`apps/mobile/src/j5/crew/spawnedChildren.ts`), which keeps the spawned-children read (`j5.fleet.listSpawnedChildren`) current for every listed thread and drops the threads an agent spawned unless they are pinned, so every list, shelf and reorder computed after it sees the same rows. Mobile has no Fleet roster to bound re-reads by, so a moved `crew` or `fleet` revision re-reads that server's listed rows in one batched read. `apps/mobile/src/features/threads/thread-list-v2-items.tsx` mounts J5-owned `CaptainSeatsToggle` (`apps/mobile/src/j5/crew/CaptainSeats.tsx`) inside the card row's bottom line, before the pull request badge, and inside the slim row before its time, so a collapsed spawner is no taller; and it mounts `CaptainSeats` after the row's swipeable, outside its long-press menu, handing it upstream's own `STATUS_LABEL_BY_STATUS` so seat rows read as rows do. The expanded seats show each Crew's summary, Stop crew while a seat is running, "Not started", and "Replaced by". The grouping, the membership rule and the Crew state labels moved from web to `packages/client-runtime/src/j5/spawnedChildren.ts` and `crewState.ts`, reached through the `./j5/spawned-children` and `./j5/crew-state` exports this case adds to `packages/client-runtime/package.json`. Its test mocks the hook as a passthrough, since the hook reads server connections. On a pin advance: keep the one wrap at the top of `useThreadListV2`, the toggle inside both row layouts, and the seats outside the swipeable. diff --git a/apps/mobile/src/j5/a2a/AdjudicationDock.tsx b/apps/mobile/src/j5/a2a/AdjudicationDock.tsx new file mode 100644 index 0000000000000..87e4b8cc4b68f --- /dev/null +++ b/apps/mobile/src/j5/a2a/AdjudicationDock.tsx @@ -0,0 +1,216 @@ +import { useAtomValue } from "@effect/atom-react"; +import { scopeThreadRef } from "@t3tools/client-runtime/environment"; +import { + adjudicationAsks, + commandsACrew, + hasMoreThanExcerpt, + pickShownAsk, +} from "@t3tools/client-runtime/j5/adjudication-dock"; +import { closedLine, mergeHumanInboxSources } from "@t3tools/client-runtime/j5/inbox"; +import type { EnvironmentId, ThreadId } from "@t3tools/contracts"; +import { useState } from "react"; +import { Pressable, ScrollView, View } from "react-native"; + +import { SymbolView } from "../../components/ui/AppSymbol"; +import { AppText as Text, AppTextInput as TextInput } from "../../components/ui/AppText"; +import { Button } from "../../components/ui/Button"; +import { useMarkdownPreviewStyles } from "../../features/files/FileMarkdownPreview"; +import { relativeTime } from "../../lib/time"; +import { SelectableMarkdownText } from "../../native/SelectableMarkdownText"; +import { useCrewMembership } from "../crew/crewMemberships"; +import { useInboxAnswers } from "../inbox/inboxAnswers"; +import { answeredInboxSourcesAtom, openInboxSourcesAtom } from "../inbox/inboxSources"; +import { j5Sharing } from "../sharing/guestAccess"; +import { j5Environment } from "../state"; + +const URGENCY = { + blocking: { label: "Blocking", className: "text-danger-foreground" }, + soon: { label: "Soon", className: "text-warning-foreground" }, + fyi: { label: "FYI", className: "text-foreground-muted" }, +} as const; + +/** + * A Captain's open asks to the person, pinned above its composer as web's dock is. They are the + * Inbox's own asks, answered through the same command, so answering here or there closes the one + * Exchange (Crews: adjudication request). Only a Captain's asks are pinned; others stay in the Inbox. + */ +export function AdjudicationDock(props: { + readonly environmentId: EnvironmentId; + readonly threadId: ThreadId; +}) { + const membership = useCrewMembership(scopeThreadRef(props.environmentId, props.threadId)); + // The Inbox is read only for a Captain's thread. + return commandsACrew(membership) ? : null; +} + +function CaptainAsks(props: { + readonly environmentId: EnvironmentId; + readonly threadId: ThreadId; +}) { + const { environmentId, threadId } = props; + const openSources = useAtomValue(openInboxSourcesAtom); + const answeredSources = useAtomValue(answeredInboxSourcesAtom); + const ofThisThread = (items: ReturnType) => + items.filter((item) => item.environmentId === environmentId); + const answers = useInboxAnswers({ + openSources, + items: ofThisThread(mergeHumanInboxSources(openSources)), + answeredSources, + answered: ofThisThread(mergeHumanInboxSources(answeredSources)), + }); + const mayAnswer = useAtomValue(j5Environment.answerHumanExchange.permissionAtom(environmentId)); + const access = useAtomValue(j5Sharing.connectionAccess(environmentId)); + const styles = useMarkdownPreviewStyles(); + const [open, setOpen] = useState(false); + const [full, setFull] = useState(false); + const [picked, setPicked] = useState(null); + + // An ask that closed while the person had typed into it stays, with who answered (Inbox AC17). + const asks = adjudicationAsks({ + items: answers.shownItems, + refused: [], + threadId, + hasWords: () => true, + }); + const view = pickShownAsk(asks, picked); + if (!mayAnswer || view === null) return null; + const { shown, others } = view; + const urgency = URGENCY[shown.urgency]; + const closed = answers.closedOf(shown); + const closedText = + closed === undefined + ? null + : closedLine({ ...closed, ownName: access?.kind === "person" ? access.name : null }); + const text = answers.answerText(shown); + const delivering = answers.pendingKey !== null; + const error = answers.errorFor(shown); + const longer = + hasMoreThanExcerpt(shown.message) || + (shown.followUps?.length ?? 0) > 0 || + shown.escalation !== undefined || + shown.personaDraft !== undefined; + const markdown = (value: string) => ( + + ); + + return ( + + + setOpen((value) => !value)} + className="min-h-11 flex-row items-center gap-2" + > + + + + Question for you · open {relativeTime(shown.openedAt)} + + + {shown.intent} + + + + {urgency.label} + + + + {open ? ( + + + + {markdown(shown.message)} + {[shown.escalation?.summary, shown.personaDraft?.summary].map((record) => + record === undefined ? null : ( + // J5's own record, apart from the agent's words; plain text, so they can't alter it. + + + Recorded by J5 + + {record} + + ), + )} + {shown.followUps?.map((followUp) => ( + + Follow-up + {markdown(followUp.message)} + + ))} + + + {longer ? ( + setFull((value) => !value)} + > + + {full ? "Show less" : "Show full question"} + + + ) : null} + answers.setAnswerText(shown, value)} + style={{ minHeight: 44, maxHeight: 120, textAlignVertical: "top" }} + /> + {error === null ? null : ( + + {error} + + )} + + {closedText !== null ? ( + {closedText} + ) : ( + diff --git a/packages/client-runtime/src/j5/adjudicationDock.test.ts b/packages/client-runtime/src/j5/adjudicationDock.test.ts index 8e88078a512ed..2a6ca358f7f11 100644 --- a/packages/client-runtime/src/j5/adjudicationDock.test.ts +++ b/packages/client-runtime/src/j5/adjudicationDock.test.ts @@ -65,6 +65,19 @@ it("shows the oldest ask in full, or the one the person picked while it is still ]); expect(pickShownAsk(asks, "second")?.shown.exchangeId).toBe("second"); expect(pickShownAsk(asks, "gone")?.shown.exchangeId).toBe("first"); + expect(pickShownAsk([ask("only")], null)?.next).toBeNull(); +}); + +it("moves through every pinned ask from the more-questions row, wrapping to the oldest", () => { + const asks = [ask("first"), ask("second"), ask("third")]; + const visited: Array = []; + let picked: string | null = null; + for (let step = 0; step < 4; step += 1) { + const view: ReturnType> = pickShownAsk(asks, picked); + visited.push(view!.shown.exchangeId); + picked = view!.next!.exchangeId; + } + expect(visited).toEqual(["first", "second", "third", "first"]); }); it("offers the full question only for a body longer than the three-line excerpt", () => { diff --git a/packages/client-runtime/src/j5/adjudicationDock.ts b/packages/client-runtime/src/j5/adjudicationDock.ts index e9e1359dcd80f..3c70cd4cdfd0b 100644 --- a/packages/client-runtime/src/j5/adjudicationDock.ts +++ b/packages/client-runtime/src/j5/adjudicationDock.ts @@ -42,16 +42,29 @@ export function adjudicationAsks(input: { } /** - * The ask shown in full, and the rest behind the "more questions" row. The person's pick wins - * while it is still pinned; otherwise the oldest. + * The ask shown in full, the rest behind the "more questions" row, and the one that row moves to: + * the next after the shown ask, wrapping, so every ask is reachable. The person's pick wins while + * it is still pinned; otherwise the oldest. */ export function pickShownAsk( asks: ReadonlyArray, pickedExchangeId: string | null, -): { readonly shown: Ask; readonly others: ReadonlyArray } | null { - const shown = asks.find((ask) => ask.exchangeId === pickedExchangeId) ?? asks[0]; +): { + readonly shown: Ask; + readonly others: ReadonlyArray; + readonly next: Ask | null; +} | null { + const index = Math.max( + 0, + asks.findIndex((ask) => ask.exchangeId === pickedExchangeId), + ); + const shown = asks[index]; if (shown === undefined) return null; - return { shown, others: asks.filter((ask) => ask !== shown) }; + return { + shown, + others: asks.filter((ask) => ask !== shown), + next: asks.length > 1 ? asks[(index + 1) % asks.length]! : null, + }; } /** The refusals that mean someone else's answer, or the agent's withdrawal, closed the ask first. */ From d6c168a7151793f3748760959620ff0a10009312 Mon Sep 17 00:00:00 2001 From: Jackson Miller Date: Mon, 9 Nov 2026 03:48:15 -0500 Subject: [PATCH 3/3] fix(mobile): each pinned ask measures its own question when the dock switches Co-Authored-By: Claude Opus 5.5 --- apps/mobile/src/j5/a2a/AdjudicationDock.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/mobile/src/j5/a2a/AdjudicationDock.tsx b/apps/mobile/src/j5/a2a/AdjudicationDock.tsx index b63f76f1628e5..f6ff6c5181265 100644 --- a/apps/mobile/src/j5/a2a/AdjudicationDock.tsx +++ b/apps/mobile/src/j5/a2a/AdjudicationDock.tsx @@ -128,6 +128,8 @@ function CaptainAsks(props: { {open ? (