@leocm/flowcraft 0.0.0-stage → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. package/README.md +855 -3
  2. package/bin/cli.js +108 -0
  3. package/flowcraft.yaml +30 -0
  4. package/install.sh +24 -0
  5. package/lib/args.js +38 -0
  6. package/lib/config.js +20 -0
  7. package/lib/copy.js +131 -0
  8. package/lib/fix.js +110 -0
  9. package/lib/fsutil.js +104 -0
  10. package/lib/global.js +229 -0
  11. package/lib/init.js +43 -0
  12. package/lib/runtime.js +84 -0
  13. package/lib/version.js +55 -0
  14. package/lib/wizard.js +125 -0
  15. package/package.json +31 -4
  16. package/presets/backend.yaml +20 -0
  17. package/presets/default.yaml +15 -0
  18. package/presets/frontend.yaml +20 -0
  19. package/presets/quick-fix.yaml +15 -0
  20. package/setup/.claude/commands/P0.5.md +1 -0
  21. package/setup/.claude/commands/P0.md +1 -0
  22. package/setup/.claude/commands/P1.md +1 -0
  23. package/setup/.claude/commands/P2.md +1 -0
  24. package/setup/.claude/commands/P3.md +1 -0
  25. package/setup/.claude/commands/P4.md +1 -0
  26. package/setup/.claude/commands/P5.md +1 -0
  27. package/setup/.claude/commands/code-analysis-init.md +1 -0
  28. package/setup/.claude/commands/code-analysis-rebuild.md +1 -0
  29. package/setup/.claude/commands/code-analysis-show-memory.md +1 -0
  30. package/setup/.claude/commands/code-analysis-update.md +1 -0
  31. package/setup/.claude/hooks/check-phase-advancement.py +180 -0
  32. package/setup/.claude/hooks/check-phase-test.py +152 -0
  33. package/setup/.claude/hooks/check-phase-write.py +235 -0
  34. package/setup/.claude/hooks/dispatch.py +67 -0
  35. package/setup/.claude/hooks/file-suggestion.py +45 -0
  36. package/setup/.claude/hooks/flowcraft_env.py +137 -0
  37. package/setup/.claude/hooks/log_session.py +93 -0
  38. package/setup/.claude/hooks/permission-request.py +125 -0
  39. package/setup/.claude/hooks/post-tool-failure.py +36 -0
  40. package/setup/.claude/hooks/pre-compact.py +66 -0
  41. package/setup/.claude/hooks/review-runner.py +846 -0
  42. package/setup/.claude/hooks/session-end.py +184 -0
  43. package/setup/.claude/hooks/session-start.py +188 -0
  44. package/setup/.claude/hooks/settings.json +0 -0
  45. package/setup/.claude/hooks/setup-keys.py +282 -0
  46. package/setup/.claude/hooks/statusline.py +63 -0
  47. package/setup/.claude/hooks/stop-check.py +171 -0
  48. package/setup/.claude/hooks/subagent-start.py +50 -0
  49. package/setup/.claude/hooks/subagent-stop.py +63 -0
  50. package/setup/.claude/hooks/task-completed.py +57 -0
  51. package/setup/.claude/hooks/task_manager.py +592 -0
  52. package/setup/.claude/hooks/user-prompt-submit.py +85 -0
  53. package/setup/.claude/project-state.md +109 -0
  54. package/setup/.claude/settings.json +237 -0
  55. package/setup/.claude/settings.local.json +13 -0
  56. package/setup/.claude/skills/P5report/SKILL.md +77 -0
  57. package/setup/.claude/skills/Pstatus/SKILL.md +68 -0
  58. package/setup/.claude/skills/archive/SKILL.md +196 -0
  59. package/setup/.claude/skills/brainstorming/SKILL.md +155 -0
  60. package/setup/.claude/skills/brainstorming/scripts/frame-template.html +213 -0
  61. package/setup/.claude/skills/brainstorming/scripts/helper.js +167 -0
  62. package/setup/.claude/skills/brainstorming/scripts/server.cjs +723 -0
  63. package/setup/.claude/skills/brainstorming/scripts/start-server.py +245 -0
  64. package/setup/.claude/skills/brainstorming/scripts/stop-server.py +178 -0
  65. package/setup/.claude/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
  66. package/setup/.claude/skills/brainstorming/visual-companion.md +298 -0
  67. package/setup/.claude/skills/checkpoint/SKILL.md +42 -0
  68. package/setup/.claude/skills/chrome-integration/SKILL.md +67 -0
  69. package/setup/.claude/skills/code-analysis/SKILL.md +1243 -0
  70. package/setup/.claude/skills/code-review/SKILL.md +265 -0
  71. package/setup/.claude/skills/cross-review/SKILL.md +41 -0
  72. package/setup/.claude/skills/executing-plans/SKILL.md +64 -0
  73. package/setup/.claude/skills/git-prep/SKILL.md +50 -0
  74. package/setup/.claude/skills/gitnexus/gitnexus-cli/SKILL.md +67 -0
  75. package/setup/.claude/skills/gitnexus/gitnexus-debugging/SKILL.md +89 -0
  76. package/setup/.claude/skills/gitnexus/gitnexus-exploring/SKILL.md +78 -0
  77. package/setup/.claude/skills/gitnexus/gitnexus-guide/SKILL.md +66 -0
  78. package/setup/.claude/skills/gitnexus/gitnexus-impact-analysis/SKILL.md +97 -0
  79. package/setup/.claude/skills/gitnexus/gitnexus-refactoring/SKILL.md +121 -0
  80. package/setup/.claude/skills/graphify/SKILL.md +49 -0
  81. package/setup/.claude/skills/openspec-apply-change/SKILL.md +185 -0
  82. package/setup/.claude/skills/openspec-archive-change/SKILL.md +182 -0
  83. package/setup/.claude/skills/openspec-bulk-archive-change/SKILL.md +339 -0
  84. package/setup/.claude/skills/openspec-continue-change/SKILL.md +118 -0
  85. package/setup/.claude/skills/openspec-explore/SKILL.md +311 -0
  86. package/setup/.claude/skills/openspec-ff-change/SKILL.md +113 -0
  87. package/setup/.claude/skills/openspec-new-change/SKILL.md +77 -0
  88. package/setup/.claude/skills/openspec-onboard/SKILL.md +573 -0
  89. package/setup/.claude/skills/openspec-propose/SKILL.md +149 -0
  90. package/setup/.claude/skills/openspec-sync-specs/SKILL.md +262 -0
  91. package/setup/.claude/skills/openspec-update-change/SKILL.md +91 -0
  92. package/setup/.claude/skills/openspec-verify-change/SKILL.md +175 -0
  93. package/setup/.claude/skills/oss-version-check/SKILL.md +71 -0
  94. package/setup/.claude/skills/oss-version-check/check_oss_version.py +205 -0
  95. package/setup/.claude/skills/phase/SKILL.md +63 -0
  96. package/setup/.claude/skills/playwright/SKILL.md +86 -0
  97. package/setup/.claude/skills/playwright-cli/SKILL.md +420 -0
  98. package/setup/.claude/skills/playwright-cli/references/element-attributes.md +23 -0
  99. package/setup/.claude/skills/playwright-cli/references/playwright-tests.md +39 -0
  100. package/setup/.claude/skills/playwright-cli/references/references/element-attributes.md +23 -0
  101. package/setup/.claude/skills/playwright-cli/references/references/playwright-tests.md +39 -0
  102. package/setup/.claude/skills/playwright-cli/references/references/request-mocking.md +87 -0
  103. package/setup/.claude/skills/playwright-cli/references/references/running-code.md +241 -0
  104. package/setup/.claude/skills/playwright-cli/references/references/session-management.md +225 -0
  105. package/setup/.claude/skills/playwright-cli/references/references/storage-state.md +275 -0
  106. package/setup/.claude/skills/playwright-cli/references/references/test-generation.md +433 -0
  107. package/setup/.claude/skills/playwright-cli/references/references/tracing.md +139 -0
  108. package/setup/.claude/skills/playwright-cli/references/references/video-recording.md +143 -0
  109. package/setup/.claude/skills/playwright-cli/references/request-mocking.md +87 -0
  110. package/setup/.claude/skills/playwright-cli/references/running-code.md +241 -0
  111. package/setup/.claude/skills/playwright-cli/references/session-management.md +225 -0
  112. package/setup/.claude/skills/playwright-cli/references/storage-state.md +275 -0
  113. package/setup/.claude/skills/playwright-cli/references/test-generation.md +433 -0
  114. package/setup/.claude/skills/playwright-cli/references/tracing.md +139 -0
  115. package/setup/.claude/skills/playwright-cli/references/video-recording.md +143 -0
  116. package/setup/.claude/skills/review/SKILL.md +98 -0
  117. package/setup/.claude/skills/review-tools/SKILL.md +76 -0
  118. package/setup/.claude/skills/subagent-driven-development/SKILL.md +94 -0
  119. package/setup/.claude/skills/task/SKILL.md +26 -0
  120. package/setup/.claude/skills/test-driven-development/SKILL.md +320 -0
  121. package/setup/.claude/skills/test-driven-development/writing-good-tests.md +198 -0
  122. package/setup/.claude/skills/ui-ux-pro-max/SKILL.md +377 -0
  123. package/setup/.claude/skills/ui-ux-pro-max/data/charts.csv +26 -0
  124. package/setup/.claude/skills/ui-ux-pro-max/data/colors.csv +97 -0
  125. package/setup/.claude/skills/ui-ux-pro-max/data/icons.csv +101 -0
  126. package/setup/.claude/skills/ui-ux-pro-max/data/landing.csv +31 -0
  127. package/setup/.claude/skills/ui-ux-pro-max/data/products.csv +97 -0
  128. package/setup/.claude/skills/ui-ux-pro-max/data/react-performance.csv +45 -0
  129. package/setup/.claude/skills/ui-ux-pro-max/data/stacks/astro.csv +54 -0
  130. package/setup/.claude/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
  131. package/setup/.claude/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
  132. package/setup/.claude/skills/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
  133. package/setup/.claude/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
  134. package/setup/.claude/skills/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
  135. package/setup/.claude/skills/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
  136. package/setup/.claude/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
  137. package/setup/.claude/skills/ui-ux-pro-max/data/stacks/react.csv +54 -0
  138. package/setup/.claude/skills/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
  139. package/setup/.claude/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
  140. package/setup/.claude/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
  141. package/setup/.claude/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -0
  142. package/setup/.claude/skills/ui-ux-pro-max/data/styles.csv +68 -0
  143. package/setup/.claude/skills/ui-ux-pro-max/data/typography.csv +58 -0
  144. package/setup/.claude/skills/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
  145. package/setup/.claude/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
  146. package/setup/.claude/skills/ui-ux-pro-max/data/web-interface.csv +31 -0
  147. package/setup/.claude/skills/ui-ux-pro-max/scripts/core.py +253 -0
  148. package/setup/.claude/skills/ui-ux-pro-max/scripts/design_system.py +1067 -0
  149. package/setup/.claude/skills/ui-ux-pro-max/scripts/search.py +114 -0
  150. package/setup/.claude/skills/ui-ux-standards/SKILL.md +154 -0
  151. package/setup/.claude/skills/verification-before-completion/SKILL.md +120 -0
  152. package/setup/.claude/skills/wiki-read/SKILL.md +190 -0
  153. package/setup/.claude/skills/writing-plans/SKILL.md +168 -0
  154. package/setup/.claude/skills/writing-plans/plan-document-reviewer-prompt.md +49 -0
  155. package/setup/.claude/tasks/.last-session +1 -0
  156. package/setup/.codex/.agents/skills/P5report/SKILL.md +77 -0
  157. package/setup/.codex/.agents/skills/Pstatus/SKILL.md +30 -0
  158. package/setup/.codex/.agents/skills/archive/SKILL.md +196 -0
  159. package/setup/.codex/.agents/skills/brainstorming/SKILL.md +155 -0
  160. package/setup/.codex/.agents/skills/brainstorming/scripts/frame-template.html +213 -0
  161. package/setup/.codex/.agents/skills/brainstorming/scripts/helper.js +167 -0
  162. package/setup/.codex/.agents/skills/brainstorming/scripts/server.cjs +723 -0
  163. package/setup/.codex/.agents/skills/brainstorming/scripts/start-server.py +245 -0
  164. package/setup/.codex/.agents/skills/brainstorming/scripts/stop-server.py +178 -0
  165. package/setup/.codex/.agents/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
  166. package/setup/.codex/.agents/skills/brainstorming/visual-companion.md +298 -0
  167. package/setup/.codex/.agents/skills/checkpoint/SKILL.md +42 -0
  168. package/setup/.codex/.agents/skills/chrome-integration/SKILL.md +67 -0
  169. package/setup/.codex/.agents/skills/code-analysis/SKILL.md +1243 -0
  170. package/setup/.codex/.agents/skills/code-review/SKILL.md +265 -0
  171. package/setup/.codex/.agents/skills/cross-review/SKILL.md +42 -0
  172. package/setup/.codex/.agents/skills/executing-plans/SKILL.md +64 -0
  173. package/setup/.codex/.agents/skills/git-prep/SKILL.md +50 -0
  174. package/setup/.codex/.agents/skills/gitnexus/gitnexus-cli/SKILL.md +67 -0
  175. package/setup/.codex/.agents/skills/gitnexus/gitnexus-debugging/SKILL.md +89 -0
  176. package/setup/.codex/.agents/skills/gitnexus/gitnexus-exploring/SKILL.md +78 -0
  177. package/setup/.codex/.agents/skills/gitnexus/gitnexus-guide/SKILL.md +66 -0
  178. package/setup/.codex/.agents/skills/gitnexus/gitnexus-impact-analysis/SKILL.md +97 -0
  179. package/setup/.codex/.agents/skills/gitnexus/gitnexus-refactoring/SKILL.md +121 -0
  180. package/setup/.codex/.agents/skills/graphify/SKILL.md +49 -0
  181. package/setup/.codex/.agents/skills/openspec-apply-change/SKILL.md +185 -0
  182. package/setup/.codex/.agents/skills/openspec-archive-change/SKILL.md +182 -0
  183. package/setup/.codex/.agents/skills/openspec-bulk-archive-change/SKILL.md +339 -0
  184. package/setup/.codex/.agents/skills/openspec-continue-change/SKILL.md +118 -0
  185. package/setup/.codex/.agents/skills/openspec-explore/SKILL.md +311 -0
  186. package/setup/.codex/.agents/skills/openspec-ff-change/SKILL.md +113 -0
  187. package/setup/.codex/.agents/skills/openspec-new-change/SKILL.md +77 -0
  188. package/setup/.codex/.agents/skills/openspec-onboard/SKILL.md +573 -0
  189. package/setup/.codex/.agents/skills/openspec-propose/SKILL.md +149 -0
  190. package/setup/.codex/.agents/skills/openspec-sync-specs/SKILL.md +262 -0
  191. package/setup/.codex/.agents/skills/openspec-update-change/SKILL.md +91 -0
  192. package/setup/.codex/.agents/skills/openspec-verify-change/SKILL.md +175 -0
  193. package/setup/.codex/.agents/skills/oss-version-check/SKILL.md +71 -0
  194. package/setup/.codex/.agents/skills/oss-version-check/check_oss_version.py +205 -0
  195. package/setup/.codex/.agents/skills/phase/SKILL.md +63 -0
  196. package/setup/.codex/.agents/skills/playwright/SKILL.md +86 -0
  197. package/setup/.codex/.agents/skills/playwright-cli/SKILL.md +420 -0
  198. package/setup/.codex/.agents/skills/playwright-cli/references/element-attributes.md +23 -0
  199. package/setup/.codex/.agents/skills/playwright-cli/references/playwright-tests.md +39 -0
  200. package/setup/.codex/.agents/skills/playwright-cli/references/references/element-attributes.md +23 -0
  201. package/setup/.codex/.agents/skills/playwright-cli/references/references/playwright-tests.md +39 -0
  202. package/setup/.codex/.agents/skills/playwright-cli/references/references/request-mocking.md +87 -0
  203. package/setup/.codex/.agents/skills/playwright-cli/references/references/running-code.md +241 -0
  204. package/setup/.codex/.agents/skills/playwright-cli/references/references/session-management.md +225 -0
  205. package/setup/.codex/.agents/skills/playwright-cli/references/references/storage-state.md +275 -0
  206. package/setup/.codex/.agents/skills/playwright-cli/references/references/test-generation.md +433 -0
  207. package/setup/.codex/.agents/skills/playwright-cli/references/references/tracing.md +139 -0
  208. package/setup/.codex/.agents/skills/playwright-cli/references/references/video-recording.md +143 -0
  209. package/setup/.codex/.agents/skills/playwright-cli/references/request-mocking.md +87 -0
  210. package/setup/.codex/.agents/skills/playwright-cli/references/running-code.md +241 -0
  211. package/setup/.codex/.agents/skills/playwright-cli/references/session-management.md +225 -0
  212. package/setup/.codex/.agents/skills/playwright-cli/references/storage-state.md +275 -0
  213. package/setup/.codex/.agents/skills/playwright-cli/references/test-generation.md +433 -0
  214. package/setup/.codex/.agents/skills/playwright-cli/references/tracing.md +139 -0
  215. package/setup/.codex/.agents/skills/playwright-cli/references/video-recording.md +143 -0
  216. package/setup/.codex/.agents/skills/review/SKILL.md +98 -0
  217. package/setup/.codex/.agents/skills/review-tools/SKILL.md +76 -0
  218. package/setup/.codex/.agents/skills/subagent-driven-development/SKILL.md +94 -0
  219. package/setup/.codex/.agents/skills/task/SKILL.md +27 -0
  220. package/setup/.codex/.agents/skills/test-driven-development/SKILL.md +320 -0
  221. package/setup/.codex/.agents/skills/test-driven-development/writing-good-tests.md +198 -0
  222. package/setup/.codex/.agents/skills/ui-ux-pro-max/SKILL.md +377 -0
  223. package/setup/.codex/.agents/skills/ui-ux-pro-max/data/charts.csv +26 -0
  224. package/setup/.codex/.agents/skills/ui-ux-pro-max/data/colors.csv +97 -0
  225. package/setup/.codex/.agents/skills/ui-ux-pro-max/data/icons.csv +101 -0
  226. package/setup/.codex/.agents/skills/ui-ux-pro-max/data/landing.csv +31 -0
  227. package/setup/.codex/.agents/skills/ui-ux-pro-max/data/products.csv +97 -0
  228. package/setup/.codex/.agents/skills/ui-ux-pro-max/data/react-performance.csv +45 -0
  229. package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/astro.csv +54 -0
  230. package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
  231. package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
  232. package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
  233. package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
  234. package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
  235. package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
  236. package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
  237. package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/react.csv +54 -0
  238. package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
  239. package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
  240. package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
  241. package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -0
  242. package/setup/.codex/.agents/skills/ui-ux-pro-max/data/styles.csv +68 -0
  243. package/setup/.codex/.agents/skills/ui-ux-pro-max/data/typography.csv +58 -0
  244. package/setup/.codex/.agents/skills/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
  245. package/setup/.codex/.agents/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
  246. package/setup/.codex/.agents/skills/ui-ux-pro-max/data/web-interface.csv +31 -0
  247. package/setup/.codex/.agents/skills/ui-ux-pro-max/scripts/core.py +253 -0
  248. package/setup/.codex/.agents/skills/ui-ux-pro-max/scripts/design_system.py +1067 -0
  249. package/setup/.codex/.agents/skills/ui-ux-pro-max/scripts/search.py +114 -0
  250. package/setup/.codex/.agents/skills/ui-ux-standards/SKILL.md +154 -0
  251. package/setup/.codex/.agents/skills/verification-before-completion/SKILL.md +120 -0
  252. package/setup/.codex/.agents/skills/wiki-read/SKILL.md +190 -0
  253. package/setup/.codex/.agents/skills/writing-plans/SKILL.md +168 -0
  254. package/setup/.codex/.agents/skills/writing-plans/plan-document-reviewer-prompt.md +49 -0
  255. package/setup/.codex/config.toml +10 -0
  256. package/setup/.codex/hooks/log_session.py +92 -0
  257. package/setup/.codex/hooks/review-runner.py +851 -0
  258. package/setup/.codex/hooks/sdlc-codex-hook.cjs +1039 -0
  259. package/setup/.codex/hooks/setup-keys.py +287 -0
  260. package/setup/.codex/hooks.json +121 -0
  261. package/setup/.codex/model-catalog.json +154 -0
  262. package/setup/.codex/project-state.md +103 -0
  263. package/setup/AGENTS.md +722 -0
  264. package/setup/CLAUDE.md +717 -0
  265. package/setup/install.sh +24 -0
  266. package/setup/tests/test_decision_timeout.py +241 -0
  267. package/setup/tests/test_hook_guards.py +357 -0
  268. package/setup/tests/test_sdlc_bootstrap.py +167 -0
  269. package/setup/tests/test_task_manager.py +148 -0
@@ -0,0 +1,24 @@
1
+ #!/bin/bash
2
+ # install.sh - FlowCraft 框架安装工具(薄包装:Node 为唯一安装逻辑源)
3
+ # 用法: ./install.sh [install|init] [--global] [--preset <name|file>] [--quick] [--interactive]
4
+ # 实现见 bin/cli.js 与 lib/(方案A 单实现收敛:本脚本仅探测 node 并转调)
5
+
6
+ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
7
+
8
+ # 探测 Node(>=20),缺失时尝试安装后重试一次
9
+ if ! node --version >/dev/null 2>&1; then
10
+ echo "[运行时] 未检测到 Node.js,尝试安装 Node.js 24 ..."
11
+ if command -v winget >/dev/null 2>&1; then
12
+ winget install -e --id OpenJS.NodeJS.24 --accept-source-agreements --accept-package-agreements >/dev/null 2>&1
13
+ elif command -v brew >/dev/null 2>&1; then
14
+ brew install node@24 >/dev/null 2>&1
15
+ elif command -v apt-get >/dev/null 2>&1; then
16
+ sudo apt-get install -y nodejs >/dev/null 2>&1
17
+ fi
18
+ if ! node --version >/dev/null 2>&1; then
19
+ echo "错误: 未找到 Node.js(>=20),请先安装 https://nodejs.org/ 后重试"
20
+ exit 1
21
+ fi
22
+ fi
23
+
24
+ exec node "$SCRIPT_DIR/bin/cli.js" "$@"
@@ -0,0 +1,241 @@
1
+ """Decision-timeout auto-default tests for PRD R1-R7 (lazy channel).
2
+
3
+ Covers: decision-card parsing (R4), timeout config (R3), pending-marker
4
+ write/cleanup (R4), danger-card exclusion (R2), user-input resolution (R7),
5
+ expired-marker injection on session start (R5), Codex parity (R5/R6).
6
+ """
7
+ import importlib.util
8
+ import json
9
+ import os
10
+ import subprocess
11
+ import sys
12
+ import time
13
+ from pathlib import Path
14
+
15
+ import pytest
16
+
17
+ HOOKS = Path(__file__).resolve().parents[1] / ".claude" / "hooks"
18
+ CODEX_HOOK = Path(__file__).resolve().parents[1] / ".codex" / "hooks" / "sdlc-codex-hook.cjs"
19
+ sys.path.insert(0, str(HOOKS))
20
+
21
+
22
+ def load_hook_module(name, filename):
23
+ """Load a hyphenated hook script as a module for unit tests.
24
+
25
+ Args:
26
+ name: Module name to register.
27
+ filename: Hook file name under the hooks directory.
28
+ Returns:
29
+ The loaded module object.
30
+ """
31
+ spec = importlib.util.spec_from_file_location(name, HOOKS / filename)
32
+ mod = importlib.util.module_from_spec(spec)
33
+ spec.loader.exec_module(mod)
34
+ return mod
35
+
36
+
37
+ stop_check = load_hook_module("stop_check_under_test", "stop-check.py")
38
+
39
+ CARD = (
40
+ "**🧭 决策点 3 | PRD 确认**\n"
41
+ "⏱ 120s 未选择 → 自动按推荐项执行\n\n"
42
+ "**✅ 推荐 · A. 确认 PRD**\n"
43
+ "**选择规则 / Selection rule**: 请选择 A / B。"
44
+ )
45
+
46
+
47
+ def make_project(root):
48
+ """Create a minimal SDLC project skeleton for hook integration tests."""
49
+ (root / ".claude").mkdir(parents=True, exist_ok=True)
50
+ (root / ".claude" / "project-state.md").write_text(
51
+ 'current_phase: P2\ntask_description: "t"\n', encoding="utf-8"
52
+ )
53
+ hooks = root / ".claude" / "hooks"
54
+ hooks.mkdir(exist_ok=True)
55
+ (hooks / "log_session.py").write_text("import sys\nsys.exit(0)\n", encoding="utf-8")
56
+
57
+
58
+ def run_hook(name, payload, cwd):
59
+ """Run a hook script against a fake project via CLAUDE_PROJECT_DIR."""
60
+ env = os.environ.copy()
61
+ env["CLAUDE_PROJECT_DIR"] = str(cwd)
62
+ env.pop("FLOWCRAFT_TASK_ID", None)
63
+ env.pop("FLOWCRAFT_SESSION_ID", None)
64
+ return subprocess.run(
65
+ [sys.executable, str(HOOKS / name)],
66
+ input=payload,
67
+ capture_output=True,
68
+ encoding="utf-8",
69
+ errors="replace",
70
+ cwd=str(cwd),
71
+ env=env,
72
+ timeout=60,
73
+ )
74
+
75
+
76
+ # ---------- R2/R4: decision-card parsing ----------
77
+
78
+ class TestParseDecisionCard:
79
+ def test_card_with_recommendation(self):
80
+ point, rec = stop_check._parse_decision_card(CARD)
81
+ assert point == "PRD 确认"
82
+ assert rec == "A"
83
+
84
+ def test_plain_reply_no_card(self):
85
+ assert stop_check._parse_decision_card("实现完成,无决策。") == ("", "")
86
+
87
+ def test_card_without_recommendation_yields_empty(self):
88
+ """解析不出推荐项 → 不写标记(宁缺勿误执行)。"""
89
+ point, rec = stop_check._parse_decision_card("🧭 决策点 | 测试\n请选择 A / B。")
90
+ assert point == "测试"
91
+ assert rec == ""
92
+
93
+
94
+ # ---------- R3: timeout config ----------
95
+
96
+ class TestReadTimeout:
97
+ def test_default_120(self, tmp_path):
98
+ assert stop_check._read_timeout(tmp_path) == 120
99
+
100
+ def test_value_from_yaml(self, tmp_path):
101
+ (tmp_path / "flowcraft.yaml").write_text("decision_timeout: 30\n", encoding="utf-8")
102
+ assert stop_check._read_timeout(tmp_path) == 30
103
+
104
+
105
+ # ---------- R2/R4/R7: marker lifecycle (integration) ----------
106
+
107
+ class TestMarkerLifecycle:
108
+ def test_card_stop_writes_marker(self, tmp_path):
109
+ make_project(tmp_path)
110
+ p = run_hook("stop-check.py", json.dumps({"last_assistant_message": CARD}), tmp_path)
111
+ assert p.returncode == 0
112
+ data = json.loads((tmp_path / ".claude" / "decision-pending.json").read_text(encoding="utf-8"))
113
+ assert data["point"] == "PRD 确认"
114
+ assert data["recommended"] == "A"
115
+ assert data["timeout"] == 120
116
+ assert data["deadline"] > time.time()
117
+
118
+ def test_danger_card_writes_no_marker(self, tmp_path):
119
+ make_project(tmp_path)
120
+ card = "**🧭 决策点 | 删除确认**\n**✅ 推荐 · A. 删除文件**\n请选择 A / B。"
121
+ run_hook("stop-check.py", json.dumps({"last_assistant_message": card}), tmp_path)
122
+ assert not (tmp_path / ".claude" / "decision-pending.json").exists()
123
+
124
+ def test_non_card_stop_clears_marker(self, tmp_path):
125
+ make_project(tmp_path)
126
+ marker = tmp_path / ".claude" / "decision-pending.json"
127
+ marker.write_text("{}", encoding="utf-8")
128
+ run_hook("stop-check.py", json.dumps({"last_assistant_message": "任务完成。"}), tmp_path)
129
+ assert not marker.exists()
130
+
131
+ def test_user_input_clears_marker(self, tmp_path):
132
+ """R7: 任意用户输入即视为已响应。"""
133
+ make_project(tmp_path)
134
+ marker = tmp_path / ".claude" / "decision-pending.json"
135
+ marker.write_text("{}", encoding="utf-8")
136
+ p = run_hook("user-prompt-submit.py", "A", tmp_path)
137
+ assert p.returncode == 0
138
+ assert not marker.exists()
139
+
140
+
141
+ # ---------- R5: lazy check on session start ----------
142
+
143
+ class TestSessionStartLazyCheck:
144
+ def test_expired_marker_injects_auto_execute(self, tmp_path):
145
+ make_project(tmp_path)
146
+ (tmp_path / ".claude" / "decision-pending.json").write_text(
147
+ json.dumps({"point": "PRD 确认", "recommended": "A", "deadline": int(time.time()) - 1, "timeout": 120}),
148
+ encoding="utf-8",
149
+ )
150
+ p = run_hook("session-start.py", json.dumps({"source": "startup", "session_id": "s"}), tmp_path)
151
+ out = json.loads(p.stdout)
152
+ ctx = out["hookSpecificOutput"]["additionalContext"]
153
+ assert "已超时" in ctx
154
+ assert "PRD 确认" in ctx
155
+
156
+ def test_unexpired_marker_not_injected(self, tmp_path):
157
+ make_project(tmp_path)
158
+ (tmp_path / ".claude" / "decision-pending.json").write_text(
159
+ json.dumps({"point": "PRD 确认", "recommended": "A", "deadline": int(time.time()) + 600, "timeout": 120}),
160
+ encoding="utf-8",
161
+ )
162
+ p = run_hook("session-start.py", json.dumps({"source": "startup", "session_id": "s"}), tmp_path)
163
+ ctx = json.loads(p.stdout)["hookSpecificOutput"]["additionalContext"]
164
+ assert "已超时" not in ctx
165
+
166
+ def test_codex_expired_marker_injects(self, tmp_path):
167
+ """Codex 侧对等:懒检查注入(R5 兜底通道)。"""
168
+ copy_dir = tmp_path / "hookcopy"
169
+ copy_dir.mkdir()
170
+ target = copy_dir / "sdlc-codex-hook.cjs"
171
+ target.write_bytes(CODEX_HOOK.read_bytes())
172
+ proj = tmp_path / "proj"
173
+ proj.mkdir()
174
+ (proj / ".codex").mkdir()
175
+ (proj / ".codex" / "project-state.md").write_text('current_phase: P2\ntask_description: "t"\n', encoding="utf-8")
176
+ (proj / ".codex" / "decision-pending.json").write_text(
177
+ json.dumps({"point": "PRD 确认", "recommended": "A", "deadline": int(time.time()) - 1, "timeout": 120}),
178
+ encoding="utf-8",
179
+ )
180
+ p = subprocess.run(
181
+ ["node", str(target), "session-start"],
182
+ input=json.dumps({"cwd": str(proj), "source": "startup"}),
183
+ capture_output=True,
184
+ encoding="utf-8",
185
+ errors="replace",
186
+ cwd=str(proj),
187
+ timeout=60,
188
+ )
189
+ assert p.returncode == 0
190
+ assert "已超时" in p.stdout
191
+ assert "PRD 确认" in p.stdout
192
+
193
+
194
+ # ---------- R4/R5: Codex marker lifecycle parity ----------
195
+
196
+ def make_codex_project(root):
197
+ """Create a minimal Codex-side SDLC project skeleton."""
198
+ (root / ".codex").mkdir(parents=True, exist_ok=True)
199
+ (root / ".codex" / "project-state.md").write_text(
200
+ 'current_phase: P2\ntask_description: "t"\n', encoding="utf-8"
201
+ )
202
+
203
+
204
+ def run_codex_hook(tmp_path, proj, event, payload):
205
+ """Run a copied codex hook against a fake project (neutral __dirname)."""
206
+ copy_dir = tmp_path / "codexcopy"
207
+ copy_dir.mkdir(exist_ok=True)
208
+ target = copy_dir / "sdlc-codex-hook.cjs"
209
+ if not target.exists():
210
+ target.write_bytes(CODEX_HOOK.read_bytes())
211
+ return subprocess.run(
212
+ ["node", str(target), event],
213
+ input=json.dumps(payload),
214
+ capture_output=True,
215
+ encoding="utf-8",
216
+ errors="replace",
217
+ cwd=str(proj),
218
+ timeout=60,
219
+ )
220
+
221
+
222
+ class TestCodexMarkerLifecycle:
223
+ def test_card_stop_writes_marker(self, tmp_path):
224
+ proj = tmp_path / "proj"
225
+ proj.mkdir()
226
+ make_codex_project(proj)
227
+ p = run_codex_hook(tmp_path, proj, "stop-check", {"cwd": str(proj), "last_assistant_message": CARD})
228
+ assert p.returncode == 0
229
+ data = json.loads((proj / ".codex" / "decision-pending.json").read_text(encoding="utf-8"))
230
+ assert data["point"] == "PRD 确认"
231
+ assert data["recommended"] == "A"
232
+
233
+ def test_non_card_stop_clears_marker(self, tmp_path):
234
+ proj = tmp_path / "proj"
235
+ proj.mkdir()
236
+ make_codex_project(proj)
237
+ marker = proj / ".codex" / "decision-pending.json"
238
+ marker.write_text("{}", encoding="utf-8")
239
+ p = run_codex_hook(tmp_path, proj, "stop-check", {"cwd": str(proj), "last_assistant_message": "任务完成。"})
240
+ assert p.returncode == 0
241
+ assert not marker.exists()
@@ -0,0 +1,357 @@
1
+ """Hook guard tests for PRD R1-R6: payload extraction, phase write guards.
2
+
3
+ Runs the real hook scripts via subprocess with stdin payloads (same shape
4
+ Claude Code sends), asserting exit codes, stderr and state mutations.
5
+ """
6
+ import json
7
+ import os
8
+ import subprocess
9
+ import sys
10
+ from pathlib import Path
11
+
12
+ import pytest
13
+
14
+ HOOKS = Path(__file__).resolve().parents[1] / ".claude" / "hooks"
15
+ sys.path.insert(0, str(HOOKS))
16
+
17
+ import flowcraft_env as fe
18
+
19
+
20
+ def run_hook(name, payload, cwd, extra_env=None):
21
+ """Run a hook script with the given stdin payload from cwd.
22
+
23
+ CLAUDE_PROJECT_DIR pins root resolution to the tmp project so the walk-up
24
+ never escapes into the real user home or the repo's setup template state.
25
+ """
26
+ env = os.environ.copy()
27
+ env["CLAUDE_PROJECT_DIR"] = str(cwd)
28
+ env.pop("FLOWCRAFT_TASK_ID", None)
29
+ env.pop("FLOWCRAFT_SESSION_ID", None)
30
+ if extra_env:
31
+ env.update(extra_env)
32
+ return subprocess.run(
33
+ [sys.executable, str(HOOKS / name)],
34
+ input=payload,
35
+ capture_output=True,
36
+ encoding="utf-8",
37
+ errors="replace",
38
+ cwd=str(cwd),
39
+ env=env,
40
+ timeout=60,
41
+ )
42
+
43
+
44
+ def make_state(root, phase, complexity='"medium"'):
45
+ """Create a minimal project-state.md in tmp root."""
46
+ (root / ".claude").mkdir(parents=True, exist_ok=True)
47
+ (root / ".claude" / "project-state.md").write_text(
48
+ f"current_phase: {phase}\ncomplexity_level: {complexity}\nphase_history: []\n",
49
+ encoding="utf-8",
50
+ )
51
+
52
+
53
+ def edit_payload(file_path, new_string="b"):
54
+ """Realistic PreToolUse payload: file_path nested under tool_input."""
55
+ return json.dumps({
56
+ "tool_name": "Edit",
57
+ "tool_input": {"file_path": file_path, "old_string": "a", "new_string": new_string},
58
+ })
59
+
60
+
61
+ def read_phase(root):
62
+ content = (root / ".claude" / "project-state.md").read_text(encoding="utf-8")
63
+ for line in content.splitlines():
64
+ if line.startswith("current_phase:"):
65
+ return line.split(":", 1)[1].strip()
66
+ return ""
67
+
68
+
69
+ # ---------- R5: extract_nested unit tests ----------
70
+
71
+ class TestExtractNested:
72
+ def test_nested_tool_input(self):
73
+ raw = '{"tool_name":"Edit","tool_input":{"file_path":"C:/a.py"}}'
74
+ assert fe.extract_nested(raw, "file_path") == "C:/a.py"
75
+
76
+ def test_flat_top_level(self):
77
+ raw = '{"file_path":"C:/b.py"}'
78
+ assert fe.extract_nested(raw, "file_path") == "C:/b.py"
79
+
80
+ def test_missing_key_returns_empty(self):
81
+ raw = '{"tool_name":"Edit","tool_input":{"other":1}}'
82
+ assert fe.extract_nested(raw, "file_path") == ""
83
+
84
+ def test_empty_payload(self):
85
+ assert fe.extract_nested("", "file_path") == ""
86
+
87
+ def test_malformed_json_regex_fallback(self):
88
+ raw = 'not json {"tool_input":{"command":"pytest -q"}} tail'
89
+ assert fe.extract_nested(raw, "command") == "pytest -q"
90
+
91
+ def test_bytes_input(self):
92
+ raw = b'{"file_path":"C:/c.py"}'
93
+ assert fe.extract_nested(raw, "file_path") == "C:/c.py"
94
+
95
+ def test_nested_empty_value_falls_to_flat(self):
96
+ raw = '{"tool_input":{"command":""},"command":"pytest"}'
97
+ assert fe.extract_nested(raw, "command") == "pytest"
98
+
99
+
100
+ # ---------- R1: check-phase-write extraction + phase blocks ----------
101
+
102
+ class TestCheckPhaseWrite:
103
+ def test_p1_nested_payload_blocks(self, tmp_path):
104
+ make_state(tmp_path, "P1")
105
+ p = run_hook("check-phase-write.py", edit_payload("C:/x/demo.py"), tmp_path)
106
+ assert p.returncode == 2
107
+ assert "P1阶段禁止" in p.stderr
108
+
109
+ def test_p1_flat_payload_blocks(self, tmp_path):
110
+ make_state(tmp_path, "P1")
111
+ p = run_hook("check-phase-write.py", '{"file_path":"C:/x/demo.py"}', tmp_path)
112
+ assert p.returncode == 2
113
+
114
+ def test_p05_nested_payload_blocks(self, tmp_path):
115
+ make_state(tmp_path, "P0.5")
116
+ p = run_hook("check-phase-write.py", edit_payload("C:/x/demo.py"), tmp_path)
117
+ assert p.returncode == 2
118
+ assert "P0.5" in p.stderr
119
+
120
+ def test_p5_nested_payload_blocks(self, tmp_path):
121
+ make_state(tmp_path, "P5")
122
+ p = run_hook("check-phase-write.py", edit_payload("C:/x/demo.py"), tmp_path)
123
+ assert p.returncode == 2
124
+
125
+ def test_p1_plan_file_allowed(self, tmp_path):
126
+ make_state(tmp_path, "P1")
127
+ p = run_hook("check-phase-write.py", edit_payload("C:/x/plan/t.md"), tmp_path)
128
+ assert p.returncode == 0
129
+
130
+ def test_framework_file_blocked(self, tmp_path):
131
+ """R1: 项目内 .claude 框架文件仍拦(守卫只守本项目,项目内不放开)。"""
132
+ make_state(tmp_path, "P2")
133
+ target = tmp_path / ".claude" / "settings.json"
134
+ p = run_hook("check-phase-write.py", edit_payload(str(target)), tmp_path)
135
+ assert p.returncode == 2
136
+
137
+ def test_user_level_claude_allowed(self, tmp_path):
138
+ """R1: 非项目内的 .claude(如 ~/.claude/plans/ 计划草稿)不归守卫管,放行。"""
139
+ make_state(tmp_path, "P2")
140
+ outside = tmp_path.parent / "fake-home" / ".claude" / "plans" / "draft.md"
141
+ p = run_hook("check-phase-write.py", edit_payload(str(outside)), tmp_path)
142
+ assert p.returncode == 0
143
+
144
+ def test_project_claude_plans_allowed(self, tmp_path):
145
+ """R2: 白名单补 plans/,项目内计划草稿目录放行。"""
146
+ make_state(tmp_path, "P2")
147
+ target = tmp_path / ".claude" / "plans" / "x.md"
148
+ p = run_hook("check-phase-write.py", edit_payload(str(target)), tmp_path)
149
+ assert p.returncode == 0
150
+
151
+ def test_task_state_file_allowed(self, tmp_path):
152
+ """R6: .claude/tasks/*.md editable (multi-task state files)."""
153
+ make_state(tmp_path, "P2")
154
+ p = run_hook("check-phase-write.py", edit_payload("C:/x/.claude/tasks/t1.md"), tmp_path)
155
+ assert p.returncode == 0
156
+
157
+ def test_code_review_report_allowed(self, tmp_path):
158
+ """AI 审查报告是框架规定产物,任意阶段可写(与 prd.md 同类)。"""
159
+ make_state(tmp_path, "P2")
160
+ p = run_hook("check-phase-write.py", edit_payload("C:/x/.claude/code-review-report.md"), tmp_path)
161
+ assert p.returncode == 0
162
+
163
+ def test_missing_state_allows(self, tmp_path):
164
+ """R3 AC1: no state file -> non-SDLC project, allow."""
165
+ (tmp_path / ".claude").mkdir()
166
+ p = run_hook("check-phase-write.py", edit_payload("C:/x/demo.py"), tmp_path)
167
+ assert p.returncode == 0
168
+
169
+ def test_no_file_path_allows(self, tmp_path):
170
+ make_state(tmp_path, "P1")
171
+ p = run_hook("check-phase-write.py", '{"tool_name":"Edit","tool_input":{"other":1}}', tmp_path)
172
+ assert p.returncode == 0
173
+
174
+
175
+ # ---------- R2: P0 write blocked + auto-transition to P1 ----------
176
+
177
+ class TestP0Behavior:
178
+ def test_p0_code_write_blocks_and_transitions(self, tmp_path):
179
+ make_state(tmp_path, "P0")
180
+ p = run_hook("check-phase-write.py", edit_payload("C:/x/demo.py"), tmp_path)
181
+ assert p.returncode == 2
182
+ assert read_phase(tmp_path) == "P1"
183
+
184
+ def test_p0_bash_write_blocks_and_transitions(self, tmp_path):
185
+ make_state(tmp_path, "P0")
186
+ payload = json.dumps({"tool_name": "Bash", "tool_input": {"command": "echo x > C:/x/demo.py"}})
187
+ p = run_hook("check-phase-test.py", payload, tmp_path)
188
+ assert p.returncode == 2
189
+ assert read_phase(tmp_path) == "P1"
190
+
191
+
192
+ # ---------- R3: get_project_root strict walk-up ----------
193
+
194
+ class TestGetProjectRoot:
195
+ def test_finds_project_by_state_file(self, tmp_path):
196
+ make_state(tmp_path, "P0")
197
+ sub = tmp_path / "sub"
198
+ sub.mkdir()
199
+ # cwd changed via subprocess-free direct call with monkeypatched cwd
200
+ import flowcraft_env
201
+ saved = os.getcwd()
202
+ try:
203
+ os.chdir(str(sub))
204
+ assert flowcraft_env.get_project_root() == tmp_path.resolve()
205
+ finally:
206
+ os.chdir(saved)
207
+
208
+ def test_skips_non_empty_claude_without_state(self, tmp_path):
209
+ """A non-empty .claude dir without state (e.g. user-level) is skipped;
210
+ the walk continues to the real state-bearing ancestor."""
211
+ make_state(tmp_path, "P0")
212
+ fake_home = tmp_path / "home"
213
+ (fake_home / ".claude").mkdir(parents=True)
214
+ (fake_home / ".claude" / "settings.json").write_text("{}", encoding="utf-8")
215
+ sub = fake_home / "sub"
216
+ sub.mkdir()
217
+ import flowcraft_env
218
+ saved = os.getcwd()
219
+ try:
220
+ os.chdir(str(sub))
221
+ # walk: sub -> fake_home (non-empty .claude, no state -> skip) -> tmp (state)
222
+ assert flowcraft_env.get_project_root() == tmp_path.resolve()
223
+ finally:
224
+ os.chdir(saved)
225
+
226
+ def test_home_state_never_project_root(self, tmp_path, monkeypatch):
227
+ """R3 AC2: a state-bearing user home must not become the project root."""
228
+ fake_home = tmp_path / "home"
229
+ make_state(fake_home, "P1")
230
+ sub = fake_home / "sub"
231
+ sub.mkdir()
232
+ import flowcraft_env
233
+ monkeypatch.setattr(flowcraft_env.Path, "home", classmethod(lambda cls: fake_home))
234
+ saved = os.getcwd()
235
+ try:
236
+ os.chdir(str(sub))
237
+ # walk: sub -> home (state-bearing ancestor that IS the user home -> skipped)
238
+ root = flowcraft_env.get_project_root()
239
+ assert root != fake_home
240
+ finally:
241
+ os.chdir(saved)
242
+
243
+ def test_home_as_cwd_allowed(self, tmp_path, monkeypatch):
244
+ """R3 AC2 exception: when cwd IS the home dir, its state may match."""
245
+ fake_home = tmp_path / "home"
246
+ make_state(fake_home, "P1")
247
+ import flowcraft_env
248
+ monkeypatch.setattr(flowcraft_env.Path, "home", classmethod(lambda cls: fake_home))
249
+ saved = os.getcwd()
250
+ try:
251
+ os.chdir(str(fake_home))
252
+ assert flowcraft_env.get_project_root() == fake_home.resolve()
253
+ finally:
254
+ os.chdir(saved)
255
+
256
+ def test_env_var_priority(self, tmp_path):
257
+ make_state(tmp_path, "P0")
258
+ import flowcraft_env
259
+ saved = os.environ.get("CLAUDE_PROJECT_DIR")
260
+ os.environ["CLAUDE_PROJECT_DIR"] = str(tmp_path)
261
+ try:
262
+ assert flowcraft_env.get_project_root() == tmp_path.resolve()
263
+ finally:
264
+ if saved is None:
265
+ os.environ.pop("CLAUDE_PROJECT_DIR", None)
266
+ else:
267
+ os.environ["CLAUDE_PROJECT_DIR"] = saved
268
+
269
+
270
+ # ---------- R4: advancement supports P0.5 ----------
271
+
272
+ def adv_payload(state_path, old_phase, new_phase):
273
+ return json.dumps({
274
+ "tool_name": "Edit",
275
+ "tool_input": {
276
+ "file_path": str(state_path).replace("\\", "/"),
277
+ "old_string": f"current_phase: {old_phase}",
278
+ "new_string": f"current_phase: {new_phase}",
279
+ },
280
+ })
281
+
282
+
283
+ class TestAdvancementP05:
284
+ def _state(self, tmp_path, phase):
285
+ make_state(tmp_path, phase)
286
+ return tmp_path / ".claude" / "project-state.md"
287
+
288
+ def test_p2_to_p05_allowed(self, tmp_path):
289
+ state = self._state(tmp_path, "P2")
290
+ p = run_hook(
291
+ "check-phase-advancement.py",
292
+ adv_payload(state, "P2", "P0.5"),
293
+ tmp_path,
294
+ extra_env={"CLAUDE_PROJECT_DIR": str(tmp_path)},
295
+ )
296
+ assert p.returncode == 0, p.stdout
297
+
298
+ def test_p2_to_p3_still_allowed(self, tmp_path):
299
+ state = self._state(tmp_path, "P2")
300
+ p = run_hook(
301
+ "check-phase-advancement.py",
302
+ adv_payload(state, "P2", "P3"),
303
+ tmp_path,
304
+ extra_env={"CLAUDE_PROJECT_DIR": str(tmp_path)},
305
+ )
306
+ assert p.returncode == 0, p.stdout
307
+
308
+ def test_p2_to_p4_still_denied(self, tmp_path):
309
+ state = self._state(tmp_path, "P2")
310
+ p = run_hook(
311
+ "check-phase-advancement.py",
312
+ adv_payload(state, "P2", "P4"),
313
+ tmp_path,
314
+ extra_env={"CLAUDE_PROJECT_DIR": str(tmp_path)},
315
+ )
316
+ assert p.returncode == 1
317
+
318
+
319
+ # ---------- R5: permission-request migration keeps behavior ----------
320
+
321
+ class TestPermissionRequest:
322
+ def test_write_py_in_p1_denies(self, tmp_path):
323
+ make_state(tmp_path, "P1")
324
+ p = run_hook(
325
+ "permission-request.py",
326
+ edit_payload("C:/x/demo.py"),
327
+ tmp_path,
328
+ extra_env={"CLAUDE_PROJECT_DIR": str(tmp_path)},
329
+ )
330
+ assert p.returncode == 0
331
+ out = json.loads(p.stdout)
332
+ assert out["hookSpecificOutput"]["decision"]["behavior"] == "deny"
333
+
334
+ def test_write_md_in_p1_allows(self, tmp_path):
335
+ make_state(tmp_path, "P1")
336
+ p = run_hook(
337
+ "permission-request.py",
338
+ edit_payload("C:/x/readme.md"),
339
+ tmp_path,
340
+ extra_env={"CLAUDE_PROJECT_DIR": str(tmp_path)},
341
+ )
342
+ assert p.returncode == 0
343
+ out = json.loads(p.stdout)
344
+ assert out["hookSpecificOutput"]["decision"]["behavior"] == "allow"
345
+
346
+ def test_bash_git_commit_in_p2_denies(self, tmp_path):
347
+ make_state(tmp_path, "P2")
348
+ payload = json.dumps({"tool_name": "Bash", "tool_input": {"command": "git commit -m x"}})
349
+ p = run_hook(
350
+ "permission-request.py",
351
+ payload,
352
+ tmp_path,
353
+ extra_env={"CLAUDE_PROJECT_DIR": str(tmp_path)},
354
+ )
355
+ assert p.returncode == 0
356
+ out = json.loads(p.stdout)
357
+ assert out["hookSpecificOutput"]["decision"]["behavior"] == "deny"