From d7a6d78c728d2559d7e06bc8bd98d764b1e76229 Mon Sep 17 00:00:00 2001 From: Luca Martial Date: Mon, 11 May 2026 20:39:09 -0700 Subject: [PATCH] Return wiki content after edits --- .../context/src/wiki/tools/wiki-write.tool.test.ts | 2 +- packages/context/src/wiki/tools/wiki-write.tool.ts | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/context/src/wiki/tools/wiki-write.tool.test.ts b/packages/context/src/wiki/tools/wiki-write.tool.test.ts index 71d57196..ec9b1ae9 100644 --- a/packages/context/src/wiki/tools/wiki-write.tool.test.ts +++ b/packages/context/src/wiki/tools/wiki-write.tool.test.ts @@ -127,7 +127,7 @@ describe('WikiWriteTool', () => { baseContext, ); - expect(result.structured).toEqual({ success: true, key: 'orbit-customers', action: 'updated' }); + expect(result.structured).toMatchObject({ success: true, key: 'orbit-customers', action: 'updated' }); expect(wikiService.writePage).toHaveBeenCalledWith( 'USER', 'u', diff --git a/packages/context/src/wiki/tools/wiki-write.tool.ts b/packages/context/src/wiki/tools/wiki-write.tool.ts index a31710c4..21f78fd2 100644 --- a/packages/context/src/wiki/tools/wiki-write.tool.ts +++ b/packages/context/src/wiki/tools/wiki-write.tool.ts @@ -45,6 +45,7 @@ interface WikiWriteStructured { success: boolean; key: string; action?: 'created' | 'updated'; + content?: string; } function looksLikeEscapedMarkdown(content: string): boolean { @@ -181,9 +182,17 @@ tags/refs/sl_refs use REPLACE semantics: omit to keep existing on update, [] to context.session.actions.push({ target: 'wiki', type: action, key: input.key, detail: input.summary }); } + // When the LLM used `replacements` (edit mode), it doesn't have the + // post-edit content cached. Returning the result here prevents the + // common bug where a follow-up edit uses an oldText string that no + // longer matches because a prior edit already changed the page. + const markdown = hasReplacements + ? `Page "${input.key}" ${action}.\n\nCurrent content (use for subsequent edits):\n\n${finalContent}` + : `Page "${input.key}" ${action}.`; + return { - markdown: `Page "${input.key}" ${action}.`, - structured: { success: true, key: input.key, action }, + markdown, + structured: { success: true, key: input.key, action, content: finalContent }, }; } }