phase-loop-runtime 0.2.0__py3-none-any.whl

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 (370) hide show
  1. phase_loop_runtime/__init__.py +20 -0
  2. phase_loop_runtime/_contract_docs/phase-loop/extraction-readiness.md +90 -0
  3. phase_loop_runtime/_contract_docs/phase-loop/granular-execution-policy.md +137 -0
  4. phase_loop_runtime/_contract_docs/phase-loop/harness-capability-matrix.md +510 -0
  5. phase_loop_runtime/_contract_docs/phase-loop/harness-skill-matrix.md +125 -0
  6. phase_loop_runtime/_contract_docs/phase-loop/harness-substrate-manifest.md +232 -0
  7. phase_loop_runtime/_contract_docs/phase-loop/pi-loop-control.md +247 -0
  8. phase_loop_runtime/_contract_docs/phase-loop/protocol.md +2759 -0
  9. phase_loop_runtime/_contract_docs/phase-loop/runtime-boundary.md +289 -0
  10. phase_loop_runtime/_contract_docs/phase-loop/spec-discovery-roots.md +47 -0
  11. phase_loop_runtime/_contract_docs/phase-loop/substrate-soak-governed-pipeline.md +42 -0
  12. phase_loop_runtime/_contract_docs/phase-loop/substrate-soak-portal-projection.md +34 -0
  13. phase_loop_runtime/_contract_docs/phase-loop/substrate-soak-regenesis.md +29 -0
  14. phase_loop_runtime/_contract_docs/phase-loop/substrate-soak-report.md +32 -0
  15. phase_loop_runtime/_contract_docs/runtime/verification-evidence-contract.md +52 -0
  16. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/borderline/borderline-mixed-signals/commands.txt +2 -0
  17. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/borderline/borderline-mixed-signals/manifest.json +16 -0
  18. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/borderline/borderline-mixed-signals/mixed.json +5 -0
  19. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/borderline/borderline-provider-timeout/manifest.json +16 -0
  20. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/borderline/borderline-provider-timeout/timeout-note.txt +2 -0
  21. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/borderline/borderline-redacted-summary/manifest.json +16 -0
  22. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/borderline/borderline-redacted-summary/redacted-summary.json +6 -0
  23. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/borderline/borderline-small-sample/manifest.json +16 -0
  24. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/borderline/borderline-small-sample/sample.json +7 -0
  25. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/borderline/borderline-threshold-edge/edge.txt +2 -0
  26. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/borderline/borderline-threshold-edge/manifest.json +16 -0
  27. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-fake/fake-duplicate-png/manifest.json +16 -0
  28. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-fake/fake-duplicate-png/shot-a.txt +1 -0
  29. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-fake/fake-duplicate-png/shot-b.txt +1 -0
  30. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-fake/fake-duplicate-png/shot-c.txt +1 -0
  31. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-fake/fake-missing-references/claimed-results.json +5 -0
  32. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-fake/fake-missing-references/manifest.json +16 -0
  33. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-fake/fake-subtle-low-variance/manifest.json +16 -0
  34. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-fake/fake-subtle-low-variance/metrics.json +9 -0
  35. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-fake/fake-templated-prose/findings.md +10 -0
  36. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-fake/fake-templated-prose/manifest.json +16 -0
  37. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-fake/fake-uniform-scores/manifest.json +16 -0
  38. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-fake/fake-uniform-scores/scores.json +4 -0
  39. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-fake/fake-uniform-scores/summary.txt +1 -0
  40. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-real/real-adoption-bundle/bundle-check.json +8 -0
  41. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-real/real-adoption-bundle/manifest.json +16 -0
  42. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-real/real-adoption-bundle/operator-note.txt +2 -0
  43. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-real/real-handoff-ledger/events-sample.jsonl +3 -0
  44. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-real/real-handoff-ledger/manifest.json +16 -0
  45. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-real/real-handoff-ledger/receipt.txt +1 -0
  46. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-real/real-runner-diff/evidence.json +13 -0
  47. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-real/real-runner-diff/manifest.json +16 -0
  48. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-real/real-runner-diff/summary.txt +2 -0
  49. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-real/real-test-matrix/manifest.json +16 -0
  50. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-real/real-test-matrix/matrix.json +9 -0
  51. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-real/real-test-matrix/notes.md +4 -0
  52. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-real/real-ui-screenshot-standin/console-summary.txt +2 -0
  53. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-real/real-ui-screenshot-standin/manifest.json +16 -0
  54. phase_loop_runtime/_test_fixtures/evidence-audit-calibration/known-real/real-ui-screenshot-standin/screenshot-standin.ppm +5 -0
  55. phase_loop_runtime/adoption_bundle.py +273 -0
  56. phase_loop_runtime/advisor_board/CONTRACTS.md +257 -0
  57. phase_loop_runtime/advisor_board/__init__.py +288 -0
  58. phase_loop_runtime/advisor_board/backing.py +137 -0
  59. phase_loop_runtime/advisor_board/backing_omnigent.py +498 -0
  60. phase_loop_runtime/advisor_board/config.py +225 -0
  61. phase_loop_runtime/advisor_board/events.py +115 -0
  62. phase_loop_runtime/advisor_board/fixtures/advisor-boards.example.toml +59 -0
  63. phase_loop_runtime/advisor_board/fixtures.py +91 -0
  64. phase_loop_runtime/advisor_board/harness_mapping.py +125 -0
  65. phase_loop_runtime/advisor_board/matrix.py +146 -0
  66. phase_loop_runtime/advisor_board/observability.py +481 -0
  67. phase_loop_runtime/advisor_board/presets.py +188 -0
  68. phase_loop_runtime/advisor_board/registries.py +309 -0
  69. phase_loop_runtime/advisor_board/resolver.py +253 -0
  70. phase_loop_runtime/advisor_board/schema.py +269 -0
  71. phase_loop_runtime/advisor_board/standin.py +166 -0
  72. phase_loop_runtime/advisor_board/validation.py +159 -0
  73. phase_loop_runtime/agent_runtime_provider.py +676 -0
  74. phase_loop_runtime/baml_modular.py +656 -0
  75. phase_loop_runtime/baml_src/dotfiles_adoption_manifest.baml +37 -0
  76. phase_loop_runtime/baml_src/dotfiles_c4_document.baml +14 -0
  77. phase_loop_runtime/baml_src/dotfiles_plan_manifest.baml +50 -0
  78. phase_loop_runtime/baml_src/dotfiles_runtime_projection.baml +16 -0
  79. phase_loop_runtime/baml_src/dotfiles_task_catalog.baml +20 -0
  80. phase_loop_runtime/baml_src/emit_phase_closeout.baml +86 -0
  81. phase_loop_runtime/baml_src/evaluate_suspected_fake_evidence.baml +36 -0
  82. phase_loop_runtime/baml_src/verification_evidence.baml +40 -0
  83. phase_loop_runtime/broker.py +181 -0
  84. phase_loop_runtime/build_bundle.py +294 -0
  85. phase_loop_runtime/capability_registry.py +835 -0
  86. phase_loop_runtime/classifier.py +87 -0
  87. phase_loop_runtime/claude_agent_view.py +625 -0
  88. phase_loop_runtime/claude_channel_sidecar.py +1086 -0
  89. phase_loop_runtime/cli.py +2599 -0
  90. phase_loop_runtime/closeout.py +865 -0
  91. phase_loop_runtime/closeout_classifier.py +120 -0
  92. phase_loop_runtime/closeout_evidence_audit.py +112 -0
  93. phase_loop_runtime/closeout_validation.py +144 -0
  94. phase_loop_runtime/closeout_validators.py +203 -0
  95. phase_loop_runtime/consiliency_gates.py +374 -0
  96. phase_loop_runtime/consiliency_ingest.py +399 -0
  97. phase_loop_runtime/consiliency_layout.py +176 -0
  98. phase_loop_runtime/consiliency_scaffold.py +305 -0
  99. phase_loop_runtime/cross_repo_channel.py +331 -0
  100. phase_loop_runtime/discovery.py +2368 -0
  101. phase_loop_runtime/dispatch_lock.py +167 -0
  102. phase_loop_runtime/doc_delta_validator.py +98 -0
  103. phase_loop_runtime/docs_audit.py +285 -0
  104. phase_loop_runtime/docs_freshness.py +468 -0
  105. phase_loop_runtime/docs_surfaces.py +150 -0
  106. phase_loop_runtime/dotfiles_profile_plugin.py +96 -0
  107. phase_loop_runtime/events.py +154 -0
  108. phase_loop_runtime/events_migration.py +96 -0
  109. phase_loop_runtime/evidence_audit.py +1082 -0
  110. phase_loop_runtime/evidence_audit_config.py +172 -0
  111. phase_loop_runtime/fleet_map.py +426 -0
  112. phase_loop_runtime/fleet_metrics.py +298 -0
  113. phase_loop_runtime/fleet_metrics_export.py +196 -0
  114. phase_loop_runtime/git_discipline.py +479 -0
  115. phase_loop_runtime/git_ops.py +122 -0
  116. phase_loop_runtime/git_topology.py +252 -0
  117. phase_loop_runtime/governed_bundle.py +137 -0
  118. phase_loop_runtime/governed_premerge.py +219 -0
  119. phase_loop_runtime/governed_review.py +264 -0
  120. phase_loop_runtime/handoff.py +932 -0
  121. phase_loop_runtime/handoff_path.py +14 -0
  122. phase_loop_runtime/injection.py +740 -0
  123. phase_loop_runtime/install_status.py +88 -0
  124. phase_loop_runtime/lane_scheduler.py +317 -0
  125. phase_loop_runtime/launcher.py +2760 -0
  126. phase_loop_runtime/lease_store.py +553 -0
  127. phase_loop_runtime/maintenance.py +401 -0
  128. phase_loop_runtime/migrate_handoffs.py +201 -0
  129. phase_loop_runtime/models.py +2144 -0
  130. phase_loop_runtime/observability.py +1290 -0
  131. phase_loop_runtime/panel_invoker.py +1638 -0
  132. phase_loop_runtime/phase_loop_drift_audit.py +388 -0
  133. phase_loop_runtime/phase_worktree_executor.py +433 -0
  134. phase_loop_runtime/pipeline_adapter/__init__.py +12 -0
  135. phase_loop_runtime/pipeline_adapter/branch_ops.py +274 -0
  136. phase_loop_runtime/pipeline_adapter/flag.py +55 -0
  137. phase_loop_runtime/pipeline_adapter/markers.py +13 -0
  138. phase_loop_runtime/pipeline_adapter/merge_policy.py +72 -0
  139. phase_loop_runtime/pipeline_adapter/ratification.py +100 -0
  140. phase_loop_runtime/pipeline_adapter/sibling_matcher.py +123 -0
  141. phase_loop_runtime/plan_ir.py +523 -0
  142. phase_loop_runtime/plan_manifest.py +415 -0
  143. phase_loop_runtime/planner_validation.py +176 -0
  144. phase_loop_runtime/profiles.py +462 -0
  145. phase_loop_runtime/prompts.py +365 -0
  146. phase_loop_runtime/provenance.py +165 -0
  147. phase_loop_runtime/publishing.py +339 -0
  148. phase_loop_runtime/py.typed +1 -0
  149. phase_loop_runtime/reconcile.py +1550 -0
  150. phase_loop_runtime/redaction.py +184 -0
  151. phase_loop_runtime/reflection_sync.py +293 -0
  152. phase_loop_runtime/release_guard.py +186 -0
  153. phase_loop_runtime/render.py +432 -0
  154. phase_loop_runtime/repo_validation.py +427 -0
  155. phase_loop_runtime/review_summary.py +150 -0
  156. phase_loop_runtime/roadmap_lint.py +425 -0
  157. phase_loop_runtime/route_log.py +59 -0
  158. phase_loop_runtime/route_policy/__init__.py +11 -0
  159. phase_loop_runtime/route_policy/fixtures/route_selection.golden.json +263 -0
  160. phase_loop_runtime/runner.py +8400 -0
  161. phase_loop_runtime/runtime_paths.py +225 -0
  162. phase_loop_runtime/runtime_projection.py +113 -0
  163. phase_loop_runtime/runtime_resources.py +36 -0
  164. phase_loop_runtime/schema_export.py +292 -0
  165. phase_loop_runtime/schemas/phase_loop_closeout.schema.json +366 -0
  166. phase_loop_runtime/skill_install.py +176 -0
  167. phase_loop_runtime/skill_inventory.py +662 -0
  168. phase_loop_runtime/skill_paths.py +42 -0
  169. phase_loop_runtime/skill_sources_plugin.py +37 -0
  170. phase_loop_runtime/skills_bundle/claude-advisor-board/README.md +1 -0
  171. phase_loop_runtime/skills_bundle/claude-advisor-board/SKILL.md +38 -0
  172. phase_loop_runtime/skills_bundle/claude-advisor-panel/README.md +1 -0
  173. phase_loop_runtime/skills_bundle/claude-advisor-panel/SKILL.md +38 -0
  174. phase_loop_runtime/skills_bundle/claude-execute-detailed/README.md +1 -0
  175. phase_loop_runtime/skills_bundle/claude-execute-detailed/SKILL.md +152 -0
  176. phase_loop_runtime/skills_bundle/claude-execute-phase/README.md +1 -0
  177. phase_loop_runtime/skills_bundle/claude-execute-phase/SKILL.md +745 -0
  178. phase_loop_runtime/skills_bundle/claude-execute-phase/scripts/allocate_worktree_name.sh +33 -0
  179. phase_loop_runtime/skills_bundle/claude-execute-phase/scripts/audit_lane_file_touches.py +197 -0
  180. phase_loop_runtime/skills_bundle/claude-execute-phase/scripts/cleanup_lane_worktrees.sh +103 -0
  181. phase_loop_runtime/skills_bundle/claude-execute-phase/scripts/parent_tree_leakage_check.sh +125 -0
  182. phase_loop_runtime/skills_bundle/claude-execute-phase/scripts/post_merge_import_smoke.sh +62 -0
  183. phase_loop_runtime/skills_bundle/claude-execute-phase/scripts/pre_merge_destructiveness_check.sh +127 -0
  184. phase_loop_runtime/skills_bundle/claude-execute-phase/scripts/resolve_branch_from_sha.sh +51 -0
  185. phase_loop_runtime/skills_bundle/claude-execute-phase/scripts/state.py +274 -0
  186. phase_loop_runtime/skills_bundle/claude-execute-phase/scripts/sweep_stale_worktrees.sh +62 -0
  187. phase_loop_runtime/skills_bundle/claude-execute-phase/scripts/team_teardown.sh +32 -0
  188. phase_loop_runtime/skills_bundle/claude-execute-phase/scripts/validate_plan_doc.py +642 -0
  189. phase_loop_runtime/skills_bundle/claude-execute-phase/scripts/verify_harness.sh +96 -0
  190. phase_loop_runtime/skills_bundle/claude-phase-loop/README.md +1 -0
  191. phase_loop_runtime/skills_bundle/claude-phase-loop/SKILL.md +115 -0
  192. phase_loop_runtime/skills_bundle/claude-phase-roadmap-builder/README.md +1 -0
  193. phase_loop_runtime/skills_bundle/claude-phase-roadmap-builder/SKILL.md +439 -0
  194. phase_loop_runtime/skills_bundle/claude-phase-roadmap-builder/assets/review_prompt.md +19 -0
  195. phase_loop_runtime/skills_bundle/claude-phase-roadmap-builder/references/parallelization-heuristics.md +111 -0
  196. phase_loop_runtime/skills_bundle/claude-phase-roadmap-builder/references/roadmap-template.md +193 -0
  197. phase_loop_runtime/skills_bundle/claude-phase-roadmap-builder/scripts/validate_roadmap.py +32 -0
  198. phase_loop_runtime/skills_bundle/claude-plan-detailed/README.md +1 -0
  199. phase_loop_runtime/skills_bundle/claude-plan-detailed/SKILL.md +334 -0
  200. phase_loop_runtime/skills_bundle/claude-plan-detailed/assets/review_prompt.md +25 -0
  201. phase_loop_runtime/skills_bundle/claude-plan-phase/README.md +1 -0
  202. phase_loop_runtime/skills_bundle/claude-plan-phase/SKILL.md +776 -0
  203. phase_loop_runtime/skills_bundle/claude-plan-phase/assets/review_prompt.md +17 -0
  204. phase_loop_runtime/skills_bundle/claude-plan-phase/scripts/validate_plan_doc.py +1092 -0
  205. phase_loop_runtime/skills_bundle/claude-run-train/README.md +1 -0
  206. phase_loop_runtime/skills_bundle/claude-run-train/SKILL.md +75 -0
  207. phase_loop_runtime/skills_bundle/claude-skill-editor/README.md +1 -0
  208. phase_loop_runtime/skills_bundle/claude-skill-editor/SKILL.md +243 -0
  209. phase_loop_runtime/skills_bundle/claude-skill-editor/assets/editor_prompt.md +72 -0
  210. phase_loop_runtime/skills_bundle/claude-skill-improvement-planner/README.md +1 -0
  211. phase_loop_runtime/skills_bundle/claude-skill-improvement-planner/SKILL.md +249 -0
  212. phase_loop_runtime/skills_bundle/claude-skill-improvement-planner/assets/aggregator_prompt.md +79 -0
  213. phase_loop_runtime/skills_bundle/claude-task-contextualizer/README.md +1 -0
  214. phase_loop_runtime/skills_bundle/claude-task-contextualizer/SKILL.md +74 -0
  215. phase_loop_runtime/skills_bundle/claude-task-contextualizer/references/task-templates.md +103 -0
  216. phase_loop_runtime/skills_bundle/codex-advisor-board/README.md +1 -0
  217. phase_loop_runtime/skills_bundle/codex-advisor-board/SKILL.md +38 -0
  218. phase_loop_runtime/skills_bundle/codex-advisor-panel/README.md +1 -0
  219. phase_loop_runtime/skills_bundle/codex-advisor-panel/SKILL.md +38 -0
  220. phase_loop_runtime/skills_bundle/codex-execute-detailed/README.md +1 -0
  221. phase_loop_runtime/skills_bundle/codex-execute-detailed/SKILL.md +154 -0
  222. phase_loop_runtime/skills_bundle/codex-execute-phase/README.md +1 -0
  223. phase_loop_runtime/skills_bundle/codex-execute-phase/SKILL.md +231 -0
  224. phase_loop_runtime/skills_bundle/codex-execute-phase/scripts/allocate_worktree_name.sh +33 -0
  225. phase_loop_runtime/skills_bundle/codex-execute-phase/scripts/audit_lane_file_touches.py +197 -0
  226. phase_loop_runtime/skills_bundle/codex-execute-phase/scripts/cleanup_lane_worktrees.sh +103 -0
  227. phase_loop_runtime/skills_bundle/codex-execute-phase/scripts/parent_tree_leakage_check.sh +125 -0
  228. phase_loop_runtime/skills_bundle/codex-execute-phase/scripts/post_merge_import_smoke.sh +62 -0
  229. phase_loop_runtime/skills_bundle/codex-execute-phase/scripts/pre_merge_destructiveness_check.sh +127 -0
  230. phase_loop_runtime/skills_bundle/codex-execute-phase/scripts/resolve_branch_from_sha.sh +51 -0
  231. phase_loop_runtime/skills_bundle/codex-execute-phase/scripts/state.py +274 -0
  232. phase_loop_runtime/skills_bundle/codex-execute-phase/scripts/sweep_stale_worktrees.sh +62 -0
  233. phase_loop_runtime/skills_bundle/codex-execute-phase/scripts/team_teardown.sh +32 -0
  234. phase_loop_runtime/skills_bundle/codex-execute-phase/scripts/validate_plan_doc.py +642 -0
  235. phase_loop_runtime/skills_bundle/codex-execute-phase/scripts/verify_harness.sh +96 -0
  236. phase_loop_runtime/skills_bundle/codex-phase-loop/README.md +1 -0
  237. phase_loop_runtime/skills_bundle/codex-phase-loop/SKILL.md +248 -0
  238. phase_loop_runtime/skills_bundle/codex-phase-roadmap-builder/README.md +1 -0
  239. phase_loop_runtime/skills_bundle/codex-phase-roadmap-builder/SKILL.md +150 -0
  240. phase_loop_runtime/skills_bundle/codex-phase-roadmap-builder/assets/review_prompt.md +19 -0
  241. phase_loop_runtime/skills_bundle/codex-phase-roadmap-builder/references/parallelization-heuristics.md +111 -0
  242. phase_loop_runtime/skills_bundle/codex-phase-roadmap-builder/references/roadmap-template.md +193 -0
  243. phase_loop_runtime/skills_bundle/codex-phase-roadmap-builder/scripts/validate_roadmap.py +32 -0
  244. phase_loop_runtime/skills_bundle/codex-plan-detailed/README.md +1 -0
  245. phase_loop_runtime/skills_bundle/codex-plan-detailed/SKILL.md +119 -0
  246. phase_loop_runtime/skills_bundle/codex-plan-detailed/assets/review_prompt.md +25 -0
  247. phase_loop_runtime/skills_bundle/codex-plan-phase/README.md +1 -0
  248. phase_loop_runtime/skills_bundle/codex-plan-phase/SKILL.md +307 -0
  249. phase_loop_runtime/skills_bundle/codex-plan-phase/assets/review_prompt.md +17 -0
  250. phase_loop_runtime/skills_bundle/codex-plan-phase/scripts/validate_plan_doc.py +1092 -0
  251. phase_loop_runtime/skills_bundle/codex-run-train/README.md +1 -0
  252. phase_loop_runtime/skills_bundle/codex-run-train/SKILL.md +75 -0
  253. phase_loop_runtime/skills_bundle/codex-skill-editor/README.md +1 -0
  254. phase_loop_runtime/skills_bundle/codex-skill-editor/SKILL.md +94 -0
  255. phase_loop_runtime/skills_bundle/codex-skill-editor/assets/editor_prompt.md +72 -0
  256. phase_loop_runtime/skills_bundle/codex-skill-improvement-planner/README.md +1 -0
  257. phase_loop_runtime/skills_bundle/codex-skill-improvement-planner/SKILL.md +114 -0
  258. phase_loop_runtime/skills_bundle/codex-skill-improvement-planner/assets/aggregator_prompt.md +79 -0
  259. phase_loop_runtime/skills_bundle/codex-task-contextualizer/README.md +1 -0
  260. phase_loop_runtime/skills_bundle/codex-task-contextualizer/SKILL.md +102 -0
  261. phase_loop_runtime/skills_bundle/codex-task-contextualizer/references/task-templates.md +103 -0
  262. phase_loop_runtime/skills_bundle/gemini-advisor-board/README.md +1 -0
  263. phase_loop_runtime/skills_bundle/gemini-advisor-board/SKILL.md +38 -0
  264. phase_loop_runtime/skills_bundle/gemini-advisor-panel/README.md +1 -0
  265. phase_loop_runtime/skills_bundle/gemini-advisor-panel/SKILL.md +38 -0
  266. phase_loop_runtime/skills_bundle/gemini-execute-detailed/README.md +1 -0
  267. phase_loop_runtime/skills_bundle/gemini-execute-detailed/SKILL.md +144 -0
  268. phase_loop_runtime/skills_bundle/gemini-execute-phase/README.md +1 -0
  269. phase_loop_runtime/skills_bundle/gemini-execute-phase/SKILL.md +198 -0
  270. phase_loop_runtime/skills_bundle/gemini-execute-phase/scripts/allocate_worktree_name.sh +33 -0
  271. phase_loop_runtime/skills_bundle/gemini-execute-phase/scripts/audit_lane_file_touches.py +197 -0
  272. phase_loop_runtime/skills_bundle/gemini-execute-phase/scripts/cleanup_lane_worktrees.sh +103 -0
  273. phase_loop_runtime/skills_bundle/gemini-execute-phase/scripts/parent_tree_leakage_check.sh +125 -0
  274. phase_loop_runtime/skills_bundle/gemini-execute-phase/scripts/post_merge_import_smoke.sh +62 -0
  275. phase_loop_runtime/skills_bundle/gemini-execute-phase/scripts/pre_merge_destructiveness_check.sh +127 -0
  276. phase_loop_runtime/skills_bundle/gemini-execute-phase/scripts/resolve_branch_from_sha.sh +51 -0
  277. phase_loop_runtime/skills_bundle/gemini-execute-phase/scripts/state.py +274 -0
  278. phase_loop_runtime/skills_bundle/gemini-execute-phase/scripts/sweep_stale_worktrees.sh +62 -0
  279. phase_loop_runtime/skills_bundle/gemini-execute-phase/scripts/team_teardown.sh +32 -0
  280. phase_loop_runtime/skills_bundle/gemini-execute-phase/scripts/validate_plan_doc.py +642 -0
  281. phase_loop_runtime/skills_bundle/gemini-execute-phase/scripts/verify_harness.sh +96 -0
  282. phase_loop_runtime/skills_bundle/gemini-phase-loop/README.md +1 -0
  283. phase_loop_runtime/skills_bundle/gemini-phase-loop/SKILL.md +111 -0
  284. phase_loop_runtime/skills_bundle/gemini-phase-roadmap-builder/README.md +1 -0
  285. phase_loop_runtime/skills_bundle/gemini-phase-roadmap-builder/SKILL.md +147 -0
  286. phase_loop_runtime/skills_bundle/gemini-phase-roadmap-builder/assets/review_prompt.md +19 -0
  287. phase_loop_runtime/skills_bundle/gemini-phase-roadmap-builder/references/parallelization-heuristics.md +111 -0
  288. phase_loop_runtime/skills_bundle/gemini-phase-roadmap-builder/references/roadmap-template.md +193 -0
  289. phase_loop_runtime/skills_bundle/gemini-phase-roadmap-builder/scripts/validate_roadmap.py +32 -0
  290. phase_loop_runtime/skills_bundle/gemini-plan-detailed/README.md +1 -0
  291. phase_loop_runtime/skills_bundle/gemini-plan-detailed/SKILL.md +119 -0
  292. phase_loop_runtime/skills_bundle/gemini-plan-detailed/assets/review_prompt.md +25 -0
  293. phase_loop_runtime/skills_bundle/gemini-plan-phase/README.md +1 -0
  294. phase_loop_runtime/skills_bundle/gemini-plan-phase/SKILL.md +217 -0
  295. phase_loop_runtime/skills_bundle/gemini-plan-phase/assets/review_prompt.md +17 -0
  296. phase_loop_runtime/skills_bundle/gemini-plan-phase/scripts/validate_plan_doc.py +1092 -0
  297. phase_loop_runtime/skills_bundle/gemini-run-train/README.md +1 -0
  298. phase_loop_runtime/skills_bundle/gemini-run-train/SKILL.md +75 -0
  299. phase_loop_runtime/skills_bundle/gemini-skill-editor/README.md +1 -0
  300. phase_loop_runtime/skills_bundle/gemini-skill-editor/SKILL.md +87 -0
  301. phase_loop_runtime/skills_bundle/gemini-skill-editor/assets/editor_prompt.md +72 -0
  302. phase_loop_runtime/skills_bundle/gemini-skill-improvement-planner/README.md +1 -0
  303. phase_loop_runtime/skills_bundle/gemini-skill-improvement-planner/SKILL.md +109 -0
  304. phase_loop_runtime/skills_bundle/gemini-skill-improvement-planner/assets/aggregator_prompt.md +79 -0
  305. phase_loop_runtime/skills_bundle/gemini-task-contextualizer/README.md +1 -0
  306. phase_loop_runtime/skills_bundle/gemini-task-contextualizer/SKILL.md +98 -0
  307. phase_loop_runtime/skills_bundle/gemini-task-contextualizer/references/task-templates.md +103 -0
  308. phase_loop_runtime/skills_bundle/opencode-advisor-board/README.md +1 -0
  309. phase_loop_runtime/skills_bundle/opencode-advisor-board/SKILL.md +38 -0
  310. phase_loop_runtime/skills_bundle/opencode-advisor-panel/README.md +1 -0
  311. phase_loop_runtime/skills_bundle/opencode-advisor-panel/SKILL.md +38 -0
  312. phase_loop_runtime/skills_bundle/opencode-execute-detailed/README.md +1 -0
  313. phase_loop_runtime/skills_bundle/opencode-execute-detailed/SKILL.md +144 -0
  314. phase_loop_runtime/skills_bundle/opencode-execute-phase/README.md +1 -0
  315. phase_loop_runtime/skills_bundle/opencode-execute-phase/SKILL.md +196 -0
  316. phase_loop_runtime/skills_bundle/opencode-execute-phase/scripts/allocate_worktree_name.sh +33 -0
  317. phase_loop_runtime/skills_bundle/opencode-execute-phase/scripts/audit_lane_file_touches.py +197 -0
  318. phase_loop_runtime/skills_bundle/opencode-execute-phase/scripts/cleanup_lane_worktrees.sh +103 -0
  319. phase_loop_runtime/skills_bundle/opencode-execute-phase/scripts/parent_tree_leakage_check.sh +125 -0
  320. phase_loop_runtime/skills_bundle/opencode-execute-phase/scripts/post_merge_import_smoke.sh +62 -0
  321. phase_loop_runtime/skills_bundle/opencode-execute-phase/scripts/pre_merge_destructiveness_check.sh +127 -0
  322. phase_loop_runtime/skills_bundle/opencode-execute-phase/scripts/resolve_branch_from_sha.sh +51 -0
  323. phase_loop_runtime/skills_bundle/opencode-execute-phase/scripts/state.py +274 -0
  324. phase_loop_runtime/skills_bundle/opencode-execute-phase/scripts/sweep_stale_worktrees.sh +62 -0
  325. phase_loop_runtime/skills_bundle/opencode-execute-phase/scripts/team_teardown.sh +32 -0
  326. phase_loop_runtime/skills_bundle/opencode-execute-phase/scripts/validate_plan_doc.py +642 -0
  327. phase_loop_runtime/skills_bundle/opencode-execute-phase/scripts/verify_harness.sh +96 -0
  328. phase_loop_runtime/skills_bundle/opencode-phase-loop/README.md +1 -0
  329. phase_loop_runtime/skills_bundle/opencode-phase-loop/SKILL.md +113 -0
  330. phase_loop_runtime/skills_bundle/opencode-phase-roadmap-builder/README.md +1 -0
  331. phase_loop_runtime/skills_bundle/opencode-phase-roadmap-builder/SKILL.md +147 -0
  332. phase_loop_runtime/skills_bundle/opencode-phase-roadmap-builder/assets/review_prompt.md +19 -0
  333. phase_loop_runtime/skills_bundle/opencode-phase-roadmap-builder/references/parallelization-heuristics.md +111 -0
  334. phase_loop_runtime/skills_bundle/opencode-phase-roadmap-builder/references/roadmap-template.md +193 -0
  335. phase_loop_runtime/skills_bundle/opencode-phase-roadmap-builder/scripts/validate_roadmap.py +32 -0
  336. phase_loop_runtime/skills_bundle/opencode-plan-detailed/README.md +1 -0
  337. phase_loop_runtime/skills_bundle/opencode-plan-detailed/SKILL.md +119 -0
  338. phase_loop_runtime/skills_bundle/opencode-plan-detailed/assets/review_prompt.md +25 -0
  339. phase_loop_runtime/skills_bundle/opencode-plan-phase/README.md +1 -0
  340. phase_loop_runtime/skills_bundle/opencode-plan-phase/SKILL.md +211 -0
  341. phase_loop_runtime/skills_bundle/opencode-plan-phase/assets/review_prompt.md +17 -0
  342. phase_loop_runtime/skills_bundle/opencode-plan-phase/scripts/validate_plan_doc.py +1092 -0
  343. phase_loop_runtime/skills_bundle/opencode-run-train/README.md +1 -0
  344. phase_loop_runtime/skills_bundle/opencode-run-train/SKILL.md +75 -0
  345. phase_loop_runtime/skills_bundle/opencode-skill-editor/README.md +1 -0
  346. phase_loop_runtime/skills_bundle/opencode-skill-editor/SKILL.md +87 -0
  347. phase_loop_runtime/skills_bundle/opencode-skill-editor/assets/editor_prompt.md +72 -0
  348. phase_loop_runtime/skills_bundle/opencode-skill-improvement-planner/README.md +1 -0
  349. phase_loop_runtime/skills_bundle/opencode-skill-improvement-planner/SKILL.md +109 -0
  350. phase_loop_runtime/skills_bundle/opencode-skill-improvement-planner/assets/aggregator_prompt.md +79 -0
  351. phase_loop_runtime/skills_bundle/opencode-task-contextualizer/README.md +1 -0
  352. phase_loop_runtime/skills_bundle/opencode-task-contextualizer/SKILL.md +98 -0
  353. phase_loop_runtime/skills_bundle/opencode-task-contextualizer/references/task-templates.md +103 -0
  354. phase_loop_runtime/state.py +156 -0
  355. phase_loop_runtime/state_degradation.py +136 -0
  356. phase_loop_runtime/state_ops.py +676 -0
  357. phase_loop_runtime/train_ledger.py +215 -0
  358. phase_loop_runtime/train_roadmap.py +339 -0
  359. phase_loop_runtime/train_runner.py +1197 -0
  360. phase_loop_runtime/verification_evidence.py +650 -0
  361. phase_loop_runtime/verification_evidence_validator.py +75 -0
  362. phase_loop_runtime/visual_evidence_validator.py +36 -0
  363. phase_loop_runtime/worker_pool.py +123 -0
  364. phase_loop_runtime/worktree_index.py +270 -0
  365. phase_loop_runtime-0.2.0.data/data/share/phase-loop-runtime/protocol/protocol.md +2475 -0
  366. phase_loop_runtime-0.2.0.dist-info/METADATA +106 -0
  367. phase_loop_runtime-0.2.0.dist-info/RECORD +370 -0
  368. phase_loop_runtime-0.2.0.dist-info/WHEEL +5 -0
  369. phase_loop_runtime-0.2.0.dist-info/entry_points.txt +9 -0
  370. phase_loop_runtime-0.2.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,432 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ from pathlib import Path
5
+
6
+ from .discovery import execution_policy_for_action, find_plan_artifact, parse_execution_policy
7
+ from .git_topology import attach_git_topology
8
+ from .models import StateSnapshot
9
+
10
+ EXECUTION_POLICY_ACTIONS = ("plan", "execute", "repair", "review")
11
+
12
+
13
+ def render_status(snapshot: StateSnapshot, as_json: bool = False, ledger_debug: bool = False) -> str:
14
+ snapshot = attach_git_topology(Path(snapshot.repo), snapshot)
15
+ if as_json:
16
+ payload = snapshot.to_json()
17
+ policy_block = _resolve_execution_policy_block(snapshot)
18
+ if policy_block:
19
+ payload["execution_policy"] = policy_block
20
+ if ledger_debug:
21
+ payload["rejected_events"] = [_ledger_debug_record(warning) for warning in snapshot.ledger_warnings]
22
+ payload["duplicates_skipped"] = [
23
+ _ledger_duplicate_debug_record(record) for record in snapshot.ledger_duplicates_skipped
24
+ ]
25
+ return json.dumps(payload, indent=2, sort_keys=True)
26
+ lines = [f"Roadmap: {snapshot.roadmap}", "Phase statuses:"]
27
+ for phase, status in snapshot.phases.items():
28
+ marker = "*" if phase == snapshot.current_phase else " "
29
+ lines.append(f"{marker} {phase}: {status}")
30
+ if snapshot.current_phase is None and snapshot.phases and all(status == "complete" for status in snapshot.phases.values()):
31
+ lines.append("Roadmap complete: all phases are complete")
32
+ terminal_summary = _current_terminal_summary(snapshot)
33
+ if terminal_summary:
34
+ lines.extend(_terminal_summary_lines(terminal_summary))
35
+ if snapshot.metrics_summary:
36
+ lines.extend(_metrics_summary_lines(snapshot.metrics_summary))
37
+ if snapshot.human_required:
38
+ lines.append(f"Human required: {snapshot.blocker_class or 'unknown'}")
39
+ if snapshot.blocker_summary:
40
+ lines.append(f"Blocker: {snapshot.blocker_summary}")
41
+ elif snapshot.current_phase and snapshot.phases.get(snapshot.current_phase) == "awaiting_phase_closeout":
42
+ lines.append("Closeout required: verified dirty phase output is awaiting preservation")
43
+ lines.extend(_live_git_topology_lines(snapshot.git_topology))
44
+ if snapshot.dirty_paths:
45
+ lines.append(f"Dirty paths: {', '.join(snapshot.dirty_paths)}")
46
+ lines.append(f"Phase-owned dirty: {'yes' if snapshot.phase_owned_dirty else 'no'}")
47
+ if snapshot.phase_owned_dirty_paths:
48
+ lines.append(f"Phase-owned paths: {', '.join(snapshot.phase_owned_dirty_paths)}")
49
+ if snapshot.previous_phase_owned_paths:
50
+ lines.append(f"Previous phase-owned paths: {', '.join(snapshot.previous_phase_owned_paths)}")
51
+ if snapshot.unowned_dirty_paths:
52
+ lines.append(f"Unowned paths: {', '.join(snapshot.unowned_dirty_paths)}")
53
+ if snapshot.pre_existing_dirty_paths:
54
+ lines.append(f"Pre-existing paths: {', '.join(snapshot.pre_existing_dirty_paths)}")
55
+ if snapshot.closeout_summary:
56
+ lines.extend(_closeout_summary_lines(snapshot.closeout_summary))
57
+ if snapshot.blocker_class and not snapshot.human_required:
58
+ lines.append(f"Blocker: {snapshot.blocker_class}")
59
+ if snapshot.blocker_summary:
60
+ lines.append(f"Blocker summary: {snapshot.blocker_summary}")
61
+ lines.append(
62
+ "Repair guidance: start with .phase-loop/tui-handoff.md or `phase-loop handoff`, "
63
+ "then verify `phase-loop status --json` before relaunching repair. "
64
+ "Legacy .codex/phase-loop state remains readable during migration."
65
+ )
66
+ if snapshot.ledger_warnings:
67
+ lines.append(f"Ledger warnings: {len(snapshot.ledger_warnings)}")
68
+ if ledger_debug:
69
+ lines.extend(_ledger_debug_lines(snapshot.ledger_warnings))
70
+ lines.extend(_ledger_duplicate_debug_lines(snapshot.ledger_duplicates_skipped))
71
+ return "\n".join(lines)
72
+
73
+
74
+ def render_state_inspection(summary: dict[str, object], as_json: bool = False) -> str:
75
+ if as_json:
76
+ return json.dumps(summary, indent=2, sort_keys=True)
77
+ lines = [
78
+ f"State path: {summary.get('state_path')}",
79
+ f"Events: {summary.get('event_count', 0)}",
80
+ f"Current phase: {summary.get('current_phase') or 'unknown'}",
81
+ f"Runs path: {summary.get('runs_path')}",
82
+ f"Stop file: {summary.get('stop_file')}",
83
+ f"TUI handoff: {summary.get('tui_handoff_path')}",
84
+ f"Stop requested: {summary.get('stop_requested', False)}",
85
+ f"Legacy entries: {summary.get('legacy_count', 0)}",
86
+ f"Ledger warnings: {summary.get('mismatch_count', 0)}",
87
+ ]
88
+ if summary.get("last_event"):
89
+ last = summary["last_event"]
90
+ lines.append(f"Last event: {last.get('phase')} {last.get('status')} {last.get('timestamp')}")
91
+ if summary.get("latest_heartbeat"):
92
+ heartbeat = summary["latest_heartbeat"]
93
+ lines.append(
94
+ "Heartbeat: "
95
+ f"alive={heartbeat.get('process_alive')} "
96
+ f"level={heartbeat.get('quiet_level')} "
97
+ f"elapsed={heartbeat.get('elapsed_seconds', 'unknown')}s "
98
+ f"quiet={heartbeat.get('seconds_since_log_update', 'unknown')}s"
99
+ )
100
+ if summary.get("latest_terminal_summary"):
101
+ lines.extend(_terminal_summary_lines(summary["latest_terminal_summary"]))
102
+ if summary.get("latest_metric"):
103
+ latest = summary["latest_metric"]
104
+ lines.append(f"Latest metric: {latest.get('metric_id')} {latest.get('terminal_status', 'unknown')}")
105
+ if summary.get("metrics_summary"):
106
+ lines.extend(_metrics_summary_lines(summary["metrics_summary"]))
107
+ if summary.get("dirty_paths"):
108
+ lines.append(f"Dirty paths: {', '.join(summary['dirty_paths'])}")
109
+ lines.append(f"Phase-owned dirty: {summary.get('phase_owned_dirty', False)}")
110
+ if summary.get("phase_owned_dirty_paths"):
111
+ lines.append(f"Phase-owned paths: {', '.join(summary['phase_owned_dirty_paths'])}")
112
+ if summary.get("previous_phase_owned_paths"):
113
+ lines.append(f"Previous phase-owned paths: {', '.join(summary['previous_phase_owned_paths'])}")
114
+ if summary.get("unowned_dirty_paths"):
115
+ lines.append(f"Unowned paths: {', '.join(summary['unowned_dirty_paths'])}")
116
+ if summary.get("pre_existing_dirty_paths"):
117
+ lines.append(f"Pre-existing paths: {', '.join(summary['pre_existing_dirty_paths'])}")
118
+ if summary.get("closeout_summary"):
119
+ lines.extend(_closeout_summary_lines(summary["closeout_summary"]))
120
+ return "\n".join(lines)
121
+
122
+
123
+ def render_archive_result(summary: dict[str, object], as_json: bool = False) -> str:
124
+ if as_json:
125
+ return json.dumps(summary, indent=2, sort_keys=True)
126
+ moved = summary.get("moved", ())
127
+ if summary.get("dry_run"):
128
+ if not moved:
129
+ return "Dry-run: no phase-loop state files to archive (no changes made)."
130
+ return (
131
+ f"Dry-run: would archive {len(moved)} phase-loop state file(s) to "
132
+ f"{summary.get('archive_path')} (no changes made)."
133
+ )
134
+ if not summary.get("archived"):
135
+ return "No phase-loop state files to archive."
136
+ return f"Archived {len(moved)} phase-loop state file(s) to {summary.get('archive_path')}"
137
+
138
+
139
+ def render_skill_sync_result(summary: dict[str, object], as_json: bool = False) -> str:
140
+ if as_json:
141
+ return json.dumps(summary, indent=2, sort_keys=True)
142
+ lines = [
143
+ f"Mode: {summary.get('mode', 'check')}",
144
+ f"Repo: {summary.get('repo')}",
145
+ f"Harnesses: {', '.join(summary.get('harnesses', []))}",
146
+ ]
147
+ blocker = summary.get("blocker")
148
+ if isinstance(blocker, dict) and blocker.get("blocker_class"):
149
+ lines.append(f"Blocked: {blocker['blocker_class']}")
150
+ if blocker.get("blocker_summary"):
151
+ lines.append(f"Blocker summary: {blocker['blocker_summary']}")
152
+ for record in summary.get("bridge_skills", []):
153
+ if not isinstance(record, dict):
154
+ continue
155
+ skill_name = record.get("skill_name") or "unknown"
156
+ lines.append(f"Bridge parity: {record.get('harness_target')}: {skill_name} -> {record.get('parity_status', 'unknown')}")
157
+ if record.get("repair_target"):
158
+ lines.append(f" repair target: {record['repair_target']}")
159
+ for record in summary.get("workflow_sources", []):
160
+ if not isinstance(record, dict):
161
+ continue
162
+ skill_name = record.get("skill_name") or "unknown"
163
+ lines.append(f"Workflow source: {record.get('harness_target')}: {skill_name} -> {record.get('parity_status', 'unknown')}")
164
+ for record in summary.get("vestigial_workflow_candidates", []):
165
+ if not isinstance(record, dict):
166
+ continue
167
+ lines.append(f"Vestigial workflow: {record.get('path')} -> {record.get('status', 'unknown')}")
168
+ for record in summary.get("skill_classifications", []):
169
+ if not isinstance(record, dict):
170
+ continue
171
+ skill_name = record.get("skill_name") or "unknown"
172
+ replacement = record.get("canonical_replacement")
173
+ suffix = f" replacement={replacement}" if replacement else ""
174
+ lines.append(
175
+ f"Skill classification: {skill_name} -> {record.get('classification', 'unknown')}{suffix}"
176
+ )
177
+ changed = summary.get("changed", [])
178
+ if changed:
179
+ lines.append(f"Repaired bridge skills: {len(changed)}")
180
+ unrepaired = summary.get("unrepaired", [])
181
+ if unrepaired:
182
+ lines.append(f"Could NOT repair {len(unrepaired)} bridge skill(s) — no skill source resolved:")
183
+ for record in unrepaired:
184
+ if not isinstance(record, dict):
185
+ continue
186
+ lines.append(
187
+ f" unrepaired: {record.get('harness_target')}: {record.get('skill_name')} "
188
+ f"({record.get('reason', 'unknown')})"
189
+ )
190
+ return "\n".join(lines)
191
+
192
+
193
+ def _closeout_summary_lines(summary: dict[str, object]) -> list[str]:
194
+ lines: list[str] = []
195
+ mode = summary.get("closeout_mode")
196
+ action = summary.get("closeout_action")
197
+ if mode:
198
+ lines.append(f"Closeout mode: {mode}")
199
+ if action:
200
+ lines.append(f"Closeout action: {action}")
201
+ if summary.get("closeout_commit"):
202
+ lines.append(f"Closeout commit: {summary['closeout_commit']}")
203
+ if summary.get("closeout_push_ref"):
204
+ lines.append(f"Closeout push ref: {summary['closeout_push_ref']}")
205
+ if summary.get("closeout_refusal_reason"):
206
+ lines.append(f"Closeout refusal: {summary['closeout_refusal_reason']}")
207
+ if summary.get("verification_status"):
208
+ lines.append(f"Closeout verification: {summary['verification_status']}")
209
+ return lines
210
+
211
+
212
+ def _terminal_summary_lines(summary: dict[str, object]) -> list[str]:
213
+ lines = [
214
+ f"Terminal status: {summary.get('terminal_status', 'unknown')}",
215
+ f"Terminal verification: {summary.get('verification_status', 'unknown')}",
216
+ f"Phase-owned dirty: {'yes' if summary.get('phase_owned_dirty') else 'no'}",
217
+ ]
218
+ if summary.get("metric_id"):
219
+ lines.append(f"Metric id: {summary['metric_id']}")
220
+ closeout = summary.get("phase_loop_closeout")
221
+ if isinstance(closeout, dict):
222
+ lines.append(f"Pipeline closeout: {closeout.get('outcome', 'unknown')} {closeout.get('pipeline_phase_id', 'unknown')}")
223
+ if summary.get("next_action"):
224
+ lines.append(f"Next action: {summary['next_action']}")
225
+ blocker = summary.get("terminal_blocker")
226
+ if isinstance(blocker, dict) and blocker.get("blocker_class"):
227
+ lines.append(f"Terminal blocker: {blocker['blocker_class']}")
228
+ if blocker.get("blocker_summary"):
229
+ lines.append(f"Terminal blocker summary: {blocker['blocker_summary']}")
230
+ dirty_paths = summary.get("dirty_paths")
231
+ if dirty_paths:
232
+ lines.append(f"Terminal dirty paths: {', '.join(dirty_paths)}")
233
+ return lines
234
+
235
+
236
+ def _metrics_summary_lines(summary: dict[str, object]) -> list[str]:
237
+ if not summary.get("total"):
238
+ return []
239
+ lines = [f"Metrics: {summary.get('total')} recent work unit(s)"]
240
+ if summary.get("not_run_alert"):
241
+ lines.append(
242
+ "Verification not_run alert: "
243
+ f"{summary.get('not_run_count')} of {summary.get('sample_size')} "
244
+ f"recent work units ({summary.get('not_run_ratio')}) exceeded threshold {summary.get('threshold')}"
245
+ )
246
+ for label, key in (
247
+ ("Executors", "by_executor"),
248
+ ("Models", "by_model"),
249
+ ("Efforts", "by_effort"),
250
+ ("Terminal statuses", "by_terminal_status"),
251
+ ("Verification", "by_verification_status"),
252
+ ("Blockers", "by_blocker_class"),
253
+ ):
254
+ bucket = summary.get(key)
255
+ if isinstance(bucket, dict) and bucket:
256
+ lines.append(f"{label}: {_format_counts(bucket)}")
257
+ return lines
258
+
259
+
260
+ def _format_counts(bucket: dict[str, object]) -> str:
261
+ return ", ".join(f"{key}={value}" for key, value in sorted(bucket.items()))
262
+
263
+
264
+ def _ledger_debug_lines(warnings: tuple[dict[str, object], ...]) -> list[str]:
265
+ lines = ["Rejected events:"]
266
+ if not warnings:
267
+ lines.append(" none")
268
+ return lines
269
+ for warning in warnings:
270
+ record = _ledger_debug_record(warning)
271
+ summary = _format_raw_event_summary(record.get("raw_event_summary"))
272
+ lines.append(
273
+ " "
274
+ f"phase={record.get('phase') or 'unknown'} "
275
+ f"timestamp={record.get('timestamp') or 'unknown'} "
276
+ f"action={record.get('action') or 'unknown'} "
277
+ f"status={record.get('status') or 'unknown'} "
278
+ f"reason={record.get('reason') or 'unknown'} "
279
+ f"raw_event_summary={summary}"
280
+ )
281
+ return lines
282
+
283
+
284
+ def _ledger_debug_record(warning: dict[str, object]) -> dict[str, object]:
285
+ return {
286
+ "phase": warning.get("phase"),
287
+ "timestamp": warning.get("timestamp"),
288
+ "action": warning.get("action"),
289
+ "status": warning.get("status"),
290
+ "reason": warning.get("canonical_reason") or warning.get("reason"),
291
+ "raw_event_summary": warning.get("raw_event_summary") or _legacy_raw_event_summary(warning),
292
+ }
293
+
294
+
295
+ def _ledger_duplicate_debug_lines(duplicates: tuple[dict[str, object], ...]) -> list[str]:
296
+ lines = ["Duplicates skipped:"]
297
+ if not duplicates:
298
+ lines.append(" none")
299
+ return lines
300
+ lines.append(f" count={len(duplicates)}")
301
+ for duplicate in duplicates:
302
+ record = _ledger_duplicate_debug_record(duplicate)
303
+ summary = _format_raw_event_summary(record.get("raw_event_summary"))
304
+ lines.append(
305
+ " "
306
+ f"phase={record.get('phase') or 'unknown'} "
307
+ f"timestamp={record.get('timestamp') or 'unknown'} "
308
+ f"action={record.get('action') or 'unknown'} "
309
+ f"status={record.get('status') or 'unknown'} "
310
+ f"automation_status={record.get('automation_status') or 'unknown'} "
311
+ f"blocker_class={record.get('blocker_class') or 'none'} "
312
+ f"duplicate_key={_format_raw_event_summary(record.get('duplicate_key'))} "
313
+ f"raw_event_summary={summary}"
314
+ )
315
+ return lines
316
+
317
+
318
+ def _ledger_duplicate_debug_record(duplicate: dict[str, object]) -> dict[str, object]:
319
+ return {
320
+ "phase": duplicate.get("phase"),
321
+ "timestamp": duplicate.get("timestamp"),
322
+ "action": duplicate.get("action"),
323
+ "status": duplicate.get("status"),
324
+ "automation_status": duplicate.get("automation_status"),
325
+ "blocker_class": duplicate.get("blocker_class"),
326
+ "duplicate_key": duplicate.get("duplicate_key") or {},
327
+ "raw_event_summary": duplicate.get("raw_event_summary") or _legacy_raw_event_summary(duplicate),
328
+ }
329
+
330
+
331
+ def _legacy_raw_event_summary(warning: dict[str, object]) -> dict[str, object]:
332
+ return {
333
+ key: warning[key]
334
+ for key in ("source", "phase", "status")
335
+ if warning.get(key) not in (None, "")
336
+ }
337
+
338
+
339
+ def _format_raw_event_summary(value: object) -> str:
340
+ if isinstance(value, dict):
341
+ return ",".join(f"{key}={value[key]}" for key in sorted(value))
342
+ if value is None:
343
+ return "none"
344
+ return str(value)
345
+
346
+
347
+ def _resolve_execution_policy_block(snapshot: StateSnapshot) -> dict[str, dict[str, dict[str, object]]]:
348
+ repo = Path(snapshot.repo)
349
+ roadmap = Path(snapshot.roadmap) if snapshot.roadmap else None
350
+ if roadmap is None or not roadmap.exists():
351
+ return {}
352
+ try:
353
+ roadmap_doc = parse_execution_policy(roadmap, kind="roadmap")
354
+ except Exception:
355
+ roadmap_doc = None
356
+ result: dict[str, dict[str, dict[str, object]]] = {}
357
+ for phase in snapshot.phases:
358
+ plan_path = find_plan_artifact(repo, phase, roadmap=roadmap)
359
+ try:
360
+ plan_doc = parse_execution_policy(plan_path, kind="plan") if plan_path is not None else None
361
+ except Exception:
362
+ plan_doc = None
363
+ per_action: dict[str, dict[str, object]] = {}
364
+ for action in EXECUTION_POLICY_ACTIONS:
365
+ rule = None
366
+ source = None
367
+ if plan_doc is not None:
368
+ rule = execution_policy_for_action(plan_doc, action)
369
+ if rule is not None:
370
+ source = "phase-plan policy"
371
+ if rule is None and roadmap_doc is not None:
372
+ rule = execution_policy_for_action(roadmap_doc, action)
373
+ if rule is not None:
374
+ source = "roadmap policy"
375
+ if rule is None:
376
+ continue
377
+ per_action[action] = {
378
+ "executor": rule.executor,
379
+ "model": rule.model,
380
+ "effort": rule.effort,
381
+ "source": source,
382
+ }
383
+ if per_action:
384
+ result[phase] = per_action
385
+ return result
386
+
387
+
388
+ def _live_git_topology_lines(topology: dict[str, object] | None) -> list[str]:
389
+ if not isinstance(topology, dict) or not topology.get("available"):
390
+ return []
391
+ branch = topology.get("branch")
392
+ head = topology.get("head")
393
+ clean = topology.get("clean")
394
+ lines = ["Live git topology:"]
395
+ if branch:
396
+ lines.append(f" Branch: {branch}")
397
+ if isinstance(head, str) and head:
398
+ lines.append(f" HEAD: {head[:12]}")
399
+ if clean is True:
400
+ lines.append(" Working tree: clean")
401
+ elif clean is False:
402
+ dirty_count = _dirty_path_count(topology.get("status_short_branch"))
403
+ if dirty_count is None:
404
+ lines.append(" Working tree: dirty")
405
+ else:
406
+ suffix = "path" if dirty_count == 1 else "paths"
407
+ lines.append(f" Working tree: dirty ({dirty_count} {suffix})")
408
+ return lines
409
+
410
+
411
+ def _dirty_path_count(status_short_branch: object) -> int | None:
412
+ if not isinstance(status_short_branch, str) or not status_short_branch:
413
+ return None
414
+ return sum(1 for line in status_short_branch.splitlines() if line and not line.startswith("##"))
415
+
416
+
417
+ def _current_terminal_summary(snapshot: StateSnapshot) -> dict[str, object] | None:
418
+ if not snapshot.terminal_summary:
419
+ return None
420
+ if snapshot.current_phase is None and snapshot.phases and all(status == "complete" for status in snapshot.phases.values()):
421
+ if snapshot.terminal_summary.get("terminal_status") != "complete":
422
+ return None
423
+ phase = snapshot.terminal_summary.get("phase")
424
+ closeout = snapshot.closeout_summary or {}
425
+ if (
426
+ phase
427
+ and phase != snapshot.current_phase
428
+ and closeout.get("phase") == phase
429
+ and closeout.get("closeout_commit")
430
+ ):
431
+ return None
432
+ return snapshot.terminal_summary