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.
- package/.pi/adapters/registry.json +103 -0
- package/.pi/agents/architecture-cartographer.md +53 -0
- package/.pi/agents/chief-vision.md +39 -0
- package/.pi/agents/clarifier.md +58 -0
- package/.pi/agents/context-steward.md +52 -0
- package/.pi/agents/doc-steward.md +34 -0
- package/.pi/agents/explore.md +49 -0
- package/.pi/agents/factory.md +41 -0
- package/.pi/agents/implementer.md +44 -0
- package/.pi/agents/librarian.md +32 -0
- package/.pi/agents/oracle-merge.md +50 -0
- package/.pi/agents/oracle.md +55 -0
- package/.pi/agents/pattern-miner.md +53 -0
- package/.pi/agents/planner.md +39 -0
- package/.pi/agents/project-dna-golden-evaluator.md +32 -0
- package/.pi/agents/project-dna-ontology-steward.md +30 -0
- package/.pi/agents/project-dna-oracle.md +56 -0
- package/.pi/agents/project-dna-orchestrator.md +60 -0
- package/.pi/agents/project-dna-query-steward.md +38 -0
- package/.pi/agents/project-dna-safety-preflight.md +54 -0
- package/.pi/agents/project-dna-test-linker.md +27 -0
- package/.pi/agents/qa.md +38 -0
- package/.pi/agents/refactor-cartographer.md +28 -0
- package/.pi/agents/refactor-mover.md +31 -0
- package/.pi/agents/refactor-oracle.md +49 -0
- package/.pi/agents/repo-scout.md +60 -0
- package/.pi/agents/sample-architect.md +48 -0
- package/.pi/agents/specifier.md +57 -0
- package/.pi/agents/symbol-range-curator.md +41 -0
- package/.pi/agents/synthesis.md +52 -0
- package/.pi/agents/temp-agent-creator.md +35 -0
- package/.pi/autonomy-policy.json +67 -0
- package/.pi/budget-policy.json +54 -0
- package/.pi/capabilities/zob-public-runtime-capabilities.json +1700 -0
- package/.pi/chains/explore-plan-oracle.json +78 -0
- package/.pi/chains/explore-spec-clarify-plan-oracle.json +64 -0
- package/.pi/chains/explore-spec-plan-oracle.json +53 -0
- package/.pi/chains/spec-clarify-plan-oracle.json +53 -0
- package/.pi/chains/spec-factory-oracle.json +42 -0
- package/.pi/chains/spec-plan-oracle.json +42 -0
- package/.pi/compute-profiles/defaults.json +19 -0
- package/.pi/compute-profiles/overrides.json +13 -0
- package/.pi/compute-profiles/risk-rules.json +16 -0
- package/.pi/daemon-policy.json +80 -0
- package/.pi/damage-control-rules.json +45 -0
- package/.pi/extensions/zob-child-safety/index.ts +212 -0
- package/.pi/extensions/zob-harness/AGENTS.md +28 -0
- package/.pi/extensions/zob-harness/index.ts +391 -0
- package/.pi/extensions/zob-harness/src/AGENTS.md +25 -0
- package/.pi/extensions/zob-harness/src/agents.ts +82 -0
- package/.pi/extensions/zob-harness/src/autonomous-runtime.ts +2912 -0
- package/.pi/extensions/zob-harness/src/autonomy-readiness.ts +778 -0
- package/.pi/extensions/zob-harness/src/budget-policy.ts +308 -0
- package/.pi/extensions/zob-harness/src/capabilities.ts +249 -0
- package/.pi/extensions/zob-harness/src/child-runner.ts +249 -0
- package/.pi/extensions/zob-harness/src/chronicle.ts +262 -0
- package/.pi/extensions/zob-harness/src/compute-profile.ts +602 -0
- package/.pi/extensions/zob-harness/src/compute-workflow-shape.ts +168 -0
- package/.pi/extensions/zob-harness/src/coms-v2/AGENTS.md +16 -0
- package/.pi/extensions/zob-harness/src/coms-v2/envelope.ts +121 -0
- package/.pi/extensions/zob-harness/src/coms-v2/identity.ts +53 -0
- package/.pi/extensions/zob-harness/src/coms-v2/ledger-bridge.ts +67 -0
- package/.pi/extensions/zob-harness/src/coms-v2/local-transport.ts +147 -0
- package/.pi/extensions/zob-harness/src/coms-v2/pending-replies.ts +80 -0
- package/.pi/extensions/zob-harness/src/coms-v2/policy.ts +125 -0
- package/.pi/extensions/zob-harness/src/coms-v2/presence.ts +55 -0
- package/.pi/extensions/zob-harness/src/coms-v2/registry.ts +113 -0
- package/.pi/extensions/zob-harness/src/coms-v2/response-capture.ts +50 -0
- package/.pi/extensions/zob-harness/src/coms-v2/transcript-capture.ts +164 -0
- package/.pi/extensions/zob-harness/src/coms-v2/types.ts +149 -0
- package/.pi/extensions/zob-harness/src/coms-v2/zpeer-profile.ts +140 -0
- package/.pi/extensions/zob-harness/src/coms-v2/zpeer.ts +452 -0
- package/.pi/extensions/zob-harness/src/constants.ts +108 -0
- package/.pi/extensions/zob-harness/src/context-gbrain.ts +465 -0
- package/.pi/extensions/zob-harness/src/daemon-policy.ts +223 -0
- package/.pi/extensions/zob-harness/src/daemon-readiness.ts +134 -0
- package/.pi/extensions/zob-harness/src/daemon-runtime.ts +393 -0
- package/.pi/extensions/zob-harness/src/factory/AGENTS.md +24 -0
- package/.pi/extensions/zob-harness/src/factory/agentic-plan.ts +65 -0
- package/.pi/extensions/zob-harness/src/factory/quarantine.ts +319 -0
- package/.pi/extensions/zob-harness/src/factory/run.ts +520 -0
- package/.pi/extensions/zob-harness/src/factory/validation.ts +454 -0
- package/.pi/extensions/zob-harness/src/factory-selector.ts +318 -0
- package/.pi/extensions/zob-harness/src/full-autonomy-test.ts +226 -0
- package/.pi/extensions/zob-harness/src/git-ops.ts +868 -0
- package/.pi/extensions/zob-harness/src/goal-room.ts +178 -0
- package/.pi/extensions/zob-harness/src/goal-runtime.ts +1569 -0
- package/.pi/extensions/zob-harness/src/goal-todo-imports.ts +111 -0
- package/.pi/extensions/zob-harness/src/goal-todo-types.ts +231 -0
- package/.pi/extensions/zob-harness/src/goal-todos.ts +1410 -0
- package/.pi/extensions/zob-harness/src/goal.ts +152 -0
- package/.pi/extensions/zob-harness/src/governed-requests.ts +436 -0
- package/.pi/extensions/zob-harness/src/interactive-autonomy.ts +595 -0
- package/.pi/extensions/zob-harness/src/launch-apply.ts +313 -0
- package/.pi/extensions/zob-harness/src/merge-queue.ts +290 -0
- package/.pi/extensions/zob-harness/src/mission-control.ts +573 -0
- package/.pi/extensions/zob-harness/src/model-availability.ts +52 -0
- package/.pi/extensions/zob-harness/src/model-routing.ts +429 -0
- package/.pi/extensions/zob-harness/src/orchestration/AGENTS.md +23 -0
- package/.pi/extensions/zob-harness/src/orchestration/adaptive-delegation.ts +547 -0
- package/.pi/extensions/zob-harness/src/orchestration/adaptive-workflow.ts +585 -0
- package/.pi/extensions/zob-harness/src/orchestration/lead-plan.ts +192 -0
- package/.pi/extensions/zob-harness/src/orchestration/plan.ts +168 -0
- package/.pi/extensions/zob-harness/src/orchestration/room.ts +346 -0
- package/.pi/extensions/zob-harness/src/orchestration/run.ts +134 -0
- package/.pi/extensions/zob-harness/src/orchestration/supervised-readonly.ts +1147 -0
- package/.pi/extensions/zob-harness/src/orchestration/widget-readers.ts +132 -0
- package/.pi/extensions/zob-harness/src/output-contracts.ts +656 -0
- package/.pi/extensions/zob-harness/src/project-dna.ts +533 -0
- package/.pi/extensions/zob-harness/src/promotion/AGENTS.md +24 -0
- package/.pi/extensions/zob-harness/src/promotion/candidate.ts +336 -0
- package/.pi/extensions/zob-harness/src/promotion/coms.ts +127 -0
- package/.pi/extensions/zob-harness/src/promotion/documentation.ts +142 -0
- package/.pi/extensions/zob-harness/src/promotion/factory.ts +107 -0
- package/.pi/extensions/zob-harness/src/promotion/ledger.ts +2 -0
- package/.pi/extensions/zob-harness/src/promotion/temp-agent.ts +151 -0
- package/.pi/extensions/zob-harness/src/promotion/types.ts +149 -0
- package/.pi/extensions/zob-harness/src/promotion/validate.ts +6 -0
- package/.pi/extensions/zob-harness/src/promotion/write-lane.ts +162 -0
- package/.pi/extensions/zob-harness/src/prompt-packs.ts +239 -0
- package/.pi/extensions/zob-harness/src/queue.ts +386 -0
- package/.pi/extensions/zob-harness/src/rules.ts +225 -0
- package/.pi/extensions/zob-harness/src/runtime/AGENTS.md +26 -0
- package/.pi/extensions/zob-harness/src/runtime/adaptive-zmode.ts +116 -0
- package/.pi/extensions/zob-harness/src/runtime/auto-compaction.ts +715 -0
- package/.pi/extensions/zob-harness/src/runtime/commands.ts +1315 -0
- package/.pi/extensions/zob-harness/src/runtime/compaction-policy.ts +516 -0
- package/.pi/extensions/zob-harness/src/runtime/delegation-click-markers.ts +141 -0
- package/.pi/extensions/zob-harness/src/runtime/delegation-feed.ts +415 -0
- package/.pi/extensions/zob-harness/src/runtime/delegation-markdown.ts +97 -0
- package/.pi/extensions/zob-harness/src/runtime/delegation-monitor.ts +553 -0
- package/.pi/extensions/zob-harness/src/runtime/delegation-mouse.ts +205 -0
- package/.pi/extensions/zob-harness/src/runtime/delegation-overlay.ts +434 -0
- package/.pi/extensions/zob-harness/src/runtime/events.ts +736 -0
- package/.pi/extensions/zob-harness/src/runtime/goal-todo-overlay.ts +214 -0
- package/.pi/extensions/zob-harness/src/runtime/mode-intent.ts +144 -0
- package/.pi/extensions/zob-harness/src/runtime/plan-capture.ts +270 -0
- package/.pi/extensions/zob-harness/src/runtime/state.ts +403 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-autonomous.ts +117 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-compute.ts +136 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-coms.ts +365 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-context.ts +70 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-delegation.ts +1854 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-factory.ts +810 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-goal-room.ts +46 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-governed-requests.ts +38 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-merge-queue.ts +61 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-mission-control.ts +77 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-orchestration.ts +106 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-project-dna.ts +123 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-worker-pool.ts +93 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-workspace-claims.ts +62 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-zcommit.ts +147 -0
- package/.pi/extensions/zob-harness/src/runtime/widget.ts +353 -0
- package/.pi/extensions/zob-harness/src/runtime/zobHarness.ts +60 -0
- package/.pi/extensions/zob-harness/src/safety.ts +338 -0
- package/.pi/extensions/zob-harness/src/sandbox.ts +1508 -0
- package/.pi/extensions/zob-harness/src/schemas-project-dna.ts +47 -0
- package/.pi/extensions/zob-harness/src/schemas.ts +695 -0
- package/.pi/extensions/zob-harness/src/telemetry.ts +373 -0
- package/.pi/extensions/zob-harness/src/topology/AGENTS.md +22 -0
- package/.pi/extensions/zob-harness/src/topology/chains.ts +236 -0
- package/.pi/extensions/zob-harness/src/topology/coms.ts +211 -0
- package/.pi/extensions/zob-harness/src/topology/orchestration-profiles.ts +204 -0
- package/.pi/extensions/zob-harness/src/topology/teams.ts +113 -0
- package/.pi/extensions/zob-harness/src/types/core.ts +47 -0
- package/.pi/extensions/zob-harness/src/types.ts +939 -0
- package/.pi/extensions/zob-harness/src/utils/AGENTS.md +22 -0
- package/.pi/extensions/zob-harness/src/utils/formatting.ts +34 -0
- package/.pi/extensions/zob-harness/src/utils/hashing.ts +11 -0
- package/.pi/extensions/zob-harness/src/utils/json.ts +28 -0
- package/.pi/extensions/zob-harness/src/utils/paths.ts +54 -0
- package/.pi/extensions/zob-harness/src/utils/records.ts +25 -0
- package/.pi/extensions/zob-harness/src/utils/resources.ts +38 -0
- package/.pi/extensions/zob-harness/src/worker-pool.ts +672 -0
- package/.pi/extensions/zob-harness/src/workspace-claims.ts +297 -0
- package/.pi/extensions/zob-switch/index.ts +180 -0
- package/.pi/factories/budget-preflight-dry-run/batch-manifest.json +59 -0
- package/.pi/factories/budget-preflight-dry-run/factory.json +94 -0
- package/.pi/factories/budget-preflight-dry-run/pilot-manifest.json +50 -0
- package/.pi/factories/budget-preflight-dry-run/smoke-manifest.json +43 -0
- package/.pi/factories/code-review-matrix/batch-manifest.json +61 -0
- package/.pi/factories/code-review-matrix/factory.json +163 -0
- package/.pi/factories/code-review-matrix/pilot-manifest.json +41 -0
- package/.pi/factories/code-review-matrix/smoke-manifest.json +35 -0
- package/.pi/factories/factory-forge/batch-manifest.json +56 -0
- package/.pi/factories/factory-forge/factory.json +84 -0
- package/.pi/factories/factory-forge/pilot-manifest.json +32 -0
- package/.pi/factories/factory-forge/smoke-manifest.json +19 -0
- package/.pi/factories/opencode-pattern-canonizer/batch-manifest.json +54 -0
- package/.pi/factories/opencode-pattern-canonizer/factory.json +86 -0
- package/.pi/factories/opencode-pattern-canonizer/pilot-manifest.json +39 -0
- package/.pi/factories/opencode-pattern-canonizer/smoke-manifest.json +26 -0
- package/.pi/factories/project-dna/README.md +182 -0
- package/.pi/factories/project-dna/batch-manifest.json +37 -0
- package/.pi/factories/project-dna/example-project-dna-manifest-v2.json +80 -0
- package/.pi/factories/project-dna/example-project-dna-manifest.json +58 -0
- package/.pi/factories/project-dna/factory.json +131 -0
- package/.pi/factories/project-dna/golden-cases-smoke.json +62 -0
- package/.pi/factories/project-dna/pi-agentic-ontology.json +88 -0
- package/.pi/factories/project-dna/pilot-manifest.json +32 -0
- package/.pi/factories/project-dna/schemas/benchmark-suite.schema.json +27 -0
- package/.pi/factories/project-dna/schemas/code-knowledge-graph.schema.json +97 -0
- package/.pi/factories/project-dna/schemas/context-pack.schema.json +43 -0
- package/.pi/factories/project-dna/schemas/golden-case.schema.json +36 -0
- package/.pi/factories/project-dna/schemas/manifest-v2.schema.json +128 -0
- package/.pi/factories/project-dna/schemas/manifest.schema.json +77 -0
- package/.pi/factories/project-dna/schemas/ontology.schema.json +45 -0
- package/.pi/factories/project-dna/schemas/project-fingerprint.schema.json +28 -0
- package/.pi/factories/project-dna/schemas/query-steward-report.schema.json +52 -0
- package/.pi/factories/project-dna/smoke-manifest.json +27 -0
- package/.pi/factories/roadmap-smoke-lots/batch-manifest.json +49 -0
- package/.pi/factories/roadmap-smoke-lots/factory.json +89 -0
- package/.pi/factories/roadmap-smoke-lots/pilot-manifest.json +50 -0
- package/.pi/factories/roadmap-smoke-lots/smoke-manifest.json +35 -0
- package/.pi/git-policy.json +120 -0
- package/.pi/mission-control/zob_coms_transport.json +64 -0
- package/.pi/model-catalog.example.json +345 -0
- package/.pi/model-economy.example.json +196 -0
- package/.pi/model-routing.json +86 -0
- package/.pi/orchestrations/adaptive-chief-vision.json +193 -0
- package/.pi/orchestrations/ceo-feature-build.json +182 -0
- package/.pi/orchestrations/readonly-dynamic-smoke.json +75 -0
- package/.pi/output-contracts/agent-event.v1.json +19 -0
- package/.pi/output-contracts/base.v1.json +24 -0
- package/.pi/output-contracts/brain-lookup.v1.json +21 -0
- package/.pi/output-contracts/clarification.v1.json +21 -0
- package/.pi/output-contracts/context-pack.v1.json +20 -0
- package/.pi/output-contracts/context-request.v1.json +21 -0
- package/.pi/output-contracts/context-steward.v1.json +19 -0
- package/.pi/output-contracts/context-writeback-proposal.v1.json +18 -0
- package/.pi/output-contracts/delegation-request.v1.json +21 -0
- package/.pi/output-contracts/explore.v1.json +52 -0
- package/.pi/output-contracts/factory.v1.json +48 -0
- package/.pi/output-contracts/guidance-steward.v1.json +18 -0
- package/.pi/output-contracts/implement.v1.json +40 -0
- package/.pi/output-contracts/launch-authorization.v1.json +21 -0
- package/.pi/output-contracts/lead-plan.v1.json +22 -0
- package/.pi/output-contracts/mission-readiness.v1.json +20 -0
- package/.pi/output-contracts/oracle-merge.v1.json +44 -0
- package/.pi/output-contracts/oracle-request.v1.json +20 -0
- package/.pi/output-contracts/oracle.v1.json +44 -0
- package/.pi/output-contracts/orchestration-profile.v1.json +22 -0
- package/.pi/output-contracts/plan.v1.json +48 -0
- package/.pi/output-contracts/prompt-pack.v1.json +20 -0
- package/.pi/output-contracts/qa.v1.json +40 -0
- package/.pi/output-contracts/research.v1.json +36 -0
- package/.pi/output-contracts/spec.v1.json +22 -0
- package/.pi/output-contracts/synthesis.v1.json +44 -0
- package/.pi/output-contracts/temp-agent-card.v1.json +23 -0
- package/.pi/output-contracts/todo-child-result.v1.json +20 -0
- package/.pi/output-contracts/todo-child-result.v2.json +22 -0
- package/.pi/output-contracts/todo-claim-validation.v1.json +22 -0
- package/.pi/output-contracts/todo-split-request.v1.json +20 -0
- package/.pi/prompts/adaptive-workflow.md +63 -0
- package/.pi/prompts/autonomous-runtime.md +15 -0
- package/.pi/prompts/benchmark-contender.md +15 -0
- package/.pi/prompts/benchmark-judge.md +19 -0
- package/.pi/prompts/clarify-spec.md +20 -0
- package/.pi/prompts/compute-plan.md +36 -0
- package/.pi/prompts/compute-preview.md +42 -0
- package/.pi/prompts/contract.md +29 -0
- package/.pi/prompts/explore.md +13 -0
- package/.pi/prompts/factory-run.md +36 -0
- package/.pi/prompts/factory.md +20 -0
- package/.pi/prompts/implement.md +27 -0
- package/.pi/prompts/model-catalog.md +68 -0
- package/.pi/prompts/model-economy.md +64 -0
- package/.pi/prompts/oracle-merge.md +18 -0
- package/.pi/prompts/oracle.md +13 -0
- package/.pi/prompts/orchestrator.md +48 -0
- package/.pi/prompts/parallel-review.md +21 -0
- package/.pi/prompts/plan.md +21 -0
- package/.pi/prompts/project-dna.md +90 -0
- package/.pi/prompts/refactor-oracle.md +23 -0
- package/.pi/prompts/refactor-slice.md +24 -0
- package/.pi/prompts/research.md +20 -0
- package/.pi/prompts/spec.md +19 -0
- package/.pi/prompts/synthesis.md +18 -0
- package/.pi/rules/always.md +38 -0
- package/.pi/rules/docs.md +32 -0
- package/.pi/rules/factory.md +44 -0
- package/.pi/rules/oracle.md +34 -0
- package/.pi/rules/orchestration.md +44 -0
- package/.pi/rules/project.md +34 -0
- package/.pi/rules/prompts.md +43 -0
- package/.pi/rules/runtime.md +43 -0
- package/.pi/rules/sandbox.md +43 -0
- package/.pi/settings.json +28 -0
- package/.pi/skills/zob-agentic-access/SKILL.md +20 -0
- package/.pi/skills/zob-autonomous-runtime/SKILL.md +41 -0
- package/.pi/skills/zob-commit/SKILL.md +79 -0
- package/.pi/skills/zob-compaction-policy/SKILL.md +92 -0
- package/.pi/skills/zob-compute-profile/SKILL.md +108 -0
- package/.pi/skills/zob-coms-safety/SKILL.md +54 -0
- package/.pi/skills/zob-coms-v2-live/SKILL.md +47 -0
- package/.pi/skills/zob-delegation-routing/SKILL.md +82 -0
- package/.pi/skills/zob-factory/SKILL.md +28 -0
- package/.pi/skills/zob-goal-todo-tree/SKILL.md +279 -0
- package/.pi/skills/zob-harness/SKILL.md +68 -0
- package/.pi/skills/zob-mission-control-coms/SKILL.md +39 -0
- package/.pi/skills/zob-oracle/SKILL.md +21 -0
- package/.pi/skills/zob-owner-pool-drill-writer/SKILL.md +244 -0
- package/.pi/skills/zob-owner-pool-launcher/SKILL.md +261 -0
- package/.pi/skills/zob-project-dna/SKILL.md +275 -0
- package/.pi/skills/zob-sandbox/SKILL.md +29 -0
- package/.pi/skills/zob-spec/SKILL.md +25 -0
- package/.pi/skills/zob-split-refactor/SKILL.md +39 -0
- package/.pi/skills/zob-tool-router/SKILL.md +104 -0
- package/.pi/teams/zob-core.json +122 -0
- package/AGENTS.md +89 -0
- package/CONTRIBUTING.md +56 -0
- package/LICENSE +21 -0
- package/README.md +360 -0
- package/SECURITY.md +35 -0
- package/SOURCE_INDEX.md +46 -0
- package/package.json +135 -0
- package/scripts/README.md +57 -0
- package/scripts/autonomy/mission-readiness-secret-smoke.mjs +90 -0
- package/scripts/compute-profile/plan-workflow.mjs +85 -0
- package/scripts/compute-profile/preview.mjs +242 -0
- package/scripts/compute-profile/regression-smoke.mjs +38 -0
- package/scripts/compute-profile/summarize.mjs +72 -0
- package/scripts/compute-profile/validate-policy.mjs +50 -0
- package/scripts/compute-profile/validate-preview.mjs +95 -0
- package/scripts/compute-profile/validate-workflow.mjs +58 -0
- package/scripts/git-ops/commit-policy-smoke.mjs +221 -0
- package/scripts/goal-todo/child-goal-ref-smoke.mjs +252 -0
- package/scripts/harness-switch/static-smoke.mjs +43 -0
- package/scripts/model-catalog/validate-economy.mjs +223 -0
- package/scripts/model-catalog/validate.mjs +199 -0
- package/scripts/package-surface/validate-script-refs.mjs +190 -0
- package/scripts/path-policy/validate-smoke.mjs +103 -0
- package/scripts/project-dna/bench-smoke.mjs +217 -0
- package/scripts/project-dna/build-capsules.mjs +207 -0
- package/scripts/project-dna/build-sample-spec.mjs +140 -0
- package/scripts/project-dna/emit-golden-cases.mjs +75 -0
- package/scripts/project-dna/emit-ontology.mjs +75 -0
- package/scripts/project-dna/generate-sample.mjs +302 -0
- package/scripts/project-dna/oracle-review-smoke.mjs +157 -0
- package/scripts/project-dna/plan-workflow.mjs +289 -0
- package/scripts/project-dna/query-context.mjs +276 -0
- package/scripts/project-dna/query-steward.mjs +149 -0
- package/scripts/project-dna/scan.mjs +553 -0
- package/scripts/project-dna/validate-5of5.mjs +159 -0
- package/scripts/project-dna/validate-golden-cases.mjs +78 -0
- package/scripts/project-dna/validate-ontology.mjs +97 -0
- package/scripts/project-dna/validate-sample-project.mjs +105 -0
- package/scripts/project-dna/validate-scaffold.mjs +383 -0
- package/scripts/project-dna/validate-scan-artifacts.mjs +187 -0
- package/scripts/project-dna/validate-workflow.mjs +166 -0
- package/scripts/start-pi.sh +4 -0
- package/scripts/worker-pool/static-smoke.mjs +54 -0
- package/scripts/zpeer-local-e2e-smoke.mjs +395 -0
- package/scripts/zpeer-static-smoke.mjs +129 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
import { evaluateBudgetPreflightDryRun } from "./chronicle.js";
|
|
5
|
+
import type { BudgetPreflightDryRunCaps, FactoryRunBudgetInput } from "./types.js";
|
|
6
|
+
import { sha256 } from "./utils/hashing.js";
|
|
7
|
+
import { parseJsonFile } from "./utils/json.js";
|
|
8
|
+
import { safeFileStem } from "./utils/paths.js";
|
|
9
|
+
import { isRecord } from "./utils/records.js";
|
|
10
|
+
|
|
11
|
+
const FORBIDDEN_BUDGET_BODY_KEYS = new Set(["task", "prompt", "output", "body", "content"]);
|
|
12
|
+
const REQUIRED_CAP_KEYS: Array<keyof BudgetPreflightDryRunCaps> = ["maxCostUsd", "maxRuns", "maxDurationMs", "maxParallelChildren"];
|
|
13
|
+
const REQUIRED_PROFILES = ["smoke", "pilot", "batch"];
|
|
14
|
+
|
|
15
|
+
export interface BudgetReadinessAuditInput {
|
|
16
|
+
run_id?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface StrictBudgetDispatchGateInput {
|
|
20
|
+
runId?: string;
|
|
21
|
+
mode?: string;
|
|
22
|
+
execution?: string;
|
|
23
|
+
taskCount?: number;
|
|
24
|
+
selectedItems?: number;
|
|
25
|
+
budget?: FactoryRunBudgetInput;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function hasForbiddenBodyKeys(value: unknown): boolean {
|
|
29
|
+
if (!value || typeof value !== "object") return false;
|
|
30
|
+
if (Array.isArray(value)) return value.some(hasForbiddenBodyKeys);
|
|
31
|
+
return Object.entries(value as Record<string, unknown>).some(([key, child]) => FORBIDDEN_BUDGET_BODY_KEYS.has(key) || hasForbiddenBodyKeys(child));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function finiteNonnegative(value: unknown): value is number {
|
|
35
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function capsFromRecord(record: unknown): BudgetPreflightDryRunCaps | undefined {
|
|
39
|
+
if (!isRecord(record)) return undefined;
|
|
40
|
+
const caps: BudgetPreflightDryRunCaps = {};
|
|
41
|
+
for (const key of REQUIRED_CAP_KEYS) {
|
|
42
|
+
if (!finiteNonnegative(record[key])) return undefined;
|
|
43
|
+
caps[key] = record[key] as number;
|
|
44
|
+
}
|
|
45
|
+
return caps;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function readinessCheck(name: string, passed: boolean, detail: Record<string, unknown> = {}): Record<string, unknown> {
|
|
49
|
+
return { name, passed, detail };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function nonnegativeOrUndefined(value: unknown): number | undefined {
|
|
53
|
+
return finiteNonnegative(value) ? value : undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function evaluateStrictBudgetDispatchGate(input: StrictBudgetDispatchGateInput = {}): Record<string, unknown> {
|
|
57
|
+
const budget = isRecord(input.budget) ? input.budget as FactoryRunBudgetInput : undefined;
|
|
58
|
+
const caps: BudgetPreflightDryRunCaps = {
|
|
59
|
+
...(nonnegativeOrUndefined(budget?.maxCostUsd) !== undefined ? { maxCostUsd: nonnegativeOrUndefined(budget?.maxCostUsd) } : {}),
|
|
60
|
+
...(nonnegativeOrUndefined(budget?.maxRuns) !== undefined ? { maxRuns: nonnegativeOrUndefined(budget?.maxRuns) } : {}),
|
|
61
|
+
...(nonnegativeOrUndefined(budget?.maxDurationMs) !== undefined ? { maxDurationMs: nonnegativeOrUndefined(budget?.maxDurationMs) } : {}),
|
|
62
|
+
...(nonnegativeOrUndefined(budget?.maxParallelChildren) !== undefined ? { maxParallelChildren: nonnegativeOrUndefined(budget?.maxParallelChildren) } : {}),
|
|
63
|
+
};
|
|
64
|
+
const observed = {
|
|
65
|
+
costUsd: nonnegativeOrUndefined(budget?.estimatedCostUsd) ?? 0,
|
|
66
|
+
runs: nonnegativeOrUndefined(budget?.estimatedRuns) ?? Math.max(0, Math.floor(input.taskCount ?? 0)),
|
|
67
|
+
durationMs: nonnegativeOrUndefined(budget?.estimatedDurationMs) ?? 0,
|
|
68
|
+
parallelChildren: nonnegativeOrUndefined(budget?.estimatedParallelChildren) ?? 1,
|
|
69
|
+
};
|
|
70
|
+
const strictEnabled = budget?.strictEnabled === true;
|
|
71
|
+
const strictRequested = budget?.strictRequested === true || strictEnabled;
|
|
72
|
+
const preflight = evaluateBudgetPreflightDryRun({
|
|
73
|
+
costUsd: observed.costUsd,
|
|
74
|
+
runs: observed.runs,
|
|
75
|
+
durationMs: observed.durationMs,
|
|
76
|
+
parallelChildren: observed.parallelChildren,
|
|
77
|
+
caps,
|
|
78
|
+
strictRequested,
|
|
79
|
+
});
|
|
80
|
+
const failures = Array.isArray(preflight.failures) ? preflight.failures.filter((failure): failure is string => typeof failure === "string") : [];
|
|
81
|
+
const wouldBlockDispatch = strictEnabled && failures.length > 0;
|
|
82
|
+
return {
|
|
83
|
+
schema: "zob.strict-budget-dispatch-gate.v1",
|
|
84
|
+
runId: input.runId,
|
|
85
|
+
mode: input.mode,
|
|
86
|
+
execution: input.execution,
|
|
87
|
+
strictRequested,
|
|
88
|
+
strictEnabled,
|
|
89
|
+
budgetEnforced: strictEnabled,
|
|
90
|
+
caps,
|
|
91
|
+
observed,
|
|
92
|
+
checks: preflight.checks,
|
|
93
|
+
passed: failures.length === 0,
|
|
94
|
+
failures,
|
|
95
|
+
wouldExceed: failures.length > 0,
|
|
96
|
+
wouldBlockDispatch,
|
|
97
|
+
dispatchDecision: wouldBlockDispatch ? "block" : strictEnabled ? "allow_strict" : "allow_advisory",
|
|
98
|
+
childDispatchAllowed: strictEnabled && !wouldBlockDispatch,
|
|
99
|
+
stopCondition: wouldBlockDispatch ? "blocked" : "none",
|
|
100
|
+
defaultDispatchDecision: strictEnabled ? "gate_decides" : "allow",
|
|
101
|
+
advisoryFallback: !strictEnabled,
|
|
102
|
+
gateEvaluationOnly: true,
|
|
103
|
+
noExecution: true,
|
|
104
|
+
bodyStored: false,
|
|
105
|
+
promptBodiesStored: false,
|
|
106
|
+
outputBodiesStored: false,
|
|
107
|
+
generatedAt: new Date().toISOString(),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function budgetSafetyPassed(result: Record<string, unknown>): boolean {
|
|
112
|
+
return result.dryRun === true
|
|
113
|
+
&& result.mode === "advisory"
|
|
114
|
+
&& result.advisory === true
|
|
115
|
+
&& result.strictEnabled === false
|
|
116
|
+
&& result.budgetEnforced === false
|
|
117
|
+
&& result.wouldBlockDispatch === false
|
|
118
|
+
&& result.defaultDispatchDecision === "allow"
|
|
119
|
+
&& result.modelRouterUsed === false
|
|
120
|
+
&& result.daemonStarted === false
|
|
121
|
+
&& result.childDispatchAllowed === false
|
|
122
|
+
&& result.noExecution === true;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function validateBudgetPolicyConfig(repoRoot: string): Record<string, unknown> {
|
|
126
|
+
const configPath = join(repoRoot, ".pi", "budget-policy.json");
|
|
127
|
+
const errors: string[] = [];
|
|
128
|
+
let parsed: Record<string, unknown> | undefined;
|
|
129
|
+
let configHash: string | undefined;
|
|
130
|
+
if (!existsSync(configPath)) {
|
|
131
|
+
errors.push(".pi/budget-policy.json is missing");
|
|
132
|
+
} else {
|
|
133
|
+
try {
|
|
134
|
+
const raw = readFileSync(configPath, "utf8");
|
|
135
|
+
configHash = sha256(raw);
|
|
136
|
+
const value = parseJsonFile(configPath);
|
|
137
|
+
if (!isRecord(value)) errors.push("budget policy config must be a JSON object");
|
|
138
|
+
else parsed = value;
|
|
139
|
+
} catch (error) {
|
|
140
|
+
errors.push(`budget policy config could not be parsed: ${error instanceof Error ? error.message : String(error)}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const defaultCaps = capsFromRecord(parsed?.defaultCaps);
|
|
145
|
+
const profiles = isRecord(parsed?.profiles) ? parsed.profiles : undefined;
|
|
146
|
+
const validProfiles: Record<string, BudgetPreflightDryRunCaps> = {};
|
|
147
|
+
|
|
148
|
+
if (parsed) {
|
|
149
|
+
if (parsed.schema !== "zob.budget-policy.v1") errors.push("budget policy schema must be zob.budget-policy.v1");
|
|
150
|
+
if (parsed.advisoryOnly !== true) errors.push("budget policy must keep advisoryOnly=true");
|
|
151
|
+
if (parsed.strictBudgetDispatchGateAvailable !== true) errors.push("budget policy must declare strictBudgetDispatchGateAvailable=true");
|
|
152
|
+
if (parsed.strictBudgetRequiresExplicitInput !== true) errors.push("budget policy must declare strictBudgetRequiresExplicitInput=true");
|
|
153
|
+
for (const flag of ["strictBudgetDefaultEnabled", "strictBudgetEnabled", "budgetEnforced", "wouldBlockDispatch", "modelRouterUsed", "childDispatchAllowed", "daemonStarted", "networkAccessed", "bodyStored", "promptBodiesStored", "outputBodiesStored"]) {
|
|
154
|
+
if (parsed[flag] !== false) errors.push(`budget policy must keep ${flag}=false`);
|
|
155
|
+
}
|
|
156
|
+
if (parsed.noExecution !== true) errors.push("budget policy must keep noExecution=true");
|
|
157
|
+
if (parsed.defaultDispatchDecision !== "allow") errors.push("budget policy defaultDispatchDecision must remain allow");
|
|
158
|
+
if (!defaultCaps) errors.push("budget policy requires complete nonnegative defaultCaps");
|
|
159
|
+
if (!profiles) {
|
|
160
|
+
errors.push("budget policy requires profiles object");
|
|
161
|
+
} else {
|
|
162
|
+
for (const profileName of REQUIRED_PROFILES) {
|
|
163
|
+
const caps = capsFromRecord(profiles[profileName]);
|
|
164
|
+
if (!caps) errors.push(`budget policy requires complete nonnegative profiles.${profileName}`);
|
|
165
|
+
else validProfiles[profileName] = caps;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (!Array.isArray(parsed.futureStrictBudgetPrerequisites) || !parsed.futureStrictBudgetPrerequisites.every((item) => typeof item === "string") || parsed.futureStrictBudgetPrerequisites.length === 0) {
|
|
169
|
+
errors.push("budget policy requires futureStrictBudgetPrerequisites string array");
|
|
170
|
+
}
|
|
171
|
+
if (hasForbiddenBodyKeys(parsed)) errors.push("budget policy must not store raw task/prompt/output/body/content fields");
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return {
|
|
175
|
+
schema: "zob.budget-policy-validation.v1",
|
|
176
|
+
path: ".pi/budget-policy.json",
|
|
177
|
+
present: existsSync(configPath),
|
|
178
|
+
valid: errors.length === 0,
|
|
179
|
+
errors,
|
|
180
|
+
configHash,
|
|
181
|
+
defaultCaps,
|
|
182
|
+
profiles: Object.keys(validProfiles).sort(),
|
|
183
|
+
advisoryOnly: parsed?.advisoryOnly === true,
|
|
184
|
+
strictBudgetDispatchGateAvailable: parsed?.strictBudgetDispatchGateAvailable === true,
|
|
185
|
+
strictBudgetRequiresExplicitInput: parsed?.strictBudgetRequiresExplicitInput === true,
|
|
186
|
+
strictBudgetDefaultEnabled: parsed?.strictBudgetDefaultEnabled === true,
|
|
187
|
+
strictBudgetEnabled: parsed?.strictBudgetEnabled === true,
|
|
188
|
+
budgetEnforced: parsed?.budgetEnforced === true,
|
|
189
|
+
wouldBlockDispatch: parsed?.wouldBlockDispatch === true,
|
|
190
|
+
modelRouterUsed: parsed?.modelRouterUsed === true,
|
|
191
|
+
childDispatchAllowed: parsed?.childDispatchAllowed === true,
|
|
192
|
+
daemonStarted: parsed?.daemonStarted === true,
|
|
193
|
+
networkAccessed: parsed?.networkAccessed === true,
|
|
194
|
+
noExecution: parsed?.noExecution === true,
|
|
195
|
+
bodyStored: false,
|
|
196
|
+
promptBodiesStored: false,
|
|
197
|
+
outputBodiesStored: false,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function buildBudgetReadinessAudit(repoRoot: string, input: BudgetReadinessAuditInput = {}): Record<string, unknown> {
|
|
202
|
+
const configValidation = validateBudgetPolicyConfig(repoRoot);
|
|
203
|
+
const defaultCaps = isRecord(configValidation.defaultCaps) ? configValidation.defaultCaps as BudgetPreflightDryRunCaps : { maxCostUsd: 1, maxRuns: 1, maxDurationMs: 1000, maxParallelChildren: 1 };
|
|
204
|
+
const scenarios = [
|
|
205
|
+
{ name: "within_default_caps", input: { costUsd: 0.5, runs: 1, durationMs: 500, parallelChildren: 1, caps: defaultCaps } },
|
|
206
|
+
{ name: "cost_exceeds_default_caps", input: { costUsd: Number(defaultCaps.maxCostUsd ?? 1) + 1, runs: 1, durationMs: 500, parallelChildren: 1, caps: defaultCaps } },
|
|
207
|
+
{ name: "runs_exceed_default_caps", input: { costUsd: 0.5, runs: Number(defaultCaps.maxRuns ?? 1) + 1, durationMs: 500, parallelChildren: 1, caps: defaultCaps } },
|
|
208
|
+
{ name: "duration_exceeds_default_caps", input: { costUsd: 0.5, runs: 1, durationMs: Number(defaultCaps.maxDurationMs ?? 1000) + 1, parallelChildren: 1, caps: defaultCaps } },
|
|
209
|
+
{ name: "parallel_children_exceed_default_caps", input: { costUsd: 0.5, runs: 1, durationMs: 500, parallelChildren: Number(defaultCaps.maxParallelChildren ?? 1) + 1, caps: defaultCaps } },
|
|
210
|
+
{ name: "strict_budget_request_inert", input: { costUsd: Number(defaultCaps.maxCostUsd ?? 1) + 1, runs: 1, durationMs: 500, parallelChildren: 1, caps: defaultCaps, strictRequested: true } },
|
|
211
|
+
].map((scenario) => {
|
|
212
|
+
const result = evaluateBudgetPreflightDryRun(scenario.input);
|
|
213
|
+
return {
|
|
214
|
+
name: scenario.name,
|
|
215
|
+
inputHash: sha256(JSON.stringify(scenario.input)),
|
|
216
|
+
passed: result.passed,
|
|
217
|
+
wouldExceed: result.wouldExceed,
|
|
218
|
+
strictRequested: result.strictRequested,
|
|
219
|
+
strictEnabled: result.strictEnabled,
|
|
220
|
+
budgetEnforced: result.budgetEnforced,
|
|
221
|
+
wouldBlockDispatch: result.wouldBlockDispatch,
|
|
222
|
+
childDispatchAllowed: result.childDispatchAllowed,
|
|
223
|
+
noExecution: result.noExecution,
|
|
224
|
+
failures: result.failures,
|
|
225
|
+
safetyPassed: budgetSafetyPassed(result),
|
|
226
|
+
};
|
|
227
|
+
});
|
|
228
|
+
const strictScenario = scenarios.find((scenario) => scenario.name === "strict_budget_request_inert");
|
|
229
|
+
const strictGateScenarios = [
|
|
230
|
+
{ name: "strict_gate_allows_within_caps", input: { runId: "strict-gate-allow", mode: "smoke", execution: "agentic", taskCount: 1, budget: { strictEnabled: true, maxRuns: 2, estimatedRuns: 1, maxParallelChildren: 1, estimatedParallelChildren: 1 } } },
|
|
231
|
+
{ name: "strict_gate_blocks_exceedance", input: { runId: "strict-gate-block", mode: "smoke", execution: "agentic", taskCount: 3, budget: { strictEnabled: true, maxRuns: 2, estimatedRuns: 3, maxParallelChildren: 1, estimatedParallelChildren: 1 } } },
|
|
232
|
+
{ name: "strict_gate_default_disabled_advisory", input: { runId: "strict-gate-default", mode: "smoke", execution: "agentic", taskCount: 3, budget: { strictRequested: true, maxRuns: 2, estimatedRuns: 3 } } },
|
|
233
|
+
].map((scenario) => {
|
|
234
|
+
const result = evaluateStrictBudgetDispatchGate(scenario.input);
|
|
235
|
+
return {
|
|
236
|
+
name: scenario.name,
|
|
237
|
+
inputHash: sha256(JSON.stringify(scenario.input)),
|
|
238
|
+
strictRequested: result.strictRequested,
|
|
239
|
+
strictEnabled: result.strictEnabled,
|
|
240
|
+
budgetEnforced: result.budgetEnforced,
|
|
241
|
+
wouldExceed: result.wouldExceed,
|
|
242
|
+
wouldBlockDispatch: result.wouldBlockDispatch,
|
|
243
|
+
childDispatchAllowed: result.childDispatchAllowed,
|
|
244
|
+
dispatchDecision: result.dispatchDecision,
|
|
245
|
+
stopCondition: result.stopCondition,
|
|
246
|
+
noExecution: result.noExecution,
|
|
247
|
+
failures: result.failures,
|
|
248
|
+
};
|
|
249
|
+
});
|
|
250
|
+
const strictAllow = strictGateScenarios.find((scenario) => scenario.name === "strict_gate_allows_within_caps");
|
|
251
|
+
const strictBlock = strictGateScenarios.find((scenario) => scenario.name === "strict_gate_blocks_exceedance");
|
|
252
|
+
const strictDefault = strictGateScenarios.find((scenario) => scenario.name === "strict_gate_default_disabled_advisory");
|
|
253
|
+
const checks = [
|
|
254
|
+
readinessCheck("budget_policy_config_valid", configValidation.present === true && configValidation.valid === true, { configHash: configValidation.configHash, errors: configValidation.errors }),
|
|
255
|
+
readinessCheck("budget_dry_run_scenarios_safe", scenarios.every((scenario) => scenario.safetyPassed === true), { scenarioCount: scenarios.length }),
|
|
256
|
+
readinessCheck("budget_exceedances_detected", scenarios.filter((scenario) => String(scenario.name).includes("exceed")).every((scenario) => scenario.wouldExceed === true), { exceedanceScenarios: scenarios.filter((scenario) => String(scenario.name).includes("exceed")).map((scenario) => scenario.name) }),
|
|
257
|
+
readinessCheck("strict_budget_request_inert_without_enable", strictScenario?.wouldExceed === true && strictScenario.strictRequested === true && strictScenario.strictEnabled === false && strictScenario.budgetEnforced === false && strictScenario.wouldBlockDispatch === false, { scenario: strictScenario?.name }),
|
|
258
|
+
readinessCheck("strict_budget_dispatch_gate_blocks_when_enabled", strictAllow?.strictEnabled === true && strictAllow.budgetEnforced === true && strictAllow.wouldBlockDispatch === false && strictAllow.childDispatchAllowed === true && strictBlock?.strictEnabled === true && strictBlock.budgetEnforced === true && strictBlock.wouldBlockDispatch === true && strictBlock.childDispatchAllowed === false && strictBlock.stopCondition === "blocked", { allow: strictAllow?.dispatchDecision, block: strictBlock?.dispatchDecision }),
|
|
259
|
+
readinessCheck("strict_budget_default_disabled", strictDefault?.strictRequested === true && strictDefault.strictEnabled === false && strictDefault.budgetEnforced === false && strictDefault.wouldBlockDispatch === false && strictDefault.dispatchDecision === "allow_advisory", { scenario: strictDefault?.name }),
|
|
260
|
+
readinessCheck("budget_enforcement_integration_implemented", true, { reason: "strict budget dispatch gate is available and can block before live child dispatch when explicitly enabled" }),
|
|
261
|
+
readinessCheck("strict_budget_global_default_enabled", false, { reason: "global/default strict budget enforcement remains disabled until operator approval and broader autonomy gates are proven" }),
|
|
262
|
+
];
|
|
263
|
+
const failedChecks = checks.filter((check) => check.passed !== true).map((check) => check.name);
|
|
264
|
+
const auditPassed = checks.filter((check) => check.name !== "strict_budget_global_default_enabled").every((check) => check.passed === true);
|
|
265
|
+
const report = {
|
|
266
|
+
schema: "zob.budget-readiness-audit.v1",
|
|
267
|
+
runId: input.run_id,
|
|
268
|
+
auditPassed,
|
|
269
|
+
readiness: failedChecks.length === 0 ? "strict_budget_enabled_globally" : "strict_gate_available_default_blocked",
|
|
270
|
+
strictBudgetBlocked: failedChecks.length > 0,
|
|
271
|
+
strictBudgetNoShip: true,
|
|
272
|
+
strictBudgetBlockers: [
|
|
273
|
+
"global/default strict budget enforcement remains disabled",
|
|
274
|
+
"strict dispatch blocking requires explicit per-run budget.strictEnabled=true",
|
|
275
|
+
"oracle review and explicit approval are required before enabling strict budgets by default",
|
|
276
|
+
],
|
|
277
|
+
checks,
|
|
278
|
+
failedChecks,
|
|
279
|
+
scenarios,
|
|
280
|
+
strictGateScenarios,
|
|
281
|
+
config: configValidation,
|
|
282
|
+
strictBudgetDispatchGateAvailable: true,
|
|
283
|
+
strictBudgetRequiresExplicitInput: true,
|
|
284
|
+
budgetEnforced: false,
|
|
285
|
+
strictEnabled: false,
|
|
286
|
+
wouldBlockDispatch: false,
|
|
287
|
+
defaultDispatchDecision: "allow",
|
|
288
|
+
modelRouterUsed: false,
|
|
289
|
+
childDispatchAllowed: false,
|
|
290
|
+
daemonStarted: false,
|
|
291
|
+
networkAccessed: false,
|
|
292
|
+
noExecution: true,
|
|
293
|
+
bodyStored: false,
|
|
294
|
+
promptBodiesStored: false,
|
|
295
|
+
outputBodiesStored: false,
|
|
296
|
+
generatedAt: new Date().toISOString(),
|
|
297
|
+
};
|
|
298
|
+
if (hasForbiddenBodyKeys(report)) throw new Error("Budget readiness audit would store forbidden body keys");
|
|
299
|
+
return report;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export function writeBudgetReadinessAuditReport(repoRoot: string, runId = "budget-readiness", input: BudgetReadinessAuditInput = {}): string {
|
|
303
|
+
const dir = join(repoRoot, ".pi", "logs", "budget");
|
|
304
|
+
mkdirSync(dir, { recursive: true });
|
|
305
|
+
const outputPath = join(dir, `${safeFileStem(runId)}.json`);
|
|
306
|
+
writeFileSync(outputPath, JSON.stringify(buildBudgetReadinessAudit(repoRoot, { ...input, run_id: runId }), null, 2), "utf8");
|
|
307
|
+
return outputPath;
|
|
308
|
+
}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { basename, join, relative } from "node:path";
|
|
3
|
+
|
|
4
|
+
import { discoverAgents } from "./agents.js";
|
|
5
|
+
import { getOutputContractDefinitions } from "./output-contracts.js";
|
|
6
|
+
import { loadChainDefinition, listChainDefinitions } from "./topology/chains.js";
|
|
7
|
+
import { sha256 } from "./utils/hashing.js";
|
|
8
|
+
import { parseJsonFile } from "./utils/json.js";
|
|
9
|
+
import { safeFileStem } from "./utils/paths.js";
|
|
10
|
+
import { isRecord } from "./utils/records.js";
|
|
11
|
+
import { readableZobResourcePath, readableZobResourcePaths } from "./utils/resources.js";
|
|
12
|
+
|
|
13
|
+
export interface ReuseScoutInput {
|
|
14
|
+
query: string;
|
|
15
|
+
run_id?: string;
|
|
16
|
+
limit?: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type CapabilityKind = "agent" | "factory" | "chain" | "output_contract";
|
|
20
|
+
|
|
21
|
+
interface CapabilityCandidate {
|
|
22
|
+
kind: CapabilityKind;
|
|
23
|
+
id: string;
|
|
24
|
+
sourcePath?: string;
|
|
25
|
+
summary: string;
|
|
26
|
+
searchText: string;
|
|
27
|
+
metadata: Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const FORBIDDEN_BODY_KEYS = new Set(["task", "prompt", "output", "body", "content"]);
|
|
31
|
+
|
|
32
|
+
function hasForbiddenBodyKeys(value: unknown): boolean {
|
|
33
|
+
if (!value || typeof value !== "object") return false;
|
|
34
|
+
if (Array.isArray(value)) return value.some(hasForbiddenBodyKeys);
|
|
35
|
+
return Object.entries(value as Record<string, unknown>).some(([key, child]) => FORBIDDEN_BODY_KEYS.has(key) || hasForbiddenBodyKeys(child));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function keywords(value: string): string[] {
|
|
39
|
+
const stop = new Set(["the", "and", "for", "with", "from", "that", "this", "into", "only", "zob", "agent", "factory"]);
|
|
40
|
+
return [...new Set(value.toLowerCase().split(/[^a-z0-9_]+/).filter((item) => item.length >= 3 && !stop.has(item)))].sort();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function repoRelative(repoRoot: string, path: string): string {
|
|
44
|
+
return relative(repoRoot, path).replace(/\\/g, "/");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function readJsonObject(path: string): Record<string, unknown> | undefined {
|
|
48
|
+
if (!existsSync(path)) return undefined;
|
|
49
|
+
try {
|
|
50
|
+
const parsed = parseJsonFile(path);
|
|
51
|
+
return isRecord(parsed) ? parsed : undefined;
|
|
52
|
+
} catch {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function listFactoryNames(repoRoot: string): string[] {
|
|
58
|
+
const names = new Set<string>();
|
|
59
|
+
for (const dir of readableZobResourcePaths(repoRoot, "factories")) {
|
|
60
|
+
for (const name of readdirSync(dir)) {
|
|
61
|
+
if (existsSync(join(dir, name, "factory.json"))) names.add(name);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return [...names].sort();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function listOutputContractFiles(repoRoot: string): string[] {
|
|
68
|
+
const fileNames = new Set<string>();
|
|
69
|
+
for (const dir of readableZobResourcePaths(repoRoot, "output-contracts")) {
|
|
70
|
+
for (const name of readdirSync(dir)) {
|
|
71
|
+
if (name.endsWith(".json")) fileNames.add(name);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return [...fileNames].sort();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function capabilityCandidates(repoRoot: string): CapabilityCandidate[] {
|
|
78
|
+
const agents = discoverAgents(repoRoot, "project").map((agent) => ({
|
|
79
|
+
kind: "agent" as const,
|
|
80
|
+
id: agent.name,
|
|
81
|
+
sourcePath: repoRelative(repoRoot, agent.filePath),
|
|
82
|
+
summary: agent.description,
|
|
83
|
+
searchText: [agent.name, agent.description, agent.tools?.join(" ") ?? ""].join(" "),
|
|
84
|
+
metadata: {
|
|
85
|
+
tools: agent.tools ?? [],
|
|
86
|
+
source: agent.source,
|
|
87
|
+
modelClass: agent.model,
|
|
88
|
+
promptHash: sha256(agent.prompt),
|
|
89
|
+
},
|
|
90
|
+
}));
|
|
91
|
+
|
|
92
|
+
const factories = listFactoryNames(repoRoot).map((name) => {
|
|
93
|
+
const factoryPath = readableZobResourcePath(repoRoot, "factories", name, "factory.json");
|
|
94
|
+
const definition = readJsonObject(factoryPath) ?? {};
|
|
95
|
+
const stages = Array.isArray(definition.stages) ? definition.stages.filter(isRecord) : [];
|
|
96
|
+
const stageAgents = [...new Set(stages.map((stage) => String(stage.agent ?? "")).filter(Boolean))].sort();
|
|
97
|
+
const stageContracts = [...new Set(stages.map((stage) => String(stage.outputContract ?? "")).filter(Boolean))].sort();
|
|
98
|
+
const stageTypes = [...new Set(stages.map((stage) => String(stage.type ?? "")).filter(Boolean))].sort();
|
|
99
|
+
const manifests = ["smoke-manifest.json", "pilot-manifest.json", "batch-manifest.json"].filter((fileName) => existsSync(readableZobResourcePath(repoRoot, "factories", name, fileName)));
|
|
100
|
+
const description = typeof definition.description === "string" ? definition.description : "";
|
|
101
|
+
return {
|
|
102
|
+
kind: "factory" as const,
|
|
103
|
+
id: name,
|
|
104
|
+
sourcePath: repoRelative(repoRoot, factoryPath),
|
|
105
|
+
summary: description,
|
|
106
|
+
searchText: [name, description, stageAgents.join(" "), stageContracts.join(" "), stageTypes.join(" ")].join(" "),
|
|
107
|
+
metadata: {
|
|
108
|
+
version: definition.version,
|
|
109
|
+
defaultMode: definition.defaultMode,
|
|
110
|
+
stageTypes,
|
|
111
|
+
stageAgents,
|
|
112
|
+
outputContracts: stageContracts,
|
|
113
|
+
manifests,
|
|
114
|
+
expectedArtifacts: Array.isArray(definition.expectedArtifacts) ? definition.expectedArtifacts : [],
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const chains = listChainDefinitions(repoRoot).map((name) => {
|
|
120
|
+
const loaded = loadChainDefinition(repoRoot, name);
|
|
121
|
+
const definition = loaded.definition;
|
|
122
|
+
const steps = definition?.steps ?? [];
|
|
123
|
+
const stepAgents = [...new Set(steps.map((step) => step.agent))].sort();
|
|
124
|
+
const stepContracts = [...new Set(steps.map((step) => step.outputContract))].sort();
|
|
125
|
+
return {
|
|
126
|
+
kind: "chain" as const,
|
|
127
|
+
id: name,
|
|
128
|
+
sourcePath: repoRelative(repoRoot, loaded.chainPath),
|
|
129
|
+
summary: definition?.description ?? "",
|
|
130
|
+
searchText: [name, definition?.description ?? "", stepAgents.join(" "), stepContracts.join(" ")].join(" "),
|
|
131
|
+
metadata: {
|
|
132
|
+
readOnly: definition?.readOnly ?? true,
|
|
133
|
+
defaultExecution: definition?.defaultExecution ?? "plan_only",
|
|
134
|
+
steps: steps.length,
|
|
135
|
+
stepAgents,
|
|
136
|
+
outputContracts: stepContracts,
|
|
137
|
+
definitionHash: definition ? sha256(JSON.stringify(definition)) : undefined,
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const contractDefinitions = new Map(getOutputContractDefinitions().map((definition) => [definition.id, definition.required]));
|
|
143
|
+
const outputContracts = listOutputContractFiles(repoRoot).map((fileName) => {
|
|
144
|
+
const contractPath = readableZobResourcePath(repoRoot, "output-contracts", fileName);
|
|
145
|
+
const parsed = readJsonObject(contractPath) ?? {};
|
|
146
|
+
const id = typeof parsed.id === "string" ? parsed.id : basename(fileName, ".json");
|
|
147
|
+
const description = typeof parsed.description === "string" ? parsed.description : "";
|
|
148
|
+
const required = contractDefinitions.get(id) ?? [];
|
|
149
|
+
return {
|
|
150
|
+
kind: "output_contract" as const,
|
|
151
|
+
id,
|
|
152
|
+
sourcePath: repoRelative(repoRoot, contractPath),
|
|
153
|
+
summary: description,
|
|
154
|
+
searchText: [id, description, required.join(" ")].join(" "),
|
|
155
|
+
metadata: {
|
|
156
|
+
required,
|
|
157
|
+
contractHash: sha256(readFileSync(contractPath, "utf8")),
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
return [...agents, ...factories, ...chains, ...outputContracts].sort((left, right) => `${left.kind}:${left.id}`.localeCompare(`${right.kind}:${right.id}`));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function buildCapabilityIndex(repoRoot: string): Record<string, unknown> {
|
|
166
|
+
const candidates = capabilityCandidates(repoRoot);
|
|
167
|
+
const byKind = candidates.reduce<Record<string, number>>((accumulator, candidate) => {
|
|
168
|
+
accumulator[candidate.kind] = (accumulator[candidate.kind] ?? 0) + 1;
|
|
169
|
+
return accumulator;
|
|
170
|
+
}, {});
|
|
171
|
+
const capabilities = candidates.map((candidate) => ({
|
|
172
|
+
kind: candidate.kind,
|
|
173
|
+
id: candidate.id,
|
|
174
|
+
sourcePath: candidate.sourcePath,
|
|
175
|
+
summary: candidate.summary,
|
|
176
|
+
keywords: keywords(candidate.searchText),
|
|
177
|
+
metadata: candidate.metadata,
|
|
178
|
+
}));
|
|
179
|
+
const index = {
|
|
180
|
+
schema: "zob.capability-index.v1",
|
|
181
|
+
counts: { total: capabilities.length, byKind },
|
|
182
|
+
capabilities,
|
|
183
|
+
noExecution: true,
|
|
184
|
+
childDispatchAllowed: false,
|
|
185
|
+
networkAccessed: false,
|
|
186
|
+
bodyStored: false,
|
|
187
|
+
promptBodiesStored: false,
|
|
188
|
+
outputBodiesStored: false,
|
|
189
|
+
generatedAt: new Date().toISOString(),
|
|
190
|
+
};
|
|
191
|
+
if (hasForbiddenBodyKeys(index)) throw new Error("Capability index would store forbidden body keys");
|
|
192
|
+
return index;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export function buildReuseScoutReport(repoRoot: string, input: ReuseScoutInput): Record<string, unknown> {
|
|
196
|
+
const queryKeywords = keywords(input.query);
|
|
197
|
+
const limit = Math.max(1, Math.min(20, Math.floor(input.limit ?? 10)));
|
|
198
|
+
const candidates = capabilityCandidates(repoRoot)
|
|
199
|
+
.map((candidate) => {
|
|
200
|
+
const candidateKeywords = keywords(candidate.searchText);
|
|
201
|
+
const overlap = candidateKeywords.filter((keyword) => queryKeywords.includes(keyword));
|
|
202
|
+
const kindBoost = candidate.kind === "factory" && queryKeywords.includes("factory") ? 2 : candidate.kind === "chain" && queryKeywords.includes("workflow") ? 2 : 0;
|
|
203
|
+
const score = overlap.length + kindBoost;
|
|
204
|
+
return {
|
|
205
|
+
kind: candidate.kind,
|
|
206
|
+
id: candidate.id,
|
|
207
|
+
sourcePath: candidate.sourcePath,
|
|
208
|
+
score,
|
|
209
|
+
reasonCodes: [...overlap.map((keyword) => `keyword:${keyword}`), ...(kindBoost > 0 ? [`kind_boost:${candidate.kind}`] : [])].sort(),
|
|
210
|
+
summaryHash: sha256(candidate.summary),
|
|
211
|
+
metadata: candidate.metadata,
|
|
212
|
+
};
|
|
213
|
+
})
|
|
214
|
+
.filter((candidate) => candidate.score > 0)
|
|
215
|
+
.sort((left, right) => right.score - left.score || `${left.kind}:${left.id}`.localeCompare(`${right.kind}:${right.id}`))
|
|
216
|
+
.slice(0, limit);
|
|
217
|
+
const report = {
|
|
218
|
+
schema: "zob.reuse-scout-report.v1",
|
|
219
|
+
queryHash: sha256(input.query),
|
|
220
|
+
queryKeywords,
|
|
221
|
+
candidates,
|
|
222
|
+
candidateCount: candidates.length,
|
|
223
|
+
noExecution: true,
|
|
224
|
+
childDispatchAllowed: false,
|
|
225
|
+
networkAccessed: false,
|
|
226
|
+
bodyStored: false,
|
|
227
|
+
promptBodiesStored: false,
|
|
228
|
+
outputBodiesStored: false,
|
|
229
|
+
generatedAt: new Date().toISOString(),
|
|
230
|
+
};
|
|
231
|
+
if (hasForbiddenBodyKeys(report)) throw new Error("Reuse scout report would store forbidden body keys");
|
|
232
|
+
return report;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export function writeCapabilityIndex(repoRoot: string, runId = "capability-index"): string {
|
|
236
|
+
const dir = join(repoRoot, ".pi", "logs", "capabilities");
|
|
237
|
+
mkdirSync(dir, { recursive: true });
|
|
238
|
+
const outputPath = join(dir, `${safeFileStem(runId)}.json`);
|
|
239
|
+
writeFileSync(outputPath, JSON.stringify(buildCapabilityIndex(repoRoot), null, 2), "utf8");
|
|
240
|
+
return outputPath;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export function writeReuseScoutReport(repoRoot: string, input: ReuseScoutInput): string {
|
|
244
|
+
const dir = join(repoRoot, ".pi", "logs", "capabilities");
|
|
245
|
+
mkdirSync(dir, { recursive: true });
|
|
246
|
+
const outputPath = join(dir, `${safeFileStem(input.run_id ?? "reuse-scout")}.json`);
|
|
247
|
+
writeFileSync(outputPath, JSON.stringify(buildReuseScoutReport(repoRoot, input), null, 2), "utf8");
|
|
248
|
+
return outputPath;
|
|
249
|
+
}
|