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,346 @@
1
+ import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+
4
+ import { SUPERVISED_READONLY_CHILD_TOOLS, SUPERVISED_SMOKE_CHILD_TOOLS } from "../constants.js";
5
+ import type { OrchestrateExecutionMode, TeamDefinition } from "../types.js";
6
+ import { sha256 } from "../utils/hashing.js";
7
+ import { isRecord } from "../utils/records.js";
8
+
9
+ function orchestrationLedger(runDir: string, entry: Record<string, unknown>): void {
10
+ appendFileSync(join(runDir, "ledger.jsonl"), `${JSON.stringify({ ...entry, timestamp: new Date().toISOString() })}\n`, "utf8");
11
+ }
12
+
13
+ function buildOrchestrationMessages(definition: TeamDefinition, plan: Record<string, unknown>, runId: string, execution: OrchestrateExecutionMode): Array<Record<string, unknown>> {
14
+ const tasks = Array.isArray(plan.tasks) ? plan.tasks.filter(isRecord) : [];
15
+ return tasks.map((task, index) => {
16
+ const taskId = typeof task.id === "string" ? task.id : `task-${index + 1}`;
17
+ const taskType = typeof task.type === "string" ? task.type : "unknown";
18
+ const leadId = typeof task.leadId === "string" ? task.leadId : undefined;
19
+ const workerId = typeof task.workerId === "string" ? task.workerId : undefined;
20
+ const sender = taskType === "lead_plan" ? definition.orchestrator.id : (typeof task.proposedBy === "string" ? task.proposedBy : definition.orchestrator.id);
21
+ const receiver = taskType === "lead_plan" ? (leadId ?? "unknown-lead") : (workerId ?? leadId ?? "unknown-worker");
22
+ const contractFingerprint = JSON.stringify({
23
+ task: typeof task.task === "string" ? task.task : "",
24
+ expected_outcome: typeof task.expected_outcome === "string" ? task.expected_outcome : "",
25
+ required_tools: Array.isArray(task.required_tools) ? task.required_tools : [],
26
+ output_contract: typeof task.output_contract === "string" ? task.output_contract : "",
27
+ must_do: Array.isArray(task.must_do) ? task.must_do : [],
28
+ must_not_do: Array.isArray(task.must_not_do) ? task.must_not_do : [],
29
+ context: typeof task.context === "string" ? task.context : "",
30
+ });
31
+ return {
32
+ schema: "zob.orchestration-message.v1",
33
+ msgId: `${runId}:${taskId}`,
34
+ runId,
35
+ parentId: typeof task.parent === "string" ? task.parent : definition.orchestrator.id,
36
+ sender,
37
+ receiver,
38
+ receiverAgent: typeof task.agent === "string" ? task.agent : "unknown-agent",
39
+ role: typeof task.role === "string" ? task.role : "unknown-role",
40
+ taskId,
41
+ taskType,
42
+ goalId: typeof task.goalId === "string" ? task.goalId : undefined,
43
+ todoId: typeof task.todoId === "string" ? task.todoId : undefined,
44
+ todoRef: isRecord(task.todoRef) ? task.todoRef : undefined,
45
+ taskHash: sha256(contractFingerprint),
46
+ outputHash: null,
47
+ status: "planned",
48
+ ack: "not_sent",
49
+ execution,
50
+ noExecution: true,
51
+ timestamp: new Date().toISOString(),
52
+ };
53
+ });
54
+ }
55
+
56
+ function writeOrchestrationMessages(runDir: string, messages: Array<Record<string, unknown>>): void {
57
+ writeFileSync(join(runDir, "messages.jsonl"), messages.map((message) => JSON.stringify(message)).join("\n") + (messages.length > 0 ? "\n" : ""), "utf8");
58
+ }
59
+
60
+ function buildOrchestrationStatuses(messages: Array<Record<string, unknown>>, runId: string, execution: OrchestrateExecutionMode): Array<Record<string, unknown>> {
61
+ return messages.map((message) => ({
62
+ schema: "zob.orchestration-status.v1",
63
+ event: "status_planned",
64
+ runId,
65
+ msgId: typeof message.msgId === "string" ? message.msgId : "unknown-message",
66
+ parentId: typeof message.parentId === "string" ? message.parentId : "unknown-parent",
67
+ sender: typeof message.sender === "string" ? message.sender : "unknown-sender",
68
+ receiver: typeof message.receiver === "string" ? message.receiver : "unknown-receiver",
69
+ receiverAgent: typeof message.receiverAgent === "string" ? message.receiverAgent : "unknown-agent",
70
+ role: typeof message.role === "string" ? message.role : "unknown-role",
71
+ taskId: typeof message.taskId === "string" ? message.taskId : "unknown-task",
72
+ taskHash: typeof message.taskHash === "string" ? message.taskHash : "",
73
+ outputHash: null,
74
+ status: "planned",
75
+ ack: "not_sent",
76
+ ping: "not_started",
77
+ running: false,
78
+ startedAt: null,
79
+ lastPingAt: null,
80
+ lastAckAt: null,
81
+ completedAt: null,
82
+ execution,
83
+ noExecution: true,
84
+ supervisedSmoke: execution === "supervised_smoke" ? { planned: true, liveChildExecution: false, allowedTools: [...SUPERVISED_SMOKE_CHILD_TOOLS] } : undefined,
85
+ supervisedReadonly: execution === "supervised_readonly" ? { planned: true, parentOwnedDispatch: true, allowedTools: [...SUPERVISED_READONLY_CHILD_TOOLS] } : undefined,
86
+ timestamp: new Date().toISOString(),
87
+ }));
88
+ }
89
+
90
+ function writeOrchestrationStatuses(runDir: string, statuses: Array<Record<string, unknown>>, runId: string, execution: OrchestrateExecutionMode): void {
91
+ writeFileSync(join(runDir, "status.jsonl"), statuses.map((status) => JSON.stringify(status)).join("\n") + (statuses.length > 0 ? "\n" : ""), "utf8");
92
+ const latestByMsgId = new Map<string, Record<string, unknown>>();
93
+ statuses.forEach((status, index) => latestByMsgId.set(typeof status.msgId === "string" ? status.msgId : `unknown-${index}`, status));
94
+ const snapshotStatuses = [...latestByMsgId.values()];
95
+ const byStatus = snapshotStatuses.reduce<Record<string, number>>((counts, status) => {
96
+ const key = typeof status.status === "string" ? status.status : "unknown";
97
+ counts[key] = (counts[key] ?? 0) + 1;
98
+ return counts;
99
+ }, {});
100
+ const byAck = snapshotStatuses.reduce<Record<string, number>>((counts, status) => {
101
+ const key = typeof status.ack === "string" ? status.ack : "unknown";
102
+ counts[key] = (counts[key] ?? 0) + 1;
103
+ return counts;
104
+ }, {});
105
+ const byPing = snapshotStatuses.reduce<Record<string, number>>((counts, status) => {
106
+ const key = typeof status.ping === "string" ? status.ping : "unknown";
107
+ counts[key] = (counts[key] ?? 0) + 1;
108
+ return counts;
109
+ }, {});
110
+ const snapshot = {
111
+ schema: "zob.orchestration-status-snapshot.v1",
112
+ runId,
113
+ execution,
114
+ total: snapshotStatuses.length,
115
+ events: statuses.length,
116
+ byStatus,
117
+ byAck,
118
+ byPing,
119
+ running: snapshotStatuses.filter((status) => status.running === true).length,
120
+ noExecution: snapshotStatuses.every((status) => status.noExecution !== false),
121
+ supervisedSmoke: execution === "supervised_smoke" ? { planned: true, liveChildExecution: false, allowedTools: [...SUPERVISED_SMOKE_CHILD_TOOLS] } : undefined,
122
+ supervisedReadonly: execution === "supervised_readonly" ? { parentOwnedDispatch: true, allowedTools: [...SUPERVISED_READONLY_CHILD_TOOLS] } : undefined,
123
+ timestamp: new Date().toISOString(),
124
+ };
125
+ writeFileSync(join(runDir, "status-snapshot.json"), JSON.stringify(snapshot, null, 2), "utf8");
126
+ }
127
+
128
+ export function writeOrchestrationRoomArtifacts(input: {
129
+ runDir: string;
130
+ runId: string;
131
+ definition: TeamDefinition;
132
+ plan: Record<string, unknown>;
133
+ messages: Array<Record<string, unknown>>;
134
+ statuses: Array<Record<string, unknown>>;
135
+ execution: OrchestrateExecutionMode;
136
+ goal: string;
137
+ originalUserAsk: string;
138
+ goalId?: string;
139
+ rootTodoId?: string;
140
+ comsMirrored?: number;
141
+ adaptiveWorkflow?: Record<string, unknown>;
142
+ }): { roomDir: string; artifacts: string[] } {
143
+ const roomDir = join(input.runDir, "room");
144
+ mkdirSync(roomDir, { recursive: true });
145
+ const participants = [input.definition.orchestrator.id, ...input.definition.leads.map((lead) => lead.id), ...input.definition.workers.map((worker) => worker.id)];
146
+ const roleById = new Map<string, { agent: string; roleType: string; leadId?: string }>();
147
+ roleById.set(input.definition.orchestrator.id, { agent: input.definition.orchestrator.agent, roleType: "orchestrator" });
148
+ for (const lead of input.definition.leads) roleById.set(lead.id, { agent: lead.agent, roleType: "lead" });
149
+ for (const worker of input.definition.workers) roleById.set(worker.id, { agent: worker.agent, roleType: "worker", leadId: worker.leadId });
150
+
151
+ const room = {
152
+ schema: "zob.room.v1",
153
+ runId: input.runId,
154
+ goalHash: sha256(input.goal),
155
+ originalUserAskHash: sha256(input.originalUserAsk),
156
+ profile: input.definition.name,
157
+ participants,
158
+ policy: {
159
+ bodyPolicy: "hash_only_by_default",
160
+ allowedEdges: "from team topology",
161
+ networked: false,
162
+ promptBodiesStored: false,
163
+ outputBodiesStored: false,
164
+ parentOwnedPreflight: true,
165
+ parentDispatchOnly: true,
166
+ workerSpawnsWorker: false,
167
+ },
168
+ createdAt: new Date().toISOString(),
169
+ };
170
+
171
+ const roomMessages = input.messages.map((message) => {
172
+ const receiver = typeof message.receiver === "string" ? message.receiver : "unknown";
173
+ const sender = typeof message.sender === "string" ? message.sender : "unknown";
174
+ const taskType = typeof message.taskType === "string" ? message.taskType : "task";
175
+ return {
176
+ schema: "zob.room-message.v1",
177
+ msgId: typeof message.msgId === "string" ? message.msgId : `${input.runId}:${sender}:${receiver}`,
178
+ runId: input.runId,
179
+ threadId: taskType,
180
+ goalId: typeof message.goalId === "string" ? message.goalId : input.goalId,
181
+ todoId: typeof message.todoId === "string" ? message.todoId : input.rootTodoId,
182
+ sender,
183
+ receiver,
184
+ type: taskType === "lead_plan" || taskType === "worker_contract" ? "task" : "status",
185
+ status: typeof message.status === "string" ? message.status : "planned",
186
+ summary: `${sender} -> ${receiver}: ${taskType} handoff (${input.execution})`,
187
+ taskHash: typeof message.taskHash === "string" ? message.taskHash : null,
188
+ outputHash: typeof message.outputHash === "string" ? message.outputHash : null,
189
+ artifactRefs: ["orchestration-plan.json", "messages.jsonl", "status.jsonl"],
190
+ bodyStored: false,
191
+ promptBodiesStored: false,
192
+ outputBodiesStored: false,
193
+ timestamp: typeof message.timestamp === "string" ? message.timestamp : new Date().toISOString(),
194
+ };
195
+ });
196
+
197
+ const roomStatuses = input.statuses.map((status) => ({
198
+ schema: "zob.room-status.v1",
199
+ runId: input.runId,
200
+ msgId: typeof status.msgId === "string" ? status.msgId : "unknown-message",
201
+ actor: typeof status.receiver === "string" ? status.receiver : "unknown-actor",
202
+ status: typeof status.status === "string" ? status.status : "unknown",
203
+ ack: typeof status.ack === "string" ? status.ack : "unknown",
204
+ ping: typeof status.ping === "string" ? status.ping : "unknown",
205
+ running: status.running === true,
206
+ outputHash: typeof status.outputHash === "string" ? status.outputHash : null,
207
+ bodyStored: false,
208
+ timestamp: typeof status.timestamp === "string" ? status.timestamp : new Date().toISOString(),
209
+ }));
210
+
211
+ const decisions = [
212
+ {
213
+ schema: "zob.room-decision.v1",
214
+ runId: input.runId,
215
+ decisionId: `${input.runId}:parent-owned-preflight`,
216
+ summary: "Parent-owned preflight and dispatch boundary preserved; worker-to-worker communication remains blocked by default.",
217
+ evidenceRefs: ["orchestration-plan.json", "validation.json"],
218
+ bodyStored: false,
219
+ timestamp: new Date().toISOString(),
220
+ },
221
+ ];
222
+
223
+ const blockers = input.statuses
224
+ .filter((status) => status.status === "failed" || status.ping === "blocked")
225
+ .map((status, index) => ({
226
+ schema: "zob.room-blocker.v1",
227
+ runId: input.runId,
228
+ blockerId: `${input.runId}:blocker-${index + 1}`,
229
+ actor: typeof status.receiver === "string" ? status.receiver : "unknown-actor",
230
+ summary: `Blocked or failed status for ${typeof status.taskId === "string" ? status.taskId : "unknown-task"}`,
231
+ status: typeof status.status === "string" ? status.status : "unknown",
232
+ evidenceRefs: ["status.jsonl", "validation.json"],
233
+ bodyStored: false,
234
+ timestamp: typeof status.timestamp === "string" ? status.timestamp : new Date().toISOString(),
235
+ }));
236
+
237
+ const latestByRole: Record<string, string> = {};
238
+ for (const participant of participants) {
239
+ const role = roleById.get(participant);
240
+ latestByRole[participant] = `${role?.roleType ?? "role"} ${role?.agent ?? "unknown-agent"}: ${input.execution} planned metadata`;
241
+ }
242
+ const tasks = Array.isArray(input.plan.tasks) ? input.plan.tasks.filter(isRecord) : [];
243
+ const latestStatusByMsgId = new Map<string, Record<string, unknown>>();
244
+ input.statuses.forEach((status, index) => latestStatusByMsgId.set(typeof status.msgId === "string" ? status.msgId : `unknown-${index}`, status));
245
+ const latestStatuses = [...latestStatusByMsgId.values()];
246
+ const contextScope = {
247
+ schema: "zob.context-scope.v1",
248
+ scopeId: `${input.runId}-orchestration-context-scope`,
249
+ runId: input.runId,
250
+ allowedBrains: ["harness-system"],
251
+ allowedSources: ["orchestration-run-artifacts", "zob-harness-orchestration-room"],
252
+ forbiddenSources: [".env", ".env.*", "secrets", "raw-conversation-history", "node_modules", "dist", "build"],
253
+ agentProfile: "orchestration-room",
254
+ maxContextTokens: 4000,
255
+ freshnessPolicy: "current_run_artifacts",
256
+ readPolicy: "bounded_metadata_only",
257
+ writePolicy: "proposal_only",
258
+ citationRequired: true,
259
+ contextPackRequired: true,
260
+ sourceScopeRequired: true,
261
+ bodyStored: false,
262
+ promptBodiesStored: false,
263
+ outputBodiesStored: false,
264
+ };
265
+ const contextCitations = [
266
+ `harness-system:orchestration-run-artifacts:${input.runId}/manifest.json`,
267
+ `harness-system:orchestration-run-artifacts:${input.runId}/validation.json`,
268
+ ];
269
+ const adaptiveWorkflow = isRecord(input.adaptiveWorkflow) ? input.adaptiveWorkflow : undefined;
270
+ const adaptiveWorkflowRefs = Array.isArray(adaptiveWorkflow?.adaptiveWorkflowRefs) ? adaptiveWorkflow.adaptiveWorkflowRefs.filter((ref): ref is string => typeof ref === "string") : [];
271
+ const documentationRefs = ["documentation-policy.json", "guidance-index.json", "docs/layer-doc-pack.json", "docs/role-doc-packs.json", "docs/writeback-proposals.json"].filter((ref) => adaptiveWorkflowRefs.includes(ref));
272
+ const contextPack = {
273
+ schema: "zob.context-pack.v2",
274
+ runId: input.runId,
275
+ profile: input.definition.name,
276
+ goal: "redacted; see goalHash in room.json",
277
+ goalHash: sha256(input.goal),
278
+ currentPhase: input.execution === "plan_only" ? "planning" : input.execution,
279
+ currentState: latestStatuses.some((status) => status.running === true) ? "running" : latestStatuses.some((status) => status.status === "failed") ? "failed" : latestStatuses.some((status) => status.status === "completed") ? "completed" : "planned",
280
+ decisions: decisions.map((decision) => decision.summary),
281
+ openQuestions: tasks.length === 0 ? ["No tasks planned"] : [],
282
+ blockers: blockers.map((blocker) => blocker.summary),
283
+ evidenceRefs: ["manifest.json", "orchestration-plan.json", "messages.jsonl", "status.jsonl", "validation.json", "room/blockers.jsonl", ...adaptiveWorkflowRefs],
284
+ todoGraphBinding: input.rootTodoId ? { goalId: input.goalId, rootTodoId: input.rootTodoId, attachmentPolicy: "messages_delegations_blockers_claims_evidence_attach_to_todo", bodyStored: false } : undefined,
285
+ contextScope,
286
+ contextLoading: { contextScopeRequired: true, boundedContextPack: true, agentLoadsEntireCorpus: false, citationRequired: true, writePolicy: "proposal_only" },
287
+ sourceLocks: [
288
+ { sourceId: "orchestration-run-artifacts", brainId: "harness-system", sourceRoot: `reports/orchestrations/${input.runId}`, sourceRootHash: sha256(`reports/orchestrations/${input.runId}`) },
289
+ { sourceId: "zob-harness-orchestration-room", brainId: "harness-system", sourceRoot: ".pi/extensions/zob-harness/src/orchestration", sourceRootHash: sha256(".pi/extensions/zob-harness/src/orchestration") },
290
+ ],
291
+ citations: contextCitations,
292
+ latestByRole,
293
+ ruleProfile: {
294
+ profile: "orchestration-engineer",
295
+ rulePacks: ["always", "project", "orchestration", "oracle"],
296
+ oracleRequired: true,
297
+ noShipConditions: ["worker-to-worker edge accepted without policy", "networked coms enabled", "DONE.sentinel written without evidence and oracle gate", "plaintext body persisted in coms or room", "documentation policy missing for multi-layer workflow", "model/security downgrade without explicit policy", "large scale without budget/approval/oracle"],
298
+ },
299
+ modelRoutingSummary: adaptiveWorkflow ? { modelPolicyRef: adaptiveWorkflow.modelPolicyRef, scalePolicyRef: adaptiveWorkflow.scalePolicyRef } : {},
300
+ adaptiveWorkflow: adaptiveWorkflow ? {
301
+ refs: adaptiveWorkflowRefs,
302
+ promptPolicyRef: adaptiveWorkflow.promptPolicyRef,
303
+ documentationPolicyRef: adaptiveWorkflow.documentationPolicyRef,
304
+ guidanceIndexRef: adaptiveWorkflow.guidanceIndexRef,
305
+ tempAgentRosterRef: adaptiveWorkflow.tempAgentRosterRef,
306
+ rootNonCoding: adaptiveWorkflow.rootNonCoding,
307
+ parentOwnedDispatch: adaptiveWorkflow.parentOwnedDispatch,
308
+ childDirectDispatch: adaptiveWorkflow.childDirectDispatch,
309
+ bodyStored: false,
310
+ } : undefined,
311
+ documentationRefs,
312
+ roomPolicy: room.policy,
313
+ promptBodiesStored: false,
314
+ outputBodiesStored: false,
315
+ bodyStored: false,
316
+ generatedAt: new Date().toISOString(),
317
+ };
318
+
319
+ const evidenceIndex = {
320
+ schema: "zob.evidence-index.v1",
321
+ runId: input.runId,
322
+ artifacts: [
323
+ { artifact: "manifest.json", kind: "manifest", hash: existsSync(join(input.runDir, "manifest.json")) ? sha256(readFileSync(join(input.runDir, "manifest.json"), "utf8")) : null },
324
+ { artifact: "orchestration-plan.json", kind: "plan", hash: existsSync(join(input.runDir, "orchestration-plan.json")) ? sha256(readFileSync(join(input.runDir, "orchestration-plan.json"), "utf8")) : null },
325
+ { artifact: "messages.jsonl", kind: "messages", hash: existsSync(join(input.runDir, "messages.jsonl")) ? sha256(readFileSync(join(input.runDir, "messages.jsonl"), "utf8")) : null },
326
+ { artifact: "status.jsonl", kind: "status", hash: existsSync(join(input.runDir, "status.jsonl")) ? sha256(readFileSync(join(input.runDir, "status.jsonl"), "utf8")) : null },
327
+ { artifact: "validation.json", kind: "validation", hash: existsSync(join(input.runDir, "validation.json")) ? sha256(readFileSync(join(input.runDir, "validation.json"), "utf8")) : null },
328
+ ...adaptiveWorkflowRefs.map((artifact) => ({ artifact, kind: "adaptive_workflow", hash: existsSync(join(input.runDir, artifact)) ? sha256(readFileSync(join(input.runDir, artifact), "utf8")) : null })),
329
+ ],
330
+ comsMirrored: input.comsMirrored ?? 0,
331
+ promptBodiesStored: false,
332
+ outputBodiesStored: false,
333
+ generatedAt: new Date().toISOString(),
334
+ };
335
+
336
+ writeFileSync(join(roomDir, "room.json"), JSON.stringify(room, null, 2), "utf8");
337
+ writeFileSync(join(roomDir, "messages.jsonl"), roomMessages.map((message) => JSON.stringify(message)).join("\n") + (roomMessages.length > 0 ? "\n" : ""), "utf8");
338
+ writeFileSync(join(roomDir, "status.jsonl"), roomStatuses.map((status) => JSON.stringify(status)).join("\n") + (roomStatuses.length > 0 ? "\n" : ""), "utf8");
339
+ writeFileSync(join(roomDir, "decisions.jsonl"), decisions.map((decision) => JSON.stringify(decision)).join("\n") + "\n", "utf8");
340
+ writeFileSync(join(roomDir, "blockers.jsonl"), blockers.map((blocker) => JSON.stringify(blocker)).join("\n") + (blockers.length > 0 ? "\n" : ""), "utf8");
341
+ writeFileSync(join(roomDir, "context-pack.json"), JSON.stringify(contextPack, null, 2), "utf8");
342
+ writeFileSync(join(roomDir, "evidence-index.json"), JSON.stringify(evidenceIndex, null, 2), "utf8");
343
+ return { roomDir, artifacts: ["room/room.json", "room/messages.jsonl", "room/status.jsonl", "room/decisions.jsonl", "room/blockers.jsonl", "room/context-pack.json", "room/evidence-index.json"] };
344
+ }
345
+
346
+ export { buildOrchestrationMessages, buildOrchestrationStatuses, orchestrationLedger, writeOrchestrationMessages, writeOrchestrationStatuses };
@@ -0,0 +1,134 @@
1
+ import { existsSync, mkdirSync, unlinkSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+
4
+ import { resolveComputeProfile } from "../compute-profile.js";
5
+ import { SUPERVISED_SMOKE_CHILD_TOOLS } from "../constants.js";
6
+ import type { OrchestrateExecutionMode, OrchestrateRunInput, OrchestrateRunResult, TeamDefinition } from "../types.js";
7
+ import { mirrorOrchestrationToComs } from "../topology/coms.js";
8
+ import { loadOrchestrationProfile, teamDefinitionFromOrchestrationProfile, validateOrchestrateRunInputs } from "../topology/orchestration-profiles.js";
9
+ import { loadTeamDefinition } from "../topology/teams.js";
10
+ import { sha256 } from "../utils/hashing.js";
11
+ import { safeRunId } from "../utils/paths.js";
12
+ import { isRecord } from "../utils/records.js";
13
+ import { buildInitialAdaptiveDelegationGovernorState, normalizeAdaptiveDelegationPolicy } from "./adaptive-delegation.js";
14
+ import { writeAdaptiveWorkflowArtifacts } from "./adaptive-workflow.js";
15
+ import { buildOrchestrationPlan, redactBodyLikeFieldsForPersistence, redactOrchestrationPlanForPersistence } from "./plan.js";
16
+ import { buildOrchestrationMessages, buildOrchestrationStatuses, orchestrationLedger, writeOrchestrationMessages, writeOrchestrationRoomArtifacts, writeOrchestrationStatuses } from "./room.js";
17
+
18
+ export function runOrchestrateRun(repoRoot: string, input: OrchestrateRunInput): OrchestrateRunResult {
19
+ const errors = validateOrchestrateRunInputs(repoRoot, input);
20
+ const runId = safeRunId(input.run_id, "orchestrate");
21
+ const runDir = join(repoRoot, "reports", "orchestrations", runId);
22
+ if (existsSync(runDir) && !input.resume) errors.push(`Orchestration run directory already exists. Use resume=true or choose another run_id: ${runDir}`);
23
+ if (errors.length > 0) return { runId, runDir, status: "failed_preflight", tasks: 0, artifacts: [], errors };
24
+
25
+ mkdirSync(runDir, { recursive: true });
26
+ const sentinelPath = join(runDir, "DONE.sentinel");
27
+ if (existsSync(sentinelPath)) unlinkSync(sentinelPath);
28
+ const profile = input.profile ? loadOrchestrationProfile(repoRoot, input.profile) : undefined;
29
+ const team = input.profile ? undefined : loadTeamDefinition(repoRoot, input.team ?? "zob-core");
30
+ const definition = profile?.definition ? teamDefinitionFromOrchestrationProfile(profile.definition) : team?.definition as TeamDefinition;
31
+ const execution: OrchestrateExecutionMode = input.execution ?? "plan_only";
32
+ const adaptiveDelegation = normalizeAdaptiveDelegationPolicy(input.adaptive_delegation);
33
+ const computeProfile = resolveComputeProfile(repoRoot, {
34
+ runId,
35
+ domain: "orchestration",
36
+ requestedProfile: input.compute_profile ?? "auto",
37
+ targetPath: ".pi/teams",
38
+ taskHash: sha256(input.original_user_ask ?? input.goal),
39
+ computeCaps: input.compute_caps,
40
+ riskHints: execution === "supervised_readonly" ? ["durable"] : [],
41
+ });
42
+ const originalUserAsk = input.original_user_ask ?? input.goal;
43
+ const persistedInput = adaptiveDelegation.enabled || input.compute_profile || input.compute_caps ? { ...input, adaptive_delegation: adaptiveDelegation, compute_profile_resolution: computeProfile } : input;
44
+ const plan = buildOrchestrationPlan(definition, input, { runId, runDir, execution });
45
+ const tasks = Array.isArray(plan.tasks) ? plan.tasks.length : 0;
46
+ const adaptiveArtifacts = adaptiveDelegation.enabled ? ["adaptive-delegation-policy.json", "delegation-governor-state.json", "delegation-requests.json", "delegation-decisions.json", "delegation-oracle-decisions.json", "delegation-dispatches.json", "adaptive-delegation-summary.md"] : [];
47
+ const adaptiveWorkflow = writeAdaptiveWorkflowArtifacts({ repoRoot, runDir, runId, definition, profileDefinition: profile?.definition, input, computeProfile, adaptiveDelegation, execution, goal: input.goal, originalUserAsk });
48
+ const adaptiveWorkflowArtifacts = adaptiveWorkflow.artifacts;
49
+
50
+ const redactPersistentBodies = execution === "supervised_readonly" || input.profile === "adaptive-chief-vision";
51
+ const manifest = { team: definition, input: persistedInput, sourceTeamPath: team?.teamPath, sourceProfilePath: profile?.profilePath, execution, computeProfile, adaptiveWorkflow: adaptiveWorkflow.context };
52
+ writeFileSync(join(runDir, "manifest.json"), JSON.stringify(redactPersistentBodies ? redactBodyLikeFieldsForPersistence(manifest) : manifest, null, 2), "utf8");
53
+ writeFileSync(join(runDir, "compute-profile-resolution.json"), JSON.stringify(computeProfile, null, 2), "utf8");
54
+ const persistedPlan = redactPersistentBodies ? redactOrchestrationPlanForPersistence(plan) : plan;
55
+ writeFileSync(join(runDir, "orchestration-plan.json"), JSON.stringify(persistedPlan, null, 2), "utf8");
56
+ const messages = buildOrchestrationMessages(definition, plan, runId, execution);
57
+ const statuses = buildOrchestrationStatuses(messages, runId, execution);
58
+ writeOrchestrationMessages(runDir, messages);
59
+ writeOrchestrationStatuses(runDir, statuses, runId, execution);
60
+ const comsMirrored = mirrorOrchestrationToComs(repoRoot, definition, messages);
61
+ if (adaptiveDelegation.enabled) {
62
+ const rootGoalHash = sha256(originalUserAsk);
63
+ const governorState = buildInitialAdaptiveDelegationGovernorState({ runId, rootGoalHash, policy: adaptiveDelegation });
64
+ writeFileSync(join(runDir, "adaptive-delegation-policy.json"), JSON.stringify(adaptiveDelegation, null, 2), "utf8");
65
+ writeFileSync(join(runDir, "delegation-governor-state.json"), JSON.stringify(governorState, null, 2), "utf8");
66
+ writeFileSync(join(runDir, "delegation-requests.json"), JSON.stringify({ schema: "zob.delegation-request-set.v1", runId, requests: [], bodyStored: false, promptBodiesStored: false, outputBodiesStored: false }, null, 2), "utf8");
67
+ writeFileSync(join(runDir, "delegation-decisions.json"), JSON.stringify({ schema: "zob.governor-decision-set.v1", runId, decisions: [], bodyStored: false, promptBodiesStored: false, outputBodiesStored: false }, null, 2), "utf8");
68
+ writeFileSync(join(runDir, "delegation-oracle-decisions.json"), JSON.stringify({ schema: "zob.delegation-oracle-decision-set.v1", runId, oracleRequired: 0, decisions: [], liveOracleDispatched: false, bodyStored: false, promptBodiesStored: false, outputBodiesStored: false }, null, 2), "utf8");
69
+ writeFileSync(join(runDir, "delegation-dispatches.json"), JSON.stringify({ schema: "zob.parent-dispatch-contract-set.v1", runId, dispatches: [], dispatchContractsQueued: 0, liveDispatches: 0, adaptiveLiveDispatchEnabled: false, bodyStored: false, promptBodiesStored: false, outputBodiesStored: false }, null, 2), "utf8");
70
+ writeFileSync(join(runDir, "adaptive-delegation-summary.md"), [`# Adaptive Delegation Summary`, ``, `- runId: ${runId}`, `- enabled: ${adaptiveDelegation.enabled}`, `- mode: ${adaptiveDelegation.mode}`, `- dispatch: ${adaptiveDelegation.dispatch}`, `- configuredMaxDepth: ${adaptiveDelegation.configuredMaxDepth}`, `- runtimeMaxDepth: ${adaptiveDelegation.runtimeMaxDepth}`, `- parent_owned_dispatch: ${adaptiveDelegation.parentOwnedDispatch}`, `- child_direct_dispatch: ${adaptiveDelegation.childDirectDispatch}`, `- live_dispatches: 0`, `- sentinel: not written`, ``].join("\n"), "utf8");
71
+ }
72
+ const roomArtifacts = writeOrchestrationRoomArtifacts({ runDir, runId, definition, plan: persistedPlan, messages, statuses, execution, goal: input.goal, originalUserAsk, goalId: input.goal_id, rootTodoId: input.todo_id, comsMirrored, adaptiveWorkflow: adaptiveWorkflow.context });
73
+ orchestrationLedger(runDir, { event: "initialized", runId, team: definition.name, execution });
74
+ orchestrationLedger(runDir, { event: "team_loaded", leads: definition.leads.length, workers: definition.workers.length });
75
+ orchestrationLedger(runDir, { event: "plan_written", tasks, execution, noExecution: true });
76
+ orchestrationLedger(runDir, { event: "messages_written", messages: messages.length, execution, noExecution: true });
77
+ orchestrationLedger(runDir, { event: "status_written", statuses: statuses.length, running: 0, execution, noExecution: true });
78
+ orchestrationLedger(runDir, { event: "coms_mirrored", messages: comsMirrored, path: ".pi/coms/messages.jsonl", execution, noExecution: true });
79
+ orchestrationLedger(runDir, { event: "room_written", artifacts: roomArtifacts.artifacts, path: "room/", execution, noExecution: true });
80
+ if (adaptiveDelegation.enabled) orchestrationLedger(runDir, { event: "adaptive_delegation_policy_written", artifacts: adaptiveArtifacts, execution, noExecution: true, dispatch: adaptiveDelegation.dispatch });
81
+
82
+ const supervisedSmoke = execution === "supervised_smoke" ? {
83
+ schema: "zob.orchestration-supervised-smoke.v1",
84
+ mode: "read_only",
85
+ parentOwnedPreflight: true,
86
+ parentOwnedDispatch: true,
87
+ workerSpawnsWorker: false,
88
+ allowedTools: [...SUPERVISED_SMOKE_CHILD_TOOLS],
89
+ blockedTools: ["bash", "edit", "write", "delegate_agent", "delegate_task", "orchestrate_run", "factory_run", "factory_quarantine_review", "factory_quarantine_activate", "factory_quarantine_verify_activation"],
90
+ liveChildExecution: false,
91
+ modelRouterUsed: false,
92
+ budgetEnforced: false,
93
+ finalGate: {
94
+ status: "planned_not_executed",
95
+ passed: false,
96
+ reason: "supervised_smoke records parent-owned read-only execution metadata without live child/model execution in smoke validation",
97
+ requiresLiveChildEvidence: true,
98
+ },
99
+ } : undefined;
100
+
101
+ const validation = {
102
+ runId,
103
+ team: definition.name,
104
+ execution,
105
+ status: "planned",
106
+ noExecution: true,
107
+ tasks,
108
+ messages: messages.length,
109
+ statuses: statuses.length,
110
+ comsMirrored,
111
+ artifactsPresent: ["manifest.json", "ledger.jsonl", "compute-profile-resolution.json", "orchestration-plan.json", "messages.jsonl", "status.jsonl", "status-snapshot.json", ...adaptiveWorkflowArtifacts, "room/room.json", "room/context-pack.json", "room/evidence-index.json", "final-report.md"].map((artifact) => ({ artifact, exists: artifact === "final-report.md" ? false : existsSync(join(runDir, artifact)) })),
112
+ roomArtifactsPresent: roomArtifacts.artifacts.map((artifact) => ({ artifact, exists: existsSync(join(runDir, artifact)) })),
113
+ room: { schema: "zob.room.v1", path: "room/", contextPack: "room/context-pack.json", evidenceIndex: "room/evidence-index.json", promptBodiesStored: false, outputBodiesStored: false },
114
+ invariants: isRecord(plan.invariants) ? plan.invariants : {},
115
+ todoGraphBinding: input.todo_id ? { goalId: input.goal_id, rootTodoId: input.todo_id, parentOwned: true, bodyStored: false } : undefined,
116
+ supervisedSmoke,
117
+ computeProfile,
118
+ adaptiveDelegation: adaptiveDelegation.enabled ? { schema: "zob.adaptive-delegation-validation.v1", enabled: true, mode: adaptiveDelegation.mode, dispatch: adaptiveDelegation.dispatch, recordDecisionsOnly: adaptiveDelegation.recordDecisionsOnly, configuredMaxDepth: adaptiveDelegation.configuredMaxDepth, runtimeMaxDepth: adaptiveDelegation.runtimeMaxDepth, parentOwnedDispatch: true, childDirectDispatch: false, liveDispatches: 0, advisoryOnly: adaptiveDelegation.dispatch === false, artifacts: adaptiveArtifacts, noExecution: true, bodyStored: false, promptBodiesStored: false, outputBodiesStored: false } : { enabled: false },
119
+ adaptiveWorkflow: adaptiveWorkflow.validationSummary,
120
+ budgetEnforced: false,
121
+ modelRouterUsed: false,
122
+ sentinelWritten: existsSync(join(runDir, "DONE.sentinel")),
123
+ bodyStored: false,
124
+ promptBodiesStored: false,
125
+ outputBodiesStored: false,
126
+ };
127
+ writeFileSync(join(runDir, "validation.json"), JSON.stringify(validation, null, 2), "utf8");
128
+ writeFileSync(join(runDir, "final-report.md"), [`# Orchestration Run Report`, ``, `- runId: ${runId}`, `- team: ${definition.name}`, `- status: planned`, `- execution: ${execution}`, `- tasks: ${tasks}`, `- messages: ${messages.length}`, `- statuses: ${statuses.length}`, `- coms_mirrored: ${comsMirrored}`, `- room: room/context-pack.json`, `- running: 0`, `- child_agents_executed: no`, `- supervised_smoke_read_only: ${execution === "supervised_smoke" ? "yes" : "n/a"}`, `- supervised_readonly: ${execution === "supervised_readonly" ? "yes" : "n/a"}`, `- sentinel: not written`, ``].join("\n"), "utf8");
129
+ const finalValidation = { ...validation, artifactsPresent: ["manifest.json", "ledger.jsonl", "compute-profile-resolution.json", "orchestration-plan.json", "messages.jsonl", "status.jsonl", "status-snapshot.json", ...adaptiveWorkflowArtifacts, "room/room.json", "room/messages.jsonl", "room/status.jsonl", "room/decisions.jsonl", "room/blockers.jsonl", "room/context-pack.json", "room/evidence-index.json", ...adaptiveArtifacts, "validation.json", "final-report.md"].map((artifact) => ({ artifact, exists: existsSync(join(runDir, artifact)) })) };
130
+ writeFileSync(join(runDir, "validation.json"), JSON.stringify(finalValidation, null, 2), "utf8");
131
+ orchestrationLedger(runDir, { event: "planned", tasks, sentinel: "not written" });
132
+
133
+ return { runId, runDir, status: "planned", tasks, artifacts: ["manifest.json", "ledger.jsonl", "compute-profile-resolution.json", "orchestration-plan.json", "messages.jsonl", "status.jsonl", "status-snapshot.json", ...adaptiveWorkflowArtifacts, ...roomArtifacts.artifacts, ...adaptiveArtifacts, "validation.json", "final-report.md"], errors: [] };
134
+ }