okstra 0.206.0 → 0.207.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 (259) hide show
  1. package/README.md +3 -3
  2. package/dist/cli-registry.mjs +7 -1
  3. package/dist/cli-registry.mjs.map +1 -1
  4. package/dist/commands/lifecycle/install.mjs +1 -1
  5. package/dist/commands/lifecycle/install.mjs.map +1 -1
  6. package/docs/architecture/storage-model.md +1 -0
  7. package/docs/architecture.md +40 -16
  8. package/docs/cli.md +17 -15
  9. package/docs/contributor-change-matrix.md +3 -2
  10. package/docs/performance-improvement-plan-v2.md +1 -1
  11. package/docs/project-structure-overview.md +43 -20
  12. package/package.json +1 -1
  13. package/runtime/BUILD.json +2 -2
  14. package/runtime/agents/operations/code-review.json +1 -1
  15. package/runtime/bin/lib/okstra/usage.sh +3 -3
  16. package/runtime/bin/okstra-compact-reminder.sh +1 -1
  17. package/runtime/bin/okstra-spawn-followups.py +2 -2
  18. package/runtime/prompts/duties/direction-selection-worker.json +1 -1
  19. package/runtime/prompts/launch.template.md +2 -2
  20. package/runtime/prompts/lead/adapters/cmux.md +4 -3
  21. package/runtime/prompts/lead/context-loader.md +1 -1
  22. package/runtime/prompts/lead/convergence.md +44 -12
  23. package/runtime/prompts/lead/okstra-lead-contract.md +44 -73
  24. package/runtime/prompts/lead/phase-routing.md +64 -0
  25. package/runtime/prompts/lead/report-writer.md +10 -8
  26. package/runtime/prompts/lead/team-contract.md +1 -1
  27. package/runtime/prompts/profiles/_clarification-recommendation.md +4 -4
  28. package/runtime/prompts/profiles/_coding-conventions-preflight.md +1 -1
  29. package/runtime/prompts/profiles/_common-contract.md +2 -2
  30. package/runtime/prompts/profiles/_coverage-critic.md +1 -1
  31. package/runtime/prompts/profiles/forbidden-actions.json +0 -94
  32. package/runtime/prompts/wizard/prompts.ko.json +2 -1
  33. package/runtime/python/okstra_ctl/adapters/hosts/antigravity/relay.md +1 -1
  34. package/runtime/python/okstra_ctl/adapters/hosts/claude-code/relay.md +5 -5
  35. package/runtime/python/okstra_ctl/adapters/hosts/codex/relay.md +1 -1
  36. package/runtime/python/okstra_ctl/adapters/hosts/external/relay.md +3 -2
  37. package/runtime/python/okstra_ctl/adapters/hosts/grok/relay.md +1 -1
  38. package/runtime/python/okstra_ctl/adapters/hosts/kimi/relay.md +1 -1
  39. package/runtime/python/okstra_ctl/adapters/providers/codex/adapter.py +17 -26
  40. package/runtime/python/okstra_ctl/agent/prompt_cli/batch.py +183 -0
  41. package/runtime/python/okstra_ctl/agent/prompt_cli/cli.py +60 -10
  42. package/runtime/python/okstra_ctl/agent/prompt_cli/corrections.py +1 -1
  43. package/runtime/python/okstra_ctl/agent/prompt_cli/jobs.py +21 -4
  44. package/runtime/python/okstra_ctl/agent/prompt_cli/materialize.py +10 -1
  45. package/runtime/python/okstra_ctl/analysis_inputs.py +0 -39
  46. package/runtime/python/okstra_ctl/analysis_scope.py +31 -0
  47. package/runtime/python/okstra_ctl/approval_decisions.py +32 -2
  48. package/runtime/python/okstra_ctl/asset_roots.py +19 -0
  49. package/runtime/python/okstra_ctl/assignment_resolver.py +8 -0
  50. package/runtime/python/okstra_ctl/blocking_checks.py +7 -0
  51. package/runtime/python/okstra_ctl/code_review_target.py +92 -6
  52. package/runtime/python/okstra_ctl/consumers.py +12 -0
  53. package/runtime/python/okstra_ctl/dispatch_checkpoints.py +121 -0
  54. package/runtime/python/okstra_ctl/dispatch_core.py +54 -32
  55. package/runtime/python/okstra_ctl/dispatch_state.py +34 -5
  56. package/runtime/python/okstra_ctl/doctor.py +2 -1
  57. package/runtime/python/okstra_ctl/domain/provider.py +5 -0
  58. package/runtime/python/okstra_ctl/domain/worker_presentation.py +21 -2
  59. package/runtime/python/okstra_ctl/domain/write_policy.py +2 -1
  60. package/runtime/python/okstra_ctl/execution_mutation_audit.py +46 -9
  61. package/runtime/python/okstra_ctl/handoff.py +11 -466
  62. package/runtime/python/okstra_ctl/handoff_error.py +5 -0
  63. package/runtime/python/okstra_ctl/implementation_direction.py +0 -477
  64. package/runtime/python/okstra_ctl/initial_prompt_materialization.py +13 -1
  65. package/runtime/python/okstra_ctl/lead_progress.py +33 -1
  66. package/runtime/python/okstra_ctl/manager_view.py +26 -19
  67. package/runtime/python/okstra_ctl/model_io/lines.py +21 -4
  68. package/runtime/python/okstra_ctl/models.py +4 -1
  69. package/runtime/python/okstra_ctl/operation_invocation.py +11 -2
  70. package/runtime/python/okstra_ctl/option_comparison.py +3 -165
  71. package/runtime/python/okstra_ctl/option_votes.py +3 -191
  72. package/runtime/python/okstra_ctl/paths.py +8 -6
  73. package/runtime/python/okstra_ctl/phases/catalog.py +56 -12
  74. package/runtime/python/okstra_ctl/phases/change_impact_analysis/boundary.json +11 -0
  75. package/runtime/python/okstra_ctl/phases/change_impact_analysis/entry.py +39 -0
  76. package/runtime/python/okstra_ctl/{report_html/view_models/change_impact_analysis.py → phases/change_impact_analysis/report.py} +3 -3
  77. package/runtime/python/okstra_ctl/phases/change_impact_analysis/spec.md +26 -0
  78. package/runtime/python/okstra_ctl/phases/change_impact_analysis/validation.py +23 -0
  79. package/runtime/python/okstra_ctl/phases/error_analysis/__init__.py +1 -0
  80. package/runtime/python/okstra_ctl/phases/error_analysis/boundary.json +9 -0
  81. package/runtime/{prompts/profiles/error-analysis.md → python/okstra_ctl/phases/error_analysis/profile.md} +2 -2
  82. package/runtime/python/okstra_ctl/{report_html/view_models/error_analysis.py → phases/error_analysis/report.py} +9 -8
  83. package/runtime/{templates/reports → python/okstra_ctl/phases/error_analysis/report_assets}/error-analysis-input.template.md +1 -1
  84. package/runtime/python/okstra_ctl/phases/error_analysis/spec.md +118 -0
  85. package/runtime/python/okstra_ctl/phases/error_analysis/validation.py +241 -0
  86. package/runtime/python/okstra_ctl/phases/feature_analysis/__init__.py +1 -0
  87. package/runtime/python/okstra_ctl/phases/feature_analysis/boundary.json +8 -0
  88. package/runtime/python/okstra_ctl/phases/feature_analysis/entry.py +63 -0
  89. package/runtime/python/okstra_ctl/{report_html/view_models/feature_analysis.py → phases/feature_analysis/report.py} +12 -5
  90. package/runtime/python/okstra_ctl/phases/feature_analysis/spec.md +22 -0
  91. package/runtime/python/okstra_ctl/phases/feature_analysis/validation.py +27 -0
  92. package/runtime/python/okstra_ctl/phases/feature_analysis/wizard.py +95 -0
  93. package/runtime/python/okstra_ctl/phases/final_verification/boundary.json +8 -0
  94. package/runtime/python/okstra_ctl/phases/final_verification/profile.md +2 -2
  95. package/runtime/{templates/reports → python/okstra_ctl/phases/final_verification/report_assets}/final-verification-input.template.md +1 -1
  96. package/runtime/python/okstra_ctl/phases/final_verification/spec.md +1 -1
  97. package/runtime/python/okstra_ctl/phases/implementation/__init__.py +1 -0
  98. package/runtime/python/okstra_ctl/phases/implementation/boundary.json +17 -0
  99. package/runtime/python/okstra_ctl/{implementation_stage.py → phases/implementation/entry.py} +22 -10
  100. package/runtime/{prompts/host-orchestration/implementation.md → python/okstra_ctl/phases/implementation/host-rules.md} +1 -1
  101. package/runtime/{prompts/profiles → python/okstra_ctl/phases/implementation/instructions}/_implementation-deliverable.md +1 -1
  102. package/runtime/{prompts/profiles → python/okstra_ctl/phases/implementation/instructions}/_implementation-executor.md +4 -3
  103. package/runtime/{prompts/profiles → python/okstra_ctl/phases/implementation/instructions}/_implementation-verifier.md +18 -7
  104. package/runtime/{prompts/profiles/implementation.md → python/okstra_ctl/phases/implementation/profile.md} +5 -5
  105. package/runtime/python/okstra_ctl/{report_html/view_models/implementation.py → phases/implementation/report.py} +3 -3
  106. package/runtime/{templates/reports → python/okstra_ctl/phases/implementation/report_assets}/implementation-input.template.md +1 -1
  107. package/runtime/python/okstra_ctl/phases/implementation/spec.md +238 -0
  108. package/runtime/python/okstra_ctl/phases/implementation/validation.py +205 -0
  109. package/runtime/python/okstra_ctl/phases/implementation/wizard.py +39 -0
  110. package/runtime/python/okstra_ctl/phases/implementation_option_selection/__init__.py +1 -0
  111. package/runtime/python/okstra_ctl/phases/implementation_option_selection/authoring.py +80 -0
  112. package/runtime/python/okstra_ctl/phases/implementation_option_selection/boundary.json +10 -0
  113. package/runtime/python/okstra_ctl/phases/implementation_option_selection/comparison.py +168 -0
  114. package/runtime/python/okstra_ctl/phases/implementation_option_selection/entry.py +27 -0
  115. package/runtime/{prompts/profiles/implementation-option-selection.md → python/okstra_ctl/phases/implementation_option_selection/profile.md} +3 -3
  116. package/runtime/python/okstra_ctl/{report_html/view_models/implementation_option_selection.py → phases/implementation_option_selection/report.py} +2 -2
  117. package/runtime/python/okstra_ctl/phases/implementation_option_selection/spec.md +83 -0
  118. package/runtime/python/okstra_ctl/{implementation_options.py → phases/implementation_option_selection/validation.py} +3 -3
  119. package/runtime/python/okstra_ctl/phases/implementation_option_selection/votes.py +194 -0
  120. package/runtime/python/okstra_ctl/phases/implementation_planning/__init__.py +1 -0
  121. package/runtime/python/okstra_ctl/phases/implementation_planning/authoring.py +2345 -0
  122. package/runtime/python/okstra_ctl/phases/implementation_planning/boundary.json +12 -0
  123. package/runtime/python/okstra_ctl/phases/implementation_planning/entry.py +161 -0
  124. package/runtime/python/okstra_ctl/phases/implementation_planning/guidance.py +178 -0
  125. package/runtime/{prompts/lead → python/okstra_ctl/phases/implementation_planning/instructions}/plan-body-verification.md +61 -51
  126. package/runtime/python/okstra_ctl/phases/implementation_planning/plan_body.py +3295 -0
  127. package/runtime/{prompts/profiles/implementation-planning.md → python/okstra_ctl/phases/implementation_planning/profile.md} +74 -25
  128. package/runtime/python/okstra_ctl/phases/implementation_planning/report.py +237 -0
  129. package/runtime/{templates/reports → python/okstra_ctl/phases/implementation_planning/report_assets}/implementation-planning-input.template.md +2 -2
  130. package/runtime/python/okstra_ctl/phases/implementation_planning/spec.md +204 -0
  131. package/runtime/python/okstra_ctl/phases/implementation_planning/validation.py +597 -0
  132. package/runtime/python/okstra_ctl/phases/implementation_planning/wizard.py +166 -0
  133. package/runtime/python/okstra_ctl/phases/improvement_discovery/boundary.json +12 -0
  134. package/runtime/python/okstra_ctl/{improvement_lenses.py → phases/improvement_discovery/lenses.py} +1 -6
  135. package/runtime/{prompts/profiles/improvement-discovery.md → python/okstra_ctl/phases/improvement_discovery/profile.md} +5 -5
  136. package/runtime/python/okstra_ctl/{report_html/view_models/improvement_discovery.py → phases/improvement_discovery/report.py} +3 -3
  137. package/runtime/{templates/reports → python/okstra_ctl/phases/improvement_discovery/report_assets}/improvement-discovery-input.template.md +1 -2
  138. package/runtime/python/okstra_ctl/phases/improvement_discovery/spec.md +29 -0
  139. package/runtime/{validators/validate_improvement_report.py → python/okstra_ctl/phases/improvement_discovery/validation.py} +5 -14
  140. package/runtime/python/okstra_ctl/phases/project_analysis/__init__.py +1 -0
  141. package/runtime/python/okstra_ctl/phases/project_analysis/boundary.json +8 -0
  142. package/runtime/python/okstra_ctl/phases/project_analysis/entry.py +11 -0
  143. package/runtime/python/okstra_ctl/{report_html/view_models/project_analysis.py → phases/project_analysis/report.py} +3 -3
  144. package/runtime/python/okstra_ctl/phases/project_analysis/spec.md +33 -0
  145. package/runtime/python/okstra_ctl/phases/project_analysis/validation.py +55 -0
  146. package/runtime/python/okstra_ctl/phases/release_handoff/__init__.py +1 -0
  147. package/runtime/python/okstra_ctl/phases/release_handoff/boundary.json +17 -0
  148. package/runtime/python/okstra_ctl/phases/release_handoff/entry.py +147 -0
  149. package/runtime/python/okstra_ctl/phases/release_handoff/operations.py +446 -0
  150. package/runtime/{prompts/profiles/release-handoff.md → python/okstra_ctl/phases/release_handoff/profile.md} +3 -3
  151. package/runtime/python/okstra_ctl/{report_html/view_models/release_handoff.py → phases/release_handoff/report.py} +3 -3
  152. package/runtime/{templates/reports → python/okstra_ctl/phases/release_handoff/report_assets}/release-handoff-input.template.md +1 -1
  153. package/runtime/python/okstra_ctl/phases/release_handoff/spec.md +233 -0
  154. package/runtime/python/okstra_ctl/phases/release_handoff/wizard.py +84 -0
  155. package/runtime/python/okstra_ctl/phases/requirements_discovery/__init__.py +1 -0
  156. package/runtime/python/okstra_ctl/phases/requirements_discovery/boundary.json +9 -0
  157. package/runtime/{prompts/profiles/requirements-discovery.md → python/okstra_ctl/phases/requirements_discovery/profile.md} +2 -3
  158. package/runtime/python/okstra_ctl/{report_html/view_models/requirements_discovery.py → phases/requirements_discovery/report.py} +3 -3
  159. package/runtime/python/okstra_ctl/phases/requirements_discovery/spec.md +132 -0
  160. package/runtime/{validators/validate_fanout.py → python/okstra_ctl/phases/requirements_discovery/validation.py} +11 -12
  161. package/runtime/python/okstra_ctl/phases/technical_verification/__init__.py +1 -0
  162. package/runtime/python/okstra_ctl/phases/technical_verification/boundary.json +9 -0
  163. package/runtime/python/okstra_ctl/phases/technical_verification/entry.py +100 -0
  164. package/runtime/{prompts/profiles/technical-verification.md → python/okstra_ctl/phases/technical_verification/profile.md} +2 -2
  165. package/runtime/python/okstra_ctl/{report_html/view_models/technical_verification.py → phases/technical_verification/report.py} +2 -2
  166. package/runtime/python/okstra_ctl/phases/technical_verification/spec.md +37 -0
  167. package/runtime/python/okstra_ctl/phases/technical_verification/validation.py +90 -0
  168. package/runtime/python/okstra_ctl/plan_approval.py +70 -0
  169. package/runtime/python/okstra_ctl/plan_items_cli.py +2 -2130
  170. package/runtime/python/okstra_ctl/process_group.py +118 -0
  171. package/runtime/python/okstra_ctl/profile_show.py +3 -3
  172. package/runtime/python/okstra_ctl/render.py +15 -4
  173. package/runtime/python/okstra_ctl/report_assembly.py +28 -92
  174. package/runtime/python/okstra_ctl/report_finalize.py +106 -2
  175. package/runtime/python/okstra_ctl/report_html/context_links.py +1 -1
  176. package/runtime/python/okstra_ctl/report_projections.py +1 -36
  177. package/runtime/python/okstra_ctl/report_routing.py +23 -0
  178. package/runtime/python/okstra_ctl/report_synthesis_packet.py +4 -73
  179. package/runtime/python/okstra_ctl/report_validation_identity.py +38 -0
  180. package/runtime/python/okstra_ctl/report_views.py +1 -1
  181. package/runtime/python/okstra_ctl/run.py +68 -350
  182. package/runtime/python/okstra_ctl/run_artifact_prune.py +200 -0
  183. package/runtime/python/okstra_ctl/stage_map.py +13 -0
  184. package/runtime/python/okstra_ctl/team.py +108 -9
  185. package/runtime/python/okstra_ctl/technical_verification_facts.py +52 -0
  186. package/runtime/python/okstra_ctl/wizard/__init__.py +31 -31
  187. package/runtime/python/okstra_ctl/wizard/api.py +18 -0
  188. package/runtime/python/okstra_ctl/wizard/outcome.py +3 -12
  189. package/runtime/python/okstra_ctl/wizard/registry.py +20 -12
  190. package/runtime/python/okstra_ctl/wizard/steps_analysis.py +0 -97
  191. package/runtime/python/okstra_ctl/wizard/steps_options.py +8 -0
  192. package/runtime/python/okstra_ctl/wizard/steps_plan.py +10 -263
  193. package/runtime/python/okstra_ctl/wizard/steps_roles.py +2 -1
  194. package/runtime/python/okstra_ctl/work_categories.py +1 -1
  195. package/runtime/python/okstra_ctl/worker_dispatch.py +44 -3
  196. package/runtime/python/okstra_ctl/worker_prompt_contract.py +36 -0
  197. package/runtime/python/okstra_ctl/worker_prompt_policy.py +19 -0
  198. package/runtime/python/okstra_ctl/worker_runner.py +21 -3
  199. package/runtime/python/okstra_ctl/workflow.py +26 -143
  200. package/runtime/python/okstra_ctl/write_policy.py +57 -7
  201. package/runtime/python/okstra_project/dirs.py +14 -0
  202. package/runtime/python/okstra_project/resolver.py +2 -1
  203. package/runtime/schemas/execution-manifest-v2.schema.json +2 -1
  204. package/runtime/skills/okstra-brief-gen/SKILL.md +3 -3
  205. package/runtime/skills/okstra-code-review/SKILL.md +70 -32
  206. package/runtime/skills/okstra-code-review/references/review-calibration.md +26 -6
  207. package/runtime/skills/okstra-run/SKILL.md +3 -3
  208. package/runtime/templates/manager/view.template.html +18 -1
  209. package/runtime/templates/reports/quick-input.template.md +1 -1
  210. package/runtime/templates/reports/task-brief.template.md +1 -1
  211. package/runtime/validators/validate-brief.py +2 -2
  212. package/runtime/validators/validate-run.py +299 -3940
  213. package/runtime/validators/validate_analysis_report.py +14 -126
  214. package/runtime/python/okstra_ctl/report_html/view_models/implementation_planning.py +0 -147
  215. package/runtime/python/okstra_ctl/technical_verification.py +0 -195
  216. /package/runtime/{prompts/profiles/change-impact-analysis.json → python/okstra_ctl/phases/change_impact_analysis/profile.json} +0 -0
  217. /package/runtime/{prompts/profiles/change-impact-analysis.md → python/okstra_ctl/phases/change_impact_analysis/profile.md} +0 -0
  218. /package/runtime/{templates/reports → python/okstra_ctl/phases/change_impact_analysis/report_assets}/change-impact-analysis-input.template.md +0 -0
  219. /package/runtime/{templates/reports/html/tasks → python/okstra_ctl/phases/change_impact_analysis/report_assets}/change-impact-analysis.template.html +0 -0
  220. /package/runtime/{templates/reports/md/tasks → python/okstra_ctl/phases/change_impact_analysis/report_assets}/change-impact-analysis.template.md +0 -0
  221. /package/runtime/{prompts/profiles/error-analysis.json → python/okstra_ctl/phases/error_analysis/profile.json} +0 -0
  222. /package/runtime/{templates/reports/html/tasks → python/okstra_ctl/phases/error_analysis/report_assets}/error-analysis.template.html +0 -0
  223. /package/runtime/{templates/reports/md/tasks → python/okstra_ctl/phases/error_analysis/report_assets}/error-analysis.template.md +0 -0
  224. /package/runtime/{prompts/profiles/feature-analysis.json → python/okstra_ctl/phases/feature_analysis/profile.json} +0 -0
  225. /package/runtime/{prompts/profiles/feature-analysis.md → python/okstra_ctl/phases/feature_analysis/profile.md} +0 -0
  226. /package/runtime/{templates/reports → python/okstra_ctl/phases/feature_analysis/report_assets}/feature-analysis-input.template.md +0 -0
  227. /package/runtime/{templates/reports/html/tasks → python/okstra_ctl/phases/feature_analysis/report_assets}/feature-analysis.template.html +0 -0
  228. /package/runtime/{templates/reports/md/tasks → python/okstra_ctl/phases/feature_analysis/report_assets}/feature-analysis.template.md +0 -0
  229. /package/runtime/{prompts/profiles → python/okstra_ctl/phases/implementation/instructions}/_implementation-diff-review.md +0 -0
  230. /package/runtime/{prompts/profiles → python/okstra_ctl/phases/implementation/instructions}/_implementation-self-check.md +0 -0
  231. /package/runtime/{prompts/profiles/implementation.json → python/okstra_ctl/phases/implementation/profile.json} +0 -0
  232. /package/runtime/{templates/reports/html/tasks → python/okstra_ctl/phases/implementation/report_assets}/implementation.template.html +0 -0
  233. /package/runtime/{templates/reports/md/tasks → python/okstra_ctl/phases/implementation/report_assets}/implementation.template.md +0 -0
  234. /package/runtime/{prompts/profiles/implementation-option-selection.json → python/okstra_ctl/phases/implementation_option_selection/profile.json} +0 -0
  235. /package/runtime/{templates/reports/html/tasks → python/okstra_ctl/phases/implementation_option_selection/report_assets}/implementation-option-selection.template.html +0 -0
  236. /package/runtime/{templates/reports/md/tasks → python/okstra_ctl/phases/implementation_option_selection/report_assets}/implementation-option-selection.template.md +0 -0
  237. /package/runtime/{prompts/host-orchestration/implementation-planning.md → python/okstra_ctl/phases/implementation_planning/host-rules.md} +0 -0
  238. /package/runtime/{prompts/profiles/implementation-planning.json → python/okstra_ctl/phases/implementation_planning/profile.json} +0 -0
  239. /package/runtime/{templates/reports/html/tasks → python/okstra_ctl/phases/implementation_planning/report_assets}/implementation-planning.template.html +0 -0
  240. /package/runtime/{templates/reports/md/tasks → python/okstra_ctl/phases/implementation_planning/report_assets}/implementation-planning.template.md +0 -0
  241. /package/runtime/{prompts/profiles/improvement-discovery.json → python/okstra_ctl/phases/improvement_discovery/profile.json} +0 -0
  242. /package/runtime/{templates/reports/html/tasks → python/okstra_ctl/phases/improvement_discovery/report_assets}/improvement-discovery.template.html +0 -0
  243. /package/runtime/{templates/reports/md/tasks → python/okstra_ctl/phases/improvement_discovery/report_assets}/improvement-discovery.template.md +0 -0
  244. /package/runtime/{prompts/profiles/project-analysis.json → python/okstra_ctl/phases/project_analysis/profile.json} +0 -0
  245. /package/runtime/{prompts/profiles/project-analysis.md → python/okstra_ctl/phases/project_analysis/profile.md} +0 -0
  246. /package/runtime/{templates/reports → python/okstra_ctl/phases/project_analysis/report_assets}/project-analysis-input.template.md +0 -0
  247. /package/runtime/{templates/reports/html/tasks → python/okstra_ctl/phases/project_analysis/report_assets}/project-analysis.template.html +0 -0
  248. /package/runtime/{templates/reports/md/tasks → python/okstra_ctl/phases/project_analysis/report_assets}/project-analysis.template.md +0 -0
  249. /package/runtime/{prompts/profiles/release-handoff.json → python/okstra_ctl/phases/release_handoff/profile.json} +0 -0
  250. /package/runtime/{templates/reports/html/tasks → python/okstra_ctl/phases/release_handoff/report_assets}/release-handoff.template.html +0 -0
  251. /package/runtime/{templates/reports/md/tasks → python/okstra_ctl/phases/release_handoff/report_assets}/release-handoff.template.md +0 -0
  252. /package/runtime/python/okstra_ctl/{fanout.py → phases/requirements_discovery/fanout.py} +0 -0
  253. /package/runtime/{prompts/profiles/requirements-discovery.json → python/okstra_ctl/phases/requirements_discovery/profile.json} +0 -0
  254. /package/runtime/{templates/reports → python/okstra_ctl/phases/requirements_discovery/report_assets}/fan-out-unit.template.md +0 -0
  255. /package/runtime/{templates/reports/html/tasks → python/okstra_ctl/phases/requirements_discovery/report_assets}/requirements-discovery.template.html +0 -0
  256. /package/runtime/{templates/reports/md/tasks → python/okstra_ctl/phases/requirements_discovery/report_assets}/requirements-discovery.template.md +0 -0
  257. /package/runtime/{prompts/profiles/technical-verification.json → python/okstra_ctl/phases/technical_verification/profile.json} +0 -0
  258. /package/runtime/{templates/reports/html/tasks → python/okstra_ctl/phases/technical_verification/report_assets}/technical-verification.template.html +0 -0
  259. /package/runtime/{templates/reports/md/tasks → python/okstra_ctl/phases/technical_verification/report_assets}/technical-verification.template.md +0 -0
@@ -0,0 +1,446 @@
1
+ """단계별 전달 자격, PR 계획, 원격 조정과 로컬 인계 정책."""
2
+ from __future__ import annotations
3
+
4
+ import subprocess
5
+ from pathlib import Path
6
+ from typing import Any, Dict, List, Optional
7
+
8
+ from okstra_ctl import consumers, stage_targets, worktree_registry
9
+ from okstra_ctl.handoff_verification import verification_row_is_current
10
+ from okstra_ctl.handoff_error import HandoffError
11
+ from okstra_ctl.stage_integrate import (
12
+ IntegrateError, MergeBranchConflict, ensure_stage_merge_branch,
13
+ )
14
+ from okstra_ctl.worktree import (
15
+ compute_branch_name, main_worktree_path, is_dirty_excluding_okstra,
16
+ nested_worktree_excludes, is_ancestor, remove_worktree_force, _git,
17
+ )
18
+
19
+
20
+ class HandoffConflict(Exception):
21
+ """선행 stage 들 사이의 merge 충돌 — exit 2, 충돌 경로 동봉."""
22
+
23
+ def __init__(self, stage: int, branch: str, paths: List[str]):
24
+ self.stage = stage
25
+ self.branch = branch
26
+ self.paths = paths
27
+ super().__init__(
28
+ f"merge conflict while merging stage {stage} ({branch}): "
29
+ f"{', '.join(paths)}")
30
+
31
+
32
+ def compute_eligibility(stage_map: List[Dict[str, Any]],
33
+ rows: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
34
+ """stage 별 PR 가능 여부와 차단 사유. 의존이 어느 브랜치로 내려앉는지는
35
+ 선택 집합과 origin 의 상태가 정하므로 여기서는 판정하지 않는다
36
+ (`pr_plan` 의 base 해소가 담당)."""
37
+ eligibility = stage_targets.stage_lifecycle_snapshot_from_rows(
38
+ stage_map,
39
+ rows,
40
+ ).handoff_eligibility()
41
+ # 재구현된 stage 의 커밋 동일성은 `consumers.verified_accepted_stages` 가
42
+ # 이미 본다(`handoff_eligibility` 가 그 집합을 읽는다). 여기 남는 판정은
43
+ # "그 승인 행이 가리키는 검증 run 이 아직 최신인가" 하나다.
44
+ last = {row["stage"]: row for row in rows if row.get("status") == "verified"}
45
+ for item in eligibility:
46
+ if item["eligible"] and not verification_row_is_current(last.get(item["stage"], {})):
47
+ item["eligible"] = False
48
+ item["reasons"].append("verification-stale-or-unproven: re-run final-verification")
49
+ return eligibility
50
+
51
+
52
+ def _run_git(args: List[str], cwd, check: bool = True) -> subprocess.CompletedProcess:
53
+ """worktree._git(공용 러너) 위에 check=True 시 HandoffError 변환만 얹는다."""
54
+ r = _git(Path(cwd), *args)
55
+ if check and r.returncode != 0:
56
+ raise HandoffError(f"git {' '.join(args)} failed: {r.stderr.strip()}")
57
+ return r
58
+
59
+
60
+ def _require_eligible(stage_map, rows, stages) -> Dict[int, Dict[str, Any]]:
61
+ elig = {e["stage"]: e for e in compute_eligibility(stage_map, rows)}
62
+ unknown = [n for n in stages if n not in elig]
63
+ if unknown:
64
+ raise HandoffError(f"stages not in Stage Map: {unknown}")
65
+ bad = {n: elig[n]["reasons"] for n in stages if elig[n]["reasons"]}
66
+ if bad:
67
+ raise HandoffError(f"stages not eligible: {bad}")
68
+ return elig
69
+
70
+
71
+ def _branch_exists(project_root, branch: str) -> bool:
72
+ return _git(Path(project_root), "rev-parse", "--verify", "--quiet",
73
+ f"refs/heads/{branch}").returncode == 0
74
+
75
+
76
+ def _stage_branch(work_category: str, task_id: str, stage: int) -> str:
77
+ return compute_branch_name(work_category=work_category,
78
+ task_id_segment=task_id, stage_number=stage)
79
+
80
+
81
+ def _done_head(done: Dict[int, Dict[str, Any]], stage: int) -> str:
82
+ head = (done.get(stage) or {}).get("head_commit", "")
83
+ if not head:
84
+ raise HandoffError(
85
+ f"stage {stage} has no done row with head_commit in "
86
+ "consumers.jsonl — finish that implementation stage first")
87
+ return head
88
+
89
+
90
+ def _merge_base_for(*, project_root, project_id, task_group, task_id,
91
+ work_category, heads, anchor_base):
92
+ """선행들을 담은 바닥 브랜치. 원시연산은 잠금 없이 돌므로 여기서 task-key
93
+ 락을 잡는다 — implementation 경로는 이미 그 락 안에서 직접 부른다.
94
+ 기존 브랜치에 빠진 commit 이 있으면 거부한다: 그 브랜치는 이미 열린 PR 의
95
+ base 일 수 있고, 말없이 옮기면 리뷰어가 본 diff 가 바뀐다."""
96
+ from okstra_project.dirs import okstra_home
97
+
98
+ from okstra_ctl.locks import worktree_provision_mutex
99
+
100
+ try:
101
+ with worktree_provision_mutex(okstra_home(), project_id, task_group,
102
+ task_id):
103
+ return ensure_stage_merge_branch(
104
+ project_root=project_root, project_id=project_id,
105
+ task_group=task_group, task_id=task_id,
106
+ work_category=work_category, heads=heads,
107
+ anchor_base=anchor_base)
108
+ except MergeBranchConflict as exc:
109
+ raise HandoffConflict(stage=exc.stage, branch=exc.branch,
110
+ paths=exc.paths) from exc
111
+ except IntegrateError as exc:
112
+ raise HandoffError(str(exc)) from exc
113
+
114
+
115
+ def _resolve_stage_base(
116
+ *, stage: int, deps: List[int], selected: List[int], pr_covered: set,
117
+ done: Dict[int, Dict[str, Any]], project_root, base_branch: str,
118
+ work_category: str, task_id: str, project_id: str, task_group: str,
119
+ anchor_base: str,
120
+ ) -> Dict[str, Any]:
121
+ """한 stage 의 PR base. 이미 릴리스 base 에 들어간 선행은 base 를 올리지
122
+ 않으므로 제외하고, 남은 선행의 개수가 모양을 정한다."""
123
+ live = [d for d in sorted(deps)
124
+ if not is_ancestor(project_root, _done_head(done, d),
125
+ f"origin/{base_branch}")]
126
+ if not live:
127
+ commit = _run_git(["rev-parse", f"origin/{base_branch}"],
128
+ project_root).stdout.strip()
129
+ return {"base_kind": "release-base", "base_branch": base_branch,
130
+ "base_commit": commit, "base_stages": []}
131
+
132
+ undelivered = [d for d in live if d not in selected and d not in pr_covered]
133
+ if undelivered:
134
+ raise HandoffError(
135
+ f"stage {stage} depends on stage(s) {undelivered}, which are "
136
+ f"neither selected in this run nor already PR'd nor merged into "
137
+ f"origin/{base_branch} — a stacked PR needs its base branch to "
138
+ "exist on origin, so include them in this handoff or merge them "
139
+ "first")
140
+
141
+ if len(live) == 1:
142
+ dep = live[0]
143
+ branch = _stage_branch(work_category, task_id, dep)
144
+ if not _branch_exists(project_root, branch):
145
+ raise HandoffError(
146
+ f"stage {stage} needs branch {branch} (stage {dep}) as its PR "
147
+ "base, but that branch no longer exists in this repository")
148
+ return {"base_kind": "stage", "base_branch": branch,
149
+ "base_commit": _done_head(done, dep), "base_stages": [dep]}
150
+
151
+ merged = _merge_base_for(
152
+ project_root=project_root, project_id=project_id,
153
+ task_group=task_group, task_id=task_id, work_category=work_category,
154
+ heads={n: _done_head(done, n) for n in live}, anchor_base=anchor_base)
155
+ return {"base_kind": "merge-base", "base_branch": merged.branch,
156
+ "base_commit": merged.commit, "base_stages": list(merged.stages),
157
+ "base_merge_commits": list(merged.merge_commits),
158
+ "base_branch_created": merged.created}
159
+
160
+
161
+ def _local_tip(project_root, branch: str) -> str:
162
+ """로컬 브랜치의 현재 커밋. 없으면 빈 문자열."""
163
+ return _git(Path(project_root), "rev-parse", "--verify", "--quiet",
164
+ f"refs/heads/{branch}").stdout.strip()
165
+
166
+
167
+ def _remote_tips(project_root, branches: List[str]) -> Dict[str, str]:
168
+ """origin 이 지금 가진 브랜치와 커밋. 없는 브랜치는 키가 없다.
169
+
170
+ `ls-remote` 로 묻는다 — 비교하려고 ref 를 쓰지 않고, 없는 브랜치를 fetch
171
+ 하려다 실패하지도 않는다.
172
+ """
173
+ if not branches:
174
+ return {}
175
+ res = _git(Path(project_root), "ls-remote", "--heads", "origin", *branches)
176
+ if res.returncode != 0:
177
+ raise HandoffError(f"cannot read origin branch state: {res.stderr.strip()}")
178
+ tips: Dict[str, str] = {}
179
+ for line in res.stdout.splitlines():
180
+ parts = line.split()
181
+ if len(parts) == 2 and parts[1].startswith("refs/heads/"):
182
+ tips[parts[1][len("refs/heads/"):]] = parts[0]
183
+ return tips
184
+
185
+
186
+ def _branch_worktree(project_root, branch: str) -> Optional[Path]:
187
+ """그 브랜치를 체크아웃해 둔 워크트리. 없으면 None.
188
+
189
+ 체크아웃된 브랜치는 `git branch -f` 로 옮길 수 없으므로, fast-forward 는 그
190
+ 워크트리 안에서 해야 한다.
191
+ """
192
+ res = _git(Path(project_root), "worktree", "list", "--porcelain")
193
+ if res.returncode != 0:
194
+ return None
195
+ current: Optional[Path] = None
196
+ for line in res.stdout.splitlines():
197
+ if line.startswith("worktree "):
198
+ current = Path(line[len("worktree "):].strip())
199
+ elif line.strip() == f"branch refs/heads/{branch}":
200
+ return current
201
+ return None
202
+
203
+
204
+ def _fast_forward_local(project_root, branch: str, remote_commit: str) -> None:
205
+ """로컬 브랜치를 origin 의 커밋으로 fast-forward 한다.
206
+
207
+ 호출자가 조상 관계를 이미 확인했으므로 내용이 사라질 수 없다. 체크아웃
208
+ 상태면 그 워크트리에서 `merge --ff-only` 로, 아니면 ref 를 옮긴다.
209
+ """
210
+ _run_git(["fetch", "origin", branch], project_root)
211
+ holder = _branch_worktree(project_root, branch)
212
+ if holder is None:
213
+ _run_git(["branch", "-f", branch, remote_commit], project_root)
214
+ return
215
+ if is_dirty_excluding_okstra(holder):
216
+ raise HandoffError(
217
+ f"branch {branch} is behind origin and is checked out in {holder}, "
218
+ "which has uncommitted changes — commit or stash them so the "
219
+ "branch can be fast-forwarded to origin")
220
+ _run_git(["merge", "--ff-only", remote_commit], holder)
221
+
222
+
223
+ def _plan_branch_order(planned: List[Dict[str, Any]]) -> List[tuple[str, str]]:
224
+ ordered: List[tuple[str, str]] = []
225
+ seen: set[str] = set()
226
+ for row in planned:
227
+ if row["base_kind"] == "merge-base" and row["base_branch"] not in seen:
228
+ seen.add(row["base_branch"])
229
+ ordered.append((row["base_branch"], row["base_commit"]))
230
+ for row in planned:
231
+ if row["head_branch"] not in seen:
232
+ seen.add(row["head_branch"])
233
+ ordered.append((row["head_branch"], row["head_commit"]))
234
+ return ordered
235
+
236
+
237
+ def _reconcile_with_origin(
238
+ project_root, planned: List[Dict[str, Any]],
239
+ ) -> tuple[List[Dict[str, Any]], List[str]]:
240
+ """PR 이 올라앉을 브랜치를 origin 기준으로 맞춘다.
241
+
242
+ PR 의 head 와 base 는 GitHub 이 **이름으로 origin 에서** 찾는다. 계획이
243
+ 로컬 ref 만 보고 짜이던 동안, origin 의 같은 이름이 다른 커밋에 있어도
244
+ 계획은 그 사실을 몰랐다 — push 단계에서 거절되거나, PR 의 diff 가 계획서의
245
+ 커밋과 달랐다.
246
+
247
+ 네 가지 상태를 가른다. origin 에 없거나 뒤처져 있으면 push 가 해결하므로
248
+ 무엇을 어떤 순서로 올려야 하는지만 계획에 싣는다. origin 이 앞서 있으면
249
+ 로컬을 fast-forward 하고, 그 추가 커밋이 이 run 이 검증한 범위 밖이라는
250
+ 사실을 경고로 남긴다. 갈라져 있으면 거절한다 — 그 상태를 push 로 넘기는
251
+ 길은 force 뿐이고, 그건 열린 PR 의 리뷰 커밋을 지운다.
252
+ """
253
+ order = _plan_branch_order(planned)
254
+ tips = _remote_tips(project_root, [branch for branch, _ in order])
255
+ push_plan: List[Dict[str, Any]] = []
256
+ warnings: List[str] = []
257
+ for branch, recorded in order:
258
+ local = _local_tip(project_root, branch)
259
+ if not local:
260
+ raise HandoffError(
261
+ f"branch {branch} does not exist in this repository — there is "
262
+ "nothing to open a PR from")
263
+ # tip 이 기록된 커밋보다 앞선 것은 정상 상태다 — git-reconcile 이 done
264
+ # 이후의 커밋을 그 브랜치에 남긴다. 담기지 않은 것만 거절한다: 검증한
265
+ # 커밋이 브랜치에 없으면 그 PR 은 검증된 것을 나르지 않는다.
266
+ if recorded and local != recorded:
267
+ if not is_ancestor(project_root, recorded, local):
268
+ raise HandoffError(
269
+ f"branch {branch} is at {local}, which does not contain the "
270
+ f"commit this task's ledger verified for it ({recorded}) — "
271
+ "the branch was rewritten, so its PR would not carry the "
272
+ "verified work")
273
+ warnings.append(
274
+ f"branch {branch} is ahead of the commit this run verified "
275
+ f"({recorded} -> {local}); the commits it adds are outside the "
276
+ "verified scope")
277
+ remote = tips.get(branch)
278
+ if remote is None:
279
+ action = "create"
280
+ elif remote == local:
281
+ action = "up-to-date"
282
+ elif is_ancestor(project_root, remote, local):
283
+ action = "fast-forward"
284
+ elif is_ancestor(project_root, local, remote):
285
+ _fast_forward_local(project_root, branch, remote)
286
+ action = "up-to-date"
287
+ warnings.append(
288
+ f"branch {branch} was behind origin ({local} -> {remote}) and "
289
+ "was fast-forwarded to it; the commits origin adds are outside "
290
+ f"what this run verified ({recorded or local})")
291
+ else:
292
+ raise HandoffError(
293
+ f"branch {branch} and origin/{branch} have diverged (local "
294
+ f"{local}, origin {remote}) — only a force push could deliver "
295
+ "this branch, which would drop the commits origin holds")
296
+ push_plan.append({"branch": branch, "commit": local, "action": action})
297
+ return push_plan, warnings
298
+
299
+
300
+ def pr_plan(*, project_root, plan_run_root, stage_map, stages, base_branch,
301
+ work_category, project_id, task_group, task_id) -> Dict[str, Any]:
302
+ """선택한 stage 각각의 PR head/base 를 정하고, 필요한 선행 머지 브랜치를
303
+ 만든다. PR 은 stage 당 하나이고 head 는 그 stage 의 스택 브랜치다 — 커밋
304
+ 히스토리를 접지 않으므로 이 경로는 stage 브랜치를 고쳐 쓰지 않는다."""
305
+ stages = sorted(set(stages))
306
+ rows = consumers.read_consumers(Path(plan_run_root))
307
+ _require_eligible(stage_map, rows, stages)
308
+ _run_git(["fetch", "origin", base_branch], project_root)
309
+ done = consumers.latest_done_by_stage(rows)
310
+ pr_covered = consumers.pr_covered_stages(rows)
311
+ by_n = {s["stage_number"]: s for s in stage_map}
312
+ anchor_base = worktree_registry.get_implementation_base(
313
+ project_id, task_group, task_id) or ""
314
+
315
+ planned: List[Dict[str, Any]] = []
316
+ for n in stages:
317
+ head_branch = _stage_branch(work_category, task_id, n)
318
+ if not _branch_exists(project_root, head_branch):
319
+ raise HandoffError(
320
+ f"stage {n} branch {head_branch} does not exist in this "
321
+ "repository — it was deleted, so there is nothing to open a "
322
+ "PR from")
323
+ row = {
324
+ "stage": n,
325
+ "head_branch": head_branch,
326
+ "head_commit": _done_head(done, n),
327
+ **_resolve_stage_base(
328
+ stage=n, deps=list(by_n[n]["depends_on"]), selected=stages,
329
+ pr_covered=pr_covered, done=done, project_root=project_root,
330
+ base_branch=base_branch, work_category=work_category,
331
+ task_id=task_id, project_id=project_id, task_group=task_group,
332
+ anchor_base=anchor_base),
333
+ }
334
+ planned.append(row)
335
+ push_plan, warnings = _reconcile_with_origin(project_root, planned)
336
+ return {"ok": True, "release_base": base_branch, "stages": planned,
337
+ "push_plan": push_plan, "warnings": warnings}
338
+
339
+
340
+ def _remove_task_worktree(main_wt, target: str) -> Optional[str]:
341
+ """Remove an okstra worktree — task-key or stage — already confirmed clean
342
+ by the caller. No-op when it is already gone. Returns a human-readable
343
+ detail string on failure, None on success or absence.
344
+ Refuses while a nested worktree remains inside the target — a --force
345
+ removal would drop only the physical directory and leave git's and the
346
+ registry's stage-key admin entries orphaned."""
347
+ if not Path(target).exists():
348
+ return None # 이미 teardown 됨 — checkout 으로 진행
349
+ nested = nested_worktree_excludes(target)
350
+ if nested:
351
+ return f"nested 워크트리가 남아있습니다: {', '.join(nested)}"
352
+ rm = remove_worktree_force(main_wt, target)
353
+ if rm.returncode != 0:
354
+ return rm.stderr.strip()
355
+ return None
356
+
357
+
358
+ def _local_checkout_target(project_id, task_group, task_id,
359
+ stage: int) -> tuple:
360
+ """Resolve (branch, worktree_path) for a stage's local checkout. The
361
+ returned path is "" only when the row carries no `worktree_path`; teardown
362
+ does not clear it, so a torn-down stage yields a stale path to a directory
363
+ that no longer exists. The caller must probe the path before acting on it.
364
+
365
+ A stage row's `status == "active"` is a live reservation: done-time release
366
+ flips it (`consumers._release_stage_occupancy_keeping_branch`,
367
+ `stage_integrate._teardown_stage`), and `list_active_stage_numbers` feeds the
368
+ stage resolver, so an active stage row means a run holds it."""
369
+ row = worktree_registry.get_stage_row(project_id, task_group, task_id, stage)
370
+ if not row or not row.get("branch"):
371
+ raise HandoffError(
372
+ f"stage {stage} 의 worktree registry 엔트리가 없습니다 — "
373
+ "local checkout 대상 없음")
374
+ if row.get("status") == "active":
375
+ raise HandoffError(
376
+ f"stage {stage} 를 실행 중인 런이 점유하고 있습니다 (status=active) — "
377
+ "그 런이 끝나 점유가 해제된 뒤 다시 시도하세요")
378
+ return row["branch"], row.get("worktree_path") or ""
379
+
380
+
381
+ def local_checkout(*, project_root, project_id, task_group, task_id,
382
+ stage: int) -> Dict[str, Any]:
383
+ """그 stage 의 okstra 워크트리를 제거하고 stage 브랜치를 메인 워크트리에
384
+ checkout 한다(브랜치 보존). 메인·대상 워크트리가 dirty 면 거부. base 브랜치는
385
+ 건드리지 않는다."""
386
+ branch, wt_path = _local_checkout_target(
387
+ project_id, task_group, task_id, stage)
388
+ main_wt = main_worktree_path(Path(project_root))
389
+ if is_dirty_excluding_okstra(main_wt):
390
+ raise HandoffError(
391
+ f"메인 워크트리에 미커밋 변경이 있습니다 ({main_wt}) — "
392
+ "커밋/스태시 후 다시 시도하세요")
393
+ # 브랜치 부재는 어떤 변경 앞에서 잡는다. 종전에는 워크트리 제거·registry
394
+ # 해제 뒤에 `git checkout` 이 실패해(스택 브랜치를 사용자가 이미 지운 경우)
395
+ # 절반만 바뀐 상태가 남았다(2026-09-07 dev-10626 stage-1 실측).
396
+ probe = _git(Path(main_wt), "rev-parse", "--verify", "--quiet",
397
+ f"refs/heads/{branch}")
398
+ if probe.returncode != 0:
399
+ raise HandoffError(
400
+ f"브랜치 {branch} 가 저장소에 없습니다(삭제됨) — checkout 대상이 없어 "
401
+ "워크트리와 registry 는 건드리지 않았습니다")
402
+ removed = ""
403
+ # The removal gate must inspect the okstra worktree being destroyed, not main.
404
+ # A torn-down stage leaves a stale path in its row, so probe the directory.
405
+ if wt_path and Path(wt_path).exists():
406
+ if is_dirty_excluding_okstra(wt_path):
407
+ raise HandoffError(
408
+ f"okstra 워크트리에 미커밋 변경이 있습니다 ({wt_path}) — "
409
+ "해당 워크트리에서 커밋/스태시 후 다시 시도하세요")
410
+ detail = _remove_task_worktree(main_wt, wt_path)
411
+ if detail is not None:
412
+ raise HandoffError(
413
+ f"워크트리 제거 실패 ({wt_path}): {detail} — "
414
+ "위 사유를 해소한 뒤 다시 시도하세요")
415
+ removed = wt_path
416
+ worktree_registry.release_status(project_id, task_group, task_id,
417
+ stage_number=stage)
418
+ co = _git(Path(main_wt), "checkout", branch)
419
+ if co.returncode != 0:
420
+ removal = f"워크트리는 제거됨({removed})" if removed else "제거된 워크트리 없음"
421
+ raise HandoffError(
422
+ f"git checkout {branch} 실패: {co.stderr.strip()} — {removal}; "
423
+ f"메인({main_wt})에서 수동 checkout 으로 복구하세요")
424
+ return {"ok": True, "branch": branch, "mainWorktreePath": str(main_wt),
425
+ "removedWorktree": removed, "status": "checked-out", "stage": stage}
426
+
427
+
428
+ def record_pr(*, plan_run_root, stage: int, branch: str, base: str,
429
+ url: str) -> Dict[str, Any]:
430
+ """한 stage 의 PR 기록. PR 은 stage 당 하나이므로 행도 stage 당 하나다."""
431
+ rows = consumers.read_consumers(Path(plan_run_root))
432
+ key = consumers.require_done_task_key(rows, stage)
433
+ consumers.append_pr(Path(plan_run_root), impl_task_key=key,
434
+ stages=[stage], branch=branch, base=base, url=url)
435
+ return {"ok": True, "stage": stage, "branch": branch, "base": base,
436
+ "url": url}
437
+
438
+
439
+ def _parse_stages_csv(raw: str) -> List[int]:
440
+ try:
441
+ out = sorted({int(x) for x in raw.split(",") if x.strip()})
442
+ except ValueError:
443
+ raise HandoffError(f"--stages must be a comma-separated int list, got {raw!r}")
444
+ if not out:
445
+ raise HandoffError("--stages must select at least one stage")
446
+ return out
@@ -15,7 +15,7 @@
15
15
  - Pre-handoff entry gate (mandatory — refuse to start if any item fails):
16
16
  - the run's input document (`release-handoff-input.md`, generated by prepare in place of a task brief — briefs belong to entry phases only) carries a `## Source Verification Report` section with `Stages` and one table row per cited `final-verification` final-report. The run context exposes the same selection as `HANDOFF_STAGES` (csv, never empty — prepare defaults it to every eligible stage).
17
17
  - the lead opens each cited single-stage report and confirms its `verificationScope` is `single-stage` and its verdict is release-ready — `Verdict Token` exactly `accepted`, or exactly `conditional-accept` with every **Conditional Acceptance Condition** row declaring `blocksReleaseHandoff: false`. The rule lives in `okstra_ctl.release_gate.release_handoff_allowed`; the lead reads the reports against it and does not invent a third case. Eligibility was already enforced at prepare time (`okstra_ctl.handoff.compute_eligibility`) and is re-enforced by `okstra handoff pr-plan` — the lead never hand-computes it.
18
- - if any cited verdict is `blocked`, a `conditional-accept` carrying a condition that blocks release, or any other token (including ambiguous phrasing like "looks good"), the run MUST end immediately with status `blocked` and a routing recommendation back to `error-analysis` or `implementation-planning`. Do NOT prompt the user; Do NOT run any git command.
18
+ - Record each cited verdict and any blocking acceptance condition as entry-gate evidence. Read the `## release-handoff` section of `prompts/lead/phase-routing.md` before user questions or Git commands.
19
19
  - when a cited verdict is `conditional-accept`, the lead MUST carry that stage's **Conditional Acceptance Condition** rows into **that stage's** PR body under a heading naming them as unresolved — id, condition, and the evidence the reviewer would need. These conditions are the whole reason a non-`accepted` verdict was allowed through; a PR body that drops them turns a recorded condition into a silent one.
20
20
  - the lead MUST capture `git status --short` and confirm the working tree is clean. Dirty state aborts the run; release-handoff packages the commits produced by `implementation`, it does not stage or commit changes.
21
21
  - the lead MUST capture `git rev-parse --abbrev-ref HEAD` and record it as the run's current branch. It is evidence, not a PR head: every PR head comes from `okstra handoff pr-plan`. If the current branch is `main`, `master`, `prod`, `preprod`, `staging`, or `dev`, record it and do not push it — release-handoff never pushes a base branch.
@@ -97,9 +97,9 @@
97
97
  - `- Checked out <branch> (stage <N>) into <main worktree path>; okstra worktree <path> removed. Next: to run a local test and then open a PR, re-enter release-handoff via okstra-run → push + PR.`
98
98
  - `- Checked out <branch> (stage <N>) into <main worktree path>; no okstra worktree removed (already torn down — the branch survived). Next: to run a local test and then open a PR, re-enter release-handoff via okstra-run → push + PR.`
99
99
  - Pick between the two `Checked out` variants by the command's `removedWorktree` field: a non-empty path takes the first, an empty string takes the second. Never write a removal that did not happen.
100
- - **Routing recommendation**: explicit `done` token, since release-handoff is the terminal lifecycle phase. If the run ended in `skip` or `cancel`, or delivered only some of the selected stages, the recommendation MUST state which stages still need a PR and that re-entry into release-handoff is appropriate.
100
+ - **Routing recommendation**: record which selected stages were delivered, skipped, cancelled, or still need a PR. The lead chooses the next phase under `## release-handoff` in `prompts/lead/phase-routing.md`.
101
101
  - Self-review pass before finalising the report (the Okstra lead runs this):
102
- 1. **Entry-gate audit** — the report cites, for every stage it delivered, that stage's final-verification report path and the literal `Verdict Token` row with a release-ready value. If any is missing, or a `conditional-accept` stage's PR body omits its conditions, the run is invalid and MUST be re-routed to `final-verification`.
102
+ 1. **Entry-gate audit** — record the final-verification report path and literal `Verdict Token` row for every delivered stage, and the conditions transcribed into each conditional-accept stage's PR body. Record any missing evidence for the lead's routing decision.
103
103
  2. **User-selection traceability** — every executed mutating command maps to a user selection captured in the report. Any mutating command without a corresponding user answer is a contract violation.
104
104
  3. **Forbidden-action audit** — scan the run's session transcripts (`git`, `gh` invocations) for every entry in the Forbidden actions list above. Any occurrence means the run has crossed into unsafe territory and MUST be flagged as `contract-violated`.
105
105
  4. **Push-target audit** — for every `git push` recorded, confirm the refspec resolves to a branch that appears in the pr-plan output, not to the release base branch.
@@ -3,9 +3,9 @@ from __future__ import annotations
3
3
 
4
4
  from urllib.parse import urlparse
5
5
 
6
- from ..common import evidence_index
7
- from ..models import HumanReportView, VisualNode
8
- from ..visualizations import timeline_figure
6
+ from okstra_ctl.report_html.common import evidence_index
7
+ from okstra_ctl.report_html.models import HumanReportView, VisualNode
8
+ from okstra_ctl.report_html.visualizations import timeline_figure
9
9
 
10
10
  # Record fields this template anchors as `id-<row id>` (see
11
11
  # `HumanReportView.anchored_fields`); ids elsewhere land in the ledger.
@@ -84,7 +84,7 @@ The user picks ONE release base for the whole run. Each stage's own PR base is t
84
84
 
85
85
  > The lead MUST NOT extend handoff actions into items listed here. If an excluded item should ship in this PR, edit this section before the run starts — do not silently fold it in.
86
86
 
87
- **Enforced (delivery only):** `tests/contract/test_scope_boundary_delivery.py` pins that a filled section reaches every analysis worker through `okstra_ctl.analysis_packet` — drop it from `CANONICAL_BRIEF_SECTIONS` and every run's exclusions vanish silently. The exclusions themselves are prose and are **not** machine-checked: only the codebase-scan `out-of-scope` frontmatter is a path list, and `validators/validate_improvement_report.py` checks that one.
87
+ **Enforced (delivery only):** `tests/contract/test_scope_boundary_delivery.py` pins that a filled section reaches every analysis worker through `okstra_ctl.analysis_packet` — drop it from `CANONICAL_BRIEF_SECTIONS` and every run's exclusions vanish silently. The exclusions themselves are prose and are **not** machine-checked: only the codebase-scan `out-of-scope` frontmatter is a path list, and `scripts/okstra_ctl/phases/improvement_discovery/validation.py` checks that one.
88
88
 
89
89
  ## Questions for Lead Drafting
90
90