zob-harness 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (356) hide show
  1. package/.pi/adapters/registry.json +103 -0
  2. package/.pi/agents/architecture-cartographer.md +53 -0
  3. package/.pi/agents/chief-vision.md +39 -0
  4. package/.pi/agents/clarifier.md +58 -0
  5. package/.pi/agents/context-steward.md +52 -0
  6. package/.pi/agents/doc-steward.md +34 -0
  7. package/.pi/agents/explore.md +49 -0
  8. package/.pi/agents/factory.md +41 -0
  9. package/.pi/agents/implementer.md +44 -0
  10. package/.pi/agents/librarian.md +32 -0
  11. package/.pi/agents/oracle-merge.md +50 -0
  12. package/.pi/agents/oracle.md +55 -0
  13. package/.pi/agents/pattern-miner.md +53 -0
  14. package/.pi/agents/planner.md +39 -0
  15. package/.pi/agents/project-dna-golden-evaluator.md +32 -0
  16. package/.pi/agents/project-dna-ontology-steward.md +30 -0
  17. package/.pi/agents/project-dna-oracle.md +56 -0
  18. package/.pi/agents/project-dna-orchestrator.md +60 -0
  19. package/.pi/agents/project-dna-query-steward.md +38 -0
  20. package/.pi/agents/project-dna-safety-preflight.md +54 -0
  21. package/.pi/agents/project-dna-test-linker.md +27 -0
  22. package/.pi/agents/qa.md +38 -0
  23. package/.pi/agents/refactor-cartographer.md +28 -0
  24. package/.pi/agents/refactor-mover.md +31 -0
  25. package/.pi/agents/refactor-oracle.md +49 -0
  26. package/.pi/agents/repo-scout.md +60 -0
  27. package/.pi/agents/sample-architect.md +48 -0
  28. package/.pi/agents/specifier.md +57 -0
  29. package/.pi/agents/symbol-range-curator.md +41 -0
  30. package/.pi/agents/synthesis.md +52 -0
  31. package/.pi/agents/temp-agent-creator.md +35 -0
  32. package/.pi/autonomy-policy.json +67 -0
  33. package/.pi/budget-policy.json +54 -0
  34. package/.pi/capabilities/zob-public-runtime-capabilities.json +1700 -0
  35. package/.pi/chains/explore-plan-oracle.json +78 -0
  36. package/.pi/chains/explore-spec-clarify-plan-oracle.json +64 -0
  37. package/.pi/chains/explore-spec-plan-oracle.json +53 -0
  38. package/.pi/chains/spec-clarify-plan-oracle.json +53 -0
  39. package/.pi/chains/spec-factory-oracle.json +42 -0
  40. package/.pi/chains/spec-plan-oracle.json +42 -0
  41. package/.pi/compute-profiles/defaults.json +19 -0
  42. package/.pi/compute-profiles/overrides.json +13 -0
  43. package/.pi/compute-profiles/risk-rules.json +16 -0
  44. package/.pi/daemon-policy.json +80 -0
  45. package/.pi/damage-control-rules.json +45 -0
  46. package/.pi/extensions/zob-child-safety/index.ts +212 -0
  47. package/.pi/extensions/zob-harness/AGENTS.md +28 -0
  48. package/.pi/extensions/zob-harness/index.ts +391 -0
  49. package/.pi/extensions/zob-harness/src/AGENTS.md +25 -0
  50. package/.pi/extensions/zob-harness/src/agents.ts +82 -0
  51. package/.pi/extensions/zob-harness/src/autonomous-runtime.ts +2912 -0
  52. package/.pi/extensions/zob-harness/src/autonomy-readiness.ts +778 -0
  53. package/.pi/extensions/zob-harness/src/budget-policy.ts +308 -0
  54. package/.pi/extensions/zob-harness/src/capabilities.ts +249 -0
  55. package/.pi/extensions/zob-harness/src/child-runner.ts +249 -0
  56. package/.pi/extensions/zob-harness/src/chronicle.ts +262 -0
  57. package/.pi/extensions/zob-harness/src/compute-profile.ts +602 -0
  58. package/.pi/extensions/zob-harness/src/compute-workflow-shape.ts +168 -0
  59. package/.pi/extensions/zob-harness/src/coms-v2/AGENTS.md +16 -0
  60. package/.pi/extensions/zob-harness/src/coms-v2/envelope.ts +121 -0
  61. package/.pi/extensions/zob-harness/src/coms-v2/identity.ts +53 -0
  62. package/.pi/extensions/zob-harness/src/coms-v2/ledger-bridge.ts +67 -0
  63. package/.pi/extensions/zob-harness/src/coms-v2/local-transport.ts +147 -0
  64. package/.pi/extensions/zob-harness/src/coms-v2/pending-replies.ts +80 -0
  65. package/.pi/extensions/zob-harness/src/coms-v2/policy.ts +125 -0
  66. package/.pi/extensions/zob-harness/src/coms-v2/presence.ts +55 -0
  67. package/.pi/extensions/zob-harness/src/coms-v2/registry.ts +113 -0
  68. package/.pi/extensions/zob-harness/src/coms-v2/response-capture.ts +50 -0
  69. package/.pi/extensions/zob-harness/src/coms-v2/transcript-capture.ts +164 -0
  70. package/.pi/extensions/zob-harness/src/coms-v2/types.ts +149 -0
  71. package/.pi/extensions/zob-harness/src/coms-v2/zpeer-profile.ts +140 -0
  72. package/.pi/extensions/zob-harness/src/coms-v2/zpeer.ts +452 -0
  73. package/.pi/extensions/zob-harness/src/constants.ts +108 -0
  74. package/.pi/extensions/zob-harness/src/context-gbrain.ts +465 -0
  75. package/.pi/extensions/zob-harness/src/daemon-policy.ts +223 -0
  76. package/.pi/extensions/zob-harness/src/daemon-readiness.ts +134 -0
  77. package/.pi/extensions/zob-harness/src/daemon-runtime.ts +393 -0
  78. package/.pi/extensions/zob-harness/src/factory/AGENTS.md +24 -0
  79. package/.pi/extensions/zob-harness/src/factory/agentic-plan.ts +65 -0
  80. package/.pi/extensions/zob-harness/src/factory/quarantine.ts +319 -0
  81. package/.pi/extensions/zob-harness/src/factory/run.ts +520 -0
  82. package/.pi/extensions/zob-harness/src/factory/validation.ts +454 -0
  83. package/.pi/extensions/zob-harness/src/factory-selector.ts +318 -0
  84. package/.pi/extensions/zob-harness/src/full-autonomy-test.ts +226 -0
  85. package/.pi/extensions/zob-harness/src/git-ops.ts +868 -0
  86. package/.pi/extensions/zob-harness/src/goal-room.ts +178 -0
  87. package/.pi/extensions/zob-harness/src/goal-runtime.ts +1569 -0
  88. package/.pi/extensions/zob-harness/src/goal-todo-imports.ts +111 -0
  89. package/.pi/extensions/zob-harness/src/goal-todo-types.ts +231 -0
  90. package/.pi/extensions/zob-harness/src/goal-todos.ts +1410 -0
  91. package/.pi/extensions/zob-harness/src/goal.ts +152 -0
  92. package/.pi/extensions/zob-harness/src/governed-requests.ts +436 -0
  93. package/.pi/extensions/zob-harness/src/interactive-autonomy.ts +595 -0
  94. package/.pi/extensions/zob-harness/src/launch-apply.ts +313 -0
  95. package/.pi/extensions/zob-harness/src/merge-queue.ts +290 -0
  96. package/.pi/extensions/zob-harness/src/mission-control.ts +573 -0
  97. package/.pi/extensions/zob-harness/src/model-availability.ts +52 -0
  98. package/.pi/extensions/zob-harness/src/model-routing.ts +429 -0
  99. package/.pi/extensions/zob-harness/src/orchestration/AGENTS.md +23 -0
  100. package/.pi/extensions/zob-harness/src/orchestration/adaptive-delegation.ts +547 -0
  101. package/.pi/extensions/zob-harness/src/orchestration/adaptive-workflow.ts +585 -0
  102. package/.pi/extensions/zob-harness/src/orchestration/lead-plan.ts +192 -0
  103. package/.pi/extensions/zob-harness/src/orchestration/plan.ts +168 -0
  104. package/.pi/extensions/zob-harness/src/orchestration/room.ts +346 -0
  105. package/.pi/extensions/zob-harness/src/orchestration/run.ts +134 -0
  106. package/.pi/extensions/zob-harness/src/orchestration/supervised-readonly.ts +1147 -0
  107. package/.pi/extensions/zob-harness/src/orchestration/widget-readers.ts +132 -0
  108. package/.pi/extensions/zob-harness/src/output-contracts.ts +656 -0
  109. package/.pi/extensions/zob-harness/src/project-dna.ts +533 -0
  110. package/.pi/extensions/zob-harness/src/promotion/AGENTS.md +24 -0
  111. package/.pi/extensions/zob-harness/src/promotion/candidate.ts +336 -0
  112. package/.pi/extensions/zob-harness/src/promotion/coms.ts +127 -0
  113. package/.pi/extensions/zob-harness/src/promotion/documentation.ts +142 -0
  114. package/.pi/extensions/zob-harness/src/promotion/factory.ts +107 -0
  115. package/.pi/extensions/zob-harness/src/promotion/ledger.ts +2 -0
  116. package/.pi/extensions/zob-harness/src/promotion/temp-agent.ts +151 -0
  117. package/.pi/extensions/zob-harness/src/promotion/types.ts +149 -0
  118. package/.pi/extensions/zob-harness/src/promotion/validate.ts +6 -0
  119. package/.pi/extensions/zob-harness/src/promotion/write-lane.ts +162 -0
  120. package/.pi/extensions/zob-harness/src/prompt-packs.ts +239 -0
  121. package/.pi/extensions/zob-harness/src/queue.ts +386 -0
  122. package/.pi/extensions/zob-harness/src/rules.ts +225 -0
  123. package/.pi/extensions/zob-harness/src/runtime/AGENTS.md +26 -0
  124. package/.pi/extensions/zob-harness/src/runtime/adaptive-zmode.ts +116 -0
  125. package/.pi/extensions/zob-harness/src/runtime/auto-compaction.ts +715 -0
  126. package/.pi/extensions/zob-harness/src/runtime/commands.ts +1315 -0
  127. package/.pi/extensions/zob-harness/src/runtime/compaction-policy.ts +516 -0
  128. package/.pi/extensions/zob-harness/src/runtime/delegation-click-markers.ts +141 -0
  129. package/.pi/extensions/zob-harness/src/runtime/delegation-feed.ts +415 -0
  130. package/.pi/extensions/zob-harness/src/runtime/delegation-markdown.ts +97 -0
  131. package/.pi/extensions/zob-harness/src/runtime/delegation-monitor.ts +553 -0
  132. package/.pi/extensions/zob-harness/src/runtime/delegation-mouse.ts +205 -0
  133. package/.pi/extensions/zob-harness/src/runtime/delegation-overlay.ts +434 -0
  134. package/.pi/extensions/zob-harness/src/runtime/events.ts +736 -0
  135. package/.pi/extensions/zob-harness/src/runtime/goal-todo-overlay.ts +214 -0
  136. package/.pi/extensions/zob-harness/src/runtime/mode-intent.ts +144 -0
  137. package/.pi/extensions/zob-harness/src/runtime/plan-capture.ts +270 -0
  138. package/.pi/extensions/zob-harness/src/runtime/state.ts +403 -0
  139. package/.pi/extensions/zob-harness/src/runtime/tools-autonomous.ts +117 -0
  140. package/.pi/extensions/zob-harness/src/runtime/tools-compute.ts +136 -0
  141. package/.pi/extensions/zob-harness/src/runtime/tools-coms.ts +365 -0
  142. package/.pi/extensions/zob-harness/src/runtime/tools-context.ts +70 -0
  143. package/.pi/extensions/zob-harness/src/runtime/tools-delegation.ts +1854 -0
  144. package/.pi/extensions/zob-harness/src/runtime/tools-factory.ts +810 -0
  145. package/.pi/extensions/zob-harness/src/runtime/tools-goal-room.ts +46 -0
  146. package/.pi/extensions/zob-harness/src/runtime/tools-governed-requests.ts +38 -0
  147. package/.pi/extensions/zob-harness/src/runtime/tools-merge-queue.ts +61 -0
  148. package/.pi/extensions/zob-harness/src/runtime/tools-mission-control.ts +77 -0
  149. package/.pi/extensions/zob-harness/src/runtime/tools-orchestration.ts +106 -0
  150. package/.pi/extensions/zob-harness/src/runtime/tools-project-dna.ts +123 -0
  151. package/.pi/extensions/zob-harness/src/runtime/tools-worker-pool.ts +93 -0
  152. package/.pi/extensions/zob-harness/src/runtime/tools-workspace-claims.ts +62 -0
  153. package/.pi/extensions/zob-harness/src/runtime/tools-zcommit.ts +147 -0
  154. package/.pi/extensions/zob-harness/src/runtime/widget.ts +353 -0
  155. package/.pi/extensions/zob-harness/src/runtime/zobHarness.ts +60 -0
  156. package/.pi/extensions/zob-harness/src/safety.ts +338 -0
  157. package/.pi/extensions/zob-harness/src/sandbox.ts +1508 -0
  158. package/.pi/extensions/zob-harness/src/schemas-project-dna.ts +47 -0
  159. package/.pi/extensions/zob-harness/src/schemas.ts +695 -0
  160. package/.pi/extensions/zob-harness/src/telemetry.ts +373 -0
  161. package/.pi/extensions/zob-harness/src/topology/AGENTS.md +22 -0
  162. package/.pi/extensions/zob-harness/src/topology/chains.ts +236 -0
  163. package/.pi/extensions/zob-harness/src/topology/coms.ts +211 -0
  164. package/.pi/extensions/zob-harness/src/topology/orchestration-profiles.ts +204 -0
  165. package/.pi/extensions/zob-harness/src/topology/teams.ts +113 -0
  166. package/.pi/extensions/zob-harness/src/types/core.ts +47 -0
  167. package/.pi/extensions/zob-harness/src/types.ts +939 -0
  168. package/.pi/extensions/zob-harness/src/utils/AGENTS.md +22 -0
  169. package/.pi/extensions/zob-harness/src/utils/formatting.ts +34 -0
  170. package/.pi/extensions/zob-harness/src/utils/hashing.ts +11 -0
  171. package/.pi/extensions/zob-harness/src/utils/json.ts +28 -0
  172. package/.pi/extensions/zob-harness/src/utils/paths.ts +54 -0
  173. package/.pi/extensions/zob-harness/src/utils/records.ts +25 -0
  174. package/.pi/extensions/zob-harness/src/utils/resources.ts +38 -0
  175. package/.pi/extensions/zob-harness/src/worker-pool.ts +672 -0
  176. package/.pi/extensions/zob-harness/src/workspace-claims.ts +297 -0
  177. package/.pi/extensions/zob-switch/index.ts +180 -0
  178. package/.pi/factories/budget-preflight-dry-run/batch-manifest.json +59 -0
  179. package/.pi/factories/budget-preflight-dry-run/factory.json +94 -0
  180. package/.pi/factories/budget-preflight-dry-run/pilot-manifest.json +50 -0
  181. package/.pi/factories/budget-preflight-dry-run/smoke-manifest.json +43 -0
  182. package/.pi/factories/code-review-matrix/batch-manifest.json +61 -0
  183. package/.pi/factories/code-review-matrix/factory.json +163 -0
  184. package/.pi/factories/code-review-matrix/pilot-manifest.json +41 -0
  185. package/.pi/factories/code-review-matrix/smoke-manifest.json +35 -0
  186. package/.pi/factories/factory-forge/batch-manifest.json +56 -0
  187. package/.pi/factories/factory-forge/factory.json +84 -0
  188. package/.pi/factories/factory-forge/pilot-manifest.json +32 -0
  189. package/.pi/factories/factory-forge/smoke-manifest.json +19 -0
  190. package/.pi/factories/opencode-pattern-canonizer/batch-manifest.json +54 -0
  191. package/.pi/factories/opencode-pattern-canonizer/factory.json +86 -0
  192. package/.pi/factories/opencode-pattern-canonizer/pilot-manifest.json +39 -0
  193. package/.pi/factories/opencode-pattern-canonizer/smoke-manifest.json +26 -0
  194. package/.pi/factories/project-dna/README.md +182 -0
  195. package/.pi/factories/project-dna/batch-manifest.json +37 -0
  196. package/.pi/factories/project-dna/example-project-dna-manifest-v2.json +80 -0
  197. package/.pi/factories/project-dna/example-project-dna-manifest.json +58 -0
  198. package/.pi/factories/project-dna/factory.json +131 -0
  199. package/.pi/factories/project-dna/golden-cases-smoke.json +62 -0
  200. package/.pi/factories/project-dna/pi-agentic-ontology.json +88 -0
  201. package/.pi/factories/project-dna/pilot-manifest.json +32 -0
  202. package/.pi/factories/project-dna/schemas/benchmark-suite.schema.json +27 -0
  203. package/.pi/factories/project-dna/schemas/code-knowledge-graph.schema.json +97 -0
  204. package/.pi/factories/project-dna/schemas/context-pack.schema.json +43 -0
  205. package/.pi/factories/project-dna/schemas/golden-case.schema.json +36 -0
  206. package/.pi/factories/project-dna/schemas/manifest-v2.schema.json +128 -0
  207. package/.pi/factories/project-dna/schemas/manifest.schema.json +77 -0
  208. package/.pi/factories/project-dna/schemas/ontology.schema.json +45 -0
  209. package/.pi/factories/project-dna/schemas/project-fingerprint.schema.json +28 -0
  210. package/.pi/factories/project-dna/schemas/query-steward-report.schema.json +52 -0
  211. package/.pi/factories/project-dna/smoke-manifest.json +27 -0
  212. package/.pi/factories/roadmap-smoke-lots/batch-manifest.json +49 -0
  213. package/.pi/factories/roadmap-smoke-lots/factory.json +89 -0
  214. package/.pi/factories/roadmap-smoke-lots/pilot-manifest.json +50 -0
  215. package/.pi/factories/roadmap-smoke-lots/smoke-manifest.json +35 -0
  216. package/.pi/git-policy.json +120 -0
  217. package/.pi/mission-control/zob_coms_transport.json +64 -0
  218. package/.pi/model-catalog.example.json +345 -0
  219. package/.pi/model-economy.example.json +196 -0
  220. package/.pi/model-routing.json +86 -0
  221. package/.pi/orchestrations/adaptive-chief-vision.json +193 -0
  222. package/.pi/orchestrations/ceo-feature-build.json +182 -0
  223. package/.pi/orchestrations/readonly-dynamic-smoke.json +75 -0
  224. package/.pi/output-contracts/agent-event.v1.json +19 -0
  225. package/.pi/output-contracts/base.v1.json +24 -0
  226. package/.pi/output-contracts/brain-lookup.v1.json +21 -0
  227. package/.pi/output-contracts/clarification.v1.json +21 -0
  228. package/.pi/output-contracts/context-pack.v1.json +20 -0
  229. package/.pi/output-contracts/context-request.v1.json +21 -0
  230. package/.pi/output-contracts/context-steward.v1.json +19 -0
  231. package/.pi/output-contracts/context-writeback-proposal.v1.json +18 -0
  232. package/.pi/output-contracts/delegation-request.v1.json +21 -0
  233. package/.pi/output-contracts/explore.v1.json +52 -0
  234. package/.pi/output-contracts/factory.v1.json +48 -0
  235. package/.pi/output-contracts/guidance-steward.v1.json +18 -0
  236. package/.pi/output-contracts/implement.v1.json +40 -0
  237. package/.pi/output-contracts/launch-authorization.v1.json +21 -0
  238. package/.pi/output-contracts/lead-plan.v1.json +22 -0
  239. package/.pi/output-contracts/mission-readiness.v1.json +20 -0
  240. package/.pi/output-contracts/oracle-merge.v1.json +44 -0
  241. package/.pi/output-contracts/oracle-request.v1.json +20 -0
  242. package/.pi/output-contracts/oracle.v1.json +44 -0
  243. package/.pi/output-contracts/orchestration-profile.v1.json +22 -0
  244. package/.pi/output-contracts/plan.v1.json +48 -0
  245. package/.pi/output-contracts/prompt-pack.v1.json +20 -0
  246. package/.pi/output-contracts/qa.v1.json +40 -0
  247. package/.pi/output-contracts/research.v1.json +36 -0
  248. package/.pi/output-contracts/spec.v1.json +22 -0
  249. package/.pi/output-contracts/synthesis.v1.json +44 -0
  250. package/.pi/output-contracts/temp-agent-card.v1.json +23 -0
  251. package/.pi/output-contracts/todo-child-result.v1.json +20 -0
  252. package/.pi/output-contracts/todo-child-result.v2.json +22 -0
  253. package/.pi/output-contracts/todo-claim-validation.v1.json +22 -0
  254. package/.pi/output-contracts/todo-split-request.v1.json +20 -0
  255. package/.pi/prompts/adaptive-workflow.md +63 -0
  256. package/.pi/prompts/autonomous-runtime.md +15 -0
  257. package/.pi/prompts/benchmark-contender.md +15 -0
  258. package/.pi/prompts/benchmark-judge.md +19 -0
  259. package/.pi/prompts/clarify-spec.md +20 -0
  260. package/.pi/prompts/compute-plan.md +36 -0
  261. package/.pi/prompts/compute-preview.md +42 -0
  262. package/.pi/prompts/contract.md +29 -0
  263. package/.pi/prompts/explore.md +13 -0
  264. package/.pi/prompts/factory-run.md +36 -0
  265. package/.pi/prompts/factory.md +20 -0
  266. package/.pi/prompts/implement.md +27 -0
  267. package/.pi/prompts/model-catalog.md +68 -0
  268. package/.pi/prompts/model-economy.md +64 -0
  269. package/.pi/prompts/oracle-merge.md +18 -0
  270. package/.pi/prompts/oracle.md +13 -0
  271. package/.pi/prompts/orchestrator.md +48 -0
  272. package/.pi/prompts/parallel-review.md +21 -0
  273. package/.pi/prompts/plan.md +21 -0
  274. package/.pi/prompts/project-dna.md +90 -0
  275. package/.pi/prompts/refactor-oracle.md +23 -0
  276. package/.pi/prompts/refactor-slice.md +24 -0
  277. package/.pi/prompts/research.md +20 -0
  278. package/.pi/prompts/spec.md +19 -0
  279. package/.pi/prompts/synthesis.md +18 -0
  280. package/.pi/rules/always.md +38 -0
  281. package/.pi/rules/docs.md +32 -0
  282. package/.pi/rules/factory.md +44 -0
  283. package/.pi/rules/oracle.md +34 -0
  284. package/.pi/rules/orchestration.md +44 -0
  285. package/.pi/rules/project.md +34 -0
  286. package/.pi/rules/prompts.md +43 -0
  287. package/.pi/rules/runtime.md +43 -0
  288. package/.pi/rules/sandbox.md +43 -0
  289. package/.pi/settings.json +28 -0
  290. package/.pi/skills/zob-agentic-access/SKILL.md +20 -0
  291. package/.pi/skills/zob-autonomous-runtime/SKILL.md +41 -0
  292. package/.pi/skills/zob-commit/SKILL.md +79 -0
  293. package/.pi/skills/zob-compaction-policy/SKILL.md +92 -0
  294. package/.pi/skills/zob-compute-profile/SKILL.md +108 -0
  295. package/.pi/skills/zob-coms-safety/SKILL.md +54 -0
  296. package/.pi/skills/zob-coms-v2-live/SKILL.md +47 -0
  297. package/.pi/skills/zob-delegation-routing/SKILL.md +82 -0
  298. package/.pi/skills/zob-factory/SKILL.md +28 -0
  299. package/.pi/skills/zob-goal-todo-tree/SKILL.md +279 -0
  300. package/.pi/skills/zob-harness/SKILL.md +68 -0
  301. package/.pi/skills/zob-mission-control-coms/SKILL.md +39 -0
  302. package/.pi/skills/zob-oracle/SKILL.md +21 -0
  303. package/.pi/skills/zob-owner-pool-drill-writer/SKILL.md +244 -0
  304. package/.pi/skills/zob-owner-pool-launcher/SKILL.md +261 -0
  305. package/.pi/skills/zob-project-dna/SKILL.md +275 -0
  306. package/.pi/skills/zob-sandbox/SKILL.md +29 -0
  307. package/.pi/skills/zob-spec/SKILL.md +25 -0
  308. package/.pi/skills/zob-split-refactor/SKILL.md +39 -0
  309. package/.pi/skills/zob-tool-router/SKILL.md +104 -0
  310. package/.pi/teams/zob-core.json +122 -0
  311. package/AGENTS.md +89 -0
  312. package/CONTRIBUTING.md +56 -0
  313. package/LICENSE +21 -0
  314. package/README.md +360 -0
  315. package/SECURITY.md +35 -0
  316. package/SOURCE_INDEX.md +46 -0
  317. package/package.json +135 -0
  318. package/scripts/README.md +57 -0
  319. package/scripts/autonomy/mission-readiness-secret-smoke.mjs +90 -0
  320. package/scripts/compute-profile/plan-workflow.mjs +85 -0
  321. package/scripts/compute-profile/preview.mjs +242 -0
  322. package/scripts/compute-profile/regression-smoke.mjs +38 -0
  323. package/scripts/compute-profile/summarize.mjs +72 -0
  324. package/scripts/compute-profile/validate-policy.mjs +50 -0
  325. package/scripts/compute-profile/validate-preview.mjs +95 -0
  326. package/scripts/compute-profile/validate-workflow.mjs +58 -0
  327. package/scripts/git-ops/commit-policy-smoke.mjs +221 -0
  328. package/scripts/goal-todo/child-goal-ref-smoke.mjs +252 -0
  329. package/scripts/harness-switch/static-smoke.mjs +43 -0
  330. package/scripts/model-catalog/validate-economy.mjs +223 -0
  331. package/scripts/model-catalog/validate.mjs +199 -0
  332. package/scripts/package-surface/validate-script-refs.mjs +190 -0
  333. package/scripts/path-policy/validate-smoke.mjs +103 -0
  334. package/scripts/project-dna/bench-smoke.mjs +217 -0
  335. package/scripts/project-dna/build-capsules.mjs +207 -0
  336. package/scripts/project-dna/build-sample-spec.mjs +140 -0
  337. package/scripts/project-dna/emit-golden-cases.mjs +75 -0
  338. package/scripts/project-dna/emit-ontology.mjs +75 -0
  339. package/scripts/project-dna/generate-sample.mjs +302 -0
  340. package/scripts/project-dna/oracle-review-smoke.mjs +157 -0
  341. package/scripts/project-dna/plan-workflow.mjs +289 -0
  342. package/scripts/project-dna/query-context.mjs +276 -0
  343. package/scripts/project-dna/query-steward.mjs +149 -0
  344. package/scripts/project-dna/scan.mjs +553 -0
  345. package/scripts/project-dna/validate-5of5.mjs +159 -0
  346. package/scripts/project-dna/validate-golden-cases.mjs +78 -0
  347. package/scripts/project-dna/validate-ontology.mjs +97 -0
  348. package/scripts/project-dna/validate-sample-project.mjs +105 -0
  349. package/scripts/project-dna/validate-scaffold.mjs +383 -0
  350. package/scripts/project-dna/validate-scan-artifacts.mjs +187 -0
  351. package/scripts/project-dna/validate-workflow.mjs +166 -0
  352. package/scripts/start-pi.sh +4 -0
  353. package/scripts/worker-pool/static-smoke.mjs +54 -0
  354. package/scripts/zpeer-local-e2e-smoke.mjs +395 -0
  355. package/scripts/zpeer-static-smoke.mjs +129 -0
  356. package/tsconfig.json +12 -0
@@ -0,0 +1,313 @@
1
+ import { DEFAULT_RULES } from "./constants.js";
2
+ import { sha256 } from "./utils/hashing.js";
3
+ import { pathMatches, resolveRepoPath, safeFileStem } from "./utils/paths.js";
4
+ import { isRecord } from "./utils/records.js";
5
+
6
+ export type WorkerPoolLaneKind = "context" | "factory" | "implement" | "qa" | "oracle";
7
+ export type ApplyGateStatus = "eligible_not_applied" | "blocked";
8
+
9
+ export interface ControlledWorkerPoolLane {
10
+ laneId: string;
11
+ kind: WorkerPoolLaneKind;
12
+ maxWorkers: number;
13
+ parentOwnedDispatch: true;
14
+ childDirectDispatch: false;
15
+ workspaceClaimRequired: true;
16
+ goalRoomEventsRequired: true;
17
+ todoClaimReducerRequired: true;
18
+ outputContract: string;
19
+ }
20
+
21
+ export interface ControlledWorkerPoolPlan {
22
+ schema: "zob.controlled-worker-pool-plan.v1";
23
+ runId: string;
24
+ maxParallelWorkers: number;
25
+ launchAuthorizationRequired: true;
26
+ strictBudgetRequired: true;
27
+ workerPoolEnabledByLaunch: boolean;
28
+ lanes: ControlledWorkerPoolLane[];
29
+ l5ControlledWorkerPool: true;
30
+ parentOwnedDispatch: true;
31
+ childDirectDispatch: false;
32
+ eventContract: "agent-event.v1";
33
+ todoReducerContract: "zob.todo-event-reducer-decision.v1";
34
+ bodyStored: false;
35
+ promptBodiesStored: false;
36
+ outputBodiesStored: false;
37
+ }
38
+
39
+ export interface LaunchAuthorizedApplyInput {
40
+ runId: string;
41
+ launchAuthorization: Record<string, unknown>;
42
+ changedPaths: string[];
43
+ allowedPaths?: string[];
44
+ forbiddenPaths?: string[];
45
+ diffHash: string;
46
+ sandboxRunId?: string;
47
+ oracleReviewRef?: string;
48
+ validationRefs?: string[];
49
+ workerPoolPlan?: ControlledWorkerPoolPlan;
50
+ }
51
+
52
+ export interface LaunchAuthorizedApplyGate {
53
+ schema: "zob.launch-authorized-apply-gate.v1";
54
+ runId: string;
55
+ status: ApplyGateStatus;
56
+ applyEligible: boolean;
57
+ autoApplyAuthorizedByLaunch: boolean;
58
+ manualPerActionApprovalRequired: false;
59
+ exceptionApprovalRequiredOnlyForOutOfScope: true;
60
+ applyPerformed: false;
61
+ productionWritesPerformed: false;
62
+ changedPaths: string[];
63
+ changedPathHashes: string[];
64
+ diffHash: string;
65
+ sandboxRunIdHash?: string;
66
+ oracleReviewRef?: string;
67
+ validationRefs: string[];
68
+ gates: {
69
+ specLocked: boolean;
70
+ userLaunchConfirmed: boolean;
71
+ launchAuthorizesInScopeActions: boolean;
72
+ applyPolicyAutoApplyInScope: boolean;
73
+ workerPoolControlled: boolean;
74
+ changedPathsAllowed: boolean;
75
+ forbiddenPathsClear: boolean;
76
+ sandboxEvidencePresent: boolean;
77
+ oracleReviewPresent: boolean;
78
+ validationRefsPresent: boolean;
79
+ diffHashPresent: boolean;
80
+ };
81
+ blockers: string[];
82
+ l6LaunchAuthorizedApply: true;
83
+ parentOwnedApplyCoordinatorRequired: true;
84
+ rollbackRequired: true;
85
+ postApplyValidationRequired: true;
86
+ postApplyOracleRequired: true;
87
+ bodyStored: false;
88
+ promptBodiesStored: false;
89
+ outputBodiesStored: false;
90
+ }
91
+
92
+ export interface LaunchAuthorizedApplySmokeReport {
93
+ schema: "zob.launch-authorized-apply-smoke.v1";
94
+ status: "passed" | "failed";
95
+ workerPool: ControlledWorkerPoolPlan;
96
+ eligibleGate: LaunchAuthorizedApplyGate;
97
+ blockedGate: LaunchAuthorizedApplyGate;
98
+ checks: Array<{ name: string; passed: boolean }>;
99
+ failedChecks: string[];
100
+ no_ship: boolean;
101
+ bodyStored: false;
102
+ promptBodiesStored: false;
103
+ outputBodiesStored: false;
104
+ generatedAt: string;
105
+ }
106
+
107
+ const SHA256_HEX = /^[a-f0-9]{64}$/i;
108
+
109
+ function stableStrings(values: unknown): string[] {
110
+ return Array.isArray(values) ? values.filter((value): value is string => typeof value === "string" && value.trim().length > 0).map((value) => value.trim()).sort() : [];
111
+ }
112
+
113
+ function hashStrings(values: string[]): string[] {
114
+ return values.map((value) => sha256(value)).sort();
115
+ }
116
+
117
+ function launchApplyPolicyMode(launchAuthorization: Record<string, unknown>): string | undefined {
118
+ const applyPolicy = isRecord(launchAuthorization.applyPolicy) ? launchAuthorization.applyPolicy : undefined;
119
+ return typeof applyPolicy?.mode === "string" ? applyPolicy.mode : undefined;
120
+ }
121
+
122
+ function launchAllowedPaths(launchAuthorization: Record<string, unknown>, fallback: string[] | undefined): string[] {
123
+ return stableStrings(fallback && fallback.length > 0 ? fallback : launchAuthorization.allowedPaths);
124
+ }
125
+
126
+ function launchForbiddenPaths(launchAuthorization: Record<string, unknown>, fallback: string[] | undefined): string[] {
127
+ return stableStrings(fallback && fallback.length > 0 ? fallback : launchAuthorization.forbiddenPaths);
128
+ }
129
+
130
+ function pathAllowed(repoRoot: string, path: string, allowedPaths: string[]): boolean {
131
+ return allowedPaths.some((allowedPath) => pathMatches(path, allowedPath, repoRoot, repoRoot));
132
+ }
133
+
134
+ function pathForbidden(repoRoot: string, path: string, forbiddenPaths: string[]): boolean {
135
+ return [...DEFAULT_RULES.zeroAccessPaths, ...forbiddenPaths].some((forbiddenPath) => pathMatches(path, forbiddenPath, repoRoot, repoRoot));
136
+ }
137
+
138
+ function validateChangedPaths(repoRoot: string, changedPaths: string[], allowedPaths: string[], forbiddenPaths: string[]): { allowed: boolean; forbiddenClear: boolean; blockers: string[] } {
139
+ const blockers: string[] = [];
140
+ for (const changedPath of changedPaths) {
141
+ const resolved = resolveRepoPath(repoRoot, changedPath);
142
+ blockers.push(...resolved.errors.map((error) => `changed_path:${error}`));
143
+ if (resolved.errors.length === 0 && !pathAllowed(repoRoot, changedPath, allowedPaths)) blockers.push(`changed_path_not_allowed:${changedPath}`);
144
+ if (pathForbidden(repoRoot, changedPath, forbiddenPaths)) blockers.push(`changed_path_forbidden:${changedPath}`);
145
+ }
146
+ return {
147
+ allowed: changedPaths.length > 0 && blockers.every((blocker) => !blocker.startsWith("changed_path_not_allowed") && !blocker.startsWith("changed_path:Path")),
148
+ forbiddenClear: blockers.every((blocker) => !blocker.startsWith("changed_path_forbidden")),
149
+ blockers,
150
+ };
151
+ }
152
+
153
+ export function buildControlledWorkerPoolPlan(input: { runId: string; maxParallelWorkers?: number; launchAuthorization?: Record<string, unknown> }): ControlledWorkerPoolPlan {
154
+ const maxParallelWorkers = Math.max(1, Math.min(8, Math.trunc(input.maxParallelWorkers ?? 4)));
155
+ const launchAuthorization = input.launchAuthorization ?? {};
156
+ const launchAuthorized = launchAuthorization.specLocked === true && launchAuthorization.userLaunchConfirmed === true && launchAuthorization.launchAuthorizesInScopeActions === true;
157
+ const lane = (kind: WorkerPoolLaneKind, index: number, outputContract: string): ControlledWorkerPoolLane => ({
158
+ laneId: safeFileStem(`${index}-${kind}`),
159
+ kind,
160
+ maxWorkers: kind === "implement" ? Math.max(1, Math.min(3, maxParallelWorkers - 1)) : 1,
161
+ parentOwnedDispatch: true,
162
+ childDirectDispatch: false,
163
+ workspaceClaimRequired: true,
164
+ goalRoomEventsRequired: true,
165
+ todoClaimReducerRequired: true,
166
+ outputContract,
167
+ });
168
+ return {
169
+ schema: "zob.controlled-worker-pool-plan.v1",
170
+ runId: safeFileStem(input.runId),
171
+ maxParallelWorkers,
172
+ launchAuthorizationRequired: true,
173
+ strictBudgetRequired: true,
174
+ workerPoolEnabledByLaunch: launchAuthorized,
175
+ lanes: [
176
+ lane("context", 1, "context-pack.v1"),
177
+ lane("factory", 2, "factory.v1"),
178
+ lane("implement", 3, "implement.v1"),
179
+ lane("qa", 4, "qa.v1"),
180
+ lane("oracle", 5, "oracle.v1"),
181
+ ],
182
+ l5ControlledWorkerPool: true,
183
+ parentOwnedDispatch: true,
184
+ childDirectDispatch: false,
185
+ eventContract: "agent-event.v1",
186
+ todoReducerContract: "zob.todo-event-reducer-decision.v1",
187
+ bodyStored: false,
188
+ promptBodiesStored: false,
189
+ outputBodiesStored: false,
190
+ };
191
+ }
192
+
193
+ export function evaluateLaunchAuthorizedApplyGate(repoRoot: string, input: LaunchAuthorizedApplyInput): LaunchAuthorizedApplyGate {
194
+ const launchAuthorization = input.launchAuthorization;
195
+ const changedPaths = stableStrings(input.changedPaths);
196
+ const allowedPaths = launchAllowedPaths(launchAuthorization, input.allowedPaths);
197
+ const forbiddenPaths = launchForbiddenPaths(launchAuthorization, input.forbiddenPaths);
198
+ const pathGate = validateChangedPaths(repoRoot, changedPaths, allowedPaths, forbiddenPaths);
199
+ const validationRefs = stableStrings(input.validationRefs);
200
+ const gates = {
201
+ specLocked: launchAuthorization.specLocked === true,
202
+ userLaunchConfirmed: launchAuthorization.userLaunchConfirmed === true,
203
+ launchAuthorizesInScopeActions: launchAuthorization.launchAuthorizesInScopeActions === true,
204
+ applyPolicyAutoApplyInScope: launchApplyPolicyMode(launchAuthorization) === "auto_apply_in_scope",
205
+ workerPoolControlled: input.workerPoolPlan?.l5ControlledWorkerPool === true && input.workerPoolPlan.parentOwnedDispatch === true && input.workerPoolPlan.childDirectDispatch === false,
206
+ changedPathsAllowed: pathGate.allowed,
207
+ forbiddenPathsClear: pathGate.forbiddenClear,
208
+ sandboxEvidencePresent: typeof input.sandboxRunId === "string" && input.sandboxRunId.trim().length > 0,
209
+ oracleReviewPresent: typeof input.oracleReviewRef === "string" && input.oracleReviewRef.trim().length > 0,
210
+ validationRefsPresent: validationRefs.length > 0,
211
+ diffHashPresent: SHA256_HEX.test(input.diffHash),
212
+ };
213
+ const blockers = [
214
+ ...(!gates.specLocked ? ["spec_not_locked"] : []),
215
+ ...(!gates.userLaunchConfirmed ? ["user_launch_not_confirmed"] : []),
216
+ ...(!gates.launchAuthorizesInScopeActions ? ["launch_does_not_authorize_in_scope_actions"] : []),
217
+ ...(!gates.applyPolicyAutoApplyInScope ? ["apply_policy_not_auto_apply_in_scope"] : []),
218
+ ...(!gates.workerPoolControlled ? ["l5_worker_pool_not_controlled"] : []),
219
+ ...(!gates.changedPathsAllowed ? ["changed_paths_not_allowed"] : []),
220
+ ...(!gates.forbiddenPathsClear ? ["changed_paths_hit_forbidden_policy"] : []),
221
+ ...(!gates.sandboxEvidencePresent ? ["sandbox_evidence_missing"] : []),
222
+ ...(!gates.oracleReviewPresent ? ["oracle_review_missing"] : []),
223
+ ...(!gates.validationRefsPresent ? ["validation_refs_missing"] : []),
224
+ ...(!gates.diffHashPresent ? ["diff_hash_missing_or_invalid"] : []),
225
+ ...pathGate.blockers,
226
+ ];
227
+ const applyEligible = blockers.length === 0;
228
+ return {
229
+ schema: "zob.launch-authorized-apply-gate.v1",
230
+ runId: safeFileStem(input.runId),
231
+ status: applyEligible ? "eligible_not_applied" : "blocked",
232
+ applyEligible,
233
+ autoApplyAuthorizedByLaunch: gates.specLocked && gates.userLaunchConfirmed && gates.launchAuthorizesInScopeActions && gates.applyPolicyAutoApplyInScope,
234
+ manualPerActionApprovalRequired: false,
235
+ exceptionApprovalRequiredOnlyForOutOfScope: true,
236
+ applyPerformed: false,
237
+ productionWritesPerformed: false,
238
+ changedPaths,
239
+ changedPathHashes: hashStrings(changedPaths),
240
+ diffHash: input.diffHash,
241
+ sandboxRunIdHash: input.sandboxRunId ? sha256(input.sandboxRunId) : undefined,
242
+ oracleReviewRef: input.oracleReviewRef,
243
+ validationRefs,
244
+ gates,
245
+ blockers,
246
+ l6LaunchAuthorizedApply: true,
247
+ parentOwnedApplyCoordinatorRequired: true,
248
+ rollbackRequired: true,
249
+ postApplyValidationRequired: true,
250
+ postApplyOracleRequired: true,
251
+ bodyStored: false,
252
+ promptBodiesStored: false,
253
+ outputBodiesStored: false,
254
+ };
255
+ }
256
+
257
+ export function buildLaunchAuthorizedApplySmokeReport(repoRoot: string): LaunchAuthorizedApplySmokeReport {
258
+ const launchAuthorization = {
259
+ schema: "zob.launch-authorization.v1",
260
+ specLocked: true,
261
+ userLaunchConfirmed: true,
262
+ launchAuthorizesInScopeActions: true,
263
+ allowedPaths: ["docs/", ".pi/extensions/zob-harness/src/"],
264
+ forbiddenPaths: [".env", "**/.env*", "node_modules", "dist", "build"],
265
+ applyPolicy: { mode: "auto_apply_in_scope" },
266
+ bodyStored: false,
267
+ promptBodiesStored: false,
268
+ outputBodiesStored: false,
269
+ };
270
+ const workerPool = buildControlledWorkerPoolPlan({ runId: "launch-authorized-apply-smoke", maxParallelWorkers: 4, launchAuthorization });
271
+ const eligibleGate = evaluateLaunchAuthorizedApplyGate(repoRoot, {
272
+ runId: "launch-authorized-apply-smoke",
273
+ launchAuthorization,
274
+ workerPoolPlan: workerPool,
275
+ changedPaths: ["docs/ZOB_GENERAL_FACTORY_AGENT_L4_L6_MASTER_PLAN.md"],
276
+ diffHash: sha256("eligible launch-authorized smoke diff"),
277
+ sandboxRunId: "sandbox-launch-authorized-smoke",
278
+ oracleReviewRef: "reports/sandbox-manual-apply-preflight-smoke.json",
279
+ validationRefs: ["npm run check -- --pretty false", "npm run smoke:launch-authorized-apply"],
280
+ });
281
+ const blockedGate = evaluateLaunchAuthorizedApplyGate(repoRoot, {
282
+ runId: "launch-authorized-apply-smoke-blocked",
283
+ launchAuthorization: { ...launchAuthorization, userLaunchConfirmed: false, launchAuthorizesInScopeActions: false },
284
+ workerPoolPlan: workerPool,
285
+ changedPaths: [".env"],
286
+ diffHash: "invalid",
287
+ sandboxRunId: "sandbox-launch-authorized-smoke",
288
+ validationRefs: [],
289
+ });
290
+ const checks = [
291
+ { name: "l5_worker_pool_parent_owned", passed: workerPool.l5ControlledWorkerPool === true && workerPool.parentOwnedDispatch === true && workerPool.childDirectDispatch === false },
292
+ { name: "worker_pool_uses_events_and_todo_reducer", passed: workerPool.lanes.every((lane) => lane.goalRoomEventsRequired === true && lane.todoClaimReducerRequired === true) },
293
+ { name: "eligible_gate_authorizes_without_per_action_approval", passed: eligibleGate.applyEligible === true && eligibleGate.manualPerActionApprovalRequired === false && eligibleGate.autoApplyAuthorizedByLaunch === true },
294
+ { name: "eligible_gate_does_not_apply", passed: eligibleGate.applyPerformed === false && eligibleGate.productionWritesPerformed === false },
295
+ { name: "blocked_gate_rejects_missing_launch_and_forbidden_path", passed: blockedGate.applyEligible === false && blockedGate.blockers.includes("user_launch_not_confirmed") && blockedGate.blockers.some((blocker) => blocker.startsWith("changed_path_forbidden")) },
296
+ { name: "body_free", passed: eligibleGate.bodyStored === false && workerPool.bodyStored === false },
297
+ ];
298
+ const failedChecks = checks.filter((check) => !check.passed).map((check) => check.name);
299
+ return {
300
+ schema: "zob.launch-authorized-apply-smoke.v1",
301
+ status: failedChecks.length === 0 ? "passed" : "failed",
302
+ workerPool,
303
+ eligibleGate,
304
+ blockedGate,
305
+ checks,
306
+ failedChecks,
307
+ no_ship: failedChecks.length > 0,
308
+ bodyStored: false,
309
+ promptBodiesStored: false,
310
+ outputBodiesStored: false,
311
+ generatedAt: new Date().toISOString(),
312
+ };
313
+ }
@@ -0,0 +1,290 @@
1
+ import { appendFileSync, mkdirSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+
4
+ import { DEFAULT_RULES } from "./constants.js";
5
+ import type { TeamDefinition } from "./types.js";
6
+ import { sha256 } from "./utils/hashing.js";
7
+ import { readJsonl } from "./utils/json.js";
8
+ import { pathMatches, resolveRepoPath, safeFileStem } from "./utils/paths.js";
9
+ import { isRecord } from "./utils/records.js";
10
+
11
+ export type MergeCandidatePriority = "low" | "normal" | "high" | "critical";
12
+ export type MergeCandidateRisk = "low" | "medium" | "high";
13
+ export type MergeDecision = "approve_for_manual_apply" | "reject" | "needs_oracle";
14
+
15
+ export interface MergeCandidateInput {
16
+ run_id: string;
17
+ submitted_by: string;
18
+ sandbox_run_id: string;
19
+ workspace_claim_ids: string[];
20
+ changed_paths: string[];
21
+ diff_hash: string;
22
+ validation_refs: string[];
23
+ summary_hash?: string;
24
+ todo_id?: string;
25
+ oracle_review_ref?: string;
26
+ rollback_ref?: string;
27
+ priority?: MergeCandidatePriority;
28
+ risk_level?: MergeCandidateRisk;
29
+ }
30
+
31
+ export interface MergeDecisionInput {
32
+ candidate_id: string;
33
+ decided_by: string;
34
+ decision: MergeDecision;
35
+ reason_hash: string;
36
+ oracle_review_ref?: string;
37
+ }
38
+
39
+ export interface MergeQueueListInput {
40
+ run_id?: string;
41
+ submitted_by?: string;
42
+ status?: string;
43
+ limit?: number;
44
+ }
45
+
46
+ export interface MergeCandidateRecord {
47
+ schema: "zob.merge-candidate.v1";
48
+ candidateId: string;
49
+ runId: string;
50
+ submittedBy: string;
51
+ todoId: string | null;
52
+ sandboxRunId: string;
53
+ workspaceClaimIds: string[];
54
+ changedPaths: string[];
55
+ changedPathHashes: string[];
56
+ diffHash: string;
57
+ validationRefs: string[];
58
+ oracleReviewRef: string | null;
59
+ rollbackRef: string | null;
60
+ summaryHash: string | null;
61
+ priority: MergeCandidatePriority;
62
+ riskLevel: MergeCandidateRisk;
63
+ status: "queued";
64
+ parentOwnedQueue: true;
65
+ sequentialApplyRequired: true;
66
+ oracleReviewRequired: boolean;
67
+ humanApprovalRequired: true;
68
+ applyPerformed: false;
69
+ productionWritesPerformed: false;
70
+ autoApply: false;
71
+ bodyStored: false;
72
+ promptBodiesStored: false;
73
+ outputBodiesStored: false;
74
+ queuedAt: string;
75
+ }
76
+
77
+ export interface MergeDecisionRecord {
78
+ schema: "zob.merge-decision.v1";
79
+ decisionId: string;
80
+ candidateId: string;
81
+ decidedBy: string;
82
+ decision: MergeDecision;
83
+ reasonHash: string;
84
+ oracleReviewRef: string | null;
85
+ parentOwnedDecision: true;
86
+ manualApplyOnly: true;
87
+ applyPerformed: false;
88
+ productionWritesPerformed: false;
89
+ autoApply: false;
90
+ bodyStored: false;
91
+ promptBodiesStored: false;
92
+ outputBodiesStored: false;
93
+ decidedAt: string;
94
+ }
95
+
96
+ const SHA256_HEX = /^[a-f0-9]{64}$/i;
97
+ const PRIORITIES = new Set<MergeCandidatePriority>(["low", "normal", "high", "critical"]);
98
+ const RISKS = new Set<MergeCandidateRisk>(["low", "medium", "high"]);
99
+ const DECISIONS = new Set<MergeDecision>(["approve_for_manual_apply", "reject", "needs_oracle"]);
100
+
101
+ function mergeQueueDir(repoRoot: string): string {
102
+ return join(repoRoot, ".pi", "merge-queue");
103
+ }
104
+
105
+ function candidatesDir(repoRoot: string): string {
106
+ return join(mergeQueueDir(repoRoot), "candidates");
107
+ }
108
+
109
+ function candidatesPath(repoRoot: string): string {
110
+ return join(mergeQueueDir(repoRoot), "candidates.jsonl");
111
+ }
112
+
113
+ function decisionsPath(repoRoot: string): string {
114
+ return join(mergeQueueDir(repoRoot), "decisions.jsonl");
115
+ }
116
+
117
+ function eventsPath(repoRoot: string): string {
118
+ return join(mergeQueueDir(repoRoot), "events.jsonl");
119
+ }
120
+
121
+ function knownRoleIds(definition: TeamDefinition): Set<string> {
122
+ return new Set([definition.orchestrator.id, ...definition.leads.map((lead) => lead.id), ...definition.workers.map((worker) => worker.id), "parent", "mission-control"]);
123
+ }
124
+
125
+ function appendMergeEvent(repoRoot: string, event: Record<string, unknown>): void {
126
+ mkdirSync(mergeQueueDir(repoRoot), { recursive: true });
127
+ appendFileSync(eventsPath(repoRoot), `${JSON.stringify({ ...event, timestamp: new Date().toISOString(), bodyStored: false, promptBodiesStored: false, outputBodiesStored: false, applyPerformed: false, productionWritesPerformed: false, autoApply: false })}\n`, "utf8");
128
+ }
129
+
130
+ function validateRef(repoRoot: string, ref: string, label: string): string[] {
131
+ const errors: string[] = [];
132
+ if (typeof ref !== "string" || ref.trim().length === 0) return [`${label} contains an empty ref`];
133
+ if (ref.includes("\0")) errors.push(`${label} contains NUL byte: ${ref}`);
134
+ const resolved = resolveRepoPath(repoRoot, ref);
135
+ errors.push(...resolved.errors.map((error) => `${label}: ${error}`));
136
+ for (const protectedPattern of DEFAULT_RULES.zeroAccessPaths) {
137
+ if (pathMatches(ref, protectedPattern, repoRoot, repoRoot)) errors.push(`${label} references zero-access path: ${protectedPattern}`);
138
+ }
139
+ return errors;
140
+ }
141
+
142
+ function validateCandidateInput(repoRoot: string, definition: TeamDefinition, input: MergeCandidateInput): string[] {
143
+ const errors: string[] = [];
144
+ if (!input.run_id || safeFileStem(input.run_id) !== input.run_id) errors.push(`run_id must be path-safe: ${input.run_id}`);
145
+ if (input.todo_id && safeFileStem(input.todo_id) !== input.todo_id) errors.push(`todo_id must be path-safe: ${input.todo_id}`);
146
+ if (!input.sandbox_run_id || safeFileStem(input.sandbox_run_id) !== input.sandbox_run_id) errors.push(`sandbox_run_id must be path-safe: ${input.sandbox_run_id}`);
147
+ if (!knownRoleIds(definition).has(input.submitted_by)) errors.push(`Unknown merge candidate submitter '${input.submitted_by}'`);
148
+ if (!Array.isArray(input.workspace_claim_ids) || input.workspace_claim_ids.length === 0) errors.push("merge candidate requires workspace_claim_ids");
149
+ for (const claimId of input.workspace_claim_ids ?? []) {
150
+ if (!claimId || safeFileStem(claimId) !== claimId) errors.push(`workspace claim id must be path-safe: ${claimId}`);
151
+ }
152
+ if (!Array.isArray(input.changed_paths) || input.changed_paths.length === 0) errors.push("merge candidate requires changed_paths");
153
+ if (input.changed_paths.length > 100) errors.push("merge candidate changed_paths are capped at 100");
154
+ for (const changedPath of input.changed_paths ?? []) errors.push(...validateRef(repoRoot, changedPath, "changed_paths"));
155
+ if (!SHA256_HEX.test(input.diff_hash)) errors.push("merge candidate diff_hash must be sha256 hex");
156
+ if (input.summary_hash !== undefined && !SHA256_HEX.test(input.summary_hash)) errors.push("merge candidate summary_hash must be sha256 hex");
157
+ if (!Array.isArray(input.validation_refs) || input.validation_refs.length === 0) errors.push("merge candidate requires validation_refs");
158
+ for (const ref of input.validation_refs ?? []) errors.push(...validateRef(repoRoot, ref, "validation_refs"));
159
+ if (input.oracle_review_ref) errors.push(...validateRef(repoRoot, input.oracle_review_ref, "oracle_review_ref"));
160
+ if (input.rollback_ref) errors.push(...validateRef(repoRoot, input.rollback_ref, "rollback_ref"));
161
+ if (input.priority !== undefined && !PRIORITIES.has(input.priority)) errors.push("merge candidate priority must be low|normal|high|critical");
162
+ if (input.risk_level !== undefined && !RISKS.has(input.risk_level)) errors.push("merge candidate risk_level must be low|medium|high");
163
+ return errors;
164
+ }
165
+
166
+ function readCandidates(repoRoot: string): MergeCandidateRecord[] {
167
+ return readJsonl(candidatesPath(repoRoot)).filter(isMergeCandidateRecord).map((record) => record as unknown as MergeCandidateRecord);
168
+ }
169
+
170
+ function readDecisions(repoRoot: string): MergeDecisionRecord[] {
171
+ return readJsonl(decisionsPath(repoRoot)).filter(isMergeDecisionRecord).map((record) => record as unknown as MergeDecisionRecord);
172
+ }
173
+
174
+ function latestDecision(candidateId: string, decisions: MergeDecisionRecord[]): MergeDecisionRecord | undefined {
175
+ return decisions.filter((decision) => decision.candidateId === candidateId).at(-1);
176
+ }
177
+
178
+ export function submitMergeCandidate(repoRoot: string, definition: TeamDefinition, input: MergeCandidateInput): MergeCandidateRecord {
179
+ const errors = validateCandidateInput(repoRoot, definition, input);
180
+ if (errors.length > 0) throw new Error(errors.join("; "));
181
+ const now = Date.now();
182
+ const changedPaths = [...new Set(input.changed_paths)].sort();
183
+ const candidateId = `merge_${sha256(`${input.run_id}:${input.submitted_by}:${input.sandbox_run_id}:${input.diff_hash}:${now}`).slice(0, 16)}`;
184
+ const candidate: MergeCandidateRecord = {
185
+ schema: "zob.merge-candidate.v1",
186
+ candidateId,
187
+ runId: input.run_id,
188
+ submittedBy: input.submitted_by,
189
+ todoId: input.todo_id ?? null,
190
+ sandboxRunId: input.sandbox_run_id,
191
+ workspaceClaimIds: [...new Set(input.workspace_claim_ids)].sort(),
192
+ changedPaths,
193
+ changedPathHashes: changedPaths.map((path) => sha256(path)),
194
+ diffHash: input.diff_hash,
195
+ validationRefs: [...new Set(input.validation_refs)].sort(),
196
+ oracleReviewRef: input.oracle_review_ref ?? null,
197
+ rollbackRef: input.rollback_ref ?? null,
198
+ summaryHash: input.summary_hash ?? null,
199
+ priority: input.priority ?? "normal",
200
+ riskLevel: input.risk_level ?? "medium",
201
+ status: "queued",
202
+ parentOwnedQueue: true,
203
+ sequentialApplyRequired: true,
204
+ oracleReviewRequired: input.oracle_review_ref === undefined,
205
+ humanApprovalRequired: true,
206
+ applyPerformed: false,
207
+ productionWritesPerformed: false,
208
+ autoApply: false,
209
+ bodyStored: false,
210
+ promptBodiesStored: false,
211
+ outputBodiesStored: false,
212
+ queuedAt: new Date(now).toISOString(),
213
+ };
214
+ mkdirSync(candidatesDir(repoRoot), { recursive: true });
215
+ appendFileSync(candidatesPath(repoRoot), `${JSON.stringify(candidate)}\n`, "utf8");
216
+ writeFileSync(join(candidatesDir(repoRoot), `${candidateId}.json`), JSON.stringify(candidate, null, 2), "utf8");
217
+ appendMergeEvent(repoRoot, { event: "candidate_queued", candidateId, runId: candidate.runId, submittedBy: candidate.submittedBy, applyPerformed: false, productionWritesPerformed: false, autoApply: false });
218
+ return candidate;
219
+ }
220
+
221
+ export function decideMergeCandidate(repoRoot: string, definition: TeamDefinition, input: MergeDecisionInput): MergeDecisionRecord {
222
+ if (!input.candidate_id || safeFileStem(input.candidate_id) !== input.candidate_id) throw new Error(`candidate_id must be path-safe: ${input.candidate_id}`);
223
+ if (!knownRoleIds(definition).has(input.decided_by)) throw new Error(`Unknown merge decision actor '${input.decided_by}'`);
224
+ if (!DECISIONS.has(input.decision)) throw new Error("merge decision must be approve_for_manual_apply|reject|needs_oracle");
225
+ if (!SHA256_HEX.test(input.reason_hash)) throw new Error("merge decision reason_hash must be sha256 hex");
226
+ const candidate = readCandidates(repoRoot).find((item) => item.candidateId === input.candidate_id);
227
+ if (!candidate) throw new Error(`merge candidate not found: ${input.candidate_id}`);
228
+ const errors = input.oracle_review_ref ? validateRef(repoRoot, input.oracle_review_ref, "oracle_review_ref") : [];
229
+ if (input.decision === "approve_for_manual_apply" && !input.oracle_review_ref && candidate.oracleReviewRequired) errors.push("approve_for_manual_apply requires oracle_review_ref when candidate lacks prior oracle review");
230
+ if (errors.length > 0) throw new Error(errors.join("; "));
231
+ const decision: MergeDecisionRecord = {
232
+ schema: "zob.merge-decision.v1",
233
+ decisionId: `mdecision_${sha256(`${input.candidate_id}:${input.decided_by}:${input.decision}:${Date.now()}`).slice(0, 16)}`,
234
+ candidateId: input.candidate_id,
235
+ decidedBy: input.decided_by,
236
+ decision: input.decision,
237
+ reasonHash: input.reason_hash,
238
+ oracleReviewRef: input.oracle_review_ref ?? null,
239
+ parentOwnedDecision: true,
240
+ manualApplyOnly: true,
241
+ applyPerformed: false,
242
+ productionWritesPerformed: false,
243
+ autoApply: false,
244
+ bodyStored: false,
245
+ promptBodiesStored: false,
246
+ outputBodiesStored: false,
247
+ decidedAt: new Date().toISOString(),
248
+ };
249
+ mkdirSync(mergeQueueDir(repoRoot), { recursive: true });
250
+ appendFileSync(decisionsPath(repoRoot), `${JSON.stringify(decision)}\n`, "utf8");
251
+ appendMergeEvent(repoRoot, { event: "decision_recorded", candidateId: decision.candidateId, decision: decision.decision, applyPerformed: false, productionWritesPerformed: false, autoApply: false });
252
+ return decision;
253
+ }
254
+
255
+ export function listMergeQueue(repoRoot: string, input: MergeQueueListInput = {}): Array<MergeCandidateRecord & { latestDecision?: MergeDecisionRecord }> {
256
+ const decisions = readDecisions(repoRoot);
257
+ const limit = Math.max(1, Math.min(100, Math.floor(input.limit ?? 20)));
258
+ return readCandidates(repoRoot)
259
+ .map((candidate) => ({ ...candidate, latestDecision: latestDecision(candidate.candidateId, decisions) }))
260
+ .filter((candidate) => !input.run_id || candidate.runId === input.run_id)
261
+ .filter((candidate) => !input.submitted_by || candidate.submittedBy === input.submitted_by)
262
+ .filter((candidate) => !input.status || candidate.latestDecision?.decision === input.status || (!candidate.latestDecision && candidate.status === input.status))
263
+ .slice(-limit);
264
+ }
265
+
266
+ export function mergeQueueBodyFreeViolations(value: unknown): string[] {
267
+ const forbidden = new Set(["body", "task", "prompt", "output", "content", "patch", "diff"]);
268
+ const violations: string[] = [];
269
+ const visit = (item: unknown, path: string): void => {
270
+ if (!item || typeof item !== "object") return;
271
+ if (Array.isArray(item)) {
272
+ item.forEach((child, index) => visit(child, `${path}[${index}]`));
273
+ return;
274
+ }
275
+ for (const [key, child] of Object.entries(item as Record<string, unknown>)) {
276
+ if (forbidden.has(key)) violations.push(`${path}.${key}`);
277
+ visit(child, `${path}.${key}`);
278
+ }
279
+ };
280
+ visit(value, "root");
281
+ return violations;
282
+ }
283
+
284
+ export function isMergeCandidateRecord(value: unknown): value is MergeCandidateRecord {
285
+ return isRecord(value) && value.schema === "zob.merge-candidate.v1" && typeof value.candidateId === "string" && value.bodyStored === false && value.applyPerformed === false && value.autoApply === false;
286
+ }
287
+
288
+ export function isMergeDecisionRecord(value: unknown): value is MergeDecisionRecord {
289
+ return isRecord(value) && value.schema === "zob.merge-decision.v1" && typeof value.candidateId === "string" && value.bodyStored === false && value.applyPerformed === false && value.autoApply === false;
290
+ }