From cd17f91d056c7566eb4bd11fa54a4dcc2441b18d Mon Sep 17 00:00:00 2001 From: Jackson Miller Date: Sun, 8 Nov 2026 23:40:04 -0500 Subject: [PATCH] fix(j5): a persona draft's definition keeps its layout in the Recorded by J5 panel The panel wrapped a persona draft's quoted definition as prose, so wrapped lines lost their indentation. A shared splitter now separates the record's indented block, by indentation alone, and web and mobile show it in a monospace block that scrolls sideways, with the prose still wrapping. Co-Authored-By: Claude Opus 5.5 --- apps/mobile/src/j5/inbox/InboxScreen.tsx | 9 ++---- apps/mobile/src/j5/inbox/J5RecordPanel.tsx | 32 +++++++++++++++++++ apps/web/src/j5/a2a/J5RecordPanel.tsx | 22 +++++++++++-- packages/client-runtime/src/j5/inbox.test.ts | 33 ++++++++++++++++++++ packages/client-runtime/src/j5/inbox.ts | 24 ++++++++++++++ 5 files changed, 111 insertions(+), 9 deletions(-) create mode 100644 apps/mobile/src/j5/inbox/J5RecordPanel.tsx diff --git a/apps/mobile/src/j5/inbox/InboxScreen.tsx b/apps/mobile/src/j5/inbox/InboxScreen.tsx index e4385a6fe0c91..a0d71f3dab07b 100644 --- a/apps/mobile/src/j5/inbox/InboxScreen.tsx +++ b/apps/mobile/src/j5/inbox/InboxScreen.tsx @@ -35,6 +35,7 @@ import { j5Environment } from "../state"; import { type ClosedItem, useInboxAnswers } from "./inboxAnswers"; import { AgentQuestionsSection, SeatApprovalsSection } from "./InboxCrewRequests"; import { WorktreeCleanupsSection } from "./InboxWorktreeCleanups"; +import { J5RecordPanel } from "./J5RecordPanel"; import { answeredInboxQueryAtom, answeredInboxSourcesAtom, @@ -290,13 +291,7 @@ function InboxItem(props: { {[item.escalation?.summary, item.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} - - ), + record === undefined ? null : , )} {item.followUps?.map((followUp) => ( diff --git a/apps/mobile/src/j5/inbox/J5RecordPanel.tsx b/apps/mobile/src/j5/inbox/J5RecordPanel.tsx new file mode 100644 index 0000000000000..2b65ca7158351 --- /dev/null +++ b/apps/mobile/src/j5/inbox/J5RecordPanel.tsx @@ -0,0 +1,32 @@ +import { splitRecordText } from "@t3tools/client-runtime/j5/inbox"; +import { ScrollView, View } from "react-native"; + +import { AppText as Text } from "../../components/ui/AppText"; + +/** + * J5's own record, apart from the agent's words, as web's panel shows it: plain text, so they + * can't alter it, and an indented block it quotes, such as a persona draft's definition, keeps its + * layout and scrolls sideways. + */ +export function J5RecordPanel(props: { readonly text: string }) { + return ( + + Recorded by J5 + {splitRecordText(props.text).map((part, index) => + part.kind === "block" ? ( + // oxlint-disable-next-line react/no-array-index-key -- the parts are the record's fixed order. + + + {part.text} + + + ) : ( + // oxlint-disable-next-line react/no-array-index-key -- the parts are the record's fixed order. + + {part.text} + + ), + )} + + ); +} diff --git a/apps/web/src/j5/a2a/J5RecordPanel.tsx b/apps/web/src/j5/a2a/J5RecordPanel.tsx index 90f160208c4bb..2f5a98c529254 100644 --- a/apps/web/src/j5/a2a/J5RecordPanel.tsx +++ b/apps/web/src/j5/a2a/J5RecordPanel.tsx @@ -1,7 +1,10 @@ +import { splitRecordText } from "@t3tools/client-runtime/j5/inbox"; + /** * Text J5 itself recorded, such as a blocked persona's escalation, shown beside an agent's * message rather than inside it. It renders as plain text, so nothing an agent writes, and - * no markup in the record, can hide it, swallow it, or imitate it. + * no markup in the record, can hide it, swallow it, or imitate it. An indented block it quotes, + * such as a persona draft's definition, keeps its layout and scrolls sideways. */ export function J5RecordPanel(props: { readonly text: string; readonly label?: string }) { return ( @@ -13,7 +16,22 @@ export function J5RecordPanel(props: { readonly text: string; readonly label?: s

{props.label ?? "Recorded by J5"}

-

{props.text}

+ {splitRecordText(props.text).map((part, index) => + part.kind === "block" ? ( +
+            {part.text}
+          
+ ) : ( + // oxlint-disable-next-line react/no-array-index-key -- the parts are the record's fixed order. +

+ {part.text} +

+ ), + )} ); } diff --git a/packages/client-runtime/src/j5/inbox.test.ts b/packages/client-runtime/src/j5/inbox.test.ts index ef30cffd98f85..ee434b580610c 100644 --- a/packages/client-runtime/src/j5/inbox.test.ts +++ b/packages/client-runtime/src/j5/inbox.test.ts @@ -15,6 +15,7 @@ import { mergeHumanInboxSources, mergeOpenInboxCounts, nextKeptItems, + splitRecordText, submitHumanInboxAnswer, writesNowhere, } from "./inbox.ts"; @@ -440,3 +441,35 @@ describe("what the inbox bell says", () => { expect(inboxBellPresentation({ count: null, incomplete: true }).badge).toBe("?"); }); }); + +describe("splitRecordText", () => { + it("keeps a draft's indented definition apart from the prose around it, by indentation alone", () => { + const record = [ + "J5 recorded this persona draft: a new persona, demo-helper, for this server's library. Its full definition:", + [ + " id: demo-helper", + " modelRoute:", + " - driver: claudeAgent", + " ", + ' instructions: "A long single line that should scroll rather than wrap."', + ].join("\n"), + "Saving takes an Owner's Save persona button on this ask.", + ].join("\n\n"); + expect(splitRecordText(record)).toEqual([ + { + kind: "prose", + text: "J5 recorded this persona draft: a new persona, demo-helper, for this server's library. Its full definition:", + }, + { + kind: "block", + text: 'id: demo-helper\nmodelRoute:\n - driver: claudeAgent\n\ninstructions: "A long single line that should scroll rather than wrap."', + }, + { kind: "prose", text: "Saving takes an Owner's Save persona button on this ask." }, + ]); + }); + + it("leaves a record with no indented block as the exact prose", () => { + const record = "Persona reviewer is blocked.\n- displayName: one\n\nOwner approved"; + expect(splitRecordText(record)).toEqual([{ kind: "prose", text: record }]); + }); +}); diff --git a/packages/client-runtime/src/j5/inbox.ts b/packages/client-runtime/src/j5/inbox.ts index 3c1a18b1845e9..a09a497fec292 100644 --- a/packages/client-runtime/src/j5/inbox.ts +++ b/packages/client-runtime/src/j5/inbox.ts @@ -73,6 +73,30 @@ export function inboxBellPresentation(input: { return { badge, label }; } +export interface RecordPart { + readonly kind: "prose" | "block"; + readonly text: string; +} + +/** + * J5's record split into its prose and the indented blocks it quotes, such as a persona draft's + * definition, so a block can keep its layout. Indentation alone decides: four leading spaces. + */ +export function splitRecordText(text: string): ReadonlyArray { + const parts: Array = []; + for (const line of text.split("\n")) { + const kind = line.startsWith(" ") ? "block" : "prose"; + const body = kind === "block" ? line.slice(4) : line; + const last = parts[parts.length - 1]; + if (last?.kind === kind) parts[parts.length - 1] = { kind, text: `${last.text}\n${body}` }; + else parts.push({ kind, text: body }); + } + return parts.flatMap((part) => { + const trimmed = part.kind === "prose" ? part.text.replace(/^\n+|\n+$/g, "") : part.text; + return trimmed === "" ? [] : [{ kind: part.kind, text: trimmed }]; + }); +} + export function j5SourceNotice(source: J5ReadSource): string | null { switch (source.status) { case "ready":