diff --git a/domain/aiSessionFork.test.ts b/domain/aiSessionFork.test.ts index f1e474970..5a3c1a70d 100644 --- a/domain/aiSessionFork.test.ts +++ b/domain/aiSessionFork.test.ts @@ -282,3 +282,14 @@ test('one-pass fork eligibility matches clicked-boundary validation', () => { const orphan = session([msg({ role: 'tool', toolResults: [{ toolCallId: 'orphan' }] }), msg({ content: 'reply' })]); assert.equal(getForkableMessageIds(orphan).size, 0); }); + +test('fork removes bare output identifiers in transcript previews while preserving JSON', () => { + const assistant = msg({ content: 'Read tool-output-source with tool_output_read', thinking: 'Output tool-output-source is saved', toolResults: [{ toolCallId: 'call', content: '{"handleId":"tool-output-source","preview":"Read tool-output-source"}' }] }); + const plan = planSessionFork(session([msg({ toolCalls: [{ id: 'call' }] }), assistant]), assistant.id); + assert.ok(plan.ok); + assert.doesNotMatch(JSON.stringify(plan.messages), /tool-output-source/); + const parsed = JSON.parse(plan.messages[1].toolResults![0].content!); + assert.equal(parsed.handleId, null); + assert.match(parsed.preview, /Read/); + assert.match(assistant.content, /tool-output-source/); +}); diff --git a/domain/aiSessionFork.ts b/domain/aiSessionFork.ts index debd854cf..70c369f0f 100644 --- a/domain/aiSessionFork.ts +++ b/domain/aiSessionFork.ts @@ -157,7 +157,8 @@ function validateToolCallResultPairing( function stripSourceOutputHandles(value: string): string { return value .replace(/\bhandleId=tool-output-[A-Za-z0-9-]+/g, '[saved output remains in the original chat]') - .replace(/"handleId"\s*:\s*"tool-output-[A-Za-z0-9-]+"/g, '"handleId":null,"note":"Saved output remains in the original chat"'); + .replace(/"handleId"\s*:\s*"tool-output-[A-Za-z0-9-]+"/g, '"handleId":null,"note":"Saved output remains in the original chat"') + .replace(/\btool-output-[A-Za-z0-9-]+/g, '[saved output remains in the original chat]'); } export function stripMessageContinuationState(message: M): M {