mirror of
https://github.com/bendtherules/opencode-plugin-compaction-prompt.git
synced 2026-08-18 13:42:55 +00:00
feat: mark compaction status
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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."
|
||||
}
|
||||
]
|
||||
]
|
||||
@@ -39,14 +39,16 @@ 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. |
|
||||
| `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
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"memoryFile": ".opencode/compaction.md",
|
||||
"mode": "append",
|
||||
"prompt": "<Example prompt for compaction>",
|
||||
"completionMarker": "Custom compaction request honored."
|
||||
"completionMarker": "opencode-plugin-compaction-prompt: Custom compaction done."
|
||||
}
|
||||
]
|
||||
]
|
||||
|
||||
+10
-1
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+14
-5
@@ -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.",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user