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..f6ff6c5181265
--- /dev/null
+++ b/apps/mobile/src/j5/a2a/AdjudicationDock.tsx
@@ -0,0 +1,222 @@
+import { useAtomValue } from "@effect/atom-react";
+import { scopeThreadRef } from "@t3tools/client-runtime/environment";
+import {
+ adjudicationAsks,
+ commandsACrew,
+ 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";
+
+/** About three lines of the question while the dock is opened but not in full. */
+const EXCERPT_HEIGHT = 72;
+
+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 ofThisEnvironment = (items: ReturnType) =>
+ items.filter((item) => item.environmentId === environmentId);
+ const answers = useInboxAnswers({
+ openSources,
+ items: ofThisEnvironment(mergeHumanInboxSources(openSources)),
+ answeredSources,
+ answered: ofThisEnvironment(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);
+ // The ask whose question runs past the excerpt's height.
+ const [overflowing, setOverflowing] = 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, next: nextAsk } = 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);
+ // Measured, not counted: a few short lines can still wrap past the excerpt on a phone.
+ const longer = full || overflowing === shown.exchangeId;
+ 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 ? (
+
+
+ setOverflowing(height > EXCERPT_HEIGHT ? shown.exchangeId : null)
+ }
+ >
+
+ {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}
+ ) : (
+
+
+ ) : null}
+ {nextAsk !== null ? (
+ {
+ setPicked(nextAsk.exchangeId);
+ setFull(false);
+ }}
+ className="min-h-9 flex-row items-center gap-1 border-t border-border-subtle"
+ >
+
+ {others.length} more {others.length === 1 ? "question" : "questions"}
+
+
+ · {nextAsk.intent}
+
+
+
+ ) : null}
+
+
+ );
+}
diff --git a/apps/mobile/src/j5/composer/J5ComposerControls.tsx b/apps/mobile/src/j5/composer/J5ComposerControls.tsx
index 1939ce66066f7..d0ac33aef4203 100644
--- a/apps/mobile/src/j5/composer/J5ComposerControls.tsx
+++ b/apps/mobile/src/j5/composer/J5ComposerControls.tsx
@@ -1,5 +1,6 @@
import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
+import { AdjudicationDock } from "../a2a/AdjudicationDock";
import { CrewRosterStrip } from "../crew/CrewRosterStrip";
/**
@@ -7,5 +8,10 @@ import { CrewRosterStrip } from "../crew/CrewRosterStrip";
* J5 control (a Crew's roster review, the adjudication dock) joins here without another seam.
*/
export function J5ComposerControls(props: { environmentId: EnvironmentId; threadId: ThreadId }) {
- return ;
+ return (
+ <>
+
+
+ >
+ );
}
diff --git a/apps/mobile/src/j5/crew/crewMemberships.ts b/apps/mobile/src/j5/crew/crewMemberships.ts
new file mode 100644
index 0000000000000..2344068fe5e85
--- /dev/null
+++ b/apps/mobile/src/j5/crew/crewMemberships.ts
@@ -0,0 +1,54 @@
+import { useAtomValue } from "@effect/atom-react";
+import { scopedThreadKey, scopeThreadRef } from "@t3tools/client-runtime/environment";
+import { replaceCrewMemberships } from "@t3tools/client-runtime/j5/crew-memberships";
+import { createScopedThreadReadStore } from "@t3tools/client-runtime/j5/scopedThreadReadStore";
+import type { ScopedThreadRef } from "@t3tools/contracts";
+import type { CrewMembershipEntry, ThreadCrewMembership } from "@t3tools/contracts/j5";
+import * as Cause from "effect/Cause";
+import { Atom } from "effect/reactivity";
+import { useEffect, useSyncExternalStore } from "react";
+
+import { appAtomRegistry } from "../../state/atom-registry";
+import { j5Environment } from "../state";
+import { threadReadConnectionsAtom } from "./spawnedChildren";
+
+const store = createScopedThreadReadStore({
+ load: async (environmentId, threadIds) => {
+ const result = await j5Environment.listCrewMemberships.run(appAtomRegistry, {
+ environmentId,
+ input: { threadIds },
+ });
+ if (result._tag === "Failure") throw Cause.squash(result.cause);
+ return result.value.entries;
+ },
+ replace: replaceCrewMemberships,
+});
+
+const NO_REVISION = Atom.make(null).pipe(
+ Atom.withLabel("mobile-j5:no-crew-revision"),
+);
+
+/**
+ * One thread's Crew membership, read when it is first shown and again whenever its server says
+ * a Crew changed, so a thread that becomes a Captain while open learns it. Undefined until read,
+ * and for a thread in no Crew.
+ */
+export function useCrewMembership(
+ ref: ScopedThreadRef | undefined,
+): ThreadCrewMembership | undefined {
+ const connections = useAtomValue(threadReadConnectionsAtom);
+ const environmentId = ref?.environmentId;
+ const threadId = ref?.threadId;
+ const crewRevision = useAtomValue(
+ environmentId === undefined ? NO_REVISION : j5Environment.rereadOn("crew")({ environmentId }),
+ );
+ // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- asks the server for this thread's Crew membership, and again when its Crew revision moves.
+ useEffect(() => {
+ store.setConnections(connections);
+ if (environmentId !== undefined && threadId !== undefined)
+ store.request([scopeThreadRef(environmentId, threadId)], true);
+ // oxlint-disable-next-line react/exhaustive-effect-dependencies -- a moved Crew revision re-reads the membership.
+ }, [connections, crewRevision, environmentId, threadId]);
+ const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
+ return ref === undefined ? undefined : snapshot.get(scopedThreadKey(ref));
+}
diff --git a/apps/mobile/src/j5/crew/spawnedChildren.ts b/apps/mobile/src/j5/crew/spawnedChildren.ts
index 6e5971ce40b3e..2207355226e10 100644
--- a/apps/mobile/src/j5/crew/spawnedChildren.ts
+++ b/apps/mobile/src/j5/crew/spawnedChildren.ts
@@ -38,7 +38,7 @@ const store = createScopedThreadReadStore {
+export const threadReadConnectionsAtom = Atom.make((get) => {
const connections = new Map();
for (const id of get(environmentCatalog.catalogValueAtom).entries.keys()) {
const state = Option.getOrNull(AsyncResult.value(get(environmentCatalog.stateAtom(id))));
@@ -47,7 +47,7 @@ const threadReadConnectionsAtom = Atom.make((get) => {
connections.set(id, readable ? Option.getOrNull(prepared) : null);
}
return connections;
-}).pipe(Atom.withLabel("mobile-j5:spawned-children-connections"));
+}).pipe(Atom.withLabel("mobile-j5:thread-read-connections"));
/** Each environment's Crew and Fleet revisions; a moved pair means placements may have changed. */
const placementRevisionsAtom = Atom.make((get) => {
diff --git a/apps/web/src/j5/a2a/AdjudicationDock.tsx b/apps/web/src/j5/a2a/AdjudicationDock.tsx
index 0ce9e74fb8dd0..b92952e708414 100644
--- a/apps/web/src/j5/a2a/AdjudicationDock.tsx
+++ b/apps/web/src/j5/a2a/AdjudicationDock.tsx
@@ -21,7 +21,7 @@ import {
hasMoreThanExcerpt,
isAskAlreadyClosed,
pickShownAsk,
-} from "./adjudicationDock.logic";
+} from "@t3tools/client-runtime/j5/adjudication-dock";
import {
AnswerAttachButton,
AnswerAttachmentList,
@@ -87,7 +87,7 @@ export function AdjudicationDock(props: {
});
const view = pickShownAsk(asks, picked);
if (!captain || !mayAnswer || environmentId === undefined || view === null) return null;
- const { shown, others } = view;
+ const { shown, others, next: nextAsk } = view;
const isOpen = (query.data?.items ?? []).some((item) => item.exchangeId === shown.exchangeId);
const message = answers[shown.exchangeId] ?? "";
const urgency = urgencyBadge[shown.urgency];
@@ -254,10 +254,10 @@ export function AdjudicationDock(props: {
)}
- {others.length > 0 ? (
+ {nextAsk !== null ? (
diff --git a/apps/web/src/j5/crew/CrewMembershipsClient.test.ts b/apps/web/src/j5/crew/CrewMembershipsClient.test.ts
index f64f6ac698cf8..5ab49fbbdb89c 100644
--- a/apps/web/src/j5/crew/CrewMembershipsClient.test.ts
+++ b/apps/web/src/j5/crew/CrewMembershipsClient.test.ts
@@ -1,12 +1,6 @@
import { expect, it } from "@effect/vitest";
-import { scopedThreadKey, scopeThreadRef } from "@t3tools/client-runtime/environment";
-import { EnvironmentId, ThreadId } from "@t3tools/contracts";
-import {
- presentCrewMembership,
- replaceCrewMemberships,
- type ThreadCrewMembership,
-} from "./CrewMembershipsClient";
+import { presentCrewMembership } from "./CrewMembershipsClient";
const live = { crewInstanceId: "crew:1", crewName: "Review Pair" };
@@ -25,29 +19,3 @@ it("labels members by seat and captains by the crews they command", () => {
).toEqual({ kind: "captain", title: "Commands Review Pair, Second" });
expect(presentCrewMembership({ kind: "captain", crews: [] })).toBeNull();
});
-
-it("treats the visible rows as the whole truth when replacing memberships, per environment", () => {
- const environmentId = EnvironmentId.make("env:a");
- const other = EnvironmentId.make("env:b");
- const key = (id: string, env = environmentId) =>
- scopedThreadKey(scopeThreadRef(env, ThreadId.make(id)));
- const stale = ThreadId.make("thread:stale");
- const fresh = ThreadId.make("thread:fresh");
- const membership: ThreadCrewMembership = { kind: "member", seat: "builder", crew: live };
- const previous = new Map([
- [key("thread:stale"), membership],
- [key("thread:kept"), membership],
- // The same local id on another environment is a different thread and stays untouched.
- [key("thread:stale", other), membership],
- ]);
- const next = replaceCrewMemberships(
- previous,
- environmentId,
- [stale, fresh],
- [{ threadId: fresh, membership: { kind: "captain", crews: [live] } }],
- );
- expect([...next.keys()].toSorted()).toEqual(
- [key("thread:fresh"), key("thread:kept"), key("thread:stale", other)].toSorted(),
- );
- expect(previous.size).toBe(3);
-});
diff --git a/apps/web/src/j5/crew/CrewMembershipsClient.ts b/apps/web/src/j5/crew/CrewMembershipsClient.ts
index 8503ebc4f587e..dd9a276a51bc4 100644
--- a/apps/web/src/j5/crew/CrewMembershipsClient.ts
+++ b/apps/web/src/j5/crew/CrewMembershipsClient.ts
@@ -1,7 +1,8 @@
import type { PreparedConnection } from "@t3tools/client-runtime/connection";
-import { scopedThreadKey, scopeThreadRef } from "@t3tools/client-runtime/environment";
+import { scopedThreadKey } from "@t3tools/client-runtime/environment";
+import { replaceCrewMemberships } from "@t3tools/client-runtime/j5/crew-memberships";
import { createScopedThreadReadStore } from "@t3tools/client-runtime/j5/scopedThreadReadStore";
-import type { EnvironmentId, ScopedThreadRef, ThreadId } from "@t3tools/contracts";
+import type { EnvironmentId, ScopedThreadRef } from "@t3tools/contracts";
import type { CrewMembershipEntry, ThreadCrewMembership } from "@t3tools/contracts/j5";
import * as Cause from "effect/Cause";
import { useSyncExternalStore } from "react";
@@ -35,21 +36,6 @@ export function presentCrewMembership(
};
}
-/** The visible rows are the whole truth: a thread that left every Crew loses its chip on the next read. */
-export const replaceCrewMemberships = (
- previous: ReadonlyMap,
- environmentId: EnvironmentId,
- requested: ReadonlyArray,
- entries: ReadonlyArray,
-) => {
- const next = new Map(previous);
- for (const threadId of requested)
- next.delete(scopedThreadKey(scopeThreadRef(environmentId, threadId)));
- for (const entry of entries)
- next.set(scopedThreadKey(scopeThreadRef(environmentId, entry.threadId)), entry.membership);
- return next;
-};
-
const store = createScopedThreadReadStore({
load: async (environmentId, threadIds) => {
const result = await j5Environment.listCrewMemberships.run(appAtomRegistry, {
diff --git a/packages/client-runtime/package.json b/packages/client-runtime/package.json
index 8512ac20d0e01..b284e0701bc63 100644
--- a/packages/client-runtime/package.json
+++ b/packages/client-runtime/package.json
@@ -527,6 +527,14 @@
"types": "./src/j5/spawnedChildren.ts",
"default": "./src/j5/spawnedChildren.ts"
},
+ "./j5/crew-memberships": {
+ "types": "./src/j5/crewMemberships.ts",
+ "default": "./src/j5/crewMemberships.ts"
+ },
+ "./j5/adjudication-dock": {
+ "types": "./src/j5/adjudicationDock.ts",
+ "default": "./src/j5/adjudicationDock.ts"
+ },
"./pull-request-project-filter": {
"types": "./src/pullRequestProjectFilter.ts",
"default": "./src/pullRequestProjectFilter.ts"
diff --git a/apps/web/src/j5/a2a/adjudicationDock.logic.test.ts b/packages/client-runtime/src/j5/adjudicationDock.test.ts
similarity index 84%
rename from apps/web/src/j5/a2a/adjudicationDock.logic.test.ts
rename to packages/client-runtime/src/j5/adjudicationDock.test.ts
index 9345eb3a3db20..2a6ca358f7f11 100644
--- a/apps/web/src/j5/a2a/adjudicationDock.logic.test.ts
+++ b/packages/client-runtime/src/j5/adjudicationDock.test.ts
@@ -6,7 +6,7 @@ import {
hasMoreThanExcerpt,
isAskAlreadyClosed,
pickShownAsk,
-} from "./adjudicationDock.logic";
+} from "./adjudicationDock.ts";
const ask = (
exchangeId: string,
@@ -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/apps/web/src/j5/a2a/adjudicationDock.logic.ts b/packages/client-runtime/src/j5/adjudicationDock.ts
similarity index 77%
rename from apps/web/src/j5/a2a/adjudicationDock.logic.ts
rename to packages/client-runtime/src/j5/adjudicationDock.ts
index a457ad603b04d..3c70cd4cdfd0b 100644
--- a/apps/web/src/j5/a2a/adjudicationDock.logic.ts
+++ b/packages/client-runtime/src/j5/adjudicationDock.ts
@@ -33,7 +33,8 @@ export function adjudicationAsks(input: {
const kept = input.refused.filter(
(item) => !openIds.has(item.exchangeId) && input.hasWords(item.exchangeId),
);
- return [...open, ...kept].toSorted(
+ // A fresh array, sorted in place: Hermes has no `toSorted`.
+ return [...open, ...kept].sort(
(left, right) =>
left.openedAt.localeCompare(right.openedAt) ||
left.exchangeId.localeCompare(right.exchangeId),
@@ -41,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. */
diff --git a/packages/client-runtime/src/j5/crewMemberships.test.ts b/packages/client-runtime/src/j5/crewMemberships.test.ts
new file mode 100644
index 0000000000000..127274aa678eb
--- /dev/null
+++ b/packages/client-runtime/src/j5/crewMemberships.test.ts
@@ -0,0 +1,34 @@
+import { EnvironmentId, ThreadId } from "@t3tools/contracts";
+import type { ThreadCrewMembership } from "@t3tools/contracts/j5";
+import { expect, it } from "vite-plus/test";
+
+import { scopedThreadKey, scopeThreadRef } from "../environment/scoped.ts";
+import { replaceCrewMemberships } from "./crewMemberships.ts";
+
+const live = { crewInstanceId: "crew:1", crewName: "Review Pair" };
+
+it("treats the visible rows as the whole truth when replacing memberships, per environment", () => {
+ const environmentId = EnvironmentId.make("env:a");
+ const other = EnvironmentId.make("env:b");
+ const key = (id: string, env = environmentId) =>
+ scopedThreadKey(scopeThreadRef(env, ThreadId.make(id)));
+ const stale = ThreadId.make("thread:stale");
+ const fresh = ThreadId.make("thread:fresh");
+ const membership: ThreadCrewMembership = { kind: "member", seat: "builder", crew: live };
+ const previous = new Map([
+ [key("thread:stale"), membership],
+ [key("thread:kept"), membership],
+ // The same local id on another environment is a different thread and stays untouched.
+ [key("thread:stale", other), membership],
+ ]);
+ const next = replaceCrewMemberships(
+ previous,
+ environmentId,
+ [stale, fresh],
+ [{ threadId: fresh, membership: { kind: "captain", crews: [live] } }],
+ );
+ expect([...next.keys()].toSorted()).toEqual(
+ [key("thread:fresh"), key("thread:kept"), key("thread:stale", other)].toSorted(),
+ );
+ expect(previous.size).toBe(3);
+});
diff --git a/packages/client-runtime/src/j5/crewMemberships.ts b/packages/client-runtime/src/j5/crewMemberships.ts
new file mode 100644
index 0000000000000..63f4f88776e6e
--- /dev/null
+++ b/packages/client-runtime/src/j5/crewMemberships.ts
@@ -0,0 +1,19 @@
+import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
+import type { CrewMembershipEntry, ThreadCrewMembership } from "@t3tools/contracts/j5";
+
+import { scopedThreadKey, scopeThreadRef } from "../environment/scoped.ts";
+
+/** The visible rows are the whole truth: a thread that left every Crew loses its chip on the next read. */
+export const replaceCrewMemberships = (
+ previous: ReadonlyMap,
+ environmentId: EnvironmentId,
+ requested: ReadonlyArray,
+ entries: ReadonlyArray,
+) => {
+ const next = new Map(previous);
+ for (const threadId of requested)
+ next.delete(scopedThreadKey(scopeThreadRef(environmentId, threadId)));
+ for (const entry of entries)
+ next.set(scopedThreadKey(scopeThreadRef(environmentId, entry.threadId)), entry.membership);
+ return next;
+};