diff --git a/.changeset/compaction-history-direction.md b/.changeset/compaction-history-direction.md new file mode 100644 index 00000000000..b5db7813475 --- /dev/null +++ b/.changeset/compaction-history-direction.md @@ -0,0 +1,5 @@ +--- +"@opencode-ai/core": patch +--- + +Correct the compaction prompt to point existing summaries at the conversation history that follows them. diff --git a/packages/core/src/session/compaction.ts b/packages/core/src/session/compaction.ts index c04e13bca4b..60259d8ea6a 100644 --- a/packages/core/src/session/compaction.ts +++ b/packages/core/src/session/compaction.ts @@ -215,7 +215,7 @@ const select = ( export const buildPrompt = (input: { readonly previousSummary?: string; readonly context: readonly string[] }) => [ input.previousSummary - ? `Update the anchored summary below using the conversation history above.\nPreserve still-true details, remove stale details, and merge in the new facts.\n\n${input.previousSummary}\n` + ? `Update the anchored summary below using the conversation history below.\nPreserve still-true details, remove stale details, and merge in the new facts.\n\n${input.previousSummary}\n` : "Create a new anchored summary from the conversation history.", SUMMARY_TEMPLATE, "The following is the conversation history:", diff --git a/packages/core/test/session-compaction.test.ts b/packages/core/test/session-compaction.test.ts index c2167485f31..c3a3ba6f6ee 100644 --- a/packages/core/test/session-compaction.test.ts +++ b/packages/core/test/session-compaction.test.ts @@ -143,6 +143,13 @@ test("compaction prompt requires the checkpoint headings in order", () => { expect(prompt).toContain("Keep every section, even when empty.") }) +test("compaction points an existing summary to the following history", () => { + const prompt = SessionCompaction.buildPrompt({ previousSummary: "Previous summary", context: ["Recent history"] }) + + expect(prompt.split("\n", 1)[0]).toBe("Update the anchored summary below using the conversation history below.") + expect(prompt).not.toContain("conversation history above") +}) + it.effect("auto compaction reserves a buffer below the prompt ceiling", () => Effect.gen(function* () { const compaction = yield* SessionCompaction.Service