Skip to content

Commit 1e211d4

Browse files
authored
Merge branch 'dev' into patch-1
2 parents 4e43419 + 418ad56 commit 1e211d4

Some content is hidden

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

67 files changed

+4374
-1024
lines changed

.gitignore

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@ Thumbs.db
2828
# OpenCode
2929
.opencode/
3030

31-
# Tests (local development only)
32-
tests/
31+
# Generated prompt files (from scripts/generate-prompts.ts)
32+
lib/prompts/**/*.generated.ts
33+
34+
# Tests
35+
tests/results/
3336
notes/
3437
test-update.ts
3538

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

CONTRIBUTING.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Contributing to DCP
2+
3+
Thank you for your interest in contributing to Dynamic Context Pruning (DCP)!
4+
5+
## License and Contributions
6+
7+
This project uses the **GNU Affero General Public License v3.0 (AGPL-3.0)**.
8+
9+
### Contribution Agreement
10+
11+
By submitting a Pull Request to this project, you agree that:
12+
13+
1. Your contributions are licensed under the **AGPL-3.0**.
14+
2. You grant the project maintainer(s) a non-exclusive, perpetual, irrevocable, worldwide, royalty-free, transferable license to use, modify, and re-license your contributions under any terms they choose, including commercial or proprietary licenses.
15+
16+
This arrangement ensures the project remains Open Source while providing a path for commercial sustainability.
17+
18+
## Getting Started
19+
20+
1. Fork the repository.
21+
2. Create a feature branch.
22+
3. Implement your changes and add tests if applicable.
23+
4. Ensure all tests pass and the code is formatted.
24+
5. Submit a Pull Request.
25+
26+
We look forward to your contributions!

LICENSE

Lines changed: 619 additions & 21 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 96 additions & 85 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

5-
Automatically reduces token usage in OpenCode by removing obsolete tools from conversation history.
6+
Automatically reduces token usage in OpenCode by removing obsolete content 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,15 +28,17 @@ 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

3639
**Deduplication** — Identifies repeated tool calls (e.g., reading the same file multiple times) and keeps only the most recent output. Runs automatically on every request with zero LLM cost.
3740

38-
**Supersede Writes**Prunes write tool inputs for files that have subsequently been read. When a file is written and later read, the original write content becomes redundant since the current file state is captured in the read result. Runs automatically on every request with zero LLM cost.
41+
**Supersede Writes**Removes write tool calls for files that have subsequently been read. When a file is written and later read, the original write content becomes redundant since the current file state is captured in the read result. Runs automatically on every request with zero LLM cost.
3942

4043
**Purge Errors** — Prunes tool inputs for tools that returned errors after a configurable number of turns (default: 4). Error messages are preserved for context, but the potentially large input content is removed. Runs automatically on every request with zero LLM cost.
4144

@@ -47,13 +50,17 @@ LLM providers like Anthropic and OpenAI cache prompts based on exact prefix matc
4750

4851
**Trade-off:** You lose some cache read benefits but gain larger token savings from reduced context size and performance improvements through reduced context poisoning. In most cases, the token savings outweigh the cache miss cost—especially in long sessions where context bloat becomes significant.
4952

50-
> **Note:** In testing, cache hit rates were approximately 65% with DCP enabled vs 85% without.
53+
> **Note:** In testing, cache hit rates were approximately 80% with DCP enabled vs 85% without for most providers.
54+
55+
**Best use case:** Providers that count usage in requests, such as Github Copilot and Google Antigravity, have no negative price impact.
5156

5257
**Best use cases:**
5358

5459
- **Request-based billing** — Providers that count usage in requests, such as Github Copilot and Google Antigravity, have no negative price impact.
5560
- **Uniform token pricing** — Providers that bill cached tokens at the same rate as regular input tokens, such as Cerebras, see pure savings with no cache-miss penalty.
5661

62+
**Claude Subscriptions:** Anthropic subscription users (who receive "free" caching) may experience faster limit depletion than hit-rate ratios suggest due to the higher relative cost of cache misses. See [Claude Cache Limits](https://she-llac.com/claude-limits) for details.
63+
5764
## Configuration
5865

5966
DCP uses its own config file:
@@ -62,78 +69,86 @@ DCP uses its own config file:
6269
- Custom config directory: `$OPENCODE_CONFIG_DIR/dcp.jsonc` (or `dcp.json`), if `OPENCODE_CONFIG_DIR` is set
6370
- Project: `.opencode/dcp.jsonc` (or `dcp.json`) in your project's `.opencode` directory
6471

65-
<details>
66-
<summary><strong>Default Configuration</strong> (click to expand)</summary>
67-
68-
```jsonc
69-
{
70-
"$schema": "https://raw.githubusercontent.com/Opencode-DCP/opencode-dynamic-context-pruning/master/dcp.schema.json",
71-
// Enable or disable the plugin
72-
"enabled": true,
73-
// Enable debug logging to ~/.config/opencode/logs/dcp/
74-
"debug": false,
75-
// Notification display: "off", "minimal", or "detailed"
76-
"pruneNotification": "detailed",
77-
// Slash commands configuration
78-
"commands": {
79-
"enabled": true,
80-
// Additional tools to protect from pruning via commands (e.g., /dcp sweep)
81-
"protectedTools": [],
82-
},
83-
// Protect from pruning for <turns> message turns
84-
"turnProtection": {
85-
"enabled": false,
86-
"turns": 4,
87-
},
88-
// Protect file operations from pruning via glob patterns
89-
// Patterns match tool parameters.filePath (e.g. read/write/edit)
90-
"protectedFilePatterns": [],
91-
// LLM-driven context pruning tools
92-
"tools": {
93-
// Shared settings for all prune tools
94-
"settings": {
95-
// Nudge the LLM to use prune tools (every <nudgeFrequency> tool results)
96-
"nudgeEnabled": true,
97-
"nudgeFrequency": 10,
98-
// Additional tools to protect from pruning
99-
"protectedTools": [],
100-
},
101-
// Removes tool content from context without preservation (for completed tasks or noise)
102-
"discard": {
103-
"enabled": true,
104-
},
105-
// Distills key findings into preserved knowledge before removing raw content
106-
"extract": {
107-
"enabled": true,
108-
// Show distillation content as an ignored message notification
109-
"showDistillation": false,
110-
},
111-
},
112-
// Automatic pruning strategies
113-
"strategies": {
114-
// Remove duplicate tool calls (same tool with same arguments)
115-
"deduplication": {
116-
"enabled": true,
117-
// Additional tools to protect from pruning
118-
"protectedTools": [],
119-
},
120-
// Prune write tool inputs when the file has been subsequently read
121-
"supersedeWrites": {
122-
"enabled": false,
123-
},
124-
// Prune tool inputs for errored tools after X turns
125-
"purgeErrors": {
126-
"enabled": true,
127-
// Number of turns before errored tool inputs are pruned
128-
"turns": 4,
129-
// Additional tools to protect from pruning
130-
"protectedTools": [],
131-
},
132-
},
133-
}
134-
```
135-
136-
</details>
72+
> <details>
73+
> <summary><strong>Default Configuration</strong> (click to expand)</summary>
74+
>
75+
> ```jsonc
76+
> {
77+
> "$schema": "https://raw.githubusercontent.com/Opencode-DCP/opencode-dynamic-context-pruning/master/dcp.schema.json",
78+
> // Enable or disable the plugin
79+
> "enabled": true,
80+
> // Enable debug logging to ~/.config/opencode/logs/dcp/
81+
> "debug": false,
82+
> // Notification display: "off", "minimal", or "detailed"
83+
> "pruneNotification": "detailed",
84+
> // Notification type: "chat" (in-conversation) or "toast" (system toast)
85+
> "pruneNotificationType": "chat",
86+
> // Slash commands configuration
87+
> "commands": {
88+
> "enabled": true,
89+
> // Additional tools to protect from pruning via commands (e.g., /dcp sweep)
90+
> "protectedTools": [],
91+
> },
92+
> // Protect from pruning for <turns> message turns past tool invocation
93+
> "turnProtection": {
94+
> "enabled": false,
95+
> "turns": 4,
96+
> },
97+
> // Protect file operations from pruning via glob patterns
98+
> // Patterns match tool parameters.filePath (e.g. read/write/edit)
99+
> "protectedFilePatterns": [],
100+
> // LLM-driven context pruning tools
101+
> "tools": {
102+
> // Shared settings for all prune tools
103+
> "settings": {
104+
> // Nudge the LLM to use prune tools (every <nudgeFrequency> tool results)
105+
> "nudgeEnabled": true,
106+
> "nudgeFrequency": 10,
107+
> // Additional tools to protect from pruning
108+
> "protectedTools": [],
109+
> },
110+
> // Removes tool content from context without preservation (for completed tasks or noise)
111+
> "prune": {
112+
> "enabled": true,
113+
> },
114+
> // Distills key findings into preserved knowledge before removing raw content
115+
> "distill": {
116+
> "enabled": true,
117+
> // Show distillation content as an ignored message notification
118+
> "showDistillation": false,
119+
> },
120+
> // Collapses a range of conversation content into a single summary
121+
> "compress": {
122+
> "enabled": true,
123+
> // Show summary content as an ignored message notification
124+
> "showCompression": true,
125+
> },
126+
> },
127+
> // Automatic pruning strategies
128+
> "strategies": {
129+
> // Remove duplicate tool calls (same tool with same arguments)
130+
> "deduplication": {
131+
> "enabled": true,
132+
> // Additional tools to protect from pruning
133+
> "protectedTools": [],
134+
> },
135+
> // Prune write tool inputs when the file has been subsequently read
136+
> "supersedeWrites": {
137+
> "enabled": true,
138+
> },
139+
> // Prune tool inputs for errored tools after X turns
140+
> "purgeErrors": {
141+
> "enabled": true,
142+
> // Number of turns before errored tool inputs are pruned
143+
> "turns": 4,
144+
> // Additional tools to protect from pruning
145+
> "protectedTools": [],
146+
> },
147+
> },
148+
> }
149+
> ```
150+
>
151+
> </details>
137152
138153
### Commands
139154
@@ -144,14 +159,10 @@ DCP provides a `/dcp` slash command:
144159
- `/dcp stats` — Shows cumulative pruning statistics across all sessions.
145160
- `/dcp sweep` — Prunes all tools since the last user message. Accepts an optional count: `/dcp sweep 10` prunes the last 10 tools. Respects `commands.protectedTools`.
146161
147-
### Turn Protection
148-
149-
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.
150-
151162
### Protected Tools
152163
153-
By default, these tools are always protected from pruning across all strategies:
154-
`task`, `todowrite`, `todoread`, `discard`, `extract`, `batch`, `write`, `edit`
164+
By default, these tools are always protected from pruning:
165+
`task`, `todowrite`, `todoread`, `distill`, `compress`, `prune`, `batch`, `plan_enter`, `plan_exit`
155166
156167
The `protectedTools` arrays in each section add to this default list.
157168
@@ -169,4 +180,4 @@ Restart OpenCode after making config changes.
169180
170181
## License
171182
172-
MIT
183+
AGPL-3.0-or-later
File renamed without changes.

0 commit comments

Comments
 (0)