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,249 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { existsSync, mkdirSync } from "node:fs";
|
|
3
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
7
|
+
|
|
8
|
+
import { discoverAgents } from "./agents.js";
|
|
9
|
+
import { SUPERVISED_READONLY_CHILD_TOOLS } from "./constants.js";
|
|
10
|
+
import { validateExplicitModelOverride } from "./model-availability.js";
|
|
11
|
+
import { applyChildGates } from "./output-contracts.js";
|
|
12
|
+
import { buildChildEnv } from "./safety.js";
|
|
13
|
+
import { updateUsage, usageEmpty } from "./telemetry.js";
|
|
14
|
+
import type { ChildResult, ChildThinkingLevel, HarnessAgent, SupervisedReadonlyDispatchContract, SupervisedReadonlyDispatcher } from "./types.js";
|
|
15
|
+
import { sha256 } from "./utils/hashing.js";
|
|
16
|
+
import { safeFileStem } from "./utils/paths.js";
|
|
17
|
+
import { parseJsonLine, textFromMessage } from "./utils/records.js";
|
|
18
|
+
|
|
19
|
+
function getPiInvocation(args: string[]): { command: string; args: string[] } {
|
|
20
|
+
const currentScript = process.argv[1];
|
|
21
|
+
if (currentScript && existsSync(currentScript) && !currentScript.startsWith("/$bunfs/root/")) {
|
|
22
|
+
return { command: process.execPath, args: [currentScript, ...args] };
|
|
23
|
+
}
|
|
24
|
+
return { command: "pi", args };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const CHILD_THINKING_LEVELS = new Set<string>(["low", "medium", "high", "xhigh"]);
|
|
28
|
+
|
|
29
|
+
function validateChildThinkingOverride(thinking: string | undefined, fieldName = "thinking"): string[] {
|
|
30
|
+
if (thinking === undefined) return [];
|
|
31
|
+
return CHILD_THINKING_LEVELS.has(thinking) ? [] : [`${fieldName} must be one of low, medium, high, xhigh`];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function resolveChildThinking(agent: HarnessAgent, thinkingOverride: ChildThinkingLevel | undefined): string | undefined {
|
|
35
|
+
return thinkingOverride ?? agent.thinking;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function formatSupervisedReadonlyTask(contract: SupervisedReadonlyDispatchContract): string {
|
|
39
|
+
const outputContractGuidance = contract.outputContract === "lead-plan.v1"
|
|
40
|
+
? [
|
|
41
|
+
"For lead-plan.v1, include parseable JSON inside <worker_contracts>...</worker_contracts>.",
|
|
42
|
+
"Use this exact JSON shape: {\"worker_contracts\":[{\"worker_id\":\"...\",\"lead_id\":\"...\",\"agent\":\"...\",\"task\":\"...\",\"expected_outcome\":\"...\",\"required_tools\":[\"read\",\"grep\",\"find\",\"ls\"],\"output_contract\":\"explore.v1\",\"must_do\":[\"...\"],\"must_not_do\":[\"...\"],\"context\":\"...\",\"allowed_paths\":[\"repo-relative/path\"],\"forbidden_paths\":[\"repo-relative/path\",\"~/secret-dir\",\"/absolute/deny-only/path\"],\"model_class\":\"cheap_scout\"}]}",
|
|
43
|
+
"allowed_paths must be repo-relative only; do not include absolute paths, home paths, or paths starting with '~'. forbidden_paths are deny-only patterns and may be repo-local, absolute, or home-relative; broad roots are rejected.",
|
|
44
|
+
"Also include literal lead-plan fields: lead_id, phase, required_tools, allowed_paths, forbidden_paths, output_contract, model_class, evidence_needed, no_ship_criteria, evidence, risks/blockers, compliance.",
|
|
45
|
+
].join("\n")
|
|
46
|
+
: "Return the required contract sections.";
|
|
47
|
+
return [
|
|
48
|
+
`1. TASK: ${contract.task}`,
|
|
49
|
+
`2. EXPECTED OUTCOME: ${contract.expectedOutcome}`,
|
|
50
|
+
`3. REQUIRED TOOLS: ${contract.requiredTools.join(", ")}`,
|
|
51
|
+
`4. MUST DO:\n- ${contract.mustDo.join("\n- ")}`,
|
|
52
|
+
`5. MUST NOT DO:\n- ${[...contract.mustNotDo, "Do not delegate to other workers", "Do not use tools outside read, grep, find, ls"].join("\n- ")}`,
|
|
53
|
+
`6. CONTEXT: ${contract.context}`,
|
|
54
|
+
`OUTPUT_CONTRACT: ${contract.outputContract}`,
|
|
55
|
+
outputContractGuidance,
|
|
56
|
+
`Final line must be exactly: deliverable_delivered: yes`,
|
|
57
|
+
].join("\n");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function createSupervisedReadonlyDispatcher(ctx: ExtensionContext, signal: AbortSignal | undefined, modelOverride: string | undefined, emitUpdate: ((result: ChildResult) => void) | undefined): SupervisedReadonlyDispatcher {
|
|
61
|
+
return async (contract) => {
|
|
62
|
+
const agents = discoverAgents(ctx.cwd, "project");
|
|
63
|
+
const agent = agents.find((candidate) => candidate.name.toLowerCase() === contract.agent.toLowerCase());
|
|
64
|
+
if (!agent) return { status: "failed", error: `agent_not_found:${sha256(contract.agent)}` };
|
|
65
|
+
|
|
66
|
+
const childResult = await runChildAgent(ctx, agent, formatSupervisedReadonlyTask(contract), ctx.cwd, signal, modelOverride, SUPERVISED_READONLY_CHILD_TOOLS.join(","), emitUpdate);
|
|
67
|
+
childResult.outputContract = contract.outputContract;
|
|
68
|
+
applyChildGates(childResult, { repoRoot: ctx.cwd });
|
|
69
|
+
|
|
70
|
+
const outputHash = childResult.output ? sha256(childResult.output) : undefined;
|
|
71
|
+
if (isFailed(childResult)) {
|
|
72
|
+
const gateErrorHash = childResult.gateErrors && childResult.gateErrors.length > 0 ? sha256(childResult.gateErrors.join("\n")) : undefined;
|
|
73
|
+
const runtimeErrorHash = childResult.errorMessage ? sha256(childResult.errorMessage) : undefined;
|
|
74
|
+
return { status: "failed", outputHash, output: childResult.output, error: gateErrorHash ?? runtimeErrorHash ?? `child_failed:${childResult.exitCode}`, dispatcher: "live_child_pi", mocked: false, sessionPath: childResult.sessionPath, outputContractValidated: childResult.gatePassed !== undefined, gatePassed: childResult.gatePassed };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return { status: "completed", outputHash, output: childResult.output, dispatcher: "live_child_pi", mocked: false, sessionPath: childResult.sessionPath, outputContractValidated: childResult.gatePassed !== undefined, gatePassed: childResult.gatePassed };
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function runChildAgent(
|
|
82
|
+
ctx: ExtensionContext,
|
|
83
|
+
agent: HarnessAgent,
|
|
84
|
+
task: string,
|
|
85
|
+
cwd: string | undefined,
|
|
86
|
+
signal: AbortSignal | undefined,
|
|
87
|
+
modelOverride: string | undefined,
|
|
88
|
+
toolsOverride: string | undefined,
|
|
89
|
+
emitUpdate: ((result: ChildResult) => void) | undefined,
|
|
90
|
+
pathPolicy?: { allowedPaths?: string[]; forbiddenPaths?: string[]; sandboxRoot?: string },
|
|
91
|
+
thinkingOverride?: ChildThinkingLevel,
|
|
92
|
+
): Promise<ChildResult> {
|
|
93
|
+
const result: ChildResult = {
|
|
94
|
+
agent: agent.name,
|
|
95
|
+
task,
|
|
96
|
+
exitCode: 0,
|
|
97
|
+
output: "",
|
|
98
|
+
stderr: "",
|
|
99
|
+
model: modelOverride ?? agent.model,
|
|
100
|
+
usage: usageEmpty(),
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const modelOverrideValidation = validateExplicitModelOverride(ctx.cwd, modelOverride);
|
|
104
|
+
if (!modelOverrideValidation.ok) {
|
|
105
|
+
return {
|
|
106
|
+
...result,
|
|
107
|
+
exitCode: 1,
|
|
108
|
+
output: `Delegation preflight failed (no child launched):\n- ${modelOverrideValidation.errors.join("\n- ")}`,
|
|
109
|
+
gatePassed: false,
|
|
110
|
+
gateErrors: modelOverrideValidation.errors,
|
|
111
|
+
contractErrors: modelOverrideValidation.errors,
|
|
112
|
+
failureKind: "config",
|
|
113
|
+
errorMessage: `Configuration blocked; no child launched: ${modelOverrideValidation.errors.join("; ")}`,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const tmp = await mkdtemp(join(tmpdir(), "zob-agent-"));
|
|
118
|
+
const agentSessionDir = join(ctx.cwd, ".pi", "agent-sessions");
|
|
119
|
+
mkdirSync(agentSessionDir, { recursive: true });
|
|
120
|
+
const sessionPath = join(agentSessionDir, `${Date.now()}-${process.pid}-${safeFileStem(agent.name)}.jsonl`);
|
|
121
|
+
result.sessionPath = sessionPath;
|
|
122
|
+
emitUpdate?.(result);
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
const childSafetyExtension = join(ctx.cwd, ".pi", "extensions", "zob-child-safety", "index.ts");
|
|
126
|
+
const args = ["--mode", "json", "-p", "--no-extensions"];
|
|
127
|
+
if (existsSync(childSafetyExtension)) args.push("-e", childSafetyExtension);
|
|
128
|
+
args.push("--session", sessionPath);
|
|
129
|
+
const model = modelOverride ?? agent.model;
|
|
130
|
+
if (model) args.push("--model", model);
|
|
131
|
+
const thinking = resolveChildThinking(agent, thinkingOverride);
|
|
132
|
+
if (thinking) args.push("--thinking", thinking);
|
|
133
|
+
const tools = toolsOverride ?? agent.tools?.join(",");
|
|
134
|
+
if (tools) args.push("--tools", tools);
|
|
135
|
+
args.push("--append-system-prompt", agent.prompt);
|
|
136
|
+
args.push(task);
|
|
137
|
+
|
|
138
|
+
await new Promise<void>((resolvePromise) => {
|
|
139
|
+
const invocation = getPiInvocation(args);
|
|
140
|
+
const child = spawn(invocation.command, invocation.args, {
|
|
141
|
+
cwd: cwd ?? ctx.cwd,
|
|
142
|
+
shell: false,
|
|
143
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
144
|
+
env: buildChildEnv(ctx.cwd, pathPolicy),
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
let stdoutBuffer = "";
|
|
148
|
+
let finalText = "";
|
|
149
|
+
let wasAborted = false;
|
|
150
|
+
|
|
151
|
+
const processLine = (line: string): void => {
|
|
152
|
+
const event = parseJsonLine(line);
|
|
153
|
+
if (!event) return;
|
|
154
|
+
|
|
155
|
+
if (event.type === "message_update" && event.assistantMessageEvent?.type === "text_delta") {
|
|
156
|
+
const delta = event.assistantMessageEvent.delta ?? "";
|
|
157
|
+
finalText += delta;
|
|
158
|
+
result.output = finalText;
|
|
159
|
+
emitUpdate?.(result);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (event.type === "message_end" && event.message?.role === "assistant") {
|
|
163
|
+
const text = textFromMessage(event.message);
|
|
164
|
+
if (text) {
|
|
165
|
+
finalText = text;
|
|
166
|
+
result.output = text;
|
|
167
|
+
}
|
|
168
|
+
result.stopReason = event.message.stopReason;
|
|
169
|
+
result.errorMessage = event.message.errorMessage;
|
|
170
|
+
if (event.message.model) result.model = `${event.message.provider ?? ""}/${event.message.model}`.replace(/^\//, "");
|
|
171
|
+
updateUsage(result, event.message);
|
|
172
|
+
emitUpdate?.(result);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (event.type === "agent_end" && Array.isArray(event.messages)) {
|
|
176
|
+
const assistantMessages = event.messages.filter((message) => message.role === "assistant");
|
|
177
|
+
const last = assistantMessages.at(-1);
|
|
178
|
+
const text = textFromMessage(last);
|
|
179
|
+
if (text) result.output = text;
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
child.stdout.setEncoding("utf8");
|
|
184
|
+
child.stdout.on("data", (chunk: string) => {
|
|
185
|
+
stdoutBuffer += chunk;
|
|
186
|
+
const lines = stdoutBuffer.split("\n");
|
|
187
|
+
stdoutBuffer = lines.pop() ?? "";
|
|
188
|
+
for (const line of lines) processLine(line);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
child.stderr.setEncoding("utf8");
|
|
192
|
+
child.stderr.on("data", (chunk: string) => {
|
|
193
|
+
result.stderr += chunk;
|
|
194
|
+
emitUpdate?.(result);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
const abortChild = (): void => {
|
|
198
|
+
wasAborted = true;
|
|
199
|
+
child.kill("SIGTERM");
|
|
200
|
+
setTimeout(() => {
|
|
201
|
+
if (!child.killed) child.kill("SIGKILL");
|
|
202
|
+
}, 5000).unref();
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
if (signal?.aborted) abortChild();
|
|
206
|
+
else signal?.addEventListener("abort", abortChild, { once: true });
|
|
207
|
+
|
|
208
|
+
child.on("error", (error) => {
|
|
209
|
+
result.exitCode = 1;
|
|
210
|
+
result.errorMessage = error.message;
|
|
211
|
+
resolvePromise();
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
child.on("close", (code) => {
|
|
215
|
+
signal?.removeEventListener("abort", abortChild);
|
|
216
|
+
if (stdoutBuffer.trim()) processLine(stdoutBuffer);
|
|
217
|
+
result.exitCode = code ?? (wasAborted ? 130 : 0);
|
|
218
|
+
if (wasAborted) {
|
|
219
|
+
result.stopReason = "aborted";
|
|
220
|
+
result.errorMessage = "Child agent aborted";
|
|
221
|
+
}
|
|
222
|
+
resolvePromise();
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
} finally {
|
|
226
|
+
await rm(tmp, { recursive: true, force: true });
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return result;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function isFailed(result: ChildResult): boolean {
|
|
233
|
+
return result.exitCode !== 0 || result.stopReason === "error" || result.stopReason === "aborted" || result.gatePassed === false;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async function mapWithConcurrency<T, R>(items: T[], limit: number, fn: (item: T, index: number) => Promise<R>): Promise<R[]> {
|
|
237
|
+
const results: R[] = new Array(items.length);
|
|
238
|
+
let cursor = 0;
|
|
239
|
+
const workers = new Array(Math.min(limit, items.length)).fill(undefined).map(async () => {
|
|
240
|
+
while (cursor < items.length) {
|
|
241
|
+
const index = cursor++;
|
|
242
|
+
results[index] = await fn(items[index], index);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
await Promise.all(workers);
|
|
246
|
+
return results;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export { createSupervisedReadonlyDispatcher, isFailed, mapWithConcurrency, runChildAgent, validateChildThinkingOverride };
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
BudgetPreflightDryRunInput,
|
|
6
|
+
ChildStopCondition,
|
|
7
|
+
ChildStopConditionInput,
|
|
8
|
+
ChronicleClassifyInput,
|
|
9
|
+
DelegationTelemetryInput,
|
|
10
|
+
FactoryTelemetryInput,
|
|
11
|
+
RunawayGuardInput,
|
|
12
|
+
} from "./types.js";
|
|
13
|
+
import { sha256 } from "./utils/hashing.js";
|
|
14
|
+
import { safeFileStem } from "./utils/paths.js";
|
|
15
|
+
|
|
16
|
+
export const CHRONICLE_STATES = [
|
|
17
|
+
"created",
|
|
18
|
+
"preflighted",
|
|
19
|
+
"running",
|
|
20
|
+
"assistant_turn_seen",
|
|
21
|
+
"output_captured",
|
|
22
|
+
"output_validated",
|
|
23
|
+
"evidence_checked",
|
|
24
|
+
"complete",
|
|
25
|
+
"failed_preflight",
|
|
26
|
+
"incomplete_no_assistant_turn",
|
|
27
|
+
"incomplete_no_evidence",
|
|
28
|
+
"failed_validation",
|
|
29
|
+
"scope_violation",
|
|
30
|
+
"timeout",
|
|
31
|
+
"blocked",
|
|
32
|
+
"planned",
|
|
33
|
+
"agentic_failed",
|
|
34
|
+
] as const;
|
|
35
|
+
|
|
36
|
+
export type ChronicleState = (typeof CHRONICLE_STATES)[number];
|
|
37
|
+
|
|
38
|
+
const TERMINAL_CHRONICLE_FAILURE_STATES = new Set<ChronicleState>([
|
|
39
|
+
"failed_preflight",
|
|
40
|
+
"incomplete_no_assistant_turn",
|
|
41
|
+
"incomplete_no_evidence",
|
|
42
|
+
"failed_validation",
|
|
43
|
+
"scope_violation",
|
|
44
|
+
"timeout",
|
|
45
|
+
"blocked",
|
|
46
|
+
"agentic_failed",
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
export function evaluateBudgetPreflightDryRun(input: BudgetPreflightDryRunInput): Record<string, unknown> {
|
|
50
|
+
const caps = input.caps ?? {};
|
|
51
|
+
const observed = {
|
|
52
|
+
costUsd: input.costUsd ?? 0,
|
|
53
|
+
runs: input.runs ?? 0,
|
|
54
|
+
durationMs: input.durationMs ?? 0,
|
|
55
|
+
parallelChildren: input.parallelChildren ?? 0,
|
|
56
|
+
};
|
|
57
|
+
const checks = [
|
|
58
|
+
{ name: "maxCostUsd", cap: caps.maxCostUsd, observed: observed.costUsd },
|
|
59
|
+
{ name: "maxRuns", cap: caps.maxRuns, observed: observed.runs },
|
|
60
|
+
{ name: "maxDurationMs", cap: caps.maxDurationMs, observed: observed.durationMs },
|
|
61
|
+
{ name: "maxParallelChildren", cap: caps.maxParallelChildren, observed: observed.parallelChildren },
|
|
62
|
+
].map((check) => ({
|
|
63
|
+
...check,
|
|
64
|
+
passed: check.cap === undefined || check.observed <= check.cap,
|
|
65
|
+
}));
|
|
66
|
+
const failures = checks.filter((check) => !check.passed).map((check) => check.name);
|
|
67
|
+
return {
|
|
68
|
+
schema: "zob.budget-preflight-result.v1",
|
|
69
|
+
passed: failures.length === 0,
|
|
70
|
+
failures,
|
|
71
|
+
caps,
|
|
72
|
+
observed,
|
|
73
|
+
checks,
|
|
74
|
+
dryRun: true,
|
|
75
|
+
mode: "advisory",
|
|
76
|
+
advisory: true,
|
|
77
|
+
wouldExceed: failures.length > 0,
|
|
78
|
+
strictRequested: input.strictRequested === true,
|
|
79
|
+
strictEnabled: false,
|
|
80
|
+
budgetEnforced: false,
|
|
81
|
+
wouldBlockDispatch: false,
|
|
82
|
+
defaultDispatchDecision: "allow",
|
|
83
|
+
modelRouterUsed: false,
|
|
84
|
+
daemonStarted: false,
|
|
85
|
+
childDispatchAllowed: false,
|
|
86
|
+
noExecution: true,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function outputHasEvidenceMarker(output: string | undefined): boolean {
|
|
91
|
+
if (!output) return false;
|
|
92
|
+
return /(?:<evidence>[\s\S]*?<\/evidence>|<evidence>|\bevidence\b|preuve|preuves)/i.test(output);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function detectOracleFail(output: string | undefined): { oracleFailed: boolean; noShip: boolean; stopCondition: ChildStopCondition } {
|
|
96
|
+
const text = output ?? "";
|
|
97
|
+
const oracleFailed = /(?:<verdict>\s*FAIL\s*<\/verdict>|\bverdict\s*[:=-]\s*FAIL\b|^\s*FAIL\b)/im.test(text);
|
|
98
|
+
const noShip = /(?:<no_ship>\s*(?:true|yes)\s*<\/no_ship>|\bno_ship\s*[:=-]\s*(?:true|yes)\b|\bno ship\s*[:=-]\s*(?:true|yes)\b)/i.test(text);
|
|
99
|
+
return { oracleFailed, noShip, stopCondition: noShip ? "no_ship" : oracleFailed ? "oracle_fail" : "none" };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function summarizeRunawayGuard(input: RunawayGuardInput = {}): Record<string, unknown> {
|
|
103
|
+
const threshold = Math.max(1, Math.floor(input.failLoopThreshold ?? 3));
|
|
104
|
+
const failureStatuses = new Set(["failed", "failed_preflight", "failed_validation", "incomplete_or_failed", "incomplete_no_assistant_turn", "incomplete_no_evidence", "timeout", "agentic_failed", "oracle_fail", "no_ship"]);
|
|
105
|
+
const recentFailures = typeof input.failures === "number" ? input.failures : (input.recentStatuses ?? []).filter((status) => failureStatuses.has(status)).length;
|
|
106
|
+
const failLoopExceeded = recentFailures >= threshold;
|
|
107
|
+
return {
|
|
108
|
+
schema: "zob.runaway-guard.v1",
|
|
109
|
+
stopCondition: failLoopExceeded ? "fail_loop" : "none",
|
|
110
|
+
shouldStop: failLoopExceeded,
|
|
111
|
+
failLoopThreshold: threshold,
|
|
112
|
+
recentFailures,
|
|
113
|
+
budget: {
|
|
114
|
+
wouldExceed: input.budgetWouldExceed === true,
|
|
115
|
+
enforced: false,
|
|
116
|
+
advisory: true,
|
|
117
|
+
wouldBlockDispatch: false,
|
|
118
|
+
},
|
|
119
|
+
budgetEnforced: false,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function classifyChildStopCondition(input: ChildStopConditionInput): Record<string, unknown> {
|
|
124
|
+
const oracle = detectOracleFail(input.output);
|
|
125
|
+
const outputCaptured = input.outputCaptured ?? Boolean(input.outputHash);
|
|
126
|
+
let stopCondition: ChildStopCondition = "none";
|
|
127
|
+
|
|
128
|
+
if (input.failLoopExceeded) stopCondition = "fail_loop";
|
|
129
|
+
else if (input.scopeViolation) stopCondition = "scope_violation";
|
|
130
|
+
else if (input.timedOut || input.status === "timeout") stopCondition = "timeout";
|
|
131
|
+
else if (input.blocked || input.status === "blocked") stopCondition = "blocked";
|
|
132
|
+
else if (input.agenticFailed || input.status === "agentic_failed") stopCondition = "agentic_failed";
|
|
133
|
+
else if (input.preflightPassed === false || input.status === "failed_preflight" || input.status === "unknown_agent") stopCondition = "failed_preflight";
|
|
134
|
+
else if (oracle.noShip) stopCondition = "no_ship";
|
|
135
|
+
else if (oracle.oracleFailed) stopCondition = "oracle_fail";
|
|
136
|
+
else if (input.assistantTurnSeen === false) stopCondition = "incomplete_no_assistant_turn";
|
|
137
|
+
else if (!outputCaptured || !input.outputHash || input.evidenceChecked === false) stopCondition = "incomplete_no_evidence";
|
|
138
|
+
else if (input.outputValidated === false || input.status === "failed_validation" || input.status === "incomplete_or_failed") stopCondition = "failed_validation";
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
schema: "zob.child-stop-condition.v1",
|
|
142
|
+
stopCondition,
|
|
143
|
+
shouldStop: stopCondition !== "none",
|
|
144
|
+
oracleFailed: oracle.oracleFailed,
|
|
145
|
+
noShip: oracle.noShip,
|
|
146
|
+
budget: { advisory: true, enforced: false },
|
|
147
|
+
budgetEnforced: false,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function classifyChronicleCompletion(input: ChronicleClassifyInput): Record<string, unknown> {
|
|
152
|
+
const preflightPassed = input.preflightPassed ?? input.status !== "failed_preflight";
|
|
153
|
+
const assistantTurnSeen = input.assistantTurnSeen === true;
|
|
154
|
+
const outputCaptured = input.outputCaptured ?? Boolean(input.outputHash);
|
|
155
|
+
const outputValidated = input.outputValidated === true;
|
|
156
|
+
const evidenceChecked = input.evidenceChecked === true;
|
|
157
|
+
let state: ChronicleState = "created";
|
|
158
|
+
|
|
159
|
+
if (input.scopeViolation) state = "scope_violation";
|
|
160
|
+
else if (input.timedOut) state = "timeout";
|
|
161
|
+
else if (input.blocked) state = "blocked";
|
|
162
|
+
else if (input.agenticFailed || input.status === "agentic_failed") state = "agentic_failed";
|
|
163
|
+
else if (!preflightPassed || input.status === "failed_preflight") state = "failed_preflight";
|
|
164
|
+
else if (input.planned || input.status === "planned") state = "planned";
|
|
165
|
+
else if (!assistantTurnSeen) state = "incomplete_no_assistant_turn";
|
|
166
|
+
else if (!outputCaptured || !input.outputHash || !evidenceChecked) state = "incomplete_no_evidence";
|
|
167
|
+
else if (!outputValidated) state = "failed_validation";
|
|
168
|
+
else state = "complete";
|
|
169
|
+
|
|
170
|
+
const stopCondition = input.stopCondition ?? (state === "complete" || state === "planned" ? "none" : (state as ChildStopCondition));
|
|
171
|
+
|
|
172
|
+
return {
|
|
173
|
+
schema: "zob.chronicle-state.v1",
|
|
174
|
+
kind: input.kind,
|
|
175
|
+
runId: input.runId,
|
|
176
|
+
state,
|
|
177
|
+
complete: state === "complete",
|
|
178
|
+
stopCondition,
|
|
179
|
+
falseDoneGuard: {
|
|
180
|
+
assistantTurnSeen,
|
|
181
|
+
outputCaptured: Boolean(outputCaptured && input.outputHash),
|
|
182
|
+
outputValidated,
|
|
183
|
+
evidenceChecked,
|
|
184
|
+
passed: state === "complete",
|
|
185
|
+
},
|
|
186
|
+
taskHash: input.taskHash,
|
|
187
|
+
outputHash: input.outputHash,
|
|
188
|
+
evidencePaths: input.evidencePaths ?? [],
|
|
189
|
+
budget: {
|
|
190
|
+
advisory: input.budget?.advisory ?? true,
|
|
191
|
+
enforced: input.budget?.enforced === true,
|
|
192
|
+
},
|
|
193
|
+
terminalFailure: TERMINAL_CHRONICLE_FAILURE_STATES.has(state),
|
|
194
|
+
errors: input.errors ?? [],
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export function classifyDelegationChronicleCompletion(input: DelegationTelemetryInput): Record<string, unknown> {
|
|
199
|
+
const stop = classifyChildStopCondition({
|
|
200
|
+
status: input.status,
|
|
201
|
+
agent: input.agent,
|
|
202
|
+
outputContract: input.outputContract,
|
|
203
|
+
assistantTurnSeen: input.assistantTurnSeen ?? ((input.usage?.turns ?? 0) > 0),
|
|
204
|
+
outputHash: input.outputHash,
|
|
205
|
+
outputCaptured: input.outputCaptured ?? Boolean(input.outputHash),
|
|
206
|
+
outputValidated: input.outputValidated ?? input.gatePassed === true,
|
|
207
|
+
evidenceChecked: input.evidenceChecked ?? input.gatePassed === true,
|
|
208
|
+
preflightPassed: input.status !== "failed_preflight" && input.status !== "unknown_agent",
|
|
209
|
+
timedOut: input.status === "timeout",
|
|
210
|
+
blocked: input.status === "blocked",
|
|
211
|
+
});
|
|
212
|
+
return classifyChronicleCompletion({
|
|
213
|
+
kind: "delegation",
|
|
214
|
+
runId: input.runId,
|
|
215
|
+
status: input.status,
|
|
216
|
+
taskHash: input.taskHash,
|
|
217
|
+
outputHash: input.outputHash,
|
|
218
|
+
stopCondition: input.stopCondition ?? (stop.stopCondition as ChildStopCondition),
|
|
219
|
+
assistantTurnSeen: input.assistantTurnSeen ?? ((input.usage?.turns ?? 0) > 0),
|
|
220
|
+
outputCaptured: input.outputCaptured ?? Boolean(input.outputHash),
|
|
221
|
+
outputValidated: input.outputValidated ?? input.gatePassed === true,
|
|
222
|
+
evidenceChecked: input.evidenceChecked ?? input.gatePassed === true,
|
|
223
|
+
preflightPassed: input.status !== "failed_preflight" && input.status !== "unknown_agent",
|
|
224
|
+
timedOut: input.status === "timeout",
|
|
225
|
+
blocked: input.status === "blocked",
|
|
226
|
+
budget: { advisory: true, enforced: false },
|
|
227
|
+
errors: input.gateErrors ?? [],
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export function classifyFactoryChronicleCompletion(input: FactoryTelemetryInput): Record<string, unknown> {
|
|
232
|
+
const outputHash = input.generatedArtifacts.length > 0 ? sha256(input.generatedArtifacts.join("\n")) : undefined;
|
|
233
|
+
const validationPassed = input.status === "done";
|
|
234
|
+
return classifyChronicleCompletion({
|
|
235
|
+
kind: "factory",
|
|
236
|
+
runId: input.runId,
|
|
237
|
+
status: input.status,
|
|
238
|
+
outputHash,
|
|
239
|
+
evidencePaths: input.generatedArtifacts,
|
|
240
|
+
assistantTurnSeen: input.execution === "agentic" ? (input.usage?.turns ?? 0) > 0 : input.status !== "failed_preflight",
|
|
241
|
+
outputCaptured: input.generatedArtifacts.length > 0,
|
|
242
|
+
outputValidated: validationPassed,
|
|
243
|
+
evidenceChecked: validationPassed,
|
|
244
|
+
preflightPassed: input.status !== "failed_preflight",
|
|
245
|
+
planned: input.status === "planned",
|
|
246
|
+
agenticFailed: input.status === "agentic_failed",
|
|
247
|
+
budget: { advisory: true, enforced: false },
|
|
248
|
+
errors: input.errors ?? [],
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export function writeChronicleSnapshot(repoRoot: string, snapshot: Record<string, unknown>): string {
|
|
253
|
+
const runId = typeof snapshot.runId === "string" && snapshot.runId ? snapshot.runId : "unknown";
|
|
254
|
+
const kind = typeof snapshot.kind === "string" && snapshot.kind ? snapshot.kind : "run";
|
|
255
|
+
const dir = join(repoRoot, ".pi", "logs", "chronicle");
|
|
256
|
+
mkdirSync(dir, { recursive: true });
|
|
257
|
+
const outputPath = join(dir, `${safeFileStem(kind)}-${safeFileStem(runId)}.json`);
|
|
258
|
+
writeFileSync(outputPath, JSON.stringify(snapshot, null, 2), "utf8");
|
|
259
|
+
return outputPath;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export { outputHasEvidenceMarker };
|