okstra 0.174.0 → 0.175.1

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 (374) hide show
  1. package/README.md +18 -9
  2. package/bin/okstra +8 -4
  3. package/dist/cli-registry.d.mts +16 -0
  4. package/dist/cli-registry.mjs +560 -0
  5. package/dist/cli-registry.mjs.map +1 -0
  6. package/dist/commands/execute/agent-prompt.d.mts +1 -0
  7. package/{src → dist}/commands/execute/agent-prompt.mjs +10 -11
  8. package/dist/commands/execute/agent-prompt.mjs.map +1 -0
  9. package/dist/commands/execute/codex-dispatch.d.mts +3 -0
  10. package/dist/commands/execute/codex-dispatch.mjs +6 -0
  11. package/dist/commands/execute/codex-dispatch.mjs.map +1 -0
  12. package/dist/commands/execute/codex-run.d.mts +3 -0
  13. package/{src → dist}/commands/execute/codex-run.mjs +30 -37
  14. package/dist/commands/execute/codex-run.mjs.map +1 -0
  15. package/dist/commands/execute/convergence.d.mts +1 -0
  16. package/{src → dist}/commands/execute/convergence.mjs +15 -16
  17. package/dist/commands/execute/convergence.mjs.map +1 -0
  18. package/dist/commands/execute/error-log.d.mts +1 -0
  19. package/{src → dist}/commands/execute/error-log.mjs +2 -3
  20. package/dist/commands/execute/error-log.mjs.map +1 -0
  21. package/dist/commands/execute/git-reconcile.d.mts +1 -0
  22. package/{src → dist}/commands/execute/git-reconcile.mjs +10 -11
  23. package/dist/commands/execute/git-reconcile.mjs.map +1 -0
  24. package/dist/commands/execute/handoff.d.mts +1 -0
  25. package/{src → dist}/commands/execute/handoff.mjs +10 -11
  26. package/dist/commands/execute/handoff.mjs.map +1 -0
  27. package/dist/commands/execute/incremental-carry.d.mts +1 -0
  28. package/{src → dist}/commands/execute/incremental-carry.mjs +2 -3
  29. package/dist/commands/execute/incremental-carry.mjs.map +1 -0
  30. package/dist/commands/execute/incremental-scope.d.mts +1 -0
  31. package/{src → dist}/commands/execute/incremental-scope.mjs +2 -3
  32. package/dist/commands/execute/incremental-scope.mjs.map +1 -0
  33. package/dist/commands/execute/integrate-stages.d.mts +1 -0
  34. package/{src → dist}/commands/execute/integrate-stages.mjs +10 -11
  35. package/dist/commands/execute/integrate-stages.mjs.map +1 -0
  36. package/dist/commands/execute/pane-title.d.mts +1 -0
  37. package/dist/commands/execute/pane-title.mjs +20 -0
  38. package/dist/commands/execute/pane-title.mjs.map +1 -0
  39. package/dist/commands/execute/plan-items.d.mts +1 -0
  40. package/dist/commands/execute/plan-items.mjs +9 -0
  41. package/dist/commands/execute/plan-items.mjs.map +1 -0
  42. package/dist/commands/execute/plan-validate.d.mts +1 -0
  43. package/dist/commands/execute/plan-validate.mjs +68 -0
  44. package/dist/commands/execute/plan-validate.mjs.map +1 -0
  45. package/dist/commands/execute/plan-verify.d.mts +1 -0
  46. package/{src → dist}/commands/execute/plan-verify.mjs +13 -16
  47. package/dist/commands/execute/plan-verify.mjs.map +1 -0
  48. package/dist/commands/execute/render-bundle.d.mts +3 -0
  49. package/{src → dist}/commands/execute/render-bundle.mjs +65 -61
  50. package/dist/commands/execute/render-bundle.mjs.map +1 -0
  51. package/dist/commands/execute/run.d.mts +24 -0
  52. package/dist/commands/execute/run.mjs +196 -0
  53. package/dist/commands/execute/run.mjs.map +1 -0
  54. package/dist/commands/execute/spawn-followups.d.mts +1 -0
  55. package/{src → dist}/commands/execute/spawn-followups.mjs +6 -7
  56. package/dist/commands/execute/spawn-followups.mjs.map +1 -0
  57. package/dist/commands/execute/team.d.mts +3 -0
  58. package/{src → dist}/commands/execute/team.mjs +29 -36
  59. package/dist/commands/execute/team.mjs.map +1 -0
  60. package/dist/commands/execute/token-usage.d.mts +1 -0
  61. package/{src → dist}/commands/execute/token-usage.mjs +2 -3
  62. package/dist/commands/execute/token-usage.mjs.map +1 -0
  63. package/dist/commands/execute/wizard.d.mts +8 -0
  64. package/dist/commands/execute/wizard.mjs +191 -0
  65. package/dist/commands/execute/wizard.mjs.map +1 -0
  66. package/dist/commands/execute/worker-audit-check.d.mts +1 -0
  67. package/{src → dist}/commands/execute/worker-audit-check.mjs +11 -12
  68. package/dist/commands/execute/worker-audit-check.mjs.map +1 -0
  69. package/dist/commands/execute/worker-dispatch.d.mts +7 -0
  70. package/{src → dist}/commands/execute/worker-dispatch.mjs +34 -46
  71. package/dist/commands/execute/worker-dispatch.mjs.map +1 -0
  72. package/dist/commands/execute/worker-state.d.mts +1 -0
  73. package/{src → dist}/commands/execute/worker-state.mjs +15 -16
  74. package/dist/commands/execute/worker-state.mjs.map +1 -0
  75. package/dist/commands/execute/worktree-lookup.d.mts +1 -0
  76. package/{src → dist}/commands/execute/worktree-lookup.mjs +38 -37
  77. package/dist/commands/execute/worktree-lookup.mjs.map +1 -0
  78. package/dist/commands/execute/worktree-status.d.mts +1 -0
  79. package/{src → dist}/commands/execute/worktree-status.mjs +52 -46
  80. package/dist/commands/execute/worktree-status.mjs.map +1 -0
  81. package/dist/commands/inspect/code-review.d.mts +1 -0
  82. package/{src → dist}/commands/inspect/code-review.mjs +16 -19
  83. package/dist/commands/inspect/code-review.mjs.map +1 -0
  84. package/dist/commands/inspect/container.d.mts +1 -0
  85. package/{src → dist}/commands/inspect/container.mjs +11 -13
  86. package/dist/commands/inspect/container.mjs.map +1 -0
  87. package/dist/commands/inspect/context-cost.d.mts +1 -0
  88. package/{src → dist}/commands/inspect/context-cost.mjs +11 -13
  89. package/dist/commands/inspect/context-cost.mjs.map +1 -0
  90. package/dist/commands/inspect/design-prep.d.mts +1 -0
  91. package/{src → dist}/commands/inspect/design-prep.mjs +10 -11
  92. package/dist/commands/inspect/design-prep.mjs.map +1 -0
  93. package/dist/commands/inspect/error-report.d.mts +1 -0
  94. package/{src → dist}/commands/inspect/error-report.mjs +11 -13
  95. package/dist/commands/inspect/error-report.mjs.map +1 -0
  96. package/dist/commands/inspect/error-zip.d.mts +1 -0
  97. package/{src → dist}/commands/inspect/error-zip.mjs +11 -12
  98. package/dist/commands/inspect/error-zip.mjs.map +1 -0
  99. package/dist/commands/inspect/log-report.d.mts +1 -0
  100. package/{src → dist}/commands/inspect/log-report.mjs +11 -13
  101. package/dist/commands/inspect/log-report.mjs.map +1 -0
  102. package/dist/commands/inspect/profile-show.d.mts +1 -0
  103. package/{src → dist}/commands/inspect/profile-show.mjs +10 -11
  104. package/dist/commands/inspect/profile-show.mjs.map +1 -0
  105. package/dist/commands/inspect/recap.d.mts +1 -0
  106. package/{src → dist}/commands/inspect/recap.mjs +11 -13
  107. package/dist/commands/inspect/recap.mjs.map +1 -0
  108. package/dist/commands/inspect/resolve-task-key.d.mts +1 -0
  109. package/{src → dist}/commands/inspect/resolve-task-key.mjs +11 -13
  110. package/dist/commands/inspect/resolve-task-key.mjs.map +1 -0
  111. package/dist/commands/inspect/rollup.d.mts +1 -0
  112. package/{src → dist}/commands/inspect/rollup.mjs +11 -13
  113. package/dist/commands/inspect/rollup.mjs.map +1 -0
  114. package/dist/commands/inspect/run-audit.d.mts +1 -0
  115. package/{src → dist}/commands/inspect/run-audit.mjs +11 -12
  116. package/dist/commands/inspect/run-audit.mjs.map +1 -0
  117. package/dist/commands/inspect/set-work-status.d.mts +1 -0
  118. package/{src → dist}/commands/inspect/set-work-status.mjs +11 -13
  119. package/dist/commands/inspect/set-work-status.mjs.map +1 -0
  120. package/dist/commands/inspect/stage-map.d.mts +1 -0
  121. package/dist/commands/inspect/stage-map.mjs +110 -0
  122. package/dist/commands/inspect/stage-map.mjs.map +1 -0
  123. package/dist/commands/inspect/task-list.d.mts +1 -0
  124. package/dist/commands/inspect/task-list.mjs +103 -0
  125. package/dist/commands/inspect/task-list.mjs.map +1 -0
  126. package/dist/commands/inspect/task-show.d.mts +1 -0
  127. package/dist/commands/inspect/task-show.mjs +108 -0
  128. package/dist/commands/inspect/task-show.mjs.map +1 -0
  129. package/dist/commands/inspect/time-report.d.mts +1 -0
  130. package/{src → dist}/commands/inspect/time-report.mjs +11 -13
  131. package/dist/commands/inspect/time-report.mjs.map +1 -0
  132. package/dist/commands/inspect/usage-report.d.mts +1 -0
  133. package/{src → dist}/commands/inspect/usage-report.mjs +11 -13
  134. package/dist/commands/inspect/usage-report.mjs.map +1 -0
  135. package/dist/commands/inspect/user-response.d.mts +1 -0
  136. package/{src → dist}/commands/inspect/user-response.mjs +10 -11
  137. package/dist/commands/inspect/user-response.mjs.map +1 -0
  138. package/dist/commands/inspect/worker-liveness.d.mts +1 -0
  139. package/{src → dist}/commands/inspect/worker-liveness.mjs +11 -13
  140. package/dist/commands/inspect/worker-liveness.mjs.map +1 -0
  141. package/dist/commands/lifecycle/check-project.d.mts +21 -0
  142. package/dist/commands/lifecycle/check-project.mjs +175 -0
  143. package/dist/commands/lifecycle/check-project.mjs.map +1 -0
  144. package/dist/commands/lifecycle/config.d.mts +1 -0
  145. package/dist/commands/lifecycle/config.mjs +369 -0
  146. package/dist/commands/lifecycle/config.mjs.map +1 -0
  147. package/dist/commands/lifecycle/doctor.d.mts +10 -0
  148. package/dist/commands/lifecycle/doctor.mjs +317 -0
  149. package/dist/commands/lifecycle/doctor.mjs.map +1 -0
  150. package/dist/commands/lifecycle/install.d.mts +17 -0
  151. package/dist/commands/lifecycle/install.mjs +1077 -0
  152. package/dist/commands/lifecycle/install.mjs.map +1 -0
  153. package/dist/commands/lifecycle/migrate.d.mts +1 -0
  154. package/{src → dist}/commands/lifecycle/migrate.mjs +10 -11
  155. package/dist/commands/lifecycle/migrate.mjs.map +1 -0
  156. package/dist/commands/lifecycle/model.d.mts +1 -0
  157. package/dist/commands/lifecycle/model.mjs +22 -0
  158. package/dist/commands/lifecycle/model.mjs.map +1 -0
  159. package/dist/commands/lifecycle/paths.d.mts +1 -0
  160. package/dist/commands/lifecycle/paths.mjs +102 -0
  161. package/dist/commands/lifecycle/paths.mjs.map +1 -0
  162. package/dist/commands/lifecycle/preflight.d.mts +1 -0
  163. package/dist/commands/lifecycle/preflight.mjs +124 -0
  164. package/dist/commands/lifecycle/preflight.mjs.map +1 -0
  165. package/dist/commands/lifecycle/setup.d.mts +1 -0
  166. package/dist/commands/lifecycle/setup.mjs +297 -0
  167. package/dist/commands/lifecycle/setup.mjs.map +1 -0
  168. package/dist/commands/lifecycle/uninstall.d.mts +4 -0
  169. package/dist/commands/lifecycle/uninstall.mjs +262 -0
  170. package/dist/commands/lifecycle/uninstall.mjs.map +1 -0
  171. package/dist/commands/manager.d.mts +3 -0
  172. package/{src → dist}/commands/manager.mjs +25 -32
  173. package/dist/commands/manager.mjs.map +1 -0
  174. package/dist/commands/memory/memory.d.mts +1 -0
  175. package/dist/commands/memory/memory.mjs +569 -0
  176. package/dist/commands/memory/memory.mjs.map +1 -0
  177. package/dist/commands/pr/pr.d.mts +33 -0
  178. package/dist/commands/pr/pr.mjs +296 -0
  179. package/dist/commands/pr/pr.mjs.map +1 -0
  180. package/dist/commands/report/agent-activity.d.mts +1 -0
  181. package/{src → dist}/commands/report/agent-activity.mjs +11 -12
  182. package/dist/commands/report/agent-activity.mjs.map +1 -0
  183. package/dist/commands/report/finalize.d.mts +4 -0
  184. package/{src → dist}/commands/report/finalize.mjs +25 -32
  185. package/dist/commands/report/finalize.mjs.map +1 -0
  186. package/dist/commands/report/inject-report-index.d.mts +1 -0
  187. package/{src → dist}/commands/report/inject-report-index.mjs +6 -7
  188. package/dist/commands/report/inject-report-index.mjs.map +1 -0
  189. package/dist/commands/report/render-final-report.d.mts +1 -0
  190. package/{src → dist}/commands/report/render-final-report.mjs +6 -7
  191. package/dist/commands/report/render-final-report.mjs.map +1 -0
  192. package/dist/commands/report/render-views.d.mts +1 -0
  193. package/{src → dist}/commands/report/render-views.mjs +6 -7
  194. package/dist/commands/report/render-views.mjs.map +1 -0
  195. package/dist/commands/report/translate.d.mts +1 -0
  196. package/{src → dist}/commands/report/translate.mjs +6 -7
  197. package/dist/commands/report/translate.mjs.map +1 -0
  198. package/dist/lib/helper-scripts.d.mts +3 -0
  199. package/{src → dist}/lib/helper-scripts.mjs +11 -14
  200. package/dist/lib/helper-scripts.mjs.map +1 -0
  201. package/dist/lib/host-registry-client.d.mts +25 -0
  202. package/dist/lib/host-registry-client.mjs +152 -0
  203. package/dist/lib/host-registry-client.mjs.map +1 -0
  204. package/dist/lib/install-assets.d.mts +8 -0
  205. package/{src → dist}/lib/install-assets.mjs +17 -20
  206. package/dist/lib/install-assets.mjs.map +1 -0
  207. package/dist/lib/okstra-dirs.d.mts +4 -0
  208. package/{src → dist}/lib/okstra-dirs.mjs +3 -6
  209. package/dist/lib/okstra-dirs.mjs.map +1 -0
  210. package/dist/lib/paths.d.mts +4 -0
  211. package/dist/lib/paths.mjs +78 -0
  212. package/dist/lib/paths.mjs.map +1 -0
  213. package/dist/lib/proc.d.mts +3 -0
  214. package/dist/lib/proc.mjs +31 -0
  215. package/dist/lib/proc.mjs.map +1 -0
  216. package/dist/lib/python-helper.d.mts +8 -0
  217. package/dist/lib/python-helper.mjs +123 -0
  218. package/dist/lib/python-helper.mjs.map +1 -0
  219. package/dist/lib/runtime-manifest.d.mts +7 -0
  220. package/dist/lib/runtime-manifest.mjs +73 -0
  221. package/dist/lib/runtime-manifest.mjs.map +1 -0
  222. package/dist/lib/skill-catalog.d.mts +4 -0
  223. package/dist/lib/skill-catalog.mjs +50 -0
  224. package/dist/lib/skill-catalog.mjs.map +1 -0
  225. package/dist/lib/types.d.mts +129 -0
  226. package/dist/lib/types.mjs +2 -0
  227. package/dist/lib/types.mjs.map +1 -0
  228. package/dist/lib/version.d.mts +2 -0
  229. package/dist/lib/version.mjs +27 -0
  230. package/dist/lib/version.mjs.map +1 -0
  231. package/docs/architecture/storage-model.md +4 -0
  232. package/docs/architecture.md +7 -1
  233. package/docs/cli.md +26 -6
  234. package/docs/contributor-change-matrix.md +2 -2
  235. package/docs/project-structure-overview.md +16 -7
  236. package/docs/task-process/README.md +2 -0
  237. package/docs/task-process/implementation-planning.md +1 -1
  238. package/docs/task-process/implementation.md +1 -1
  239. package/package.json +11 -5
  240. package/runtime/BUILD.json +2 -2
  241. package/runtime/agents/workers/claude-worker.md +2 -1
  242. package/runtime/agents/workers/report-writer-worker.md +3 -1
  243. package/runtime/agents/workers/translator-worker.md +3 -1
  244. package/runtime/bin/lib/okstra/cli.sh +12 -0
  245. package/runtime/bin/lib/okstra/globals.sh +3 -0
  246. package/runtime/bin/lib/okstra/usage.sh +4 -4
  247. package/runtime/bin/okstra-error-log.py +27 -0
  248. package/runtime/bin/okstra-provider-exec.py +217 -5
  249. package/runtime/bin/okstra.sh +10 -0
  250. package/runtime/prompts/lead/convergence.md +27 -18
  251. package/runtime/prompts/lead/okstra-lead-contract.md +3 -1
  252. package/runtime/prompts/lead/plan-body-verification.md +10 -3
  253. package/runtime/prompts/lead/team-contract.md +1 -1
  254. package/runtime/prompts/profiles/change-impact-analysis.md +16 -0
  255. package/runtime/prompts/profiles/error-analysis.md +20 -0
  256. package/runtime/prompts/profiles/feature-analysis.md +16 -0
  257. package/runtime/prompts/profiles/final-verification.md +16 -0
  258. package/runtime/prompts/profiles/implementation-option-selection.md +16 -0
  259. package/runtime/prompts/profiles/implementation-planning.md +20 -0
  260. package/runtime/prompts/profiles/implementation.md +15 -0
  261. package/runtime/prompts/profiles/improvement-discovery.md +16 -0
  262. package/runtime/prompts/profiles/project-analysis.md +16 -0
  263. package/runtime/prompts/profiles/release-handoff.md +4 -0
  264. package/runtime/prompts/profiles/requirements-discovery.md +20 -0
  265. package/runtime/prompts/wizard/prompts.ko.json +18 -0
  266. package/runtime/python/okstra_ctl/adapters/dispatch/cli_wrapper.py +8 -0
  267. package/runtime/python/okstra_ctl/adapters/dispatch/cmux.py +8 -0
  268. package/runtime/python/okstra_ctl/adapters/dispatch/native_team.py +13 -0
  269. package/runtime/python/okstra_ctl/adapters/hosts/antigravity/adapter.py +2 -2
  270. package/runtime/python/okstra_ctl/adapters/hosts/claude-code/adapter.py +25 -5
  271. package/runtime/python/okstra_ctl/adapters/hosts/codex/adapter.py +2 -2
  272. package/runtime/python/okstra_ctl/adapters/hosts/external/adapter.py +4 -1
  273. package/runtime/python/okstra_ctl/adapters/hosts/grok/adapter.py +2 -2
  274. package/runtime/python/okstra_ctl/adapters/hosts/kimi/adapter.py +2 -2
  275. package/runtime/python/okstra_ctl/adapters/providers/antigravity/adapter.py +79 -11
  276. package/runtime/python/okstra_ctl/adapters/providers/claude/adapter.py +95 -25
  277. package/runtime/python/okstra_ctl/adapters/providers/codex/adapter.py +59 -14
  278. package/runtime/python/okstra_ctl/adapters/providers/grok/adapter.py +55 -9
  279. package/runtime/python/okstra_ctl/adapters/providers/kimi/adapter.py +51 -12
  280. package/runtime/python/okstra_ctl/agent_activity.py +5 -1
  281. package/runtime/python/okstra_ctl/agent_invocation.py +608 -14
  282. package/runtime/python/okstra_ctl/agent_prompt_cli.py +249 -50
  283. package/runtime/python/okstra_ctl/application/resolve_assignment.py +53 -12
  284. package/runtime/python/okstra_ctl/assignment_environment.py +102 -0
  285. package/runtime/python/okstra_ctl/assignment_resolver.py +790 -0
  286. package/runtime/python/okstra_ctl/attempt_evidence.py +342 -0
  287. package/runtime/python/okstra_ctl/convergence.py +409 -3
  288. package/runtime/python/okstra_ctl/convergence_engine.py +248 -15
  289. package/runtime/python/okstra_ctl/convergence_store.py +170 -1
  290. package/runtime/python/okstra_ctl/dispatch_core.py +1092 -63
  291. package/runtime/python/okstra_ctl/dispatch_state.py +696 -11
  292. package/runtime/python/okstra_ctl/doctor.py +14 -0
  293. package/runtime/python/okstra_ctl/domain/host.py +32 -1
  294. package/runtime/python/okstra_ctl/domain/provider.py +212 -6
  295. package/runtime/python/okstra_ctl/domain/role.py +125 -0
  296. package/runtime/python/okstra_ctl/domain/wizard/interaction.py +13 -0
  297. package/runtime/python/okstra_ctl/domain/worker_exec.py +34 -1
  298. package/runtime/python/okstra_ctl/domain/worker_role.py +13 -3
  299. package/runtime/python/okstra_ctl/domain/worker_stream.py +24 -0
  300. package/runtime/python/okstra_ctl/error_log_write.py +9 -0
  301. package/runtime/python/okstra_ctl/error_report.py +21 -1
  302. package/runtime/python/okstra_ctl/execution_identity.py +529 -0
  303. package/runtime/python/okstra_ctl/execution_manifest.py +1281 -0
  304. package/runtime/python/okstra_ctl/execution_mutation_audit.py +619 -0
  305. package/runtime/python/okstra_ctl/index.py +6 -2
  306. package/runtime/python/okstra_ctl/initial_prompt_materialization.py +43 -3
  307. package/runtime/python/okstra_ctl/legacy_model_selection.py +490 -0
  308. package/runtime/python/okstra_ctl/model_cli.py +278 -0
  309. package/runtime/python/okstra_ctl/model_defaults.py +46 -0
  310. package/runtime/python/okstra_ctl/model_discovery.py +26 -7
  311. package/runtime/python/okstra_ctl/model_pool.py +501 -0
  312. package/runtime/python/okstra_ctl/models.py +47 -27
  313. package/runtime/python/okstra_ctl/mutation_recovery.py +293 -0
  314. package/runtime/python/okstra_ctl/pane_title.py +151 -0
  315. package/runtime/python/okstra_ctl/ports/host_model.py +48 -17
  316. package/runtime/python/okstra_ctl/ports/worker_dispatch.py +4 -0
  317. package/runtime/python/okstra_ctl/registry/provider_registry.py +8 -4
  318. package/runtime/python/okstra_ctl/render.py +78 -10
  319. package/runtime/python/okstra_ctl/render_final_report.py +19 -0
  320. package/runtime/python/okstra_ctl/report_contract.py +39 -0
  321. package/runtime/python/okstra_ctl/report_finalize.py +16 -0
  322. package/runtime/python/okstra_ctl/report_html/render.py +1 -0
  323. package/runtime/python/okstra_ctl/role_requirements.py +217 -0
  324. package/runtime/python/okstra_ctl/run.py +1207 -258
  325. package/runtime/python/okstra_ctl/run_index_row.py +7 -1
  326. package/runtime/python/okstra_ctl/time_report.py +38 -4
  327. package/runtime/python/okstra_ctl/usage_identity.py +86 -0
  328. package/runtime/python/okstra_ctl/usage_report.py +15 -3
  329. package/runtime/python/okstra_ctl/wizard.py +1253 -62
  330. package/runtime/python/okstra_ctl/worker_audit_ledger.py +68 -65
  331. package/runtime/python/okstra_ctl/worker_request.py +7 -1
  332. package/runtime/python/okstra_ctl/worker_runner.py +130 -5
  333. package/runtime/python/okstra_ctl/workers.py +7 -5
  334. package/runtime/python/okstra_ctl/write_policy.py +571 -0
  335. package/runtime/schemas/convergence-groups-v2.0.schema.json +128 -0
  336. package/runtime/schemas/execution-manifest-v2.schema.json +340 -0
  337. package/runtime/schemas/final-report-v2.0.schema.json +25 -0
  338. package/runtime/skills/okstra-run/SKILL.md +9 -9
  339. package/runtime/templates/report-writer-prompt-preamble.md +2 -0
  340. package/runtime/templates/reports/final-report-v2.template.md +7 -1
  341. package/runtime/templates/reports/html/base.template.html +21 -0
  342. package/runtime/templates/reports/html/i18n/en.json +4 -0
  343. package/runtime/templates/reports/html/i18n/ko.json +4 -0
  344. package/runtime/templates/worker-prompt-preamble.md +6 -2
  345. package/runtime/validators/lib/fixtures.sh +49 -16
  346. package/runtime/validators/validate-run.py +429 -35
  347. package/runtime/validators/validate_session_conformance.py +25 -7
  348. package/src/cli-registry.mjs +0 -539
  349. package/src/commands/execute/codex-dispatch.mjs +0 -10
  350. package/src/commands/execute/plan-items.mjs +0 -9
  351. package/src/commands/execute/plan-validate.mjs +0 -68
  352. package/src/commands/execute/run.mjs +0 -208
  353. package/src/commands/execute/wizard.mjs +0 -167
  354. package/src/commands/inspect/stage-map.mjs +0 -98
  355. package/src/commands/inspect/task-list.mjs +0 -97
  356. package/src/commands/inspect/task-show.mjs +0 -100
  357. package/src/commands/lifecycle/check-project.mjs +0 -187
  358. package/src/commands/lifecycle/config.mjs +0 -385
  359. package/src/commands/lifecycle/doctor.mjs +0 -308
  360. package/src/commands/lifecycle/install.mjs +0 -1170
  361. package/src/commands/lifecycle/paths.mjs +0 -104
  362. package/src/commands/lifecycle/preflight.mjs +0 -125
  363. package/src/commands/lifecycle/setup.mjs +0 -333
  364. package/src/commands/lifecycle/uninstall.mjs +0 -279
  365. package/src/commands/memory/memory.mjs +0 -524
  366. package/src/commands/pr/pr.mjs +0 -261
  367. package/src/lib/host-registry-client.mjs +0 -176
  368. package/src/lib/paths.mjs +0 -86
  369. package/src/lib/proc.mjs +0 -31
  370. package/src/lib/python-helper.mjs +0 -142
  371. package/src/lib/runtime-manifest.mjs +0 -70
  372. package/src/lib/skill-catalog.mjs +0 -53
  373. package/src/lib/version.mjs +0 -20
  374. /package/{src → dist}/commands/pr/default.md +0 -0
@@ -39,10 +39,36 @@ from .dispatch_state import (
39
39
  TEARDOWN_BEFORE_TERMINAL_REASON,
40
40
  utc_now as _utc_now,
41
41
  validate_dispatch_prompts as _validate_dispatch_prompts,
42
+ v2_worker_state_key as _v2_worker_state_key,
43
+ worker_execution_identity as _worker_execution_identity,
42
44
  worker_jobs_from_file as _worker_jobs_from_file,
43
45
  worker_state as _worker_state,
44
46
  worktree_path as _worktree_path,
45
47
  )
48
+ from .assignment_resolver import (
49
+ AssignmentEnvironment,
50
+ AssignmentResolutionError,
51
+ RoleInstance,
52
+ resolve_model_assignment,
53
+ )
54
+ from .domain.host import HostSessionContext
55
+ from .domain.provider import HostModelBinding, ServedModelAttestation
56
+ from .domain.worker_exec import SERVED_MODEL_MISMATCH_EXIT_CODE
57
+ from .execution_identity import Attempt, Invocation, RoleExecution, model_spec_digest
58
+ from .execution_manifest import (
59
+ finish_attempt_mutation,
60
+ read_execution_manifest,
61
+ record_invocation_attempt,
62
+ )
63
+ from .execution_mutation_audit import (
64
+ ExecutionMutationAudit,
65
+ MutationAuditResult,
66
+ MutationSnapshot,
67
+ assert_compatible_batch,
68
+ )
69
+ from .convergence_store import write_json_atomic
70
+ from .assignment_environment import load_assignment_context
71
+ from .model_pool import ModelPool
46
72
  from .error_log_write import append_observed
47
73
  from .lead_events import LeadEvent, append_lead_event
48
74
  from .initial_prompt_materialization import (
@@ -52,6 +78,7 @@ from .initial_prompt_materialization import (
52
78
  PromptDeliveryMode,
53
79
  materialize_initial_prompts,
54
80
  )
81
+ from .agent_invocation import AgentInvocationError, materialize_retry_invocation
55
82
  from .path_hints import hydrate_active_run_context
56
83
  from .schema_excerpt import bundle_excerpt_path, excerpt_version_skew
57
84
  from .seeding import installed_version
@@ -72,6 +99,15 @@ from .worker_prompt_headers import (
72
99
  )
73
100
  from .worker_artifact_paths import audit_sidecar_rel
74
101
  from .wrapper_status import read_wrapper_status, status_path_for_prompt
102
+ from .worker_request import verifier_extra_dirs
103
+ from .write_policy import (
104
+ WriteEnforcement,
105
+ WritePolicy,
106
+ build_invocation_write_contract,
107
+ planned_paths_from_run_manifest,
108
+ write_enforcement_from_payload,
109
+ write_policy_from_payload,
110
+ )
75
111
 
76
112
 
77
113
  MAX_WORKER_ATTEMPTS = 2
@@ -84,6 +120,102 @@ _WRAPPER_TIMEOUT_EXIT_CODE = 124
84
120
  _WRAPPER_LOG_TAIL_BYTES = 800
85
121
 
86
122
 
123
+ @dataclass(frozen=True)
124
+ class RevalidatedBinding:
125
+ role_execution_ref: str
126
+ binding: HostModelBinding
127
+ model_spec_digest: str
128
+
129
+
130
+ def revalidate_role_execution(
131
+ role_execution: RoleExecution,
132
+ pool: ModelPool,
133
+ host: AssignmentEnvironment,
134
+ ) -> RevalidatedBinding:
135
+ """Recompute one selected model binding without inspecting unrelated rows."""
136
+ if (
137
+ role_execution.model_ref is None
138
+ or role_execution.binding is None
139
+ or role_execution.model_spec_digest is None
140
+ ):
141
+ raise DispatchError("model binding changed: role execution is unbound")
142
+ try:
143
+ assignment = resolve_model_assignment(
144
+ instance=RoleInstance(
145
+ role_execution.role,
146
+ role_execution.role,
147
+ role_execution.ordinal,
148
+ ),
149
+ model_ref=role_execution.model_ref,
150
+ pool=pool,
151
+ host=HostSessionContext(
152
+ host_id=host.host_descriptor.id,
153
+ entry_mode="spawn-process",
154
+ available_functions=frozenset(),
155
+ interaction_surface="role-execution-dispatch",
156
+ ),
157
+ environment=host,
158
+ )
159
+ binding = assignment.binding
160
+ if binding is None:
161
+ raise AssignmentResolutionError("selected model has no worker binding")
162
+ digest = model_spec_digest(pool.resolve(role_execution.model_ref), binding)
163
+ except (ValueError, RuntimeError) as exc:
164
+ raise DispatchError(f"model binding changed: {exc}") from exc
165
+ identity_matches = (
166
+ assignment.provider_id == role_execution.provider
167
+ and assignment.model_id == role_execution.model_id
168
+ and binding == role_execution.binding
169
+ and digest == role_execution.model_spec_digest
170
+ )
171
+ if not identity_matches:
172
+ raise DispatchError("model binding changed for selected role execution")
173
+ return RevalidatedBinding(role_execution.role_execution_ref, binding, digest)
174
+
175
+
176
+ def dispatch_revalidated_role_execution(
177
+ role_execution: RoleExecution,
178
+ pool: ModelPool,
179
+ host: AssignmentEnvironment,
180
+ dispatch,
181
+ ):
182
+ """Run a dispatch callback only after the pure binding gate succeeds."""
183
+ binding = revalidate_role_execution(role_execution, pool, host)
184
+ return dispatch(binding)
185
+
186
+
187
+ def verify_served_model(
188
+ role_execution: RoleExecution,
189
+ attestation: ServedModelAttestation,
190
+ *,
191
+ pool: ModelPool,
192
+ ) -> ServedModelAttestation:
193
+ """Reject observed substitution while preserving unobservable attempts."""
194
+ if attestation.level == "unknown":
195
+ return attestation
196
+ if role_execution.model_ref is None or not attestation.normalized_model_ref:
197
+ raise DispatchError("served model differs from selected model")
198
+ try:
199
+ selected = pool.resolve(role_execution.model_ref)
200
+ observed = pool.resolve(attestation.normalized_model_ref)
201
+ except ValueError as exc:
202
+ raise DispatchError("served model differs from selected model") from exc
203
+ expected_level = "channel" if observed.version_kind == "channel" else "exact"
204
+ if attestation.level != expected_level:
205
+ raise DispatchError("served model attestation level is inconsistent")
206
+ if selected.version_kind == "pinned":
207
+ if str(selected.model_ref) != str(observed.model_ref):
208
+ raise DispatchError("served model differs from selected model")
209
+ return attestation
210
+ if (
211
+ selected.provider_id != observed.provider_id
212
+ or not selected.channel_family
213
+ or selected.channel_family != observed.channel_family
214
+ ):
215
+ raise DispatchError("served model channel family differs")
216
+ return attestation
217
+
218
+
87
219
  @dataclass(frozen=True)
88
220
  class WorkerHandle:
89
221
  job: WorkerJob
@@ -92,6 +224,11 @@ class WorkerHandle:
92
224
  status_sidecar_path: Path | None
93
225
  degraded_from: str
94
226
  running_process: subprocess.Popen[str] | None = None
227
+ mutation_snapshot: MutationSnapshot | None = None
228
+ mutation_policies: tuple[WritePolicy, ...] = ()
229
+ mutation_retry_allowed: bool = True
230
+ write_policy_digest: str = ""
231
+ write_enforcement: WriteEnforcement | None = None
95
232
 
96
233
 
97
234
  @dataclass(frozen=True)
@@ -223,6 +360,7 @@ def build_dispatch_plan(
223
360
  def dispatch_plan(plan: DispatchPlan, *, wait: bool = True) -> int:
224
361
  _validate_report_writer_isolation(plan.jobs)
225
362
  _validate_implementation_phase_order(plan.jobs)
363
+ _revalidate_plan_role_executions(plan)
226
364
  if wait:
227
365
  pane_backends = sorted(
228
366
  {
@@ -255,12 +393,43 @@ def dispatch_cli_wrapper_plan(plan: DispatchPlan) -> int:
255
393
  raise DispatchError("concurrent CLI dispatch requires cli-wrapper jobs only")
256
394
  _validate_report_writer_isolation(plan.jobs)
257
395
  _validate_implementation_phase_order(plan.jobs)
396
+ _revalidate_plan_role_executions(plan)
258
397
  _record_dispatch_facts(plan.team_state_path, _dispatch_mode(plan.jobs))
259
398
  final_codes = _dispatch_cli_wrapper_batch(plan, plan.jobs)
260
399
  return next((final_codes[job.worker_id] for job in plan.jobs
261
400
  if final_codes.get(job.worker_id, 0) != 0), 0)
262
401
 
263
402
 
403
+ def _revalidate_job_role_execution(plan: DispatchPlan, job: WorkerJob) -> None:
404
+ manifest = read_execution_manifest(plan.manifest_path)
405
+ executions = {
406
+ row.role_execution_ref: row for row in manifest.role_executions
407
+ }
408
+ context = load_assignment_context(
409
+ host_runtime=_require_string(plan.manifest, "leadRuntime"),
410
+ terminal_backend=_require_string(plan.manifest, "terminalBackend"),
411
+ execution_provider_ids=(job.provider,),
412
+ )
413
+ role_execution = executions.get(job.role_execution_ref)
414
+ if (
415
+ role_execution is None
416
+ or role_execution.participant_ref != job.participant_ref
417
+ or role_execution.execution_label != job.execution_label
418
+ ):
419
+ raise DispatchError("worker job role execution does not match run manifest")
420
+ revalidate_role_execution(
421
+ role_execution,
422
+ context.pool,
423
+ context.environment,
424
+ )
425
+
426
+
427
+ def _revalidate_plan_role_executions(plan: DispatchPlan) -> None:
428
+ for job in plan.jobs:
429
+ if job.has_execution_identity:
430
+ _revalidate_job_role_execution(plan, job)
431
+
432
+
264
433
  def _validate_report_writer_isolation(jobs: Sequence[WorkerJob]) -> None:
265
434
  if (
266
435
  any(job.worker_id == REPORT_WRITER_WORKER_ID for job in jobs)
@@ -328,15 +497,60 @@ def _dispatch_cli_wrapper_batch(
328
497
  """Run one concurrent batch through all retries before the next dependency."""
329
498
  pending = [(job, 1) for job in jobs]
330
499
  final_codes: dict[str, int] = {}
500
+ baseline_snapshot: MutationSnapshot | None = None
331
501
  while pending:
332
502
  active: list[tuple[WorkerHandle, int]] = []
503
+ draft_contracts = tuple(
504
+ _canonical_write_contract(plan, job) if job.has_execution_identity else None
505
+ for job, _attempt in pending
506
+ )
507
+ draft_policies = tuple(
508
+ contract[0] for contract in draft_contracts if contract is not None
509
+ )
510
+ if draft_policies:
511
+ assert_compatible_batch(draft_policies)
512
+ prepared = [
513
+ (_prepare_job_attempt(plan, job, attempt), attempt)
514
+ for job, attempt in pending
515
+ ]
516
+ contracts = tuple(
517
+ _persisted_write_contract(plan, job) for job, _ in prepared
518
+ )
519
+ policies = tuple(
520
+ contract[0] for contract in contracts if contract is not None
521
+ )
522
+ needs_batch = any(
523
+ contract is not None and contract[1].mutation_audit == "batch"
524
+ for contract in contracts
525
+ )
526
+ if needs_batch and baseline_snapshot is None:
527
+ baseline_snapshot = _mutation_snapshot(
528
+ plan, policies, tuple(job for job, _ in prepared)
529
+ )
530
+ snapshot = baseline_snapshot if needs_batch else None
333
531
  starting_job: WorkerJob | None = None
334
532
  starting_attempt = 1
335
533
  try:
336
- for job, attempt in pending:
534
+ for (job, attempt), contract in zip(prepared, contracts, strict=True):
337
535
  starting_job = job
338
536
  starting_attempt = attempt
339
- active.append((_spawn_cli_job_nonblocking(plan, job, attempt), attempt))
537
+ handle = _spawn_cli_job_nonblocking(plan, job, attempt)
538
+ handle = replace(
539
+ handle,
540
+ mutation_snapshot=snapshot,
541
+ mutation_policies=policies,
542
+ write_policy_digest=contract[0].digest if contract else "",
543
+ write_enforcement=contract[1] if contract else None,
544
+ )
545
+ active.append((handle, attempt))
546
+ _record_dispatch(
547
+ plan.team_state_path, handle, attempt, "running", ""
548
+ )
549
+ _append_event(
550
+ plan,
551
+ "worker-dispatched",
552
+ _attempt_details(job, attempt, handle),
553
+ )
340
554
  except (OSError, DispatchError) as exc:
341
555
  if starting_job is not None:
342
556
  _abort_cli_batch_start(
@@ -344,7 +558,9 @@ def _dispatch_cli_wrapper_batch(
344
558
  active,
345
559
  starting_job,
346
560
  starting_attempt,
347
- pending,
561
+ prepared,
562
+ snapshot,
563
+ policies,
348
564
  exc,
349
565
  )
350
566
  raise
@@ -361,11 +577,18 @@ def _dispatch_cli_wrapper_batch(
361
577
  next_round: list[tuple[WorkerJob, int]] = []
362
578
  for handle, attempt, outcome in outcomes:
363
579
  job = handle.job
364
- _finish_attempt(plan, job, attempt, outcome)
365
- if _worker_terminal_status(plan.team_state_path, job.worker_id) == "completed":
580
+ retry_allowed = _finish_attempt(
581
+ plan,
582
+ job,
583
+ attempt,
584
+ outcome,
585
+ snapshot=handle.mutation_snapshot,
586
+ policies=handle.mutation_policies,
587
+ )
588
+ if _job_terminal_status(plan, job, attempt) == "completed":
366
589
  final_codes[job.worker_id] = 0
367
590
  continue
368
- if _should_retry(outcome, attempt):
591
+ if _should_retry(outcome, attempt) and retry_allowed:
369
592
  _append_event(
370
593
  plan,
371
594
  "worker-retry-scheduled",
@@ -384,6 +607,8 @@ def _abort_cli_batch_start(
384
607
  failed_job: WorkerJob,
385
608
  failed_attempt: int,
386
609
  pending: Sequence[tuple[WorkerJob, int]],
610
+ snapshot: MutationSnapshot | None,
611
+ policies: Sequence[WritePolicy],
387
612
  error: Exception,
388
613
  ) -> None:
389
614
  reason = f"concurrent CLI batch launch failed: {error}"
@@ -395,15 +620,11 @@ def _abort_cli_batch_start(
395
620
  process = handle.running_process
396
621
  if process is not None:
397
622
  process.wait()
398
- _transition_worker_status(
399
- plan.team_state_path, handle.job.worker_id, "error", reason
400
- )
623
+ _transition_job_status(plan, handle.job, "error", reason)
401
624
  _update_dispatch_status(
402
625
  plan.team_state_path, handle.job, attempt, "error", reason
403
626
  )
404
- _transition_worker_status(
405
- plan.team_state_path, failed_job.worker_id, "error", reason
406
- )
627
+ _transition_job_status(plan, failed_job, "error", reason)
407
628
  if not _update_dispatch_status(
408
629
  plan.team_state_path,
409
630
  failed_job,
@@ -411,12 +632,19 @@ def _abort_cli_batch_start(
411
632
  "error",
412
633
  reason,
413
634
  ):
635
+ failed_contract = _persisted_write_contract(plan, failed_job)
414
636
  failed_handle = WorkerHandle(
415
637
  failed_job,
416
638
  "",
417
639
  None,
418
640
  status_path_for_prompt(failed_job.prompt_path),
419
641
  "",
642
+ mutation_snapshot=snapshot,
643
+ mutation_policies=tuple(policies),
644
+ write_policy_digest=(
645
+ failed_contract[0].digest if failed_contract else ""
646
+ ),
647
+ write_enforcement=(failed_contract[1] if failed_contract else None),
420
648
  )
421
649
  _record_dispatch(
422
650
  plan.team_state_path,
@@ -432,18 +660,21 @@ def _abort_cli_batch_start(
432
660
  for job, attempt in pending:
433
661
  if (job.worker_id, attempt) in closed:
434
662
  continue
435
- _transition_worker_status(
436
- plan.team_state_path, job.worker_id, "error", reason
437
- )
663
+ _transition_job_status(plan, job, "error", reason)
438
664
  if not _update_dispatch_status(
439
665
  plan.team_state_path, job, attempt, "error", reason
440
666
  ):
667
+ contract = _persisted_write_contract(plan, job)
441
668
  handle = WorkerHandle(
442
669
  job,
443
670
  "",
444
671
  None,
445
672
  status_path_for_prompt(job.prompt_path),
446
673
  "",
674
+ mutation_snapshot=snapshot,
675
+ mutation_policies=tuple(policies),
676
+ write_policy_digest=contract[0].digest if contract else "",
677
+ write_enforcement=contract[1] if contract else None,
447
678
  )
448
679
  _record_dispatch(
449
680
  plan.team_state_path,
@@ -452,6 +683,20 @@ def _abort_cli_batch_start(
452
683
  "error",
453
684
  reason,
454
685
  )
686
+ for job, attempt in pending:
687
+ if not job.has_execution_identity:
688
+ continue
689
+ outcome = WorkerOutcome(
690
+ returncode=1,
691
+ missing_completion_paths=_missing_completion_paths(job),
692
+ pane_id="",
693
+ status_sidecar_path=status_path_for_prompt(job.prompt_path),
694
+ timeout=False,
695
+ terminal_stage="launch-failed",
696
+ degraded_from="",
697
+ )
698
+ mutation = _audit_attempt(job, outcome, snapshot, policies)
699
+ _finish_manifest_attempt(plan, job, attempt, mutation, None)
455
700
 
456
701
 
457
702
  def await_dispatches(
@@ -497,6 +742,15 @@ def _jobs_from_roster(
497
742
  options,
498
743
  team_state=team_state,
499
744
  )
745
+ if selected == ["translator"]:
746
+ return [_translator_job_from_reservation(
747
+ project_root,
748
+ workspace_root,
749
+ manifest,
750
+ team_state,
751
+ active_context,
752
+ options,
753
+ )]
500
754
  _mark_roster_skips(project_root, manifest, team_state, selected, requested_workers, options)
501
755
  worker_facts, prompt_paths = _materialize_roster_prompts(
502
756
  project_root,
@@ -533,6 +787,18 @@ def _select_workers(
533
787
  recommended = _string_list(manifest.get("recommendedWorkers"))
534
788
  if not recommended:
535
789
  raise DispatchError("run manifest has no recommendedWorkers entries")
790
+ if tuple(requested_workers) == ("translator",):
791
+ provider = _canonical_translator_provider(manifest)
792
+ if provider is None:
793
+ raise DispatchError(
794
+ "translator dispatch requires a canonical translator role execution"
795
+ )
796
+ if provider not in options.supported_worker_wrappers:
797
+ raise DispatchError(
798
+ f"unsupported {options.unsupported_worker_label} translator provider: "
799
+ f"{provider}"
800
+ )
801
+ return ["translator"]
536
802
  if options.cli_wrapper_assignments_only:
537
803
  return _select_cli_wrapper_assignments(
538
804
  recommended,
@@ -564,6 +830,178 @@ def _select_workers(
564
830
  return selected
565
831
 
566
832
 
833
+ def _canonical_translator_provider(manifest: Mapping[str, Any]) -> str | None:
834
+ execution = _canonical_translator_execution(manifest)
835
+ return _string_value(execution.get("provider")) if execution else None
836
+
837
+
838
+ def _canonical_translator_execution(
839
+ manifest: Mapping[str, Any],
840
+ ) -> Mapping[str, Any] | None:
841
+ assignments = manifest.get("invocationAssignments")
842
+ assignment = (
843
+ assignments.get("translator") if isinstance(assignments, Mapping) else None
844
+ )
845
+ if not isinstance(assignment, Mapping):
846
+ return None
847
+ provider = _string_value(assignment.get("provider"))
848
+ model_execution = _string_value(assignment.get("modelExecutionValue"))
849
+ runner = _string_value(assignment.get("runner"))
850
+ if not provider or not model_execution or runner != BACKEND_CLI_WRAPPER:
851
+ return None
852
+ role_executions = manifest.get("roleExecutions")
853
+ matches = [
854
+ row
855
+ for row in role_executions
856
+ if isinstance(row, Mapping)
857
+ and row.get("role") == "translator"
858
+ and row.get("provider") == provider
859
+ and isinstance(row.get("binding"), Mapping)
860
+ and row["binding"].get("runner") == runner
861
+ and row["binding"].get("resolvedExecutionValue") == model_execution
862
+ ] if isinstance(role_executions, list) else []
863
+ return matches[0] if len(matches) == 1 else None
864
+
865
+
866
+ _TRANSLATOR_RESERVATION_KEYS = {
867
+ "schemaVersion", "executionIdentityVersion", "invocationId",
868
+ "assignmentRef", "audience", "dispatchKind", "promptPath",
869
+ "metadataPath", "invocationRef", "participantRef",
870
+ "roleExecutionRef", "dutyId", "attempt",
871
+ }
872
+
873
+
874
+ def _translator_job_from_reservation(
875
+ project_root: Path,
876
+ workspace_root: Path,
877
+ manifest: Mapping[str, Any],
878
+ team_state: Mapping[str, Any],
879
+ active_context: Mapping[str, Any],
880
+ options: _BuildOptions,
881
+ ) -> WorkerJob:
882
+ execution = _canonical_translator_execution(manifest)
883
+ if execution is None:
884
+ raise DispatchError(
885
+ "translator dispatch requires a canonical translator role execution"
886
+ )
887
+ contract = manifest.get("agentContract")
888
+ if not isinstance(contract, Mapping):
889
+ raise DispatchError("translator dispatch requires an agent contract")
890
+ reservation_root = _resolve_required_path(
891
+ project_root, contract, "invocationReservationRootPath"
892
+ )
893
+ dispatched_ids = {
894
+ str(row.get("dispatchId") or "")
895
+ for collection in (
896
+ team_state.get("workerDispatches") or [],
897
+ team_state.get("agentDispatches") or [],
898
+ )
899
+ for row in collection
900
+ if isinstance(row, Mapping)
901
+ }
902
+ candidates: list[Mapping[str, Any]] = []
903
+ for path in sorted(reservation_root.glob("*.json")):
904
+ reservation = _load_json_object(path, "agent invocation reservation")
905
+ if (
906
+ set(reservation) == _TRANSLATOR_RESERVATION_KEYS
907
+ and reservation.get("schemaVersion") == "2.0"
908
+ and reservation.get("executionIdentityVersion") == 2
909
+ and reservation.get("assignmentRef") == "translator"
910
+ and reservation.get("audience") == "translator"
911
+ and reservation.get("dispatchKind") == "translator"
912
+ and reservation.get("dutyId") == "translator"
913
+ and reservation.get("participantRef") == execution.get("participantRef")
914
+ and reservation.get("roleExecutionRef") == execution.get("roleExecutionRef")
915
+ and _build_dispatch_id(
916
+ str(reservation.get("invocationId") or ""),
917
+ int(reservation.get("attempt") or 0),
918
+ ) not in dispatched_ids
919
+ ):
920
+ candidates.append(reservation)
921
+ if len(candidates) != 1:
922
+ raise DispatchError(
923
+ "translator dispatch requires exactly one canonical invocation reservation"
924
+ )
925
+ reservation = candidates[0]
926
+ prompt_path = _resolve_project_path(
927
+ project_root, _require_string(reservation, "promptPath")
928
+ )
929
+ metadata_path = _resolve_project_path(
930
+ project_root, _require_string(reservation, "metadataPath")
931
+ )
932
+ expected_metadata = prompt_path.with_name(prompt_path.name + ".meta.json")
933
+ if metadata_path != expected_metadata:
934
+ raise DispatchError("translator invocation metadata path is not prompt-adjacent")
935
+ metadata = _load_json_object(metadata_path, "agent invocation metadata")
936
+ invocation = _invocation_job_fields(metadata, prompt_path, manifest)
937
+ expected = {
938
+ "invocationId": invocation["invocation_id"],
939
+ "invocationRef": invocation["invocation_ref"],
940
+ "participantRef": invocation["participant_ref"],
941
+ "roleExecutionRef": invocation["role_execution_ref"],
942
+ "dutyId": invocation["duty_id"],
943
+ "attempt": invocation["attempt"],
944
+ }
945
+ if any(reservation.get(key) != value for key, value in expected.items()):
946
+ raise DispatchError("translator reservation and invocation metadata differ")
947
+ if (
948
+ invocation["audience"] != "translator"
949
+ or invocation["assignment_ref"] != "translator"
950
+ or metadata.get("dispatchKind") != "translator"
951
+ ):
952
+ raise DispatchError("translator invocation identity is invalid")
953
+ result_path, worker_result_path = _translator_prompt_outputs(
954
+ project_root, prompt_path
955
+ )
956
+ if result_path == worker_result_path:
957
+ raise DispatchError(
958
+ "translator result and standard worker result paths must differ"
959
+ )
960
+ provider = _require_string(execution, "provider")
961
+ binding = execution.get("binding")
962
+ if not isinstance(binding, Mapping):
963
+ raise DispatchError("translator role execution has no binding")
964
+ return WorkerJob(
965
+ worker_id="translator",
966
+ provider=provider,
967
+ backend=options.default_backend,
968
+ project_root=project_root,
969
+ model_execution_value=_require_string(binding, "resolvedExecutionValue"),
970
+ wrapper_path=_resolve_wrapper(provider, workspace_root, options),
971
+ prompt_path=prompt_path,
972
+ result_path=result_path,
973
+ worker_result_path=worker_result_path,
974
+ completion_paths=(result_path, worker_result_path),
975
+ worktree_path=_worktree_path(manifest, active_context),
976
+ role="translator",
977
+ idle_timeout_seconds=options.idle_timeout_seconds,
978
+ dispatch_kind="translator",
979
+ **invocation,
980
+ )
981
+
982
+
983
+ def _translator_prompt_outputs(
984
+ project_root: Path, prompt_path: Path,
985
+ ) -> tuple[Path, Path]:
986
+ try:
987
+ lines = prompt_path.read_text(encoding="utf-8").splitlines()
988
+ except OSError as exc:
989
+ raise DispatchError(f"cannot read translator prompt: {exc}") from exc
990
+ values: list[str] = []
991
+ for header in ("Result Path", "Worker Result Path"):
992
+ prefix = f"**{header}:** "
993
+ matches = [line[len(prefix):].strip() for line in lines if line.startswith(prefix)]
994
+ if len(matches) != 1 or not matches[0]:
995
+ raise DispatchError(
996
+ f"translator prompt requires exactly one non-empty {prefix.strip()} header"
997
+ )
998
+ values.append(matches[0])
999
+ return (
1000
+ _resolve_project_path(project_root, values[0]),
1001
+ _resolve_project_path(project_root, values[1]),
1002
+ )
1003
+
1004
+
567
1005
  def _select_cli_wrapper_assignments(
568
1006
  recommended: Sequence[str],
569
1007
  requested_workers: Sequence[str],
@@ -642,7 +1080,7 @@ def _job_from_roster_worker(
642
1080
  ) -> WorkerJob:
643
1081
  result_path = _resolve_project_path(project_root, fact.result_path)
644
1082
  metadata = _agent_metadata(prompt_path)
645
- invocation = _invocation_job_fields(metadata, prompt_path)
1083
+ invocation = _invocation_job_fields(metadata, prompt_path, manifest)
646
1084
  return WorkerJob(
647
1085
  worker_id=fact.worker_id,
648
1086
  provider=fact.provider,
@@ -677,6 +1115,7 @@ def _agent_metadata(prompt_path: Path) -> Mapping[str, Any] | None:
677
1115
  def _invocation_job_fields(
678
1116
  metadata: Mapping[str, Any] | None,
679
1117
  prompt_path: Path,
1118
+ manifest: Mapping[str, Any],
680
1119
  ) -> dict[str, Any]:
681
1120
  if metadata is None:
682
1121
  return {}
@@ -687,7 +1126,7 @@ def _invocation_job_fields(
687
1126
  host_model_value = assignment.get("hostModelValue")
688
1127
  if host_model_value is not None and not isinstance(host_model_value, str):
689
1128
  raise DispatchError("agent invocation hostModelValue is invalid")
690
- return {
1129
+ fields = {
691
1130
  "invocation_id": _require_string(metadata, "invocationId"),
692
1131
  "audience": _require_string(metadata, "audience"),
693
1132
  "assignment_ref": _require_string(metadata, "assignmentRef"),
@@ -702,6 +1141,37 @@ def _invocation_job_fields(
702
1141
  "host_model_value": host_model_value,
703
1142
  "enforcement_mode": "core-pre-dispatch",
704
1143
  }
1144
+ schema = metadata.get("schemaVersion")
1145
+ identity_version = metadata.get("executionIdentityVersion")
1146
+ if schema == 1 and identity_version is None:
1147
+ return fields
1148
+ if schema != "2.0" or identity_version != 2:
1149
+ raise DispatchError("agent invocation metadata mixes v1 and v2 identity")
1150
+ participant_ref = _require_string(metadata, "participantRef")
1151
+ role_execution_ref = _require_string(metadata, "roleExecutionRef")
1152
+ role_executions = manifest.get("roleExecutions")
1153
+ execution = next((
1154
+ row for row in role_executions
1155
+ if isinstance(row, Mapping)
1156
+ and row.get("roleExecutionRef") == role_execution_ref
1157
+ ), None) if isinstance(role_executions, list) else None
1158
+ if execution is None or execution.get("participantRef") != participant_ref:
1159
+ raise DispatchError("agent invocation role execution does not match run manifest")
1160
+ execution_label = _require_string(metadata, "executionLabel")
1161
+ if execution.get("executionLabel") != execution_label:
1162
+ raise DispatchError("agent invocation execution label does not match run manifest")
1163
+ attempt = metadata.get("attempt")
1164
+ if not isinstance(attempt, int) or isinstance(attempt, bool) or attempt < 1:
1165
+ raise DispatchError("agent invocation v2 attempt must be positive")
1166
+ fields.update({
1167
+ "participant_ref": participant_ref,
1168
+ "role_execution_ref": role_execution_ref,
1169
+ "execution_label": execution_label,
1170
+ "duty_id": _require_string(metadata, "dutyId"),
1171
+ "invocation_ref": _require_string(metadata, "invocationRef"),
1172
+ "attempt": attempt,
1173
+ })
1174
+ return fields
705
1175
 
706
1176
 
707
1177
  def _materialize_roster_prompts(
@@ -775,34 +1245,50 @@ def _jobs_from_file(
775
1245
 
776
1246
 
777
1247
  def _spawn_job(plan: DispatchPlan, job: WorkerJob, attempt: int) -> WorkerHandle:
778
- _transition_worker_status(
779
- plan.team_state_path, job.worker_id, "in-progress", "",
780
- model_execution_value=job.model_execution_value,
1248
+ job = _prepare_job_attempt(plan, job, attempt)
1249
+ contract = _persisted_write_contract(plan, job)
1250
+ policies = (contract[0],) if contract else ()
1251
+ snapshot = None
1252
+ if contract is not None and contract[1].mutation_audit == "batch":
1253
+ snapshot_path = _mutation_snapshot_path(job)
1254
+ if snapshot_path.is_file():
1255
+ snapshot = MutationSnapshot.from_payload(
1256
+ _load_json_object(snapshot_path, "mutation audit snapshot")
1257
+ )
1258
+ else:
1259
+ snapshot = _mutation_snapshot(plan, policies, (job,))
1260
+ handle = replace(
1261
+ _start_job(plan, job),
1262
+ mutation_snapshot=snapshot,
1263
+ mutation_policies=policies,
1264
+ write_policy_digest=contract[0].digest if contract else "",
1265
+ write_enforcement=contract[1] if contract else None,
781
1266
  )
782
- handle = _start_job(plan, job)
783
1267
  _record_dispatch(plan.team_state_path, handle, attempt, "running", "")
784
1268
  _append_event(plan, "worker-dispatched", _attempt_details(job, attempt, handle))
785
1269
  if handle.completed_process is not None:
786
1270
  outcome = _outcome_from_completed(handle)
787
- _finish_attempt(plan, job, attempt, outcome)
1271
+ retry_allowed = _finish_attempt(
1272
+ plan,
1273
+ job,
1274
+ attempt,
1275
+ outcome,
1276
+ snapshot=snapshot,
1277
+ policies=policies,
1278
+ )
1279
+ handle = replace(handle, mutation_retry_allowed=retry_allowed)
788
1280
  return handle
789
1281
 
790
1282
 
791
1283
  def _spawn_cli_job_nonblocking(
792
1284
  plan: DispatchPlan, job: WorkerJob, attempt: int,
793
1285
  ) -> WorkerHandle:
794
- _transition_worker_status(
795
- plan.team_state_path, job.worker_id, "in-progress", "",
796
- model_execution_value=job.model_execution_value,
797
- )
798
1286
  process: subprocess.Popen[str] | None = None
799
1287
  try:
800
1288
  process = subprocess.Popen(job.command, cwd=plan.project_root, text=True)
801
1289
  handle = WorkerHandle(
802
1290
  job, "", None, status_path_for_prompt(job.prompt_path), "", process
803
1291
  )
804
- _record_dispatch(plan.team_state_path, handle, attempt, "running", "")
805
- _append_event(plan, "worker-dispatched", _attempt_details(job, attempt, handle))
806
1292
  return handle
807
1293
  except (OSError, DispatchError):
808
1294
  if process is not None and process.poll() is None:
@@ -811,15 +1297,217 @@ def _spawn_cli_job_nonblocking(
811
1297
  raise
812
1298
 
813
1299
 
1300
+ def _prepare_job_attempt(
1301
+ plan: DispatchPlan, job: WorkerJob, attempt: int
1302
+ ) -> WorkerJob:
1303
+ if job.has_execution_identity:
1304
+ _revalidate_job_role_execution(plan, job)
1305
+ job = _job_for_attempt(job, attempt)
1306
+ _record_execution_attempt(plan, job)
1307
+ _transition_job_status(
1308
+ plan,
1309
+ job,
1310
+ "in-progress",
1311
+ "",
1312
+ model_execution_value=job.model_execution_value,
1313
+ )
1314
+ return job
1315
+
1316
+
1317
+ def _persisted_write_contract(
1318
+ plan: DispatchPlan, job: WorkerJob
1319
+ ) -> tuple[WritePolicy, WriteEnforcement] | None:
1320
+ if not job.has_execution_identity:
1321
+ return None
1322
+ manifest = read_execution_manifest(plan.manifest_path)
1323
+ invocation = next(
1324
+ (
1325
+ row for row in manifest.invocations
1326
+ if row.invocation_ref == job.invocation_ref
1327
+ ),
1328
+ None,
1329
+ )
1330
+ if invocation is None:
1331
+ raise DispatchError("worker invocation write policy was not persisted")
1332
+ try:
1333
+ enforcement = write_enforcement_from_payload(
1334
+ invocation.write_enforcement
1335
+ )
1336
+ policy = replace(
1337
+ write_policy_from_payload(invocation.write_policy),
1338
+ maximum_boundary_precision=enforcement.boundary_precision,
1339
+ )
1340
+ except (TypeError, ValueError) as exc:
1341
+ raise DispatchError(f"persisted worker write policy is invalid: {exc}") from exc
1342
+ if policy.digest != invocation.write_policy_digest:
1343
+ raise DispatchError("persisted worker write policy digest changed")
1344
+ return policy, enforcement
1345
+
1346
+
1347
+ def _mutation_snapshot(
1348
+ plan: DispatchPlan,
1349
+ policies: Sequence[WritePolicy],
1350
+ jobs: Sequence[WorkerJob],
1351
+ ) -> MutationSnapshot:
1352
+ sidecars = tuple(_mutation_snapshot_path(job) for job in jobs)
1353
+ snapshot = ExecutionMutationAudit().snapshot(
1354
+ policies,
1355
+ orchestrator_paths=(
1356
+ plan.manifest_path,
1357
+ plan.team_state_path,
1358
+ Path(f"{plan.team_state_path}.lock"),
1359
+ plan.lead_events_path,
1360
+ plan.lead_events_path.with_name(
1361
+ f".{plan.lead_events_path.name}.lock"
1362
+ ),
1363
+ *sidecars,
1364
+ ),
1365
+ )
1366
+ for path in sidecars:
1367
+ write_json_atomic(path, snapshot.to_payload())
1368
+ return snapshot
1369
+
1370
+
1371
+ def _mutation_snapshot_path(job: WorkerJob) -> Path:
1372
+ return job.prompt_path.with_suffix(job.prompt_path.suffix + ".mutation-audit.json")
1373
+
1374
+
1375
+ def _record_execution_attempt(plan: DispatchPlan, job: WorkerJob) -> None:
1376
+ task_key = _require_string(plan.manifest, "taskKey")
1377
+ write_policy, write_enforcement = _canonical_write_contract(plan, job)
1378
+ record_invocation_attempt(
1379
+ plan.manifest_path,
1380
+ Invocation(
1381
+ invocation_ref=job.invocation_ref,
1382
+ participant_ref=job.participant_ref,
1383
+ role_execution_ref=job.role_execution_ref,
1384
+ source_invocation_ref=None,
1385
+ recovery_ref=None,
1386
+ duty_id=job.duty_id,
1387
+ dispatch_kind=job.dispatch_kind,
1388
+ round=_dispatch_round(job.dispatch_kind),
1389
+ input_digest=job.prompt_digest,
1390
+ write_policy=write_policy.to_payload(),
1391
+ write_policy_digest=write_policy.digest,
1392
+ write_enforcement=write_enforcement.to_payload(),
1393
+ ),
1394
+ Attempt(
1395
+ invocation_ref=job.invocation_ref,
1396
+ attempt=job.attempt,
1397
+ started_at=_utc_now(),
1398
+ finished_at=None,
1399
+ status="started",
1400
+ result_path=None,
1401
+ error_path=None,
1402
+ change_summary={},
1403
+ evidence_seal_ref=None,
1404
+ ),
1405
+ task_key=task_key,
1406
+ )
1407
+
1408
+
1409
+ def _canonical_write_contract(
1410
+ plan: DispatchPlan, job: WorkerJob
1411
+ ) -> tuple[WritePolicy, WriteEnforcement]:
1412
+ manifest = read_execution_manifest(plan.manifest_path)
1413
+ execution = next(
1414
+ (
1415
+ row for row in manifest.role_executions
1416
+ if row.role_execution_ref == job.role_execution_ref
1417
+ ),
1418
+ None,
1419
+ )
1420
+ if execution is None or execution.binding is None:
1421
+ raise DispatchError("worker write policy has no role execution binding")
1422
+ capability = execution.binding.worker_write_capability
1423
+ if capability is None:
1424
+ raise DispatchError("worker write policy has no runner write capability")
1425
+ artifacts = _worker_artifact_paths(plan, job)
1426
+ worktree = Path(job.worktree_path) if job.worktree_path else None
1427
+ try:
1428
+ return build_invocation_write_contract(
1429
+ role=execution.role,
1430
+ project_root=plan.project_root,
1431
+ worktree=worktree,
1432
+ artifact_paths=artifacts,
1433
+ maximum_precision=capability.max_boundary_precision,
1434
+ planned_paths=(
1435
+ planned_paths_from_run_manifest(plan.project_root, plan.manifest)
1436
+ if execution.role == "implementer"
1437
+ else ()
1438
+ ),
1439
+ auxiliary_roots=verifier_extra_dirs(execution.role),
1440
+ validated_auxiliary_roots=verifier_extra_dirs(execution.role),
1441
+ )
1442
+ except (OSError, ValueError) as exc:
1443
+ raise DispatchError(f"worker write policy is invalid: {exc}") from exc
1444
+
1445
+
1446
+ def _worker_artifact_paths(plan: DispatchPlan, job: WorkerJob) -> tuple[Path, ...]:
1447
+ active_context = _load_optional_json(
1448
+ plan.project_root, plan.manifest.get("activeRunContextPath")
1449
+ )
1450
+ paths = {
1451
+ job.result_path,
1452
+ job.worker_result_path,
1453
+ *job.completion_paths,
1454
+ Path(audit_sidecar_rel(str(job.worker_result_path))),
1455
+ status_path_for_prompt(job.prompt_path),
1456
+ job.prompt_path.with_suffix(job.prompt_path.suffix + ".log"),
1457
+ }
1458
+ error_logs = active_context.get("errorLogs")
1459
+ if isinstance(error_logs, Mapping):
1460
+ sidecars = error_logs.get("sidecarsByWorkerId")
1461
+ if isinstance(sidecars, Mapping):
1462
+ value = _string_value(sidecars.get(job.worker_id))
1463
+ if value:
1464
+ paths.add(_resolve_project_path(plan.project_root, value))
1465
+ return tuple(sorted(paths, key=str))
1466
+
1467
+
1468
+
1469
+
1470
+ def _job_for_attempt(job: WorkerJob, attempt: int) -> WorkerJob:
1471
+ if attempt == job.attempt:
1472
+ return job
1473
+ try:
1474
+ retry = materialize_retry_invocation(
1475
+ job.prompt_metadata_path,
1476
+ project_root=job.project_root,
1477
+ attempt=attempt,
1478
+ )
1479
+ except AgentInvocationError as exc:
1480
+ raise DispatchError(f"cannot materialize retry invocation: {exc}") from exc
1481
+ if retry.invocation_ref != job.invocation_ref:
1482
+ raise DispatchError("retry invocation reference changed")
1483
+ return replace(
1484
+ job,
1485
+ prompt_path=retry.prompt_path,
1486
+ prompt_metadata_path=retry.metadata_path,
1487
+ invocation_id=retry.invocation_id,
1488
+ attempt=retry.attempt,
1489
+ )
1490
+
1491
+
1492
+ def _dispatch_round(dispatch_kind: str) -> int:
1493
+ prefix = "reverify-r"
1494
+ if not dispatch_kind.startswith(prefix):
1495
+ return 1
1496
+ suffix = dispatch_kind[len(prefix):]
1497
+ if not suffix.isdigit() or int(suffix) < 1:
1498
+ raise DispatchError(f"invalid reverify dispatch kind: {dispatch_kind}")
1499
+ return int(suffix)
1500
+
1501
+
814
1502
  def _dispatch_job_with_retry(plan: DispatchPlan, job: WorkerJob) -> int:
815
1503
  for attempt in range(1, MAX_WORKER_ATTEMPTS + 1):
816
1504
  handle = _spawn_job(plan, job, attempt)
817
1505
  if handle.completed_process is None:
818
1506
  return await_dispatches(plan, timeout_seconds=None)
819
1507
  outcome = _outcome_from_completed(handle)
820
- if _worker_terminal_status(plan.team_state_path, job.worker_id) == "completed":
1508
+ if _job_terminal_status(plan, job, attempt) == "completed":
821
1509
  return 0
822
- if _should_retry(outcome, attempt):
1510
+ if _should_retry(outcome, attempt) and handle.mutation_retry_allowed:
823
1511
  _append_event(plan, "worker-retry-scheduled", _retry_details(job, attempt, outcome))
824
1512
  job = _job_for_next_attempt(job)
825
1513
  continue
@@ -845,7 +1533,11 @@ def _start_cmux_or_degrade(plan: DispatchPlan, job: WorkerJob) -> WorkerHandle:
845
1533
  workspace=workspace,
846
1534
  cwd=plan.project_root,
847
1535
  command=job.command,
848
- title=f"{job.worker_id}-worker",
1536
+ title=(
1537
+ job.execution_label
1538
+ if job.has_execution_identity
1539
+ else f"{job.worker_id}-worker"
1540
+ ),
849
1541
  owned_surface_ids=_opened_cmux_surfaces(plan.team_state_path),
850
1542
  )
851
1543
  except (RuntimeError, OSError, subprocess.SubprocessError):
@@ -964,16 +1656,17 @@ def _advance_running_dispatches(plan: DispatchPlan, records: Sequence[Mapping[st
964
1656
  if status is None or not status.is_terminal:
965
1657
  continue
966
1658
  outcome = _outcome_from_status(record, status)
967
- if _should_retry(outcome, int(record.get("attempt", 1))):
1659
+ retry_allowed = _finish_record(plan, record, outcome)
1660
+ if (
1661
+ _should_retry(outcome, int(record.get("attempt", 1)))
1662
+ and retry_allowed
1663
+ ):
968
1664
  _retry_from_record(plan, record, outcome)
969
- continue
970
- _finish_record(plan, record, outcome)
971
1665
 
972
1666
 
973
1667
  def _retry_from_record(
974
1668
  plan: DispatchPlan, record: Mapping[str, Any], outcome: WorkerOutcome
975
1669
  ) -> None:
976
- worker_id = _require_string(record, "workerId")
977
1670
  attempt = int(record.get("attempt", 1))
978
1671
  job = _job_from_record(plan.project_root, record)
979
1672
  reason = "required worker artifact was not produced"
@@ -981,7 +1674,7 @@ def _retry_from_record(
981
1674
  # `team-contract` counts the first attempt's failure as a recorded
982
1675
  # `cli-failure`; a retry that succeeds settles `completed` and would
983
1676
  # otherwise leave no trace that anything had to be re-run.
984
- details: dict[str, Any] = {"workerId": worker_id, "attempt": attempt}
1677
+ details = _event_execution_identity(job, attempt)
985
1678
  details["errorLogAppend"] = _record_wrapper_failure(
986
1679
  plan, job, attempt, outcome, reason
987
1680
  )
@@ -991,14 +1684,37 @@ def _retry_from_record(
991
1684
  _spawn_job(plan, _job_for_next_attempt(job), attempt + 1)
992
1685
 
993
1686
 
994
- def _finish_attempt(plan: DispatchPlan, job: WorkerJob, attempt: int, outcome: WorkerOutcome) -> None:
1687
+ def _finish_attempt(
1688
+ plan: DispatchPlan,
1689
+ job: WorkerJob,
1690
+ attempt: int,
1691
+ outcome: WorkerOutcome,
1692
+ *,
1693
+ snapshot: MutationSnapshot | None = None,
1694
+ policies: Sequence[WritePolicy] = (),
1695
+ ) -> bool:
1696
+ mutation = _audit_attempt(job, outcome, snapshot, policies)
1697
+ if mutation is not None and mutation.status in {
1698
+ "contract-failed-unattributed",
1699
+ "mutation-present-unresolved",
1700
+ }:
1701
+ reason = "; ".join(mutation.violations) or mutation.status
1702
+ _transition_job_status(plan, job, "error", reason)
1703
+ _update_dispatch_status(
1704
+ plan.team_state_path, job, attempt, "error", reason
1705
+ )
1706
+ details = _failure_details(job, attempt, outcome, reason)
1707
+ details["mutationAudit"] = mutation.change_summary()
1708
+ _append_event(plan, "worker-failed", details)
1709
+ _finish_manifest_attempt(plan, job, attempt, mutation, None)
1710
+ return False
995
1711
  settlement = _settle(plan, job, attempt, outcome)
996
1712
  if settlement.completed:
997
1713
  result_link = _link_result(plan, job, attempt)
998
1714
  post_process = _post_process_report_writer_result(plan, job)
999
1715
  if not post_process["ok"]:
1000
1716
  reason = _require_string(post_process, "reason")
1001
- _transition_worker_status(plan.team_state_path, job.worker_id, "error", reason)
1717
+ _transition_job_status(plan, job, "error", reason)
1002
1718
  _update_dispatch_status(
1003
1719
  plan.team_state_path,
1004
1720
  job,
@@ -1015,10 +1731,9 @@ def _finish_attempt(plan: DispatchPlan, job: WorkerJob, attempt: int, outcome: W
1015
1731
  )
1016
1732
  details["postProcessing"] = post_process["steps"]
1017
1733
  _append_event(plan, "worker-failed", details)
1018
- return
1019
- _transition_worker_status(
1020
- plan.team_state_path, job.worker_id, "completed", ""
1021
- )
1734
+ _finish_manifest_attempt(plan, job, attempt, mutation, None)
1735
+ return False
1736
+ _transition_job_status(plan, job, "completed", "")
1022
1737
  _update_dispatch_status(
1023
1738
  plan.team_state_path,
1024
1739
  job,
@@ -1031,16 +1746,148 @@ def _finish_attempt(plan: DispatchPlan, job: WorkerJob, attempt: int, outcome: W
1031
1746
  details["resultLink"] = result_link
1032
1747
  if settlement.error_log_append is not None:
1033
1748
  details["errorLogAppend"] = settlement.error_log_append
1749
+ if mutation is not None:
1750
+ details["mutationAudit"] = mutation.change_summary()
1034
1751
  _append_event(plan, "worker-result-collected", details)
1035
- return
1752
+ _finish_manifest_attempt(
1753
+ plan, job, attempt, mutation, job.worker_result_path
1754
+ )
1755
+ return False
1036
1756
  reason = settlement.reason
1037
1757
  status = "timeout" if outcome.timeout else "error"
1038
- _transition_worker_status(plan.team_state_path, job.worker_id, status, reason)
1758
+ _transition_job_status(plan, job, status, reason)
1039
1759
  _update_dispatch_status(plan.team_state_path, job, attempt, status, reason)
1040
1760
  details = _failure_details(job, attempt, outcome, reason)
1041
1761
  if settlement.error_log_append is not None:
1042
1762
  details["errorLogAppend"] = settlement.error_log_append
1763
+ if mutation is not None:
1764
+ details["mutationAudit"] = mutation.change_summary()
1043
1765
  _append_event(plan, "worker-failed", details)
1766
+ _finish_manifest_attempt(plan, job, attempt, mutation, None)
1767
+ return mutation.retry_allowed if mutation is not None else True
1768
+
1769
+
1770
+ def _audit_attempt(
1771
+ job: WorkerJob,
1772
+ outcome: WorkerOutcome,
1773
+ snapshot: MutationSnapshot | None,
1774
+ policies: Sequence[WritePolicy],
1775
+ ) -> MutationAuditResult | None:
1776
+ if not job.has_execution_identity or not policies:
1777
+ return None
1778
+ succeeded = outcome.returncode == 0 and not outcome.timeout
1779
+ result_present = not outcome.missing_completion_paths
1780
+ if snapshot is None:
1781
+ status = "ok" if succeeded and result_present else "failed-no-mutation"
1782
+ return MutationAuditResult(
1783
+ status=status,
1784
+ changed_paths=(),
1785
+ source_changed=False,
1786
+ git_changed=False,
1787
+ attribution="call",
1788
+ retry_allowed=status == "failed-no-mutation",
1789
+ violations=(),
1790
+ before_digest="",
1791
+ after_digest="",
1792
+ git_projection={},
1793
+ )
1794
+ return ExecutionMutationAudit().compare(
1795
+ snapshot,
1796
+ policies,
1797
+ out_of_plan_edits=_out_of_plan_edit_paths(job.result_path),
1798
+ attempt_succeeded=succeeded,
1799
+ result_present=result_present,
1800
+ )
1801
+
1802
+
1803
+ def _out_of_plan_edit_paths(result_path: Path) -> tuple[str, ...]:
1804
+ if not result_path.is_file() or result_path.suffix != ".json":
1805
+ return ()
1806
+ try:
1807
+ payload = json.loads(result_path.read_text(encoding="utf-8"))
1808
+ except (OSError, UnicodeError, json.JSONDecodeError):
1809
+ return ()
1810
+ implementation = payload.get("implementation") if isinstance(payload, Mapping) else None
1811
+ rows = implementation.get("outOfPlanEdits") if isinstance(implementation, Mapping) else None
1812
+ if not isinstance(rows, list):
1813
+ return ()
1814
+ return tuple(
1815
+ str(row["file"])
1816
+ for row in rows
1817
+ if isinstance(row, Mapping)
1818
+ and isinstance(row.get("file"), str)
1819
+ and row["file"]
1820
+ )
1821
+
1822
+
1823
+ def _finish_manifest_attempt(
1824
+ plan: DispatchPlan,
1825
+ job: WorkerJob,
1826
+ attempt: int,
1827
+ mutation: MutationAuditResult | None,
1828
+ result_path: Path | None,
1829
+ ) -> None:
1830
+ if mutation is None:
1831
+ return
1832
+ manifest = read_execution_manifest(plan.manifest_path)
1833
+ existing = next(
1834
+ (
1835
+ row for row in manifest.attempts
1836
+ if row.invocation_ref == job.invocation_ref
1837
+ and row.attempt == attempt
1838
+ ),
1839
+ None,
1840
+ )
1841
+ expected_result = str(result_path) if result_path is not None else None
1842
+ if existing is not None and existing.finished_at is not None:
1843
+ if (
1844
+ existing.status == mutation.status
1845
+ and existing.result_path == expected_result
1846
+ and dict(existing.change_summary) == mutation.change_summary()
1847
+ ):
1848
+ return
1849
+ raise DispatchError("attempt terminal mutation result drift")
1850
+ finish_attempt_mutation(
1851
+ plan.manifest_path,
1852
+ invocation_ref=job.invocation_ref,
1853
+ attempt=attempt,
1854
+ finished_at=_utc_now(),
1855
+ status=mutation.status,
1856
+ result_path=expected_result,
1857
+ error_path=None,
1858
+ change_summary=mutation.change_summary(),
1859
+ task_key=_require_string(plan.manifest, "taskKey"),
1860
+ )
1861
+ _seal_finished_attempt(plan, job, attempt, mutation)
1862
+
1863
+
1864
+ def _seal_finished_attempt(plan, job, attempt, mutation) -> None:
1865
+ from .attempt_evidence import TerminalObservation, finalize_attempt
1866
+
1867
+ events = job.prompt_path.with_name(job.prompt_path.name + ".host-events.jsonl")
1868
+ if not events.is_file() or not job.has_execution_identity:
1869
+ return
1870
+ artifacts = tuple(
1871
+ path for path in (job.result_path, job.worker_result_path) if path
1872
+ )
1873
+ try:
1874
+ finalize_attempt(
1875
+ plan.manifest_path,
1876
+ _build_dispatch_id(job.invocation_ref, attempt),
1877
+ TerminalObservation(
1878
+ status=mutation.status,
1879
+ source_diff_digest=mutation.change_summary().get("beforeDigest", ""),
1880
+ git_projection_digest=mutation.change_summary().get("afterDigest", ""),
1881
+ changed_paths=tuple(mutation.changed_paths),
1882
+ artifact_paths=artifacts,
1883
+ host_event_stream_path=events,
1884
+ project_root=plan.project_root,
1885
+ worktree=Path(job.worktree_path) if job.worktree_path else None,
1886
+ ),
1887
+ task_key=_require_string(plan.manifest, "taskKey"),
1888
+ )
1889
+ except (OSError, ValueError):
1890
+ return
1044
1891
 
1045
1892
 
1046
1893
  def _link_result(
@@ -1080,9 +1927,34 @@ def _link_result(
1080
1927
  return link
1081
1928
 
1082
1929
 
1083
- def _finish_record(plan: DispatchPlan, record: Mapping[str, Any], outcome: WorkerOutcome) -> None:
1930
+ def _finish_record(
1931
+ plan: DispatchPlan,
1932
+ record: Mapping[str, Any],
1933
+ outcome: WorkerOutcome,
1934
+ ) -> bool:
1084
1935
  job = _job_from_record(plan.project_root, record)
1085
- _finish_attempt(plan, job, int(record.get("attempt", 1)), outcome)
1936
+ snapshot = _snapshot_from_record(record)
1937
+ contract = _persisted_write_contract(plan, job)
1938
+ policies = (contract[0],) if contract is not None else ()
1939
+ return _finish_attempt(
1940
+ plan,
1941
+ job,
1942
+ int(record.get("attempt", 1)),
1943
+ outcome,
1944
+ snapshot=snapshot,
1945
+ policies=policies,
1946
+ )
1947
+
1948
+
1949
+ def _snapshot_from_record(record: Mapping[str, Any]) -> MutationSnapshot | None:
1950
+ value = _string_value(record.get("mutationAuditSnapshotPath"))
1951
+ if not value:
1952
+ return None
1953
+ payload = _load_json_object(Path(value), "mutation audit snapshot")
1954
+ try:
1955
+ return MutationSnapshot.from_payload(payload)
1956
+ except (KeyError, TypeError, ValueError) as exc:
1957
+ raise DispatchError("mutation audit snapshot is invalid") from exc
1086
1958
 
1087
1959
 
1088
1960
  @dataclass(frozen=True)
@@ -1120,7 +1992,11 @@ def _settle(
1120
1992
  reason = _failure_reason(outcome)
1121
1993
  completed = False
1122
1994
  note = ""
1123
- if not outcome.timeout and not outcome.missing_completion_paths:
1995
+ if (
1996
+ outcome.returncode != SERVED_MODEL_MISMATCH_EXIT_CODE
1997
+ and not outcome.timeout
1998
+ and not outcome.missing_completion_paths
1999
+ ):
1124
2000
  audit_failures = _audit_sidecar_failures(job)
1125
2001
  if audit_failures:
1126
2002
  reason = (
@@ -1214,6 +2090,11 @@ def _record_wrapper_failure(
1214
2090
  message=f"attempt {attempt}: {message}",
1215
2091
  stderr_excerpt=_wrapper_log_tail(job),
1216
2092
  context=None,
2093
+ identity=(
2094
+ _job_stored_identity(job, attempt)
2095
+ if job.has_execution_identity
2096
+ else None
2097
+ ),
1217
2098
  )
1218
2099
  except (OSError, ValueError, TypeError, WorkerPromptHeaderError) as exc:
1219
2100
  result["reason"] = f"{type(exc).__name__}: {exc}"
@@ -1222,6 +2103,17 @@ def _record_wrapper_failure(
1222
2103
  return result
1223
2104
 
1224
2105
 
2106
+ def _job_stored_identity(job: WorkerJob, attempt: int) -> dict[str, Any]:
2107
+ """Copy the job's stored execution refs. Do not infer them from labels."""
2108
+ return {
2109
+ "participantRef": job.participant_ref,
2110
+ "roleExecutionRef": job.role_execution_ref,
2111
+ "invocationRef": job.invocation_ref,
2112
+ "attempt": job.attempt or attempt,
2113
+ "executionLabel": job.execution_label,
2114
+ }
2115
+
2116
+
1225
2117
  def _error_log_agent(worker_id: str) -> str:
1226
2118
  """The error log's `--agent` enum value for a worker id.
1227
2119
 
@@ -1300,9 +2192,87 @@ def _post_process_report_writer_result(
1300
2192
  return {"ok": False, "reason": str(exc), "steps": []}
1301
2193
 
1302
2194
 
1303
- def _worker_terminal_status(team_state_path: Path, worker_id: str) -> str:
1304
- team_state = _load_json_object(team_state_path, "team-state")
1305
- return _string_value(_worker_state(team_state, worker_id).get("status"))
2195
+ def _projectionless_translator(plan: DispatchPlan, job: WorkerJob) -> bool:
2196
+ if not (
2197
+ job.has_execution_identity
2198
+ and job.role == "translator"
2199
+ and job.worker_id == "translator"
2200
+ and job.audience == "translator"
2201
+ and job.assignment_ref == "translator"
2202
+ and job.duty_id == "translator"
2203
+ and job.dispatch_kind == "translator"
2204
+ ):
2205
+ return False
2206
+ execution = _canonical_translator_execution(plan.manifest)
2207
+ return bool(
2208
+ execution
2209
+ and execution.get("roleExecutionRef") == job.role_execution_ref
2210
+ and execution.get("participantRef") == job.participant_ref
2211
+ and execution.get("executionLabel") == job.execution_label
2212
+ and execution.get("provider") == job.provider
2213
+ )
2214
+
2215
+
2216
+ def _transition_job_status(
2217
+ plan: DispatchPlan,
2218
+ job: WorkerJob,
2219
+ status: str,
2220
+ reason: str,
2221
+ *,
2222
+ model_execution_value: str = "",
2223
+ ) -> None:
2224
+ if not _projectionless_translator(plan, job):
2225
+ _transition_worker_status(
2226
+ plan.team_state_path,
2227
+ job.worker_id,
2228
+ status,
2229
+ reason,
2230
+ model_execution_value=model_execution_value,
2231
+ )
2232
+ return
2233
+ team_state = _load_json_object(plan.team_state_path, "team-state")
2234
+ workers = team_state.get("workers")
2235
+ if not isinstance(workers, list):
2236
+ raise DispatchError("team-state workers must be an array")
2237
+ if not any(
2238
+ isinstance(row, Mapping) and row.get("workerId") == job.worker_id
2239
+ for row in workers
2240
+ ):
2241
+ return
2242
+ _transition_worker_status(
2243
+ plan.team_state_path,
2244
+ job.worker_id,
2245
+ status,
2246
+ reason,
2247
+ model_execution_value=model_execution_value,
2248
+ )
2249
+
2250
+
2251
+ def _job_terminal_status(
2252
+ plan: DispatchPlan, job: WorkerJob, attempt: int,
2253
+ ) -> str:
2254
+ team_state = _load_json_object(plan.team_state_path, "team-state")
2255
+ workers = team_state.get("workers")
2256
+ if not isinstance(workers, list):
2257
+ raise DispatchError("team-state workers must be an array")
2258
+ matches = [
2259
+ row for row in workers
2260
+ if isinstance(row, Mapping) and row.get("workerId") == job.worker_id
2261
+ ]
2262
+ if len(matches) == 1:
2263
+ return _string_value(matches[0].get("status"))
2264
+ if matches or not _projectionless_translator(plan, job):
2265
+ raise DispatchError(f"team-state has no unique workerId={job.worker_id}")
2266
+ dispatches = team_state.get("workerDispatches")
2267
+ records = [
2268
+ row for row in dispatches
2269
+ if isinstance(row, Mapping)
2270
+ and row.get("promptPath") == str(job.prompt_path)
2271
+ and row.get("attempt") == attempt
2272
+ ] if isinstance(dispatches, list) else []
2273
+ if len(records) != 1:
2274
+ raise DispatchError("translator dispatch has no unique status record")
2275
+ return _string_value(records[0].get("status"))
1306
2276
 
1307
2277
 
1308
2278
  def _record_dispatch(
@@ -1317,15 +2287,31 @@ def _record_dispatch(
1317
2287
  handle.pane_id,
1318
2288
  handle.degraded_from,
1319
2289
  reason,
2290
+ mutation_snapshot_path=(
2291
+ _mutation_snapshot_path(handle.job)
2292
+ if handle.mutation_snapshot is not None
2293
+ else None
2294
+ ),
2295
+ write_policy_digest=handle.write_policy_digest,
2296
+ write_enforcement=handle.write_enforcement,
1320
2297
  ),
1321
2298
  )
1322
2299
 
1323
2300
 
1324
2301
  def _dispatch_record(
1325
- job: WorkerJob, attempt: int, status: str, pane_id: str, degraded_from: str, reason: str = ""
2302
+ job: WorkerJob,
2303
+ attempt: int,
2304
+ status: str,
2305
+ pane_id: str,
2306
+ degraded_from: str,
2307
+ reason: str = "",
2308
+ *,
2309
+ mutation_snapshot_path: Path | None = None,
2310
+ write_policy_digest: str = "",
2311
+ write_enforcement: WriteEnforcement | None = None,
1326
2312
  ) -> dict[str, Any]:
2313
+ has_execution_identity = job.has_execution_identity
1327
2314
  record = {
1328
- "workerId": job.worker_id,
1329
2315
  "role": job.role,
1330
2316
  "kind": job.dispatch_kind,
1331
2317
  "attempt": attempt,
@@ -1363,6 +2349,27 @@ def _dispatch_record(
1363
2349
  "hostModelValue": job.host_model_value,
1364
2350
  "enforcementMode": job.enforcement_mode,
1365
2351
  })
2352
+ if has_execution_identity:
2353
+ record.update({
2354
+ "schemaVersion": "2.0",
2355
+ "executionIdentityVersion": 2,
2356
+ "participantRef": job.participant_ref,
2357
+ "roleExecutionRef": job.role_execution_ref,
2358
+ "executionLabel": job.execution_label,
2359
+ "dutyId": job.duty_id,
2360
+ "invocationRef": job.invocation_ref,
2361
+ "writePolicyDigest": write_policy_digest,
2362
+ "writeEnforcement": (
2363
+ write_enforcement.to_payload()
2364
+ if write_enforcement is not None
2365
+ else None
2366
+ ),
2367
+ "mutationAuditSnapshotPath": (
2368
+ str(mutation_snapshot_path) if mutation_snapshot_path else ""
2369
+ ),
2370
+ })
2371
+ else:
2372
+ record["workerId"] = job.worker_id
1366
2373
  return record
1367
2374
 
1368
2375
 
@@ -1500,7 +2507,9 @@ def _relay_to_sidebar(plan: DispatchPlan, event_type: str, details: Mapping[str,
1500
2507
  if plan.default_backend != BACKEND_CMUX_PANE:
1501
2508
  return
1502
2509
  workspace = cmux.resolve_lead_workspace()
1503
- worker_id = str(details.get("workerId", "") or "worker")
2510
+ worker_id = str(
2511
+ details.get("executionLabel") or details.get("workerId") or "worker"
2512
+ )
1504
2513
  cmux.sidebar_log(
1505
2514
  workspace,
1506
2515
  f"{worker_id}: {event_type.removeprefix('worker-')}",
@@ -1531,13 +2540,16 @@ def _append_event(plan: DispatchPlan, event_type: str, details: Mapping[str, Any
1531
2540
 
1532
2541
 
1533
2542
  def _attempt_details(job: WorkerJob, attempt: int, handle: WorkerHandle) -> dict[str, Any]:
1534
- return {**_event_details(job, handle), "attempt": attempt, "maxAttempts": MAX_WORKER_ATTEMPTS}
2543
+ return {
2544
+ **_event_details(job, handle),
2545
+ **_event_execution_identity(job, attempt),
2546
+ "maxAttempts": MAX_WORKER_ATTEMPTS,
2547
+ }
1535
2548
 
1536
2549
 
1537
2550
  def _event_details(job: WorkerJob, handle: WorkerHandle) -> dict[str, Any]:
1538
- return {
2551
+ details = {
1539
2552
  "dispatchMode": BACKEND_CLI_WRAPPER if handle.degraded_from else job.backend,
1540
- "workerId": job.worker_id,
1541
2553
  "promptPath": str(job.prompt_path),
1542
2554
  "resultPath": str(job.result_path),
1543
2555
  "workerResultPath": str(job.worker_result_path),
@@ -1546,12 +2558,25 @@ def _event_details(job: WorkerJob, handle: WorkerHandle) -> dict[str, Any]:
1546
2558
  "paneId": handle.pane_id,
1547
2559
  "degradedFrom": handle.degraded_from,
1548
2560
  }
2561
+ return details
2562
+
2563
+
2564
+ def _event_execution_identity(job: WorkerJob, attempt: int) -> dict[str, Any]:
2565
+ if job.has_execution_identity:
2566
+ return {
2567
+ "participantRef": job.participant_ref,
2568
+ "roleExecutionRef": job.role_execution_ref,
2569
+ "executionLabel": job.execution_label,
2570
+ "dutyId": job.duty_id,
2571
+ "invocationRef": job.invocation_ref,
2572
+ "attempt": attempt,
2573
+ }
2574
+ return {"workerId": job.worker_id, "attempt": attempt}
1549
2575
 
1550
2576
 
1551
2577
  def _result_details(job: WorkerJob, attempt: int, outcome: WorkerOutcome) -> dict[str, Any]:
1552
2578
  return {
1553
- "workerId": job.worker_id,
1554
- "attempt": attempt,
2579
+ **_event_execution_identity(job, attempt),
1555
2580
  "dispatchMode": BACKEND_CLI_WRAPPER if outcome.degraded_from else job.backend,
1556
2581
  "missingCompletionPaths": [],
1557
2582
  # A collected result can still come from a wrapper that exited non-zero
@@ -1570,8 +2595,7 @@ def _failure_details(
1570
2595
  exit_code: int | None = None,
1571
2596
  ) -> dict[str, Any]:
1572
2597
  return {
1573
- "workerId": job.worker_id,
1574
- "attempt": attempt,
2598
+ **_event_execution_identity(job, attempt),
1575
2599
  "maxAttempts": MAX_WORKER_ATTEMPTS,
1576
2600
  "dispatchMode": BACKEND_CLI_WRAPPER if outcome.degraded_from else job.backend,
1577
2601
  "exitCode": outcome.returncode if exit_code is None else exit_code,
@@ -1587,8 +2611,7 @@ def _failure_details(
1587
2611
 
1588
2612
  def _retry_details(job: WorkerJob, attempt: int, outcome: WorkerOutcome) -> dict[str, Any]:
1589
2613
  return {
1590
- "workerId": job.worker_id,
1591
- "attempt": attempt,
2614
+ **_event_execution_identity(job, attempt),
1592
2615
  "missingCompletionPaths": [str(path) for path in outcome.missing_completion_paths],
1593
2616
  "reason": "required worker artifact was not produced",
1594
2617
  }
@@ -1607,8 +2630,13 @@ def _outcome_from_status(record: Mapping[str, Any], status) -> WorkerOutcome:
1607
2630
 
1608
2631
 
1609
2632
  def _job_from_record(project_root: Path, record: Mapping[str, Any]) -> WorkerJob:
2633
+ identity = _worker_execution_identity(record)
1610
2634
  return WorkerJob(
1611
- worker_id=_require_string(record, "workerId"),
2635
+ worker_id=(
2636
+ _require_string(record, "workerId")
2637
+ if identity is None
2638
+ else _v2_worker_state_key(record)
2639
+ ),
1612
2640
  provider=_require_string(record, "provider"),
1613
2641
  backend=BACKEND_CLI_WRAPPER,
1614
2642
  project_root=project_root,
@@ -1643,6 +2671,7 @@ def _job_from_record(project_root: Path, record: Mapping[str, Any]) -> WorkerJob
1643
2671
  else None
1644
2672
  ),
1645
2673
  enforcement_mode=_string_value(record.get("enforcementMode")),
2674
+ **(identity or {}),
1646
2675
  )
1647
2676
 
1648
2677