dsh-go-token-diet 0.0.0-stage → 2.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dsh-token-diet 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,57 @@
1
- # Temporary Holding Version
1
+ # dsh-go-token-diet · 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
+ 给 [dsh-go](https://dsh-go.com) 手机 App 的原生小插件:**看清楚上下文被谁吃掉了,然后一键让 AI 压缩。**
4
+
5
+ 手机上的对话最容易「越长越贵」:一次 `ls -R`、一份日志、一段 JSON,就能把上下文顶到 80%。
6
+ 这个插件把 DSH 已经写下的会话事件折成三样东西,只读、不联网、不改任何日志:
7
+
8
+ | 在哪儿 | 看到什么 |
9
+ |---|---|
10
+ | 输入框上方的胶囊 | `上下文 63%`(超过 60% 变黄,85% 变红;有超 8K 的工具输出会提前提醒) |
11
+ | 面板(对话详情页「插件」/ 全部功能) | 上下文进度条 + 缓存命中、按工具分的输出排行、超 8K 条目数、最近输入/输出/请求数、一句建议 |
12
+ | 每个回合的尾注 | `入 12K · 出 1.2K` |
13
+ | 面板按钮 | **压缩**(把压缩请求填进输入框)、**复制报告** |
14
+
15
+ ## 它怎么算的
16
+
17
+ 全部来自当前会话的事件流(`sessions.get(id).snapshotEvents()`):
18
+
19
+ - **工具输出字数**:`tool/result` 里所有 `text` 块的码点长度,按 `tool/call` 的 `name` 归到工具名下(调用 id 依次找 `message.callId`、`message.toolCallId`、`message.source.callId`)。
20
+ - **上下文占用**:最近一次 `request/context.contextWindow` 与最近一次 usage 的 `inputTokens + cacheReadTokens + cacheWriteTokens` 之比。
21
+ - **缓存命中**:`cacheRead ÷ (input + cacheRead + cacheWrite)`。
22
+ - **回合脚注**:按回合累加各 step 的 usage,同一 `(turn, step)` 的重写以最后一次为准。
23
+ - **超 8K 条目**:单条工具结果 ≥ 8192 字——这正是内置压缩器 `@deepseek-ai/dsh-compaction-tool-result-pruner` 的默认 `thresholdChars`,压缩时这类条目会被自动裁剪成头尾摘要。
24
+
25
+ 插件**不**拦截工具结果、**不**改日志、**不**调用模型,也没有网络请求。它只做两件有副作用的事:把压缩请求填进输入框(**不自动发送**)、把报告放进剪贴板(都要你点)。
26
+
27
+ > 为什么不直接调 `/compact`:装了 billion-context(bili)的主机会把 `command-compact` 静态关掉——`/compact` 驱动的正是 bili 明确拒绝的宿主压缩路径。所以按钮改成把一句「让 AI 用 compress 压旧内容」填进输入框,压缩仍由模型按 acp 的规则执行。
28
+
29
+ ## 为什么不做「省了多少 token」
30
+
31
+ 这个主机上没有任何 compaction/prune 完成记录可读,硬算「已省」只能编数字。压缩效果请直接看压缩后的上下文占用与缓存命中变化。
32
+
33
+ ## 安装
34
+
35
+ ```sh
36
+ # 目录:$DSH_HOME/dsh-go/plugins/dsh-go-token-diet
37
+ dsh plugin --profile web add "$DSH_HOME/dsh-go/plugins/dsh-go-token-diet"
38
+ ```
39
+
40
+ 装上即生效,不用重启;改了 `lib/` 里的代码要在 App「引擎」页重启引擎。卸载:`dsh plugin --profile web remove dsh-go-token-diet`,再删目录。
41
+
42
+ ## 开发
43
+
44
+ ```sh
45
+ node "$DSH_HOME/skills/dsh-go-plugin/kit/bin/check.mjs" . --load # 官方检查器
46
+ node test/verify.mjs # 用官方 createTestHost 跑注册、数据、动作
47
+ ```
48
+
49
+ `test/verify.mjs` 覆盖:三个面的注册、胶囊文案与色调、面板数据(9000 字算超 8K、占比、缓存命中、工具名走 `toolCallId`)、视图可渲染、回合脚注、压缩请求插入、复制报告、英文环境、空会话。
50
+
51
+ ## English
52
+
53
+ A native dsh-go plugin that folds the current session's event log into a glance: context-window usage in the composer strip, a panel ranking tool output by tool with cache-hit rate and over-8192-char result count, per-turn in/out notes, and one-tap **compact** (fills a compression request into the composer) plus **copy report**. Local-only, read-only, no model calls.
54
+
55
+ ## License
56
+
57
+ MIT
@@ -0,0 +1,4 @@
1
+ # id: any unique id; name: must equal "name" in package.json.
2
+ - insert:
3
+ - id: local-dsh-go-token-diet
4
+ name: dsh-go-token-diet
package/lib/index.js ADDED
@@ -0,0 +1,455 @@
1
+ /**
2
+ * dsh-token-diet — 给 dsh-go 的会话"称重"。
3
+ *
4
+ * 手机屏幕上最贵的不是字,是上下文:
5
+ * · 输入框上方的胶囊:一眼看到上下文占了百分之几;
6
+ * · 面板:谁在吃 token(按工具分)、缓存命中、超 8K 的条目;
7
+ * · 一键「压缩上下文」:把压缩请求填进输入框(上下文由 acp/bili 压缩器处理,工具输出超 8192 字的条目会被自动瘦身);
8
+ * · 回合脚注:每个回合的入/出 token。
9
+ *
10
+ * 只读会话事件(session.snapshotEvents),不改任何日志,也不拦截工具结果。
11
+ */
12
+
13
+ export const name = 'dsh-token-diet'
14
+
15
+ const TICK_MS = 3000
16
+ const CACHE_MS = 900
17
+ // @deepseek-ai/dsh-compaction-tool-result-pruner 的默认 thresholdChars。
18
+ const PRUNE_CHARS = 8192
19
+ const MAX_TOOLS = 6
20
+ const MAX_NOTES = 8
21
+
22
+ /** 最近一次渲染用的语言;面板动作拿不到 caps,用它复制报告。 */
23
+ let lastZh = true
24
+
25
+ /** 从宿主取服务;没注册或取不到都返回 undefined。 */
26
+ function service(ctx, key) {
27
+ try {
28
+ return typeof ctx.get === 'function' ? ctx.get(key, false) : undefined
29
+ } catch {
30
+ return undefined
31
+ }
32
+ }
33
+
34
+ function num(value) {
35
+ return typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : 0
36
+ }
37
+
38
+ /** 按码点算长度,中文一个字就是一,跟 "字" 的说法对得上。 */
39
+ function cpLength(text) {
40
+ if (typeof text !== 'string' || text === '') return 0
41
+ let count = 0
42
+ for (const _ of text) count += 1
43
+ return count
44
+ }
45
+
46
+ function emptyReport() {
47
+ return {
48
+ toolChars: 0,
49
+ toolCount: 0,
50
+ bigCount: 0,
51
+ tools: [],
52
+ input: 0,
53
+ cacheRead: 0,
54
+ cacheWrite: 0,
55
+ output: 0,
56
+ requests: 0,
57
+ contextWindow: null,
58
+ lastPrompt: null,
59
+ turns: [],
60
+ }
61
+ }
62
+
63
+ /** 一条工具结果里所有文本块的字数。 */
64
+ /** 工具结果里指向调用 id 的字段:不同版本分别放在 message.callId / toolCallId / source.callId。 */
65
+ function nameOfCall(message, callNames) {
66
+ const ids = [message.callId, message.toolCallId, message.source && message.source.callId]
67
+ for (const id of ids) {
68
+ if (typeof id === 'string' && callNames.has(id)) return callNames.get(id)
69
+ }
70
+ return undefined
71
+ }
72
+
73
+ function textChars(content) {
74
+ if (!Array.isArray(content)) return 0
75
+ let chars = 0
76
+ for (const block of content) {
77
+ if (block && block.type === 'text' && typeof block.text === 'string') chars += cpLength(block.text)
78
+ }
79
+ return chars
80
+ }
81
+
82
+ function streamUsage(stream) {
83
+ if (!Array.isArray(stream)) return undefined
84
+ let usage
85
+ for (const item of stream) {
86
+ const chunk = item && item.chunk
87
+ if (chunk && chunk.type === 'usage' && chunk.usage) usage = chunk.usage
88
+ }
89
+ return usage
90
+ }
91
+
92
+ /**
93
+ * 折叠一个会话的事件流。不会抛:脏事件直接跳过,面板不能因为一条怪日志整块空掉。
94
+ * 用量按 (turn, step) 去重——重试会在同一 step 上再写一条,以最后一条为准。
95
+ */
96
+ function foldSession(session) {
97
+ const report = emptyReport()
98
+ if (!session || typeof session.snapshotEvents !== 'function') return report
99
+ let events
100
+ try {
101
+ events = session.snapshotEvents()
102
+ } catch {
103
+ return report
104
+ }
105
+ if (!Array.isArray(events)) return report
106
+
107
+ const callNames = new Map()
108
+ const perTool = new Map()
109
+ const perStep = new Map()
110
+ let lastKey
111
+
112
+ for (const event of events) {
113
+ if (!event || typeof event !== 'object') continue
114
+ const data = event.data ?? {}
115
+ try {
116
+ if (event.type === 'tool/call') {
117
+ if (typeof data.callId === 'string' && typeof data.name === 'string') callNames.set(data.callId, data.name)
118
+ continue
119
+ }
120
+ if (event.type === 'tool/result') {
121
+ const message = data.message ?? {}
122
+ const chars = textChars(message.content)
123
+ const tool = nameOfCall(message, callNames) ?? 'other'
124
+ const entry = perTool.get(tool) ?? { name: tool, chars: 0, count: 0 }
125
+ entry.chars += chars
126
+ entry.count += 1
127
+ perTool.set(tool, entry)
128
+ report.toolChars += chars
129
+ report.toolCount += 1
130
+ if (chars >= PRUNE_CHARS) report.bigCount += 1
131
+ continue
132
+ }
133
+ if (event.type === 'request/context') {
134
+ const window = num(data.contextWindow)
135
+ if (window > 0) report.contextWindow = window
136
+ continue
137
+ }
138
+ if (event.type === 'assistant/message' || event.type === 'assistant/chunk' || event.type === 'assistant/attempt') {
139
+ const usage = event.type === 'assistant/chunk'
140
+ ? (data.chunk && data.chunk.type === 'usage' ? data.chunk.usage : undefined)
141
+ : (data.usage ?? streamUsage(data.stream))
142
+ if (!usage) continue
143
+ const turn = data.turn
144
+ const step = data.step
145
+ if (!Number.isInteger(turn) || !Number.isInteger(step)) continue
146
+ const key = turn + ':' + step
147
+ perStep.set(key, {
148
+ turn,
149
+ input: num(usage.inputTokens ?? usage.uncachedInputTokens),
150
+ cacheRead: num(usage.cacheReadTokens),
151
+ cacheWrite: num(usage.cacheWriteTokens),
152
+ output: num(usage.outputTokens),
153
+ })
154
+ lastKey = key
155
+ }
156
+ } catch {
157
+ // 单条事件坏了不影响整份报告。
158
+ }
159
+ }
160
+
161
+ const byTurn = new Map()
162
+ for (const sample of perStep.values()) {
163
+ report.input += sample.input
164
+ report.cacheRead += sample.cacheRead
165
+ report.cacheWrite += sample.cacheWrite
166
+ report.output += sample.output
167
+ report.requests += 1
168
+ const turn = byTurn.get(sample.turn) ?? { turn: sample.turn, input: 0, output: 0 }
169
+ turn.input += sample.input + sample.cacheRead + sample.cacheWrite
170
+ turn.output += sample.output
171
+ byTurn.set(sample.turn, turn)
172
+ }
173
+ report.turns = [...byTurn.values()].sort((a, b) => a.turn - b.turn)
174
+
175
+ if (lastKey !== undefined) {
176
+ const sample = perStep.get(lastKey)
177
+ report.lastPrompt = sample.input + sample.cacheRead + sample.cacheWrite
178
+ }
179
+
180
+ report.tools = [...perTool.values()].sort((a, b) => b.chars - a.chars).slice(0, MAX_TOOLS)
181
+ return report
182
+ }
183
+
184
+ const cache = { sessionId: null, at: 0, value: null }
185
+
186
+ function reportFor(ctx, sessionId) {
187
+ if (typeof sessionId !== 'string' || sessionId === '') return emptyReport()
188
+ const now = Date.now()
189
+ if (cache.sessionId === sessionId && cache.value && now - cache.at < CACHE_MS) return cache.value
190
+ const sessions = service(ctx, 'sessions')
191
+ let session
192
+ try {
193
+ session = sessions && typeof sessions.get === 'function' ? sessions.get(sessionId) : undefined
194
+ } catch {
195
+ session = undefined
196
+ }
197
+ const value = foldSession(session)
198
+ cache.sessionId = sessionId
199
+ cache.at = now
200
+ cache.value = value
201
+ return value
202
+ }
203
+
204
+ function trimZero(text) {
205
+ return text.replace(/\.0$/, '')
206
+ }
207
+
208
+ function fmtBig(value) {
209
+ const v = typeof value === 'number' && Number.isFinite(value) ? Math.max(0, value) : 0
210
+ if (v >= 1e6) return trimZero((v / 1e6).toFixed(v >= 1e7 ? 0 : 1)) + 'M'
211
+ if (v >= 1e3) return trimZero((v / 1e3).toFixed(v >= 1e4 ? 0 : 1)) + 'K'
212
+ return String(Math.round(v))
213
+ }
214
+
215
+ function pctValue(value) {
216
+ if (typeof value !== 'number' || !Number.isFinite(value)) return null
217
+ return Math.min(100, Math.max(0, value))
218
+ }
219
+
220
+ function pctText(value) {
221
+ const pct = pctValue(value)
222
+ if (pct === null) return '—'
223
+ return (pct >= 10 ? String(Math.round(pct)) : pct.toFixed(1)) + '%'
224
+ }
225
+
226
+ function toneFor(pct, bigCount) {
227
+ if (pct !== null && pct >= 85) return 'bad'
228
+ if (pct !== null && pct >= 60) return 'warn'
229
+ if (bigCount > 0) return 'warn'
230
+ return 'good'
231
+ }
232
+
233
+ function dataFor(report, zh) {
234
+ const pct = report.contextWindow && report.lastPrompt !== null
235
+ ? (report.lastPrompt / report.contextWindow) * 100
236
+ : null
237
+ const clamped = pctValue(pct)
238
+ const promptBase = report.input + report.cacheRead + report.cacheWrite
239
+ const hit = promptBase > 0 ? (report.cacheRead / promptBase) * 100 : null
240
+ const tone = toneFor(clamped, report.bigCount)
241
+
242
+ const ctxText = report.lastPrompt !== null && report.contextWindow
243
+ ? fmtBig(report.lastPrompt) + ' / ' + fmtBig(report.contextWindow) + (hit === null ? '' : (zh ? ' · 命中 ' + Math.round(hit) + '%' : ' · hit ' + Math.round(hit) + '%'))
244
+ : (zh ? '还没有请求' : 'No request yet')
245
+
246
+ const rows = []
247
+ const total = report.toolChars
248
+ for (const tool of report.tools) {
249
+ const share = total > 0 ? Math.round((tool.chars / total) * 100) : 0
250
+ rows.push([tool.name, fmtBig(tool.chars), share + '%'])
251
+ }
252
+ if (rows.length === 0) rows.push([zh ? '(暂无工具输出)' : '(no tool output yet)', '—', '—'])
253
+
254
+ const kv = [
255
+ [zh ? '最近一次输入' : 'Last prompt', report.lastPrompt === null ? '—' : fmtBig(report.lastPrompt) + ' tok'],
256
+ [zh ? '缓存读取' : 'Cache read', fmtBig(report.cacheRead) + ' tok'],
257
+ [zh ? '模型输出' : 'Output', fmtBig(report.output) + ' tok'],
258
+ [zh ? '计费请求' : 'Requests', fmtBig(report.requests) + (zh ? ' 次' : '')],
259
+ ]
260
+
261
+ const top = report.tools[0]
262
+ const topShare = top && total > 0 ? Math.round((top.chars / total) * 100) : 0
263
+ let advice
264
+ let adviceTone = 'info'
265
+ if (clamped !== null && clamped >= 80) {
266
+ advice = zh
267
+ ? '上下文已到 ' + Math.round(clamped) + '%,点「压缩」把请求填进输入框再发送。'
268
+ : 'Context at ' + Math.round(clamped) + '%, tap “Compact” to put the request in the composer.'
269
+ adviceTone = 'warn'
270
+ } else if (report.bigCount > 0) {
271
+ advice = zh
272
+ ? '有 ' + report.bigCount + ' 条工具输出超过 8192 字,压缩时会被自动瘦身。'
273
+ : report.bigCount + ' tool result(s) exceed 8192 chars; compaction will prune them.'
274
+ adviceTone = 'warn'
275
+ } else if (top && topShare >= 50) {
276
+ advice = zh
277
+ ? '「' + top.name + '」占了 ' + topShare + '% 的工具输出,试试把多条命令合成一次。'
278
+ : '“' + top.name + '” is ' + topShare + '% of tool output; batch commands into one call.'
279
+ adviceTone = 'info'
280
+ } else {
281
+ advice = zh
282
+ ? '目前很干净;工具输出超过 8192 字时,压缩会自动瘦身。'
283
+ : 'All clean; compaction prunes tool results over 8192 chars.'
284
+ adviceTone = 'good'
285
+ }
286
+
287
+ return {
288
+ pct: clamped === null ? 0 : Math.round(clamped * 10) / 10,
289
+ ctxText,
290
+ ctxTone: tone,
291
+ toolText: fmtBig(report.toolChars) + (zh ? ' 字' : ' chars'),
292
+ toolCaption: report.toolCount === 0
293
+ ? (zh ? '还没有工具输出' : 'No tool output yet')
294
+ : report.toolCount + (zh ? ' 条 · 约 ' : ' calls · ~') + fmtBig(Math.round(report.toolChars / 3)) + ' tok',
295
+ bigText: String(report.bigCount),
296
+ bigTone: report.bigCount > 0 ? 'warn' : 'good',
297
+ rows,
298
+ kv,
299
+ advice,
300
+ adviceTone,
301
+ }
302
+ }
303
+
304
+ function stripFor(report, zh) {
305
+ const pct = report.contextWindow && report.lastPrompt !== null
306
+ ? (report.lastPrompt / report.contextWindow) * 100
307
+ : null
308
+ let text
309
+ if (pct !== null) {
310
+ text = (zh ? '上下文 ' : 'ctx ') + pctText(pct)
311
+ } else if (report.toolCount > 0) {
312
+ text = (zh ? '工具 ' : 'tools ') + fmtBig(report.toolChars) + (zh ? '字' : 'c')
313
+ } else {
314
+ text = zh ? '暂无数据' : 'No data yet'
315
+ }
316
+ return { text: text.slice(0, 24), tone: toneFor(pctValue(pct), report.bigCount) }
317
+ }
318
+
319
+ function noteText(turn, zh) {
320
+ return ((zh ? '入 ' : 'in ') + fmtBig(turn.input) + (zh ? ' · 出 ' : ' · out ') + fmtBig(turn.output)).slice(0, 16)
321
+ }
322
+
323
+ function reportText(report, zh) {
324
+ const data = dataFor(report, zh)
325
+ const lines = [
326
+ zh ? 'Token 瘦身报告' : 'Token diet report',
327
+ (zh ? '上下文:' : 'Context: ') + data.ctxText,
328
+ (zh ? '工具输出:' : 'Tool output: ') + data.toolText + (zh ? ',' + report.toolCount + ' 条' : ', ' + report.toolCount + ' results'),
329
+ ]
330
+ for (const tool of report.tools) {
331
+ const share = report.toolChars > 0 ? Math.round((tool.chars / report.toolChars) * 100) : 0
332
+ lines.push('· ' + tool.name + ': ' + fmtBig(tool.chars) + (zh ? ' 字(' + share + '%)' : ' chars (' + share + '%)'))
333
+ }
334
+ lines.push((zh ? '建议:' : 'Advice: ') + data.advice)
335
+ return lines.join('\n')
336
+ }
337
+
338
+ function zhOf(caps) {
339
+ const locale = caps && typeof caps.locale === 'string' ? caps.locale.toLowerCase() : ''
340
+ return locale.startsWith('zh')
341
+ }
342
+
343
+ function panelView(zh) {
344
+ const t = (zhText, enText) => (zh ? zhText : enText)
345
+ return {
346
+ type: 'stack',
347
+ children: [
348
+ {
349
+ type: 'progress',
350
+ label: t('上下文占用', 'Context used'),
351
+ value: { $: 'data.pct' },
352
+ max: 100,
353
+ caption: { $: 'data.ctxText' },
354
+ tone: { $: 'data.ctxTone' },
355
+ },
356
+ {
357
+ type: 'row',
358
+ children: [
359
+ {
360
+ type: 'metric',
361
+ label: t('工具输出', 'Tool output'),
362
+ value: { $: 'data.toolText' },
363
+ caption: { $: 'data.toolCaption' },
364
+ },
365
+ {
366
+ type: 'metric',
367
+ label: t('超 8K 条目', 'Over 8K'),
368
+ value: { $: 'data.bigText' },
369
+ tone: { $: 'data.bigTone' },
370
+ caption: t('压缩时自动瘦身', 'pruned on compact'),
371
+ },
372
+ ],
373
+ },
374
+ {
375
+ type: 'table',
376
+ columns: t(['工具', '输出', '占比'], ['Tool', 'Chars', 'Share']),
377
+ rows: { $: 'data.rows' },
378
+ },
379
+ { type: 'keyValue', items: { $: 'data.kv' } },
380
+ { type: 'callout', text: { $: 'data.advice' }, tone: { $: 'data.adviceTone' } },
381
+ {
382
+ type: 'actions',
383
+ items: [
384
+ { label: t('压缩', 'Compact'), action: 'compact', icon: 'archive', style: 'primary' },
385
+ { label: t('复制报告', 'Copy report'), action: 'copy', icon: 'copy' },
386
+ ],
387
+ },
388
+ ],
389
+ }
390
+ }
391
+
392
+ export function apply(ctx) {
393
+ ctx.inject(['dshGo'], (ctx) => {
394
+ const dshGo = ctx.dshGo
395
+
396
+ // 胶囊:上下文占用百分比(没法开面板时不至于空白)。
397
+ dshGo.strip('diet-strip', (scope, emit, caps) => {
398
+ const zh = zhOf(caps)
399
+ const push = () => {
400
+ const strip = stripFor(reportFor(ctx, scope.sessionId), zh)
401
+ emit({ text: strip.text, icon: 'chart', tone: strip.tone })
402
+ }
403
+ push()
404
+ const timer = setInterval(push, TICK_MS)
405
+ return () => clearInterval(timer)
406
+ })
407
+
408
+ // 面板:进度条 + 工具排行 + 用量 + 两条动作。
409
+ dshGo.panel('diet', {
410
+ view: (scope, caps) => {
411
+ const zh = zhOf(caps)
412
+ lastZh = zh
413
+ return panelView(zh)
414
+ },
415
+ data: (scope, emit, caps) => {
416
+ const zh = zhOf(caps)
417
+ lastZh = zh
418
+ const push = () => emit(dataFor(reportFor(ctx, scope.sessionId), zh))
419
+ push()
420
+ const timer = setInterval(push, TICK_MS)
421
+ return () => clearInterval(timer)
422
+ },
423
+ actions: {
424
+ compact: () => ({
425
+ insert: lastZh
426
+ ? '帮我把上下文压缩一下:先看 acp_status 里还能压的区间,再用 compress 把最旧的能压区间压掉。'
427
+ : 'Compact my context: check acp_status for open ranges, then compress the oldest foldable one.',
428
+ toast: lastZh ? '已填进输入框,点发送即可' : 'Filled into the composer — tap send',
429
+ }),
430
+ copy: (scope) => ({
431
+ copy: reportText(reportFor(ctx, scope.sessionId), lastZh),
432
+ toast: lastZh ? '报告已复制' : 'Report copied',
433
+ }),
434
+ },
435
+ })
436
+
437
+ // 回合脚注:最近几个回合的入/出 token。
438
+ dshGo.turnNote('diet-note', (scope, emit, caps) => {
439
+ const zh = zhOf(caps)
440
+ const push = () => {
441
+ const report = reportFor(ctx, scope.sessionId)
442
+ const notes = {}
443
+ for (const turn of report.turns.slice(-MAX_NOTES)) {
444
+ notes[String(turn.turn)] = { text: noteText(turn, zh), tone: 'info' }
445
+ }
446
+ emit(notes)
447
+ }
448
+ push()
449
+ const timer = setInterval(push, TICK_MS)
450
+ return () => clearInterval(timer)
451
+ })
452
+ })
453
+ }
454
+
455
+ export default apply
package/package.json CHANGED
@@ -1,6 +1,79 @@
1
1
  {
2
2
  "name": "dsh-go-token-diet",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.1.1",
4
+ "description": "Token diet for dsh-go: see which tool results and turns are eating your context, then hand a compaction request to the agent with one tap.",
5
+ "type": "module",
6
+ "main": "lib/index.js",
7
+ "dsh": {
8
+ "bundle": {
9
+ "patch": "./cordis.patch.yml"
10
+ }
11
+ },
12
+ "engines": {
13
+ "dsh": ">=0.2.1-rc.2 <0.3.0-0"
14
+ },
15
+ "dshGo": {
16
+ "v": 1,
17
+ "title": {
18
+ "zh": "Token 瘦身",
19
+ "en": "Token Diet"
20
+ },
21
+ "icon": "chart",
22
+ "wants": [],
23
+ "contributes": {
24
+ "composer.strip": [
25
+ {
26
+ "id": "diet-strip",
27
+ "icon": "chart",
28
+ "panel": "diet"
29
+ }
30
+ ],
31
+ "panels": [
32
+ {
33
+ "id": "diet",
34
+ "title": {
35
+ "zh": "Token 瘦身",
36
+ "en": "Token Diet"
37
+ },
38
+ "icon": "chart",
39
+ "placement": [
40
+ "session.tab",
41
+ "features",
42
+ "chat.panel"
43
+ ]
44
+ }
45
+ ],
46
+ "turn.note": [
47
+ {
48
+ "id": "diet-note"
49
+ }
50
+ ]
51
+ }
52
+ },
53
+ "files": [
54
+ "lib/index.js",
55
+ "cordis.patch.yml",
56
+ "README.md",
57
+ "LICENSE"
58
+ ],
59
+ "keywords": [
60
+ "dsh-go",
61
+ "dsh",
62
+ "deepseek-harness",
63
+ "plugin",
64
+ "token",
65
+ "context",
66
+ "compaction",
67
+ "android"
68
+ ],
69
+ "license": "MIT",
70
+ "repository": {
71
+ "type": "git",
72
+ "url": "git+https://github.com/wangtianyi00001-pixel/dsh-go-token-diet.git"
73
+ },
74
+ "homepage": "https://github.com/wangtianyi00001-pixel/dsh-go-token-diet#readme",
75
+ "bugs": {
76
+ "url": "https://github.com/wangtianyi00001-pixel/dsh-go-token-diet/issues"
77
+ },
78
+ "author": "wangtianyi00001-pixel"
79
+ }