dsh-cohub 0.1.0 → 0.4.2

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,7 +1,7 @@
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
+ 把「纯调度模式 + 12 专职代理 + 多模型共识 + 运行期调度韧性」移植到 DSH 原生能力之上。
5
5
 
6
6
  ## 与 OpenCode 版的机制映射
7
7
 
@@ -15,7 +15,11 @@ DeepSeek Harness 版 [oh-my-opencode-cohub](https://github.com/Mr-cjf/oh-my-open
15
15
  | ContextEngine 上下文提取 | subagent_fork 继承会话(删除) |
16
16
  | council_session 工具 | M4:workflow 并行 + provider/model 覆盖 |
17
17
  | TUI 面板 | DSH Web GUI 原生面板(删除) |
18
- | CLI 安装器 | dsh plugin add(删除) |
18
+ | CLI 安装器 | dsh plugin add(转发 pnpm) |
19
+ | **M2/M3/M4 调度韧性**(N2 停滞检测 / N3 调度参数) | **P3-1/P3-3 切片**(stall 检测器 + schedule 配置 + systemPrompt 段) |
20
+ | **环境契约一次学习持续使用**(N1) | **P3-2 切片**(envSignatures 模块 + 缓存到 `~/.dsh/cohub/env-signatures.json`) |
21
+
22
+ > 注:`dsh plugin add` 不是 CLI 独立子命令,而是把参数转发给 profile 目录内的 `pnpm`(`dsh plugin --profile <name> add <pkg>` ≡ 在该 profile 执行 `pnpm add <pkg>`),安装后自动把声明 `dsh.bundle` 的依赖加入 `dsh.profile.bundles`。
19
23
 
20
24
  ## 技能清单(12 个)
21
25
 
@@ -29,34 +33,50 @@ co-rule-user / co-rule-project / co-rule-app(规范分析)
29
33
  前置:系统 bun(与主仓库一致)。
30
34
 
31
35
  ```bash
32
- cd dsh-port
33
- npm run build # generate-skills.ts 生成 src/skills.ts → bun build → lib/index.js
36
+ cd dsh-cohub
37
+ npm run build
38
+ # 等价于:
39
+ # bun run scripts/generate-skills.ts # 生成 src/skills.ts
40
+ # bun build src/index.ts --outdir lib --target node --format esm \
41
+ # --external @deepseek-ai/cordis --external @deepseek-ai/schemastery \
42
+ # --external @deepseek-ai/dsh-tools --external @deepseek-ai/dsh-system-prompt \
43
+ # --external @deepseek-ai/dsh-skill --external @deepseek-ai/dsh-home-paths \
44
+ # --external @deepseek-ai/dsh-settings
45
+ # bun run scripts/build-client.js # src/client/index.js → lib/client.js
34
46
  ```
35
47
 
36
48
  ## 安装到 profile
37
49
 
38
50
  ```bash
39
- dsh plugin --profile web add <本目录>
51
+ dsh plugin --profile web add dsh-cohub
52
+ ```
53
+
54
+ 本地开发安装:
55
+
56
+ ```bash
57
+ dsh plugin --profile web add C:\Users\14023\Desktop\dsh-cohub
40
58
  ```
41
59
 
42
60
  或手动:profile 的 package.json
43
61
 
44
62
  ```json
45
63
  {
46
- "dependencies": { "dsh-cohub": "file:../dsh-port" },
64
+ "dependencies": { "dsh-cohub": "file:../dsh-cohub" },
47
65
  "dsh": { "profile": { "bundles": ["@deepseek-ai/dsh-base", "dsh-cohub"] } }
48
66
  }
49
67
  ```
50
68
 
51
69
  ## 配置(profile 的 cordis.patch.yml,按行 id "cohub" 覆盖)
52
70
 
71
+ 最小配置(不开 council):
72
+
53
73
  ```yaml
54
74
  - id: cohub
55
75
  name: 'dsh-cohub'
56
76
  config:
57
77
  councillors: [] # 为空则不注册 council_session 工具
58
78
  councilTimeoutMs: 180000
59
- councilProvider: spawn
79
+ skills: [] # delegate 委派路由(可用 settings.yaml 的 cohub.skills 覆盖)
60
80
  ```
61
81
 
62
82
  **M4 启用 council**(councillors 非空时自动注册 council_session 工具):
@@ -71,7 +91,44 @@ dsh plugin --profile web add <本目录>
71
91
  - { name: expert3, provider: deepseek-official, model: deepseek-v4-pro, prompt: 你是首席架构师,先列风险再给结论 }
72
92
  ```
73
93
 
74
- council_session 由配置了 councillors 的部署自动提供给模型;模型端约定由 co-council 技能使用。
94
+ **P3 完整配置**(cordis.patch.yml 18 行起所有注释块都是可选 profile 覆盖):
95
+
96
+ ```yaml
97
+ - id: cohub
98
+ name: 'dsh-cohub'
99
+ config:
100
+ # delegateEnvContract:环境契约注入(默认开)。部署已知环境可覆盖 text 跳过探测:
101
+ delegateEnvContract: { enabled: true }
102
+ # delegateRetry:中止/失败自动重试。默认不重试(保持现状)。
103
+ # P3-1 N2 停滞检测:默认关闭(enabled=false),启用后在 spawn 子代理时挂 StallWatchdog,
104
+ # 按 session/event 在线估计 S1-S4 信号并提前中止(复用 delegateRetry 重试预算)。
105
+ delegateRetry:
106
+ maxRetries: 2
107
+ retryDelayMs: 1500
108
+ retryableReasons: ["aborted"]
109
+ stall:
110
+ enabled: true
111
+ consecutiveErrors: 3 # S1 连续同类错误阈值
112
+ idleMs: 180000 # S2 无结果空转毫秒
113
+ reasoningWithoutAction: 50 # S3 纯推理无动作阈值
114
+ loopCount: 3 # S4 同工具名 + 同参数重复次数
115
+ graceMs: 30000 # 宽限窗口
116
+ recoverable: true # 触发后按 retryableReasons 判定
117
+ # P3-2 N1 环境契约持久化:默认 auto(无缓存时行为不变)。
118
+ # 累计同一归一化签名达 confirmCount 次后写入 dshHomePath("cohub","env-signatures.json")。
119
+ envSignatures:
120
+ use: auto # auto / off / manual
121
+ ttlMs: 604800000 # 7 天
122
+ confirmCount: 2
123
+ # P3-3 N3 调度参数:通过 systemPrompt.section 注入实际生效值(cohub:schedule),子代理可见。
124
+ schedule:
125
+ maxParallelBatch: 3
126
+ wallClockBudgetMs: 600000
127
+ useJobTracking: auto # auto / on / off
128
+ adaptiveBatch: auto # auto / off
129
+ ```
130
+
131
+ 完整字段含义与缺省见 [`cordis.patch.yml`](cordis.patch.yml) 顶部注释块。
75
132
 
76
133
  ## 使用
77
134
 
@@ -79,9 +136,60 @@ council_session 由配置了 councillors 的部署自动提供给模型;模型
79
136
  2. 按提示词流程:信息收集(并行 subagent)→ co-planner 方案 → 审核 → 执行 → 验证
80
137
  3. 子代理统一通过 DSH 原生 subagent 工具委派,后台任务走 job board
81
138
 
139
+ ### settings 卡片
140
+
141
+ `npm run build` 后重启 DSH,打开设置 → **插件** 标签,可看到「CoHub 代理模型」卡片:
142
+
143
+ - **12 个 skill 行**(每个独立配置 provider / model)
144
+ - **调度参数(可选)**:批大小 / 墙钟预算 / Job 跟踪 / 批间自适应
145
+ - **委派重试 / 重试间隔**:maxRetries / retryDelayMs / 可重试原因(逗号分隔)
146
+ - **停滞检测(可选)**:启用复选框 + 5 个阈值 + 可重试复选框(未启用时数字输入框 disabled)
147
+ - **环境契约持久化(可选)**:契约模式(auto/off/manual)/ 缓存 TTL / 确认次数
148
+
149
+ 改卡片后无需重启即生效(`text` 是函数,每次 prompt 装配时动态读取当前 settings)。
150
+
151
+ ### 环境契约持久化
152
+
153
+ `envSignatures.use="auto"` 时:
154
+
155
+ - 累计同一归一化错误签名(`err:<msg>#`)出现 ≥ `confirmCount`(缺省 2)次
156
+ - 写入 `~/.dsh/cohub/env-signatures.json`(插件自管,不依赖 settings)
157
+ - 下次 spawn 命中缓存(指纹一致 + TTL 内)→ 用确定性契约文本前馈注入,跳过探针
158
+
159
+ `use="off"` 不读不写,每次都走 DEFAULT_ENV_CONTRACT 探针式。
160
+ `use="manual"` 只读 manual 配置(schema 中 `contract` 字段,部署可静态指定),不学习。
161
+
162
+ ### 停滞检测
163
+
164
+ `delegateRetry.stall.enabled=true` 时启用:
165
+
166
+ - 通过 `ctx.on("session/event")` 监听 session/event 全局事件总线,按 `run.id` 归属子代理事件
167
+ - 四类噪声信号:S1 连续同类错误 / S2 无结果空转 / S3 纯推理无动作 / S4 重复调用循环
168
+ - 触发条件:`S1 ∪ (S2 ∪ S3 ∪ S4)` **且**距最近一次成功工具结果超过 `graceMs`(最近成功过不触发)
169
+ - 触发后 `ac.abort()` 提前中止,复用 `delegateRetry` 重试预算(`recoverable=true`)
170
+ - T3:父 `exec.signal` 中止通过内部 `AbortController` 转发到子代理
171
+ - 降级:若 `ctx.on` 缺失(无事件源),自动降级关闭,看门狗完全不介入(维持现状)
172
+ - `error.cause.stall` 写入结构化信息 `{ signals: [...], diagnostics: "..." }`
173
+
174
+ 无事件源的部署会自动降级,不会因缺失 session/event 而崩。
175
+
176
+ ### 会话审计
177
+
178
+ 会话导出目录(含根 `session.jsonl` + `subagents/.../session.jsonl`)可跑:
179
+
180
+ ```bash
181
+ npm run audit -- <sessionDir> [--rules <json>] [--rules-file <path>] [--json <out>]
182
+ ```
183
+
184
+ 输出工具调用/结果/错误、错误类别、通用"重复盲试"、委派树、墙钟超时与环境签名。完整规则与退出码见 `scripts/audit-session.mjs` 顶部注释。
185
+
82
186
  ## co-orchestrator agent preset(Phase 2)
83
187
 
84
- `presets/co-orchestrator/` 提供调度者主代理身份(persona + 调度工具面:subagent/fork/workflow/ralph/skill/todo/jobs/ask-user/goal)。安装:
188
+ `presets/co-orchestrator/` 提供调度者主代理身份(persona + 调度工具面:subagent/fork/workflow/skill/todo/jobs/ask-user/goal + compaction)。
189
+
190
+ **自动安装**:本包在 `apply` 时会把内置 preset 复制到 `~/.dsh/.agent-presets/co-orchestrator/`(幂等,不覆盖你已修改的同名 preset)。`dsh plugin --profile web add dsh-cohub` 装完重启后,即可在 GUI 的 agent preset 选择器中切换,无需手动操作。
191
+
192
+ 若 preset 未出现(例如本地源码开发、或想手动摆放),可兜底执行:
85
193
 
86
194
  ```bash
87
195
  mkdir -p ~/.dsh/.agent-presets/co-orchestrator
@@ -90,15 +198,65 @@ cp presets/co-orchestrator/* ~/.dsh/.agent-presets/co-orchestrator/
90
198
 
91
199
  在 GUI 的 agent preset 选择器中切换。注意(rc.6 限制):子代理继承父代理的 preset 组合且 toolFilter 只能收窄,因此 preset 不硬性移除文件工具——「绝不亲自操作文件」由 co-orchestrator 技能在提示词层约束(与 OpenCode 原版一致)。
92
200
 
201
+ **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
+
203
+ ## cohub-standard agent preset(Phase 4,v0.3.0 新增)
204
+
205
+ `presets/cohub-standard/` 提供 **DSH 标准 preset 骨架 + cohub 中文身份** 的第二选择——给不需要「纯调度硬约束」、想直接动手 + 调度混合工作流的用户。
206
+
207
+ **与 co-orchestrator 的关键差异**:
208
+
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 软约束(可自主决定何时自取何时委派) |
216
+
217
+ **共同点**:
218
+
219
+ - 12 个 co-* 技能 + delegate 工具(host plane 注入,与 preset 解耦)
220
+ - 中文 persona + 调度参数(cohub:language / cohub:schedule 段)
221
+ - subagent / subagent_fork / ralph / workflow 完整调度工具面
222
+
223
+ **自动安装**:与 co-orchestrator 同样在 `apply()` 时复制到 `~/.dsh/.agent-presets/cohub-standard/`。重启后 GUI 的 agent preset 选择器中即可切换。
224
+
225
+ ## 测试
226
+
227
+ ```bash
228
+ node test/unit.ts # 基础集成(12 技能 + 内容 + brief + delegate 注入 + M4 council)
229
+ node test/delegate-p1.ts # P1:环境契约注入 + 重试
230
+ node test/stall-p3.ts # P3-1 N2 停滞检测(35 用例)
231
+ node test/schedule-p3.ts # P3-3 N3 调度参数(24 用例)
232
+ node test/env-sig-p3.ts # P3-2 N1 环境契约持久化(50 用例)
233
+ ```
234
+
235
+ 基线合计 **137 用例全 PASS / 0 FAIL**(node >= 24)。无需 LLM,单测纯本地模拟。
236
+
93
237
  ## 目录
94
238
 
95
239
  ```
96
- skills/ 提示词源文件(.md,人工编辑)
97
- scripts/ generate-skills.ts(.md → src/skills.ts)
98
- src/ 插件行入口 + 生成物(council.ts = M4 共识工具)
99
- presets/ co-orchestrator agent preset(Phase 2)
100
- test/ unit.ts 运行时单测(node test/unit.ts,无需 LLM)
101
- cordis.patch.yml bundle patch(挂载本包到 profile 组合)
240
+ skills/ 提示词源文件(.md,人工编辑;scripts/generate-skills.ts 据此生成 src/skills.ts)
241
+ scripts/
242
+ generate-skills.ts .md → src/skills.ts(必须先跑)
243
+ build-client.js src/client/index.js lib/client.js
244
+ audit-session.mjs 会话导出目录审计 / 回归
245
+ src/
246
+ index.ts 插件行入口(apply、Config schema、P3 三切片 schema)
247
+ delegate.ts delegate 工具 + P3-1 StallWatchdog
248
+ env-signatures.ts P3-2 环境契约持久化(EnvSignatureLearner + 缓存)
249
+ skills.ts generate-skills.ts 生成物(禁止手编)
250
+ client/index.js settings 卡片(i18n + 12 个 P3 控件)
251
+ presets/co-orchestrator/ 内置 agent preset(Phase 2,纯调度模式 + 委派工具面补全 + compaction)
252
+ presets/cohub-standard/ 内置 agent preset(Phase 4,标准模式 + 中文身份,v0.3.0 新增)
253
+ test/
254
+ unit.ts 基础集成
255
+ delegate-p1.ts P1 环境契约注入 + 重试
256
+ stall-p3.ts P3-1 N2 停滞检测
257
+ schedule-p3.ts P3-3 N3 调度参数
258
+ env-sig-p3.ts P3-2 N1 环境契约持久化
259
+ cordis.patch.yml bundle patch(含 P1/P3 全部 profile 字段示例)
102
260
  ```
103
261
 
104
- > DSH 处于 0.1.0-rc 阶段,本包 peerDependencies 锁定 rc.6。
262
+ > DSH 处于 0.1.0-rc 阶段,本包 peerDependencies 锁定 rc.6。
package/cordis.patch.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # dsh-cohub bundle patch —— 在 profile 组合中挂载 CoHub 插件行。
2
2
  # 行 id 为 "cohub":profile 级 cordis.patch.yml 可用该 id 覆盖 config
3
- #(如关闭 council 或配置 councillors 模型列表)。
3
+ #(如关闭 council 或配置 councillors 模型列表、调整 P3 字段)。
4
4
  - insert:
5
5
  - id: cohub
6
6
  name: 'dsh-cohub'
@@ -9,3 +9,47 @@
9
9
  # - { name: expert1, provider: deepseek-official, model: deepseek-v4-flash }
10
10
  councillors: []
11
11
  councilTimeoutMs: 180000
12
+ # skills: delegate 委派路由,按 skill 名覆盖子代理的 provider/model/maxTokens。
13
+ # skills 现在可通过 DSH settings(settings.yaml 的 cohub.skills)配置,此处为默认值/组合层(base);未配置则继承父模型。示例:
14
+ # skills:
15
+ # - { name: co-fixer, provider: deepseek-official, model: deepseek-v4-flash }
16
+ # - { name: co-explorer, provider: deepseek-official, model: deepseek-v4-flash }
17
+ skills: []
18
+ # delegateEnvContract: delegate 委派时是否在子代理 prompt 前注入「执行器环境契约」
19
+ # (通用原则 + 探测式自适应,避免子代理在陌生执行环境现场盲试)。默认开;可关闭/可覆盖文本:
20
+ # delegateEnvContract: { enabled: true } # 默认
21
+ # delegateEnvContract: { enabled: false } # 关闭注入
22
+ # delegateEnvContract: { enabled: true, text: "..." } # 部署覆盖为已知环境契约
23
+ # 缺省文本为「通用原则 + 探测流程」(不写死 await import()/require/600s 等环境断言)。
24
+ # delegateRetry: delegate 中止/失败后的自动重试。默认不重试(保持现状):
25
+ # delegateRetry: { maxRetries: 0, retryDelayMs: 1000, retryableReasons: ["aborted"] }
26
+ # - maxRetries: 0 = 不重试;>0 时仅对 retryableReasons 中的 reason 重试
27
+ # - retryableReasons: 默认仅 "aborted";未知 stopReason 一律不重试(保守,跨版本安全)
28
+ # delegateRetry.stall(P3-1 N2 停滞检测):默认关闭(enabled=false)。启用后会在 spawn 子代理
29
+ # 时挂载 StallWatchdog,按 session/event 在线估计 S1-S4 信号并提前中止(复用 delegateRetry 重试预算):
30
+ # delegateRetry:
31
+ # maxRetries: 2
32
+ # retryDelayMs: 1500
33
+ # retryableReasons: ["aborted"]
34
+ # stall:
35
+ # enabled: true
36
+ # consecutiveErrors: 3 # S1 连续同类错误阈值
37
+ # idleMs: 180000 # S2 无结果空转毫秒
38
+ # reasoningWithoutAction: 50 # S3 纯推理无动作阈值(连续推理块数,期间 0 工具调用)
39
+ # loopCount: 3 # S4 同工具名 + 同参数重复次数
40
+ # graceMs: 30000 # 宽限窗口(最近一次成功工具结果距今超过它才允许触发)
41
+ # recoverable: true # 触发后按 retryableReasons 判定(false 则直接失败)
42
+ # envSignatures(P3-2 N1 环境契约持久化):默认 auto(无缓存时与 P1 行为完全一致)。
43
+ # 累计同一归一化签名达 confirmCount 次后写入 dshHomePath("cohub","env-signatures.json");
44
+ # 下次 spawn 命中缓存(指纹 + TTL 有效)→ 用确定性契约文本前馈注入,跳过探针。
45
+ # envSignatures:
46
+ # use: auto # auto / off / manual
47
+ # ttlMs: 604800000 # 7 天(到期重探,防环境静默升级)
48
+ # confirmCount: 2 # 观察一致次数(防瞬态误判)
49
+ # schedule(P3-3 N3 调度参数):通过 systemPrompt.section 注入实际生效值(cohub:schedule),
50
+ # 子代理与主代理均可见该段;text 为函数,settings 卡片改了立即重读无需重启。
51
+ # schedule:
52
+ # maxParallelBatch: 3 # 单批并行委派上限(本环境观测值,部署可调)
53
+ # wallClockBudgetMs: 600000 # 单次执行单元墙钟预算(10 分钟)
54
+ # useJobTracking: auto # auto / on / off(auto = 有 job 能力则后台跟踪)
55
+ # adaptiveBatch: auto # auto / off(auto = 提示词级按本会话已观测错误/超时收放批大小)