prizmkit 1.1.100 → 1.1.101

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 (309) hide show
  1. package/bin/create-prizmkit.js +4 -4
  2. package/bundled/VERSION.json +3 -3
  3. package/bundled/dev-pipeline/.env.example +3 -3
  4. package/bundled/dev-pipeline/README.md +110 -90
  5. package/bundled/dev-pipeline/assets/prizm-dev-team-integration.md +1 -1
  6. package/bundled/dev-pipeline/cli.py +27 -0
  7. package/bundled/dev-pipeline/prizmkit_runtime/__init__.py +13 -0
  8. package/bundled/dev-pipeline/prizmkit_runtime/__main__.py +9 -0
  9. package/bundled/dev-pipeline/prizmkit_runtime/cli.py +193 -0
  10. package/bundled/dev-pipeline/prizmkit_runtime/commands.py +313 -0
  11. package/bundled/dev-pipeline/prizmkit_runtime/compat.py +32 -0
  12. package/bundled/dev-pipeline/prizmkit_runtime/config.py +410 -0
  13. package/bundled/dev-pipeline/prizmkit_runtime/daemon.py +478 -0
  14. package/bundled/dev-pipeline/prizmkit_runtime/gitops.py +734 -0
  15. package/bundled/dev-pipeline/prizmkit_runtime/heartbeat.py +256 -0
  16. package/bundled/dev-pipeline/prizmkit_runtime/interoperability.py +109 -0
  17. package/bundled/dev-pipeline/prizmkit_runtime/paths.py +110 -0
  18. package/bundled/dev-pipeline/prizmkit_runtime/processes.py +373 -0
  19. package/bundled/dev-pipeline/prizmkit_runtime/reset.py +389 -0
  20. package/bundled/dev-pipeline/prizmkit_runtime/runner_bookkeeping.py +51 -0
  21. package/bundled/dev-pipeline/prizmkit_runtime/runner_classification.py +179 -0
  22. package/bundled/dev-pipeline/prizmkit_runtime/runner_models.py +345 -0
  23. package/bundled/dev-pipeline/prizmkit_runtime/runner_prompts.py +118 -0
  24. package/bundled/dev-pipeline/prizmkit_runtime/runner_recovery.py +187 -0
  25. package/bundled/dev-pipeline/prizmkit_runtime/runner_status.py +147 -0
  26. package/bundled/dev-pipeline/prizmkit_runtime/runners.py +422 -0
  27. package/bundled/dev-pipeline/prizmkit_runtime/sessions.py +552 -0
  28. package/bundled/dev-pipeline/prizmkit_runtime/status.py +71 -0
  29. package/bundled/dev-pipeline/scripts/generate-bootstrap-prompt.py +38 -23
  30. package/bundled/dev-pipeline/scripts/generate-bugfix-prompt.py +20 -5
  31. package/bundled/dev-pipeline/scripts/generate-recovery-prompt.py +2 -2
  32. package/bundled/dev-pipeline/scripts/parse-stream-progress.py +39 -0
  33. package/bundled/dev-pipeline/templates/agent-prompts/dev-implement.md +7 -1
  34. package/bundled/dev-pipeline/templates/bootstrap-prompt.md +4 -0
  35. package/bundled/dev-pipeline/templates/bootstrap-tier1.md +12 -3
  36. package/bundled/dev-pipeline/templates/bootstrap-tier2.md +13 -3
  37. package/bundled/dev-pipeline/templates/bootstrap-tier3.md +13 -3
  38. package/bundled/dev-pipeline/templates/sections/context-budget-rules.md +2 -0
  39. package/bundled/dev-pipeline/templates/sections/log-size-awareness.md +9 -30
  40. package/bundled/dev-pipeline/templates/sections/phase-context-snapshot-agent-suffix.md +15 -7
  41. package/bundled/dev-pipeline/templates/sections/phase-implement-agent.md +42 -29
  42. package/bundled/dev-pipeline/templates/sections/phase-implement-full.md +41 -39
  43. package/bundled/dev-pipeline/templates/sections/test-failure-recovery-agent.md +4 -0
  44. package/bundled/dev-pipeline/templates/sections/test-failure-recovery-lite.md +4 -0
  45. package/bundled/dev-pipeline/tests/test_auto_skip.py +436 -14
  46. package/bundled/dev-pipeline/tests/test_generate_bootstrap_prompt.py +104 -0
  47. package/bundled/dev-pipeline/tests/test_generate_bugfix_prompt.py +40 -0
  48. package/bundled/dev-pipeline/tests/test_python_runner_parity.py +1138 -0
  49. package/bundled/dev-pipeline/tests/test_unified_cli.py +1045 -0
  50. package/bundled/skills/_metadata.json +1 -1
  51. package/bundled/skills/bugfix-pipeline-launcher/SKILL.md +29 -34
  52. package/bundled/skills/bugfix-pipeline-launcher/references/configuration.md +6 -5
  53. package/bundled/skills/feature-pipeline-launcher/SKILL.md +29 -35
  54. package/bundled/skills/feature-pipeline-launcher/references/configuration.md +7 -6
  55. package/bundled/skills/feature-workflow/SKILL.md +3 -6
  56. package/bundled/skills/recovery-workflow/SKILL.md +23 -32
  57. package/bundled/skills/refactor-pipeline-launcher/SKILL.md +29 -35
  58. package/bundled/skills/refactor-pipeline-launcher/references/configuration.md +7 -6
  59. package/bundled/skills/refactor-workflow/SKILL.md +3 -6
  60. package/bundled/templates/hooks/commit-intent.json +2 -2
  61. package/bundled/templates/hooks/diff-prizm-docs.py +226 -0
  62. package/bundled/templates/hooks/prizm-pre-commit.py +45 -0
  63. package/bundled/templates/hooks/validate-prizm-docs.py +240 -0
  64. package/package.json +1 -1
  65. package/src/config.js +33 -12
  66. package/src/index.js +3 -6
  67. package/src/manifest.js +3 -2
  68. package/src/metadata.js +7 -18
  69. package/src/prompts.js +0 -12
  70. package/src/runtimes.js +18 -11
  71. package/src/scaffold.js +133 -116
  72. package/src/upgrade.js +1 -1
  73. package/bundled/dev-pipeline/launch-bugfix-daemon.sh +0 -500
  74. package/bundled/dev-pipeline/launch-feature-daemon.sh +0 -657
  75. package/bundled/dev-pipeline/launch-refactor-daemon.sh +0 -502
  76. package/bundled/dev-pipeline/lib/branch.sh +0 -326
  77. package/bundled/dev-pipeline/lib/common.sh +0 -1476
  78. package/bundled/dev-pipeline/lib/heartbeat.sh +0 -469
  79. package/bundled/dev-pipeline/reset-bug.sh +0 -425
  80. package/bundled/dev-pipeline/reset-feature.sh +0 -436
  81. package/bundled/dev-pipeline/reset-refactor.sh +0 -423
  82. package/bundled/dev-pipeline/run-bugfix.sh +0 -1430
  83. package/bundled/dev-pipeline/run-feature.sh +0 -1718
  84. package/bundled/dev-pipeline/run-recovery.sh +0 -648
  85. package/bundled/dev-pipeline/run-refactor.sh +0 -1463
  86. package/bundled/dev-pipeline/tests/test-path-resolution.sh +0 -100
  87. package/bundled/dev-pipeline-windows/.env.example +0 -36
  88. package/bundled/dev-pipeline-windows/README.md +0 -30
  89. package/bundled/dev-pipeline-windows/SCHEMA_ANALYSIS.md +0 -533
  90. package/bundled/dev-pipeline-windows/assets/feature-list-example.json +0 -146
  91. package/bundled/dev-pipeline-windows/assets/prizm-dev-team-integration.md +0 -137
  92. package/bundled/dev-pipeline-windows/launch-bugfix-daemon.ps1 +0 -9
  93. package/bundled/dev-pipeline-windows/launch-feature-daemon.ps1 +0 -9
  94. package/bundled/dev-pipeline-windows/launch-refactor-daemon.ps1 +0 -9
  95. package/bundled/dev-pipeline-windows/lib/branch.ps1 +0 -235
  96. package/bundled/dev-pipeline-windows/lib/common.ps1 +0 -991
  97. package/bundled/dev-pipeline-windows/lib/daemon.ps1 +0 -140
  98. package/bundled/dev-pipeline-windows/lib/pipeline.ps1 +0 -1051
  99. package/bundled/dev-pipeline-windows/lib/reset.ps1 +0 -121
  100. package/bundled/dev-pipeline-windows/reset-bug.ps1 +0 -10
  101. package/bundled/dev-pipeline-windows/reset-feature.ps1 +0 -10
  102. package/bundled/dev-pipeline-windows/reset-refactor.ps1 +0 -10
  103. package/bundled/dev-pipeline-windows/run-bugfix.ps1 +0 -9
  104. package/bundled/dev-pipeline-windows/run-feature.ps1 +0 -9
  105. package/bundled/dev-pipeline-windows/run-recovery.ps1 +0 -179
  106. package/bundled/dev-pipeline-windows/run-refactor.ps1 +0 -9
  107. package/bundled/dev-pipeline-windows/scripts/check-session-status.py +0 -301
  108. package/bundled/dev-pipeline-windows/scripts/continuation.py +0 -374
  109. package/bundled/dev-pipeline-windows/scripts/detect-stuck.py +0 -530
  110. package/bundled/dev-pipeline-windows/scripts/generate-bootstrap-prompt.py +0 -2279
  111. package/bundled/dev-pipeline-windows/scripts/generate-bugfix-prompt.py +0 -763
  112. package/bundled/dev-pipeline-windows/scripts/generate-recovery-prompt.py +0 -805
  113. package/bundled/dev-pipeline-windows/scripts/generate-refactor-prompt.py +0 -841
  114. package/bundled/dev-pipeline-windows/scripts/init-bugfix-pipeline.py +0 -316
  115. package/bundled/dev-pipeline-windows/scripts/init-dev-team.py +0 -134
  116. package/bundled/dev-pipeline-windows/scripts/init-pipeline.py +0 -382
  117. package/bundled/dev-pipeline-windows/scripts/init-refactor-pipeline.py +0 -399
  118. package/bundled/dev-pipeline-windows/scripts/parse-stream-progress.py +0 -1362
  119. package/bundled/dev-pipeline-windows/scripts/patch-completion-notes.py +0 -191
  120. package/bundled/dev-pipeline-windows/scripts/prizmkit-test-gate.py +0 -446
  121. package/bundled/dev-pipeline-windows/scripts/update-bug-status.py +0 -1121
  122. package/bundled/dev-pipeline-windows/scripts/update-checkpoint.py +0 -173
  123. package/bundled/dev-pipeline-windows/scripts/update-feature-status.py +0 -1789
  124. package/bundled/dev-pipeline-windows/scripts/update-refactor-status.py +0 -1327
  125. package/bundled/dev-pipeline-windows/scripts/utils.py +0 -542
  126. package/bundled/dev-pipeline-windows/templates/agent-prompts/critic-plan-challenge.md +0 -7
  127. package/bundled/dev-pipeline-windows/templates/agent-prompts/dev-fix.md +0 -7
  128. package/bundled/dev-pipeline-windows/templates/agent-prompts/dev-implement.md +0 -65
  129. package/bundled/dev-pipeline-windows/templates/agent-prompts/dev-resume.md +0 -5
  130. package/bundled/dev-pipeline-windows/templates/agent-prompts/reviewer-review.md +0 -7
  131. package/bundled/dev-pipeline-windows/templates/bootstrap-prompt.md +0 -73
  132. package/bundled/dev-pipeline-windows/templates/bootstrap-tier1.md +0 -589
  133. package/bundled/dev-pipeline-windows/templates/bootstrap-tier2.md +0 -710
  134. package/bundled/dev-pipeline-windows/templates/bootstrap-tier3.md +0 -791
  135. package/bundled/dev-pipeline-windows/templates/bug-fix-list-schema.json +0 -263
  136. package/bundled/dev-pipeline-windows/templates/bugfix-bootstrap-prompt.md +0 -326
  137. package/bundled/dev-pipeline-windows/templates/feature-list-schema.json +0 -237
  138. package/bundled/dev-pipeline-windows/templates/refactor-bootstrap-prompt.md +0 -340
  139. package/bundled/dev-pipeline-windows/templates/refactor-list-schema.json +0 -270
  140. package/bundled/dev-pipeline-windows/templates/sections/ac-verification-checklist.md +0 -7
  141. package/bundled/dev-pipeline-windows/templates/sections/checkpoint-system.md +0 -91
  142. package/bundled/dev-pipeline-windows/templates/sections/context-budget-rules.md +0 -34
  143. package/bundled/dev-pipeline-windows/templates/sections/critical-paths-agent.md +0 -10
  144. package/bundled/dev-pipeline-windows/templates/sections/critical-paths-full.md +0 -12
  145. package/bundled/dev-pipeline-windows/templates/sections/critical-paths-lite.md +0 -7
  146. package/bundled/dev-pipeline-windows/templates/sections/directory-convention-agent.md +0 -8
  147. package/bundled/dev-pipeline-windows/templates/sections/directory-convention-full.md +0 -9
  148. package/bundled/dev-pipeline-windows/templates/sections/directory-convention-lite.md +0 -6
  149. package/bundled/dev-pipeline-windows/templates/sections/failure-capture.md +0 -21
  150. package/bundled/dev-pipeline-windows/templates/sections/feature-context.md +0 -21
  151. package/bundled/dev-pipeline-windows/templates/sections/log-size-awareness.md +0 -41
  152. package/bundled/dev-pipeline-windows/templates/sections/phase-browser-verification-auto.md +0 -283
  153. package/bundled/dev-pipeline-windows/templates/sections/phase-browser-verification-opencli.md +0 -112
  154. package/bundled/dev-pipeline-windows/templates/sections/phase-browser-verification.md +0 -168
  155. package/bundled/dev-pipeline-windows/templates/sections/phase-commit-full.md +0 -82
  156. package/bundled/dev-pipeline-windows/templates/sections/phase-commit.md +0 -75
  157. package/bundled/dev-pipeline-windows/templates/sections/phase-context-snapshot-agent-suffix.md +0 -23
  158. package/bundled/dev-pipeline-windows/templates/sections/phase-context-snapshot-base.md +0 -14
  159. package/bundled/dev-pipeline-windows/templates/sections/phase-context-snapshot-lite-suffix.md +0 -19
  160. package/bundled/dev-pipeline-windows/templates/sections/phase-critic-plan-full.md +0 -63
  161. package/bundled/dev-pipeline-windows/templates/sections/phase-critic-plan.md +0 -42
  162. package/bundled/dev-pipeline-windows/templates/sections/phase-implement-agent.md +0 -44
  163. package/bundled/dev-pipeline-windows/templates/sections/phase-implement-full.md +0 -59
  164. package/bundled/dev-pipeline-windows/templates/sections/phase-implement-lite.md +0 -39
  165. package/bundled/dev-pipeline-windows/templates/sections/phase-plan-agent.md +0 -27
  166. package/bundled/dev-pipeline-windows/templates/sections/phase-plan-lite.md +0 -27
  167. package/bundled/dev-pipeline-windows/templates/sections/phase-prizmkit-test.md +0 -39
  168. package/bundled/dev-pipeline-windows/templates/sections/phase-review-agent.md +0 -35
  169. package/bundled/dev-pipeline-windows/templates/sections/phase-review-full.md +0 -35
  170. package/bundled/dev-pipeline-windows/templates/sections/phase-specify-plan-full.md +0 -73
  171. package/bundled/dev-pipeline-windows/templates/sections/phase0-init.md +0 -13
  172. package/bundled/dev-pipeline-windows/templates/sections/phase0-test-baseline.md +0 -21
  173. package/bundled/dev-pipeline-windows/templates/sections/session-context.md +0 -5
  174. package/bundled/dev-pipeline-windows/templates/sections/subagent-timeout-recovery.md +0 -6
  175. package/bundled/dev-pipeline-windows/templates/sections/task-contract.md +0 -34
  176. package/bundled/dev-pipeline-windows/templates/sections/test-failure-recovery-agent.md +0 -48
  177. package/bundled/dev-pipeline-windows/templates/sections/test-failure-recovery-lite.md +0 -48
  178. package/bundled/dev-pipeline-windows/templates/session-status-schema.json +0 -83
  179. package/bundled/skills-windows/app-planner/SKILL.md +0 -296
  180. package/bundled/skills-windows/app-planner/assets/app-design-guide.md +0 -101
  181. package/bundled/skills-windows/app-planner/references/architecture-decisions.md +0 -52
  182. package/bundled/skills-windows/app-planner/references/brainstorm-guide.md +0 -101
  183. package/bundled/skills-windows/app-planner/references/frontend-design-guide.md +0 -71
  184. package/bundled/skills-windows/app-planner/references/infrastructure-convention-discovery.md +0 -108
  185. package/bundled/skills-windows/app-planner/references/project-brief-guide.md +0 -82
  186. package/bundled/skills-windows/app-planner/references/project-conventions-discovery.md +0 -59
  187. package/bundled/skills-windows/app-planner/references/project-state-detection.md +0 -90
  188. package/bundled/skills-windows/app-planner/references/red-team-checklist.md +0 -40
  189. package/bundled/skills-windows/app-planner/references/rules/backend/derivation-rules.md +0 -619
  190. package/bundled/skills-windows/app-planner/references/rules/backend/fixed-rules.md +0 -285
  191. package/bundled/skills-windows/app-planner/references/rules/backend/question-bank.md +0 -249
  192. package/bundled/skills-windows/app-planner/references/rules/backend/question-manifest.json +0 -46
  193. package/bundled/skills-windows/app-planner/references/rules/backend/template.md +0 -173
  194. package/bundled/skills-windows/app-planner/references/rules/database/derivation-rules.md +0 -382
  195. package/bundled/skills-windows/app-planner/references/rules/database/fixed-rules.md +0 -211
  196. package/bundled/skills-windows/app-planner/references/rules/database/question-bank.md +0 -184
  197. package/bundled/skills-windows/app-planner/references/rules/database/question-manifest.json +0 -39
  198. package/bundled/skills-windows/app-planner/references/rules/database/template.md +0 -158
  199. package/bundled/skills-windows/app-planner/references/rules/frontend/derivation-rules.md +0 -820
  200. package/bundled/skills-windows/app-planner/references/rules/frontend/fixed-rules.md +0 -188
  201. package/bundled/skills-windows/app-planner/references/rules/frontend/question-bank.md +0 -319
  202. package/bundled/skills-windows/app-planner/references/rules/frontend/question-manifest.json +0 -51
  203. package/bundled/skills-windows/app-planner/references/rules/frontend/template.md +0 -339
  204. package/bundled/skills-windows/app-planner/references/rules/mobile/derivation-rules.md +0 -649
  205. package/bundled/skills-windows/app-planner/references/rules/mobile/fixed-rules.md +0 -290
  206. package/bundled/skills-windows/app-planner/references/rules/mobile/question-bank.md +0 -232
  207. package/bundled/skills-windows/app-planner/references/rules/mobile/question-manifest.json +0 -47
  208. package/bundled/skills-windows/app-planner/references/rules/mobile/template.md +0 -175
  209. package/bundled/skills-windows/app-planner/references/rules-configuration.md +0 -46
  210. package/bundled/skills-windows/bug-fix-workflow/SKILL.md +0 -379
  211. package/bundled/skills-windows/bug-fix-workflow/references/bug-diagnosis.md +0 -41
  212. package/bundled/skills-windows/bug-planner/SKILL.md +0 -402
  213. package/bundled/skills-windows/bug-planner/assets/bug-confirmation-template.md +0 -43
  214. package/bundled/skills-windows/bug-planner/references/critic-and-verification.md +0 -44
  215. package/bundled/skills-windows/bug-planner/references/error-recovery.md +0 -73
  216. package/bundled/skills-windows/bug-planner/references/input-formats.md +0 -53
  217. package/bundled/skills-windows/bug-planner/references/schema-validation.md +0 -25
  218. package/bundled/skills-windows/bug-planner/references/severity-rules.md +0 -16
  219. package/bundled/skills-windows/bug-planner/scripts/validate-bug-list.py +0 -322
  220. package/bundled/skills-windows/bugfix-pipeline-launcher/SKILL.md +0 -304
  221. package/bundled/skills-windows/bugfix-pipeline-launcher/references/configuration.md +0 -84
  222. package/bundled/skills-windows/feature-pipeline-launcher/SKILL.md +0 -381
  223. package/bundled/skills-windows/feature-pipeline-launcher/references/configuration.md +0 -67
  224. package/bundled/skills-windows/feature-pipeline-launcher/scripts/preflight-check.py +0 -462
  225. package/bundled/skills-windows/feature-planner/SKILL.md +0 -397
  226. package/bundled/skills-windows/feature-planner/assets/evaluation-guide.md +0 -64
  227. package/bundled/skills-windows/feature-planner/assets/planning-guide.md +0 -214
  228. package/bundled/skills-windows/feature-planner/references/browser-interaction.md +0 -59
  229. package/bundled/skills-windows/feature-planner/references/completeness-review.md +0 -57
  230. package/bundled/skills-windows/feature-planner/references/decomposition-patterns.md +0 -75
  231. package/bundled/skills-windows/feature-planner/references/error-recovery.md +0 -90
  232. package/bundled/skills-windows/feature-planner/references/incremental-feature-planning.md +0 -112
  233. package/bundled/skills-windows/feature-planner/references/new-project-planning.md +0 -85
  234. package/bundled/skills-windows/feature-planner/scripts/validate-and-generate.py +0 -1020
  235. package/bundled/skills-windows/feature-workflow/SKILL.md +0 -374
  236. package/bundled/skills-windows/feature-workflow/references/brainstorm-guide.md +0 -137
  237. package/bundled/skills-windows/prizm-kit/SKILL.md +0 -93
  238. package/bundled/skills-windows/prizmkit-code-review/SKILL.md +0 -161
  239. package/bundled/skills-windows/prizmkit-code-review/references/dev-agent-prompt.md +0 -30
  240. package/bundled/skills-windows/prizmkit-code-review/references/review-report-template.md +0 -31
  241. package/bundled/skills-windows/prizmkit-code-review/references/reviewer-agent-prompt.md +0 -66
  242. package/bundled/skills-windows/prizmkit-code-review/scripts/check_loop.py +0 -186
  243. package/bundled/skills-windows/prizmkit-committer/SKILL.md +0 -89
  244. package/bundled/skills-windows/prizmkit-deploy/SKILL.md +0 -444
  245. package/bundled/skills-windows/prizmkit-deploy/references/ci-cd-workflows.md +0 -115
  246. package/bundled/skills-windows/prizmkit-deploy/references/cloud-platform-deploy.md +0 -93
  247. package/bundled/skills-windows/prizmkit-deploy/references/data-safety-examples.md +0 -120
  248. package/bundled/skills-windows/prizmkit-deploy/references/database-setup.md +0 -46
  249. package/bundled/skills-windows/prizmkit-deploy/references/deploy-config-schema.md +0 -148
  250. package/bundled/skills-windows/prizmkit-deploy/references/deploy-history-schema.md +0 -62
  251. package/bundled/skills-windows/prizmkit-deploy/references/deployment-modes.md +0 -50
  252. package/bundled/skills-windows/prizmkit-deploy/references/direct-upload.md +0 -26
  253. package/bundled/skills-windows/prizmkit-deploy/references/dns-setup.md +0 -42
  254. package/bundled/skills-windows/prizmkit-deploy/references/docker-deploy.md +0 -31
  255. package/bundled/skills-windows/prizmkit-deploy/references/firewall-setup.md +0 -37
  256. package/bundled/skills-windows/prizmkit-deploy/references/live-validation-notes.md +0 -21
  257. package/bundled/skills-windows/prizmkit-deploy/references/nginx-blue-green.md +0 -59
  258. package/bundled/skills-windows/prizmkit-deploy/references/ssh-bootstrap-flow.md +0 -49
  259. package/bundled/skills-windows/prizmkit-deploy/references/ssh-execution-flow.md +0 -41
  260. package/bundled/skills-windows/prizmkit-deploy/references/ssh-takeover.md +0 -20
  261. package/bundled/skills-windows/prizmkit-deploy/references/ssl-setup.md +0 -56
  262. package/bundled/skills-windows/prizmkit-implement/SKILL.md +0 -71
  263. package/bundled/skills-windows/prizmkit-init/SKILL.md +0 -356
  264. package/bundled/skills-windows/prizmkit-init/assets/project-brief-template.md +0 -82
  265. package/bundled/skills-windows/prizmkit-init/references/config-schema.md +0 -70
  266. package/bundled/skills-windows/prizmkit-init/references/rules/layer-detection.md +0 -41
  267. package/bundled/skills-windows/prizmkit-init/references/tech-stack-catalog.md +0 -13
  268. package/bundled/skills-windows/prizmkit-init/references/update-supplement.md +0 -9
  269. package/bundled/skills-windows/prizmkit-plan/SKILL.md +0 -102
  270. package/bundled/skills-windows/prizmkit-plan/assets/plan-template.md +0 -115
  271. package/bundled/skills-windows/prizmkit-plan/assets/spec-template.md +0 -73
  272. package/bundled/skills-windows/prizmkit-plan/references/clarify-guide.md +0 -67
  273. package/bundled/skills-windows/prizmkit-plan/references/examples.md +0 -85
  274. package/bundled/skills-windows/prizmkit-plan/references/verification-checklist.md +0 -60
  275. package/bundled/skills-windows/prizmkit-prizm-docs/SKILL.md +0 -129
  276. package/bundled/skills-windows/prizmkit-prizm-docs/assets/prizm-docs-format.md +0 -613
  277. package/bundled/skills-windows/prizmkit-prizm-docs/references/op-init.md +0 -45
  278. package/bundled/skills-windows/prizmkit-prizm-docs/references/op-rebuild.md +0 -15
  279. package/bundled/skills-windows/prizmkit-prizm-docs/references/op-status.md +0 -14
  280. package/bundled/skills-windows/prizmkit-prizm-docs/references/op-update.md +0 -19
  281. package/bundled/skills-windows/prizmkit-prizm-docs/references/op-validate.md +0 -17
  282. package/bundled/skills-windows/prizmkit-retrospective/SKILL.md +0 -87
  283. package/bundled/skills-windows/prizmkit-retrospective/references/knowledge-injection-steps.md +0 -50
  284. package/bundled/skills-windows/prizmkit-retrospective/references/structural-sync-steps.md +0 -43
  285. package/bundled/skills-windows/prizmkit-test/SKILL.md +0 -227
  286. package/bundled/skills-windows/prizmkit-test/references/boundary-coverage-protocol.md +0 -220
  287. package/bundled/skills-windows/prizmkit-test/references/examples.md +0 -143
  288. package/bundled/skills-windows/prizmkit-test/references/service-boundary-test-catalog.md +0 -225
  289. package/bundled/skills-windows/prizmkit-test/references/test-generation-steps.md +0 -109
  290. package/bundled/skills-windows/prizmkit-test/references/test-report-template.md +0 -111
  291. package/bundled/skills-windows/prizmkit-test/scripts/validate_boundary_report.py +0 -347
  292. package/bundled/skills-windows/recovery-workflow/SKILL.md +0 -355
  293. package/bundled/skills-windows/recovery-workflow/evals/evals.json +0 -46
  294. package/bundled/skills-windows/recovery-workflow/references/detection.md +0 -58
  295. package/bundled/skills-windows/recovery-workflow/scripts/detect-recovery-state.py +0 -544
  296. package/bundled/skills-windows/refactor-pipeline-launcher/SKILL.md +0 -346
  297. package/bundled/skills-windows/refactor-pipeline-launcher/references/configuration.md +0 -72
  298. package/bundled/skills-windows/refactor-planner/SKILL.md +0 -398
  299. package/bundled/skills-windows/refactor-planner/assets/planning-guide.md +0 -292
  300. package/bundled/skills-windows/refactor-planner/references/behavior-preservation.md +0 -301
  301. package/bundled/skills-windows/refactor-planner/references/fast-path.md +0 -59
  302. package/bundled/skills-windows/refactor-planner/references/planning-phases.md +0 -135
  303. package/bundled/skills-windows/refactor-planner/references/refactor-scoping-guide.md +0 -221
  304. package/bundled/skills-windows/refactor-planner/scripts/validate-and-generate-refactor.py +0 -858
  305. package/bundled/skills-windows/refactor-workflow/SKILL.md +0 -343
  306. package/bundled/skills-windows/refactor-workflow/references/brainstorm-guide.md +0 -116
  307. package/bundled/templates/hooks/diff-prizm-docs.sh +0 -158
  308. package/bundled/templates/hooks/prizm-pre-commit.sh +0 -108
  309. package/bundled/templates/hooks/validate-prizm-docs.sh +0 -139
@@ -1,1463 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
-
4
- # ============================================================
5
- # dev-pipeline/run-refactor.sh - Autonomous Refactor Pipeline Runner
6
- #
7
- # Drives the prizm-dev-team through iterative AI CLI sessions to
8
- # execute refactors from a .prizmkit/plans/refactor-list.json specification.
9
- #
10
- # Usage:
11
- # ./run-refactor.sh run [.prizmkit/plans/refactor-list.json] [options] Run all refactors
12
- # ./run-refactor.sh run <refactor-id> [options] Run a single refactor
13
- # ./run-refactor.sh status [.prizmkit/plans/refactor-list.json] Show pipeline status
14
- # ./run-refactor.sh reset Clear all state
15
- #
16
- # Environment Variables:
17
- # MAX_RETRIES Max code retries per refactor (default: 3)
18
- # MAX_INFRA_RETRIES Max infrastructure/provider retries per refactor (default: 3)
19
- # AI_CLI AI CLI command name (auto-detected: cbc, claude, or codex)
20
- # CODEBUDDY_CLI Legacy alias for AI_CLI (deprecated, use AI_CLI instead)
21
- # PRIZMKIT_PLATFORM Platform hint for custom AI_CLI wrappers: codebuddy, claude, or codex
22
- # VERBOSE Set to 1 to enable --verbose on AI CLI
23
- # HEARTBEAT_INTERVAL Heartbeat log interval in seconds (default: 30)
24
- # STALE_KILL_THRESHOLD Auto-kill session after N seconds of no progress (default: 900)
25
- # HEARTBEAT_STALE_THRESHOLD Heartbeat stale threshold in seconds (default: 600)
26
- # MAX_LOG_SIZE Include passive log-size checkpoint guidance above this threshold (default: 2097152 = 2MB, set 0 to disable)
27
- # DEV_BRANCH Custom dev branch name (default: auto-generated refactor/pipeline-{run_id})
28
- # AUTO_PUSH Auto-push to remote after successful refactor (default: 0). Set to 1 to enable.
29
- # STOP_ON_FAILURE Stop pipeline after a task exhausts all retries (default: 0). Set to 1 to stop.
30
- # STRICT_BEHAVIOR_CHECK Force full test suite after each refactor item (default: 1)
31
- # ============================================================
32
-
33
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
34
-
35
- # Source shared common helpers (exports PIPELINE_DIR/PRIZMKIT_DIR/PROJECT_ROOT,
36
- # CLI/platform detection, logs, deps)
37
- source "$SCRIPT_DIR/lib/common.sh"
38
-
39
- STATE_DIR="${PRIZMKIT_DIR}/state/refactor"
40
- SCRIPTS_DIR="$SCRIPT_DIR/scripts"
41
-
42
- # Configuration
43
- MAX_RETRIES=${MAX_RETRIES:-3}
44
- MAX_INFRA_RETRIES=${MAX_INFRA_RETRIES:-3}
45
- HEARTBEAT_STALE_THRESHOLD=${HEARTBEAT_STALE_THRESHOLD:-600}
46
- HEARTBEAT_INTERVAL=${HEARTBEAT_INTERVAL:-30}
47
- STALE_KILL_THRESHOLD=${STALE_KILL_THRESHOLD:-900}
48
- VERBOSE=${VERBOSE:-0}
49
- MODEL=${MODEL:-""}
50
- PRIZMKIT_EFFORT=${PRIZMKIT_EFFORT:-""}
51
- DEV_BRANCH=${DEV_BRANCH:-""}
52
- AUTO_PUSH=${AUTO_PUSH:-0}
53
- STOP_ON_FAILURE=${STOP_ON_FAILURE:-0}
54
- STRICT_BEHAVIOR_CHECK=${STRICT_BEHAVIOR_CHECK:-1}
55
- ENABLE_DEPLOY=${ENABLE_DEPLOY:-0}
56
-
57
- # Source shared common helpers (CLI/platform detection + logs + deps)
58
- prizm_detect_cli_and_platform
59
-
60
- # Validate PRIZMKIT_EFFORT early (fail-fast before any sessions are spawned)
61
- prizm_validate_effort
62
-
63
- # Source shared heartbeat library
64
- source "$SCRIPT_DIR/lib/heartbeat.sh"
65
-
66
- # Source shared branch library
67
- source "$SCRIPT_DIR/lib/branch.sh"
68
-
69
- # Detect stream-json support
70
- detect_stream_json_support "$CLI_CMD"
71
-
72
- # Refactor list path (set in main, used by cleanup trap)
73
- REFACTOR_LIST=""
74
-
75
- # Branch tracking (for cleanup on interrupt)
76
- _ORIGINAL_BRANCH=""
77
- _DEV_BRANCH_NAME=""
78
-
79
- # ============================================================
80
- # Shared: Spawn AI CLI session and wait for result
81
- # ============================================================
82
-
83
- spawn_and_wait_session() {
84
- local refactor_id="$1"
85
- local refactor_list="$2"
86
- local session_id="$3"
87
- local bootstrap_prompt="$4"
88
- local session_dir="$5"
89
- local max_retries="$6"
90
- local max_infra_retries="$7"
91
- local item_model="${8:-}"
92
- local base_branch="${9:-main}"
93
-
94
- local session_log="$session_dir/logs/session.log"
95
- local progress_json="$session_dir/logs/progress.json"
96
-
97
- local effective_model=""
98
- if [[ -n "$item_model" ]]; then
99
- effective_model="$item_model"
100
- elif [[ -n "${MODEL:-}" ]]; then
101
- effective_model="$MODEL"
102
- fi
103
-
104
- # Log bootstrap prompt in test mode
105
- prizm_log_bootstrap_prompt "$bootstrap_prompt" "$refactor_id"
106
-
107
- local cli_pid
108
- prizm_start_ai_session "$bootstrap_prompt" "$session_log" "$effective_model"
109
- cli_pid="$PRIZM_AI_PID"
110
-
111
- # Start progress parser (no-op if stream-json not supported)
112
- start_progress_parser "$session_log" "$progress_json" "$SCRIPTS_DIR"
113
- local parser_pid="${_PARSER_PID:-}"
114
-
115
- # Heartbeat monitor (with stale-kill protection)
116
- start_heartbeat "$cli_pid" "$session_log" "$progress_json" "$HEARTBEAT_INTERVAL" "$STALE_KILL_THRESHOLD"
117
- local heartbeat_pid="${_HEARTBEAT_PID:-}"
118
-
119
- # Wait for AI CLI to finish
120
- local exit_code=0
121
- if wait "$cli_pid" 2>/dev/null; then
122
- exit_code=0
123
- else
124
- exit_code=$?
125
- fi
126
-
127
- # Cleanup
128
- stop_heartbeat "$heartbeat_pid"
129
- stop_progress_parser "$parser_pid"
130
-
131
- # Recover session log from backup if truncated by subagent stdout redirection
132
- prizm_recover_session_log "$session_log"
133
-
134
- # Check for stale-kill marker (heartbeat killed the process due to no progress)
135
- local stale_kill_marker="$session_dir/logs/stale-kill.json"
136
- local was_stale_killed=false
137
- if [[ -f "$stale_kill_marker" ]]; then
138
- was_stale_killed=true
139
- log_warn "Session was stale-killed by heartbeat monitor (no progress for too long)"
140
- fi
141
-
142
- local was_context_overflow=false
143
- if prizm_detect_context_overflow_error "$session_log" "$progress_json"; then
144
- was_context_overflow=true
145
- fi
146
-
147
- local was_ai_runtime_error=false
148
- if prizm_detect_ai_runtime_error "$session_log" "$progress_json"; then
149
- was_ai_runtime_error=true
150
- fi
151
-
152
- local was_infra_error=false
153
- if [[ $exit_code -ne 0 ]] && prizm_detect_infra_error "$session_log" "$progress_json"; then
154
- was_infra_error=true
155
- fi
156
-
157
- # Session summary
158
- if [[ -f "$session_log" ]]; then
159
- local final_size=$(wc -c < "$session_log" 2>/dev/null | tr -d ' ')
160
- local final_lines=$(wc -l < "$session_log" 2>/dev/null | tr -d ' ')
161
- log_info "Session log: $final_lines lines, $((final_size / 1024))KB"
162
- if [[ "$final_size" -lt 1024 && "$exit_code" -eq 0 ]]; then
163
- log_warn "Session log was truncated during execution (subagent stdout redirection may have severed it)"
164
- log_warn "Proceeding with exit-code-only outcome detection — child transcripts and git state are still valid"
165
- fi
166
- fi
167
- log_info "exit_code=$exit_code"
168
-
169
- # ── Determine session outcome from observable signals ──────────────
170
- local session_status
171
- local project_root
172
- project_root="$PROJECT_ROOT"
173
- local default_branch="$base_branch"
174
-
175
- local has_commits=""
176
- if git -C "$project_root" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
177
- has_commits=$(git -C "$project_root" log "${default_branch}..HEAD" --oneline 2>/dev/null | head -1)
178
- fi
179
-
180
- if [[ -n "$has_commits" ]]; then
181
- session_status="success"
182
- elif [[ "$was_context_overflow" == true ]]; then
183
- log_warn "Session failed because the AI CLI exceeded the model context window"
184
- log_warn "Context overflow is retried without consuming code retry budget"
185
- session_status="context_overflow"
186
- elif [[ "$was_ai_runtime_error" == true ]]; then
187
- log_warn "Session failed due to structured AI runtime error"
188
- log_warn "AI runtime errors are retried without consuming code retry budget"
189
- session_status="infra_error"
190
- elif [[ "$was_infra_error" == true ]]; then
191
- log_warn "Session failed due to AI CLI/provider infrastructure error"
192
- log_warn "Infrastructure errors are retried without consuming code retry budget"
193
- session_status="infra_error"
194
- elif [[ "$was_stale_killed" == true ]]; then
195
- log_warn "Session stale-killed (no progress for ${STALE_KILL_THRESHOLD}s)"
196
- log_warn "Stale-killed sessions are treated as failed; dev branch is preserved for inspection"
197
- session_status="crashed"
198
- elif [[ $exit_code -ne 0 ]]; then
199
- log_warn "Session exited with code $exit_code"
200
- session_status="crashed"
201
- else
202
- # Exit code 0 — check if the session actually produced commits
203
- local has_commits=""
204
- if git -C "$project_root" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
205
- has_commits=$(git -C "$project_root" log "${default_branch}..HEAD" --oneline 2>/dev/null | head -1)
206
- fi
207
-
208
- if [[ -n "$has_commits" ]]; then
209
- session_status="success"
210
- else
211
- local uncommitted=""
212
- uncommitted=$(prizm_git_status_safe "$project_root" | head -1 || true)
213
- if [[ -n "$uncommitted" ]]; then
214
- log_warn "Session exited cleanly but produced no commits (uncommitted changes found) — auto-committing..."
215
- prizm_git_add_all_safe "$project_root" || true
216
- if git -C "$project_root" commit --no-verify -m "chore($refactor_id): auto-commit session work" 2>/dev/null; then
217
- log_info "Auto-commit succeeded"
218
- session_status="success"
219
- else
220
- log_warn "Auto-commit failed — no changes to commit"
221
- session_status="crashed"
222
- fi
223
- else
224
- log_warn "Session exited cleanly but produced no commits and no changes"
225
- session_status="crashed"
226
- fi
227
- fi
228
- fi
229
-
230
- # ── Post-success validation ──────────────────────────────────────────
231
- if [[ "$session_status" == "success" ]]; then
232
- if git -C "$project_root" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
233
- local dirty_files=""
234
- dirty_files=$(prizm_git_status_safe "$project_root" || true)
235
- if [[ -n "$dirty_files" ]]; then
236
- log_info "Auto-committing remaining session artifacts..."
237
- prizm_git_add_all_safe "$project_root" || true
238
- git -C "$project_root" commit --no-verify --amend --no-edit 2>/dev/null \
239
- || git -C "$project_root" commit --no-verify -m "chore($refactor_id): include remaining session artifacts" 2>/dev/null \
240
- || true
241
- fi
242
- fi
243
- fi
244
-
245
- log_info "Session result: $session_status"
246
-
247
- # Validate key artifacts exist after successful session
248
- if [[ "$session_status" == "success" ]]; then
249
- local plan_file="$PRIZMKIT_DIR/refactor/$refactor_id/plan.md"
250
- if [[ ! -f "$plan_file" ]]; then
251
- log_warn "ARTIFACT_MISSING: plan.md not found at $plan_file"
252
- fi
253
-
254
- # Validate checkpoint completeness
255
- local checkpoint_file="$PRIZMKIT_DIR/refactor/$refactor_id/workflow-checkpoint.json"
256
- if [[ -f "$checkpoint_file" ]]; then
257
- local checkpoint_result
258
- checkpoint_result=$(python3 -c "
259
- import json, sys
260
- try:
261
- with open(sys.argv[1]) as f:
262
- data = json.load(f)
263
- except json.JSONDecodeError as e:
264
- print('CORRUPTED: {}'.format(e))
265
- sys.exit(2)
266
- incomplete = [s for s in data['steps'] if s['status'] not in ('completed', 'skipped')]
267
- if incomplete:
268
- for s in incomplete:
269
- print('INCOMPLETE: {} {} = {}'.format(s['id'], s['skill'], s['status']))
270
- sys.exit(1)
271
- print('ALL_COMPLETE')
272
- sys.exit(0)
273
- " "$checkpoint_file" 2>&1) || checkpoint_result="CHECK_FAILED"
274
- local check_exit=$?
275
- if [[ "$checkpoint_result" == "CHECK_FAILED" ]]; then
276
- check_exit=2
277
- elif [[ "$checkpoint_result" == *"INCOMPLETE"* ]]; then
278
- check_exit=1
279
- else
280
- check_exit=0
281
- fi
282
- if [[ $check_exit -eq 2 ]]; then
283
- log_warn "CHECKPOINT_CORRUPTED: workflow-checkpoint.json is not valid JSON"
284
- elif [[ $check_exit -eq 1 ]]; then
285
- log_warn "CHECKPOINT_INCOMPLETE: Not all workflow steps completed:"
286
- echo "$checkpoint_result" | while read -r line; do log_warn " $line"; done
287
- else
288
- log_info "CHECKPOINT: All workflow steps completed"
289
- fi
290
- else
291
- log_info "CHECKPOINT: No workflow-checkpoint.json found (checkpoint system not active)"
292
- fi
293
- fi
294
-
295
- # Subagent detection
296
- prizm_detect_subagents "$session_log"
297
-
298
- # Propagate completion notes for dependency context (only on success)
299
- if [[ "$session_status" == "success" ]]; then
300
- local summary_path="$PRIZMKIT_DIR/refactor/$refactor_id/completion-summary.json"
301
- if [[ -f "$summary_path" ]]; then
302
- python3 "$SCRIPTS_DIR/patch-completion-notes.py" \
303
- --refactor-list "$refactor_list" \
304
- --refactor-id "$refactor_id" \
305
- --summary "$summary_path" >/dev/null 2>&1 && {
306
- log_info "Propagated completion notes for $refactor_id to refactor-list.json"
307
- } || {
308
- log_warn "Failed to propagate completion notes for $refactor_id"
309
- }
310
- else
311
- log_info "No completion-summary.json for $refactor_id — dependency context will be limited"
312
- fi
313
- fi
314
-
315
- # Final status updates happen after the caller returns to the original branch.
316
- _SPAWN_RESULT="$session_status"
317
- }
318
-
319
- finalize_refactor_status_after_branch_return() {
320
- local refactor_id="$1"
321
- local refactor_list="$2"
322
- local session_id="$3"
323
- local session_status="$4"
324
- local max_retries="$5"
325
- local max_infra_retries="$6"
326
- local base_branch="${7:-main}"
327
- local active_dev_branch="${8:-}"
328
- local fatal_error_code="${9:-}"
329
- local continuation_summary_path="${10:-}"
330
- local no_progress_count="${11:-0}"
331
- local progress_fingerprint="${12:-}"
332
-
333
- # Update refactor status on the original branch. The caller commits the
334
- # resulting refactor-list diff immediately after this helper returns.
335
- local update_output
336
- update_output=$(python3 "$SCRIPTS_DIR/update-refactor-status.py" \
337
- --refactor-list "$refactor_list" \
338
- --state-dir "$STATE_DIR" \
339
- --refactor-id "$refactor_id" \
340
- --session-status "$session_status" \
341
- --session-id "$session_id" \
342
- --max-retries "$max_retries" \
343
- --max-infra-retries "$max_infra_retries" \
344
- --active-dev-branch "$active_dev_branch" \
345
- --base-branch "$base_branch" \
346
- --last-fatal-error-code "$fatal_error_code" \
347
- --continuation-summary-path "$continuation_summary_path" \
348
- --no-progress-count "$no_progress_count" \
349
- --progress-fingerprint "$progress_fingerprint" \
350
- --action update) || {
351
- log_error "Failed to update refactor status: $update_output"
352
- update_output=""
353
- }
354
-
355
- _SPAWN_ITEM_STATUS="$(printf '%s' "$update_output" | prizm_extract_update_new_status)"
356
- }
357
-
358
- # ============================================================
359
- # Graceful Shutdown
360
- # ============================================================
361
-
362
- cleanup() {
363
- echo ""
364
- log_warn "Received interrupt signal. Saving state..."
365
-
366
- # Kill all child processes (claude-internal, heartbeat, progress parser, etc.)
367
- kill 0 2>/dev/null || true
368
-
369
- # Log current branch info for recovery
370
- if [[ -n "$_DEV_BRANCH_NAME" ]]; then
371
- log_info "Development was on branch: $_DEV_BRANCH_NAME"
372
- log_info "Original branch was: $_ORIGINAL_BRANCH"
373
- fi
374
-
375
- # Update status of currently in-progress refactor to interrupted
376
- if [[ -n "$REFACTOR_LIST" && -f "$REFACTOR_LIST" ]]; then
377
- # Find any in-progress refactor and mark it as failed
378
- local _interrupted_id
379
- _interrupted_id=$(python3 -c "
380
- import json, sys
381
- with open(sys.argv[1]) as f:
382
- data = json.load(f)
383
- for item in data.get('refactors', []):
384
- if item.get('status') == 'in_progress':
385
- print(item['id'])
386
- break
387
- " "$REFACTOR_LIST" 2>/dev/null || echo "")
388
-
389
- if [[ -n "$_interrupted_id" ]]; then
390
- python3 "$SCRIPTS_DIR/update-refactor-status.py" \
391
- --refactor-list "$REFACTOR_LIST" \
392
- --state-dir "$STATE_DIR" \
393
- --refactor-id "$_interrupted_id" \
394
- --session-status "failed" \
395
- --max-retries "$MAX_RETRIES" \
396
- --max-infra-retries "$MAX_INFRA_RETRIES" \
397
- --action update 2>/dev/null || true
398
- log_info "Refactor $_interrupted_id marked as failed due to interrupt"
399
- fi
400
-
401
- # Pause the pipeline
402
- python3 "$SCRIPTS_DIR/update-refactor-status.py" \
403
- --refactor-list "$REFACTOR_LIST" \
404
- --state-dir "$STATE_DIR" \
405
- --action pause 2>/dev/null || true
406
- fi
407
-
408
- # GUARANTEED: always return to original branch (save WIP on dev branch first)
409
- branch_ensure_return "$PROJECT_ROOT" "$_ORIGINAL_BRANCH" "$_DEV_BRANCH_NAME"
410
-
411
- log_info "Refactor pipeline paused. Run './run-refactor.sh run' to resume."
412
- exit 130
413
- }
414
- trap cleanup SIGINT SIGTERM
415
-
416
- # ============================================================
417
- # Dependency Check
418
- # ============================================================
419
-
420
- check_dependencies() {
421
- prizm_check_common_dependencies "$CLI_CMD"
422
- local _project_root
423
- _project_root="$PROJECT_ROOT"
424
- prizm_ensure_git_repo "$_project_root"
425
- }
426
-
427
- # ============================================================
428
- # run-one: Run a single refactor
429
- # ============================================================
430
-
431
- run_one() {
432
- local refactor_id=""
433
- local refactor_list=""
434
- local dry_run=false
435
- local do_clean=false
436
- local no_reset=false
437
- local mode_override=""
438
- local critic_override=""
439
-
440
- while [[ $# -gt 0 ]]; do
441
- case "$1" in
442
- --dry-run) dry_run=true; shift ;;
443
- --clean) do_clean=true; shift ;;
444
- --no-reset) no_reset=true; shift ;;
445
- --max-infra-retries)
446
- shift
447
- if [[ $# -eq 0 ]]; then
448
- log_error "--max-infra-retries requires a value"
449
- exit 1
450
- fi
451
- prizm_require_positive_int "--max-infra-retries" "$1"
452
- MAX_INFRA_RETRIES="$1"
453
- shift
454
- ;;
455
- --mode)
456
- shift
457
- if [[ $# -eq 0 ]]; then
458
- log_error "--mode requires a value (lite|standard|full)"
459
- exit 1
460
- fi
461
- case "$1" in
462
- lite|standard|full) mode_override="$1" ;;
463
- *) log_error "Invalid mode: $1 (must be lite, standard, or full)"; exit 1 ;;
464
- esac
465
- shift
466
- ;;
467
- --critic) critic_override="true"; shift ;;
468
- --no-critic) critic_override="false"; shift ;;
469
- R-*|r-*) refactor_id="$1"; shift ;;
470
- *) refactor_list="$1"; shift ;;
471
- esac
472
- done
473
-
474
- if [[ -z "$refactor_id" ]]; then
475
- log_error "Refactor ID is required (e.g. R-001)"
476
- echo ""
477
- show_help
478
- exit 1
479
- fi
480
-
481
- if [[ -z "$refactor_list" ]]; then
482
- refactor_list="$PRIZMKIT_DIR/plans/refactor-list.json"
483
- fi
484
- if [[ ! "$refactor_list" = /* ]]; then
485
- refactor_list="$(pwd)/$refactor_list"
486
- fi
487
- REFACTOR_LIST="$refactor_list"
488
-
489
- if [[ ! -f "$refactor_list" ]]; then
490
- log_error "Refactor list not found: $refactor_list"
491
- exit 1
492
- fi
493
-
494
- check_dependencies
495
-
496
- # Initialize state if needed
497
- if [[ ! -f "$STATE_DIR/pipeline.json" ]]; then
498
- log_info "Initializing refactor pipeline state..."
499
- local init_result init_stderr init_tmpstderr
500
- init_tmpstderr=$(mktemp)
501
- if ! init_result=$(python3 "$SCRIPTS_DIR/init-refactor-pipeline.py" \
502
- --refactor-list "$refactor_list" \
503
- --state-dir "$STATE_DIR" 2>"$init_tmpstderr"); then
504
- init_stderr=$(cat "$init_tmpstderr" 2>/dev/null || true)
505
- rm -f "$init_tmpstderr"
506
- if [[ -n "$init_stderr" ]]; then
507
- log_warn "$init_stderr"
508
- fi
509
- log_error "Refactor pipeline initialization failed (script error)"
510
- exit 1
511
- fi
512
- init_stderr=$(cat "$init_tmpstderr" 2>/dev/null || true)
513
- rm -f "$init_tmpstderr"
514
-
515
- if [[ -n "$init_stderr" ]]; then
516
- log_warn "$init_stderr"
517
- fi
518
-
519
- local init_valid
520
- init_valid=$(echo "$init_result" | python3 -c "import sys,json; print(json.load(sys.stdin).get('valid', False))" 2>/dev/null || echo "False")
521
-
522
- if [[ "$init_valid" != "True" ]]; then
523
- log_error "Refactor pipeline initialization failed:"
524
- echo "$init_result"
525
- exit 1
526
- fi
527
-
528
- local refactors_count
529
- refactors_count=$(echo "$init_result" | python3 -c "import sys,json; print(json.load(sys.stdin).get('refactors_count', 0))" 2>/dev/null || echo "0")
530
- log_success "Refactor pipeline initialized with $refactors_count refactors"
531
- fi
532
-
533
- # Verify refactor exists
534
- local refactor_title
535
- refactor_title=$(python3 -c "
536
- import json, sys
537
- with open(sys.argv[1]) as f:
538
- data = json.load(f)
539
- for item in data.get('refactors', []):
540
- if item.get('id') == sys.argv[2]:
541
- print(item.get('title', ''))
542
- sys.exit(0)
543
- sys.exit(1)
544
- " "$refactor_list" "$refactor_id" 2>/dev/null) || {
545
- log_error "Refactor $refactor_id not found in $refactor_list"
546
- exit 1
547
- }
548
-
549
- local refactor_complexity
550
- refactor_complexity=$(python3 -c "
551
- import json, sys
552
- with open(sys.argv[1]) as f:
553
- data = json.load(f)
554
- for item in data.get('refactors', []):
555
- if item.get('id') == sys.argv[2]:
556
- print(item.get('complexity', 'medium'))
557
- sys.exit(0)
558
- sys.exit(1)
559
- " "$refactor_list" "$refactor_id" 2>/dev/null) || refactor_complexity="medium"
560
-
561
- # Optional Clean
562
- if [[ "$do_clean" == true ]]; then
563
- if [[ "$dry_run" == true ]]; then
564
- log_warn "Dry-run mode: --clean ignored (no artifacts will be deleted)"
565
- else
566
- log_info "Cleaning artifacts for $refactor_id..."
567
-
568
- local project_root
569
- project_root="$PROJECT_ROOT"
570
-
571
- local refactor_dir="$PRIZMKIT_DIR/refactor/$refactor_id"
572
- if [[ -d "$refactor_dir" ]]; then
573
- rm -rf "$refactor_dir"
574
- log_info "Removed $refactor_dir"
575
- fi
576
-
577
- local dev_team_dir="$project_root/.dev-team"
578
- if [[ -d "$dev_team_dir" ]]; then
579
- rm -rf "$dev_team_dir"
580
- log_info "Removed $dev_team_dir"
581
- fi
582
-
583
- local refactor_state_dir="$STATE_DIR/$refactor_id"
584
- if [[ -d "$refactor_state_dir" ]]; then
585
- rm -rf "$refactor_state_dir"
586
- log_info "Removed $refactor_state_dir"
587
- fi
588
- fi
589
- fi
590
-
591
- # Reset refactor status (conditional)
592
- if [[ "$no_reset" == false && "$dry_run" == false ]]; then
593
- python3 "$SCRIPTS_DIR/update-refactor-status.py" \
594
- --refactor-list "$refactor_list" \
595
- --state-dir "$STATE_DIR" \
596
- --refactor-id "$refactor_id" \
597
- --action reset >/dev/null 2>&1 || {
598
- log_warn "Failed to reset refactor status (may already be pending)"
599
- }
600
- elif [[ "$dry_run" == true && "$no_reset" == false ]]; then
601
- log_info "Dry-run mode: skipping status reset"
602
- fi
603
-
604
- # Generate bootstrap prompt
605
- local run_id session_id session_dir bootstrap_prompt
606
- run_id=$(jq -r '.run_id' "$STATE_DIR/pipeline.json")
607
- session_id="${refactor_id}-$(date +%Y%m%d%H%M%S)"
608
- session_dir="$STATE_DIR/$refactor_id/sessions/$session_id"
609
- mkdir -p "$session_dir/logs"
610
-
611
- bootstrap_prompt="$session_dir/bootstrap-prompt.md"
612
-
613
- # Read retry count from status.json
614
- local retry_count
615
- retry_count=$(python3 -c "
616
- import json, os
617
- status_path = os.path.join('$STATE_DIR', '$refactor_id', 'status.json')
618
- if os.path.isfile(status_path):
619
- with open(status_path) as f:
620
- d = json.load(f)
621
- print(d.get('retry_count', 0))
622
- else:
623
- print(0)
624
- " 2>/dev/null || echo "0")
625
- local resume_phase
626
- resume_phase=$(python3 -c "
627
- import json, os
628
- status_path = os.path.join('$STATE_DIR', '$refactor_id', 'status.json')
629
- if os.path.isfile(status_path):
630
- with open(status_path) as f:
631
- d = json.load(f)
632
- print(d.get('resume_from_phase') or 'null')
633
- else:
634
- print('null')
635
- " 2>/dev/null || echo "null")
636
-
637
- log_info "Generating refactor bootstrap prompt..."
638
- local prompt_args=(
639
- --refactor-list "$refactor_list"
640
- --refactor-id "$refactor_id"
641
- --session-id "$session_id"
642
- --run-id "$run_id"
643
- --retry-count "$retry_count"
644
- --resume-phase "$resume_phase"
645
- --state-dir "$STATE_DIR"
646
- --output "$bootstrap_prompt"
647
- )
648
-
649
- if [[ -n "$mode_override" ]]; then
650
- prompt_args+=(--mode "$mode_override")
651
- elif [[ -n "${PIPELINE_MODE:-}" ]]; then
652
- prompt_args+=(--mode "$PIPELINE_MODE")
653
- fi
654
-
655
- if [[ -n "${critic_override:-}" ]]; then
656
- prompt_args+=(--critic "$critic_override")
657
- elif [[ "${ENABLE_CRITIC:-}" == "true" || "${ENABLE_CRITIC:-}" == "1" ]]; then
658
- prompt_args+=(--critic "true")
659
- elif [[ "${ENABLE_CRITIC:-}" == "false" || "${ENABLE_CRITIC:-}" == "0" ]]; then
660
- prompt_args+=(--critic "false")
661
- fi
662
-
663
- local gen_output
664
- gen_output=$(python3 "$SCRIPTS_DIR/generate-refactor-prompt.py" "${prompt_args[@]}" 2>/dev/null) || {
665
- log_error "Failed to generate bootstrap prompt for $refactor_id"
666
- return 1
667
- }
668
- local refactor_model pipeline_mode agent_count critic_enabled
669
- refactor_model=$(echo "$gen_output" | python3 -c "import json,sys; print(json.load(sys.stdin).get('model',''))" 2>/dev/null || echo "")
670
- pipeline_mode=$(echo "$gen_output" | python3 -c "import json,sys; print(json.load(sys.stdin).get('pipeline_mode','standard'))" 2>/dev/null || echo "standard")
671
- agent_count=$(echo "$gen_output" | python3 -c "import json,sys; print(json.load(sys.stdin).get('agent_count',3))" 2>/dev/null || echo "3")
672
- critic_enabled=$(echo "$gen_output" | python3 -c "import json,sys; print(json.load(sys.stdin).get('critic_enabled','false'))" 2>/dev/null || echo "false")
673
-
674
- if [[ "$dry_run" == true ]]; then
675
- echo ""
676
- echo -e "${BOLD}════════════════════════════════════════════════════${NC}"
677
- echo -e "${BOLD} Dry Run: $refactor_id — $refactor_title${NC}"
678
- echo -e "${BOLD} Complexity: $refactor_complexity${NC}"
679
- echo -e "${BOLD}════════════════════════════════════════════════════${NC}"
680
- echo ""
681
- log_info "Session ID: $session_id"
682
- if [[ -n "$mode_override" ]]; then
683
- log_info "Mode Override: $mode_override"
684
- fi
685
- log_info "Pipeline mode: $pipeline_mode"
686
- log_info "Agents: $agent_count (critic: $([ "$critic_enabled" = "true" ] && echo "enabled" || echo "disabled"))"
687
- if [[ -n "$refactor_model" ]]; then
688
- log_info "Refactor Model: $refactor_model"
689
- elif [[ -n "$MODEL" ]]; then
690
- log_info "Model (env): $MODEL"
691
- else
692
- log_info "Model: (CLI default)"
693
- fi
694
- echo ""
695
- log_info "Bootstrap prompt written to:"
696
- echo " $bootstrap_prompt"
697
- echo ""
698
- log_success "Dry run complete. Inspect full prompt with:"
699
- echo " cat $bootstrap_prompt"
700
- return 0
701
- fi
702
-
703
- echo ""
704
- echo -e "${BOLD}════════════════════════════════════════════════════${NC}"
705
- echo -e "${BOLD} Refactor: $refactor_id — $refactor_title${NC}"
706
- echo -e "${BOLD} Complexity: $refactor_complexity${NC}"
707
- echo -e "${BOLD}════════════════════════════════════════════════════${NC}"
708
- log_info "Session ID: $session_id"
709
- log_info "Prompt: $bootstrap_prompt"
710
- log_info "Log: $session_dir/logs/session.log"
711
- local _run_one_mode_desc
712
- case "$pipeline_mode" in
713
- lite) _run_one_mode_desc="Tier 1 — Single Agent" ;;
714
- standard) _run_one_mode_desc="Tier 2 — Orchestrator + Dev + Reviewer" ;;
715
- full) _run_one_mode_desc="Tier 3 — Full Team (+ Multi-Critic)" ;;
716
- *) _run_one_mode_desc="$pipeline_mode" ;;
717
- esac
718
- log_info "Pipeline mode: ${BOLD}$pipeline_mode${NC} ($_run_one_mode_desc)"
719
- log_info "Agents: $agent_count (critic: $([ "$critic_enabled" = "true" ] && echo "enabled" || echo "disabled"))"
720
- if [[ -n "$refactor_model" ]]; then
721
- log_info "Refactor model: $refactor_model"
722
- fi
723
- if [[ "$STRICT_BEHAVIOR_CHECK" == "1" ]]; then
724
- log_info "Strict behavior check: enabled"
725
- fi
726
- echo -e "${BOLD}════════════════════════════════════════════════════${NC}"
727
- echo ""
728
-
729
- cleanup_single_refactor() {
730
- echo ""
731
- log_warn "Interrupted. Killing session..."
732
- kill 0 2>/dev/null || true
733
- # Log current branch info
734
- if [[ -n "$_DEV_BRANCH_NAME" ]]; then
735
- log_info "Development was on branch: $_DEV_BRANCH_NAME"
736
- fi
737
- log_info "Session log: $session_dir/logs/session.log"
738
-
739
- # Update refactor status to failed on interrupt
740
- if [[ -n "$refactor_list" && -f "$refactor_list" ]]; then
741
- python3 "$SCRIPTS_DIR/update-refactor-status.py" \
742
- --refactor-list "$refactor_list" \
743
- --state-dir "$STATE_DIR" \
744
- --refactor-id "$refactor_id" \
745
- --session-status "failed" \
746
- --max-retries "$MAX_RETRIES" \
747
- --max-infra-retries "$MAX_INFRA_RETRIES" \
748
- --action update 2>/dev/null || true
749
- log_info "Refactor $refactor_id marked as failed due to interrupt"
750
- fi
751
-
752
- # GUARANTEED: always return to original branch (save WIP on dev branch first)
753
- branch_ensure_return "$PROJECT_ROOT" "$_ORIGINAL_BRANCH" "$_DEV_BRANCH_NAME"
754
- exit 130
755
- }
756
- trap cleanup_single_refactor SIGINT SIGTERM
757
-
758
- _SPAWN_RESULT=""
759
- _SPAWN_ITEM_STATUS=""
760
-
761
- # Branch lifecycle: create and checkout refactor branch
762
- local _proj_root
763
- _proj_root="$PROJECT_ROOT"
764
- local _source_branch
765
- _source_branch=$(git -C "$_proj_root" rev-parse --abbrev-ref HEAD 2>/dev/null || echo "main")
766
- _ORIGINAL_BRANCH="$_source_branch"
767
-
768
- # Mark refactor as in-progress (update JSON for runtime monitoring, no commit)
769
- # The status change will be committed together with the final status update
770
- # after the session completes, avoiding an extra noise commit per refactor.
771
- python3 "$SCRIPTS_DIR/update-refactor-status.py" \
772
- --refactor-list "$refactor_list" \
773
- --state-dir "$STATE_DIR" \
774
- --refactor-id "$refactor_id" \
775
- --action start >/dev/null 2>&1 || true
776
-
777
- local _branch_name="${DEV_BRANCH:-refactor/${refactor_id}-$(date +%s)}"
778
- if branch_create "$_proj_root" "$_branch_name" "$_source_branch"; then
779
- _DEV_BRANCH_NAME="$_branch_name"
780
- else
781
- log_error "Failed to create branch: $_branch_name from $_source_branch — aborting to avoid running on $_source_branch"
782
- return 1
783
- fi
784
-
785
- spawn_and_wait_session \
786
- "$refactor_id" "$refactor_list" "$session_id" \
787
- "$bootstrap_prompt" "$session_dir" "$MAX_RETRIES" "$MAX_INFRA_RETRIES" "$refactor_model" "$_ORIGINAL_BRANCH"
788
- local session_status="$_SPAWN_RESULT"
789
-
790
- local active_dev_branch_for_status="$_DEV_BRANCH_NAME"
791
- local continuation_summary_path=""
792
- local no_progress_count=0
793
- local progress_after=""
794
-
795
- # Merge dev branch back to original on success
796
- if [[ "$session_status" == "success" && -n "$_DEV_BRANCH_NAME" ]]; then
797
- if branch_merge "$_proj_root" "$_DEV_BRANCH_NAME" "$_ORIGINAL_BRANCH" "$AUTO_PUSH"; then
798
- _DEV_BRANCH_NAME=""
799
- else
800
- log_warn "Auto-merge failed — dev branch preserved: $_DEV_BRANCH_NAME"
801
- log_warn "Merge manually: git checkout $_ORIGINAL_BRANCH && git rebase $_DEV_BRANCH_NAME"
802
- session_status="merge_conflict"
803
- fi
804
- elif [[ -n "$_DEV_BRANCH_NAME" ]]; then
805
- # Session failed — preserve dev branch for inspection
806
- log_warn "Session failed — dev branch preserved for inspection: $_DEV_BRANCH_NAME"
807
- _DEV_BRANCH_NAME=""
808
- fi
809
-
810
- # GUARANTEED: always return to original branch regardless of success/failure/merge outcome
811
- branch_ensure_return "$_proj_root" "$_ORIGINAL_BRANCH"
812
-
813
- finalize_refactor_status_after_branch_return \
814
- "$refactor_id" "$refactor_list" "$session_id" "$session_status" "$MAX_RETRIES" "$MAX_INFRA_RETRIES" "$_ORIGINAL_BRANCH" "$active_dev_branch_for_status" "context_overflow" "$continuation_summary_path" "$no_progress_count" "${progress_after:-}"
815
-
816
- # Commit refactor status update on the original branch (after guaranteed return)
817
- if ! git -C "$_proj_root" diff --quiet "$refactor_list" 2>/dev/null; then
818
- prizm_git_commit_paths "$_proj_root" "chore($refactor_id): update refactor status" "$refactor_list"
819
- fi
820
-
821
- echo ""
822
- if [[ "$session_status" == "success" ]]; then
823
- log_success "════════════════════════════════════════════════════"
824
- log_success " $refactor_id completed successfully!"
825
- log_success "════════════════════════════════════════════════════"
826
- else
827
- log_error "════════════════════════════════════════════════════"
828
- log_error " $refactor_id result: $session_status"
829
- log_error " Review log: $session_dir/logs/session.log"
830
- log_error "════════════════════════════════════════════════════"
831
- fi
832
- }
833
-
834
- # ============================================================
835
- # Main Loop: Run all refactors
836
- # ============================================================
837
-
838
- main() {
839
- local refactor_list="$PRIZMKIT_DIR/plans/refactor-list.json"
840
-
841
- while [[ $# -gt 0 ]]; do
842
- case "$1" in
843
- --max-infra-retries)
844
- shift
845
- if [[ $# -eq 0 ]]; then
846
- log_error "--max-infra-retries requires a value"
847
- exit 1
848
- fi
849
- prizm_require_positive_int "--max-infra-retries" "$1"
850
- MAX_INFRA_RETRIES="$1"
851
- shift
852
- ;;
853
- --)
854
- shift
855
- break
856
- ;;
857
- -*)
858
- log_error "Unknown option: $1"
859
- show_help
860
- exit 1
861
- ;;
862
- *)
863
- refactor_list="$1"
864
- shift
865
- ;;
866
- esac
867
- done
868
-
869
- if [[ $# -gt 0 ]]; then
870
- log_error "Unexpected arguments: $*"
871
- show_help
872
- exit 1
873
- fi
874
-
875
- if [[ ! "$refactor_list" = /* ]]; then
876
- refactor_list="$(pwd)/$refactor_list"
877
- fi
878
- REFACTOR_LIST="$refactor_list"
879
-
880
- if [[ ! -f "$refactor_list" ]]; then
881
- log_error "Refactor list not found: $refactor_list"
882
- log_info "Create a refactor list first using the refactor-planner skill,"
883
- log_info "or provide a path: ./run-refactor.sh run <path-to-.prizmkit/plans/refactor-list.json>"
884
- exit 1
885
- fi
886
-
887
- check_dependencies
888
-
889
- # Initialize pipeline state if needed
890
- if [[ ! -f "$STATE_DIR/pipeline.json" ]]; then
891
- log_info "Initializing refactor pipeline state..."
892
- local init_result init_stderr init_tmpstderr
893
- init_tmpstderr=$(mktemp)
894
- if ! init_result=$(python3 "$SCRIPTS_DIR/init-refactor-pipeline.py" \
895
- --refactor-list "$refactor_list" \
896
- --state-dir "$STATE_DIR" 2>"$init_tmpstderr"); then
897
- init_stderr=$(cat "$init_tmpstderr" 2>/dev/null || true)
898
- rm -f "$init_tmpstderr"
899
- if [[ -n "$init_stderr" ]]; then
900
- log_warn "$init_stderr"
901
- fi
902
- log_error "Refactor pipeline initialization failed (script error)"
903
- exit 1
904
- fi
905
- init_stderr=$(cat "$init_tmpstderr" 2>/dev/null || true)
906
- rm -f "$init_tmpstderr"
907
-
908
- if [[ -n "$init_stderr" ]]; then
909
- log_warn "$init_stderr"
910
- fi
911
-
912
- local init_valid
913
- init_valid=$(echo "$init_result" | python3 -c "import sys,json; print(json.load(sys.stdin).get('valid', False))" 2>/dev/null || echo "False")
914
-
915
- if [[ "$init_valid" != "True" ]]; then
916
- log_error "Refactor pipeline initialization failed:"
917
- echo "$init_result"
918
- exit 1
919
- fi
920
-
921
- local refactors_count
922
- refactors_count=$(echo "$init_result" | python3 -c "import sys,json; print(json.load(sys.stdin).get('refactors_count', 0))" 2>/dev/null || echo "0")
923
- log_success "Refactor pipeline initialized with $refactors_count refactors"
924
- else
925
- log_info "Resuming existing refactor pipeline..."
926
- fi
927
-
928
- # Print header
929
- echo ""
930
- echo -e "${BOLD}════════════════════════════════════════════════════${NC}"
931
- echo -e "${BOLD} Refactor Pipeline Runner Started${NC}"
932
- echo -e "${BOLD}════════════════════════════════════════════════════${NC}"
933
- log_info "Refactor list: $refactor_list"
934
- log_info "Max code retries per refactor: $MAX_RETRIES"
935
- log_info "Max infrastructure retries per refactor: $MAX_INFRA_RETRIES"
936
- log_info "AI CLI: $CLI_CMD (platform: $PLATFORM)"
937
- if [[ -n "${MODEL:-}" ]]; then
938
- log_info "Default Model: $MODEL"
939
- fi
940
- if [[ "$STRICT_BEHAVIOR_CHECK" == "1" ]]; then
941
- log_info "Strict behavior check: enabled"
942
- else
943
- log_info "Strict behavior check: disabled"
944
- fi
945
- if [[ "$STOP_ON_FAILURE" == "1" ]]; then
946
- log_info "Stop on failure: enabled"
947
- fi
948
- echo -e "${BOLD}════════════════════════════════════════════════════${NC}"
949
- echo ""
950
-
951
- # Branch lifecycle: per-refactor branches (like feature pipeline)
952
- local _proj_root
953
- _proj_root="$PROJECT_ROOT"
954
- local _source_branch
955
- _source_branch=$(git -C "$_proj_root" rev-parse --abbrev-ref HEAD 2>/dev/null || echo "main")
956
- _ORIGINAL_BRANCH="$_source_branch"
957
-
958
- local session_count=0
959
- local total_subagent_calls=0
960
-
961
- while true; do
962
- # Safety net: ensure we're on the original branch at the start of each iteration.
963
- # If a previous iteration's `continue` skipped branch_ensure_return, we could
964
- # still be on a dev branch. This prevents cascading branch confusion.
965
- if [[ -n "$_ORIGINAL_BRANCH" ]]; then
966
- local _cur_branch
967
- _cur_branch=$(git -C "$_proj_root" rev-parse --abbrev-ref HEAD 2>/dev/null || true)
968
- if [[ -n "$_cur_branch" && "$_cur_branch" != "$_ORIGINAL_BRANCH" ]]; then
969
- log_warn "Still on branch $_cur_branch at loop start — returning to $_ORIGINAL_BRANCH"
970
- branch_ensure_return "$_proj_root" "$_ORIGINAL_BRANCH"
971
- fi
972
- fi
973
-
974
- # Find next refactor to process (dependency-topological order)
975
- local next_refactor
976
- if ! next_refactor=$(python3 "$SCRIPTS_DIR/update-refactor-status.py" \
977
- --refactor-list "$refactor_list" \
978
- --state-dir "$STATE_DIR" \
979
- --max-retries "$MAX_RETRIES" \
980
- --max-infra-retries "$MAX_INFRA_RETRIES" \
981
- --action get_next 2>/dev/null); then
982
- log_error "Failed to get next refactor"
983
- break
984
- fi
985
-
986
- if [[ "$next_refactor" == "PIPELINE_COMPLETE" ]]; then
987
- echo ""
988
- log_success "════════════════════════════════════════════════════"
989
- log_success " All refactors processed! Refactor pipeline finished."
990
- log_success " Total sessions: $session_count"
991
- log_success " Total subagent calls: $total_subagent_calls"
992
- log_success "════════════════════════════════════════════════════"
993
-
994
- # ── Deploy session (only if ENABLE_DEPLOY=1 and all refactors completed) ──
995
- if [[ "$ENABLE_DEPLOY" == "1" ]]; then
996
- local incomplete_count
997
- incomplete_count=$({ python3 -c "
998
- import json, sys
999
- with open(sys.argv[1]) as f:
1000
- data = json.load(f)
1001
- bad = [r for r in data.get('refactors', [])
1002
- if r.get('status') not in ('completed', 'skipped')]
1003
- for r in bad:
1004
- print(f\" {r['id']}: {r.get('status', 'unknown')} — {r.get('title', '')}\")
1005
- print(len(bad))
1006
- " "$refactor_list" 2>/dev/null || echo "0"; } | tee /dev/stderr | tail -1)
1007
-
1008
- if [[ "$incomplete_count" -gt 0 ]]; then
1009
- echo ""
1010
- log_warn "DEPLOY BLOCKED: $incomplete_count refactor(s) not completed successfully."
1011
- log_warn "Fix failed refactors and re-run, or manually run /prizmkit-deploy."
1012
- else
1013
- echo ""
1014
- log_info "All refactors completed — starting deploy session..."
1015
- log_info "ENABLE_DEPLOY=1"
1016
-
1017
- local deploy_session_id="deploy-$(date +%Y%m%d%H%M%S)"
1018
- local deploy_session_dir="$STATE_DIR/deploy/$deploy_session_id"
1019
- mkdir -p "$deploy_session_dir/logs"
1020
-
1021
- local deploy_prompt="$deploy_session_dir/bootstrap-prompt.md"
1022
- local _deploy_branch _deploy_commit
1023
- _deploy_branch=$(git -C "$_proj_root" rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
1024
- _deploy_commit=$(git -C "$_proj_root" rev-parse --short HEAD 2>/dev/null || echo "unknown")
1025
- cat > "$deploy_prompt" << DEPLOY_PROMPT_EOF
1026
- ## Deploy
1027
-
1028
- All refactor tasks have been completed successfully.
1029
-
1030
- - Branch: $_deploy_branch
1031
- - Commit: $_deploy_commit
1032
-
1033
- Run /prizmkit-deploy to deploy the project. Read .prizmkit/deploy/deploy.config.json
1034
- for deployment configuration. If no deploy config exists, guide the user through
1035
- setting one up before deploying.
1036
- DEPLOY_PROMPT_EOF
1037
-
1038
- log_info "Deploy prompt: $deploy_prompt"
1039
- log_info "Deploy log: $deploy_session_dir/logs/session.log"
1040
-
1041
- prizm_run_ai_session "$deploy_prompt" "$deploy_session_dir/logs/session.log"
1042
- local deploy_exit=$?
1043
-
1044
- # Recover log from backup if truncated
1045
- prizm_recover_session_log "$deploy_session_dir/logs/session.log"
1046
-
1047
- if [[ $deploy_exit -eq 0 ]]; then
1048
- log_success "Deploy session completed (exit 0)"
1049
- else
1050
- log_warn "Deploy session exited with code $deploy_exit"
1051
- log_warn "Review log: $deploy_session_dir/logs/session.log"
1052
- fi
1053
- fi
1054
- fi
1055
-
1056
- break
1057
- fi
1058
-
1059
- if [[ "$next_refactor" == "PIPELINE_BLOCKED" ]]; then
1060
- log_warn "All remaining refactors are blocked (failed/dependency unmet)."
1061
- log_warn "Run './run-refactor.sh status' to see details."
1062
- log_warn "Waiting 60s before re-checking... (Ctrl+C to stop)"
1063
- sleep 60
1064
- continue
1065
- fi
1066
-
1067
- # Parse refactor info
1068
- local refactor_id refactor_title refactor_complexity retry_count infra_error_count resume_phase active_dev_branch base_branch continuation_pending continuation_reason context_overflow_count continuation_count previous_session_id no_progress_count
1069
- refactor_id=$(echo "$next_refactor" | jq -r '.refactor_id')
1070
- refactor_title=$(echo "$next_refactor" | jq -r '.title')
1071
- refactor_complexity=$(echo "$next_refactor" | jq -r '.complexity')
1072
- retry_count=$(echo "$next_refactor" | jq -r '.retry_count // 0')
1073
- infra_error_count=$(echo "$next_refactor" | jq -r '.infra_error_count // 0')
1074
- resume_phase=$(echo "$next_refactor" | jq -r '.resume_from_phase // "null"')
1075
- active_dev_branch=$(echo "$next_refactor" | jq -r '.active_dev_branch // ""')
1076
- base_branch=$(echo "$next_refactor" | jq -r '.base_branch // ""')
1077
- continuation_pending=$(echo "$next_refactor" | jq -r '.continuation_pending // false')
1078
- continuation_reason=$(echo "$next_refactor" | jq -r '.continuation_reason // ""')
1079
- context_overflow_count=$(echo "$next_refactor" | jq -r '.context_overflow_count // 0')
1080
- continuation_count=$(echo "$next_refactor" | jq -r '.continuation_count // 0')
1081
- previous_session_id=$(echo "$next_refactor" | jq -r '.last_context_overflow_session_id // ""')
1082
- no_progress_count=$(echo "$next_refactor" | jq -r '.no_progress_count // 0')
1083
-
1084
- echo ""
1085
- echo -e "${BOLD}────────────────────────────────────────────────────${NC}"
1086
- log_info "Refactor: ${BOLD}$refactor_id${NC} — $refactor_title"
1087
- log_info "Complexity: $refactor_complexity"
1088
- log_info "Code retry: $retry_count / $MAX_RETRIES"
1089
- log_info "Infrastructure retry: $infra_error_count / $MAX_INFRA_RETRIES"
1090
- if [[ "$resume_phase" != "null" ]]; then
1091
- log_info "Resuming from Phase $resume_phase"
1092
- fi
1093
- if [[ "$continuation_pending" == "true" && -n "$active_dev_branch" ]]; then
1094
- log_info "Continuation pending (${continuation_reason:-context_overflow}); reusing dev branch: $active_dev_branch"
1095
- log_info "Continuation count: $continuation_count (context overflows: $context_overflow_count)"
1096
- fi
1097
- echo -e "${BOLD}────────────────────────────────────────────────────${NC}"
1098
-
1099
- # Auto-commit any uncommitted workspace changes before starting the pipeline.
1100
- # This ensures a clean baseline without blocking execution.
1101
- local _dirty_files=""
1102
- _dirty_files=$(prizm_git_status_non_bookkeeping "$_proj_root" "$STATE_DIR" "$refactor_list" || true)
1103
- if [[ -n "$_dirty_files" ]]; then
1104
- log_info "Auto-committing workspace changes before $refactor_id..."
1105
- prizm_git_add_all_safe "$_proj_root"
1106
- git -C "$_proj_root" commit --no-verify -m "chore: workspace snapshot ready for run $refactor_id" 2>/dev/null || true
1107
- fi
1108
-
1109
- local _bookkeeping_dirty=""
1110
- _bookkeeping_dirty=$(prizm_git_status_bookkeeping "$_proj_root" "$STATE_DIR" "$refactor_list" || true)
1111
- if [[ -n "$_bookkeeping_dirty" ]]; then
1112
- log_info "Committing pending pipeline bookkeeping before $refactor_id..."
1113
- prizm_git_commit_paths "$_proj_root" "chore($refactor_id): include pipeline bookkeeping" "$refactor_list" "$STATE_DIR"
1114
- fi
1115
-
1116
- # Mark refactor as in-progress BEFORE creating dev branch
1117
- # This ensures the in_progress status commit lands on the original branch,
1118
- # not the dev branch — preventing rebase conflicts in branch_merge later.
1119
- python3 "$SCRIPTS_DIR/update-refactor-status.py" \
1120
- --refactor-list "$refactor_list" \
1121
- --state-dir "$STATE_DIR" \
1122
- --refactor-id "$refactor_id" \
1123
- --action start >/dev/null 2>&1 || true
1124
- # Commit the in_progress status on the original branch
1125
- if ! git -C "$_proj_root" diff --quiet "$refactor_list" 2>/dev/null; then
1126
- prizm_git_commit_paths "$_proj_root" "chore($refactor_id): mark in_progress" "$refactor_list"
1127
- fi
1128
-
1129
- # Continuation base branch from runtime state is authoritative for branch reuse.
1130
- if [[ "$continuation_pending" == "true" && -n "$base_branch" ]]; then
1131
- _ORIGINAL_BRANCH="$base_branch"
1132
- fi
1133
-
1134
- # Create or reuse per-refactor dev branch (from the now-updated original branch)
1135
- local _refactor_branch
1136
- if [[ -n "$DEV_BRANCH" ]]; then
1137
- _refactor_branch="$DEV_BRANCH"
1138
- elif [[ "$continuation_pending" == "true" && -n "$active_dev_branch" ]]; then
1139
- _refactor_branch="$active_dev_branch"
1140
- else
1141
- _refactor_branch="refactor/${refactor_id}-$(date +%Y%m%d%H%M)"
1142
- fi
1143
- if branch_create "$_proj_root" "$_refactor_branch" "$_ORIGINAL_BRANCH"; then
1144
- _DEV_BRANCH_NAME="$_refactor_branch"
1145
- log_info "Dev branch: $_refactor_branch"
1146
- else
1147
- log_error "Failed to create dev branch: $_refactor_branch from $_ORIGINAL_BRANCH — aborting to avoid running on $_ORIGINAL_BRANCH"
1148
- _DEV_BRANCH_NAME=""
1149
- break
1150
- fi
1151
-
1152
- while true; do
1153
- # Generate session
1154
- local session_id run_id
1155
- run_id=$(jq -r '.run_id' "$STATE_DIR/pipeline.json")
1156
- session_id="${refactor_id}-$(date +%Y%m%d%H%M%S)"
1157
-
1158
- local session_dir="$STATE_DIR/$refactor_id/sessions/$session_id"
1159
- mkdir -p "$session_dir/logs"
1160
-
1161
- local bootstrap_prompt="$session_dir/bootstrap-prompt.md"
1162
- local continuation_summary_path=".prizmkit/refactor/${refactor_id}/continuation-summary.md"
1163
-
1164
- local main_prompt_args=(
1165
- --refactor-list "$refactor_list"
1166
- --refactor-id "$refactor_id"
1167
- --session-id "$session_id"
1168
- --run-id "$run_id"
1169
- --retry-count "$retry_count"
1170
- --resume-phase "$resume_phase"
1171
- --state-dir "$STATE_DIR"
1172
- --output "$bootstrap_prompt"
1173
- )
1174
-
1175
- if [[ "$continuation_pending" == "true" ]]; then
1176
- main_prompt_args+=(
1177
- --continuation-mode "${continuation_reason:-context_overflow}"
1178
- --previous-session-id "$previous_session_id"
1179
- --continuation-count "$continuation_count"
1180
- --context-overflow-count "$context_overflow_count"
1181
- --task-type "refactor"
1182
- --active-dev-branch "$active_dev_branch"
1183
- --base-branch "$base_branch"
1184
- --continuation-summary-path "$continuation_summary_path"
1185
- )
1186
- fi
1187
-
1188
- # Support PIPELINE_MODE env var (set by launch-refactor-daemon.sh --mode)
1189
- if [[ -n "${PIPELINE_MODE:-}" ]]; then
1190
- main_prompt_args+=(--mode "$PIPELINE_MODE")
1191
- fi
1192
-
1193
- # Support ENABLE_CRITIC env var (set by launch-refactor-daemon.sh --critic)
1194
- if [[ "${ENABLE_CRITIC:-}" == "true" || "${ENABLE_CRITIC:-}" == "1" ]]; then
1195
- main_prompt_args+=(--critic "true")
1196
- elif [[ "${ENABLE_CRITIC:-}" == "false" || "${ENABLE_CRITIC:-}" == "0" ]]; then
1197
- main_prompt_args+=(--critic "false")
1198
- fi
1199
-
1200
- local gen_output
1201
- gen_output=$(python3 "$SCRIPTS_DIR/generate-refactor-prompt.py" "${main_prompt_args[@]}" 2>/dev/null) || {
1202
- log_error "Failed to generate bootstrap prompt for $refactor_id"
1203
- branch_ensure_return "$_proj_root" "$_ORIGINAL_BRANCH"
1204
- _DEV_BRANCH_NAME=""
1205
- continue 2
1206
- }
1207
- local refactor_model pipeline_mode agent_count critic_enabled
1208
- refactor_model=$(echo "$gen_output" | python3 -c "import json,sys; print(json.load(sys.stdin).get('model',''))" 2>/dev/null || echo "")
1209
- pipeline_mode=$(echo "$gen_output" | python3 -c "import json,sys; print(json.load(sys.stdin).get('pipeline_mode','standard'))" 2>/dev/null || echo "standard")
1210
- agent_count=$(echo "$gen_output" | python3 -c "import json,sys; print(json.load(sys.stdin).get('agent_count',3))" 2>/dev/null || echo "3")
1211
- critic_enabled=$(echo "$gen_output" | python3 -c "import json,sys; print(json.load(sys.stdin).get('critic_enabled','false'))" 2>/dev/null || echo "false")
1212
-
1213
- # Log pipeline mode and agent configuration
1214
- local _mode_desc
1215
- case "$pipeline_mode" in
1216
- lite) _mode_desc="Tier 1 — Single Agent" ;;
1217
- standard) _mode_desc="Tier 2 — Orchestrator + Dev + Reviewer" ;;
1218
- full) _mode_desc="Tier 3 — Full Team (+ Multi-Critic)" ;;
1219
- *) _mode_desc="$pipeline_mode" ;;
1220
- esac
1221
- log_info "Pipeline mode: ${BOLD}$pipeline_mode${NC} ($_mode_desc)"
1222
- log_info "Agents: $agent_count (critic: $([ "$critic_enabled" = "true" ] && echo "enabled" || echo "disabled"))"
1223
-
1224
- if [[ -n "$refactor_model" ]]; then
1225
- log_info "Refactor model: $refactor_model"
1226
- fi
1227
-
1228
- local continuation_artifact_dir=".prizmkit/refactor/${refactor_id}"
1229
- local continuation_checkpoint_path="$continuation_artifact_dir/workflow-checkpoint.json"
1230
- local progress_before progress_after
1231
- progress_before=$(prizm_context_progress_fingerprint "$_proj_root" "refactor" "$refactor_id" "$continuation_artifact_dir" "$continuation_checkpoint_path")
1232
-
1233
- # Spawn session
1234
- log_info "Spawning AI CLI session: $session_id"
1235
- _SPAWN_RESULT=""
1236
- _SPAWN_ITEM_STATUS=""
1237
-
1238
- spawn_and_wait_session \
1239
- "$refactor_id" "$refactor_list" "$session_id" \
1240
- "$bootstrap_prompt" "$session_dir" "$MAX_RETRIES" "$MAX_INFRA_RETRIES" "$refactor_model" "$_ORIGINAL_BRANCH"
1241
-
1242
- # Validate key artifacts after successful session
1243
- if [[ "$_SPAWN_RESULT" == "success" ]]; then
1244
- local plan_file="$PRIZMKIT_DIR/refactor/$refactor_id/plan.md"
1245
- if [[ ! -f "$plan_file" ]]; then
1246
- log_warn "ARTIFACT_MISSING: plan.md not found at $plan_file"
1247
- else
1248
- log_info "ARTIFACT_CHECK: plan.md exists for $refactor_id"
1249
- fi
1250
- fi
1251
-
1252
- local session_status="$_SPAWN_RESULT"
1253
-
1254
- # Merge per-refactor dev branch back to original on success
1255
- local active_dev_branch_for_status="$_DEV_BRANCH_NAME"
1256
- if [[ "$session_status" == "context_overflow" ]]; then
1257
- progress_after=$(prizm_context_progress_fingerprint "$_proj_root" "refactor" "$refactor_id" "$continuation_artifact_dir" "$continuation_checkpoint_path")
1258
- if prizm_context_progress_changed "$progress_before" "$progress_after"; then
1259
- no_progress_count=0
1260
- log_info "Context-overflow session made observable progress; continuing on $_DEV_BRANCH_NAME"
1261
- else
1262
- no_progress_count=$((no_progress_count + 1))
1263
- log_warn "Context-overflow session made no observable progress ($no_progress_count consecutive)"
1264
- fi
1265
- if [[ "$no_progress_count" -ge 2 ]]; then
1266
- log_warn "Pausing automatic continuation: context_overflow_without_git_checkpoint_or_artifact_progress"
1267
- session_status="stalled_context_continuation"
1268
- else
1269
- finalize_refactor_status_after_branch_return \
1270
- "$refactor_id" "$refactor_list" "$session_id" "$session_status" "$MAX_RETRIES" "$MAX_INFRA_RETRIES" "$_ORIGINAL_BRANCH" "$active_dev_branch_for_status" "context_overflow" "$continuation_summary_path" "$no_progress_count" "$progress_after"
1271
- session_count=$((session_count + 1))
1272
- total_subagent_calls=$((total_subagent_calls + _SUBAGENT_COUNT))
1273
- continuation_pending="true"
1274
- continuation_reason="context_overflow"
1275
- previous_session_id="$session_id"
1276
- active_dev_branch="$_DEV_BRANCH_NAME"
1277
- base_branch="$_ORIGINAL_BRANCH"
1278
- context_overflow_count=$((context_overflow_count + 1))
1279
- continuation_count=$((continuation_count + 1))
1280
- log_info "Launching automatic continuation for $refactor_id on same branch/worktree"
1281
- continue
1282
- fi
1283
- fi
1284
-
1285
- if [[ "$session_status" == "success" && -n "$_DEV_BRANCH_NAME" ]]; then
1286
- if branch_merge "$_proj_root" "$_DEV_BRANCH_NAME" "$_ORIGINAL_BRANCH" "$AUTO_PUSH"; then
1287
- _DEV_BRANCH_NAME=""
1288
- else
1289
- log_warn "Auto-merge failed — dev branch preserved: $_DEV_BRANCH_NAME"
1290
- log_warn "Merge manually: git checkout $_ORIGINAL_BRANCH && git rebase $_DEV_BRANCH_NAME"
1291
- session_status="merge_conflict"
1292
- fi
1293
- elif [[ -n "$_DEV_BRANCH_NAME" ]]; then
1294
- # Session failed — preserve dev branch for inspection
1295
- log_warn "Session failed — dev branch preserved for inspection: $_DEV_BRANCH_NAME"
1296
- fi
1297
-
1298
- # GUARANTEED: always return to original branch regardless of success/failure/merge outcome
1299
- branch_ensure_return "$_proj_root" "$_ORIGINAL_BRANCH"
1300
-
1301
- finalize_refactor_status_after_branch_return \
1302
- "$refactor_id" "$refactor_list" "$session_id" "$session_status" "$MAX_RETRIES" "$MAX_INFRA_RETRIES" "$_ORIGINAL_BRANCH" "$active_dev_branch_for_status" "context_overflow" "$continuation_summary_path" "$no_progress_count" "${progress_after:-}"
1303
- local item_status_after_session="${_SPAWN_ITEM_STATUS:-}"
1304
-
1305
- # Commit refactor status update on the original branch (after guaranteed return)
1306
- if ! git -C "$_proj_root" diff --quiet "$refactor_list" 2>/dev/null; then
1307
- prizm_git_commit_paths "$_proj_root" "chore($refactor_id): update refactor status" "$refactor_list"
1308
- fi
1309
-
1310
- # Stuck detection
1311
- if python3 "$SCRIPTS_DIR/detect-stuck.py" \
1312
- --state-dir "$STATE_DIR" \
1313
- --pipeline-type refactor \
1314
- --refactor-list "$REFACTOR_LIST" \
1315
- --max-retries "$MAX_RETRIES" \
1316
- 2>/dev/null | jq -e '.stuck_count > 0' >/dev/null 2>&1; then
1317
- log_warn "STUCK_DETECTED: Some refactors may be stuck — run detect-stuck.py for details"
1318
- fi
1319
-
1320
- session_count=$((session_count + 1))
1321
- total_subagent_calls=$((total_subagent_calls + _SUBAGENT_COUNT))
1322
- break
1323
- done
1324
-
1325
- # Stop-on-failure: abort only after the task is actually marked failed.
1326
- # Pending retry outcomes, including infrastructure errors, keep running.
1327
- if [[ "$session_status" != "success" && "$STOP_ON_FAILURE" == "1" && "$item_status_after_session" == "failed" ]]; then
1328
- echo ""
1329
- log_error "════════════════════════════════════════════════════"
1330
- log_error " STOP_ON_FAILURE: Pipeline halted after $refactor_id exhausted retries."
1331
- log_error " Total sessions completed: $session_count"
1332
- log_error " Set STOP_ON_FAILURE=0 to continue past failures."
1333
- log_error "════════════════════════════════════════════════════"
1334
- break
1335
- elif [[ "$session_status" != "success" && "$STOP_ON_FAILURE" == "1" ]]; then
1336
- log_info "STOP_ON_FAILURE: $refactor_id is ${item_status_after_session:-unknown}; code/infra retry budget not exhausted, continuing."
1337
- fi
1338
-
1339
- log_info "Pausing 5s before next refactor..."
1340
- sleep 5
1341
- done
1342
- }
1343
-
1344
- # ============================================================
1345
- # Entry Point
1346
- # ============================================================
1347
-
1348
- show_help() {
1349
- echo "Usage: $0 <command> [options]"
1350
- echo ""
1351
- echo "Commands:"
1352
- echo " run [.prizmkit/plans/refactor-list.json] [options] Run all refactors in dependency-topological order"
1353
- echo " run <refactor-id> [options] Run a single refactor"
1354
- echo " status [.prizmkit/plans/refactor-list.json] Show refactor pipeline status"
1355
- echo " reset Clear all refactor state"
1356
- echo " help Show this help message"
1357
- echo ""
1358
- echo "Single Refactor Options (run <refactor-id>):"
1359
- echo " --dry-run Generate bootstrap prompt only, don't spawn session"
1360
- echo " --clean Delete artifacts and reset before running"
1361
- echo " --no-reset Skip status reset (preserve retry count)"
1362
- echo " --max-infra-retries N Max infrastructure/provider retries (default: 3)"
1363
- echo " --mode <lite|standard|full> Override pipeline mode"
1364
- echo " --critic Enable adversarial critic review"
1365
- echo " --no-critic Disable adversarial critic review"
1366
- echo ""
1367
- echo "Pipeline Options (run all):"
1368
- echo " --max-infra-retries N Max infrastructure/provider retries (default: 3)"
1369
- echo ""
1370
- echo "Environment Variables:"
1371
- echo " MAX_RETRIES Max code retries per refactor (default: 3)"
1372
- echo " MAX_INFRA_RETRIES Max infrastructure/provider retries per refactor (default: 3)"
1373
- echo " MODEL Default AI model (overridden by per-refactor model in refactor list)"
1374
- echo " PRIZMKIT_EFFORT AI reasoning effort (low|medium|high|xhigh|max; max is Claude Code only)"
1375
- echo " PIPELINE_MODE Default pipeline mode: lite|standard|full (overridden by --mode)"
1376
- echo " ENABLE_CRITIC Enable/disable critic: true|false|1|0 (overridden by --critic/--no-critic)"
1377
- echo " AI_CLI AI CLI command name (auto-detected: cbc, claude, or codex)"
1378
- echo " VERBOSE Set to 1 for verbose AI CLI output"
1379
- echo " STRICT_BEHAVIOR_CHECK Force full test suite after each refactor (default: 1)"
1380
- echo " HEARTBEAT_INTERVAL Heartbeat log interval in seconds (default: 30)"
1381
- echo " STALE_KILL_THRESHOLD Auto-kill session after N seconds of no progress (default: 900)"
1382
- echo " MAX_LOG_SIZE Include passive log-size checkpoint guidance above this threshold (default: 2097152 = 2MB, set 0 to disable)"
1383
- echo " STOP_ON_FAILURE Stop pipeline when a task exhausts retries: 0|1 (default: 0)"
1384
- echo ""
1385
- echo "Examples:"
1386
- echo " ./run-refactor.sh run # Run all refactors"
1387
- echo " ./run-refactor.sh run .prizmkit/plans/refactor-list.json # Custom refactor list"
1388
- echo " ./run-refactor.sh run R-001 --dry-run # Inspect generated prompt"
1389
- echo " ./run-refactor.sh status # Show status"
1390
- echo " STRICT_BEHAVIOR_CHECK=0 ./run-refactor.sh run # Skip full test suite"
1391
- echo " MAX_RETRIES=5 ./run-refactor.sh run # Custom retries"
1392
- }
1393
-
1394
- case "${1:-run}" in
1395
- run|resume)
1396
- shift || true
1397
- if [[ "${1:-}" =~ ^[Rr]-[0-9]+ ]]; then
1398
- run_one "$@"
1399
- else
1400
- main "$@"
1401
- fi
1402
- ;;
1403
- status)
1404
- check_dependencies
1405
- if [[ ! -f "$STATE_DIR/pipeline.json" ]]; then
1406
- log_error "No refactor pipeline state found. Run './run-refactor.sh run' first."
1407
- exit 1
1408
- fi
1409
- python3 "$SCRIPTS_DIR/update-refactor-status.py" \
1410
- --refactor-list "${2:-$PRIZMKIT_DIR/plans/refactor-list.json}" \
1411
- --state-dir "$STATE_DIR" \
1412
- --max-retries "$MAX_RETRIES" \
1413
- --max-infra-retries "$MAX_INFRA_RETRIES" \
1414
- --action status
1415
- ;;
1416
- reset)
1417
- log_warn "Resetting refactor pipeline state..."
1418
- rm -rf "$STATE_DIR"
1419
- log_success "Refactor state cleared. Run './run-refactor.sh run' to start fresh."
1420
- ;;
1421
- unskip)
1422
- check_dependencies
1423
- if [[ ! -f "$STATE_DIR/pipeline.json" ]]; then
1424
- log_error "No refactor pipeline state found. Run './run-refactor.sh run' first."
1425
- exit 1
1426
- fi
1427
- _unskip_refactor_list="$PRIZMKIT_DIR/plans/refactor-list.json"
1428
- _unskip_refactor_id=""
1429
- shift || true
1430
- # Parse arguments: optional refactor-id and refactor-list path
1431
- while [[ $# -gt 0 ]]; do
1432
- if [[ "$1" =~ ^[Rr]-[0-9]+ ]]; then
1433
- _unskip_refactor_id="$1"
1434
- else
1435
- _unskip_refactor_list="$1"
1436
- fi
1437
- shift
1438
- done
1439
- _unskip_args=(
1440
- --refactor-list "$_unskip_refactor_list"
1441
- --state-dir "$STATE_DIR"
1442
- --action unskip
1443
- )
1444
- if [[ -n "$_unskip_refactor_id" ]]; then
1445
- _unskip_args+=(--refactor-id "$_unskip_refactor_id")
1446
- fi
1447
- python3 "$SCRIPTS_DIR/update-refactor-status.py" "${_unskip_args[@]}"
1448
-
1449
- # Commit the status change
1450
- if ! git diff --quiet "$_unskip_refactor_list" 2>/dev/null; then
1451
- git add "$_unskip_refactor_list"
1452
- git commit -m "chore: unskip auto-skipped refactors" 2>/dev/null || true
1453
- fi
1454
- ;;
1455
- help|--help|-h)
1456
- show_help
1457
- ;;
1458
- *)
1459
- log_error "Unknown command: $1"
1460
- show_help
1461
- exit 1
1462
- ;;
1463
- esac