dsh-oh-my-token 0.0.0-stage → 0.0.2

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/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dsh-lean 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.
22
+
23
+ ---
24
+
25
+ Third-party notices, including the Apache-2.0 text for the RTK-style structural
26
+ filters, are in THIRD_PARTY_NOTICES.md and LICENSES/Apache-2.0.txt. They apply to
27
+ those portions only and do not change the MIT license of the rest of this
28
+ package.
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 RTK AI Labs
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,186 @@
1
- # Temporary Holding Version
1
+ # dsh-oh-my-token
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
+ [English](README_EN.md) | 中文
4
+
5
+ > 让工具输出在 agent 真正需要之前,不进入提示词。
6
+
7
+ `dsh-oh-my-token` 是 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 插件。它在工具结果**写入日志之前**完成改写,因此模型看到的字节与持久化记录完全一致;它从不改写工具参数、从不触碰磁盘上的会话文件、也不启动任何外部进程。
8
+
9
+ 它把两个工具的理念内建到进程里,而不是捆绑两个二进制:
10
+
11
+ | 理念 | 来源 | 本插件的做法 |
12
+ | --- | --- | --- |
13
+ | 按命令与输出形状压缩 | [RTK](https://github.com/rtk-ai/rtk)(Apache-2.0) | 先解析模型已运行的命令,只保留结论和失败细节;命令过滤器没命中时,再按内容形状压缩:git diff/status/log、构建日志、grep/find/ls/tree、重复日志、编号文件与搜索结果。纯 JS,无二进制。 |
14
+ | 检索符号而非整文件 | [codegraph](https://github.com/isink17/codegraph) | 把超大且未指定范围的 `read` 变成符号大纲,并限制过大的 `grep` 结果。无 SQLite 图库、无 MCP 服务。 |
15
+
16
+ 外加两项模型根本不需要读取的变换(可分别开关):对可判定为散文的行,按一张**可自定义的词表**删去或替换「谢谢」「请」「please」「thanks」等词(默认删,也可配成替换成别的词);以及整理标点——段首的标点删去、挨在一起的两个标点只保留一个(逗号+句号留句号,其余强弱类推)、再删去句末**连续的** `.`、`。`、`,`、`,`(ASCII 省略号 `...` / `…` 除外)。它们作用于工具输出、你亲手输入的消息、助手的回复,以及历史对话——历史部分在组装请求时剥离,因此模型永远不会看到这些内容,而磁盘上的会话文件保持逐字节不变。
17
+
18
+ 还能顺手做的两件事:
19
+
20
+ - **对话内容编辑**:在设置页直接改写最近的消息(你自己发的或模型回的)。改写只写进下一次请求,不落盘、不改历史日志;点「恢复原内容」即撤销。
21
+ - **聊天里的红线**:你自己发的消息和模型回复的**正文**里,被自动删掉的词都在原位置画红线,替换成新词的部分是绿色。消息走宿主的文本规则接口,回复正文由宿主渲染 Markdown、没有文本钩子,所以插件在渲染完成后把被删的字插回原位做标记(重渲染会自动补回)。
22
+ - **自动变换记录**:设置页把最近每次散文步骤的改动按 diff 展开——被删掉的词用红色划线,替换或新出现的字用绿色,像看 GitHub 的改动文件一样一眼看到程序动了哪里。记录会写进配置目录,重启 DSH 后仍然在。
23
+
24
+ ## 它保留了什么
25
+
26
+ 过滤只允许丢弃不承载决策的文本。具体来说:
27
+
28
+ - `pytest` → `✓ 42 passed in 1.23s`;失败时保留每一条 `FAILED`、`E `、回溯与摘要行。
29
+ - `git status` → `clean`,或前 40 行。
30
+ - `git diff` → 文件头加变更行;纯空白 diff 折叠为一行。
31
+ - `tsc` → 每条 `error TSxxxx` 加总数;告警丢弃。
32
+ - `npm/pnpm/yarn/bun/pip/uv/poetry` 安装 → 成功留摘要行,失败留错误行。
33
+ - 其他命令 → 只做 ANSI、回车重绘、重复行与进度条清理。命令字符串永不改写。
34
+ - 命令过滤器没命中时(或对历史中的旧工具结果),RTK 结构压缩按形状接管:`git diff/status/log` 保留文件名、计数与 hunk 头;构建日志保留错误、告警与摘要;`cargo build/test` 折叠 Compiling/Checking 进度、保留 `error[E…]`、`test result:` 与 Finished;`go test` 把所有 `ok`/`?` 包折叠成一行结论、失败时保留首个 FAIL 起的细节;`eslint` 紧凑格式按文件分组计数;`grep/find/ls/tree/search-list` 按文件/目录分组并给出计数;重复日志折叠;超长无结构内容保留头尾。它只收缩,不放大。
35
+
36
+ 结果仍超预算时,全文通过 `ctx.spillStore` 保存,标记会告诉模型去哪里取。如果没挂载 spill store,标记会说明如何重跑或重新读取——插件绝不丢弃无法恢复的文本。
37
+
38
+ ## 安装
39
+
40
+ ```sh
41
+ dsh plugin --profile web add dsh-oh-my-token
42
+ ```
43
+
44
+ 本地检出:
45
+
46
+ ```sh
47
+ dsh plugin --profile web add file:/path/to/dsh-oh-my-token
48
+ ```
49
+
50
+ 该命令把包加入配置目录的 `dsh.profile.bundles`,包自带的 `cordis.patch.yml` 负责挂载这一行。可用 `dsh --profile web --dump-config` 查看合成后的配置。
51
+
52
+ 要改预算,在配置目录的 `cordis.patch.yml` 对应行下添加字段;省略的字段沿用 bundle patch 的默认值。开关和散文范围无需改 patch——由设置页面管理。
53
+
54
+ ## 设置页面
55
+
56
+ **设置 → 省 Token** 是管理面板,顶部按 **概览 / 压缩 / 散文 / 对话 / 提示词 / 关于** 分栏,不再是一整页长表单(「关于」页显示插件名、从 `package.json` 读出的版本号,以及一个打开 GitHub 仓库的按钮):
57
+
58
+ - 每个变换一个开关(5 个命令过滤器、RTK 结构压缩、2 个检索变换、标点整理);
59
+ - 压缩力度:省着压 / 默认 / 狠压三档一键设置字符上限与最小改写阈值,展开「高级数字」仍可逐项精调;
60
+ - 高级配置:预算、`minChars`/`minGain`、检索阈值、超预算处理(`spill`/`rerun`/`none`)与 `logEvery`,以及插件总开关;
61
+ - 散文变换(标点 / 词语)共用的三档范围(`off` / 仅散文输出 / 所有散文);
62
+ - 词语表(规则)编辑:每行「词 + 替换」(替换留空即删除);内置规则含「谢谢 / 请 / please / thanks」以及「啊 / 呀 / 吧 / 呢 / 嘛 / 哦」等语气词,语气词只在句尾或标点前删,「酒吧」「网吧」「毛呢」「哗啦」不会被拆;
63
+ - 对话内容编辑:改写最近消息,只在下次请求发给模型,历史不动,可恢复原内容;聊天里每条消息(当前这一轮)还有「改写」按钮,按原文匹配,**不需要宿主先认识这个会话**,重启后立刻可用;
64
+ - 自动变换记录:最近每次散文步骤的改动按 diff 展开,删掉的词红色划线、替换或新增的字绿色(同一行只显示变动附近的内容);
65
+ - 节省记录:本次进程与历史累计、移除的 token 与字符、节省比例、按工具明细表,以及消息/回复剥离计数;
66
+ - 选择被写入的配置目录,方便确认开关是否真的落盘。
67
+
68
+ 改动在下一次工具调用即生效,无需重启。选择写入配置目录的 `dsh-oh-my-token.state.json`(优先取 `DSH_PROFILE_DIR`,否则从携带本包的配置目录推断),下次启动时覆盖 bundle 配置。统计在同目录的 `dsh-oh-my-token.stats.json`,可在页面清除。
69
+
70
+ 页面由三条精确路由支撑:`/dsh-oh-my-token/state`、`/dsh-oh-my-token/stats` 与 `/dsh-oh-my-token/prompt`(读取当前生效的系统提示词)。
71
+
72
+ ## 完整提示词
73
+
74
+ 「设置 → 省 Token」里的「完整提示词」卡片不是编辑器,是**只读查看**:点「获取提示词」,插件会在宿主真正组装系统提示词的那一刻抓一份当前结果返回,所以看到的就是下一次请求实际会发的内容——核心提示词、宿主上下文,以及**其他插件注入的段落**都在里面,顺序也一致。变量(如 `{{provider}}`、`{{model}}`)已替换成当前值;当前没有值的变量保持字面量,不会因此报错。
75
+
76
+ - 「复制全文」把读到的内容放进剪贴板;
77
+ - 卡片标题右侧显示「N 段 · M 字符」,方便核对拼接结果;
78
+ - 插件不修改系统提示词,只读不写。
79
+
80
+ ## 配置
81
+
82
+ | 字段 | 默认值 | 说明 |
83
+ | --- | --- | --- |
84
+ | `enabled` | `true` | 关闭插件但不移除配置行。 |
85
+ | `budgets.default` | `6000` | 没有单独配置的工具的字符上限。 |
86
+ | `budgets.read` | `12000` | 文件内容是编辑的基础,因此额度更高。 |
87
+ | `budgets.grep` | `6000` | |
88
+ | `budgets.bash` | `4000` | |
89
+ | `budgets.errorFactor` | `2` | 错误结果允许放大到倍数。 |
90
+ | `minChars` | `800` | 小于此值的结果不动(清理不值得冒险)。 |
91
+ | `minGain` | `0.05` | 丢弃节省低于此比例的改写;散文句号改写始终保留。 |
92
+ | `filters.*` | 全部 `true` | 各过滤器开关:`pytest`、`git`、`tsc`、`packageManager`、`generic`。 |
93
+ | `rtk` | `true` | 命令过滤器未命中时,按输出形状再做一层 RTK 结构压缩。也可在设置页面关闭。 |
94
+ | `retrieval.readOutlineOverLines` | `400` | 仅当行数超过此值且调用未带 `offset`/`limit` 时才生成大纲。 |
95
+ | `retrieval.maxOutlineSymbols` | `60` | |
96
+ | `retrieval.maxGrepMatches` | `50` | |
97
+ | `prose.stripTrailingPeriod` | `true` | 标点整理:段首标点删去;相邻两个标点只留一个(逗号+句号留句号,同强保留右边);再删句末**连续的** `.` / `。` / `,` / `,`(省略号除外)。 |
98
+ | `prose.stripPoliteness` | `true` | 按 `politenessWords` 词表删去或替换散文行里的词。 |
99
+ | `prose.politenessWords` | 内置规则 + 语气词 | 每项 `{ word, replace? }`:`replace` 留空或省略 = 删除,填字符串 = 替换。整表未配置时用内置规则:「谢谢 / 请 / please / thanks…」以及「啊 / 呀 / 吧 / 呢 / 嘛 / 哦…」等语气词(语气词只在句尾或标点前删,含护栏防拆词);配置空表 `[]` 则关闭词变换。 |
100
+ | `prose.scope` | `filtered` | `filtered` = 仅命令过滤器标记为散文的输出(如 `git log`);`all`;`off`。 |
101
+ | `recovery` | `spill` | `spill` \| `rerun` \| `none`。 |
102
+ | `logEvery` | `0` | 每 N 次改写打印一条节省日志;`0` 为静默。 |
103
+
104
+ 未知字段会在激活时报错,而不是静默忽略。以上字段都可以在「设置 → 省 Token」的「高级配置」里修改;`enabled` 是总开关,`filters.*` 对应上方的开关行。
105
+
106
+ ### 为什么句号剥离有防护
107
+
108
+ 删掉文件名、URL、版本号或代码行里的句号,为了省一个 token 而损坏数据,代价太大。因此 `isProseLine` 会拒绝:
109
+
110
+ - 围栏代码、diff 行、以 `{ [ <` 开头或以 `;{}=` 结尾的行,以及带 `= ( ) ; { } [ ]` 等代码标点又以逗号结尾的行;
111
+ - 赋值/声明/语句行(含 `= ; { }` 或以 `const`/`function`/`import` 等开头),规则删除不会碰它们;
112
+ - 含 URL、邮箱、带扩展名路径的行;
113
+ - 看起来像版本号(`2.2.0`)或 `host:port` 的内容;
114
+ - 列表项(`- `、`*`)、省略号,以及 `e.g.` / `i.e.`。
115
+
116
+ ## 测量
117
+
118
+ ```sh
119
+ oh-my-token report [profile-dir | session.jsonl]
120
+ ```
121
+
122
+ 按事件类型(`user/message`、`assistant/message`、`tool/call`、`tool/result`)统计会话日志,并列出最昂贵的工具结果。这是「改写前」的数字;设置页面显示「改写后」。
123
+
124
+ ```sh
125
+ oh-my-token map <file|dir> # read 会生成的大纲
126
+ oh-my-token lint [config.json] # 校验行配置,不启动 DSH
127
+ ```
128
+
129
+ ## 还能压什么
130
+
131
+ 把「模型要据此决策的字节」逐个过一遍,结论如下:
132
+
133
+ - **命令输出**(收益最大):已有 5 个命令过滤器 + 17 种 RTK 结构压缩器,覆盖 pytest / git / tsc / 包管理器 / eslint / cargo / go test / grep / find / ls / tree 等。剩下的长尾命令(docker、kubectl、make…)按 RTK 的形状识别走 generic + smart-truncate,不再逐个写解析器——每加一个解析器都是一份要维护的回归测试。
134
+ - **读文件**:大 `read` 出符号大纲、大 `grep` 截断。再往下压(只给 AST、跳过 import 块)会把「模型能直接引用的文本」换成「模型要再问一次才能拿到的摘要」,省得不多还容易漏关键行,不做。
135
+ - **JSON / 图片**:JSON 数组折叠(同结构 N 份只留一份 + 计数)是下一步候选,但 `package-lock` 这类文件删一行就可能让模型拿错版本号,风险不对称,暂缓;图片字节不是文本,属于上游多模态编码的开销,插件层没有安全的压缩点。
136
+ - **对话文本**:本轮加了词删除/替换、标点整理、对话编辑。更激进的「语义摘要历史消息」需要额外一次 LLM 调用才能做,违背「不起外部进程」的约束,不做。
137
+ - **系统提示词**:只读不改。提示词里每一个词都是你写来约束模型的,插件不做自动裁剪,也不追加内容。
138
+
139
+ ## 设计约束
140
+
141
+ - **工具结果只追加。** 替换发生在 `tools/post-execute`,因此被记录的就是替换后的内容。不用 `sessionProjections`、不做追溯修改、不会让前缀缓存失效。聊天文本与旧工具结果则有意不同:历史句号与旧工具结果的 RTK 压缩只在派生请求(`session.deriveMessages()`)中发生,从不写入持久化日志。
142
+ - **不改写参数。** DSH 在工具管线里禁止这样做,改写过的命令是另一个可能出错的地方。
143
+ - **零新依赖。** `index.js` 只引入自己的文件。
144
+ - **过滤器故障不等于工具失败。** 每个分支都有保护;出错时返回原始 decision。
145
+ - **与 `dsh-token-frugal` 兼容。** 两者同时挂载时,让 `dsh-token-frugal` 先跑无损编码,再由 `dsh-oh-my-token` 做语义准入。两者在任何变换上都不重叠。
146
+
147
+ ## 刻意不做
148
+
149
+ - **宿主 CLI 发现。** 告诉 agent 有哪些二进制可用(`PromptContext` 条目、`oh-my-token host-tools`)是独立的可选阶段;注入工具清单会让每个会话都付出提示词字节,包括从不调用 shell 的会话。
150
+ - **字符级压缩。** 到处删标点风险很大,只为省一个 token 的零头。只保留上面的散文场景。
151
+ - **符号图。** 大纲来自语言感知的正则。LSP 解析器更好,但那也是本插件拒绝引入的构建依赖。
152
+ - **输入框下方的小卡片。** 页面放在设置里——人找策略时会去那里;输入框下方的卡片会在每个屏幕重复同样的数字。
153
+
154
+ ## 打赏支持
155
+
156
+ 这个插件在 MIT 许可下完全开源,维护靠个人时间。如果你用起来觉得确实省了 token,欢迎请我喝杯咖啡:
157
+
158
+ ![打赏码](docs/sponsor-qrcode.jpg)
159
+
160
+ 不强制也不承诺什么——代码已经归你用了。
161
+
162
+ ## 贡献者
163
+
164
+ 名单按 GitHub 的实时数据渲染,不在仓库里写死:
165
+
166
+ <a href="https://github.com/dtyg123/dsh-oh-my-token/graphs/contributors">
167
+ <img src="https://contrib.rocks/image?repo=dtyg123/dsh-oh-my-token" alt="Contributors" />
168
+ </a>
169
+
170
+ ## Star
171
+
172
+ [![Star 趋势](https://api.star-history.com/svg?repos=dtyg123/dsh-oh-my-token&type=Date)](https://star-history.com/#dtyg123/dsh-oh-my-token&Date)
173
+
174
+ ![GitHub stars](https://img.shields.io/github/stars/dtyg123/dsh-oh-my-token?style=social)
175
+
176
+ ## 致谢
177
+
178
+ - **[RTK](https://github.com/rtk-ai/rtk)(Apache-2.0)** — 按命令过滤工具输出的思路来自 RTK;本插件的命令过滤器与结构过滤器都是纯 JS 实现。
179
+ - **[codegraph](https://github.com/isink17/codegraph)(MCP 服务,FSL-1.1)** — 「先取符号地图,再按范围读取」的检索思路来自 codegraph;本插件用语言感知的正则做了无图库、无 MCP 服务的轻量实现。
180
+ - 许可证细节见 [`THIRD_PARTY_NOTICES.md`](THIRD_PARTY_NOTICES.md) 与 [`LICENSES/Apache-2.0.txt`](LICENSES/Apache-2.0.txt)。
181
+
182
+ ## 许可
183
+
184
+ MIT
185
+
186
+ RTK 结构过滤器按 Apache-2.0 使用;完整第三方声明(含 Apache-2.0 全文)见 `THIRD_PARTY_NOTICES.md` 与 `LICENSES/Apache-2.0.txt`。
package/README_EN.md ADDED
@@ -0,0 +1,186 @@
1
+ # dsh-oh-my-token
2
+
3
+ [中文](README.md) | English
4
+
5
+ > Keep tool output out of the prompt unless the agent needs it.
6
+
7
+ `dsh-oh-my-token` is a [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) plugin that rewrites a tool result **before it is logged**, so the model and the durable transcript see the same bytes. It never rewrites tool arguments, never touches session files on disk, and never spawns a helper process.
8
+
9
+ It internalises two ideas rather than bundling two tools:
10
+
11
+ | Idea | Source | What `dsh-oh-my-token` does instead |
12
+ | --- | --- | --- |
13
+ | Command- and structure-aware compaction | [RTK](https://github.com/rtk-ai/rtk) (Apache-2.0) | Parses the command the model already ran and keeps the verdict plus failure detail; when no command filter matched, compacts by output shape: git diff/status/log, build logs, grep/find/ls/tree, duplicate logs, numbered dumps and search lists. Pure JS, no binary. |
14
+ | Retrieve symbols, not files | [codegraph](https://github.com/isink17/codegraph) | Turns a large un-ranged `read` into a symbol outline and caps huge `grep` results. No SQLite graph, no MCP server. |
15
+
16
+ Plus two transformations the model never needs to read (independently switchable): on a line that is provably prose, a configurable word table deletes or replaces words (`谢谢`, `请`, `please`, `thanks`, … — delete by default, or swap one word for another), and punctuation is tidied: a mark opening a paragraph is dropped, two stuck-together marks collapse to one (a comma and a period keep the period; the same strength rule applies to the rest), and the run of **sentence-final** `.`, `。`, `,` and `,` marks is removed (an ASCII ellipsis is kept). They apply to tool output, your own typed messages, the assistant's replies, and past turns — the last of these is stripped while the request is assembled, so the model never sees those bytes while the stored session files stay byte-for-byte unchanged.
17
+
18
+ Plus two extras on the same derived path:
19
+
20
+ - **Conversation editing** — rewrite any recent message from the settings page. The rewrite is only carried in the next request; it is never written to the durable log, and "restore" puts the original back.
21
+ - **Red lines in the chat** — in your own messages and in the **body** of the model's replies, every word the plugin drops is drawn where it was: struck through in red, a replacement in green. Your messages use the harness's text-rule hook; a reply body is harness-rendered Markdown with no text hook, so the plugin puts the removed words back into the finished DOM (a re-render is decorated again).
22
+ - **Transform record** — the settings page expands each recent prose change as a diff: removed words struck through in red, replaced or new text in green, the way a changed file reads on GitHub. The record is written to the profile directory, so it survives a restart.
23
+
24
+ ## What it keeps
25
+
26
+ Filtering is only allowed to drop text that carries no decision. Concretely:
27
+
28
+ - `pytest` → `✓ 42 passed in 1.23s`; on failure every `FAILED`, `E `, traceback and summary line survives.
29
+ - `git status` → `clean`, or the first 40 lines.
30
+ - `git diff` → headers plus changed lines; a whitespace-only diff collapses.
31
+ - `tsc` → every `error TSxxxx` line and a total count; warnings drop.
32
+ - `npm/pnpm/yarn/bun/pip/uv/poetry` install → the summary line, or the error lines on failure.
33
+ - Any other command → ANSI, carriage-return repaints, repeated lines and progress bars only. The command string is never rewritten.
34
+ - When no command filter matched (or for old tool results in history), RTK structure compaction takes over by shape: git diff/status/log keep names, counts and hunk headers; build logs keep errors, warnings and the summary; `cargo build/test` folds the Compiling/Checking progress and keeps `error[E…]`, `test result:` and Finished; `go test` collapses every `ok`/`?` package into one verdict line and, on failure, keeps the detail from the first FAIL; `eslint` compact output groups and counts by file; grep/find/ls/tree/search-list group and count; duplicate log lines collapse; an unstructured blob keeps head and tail. It only ever shrinks.
35
+
36
+ When a result is still over budget, the full text is saved through `ctx.spillStore` and the marker tells the model where it went. If no spill store is mounted, the marker says how to re-run or re-read instead — the plugin never elides text it cannot recover.
37
+
38
+ ## Install
39
+
40
+ ```sh
41
+ dsh plugin --profile web add dsh-oh-my-token
42
+ ```
43
+
44
+ For a local checkout:
45
+
46
+ ```sh
47
+ dsh plugin --profile web add file:/path/to/dsh-oh-my-token
48
+ ```
49
+
50
+ The command adds the package to the profile's `dsh.profile.bundles`, and the package's own `cordis.patch.yml` mounts the row. `dsh --profile web --dump-config` shows the composed row if you want to confirm it.
51
+
52
+ To change a budget, add the field under that row in the profile's `cordis.patch.yml`; anything omitted keeps the default from the bundle patch. The switches and the prose scope do not need the patch — the Settings page owns them.
53
+
54
+ ## Settings page
55
+
56
+ **Settings → 省 Token** is the management panel, split into **Overview / Compression / Prose / Chat / Prompt / About** tabs instead of one long page (About shows the plugin name, the version read from `package.json`, and a button that opens the GitHub repository):
57
+
58
+ - One switch per transform (5 command filters, RTK structure compaction, 2 retrieval transforms, the punctuation tidy);
59
+ - A plain-language compression-strength pick (gentle / default / aggressive) that sets the budgets and min-rewrite thresholds in one click, with the raw numbers still available under "advanced";
60
+ - Advanced: budgets, `minChars`/`minGain`, retrieval thresholds, over-budget recovery (`spill`/`rerun`/`none`), `logEvery`, and the plugin master switch;
61
+ - A three-way scope shared by the prose transforms (punctuation / words) (`off` / prose outputs only / all prose);
62
+ - The word table (rules) editor: one row per word with an optional replacement (empty = delete), saved as `prose.politenessWords`; the built-in rules cover politeness words and speech particles (啊 / 呀 / 吧 / 呢 / 嘛 / 哦…), and a particle is only dropped at the end of a phrase so 酒吧 / 网吧 / 毛呢 / 哗啦 stay intact;
63
+ - Conversation editing: rewrite recent messages; the rewrite only ships in the next request, never the durable log, and can be restored. Each message of the live turn also has a 改写 button in the chat; it matches on the message text, so it needs no session knowledge and works right after a restart;
64
+ - The transform record: each recent prose change shown as a diff, removed words struck through in red and new text in green;
65
+ - The savings record: this process and all time, tokens and characters removed, the saved share, a per-tool table, and a message/reply strip count;
66
+ - The profile directory the choice is written to, so you can see whether a switch actually persisted.
67
+
68
+ Changes apply on the next tool call — no restart. The choice is written to `dsh-oh-my-token.state.json` in the profile directory (`DSH_PROFILE_DIR` when set, otherwise discovered from the profile that carries this package) and wins over the bundle config on the next start. Statistics live beside it in `dsh-oh-my-token.stats.json` and can be cleared from the page.
69
+
70
+ Three exact routes back the page: `/dsh-oh-my-token/state`, `/dsh-oh-my-token/stats`, and `/dsh-oh-my-token/prompt` (reads the currently effective system prompt).
71
+
72
+ ## Full prompt
73
+
74
+ The 完整提示词 card in Settings → 省 Token is **read-only**, not an editor: press 获取提示词 and the plugin asks the host to assemble the system prompt right now, so what you see is exactly what the next request would carry — the core prompt, the host's context, and **sections other plugins injected**, in the same order. Variables such as `{{provider}}` and `{{model}}` are substituted with their current values; a variable with no value stays literal instead of failing the read.
75
+
76
+ - 复制全文 copies the text to the clipboard;
77
+ - the card's header shows `N sections · M characters`, so a composed prompt can be checked at a glance;
78
+ - the plugin never edits the prompt — it only reads it.
79
+
80
+ ## Configuration
81
+
82
+ | Field | Default | Meaning |
83
+ | --- | --- | --- |
84
+ | `enabled` | `true` | Turn the plugin off without removing the row. |
85
+ | `budgets.default` | `6000` | Character cap for any tool without its own entry. |
86
+ | `budgets.read` | `12000` | File content is the substrate for edits, so it gets more. |
87
+ | `budgets.grep` | `6000` | |
88
+ | `budgets.bash` | `4000` | |
89
+ | `budgets.errorFactor` | `2` | An error result is allowed to be this many times larger. |
90
+ | `minChars` | `800` | Results below this are left alone (cleanup is not worth the risk). |
91
+ | `minGain` | `0.05` | Discard a rewrite that saves less than this fraction. A prose-period rewrite is kept regardless. |
92
+ | `filters.*` | all `true` | Per-filter switches: `pytest`, `git`, `tsc`, `packageManager`, `generic`. |
93
+ | `rtk` | `true` | Enable RTK structure compaction when no command filter matched; also a Settings switch. |
94
+ | `retrieval.readOutlineOverLines` | `400` | Outline a `read` only above this line count, and only when the call had no `offset`/`limit`. |
95
+ | `retrieval.maxOutlineSymbols` | `60` | |
96
+ | `retrieval.maxGrepMatches` | `50` | |
97
+ | `prose.stripTrailingPeriod` | `true` | Tidy punctuation: drop a mark opening a paragraph; collapse two stuck-together marks to one (a comma and a period keep the period, same-strength keeps the right one); then drop the run of trailing `.` / `。` / `,` / `,` (an ASCII ellipsis is kept). |
98
+ | `prose.stripPoliteness` | `true` | Delete or replace words on prose lines via the `politenessWords` table. |
99
+ | `prose.politenessWords` | built-in rules + particles | Each entry is `{ word, replace? }`: empty/omitted `replace` deletes the word, a string replaces it. Unset = the built-in rules (谢谢 / 请 / please / thanks, … plus particles 啊 / 呀 / 吧 / 呢 / 嘛 / 哦, …, deleted only at a phrase end and guarded against splitting 酒吧 / 网吧 / 毛呢 / 哗啦); an explicit empty list turns the word step off. |
100
+ | `prose.scope` | `filtered` | `filtered` = only output a command filter marked as prose (e.g. `git log`); `all`; `off`. |
101
+ | `recovery` | `spill` | `spill` \| `rerun` \| `none`. |
102
+ | `logEvery` | `0` | Log a savings line every N rewritten results; `0` is quiet. |
103
+
104
+ An unknown field is an error at activation, not a silent no-op. Every field above is editable in Settings → 省 Token → Advanced; `enabled` is the master switch, and `filters.*` map to the switch rows above.
105
+
106
+ ### Why the period trimmer is guarded
107
+
108
+ Deleting a period from a filename, a URL, a version or a line of code corrupts data to save one token. `isProseLine` therefore refuses:
109
+
110
+ - fenced code, diff lines, lines starting with `{ [ <`, lines ending in `;{}=`, and lines carrying code punctuation (`= ( ) ; { } [ ]`) that end in a comma;
111
+ - assignment/statement lines (containing `= ; { }` or starting with `const`/`function`/`import`), which politeness removal never touches;
112
+ - anything containing a URL, an email address, a path with an extension;
113
+ - anything that looks like a version (`2.2.0`) or `host:port`;
114
+ - list items (`- `, `* `), ellipses, and `e.g.` / `i.e.`.
115
+
116
+ ## Measure it
117
+
118
+ ```sh
119
+ oh-my-token report [profile-dir | session.jsonl]
120
+ ```
121
+
122
+ Buckets a session log by event type (`user/message`, `assistant/message`, `tool/call`, `tool/result`) and lists the most expensive tool results. That is the "before" number; the Settings page shows the "after".
123
+
124
+ ```sh
125
+ oh-my-token map <file|dir> # the outline `read` would produce
126
+ oh-my-token lint [config.json] # validate a row config without starting DSH
127
+ ```
128
+
129
+ ## Where else it could compress
130
+
131
+ Walked through "every byte the model could act on" once more:
132
+
133
+ - **Command output** (the big one): 5 command filters + 17 RTK structural compactors already cover pytest / git / tsc / package managers / eslint / cargo / go test / grep / find / ls / tree. The long tail (docker, kubectl, make…) runs through shape detection + generic cleanup + smart-truncation instead of one more hand-written parser — every parser is a regression-test surface to maintain.
134
+ - **File reads**: large `read` gets a symbol outline, large `grep` gets capped. Going further (AST-only, skip import blocks) would trade "text the model can quote" for "a summary the model has to ask for again", with a real chance of dropping the one line that matters. Not worth it.
135
+ - **JSON / images**: collapsing repeated JSON objects is the next candidate, but for a lockfile one deleted line can send the model after the wrong version — asymmetric risk, deferred. Image bytes are not text; that cost lives in the upstream multimodal encoder, where no plugin-side compression is safe.
136
+ - **Conversation text**: covered by the word table, punctuation tidy and the conversation editor. Anything more aggressive (summarising history) needs another LLM call, which breaks the no-helper-process constraint.
137
+ - **System prompt**: read-only. Every word in a prompt is a constraint the user chose, so the plugin never trims it and never appends to it.
138
+
139
+ ## Design constraints
140
+
141
+ - **Append-only tool results.** The replacement is produced in `tools/post-execute`, so it is what gets logged. No `sessionProjections`, no retroactive edits, no prefix cache invalidation. Chat text and old tool results are different by design: historical periods and RTK compaction of old tool results happen only in the derived request (`session.deriveMessages()`), never in the durable session log.
142
+ - **No argument rewriting.** DSH forbids it in the tool pipeline, and a rewritten command is a second thing that can be wrong.
143
+ - **No new dependencies.** `index.js` imports only its own files.
144
+ - **A filter fault is not a tool failure.** Every branch is wrapped; on error the original decision is returned untouched.
145
+ - **Plays well with `dsh-token-frugal`.** If both are mounted, let `dsh-token-frugal` run its lossless encoders first and `dsh-oh-my-token` do the semantic admission. The two do not overlap on any transform.
146
+
147
+ ## Deliberately not here
148
+
149
+ - **Host CLI discovery.** Telling the agent which binaries exist (`PromptContext` entry, `oh-my-token host-tools`) is a separate, optional phase; injecting a tool inventory costs prompt bytes for every session, including ones that never shell out.
150
+ - **Character-level compression.** Removing punctuation everywhere is a large risk for a rounding error in tokens. Only the prose case above is kept.
151
+ - **A symbol graph.** Outlines come from language-aware regexes. An LSP-backed resolver would be better; it is also a build dependency this plugin refuses to take.
152
+ - **A composer-dock chip.** The page is under Settings, where a person looks for a policy; a chip below the composer would repeat the same numbers on every screen.
153
+
154
+ ## Sponsor
155
+
156
+ This plugin is fully open-source under the MIT licence and maintained on personal time. If it saves you enough tokens to feel worth a coffee, you can support me here:
157
+
158
+ ![QR for sponsorship](docs/sponsor-qrcode.jpg)
159
+
160
+ Not required, not expected, and it doesn't buy any promises — the code is already yours.
161
+
162
+ ## Contributors
163
+
164
+ Rendered from GitHub's live data — nothing is hard-coded in the repository:
165
+
166
+ <a href="https://github.com/dtyg123/dsh-oh-my-token/graphs/contributors">
167
+ <img src="https://contrib.rocks/image?repo=dtyg123/dsh-oh-my-token" alt="Contributors" />
168
+ </a>
169
+
170
+ ## Stars
171
+
172
+ [![Star history](https://api.star-history.com/svg?repos=dtyg123/dsh-oh-my-token&type=Date)](https://star-history.com/#dtyg123/dsh-oh-my-token&Date)
173
+
174
+ ![GitHub stars](https://img.shields.io/github/stars/dtyg123/dsh-oh-my-token?style=social)
175
+
176
+ ## Acknowledgements
177
+
178
+ - **[RTK](https://github.com/rtk-ai/rtk) (Apache-2.0)** — the per-command output-filtering idea comes from RTK; this plugin implements both the command filters and the structural filters in pure JS.
179
+ - **[codegraph](https://github.com/isink17/codegraph) (MCP service, FSL-1.1)** — the "read the symbol map first, then a range" retrieval idea comes from codegraph; this plugin implements a lightweight version with language-aware regexes, with no graph database and no MCP server.
180
+ - See the third-party notices for the exact licence terms and the Apache-2.0 text: [`THIRD_PARTY_NOTICES.md`](THIRD_PARTY_NOTICES.md) and [`LICENSES/Apache-2.0.txt`](LICENSES/Apache-2.0.txt).
181
+
182
+ ## Licence
183
+
184
+ MIT
185
+
186
+ The RTK structural filters are used under Apache-2.0; the full third-party notices (including the Apache-2.0 text) are in `THIRD_PARTY_NOTICES.md` and `LICENSES/Apache-2.0.txt`.
@@ -0,0 +1,34 @@
1
+ # Third-Party Notices / 第三方声明
2
+
3
+ `dsh-oh-my-token` is MIT-licensed (see `LICENSE`). It contains or derives from
4
+ the works below; their notices are reproduced here as required.
5
+
6
+ ## RTK — Apache License 2.0
7
+
8
+ - Project: RTK — https://github.com/rtk-ai/rtk
9
+ - License: Apache License 2.0 (full text: [`LICENSES/Apache-2.0.txt`](LICENSES/Apache-2.0.txt))
10
+ - Copyright: the RTK contributors.
11
+
12
+ `lib/rtk.js` is an independent JavaScript implementation of the RTK structural
13
+ filter behaviour, written from the behaviour of the RTK tool (Apache-2.0). No
14
+ third-party JavaScript port was copied. The numeric thresholds and output shapes
15
+ are kept compatible with RTK; the diff-recovery marker names this plugin's own
16
+ recovery path instead of the `rtk` binary.
17
+
18
+ The RTK-style portion is used under Apache-2.0; the rest of this package is MIT.
19
+ Apache-2.0 is compatible with MIT and does not change this package's MIT license.
20
+
21
+ ## codegraph — Functional Source License 1.1
22
+
23
+ - Project: codegraph — https://github.com/isink17/codegraph
24
+ - License: Functional Source License, Version 1.1 (FSL-1.1; source-available,
25
+ converts to Apache-2.0 on 2028-03-18)
26
+ - Copyright © 2026 isink17.
27
+
28
+ No code from codegraph is copied into this package. The retrieval transform — a
29
+ symbol outline before a ranged read — is an independent implementation in
30
+ `lib/retrieval.js`, written from the idea alone. Ideas and algorithms are not
31
+ copyrightable, so codegraph's license does not apply to this package; the
32
+ acknowledgement is a courtesy. If code is ever copied from codegraph, its FSL
33
+ terms (including the non-commercial restriction before the change date) would
34
+ need to be honoured and could be incompatible with an MIT release.