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,585 @@
1
+ import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+
4
+ import type { AdaptiveDelegationPolicy, OrchestrateExecutionMode, OrchestrateRunInput, OrchestrationProfileDefinition, TeamDefinition, TeamRoleBase, TeamLead, TeamWorker } from "../types.js";
5
+ import { sha256 } from "../utils/hashing.js";
6
+ import { safeFileStem } from "../utils/paths.js";
7
+ import { isRecord } from "../utils/records.js";
8
+
9
+ const BODY_FREE_SCHEMA_VERSION = "v1";
10
+ const GUIDANCE_SCAN_LIMIT = 200;
11
+ const FORBIDDEN_BODY_KEYS = new Set(["task", "prompt", "output", "body", "content", "patch", "diff", "messages", "transcript", "rawContext", "rawPrompt"]);
12
+ const SECRET_PATH_PATTERN = /(^|\/)\.env($|[./])|(^|\/)(\.ssh|\.aws)(\/|$)|secret|credential|\.pem$|\.p12$|\.pfx$|(^|[-_])key([-_.]|$)/i;
13
+
14
+ export interface AdaptiveWorkflowArtifactsInput {
15
+ repoRoot: string;
16
+ runDir: string;
17
+ runId: string;
18
+ definition: TeamDefinition;
19
+ profileDefinition?: OrchestrationProfileDefinition;
20
+ input: OrchestrateRunInput;
21
+ computeProfile: Record<string, unknown>;
22
+ adaptiveDelegation: AdaptiveDelegationPolicy;
23
+ execution: OrchestrateExecutionMode;
24
+ goal: string;
25
+ originalUserAsk: string;
26
+ }
27
+
28
+ export interface AdaptiveWorkflowArtifactsResult {
29
+ artifacts: string[];
30
+ context: Record<string, unknown>;
31
+ validationSummary: Record<string, unknown>;
32
+ }
33
+
34
+ type GuidanceKind = "root_doc" | "layer_doc" | "rule" | "skill" | "prompt" | "agent" | "output_contract" | "runtime_doc";
35
+
36
+ type RoleLike = (TeamRoleBase | TeamLead | TeamWorker) & { roleType?: string; leadId?: string };
37
+
38
+ function profileRank(profile: string | undefined): number {
39
+ return ["low", "medium", "high", "xhigh", "max"].indexOf(profile ?? "low");
40
+ }
41
+
42
+ function asString(value: unknown, fallback: string): string {
43
+ return typeof value === "string" && value.trim().length > 0 ? value : fallback;
44
+ }
45
+
46
+ function asNumber(value: unknown, fallback: number): number {
47
+ return typeof value === "number" && Number.isFinite(value) ? value : fallback;
48
+ }
49
+
50
+ function asBool(value: unknown, fallback: boolean): boolean {
51
+ return typeof value === "boolean" ? value : fallback;
52
+ }
53
+
54
+ function isSafeGuidancePath(path: string): boolean {
55
+ return path.length > 0 && !path.includes("\0") && !path.startsWith("/") && !path.startsWith("../") && !path.includes("/../") && !SECRET_PATH_PATTERN.test(path) && !/(^|\/)(node_modules|dist|build|coverage)(\/|$)/.test(path);
56
+ }
57
+
58
+ function guidanceEntry(repoRoot: string, ref: string, kind: GuidanceKind, extra: Record<string, unknown> = {}): Record<string, unknown> | undefined {
59
+ if (!isSafeGuidancePath(ref)) return undefined;
60
+ const absolute = join(repoRoot, ref);
61
+ if (!existsSync(absolute)) return undefined;
62
+ const stat = statSync(absolute);
63
+ if (!stat.isFile()) return undefined;
64
+ const raw = readFileSync(absolute, "utf8");
65
+ return {
66
+ schema: "zob.guidance-ref.v1",
67
+ ref,
68
+ kind,
69
+ bytes: stat.size,
70
+ sha256: sha256(raw),
71
+ bodyStored: false,
72
+ ...extra,
73
+ };
74
+ }
75
+
76
+ function pushEntry(target: Record<string, unknown>[], repoRoot: string, ref: string, kind: GuidanceKind, extra: Record<string, unknown> = {}): void {
77
+ const entry = guidanceEntry(repoRoot, ref, kind, extra);
78
+ if (entry) target.push(entry);
79
+ }
80
+
81
+ function listFiles(repoRoot: string, relativeDir: string, predicate: (relativePath: string) => boolean, limit = GUIDANCE_SCAN_LIMIT): string[] {
82
+ const root = join(repoRoot, relativeDir);
83
+ if (!existsSync(root)) return [];
84
+ const results: string[] = [];
85
+ const visit = (dir: string, rel: string, depth: number): void => {
86
+ if (results.length >= limit || depth > 3) return;
87
+ for (const entry of readdirSync(dir, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name))) {
88
+ const childRel = rel ? `${rel}/${entry.name}` : entry.name;
89
+ const repoRel = `${relativeDir}/${childRel}`.replace(/\/+/g, "/");
90
+ if (!isSafeGuidancePath(repoRel)) continue;
91
+ const childAbs = join(dir, entry.name);
92
+ if (entry.isDirectory()) visit(childAbs, childRel, depth + 1);
93
+ else if (entry.isFile() && predicate(repoRel)) results.push(repoRel);
94
+ if (results.length >= limit) return;
95
+ }
96
+ };
97
+ visit(root, "", 0);
98
+ return results;
99
+ }
100
+
101
+ function buildGuidanceIndex(repoRoot: string, definition: TeamDefinition): Record<string, unknown> {
102
+ const rootDocs: Record<string, unknown>[] = [];
103
+ const layerDocs: Record<string, unknown>[] = [];
104
+ const rules: Record<string, unknown>[] = [];
105
+ const skills: Record<string, unknown>[] = [];
106
+ const prompts: Record<string, unknown>[] = [];
107
+ const agents: Record<string, unknown>[] = [];
108
+ const outputContracts: Record<string, unknown>[] = [];
109
+
110
+ for (const ref of ["AGENTS.md", "README.md", "docs/ROADMAP.md", "docs/OPERATING_MODEL.md", "docs/ZOB_ADAPTIVE_WORKFLOW_RUNTIME_PLAN.md", "docs/ZOB_RULES_SYSTEM.md"]) {
111
+ pushEntry(rootDocs, repoRoot, ref, "root_doc", { layerId: "project-root" });
112
+ }
113
+ for (const ref of listFiles(repoRoot, ".", (candidate) => /(^|\/)AGENTS\.md$/.test(candidate), 50)) {
114
+ pushEntry(layerDocs, repoRoot, ref, "layer_doc", { layerId: safeFileStem(ref.replace(/\/AGENTS\.md$/, "") || "project-root") });
115
+ }
116
+ for (const ref of listFiles(repoRoot, ".pi/rules", (candidate) => candidate.endsWith(".md"), 80)) pushEntry(rules, repoRoot, ref, "rule");
117
+ for (const ref of listFiles(repoRoot, ".pi/skills", (candidate) => candidate.endsWith("/SKILL.md"), 80)) pushEntry(skills, repoRoot, ref, "skill");
118
+ for (const ref of listFiles(repoRoot, ".pi/prompts", (candidate) => candidate.endsWith(".md"), 80)) pushEntry(prompts, repoRoot, ref, "prompt");
119
+ for (const ref of listFiles(repoRoot, ".pi/agents", (candidate) => candidate.endsWith(".md"), 120)) pushEntry(agents, repoRoot, ref, "agent");
120
+ for (const ref of listFiles(repoRoot, ".pi/output-contracts", (candidate) => candidate.endsWith(".json"), 120)) pushEntry(outputContracts, repoRoot, ref, "output_contract");
121
+
122
+ const roleRefs = [definition.orchestrator, ...definition.leads, ...definition.workers].map((role) => ({
123
+ roleId: role.id,
124
+ agent: role.agent,
125
+ agentRef: `.pi/agents/${safeFileStem(role.agent)}.md`,
126
+ outputContractRef: `.pi/output-contracts/${safeFileStem(role.outputContract)}.json`,
127
+ }));
128
+
129
+ return {
130
+ schema: "zob.guidance-index.v1",
131
+ schemaVersion: BODY_FREE_SCHEMA_VERSION,
132
+ rootDocs,
133
+ layerDocs,
134
+ rules,
135
+ skills,
136
+ prompts,
137
+ agents,
138
+ outputContracts,
139
+ roleRefs,
140
+ totalRefs: rootDocs.length + layerDocs.length + rules.length + skills.length + prompts.length + agents.length + outputContracts.length,
141
+ bodyStored: false,
142
+ promptBodiesStored: false,
143
+ outputBodiesStored: false,
144
+ generatedAt: new Date().toISOString(),
145
+ };
146
+ }
147
+
148
+ function allRoles(definition: TeamDefinition, profileDefinition?: OrchestrationProfileDefinition): RoleLike[] {
149
+ const profileRoles = new Map<string, { roleType?: string; modelClass?: string }>();
150
+ if (profileDefinition) {
151
+ profileRoles.set(profileDefinition.orchestrator.id, { roleType: profileDefinition.orchestrator.roleType, modelClass: profileDefinition.orchestrator.modelClass });
152
+ for (const role of profileDefinition.roles) profileRoles.set(role.id, { roleType: role.roleType, modelClass: role.modelClass });
153
+ }
154
+ const roles: RoleLike[] = [
155
+ { ...definition.orchestrator, roleType: "orchestrator" },
156
+ ...definition.leads.map((role) => ({ ...role, roleType: "lead" })),
157
+ ...definition.workers.map((role) => ({ ...role, roleType: "worker" })),
158
+ ];
159
+ return roles.map((role) => ({ ...role, ...profileRoles.get(role.id) }));
160
+ }
161
+
162
+ const DEFAULT_MODEL_CLASSES: Record<string, Record<string, unknown>> = {
163
+ cheap_scout: { description: "Fast low-risk exploration", downgradeAllowed: true },
164
+ balanced_worker: { description: "Standard execution and QA", downgradeAllowed: true },
165
+ strong_reasoning: { description: "Planning, orchestration, architecture", downgradeAllowed: false },
166
+ strong_oracle: { description: "Critical validation, oracle, security", downgradeAllowed: false },
167
+ high_context: { description: "Large-context synthesis and documentation", downgradeAllowed: false },
168
+ };
169
+
170
+ function chooseModelClass(role: RoleLike): string {
171
+ const text = `${role.id} ${role.agent} ${role.outputContract} ${role.roleType ?? ""}`.toLowerCase();
172
+ const profileModelClass = (role as unknown as Record<string, unknown>).modelClass;
173
+ if (typeof profileModelClass === "string" && profileModelClass.length > 0) return profileModelClass;
174
+ if (text.includes("oracle") || text.includes("security") || text.includes("validation")) return "strong_oracle";
175
+ if (role.roleType === "orchestrator" || role.roleType === "lead" || text.includes("planner")) return "strong_reasoning";
176
+ if (text.includes("explore") || text.includes("scout")) return "cheap_scout";
177
+ if (text.includes("context") || text.includes("documentation") || text.includes("doc")) return "high_context";
178
+ return "balanced_worker";
179
+ }
180
+
181
+ function buildAdaptiveModelPolicy(runId: string, definition: TeamDefinition, profileDefinition?: OrchestrationProfileDefinition): Record<string, unknown> {
182
+ const classes = isRecord(profileDefinition?.modelPolicy?.classes) && Object.keys(profileDefinition?.modelPolicy?.classes ?? {}).length > 0
183
+ ? profileDefinition?.modelPolicy?.classes as Record<string, unknown>
184
+ : DEFAULT_MODEL_CLASSES;
185
+ const roleAssignments = allRoles(definition, profileDefinition).map((role) => {
186
+ const modelClass = chooseModelClass(role);
187
+ const classConfig = isRecord(classes[modelClass]) ? classes[modelClass] as Record<string, unknown> : {};
188
+ return {
189
+ roleId: role.id,
190
+ roleType: role.roleType ?? "role",
191
+ agent: role.agent,
192
+ outputContract: role.outputContract,
193
+ modelClass,
194
+ downgradeAllowed: classConfig.downgradeAllowed === true,
195
+ reasonHash: sha256(JSON.stringify({ roleId: role.id, roleType: role.roleType, agent: role.agent, outputContract: role.outputContract, modelClass })),
196
+ };
197
+ });
198
+ return {
199
+ schema: "zob.adaptive-model-policy.v1",
200
+ runId,
201
+ source: profileDefinition?.modelPolicy ? "orchestration_profile" : "runtime_defaults",
202
+ classes,
203
+ layers: {
204
+ root: roleAssignments.filter((role) => role.roleType === "orchestrator").map((role) => role.modelClass),
205
+ leads: roleAssignments.filter((role) => role.roleType === "lead").map((role) => role.modelClass),
206
+ workers: roleAssignments.filter((role) => role.roleType === "worker").map((role) => role.modelClass),
207
+ tempAgentCreator: "strong_reasoning",
208
+ oracleSecurity: "strong_oracle",
209
+ },
210
+ roleAssignments,
211
+ downgradePolicy: "blocked_for_oracle_security",
212
+ criticalNoDowngradeRoles: roleAssignments.filter((role) => role.modelClass === "strong_oracle" || role.modelClass === "strong_reasoning").map((role) => role.roleId),
213
+ bodyStored: false,
214
+ promptBodiesStored: false,
215
+ outputBodiesStored: false,
216
+ };
217
+ }
218
+
219
+ function buildAdaptiveCaps(input: AdaptiveWorkflowArtifactsInput): Record<string, unknown> {
220
+ const caps = isRecord(input.computeProfile.caps) ? input.computeProfile.caps : {};
221
+ const effectiveProfile = asString(input.computeProfile.effectiveProfile, "low");
222
+ const maxDelegationDepth = asNumber(caps.maxDelegationDepth, input.adaptiveDelegation.runtimeMaxDepth ?? 1);
223
+ const maxTotalAgents = asNumber(caps.maxAgents, input.adaptiveDelegation.maxTotalAgents ?? Math.max(1, input.definition.leads.length + input.definition.workers.length + 1));
224
+ const highProfile = profileRank(effectiveProfile) >= profileRank("high");
225
+ return {
226
+ schema: "zob.adaptive-workflow-caps.v1",
227
+ maxTodoDepth: Math.max(2, maxDelegationDepth + 2),
228
+ maxDelegationDepth,
229
+ maxChildrenPerTodo: input.adaptiveDelegation.nodeFanoutMax,
230
+ maxTotalAgents,
231
+ maxParallelAgents: asNumber(caps.maxParallel, input.adaptiveDelegation.globalParallelMax ?? 1),
232
+ maxAgentsPerWave: Math.max(1, Math.min(asNumber(caps.maxParallel, input.adaptiveDelegation.globalParallelMax ?? 1), input.adaptiveDelegation.globalParallelMax ?? 1, maxTotalAgents)),
233
+ maxIterations: asNumber(caps.maxIterations, 1),
234
+ maxDurationMs: caps.maxDurationMs,
235
+ maxCostUsd: caps.maxCostUsd,
236
+ strictBudgetRequired: asBool(caps.strictBudgetRequired, input.adaptiveDelegation.strictBudgetRequired ?? highProfile),
237
+ oracleRequired: asBool(caps.oracleRequired, highProfile || input.adaptiveDelegation.oracle !== "off"),
238
+ humanApprovalRequired: effectiveProfile === "max" || input.adaptiveDelegation.maxTotalAgentsWithOracle > 20,
239
+ sandboxRequiredForWrites: true,
240
+ liveComsRequired: input.execution === "supervised_readonly",
241
+ allowTempAgents: highProfile || input.adaptiveDelegation.maxTotalAgents > 4,
242
+ allowLargeScaleAgentPool: input.adaptiveDelegation.maxTotalAgentsWithOracle > 20,
243
+ bodyStored: false,
244
+ promptBodiesStored: false,
245
+ outputBodiesStored: false,
246
+ };
247
+ }
248
+
249
+ function buildAdaptiveScalePolicy(input: AdaptiveWorkflowArtifactsInput, caps: Record<string, unknown>): Record<string, unknown> {
250
+ const maxTotalAgents = asNumber(caps.maxTotalAgents, 1);
251
+ const maxParallelAgents = asNumber(caps.maxParallelAgents, 1);
252
+ const maxAgentsPerWave = Math.max(1, asNumber(caps.maxAgentsPerWave, 1));
253
+ const maxWaves = Math.max(1, Math.ceil(maxTotalAgents / maxAgentsPerWave));
254
+ const highScale = input.adaptiveDelegation.maxTotalAgentsWithOracle > 20 || maxTotalAgents > 20;
255
+ return {
256
+ schema: "zob.adaptive-scale-policy.v1",
257
+ runId: input.runId,
258
+ requestedScale: highScale ? "large" : "default",
259
+ maxTotalAgents,
260
+ maxTotalAgentsWithOracle: input.adaptiveDelegation.maxTotalAgentsWithOracle,
261
+ maxParallelAgents,
262
+ maxAgentsPerWave,
263
+ maxWaves,
264
+ waveSchedulerRequired: true,
265
+ requiresBudget: caps.strictBudgetRequired === true,
266
+ requiresScaleApproval: highScale,
267
+ scaleApprovalPresent: Boolean(input.adaptiveDelegation.scaleApproval),
268
+ requiresOracleAfterWave: highScale || caps.oracleRequired === true,
269
+ duplicateDetectionRequired: true,
270
+ stalePeerBlocksCompletion: true,
271
+ blocks: highScale && !input.adaptiveDelegation.scaleApproval ? ["scale_approval_missing"] : [],
272
+ bodyStored: false,
273
+ promptBodiesStored: false,
274
+ outputBodiesStored: false,
275
+ };
276
+ }
277
+
278
+ function buildAdaptivePromptPolicy(input: AdaptiveWorkflowArtifactsInput, caps: Record<string, unknown>): { policy: Record<string, unknown>; stackHashes: Record<string, unknown> } {
279
+ const components = [
280
+ { name: "root_non_coding", hash: sha256("root cannot edit/write/bash directly in Chief Vision/orchestrator mode"), required: true },
281
+ { name: "goal_hash", hash: sha256(input.goal), required: true },
282
+ { name: "original_user_ask_hash", hash: sha256(input.originalUserAsk), required: true },
283
+ { name: "todo_graph_policy", hash: sha256("all delegations/messages/evidence attach to TODO nodes when goal TODOs are active"), required: true },
284
+ { name: "compute_caps", hash: sha256(JSON.stringify(caps)), required: true },
285
+ { name: "model_policy", hash: sha256("model policy artifact required per layer/agent"), required: true },
286
+ { name: "documentation_policy", hash: sha256("documentation policy and guidance index required for multi-layer runs"), required: true },
287
+ { name: "temp_agent_policy", hash: sha256("temp agents are run-scoped proposal-only until validated"), required: true },
288
+ { name: "no_ship_gates", hash: sha256("no completion without evidence/oracle/no_ship=false"), required: true },
289
+ ];
290
+ return {
291
+ policy: {
292
+ schema: "zob.adaptive-prompt-policy.v1",
293
+ runId: input.runId,
294
+ rootRoleId: input.definition.orchestrator.id,
295
+ rootMode: "chief_vision_orchestrator",
296
+ rootCanWriteDirectly: false,
297
+ rootDirectWriteToolsBlocked: ["bash", "edit", "write"],
298
+ delegationToolsParentOwned: true,
299
+ promptBodiesStored: false,
300
+ outputBodiesStored: false,
301
+ bodyStored: false,
302
+ components,
303
+ },
304
+ stackHashes: {
305
+ schema: "zob.prompt-stack-hashes.v1",
306
+ runId: input.runId,
307
+ algorithm: "sha256",
308
+ components,
309
+ stackHash: sha256(JSON.stringify(components.map((component) => [component.name, component.hash]))),
310
+ bodyStored: false,
311
+ promptBodiesStored: false,
312
+ outputBodiesStored: false,
313
+ },
314
+ };
315
+ }
316
+
317
+ function buildDocumentationPolicy(runId: string, definition: TeamDefinition, guidanceIndex: Record<string, unknown>): Record<string, unknown> {
318
+ const rootDocs = Array.isArray(guidanceIndex.rootDocs) ? guidanceIndex.rootDocs.filter(isRecord).map((doc) => doc.ref).filter((ref): ref is string => typeof ref === "string") : [];
319
+ const layerDocRefs = Array.isArray(guidanceIndex.layerDocs) ? guidanceIndex.layerDocs.filter(isRecord).map((doc) => doc.ref).filter((ref): ref is string => typeof ref === "string") : [];
320
+ const ruleRefs = Array.isArray(guidanceIndex.rules) ? guidanceIndex.rules.filter(isRecord).map((doc) => doc.ref).filter((ref): ref is string => typeof ref === "string") : [];
321
+ const roleDocs = [definition.orchestrator, ...definition.leads, ...definition.workers].map((role) => ({
322
+ roleId: role.id,
323
+ refs: [
324
+ `.pi/agents/${safeFileStem(role.agent)}.md`,
325
+ `.pi/output-contracts/${safeFileStem(role.outputContract)}.json`,
326
+ ...ruleRefs.slice(0, 4),
327
+ ].filter(isSafeGuidancePath),
328
+ }));
329
+ return {
330
+ schema: "zob.adaptive-documentation-policy.v1",
331
+ runId,
332
+ rootDocs,
333
+ layerDocs: [
334
+ { layerId: "project-root", paths: rootDocs, appliesToRoles: [definition.orchestrator.id, ...definition.leads.map((lead) => lead.id)] },
335
+ { layerId: "runtime-layers", paths: layerDocRefs, appliesToRoles: [definition.orchestrator.id, ...definition.leads.map((lead) => lead.id), ...definition.workers.map((worker) => worker.id)] },
336
+ { layerId: "rules", paths: ruleRefs, appliesToRoles: [definition.orchestrator.id, ...definition.leads.map((lead) => lead.id), ...definition.workers.map((worker) => worker.id)] },
337
+ ],
338
+ roleDocs,
339
+ runDocs: ["adaptive-workflow-run.json", "prompt-policy.json", "prompt-stack-hashes.json", "model-policy.json", "scale-policy.json", "documentation-policy.json", "guidance-index.json"],
340
+ writebackPolicy: "human_approval_required",
341
+ maxDocsPerAgent: 12,
342
+ maxDocContextTokens: 4000,
343
+ bodyStored: false,
344
+ promptBodiesStored: false,
345
+ outputBodiesStored: false,
346
+ };
347
+ }
348
+
349
+ function buildDocPacks(definition: TeamDefinition, documentationPolicy: Record<string, unknown>, guidanceIndex: Record<string, unknown>): { layerDocPack: Record<string, unknown>; roleDocPacks: Record<string, unknown>; writebackProposals: Record<string, unknown> } {
350
+ const maxDocs = asNumber(documentationPolicy.maxDocsPerAgent, 12);
351
+ const layerDocPack = {
352
+ schema: "zob.layer-doc-pack.v1",
353
+ layers: documentationPolicy.layerDocs,
354
+ guidanceIndexHash: sha256(JSON.stringify(guidanceIndex)),
355
+ bodyStored: false,
356
+ promptBodiesStored: false,
357
+ outputBodiesStored: false,
358
+ };
359
+ const roleDocPacks = {
360
+ schema: "zob.role-doc-packs.v1",
361
+ packs: [definition.orchestrator, ...definition.leads, ...definition.workers].map((role) => {
362
+ const roleDoc = Array.isArray(documentationPolicy.roleDocs) ? documentationPolicy.roleDocs.find((doc) => isRecord(doc) && doc.roleId === role.id) : undefined;
363
+ const refs = isRecord(roleDoc) && Array.isArray(roleDoc.refs) ? roleDoc.refs.filter((ref): ref is string => typeof ref === "string").slice(0, maxDocs) : [];
364
+ return { roleId: role.id, agent: role.agent, refs, guidanceIndexHash: sha256(JSON.stringify({ roleId: role.id, refs })), bodyStored: false };
365
+ }),
366
+ bodyStored: false,
367
+ promptBodiesStored: false,
368
+ outputBodiesStored: false,
369
+ };
370
+ const writebackProposals = {
371
+ schema: "zob.doc-writeback-proposal-set.v1",
372
+ proposals: [],
373
+ writebackPolicy: documentationPolicy.writebackPolicy,
374
+ durableWritesPerformed: false,
375
+ autoPromotion: false,
376
+ requiresReview: true,
377
+ bodyStored: false,
378
+ promptBodiesStored: false,
379
+ outputBodiesStored: false,
380
+ };
381
+ return { layerDocPack, roleDocPacks, writebackProposals };
382
+ }
383
+
384
+ function buildTempAgentRoster(input: AdaptiveWorkflowArtifactsInput, caps: Record<string, unknown>): Record<string, unknown> {
385
+ return {
386
+ schema: "zob.temp-agent-roster.v1",
387
+ runId: input.runId,
388
+ allowTempAgents: caps.allowTempAgents === true,
389
+ requestKind: "AGENT_CREATE_REQUEST.v1",
390
+ tempAgentCardSchema: "zob.temp-agent-card.v1",
391
+ tempAgents: [],
392
+ pendingCreateRequests: [],
393
+ durableAgentWritesPerformed: false,
394
+ promotionStatus: "proposal",
395
+ promotionRequires: ["run_finished", "oracle_PASS_no_ship_false", "repeated_usefulness", "human_approval", "smoke_test"],
396
+ bodyStored: false,
397
+ promptBodiesStored: false,
398
+ outputBodiesStored: false,
399
+ };
400
+ }
401
+
402
+ function buildFactoryCandidate(input: AdaptiveWorkflowArtifactsInput): Record<string, unknown> {
403
+ return {
404
+ schema: "zob.workflow-to-factory-candidate.v1",
405
+ runId: input.runId,
406
+ candidateStatus: "not_candidate_until_workflow_validated",
407
+ repeatableWorkflowDetected: false,
408
+ promotionReady: false,
409
+ promotionPerformed: false,
410
+ requiresSmoke: true,
411
+ requiresPilot: true,
412
+ requiresOracle: true,
413
+ requiresHumanApproval: true,
414
+ bodyStored: false,
415
+ promptBodiesStored: false,
416
+ outputBodiesStored: false,
417
+ };
418
+ }
419
+
420
+ function buildWorkflowRun(input: AdaptiveWorkflowArtifactsInput, caps: Record<string, unknown>): Record<string, unknown> {
421
+ const requestedProfile = asString(input.computeProfile.requestedProfile, input.input.compute_profile ?? "auto");
422
+ const effectiveProfile = asString(input.computeProfile.effectiveProfile, "low");
423
+ return {
424
+ schema: "zob.adaptive-workflow-run.v1",
425
+ runId: input.runId,
426
+ goalHash: sha256(input.goal),
427
+ originalUserAskHash: sha256(input.originalUserAsk),
428
+ goalStored: false,
429
+ rootRole: "chief_vision",
430
+ rootRoleId: input.definition.orchestrator.id,
431
+ status: "planning",
432
+ completionClaim: "not_complete",
433
+ rootCompletionRequiresOracle: true,
434
+ executionMode: input.execution,
435
+ liveExecutionStatus: input.execution === "supervised_readonly" ? "supervised_readonly_metadata_only" : "not_started",
436
+ writeCapableExecution: false,
437
+ durableWritesPerformed: false,
438
+ requestedComputeProfile: requestedProfile,
439
+ effectiveComputeProfile: effectiveProfile,
440
+ caps,
441
+ todoGraphRef: input.input.todo_id ? `goal:${input.input.goal_id ?? "active"}/todo:${input.input.todo_id}` : "runtime-goal-todos-if-active",
442
+ todoGraphBinding: input.input.todo_id ? { goalId: input.input.goal_id, rootTodoId: input.input.todo_id, parentOwned: true, attachmentPolicy: "messages_delegations_blockers_claims_evidence_attach_to_todo", bodyStored: false } : undefined,
443
+ roomRef: "room/room.json",
444
+ factoryCandidateRef: "factory-candidate.json",
445
+ artifacts: ["prompt-policy.json", "prompt-stack-hashes.json", "model-policy.json", "scale-policy.json", "documentation-policy.json", "guidance-index.json", "agents/temp-agent-cards.json"],
446
+ bodyStored: false,
447
+ promptBodiesStored: false,
448
+ outputBodiesStored: false,
449
+ generatedAt: new Date().toISOString(),
450
+ };
451
+ }
452
+
453
+ function hasForbiddenBodyKeys(value: unknown): boolean {
454
+ if (!value || typeof value !== "object") return false;
455
+ if (Array.isArray(value)) return value.some(hasForbiddenBodyKeys);
456
+ return Object.entries(value as Record<string, unknown>).some(([key, child]) => FORBIDDEN_BODY_KEYS.has(key) || hasForbiddenBodyKeys(child));
457
+ }
458
+
459
+ function bodyFlagsFalse(value: unknown): boolean {
460
+ return isRecord(value) && value.bodyStored === false && value.promptBodiesStored === false && value.outputBodiesStored === false;
461
+ }
462
+
463
+ export function validateAdaptiveWorkflowArtifacts(artifacts: Record<string, unknown>): string[] {
464
+ const errors: string[] = [];
465
+ for (const [name, artifact] of Object.entries(artifacts)) {
466
+ if (!isRecord(artifact)) {
467
+ errors.push(`${name} must be an object`);
468
+ continue;
469
+ }
470
+ if (!bodyFlagsFalse(artifact)) errors.push(`${name} must keep bodyStored/promptBodiesStored/outputBodiesStored false`);
471
+ if (hasForbiddenBodyKeys(artifact)) errors.push(`${name} contains forbidden raw body-like keys`);
472
+ }
473
+ const workflowRun = artifacts.workflowRun;
474
+ const promptPolicy = artifacts.promptPolicy;
475
+ const modelPolicy = artifacts.modelPolicy;
476
+ const scalePolicy = artifacts.scalePolicy;
477
+ const documentationPolicy = artifacts.documentationPolicy;
478
+ const guidanceIndex = artifacts.guidanceIndex;
479
+ const writebackProposals = artifacts.writebackProposals;
480
+ const tempAgentRoster = artifacts.tempAgentRoster;
481
+ const factoryCandidate = artifacts.factoryCandidate;
482
+ if (!isRecord(workflowRun) || workflowRun.schema !== "zob.adaptive-workflow-run.v1") errors.push("workflowRun schema mismatch");
483
+ if (isRecord(workflowRun)) {
484
+ if (workflowRun.status === "complete" || workflowRun.completionClaim === "complete") errors.push("workflowRun must not claim root completion");
485
+ if (workflowRun.rootCompletionRequiresOracle !== true) errors.push("workflowRun root completion must require oracle");
486
+ if (workflowRun.writeCapableExecution !== false || workflowRun.durableWritesPerformed !== false) errors.push("workflowRun must not claim write-capable or durable execution");
487
+ if (!["not_started", "supervised_readonly_metadata_only"].includes(asString(workflowRun.liveExecutionStatus, ""))) errors.push("workflowRun liveExecutionStatus must avoid live completion overclaim");
488
+ }
489
+ if (!isRecord(promptPolicy) || promptPolicy.rootCanWriteDirectly !== false) errors.push("promptPolicy must block direct root coding");
490
+ if (!isRecord(modelPolicy) || modelPolicy.downgradePolicy !== "blocked_for_oracle_security") errors.push("modelPolicy must block oracle/security downgrades");
491
+ if (!isRecord(scalePolicy) || scalePolicy.stalePeerBlocksCompletion !== true || scalePolicy.duplicateDetectionRequired !== true) errors.push("scalePolicy must require stale/duplicate safeguards");
492
+ if (isRecord(scalePolicy) && scalePolicy.requestedScale !== "default" && scalePolicy.requiresScaleApproval !== true) errors.push("large scale requires explicit scale approval gate");
493
+ if (!isRecord(documentationPolicy) || !Array.isArray(documentationPolicy.roleDocs) || documentationPolicy.writebackPolicy !== "human_approval_required") errors.push("documentationPolicy must include role docs and human-approved durable writeback");
494
+ if (!isRecord(guidanceIndex) || asNumber(guidanceIndex.totalRefs, 0) < 1) errors.push("guidanceIndex must include at least one guidance ref");
495
+ if (!isRecord(writebackProposals) || writebackProposals.writebackPolicy !== "human_approval_required" || writebackProposals.durableWritesPerformed !== false || writebackProposals.autoPromotion !== false || writebackProposals.requiresReview !== true) errors.push("writebackProposals must remain proposal-only with human review and no durable writes");
496
+ if (!isRecord(tempAgentRoster) || tempAgentRoster.durableAgentWritesPerformed !== false || tempAgentRoster.promotionStatus !== "proposal") errors.push("tempAgentRoster must remain proposal-only and must not perform durable agent writes");
497
+ if (isRecord(tempAgentRoster)) {
498
+ const promotionRequires = Array.isArray(tempAgentRoster.promotionRequires) ? tempAgentRoster.promotionRequires : [];
499
+ for (const requiredGate of ["oracle_PASS_no_ship_false", "human_approval", "smoke_test"]) {
500
+ if (!promotionRequires.includes(requiredGate)) errors.push(`tempAgentRoster promotion must require ${requiredGate}`);
501
+ }
502
+ }
503
+ if (!isRecord(factoryCandidate) || factoryCandidate.promotionPerformed !== false || factoryCandidate.requiresOracle !== true || factoryCandidate.requiresHumanApproval !== true) errors.push("factoryCandidate must not promote without oracle and human approval gates");
504
+ return errors;
505
+ }
506
+
507
+ function writeJson(runDir: string, relativePath: string, value: Record<string, unknown>): string {
508
+ const absolute = join(runDir, relativePath);
509
+ mkdirSync(dirname(absolute), { recursive: true });
510
+ writeFileSync(absolute, JSON.stringify(value, null, 2), "utf8");
511
+ return relativePath;
512
+ }
513
+
514
+ function ensureSubdirs(runDir: string): void {
515
+ mkdirSync(join(runDir, "agents"), { recursive: true });
516
+ mkdirSync(join(runDir, "docs"), { recursive: true });
517
+ }
518
+
519
+ export function writeAdaptiveWorkflowArtifacts(input: AdaptiveWorkflowArtifactsInput): AdaptiveWorkflowArtifactsResult {
520
+ ensureSubdirs(input.runDir);
521
+ const caps = buildAdaptiveCaps(input);
522
+ const workflowRun = buildWorkflowRun(input, caps);
523
+ const modelPolicy = buildAdaptiveModelPolicy(input.runId, input.definition, input.profileDefinition);
524
+ const scalePolicy = buildAdaptiveScalePolicy(input, caps);
525
+ const { policy: promptPolicy, stackHashes } = buildAdaptivePromptPolicy(input, caps);
526
+ const guidanceIndex = buildGuidanceIndex(input.repoRoot, input.definition);
527
+ const documentationPolicy = buildDocumentationPolicy(input.runId, input.definition, guidanceIndex);
528
+ const { layerDocPack, roleDocPacks, writebackProposals } = buildDocPacks(input.definition, documentationPolicy, guidanceIndex);
529
+ const tempAgentRoster = buildTempAgentRoster(input, caps);
530
+ const factoryCandidate = buildFactoryCandidate(input);
531
+ const artifactSet = { workflowRun, promptPolicy, stackHashes, modelPolicy, scalePolicy, documentationPolicy, guidanceIndex, layerDocPack, roleDocPacks, writebackProposals, tempAgentRoster, factoryCandidate };
532
+ const validationErrors = validateAdaptiveWorkflowArtifacts(artifactSet);
533
+ const validationSummary = {
534
+ schema: "zob.adaptive-workflow-artifacts-validation.v1",
535
+ runId: input.runId,
536
+ valid: validationErrors.length === 0,
537
+ errors: validationErrors,
538
+ rootNonCoding: promptPolicy.rootCanWriteDirectly === false,
539
+ modelPolicyPresent: true,
540
+ scalePolicyPresent: true,
541
+ documentationPolicyPresent: true,
542
+ tempAgentRosterPresent: true,
543
+ factoryCandidatePresent: true,
544
+ bodyStored: false,
545
+ promptBodiesStored: false,
546
+ outputBodiesStored: false,
547
+ generatedAt: new Date().toISOString(),
548
+ };
549
+ const artifacts = [
550
+ writeJson(input.runDir, "adaptive-workflow-run.json", workflowRun),
551
+ writeJson(input.runDir, "prompt-policy.json", promptPolicy),
552
+ writeJson(input.runDir, "prompt-stack-hashes.json", stackHashes),
553
+ writeJson(input.runDir, "model-policy.json", modelPolicy),
554
+ writeJson(input.runDir, "scale-policy.json", scalePolicy),
555
+ writeJson(input.runDir, "documentation-policy.json", documentationPolicy),
556
+ writeJson(input.runDir, "guidance-index.json", guidanceIndex),
557
+ writeJson(input.runDir, "agents/temp-agent-cards.json", tempAgentRoster),
558
+ writeJson(input.runDir, "docs/layer-doc-pack.json", layerDocPack),
559
+ writeJson(input.runDir, "docs/role-doc-packs.json", roleDocPacks),
560
+ writeJson(input.runDir, "docs/writeback-proposals.json", writebackProposals),
561
+ writeJson(input.runDir, "factory-candidate.json", factoryCandidate),
562
+ writeJson(input.runDir, "adaptive-workflow-validation.json", validationSummary),
563
+ ];
564
+ return {
565
+ artifacts,
566
+ context: {
567
+ schema: "zob.adaptive-workflow-context.v1",
568
+ runId: input.runId,
569
+ adaptiveWorkflowRefs: artifacts,
570
+ modelPolicyRef: "model-policy.json",
571
+ scalePolicyRef: "scale-policy.json",
572
+ documentationPolicyRef: "documentation-policy.json",
573
+ guidanceIndexRef: "guidance-index.json",
574
+ tempAgentRosterRef: "agents/temp-agent-cards.json",
575
+ promptPolicyRef: "prompt-policy.json",
576
+ rootNonCoding: true,
577
+ parentOwnedDispatch: true,
578
+ childDirectDispatch: false,
579
+ bodyStored: false,
580
+ promptBodiesStored: false,
581
+ outputBodiesStored: false,
582
+ },
583
+ validationSummary,
584
+ };
585
+ }