dsh-worldbook 0.0.0-stage → 0.1.0

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-worldbook 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,350 @@
1
- # Temporary Holding Version
1
+ # dsh-worldbook
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
+ 给 **DeepSeek Harness** 与 **dsh-go** 用的 SillyTavern 兼容世界书(World Info / Lorebook)插件。
4
+
5
+ - 直接读取 SillyTavern 导出的世界书 JSON,不需要转换。
6
+ - 关键词触发、正则键、二级键四种逻辑、包含组、概率、预算、递归、最小激活、sticky / cooldown / delay、outlet,全部按 SillyTavern 语义实现。
7
+ - 激活内容作为**动态 system prompt section** 注入,不写入聊天历史,不会越积越多,压缩(`/compact`)之后仍然有效。
8
+ - 注册 `/worldbook` 命令与 `worldbook_search` 工具;dsh-go 另带原生状态条和面板。
9
+
10
+ ---
11
+
12
+ ## 1. 安装
13
+
14
+ ### Desktop(`tauri` profile)
15
+
16
+ ```bash
17
+ "C:/Users/jayma/AppData/Local/deepseek-harness/bin/dsh.cmd" plugin --profile tauri add dsh-worldbook@0.1.0
18
+ ```
19
+
20
+ 本地 tgz:
21
+
22
+ ```bash
23
+ "C:/Users/jayma/AppData/Local/deepseek-harness/bin/dsh.cmd" plugin --profile tauri add ./dsh-worldbook-0.1.0.tgz
24
+ ```
25
+
26
+ > Desktop 不要用 `file:` / 目录链接安装:`ensure_internal_plugins` 会把它们当成 orphan 清掉。用 npm、git 或 HTTP tarball。
27
+
28
+ ### dsh-go(本机引擎,`web` profile)
29
+
30
+ ```bash
31
+ dsh plugin --profile web add dsh-worldbook@0.1.0
32
+ ```
33
+
34
+ 远程主机模式:在电脑/服务器上装到对应 profile,手机只是客户端。
35
+
36
+ ### dsh-go 原生状态条与面板(可选)
37
+
38
+ `dsh-go/` 是一个独立的小插件,读取主插件提供的 `worldbook` 服务:
39
+
40
+ ```bash
41
+ # $DSH_HOME 默认 ~/.dsh
42
+ mkdir -p "$DSH_HOME/dsh-go/plugins"
43
+ cp -r node_modules/dsh-worldbook/dsh-go "$DSH_HOME/dsh-go/plugins/local-worldbook"
44
+ dsh plugin --profile web add "$DSH_HOME/dsh-go/plugins/local-worldbook"
45
+ ```
46
+
47
+ 装好后在 dsh-go:
48
+
49
+ - 输入框上方出现 `世界书 N` 状态条,点开进入面板;
50
+ - 面板显示本会话激活条数、预算、启用书目,提供“重新加载”和“会话开关”;
51
+ - 设置页仍用 dsh-go 原生插件设置页编辑 volatile 配置。
52
+
53
+ > 原生插件是目录链接安装,目录不能删。`package.json` / 清单改动会自动重读;`lib/` 改动需要重启引擎。
54
+
55
+ ---
56
+
57
+ ## 2. 世界书放在哪
58
+
59
+ 默认目录:`$DSH_HOME/worldbooks`(Windows 即 `C:\Users\<你>\.dsh\worldbooks`)。
60
+
61
+ 每个 `*.json` 是一个世界书。三种写法都接受:
62
+
63
+ **SillyTavern 导出(直接丢进来即可)**
64
+
65
+ ```json
66
+ {
67
+ "entries": {
68
+ "0": {
69
+ "uid": 0,
70
+ "key": ["dragon", "wyrm"],
71
+ "keysecondary": ["fire"],
72
+ "comment": "Dragons",
73
+ "content": "Dragons live in the northern mountains.",
74
+ "order": 100,
75
+ "position": 0,
76
+ "depth": 4,
77
+ "probability": 100,
78
+ "useProbability": true,
79
+ "selective": true,
80
+ "selectiveLogic": 0,
81
+ "group": "",
82
+ "groupWeight": 100,
83
+ "scanDepth": null,
84
+ "caseSensitive": null,
85
+ "matchWholeWords": null,
86
+ "sticky": 0,
87
+ "cooldown": 0,
88
+ "delay": 0
89
+ }
90
+ }
91
+ }
92
+ ```
93
+
94
+ **条目数组**
95
+
96
+ ```json
97
+ { "name": "lore", "entries": [{ "key": ["dragon"], "content": "..." }] }
98
+ ```
99
+
100
+ **插件自己的名字 + ST 字段**
101
+
102
+ ```json
103
+ {
104
+ "name": "我的世界书",
105
+ "enabled": true,
106
+ "entries": {
107
+ "0": { "keys": ["龙"], "title": "龙", "content": "龙住在北境。" }
108
+ }
109
+ }
110
+ ```
111
+
112
+ 字段别名:`keys`/`key`、`secondaryKeys`/`keysecondary`、`title`/`comment`、`enabled`/`disable`、`insertionOrder`/`order`、`insertionPosition`/`position`。
113
+
114
+ 重新加载:
115
+
116
+ ```text
117
+ /worldbook reload
118
+ ```
119
+
120
+ 插件也会监听目录变化并自动重载(防抖 300ms)。
121
+
122
+ ---
123
+
124
+ ## 3. 命令
125
+
126
+ ```text
127
+ /worldbook 状态概览
128
+ /worldbook list 列出世界书
129
+ /worldbook show <书> 列出条目
130
+ /worldbook search <关键词> 搜索标题、关键词、内容
131
+ /worldbook test <文本> 用文本 + 当前历史试算激活(不写入状态)
132
+ /worldbook use <书|all|none> 本会话启用哪些书(逗号分隔;支持带空格的书名)
133
+ /worldbook outlets 查看 outlet 与对应的 prompt 变量
134
+ /worldbook import <路径> [名称] 导入 SillyTavern JSON
135
+ /worldbook reload 重新加载目录
136
+ /worldbook on | off 会话内临时开关
137
+ ```
138
+
139
+ `/worldbook test` 是排查“为什么没触发”的首选:它会显示激活条数、token 预算和每个条目的位置 / order。
140
+
141
+ ## 4. 工具
142
+
143
+ 模型可调用 `worldbook_search`:
144
+
145
+ ```
146
+ query: 关键词/人名/地名
147
+ book: 可选,限定某本世界书
148
+ limit: 1-20,默认 5
149
+ ```
150
+
151
+ 它按标题、关键词、正文检索**本会话启用的书**,返回完整条目内容。适合“关键词没触发但模型需要设定”的场景,也是世界书的按需检索入口。
152
+
153
+ ---
154
+
155
+ ## 5. 配置
156
+
157
+ Desktop 的 host-only 插件没有 Web 设置表单,改 profile YAML;dsh-go 用原生插件设置页改(所有字段都是 volatile,实时生效)。
158
+
159
+ ```yaml
160
+ # ~/.dsh/profiles/tauri/cordis.patch.yml
161
+ - id: worldbook-settings
162
+ config:
163
+ enabled: true
164
+ worldbookDir: '' # 空 = $DSH_HOME/worldbooks
165
+ activeBooks: [] # 空 = 目录内全部启用的书
166
+ locale: zh # zh | en | auto
167
+ scanDepth: 2
168
+ includeNames: true
169
+ userName: User
170
+ charName: Assistant
171
+ caseSensitive: false
172
+ matchWholeWords: false
173
+ recursive: true
174
+ maxRecursionSteps: 0 # 0 = 不限制
175
+ minActivations: 0
176
+ minActivationsMaxDepth: 0 # 0 = 到历史尽头
177
+ groupScoring: false
178
+ budgetTokens: 2048
179
+ budgetPercent: 0 # >0 时按模型上下文窗口百分比
180
+ budgetCap: 0 # 0 = 不封顶
181
+ contextWindow: 0 # >0 时跳过自动探测
182
+ includeToolResults: false
183
+ toolResultMaxChars: 4000
184
+ includeCheckpoints: true
185
+ includeSubagents: false
186
+ maxScanMessages: 1000
187
+ includeSectionTitle: true
188
+ sectionTitle: '' # 空 = 世界书 / World Info
189
+ macroChar: '' # {{char}} 的替换值,空 = charName
190
+ macroUser: '' # {{user}} 的替换值,空 = userName
191
+ debug: false
192
+ ```
193
+
194
+ 注意:
195
+
196
+ - `minActivations > 0` 与 `maxRecursionSteps > 0` 互斥(与 SillyTavern 一致);同时设置时递归步数会被强制为 0。
197
+ - `budgetPercent > 0` 时优先用 `contextWindow`;没配置就异步读取当前模型上下文窗口,读不到则退回 `budgetTokens`。
198
+ - `locale` 只影响命令 / 面板文案和默认标题,不影响世界书内容。
199
+
200
+ ---
201
+
202
+ ## 6. SillyTavern 语义对照
203
+
204
+ | ST 字段 | 支持 | 说明 |
205
+ |---|---|---|
206
+ | `key`(逗号分隔 / 正则 `/.../flags`) | ✅ | 正则键优先级最高,忽略大小写与整词设置 |
207
+ | `keysecondary` + `selectiveLogic` | ✅ | AND_ANY / NOT_ALL / NOT_ANY / AND_ALL |
208
+ | `constant` / `disable` | ✅ | 蓝圈 / 禁用 |
209
+ | `order` | ✅ | 扫描时大 order 优先;注入时小 order 在前 |
210
+ | `position` | ⚠️ | DSH 没有角色卡/AN/示例消息槽位,映射为四段 system prompt(见下) |
211
+ | `depth` / `role` | ⚠️ | 记录但统一进入 `worldbook:at-depth` 段 |
212
+ | `probability` / `useProbability` | ✅ | sticky 期间不重掷 |
213
+ | `group` / `groupWeight` / `groupOverride` / `useGroupScoring` | ✅ | 多个组用逗号分隔 |
214
+ | `scanDepth` / `caseSensitive` / `matchWholeWords` | ✅ | 每条目可覆盖全局 |
215
+ | `sticky` / `cooldown` / `delay` | ✅ | 进程内按会话消息数计时,重启引擎后清空 |
216
+ | `excludeRecursion` / `preventRecursion` / `delayUntilRecursion` | ✅ | 支持递归层级 |
217
+ | `ignoreBudget` | ✅ | 预算满时仍可注入 |
218
+ | `outletName` | ✅ | 不自动注入,注册为 `{{worldbook_outlet_<slug>}}` |
219
+ | `@@activate` / `@@dont_activate` | ✅ | 内容首行的装饰器 |
220
+ | `{{char}}` / `{{user}}` | ✅ | 用 `charName` / `userName` 或 `macroChar` / `macroUser` 替换 |
221
+ | `vectorized` / 向量检索 | ❌ | 没有嵌入源;仍按关键词工作 |
222
+ | `matchPersonaDescription` 等角色卡字段 | ❌ | DSH 没有角色卡 |
223
+ | `characterFilter` / `triggers` | ❌ | 用“每会话启用书目”代替 |
224
+
225
+ ### 位置映射
226
+
227
+ DSH 的 system prompt 是唯一稳定的“全局设定”通道,所以:
228
+
229
+ | ST position | 常量 | 注入位置 |
230
+ |---|---|---|
231
+ | Before Char Defs | 0 | `worldbook:before`,order -100(persona 之前) |
232
+ | After Char Defs | 1 | `worldbook:after`,order 100(persona 之后) |
233
+ | AN Top / Bottom | 2 / 3 | `worldbook:an-top` / `worldbook:an-bottom`,order 9300 / 9310 |
234
+ | EM Top / Bottom | 5 / 6 | `worldbook:em-top` / `worldbook:em-bottom`,order 9320 / 9330 |
235
+ | @ D | 4 | `worldbook:at-depth`,order 9400 |
236
+ | Outlet | 7 | 不注入,注册 `{{worldbook_outlet_<slug>}}` |
237
+
238
+ outlet 变量可以写进任何支持 prompt 变量的 section,例如预设里的自定义段落:
239
+
240
+ ```text
241
+ {{worldbook_outlet_west}}
242
+ ```
243
+
244
+ `/worldbook outlets` 会列出精确的变量名。
245
+
246
+ ---
247
+
248
+ ## 7. 工作方式(为什么不会写脏历史)
249
+
250
+ 1. **注册动态 system prompt section**:`systemPrompt.section({ order, interpolate: false, text })`,每次组装 prompt 时重新计算。内容变化时 DSH 自己替换 surface 上的 system 节点,不追加消息,也不会被压缩吃掉。
251
+ 2. **`interpolate: false`**:世界书里的任意 `{{...}}` 都不会触发 prompt 变量解析错误。
252
+ 3. **`agent/inbox/claimed` 补位**:agent loop 先取出待处理消息、组装 system prompt,之后才把用户消息写进 session。插件在 claim 事件里缓存这批消息,因此**本轮第一条模型请求就能看到最新用户输入**——这是关键词触发的关键。
253
+ 4. **按会话缓存**:同一 surface 节点数 + 同配置 + 同 pending 只扫描一次;一个 assembly 里 7 个 section 共享结果。
254
+ 5. **每会话书目选择**:持久化在 `$DSH_HOME/worldbook-state.json`,`/worldbook use` 重启后仍生效。
255
+
256
+ ### 扫描输入
257
+
258
+ - 默认只扫 user / assistant 文本;推理块不参与。
259
+ - 可选 `includeToolResults`(工具结果,默认关,避免长输出乱触发)。
260
+ - compact checkpoint 默认参与,保留压缩后的上下文连贯性。
261
+ - 同名消息前缀 `userName:` / `charName:`;`includeNames: false` 可关。
262
+ - 支持 ST 的 `\x01` 消息边界正则。
263
+
264
+ ### 预算
265
+
266
+ - 默认 2048 tokens;`budgetPercent` 可改为模型上下文窗口的百分比。
267
+ - 预算是硬上限:按扫描顺序(order 从大到小)累加,超过后跳过后续条目;`ignoreBudget` 例外。
268
+ - 估算器:CJK 每字符 1 token,其他约 4 字符 1 token。
269
+
270
+ ---
271
+
272
+ ## 8. dsh-go 适配
273
+
274
+ - **免费适配**:插件装在引擎里,dsh-go 只是客户端。`/worldbook` 自动出现在 `/` 面板;设置页可改所有 volatile 字段;注入逻辑与 Desktop 完全一致。
275
+ - **原生 UI**:`dsh-go/` 伴生插件提供状态条与面板(见第 1 节)。
276
+ - **本机 vs 远程**:本机引擎要装到手机的 `web` profile;远程模式在主机上装,手机不用重复装。
277
+ - **`/compact` 不受影响**:世界书走 system prompt,不参与压缩区间。
278
+
279
+ ---
280
+
281
+ ## 9. 已知限制
282
+
283
+ - 没有向量检索 / 嵌入;`vectorized` 条目退回关键词。
284
+ - 没有角色卡、persona lore、chat lore 的概念:用目录 + 每会话 `use` 选择来模拟。
285
+ - 若某个 preset 注册了 `complete` prompt section,DSH 会用该 section 覆盖整个 system prompt,世界书 section 也会被丢掉。遇到“突然不注入”的预设,先检查它是否用了 complete section。
286
+ - `sticky` / `cooldown` / `delay` 的计时状态在内存里,引擎重启后重置;每会话书目选择会持久化。
287
+ - `depth` / `role` 只记录不拆分,全部进入 `worldbook:at-depth` 段。
288
+ - 大型世界书(数千条)每次目录变化会全量重载;建议单本控制在合理规模,或拆成多本按会话启用。
289
+
290
+ ---
291
+
292
+ ## 10. 开发与测试
293
+
294
+ ```bash
295
+ npm test
296
+ npm pack --dry-run
297
+ ```
298
+
299
+ 测试覆盖匹配引擎(键、正则、二级逻辑、深度、预算、递归、组、概率、计时效果、最小激活、outlet)、ST 导入/序列化、会话扫描、渲染、命令和服务缓存。
300
+
301
+ 隔离环境验证:
302
+
303
+ ```bash
304
+ export DSH_HOME=/tmp/dsh-wb-test
305
+ dsh --profile web --dump-config
306
+ dsh plugin --profile web add ./dsh-worldbook-0.1.0.tgz
307
+ dsh --profile web --port 3099
308
+ ```
309
+
310
+ `--dump-config` 应出现:
311
+
312
+ ```yaml
313
+ - id: worldbook-core
314
+ name: dsh-worldbook
315
+ - id: worldbook-settings
316
+ name: dsh-worldbook/settings
317
+ ```
318
+
319
+ ### 升级回归点
320
+
321
+ dsh 升级后重点回归:
322
+
323
+ 1. `system-prompt/assemble` 与 `systemPrompt.section({ interpolate })` 签名;
324
+ 2. `agent/inbox/claimed` 事件与 `agent.session.surface` / `deriveEventMessage`;
325
+ 3. `AgentOptions.subagentDepth` 与 `requestHeader()`;
326
+ 4. dsh-go `dshGo` manifest / panel / strip 协议;
327
+ 5. `systemPrompt.variable` 的命名规则(`[a-z][a-z0-9_]*`)。
328
+
329
+ ---
330
+
331
+ ## 11. 文件结构
332
+
333
+ ```text
334
+ dsh-worldbook/
335
+ ├── package.json
336
+ ├── cordis.patch.yml # worldbook-core + worldbook-settings 两行
337
+ ├── lib/
338
+ │ ├── index.js # 服务、section 注册、claim 缓存、命令/工具接线
339
+ │ ├── settings.js # 全 volatile Config
340
+ │ ├── service.js # 书目录、按会话缓存、预算、计时状态、面板数据
341
+ │ ├── store.js # ST/插件 JSON 解析、导入、会话状态
342
+ │ ├── entry.js # 字段归一化、别名、装饰器、正则键拆分
343
+ │ ├── matcher.js # 纯匹配引擎
344
+ │ ├── scan.js # session surface + pending claim → 扫描消息
345
+ │ ├── render.js # 激活结果 → prompt sections / outlet 变量
346
+ │ ├── commands.js # /worldbook
347
+ │ └── tools.js # worldbook_search
348
+ ├── dsh-go/ # dsh-go 原生伴生插件(local-worldbook)
349
+ └── test/ # node:test,61 项
350
+ ```
@@ -0,0 +1,15 @@
1
+ # dsh-worldbook bundle layer.
2
+ #
3
+ # Mounts:
4
+ # worldbook-core host service `worldbook`: worldbook files, matching engine,
5
+ # prompt assembly hook, `/worldbook` command, `worldbook_search` tool
6
+ # worldbook-settings editable, all-volatile Config (desktop profile YAML / dsh-go plugin settings)
7
+ #
8
+ # No preset inject and no internal/config gate are needed: world info is injected
9
+ # through the global `system-prompt/assemble` waterfall, so it applies to every
10
+ # agent preset without replacing any preset-owned row.
11
+ - insert:
12
+ - id: worldbook-core
13
+ name: 'dsh-worldbook'
14
+ - id: worldbook-settings
15
+ name: 'dsh-worldbook/settings'
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: local-worldbook
3
+ name: 'local-worldbook'
@@ -0,0 +1,147 @@
1
+ /**
2
+ * dsh-go native companion for dsh-worldbook.
3
+ *
4
+ * The App only renders the declared strip and panel; this engine-side plugin
5
+ * reads the `worldbook` service provided by the host plugin. It mounts even
6
+ * without that service so the panel can explain what is missing.
7
+ */
8
+
9
+ export const name = 'local-worldbook'
10
+
11
+ function bookService(ctx) {
12
+ try {
13
+ return ctx.get('worldbook')
14
+ } catch {
15
+ return undefined
16
+ }
17
+ }
18
+
19
+ function zh(caps) {
20
+ return (caps?.locale ?? 'zh').toLowerCase().startsWith('zh')
21
+ }
22
+
23
+ function shortList(names, locale, max = 3) {
24
+ if (names.length === 0) return locale ? '无' : 'none'
25
+ if (names.length <= max) return names.join(locale ? '、' : ', ')
26
+ return locale
27
+ ? `${names.slice(0, max).join('、')} 等 ${names.length} 本`
28
+ : `${names.slice(0, max).join(', ')} +${names.length - max} more`
29
+ }
30
+
31
+ export function apply(ctx) {
32
+ ctx.inject(['dshGo'], (dshCtx) => {
33
+ dshCtx.dshGo.strip('lore', (scope, emit, caps) => {
34
+ const locale = zh(caps)
35
+ const render = () => {
36
+ const service = bookService(dshCtx)
37
+ if (service === undefined) {
38
+ emit({ text: locale ? '世界书未安装' : 'no worldbook', icon: 'book', tone: 'muted' })
39
+ return
40
+ }
41
+ const stats = service.statsForSession(scope.sessionId)
42
+ if (!stats.enabled) {
43
+ emit({ text: locale ? '世界书 关' : 'worldbook off', icon: 'book', tone: 'muted' })
44
+ return
45
+ }
46
+ emit({
47
+ text: stats.budget === 0
48
+ ? (locale ? '世界书 待命' : 'worldbook idle')
49
+ : (locale ? `世界书 ${stats.count}` : `worldbook ${stats.count}`),
50
+ icon: 'book',
51
+ ...stats.overflow ? { tone: 'warn' } : {},
52
+ })
53
+ }
54
+ render()
55
+ const timer = setInterval(render, 3000)
56
+ return () => clearInterval(timer)
57
+ })
58
+
59
+ dshCtx.dshGo.panel('worldbook', {
60
+ view: () => ({
61
+ type: 'stack',
62
+ children: [
63
+ { type: 'metric', label: '本会话激活', value: { $: 'data.count' } },
64
+ { type: 'text', text: { $: 'data.budgetLine' } },
65
+ { type: 'callout', text: { $: 'data.status' }, tone: { $: 'data.statusTone' } },
66
+ {
67
+ type: 'keyValue',
68
+ items: [
69
+ { label: '目录', value: { $: 'data.dir' } },
70
+ { label: '启用', value: { $: 'data.booksLine' } },
71
+ { label: '最近扫描', value: { $: 'data.scanLine' } },
72
+ ],
73
+ },
74
+ {
75
+ type: 'actions',
76
+ items: [
77
+ { label: '重新加载', action: 'reload' },
78
+ { label: '会话开关', action: 'toggle' },
79
+ ],
80
+ },
81
+ ],
82
+ }),
83
+ data: (scope, emit, caps) => {
84
+ const locale = zh(caps)
85
+ const render = () => {
86
+ const service = bookService(dshCtx)
87
+ if (service === undefined) {
88
+ emit({
89
+ count: '—',
90
+ budgetLine: locale ? '未找到宿主机插件 dsh-worldbook' : 'host plugin dsh-worldbook not found',
91
+ status: locale
92
+ ? '请先在引擎的 web profile 中安装 dsh-worldbook,再重启引擎。'
93
+ : 'Install dsh-worldbook into the engine web profile, then restart the engine.',
94
+ statusTone: 'warn',
95
+ dir: '—',
96
+ booksLine: '—',
97
+ scanLine: '—',
98
+ })
99
+ return
100
+ }
101
+ const stats = service.statsForSession(scope.sessionId)
102
+ const books = service.bookList()
103
+ const active = service.resolveSessionBooks(scope.sessionId)
104
+ emit({
105
+ count: stats.budget === 0 ? '—' : String(stats.count),
106
+ budgetLine: stats.budget === 0
107
+ ? (locale ? '尚未发生模型调用' : 'no model call yet')
108
+ : (locale ? `约 ${stats.used} / ${stats.budget} tokens` : `~${stats.used} / ${stats.budget} tokens`),
109
+ status: !stats.enabled
110
+ ? (locale ? '本会话已关闭世界书。' : 'World info is off for this session.')
111
+ : stats.overflow
112
+ ? (locale ? '预算已满,后面的条目未注入。' : 'Budget reached; later entries were not injected.')
113
+ : (locale
114
+ ? `共 ${books.length} 本,本会话启用 ${active.length} 本。`
115
+ : `${books.length} book(s); ${active.length} active in this session.`),
116
+ statusTone: stats.overflow ? 'warn' : 'info',
117
+ dir: service.dir,
118
+ booksLine: shortList(active.map(book => book.name), locale),
119
+ scanLine: stats.budget === 0
120
+ ? (locale ? '尚无扫描' : 'no scan yet')
121
+ : (locale
122
+ ? `${stats.count} 条激活${stats.overflow ? '(预算已满)' : ''}`
123
+ : `${stats.count} active${stats.overflow ? ' (budget reached)' : ''}`),
124
+ })
125
+ }
126
+ render()
127
+ const timer = setInterval(render, 3000)
128
+ return () => clearInterval(timer)
129
+ },
130
+ actions: {
131
+ reload: () => {
132
+ const service = bookService(dshCtx)
133
+ if (service === undefined) return { toast: '世界书插件未安装' }
134
+ const result = service.reload()
135
+ return { toast: `已重载 ${result.books} 本`, refresh: true }
136
+ },
137
+ toggle: (scope) => {
138
+ const service = bookService(dshCtx)
139
+ if (service === undefined) return { toast: '世界书插件未安装' }
140
+ const enabled = service.isEnabledFor(scope.sessionId)
141
+ service.setSessionEnabled(scope.sessionId, !enabled)
142
+ return { toast: enabled ? '本会话已关闭世界书' : '本会话已开启世界书', refresh: true }
143
+ },
144
+ },
145
+ })
146
+ })
147
+ }
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "local-worldbook",
3
+ "version": "0.1.0",
4
+ "description": "dsh-go native UI companion for dsh-worldbook: an input strip with the active entry count and a panel with books, budget, reload and a session toggle.",
5
+ "type": "module",
6
+ "main": "lib/index.js",
7
+ "dsh": {
8
+ "bundle": {
9
+ "patch": "./cordis.patch.yml"
10
+ }
11
+ },
12
+ "dshGo": {
13
+ "v": 1,
14
+ "title": { "zh": "世界书", "en": "World Book" },
15
+ "icon": "book",
16
+ "contributes": {
17
+ "composer.strip": [
18
+ { "id": "lore", "icon": "book", "panel": "worldbook" }
19
+ ],
20
+ "panels": [
21
+ {
22
+ "id": "worldbook",
23
+ "title": { "zh": "世界书", "en": "World Book" },
24
+ "icon": "book",
25
+ "placement": ["session.tab"]
26
+ }
27
+ ]
28
+ }
29
+ }
30
+ }