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,108 @@
|
|
|
1
|
+
import type { DamageRules, ModeName } from "./types.js";
|
|
2
|
+
|
|
3
|
+
const DEFAULT_RULES: DamageRules = {
|
|
4
|
+
bashToolPatterns: [
|
|
5
|
+
{ pattern: "\\brm\\s+(-rf?|--recursive)", reason: "recursive deletion" },
|
|
6
|
+
{ pattern: "\\bgit\\s+reset\\s+--hard\\b", reason: "destructive git reset" },
|
|
7
|
+
{ pattern: "\\bgit\\s+clean\\s+-", reason: "destructive git clean" },
|
|
8
|
+
{ pattern: "\\bgit\\s+add\\s+(-A|\\.)", reason: "bulk git staging" },
|
|
9
|
+
{ pattern: "\\bsudo\\b", reason: "privileged command", ask: true },
|
|
10
|
+
],
|
|
11
|
+
zeroAccessPaths: [".env", ".env.*", "~/.ssh", "~/.aws", "*.pem", "*.key"],
|
|
12
|
+
readOnlyPaths: [".git/", "node_modules/", "dist/", "build/", "package-lock.json", "pnpm-lock.yaml", "bun.lock"],
|
|
13
|
+
noDeletePaths: [".git/", "AGENTS.md", "README.md", ".pi/"],
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { DEFAULT_RULES };
|
|
17
|
+
|
|
18
|
+
export const ZOB_TOOL_ROUTING_CONTRACT = [
|
|
19
|
+
"ZOB TOOL ROUTING CONTRACT",
|
|
20
|
+
"- For non-trivial or tool-ambiguous work, run a lightweight routing loop before acting.",
|
|
21
|
+
"- Classify applicable families: goal/TODO, delegation, orchestration, compute, context/ProjectDNA, factory, coms/goal-room, workspace/merge, autonomous-runtime, oracle.",
|
|
22
|
+
"- Load .pi/skills/zob-tool-router/SKILL.md when routing is uncertain or work spans multiple families; then load the domain skill(s) named by the registry.",
|
|
23
|
+
"- Use the smallest sufficient tool set: use, delegate, or explicitly skip applicable families with a reason.",
|
|
24
|
+
"- Do not bypass mode/tool safety, approval, sandbox, budget, evidence, or oracle gates.",
|
|
25
|
+
].join("\n");
|
|
26
|
+
|
|
27
|
+
export const ZOB_COMPACTION_CONTINUITY_CONTRACT = [
|
|
28
|
+
"ZOB COMPACTION CONTINUITY CONTRACT",
|
|
29
|
+
"- After compaction, trust persisted goal/TODO/evidence state and cited artifacts over memory or summary prose.",
|
|
30
|
+
"- Reload critical skills/docs/files by path when detailed behavior or edits depend on them; compaction keeps refs, not full bodies.",
|
|
31
|
+
"- Do not assume compacted tool outputs preserve all details; validate from commands, ledgers, reports, or safe file refs before completion.",
|
|
32
|
+
"- Preserve blockers/no_ship/next action across compaction; if unclear, inspect live state or block instead of claiming done.",
|
|
33
|
+
].join("\n");
|
|
34
|
+
|
|
35
|
+
export const SUPERVISED_SMOKE_CHILD_TOOLS = ["read", "grep", "find", "ls"] as const;
|
|
36
|
+
export const SUPERVISED_READONLY_CHILD_TOOLS = ["read", "grep", "find", "ls"] as const;
|
|
37
|
+
export const READ_ONLY_CHAIN_TOOLS = ["read", "grep", "find", "ls"] as const;
|
|
38
|
+
export const BLOCKED_CHAIN_TOOLS = ["bash", "edit", "write", "delegate_agent", "delegate_task", "orchestrate_run", "factory_run", "factory_quarantine_review", "factory_quarantine_activate", "factory_quarantine_verify_activation", "chain_run"] as const;
|
|
39
|
+
|
|
40
|
+
export const ZOB_COMS_TOOLS = ["zob_coms_send", "zob_coms_ack", "zob_coms_status", "zob_coms_reply", "zob_coms_list", "zob_coms_get", "zob_coms_await", "zpeer_ask"] as const;
|
|
41
|
+
export const ZOB_GOAL_ROOM_TOOLS = ["zob_goal_room_send", "zob_goal_room_list"] as const;
|
|
42
|
+
export const ZOB_GOVERNED_REQUEST_TOOLS = ["zob_governed_request_extract"] as const;
|
|
43
|
+
export const ZOB_WORKSPACE_CLAIM_TOOLS = ["zob_workspace_claim", "zob_workspace_release", "zob_workspace_claims_list"] as const;
|
|
44
|
+
export const ZOB_WORKER_POOL_TOOLS = ["zob_worker_pool_plan", "zob_worker_pool_status", "zob_worker_pool_owner_request", "zob_worker_pool_owner_decision"] as const;
|
|
45
|
+
export const ZOB_MERGE_QUEUE_TOOLS = ["zob_merge_candidate_submit", "zob_merge_queue_decide", "zob_merge_queue_list"] as const;
|
|
46
|
+
export const ZOB_ZCOMMIT_TOOLS = ["zob_zcommit_run"] as const;
|
|
47
|
+
export const ZOB_DELEGATION_READ_TOOLS = ["zob_delegation_catalog", "get_delegation_run", "await_delegation_run"] as const;
|
|
48
|
+
export const ZOB_MISSION_CONTROL_READ_TOOLS = ["zob_coms_readiness", "zob_mission_control_snapshot"] as const;
|
|
49
|
+
export const ZOB_MISSION_CONTROL_PROPOSAL_TOOLS = ["zob_mission_control_propose_command"] as const;
|
|
50
|
+
export const ZOB_CONTEXT_READ_TOOLS = ["zob_context_readiness", "zob_context_validate_scope"] as const;
|
|
51
|
+
export const ZOB_CONTEXT_PROPOSAL_TOOLS = ["zob_context_writeback_proposal"] as const;
|
|
52
|
+
export const ZOB_COMPUTE_READ_TOOLS = ["zob_compute_preview", "zob_compute_resolve_profile", "zob_compute_plan_workflow", "zob_compute_validate_profile"] as const;
|
|
53
|
+
export const ZOB_COMPUTE_REPORT_TOOLS = ["zob_compute_write_profile_reports"] as const;
|
|
54
|
+
export const ZOB_PROJECT_DNA_READ_TOOLS = ["zob_project_dna_readiness", "zob_project_dna_plan_workflow", "zob_project_dna_query", "zob_project_dna_federated_query"] as const;
|
|
55
|
+
export const ZOB_PROJECT_DNA_PROPOSAL_TOOLS = ["zob_project_dna_writeback_proposal"] as const;
|
|
56
|
+
export const ZOB_RUNTIME_GOAL_TOOLS = ["get_goal", "get_goal_todos", "add_goal_todo", "add_goal_todos", "update_goal_todo", "resolve_goal_todo", "complete_goal_todo", "block_goal_todo", "split_goal_todo", "validate_goal_todo_claim", "accept_goal_todo_claim", "reject_goal_todo_claim", "import_factory_todos", "import_orchestration_todos", "import_chain_todos", "create_goal", "resume_goal", "propose_goal_completion", "record_goal_oracle", "update_goal"] as const;
|
|
57
|
+
export const ZOB_AUTONOMOUS_READ_TOOLS = ["zob_autonomous_validate_run", "zob_autonomous_validate_smoke"] as const;
|
|
58
|
+
export const ZOB_AUTONOMOUS_FACTORY_TOOLS = ["zob_autonomous_dry_run", "zob_autonomous_readonly_smoke"] as const;
|
|
59
|
+
|
|
60
|
+
export const MODE_TOOLS: Record<ModeName, string[]> = {
|
|
61
|
+
explore: ["read", "grep", "find", "ls", "bash", "delegate_agent", "delegate_task", "zob_coms_list", "zob_coms_get", "zob_coms_await", "zpeer_ask", "zob_goal_room_list", "zob_workspace_claims_list", "zob_worker_pool_status", "zob_merge_queue_list", ...ZOB_RUNTIME_GOAL_TOOLS, ...ZOB_DELEGATION_READ_TOOLS, ...ZOB_ZCOMMIT_TOOLS, ...ZOB_AUTONOMOUS_READ_TOOLS, ...ZOB_MISSION_CONTROL_READ_TOOLS, ...ZOB_CONTEXT_READ_TOOLS, ...ZOB_COMPUTE_READ_TOOLS, ...ZOB_PROJECT_DNA_READ_TOOLS],
|
|
62
|
+
plan: ["read", "grep", "find", "ls", "delegate_agent", "delegate_task", "orchestrate_run", "chain_run", ...ZOB_RUNTIME_GOAL_TOOLS, ...ZOB_DELEGATION_READ_TOOLS, ...ZOB_ZCOMMIT_TOOLS, ...ZOB_COMS_TOOLS, ...ZOB_GOAL_ROOM_TOOLS, ...ZOB_GOVERNED_REQUEST_TOOLS, ...ZOB_WORKSPACE_CLAIM_TOOLS, ...ZOB_WORKER_POOL_TOOLS, ...ZOB_MERGE_QUEUE_TOOLS, ...ZOB_MISSION_CONTROL_READ_TOOLS, ...ZOB_MISSION_CONTROL_PROPOSAL_TOOLS, ...ZOB_CONTEXT_READ_TOOLS, ...ZOB_CONTEXT_PROPOSAL_TOOLS, ...ZOB_COMPUTE_READ_TOOLS, ...ZOB_COMPUTE_REPORT_TOOLS, ...ZOB_PROJECT_DNA_READ_TOOLS, ...ZOB_PROJECT_DNA_PROPOSAL_TOOLS],
|
|
63
|
+
implement: ["read", "bash", "edit", "write", "grep", "find", "ls", "delegate_agent", "delegate_task", ...ZOB_RUNTIME_GOAL_TOOLS, ...ZOB_DELEGATION_READ_TOOLS, ...ZOB_ZCOMMIT_TOOLS, ...ZOB_COMS_TOOLS, ...ZOB_GOAL_ROOM_TOOLS, ...ZOB_GOVERNED_REQUEST_TOOLS, ...ZOB_WORKSPACE_CLAIM_TOOLS, ...ZOB_WORKER_POOL_TOOLS, ...ZOB_MERGE_QUEUE_TOOLS, ...ZOB_MISSION_CONTROL_READ_TOOLS, ...ZOB_MISSION_CONTROL_PROPOSAL_TOOLS, ...ZOB_CONTEXT_READ_TOOLS, ...ZOB_CONTEXT_PROPOSAL_TOOLS, ...ZOB_COMPUTE_READ_TOOLS, ...ZOB_COMPUTE_REPORT_TOOLS, ...ZOB_PROJECT_DNA_READ_TOOLS, ...ZOB_PROJECT_DNA_PROPOSAL_TOOLS],
|
|
64
|
+
oracle: ["read", "grep", "find", "ls", "bash", "delegate_agent", "delegate_task", "zob_coms_list", "zob_coms_get", "zob_coms_await", "zpeer_ask", "zob_goal_room_list", "zob_workspace_claims_list", "zob_worker_pool_status", "zob_merge_queue_list", ...ZOB_RUNTIME_GOAL_TOOLS, ...ZOB_DELEGATION_READ_TOOLS, ...ZOB_ZCOMMIT_TOOLS, ...ZOB_AUTONOMOUS_READ_TOOLS, ...ZOB_MISSION_CONTROL_READ_TOOLS, ...ZOB_CONTEXT_READ_TOOLS, ...ZOB_COMPUTE_READ_TOOLS, ...ZOB_PROJECT_DNA_READ_TOOLS],
|
|
65
|
+
orchestrator: ["read", "grep", "find", "ls", "delegate_agent", "delegate_task", "orchestrate_run", "chain_run", ...ZOB_RUNTIME_GOAL_TOOLS, ...ZOB_DELEGATION_READ_TOOLS, ...ZOB_ZCOMMIT_TOOLS, ...ZOB_COMS_TOOLS, ...ZOB_GOAL_ROOM_TOOLS, ...ZOB_GOVERNED_REQUEST_TOOLS, ...ZOB_WORKSPACE_CLAIM_TOOLS, ...ZOB_WORKER_POOL_TOOLS, ...ZOB_MERGE_QUEUE_TOOLS, ...ZOB_MISSION_CONTROL_READ_TOOLS, ...ZOB_MISSION_CONTROL_PROPOSAL_TOOLS, ...ZOB_CONTEXT_READ_TOOLS, ...ZOB_CONTEXT_PROPOSAL_TOOLS, ...ZOB_COMPUTE_READ_TOOLS, ...ZOB_COMPUTE_REPORT_TOOLS],
|
|
66
|
+
factory: ["read", "bash", "edit", "write", "grep", "find", "ls", "delegate_agent", "delegate_task", "orchestrate_run", "factory_run", "factory_quarantine_review", "factory_quarantine_activate", "factory_quarantine_verify_activation", "chain_run", ...ZOB_RUNTIME_GOAL_TOOLS, ...ZOB_DELEGATION_READ_TOOLS, ...ZOB_ZCOMMIT_TOOLS, ...ZOB_AUTONOMOUS_READ_TOOLS, ...ZOB_AUTONOMOUS_FACTORY_TOOLS, ...ZOB_COMS_TOOLS, ...ZOB_GOAL_ROOM_TOOLS, ...ZOB_GOVERNED_REQUEST_TOOLS, ...ZOB_WORKSPACE_CLAIM_TOOLS, ...ZOB_WORKER_POOL_TOOLS, ...ZOB_MERGE_QUEUE_TOOLS, ...ZOB_MISSION_CONTROL_READ_TOOLS, ...ZOB_MISSION_CONTROL_PROPOSAL_TOOLS, ...ZOB_CONTEXT_READ_TOOLS, ...ZOB_CONTEXT_PROPOSAL_TOOLS, ...ZOB_COMPUTE_READ_TOOLS, ...ZOB_COMPUTE_REPORT_TOOLS, ...ZOB_PROJECT_DNA_READ_TOOLS, ...ZOB_PROJECT_DNA_PROPOSAL_TOOLS],
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export const MODE_PROMPTS: Record<ModeName, string> = {
|
|
70
|
+
explore: `ZOB MODE: EXPLORE (read-only reconnaissance)
|
|
71
|
+
- Start with: Literal Request / Actual Need / Success Looks Like.
|
|
72
|
+
- Use read/grep/find/ls and safe read-only bash only.
|
|
73
|
+
- Return <files>, <answer>, <next_steps>. Mirror every numbered user question.
|
|
74
|
+
- Do not edit files. If a write is required, propose the smallest follow-up implement task.`,
|
|
75
|
+
plan: `ZOB MODE: PLAN (factory planning)
|
|
76
|
+
- No edits, no commits, no broad test runs.
|
|
77
|
+
- For non-trivial or tool-ambiguous plans, apply the ZOB tool-routing contract and state which families are in/out before detailed steps.
|
|
78
|
+
- Produce scope table, likely files, TDD sequence, validation ladder, atomic commit plan, risks, and stop conditions.
|
|
79
|
+
- Consume prior explore outputs before re-reading. Avoid duplicate discovery.
|
|
80
|
+
- Single-plan rule: if the immediately previous assistant response already provided a complete plan for the same request, do not restate it; summarize that the plan is already provided and offer to refine, save, or implement it.
|
|
81
|
+
- If auto-mode switched to plan after a short handoff, produce the deferred plan once and do not request plan mode again.`,
|
|
82
|
+
implement: `ZOB MODE: IMPLEMENT (bounded build)
|
|
83
|
+
- Before editing, state a sufficiency verdict: sufficient/no-change or exact gap + smallest file set.
|
|
84
|
+
- For non-trivial or tool-ambiguous slices, apply the ZOB tool-routing contract but avoid unnecessary delegation/compute/coms for small edits.
|
|
85
|
+
- Make surgical edits only. Prefer edit over write for existing files.
|
|
86
|
+
- Use edit/write for file changes; do not mutate repo files through bash/python/perl/node patch scripts unless the user explicitly approves that fallback.
|
|
87
|
+
- Verify in ladder order: touched-file diagnostics or static checks -> smallest targeted test -> affected package build/typecheck when justified.
|
|
88
|
+
- End with commands/results and explicit MUST NOT compliance. No commits unless the user asks.`,
|
|
89
|
+
oracle: `ZOB MODE: ORACLE (skeptical verdict)
|
|
90
|
+
- Read-only verification. Lead with PASS / FAIL / WARN and confidence.
|
|
91
|
+
- Cite file paths, commands, logs, or exact missing evidence.
|
|
92
|
+
- Separate blockers from non-blocking notes. Do not patch.`,
|
|
93
|
+
orchestrator: `ZOB MODE: ORCHESTRATOR (Chief Vision non-coding)
|
|
94
|
+
- Root role: govern goals, TODOs, work graphs, routing, parent-owned delegation, evidence, blockers, and completion gates.
|
|
95
|
+
- Apply the ZOB tool-routing contract before building the workgraph: classify families, load relevant domain skills, and use/delegate/skip each with a reason.
|
|
96
|
+
- Do not code directly: no edit/write/patch/commit and no destructive shell; do not perform worker implementation yourself.
|
|
97
|
+
- For any substantive exploration, implementation, QA, security review, documentation production, or oracle judgment, create or delegate a bounded subtask instead of doing the work yourself.
|
|
98
|
+
- You may perform only lightweight coordination, TODO/goal metadata management, synthesis of returned evidence, blocker decisions, and user clarification.
|
|
99
|
+
- Use delegate_task/delegate_agent for bounded specialist subtasks and prefer orchestrate_run for multi-agent Lead/Worker decomposition; default orchestration execution=plan_only unless explicit parent/oracle gates allow supervised_readonly.
|
|
100
|
+
- Use goal/TODO graph, compute profile, context scopes, chain_run plan_only, goal-room/coms metadata, Mission Control proposals, and oracle gates to coordinate.
|
|
101
|
+
- Do not treat planned orchestration as completed implementation work.
|
|
102
|
+
- Completion requires evidence, validation, oracle PASS, and no_ship=false.`,
|
|
103
|
+
factory: `ZOB MODE: FACTORY (build the system that builds the system)
|
|
104
|
+
- Apply the ZOB tool-routing contract for repeatability/autonomy/context/oracle questions before designing the pipeline.
|
|
105
|
+
- Turn repeated work into reusable prompts, agents, scripts, schemas, or Pi extensions.
|
|
106
|
+
- Prefer deterministic scaffolding for immutable content; let LLMs enrich structured sections only.
|
|
107
|
+
- Require sentinel/completion artifacts and validation before scale-up.`,
|
|
108
|
+
};
|
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
import { sha256 } from "./utils/hashing.js";
|
|
5
|
+
import { safeFileStem } from "./utils/paths.js";
|
|
6
|
+
import { isRecord } from "./utils/records.js";
|
|
7
|
+
|
|
8
|
+
const FORBIDDEN_CONTEXT_BODY_KEYS = new Set(["body", "task", "prompt", "output", "content", "message", "diff", "patch", "rawConversation", "conversationHistory"]);
|
|
9
|
+
const CONTEXT_SCOPE_MAX_TOKENS_CAP = 8000;
|
|
10
|
+
|
|
11
|
+
export interface ContextScopeInput {
|
|
12
|
+
scopeId?: string;
|
|
13
|
+
runId: string;
|
|
14
|
+
todoId?: string;
|
|
15
|
+
allowedBrains?: string[];
|
|
16
|
+
allowedSources?: string[];
|
|
17
|
+
forbiddenSources?: string[];
|
|
18
|
+
agentProfile?: string;
|
|
19
|
+
maxContextTokens?: number;
|
|
20
|
+
freshnessPolicy?: string;
|
|
21
|
+
readPolicy?: string;
|
|
22
|
+
writePolicy?: string;
|
|
23
|
+
citationRequired?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ContextLookupInput {
|
|
27
|
+
lookupId?: string;
|
|
28
|
+
scope: Record<string, unknown>;
|
|
29
|
+
brainId: string;
|
|
30
|
+
sourceId: string;
|
|
31
|
+
queryHash: string;
|
|
32
|
+
facts?: Array<Record<string, unknown>>;
|
|
33
|
+
patterns?: Array<Record<string, unknown>>;
|
|
34
|
+
gaps?: Array<Record<string, unknown>>;
|
|
35
|
+
freshness?: string;
|
|
36
|
+
confidence?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface ContextWritebackProposalInput {
|
|
40
|
+
proposalId?: string;
|
|
41
|
+
runId: string;
|
|
42
|
+
observedProblemHash: string;
|
|
43
|
+
newPatternHash: string;
|
|
44
|
+
evidenceRefs: string[];
|
|
45
|
+
recommendedArtifact: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function hasForbiddenContextBodyKey(value: unknown): boolean {
|
|
49
|
+
if (!value || typeof value !== "object") return false;
|
|
50
|
+
if (Array.isArray(value)) return value.some(hasForbiddenContextBodyKey);
|
|
51
|
+
return Object.entries(value).some(([key, child]) => FORBIDDEN_CONTEXT_BODY_KEYS.has(key) || hasForbiddenContextBodyKey(child));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function isHexSha256(value: unknown): boolean {
|
|
55
|
+
return typeof value === "string" && /^[a-f0-9]{64}$/i.test(value);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function isSafeSourceRef(value: string): boolean {
|
|
59
|
+
if (!value || value.startsWith("/") || value.includes("\\") || value.includes("..")) return false;
|
|
60
|
+
if (value === ".env" || value.startsWith(".env.") || value.includes("/.env")) return false;
|
|
61
|
+
if (value.includes("node_modules/") || value.includes("dist/") || value.includes("build/")) return false;
|
|
62
|
+
if (value.endsWith(".pem") || value.endsWith(".key")) return false;
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function uniqueSorted(values: string[]): string[] {
|
|
67
|
+
return [...new Set(values)].sort();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function stringArray(value: unknown): string[] {
|
|
71
|
+
return Array.isArray(value) ? value.filter((item): item is string => typeof item === "string" && item.length > 0) : [];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function isCitation(value: unknown): boolean {
|
|
75
|
+
if (typeof value === "string") return value.includes(":") || value.startsWith("docs/") || value.startsWith(".pi/") || value.startsWith("reports/");
|
|
76
|
+
if (!isRecord(value)) return false;
|
|
77
|
+
const ref = value.ref;
|
|
78
|
+
const sourceId = value.sourceId;
|
|
79
|
+
const path = value.path;
|
|
80
|
+
return (typeof ref === "string" && ref.length > 0) || (typeof sourceId === "string" && typeof path === "string" && isSafeSourceRef(path));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function entriesHaveCitations(entries: unknown): boolean {
|
|
84
|
+
if (!Array.isArray(entries)) return true;
|
|
85
|
+
return entries.every((entry) => {
|
|
86
|
+
if (!isRecord(entry)) return false;
|
|
87
|
+
const citations = Array.isArray(entry.citations) ? entry.citations : (entry.citation ? [entry.citation] : []);
|
|
88
|
+
return citations.length > 0 && citations.every(isCitation);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function sourceMap(registry: Record<string, unknown>): Map<string, Record<string, unknown>> {
|
|
93
|
+
const sources = Array.isArray(registry.sources) ? registry.sources.filter(isRecord) : [];
|
|
94
|
+
return new Map(sources.map((source) => [String(source.sourceId), source]));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function brainSet(registry: Record<string, unknown>): Set<string> {
|
|
98
|
+
const brains = Array.isArray(registry.brains) ? registry.brains.filter(isRecord) : [];
|
|
99
|
+
return new Set(brains.map((brain) => String(brain.brainId)));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function buildContextBrainSourceRegistry(repoRoot: string): Record<string, unknown> {
|
|
103
|
+
const sources = [
|
|
104
|
+
{
|
|
105
|
+
brainId: "harness-system",
|
|
106
|
+
sourceId: "zob-harness-src",
|
|
107
|
+
domain: "harness/system brain",
|
|
108
|
+
owner: "zob-harness",
|
|
109
|
+
sourceRoot: ".pi/extensions/zob-harness/src",
|
|
110
|
+
gbrainSourceId: null,
|
|
111
|
+
allowedAgents: ["planner", "explore", "oracle", "context-steward", "factory"],
|
|
112
|
+
readPolicy: "repo_local_metadata_only",
|
|
113
|
+
writePolicy: "proposal_only",
|
|
114
|
+
freshnessPolicy: "current_source_required",
|
|
115
|
+
noShipRules: ["citation_required", "context_scope_required", "no_raw_bodies"],
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
brainId: "harness-system",
|
|
119
|
+
sourceId: "zob-harness-docs",
|
|
120
|
+
domain: "harness/system brain",
|
|
121
|
+
owner: "zob-harness",
|
|
122
|
+
sourceRoot: "docs",
|
|
123
|
+
gbrainSourceId: null,
|
|
124
|
+
allowedAgents: ["planner", "explore", "oracle", "context-steward", "factory"],
|
|
125
|
+
readPolicy: "repo_local_metadata_only",
|
|
126
|
+
writePolicy: "proposal_only",
|
|
127
|
+
freshnessPolicy: "current_source_required",
|
|
128
|
+
noShipRules: ["citation_required", "context_scope_required", "no_raw_bodies"],
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
brainId: "factory-evidence",
|
|
132
|
+
sourceId: "factory-run-reports",
|
|
133
|
+
domain: "factory-evidence brain",
|
|
134
|
+
owner: "zob-harness",
|
|
135
|
+
sourceRoot: "reports/factory-runs",
|
|
136
|
+
gbrainSourceId: null,
|
|
137
|
+
allowedAgents: ["oracle", "context-steward", "factory"],
|
|
138
|
+
readPolicy: "validated_summaries_only",
|
|
139
|
+
writePolicy: "proposal_only",
|
|
140
|
+
freshnessPolicy: "current_run_validation_required",
|
|
141
|
+
noShipRules: ["citation_required", "sentinel_or_validation_required", "no_raw_outputs"],
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
brainId: "conversation-chronicle",
|
|
145
|
+
sourceId: "redacted-chronicle-summaries",
|
|
146
|
+
domain: "conversation/chronicle brain",
|
|
147
|
+
owner: "zob-harness",
|
|
148
|
+
sourceRoot: ".pi/logs/summaries",
|
|
149
|
+
gbrainSourceId: null,
|
|
150
|
+
allowedAgents: ["planner", "context-steward", "oracle"],
|
|
151
|
+
readPolicy: "redacted_summaries_only",
|
|
152
|
+
writePolicy: "proposal_only",
|
|
153
|
+
freshnessPolicy: "summary_hash_required",
|
|
154
|
+
noShipRules: ["no_raw_conversation_history", "citation_required"],
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
brainId: "learning-patterns",
|
|
158
|
+
sourceId: "writeback-proposals",
|
|
159
|
+
domain: "learning/pattern brain",
|
|
160
|
+
owner: "zob-harness",
|
|
161
|
+
sourceRoot: ".pi/context/writeback-proposals.jsonl",
|
|
162
|
+
gbrainSourceId: null,
|
|
163
|
+
allowedAgents: ["context-steward", "oracle"],
|
|
164
|
+
readPolicy: "proposal_metadata_only",
|
|
165
|
+
writePolicy: "proposal_only_no_auto_promote",
|
|
166
|
+
freshnessPolicy: "oracle_review_required_before_promotion",
|
|
167
|
+
noShipRules: ["auto_promote_blocked", "human_approval_required_for_promotion"],
|
|
168
|
+
},
|
|
169
|
+
];
|
|
170
|
+
return {
|
|
171
|
+
schema: "zob.context-brain-source-registry.v1",
|
|
172
|
+
repoRootHash: sha256(repoRoot),
|
|
173
|
+
brains: uniqueSorted(sources.map((source) => source.brainId)).map((brainId) => ({ brainId, controlPlane: false, knowledgePlane: true })),
|
|
174
|
+
sources,
|
|
175
|
+
p0EmulatedBrainsOnly: true,
|
|
176
|
+
gbrainImportEnabled: false,
|
|
177
|
+
gbrainEmbedEnabled: false,
|
|
178
|
+
gbrainSyncEnabled: false,
|
|
179
|
+
gbrainWriteEnabled: false,
|
|
180
|
+
bodyStored: false,
|
|
181
|
+
promptBodiesStored: false,
|
|
182
|
+
outputBodiesStored: false,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export function buildDefaultContextScope(repoRoot: string, input: ContextScopeInput): Record<string, unknown> {
|
|
187
|
+
const registry = buildContextBrainSourceRegistry(repoRoot);
|
|
188
|
+
const defaultSources = ["zob-harness-src", "zob-harness-docs", "factory-run-reports"];
|
|
189
|
+
const allowedSources = uniqueSorted(input.allowedSources ?? defaultSources);
|
|
190
|
+
const registrySources = sourceMap(registry);
|
|
191
|
+
const allowedBrains = uniqueSorted(input.allowedBrains ?? allowedSources.map((sourceId) => String(registrySources.get(sourceId)?.brainId ?? "")).filter(Boolean));
|
|
192
|
+
return {
|
|
193
|
+
schema: "zob.context-scope.v1",
|
|
194
|
+
scopeId: input.scopeId ?? safeFileStem(`${input.runId}-context-scope`),
|
|
195
|
+
runId: input.runId,
|
|
196
|
+
todoId: input.todoId ?? null,
|
|
197
|
+
allowedBrains,
|
|
198
|
+
allowedSources,
|
|
199
|
+
forbiddenSources: uniqueSorted(input.forbiddenSources ?? [".env", ".env.*", "secrets", "raw-conversation-history", "node_modules", "dist", "build"]),
|
|
200
|
+
agentProfile: input.agentProfile ?? "context-steward-p0",
|
|
201
|
+
maxContextTokens: Math.min(CONTEXT_SCOPE_MAX_TOKENS_CAP, Math.max(1, Math.floor(input.maxContextTokens ?? 4000))),
|
|
202
|
+
freshnessPolicy: input.freshnessPolicy ?? "current_source_or_declared_stale",
|
|
203
|
+
readPolicy: input.readPolicy ?? "bounded_metadata_only",
|
|
204
|
+
writePolicy: input.writePolicy ?? "proposal_only",
|
|
205
|
+
citationRequired: input.citationRequired ?? true,
|
|
206
|
+
contextPackRequired: true,
|
|
207
|
+
sourceScopeRequired: true,
|
|
208
|
+
bodyStored: false,
|
|
209
|
+
promptBodiesStored: false,
|
|
210
|
+
outputBodiesStored: false,
|
|
211
|
+
generatedAt: new Date().toISOString(),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export function validateContextScope(repoRoot: string, scope: Record<string, unknown>): string[] {
|
|
216
|
+
const errors: string[] = [];
|
|
217
|
+
const registry = buildContextBrainSourceRegistry(repoRoot);
|
|
218
|
+
const knownBrains = brainSet(registry);
|
|
219
|
+
const knownSources = sourceMap(registry);
|
|
220
|
+
if (hasForbiddenContextBodyKey(scope)) errors.push("context_scope must not contain raw task/prompt/output/body/content/conversation fields");
|
|
221
|
+
if (scope.schema !== "zob.context-scope.v1") errors.push("context_scope schema must be zob.context-scope.v1");
|
|
222
|
+
if (typeof scope.runId !== "string" || scope.runId.length === 0) errors.push("context_scope requires runId");
|
|
223
|
+
if (scope.todoId !== undefined && scope.todoId !== null && (typeof scope.todoId !== "string" || !/^[A-Za-z0-9._:-]+$/.test(scope.todoId))) errors.push("context_scope todoId must be metadata-safe when provided");
|
|
224
|
+
if (scope.citationRequired !== true) errors.push("context_scope must set citationRequired=true");
|
|
225
|
+
if (scope.writePolicy !== "proposal_only") errors.push("context_scope writePolicy must be proposal_only in P0");
|
|
226
|
+
if (scope.readPolicy !== "bounded_metadata_only" && scope.readPolicy !== "repo_local_metadata_only") errors.push("context_scope readPolicy must be bounded metadata-only in P0");
|
|
227
|
+
const maxTokens = typeof scope.maxContextTokens === "number" ? scope.maxContextTokens : 0;
|
|
228
|
+
if (!Number.isFinite(maxTokens) || maxTokens < 1 || maxTokens > CONTEXT_SCOPE_MAX_TOKENS_CAP) errors.push(`context_scope maxContextTokens must be 1..${CONTEXT_SCOPE_MAX_TOKENS_CAP}`);
|
|
229
|
+
const allowedBrains = stringArray(scope.allowedBrains);
|
|
230
|
+
const allowedSources = stringArray(scope.allowedSources);
|
|
231
|
+
const forbiddenSources = stringArray(scope.forbiddenSources);
|
|
232
|
+
if (allowedBrains.length === 0) errors.push("context_scope requires allowedBrains");
|
|
233
|
+
if (allowedSources.length === 0) errors.push("context_scope requires allowedSources");
|
|
234
|
+
for (const brainId of allowedBrains) if (!knownBrains.has(brainId)) errors.push(`context_scope unknown brain: ${brainId}`);
|
|
235
|
+
for (const sourceId of allowedSources) {
|
|
236
|
+
const source = knownSources.get(sourceId);
|
|
237
|
+
if (!source) errors.push(`context_scope unknown source: ${sourceId}`);
|
|
238
|
+
else if (!allowedBrains.includes(String(source.brainId))) errors.push(`context_scope source outside allowed brain: ${sourceId}`);
|
|
239
|
+
}
|
|
240
|
+
for (const forbidden of forbiddenSources) {
|
|
241
|
+
if (allowedSources.includes(forbidden)) errors.push(`context_scope source cannot be both allowed and forbidden: ${forbidden}`);
|
|
242
|
+
}
|
|
243
|
+
if (!forbiddenSources.some((source) => source.includes(".env")) || !forbiddenSources.some((source) => source.includes("raw-conversation"))) errors.push("context_scope must forbid secrets and raw conversation history");
|
|
244
|
+
return errors;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function validateLookupAccess(repoRoot: string, scope: Record<string, unknown>, brainId: string, sourceId: string): string[] {
|
|
248
|
+
const errors = validateContextScope(repoRoot, scope);
|
|
249
|
+
const allowedBrains = stringArray(scope.allowedBrains);
|
|
250
|
+
const allowedSources = stringArray(scope.allowedSources);
|
|
251
|
+
const forbiddenSources = stringArray(scope.forbiddenSources);
|
|
252
|
+
const registrySources = sourceMap(buildContextBrainSourceRegistry(repoRoot));
|
|
253
|
+
const source = registrySources.get(sourceId);
|
|
254
|
+
if (!allowedBrains.includes(brainId)) errors.push(`brain outside context_scope: ${brainId}`);
|
|
255
|
+
if (!allowedSources.includes(sourceId)) errors.push(`source outside context_scope: ${sourceId}`);
|
|
256
|
+
if (forbiddenSources.includes(sourceId)) errors.push(`source forbidden by context_scope: ${sourceId}`);
|
|
257
|
+
if (!source) errors.push(`unknown source: ${sourceId}`);
|
|
258
|
+
else if (String(source.brainId) !== brainId) errors.push(`source '${sourceId}' does not belong to brain '${brainId}'`);
|
|
259
|
+
return errors;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export function buildBrainLookupResult(repoRoot: string, input: ContextLookupInput): Record<string, unknown> {
|
|
263
|
+
const accessErrors = validateLookupAccess(repoRoot, input.scope, input.brainId, input.sourceId);
|
|
264
|
+
if (accessErrors.length > 0) throw new Error(accessErrors.join("; "));
|
|
265
|
+
const lookup = {
|
|
266
|
+
schema: "zob.brain-lookup-result.v1",
|
|
267
|
+
lookupId: input.lookupId ?? safeFileStem(`${String(input.scope.runId)}-${input.sourceId}-lookup`),
|
|
268
|
+
runId: input.scope.runId,
|
|
269
|
+
scopeId: input.scope.scopeId,
|
|
270
|
+
brainId: input.brainId,
|
|
271
|
+
sourceId: input.sourceId,
|
|
272
|
+
queryHash: input.queryHash,
|
|
273
|
+
queryStored: false,
|
|
274
|
+
facts: input.facts ?? [],
|
|
275
|
+
patterns: input.patterns ?? [],
|
|
276
|
+
gaps: input.gaps ?? [],
|
|
277
|
+
freshness: input.freshness ?? "current_or_declared_stale",
|
|
278
|
+
confidence: input.confidence ?? "MEDIUM",
|
|
279
|
+
citationRequired: true,
|
|
280
|
+
bodyStored: false,
|
|
281
|
+
promptBodiesStored: false,
|
|
282
|
+
outputBodiesStored: false,
|
|
283
|
+
generatedAt: new Date().toISOString(),
|
|
284
|
+
};
|
|
285
|
+
const validationErrors = validateBrainLookupResult(repoRoot, input.scope, lookup);
|
|
286
|
+
if (validationErrors.length > 0) throw new Error(validationErrors.join("; "));
|
|
287
|
+
return lookup;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export function validateBrainLookupResult(repoRoot: string, scope: Record<string, unknown>, lookup: Record<string, unknown>): string[] {
|
|
291
|
+
const errors: string[] = [];
|
|
292
|
+
if (hasForbiddenContextBodyKey(lookup)) errors.push("brain_lookup must not contain raw task/prompt/output/body/content fields");
|
|
293
|
+
if (lookup.schema !== "zob.brain-lookup-result.v1") errors.push("brain_lookup schema must be zob.brain-lookup-result.v1");
|
|
294
|
+
if (!isHexSha256(lookup.queryHash)) errors.push("brain_lookup requires queryHash sha256; raw query is not stored");
|
|
295
|
+
if (lookup.queryStored !== false) errors.push("brain_lookup queryStored must be false");
|
|
296
|
+
if (lookup.citationRequired !== true) errors.push("brain_lookup citationRequired must be true");
|
|
297
|
+
if (typeof lookup.brainId !== "string" || typeof lookup.sourceId !== "string") errors.push("brain_lookup requires brainId and sourceId");
|
|
298
|
+
else errors.push(...validateLookupAccess(repoRoot, scope, lookup.brainId, lookup.sourceId));
|
|
299
|
+
if (!entriesHaveCitations(lookup.facts)) errors.push("brain_lookup facts require citations");
|
|
300
|
+
if (!entriesHaveCitations(lookup.patterns)) errors.push("brain_lookup patterns require citations");
|
|
301
|
+
if (lookup.bodyStored !== false || lookup.promptBodiesStored !== false || lookup.outputBodiesStored !== false) errors.push("brain_lookup must mark body/prompt/output storage false");
|
|
302
|
+
return errors;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export function buildContextPack(repoRoot: string, scope: Record<string, unknown>, lookups: Array<Record<string, unknown>>): Record<string, unknown> {
|
|
306
|
+
const scopeErrors = validateContextScope(repoRoot, scope);
|
|
307
|
+
if (scopeErrors.length > 0) throw new Error(scopeErrors.join("; "));
|
|
308
|
+
const lookupErrors = lookups.flatMap((lookup) => validateBrainLookupResult(repoRoot, scope, lookup));
|
|
309
|
+
if (lookupErrors.length > 0) throw new Error(lookupErrors.join("; "));
|
|
310
|
+
const registrySources = sourceMap(buildContextBrainSourceRegistry(repoRoot));
|
|
311
|
+
const allowedSources = stringArray(scope.allowedSources);
|
|
312
|
+
const sourceLocks = allowedSources.map((sourceId) => {
|
|
313
|
+
const source = registrySources.get(sourceId);
|
|
314
|
+
const sourceRoot = typeof source?.sourceRoot === "string" ? source.sourceRoot : sourceId;
|
|
315
|
+
return { sourceId, brainId: source?.brainId, sourceRoot, sourceRootHash: sha256(sourceRoot), exists: existsSync(join(repoRoot, sourceRoot)) };
|
|
316
|
+
});
|
|
317
|
+
const citations = uniqueSorted(lookups.flatMap((lookup) => [lookup.facts, lookup.patterns].flatMap((entries) => Array.isArray(entries) ? entries.flatMap((entry) => isRecord(entry) ? (Array.isArray(entry.citations) ? entry.citations : [entry.citation]).filter((citation): citation is string => typeof citation === "string") : []) : [])));
|
|
318
|
+
return {
|
|
319
|
+
schema: "zob.context-pack.v1",
|
|
320
|
+
packId: safeFileStem(`${String(scope.runId)}-context-pack`),
|
|
321
|
+
runId: scope.runId,
|
|
322
|
+
scopeId: scope.scopeId,
|
|
323
|
+
contextScope: scope,
|
|
324
|
+
lookupIds: lookups.map((lookup) => lookup.lookupId),
|
|
325
|
+
sourceLocks,
|
|
326
|
+
loadingRules: { contextScopeRequired: true, boundedContextOnly: true, agentLoadsEntireCorpus: false, citationRequired: true },
|
|
327
|
+
agentProfileMap: { [String(scope.agentProfile ?? "context-steward-p0")]: { maxContextTokens: scope.maxContextTokens, allowedSources: scope.allowedSources } },
|
|
328
|
+
citations,
|
|
329
|
+
budgetLimits: { maxContextTokens: scope.maxContextTokens, maxLookups: 10, budgetEnforced: false },
|
|
330
|
+
gaps: lookups.flatMap((lookup) => Array.isArray(lookup.gaps) ? lookup.gaps : []),
|
|
331
|
+
bodyStored: false,
|
|
332
|
+
promptBodiesStored: false,
|
|
333
|
+
outputBodiesStored: false,
|
|
334
|
+
generatedAt: new Date().toISOString(),
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export function validateContextPack(repoRoot: string, pack: Record<string, unknown>): string[] {
|
|
339
|
+
const errors: string[] = [];
|
|
340
|
+
if (hasForbiddenContextBodyKey(pack)) errors.push("context_pack must not contain raw task/prompt/output/body/content fields");
|
|
341
|
+
if (pack.schema !== "zob.context-pack.v1") errors.push("context_pack schema must be zob.context-pack.v1");
|
|
342
|
+
const scope = isRecord(pack.contextScope) ? pack.contextScope : undefined;
|
|
343
|
+
if (!scope) errors.push("context_pack requires contextScope");
|
|
344
|
+
else errors.push(...validateContextScope(repoRoot, scope));
|
|
345
|
+
const loadingRules = isRecord(pack.loadingRules) ? pack.loadingRules : {};
|
|
346
|
+
if (loadingRules.contextScopeRequired !== true || loadingRules.boundedContextOnly !== true || loadingRules.agentLoadsEntireCorpus !== false || loadingRules.citationRequired !== true) errors.push("context_pack loadingRules must require scope, citations, and bounded context only");
|
|
347
|
+
if (!Array.isArray(pack.sourceLocks) || pack.sourceLocks.length === 0) errors.push("context_pack requires sourceLocks");
|
|
348
|
+
if (!Array.isArray(pack.citations) || pack.citations.length === 0 || !pack.citations.every(isCitation)) errors.push("context_pack requires citations");
|
|
349
|
+
if (pack.bodyStored !== false || pack.promptBodiesStored !== false || pack.outputBodiesStored !== false) errors.push("context_pack must mark body/prompt/output storage false");
|
|
350
|
+
return errors;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
export function buildContextWritebackProposal(input: ContextWritebackProposalInput): Record<string, unknown> {
|
|
354
|
+
const proposal = {
|
|
355
|
+
schema: "zob.context-writeback-proposal.v1",
|
|
356
|
+
proposalId: input.proposalId ?? safeFileStem(`${input.runId}-context-writeback`),
|
|
357
|
+
runId: input.runId,
|
|
358
|
+
observedProblemHash: input.observedProblemHash,
|
|
359
|
+
newPatternHash: input.newPatternHash,
|
|
360
|
+
evidenceRefs: input.evidenceRefs,
|
|
361
|
+
recommendedArtifact: input.recommendedArtifact,
|
|
362
|
+
promotionRequires: ["oracle_PASS", "human_approval", "smoke_proof"],
|
|
363
|
+
autoPromote: false,
|
|
364
|
+
writebackApplied: false,
|
|
365
|
+
gbrainWriteEnabled: false,
|
|
366
|
+
bodyStored: false,
|
|
367
|
+
promptBodiesStored: false,
|
|
368
|
+
outputBodiesStored: false,
|
|
369
|
+
generatedAt: new Date().toISOString(),
|
|
370
|
+
};
|
|
371
|
+
const errors = validateContextWritebackProposal(proposal);
|
|
372
|
+
if (errors.length > 0) throw new Error(errors.join("; "));
|
|
373
|
+
return proposal;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
export function validateContextWritebackProposal(proposal: Record<string, unknown>): string[] {
|
|
377
|
+
const errors: string[] = [];
|
|
378
|
+
if (hasForbiddenContextBodyKey(proposal)) errors.push("context writeback proposal must not contain raw task/prompt/output/body/content fields");
|
|
379
|
+
if (proposal.schema !== "zob.context-writeback-proposal.v1") errors.push("context writeback proposal schema must be zob.context-writeback-proposal.v1");
|
|
380
|
+
if (!isHexSha256(proposal.observedProblemHash)) errors.push("context writeback proposal requires observedProblemHash sha256");
|
|
381
|
+
if (!isHexSha256(proposal.newPatternHash)) errors.push("context writeback proposal requires newPatternHash sha256");
|
|
382
|
+
if (!Array.isArray(proposal.evidenceRefs) || proposal.evidenceRefs.length === 0 || !proposal.evidenceRefs.every((ref) => typeof ref === "string" && isSafeSourceRef(ref))) errors.push("context writeback proposal requires safe evidenceRefs");
|
|
383
|
+
if (typeof proposal.recommendedArtifact !== "string" || !isSafeSourceRef(proposal.recommendedArtifact)) errors.push("context writeback proposal requires safe recommendedArtifact");
|
|
384
|
+
if (proposal.autoPromote !== false || proposal.writebackApplied !== false || proposal.gbrainWriteEnabled !== false) errors.push("context writeback proposal must be proposal-only with no auto-promotion or GBrain write");
|
|
385
|
+
if (!Array.isArray(proposal.promotionRequires) || !["oracle_PASS", "human_approval", "smoke_proof"].every((item) => (proposal.promotionRequires as unknown[]).includes(item))) errors.push("context writeback proposal requires oracle, human approval, and smoke proof before promotion");
|
|
386
|
+
if (proposal.bodyStored !== false || proposal.promptBodiesStored !== false || proposal.outputBodiesStored !== false) errors.push("context writeback proposal must mark body/prompt/output storage false");
|
|
387
|
+
return errors;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
export function writeContextWritebackProposal(repoRoot: string, input: ContextWritebackProposalInput): Record<string, unknown> {
|
|
391
|
+
const proposal = buildContextWritebackProposal(input);
|
|
392
|
+
const dir = join(repoRoot, ".pi", "context");
|
|
393
|
+
mkdirSync(dir, { recursive: true });
|
|
394
|
+
const ledgerPath = join(dir, "writeback-proposals.jsonl");
|
|
395
|
+
const artifactPath = join(dir, `${proposal.proposalId}.json`);
|
|
396
|
+
writeFileSync(artifactPath, JSON.stringify(proposal, null, 2), "utf8");
|
|
397
|
+
writeFileSync(ledgerPath, `${JSON.stringify(proposal)}\n`, { flag: "a" });
|
|
398
|
+
return { ...proposal, proposalLedger: ".pi/context/writeback-proposals.jsonl", proposalArtifact: `.pi/context/${proposal.proposalId}.json` };
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
export function buildContextGbrainReadinessAudit(repoRoot: string, input: { runId?: string } = {}): Record<string, unknown> {
|
|
402
|
+
const registry = buildContextBrainSourceRegistry(repoRoot);
|
|
403
|
+
const scope = buildDefaultContextScope(repoRoot, { runId: input.runId ?? "context-gbrain-readiness-smoke", maxContextTokens: 2000 });
|
|
404
|
+
const citation = "harness-system:zob-harness-docs:docs/AUTONOMOUS_SUPER_FACTORY_GOAL.md#phase-1.5";
|
|
405
|
+
const lookup = buildBrainLookupResult(repoRoot, {
|
|
406
|
+
scope,
|
|
407
|
+
brainId: "harness-system",
|
|
408
|
+
sourceId: "zob-harness-docs",
|
|
409
|
+
queryHash: sha256("context readiness P0"),
|
|
410
|
+
facts: [{ factHash: sha256("context_scope required before lookup"), citations: [citation], confidence: "HIGH" }],
|
|
411
|
+
gaps: [{ gapHash: sha256("real GBrain adapter not enabled"), citations: [citation], noShipIfTreatedAsPass: true }],
|
|
412
|
+
confidence: "HIGH",
|
|
413
|
+
});
|
|
414
|
+
const pack = buildContextPack(repoRoot, scope, [lookup]);
|
|
415
|
+
const writeback = buildContextWritebackProposal({
|
|
416
|
+
runId: String(scope.runId),
|
|
417
|
+
observedProblemHash: sha256("context readiness observed problem"),
|
|
418
|
+
newPatternHash: sha256("context readiness writeback pattern"),
|
|
419
|
+
evidenceRefs: ["docs/AUTONOMOUS_SUPER_FACTORY_GOAL.md", ".pi/extensions/zob-harness/src/context-gbrain.ts"],
|
|
420
|
+
recommendedArtifact: ".pi/context/writeback-proposals.jsonl",
|
|
421
|
+
});
|
|
422
|
+
const forbiddenScope = { ...scope, allowedSources: ["zob-harness-docs", "raw-conversation-history"], forbiddenSources: ["raw-conversation-history", ".env"] };
|
|
423
|
+
const checks = [
|
|
424
|
+
{ name: "registry_metadata_only", passed: registry.gbrainImportEnabled === false && registry.gbrainEmbedEnabled === false && registry.gbrainSyncEnabled === false && registry.gbrainWriteEnabled === false && registry.p0EmulatedBrainsOnly === true && !hasForbiddenContextBodyKey(registry), detail: "P0 emulated registry only" },
|
|
425
|
+
{ name: "context_scope_required_and_valid", passed: validateContextScope(repoRoot, scope).length === 0, detail: JSON.stringify({ scopeId: scope.scopeId, allowedSources: scope.allowedSources }) },
|
|
426
|
+
{ name: "forbidden_source_blocked", passed: validateContextScope(repoRoot, forbiddenScope).some((error) => error.includes("both allowed and forbidden")), detail: "raw-conversation-history cannot be allowed" },
|
|
427
|
+
{ name: "lookup_scope_and_citations_enforced", passed: validateBrainLookupResult(repoRoot, scope, lookup).length === 0 && validateBrainLookupResult(repoRoot, scope, { ...lookup, facts: [{ factHash: sha256("missing citation") }] }).some((error) => error.includes("citations")), detail: String(lookup.lookupId) },
|
|
428
|
+
{ name: "context_pack_bounded_body_free", passed: validateContextPack(repoRoot, pack).length === 0 && !hasForbiddenContextBodyKey(pack), detail: JSON.stringify({ packId: pack.packId, citations: Array.isArray(pack.citations) ? pack.citations.length : 0 }) },
|
|
429
|
+
{ name: "writeback_local_metadata_proposal_only", passed: validateContextWritebackProposal(writeback).length === 0 && writeback.autoPromote === false && writeback.writebackApplied === false && writeback.gbrainWriteEnabled === false, detail: JSON.stringify({ proposalId: writeback.proposalId, localProposalArtifactAllowed: true, corpusWrite: false, gbrainWrite: false }) },
|
|
430
|
+
];
|
|
431
|
+
const failedChecks = checks.filter((check) => !check.passed).map((check) => check.name);
|
|
432
|
+
return {
|
|
433
|
+
schema: "zob.context-gbrain-readiness-audit.v1",
|
|
434
|
+
verdict: failedChecks.length === 0 ? "PASS" : "FAIL",
|
|
435
|
+
no_ship: failedChecks.length > 0,
|
|
436
|
+
checks,
|
|
437
|
+
failedChecks,
|
|
438
|
+
registry,
|
|
439
|
+
contextScope: scope,
|
|
440
|
+
sampleLookup: lookup,
|
|
441
|
+
sampleContextPack: pack,
|
|
442
|
+
sampleWritebackProposal: writeback,
|
|
443
|
+
gbrainImportEnabled: false,
|
|
444
|
+
gbrainEmbedEnabled: false,
|
|
445
|
+
gbrainSyncEnabled: false,
|
|
446
|
+
gbrainWriteEnabled: false,
|
|
447
|
+
localProposalArtifactsAllowed: true,
|
|
448
|
+
corpusWritesEnabled: false,
|
|
449
|
+
controlPlane: false,
|
|
450
|
+
knowledgePlane: true,
|
|
451
|
+
bodyStored: false,
|
|
452
|
+
promptBodiesStored: false,
|
|
453
|
+
outputBodiesStored: false,
|
|
454
|
+
generatedAt: new Date().toISOString(),
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
export function writeContextGbrainReadinessAuditReport(repoRoot: string, runId = "context-gbrain-readiness-smoke"): string {
|
|
459
|
+
const report = buildContextGbrainReadinessAudit(repoRoot, { runId });
|
|
460
|
+
const reportsDir = join(repoRoot, "reports");
|
|
461
|
+
mkdirSync(reportsDir, { recursive: true });
|
|
462
|
+
const path = join(reportsDir, `${safeFileStem(runId)}.json`);
|
|
463
|
+
writeFileSync(path, JSON.stringify(report, null, 2), "utf8");
|
|
464
|
+
return path;
|
|
465
|
+
}
|