dsh-go-caveman 0.1.0 → 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/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # 🐒 dsh-go-caveman
2
2
 
3
+ > **0.1.1** 🛠️ 修复:状态条/面板的统计键用 `agent.id` 记账、却按 `sessionId` 读取,导致永远显示 0;现在统一用 `exec.agent.session.id`。
4
+
3
5
  > 🪨 **出处**:[JuliusBrussee/caveman](https://github.com/JuliusBrussee/caveman) —— *"why many token when few do trick"*。
4
6
  > 本插件按 DSH 的插件接口重写,**不是代理**,也没有复制它的 Go 实现;灵感、规则结构、两块石头的划分都来自它。
5
7
 
package/lib/index.js CHANGED
@@ -43,6 +43,9 @@ export function apply(ctx, config = {}) {
43
43
  const cfg = { ...DEFAULT_CONFIG, ...(config && typeof config === 'object' ? config : {}) }
44
44
  const stats = new Map()
45
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)')
46
49
  const statsOf = (sessionId) => {
47
50
  const key = String(sessionId ?? '(global)')
48
51
  let s = stats.get(key)
@@ -90,7 +93,7 @@ export function apply(ctx, config = {}) {
90
93
 
91
94
  const replaced = content.slice()
92
95
  replaced[target] = { ...content[target], text: folded.text }
93
- const s = statsOf(exec?.agent?.id)
96
+ const s = statsOf(statsKeyOf(exec))
94
97
  s.folds += 1
95
98
  s.charsIn += original.length
96
99
  s.charsOut += folded.text.length
@@ -136,7 +139,7 @@ export function apply(ctx, config = {}) {
136
139
  return { text: `找不到这段原文(id=${id || '空'})。可能已经被清理,或 id 写错了。` }
137
140
  }
138
141
  const slice = sliceRestore(text, { offset: args?.offset, limit: args?.limit })
139
- statsOf(exec?.agent?.id).restores += 1
142
+ statsOf(statsKeyOf(exec)).restores += 1
140
143
  return { text: slice.text }
141
144
  },
142
145
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-go-caveman",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "description": "🐒 dsh 插件:让 agent 说少、读少 —— 工具输出折叠 🗜️、原文随时取回 🔁,外加一段更短的表达规则 💬",