Skip to content

Commit fc8d324

Browse files
authored
feat(agents2): show Codex and Claude Code session transcripts (#842)
Signed-off-by: Salman Mohammed <[email protected]>
1 parent 53970a7 commit fc8d324

18 files changed

Lines changed: 1501 additions & 56 deletions

‎src/bundled/agent-activity/ActivityPanel.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
import { activityRecords } from "../../features/agents/activity-records";
1515
import { activityTranscript } from "../../features/agents/activity-transcript";
1616
import { Tabs } from "../../shared/design-system/ui/Tabs";
17-
import { ActivityTranscript } from "./ActivityTranscript";
17+
import { ActivityTranscript } from "../../features/agents/ActivityTranscript";
1818
import { Accordion } from "../../shared/design-system/ui/Accordion";
1919
import { Select } from "../../shared/design-system/ui/Select";
2020
import { Button } from "../../shared/design-system/ui/Button";

‎src/bundled/claude-code/manifest.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"program": "bash",
1111
"args": ["-c", "curl -fsSL https://claude.ai/install.sh | bash"]
1212
},
13-
{ "id": "read", "program": "base64", "args": ["-i"] }
13+
{ "id": "read", "program": "base64", "args": ["-i"] },
14+
{ "id": "workspace", "program": "pwd" }
1415
]
1516
}
1617
}

‎src/bundled/claude-code/runtime.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
watchPrompt,
3434
} from "./prompt";
3535
import { AgentSessions, localSessions, Spare } from "./sessions";
36+
import { readTranscript, type Conversation } from "./transcript";
3637

3738
/** What a session can switch to between turns. Claude runs `max` as
3839
* `xhigh` in a stream-json session, so it is not offered. */
@@ -63,6 +64,16 @@ export const config = (value: unknown): Config => ({
6364
...(value && typeof value === "object" ? (value as Partial<Config>) : {}),
6465
});
6566

67+
/** A saved session, for the owner's transcript list. */
68+
export type SavedConversation = Conversation & {
69+
key: string;
70+
/** The channel's name, when this community lists it. */
71+
name?: string;
72+
at: number;
73+
};
74+
/** Saved sessions listed for the owner. */
75+
const CONVERSATION_LIMIT = 30;
76+
6677
/** How long a read of the agent's core memory is reused. */
6778
const MEMORY_TTL_MS = 5 * 60_000;
6879
const MEMORY_TIMEOUT_MS = 5_000;
@@ -222,6 +233,38 @@ export class ClaudeRuntime {
222233
}
223234
return view;
224235
}
236+
/** The agent's most recently used saved sessions. */
237+
conversations(pubkey: string): SavedConversation[] {
238+
const snapshot = this.relay(pubkey)?.snapshot();
239+
const channels =
240+
snapshot?.status === "ready"
241+
? snapshot.session.channels.list().channels
242+
: [];
243+
return localSessions(this.storage, pubkey)
244+
.list()
245+
.slice(0, CONVERSATION_LIMIT)
246+
.map(([key, saved]) => {
247+
const [channelId = key, root] = key.split("/");
248+
const name = channels.find((row) => row.id === channelId)?.name;
249+
return {
250+
key,
251+
sessionId: saved.id,
252+
channelId,
253+
...(root ? { root } : {}),
254+
...(name ? { name } : {}),
255+
at: saved.at,
256+
};
257+
});
258+
}
259+
/** A saved session's transcript, found from the workspace it ran in. */
260+
transcript(
261+
conversation: SavedConversation,
262+
workspace: string,
263+
working: boolean,
264+
signal: AbortSignal,
265+
) {
266+
return readTranscript(this.spawn, workspace, conversation, working, signal);
267+
}
225268
subscribe(listener: () => void) {
226269
this.listeners.add(listener);
227270
return () => {

‎src/bundled/claude-code/sessions.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,10 @@ export function localSessions(
480480
storage: Storage,
481481
agent: string,
482482
name = "buzz.claude-code.sessions.v1",
483-
): SessionStore {
483+
): SessionStore & {
484+
/** Saved sessions, most recently used first. */
485+
list(): [string, SavedSession][];
486+
} {
484487
const readAll = (): Record<string, Record<string, SavedSession>> => {
485488
try {
486489
const value = JSON.parse(storage.getItem(name) ?? "{}");
@@ -504,6 +507,10 @@ export function localSessions(
504507
}
505508
};
506509
return {
510+
list: () =>
511+
Object.entries(readAll()[agent] ?? {})
512+
.filter(([, saved]) => typeof saved?.id === "string")
513+
.sort(([, a], [, b]) => b.at - a.at),
507514
get: (key) => {
508515
const saved = readAll()[agent]?.[key];
509516
return saved && typeof saved.id === "string" ? saved : undefined;

‎src/bundled/claude-code/tabs.test.tsx‎

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ afterEach(() => {
3434
cleanup();
3535
vi.unstubAllGlobals();
3636
vi.restoreAllMocks();
37+
localStorage.clear();
3738
});
3839

3940
const agent = (config: Config = DEFAULT_CONFIG) =>
@@ -49,10 +50,35 @@ const agent = (config: Config = DEFAULT_CONFIG) =>
4950
// browser drops it, so the focus tests also check for no `disabled`.
5051

5152
/** Applies the plugin to a stand-in context; sign-in runs until killed. */
52-
function applied({ loggedIn = true } = {}) {
53+
function applied({
54+
loggedIn = true,
55+
files = {},
56+
}: {
57+
loggedIn?: boolean;
58+
files?: Record<string, string>;
59+
} = {}) {
5360
let type: AgentType<Config> | undefined;
54-
const spawn = vi.fn(async (_id: string, options: HostProcessOptions = {}) => {
61+
const spawn = vi.fn(async (id: string, options: HostProcessOptions = {}) => {
5562
const args = (options.args ?? []).join(" ");
63+
if (id === "workspace" || id === "read") {
64+
const file = files[args];
65+
queueMicrotask(() =>
66+
id === "workspace"
67+
? options.onStdout?.("/Users/me/.buzz\n")
68+
: file === undefined
69+
? options.onStderr?.(`base64: ${args}: No such file or directory`)
70+
: options.onStdout?.(btoa(file)),
71+
);
72+
const code = id === "read" && file === undefined ? 1 : 0;
73+
return {
74+
write: async () => undefined,
75+
end: async () => undefined,
76+
kill: async () => undefined,
77+
exited: new Promise<number>((resolve) =>
78+
setTimeout(() => resolve(code), 0),
79+
),
80+
};
81+
}
5682
let kill: () => void = () => undefined;
5783
const exited = new Promise<number | null>((resolve) => {
5884
if (args === "auth login") kill = () => resolve(null);
@@ -90,7 +116,7 @@ function applied({ loggedIn = true } = {}) {
90116
apply(ctx as never);
91117
return { type, spawn };
92118
}
93-
function installed(options?: { loggedIn?: boolean }) {
119+
function installed(options?: Parameters<typeof applied>[0]) {
94120
const { type, spawn } = applied(options);
95121
if (!type) throw new Error("no type registered");
96122
return { type, spawn };
@@ -219,6 +245,60 @@ it("keeps Save focused while saving, and lets a failed save be retried", async (
219245
await waitFor(() => expect(screen.queryByRole("alert")).toBeNull());
220246
});
221247

248+
it("lists saved conversations and shows one's transcript, or that it is gone", async () => {
249+
const thread = `channel/${"e".repeat(64)}`;
250+
localStorage.setItem(
251+
"buzz.claude-code.sessions.v1",
252+
JSON.stringify({
253+
[agent().pubkey]: {
254+
channel: { id: "deleted", seen: 0, at: 1 },
255+
[thread]: { id: "kept", seen: 0, at: 2 },
256+
},
257+
}),
258+
);
259+
const transcript = [
260+
JSON.stringify({
261+
type: "user",
262+
uuid: "u1",
263+
timestamp: "2026-10-09T10:00:00Z",
264+
message: {
265+
content:
266+
"<buzz-event>\nEvent ID: e\nContent: what changed?\nTags: []\n</buzz-event>",
267+
},
268+
}),
269+
JSON.stringify({
270+
type: "assistant",
271+
uuid: "u2",
272+
timestamp: "2026-10-09T10:00:05Z",
273+
message: { content: [{ type: "text", text: "Two files." }] },
274+
}),
275+
].join("\n");
276+
const Claude = tab(
277+
installed({ files: { "./-Users-me--buzz/kept.jsonl": transcript } }).type,
278+
0,
279+
);
280+
render(<Claude agent={agent()} save={vi.fn()} />);
281+
const user = userEvent.setup();
282+
const rows = screen.getAllByRole("listitem");
283+
expect(rows.map((row) => row.textContent)).toEqual([
284+
expect.stringContaining("channel · thread eeeeeeee"),
285+
expect.stringContaining("channel · channel"),
286+
]);
287+
const viewButton = (index: number) =>
288+
screen.getAllByRole("button", { name: "View transcript" })[
289+
index
290+
] as HTMLElement;
291+
await user.click(viewButton(0));
292+
expect(await screen.findByText("what changed?")).toBeVisible();
293+
expect(screen.getByText("Two files.")).toBeVisible();
294+
await user.click(screen.getByRole("button", { name: "Back" }));
295+
await user.click(viewButton(1));
296+
expect(
297+
await screen.findByText(/no transcript for this conversation/),
298+
).toBeVisible();
299+
expect(screen.queryByRole("alert")).toBeNull();
300+
});
301+
222302
it("starts a new agent from a model and instructions, keeping the rest", async () => {
223303
const Create = installed().type.Create;
224304
if (!Create) throw new Error("no create view");

0 commit comments

Comments
 (0)