dsh-harness-kit 0.0.0-stage → 0.1.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 (87) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +321 -2
  3. package/README.zh-CN.md +278 -0
  4. package/client.js +1272 -0
  5. package/cordis.patch.yml +4 -0
  6. package/docs/DETAIL.en.md +97 -0
  7. package/docs/DETAIL.md +73 -0
  8. package/docs/assets/ui-new-task.png +0 -0
  9. package/docs/assets/ui-onboarding.png +0 -0
  10. package/docs/assets/ui-war-room.png +0 -0
  11. package/icon.svg +7 -0
  12. package/index.js +49 -0
  13. package/kernel/advance.js +96 -0
  14. package/kernel/bindings.js +24 -0
  15. package/kernel/commands.js +927 -0
  16. package/kernel/env.js +64 -0
  17. package/kernel/exec.js +41 -0
  18. package/kernel/flows.js +89 -0
  19. package/kernel/guards.js +79 -0
  20. package/kernel/miniyaml.js +133 -0
  21. package/kernel/models.js +104 -0
  22. package/kernel/panel.js +1103 -0
  23. package/kernel/paths.js +53 -0
  24. package/kernel/roles.js +67 -0
  25. package/kernel/setup.js +644 -0
  26. package/kernel/state.js +59 -0
  27. package/kernel/steer.js +27 -0
  28. package/kernel/sync.js +140 -0
  29. package/kernel/te.js +122 -0
  30. package/kernel/worktree.js +868 -0
  31. package/locale/en.json +14 -0
  32. package/locale/zh.json +14 -0
  33. package/package.json +63 -4
  34. package/packs/ai-coding/agents/business-analyst.md +90 -0
  35. package/packs/ai-coding/agents/code-reviewer.md +156 -0
  36. package/packs/ai-coding/agents/developer.md +147 -0
  37. package/packs/ai-coding/agents/project-manager.md +190 -0
  38. package/packs/ai-coding/agents/readiness-reviewer.md +123 -0
  39. package/packs/ai-coding/agents/solution-architect.md +122 -0
  40. package/packs/ai-coding/agents/test-engineer.md +230 -0
  41. package/packs/ai-coding/assets/scripts/check_codegraph.py +215 -0
  42. package/packs/ai-coding/assets/scripts/codebase_guide_init.py +330 -0
  43. package/packs/ai-coding/assets/scripts/env_auto.py +612 -0
  44. package/packs/ai-coding/assets/scripts/harness.py +38 -0
  45. package/packs/ai-coding/assets/scripts/harness_init.py +193 -0
  46. package/packs/ai-coding/assets/scripts/lib.py +1011 -0
  47. package/packs/ai-coding/assets/scripts/run_field.py +295 -0
  48. package/packs/ai-coding/assets/scripts/spec_lint.py +247 -0
  49. package/packs/ai-coding/assets/scripts/update_board.py +524 -0
  50. package/packs/ai-coding/assets/scripts/verify.py +184 -0
  51. package/packs/ai-coding/assets/templates/dotnet/dotnet-multimodule/CODE_STANDARDS.tmpl +44 -0
  52. package/packs/ai-coding/assets/templates/dotnet/dotnet-multimodule/app-CLAUDE.tmpl +34 -0
  53. package/packs/ai-coding/assets/templates/dotnet/dotnet-multimodule/build.tmpl +8 -0
  54. package/packs/ai-coding/assets/templates/dotnet/dotnet-multimodule/module-CLAUDE.tmpl +42 -0
  55. package/packs/ai-coding/assets/templates/dotnet/dotnet-multimodule/root-CLAUDE.tmpl +41 -0
  56. package/packs/ai-coding/assets/templates/java/maven/CODE_STANDARDS.tmpl +44 -0
  57. package/packs/ai-coding/assets/templates/java/maven/build.tmpl +9 -0
  58. package/packs/ai-coding/assets/templates/java/maven/root-CLAUDE.tmpl +38 -0
  59. package/packs/ai-coding/assets/templates/java/maven-multimodule/CODE_STANDARDS.tmpl +44 -0
  60. package/packs/ai-coding/assets/templates/java/maven-multimodule/build.tmpl +9 -0
  61. package/packs/ai-coding/assets/templates/java/maven-multimodule/module-CLAUDE.tmpl +40 -0
  62. package/packs/ai-coding/assets/templates/java/maven-multimodule/root-CLAUDE.tmpl +38 -0
  63. package/packs/ai-coding/assets/templates/javascript/mobile-app/CODE_STANDARDS.tmpl +51 -0
  64. package/packs/ai-coding/assets/templates/javascript/mobile-app/build.tmpl +8 -0
  65. package/packs/ai-coding/assets/templates/javascript/mobile-app/root-CLAUDE.tmpl +36 -0
  66. package/packs/ai-coding/assets/templates/javascript/uniapp/CODE_STANDARDS.tmpl +69 -0
  67. package/packs/ai-coding/assets/templates/javascript/uniapp/build.tmpl +8 -0
  68. package/packs/ai-coding/assets/templates/javascript/uniapp/root-CLAUDE.tmpl +56 -0
  69. package/packs/ai-coding/assets/templates/javascript/vue-multimodule/CODE_STANDARDS.tmpl +51 -0
  70. package/packs/ai-coding/assets/templates/javascript/vue-multimodule/app-CLAUDE.tmpl +36 -0
  71. package/packs/ai-coding/assets/templates/javascript/vue-multimodule/build.tmpl +8 -0
  72. package/packs/ai-coding/assets/templates/javascript/vue-multimodule/root-CLAUDE.tmpl +34 -0
  73. package/packs/ai-coding/flows/_router.yml +14 -0
  74. package/packs/ai-coding/flows/bugfix.yml +37 -0
  75. package/packs/ai-coding/flows/fix.yml +44 -0
  76. package/packs/ai-coding/flows/init.yml +83 -0
  77. package/packs/ai-coding/flows/new.yml +29 -0
  78. package/packs/ai-coding/flows/quick.yml +40 -0
  79. package/packs/ai-coding/flows/refactor.yml +50 -0
  80. package/packs/ai-coding/flows/standard.yml +49 -0
  81. package/packs/ai-coding/rules/code-standards.md +30 -0
  82. package/packs/ai-coding/rules/core.md +83 -0
  83. package/packs/ai-coding/templates/bugfix.md +29 -0
  84. package/packs/ai-coding/templates/memory-entry.md +46 -0
  85. package/packs/ai-coding/templates/proposal.md +47 -0
  86. package/packs/ai-coding/templates/spec-template.md +34 -0
  87. package/screenshots.json +5 -0
@@ -0,0 +1,4 @@
1
+ # Harness Kit bundle composition: one Host plugin row.
2
+ - insert:
3
+ - id: harness-kit
4
+ name: 'dsh-harness-kit'
@@ -0,0 +1,97 @@
1
+ # Harness Kit
2
+
3
+ **Turn AI coding from a personal habit into a team process.**
4
+
5
+ Harness Kit splits analysis, design, implementation, review and testing across fixed roles, puts a
6
+ human at every approval point, and keeps each round's output in your own git asset repository.
7
+ AI executes, humans gate, assets accumulate.
8
+
9
+ Used alone, it is your project memory and a second pair of eyes. Used by a team, it is a shared
10
+ process and shared assets.
11
+
12
+ > A harness is a set of restraints: the stronger the model, the more it needs a stable process.
13
+
14
+ ## It also fills in the project context
15
+
16
+ After the workspace exists, **Start initialization orchestration** probes the registered source
17
+ repositories and generates or fills in the root `AGENTS.md`, per-repository `CLAUDE.md` and
18
+ `docs/CODE_STANDARDS.md`, `<repo>/.harness/build.json` (build, start and test commands),
19
+ `codebase-guide/` module docs and a `.codegraph/` index. Existing files are skipped, and you confirm
20
+ the plan before anything is written.
21
+
22
+ ## Three steps in the UI
23
+
24
+ 1. **Create a workspace**: Harness Kit → + Workspace → New workspace. Pick a directory, an asset
25
+ repository (local, new git, or team git) and source repositories, then create and initialize. The
26
+ wizard checks `git` and `Python 3` first and shows install commands when something is missing.
27
+ Initialization runs in the background and survives a refresh; then start the initialization
28
+ orchestration to generate docs and indexes.
29
+ 2. **Create a task**: + → Requirement or Fix → one sentence (the task name can stay empty). A
30
+ dedicated session opens automatically.
31
+ 3. **Work from the panel**: cards move between Planning / Implementing / To archive. **Needs you**
32
+ lists approvals, archives and sync problems; **Continue session** jumps to the task session.
33
+ Archived work moves to the history board; 🕘 shows team activity; ⚙ edits source branches,
34
+ auto-sync and model mappings.
35
+
36
+ Approvals are written by a human (`proposal.md` for approval 1, `bugfix.md` for the quality gate);
37
+ the panel only reminds. Asset rebinding and removing source repositories stay in commands.
38
+
39
+ ![War room: needs-you list, planning/implementing/to-archive lanes and history board](assets/ui-war-room.png)
40
+
41
+ The screenshot uses a sample workspace (`acme-platform`), not real project data.
42
+
43
+ ## Vibe coding vs Harness Kit
44
+
45
+ | | Personal vibe coding | Harness Kit |
46
+ |---|---|---|
47
+ | Context | In one session, gone when it closes | Under `.harness/`, diffable and handover-ready |
48
+ | Quality | The individual's review at that moment | Fixed roles + approval gates + guards |
49
+ | Collaboration | Separate sessions, verbal sync | Claims, parallel worktrees, test-environment lease |
50
+ | Models | One model throughout | Role/stage routing |
51
+ | Audit | Chat history | Artifacts + approval markers + git history |
52
+
53
+ A one-file change is slower; iterative, cross-module work that you return to weeks later is faster.
54
+
55
+ ## Roles and flows
56
+
57
+ Seven roles: Project Manager (the session Lead), Business Analyst (`requirements.md`), Solution
58
+ Architect (`design.md`), Readiness Reviewer (`readiness-report.md`), Developer (code and
59
+ `dev-log.md`), Code Reviewer (`code-review.md`), Test Engineer (`test-report.md`).
60
+
61
+ Four profiles plus the `fix` shortcut:
62
+
63
+ - `standard`: BA → SA → RR → approval 1 → Dev → CR → TE → approval 2
64
+ - `quick`: small changes, with a self readiness check
65
+ - `bugfix`: full defect-fix flow
66
+ - `refactor`: blast-radius analysis first
67
+ - `fix`: quality gate → Dev → (`--full` adds CR/TE, `--light` verifies only) → archive
68
+
69
+ Source writes are blocked until the quality gate is recorded; `reset --hard`, `clean -f` and
70
+ `push --force` are rejected.
71
+
72
+ ## Assets accumulate
73
+
74
+ `.harness/` is the working copy of the asset repository: `kit.json`, `deliverables/`, `specs/`,
75
+ `memory/`, `tasks/`, and project-level `agents/ flows/`. Every round settles specs and lessons;
76
+ used solo this matters most, because the longer you use it, the thicker the assets and the less the
77
+ next session has to re-explain. Templates and rules
78
+ also live under `.harness/` and can be adapted and committed per team.
79
+
80
+ ## Requirements
81
+
82
+ - DeepSeek Harness 0.2.x with the Web client
83
+ - `git` and `Python 3` (the wizard checks and shows install commands)
84
+ - A DSH session working directory as the Harness workspace
85
+
86
+ ## Compatibility and limits
87
+
88
+ - DSH `>=0.2.0 <0.3.0`; 0.3 needs a new release
89
+ - The panel is a Web feature; commands and guards work in any profile that loads the Host plugin
90
+ - The bundled content pack and panel text are Chinese-first; roles and flows are overridable
91
+ - No MCP host support yet
92
+ - The panel does not write approvals or rebind asset repositories
93
+
94
+ ## Data
95
+
96
+ The plugin runs locally with zero runtime dependencies, no install scripts and no telemetry. Project
97
+ assets live in your team's git; model requests go only to the provider you configure.
package/docs/DETAIL.md ADDED
@@ -0,0 +1,73 @@
1
+ # Harness Kit
2
+
3
+ **把 AI 编程从个人手感,变成团队流程。**
4
+
5
+ Harness Kit 把方案、开发、评审、测试拆给固定角色,在关键节点让人做审批,并把每一轮产物沉淀进你自己的 git 资产仓库。AI 负责执行,人负责把关,资产持续沉淀。
6
+
7
+ 一个人用,它是你的项目记忆和第二双眼睛;一个团队用,它是共享的流程和资产。
8
+
9
+ > Harness 是"挽具":模型越强,越需要一套约束让它稳定输出。
10
+
11
+ ## 它还会补齐项目上下文
12
+
13
+ 创建完成后点「启动初始化编排」,它会探测已登记的子工程,生成/补齐根 `AGENTS.md`、子工程 `CLAUDE.md`、`docs/CODE_STANDARDS.md`、`<子工程>/.harness/build.json`(构建/启动/测试命令)、`codebase-guide/` 模块文档与 `.codegraph/` 索引;已有文件跳过,生成前先给计划确认。
14
+
15
+ ## 三步上手(界面)
16
+
17
+ 1. **新建工作区**:侧栏 Harness Kit →「+ 工作区」→「新建工作区」,选目录、资产仓库、子工程,点「创建并初始化」。向导先检查 `git` / `Python 3`,缺失时直接给出安装命令;初始化在后台执行,刷新页面不中断,完成后可启动初始化编排生成文档与索引。
18
+ 2. **立项**:顶部「+」→「需求」或「fix 直通」→ 一句话描述(任务名可留空)→ 自动打开专属会话。
19
+ 3. **推进**:任务卡片在「规划中 / 实施中 / 待归档」之间移动;「需要你」提醒审批、归档、同步;点「继续会话」处理。归档后进历史任务板;🕘 团队动态;⚙ 配置分支、自动同步与模型映射。
20
+
21
+ 审批由人写下(`proposal.md` 的「审批 1:通过」、`bugfix.md` 的质量门裁决),面板只提醒、不代写。资产换绑与删除子工程仍走命令。
22
+
23
+ ![作战室:需要你、规划/实施/待归档三列与历史任务板](assets/ui-war-room.png)
24
+
25
+ 截图使用示例工作区(`acme-platform`),不是真实项目数据。
26
+
27
+ ## 与个人 Vibe Coding 的区别
28
+
29
+ | | 个人 Vibe Coding | Harness Kit |
30
+ |---|---|---|
31
+ | 上下文 | 留在会话里,关掉就散 | 落进 `.harness/`,可 diff、可交接 |
32
+ | 质量 | 靠个人当场审查 | 固定角色 + 审批点 + 工具护栏 |
33
+ | 协作 | 各开各的会话 | 任务认领、并行 worktree、测试环境租约 |
34
+ | 模型 | 一个模型全程 | 角色/阶段路由 |
35
+ | 审计 | 聊天记录 | 产物 + 审批标记 + git 历史 |
36
+
37
+ 单文件小改会更慢;需要反复迭代、跨模块、隔一段时间再回来接手的活更快。
38
+
39
+ ## 七个角色
40
+
41
+ Project Manager(当前会话 Lead,编排与看板)、Business Analyst(`requirements.md`)、Solution Architect(`design.md`)、Readiness Reviewer(`readiness-report.md`)、Developer(代码 + `dev-log.md`)、Code Reviewer(`code-review.md`)、Test Engineer(`test-report.md`)。
42
+
43
+ ## 四档流程
44
+
45
+ - `standard`:BA → SA → RR → 审批 1 → Dev → CR → TE → 审批 2
46
+ - `quick`:小改动,SA 做就绪自评
47
+ - `bugfix`:缺陷修复全流程
48
+ - `refactor`:SA 先做影响面分析
49
+ - `fix` 直通:质量门 → Dev →(`--full` 含 CR/TE,`--light` 只验证)→ 归档
50
+
51
+ 质量门未裁决时禁止写源码区;`reset --hard`、`clean -f`、`push --force` 直接拦截。
52
+
53
+ ## 资产沉淀
54
+
55
+ `.harness/` 是资产仓库的工作副本:`kit.json`、`deliverables/`、`specs/`、`memory/`、`tasks/`、项目级 `agents/ flows/`。每跑完一轮,规格与踩坑记忆都会沉淀下来;一个人用尤其明显:用得越久,资产越厚,下一次从零解释的成本越低。模板和规则也在 `.harness/` 里,可按团队习惯改写并提交。
56
+
57
+ ## 要求
58
+
59
+ - DeepSeek Harness 0.2.x,带 Web 客户端
60
+ - `git` 与 `Python 3`(向导会检查并给出安装命令)
61
+ - 一个 DSH 会话工作目录作为 Harness 工作区
62
+
63
+ ## 兼容与限制
64
+
65
+ - DSH 范围 `>=0.2.0 <0.3.0`,0.3 需要新版本
66
+ - 面板为 Web 端功能;命令与护栏在加载 Host 插件的 profile 中可用
67
+ - 内置内容包与面板文案以中文为主,角色/流程可按项目覆写
68
+ - 暂不支持 MCP 宿主
69
+ - 面板不代写审批、不做资产换绑
70
+
71
+ ## 数据
72
+
73
+ 插件本地运行,零运行时依赖、无安装脚本、不收集遥测;项目资产在团队自己的 git 仓库;模型请求只发往你配置的 provider。
Binary file
Binary file
Binary file
package/icon.svg ADDED
@@ -0,0 +1,7 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64">
2
+ <rect x="4" y="4" width="56" height="56" rx="12" fill="#1e293b"/>
3
+ <circle cx="32" cy="14" r="5" fill="#38bdf8"/>
4
+ <circle cx="16" cy="44" r="5" fill="#a78bfa"/>
5
+ <circle cx="48" cy="44" r="5" fill="#34d399"/>
6
+ <path d="M32 19 L17 40 M32 19 L47 40 M21 44 L43 44" stroke="#e2e8f0" stroke-width="2.5" stroke-linecap="round" fill="none"/>
7
+ </svg>
package/index.js ADDED
@@ -0,0 +1,49 @@
1
+ // Harness Kit — Host plugin entry.
2
+ // M1: command-driven orchestration (commands steer the Lead with compiled
3
+ // flow prompts), role registry with workspace override, and the Bootstrap
4
+ // write-zone ToolGuard. No custom tools, no runtime imports from shipped
5
+ // dsh packages (bundles cannot resolve @deepseek-ai/* from the profile).
6
+ import fs from 'node:fs';
7
+ import path from 'node:path';
8
+ import { registerCommands } from './kernel/commands.js';
9
+ import { installGuards } from './kernel/guards.js';
10
+ import { registerPanelApi } from './kernel/panel.js';
11
+ import { readKit } from './kernel/paths.js';
12
+ import { collectModelRoutes } from './kernel/models.js';
13
+
14
+ export const inject = ['commands', 'tools'];
15
+
16
+ export function apply(ctx) {
17
+ registerCommands(ctx);
18
+ installGuards(ctx, ctx.get('logger'));
19
+
20
+ // 子智能体模型路由自动授权:DSH 默认子模型限父会话当前模型,宿主级 subagentModelSelection
21
+ // 出厂关且无 GUI——HarnessKit 在会话创建时按工作区 kit.json models 映射追加授权策略事件
22
+ // (与宿主 SubagentModelSelectionConfig 同一挂点 agent/created;子会话自动继承父策略)。
23
+ try {
24
+ ctx.on('agent/created', ({ agent }) => {
25
+ try {
26
+ const session = agent?.session;
27
+ const cwd = session?.header?.cwd;
28
+ if (typeof cwd !== 'string' || cwd === '') return;
29
+ if (!fs.existsSync(path.join(cwd, '.harness', 'kit.json'))) return;
30
+ const kit = readKit(cwd);
31
+ const routes = collectModelRoutes(kit);
32
+ if (routes.length === 0) return;
33
+ // 已挂策略的会话(含子会话继承)由投影幂等忽略重复 append
34
+ session?.append?.('subagent/model-selection-policy', { allowedModels: routes });
35
+ } catch { /* 授权失败不阻断会话 */ }
36
+ });
37
+ } catch { /* 事件不可用(非常规宿主)则静默跳过 */ }
38
+
39
+ // webServer / workspaceRegistry 是异步启动的 cordis 服务:冷启动时 apply
40
+ // 可能先于它们就绪(ctx.get 返回 undefined,路由静默不挂载——2026-11-12
41
+ // 事故:插件随会话中途启用时服务已就绪所以能用,重启后 404)。用 ctx.inject
42
+ // 依赖注入回调,服务就绪后才注册路由;回调返回值作为该注入作用域的 disposer。
43
+ ctx.inject(['webServer', 'workspaceRegistry'], (webCtx) => {
44
+ const disposers = registerPanelApi(webCtx);
45
+ webCtx.get('logger')?.info?.('harness-kit: panel api mounted');
46
+ return () => disposers.forEach((d) => d());
47
+ });
48
+ ctx.get('logger')?.info?.('harness-kit: loaded (commands + guards)');
49
+ }
@@ -0,0 +1,96 @@
1
+ // 自动续接引擎(纯函数部分):人裁决已经在会话里发生后,确定性闸门自动接力,
2
+ // 不再要求人手动敲下一条斜杠命令。
3
+ // 目前两条接力边(都与 flows/*.yml 的硬闸门一一对应):
4
+ // 定稿(proposal.md 状态行 approved)+ 看板 PENDING → /hk-propose <task>
5
+ // 审批 1 通过 + 看板 IN_PROGRESS → /hk-apply <task>
6
+ // 触发守卫:
7
+ // - 看板状态行是第一道闸(hk-propose 成功会置 IN_PROGRESS,天然阻断重复触发);
8
+ // - 一次性标记落盘 .harness/tasks/auto-advance.json(host 重载后仍然幂等;
9
+ // /hk-new、/hk-fix、/hk-archive 会清理对应任务标记,重建/归档后可重新接力);
10
+ // - 审批/归档本身仍是人裁决:本引擎只在人写下 approved / 审批 1:通过 之后接力。
11
+ // 修复直通(fix profile)没有这两个闸门,不参与自动续接。
12
+ import fs from 'node:fs';
13
+ import path from 'node:path';
14
+ import { harnessDir } from './paths.js';
15
+
16
+ // 与 kernel/commands.js 的闸门正则同源(那边用于命令准入,这边用于触发扫描)。
17
+ const APPROVAL1 = /审批\s*1[^0-9\n]{0,20}(通过|PASS)/i;
18
+ // 审批 2 在看板 Apply 链上以「审批2✅」落标记(update_board.py 的链 token),
19
+ // PM 只有在人裁决通过后才写——引擎据此接力 /hk-archive(2026-11-17 定,与 审批1→apply 同构)。
20
+ const APPROVAL2 = /审批\s*2\s*(✅|通过|PASS)/i;
21
+ const STATUS_APPROVED = /状态[**]*[::][ \t]*`?approved(?![\w-])/im;
22
+ const TASK_RE = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
23
+
24
+ const marksPath = (ws) => path.join(harnessDir(ws), 'tasks', 'auto-advance.json');
25
+
26
+ /** 读一次性触发标记(坏文件容忍为 {})。 */
27
+ export function readAdvanceMarks(ws) {
28
+ try {
29
+ const data = JSON.parse(fs.readFileSync(marksPath(ws), 'utf8'));
30
+ return data && typeof data === 'object' && data.fired && typeof data.fired === 'object' ? data.fired : {};
31
+ } catch { return {}; }
32
+ }
33
+
34
+ /** 落盘一条触发标记(task:hop → ISO 时间)。 */
35
+ export function markAdvanceFired(ws, task, hop) {
36
+ const fired = readAdvanceMarks(ws);
37
+ fired[`${task}:${hop}`] = new Date().toISOString();
38
+ fs.mkdirSync(path.dirname(marksPath(ws)), { recursive: true });
39
+ fs.writeFileSync(marksPath(ws), `${JSON.stringify({ fired }, null, 2)}\n`, 'utf8');
40
+ }
41
+
42
+ /** 清理某任务的全部触发标记(/hk-new、/hk-fix 重建任务、/hk-archive 归档时调用)。 */
43
+ export function clearAdvanceMarks(ws, task) {
44
+ const fired = readAdvanceMarks(ws);
45
+ let changed = false;
46
+ for (const key of Object.keys(fired)) {
47
+ if (key.startsWith(`${task}:`)) { delete fired[key]; changed = true; }
48
+ }
49
+ if (changed) {
50
+ fs.mkdirSync(path.dirname(marksPath(ws)), { recursive: true });
51
+ fs.writeFileSync(marksPath(ws), `${JSON.stringify({ fired }, null, 2)}\n`, 'utf8');
52
+ }
53
+ }
54
+
55
+ /** 解析看板 markdown 表行(与 panel.js parseBoard 的列契约一致,只取需要的列)。 */
56
+ function boardRows(text) {
57
+ const table = text.split('\n').filter((l) => l.startsWith('|'));
58
+ if (table.length < 3) return [];
59
+ return table.slice(2).map((line) => {
60
+ const c = line.trim().replace(/^\||\|$/g, '').split('|').map((x) => x.trim());
61
+ return { task: c[0] ?? '', status: (c[1] ?? '').toUpperCase(), profile: (c[2] ?? '').toLowerCase(), apply: c[3] ?? '' };
62
+ });
63
+ }
64
+
65
+ /**
66
+ * 扫描一个工作区,返回当前应自动接力的动作列表。
67
+ * 三条接力边(与 flows 的硬闸门一一对应):
68
+ * 定稿 approved + PENDING → /hk-propose
69
+ * 审批 1 通过 + IN_PROGRESS → /hk-apply
70
+ * 审批 2 ✅ + AWAITING_ARCHIVE → /hk-archive(人已裁决归档,机器执行)
71
+ * @returns {{task: string, hop: 'propose'|'apply'|'archive', line: string}[]}
72
+ */
73
+ export function scanAutoAdvance(ws) {
74
+ const boardFile = path.join(harnessDir(ws), 'tasks', 'board.md');
75
+ if (!fs.existsSync(boardFile)) return [];
76
+ let rows;
77
+ try { rows = boardRows(fs.readFileSync(boardFile, 'utf8')); } catch { return []; }
78
+ const marks = readAdvanceMarks(ws);
79
+ const out = [];
80
+ for (const row of rows) {
81
+ if (!TASK_RE.test(row.task)) continue;
82
+ // 只看全流程任务(有 proposal.md);fix 直通/bugfix 无此文档,天然跳过
83
+ const proposalPath = path.join(harnessDir(ws), 'deliverables', row.task, 'proposal.md');
84
+ if (!fs.existsSync(proposalPath)) continue;
85
+ let proposal;
86
+ try { proposal = fs.readFileSync(proposalPath, 'utf8'); } catch { continue; }
87
+ if (row.status === 'PENDING' && STATUS_APPROVED.test(proposal) && !marks[`${row.task}:propose`]) {
88
+ out.push({ task: row.task, hop: 'propose', line: `/hk-propose ${row.task}` });
89
+ } else if (row.status === 'IN_PROGRESS' && APPROVAL1.test(proposal) && !marks[`${row.task}:apply`]) {
90
+ out.push({ task: row.task, hop: 'apply', line: `/hk-apply ${row.task}` });
91
+ } else if (row.status === 'AWAITING_ARCHIVE' && APPROVAL2.test(row.apply) && !marks[`${row.task}:archive`]) {
92
+ out.push({ task: row.task, hop: 'archive', line: `/hk-archive ${row.task}` });
93
+ }
94
+ }
95
+ return out;
96
+ }
@@ -0,0 +1,24 @@
1
+ // 任务 ↔ 会话绑定表(.harness/tasks/sessions.json)。
2
+ // 记录点:面板 /harness-kit/command 成功执行、kernel 命令 handler(hk-new/hk-fix 内直接登记,
3
+ // 覆盖「在会话里手敲命令」的场景)、客户端新开会话后 POST /harness-kit/bind-session。
4
+ // 用途:面板「重开/继续实施/转到会话」跳转;自动续接引擎据此找到任务所属会话。
5
+ import fs from 'node:fs';
6
+ import path from 'node:path';
7
+ import { harnessDir } from './paths.js';
8
+
9
+ /** 读任务→会话绑定表(坏文件容忍为 {})。 */
10
+ export function readTaskSessions(ws) {
11
+ try {
12
+ const data = JSON.parse(fs.readFileSync(path.join(harnessDir(ws), 'tasks', 'sessions.json'), 'utf8'));
13
+ return data && typeof data === 'object' && data.tasks && typeof data.tasks === 'object' ? data.tasks : {};
14
+ } catch { return {}; }
15
+ }
16
+
17
+ /** 登记/覆盖任务→会话绑定。 */
18
+ export function recordTaskSession(ws, task, sessionId) {
19
+ const file = path.join(harnessDir(ws), 'tasks', 'sessions.json');
20
+ const tasks = readTaskSessions(ws);
21
+ tasks[task] = { sessionId, at: new Date().toISOString() };
22
+ fs.mkdirSync(path.dirname(file), { recursive: true });
23
+ fs.writeFileSync(file, `${JSON.stringify({ tasks }, null, 2)}\n`, 'utf8');
24
+ }