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 +2 -0
- package/lib/index.js +5 -2
- package/package.json +1 -1
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
|
|
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
|
|
142
|
+
statsOf(statsKeyOf(exec)).restores += 1
|
|
140
143
|
return { text: slice.text }
|
|
141
144
|
},
|
|
142
145
|
})
|