doukui 0.8.0 → 0.9.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 (62) hide show
  1. package/README.en.md +85 -18
  2. package/README.md +8 -8
  3. package/bin/commands/help.js +2 -0
  4. package/bin/commands/plan-lint.js +105 -0
  5. package/bin/commands/verify.js +263 -0
  6. package/bin/doukui.js +2 -0
  7. package/package.json +1 -1
  8. package/plugins/core/hook-session-start/index.js +1 -1
  9. package/plugins/core/hook-skill-gate/index.js +64 -15
  10. package/plugins/core/hook-skill-gate/plugin.json +1 -1
  11. package/plugins/core/skill-agent-dispatcher/cleanup-reference.md +7 -28
  12. package/plugins/core/skill-agent-dispatcher/monitoring-reference.md +5 -177
  13. package/plugins/core/skill-agent-dispatcher/plugin.json +1 -1
  14. package/plugins/core/skill-agent-dispatcher/recovery-reference.md +99 -58
  15. package/plugins/core/skill-agent-dispatcher/roles-reference.md +9 -22
  16. package/plugins/core/skill-agent-dispatcher/skill.md +112 -524
  17. package/plugins/core/skill-agentic-loop/mirror-rules.md +15 -3
  18. package/plugins/core/skill-agentic-loop/plugin.json +1 -1
  19. package/plugins/core/skill-agentic-loop/skill.md +123 -324
  20. package/plugins/core/skill-batch-task-creator/plugin.json +1 -1
  21. package/plugins/core/skill-checklist/skill.md +15 -141
  22. package/plugins/core/skill-completion-report/plugin.json +1 -1
  23. package/plugins/core/skill-doukui-plan/plugin.json +1 -1
  24. package/plugins/core/skill-doukui-plan/skill.md +22 -22
  25. package/plugins/core/skill-experience-logger/plugin.json +1 -1
  26. package/plugins/core/skill-human-checkpoint/skill.md +1 -0
  27. package/plugins/core/skill-split-work-package/plugin.json +1 -1
  28. package/plugins/core/skill-task-creator/plugin.json +1 -1
  29. package/plugins/core/skill-task-creator/skill.md +1 -139
  30. package/plugins/core/skill-workflow-orchestrator/plugin.json +1 -1
  31. package/plugins/plugin-registry.json +0 -36
  32. package/plugins/runtime/harness-build.js +5 -5
  33. package/plugins/runtime/plan-reader.js +21 -3
  34. package/plugins/runtime/resolve-plugin-path.js +2 -2
  35. package/plugins/contracts/capabilities.js +0 -268
  36. package/plugins/core/provider-memory-store/index.js +0 -510
  37. package/plugins/core/provider-memory-store/plugin.json +0 -9
  38. package/plugins/core/provider-state-store/index.js +0 -244
  39. package/plugins/core/provider-state-store/plugin.json +0 -9
  40. package/plugins/core/provider-watchdog/assets/daemon-config.template.json +0 -32
  41. package/plugins/core/provider-watchdog/assets/lib/watchdog-multi-window.js +0 -676
  42. package/plugins/core/provider-watchdog/assets/watchdog.js +0 -754
  43. package/plugins/core/provider-watchdog/index.js +0 -151
  44. package/plugins/core/provider-watchdog/plugin.json +0 -13
  45. package/plugins/core/skill-agent-dispatcher/daemon-helpers-reference.md +0 -249
  46. package/plugins/core/skill-watchdog-manager/plugin.json +0 -10
  47. package/plugins/core/skill-watchdog-manager/skill.md +0 -143
  48. package/plugins/core/validator-doc-sync/index.js +0 -248
  49. package/plugins/core/validator-doc-sync/plugin.json +0 -12
  50. package/plugins/core/validator-work-package/index.js +0 -300
  51. package/plugins/core/validator-work-package/plugin.json +0 -12
  52. package/plugins/runtime/audit-logger.js +0 -311
  53. package/plugins/runtime/build-cli.js +0 -89
  54. package/plugins/runtime/event-bus.js +0 -207
  55. package/plugins/runtime/hook-dispatcher.js +0 -315
  56. package/plugins/runtime/plugin-loader.js +0 -798
  57. package/plugins/runtime/plugin-trust.js +0 -182
  58. package/plugins/runtime/sandbox-context.js +0 -235
  59. package/plugins/runtime/sandbox-manager.js +0 -609
  60. package/plugins/runtime/sandbox-worker.js +0 -215
  61. package/plugins/runtime/text-tokenize.js +0 -24
  62. package/plugins/runtime/validator-pipeline.js +0 -475
package/README.en.md CHANGED
@@ -1,42 +1,109 @@
1
1
  # Doukui
2
2
 
3
- > Multi-provider AI agent orchestration harness for Claude Code — goal-driven agentic loop, dependency-graph parallel dispatch, per-WP worktree isolation, and first-class multi-provider support (GLM / DeepSeek / MiMo / Claude)
3
+ > An in-session orchestration discipline pack for Claude Code — a full set of skills (workflow / task splitting / loop / checkpoints), the plan-reader contract, dispatcher multi-agent parallelism, and the PROGRESS convention
4
4
 
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
6
- [![Version](https://img.shields.io/badge/version-0.3.0-blue.svg)](https://github.com/chen-xiaochen/doukui)
6
+ [![Version](https://img.shields.io/badge/version-0.9.0-blue.svg)](https://github.com/chen-xiaochen/doukui)
7
7
 
8
8
  **[中文文档](./README.md)**
9
9
 
10
- > "Doukui" (斗魁) names the four stars forming the bowl of the Big Dipper — the pivot around which the handle turns. All work packages orbit it; many models drive it.
10
+ > "Doukui" (斗魁) names the four stars forming the bowl of the Big Dipper — the pivot around which the handle turns. Every work package orbits it.
11
11
  > Doukui is a ground-up rebuild of [tackle-harness](https://github.com/ph419/tackle-harness) v0.4.9 (Nov 2026, refactor phases A–E). Thanks to its predecessor.
12
12
 
13
13
  ## Why Doukui
14
14
 
15
- You run Claude Code, but your daily models are domestic providers (Zhipu GLM / DeepSeek / MiMo) over Anthropic-compatible endpoints. The official ecosystem does not cover you: server-side compaction, the memory tool, and constrained decoding are Anthropic-side capabilities. **Doukui fills the orchestration layer that the domestic-model camp is missing**:
15
+ You run complex tasks in Claude Code, but the model itself does not orchestrate: how to split requirements, how to parallelize agents, how to self-heal on failure, how to keep progress — all improvised again in every session. **Doukui fixes that orchestration discipline into skills + contracts + config**:
16
16
 
17
- - **Plan first, human gate** — the AI outputs an implementation plan and work-package split; you approve before any code is written.
18
- - **Parallel delivery by dependency graph** — large requests are split into work packages (WPs) dispatched in parallel; each WP runs in its own git worktree and is cherry-picked back.
19
- - **Multi-provider in one plan** — switch providers with `--settings`; per-provider quota accounting, context-window tiering (DeepSeek V4 → 1M), GLM 5h-window quota as observability-only.
20
- - **Selectable execution carrier** — `--executor=sdk` (Claude Agent SDK: streaming messages, session resume) or `--executor=default` (spawn CLI fallback, zero SDK dependency). Checklist self-reports pass through JSON Schema validation plus objective command cross-checking; LLM lying is overridden.
21
- - **Experience accrues** — lessons are distilled after each task and stored per role for future sessions.
17
+ - **Plan first, human gate** — the AI outputs an implementation plan and a work-package split; you approve before any code is written. No "the AI went ahead and changed a pile of things".
18
+ - **Complex requirements, parallel delivery** — large requirements are split into independent work packages (WPs), dispatched in parallel by the dispatcher along the dependency graph.
19
+ - **Goal-driven closed loop (Agentic Loop)** — a failing checklist does not return to a human; the loop retries / resplits in-session for several rounds until it converges or exhausts self-rescue. Rules and thresholds have a single source of truth (`mirror-rules.md`), no improvisation.
20
+ - **Verify-first acceptance** — plan checklist items can carry a `[verify: npm test]` tag; anything a command can verify needs zero LLM free-form judgment (more reliable, fewer tokens).
21
+ - **Experience accrues** — lessons are distilled after each task and archived per role for later sessions.
22
22
 
23
- ## Quick start
23
+ > Since v0.7.0 the unattended driver (`doukui loop` subprocess) is retired — the in-session path is the only execution path, and provider/model switching is back to Claude Code session-level config (see the BREAKING note in the [CHANGELOG](CHANGELOG.md)).
24
+
25
+ ## Core concept: Agentic Loop (in-session)
26
+
27
+ - **Single source of truth for decisions**: `plugins/core/skill-agentic-loop/mirror-rules.md` owns all Observe→Think→Act→Reflect→Decide rules and threshold defaults; the in-session Lead reproduces them from that file. There is no JS decision-engine mirror and no CI mirror lock.
28
+ - **Triple caps + self-rescue before terminal state**: `max_iterations` (default 6), `max_round_time_ms` (10 min), `max_wall_time_ms` (1 h); the P1 confirmation may override them. Before a terminal state (diverged/timeout) the Lead exhausts the retry/resplit order from mirror-rules; only then escalates to a human.
29
+ - **Act is delegated to the dispatcher**: the loop is the decision layer and never writes code; Act serializes the decision into dispatcher instructions executed by agent-dispatcher with multiple agents.
30
+ - **Verify-first acceptance**: plan checklist items can carry a `[verify: npm test]` tag — command-verifiable items need zero LLM judgment.
31
+ - **Progress is observability**: every round's verdict/proximity is written to PROGRESS.md / task.md (`skill-progress-tracker`), the same source the Observe snapshot reads.
32
+ - **Risk-tiered human review**: a plan declares `风险分级: low` at the top level (pure doc/test work) — P1 becomes a lightweight one-line confirmation and the mandatory-pause gate is waived automatically; undeclared plans get the full human review as usual.
33
+
34
+ ## Install
35
+
36
+ Requires Node.js >= 18.0.0
24
37
 
25
38
  ```bash
26
39
  npm install -g doukui
27
40
  cd your-project
28
- doukui init
41
+ doukui init # create config dir + register hooks
42
+ ```
29
43
 
30
- # Smoke test (mock executor, free)
31
- doukui loop test/fixtures/todo-cli-smoke.md --executor=local
44
+ ## Commands
45
+
46
+ | Command | Description |
47
+ |------|------|
48
+ | `doukui build` | Build all plugins (default command) |
49
+ | `doukui validate` / `validate-config` | Validate plugin format / harness-config |
50
+ | `doukui plan-lint <plan.md>` | Lint a plan file (read-only): work units / dependency topology / success criteria / verify coverage. Exit 0 usable, 1 unusable |
51
+ | `doukui verify <plan.md> --wp WP-NNN\|all` | Batch-run a unit's `[verify:]` checklist commands and emit a CheckResult. Exit 0 all passed / 1 any failure / 2 no verify item |
52
+ | `doukui init` | First-time setup: build + config |
53
+ | `doukui install` | Install an external plugin (with security review) |
54
+ | `doukui migrate` | Migrate legacy project config |
55
+ | `doukui status` / `list` / `config` | Status / plugin list / config query |
56
+ | `doukui interactive` | Interactive plugin management (alias `i`) |
57
+ | `doukui setup-global` | Install global skills to ~/.claude/skills/ |
58
+ | `doukui team-cleanup <name>` | Deterministic cleanup of leftover Agent Teams directories |
59
+ | `doukui version` / `help` | Version / help |
60
+
61
+ ## Workflow overview
32
62
 
33
- # Real run: SDK carrier over a GLM plan (provider auto-detected from --settings)
34
- doukui loop docs/plan/my-plan.md --executor=sdk \
35
- --settings=~/.claude/settings-glm-5.2[1m]max.json
36
63
  ```
64
+ requirement → plan(P0) → review(P1) → execute(P2) → check(P3) → report(P4) → deliver
65
+ ```
66
+
67
+ | Stage | What happens | Key skills |
68
+ |------|--------|----------|
69
+ | **P0 plan** | Parse the requirement, split into work packages, write docs | task-creator, split-work-package |
70
+ | **P1 review** | Pause for your approval of the plan (mandatory human gate) | human-checkpoint |
71
+ | **P2 execute** | Multi-agent parallel development, dispatched along the dependency graph | agent-dispatcher / agentic-loop |
72
+ | **P3 check** | Code/test/doc quality verification, distill lessons | checklist, experience-logger |
73
+ | **P4 report** | Generate the completion report, ask for next steps | completion-report |
74
+
75
+ ## Plugin architecture
76
+
77
+ Three plugin types, 19 in total:
78
+
79
+ | Type | Count | Role |
80
+ |------|------|------|
81
+ | Skill | 16 | Executable skills, called directly by Claude Code |
82
+ | Provider | 1 | Role registry (consumed by agent-def-generator) |
83
+ | Hook | 2 | Skill gating + session-start injection of plan-mode rules |
84
+
85
+ ## Docs (Chinese)
86
+
87
+ - [Workflow in depth](docs/design/ai_workflow.md) — full data flow
88
+ - [Agentic Loop design](docs/design/agentic-loop-design.md) — historical design doc (driver path retired, banner at the top; current rules live in `plugins/core/skill-agentic-loop/mirror-rules.md`)
89
+ - [Config reference](docs/design/config-reference.md) — full harness-config.yaml reference
90
+ - [Plugin development](docs/design/plugin-development.md) / [API reference](docs/design/api-reference.md)
91
+ - [Security policy](SECURITY.md) — vulnerability reporting; the sandbox isolation layer was retired in v0.9.0 ([historical threat model](docs/design/sandbox-threat-model.md)). Third-party plugins are loaded after `doukui install` capability confirmation + manual review
92
+
93
+ ## Relation to the predecessor
94
+
95
+ | | tackle-harness (predecessor) | doukui |
96
+ |---|---|---|
97
+ | Execution carrier | spawn `claude -p`, single path | in-session skills + dispatcher multi-agent (driver subprocess retired in v0.7.0) |
98
+ | Structured output | bare fenced-block parsing | fenced + machine-readable block + objective verify commands |
99
+ | Thresholds/decisions | three hard-coded copies | mirror-rules.md single source of truth (self-owned thresholds) |
100
+ | Brand/commands | tackle-harness / tackle | doukui |
101
+
102
+ ## Acknowledgements
37
103
 
38
- Requires Node.js >= 18. See the [Chinese README](./README.md) for the full guide (command reference, plugin architecture, design docs, provider capability matrix).
104
+ - [tackle-harness](https://github.com/ph419/tackle-harness) — the predecessor; the entire skeleton of Doukui comes from it
105
+ - DeerFlow — reference for memory extraction and plugin architecture
39
106
 
40
107
  ## License
41
108
 
42
- MIT — see [LICENSE](LICENSE).
109
+ MIT License - see [LICENSE](LICENSE)
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  > Claude Code 的会话内编排纪律包 —— skills 全家(工作流/任务拆分/循环/检查点)、plan-reader 契约、dispatcher 多 agent 并行、PROGRESS 进度约定
4
4
 
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
6
- [![Version](https://img.shields.io/badge/version-0.7.0-blue.svg)](https://github.com/chen-xiaochen/doukui)
6
+ [![Version](https://img.shields.io/badge/version-0.9.0-blue.svg)](https://github.com/chen-xiaochen/doukui)
7
7
 
8
8
  **[English](./README.en.md)**
9
9
 
@@ -27,9 +27,8 @@
27
27
  - **判定规则单一真相源**:`plugins/core/skill-agentic-loop/mirror-rules.md` 自持 Observe→Think→Act→Reflect→Decide 全部规则与阈值默认;会话内 Lead 按该文件复现,不存在 JS 判定代码镜像,也没有 CI 镜像锁
28
28
  - **三重上限保护 + 终态前自救**:`max_iterations`(默认 6)、`max_round_time_ms`(10min)、`max_wall_time_ms`(1h)触发或 P1 确认时可覆盖;终态(diverged/timeout)前先按 mirror-rules 的 retry/resplit 顺序穷尽自救,穷尽才升级人介入
29
29
  - **Act 委托 dispatcher**:loop 是决策层不写代码,Act 阶段把 decision 序列化为 dispatcher 指令,由 agent-dispatcher 多 agent 执行
30
- - **verify 优先的验收**:plan 验收项可加 `[verify: npm test]` 尾标——命令可验证的项零 LLM 自由判断(更可靠且省 token)
31
30
  - **进度即观测**:每轮 verdict/proximity 记录到 PROGRESS.md / task.md(`skill-progress-tracker`),Observe 快照同源
32
- - **风险分级人审**:plan 顶层声明 `风险分级: low` + 环境设一次 `DOUKUI_LOW_RISK_GATE=1`,纯文档/测试类任务全程无人值守;未声明的 plan 照常完整人审
31
+ - **风险分级人审**:plan 顶层声明 `风险分级: low`(纯文档/测试补充类)→ P1 轻量化一句话确认、门控自动豁免强制暂停;未声明风险的 plan 照常完整人审
33
32
 
34
33
  ## 安装
35
34
 
@@ -47,6 +46,8 @@ doukui init # 创建配置目录 + 注册钩子
47
46
  |------|------|
48
47
  | `doukui build` | 构建所有插件(默认命令) |
49
48
  | `doukui validate` / `validate-config` | 插件格式 / harness-config 校验 |
49
+ | `doukui plan-lint <plan.md>` | 计划体检(只读):工作单元 / 依赖拓扑 / 成功标准 / verify 覆盖率,退出码 0 可用 1 不可用 |
50
+ | `doukui verify <plan.md> --wp WP-NNN\|all` | 批跑单元 checklist 的 `[verify:]` 命令并输出 CheckResult,退出码 0 全过 / 1 有失败 / 2 无 verify 项 |
50
51
  | `doukui init` | 首次安装:build + config |
51
52
  | `doukui install` | 安装外部插件(含安全审查) |
52
53
  | `doukui migrate` | 迁移旧项目配置 |
@@ -72,14 +73,13 @@ doukui init # 创建配置目录 + 注册钩子
72
73
 
73
74
  ## 插件架构
74
75
 
75
- 四类插件,共 25 个:
76
+ 三类插件,共 19 个:
76
77
 
77
78
  | 类型 | 数量 | 作用 |
78
79
  |------|------|------|
79
- | Skill | 17 | 可执行技能,Claude Code 直接调用 |
80
- | Provider | 4 | 状态存储、角色注册、记忆存储、守护进程 |
80
+ | Skill | 16 | 可执行技能,Claude Code 直接调用 |
81
+ | Provider | 1 | 角色注册(agent-def-generator 消费) |
81
82
  | Hook | 2 | 技能门控 + 会话启动注入 plan-mode 规则 |
82
- | Validator | 2 | 文档同步验证、工作包验证 |
83
83
 
84
84
  ## 文档
85
85
 
@@ -87,7 +87,7 @@ doukui init # 创建配置目录 + 注册钩子
87
87
  - [Agentic Loop 设计](docs/design/agentic-loop-design.md) — 历史设计文档(driver 路径已退役,顶部有横幅;现行判定规则见 `plugins/core/skill-agentic-loop/mirror-rules.md`)
88
88
  - [配置参考](docs/design/config-reference.md) — harness-config.yaml 全量说明
89
89
  - [插件开发](docs/design/plugin-development.md) / [API 参考](docs/design/api-reference.md)
90
- - [安全披露](SECURITY.md) — sandbox 能力声明当前为 decorative(未强制),加载第三方插件前请阅读
90
+ - [安全政策](SECURITY.md) — 漏洞报告渠道;沙箱隔离层已随 v0.9.0 退役([历史威胁模型](docs/design/sandbox-threat-model.md)),第三方插件经 `doukui install` 能力确认 + 人工审查后加载
91
91
 
92
92
  ## 与前身的关系
93
93
 
@@ -23,6 +23,8 @@ module.exports = {
23
23
  ['build', 'Build all plugins (default)'],
24
24
  ['validate', 'Validate plugin.json files'],
25
25
  ['validate-config', 'Validate harness-config.yaml'],
26
+ ['plan-lint', 'Lint a plan file: work units, dependency order, verify coverage'],
27
+ ['verify', 'Run a plan work unit\'s [verify:] commands and emit CheckResult'],
26
28
  ['init', 'First-time setup (build + config)'],
27
29
  ['install', 'Install an external plugin with security review'],
28
30
  ['migrate', 'Migrate legacy project structure to global setup'],
@@ -0,0 +1,105 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * plan-lint command - Lint a plan file via plan-reader and print a work-unit summary (read-only)
5
+ * @public
6
+ */
7
+
8
+ var planReader = require('../../plugins/runtime/plan-reader');
9
+
10
+ /**
11
+ * Aggregate verify coverage over all work packages (works for cyclic results too,
12
+ * where goal.checklistSpec is null).
13
+ * @param {Array} workPackages
14
+ * @returns {{withVerify:number, total:number}}
15
+ */
16
+ function verifyCoverage(workPackages) {
17
+ var total = 0;
18
+ var withVerify = 0;
19
+ for (var i = 0; i < workPackages.length; i++) {
20
+ var cl = workPackages[i].checklist || [];
21
+ total += cl.length;
22
+ for (var j = 0; j < cl.length; j++) {
23
+ if (cl[j].verify) withVerify += 1;
24
+ }
25
+ }
26
+ return { withVerify: withVerify, total: total };
27
+ }
28
+
29
+ module.exports = {
30
+ name: 'plan-lint',
31
+ description: 'Lint a plan file: work units, dependency order, verify coverage (read-only)',
32
+ /**
33
+ * Execute the plan-lint command.
34
+ * usage: doukui plan-lint [path] [--json]
35
+ * path defaults to resolvePlanPath() (argument path > .claude/plan.md)
36
+ * exit 0 = usable; exit 1 = unusable
37
+ * (parse error / wpIds empty / successCriteria empty / cyclic dependency)
38
+ * @public
39
+ * @param {object} ctx - CLI context object
40
+ */
41
+ execute: function (ctx) {
42
+ var argv = ctx.argv || [];
43
+ var json = false;
44
+ var positional = null;
45
+ for (var i = 0; i < argv.length; i++) {
46
+ if (argv[i] === '--json') json = true;
47
+ else if (positional === null) positional = argv[i];
48
+ }
49
+
50
+ var projectRoot = ctx.targetRoot;
51
+ var planPath = planReader.resolvePlanPath({ planFilePath: positional, projectRoot: projectRoot });
52
+ var result = planReader.parsePlanToGoal({
53
+ planFilePath: planPath,
54
+ projectRoot: projectRoot,
55
+ throwOnCycle: false,
56
+ });
57
+
58
+ var reasons = [];
59
+ if (result.error) reasons.push(result.error);
60
+ if (result.goal.wpIds.length === 0) reasons.push('wpIds-empty');
61
+ if (result.dependencyGraph.hasCycle) reasons.push('cyclic-dependency');
62
+ // cyclic path returns before goal assembly, successCriteria is not extracted there
63
+ else if (result.goal.successCriteria.length === 0) reasons.push('successCriteria-empty');
64
+ var usable = reasons.length === 0;
65
+
66
+ if (json) {
67
+ console.log(JSON.stringify(result, null, 2));
68
+ ctx.exit(usable ? 0 : 1);
69
+ return;
70
+ }
71
+
72
+ var wps = result.workPackages;
73
+ var cov = verifyCoverage(wps);
74
+ var pct = cov.total === 0 ? 0 : Math.round((cov.withVerify / cov.total) * 100);
75
+
76
+ console.log(ctx.colorize('plan: ', 'dim') + result.planFilePath);
77
+ console.log(ctx.colorize('工作单元', 'cyan') + '(' + wps.length + ' 个)');
78
+ for (var w = 0; w < wps.length; w++) {
79
+ var wp = wps[w];
80
+ var deps = wp.dependencies.length ? wp.dependencies.join(', ') : '无';
81
+ var verifyCount = wp.checklist.filter(function (it) { return it.verify; }).length;
82
+ console.log(' ' + ctx.colorize(wp.wpId, 'green') + ' ' + wp.title);
83
+ console.log(
84
+ ctx.colorize(' 依赖: ', 'dim') + deps +
85
+ ctx.colorize(' checklist: ', 'dim') + wp.checklist.length +
86
+ ctx.colorize(' verify: ', 'dim') + verifyCount
87
+ );
88
+ }
89
+ console.log(ctx.colorize('拓扑序', 'cyan') + ':' + (result.dependencyGraph.order.join(' → ') || '(空)'));
90
+ console.log(ctx.colorize('成功标准', 'cyan') + ':' + result.goal.successCriteria.length + ' 条');
91
+ console.log(ctx.colorize('风险分级', 'cyan') + ':riskLow=' +
92
+ (result.riskLow === true ? 'true(人审豁免)' : 'false(人审照常)'));
93
+ console.log(ctx.colorize('verify 覆盖率', 'cyan') + ':' + cov.withVerify + '/' + cov.total + '(' + pct + '%)');
94
+
95
+ if (usable) {
96
+ console.log(ctx.colorize('结论:可用', 'green'));
97
+ } else {
98
+ console.log(ctx.colorize('结论:不可用', 'red'));
99
+ for (var r = 0; r < reasons.length; r++) {
100
+ console.log(ctx.colorize(' - ' + reasons[r], 'red'));
101
+ }
102
+ }
103
+ ctx.exit(usable ? 0 : 1);
104
+ },
105
+ };
@@ -0,0 +1,263 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * verify command - Batch-run the `[verify: ...]` commands of a plan work unit's
5
+ * checklist (plan-reader contract) and emit a CheckResult
6
+ * @public
7
+ */
8
+
9
+ var childProcess = require('child_process');
10
+ var planReader = require('../../plugins/runtime/plan-reader');
11
+
12
+ var DEFAULT_TIMEOUT_SEC = 600;
13
+ var MAX_TIMEOUT_SEC = 1800;
14
+ var MAX_BUFFER = 16 * 1024 * 1024;
15
+ var OUTPUT_TAIL_LEN = 600;
16
+ var USAGE = 'doukui verify <plan路径> --wp WP-NNN|all [--timeout 秒] [--json]';
17
+
18
+ /**
19
+ * Tail of captured stdout/stderr (truncated, for retry positioning).
20
+ */
21
+ function tailOf(stdout, stderr) {
22
+ var s = (String(stdout || '') + '\n' + String(stderr || '')).trim();
23
+ return s.length > OUTPUT_TAIL_LEN ? '…' + s.slice(-OUTPUT_TAIL_LEN) : s;
24
+ }
25
+
26
+ /**
27
+ * Kill the whole process tree on timeout. On Windows the shell must still be
28
+ * alive for `taskkill /T` to trace its children (once the shell dies they are
29
+ * orphaned), so the tree is killed here instead of relying on exec's own
30
+ * timeout. POSIX: only the shell itself.
31
+ */
32
+ function defaultKillTree(child) {
33
+ if (!child || !child.pid) return;
34
+ if (process.platform === 'win32') {
35
+ childProcess.spawnSync('taskkill', ['/T', '/F', '/PID', String(child.pid)], { windowsHide: true });
36
+ return;
37
+ }
38
+ try { child.kill('SIGKILL'); } catch (e) { /* already gone */ }
39
+ }
40
+
41
+ /**
42
+ * Run one command (cwd = project root, default shell).
43
+ * done({ exitCode, passed, reason, outputTail })
44
+ * reason: null | 'exit=N' | 'timeout' | '命令不可执行: <msg>'
45
+ */
46
+ function runCommand(deps, command, cwd, timeoutMs, done) {
47
+ var timedOut = false;
48
+ var timer = null;
49
+ function finish(exitCode, reason, stdout, stderr) {
50
+ done({
51
+ exitCode: exitCode,
52
+ passed: reason === null,
53
+ reason: reason,
54
+ outputTail: reason === null ? undefined : tailOf(stdout, stderr),
55
+ });
56
+ }
57
+ var child;
58
+ try {
59
+ child = deps.exec(command, { cwd: cwd, maxBuffer: MAX_BUFFER, windowsHide: true }, function (err, stdout, stderr) {
60
+ clearTimeout(timer);
61
+ if (timedOut) { finish(null, 'timeout', stdout, stderr); return; }
62
+ // spawn 失败(shell 起不来 / ENOENT / EACCES):err.code 是字符串而非退出码
63
+ if (err && typeof err.code === 'string') {
64
+ finish(null, '命令不可执行: ' + (err.message || err), stdout, stderr);
65
+ return;
66
+ }
67
+ var code = err ? (typeof err.code === 'number' ? err.code : 1) : 0;
68
+ finish(code, code === 0 ? null : 'exit=' + code, stdout, stderr);
69
+ });
70
+ } catch (e) {
71
+ finish(null, '命令不可执行: ' + (e && e.message ? e.message : e), '', '');
72
+ return;
73
+ }
74
+ timer = setTimeout(function () {
75
+ timedOut = true;
76
+ deps.killTree(child);
77
+ }, timeoutMs);
78
+ }
79
+
80
+ /**
81
+ * Serially run every verify item of one work unit. done(checkResult).
82
+ */
83
+ function verifyWorkPackage(wp, deps, done) {
84
+ var checklist = wp.checklist || [];
85
+ var verifyItems = [];
86
+ var manualItems = [];
87
+ for (var i = 0; i < checklist.length; i++) {
88
+ var it = checklist[i];
89
+ if (it.verify && it.verify.command) verifyItems.push(it);
90
+ else manualItems.push({ id: it.id, item: it.item });
91
+ }
92
+ var results = [];
93
+ var failedItems = [];
94
+ (function next() {
95
+ if (results.length >= verifyItems.length) {
96
+ var passCount = results.filter(function (r) { return r.passed; }).length;
97
+ var failCount = results.length - passCount;
98
+ done({
99
+ wpId: wp.wpId,
100
+ passed: failCount === 0 && verifyItems.length > 0,
101
+ summary: { total: checklist.length, passed: passCount, failed: failCount, manual: manualItems.length },
102
+ verifyResults: results,
103
+ failedItems: failedItems,
104
+ manualItems: manualItems,
105
+ });
106
+ return;
107
+ }
108
+ var item = verifyItems[results.length];
109
+ runCommand(deps, item.verify.command, deps.cwd, deps.timeoutMs, function (r) {
110
+ var entry = { id: item.id, item: item.item, command: item.verify.command, exitCode: r.exitCode, passed: r.passed };
111
+ if (!r.passed) {
112
+ entry.outputTail = r.outputTail;
113
+ failedItems.push({ category: item.category, id: item.id, item: item.item, reason: r.reason });
114
+ }
115
+ results.push(entry);
116
+ if (deps.onResult) deps.onResult(entry, r.reason);
117
+ next();
118
+ });
119
+ })();
120
+ }
121
+
122
+ /**
123
+ * 0 = every verify item passed; 1 = any failure; 2 = no verify item in scope.
124
+ */
125
+ function exitCodeOf(result) {
126
+ if (result.verifyResults.length === 0) return 2;
127
+ return result.failedItems.length > 0 ? 1 : 0;
128
+ }
129
+
130
+ function printEntry(ctx, entry, reason) {
131
+ var mark = entry.passed ? ctx.colorize('PASS', 'green') : ctx.colorize('FAIL', 'red');
132
+ console.log(' ' + mark + ' ' + entry.id + ' exit=' + (entry.exitCode === null ? '-' : entry.exitCode) +
133
+ ' ' + entry.item + (entry.passed ? '' : ctx.colorize(' ← ' + reason, 'red')));
134
+ if (entry.outputTail) {
135
+ console.log(ctx.colorize(entry.outputTail.split('\n').map(function (l) { return ' ' + l; }).join('\n'), 'dim'));
136
+ }
137
+ }
138
+
139
+ function printSummary(ctx, r) {
140
+ var s = r.summary;
141
+ var head = '结论:' + r.wpId + ' verify ' + s.passed + '/' + (s.passed + s.failed);
142
+ if (r.verifyResults.length === 0) {
143
+ console.log(ctx.colorize(head + ' 无 verify 项,' + s.manual + ' 项全 manual,需 LLM 判(exit 2)', 'yellow'));
144
+ } else if (r.failedItems.length > 0) {
145
+ console.log(ctx.colorize(head + ' 失败 ' + s.failed + ' 项(exit 1)', 'red'));
146
+ } else {
147
+ console.log(ctx.colorize(head + ' 全过(exit 0)', 'green') +
148
+ (s.manual > 0 ? ctx.colorize(' manual ' + s.manual + ' 项待 Lead 判定', 'dim') : ''));
149
+ }
150
+ for (var i = 0; i < r.manualItems.length; i++) {
151
+ console.log(ctx.colorize(' MANUAL ' + r.manualItems[i].id + ' ' + r.manualItems[i].item, 'dim'));
152
+ }
153
+ }
154
+
155
+ function parseArgs(argv) {
156
+ var o = { planPath: null, wp: null, timeoutSec: DEFAULT_TIMEOUT_SEC, json: false, usageError: null };
157
+ for (var i = 0; i < argv.length && !o.usageError; i++) {
158
+ var a = argv[i];
159
+ if (a === '--json') o.json = true;
160
+ else if (a === '--wp' || a === '--timeout') {
161
+ var v = argv[i + 1];
162
+ if (v === undefined || v.indexOf('--') === 0) o.usageError = a + ' 缺少参数';
163
+ else if (a === '--wp') o.wp = v;
164
+ else o.timeoutSec = parseFloat(v);
165
+ i += 1;
166
+ } else if (a.indexOf('--wp=') === 0) o.wp = a.slice(5);
167
+ else if (a.indexOf('--timeout=') === 0) o.timeoutSec = parseFloat(a.slice(10));
168
+ else if (a.indexOf('--') === 0) o.usageError = '未知参数 ' + a;
169
+ else if (o.planPath === null) o.planPath = a;
170
+ else o.usageError = '多余参数 ' + a;
171
+ }
172
+ if (!o.usageError && !o.planPath) o.usageError = '缺少 plan 路径';
173
+ if (!o.usageError && !o.wp) o.usageError = '缺少 --wp WP-NNN|all';
174
+ if (!o.usageError && !(o.timeoutSec > 0)) o.usageError = '--timeout 需为正数秒';
175
+ if (o.timeoutSec > MAX_TIMEOUT_SEC) o.timeoutSec = MAX_TIMEOUT_SEC;
176
+ return o;
177
+ }
178
+
179
+ /**
180
+ * Command factory. deps.exec / deps.killTree are injectable (tests use fakes);
181
+ * defaults are child_process.exec and the taskkill tree-kill above.
182
+ */
183
+ function createVerifyCommand(deps) {
184
+ deps = deps || {};
185
+ return {
186
+ name: 'verify',
187
+ description: 'Run a plan work unit\'s [verify:] commands and emit CheckResult',
188
+ /**
189
+ * usage: doukui verify <plan路径> --wp WP-NNN|all [--timeout 秒] [--json]
190
+ * exit 0 = all verify items passed; 1 = any failure (usage/parse errors too);
191
+ * 2 = no verify item in scope (all manual, needs LLM judgment)
192
+ * @public
193
+ * @param {object} ctx - CLI context object
194
+ * @returns {Promise<void>}
195
+ */
196
+ execute: function (ctx) {
197
+ var opts = parseArgs(ctx.argv || []);
198
+ var fail = function (msg) {
199
+ console.error(ctx.colorize('Error: ' + msg, 'red'));
200
+ ctx.exit(1);
201
+ };
202
+ if (opts.usageError) return fail(opts.usageError + '\nUsage: ' + USAGE);
203
+
204
+ var projectRoot = ctx.targetRoot;
205
+ var parsed = planReader.parsePlanToGoal({
206
+ planFilePath: opts.planPath,
207
+ projectRoot: projectRoot,
208
+ throwOnCycle: false,
209
+ });
210
+ if (parsed.error) return fail(parsed.error);
211
+
212
+ var all = opts.wp.toLowerCase() === 'all';
213
+ var targets = parsed.workPackages;
214
+ if (!all) {
215
+ var wanted = opts.wp.toUpperCase();
216
+ targets = targets.filter(function (wp) { return wp.wpId.toUpperCase() === wanted; });
217
+ if (targets.length === 0) {
218
+ return fail('wp-not-found: ' + opts.wp + '(可用: ' + parsed.goal.wpIds.join(', ') + ')');
219
+ }
220
+ }
221
+
222
+ var runDeps = {
223
+ cwd: projectRoot,
224
+ timeoutMs: Math.round(opts.timeoutSec * 1000),
225
+ exec: deps.exec || childProcess.exec,
226
+ killTree: deps.killTree || defaultKillTree,
227
+ onResult: opts.json ? null : function (entry, reason) { printEntry(ctx, entry, reason); },
228
+ };
229
+ if (!opts.json) console.log(ctx.colorize('plan: ', 'dim') + parsed.planFilePath);
230
+
231
+ var results = [];
232
+ return new Promise(function (resolve) {
233
+ (function next() {
234
+ if (results.length >= targets.length) {
235
+ var codes = results.map(exitCodeOf);
236
+ var code = codes.indexOf(1) !== -1 ? 1 : (codes.indexOf(0) !== -1 ? 0 : 2);
237
+ if (opts.json) {
238
+ console.log(JSON.stringify(all ? results : results[0], null, 2));
239
+ } else {
240
+ for (var i = 0; i < results.length; i++) {
241
+ printSummary(ctx, results[i]);
242
+ console.log('```json:machine-readable\n' + JSON.stringify(results[i]) + '\n```');
243
+ }
244
+ }
245
+ ctx.exit(code);
246
+ resolve();
247
+ return;
248
+ }
249
+ var wp = targets[results.length];
250
+ if (!opts.json) {
251
+ var verifyCount = wp.checklist.filter(function (it) { return it.verify; }).length;
252
+ console.log(ctx.colorize(wp.wpId, 'green') + ' ' + wp.title +
253
+ ctx.colorize(' verify ' + verifyCount + '/' + wp.checklist.length + ' timeout ' + opts.timeoutSec + 's', 'dim'));
254
+ }
255
+ verifyWorkPackage(wp, runDeps, function (r) { results.push(r); next(); });
256
+ })();
257
+ });
258
+ },
259
+ };
260
+ }
261
+
262
+ module.exports = createVerifyCommand();
263
+ module.exports.createVerifyCommand = createVerifyCommand;
package/bin/doukui.js CHANGED
@@ -109,6 +109,8 @@ var commandModules = {
109
109
  'build': 'build.js',
110
110
  'validate': 'validate.js',
111
111
  'validate-config': 'validate-config.js',
112
+ 'plan-lint': 'plan-lint.js',
113
+ 'verify': 'verify.js',
112
114
  'init': 'init.js',
113
115
  'migrate': 'migrate.js',
114
116
  'status': 'status.js',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doukui",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Doukui (斗魁) - in-session orchestration discipline pack for Claude Code: skills suite, plan-reader contract, multi-agent dispatch, agentic loop",
5
5
  "bin": {
6
6
  "doukui": "bin/doukui.js"
@@ -257,7 +257,7 @@ function shouldSkipForDoubleTrigger(projectRoot) {
257
257
  }
258
258
  })();
259
259
 
260
- // Export a no-op class for PluginLoader compatibility
260
+ // Export a no-op class for hook host compatibility
261
261
  class SessionStartHook {
262
262
  constructor() {
263
263
  this.name = 'hook-session-start';