diff --git a/FORK.md b/FORK.md index 92fac016ab9c7..bf2827b6e0c9c 100644 --- a/FORK.md +++ b/FORK.md @@ -515,7 +515,7 @@ migrations after upstream migrations. 96. J5's person actions count as upstream's `feature.used` ([#766](https://github.com/Jacksondr5/j5code/issues/766), Jackson's 2026-10-24 decision on #510). Upstream records `feature.used` in its RPC authorization middleware after a request succeeds, from the allowlist in `apps/server/src/telemetry/FeatureUsage.ts`. Its `featureUsage` also looks in J5-owned `J5_METHOD_FEATURES` (`apps/server/src/j5/analytics/featureUsage.ts`) when upstream's own table has no entry for the method (one import and the `??` on the lookup line). The J5 table checks every variant against a contract literal schema. It keys one upstream method, `orchestration.launchThread`, counted as `persona.assign` only when the launch carries `agentPersona`. Upstream wins if it ever maps that method itself. Proofs: `apps/server/src/j5/analytics/featureUsage.test.ts`, which goes through upstream's `featureUsage`. On every rebase, keep the fallback in `featureUsage`, and check whether upstream now maps any method J5's table keys. -97. Mobile's timeline delegate and queue-row formatter, the mobile half of case 7 and case 24 ([#699](https://github.com/Jacksondr5/j5code/issues/699), register D38). `apps/mobile/src/features/threads/ThreadFeed.tsx` imports J5-owned `apps/mobile/src/j5/a2a/timeline.tsx`. `ThreadFeed` calls `useJ5Timeline` (J5-owned `apps/mobile/src/j5/a2a/timelineState.ts`, kept apart because it reaches the connection) over its feed's messages: the reader's person id from `j5Sharing.connectionAccess`, and one identity read (`useParticipantIdentities`) for the senders the shared classifier names. It passes the result to `renderFeedEntry` as `j5Timeline`, adds it to `listAppearanceData`, and `getItemType` reads `resolveJ5FeedMessage` so rows J5 folds share upstream's agent recycling pool. In `renderFeedEntry`, `resolveJ5FeedMessage(message, props.j5Timeline)` replaces upstream's `resolveUserMessagePresentation`: upstream's shape with the letter without its envelope as `text`, `"agent"` for every participant who is not a person, `j5`, `side` and `preview`. Before upstream's rows, `renderJ5TimelineNotice` returns J5's silence line, or the labelled raw card for a Crew notice or a delivery notice no parser reads yet, until [#698](https://github.com/Jacksondr5/j5code/issues/698). The user row is `items-start` when `side` is `"left"`, mounts `J5MessageAuthorLine` above the bubble ("You · via Inbox", another person's name, or the sender's identity line with its tag or badge), passes `AgentMessageFoldHeader` its `label` and `summary` through J5-owned `j5FoldHeader` when J5 read the message: folded, an empty `label` (a new optional prop) and J5's `preview`; open, the sender's name and no summary when the body opens with it (a Crew seat's brief keeps it). The header renders the summary only when it is not empty, and its label then takes the row's width with `flex-1`, so the chevron stays at the end (web's shape in pingdotgg/t3code#29373, whose mobile half hides the summary whenever the row is open and uses `shrink`), opens the sender with `J5OpenSenderThread` (the identity read's thread, on this server or a peer, or a brief's spawner thread) where upstream's `OpenSenderThreadButton` reads only `senderThreadId`, and leaves the composer-context copy to upstream's plain copy for a message J5 unwrapped, so Copy never carries the envelope. `apps/mobile/src/features/threads/ThreadQueueControl.tsx`, which upstream rewrote at v0.1.7 with a compact sender line per row (`QueuedRunSender`), imports `useJ5QueuedDeliveries` from J5-owned `apps/mobile/src/j5/a2a/queuedDelivery.tsx` (Jackson's decision 15 of 2026-11-05). For a queued J5 delivery the row's text is the letter's first line (`preview`) and its sender line is J5's (`sender`): the participant's name with the Automation, Outside agent, Expects reply or Replied tag, or "You · via Inbox" or " · via Inbox" for an Inbox reply, through the pure `presentJ5QueuedMessage` in `timelinePresentation.ts`. Anything J5 did not unwrap keeps upstream's `QueuedRunSender`, and J5's old `From :` prefix is gone. "Sent by T3 Code" reads "Sent by J5 Code". The mobile queue sheet has no sides. `apps/mobile/src/lib/filePreview.test.ts`, which renders `ThreadFeed` with upstream's state modules mocked, mocks `timelineState.ts` beside them. Proofs: `apps/mobile/src/j5/a2a/timelinePresentation.test.ts`, `packages/client-runtime/src/j5/participantIdentity.test.ts`, and the files' rows in `apps/mobile/src/j5/upstreamSeams.test.ts`. On every rebase, keep the calls that test lists; if upstream moves the agent fold out of `renderFeedEntry`, move the seam with it. +97. Mobile's timeline delegate and queue-row formatter, the mobile half of case 7 and case 24 ([#699](https://github.com/Jacksondr5/j5code/issues/699), register D38). `apps/mobile/src/features/threads/ThreadFeed.tsx` imports J5-owned `apps/mobile/src/j5/a2a/timeline.tsx`. `ThreadFeed` calls `useJ5Timeline` (J5-owned `apps/mobile/src/j5/a2a/timelineState.ts`, kept apart because it reaches the connection) over its feed's messages: the reader's person id from `j5Sharing.connectionAccess`, and one identity read (`useParticipantIdentities`) for the senders the shared classifier names. It passes the result to `renderFeedEntry` as `j5Timeline`, adds it to `listAppearanceData`, and `getItemType` reads `resolveJ5FeedMessage` so rows J5 folds share upstream's agent recycling pool. In `renderFeedEntry`, `resolveJ5FeedMessage(message, props.j5Timeline)` replaces upstream's `resolveUserMessagePresentation`: upstream's shape with the letter without its envelope as `text`, `"agent"` for every participant who is not a person, `j5`, `side` and `preview`. Before upstream's rows, `renderJ5TimelineNotice` (given `j5Timeline` for names and seat links) returns J5's platform notice as one grey line on the left that opens to its detail, as web's `J5NoticeLine` does ([#918](https://github.com/Jacksondr5/j5code/issues/918)): a notice the classifier has a summary for, with its participant ids named (`nameJ5NoticeParticipants`); what a Crew member was told; and a Crew notice's approval or decline line and `crewNoticeLines`, each seat opening its thread. A notice nothing can read returns null and is upstream's row, on the left when the platform wrote it. A playbook step or native question is `"automation"` in `resolveJ5FeedMessage`, with J5's `prompt`, so upstream's `ThreadAutomationMessageRow` draws it: its new `prompt` prop leads the label, summary and icon (`J5_PROMPT_ICONS`), and the row sits on the left with a border in place of the user bubble's fill and colours, for upstream's automation runs too, as web's case 7 does. A J5 prompt's pill is full width while folded too, with its label capped at 55% of the row, because J5's labels are long; upstream's "Automation" label never shrinks. The user row is `items-start` when `side` is `"left"`, mounts `J5MessageAuthorLine` above the bubble ("You · via Inbox", another person's name, or the sender's identity line with its tag or badge), passes `AgentMessageFoldHeader` its `label` and `summary` through J5-owned `j5FoldHeader` when J5 read the message: folded, an empty `label` (a new optional prop) and J5's `preview`; open, the sender's name and no summary when the body opens with it (a Crew seat's brief keeps it). The header renders the summary only when it is not empty, and its label then takes the row's width with `flex-1`, so the chevron stays at the end (web's shape in pingdotgg/t3code#29373, whose mobile half hides the summary whenever the row is open and uses `shrink`), opens the sender with `J5OpenSenderThread` (the identity read's thread, on this server or a peer, or a brief's spawner thread) where upstream's `OpenSenderThreadButton` reads only `senderThreadId`, and leaves the composer-context copy to upstream's plain copy for a message J5 unwrapped, so Copy never carries the envelope. `apps/mobile/src/features/threads/ThreadQueueControl.tsx`, which upstream rewrote at v0.1.7 with a compact sender line per row (`QueuedRunSender`), imports `useJ5QueuedDeliveries` from J5-owned `apps/mobile/src/j5/a2a/queuedDelivery.tsx` (Jackson's decision 15 of 2026-11-05). For a queued J5 delivery the row's text is the letter's first line (`preview`) and its sender line is J5's (`sender`): the participant's name with the Automation, Outside agent, Expects reply or Replied tag, or "You · via Inbox" or " · via Inbox" for an Inbox reply, through the pure `presentJ5QueuedMessage` in `timelinePresentation.ts`. Anything J5 did not unwrap keeps upstream's `QueuedRunSender`, and J5's old `From :` prefix is gone. "Sent by T3 Code" reads "Sent by J5 Code". The mobile queue sheet has no sides. `apps/mobile/src/lib/filePreview.test.ts`, which renders `ThreadFeed` with upstream's state modules mocked, mocks `timelineState.ts` beside them. Proofs: `apps/mobile/src/j5/a2a/timelinePresentation.test.ts`, `packages/client-runtime/src/j5/participantIdentity.test.ts`, and the files' rows in `apps/mobile/src/j5/upstreamSeams.test.ts`. On every rebase, keep the calls that test lists; if upstream moves the agent fold out of `renderFeedEntry`, move the seam with it. 98. Mobile reads artifacts ([#833](https://github.com/Jacksondr5/j5code/issues/833)), landing two reserved mobile seams. Route registration: `apps/mobile/src/Stack.tsx` imports J5-owned `j5ThreadArtifactRoutes` (`apps/mobile/src/j5/artifacts/routes.ts`) and spreads it after `ThreadFile`, adding the thread-scoped `ThreadArtifacts` list and `ThreadArtifact` viewer (`apps/mobile/src/j5/artifacts/ThreadArtifactsScreen.tsx`), read-only, with no delete. Link resolver: `onMarkdownLinkPress` in `apps/mobile/src/features/threads/ThreadFeed.tsx` makes one call to J5-owned `openArtifactLink` before its thread, media and file branches, so an `artifacts/…` link opens the viewer instead of a missing workspace file; its `fileContextMenu` and `onFileContextMenuAction` each make one call first (`artifactLinkContextMenu`, `onArtifactLinkMenuAction`), so an artifact link's long press offers Open artifact and Copy path instead of workspace-file actions. Links inside a Markdown artifact go through the same helpers in the J5 viewer. Recognition, preview kind and the HTTP read are shared with web in `packages/client-runtime/src/j5/artifacts.ts`. No upstream entry point reaches the list yet; it is one tap from any opened artifact. @@ -529,7 +529,7 @@ migrations after upstream migrations. 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. -104. A Crew notice with nothing for the person takes no timeline row ([#741](https://github.com/Jacksondr5/j5code/issues/741), Bryant 2026-10-27). `apps/web/src/components/chat/MessagesTimeline.tsx` carries one J5 import and one changed line in `ConversationTimeline`: `const rows = useStableRows(withoutHiddenCrewNotices(rawRows), listIdentityKey)`, J5-owned in `apps/web/src/j5/crew/crewNotices.logic.ts`. It drops the message rows of platform Crew notices (`createdBy === "system"`) whose `crewNoticeLines` are empty, a clean launch report or a clean finish, after upstream has derived the rows, so each notice still bounds the Captain turn it started (`deriveActiveVisualResponseRunIds`, terminal assistant messages and rollback all read user messages as turn boundaries), and returns the same array when nothing is hidden, cached per input array, because `useStableRows` compares its source by identity. Upstream's minimap reads the filtered rows, so an ask's reply preview can run past a hidden notice; that is accepted. Proof: `apps/web/src/j5/crew/crewNotices.logic.test.ts`, "keeps the rows a hidden notice bounded". On a pin advance: if upstream stops deriving rows through `useStableRows`, apply the filter to whatever the list renders, after turn boundaries are computed, never to the entries before them. +104. A Crew notice with nothing for the person takes no timeline row ([#741](https://github.com/Jacksondr5/j5code/issues/741), Bryant 2026-10-27). `apps/web/src/components/chat/MessagesTimeline.tsx` carries one J5 import and one changed line in `ConversationTimeline`: `const rows = useStableRows(withoutHiddenCrewNotices(rawRows), listIdentityKey)`, J5-owned in `apps/web/src/j5/crew/crewNotices.logic.ts` over the shared filter in `packages/client-runtime/src/j5/crewNotices.ts`. It drops the message rows of platform Crew notices (`createdBy === "system"`) whose `crewNoticeLines` are empty, a clean launch report or a clean finish, after upstream has derived the rows, so each notice still bounds the Captain turn it started (`deriveActiveVisualResponseRunIds`, terminal assistant messages and rollback all read user messages as turn boundaries), and returns the same array when nothing is hidden, cached per input array, because `useStableRows` compares its source by identity. Upstream's minimap reads the filtered rows, so an ask's reply preview can run past a hidden notice; that is accepted. On mobile, `apps/mobile/src/features/threads/ThreadFeed.tsx` wraps `presentedFeed` in the same filter, after `useThreadFeedPresentation` has run `deriveThreadFeedPresentation`, which also reads user messages as turn boundaries ([#918](https://github.com/Jacksondr5/j5code/issues/918)). Proof: `packages/client-runtime/src/j5/crewNotices.test.ts`, "keeps the rows a hidden notice bounded", and the mobile row in `apps/mobile/src/j5/upstreamSeams.test.ts`. On a pin advance: if upstream stops deriving rows through `useStableRows`, apply the filter to whatever the list renders, after turn boundaries are computed, never to the entries before them. 105. Agent Setup and Crew approval settings ([#743](https://github.com/Jacksondr5/j5code/issues/743)): `packages/contracts/src/settings.ts` registers J5's `crewAutoApprove` boolean (default off) in server settings, patches, and project overrides. `apps/web/src/components/settings/settingsSearch.ts` renames the existing `/settings/personas` destination to Agent Setup and adds search terms and the scoped Crew setting target. `apps/mobile/src/features/settings/SettingsRouteScreen.tsx` and `apps/mobile/src/Stack.tsx` rename the existing Personas navigation entry and title to Agent Setup. Runtime behavior and the web sections stay in J5-owned files; mobile still exposes only the persona library. @@ -970,7 +970,7 @@ explicitly marked. | `packages/shared/src/composerTrigger.ts` | A | 49, Saved-agent mentions | | `packages/shared/src/composerInlineTokens.ts` | A | 49, Saved-agent mentions | | `apps/mobile/src/features/threads/ComposerCommandPopover.tsx` | A | 49, Saved-agent mentions | -| `apps/mobile/src/features/threads/ThreadFeed.tsx` | N | 97, 98 | +| `apps/mobile/src/features/threads/ThreadFeed.tsx` | N | 97, 98, 104 | | `apps/mobile/src/features/threads/ThreadQueueControl.tsx` | N | 97, 99 | | `apps/mobile/src/lib/filePreview.test.ts` | N | 97, 99 | | `apps/mobile/src/features/threads/thread-search-match.tsx` | N | 99 | diff --git a/apps/mobile/src/features/threads/ThreadFeed.tsx b/apps/mobile/src/features/threads/ThreadFeed.tsx index b92cd1e1b6a3b..0d84ce9b6fe82 100644 --- a/apps/mobile/src/features/threads/ThreadFeed.tsx +++ b/apps/mobile/src/features/threads/ThreadFeed.tsx @@ -293,14 +293,17 @@ import { } from "./ThreadMarkdownImage"; import { openSettings } from "../settings/settings-navigation"; import { + J5_PROMPT_ICONS, J5MessageAuthorLine, J5OpenSenderThread, j5FoldHeader, + type J5FeedMessagePresentation, renderJ5TimelineNotice, resolveJ5FeedMessage, type J5Timeline, } from "../../j5/a2a/timeline"; import { useJ5Timeline } from "../../j5/a2a/timelineState"; +import { withoutHiddenCrewNotices } from "@t3tools/client-runtime/j5/crew-notices"; import { useSelectWorkspaceDetail } from "../workspace/useSelectWorkspaceDetail"; const WIDE_MARKDOWN_BLOCK_OPTIONS = { @@ -1482,10 +1485,11 @@ function ThreadAutomationMessageRow(props: { readonly text: string; readonly context?: OrchestrationMessageContext; readonly scheduledTaskId: ScheduledTaskId | undefined; + /** J5's playbook step or native question, which this row draws under J5's own heading. */ + readonly prompt: J5FeedMessagePresentation["prompt"]; readonly timestampLabel: string; readonly expanded: boolean; readonly onToggle: () => void; - readonly bubbleColor: ColorValue; readonly bubbleMaxWidth: number | "85%"; readonly contentMaxWidth: number; readonly iconSubtleColor: ColorValue; @@ -1502,21 +1506,24 @@ function ThreadAutomationMessageRow(props: { : null, ); const taskTitle = tasks.data?.tasks.find((task) => task.id === props.scheduledTaskId)?.title; - const summary = taskTitle ?? props.text.trim().split(/\r?\n/, 1)[0] ?? ""; + const summary = + props.prompt?.preview ?? taskTitle ?? props.text.trim().split(/\r?\n/, 1)[0] ?? ""; + const label = props.prompt?.label ?? "Automation"; + // J5 (case 97): the platform's prompts sit on the left without a fill, never as the reader's. return ( - + - - Automation + + {label} - + {summary} {props.expanded ? ( - + {props.scheduledTaskId ? ( props.onToggleWorkRow(rowId, entry.id)} - bubbleColor={userBubbleColor} bubbleMaxWidth={props.duoColumns ? "85%" : props.userBubbleMaxWidth} contentMaxWidth={props.userBubbleMaxWidth - USER_BUBBLE_HORIZONTAL_PADDING * 2} iconSubtleColor={iconSubtleColor} - markdownStyles={markdownStyles.user} + markdownStyles={markdownStyles.assistant} reviewCommentColors={props.reviewCommentColors} skills={props.skills} linkHandlers={props.markdownLinkHandlers} @@ -3383,9 +3400,13 @@ export const ThreadFeed = memo(function ThreadFeed({ const [loadedListKey, setLoadedListKey] = useState(null); const { jumpToMessageId } = props; const jumpReady = !!jumpToMessageId && loadedListKey === `${feedThreadKey}:filled`; - const presentedFeed = appendGuestPendingMessages( - useThreadFeedPresentation(props, expandedTurnIds, expandedWorkGroups), - guestShare, + // J5 (case 104): after derivation, so a hidden Crew notice still bounds the turn it started. + const presentedFeed = withoutHiddenCrewNotices( + appendGuestPendingMessages( + useThreadFeedPresentation(props, expandedTurnIds, expandedWorkGroups), + guestShare, + ), + (entry) => (entry.type === "message" ? entry.message : undefined), ); const jumpRunId = jumpReady && diff --git a/apps/mobile/src/j5/a2a/timeline.tsx b/apps/mobile/src/j5/a2a/timeline.tsx index 69a36921e4598..292ce06946df9 100644 --- a/apps/mobile/src/j5/a2a/timeline.tsx +++ b/apps/mobile/src/j5/a2a/timeline.tsx @@ -2,7 +2,15 @@ import { j5MessageAuthorName, j5SenderThreadRef, } from "@t3tools/client-runtime/j5/participant-identity"; +import { + crewApprovalSummary, + crewDeclinedSummary, + crewNoticeLines, + type CrewNoticePresentation, +} from "@t3tools/client-runtime/j5/crew-notices"; import type { + J5NoticeKind, + J5PromptKind, J5UserMessageInput, J5UserMessagePresentation, } from "@t3tools/client-runtime/j5/user-message"; @@ -10,6 +18,7 @@ import { isSharedNote } from "@t3tools/client-runtime/j5/shared-conversation"; import { useState, type ReactNode } from "react"; import { Pressable, View } from "react-native"; +import { SymbolView, type AppSymbolName } from "../../components/ui/AppSymbol"; import { AppText as Text } from "../../components/ui/AppText"; import { useOpenLinkedThread } from "../../features/threads/useOpenLinkedThread"; import { cn } from "../../lib/cn"; @@ -22,60 +31,242 @@ import { type J5Timeline, } from "./timelinePresentation"; -export { j5FoldHeader, resolveJ5FeedMessage, type J5Timeline } from "./timelinePresentation"; +export { + j5FoldHeader, + resolveJ5FeedMessage, + type J5FeedMessagePresentation, + type J5Timeline, +} from "./timelinePresentation"; -/** Silence lines and raw cards in place of upstream's row (`presentJ5TimelineNotice`). */ +/** + * J5's platform notices in place of upstream's row, each one grey line on the left that opens + * to its detail (web's `J5NoticeLine`): a shared conversation's note, what a Crew member was told, + * a Crew notice's lines, and every notice the classifier has a summary for. + */ export function renderJ5TimelineNotice(input: { readonly message: J5UserMessageInput; readonly timestampLabel: string; + readonly timeline: J5Timeline; }) { if (isSharedNote(input.message)) { return ; } - const notice = presentJ5TimelineNotice(input.message); + const notice = presentJ5TimelineNotice(input.message, input.timeline.labels); if (notice === null) return null; - if (notice.kind === "silence") { + if (notice.kind === "crew") { return ( - - - ⚠ {notice.summary} - {input.timestampLabel ? ` · ${input.timestampLabel}` : null} - - + ); } - if (notice.kind === "context") { - return ; - } return ( - - {notice.label} - - {input.message.text} - + + {notice.kind === "context" ? ( + // What the model read, long and not written for the person, so it opens on request. + + + {notice.text} + + + ) : ( + + {notice.detail === null ? null : } + + )} ); } -/** What the platform told a Crew member: its title, and the model's own reading once opened. */ -function CrewContextNotice(props: { readonly title: string; readonly text: string }) { +const NOTICE_ICONS: Partial> = { + silence: "bubble.left", + "not-delivered": "exclamationmark.circle", + "exchange-dropped": "slash.circle", + "exchange-withdrawn": "arrow.uturn.backward", +}; + +/** The icon for each of J5's prompts in upstream's Automation row. */ +export const J5_PROMPT_ICONS: Record, AppSymbolName> = { + "playbook-step": "list.number", + "native-question": "questionmark.bubble", +}; + +const TONE_TINT = { + bad: "accent-danger-foreground", + warn: "accent-warning-foreground", + none: "accent-foreground-muted", +} as const; + +/** One grey line with an icon, a summary and the time; with a detail, it opens beneath a rule. */ +function J5NoticeLine(props: { + readonly icon: AppSymbolName; + readonly tone?: keyof typeof TONE_TINT; + readonly summary: string; + readonly timestampLabel: string; + readonly children?: ReactNode; +}) { const [open, setOpen] = useState(false); - return ( - - setOpen((value) => !value)} + const hasDetail = props.children !== undefined && props.children !== null; + const line = ( + <> + + - - {open ? "▾" : "▸"} {props.title} from J5 - - - {open ? ( - - {props.text} + {props.summary} + + {props.timestampLabel ? ( + + {props.timestampLabel} ) : null} + + ); + const lineClass = "max-w-full flex-row items-center gap-1.5 py-0.5"; + return ( + + {hasDetail ? ( + setOpen((value) => !value)} + > + {line} + + + ) : ( + {line} + )} + {hasDetail && open ? ( + {props.children} + ) : null} + + ); +} + +function J5NoticeDetailText(props: { readonly text: string }) { + return ( + + {props.text} + + ); +} + +function OpenSeatThread(props: { + readonly environmentId: string; + readonly threadId: string; + readonly label: string; +}) { + const openLinkedThread = useOpenLinkedThread(); + return ( + + openLinkedThread({ environmentId: props.environmentId, threadId: props.threadId }) + } + > + {props.label} + + ); +} + +/** + * A Crew notice in the Captain's thread (web's `renderCrewNotice`): the approval or decline line, + * then one line per seat that needs the person. A seat whose thread was never created has no link. + */ +function CrewNotice(props: { + readonly notice: CrewNoticePresentation; + readonly timestampLabel: string; + readonly environmentId: string; +}) { + const { notice, timestampLabel, environmentId } = props; + if (notice.kind === "gate" && notice.decision === "declined") { + const requested = notice.requestedSeats + .map((seat) => `${seat.seat} (${seat.agentId})`) + .join(", "); + return ( + + + + + + ); + } + const summary = crewApprovalSummary(notice); + return ( + + {summary === null || notice.kind !== "gate" ? null : ( + + {notice.changes === null ? null : ( + + )} + + {notice.roster.map((seat) => ( + + ))} + + + )} + {crewNoticeLines(notice).map((line, index) => ( + + {line.detail === null && line.threadId === null ? null : ( + <> + {line.detail === null ? null : } + {line.threadId === null ? null : ( + + + + )} + + )} + + ))} ); } diff --git a/apps/mobile/src/j5/a2a/timelinePresentation.test.ts b/apps/mobile/src/j5/a2a/timelinePresentation.test.ts index 76b93b55491ba..6c632a47e847a 100644 --- a/apps/mobile/src/j5/a2a/timelinePresentation.test.ts +++ b/apps/mobile/src/j5/a2a/timelinePresentation.test.ts @@ -56,7 +56,7 @@ const briefRaw = [ const silenceRaw = [ "[Cross-agent messaging system notice: turn-ended-no-reply]", "", - "Captain's turn ended without replying on exchange:one. The latest delivered message was processed.", + "agent:captain's turn ended without replying on exchange:one. The latest delivered message was processed.", "", "This is a platform-authored delivery signal, not a peer reply.", ].join("\n"); @@ -136,7 +136,7 @@ describe("resolveJ5FeedMessage", () => { }); }); - it("leaves a message J5 cannot read to upstream's row as stored", () => { + it("leaves a message J5 cannot read to upstream's row as stored, on the left if the platform's", () => { const unknown = delivery("agent", "[Cross-agent message from x]\n\nv7"); expect(resolveJ5FeedMessage(unknown, timeline(null))).toMatchObject({ j5: null, @@ -144,6 +144,31 @@ describe("resolveJ5FeedMessage", () => { preview: null, text: unknown.text, }); + const platform = { id: "other", role: "user", createdBy: "system" as const, text: "Hm." }; + expect(resolveJ5FeedMessage(platform, timeline(null))).toMatchObject({ + j5: null, + prompt: null, + side: "left", + }); + }); + + it("sends a playbook step to upstream's Automation row under J5's heading", () => { + const step = { + id: "message:step", + role: "user", + createdBy: "system" as const, + text: "\nstep: build | Build the timeline\nposition: 2 of 3\n\n\nBuild it.\n\n", + }; + expect(resolveJ5FeedMessage(step, timeline(null))).toMatchObject({ + attribution: "automation", + text: "Build it.", + side: "left", + prompt: { + kind: "playbook-step", + label: "Playbook step 2 of 3", + preview: "Build the timeline", + }, + }); }); }); @@ -165,35 +190,48 @@ describe("presentJ5QueuedMessage", () => { }); describe("presentJ5TimelineNotice", () => { - it("summarizes a silence in one line", () => { - expect(presentJ5TimelineNotice(delivery("system", silenceRaw))).toEqual({ - kind: "silence", + const labels = new Map([["agent:captain", "Captain"]]); + + it("names the participants in a notice's line and detail", () => { + expect(presentJ5TimelineNotice(delivery("system", silenceRaw), labels)).toEqual({ + kind: "line", + noticeKind: "silence", summary: "Captain's turn ended without replying", + detail: "The latest delivered message was processed.", }); }); - it("keeps a delivery notice it cannot read, and a Crew notice, as a labelled raw card", () => { + it("reads a Crew notice for its lines, and leaves a delivery notice it cannot read to upstream", () => { expect( - presentJ5TimelineNotice(delivery("system", "[Cross-agent messaging system notice: v7]\n\n?")), - ).toEqual({ kind: "raw", label: "Raw A2A delivery" }); + presentJ5TimelineNotice( + delivery("system", "[Cross-agent messaging system notice: v7]\n\n?"), + labels, + ), + ).toBeNull(); expect( - presentJ5TimelineNotice({ - id: "message:crew", - role: "user", - createdBy: "system", - text: "\nproposal_id: crew:proposal:1\nkind: roster\ndecision: declined\n", - }), - ).toEqual({ kind: "raw", label: "Crew notice" }); + presentJ5TimelineNotice( + { + id: "message:crew", + role: "user", + createdBy: "system", + text: "\nproposal_id: crew:proposal:1\nkind: roster\ndecision: declined\n", + }, + labels, + ), + ).toMatchObject({ kind: "crew", notice: { kind: "gate", decision: "declined" } }); }); - it("shows what a Crew member was told as a card of its own, not as the reader's message", () => { + it("shows what a Crew member was told as a line of its own, not as the reader's message", () => { expect( - presentJ5TimelineNotice({ - id: "message:j5:crew-context:abc", - role: "user", - createdBy: "system", - text: "\n\njoined: security\n\n", - }), + presentJ5TimelineNotice( + { + id: "message:j5:crew-context:abc", + role: "user", + createdBy: "system", + text: "\n\njoined: security\n\n", + }, + labels, + ), ).toEqual({ kind: "context", title: "Roster changed", @@ -202,14 +240,12 @@ describe("presentJ5TimelineNotice", () => { }); it("leaves letters and upstream's own messages to their rows", () => { - expect(presentJ5TimelineNotice(delivery("agent", askRaw))).toBeNull(); + expect(presentJ5TimelineNotice(delivery("agent", askRaw), labels)).toBeNull(); expect( - presentJ5TimelineNotice({ - id: "message:pr-watch:1", - role: "user", - createdBy: "system", - text: "PR merged", - }), + presentJ5TimelineNotice( + { id: "message:pr-watch:1", role: "user", createdBy: "system", text: "PR merged" }, + labels, + ), ).toBeNull(); }); }); diff --git a/apps/mobile/src/j5/a2a/timelinePresentation.ts b/apps/mobile/src/j5/a2a/timelinePresentation.ts index 10195a367c663..b0a7a7ca2a281 100644 --- a/apps/mobile/src/j5/a2a/timelinePresentation.ts +++ b/apps/mobile/src/j5/a2a/timelinePresentation.ts @@ -1,10 +1,18 @@ -import { presentCrewContext } from "@t3tools/client-runtime/j5/crew-notices"; -import type { ParticipantIdentities } from "@t3tools/client-runtime/j5/participant-identity"; +import { + presentCrewContext, + presentCrewNotice, + type CrewNoticePresentation, +} from "@t3tools/client-runtime/j5/crew-notices"; +import { + nameJ5NoticeParticipants, + type ParticipantIdentities, +} from "@t3tools/client-runtime/j5/participant-identity"; import { firstLine, - isJ5DeliveryMessage, presentJ5UserMessage, resolveJ5UserMessagePresentation, + type J5NoticeKind, + type J5PromptKind, type J5UserMessageInput, } from "@t3tools/client-runtime/j5/user-message"; import type { EnvironmentId } from "@t3tools/contracts"; @@ -23,7 +31,8 @@ export interface J5Timeline extends ParticipantIdentities { /** * Upstream's user-message presentation with J5's reading on top (the shared classifier): the * letter without its envelope, `"agent"` for every participant so it folds, which side it sits - * on, and the folded row's preview where J5 read the message. + * on, and the folded row's preview where J5 read the message. A playbook step or a native + * question is `"automation"`, so upstream's Automation row draws it with J5's `prompt` heading. */ export function resolveJ5FeedMessage(message: J5UserMessageInput, timeline: J5Timeline) { const presentation = resolveJ5UserMessagePresentation(message, { @@ -34,15 +43,32 @@ export function resolveJ5FeedMessage(message: J5UserMessageInput, timeline: J5Ti j5?.group === "person" && !j5.viaInbox && message.id !== undefined ? timeline.sharedAuthors.get(String(message.id)) : undefined; + const prompt = j5 === null ? j5Prompt(message) : null; return { ...presentation, + ...(prompt === null + ? null + : { attribution: "automation" as const, text: prompt.text, scheduledTaskId: undefined }), + prompt, // Another person's message in a shared conversation sits on the left, named (AC16). sharedAuthor, - side: sharedAuthor !== undefined && !sharedAuthor.you ? "left" : (j5?.side ?? "right"), + // The platform's words are never the reader's, even in a notice nothing here can read. + side: + sharedAuthor !== undefined && !sharedAuthor.you + ? "left" + : (j5?.side ?? (message.createdBy === "system" ? "left" : "right")), preview: j5?.group === "participant" && j5.unwrapped ? j5.preview : null, }; } +/** J5's platform prompts other than an automation run, which upstream's row reads itself. */ +function j5Prompt(message: J5UserMessageInput) { + const j5 = presentJ5UserMessage(message); + if (j5?.group !== "prompt" || j5.kind === "automation") return null; + const kind: Exclude = j5.kind; + return { kind, label: j5.label, preview: j5.preview, text: j5.text }; +} + export type J5FeedMessagePresentation = ReturnType; /** @@ -76,28 +102,35 @@ export function j5FoldHeader( } /** - * J5's platform notices that upstream's row would draw as the reader's own message: a silence, - * which has a plain summary, what a Crew member was told (a card that opens to the text), and a - * Crew notice or a delivery notice this client cannot read yet, which keep their raw text until - * the notices are redrawn. Null for every other message. + * J5's platform notices, drawn in place of upstream's row: what a Crew member was told, a Crew + * notice, and any notice the classifier has a summary for, with participants named. Null for + * every other message, a notice nothing here can read included, which upstream's row shows. */ export function presentJ5TimelineNotice( message: J5UserMessageInput, + labels: ReadonlyMap, ): - | { readonly kind: "silence"; readonly summary: string | null } - | { readonly kind: "raw"; readonly label: string } | { readonly kind: "context"; readonly title: string; readonly text: string } + | { readonly kind: "crew"; readonly notice: CrewNoticePresentation } + | { + readonly kind: "line"; + readonly noticeKind: J5NoticeKind; + readonly summary: string; + readonly detail: string | null; + } | null { if (message.role !== "user" || message.createdBy !== "system") return null; const context = presentCrewContext(message); if (context !== null) return { kind: "context", title: context.title, text: context.text }; - const presentation = presentJ5UserMessage(message); - if (presentation?.group !== "notice") { - return isJ5DeliveryMessage(message) ? { kind: "raw", label: "Raw A2A delivery" } : null; - } - if (presentation.kind === "silence") return { kind: "silence", summary: presentation.summary }; - if (presentation.kind === "crew-gate" || presentation.kind === "crew-seats") { - return { kind: "raw", label: "Crew notice" }; - } - return isJ5DeliveryMessage(message) ? { kind: "raw", label: "Raw A2A delivery" } : null; + const crew = presentCrewNotice(message); + if (crew !== null) return { kind: "crew", notice: crew }; + const notice = presentJ5UserMessage(message); + if (notice?.group !== "notice" || notice.summary === null) return null; + const named = (text: string) => nameJ5NoticeParticipants(text, notice.participantIds, labels); + return { + kind: "line", + noticeKind: notice.kind, + summary: named(notice.summary), + detail: notice.detail === null ? null : named(notice.detail), + }; } diff --git a/apps/mobile/src/j5/upstreamSeams.test.ts b/apps/mobile/src/j5/upstreamSeams.test.ts index 8381da8635f50..eaca533a95d4a 100644 --- a/apps/mobile/src/j5/upstreamSeams.test.ts +++ b/apps/mobile/src/j5/upstreamSeams.test.ts @@ -115,7 +115,10 @@ const SEAMS: ReadonlyArray = [ from: "../../j5/a2a/timeline", reaches: [ "resolveJ5FeedMessage(message, props.j5Timeline)", - "renderJ5TimelineNotice({ message, timestampLabel })", + "renderJ5TimelineNotice({", + "timeline: props.j5Timeline,", + "prompt={presentation.prompt}", + "J5_PROMPT_ICONS[props.prompt.kind]", " = [ "j5FoldHeader(", ], }, + { + file: "features/threads/ThreadFeed.tsx", + record: "case 104: a Crew notice with nothing for the person takes no row", + from: "@t3tools/client-runtime/j5/crew-notices", + reaches: ["withoutHiddenCrewNotices(\n appendGuestPendingMessages("], + }, { file: "lib/filePreview.test.ts", record: "case 97: Timeline delegate", diff --git a/apps/web/src/j5/crew/crewNotices.logic.test.ts b/apps/web/src/j5/crew/crewNotices.logic.test.ts index 9724bb52101e3..53d5c49ade497 100644 --- a/apps/web/src/j5/crew/crewNotices.logic.test.ts +++ b/apps/web/src/j5/crew/crewNotices.logic.test.ts @@ -4,11 +4,10 @@ import { crewApprovalSummary, crewDeclinedSummary, crewNoticeLines, + isHiddenCrewNotice, presentCrewNotice, } from "@t3tools/client-runtime/j5/crew-notices"; -import { isHiddenCrewNotice, withoutHiddenCrewNotices } from "./crewNotices.logic"; - const approvedGate = [ "", "proposal_id: crew:j5:a2a:mcp:s:proposal:r1", @@ -287,33 +286,6 @@ describe("crew notices in the Captain's thread", () => { ]); }); - it("keeps the rows a hidden notice bounded, dropping only that notice's row", () => { - const row = (id: string, message: { role: string; createdBy: string; text: string }) => ({ - kind: "message", - id, - message, - }); - const visible = [ - row("ask", { role: "user", createdBy: "user", text: "Ship it" }), - { kind: "work", id: "w1" }, - ]; - // Nothing hidden: the same array comes back, so the list's identity check holds. - expect(withoutHiddenCrewNotices(visible)).toBe(visible); - const rows = [ - ...visible, - row("launch", { - role: "user", - createdBy: "system", - text: "\nseat: builder\nparticipant_id: agent:b\nthread_id: thread:b\nrun_status: completed\n", - }), - row("reply", { role: "assistant", createdBy: "agent", text: "Crew is running." }), - ]; - const shown = withoutHiddenCrewNotices(rows); - expect(shown.map((entry) => entry.id)).toEqual(["ask", "w1", "reply"]); - // The same input gives the same output array. - expect(withoutHiddenCrewNotices(rows)).toBe(shown); - }); - it("presents an added seat as new and a decline with what was requested", () => { const addition = approvedGate .replace("kind: roster", "kind: addition") diff --git a/apps/web/src/j5/crew/crewNotices.logic.ts b/apps/web/src/j5/crew/crewNotices.logic.ts index 6ef421c23fd3f..bf5828b854ea7 100644 --- a/apps/web/src/j5/crew/crewNotices.logic.ts +++ b/apps/web/src/j5/crew/crewNotices.logic.ts @@ -1,35 +1,12 @@ import { - crewApprovalSummary, - crewNoticeLines, - presentCrewNotice, + withoutHiddenCrewNotices as withoutHidden, type CrewNoticeMessage, } from "@t3tools/client-runtime/j5/crew-notices"; -/** Completed finishes and successful additions take no row in the timeline. */ -export const isHiddenCrewNotice = (message: CrewNoticeMessage): boolean => { - const notice = presentCrewNotice(message); - if (notice === null || (notice.kind === "gate" && notice.decision === "declined")) return false; - return crewApprovalSummary(notice) === null && crewNoticeLines(notice).length === 0; -}; - -const visibleRows = new WeakMap>(); - -/** - * The timeline's rows without the hidden Crew notices (FORK.md case 104). It runs on rows already - * derived, because upstream reads every user message as a turn boundary: dropping a notice before - * that would merge the Captain turn it started into the one before. The result is the input when - * nothing is hidden and is cached per input, since the list compares its rows by identity. - */ +/** The timeline's message rows without the hidden Crew notices (FORK.md case 104). */ export const withoutHiddenCrewNotices = ( rows: Array, -): Array => { - const cached = visibleRows.get(rows); - if (cached !== undefined) return cached as Array; - const hidden = (row: Row) => - row.kind === "message" && - "message" in row && - isHiddenCrewNotice(row.message as CrewNoticeMessage); - const visible = rows.some(hidden) ? rows.filter((row) => !hidden(row)) : rows; - visibleRows.set(rows, visible); - return visible; -}; +): Array => + withoutHidden(rows, (row) => + row.kind === "message" && "message" in row ? (row.message as CrewNoticeMessage) : undefined, + ); diff --git a/packages/client-runtime/src/j5/crewNotices.test.ts b/packages/client-runtime/src/j5/crewNotices.test.ts index 270a519e90d15..59b9ace814773 100644 --- a/packages/client-runtime/src/j5/crewNotices.test.ts +++ b/packages/client-runtime/src/j5/crewNotices.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from "vite-plus/test"; -import { presentCrewContext } from "./crewNotices.ts"; +import { presentCrewContext, withoutHiddenCrewNotices } from "./crewNotices.ts"; const context = (text: string) => `\n${text}\n`; @@ -42,3 +42,30 @@ describe("presentCrewContext", () => { expect(presentCrewContext(system(context(" ")))).toBeNull(); }); }); + +describe("withoutHiddenCrewNotices", () => { + it("keeps the rows a hidden notice bounded, dropping only that notice's row", () => { + type Row = { readonly id: string; readonly message?: ReturnType }; + const messageOf = (row: Row) => row.message; + const visible: ReadonlyArray = [ + { id: "ask", message: { role: "user", createdBy: "user", text: "Ship it" } }, + { id: "w1" }, + ]; + // Nothing hidden: the same array comes back, so the list's identity check holds. + expect(withoutHiddenCrewNotices(visible, messageOf)).toBe(visible); + const rows: ReadonlyArray = [ + ...visible, + { + id: "launch", + message: system( + "\nseat: builder\nparticipant_id: agent:b\nthread_id: thread:b\nrun_status: completed\n", + ), + }, + { id: "reply", message: { role: "assistant", createdBy: "agent", text: "Crew is running." } }, + ]; + const shown = withoutHiddenCrewNotices(rows, messageOf); + expect(shown.map((entry) => entry.id)).toEqual(["ask", "w1", "reply"]); + // The same input gives the same output array. + expect(withoutHiddenCrewNotices(rows, messageOf)).toBe(shown); + }); +}); diff --git a/packages/client-runtime/src/j5/crewNotices.ts b/packages/client-runtime/src/j5/crewNotices.ts index 926f333871996..c4a13592ea9ca 100644 --- a/packages/client-runtime/src/j5/crewNotices.ts +++ b/packages/client-runtime/src/j5/crewNotices.ts @@ -339,3 +339,35 @@ export const crewNoticeSummary = (notice: CrewNoticePresentation): string | null notice.kind === "gate" && notice.decision === "declined" ? crewDeclinedSummary(notice) : crewApprovalSummary(notice); + +/** Completed finishes and successful additions take no row in the timeline. */ +export const isHiddenCrewNotice = (message: CrewNoticeMessage): boolean => { + const notice = presentCrewNotice(message); + if (notice === null || (notice.kind === "gate" && notice.decision === "declined")) return false; + return crewApprovalSummary(notice) === null && crewNoticeLines(notice).length === 0; +}; + +const visibleRows = new WeakMap>(); + +/** + * A timeline's rows without the hidden Crew notices. Run it on rows already derived: every user + * message is a turn boundary, so dropping a notice before that would merge the Captain turn it + * started into the one before. The result is the input when nothing is hidden and is cached per + * input, since a list compares its rows by identity. + */ +export const withoutHiddenCrewNotices = >( + rows: Rows, + messageOf: (row: Rows[number]) => CrewNoticeMessage | undefined, +): Rows => { + const cached = visibleRows.get(rows); + if (cached !== undefined) return cached as Rows; + const hidden = (row: Rows[number]) => { + const message = messageOf(row); + return message !== undefined && isHiddenCrewNotice(message); + }; + const visible = rows.some(hidden) + ? (rows.filter((row) => !hidden(row)) as unknown as Rows) + : rows; + visibleRows.set(rows, visible); + return visible; +};