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'
This commit is contained in:
Ralph Chang
2026-04-27 14:40:32 +08:00
parent 023589a905
commit ca68b7f55c
2 changed files with 24 additions and 0 deletions
+16
View File
@@ -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.",
+8
View File
@@ -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,