dsh-cohub 0.4.4 → 0.4.11

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,13 +1,13 @@
1
1
  # dsh-cohub
2
2
 
3
3
  DeepSeek Harness 版 [oh-my-opencode-cohub](https://github.com/Mr-cjf/oh-my-opencode-cohub):中文智能体编排插件。
4
- 把「纯调度模式 + 12 专职代理 + 多模型共识 + 运行期调度韧性」移植到 DSH 原生能力之上。
4
+ 把「纯调度模式 + 13 个 co-* 技能(12 专职代理 + `co-cordis` 创造模式)+ 多模型共识 + 运行期调度韧性」移植到 DSH 原生能力之上。
5
5
 
6
6
  ## 与 OpenCode 版的机制映射
7
7
 
8
8
  | OpenCode 版(oh-my-opencode-cohub) | DSH 版(本包) |
9
9
  |---|---|
10
- | 12 个 agent 注册(双重注册 + config hook) | 12 个 runtime skills(本插件 apply 时注册) |
10
+ | 12 个 agent 注册(双重注册 + config hook) | 13 个 runtime skills(本插件 apply 时注册) |
11
11
  | 中文注入 experimental.chat.system.transform | ctx.systemPrompt.section |
12
12
  | task 工具 + 并行派发 | DSH 原生 subagent 工具(后台/续聊) |
13
13
  | todowrite | DSH 原生 todo_write |
@@ -21,12 +21,16 @@ DeepSeek Harness 版 [oh-my-opencode-cohub](https://github.com/Mr-cjf/oh-my-open
21
21
 
22
22
  > 注:`dsh plugin add` 不是 CLI 独立子命令,而是把参数转发给 profile 目录内的 `pnpm`(`dsh plugin --profile <name> add <pkg>` ≡ 在该 profile 执行 `pnpm add <pkg>`),安装后自动把声明 `dsh.bundle` 的依赖加入 `dsh.profile.bundles`。
23
23
 
24
- ## 技能清单(12 个)
24
+ ## 技能清单(13 个)
25
25
 
26
26
  co-orchestrator(调度)/ co-planner(方案)/ co-oracle(审查)/
27
27
  co-explorer(搜索)/ co-librarian(研究)/ co-observer(视觉)/
28
28
  co-fixer(执行)/ co-designer(UI)/ co-council(共识)/
29
- co-rule-user / co-rule-project / co-rule-app(规范分析)
29
+ co-rule-user / co-rule-project / co-rule-app(规范分析)/
30
+ co-cordis(Cordis 插件与 preset 组合创造 —— 第 13 个,需读写+Bash 权限)
31
+
32
+ > 前 12 个是「专职代理」,`co-cordis` 是 v0.4.7 起新增的创造模式角色(修插件 / 改 harness 组合 / 写 preset)。
33
+ > `test/unit.ts` 断言的正是这 13 个名字,改动技能清单需同步 `scripts/generate-skills.ts` 与测试。
30
34
 
31
35
  ## 构建
32
36
 
@@ -36,12 +40,15 @@ co-rule-user / co-rule-project / co-rule-app(规范分析)
36
40
  cd dsh-cohub
37
41
  npm run build
38
42
  # 等价于:
39
- # bun run scripts/generate-skills.ts # 生成 src/skills.ts
43
+ # bun run scripts/generate-skills.ts # ① 生成 src/skills.ts(.md → 技能定义,必须先跑)
44
+ # bun run scripts/guard-schema.ts # ② 校验 Config / ScheduleConfig schema 与 cordis.patch.yml 一致
40
45
  # bun build src/index.ts --outdir lib --target node --format esm \
41
46
  # --external @deepseek-ai/cordis --external @deepseek-ai/schemastery \
42
47
  # --external @deepseek-ai/dsh-tools --external @deepseek-ai/dsh-system-prompt \
43
48
  # --external @deepseek-ai/dsh-skill --external @deepseek-ai/dsh-home-paths \
44
49
  # --external @deepseek-ai/dsh-settings
50
+ # bun build src/co-cordis-plugin.ts --outdir lib --target node --format esm \
51
+ # --external @deepseek-ai/dsh-tools # co-cordis 专用插件(第 13 个技能)
45
52
  # bun run scripts/build-client.js # src/client/index.js → lib/client.js
46
53
  ```
47
54
 
@@ -54,7 +61,7 @@ dsh plugin --profile web add dsh-cohub
54
61
  本地开发安装:
55
62
 
56
63
  ```bash
57
- dsh plugin --profile web add C:\Users\14023\Desktop\dsh-cohub
64
+ dsh plugin --profile web add <monorepo>/packages/dsh-cohub
58
65
  ```
59
66
 
60
67
  或手动:profile 的 package.json
@@ -121,11 +128,10 @@ dsh plugin --profile web add C:\Users\14023\Desktop\dsh-cohub
121
128
  ttlMs: 604800000 # 7 天
122
129
  confirmCount: 2
123
130
  # P3-3 N3 调度参数:通过 systemPrompt.section 注入实际生效值(cohub:schedule),子代理可见。
131
+ # ⚠️ useJobTracking 与 adaptiveBatch 已于 2026-09-03 移除(声明了但代码不读的死参数),不要再配。
124
132
  schedule:
125
133
  maxParallelBatch: 3
126
134
  wallClockBudgetMs: 600000
127
- useJobTracking: auto # auto / on / off
128
- adaptiveBatch: auto # auto / off
129
135
  ```
130
136
 
131
137
  完整字段含义与缺省见 [`cordis.patch.yml`](cordis.patch.yml) 顶部注释块。
@@ -140,8 +146,8 @@ dsh plugin --profile web add C:\Users\14023\Desktop\dsh-cohub
140
146
 
141
147
  `npm run build` 后重启 DSH,打开设置 → **插件** 标签,可看到「CoHub 代理模型」卡片:
142
148
 
143
- - **12 个 skill 行**(每个独立配置 provider / model)
144
- - **调度参数(可选)**:批大小 / 墙钟预算 / Job 跟踪 / 批间自适应
149
+ - **13 个 skill 行**(每个独立配置 provider / model)
150
+ - **调度参数(可选)**:批大小 / 墙钟预算(`useJobTracking`、`adaptiveBatch` 两个控件已随死参数一并从 GUI 删除)
145
151
  - **委派重试 / 重试间隔**:maxRetries / retryDelayMs / 可重试原因(逗号分隔)
146
152
  - **停滞检测(可选)**:启用复选框 + 5 个阈值 + 可重试复选框(未启用时数字输入框 disabled)
147
153
  - **环境契约持久化(可选)**:契约模式(auto/off/manual)/ 缓存 TTL / 确认次数
@@ -196,43 +202,115 @@ mkdir -p ~/.dsh/.agent-presets/co-orchestrator
196
202
  cp presets/co-orchestrator/* ~/.dsh/.agent-presets/co-orchestrator/
197
203
  ```
198
204
 
205
+ > ⚠️ 上面的 `cp presets/<name>/*` **不会带上子目录**。带 `skills/` 的 preset(如 `cohub-cordis`)必须整目录复制,否则技能丢失;Windows 上推荐直接用随仓库提供的脚本(递归复制 + 防 `Copy-Item` 同名嵌套陷阱):
206
+ >
207
+ > ```powershell
208
+ > pwsh -File scripts/deploy-preset.ps1 # 默认 cohub-cordis
209
+ > pwsh -File scripts/deploy-preset.ps1 -PresetName co-orchestrator
210
+ > ```
211
+
199
212
  在 GUI 的 agent preset 选择器中切换。注意(rc.6 限制):子代理继承父代理的 preset 组合且 toolFilter 只能收窄,因此 preset 不硬性移除文件工具——「绝不亲自操作文件」由 co-orchestrator 技能在提示词层约束(与 OpenCode 原版一致)。
200
213
 
201
214
  **v0.3.0 修正(修复派发)**:原 preset 只挂 `tool-workflow`,缺 spawn/fork 委派工具行,主代理无法实际 spawn co-* 子代理。v0.3.0 补齐 `delegation-subagents` group(subagent / subagent_fork / control / list-agents / ralph)+ compaction group(防长会话爆 context);persona「全部委派给专职子代理」才能落地。**前序版本中尝试用运行时 `tools.restrict({deny})` 物理收口文件 / Shell / 外网工具的做法已回退**——实测发现该 API 在 DSH 0.1.0-rc.6 上行为不符合预期,会连带影响委派工具,导致主代理无法派发;现回到「preset 不挂 fs/shell/web 工具行 + persona 软约束」方案。
202
215
 
203
- ## cohub-standard agent preset(Phase 4,v0.3.0 新增)
216
+ **v0.4.6 修正(修复「留空 model」的秒失败)**:`cohub.skills` 中只配 `provider`、不配 `model` 时,旧版 `buildAgentOptions()` 只把 `provider` 交给子代理,模型则回落到**父会话的模型名**。当该模型名不属于这个 provider(例:`provider: tokenproto` 而父会话是 `deepseek-official/deepseek-flash`),DSH 的 pi-ai 适配器在网络 I/O 前就以 `UNKNOWN_MODEL` 拒绝,`delegate` 只返回 `subagent stopped with reason "error" after 0 retry(ies); partial:`,子代理会话里没有任何模型消息。v0.4.6 起:model 缺失时用 `ctx.llm.listModels(provider)` 取该 provider 目录的首个模型作为回退(适配器偏好顺序的第一项),查询失败或空目录则降级为旧行为。同时 settings 卡片的模型下拉框新增 `value=""` 占位项——旧版在 `value=""` 时会被浏览器渲染成列表**第一项**,让「留空」看起来像已经选好了模型。
217
+
218
+ **v0.4.7 修正(工具批处理 + 委派细分 + 创造模式)**:
219
+ - **A|执行器环境契约新增「工具批处理」通用原则**(`src/env-contract.ts`):一条消息里可发多个无依赖调用、无依赖只读调用应打包同批、`pwsh`/`bash` 按批执行是逐条串行所以能用一条命令表达的不要拆成多次 shell 调用;同时明确**批处理只省往返、不等于并行加速**(实测同批调用多被串行执行),并列出必须串行留白的场景(后续参数取决于前序结果 / 同文件写 / 破坏性 shell)。契约由 `delegate` 注入所有子代理,一处生效覆盖 13 个技能。
220
+ - **C|orchestrator 增加「信息收集的细分原则」**(`skills/orchestrator.md`):先列独立事实清单 → 每个事实维度一个子任务 → ≥2 时用**一次 `delegate_batch`** 并行发出(实测 agent loop 对同批 tool_use 极少真并发,而 `delegate_batch` 内部 `Promise.allSettled` 是真并行)。
221
+ - **D|新增 cohub-cordis preset(创造模式)**:见上节。
222
+
223
+ **v0.4.8 变更(preset 安装台账 + 移除 cohub-standard)**:
224
+ - **A|preset 安装/升级台账**(`src/preset-install.ts`):在 preset root 的**上一级**写 `<root>/../.cohub-preset-install.json`,记录每个 preset 的安装版本与逐文件 sha256。包版本升级时逐文件比对——**未被用户改动的文件跟随更新,用户改过的文件跳过并告警**,解决旧实现"目录已存在就跳过、老用户永远收不到 preset 修复"的问题。首次遇到"已存在但台账未记录"的目录时会尝试**纳入台账**(与包内有内容一致即视为插件早前安装),完全无一致文件的目录视为用户自建,永不触碰。台账损坏/读写失败一律降级为"仅新增",绝不覆盖既有内容。
225
+ - **B|安装开关**:`cohub.installPresets`(默认 `true`)设为 `false` 后本插件完全不再触碰 `~/.dsh/.agent-presets/`,给不需要这些 preset 的部署一个干净出口。
226
+ - **孤儿清理**:包内已不再发布的 preset(曾记录在台账中的)会在加载时从用户目录移除,避免选择器残留幽灵条目;只清理台账确认由本插件安装过的 id,**不碰用户自建目录**。
227
+ - **移除 `cohub-standard`**:其工具面是 `cohub-cordis` 的真子集,详见下方说明。
228
+
229
+ **v0.4.9 修复(preset 无法挂载 → 新会话无法创建)**:这一次修的是**两个独立的挂载期故障**,症状相同(preset 不可用 → 以它为默认 preset 时新会话建不出来),日志都在 `%APPDATA%\DSH Desktop\logs\host\dsh-*.log`。
230
+
231
+ **其一:persona 字段名过时。** `@deepseek-ai/dsh-persona` 的 schema 是 `prefix`(required)/ `suffix`,而两个内置 preset 一直沿用旧字段 `text:`:
232
+
233
+ ```
234
+ [preset-tree] Error: failed to apply loader entry persona (@deepseek-ai/dsh-persona):
235
+ invalid config: - $.prefix missing required value (at prefix)
236
+ ```
237
+
238
+ 已把两个 preset 的字段统一为 `prefix`。
239
+
240
+ **其二:`tool-cordis` 与官方创造模式撞名。** `@deepseek-ai/dsh-tool-cordis` 挂载时会把一组 **Host 级 inspect provider**(`Service` / `Event` / `Builtin` / `Tool`)注册进**进程单例**注册表(`dsh-cordis-host-runner` 的 `CordisInspectRegistryService.register()`:`if (this.providers.has(manifest.id)) throw ...`)。官方 `cordis`(创造模式)preset 同样挂这一行,而 DSH 对同一 preset 共享 standing mount —— 于是两个 preset 在同一进程里各自挂载时必然撞名:
241
+
242
+ ```
243
+ [tool-cordis] Error: Host Cordis inspect provider "Service" is already registered
244
+ [preset-tree] Error: failed to apply loader entry tool-cordis (@deepseek-ai/dsh-tool-cordis):
245
+ Host Cordis inspect provider "Service" is already registered
246
+ ```
247
+
248
+ **v0.4.9 曾把它改由 host 层单次挂载,v0.4.10 已撤销 —— 那是个更糟的修复。** v0.4.9 在 `dsh-cohub` 自带的 `cordis.patch.yml`(bundle 层)里用顶层 `insert`(无 id → 追加到 host 组合)挂了一次:
249
+
250
+ ```yaml
251
+ - insert:
252
+ - id: tool-cordis
253
+ name: '@deepseek-ai/dsh-tool-cordis'
254
+ ```
255
+
256
+ 它的假设是"host 层挂一次,创造模式就不必自己挂了"。但官方 `cordis` preset 是**部署自带、不可修改**的(升级会覆盖),它**仍然会自己挂那一行**,于是 host 层那份变成了抢占者:
257
+
258
+ - 创造模式的 standing mount 失败 → agent 创建在 preset 的 compose 阶段被**回滚** → **每次对话都报 `client api: session/prompt failed: Failed to fetch (gateway/internal)`**;
259
+ - host 同时以 ~10 次/秒重试失败的挂载,日志写到 **10MB/分钟**(一天 200MB+)。
260
+
261
+ 所以 v0.4.10 起:**`tool-cordis` 全进程只由官方「创造模式」挂**。`dsh-cohub` 的 bundle patch 不再插入该行,`cohub-cordis` 也不挂它,而 cohub 插件行照常挂载。
262
+
263
+ **v0.4.11 变更(orchestrator 技能瘦身,2026-10-17)**:`skills/orchestrator.md` 20587 → 15532 bytes(约 -24.6%)。主代理保持纯调度,两层并行/聚合、brief 300、planner 237、批次上限 3 均不变;不伪造 runtime 200K,不自动压缩/硬裁 delegate。规格细节见 [skills/orchestrator.md](skills/orchestrator.md)。
264
+
265
+ > **`cohub-cordis` 因此不含 `cordis_*` 工具**(`cordis_define` / `cordis_run` / `cordis_mount` / `cordis_inspect_*`)。需要 Cordis 自指能力时,请用官方**创造模式**会话;本 preset 用于"标准能力 + cohub 委派纪律"的日常开发。
266
+ >
267
+ > 也**不要**在 profile 的 `cordis.patch.yml` 里 insert 同 id —— 那会重新制造同一个故障。
268
+ >
269
+ > 需要回退时:把 `dsh-cohub` 从 profile `package.json` 的 `dsh.profile.bundles` 移除即可。
270
+
271
+ `test/preset-schema.ts` 现在同时断言:persona 必须 `prefix` 非空、**不得残留 `text:`**、**preset 不得挂 `tool-cordis`**、关键工具行齐全、无制表符缩进、`cohub-standard` 不得复活。
272
+
273
+ > 升级注意:安装台账按「用户是否改过」逐文件保护。若某个 preset 文件**既被用户改过、又需要跟随上游改名**,台账会判为用户改动而跳过自动更新 —— 此时需手动同步(或删除该 preset 目录让插件重新安装)。本次就是这种情况,已在该机器上手动修正。
274
+
275
+ ### 关于 `cohub-standard`(v0.4.7 移除)
276
+
277
+ 原先的 `cohub-standard`(标准模式 + cohub 身份)其 29 行工具面是 `cohub-cordis` 的**真子集**——只少了 `tool-cordis`、`present`、`command-goal`,而两者的 delegate 能力完全相同。因此 v0.4.7 删除该 preset,统一指向 **cohub-cordis**(标准模式全部能力 + 自改运行时)。
278
+
279
+ 对已安装的老用户:插件加载时会读取安装台账,自动移除"曾由本插件安装、但已不再随包发布"的目录,所以重启后选择器里不会再出现它。若你**手动改造过** `~/.dsh/.agent-presets/cohub-standard/`,或该目录早于台账机制存在,它不会被自动清理——按需手动删除即可。
280
+
281
+ ## cohub-cordis agent preset(Phase 5,v0.4.7 新增;v0.4.10 起不含 tool-cordis)
282
+
283
+ `presets/cohub-cordis/` 是 **DSH 官方「创造模式」(`cordis` preset)的骨架 + cohub 中文身份与委派指引**:标准模式的全部工具面、`present` 产物交付、组合创作技能,加上直接可用的 cohub `delegate` / `delegate_batch`。
284
+
285
+ **⚠️ 它不含运行时自改能力(`cordis_*` 工具)**:`tool-cordis` 在 Host 进程级 inspect 注册表里按 id 占位,全进程只能挂一次,而官方创造模式自带这一行(v0.4.10 撤销了 v0.4.9 的 host 层方案,原因见上)。要读写 harness 组合、做 `cordis_mount` 插件实验、动态定义/运行插件,请用官方**创造模式**;本 preset 用于"标准能力 + cohub 委派纪律"的日常开发。
204
286
 
205
- `presets/cohub-standard/` 提供 **DSH 标准 preset 骨架 + cohub 中文身份** 的第二选择——给不需要「纯调度硬约束」、想直接动手 + 调度混合工作流的用户。
287
+ **两者定位**:
206
288
 
207
- **与 co-orchestrator 的关键差异**:
289
+ | preset | 工具模式 | 委派 | 运行时自改 | 适用场景 |
290
+ |---|---|---|---|---|
291
+ | co-orchestrator | 纯调度(不挂 fs/shell/web + persona 软约束) | ✅ delegate | ✗ | 长链调度 / 多模型共识 / 严格自律 |
292
+ | **cohub-cordis** | **标准模式 + 中文身份 + 组合创作技能** | ✅ delegate | ✗(用官方创造模式) | 直接动手 + 委派混合、插件开发日常 |
293
+ | 官方 **创造模式**(`cordis`) | 标准 + **Cordis 自指工具面** | ✅ delegate(host plane,同样可用) | ✅ | 自改 harness / preset 创作 / 插件实验 |
208
294
 
209
- | 维度 | co-orchestrator | cohub-standard |
210
- |---|---|---|
211
- | 工具模式 | Native 模式(不挂载 fs/shell/web + persona 软约束) | 标准模式(直接调工具) |
212
- | fs/shell/web | 不挂载(persona 软约束) | 直接挂载 |
213
- | 委派工具面 | delegate + subagent + ralph + workflow | delegate + subagent + ralph + workflow |
214
- | 适用场景 | 长链调度 / 多模型共识 / 严格自律 | 直接动手 + 调度混合 |
215
- | 调度纪律 | persona 软约束(不可破) | persona 软约束(可自主决定何时自取何时委派) |
295
+ **cohub 能力从哪来**:13 个 co-* 技能与 `delegate` / `delegate_batch` 工具由 dsh-cohub bundle 在 **host plane 全局注册**,与 preset 解耦——所以本 preset 不需要(也没有)额外的委派工具行。已实测确认:`delegate` 与 `delegate_batch` 都出现在会话工具表中,任何 preset 的会话(含创造模式)都能直接用,只要 dsh-cohub 挂在该 profile 上。
216
296
 
217
- **共同点**:
297
+ **使用方式**:agent preset 在会话**首次 turn 之后即锁定**(`agent-preset/locked: session has already started; its agent preset is fixed`),所以创造模式只能**新建会话**时选择,不能中途切换。
218
298
 
219
- - 12 个 co-* 技能 + delegate 工具(host plane 注入,与 preset 解耦)
220
- - 中文 persona + 调度参数(cohub:language / cohub:schedule 段)
221
- - subagent / subagent_fork / ralph / workflow 完整调度工具面
299
+ **自包含技能**:本 preset 自带 `skills/`(`cordis-plugin-development`、`editing-cordis-compositions` 两份组合创作指导),通过 `customSkillDirs` 指向 preset 自身目录,因此无论安装到哪里都能解析。
222
300
 
223
- **自动安装**:与 co-orchestrator 同样在 `apply()` 时复制到 `~/.dsh/.agent-presets/cohub-standard/`。重启后 GUI 的 agent preset 选择器中即可切换。
301
+ > **TRUST**:`cordis_mount` 会对模型写出的 JavaScript 求值并在活动运行时里执行,且本 agent 写出的组合会成为其他会话可挂载的 preset。请把使用本 preset 的会话**等同于 shell 访问权限**对待。
224
302
 
225
303
  ## 测试
226
304
 
227
305
  ```bash
228
- node test/unit.ts # 基础集成(12 技能 + 内容 + brief + delegate 注入 + M4 council)
306
+ node test/unit.ts # 基础集成(13 技能 + 内容 + brief + delegate 注入 + M4 council)
229
307
  node test/delegate-p1.ts # P1:环境契约注入 + 重试
230
308
  node test/stall-p3.ts # P3-1 N2 停滞检测(35 用例)
231
309
  node test/schedule-p3.ts # P3-3 N3 调度参数(24 用例)
232
310
  node test/env-sig-p3.ts # P3-2 N1 环境契约持久化(50 用例)
233
311
  ```
234
312
 
235
- 基线合计 **137 用例全 PASS / 0 FAIL**(node >= 24)。无需 LLM,单测纯本地模拟。
313
+ 基线说明(2026-09-03 实测,`node` 直跑):`unit` 全 PASS + `delegate-p1` 41 + `stall-p3` 35 + `schedule-p3` 24 + `env-sig-p3` 50 + `preset-copy` 13 + `preset-install` 35 + `preset-schema` 28 —— **8/8 全绿,全部 PASS**(node >= 24)。无需 LLM,单测纯本地模拟。
236
314
 
237
315
  ## 目录
238
316
 
@@ -242,20 +320,26 @@ scripts/
242
320
  generate-skills.ts .md → src/skills.ts(必须先跑)
243
321
  build-client.js src/client/index.js → lib/client.js
244
322
  audit-session.mjs 会话导出目录审计 / 回归
323
+ deploy-preset.ps1 手动部署内置 preset 到用户 preset root(幂等,防嵌套)
245
324
  src/
246
- index.ts 插件行入口(apply、Config schema、P3 三切片 schema)
325
+ index.ts 插件行入口(apply、Config schema、P3 三切片 schema、preset 安装接线)
326
+ preset-install.ts 内置 preset 安装/升级台账(未改动则更新、用户改动则跳过、孤儿清理)
247
327
  delegate.ts delegate 工具 + P3-1 StallWatchdog
328
+ env-contract.ts 注入子代理的执行器环境契约文本(含「工具批处理」通用原则)
248
329
  env-signatures.ts P3-2 环境契约持久化(EnvSignatureLearner + 缓存)
249
330
  skills.ts generate-skills.ts 生成物(禁止手编)
250
- client/index.js settings 卡片(i18n + 12 个 P3 控件)
331
+ client/index.js settings 卡片(i18n + 13 个 P3 控件)
251
332
  presets/co-orchestrator/ 内置 agent preset(Phase 2,纯调度模式 + 委派工具面补全 + compaction)
252
- presets/cohub-standard/ 内置 agent preset(Phase 4,标准模式 + 中文身份,v0.3.0 新增)
333
+ presets/cohub-cordis/ 内置 agent preset(Phase 5,创造模式 + 中文身份 + 自包含组合创作技能,v0.4.7 新增)
253
334
  test/
254
335
  unit.ts 基础集成
255
- delegate-p1.ts P1 环境契约注入 + 重试
336
+ delegate-p1.ts P1 环境契约注入 + 重试 + 模型回退
256
337
  stall-p3.ts P3-1 N2 停滞检测
257
338
  schedule-p3.ts P3-3 N3 调度参数
258
339
  env-sig-p3.ts P3-2 N1 环境契约持久化
340
+ preset-copy.ts preset 递归复制(含真实 preset 结构断言)
341
+ preset-install.ts preset 安装/升级台账(用户改动保护 + 孤儿清理 + 降级)
342
+ preset-schema.ts preset YAML schema 断言(persona.prefix / 无 text: / 不挂 tool-cordis / 无 tab 缩进)
259
343
  cordis.patch.yml bundle patch(含 P1/P3 全部 profile 字段示例)
260
344
  ```
261
345
 
package/cordis.patch.yml CHANGED
@@ -46,10 +46,32 @@
46
46
  # use: auto # auto / off / manual
47
47
  # ttlMs: 604800000 # 7 天(到期重探,防环境静默升级)
48
48
  # confirmCount: 2 # 观察一致次数(防瞬态误判)
49
- # schedule(P3-3 N3 调度参数):通过 systemPrompt.section 注入实际生效值(cohub:schedule),
50
- # 子代理与主代理均可见该段;text 为函数,settings 卡片改了立即重读无需重启。
49
+ # schedule(P3-3 N3 调度参数):运行时代码直接读取 settings 使用。
50
+ # useJobTracking / adaptiveBatch 已于 2026-09-03 移除(死参数)。
51
51
  # schedule:
52
52
  # maxParallelBatch: 3 # 单批并行委派上限(本环境观测值,部署可调)
53
53
  # wallClockBudgetMs: 600000 # 单次执行单元墙钟预算(10 分钟)
54
- # useJobTracking: auto # auto / on / off(auto = 有 job 能力则后台跟踪)
55
- # adaptiveBatch: auto # auto / off(auto = 提示词级按本会话已观测错误/超时收放批大小)
54
+
55
+ # ── tool-cordis:本文件【刻意不挂】────────────────────────────────────────────
56
+ # @deepseek-ai/dsh-tool-cordis 会把一组 Host 级 inspect provider(Service /
57
+ # Event / Builtin / Tool)注册进**进程单例**注册表;dsh-cordis-host-runner 的
58
+ # CordisInspectRegistryService.register() 见到同名 id 直接抛错:
59
+ # Error: Host Cordis inspect provider "Service" is already registered
60
+ #
61
+ # 官方「创造模式」(dsh-agent-presets 的 `cordis` preset)**自带这一行**,它是
62
+ # 部署自带的 preset,不能改(升级会覆盖),而一个 preset 的 standing mount 又由
63
+ # DSH 共享并常驻(dsh-agent-presets 的 ensureStanding)。因此任何第二份挂载 ——
64
+ # 不管在别的 preset 里,还是这里的 host 层顶层 insert —— 都会让创造模式的
65
+ # standing mount 失败:
66
+ # [preset-tree] Error: failed to apply loader entry tool-cordis (...)
67
+ # 而 agent 创建就发生在 preset 的 compose 阶段(setup 里 ensureStanding),失败
68
+ # 会回滚 agent 创建,表现为每次对话都报:
69
+ # client api: session/prompt failed: Failed to fetch (gateway/internal)
70
+ #
71
+ # 这正是 v0.4.9 发布后的实际故障:官方创造模式(默认 preset 之一)会话几乎无法
72
+ # 对话,host 同时以 ~10 次/秒重试失败的挂载,日志写到 10MB/分钟。v0.4.10 撤销了
73
+ # 这里的 insert —— 全进程只由官方创造模式挂它。
74
+ #
75
+ # cohub-cordis 需要 cordis_define / cordis_run / cordis_mount / cordis_inspect_*
76
+ # 时,直接用官方**创造模式**会话(见 README「cohub-cordis agent preset」一节)。
77
+ # 本文件其余部分只挂 cohub 插件行,不受影响。
package/lib/client.js CHANGED
@@ -47,13 +47,6 @@ window.__ModuleLoader__.load({
47
47
  batchSize: "批大小(单批并行委派上限)",
48
48
  wallClock: "墙钟预算(毫秒)",
49
49
  maxRetries: "委派重试上限(0 = 不重试)",
50
- useJobTrackingLabel: "Job 跟踪",
51
- adaptiveBatchLabel: "批间自适应",
52
- useJobTrackingAuto: "auto(自动)",
53
- useJobTrackingOn: "on(启用)",
54
- useJobTrackingOff: "off(关闭)",
55
- adaptiveBatchAuto: "auto(自适应)",
56
- adaptiveBatchOff: "off(固定)",
57
50
  retryDelayMs: "重试间隔(毫秒)",
58
51
  retryableReasons: "可重试原因(逗号分隔)",
59
52
  retryableReasonsHint: "如 aborted, error;未知原因不重试",
@@ -101,13 +94,6 @@ window.__ModuleLoader__.load({
101
94
  batchSize: "Batch size (max parallel delegates)",
102
95
  wallClock: "Wall-clock budget (ms)",
103
96
  maxRetries: "Delegate retry limit (0 = no retry)",
104
- useJobTrackingLabel: "Job tracking",
105
- adaptiveBatchLabel: "Adaptive batch",
106
- useJobTrackingAuto: "auto (automatic)",
107
- useJobTrackingOn: "on (enabled)",
108
- useJobTrackingOff: "off (disabled)",
109
- adaptiveBatchAuto: "auto (adaptive)",
110
- adaptiveBatchOff: "off (fixed)",
111
97
  retryDelayMs: "Retry delay (ms)",
112
98
  retryableReasons: "Retryable reasons (comma-separated)",
113
99
  retryableReasonsHint: "e.g. aborted, error; unknown reasons will not retry",
@@ -332,9 +318,7 @@ window.__ModuleLoader__.load({
332
318
  var s = snapshot.value && snapshot.value.schedule;
333
319
  return {
334
320
  maxParallelBatch: s && typeof s.maxParallelBatch === "number" ? s.maxParallelBatch : 3,
335
- wallClockBudgetMs: s && typeof s.wallClockBudgetMs === "number" ? s.wallClockBudgetMs : 600000,
336
- useJobTracking: s && typeof s.useJobTracking === "string" ? s.useJobTracking : "auto",
337
- adaptiveBatch: s && typeof s.adaptiveBatch === "string" ? s.adaptiveBatch : "auto"
321
+ wallClockBudgetMs: s && typeof s.wallClockBudgetMs === "number" ? s.wallClockBudgetMs : 600000
338
322
  };
339
323
  });
340
324
  var [retryDraft, setRetryDraft] = React.useState(function () {
@@ -379,9 +363,7 @@ window.__ModuleLoader__.load({
379
363
  var s = snapshot.value && snapshot.value.schedule;
380
364
  setScheduleDraft({
381
365
  maxParallelBatch: s && typeof s.maxParallelBatch === "number" ? s.maxParallelBatch : 3,
382
- wallClockBudgetMs: s && typeof s.wallClockBudgetMs === "number" ? s.wallClockBudgetMs : 600000,
383
- useJobTracking: s && typeof s.useJobTracking === "string" ? s.useJobTracking : "auto",
384
- adaptiveBatch: s && typeof s.adaptiveBatch === "string" ? s.adaptiveBatch : "auto"
366
+ wallClockBudgetMs: s && typeof s.wallClockBudgetMs === "number" ? s.wallClockBudgetMs : 600000
385
367
  });
386
368
  var r = snapshot.value && snapshot.value.delegateRetry;
387
369
  setRetryDraft({
@@ -541,9 +523,7 @@ window.__ModuleLoader__.load({
541
523
  var s = snapshot.value && snapshot.value.schedule;
542
524
  setScheduleDraft({
543
525
  maxParallelBatch: s && typeof s.maxParallelBatch === "number" ? s.maxParallelBatch : 3,
544
- wallClockBudgetMs: s && typeof s.wallClockBudgetMs === "number" ? s.wallClockBudgetMs : 600000,
545
- useJobTracking: s && typeof s.useJobTracking === "string" ? s.useJobTracking : "auto",
546
- adaptiveBatch: s && typeof s.adaptiveBatch === "string" ? s.adaptiveBatch : "auto"
526
+ wallClockBudgetMs: s && typeof s.wallClockBudgetMs === "number" ? s.wallClockBudgetMs : 600000
547
527
  });
548
528
  var r = snapshot.value && snapshot.value.delegateRetry;
549
529
  setRetryDraft({
@@ -600,9 +580,7 @@ window.__ModuleLoader__.load({
600
580
  if (!Number.isFinite(wall) || wall < 0) wall = 600000;
601
581
  await scope.set("schedule", {
602
582
  maxParallelBatch: batch,
603
- wallClockBudgetMs: wall,
604
- useJobTracking: scheduleDraft.useJobTracking || "auto",
605
- adaptiveBatch: scheduleDraft.adaptiveBatch || "auto"
583
+ wallClockBudgetMs: wall
606
584
  });
607
585
  }
608
586
  if (retryTouched || stallTouched) {
@@ -717,12 +695,16 @@ window.__ModuleLoader__.load({
717
695
  React.createElement("option", { value: "" }, t("loading"))
718
696
  );
719
697
  } else if (models.length > 0) {
698
+ // 未保存 model 时插入一个 value="" 的占位项。否则 <select value=""> 会被浏览器
699
+ // 渲染成列表第一项,让人误以为「已经选好了模型」,而实际保存值仍是空 —— 服务端随后
700
+ // 只能继承父会话模型并可能以 UNKNOWN_MODEL 失败。
701
+ var modelSelectOptions = [React.createElement("option", { key: "__inherit", value: "" }, t("modelPlaceholder"))].concat(modelOptions);
720
702
  modelControl = React.createElement("select", {
721
703
  className: "cohub-select",
722
- value: row.model,
704
+ value: row.model || "",
723
705
  disabled: !writable,
724
706
  onChange: function (event) { update(skill.name, "model", event.target.value); }
725
- }, modelOptions);
707
+ }, modelSelectOptions);
726
708
  } else {
727
709
  modelControl = React.createElement("input", {
728
710
  className: "cohub-input",
@@ -785,21 +767,6 @@ window.__ModuleLoader__.load({
785
767
  React.createElement("div", { className: "cohub-field" },
786
768
  React.createElement("label", { className: "cohub-label" }, t("wallClock")),
787
769
  React.createElement("input", { className: "cohub-input", type: "number", min: 0, step: 1000, value: scheduleDraft.wallClockBudgetMs, disabled: !writable, onChange: function (event) { updateSchedule("wallClockBudgetMs", event.target.value); } })
788
- ),
789
- React.createElement("div", { className: "cohub-field" },
790
- React.createElement("label", { className: "cohub-label" }, t("useJobTrackingLabel")),
791
- React.createElement("select", { className: "cohub-select", value: scheduleDraft.useJobTracking, disabled: !writable, onChange: function (event) { updateSchedule("useJobTracking", event.target.value); } },
792
- React.createElement("option", { value: "auto" }, t("useJobTrackingAuto")),
793
- React.createElement("option", { value: "on" }, t("useJobTrackingOn")),
794
- React.createElement("option", { value: "off" }, t("useJobTrackingOff"))
795
- )
796
- ),
797
- React.createElement("div", { className: "cohub-field" },
798
- React.createElement("label", { className: "cohub-label" }, t("adaptiveBatchLabel")),
799
- React.createElement("select", { className: "cohub-select", value: scheduleDraft.adaptiveBatch, disabled: !writable, onChange: function (event) { updateSchedule("adaptiveBatch", event.target.value); } },
800
- React.createElement("option", { value: "auto" }, t("adaptiveBatchAuto")),
801
- React.createElement("option", { value: "off" }, t("adaptiveBatchOff"))
802
- )
803
770
  )
804
771
  )
805
772
  ),
@@ -0,0 +1,192 @@
1
+ // src/co-cordis-plugin.ts
2
+ import { defineTool } from "@deepseek-ai/dsh-tools";
3
+ var name = "co-cordis-plugin";
4
+ var inject = ["tools", "cordisInspect", "dynamicCordisRunner"];
5
+ function requireAgent(exec) {
6
+ if (exec.agent === undefined)
7
+ throw new Error("co-cordis 工具需要 Agent 支持的会话");
8
+ return exec.agent;
9
+ }
10
+ function apply(ctx) {
11
+ ctx.tools.register(defineTool({
12
+ name: "co_inspect_list",
13
+ description: "列出 Host 端所有已知的 Cordis Inspect Provider,包含它们的平台、目的、方法名与输入/输出 schema。调用此工具后再用 co_inspect_query 查具体定义。",
14
+ parameters: {},
15
+ output: { schema: { type: "json" }, render: (_a, v) => [{ type: "text", text: JSON.stringify(v, null, 2) }] },
16
+ execute() {
17
+ return Promise.resolve({ providers: ctx.cordisInspect.list() });
18
+ }
19
+ }));
20
+ ctx.tools.register(defineTool({
21
+ name: "co_inspect_query",
22
+ description: "按 platform + provider + method 查一个 Inspect Provider 的具体结构化定义。platform 和 provider 必须来自 co_inspect_list 的返回结果。输入格式必须满足该 method 的 inputSchema。Host 查询在本地执行。此工具只读,不能调用业务 Service 方法或修改运行时。",
23
+ parameters: {
24
+ platform: { type: "string", required: true, enum: ["host", "client"], description: "Provider 所属运行时平台" },
25
+ provider: { type: "string", required: true, description: "Provider ID(来自 co_inspect_list)" },
26
+ method: { type: "string", required: true, description: "方法名(来自 co_inspect_list)" },
27
+ input: { type: "json", description: "查询输入(可选);必须满足该方法的 inputSchema" }
28
+ },
29
+ output: { schema: { type: "json" }, render: (_a, v) => [{ type: "text", text: JSON.stringify(v, null, 2) }] },
30
+ async execute(args, exec) {
31
+ const agent = requireAgent(exec);
32
+ const data = await ctx.cordisInspect.query(args.platform, args.provider, args.method, args.input, agent, exec.signal);
33
+ return { platform: args.platform, provider: args.provider, method: args.method, data };
34
+ }
35
+ }));
36
+ ctx.tools.register(defineTool({
37
+ name: "co_inspect_self",
38
+ description: "查当前会话通过 co_define / co_run 管理的动态 Cordis 插件清单。无参数时列出所有插件摘要;传入 pluginId 时返回该插件的简要状态与包列表;同时传入 pluginId + packageId 时返回该不可变包的具体源码与运行时诊断。",
39
+ parameters: {
40
+ pluginId: { type: "string", description: "插件 ID(省略时列出全部);必须与 packageId 同时传入才能查具体包" },
41
+ packageId: { type: "string", description: "包的不可变 ID;需要 pluginId 一起传入" }
42
+ },
43
+ output: { schema: { type: "json" }, render: (_a, v) => [{ type: "text", text: JSON.stringify(v, null, 2) }] },
44
+ execute(args, exec) {
45
+ const agent = requireAgent(exec);
46
+ if (args.packageId !== undefined && args.pluginId === undefined)
47
+ throw new Error("co_inspect_self: packageId 需要 pluginId 一起传入");
48
+ if (args.pluginId === undefined) {
49
+ return Promise.resolve({
50
+ mode: "plugins",
51
+ plugins: ctx.dynamicCordisRunner.listPlugins(agent).map((ref) => ({
52
+ pluginId: String(ref.pluginId),
53
+ name: ref.name,
54
+ purpose: ref.purpose,
55
+ status: ref.status,
56
+ currentPackageId: String(ref.currentPackageId),
57
+ nextPackageId: ref.nextPackageId !== undefined ? String(ref.nextPackageId) : undefined
58
+ }))
59
+ });
60
+ }
61
+ const plugin = ctx.dynamicCordisRunner.inspectPlugin(agent, args.pluginId);
62
+ if (args.packageId === undefined) {
63
+ return Promise.resolve({
64
+ mode: "plugin",
65
+ pluginId: String(plugin.pluginId),
66
+ name: plugin.name,
67
+ purpose: plugin.purpose,
68
+ status: plugin.status,
69
+ packages: plugin.packages.map((pkg) => ({
70
+ packageId: String(pkg.packageId),
71
+ isCurrent: pkg.packageId === plugin.currentPackageId,
72
+ isNext: pkg.packageId === plugin.nextPackageId
73
+ }))
74
+ });
75
+ }
76
+ const pkg = ctx.dynamicCordisRunner.inspectPackage(agent, args.pluginId, args.packageId);
77
+ return Promise.resolve({
78
+ mode: "package",
79
+ packageId: String(pkg.packageId),
80
+ name: pkg.name,
81
+ purpose: pkg.purpose,
82
+ source: pkg.source,
83
+ diagnostics: pkg.diagnostics
84
+ });
85
+ }
86
+ }));
87
+ ctx.tools.register(defineTool({
88
+ name: "co_define",
89
+ description: "定义一个不可变的 Cordis Package。新建 Plugin 用 kind:'new'(提供 3-6 个小写字母前缀);给已有 Plugin 追加用 kind:'existing'。至少提供 code.host 和 code.client 其中之一。每个 value 是一个返回 Cordis Plugin 的纯 JavaScript 函数体;无 TypeScript/JSX。定义完成后再用 co_run 激活。",
90
+ parameters: {
91
+ plugin: {
92
+ required: true,
93
+ oneOf: [{
94
+ type: "object",
95
+ additionalProperties: false,
96
+ properties: { kind: { type: "string", const: "new", required: true }, idPrefix: { type: "string", required: true, description: "3-6 个小写字母语义前缀" } }
97
+ }, {
98
+ type: "object",
99
+ additionalProperties: false,
100
+ properties: { kind: { type: "string", const: "existing", required: true }, pluginId: { type: "string", required: true, description: "已有 Plugin 的精确 ID" } }
101
+ }]
102
+ },
103
+ name: { type: "string", required: true, description: "简短可读的包名" },
104
+ purpose: { type: "string", required: true, description: "一句话用途说明" },
105
+ code: {
106
+ type: "object",
107
+ additionalProperties: false,
108
+ required: true,
109
+ properties: {
110
+ host: { type: "string", description: "返回 Host 端 Cordis Plugin 的 JS 函数体" },
111
+ client: { type: "string", description: "返回 Client(浏览器)端 Cordis Plugin 的 JS 函数体" }
112
+ }
113
+ }
114
+ },
115
+ output: {
116
+ schema: { type: "object", properties: { pluginId: { type: "string", required: true }, packageId: { type: "string", required: true }, name: { type: "string", required: true }, purpose: { type: "string", required: true }, hasHostHalf: { type: "boolean" }, hasClientHalf: { type: "boolean" } }, additionalProperties: false },
117
+ render: (_a, v) => [{ type: "text", text: `已定义 ${v.pluginId}/${v.packageId} (${v.name});尚未运行,用 co_run 激活。` }]
118
+ },
119
+ execute(args, _exec) {
120
+ const plugin = args.plugin.kind === "new" ? { kind: "new", idPrefix: args.plugin.idPrefix } : { kind: "existing", pluginId: args.plugin.pluginId };
121
+ const receipt = ctx.dynamicCordisRunner.define({
122
+ sessionId: requireAgent(_exec).id,
123
+ plugin,
124
+ name: args.name,
125
+ purpose: args.purpose,
126
+ code: {
127
+ ...args.code.host === undefined ? {} : { host: args.code.host },
128
+ ...args.code.client === undefined ? {} : { client: args.code.client }
129
+ }
130
+ });
131
+ return Promise.resolve({
132
+ pluginId: String(receipt.pluginId),
133
+ packageId: String(receipt.packageId),
134
+ name: receipt.name,
135
+ purpose: receipt.purpose,
136
+ hasHostHalf: receipt.hasHostHalf,
137
+ hasClientHalf: receipt.hasClientHalf
138
+ });
139
+ }
140
+ }));
141
+ ctx.tools.register(defineTool({
142
+ name: "co_run",
143
+ description: "激活一个动态插件。首次激活或重启用 mode:'run';切换到同一 Plugin 下的另一个已定义 Package 用 mode:'update'。Client 端激活可能需要用户审批(返回 awaiting-approval);Host 端激活成功后返回 running。",
144
+ parameters: {
145
+ pluginId: { type: "string", required: true, description: "Plugin ID(来自 co_define 的返回)" },
146
+ packageId: { type: "string", required: true, description: "Package ID(来自 co_define 的返回)" },
147
+ mode: { type: "string", required: true, enum: ["run", "update"], description: "run=首次/重启/回滚;update=切换到同一 Plugin 不同版本" }
148
+ },
149
+ output: { schema: { type: "json" }, render: (_a, v) => [{ type: "text", text: JSON.stringify(v, null, 2) }] },
150
+ async execute(args, exec) {
151
+ const agent = requireAgent(exec);
152
+ const receipt = await ctx.dynamicCordisRunner.run(agent, args.pluginId, args.packageId, args.mode, exec.signal);
153
+ if (!receipt.ok)
154
+ throw new Error(receipt.message);
155
+ return {
156
+ status: receipt.status,
157
+ pluginId: args.pluginId,
158
+ packageId: args.packageId,
159
+ pluginRunId: String(receipt.pluginRunId),
160
+ mode: receipt.mode,
161
+ ...receipt.currentPackageId === undefined ? {} : { currentPackageId: String(receipt.currentPackageId) },
162
+ nextPackageId: String(receipt.nextPackageId),
163
+ ...receipt.hostStatus === undefined ? {} : { hostStatus: receipt.hostStatus }
164
+ };
165
+ }
166
+ }));
167
+ ctx.tools.register(defineTool({
168
+ name: "co_stop",
169
+ description: "停止一个正在运行的动态 Plugin。保留其定义、版本指针与审批记录,可以后续用 co_run 重新激活或回滚。要彻底删除用 co_remove。",
170
+ parameters: { pluginId: { type: "string", required: true, description: "要停止的 Plugin ID" } },
171
+ output: { schema: { type: "object", properties: { stopped: { type: "boolean" } }, additionalProperties: false } },
172
+ async execute(args, exec) {
173
+ await ctx.dynamicCordisRunner.stop(requireAgent(exec), args.pluginId);
174
+ return { stopped: true };
175
+ }
176
+ }));
177
+ ctx.tools.register(defineTool({
178
+ name: "co_remove",
179
+ description: "彻底删除一个动态 Plugin:先停止运行、取消审批请求,然后删除所有版本与授权。执行后其 pluginId、packageId 和 @ 引用全部失效。要保留版本以便重新激活用 co_stop。",
180
+ parameters: { pluginId: { type: "string", required: true, description: "要彻底删除的 Plugin ID" } },
181
+ output: { schema: { type: "object", properties: { removed: { type: "boolean" } }, additionalProperties: false } },
182
+ async execute(args, exec) {
183
+ await ctx.dynamicCordisRunner.undefine(requireAgent(exec), args.pluginId);
184
+ return { removed: true };
185
+ }
186
+ }));
187
+ }
188
+ export {
189
+ apply,
190
+ inject,
191
+ name
192
+ };