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,595 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+
4
+ import { sha256 } from "./utils/hashing.js";
5
+ import { isRecord } from "./utils/records.js";
6
+
7
+ export const INTERACTIVE_AUTONOMY_MODES = ["off", "open", "controlled", "adaptive"] as const;
8
+ export type InteractiveAutonomyMode = typeof INTERACTIVE_AUTONOMY_MODES[number];
9
+ export type MissionReadinessDecision = "auto_launch" | "clarify" | "block" | "stopped";
10
+ export type MissionReadinessVerdict = "READY" | "NEEDS_CLARIFICATION" | "BLOCKED" | "STOPPED";
11
+ export type MissionRiskLevel = "low" | "medium" | "high";
12
+
13
+ export interface InteractiveAutonomyThresholds {
14
+ adaptiveAutoLaunch: number;
15
+ adaptiveClarifyBelow: number;
16
+ controlledAutoLaunch: number;
17
+ controlledMinimumSignals: number;
18
+ }
19
+
20
+ export interface InteractiveAutonomySafetyPolicy {
21
+ blockSecretAccess: boolean;
22
+ blockDestructiveCommands: boolean;
23
+ blockProductionApply: boolean;
24
+ forbiddenPathPatterns: string[];
25
+ destructivePatterns: string[];
26
+ secretPatterns: string[];
27
+ }
28
+
29
+ export interface InteractiveAutonomyLaunchPolicy {
30
+ defaultAllowedActions: string[];
31
+ defaultAllowedPaths: string[];
32
+ stopConditions: string[];
33
+ manualPerActionApprovalWhenLaunched: boolean;
34
+ requireValidationEvidence: boolean;
35
+ requireOracleForCompletion: boolean;
36
+ }
37
+
38
+ export interface InteractiveAutonomyPolicy {
39
+ schema: "zob.interactive-autonomy-policy.v1";
40
+ defaultMode: InteractiveAutonomyMode;
41
+ thresholds: InteractiveAutonomyThresholds;
42
+ safety: InteractiveAutonomySafetyPolicy;
43
+ launch: InteractiveAutonomyLaunchPolicy;
44
+ bodyStored: false;
45
+ promptBodiesStored: false;
46
+ outputBodiesStored: false;
47
+ source: string;
48
+ }
49
+
50
+ export interface MissionReadinessSignals {
51
+ clarity: number;
52
+ acceptanceCriteria: number;
53
+ targetPaths: number;
54
+ testability: number;
55
+ safety: number;
56
+ }
57
+
58
+ export interface InteractiveLaunchAuthorization {
59
+ schema: "zob.launch-authorization.v1";
60
+ userInputHash: string;
61
+ missionReadinessHash: string;
62
+ specLocked: boolean;
63
+ userLaunchConfirmed: boolean;
64
+ autonomyMode: Exclude<InteractiveAutonomyMode, "off">;
65
+ allowedActions: string[];
66
+ allowedPaths: string[];
67
+ forbiddenPaths: string[];
68
+ applyPolicy: {
69
+ mode: "interactive_in_scope";
70
+ manualPerActionApprovalRequired: boolean;
71
+ validationRequired: boolean;
72
+ oracleRequiredForCompletion: boolean;
73
+ productionApplyAllowed: false;
74
+ };
75
+ stopConditions: string[];
76
+ launchAuthorizesInScopeActions: boolean;
77
+ actionExecutionBlockedUntilLaunch: false;
78
+ exceptionApprovalRequiredOnlyForOutOfScope: true;
79
+ globalProductionClaimAllowed: false;
80
+ bodyStored: false;
81
+ promptBodiesStored: false;
82
+ outputBodiesStored: false;
83
+ }
84
+
85
+ export interface MissionReadinessReport {
86
+ schema: "zob.mission-readiness.v1";
87
+ mode: InteractiveAutonomyMode;
88
+ decision: MissionReadinessDecision;
89
+ verdict: MissionReadinessVerdict;
90
+ score: number;
91
+ risk: MissionRiskLevel;
92
+ signals: MissionReadinessSignals;
93
+ blockerCodes: string[];
94
+ clarificationCodes: string[];
95
+ safetyGateCodes: string[];
96
+ userInputHash: string;
97
+ rawInputStored: false;
98
+ targetPathRefs: string[];
99
+ targetPathHashes: string[];
100
+ manualPerActionApprovalRequired: boolean;
101
+ inScopeAutonomousActionsAuthorized: boolean;
102
+ safetyGatesStillEnabled: true;
103
+ noShip: boolean;
104
+ globalProductionClaimAllowed: false;
105
+ launchAuthorization?: InteractiveLaunchAuthorization;
106
+ bodyStored: false;
107
+ promptBodiesStored: false;
108
+ outputBodiesStored: false;
109
+ generatedAt: string;
110
+ }
111
+
112
+ export interface InteractiveAutonomyRuntimeState {
113
+ mode: InteractiveAutonomyMode;
114
+ enabled: boolean;
115
+ policy: InteractiveAutonomyPolicy;
116
+ policyHash: string;
117
+ updatedAt?: string;
118
+ lastReadiness?: MissionReadinessReport;
119
+ lastLaunchAuthorization?: InteractiveLaunchAuthorization;
120
+ }
121
+
122
+ const DEFAULT_POLICY_SOURCE = "builtin-default";
123
+
124
+ export const DEFAULT_INTERACTIVE_AUTONOMY_POLICY: InteractiveAutonomyPolicy = {
125
+ schema: "zob.interactive-autonomy-policy.v1",
126
+ defaultMode: "adaptive",
127
+ thresholds: {
128
+ adaptiveAutoLaunch: 0.72,
129
+ adaptiveClarifyBelow: 0.45,
130
+ controlledAutoLaunch: 0.86,
131
+ controlledMinimumSignals: 3,
132
+ },
133
+ safety: {
134
+ blockSecretAccess: true,
135
+ blockDestructiveCommands: true,
136
+ blockProductionApply: true,
137
+ forbiddenPathPatterns: [".env", "**/.env*", "**/*secret*", "**/*private-key*", "~/.ssh", "~/.aws"],
138
+ destructivePatterns: ["rm\\s+-rf", "git\\s+reset\\s+--hard", "git\\s+clean\\b", "pkill\\s+-9", "killall\\b", "drop\\s+database", "truncate\\s+table"],
139
+ secretPatterns: ["\\.env", "api[_ -]?key", "private\\s+key", "ssh\\s+key", "aws\\s+credential", "secret\\s+token"],
140
+ },
141
+ launch: {
142
+ defaultAllowedActions: ["read_repo", "plan", "edit_in_scope", "delegate_in_scope", "validate", "oracle_review"],
143
+ defaultAllowedPaths: ["."],
144
+ stopConditions: ["scope_drift", "secret_required", "destructive_action_requested", "validation_failure", "oracle_no_ship", "user_stop"],
145
+ manualPerActionApprovalWhenLaunched: false,
146
+ requireValidationEvidence: true,
147
+ requireOracleForCompletion: true,
148
+ },
149
+ bodyStored: false,
150
+ promptBodiesStored: false,
151
+ outputBodiesStored: false,
152
+ source: DEFAULT_POLICY_SOURCE,
153
+ };
154
+
155
+ function clamp01(value: number): number {
156
+ if (!Number.isFinite(value)) return 0;
157
+ return Math.max(0, Math.min(1, value));
158
+ }
159
+
160
+ function round2(value: number): number {
161
+ return Math.round(clamp01(value) * 100) / 100;
162
+ }
163
+
164
+ function stringArray(value: unknown, fallback: string[]): string[] {
165
+ if (!Array.isArray(value)) return [...fallback];
166
+ const result = value.map((item) => typeof item === "string" ? item.trim() : "").filter(Boolean);
167
+ return result.length > 0 ? result : [...fallback];
168
+ }
169
+
170
+ function numberField(value: unknown, fallback: number): number {
171
+ return typeof value === "number" && Number.isFinite(value) ? clamp01(value) : fallback;
172
+ }
173
+
174
+ export function asInteractiveAutonomyMode(value: unknown): InteractiveAutonomyMode | undefined {
175
+ return typeof value === "string" && INTERACTIVE_AUTONOMY_MODES.includes(value as InteractiveAutonomyMode) ? value as InteractiveAutonomyMode : undefined;
176
+ }
177
+
178
+ function normalizePolicy(value: unknown, source: string): InteractiveAutonomyPolicy {
179
+ if (!isRecord(value)) return { ...DEFAULT_INTERACTIVE_AUTONOMY_POLICY, source };
180
+ const defaultMode = asInteractiveAutonomyMode(value.defaultMode) ?? DEFAULT_INTERACTIVE_AUTONOMY_POLICY.defaultMode;
181
+ const thresholdsValue = isRecord(value.thresholds) ? value.thresholds : {};
182
+ const safetyValue = isRecord(value.safety) ? value.safety : {};
183
+ const launchValue = isRecord(value.launch) ? value.launch : {};
184
+ return {
185
+ schema: "zob.interactive-autonomy-policy.v1",
186
+ defaultMode,
187
+ thresholds: {
188
+ adaptiveAutoLaunch: numberField(thresholdsValue.adaptiveAutoLaunch, DEFAULT_INTERACTIVE_AUTONOMY_POLICY.thresholds.adaptiveAutoLaunch),
189
+ adaptiveClarifyBelow: numberField(thresholdsValue.adaptiveClarifyBelow, DEFAULT_INTERACTIVE_AUTONOMY_POLICY.thresholds.adaptiveClarifyBelow),
190
+ controlledAutoLaunch: numberField(thresholdsValue.controlledAutoLaunch, DEFAULT_INTERACTIVE_AUTONOMY_POLICY.thresholds.controlledAutoLaunch),
191
+ controlledMinimumSignals: typeof thresholdsValue.controlledMinimumSignals === "number" && Number.isFinite(thresholdsValue.controlledMinimumSignals)
192
+ ? Math.max(1, Math.min(5, Math.round(thresholdsValue.controlledMinimumSignals)))
193
+ : DEFAULT_INTERACTIVE_AUTONOMY_POLICY.thresholds.controlledMinimumSignals,
194
+ },
195
+ safety: {
196
+ blockSecretAccess: safetyValue.blockSecretAccess !== false,
197
+ blockDestructiveCommands: safetyValue.blockDestructiveCommands !== false,
198
+ blockProductionApply: safetyValue.blockProductionApply !== false,
199
+ forbiddenPathPatterns: stringArray(safetyValue.forbiddenPathPatterns, DEFAULT_INTERACTIVE_AUTONOMY_POLICY.safety.forbiddenPathPatterns),
200
+ destructivePatterns: stringArray(safetyValue.destructivePatterns, DEFAULT_INTERACTIVE_AUTONOMY_POLICY.safety.destructivePatterns),
201
+ secretPatterns: stringArray(safetyValue.secretPatterns, DEFAULT_INTERACTIVE_AUTONOMY_POLICY.safety.secretPatterns),
202
+ },
203
+ launch: {
204
+ defaultAllowedActions: stringArray(launchValue.defaultAllowedActions, DEFAULT_INTERACTIVE_AUTONOMY_POLICY.launch.defaultAllowedActions),
205
+ defaultAllowedPaths: stringArray(launchValue.defaultAllowedPaths, DEFAULT_INTERACTIVE_AUTONOMY_POLICY.launch.defaultAllowedPaths),
206
+ stopConditions: stringArray(launchValue.stopConditions, DEFAULT_INTERACTIVE_AUTONOMY_POLICY.launch.stopConditions),
207
+ manualPerActionApprovalWhenLaunched: launchValue.manualPerActionApprovalWhenLaunched === true,
208
+ requireValidationEvidence: launchValue.requireValidationEvidence !== false,
209
+ requireOracleForCompletion: launchValue.requireOracleForCompletion !== false,
210
+ },
211
+ bodyStored: false,
212
+ promptBodiesStored: false,
213
+ outputBodiesStored: false,
214
+ source,
215
+ };
216
+ }
217
+
218
+ export function readInteractiveAutonomyPolicy(repoRoot?: string): InteractiveAutonomyPolicy {
219
+ if (!repoRoot) return { ...DEFAULT_INTERACTIVE_AUTONOMY_POLICY };
220
+ const policyPath = join(repoRoot, ".pi", "autonomy-policy.json");
221
+ if (!existsSync(policyPath)) return { ...DEFAULT_INTERACTIVE_AUTONOMY_POLICY };
222
+ try {
223
+ return normalizePolicy(JSON.parse(readFileSync(policyPath, "utf8")) as unknown, ".pi/autonomy-policy.json");
224
+ } catch {
225
+ return { ...DEFAULT_INTERACTIVE_AUTONOMY_POLICY, source: `${DEFAULT_POLICY_SOURCE}:parse-error` };
226
+ }
227
+ }
228
+
229
+ export function hashInteractiveAutonomyPolicy(policy: InteractiveAutonomyPolicy): string {
230
+ return sha256(JSON.stringify({ ...policy, source: undefined }));
231
+ }
232
+
233
+ export function createInteractiveAutonomyRuntimeState(policy: InteractiveAutonomyPolicy = DEFAULT_INTERACTIVE_AUTONOMY_POLICY): InteractiveAutonomyRuntimeState {
234
+ return {
235
+ mode: policy.defaultMode,
236
+ enabled: policy.defaultMode !== "off",
237
+ policy,
238
+ policyHash: hashInteractiveAutonomyPolicy(policy),
239
+ };
240
+ }
241
+
242
+ function patternMatchesAny(text: string, patterns: string[]): boolean {
243
+ return patterns.some((pattern) => {
244
+ try {
245
+ return new RegExp(pattern, "i").test(text);
246
+ } catch {
247
+ return text.toLowerCase().includes(pattern.toLowerCase());
248
+ }
249
+ });
250
+ }
251
+
252
+ const SECRET_ACCESS_VERB_PATTERN = /\b(read|cat|open|inspect|print|show|copy|extract|use|lire|ouvrir|affiche|imprime|copie|extrais|utilise)\b/i;
253
+ const SECRET_ACCESS_CONTEXT_PATTERN = /\b(secret|token|api[_ -]?key|private\s+key|ssh\s+key|credential|identifiant)\b.{0,80}\b(read|show|print|copy|use|lire|affiche|copie|utilise)\b/i;
254
+ const NEGATIVE_SAFETY_DIRECTIVE_PATTERN = /\b(do not|don't|dont|never|must not|mustn't|avoid|forbidden|denylist|deny list|blocked|without|no\s+secrets?|ne\s+pas|ne\s+jamais|n'ouvre\s+pas|ne\s+lis\s+pas|interdit|sans)\b/i;
255
+ const CONTRAST_OR_EXCEPTION_PATTERN = /\b(but|however|except|unless|sauf|mais|pourtant)\b/i;
256
+
257
+ function isNegativeSecretSafetyLine(line: string, policy: InteractiveAutonomyPolicy): boolean {
258
+ const trimmed = line.trim();
259
+ if (!trimmed || !patternMatchesAny(trimmed, policy.safety.secretPatterns)) return false;
260
+ if (CONTRAST_OR_EXCEPTION_PATTERN.test(trimmed)) return false;
261
+ return NEGATIVE_SAFETY_DIRECTIVE_PATTERN.test(trimmed)
262
+ || /^\s*(must\s+not|forbidden[_ -]?paths?|forbidden|denylist|deny[_ -]?list|do\s+not)\s*[:\-]/i.test(trimmed);
263
+ }
264
+
265
+ function secretAccessDetectionText(text: string, policy: InteractiveAutonomyPolicy): string {
266
+ return text
267
+ .split(/\r?\n/)
268
+ .filter((line) => !isNegativeSecretSafetyLine(line, policy))
269
+ .join("\n");
270
+ }
271
+
272
+ function secretAccessRequested(text: string, policy: InteractiveAutonomyPolicy): boolean {
273
+ const detectionText = secretAccessDetectionText(text, policy);
274
+ const secretMention = patternMatchesAny(detectionText, policy.safety.secretPatterns);
275
+ if (!secretMention) return false;
276
+ return SECRET_ACCESS_VERB_PATTERN.test(detectionText)
277
+ || SECRET_ACCESS_CONTEXT_PATTERN.test(detectionText);
278
+ }
279
+
280
+ function productionApplyRequested(text: string): boolean {
281
+ return /\b(deploy|release|ship|apply|write|push|publish|déploie|deploie|publie|livre|applique)\b.{0,80}\b(prod|production|live)\b/i.test(text)
282
+ || /\b(prod|production|live)\b.{0,80}\b(deploy|release|ship|apply|write|push|publish|déploie|deploie|publie|livre|applique)\b/i.test(text);
283
+ }
284
+
285
+ function extractTargetPaths(text: string): string[] {
286
+ const matches = text.match(/(?:^|[\s`'"(:])((?:\.?\.?\/?[\w@.-]+\/)*[\w@.-]+\.(?:ts|tsx|js|jsx|mjs|cjs|json|md|mdx|yml|yaml|toml|py|rs|go|java|kt|css|scss|html|sh|sql))(?:$|[\s`'"),.:;])/gi) ?? [];
287
+ const normalized = matches
288
+ .map((match) => match.replace(/^[\s`'"(:]+|[\s`'"),.:;]+$/g, ""))
289
+ .filter((item) => item.length > 0 && !item.startsWith("/home/") && !item.startsWith("~"));
290
+ return [...new Set(normalized)].slice(0, 12);
291
+ }
292
+
293
+ function countPositiveSignals(signals: MissionReadinessSignals): number {
294
+ return [signals.clarity, signals.acceptanceCriteria, signals.targetPaths, signals.testability, signals.safety].filter((value) => value >= 0.5).length;
295
+ }
296
+
297
+ function missionReadinessHash(base: Omit<MissionReadinessReport, "launchAuthorization">): string {
298
+ return sha256(JSON.stringify({
299
+ schema: base.schema,
300
+ mode: base.mode,
301
+ decision: base.decision,
302
+ verdict: base.verdict,
303
+ score: base.score,
304
+ risk: base.risk,
305
+ signals: base.signals,
306
+ blockerCodes: base.blockerCodes,
307
+ clarificationCodes: base.clarificationCodes,
308
+ safetyGateCodes: base.safetyGateCodes,
309
+ userInputHash: base.userInputHash,
310
+ targetPathHashes: base.targetPathHashes,
311
+ generatedAt: base.generatedAt,
312
+ }));
313
+ }
314
+
315
+ export function buildInteractiveLaunchAuthorization(input: {
316
+ readiness: Omit<MissionReadinessReport, "launchAuthorization">;
317
+ policy: InteractiveAutonomyPolicy;
318
+ mode: Exclude<InteractiveAutonomyMode, "off">;
319
+ }): InteractiveLaunchAuthorization {
320
+ const allowedPaths = input.readiness.targetPathRefs.length > 0 ? input.readiness.targetPathRefs : input.policy.launch.defaultAllowedPaths;
321
+ return {
322
+ schema: "zob.launch-authorization.v1",
323
+ userInputHash: input.readiness.userInputHash,
324
+ missionReadinessHash: missionReadinessHash(input.readiness),
325
+ specLocked: true,
326
+ userLaunchConfirmed: true,
327
+ autonomyMode: input.mode,
328
+ allowedActions: input.policy.launch.defaultAllowedActions,
329
+ allowedPaths,
330
+ forbiddenPaths: input.policy.safety.forbiddenPathPatterns,
331
+ applyPolicy: {
332
+ mode: "interactive_in_scope",
333
+ manualPerActionApprovalRequired: input.policy.launch.manualPerActionApprovalWhenLaunched,
334
+ validationRequired: input.policy.launch.requireValidationEvidence,
335
+ oracleRequiredForCompletion: input.policy.launch.requireOracleForCompletion,
336
+ productionApplyAllowed: false,
337
+ },
338
+ stopConditions: input.policy.launch.stopConditions,
339
+ launchAuthorizesInScopeActions: true,
340
+ actionExecutionBlockedUntilLaunch: false,
341
+ exceptionApprovalRequiredOnlyForOutOfScope: true,
342
+ globalProductionClaimAllowed: false,
343
+ bodyStored: false,
344
+ promptBodiesStored: false,
345
+ outputBodiesStored: false,
346
+ };
347
+ }
348
+
349
+ export function scoreMissionReadiness(text: string, options: { mode: InteractiveAutonomyMode; policy: InteractiveAutonomyPolicy; generatedAt?: string | Date }): MissionReadinessReport {
350
+ const policy = options.policy;
351
+ const mode = options.mode;
352
+ const raw = text.trim();
353
+ const normalized = raw.toLowerCase();
354
+ const userInputHash = sha256(raw);
355
+ const generatedAt = options.generatedAt instanceof Date ? options.generatedAt.toISOString() : options.generatedAt ?? new Date().toISOString();
356
+ const targetPathRefs = extractTargetPaths(raw);
357
+ const targetPathHashes = targetPathRefs.map((item) => sha256(item));
358
+
359
+ const blockerCodes: string[] = [];
360
+ const clarificationCodes: string[] = [];
361
+ const safetyGateCodes = ["no_secrets", "no_destructive_commands", "no_production_apply", "no_global_production_claim", "validation_required"];
362
+
363
+ const hasActionVerb = /\b(implement|impl[eé]mente|build|cr[eé]e|create|add|ajoute|fix|corrige|modify|modifie|change|update|mets?|refactor|refactorise|wire|branche|brancher|validate|test|smoke|audit|review|documente|write|edit|fais|make)\b/i.test(raw);
364
+ const hasAcceptanceLanguage = /\b(acceptance|criteria|crit[eè]res?|must|must not|doit|ne doit pas|validation|validate|test|smoke|preuve|evidence|oracle|done when|definition of done)\b/i.test(raw);
365
+ const hasTestabilityLanguage = /\b(test|tests|smoke|npm run|check|typecheck|validation|validate|oracle|proof|preuve|assert|v[eé]rifie|verify)\b/i.test(raw);
366
+ const asksClarificationOnly = /\b(explain|explique|pourquoi|question|aide|help|status|statut|montre|show)\b/i.test(raw) && !hasActionVerb;
367
+ const destructiveRequested = policy.safety.blockDestructiveCommands && patternMatchesAny(raw, policy.safety.destructivePatterns);
368
+ const secretRequested = policy.safety.blockSecretAccess && secretAccessRequested(raw, policy);
369
+ const productionRequested = policy.safety.blockProductionApply && productionApplyRequested(raw);
370
+ const globalClaimRequested = /\b(100%|global|production[- ]?wide|full production|prod)\b.{0,80}\b(claim|declare|prouve|prove|certifie|certify|ready|autonomous|autonomie)\b/i.test(raw);
371
+
372
+ if (!raw) blockerCodes.push("user_input_missing");
373
+ if (destructiveRequested) blockerCodes.push("destructive_action_requested");
374
+ if (secretRequested) blockerCodes.push("secret_access_requested");
375
+ if (productionRequested) blockerCodes.push("production_apply_requires_explicit_gate");
376
+ if (globalClaimRequested) clarificationCodes.push("global_production_claim_requires_fresh_oracle_proof");
377
+
378
+ const clarity = raw.length >= 80 && hasActionVerb ? 0.9 : raw.length >= 35 && hasActionVerb ? 0.72 : hasActionVerb ? 0.55 : asksClarificationOnly ? 0.35 : raw.length > 0 ? 0.25 : 0;
379
+ const acceptanceCriteria = hasAcceptanceLanguage ? 0.8 : /\b(done|fini|termin[eé]|livrable|deliverable)\b/i.test(raw) ? 0.5 : 0.15;
380
+ const targetPaths = targetPathRefs.length > 0 ? 0.85 : /\b(repo|project|harness|pi|extension|codebase|projet)\b/i.test(raw) ? 0.45 : 0.15;
381
+ const testability = hasTestabilityLanguage ? 0.85 : /\b(works|fonctionne|ready|ok)\b/i.test(raw) ? 0.35 : 0.15;
382
+ const risk: MissionRiskLevel = blockerCodes.length > 0 || productionRequested ? "high" : /\b(network|browser|cloud|api|deploy|publish|commit|database|db|payment|auth)\b/i.test(normalized) ? "medium" : "low";
383
+ const safety = risk === "high" ? 0 : risk === "medium" ? 0.55 : 1;
384
+ const signals: MissionReadinessSignals = {
385
+ clarity: round2(clarity),
386
+ acceptanceCriteria: round2(acceptanceCriteria),
387
+ targetPaths: round2(targetPaths),
388
+ testability: round2(testability),
389
+ safety: round2(safety),
390
+ };
391
+ const score = round2((signals.clarity * 0.3) + (signals.acceptanceCriteria * 0.22) + (signals.targetPaths * 0.18) + (signals.testability * 0.18) + (signals.safety * 0.12));
392
+
393
+ if (signals.clarity < 0.5) clarificationCodes.push("mission_intent_unclear");
394
+ if (signals.targetPaths < 0.5) clarificationCodes.push("target_paths_or_scope_missing");
395
+ if (signals.testability < 0.5) clarificationCodes.push("validation_evidence_missing");
396
+ if (signals.acceptanceCriteria < 0.5) clarificationCodes.push("acceptance_criteria_missing");
397
+ if (risk === "medium") clarificationCodes.push("medium_risk_requires_scope_confirmation");
398
+
399
+ let decision: MissionReadinessDecision;
400
+ if (mode === "off") decision = "stopped";
401
+ else if (blockerCodes.length > 0) decision = "block";
402
+ else if (mode === "open") decision = raw.length > 0 ? "auto_launch" : "clarify";
403
+ else if (mode === "controlled") {
404
+ decision = score >= policy.thresholds.controlledAutoLaunch && countPositiveSignals(signals) >= policy.thresholds.controlledMinimumSignals ? "auto_launch" : "clarify";
405
+ } else {
406
+ decision = score >= policy.thresholds.adaptiveAutoLaunch && signals.clarity >= 0.5 && risk !== "medium" ? "auto_launch" : "clarify";
407
+ if (score < policy.thresholds.adaptiveClarifyBelow) decision = "clarify";
408
+ }
409
+
410
+ const verdict: MissionReadinessVerdict = decision === "auto_launch" ? "READY" : decision === "block" ? "BLOCKED" : decision === "stopped" ? "STOPPED" : "NEEDS_CLARIFICATION";
411
+ const base: Omit<MissionReadinessReport, "launchAuthorization"> = {
412
+ schema: "zob.mission-readiness.v1",
413
+ mode,
414
+ decision,
415
+ verdict,
416
+ score,
417
+ risk,
418
+ signals,
419
+ blockerCodes: [...new Set(blockerCodes)],
420
+ clarificationCodes: [...new Set(clarificationCodes)],
421
+ safetyGateCodes,
422
+ userInputHash,
423
+ rawInputStored: false,
424
+ targetPathRefs,
425
+ targetPathHashes,
426
+ manualPerActionApprovalRequired: decision !== "auto_launch" || policy.launch.manualPerActionApprovalWhenLaunched,
427
+ inScopeAutonomousActionsAuthorized: decision === "auto_launch",
428
+ safetyGatesStillEnabled: true,
429
+ noShip: decision === "block",
430
+ globalProductionClaimAllowed: false,
431
+ bodyStored: false,
432
+ promptBodiesStored: false,
433
+ outputBodiesStored: false,
434
+ generatedAt,
435
+ };
436
+ return decision === "auto_launch" && mode !== "off"
437
+ ? { ...base, launchAuthorization: buildInteractiveLaunchAuthorization({ readiness: base, policy, mode }) }
438
+ : base;
439
+ }
440
+
441
+ export function toAutonomyStateLedgerEntry(state: InteractiveAutonomyRuntimeState): Record<string, unknown> {
442
+ return {
443
+ schema: "zob.interactive-autonomy-state.v1",
444
+ mode: state.mode,
445
+ enabled: state.enabled,
446
+ policyHash: state.policyHash,
447
+ policySource: state.policy.source,
448
+ manualPerActionApprovalWhenLaunched: state.policy.launch.manualPerActionApprovalWhenLaunched,
449
+ safetyGatesStillEnabled: true,
450
+ bodyStored: false,
451
+ promptBodiesStored: false,
452
+ outputBodiesStored: false,
453
+ updatedAt: state.updatedAt ?? new Date().toISOString(),
454
+ };
455
+ }
456
+
457
+ export function toMissionReadinessLedgerEntry(readiness: MissionReadinessReport): Record<string, unknown> {
458
+ return {
459
+ schema: readiness.schema,
460
+ mode: readiness.mode,
461
+ decision: readiness.decision,
462
+ verdict: readiness.verdict,
463
+ score: readiness.score,
464
+ risk: readiness.risk,
465
+ signals: readiness.signals,
466
+ blockerCodes: readiness.blockerCodes,
467
+ clarificationCodes: readiness.clarificationCodes,
468
+ safetyGateCodes: readiness.safetyGateCodes,
469
+ userInputHash: readiness.userInputHash,
470
+ rawInputStored: false,
471
+ targetPathHashes: readiness.targetPathHashes,
472
+ targetPathRefsStored: false,
473
+ manualPerActionApprovalRequired: readiness.manualPerActionApprovalRequired,
474
+ inScopeAutonomousActionsAuthorized: readiness.inScopeAutonomousActionsAuthorized,
475
+ launchAuthorizationHash: readiness.launchAuthorization ? sha256(JSON.stringify(readiness.launchAuthorization)) : undefined,
476
+ launchAuthorizationSchema: readiness.launchAuthorization?.schema,
477
+ noShip: readiness.noShip,
478
+ globalProductionClaimAllowed: false,
479
+ bodyStored: false,
480
+ promptBodiesStored: false,
481
+ outputBodiesStored: false,
482
+ generatedAt: readiness.generatedAt,
483
+ };
484
+ }
485
+
486
+ export function restoreInteractiveAutonomyState(repoRoot: string | undefined, branch: unknown[], previous?: InteractiveAutonomyRuntimeState): InteractiveAutonomyRuntimeState {
487
+ const policy = readInteractiveAutonomyPolicy(repoRoot);
488
+ const restored = previous ?? createInteractiveAutonomyRuntimeState(policy);
489
+ restored.policy = policy;
490
+ restored.policyHash = hashInteractiveAutonomyPolicy(policy);
491
+ restored.mode = policy.defaultMode;
492
+ restored.enabled = policy.defaultMode !== "off";
493
+ for (const entry of branch) {
494
+ if (!isRecord(entry)) continue;
495
+ const customType = typeof entry.customType === "string" ? entry.customType : "";
496
+ const data = isRecord(entry.data) ? entry.data : undefined;
497
+ if (customType === "zob-autonomy-state" && data) {
498
+ const mode = asInteractiveAutonomyMode(data.mode);
499
+ if (mode) {
500
+ restored.mode = mode;
501
+ restored.enabled = mode !== "off" && data.enabled !== false;
502
+ restored.updatedAt = typeof data.updatedAt === "string" ? data.updatedAt : restored.updatedAt;
503
+ }
504
+ }
505
+ if (customType === "zob-mission-readiness" && data && data.schema === "zob.mission-readiness.v1") {
506
+ const mode = asInteractiveAutonomyMode(data.mode) ?? restored.mode;
507
+ const decision = typeof data.decision === "string" && ["auto_launch", "clarify", "block", "stopped"].includes(data.decision) ? data.decision as MissionReadinessDecision : undefined;
508
+ const verdict = typeof data.verdict === "string" && ["READY", "NEEDS_CLARIFICATION", "BLOCKED", "STOPPED"].includes(data.verdict) ? data.verdict as MissionReadinessVerdict : undefined;
509
+ if (decision && verdict && typeof data.userInputHash === "string") {
510
+ const signals = isRecord(data.signals) ? data.signals : {};
511
+ restored.lastReadiness = {
512
+ schema: "zob.mission-readiness.v1",
513
+ mode,
514
+ decision,
515
+ verdict,
516
+ score: typeof data.score === "number" ? data.score : 0,
517
+ risk: data.risk === "medium" || data.risk === "high" ? data.risk : "low",
518
+ signals: {
519
+ clarity: typeof signals.clarity === "number" ? signals.clarity : 0,
520
+ acceptanceCriteria: typeof signals.acceptanceCriteria === "number" ? signals.acceptanceCriteria : 0,
521
+ targetPaths: typeof signals.targetPaths === "number" ? signals.targetPaths : 0,
522
+ testability: typeof signals.testability === "number" ? signals.testability : 0,
523
+ safety: typeof signals.safety === "number" ? signals.safety : 0,
524
+ },
525
+ blockerCodes: stringArray(data.blockerCodes, []),
526
+ clarificationCodes: stringArray(data.clarificationCodes, []),
527
+ safetyGateCodes: stringArray(data.safetyGateCodes, []),
528
+ userInputHash: data.userInputHash,
529
+ rawInputStored: false,
530
+ targetPathRefs: stringArray(data.targetPathRefs, []),
531
+ targetPathHashes: stringArray(data.targetPathHashes, []),
532
+ manualPerActionApprovalRequired: data.manualPerActionApprovalRequired !== false,
533
+ inScopeAutonomousActionsAuthorized: data.inScopeAutonomousActionsAuthorized === true,
534
+ safetyGatesStillEnabled: true,
535
+ noShip: data.noShip === true,
536
+ globalProductionClaimAllowed: false,
537
+ bodyStored: false,
538
+ promptBodiesStored: false,
539
+ outputBodiesStored: false,
540
+ generatedAt: typeof data.generatedAt === "string" ? data.generatedAt : new Date().toISOString(),
541
+ };
542
+ }
543
+ }
544
+ }
545
+ restored.lastLaunchAuthorization = restored.lastReadiness?.launchAuthorization;
546
+ return restored;
547
+ }
548
+
549
+ export function formatMissionReadinessForUi(readiness: MissionReadinessReport | undefined): string {
550
+ if (!readiness) return "mission-readiness: none";
551
+ const codes = readiness.decision === "block" ? readiness.blockerCodes : readiness.clarificationCodes;
552
+ const suffix = codes.length > 0 ? ` · ${codes.slice(0, 3).join(",")}` : "";
553
+ return `mission-readiness ${readiness.mode}/${readiness.decision} · score=${readiness.score.toFixed(2)} · risk=${readiness.risk}${suffix}`;
554
+ }
555
+
556
+ export function formatInteractiveAutonomyStatus(state: InteractiveAutonomyRuntimeState): string {
557
+ const launch = state.lastLaunchAuthorization ? "launch=authorized" : "launch=none";
558
+ return [
559
+ `autonomy mode=${state.mode} enabled=${state.enabled}`,
560
+ `policy=${state.policy.source} hash=${state.policyHash.slice(0, 12)}`,
561
+ `manual_per_action_when_launched=${state.policy.launch.manualPerActionApprovalWhenLaunched}`,
562
+ `safety=no-secrets,no-destructive,no-production-apply,on`,
563
+ `${formatMissionReadinessForUi(state.lastReadiness)} · ${launch}`,
564
+ `globalProductionClaimAllowed=false bodyStored=false`,
565
+ ].join("\n");
566
+ }
567
+
568
+ export function formatInteractiveAutonomyPromptHint(state: InteractiveAutonomyRuntimeState): string {
569
+ const readiness = state.lastReadiness;
570
+ const launch = readiness?.launchAuthorization;
571
+ const modeLine = `- mode: ${state.mode} (${state.enabled ? "enabled" : "disabled"}); policy=${state.policy.source}; policy_hash=${state.policyHash.slice(0, 12)}`;
572
+ const readinessLine = readiness
573
+ ? `- mission-readiness.v1: decision=${readiness.decision}; verdict=${readiness.verdict}; score=${readiness.score.toFixed(2)}; risk=${readiness.risk}; input_hash=${readiness.userInputHash.slice(0, 12)}; raw_input_stored=false`
574
+ : "- mission-readiness.v1: none for this branch yet";
575
+ const launchLine = launch
576
+ ? `- launch-authorization.v1: spec_locked=true; user_launch_confirmed=true; manual_per_action_approval_required=${launch.applyPolicy.manualPerActionApprovalRequired}; allowed_actions=${launch.allowedActions.join(",")}; production_apply_allowed=false`
577
+ : "- launch-authorization.v1: none; if decision is clarify/block do not proceed as launched";
578
+ const behavior = readiness?.decision === "auto_launch" && launch
579
+ ? "- Behavior: proceed autonomously for in-scope, policy-compliant work without per-action approval; still use Explore→Plan→Implement→Oracle, concrete validation, TODO/goal gates when appropriate."
580
+ : readiness?.decision === "auto_launch" && !launch
581
+ ? "- Behavior: prior auto-launch readiness was restored hash-only without path scope; do not treat it as active launch authorization. Ask for re-confirmation or re-score the current user request."
582
+ : readiness?.decision === "block"
583
+ ? "- Behavior: do not execute the requested risky action; explain the blocker and request a safe, in-scope revision."
584
+ : readiness?.decision === "stopped" || state.mode === "off"
585
+ ? "- Behavior: autonomy stopped; operate in normal supervised harness mode."
586
+ : "- Behavior: ask the minimum clarifying/challenge questions needed before launching; do not claim launch authorization yet.";
587
+ return [
588
+ "ZOB INTERACTIVE AUTONOMY",
589
+ modeLine,
590
+ readinessLine,
591
+ launchLine,
592
+ behavior,
593
+ "- Non-negotiable gates remain active: no secrets, no destructive commands, no commits unless requested, no out-of-scope writes, no global production autonomy claim without fresh proof and oracle PASS/no_ship=false.",
594
+ ].join("\n");
595
+ }