cc-devflow 4.1.6 → 4.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 (128) hide show
  1. package/.claude/commands/core/architecture.md +30 -0
  2. package/.claude/commands/core/guidelines.md +25 -0
  3. package/.claude/commands/core/roadmap.md +29 -0
  4. package/.claude/commands/core/style.md +18 -0
  5. package/.claude/commands/flow/CLAUDE.md +0 -4
  6. package/.claude/docs/examples/design-inspiration-pool.md +59 -0
  7. package/.claude/docs/examples/ui-prototype-constitution-checklist.md +75 -0
  8. package/.claude/docs/implementation-summary-v7.md +449 -0
  9. package/.claude/docs/spec-format-guide.md +349 -0
  10. package/.claude/docs/state-consolidation-design.md +323 -0
  11. package/.claude/docs/templates/ARCHITECTURE_TEMPLATE.md +85 -386
  12. package/.claude/docs/templates/DESIGN_TEMPLATE.md +157 -0
  13. package/.claude/docs/templates/PROPOSAL_TEMPLATE.md +91 -0
  14. package/.claude/docs/templates/SPEC_TEMPLATE_DELTA.md +139 -0
  15. package/.claude/docs/templates/SPEC_TEMPLATE_PROJECT.md +93 -0
  16. package/.claude/docs/templates/STYLE_TEMPLATE.md +114 -901
  17. package/.claude/docs/templates/UI_PROTOTYPE_TEMPLATE.md +143 -1205
  18. package/.claude/hooks/inject-agent-context.ts +9 -9
  19. package/.claude/scripts/.claude/commands/flow/export-openspec.md +221 -0
  20. package/.claude/scripts/.claude/commands/flow/import-openspec.md +171 -0
  21. package/.claude/scripts/__tests__/openspec.test.js +212 -0
  22. package/.claude/scripts/delta-parser.ts +112 -2
  23. package/.claude/scripts/export-openspec.js +222 -0
  24. package/.claude/scripts/import-openspec.js +272 -0
  25. package/.claude/scripts/validate-scope.sh +200 -0
  26. package/.claude/skills/cc-devflow-orchestrator/SKILL.md +25 -0
  27. package/.claude/skills/flow-dev/SKILL.md +94 -0
  28. package/.claude/skills/flow-init/SKILL.md +105 -0
  29. package/.claude/skills/{workflow/flow-release → flow-release}/SKILL.md +14 -3
  30. package/.claude/skills/flow-spec/SKILL.md +102 -0
  31. package/.claude/skills/utility/npm-release/CLAUDE.md +55 -0
  32. package/.claude/skills/utility/npm-release/SKILL.md +111 -46
  33. package/.claude/skills/utility/npm-release/references/version-decision-guide.md +134 -0
  34. package/.claude/skills/utility/npm-release/scripts/atomic-version-bump.sh +95 -0
  35. package/.claude/skills/utility/npm-release/scripts/validate-version-sync.sh +82 -0
  36. package/.claude/skills/utility/npm-release/scripts/version-decision-tree.sh +44 -0
  37. package/.claude/tsc-cache/70d2fc6d-2936-429b-b529-429f1aae8c88/affected-repos.txt +1 -0
  38. package/.claude/tsc-cache/70d2fc6d-2936-429b-b529-429f1aae8c88/edited-files.log +2 -0
  39. package/CHANGELOG.md +81 -0
  40. package/README.md +7 -1
  41. package/README.zh-CN.md +7 -1
  42. package/bin/cc-devflow-cli.js +154 -0
  43. package/docs/v4.3.0-migration-guide.md +276 -0
  44. package/lib/harness/CLAUDE.md +5 -4
  45. package/lib/harness/__tests__/planner.tdd.test.js +125 -0
  46. package/lib/harness/index.js +4 -2
  47. package/lib/harness/operations/dispatch.js +13 -0
  48. package/lib/harness/operations/plan.js +55 -1
  49. package/lib/harness/operations/release.js +87 -0
  50. package/lib/harness/operations/verify.js +14 -0
  51. package/lib/harness/planner.js +131 -0
  52. package/lib/harness/query.js +126 -0
  53. package/lib/harness/schemas.js +22 -1
  54. package/package.json +1 -1
  55. package/.claude/commands/flow/checklist.md +0 -18
  56. package/.claude/commands/flow/clarify.md +0 -18
  57. package/.claude/commands/flow/new.md +0 -23
  58. package/.claude/commands/flow/quality.md +0 -21
  59. package/.claude/docs/templates/EPIC_TEMPLATE.md +0 -805
  60. package/.claude/docs/templates/PRD_TEMPLATE.md +0 -562
  61. package/.claude/docs/templates/TASKS_TEMPLATE.md +0 -523
  62. package/.claude/docs/templates/TECH_DESIGN_TEMPLATE.md +0 -1019
  63. package/.claude/skills/workflow/CLAUDE.md +0 -24
  64. package/.claude/skills/workflow/flow-dev/SKILL.md +0 -58
  65. package/.claude/skills/workflow/flow-init/SKILL.md +0 -55
  66. package/.claude/skills/workflow/flow-spec/SKILL.md +0 -42
  67. /package/.claude/skills/{domain/attention-refresh → attention-refresh}/SKILL.md +0 -0
  68. /package/.claude/skills/{domain/brainstorming → brainstorming}/SKILL.md +0 -0
  69. /package/.claude/skills/{guardrail/constitution-guardian → constitution-guardian}/SKILL.md +0 -0
  70. /package/.claude/skills/{utility/constitution-quick-ref → constitution-quick-ref}/SKILL.md +0 -0
  71. /package/.claude/skills/{domain/debugging → debugging}/SKILL.md +0 -0
  72. /package/.claude/skills/{utility/file-standards → file-standards}/SKILL.md +0 -0
  73. /package/.claude/skills/{domain/finishing-branch → finishing-branch}/SKILL.md +0 -0
  74. /package/.claude/skills/{workflow/flow-dev → flow-dev}/CLAUDE.md +0 -0
  75. /package/.claude/skills/{workflow/flow-dev → flow-dev}/assets/IMPLEMENTATION_PLAN_TEMPLATE.md +0 -0
  76. /package/.claude/skills/{workflow/flow-dev → flow-dev}/context.jsonl +0 -0
  77. /package/.claude/skills/{workflow/flow-dev → flow-dev}/dev-implementer.jsonl +0 -0
  78. /package/.claude/skills/{workflow/flow-dev → flow-dev}/scripts/entry-gate.sh +0 -0
  79. /package/.claude/skills/{workflow/flow-dev → flow-dev}/scripts/exit-gate.sh +0 -0
  80. /package/.claude/skills/{workflow/flow-dev → flow-dev}/scripts/task-orchestrator.sh +0 -0
  81. /package/.claude/skills/{workflow/flow-fix → flow-fix}/SKILL.md +0 -0
  82. /package/.claude/skills/{workflow/flow-fix → flow-fix}/context.jsonl +0 -0
  83. /package/.claude/skills/{workflow/flow-fix → flow-fix}/references/bug-analyzer.md +0 -0
  84. /package/.claude/skills/{workflow/flow-init → flow-init}/assets/BRAINSTORM_TEMPLATE.md +0 -0
  85. /package/.claude/skills/{workflow/flow-init → flow-init}/assets/INIT_FLOW_TEMPLATE.md +0 -0
  86. /package/.claude/skills/{workflow/flow-init → flow-init}/assets/RESEARCH_TEMPLATE.md +0 -0
  87. /package/.claude/skills/{workflow/flow-init → flow-init}/context.jsonl +0 -0
  88. /package/.claude/skills/{workflow/flow-init → flow-init}/references/flow-researcher.md +0 -0
  89. /package/.claude/skills/{workflow/flow-init → flow-init}/scripts/check-prerequisites.sh +0 -0
  90. /package/.claude/skills/{workflow/flow-init → flow-init}/scripts/consolidate-research.sh +0 -0
  91. /package/.claude/skills/{workflow/flow-init → flow-init}/scripts/create-requirement.sh +0 -0
  92. /package/.claude/skills/{workflow/flow-init → flow-init}/scripts/generate-research-tasks.sh +0 -0
  93. /package/.claude/skills/{workflow/flow-init → flow-init}/scripts/populate-research-tasks.sh +0 -0
  94. /package/.claude/skills/{workflow/flow-init → flow-init}/scripts/validate-research.sh +0 -0
  95. /package/.claude/skills/{workflow/flow-quality → flow-quality}/SKILL.md +0 -0
  96. /package/.claude/skills/{workflow/flow-quality → flow-quality}/context.jsonl +0 -0
  97. /package/.claude/skills/{workflow/flow-quality → flow-quality}/references/code-quality-reviewer.md +0 -0
  98. /package/.claude/skills/{workflow/flow-quality → flow-quality}/references/qa-tester.md +0 -0
  99. /package/.claude/skills/{workflow/flow-quality → flow-quality}/references/security-reviewer.md +0 -0
  100. /package/.claude/skills/{workflow/flow-quality → flow-quality}/references/spec-reviewer.md +0 -0
  101. /package/.claude/skills/{workflow/flow-release → flow-release}/context.jsonl +0 -0
  102. /package/.claude/skills/{workflow/flow-release → flow-release}/references/release-manager.md +0 -0
  103. /package/.claude/skills/{workflow/flow-spec → flow-spec}/CLAUDE.md +0 -0
  104. /package/.claude/skills/{workflow/flow-spec → flow-spec}/context.jsonl +0 -0
  105. /package/.claude/skills/{workflow/flow-spec → flow-spec}/scripts/entry-gate.sh +0 -0
  106. /package/.claude/skills/{workflow/flow-spec → flow-spec}/scripts/exit-gate.sh +0 -0
  107. /package/.claude/skills/{workflow/flow-spec → flow-spec}/scripts/parallel-orchestrator.sh +0 -0
  108. /package/.claude/skills/{workflow/flow-spec → flow-spec}/scripts/team-communication.sh +0 -0
  109. /package/.claude/skills/{workflow/flow-spec → flow-spec}/scripts/team-init.sh +0 -0
  110. /package/.claude/skills/{workflow/flow-spec → flow-spec}/scripts/test-team-mode.sh +0 -0
  111. /package/.claude/skills/{workflow/flow-spec → flow-spec}/team-config.json +0 -0
  112. /package/.claude/skills/{workflow/flow-verify → flow-verify}/CLAUDE.md +0 -0
  113. /package/.claude/skills/{workflow/flow-verify → flow-verify}/SKILL.md +0 -0
  114. /package/.claude/skills/{workflow/flow-verify → flow-verify}/context.jsonl +0 -0
  115. /package/.claude/skills/{utility/fractal-docs → fractal-docs}/SKILL.md +0 -0
  116. /package/.claude/skills/{utility/journey-checker → journey-checker}/SKILL.md +0 -0
  117. /package/.claude/skills/{utility/journey-checker → journey-checker}/pressure-scenarios.md +0 -0
  118. /package/.claude/skills/{domain/receiving-review → receiving-review}/SKILL.md +0 -0
  119. /package/.claude/skills/{utility/skill-creator → skill-creator}/LICENSE.txt +0 -0
  120. /package/.claude/skills/{utility/skill-creator → skill-creator}/SKILL.md +0 -0
  121. /package/.claude/skills/{utility/skill-creator → skill-creator}/references/output-patterns.md +0 -0
  122. /package/.claude/skills/{utility/skill-creator → skill-creator}/references/workflows.md +0 -0
  123. /package/.claude/skills/{utility/skill-creator → skill-creator}/scripts/init_skill.py +0 -0
  124. /package/.claude/skills/{utility/skill-creator → skill-creator}/scripts/package_skill.py +0 -0
  125. /package/.claude/skills/{utility/skill-creator → skill-creator}/scripts/quick_validate.py +0 -0
  126. /package/.claude/skills/{domain/tdd → tdd}/SKILL.md +0 -0
  127. /package/.claude/skills/{guardrail/tdd-enforcer → tdd-enforcer}/SKILL.md +0 -0
  128. /package/.claude/skills/{domain/verification → verification}/SKILL.md +0 -0
package/CHANGELOG.md CHANGED
@@ -7,6 +7,81 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ---
9
9
 
10
+ ## [4.3.0] - 2026-03-13
11
+
12
+ ### ✨ TDD Enforcement + OpenSpec Interop
13
+
14
+ v4.3.0 adds automatic TDD order validation and bidirectional OpenSpec conversion to solve requirement drift problems.
15
+
16
+ #### Added
17
+
18
+ - **TDD Order Validation**
19
+ - Added `validateTDDOrder()` in `lib/harness/planner.js` to enforce Constitution Article VI
20
+ - Validates that [IMPL] tasks depend on corresponding [TEST] tasks
21
+ - Validates that [TEST] tasks don't depend on [IMPL] tasks
22
+ - Intelligent feature name matching with fuzzy algorithm (removes suffixes like "测试", "实现", "功能")
23
+ - Extended `TaskSchema` in `lib/harness/schemas.js` with `type` field (TEST/IMPL/OTHER)
24
+ - Comprehensive test coverage in `lib/harness/__tests__/planner.tdd.test.js` (10 tests, all passing)
25
+
26
+ - **OpenSpec Interoperability**
27
+ - Added `.claude/scripts/import-openspec.js` for OpenSpec → CC-DevFlow conversion
28
+ - Parses OpenSpec format (Purpose + Requirements + BDD scenarios)
29
+ - Auto-generates TDD tasks (TEST + IMPL pairs with correct dependencies)
30
+ - Adds Design section with [NEEDS CLARIFICATION] markers
31
+ - Generates Verification checklist
32
+ - Added `.claude/scripts/export-openspec.js` for CC-DevFlow → OpenSpec conversion
33
+ - Strips YAML frontmatter and metadata
34
+ - Removes Design, Tasks, Verification sections
35
+ - Removes [NEEDS CLARIFICATION] markers
36
+ - Outputs pure Requirements in OpenSpec format
37
+ - Added `.claude/commands/flow/import-openspec.md` command documentation
38
+ - Added `.claude/commands/flow/export-openspec.md` command documentation
39
+ - Comprehensive test coverage in `.claude/scripts/__tests__/openspec.test.js` (5 tests, all passing)
40
+ - Round-trip conversion preserves requirements integrity
41
+
42
+ #### Benefits
43
+
44
+ - ✅ Automatic enforcement of TDD order (Constitution Article VI)
45
+ - ✅ Prevents implementation before tests at parse time
46
+ - ✅ Bidirectional OpenSpec compatibility
47
+ - ✅ Automatic TDD task generation during import
48
+ - ✅ Clean requirement export without implementation details
49
+
50
+ ## [4.2.0] - 2026-02-19
51
+
52
+ ### 🧠 Long-Running Harness Protocol Alignment
53
+
54
+ v4.2.0 unifies long-running execution protocol across project-level `/core:*` commands and requirement-level `/flow:*` skills, reducing context-loss regressions and premature completion.
55
+
56
+ #### Added
57
+
58
+ - **Project-level harness protocol**
59
+ - Added `Initializer / Worker / Done Gate` guidance to:
60
+ - `.claude/commands/core/roadmap.md`
61
+ - `.claude/commands/core/architecture.md`
62
+ - `.claude/commands/core/guidelines.md`
63
+ - `.claude/commands/core/style.md`
64
+ - Standardized resumable artifacts under `devflow/.core-harness/*` (`checklist`, `progress`, `handoff`)
65
+
66
+ - **Requirement-level protocol parity**
67
+ - Added the same long-running protocol to:
68
+ - `.claude/skills/workflow/flow-init/SKILL.md`
69
+ - `.claude/skills/workflow/flow-spec/SKILL.md`
70
+ - `.claude/skills/workflow/flow-dev/SKILL.md`
71
+ - Standardized requirement session artifacts:
72
+ - `session-checklist.json`
73
+ - `session-progress.md`
74
+ - `session-handoff.md`
75
+
76
+ - **Routing-level enforcement**
77
+ - Extended `.claude/skills/cc-devflow-orchestrator/SKILL.md` with project-level harness routing defaults and artifact-backed completion rules
78
+
79
+ #### Benefits
80
+
81
+ - ✅ Consistent long-running behavior between `/core:*` and `/flow:*`
82
+ - ✅ Clear resumability across context windows
83
+ - ✅ Stronger done criteria via artifact-backed gates (instead of subjective completion)
84
+
10
85
  ## [4.1.6] - 2026-02-18
11
86
 
12
87
  ### 🔧 Multi-Platform Adapt Pipeline Stabilization
@@ -19,6 +94,12 @@ v4.1.6 fixes multi-platform `adapt` compilation drift and parsing failures, with
19
94
  - `.claude/commands/**/CLAUDE.md` is now excluded from command parsing
20
95
  - Prevents false `Missing YAML frontmatter` failures during `npm run adapt`
21
96
 
97
+ - **Harness runtime chain bootstrap**
98
+ - `cc-devflow init` and `cc-devflow adapt` now auto-add missing `harness:*` npm scripts into target `package.json`
99
+ - Added `cc-devflow harness <subcommand>` passthrough so injected scripts have a stable runtime entry
100
+ - Injected scripts are now machine-portable (`cc-devflow harness ...`) with no absolute-path coupling
101
+ - Auto-repairs legacy `node bin/harness.js <cmd>`, old `npx` wrappers, and prior absolute-path script values
102
+
22
103
  - **Manifest consistency across platforms**
23
104
  - Separated source hash (`sourceHash`) and emitted target hash (`hash`)
24
105
  - Drift detection now compares emitted artifact hashes correctly
package/README.md CHANGED
@@ -27,8 +27,9 @@ Harness-first five-stage workflow from requirement setup to release: `/flow:init
27
27
  - 🔗 **GitHub Integration** - Automated PR creation, branch management, and conventional commits
28
28
  - 📊 **Progress Tracking** - Real-time status monitoring and intelligent restart points
29
29
  - 🔍 **Consistency Verification** - Enterprise-grade consistency checking with intelligent conflict detection
30
- - 🧪 **TDD Enforced** - Strict Test-Driven Development with TEST VERIFICATION CHECKPOINT
30
+ - 🧪 **TDD Enforced** - Strict Test-Driven Development with automatic TDD order validation in harness planner
31
31
  - 📜 **Constitution** - 10 Articles governing quality, security, and architecture
32
+ - 🔄 **OpenSpec Interop** - Bidirectional conversion between OpenSpec and CC-DevFlow formats with automatic TDD task generation
32
33
  - 🔄 **Autonomous Development** - Ralph × Manus Integration for memory-enhanced continuous iteration
33
34
  - 🔌 **Multi-Platform Support** - Compile workflows for Codex, Cursor, Qwen, Antigravity via `npm run adapt`
34
35
  - 🔄 **Multi-Module Compiler** - Full module compilation: skills, commands, agents, rules, hooks
@@ -184,8 +185,13 @@ cc-devflow init --dir /path/to/project
184
185
  # Compile for specific platform
185
186
  cc-devflow adapt --platform codex
186
187
  cc-devflow adapt --cwd /path/to/project --platform cursor
188
+
189
+ # Run harness runtime directly (for npm script delegation)
190
+ cc-devflow harness release --change-id REQ-123
187
191
  ```
188
192
 
193
+ `cc-devflow init` and `cc-devflow adapt` now auto-bootstrap missing `harness:*` npm scripts in `package.json` using portable `cc-devflow harness <subcommand>` entries (no machine-specific absolute paths), so `/flow:*` can execute the runtime chain without manual script patching.
194
+
189
195
  ### Optional Dependencies
190
196
 
191
197
  ```bash
package/README.zh-CN.md CHANGED
@@ -27,8 +27,9 @@
27
27
  - 🔗 **GitHub 集成** - 自动化 PR 创建、分支管理和规范化提交
28
28
  - 📊 **进度跟踪** - 实时状态监控和智能重启点
29
29
  - 🔍 **一致性验证** - 企业级一致性检查,智能冲突检测
30
- - 🧪 **TDD 强制执行** - 严格的测试驱动开发,TEST VERIFICATION CHECKPOINT
30
+ - 🧪 **TDD 强制执行** - 严格的测试驱动开发,harness planner 自动 TDD 顺序验证
31
31
  - 📜 **Constitution** - 10条宪法条款管控质量、安全和架构
32
+ - 🔄 **OpenSpec 互操作** - OpenSpec 与 CC-DevFlow 格式双向转换,自动生成 TDD 任务
32
33
  - 🔄 **自主开发** - Ralph × Manus 集成实现有记忆的持续迭代
33
34
  - 🔌 **多平台支持** - 通过 `npm run adapt` 编译工作流到 Codex、Cursor、Qwen、Antigravity
34
35
  - 🔄 **多模块编译器** - 完整模块编译:skills、commands、agents、rules、hooks
@@ -184,8 +185,13 @@ cc-devflow init --dir /path/to/project
184
185
  # 编译到特定平台
185
186
  cc-devflow adapt --platform codex
186
187
  cc-devflow adapt --cwd /path/to/project --platform cursor
188
+
189
+ # 直接运行 harness runtime(供 npm scripts 委派)
190
+ cc-devflow harness release --change-id REQ-123
187
191
  ```
188
192
 
193
+ `cc-devflow init` 与 `cc-devflow adapt` 现在会自动补齐 `package.json` 中缺失的 `harness:*` scripts,且统一写入可移植的 `cc-devflow harness <subcommand>`(不使用机器绝对路径),避免 `/flow:*` 因脚本缺失退化到手工 fallback。
194
+
189
195
  ### 验证安装
190
196
 
191
197
  ```bash
@@ -1,4 +1,10 @@
1
1
  #!/usr/bin/env node
2
+ /**
3
+ * [INPUT]: 依赖 .claude 模板、adapt 编译入口与 harness 运行时入口。
4
+ * [OUTPUT]: 提供 init/adapt/harness 命令,并在目标仓库自动补齐 harness npm scripts。
5
+ * [POS]: cc-devflow 的统一 CLI 门面,串联安装、编译与运行时发布链路。
6
+ * [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
7
+ */
2
8
  const fs = require('fs');
3
9
  const path = require('path');
4
10
  const { spawnSync } = require('child_process');
@@ -7,6 +13,17 @@ const PACKAGE_ROOT = path.resolve(__dirname, '..');
7
13
  const TEMPLATE_DIR = path.join(PACKAGE_ROOT, '.claude');
8
14
  const ADAPT_BIN = path.join(PACKAGE_ROOT, 'bin', 'adapt.js');
9
15
  const ADAPTER_BIN = path.join(PACKAGE_ROOT, 'bin', 'cc-devflow.js');
16
+ const HARNESS_BIN = path.join(PACKAGE_ROOT, 'bin', 'harness.js');
17
+ const HARNESS_SCRIPT_COMMANDS = {
18
+ 'harness:init': 'init',
19
+ 'harness:pack': 'pack',
20
+ 'harness:plan': 'plan',
21
+ 'harness:dispatch': 'dispatch',
22
+ 'harness:verify': 'verify',
23
+ 'harness:release': 'release',
24
+ 'harness:resume': 'resume',
25
+ 'harness:janitor': 'janitor'
26
+ };
10
27
 
11
28
  function showHelp() {
12
29
  console.log(`
@@ -15,6 +32,7 @@ Usage: cc-devflow <command> [options]
15
32
  Commands:
16
33
  init Install .claude template into a project
17
34
  adapt Compile .claude into multi-platform outputs
35
+ harness Run harness runtime commands (init/verify/release/janitor...)
18
36
 
19
37
  Init options:
20
38
  --dir <path> Target project path (default: cwd)
@@ -34,6 +52,7 @@ Examples:
34
52
  cc-devflow init --dir /path/to/project
35
53
  cc-devflow adapt --platform cursor
36
54
  cc-devflow adapt --cwd /path/to/project --platform codex
55
+ cc-devflow harness release --change-id REQ-123
37
56
  `);
38
57
  }
39
58
 
@@ -122,6 +141,114 @@ function copyIncremental(src, dest) {
122
141
  }
123
142
  }
124
143
 
144
+ function detectJsonIndent(content) {
145
+ const match = content.match(/\n([ \t]+)"[^"\n]+":/);
146
+ if (!match) {
147
+ return 2;
148
+ }
149
+
150
+ const indent = match[1];
151
+ return indent.includes('\t') ? '\t' : indent.length;
152
+ }
153
+
154
+ function hasLocalHarnessBinary(targetRoot) {
155
+ return fs.existsSync(path.join(targetRoot, 'bin', 'harness.js'));
156
+ }
157
+
158
+ function getHarnessScriptCommand(targetRoot, subcommand) {
159
+ if (hasLocalHarnessBinary(targetRoot)) {
160
+ return `node bin/harness.js ${subcommand}`;
161
+ }
162
+ return `cc-devflow harness ${subcommand}`;
163
+ }
164
+
165
+ function ensureHarnessScripts(targetRoot) {
166
+ const pkgPath = path.join(targetRoot, 'package.json');
167
+ if (!fs.existsSync(pkgPath)) {
168
+ console.warn(`[WARN] Missing package.json in ${targetRoot}; skipping harness script bootstrap.`);
169
+ return;
170
+ }
171
+
172
+ let raw;
173
+ let packageJson;
174
+ try {
175
+ raw = fs.readFileSync(pkgPath, 'utf8');
176
+ packageJson = JSON.parse(raw);
177
+ } catch (error) {
178
+ console.warn(`[WARN] Skipping harness script bootstrap: cannot parse package.json (${error.message})`);
179
+ return;
180
+ }
181
+
182
+ if (!packageJson || typeof packageJson !== 'object' || Array.isArray(packageJson)) {
183
+ console.warn('[WARN] Skipping harness script bootstrap: package.json root must be an object.');
184
+ return;
185
+ }
186
+
187
+ if (!packageJson.scripts || typeof packageJson.scripts !== 'object' || Array.isArray(packageJson.scripts)) {
188
+ packageJson.scripts = {};
189
+ }
190
+
191
+ const hasLocalBinary = hasLocalHarnessBinary(targetRoot);
192
+ const added = [];
193
+ const repaired = [];
194
+ let changed = false;
195
+
196
+ for (const [scriptName, subcommand] of Object.entries(HARNESS_SCRIPT_COMMANDS)) {
197
+ const desired = getHarnessScriptCommand(targetRoot, subcommand);
198
+ const existing = packageJson.scripts[scriptName];
199
+
200
+ if (typeof existing === 'undefined') {
201
+ packageJson.scripts[scriptName] = desired;
202
+ added.push(scriptName);
203
+ changed = true;
204
+ continue;
205
+ }
206
+
207
+ if (typeof existing !== 'string') {
208
+ continue;
209
+ }
210
+
211
+ // Auto-repair legacy value when local harness binary does not exist.
212
+ if (!hasLocalBinary && existing.trim() === `node bin/harness.js ${subcommand}`) {
213
+ packageJson.scripts[scriptName] = desired;
214
+ repaired.push(scriptName);
215
+ changed = true;
216
+ continue;
217
+ }
218
+
219
+ // Auto-repair previous injected npx-based value to deterministic runtime path.
220
+ if (!hasLocalBinary && existing.trim() === `npx --yes cc-devflow harness ${subcommand}`) {
221
+ packageJson.scripts[scriptName] = desired;
222
+ repaired.push(scriptName);
223
+ changed = true;
224
+ continue;
225
+ }
226
+
227
+ // Auto-repair previous absolute-path fallback value (not portable across machines).
228
+ const escapedHarnessBin = HARNESS_BIN.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
229
+ const absoluteLegacy = new RegExp(`^node\\s+["']?${escapedHarnessBin}["']?\\s+${subcommand}(\\s*\\|\\|\\s*cc-devflow\\s+harness\\s+${subcommand})?$`);
230
+ if (!hasLocalBinary && absoluteLegacy.test(existing.trim())) {
231
+ packageJson.scripts[scriptName] = desired;
232
+ repaired.push(scriptName);
233
+ changed = true;
234
+ }
235
+ }
236
+
237
+ if (!changed) {
238
+ return;
239
+ }
240
+
241
+ const indent = detectJsonIndent(raw);
242
+ fs.writeFileSync(pkgPath, `${JSON.stringify(packageJson, null, indent)}\n`);
243
+
244
+ if (added.length > 0) {
245
+ console.log(`[UPDATE] package.json (added ${added.join(', ')})`);
246
+ }
247
+ if (repaired.length > 0) {
248
+ console.log(`[UPDATE] package.json (repaired ${repaired.join(', ')})`);
249
+ }
250
+ }
251
+
125
252
  function runInit(args) {
126
253
  const { options } = parseCliArgs(args);
127
254
 
@@ -141,6 +268,7 @@ function runInit(args) {
141
268
  // Case 1: Directory does not exist - Clean Install
142
269
  if (!fs.existsSync(targetDir)) {
143
270
  fs.cpSync(TEMPLATE_DIR, targetDir, { recursive: true });
271
+ ensureHarnessScripts(targetRoot);
144
272
  console.log(`Initialized .claude in ${targetRoot}`);
145
273
  return 0;
146
274
  }
@@ -150,6 +278,7 @@ function runInit(args) {
150
278
  console.log('Force flag detected. Resetting .claude directory...');
151
279
  fs.rmSync(targetDir, { recursive: true, force: true });
152
280
  fs.cpSync(TEMPLATE_DIR, targetDir, { recursive: true });
281
+ ensureHarnessScripts(targetRoot);
153
282
  console.log(`Re-initialized .claude in ${targetRoot}`);
154
283
  return 0;
155
284
  }
@@ -157,6 +286,7 @@ function runInit(args) {
157
286
  // Case 3: Directory exists - Incremental Update
158
287
  console.log(`Target ${targetDir} already exists. Performing incremental update...`);
159
288
  copyIncremental(TEMPLATE_DIR, targetDir);
289
+ ensureHarnessScripts(targetRoot);
160
290
  console.log('Incremental update complete. Existing files were preserved.');
161
291
  return 0;
162
292
  }
@@ -178,6 +308,8 @@ function runAdapt(args) {
178
308
  return 1;
179
309
  }
180
310
 
311
+ ensureHarnessScripts(targetRoot);
312
+
181
313
  const result = spawnSync(process.execPath, [ADAPT_BIN, ...rest], {
182
314
  stdio: 'inherit',
183
315
  cwd: targetRoot
@@ -191,6 +323,24 @@ function runAdapt(args) {
191
323
  return typeof result.status === 'number' ? result.status : 1;
192
324
  }
193
325
 
326
+ function runHarness(args) {
327
+ const { options, rest } = parseCliArgs(args);
328
+
329
+ const targetRoot = path.resolve(options.cwd || process.cwd());
330
+ const cliArgs = options.help || rest.length === 0 ? ['--help'] : rest;
331
+ const result = spawnSync(process.execPath, [HARNESS_BIN, ...cliArgs], {
332
+ stdio: 'inherit',
333
+ cwd: targetRoot
334
+ });
335
+
336
+ if (result.error) {
337
+ console.error(`Failed to run harness: ${result.error.message}`);
338
+ return 1;
339
+ }
340
+
341
+ return typeof result.status === 'number' ? result.status : 1;
342
+ }
343
+
194
344
  function runAdapter(command, args) {
195
345
  const result = spawnSync(process.execPath, [ADAPTER_BIN, command, ...args], {
196
346
  stdio: 'inherit'
@@ -221,6 +371,10 @@ function main() {
221
371
  return runAdapt(rest);
222
372
  }
223
373
 
374
+ if (command === 'harness') {
375
+ return runHarness(rest);
376
+ }
377
+
224
378
  return runAdapter(command, rest);
225
379
  }
226
380
 
@@ -0,0 +1,276 @@
1
+ # CC-DevFlow v4.3.0 Migration Guide
2
+
3
+ ## Overview
4
+
5
+ CC-DevFlow v4.3.0 introduces automatic TDD order validation and OpenSpec interoperability to solve requirement drift problems. This guide helps you migrate from v4.2.x to v4.3.0.
6
+
7
+ ---
8
+
9
+ ## What's New in v4.3.0
10
+
11
+ ### 1. Automatic TDD Order Validation
12
+
13
+ **Feature**: The harness planner now automatically validates TDD order when parsing TASKS.md.
14
+
15
+ **Impact**:
16
+ - [IMPL] tasks MUST depend on corresponding [TEST] tasks
17
+ - [TEST] tasks CANNOT depend on [IMPL] tasks
18
+ - Violations throw detailed error messages at `harness:plan` time
19
+
20
+ **Example Error**:
21
+ ```
22
+ TDD Order Validation Failed (Constitution Article VI):
23
+
24
+ 1. Task T002 (用户登录实现) missing corresponding TEST task.
25
+ Constitution Article VI requires: NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST.
26
+
27
+ 2. Task T004 (用户注册实现) must depend on T003 (用户注册测试).
28
+ TDD violation: Implementation must come AFTER test.
29
+ ```
30
+
31
+ **Migration Steps**:
32
+ 1. Review your existing TASKS.md files
33
+ 2. Ensure all [IMPL] tasks have corresponding [TEST] tasks
34
+ 3. Add `dependsOn` to [IMPL] tasks pointing to [TEST] tasks
35
+ 4. Use `[P]` marker for parallel tasks that don't follow TEST→IMPL pattern
36
+
37
+ **Example Fix**:
38
+ ```markdown
39
+ <!-- Before (INVALID) -->
40
+ - [ ] T001 [IMPL] 用户登录实现
41
+ - [ ] T002 [TEST] 用户登录测试
42
+
43
+ <!-- After (VALID) -->
44
+ - [ ] T001 [TEST] 用户登录测试
45
+ - [ ] T002 [IMPL] 用户登录实现 (dependsOn:T001)
46
+ ```
47
+
48
+ ### 2. OpenSpec Interoperability
49
+
50
+ **Feature**: Bidirectional conversion between OpenSpec and CC-DevFlow formats.
51
+
52
+ **New Commands**:
53
+ - `/flow:import-openspec` - Import OpenSpec spec.md to CC-DevFlow
54
+ - `/flow:export-openspec` - Export CC-DevFlow spec.md to OpenSpec
55
+
56
+ **Use Cases**:
57
+
58
+ #### Import from OpenSpec
59
+ ```bash
60
+ /flow:import-openspec "/path/to/openspec/specs/auth/spec.md" \
61
+ --req-id "REQ-123" \
62
+ --title "用户认证系统"
63
+ ```
64
+
65
+ **What happens**:
66
+ 1. Parses OpenSpec format (Purpose + Requirements + BDD scenarios)
67
+ 2. Generates CC-DevFlow spec.md with YAML frontmatter
68
+ 3. Auto-generates TDD tasks (TEST + IMPL pairs with correct dependencies)
69
+ 4. Adds Design section with [NEEDS CLARIFICATION] markers
70
+ 5. Generates Verification checklist
71
+
72
+ #### Export to OpenSpec
73
+ ```bash
74
+ /flow:export-openspec "REQ-123" \
75
+ --output "/path/to/openspec/specs/auth/spec.md"
76
+ ```
77
+
78
+ **What happens**:
79
+ 1. Parses CC-DevFlow spec.md
80
+ 2. Strips YAML frontmatter and metadata
81
+ 3. Removes Design, Tasks, Verification sections
82
+ 4. Removes [NEEDS CLARIFICATION] markers
83
+ 5. Outputs pure Requirements in OpenSpec format
84
+
85
+ **Round-Trip Guarantee**: Requirements are preserved through import→export→import cycles.
86
+
87
+ ---
88
+
89
+ ## Breaking Changes
90
+
91
+ ### 1. TASKS.md Validation
92
+
93
+ **Before v4.3.0**: TDD order was recommended but not enforced.
94
+
95
+ **After v4.3.0**: TDD order is enforced at `harness:plan` time.
96
+
97
+ **Migration**: Update existing TASKS.md files to follow TDD order.
98
+
99
+ ### 2. Task Type Detection
100
+
101
+ **Before v4.3.0**: Task types were not tracked.
102
+
103
+ **After v4.3.0**: Tasks are classified as TEST/IMPL/OTHER based on markers.
104
+
105
+ **Migration**: Ensure your TASKS.md uses `[TEST]` and `[IMPL]` markers consistently.
106
+
107
+ ---
108
+
109
+ ## Feature Name Matching Algorithm
110
+
111
+ The TDD validator uses intelligent fuzzy matching to pair TEST and IMPL tasks:
112
+
113
+ **Normalization Rules**:
114
+ - Removes suffixes: "测试", "实现", "功能", "开发", "编写"
115
+ - Trims whitespace
116
+ - Compares core feature names
117
+
118
+ **Examples**:
119
+ ```
120
+ "用户登录功能测试" ↔ "用户登录功能实现" ✅ Match
121
+ "用户登录测试" ↔ "用户登录实现" ✅ Match
122
+ "用户登录" ↔ "用户登录功能" ✅ Match
123
+ "用户登录" ↔ "用户注册" ❌ No match
124
+ ```
125
+
126
+ ---
127
+
128
+ ## Parallel Tasks
129
+
130
+ For tasks that don't follow TEST→IMPL pattern, use the `[P]` marker:
131
+
132
+ ```markdown
133
+ - [ ] T001 [TEST] 用户登录测试
134
+ - [ ] T002 [IMPL] 用户登录实现 (dependsOn:T001)
135
+ - [ ] T003 [OTHER] 数据库迁移 [P]
136
+ - [ ] T004 [OTHER] 配置文件更新 [P]
137
+ ```
138
+
139
+ The `[P]` marker tells the validator to skip dependency checks for that task.
140
+
141
+ ---
142
+
143
+ ## OpenSpec Format Reference
144
+
145
+ ### OpenSpec Format (Input)
146
+ ```markdown
147
+ # Authentication Module
148
+
149
+ ## Purpose
150
+ Provides secure authentication and session management.
151
+
152
+ ## Requirements
153
+
154
+ ### Requirement: User Login
155
+ The system SHALL allow users to log in with email and password.
156
+
157
+ #### Scenario: Valid credentials
158
+ - GIVEN a registered user
159
+ - WHEN the user submits valid email and password
160
+ - THEN a JWT token is issued
161
+ - AND the user is redirected to dashboard
162
+ ```
163
+
164
+ ### CC-DevFlow Format (Output)
165
+ ```markdown
166
+ ---
167
+ req_id: "REQ-123"
168
+ title: "用户认证系统"
169
+ created_at: "2026-03-13T10:00:00Z"
170
+ version: "1.0.0"
171
+ status: "draft"
172
+ source: "openspec"
173
+ ---
174
+
175
+ # Authentication Module
176
+
177
+ ## Purpose
178
+ Provides secure authentication and session management.
179
+
180
+ ## Requirements
181
+
182
+ ### Requirement: User Login
183
+ The system SHALL allow users to log in with email and password.
184
+
185
+ #### Scenario: Valid credentials
186
+ - GIVEN a registered user
187
+ - WHEN the user submits valid email and password
188
+ - THEN a JWT token is issued
189
+ - AND the user is redirected to dashboard
190
+
191
+ ## Design
192
+ [NEEDS CLARIFICATION: 技术实现方案]
193
+
194
+ ## Tasks
195
+ - [ ] T001 [TEST] User Login - 测试
196
+ - [ ] T002 [IMPL] User Login - 实现 (dependsOn:T001)
197
+
198
+ ## Verification
199
+ - [ ] User Login
200
+ - [ ] Valid credentials
201
+ ```
202
+
203
+ ---
204
+
205
+ ## Testing
206
+
207
+ All v4.3.0 features are covered by automated tests:
208
+
209
+ ```bash
210
+ # Run all tests
211
+ npm test
212
+
213
+ # Run TDD validation tests only
214
+ npm test -- planner.tdd.test.js
215
+
216
+ # Run OpenSpec interop tests only
217
+ npm test -- openspec.test.js
218
+ ```
219
+
220
+ **Test Coverage**:
221
+ - TDD validation: 10 tests (all passing)
222
+ - OpenSpec interop: 5 tests (all passing)
223
+ - Total: 233 tests (all passing)
224
+
225
+ ---
226
+
227
+ ## Troubleshooting
228
+
229
+ ### Error: "Task T002 missing corresponding TEST task"
230
+
231
+ **Cause**: An [IMPL] task has no matching [TEST] task.
232
+
233
+ **Solution**: Add a [TEST] task with similar feature name before the [IMPL] task.
234
+
235
+ ### Error: "Task T002 must depend on T001"
236
+
237
+ **Cause**: An [IMPL] task doesn't depend on its corresponding [TEST] task.
238
+
239
+ **Solution**: Add `(dependsOn:T001)` to the [IMPL] task.
240
+
241
+ ### Error: "Task T001 depends on IMPL tasks"
242
+
243
+ **Cause**: A [TEST] task depends on an [IMPL] task (reverse TDD order).
244
+
245
+ **Solution**: Remove the dependency or reorder tasks.
246
+
247
+ ### Feature Name Mismatch
248
+
249
+ **Cause**: TEST and IMPL tasks have very different feature names.
250
+
251
+ **Solution**: Rename tasks to have similar core feature names, or use `[P]` marker if they're truly independent.
252
+
253
+ ---
254
+
255
+ ## Rollback
256
+
257
+ If you need to rollback to v4.2.0:
258
+
259
+ ```bash
260
+ npm install cc-devflow@4.2.0
261
+ ```
262
+
263
+ Note: v4.2.0 does not have TDD validation or OpenSpec interop features.
264
+
265
+ ---
266
+
267
+ ## Support
268
+
269
+ - GitHub Issues: https://github.com/anthropics/cc-devflow/issues
270
+ - Documentation: https://github.com/anthropics/cc-devflow/tree/main/docs
271
+ - Constitution: `.claude/rules/project-constitution.md`
272
+
273
+ ---
274
+
275
+ **Last Updated**: 2026-03-13
276
+ **Version**: 4.3.0
@@ -3,16 +3,17 @@
3
3
 
4
4
  成员清单
5
5
  index.js: 聚合导出 harness 基础模块,供 CLI 与测试统一引用。
6
- schemas.js: 定义 manifest/report/checkpoint 的 Zod 契约,阻断脏数据进入执行层。
6
+ schemas.js: 定义 manifest/report/checkpoint/harness-state 的 Zod 契约,阻断脏数据进入执行层。
7
7
  store.js: 提供路径规范、JSON/文本读写、JSONL 事件记录与 shell 命令执行。
8
8
  planner.js: 将 TASKS.md 解析为 dependency-aware 的 task-manifest.json。
9
+ query.js: 聚合分散状态文件,提供 getProgress/getNextTask/getFullState 查询函数。
9
10
  cli.js: 解析命令参数并分发到 operations 子模块。
10
11
  operations/init.js: 初始化 requirement 与 runtime 目录并写入 harness-state。
11
12
  operations/pack.js: 采集 git 与脚本事实,生成 context-package.md。
12
- operations/plan.js: 调用 planner 生成 task-manifest.json。
13
- operations/dispatch.js: 依据依赖图与文件冲突并行执行任务,写 checkpoint 与 events。
13
+ operations/plan.js: 调用 planner 生成 task-manifest.json,更新 harness-state 为 planned
14
+ operations/dispatch.js: 依据依赖图与文件冲突并行执行任务,写 checkpoint 与 events,更新 harness-state 为 in_progress
14
15
  operations/resume.js: 恢复中断任务并复用 dispatch 继续执行。
15
- operations/verify.js: 执行 quick/strict 质量门禁并输出 report-card.json。
16
+ operations/verify.js: 执行 quick/strict 质量门禁并输出 report-card.json,通过时更新 harness-state 为 verified
16
17
  operations/release.js: 读取通过的 report-card,生成 RELEASE_NOTE 并标记 released。
17
18
  operations/janitor.js: 清理过期 runtime 工件,保留运行中任务状态。
18
19