dsh-oh-my-token 0.0.0-stage → 0.0.1
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 +28 -0
- package/LICENSES/Apache-2.0.txt +190 -0
- package/README.md +144 -2
- package/README_EN.md +145 -0
- package/THIRD_PARTY_NOTICES.md +34 -0
- package/bin/oh-my-token.js +131 -0
- package/client.js +818 -0
- package/cordis.patch.yml +57 -0
- package/index.js +382 -0
- package/lib/config.js +184 -0
- package/lib/filters.js +299 -0
- package/lib/gate.js +217 -0
- package/lib/messages.js +186 -0
- package/lib/modes.js +255 -0
- package/lib/report.js +144 -0
- package/lib/retrieval.js +176 -0
- package/lib/rtk.js +612 -0
- package/lib/stats.js +130 -0
- package/lib/system-prompt.js +128 -0
- package/lib/text.js +285 -0
- package/package.json +68 -4
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,145 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-oh-my-token
|
|
2
2
|
|
|
3
|
-
|
|
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
|
+
|
|
22
|
+
- `pytest` → `✓ 42 passed in 1.23s`;失败时保留每一条 `FAILED`、`E `、回溯与摘要行。
|
|
23
|
+
- `git status` → `clean`,或前 40 行。
|
|
24
|
+
- `git diff` → 文件头加变更行;纯空白 diff 折叠为一行。
|
|
25
|
+
- `tsc` → 每条 `error TSxxxx` 加总数;告警丢弃。
|
|
26
|
+
- `npm/pnpm/yarn/bun/pip/uv/poetry` 安装 → 成功留摘要行,失败留错误行。
|
|
27
|
+
- 其他命令 → 只做 ANSI、回车重绘、重复行与进度条清理。命令字符串永不改写。
|
|
28
|
+
- 命令过滤器没命中时(或对历史中的旧工具结果),RTK 结构压缩按形状接管:`git diff/status/log` 保留文件名、计数与 hunk 头;构建日志保留错误、告警与摘要;`grep/find/ls/tree/search-list` 按文件/目录分组并给出计数;重复日志折叠;超长无结构内容保留头尾。它只收缩,不放大。
|
|
29
|
+
|
|
30
|
+
结果仍超预算时,全文通过 `ctx.spillStore` 保存,标记会告诉模型去哪里取。如果没挂载 spill store,标记会说明如何重跑或重新读取——插件绝不丢弃无法恢复的文本。
|
|
31
|
+
|
|
32
|
+
## 安装
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
dsh plugin --profile web add dsh-oh-my-token
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
本地检出:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
dsh plugin --profile web add file:/path/to/dsh-oh-my-token
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
该命令把包加入配置目录的 `dsh.profile.bundles`,包自带的 `cordis.patch.yml` 负责挂载这一行。可用 `dsh --profile web --dump-config` 查看合成后的配置。
|
|
45
|
+
|
|
46
|
+
要改预算,在配置目录的 `cordis.patch.yml` 对应行下添加字段;省略的字段沿用 bundle patch 的默认值。开关和散文范围无需改 patch——由设置页面管理。
|
|
47
|
+
|
|
48
|
+
## 设置页面
|
|
49
|
+
|
|
50
|
+
**设置 → 省 Token** 是管理面板:
|
|
51
|
+
|
|
52
|
+
- 每个变换一个开关(5 个命令过滤器、RTK 结构压缩、2 个检索变换、句末标点、客套词、系统提示词编辑);
|
|
53
|
+
- 高级配置:预算、`minChars`/`minGain`、检索阈值、超预算处理(`spill`/`rerun`/`none`)与 `logEvery`,以及插件总开关;
|
|
54
|
+
- 散文变换(句末标点 / 客套词)共用的三档范围(`off` / 仅散文输出 / 所有散文);
|
|
55
|
+
- 节省记录:本次进程与历史累计、移除的 token 与字符、节省比例、按工具明细表,以及消息/回复剥离计数;
|
|
56
|
+
- 选择被写入的配置目录,方便确认开关是否真的落盘。
|
|
57
|
+
|
|
58
|
+
改动在下一次工具调用即生效,无需重启。选择写入配置目录的 `dsh-oh-my-token.state.json`(优先取 `DSH_PROFILE_DIR`,否则从携带本包的配置目录推断),下次启动时覆盖 bundle 配置。统计在同目录的 `dsh-oh-my-token.stats.json`,可在页面清除。
|
|
59
|
+
|
|
60
|
+
页面由三条精确路由支撑:`/dsh-oh-my-token/state`、`/dsh-oh-my-token/stats` 与 `/dsh-oh-my-token/prompt`(读取当前生效的系统提示词)。
|
|
61
|
+
|
|
62
|
+
## 系统提示词
|
|
63
|
+
|
|
64
|
+
在「设置 → 省 Token」底部的「系统提示词」卡片里,打开开关,把你要追加的内容拆成若干个**小段(卡片)**:每张卡片一小段正文,点击「添加一小段」新增,「上移 / 下移」调整顺序,「删除这一段」移除。保存后,所有卡片按从上到下的顺序**拼合成的最终系统提示词**追加到现有 section 之后。保存时旧版 `{ mode, text }` 配置自动迁移为单卡片。
|
|
65
|
+
|
|
66
|
+
- 每段一个 `interpolate: false` 的 section——已自行替换已知变量,其余 `{{...}}` 保持字面量,不会被当作未知变量而报错;
|
|
67
|
+
- 卡片顺序即提示词顺序;
|
|
68
|
+
- 运行时上下文快照不受影响;改动在下一次请求生效,无需重启。
|
|
69
|
+
- `{{变量}}`:目前 DSH 内置 `{{provider}}`(当前模型供应商)与 `{{model}}`(当前模型名),保存后这两个写法会被替换成当前值;其他写法保持字面量,不报错。
|
|
70
|
+
- 「恢复默认提示词」:立即按当前注册实时组装一份系统提示词(首次使用、未发过消息也能读到),按空行**拆成多张卡片**放进编辑器,方便在原默认内容上重新改写;读到的始终是未注入定制文本的原始提示词。
|
|
71
|
+
|
|
72
|
+
## 配置
|
|
73
|
+
|
|
74
|
+
| 字段 | 默认值 | 说明 |
|
|
75
|
+
| --- | --- | --- |
|
|
76
|
+
| `enabled` | `true` | 关闭插件但不移除配置行。 |
|
|
77
|
+
| `budgets.default` | `6000` | 没有单独配置的工具的字符上限。 |
|
|
78
|
+
| `budgets.read` | `12000` | 文件内容是编辑的基础,因此额度更高。 |
|
|
79
|
+
| `budgets.grep` | `6000` | |
|
|
80
|
+
| `budgets.bash` | `4000` | |
|
|
81
|
+
| `budgets.errorFactor` | `2` | 错误结果允许放大到倍数。 |
|
|
82
|
+
| `minChars` | `800` | 小于此值的结果不动(清理不值得冒险)。 |
|
|
83
|
+
| `minGain` | `0.05` | 丢弃节省低于此比例的改写;散文句号改写始终保留。 |
|
|
84
|
+
| `filters.*` | 全部 `true` | 各过滤器开关:`pytest`、`git`、`tsc`、`packageManager`、`generic`。 |
|
|
85
|
+
| `rtk` | `true` | 命令过滤器未命中时,按输出形状再做一层 RTK 结构压缩。也可在设置页面关闭。 |
|
|
86
|
+
| `retrieval.readOutlineOverLines` | `400` | 仅当行数超过此值且调用未带 `offset`/`limit` 时才生成大纲。 |
|
|
87
|
+
| `retrieval.maxOutlineSymbols` | `60` | |
|
|
88
|
+
| `retrieval.maxGrepMatches` | `50` | |
|
|
89
|
+
| `prose.stripTrailingPeriod` | `true` | 删除散文行末尾**连续的** `.` / `。` / `,` / `,`(省略号除外)。 |
|
|
90
|
+
| `prose.stripPoliteness` | `true` | 删去散文行里的「谢谢」「请」「please」「thanks」等客套词。 |
|
|
91
|
+
| `prose.scope` | `filtered` | `filtered` = 仅命令过滤器标记为散文的输出(如 `git log`);`all`;`off`。 |
|
|
92
|
+
| `recovery` | `spill` | `spill` \| `rerun` \| `none`。 |
|
|
93
|
+
| `logEvery` | `0` | 每 N 次改写打印一条节省日志;`0` 为静默。 |
|
|
94
|
+
|
|
95
|
+
未知字段会在激活时报错,而不是静默忽略。以上字段都可以在「设置 → 省 Token」的「高级配置」里修改;`enabled` 是总开关,`filters.*` 对应上方的开关行。
|
|
96
|
+
|
|
97
|
+
### 为什么句号剥离有防护
|
|
98
|
+
|
|
99
|
+
删掉文件名、URL、版本号或代码行里的句号,为了省一个 token 而损坏数据,代价太大。因此 `isProseLine` 会拒绝:
|
|
100
|
+
|
|
101
|
+
- 围栏代码、diff 行、以 `{ [ <` 开头或以 `;{}=` 结尾的行,以及带 `= ( ) ; { } [ ]` 等代码标点又以逗号结尾的行;
|
|
102
|
+
- 赋值/声明/语句行(含 `= ; { }` 或以 `const`/`function`/`import` 等开头),客套词删除不会碰它们;
|
|
103
|
+
- 含 URL、邮箱、带扩展名路径的行;
|
|
104
|
+
- 看起来像版本号(`2.2.0`)或 `host:port` 的内容;
|
|
105
|
+
- 列表项(`- `、`*`)、省略号,以及 `e.g.` / `i.e.`。
|
|
106
|
+
|
|
107
|
+
## 测量
|
|
108
|
+
|
|
109
|
+
```sh
|
|
110
|
+
oh-my-token report [profile-dir | session.jsonl]
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
按事件类型(`user/message`、`assistant/message`、`tool/call`、`tool/result`)统计会话日志,并列出最昂贵的工具结果。这是「改写前」的数字;设置页面显示「改写后」。
|
|
114
|
+
|
|
115
|
+
```sh
|
|
116
|
+
oh-my-token map <file|dir> # read 会生成的大纲
|
|
117
|
+
oh-my-token lint [config.json] # 校验行配置,不启动 DSH
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## 设计约束
|
|
121
|
+
|
|
122
|
+
- **工具结果只追加。** 替换发生在 `tools/post-execute`,因此被记录的就是替换后的内容。不用 `sessionProjections`、不做追溯修改、不会让前缀缓存失效。聊天文本与旧工具结果则有意不同:历史句号与旧工具结果的 RTK 压缩只在派生请求(`session.deriveMessages()`)中发生,从不写入持久化日志。
|
|
123
|
+
- **不改写参数。** DSH 在工具管线里禁止这样做,改写过的命令是另一个可能出错的地方。
|
|
124
|
+
- **零新依赖。** `index.js` 只引入自己的文件。
|
|
125
|
+
- **过滤器故障不等于工具失败。** 每个分支都有保护;出错时返回原始 decision。
|
|
126
|
+
- **与 `dsh-token-frugal` 兼容。** 两者同时挂载时,让 `dsh-token-frugal` 先跑无损编码,再由 `dsh-oh-my-token` 做语义准入。两者在任何变换上都不重叠。
|
|
127
|
+
|
|
128
|
+
## 刻意不做
|
|
129
|
+
|
|
130
|
+
- **宿主 CLI 发现。** 告诉 agent 有哪些二进制可用(`PromptContext` 条目、`oh-my-token host-tools`)是独立的可选阶段;注入工具清单会让每个会话都付出提示词字节,包括从不调用 shell 的会话。
|
|
131
|
+
- **字符级压缩。** 到处删标点风险很大,只为省一个 token 的零头。只保留上面的散文场景。
|
|
132
|
+
- **符号图。** 大纲来自语言感知的正则。LSP 解析器更好,但那也是本插件拒绝引入的构建依赖。
|
|
133
|
+
- **输入框下方的小卡片。** 页面放在设置里——人找策略时会去那里;输入框下方的卡片会在每个屏幕重复同样的数字。
|
|
134
|
+
|
|
135
|
+
## 致谢
|
|
136
|
+
|
|
137
|
+
- **[RTK](https://github.com/rtk-ai/rtk)(Apache-2.0)** — 按命令过滤工具输出的思路来自 RTK;本插件的命令过滤器与结构过滤器都是纯 JS 实现。
|
|
138
|
+
- **[codegraph](https://github.com/isink17/codegraph)(MCP 服务,FSL-1.1)** — 「先取符号地图,再按范围读取」的检索思路来自 codegraph;本插件用语言感知的正则做了无图库、无 MCP 服务的轻量实现。
|
|
139
|
+
- 许可证细节见 [`THIRD_PARTY_NOTICES.md`](THIRD_PARTY_NOTICES.md) 与 [`LICENSES/Apache-2.0.txt`](LICENSES/Apache-2.0.txt)。
|
|
140
|
+
|
|
141
|
+
## 许可
|
|
142
|
+
|
|
143
|
+
MIT
|
|
144
|
+
|
|
145
|
+
RTK 结构过滤器按 Apache-2.0 使用;完整第三方声明(含 Apache-2.0 全文)见 `THIRD_PARTY_NOTICES.md` 与 `LICENSES/Apache-2.0.txt`。
|
package/README_EN.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
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, politeness words (`谢谢`, `请`, `please`, `thanks`, …) are dropped, and the run of **sentence-final** `.`, `。`, `,` and `,` marks is removed. 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
|
+
## What it keeps
|
|
19
|
+
|
|
20
|
+
Filtering is only allowed to drop text that carries no decision. Concretely:
|
|
21
|
+
|
|
22
|
+
- `pytest` → `✓ 42 passed in 1.23s`; on failure every `FAILED`, `E `, traceback and summary line survives.
|
|
23
|
+
- `git status` → `clean`, or the first 40 lines.
|
|
24
|
+
- `git diff` → headers plus changed lines; a whitespace-only diff collapses.
|
|
25
|
+
- `tsc` → every `error TSxxxx` line and a total count; warnings drop.
|
|
26
|
+
- `npm/pnpm/yarn/bun/pip/uv/poetry` install → the summary line, or the error lines on failure.
|
|
27
|
+
- Any other command → ANSI, carriage-return repaints, repeated lines and progress bars only. The command string is never rewritten.
|
|
28
|
+
- 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; grep/find/ls/tree/search-list group and count; duplicate log lines collapse; an unstructured blob keeps head and tail. It only ever shrinks.
|
|
29
|
+
|
|
30
|
+
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.
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
dsh plugin --profile web add dsh-oh-my-token
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
For a local checkout:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
dsh plugin --profile web add file:/path/to/dsh-oh-my-token
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
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.
|
|
45
|
+
|
|
46
|
+
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.
|
|
47
|
+
|
|
48
|
+
## Settings page
|
|
49
|
+
|
|
50
|
+
**Settings → 省 Token** is the management panel:
|
|
51
|
+
|
|
52
|
+
- One switch per transform (5 command filters, RTK structure compaction, 2 retrieval transforms, the period trimmer, the politeness trimmer, the system-prompt editor);
|
|
53
|
+
- Advanced: budgets, `minChars`/`minGain`, retrieval thresholds, over-budget recovery (`spill`/`rerun`/`none`), `logEvery`, and the plugin master switch;
|
|
54
|
+
- A three-way scope shared by the prose trimmers (punctuation / politeness) (`off` / prose outputs only / all prose);
|
|
55
|
+
- 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;
|
|
56
|
+
- The profile directory the choice is written to, so you can see whether a switch actually persisted.
|
|
57
|
+
|
|
58
|
+
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.
|
|
59
|
+
|
|
60
|
+
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).
|
|
61
|
+
|
|
62
|
+
## System prompt
|
|
63
|
+
|
|
64
|
+
At the bottom of Settings → 省 Token, the 系统提示词 card lets you enable the switch and split what you want appended into **segment cards** — each card is one piece of prose; "添加一小段" adds a card, "上移 / 下移" reorder, "删除这一段" removes it. On save, all cards are **joined top-to-bottom into the final system prompt** and appended after the existing sections. The old `{ mode, text }` config migrates to a single card automatically.
|
|
65
|
+
|
|
66
|
+
- each card becomes its own `interpolate: false` section — known variables are already substituted by us, so unknown `{{...}}` stays literal instead of throwing as an unknown variable;
|
|
67
|
+
- card order is prompt order;
|
|
68
|
+
- runtime context snapshots are untouched, and changes apply on the next request with no restart.
|
|
69
|
+
- `{{variables}}`: DSH currently ships `{{provider}}` (the active model provider) and `{{model}}` (the active model). Both are replaced with their current value on save; any other spelling stays literal without error.
|
|
70
|
+
- 「恢复默认提示词」live-assembles the currently effective system prompt — readable from the very first use, before any message is sent — and **splits it into cards** on the blank-line boundaries, so you can rewrite on top of the default. It always reads the original prompt without your injected text.
|
|
71
|
+
|
|
72
|
+
## Configuration
|
|
73
|
+
|
|
74
|
+
| Field | Default | Meaning |
|
|
75
|
+
| --- | --- | --- |
|
|
76
|
+
| `enabled` | `true` | Turn the plugin off without removing the row. |
|
|
77
|
+
| `budgets.default` | `6000` | Character cap for any tool without its own entry. |
|
|
78
|
+
| `budgets.read` | `12000` | File content is the substrate for edits, so it gets more. |
|
|
79
|
+
| `budgets.grep` | `6000` | |
|
|
80
|
+
| `budgets.bash` | `4000` | |
|
|
81
|
+
| `budgets.errorFactor` | `2` | An error result is allowed to be this many times larger. |
|
|
82
|
+
| `minChars` | `800` | Results below this are left alone (cleanup is not worth the risk). |
|
|
83
|
+
| `minGain` | `0.05` | Discard a rewrite that saves less than this fraction. A prose-period rewrite is kept regardless. |
|
|
84
|
+
| `filters.*` | all `true` | Per-filter switches: `pytest`, `git`, `tsc`, `packageManager`, `generic`. |
|
|
85
|
+
| `rtk` | `true` | Enable RTK structure compaction when no command filter matched; also a Settings switch. |
|
|
86
|
+
| `retrieval.readOutlineOverLines` | `400` | Outline a `read` only above this line count, and only when the call had no `offset`/`limit`. |
|
|
87
|
+
| `retrieval.maxOutlineSymbols` | `60` | |
|
|
88
|
+
| `retrieval.maxGrepMatches` | `50` | |
|
|
89
|
+
| `prose.stripTrailingPeriod` | `true` | Remove every trailing `.` / `。` / `,` / `,` from prose lines (an ASCII ellipsis is kept). |
|
|
90
|
+
| `prose.stripPoliteness` | `true` | Drop politeness words (`谢谢`, `请`, `please`, `thanks`, …) from prose lines. |
|
|
91
|
+
| `prose.scope` | `filtered` | `filtered` = only output a command filter marked as prose (e.g. `git log`); `all`; `off`. |
|
|
92
|
+
| `recovery` | `spill` | `spill` \| `rerun` \| `none`. |
|
|
93
|
+
| `logEvery` | `0` | Log a savings line every N rewritten results; `0` is quiet. |
|
|
94
|
+
|
|
95
|
+
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.
|
|
96
|
+
|
|
97
|
+
### Why the period trimmer is guarded
|
|
98
|
+
|
|
99
|
+
Deleting a period from a filename, a URL, a version or a line of code corrupts data to save one token. `isProseLine` therefore refuses:
|
|
100
|
+
|
|
101
|
+
- fenced code, diff lines, lines starting with `{ [ <`, lines ending in `;{}=`, and lines carrying code punctuation (`= ( ) ; { } [ ]`) that end in a comma;
|
|
102
|
+
- assignment/statement lines (containing `= ; { }` or starting with `const`/`function`/`import`), which politeness removal never touches;
|
|
103
|
+
- anything containing a URL, an email address, a path with an extension;
|
|
104
|
+
- anything that looks like a version (`2.2.0`) or `host:port`;
|
|
105
|
+
- list items (`- `, `* `), ellipses, and `e.g.` / `i.e.`.
|
|
106
|
+
|
|
107
|
+
## Measure it
|
|
108
|
+
|
|
109
|
+
```sh
|
|
110
|
+
oh-my-token report [profile-dir | session.jsonl]
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
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".
|
|
114
|
+
|
|
115
|
+
```sh
|
|
116
|
+
oh-my-token map <file|dir> # the outline `read` would produce
|
|
117
|
+
oh-my-token lint [config.json] # validate a row config without starting DSH
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Design constraints
|
|
121
|
+
|
|
122
|
+
- **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.
|
|
123
|
+
- **No argument rewriting.** DSH forbids it in the tool pipeline, and a rewritten command is a second thing that can be wrong.
|
|
124
|
+
- **No new dependencies.** `index.js` imports only its own files.
|
|
125
|
+
- **A filter fault is not a tool failure.** Every branch is wrapped; on error the original decision is returned untouched.
|
|
126
|
+
- **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.
|
|
127
|
+
|
|
128
|
+
## Deliberately not here
|
|
129
|
+
|
|
130
|
+
- **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.
|
|
131
|
+
- **Character-level compression.** Removing punctuation everywhere is a large risk for a rounding error in tokens. Only the prose case above is kept.
|
|
132
|
+
- **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.
|
|
133
|
+
- **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.
|
|
134
|
+
|
|
135
|
+
## Acknowledgements
|
|
136
|
+
|
|
137
|
+
- **[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.
|
|
138
|
+
- **[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.
|
|
139
|
+
- 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).
|
|
140
|
+
|
|
141
|
+
## Licence
|
|
142
|
+
|
|
143
|
+
MIT
|
|
144
|
+
|
|
145
|
+
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.
|