Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ opencode plugin add @tarquinen/opencode-dcp@latest

This installs the package and adds it to your global OpenCode config.

To try a local build in V2, run `npm install` and `npm run build` in this
directory, then add the directory to your project's `opencode.jsonc`:

```jsonc
{
"$schema": "https://opencode.ai/config.json",
"plugins": ["/absolute/path/to/opencode-dynamic-context-pruning"]
}
```

The existing V2 implementation is not yet fully equivalent to V1: compression
with the `ask` permission is blocked, and some command reports are logged rather
than displayed in the session. Test the features you rely on before replacing
your V1 installation.

## Project Status

Development on DCP has slowed because most new context-management work has moved to [Sleev](https://sleev.ai) and the `sleev` CLI.
Expand Down Expand Up @@ -61,7 +76,9 @@ DCP uses its own config file, searched in order:
2. Custom config directory: `$OPENCODE_CONFIG_DIR/dcp.jsonc` (or `dcp.json`), if `OPENCODE_CONFIG_DIR` is set
3. Project: `.opencode/dcp.jsonc` (or `dcp.json`) in your project's `.opencode` directory

Each level overrides the previous, so project settings take priority over global. Restart OpenCode after making config changes.
Each level overrides the previous, so project settings take priority over global. See
[`dcp.example.jsonc`](./dcp.example.jsonc) for all options, defaults, and V2 limitations.
DCP reads its settings when the plugin loads; reload OpenCode's configuration after changing them.

> [!NOTE]
> If your model has a smaller context window, lower `compress.minContextLimit` and `compress.maxContextLimit` in your configuration to match the available context.
Expand Down
96 changes: 96 additions & 0 deletions dcp.example.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
// Reference only: copy desired settings to ~/.config/opencode/dcp.jsonc or
// <project>/.opencode/dcp.jsonc. This example is not loaded automatically.
// Project values override global values; protected-tool lists are additive.
"$schema": "https://raw.githubusercontent.com/Opencode-DCP/opencode-dynamic-context-pruning/master/dcp.schema.json",

// Enable the plugin. Defaults are shown throughout this file.
"enabled": true,
// V1 npm auto-update setting; the V2 implementation does not run it.
"autoUpdate": true,
// Write diagnostic information to the DCP log directory.
"debug": false,
// Notification verbosity: "off", "minimal", or "detailed".
// V2 currently logs reports rather than showing chat/toast notifications.
"pruneNotification": "detailed",
// Notification destination: "chat" or "toast" (V2 limitation above).
"pruneNotificationType": "chat",

"commands": {
// Enable the /dcp panel and commands.
"enabled": true,
// Additional tools protected from command-based pruning; supports * and ?.
// Example: ["mcp_*", "my_tool_?"]
"protectedTools": []
},
"manualMode": {
// Start new sessions in manual mode; automatic compression is disabled.
"enabled": false,
// Keep automatic cleanup strategies available while in manual mode.
"automaticStrategies": true
},
"turnProtection": {
// Protect recent tool outputs from pruning.
"enabled": false,
// Number of recent turns to protect (at least 1).
"turns": 4
},
"experimental": {
// Allow processing and compression in subagent sessions.
"allowSubAgents": false,
// Enable prompt files in dcp-prompts override directories.
"customPrompts": false
},
// File path glob patterns whose matching tool calls should be protected.
// Example: ["**/AGENTS.md", "**/*.config.ts"]
"protectedFilePatterns": [],

"compress": {
// "range" summarizes spans; experimental "message" summarizes individual messages.
"mode": "range",
// "allow" runs without asking; "deny" disables compression. V2 currently
// blocks "ask" instead of displaying a permission prompt.
"permission": "allow",
// Include compression summaries in notifications (V2 reports are logged).
"showCompression": false,
// Add active summary tokens to the upper nudge threshold.
"summaryBuffer": true,
// Soft thresholds in tokens or as a percentage of the model context window.
// Above max, stronger nudges are sent; below min, reminders are suppressed.
"maxContextLimit": 100000,
"minContextLimit": 50000,
// Exact provider/model keys override the thresholds above for that model.
// Examples: { "provider/model": "80%" } and { "provider/model": "25%" }.
"modelMaxLimits": {},
"modelMinLimits": {},
// Above the maximum, nudge every N model fetches (minimum 1).
"nudgeFrequency": 5,
// Number of messages after the last user message before reminders (minimum 1).
"iterationNudgeThreshold": 15,
// "strong" encourages compression more aggressively than "soft".
"nudgeForce": "soft",
// Additional tools whose completed results are preserved in summaries.
// Supports * and ?; built-in protected tools remain protected.
"protectedTools": [],
// Preserve content enclosed in <protect>...</protect> tags.
"protectTags": false,
// Preserve user messages verbatim; large pasted messages then remain large.
"protectUserMessages": false
},
"strategies": {
"deduplication": {
// Remove older duplicate outputs for identical tool calls.
"enabled": true,
// Additional tool names/globs excluded from deduplication.
"protectedTools": []
},
"purgeErrors": {
// Prune inputs of old failed calls; retain their error messages.
"enabled": true,
// Wait this many turns before pruning failed tool inputs (minimum 1).
"turns": 4,
// Additional tool names/globs excluded from error purging.
"protectedTools": []
}
}
}
1 change: 1 addition & 0 deletions lib/tui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type Theme = Pick<
>
export type ThemeColor = keyof Theme
export type ViewApi = {
centeredDialog?: boolean
theme: { readonly current: Theme }
renderer: Pick<TuiApi["renderer"], "height" | "on" | "off">
ui: { dialog: { clear(): void } }
Expand Down
7 changes: 5 additions & 2 deletions lib/tui/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ export function DcpFrame(props: {
let inner: BoxRenderable | undefined
function available() {
const height = props.api.renderer.height
return Math.max(10, height - Math.floor(height / 4) - 2) - FRAME_OVERHEAD
const reserved = props.api.centeredDialog ? 4 : Math.floor(height / 4) + 2
return Math.max(1, height - reserved - FRAME_OVERHEAD)
}
function resize() {
if (body) body.height = Math.min(inner?.height || available(), available())
const extra = props.api.centeredDialog ? 2 : 0
if (body)
body.height = Math.min(inner?.height ? inner.height + extra : available(), available())
}
return (
<box paddingLeft={3} paddingRight={3} paddingBottom={1} gap={1}>
Expand Down
3 changes: 2 additions & 1 deletion lib/v2/tui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export async function setup(ctx: Plugin.Context) {
const options = () => ({ location: ctx.location ?? ctx.data.location.default() })
if (!(await client.status({}, options())).enabled) return
const api: ViewApi = {
centeredDialog: true,
renderer: ctx.renderer,
theme: {
get current() {
Expand All @@ -19,8 +20,8 @@ export async function setup(ctx: Plugin.Context) {
ui: { dialog: { clear: () => ctx.ui.dialog.clear() } },
}
function show(render: Parameters<typeof ctx.ui.dialog.show>[0]) {
ctx.ui.dialog.set({ size: "xlarge" })
ctx.ui.dialog.show(render)
ctx.ui.dialog.set({ size: "large", centered: true })
}
async function open(page: "panel" | "context" | "stats" = "panel") {
const route = ctx.ui.router.current()
Expand Down
Loading