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,373 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
import { classifyDelegationChronicleCompletion, classifyFactoryChronicleCompletion, writeChronicleSnapshot } from "./chronicle.js";
|
|
5
|
+
import type { AssistantLikeMessage, ChildResult, ChildStopCondition, DelegationTelemetryInput, FactoryTelemetryInput } from "./types.js";
|
|
6
|
+
import { parseJsonFile } from "./utils/json.js";
|
|
7
|
+
import { safeFileStem } from "./utils/paths.js";
|
|
8
|
+
import { isRecord } from "./utils/records.js";
|
|
9
|
+
|
|
10
|
+
function usageEmpty(): ChildResult["usage"] {
|
|
11
|
+
return { turns: 0, input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, contextTokens: 0 };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function addUsage(target: ChildResult["usage"], source: ChildResult["usage"] | undefined): void {
|
|
15
|
+
if (!source) return;
|
|
16
|
+
target.turns += source.turns ?? 0;
|
|
17
|
+
target.input += source.input ?? 0;
|
|
18
|
+
target.output += source.output ?? 0;
|
|
19
|
+
target.cacheRead += source.cacheRead ?? 0;
|
|
20
|
+
target.cacheWrite += source.cacheWrite ?? 0;
|
|
21
|
+
target.cost += source.cost ?? 0;
|
|
22
|
+
target.contextTokens = Math.max(target.contextTokens, source.contextTokens ?? 0);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function updateUsage(result: ChildResult, message: AssistantLikeMessage): void {
|
|
26
|
+
result.usage.turns += 1;
|
|
27
|
+
const usage = message.usage;
|
|
28
|
+
if (!usage) return;
|
|
29
|
+
result.usage.input += usage.input ?? 0;
|
|
30
|
+
result.usage.output += usage.output ?? 0;
|
|
31
|
+
result.usage.cacheRead += usage.cacheRead ?? 0;
|
|
32
|
+
result.usage.cacheWrite += usage.cacheWrite ?? 0;
|
|
33
|
+
result.usage.cost += usage.cost?.total ?? 0;
|
|
34
|
+
result.usage.contextTokens = usage.totalTokens ?? result.usage.contextTokens;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function buildDelegationTelemetrySummary(input: DelegationTelemetryInput): Record<string, unknown> {
|
|
38
|
+
const usage = input.usage ?? usageEmpty();
|
|
39
|
+
return {
|
|
40
|
+
schema: "zob.delegation-telemetry.v1",
|
|
41
|
+
runId: input.runId,
|
|
42
|
+
source: input.source,
|
|
43
|
+
mode: input.mode,
|
|
44
|
+
agent: input.agent,
|
|
45
|
+
model: input.model,
|
|
46
|
+
cwd: input.cwd,
|
|
47
|
+
tools: input.tools,
|
|
48
|
+
taskHash: input.taskHash,
|
|
49
|
+
outputHash: input.outputHash,
|
|
50
|
+
outputContract: input.outputContract,
|
|
51
|
+
status: input.status,
|
|
52
|
+
stopCondition: input.stopCondition ?? (classifyDelegationChronicleCompletion(input).stopCondition as ChildStopCondition),
|
|
53
|
+
chronicle: classifyDelegationChronicleCompletion(input),
|
|
54
|
+
gate: {
|
|
55
|
+
passed: input.gatePassed ?? false,
|
|
56
|
+
errors: input.gateErrors ?? [],
|
|
57
|
+
},
|
|
58
|
+
usage: {
|
|
59
|
+
turns: usage.turns,
|
|
60
|
+
input: usage.input,
|
|
61
|
+
output: usage.output,
|
|
62
|
+
cacheRead: usage.cacheRead,
|
|
63
|
+
cacheWrite: usage.cacheWrite,
|
|
64
|
+
cost: usage.cost,
|
|
65
|
+
contextTokens: usage.contextTokens,
|
|
66
|
+
},
|
|
67
|
+
latencyMs: Math.max(0, Math.round(input.latencyMs)),
|
|
68
|
+
startedAt: input.startedAt,
|
|
69
|
+
endedAt: input.endedAt,
|
|
70
|
+
sessionPath: input.sessionPath,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function writeDelegationTelemetrySummary(repoRoot: string, input: DelegationTelemetryInput): string {
|
|
75
|
+
const dir = join(repoRoot, ".pi", "logs", "telemetry");
|
|
76
|
+
mkdirSync(dir, { recursive: true });
|
|
77
|
+
const outputPath = join(dir, `${safeFileStem(input.runId)}.json`);
|
|
78
|
+
const summary = buildDelegationTelemetrySummary(input);
|
|
79
|
+
writeFileSync(outputPath, JSON.stringify(summary, null, 2), "utf8");
|
|
80
|
+
if (isRecord(summary.chronicle)) writeChronicleSnapshot(repoRoot, summary.chronicle as Record<string, unknown>);
|
|
81
|
+
writeDailyTelemetrySummary(repoRoot, input.startedAt.slice(0, 10));
|
|
82
|
+
return outputPath;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function buildFactoryTelemetrySummary(input: FactoryTelemetryInput): Record<string, unknown> {
|
|
86
|
+
const usage = input.usage ?? usageEmpty();
|
|
87
|
+
const costTotal = usage.cost;
|
|
88
|
+
return {
|
|
89
|
+
schema: "zob.factory-telemetry.v1",
|
|
90
|
+
runId: input.runId,
|
|
91
|
+
factory: input.factory,
|
|
92
|
+
mode: input.mode,
|
|
93
|
+
execution: input.execution,
|
|
94
|
+
status: input.status,
|
|
95
|
+
items: {
|
|
96
|
+
selected: input.itemCount,
|
|
97
|
+
processed: input.processed,
|
|
98
|
+
failed: input.failed,
|
|
99
|
+
costTotal,
|
|
100
|
+
costPerItem: input.itemCount > 0 ? costTotal / input.itemCount : 0,
|
|
101
|
+
},
|
|
102
|
+
artifacts: {
|
|
103
|
+
expected: input.expectedArtifacts,
|
|
104
|
+
generated: input.generatedArtifacts,
|
|
105
|
+
count: input.generatedArtifacts.length,
|
|
106
|
+
costTotal,
|
|
107
|
+
costPerArtifact: input.generatedArtifacts.length > 0 ? costTotal / input.generatedArtifacts.length : 0,
|
|
108
|
+
},
|
|
109
|
+
stages: {
|
|
110
|
+
declared: input.stageCount,
|
|
111
|
+
agenticTasks: input.agenticTasks,
|
|
112
|
+
failuresByStage: input.failuresByStage,
|
|
113
|
+
},
|
|
114
|
+
retries: {
|
|
115
|
+
count: input.retryCount,
|
|
116
|
+
},
|
|
117
|
+
usage: {
|
|
118
|
+
turns: usage.turns,
|
|
119
|
+
input: usage.input,
|
|
120
|
+
output: usage.output,
|
|
121
|
+
cacheRead: usage.cacheRead,
|
|
122
|
+
cacheWrite: usage.cacheWrite,
|
|
123
|
+
cost: usage.cost,
|
|
124
|
+
contextTokens: usage.contextTokens,
|
|
125
|
+
},
|
|
126
|
+
wallTimeMs: Math.max(0, Math.round(input.wallTimeMs)),
|
|
127
|
+
startedAt: input.startedAt,
|
|
128
|
+
endedAt: input.endedAt,
|
|
129
|
+
budgetEnforced: input.budgetEnforced === true,
|
|
130
|
+
modelRouterUsed: input.modelRouterUsed === true,
|
|
131
|
+
chronicle: classifyFactoryChronicleCompletion(input),
|
|
132
|
+
errors: input.errors ?? [],
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function writeFactoryTelemetrySummary(repoRoot: string, input: FactoryTelemetryInput): { globalPath: string; runPath?: string } {
|
|
137
|
+
const dir = join(repoRoot, ".pi", "logs", "telemetry");
|
|
138
|
+
mkdirSync(dir, { recursive: true });
|
|
139
|
+
const summary = buildFactoryTelemetrySummary(input);
|
|
140
|
+
if (isRecord(summary.chronicle)) writeChronicleSnapshot(repoRoot, summary.chronicle as Record<string, unknown>);
|
|
141
|
+
const globalStem = input.status === "failed_preflight" && !input.runDir ? `factory-${safeFileStem(input.runId)}-failed-preflight` : `factory-${safeFileStem(input.runId)}`;
|
|
142
|
+
const globalPath = join(dir, `${globalStem}.json`);
|
|
143
|
+
writeFileSync(globalPath, JSON.stringify(summary, null, 2), "utf8");
|
|
144
|
+
writeDailyTelemetrySummary(repoRoot, input.startedAt.slice(0, 10));
|
|
145
|
+
let runPath: string | undefined;
|
|
146
|
+
if (input.runDir && existsSync(input.runDir)) {
|
|
147
|
+
runPath = join(input.runDir, "telemetry.json");
|
|
148
|
+
writeFileSync(runPath, JSON.stringify(summary, null, 2), "utf8");
|
|
149
|
+
}
|
|
150
|
+
return { globalPath, runPath };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function normalizeDailyTelemetryDate(date?: string): string {
|
|
154
|
+
const candidate = (date ?? new Date().toISOString()).slice(0, 10);
|
|
155
|
+
return /^\d{4}-\d{2}-\d{2}$/.test(candidate) ? candidate : new Date().toISOString().slice(0, 10);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function numberFrom(value: unknown): number {
|
|
159
|
+
return typeof value === "number" && Number.isFinite(value) ? value : 0;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function stringFrom(value: unknown): string | undefined {
|
|
163
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function usageFromRecord(value: unknown): ChildResult["usage"] {
|
|
167
|
+
if (!isRecord(value)) return usageEmpty();
|
|
168
|
+
return {
|
|
169
|
+
turns: numberFrom(value.turns),
|
|
170
|
+
input: numberFrom(value.input),
|
|
171
|
+
output: numberFrom(value.output),
|
|
172
|
+
cacheRead: numberFrom(value.cacheRead),
|
|
173
|
+
cacheWrite: numberFrom(value.cacheWrite),
|
|
174
|
+
cost: numberFrom(value.cost),
|
|
175
|
+
contextTokens: numberFrom(value.contextTokens),
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function incrementCounter(target: Record<string, number>, key: string | undefined, amount = 1): void {
|
|
180
|
+
if (!key) return;
|
|
181
|
+
target[key] = (target[key] ?? 0) + amount;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function incrementUsageBucket(target: Record<string, { runs: number; cost: number; input: number; output: number; failures: number }>, key: string | undefined, usage: ChildResult["usage"], failed: boolean): void {
|
|
185
|
+
if (!key) return;
|
|
186
|
+
const bucket = target[key] ?? { runs: 0, cost: 0, input: 0, output: 0, failures: 0 };
|
|
187
|
+
bucket.runs += 1;
|
|
188
|
+
bucket.cost += usage.cost;
|
|
189
|
+
bucket.input += usage.input;
|
|
190
|
+
bucket.output += usage.output;
|
|
191
|
+
if (failed) bucket.failures += 1;
|
|
192
|
+
target[key] = bucket;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function telemetryRecordDate(record: Record<string, unknown>): string | undefined {
|
|
196
|
+
const startedAt = stringFrom(record.startedAt);
|
|
197
|
+
if (startedAt && /^\d{4}-\d{2}-\d{2}/.test(startedAt)) return startedAt.slice(0, 10);
|
|
198
|
+
const endedAt = stringFrom(record.endedAt);
|
|
199
|
+
if (endedAt && /^\d{4}-\d{2}-\d{2}/.test(endedAt)) return endedAt.slice(0, 10);
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function telemetryStatusFailed(record: Record<string, unknown>): boolean {
|
|
204
|
+
const status = stringFrom(record.status) ?? "unknown";
|
|
205
|
+
if (["failed", "failed_preflight", "failed_validation", "agentic_failed", "incomplete_or_failed", "unknown_agent"].includes(status)) return true;
|
|
206
|
+
const gate = isRecord(record.gate) ? record.gate : undefined;
|
|
207
|
+
return gate?.passed === false;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export function buildDailyTelemetrySummary(repoRoot: string, date?: string): Record<string, unknown> {
|
|
211
|
+
const day = normalizeDailyTelemetryDate(date);
|
|
212
|
+
const telemetryDir = join(repoRoot, ".pi", "logs", "telemetry");
|
|
213
|
+
const parseErrors: Array<{ file: string; error: string }> = [];
|
|
214
|
+
const records: Array<Record<string, unknown>> = [];
|
|
215
|
+
const runSummaries: Array<Record<string, unknown>> = [];
|
|
216
|
+
const statusCounts: Record<string, number> = {};
|
|
217
|
+
const schemaCounts: Record<string, number> = {};
|
|
218
|
+
const bySource: Record<string, number> = {};
|
|
219
|
+
const byAgent: Record<string, { runs: number; cost: number; input: number; output: number; failures: number }> = {};
|
|
220
|
+
const byModel: Record<string, { runs: number; cost: number; input: number; output: number; failures: number }> = {};
|
|
221
|
+
const byOutputContract: Record<string, { runs: number; cost: number; input: number; output: number; failures: number }> = {};
|
|
222
|
+
const byFactory: Record<string, { runs: number; cost: number; input: number; output: number; failures: number }> = {};
|
|
223
|
+
const failuresByStage: Record<string, number> = {};
|
|
224
|
+
const forbiddenTopLevelFields: Array<{ file: string; field: string }> = [];
|
|
225
|
+
const totals = {
|
|
226
|
+
runs: 0,
|
|
227
|
+
delegationRuns: 0,
|
|
228
|
+
factoryRuns: 0,
|
|
229
|
+
failures: 0,
|
|
230
|
+
gatePassed: 0,
|
|
231
|
+
gateFailed: 0,
|
|
232
|
+
gateErrors: 0,
|
|
233
|
+
turns: 0,
|
|
234
|
+
input: 0,
|
|
235
|
+
output: 0,
|
|
236
|
+
cacheRead: 0,
|
|
237
|
+
cacheWrite: 0,
|
|
238
|
+
contextTokens: 0,
|
|
239
|
+
cost: 0,
|
|
240
|
+
latencyMs: 0,
|
|
241
|
+
wallTimeMs: 0,
|
|
242
|
+
retries: 0,
|
|
243
|
+
itemsSelected: 0,
|
|
244
|
+
itemsProcessed: 0,
|
|
245
|
+
itemsFailed: 0,
|
|
246
|
+
artifactsGenerated: 0,
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const files = existsSync(telemetryDir) ? readdirSync(telemetryDir).filter((file) => file.endsWith(".json")).sort() : [];
|
|
250
|
+
for (const file of files) {
|
|
251
|
+
const path = join(telemetryDir, file);
|
|
252
|
+
let parsed: unknown;
|
|
253
|
+
try {
|
|
254
|
+
parsed = parseJsonFile(path);
|
|
255
|
+
} catch (error) {
|
|
256
|
+
parseErrors.push({ file, error: error instanceof Error ? error.message : String(error) });
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
if (!isRecord(parsed)) continue;
|
|
260
|
+
const schema = stringFrom(parsed.schema);
|
|
261
|
+
if (schema !== "zob.delegation-telemetry.v1" && schema !== "zob.factory-telemetry.v1") continue;
|
|
262
|
+
if (telemetryRecordDate(parsed) !== day) continue;
|
|
263
|
+
|
|
264
|
+
records.push(parsed);
|
|
265
|
+
const usage = usageFromRecord(parsed.usage);
|
|
266
|
+
const status = stringFrom(parsed.status) ?? "unknown";
|
|
267
|
+
const failed = telemetryStatusFailed(parsed);
|
|
268
|
+
const source = schema === "zob.factory-telemetry.v1" ? "factory_run" : stringFrom(parsed.source) ?? "delegation";
|
|
269
|
+
const gate = isRecord(parsed.gate) ? parsed.gate : undefined;
|
|
270
|
+
|
|
271
|
+
totals.runs += 1;
|
|
272
|
+
if (schema === "zob.delegation-telemetry.v1") totals.delegationRuns += 1;
|
|
273
|
+
if (schema === "zob.factory-telemetry.v1") totals.factoryRuns += 1;
|
|
274
|
+
if (failed) totals.failures += 1;
|
|
275
|
+
totals.turns += usage.turns;
|
|
276
|
+
totals.input += usage.input;
|
|
277
|
+
totals.output += usage.output;
|
|
278
|
+
totals.cacheRead += usage.cacheRead;
|
|
279
|
+
totals.cacheWrite += usage.cacheWrite;
|
|
280
|
+
totals.contextTokens = Math.max(totals.contextTokens, usage.contextTokens);
|
|
281
|
+
totals.cost += usage.cost;
|
|
282
|
+
totals.latencyMs += numberFrom(parsed.latencyMs);
|
|
283
|
+
totals.wallTimeMs += numberFrom(parsed.wallTimeMs);
|
|
284
|
+
|
|
285
|
+
if (gate) {
|
|
286
|
+
if (gate.passed === true) totals.gatePassed += 1;
|
|
287
|
+
if (gate.passed === false) totals.gateFailed += 1;
|
|
288
|
+
if (Array.isArray(gate.errors)) totals.gateErrors += gate.errors.length;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (schema === "zob.factory-telemetry.v1") {
|
|
292
|
+
const items = isRecord(parsed.items) ? parsed.items : {};
|
|
293
|
+
const artifacts = isRecord(parsed.artifacts) ? parsed.artifacts : {};
|
|
294
|
+
const retries = isRecord(parsed.retries) ? parsed.retries : {};
|
|
295
|
+
const stages = isRecord(parsed.stages) ? parsed.stages : {};
|
|
296
|
+
totals.itemsSelected += numberFrom(items.selected);
|
|
297
|
+
totals.itemsProcessed += numberFrom(items.processed);
|
|
298
|
+
totals.itemsFailed += numberFrom(items.failed);
|
|
299
|
+
totals.artifactsGenerated += numberFrom(artifacts.count);
|
|
300
|
+
totals.retries += numberFrom(retries.count);
|
|
301
|
+
const stageFailures = isRecord(stages.failuresByStage) ? stages.failuresByStage : {};
|
|
302
|
+
for (const [stage, count] of Object.entries(stageFailures)) incrementCounter(failuresByStage, stage, numberFrom(count));
|
|
303
|
+
incrementUsageBucket(byFactory, stringFrom(parsed.factory), usage, failed);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
incrementCounter(statusCounts, status);
|
|
307
|
+
incrementCounter(schemaCounts, schema);
|
|
308
|
+
incrementCounter(bySource, source);
|
|
309
|
+
incrementUsageBucket(byAgent, stringFrom(parsed.agent), usage, failed);
|
|
310
|
+
incrementUsageBucket(byModel, stringFrom(parsed.model), usage, failed);
|
|
311
|
+
incrementUsageBucket(byOutputContract, stringFrom(parsed.outputContract), usage, failed);
|
|
312
|
+
|
|
313
|
+
for (const field of ["task", "output", "prompt", "body"]) {
|
|
314
|
+
if (Object.prototype.hasOwnProperty.call(parsed, field)) forbiddenTopLevelFields.push({ file, field });
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
runSummaries.push({
|
|
318
|
+
file,
|
|
319
|
+
schema,
|
|
320
|
+
runId: stringFrom(parsed.runId),
|
|
321
|
+
source,
|
|
322
|
+
status,
|
|
323
|
+
agent: stringFrom(parsed.agent),
|
|
324
|
+
factory: stringFrom(parsed.factory),
|
|
325
|
+
model: stringFrom(parsed.model),
|
|
326
|
+
outputContract: stringFrom(parsed.outputContract),
|
|
327
|
+
cost: usage.cost,
|
|
328
|
+
input: usage.input,
|
|
329
|
+
outputTokens: usage.output,
|
|
330
|
+
failed,
|
|
331
|
+
startedAt: stringFrom(parsed.startedAt),
|
|
332
|
+
endedAt: stringFrom(parsed.endedAt),
|
|
333
|
+
latencyMs: numberFrom(parsed.latencyMs),
|
|
334
|
+
wallTimeMs: numberFrom(parsed.wallTimeMs),
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
return {
|
|
339
|
+
schema: "zob.telemetry-daily-summary.v1",
|
|
340
|
+
date: day,
|
|
341
|
+
generatedAt: new Date().toISOString(),
|
|
342
|
+
sourceDir: ".pi/logs/telemetry",
|
|
343
|
+
telemetryFiles: records.length,
|
|
344
|
+
totals,
|
|
345
|
+
statusCounts,
|
|
346
|
+
schemaCounts,
|
|
347
|
+
bySource,
|
|
348
|
+
byAgent,
|
|
349
|
+
byModel,
|
|
350
|
+
byOutputContract,
|
|
351
|
+
byFactory,
|
|
352
|
+
failuresByStage,
|
|
353
|
+
bodySafety: {
|
|
354
|
+
forbiddenTopLevelFieldsPresent: forbiddenTopLevelFields,
|
|
355
|
+
storesPromptOrOutputBodies: forbiddenTopLevelFields.length > 0,
|
|
356
|
+
},
|
|
357
|
+
budgetEnforced: false,
|
|
358
|
+
modelRouterUsed: false,
|
|
359
|
+
parseErrors,
|
|
360
|
+
runs: runSummaries,
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
export function writeDailyTelemetrySummary(repoRoot: string, date?: string): string {
|
|
365
|
+
const day = normalizeDailyTelemetryDate(date);
|
|
366
|
+
const dir = join(repoRoot, ".pi", "logs", "summaries");
|
|
367
|
+
mkdirSync(dir, { recursive: true });
|
|
368
|
+
const outputPath = join(dir, `${day}.json`);
|
|
369
|
+
writeFileSync(outputPath, JSON.stringify(buildDailyTelemetrySummary(repoRoot, day), null, 2), "utf8");
|
|
370
|
+
return outputPath;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export { addUsage, incrementCounter, normalizeDailyTelemetryDate, stringFrom, updateUsage, usageEmpty };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Scope du dossier
|
|
2
|
+
|
|
3
|
+
- Teams, orchestration profiles, chains et coms locales `.pi/coms`.
|
|
4
|
+
- Ce dossier gère les guards de topology et les messages hash-only.
|
|
5
|
+
|
|
6
|
+
# Invariants
|
|
7
|
+
|
|
8
|
+
- Préserver le topology guard et le blocage worker-to-worker.
|
|
9
|
+
- `chain_run` reste plan-only et read-only.
|
|
10
|
+
- Les coms restent hash-only: ne pas stocker les bodies de prompts ou outputs.
|
|
11
|
+
- Conserver la logique de status dérivé et le timeout max 5000ms pour await.
|
|
12
|
+
|
|
13
|
+
# Imports
|
|
14
|
+
|
|
15
|
+
- Peut importer types/constants/utils nécessaires depuis `src/**` avec suffixe `.js`.
|
|
16
|
+
- Interdit: importer depuis `index.ts`.
|
|
17
|
+
- Éviter dépendances runtime Pi directes; les tools runtime appellent ce domaine.
|
|
18
|
+
|
|
19
|
+
# Validation locale
|
|
20
|
+
|
|
21
|
+
- `npm run check -- --pretty false`.
|
|
22
|
+
- `npm run smoke:harness` après tout changement chains/coms/topology.
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { appendFileSync, existsSync, mkdirSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
import { loadProjectAgents } from "../agents.js";
|
|
5
|
+
import { BLOCKED_CHAIN_TOOLS, READ_ONLY_CHAIN_TOOLS } from "../constants.js";
|
|
6
|
+
import { validateOutputContractId } from "../output-contracts.js";
|
|
7
|
+
import { validateToolList } from "../safety.js";
|
|
8
|
+
import type { ChainDefinition, ChainRunInput, ChainRunResult, ChainStepDefinition } from "../types.js";
|
|
9
|
+
import { sha256 } from "../utils/hashing.js";
|
|
10
|
+
import { parseJsonFile } from "../utils/json.js";
|
|
11
|
+
import { isSafeArtifactName, safeFileStem, safeRunId } from "../utils/paths.js";
|
|
12
|
+
import { isRecord } from "../utils/records.js";
|
|
13
|
+
import { listZobResourceJsonStems, readableZobResourcePath } from "../utils/resources.js";
|
|
14
|
+
import { isStringArray } from "./teams.js";
|
|
15
|
+
|
|
16
|
+
function chainsDir(repoRoot: string): string {
|
|
17
|
+
return join(repoRoot, ".pi", "chains");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function listChainDefinitions(repoRoot: string): string[] {
|
|
21
|
+
return listZobResourceJsonStems(repoRoot, "chains");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function isChainStepDefinition(value: unknown): value is ChainStepDefinition {
|
|
25
|
+
return (
|
|
26
|
+
isRecord(value) &&
|
|
27
|
+
typeof value.id === "string" &&
|
|
28
|
+
typeof value.agent === "string" &&
|
|
29
|
+
typeof value.task === "string" &&
|
|
30
|
+
typeof value.expectedOutcome === "string" &&
|
|
31
|
+
isStringArray(value.requiredTools) &&
|
|
32
|
+
typeof value.outputContract === "string" &&
|
|
33
|
+
isStringArray(value.mustDo) &&
|
|
34
|
+
isStringArray(value.mustNotDo) &&
|
|
35
|
+
typeof value.context === "string"
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function isChainDefinition(value: unknown): value is ChainDefinition {
|
|
40
|
+
return (
|
|
41
|
+
isRecord(value) &&
|
|
42
|
+
typeof value.name === "string" &&
|
|
43
|
+
typeof value.version === "string" &&
|
|
44
|
+
typeof value.description === "string" &&
|
|
45
|
+
(value.readOnly === undefined || typeof value.readOnly === "boolean") &&
|
|
46
|
+
(value.defaultExecution === undefined || value.defaultExecution === "plan_only") &&
|
|
47
|
+
Array.isArray(value.steps) &&
|
|
48
|
+
value.steps.every(isChainStepDefinition)
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function loadChainDefinition(repoRoot: string, chainName: string): { definition?: ChainDefinition; chainPath: string; errors: string[] } {
|
|
53
|
+
if (!/^[a-zA-Z0-9._-]+$/.test(chainName)) return { chainPath: join(chainsDir(repoRoot), `${safeFileStem(chainName)}.json`), errors: [`Invalid chain name '${chainName}'`] };
|
|
54
|
+
const chainPath = readableZobResourcePath(repoRoot, "chains", `${chainName}.json`);
|
|
55
|
+
if (!existsSync(chainPath)) return { chainPath, errors: [`Chain definition not found: ${chainPath}`] };
|
|
56
|
+
try {
|
|
57
|
+
const parsed = parseJsonFile(chainPath);
|
|
58
|
+
if (!isChainDefinition(parsed)) return { chainPath, errors: [`Invalid chain definition: ${chainPath}`] };
|
|
59
|
+
if (parsed.name !== chainName) return { chainPath, errors: [`Chain definition name '${parsed.name}' does not match requested '${chainName}'`] };
|
|
60
|
+
return { definition: parsed, chainPath, errors: [] };
|
|
61
|
+
} catch (error) {
|
|
62
|
+
return { chainPath, errors: [`Could not parse chain definition '${chainPath}': ${error instanceof Error ? error.message : String(error)}`] };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function renderChainTemplate(template: string, values: Record<string, string>): string {
|
|
67
|
+
return template.replace(/\{([a-zA-Z0-9_]+)\}/g, (match, key) => values[key] ?? match);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function validateChainDefinition(repoRoot: string, definition: ChainDefinition | undefined): string[] {
|
|
71
|
+
const errors: string[] = [];
|
|
72
|
+
if (!definition) return ["Chain definition is missing"];
|
|
73
|
+
if (!isSafeArtifactName(definition.name)) errors.push(`Chain name must be path-safe: ${definition.name}`);
|
|
74
|
+
if (definition.readOnly === false) errors.push("Write-enabled chains are not supported without sandbox; only read-only chains may run");
|
|
75
|
+
if (definition.defaultExecution !== undefined && definition.defaultExecution !== "plan_only") errors.push("Chain defaultExecution must be plan_only");
|
|
76
|
+
if (definition.steps.length === 0) errors.push("Chain definition must include at least one step");
|
|
77
|
+
const agents = new Map(loadProjectAgents(repoRoot).map((agent) => [agent.name.toLowerCase(), agent]));
|
|
78
|
+
const ids = new Set<string>();
|
|
79
|
+
const readOnlyTools = new Set<string>(READ_ONLY_CHAIN_TOOLS);
|
|
80
|
+
const blockedTools = new Set<string>(BLOCKED_CHAIN_TOOLS);
|
|
81
|
+
|
|
82
|
+
for (const step of definition.steps) {
|
|
83
|
+
const label = `chain step '${step.id}'`;
|
|
84
|
+
if (ids.has(step.id)) errors.push(`Duplicate chain step id: ${step.id}`);
|
|
85
|
+
ids.add(step.id);
|
|
86
|
+
if (!isSafeArtifactName(step.id)) errors.push(`${label} id must be path-safe: ${step.id}`);
|
|
87
|
+
const agent = agents.get(step.agent.toLowerCase());
|
|
88
|
+
if (!agent) {
|
|
89
|
+
errors.push(`${label} references unknown agent '${step.agent}'`);
|
|
90
|
+
} else {
|
|
91
|
+
errors.push(...validateToolList(agent, step.requiredTools).map((error) => `${label}: ${error}`));
|
|
92
|
+
}
|
|
93
|
+
for (const tool of step.requiredTools) {
|
|
94
|
+
if (blockedTools.has(tool)) errors.push(`${label}: Tool '${tool}' is unsafe for read-only chain execution`);
|
|
95
|
+
if (!readOnlyTools.has(tool)) errors.push(`${label}: Tool '${tool}' is not in read-only chain allowlist (${READ_ONLY_CHAIN_TOOLS.join(", ")})`);
|
|
96
|
+
}
|
|
97
|
+
errors.push(...validateOutputContractId(step.outputContract).map((error) => `${label}: ${error}`));
|
|
98
|
+
}
|
|
99
|
+
return errors;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function validateChainRunInputs(repoRoot: string, input: ChainRunInput): string[] {
|
|
103
|
+
const errors: string[] = [];
|
|
104
|
+
if (!input.goal || input.goal.trim().length === 0) errors.push("goal is required");
|
|
105
|
+
if (input.run_id && safeFileStem(input.run_id) !== input.run_id) errors.push(`run_id must be path-safe: ${input.run_id}`);
|
|
106
|
+
if (input.execution !== undefined && input.execution !== "plan_only") errors.push("chain_run only supports execution=plan_only; write/live execution requires a future sandbox");
|
|
107
|
+
const loaded = loadChainDefinition(repoRoot, input.chain);
|
|
108
|
+
errors.push(...loaded.errors);
|
|
109
|
+
errors.push(...validateChainDefinition(repoRoot, loaded.definition));
|
|
110
|
+
return errors;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function buildChainPlan(repoRoot: string, definition: ChainDefinition, input: ChainRunInput, runId = safeRunId(input.run_id, "chain")): Record<string, unknown> {
|
|
114
|
+
const previousStepIds: string[] = [];
|
|
115
|
+
const originalUserAsk = input.original_user_ask ?? input.goal;
|
|
116
|
+
const tasks = definition.steps.map((step, index) => {
|
|
117
|
+
const values = { goal: input.goal, original_user_ask: originalUserAsk, chain: definition.name, step_id: step.id, previous_step_ids: previousStepIds.join(", ") || "none" };
|
|
118
|
+
const task = {
|
|
119
|
+
id: step.id,
|
|
120
|
+
sequence: index + 1,
|
|
121
|
+
agent: step.agent,
|
|
122
|
+
task: renderChainTemplate(step.task, values),
|
|
123
|
+
expected_outcome: renderChainTemplate(step.expectedOutcome, values),
|
|
124
|
+
required_tools: step.requiredTools,
|
|
125
|
+
must_do: step.mustDo.map((item) => renderChainTemplate(item, values)),
|
|
126
|
+
must_not_do: step.mustNotDo.map((item) => renderChainTemplate(item, values)),
|
|
127
|
+
context: renderChainTemplate(step.context, values),
|
|
128
|
+
output_contract: step.outputContract,
|
|
129
|
+
run_in_background: false,
|
|
130
|
+
load_skills: [],
|
|
131
|
+
};
|
|
132
|
+
previousStepIds.push(step.id);
|
|
133
|
+
return task;
|
|
134
|
+
});
|
|
135
|
+
return {
|
|
136
|
+
schema: "zob.chain-plan.v1",
|
|
137
|
+
chain: definition.name,
|
|
138
|
+
version: definition.version,
|
|
139
|
+
runId,
|
|
140
|
+
execution: "plan_only",
|
|
141
|
+
readOnly: definition.readOnly !== false,
|
|
142
|
+
noExecution: true,
|
|
143
|
+
liveChildExecution: false,
|
|
144
|
+
budgetEnforced: false,
|
|
145
|
+
modelRouterUsed: false,
|
|
146
|
+
blockedTools: [...BLOCKED_CHAIN_TOOLS],
|
|
147
|
+
allowedTools: [...READ_ONLY_CHAIN_TOOLS],
|
|
148
|
+
invariants: {
|
|
149
|
+
contractFirst: true,
|
|
150
|
+
delegateTaskShaped: true,
|
|
151
|
+
promptBodiesStored: false,
|
|
152
|
+
outputBodiesStored: false,
|
|
153
|
+
sentinelWritten: false,
|
|
154
|
+
mandatoryBudgetGate: false,
|
|
155
|
+
},
|
|
156
|
+
tasks,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function runChainPlanOnly(repoRoot: string, input: ChainRunInput): ChainRunResult {
|
|
161
|
+
const errors = validateChainRunInputs(repoRoot, input);
|
|
162
|
+
const runId = safeRunId(input.run_id, "chain");
|
|
163
|
+
const runDir = join(repoRoot, "reports", "chains", runId);
|
|
164
|
+
if (existsSync(runDir) && !input.resume) errors.push(`Chain run directory already exists. Use resume=true or choose another run_id: ${runDir}`);
|
|
165
|
+
const loaded = loadChainDefinition(repoRoot, input.chain);
|
|
166
|
+
if (errors.length > 0 || !loaded.definition) return { runId, runDir, status: "failed_preflight", chain: input.chain, steps: 0, artifacts: [], errors };
|
|
167
|
+
|
|
168
|
+
mkdirSync(runDir, { recursive: true });
|
|
169
|
+
const sentinelPath = join(runDir, "DONE.sentinel");
|
|
170
|
+
if (existsSync(sentinelPath)) unlinkSync(sentinelPath);
|
|
171
|
+
const plan = buildChainPlan(repoRoot, loaded.definition, input, runId);
|
|
172
|
+
const tasks = Array.isArray(plan.tasks) ? plan.tasks : [];
|
|
173
|
+
const artifacts = ["manifest.json", "ledger.jsonl", "chain-plan.json", "status.jsonl", "validation.json", "final-report.md"];
|
|
174
|
+
const manifest = {
|
|
175
|
+
schema: "zob.chain-run-manifest.v1",
|
|
176
|
+
runId,
|
|
177
|
+
chain: loaded.definition.name,
|
|
178
|
+
chainPath: loaded.chainPath,
|
|
179
|
+
execution: "plan_only",
|
|
180
|
+
readOnly: true,
|
|
181
|
+
noExecution: true,
|
|
182
|
+
goalHash: sha256(input.goal),
|
|
183
|
+
originalUserAskHash: sha256(input.original_user_ask ?? input.goal),
|
|
184
|
+
steps: tasks.length,
|
|
185
|
+
createdAt: new Date().toISOString(),
|
|
186
|
+
budgetEnforced: false,
|
|
187
|
+
mandatoryBudgetGate: false,
|
|
188
|
+
};
|
|
189
|
+
writeFileSync(join(runDir, "manifest.json"), JSON.stringify(manifest, null, 2), "utf8");
|
|
190
|
+
writeFileSync(join(runDir, "chain-plan.json"), JSON.stringify(plan, null, 2), "utf8");
|
|
191
|
+
const statusLines = tasks.map((task) => {
|
|
192
|
+
const record = isRecord(task) ? task : {};
|
|
193
|
+
return JSON.stringify({
|
|
194
|
+
schema: "zob.chain-status.v1",
|
|
195
|
+
runId,
|
|
196
|
+
chain: loaded.definition?.name,
|
|
197
|
+
stepId: record.id,
|
|
198
|
+
sequence: record.sequence,
|
|
199
|
+
agent: record.agent,
|
|
200
|
+
outputContract: record.output_contract,
|
|
201
|
+
status: "planned",
|
|
202
|
+
noExecution: true,
|
|
203
|
+
running: false,
|
|
204
|
+
taskHash: sha256(JSON.stringify(record)),
|
|
205
|
+
outputHash: null,
|
|
206
|
+
bodyStored: false,
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
writeFileSync(join(runDir, "status.jsonl"), `${statusLines.join("\n")}\n`, "utf8");
|
|
210
|
+
appendFileSync(join(runDir, "ledger.jsonl"), `${JSON.stringify({ schema: "zob.chain-ledger.v1", event: "planned", runId, chain: loaded.definition.name, steps: tasks.length, noExecution: true, sentinel: "not written", promptBodiesStored: false, outputBodiesStored: false, budgetEnforced: false, mandatoryBudgetGate: false })}\n`, "utf8");
|
|
211
|
+
writeFileSync(join(runDir, "final-report.md"), [`# Chain Run Report`, ``, `- runId: ${runId}`, `- chain: ${loaded.definition.name}`, `- status: planned`, `- execution: plan_only`, `- steps: ${tasks.length}`, `- child_agents_executed: no`, `- read_only: yes`, `- sentinel: not written`, ``].join("\n"), "utf8");
|
|
212
|
+
const validation = {
|
|
213
|
+
schema: "zob.chain-validation.v1",
|
|
214
|
+
runId,
|
|
215
|
+
chain: loaded.definition.name,
|
|
216
|
+
status: "planned",
|
|
217
|
+
execution: "plan_only",
|
|
218
|
+
readOnly: true,
|
|
219
|
+
noExecution: true,
|
|
220
|
+
liveChildExecution: false,
|
|
221
|
+
steps: tasks.length,
|
|
222
|
+
allowedTools: [...READ_ONLY_CHAIN_TOOLS],
|
|
223
|
+
blockedTools: [...BLOCKED_CHAIN_TOOLS],
|
|
224
|
+
artifactsPresent: artifacts.map((artifact) => ({ artifact, exists: artifact === "validation.json" ? true : existsSync(join(runDir, artifact)) })),
|
|
225
|
+
sentinelWritten: existsSync(sentinelPath),
|
|
226
|
+
budgetEnforced: false,
|
|
227
|
+
mandatoryBudgetGate: false,
|
|
228
|
+
promptBodiesStored: false,
|
|
229
|
+
outputBodiesStored: false,
|
|
230
|
+
errors: [],
|
|
231
|
+
};
|
|
232
|
+
writeFileSync(join(runDir, "validation.json"), JSON.stringify(validation, null, 2), "utf8");
|
|
233
|
+
return { runId, runDir, status: "planned", chain: loaded.definition.name, steps: tasks.length, artifacts, errors: [] };
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export { renderChainTemplate };
|