@lexwdex-org/opencode-dcp 3.4.11 → 3.4.13

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 CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  **English** | [中文](./README.md)
6
6
 
7
- DCP supplies a semantic-pruning policy to OpenCode's native compaction lifecycle. It no longer owns message markers, message IDs, compression blocks, anchors, placeholders, or a second summary state machine.
7
+ DCP supplies a semantic-pruning policy and proactive triggers to OpenCode's native compaction lifecycle. It does not own message markers, message IDs, compression blocks, anchors, or placeholders.
8
8
 
9
9
  ## How it works
10
10
 
@@ -14,7 +14,27 @@ OpenCode owns one rolling checkpoint. After compaction, the model sees only:
14
14
  latest pruned checkpoint + uncompacted recent tail
15
15
  ```
16
16
 
17
- During `experimental.session.compacting`, DCP asks the summarizer to remove unrelated chat and other-project context, fold tool retries into the final successful result, fold repeated edits into the final state and valid decisions, and reduce small completed topics to short outcomes. Continuation-critical goals, constraints, decisions, implementation state, risks, and next steps remain.
17
+ During `experimental.session.compacting`, DCP asks the summarizer to organize the checkpoint into a fixed three-tier structure:
18
+
19
+ - `## 系统上下文` (System context) — system-level rules such as AGENTS.md, carried forward verbatim from the previous checkpoint;
20
+ - `## 历史概要` (History digest) — early and middle history heavily compressed: one-line outcomes only, no process;
21
+ - Recent tasks — lightly compressed: completed tasks summarized in one line each; in-progress tasks keep full detail (goal, finished steps, file paths, key decisions, blockers, next actions). Details related to the current task are preserved first so work can continue from the checkpoint alone.
22
+
23
+ Unrelated chat, other-project context, tool retries, and repeated edits are folded away as before.
24
+
25
+ ## Trigger compaction
26
+
27
+ - **OpenCode automatic compaction** uses the policy automatically.
28
+ - **The `dcp_prune` model tool** — DCP registers an LLM-invokable tool whose description carries heuristic guidance: call it immediately when the topic clearly changes, when a task wraps up, or when the context has grown noticeably.
29
+ - **Heuristic auto-prune** (`autoPrune`) — observes incoming user messages and triggers native compaction at turn boundaries (`session.idle`) on:
30
+ - topic drift: lexical similarity between the newest message and recent history drops sharply (CJK bigrams + Jaccard);
31
+ - message volume since the last prune crossing a threshold;
32
+ - resuming after a long idle gap.
33
+ Auto-triggers respect a cooldown; native `/compact` or host compaction also resets the counters.
34
+ - OpenCode's native `/compact` command uses the same path.
35
+ - `/dcp summarize` calls native `session.summarize()` manually.
36
+
37
+ All entries share one coordinator: concurrent requests for the same session share a single native call. A failed call is fail-open and keeps the original context; retries are cooled down for 30 seconds by default.
18
38
 
19
39
  Pruned prefixes stop being sent to the model, but the original session history is not physically deleted from OpenCode's database. A later compaction replaces the previous checkpoint with one merged checkpoint instead of nesting summaries or building a compression-block graph.
20
40
 
@@ -24,14 +44,6 @@ Pruned prefixes stop being sent to the model, but the original session history i
24
44
  opencode plugin @lexwdex-org/opencode-dcp@latest --global
25
45
  ```
26
46
 
27
- ## Trigger compaction
28
-
29
- - OpenCode automatic compaction uses the policy automatically.
30
- - OpenCode's native `/compact` command uses the same path.
31
- - `/dcp summarize` calls native `session.summarize()` for one-step semantic pruning.
32
-
33
- Concurrent requests for the same session share one native call. A failed call is fail-open and keeps the original context; retries are cooled down for 30 seconds by default.
34
-
35
47
  ## Configuration
36
48
 
37
49
  DCP loads global, custom-config-directory, then project configuration:
@@ -42,12 +54,33 @@ DCP loads global, custom-config-directory, then project configuration:
42
54
  "enabled": true,
43
55
  "autoUpdate": true,
44
56
  "debug": false,
57
+ "language": "zh",
45
58
  "commands": { "enabled": true },
46
59
  "experimental": { "customPrompts": false },
47
60
  "summarize": { "failureCooldownMs": 30000 },
61
+ "tool": { "enabled": true },
62
+ "autoPrune": {
63
+ "enabled": true,
64
+ "minMessages": 8,
65
+ "volumeThreshold": 30,
66
+ "driftThreshold": 0.18,
67
+ "idleGapMs": 1800000,
68
+ "cooldownMs": 300000,
69
+ },
48
70
  }
49
71
  ```
50
72
 
73
+ | Key | Meaning |
74
+ | --------------------------- | --------------------------------------------------------------------------------------------- |
75
+ | `language` | Language of the bundled compaction prompt: `zh` (default) / `en`; custom overrides always win |
76
+ | `tool.enabled` | Register the model-invokable `dcp_prune` tool with heuristic usage guidance |
77
+ | `autoPrune.enabled` | Enable plugin-side heuristic auto-compaction |
78
+ | `autoPrune.minMessages` | Minimum user messages before any auto-prune signal is considered |
79
+ | `autoPrune.volumeThreshold` | User messages since the last prune that trigger compaction by volume |
80
+ | `autoPrune.driftThreshold` | Jaccard similarity below which consecutive messages count as a topic change (0–1) |
81
+ | `autoPrune.idleGapMs` | Gap between user messages that counts as resuming after a long break |
82
+ | `autoPrune.cooldownMs` | Minimum interval between two automatic prunes of the same session |
83
+
51
84
  When `experimental.customPrompts` is enabled, copy the generated
52
85
  `~/.config/opencode/dcp-prompts/defaults/compaction.md` to a project, custom-config, or global `dcp-prompts/overrides/compaction.md` path.
53
86
 
@@ -55,6 +88,6 @@ When `experimental.customPrompts` is enabled, copy the generated
55
88
 
56
89
  Legacy `compress`, `manualMode`, `strategies`, `turnProtection`, notification, protected-file, and command-protection settings are removed. DCP reports them as deprecated and ignores them.
57
90
 
58
- The old model tools, range/message compression, `/dcp compress`, decompression/recompression/sweep commands, message markers, nudges, and plugin compression persistence are gone. Existing legacy DCP state files are neither read nor modified; remove them manually only after deciding that you will not roll back.
91
+ The old model tools, range/message compression, `/dcp compress`, decompression/recompression/sweep commands, message markers, and plugin compression persistence are gone. Existing legacy DCP state files are neither read nor modified; remove them manually only after deciding that you will not roll back.
59
92
 
60
93
  License: AGPL-3.0-or-later.
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  [**English**](./README.en.md) | **中文**
6
6
 
7
- DCP 为 OpenCode 原生 compaction 提供语义剪枝策略。它不再维护消息标记、消息 ID、压缩块、锚点、占位符或第二套摘要状态机。
7
+ DCP 为 OpenCode 原生 compaction 提供语义剪枝策略与主动触发机制。它不维护消息标记、消息 ID、压缩块、锚点或占位符。
8
8
 
9
9
  ## 工作原理
10
10
 
@@ -14,15 +14,27 @@ OpenCode 原生 compaction 负责生成和保存一个滚动检查点,并在
14
14
  最新剪枝检查点 + 尚未压缩的近期尾部
15
15
  ```
16
16
 
17
- DCP 只在 `experimental.session.compacting` 阶段提供专用提示词。提示词会:
17
+ DCP `experimental.session.compacting` 阶段提供专用提示词,把检查点组织为固定三段结构:
18
18
 
19
- - 删除无关闲聊、其他项目内容、重复解释和已推翻方案;
20
- - 把多次工具试错折叠为最终成功结果,必要时保留一次根因;
21
- - 把同一内容的重复修改折叠为最终状态和仍有效的决策;
22
- - 把小型已完成主题压缩为一句结果;
23
- - 保留继续工作需要的目标、约束、决策、实现状态、风险和下一步。
19
+ - `## 系统上下文` — AGENTS.md、项目规则等系统级内容,从上一份检查点原样保留合并;
20
+ - `## 历史概要` — 早期历史和中部历史高度压缩:每项主题只留一句结论,不含过程;
21
+ - 最近任务 — 轻度压缩:已完成任务一句话概括;进行中任务保留完整详情(目标、已完成步骤、文件路径、关键决策、阻塞、下一步)。与当前任务相关的近期细节优先保留,保证凭检查点即可直接继续工作。
24
22
 
25
- 压缩后的旧前缀不会再发送给模型,但 OpenCode 数据库中的原始会话历史不会被物理删除。下一次压缩会把旧检查点和新增尾部合并为一个新检查点,不会形成嵌套摘要或压缩块 DAG。
23
+ ## 触发压缩
24
+
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()`。
34
+
35
+ 所有入口都经过同一协调器:同一会话的并发请求合并为一次原生调用;失败不会提交半成品检查点,原始上下文保持可用,默认 30 秒内不重试失败的请求。
36
+
37
+ 压缩后的旧前缀不会再发送给模型,但 OpenCode 数据库中的原始会话历史不会被物理删除。下一次压缩会把旧检查点和新增尾部合并为一个新检查点,不会形成嵌套摘要。
26
38
 
27
39
  ## 安装
28
40
 
@@ -30,14 +42,6 @@ DCP 只在 `experimental.session.compacting` 阶段提供专用提示词。提
30
42
  opencode plugin @lexwdex-org/opencode-dcp@latest --global
31
43
  ```
32
44
 
33
- ## 触发压缩
34
-
35
- - OpenCode 自动 compaction:达到宿主阈值时自动运行。
36
- - OpenCode 原生 `/compact`:手动触发同一条 compaction 路径。
37
- - `/dcp summarize`:调用原生 `session.summarize()`,一次完成语义摘要和真实上下文剪枝。
38
-
39
- 同一会话的并发 `/dcp summarize` 会合并为一次原生调用。失败不会提交半成品检查点,原始上下文保持可用;默认 30 秒内不会重复调用失败的请求。
40
-
41
45
  ## 配置
42
46
 
43
47
  DCP 依次读取以下配置,后面的层覆盖前面的层:
@@ -52,6 +56,7 @@ DCP 依次读取以下配置,后面的层覆盖前面的层:
52
56
  "enabled": true,
53
57
  "autoUpdate": true,
54
58
  "debug": false,
59
+ "language": "zh",
55
60
  "commands": {
56
61
  "enabled": true,
57
62
  },
@@ -61,9 +66,31 @@ DCP 依次读取以下配置,后面的层覆盖前面的层:
61
66
  "summarize": {
62
67
  "failureCooldownMs": 30000,
63
68
  },
69
+ "tool": {
70
+ "enabled": true,
71
+ },
72
+ "autoPrune": {
73
+ "enabled": true,
74
+ "minMessages": 8,
75
+ "volumeThreshold": 30,
76
+ "driftThreshold": 0.18,
77
+ "idleGapMs": 1800000,
78
+ "cooldownMs": 300000,
79
+ },
64
80
  }
65
81
  ```
66
82
 
83
+ | 键 | 说明 |
84
+ | --------------------------- | ------------------------------------------------------------------------- |
85
+ | `language` | 内置压缩提示词语言:`zh`(默认)/ `en`;自定义覆盖文件优先于该配置 |
86
+ | `tool.enabled` | 注册模型可调用的 `dcp_prune` 工具(描述含"话题变更立即使用"的启发式指令) |
87
+ | `autoPrune.enabled` | 启用插件侧启发式自动压缩 |
88
+ | `autoPrune.minMessages` | 会话用户消息数达到该值前不做任何自动判定 |
89
+ | `autoPrune.volumeThreshold` | 距上次压缩的用户消息量阈值 |
90
+ | `autoPrune.driftThreshold` | Jaccard 相似度低于该值视为话题变更(0–1) |
91
+ | `autoPrune.idleGapMs` | 用户消息间隔超过该值视为长时间中断后恢复 |
92
+ | `autoPrune.cooldownMs` | 同一会话两次自动压缩的最小间隔 |
93
+
67
94
  启用 `experimental.customPrompts` 后,可将生成的
68
95
  `~/.config/opencode/dcp-prompts/defaults/compaction.md` 复制到以下任一覆盖位置:
69
96
 
@@ -77,7 +104,7 @@ DCP 依次读取以下配置,后面的层覆盖前面的层:
77
104
  `pruneNotification`、`protectedFilePatterns` 及旧命令保护字段均已删除。DCP 会显示迁移警告并忽略这些字段,不会静默继续旧行为。
78
105
 
79
106
  以下功能已删除:`compress` / `compress_range` 模型工具、`/dcp compress`、
80
- `/dcp decompress`、`/dcp recompress`、`/dcp sweep`、消息标记、nudge 和插件压缩状态持久化。磁盘上已有的旧 DCP 会话状态文件不会被读取、改写或删除,可在确认不再回退旧版本后自行清理。
107
+ `/dcp decompress`、`/dcp recompress`、`/dcp sweep`、消息标记和插件压缩状态持久化。磁盘上已有的旧 DCP 会话状态文件不会被读取、改写或删除,可在确认不再回退旧版本后自行清理。
81
108
 
82
109
  ## 开发验证
83
110
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAQjD,QAAA,MAAM,MAAM,EAAE,MA8BK,CAAA;AAEnB,eAAe,MAAM,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,MAkDK,CAAA;AAEnB,eAAe,MAAM,CAAA"}