phasegate 0.16.0 → 0.31.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 (215) hide show
  1. package/README.ja.md +71 -39
  2. package/README.md +69 -9
  3. package/docs/ADR/ADR-013-story-reflection-gate.md +100 -0
  4. package/docs/guide/configuration.md +244 -7
  5. package/package.json +4 -2
  6. package/scripts/harness/adr-foundation/domain/ports/adr-document-parser-port.ts +1 -0
  7. package/scripts/harness/adr-foundation/domain/ports/adr-frontmatter-parser-port.ts +1 -0
  8. package/scripts/harness/adr-foundation/domain/ports/adr-repository-port.ts +1 -0
  9. package/scripts/harness/adr-foundation/domain/value-objects/adr-status.ts +6 -6
  10. package/scripts/harness/agent-integration/application/dto/handle-pre-tool-use-dto.ts +3 -1
  11. package/scripts/harness/agent-integration/application/usecases/handle-pre-tool-use-usecase.ts +108 -2
  12. package/scripts/harness/agent-integration/domain/ports/config-query-port.ts +2 -0
  13. package/scripts/harness/agent-integration/domain/ports/phase-gate-query-port.ts +1 -1
  14. package/scripts/harness/agent-integration/domain/ports/story-reflection-query-port.ts +8 -0
  15. package/scripts/harness/agent-integration/domain/services/bash-write-target-extractor.ts +258 -0
  16. package/scripts/harness/agent-integration/domain/services/hook-to-cli-translator.ts +21 -4
  17. package/scripts/harness/agent-integration/domain/value-objects/protected-file-list.ts +20 -0
  18. package/scripts/harness/agent-integration/domain/value-objects/story-reflection-query-result.ts +63 -0
  19. package/scripts/harness/agent-integration/infrastructure/adapters/file-system-story-reflection-query-adapter.ts +122 -0
  20. package/scripts/harness/agent-integration/infrastructure/adapters/harness-config-config-query-adapter.ts +20 -0
  21. package/scripts/harness/agent-integration/infrastructure/adapters/phase-gate-query-adapter.ts +17 -3
  22. package/scripts/harness/agent-integration/presentation/pre-tool-use-hook.ts +29 -2
  23. package/scripts/harness/biome-ast-engine/domain/services/lint-runner.ts +24 -0
  24. package/scripts/harness/biome-ast-engine/domain/services/rule-definition-registry.ts +1 -1
  25. package/scripts/harness/biome-ast-engine/domain/value-objects/source-module-snapshot.ts +5 -2
  26. package/scripts/harness/biome-ast-engine/infrastructure/adapters/node-workspace-file-adapter.ts +1 -1
  27. package/scripts/harness/biome-ast-engine/infrastructure/adapters/typescript-source-module-analyzer-adapter.ts +1 -1
  28. package/scripts/harness/biome-ast-engine/infrastructure/parsers/unit-comment-parser.ts +12 -7
  29. package/scripts/harness/ci-governance/composition-root.ts +1 -0
  30. package/scripts/harness/config-foundation/application/mappers/phase-config-section-mapper.ts +44 -0
  31. package/scripts/harness/config-foundation/application/usecases/load-resolved-config-use-case.ts +20 -1
  32. package/scripts/harness/config-foundation/domain/harness-config.ts +2 -1
  33. package/scripts/harness/config-foundation/domain/value-objects/phase-dependencies-config.ts +18 -4
  34. package/scripts/harness/config-foundation/infrastructure/schemas/harness-config-v2.schema.json +185 -10
  35. package/scripts/harness/config-foundation/infrastructure/validators/ajv-config-schema-validator.ts +2 -1
  36. package/scripts/harness/harness-api/application/dto/command-dispatch-input.ts +1 -0
  37. package/scripts/harness/harness-api/application/dto/command-dispatch-output.ts +1 -0
  38. package/scripts/harness/harness-api/application/dto/exit-code-decision-input.ts +1 -0
  39. package/scripts/harness/harness-api/application/dto/exit-code-decision-output.ts +1 -0
  40. package/scripts/harness/harness-api/application/dto/harness-api-response-contract.ts +1 -0
  41. package/scripts/harness/harness-api/application/dto/initialize-registry-input.ts +1 -0
  42. package/scripts/harness/harness-api/application/dto/registry-summary-output.ts +1 -0
  43. package/scripts/harness/harness-api/application/dto/status-derivation-input.ts +1 -0
  44. package/scripts/harness/harness-api/application/mappers/harness-api-response-mapper.ts +1 -0
  45. package/scripts/harness/harness-api/application/usecases/decide-exit-code-usecase.ts +1 -0
  46. package/scripts/harness/harness-api/application/usecases/derive-harness-status-usecase.ts +1 -0
  47. package/scripts/harness/harness-api/application/usecases/dispatch-command-usecase.ts +1 -0
  48. package/scripts/harness/harness-api/application/usecases/initialize-command-registry-usecase.ts +1 -0
  49. package/scripts/harness/harness-api/composition-root.ts +1 -0
  50. package/scripts/harness/harness-api/domain/ports/artifact-scanner-port.ts +1 -0
  51. package/scripts/harness/harness-api/domain/ports/biome-lint-port.ts +1 -0
  52. package/scripts/harness/harness-api/domain/ports/config-query-port.ts +1 -0
  53. package/scripts/harness/harness-api/domain/ports/impact-analysis-port.ts +1 -0
  54. package/scripts/harness/harness-api/domain/ports/phase-gate-query-port.ts +1 -0
  55. package/scripts/harness/harness-api/domain/ports/validator-execution-port.ts +1 -0
  56. package/scripts/harness/harness-api/domain/services/command-dispatch-service.ts +1 -0
  57. package/scripts/harness/harness-api/domain/services/command-registry.ts +1 -0
  58. package/scripts/harness/harness-api/domain/services/status-derivation-service.ts +1 -0
  59. package/scripts/harness/harness-api/domain/value-objects/artifact-scan-result.ts +1 -0
  60. package/scripts/harness/harness-api/domain/value-objects/check-ready-result.ts +1 -0
  61. package/scripts/harness/harness-api/domain/value-objects/ci-check-result.ts +1 -0
  62. package/scripts/harness/harness-api/domain/value-objects/cli-command-definition.ts +1 -0
  63. package/scripts/harness/harness-api/domain/value-objects/command-input-spec.ts +1 -0
  64. package/scripts/harness/harness-api/domain/value-objects/drift-report-summary.ts +1 -0
  65. package/scripts/harness/harness-api/domain/value-objects/exit-code-spec.ts +1 -0
  66. package/scripts/harness/harness-api/domain/value-objects/harness-api-response.ts +1 -0
  67. package/scripts/harness/harness-api/domain/value-objects/harness-status-summary.ts +1 -0
  68. package/scripts/harness/harness-api/domain/value-objects/layer-health.ts +1 -0
  69. package/scripts/harness/harness-api/domain/value-objects/phase-info.ts +1 -0
  70. package/scripts/harness/harness-api/index.ts +1 -0
  71. package/scripts/harness/harness-api/infrastructure/adapters/biome-ast-engine-lint-adapter.ts +1 -0
  72. package/scripts/harness/harness-api/infrastructure/adapters/file-system-artifact-scanner-adapter.ts +1 -0
  73. package/scripts/harness/harness-api/infrastructure/adapters/harness-config-query-adapter.ts +1 -0
  74. package/scripts/harness/harness-api/infrastructure/adapters/nyquist-validation-impact-analysis-adapter.ts +1 -0
  75. package/scripts/harness/harness-api/infrastructure/adapters/phase-dependency-model-query-adapter.ts +1 -0
  76. package/scripts/harness/harness-api/infrastructure/adapters/validator-system-execution-adapter.ts +1 -0
  77. package/scripts/harness/harness-api/presentation/dto/cli-output-options.ts +1 -0
  78. package/scripts/harness/harness-api/presentation/formatters/harness-api-json-formatter.ts +1 -0
  79. package/scripts/harness/harness-api/presentation/handlers/check-phase-handler.ts +1 -0
  80. package/scripts/harness/harness-api/presentation/handlers/check-ready-handler.ts +1 -0
  81. package/scripts/harness/harness-api/presentation/handlers/ci-check-handler.ts +1 -0
  82. package/scripts/harness/harness-api/presentation/handlers/complete-check-handler.ts +1 -0
  83. package/scripts/harness/harness-api/presentation/handlers/detect-drift-handler.ts +1 -0
  84. package/scripts/harness/harness-api/presentation/handlers/impact-analysis-handler.ts +1 -0
  85. package/scripts/harness/harness-api/presentation/handlers/lint-handler.ts +1 -0
  86. package/scripts/harness/harness-api/presentation/handlers/status-handler.ts +1 -0
  87. package/scripts/harness/harness-error/infrastructure/adapters/legacy-error-reporter-adapter.ts +7 -1
  88. package/scripts/harness/integrations/pre-commit.ts +1 -0
  89. package/scripts/harness/main.ts +154 -34
  90. package/scripts/harness/phase-dependency-model/application/dto/resolve-gate-result-dto.ts +14 -0
  91. package/scripts/harness/phase-dependency-model/application/services/phase-gate-result-mapper.ts +20 -0
  92. package/scripts/harness/phase-dependency-model/application/usecases/check-story-reflection-usecase.ts +42 -0
  93. package/scripts/harness/phase-dependency-model/application/usecases/resolve-gate-usecase.ts +161 -0
  94. package/scripts/harness/phase-dependency-model/composition-root.ts +57 -1
  95. package/scripts/harness/phase-dependency-model/domain/definitions/{default-phase-dependencies.ts → full-phase-dependencies.ts} +3 -3
  96. package/scripts/harness/phase-dependency-model/domain/definitions/{default-phase-nodes.ts → full-phase-nodes.ts} +1 -1
  97. package/scripts/harness/phase-dependency-model/domain/definitions/full-story-reflection-defaults.ts +28 -0
  98. package/scripts/harness/phase-dependency-model/domain/definitions/minimal-phase-dependencies.ts +32 -0
  99. package/scripts/harness/phase-dependency-model/domain/definitions/minimal-phase-nodes.ts +50 -0
  100. package/scripts/harness/phase-dependency-model/domain/definitions/minimal-story-reflection-defaults.ts +8 -0
  101. package/scripts/harness/phase-dependency-model/domain/definitions/standard-phase-dependencies.ts +39 -0
  102. package/scripts/harness/phase-dependency-model/domain/definitions/standard-phase-nodes.ts +118 -0
  103. package/scripts/harness/phase-dependency-model/domain/definitions/standard-story-reflection-defaults.ts +23 -0
  104. package/scripts/harness/phase-dependency-model/domain/models/phase-structure.ts +95 -23
  105. package/scripts/harness/phase-dependency-model/domain/ports/glob-matcher-port.ts +8 -0
  106. package/scripts/harness/phase-dependency-model/domain/ports/phase-config-provider-port.ts +2 -0
  107. package/scripts/harness/phase-dependency-model/domain/ports/story-annotation-verifier-port.ts +14 -0
  108. package/scripts/harness/phase-dependency-model/domain/ports/story-reflection-file-system-port.ts +16 -0
  109. package/scripts/harness/phase-dependency-model/domain/services/gate-graph.ts +223 -0
  110. package/scripts/harness/phase-dependency-model/domain/services/story-reflection-checker.ts +66 -0
  111. package/scripts/harness/phase-dependency-model/domain/values/gate-definition.ts +127 -0
  112. package/scripts/harness/phase-dependency-model/domain/values/gate-name.ts +40 -0
  113. package/scripts/harness/phase-dependency-model/domain/values/gate-story-annotation.ts +39 -0
  114. package/scripts/harness/phase-dependency-model/domain/values/phase-customization-policy.ts +16 -4
  115. package/scripts/harness/phase-dependency-model/domain/values/story-reflection-config.ts +44 -0
  116. package/scripts/harness/phase-dependency-model/domain/values/story-reflection-mapping.ts +91 -0
  117. package/scripts/harness/phase-dependency-model/domain/values/story-reflection-result.ts +55 -0
  118. package/scripts/harness/phase-dependency-model/infrastructure/adapters/picomatch-glob-matcher.ts +17 -0
  119. package/scripts/harness/phase-dependency-model/infrastructure/adapters/story-annotation-verifier-adapter.ts +46 -0
  120. package/scripts/harness/phase-dependency-model/infrastructure/config/custom-gates-config-parser.ts +22 -0
  121. package/scripts/harness/phase-dependency-model/infrastructure/config/harness-config-phase-config-provider.ts +78 -2
  122. package/scripts/harness/phase-dependency-model/infrastructure/filesystem/file-system-story-reflection-adapter.ts +94 -0
  123. package/scripts/harness/phase-dependency-model/presentation/cli/check-phase-gate-command-handler.ts +12 -4
  124. package/scripts/harness/phase-dependency-model/presentation/cli/story-reflection-status-presenter.ts +87 -0
  125. package/scripts/harness/regression-suite/application/dto/analyze-migration-input.ts +1 -0
  126. package/scripts/harness/regression-suite/application/dto/analyze-migration-output.ts +1 -0
  127. package/scripts/harness/regression-suite/application/dto/configure-ci-gate-input.ts +1 -0
  128. package/scripts/harness/regression-suite/application/dto/configure-ci-gate-output.ts +1 -0
  129. package/scripts/harness/regression-suite/application/dto/migrate-v0-tests-input.ts +1 -0
  130. package/scripts/harness/regression-suite/application/dto/migrate-v0-tests-output.ts +1 -0
  131. package/scripts/harness/regression-suite/application/dto/run-regression-suite-input.ts +1 -0
  132. package/scripts/harness/regression-suite/application/dto/run-regression-suite-output.ts +1 -0
  133. package/scripts/harness/regression-suite/application/mappers/migration-mapping-mapper.ts +1 -0
  134. package/scripts/harness/regression-suite/application/mappers/test-execution-summary-mapper.ts +1 -0
  135. package/scripts/harness/regression-suite/application/usecases/analyze-v0-migration-usecase.ts +1 -0
  136. package/scripts/harness/regression-suite/application/usecases/configure-ci-gate-usecase.ts +1 -0
  137. package/scripts/harness/regression-suite/application/usecases/migrate-v0-tests-usecase.ts +1 -0
  138. package/scripts/harness/regression-suite/application/usecases/run-agent-independence-guard-usecase.ts +1 -0
  139. package/scripts/harness/regression-suite/application/usecases/run-gng-gate-regression-usecase.ts +1 -0
  140. package/scripts/harness/regression-suite/application/usecases/run-k-requirements-regression-usecase.ts +1 -0
  141. package/scripts/harness/regression-suite/application/usecases/run-k14-k15-regression-usecase.ts +1 -0
  142. package/scripts/harness/regression-suite/composition-root.ts +1 -0
  143. package/scripts/harness/regression-suite/domain/aggregates/v0-test-migration.ts +1 -0
  144. package/scripts/harness/regression-suite/domain/ports/ci-gate-result-writer-port.ts +1 -0
  145. package/scripts/harness/regression-suite/domain/ports/config-query-port.ts +1 -0
  146. package/scripts/harness/regression-suite/domain/ports/import-analyzer-port.ts +1 -0
  147. package/scripts/harness/regression-suite/domain/ports/migration-mapping-repository-port.ts +1 -0
  148. package/scripts/harness/regression-suite/domain/ports/suite-registry-port.ts +1 -0
  149. package/scripts/harness/regression-suite/domain/ports/test-runner-port.ts +1 -0
  150. package/scripts/harness/regression-suite/domain/ports/v0-spec-reader-port.ts +1 -0
  151. package/scripts/harness/regression-suite/domain/services/import-guard-service.ts +1 -0
  152. package/scripts/harness/regression-suite/domain/services/migration-analyzer.ts +1 -0
  153. package/scripts/harness/regression-suite/domain/services/regression-runner.ts +1 -0
  154. package/scripts/harness/regression-suite/domain/value-objects/agent-independence-test.ts +1 -0
  155. package/scripts/harness/regression-suite/domain/value-objects/biome-modification-spec.ts +1 -0
  156. package/scripts/harness/regression-suite/domain/value-objects/ci-gate-config.ts +1 -0
  157. package/scripts/harness/regression-suite/domain/value-objects/coverage-rate.ts +1 -0
  158. package/scripts/harness/regression-suite/domain/value-objects/gng-condition-test.ts +1 -0
  159. package/scripts/harness/regression-suite/domain/value-objects/import-violation.ts +1 -0
  160. package/scripts/harness/regression-suite/domain/value-objects/k-requirement-test.ts +1 -0
  161. package/scripts/harness/regression-suite/domain/value-objects/migration-mapping.ts +1 -0
  162. package/scripts/harness/regression-suite/domain/value-objects/regression-suite-definition.ts +1 -0
  163. package/scripts/harness/regression-suite/domain/value-objects/suite-id.ts +1 -0
  164. package/scripts/harness/regression-suite/domain/value-objects/test-execution-summary.ts +1 -0
  165. package/scripts/harness/regression-suite/domain/value-objects/test-failure-detail.ts +1 -0
  166. package/scripts/harness/regression-suite/domain/value-objects/v0-test-id.ts +1 -0
  167. package/scripts/harness/regression-suite/domain/value-objects/v1-test-path.ts +1 -0
  168. package/scripts/harness/regression-suite/infrastructure/adapters/biome-ast-import-analyzer-adapter.ts +1 -0
  169. package/scripts/harness/regression-suite/infrastructure/adapters/file-system-v0-spec-reader-adapter.ts +1 -0
  170. package/scripts/harness/regression-suite/infrastructure/adapters/harness-config-query-adapter.ts +1 -0
  171. package/scripts/harness/regression-suite/infrastructure/adapters/json-ci-gate-result-writer-adapter.ts +1 -0
  172. package/scripts/harness/regression-suite/infrastructure/adapters/markdown-migration-mapping-repository-adapter.ts +1 -0
  173. package/scripts/harness/regression-suite/infrastructure/adapters/static-suite-registry-adapter.ts +1 -0
  174. package/scripts/harness/regression-suite/infrastructure/adapters/vitest-test-runner-adapter.ts +1 -0
  175. package/scripts/harness/regression-suite/infrastructure/registry/agent-independence-suite-definition.ts +1 -0
  176. package/scripts/harness/regression-suite/infrastructure/registry/gng-gate-suite-definition.ts +1 -0
  177. package/scripts/harness/regression-suite/infrastructure/registry/k-requirements-suite-definition.ts +1 -0
  178. package/scripts/harness/regression-suite/infrastructure/registry/v0-migration-suite-definition.ts +1 -0
  179. package/scripts/harness/setup/skill-deployer.ts +82 -5
  180. package/scripts/harness/shared-kernel/harness-api.ts +1 -0
  181. package/scripts/harness/skill-quality/composition-root.ts +1 -0
  182. package/scripts/harness/skill-quality/infrastructure/adapters/ajv-lesson-artifact-schema-adapter.ts +5 -4
  183. package/scripts/harness/traceability-model/domain/services/metadata-validator.ts +12 -10
  184. package/scripts/harness/traceability-model/infrastructure/parsers/source-metadata-parser.ts +16 -2
  185. package/skills/cascade-updater/SKILL.md +16 -3
  186. package/skills/codebase-mapper/SKILL.md +9 -9
  187. package/skills/codex-delegator/SKILL.md +5 -56
  188. package/skills/consistency-checker/SKILL.md +5 -9
  189. package/skills/consistency-checker/references//343/203/201/343/202/247/343/203/203/343/202/257/343/203/252/343/202/271/343/203/210.md +6 -3
  190. package/skills/doc-freshness-checker/SKILL.md +6 -6
  191. package/skills/engineering-perspective/SKILL.md +2 -58
  192. package/skills/engineering-perspective/references/domain-model.md +4 -135
  193. package/skills/implementation-readiness-checker/SKILL.md +18 -72
  194. package/skills/it-test-designer/SKILL.md +25 -161
  195. package/skills/it-test-designer/references/it-test-design-template.md +131 -0
  196. package/skills/it-test-logic-designer/SKILL.md +13 -388
  197. package/skills/it-test-logic-designer/references/controller-test-patterns.md +100 -0
  198. package/skills/it-test-logic-designer/references/repository-test-patterns.md +206 -0
  199. package/skills/it-test-logic-designer/references/usecase-test-patterns.md +87 -0
  200. package/skills/pointer-validator/SKILL.md +4 -4
  201. package/skills/scenario-test-designer/SKILL.md +4 -68
  202. package/skills/scenario-test-designer/references/scenario-test-design-template.md +41 -0
  203. package/skills/scenario-test-designer/references/scenario-test-plan-template.md +35 -0
  204. package/skills/scenario-test-logic-designer/SKILL.md +21 -304
  205. package/skills/scenario-test-logic-designer/references/msw-patterns.md +36 -0
  206. package/skills/scenario-test-logic-designer/references/playwright-patterns.md +237 -0
  207. package/skills/test-coverage-checker/SKILL.md +39 -121
  208. package/skills/test-coverage-checker/references/coverage-report-template.md +99 -0
  209. package/skills/uiux-designer/SKILL.md +27 -92
  210. package/skills/uiux-designer/references/data-testid-convention.md +38 -0
  211. package/skills/uiux-designer/references/uiux-design-template.md +105 -0
  212. package/skills/unit-test-designer/SKILL.md +5 -106
  213. package/skills/unit-test-designer/references/unit-test-design-template.md +127 -0
  214. package/skills/unit-test-logic-designer/SKILL.md +28 -250
  215. package/skills/unit-test-logic-designer/references/test-patterns.md +207 -0
package/README.ja.md CHANGED
@@ -48,6 +48,9 @@ AIエージェント(Claude Code, Codex, Cursor, その他)が生成する
48
48
  | **Nyquist Validation** | 要件→テストの双方向トレーサビリティを`requirement-test-matrix.json`で保証 |
49
49
  | **Cascade Updater** | 下位フェーズの発見を上位設計文書に自動フィードバック |
50
50
  | **Regression Suite** | K1-K15非交渉要件・GnGゲート・エージェント非依存性を回帰テストで継続検証 |
51
+ | **カスタムフェーズゲート** | `phasegate.config.json` の `gates[]` で独自のフェーズゲートを定義可能。デフォルトはAIDLCフェーズ依存 |
52
+ | **保護ファイル制御** | `protectedFiles.exclude` でAI書き込みから保護するファイルを設定 |
53
+ | **Bash書き込み検出** | シェル経由のファイル書き込み(`sed -i`, `tee`, `cp`, `mv`, リダイレクト等)を検出してブロック |
51
54
 
52
55
  ---
53
56
 
@@ -135,7 +138,7 @@ npm install --save-dev phasegate
135
138
  ```json
136
139
  {
137
140
  "devDependencies": {
138
- "phasegate": "^0.14.0"
141
+ "phasegate": "^0.31.0"
139
142
  }
140
143
  }
141
144
  ```
@@ -194,25 +197,13 @@ npx phasegate update-skills
194
197
 
195
198
  ```jsonc
196
199
  {
197
- "version": "1.0",
198
- "preset": "standard", // "minimal" | "standard" | "strict"
199
- "project": {
200
- "name": "my-project",
201
- "architecture": "clean-architecture",
202
- "paths": {
203
- "source": ["src"],
204
- "docs": {
205
- "units": "docs/product/units",
206
- "inception": "docs/inception",
207
- "construction": "docs/product/construction"
208
- }
209
- }
210
- },
200
+ "project": { "name": "my-project", "preset": "standard" },
211
201
  "layers": {
212
- "L1_editor": { "enabled": true },
213
- "L2_precommit": { "enabled": true },
214
- "L3_ci": { "enabled": true },
215
- "L4_scheduled": { "enabled": false } // strict preset では true
202
+ "L0": { "enabled": false },
203
+ "L1": { "enabled": true },
204
+ "L2": { "enabled": true },
205
+ "L3": { "enabled": true },
206
+ "L4": { "enabled": false }
216
207
  },
217
208
  "quickMode": {
218
209
  "allowedCategories": ["bugfix", "docs", "test", "config"],
@@ -220,27 +211,16 @@ npx phasegate update-skills
220
211
  "relaxedGates": ["phase-gate", "2-phase-execution"]
221
212
  },
222
213
  "phaseDependencies": {
223
- "preset": "default", // "default" | "custom"
224
- "override": false, // true でフェーズ依存の緩和を許可
225
- "customRules": []
214
+ "preset": "standard",
215
+ "override": false,
216
+ "storyReflection": { "enabled": true }
226
217
  },
227
- "planningMode": {
228
- "default": "interactive", // "interactive" | "embedded-qa"
229
- "perPhase": {}
230
- },
231
- "harnesses": {
232
- "agentLessonCollection": false,
233
- "cascadeUpdate": false,
234
- "bundleSizeLimit": 0,
235
- "deadCodeGC": false
218
+ "protectedFiles": {
219
+ "exclude": ["tsconfig.json", "package.json"]
236
220
  },
237
221
  "paths": {
238
222
  "designDocs": "docs/product/construction",
239
223
  "inceptionDocs": "docs/inception"
240
- },
241
- "reporting": {
242
- "format": "json",
243
- "outputDir": "reports"
244
224
  }
245
225
  }
246
226
  ```
@@ -507,7 +487,7 @@ describe('ConfigSchema', () => {
507
487
  "hooks": {
508
488
  "PreToolUse": [
509
489
  {
510
- "matcher": "Write|Edit",
490
+ "matcher": "Write|Edit|Bash",
511
491
  "hooks": [{
512
492
  "type": "command",
513
493
  "command": "npx tsx scripts/harness/agent-integration/presentation/pre-tool-use-hook.ts"
@@ -538,7 +518,7 @@ describe('ConfigSchema', () => {
538
518
 
539
519
  | Hook | タイミング | 動作 |
540
520
  |---|---|---|
541
- | **PreToolUse** | ファイル書き込み前 | Phase Gate強制・保護ファイルへの変更をブロック。ブロック時はアクショナブルなエラーメッセージ(違反理由・不足成果物・次に使うべきスキル)を返却 |
521
+ | **PreToolUse** | ファイル書き込み前 | Phase Gate強制・保護ファイルへの変更をブロック・**Bash経由の書き込み検出(`sed -i`, `tee`, `cp`, `mv`, リダイレクト)**。ブロック時はアクショナブルなエラーメッセージ(違反理由・不足成果物・次に使うべきスキル)を返却 |
542
522
  | **PostToolUse** | ファイル書き込み後 | Biome ASTルールを自動実行、違反があれば即時フィードバック |
543
523
  | **Stop** | セッション終了前 | `phasegate:complete-check` (L2-L4全チェック) を実行、全グリーンでないとセッション終了を保留 |
544
524
 
@@ -674,7 +654,9 @@ npx phasegate ci-check --quick
674
654
 
675
655
  ## プリセット
676
656
 
677
- `phasegate.config.json` の `preset` フィールドで段階的に品質レベルを選択できます。
657
+ `phasegate.config.json` のプリセットは **2 系統** あります。
658
+
659
+ ### `project.preset` — レイヤー厳密度(L1-L4 有効化とカバレッジ閾値)
678
660
 
679
661
  | プリセット | 用途 | 有効レイヤー | カバレッジ閾値 |
680
662
  |---|---|---|---|
@@ -688,6 +670,56 @@ npx phasegate ci-check --quick
688
670
  - `bundleSizeLimit: 500 KB`
689
671
  - `deadCodeGC: true`
690
672
 
673
+ ### `phaseDependencies.preset` — フェーズゲート構成と storyReflection デフォルト
674
+
675
+ `project.preset` とは独立。`"default"` は後方互換のため `"full"` にフォールバックされます。
676
+
677
+ | プリセット | Phase 3 ゲート | storyReflection デフォルト | 用途 |
678
+ |---|---|---|---|
679
+ | **full** | 全 AIDLC ゲート | 有効 — `logical_design` + `domain_model` required、`uiux` optional | AIDLC フルセレモニー(旧 `default`) |
680
+ | **standard** | コアゲート | 有効 — `logical_design` required、`domain_model` optional | 通常開発・中庸な厳密度 |
681
+ | **minimal** | なし | 無効 — inception → product 反映強制なし | プロトタイプ・試行錯誤段階 |
682
+ | **custom** | ユーザー定義 | `storyReflection.mappings` で定義 | 完全カスタマイズ(`override: true` 必須) |
683
+
684
+ `storyReflection` は inception の US/issue 設計が `docs/product/construction/{unit}/` に反映されていない場合に `src/{unit}/*` への Write/Edit をブロックします。config で省略した場合はプリセットのデフォルト mappings がゼロコンフィグで自動適用されます。`cascade-updater` スキルがこのゲートを通過する標準手段です。詳細は [ADR-013](docs/ADR/ADR-013-story-reflection-gate.md) と [Configuration guide](docs/guide/configuration.md#storyreflection-inception--product-gate) を参照してください。
685
+
686
+ ---
687
+
688
+ ## カスタムフェーズゲート
689
+
690
+ デフォルトでは **AIDLCフェーズ依存モデル** が適用され、設計文書なしでの実装ファイル書き込みがブロックされます。`standard` または `full` プリセットでゼロコンフィグで動作します。
691
+
692
+ AIDLCを使わないプロジェクトでは、`phasegate.config.json` の `gates[]` 配列で **独自のゲート** を定義できます:
693
+
694
+ ```jsonc
695
+ {
696
+ "phaseDependencies": {
697
+ "preset": "custom",
698
+ "override": true,
699
+ "gates": [
700
+ {
701
+ "name": "schema-first",
702
+ "level": 3,
703
+ "blocks": ["src/api/**/*.ts"],
704
+ "requires": ["docs/api/openapi.yaml"],
705
+ "description": "API実装にはOpenAPIスキーマが必要"
706
+ }
707
+ ]
708
+ }
709
+ }
710
+ ```
711
+
712
+ | フィールド | 型 | 説明 |
713
+ |---|---|---|
714
+ | `name` | string | ゲートの一意識別子 |
715
+ | `level` | 1 \| 2 \| 3 | フェーズレベル(上位レベルは下位レベルのゲート通過が前提) |
716
+ | `blocks` | string[] | このゲートが保護するファイルのglobパターン |
717
+ | `requires` | string[] | ブロック対象パスへの書き込み前に存在が必要なファイル |
718
+ | `dependsOn` | string[] | 事前に通過が必要な他のゲート名 |
719
+ | `description` | string | ゲートの説明 |
720
+
721
+ ゲートは **DAG**(有向非巡回グラフ)を形成します。循環依存は設定読み込み時に拒否されます。
722
+
691
723
  ---
692
724
 
693
725
  ## CI/CD テンプレート
@@ -885,4 +917,4 @@ npx phasegate update-skills
885
917
 
886
918
  ---
887
919
 
888
- *Last updated: 2026-04-02 — v0.11.0*
920
+ *Last updated: 2026-04-06 — v0.31.0*
package/README.md CHANGED
@@ -27,6 +27,9 @@ Works with **Claude Code, Codex, Cursor, Copilot**, or any other AI agent.
27
27
  | **Quick Mode** | Lightweight gate for bugfixes, docs, tests, and config changes |
28
28
  | **Claude Code Hooks** | Native PreToolUse / PostToolUse / Stop hook integration |
29
29
  | **HarnessError Format** | Every error includes ADR references and fix examples for AI self-correction |
30
+ | **Configurable Phase Gates** | Define custom gates with `gates[]` in config. Default uses AIDLC phase dependencies |
31
+ | **Protected File Control** | Configure which files are protected from AI writes via `protectedFiles.exclude` |
32
+ | **Bash Write Detection** | Detects and blocks shell-based file writes (`sed -i`, `tee`, `cp`, `mv`, redirects) |
30
33
  | **Presets** | minimal, standard, and strict -- choose your quality level |
31
34
 
32
35
  ---
@@ -157,41 +160,98 @@ Skills cover the full **AIDLC (AI-Driven Development Life Cycle)**, enforcing ph
157
160
 
158
161
  ### Presets
159
162
 
163
+ `project.preset` -- overall layer strictness:
164
+
160
165
  | Preset | Layers | Coverage | Use Case |
161
166
  |---|---|---|---|
162
167
  | `minimal` | L1 + L2 | -- | Prototyping, early exploration |
163
168
  | `standard` | L1 - L3 | 90% | Production development (default) |
164
169
  | `strict` | L1 - L4 | 95% | Mission-critical systems |
165
170
 
171
+ `phaseDependencies.preset` -- phase-gate shape and storyReflection defaults (independent of `project.preset`):
172
+
173
+ | Preset | Phase 3 gates | storyReflection default | Use Case |
174
+ |---|---|---|---|
175
+ | `full` | All AIDLC gates | Enabled -- `logical_design` + `domain_model` required, `uiux` optional | AIDLC full ceremony (alias for legacy `default`) |
176
+ | `standard` | Core gates | Enabled -- `logical_design` required, `domain_model` optional | Production development with moderate rigor |
177
+ | `minimal` | None | Disabled -- no inception -> product enforcement | Prototyping / exploration |
178
+ | `custom` | User-defined via `gates[]` array | User-defined via `storyReflection.mappings` | Full control (requires `override: true`) |
179
+
180
+ `storyReflection` blocks writes to `src/{unit}/*` when an inception US/issue design exists but has not been cascaded into `docs/product/construction/{unit}/`. See [ADR-013](docs/ADR/ADR-013-story-reflection-gate.md) and the [Configuration guide](docs/guide/configuration.md#storyreflection-inception--product-gate).
181
+
166
182
  ### Key Configuration Sections
167
183
 
168
184
  ```jsonc
169
185
  {
170
- "preset": "standard",
171
- "project": { "name": "my-project", "architecture": "clean-architecture" },
186
+ "project": { "name": "my-project", "preset": "standard" },
172
187
  "layers": {
173
- "L1_editor": { "enabled": true },
174
- "L2_precommit": { "enabled": true },
175
- "L3_ci": { "enabled": true },
176
- "L4_scheduled": { "enabled": false }
188
+ "L0": { "enabled": false },
189
+ "L1": { "enabled": true },
190
+ "L2": { "enabled": true },
191
+ "L3": { "enabled": true },
192
+ "L4": { "enabled": false }
177
193
  },
178
194
  "quickMode": {
179
195
  "allowedCategories": ["bugfix", "docs", "test", "config"],
180
- "maintainedLayers": ["L1", "L2"]
196
+ "maintainedLayers": ["L1", "L2"],
197
+ "relaxedGates": ["phase-gate", "2-phase-execution"]
181
198
  },
182
- "phaseDependencies": { "preset": "default" }
199
+ "phaseDependencies": {
200
+ "preset": "standard",
201
+ "storyReflection": { "enabled": true }
202
+ },
203
+ "protectedFiles": {
204
+ "exclude": ["tsconfig.json", "package.json"]
205
+ }
183
206
  }
184
207
  ```
185
208
 
186
209
  ---
187
210
 
211
+ ## Configurable Phase Gates
212
+
213
+ By default, Phasegate enforces the **AIDLC phase dependency model** -- implementation files cannot be written without prerequisite design documents. This works out of the box with the `standard` or `full` preset.
214
+
215
+ For projects that don't follow AIDLC, you can define **custom gates** using the `gates[]` array in `phasegate.config.json`:
216
+
217
+ ```jsonc
218
+ {
219
+ "phaseDependencies": {
220
+ "preset": "custom",
221
+ "override": true,
222
+ "gates": [
223
+ {
224
+ "name": "schema-first",
225
+ "level": 3,
226
+ "blocks": ["src/api/**/*.ts"],
227
+ "requires": ["docs/api/openapi.yaml"],
228
+ "description": "API implementation requires OpenAPI schema"
229
+ }
230
+ ]
231
+ }
232
+ }
233
+ ```
234
+
235
+ | Field | Type | Description |
236
+ |---|---|---|
237
+ | `name` | string | Unique gate identifier |
238
+ | `level` | 1 \| 2 \| 3 | Phase level (higher levels require lower-level gates to pass first) |
239
+ | `blocks` | string[] | Glob patterns for files this gate protects |
240
+ | `requires` | string[] | Files that must exist before writing to blocked paths |
241
+ | `dependsOn` | string[] | Other gate names that must pass first |
242
+ | `description` | string | Human-readable gate description |
243
+
244
+ Gates form a **DAG** (Directed Acyclic Graph). Circular dependencies are rejected at config load time.
245
+
246
+ ---
247
+
188
248
  ## Claude Code Hooks Integration
189
249
 
190
250
  Phasegate integrates natively with Claude Code via hooks in `.claude/settings.json`:
191
251
 
192
252
  | Hook | Trigger | Behavior |
193
253
  |---|---|---|
194
- | `PreToolUse` | `Write` or `Edit` | Blocks writes to source files without design docs; runs Biome lint |
254
+ | `PreToolUse` | `Write`, `Edit`, or `Bash` (write operations detected) | Blocks writes to source files without design docs; protects configured files; detects Bash write operations (`sed -i`, `tee`, `cp`, etc.) |
195
255
  | `PostToolUse` | `Write` or `Edit` | Auto-formats and validates metadata |
196
256
  | `Stop` | Session end | Runs full test suite to ensure all tests pass |
197
257
 
@@ -0,0 +1,100 @@
1
+ # ADR-013: storyReflection ゲート(inception → product 反映の機械強制)
2
+
3
+ ## Status
4
+
5
+ Accepted
6
+
7
+ ## Context
8
+
9
+ AIDLC では US/issue ごとの設計文書が `docs/inception/{unit}/{storyId}/` 配下に作成され、Unit ごとに累積される設計文書が `docs/product/construction/{unit}/` に反映される。従来この反映は cascade-updater スキルに委ねられていたが、**手動運用のため抜け落ちが発生**し、以下の問題が顕在化した。
10
+
11
+ - inception の US-XXX 設計が存在するのに product 文書へ反映されず、Unit 全体の設計整合性が崩れる
12
+ - 実装ファイルの `@unit` → `docs/product/construction/{unit}/` のトレーサビリティが未反映 US に対して欠落する
13
+ - cascade-updater の実行有無をレビュー時に目視確認する必要があり、ヒューマンエラーが避けられない
14
+
15
+ Phase Gate(L2-001)は設計文書の**存在**を検証するが、inception と product の**整合性**(「inception にあるものが product にも反映されているか」)は検証範囲外だった。実装段階でこの欠落がブロックされなければ、設計の単一源としての product 文書が信頼できなくなる。
16
+
17
+ ## Decision
18
+
19
+ `phaseDependencies.storyReflection` を導入し、**実装着手時(`src/` / `scripts/harness/` への Write/Edit)に inception → product 反映を機械的に検証**する。
20
+
21
+ ### 設計原則
22
+
23
+ configurable_phase_gate_plan.md §4 から引用:
24
+
25
+ - **ハードコードされたデフォルトはプリセットとして残す(後方互換)**
26
+ - **Phase Gate / L2-002 / storyReflection / cascade-updater の 4 系統がプリセット単位で連動**
27
+ - storyReflection の対象は **product に累積更新される設計文書のみ**(テスト設計は US 単位で inception に閉じるため対象外)
28
+ - config 省略時はプリセットのデフォルト mappings が自動適用(**ゼロコンフィグ**)
29
+ - cascade-updater は storyReflection ゲート通過の**唯一の標準手段**
30
+
31
+ ### プリセット別デフォルト
32
+
33
+ | プリセット | storyReflection | デフォルト mappings |
34
+ |-----------|-----------------|--------------------|
35
+ | `full` | 必須 | `logical_design.md` + `domain_model.md` required、`uiux_design.md` optional |
36
+ | `standard` | 必須 | `logical_design.md` required、`domain_model.md` optional |
37
+ | `minimal` | 無効 | — |
38
+ | `custom` | 任意 | config で明示指定 |
39
+
40
+ `minimal` で storyReflection を無効にする理由: Phase 3 ゲートなしの状態で story 反映を強制するのは矛盾するため。
41
+
42
+ ### チェックロジック
43
+
44
+ ```
45
+ 発火条件: src/{unit}/* または scripts/harness/{unit}/* への Write/Edit
46
+ 1. WriteTargetScope から unitId を解決(@unit 複数ユニット対応)
47
+ 2. docs/inception/{unit}/ 配下の storyId ディレクトリを列挙
48
+ 3. 各 storyId × 各 mapping について:
49
+ - inception ファイルが存在する AND mapping.required == true
50
+ - → product ファイル内に @story-id {storyId} が含まれているか検証
51
+ - 含まれていない → ブロック
52
+ ```
53
+
54
+ ### エラーメッセージフォーマット
55
+
56
+ `HandlePreToolUseUseCase.blockReason: 'STORY_REFLECTION'` で返されるブロックメッセージは以下の形式とする(configurable_phase_gate_plan.md §4.3 より):
57
+
58
+ ```
59
+ [L2-STORY-REFLECTION] docs/product/construction/order/logical_design.md に
60
+ @story-id US-002 が反映されていません。
61
+
62
+ inception/order/US-002/logical_design.md は存在しますが、
63
+ 対応する product 文書に US-002 の設計が含まれていません。
64
+
65
+ 修正方法:
66
+ 1. cascade-updater を実行して product 文書を更新
67
+ 2. または手動で logical_design.md に @story-id US-002 を追加
68
+
69
+ 参照: ADR-013
70
+ ```
71
+
72
+ ### 関連コンポーネント
73
+
74
+ - `PhaseConfigProviderPort.getStoryReflectionConfig()` — プリセット + config から有効な mappings を解決
75
+ - `FileSystemStoryReflectionAdapter` — inception ディレクトリ列挙と product 文書内 `@story-id` 検索
76
+ - `HandlePreToolUseUseCase` — src/ への Write 発火時に storyReflection チェックを呼び出し、未反映ならブロック
77
+ - Quick Mode (`relaxedGates: ["phase-gate"]`) 時は storyReflection も緩和される(§4.6)
78
+
79
+ ## Consequences
80
+
81
+ ### Positive
82
+
83
+ - inception → product 反映の欠落が実装着手時点で機械的にブロックされる
84
+ - cascade-updater の実行が事実上必須化され、手動運用の抜け漏れが排除される
85
+ - config 省略時もプリセットデフォルトで動作するため、既存ユーザーはゼロコンフィグで恩恵を受ける
86
+ - `@unit` 複数ユニット対応と組み合わせ、共有インフラファイルでも全 Unit の反映状態が検証される
87
+
88
+ ### Negative / Trade-off
89
+
90
+ - 実装着手時に反映漏れがあると Write/Edit がブロックされるため、cascade-updater 実行の手間が増える
91
+ - `full` プリセットでは `domain_model.md` も required のため、軽微な変更でも反映が必要になる場合がある → `standard` または `custom` で緩和可能
92
+ - `minimal` ではこの保証が得られない(プロトタイプ段階の試行錯誤を優先するトレードオフ)
93
+
94
+ ## 関連要件・文書
95
+
96
+ - configurable_phase_gate_plan.md §4(Phase A: プリセット拡充 + storyReflection)
97
+ - ADR-007(phasegate.config.json — Single Source of Truth)
98
+ - ADR-008(Quick Mode)— storyReflection も `relaxedGates` で緩和される
99
+ - ADR-012(2-Phase Execution)— storyReflection は Phase 2 完了の事後条件に相当
100
+ - `docs/folder_management_rules.md` — inception / product の累積更新フロー
@@ -27,9 +27,14 @@ This file is the **Single Source of Truth** for all quality configuration in a P
27
27
  "relaxedGates": ["phase-gate", "2-phase-execution"]
28
28
  },
29
29
  "phaseDependencies": {
30
- "preset": "default", // "default" | "custom"
30
+ "preset": "standard", // "full" | "standard" | "minimal" | "custom" ("default" -> "full")
31
31
  "override": false,
32
- "customRules": []
32
+ "customRules": [],
33
+ "gates": [], // Optional. Custom phase gates (preset: "custom"). See gates[] reference below.
34
+ "storyReflection": { // Optional. Defaults per preset when omitted.
35
+ "enabled": true,
36
+ "mappings": [] // Omit to use the preset's built-in mappings.
37
+ }
33
38
  },
34
39
  "planningMode": {
35
40
  "default": "interactive", // "interactive" | "embedded-qa"
@@ -108,11 +113,243 @@ The five layers are:
108
113
 
109
114
  #### `phaseDependencies`
110
115
 
111
- | Sub-field | Type | Default | Description |
112
- |---------------|------------|-------------|--------------------------------------------------------------------|
113
- | `preset` | `string` | `"default"` | `"default"` uses the built-in AIDLC phase dependency graph. `"custom"` enables `customRules`. |
114
- | `override` | `boolean` | `false` | When `true`, custom rules fully replace the default graph instead of extending it. |
115
- | `customRules` | `array` | `[]` | Array of custom phase dependency rules. Only used when `preset` is `"custom"`. |
116
+ | Sub-field | Type | Default | Description |
117
+ |--------------------|------------|--------------|--------------------------------------------------------------------|
118
+ | `preset` | `string` | `"standard"` | One of `"full"`, `"standard"`, `"minimal"`, `"custom"`. `"default"` is accepted for backward compatibility and falls back to `"full"`. |
119
+ | `override` | `boolean` | `false` | When `true`, custom rules fully replace the default graph instead of extending it. Required when `preset` is `"custom"`. |
120
+ | `customRules` | `array` | `[]` | Array of custom phase dependency rules. Only used when `preset` is `"custom"`. |
121
+ | `gates` | `array` | `[]` | Array of custom phase gate definitions. See [gates\[\]](#gates-custom-phase-gates) below. Optional; defaults to empty. |
122
+ | `storyReflection` | `object` | preset-based | See [storyReflection](#storyreflection-inception--product-gate) below. Omit entirely for zero-config defaults per preset. |
123
+
124
+ ##### Phase Dependency Presets
125
+
126
+ | Preset | Phase 3 Gates | storyReflection default | Use Case |
127
+ |------------|---------------|-------------------------------------------------------------------------|----------------------------------------------------|
128
+ | `full` | All gates | **Enabled** -- `logical_design.md` + `domain_model.md` required, `uiux_design.md` optional | AIDLC full ceremony; mission-critical systems |
129
+ | `standard` | Core gates | **Enabled** -- `logical_design.md` required, `domain_model.md` optional | Production development with moderate rigor |
130
+ | `minimal` | None | **Disabled** | Prototyping / exploration (trade-off: no reflection enforcement) |
131
+ | `custom` | User-defined | User-defined (zero or explicit `mappings`) | Full control via `customRules` and `storyReflection.mappings` |
132
+
133
+ > `"default"` is accepted as an alias for `"full"` so existing `phasegate.config.json` files keep working after the upgrade.
134
+
135
+ #### `gates[]` (custom phase gates)
136
+
137
+ `gates[]` lets a project declare **additional phase gates** that fire when a write targets specific file globs. Each gate is checked at the pre-tool-use hook (and via `check-phase-gate` CLI) and blocks the write if its preconditions are not met.
138
+
139
+ `gates[]` is typically combined with `preset: "custom"` and `override: true` when the project wants full control over the phase dependency graph. It is also valid to layer a small number of gates on top of `preset: "custom"` without replacing the full graph.
140
+
141
+ **Validation is fail-fast**: a malformed `gates[]` entry (e.g. `level: 99`, unknown dependency) causes `loadResolvedConfig()` to exit with code `2` and prints `Invalid phasegate.config.json: ...` to stderr. The same error surfaces as a `blocker` in the hook path.
142
+
143
+ ##### Gate definition schema
144
+
145
+ Each entry in `gates[]` is an object with:
146
+
147
+ | Field | Type | Required | Description |
148
+ |-------------------|------------|----------|-------------------------------------------------------------------------------------------------------------------|
149
+ | `name` | `string` | yes | Unique gate identifier. Must match `^[a-z][a-z0-9-]*$`. |
150
+ | `level` | `integer` | yes | Phase level this gate belongs to. One of `1`, `2`, `3`. |
151
+ | `requires` | `object[]` | yes | Required artifacts. Each entry is `{ "path": "<glob or path>", "required": <boolean> }`. |
152
+ | `blocks` | `string[]` | yes | Glob patterns of files the gate guards. A write targeting any matching file triggers this gate. |
153
+ | `dependsOn` | `string[]` | yes | Names of other gates that must pass first. Forms a DAG; cycles are rejected at load time. |
154
+ | `storyAnnotation` | `object` | no | `{ "required": <boolean>, "tag": "<tag-name>" }`. When `required: true`, matched files must contain the tag (e.g. `@story-id H01-01`). Only valid when `level: 3`. |
155
+
156
+ **Rules:**
157
+
158
+ - `name` must be unique across the whole `gates[]` array.
159
+ - `level` is restricted to `1`, `2`, or `3`. `level: 99` or similar is a schema violation.
160
+ - `dependsOn` must reference existing gate names and must not form a cycle.
161
+ - `storyAnnotation` may only appear on `level: 3` gates (schema-enforced).
162
+ - `blocks` uses picomatch glob syntax (e.g. `"src/**/*.ts"`, `"scripts/harness/order/**"`).
163
+
164
+ ##### Example 1 — single level-3 story gate
165
+
166
+ Enforce that any write under `scripts/harness/order/**` carries an `@story-id` annotation:
167
+
168
+ ```jsonc
169
+ {
170
+ "phaseDependencies": {
171
+ "preset": "custom",
172
+ "override": true,
173
+ "customRules": [],
174
+ "gates": [
175
+ {
176
+ "name": "order-story-impl",
177
+ "level": 3,
178
+ "requires": [
179
+ { "path": "docs/product/user_stories.md", "required": true }
180
+ ],
181
+ "blocks": ["scripts/harness/order/**/*.ts"],
182
+ "dependsOn": [],
183
+ "storyAnnotation": { "required": true, "tag": "@story-id" }
184
+ }
185
+ ]
186
+ }
187
+ }
188
+ ```
189
+
190
+ ##### Example 2 — diamond DAG with multiple chains
191
+
192
+ Two level-1 gates feed into a level-2 aggregate, which gates a level-3 implementation:
193
+
194
+ ```jsonc
195
+ {
196
+ "phaseDependencies": {
197
+ "preset": "custom",
198
+ "override": true,
199
+ "customRules": [],
200
+ "gates": [
201
+ {
202
+ "name": "logical-design",
203
+ "level": 1,
204
+ "requires": [
205
+ { "path": "docs/product/construction/{unit}/logical_design.md", "required": true }
206
+ ],
207
+ "blocks": [],
208
+ "dependsOn": []
209
+ },
210
+ {
211
+ "name": "domain-model",
212
+ "level": 1,
213
+ "requires": [
214
+ { "path": "docs/product/construction/{unit}/domain_model.md", "required": true }
215
+ ],
216
+ "blocks": [],
217
+ "dependsOn": []
218
+ },
219
+ {
220
+ "name": "tdd-plan",
221
+ "level": 2,
222
+ "requires": [
223
+ { "path": "docs/inception/{unit}/{storyId}/tdd_implementation_plan.md", "required": true }
224
+ ],
225
+ "blocks": [],
226
+ "dependsOn": ["logical-design", "domain-model"]
227
+ },
228
+ {
229
+ "name": "story-impl",
230
+ "level": 3,
231
+ "requires": [],
232
+ "blocks": ["scripts/harness/**/*.ts"],
233
+ "dependsOn": ["tdd-plan"],
234
+ "storyAnnotation": { "required": true, "tag": "@story-id" }
235
+ }
236
+ ]
237
+ }
238
+ }
239
+ ```
240
+
241
+ ##### Example 3 — minimal level-1 gate (no storyAnnotation)
242
+
243
+ Block commits that touch a protected path unless a design artifact exists — no story-id enforcement:
244
+
245
+ ```jsonc
246
+ {
247
+ "phaseDependencies": {
248
+ "preset": "custom",
249
+ "override": true,
250
+ "customRules": [],
251
+ "gates": [
252
+ {
253
+ "name": "schema-guard",
254
+ "level": 1,
255
+ "requires": [
256
+ { "path": "docs/schema/migration-notes.md", "required": true }
257
+ ],
258
+ "blocks": ["db/migrations/**/*.sql"],
259
+ "dependsOn": []
260
+ }
261
+ ]
262
+ }
263
+ }
264
+ ```
265
+
266
+ #### `storyReflection` (inception -> product gate)
267
+
268
+ `storyReflection` enforces that every US / issue under `docs/inception/{unit}/{storyId}/` has been **cascaded into the accumulating product design documents** (`docs/product/construction/{unit}/`) before source code under `src/{unit}/` or `scripts/harness/{unit}/` can be written or edited.
269
+
270
+ The check fires at the pre-tool-use hook and blocks `Write`/`Edit` (and their Bash equivalents such as `cat > file`, `tee`, heredoc, `sed -i`, `cp`, `mv`, `touch`) whenever an inception design exists but its `@story-id` is not reflected in the corresponding product file.
271
+
272
+ **Zero-config**: omitting the `storyReflection` block, or specifying it without `mappings`, applies the preset's built-in mappings automatically.
273
+
274
+ | Sub-field | Type | Default | Description |
275
+ |-------------|------------|-------------------------|------------------------------------------------------------------------------|
276
+ | `enabled` | `boolean` | preset-dependent | Master switch. `full` / `standard` default to `true`; `minimal` defaults to `false`. |
277
+ | `mappings` | `array` | preset-dependent | Array of inception -> product file mappings. Omit to use the preset default. |
278
+
279
+ Each mapping entry:
280
+
281
+ | Field | Type | Description |
282
+ |-------------|-----------|-----------------------------------------------------------------------------|
283
+ | `inception` | `string` | Template path, e.g. `"docs/inception/{unit}/{storyId}/logical_design.md"`. |
284
+ | `product` | `string` | Template path, e.g. `"docs/product/construction/{unit}/logical_design.md"`.|
285
+ | `required` | `boolean` | When `true`, missing reflection blocks the write. When `false`, it is tolerated (optional mapping). |
286
+
287
+ ##### Preset defaults (hard-coded)
288
+
289
+ **`full`** -- AIDLC recommended (product-accumulated design documents only; test designs are out of scope because they live per-US inside `inception/`):
290
+
291
+ ```jsonc
292
+ [
293
+ { "inception": "docs/inception/{unit}/{storyId}/logical_design.md",
294
+ "product": "docs/product/construction/{unit}/logical_design.md",
295
+ "required": true },
296
+ { "inception": "docs/inception/{unit}/{storyId}/domain_model.md",
297
+ "product": "docs/product/construction/{unit}/domain_model.md",
298
+ "required": true },
299
+ { "inception": "docs/inception/{unit}/{storyId}/uiux_design.md",
300
+ "product": "docs/product/construction/{unit}/uiux_design.md",
301
+ "required": false }
302
+ ]
303
+ ```
304
+
305
+ **`standard`**:
306
+
307
+ ```jsonc
308
+ [
309
+ { "inception": "docs/inception/{unit}/{storyId}/logical_design.md",
310
+ "product": "docs/product/construction/{unit}/logical_design.md",
311
+ "required": true },
312
+ { "inception": "docs/inception/{unit}/{storyId}/domain_model.md",
313
+ "product": "docs/product/construction/{unit}/domain_model.md",
314
+ "required": false }
315
+ ]
316
+ ```
317
+
318
+ **`minimal`**: `enabled: false`. No storyReflection checking.
319
+
320
+ ##### Custom mappings example
321
+
322
+ Override the preset defaults only when your project needs a different policy:
323
+
324
+ ```jsonc
325
+ {
326
+ "phaseDependencies": {
327
+ "preset": "standard",
328
+ "storyReflection": {
329
+ "enabled": true,
330
+ "mappings": [
331
+ { "inception": "docs/inception/{unit}/{storyId}/logical_design.md",
332
+ "product": "docs/product/construction/{unit}/logical_design.md",
333
+ "required": true }
334
+ ]
335
+ }
336
+ }
337
+ }
338
+ ```
339
+
340
+ ##### How the check fires
341
+
342
+ 1. `Write` / `Edit` (or a Bash write such as `cat > src/order/foo.ts`) targets a source file under a Unit.
343
+ 2. `WriteTargetScope` resolves the `@unit` annotation (comma-separated and multi-line `@unit` are both supported; **all** listed units are checked).
344
+ 3. For each unit, every `storyId` directory under `docs/inception/{unit}/` is enumerated.
345
+ 4. For each required mapping, the pre-tool-use hook checks that the target product document contains `@story-id {storyId}`.
346
+ 5. Any missing reflection produces a `STORY_REFLECTION` block reason with a fix hint that points to the `cascade-updater` skill and [ADR-013](../ADR/ADR-013-story-reflection-gate.md).
347
+
348
+ ##### Passing the gate
349
+
350
+ `cascade-updater` is the **standard means of passing the storyReflection gate**: run it to propagate the new US / issue design into the accumulating product documents. Manual editing of the product file with an appended `@story-id` tag is also accepted.
351
+
352
+ Quick Mode with `relaxedGates: ["phase-gate"]` relaxes `storyReflection` as well (see [Quick Mode](#quick-mode)). L1 and L2 `metadata` / `test-quality` checks remain fully enforced.
116
353
 
117
354
  #### `planningMode`
118
355