From ca68b7f55c6300a15a44cd24c4525784a58cb87f Mon Sep 17 00:00:00 2001 From: Ralph Chang Date: Mon, 27 Apr 2026 14:40:32 +0800 Subject: [PATCH] feat: sharpen compaction memory extraction prompt Wave 3 of memory quality optimization plan. - Add good memory examples in buildCompactionPrompt() - Add bad memory examples to skip (test counts, commit hashes, etc.) - Add prompt assertions in tests to prevent regression - Emphasize 'useful if a new agent opens this workspace next week' --- src/plugin.ts | 16 ++++++++++++++++ tests/plugin.test.ts | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/src/plugin.ts b/src/plugin.ts index 913fcde..91c879c 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -114,6 +114,22 @@ function buildCompactionPrompt(privateContext: string): string { "", "When unsure, skip it. Fewer high-signal memories are better than many low-value ones.", "", + "Good memory examples:", + "- [feedback] User prefers architecture reviews in Traditional Chinese.", + "- [decision] Use frozen workspace memory snapshots plus ephemeral hot state for cache stability.", + "- [project] The plugin should piggyback memory extraction on OpenCode compaction and avoid extra LLM calls.", + "- [reference] Workspace memory appears in frozen system[1]; pending memories appear in hot session state until compaction.", + "", + "Bad memory examples to skip:", + "- 42 tests passed.", + "- Wave 2 completed successfully.", + "- Modified 5 files.", + "- commit 4309cb8 contains the latest fix.", + "- TypeError: Cannot read properties of undefined.", + "- Currently running npm test.", + "", + "A memory should still be useful if a new agent opens this workspace next week.", + "", "Only extract facts that are likely to stay true across sessions.", "Do not extract session-specific progress like exact test counts, file counts, or phase numbers.", "For progress, extract the stable goal or durable milestone, not the current number.", diff --git a/tests/plugin.test.ts b/tests/plugin.test.ts index b7d7d1b..ecd5e68 100644 --- a/tests/plugin.test.ts +++ b/tests/plugin.test.ts @@ -275,6 +275,14 @@ test("compaction hook sets output.prompt with ---free template", async () => { // Should contain Memory candidates format assert.equal(prompt!.includes("Memory candidates:"), true, "Prompt should include Memory candidates: label"); + assert.equal(prompt!.includes("Good memory examples:"), true, + "Prompt should include concrete positive memory examples"); + assert.equal(prompt!.includes("Bad memory examples to skip:"), true, + "Prompt should include concrete negative memory examples"); + assert.equal(prompt!.includes("42 tests passed"), true, + "Prompt should explicitly reject test-count snapshots"); + assert.equal(prompt!.includes("commit 4309cb8"), true, + "Prompt should explicitly reject commit-hash snapshots"); // Should contain our context data (hot session state) assert.equal(prompt!.includes("Hot session state"), true,