Skip to content

Commit fbf3bd8

Browse files
authored
Merge pull request #331 from Opencode-DCP/beta
merge beta into master
2 parents 6f2813f + 9ad912c commit fbf3bd8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1629
-723
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ Thumbs.db
2828
# OpenCode
2929
.opencode/
3030

31+
# Generated prompt files (from scripts/generate-prompts.ts)
32+
lib/prompts/*.generated.ts
33+
3134
# Tests (local development only)
3235
tests/
3336
notes/
@@ -36,3 +39,5 @@ test-update.ts
3639
# Documentation (local development only)
3740
docs/
3841
SCHEMA_NOTES.md
42+
43+
repomix-output.xml

.repomixignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.github/
2+
.logs/
3+
.opencode/
4+
dist/
5+
.repomixignore
6+
repomix-output.xml
7+
bun.lock
8+
package-lock.jsonc
9+
LICENCE

README.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Dynamic Context Pruning Plugin
22

3+
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/dansmolsky)
34
[![npm version](https://img.shields.io/npm/v/@tarquinen/opencode-dcp.svg)](https://www.npmjs.com/package/@tarquinen/opencode-dcp)
45

56
Automatically reduces token usage in OpenCode by removing obsolete tools from conversation history.
67

7-
![DCP in action](dcp-demo5.png)
8+
![DCP in action](assets/images/dcp-demo5.png)
89

910
## Installation
1011

@@ -27,9 +28,11 @@ DCP uses multiple tools and strategies to reduce context size:
2728

2829
### Tools
2930

30-
**Discard** — Exposes a `discard` tool that the AI can call to remove completed or noisy tool content from context.
31+
**Distill** — Exposes a `distill` tool that the AI can call to distill valuable context into concise summaries before removing the tool content.
3132

32-
**Extract** — Exposes an `extract` tool that the AI can call to distill valuable context into concise summaries before removing the tool content.
33+
**Compress** — Exposes a `compress` tool that the AI can call to collapse a large section of conversation (messages and tools) into a single summary.
34+
35+
**Prune** — Exposes a `prune` tool that the AI can call to remove completed or noisy tool content from context.
3336

3437
### Strategies
3538

@@ -57,7 +60,7 @@ DCP uses its own config file:
5760

5861
- Global: `~/.config/opencode/dcp.jsonc` (or `dcp.json`), created automatically on first run
5962
- Custom config directory: `$OPENCODE_CONFIG_DIR/dcp.jsonc` (or `dcp.json`), if `OPENCODE_CONFIG_DIR` is set
60-
- Project: `.opencode/dcp.jsonc` (or `dcp.json`) in your projects `.opencode` directory
63+
- Project: `.opencode/dcp.jsonc` (or `dcp.json`) in your project's `.opencode` directory
6164

6265
<details>
6366
<summary><strong>Default Configuration</strong> (click to expand)</summary>
@@ -96,15 +99,21 @@ DCP uses its own config file:
9699
"protectedTools": [],
97100
},
98101
// Removes tool content from context without preservation (for completed tasks or noise)
99-
"discard": {
102+
"prune": {
100103
"enabled": true,
101104
},
102105
// Distills key findings into preserved knowledge before removing raw content
103-
"extract": {
106+
"distill": {
104107
"enabled": true,
105108
// Show distillation content as an ignored message notification
106109
"showDistillation": false,
107110
},
111+
// Collapses a range of conversation content into a single summary
112+
"compress": {
113+
"enabled": true,
114+
// Show summary content as an ignored message notification
115+
"showCompression": true,
116+
},
108117
},
109118
// Automatic pruning strategies
110119
"strategies": {
@@ -143,12 +152,12 @@ DCP provides a `/dcp` slash command:
143152

144153
### Turn Protection
145154

146-
When enabled, turn protection prevents tool outputs from being pruned for a configurable number of message turns. This gives the AI time to reference recent tool outputs before they become prunable. Applies to both `discard` and `extract` tools, as well as automatic strategies.
155+
When enabled, turn protection prevents tool outputs from being pruned for a configurable number of message turns. This gives the AI time to reference recent tool outputs before they become prunable. Applies to both `prune` and `distill` tools, as well as automatic strategies.
147156

148157
### Protected Tools
149158

150159
By default, these tools are always protected from pruning across all strategies:
151-
`task`, `todowrite`, `todoread`, `discard`, `extract`, `batch`, `write`, `edit`
160+
`task`, `todowrite`, `todoread`, `distill`, `compress`, `prune`, `batch`, `write`, `edit`, `plan_enter`, `plan_exit`
152161

153162
The `protectedTools` arrays in each section add to this default list.
154163

File renamed without changes.

dcp.schema.json

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -100,46 +100,54 @@
100100
"items": {
101101
"type": "string"
102102
},
103-
"default": [
104-
"task",
105-
"todowrite",
106-
"todoread",
107-
"discard",
108-
"extract",
109-
"batch",
110-
"write",
111-
"edit"
112-
],
103+
"default": [],
113104
"description": "Tool names that should be protected from automatic pruning"
114105
}
115106
}
116107
},
117-
"discard": {
108+
"distill": {
118109
"type": "object",
119-
"description": "Configuration for the discard tool",
110+
"description": "Configuration for the distill tool",
120111
"additionalProperties": false,
121112
"properties": {
122113
"enabled": {
123114
"type": "boolean",
124115
"default": true,
125-
"description": "Enable the discard tool"
116+
"description": "Enable the distill tool"
117+
},
118+
"showDistillation": {
119+
"type": "boolean",
120+
"default": false,
121+
"description": "Show distillation output in the UI"
126122
}
127123
}
128124
},
129-
"extract": {
125+
"compress": {
130126
"type": "object",
131-
"description": "Configuration for the extract tool",
127+
"description": "Configuration for the compress tool",
132128
"additionalProperties": false,
133129
"properties": {
134130
"enabled": {
135131
"type": "boolean",
136132
"default": true,
137-
"description": "Enable the extract tool"
133+
"description": "Enable the compress tool"
138134
},
139-
"showDistillation": {
135+
"showCompression": {
140136
"type": "boolean",
141-
"default": false,
142-
"description": "Show distillation output in the UI"
137+
"default": true,
138+
"description": "Show summary output in the UI"
139+
}
140+
}
141+
},
142+
"prune": {
143+
"type": "object",
144+
"description": "Configuration for the prune tool",
145+
"additionalProperties": false,
146+
"properties": {
147+
"enabled": {
148+
"type": "boolean",
149+
"default": true,
150+
"description": "Enable the prune tool"
143151
}
144152
}
145153
}
@@ -165,16 +173,7 @@
165173
"items": {
166174
"type": "string"
167175
},
168-
"default": [
169-
"task",
170-
"todowrite",
171-
"todoread",
172-
"discard",
173-
"extract",
174-
"batch",
175-
"write",
176-
"edit"
177-
],
176+
"default": [],
178177
"description": "Tool names excluded from deduplication"
179178
}
180179
}
@@ -211,16 +210,7 @@
211210
"items": {
212211
"type": "string"
213212
},
214-
"default": [
215-
"task",
216-
"todowrite",
217-
"todoread",
218-
"discard",
219-
"extract",
220-
"batch",
221-
"write",
222-
"edit"
223-
],
213+
"default": [],
224214
"description": "Tool names excluded from error purging"
225215
}
226216
}

index.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import type { Plugin } from "@opencode-ai/plugin"
22
import { getConfig } from "./lib/config"
33
import { Logger } from "./lib/logger"
44
import { createSessionState } from "./lib/state"
5-
import { createDiscardTool, createExtractTool } from "./lib/strategies"
5+
import { createPruneTool, createDistillTool, createCompressTool } from "./lib/strategies"
66
import {
77
createChatMessageTransformHandler,
88
createCommandExecuteHandler,
99
createSystemPromptHandler,
1010
} from "./lib/hooks"
11+
import { configureClientAuth, isSecureMode } from "./lib/auth"
1112

1213
const plugin: Plugin = (async (ctx) => {
1314
const config = getConfig(ctx)
@@ -19,6 +20,11 @@ const plugin: Plugin = (async (ctx) => {
1920
const logger = new Logger(config.debug)
2021
const state = createSessionState()
2122

23+
if (isSecureMode()) {
24+
configureClientAuth(ctx.client)
25+
// logger.info("Secure mode detected, configured client authentication")
26+
}
27+
2228
logger.info("DCP initialized", {
2329
strategies: config.strategies,
2430
})
@@ -55,17 +61,26 @@ const plugin: Plugin = (async (ctx) => {
5561
ctx.directory,
5662
),
5763
tool: {
58-
...(config.tools.discard.enabled && {
59-
discard: createDiscardTool({
64+
...(config.tools.distill.enabled && {
65+
distill: createDistillTool({
66+
client: ctx.client,
67+
state,
68+
logger,
69+
config,
70+
workingDirectory: ctx.directory,
71+
}),
72+
}),
73+
...(config.tools.compress.enabled && {
74+
compress: createCompressTool({
6075
client: ctx.client,
6176
state,
6277
logger,
6378
config,
6479
workingDirectory: ctx.directory,
6580
}),
6681
}),
67-
...(config.tools.extract.enabled && {
68-
extract: createExtractTool({
82+
...(config.tools.prune.enabled && {
83+
prune: createPruneTool({
6984
client: ctx.client,
7085
state,
7186
logger,
@@ -84,8 +99,9 @@ const plugin: Plugin = (async (ctx) => {
8499
}
85100

86101
const toolsToAdd: string[] = []
87-
if (config.tools.discard.enabled) toolsToAdd.push("discard")
88-
if (config.tools.extract.enabled) toolsToAdd.push("extract")
102+
if (config.tools.prune.enabled) toolsToAdd.push("prune")
103+
if (config.tools.distill.enabled) toolsToAdd.push("distill")
104+
if (config.tools.compress.enabled) toolsToAdd.push("compress")
89105

90106
if (toolsToAdd.length > 0) {
91107
const existingPrimaryTools = opencodeConfig.experimental?.primary_tools ?? []

0 commit comments

Comments
 (0)