From 9e09c6c761fb2af3e5f77d2d3719ba274de2be38 Mon Sep 17 00:00:00 2001 From: Jackson Miller Date: Sun, 8 Nov 2026 23:23:41 -0500 Subject: [PATCH 1/3] feat(mobile): seat approvals and agents' questions in the Inbox, counted on the bell Mobile's Inbox now lists Crew seats' approvals, answered in place with upstream's approval card, and links to questions agents asked through their provider's tool, as web's Inbox does. The bell counts them with the open asks. The logic moves from web to client-runtime, with the bell's count shared by both. Co-Authored-By: Claude Opus 5.5 --- FORK.md | 6 +- apps/mobile/src/j5/inbox/InboxBell.tsx | 15 +- .../mobile/src/j5/inbox/InboxCrewRequests.tsx | 179 ++++++++++++++++++ apps/mobile/src/j5/inbox/InboxScreen.tsx | 35 +++- apps/mobile/src/j5/inbox/inboxSources.ts | 69 ++++++- apps/web/src/j5/a2a/HumanInboxBell.tsx | 23 +-- apps/web/src/j5/a2a/HumanInboxPage.tsx | 2 +- .../src/j5/a2a/NativeQuestionInboxSection.tsx | 2 +- ...rewRuntimeRequestsSection.browser.test.tsx | 2 +- .../j5/crew/CrewRuntimeRequestsSection.tsx | 5 +- .../src/j5/crew/crewRuntimeRequestsClient.ts | 2 +- apps/web/src/j5/state.ts | 5 +- packages/client-runtime/package.json | 4 + .../src/j5/crewInboxRequests.test.ts | 38 +++- .../src/j5/crewInboxRequests.ts | 33 +++- 15 files changed, 376 insertions(+), 44 deletions(-) create mode 100644 apps/mobile/src/j5/inbox/InboxCrewRequests.tsx rename apps/web/src/j5/crew/crewRuntimeRequests.logic.test.ts => packages/client-runtime/src/j5/crewInboxRequests.test.ts (82%) rename apps/web/src/j5/crew/crewRuntimeRequests.logic.ts => packages/client-runtime/src/j5/crewInboxRequests.ts (77%) diff --git a/FORK.md b/FORK.md index 92fac016ab9c7..cfa08db481740 100644 --- a/FORK.md +++ b/FORK.md @@ -523,9 +523,9 @@ migrations after upstream migrations. 100. The mobile new-task composer gives a saved agent its own row and lets the slash menu cover the draft rows ([#866](https://github.com/Jacksondr5/j5code/issues/866), Jackson's direction at Checkpoint 1, 2026-11-01; register entry in the wave-2 docs PR). Upstream's composer shows the model in its input row and opens the slash menu above everything stacked over the input. In `apps/mobile/src/features/threads/NewTaskDraftScreen.tsx`, the draft controls render J5-owned `j5/agents/DraftAgentRow.tsx` under the checkout row: the saved-agent picker, then the chosen agent's persona, route and remove action. `apps/mobile/src/features/threads/ThreadComposer.tsx` renders the persona lock control, which wraps upstream's `usesLargeControls` model control since v0.1.7, only when `!props.isDraft`, so a draft's input row stays the editor, and wraps `ComposerPopoverAnchor` in a zero-height `relative` view placed after `draftControls`. The anchor's `bottom-full` (and the Android anchor's measured frame) then starts at the top of the input, so the menu draws over the checkout and agent rows instead of above them. A started thread has no draft controls, so its menu opens where it did. -101. Mobile has a J5 Inbox screen ([#830](https://github.com/Jacksondr5/j5code/issues/830)), landing the reserved Route registration seam for it. `apps/mobile/src/Stack.tsx` imports J5-owned `j5InboxRoutes` (`apps/mobile/src/j5/inbox/routes.ts`) and spreads it before `SETTINGS_SCREENS`, adding a root `Inbox` screen at `inbox` (`apps/mobile/src/j5/inbox/InboxScreen.tsx`). It reads every connected server's open and answered asks through J5-owned source atoms (`apps/mobile/src/j5/inbox/inboxSources.ts`, built as web's are, with `writesNowhere` for a person who can answer nothing), merges and orders them with `client-runtime/src/j5/inbox.ts`, and shows an older server's source notice. It rereads when it comes into view and on the server's inbox revision, with no timer. On a pin advance: if upstream reshapes `Stack.tsx`'s root screens, spread `j5InboxRoutes` among them again. +101. Mobile has a J5 Inbox screen ([#830](https://github.com/Jacksondr5/j5code/issues/830)), landing the reserved Route registration seam for it. `apps/mobile/src/Stack.tsx` imports J5-owned `j5InboxRoutes` (`apps/mobile/src/j5/inbox/routes.ts`) and spreads it before `SETTINGS_SCREENS`, adding a root `Inbox` screen at `inbox` (`apps/mobile/src/j5/inbox/InboxScreen.tsx`). It reads every connected server's open and answered asks through J5-owned source atoms (`apps/mobile/src/j5/inbox/inboxSources.ts`, built as web's are, with `writesNowhere` for a person who can answer nothing), merges and orders them with `client-runtime/src/j5/inbox.ts`, and shows an older server's source notice. It also lists Crew seats' approvals, answered with upstream's mobile `PendingApprovalCard`, and links to agents' questions, read as web reads them (a server is asked only while a thread there waits); their logic is J5-owned `packages/client-runtime/src/j5/crewInboxRequests.ts`, moved from web and reached through the `./j5/crew-inbox-requests` export this case appends to upstream-owned `packages/client-runtime/package.json`. It rereads when it comes into view and on the server's inbox and Crew revisions, with no timer. On a pin advance: if upstream reshapes `Stack.tsx`'s root screens, spread `j5InboxRoutes` among them again. -102. Mobile's thread list has an Inbox bell with the open count ([#830](https://github.com/Jacksondr5/j5code/issues/830)), as web's rail does. J5-owned `apps/mobile/src/j5/inbox/InboxBell.tsx` reads every connected server's open count (`inboxCountSourcesAtom`, case 101), says it through `inboxBellPresentation` (`packages/client-runtime/src/j5/inbox.ts`, shared with web's bell), and opens the `Inbox` screen. It counts open asks only; web's also counts Crew requests and seat approvals, which come to mobile with Crews. Two headers mount it, each with one import and one or two lines: `apps/mobile/src/features/home/ThreadListToolbar.tsx` (Android) adds it beside `filterButton` in the toolbar row's `filter` slot when a server is saved, and `apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx` adds it as a `Toolbar.Custom` in the right toolbar of the thread list on iPhone and iPad alike (iOS draws its sidebar's header natively, through this toolbar). Android's split view draws its sidebar header with the same `ThreadListToolbar`, so it gets the bell there; no other header holds the thread list's filter. Upstream's symbol set has no plain bell on Android, so J5's `BellGlyph` draws Tabler's there and the SF Symbol on iOS. On a pin advance: if upstream moves the thread list's filter, move the bell with it. +102. Mobile's thread list has an Inbox bell with the open count ([#830](https://github.com/Jacksondr5/j5code/issues/830)), as web's rail does. J5-owned `apps/mobile/src/j5/inbox/InboxBell.tsx` reads every connected server's open count (`inboxCountSourcesAtom`, case 101), says it through `inboxBellPresentation` (`packages/client-runtime/src/j5/inbox.ts`, shared with web's bell), and opens the `Inbox` screen. It counts open asks, seat approvals and agents' questions through `inboxBellCount` (case 101), which web's bell uses too. Two headers mount it, each with one import and one or two lines: `apps/mobile/src/features/home/ThreadListToolbar.tsx` (Android) adds it beside `filterButton` in the toolbar row's `filter` slot when a server is saved, and `apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx` adds it as a `Toolbar.Custom` in the right toolbar of the thread list on iPhone and iPad alike (iOS draws its sidebar's header natively, through this toolbar). Android's split view draws its sidebar header with the same `ThreadListToolbar`, so it gets the bell there; no other header holds the thread list's filter. Upstream's symbol set has no plain bell on Android, so J5's `BellGlyph` draws Tabler's there and the SF Symbol on iOS. On a pin advance: if upstream moves the thread list's filter, move the bell with it. 103. Mobile's persona forms and Playbook conversation form are pushed settings pages ([#894](https://github.com/Jacksondr5/j5code/issues/894), [#902](https://github.com/Jacksondr5/j5code/issues/902)), since Android's `Menu` draws in the app's root window and can't appear over an RN `Modal` or upstream's `Sheet`. `apps/mobile/src/Stack.tsx` imports J5-owned `j5SettingsFormRoutes` (`apps/mobile/src/j5/agents/routes.ts`) and spreads it into `SETTINGS_SCREENS` after `SettingsAgents`, adding `SettingsPersonaNew`, `SettingsPersonaEdit` and `SettingsPlaybookConversation`. They follow upstream's `SettingsScheduledTaskNew` and `SettingsScheduledTaskEdit`, including the guard against losing unsaved changes. On a pin advance: if upstream reshapes `SETTINGS_SCREENS`, spread the routes among them again. @@ -932,7 +932,7 @@ explicitly marked. | `apps/web/src/routeTree.gen.ts` | R | generated route registrations for 6/9 | | `apps/web/src/components/onboarding/WelcomeWizard.tsx` | R | 39, B | | `apps/web/tsconfig.json` | R | B | -| `packages/client-runtime/package.json` | R | 7, 23, 34, 45, 69, 70, 75, Role library | +| `packages/client-runtime/package.json` | R | 7, 23, 34, 45, 69, 70, 75, 101, Role library | | `packages/client-runtime/src/connection/compatibility.ts` | A | 56 | | `packages/client-runtime/src/operations/commands.ts` | R | Saved-agent mentions | | `packages/contracts/package.json` | N | 34 | diff --git a/apps/mobile/src/j5/inbox/InboxBell.tsx b/apps/mobile/src/j5/inbox/InboxBell.tsx index cc8d36a5cb00a..cd3ab9ca510c4 100644 --- a/apps/mobile/src/j5/inbox/InboxBell.tsx +++ b/apps/mobile/src/j5/inbox/InboxBell.tsx @@ -1,20 +1,25 @@ import { useAtomValue } from "@effect/atom-react"; +import { inboxBellCount } from "@t3tools/client-runtime/j5/crew-inbox-requests"; import { inboxBellPresentation, mergeOpenInboxCounts } from "@t3tools/client-runtime/j5/inbox"; import { useNavigation } from "@react-navigation/native"; import { Pressable, View } from "react-native"; import { AppText as Text } from "../../components/ui/AppText"; import { BellGlyph } from "./BellGlyph"; -import { inboxCountSourcesAtom } from "./inboxSources"; +import { crewRequestSourcesAtom, inboxCountSourcesAtom } from "./inboxSources"; /** - * The Inbox bell in the thread list's header, with the open count across every connected server. - * It counts open asks only: Crew requests and seat approvals join it with Crews on mobile. + * The Inbox bell in the thread list's header, with the open count across every connected server: + * open asks, seat approvals and agents' questions, as web's bell counts them. */ export function InboxBell() { const navigation = useNavigation(); - const sources = useAtomValue(inboxCountSourcesAtom); - const { badge, label } = inboxBellPresentation(mergeOpenInboxCounts(sources)); + const { badge, label } = inboxBellPresentation( + inboxBellCount( + mergeOpenInboxCounts(useAtomValue(inboxCountSourcesAtom)), + useAtomValue(crewRequestSourcesAtom), + ), + ); return ( + `${request.environmentId}:${request.threadId}:${request.requestId}`; + +function SectionTitle(props: { readonly title: string }) { + return ( + + {props.title} + + ); +} + +/** + * Crew seats' approvals, answered here with upstream's approval card instead of in the seat's + * thread (Crews AC9), as web's Inbox answers them. + */ +export function SeatApprovalsSection(props: { + readonly requests: ReadonlyArray; +}) { + if (props.requests.length === 0) return null; + return ( + + + {props.requests.map((request) => ( + + ))} + + ); +} + +function SeatApproval(props: { readonly request: ScopedCrewRuntimeRequest }) { + const { request } = props; + const openLinkedThread = useOpenLinkedThread(); + const canRespond = useAtomValue( + j5Environment.respondCrewRuntimeRequest.permissionAtom(request.environmentId), + ); + const respond = useAtomCommand(j5Environment.respondCrewRuntimeRequest, { + reportFailure: false, + }); + const [responding, setResponding] = useState(false); + const [error, setError] = useState(null); + return ( + + + + {request.crewName} · {request.seat} + + + openLinkedThread({ + environmentId: String(request.environmentId), + threadId: String(request.threadId), + }) + } + > + + {request.threadTitle} + + + + { + if (responding) return; + setResponding(true); + setError(null); + const result = await respond({ + environmentId: request.environmentId, + input: { threadId: request.threadId, requestId, decision }, + }); + // An answer that lost a race with another device is refused, and says so; either way + // the list is read again so a resolved request leaves. + if (result._tag === "Failure") { + const failure = squashAtomCommandFailure(result); + setError(failure instanceof Error ? failure.message : "Could not answer the request."); + } + await readCrewRequestSources(request.environmentId); + setResponding(false); + return result; + }} + /> + {error === null ? null : ( + + {error} + + )} + + ); +} + +/** + * Questions agents asked through their provider's own question tool. The answer is given in the + * agent's thread, so the Inbox links there, as web's does. + */ +export function AgentQuestionsSection(props: { + readonly questions: ReadonlyArray; + readonly showEnvironment: boolean; +}) { + const projects = useProjects(); + const openLinkedThread = useOpenLinkedThread(); + if (props.questions.length === 0) return null; + return ( + + + {props.questions.map((question) => { + const project = projects.find( + (candidate) => + candidate.environmentId === question.environmentId && + candidate.id === question.projectId, + ); + const meta = [ + project?.title, + question.crew?.name, + question.crew?.seat, + props.showEnvironment || !question.connected + ? `${props.showEnvironment ? question.environmentLabel : ""}${question.connected ? "" : props.showEnvironment ? " (offline)" : "offline"}` + : null, + ].filter((part): part is string => part !== undefined && part !== null && part !== ""); + return ( + + {question.threadTitle} + {meta.length === 0 ? null : ( + + {meta.join(" · ")} + + )} + + {question.responseCapability === "live" + ? "Waiting for an answer to continue." + : "Asked a question while continuing its work."} + + + openLinkedThread({ + environmentId: String(question.environmentId), + threadId: String(question.threadId), + }) + } + > + + {question.connected ? "Open question" : "Its server is offline"} + + + + ); + })} + + ); +} diff --git a/apps/mobile/src/j5/inbox/InboxScreen.tsx b/apps/mobile/src/j5/inbox/InboxScreen.tsx index ef0e462985b7d..cd0f41bc5a419 100644 --- a/apps/mobile/src/j5/inbox/InboxScreen.tsx +++ b/apps/mobile/src/j5/inbox/InboxScreen.tsx @@ -1,4 +1,8 @@ import { useAtomValue } from "@effect/atom-react"; +import { + mergeCrewRuntimeRequestSources, + mergeNativeQuestionInboxSources, +} from "@t3tools/client-runtime/j5/crew-inbox-requests"; import { answeredByLine, closedLine, @@ -28,12 +32,15 @@ import { SelectableMarkdownText } from "../../native/SelectableMarkdownText"; import { j5Sharing } from "../sharing/guestAccess"; import { j5Environment } from "../state"; import { type ClosedItem, useInboxAnswers } from "./inboxAnswers"; +import { AgentQuestionsSection, SeatApprovalsSection } from "./InboxCrewRequests"; import { answeredInboxQueryAtom, answeredInboxSourcesAtom, + crewRequestSourcesAtom, openInboxQueryAtom, openInboxSourcesAtom, readInboxSources, + refreshCrewRequestSources, refreshInboxSources, } from "./inboxSources"; import { createPullRefresh } from "./inboxPullRefresh.logic"; @@ -64,18 +71,28 @@ function useOwnName(environmentId: EnvironmentId): string | null { function refreshAll() { refreshInboxSources(openInboxSourcesAtom, openInboxQueryAtom); refreshInboxSources(answeredInboxSourcesAtom, answeredInboxQueryAtom); + refreshCrewRequestSources(); } /** * The person's Inbox: what agents on every connected server have asked them, most urgent first - * (Inbox AC6), answered in place, and the asks already answered. + * (Inbox AC6), answered in place, Crew seats' approvals and agents' questions, and the asks + * already answered. */ export function InboxScreen() { const openSources = useAtomValue(openInboxSourcesAtom); const answeredSources = useAtomValue(answeredInboxSourcesAtom); const items = mergeHumanInboxSources(openSources); const answered = mergeHumanInboxSources(answeredSources); - const showEnvironment = spansMultipleEnvironments([...items, ...answered]); + const crewSources = useAtomValue(crewRequestSourcesAtom); + const seatApprovals = mergeCrewRuntimeRequestSources(crewSources); + const agentQuestions = mergeNativeQuestionInboxSources(crewSources); + const showEnvironment = spansMultipleEnvironments([ + ...items, + ...answered, + ...seatApprovals, + ...agentQuestions, + ]); const labels = useScopedParticipantLabels( [...items, ...answered].map((item) => ({ environmentId: item.environmentId, @@ -96,10 +113,12 @@ export function InboxScreen() { ); const notices = [ ...new Set( - [...openSources.sources, ...answeredSources.sources].flatMap((source) => { - const notice = j5SourceNotice(source); - return notice === null ? [] : [notice]; - }), + [...openSources.sources, ...answeredSources.sources, ...crewSources.sources].flatMap( + (source) => { + const notice = j5SourceNotice(source); + return notice === null ? [] : [notice]; + }, + ), ), ]; const content = ( @@ -110,8 +129,10 @@ export function InboxScreen() { {notice} ))} + + {answers.shownItems.length === 0 ? ( - loading ? ( + seatApprovals.length > 0 || agentQuestions.length > 0 ? null : loading ? ( Loading your inbox… ) : ( + j5Environment.crewRuntimeRequests({ environmentId, input: {} }); + +/** The servers with a thread waiting on an approval or a question; the same value until that changes. */ +export const crewRequestReadAtom = Atom.make((get): CrewApprovalReadPlan => { + const next = crewApprovalReadPlan(get(environmentThreadShells.threadShellsAtom)); + const previous = Option.getOrNull(get.self()); + return previous !== null && previous.key === next.key ? previous : next; +}).pipe(Atom.withLabel("mobile-j5:crew-request-read")); + +const NO_CREW_REQUESTS = AsyncResult.success({ + requests: [], + questions: [], +}); + +// A server with no thread waiting has no seat approval or question to list, so it isn't asked, as +// on web. The server decides which waiting threads belong in the Inbox. +const gatedCrewRequestsAtom = Atom.family((environmentId: EnvironmentId) => + Atom.make((get) => + get(crewRequestReadAtom).environmentIds.includes(environmentId) + ? get(crewRequestsQueryAtom(environmentId)) + : NO_CREW_REQUESTS, + ).pipe(Atom.withLabel(`mobile-j5:gated-crew-requests:${environmentId}`)), +); + +/** Seat approvals and placed agents' questions on every connected server; the server's signal rereads them. */ +export const crewRequestSourcesAtom = createJ5ReadSourcesAtom({ + ...sourcesInput, + label: "mobile-j5:crew-request-sources", + queryAtom: gatedCrewRequestsAtom, +}); + /** * Reads each connected server's source again, as the Inbox screen does when it comes into view. * A read already in flight is left to finish. @@ -58,19 +97,32 @@ export const inboxCountSourcesAtom = createJ5ReadSourcesAtom({ export function refreshInboxSources( sourcesAtom: Atom.Atom>, queryAtom: (environmentId: EnvironmentId) => Atom.Atom>, + only?: ReadonlyArray, ) { for (const source of appAtomRegistry.get(sourcesAtom).sources) { if (!source.connected || source.status === "unsupported" || source.refreshing) continue; + if (only !== undefined && !only.includes(source.environmentId)) continue; appAtomRegistry.refresh(queryAtom(source.environmentId)); } } +/** Reads again the Crew requests of the servers with a thread waiting. */ +export const refreshCrewRequestSources = () => + refreshInboxSources( + crewRequestSourcesAtom, + crewRequestsQueryAtom, + appAtomRegistry.get(crewRequestReadAtom).environmentIds, + ); + const readConnectedSources = ( sourcesAtom: Atom.Atom>, queryAtom: (environmentId: EnvironmentId) => Atom.Atom>, + only?: ReadonlyArray, ) => appAtomRegistry.get(sourcesAtom).sources.flatMap((source) => - !source.connected || source.status === "unsupported" + !source.connected || + source.status === "unsupported" || + (only !== undefined && !only.includes(source.environmentId)) ? [] : [ executeAtomQuery(appAtomRegistry, queryAtom(source.environmentId), { @@ -81,9 +133,22 @@ const readConnectedSources = ( ], ); -/** Reads every connected server's open and answered asks, and settles when all have answered. */ +/** Reads the Crew requests of the servers with a thread waiting, and settles when all have answered. */ +export const readCrewRequestSources = (environmentId?: EnvironmentId) => { + const waiting = appAtomRegistry.get(crewRequestReadAtom).environmentIds; + return Promise.all( + readConnectedSources( + crewRequestSourcesAtom, + crewRequestsQueryAtom, + environmentId === undefined ? waiting : waiting.filter((id) => id === environmentId), + ), + ); +}; + +/** Reads every connected server's asks and Crew requests, and settles when all have answered. */ export const readInboxSources = () => Promise.all([ ...readConnectedSources(openInboxSourcesAtom, openInboxQueryAtom), ...readConnectedSources(answeredInboxSourcesAtom, answeredInboxQueryAtom), + readCrewRequestSources(), ]); diff --git a/apps/web/src/j5/a2a/HumanInboxBell.tsx b/apps/web/src/j5/a2a/HumanInboxBell.tsx index 0e99b7bc1d341..ff362b0226693 100644 --- a/apps/web/src/j5/a2a/HumanInboxBell.tsx +++ b/apps/web/src/j5/a2a/HumanInboxBell.tsx @@ -5,8 +5,8 @@ import { inboxBellPresentation, mergeOpenInboxCounts } from "@t3tools/client-run import { useSidebar } from "../../components/ui/sidebar"; import { cn } from "../../lib/utils"; -import { inboxBadgeCount } from "../crew/crewRuntimeRequests.logic"; -import { useCrewRuntimeRequests, useNativeQuestionInbox } from "../crew/crewRuntimeRequestsClient"; +import { inboxBellCount } from "@t3tools/client-runtime/j5/crew-inbox-requests"; +import { useCrewRuntimeRequests } from "../crew/crewRuntimeRequestsClient"; import { crewRuntimeRequestSourcesAtom, inboxCountQueryAtom, @@ -21,24 +21,19 @@ const useCountRefresh = createVisibleRefreshHook(() => { export function HumanInboxBell({ onBackdrop }: { readonly onBackdrop: boolean }) { const { isMobile, setOpenMobile } = useSidebar(); - const sources = useAtomValue(inboxCountSourcesAtom); - const merged = mergeOpenInboxCounts(sources); - const runtimeRequests = useCrewRuntimeRequests().length + useNativeQuestionInbox().length; - const count = inboxBadgeCount(merged.count, runtimeRequests); - const runtimeSources = useAtomValue(crewRuntimeRequestSourcesAtom); - const incomplete = - merged.incomplete || - !runtimeSources.isReady || - runtimeSources.sources.some( - (source) => source.status !== "ready" && source.status !== "unsupported", - ); + // Mounts the Crew request reads and refreshes them on focus; the count reads their sources. + useCrewRuntimeRequests(); + const bell = inboxBellCount( + mergeOpenInboxCounts(useAtomValue(inboxCountSourcesAtom)), + useAtomValue(crewRuntimeRequestSourcesAtom), + ); useCountRefresh(); const closeMobileSidebar = () => { if (isMobile) setOpenMobile(false); }; - const { badge, label } = inboxBellPresentation({ count, incomplete }); + const { badge, label } = inboxBellPresentation(bell); return ( diff --git a/apps/web/src/j5/crew/crewRuntimeRequestsClient.ts b/apps/web/src/j5/crew/crewRuntimeRequestsClient.ts index 9346045de898c..64938f84c23c2 100644 --- a/apps/web/src/j5/crew/crewRuntimeRequestsClient.ts +++ b/apps/web/src/j5/crew/crewRuntimeRequestsClient.ts @@ -15,7 +15,7 @@ import { createVisibleRefreshHook } from "../useVisibleRefresh"; import { mergeCrewRuntimeRequestSources, mergeNativeQuestionInboxSources, -} from "./crewRuntimeRequests.logic"; +} from "@t3tools/client-runtime/j5/crew-inbox-requests"; /** Answer on the environment that holds the thread; the refusal message says why it failed. */ export async function respondCrewRuntimeRequest( diff --git a/apps/web/src/j5/state.ts b/apps/web/src/j5/state.ts index 205ecba23ecac..4f81cbe5c9b2e 100644 --- a/apps/web/src/j5/state.ts +++ b/apps/web/src/j5/state.ts @@ -15,7 +15,10 @@ import { appAtomRegistry } from "../rpc/atomRegistry"; import { serverEnvironment } from "../state/server"; import { environmentThreadShells } from "../state/threads"; import { createSharingEnvironmentAtoms } from "@t3tools/client-runtime/j5/sharing"; -import { crewApprovalReadPlan, type CrewApprovalReadPlan } from "./crew/crewRuntimeRequests.logic"; +import { + crewApprovalReadPlan, + type CrewApprovalReadPlan, +} from "@t3tools/client-runtime/j5/crew-inbox-requests"; export const j5Environment = createJ5EnvironmentAtoms(connectionAtomRuntime); diff --git a/packages/client-runtime/package.json b/packages/client-runtime/package.json index c1c6f6f4cabfd..baad119abecc9 100644 --- a/packages/client-runtime/package.json +++ b/packages/client-runtime/package.json @@ -503,6 +503,10 @@ "types": "./src/j5/sharedConversation.ts", "default": "./src/j5/sharedConversation.ts" }, + "./j5/crew-inbox-requests": { + "types": "./src/j5/crewInboxRequests.ts", + "default": "./src/j5/crewInboxRequests.ts" + }, "./j5/crew-notices": { "types": "./src/j5/crewNotices.ts", "default": "./src/j5/crewNotices.ts" diff --git a/apps/web/src/j5/crew/crewRuntimeRequests.logic.test.ts b/packages/client-runtime/src/j5/crewInboxRequests.test.ts similarity index 82% rename from apps/web/src/j5/crew/crewRuntimeRequests.logic.test.ts rename to packages/client-runtime/src/j5/crewInboxRequests.test.ts index b20256b51425c..67c155ca640db 100644 --- a/apps/web/src/j5/crew/crewRuntimeRequests.logic.test.ts +++ b/packages/client-runtime/src/j5/crewInboxRequests.test.ts @@ -6,10 +6,11 @@ import type { CrewRuntimeRequestItem } from "@t3tools/contracts/j5"; import { crewApprovalReadPlan, inboxBadgeCount, + inboxBellCount, mergeCrewRuntimeRequestSources, mergeNativeQuestionInboxSources, toPendingApproval, -} from "./crewRuntimeRequests.logic"; +} from "./crewInboxRequests.ts"; const envA = EnvironmentId.make("env:a"); const envB = EnvironmentId.make("env:b"); @@ -185,3 +186,38 @@ it("reads an async question summary even when presentation keeps the thread work crewApprovalReadPlan([{ ...row, source: { pendingRuntimeRequest: null } }]).environmentIds, ).toEqual([]); }); + +it("counts asks, seat approvals and agents' questions on the bell, marking it while a server can't be read", () => { + const question = { + threadId: seatThread, + requestId: RuntimeRequestId.make("native"), + projectId: "project:1", + threadTitle: "Builder", + responseCapability: "live" as const, + createdAt: "2026-10-19T12:00:00Z", + }; + const crew = (status: string, data: unknown) => + ({ + isReady: true, + sources: [{ environmentId: envA, environmentLabel: "A", connected: true, status, data }], + }) as never; + const read = crew("ready", { requests: [item("a1")], questions: [question] }); + expect(inboxBellCount({ count: 2, incomplete: false }, read)).toEqual({ + count: 4, + incomplete: false, + }); + // A server without the read adds nothing and leaves the count complete. + expect(inboxBellCount({ count: 2, incomplete: false }, crew("unsupported", null))).toEqual({ + count: 2, + incomplete: false, + }); + // A server whose requests could not be read leaves the count last known. + expect(inboxBellCount({ count: 2, incomplete: false }, crew("offline", null))).toEqual({ + count: 2, + incomplete: true, + }); + expect(inboxBellCount({ count: null, incomplete: true }, read)).toEqual({ + count: 2, + incomplete: true, + }); +}); diff --git a/apps/web/src/j5/crew/crewRuntimeRequests.logic.ts b/packages/client-runtime/src/j5/crewInboxRequests.ts similarity index 77% rename from apps/web/src/j5/crew/crewRuntimeRequests.logic.ts rename to packages/client-runtime/src/j5/crewInboxRequests.ts index 0356d8825e1c9..46904d03a366f 100644 --- a/apps/web/src/j5/crew/crewRuntimeRequests.logic.ts +++ b/packages/client-runtime/src/j5/crewInboxRequests.ts @@ -1,5 +1,3 @@ -import type { J5ReadSources } from "@t3tools/client-runtime/j5/readSources"; -import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/models"; import type { EnvironmentId } from "@t3tools/contracts"; import type { CrewRuntimeRequestItem, @@ -7,7 +5,9 @@ import type { NativeQuestionInboxItem, } from "@t3tools/contracts/j5"; -import type { PendingApproval } from "../../session-logic"; +import type { EnvironmentThreadShell } from "../state/models.ts"; +import type { ThreadPendingApproval } from "../state/threadRequests.ts"; +import type { J5ReadSources } from "./readSources.ts"; export type ScopedCrewRuntimeRequest = CrewRuntimeRequestItem & { readonly environmentId: EnvironmentId; @@ -42,10 +42,10 @@ export const mergeNativeQuestionInboxSources = ( connected: source.connected, })), ) - .toSorted((a, b) => a.createdAt.localeCompare(b.createdAt)); + .sort((a, b) => a.createdAt.localeCompare(b.createdAt)); /** The composer's approval shape; the server lists only approvals the provider can still take. */ -export const toPendingApproval = (request: CrewRuntimeRequestItem): PendingApproval => ({ +export const toPendingApproval = (request: CrewRuntimeRequestItem): ThreadPendingApproval => ({ requestId: request.requestId, requestKind: request.requestKind, createdAt: request.createdAt, @@ -87,7 +87,7 @@ export const crewApprovalReadPlan = ( environmentId: shell.environmentId, entry: `${shell.environmentId}/${shell.id}/${shell.hasPendingApprovals}/${shell.hasPendingUserInput}/${shell.source?.pendingRuntimeRequest?.id ?? ""}`, })) - .toSorted((left, right) => left.entry.localeCompare(right.entry)); + .sort((left, right) => left.entry.localeCompare(right.entry)); return { key: pending.map((shell) => shell.entry).join("\n"), environmentIds: [...new Set(pending.map((shell) => shell.environmentId))], @@ -105,3 +105,24 @@ export const inboxBadgeCount = ( const crew = crewRuntimeRequests; return openAsks === null ? (crew > 0 ? crew : null) : openAsks + crew; }; + +/** + * The bell's count and whether it is complete: open asks, plus the seat approvals and agents' + * questions read from every server. Web and mobile both count this way. + */ +export const inboxBellCount = ( + asks: { readonly count: number | null; readonly incomplete: boolean }, + crewSources: J5ReadSources, +): { readonly count: number | null; readonly incomplete: boolean } => ({ + count: inboxBadgeCount( + asks.count, + mergeCrewRuntimeRequestSources(crewSources).length + + mergeNativeQuestionInboxSources(crewSources).length, + ), + incomplete: + asks.incomplete || + !crewSources.isReady || + crewSources.sources.some( + (source) => source.status !== "ready" && source.status !== "unsupported", + ), +}); From 463a06bcd1ed5cc0351ba2dfddd4c792a1619949 Mon Sep 17 00:00:00 2001 From: Jackson Miller Date: Sun, 8 Nov 2026 23:34:45 -0500 Subject: [PATCH 2/3] fix(mobile): a refused seat approval's reason stays when its request leaves The reason was shown under the approval card, so a request another device had already resolved took its own explanation with it on the reread. It now shows above the section's list, as web keeps it at section level. Co-Authored-By: Claude Opus 5.5 --- .../mobile/src/j5/inbox/InboxCrewRequests.tsx | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/apps/mobile/src/j5/inbox/InboxCrewRequests.tsx b/apps/mobile/src/j5/inbox/InboxCrewRequests.tsx index 4b9f3514c0311..a2b74a8abe30c 100644 --- a/apps/mobile/src/j5/inbox/InboxCrewRequests.tsx +++ b/apps/mobile/src/j5/inbox/InboxCrewRequests.tsx @@ -32,24 +32,34 @@ function SectionTitle(props: { readonly title: string }) { /** * Crew seats' approvals, answered here with upstream's approval card instead of in the seat's - * thread (Crews AC9), as web's Inbox answers them. + * thread (Crews AC9), as web's Inbox answers them. A refused answer's reason stays above the list, + * since a request that another device resolved leaves it. */ export function SeatApprovalsSection(props: { readonly requests: ReadonlyArray; }) { - if (props.requests.length === 0) return null; + const [error, setError] = useState(null); + if (props.requests.length === 0 && error === null) return null; return ( + {error === null ? null : ( + + {error} + + )} {props.requests.map((request) => ( - + ))} ); } -function SeatApproval(props: { readonly request: ScopedCrewRuntimeRequest }) { - const { request } = props; +function SeatApproval(props: { + readonly request: ScopedCrewRuntimeRequest; + readonly onError: (message: string | null) => void; +}) { + const { request, onError } = props; const openLinkedThread = useOpenLinkedThread(); const canRespond = useAtomValue( j5Environment.respondCrewRuntimeRequest.permissionAtom(request.environmentId), @@ -58,7 +68,6 @@ function SeatApproval(props: { readonly request: ScopedCrewRuntimeRequest }) { reportFailure: false, }); const [responding, setResponding] = useState(false); - const [error, setError] = useState(null); return ( @@ -87,7 +96,7 @@ function SeatApproval(props: { readonly request: ScopedCrewRuntimeRequest }) { onRespond={async (requestId, decision) => { if (responding) return; setResponding(true); - setError(null); + onError(null); const result = await respond({ environmentId: request.environmentId, input: { threadId: request.threadId, requestId, decision }, @@ -96,18 +105,13 @@ function SeatApproval(props: { readonly request: ScopedCrewRuntimeRequest }) { // the list is read again so a resolved request leaves. if (result._tag === "Failure") { const failure = squashAtomCommandFailure(result); - setError(failure instanceof Error ? failure.message : "Could not answer the request."); + onError(failure instanceof Error ? failure.message : "Could not answer the request."); } await readCrewRequestSources(request.environmentId); setResponding(false); return result; }} /> - {error === null ? null : ( - - {error} - - )} ); } From 55963a6fe6e0f93f6cfd531caef86d809e2d8fe7 Mon Sep 17 00:00:00 2001 From: Jackson Miller Date: Mon, 9 Nov 2026 00:20:21 -0500 Subject: [PATCH 3/3] fix(mobile): a seat approval's header no longer runs its seat into the thread link The thread's title, usually the seat's own name, sat flush against the seat on Android. The header now names the Crew and seat, with an "Open thread" link on the right, as an ask's card links its thread. Co-Authored-By: Claude Opus 5.5 --- apps/mobile/src/j5/inbox/InboxCrewRequests.tsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/mobile/src/j5/inbox/InboxCrewRequests.tsx b/apps/mobile/src/j5/inbox/InboxCrewRequests.tsx index a2b74a8abe30c..f9755af195378 100644 --- a/apps/mobile/src/j5/inbox/InboxCrewRequests.tsx +++ b/apps/mobile/src/j5/inbox/InboxCrewRequests.tsx @@ -70,12 +70,13 @@ function SeatApproval(props: { const [responding, setResponding] = useState(false); return ( - - + + {request.crewName} · {request.seat} openLinkedThread({ @@ -84,9 +85,7 @@ function SeatApproval(props: { }) } > - - {request.threadTitle} - + Open thread