@lexwdex-org/opencode-dcp 3.4.10 → 3.4.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +54 -253
- package/README.md +67 -246
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +785 -7461
- package/dist/index.js.map +1 -1
- package/dist/lib/auto-prune.d.ts +20 -0
- package/dist/lib/auto-prune.d.ts.map +1 -0
- package/dist/lib/config.d.ts +18 -54
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/hooks.d.ts +29 -28
- package/dist/lib/hooks.d.ts.map +1 -1
- package/dist/lib/prompts/compaction.d.ts +2 -0
- package/dist/lib/prompts/compaction.d.ts.map +1 -0
- package/dist/lib/prompts/store.d.ts +4 -14
- package/dist/lib/prompts/store.d.ts.map +1 -1
- package/dist/lib/prune-tool.d.ts +15 -0
- package/dist/lib/prune-tool.d.ts.map +1 -0
- package/dist/lib/session-model.d.ts +8 -0
- package/dist/lib/session-model.d.ts.map +1 -0
- package/dist/lib/summarize.d.ts +35 -0
- package/dist/lib/summarize.d.ts.map +1 -0
- package/package.json +2 -3
- package/dist/lib/commands/compression-targets.d.ts +0 -14
- package/dist/lib/commands/compression-targets.d.ts.map +0 -1
- package/dist/lib/commands/context.d.ts +0 -53
- package/dist/lib/commands/context.d.ts.map +0 -1
- package/dist/lib/commands/decompress.d.ts +0 -13
- package/dist/lib/commands/decompress.d.ts.map +0 -1
- package/dist/lib/commands/help.d.ts +0 -18
- package/dist/lib/commands/help.d.ts.map +0 -1
- package/dist/lib/commands/index.d.ts +0 -8
- package/dist/lib/commands/index.d.ts.map +0 -1
- package/dist/lib/commands/manual.d.ts +0 -24
- package/dist/lib/commands/manual.d.ts.map +0 -1
- package/dist/lib/commands/recompress.d.ts +0 -13
- package/dist/lib/commands/recompress.d.ts.map +0 -1
- package/dist/lib/commands/stats.d.ts +0 -16
- package/dist/lib/commands/stats.d.ts.map +0 -1
- package/dist/lib/commands/sweep.d.ts +0 -24
- package/dist/lib/commands/sweep.d.ts.map +0 -1
- package/dist/lib/compress/external-content.d.ts +0 -4
- package/dist/lib/compress/external-content.d.ts.map +0 -1
- package/dist/lib/compress/external-inference.d.ts +0 -15
- package/dist/lib/compress/external-inference.d.ts.map +0 -1
- package/dist/lib/compress/index.d.ts +0 -4
- package/dist/lib/compress/index.d.ts.map +0 -1
- package/dist/lib/compress/message-utils.d.ts +0 -8
- package/dist/lib/compress/message-utils.d.ts.map +0 -1
- package/dist/lib/compress/message.d.ts +0 -4
- package/dist/lib/compress/message.d.ts.map +0 -1
- package/dist/lib/compress/pipeline.d.ts +0 -30
- package/dist/lib/compress/pipeline.d.ts.map +0 -1
- package/dist/lib/compress/protected-content.d.ts +0 -8
- package/dist/lib/compress/protected-content.d.ts.map +0 -1
- package/dist/lib/compress/range-utils.d.ts +0 -10
- package/dist/lib/compress/range-utils.d.ts.map +0 -1
- package/dist/lib/compress/range.d.ts +0 -4
- package/dist/lib/compress/range.d.ts.map +0 -1
- package/dist/lib/compress/search.d.ts +0 -12
- package/dist/lib/compress/search.d.ts.map +0 -1
- package/dist/lib/compress/state.d.ts +0 -9
- package/dist/lib/compress/state.d.ts.map +0 -1
- package/dist/lib/compress/timing.d.ts +0 -20
- package/dist/lib/compress/timing.d.ts.map +0 -1
- package/dist/lib/compress/types.d.ts +0 -95
- package/dist/lib/compress/types.d.ts.map +0 -1
- package/dist/lib/compress-permission.d.ts +0 -6
- package/dist/lib/compress-permission.d.ts.map +0 -1
- package/dist/lib/concurrency.d.ts +0 -2
- package/dist/lib/concurrency.d.ts.map +0 -1
- package/dist/lib/config-env-override.d.ts +0 -3
- package/dist/lib/config-env-override.d.ts.map +0 -1
- package/dist/lib/host-permissions.d.ts +0 -11
- package/dist/lib/host-permissions.d.ts.map +0 -1
- package/dist/lib/message-ids.d.ts +0 -19
- package/dist/lib/message-ids.d.ts.map +0 -1
- package/dist/lib/messages/index.d.ts +0 -9
- package/dist/lib/messages/index.d.ts.map +0 -1
- package/dist/lib/messages/inject/inject.d.ts +0 -8
- package/dist/lib/messages/inject/inject.d.ts.map +0 -1
- package/dist/lib/messages/inject/subagent-results.d.ts +0 -5
- package/dist/lib/messages/inject/subagent-results.d.ts.map +0 -1
- package/dist/lib/messages/inject/utils.d.ts +0 -24
- package/dist/lib/messages/inject/utils.d.ts.map +0 -1
- package/dist/lib/messages/priority.d.ts +0 -13
- package/dist/lib/messages/priority.d.ts.map +0 -1
- package/dist/lib/messages/prune.d.ts +0 -5
- package/dist/lib/messages/prune.d.ts.map +0 -1
- package/dist/lib/messages/query.d.ts +0 -7
- package/dist/lib/messages/query.d.ts.map +0 -1
- package/dist/lib/messages/reasoning-strip.d.ts +0 -8
- package/dist/lib/messages/reasoning-strip.d.ts.map +0 -1
- package/dist/lib/messages/shape.d.ts +0 -5
- package/dist/lib/messages/shape.d.ts.map +0 -1
- package/dist/lib/messages/sync.d.ts +0 -4
- package/dist/lib/messages/sync.d.ts.map +0 -1
- package/dist/lib/messages/utils.d.ts +0 -27
- package/dist/lib/messages/utils.d.ts.map +0 -1
- package/dist/lib/prompts/compress-message.d.ts +0 -2
- package/dist/lib/prompts/compress-message.d.ts.map +0 -1
- package/dist/lib/prompts/compress-range.d.ts +0 -2
- package/dist/lib/prompts/compress-range.d.ts.map +0 -1
- package/dist/lib/prompts/context-limit-nudge.d.ts +0 -2
- package/dist/lib/prompts/context-limit-nudge.d.ts.map +0 -1
- package/dist/lib/prompts/extensions/nudge.d.ts +0 -7
- package/dist/lib/prompts/extensions/nudge.d.ts.map +0 -1
- package/dist/lib/prompts/extensions/system.d.ts +0 -4
- package/dist/lib/prompts/extensions/system.d.ts.map +0 -1
- package/dist/lib/prompts/extensions/tool.d.ts +0 -5
- package/dist/lib/prompts/extensions/tool.d.ts.map +0 -1
- package/dist/lib/prompts/index.d.ts +0 -4
- package/dist/lib/prompts/index.d.ts.map +0 -1
- package/dist/lib/prompts/iteration-nudge.d.ts +0 -2
- package/dist/lib/prompts/iteration-nudge.d.ts.map +0 -1
- package/dist/lib/prompts/system.d.ts +0 -2
- package/dist/lib/prompts/system.d.ts.map +0 -1
- package/dist/lib/prompts/turn-nudge.d.ts +0 -2
- package/dist/lib/prompts/turn-nudge.d.ts.map +0 -1
- package/dist/lib/protected-patterns.d.ts +0 -5
- package/dist/lib/protected-patterns.d.ts.map +0 -1
- package/dist/lib/state/index.d.ts +0 -6
- package/dist/lib/state/index.d.ts.map +0 -1
- package/dist/lib/state/persistence.d.ts +0 -51
- package/dist/lib/state/persistence.d.ts.map +0 -1
- package/dist/lib/state/state.d.ts +0 -10
- package/dist/lib/state/state.d.ts.map +0 -1
- package/dist/lib/state/store.d.ts +0 -38
- package/dist/lib/state/store.d.ts.map +0 -1
- package/dist/lib/state/tool-cache.d.ts +0 -13
- package/dist/lib/state/tool-cache.d.ts.map +0 -1
- package/dist/lib/state/types.d.ts +0 -100
- package/dist/lib/state/types.d.ts.map +0 -1
- package/dist/lib/state/utils.d.ts +0 -25
- package/dist/lib/state/utils.d.ts.map +0 -1
- package/dist/lib/strategies/deduplication.d.ts +0 -10
- package/dist/lib/strategies/deduplication.d.ts.map +0 -1
- package/dist/lib/strategies/index.d.ts +0 -3
- package/dist/lib/strategies/index.d.ts.map +0 -1
- package/dist/lib/strategies/purge-errors.d.ts +0 -13
- package/dist/lib/strategies/purge-errors.d.ts.map +0 -1
- package/dist/lib/subagents/subagent-results.d.ts +0 -5
- package/dist/lib/subagents/subagent-results.d.ts.map +0 -1
- package/dist/lib/token-utils.d.ts +0 -18
- package/dist/lib/token-utils.d.ts.map +0 -1
- package/dist/lib/ui/notification.d.ts +0 -18
- package/dist/lib/ui/notification.d.ts.map +0 -1
- package/dist/lib/ui/utils.d.ts +0 -10
- package/dist/lib/ui/utils.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,296 +1,117 @@
|
|
|
1
1
|
# 动态上下文剪枝插件
|
|
2
2
|
|
|
3
|
-
[](https://ko-fi.com/dansmolsky)
|
|
4
3
|
[](https://www.npmjs.com/package/@lexwdex-org/opencode-dcp)
|
|
5
4
|
|
|
6
5
|
[**English**](./README.en.md) | **中文**
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-

|
|
11
|
-
|
|
12
|
-
## 安装
|
|
13
|
-
|
|
14
|
-
从 CLI 安装:
|
|
15
|
-
|
|
16
|
-
```bash
|
|
17
|
-
opencode plugin @lexwdex-org/opencode-dcp@latest --global
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
这会安装该包并将其添加到全局 OpenCode 配置中。
|
|
7
|
+
DCP 为 OpenCode 原生 compaction 提供语义剪枝策略与主动触发机制。它不维护消息标记、消息 ID、压缩块、锚点或占位符。
|
|
21
8
|
|
|
22
9
|
## 工作原理
|
|
23
10
|
|
|
24
|
-
|
|
11
|
+
OpenCode 原生 compaction 负责生成和保存一个滚动检查点,并在后续模型请求中只发送:
|
|
25
12
|
|
|
26
|
-
|
|
13
|
+
```text
|
|
14
|
+
最新剪枝检查点 + 尚未压缩的近期尾部
|
|
15
|
+
```
|
|
27
16
|
|
|
28
|
-
|
|
17
|
+
DCP 在 `experimental.session.compacting` 阶段提供专用提示词,把检查点组织为固定三段结构:
|
|
29
18
|
|
|
30
|
-
|
|
19
|
+
- `## 系统上下文` — AGENTS.md、项目规则等系统级内容,从上一份检查点原样保留合并;
|
|
20
|
+
- `## 历史概要` — 早期历史和中部历史高度压缩:每项主题只留一句结论,不含过程;
|
|
21
|
+
- 最近任务 — 轻度压缩:已完成任务一句话概括;进行中任务保留完整详情(目标、已完成步骤、文件路径、关键决策、阻塞、下一步)。与当前任务相关的近期细节优先保留,保证凭检查点即可直接继续工作。
|
|
31
22
|
|
|
32
|
-
|
|
33
|
-
- `message` 模式(实验性)独立压缩单条原始消息,让模型能够更精细地管理上下文。
|
|
23
|
+
## 触发压缩
|
|
34
24
|
|
|
35
|
-
|
|
25
|
+
- **OpenCode 自动 compaction**:达到宿主阈值时自动运行。
|
|
26
|
+
- **模型调用 `dcp_prune` 工具**:插件注册的 LLM 工具,描述内置启发式规则——话题明显变更、任务收尾、上下文明显变长时立即调用。
|
|
27
|
+
- **插件启发式自动触发**(`autoPrune`):监听用户消息流,在回合边界(`session.idle`)触发原生压缩:
|
|
28
|
+
- 话题变更:新消息与近期消息的词面相似度骤降(CJK 二元组 + Jaccard);
|
|
29
|
+
- 消息量达到阈值;
|
|
30
|
+
- 长时间中断后恢复。
|
|
31
|
+
自动触发带冷却期;OpenCode 原生 `/compact` 或宿主压缩也会重置计数。
|
|
32
|
+
- **OpenCode 原生 `/compact`**:手动触发同一条 compaction 路径。
|
|
33
|
+
- **`/dcp summarize`**:手动调用原生 `session.summarize()`。
|
|
36
34
|
|
|
37
|
-
|
|
35
|
+
所有入口都经过同一协调器:同一会话的并发请求合并为一次原生调用;失败不会提交半成品检查点,原始上下文保持可用,默认 30 秒内不重试失败的请求。
|
|
38
36
|
|
|
39
|
-
|
|
37
|
+
压缩后的旧前缀不会再发送给模型,但 OpenCode 数据库中的原始会话历史不会被物理删除。下一次压缩会把旧检查点和新增尾部合并为一个新检查点,不会形成嵌套摘要。
|
|
40
38
|
|
|
41
|
-
|
|
39
|
+
## 安装
|
|
42
40
|
|
|
43
|
-
|
|
41
|
+
```bash
|
|
42
|
+
opencode plugin @lexwdex-org/opencode-dcp@latest --global
|
|
43
|
+
```
|
|
44
44
|
|
|
45
45
|
## 配置
|
|
46
46
|
|
|
47
|
-
DCP
|
|
47
|
+
DCP 依次读取以下配置,后面的层覆盖前面的层:
|
|
48
48
|
|
|
49
|
-
1.
|
|
50
|
-
2.
|
|
51
|
-
3.
|
|
52
|
-
|
|
53
|
-
每个层级覆盖前一个层级,因此项目设置优先于全局设置。修改配置后请重启 OpenCode。
|
|
54
|
-
|
|
55
|
-
> [!NOTE]
|
|
56
|
-
> 如果你使用的是较小上下文窗口的模型,例如 GitHub Copilot 模型或本地模型,请在配置中降低 `compress.minContextLimit` 和 `compress.maxContextLimit` 以匹配可用上下文。
|
|
57
|
-
|
|
58
|
-
> [!IMPORTANT]
|
|
59
|
-
> 默认值会自动应用。展开此项可查看或覆盖设置。
|
|
60
|
-
|
|
61
|
-
<details>
|
|
62
|
-
<summary><strong>默认配置</strong>(点击展开)</summary>
|
|
49
|
+
1. `~/.config/opencode/dcp.jsonc` 或 `dcp.json`
|
|
50
|
+
2. `$OPENCODE_CONFIG_DIR/dcp.jsonc` 或 `dcp.json`
|
|
51
|
+
3. 项目的 `.opencode/dcp.jsonc` 或 `dcp.json`
|
|
63
52
|
|
|
64
53
|
```jsonc
|
|
65
54
|
{
|
|
66
55
|
"$schema": "https://raw.githubusercontent.com/LeXwDeX/opencode-dynamic-context-pruning/master/dcp.schema.json",
|
|
67
|
-
// Enable or disable the plugin
|
|
68
56
|
"enabled": true,
|
|
69
|
-
// Check npm for a newer DCP release and show an update notification.
|
|
70
|
-
// The plugin never deletes or replaces its active installation.
|
|
71
57
|
"autoUpdate": true,
|
|
72
|
-
// Enable debug logging to ~/.config/opencode/logs/dcp/
|
|
73
58
|
"debug": false,
|
|
74
|
-
// Notification display: "off", "minimal", or "detailed"
|
|
75
|
-
"pruneNotification": "detailed",
|
|
76
|
-
// Notification type: "chat" (in-conversation) or "toast" (system toast)
|
|
77
|
-
"pruneNotificationType": "chat",
|
|
78
|
-
// Slash commands configuration
|
|
79
59
|
"commands": {
|
|
80
60
|
"enabled": true,
|
|
81
|
-
// Additional tools to protect from pruning via commands (e.g., /dcp sweep)
|
|
82
|
-
"protectedTools": [],
|
|
83
61
|
},
|
|
84
|
-
// Manual mode: disables autonomous context management,
|
|
85
|
-
// tools only run when explicitly triggered via /dcp commands
|
|
86
|
-
"manualMode": {
|
|
87
|
-
"enabled": false,
|
|
88
|
-
// When true, automatic cleanup (deduplication, purgeErrors)
|
|
89
|
-
// still runs even in manual mode
|
|
90
|
-
"automaticStrategies": true,
|
|
91
|
-
},
|
|
92
|
-
// Protect from pruning for <turns> message turns past tool invocation
|
|
93
|
-
"turnProtection": {
|
|
94
|
-
"enabled": false,
|
|
95
|
-
"turns": 4,
|
|
96
|
-
},
|
|
97
|
-
// Experimental settings
|
|
98
62
|
"experimental": {
|
|
99
|
-
// Allow DCP processing in subagent sessions
|
|
100
|
-
"allowSubAgents": false,
|
|
101
|
-
// Enable user-editable prompt overrides under dcp-prompts directories
|
|
102
|
-
// When false (default), prompt override files/directories are ignored
|
|
103
63
|
"customPrompts": false,
|
|
104
64
|
},
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
"protectedFilePatterns": [],
|
|
108
|
-
// Unified context compression tool and behavior settings
|
|
109
|
-
"compress": {
|
|
110
|
-
// Compression mode: "range" (compress spans into block summaries)
|
|
111
|
-
// or experimental "message" (compress individual raw messages)
|
|
112
|
-
"mode": "range",
|
|
113
|
-
// Permission mode: "allow" (no prompt), "ask" (prompt), "deny" (tool not registered)
|
|
114
|
-
"permission": "allow",
|
|
115
|
-
// Show compression content in a chat notification
|
|
116
|
-
"showCompression": false,
|
|
117
|
-
// Let active summary tokens extend the effective maxContextLimit
|
|
118
|
-
"summaryBuffer": true,
|
|
119
|
-
// Soft upper threshold: above this, DCP keeps injecting strong
|
|
120
|
-
// compression nudges (based on nudgeFrequency), so compression is
|
|
121
|
-
// much more likely. Accepts: number or "X%" of model context window.
|
|
122
|
-
"maxContextLimit": "85%",
|
|
123
|
-
// Soft lower threshold for reminder nudges: below this, turn/iteration
|
|
124
|
-
// reminders are off (compression less likely). At/above this, reminders
|
|
125
|
-
// are on. Accepts: number or "X%" of model context window.
|
|
126
|
-
"minContextLimit": "50%",
|
|
127
|
-
// When true (default), DCP injects a soft turn-boundary reminder at every
|
|
128
|
-
// new user turn, after session.idle, and after vcs.branch.updated events —
|
|
129
|
-
// regardless of minContextLimit, and only while below maxContextLimit —
|
|
130
|
-
// asking the model to compress the previous task when the topic changed
|
|
131
|
-
// (throttled by nudgeFrequency).
|
|
132
|
-
"boundaryNudge": true,
|
|
133
|
-
// Optional per-model override for maxContextLimit by providerID/modelID.
|
|
134
|
-
// If present, this wins over the global maxContextLimit.
|
|
135
|
-
// Accepts: number or "X%".
|
|
136
|
-
// Example:
|
|
137
|
-
// "modelMaxLimits": {
|
|
138
|
-
// "openai/gpt-5.3-codex": 120000,
|
|
139
|
-
// "anthropic/claude-sonnet-4.6": "80%"
|
|
140
|
-
// },
|
|
141
|
-
// Optional per-model override for minContextLimit.
|
|
142
|
-
// If present, this wins over the global minContextLimit.
|
|
143
|
-
// "modelMinLimits": {
|
|
144
|
-
// "openai/gpt-5.3-codex": 50000,
|
|
145
|
-
// "anthropic/claude-sonnet-4.6": "25%"
|
|
146
|
-
// },
|
|
147
|
-
// How often the context-limit nudge fires (1 = every fetch, 2 = every 2nd)
|
|
148
|
-
"nudgeFrequency": 2,
|
|
149
|
-
// Start adding compression reminders after this many
|
|
150
|
-
// messages have happened since the last user message
|
|
151
|
-
"iterationNudgeThreshold": 15,
|
|
152
|
-
// Controls how likely compression is after user messages
|
|
153
|
-
// ("strong" = more likely, "soft" = less likely)
|
|
154
|
-
"nudgeForce": "strong",
|
|
155
|
-
// Tool names whose completed outputs are appended to the compression
|
|
156
|
-
"protectedTools": [],
|
|
157
|
-
// Preserve text wrapped in <protect>...</protect> when compressed
|
|
158
|
-
"protectTags": false,
|
|
159
|
-
// Preserve your messages during compression.
|
|
160
|
-
// Warning: large copy-pasted prompts will never be compressed away
|
|
161
|
-
"protectUserMessages": false,
|
|
65
|
+
"summarize": {
|
|
66
|
+
"failureCooldownMs": 30000,
|
|
162
67
|
},
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
"
|
|
173
|
-
"enabled": true,
|
|
174
|
-
// Number of turns before errored tool inputs are pruned
|
|
175
|
-
"turns": 4,
|
|
176
|
-
// Additional tools to protect from pruning
|
|
177
|
-
"protectedTools": [],
|
|
178
|
-
},
|
|
68
|
+
"tool": {
|
|
69
|
+
"enabled": true,
|
|
70
|
+
},
|
|
71
|
+
"autoPrune": {
|
|
72
|
+
"enabled": true,
|
|
73
|
+
"minMessages": 8,
|
|
74
|
+
"volumeThreshold": 30,
|
|
75
|
+
"driftThreshold": 0.18,
|
|
76
|
+
"idleGapMs": 1800000,
|
|
77
|
+
"cooldownMs": 300000,
|
|
179
78
|
},
|
|
180
79
|
}
|
|
181
80
|
```
|
|
182
81
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
- `/dcp sweep` — 修剪自上次用户消息以来的所有工具。接受可选数量:`/dcp sweep 10` 修剪最后 10 个工具。遵循 `commands.protectedTools`。
|
|
193
|
-
- `/dcp manual [on|off]` — 切换手动模式或设置显式状态。开启时,AI 不会自主使用上下文管理工具。
|
|
194
|
-
- `/dcp compress [focus]` — 触发一次压缩工具执行。可选的 focus 文本指示要压缩的内容,遵循当前的 `compress.mode`。
|
|
195
|
-
- `/dcp decompress <n>` — 按 ID 恢复特定的活跃压缩(例如 `/dcp decompress 2`)。不加参数运行时显示可用的压缩 ID、token 大小和主题。
|
|
196
|
-
- `/dcp recompress <n>` — 按 ID 重新压缩用户已解压的压缩(例如 `/dcp recompress 2`)。不加参数运行时显示可重新压缩的 ID、token 大小和主题。
|
|
197
|
-
|
|
198
|
-
### 提示词覆盖
|
|
82
|
+
| 键 | 说明 |
|
|
83
|
+
| --------------------------- | ------------------------------------------------------------------------- |
|
|
84
|
+
| `tool.enabled` | 注册模型可调用的 `dcp_prune` 工具(描述含"话题变更立即使用"的启发式指令) |
|
|
85
|
+
| `autoPrune.enabled` | 启用插件侧启发式自动压缩 |
|
|
86
|
+
| `autoPrune.minMessages` | 会话用户消息数达到该值前不做任何自动判定 |
|
|
87
|
+
| `autoPrune.volumeThreshold` | 距上次压缩的用户消息量阈值 |
|
|
88
|
+
| `autoPrune.driftThreshold` | Jaccard 相似度低于该值视为话题变更(0–1) |
|
|
89
|
+
| `autoPrune.idleGapMs` | 用户消息间隔超过该值视为长时间中断后恢复 |
|
|
90
|
+
| `autoPrune.cooldownMs` | 同一会话两次自动压缩的最小间隔 |
|
|
199
91
|
|
|
200
|
-
|
|
92
|
+
启用 `experimental.customPrompts` 后,可将生成的
|
|
93
|
+
`~/.config/opencode/dcp-prompts/defaults/compaction.md` 复制到以下任一覆盖位置:
|
|
201
94
|
|
|
202
|
-
- `
|
|
203
|
-
-
|
|
204
|
-
-
|
|
205
|
-
- `context-limit-nudge`
|
|
206
|
-
- `turn-nudge`
|
|
207
|
-
- `iteration-nudge`
|
|
95
|
+
- 项目:`.opencode/dcp-prompts/overrides/compaction.md`
|
|
96
|
+
- 自定义配置目录:`$OPENCODE_CONFIG_DIR/dcp-prompts/overrides/compaction.md`
|
|
97
|
+
- 全局:`~/.config/opencode/dcp-prompts/overrides/compaction.md`
|
|
208
98
|
|
|
209
|
-
|
|
99
|
+
## 从 3.x 旧压缩管线迁移
|
|
210
100
|
|
|
211
|
-
|
|
101
|
+
旧配置 `compress`、`manualMode`、`strategies`、`turnProtection`、
|
|
102
|
+
`pruneNotification`、`protectedFilePatterns` 及旧命令保护字段均已删除。DCP 会显示迁移警告并忽略这些字段,不会静默继续旧行为。
|
|
212
103
|
|
|
213
|
-
|
|
104
|
+
以下功能已删除:`compress` / `compress_range` 模型工具、`/dcp compress`、
|
|
105
|
+
`/dcp decompress`、`/dcp recompress`、`/dcp sweep`、消息标记和插件压缩状态持久化。磁盘上已有的旧 DCP 会话状态文件不会被读取、改写或删除,可在确认不再回退旧版本后自行清理。
|
|
214
106
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
### 受保护工具
|
|
218
|
-
|
|
219
|
-
默认情况下,以下工具始终受保护不被修剪:
|
|
220
|
-
`task`、`skill`、`todowrite`、`todoread`、`compress`、`batch`、`plan_enter`、`plan_exit`、`write`、`edit`
|
|
221
|
-
|
|
222
|
-
`commands` 和 `strategies` 中的 `protectedTools` 数组会追加到这个默认列表。
|
|
223
|
-
|
|
224
|
-
对于 `compress` 工具,`compress.protectedTools` 确保特定工具的输出会被附加到压缩摘要中。默认包含 `task`、`skill`、`todowrite` 和 `todoread`。
|
|
225
|
-
|
|
226
|
-
### 外部模型压缩
|
|
227
|
-
|
|
228
|
-
将压缩摘要的生成工作卸载到更便宜的模型,而不是使用昂贵的主模型。
|
|
229
|
-
|
|
230
|
-
#### 优先级链
|
|
231
|
-
|
|
232
|
-
| 优先级 | 来源 | 说明 |
|
|
233
|
-
| --------- | -------- | ------------------------------------------------------ |
|
|
234
|
-
| 1(最高) | 环境变量 | `OPENCODE_DCP_EXTERNAL_COMPRESS_*` |
|
|
235
|
-
| 2 | 项目配置 | `<project>/.opencode/dcp.jsonc:compress.externalModel` |
|
|
236
|
-
| 3 | 全局配置 | `~/.config/opencode/dcp.jsonc:compress.externalModel` |
|
|
237
|
-
| 4(兜底) | 主模型 | 原始行为不变 |
|
|
238
|
-
|
|
239
|
-
#### 使用方法
|
|
240
|
-
|
|
241
|
-
**方法 1 — 环境变量(推荐用于快速设置):**
|
|
107
|
+
## 开发验证
|
|
242
108
|
|
|
243
109
|
```bash
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
export OPENCODE_DCP_EXTERNAL_COMPRESS_RETRIES="1"
|
|
110
|
+
npm test
|
|
111
|
+
npm run typecheck
|
|
112
|
+
npm run build
|
|
113
|
+
npm run format:check
|
|
114
|
+
npm run check:package
|
|
250
115
|
```
|
|
251
116
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
**方法 2 — 配置文件(`dcp.jsonc`):**
|
|
255
|
-
|
|
256
|
-
```jsonc
|
|
257
|
-
{
|
|
258
|
-
"compress": {
|
|
259
|
-
"externalModel": {
|
|
260
|
-
"url": "http://your-proxy-url/v1",
|
|
261
|
-
"model": "your-model-name",
|
|
262
|
-
"apiKey": "your-api-key",
|
|
263
|
-
"timeout": 120000,
|
|
264
|
-
"retries": 1,
|
|
265
|
-
},
|
|
266
|
-
},
|
|
267
|
-
}
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
#### 行为说明
|
|
271
|
-
|
|
272
|
-
| 场景 | 行为 |
|
|
273
|
-
| --------------------------------- | ------------------------------------------------ |
|
|
274
|
-
| 配置了外部模型 + 未提供 `summary` | 插件获取范围内容 → 调用外部模型 → 存储生成的摘要 |
|
|
275
|
-
| 配置了外部模型 + 提供了 `summary` | 插件直接使用提供的 `summary`(向后兼容) |
|
|
276
|
-
| 外部模型调用失败 | 工具抛出错误;主模型使用回退摘要重试 |
|
|
277
|
-
| 未配置 | 一切不变——主模型像以前一样编写摘要 |
|
|
278
|
-
| `url` 不兼容 OpenAI | 外部模型调用失败 → 进入上述错误路径 |
|
|
279
|
-
|
|
280
|
-
**兼容性:** 仅支持兼容 OpenAI 的 `/chat/completions` 端点(本地代理、OpenAI、DeepSeek 等)。
|
|
281
|
-
|
|
282
|
-
## 对提示词缓存的影响
|
|
283
|
-
|
|
284
|
-
LLM 提供商基于精确前缀匹配来缓存提示词。当 DCP 剪枝内容时,它会修改消息,从而从该位置开始使缓存的提示词前缀失效。
|
|
285
|
-
|
|
286
|
-
**权衡:** 你会损失一些缓存命中,但通过减小上下文尺寸和减少因过时上下文导致的幻觉来获得 token 节省。在大多数情况下,尤其是在长会话中,节省量超过了缓存未命中的成本。
|
|
287
|
-
|
|
288
|
-
> [!NOTE]
|
|
289
|
-
> 测试中,使用 DCP 的缓存命中率约为 85%,而未使用时约为 90%。
|
|
290
|
-
|
|
291
|
-
**无影响的情况:**
|
|
292
|
-
|
|
293
|
-
- **按请求计费** — 按请求收费而非按 token 收费的提供商,如 GitHub Copilot。
|
|
294
|
-
- **统一 token 定价** — 对缓存和未缓存 token 按相同费率计费的提供商,如 Cerebras。
|
|
295
|
-
|
|
296
|
-
## License
|
|
117
|
+
许可:AGPL-3.0-or-later。
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAejD,QAAA,MAAM,MAAM,EAAE,MA6CK,CAAA;AAEnB,eAAe,MAAM,CAAA"}
|