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,289 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { dirname, isAbsolute, relative, resolve, sep } from "node:path";
|
|
5
|
+
|
|
6
|
+
const repoRoot = process.cwd();
|
|
7
|
+
const profiles = new Set(["auto", "low", "medium", "high", "xhigh", "max"]);
|
|
8
|
+
const semanticCaptureModes = new Set(["full_capture", "architecture_only", "targeted_capture", "sample_first", "context_only"]);
|
|
9
|
+
const rawKeyDenylist = new Set(["body", "prompt", "output", "content", "diff", "patch"]);
|
|
10
|
+
|
|
11
|
+
function usage() {
|
|
12
|
+
console.error("Usage: node scripts/project-dna/plan-workflow.mjs --manifest .pi/factories/project-dna/example-project-dna-manifest-v2.json [--scan-dir reports/project-dna-scans/project-dna-factory-smoke] --out reports/project-dna-scans/project-dna-factory-smoke/agentic-plan.json");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function parseArgs(argv) {
|
|
16
|
+
const args = {};
|
|
17
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
18
|
+
const arg = argv[index];
|
|
19
|
+
if (arg === "--manifest") args.manifest = argv[++index];
|
|
20
|
+
else if (arg === "--scan-dir") args.scanDir = argv[++index];
|
|
21
|
+
else if (arg === "--out") args.out = argv[++index];
|
|
22
|
+
else if (arg === "--help" || arg === "-h") { usage(); process.exit(0); }
|
|
23
|
+
else throw new Error(`unknown argument: ${arg}`);
|
|
24
|
+
}
|
|
25
|
+
if (!args.manifest || !args.out) throw new Error("--manifest and --out are required");
|
|
26
|
+
return args;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function repoPath(path, label) {
|
|
30
|
+
if (!path || isAbsolute(path)) throw new Error(`${label} must be repo-relative`);
|
|
31
|
+
const resolved = resolve(repoRoot, path);
|
|
32
|
+
const root = resolve(repoRoot);
|
|
33
|
+
const rel = relative(root, resolved);
|
|
34
|
+
if (rel === "" || rel.startsWith("..") || isAbsolute(rel)) throw new Error(`${label} must stay inside repo and not be repo root: ${path}`);
|
|
35
|
+
return resolved;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function assertReportPath(path, label) {
|
|
39
|
+
const normalized = path.split(sep).join("/");
|
|
40
|
+
if (!normalized.startsWith("reports/project-dna-scans/")) throw new Error(`${label} must stay under reports/project-dna-scans: ${path}`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function isInsideOrEqual(parent, child) {
|
|
44
|
+
const rel = relative(parent, child);
|
|
45
|
+
return rel === "" || (!rel.startsWith("..") && !isAbsolute(rel));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function assertNotBroadPath(path, label) {
|
|
49
|
+
const resolved = resolve(path);
|
|
50
|
+
if (["/", "/home", "/home/ubuntu"].includes(resolved)) throw new Error(`refusing broad ${label}: ${path}`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function inputPath(path, label) {
|
|
54
|
+
if (!path) throw new Error(`${label} is required`);
|
|
55
|
+
const resolved = isAbsolute(path) ? resolve(path) : repoPath(path, label);
|
|
56
|
+
assertNotBroadPath(resolved, label);
|
|
57
|
+
return resolved;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function sha256(value) {
|
|
61
|
+
return createHash("sha256").update(value).digest("hex");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function assertNoRawKeys(value, trail = []) {
|
|
65
|
+
if (Array.isArray(value)) {
|
|
66
|
+
for (let index = 0; index < value.length; index += 1) assertNoRawKeys(value[index], [...trail, String(index)]);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (!value || typeof value !== "object") return;
|
|
70
|
+
for (const [key, child] of Object.entries(value)) {
|
|
71
|
+
if (rawKeyDenylist.has(key.toLowerCase())) throw new Error(`raw key forbidden in plan metadata: ${[...trail, key].join(".")}`);
|
|
72
|
+
assertNoRawKeys(child, [...trail, key]);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function requireBoolean(value, expected, label, errors) {
|
|
77
|
+
if (value !== expected) errors.push(`${label} must be ${expected}`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function validateManifest(manifest) {
|
|
81
|
+
const errors = [];
|
|
82
|
+
if (manifest.schema !== "zob.project-dna-manifest.v2") errors.push("manifest schema must be zob.project-dna-manifest.v2");
|
|
83
|
+
if (typeof manifest.run_id !== "string" || !/^[A-Za-z0-9._-]+$/.test(manifest.run_id)) errors.push("run_id must be a safe id");
|
|
84
|
+
if (typeof manifest.user_note !== "string" || manifest.user_note.length < 1) errors.push("user_note is required");
|
|
85
|
+
if (typeof manifest.capture_goal?.objective !== "string" || manifest.capture_goal.objective.length < 1) errors.push("capture_goal.objective is required");
|
|
86
|
+
requireBoolean(manifest.capture_goal?.bounded_context_only, true, "capture_goal.bounded_context_only", errors);
|
|
87
|
+
requireBoolean(manifest.capture_goal?.citation_required, true, "capture_goal.citation_required", errors);
|
|
88
|
+
if (!profiles.has(manifest.requested_compute_profile)) errors.push("requested_compute_profile invalid");
|
|
89
|
+
if (!semanticCaptureModes.has(manifest.capture_mode_policy?.semantic_mode)) errors.push("capture_mode_policy.semantic_mode invalid");
|
|
90
|
+
if (manifest.capture_mode_policy?.large_repo_fallback !== undefined && !["architecture_only", "targeted_capture", "sample_first", "context_only"].includes(manifest.capture_mode_policy.large_repo_fallback)) errors.push("capture_mode_policy.large_repo_fallback invalid");
|
|
91
|
+
requireBoolean(manifest.capture_mode_policy?.metadata_only, true, "capture_mode_policy.metadata_only", errors);
|
|
92
|
+
requireBoolean(manifest.capture_mode_policy?.parent_owned_dispatch, true, "capture_mode_policy.parent_owned_dispatch", errors);
|
|
93
|
+
requireBoolean(manifest.capture_mode_policy?.child_direct_dispatch_allowed, false, "capture_mode_policy.child_direct_dispatch_allowed", errors);
|
|
94
|
+
requireBoolean(manifest.capture_mode_policy?.network_access_allowed, false, "capture_mode_policy.network_access_allowed", errors);
|
|
95
|
+
requireBoolean(manifest.capture_mode_policy?.source_mutation_allowed, false, "capture_mode_policy.source_mutation_allowed", errors);
|
|
96
|
+
requireBoolean(manifest.capture_mode_policy?.knowledge_backend_write_allowed, false, "capture_mode_policy.knowledge_backend_write_allowed", errors);
|
|
97
|
+
if (manifest.capture_mode_policy?.durable_promotion_allowed !== undefined) requireBoolean(manifest.capture_mode_policy.durable_promotion_allowed, false, "capture_mode_policy.durable_promotion_allowed", errors);
|
|
98
|
+
if (typeof manifest.source_project?.source_id !== "string" || !/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(manifest.source_project.source_id)) errors.push("source_project.source_id invalid");
|
|
99
|
+
if (manifest.capture_goal?.source_id !== manifest.source_project?.source_id) errors.push("capture_goal.source_id must match source_project.source_id");
|
|
100
|
+
if (typeof manifest.source_project?.path !== "string" || manifest.source_project.path.length < 1) errors.push("source_project.path is required");
|
|
101
|
+
if (!Array.isArray(manifest.read_policy?.allowed_paths) || manifest.read_policy.allowed_paths.length < 1) errors.push("read_policy.allowed_paths required");
|
|
102
|
+
if (!Array.isArray(manifest.read_policy?.forbidden_patterns) || manifest.read_policy.forbidden_patterns.length < 1) errors.push("read_policy.forbidden_patterns required");
|
|
103
|
+
requireBoolean(manifest.read_policy?.forbid_secret_like_paths, true, "read_policy.forbid_secret_like_paths", errors);
|
|
104
|
+
requireBoolean(manifest.read_policy?.external_project_scan_allowed, false, "read_policy.external_project_scan_allowed", errors);
|
|
105
|
+
requireBoolean(manifest.sample_project?.quarantine_required, true, "sample_project.quarantine_required", errors);
|
|
106
|
+
if (manifest.sample_project?.generation_policy !== "plan_only" && manifest.sample_project?.generation_policy !== "quarantine_only") errors.push("sample_project.generation_policy invalid");
|
|
107
|
+
if (manifest.promotion?.writeback_policy !== "proposal_only") errors.push("promotion.writeback_policy must be proposal_only");
|
|
108
|
+
requireBoolean(manifest.promotion?.requires_oracle_pass, true, "promotion.requires_oracle_pass", errors);
|
|
109
|
+
requireBoolean(manifest.promotion?.requires_human_approval, true, "promotion.requires_human_approval", errors);
|
|
110
|
+
requireBoolean(manifest.promotion?.durable_promotion_allowed, false, "promotion.durable_promotion_allowed", errors);
|
|
111
|
+
return errors;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function effectiveProfile(requested) {
|
|
115
|
+
if (requested === "auto") return "medium";
|
|
116
|
+
return profiles.has(requested) ? requested : "low";
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function readOptionalScanSummary(scanDir) {
|
|
120
|
+
if (!scanDir) return {};
|
|
121
|
+
const summaryPath = repoPath(`${scanDir.replace(/\/$/, "")}/scan-summary.json`, "scan-summary");
|
|
122
|
+
if (!existsSync(summaryPath)) return {};
|
|
123
|
+
const parsed = JSON.parse(readFileSync(summaryPath, "utf8"));
|
|
124
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function deriveCaptureMode(manifest, profile, scanSummary) {
|
|
128
|
+
const requested = manifest.capture_mode_policy?.semantic_mode;
|
|
129
|
+
const fallback = manifest.capture_mode_policy?.large_repo_fallback ?? "architecture_only";
|
|
130
|
+
const fileCount = Number(scanSummary.files_scanned ?? 0);
|
|
131
|
+
const intent = `${manifest.user_note ?? ""} ${manifest.capture_goal?.objective ?? ""}`.toLowerCase();
|
|
132
|
+
if (requested && requested !== "full_capture") return requested;
|
|
133
|
+
if (/\b(sample|exemple|example|neutral)\b/.test(intent)) return "sample_first";
|
|
134
|
+
if (/\b(context|query|lookup|retrieval)\b/.test(intent)) return "context_only";
|
|
135
|
+
if (/\b(architecture|archi|structure|scaffold)\b/.test(intent)) return "architecture_only";
|
|
136
|
+
if (fileCount >= 1000 || profile === "xhigh" || profile === "max") return fallback;
|
|
137
|
+
return requested ?? "full_capture";
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function laneCatalog(profile) {
|
|
141
|
+
const base = [
|
|
142
|
+
{ id: "manifest_preflight", phase: "p0", agent: "project-dna-safety-preflight", artifactContract: "safety-metadata.v1", toolHints: ["read"], required: true },
|
|
143
|
+
{ id: "repo_scout", phase: "p0", agent: "repo-scout", artifactContract: "repo-complexity-report.v1", toolHints: ["read", "grep", "find", "ls"], required: true },
|
|
144
|
+
{ id: "read_only_scan", phase: "p1", agent: "agent", artifactContract: "scan-metadata.v1", toolHints: ["read", "grep", "find", "ls"], required: true },
|
|
145
|
+
{ id: "scan_validation", phase: "p1", agent: "qa", artifactContract: "validation-metadata.v1", toolHints: ["read", "bash"], required: true }
|
|
146
|
+
];
|
|
147
|
+
if (["medium", "high", "xhigh", "max"].includes(profile)) base.push(
|
|
148
|
+
{ id: "ontology_curation", phase: "p1", agent: "project-dna-ontology-steward", artifactContract: "ontology-metadata.v1", toolHints: ["read", "grep", "find", "ls"], required: true },
|
|
149
|
+
{ id: "architecture_cartography", phase: "p1", agent: "architecture-cartographer", artifactContract: "architecture-map.v2", toolHints: ["read", "grep", "find", "ls"], required: true },
|
|
150
|
+
{ id: "pattern_mining", phase: "p1", agent: "pattern-miner", artifactContract: "pattern-index.partial.v1", toolHints: ["read", "grep", "find", "ls"], required: true },
|
|
151
|
+
{ id: "test_linking", phase: "p1", agent: "project-dna-test-linker", artifactContract: "test-link-metadata.v1", toolHints: ["read", "grep", "find", "ls"], required: true },
|
|
152
|
+
{ id: "capsule_build", phase: "p1", agent: "context-steward", artifactContract: "capsule-pointer-metadata.v1", toolHints: ["read"], required: true },
|
|
153
|
+
{ id: "sample_spec", phase: "p1", agent: "sample-architect", artifactContract: "sample-spec-metadata.v1", toolHints: ["read"], required: true },
|
|
154
|
+
{ id: "query_steward_review", phase: "p1", agent: "project-dna-query-steward", artifactContract: "query-steward-report.v1", toolHints: ["read", "grep", "find", "ls"], required: true },
|
|
155
|
+
{ id: "bounded_query", phase: "p1", agent: "context-steward", artifactContract: "context-pack-metadata.v1", toolHints: ["read"], required: true }
|
|
156
|
+
);
|
|
157
|
+
if (["high", "xhigh", "max"].includes(profile)) base.push(
|
|
158
|
+
{ id: "symbol_range_curation", phase: "p1", agent: "symbol-range-curator", artifactContract: "range-quality-report.v1", toolHints: ["read", "grep", "find", "ls"], required: true },
|
|
159
|
+
{ id: "quarantine_sample", phase: "p1", agent: "implementer", artifactContract: "quarantine-sample-metadata.v1", toolHints: ["read", "bash"], required: false },
|
|
160
|
+
{ id: "golden_case_benchmark", phase: "p1", agent: "project-dna-golden-evaluator", artifactContract: "golden-benchmark-metadata.v1", toolHints: ["read", "bash"], required: true },
|
|
161
|
+
{ id: "benchmark", phase: "p1", agent: "qa", artifactContract: "benchmark-metadata.v1", toolHints: ["read", "bash"], required: false },
|
|
162
|
+
{ id: "oracle_review", phase: "p1", agent: "project-dna-oracle", artifactContract: "oracle-metadata.v1", toolHints: ["read", "grep", "find", "ls"], required: true }
|
|
163
|
+
);
|
|
164
|
+
if (["xhigh", "max"].includes(profile)) base.push({ id: "adversarial_safety_review", phase: "p1", agent: "project-dna-oracle", artifactContract: "oracle-metadata.v1", toolHints: ["read", "grep", "find", "ls"], required: true });
|
|
165
|
+
if (profile === "max") base.push({ id: "human_promotion_packet", phase: "p1", agent: "planner", artifactContract: "proposal-metadata.v1", toolHints: ["read"], required: true });
|
|
166
|
+
return base;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function main() {
|
|
170
|
+
const args = parseArgs(process.argv.slice(2));
|
|
171
|
+
const manifestPath = repoPath(args.manifest, "--manifest");
|
|
172
|
+
if (!existsSync(manifestPath)) throw new Error(`missing manifest: ${args.manifest}`);
|
|
173
|
+
const manifestText = readFileSync(manifestPath, "utf8");
|
|
174
|
+
const manifest = JSON.parse(manifestText);
|
|
175
|
+
assertNoRawKeys(manifest);
|
|
176
|
+
const manifestErrors = validateManifest(manifest);
|
|
177
|
+
if (manifestErrors.length > 0) throw new Error(`manifest validation failed: ${manifestErrors.join("; ")}`);
|
|
178
|
+
|
|
179
|
+
const sourcePath = inputPath(manifest.source_project.path, "source_project.path");
|
|
180
|
+
if (!existsSync(sourcePath)) throw new Error(`source_project.path does not exist: ${manifest.source_project.path}`);
|
|
181
|
+
const allowedPaths = manifest.read_policy.allowed_paths.map((allowedPath) => {
|
|
182
|
+
const allowed = inputPath(allowedPath, "read_policy.allowed_paths[]");
|
|
183
|
+
if (!existsSync(allowed)) throw new Error(`read_policy.allowed_paths entry does not exist: ${allowedPath}`);
|
|
184
|
+
return allowed;
|
|
185
|
+
});
|
|
186
|
+
if (!allowedPaths.some((allowed) => isInsideOrEqual(allowed, sourcePath))) throw new Error("source_project.path must be inside one read_policy.allowed_paths entry");
|
|
187
|
+
if (args.scanDir) {
|
|
188
|
+
assertReportPath(args.scanDir, "--scan-dir");
|
|
189
|
+
repoPath(args.scanDir, "--scan-dir");
|
|
190
|
+
}
|
|
191
|
+
assertReportPath(args.out, "--out");
|
|
192
|
+
const outPath = repoPath(args.out, "--out");
|
|
193
|
+
const profile = effectiveProfile(manifest.requested_compute_profile);
|
|
194
|
+
const scanSummary = readOptionalScanSummary(args.scanDir);
|
|
195
|
+
const effectiveCapture = deriveCaptureMode(manifest, profile, scanSummary);
|
|
196
|
+
const caps = manifest.compute_caps ?? {};
|
|
197
|
+
const maxParallel = Math.max(1, Math.min(Number(caps.maxParallel ?? 1), Number(caps.maxAgents ?? 1), 8));
|
|
198
|
+
const lanes = laneCatalog(profile).map((lane, index) => ({
|
|
199
|
+
...lane,
|
|
200
|
+
order: index + 1,
|
|
201
|
+
maxWorkers: Math.min(maxParallel, lane.id === "read_only_scan" ? 2 : 1),
|
|
202
|
+
parentOwnedDispatch: true,
|
|
203
|
+
childDirectDispatch: false,
|
|
204
|
+
liveDispatchEnabled: false,
|
|
205
|
+
sourceMutationAllowed: false,
|
|
206
|
+
backendWritesEnabled: false,
|
|
207
|
+
durablePromotionAllowed: false,
|
|
208
|
+
storesRawBodies: false
|
|
209
|
+
}));
|
|
210
|
+
const plan = {
|
|
211
|
+
schema: "zob.project-dna-agentic-plan.v1",
|
|
212
|
+
runId: manifest.run_id,
|
|
213
|
+
sourceId: manifest.source_project.source_id,
|
|
214
|
+
manifestPath: args.manifest,
|
|
215
|
+
manifestHash: sha256(manifestText),
|
|
216
|
+
manifestEmbedded: false,
|
|
217
|
+
scanDir: args.scanDir ?? `reports/project-dna-scans/${manifest.run_id}`,
|
|
218
|
+
requestedComputeProfile: manifest.requested_compute_profile,
|
|
219
|
+
effectiveComputeProfile: profile,
|
|
220
|
+
requestedCaptureMode: manifest.capture_mode_policy.semantic_mode,
|
|
221
|
+
effectiveCaptureMode: effectiveCapture,
|
|
222
|
+
captureModeRationale: "derived_from_manifest_user_note_profile_and_optional_scan_summary",
|
|
223
|
+
targetedDomains: Array.isArray(manifest.capture_mode_policy.targeted_domains) ? manifest.capture_mode_policy.targeted_domains : [],
|
|
224
|
+
repoStats: {
|
|
225
|
+
filesScanned: Number.isFinite(Number(scanSummary.files_scanned)) ? Number(scanSummary.files_scanned) : null,
|
|
226
|
+
filesSkipped: Number.isFinite(Number(scanSummary.files_skipped)) ? Number(scanSummary.files_skipped) : null,
|
|
227
|
+
scanSummaryAvailable: Object.keys(scanSummary).length > 0
|
|
228
|
+
},
|
|
229
|
+
objectiveHash: sha256(manifest.capture_goal.objective),
|
|
230
|
+
metadataOnly: true,
|
|
231
|
+
parentOwnedDispatch: true,
|
|
232
|
+
childDirectDispatch: false,
|
|
233
|
+
liveDispatchEnabled: false,
|
|
234
|
+
noExecution: true,
|
|
235
|
+
networkAccessed: false,
|
|
236
|
+
sourceProjectModified: false,
|
|
237
|
+
sourceMutationAllowed: false,
|
|
238
|
+
knowledgeBackendWriteEnabled: false,
|
|
239
|
+
durablePromotionAllowed: false,
|
|
240
|
+
rawBodiesStored: false,
|
|
241
|
+
promptBodiesStored: false,
|
|
242
|
+
resultBodiesStored: false,
|
|
243
|
+
bodyFreePlan: true,
|
|
244
|
+
dispatchPosture: "parent_owned_no_child_direct_dispatch",
|
|
245
|
+
promotionPolicy: "proposal_only",
|
|
246
|
+
artifactTargets: [
|
|
247
|
+
"project-fingerprint.json",
|
|
248
|
+
"dependency-map.json",
|
|
249
|
+
"file-map.json",
|
|
250
|
+
"symbol-map.json",
|
|
251
|
+
"import-graph.json",
|
|
252
|
+
"architecture-map.json",
|
|
253
|
+
"route-map.json",
|
|
254
|
+
"queue-map.json",
|
|
255
|
+
"config-map.json",
|
|
256
|
+
"test-map.json",
|
|
257
|
+
"db-map.json",
|
|
258
|
+
"ontology.json",
|
|
259
|
+
"golden-cases-smoke.json",
|
|
260
|
+
"query-steward-smoke.json",
|
|
261
|
+
"code-knowledge-graph.json",
|
|
262
|
+
"context-pack-smoke.json"
|
|
263
|
+
],
|
|
264
|
+
lanes,
|
|
265
|
+
safetyAssertions: {
|
|
266
|
+
sourceReadOnly: true,
|
|
267
|
+
forbiddenPathsExcluded: true,
|
|
268
|
+
secretLikePathsForbidden: true,
|
|
269
|
+
externalKnowledgeBackendDisabled: true,
|
|
270
|
+
durablePromotionRequiresHumanApproval: true,
|
|
271
|
+
citationsRequired: true,
|
|
272
|
+
boundedContextOnly: true
|
|
273
|
+
},
|
|
274
|
+
blockers: [],
|
|
275
|
+
generatedAt: new Date().toISOString()
|
|
276
|
+
};
|
|
277
|
+
assertNoRawKeys(plan);
|
|
278
|
+
mkdirSync(dirname(outPath), { recursive: true });
|
|
279
|
+
writeFileSync(outPath, `${JSON.stringify(plan, null, 2)}\n`, "utf8");
|
|
280
|
+
console.log(JSON.stringify({ schema: "zob.project-dna-agentic-plan-cli.v1", planPath: relative(repoRoot, outPath).split(sep).join("/"), effectiveComputeProfile: profile, effectiveCaptureMode: effectiveCapture, laneCount: lanes.length, metadataOnly: true, childDispatchAllowed: false }, null, 2));
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
try {
|
|
284
|
+
main();
|
|
285
|
+
} catch (error) {
|
|
286
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
287
|
+
usage();
|
|
288
|
+
process.exit(1);
|
|
289
|
+
}
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
5
|
+
|
|
6
|
+
const repoRoot = process.cwd();
|
|
7
|
+
const STOPWORDS = new Set(["the", "and", "for", "with", "how", "does", "this", "that", "dans", "avec", "pour", "comment", "faire", "using", "use", "project", "style"]);
|
|
8
|
+
|
|
9
|
+
function usage() {
|
|
10
|
+
console.error(`Usage:
|
|
11
|
+
node scripts/project-dna/query-context.mjs --scan-dir <repo-relative-scan-dir> --query <text> [--out <repo-relative-json>] [--max-files 8]
|
|
12
|
+
|
|
13
|
+
Builds a bounded cited ProjectDNA context pack from scan metadata. Raw query text is hashed, not persisted.`);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function parseArgs(argv) {
|
|
17
|
+
const out = { maxFiles: 8 };
|
|
18
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
19
|
+
const arg = argv[i];
|
|
20
|
+
if (arg === "--scan-dir") out.scanDir = argv[++i];
|
|
21
|
+
else if (arg === "--query") out.query = argv[++i];
|
|
22
|
+
else if (arg === "--out") out.out = argv[++i];
|
|
23
|
+
else if (arg === "--max-files") out.maxFiles = Number(argv[++i]);
|
|
24
|
+
else if (arg === "--golden-case-id") out.goldenCaseId = argv[++i];
|
|
25
|
+
else if (arg === "--steward-report-out") out.stewardReportOut = argv[++i];
|
|
26
|
+
else if (arg === "--help" || arg === "-h") out.help = true;
|
|
27
|
+
else throw new Error(`unknown argument: ${arg}`);
|
|
28
|
+
}
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function sha256(value) {
|
|
33
|
+
return createHash("sha256").update(value).digest("hex");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function resolveRepoPath(input, label, allowMissing = false) {
|
|
37
|
+
if (!input || isAbsolute(input)) throw new Error(`${label} must be repo-relative`);
|
|
38
|
+
const resolved = resolve(repoRoot, input);
|
|
39
|
+
const rel = relative(repoRoot, resolved);
|
|
40
|
+
if (rel.startsWith("..") || rel === "") throw new Error(`${label} must stay inside repo and not be repo root`);
|
|
41
|
+
if (!allowMissing && !existsSync(resolved)) throw new Error(`${label} not found: ${input}`);
|
|
42
|
+
return resolved;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function readJson(dir, name) {
|
|
46
|
+
const path = join(dir, name);
|
|
47
|
+
if (!existsSync(path)) throw new Error(`missing scan artifact: ${name}`);
|
|
48
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function queryTerms(query) {
|
|
52
|
+
return [...new Set(String(query).toLowerCase().split(/[^a-z0-9_.$-]+/).filter((term) => term.length >= 3 && !STOPWORDS.has(term)))];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function scoreFile(file, terms, steward = {}) {
|
|
56
|
+
const haystack = [file.path, file.kind, file.language, ...(file.imports ?? []), ...(file.exports ?? [])].join(" ").toLowerCase();
|
|
57
|
+
const path = String(file.path ?? "").toLowerCase();
|
|
58
|
+
let score = 0;
|
|
59
|
+
for (const term of terms) {
|
|
60
|
+
if (haystack.includes(term)) score += 3;
|
|
61
|
+
}
|
|
62
|
+
for (const hint of steward.expectedFileHints ?? []) {
|
|
63
|
+
const normalizedHint = String(hint).toLowerCase();
|
|
64
|
+
if (normalizedHint && path.includes(normalizedHint)) score += 30;
|
|
65
|
+
}
|
|
66
|
+
if (terms.includes("queue") && file.kind === "queue") score += 8;
|
|
67
|
+
if ((terms.includes("worker") || terms.includes("job")) && file.kind === "worker") score += 8;
|
|
68
|
+
if ((terms.includes("route") || terms.includes("api") || terms.includes("controller")) && file.kind === "route") score += 8;
|
|
69
|
+
if (terms.includes("service") && file.kind === "service") score += 8;
|
|
70
|
+
if ((terms.includes("test") || terms.includes("testing") || terms.includes("vitest")) && file.kind === "test") score += 8;
|
|
71
|
+
if ((terms.includes("config") || terms.includes("configuration") || terms.includes("manifest")) && (file.kind === "config" || file.kind === "package-manifest" || file.kind === "schema")) score += 8;
|
|
72
|
+
if ((terms.includes("schema") || terms.includes("schemas")) && file.kind === "schema") score += 10;
|
|
73
|
+
if ((terms.includes("readme") || terms.includes("docs")) && (path.endsWith("readme.md") || file.language === "markdown")) score += 8;
|
|
74
|
+
if ((terms.includes("golden") || terms.includes("benchmark")) && path.includes("golden-cases")) score += 12;
|
|
75
|
+
if ((terms.includes("ontology") || terms.includes("pattern")) && path.includes("ontology")) score += 12;
|
|
76
|
+
return score;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function unique(values) {
|
|
80
|
+
return [...new Set(values.filter(Boolean))];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function readOptionalJson(path) {
|
|
84
|
+
if (!existsSync(path)) return undefined;
|
|
85
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function loadOntology(scanDir) {
|
|
89
|
+
return readOptionalJson(join(scanDir, "ontology.json")) ?? readOptionalJson(resolve(repoRoot, ".pi/factories/project-dna/pi-agentic-ontology.json"));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function loadGoldenSuite(scanDir) {
|
|
93
|
+
return readOptionalJson(join(scanDir, "golden-cases-smoke.json")) ?? readOptionalJson(resolve(repoRoot, ".pi/factories/project-dna/golden-cases-smoke.json"));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function scoreConcept(concept, terms) {
|
|
97
|
+
const haystack = [concept.id, concept.kind, ...(concept.aliases ?? []), ...(concept.expected_file_hints ?? [])].join(" ").toLowerCase();
|
|
98
|
+
return terms.filter((term) => haystack.includes(term)).length;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function stewardExpansion(scanDir, query, goldenCaseId) {
|
|
102
|
+
const ontology = loadOntology(scanDir);
|
|
103
|
+
const suite = loadGoldenSuite(scanDir);
|
|
104
|
+
const terms = queryTerms(query);
|
|
105
|
+
const explicitCase = (suite?.cases ?? []).find((testCase) => testCase.id === goldenCaseId);
|
|
106
|
+
const matchedCase = explicitCase ?? (suite?.cases ?? [])
|
|
107
|
+
.map((testCase) => ({ testCase, score: terms.filter((term) => String(testCase.query ?? "").toLowerCase().includes(term) || String(testCase.intent_id ?? "").toLowerCase().includes(term)).length }))
|
|
108
|
+
.sort((left, right) => right.score - left.score)[0]?.testCase;
|
|
109
|
+
const matchedConcept = (ontology?.concepts ?? [])
|
|
110
|
+
.map((concept) => ({ concept, score: scoreConcept(concept, terms) + (concept.id === matchedCase?.intent_id ? 5 : 0) }))
|
|
111
|
+
.sort((left, right) => right.score - left.score)[0]?.concept;
|
|
112
|
+
const intentId = explicitCase?.intent_id ?? matchedCase?.intent_id ?? matchedConcept?.id ?? "project_dna.context_lookup";
|
|
113
|
+
const expectedPatterns = unique([...(matchedCase?.expected_patterns ?? []), intentId]);
|
|
114
|
+
const expectedFileHints = unique([...(matchedConcept?.expected_file_hints ?? []), ...(matchedCase?.required_files_to_read_first ?? []), ...(matchedCase?.required_citation_includes ?? [])]);
|
|
115
|
+
const controlledTerms = unique([intentId, ...(matchedConcept?.aliases ?? []), ...expectedFileHints].map((term) => String(term).toLowerCase()));
|
|
116
|
+
return {
|
|
117
|
+
intentId,
|
|
118
|
+
confidence: explicitCase ? "high" : matchedCase || matchedConcept ? "medium" : "low",
|
|
119
|
+
goldenCaseId: explicitCase?.id ?? matchedCase?.id ?? null,
|
|
120
|
+
expectedPatterns,
|
|
121
|
+
expectedFileHints,
|
|
122
|
+
controlledTerms,
|
|
123
|
+
ontologyId: ontology?.ontology_id ?? null,
|
|
124
|
+
suiteId: suite?.suite_id ?? null,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function writeStewardReport(outRel, scanDir, queryHash, steward) {
|
|
129
|
+
const outPath = resolveRepoPath(outRel, "--steward-report-out", true);
|
|
130
|
+
const scanDirRel = relative(repoRoot, scanDir).split(sep).join("/");
|
|
131
|
+
const report = {
|
|
132
|
+
schema: "zob.project-dna-query-steward-report.v1",
|
|
133
|
+
scan_dir: scanDirRel,
|
|
134
|
+
query_hash: queryHash,
|
|
135
|
+
raw_query_persisted: false,
|
|
136
|
+
query_stored: false,
|
|
137
|
+
intent: {
|
|
138
|
+
id: steward.intentId,
|
|
139
|
+
confidence: steward.confidence,
|
|
140
|
+
golden_case_id: steward.goldenCaseId,
|
|
141
|
+
ontology_id: steward.ontologyId,
|
|
142
|
+
suite_id: steward.suiteId,
|
|
143
|
+
},
|
|
144
|
+
controlled_expansion: {
|
|
145
|
+
stored_raw_terms: false,
|
|
146
|
+
term_hashes: steward.controlledTerms.map((term) => sha256(term)),
|
|
147
|
+
term_count: steward.controlledTerms.length,
|
|
148
|
+
},
|
|
149
|
+
expected_patterns: steward.expectedPatterns,
|
|
150
|
+
expected_file_hints: steward.expectedFileHints,
|
|
151
|
+
loading_rules: {
|
|
152
|
+
bounded_context_only: true,
|
|
153
|
+
citation_required: true,
|
|
154
|
+
agent_loads_entire_project: false,
|
|
155
|
+
writeback_policy: "proposal_only",
|
|
156
|
+
},
|
|
157
|
+
safety: {
|
|
158
|
+
source_project_modified: false,
|
|
159
|
+
knowledge_backend_write_enabled: false,
|
|
160
|
+
durable_promotion_allowed: false,
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
mkdirSync(dirname(outPath), { recursive: true });
|
|
164
|
+
writeFileSync(outPath, `${JSON.stringify(report, null, 2)}\n`, "utf8");
|
|
165
|
+
return relative(repoRoot, outPath).split(sep).join("/");
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function main() {
|
|
169
|
+
const args = parseArgs(process.argv.slice(2));
|
|
170
|
+
if (args.help || !args.scanDir || !args.query) {
|
|
171
|
+
usage();
|
|
172
|
+
if (!args.help) process.exit(2);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const scanDir = resolveRepoPath(args.scanDir, "--scan-dir");
|
|
176
|
+
const baseTerms = queryTerms(args.query);
|
|
177
|
+
const queryHash = sha256(args.query);
|
|
178
|
+
const steward = stewardExpansion(scanDir, args.query, args.goldenCaseId);
|
|
179
|
+
const terms = unique([...baseTerms, ...steward.controlledTerms]);
|
|
180
|
+
const stewardReportRef = args.stewardReportOut ? writeStewardReport(args.stewardReportOut, scanDir, queryHash, steward) : null;
|
|
181
|
+
const maxFiles = Number.isFinite(args.maxFiles) && args.maxFiles > 0 ? Math.min(20, Math.floor(args.maxFiles)) : 8;
|
|
182
|
+
|
|
183
|
+
const fingerprint = readJson(scanDir, "project-fingerprint.json");
|
|
184
|
+
const fileMap = readJson(scanDir, "file-map.json");
|
|
185
|
+
const architectureMap = readJson(scanDir, "architecture-map.json");
|
|
186
|
+
const contextPack = readJson(scanDir, "context-pack-smoke.json");
|
|
187
|
+
const graph = readJson(scanDir, "code-knowledge-graph.json");
|
|
188
|
+
|
|
189
|
+
const scored = (fileMap.files ?? [])
|
|
190
|
+
.map((file) => ({ file, score: scoreFile(file, terms, steward) }))
|
|
191
|
+
.filter((item) => item.score > 0)
|
|
192
|
+
.sort((left, right) => right.score - left.score || left.file.path.localeCompare(right.file.path));
|
|
193
|
+
const selected = (scored.length > 0 ? scored : (fileMap.files ?? []).slice(0, maxFiles).map((file) => ({ file, score: 0 }))).slice(0, maxFiles);
|
|
194
|
+
const selectedCitations = unique(selected.flatMap((item) => [...(item.file.symbol_citations ?? []), ...(item.file.citations ?? [])]));
|
|
195
|
+
const architecturePatternHits = (architectureMap.patterns ?? []).filter((pattern) => {
|
|
196
|
+
const id = String(pattern.id ?? "").toLowerCase();
|
|
197
|
+
return terms.some((term) => id.includes(term)) || steward.expectedPatterns.includes(pattern.id);
|
|
198
|
+
});
|
|
199
|
+
const stewardPatternHits = steward.expectedPatterns
|
|
200
|
+
.filter((id) => !architecturePatternHits.some((pattern) => pattern.id === id))
|
|
201
|
+
.map((id) => ({ id, confidence: steward.confidence, evidence: selectedCitations.slice(0, 3), stewarded: true }));
|
|
202
|
+
const patternHits = [...architecturePatternHits, ...stewardPatternHits];
|
|
203
|
+
const graphEdges = (graph.edges ?? []).filter((edge) => selected.some((item) => edge.to === `source:${item.file.path}` || edge.from === `source:${item.file.path}`)).slice(0, 20);
|
|
204
|
+
const broadCitations = selectedCitations.filter((citation) => {
|
|
205
|
+
const match = /:L(\d+)-L?(\d+)$/.exec(String(citation));
|
|
206
|
+
return match ? Number(match[2]) - Number(match[1]) + 1 > 250 : false;
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
const result = {
|
|
210
|
+
schema: "zob.project-dna-query-result.v1",
|
|
211
|
+
source_id: fingerprint.source_id,
|
|
212
|
+
scan_dir: relative(repoRoot, scanDir).split(sep).join("/"),
|
|
213
|
+
query_hash: queryHash,
|
|
214
|
+
query_stored: false,
|
|
215
|
+
query_terms_stored: false,
|
|
216
|
+
raw_query_persisted: false,
|
|
217
|
+
answer: selected.length > 0
|
|
218
|
+
? "ProjectDNA Query Steward found bounded cited pointers in scan metadata. Read cited files before implementation."
|
|
219
|
+
: "ProjectDNA Query Steward did not find matching files; treat this as a context gap.",
|
|
220
|
+
query_steward: {
|
|
221
|
+
used: true,
|
|
222
|
+
intent_id: steward.intentId,
|
|
223
|
+
confidence: steward.confidence,
|
|
224
|
+
golden_case_id: steward.goldenCaseId,
|
|
225
|
+
report_ref: stewardReportRef,
|
|
226
|
+
raw_query_persisted: false,
|
|
227
|
+
controlled_expansion_terms_stored: false,
|
|
228
|
+
expected_patterns: steward.expectedPatterns,
|
|
229
|
+
expected_file_hint_count: steward.expectedFileHints.length,
|
|
230
|
+
controlled_expansion_term_hashes: steward.controlledTerms.map((term) => sha256(term)),
|
|
231
|
+
},
|
|
232
|
+
files_to_read_first: selected.map((item) => ({
|
|
233
|
+
path: item.file.path,
|
|
234
|
+
kind: item.file.kind,
|
|
235
|
+
score: item.score,
|
|
236
|
+
line_range: (item.file.primary_symbol_citation ?? item.file.citations?.[0])?.split(":").at(-1) ?? null,
|
|
237
|
+
reason: item.score > 0 ? "metadata_match" : "fallback_from_context_pack",
|
|
238
|
+
citations: unique([...(item.file.symbol_citations ?? []), ...(item.file.citations ?? [])]),
|
|
239
|
+
})),
|
|
240
|
+
citations: unique([...selectedCitations, ...(patternHits.flatMap((pattern) => pattern.evidence ?? [])), ...((contextPack.citations ?? []).slice(0, 4))]),
|
|
241
|
+
graph_edges: graphEdges,
|
|
242
|
+
pattern_hits: patternHits.map((pattern) => ({ id: pattern.id, confidence: pattern.confidence, evidence: pattern.evidence ?? [], stewarded: pattern.stewarded === true })),
|
|
243
|
+
citation_quality: {
|
|
244
|
+
citations_checked: selectedCitations.length,
|
|
245
|
+
broad_citation_count: broadCitations.length,
|
|
246
|
+
broad_citation_ratio: selectedCitations.length > 0 ? Number((broadCitations.length / selectedCitations.length).toFixed(3)) : 0,
|
|
247
|
+
prefers_symbol_ranges: true,
|
|
248
|
+
},
|
|
249
|
+
gaps: selected.length === 0 ? ["No files available in ProjectDNA file map."] : patternHits.length === 0 ? ["No ontology or architecture pattern id matched the query terms; use file-level citations only."] : [],
|
|
250
|
+
loading_rules: {
|
|
251
|
+
bounded_context_only: true,
|
|
252
|
+
citation_required: true,
|
|
253
|
+
agent_loads_entire_project: false,
|
|
254
|
+
writeback_policy: "proposal_only",
|
|
255
|
+
},
|
|
256
|
+
safety: {
|
|
257
|
+
scan_metadata_only: true,
|
|
258
|
+
source_project_modified: false,
|
|
259
|
+
knowledge_backend_write_enabled: false,
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
if (args.out) {
|
|
264
|
+
const outPath = resolveRepoPath(args.out, "--out", true);
|
|
265
|
+
mkdirSync(dirname(outPath), { recursive: true });
|
|
266
|
+
writeFileSync(outPath, `${JSON.stringify(result, null, 2)}\n`, "utf8");
|
|
267
|
+
}
|
|
268
|
+
console.log(JSON.stringify(result, null, 2));
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
try {
|
|
272
|
+
main();
|
|
273
|
+
} catch (error) {
|
|
274
|
+
console.error(JSON.stringify({ schema: "zob.project-dna-query-error.v1", error: error instanceof Error ? error.message : String(error), source_project_modified: false, knowledge_backend_write_enabled: false }, null, 2));
|
|
275
|
+
process.exit(1);
|
|
276
|
+
}
|