dsh-subagent-dispatch-control 0.0.0-stage → 1.0.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 +21 -0
- package/README.md +183 -2
- package/client.js +9781 -0
- package/cordis.patch.yml +13 -0
- package/docs/BOOST-EVIDENCE.md +259 -0
- package/docs/CONFORMANCE.md +236 -0
- package/docs/FACTS-CONTRACT.md +368 -0
- package/docs/FLOW-COVERAGE.md +215 -0
- package/docs/PACKAGE-README.md +858 -0
- package/docs/RANGE-PLAN.md +357 -0
- package/docs/SECURITY-NOTES.md +110 -0
- package/docs/SPLIT-PLAN.md +604 -0
- package/docs/STAGE3-CONTRACT.md +287 -0
- package/docs/TIER-ROUTING.md +275 -0
- package/docs/badge/CONFORMANCE.md +246 -0
- package/docs/badge/DETAIL.md +319 -0
- package/docs/badge/PROJECTIONS.md +264 -0
- package/docs/badge/TEST-PLAN.md +252 -0
- package/docs/images/badge-menu.png +0 -0
- package/docs/images/dispatch.png +0 -0
- package/docs/images/header.png +0 -0
- package/docs/images/pair-header.png +0 -0
- package/docs/images/pair-panel.png +0 -0
- package/docs/images/panel.png +0 -0
- package/docs/wiki/Home.md +43 -0
- package/docs/wiki//344/275/277/347/224/250/346/214/207/345/215/227.md +97 -0
- package/docs/wiki//345/256/211/350/243/205/344/270/216/345/215/207/347/272/247.md +87 -0
- package/docs/wiki//346/225/205/351/232/234/346/216/222/346/237/245.md +94 -0
- package/icon.svg +12 -0
- package/lib/badge-policy.mjs +502 -0
- package/lib/badge-sync.mjs +385 -0
- package/lib/command.mjs +490 -0
- package/lib/completion.mjs +288 -0
- package/lib/concurrency.mjs +2555 -0
- package/lib/dispatch-command.mjs +181 -0
- package/lib/dispatch-gate.mjs +924 -0
- package/lib/facts-store.mjs +183 -0
- package/lib/gate-state.mjs +465 -0
- package/lib/gate.mjs +886 -0
- package/lib/index.js +309 -0
- package/lib/inject.mjs +195 -0
- package/lib/interrupt.mjs +376 -0
- package/lib/ledger.mjs +948 -0
- package/lib/lifecycle.mjs +274 -0
- package/lib/messages.mjs +532 -0
- package/lib/notice.mjs +769 -0
- package/lib/plan-gate.mjs +385 -0
- package/lib/projection.mjs +978 -0
- package/lib/report.mjs +290 -0
- package/lib/route.mjs +346 -0
- package/lib/run-registry.mjs +402 -0
- package/lib/services.mjs +293 -0
- package/lib/stuck.mjs +567 -0
- package/lib/tier-config.mjs +212 -0
- package/lib/tier-policy.mjs +167 -0
- package/lib/tier-state.mjs +137 -0
- package/lib/todo-gate.mjs +1672 -0
- package/lib/tools.mjs +2912 -0
- package/locale/en.json +9 -0
- package/locale/zh.json +9 -0
- package/package.json +83 -4
- package/vendor/node_modules/@deepseek-ai/cosmokit/LICENSE +21 -0
- package/vendor/node_modules/@deepseek-ai/cosmokit/README.md +30 -0
- package/vendor/node_modules/@deepseek-ai/cosmokit/lib/index.js +418 -0
- package/vendor/node_modules/@deepseek-ai/cosmokit/package.json +32 -0
- package/vendor/node_modules/@deepseek-ai/cosmokit/src/array.ts +42 -0
- package/vendor/node_modules/@deepseek-ai/cosmokit/src/index.ts +12 -0
- package/vendor/node_modules/@deepseek-ai/cosmokit/src/misc.ts +78 -0
- package/vendor/node_modules/@deepseek-ai/cosmokit/src/string.ts +113 -0
- package/vendor/node_modules/@deepseek-ai/cosmokit/src/time.ts +92 -0
- package/vendor/node_modules/@deepseek-ai/cosmokit/src/types.ts +168 -0
- package/vendor/node_modules/@deepseek-ai/cosmokit/src/volatile.ts +86 -0
- package/vendor/node_modules/@deepseek-ai/schemastery/LICENSE +21 -0
- package/vendor/node_modules/@deepseek-ai/schemastery/README.md +393 -0
- package/vendor/node_modules/@deepseek-ai/schemastery/lib/index.cjs +635 -0
- package/vendor/node_modules/@deepseek-ai/schemastery/lib/index.mjs +635 -0
- package/vendor/node_modules/@deepseek-ai/schemastery/package.json +39 -0
- package/vendor/node_modules/@deepseek-ai/schemastery/src/index.ts +962 -0
- package/vendor/node_modules/@standard-schema/spec/LICENSE +21 -0
- package/vendor/node_modules/@standard-schema/spec/README.md +198 -0
- package/vendor/node_modules/@standard-schema/spec/dist/index.cjs +18 -0
- package/vendor/node_modules/@standard-schema/spec/dist/index.js +0 -0
- package/vendor/node_modules/@standard-schema/spec/package.json +39 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# 插件开发规范符合性
|
|
2
|
+
|
|
3
|
+
本文档记录两个插件按 DSH 官方插件规范(`dsh-plugin-guide` + `dsh-standards`)
|
|
4
|
+
的自检结果,以及踩过的坑。
|
|
5
|
+
|
|
6
|
+
> **本报告不是认证、安全审计或市场准入。** `dsh-standards` 是第三方检查器,
|
|
7
|
+
> 与 DSH 官方无关。ENTRY `recognized` 不等于运行时通过,`static` 不是 pass,
|
|
8
|
+
> `not-run` 不是 pass。
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 一、检查结果
|
|
13
|
+
|
|
14
|
+
检查器:`dsh-standards@1.6.12`,宿主版本 `0.2.2-rc.3`。
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
npx -y dsh-standards@1.6.12 check <plugin-dir> \
|
|
18
|
+
--scope entry --entry-claim static --no-exec --host-version 0.2.2-rc.3
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
| 插件 | Status | Blocking | Hygiene | 说明 |
|
|
22
|
+
|---|---|---|---|---|
|
|
23
|
+
| `@local/dsh-subagent-route-badge` | **pass** | 0 | 0 | ENTRY recognized |
|
|
24
|
+
| `dsh-team-preflight` | **pass** | 0 | 0 | ENTRY recognized |
|
|
25
|
+
|
|
26
|
+
### 三层状态(`dsh-levels`)
|
|
27
|
+
|
|
28
|
+
| 层 | 状态 | 说明 |
|
|
29
|
+
|---|---|---|
|
|
30
|
+
| ENTRY | `recognized`(static claim) | 包形状、入口、patch、版本范围、metadata 均通过 |
|
|
31
|
+
| FLOW | `not-run` | 未执行 J1–J8 用户旅程;**不是 pass** |
|
|
32
|
+
| BOOST | `not-measured` | 未做 LEV-1–8 实践取证;**不是 pass** |
|
|
33
|
+
|
|
34
|
+
**FLOW 和 BOOST 需要运行时证据,当前未采集。** 按证据纪律,这里如实记为
|
|
35
|
+
`not-run` / `not-measured`,不写成通过。
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 二、manifest 契约(参考官方 recipe)
|
|
40
|
+
|
|
41
|
+
两个插件的 `package.json` 参考了官方 `recipes.md` 的最小形状,但**实际字段按各自需要有所扩展**
|
|
42
|
+
(例如 badge 需要 `dsh.client`、`exports["./client"]`、`files` 里包含 `vendor` 与 `locale`;
|
|
43
|
+
preflight 的 `main` 是 `./lib/index.js`)。
|
|
44
|
+
|
|
45
|
+
下面是**最小模板**,用于说明哪些字段是契约必需的;实际清单以各自的 `package.json` 为准。
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
{
|
|
49
|
+
"name": "...",
|
|
50
|
+
"version": "1.3.0",
|
|
51
|
+
"license": "MIT",
|
|
52
|
+
"type": "module",
|
|
53
|
+
"main": "./index.js",
|
|
54
|
+
"exports": { ".": "./index.js" },
|
|
55
|
+
"files": ["index.js", "cordis.patch.yml"],
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": ">=24.9.0",
|
|
58
|
+
"dsh": ">=0.2.2-0 <0.3.0"
|
|
59
|
+
},
|
|
60
|
+
"peerDependencies": {
|
|
61
|
+
"@deepseek-ai/dsh": ">=0.2.2-0 <0.3.0"
|
|
62
|
+
},
|
|
63
|
+
"peerDependenciesMeta": {
|
|
64
|
+
"@deepseek-ai/dsh": { "optional": true }
|
|
65
|
+
},
|
|
66
|
+
"dsh": {
|
|
67
|
+
"manifestVersion": 1,
|
|
68
|
+
"kind": "plugin",
|
|
69
|
+
"bundle": { "patch": "./cordis.patch.yml" },
|
|
70
|
+
"capabilities": [],
|
|
71
|
+
"labels": []
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### `engines.dsh` 的 `-0` 下界是必须的
|
|
77
|
+
|
|
78
|
+
```json
|
|
79
|
+
"dsh": ">=0.2.2-0 <0.3.0" ✅ 包含 0.2.2-rc.3
|
|
80
|
+
"dsh": ">=0.2.2 <0.3.0" ❌ 不包含(prerelease 排在 release 之前)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
宿主自 `0.2.1-alpha.4` 起**只读这个字段**,有它时忽略 `peerDependencies`。
|
|
84
|
+
写错会让宿主拒绝加载。
|
|
85
|
+
|
|
86
|
+
### `capabilities` 按静态触发面声明
|
|
87
|
+
|
|
88
|
+
| 插件 | 静态触发 | 声明 |
|
|
89
|
+
|---|---|---|
|
|
90
|
+
| badge | 无(`ctx.tools.register` / `ctx.fs` / `ctx.web` 等均未命中) | `[]` |
|
|
91
|
+
| preflight | `ctx.tools.register(` | `["tools:register"]` |
|
|
92
|
+
|
|
93
|
+
**`[]` 是显式的「不使用任何能力」声明,不是占位。** 一旦声明了数组(哪怕空),
|
|
94
|
+
任何未声明的静态触发都会从 WARN 升级为 **FAIL**。
|
|
95
|
+
|
|
96
|
+
### `labels` 只在需要时声明
|
|
97
|
+
|
|
98
|
+
`C-13.2` 只在特定能力下要求 label:
|
|
99
|
+
|
|
100
|
+
| 能力 | 必需 label |
|
|
101
|
+
|---|---|
|
|
102
|
+
| `system-prompt:write` | `prompt-modification` |
|
|
103
|
+
| `llm:adapter` + `network:egress` | `third-party-model-provider` |
|
|
104
|
+
| `network:ingress` | `remote-access` |
|
|
105
|
+
| 声明了 `dsh.upstream` | `mirror` |
|
|
106
|
+
|
|
107
|
+
两个插件都不命中,故 `labels: []`。
|
|
108
|
+
|
|
109
|
+
**禁止**使用 `official` / `verified` / `certified` / `secure` / `audited`
|
|
110
|
+
——这些词会被当作背书声明,直接 FAIL。
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## 三、踩过的坑
|
|
115
|
+
|
|
116
|
+
### 坑 1:`ctx.configForms` 直接访问让整个 client 插件不加载
|
|
117
|
+
|
|
118
|
+
**症状**:徽标 UI 完全不显示。但 bundle 加载、模块解析、slot 契约全部正常。
|
|
119
|
+
|
|
120
|
+
**根因**:`configForms` 是可选服务,故意没写进 `inject: ['slots','locale']`。
|
|
121
|
+
但 Cordis 的 context 是 **Proxy**,get 陷阱对未 inject 的属性**同步抛错**
|
|
122
|
+
(`cordis/src/reflect.ts:152`):
|
|
123
|
+
|
|
124
|
+
```js
|
|
125
|
+
throw new Error(`cannot get property "configForms" without inject`)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
而 `apply` 里有 4 处 `ctx.configForms` 直接访问,**第一处就在函数开头**。
|
|
129
|
+
于是 `apply` 立即抛错,末尾的 `ctx.slots.inject(...)` 永远执行不到。
|
|
130
|
+
|
|
131
|
+
**修复**:所有**读取**可选服务的地方必须走 `ctx.get()`(`reflect.get`,不做 inject 检查):
|
|
132
|
+
|
|
133
|
+
> 口径更正(2026-11-28 审计 W1-F-24):本文件早先写成「所有可选服务必须走 `ctx.get()`」,
|
|
134
|
+
> 与实现方式不完全一致,容易让 reviewer 误报。**两条都合法**:
|
|
135
|
+
> 1. `ctx.get?.('name')` + try/catch 静默降级(读点用,例如 `configFormsOf`);
|
|
136
|
+
> 2. `ctx.inject(['name'], (scope) => { ...; return disposer })` 可选注入
|
|
137
|
+
> (需要订阅/生命周期时用,例如白名单 store、模型目录、Host 的 sessionProjections)。
|
|
138
|
+
>
|
|
139
|
+
> 唯一红线是:**可选服务绝不能写进 `export const inject = []` 或 package.json 的
|
|
140
|
+
> `dsh.client.inject`**——那会变成硬依赖,服务缺失时整个半边不 materialize。
|
|
141
|
+
|
|
142
|
+
```js
|
|
143
|
+
const configFormsOf = () => {
|
|
144
|
+
try {
|
|
145
|
+
return ctx.get?.('configForms')
|
|
146
|
+
} catch {
|
|
147
|
+
return undefined
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
**防护**:跨插件的 `ctx.X` 源码扫描位于 `02-team-preflight/test-integration.mjs` 的 §10(扫描对象是本插件的 `client.js`)与 §11(扫描 02 自身 `lib/`)——任何 `ctx.X` 直接访问,若 X 既不在 `inject` 里、又不在 `ctx.inject([...])` 可选注入里,测试失败。本插件自己的 `test-integration.mjs` 只含 §0–§8,不含该扫描。
|
|
153
|
+
|
|
154
|
+
### 坑 2:`wire` 缺 `viewSchema` 让全部会话历史加载失败
|
|
155
|
+
|
|
156
|
+
**症状**:`failed to project session "...": Cannot read properties of undefined
|
|
157
|
+
(reading 'parse')(gateway/internal)`,所有会话打不开。
|
|
158
|
+
|
|
159
|
+
**根因**:投影注册表写的是
|
|
160
|
+
|
|
161
|
+
```js
|
|
162
|
+
if (def.wire !== undefined) values[key] = def.wire.viewSchema.parse(...)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
——**只看 `wire` 是否存在,不检查 `viewSchema`**。于是
|
|
166
|
+
`wire: { summary: false }`(想省掉会话摘要 payload)会让 `def.wire` 为 truthy
|
|
167
|
+
而 `viewSchema` 为 undefined,直接崩。
|
|
168
|
+
|
|
169
|
+
**第二条致命路径**:与官方共享 key 时,`wire.summary` 必须一致
|
|
170
|
+
(`index.ts:419`)。官方定义无 `wire`,`summary` 是 `undefined`;
|
|
171
|
+
传 `false` 就 `false !== undefined` → 抛 `refusing to share`。
|
|
172
|
+
|
|
173
|
+
**修复**:
|
|
174
|
+
- preflight(共享 key):硬性断言 `if ('wire' in definition) throw`
|
|
175
|
+
- badge(独立 key):`assertWireShape()` 要求三字段齐备
|
|
176
|
+
|
|
177
|
+
**规则**:`wire` 要么三字段齐备,要么整个省略。**不存在「只给 summary」的写法。**
|
|
178
|
+
|
|
179
|
+
详见 `docs/badge/PROJECTIONS.md`(63-合并 M3:01 文档已移入 docs/badge/)。
|
|
180
|
+
|
|
181
|
+
### 坑 3:模块级 await(`DSC-10`)
|
|
182
|
+
|
|
183
|
+
**症状**:检查器报 `WARN C-10.1`。
|
|
184
|
+
|
|
185
|
+
**原写法**:
|
|
186
|
+
|
|
187
|
+
```js
|
|
188
|
+
const z = await loadSchemastery() // 模块级 await
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
**问题**:模块级 await 让每个 importer 的求值等待,宿主无法注入清理。
|
|
192
|
+
更糟的是 `loadSchemastery()` 失败时**静默降级**成没有 volatile 的 fallback
|
|
193
|
+
schema,导致 settings 通道神秘失效——用户只看到「插件没装」。
|
|
194
|
+
|
|
195
|
+
**修复**:改用静态 import,失败会在加载期清晰抛出。
|
|
196
|
+
|
|
197
|
+
```js
|
|
198
|
+
import zImport from './vendor/node_modules/@deepseek-ai/schemastery/lib/index.mjs'
|
|
199
|
+
const z = typeof zImport === 'function' && typeof zImport.object === 'function'
|
|
200
|
+
? zImport
|
|
201
|
+
: undefined
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### 坑 4:`PostToolDecision.content` 是**替换**语义
|
|
205
|
+
|
|
206
|
+
**症状**:委派子代理时,工具输出变成只有路由标记,子代理名称丢失。
|
|
207
|
+
|
|
208
|
+
**根因**:误用 `downstream.content`(决策对象,没有 content)而非
|
|
209
|
+
`result.content`(执行结果)。`content` 是替换不是追加,于是原输出被整个替换。
|
|
210
|
+
|
|
211
|
+
**修复**:从 `result.content` 取原内容再拼接。
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## 四、未完成的证据
|
|
216
|
+
|
|
217
|
+
按证据纪律,以下项**未采集**,不能写成通过:
|
|
218
|
+
|
|
219
|
+
| 项 | 状态 | 需要什么 |
|
|
220
|
+
|---|---|---|
|
|
221
|
+
| FLOW J1–J8 | `not-run` | 安装/卸载/启用/禁用/配置/首次成功/权限/升级的运行时记录 |
|
|
222
|
+
| BOOST LEV-1–8 | `not-measured` | 逐实践的十三字段证据卡 |
|
|
223
|
+
| ENTRY runtime claim | `NA` | `--runtime` 或 `--host` 的实际启动证据 |
|
|
224
|
+
| 安全审计 | 未做 | `--scope security` 是静态扫描,不等于安全审计 |
|
|
225
|
+
|
|
226
|
+
**ENTRY 的 `recognized` 只说明包能被识别。** 它不保证运行时行为正确,
|
|
227
|
+
也不覆盖 FLOW(用户旅程是否顺畅)和 BOOST(是否用好 Cordis)。
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## 五、复现检查
|
|
232
|
+
|
|
233
|
+
```sh
|
|
234
|
+
# 单元测试(纯函数逻辑)
|
|
235
|
+
cd ~/.dsh/plugins/dsh-subagent-dispatch-control && node test/test.mjs
|
|
236
|
+
|
|
237
|
+
# 集成测试(含投影契约、client inject 扫描)
|
|
238
|
+
cd ~/.dsh/plugins/dsh-subagent-dispatch-control && node test/test-integration.mjs
|
|
239
|
+
|
|
240
|
+
# 官方 ENTRY 检查
|
|
241
|
+
npx -y dsh-standards@1.6.12 check <plugin-dir> \
|
|
242
|
+
--scope entry --entry-claim static --no-exec --host-version 0.2.2-rc.3
|
|
243
|
+
|
|
244
|
+
# 三层自检
|
|
245
|
+
npx -y -p dsh-standards@1.6.12 dsh-levels <plugin-dir> --format json
|
|
246
|
+
```
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
# 子代理模型快速切换
|
|
2
|
+
|
|
3
|
+
给官方已有的子代理模型选择接口加一个常驻下拉,让「这次委派用哪个模型」一步可切。
|
|
4
|
+
|
|
5
|
+
## 它做什么,不做什么
|
|
6
|
+
|
|
7
|
+
| 做 | 不做 |
|
|
8
|
+
|---|---|
|
|
9
|
+
| 从官方白名单读取可选路由 | ❌ 不修改主会话的模型 |
|
|
10
|
+
| 记住你选中的路由,供下次委派使用 | ❌ 不写 `agentOptions` 插件配置 |
|
|
11
|
+
| 显示当前选择与连接状态 | ❌ 不篡改任何官方 UI 槽位 |
|
|
12
|
+
|
|
13
|
+
**核心约束:绝不调用 `modelDirectories.directoryFor(sessionId).select()`。**
|
|
14
|
+
那是主会话的模型目录,调用它会切换主模型——这不是本插件的目的。
|
|
15
|
+
|
|
16
|
+
## 官方设计依据
|
|
17
|
+
|
|
18
|
+
### 1. 子代理模型怎么来的
|
|
19
|
+
|
|
20
|
+
`dsh-subagent/src/child-agent.ts:98-119`(节选):
|
|
21
|
+
|
|
22
|
+
> 行号说明(2026-11-28 审计 W1-F-20):本行号与 `client.js` 头注释里的
|
|
23
|
+
> `child-agent.ts:100-121` 历史上不一致(两处至少一处过期),而本环境
|
|
24
|
+
> `app.asar` 不可读、无法逐行核对。现已统一为本文这一处(98-119),
|
|
25
|
+
> `client.js:6` 同步改成同一范围并标注「无法核对」。升级 DSH 后请按实际
|
|
26
|
+
> 源码重新核对一次。
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
export function resolveChildAgentOptions(parent, requested, childDepth) {
|
|
30
|
+
const parentOptions = parentAgentOptionsForDelegation(parent)
|
|
31
|
+
const resolved = {
|
|
32
|
+
...parentProvider !== undefined ? { provider: parentProvider } : {},
|
|
33
|
+
...parentModel !== undefined ? { model: parentModel } : {},
|
|
34
|
+
...parentReasoningEffort !== undefined ? { reasoningEffort: parentReasoningEffort } : {},
|
|
35
|
+
...parentMaxTokens !== undefined ? { maxTokens: parentMaxTokens } : {},
|
|
36
|
+
...requested, // ← 工具调用时传入的覆盖
|
|
37
|
+
subagentDepth: childDepth,
|
|
38
|
+
}
|
|
39
|
+
const routeChanged = resolved.provider !== parentProvider || resolved.model !== parentModel
|
|
40
|
+
if (routeChanged && requested?.reasoningEffort === undefined) delete resolved.reasoningEffort
|
|
41
|
+
return resolved
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**子代理路由 = 父代理路由 + 调用时覆盖。** 不传就继承。
|
|
46
|
+
|
|
47
|
+
### 2. 多模型并存靠白名单
|
|
48
|
+
|
|
49
|
+
`dsh-tool-subagent/src/model-selection-settings.ts`:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
static Config = z.object({
|
|
53
|
+
enabled: z.boolean().default(false).volatile(),
|
|
54
|
+
allowedModels: z.array(AllowedModelRouteSchema).default([]).volatile(),
|
|
55
|
+
})
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
namespace = `subagent-model-selection-settings`,结构 = `{ enabled, allowedModels: [{provider, model}] }`。
|
|
59
|
+
|
|
60
|
+
**`allowedModels` 里的每个路由都可以被子代理使用**——这就是「多个 agent 模型同时选择」的实现方式。
|
|
61
|
+
|
|
62
|
+
### 3. 显式选择的前置条件
|
|
63
|
+
|
|
64
|
+
`dsh-tool-subagent/src/index.ts`:`modelSelection: true` 时,`subagent` 工具才暴露 `provider` / `model` / `reasoning_effort` 字段。
|
|
65
|
+
|
|
66
|
+
### 4. 三层优先级
|
|
67
|
+
|
|
68
|
+
README 第 79 行原文:
|
|
69
|
+
|
|
70
|
+
> Static `provider.agentRouteDefaults`, when present, form the provider/model baseline; **tool configuration and model fields overlay it** before route-aware effort merging and exact-route preflight.
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
1. provider.agentRouteDefaults 后端默认
|
|
74
|
+
2. config.agentOptions 插件实例配置(cordis.patch.yml,需重启)
|
|
75
|
+
3. 工具调用参数 每次委派显式指定(受白名单约束)
|
|
76
|
+
4. 都没给 继承父代理
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
本插件对应第 3 层——**只影响下一次委派,立即生效,不动任何配置**。
|
|
80
|
+
|
|
81
|
+
## client.js 职责地图(单文件,3463 行)
|
|
82
|
+
|
|
83
|
+
> W1-F-07(62 结构重构批次):本文件受 `window.__ModuleLoader__.load({ id, factory })`
|
|
84
|
+
> **单文件注入约束**,因此不物理拆包;改为在 factory 内按职责分区(全文检索锚点
|
|
85
|
+
> `── [X]`,X 为 A–L)。为什么不能拆成多个文件见下节「构建边界评估」。
|
|
86
|
+
|
|
87
|
+
| 分区 | 内容 | 定位线索(函数名) |
|
|
88
|
+
|---|---|---|
|
|
89
|
+
| `[A]` 常量区 | 平台模块获取 / namespace / 存储键 / 写入纪律 / 诊断键 / 样式常量 | `SELECTION_NS`、`BRIDGE_NS`、`STORAGE_KEY`、`SESSIONS_CAP`、`WRITE_TIMEOUT_MS`、`DIAG_KEY`、`MENU_MAX_WIDTH`、`EFFORT_INDENT`、`triggerStyle` |
|
|
90
|
+
| `[B]` 会话表 I/O | Host `sessions` 表的唯一读写入口(解析 / 容量裁剪 / 单次 mutate / 统一写入链) | `entryOf`、`parseSessions`、`trimSessions`、`mutateOnce`、`writeSessionsTable` |
|
|
91
|
+
| `[C]` 扩展点 | provider 注册表(window 全局扩展点,带版本化) | `REGISTRY_VERSION`、`registry` |
|
|
92
|
+
| `[D]` 路由原语 | 身份键 / effort / 等价比较 / 序列化 | `routeText`、`routeKey`、`effortOf`、`sameRoute`、`hostTierRouteOf`、`serializeSelection`、`parseStoredRoute` |
|
|
93
|
+
| `[E]` 选择存储 | localStorage 按会话 + 跨标签页同步 | `createSelectionStore`(含 `watchStorage`) |
|
|
94
|
+
| `[F]` Host 桥接写入 | 会话表合并 → 单次写入 → 重试状态机 → 绑定器;只读探针;桥接纪元 | `mergeSelectionIntoSessions`、`createSessionWriter`、`createRetryWriter`、`createHostSyncBinder`、`createHostProbes`、`createBridgeEpoch` |
|
|
95
|
+
| `[G]` 白名单存储 | 官方 `subagent-model-selection-settings` 读取(按条容错)+ 恒定外层壳(晚到自愈) | `createAllowlistStore`、`createAllowlistBridge` |
|
|
96
|
+
| `[H]` 模型目录索引 | 官方只读目录 → reasoning / 显示名 / 能力判定 | `reasoningKey`、`buildReasoningIndex`、`buildNameIndex`、`supportedEffort`、`createCatalogStore` |
|
|
97
|
+
| `[I]` 默认 provider | 徽标文案、圆点颜色与「本会话是否可用」判据 | `toneColor`、`defaultProvider.resolve` |
|
|
98
|
+
| `[J]` 视图组件 | 触发器 + 菜单 + 子视图构建器 | `OptionRow`、`renderBadgeTrigger`、`buildModelRows`、`buildEffortRows`、`buildDeepRows`、`buildMainRows`、`buildProviderSections`、`RouteBadge` |
|
|
99
|
+
| `[K]` 槽位外壳 | 投影 hook + 桥接同步三 effect | `useHostBridgeSync`、`makeSlotComponent`(`SubagentRouteBadge`) |
|
|
100
|
+
| `[L]` 插件对象 | inject / apply(服务装配 + 槽位注册)+ factory 级工具 | `createDiagnose`、`apply` |
|
|
101
|
+
|
|
102
|
+
### 函数长度(重构前 → 重构后)
|
|
103
|
+
|
|
104
|
+
| 函数 | 前 | 后 | 处理方式 |
|
|
105
|
+
|---|---:|---:|---|
|
|
106
|
+
| `factory`(ModuleLoader 外壳) | 3067 | 3389 | 不拆:它就是单文件注入单元(见下节) |
|
|
107
|
+
| `apply` | 797 | 190 | 拆出诊断 / 桥接同步 / 探针 / 纪元 / 白名单壳 / 定时器登记 |
|
|
108
|
+
| `RouteBadge` | 516 | 181 | 菜单分区拆为 6 个构建器 + provider 解析 + 触发器渲染 |
|
|
109
|
+
| `makeSlotComponent` | 229 | 98 | 三个 effect 并入 `useHostBridgeSync` |
|
|
110
|
+
| `SubagentRouteBadge` | 227 | 96 | 同上 |
|
|
111
|
+
| `createHostSyncBinder` | 350(重构中期形态) | 24 | 拆为 merge / 单次写入 / 重试状态机 / 绑定器 |
|
|
112
|
+
| **除 factory 外最长函数** | **797** | **190** | — |
|
|
113
|
+
|
|
114
|
+
### 构建边界评估(为什么不能拆成多个文件)
|
|
115
|
+
|
|
116
|
+
1. **注入契约以「一个文件 = 一个模块」为单位**:`client.js` 顶层是
|
|
117
|
+
`window.__ModuleLoader__.load({ id: '@local/dsh-subagent-route-badge', factory(require) { … } })`。
|
|
118
|
+
宿主 client bundle 加载器按 id 注册**这一个 factory**,文件本身是注册单元。
|
|
119
|
+
2. **factory 的 `require` 是宿主平台模块表,不是文件系统解析器**:本文件只
|
|
120
|
+
`require('react')`、可选 `react-dom`、可选 `@deepseek-ai/dsh-client-ui-primitives`。
|
|
121
|
+
没有相对路径 `require('./xxx.js')` 能力,因此 factory 内无法引用同目录其他文件。
|
|
122
|
+
3. **清单只声明一个 client 入口**:`package.json` 的 `exports['./client']` 与
|
|
123
|
+
`dsh.client = { platform: 'web', inject: [...] }` 指向单一 `client.js`;
|
|
124
|
+
宿主按清单组装 bundle,不会去解析额外文件。
|
|
125
|
+
4. **拆包必须引入构建步骤**:要把多文件重新打回单文件,需要 rollup/esbuild 之类
|
|
126
|
+
构建链与产物对账。本插件当前是「源码即部署副本」(全量 cp + sha256 对账,无构建产物),
|
|
127
|
+
引入构建会改变部署与审计方式,属构建体系变更,超出结构重构批次范围。
|
|
128
|
+
5. **结论**:在不改宿主 bundle 契约、不引入构建链的前提下,拆文件的唯一代价是
|
|
129
|
+
「部署对账失效 + 运行时加载失败」。因此本批只做 **factory 内部分区**:
|
|
130
|
+
分区横幅 + 相关纯函数聚簇 + 常量集中,把最小可改单元(除 factory 外最长函数)
|
|
131
|
+
从 797 行降到 190 行,而单文件注入契约、导出与行为零变更(01 套件 474/0、
|
|
132
|
+
86/0 与基线逐字相等)。
|
|
133
|
+
|
|
134
|
+
## 数据来源
|
|
135
|
+
|
|
136
|
+
| 数据 | 来源 |
|
|
137
|
+
|---|---|
|
|
138
|
+
| 可选路由 | `configForms.get('subagent-model-selection-settings')` 的 `allowedModels` |
|
|
139
|
+
| 当前主代理路由 | 会话 `modelSelection` 投影(**只读**) |
|
|
140
|
+
| 用户选中 | 本插件 localStorage,**每会话一键**:`dsh.subagentRouteBadge.selection:<sessionId>`(旧全局键 `dsh.subagentRouteBadge.selection` 仅作升级过渡回退,见 client.js 的 createSelectionStore) |
|
|
141
|
+
|
|
142
|
+
> 更正(2026-11-28 审计 W1-F-18):早先这里只写全局键。X13 起选择按会话独立,
|
|
143
|
+
> 全局键在任一会话首次新写后即退役。
|
|
144
|
+
|
|
145
|
+
## 圆点含义
|
|
146
|
+
|
|
147
|
+
只有两种状态,**颜色只由「本会话是否真的能用这条路由」决定**(`usableHere`):
|
|
148
|
+
|
|
149
|
+
- 🟢 **绿** = 已连接:子代理能按当前选择工作
|
|
150
|
+
- 选「继承」且父代理路由已知
|
|
151
|
+
- 选中的路由在本会话的授权策略里(会话创建时冻结的那份),
|
|
152
|
+
**即使它已经被从设置的白名单里删掉也仍然是绿**
|
|
153
|
+
- 🔴 **红** = 未连接:当前选择无法工作
|
|
154
|
+
- 本会话没有授权该路由(例如设置在会话创建后才加的 → 「需开新会话后可用」)
|
|
155
|
+
- 官方「允许子代理选择模型」开关关闭且本会话未授权
|
|
156
|
+
- 没有任何选择也没有父路由可继承
|
|
157
|
+
|
|
158
|
+
> 更正(2026-11-28 审计 W1-F-13):早先这里写「选了某路由且它在白名单内 = 绿 /
|
|
159
|
+
> 不在白名单内 = 红」,与实现相反。实现里 `inConfig`(是否在当前设置里)
|
|
160
|
+
> **只参与不可用时的措辞**,不参与颜色——判据见 client.js 的 `defaultProvider.resolve`
|
|
161
|
+
> 与其 `tone` 计算。按旧文档会把「设置里删了但本会话已授权」(实际为绿)
|
|
162
|
+
> 误判成插件 bug。
|
|
163
|
+
|
|
164
|
+
**不会出现第三种颜色。** 未知状态一律按红色处理。
|
|
165
|
+
|
|
166
|
+
## 选择如何传给委派
|
|
167
|
+
|
|
168
|
+
这是本插件的关键链路:
|
|
169
|
+
|
|
170
|
+
```
|
|
171
|
+
用户在徽标菜单里选中路由
|
|
172
|
+
↓ 写入 localStorage(浏览器本地)
|
|
173
|
+
↓ 同时写入 settings namespace 'subagent-route-badge'(跨端)
|
|
174
|
+
浏览器:configFormsOf().get(ns).mutate(ops) ← 见 client.js 的 write()
|
|
175
|
+
Host: ctx.settings.describe() 读到该 value
|
|
176
|
+
↓
|
|
177
|
+
dsh-team-preflight 的 check_subagent_selection 工具读取该值
|
|
178
|
+
↓
|
|
179
|
+
模型在委派前知道「用户选了什么」
|
|
180
|
+
↓
|
|
181
|
+
调用 subagent(provider, model) 时带上该路由
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
> **2026-11-18 更正**:早先这里写的是 `ctx.remote.settings.mutate(ns, ops, revision)`,
|
|
185
|
+
> 与实现不符。实际走的是 `configForms` 通道(与 Settings 界面同一路径),
|
|
186
|
+
> 契约见 `dsh-client-ui-settings/src/client/config-form.ts`:
|
|
187
|
+
> `mutate(ops, expectedRevision?) → Promise<boolean>`。
|
|
188
|
+
> `true` = Host 接受,`false` = Host 拒绝(已内部恢复读取)。
|
|
189
|
+
|
|
190
|
+
**为什么需要这条链路**:浏览器端的 localStorage 在 Host 进程里不可见。要让「模型知道用户选了什么」,必须走 DSH 官方的 settings 通道。
|
|
191
|
+
|
|
192
|
+
**委派时的提示**:`dsh-team-preflight` 会在每次 `subagent` / `subagent_fork` 后注入一条消息,包含:
|
|
193
|
+
|
|
194
|
+
- 本次实际使用的模型(继承 / 显式)
|
|
195
|
+
- Team 模式状态(已开启 / 未开启 / 服务不可用)
|
|
196
|
+
- 界面选择与实际是否一致(不一致会标 ⚠)
|
|
197
|
+
|
|
198
|
+
## 用法
|
|
199
|
+
|
|
200
|
+
1. 点头部「子代理模型」徽标
|
|
201
|
+
2. 选一个白名单路由,或选「继承主代理路由」
|
|
202
|
+
3. 下次委派时带上该路由(模型侧调用 `subagent(provider, model)`)
|
|
203
|
+
|
|
204
|
+
菜单底部固定提示:**此处选择仅影响后续委派,不改变当前会话模型**。
|
|
205
|
+
|
|
206
|
+
## 白名单为空怎么办
|
|
207
|
+
|
|
208
|
+
菜单会提示去设置里添加:
|
|
209
|
+
|
|
210
|
+
> 设置 → 插件 → 子代理 → 模型选择
|
|
211
|
+
|
|
212
|
+
那里可以勾选任意多个模型(这就是官方的多模型并存界面)。
|
|
213
|
+
|
|
214
|
+
## 扩展点
|
|
215
|
+
|
|
216
|
+
```js
|
|
217
|
+
const api = window.__DSH_SUBAGENT_ROUTE_BADGE__
|
|
218
|
+
const off = api.register({
|
|
219
|
+
id: 'my.provider',
|
|
220
|
+
order: 10,
|
|
221
|
+
resolve({ selectedRoute, allowlist, parentRoute, sessionId, t }) {
|
|
222
|
+
if (!allowlist?.some(r => r.provider === 'my-provider')) return null
|
|
223
|
+
return { label: '自建: ...', detail: '...', tone: 'on' }
|
|
224
|
+
},
|
|
225
|
+
sections: () => [{ id: 'mine', title: '我的', items: [{ id: 'a', label: '切到 A', onSelect() {} }] }],
|
|
226
|
+
})
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
`tone` 支持 `'on'`(绿)/ `'off'`(红);**其它值一律按红色(未连接)处理,没有灰色态。**
|
|
230
|
+
|
|
231
|
+
## 已知限制
|
|
232
|
+
|
|
233
|
+
- **选择以浏览器本地为准**:主存储是 localStorage(按会话一键),换浏览器/清缓存会丢;
|
|
234
|
+
同时会**尽力同步**到 Host 的 `subagent-route-badge` settings 表(`sessions` 键),
|
|
235
|
+
供 `dsh-team-preflight` 的 `check_subagent_selection` 读取。
|
|
236
|
+
同步失败(configForms 缺失 / Host 拒绝 / 传输失败)不影响本地选择,但会在控制台
|
|
237
|
+
warn 一次(耗尽重试后)。见「选择如何传给委派」一节。
|
|
238
|
+
> 更正(2026-11-28 审计 W1-F-18):早先这里写「只存在于浏览器本地」,与本文件
|
|
239
|
+
> 自己的同步链路描述矛盾。
|
|
240
|
+
- **不改 `agentOptions`**。那是插件实例配置,不在 `configForms` 暴露范围内,插件无权修改;如需改子代理默认模型,请编辑 profile 的 `cordis.patch.yml` 并重启。
|
|
241
|
+
- **白名单来自配置文档的当前值**,而每个会话在创建时会冻结当时的白名单(`subagent/model-selection-policy` 事件)。已有会话的授权不会因改设置而变。
|
|
242
|
+
- 子代理会话里不显示此徽标(与官方子代理 UI 重复)。
|
|
243
|
+
|
|
244
|
+
## 更新 vendor(schemastery)
|
|
245
|
+
|
|
246
|
+
插件内嵌了一份 `@deepseek-ai/schemastery` 副本,位于 `vendor/node_modules/@deepseek-ai/schemastery/`。
|
|
247
|
+
|
|
248
|
+
> vendor 复制范围(2026-11-28 审计 W1-F-16):`vendor/` 是**上游包的整包副本**
|
|
249
|
+
> (schemastery + cosmokit + @standard-schema/spec,共 22 个文件),其中运行时
|
|
250
|
+
> 真正被 import 链走到的只有 `schemastery/lib/index.mjs` 与 `cosmokit/lib/index.js`
|
|
251
|
+
> (外加各自 package.json)。其余文件(`lib/index.cjs`、`src/*.ts`、LICENSE/README、
|
|
252
|
+
> `@standard-schema/spec` 整个包)与运行无关。
|
|
253
|
+
> **保留整包是刻意选择**:裁剪会让「从上游 tarball 重新提取」的对账步骤不成立,
|
|
254
|
+
> 也无法用上游校验和验证副本完整性;升级 vendor 时按整包替换、不手工裁剪。
|
|
255
|
+
> 这属于**接受包体积/噪音的已知取舍**,不是遗漏清理。
|
|
256
|
+
|
|
257
|
+
**import 链事实(62 结构重构批次 W1-F-16 复核,逐文件 grep + sha256)**:
|
|
258
|
+
|
|
259
|
+
- 运行入口:`index.js` 第 110 行 `import zImport from
|
|
260
|
+
'./vendor/node_modules/@deepseek-ai/schemastery/lib/index.mjs'`。
|
|
261
|
+
- `schemastery/lib/index.mjs` 第 1 行(也是唯一 import)
|
|
262
|
+
`import { … } from "@deepseek-ai/cosmokit"` → 解析到 `vendor/…/cosmokit/lib/index.js`;
|
|
263
|
+
该文件自身**零 import**(自包含)。
|
|
264
|
+
- `schemastery/lib/index.cjs` 不被使用:`index.js` 是 ESM(`package.json` 的
|
|
265
|
+
`"type": "module"`),走 `exports.import` 分支。
|
|
266
|
+
- `@standard-schema/spec` 运行时零使用:它只出现在 `schemastery/package.json` 的
|
|
267
|
+
`dependencies` 与 `schemastery/src/index.ts` 的类型 import 里;`dist/index.js`
|
|
268
|
+
实测为 0 字节(纯类型占位)。整包 5 个文件都不在任何运行 import 链上。
|
|
269
|
+
- `client.js` **完全不 import vendor**:浏览器侧只 `require` 宿主平台模块
|
|
270
|
+
(`react` / 可选 `react-dom` / 可选 `@deepseek-ai/dsh-client-ui-primitives`)。
|
|
271
|
+
|
|
272
|
+
按严格口径,运行时必需 = 2 个入口(schemastery/lib/index.mjs、cosmokit/lib/index.js)
|
|
273
|
+
+ 2 个 `package.json`(ESM exports/main 解析)= **4/22**;其余 **18/22** 不在运行
|
|
274
|
+
import 链上。任务口径记为「16/22 运行时无关」,差异来自是否把 `lib/index.cjs` 与
|
|
275
|
+
两个包的清单/证书算入「运行时相关」;两种口径结论一致:**整包保留、本轮零改动**。
|
|
276
|
+
|
|
277
|
+
62 批次对账结果(`sha256sum` 逐文件比对 61 稳定版):**22/22 文件哈希完全相同**,
|
|
278
|
+
本批对 `vendor/` 无任何增删改。
|
|
279
|
+
|
|
280
|
+
### 为什么需要 vendor
|
|
281
|
+
|
|
282
|
+
DSH 的 settings 机制要求插件 Config 带 `volatile` 字段(`dsh-settings/src/schema.ts:37` 的
|
|
283
|
+
`volatileForm()` 只列出含 volatile 元数据的 schema)。而 `volatile` 依赖 schemastery 3.19 的
|
|
284
|
+
`toJSON()` 生成的 `{uid, refs}` 结构。
|
|
285
|
+
|
|
286
|
+
插件目录经 `link:` 安装,看不到 profile 的 `node_modules`;profile 里的是 3.18.4,
|
|
287
|
+
结构不匹配会触发 `Cannot read properties of undefined (reading 'validate')`。
|
|
288
|
+
Node 又无法 import asar 内文件(`ERR_MODULE_NOT_FOUND`),因此把 asar 内的 3.19.0 复制进来。
|
|
289
|
+
|
|
290
|
+
### DSH 升级后如何更新
|
|
291
|
+
|
|
292
|
+
1. 从 `D:\software\dsh\resources\app.asar` 提取 schemastery:
|
|
293
|
+
```
|
|
294
|
+
dsh/node_modules/@deepseek-ai/schemastery/
|
|
295
|
+
├── lib/index.mjs
|
|
296
|
+
├── lib/index.cjs
|
|
297
|
+
├── package.json
|
|
298
|
+
└── LICENSE
|
|
299
|
+
```
|
|
300
|
+
同时提取它的依赖 `dsh/node_modules/@deepseek-ai/cosmokit/`。
|
|
301
|
+
|
|
302
|
+
2. 覆盖到插件的 `vendor/node_modules/@deepseek-ai/` 下。
|
|
303
|
+
|
|
304
|
+
3. 更新 `index.js` 里的 `EXPECTED_SCHEMASTERY_VERSION` 常量为新版本号。
|
|
305
|
+
|
|
306
|
+
4. 重启 DSH,检查日志里是否出现:
|
|
307
|
+
```
|
|
308
|
+
subagent-route-badge: vendored schemastery X.Y.Z OK
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### 版本不匹配的征兆
|
|
312
|
+
|
|
313
|
+
启动日志会出现:
|
|
314
|
+
```
|
|
315
|
+
subagent-route-badge: vendored schemastery A.B.C does not match the expected X.Y.Z.
|
|
316
|
+
The settings bridge may fail with a "validate" error.
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
此时「界面选择同步到 Host」会失效,但徽标本身仍能显示和选择(只是 Host 读不到)。
|