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,602 @@
1
+ import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
2
+ import { basename, extname, join, relative, resolve } from "node:path";
3
+
4
+ import { sha256 } from "./utils/hashing.js";
5
+ import { resolveRepoPath, safeFileStem, safeRunId } from "./utils/paths.js";
6
+ import { isRecord } from "./utils/records.js";
7
+
8
+ export type ComputeRequestedProfile = "auto" | "low" | "medium" | "high" | "xhigh" | "max";
9
+ export type ComputeEffectiveProfile = Exclude<ComputeRequestedProfile, "auto">;
10
+ export type ComputeDomain = "generic" | "project-dna" | "factory" | "orchestration";
11
+ export type ComputePreviewConfidence = "low" | "medium" | "high";
12
+
13
+ export interface ComputeCapsInput {
14
+ maxAgents?: number;
15
+ maxDelegationDepth?: number;
16
+ maxParallel?: number;
17
+ maxIterations?: number;
18
+ maxDurationMs?: number;
19
+ maxCostUsd?: number;
20
+ maxContextTokens?: number;
21
+ strictBudgetRequired?: boolean;
22
+ oracleRequired?: boolean;
23
+ }
24
+
25
+ export interface ComputePreviewInput {
26
+ runId?: string;
27
+ domain?: ComputeDomain | string;
28
+ requestedProfile?: ComputeRequestedProfile | string;
29
+ targetPath?: string;
30
+ taskHash?: string;
31
+ maxProfile?: ComputeEffectiveProfile | string;
32
+ computeCaps?: ComputeCapsInput;
33
+ riskHints?: string[];
34
+ }
35
+
36
+ export interface ComputeProfileValidationInput {
37
+ previewPath: string;
38
+ resolutionPath?: string;
39
+ }
40
+
41
+ interface ProfileDefaults {
42
+ maxAgents: number;
43
+ maxDelegationDepth: number;
44
+ maxParallel: number;
45
+ maxIterations: number;
46
+ maxDurationMs: number;
47
+ maxCostUsd: number;
48
+ maxContextTokens: number;
49
+ strictBudgetRequired: boolean;
50
+ oracleRequired: boolean;
51
+ validationLevel: string;
52
+ oraclePolicy: string;
53
+ benchmarkLevel: string;
54
+ }
55
+
56
+ interface TargetStats {
57
+ exists: boolean;
58
+ targetKind: "repo" | "repo_path" | "missing";
59
+ fileCount: number;
60
+ directoryCount: number;
61
+ skippedCount: number;
62
+ totalBytesEstimate: number;
63
+ extensionCounts: Record<string, number>;
64
+ languageCount: number;
65
+ packageManifestCount: number;
66
+ workspaceIndicatorCount: number;
67
+ testFileCount: number;
68
+ docsFileCount: number;
69
+ exampleFileCount: number;
70
+ configFileCount: number;
71
+ forbiddenVisibleCount: number;
72
+ generatedVendorSkippedCount: number;
73
+ maxFilesReached: boolean;
74
+ errors: string[];
75
+ }
76
+
77
+ const PROFILE_ORDER: ComputeEffectiveProfile[] = ["low", "medium", "high", "xhigh", "max"];
78
+ const REQUESTED_PROFILES: ComputeRequestedProfile[] = ["auto", ...PROFILE_ORDER];
79
+ const DOMAINS: ComputeDomain[] = ["generic", "project-dna", "factory", "orchestration"];
80
+ const MAX_PREVIEW_FILES = 5000;
81
+
82
+ const DEFAULT_CAPS: Record<ComputeEffectiveProfile, ProfileDefaults> = {
83
+ low: {
84
+ maxAgents: 1,
85
+ maxDelegationDepth: 0,
86
+ maxParallel: 1,
87
+ maxIterations: 1,
88
+ maxDurationMs: 120_000,
89
+ maxCostUsd: 0.25,
90
+ maxContextTokens: 3000,
91
+ strictBudgetRequired: false,
92
+ oracleRequired: false,
93
+ validationLevel: "narrow",
94
+ oraclePolicy: "off_unless_risky",
95
+ benchmarkLevel: "none",
96
+ },
97
+ medium: {
98
+ maxAgents: 4,
99
+ maxDelegationDepth: 1,
100
+ maxParallel: 2,
101
+ maxIterations: 2,
102
+ maxDurationMs: 300_000,
103
+ maxCostUsd: 1,
104
+ maxContextTokens: 6000,
105
+ strictBudgetRequired: false,
106
+ oracleRequired: false,
107
+ validationLevel: "targeted",
108
+ oraclePolicy: "conditional",
109
+ benchmarkLevel: "smoke",
110
+ },
111
+ high: {
112
+ maxAgents: 10,
113
+ maxDelegationDepth: 2,
114
+ maxParallel: 4,
115
+ maxIterations: 3,
116
+ maxDurationMs: 600_000,
117
+ maxCostUsd: 5,
118
+ maxContextTokens: 12_000,
119
+ strictBudgetRequired: true,
120
+ oracleRequired: true,
121
+ validationLevel: "full_local",
122
+ oraclePolicy: "required_for_completion",
123
+ benchmarkLevel: "smoke_plus_targeted_cases",
124
+ },
125
+ xhigh: {
126
+ maxAgents: 20,
127
+ maxDelegationDepth: 3,
128
+ maxParallel: 6,
129
+ maxIterations: 4,
130
+ maxDurationMs: 1_200_000,
131
+ maxCostUsd: 15,
132
+ maxContextTokens: 20_000,
133
+ strictBudgetRequired: true,
134
+ oracleRequired: true,
135
+ validationLevel: "full_plus_adversarial",
136
+ oraclePolicy: "required_with_no_ship_gate",
137
+ benchmarkLevel: "suite",
138
+ },
139
+ max: {
140
+ maxAgents: 30,
141
+ maxDelegationDepth: 4,
142
+ maxParallel: 8,
143
+ maxIterations: 5,
144
+ maxDurationMs: 3_600_000,
145
+ maxCostUsd: 50,
146
+ maxContextTokens: 32_000,
147
+ strictBudgetRequired: true,
148
+ oracleRequired: true,
149
+ validationLevel: "exhaustive_within_scope",
150
+ oraclePolicy: "required_multiple_oracle_lanes",
151
+ benchmarkLevel: "suite_plus_regression",
152
+ },
153
+ };
154
+
155
+ const DEFAULT_FORBIDDEN_NAMES = new Set([
156
+ ".env",
157
+ ".git",
158
+ ".npmrc",
159
+ ".ssh",
160
+ ".aws",
161
+ "node_modules",
162
+ "dist",
163
+ "build",
164
+ "coverage",
165
+ ".next",
166
+ ".nuxt",
167
+ "out",
168
+ "vendor",
169
+ "generated",
170
+ ]);
171
+
172
+ const GENERATED_VENDOR_NAMES = new Set(["node_modules", "dist", "build", "coverage", ".next", ".nuxt", "out", "vendor", "generated"]);
173
+ const SECRET_NAME_PATTERNS = [/\.env(?:\..*)?$/i, /secret/i, /credential/i, /(?:^|[-_])key(?:[-_.]|$)/i, /\.pem$/i, /\.p12$/i, /\.pfx$/i, /^id_rsa$/i, /^id_ed25519$/i];
174
+ const LANGUAGE_EXTENSIONS = new Set([".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".py", ".rs", ".go", ".java", ".kt", ".cs", ".rb", ".php", ".swift", ".vue", ".svelte"]);
175
+
176
+ function clamp01(value: number): number {
177
+ if (!Number.isFinite(value)) return 0;
178
+ return Math.max(0, Math.min(1, value));
179
+ }
180
+
181
+ function finitePositive(value: unknown): number | undefined {
182
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : undefined;
183
+ }
184
+
185
+ function normalizeRequestedProfile(value: string | undefined): ComputeRequestedProfile {
186
+ return REQUESTED_PROFILES.includes(value as ComputeRequestedProfile) ? value as ComputeRequestedProfile : "auto";
187
+ }
188
+
189
+ function normalizeEffectiveProfile(value: string | undefined): ComputeEffectiveProfile | undefined {
190
+ return PROFILE_ORDER.includes(value as ComputeEffectiveProfile) ? value as ComputeEffectiveProfile : undefined;
191
+ }
192
+
193
+ function normalizeDomain(value: string | undefined): ComputeDomain {
194
+ return DOMAINS.includes(value as ComputeDomain) ? value as ComputeDomain : "generic";
195
+ }
196
+
197
+ function profileIndex(profile: ComputeEffectiveProfile): number {
198
+ return PROFILE_ORDER.indexOf(profile);
199
+ }
200
+
201
+ function minProfile(profile: ComputeEffectiveProfile, maxProfile: ComputeEffectiveProfile | undefined): ComputeEffectiveProfile {
202
+ if (!maxProfile) return profile;
203
+ return PROFILE_ORDER[Math.min(profileIndex(profile), profileIndex(maxProfile))] ?? profile;
204
+ }
205
+
206
+ function isForbiddenName(name: string): boolean {
207
+ return DEFAULT_FORBIDDEN_NAMES.has(name) || SECRET_NAME_PATTERNS.some((pattern) => pattern.test(name));
208
+ }
209
+
210
+ function isTestFile(relativePath: string): boolean {
211
+ return /(^|\/)(__tests__|test|tests|spec)(\/|$)/i.test(relativePath) || /\.(test|spec)\.[cm]?[tj]sx?$/i.test(relativePath);
212
+ }
213
+
214
+ function isDocsFile(relativePath: string): boolean {
215
+ return /(^|\/)(docs?|documentation)(\/|$)/i.test(relativePath) || /(^|\/)(readme|architecture|design|guide)[^/]*\.md$/i.test(relativePath);
216
+ }
217
+
218
+ function isExampleFile(relativePath: string): boolean {
219
+ return /(^|\/)(examples?|samples?)(\/|$)/i.test(relativePath);
220
+ }
221
+
222
+ function isConfigFile(relativePath: string): boolean {
223
+ return /(^|\/)(package\.json|tsconfig\.json|vite\.config\.|next\.config\.|eslint\.|prettier\.|tailwind\.|factory\.json|.*\.schema\.json)$/i.test(relativePath);
224
+ }
225
+
226
+ function emptyStats(targetKind: TargetStats["targetKind"], exists: boolean, errors: string[] = []): TargetStats {
227
+ return {
228
+ exists,
229
+ targetKind,
230
+ fileCount: 0,
231
+ directoryCount: 0,
232
+ skippedCount: 0,
233
+ totalBytesEstimate: 0,
234
+ extensionCounts: {},
235
+ languageCount: 0,
236
+ packageManifestCount: 0,
237
+ workspaceIndicatorCount: 0,
238
+ testFileCount: 0,
239
+ docsFileCount: 0,
240
+ exampleFileCount: 0,
241
+ configFileCount: 0,
242
+ forbiddenVisibleCount: 0,
243
+ generatedVendorSkippedCount: 0,
244
+ maxFilesReached: false,
245
+ errors,
246
+ };
247
+ }
248
+
249
+ function collectTargetStats(repoRoot: string, targetPath: string | undefined): TargetStats {
250
+ const requestedPath = targetPath && targetPath.trim().length > 0 ? targetPath : ".";
251
+ const resolved = resolveRepoPath(repoRoot, requestedPath);
252
+ if (resolved.errors.length > 0) return emptyStats("missing", false, resolved.errors);
253
+ const absoluteTarget = resolved.path;
254
+ if (!existsSync(absoluteTarget)) return emptyStats("missing", false, [`target_path does not exist: ${requestedPath}`]);
255
+
256
+ const root = resolve(repoRoot);
257
+ const stats = emptyStats(absoluteTarget === root ? "repo" : "repo_path", true);
258
+
259
+ const visit = (absolutePath: string): void => {
260
+ if (stats.fileCount >= MAX_PREVIEW_FILES) {
261
+ stats.maxFilesReached = true;
262
+ return;
263
+ }
264
+ let entries;
265
+ try {
266
+ entries = readdirSync(absolutePath, { withFileTypes: true });
267
+ } catch (error) {
268
+ stats.errors.push(`could not read directory metadata: ${relative(root, absolutePath) || "."}: ${error instanceof Error ? error.message : String(error)}`);
269
+ return;
270
+ }
271
+ for (const entry of entries) {
272
+ if (stats.fileCount >= MAX_PREVIEW_FILES) {
273
+ stats.maxFilesReached = true;
274
+ return;
275
+ }
276
+ const childAbsolute = join(absolutePath, entry.name);
277
+ const childRelative = relative(root, childAbsolute).replace(/\\/g, "/") || entry.name;
278
+ if (isForbiddenName(entry.name)) {
279
+ stats.skippedCount += 1;
280
+ stats.forbiddenVisibleCount += 1;
281
+ if (GENERATED_VENDOR_NAMES.has(entry.name)) stats.generatedVendorSkippedCount += 1;
282
+ continue;
283
+ }
284
+ if (entry.isDirectory()) {
285
+ stats.directoryCount += 1;
286
+ visit(childAbsolute);
287
+ continue;
288
+ }
289
+ if (!entry.isFile()) continue;
290
+ stats.fileCount += 1;
291
+ try {
292
+ stats.totalBytesEstimate += statSync(childAbsolute).size;
293
+ } catch {
294
+ // Keep preview metadata-only and non-failing for transient stat errors.
295
+ }
296
+ const ext = extname(entry.name).toLowerCase() || "[no-ext]";
297
+ stats.extensionCounts[ext] = (stats.extensionCounts[ext] ?? 0) + 1;
298
+ if (entry.name === "package.json") stats.packageManifestCount += 1;
299
+ if (entry.name === "pnpm-workspace.yaml" || entry.name === "lerna.json" || entry.name === "turbo.json" || entry.name === "nx.json") stats.workspaceIndicatorCount += 1;
300
+ if (isTestFile(childRelative)) stats.testFileCount += 1;
301
+ if (isDocsFile(childRelative)) stats.docsFileCount += 1;
302
+ if (isExampleFile(childRelative)) stats.exampleFileCount += 1;
303
+ if (isConfigFile(childRelative)) stats.configFileCount += 1;
304
+ }
305
+ };
306
+
307
+ const targetStat = statSync(absoluteTarget);
308
+ if (targetStat.isDirectory()) visit(absoluteTarget);
309
+ else if (targetStat.isFile()) {
310
+ stats.fileCount = 1;
311
+ stats.totalBytesEstimate = targetStat.size;
312
+ const ext = extname(absoluteTarget).toLowerCase() || "[no-ext]";
313
+ stats.extensionCounts[ext] = 1;
314
+ }
315
+
316
+ stats.languageCount = Object.keys(stats.extensionCounts).filter((ext) => LANGUAGE_EXTENSIONS.has(ext)).length;
317
+ return stats;
318
+ }
319
+
320
+ function scoreStats(stats: TargetStats, input: ComputePreviewInput, domain: ComputeDomain): Record<string, number> {
321
+ const sourceFiles = Object.entries(stats.extensionCounts)
322
+ .filter(([ext]) => LANGUAGE_EXTENSIONS.has(ext))
323
+ .reduce((sum, [, count]) => sum + count, 0);
324
+ const sourceFileRatio = stats.fileCount > 0 ? sourceFiles / stats.fileCount : 0;
325
+ const riskHints = new Set((input.riskHints ?? []).map((hint) => hint.toLowerCase()));
326
+ const writeRequested = riskHints.has("write") || riskHints.has("apply") || riskHints.has("mutation") ? 1 : 0;
327
+ const externalAccess = riskHints.has("network") || riskHints.has("browser") || riskHints.has("cloud") ? 1 : 0;
328
+ const durablePromotion = riskHints.has("promotion") || riskHints.has("durable") ? 1 : 0;
329
+ const projectDnaBoost = domain === "project-dna" ? 0.15 : 0;
330
+
331
+ const size = clamp01((stats.fileCount / 1000) * 0.35 + (stats.packageManifestCount / 20) * 0.25 + (stats.languageCount / 8) * 0.15 + (stats.totalBytesEstimate / 50_000_000) * 0.25);
332
+ const material = clamp01(sourceFileRatio * 0.25 + Math.min(stats.testFileCount, 50) / 50 * 0.25 + Math.min(stats.docsFileCount, 25) / 25 * 0.15 + Math.min(stats.packageManifestCount, 5) / 5 * 0.15 + Math.min(stats.exampleFileCount, 20) / 20 * 0.10 + Math.min(stats.configFileCount, 20) / 20 * 0.10);
333
+ const complexity = clamp01((stats.packageManifestCount / 10) * 0.30 + (stats.workspaceIndicatorCount / 4) * 0.20 + (stats.languageCount / 8) * 0.25 + (stats.configFileCount / 30) * 0.25);
334
+ const ambiguity = clamp01(input.taskHash ? 0.15 : 0.30);
335
+ const risk = clamp01((stats.forbiddenVisibleCount > 0 ? 0.20 : 0) + writeRequested * 0.25 + externalAccess * 0.15 + durablePromotion * 0.20 + (stats.errors.length > 0 ? 0.10 : 0));
336
+ const novelty = clamp01(domain === "generic" ? 0.35 : 0.45 + projectDnaBoost);
337
+ const reuseValue = clamp01((domain === "project-dna" || domain === "factory" || domain === "orchestration" ? 0.55 : 0.30) + projectDnaBoost + Math.min(stats.packageManifestCount, 5) / 5 * 0.20 + Math.min(stats.docsFileCount, 10) / 10 * 0.10);
338
+ const validationNeed = clamp01(Math.max(complexity, risk) * 0.7 + material * 0.3);
339
+
340
+ return { size, material, complexity, ambiguity, risk, novelty, reuseValue, validationNeed };
341
+ }
342
+
343
+ function reasonCodesFor(stats: TargetStats, scores: Record<string, number>, domain: ComputeDomain): string[] {
344
+ const reasons: string[] = [];
345
+ if (domain !== "generic") reasons.push(`${domain}_domain`);
346
+ if (stats.fileCount >= 500) reasons.push("large_file_count");
347
+ else if (stats.fileCount >= 100) reasons.push("medium_file_count");
348
+ if (stats.packageManifestCount > 1) reasons.push("multiple_package_manifests");
349
+ if (stats.workspaceIndicatorCount > 0) reasons.push("workspace_indicators_present");
350
+ if (stats.testFileCount > 0) reasons.push("tests_present");
351
+ if (stats.docsFileCount > 0) reasons.push("docs_present");
352
+ if (stats.forbiddenVisibleCount > 0) reasons.push("forbidden_paths_visible_but_skipped");
353
+ if (stats.maxFilesReached) reasons.push("preview_file_cap_reached");
354
+ if (scores.reuseValue >= 0.7) reasons.push("high_reuse_value");
355
+ if (scores.complexity >= 0.65) reasons.push("high_complexity");
356
+ return reasons.length > 0 ? reasons : ["small_or_low_signal_target"];
357
+ }
358
+
359
+ function recommendProfile(scores: Record<string, number>, stats: TargetStats): ComputeEffectiveProfile {
360
+ const qualityNeed = Math.max(scores.complexity, scores.ambiguity, scores.reuseValue, scores.validationNeed);
361
+ const computeWorth = scores.material * scores.reuseValue;
362
+ if (stats.errors.length > 0 && scores.material < 0.15) return "low";
363
+ if (qualityNeed > 0.85 && computeWorth > 0.75) return "xhigh";
364
+ if (qualityNeed > 0.65 && computeWorth > 0.55) return "high";
365
+ if (qualityNeed > 0.35 || stats.fileCount > 25) return "medium";
366
+ return "low";
367
+ }
368
+
369
+ function confidenceFor(stats: TargetStats, recommendedProfile: ComputeEffectiveProfile): ComputePreviewConfidence {
370
+ if (stats.errors.length > 0 || stats.maxFilesReached) return "medium";
371
+ if (recommendedProfile === "low" && stats.fileCount < 25) return "high";
372
+ if (stats.fileCount > 100 && stats.packageManifestCount > 0) return "high";
373
+ return "medium";
374
+ }
375
+
376
+ function adaptivePolicyHint(profile: ComputeEffectiveProfile): Record<string, unknown> {
377
+ const depthByProfile: Record<ComputeEffectiveProfile, number> = { low: 0, medium: 1, high: 2, xhigh: 3, max: 4 };
378
+ const fanoutByProfile: Record<ComputeEffectiveProfile, number> = { low: 1, medium: 2, high: 4, xhigh: 6, max: 8 };
379
+ return {
380
+ schema: "zob.compute-adaptive-policy-hint.v1",
381
+ profile,
382
+ enabledByDefault: false,
383
+ advisoryOnly: profile === "low" || profile === "medium",
384
+ supervisedReadonlyEligible: profile === "high" || profile === "xhigh" || profile === "max",
385
+ runtimeMaxDepthHint: depthByProfile[profile],
386
+ globalParallelMaxHint: fanoutByProfile[profile],
387
+ parentOwnedDispatch: true,
388
+ childDirectDispatch: false,
389
+ liveDispatchEnabled: false,
390
+ noExecution: true,
391
+ };
392
+ }
393
+
394
+ function mergeCaps(profile: ComputeEffectiveProfile, overrides: ComputeCapsInput | undefined): ProfileDefaults {
395
+ const base = DEFAULT_CAPS[profile];
396
+ return {
397
+ ...base,
398
+ maxAgents: finitePositive(overrides?.maxAgents) ?? base.maxAgents,
399
+ maxDelegationDepth: finitePositive(overrides?.maxDelegationDepth) ?? base.maxDelegationDepth,
400
+ maxParallel: finitePositive(overrides?.maxParallel) ?? base.maxParallel,
401
+ maxIterations: finitePositive(overrides?.maxIterations) ?? base.maxIterations,
402
+ maxDurationMs: finitePositive(overrides?.maxDurationMs) ?? base.maxDurationMs,
403
+ maxCostUsd: finitePositive(overrides?.maxCostUsd) ?? base.maxCostUsd,
404
+ maxContextTokens: finitePositive(overrides?.maxContextTokens) ?? base.maxContextTokens,
405
+ strictBudgetRequired: overrides?.strictBudgetRequired ?? base.strictBudgetRequired,
406
+ oracleRequired: overrides?.oracleRequired ?? base.oracleRequired,
407
+ };
408
+ }
409
+
410
+ function noShipFor(stats: TargetStats): { noShip: boolean; blockers: string[] } {
411
+ const blockers: string[] = [];
412
+ if (!stats.exists) blockers.push("target_path_missing_or_outside_repo");
413
+ if (stats.errors.length > 0) blockers.push("preview_metadata_errors_present");
414
+ return { noShip: blockers.length > 0, blockers };
415
+ }
416
+
417
+ export function buildComputePreview(repoRoot: string, input: ComputePreviewInput = {}): Record<string, unknown> {
418
+ const domain = normalizeDomain(input.domain);
419
+ const requestedProfile = normalizeRequestedProfile(input.requestedProfile);
420
+ const stats = collectTargetStats(repoRoot, input.targetPath);
421
+ const scores = scoreStats(stats, input, domain);
422
+ const recommendedProfile = recommendProfile(scores, stats);
423
+ const confidence = confidenceFor(stats, recommendedProfile);
424
+ const { noShip, blockers } = noShipFor(stats);
425
+ return {
426
+ schema: "zob.compute-preview.v1",
427
+ runId: input.runId,
428
+ domain,
429
+ requestedProfile,
430
+ recommendedProfile,
431
+ confidence,
432
+ scores,
433
+ reasonCodes: reasonCodesFor(stats, scores, domain),
434
+ target: {
435
+ targetKind: stats.targetKind,
436
+ targetPathHash: sha256(input.targetPath ?? "."),
437
+ targetPathStored: false,
438
+ targetBasename: basename(input.targetPath ?? repoRoot),
439
+ exists: stats.exists,
440
+ },
441
+ stats: {
442
+ fileCount: stats.fileCount,
443
+ directoryCount: stats.directoryCount,
444
+ skippedCount: stats.skippedCount,
445
+ totalBytesEstimate: stats.totalBytesEstimate,
446
+ extensionCounts: stats.extensionCounts,
447
+ languageCount: stats.languageCount,
448
+ packageManifestCount: stats.packageManifestCount,
449
+ workspaceIndicatorCount: stats.workspaceIndicatorCount,
450
+ testFileCount: stats.testFileCount,
451
+ docsFileCount: stats.docsFileCount,
452
+ exampleFileCount: stats.exampleFileCount,
453
+ configFileCount: stats.configFileCount,
454
+ forbiddenVisibleCount: stats.forbiddenVisibleCount,
455
+ generatedVendorSkippedCount: stats.generatedVendorSkippedCount,
456
+ maxFilesReached: stats.maxFilesReached,
457
+ errorCount: stats.errors.length,
458
+ },
459
+ blockers,
460
+ errors: stats.errors,
461
+ noShip,
462
+ noExecution: true,
463
+ childDispatchAllowed: false,
464
+ networkAccessed: false,
465
+ sourceProjectModified: false,
466
+ knowledgeBackendWriteEnabled: false,
467
+ bodyStored: false,
468
+ promptBodiesStored: false,
469
+ outputBodiesStored: false,
470
+ generatedAt: new Date().toISOString(),
471
+ };
472
+ }
473
+
474
+ export function resolveComputeProfile(repoRoot: string, input: ComputePreviewInput = {}): Record<string, unknown> {
475
+ const preview = buildComputePreview(repoRoot, input);
476
+ const requestedProfile = preview.requestedProfile as ComputeRequestedProfile;
477
+ const recommendedProfile = preview.recommendedProfile as ComputeEffectiveProfile;
478
+ const maxProfile = normalizeEffectiveProfile(input.maxProfile);
479
+ const requestedEffective = requestedProfile === "auto" ? recommendedProfile : requestedProfile;
480
+ const cappedProfile = minProfile(requestedEffective, maxProfile);
481
+ const caps = mergeCaps(cappedProfile, input.computeCaps);
482
+ const blockedEscalation = profileIndex(cappedProfile) < profileIndex(requestedEffective)
483
+ ? { to: requestedEffective, reason: "requested_or_recommended_profile_exceeds_max_profile_cap" }
484
+ : requestedProfile === "auto" && recommendedProfile === "max"
485
+ ? { to: "max", reason: "max requires explicit human approval; auto cannot silently select max" }
486
+ : undefined;
487
+ const effectiveProfile = requestedProfile === "auto" && recommendedProfile === "max" ? minProfile("xhigh", maxProfile) : cappedProfile;
488
+ const effectiveCaps = mergeCaps(effectiveProfile, input.computeCaps);
489
+ return {
490
+ schema: "zob.compute-profile-resolution.v1",
491
+ runId: input.runId,
492
+ domain: preview.domain,
493
+ requestedProfile,
494
+ recommendedProfile,
495
+ effectiveProfile,
496
+ confidence: preview.confidence,
497
+ reasonCodes: preview.reasonCodes,
498
+ previewHash: sha256(JSON.stringify(preview)),
499
+ previewEmbedded: false,
500
+ caps: effectiveCaps,
501
+ gates: {
502
+ strictBudgetRequired: effectiveCaps.strictBudgetRequired,
503
+ oracleRequired: effectiveCaps.oracleRequired,
504
+ humanApprovalRequired: effectiveProfile === "max",
505
+ sandboxRequiredForWrites: true,
506
+ parentOwnedDispatch: true,
507
+ childDirectDispatch: false,
508
+ },
509
+ adaptiveDelegationPolicyHint: adaptivePolicyHint(effectiveProfile),
510
+ blockedEscalation,
511
+ noShip: preview.noShip === true,
512
+ blockers: preview.blockers,
513
+ noExecution: true,
514
+ childDispatchAllowed: false,
515
+ networkAccessed: false,
516
+ sourceProjectModified: false,
517
+ knowledgeBackendWriteEnabled: false,
518
+ bodyStored: false,
519
+ promptBodiesStored: false,
520
+ outputBodiesStored: false,
521
+ generatedAt: new Date().toISOString(),
522
+ };
523
+ }
524
+
525
+ export function writeComputeProfileReports(repoRoot: string, input: ComputePreviewInput = {}): Record<string, unknown> {
526
+ const runId = safeRunId(input.runId, "compute-profile");
527
+ const dir = join(repoRoot, ".pi", "logs", "compute-profile", runId);
528
+ mkdirSync(dir, { recursive: true });
529
+ const preview = buildComputePreview(repoRoot, { ...input, runId });
530
+ const resolution = resolveComputeProfile(repoRoot, { ...input, runId });
531
+ const previewPath = join(dir, "compute-preview.json");
532
+ const resolutionPath = join(dir, "compute-profile-resolution.json");
533
+ writeFileSync(previewPath, JSON.stringify(preview, null, 2), "utf8");
534
+ writeFileSync(resolutionPath, JSON.stringify(resolution, null, 2), "utf8");
535
+ return {
536
+ schema: "zob.compute-profile-report-write.v1",
537
+ status: "written",
538
+ runId,
539
+ previewPath: relative(repoRoot, previewPath).replace(/\\/g, "/"),
540
+ resolutionPath: relative(repoRoot, resolutionPath).replace(/\\/g, "/"),
541
+ noExecution: true,
542
+ childDispatchAllowed: false,
543
+ bodyStored: false,
544
+ };
545
+ }
546
+
547
+ function readRepoJson(repoRoot: string, repoPath: string): Record<string, unknown> | undefined {
548
+ const resolved = resolveRepoPath(repoRoot, repoPath);
549
+ if (resolved.errors.length > 0 || !existsSync(resolved.path)) return undefined;
550
+ const parsed = JSON.parse(readFileSync(resolved.path, "utf8")) as unknown;
551
+ return isRecord(parsed) ? parsed : undefined;
552
+ }
553
+
554
+ function hasForbiddenBodyKeys(value: unknown): boolean {
555
+ if (!value || typeof value !== "object") return false;
556
+ if (Array.isArray(value)) return value.some(hasForbiddenBodyKeys);
557
+ return Object.entries(value as Record<string, unknown>).some(([key, child]) => ["task", "prompt", "output", "body", "content", "diff", "patch"].includes(key) || hasForbiddenBodyKeys(child));
558
+ }
559
+
560
+ function validScoreMap(value: unknown): boolean {
561
+ if (!isRecord(value)) return false;
562
+ return ["size", "material", "complexity", "ambiguity", "risk", "novelty", "reuseValue", "validationNeed"].every((key) => typeof value[key] === "number" && Number.isFinite(value[key]) && value[key] >= 0 && value[key] <= 1);
563
+ }
564
+
565
+ export function validateComputeProfileArtifacts(repoRoot: string, input: ComputeProfileValidationInput): Record<string, unknown> {
566
+ const errors: string[] = [];
567
+ const preview = readRepoJson(repoRoot, input.previewPath);
568
+ const resolution = input.resolutionPath ? readRepoJson(repoRoot, input.resolutionPath) : undefined;
569
+ if (!preview) errors.push("preview artifact missing or invalid JSON object");
570
+ if (preview) {
571
+ if (preview.schema !== "zob.compute-preview.v1") errors.push("preview schema must be zob.compute-preview.v1");
572
+ if (!REQUESTED_PROFILES.includes(preview.requestedProfile as ComputeRequestedProfile)) errors.push("preview requestedProfile invalid");
573
+ if (!PROFILE_ORDER.includes(preview.recommendedProfile as ComputeEffectiveProfile)) errors.push("preview recommendedProfile invalid");
574
+ if (!validScoreMap(preview.scores)) errors.push("preview scores invalid");
575
+ for (const flag of ["noExecution", "sourceProjectModified", "knowledgeBackendWriteEnabled", "bodyStored", "promptBodiesStored", "outputBodiesStored"]) {
576
+ if (flag === "noExecution" && preview[flag] !== true) errors.push("preview must keep noExecution=true");
577
+ if (flag !== "noExecution" && preview[flag] !== false) errors.push(`preview must keep ${flag}=false`);
578
+ }
579
+ if (preview.childDispatchAllowed !== false) errors.push("preview childDispatchAllowed must be false");
580
+ if (preview.networkAccessed !== false) errors.push("preview networkAccessed must be false");
581
+ if (hasForbiddenBodyKeys(preview)) errors.push("preview must not contain raw body/prompt/output/content/diff/patch keys");
582
+ }
583
+ if (input.resolutionPath && !resolution) errors.push("resolution artifact missing or invalid JSON object");
584
+ if (resolution) {
585
+ if (resolution.schema !== "zob.compute-profile-resolution.v1") errors.push("resolution schema must be zob.compute-profile-resolution.v1");
586
+ if (!PROFILE_ORDER.includes(resolution.effectiveProfile as ComputeEffectiveProfile)) errors.push("resolution effectiveProfile invalid");
587
+ if (resolution.childDispatchAllowed !== false) errors.push("resolution childDispatchAllowed must be false");
588
+ if (hasForbiddenBodyKeys(resolution)) errors.push("resolution must not contain raw body/prompt/output/content/diff/patch keys");
589
+ }
590
+ return {
591
+ schema: "zob.compute-profile-validation.v1",
592
+ valid: errors.length === 0,
593
+ errors,
594
+ previewPath: safeFileStem(input.previewPath),
595
+ resolutionPath: input.resolutionPath ? safeFileStem(input.resolutionPath) : undefined,
596
+ noExecution: true,
597
+ childDispatchAllowed: false,
598
+ networkAccessed: false,
599
+ bodyStored: false,
600
+ generatedAt: new Date().toISOString(),
601
+ };
602
+ }