Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions apps/mobile/src/j5/inbox/InboxScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -290,13 +291,7 @@ function InboxItem(props: {
<View className="mt-3 gap-3 border-t border-border-subtle pt-3">
<InboxMessage markdown={item.message} />
{[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.
<View key={record} className="gap-1 rounded-lg bg-subtle px-3 py-2">
<Text className="text-xs font-t3-medium text-foreground-muted">Recorded by J5</Text>
<Text className="text-sm">{record}</Text>
</View>
),
record === undefined ? null : <J5RecordPanel key={record} text={record} />,
)}
{item.followUps?.map((followUp) => (
<View className="gap-1" key={followUp.messageId}>
Expand Down
32 changes: 32 additions & 0 deletions apps/mobile/src/j5/inbox/J5RecordPanel.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<View className="gap-1 rounded-lg bg-subtle px-3 py-2">
<Text className="text-xs font-t3-medium text-foreground-muted">Recorded by J5</Text>
{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.
<ScrollView key={index} horizontal nestedScrollEnabled showsHorizontalScrollIndicator>
<Text selectable className="font-mono text-xs">
{part.text}
</Text>
</ScrollView>
) : (
// oxlint-disable-next-line react/no-array-index-key -- the parts are the record's fixed order.
<Text key={index} className="text-sm">
{part.text}
</Text>
),
)}
</View>
);
}
22 changes: 20 additions & 2 deletions apps/web/src/j5/a2a/J5RecordPanel.tsx
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -13,7 +16,22 @@ export function J5RecordPanel(props: { readonly text: string; readonly label?: s
<h3 className="text-xs font-medium text-muted-foreground">
{props.label ?? "Recorded by J5"}
</h3>
<p className="mt-1 whitespace-pre-wrap break-words text-foreground">{props.text}</p>
{splitRecordText(props.text).map((part, index) =>
part.kind === "block" ? (
<pre
// oxlint-disable-next-line react/no-array-index-key -- the parts are the record's fixed order.
key={index}
className="mt-1 overflow-x-auto whitespace-pre font-mono text-xs text-foreground"
>
{part.text}
</pre>
) : (
// oxlint-disable-next-line react/no-array-index-key -- the parts are the record's fixed order.
<p key={index} className="mt-1 whitespace-pre-wrap break-words text-foreground">
{part.text}
</p>
),
)}
</section>
);
}
33 changes: 33 additions & 0 deletions packages/client-runtime/src/j5/inbox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
mergeHumanInboxSources,
mergeOpenInboxCounts,
nextKeptItems,
splitRecordText,
submitHumanInboxAnswer,
writesNowhere,
} from "./inbox.ts";
Expand Down Expand Up @@ -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\n<b>Owner approved</b>";
expect(splitRecordText(record)).toEqual([{ kind: "prose", text: record }]);
});
});
24 changes: 24 additions & 0 deletions packages/client-runtime/src/j5/inbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<RecordPart> {
const parts: Array<RecordPart> = [];
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<unknown>): string | null {
switch (source.status) {
case "ready":
Expand Down
Loading