dsh-go-caveman 0.0.0-stage → 0.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 wangtianyi00001-pixel
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,59 @@
1
- # Temporary Holding Version
1
+ # 🐒 dsh-go-caveman
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
+ > **0.1.1** 🛠️ 修复:状态条/面板的统计键用 `agent.id` 记账、却按 `sessionId` 读取,导致永远显示 0;现在统一用 `exec.agent.session.id`。
4
+
5
+ > 🪨 **出处**:[JuliusBrussee/caveman](https://github.com/JuliusBrussee/caveman) —— *"why many token when few do trick"*。
6
+ > 本插件按 DSH 的插件接口重写,**不是代理**,也没有复制它的 Go 实现;灵感、规则结构、两块石头的划分都来自它。
7
+
8
+ **让 agent 说少 🗣️、读少 📉。** 两块石头:
9
+
10
+ - 💬 **说少**:往系统提示加一段表达规则——先结论、一句一个意思、代码和报错原样、否定词不省、该长的地方(安全提醒、不可逆操作)长。
11
+ - 🗜️ **读少**:工具结果进上下文前折叠——保开头、保结尾、把散落在中间的错误行捞出来;**原文落盘** 🔁,模型用 `caveman_restore` 按需取回。
12
+
13
+ ## ✨ 它怎么工作
14
+
15
+ ```
16
+ bash 输出 400 行 📜
17
+ ↓ fold(确定性,不调模型,零依赖)
18
+ 开头 28 行 + 中间的错误行 + 结尾 12 行
19
+ …[caveman 折叠 360 行 / 18.3k 字符;原文:caveman_restore("1cfb57fe")]…
20
+ ↓
21
+ 模型看到的是缩过的版本;要全文就调 caveman_restore 🔁
22
+ ```
23
+
24
+ 折叠只做三件事,都可预测:**保头尾 🎯、捞错误行 🚨、跳过不该折的 🚫**(`read`、恢复工具、短结果、已经折过的)。折叠出错就放行原文——它是优化,不是功能依赖。
25
+
26
+ ## 📦 装
27
+
28
+ ```sh
29
+ cp -r dsh-go-caveman "$DSH_HOME/dsh-go/plugins/dsh-go-caveman"
30
+ dsh plugin --profile web add "$DSH_HOME/dsh-go/plugins/dsh-go-caveman"
31
+ ```
32
+
33
+ 装完重启一次引擎(⚙️ 设置 → 引擎 → 重启引擎)。改 `lib/` 后同样要重启。
34
+
35
+ ## 📱 在手机上
36
+
37
+ - 输入框上方一条 `🐒 省 90% · 1 次`:本次会话折叠了多少
38
+ - 点开面板 📊:折叠次数 / 省下的比例 / 取回次数 / 最近折叠的 5 条(工具名 + 折叠前后字符数)
39
+
40
+ ## ⚙️ 配置
41
+
42
+ | 🔧 键 | 默认 | 说明 |
43
+ |---|---|---|
44
+ | `voice` | `true` | 是否注入表达规则 💬 |
45
+ | `fold` | `true` | 是否折叠工具输出 🗜️ |
46
+ | `thresholdChars` | `2400` | 超过多少字符才折 |
47
+ | `headLines` / `tailLines` | `28` / `12` | 保留的开头 / 结尾行数 |
48
+ | `maxKeptErrorLines` | `24` | 中间最多保留多少条错误行 🚨 |
49
+
50
+ ## ⚠️ 和上游的差别(诚实说)
51
+
52
+ - 上游 5.0 的 **trim-2** 是一个 3.6 MB 本地模型 🧠,会读你的问题、只留相关行;这里是**确定性的行级折叠**,不读问题,收益比它小,但可预测、零依赖。
53
+ - 上游还有 Auto(挑模型)、Blocks、Browse 🌐,这些不做。
54
+ - 本机已有官方的 `dsh-spill-policy`(按 token 预算保留头尾 + 给恢复文件路径)。本插件与它互补:官方那个是「截断并给路径」,这里是「按行挑重点 + 一个 restore 工具」;两者同时开时,已经折过的结果不会被再折。
55
+ - 原文缓存在 `$DSH_HOME/cache/dsh-caveman/`,单条上限 5 MB;缓存随时可删 🧹。
56
+
57
+ ## 📄 License
58
+
59
+ MIT。灵感与规则结构来自 Apache-2.0 的 [caveman](https://github.com/JuliusBrussee/caveman)。
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: dsh-caveman
3
+ name: dsh-go-caveman
package/lib/fold.js ADDED
@@ -0,0 +1,105 @@
1
+ /**
2
+ * 确定性折叠:不调模型,只看行。
3
+ *
4
+ * 目标不是「把输出变小」这么简单——是把**模型不需要的行**去掉,同时保住三类东西:
5
+ * 1) 开头(命令/请求的上下文)
6
+ * 2) 结尾(结果/退出状态)
7
+ * 3) 错误行(散落在中间的那几条,往往才是答案)
8
+ *
9
+ * 原文不丢:调用方先把整段存到磁盘,再把 id 交给这里,模型可以用
10
+ * caveman_restore 按需取回。
11
+ */
12
+
13
+ export const DEFAULTS = Object.freeze({
14
+ /** 低于这个字符数不折:小结果折了反而亏。 */
15
+ thresholdChars: 2400,
16
+ /** 保留开头多少行。 */
17
+ headLines: 28,
18
+ /** 保留结尾多少行。 */
19
+ tailLines: 12,
20
+ /** 中间最多保留多少条错误行。 */
21
+ maxKeptErrorLines: 24,
22
+ /** 单次 restore 最多返回多少字符。 */
23
+ maxRestoreChars: 40_000,
24
+ })
25
+
26
+ /** 这些工具的输出不折:模型明确要看全文,或者折叠会破坏结构。 */
27
+ const SKIP_TOOLS = new Set(['read', 'caveman_restore', 'present', 'write', 'edit', 'apply_patch', 'applyPatch'])
28
+
29
+ const ERROR_RE = /(error|exception|failed|failure|fatal|panic|traceback|denied|refused|timed? ?out|not found|✗|错误|失败|异常|拒绝|超时)/i
30
+
31
+ /** 折叠标记:也用来避免对同一段结果重复折叠。 */
32
+ export const FOLD_MARK = 'caveman 折叠'
33
+
34
+ export function isFoldableTool(name) {
35
+ return !SKIP_TOOLS.has(String(name ?? ''))
36
+ }
37
+
38
+ export function shouldFoldText(text, options = {}) {
39
+ const cfg = { ...DEFAULTS, ...options }
40
+ if (typeof text !== 'string' || text.length <= cfg.thresholdChars) return false
41
+ if (text.includes(FOLD_MARK)) return false
42
+ return true
43
+ }
44
+
45
+ function fmtCount(n) {
46
+ if (n >= 1e6) return `${(n / 1e6).toFixed(1)}m`
47
+ if (n >= 1e4) return `${(n / 1e3).toFixed(1)}k`
48
+ return String(n)
49
+ }
50
+
51
+ /**
52
+ * 折叠一段文本。
53
+ * @returns {{ text: string, folded: boolean, removedLines: number, removedChars: number, keptErrorLines: number }}
54
+ */
55
+ export function foldText(text, id, options = {}) {
56
+ const cfg = { ...DEFAULTS, ...options }
57
+ if (!shouldFoldText(text, cfg)) {
58
+ return { text, folded: false, removedLines: 0, removedChars: 0, keptErrorLines: 0 }
59
+ }
60
+ const lines = text.split('\n')
61
+ const head = lines.slice(0, cfg.headLines)
62
+ const tail = lines.slice(Math.max(cfg.headLines, lines.length - cfg.tailLines))
63
+ const middle = lines.slice(cfg.headLines, Math.max(cfg.headLines, lines.length - cfg.tailLines))
64
+
65
+ const errors = []
66
+ for (const line of middle) {
67
+ if (errors.length >= cfg.maxKeptErrorLines) break
68
+ if (ERROR_RE.test(line)) errors.push(line.trimEnd())
69
+ }
70
+
71
+ const kept = [...head, ...errors, ...tail]
72
+ const keptChars = kept.join('\n').length
73
+ const removedChars = Math.max(0, text.length - keptChars)
74
+ const removedLines = Math.max(0, lines.length - head.length - tail.length - errors.length)
75
+ const marker = `…[${FOLD_MARK} ${removedLines} 行 / ${fmtCount(removedChars)} 字符;原文:caveman_restore("${id}")]…`
76
+
77
+ const body = errors.length
78
+ ? `${head.join('\n')}\n${marker}\n\n…… 中间的错误行(保留了 ${errors.length} 条)……\n${errors.join('\n')}\n……\n${tail.join('\n')}`
79
+ : `${head.join('\n')}\n${marker}\n${tail.join('\n')}`
80
+
81
+ return {
82
+ text: body,
83
+ folded: true,
84
+ removedLines,
85
+ removedChars,
86
+ keptErrorLines: errors.length,
87
+ }
88
+ }
89
+
90
+ /** restore 时的切片;offset/limit 按字符算,超上限就截断并说明。 */
91
+ export function sliceRestore(text, { offset = 0, limit = DEFAULTS.maxRestoreChars } = {}) {
92
+ const start = Number.isFinite(offset) && offset > 0 ? Math.floor(offset) : 0
93
+ const max = Math.min(
94
+ DEFAULTS.maxRestoreChars,
95
+ Number.isFinite(limit) && limit > 0 ? Math.floor(limit) : DEFAULTS.maxRestoreChars,
96
+ )
97
+ const slice = text.slice(start, start + max)
98
+ const more = start + max < text.length
99
+ return {
100
+ text: more ? `${slice}\n…(还有 ${text.length - start - max} 字符;用 offset=${start + max} 继续)` : slice,
101
+ total: text.length,
102
+ offset: start,
103
+ truncated: more,
104
+ }
105
+ }
package/lib/index.js ADDED
@@ -0,0 +1,263 @@
1
+ /**
2
+ * dsh-caveman:让 agent「说少、读少」。
3
+ *
4
+ * 两块石头:
5
+ * 说少 —— 往系统提示里加一段表达规则(先结论、代码原样、否定词不省)。
6
+ * 读少 —— 在工具结果进上下文前折叠:保开头、保结尾、捞中间的错误行,
7
+ * 原文落盘,模型用 caveman_restore 按需取回。
8
+ *
9
+ * 所有折叠都是确定性的行级操作,不调模型;失败一律放行原文,绝不把工具调用弄挂。
10
+ */
11
+ import { DEFAULTS, foldText, isFoldableTool, shouldFoldText, sliceRestore } from './fold.js'
12
+ import { loadOriginal, newId, saveOriginal } from './store.js'
13
+
14
+ export const name = 'dsh-caveman'
15
+
16
+ export const inject = ['tools', 'systemPrompt']
17
+
18
+ export const VOICE = `# 表达风格:能省就省,但不丢信息
19
+ - 先给结论,再给理由。不要寒暄,不要复述我的问题。
20
+ - 一句话一个意思;能用短句就不用长句。
21
+ - 代码、命令、路径、报错原文一字不改地引用。
22
+ - 数字、单位、否定词(不 / 没 / 不要 / 只)绝不省。
23
+ - 安全警告、不可逆操作、我明显困惑时,用完整句子说清楚,之后恢复简短。
24
+ - 如果简写反而更长,就用正常写法。`
25
+
26
+ const DEFAULT_CONFIG = {
27
+ voice: true,
28
+ fold: true,
29
+ thresholdChars: DEFAULTS.thresholdChars,
30
+ headLines: DEFAULTS.headLines,
31
+ tailLines: DEFAULTS.tailLines,
32
+ maxKeptErrorLines: DEFAULTS.maxKeptErrorLines,
33
+ }
34
+
35
+ function fmtCount(n) {
36
+ const v = Number(n) || 0
37
+ if (v >= 1e6) return `${(v / 1e6).toFixed(1)}m`
38
+ if (v >= 1e4) return `${(v / 1e3).toFixed(1)}k`
39
+ return String(Math.round(v))
40
+ }
41
+
42
+ export function apply(ctx, config = {}) {
43
+ const cfg = { ...DEFAULT_CONFIG, ...(config && typeof config === 'object' ? config : {}) }
44
+ const stats = new Map()
45
+
46
+ // 折叠发生在 exec.agent 上,面板拿到的是 scope.sessionId;
47
+ // agent.id 与 session.id 不是一个东西,统计键必须统一用会话 id,否则永远显示 0。
48
+ const statsKeyOf = (exec) => String(exec?.agent?.session?.id ?? exec?.agent?.id ?? '(global)')
49
+ const statsOf = (sessionId) => {
50
+ const key = String(sessionId ?? '(global)')
51
+ let s = stats.get(key)
52
+ if (!s) {
53
+ s = { folds: 0, charsIn: 0, charsOut: 0, restores: 0, recent: [] }
54
+ stats.set(key, s)
55
+ }
56
+ return s
57
+ }
58
+
59
+ const systemPrompt = ctx.systemPrompt ?? (typeof ctx.get === 'function' ? ctx.get('systemPrompt') : undefined)
60
+
61
+ if (cfg.voice) {
62
+ try {
63
+ systemPrompt?.section?.({ name: 'caveman-voice', order: 70, text: VOICE })
64
+ } catch {
65
+ /* 老宿主没有 systemPrompt:说少这块跳过,读少照常 */
66
+ }
67
+ }
68
+
69
+ if (cfg.fold && typeof ctx.on === 'function') {
70
+ ctx.on('tools/post-execute', async (exec, result, next) => {
71
+ const decision = await next()
72
+ try {
73
+ if (decision.kind !== 'accept' || Object.hasOwn(decision, 'value')) return decision
74
+ if (!isFoldableTool(exec?.name)) return decision
75
+ // 默认决策是 { kind:'accept' },正文在 result.content 上;别的监听器也可能已经换过
76
+ const content = decision.content ?? result?.content
77
+ // 找到最长的一段文本;其它块(图片、结构化块)原样保留
78
+ let target = -1
79
+ let longest = 0
80
+ content.forEach((block, index) => {
81
+ if (block?.type === 'text' && typeof block.text === 'string' && block.text.length > longest) {
82
+ longest = block.text.length
83
+ target = index
84
+ }
85
+ })
86
+ if (target < 0 || !shouldFoldText(content[target].text, cfg)) return decision
87
+
88
+ const original = content[target].text
89
+ const id = newId()
90
+ await saveOriginal(id, original)
91
+ const folded = foldText(original, id, cfg)
92
+ if (!folded.folded) return decision
93
+
94
+ const replaced = content.slice()
95
+ replaced[target] = { ...content[target], text: folded.text }
96
+ const s = statsOf(statsKeyOf(exec))
97
+ s.folds += 1
98
+ s.charsIn += original.length
99
+ s.charsOut += folded.text.length
100
+ s.recent.unshift({ id, tool: String(exec?.name ?? 'tool'), before: original.length, after: folded.text.length, at: Date.now() })
101
+ if (s.recent.length > 10) s.recent.length = 10
102
+ return { ...decision, content: replaced }
103
+ } catch {
104
+ // 折叠是优化,不是功能依赖:出错就放行原文
105
+ return decision
106
+ }
107
+ })
108
+ }
109
+
110
+ ctx.tools.register({
111
+ name: 'caveman_restore',
112
+ description:
113
+ '取回一段被 caveman 折叠掉的工具输出原文。工具结果里出现 caveman_restore("id") 时,用这个 id 调它;默认一次最多返回 4 万字符,可用 offset 继续往后读。',
114
+ parameters: {
115
+ type: 'object',
116
+ properties: {
117
+ id: { type: 'string', description: '折叠标记里的 id。' },
118
+ offset: { type: 'integer', minimum: 0, description: '从第几个字符开始读,默认 0。' },
119
+ limit: { type: 'integer', minimum: 200, maximum: 40000, description: '这次最多返回多少字符,默认 40000。' },
120
+ },
121
+ required: ['id'],
122
+ additionalProperties: false,
123
+ },
124
+ output: {
125
+ schema: {
126
+ type: 'object',
127
+ properties: { text: { type: 'string' } },
128
+ required: ['text'],
129
+ additionalProperties: false,
130
+ },
131
+ render(_args, value) {
132
+ return [{ type: 'text', text: typeof value?.text === 'string' ? value.text : '' }]
133
+ },
134
+ },
135
+ async execute(args, exec) {
136
+ const id = String(args?.id ?? '').trim()
137
+ const text = await loadOriginal(id)
138
+ if (text == null) {
139
+ return { text: `找不到这段原文(id=${id || '空'})。可能已经被清理,或 id 写错了。` }
140
+ }
141
+ const slice = sliceRestore(text, { offset: args?.offset, limit: args?.limit })
142
+ statsOf(statsKeyOf(exec)).restores += 1
143
+ return { text: slice.text }
144
+ },
145
+ })
146
+
147
+ /* ---------------- dsh-go:状态条 + 面板 ---------------- */
148
+
149
+ function scopeKeyOf(scope) {
150
+ if (!scope || typeof scope !== 'object') return '(global)'
151
+ const keys = ['callId', 'messageId', 'sessionId', 'turnId'].filter((k) => typeof scope[k] === 'string' && scope[k])
152
+ if (!keys.length) return '(global)'
153
+ return keys
154
+ .sort()
155
+ .map((k) => `${k}=${encodeURIComponent(scope[k])}`)
156
+ .join('&')
157
+ }
158
+
159
+ function statsForScope(scope) {
160
+ return statsOf(scope && typeof scope === 'object' ? scope.sessionId : undefined)
161
+ }
162
+
163
+ function stripTextOf(s) {
164
+ if (!s || !s.folds) return '🐒 还没折叠'
165
+ const saved = s.charsIn > 0 ? Math.round((1 - s.charsOut / s.charsIn) * 100) : 0
166
+ return `🐒 省 ${saved}% · ${s.folds} 次`
167
+ }
168
+
169
+ ctx.inject(['dshGo'], (host) => {
170
+ host.dshGo.strip('caveman-strip', (scope, emit) => {
171
+ let alive = true
172
+ let last = ''
173
+ const push = () => {
174
+ const text = stripTextOf(statsForScope(scope))
175
+ if (!alive || text === last) return
176
+ last = text
177
+ try {
178
+ emit({ text, icon: 'bolt', tone: 'muted' })
179
+ } catch {
180
+ /* 订阅已断开 */
181
+ }
182
+ }
183
+ push()
184
+ const timer = setInterval(push, 20_000)
185
+ timer.unref?.()
186
+ return () => {
187
+ alive = false
188
+ clearInterval(timer)
189
+ }
190
+ })
191
+
192
+ const refreshPanel = (scope) => {
193
+ try {
194
+ host.dshGo.refresh?.('caveman', scope)
195
+ } catch {
196
+ /* 老桥接没有 refresh */
197
+ }
198
+ }
199
+
200
+ host.dshGo.panel('caveman', {
201
+ view: (scope, caps) => {
202
+ const s = statsForScope(scope)
203
+ const zh = !caps?.locale || String(caps.locale).startsWith('zh')
204
+ const saved = s.charsIn > 0 ? Math.round((1 - s.charsOut / s.charsIn) * 100) : 0
205
+ const recent = s.recent.slice(0, 5).map((r) => ({
206
+ title: r.tool,
207
+ subtitle: `${fmtCount(r.before)} → ${fmtCount(r.after)} 字符`,
208
+ trailing: r.id,
209
+ }))
210
+ return {
211
+ v: 2,
212
+ accent: 'app',
213
+ type: 'stack',
214
+ title: zh ? '🐒 caveman' : '🐒 caveman',
215
+ style: { card: 'surface', padding: 'M', gap: 'M' },
216
+ children: [
217
+ {
218
+ type: 'row',
219
+ children: [
220
+ { type: 'metric', label: zh ? '折叠' : 'Folds', value: String(s.folds) },
221
+ { type: 'metric', label: zh ? '省下' : 'Saved', value: `${saved}%`, tone: saved > 0 ? 'good' : undefined },
222
+ { type: 'metric', label: zh ? '取回' : 'Restores', value: String(s.restores) },
223
+ ],
224
+ },
225
+ {
226
+ type: 'text',
227
+ tone: 'muted',
228
+ text: zh
229
+ ? `读少:工具输出超过 ${cfg.thresholdChars} 字符就折叠,原文随时可 caveman_restore。说少:${cfg.voice ? '已开启' : '已关闭'}。`
230
+ : `Read less: outputs over ${cfg.thresholdChars} chars get folded; originals restore on demand. Say less: ${cfg.voice ? 'on' : 'off'}.`,
231
+ },
232
+ ...(recent.length
233
+ ? [{ type: 'list', items: recent }]
234
+ : [{ type: 'text', tone: 'muted', text: zh ? '这一轮还没有折叠过任何输出。' : 'No folds in this session yet.' }]),
235
+ ],
236
+ }
237
+ },
238
+ data: (scope, emit) => {
239
+ const s = statsForScope(scope)
240
+ let alive = true
241
+ const push = () => {
242
+ if (!alive) return
243
+ try {
244
+ emit({ folds: String(s.folds), saved: `${s.charsIn > 0 ? Math.round((1 - s.charsOut / s.charsIn) * 100) : 0}%` })
245
+ } catch {
246
+ /* 订阅已断开 */
247
+ }
248
+ }
249
+ push()
250
+ const timer = setInterval(() => {
251
+ push()
252
+ refreshPanel(scope)
253
+ }, 20_000)
254
+ timer.unref?.()
255
+ return () => {
256
+ alive = false
257
+ clearInterval(timer)
258
+ stats.delete(String(scope?.sessionId ?? '(global)'))
259
+ }
260
+ },
261
+ })
262
+ })
263
+ }
package/lib/store.js ADDED
@@ -0,0 +1,41 @@
1
+ /**
2
+ * 原文仓库:每次折叠前把完整文本落盘,id 交给模型。
3
+ *
4
+ * 只写 $DSH_HOME/cache/dsh-caveman/,文件名是随机 id;读的时候严格校验 id,
5
+ * 避免路径穿越。找不到就返回 null,让工具说人话而不是抛错。
6
+ */
7
+ import { randomBytes } from 'node:crypto'
8
+ import { mkdir, readFile, writeFile } from 'node:fs/promises'
9
+ import os from 'node:os'
10
+ import path from 'node:path'
11
+
12
+ const HOME = process.env.DSH_HOME || path.join(os.homedir(), '.dsh')
13
+ export const CACHE_DIR = path.join(HOME, 'cache', 'dsh-caveman')
14
+ const ID_RE = /^[a-z0-9]{6,32}$/
15
+ const MAX_BYTES = 5 * 1024 * 1024
16
+
17
+ export function newId() {
18
+ return randomBytes(8).toString('hex')
19
+ }
20
+
21
+ export function isValidId(id) {
22
+ return typeof id === 'string' && ID_RE.test(id)
23
+ }
24
+
25
+ export async function saveOriginal(id, text) {
26
+ if (!isValidId(id)) throw new Error('bad id')
27
+ await mkdir(CACHE_DIR, { recursive: true })
28
+ const file = path.join(CACHE_DIR, `${id}.txt`)
29
+ const body = Buffer.byteLength(text, 'utf8') > MAX_BYTES ? text.slice(0, MAX_BYTES) : text
30
+ await writeFile(file, body, 'utf8')
31
+ return file
32
+ }
33
+
34
+ export async function loadOriginal(id) {
35
+ if (!isValidId(id)) return null
36
+ try {
37
+ return await readFile(path.join(CACHE_DIR, `${id}.txt`), 'utf8')
38
+ } catch {
39
+ return null
40
+ }
41
+ }
package/package.json CHANGED
@@ -1,6 +1,81 @@
1
1
  {
2
2
  "name": "dsh-go-caveman",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "main": "lib/index.js",
6
+ "description": "🐒 dsh 插件:让 agent 说少、读少 —— 工具输出折叠 🗜️、原文随时取回 🔁,外加一段更短的表达规则 💬",
7
+ "files": [
8
+ "lib/",
9
+ "cordis.patch.yml",
10
+ "README.md",
11
+ "LICENSE"
12
+ ],
13
+ "scripts": {
14
+ "test": "node --test"
15
+ },
16
+ "keywords": [
17
+ "caveman",
18
+ "context",
19
+ "dsh-go",
20
+ "dsh-plugin",
21
+ "tokens"
22
+ ],
23
+ "license": "MIT",
24
+ "engines": {
25
+ "node": ">=22",
26
+ "dsh": ">=0.2.1-rc.2 <0.3.0-0"
27
+ },
28
+ "dsh": {
29
+ "bundle": {
30
+ "patch": "./cordis.patch.yml"
31
+ }
32
+ },
33
+ "dshGo": {
34
+ "v": 1,
35
+ "title": {
36
+ "zh": "caveman",
37
+ "en": "caveman"
38
+ },
39
+ "icon": "bolt",
40
+ "contributes": {
41
+ "composer.strip": [
42
+ {
43
+ "id": "caveman-strip",
44
+ "icon": "bolt",
45
+ "text": {
46
+ "zh": "caveman",
47
+ "en": "caveman"
48
+ },
49
+ "panel": "caveman"
50
+ }
51
+ ],
52
+ "panels": [
53
+ {
54
+ "id": "caveman",
55
+ "title": {
56
+ "zh": "🐒 caveman",
57
+ "en": "🐒 caveman"
58
+ },
59
+ "icon": "bolt",
60
+ "placement": [
61
+ "session.tab",
62
+ "features",
63
+ "chat.panel"
64
+ ],
65
+ "presentation": "sheet"
66
+ }
67
+ ]
68
+ }
69
+ },
70
+ "repository": {
71
+ "type": "git",
72
+ "url": "git+https://github.com/wangtianyi00001-pixel/dsh-go-caveman.git"
73
+ },
74
+ "homepage": "https://github.com/wangtianyi00001-pixel/dsh-go-caveman#readme",
75
+ "bugs": {
76
+ "url": "https://github.com/wangtianyi00001-pixel/dsh-go-caveman/issues"
77
+ },
78
+ "publishConfig": {
79
+ "access": "public"
80
+ }
81
+ }