dsh-hive-panel 0.1.6 → 0.2.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/docs/DESIGN.md CHANGED
@@ -17,7 +17,7 @@
17
17
  | `lib/index.js` | Host 半:`/api/hive` Connection Fetch 路由、cwd 解析、`ctx.shell` 执行、动作白名单 |
18
18
  | `lib/queen.js` | 女王模式:每 Session 内存开关、`hive:queen` system-prompt section、`/queen` 命令 |
19
19
  | `lib/client.js` | 浏览器半:`window.__ModuleLoader__.load({ id, factory })`,注册 `conversation.view` 条目 |
20
- | `src/client.template.js` | client bundle 模板(slot 注册、字典、locale) |
20
+ | `src/client.template.js` | client bundle 模板(slot 注册、字典、locale、打开 worker 会话的 `openSession` 回调) |
21
21
  | `scripts/build-client.mjs` | 把 `src/panel.js` 内联进 `lib/client.js`,并注入同源 URL |
22
22
  | `scripts/verify.mjs` | 离线验证(Cordis 形状 shim,不启动 DSH) |
23
23
  | `docs/DESIGN.md` | 本文件 |
@@ -86,6 +86,8 @@ ctx.slots.inject('conversation.view', () => ctx.slots.register({
86
86
  hiveSessionId: typeof sessionId === 'string' ? sessionId : '',
87
87
  hiveTranslate: t,
88
88
  hiveLocaleSubscribe: listener => ctx.locale.subscribe(listener),
89
+ // 仅当宿主暴露 ctx.uiWorkspace.openSession 时才有这一项(见 §7)。
90
+ hiveOpenSession: childSessionId => { /* ... */ },
89
91
  }),
90
92
  }, HivePanelMount))
91
93
  ```
@@ -118,6 +120,11 @@ actionsUrl: HIVE_API_PREFIX + '?op=action&name={name}' + suffix,
118
120
  `src/panel.js` 的 `requestAction()` 支持 `{name}` 占位符(独立页面仍用旧的
119
121
  `/api/actions/<name>` 形式,保持向后兼容)。**浏览器不传 cwd**;cwd 永远由 host 从 Session 状态推导。
120
122
 
123
+ `hiveOpenSession` 不在 `inject(sessionId)` 里无条件出现:只有 `ctx.get('uiWorkspace')`
124
+ 的 `openSession` 是函数时才注入,`HivePanelMount` 再把它作为
125
+ `HIVE_PANEL.mount({ openSession })` 传给渲染器。独立页面没有这个选项,卡片详情里就没有
126
+ 「打开智能体对话」按钮(见 §7)。
127
+
121
128
  ## 4. 通道(结论:Connection exact Fetch route)
122
129
 
123
130
  ### 4.1 服务与注册
@@ -222,7 +229,7 @@ child_process 会绕过 Session sandbox mode、凭证擦除、超时/输出上
222
229
  | --- | --- |
223
230
  | 快照 | `hive board --json`、`hive-tasks list --json`、`hive-tasks stats --json`、`hive roles list --json` |
224
231
  | 快照探针 | `git for-each-ref --format=%(refname) refs/hive/v1`、`git cat-file -p refs/hive/v1/mode` |
225
- | 动作 | `init add plan claim done fail retry block renew mode learn recall verdict run commit doctor roles-add` |
232
+ | 动作 | `init add plan claim done fail retry renew mode learn recall verdict run commit doctor roles-add roles-remove remove` |
226
233
 
227
234
  动作表沿用 `hive-panel/src/actions.js` 的 argv 构造;每个字段先校验(id/agent/ttl/sha/mode/整数范围/
228
235
  字符串长度/NUL),再作为独立 argv token 用单引号严格转义:
@@ -236,7 +243,7 @@ command = [bin, ...argv].map(quote).join(' ')
236
243
  不会变成 shell 语法。`bins`(hive/hive-tasks/hive-run/moc)只能来自受信 host 配置,必须是单个可执行
237
244
  token(PATH 名或绝对路径)。
238
245
 
239
- `roles-add` 是唯一新增的角色写动作:body `{ name, adapter?, model?, description? }` 映射为
246
+ `roles-add` 是角色写动作:body `{ name, adapter?, model?, description? }` 映射为
240
247
  `hive roles add <name> [--adapter dsh|claude|codex] [--model M] [--description TEXT]`;`name` 必须匹配
241
248
  `^[a-z][a-z0-9-]{1,31}$`,`adapter` 只允许 `dsh|claude|codex`,`model` 只允许
242
249
  `[A-Za-z0-9._:-]{1,64}`,`description` 是可选自由文本(≤2000 字符;`""`/`null`/省略都等价于
@@ -244,6 +251,13 @@ token(PATH 名或绝对路径)。
244
251
  `## Contract` 段)。绝不发送 `--force`:已存在的角色由 CLI 以退出码 2 + stderr 返回,
245
252
  动作信封原样带回(`ok:false, code:2, stderr:"hive roles: role \"name\" already exists; …"`)。
246
253
 
254
+ `roles-remove` 是与之配对的删除动作:body `{ name }`(同样 `^[a-z][a-z0-9-]{1,31}$`)映射为
255
+ `hive roles rm <name>`,cwd 同为会话仓库,**不发** `--force`/`--keep-file`;成功返回 CLI 的
256
+ `removed role … / kept .hive/roles/<name>.md` stdout,角色不存在时 CLI 退出 2 + stderr
257
+ (`role "<name>" not found …`)原样进动作信封。host 不预检在飞任务/限额:`hive roles rm` 本身
258
+ 不检查卡片,登记表删除后卡片仍保留 `role` 字段,`.hive/limits.json` 里的旧 key 不会被本动作清理;
259
+ 新角色列表在下一次 snapshot `roles.list` 轮询中消失。该动作需要 `writable: true`。
260
+
247
261
  ### 5.4 权限与审计(明确取舍)
248
262
 
249
263
  - 有:Session sandbox policy(read-only 会话里的写命令会被沙箱拒绝,`result.sandbox.denied` 可在结果里
@@ -292,7 +306,67 @@ token(PATH 名或绝对路径)。
292
306
  `dsh-commands/src/index.ts:285`(`commands.register` 返回 disposer)、
293
307
  `dsh-agent/src/runtime-types.ts:300`(`agent/disposed` 载荷 `{ agent }`)。
294
308
 
295
- ## 7. 0.2.2-rc.5 实测差异(文档 vs asar 实际代码)
309
+ ## 7. 打开 worker 的子智能体会话(结论:客户端导航 API,无 URL)
310
+
311
+ 卡片详情里「最近一次执行」的「打开智能体对话 / Open agent chat」等价于点击顶部
312
+ “子智能体”下拉里的某一项:**只能在客户端插件里调用
313
+ `ctx.uiWorkspace.openSession(target)`**。DSH Web 没有 `/session/<id>` 路由;会话导航
314
+ 没有 URL 参与(选择只存在 `dsh.sessions.current` persist store 里),`history.pushState` 不可行。
315
+
316
+ ### 7.1 顶部列表属于哪个包
317
+
318
+ 顶部列表是 Conversation header actions band 里的 `SubagentCatalogAction` /
319
+ `SubagentHeaderLineage`,来自 **`@deepseek-ai/dsh-client-ui-subagent`**;
320
+ `dsh-client-ui-agent-team` 是共享任务板(TeamBoard),不是子智能体列表。
321
+
322
+ 点击一行(`$D/dsh-client-ui-subagent/src/client/SubagentHeaderLineage.tsx:324-332`):
323
+
324
+ ```ts
325
+ openChild({ parentSessionId, childSessionId: entry.id, mode: entry.mode }) // SubagentAddress
326
+ ```
327
+
328
+ 在 `$D/dsh-client-ui-subagent/src/client/index.ts:60-66` 落到:
329
+
330
+ ```ts
331
+ ctx.uiWorkspace.openSession(address /* SubagentAddress */)
332
+ ```
333
+
334
+ ### 7.2 确切 API 与参数(0.2.2-rc.5 asar)
335
+
336
+ | 项 | 结论 | 证据(asar 内路径) |
337
+ | --- | --- | --- |
338
+ | 服务 | `ctx.uiWorkspace`(`UiWorkspaceService`,`Service(ctx, 'uiWorkspace')`) | `dsh-client-ui-workspace/src/client/navigation.ts:166,195` |
339
+ | 方法 | `openSession(target: SessionTarget): void` | `…/navigation.ts:45,293` |
340
+ | 参数 | `SessionTarget = SessionId \| SubagentAddress`;`SubagentAddress = { parentSessionId, childSessionId, mode: 'one-shot' \| 'continuable' \| 'unknown' }` | `dsh-api-session-controller/src/client/contract/sessions.ts:22`、`dsh-subagent/src/control-types.ts:62-71` |
341
+ | 语义 | `replaceMain(target, lifetime.signal, 'reveal')` → `ctx.sessions.retain(target, { source: 'mainView' })`,把选择写进 `dsh.sessions.current`(persist store)并 `ctx.layout.selectPanel(null)`;纯内存选中,不改 URL | `…/navigation.ts:293-295,523-553` |
342
+ | 裸 id 何时可用 | `resolveTarget` 接受裸 `SessionId`:`ctx.sessions.has(id)` 或宿主 `session.list` 里有该行、或能由 `subagentAddress(id)` 推导;否则同步抛 `sessions.retain: unknown session <id>` | `dsh-api-session-controller/src/client/sessions/manager.ts:140-152` |
343
+ | 子会话地址 | `ctx.sessions.subagentAddress(id)`:依次取已 retained 地址、父 Session 的 `subagentCatalog` 行、`origin: 'subagent'` 的列表行(mode 记为 `unknown`);返回它在面包屑里显示 parent/mode | `…/manager.ts:160-181`、`…/sessions/service.ts:356-358` |
344
+ | 其它入口 | `dsh-client-ui-workspace` 的 `WorkspaceBrowserInjected['open']` 只是再导出一遍 `uiWorkspace.openSession`,不是另一条 API | `…/src/client/index.ts:190-192,303,341` |
345
+ | URL | 会话导航没有 URL 路由,不存在 `/session/<id>`。全 asar 逐文件扫描 `pushState`/`replaceState`:`dsh-client-ui-*` 里只有文档预览的 excel/pdf vendor 产物命中,另有 `dsh-experimental-inspector` 的 DevTools vendor chunk,均与会话导航无关 | 扫描 18783 个文本文件(约 190 MB) |
346
+
347
+ ### 7.3 本插件的落地方式
348
+
349
+ 1. client 半在 `apply` 里实现 `openSession(sessionId)`(`src/client.template.js`):用
350
+ `ctx.get('uiWorkspace')` 懒解析可选服务;再用 `ctx.get('sessions')?.subagentAddress(id)`
351
+ 优先取 catalog 地址(与点列表项完全一致),拿不到就传裸 id 让 client 自己解析。
352
+ 用 `ctx.get` 读可选依赖、不写进 `inject`,所以没有 Workspace 导航的 profile 仍能加载插件。
353
+ 2. 只有 `uiWorkspace.openSession` 可用时才把 `hiveOpenSession` 放进
354
+ `conversation.view` 的 `inject(sessionId)` props;`scripts/build-client.mjs` 把它作为
355
+ `HIVE_PANEL.mount({ openSession })` 传给渲染器。
356
+ 3. 渲染器(独立页面与 DSH 共用的 `src/panel.js`)只在 `lastRun.sessionId` 非空**且**
357
+ `openSession` 是函数时渲染按钮;缺任一半都不渲染(不置灰占位)。点击只调用宿主回调,
358
+ 浏览器从不自己拼路由或 URL。
359
+ 4. snapshot 的 `lastRun` 由 `lib/index.js` 原样透传 runner 0.6.4 写入的
360
+ `sessionId`/`agentName`(有则带、无则省略,legacy 记录形状不变);不新增 HTTP 路由。
361
+
362
+ ### 7.4 不重启进程的验证边界
363
+
364
+ 客户端导航是浏览器内行为:`scripts/verify.mjs` 用 Cordis 形状 shim 断言
365
+ `inject(sessionId).hiveOpenSession` 存在时把 catalog 地址转发给 `uiWorkspace.openSession`、
366
+ 无 `uiWorkspace` 时该 prop 不出现、client bundle 把 `openSession` 传进 mount;真正的
367
+ “切到 worker 会话”仍需在浏览器里点一次确认。
368
+
369
+ ## 8. 0.2.2-rc.5 实测差异(文档 vs asar 实际代码)
296
370
 
297
371
  研读 `docs/RESEARCH.md` 与 `docs/QUEEN-ACTIVATION.md` 时核对 asar,记录差异如下(以实际代码为准):
298
372
 
@@ -310,7 +384,7 @@ token(PATH 名或绝对路径)。
310
384
  | “用 `resolveCore` 解析 hive 二进制” | host 侧无自动解析;本实现用受信配置 `bins` 或 PATH(`hive`/`hive-tasks`/`hive-run`/`moc`) | 找不到命令时返回干净的非 0 退出码与 stderr,不假装成功 |
311
385
  | 组合位置行号 | `dsh-base/cordis.patch.yml`:agent `:82`、commands `:321`、system-prompt `:528`、subprocess `:234`、sandbox `:240`、sandbox-policy `:243`、bash-sandbox `:249`、shell-env `:278`;`dsh-web-app/cordis.patch.yml`:connection `:238`、tool-bash disabled `:517` | 文档行号一致;`ctx.shell` 在 host 平面,第三方 bundle patch 可直接 inject |
312
386
 
313
- ## 8. 安装与重启
387
+ ## 9. 安装与重启
314
388
 
315
389
  `~/.dsh/profiles/web/package.json`:
316
390
 
@@ -327,7 +401,7 @@ token(PATH 名或绝对路径)。
327
401
  通过内置 Plugins 页面 / `plugin_manager` 安装时通常由 live profile recompose,无需重启。
328
402
  只改 `lib/client.js` 的 UI 代码时,有 client HMR watcher 可不重启 Host。
329
403
 
330
- ## 9. 验证(已跑通)
404
+ ## 10. 验证(已跑通)
331
405
 
332
406
  ```bash
333
407
  cd /path/to/dsh-hive-panel
@@ -336,27 +410,35 @@ npm run check
336
410
  # ok - node --check lib/queen.js
337
411
  # ok - node --check lib/client.js
338
412
  # ...
339
- # 24 checks passed
413
+ # 31 checks passed
340
414
  ```
341
415
 
342
416
  覆盖:语法、package/bundle 声明、无代理残留、client bundle 的 `/api/hive` URL 与 Session 注入、
417
+ client 的 `openSession` 回调注入(有/无 `uiWorkspace` 两种宿主)、snapshot `lastRun` 的
418
+ `sessionId`/`agentName` 透传与 legacy 记录形状、
343
419
  Connection Fetch 路由注册、快照走 `ctx.shell` 且 cwd/policy 正确、冷会话 cwd、未知 op/会话 400、
344
420
  只读语义、动作参数校验与 argv 转义、失败信封、无 `ctx.shell` 拒绝挂载、女王激活/隔离/退出/截断,
345
421
  以及 snapshot 自动激活、显式关闭后的抑制、`queen-off` 幂等、`autoQueen=false` 与手动 `queen-on`、
346
- `roles` 快照(角色列表 + 持久限额)、`roles-add` 的参数校验/argv/仓库 cwd、重复角色的 CLI stderr 透传。
422
+ `roles` 快照(角色列表 + 持久限额)、`roles-add`(含 description)的参数校验/argv/仓库 cwd、
423
+ 重复角色的 CLI stderr 透传、`roles-remove` 的 argv/非法名/只读 403/CLI 失败透传,以及 `remove` 的卡片 id 校验。
347
424
 
348
425
  不启动、不重启任何 DSH 进程,也不写运行中的 `~/.dsh`。
349
426
 
350
- ## 10. 风险与未验证点
427
+ ## 11. 风险与未验证点
351
428
 
352
429
  - **未在真实 DSH Web 页面里端到端跑过**(硬约束:不重启运行中的 dsh web)。挂载点/通道/执行层均按
353
430
  asar 公开 API + 官方包用法交叉验证;首次加载若 slot 对 `inject` 有额外要求,需要在浏览器控制台确认。
354
431
  - **依赖 0.2.2-rc.5 的公开 API**(`connection.fetch.register`、`ctx.shell`、`workingDirectory`、
355
- `systemPrompt.section`、`commands.register`);升级 DSH 需要回归 `npm run check`。
432
+ `systemPrompt.section`、`commands.register`,以及浏览器端的
433
+ `ctx.uiWorkspace.openSession(SessionTarget)`);升级 DSH 需要回归 `npm run check`。
434
+ - 打开 worker 会话只验证到 shim 层:`uiWorkspace` 服务缺失时插件仍加载且按钮不渲染,
435
+ 但“真的切过去”没有在运行中的页面里点过(不重启进程);worker 激活产生的子会话只有在
436
+ runner 0.6.4+ 写完 `.hive/runs/<id>.json` 后才会出现按钮。
356
437
  - 冷会话只能拿 `header.cwd`;`cd` 后的有效 cwd 在 resume 前不可见。
357
438
  - 每次轮询会 spawn 1–5 个 CLI 进程(实测单命令 ~110–124 ms),3 s 间隔足够;多客户端同时打开会叠加。
358
439
  - 自动女王只以 `refs/hive/v1` 为准:任何已初始化的仓库在该 Session 第一次快照时即进入女王模式;
359
440
  用户可用 `/queen off`(本进程内抑制)或配置 `autoQueen: false`(全局关闭自动)退出该行为。
360
441
  - 面板触发的命令**不进会话审计**,也没有 approval;需要硬边界时应把操作建模成 turn 内 tool 调用。
361
- - `hive`/`hive-tasks` 不在 DSH PATH 时必须在 profile config 提供 `bins`,否则动作/快照返回非 0 退出码
362
- 或空数据(与旧 hive-panel 的 fallback 语义一致)。
442
+ - `hive`/`hive-tasks` 不在 DSH PATH 时,宿主先按 PATH 名执行,失败后自动用
443
+ `npx -y -p <包> ...` 重试一次;两者都失败才返回带安装提示的非 0 退出码或空数据。显式配置的
444
+ 绝对路径不会被替换。