@yiyi_zhang/laoshi 0.2.0 → 0.3.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.
Files changed (113) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +3 -2
  3. package/adapters/dsh/adapter.ts +22 -1
  4. package/adapters/dsh/dsh-runtime.ts +14 -3
  5. package/adapters/dsh/install.mjs +16 -4
  6. package/adapters/dsh/plugin/index.mjs +197 -18
  7. package/adapters/dsh/plugin/package.json +1 -1
  8. package/adapters/mogao/adapter.ts +9 -1
  9. package/adapters/mogao/mogao-runtime.ts +30 -8
  10. package/adapters/paseo/install.mjs +13 -4
  11. package/adapters/paseo/plugin/client/data.ts +13 -2
  12. package/adapters/paseo/plugin/client/detail.tsx +244 -4
  13. package/adapters/paseo/plugin/client/format.ts +25 -117
  14. package/adapters/paseo/plugin/client/overview.tsx +3 -3
  15. package/adapters/paseo/plugin/index.server.ts +2 -1
  16. package/adapters/paseo/plugin/package.json +1 -1
  17. package/adapters/paseo/plugin/paseo-plugin.json +1 -1
  18. package/adapters/paseo/plugin/server/handlers.ts +22 -4
  19. package/adapters/paseo/plugin/server/req.ts +17 -4
  20. package/adapters/paseo/plugin/shared/contracts.ts +28 -2
  21. package/adapters/paseo/plugin/shared/view-model.ts +425 -0
  22. package/bin/req.mjs +10 -0
  23. package/contracts/cli-json.md +3 -1
  24. package/docs/design/dsh-adapter.md +9 -9
  25. package/docs/design/shared-ui.md +43 -0
  26. package/docs/guide//345/256/211/350/243/205/344/270/216/345/215/207/347/272/247.md +13 -8
  27. package/docs/guide//347/234/237/345/256/236/347/216/257/345/242/203/350/265/260/346/237/245.md +78 -0
  28. package/engine/src/api.ts +11 -2
  29. package/engine/src/board.ts +435 -0
  30. package/engine/src/config.ts +23 -0
  31. package/engine/src/doctor.ts +25 -0
  32. package/engine/src/estimate.ts +11 -0
  33. package/engine/src/extensions.ts +271 -0
  34. package/engine/src/handover-cmd.ts +47 -0
  35. package/engine/src/handover.ts +89 -0
  36. package/engine/src/history.ts +102 -0
  37. package/engine/src/joint.ts +49 -4
  38. package/engine/src/launch.ts +2 -1
  39. package/engine/src/main.ts +1 -1
  40. package/engine/src/messages.ts +58 -0
  41. package/engine/src/pipeline.ts +109 -4
  42. package/engine/src/reply.ts +27 -6
  43. package/engine/src/semver.ts +21 -0
  44. package/package.json +5 -2
  45. package/site-dist/404.html +2 -2
  46. package/site-dist/assets/{app.BxNgGFu-.js → app.DZpVs0VH.js} +1 -1
  47. package/site-dist/assets/changelog.md.CdUYbro4.js +1 -0
  48. package/site-dist/assets/{changelog.md.D0PzSXw9.lean.js → changelog.md.CdUYbro4.lean.js} +1 -1
  49. package/site-dist/assets/chunks/@localSearchIndexroot.CHr-ITwS.js +1 -0
  50. package/site-dist/assets/chunks/{VPLocalSearchBox.Dw_fzw9V.js → VPLocalSearchBox.BHkmziy1.js} +1 -1
  51. package/site-dist/assets/chunks/{theme.CwrnT4KI.js → theme.BsPChbDE.js} +2 -2
  52. package/site-dist/assets/guide_dsh.md.D0XhcUHz.js +7 -0
  53. package/site-dist/assets/guide_dsh.md.D0XhcUHz.lean.js +7 -0
  54. package/site-dist/assets/{guide_getting-started.md.CjzysdDe.js → guide_getting-started.md.BDd3nU5n.js} +1 -1
  55. package/site-dist/assets/{guide_install.md.By4WxsJG.js → guide_install.md.SsIHMfUu.js} +7 -5
  56. package/site-dist/assets/{guide_install.md.By4WxsJG.lean.js → guide_install.md.SsIHMfUu.lean.js} +7 -5
  57. package/site-dist/assets/guide_walkthrough.md.nj_PWP9Y.js +5 -0
  58. package/site-dist/assets/guide_walkthrough.md.nj_PWP9Y.lean.js +5 -0
  59. package/site-dist/assets/reference_contracts_cli-json.md.3iU9h4rw.js +1 -0
  60. package/site-dist/assets/reference_contracts_cli-json.md.3iU9h4rw.lean.js +1 -0
  61. package/site-dist/changelog.html +5 -5
  62. package/site-dist/guide/cli.html +4 -4
  63. package/site-dist/guide/dsh.html +8 -6
  64. package/site-dist/guide/getting-started.html +5 -5
  65. package/site-dist/guide/how-it-works.html +4 -4
  66. package/site-dist/guide/index.html +4 -4
  67. package/site-dist/guide/install.html +11 -9
  68. package/site-dist/guide/intranet.html +4 -4
  69. package/site-dist/guide/maintainer.html +4 -4
  70. package/site-dist/guide/mogao.html +4 -4
  71. package/site-dist/guide/phases.html +4 -4
  72. package/site-dist/guide/project.html +4 -4
  73. package/site-dist/guide/user.html +4 -4
  74. package/site-dist/guide/walkthrough.html +34 -0
  75. package/site-dist/hashmap.json +1 -1
  76. package/site-dist/index.html +4 -4
  77. package/site-dist/reference/adr/0001-new-repo-core-and-adapters.html +4 -4
  78. package/site-dist/reference/adr/0002-two-orchestration-modes.html +4 -4
  79. package/site-dist/reference/adr/0003-generate-once-then-lock.html +4 -4
  80. package/site-dist/reference/adr/0004-external-contracts-stay-stable.html +4 -4
  81. package/site-dist/reference/adr/0005-skill-names.html +4 -4
  82. package/site-dist/reference/adr/0006-deterministic-engine-platform-capabilities.html +4 -4
  83. package/site-dist/reference/adr/0007-one-install-many-repos.html +4 -4
  84. package/site-dist/reference/adr/0008-capability-sources-and-platform-plugin.html +4 -4
  85. package/site-dist/reference/adr/index.html +4 -4
  86. package/site-dist/reference/commands.html +4 -4
  87. package/site-dist/reference/config.html +4 -4
  88. package/site-dist/reference/contracts/agent-runtime.html +4 -4
  89. package/site-dist/reference/contracts/cli-json.html +5 -5
  90. package/site-dist/reference/contracts/feature-files.html +4 -4
  91. package/site-dist/reference/contracts/index.html +4 -4
  92. package/site-dist/reference/contracts/notifier-event.html +4 -4
  93. package/site-dist/reference/contracts/result-file.html +4 -4
  94. package/site-dist/reference/contracts/spec.html +4 -4
  95. package/site-dist/reference/contracts/state.html +4 -4
  96. package/site-dist/reference/contracts/usage-record.html +4 -4
  97. package/site-dist/reference/contracts/verify.html +4 -4
  98. package/site-dist/reference/design/adapter-guide.html +4 -4
  99. package/site-dist/reference/design/architecture.html +4 -4
  100. package/site-dist/reference/design/builtin-capabilities.html +4 -4
  101. package/site-dist/reference/design/cli-adapter.html +4 -4
  102. package/site-dist/reference/design/platform-vocabulary.html +4 -4
  103. package/site-dist/reference/scope.html +4 -4
  104. package/skills/laoshi-setup/SKILL.md +1 -1
  105. package/ui/shared/view-model.ts +424 -0
  106. package/ui/web/board.ts +1126 -0
  107. package/site-dist/assets/changelog.md.D0PzSXw9.js +0 -1
  108. package/site-dist/assets/chunks/@localSearchIndexroot.vA-yiw-8.js +0 -1
  109. package/site-dist/assets/guide_dsh.md.0X-eYB87.js +0 -5
  110. package/site-dist/assets/guide_dsh.md.0X-eYB87.lean.js +0 -5
  111. package/site-dist/assets/reference_contracts_cli-json.md.D6vfWOD9.js +0 -1
  112. package/site-dist/assets/reference_contracts_cli-json.md.D6vfWOD9.lean.js +0 -1
  113. /package/site-dist/assets/{guide_getting-started.md.CjzysdDe.lean.js → guide_getting-started.md.BDd3nU5n.lean.js} +0 -0
@@ -6,7 +6,7 @@ laoshi 目前支持三个 agent 平台,另外可以不用平台、直接用编
6
6
 
7
7
  | 平台 | 说明 |
8
8
  | --- | --- |
9
- | [Paseo](https://paseo.sh) 0.11<br>`--platform paseo` | 步骤 agent、工作区、服务、定时消息都由 Paseo daemon 提供 |
9
+ | [Paseo](https://paseo.sh) 0.11–0.17<br>`--platform paseo` | 步骤 agent、工作区、服务、定时消息都由 Paseo daemon 提供(优先 Web 端) |
10
10
  | DeepSeek Harness(dsh)<br>`--platform dsh` | 步骤 agent 和定时消息由 laoshi 的 dsh 插件提供;工作区和服务用 laoshi 的内置实现(`git worktree`、`.laoshi/services.json`) |
11
11
  | 命令行 agent<br>`--platform cli` | 不需要平台:步骤 agent 是 `claude -p` / `codex exec` 的一次运行;工作区和服务用 laoshi 的内置实现;没有通知发回对话,进展用 `laoshi status` 查看。见 [adapters/cli](../../adapters/cli/README.md) |
12
12
  | 摸高<br>`--platform mogao` | 以专家的形式提交到平台,第一次使用时自动装到工作区,不按本文安装;见[在摸高上使用](在摸高上使用.md) |
@@ -43,7 +43,7 @@ skill 装到哪里由平台决定:
43
43
  | Node.js | 22.19 或更新 | `node -v` |
44
44
  | npm | Node.js 自带;公司网络用镜像(见第 3 节) | `npm -v` |
45
45
  | git | 近期版本 | `git --version` |
46
- | 平台 | Paseo 0.11 的 daemon 在运行;或已装好 dsh(`dsh` 命令可用,或知道它的 `bin.js` 位置) | Paseo:能在桌面端或 `http://localhost:6767/` 对话;dsh:能在网页端对话 |
46
+ | 平台 | Paseo 0.11–0.17 的 daemon 在运行;或已装好 dsh(`dsh` 命令可用,或知道它的 `bin.js` 位置) | Paseo:能在网页端(`http://localhost:6767/`,推荐)或桌面端对话;dsh:能在网页端对话 |
47
47
  | 模型 | Paseo:Claude Code、Codex、OpenCode、Pi 至少一种已在 Paseo 中登录;dsh:对话用的模型能正常回答 | 用它开一个对话 |
48
48
 
49
49
  ## 3. 首次安装
@@ -84,10 +84,13 @@ npx -y --registry=https://npm.example.internal/ @yiyi_zhang/laoshi@latest instal
84
84
  | `--dry-run` | 演练:显示要做的事,不写文件 |
85
85
  | `--uninstall` | 卸载(见第 8 节) |
86
86
  | `--registry <地址>`、`--no-save-registry` | 只用于一步安装和 `laoshi upgrade`:这次用的 npm 源,是否保存 |
87
+ | Paseo:`--with-plugin` | 安装时顺便把 Paseo 需求插件部署并加载到 Paseo |
87
88
  | dsh:`--dsh-home <目录>` | dsh 的数据目录,默认 `DSH_HOME` 或 `~/.dsh` |
88
89
  | dsh:`--profile <名称>` | 插件装进哪个 profile,默认 `web` |
89
90
  | dsh:`--dsh-bin <路径>` | dsh 的 `bin.js`,`dsh` 不在 PATH 中时写;`dsh plugin add` 失败时安装器直接复制插件 |
90
91
  | dsh:`--approvals ask\|allow` | 步骤 agent 的审批请求:`ask` 交给人(默认),`allow` 直接批准一次 |
92
+ | dsh:`--no-board` | 关闭安装后默认随 dsh 启动的托管 Web 需求看板(默认开启 `board: true`) |
93
+ | dsh:`--board-port <端口>` | 固定 dsh 托管需求看板监听的端口(默认自动分配空闲端口) |
91
94
 
92
95
  同名 skill 的处理:带 `.laoshi-install.json` 标记的是 laoshi 装的,会被更新;paseo-req-kit 装的(带 `.req-kit-install.json`)和别人放的都不覆盖,安装器会列出它们,确认后再用 `--force`。
93
96
 
@@ -223,18 +226,20 @@ laoshi install --uninstall
223
226
 
224
227
  事件的类型和字段见 [contracts/notifier-event.md](../../contracts/notifier-event.md)。通知失败只记日志,不影响流水线。项目配置(`.laoshi.json`)中的 `notifiers` 会被忽略。
225
228
 
226
- ## 11. Paseo 的需求插件
229
+ ## 11. Paseo 需求插件与共享 Web 需求看板
227
230
 
228
- 在 Paseo 界面里看需求总览、进度和文档,确认方案、停止、继续、开始测试验证,以及选择模型的插件,随 laoshi 一起发布(`adapters/paseo/plugin`,从 paseo-req-kit 迁入):
231
+ 在 Paseo Web 端界面(以及各平台通用的本地 Web 需求看板 `laoshi board`)里查看需求总览、进度、文档、变更历史与负责人,确认方案、发起改需求、转交、停止、继续、一键试用、验收及选择模型的插件,随 laoshi 一起发布(`adapters/paseo/plugin`,适配 Paseo `0.11–0.17`):
229
232
 
230
233
  ```sh
231
- laoshi plugin install [--yes] # 安装或更新;Paseo 的插件总开关关着时会先问是否打开
232
- laoshi plugin status # 是否在运行
233
- laoshi plugin remove # 从 Paseo 移除
234
+ laoshi install --platform paseo --with-plugin # 安装 laoshi 时一步部署并加载插件
235
+ laoshi plugin install [--yes] # 单独安装或更新;Paseo 的插件总开关关着时会先问是否打开
236
+ laoshi plugin status # 是否在运行
237
+ laoshi plugin remove # 从 Paseo 移除
238
+ laoshi board # 任意平台随时打开共享 Web 需求看板(dsh 默认随宿主启动)
234
239
  ```
235
240
 
236
241
  - 插件文件复制到 `<安装根>/paseo-plugin`,Paseo 从那里加载;`laoshi install`、`laoshi upgrade` 时如果装过插件,会顺带更新文件并让 Paseo 重新加载,插件总是和程序同一个版本。
237
242
  - 插件只在本机运行 `laoshi api`([cli-json](../../contracts/cli-json.md)),不连接外部服务;插件设置里可以打开"只读",只看不改。
238
- - 插件就在安装根下,会自己找到 laoshi;安装根换过位置又找不到时,在插件设置里填安装根。
243
+ - 插件默认读取 `LAOSHI_HOME` 或 `~/.laoshi`;如果在安装时使用了非默认的 `--home` 目录(尤其在 Paseo 0.17 下,服务端插件经打包执行没有 `import.meta.url`),需确保守护进程环境变量中有对应的 `LAOSHI_HOME`,或在 Paseo「设置 → 插件 → laoshi → laoshi 的安装根」中填写实际安装根路径。
239
244
  - 装过 paseo-req-kit 的插件(id `req-kit`):两个可以同时存在,迁移到 laoshi 后用 `req plugin remove` 移除旧的。
240
245
  - 没有 `paseo` 命令(桌面版 Paseo 管理的 daemon)时,按提示在 Paseo 的 设置 → Plugins 中手动填插件目录。
@@ -0,0 +1,78 @@
1
+ # Paseo Web 与 dsh 真实环境插件走查清单
2
+
3
+ 本清单用于在**真实运行的 Paseo Web 端**与**内网 dsh(Node 24)**环境中,对 laoshi 插件、共享 Web 需求看板及核心流程扩展进行端到端人工走查。如遇到问题,请记录「结果/截图」并按文末方式打包诊断信息反馈。
4
+
5
+ ---
6
+
7
+ ## 1. 前置条件与安装确认
8
+
9
+ ### 1.1 运行环境
10
+
11
+ | 平台 | 支持范围 / 环境要求 | 参考说明 |
12
+ | --- | --- | --- |
13
+ | Paseo(Web 端优先) | Paseo daemon `>=0.11.0 <0.18.0`(见根目录 `package.json` 的 `reqKit.paseo`);Node.js `>=22` | [安装与升级](安装与升级.md) |
14
+ | DeepSeek Harness(dsh) | dsh `>=0.2.0 <0.3.0`(见 `reqKit.dsh`);内网要求 **Node 24**;Windows 下禁止依赖 PowerShell | [dsh 适配器说明](../../adapters/dsh/README.md)、[内网安装与验证](../intranet/install-verify.md) |
15
+
16
+ ### 1.2 安装与插件启用
17
+
18
+ ```sh
19
+ # Paseo(同时安装/刷新 Paseo Web 插件)
20
+ laoshi install --platform paseo --with-plugin
21
+
22
+ # dsh(默认开启托管 Web 看板 board: true)
23
+ laoshi install --platform dsh
24
+ ```
25
+
26
+ > 内网离线安装包部署 dsh 请参考 [内网安装与验证](../intranet/install-verify.md)。若 Paseo daemon 在安装时未启动,先启动 daemon 后可执行 `laoshi plugin install --yes` 完成挂载。
27
+
28
+ ### 1.3 `laoshi doctor` 期望输出
29
+
30
+ 在测试项目目录运行 `laoshi doctor`,确认以下关键项均正常(`✓`):
31
+
32
+ - **配置与核心**:配置分层正确;若项目配置开启了 `reviewPanel`,检查多厂商模型互补性;若有受控流程扩展(`extensions`),校验 `skill` 路径存在;若未登记 `relatedRepos` 且存在同级 git 仓库,应提示可用 `/laoshi-setup` 自动发现登记。
33
+ - **Paseo**:显示已连接 daemon 且版本在支持范围内,`laoshi` 插件已安装并运行。
34
+ - **dsh**:显示已连接 `laoshi` dsh 插件(socket 或 Windows 命名管道)、版本在支持范围内、可用模型提供方,以及**托管需求看板运行地址**(如 `需求看板运行中:http://127.0.0.1:<端口>/`)。
35
+
36
+ ---
37
+
38
+ ## 2. 逐项走查清单
39
+
40
+ 请在 Paseo Web 插件页面与 dsh 托管看板(以及对应项目对话)中依次验证下表每一项:
41
+
42
+ | 项目 | 操作 | 期望结果 | 结果 / 截图 |
43
+ | --- | --- | --- | --- |
44
+ | 1. 总览分组与「需要你处理」(X1) | 准备至少 1 个处于等待确认方案或业务问题的需求,打开 Paseo Web 插件总览与 dsh 需求看板首页 | 全部界面文案统一为中文;首页 Bento KPI 数字准确;「需要你处理」区置顶展示等待时长(`等了 …`)、紧急程度提示、影响说明与主操作按钮 | |
45
+ | 2. 基础操作(确认/停止/继续/验证) | 对对应状态的需求分别执行「确认方案」「停止」「继续」「开始测试验证」(本地或已部署环境) | 操作二次确认弹窗正常;执行后状态与 6 站放行轨实时更新;「停止」会中断后台进程与当前步骤,「继续」沿用已完成步骤 | |
46
+ | 3. 验收工作台与一键试用(X2) | 打开已完成或待验收需求详情:Web 看板切至「验收工作台」,Paseo 点「一键试用」「验收清单」 | 点「一键启动试用」返回可访问地址与测试说明;逐条勾选 AC(全部通过或标记不通过+原因)后提交,生成并提交 `acceptance.md`;点「停止试用」可停止服务 | |
47
+ | 4. 进度预估与预算提醒(X3) | 本机累计至少 3 个同档位已完成需求后:启动 1 个新需求(接近 `budget.tokens`),并查看进行中需求详情 | 新需求启动日志给出历史中位数用时/token 与预算提醒;详情页展示已用时长、tokens 及预计剩余时间 | |
48
+ | 5. 联合开发与多仓视图(X7) | 在配置了 `relatedRepos`(可选 `maxJointRepos` > 2)且 `spec.md` 带 `- 联合开发:…` 的项目中运行联合需求并打开详情 | 详情页展示每个联合仓库名称、分支、工作区路径与质量门通过状态徽标;`/laoshi-setup` 能列出同级 git 仓库供勾选 | |
49
+ | 6. 发起改需求(X5) | 在 Web 看板「变更与接手」页签或 Paseo 详情页点「改需求」,输入变更说明并确认发送 | 原对话收到 `【需求开发流水线通知 · 需求方要改需求】` 通知;若流水线在运行则引导先停止,按对齐流程更新 `spec.md` 版本并追加 `changes.md` | |
50
+ | 7. 变更历史与转交接手(X5) | 在 Web 看板「变更与接手」页签或 Paseo「变更历史与负责人」区块展开变更记录、查看 `spec.md` 提交 diff,并提交「转交」给另一同事 | 列表与详情显示更新后的当前负责人;`changes.md` 倒序折叠可读;git diff 以绿增/红删高亮显示改动行;`.pipeline/owner.json` 保留完整转交历史 | |
51
+ | 8. dsh 定时任务 `expiresAt` | 通过带到期时间(`expiresAt`)的预约或测试脚本在 dsh 上创建周期定时任务 | 到达 `expiresAt` 后 dsh 插件自动取消定时任务(dsh `0.2.2-rc.5+` 调用 `schedule.edit`,旧版调用 `schedule.delete`),不再继续触发 | |
52
+ | 9. dsh `scheduleNewAgent` | 运行 `laoshi digest --schedule "0 9 * * 1"` 预约需求总览,再执行 `laoshi digest --cancel <ID>` | dsh 插件新建独立会话并绑定 cron 定时任务,返回 `dsh:<sessionId>/<id>`;取消后对应定时任务被删除 | |
53
+ | 10. 只读模式拦截 | 在 Paseo 插件设置打开 `readOnly`(或启动 `laoshi board --read-only`)后尝试点击操作/验收/改需求/转交按钮 | 界面隐藏写操作表单与按钮;直接调用后端接口(`run` / `/api/action` / `/api/try` / `/api/acceptance`)也返回只读拒绝,不修改任何状态 | |
54
+ | 11. Windows 受控流程扩展(M3) | 在 Windows 项目 `.laoshi.json` 配置 `extensions`(含 `kind: "script"` 及双引号参数命令,挂载 `after: "handoff"`)后运行流水线 | 脚本通过 `cmd.exe`(不启动 PowerShell)正常执行,注入 `LAOSHI_*` 环境变量,日志完整写入 `.pipeline/extensions/<id>.log` | |
55
+
56
+ > **当前已知未接入 dsh 项说明**:dsh 的**事件流替代轮询**与**浏览器能力检测(`capabilities`)**目前仍按降级路径运行,待在真实 dsh 环境中确认对应插件 API 后再单独补齐。
57
+
58
+ ---
59
+
60
+ ## 3. dsh 自动化端到端脚本(可选)
61
+
62
+ 如果内网机器已安装 `@deepseek-ai/dsh`,可先用模拟模型跑通底层链路:
63
+
64
+ ```sh
65
+ LAOSHI_E2E_DSH=<装有 @deepseek-ai/dsh 的目录> node adapters/dsh/e2e/run-e2e.mjs --worktree
66
+ ```
67
+
68
+ 检查全部通过后再结合上表走查真实模型与插件 Web 界面效果。
69
+
70
+ ---
71
+
72
+ ## 4. 问题排查与反馈
73
+
74
+ 若走查中任一项未通过或流水线中断,请运行以下命令打包现场信息(日志与配置会自动脱敏),连同**走查表结果、页面截图、`laoshi doctor` 输出**一并发给维护者:
75
+
76
+ ```sh
77
+ laoshi diagnose <需求名称> --out ./diagnose-output
78
+ ```
package/engine/src/api.ts CHANGED
@@ -6,6 +6,7 @@
6
6
  // req api version
7
7
  // req api list [--all] [--repo <dir>]
8
8
  // req api status <需求> [--repo <dir>]
9
+ // req api history <需求> [--repo <dir>]
9
10
  // req api file <需求> <文件> [--repo <dir>]
10
11
  // req api stats [--since 30d] [--month 2026-10]
11
12
  // req api index [--rebuild <dir>...] [--prune]
@@ -23,6 +24,8 @@ import fs from "node:fs";
23
24
  import path from "node:path";
24
25
  import { resultText, stepName } from "./control.js";
25
26
  import { FEATURES_DIR, findWorktreeRun, listFeatures, resolveFeatureArg, summarize } from "./features.js";
27
+ import { readOwner } from "./handover.js";
28
+ import { apiHistory } from "./history.js";
26
29
  import { defaultConfigPath, KIT_ROOT, kitVersion } from "./locations.js";
27
30
  import { configView } from "./config-view.js";
28
31
  import { pruneIndex, readIndex, registerRequirement, requirementKey } from "./records.js";
@@ -115,6 +118,8 @@ export interface ListItem {
115
118
  codebase: Codebase;
116
119
  /** Who started its pipeline (the state file's startedBy); null before it ran or in older state files. */
117
120
  startedBy: string | null;
121
+ /** Current owner after handover (X5); null if not transferred yet. */
122
+ owner?: string | null;
118
123
  repo: string;
119
124
  sourceRepo: string | null;
120
125
  workspaceId: string | null;
@@ -205,6 +210,7 @@ function item(repo: string, branch: string | null, featureDir: string, extra: {
205
210
  project: extra.project,
206
211
  codebase: codebaseOf(extra.sourceRepo ?? repo),
207
212
  startedBy: state?.startedBy ?? null,
213
+ owner: readOwner(path.join(repo, featureDir)).owner,
208
214
  repo,
209
215
  sourceRepo: extra.sourceRepo,
210
216
  workspaceId: extra.workspaceId ?? state?.worktree?.workspaceRef ?? null,
@@ -271,6 +277,7 @@ export function apiList(input: { repo: string; all: boolean }): ListItem[] {
271
277
  project: e.project,
272
278
  codebase: codebaseOf(e.sourceRepo ?? e.repo),
273
279
  startedBy: null,
280
+ owner: null,
274
281
  repo: e.repo,
275
282
  sourceRepo: e.sourceRepo,
276
283
  workspaceId: e.workspaceId,
@@ -457,7 +464,7 @@ export function apiIndex(input: { rebuild: string[]; prune: boolean }) {
457
464
  return { scanned: [...dirs], registered, pruned, total: readIndex().length };
458
465
  }
459
466
 
460
- const RUNNABLE = ["approve", "stop", "resume", "verify", "sync", "reply", "start"] as const;
467
+ const RUNNABLE = ["approve", "stop", "resume", "verify", "sync", "reply", "start", "try", "handover"] as const;
461
468
 
462
469
  /** Runs `req <command> <需求>` where people would, and reports what it said. */
463
470
  /**
@@ -566,6 +573,8 @@ export function apiMain(argvIn: string[], cwd = process.cwd()): unknown {
566
573
  return apiList({ repo, all: flag(argv, "--all") });
567
574
  case "status":
568
575
  return apiStatus(repo, need("需求"));
576
+ case "history":
577
+ return apiHistory(repo, need("需求"));
569
578
  case "file": {
570
579
  const feature = need("需求");
571
580
  return apiFile(repo, feature, need("文件名"));
@@ -638,7 +647,7 @@ export function apiMain(argvIn: string[], cwd = process.cwd()): unknown {
638
647
  });
639
648
  }
640
649
  default:
641
- throw new ApiError("bad_arguments", `没有 "${command ?? ""}" 这个 api 命令。可用:version、list、status、file、stats、index、run、models、set-agents、config、review-url`);
650
+ throw new ApiError("bad_arguments", `没有 "${command ?? ""}" 这个 api 命令。可用:version、list、status、history、file、stats、index、run、models、set-agents、config、review-url`);
642
651
  }
643
652
  }
644
653
 
@@ -0,0 +1,435 @@
1
+ // `laoshi board [--port <端口>] [--repo <目录>] [--read-only] [--no-open]`:
2
+ // serves the shared Web requirement board (`ui/web/board.ts`) backed by `engine/src/api.ts`,
3
+ // usable standalone or embedded by a platform's web UI plugin.
4
+
5
+ import { spawn } from "node:child_process";
6
+ import crypto from "node:crypto";
7
+ import fs from "node:fs";
8
+ import http from "node:http";
9
+ import path from "node:path";
10
+ import { fileURLToPath } from "node:url";
11
+ import { apiFile, apiList, apiRun, apiStatus, type ListItem } from "./api.js";
12
+ import { acceptanceText, type Answer, buildChecklist, type Checklist, recordAcceptance, verdictOf } from "./checklist.js";
13
+ import { DEFAULT_CONFIG, loadConfig, type PipelineConfig } from "./config.js";
14
+ import { apiHistory, type RequirementHistory } from "./history.js";
15
+ import { defaultConfigPath } from "./locations.js";
16
+ import { loadRuntimeFactory, wordsFor } from "./runtime-loader.js";
17
+ import { howToTry, tryRequirement, type TryResult } from "./try.js";
18
+ import type { RequirementView } from "../../ui/shared/view-model.js";
19
+ import { renderBoardHtml } from "../../ui/web/board.js";
20
+
21
+ const ALLOWED_ACTIONS = new Set(["approve", "stop", "resume", "verify", "sync", "start", "reply", "change", "handover"]);
22
+
23
+ export function toRequirementView(item: ListItem): RequirementView {
24
+ return {
25
+ key: item.key,
26
+ repo: item.repo,
27
+ sourceRepo: item.sourceRepo,
28
+ project: item.project,
29
+ featureDir: item.featureDir,
30
+ title: item.title,
31
+ branch: item.branch,
32
+ type: item.type,
33
+ profile: item.profile,
34
+ stage: item.stage,
35
+ status: item.status,
36
+ attention: item.attention,
37
+ running: item.running,
38
+ updatedAt: item.updatedAt,
39
+ startedBy: item.startedBy,
40
+ owner: item.owner ?? null,
41
+ hasPrototype: item.hasPrototype,
42
+ current: item.current,
43
+ waiting: item.waiting,
44
+ };
45
+ }
46
+
47
+ export interface AcceptanceView {
48
+ checklist: Checklist;
49
+ howTo: string[];
50
+ hasAcceptanceRecord: boolean;
51
+ }
52
+
53
+ export interface AcceptanceSubmitResult {
54
+ ok: boolean;
55
+ verdict?: "通过" | "不通过";
56
+ committed?: boolean;
57
+ missing?: string[];
58
+ message: string;
59
+ }
60
+
61
+ export interface BoardHandlers {
62
+ list: () => RequirementView[];
63
+ detail: (repo: string, feature: string) => unknown;
64
+ file: (repo: string, feature: string, file: string) => unknown;
65
+ run: (input: { action: string; repo: string; featureDir: string; text?: string; to?: string; note?: string; verifyEnv?: string }) => { ok: boolean; message: string };
66
+ history?: (repo: string, feature: string) => RequirementHistory | unknown;
67
+ acceptance?: (repo: string, feature: string) => AcceptanceView;
68
+ submitAcceptance?: (input: { repo: string; featureDir: string; reviewer: string; answers: Answer[] }) => AcceptanceSubmitResult;
69
+ tryRun?: (input: { repo: string; featureDir: string; stop?: boolean }) => Promise<TryResult>;
70
+ }
71
+
72
+ export interface BoardServerOptions {
73
+ handlers: BoardHandlers;
74
+ platformName?: string;
75
+ readOnly?: boolean;
76
+ csrfToken?: string;
77
+ }
78
+
79
+ function readJsonBody(req: http.IncomingMessage, maxBytes = 64 * 1024): Promise<Record<string, unknown>> {
80
+ return new Promise((resolve, reject) => {
81
+ const chunks: Buffer[] = [];
82
+ let total = 0;
83
+ req.on("data", (chunk: Buffer) => {
84
+ total += chunk.length;
85
+ if (total > maxBytes) {
86
+ reject(new Error("请求体过大"));
87
+ req.destroy();
88
+ return;
89
+ }
90
+ chunks.push(chunk);
91
+ });
92
+ req.on("end", () => {
93
+ try {
94
+ const raw = Buffer.concat(chunks).toString("utf8").trim();
95
+ resolve(raw ? (JSON.parse(raw) as Record<string, unknown>) : {});
96
+ } catch {
97
+ reject(new Error("无效的 JSON 请求体"));
98
+ }
99
+ });
100
+ req.on("error", reject);
101
+ });
102
+ }
103
+
104
+ function sendJson(res: http.ServerResponse, status: number, body: unknown): void {
105
+ res.writeHead(status, { "Content-Type": "application/json; charset=utf-8", "Cache-Control": "no-store" });
106
+ res.end(JSON.stringify(body));
107
+ }
108
+
109
+ /** Creates an HTTP server for the shared requirement board and its local JSON API. */
110
+ export function createBoardServer(options: BoardServerOptions): { server: http.Server; csrfToken: string } {
111
+ const csrfToken = options.csrfToken ?? crypto.randomBytes(16).toString("hex");
112
+ const readOnly = Boolean(options.readOnly);
113
+ const platformName = options.platformName ?? "laoshi";
114
+
115
+ const server = http.createServer(async (req, res) => {
116
+ const url = new URL(req.url ?? "/", "http://127.0.0.1");
117
+ try {
118
+ if (req.method === "GET" && url.pathname === "/") {
119
+ const items = options.handlers.list();
120
+ const html = renderBoardHtml(items, {
121
+ title: "laoshi · 需求看板",
122
+ platformName,
123
+ readOnly,
124
+ apiBase: "/api",
125
+ csrfToken,
126
+ });
127
+ res.writeHead(200, { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-store" });
128
+ res.end(html);
129
+ return;
130
+ }
131
+ if (req.method === "GET" && url.pathname === "/api/list") {
132
+ sendJson(res, 200, { items: options.handlers.list() });
133
+ return;
134
+ }
135
+ if (req.method === "GET" && url.pathname === "/api/detail") {
136
+ const repo = url.searchParams.get("repo") ?? "";
137
+ const feature = url.searchParams.get("feature") ?? "";
138
+ if (!repo || !feature) {
139
+ sendJson(res, 400, { error: "缺少 repo 或 feature 参数" });
140
+ return;
141
+ }
142
+ sendJson(res, 200, options.handlers.detail(repo, feature));
143
+ return;
144
+ }
145
+ if (req.method === "GET" && url.pathname === "/api/file") {
146
+ const repo = url.searchParams.get("repo") ?? "";
147
+ const feature = url.searchParams.get("feature") ?? "";
148
+ const file = url.searchParams.get("file") ?? "";
149
+ if (!repo || !feature || !file) {
150
+ sendJson(res, 400, { error: "缺少 repo、feature 或 file 参数" });
151
+ return;
152
+ }
153
+ sendJson(res, 200, options.handlers.file(repo, feature, file));
154
+ return;
155
+ }
156
+ if (req.method === "GET" && url.pathname === "/api/acceptance") {
157
+ const repo = url.searchParams.get("repo") ?? "";
158
+ const feature = url.searchParams.get("feature") ?? "";
159
+ if (!repo || !feature) {
160
+ sendJson(res, 400, { error: "缺少 repo 或 feature 参数" });
161
+ return;
162
+ }
163
+ if (!options.handlers.acceptance) {
164
+ sendJson(res, 404, { error: "当前看板未启用验收工作台" });
165
+ return;
166
+ }
167
+ sendJson(res, 200, options.handlers.acceptance(repo, feature));
168
+ return;
169
+ }
170
+ if (req.method === "GET" && url.pathname === "/api/history") {
171
+ const repo = url.searchParams.get("repo") ?? "";
172
+ const feature = url.searchParams.get("feature") ?? "";
173
+ if (!repo || !feature) {
174
+ sendJson(res, 400, { error: "缺少 repo 或 feature 参数" });
175
+ return;
176
+ }
177
+ if (!options.handlers.history) {
178
+ sendJson(res, 404, { error: "当前看板未启用变更历史" });
179
+ return;
180
+ }
181
+ sendJson(res, 200, options.handlers.history(repo, feature));
182
+ return;
183
+ }
184
+ if (req.method === "POST" && url.pathname === "/api/try") {
185
+ if (readOnly) {
186
+ sendJson(res, 403, { ok: false, error: "看板当前为只读模式" });
187
+ return;
188
+ }
189
+ if (req.headers["x-laoshi-token"] !== csrfToken) {
190
+ sendJson(res, 403, { ok: false, error: "缺少或无效的令牌" });
191
+ return;
192
+ }
193
+ if (!options.handlers.tryRun) {
194
+ sendJson(res, 404, { ok: false, error: "当前看板未启用一键试用" });
195
+ return;
196
+ }
197
+ const body = await readJsonBody(req);
198
+ const repo = typeof body.repo === "string" ? body.repo : "";
199
+ const featureDir = typeof body.featureDir === "string" ? body.featureDir : "";
200
+ if (!repo || !featureDir) {
201
+ sendJson(res, 400, { ok: false, error: "缺少目标需求" });
202
+ return;
203
+ }
204
+ const result = await options.handlers.tryRun({ repo, featureDir, stop: Boolean(body.stop) });
205
+ sendJson(res, 200, result);
206
+ return;
207
+ }
208
+ if (req.method === "POST" && url.pathname === "/api/acceptance") {
209
+ if (readOnly) {
210
+ sendJson(res, 403, { ok: false, error: "看板当前为只读模式" });
211
+ return;
212
+ }
213
+ if (req.headers["x-laoshi-token"] !== csrfToken) {
214
+ sendJson(res, 403, { ok: false, error: "缺少或无效的令牌" });
215
+ return;
216
+ }
217
+ if (!options.handlers.submitAcceptance) {
218
+ sendJson(res, 404, { ok: false, error: "当前看板未启用验收提交" });
219
+ return;
220
+ }
221
+ const body = await readJsonBody(req);
222
+ const repo = typeof body.repo === "string" ? body.repo : "";
223
+ const featureDir = typeof body.featureDir === "string" ? body.featureDir : "";
224
+ const reviewer = typeof body.reviewer === "string" && body.reviewer.trim() ? body.reviewer.trim() : "需求方";
225
+ const answers = Array.isArray(body.answers)
226
+ ? (body.answers as Array<Record<string, unknown>>)
227
+ .filter((a) => typeof a?.id === "string" && ["pass", "fail", "skip"].includes(String(a?.mark)))
228
+ .map((a) => ({ id: String(a.id), mark: String(a.mark) as Answer["mark"], note: typeof a.note === "string" ? a.note : undefined }))
229
+ : [];
230
+ if (!repo || !featureDir) {
231
+ sendJson(res, 400, { ok: false, error: "缺少目标需求" });
232
+ return;
233
+ }
234
+ const result = options.handlers.submitAcceptance({ repo, featureDir, reviewer, answers });
235
+ sendJson(res, result.ok ? 200 : 400, result);
236
+ return;
237
+ }
238
+ if (req.method === "POST" && url.pathname === "/api/action") {
239
+ if (readOnly) {
240
+ sendJson(res, 403, { ok: false, error: "看板当前为只读模式" });
241
+ return;
242
+ }
243
+ if (req.headers["x-laoshi-token"] !== csrfToken) {
244
+ sendJson(res, 403, { ok: false, error: "缺少或无效的令牌" });
245
+ return;
246
+ }
247
+ const body = await readJsonBody(req);
248
+ const action = typeof body.action === "string" ? body.action : "";
249
+ const repo = typeof body.repo === "string" ? body.repo : "";
250
+ const featureDir = typeof body.featureDir === "string" ? body.featureDir : "";
251
+ const text = typeof body.text === "string" ? body.text : undefined;
252
+ const to = typeof body.to === "string" ? body.to : undefined;
253
+ const note = typeof body.note === "string" ? body.note : undefined;
254
+ const verifyEnv = typeof body.verifyEnv === "string" ? body.verifyEnv : undefined;
255
+ if (!ALLOWED_ACTIONS.has(action) || !repo || !featureDir) {
256
+ sendJson(res, 400, { ok: false, error: "无效的操作或缺少目标需求" });
257
+ return;
258
+ }
259
+ if (action === "change" && !text?.trim()) {
260
+ sendJson(res, 400, { ok: false, error: "改动内容是空的", message: "改动内容是空的" });
261
+ return;
262
+ }
263
+ if (action === "handover" && !to?.trim()) {
264
+ sendJson(res, 400, { ok: false, error: "接手人不能为空", message: "接手人不能为空" });
265
+ return;
266
+ }
267
+ const result = options.handlers.run({
268
+ action,
269
+ repo,
270
+ featureDir,
271
+ text,
272
+ to,
273
+ note,
274
+ verifyEnv,
275
+ });
276
+ sendJson(res, 200, result);
277
+ return;
278
+ }
279
+ sendJson(res, 404, { error: "未找到路径" });
280
+ } catch (error) {
281
+ sendJson(res, 500, { ok: false, error: (error as Error).message });
282
+ }
283
+ });
284
+
285
+ return { server, csrfToken };
286
+ }
287
+
288
+ function openBrowser(url: string): void {
289
+ const [cmd, args] =
290
+ process.platform === "darwin"
291
+ ? ["open", [url]]
292
+ : process.platform === "win32"
293
+ ? ["cmd", ["/c", "start", "", url]]
294
+ : ["xdg-open", [url]];
295
+ try {
296
+ const child = spawn(cmd, args, { stdio: "ignore", detached: true });
297
+ child.unref();
298
+ } catch {
299
+ // Best effort only.
300
+ }
301
+ }
302
+
303
+ function parseArgs(argv: string[]): { port: number; repo: string | null; readOnly: boolean; noOpen: boolean; help: boolean } {
304
+ let port = 0;
305
+ let repo: string | null = null;
306
+ let readOnly = false;
307
+ let noOpen = false;
308
+ let help = false;
309
+ for (let i = 0; i < argv.length; i++) {
310
+ const a = argv[i];
311
+ if (a === "-h" || a === "--help") help = true;
312
+ else if (a === "--read-only") readOnly = true;
313
+ else if (a === "--no-open") noOpen = true;
314
+ else if (a === "--port" && argv[i + 1]) port = Number(argv[++i]) || 0;
315
+ else if (a.startsWith("--port=")) port = Number(a.slice(7)) || 0;
316
+ else if (a === "--repo" && argv[i + 1]) repo = path.resolve(argv[++i]);
317
+ else if (a.startsWith("--repo=")) repo = path.resolve(a.slice(7));
318
+ }
319
+ return { port, repo, readOnly, noOpen, help };
320
+ }
321
+
322
+ async function main(argv: string[]): Promise<number> {
323
+ const args = parseArgs(argv);
324
+ if (args.help) {
325
+ console.log("用法:laoshi board [--port <端口>] [--repo <目录>] [--read-only] [--no-open]");
326
+ console.log("在本机打开需求看板网页(展示所有待处理、进行中、待测试与已完成需求,支持查看产物与执行操作)。");
327
+ return 0;
328
+ }
329
+ let platformName = "laoshi";
330
+ try {
331
+ const loaded = loadConfig(defaultConfigPath(), args.repo ?? process.cwd());
332
+ platformName = wordsFor(loaded.config).name;
333
+ } catch {
334
+ platformName = wordsFor(DEFAULT_CONFIG).name;
335
+ }
336
+
337
+ const handlers: BoardHandlers = {
338
+ list: () => apiList({ repo: args.repo ?? process.cwd(), all: !args.repo }).map(toRequirementView),
339
+ detail: (repo, feature) => apiStatus(repo, feature),
340
+ file: (repo, feature, file) => apiFile(repo, feature, file),
341
+ history: (repo, feature) => apiHistory(repo, feature),
342
+ run: ({ action, repo, featureDir, text, to, note, verifyEnv }) => {
343
+ if (action === "change") {
344
+ const msg = text?.trim() ?? "";
345
+ if (!msg) return { ok: false, message: "改动内容是空的" };
346
+ return apiRun("reply", repo, featureDir, ["--change", msg]);
347
+ }
348
+ if (action === "handover") {
349
+ const target = to?.trim() ?? "";
350
+ if (!target) return { ok: false, message: "接手人不能为空" };
351
+ return apiRun("handover", repo, featureDir, [target, ...(note?.trim() ? ["--note", note.trim()] : [])]);
352
+ }
353
+ const extra: string[] = [];
354
+ if (verifyEnv) extra.push("--verify-env", verifyEnv);
355
+ if (text) extra.push(text);
356
+ return apiRun(action, repo, featureDir, extra);
357
+ },
358
+ acceptance: (repo, feature) => {
359
+ const featureAbs = path.join(repo, feature);
360
+ return {
361
+ checklist: buildChecklist(featureAbs),
362
+ howTo: howToTry(featureAbs),
363
+ hasAcceptanceRecord: fs.existsSync(path.join(featureAbs, "acceptance.md")),
364
+ };
365
+ },
366
+ submitAcceptance: ({ repo, featureDir, reviewer, answers }) => {
367
+ const featureAbs = path.join(repo, featureDir);
368
+ const list = buildChecklist(featureAbs);
369
+ const v = verdictOf(list, answers);
370
+ if (v.verdict === "通过" && v.missing.length > 0) {
371
+ return {
372
+ ok: false,
373
+ missing: v.missing.map((i) => i.id),
374
+ message: `还有 ${v.missing.length} 条必验项未勾选(${v.missing.map((i) => i.id).join("、")}),全部核对后才能提交通过。`,
375
+ };
376
+ }
377
+ const prevPath = path.join(featureAbs, "acceptance.md");
378
+ const previous = fs.existsSync(prevPath) ? fs.readFileSync(prevPath, "utf8") : undefined;
379
+ const date = new Date().toISOString().slice(0, 10);
380
+ const text = acceptanceText(list, answers, { verdict: v.verdict, reviewer, date, previous });
381
+ const { committed } = recordAcceptance(repo, featureDir, text);
382
+ return {
383
+ ok: true,
384
+ verdict: v.verdict,
385
+ committed,
386
+ message: `验收结论「${v.verdict}」已写入 acceptance.md${committed ? "并提交" : ""}。`,
387
+ };
388
+ },
389
+ tryRun: async ({ repo, featureDir, stop }) => {
390
+ let config: PipelineConfig = DEFAULT_CONFIG;
391
+ try {
392
+ config = loadConfig(defaultConfigPath(), repo).config;
393
+ } catch {
394
+ // Fallback to default config.
395
+ }
396
+ const runtime = await (await loadRuntimeFactory())({ config, log: () => undefined });
397
+ try {
398
+ return await tryRequirement({ repo, featureDir, stop, runtime, config });
399
+ } finally {
400
+ await runtime.close().catch(() => undefined);
401
+ }
402
+ },
403
+ };
404
+
405
+ const { server } = createBoardServer({ handlers, platformName, readOnly: args.readOnly });
406
+ await new Promise<void>((resolve, reject) => {
407
+ server.once("error", reject);
408
+ server.listen(args.port, "127.0.0.1", () => resolve());
409
+ });
410
+ const addr = server.address();
411
+ const actualPort = typeof addr === "object" && addr ? addr.port : args.port;
412
+ const url = `http://127.0.0.1:${actualPort}/`;
413
+ console.log(`需求看板已启动:${url}${args.readOnly ? "(只读模式)" : ""}`);
414
+ console.log("按 Ctrl+C 停止。");
415
+ if (!args.noOpen) openBrowser(url);
416
+
417
+ await new Promise<void>((resolve) => {
418
+ const stop = () => {
419
+ server.close(() => resolve());
420
+ };
421
+ process.once("SIGINT", stop);
422
+ process.once("SIGTERM", stop);
423
+ });
424
+ return 0;
425
+ }
426
+
427
+ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
428
+ main(process.argv.slice(2)).then(
429
+ (code) => process.exit(code),
430
+ (error: Error) => {
431
+ console.error(`启动需求看板失败:${error.message}`);
432
+ process.exit(1);
433
+ },
434
+ );
435
+ }