dsh-compact-arsenal 0.0.0-stage → 0.2.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,45 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project uses
5
+ [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [0.2.0] — 2026-11-03
8
+
9
+ ### Added
10
+
11
+ - **Left-sidebar panel** (`上下文压缩`): per-section switches, method cards with
12
+ check marks, editable parameters, debounced auto-save, live rewrite counters.
13
+ - **Total compression** that runs on its own: replaces the oldest closed turns
14
+ with a model-written checkpoint, keeping tool calls and results paired.
15
+ - **Model-backed modes** for reasoning and tool-output sections, with
16
+ configurable provider, model, output budget and prompt; empty values follow
17
+ the current session route.
18
+ - **Batch summarization**: up to eight fragments per model call, answered as JSON
19
+ and applied item by item.
20
+ - Panel HTTP routes `/compact-arsenal/api/state` and `/compact-arsenal/api/config`,
21
+ backing the panel with `ctx.configEditor` so edits land in the profile patch.
22
+
23
+ ### Changed
24
+
25
+ - Reasoning and tool sections now gate on **section-wide size** (`minTotalChars`)
26
+ instead of a per-fragment threshold, because reasoning arrives as many small
27
+ fragments that a per-fragment threshold would never reach.
28
+ - Each section carries its own **pressure threshold**; the former single global
29
+ threshold was removed.
30
+ - Default prompts ship with the plugin and are used whenever a prompt is empty.
31
+
32
+ ### Fixed
33
+
34
+ - Panel render crash when the served config lacked the `total` section.
35
+ - Model fields overlapping in the panel; they now use a grid layout.
36
+ - Legacy `minChars: 2000` configs are migrated to the new per-fragment floor.
37
+
38
+ ## [0.1.0] — 2026-11-02
39
+
40
+ ### Added
41
+
42
+ - Bundle plugin skeleton: Cordis patch, locale resources, icon, MIT license.
43
+ - Pure, dependency-free rewrite policy with unit tests.
44
+ - Mechanical reasoning trimming (`truncate` / `clear`) and tool-output pruning,
45
+ applied through surface replacement at a pressure threshold.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dsh-compact-arsenal contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,165 @@
1
- # Temporary Holding Version
1
+ # dsh-compact-arsenal · 压缩工坊
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 给 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)(`dsh`)用的**可配置上下文压缩**插件。
4
+
5
+ 三个板块各自独立开关、各自阈值、各自方法,并在左栏提供「上下文压缩」面板:开关、方式卡片、参数都能直接点,改完自动保存,不需要命令行。
6
+
7
+ > 设计原则:**能机械解决的先机械解决;要花模型钱的部分由你显式打开。**
8
+
9
+ ---
10
+
11
+ ## 三个板块
12
+
13
+ | 板块 | 对象 | 方式 | 是否调用模型 |
14
+ |---|---|---|---|
15
+ | **总压缩** | 最旧的若干**整轮**对话 | 模型写检查点 → 整段替换 | 是 |
16
+ | **思考压缩** | 旧轮次助手消息里的 `reasoning` 块 | 机械截断 / 整块清除 / 模型要点 | 机械模式否 |
17
+ | **工具输出压缩** | 旧轮次里超长的 `tool/result` 正文 | 按字符预算 / 模型要点 | 机械模式否 |
18
+
19
+ ### 为什么思考要按「总量」判定
20
+
21
+ 模型的思考是**碎片化**的:一条 8,000 字的思考很少见,更多是几百到一两千字的短片段,散落在几百条消息里。因此按「单条超过 N 字」判定几乎永不触发。
22
+
23
+ 本插件改为:
24
+
25
+ 1. 汇总所有「旧轮次、未压过」的碎片字数,达到 **总量下限**(默认 15,000 字)才动手;
26
+ 2. 把最多 8 条、合计不超过 12,000 字的碎片**打包成一次模型调用**,模型返回逐条要点(JSON);
27
+ 3. 每条碎片原位替换为「头 + 要点 + 尾」(短碎片直接省略);
28
+ 4. 一次触发最多处理 12 条 / 省下 40,000 字,避免失控花销。
29
+
30
+ ---
31
+
32
+ ## 安装
33
+
34
+ ```sh
35
+ # npm 包(推荐,DSH 内置 Plugin Hub 可见)
36
+ dsh plugin --profile web add dsh-compact-arsenal
37
+
38
+ # GitHub 源(把 web 换成你的 profile 名)
39
+ dsh plugin --profile web add "github:TacitSay/dsh-compact-arsenal#main"
40
+
41
+ # 或本地目录(开发)
42
+ dsh plugin --profile web add E:\path\to\dsh-compact-arsenal
43
+ ```
44
+
45
+ 重启 DSH 后,左栏出现「上下文压缩」图标。**所有板块默认关闭**,装上不改变任何行为。
46
+
47
+ ---
48
+
49
+ ## 面板
50
+
51
+ - 总开关;每个板块一个开关;
52
+ - 方式以**卡片**呈现,选中的有勾选标记;未实现的方式显示为灰色;
53
+ - 参数是数字输入框,改完 500 ms 自动保存并热重载;
54
+ - 模型方式下,提供方/模型留空即**跟随当前会话的模型**;
55
+ - 底部显示本次进程已执行的次数与省下的字符数。
56
+
57
+ 面板通过两条本机路由工作,写入走官方 `ctx.configEditor`,与手动改配置等价:
58
+
59
+ | 路由 | 方法 | 作用 |
60
+ |---|---|---|
61
+ | `/compact-arsenal/api/state` | GET | 当前生效配置与运行统计 |
62
+ | `/compact-arsenal/api/config` | POST | 保存配置(落到 profile 的 `cordis.patch.yml`) |
63
+
64
+ ---
65
+
66
+ ## 配置
67
+
68
+ 也可以直接写 profile 的 `cordis.patch.yml`:
69
+
70
+ ```yaml
71
+ - id: compact-arsenal
72
+ name: dsh-compact-arsenal
73
+ config:
74
+ enabled: true
75
+ total:
76
+ enabled: true
77
+ pressureRatio: 0.8 # 本板块的触发阈值
78
+ retainTurns: 2 # 最近的整轮不动
79
+ maxInputChars: 60000 # 一次摘要读入的上限
80
+ provider: '' # 留空 = 当前会话模型
81
+ model: ''
82
+ reasoning:
83
+ enabled: true
84
+ pressureRatio: 0.75
85
+ mode: truncate # truncate | clear | model
86
+ keepLast: 3 # 最近 3 条助手消息不动
87
+ minTotalChars: 15000 # 总量门槛
88
+ minChars: 200 # 单项下限
89
+ headChars: 600
90
+ tailChars: 300
91
+ batchChars: 12000
92
+ maxItems: 12
93
+ model:
94
+ provider: ''
95
+ model: ''
96
+ prompt: '' # 留空 = 内置默认提示词
97
+ tools:
98
+ enabled: true
99
+ mode: truncate
100
+ thresholdChars: 8192
101
+ keepLast: 2
102
+ ```
103
+
104
+ ### 触发顺序
105
+
106
+ 1. 本板块开关打开;
107
+ 2. 上下文压力 ≥ 本板块的 `pressureRatio`;
108
+ 3. 目标内容总量 ≥ 本板块的 `minTotalChars`(工具板块用 `thresholdChars` 作单项预算)。
109
+
110
+ 三者都满足才会改写。
111
+
112
+ ---
113
+
114
+ ## 模型压缩到底做了什么
115
+
116
+ 以思考为例,一条碎片会被改写为:
117
+
118
+ ```
119
+ [原开头 600 字]
120
+
121
+ [... reasoning middle trimmed ...]
122
+ <该条的要点>
123
+ [... reasoning middle trimmed ...]
124
+
125
+ [原结尾 300 字]
126
+ ```
127
+
128
+ - **打包**:同一批最多 8 条碎片共用一次模型调用;
129
+ - **回填**:写回**原来那条消息**(表层替换),不新增消息、不打乱顺序;
130
+ - **可回查**:原始内容完整保留在会话日志中;
131
+ - **幂等**:已带压缩标记的内容不会再被压缩,避免摘要衰减;
132
+ - **降级**:模型不可用时自动退回机械头尾截断,不会让这一步失败。
133
+
134
+ ---
135
+
136
+ ## 安全边界
137
+
138
+ - 不动系统提示词、工具 schema、你的消息、`tool-call` 参数;
139
+ - 总压缩按**整轮**替换,工具调用与结果始终成对进出;
140
+ - 任何改写失败只记日志,不会中断当前步骤;
141
+ - 文本按 Unicode 码点切片,不会切断 emoji 或代理对。
142
+
143
+ ---
144
+
145
+ ## 开发
146
+
147
+ ```sh
148
+ node --test test/*.test.mjs
149
+ ```
150
+
151
+ - `lib/policy.js`:纯函数(测量、截断、剪枝);
152
+ - `lib/summarize.js`:模型调用与批量 JSON 解析;
153
+ - `index.js`:Host 半边(触发、改写、面板路由);
154
+ - `client.js`:面板(React,无构建步骤)。
155
+
156
+ ## 路线图
157
+
158
+ - [ ] 面板内直接编辑提示词模板并预览效果;
159
+ - [ ] 工具白名单的图形化选择;
160
+ - [ ] 压缩前后的 token 差值图表;
161
+ - [ ] 英文界面(当前面板文案为中文)。
162
+
163
+ ## License
164
+
165
+ MIT