sneakoscope 4.8.6 → 5.1.2

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 (390) hide show
  1. package/README.md +51 -726
  2. package/bench/tasks/t01-off-by-one/repo/package.json +9 -0
  3. package/bench/tasks/t01-off-by-one/repo/src/pagination.js +5 -0
  4. package/bench/tasks/t01-off-by-one/repo/test.js +5 -0
  5. package/bench/tasks/t01-off-by-one/task.json +13 -0
  6. package/bench/tasks/t02-signature-cochange/repo/package.json +9 -0
  7. package/bench/tasks/t02-signature-cochange/repo/src/admin.js +5 -0
  8. package/bench/tasks/t02-signature-cochange/repo/src/audit.js +5 -0
  9. package/bench/tasks/t02-signature-cochange/repo/src/labels.js +3 -0
  10. package/bench/tasks/t02-signature-cochange/repo/src/profile.js +5 -0
  11. package/bench/tasks/t02-signature-cochange/repo/test.js +9 -0
  12. package/bench/tasks/t02-signature-cochange/task.json +12 -0
  13. package/bench/tasks/t03-type-puzzle/repo/package.json +9 -0
  14. package/bench/tasks/t03-type-puzzle/repo/src/config.js +4 -0
  15. package/bench/tasks/t03-type-puzzle/repo/test.js +6 -0
  16. package/bench/tasks/t03-type-puzzle/task.json +13 -0
  17. package/bench/tasks/t04-refactor-preserve/repo/package.json +9 -0
  18. package/bench/tasks/t04-refactor-preserve/repo/src/cart.js +8 -0
  19. package/bench/tasks/t04-refactor-preserve/repo/test.js +4 -0
  20. package/bench/tasks/t04-refactor-preserve/task.json +12 -0
  21. package/bench/tasks/t05-performance/repo/package.json +9 -0
  22. package/bench/tasks/t05-performance/repo/src/pairs.js +9 -0
  23. package/bench/tasks/t05-performance/repo/test.js +11 -0
  24. package/bench/tasks/t05-performance/task.json +12 -0
  25. package/bench/tasks/t06-mistake-rule/repo/package.json +9 -0
  26. package/bench/tasks/t06-mistake-rule/repo/src/loader.js +6 -0
  27. package/bench/tasks/t06-mistake-rule/repo/test.js +7 -0
  28. package/bench/tasks/t06-mistake-rule/task.json +12 -0
  29. package/config/bench-baseline.json +7 -0
  30. package/crates/sks-core/Cargo.lock +1 -1
  31. package/crates/sks-core/Cargo.toml +1 -1
  32. package/crates/sks-core/src/main.rs +1 -1
  33. package/dist/bin/install.js +35 -0
  34. package/dist/bin/sks.js +1 -1
  35. package/dist/cli/cli-theme.js +51 -0
  36. package/dist/cli/command-registry.js +75 -42
  37. package/dist/cli/help-fast.js +18 -8
  38. package/dist/cli/insane-search-command.js +36 -8
  39. package/dist/cli/install-helpers.js +147 -47
  40. package/dist/cli/router.js +58 -2
  41. package/dist/commands/codex-lb.js +6 -4
  42. package/dist/commands/doctor.js +146 -8
  43. package/dist/commands/proof.js +6 -3
  44. package/dist/commands/zellij-monitor-pane.js +25 -0
  45. package/dist/commands/zellij-slot-pane.js +39 -2
  46. package/dist/commands/zellij-viewport-pane.js +56 -0
  47. package/dist/commands/zellij.js +55 -2
  48. package/dist/config/skills-manifest.json +493 -0
  49. package/dist/core/agents/agent-conflict-graph.js +5 -0
  50. package/dist/core/agents/agent-lease.js +5 -0
  51. package/dist/core/agents/agent-ledger-schemas.js +1 -0
  52. package/dist/core/agents/agent-lifecycle.js +86 -35
  53. package/dist/core/agents/agent-orchestrator.js +287 -72
  54. package/dist/core/agents/agent-output-validator.js +14 -3
  55. package/dist/core/agents/agent-patch-queue-store.js +108 -4
  56. package/dist/core/agents/agent-patch-queue.js +10 -3
  57. package/dist/core/agents/agent-patch-schema.js +13 -0
  58. package/dist/core/agents/agent-proof-evidence.js +6 -1
  59. package/dist/core/agents/agent-runner-fake.js +40 -0
  60. package/dist/core/agents/agent-scheduler.js +2 -3
  61. package/dist/core/agents/agent-worker-pipeline.js +36 -2
  62. package/dist/core/agents/codex-exec-worker-adapter.js +2 -0
  63. package/dist/core/agents/native-cli-session-swarm.js +30 -13
  64. package/dist/core/agents/native-cli-worker.js +2 -1
  65. package/dist/core/agents/native-worker-backend-router.js +58 -1
  66. package/dist/core/auto-review.js +25 -4
  67. package/dist/core/codex/agent-config-file-repair.js +15 -2
  68. package/dist/core/codex/codex-config-eperm-repair.js +8 -2
  69. package/dist/core/codex/codex-config-guard.js +289 -0
  70. package/dist/core/codex/codex-config-toml.js +122 -0
  71. package/dist/core/codex/codex-project-config-policy.js +59 -7
  72. package/dist/core/codex-app/sks-menubar.js +780 -122
  73. package/dist/core/codex-app.js +1 -0
  74. package/dist/core/codex-control/codex-fake-sdk-adapter.js +6 -4
  75. package/dist/core/codex-control/codex-sdk-config-policy.js +2 -1
  76. package/dist/core/codex-control/codex-sdk-env-policy.js +1 -1
  77. package/dist/core/codex-control/codex-task-runner.js +32 -14
  78. package/dist/core/codex-control/python-codex-sdk-adapter.js +4 -1
  79. package/dist/core/codex-control/schemas/agent-worker-result.schema.js +12 -3
  80. package/dist/core/codex-hooks/codex-hook-managed-install.js +5 -0
  81. package/dist/core/codex-hooks/codex-hook-state-writer.js +70 -11
  82. package/dist/core/codex-hooks/codex-hook-trust-doctor.js +2 -2
  83. package/dist/core/codex-lb/codex-lb-env.js +20 -1
  84. package/dist/core/codex-lb/codex-lb-setup.js +2 -5
  85. package/dist/core/codex-native/skill-registry-ledger.js +24 -5
  86. package/dist/core/commands/basic-cli.js +21 -2
  87. package/dist/core/commands/check-command.js +37 -5
  88. package/dist/core/commands/command-utils.js +22 -2
  89. package/dist/core/commands/computer-use-command.js +62 -7
  90. package/dist/core/commands/db-command.js +31 -5
  91. package/dist/core/commands/fast-mode-command.js +39 -11
  92. package/dist/core/commands/gate-result-contract.js +43 -0
  93. package/dist/core/commands/gates-command.js +6 -1
  94. package/dist/core/commands/gc-command.js +29 -2
  95. package/dist/core/commands/goal-command.js +9 -2
  96. package/dist/core/commands/gx-command.js +79 -7
  97. package/dist/core/commands/image-ux-review-command.js +188 -13
  98. package/dist/core/commands/mad-db-command.js +85 -176
  99. package/dist/core/commands/mad-sks-command.js +248 -34
  100. package/dist/core/commands/menubar-command.js +146 -0
  101. package/dist/core/commands/naruto-command.js +64 -10
  102. package/dist/core/commands/pipeline-command.js +21 -2
  103. package/dist/core/commands/plan-command.js +76 -0
  104. package/dist/core/commands/ppt-command.js +159 -24
  105. package/dist/core/commands/qa-loop-command.js +6 -2
  106. package/dist/core/commands/release-command.js +55 -2
  107. package/dist/core/commands/research-command.js +1 -1
  108. package/dist/core/commands/review-command.js +217 -0
  109. package/dist/core/commands/route-command.js +62 -0
  110. package/dist/core/commands/route-success-helpers.js +59 -0
  111. package/dist/core/commands/run-command.js +19 -7
  112. package/dist/core/commands/seo-command.js +49 -1
  113. package/dist/core/commands/status-command.js +21 -1
  114. package/dist/core/commands/team-legacy-observe-command.js +221 -3
  115. package/dist/core/commands/ui-command.js +161 -0
  116. package/dist/core/commands/uninstall-command.js +312 -0
  117. package/dist/core/db-safety.js +7 -3
  118. package/dist/core/doctor/codex-startup-config-repair.js +14 -3
  119. package/dist/core/doctor/confirm-repair.js +27 -0
  120. package/dist/core/doctor/context7-mcp-repair.js +35 -7
  121. package/dist/core/doctor/doctor-codex-startup-repair.js +10 -3
  122. package/dist/core/doctor/doctor-context7-repair.js +17 -4
  123. package/dist/core/doctor/doctor-dirty-planner.js +27 -9
  124. package/dist/core/doctor/doctor-native-capability-repair.js +12 -2
  125. package/dist/core/doctor/doctor-readiness-matrix.js +27 -2
  126. package/dist/core/doctor/doctor-repair-postcheck.js +4 -0
  127. package/dist/core/doctor/doctor-transaction.js +21 -5
  128. package/dist/core/doctor/doctor-zellij-repair.js +1 -0
  129. package/dist/core/doctor/imagegen-repair.js +161 -0
  130. package/dist/core/doctor/supabase-mcp-repair.js +23 -5
  131. package/dist/core/feature-fixture-runner.js +2 -2
  132. package/dist/core/feature-fixtures.js +65 -37
  133. package/dist/core/feature-registry.js +106 -3
  134. package/dist/core/fsx.js +91 -2
  135. package/dist/core/hooks-runtime/skill-reconcile-preflight.js +43 -0
  136. package/dist/core/hooks-runtime.js +86 -46
  137. package/dist/core/image-ux-review/imagegen-adapter.js +48 -11
  138. package/dist/core/image-ux-review.js +16 -0
  139. package/dist/core/imagegen/imagegen-capability.js +11 -5
  140. package/dist/core/imagegen/require-imagegen.js +57 -0
  141. package/dist/core/init/skills.js +271 -14
  142. package/dist/core/init.js +13 -10
  143. package/dist/core/mad-db/mad-db-coordinator.js +96 -20
  144. package/dist/core/mad-db/mad-db-policy.js +12 -10
  145. package/dist/core/mad-sks/executors/executor-base.js +8 -2
  146. package/dist/core/mad-sks/executors/index.js +4 -0
  147. package/dist/core/mad-sks/executors/sql-plane-executor.js +194 -0
  148. package/dist/core/mission.js +138 -5
  149. package/dist/core/naruto/naruto-active-pool.js +84 -30
  150. package/dist/core/naruto/naruto-backpressure.js +5 -1
  151. package/dist/core/naruto/naruto-real-worker-child.js +10 -0
  152. package/dist/core/naruto/naruto-real-worker-runtime.js +9 -7
  153. package/dist/core/naruto/naruto-role-policy.js +3 -0
  154. package/dist/core/naruto/naruto-task-hints.js +10 -0
  155. package/dist/core/naruto/naruto-work-graph.js +8 -2
  156. package/dist/core/naruto/naruto-work-item.js +6 -0
  157. package/dist/core/naruto/resource-pressure-monitor.js +33 -15
  158. package/dist/core/naruto/solution-tournament.js +101 -0
  159. package/dist/core/permission-gates.js +30 -0
  160. package/dist/core/pipeline-internals/runtime-core.js +72 -222
  161. package/dist/core/pipeline-internals/runtime-gates.js +140 -24
  162. package/dist/core/ppt-review/index.js +6 -1
  163. package/dist/core/ppt-review/slide-imagegen-review.js +75 -10
  164. package/dist/core/ppt.js +70 -2
  165. package/dist/core/proof/auto-finalize.js +70 -11
  166. package/dist/core/proof/proof-schema.js +2 -0
  167. package/dist/core/proof/route-adapter.js +5 -1
  168. package/dist/core/proof/route-finalizer.js +8 -5
  169. package/dist/core/proof/selftest-proof-fixtures.js +18 -5
  170. package/dist/core/proof/validation.js +2 -0
  171. package/dist/core/provider/model-router.js +53 -0
  172. package/dist/core/questions.js +1 -1
  173. package/dist/core/recallpulse.js +1 -1
  174. package/dist/core/release/gate-manifest.js +2 -2
  175. package/dist/core/release/release-gate-affected-selector.js +3 -10
  176. package/dist/core/release/release-gate-batch-runner.js +4 -2
  177. package/dist/core/release/release-gate-cache-v2.js +27 -14
  178. package/dist/core/release/release-gate-dag.js +6 -1
  179. package/dist/core/release/release-gate-hermetic-env.js +10 -0
  180. package/dist/core/release/release-gate-node.js +3 -0
  181. package/dist/core/release/release-gate-resource-governor.js +1 -0
  182. package/dist/core/retention.js +89 -4
  183. package/dist/core/routes/constants.js +1 -1
  184. package/dist/core/routes/diagnostic-allowlist.js +55 -0
  185. package/dist/core/routes.js +83 -33
  186. package/dist/core/safety/mutation-guard.js +5 -1
  187. package/dist/core/skill-forge.js +9 -4
  188. package/dist/core/stop-gate/gate-evaluator.js +102 -0
  189. package/dist/core/stop-gate/stop-gate-check.js +26 -4
  190. package/dist/core/stop-gate/stop-gate-resolver.js +19 -3
  191. package/dist/core/stop-gate/stop-gate-writer.js +20 -1
  192. package/dist/core/team-dag.js +12 -465
  193. package/dist/core/team-dashboard-renderer.js +13 -94
  194. package/dist/core/team-live.js +68 -804
  195. package/dist/core/triwiki/agents-md-projector.js +184 -0
  196. package/dist/core/triwiki-wrongness/wrongness-schema.js +3 -1
  197. package/dist/core/trust-kernel/trust-kernel-schema.js +1 -0
  198. package/dist/core/trust-kernel/trust-report.js +1 -1
  199. package/dist/core/trust-kernel/trust-status.js +2 -0
  200. package/dist/core/ui/dashboard-html.js +111 -0
  201. package/dist/core/update/update-migration-state.js +383 -42
  202. package/dist/core/update-check.js +201 -78
  203. package/dist/core/verification/diff-quality.js +100 -0
  204. package/dist/core/verification/impact-scan.js +164 -0
  205. package/dist/core/verification/machine-feedback.js +146 -0
  206. package/dist/core/verification/mistake-rule-compiler.js +195 -0
  207. package/dist/core/version.js +1 -1
  208. package/dist/core/zellij/zellij-layout-builder.js +44 -16
  209. package/dist/core/zellij/zellij-monitor-renderer.js +53 -0
  210. package/dist/core/zellij/zellij-self-heal.js +27 -32
  211. package/dist/core/zellij/zellij-slot-pane-renderer.js +162 -153
  212. package/dist/core/zellij/zellij-slot-telemetry.js +2 -0
  213. package/dist/core/zellij/zellij-theme.js +67 -0
  214. package/dist/core/zellij/zellij-ui-mode.js +16 -0
  215. package/dist/core/zellij/zellij-viewport-binder.js +59 -0
  216. package/dist/core/zellij/zellij-worker-pane-manager.js +53 -5
  217. package/dist/scripts/agent-patch-swarm-gate-lib.js +2 -2
  218. package/dist/scripts/build-dist.js +8 -0
  219. package/dist/scripts/check-feature-quality.js +2 -2
  220. package/dist/scripts/cli-output-consistency-check.js +57 -0
  221. package/dist/scripts/codex-lb-fast-ui-preservation-check.js +106 -0
  222. package/dist/scripts/codex-lb-gpt55-fast-profile-check.js +105 -0
  223. package/dist/scripts/codex-lb-missing-env-regression.js +2 -3
  224. package/dist/scripts/codex-project-config-policy-merge-regression.js +3 -3
  225. package/dist/scripts/coding-bench-check.js +136 -0
  226. package/dist/scripts/concurrent-session-collision-check.js +67 -0
  227. package/dist/scripts/docs-truthfulness-check.js +1 -1
  228. package/dist/scripts/doctor-imagegen-repair-check.js +62 -0
  229. package/dist/scripts/ensure-bin-executable.js +11 -3
  230. package/dist/scripts/gate-policy-audit-check.js +130 -0
  231. package/dist/scripts/harness-benchmark-check.js +104 -0
  232. package/dist/scripts/hook-latency-budget-check.js +45 -0
  233. package/dist/scripts/legacy-update-e2e-check.js +228 -0
  234. package/dist/scripts/lib/codex-sdk-gate-lib.js +2 -2
  235. package/dist/scripts/lib/real-codex-parallel-gate.js +2 -2
  236. package/dist/scripts/loop-directive-check-lib.js +1 -1
  237. package/dist/scripts/mad-db-command-check.js +11 -8
  238. package/dist/scripts/mad-db-real-supabase-e2e.js +2 -2
  239. package/dist/scripts/mad-db-route-identity-check.js +8 -6
  240. package/dist/scripts/mad-db-safety-conflict-matrix-check.js +31 -8
  241. package/dist/scripts/mad-db-skill-policy-snapshot-check.js +4 -5
  242. package/dist/scripts/mad-sks-zellij-default-pane-worker-check.js +3 -2
  243. package/dist/scripts/mad-sks-zellij-launch-check.js +1 -1
  244. package/dist/scripts/naruto-zellij-dynamic-right-column-check.js +7 -7
  245. package/dist/scripts/parallel-claim-enforcement-check.js +14 -5
  246. package/dist/scripts/ppt-real-imagegen-wiring-check.js +5 -1
  247. package/dist/scripts/project-skill-dedupe-check.js +23 -5
  248. package/dist/scripts/proof-root-cause-policy-check.js +2 -0
  249. package/dist/scripts/release-affected-selector-check.js +2 -2
  250. package/dist/scripts/release-cache-glob-hashing-check.js +1 -0
  251. package/dist/scripts/release-dag-full-coverage-check.js +13 -4
  252. package/dist/scripts/release-gate-dag-runner-check.js +10 -2
  253. package/dist/scripts/release-gate-dag-runner.js +22 -0
  254. package/dist/scripts/release-gate-existence-audit.js +2 -1
  255. package/dist/scripts/release-gate-planner.js +2 -1
  256. package/dist/scripts/release-gate-script-parity-check.js +1 -1
  257. package/dist/scripts/release-metadata-1-19-check.js +2 -1
  258. package/dist/scripts/release-readiness-report.js +38 -7
  259. package/dist/scripts/release-stability-report-check.js +12 -8
  260. package/dist/scripts/search-visibility-gate-lib.js +2 -2
  261. package/dist/scripts/seo-geo-feature-fixture-quality-check.js +1 -1
  262. package/dist/scripts/skills-manifest-continuity-check.js +46 -0
  263. package/dist/scripts/sks-1-11-gate-lib.js +8 -6
  264. package/dist/scripts/sks-menubar-install-check.js +87 -21
  265. package/dist/scripts/sks-uninstall-regression-check.js +54 -0
  266. package/dist/scripts/uninstall-inventory-check.js +3 -0
  267. package/dist/scripts/ux-review-real-loop-fixture-check.js +9 -4
  268. package/dist/scripts/ux-review-run-wires-imagegen-check.js +4 -0
  269. package/dist/scripts/zellij-layout-valid-check.js +18 -11
  270. package/dist/scripts/zellij-right-column-geometry-proof.js +2 -4
  271. package/dist/scripts/zellij-slot-pane-renderer-check.js +9 -9
  272. package/dist/scripts/zellij-slot-pane-stale-detection-check.js +3 -4
  273. package/dist/scripts/zellij-slot-pane-telemetry-renderer-check.js +3 -2
  274. package/dist/scripts/zellij-slot-telemetry-renderer-check.js +4 -2
  275. package/dist/scripts/zellij-spawn-on-demand-layout-check.js +8 -2
  276. package/dist/scripts/zellij-viewport-binder-check.js +9 -0
  277. package/docs/assets/sneakoscope-architecture-pipeline.jpg +0 -0
  278. package/docs/demo.tape +28 -0
  279. package/package.json +70 -3
  280. package/schemas/codex/completion-proof.schema.json +3 -2
  281. package/schemas/release/release-gate-node.schema.json +2 -1
  282. package/dist/scripts/agent-backfill-route-blackbox.js +0 -5
  283. package/dist/scripts/agent-dynamic-pool-route-blackbox.js +0 -5
  284. package/dist/scripts/agent-parallel-write-blackbox.js +0 -56
  285. package/dist/scripts/agent-patch-swarm-route-blackbox.js +0 -10
  286. package/dist/scripts/agent-route-blackbox-lib.js +0 -132
  287. package/dist/scripts/blackbox-command-import-smoke.js +0 -143
  288. package/dist/scripts/blackbox-global-shim.js +0 -77
  289. package/dist/scripts/blackbox-matrix.js +0 -70
  290. package/dist/scripts/blackbox-npx-one-shot.js +0 -69
  291. package/dist/scripts/blackbox-pack-install.js +0 -174
  292. package/dist/scripts/brand-neutrality-zero-leakage-blackbox.js +0 -4
  293. package/dist/scripts/build-once-runner-blackbox.js +0 -34
  294. package/dist/scripts/codex-0140-integration-blackbox.js +0 -13
  295. package/dist/scripts/codex-agent-type-blackbox.js +0 -4
  296. package/dist/scripts/codex-app-harness-blackbox.js +0 -4
  297. package/dist/scripts/codex-app-skill-agent-blackbox.js +0 -4
  298. package/dist/scripts/codex-hook-approval-blackbox.js +0 -4
  299. package/dist/scripts/codex-init-deep-directory-local-blackbox.js +0 -4
  300. package/dist/scripts/codex-native-feature-broker-blackbox.js +0 -4
  301. package/dist/scripts/codex-native-pattern-analysis-blackbox.js +0 -4
  302. package/dist/scripts/codex-native-read-repair-split-blackbox.js +0 -55
  303. package/dist/scripts/codex-native-reference-cache-blackbox.js +0 -41
  304. package/dist/scripts/core-skill-integrity-blackbox.js +0 -33
  305. package/dist/scripts/dfix-fast-blackbox-check.js +0 -37
  306. package/dist/scripts/dfix-parallel-write-blackbox.js +0 -48
  307. package/dist/scripts/dfix-patch-swarm-route-blackbox.js +0 -10
  308. package/dist/scripts/doctor-context7-mcp-repair-blackbox.js +0 -16
  309. package/dist/scripts/doctor-dirty-repair-blackbox.js +0 -22
  310. package/dist/scripts/doctor-dirty-semantic-blackbox.js +0 -8
  311. package/dist/scripts/doctor-fix-production-blackbox.js +0 -26
  312. package/dist/scripts/doctor-native-capability-repair-blackbox.js +0 -39
  313. package/dist/scripts/doctor-startup-config-repair-blackbox.js +0 -13
  314. package/dist/scripts/doctor-supabase-mcp-repair-blackbox.js +0 -14
  315. package/dist/scripts/doctor-transaction-engine-blackbox.js +0 -28
  316. package/dist/scripts/doctor-zellij-fix-blackbox.js +0 -4
  317. package/dist/scripts/doctor-zellij-no-homebrew-blackbox.js +0 -4
  318. package/dist/scripts/doctor-zellij-upgrade-blackbox.js +0 -4
  319. package/dist/scripts/gate-pack-runner-blackbox.js +0 -27
  320. package/dist/scripts/gate-pack-v2-blackbox.js +0 -18
  321. package/dist/scripts/geo-cli-blackbox-check.js +0 -18
  322. package/dist/scripts/loop-collision-blackbox.js +0 -3
  323. package/dist/scripts/loop-concurrency-oversubscription-blackbox.js +0 -3
  324. package/dist/scripts/loop-fixture-production-misuse-blackbox.js +0 -3
  325. package/dist/scripts/loop-kill-interrupt-real-blackbox.js +0 -3
  326. package/dist/scripts/loop-merge-strategy-blackbox.js +0 -3
  327. package/dist/scripts/loop-mesh-production-e2e-blackbox.js +0 -3
  328. package/dist/scripts/loop-side-effect-blackbox.js +0 -3
  329. package/dist/scripts/mad-db-operation-lifecycle-blackbox.js +0 -29
  330. package/dist/scripts/mad-sks-actual-executor-blackbox.js +0 -5
  331. package/dist/scripts/mad-zellij-headless-fallback-blackbox.js +0 -4
  332. package/dist/scripts/mad-zellij-self-heal-blackbox.js +0 -4
  333. package/dist/scripts/naruto-loop-mesh-blackbox.js +0 -3
  334. package/dist/scripts/naruto-real-parallelism-blackbox.js +0 -307
  335. package/dist/scripts/naruto-worktree-coding-blackbox.js +0 -29
  336. package/dist/scripts/parallel-runtime-real-blackbox.js +0 -44
  337. package/dist/scripts/pipeline-codex-native-doctor-mad-routing-real-blackbox.js +0 -77
  338. package/dist/scripts/pipeline-codex-native-e2e-blackbox.js +0 -13
  339. package/dist/scripts/pipeline-codex-native-image-routing-real-blackbox.js +0 -50
  340. package/dist/scripts/pipeline-codex-native-loop-routing-real-blackbox.js +0 -74
  341. package/dist/scripts/pipeline-codex-native-qa-routing-real-blackbox.js +0 -51
  342. package/dist/scripts/pipeline-codex-native-research-routing-real-blackbox.js +0 -45
  343. package/dist/scripts/pipeline-execution-profile-routing-blackbox.js +0 -4
  344. package/dist/scripts/postinstall-global-doctor-blackbox.js +0 -12
  345. package/dist/scripts/ppt-full-e2e-blackbox-check.js +0 -109
  346. package/dist/scripts/ppt-imagegen-blackbox-check.js +0 -46
  347. package/dist/scripts/project-skill-dedupe-blackbox.js +0 -36
  348. package/dist/scripts/qa-backfill-route-blackbox.js +0 -5
  349. package/dist/scripts/qa-patch-swarm-route-blackbox.js +0 -10
  350. package/dist/scripts/release-full-parallelism-blackbox.js +0 -41
  351. package/dist/scripts/release-triwiki-first-runner-blackbox.js +0 -48
  352. package/dist/scripts/release-wiring-3110-blackbox.js +0 -27
  353. package/dist/scripts/release-wiring-3112-blackbox.js +0 -17
  354. package/dist/scripts/release-wiring-3113-blackbox.js +0 -17
  355. package/dist/scripts/research-backfill-route-blackbox.js +0 -5
  356. package/dist/scripts/research-final-reviewer-blackbox.js +0 -70
  357. package/dist/scripts/research-stage-cycle-runtime-blackbox.js +0 -40
  358. package/dist/scripts/research-synthesis-writer-blackbox.js +0 -24
  359. package/dist/scripts/route-blackbox-realism-check.js +0 -21
  360. package/dist/scripts/scheduler-resource-claim-blackbox.js +0 -24
  361. package/dist/scripts/seo-cli-blackbox-check.js +0 -18
  362. package/dist/scripts/sks-3110-all-feature-regression-blackbox.js +0 -116
  363. package/dist/scripts/sks-3112-all-feature-regression-blackbox.js +0 -29
  364. package/dist/scripts/sks-3113-all-feature-regression-blackbox.js +0 -17
  365. package/dist/scripts/sks-400-all-feature-regression-blackbox.js +0 -21
  366. package/dist/scripts/sks-400-extreme-parallel-blackbox.js +0 -8
  367. package/dist/scripts/sks-400-five-minute-blackbox.js +0 -9
  368. package/dist/scripts/sks-400-legacy-purge-blackbox.js +0 -8
  369. package/dist/scripts/sks-401-all-feature-regression-blackbox.js +0 -46
  370. package/dist/scripts/sks-401-five-minute-actual-blackbox.js +0 -23
  371. package/dist/scripts/sks-402-all-feature-regression-blackbox.js +0 -9
  372. package/dist/scripts/sks-402-five-minute-real-blackbox.js +0 -22
  373. package/dist/scripts/sksd-warm-cache-blackbox.js +0 -12
  374. package/dist/scripts/supabase-secret-preservation-blackbox.js +0 -29
  375. package/dist/scripts/team-backfill-route-blackbox.js +0 -5
  376. package/dist/scripts/team-parallel-write-blackbox.js +0 -55
  377. package/dist/scripts/team-patch-swarm-route-blackbox.js +0 -10
  378. package/dist/scripts/triwiki-affected-graph-blackbox.js +0 -28
  379. package/dist/scripts/triwiki-proof-bank-blackbox.js +0 -30
  380. package/dist/scripts/triwiki-proof-bank-lock-blackbox.js +0 -7
  381. package/dist/scripts/update-preserves-supabase-keys-blackbox.js +0 -27
  382. package/dist/scripts/ux-patch-swarm-route-blackbox.js +0 -10
  383. package/dist/scripts/ux-review-imagegen-blackbox-check.js +0 -67
  384. package/dist/scripts/zellij-initial-main-only-blackbox.js +0 -28
  385. package/dist/scripts/zellij-pane-lock-concurrency-blackbox.js +0 -80
  386. package/dist/scripts/zellij-pane-lock-open-worker-integration-blackbox.js +0 -137
  387. package/dist/scripts/zellij-self-heal-typed-blackbox.js +0 -4
  388. package/dist/scripts/zellij-slot-telemetry-real-blackbox.js +0 -20
  389. package/dist/scripts/zellij-stacked-fallback-integration-blackbox.js +0 -81
  390. package/dist/scripts/zellij-worker-pane-real-ui-blackbox.js +0 -202
@@ -67,8 +67,10 @@ import { crossRebaseIdleWorktrees } from '../git/git-worktree-cross-rebase.js';
67
67
  import { gitOutputLine, runGitCommand } from '../git/git-worktree-runner.js';
68
68
  import { writeParallelRuntimeProof } from './parallel-runtime-proof.js';
69
69
  import { enforceRetention } from '../retention.js';
70
+ import { APPROACHES, rank, scoreCandidate, summarizeTournament } from '../naruto/solution-tournament.js';
70
71
  export async function runNativeAgentOrchestrator(opts = {}) {
71
72
  const root = path.resolve(opts.root || process.cwd());
73
+ const sessionKey = opts.sessionKey || null;
72
74
  const prompt = String(opts.prompt || 'Native agent run');
73
75
  const route = opts.route || '$Agent';
74
76
  const routeCommand = String(opts.routeCommand || defaultRouteCommand(route));
@@ -82,11 +84,11 @@ export async function runNativeAgentOrchestrator(opts = {}) {
82
84
  const realZellijProofRequired = realZellij && process.env.SKS_REQUIRE_ZELLIJ === '1';
83
85
  const created = opts.missionId
84
86
  ? { id: opts.missionId, dir: missionDir(root, opts.missionId), mission: { id: opts.missionId, mode: 'agent', prompt } }
85
- : await createMission(root, { mode: 'agent', prompt });
87
+ : await createMission(root, { mode: 'agent', prompt, sessionKey });
86
88
  const missionId = created.id;
87
89
  const dir = created.dir;
88
90
  if (legacyCodexExecRequested) {
89
- await setCurrent(root, { mission_id: missionId, mode: 'AGENT', phase: 'AGENT_LEGACY_CODEX_EXEC_BLOCKED', route_command: routeCommand, native_agent_backend: 'codex-sdk', updated_at: nowIso() });
91
+ await setCurrent(root, { mission_id: missionId, mode: 'AGENT', phase: 'AGENT_LEGACY_CODEX_EXEC_BLOCKED', route_command: routeCommand, native_agent_backend: 'codex-sdk', updated_at: nowIso() }, { sessionKey });
90
92
  return legacyCodexExecBlockedRun({ root, missionId, dir, route, routeCommand, routeBlackboxKind, backend: 'codex-sdk' });
91
93
  }
92
94
  // Route start: consult this route's deployed Core Skill snapshot (read-only).
@@ -155,7 +157,7 @@ export async function runNativeAgentOrchestrator(opts = {}) {
155
157
  appshots_operator_action_required: strategyGate.appshots_operator_action_required
156
158
  };
157
159
  if (!strategyGate.scheduler_allowed) {
158
- await setCurrent(root, { mission_id: missionId, mode: 'AGENT', phase: 'AGENT_STRATEGY_GATE_BLOCKED', route_command: routeCommand, native_agent_backend: backend, updated_at: nowIso() });
160
+ await setCurrent(root, { mission_id: missionId, mode: 'AGENT', phase: 'AGENT_STRATEGY_GATE_BLOCKED', route_command: routeCommand, native_agent_backend: backend, updated_at: nowIso() }, { sessionKey });
159
161
  const blockedLedgerRoot = path.join(dir, 'agents');
160
162
  return {
161
163
  schema: 'sks.agent-run.v1',
@@ -356,7 +358,7 @@ export async function runNativeAgentOrchestrator(opts = {}) {
356
358
  return killTimedOutAgentSessions(ledgerRoot, now, { hardTimeoutMs: schedulerHardTimeoutMs });
357
359
  }
358
360
  await nativeCliSwarm.initialize();
359
- await setCurrent(root, { mission_id: missionId, mode: 'AGENT', phase: 'AGENT_NATIVE_KERNEL_RUNNING', route_command: routeCommand, native_agent_backend: backend });
361
+ await setCurrent(root, { mission_id: missionId, mode: 'AGENT', phase: 'AGENT_NATIVE_KERNEL_RUNNING', route_command: routeCommand, native_agent_backend: backend }, { sessionKey });
360
362
  const scheduler = await runAgentScheduler({
361
363
  root: ledgerRoot,
362
364
  missionId,
@@ -426,6 +428,7 @@ export async function runNativeAgentOrchestrator(opts = {}) {
426
428
  workerWorktree,
427
429
  runtime: gitWorktreeRuntime
428
430
  });
431
+ enforceWorkerQualityProtocolForSlice(result, runtimeSlice);
429
432
  const terminalClose = await closeAgentTerminalSession(ledgerRoot, agent, {
430
433
  exitCode: result.status === 'done' ? 0 : 1,
431
434
  status: result.status,
@@ -497,7 +500,9 @@ export async function runNativeAgentOrchestrator(opts = {}) {
497
500
  proofMode: opts.mock === true ? 'mock-process' : 'production',
498
501
  requireWorkerPids: opts.nativeCliSwarm !== false && targetActiveSlots >= 16
499
502
  });
500
- const results = scheduler.results;
503
+ let results = scheduler.results;
504
+ const tournamentSelection = await selectSolutionTournamentWinners(root, ledgerRoot, results);
505
+ results = tournamentSelection.results;
501
506
  const nativeCliSessionProof = await writeNativeCliSessionProof(ledgerRoot, {
502
507
  requestedAgents: Number(opts.agents || roster.agent_count || targetActiveSlots),
503
508
  targetActiveSlots,
@@ -545,6 +550,7 @@ export async function runNativeAgentOrchestrator(opts = {}) {
545
550
  : results;
546
551
  const patchSwarm = await runAgentPatchSwarmRuntime(root, ledgerRoot, {
547
552
  missionId,
553
+ sessionKey,
548
554
  route,
549
555
  routeCommand,
550
556
  writeCapable,
@@ -594,8 +600,8 @@ export async function runNativeAgentOrchestrator(opts = {}) {
594
600
  route,
595
601
  routeCommand,
596
602
  routeBlackboxKind,
597
- requestedWorkItems: desiredWorkItemCount,
598
- minimumWorkItems,
603
+ requestedWorkItems: partition.task_graph?.desired_work_items || desiredWorkItemCount,
604
+ minimumWorkItems: partition.task_graph?.minimum_work_items || minimumWorkItems,
599
605
  targetActiveSlots,
600
606
  realParallel: backend === 'codex-sdk' && opts.mock !== true,
601
607
  visualLaneCount,
@@ -627,7 +633,7 @@ export async function runNativeAgentOrchestrator(opts = {}) {
627
633
  });
628
634
  await writeAgentCodexCockpitArtifacts(dir, { missionId, projectHash: namespace.root_hash });
629
635
  await enforceRetention(root, { afterRoute: true, completedMissionId: missionId, rotateLargeJsonl: true, lightweight: true }).catch(() => null);
630
- await setCurrent(root, { mission_id: missionId, mode: 'AGENT', phase: proof.ok ? 'AGENT_NATIVE_KERNEL_DONE' : 'AGENT_NATIVE_KERNEL_BLOCKED', native_agent_backend: backend, updated_at: nowIso() });
636
+ await setCurrent(root, { mission_id: missionId, mode: 'AGENT', phase: proof.ok ? 'AGENT_NATIVE_KERNEL_DONE' : 'AGENT_NATIVE_KERNEL_BLOCKED', native_agent_backend: backend, updated_at: nowIso() }, { sessionKey });
631
637
  return {
632
638
  schema: 'sks.agent-run.v1',
633
639
  ok: proof.ok,
@@ -640,11 +646,11 @@ export async function runNativeAgentOrchestrator(opts = {}) {
640
646
  roster,
641
647
  partition: { ok: partition.ok, slice_count: partition.slices.length, lease_count: partition.leases.length, blockers: partition.blockers },
642
648
  task_graph: partition.task_graph?.route_work_count_summary || null,
643
- requested_work_items: desiredWorkItemCount,
649
+ requested_work_items: partition.task_graph?.desired_work_items || desiredWorkItemCount,
644
650
  actual_total_work_items: partition.task_graph?.total_work_items || partition.slices.length,
645
651
  target_active_slots: targetActiveSlots,
646
652
  visual_lane_count: visualLaneCount,
647
- minimum_work_items: minimumWorkItems,
653
+ minimum_work_items: partition.task_graph?.minimum_work_items || minimumWorkItems,
648
654
  scheduler,
649
655
  source_intelligence: sourceIntelligenceRef,
650
656
  goal_mode: goalModeRef,
@@ -697,6 +703,112 @@ function withFinalGptPatchEnvelopes(results, patchEnvelopes = []) {
697
703
  next[0] = { ...next[0], patch_envelopes: patchEnvelopes };
698
704
  return next;
699
705
  }
706
+ async function selectSolutionTournamentWinners(root, ledgerRoot, results) {
707
+ const groups = new Map();
708
+ for (const result of results || []) {
709
+ const groupId = String(result?.tournament?.group_id || result?.naruto_runtime?.tournament?.group_id || '');
710
+ if (!groupId || !Array.isArray(result?.patch_envelopes) || result.patch_envelopes.length === 0)
711
+ continue;
712
+ groups.set(groupId, [...(groups.get(groupId) || []), result]);
713
+ }
714
+ const tournamentReports = [];
715
+ for (const [groupId, rows] of groups) {
716
+ if (rows.length < 2)
717
+ continue;
718
+ const candidates = await Promise.all(rows.map(async (result, index) => {
719
+ const candidate = {
720
+ id: String(result?.task_slice_id || result?.naruto_runtime?.work_item_id || `${groupId}-cand${index + 1}`),
721
+ approach: String(result?.tournament?.approach || result?.naruto_runtime?.tournament?.approach || APPROACHES[index] || ''),
722
+ worktree: String(firstEnvelopeField(result, 'git_worktree')?.worktree_path || ''),
723
+ patch: { patch_envelopes: result.patch_envelopes || [] },
724
+ score: null,
725
+ result
726
+ };
727
+ candidate.score = await scoreCandidate(root, candidate).catch((err) => ({
728
+ machine_ok: false,
729
+ tests_passed: 0,
730
+ tests_failed: 1,
731
+ diff_lines: 999999,
732
+ new_symbols: 999,
733
+ impact_breaks: 999,
734
+ total: 999999,
735
+ error: err instanceof Error ? err.message : String(err)
736
+ }));
737
+ return candidate;
738
+ }));
739
+ const alive = candidates
740
+ .filter((candidate) => candidate.score?.machine_ok && candidate.score.impact_breaks === 0)
741
+ .sort((a, b) => rank(a.score) - rank(b.score));
742
+ const winner = alive[0] || null;
743
+ const tournamentResult = {
744
+ schema: 'sks.solution-tournament.v1',
745
+ winner,
746
+ reason: winner ? (alive.length === 1 ? 'single_survivor' : 'judge:deterministic-maintainer-score') : 'all_candidates_failed_machine_checks',
747
+ candidates
748
+ };
749
+ const summary = summarizeTournament(tournamentResult);
750
+ const reportRow = {
751
+ ...summary,
752
+ group_id: groupId,
753
+ judge_worker: alive.length > 1 ? 'deterministic-maintainer-score' : null,
754
+ loser_cleanup: []
755
+ };
756
+ tournamentReports.push(reportRow);
757
+ if (!winner) {
758
+ for (const candidate of candidates) {
759
+ candidate.result.status = 'blocked';
760
+ candidate.result.blockers = [...new Set([...(candidate.result.blockers || []), 'solution_tournament_all_candidates_failed'])];
761
+ }
762
+ continue;
763
+ }
764
+ for (const candidate of candidates) {
765
+ if (candidate === winner) {
766
+ candidate.result.tournament = { ...candidate.result.tournament, selection: summary, selected: true };
767
+ candidate.result.patch_envelopes = (candidate.result.patch_envelopes || []).map((envelope) => ({ ...envelope, tournament: summary }));
768
+ continue;
769
+ }
770
+ const cleanup = await cleanupTournamentLoserCandidate(root, candidate).catch((err) => ({ ok: false, blockers: ['tournament_loser_cleanup_failed:' + (err instanceof Error ? err.message : String(err))] }));
771
+ reportRow.loser_cleanup.push(cleanup);
772
+ candidate.result.patch_envelopes = [];
773
+ candidate.result.changed_files = [];
774
+ candidate.result.no_patch_reason = {
775
+ schema: 'sks.solution-tournament-loser.v1',
776
+ ok: true,
777
+ reason: 'solution_tournament_loser',
778
+ group_id: groupId,
779
+ winner_id: winner.id
780
+ };
781
+ candidate.result.tournament = { ...candidate.result.tournament, selection: summary, selected: false };
782
+ }
783
+ }
784
+ const report = {
785
+ schema: 'sks.solution-tournament-report.v1',
786
+ generated_at: nowIso(),
787
+ ok: tournamentReports.every((row) => row.winner_id),
788
+ tournament_count: tournamentReports.length,
789
+ tournaments: tournamentReports
790
+ };
791
+ await writeJsonAtomic(path.join(ledgerRoot, 'solution-tournament-report.json'), report);
792
+ return { results, report };
793
+ }
794
+ async function cleanupTournamentLoserCandidate(root, candidate) {
795
+ const envelope = (candidate.patch?.patch_envelopes || []).find((row) => row?.git_worktree?.worktree_path);
796
+ const meta = envelope?.git_worktree;
797
+ if (!meta?.worktree_path || !meta?.main_repo_root)
798
+ return { ok: true, action: 'no_worktree', candidate_id: candidate.id };
799
+ const remove = await runGitCommand(String(meta.main_repo_root || root), ['worktree', 'remove', '--force', String(meta.worktree_path)]);
800
+ if (remove.ok && meta.branch)
801
+ await runGitCommand(String(meta.main_repo_root || root), ['branch', '-D', String(meta.branch)]);
802
+ return {
803
+ schema: 'sks.solution-tournament-loser-cleanup.v1',
804
+ ok: remove.ok,
805
+ action: remove.ok ? 'removed' : 'remove_failed',
806
+ candidate_id: candidate.id,
807
+ worktree_path: meta.worktree_path,
808
+ branch: meta.branch || null,
809
+ blockers: remove.ok ? [] : ['git_worktree_remove_failed']
810
+ };
811
+ }
700
812
  function uniqueWritableSlicesForWorktrees(slices = [], limit) {
701
813
  const selected = [];
702
814
  const seenOwners = new Set();
@@ -721,65 +833,90 @@ function applyNarutoWorkGraphToPartition(partition, graph, roster, targetActiveS
721
833
  const sourceIntelligenceRefs = referenceWorkItem?.source_intelligence_refs || partition?.source_intelligence_refs || null;
722
834
  const goalModeRef = referenceWorkItem?.goal_mode_ref || partition?.goal_mode_ref || null;
723
835
  const strategyRefs = referenceWorkItem?.strategy_refs || partition?.strategy_refs || null;
724
- const slices = (graph.work_items || []).map((item, index) => {
836
+ const slices = (graph.work_items || []).flatMap((item, index) => {
837
+ const candidateCount = item?.write_allowed && Number(item?.tournament || 0) >= 2
838
+ ? Math.min(4, Math.max(2, Math.floor(Number(item.tournament))))
839
+ : 1;
725
840
  const requestedOwner = item.owner ? String(item.owner) : '';
726
- const owner = requestedOwner && activeAgentIds.has(requestedOwner)
727
- ? requestedOwner
728
- : String(fallbackOwners[index % fallbackOwners.length]?.id || requestedOwner || `naruto_clone_${String(index + 1).padStart(3, '0')}`);
729
841
  const sliceId = String(item.id || `NW-${String(index + 1).padStart(6, '0')}`);
730
842
  const writePaths = normalizePathList(item.write_paths);
731
843
  const readonlyPaths = normalizePathList(item.readonly_paths);
732
844
  const targetPaths = normalizePathList(item.target_paths);
733
- const verificationNodeId = writePaths.length ? `verify:${sliceId}` : null;
734
- const rollbackNodeId = writePaths.length ? `rollback:${sliceId}` : null;
735
845
  const parentObjective = normalizeWorkerPromptText(parentPrompt);
736
- return {
737
- id: sliceId,
738
- owner_agent_id: owner,
739
- owner,
740
- lane: owner,
741
- role: String(item.required_role || 'verifier'),
742
- domain: String(item.allocation_hints?.domains?.[0] || item.kind || 'naruto'),
743
- title: String(item.title || item.id || `Naruto work ${index + 1}`),
744
- dependencies: Array.isArray(item.dependencies) ? item.dependencies.map(String) : [],
745
- priority: index + 1,
746
- required_persona_category: String(item.required_role || 'verifier'),
747
- lease_requirements: Array.isArray(item.lease_requirements) ? item.lease_requirements : [],
748
- generated_by: 'sks.naruto-work-graph.v1',
749
- route_domain: String(item.kind || 'naruto'),
750
- work_item_kind: String(item.kind || 'verification'),
751
- target_paths: targetPaths,
752
- readonly_paths: readonlyPaths,
753
- write_paths: writePaths,
754
- allocation_reason: item.allocation_reason || null,
755
- allocation_score: item.allocation_score ?? null,
756
- allocation_hints: item.allocation_hints || null,
757
- allocation_original_owner: requestedOwner || null,
758
- allocation_owner_rebalanced: Boolean(requestedOwner && owner !== requestedOwner),
759
- micro_win_id: sliceId,
760
- verification_node_id: verificationNodeId,
761
- rollback_node_id: rollbackNodeId,
762
- verification_required: item.verification_required === true,
763
- source_intelligence_refs: sourceIntelligenceRefs,
764
- goal_mode_ref: goalModeRef,
765
- strategy_refs: strategyRefs,
766
- parent_prompt: parentObjective,
767
- max_attempts: 1,
768
- description: [
769
- parentObjective ? `Parent Naruto objective:\n${parentObjective}` : null,
770
- String(item.title || item.id || 'Naruto work item'),
771
- `Naruto owner: ${owner}`,
772
- item.allocation_reason ? `Allocation: ${item.allocation_reason}` : null,
773
- writePaths.length ? `Write paths: ${writePaths.join(', ')}` : 'Read-only or no-write work item.',
774
- writePaths.length ? null : 'Read-only instruction: inspect the requested files/artifacts and do not run package scripts, build commands, tests, or temp-file-creating checks unless the parent objective explicitly requires them.'
775
- ].filter(Boolean).join('\n')
776
- };
846
+ return Array.from({ length: candidateCount }, (_unused, candidateOffset) => {
847
+ const candidateIndex = candidateOffset + 1;
848
+ const candidateSliceId = candidateCount > 1 ? `${sliceId}-cand${candidateIndex}` : sliceId;
849
+ const owner = requestedOwner && activeAgentIds.has(requestedOwner) && candidateCount === 1
850
+ ? requestedOwner
851
+ : String(fallbackOwners[(index + candidateOffset) % fallbackOwners.length]?.id || requestedOwner || `naruto_clone_${String(index + candidateIndex).padStart(3, '0')}`);
852
+ const verificationNodeId = writePaths.length ? `verify:${candidateSliceId}` : null;
853
+ const rollbackNodeId = writePaths.length ? `rollback:${candidateSliceId}` : null;
854
+ const approachDirective = candidateCount > 1 ? APPROACHES[candidateOffset] || APPROACHES[APPROACHES.length - 1] || '' : null;
855
+ return {
856
+ id: candidateSliceId,
857
+ owner_agent_id: owner,
858
+ owner,
859
+ lane: owner,
860
+ role: String(item.required_role || 'verifier'),
861
+ domain: String(item.allocation_hints?.domains?.[0] || item.kind || 'naruto'),
862
+ title: candidateCount > 1
863
+ ? `${String(item.title || item.id || `Naruto work ${index + 1}`)} (candidate ${candidateIndex}/${candidateCount})`
864
+ : String(item.title || item.id || `Naruto work ${index + 1}`),
865
+ dependencies: Array.isArray(item.dependencies) ? item.dependencies.map(String) : [],
866
+ priority: index + 1,
867
+ required_persona_category: String(item.required_role || 'verifier'),
868
+ lease_requirements: Array.isArray(item.lease_requirements) ? item.lease_requirements : [],
869
+ generated_by: 'sks.naruto-work-graph.v1',
870
+ route_domain: String(item.kind || 'naruto'),
871
+ work_item_kind: String(item.kind || 'verification'),
872
+ tournament_group_id: candidateCount > 1 ? sliceId : null,
873
+ tournament_candidate_index: candidateCount > 1 ? candidateIndex : null,
874
+ tournament_candidate_count: candidateCount > 1 ? candidateCount : null,
875
+ approach_directive: approachDirective,
876
+ target_paths: targetPaths,
877
+ readonly_paths: readonlyPaths,
878
+ write_paths: writePaths,
879
+ allocation_reason: item.allocation_reason || null,
880
+ allocation_score: item.allocation_score ?? null,
881
+ allocation_hints: item.allocation_hints || null,
882
+ allocation_original_owner: requestedOwner || null,
883
+ allocation_owner_rebalanced: Boolean(requestedOwner && owner !== requestedOwner),
884
+ micro_win_id: sliceId,
885
+ verification_node_id: verificationNodeId,
886
+ rollback_node_id: rollbackNodeId,
887
+ verification_required: item.verification_required === true,
888
+ source_intelligence_refs: sourceIntelligenceRefs,
889
+ goal_mode_ref: goalModeRef,
890
+ strategy_refs: strategyRefs,
891
+ parent_prompt: parentObjective,
892
+ max_attempts: 1,
893
+ description: [
894
+ parentObjective ? `Parent Naruto objective:\n${parentObjective}` : null,
895
+ String(item.title || item.id || 'Naruto work item'),
896
+ approachDirective ? `Solution tournament approach: ${approachDirective}` : null,
897
+ `Naruto owner: ${owner}`,
898
+ item.allocation_reason ? `Allocation: ${item.allocation_reason}` : null,
899
+ writePaths.length ? `Write paths: ${writePaths.join(', ')}` : 'Read-only or no-write work item.',
900
+ writePaths.length ? null : 'Read-only instruction: inspect the requested files/artifacts and do not run package scripts, build commands, tests, or temp-file-creating checks unless the parent objective explicitly requires them.'
901
+ ].filter(Boolean).join('\n')
902
+ };
903
+ });
777
904
  });
778
- const workItems = (graph.work_items || []).map((item) => ({
779
- ...item,
780
- source_intelligence_refs: item.source_intelligence_refs || sourceIntelligenceRefs,
781
- goal_mode_ref: item.goal_mode_ref || goalModeRef,
782
- strategy_refs: item.strategy_refs || strategyRefs
905
+ const workItems = slices.map((slice) => ({
906
+ id: slice.id,
907
+ kind: slice.work_item_kind || slice.route_domain || 'verification',
908
+ title: slice.title,
909
+ target_paths: slice.target_paths || [],
910
+ readonly_paths: slice.readonly_paths || [],
911
+ write_paths: slice.write_paths || [],
912
+ owner: slice.owner_agent_id,
913
+ tournament_group_id: slice.tournament_group_id || null,
914
+ tournament_candidate_index: slice.tournament_candidate_index || null,
915
+ tournament_candidate_count: slice.tournament_candidate_count || null,
916
+ approach_directive: slice.approach_directive || null,
917
+ source_intelligence_refs: sourceIntelligenceRefs,
918
+ goal_mode_ref: goalModeRef,
919
+ strategy_refs: strategyRefs
783
920
  }));
784
921
  const leases = slices.flatMap((slice) => [
785
922
  ...slice.write_paths.map((file, index) => ({
@@ -791,6 +928,7 @@ function applyNarutoWorkGraphToPartition(partition, graph, roster, targetActiveS
791
928
  status: 'active',
792
929
  owner_agent: slice.owner_agent_id,
793
930
  write_paths: slice.write_paths,
931
+ tournament_group_id: slice.tournament_group_id || null,
794
932
  strategy_task_id: slice.id,
795
933
  micro_win_id: slice.micro_win_id || slice.id,
796
934
  verification_node_id: slice.verification_node_id || null,
@@ -806,6 +944,7 @@ function applyNarutoWorkGraphToPartition(partition, graph, roster, targetActiveS
806
944
  status: 'active',
807
945
  owner_agent: slice.owner_agent_id,
808
946
  write_paths: slice.write_paths,
947
+ tournament_group_id: slice.tournament_group_id || null,
809
948
  strategy_task_id: slice.id,
810
949
  micro_win_id: slice.micro_win_id || slice.id,
811
950
  verification_node_id: slice.verification_node_id || null,
@@ -819,6 +958,8 @@ function applyNarutoWorkGraphToPartition(partition, graph, roster, targetActiveS
819
958
  ? {
820
959
  ...partition.task_graph,
821
960
  total_work_items: slices.length,
961
+ desired_work_items: slices.length,
962
+ minimum_work_items: Math.max(Number(partition.task_graph.minimum_work_items || 0), slices.length),
822
963
  work_items: workItems,
823
964
  route_work_count_summary: {
824
965
  ...(partition.task_graph.route_work_count_summary || {}),
@@ -891,12 +1032,13 @@ function augmentVerificationRollbackDagForNaruto(dag, slices) {
891
1032
  function buildNarutoRuntimeWiringProof(partition, graph, roster, targetActiveSlots) {
892
1033
  const activeAgentIds = new Set((Array.isArray(roster?.roster) ? roster.roster : []).slice(0, Math.max(1, targetActiveSlots)).map((row) => String(row.id || '')).filter(Boolean));
893
1034
  const slices = Array.isArray(partition?.slices) ? partition.slices : [];
894
- const activeWriteConflicts = slices.flatMap((slice) => normalizePathList(slice.write_paths));
895
- const duplicateActiveWrites = activeWriteConflicts.filter((file, index, all) => all.indexOf(file) !== index);
1035
+ const activeWriteConflicts = slices.flatMap((slice) => normalizePathList(slice.write_paths).map((file) => ({ file, tournament_group_id: slice.tournament_group_id || null })));
1036
+ const duplicateActiveWrites = activeWriteConflicts.filter((entry, index, all) => all.some((other, otherIndex) => otherIndex !== index && other.file === entry.file && !sameTournamentGroupEntry(entry, other)));
896
1037
  const ownerPreserved = slices.every((slice) => !slice.allocation_original_owner || slice.allocation_owner_rebalanced || slice.owner_agent_id === slice.allocation_original_owner);
897
1038
  const inactiveOwnersRebalanced = slices.every((slice) => !slice.allocation_original_owner || activeAgentIds.has(slice.allocation_original_owner) || slice.allocation_owner_rebalanced);
1039
+ const expectedSliceCount = (graph?.work_items || []).reduce((sum, item) => sum + (item?.write_allowed && Number(item?.tournament || 0) >= 2 ? Math.min(4, Math.max(2, Math.floor(Number(item.tournament)))) : 1), 0);
898
1040
  const blockers = [
899
- ...(slices.length === Number(graph?.work_items?.length || 0) ? [] : ['naruto_runtime_slice_count_mismatch']),
1041
+ ...(slices.length === expectedSliceCount ? [] : ['naruto_runtime_slice_count_mismatch']),
900
1042
  ...(ownerPreserved ? [] : ['naruto_runtime_owner_not_preserved']),
901
1043
  ...(inactiveOwnersRebalanced ? [] : ['naruto_runtime_inactive_owner_not_rebalanced']),
902
1044
  ...(duplicateActiveWrites.length ? ['naruto_runtime_duplicate_write_paths_in_partition'] : [])
@@ -922,6 +1064,9 @@ function buildNarutoRuntimeWiringProof(partition, graph, roster, targetActiveSlo
922
1064
  blockers
923
1065
  };
924
1066
  }
1067
+ function sameTournamentGroupEntry(a, b) {
1068
+ return Boolean(a?.tournament_group_id && b?.tournament_group_id && a.tournament_group_id === b.tournament_group_id);
1069
+ }
925
1070
  function attachNarutoRuntimeProof(result, agent, slice) {
926
1071
  const controlPlane = result?.codex_child_report || result?.codex_sdk_thread || result?.backend_router_report || null;
927
1072
  const selectedBackend = String(result?.backend_router_report?.selected_backend || result?.backend || '');
@@ -933,6 +1078,13 @@ function attachNarutoRuntimeProof(result, agent, slice) {
933
1078
  source_of_truth: 'agent-orchestrator-scheduler',
934
1079
  actual_worker_control_plane: actualWorkerControlPlane,
935
1080
  work_item_id: String(slice?.id || result?.task_slice_id || ''),
1081
+ work_item_kind: String(slice?.work_item_kind || result?.work_item_kind || ''),
1082
+ tournament: slice?.tournament_group_id ? {
1083
+ group_id: String(slice.tournament_group_id),
1084
+ candidate_index: Number(slice.tournament_candidate_index || 1),
1085
+ candidate_count: Number(slice.tournament_candidate_count || 1),
1086
+ approach: String(slice.approach_directive || '')
1087
+ } : null,
936
1088
  owner: String(slice?.owner_agent_id || slice?.owner || agent?.id || ''),
937
1089
  allocation_reason: slice?.allocation_reason || null,
938
1090
  rebalance_generation: Number(slice?.allocation_owner_rebalanced === true ? 1 : 0),
@@ -948,6 +1100,17 @@ function attachNarutoRuntimeProof(result, agent, slice) {
948
1100
  }
949
1101
  : null
950
1102
  };
1103
+ if (slice?.work_item_kind)
1104
+ result.work_item_kind = String(slice.work_item_kind);
1105
+ if (slice?.tournament_group_id) {
1106
+ result.tournament = {
1107
+ schema: 'sks.solution-tournament-candidate.v1',
1108
+ group_id: String(slice.tournament_group_id),
1109
+ candidate_index: Number(slice.tournament_candidate_index || 1),
1110
+ candidate_count: Number(slice.tournament_candidate_count || 1),
1111
+ approach: String(slice.approach_directive || '')
1112
+ };
1113
+ }
951
1114
  if (result.naruto_runtime.control_plane_result)
952
1115
  result.control_plane_result = result.naruto_runtime.control_plane_result;
953
1116
  result.verification = {
@@ -955,6 +1118,34 @@ function attachNarutoRuntimeProof(result, agent, slice) {
955
1118
  checks: [...(result.verification?.checks || []), 'naruto-agent-orchestrator-scheduler-source-of-truth']
956
1119
  };
957
1120
  }
1121
+ function enforceWorkerQualityProtocolForSlice(result, slice) {
1122
+ const writesPatch = Boolean((result.patch_envelopes || []).length || (result.changed_files || []).length || (result.writes || []).length);
1123
+ if (!writesPatch)
1124
+ return;
1125
+ const kind = String(slice?.work_item_kind || result?.work_item_kind || '').toLowerCase();
1126
+ const text = [kind, slice?.id, slice?.title].join(' ').toLowerCase();
1127
+ const blockers = [];
1128
+ if ((kind === 'bugfix' || /\b(fix|bug|regression|broken|failure|crash|error)\b|버그|회귀/.test(text)) && !validRegressionProof(result.regression_proof || firstEnvelopeField(result, 'regression_proof'))) {
1129
+ blockers.push('tdd_evidence_missing');
1130
+ }
1131
+ if ((kind === 'conflict_resolution' || /\b(repair|conflict|rebase|rollback)\b|수리|충돌/.test(text)) && !(result.repair_hypothesis || firstEnvelopeField(result, 'repair_hypothesis'))) {
1132
+ blockers.push('repair_without_hypothesis');
1133
+ }
1134
+ if (!blockers.length)
1135
+ return;
1136
+ result.status = 'blocked';
1137
+ result.blockers = [...new Set([...(result.blockers || []), ...blockers])];
1138
+ result.verification = {
1139
+ status: 'failed',
1140
+ checks: [...(result.verification?.checks || []), 'naruto-worker-quality-protocol']
1141
+ };
1142
+ }
1143
+ function firstEnvelopeField(result, field) {
1144
+ return (Array.isArray(result?.patch_envelopes) ? result.patch_envelopes : []).find((envelope) => envelope?.[field])?.[field] || null;
1145
+ }
1146
+ function validRegressionProof(proof) {
1147
+ return Boolean(proof && proof.failed_before === true && proof.passed_after === true && String(proof.test_file || '').trim());
1148
+ }
958
1149
  function normalizePathList(values) {
959
1150
  return (Array.isArray(values) ? values : []).map((file) => String(file || '').replace(/\\/g, '/').replace(/^\.\/+/, '').replace(/\/+$/, '')).filter(Boolean);
960
1151
  }
@@ -1043,6 +1234,13 @@ async function finalizeWorkerGitWorktree(input) {
1043
1234
  generationIndex: Math.max(1, Math.floor(Number(input.agent.generation_index || 1))),
1044
1235
  checkpoint
1045
1236
  });
1237
+ envelope.task_slice_id = String(input.slice.id || '');
1238
+ if (input.result.regression_proof)
1239
+ envelope.regression_proof = input.result.regression_proof;
1240
+ if (input.result.repair_hypothesis)
1241
+ envelope.repair_hypothesis = input.result.repair_hypothesis;
1242
+ if (input.result.tournament)
1243
+ envelope.tournament = input.result.tournament;
1046
1244
  input.result.patch_envelopes = [...(Array.isArray(input.result.patch_envelopes) ? input.result.patch_envelopes : []), envelope];
1047
1245
  input.result.changed_files = [...new Set([...(input.result.changed_files || []), ...diff.changed_files])];
1048
1246
  input.result.artifacts = [...new Set([...(input.result.artifacts || []), path.relative(input.ledgerRoot, path.join(input.workerWorktree.artifactDir, 'git-worktree-diff.json')), path.relative(input.ledgerRoot, path.join(input.workerWorktree.artifactDir, 'git-worktree-checkpoint.json'))])];
@@ -1122,7 +1320,7 @@ async function legacyCodexExecBlockedRun(input) {
1122
1320
  };
1123
1321
  }
1124
1322
  async function runAgentPatchSwarmRuntime(root, ledgerRoot, input) {
1125
- await setCurrent(root, { mission_id: input.missionId, mode: 'AGENT', phase: 'AGENT_PATCH_SWARM_RUNNING', route_command: input.routeCommand, updated_at: nowIso() });
1323
+ await setCurrent(root, { mission_id: input.missionId, mode: 'AGENT', phase: 'AGENT_PATCH_SWARM_RUNNING', route_command: input.routeCommand, updated_at: nowIso() }, { sessionKey: input.sessionKey });
1126
1324
  const queueStore = new PersistentAgentPatchQueueStore(ledgerRoot);
1127
1325
  for (const result of input.results || []) {
1128
1326
  for (const envelope of result.patch_envelopes || []) {
@@ -1130,7 +1328,14 @@ async function runAgentPatchSwarmRuntime(root, ledgerRoot, input) {
1130
1328
  ...envelope,
1131
1329
  agent_id: envelope.agent_id || result.agent_id,
1132
1330
  session_id: envelope.session_id || result.session_id
1133
- }, { mission_id: input.missionId, route: input.route });
1331
+ }, {
1332
+ mission_id: input.missionId,
1333
+ route: input.route,
1334
+ root,
1335
+ work_item_kind: result.work_item_kind || result.naruto_runtime?.work_item_kind,
1336
+ regression_proof: result.regression_proof,
1337
+ repair_hypothesis: result.repair_hypothesis
1338
+ });
1134
1339
  result.patch_queue_refs = [...(result.patch_queue_refs || []), entry.id];
1135
1340
  }
1136
1341
  }
@@ -1162,14 +1367,14 @@ async function runAgentPatchSwarmRuntime(root, ledgerRoot, input) {
1162
1367
  }
1163
1368
  const disjointEntries = normalEntries.filter((entry) => !conflictedEntryIds.has(entry.id));
1164
1369
  const startedAt = nowIso();
1370
+ await queueStore.markApplyingBatch([...rebaseSucceededEntryIds]);
1165
1371
  for (const entryId of rebaseSucceededEntryIds) {
1166
- await queueStore.markApplying(entryId);
1167
1372
  await queueStore.markApplied(entryId);
1168
1373
  }
1169
1374
  const rebaseApplyEntryIds = new Set((conflictRebase.apply_results || []).map((row) => String(row.entry_id || '')));
1170
1375
  const parallelEntries = disjointEntries.filter((entry) => !rebaseApplyEntryIds.has(entry.id));
1376
+ await queueStore.markApplyingBatch(parallelEntries.map((entry) => entry.id));
1171
1377
  const parallelApplyResults = await Promise.all(parallelEntries.map(async (entry) => {
1172
- await queueStore.markApplying(entry.id);
1173
1378
  const started_at = nowIso();
1174
1379
  const applyResult = await applyAgentPatchQueueEntry(root, entry, { dryRun: input.dryRun, artifactsDir: ledgerRoot });
1175
1380
  const finished_at = nowIso();
@@ -1192,6 +1397,14 @@ async function runAgentPatchSwarmRuntime(root, ledgerRoot, input) {
1192
1397
  ...parallelApplyResults,
1193
1398
  ...(conflictRebase.apply_results || []).map((row) => ({ entry_id: row.entry_id, started_at: row.apply_started_at || nowIso(), finished_at: row.apply_ended_at || nowIso(), ...row }))
1194
1399
  ];
1400
+ if (input.dryRun !== true && applyResults.some((result) => result.ok === true && Array.isArray(result.changed_files) && result.changed_files.length > 0)) {
1401
+ await setCurrent(root, {
1402
+ mission_id: input.missionId,
1403
+ reflection_invalidation_required: true,
1404
+ reflection_invalidated_at: nowIso(),
1405
+ reflection_invalidation_reason: 'agent_patch_applied'
1406
+ }, { sessionKey: input.sessionKey });
1407
+ }
1195
1408
  const finishedAt = nowIso();
1196
1409
  const entryById = new Map(queueStore.queue.entries.map((entry) => [entry.id, entry]));
1197
1410
  const verificationResults = {
@@ -1416,8 +1629,7 @@ async function runGitWorktreeIntegrationPrimary(root, ledgerRoot, missionId, ent
1416
1629
  return blockedReport;
1417
1630
  }
1418
1631
  const startedAt = nowIso();
1419
- for (const entry of entries)
1420
- await queueStore.markApplying(entry.id);
1632
+ await queueStore.markApplyingBatch(entries.map((entry) => entry.id));
1421
1633
  const queueReport = await applyGitWorktreeMergeQueue({
1422
1634
  integrationWorktreePath: integration.worktree_path,
1423
1635
  diffs,
@@ -1732,6 +1944,7 @@ async function runAgentByBackend(backend, agent, slice, opts) {
1732
1944
  model: agent.model || null,
1733
1945
  reasoningEffort: agent.reasoning_effort || null,
1734
1946
  modelReasoningEffort: agent.model_reasoning_effort || agent.reasoning_effort || null,
1947
+ serviceTier: agent.service_tier || opts.serviceTier || 'fast',
1735
1948
  inputFiles: Array.isArray(opts.inputFiles) ? opts.inputFiles.map(String) : [],
1736
1949
  inputImages: Array.isArray(opts.inputImages) ? opts.inputImages.map(String) : [],
1737
1950
  outputSchemaId: CODEX_AGENT_WORKER_RESULT_SCHEMA_ID,
@@ -1823,9 +2036,11 @@ function buildDirectSdkWorkerPrompt(slice) {
1823
2036
  const write = sdkWritePaths(slice, {});
1824
2037
  return [
1825
2038
  String(slice?.description || slice?.title || 'Complete the assigned worker task.'),
2039
+ slice?.work_item_kind ? `Work item kind: ${String(slice.work_item_kind)}.` : '',
2040
+ slice?.approach_directive ? `Solution tournament candidate directive: ${String(slice.approach_directive)}.` : '',
1826
2041
  '',
1827
2042
  write.length
1828
- ? `Write-capable slice. Return JSON matching ${CODEX_AGENT_WORKER_RESULT_SCHEMA_ID}; include patch_envelopes for write_paths=${JSON.stringify(write)}. Each patch envelope must include schema, source "model_authored", agent_id, session_id, slot_id, generation_index, task_slice_id, lease_id, allowed_paths, operations, and rationale. Each operation must include op, path, search, replace, content, and diff; use empty strings for operation fields that do not apply.`
2043
+ ? `Write-capable slice. Return JSON matching ${CODEX_AGENT_WORKER_RESULT_SCHEMA_ID}; include patch_envelopes for write_paths=${JSON.stringify(write)}. Each patch envelope must include schema, source "model_authored", agent_id, session_id, slot_id, generation_index, task_slice_id, lease_id, allowed_paths, operations, and rationale. Each operation must include op, path, search, replace, content, and diff; use empty strings for operation fields that do not apply. Impact-scan, machine-feedback, diff-quality, and mistake-rule gates run before queue acceptance; exported signature changes require cochanged callers or cochange_acknowledged_reason. Bugfixes require regression_proof failed_before true and passed_after true; repair patches require repair_hypothesis.`
1829
2044
  : `Read-only slice. Return JSON matching ${CODEX_AGENT_WORKER_RESULT_SCHEMA_ID}; inspect relevant files/artifacts, do not mutate files, do not create temporary/build outputs, do not run package scripts/build/test commands unless explicitly required, and do not report pre-existing repository dirtiness as changed_files.`,
1830
2045
  'Required JSON fields: status, summary, findings, changed_files, patch_envelopes, verification, rollback_notes, blockers.'
1831
2046
  ].join('\n');
@@ -32,6 +32,7 @@ export const AGENT_RESULT_RUNTIME_SCHEMA = {
32
32
  session_id: { type: 'string', minLength: 1 },
33
33
  persona_id: { type: 'string' },
34
34
  task_slice_id: { type: 'string' },
35
+ work_item_kind: { type: 'string' },
35
36
  status: { enum: ['done', 'blocked', 'failed'] },
36
37
  backend: { enum: ['fake', 'process', 'codex-sdk', 'python-codex-sdk', 'zellij', 'ollama', 'local-llm'] },
37
38
  summary: { type: 'string' },
@@ -78,7 +79,7 @@ export const AGENT_RESULT_RUNTIME_SCHEMA = {
78
79
  required: ['schema', 'agent_id', 'session_id', 'slot_id', 'generation_index', 'operations'],
79
80
  properties: {
80
81
  schema: { const: 'sks.agent-patch-envelope.v1' },
81
- source: { enum: ['fixture', 'model_authored', 'process_generated', 'zellij_generated'] },
82
+ source: { enum: ['fixture', 'model_authored', 'process_generated', 'zellij_generated', 'git-worktree-diff'] },
82
83
  mission_id: { type: 'string' },
83
84
  route: { type: 'string' },
84
85
  agent_id: { type: 'string', minLength: 1 },
@@ -123,7 +124,7 @@ export const AGENT_RESULT_RUNTIME_SCHEMA = {
123
124
  type: 'object',
124
125
  required: ['op', 'path'],
125
126
  properties: {
126
- op: { enum: ['replace', 'write', 'unified_diff'] },
127
+ op: { enum: ['replace', 'write', 'unified_diff', 'git_apply_patch'] },
127
128
  path: { type: 'string', minLength: 1 },
128
129
  search: { type: 'string' },
129
130
  replace: { type: 'string' },
@@ -135,7 +136,13 @@ export const AGENT_RESULT_RUNTIME_SCHEMA = {
135
136
  },
136
137
  rationale: { type: 'string' },
137
138
  verification_hint: { type: 'object', additionalProperties: { type: 'string' } },
138
- rollback_hint: { type: 'object', additionalProperties: { type: 'string' } }
139
+ rollback_hint: { type: 'object', additionalProperties: { type: 'string' } },
140
+ cochange_acknowledged: { type: 'boolean' },
141
+ cochange_acknowledged_reason: { type: 'string' },
142
+ regression_proof: { type: 'object', additionalProperties: true },
143
+ repair_hypothesis: { type: 'object', additionalProperties: true },
144
+ tournament: { type: 'object', additionalProperties: true },
145
+ git_worktree: { type: 'object', additionalProperties: true }
139
146
  },
140
147
  additionalProperties: false
141
148
  }
@@ -151,6 +158,10 @@ export const AGENT_RESULT_RUNTIME_SCHEMA = {
151
158
  model_authored_patch_envelopes: { type: 'boolean' },
152
159
  fixture_patch_envelopes: { type: 'boolean' },
153
160
  no_patch_reason: { type: 'object', additionalProperties: true },
161
+ machine_feedback: { type: 'object', additionalProperties: true },
162
+ regression_proof: { type: 'object', additionalProperties: true },
163
+ repair_hypothesis: { type: 'object', additionalProperties: true },
164
+ tournament: { type: 'object', additionalProperties: true },
154
165
  follow_up_work_items: {
155
166
  type: 'array',
156
167
  items: {