Skip to content

Commit 3d9e4df

Browse files
authored
Merge pull request #327 from Opencode-DCP/prompt/refactor
refactor(prompts): dcp prompt system + prompt dx cli + new tool names
2 parents e1f5312 + 5863a1d commit 3d9e4df

46 files changed

Lines changed: 591 additions & 790 deletions

Some content is hidden

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

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ test-update.ts
3636
# Documentation (local development only)
3737
docs/
3838
SCHEMA_NOTES.md
39+
40+
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: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ DCP uses multiple tools and strategies to reduce context size:
2828

2929
### Tools
3030

31-
**Discard** — Exposes a `discard` tool that the AI can call to remove completed or noisy tool content from context.
31+
**Prune** — Exposes a `prune` tool that the AI can call to remove completed or noisy tool content from context.
3232

33-
**Extract** — Exposes an `extract` tool that the AI can call to distill valuable context into concise summaries before removing the tool content.
33+
**Distill** — Exposes a `distill` tool that the AI can call to distill valuable context into concise summaries before removing the tool content.
3434

35-
**Squash** — Exposes a `squash` tool that the AI can call to collapse a large section of conversation (messages and tools) into a single summary.
35+
**Compress** — Exposes a `compress` tool that the AI can call to collapse a large section of conversation (messages and tools) into a single summary.
3636

3737
### Strategies
3838

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

6161
- Global: `~/.config/opencode/dcp.jsonc` (or `dcp.json`), created automatically on first run
6262
- Custom config directory: `$OPENCODE_CONFIG_DIR/dcp.jsonc` (or `dcp.json`), if `OPENCODE_CONFIG_DIR` is set
63-
- 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
6464

6565
<details>
6666
<summary><strong>Default Configuration</strong> (click to expand)</summary>
@@ -99,17 +99,17 @@ DCP uses its own config file:
9999
"protectedTools": [],
100100
},
101101
// Removes tool content from context without preservation (for completed tasks or noise)
102-
"discard": {
102+
"prune": {
103103
"enabled": true,
104104
},
105105
// Distills key findings into preserved knowledge before removing raw content
106-
"extract": {
106+
"distill": {
107107
"enabled": true,
108108
// Show distillation content as an ignored message notification
109109
"showDistillation": false,
110110
},
111111
// Collapses a range of conversation content into a single summary
112-
"squash": {
112+
"compress": {
113113
"enabled": true,
114114
// Show summary content as an ignored message notification
115115
"showSummary": true,
@@ -152,12 +152,12 @@ DCP provides a `/dcp` slash command:
152152

153153
### Turn Protection
154154

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 `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.
156156

157157
### Protected Tools
158158

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

162162
The `protectedTools` arrays in each section add to this default list.
163163

cli/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# DCP CLI
2+
3+
Dev tool for previewing prompt outputs. Verify parsing works correctly and quickly check specific tool combinations.
4+
5+
## Usage
6+
7+
```bash
8+
bun run dcp [TYPE] [-p] [-d] [-c]
9+
```
10+
11+
## Types
12+
13+
| Flag | Description |
14+
| -------------------- | --------------------------- |
15+
| `--system` | System prompt |
16+
| `--nudge` | Nudge prompt |
17+
| `--prune-list` | Example prunable tools list |
18+
| `--compress-context` | Example compress context |
19+
20+
## Tool Flags
21+
22+
| Flag | Description |
23+
| ---------------- | -------------------- |
24+
| `-p, --prune` | Enable prune tool |
25+
| `-d, --distill` | Enable distill tool |
26+
| `-c, --compress` | Enable compress tool |
27+
28+
If no tool flags specified, all are enabled.
29+
30+
## Examples
31+
32+
```bash
33+
bun run dcp --system -p -d -c # System prompt with all tools
34+
bun run dcp --system -p # System prompt with prune only
35+
bun run dcp --nudge -d -c # Nudge with distill and compress
36+
bun run dcp --prune-list # Example prunable tools list
37+
```
38+
39+
## Purpose
40+
41+
This CLI does NOT ship with the plugin. It's purely for DX - iterate on prompt templates and verify the `<tool></tool>` conditional parsing produces the expected output.

cli/print.ts

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/usr/bin/env npx tsx
2+
3+
import { renderSystemPrompt, renderNudge, type ToolFlags } from "../lib/prompts/index.js"
4+
import {
5+
wrapPrunableTools,
6+
wrapCompressContext,
7+
wrapCooldownMessage,
8+
} from "../lib/messages/inject.js"
9+
10+
const args = process.argv.slice(2)
11+
12+
const flags: ToolFlags = {
13+
prune: args.includes("-p") || args.includes("--prune"),
14+
distill: args.includes("-d") || args.includes("--distill"),
15+
compress: args.includes("-c") || args.includes("--compress"),
16+
}
17+
18+
// Default to all enabled if none specified
19+
if (!flags.prune && !flags.distill && !flags.compress) {
20+
flags.prune = true
21+
flags.distill = true
22+
flags.compress = true
23+
}
24+
25+
const showSystem = args.includes("--system")
26+
const showNudge = args.includes("--nudge")
27+
const showPruneList = args.includes("--prune-list")
28+
const showCompressContext = args.includes("--compress-context")
29+
const showCooldown = args.includes("--cooldown")
30+
const showHelp = args.includes("--help") || args.includes("-h")
31+
32+
if (
33+
showHelp ||
34+
(!showSystem && !showNudge && !showPruneList && !showCompressContext && !showCooldown)
35+
) {
36+
console.log(`
37+
Usage: bun run dcp [TYPE] [-p] [-d] [-c]
38+
39+
Types:
40+
--system System prompt
41+
--nudge Nudge prompt
42+
--prune-list Example prunable tools list
43+
--compress-context Example compress context
44+
--cooldown Cooldown message after pruning
45+
46+
Tool flags (for --system and --nudge):
47+
-p, --prune Enable prune tool
48+
-d, --distill Enable distill tool
49+
-c, --compress Enable compress tool
50+
51+
If no tool flags specified, all are enabled.
52+
53+
Examples:
54+
bun run dcp --system -p -d -c # System prompt with all tools
55+
bun run dcp --system -p # System prompt with prune only
56+
bun run dcp --nudge -d -c # Nudge with distill and compress
57+
bun run dcp --prune-list # Example prunable tools list
58+
`)
59+
process.exit(0)
60+
}
61+
62+
const header = (title: string) => {
63+
console.log()
64+
console.log("─".repeat(60))
65+
console.log(title)
66+
console.log("─".repeat(60))
67+
}
68+
69+
if (showSystem) {
70+
const enabled = [
71+
flags.prune && "prune",
72+
flags.distill && "distill",
73+
flags.compress && "compress",
74+
]
75+
.filter(Boolean)
76+
.join(", ")
77+
header(`SYSTEM PROMPT (tools: ${enabled})`)
78+
console.log(renderSystemPrompt(flags))
79+
}
80+
81+
if (showNudge) {
82+
const enabled = [
83+
flags.prune && "prune",
84+
flags.distill && "distill",
85+
flags.compress && "compress",
86+
]
87+
.filter(Boolean)
88+
.join(", ")
89+
header(`NUDGE (tools: ${enabled})`)
90+
console.log(renderNudge(flags))
91+
}
92+
93+
if (showPruneList) {
94+
header("PRUNABLE TOOLS LIST (mock example)")
95+
const mockList = `5: read, /path/to/file.ts
96+
8: bash, npm run build
97+
12: glob, src/**/*.ts
98+
15: read, /path/to/another-file.ts`
99+
console.log(wrapPrunableTools(mockList))
100+
}
101+
102+
if (showCompressContext) {
103+
header("COMPRESS CONTEXT (mock example)")
104+
console.log(wrapCompressContext(45))
105+
}
106+
107+
if (showCooldown) {
108+
const enabled = [
109+
flags.prune && "prune",
110+
flags.distill && "distill",
111+
flags.compress && "compress",
112+
]
113+
.filter(Boolean)
114+
.join(", ")
115+
header(`COOLDOWN MESSAGE (tools: ${enabled})`)
116+
console.log(wrapCooldownMessage(flags))
117+
}

dcp.schema.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,27 +105,27 @@
105105
}
106106
}
107107
},
108-
"discard": {
108+
"prune": {
109109
"type": "object",
110-
"description": "Configuration for the discard tool",
110+
"description": "Configuration for the prune tool",
111111
"additionalProperties": false,
112112
"properties": {
113113
"enabled": {
114114
"type": "boolean",
115115
"default": true,
116-
"description": "Enable the discard tool"
116+
"description": "Enable the prune tool"
117117
}
118118
}
119119
},
120-
"extract": {
120+
"distill": {
121121
"type": "object",
122-
"description": "Configuration for the extract tool",
122+
"description": "Configuration for the distill tool",
123123
"additionalProperties": false,
124124
"properties": {
125125
"enabled": {
126126
"type": "boolean",
127127
"default": true,
128-
"description": "Enable the extract tool"
128+
"description": "Enable the distill tool"
129129
},
130130
"showDistillation": {
131131
"type": "boolean",
@@ -134,15 +134,15 @@
134134
}
135135
}
136136
},
137-
"squash": {
137+
"compress": {
138138
"type": "object",
139-
"description": "Configuration for the squash tool",
139+
"description": "Configuration for the compress tool",
140140
"additionalProperties": false,
141141
"properties": {
142142
"enabled": {
143143
"type": "boolean",
144144
"default": true,
145-
"description": "Enable the squash tool"
145+
"description": "Enable the compress tool"
146146
},
147147
"showSummary": {
148148
"type": "boolean",

index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ 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, createSquashTool } from "./lib/strategies"
5+
import { createPruneTool, createDistillTool, createCompressTool } from "./lib/strategies"
66
import {
77
createChatMessageTransformHandler,
88
createCommandExecuteHandler,
@@ -61,26 +61,26 @@ const plugin: Plugin = (async (ctx) => {
6161
ctx.directory,
6262
),
6363
tool: {
64-
...(config.tools.discard.enabled && {
65-
discard: createDiscardTool({
64+
...(config.tools.distill.enabled && {
65+
distill: createDistillTool({
6666
client: ctx.client,
6767
state,
6868
logger,
6969
config,
7070
workingDirectory: ctx.directory,
7171
}),
7272
}),
73-
...(config.tools.extract.enabled && {
74-
extract: createExtractTool({
73+
...(config.tools.compress.enabled && {
74+
compress: createCompressTool({
7575
client: ctx.client,
7676
state,
7777
logger,
7878
config,
7979
workingDirectory: ctx.directory,
8080
}),
8181
}),
82-
...(config.tools.squash.enabled && {
83-
squash: createSquashTool({
82+
...(config.tools.prune.enabled && {
83+
prune: createPruneTool({
8484
client: ctx.client,
8585
state,
8686
logger,
@@ -99,9 +99,9 @@ const plugin: Plugin = (async (ctx) => {
9999
}
100100

101101
const toolsToAdd: string[] = []
102-
if (config.tools.discard.enabled) toolsToAdd.push("discard")
103-
if (config.tools.extract.enabled) toolsToAdd.push("extract")
104-
if (config.tools.squash.enabled) toolsToAdd.push("squash")
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")
105105

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

0 commit comments

Comments
 (0)