Skip to content

Commit 34dcd13

Browse files
wpfleger96npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7
andauthored
fix(desktop): parse codex ACP plan entries[] into checklist (#1824)
Signed-off-by: Will Pfleger <[email protected]> Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@sprout-oss.stage.blox.sqprod.co>
1 parent 020ac7f commit 34dcd13

3 files changed

Lines changed: 108 additions & 1 deletion

File tree

‎desktop/src/features/agents/ui/agentSessionTranscript.test.mjs‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,82 @@ test("buildTranscript promotes ACP plan updates to first-class plan items", () =
467467
assert.match(items[0].text, /Build registry/);
468468
});
469469

470+
test("buildTranscript parses standard ACP plan entries[] into a checklist", () => {
471+
const items = buildTranscript([
472+
sessionUpdate(90, {
473+
sessionUpdate: "plan",
474+
entries: [
475+
{ status: "completed", content: "Read the ticket", priority: "medium" },
476+
{ status: "in_progress", content: "Write the fix", priority: "medium" },
477+
{ status: "pending", content: "Open the PR", priority: "medium" },
478+
],
479+
}),
480+
]);
481+
482+
assert.equal(items.length, 1);
483+
assert.equal(items[0].type, "plan");
484+
assert.equal(items[0].renderClass, "plan");
485+
assert.equal(
486+
items[0].text,
487+
[
488+
"- [x] Read the ticket",
489+
"- [ ] Write the fix (in progress)",
490+
"- [ ] Open the PR",
491+
].join("\n"),
492+
);
493+
});
494+
495+
test("buildTranscript summarizes plan entries[] updates with correct N/M complete", () => {
496+
const items = buildTranscript([
497+
sessionUpdate(90, {
498+
sessionUpdate: "plan",
499+
entries: [
500+
{ status: "pending", content: "Read the ticket" },
501+
{ status: "pending", content: "Write the fix" },
502+
],
503+
}),
504+
sessionUpdate(91, {
505+
sessionUpdate: "plan",
506+
entries: [
507+
{ status: "completed", content: "Read the ticket" },
508+
{ status: "in_progress", content: "Write the fix" },
509+
],
510+
}),
511+
]);
512+
513+
const updateMarker = items.find(
514+
(item) => item.type === "plan" && item.isUpdate,
515+
);
516+
assert.ok(updateMarker, "expected a plan update marker item");
517+
assert.equal(updateMarker.title, "Plan updated");
518+
assert.equal(updateMarker.text, "1/2 complete");
519+
});
520+
521+
test("buildTranscript treats an empty plan entries[] as an empty checklist, not a JSON fallback", () => {
522+
const items = buildTranscript([
523+
sessionUpdate(90, {
524+
sessionUpdate: "plan",
525+
entries: [],
526+
}),
527+
]);
528+
529+
assert.equal(items.length, 1);
530+
assert.equal(items[0].type, "plan");
531+
assert.equal(items[0].text, "");
532+
});
533+
534+
test("buildTranscript falls back to raw JSON when a plan update has neither entries nor content", () => {
535+
const items = buildTranscript([
536+
sessionUpdate(90, {
537+
sessionUpdate: "plan",
538+
}),
539+
]);
540+
541+
assert.equal(items.length, 1);
542+
assert.equal(items[0].type, "plan");
543+
assert.match(items[0].text, /"sessionUpdate":\s*"plan"/);
544+
});
545+
470546
test("buildTranscript stores first-class render class descriptors for tool items", () => {
471547
const [item] = toolItems([
472548
acpToolUpdate(91, {

‎desktop/src/features/agents/ui/agentSessionTranscript.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
describeSessionResolved,
1919
extractBlockText,
2020
extractContentText,
21+
extractPlanText,
2122
extractPromptText,
2223
extractTriggeringEventIds,
2324
extractToolArgs,
@@ -1018,7 +1019,7 @@ export function processTranscriptEvent(
10181019
d,
10191020
`plan:${ch}:${turnKey}`,
10201021
"Plan",
1021-
extractContentText(update.content) || JSON.stringify(update, null, 2),
1022+
extractPlanText(update),
10221023
event.timestamp,
10231024
ctx,
10241025
updateType,

‎desktop/src/features/agents/ui/agentSessionTranscriptHelpers.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,36 @@ export function extractBlockText(value: unknown): string {
295295
return directText || nestedText || rawOutputText || "";
296296
}
297297

298+
/**
299+
* Build markdown checklist text for a `plan` session update.
300+
*
301+
* The standard ACP shape (`@agentclientprotocol/codex-acp`) sends
302+
* `entries[]` — `{ status, content, priority }` — with no top-level
303+
* `content` field. Older/non-standard adapters instead send
304+
* `content: { type: "text", text }` directly on the update. `entries`
305+
* (even empty) is treated as authoritative when present; `content` is
306+
* only consulted when `entries` is absent, and the raw update is
307+
* stringified only when neither yields usable text.
308+
*/
309+
export function extractPlanText(update: Record<string, unknown>): string {
310+
if (Array.isArray(update.entries)) {
311+
return update.entries
312+
.map((entry) => formatPlanEntry(asRecord(entry)))
313+
.filter(Boolean)
314+
.join("\n");
315+
}
316+
const contentText = extractContentText(update.content);
317+
return contentText || JSON.stringify(update, null, 2);
318+
}
319+
320+
function formatPlanEntry(entry: Record<string, unknown>): string {
321+
const content = asString(entry.content);
322+
if (!content) return "";
323+
const checkbox = entry.status === "completed" ? "[x]" : "[ ]";
324+
const suffix = entry.status === "in_progress" ? " (in progress)" : "";
325+
return `- ${checkbox} ${content}${suffix}`;
326+
}
327+
298328
export function extractToolArgs(
299329
update: Record<string, unknown>,
300330
): Record<string, unknown> {

0 commit comments

Comments
 (0)