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
33 changes: 32 additions & 1 deletion src/supervisor/agents/codex/canonicalMapping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1343,12 +1343,43 @@ describe("mapCodexNotification — streaming deltas", () => {
expect(text[0]).toMatchObject({ type: "content.delta", stream: "reasoning_text" });
const summary = mapCodexNotification(
"item/reasoning/summaryTextDelta",
{ threadId: "x", itemId: "rs-1", delta: "summary" },
{ threadId: "x", itemId: "rs-1", delta: "summary", summaryIndex: 0 },
state,
);
expect(summary[0]).toMatchObject({ type: "content.delta", stream: "reasoning_text" });
});

it("preserves boundaries between indexed reasoning summary parts", () => {
const state = createCodexMapperState("t-codex");
mapCodexNotification(
"item/started",
{ threadId: "x", itemId: "rs-1", item: { id: "rs-1", type: "reasoning" } },
state,
);

const events = [
...mapCodexNotification(
"item/reasoning/summaryTextDelta",
{ threadId: "x", itemId: "rs-1", delta: "**Planning sidebar**", summaryIndex: 0 },
state,
),
...mapCodexNotification(
"item/reasoning/summaryTextDelta",
{ threadId: "x", itemId: "rs-1", delta: "**Refining", summaryIndex: 1 },
state,
),
...mapCodexNotification(
"item/reasoning/summaryTextDelta",
{ threadId: "x", itemId: "rs-1", delta: " removal**", summaryIndex: 1 },
state,
),
];

expect(
events.flatMap((event) => (event.type === "content.delta" ? [event.delta] : [])).join(""),
).toBe("**Planning sidebar**\n\n**Refining removal**");
});

it("maps MCP tool progress into the existing tool payload", () => {
const state = createCodexMapperState("t-codex");
mapCodexNotification(
Expand Down
14 changes: 13 additions & 1 deletion src/supervisor/agents/codex/canonicalMapping/dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export function mapCodexNotification(
state.commandOutputSeenSet.clear();
state.fileChangeOutputMap.clear();
state.fileChangePathMap.clear();
state.reasoningSummaryIndexMap.clear();
return events;
}

Expand Down Expand Up @@ -260,6 +261,7 @@ export function mapCodexNotification(
state.commandOutputSeenSet.delete(codexItemId);
state.fileChangeOutputMap.delete(codexItemId);
state.fileChangePathMap.delete(codexItemId);
state.reasoningSummaryIndexMap.delete(codexItemId);
return events;
}
const itemType = state.itemTypeMap.get(codexItemId) ?? canonicalTypeFor(item.type ?? item.kind);
Expand Down Expand Up @@ -300,6 +302,7 @@ export function mapCodexNotification(
state.commandOutputSeenSet.delete(codexItemId);
state.fileChangeOutputMap.delete(codexItemId);
state.fileChangePathMap.delete(codexItemId);
state.reasoningSummaryIndexMap.delete(codexItemId);
return events;
}

Expand All @@ -310,6 +313,15 @@ export function mapCodexNotification(
if (!delta) return [];
const codexItemId = readItemId(params);
if (!codexItemId) return [];
let contentDelta = delta;
const summaryIndex = params?.summaryIndex;
if (method === "item/reasoning/summaryTextDelta" && typeof summaryIndex === "number") {
const previousIndex = state.reasoningSummaryIndexMap.get(codexItemId);
if (previousIndex !== summaryIndex) {
if (previousIndex !== undefined) contentDelta = `\n\n${delta}`;
state.reasoningSummaryIndexMap.set(codexItemId, summaryIndex);
}
}
let internalId = state.itemIdMap.get(codexItemId);
const opened: RuntimeEvent[] = [];
if (!internalId) {
Expand Down Expand Up @@ -349,7 +361,7 @@ export function mapCodexNotification(
threadId,
itemId: internalId,
stream,
delta,
delta: contentDelta,
},
];
}
Expand Down
3 changes: 3 additions & 0 deletions src/supervisor/agents/codex/canonicalMappingState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export interface CodexMapperState {
fileChangeOutputMap: Map<string, string>;
/** Last path emitted for a file-change item, to avoid duplicate updates. */
fileChangePathMap: Map<string, string>;
/** Last streamed reasoning summary index, used to preserve summary-part boundaries. */
reasoningSummaryIndexMap: Map<string, number>;
/** Current chat item that mirrors the provider's active goal state. */
goalItemId?: string;
/** Provider-created timestamp for the current goal, when reported. */
Expand All @@ -34,6 +36,7 @@ export function createCodexMapperState(threadId: string): CodexMapperState {
commandOutputSeenSet: new Set(),
fileChangeOutputMap: new Map(),
fileChangePathMap: new Map(),
reasoningSummaryIndexMap: new Map(),
};
}

Expand Down