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,553 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { basename, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
5
|
+
|
|
6
|
+
const repoRoot = process.cwd();
|
|
7
|
+
const DEFAULT_FORBIDDEN = [
|
|
8
|
+
".env",
|
|
9
|
+
".env.*",
|
|
10
|
+
"*.pem",
|
|
11
|
+
"*.key",
|
|
12
|
+
"*.p12",
|
|
13
|
+
"*.pfx",
|
|
14
|
+
"id_rsa",
|
|
15
|
+
"id_ed25519",
|
|
16
|
+
"secrets",
|
|
17
|
+
"credentials",
|
|
18
|
+
"node_modules",
|
|
19
|
+
"dist",
|
|
20
|
+
"build",
|
|
21
|
+
"coverage",
|
|
22
|
+
".next",
|
|
23
|
+
".nuxt",
|
|
24
|
+
"out",
|
|
25
|
+
".git",
|
|
26
|
+
];
|
|
27
|
+
const MAX_FILE_BYTES = 256 * 1024;
|
|
28
|
+
const TEXT_EXTENSIONS = new Set([
|
|
29
|
+
".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs",
|
|
30
|
+
".json", ".md", ".yaml", ".yml", ".toml",
|
|
31
|
+
".sql", ".prisma", ".py", ".go", ".rs", ".java",
|
|
32
|
+
".kt", ".rb", ".php", ".cs", ".swift", ".vue", ".svelte",
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
function sha256(value) {
|
|
36
|
+
return createHash("sha256").update(value).digest("hex");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function usage() {
|
|
40
|
+
console.error(`Usage:
|
|
41
|
+
node scripts/project-dna/scan.mjs --manifest <project-dna-manifest.json> [--out-dir <repo-relative-dir>]
|
|
42
|
+
node scripts/project-dna/scan.mjs --source-path <path> --source-id <id> --out-dir <repo-relative-dir> [--allow-repo-root]
|
|
43
|
+
|
|
44
|
+
This scanner is read-only for the source project and writes only metadata artifacts under --out-dir.`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function parseArgs(argv) {
|
|
48
|
+
const out = { allowRepoRoot: false };
|
|
49
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
50
|
+
const arg = argv[i];
|
|
51
|
+
if (arg === "--manifest") out.manifest = argv[++i];
|
|
52
|
+
else if (arg === "--source-path") out.sourcePath = argv[++i];
|
|
53
|
+
else if (arg === "--source-id") out.sourceId = argv[++i];
|
|
54
|
+
else if (arg === "--out-dir") out.outDir = argv[++i];
|
|
55
|
+
else if (arg === "--allow-repo-root") out.allowRepoRoot = true;
|
|
56
|
+
else if (arg === "--help" || arg === "-h") out.help = true;
|
|
57
|
+
else throw new Error(`unknown argument: ${arg}`);
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function safeSourceId(value) {
|
|
63
|
+
if (typeof value !== "string" || !/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(value)) {
|
|
64
|
+
throw new Error(`source_id must be lowercase kebab-ish and path safe: ${value}`);
|
|
65
|
+
}
|
|
66
|
+
return value;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function resolveRepoOutDir(outDir) {
|
|
70
|
+
if (!outDir || isAbsolute(outDir)) throw new Error("--out-dir must be repo-relative");
|
|
71
|
+
const resolved = resolve(repoRoot, outDir);
|
|
72
|
+
const rel = relative(repoRoot, resolved);
|
|
73
|
+
if (rel.startsWith("..") || rel === "") throw new Error("--out-dir must stay inside the repo and not be repo root");
|
|
74
|
+
return resolved;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function loadManifest(manifestPath) {
|
|
78
|
+
const resolved = isAbsolute(manifestPath) ? manifestPath : resolve(repoRoot, manifestPath);
|
|
79
|
+
const rel = relative(repoRoot, resolved);
|
|
80
|
+
if (rel.startsWith("..")) throw new Error("manifest must be repo-local for P0 ProjectDNA scans");
|
|
81
|
+
const parsed = JSON.parse(readFileSync(resolved, "utf8"));
|
|
82
|
+
if (parsed.schema !== "zob.project-dna-manifest.v1") throw new Error("manifest schema must be zob.project-dna-manifest.v1");
|
|
83
|
+
const sourceId = safeSourceId(parsed.source_project?.source_id);
|
|
84
|
+
const sourcePath = parsed.source_project?.path;
|
|
85
|
+
if (typeof sourcePath !== "string" || sourcePath.length === 0) throw new Error("manifest source_project.path is required");
|
|
86
|
+
const allowedPaths = Array.isArray(parsed.read_policy?.allowed_paths) ? parsed.read_policy.allowed_paths : [];
|
|
87
|
+
if (allowedPaths.length === 0) throw new Error("manifest read_policy.allowed_paths must be non-empty");
|
|
88
|
+
const forbiddenPatterns = Array.isArray(parsed.read_policy?.forbidden_patterns) ? parsed.read_policy.forbidden_patterns : DEFAULT_FORBIDDEN;
|
|
89
|
+
return { sourceId, sourcePath, allowedPaths, forbiddenPatterns };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function isInsideOrEqual(parent, child) {
|
|
93
|
+
const rel = relative(parent, child);
|
|
94
|
+
return rel === "" || (!rel.startsWith("..") && !isAbsolute(rel));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function broadRootError(path, label) {
|
|
98
|
+
const broadRoots = new Set(["/", "/home", "/home/ubuntu"]);
|
|
99
|
+
if (broadRoots.has(path)) return `refusing broad ${label}: ${path}`;
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function assertSafeSourceRoot(sourceRoot, options) {
|
|
104
|
+
if (!existsSync(sourceRoot)) throw new Error(`source path does not exist: ${sourceRoot}`);
|
|
105
|
+
const stat = statSync(sourceRoot);
|
|
106
|
+
if (!stat.isDirectory()) throw new Error(`source path must be a directory: ${sourceRoot}`);
|
|
107
|
+
const broadError = broadRootError(sourceRoot, "source root");
|
|
108
|
+
if (broadError) throw new Error(broadError);
|
|
109
|
+
if (!options.allowRepoRoot && sourceRoot === repoRoot) throw new Error("refusing repo root scan without --allow-repo-root; pass a bounded project subdir instead");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function assertSourceAllowedByManifest(sourceRoot, allowedPaths) {
|
|
113
|
+
if (!Array.isArray(allowedPaths) || allowedPaths.length === 0) throw new Error("manifest read_policy.allowed_paths must be non-empty");
|
|
114
|
+
const resolvedAllowed = allowedPaths.map((allowedPath) => resolve(String(allowedPath)));
|
|
115
|
+
for (const allowedRoot of resolvedAllowed) {
|
|
116
|
+
const broadError = broadRootError(allowedRoot, "allowed path");
|
|
117
|
+
if (broadError) throw new Error(broadError);
|
|
118
|
+
if (isInsideOrEqual(allowedRoot, sourceRoot)) return;
|
|
119
|
+
}
|
|
120
|
+
throw new Error(`source_project.path must be inside one manifest read_policy.allowed_paths entry; source=${sourceRoot}`);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function segmentMatchesForbidden(segment, pattern) {
|
|
124
|
+
if (pattern.endsWith("/*")) return segment === pattern.slice(0, -2);
|
|
125
|
+
if (pattern.startsWith("*")) return segment.endsWith(pattern.slice(1));
|
|
126
|
+
if (pattern.endsWith("*")) return segment.startsWith(pattern.slice(0, -1));
|
|
127
|
+
return segment === pattern;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function pathForbidden(relPath, forbiddenPatterns = DEFAULT_FORBIDDEN) {
|
|
131
|
+
const normalized = relPath.split(sep).join("/");
|
|
132
|
+
const segments = normalized.split("/").filter(Boolean);
|
|
133
|
+
for (const pattern of forbiddenPatterns) {
|
|
134
|
+
if (!pattern) continue;
|
|
135
|
+
const clean = String(pattern).replace(/\\/g, "/").replace(/\/$/, "");
|
|
136
|
+
if (clean.includes("/")) {
|
|
137
|
+
if (normalized === clean || normalized.startsWith(`${clean}/`)) return clean;
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
for (const segment of segments) {
|
|
141
|
+
if (segmentMatchesForbidden(segment, clean)) return clean;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function languageFor(path) {
|
|
148
|
+
const ext = extname(path).toLowerCase();
|
|
149
|
+
const map = {
|
|
150
|
+
".ts": "typescript",
|
|
151
|
+
".tsx": "typescript",
|
|
152
|
+
".js": "javascript",
|
|
153
|
+
".jsx": "javascript",
|
|
154
|
+
".mjs": "javascript",
|
|
155
|
+
".cjs": "javascript",
|
|
156
|
+
".json": "json",
|
|
157
|
+
".md": "markdown",
|
|
158
|
+
".yaml": "yaml",
|
|
159
|
+
".yml": "yaml",
|
|
160
|
+
".toml": "toml",
|
|
161
|
+
".sql": "sql",
|
|
162
|
+
".prisma": "prisma",
|
|
163
|
+
".py": "python",
|
|
164
|
+
".go": "go",
|
|
165
|
+
".rs": "rust",
|
|
166
|
+
".java": "java",
|
|
167
|
+
".kt": "kotlin",
|
|
168
|
+
".rb": "ruby",
|
|
169
|
+
".php": "php",
|
|
170
|
+
".cs": "csharp",
|
|
171
|
+
".swift": "swift",
|
|
172
|
+
".vue": "vue",
|
|
173
|
+
".svelte": "svelte",
|
|
174
|
+
};
|
|
175
|
+
return map[ext] ?? "text";
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function classifyKind(relPath) {
|
|
179
|
+
const lower = relPath.toLowerCase();
|
|
180
|
+
if (/(__tests__|\.test\.|\.spec\.|tests?\/)/.test(lower)) return "test";
|
|
181
|
+
if (/(config|settings|env|redis|database)\./.test(lower) || lower.includes("/config/")) return "config";
|
|
182
|
+
if (/(route|router|controller)\./.test(lower) || lower.includes("/routes/") || lower.includes("/controllers/")) return "route";
|
|
183
|
+
if (/service\./.test(lower) || lower.includes("/services/")) return "service";
|
|
184
|
+
if (/(worker|processor)\./.test(lower) || lower.includes("/workers/")) return "worker";
|
|
185
|
+
if (/(queue|job)\./.test(lower) || lower.includes("/queues/") || lower.includes("/jobs/")) return "queue";
|
|
186
|
+
if (lower.includes("/schemas/") || lower.endsWith(".schema.json")) return "schema";
|
|
187
|
+
if (/(model|migration|prisma)/.test(lower) || lower.includes("/db/") || lower.includes("/database/")) return "database";
|
|
188
|
+
if (/(index|main|server|app)\.(ts|tsx|js|jsx|mjs|cjs)$/.test(lower)) return "entrypoint";
|
|
189
|
+
if (lower.endsWith("package.json")) return "package-manifest";
|
|
190
|
+
return "source";
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function walk(root, forbiddenPatterns) {
|
|
194
|
+
const files = [];
|
|
195
|
+
const skipped = [];
|
|
196
|
+
function visit(dir) {
|
|
197
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
198
|
+
const full = join(dir, entry.name);
|
|
199
|
+
const relPath = relative(root, full);
|
|
200
|
+
const forbidden = pathForbidden(relPath, forbiddenPatterns);
|
|
201
|
+
if (forbidden) {
|
|
202
|
+
skipped.push({ path: relPath.split(sep).join("/"), reason: `forbidden:${forbidden}`, directory: entry.isDirectory() });
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
if (entry.isDirectory()) {
|
|
206
|
+
visit(full);
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
if (!entry.isFile()) {
|
|
210
|
+
skipped.push({ path: relPath.split(sep).join("/"), reason: "not_regular_file" });
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
const ext = extname(entry.name).toLowerCase();
|
|
214
|
+
const size = statSync(full).size;
|
|
215
|
+
if (!TEXT_EXTENSIONS.has(ext)) {
|
|
216
|
+
skipped.push({ path: relPath.split(sep).join("/"), reason: "unsupported_extension" });
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
if (size > MAX_FILE_BYTES) {
|
|
220
|
+
skipped.push({ path: relPath.split(sep).join("/"), reason: `too_large>${MAX_FILE_BYTES}` });
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
files.push({ full, relPath: relPath.split(sep).join("/"), size });
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
visit(root);
|
|
227
|
+
return { files, skipped };
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function readText(path) {
|
|
231
|
+
return readFileSync(path, "utf8");
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function extractImports(text) {
|
|
235
|
+
const imports = [];
|
|
236
|
+
const patterns = [
|
|
237
|
+
/import\s+(?:type\s+)?[\s\S]*?\s+from\s+["']([^"']+)["']/g,
|
|
238
|
+
/import\s*\(\s*["']([^"']+)["']\s*\)/g,
|
|
239
|
+
/require\s*\(\s*["']([^"']+)["']\s*\)/g,
|
|
240
|
+
];
|
|
241
|
+
for (const pattern of patterns) {
|
|
242
|
+
let match;
|
|
243
|
+
while ((match = pattern.exec(text))) imports.push(match[1]);
|
|
244
|
+
}
|
|
245
|
+
return [...new Set(imports)].sort();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function estimateSymbolEndLine(lines, startIndex) {
|
|
249
|
+
const startLine = lines[startIndex] ?? "";
|
|
250
|
+
const startsBlock = startLine.includes("{") || startLine.trim().endsWith("=>") || startLine.trim().endsWith("=");
|
|
251
|
+
if (!startsBlock) return startIndex + 1;
|
|
252
|
+
let braceDepth = 0;
|
|
253
|
+
let sawBrace = false;
|
|
254
|
+
for (let index = startIndex; index < Math.min(lines.length, startIndex + 240); index += 1) {
|
|
255
|
+
const line = lines[index].replace(/(['"`]).*?\1/g, "");
|
|
256
|
+
for (const char of line) {
|
|
257
|
+
if (char === "{") {
|
|
258
|
+
braceDepth += 1;
|
|
259
|
+
sawBrace = true;
|
|
260
|
+
} else if (char === "}") {
|
|
261
|
+
braceDepth -= 1;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (sawBrace && braceDepth <= 0 && index > startIndex) return index + 1;
|
|
265
|
+
}
|
|
266
|
+
return startIndex + 1;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function extractSymbols(text, relPath) {
|
|
270
|
+
const symbols = [];
|
|
271
|
+
const lines = text.split(/\r?\n/);
|
|
272
|
+
const symbolPatterns = [
|
|
273
|
+
{ type: "class", re: /\bexport\s+class\s+([A-Za-z_$][\w$]*)|\bclass\s+([A-Za-z_$][\w$]*)/ },
|
|
274
|
+
{ type: "function", re: /\bexport\s+(?:async\s+)?function\s+([A-Za-z_$][\w$]*)|\b(?:async\s+)?function\s+([A-Za-z_$][\w$]*)/ },
|
|
275
|
+
{ type: "interface", re: /\bexport\s+interface\s+([A-Za-z_$][\w$]*)|\binterface\s+([A-Za-z_$][\w$]*)/ },
|
|
276
|
+
{ type: "type", re: /\bexport\s+type\s+([A-Za-z_$][\w$]*)|\btype\s+([A-Za-z_$][\w$]*)/ },
|
|
277
|
+
{ type: "const", re: /\bexport\s+const\s+([A-Za-z_$][\w$]*)|\bconst\s+([A-Za-z_$][\w$]*)\s*=/ },
|
|
278
|
+
];
|
|
279
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
280
|
+
const line = lines[index];
|
|
281
|
+
for (const { type, re } of symbolPatterns) {
|
|
282
|
+
const match = re.exec(line);
|
|
283
|
+
const name = match?.[1] ?? match?.[2];
|
|
284
|
+
if (name) {
|
|
285
|
+
const endLine = Math.max(index + 1, estimateSymbolEndLine(lines, index));
|
|
286
|
+
symbols.push({
|
|
287
|
+
symbol_id: `${relPath}::${name}`,
|
|
288
|
+
name,
|
|
289
|
+
qualified_name: name,
|
|
290
|
+
type,
|
|
291
|
+
file: relPath,
|
|
292
|
+
start_line: index + 1,
|
|
293
|
+
end_line: endLine,
|
|
294
|
+
citations: [`${relPath}:L${index + 1}-L${endLine}`],
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return symbols;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function parsePackageJson(sourceRoot) {
|
|
303
|
+
const packagePath = join(sourceRoot, "package.json");
|
|
304
|
+
if (!existsSync(packagePath)) return { package_manager: null, runtime_dependencies: [], dev_dependencies: [], scripts: {} };
|
|
305
|
+
const parsed = JSON.parse(readText(packagePath));
|
|
306
|
+
const runtime = Object.keys(parsed.dependencies ?? {}).sort();
|
|
307
|
+
const dev = Object.keys(parsed.devDependencies ?? {}).sort();
|
|
308
|
+
let packageManager = null;
|
|
309
|
+
for (const marker of ["pnpm-lock.yaml", "yarn.lock", "package-lock.json", "bun.lockb", "bun.lock"]) {
|
|
310
|
+
if (existsSync(join(sourceRoot, marker))) packageManager = marker.startsWith("pnpm") ? "pnpm" : marker.startsWith("yarn") ? "yarn" : marker.startsWith("bun") ? "bun" : "npm";
|
|
311
|
+
}
|
|
312
|
+
return { package_manager: packageManager, runtime_dependencies: runtime, dev_dependencies: dev, scripts: parsed.scripts ?? {} };
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function dependencyRoles(deps) {
|
|
316
|
+
const roleMap = {
|
|
317
|
+
bullmq: "queue",
|
|
318
|
+
fastify: "api",
|
|
319
|
+
express: "api",
|
|
320
|
+
hapi: "api",
|
|
321
|
+
koa: "api",
|
|
322
|
+
next: "web-framework",
|
|
323
|
+
react: "ui",
|
|
324
|
+
vue: "ui",
|
|
325
|
+
svelte: "ui",
|
|
326
|
+
prisma: "database",
|
|
327
|
+
drizzle: "database",
|
|
328
|
+
typeorm: "database",
|
|
329
|
+
mongoose: "database",
|
|
330
|
+
zod: "validation",
|
|
331
|
+
yup: "validation",
|
|
332
|
+
vitest: "testing",
|
|
333
|
+
jest: "testing",
|
|
334
|
+
mocha: "testing",
|
|
335
|
+
eslint: "linting",
|
|
336
|
+
prettier: "formatting",
|
|
337
|
+
typescript: "language",
|
|
338
|
+
};
|
|
339
|
+
return deps.filter((name) => roleMap[name]).map((name) => ({ name, role: roleMap[name] }));
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function main() {
|
|
343
|
+
const args = parseArgs(process.argv.slice(2));
|
|
344
|
+
if (args.help) {
|
|
345
|
+
usage();
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
let sourceId;
|
|
350
|
+
let sourcePath;
|
|
351
|
+
let forbiddenPatterns = DEFAULT_FORBIDDEN;
|
|
352
|
+
let manifestAllowedPaths = [];
|
|
353
|
+
if (args.manifest) {
|
|
354
|
+
const manifest = loadManifest(args.manifest);
|
|
355
|
+
sourceId = manifest.sourceId;
|
|
356
|
+
sourcePath = manifest.sourcePath;
|
|
357
|
+
manifestAllowedPaths = manifest.allowedPaths;
|
|
358
|
+
forbiddenPatterns = [...new Set([...DEFAULT_FORBIDDEN, ...manifest.forbiddenPatterns])];
|
|
359
|
+
} else {
|
|
360
|
+
if (!args.sourcePath || !args.sourceId || !args.outDir) {
|
|
361
|
+
usage();
|
|
362
|
+
process.exit(2);
|
|
363
|
+
}
|
|
364
|
+
sourceId = safeSourceId(args.sourceId);
|
|
365
|
+
sourcePath = args.sourcePath;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
const sourceRoot = resolve(sourcePath);
|
|
369
|
+
assertSafeSourceRoot(sourceRoot, args);
|
|
370
|
+
if (args.manifest) assertSourceAllowedByManifest(sourceRoot, manifestAllowedPaths);
|
|
371
|
+
const outDir = resolveRepoOutDir(args.outDir ?? `reports/project-dna-scans/${sourceId}`);
|
|
372
|
+
const outRel = relative(repoRoot, outDir);
|
|
373
|
+
if (relative(sourceRoot, outDir) && !relative(sourceRoot, outDir).startsWith("..")) {
|
|
374
|
+
throw new Error("--out-dir must not be inside the source project");
|
|
375
|
+
}
|
|
376
|
+
mkdirSync(outDir, { recursive: true });
|
|
377
|
+
|
|
378
|
+
const { files, skipped } = walk(sourceRoot, forbiddenPatterns);
|
|
379
|
+
const languages = {};
|
|
380
|
+
const fileEntries = [];
|
|
381
|
+
const importEdges = [];
|
|
382
|
+
const allSymbols = [];
|
|
383
|
+
const kindCounts = {};
|
|
384
|
+
|
|
385
|
+
for (const file of files) {
|
|
386
|
+
const text = readText(file.full);
|
|
387
|
+
const lines = text.split(/\r?\n/);
|
|
388
|
+
const language = languageFor(file.relPath);
|
|
389
|
+
const kind = classifyKind(file.relPath);
|
|
390
|
+
languages[language] = (languages[language] ?? 0) + 1;
|
|
391
|
+
kindCounts[kind] = (kindCounts[kind] ?? 0) + 1;
|
|
392
|
+
const imports = extractImports(text);
|
|
393
|
+
for (const target of imports) importEdges.push({ from: file.relPath, to: target, type: "imports", citations: [`${file.relPath}:L1-L${lines.length}`] });
|
|
394
|
+
const symbols = extractSymbols(text, file.relPath);
|
|
395
|
+
allSymbols.push(...symbols);
|
|
396
|
+
fileEntries.push({
|
|
397
|
+
path: file.relPath,
|
|
398
|
+
language,
|
|
399
|
+
kind,
|
|
400
|
+
imports,
|
|
401
|
+
exports: symbols.map((symbol) => symbol.name),
|
|
402
|
+
symbol_citations: symbols.flatMap((symbol) => symbol.citations).slice(0, 20),
|
|
403
|
+
primary_symbol_citation: symbols[0]?.citations?.[0] ?? null,
|
|
404
|
+
lines: lines.length,
|
|
405
|
+
bytes: file.size,
|
|
406
|
+
citations: [`${file.relPath}:L1-L${lines.length}`],
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
const packageInfo = parsePackageJson(sourceRoot);
|
|
411
|
+
const allDeps = [...new Set([...packageInfo.runtime_dependencies, ...packageInfo.dev_dependencies])].sort();
|
|
412
|
+
const frameworks = dependencyRoles(allDeps).filter((item) => ["api", "web-framework", "ui", "queue", "database"].includes(item.role)).map((item) => item.name);
|
|
413
|
+
const patterns = [];
|
|
414
|
+
if (allDeps.includes("bullmq") || importEdges.some((edge) => String(edge.to).includes("bullmq"))) patterns.push({ id: "pattern.queue.bullmq", confidence: "medium", evidence: importEdges.filter((edge) => String(edge.to).includes("bullmq")).slice(0, 5).map((edge) => edge.citations[0]) });
|
|
415
|
+
if ((kindCounts.service ?? 0) > 0 && (kindCounts.route ?? 0) > 0) patterns.push({ id: "pattern.architecture.route-service-split", confidence: "medium", evidence: fileEntries.filter((file) => file.kind === "service" || file.kind === "route").slice(0, 8).flatMap((file) => file.citations) });
|
|
416
|
+
if ((kindCounts.config ?? 0) > 0) patterns.push({ id: "pattern.config.centralized", confidence: "low", evidence: fileEntries.filter((file) => file.kind === "config").slice(0, 8).flatMap((file) => file.citations) });
|
|
417
|
+
if ((kindCounts.test ?? 0) > 0) patterns.push({ id: "pattern.testing.present", confidence: "low", evidence: fileEntries.filter((file) => file.kind === "test").slice(0, 8).flatMap((file) => file.citations) });
|
|
418
|
+
|
|
419
|
+
const fingerprint = {
|
|
420
|
+
schema: "zob.project-fingerprint.v1",
|
|
421
|
+
source_id: sourceId,
|
|
422
|
+
root_hash: sha256(`${sourceId}:${basename(sourceRoot)}:${files.length}`),
|
|
423
|
+
files_scanned: files.length,
|
|
424
|
+
files_skipped: skipped.length,
|
|
425
|
+
languages,
|
|
426
|
+
package_managers: packageInfo.package_manager ? [packageInfo.package_manager] : [],
|
|
427
|
+
frameworks_detected: frameworks,
|
|
428
|
+
secret_scan: {
|
|
429
|
+
forbidden_paths_skipped: skipped.some((item) => String(item.reason).startsWith("forbidden:")),
|
|
430
|
+
secret_like_artifacts_included: false,
|
|
431
|
+
skipped_patterns: forbiddenPatterns,
|
|
432
|
+
},
|
|
433
|
+
generated_at: new Date().toISOString(),
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
const dependencyMap = {
|
|
437
|
+
schema: "zob.dependency-map.v1",
|
|
438
|
+
source_id: sourceId,
|
|
439
|
+
package_manager: packageInfo.package_manager,
|
|
440
|
+
runtime_dependencies: packageInfo.runtime_dependencies,
|
|
441
|
+
dev_dependencies: packageInfo.dev_dependencies,
|
|
442
|
+
scripts: packageInfo.scripts,
|
|
443
|
+
tool_roles: dependencyRoles(allDeps),
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
const fileMap = { schema: "zob.file-map.v1", source_id: sourceId, files: fileEntries };
|
|
447
|
+
const symbolMap = { schema: "zob.symbol-map.v1", source_id: sourceId, symbols: allSymbols };
|
|
448
|
+
const importGraph = { schema: "zob.import-graph.v1", source_id: sourceId, edges: importEdges };
|
|
449
|
+
const architectureMap = {
|
|
450
|
+
schema: "zob.architecture-map.v1",
|
|
451
|
+
source_id: sourceId,
|
|
452
|
+
kind_counts: kindCounts,
|
|
453
|
+
top_level_directories: [...new Set(fileEntries.map((file) => file.path.split("/")[0]).filter(Boolean))].sort(),
|
|
454
|
+
patterns,
|
|
455
|
+
citations: fileEntries.slice(0, 12).flatMap((file) => file.citations),
|
|
456
|
+
gaps: patterns.length === 0 ? ["No high-confidence architecture patterns detected by deterministic P1 scanner."] : [],
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
const mapForKind = (schema, kinds) => {
|
|
460
|
+
const wanted = new Set(kinds);
|
|
461
|
+
const matched = fileEntries.filter((file) => wanted.has(file.kind));
|
|
462
|
+
return {
|
|
463
|
+
schema,
|
|
464
|
+
source_id: sourceId,
|
|
465
|
+
files: matched.map((file) => ({ path: file.path, kind: file.kind, language: file.language, citations: file.citations, symbol_citations: file.symbol_citations.slice(0, 8) })),
|
|
466
|
+
citations: matched.slice(0, 12).flatMap((file) => file.citations),
|
|
467
|
+
gaps: matched.length === 0 ? [`No ${kinds.join("/")} files detected by deterministic scanner.`] : [],
|
|
468
|
+
source_project_modified: false,
|
|
469
|
+
knowledge_backend_write_enabled: false,
|
|
470
|
+
};
|
|
471
|
+
};
|
|
472
|
+
const routeMap = mapForKind("zob.route-map.v1", ["route"]);
|
|
473
|
+
const queueMap = mapForKind("zob.queue-map.v1", ["queue", "worker"]);
|
|
474
|
+
const configMap = mapForKind("zob.config-map.v1", ["config", "package-manifest"]);
|
|
475
|
+
const testMap = mapForKind("zob.test-map.v1", ["test"]);
|
|
476
|
+
const dbMap = mapForKind("zob.db-map.v1", ["database"]);
|
|
477
|
+
|
|
478
|
+
const graphNodes = [
|
|
479
|
+
{ id: `source:${sourceId}`, type: "SourceProject", label: sourceId },
|
|
480
|
+
...fileEntries.map((file) => ({ id: `source:${file.path}`, type: "File", label: basename(file.path), path: file.path })),
|
|
481
|
+
...patterns.map((pattern) => ({ id: pattern.id, type: "Pattern", label: pattern.id, confidence: pattern.confidence })),
|
|
482
|
+
];
|
|
483
|
+
const graphEdges = [
|
|
484
|
+
...fileEntries.map((file) => ({ from: `source:${sourceId}`, to: `source:${file.path}`, type: "contains", citations: file.citations })),
|
|
485
|
+
...patterns.flatMap((pattern) => (pattern.evidence ?? []).map((citation) => {
|
|
486
|
+
const file = String(citation).split(":L")[0];
|
|
487
|
+
return { from: pattern.id, to: `source:${file}`, type: "implements_pattern", citations: [citation] };
|
|
488
|
+
})),
|
|
489
|
+
];
|
|
490
|
+
const codeKnowledgeGraph = {
|
|
491
|
+
schema: "zob.code-knowledge-graph.v1",
|
|
492
|
+
source_id: sourceId,
|
|
493
|
+
nodes: graphNodes,
|
|
494
|
+
edges: graphEdges,
|
|
495
|
+
citation_required: true,
|
|
496
|
+
promotion: { writeback_policy: "proposal_only", oracle_required: true, human_approval_required: true },
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
const contextPack = {
|
|
500
|
+
schema: "zob.project-dna-context-pack.v1",
|
|
501
|
+
query_hash: sha256(`project-dna-smoke:${sourceId}`),
|
|
502
|
+
query_stored: false,
|
|
503
|
+
answer: patterns.length > 0 ? "Deterministic ProjectDNA scanner found initial code/architecture signals; read cited files before synthesis." : "No high-confidence pattern detected; use file/dependency maps as initial context only.",
|
|
504
|
+
citations: fileEntries.slice(0, 8).flatMap((file) => file.citations),
|
|
505
|
+
files_to_read_first: fileEntries.slice(0, 8).map((file) => ({ path: file.path, line_range: file.citations[0].split(":").at(-1), reason: file.kind, citations: file.citations })),
|
|
506
|
+
rules: ["bounded_context_only", "citation_required", "source_project_read_only", "writeback_proposal_only"],
|
|
507
|
+
gaps: architectureMap.gaps,
|
|
508
|
+
max_context_tokens: 4000,
|
|
509
|
+
loading_rules: { bounded_context_only: true, citation_required: true, agent_loads_entire_project: false, writeback_policy: "proposal_only" },
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
const artifacts = {
|
|
513
|
+
"project-fingerprint.json": fingerprint,
|
|
514
|
+
"dependency-map.json": dependencyMap,
|
|
515
|
+
"file-map.json": fileMap,
|
|
516
|
+
"symbol-map.json": symbolMap,
|
|
517
|
+
"import-graph.json": importGraph,
|
|
518
|
+
"architecture-map.json": architectureMap,
|
|
519
|
+
"route-map.json": routeMap,
|
|
520
|
+
"queue-map.json": queueMap,
|
|
521
|
+
"config-map.json": configMap,
|
|
522
|
+
"test-map.json": testMap,
|
|
523
|
+
"db-map.json": dbMap,
|
|
524
|
+
"code-knowledge-graph.json": codeKnowledgeGraph,
|
|
525
|
+
"context-pack-smoke.json": contextPack,
|
|
526
|
+
"skipped-files.json": { schema: "zob.project-dna-skipped-files.v1", source_id: sourceId, skipped },
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
for (const [name, artifact] of Object.entries(artifacts)) {
|
|
530
|
+
writeFileSync(join(outDir, name), `${JSON.stringify(artifact, null, 2)}\n`, "utf8");
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
const summary = {
|
|
534
|
+
schema: "zob.project-dna-scan-summary.v1",
|
|
535
|
+
source_id: sourceId,
|
|
536
|
+
out_dir: outRel.split(sep).join("/"),
|
|
537
|
+
files_scanned: files.length,
|
|
538
|
+
files_skipped: skipped.length,
|
|
539
|
+
artifacts: Object.keys(artifacts).sort(),
|
|
540
|
+
no_external_writes: true,
|
|
541
|
+
source_project_modified: false,
|
|
542
|
+
knowledge_backend_write_enabled: false,
|
|
543
|
+
};
|
|
544
|
+
writeFileSync(join(outDir, "scan-summary.json"), `${JSON.stringify(summary, null, 2)}\n`, "utf8");
|
|
545
|
+
console.log(JSON.stringify(summary, null, 2));
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
try {
|
|
549
|
+
main();
|
|
550
|
+
} catch (error) {
|
|
551
|
+
console.error(JSON.stringify({ schema: "zob.project-dna-scan-error.v1", error: error instanceof Error ? error.message : String(error), source_project_modified: false, knowledge_backend_write_enabled: false }, null, 2));
|
|
552
|
+
process.exit(1);
|
|
553
|
+
}
|