diff --git a/CHANGELOG.md b/CHANGELOG.md index e6e8c66..ece53ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.2.2 + +- Add explicit markers for applied and skipped custom compaction instructions. + ## 0.2.1 - Add the server entrypoint expected by OpenCode's npm plugin loader. diff --git a/README.md b/README.md index 4581769..851244b 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ You can also add it manually to your global `opencode.jsonc`: { "memoryFile": ".opencode/compaction.md", "mode": "append", - "completionMarker": "Custom compaction request honored." + "completionMarker": "opencode-plugin-compaction-prompt: Custom compaction done." } ] ] @@ -38,15 +38,17 @@ Create `.opencode/compaction.md` in the project when you have project-specific c ## Options -| Option | Default | Description | -| ------------------ | ------------------------------------ | ---------------------------------------------------------------------------------------------------------- | -| `memoryFile` | `.opencode/compaction.md` | File resolved relative to the active worktree. | -| `mode` | `append` | Append instructions to OpenCode's default prompt, or use `replace` to provide a complete prompt. | -| `prompt` | "" (empty) | Additional instructions used together with `memoryFile`; both are included in the compaction instructions. | -| `completionMarker` | `Custom compaction request honored.` | Exact text the model is asked to append at the end of the summary. | +| Option | Default | Description | +| ------------------ | ------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------- | +| `memoryFile` | `.opencode/compaction.md` | File resolved relative to the active worktree. | +| `mode` | `append` | Append instructions to OpenCode's default prompt, or use `replace` to provide a complete prompt. | +| `prompt` | "" (empty) | Additional instructions used together with `memoryFile`; both are included in the compaction instructions. | +| `completionMarker` | `opencode-plugin-compaction-prompt: Custom compaction done.` | Exact text the model is asked to append at the end of the summary. | Append mode is the recommended default because it preserves OpenCode's built-in compaction behavior. Replace mode is available when the complete prompt needs to be controlled by this plugin. +When neither a prompt nor a memory file is available, the plugin adds `opencode-plugin-compaction-prompt: No custom compaction applied.` instead. + ## Development ```bash diff --git a/examples/opencode.json b/examples/opencode.json index a66eab0..c290ea3 100644 --- a/examples/opencode.json +++ b/examples/opencode.json @@ -7,7 +7,7 @@ "memoryFile": ".opencode/compaction.md", "mode": "append", "prompt": "", - "completionMarker": "Custom compaction request honored." + "completionMarker": "opencode-plugin-compaction-prompt: Custom compaction done." } ] ] diff --git a/src/index.ts b/src/index.ts index 8b21b39..ab7a15c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,7 +13,10 @@ export type CompactionOptions = PluginOptions & { const defaultMemoryFile = ".opencode/compaction.md"; const defaultPrompt = ""; -const defaultCompletionMarker = "Custom compaction request honored."; +const defaultCompletionMarker = + "opencode-plugin-compaction-prompt: Custom compaction done."; +const skippedCompactionMarker = + "opencode-plugin-compaction-prompt: No custom compaction applied."; function asString(value: unknown): string | undefined { if (typeof value !== "string") { @@ -115,6 +118,12 @@ export const CompactionPromptPlugin: Plugin = async ( const instructions = buildInstructions(prompt, completionMarker, memory); if (!instructions) { + if (mode === "replace") { + output.prompt = skippedCompactionMarker; + } else { + output.context.push(skippedCompactionMarker); + } + return; } diff --git a/test/index.test.ts b/test/index.test.ts index 0054f2d..bb81d8e 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -55,7 +55,9 @@ describe("CompactionPromptPlugin", () => { ); expect(output.context[0]).toContain("Keep the active hypothesis."); - expect(output.context[0]).toContain("Custom compaction request honored."); + expect(output.context[0]).toContain( + "opencode-plugin-compaction-prompt: Custom compaction done.", + ); }); test("combines custom instructions with a configured memory file", async () => { @@ -114,10 +116,12 @@ describe("CompactionPromptPlugin", () => { ); expect(context.logs).toHaveLength(0); - expect(output.context).toHaveLength(0); + expect(output.context).toEqual([ + "opencode-plugin-compaction-prompt: No custom compaction applied.", + ]); }); - test("does not modify compaction when no instructions are provided", async () => { + test("adds a skipped marker when no instructions are provided", async () => { const context = await createContext(); const hooks = await CompactionPromptPlugin(context as never); const output: { context: string[]; prompt?: string } = { @@ -129,7 +133,10 @@ describe("CompactionPromptPlugin", () => { output, ); - expect(output.context).toEqual(["Existing context"]); + expect(output.context).toEqual([ + "Existing context", + "opencode-plugin-compaction-prompt: No custom compaction applied.", + ]); expect(output.prompt).toBeUndefined(); }); @@ -147,6 +154,8 @@ describe("CompactionPromptPlugin", () => { ); expect(context.logs).toHaveLength(1); - expect(output.context).toHaveLength(0); + expect(output.context).toEqual([ + "opencode-plugin-compaction-prompt: No custom compaction applied.", + ]); }); });