@dommaker/harness 1.7.0 → 1.8.1
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/CHANGELOG.md +44 -0
- package/bin/harness.js +17 -1
- package/dist/agents/index.d.ts +6 -2
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +6 -16
- package/dist/agents/index.js.map +1 -1
- package/dist/cli/commands/__tests__/gate-decision.d.ts +18 -0
- package/dist/cli/commands/__tests__/gate-decision.d.ts.map +1 -0
- package/dist/cli/commands/__tests__/gate-decision.js +26 -0
- package/dist/cli/commands/__tests__/gate-decision.js.map +1 -0
- package/dist/cli/commands/acceptance.d.ts.map +1 -1
- package/dist/cli/commands/acceptance.js +17 -28
- package/dist/cli/commands/acceptance.js.map +1 -1
- package/dist/cli/commands/check.d.ts +19 -3
- package/dist/cli/commands/check.d.ts.map +1 -1
- package/dist/cli/commands/check.js +36 -22
- package/dist/cli/commands/check.js.map +1 -1
- package/dist/cli/commands/command.d.ts +0 -1
- package/dist/cli/commands/command.d.ts.map +1 -1
- package/dist/cli/commands/command.js +8 -6
- package/dist/cli/commands/command.js.map +1 -1
- package/dist/cli/commands/constraints-retire.d.ts.map +1 -1
- package/dist/cli/commands/constraints-retire.js +36 -57
- package/dist/cli/commands/constraints-retire.js.map +1 -1
- package/dist/cli/commands/contract.d.ts.map +1 -1
- package/dist/cli/commands/contract.js +36 -42
- package/dist/cli/commands/contract.js.map +1 -1
- package/dist/cli/commands/definitions.d.ts +2 -0
- package/dist/cli/commands/definitions.d.ts.map +1 -1
- package/dist/cli/commands/definitions.js +11 -6
- package/dist/cli/commands/definitions.js.map +1 -1
- package/dist/cli/commands/failure.d.ts.map +1 -1
- package/dist/cli/commands/failure.js +16 -2
- package/dist/cli/commands/failure.js.map +1 -1
- package/dist/cli/commands/init.d.ts +14 -8
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +172 -364
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/knowledge-view.d.ts +90 -0
- package/dist/cli/commands/knowledge-view.d.ts.map +1 -0
- package/dist/cli/commands/knowledge-view.js +198 -0
- package/dist/cli/commands/knowledge-view.js.map +1 -0
- package/dist/cli/commands/knowledge.d.ts +137 -52
- package/dist/cli/commands/knowledge.d.ts.map +1 -1
- package/dist/cli/commands/knowledge.js +534 -400
- package/dist/cli/commands/knowledge.js.map +1 -1
- package/dist/cli/commands/passes-gate.d.ts +4 -1
- package/dist/cli/commands/passes-gate.d.ts.map +1 -1
- package/dist/cli/commands/passes-gate.js +11 -2
- package/dist/cli/commands/passes-gate.js.map +1 -1
- package/dist/cli/commands/performance.d.ts.map +1 -1
- package/dist/cli/commands/performance.js +19 -31
- package/dist/cli/commands/performance.js.map +1 -1
- package/dist/cli/commands/report.d.ts.map +1 -1
- package/dist/cli/commands/report.js +2 -1
- package/dist/cli/commands/report.js.map +1 -1
- package/dist/cli/commands/review.d.ts.map +1 -1
- package/dist/cli/commands/review.js +13 -25
- package/dist/cli/commands/review.js.map +1 -1
- package/dist/cli/commands/scaffold-templates.d.ts +73 -0
- package/dist/cli/commands/scaffold-templates.d.ts.map +1 -0
- package/dist/cli/commands/scaffold-templates.js +424 -0
- package/dist/cli/commands/scaffold-templates.js.map +1 -0
- package/dist/cli/commands/scaffold.d.ts +105 -0
- package/dist/cli/commands/scaffold.d.ts.map +1 -0
- package/dist/cli/commands/scaffold.js +263 -0
- package/dist/cli/commands/scaffold.js.map +1 -0
- package/dist/cli/commands/security.d.ts.map +1 -1
- package/dist/cli/commands/security.js +22 -24
- package/dist/cli/commands/security.js.map +1 -1
- package/dist/cli/commands/spec-baseline-check.d.ts +43 -0
- package/dist/cli/commands/spec-baseline-check.d.ts.map +1 -1
- package/dist/cli/commands/spec-baseline-check.js +109 -34
- package/dist/cli/commands/spec-baseline-check.js.map +1 -1
- package/dist/cli/commands/status.d.ts +8 -0
- package/dist/cli/commands/status.d.ts.map +1 -1
- package/dist/cli/commands/status.js +5 -7
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/cli/commands/sync-docs/context-syncer.d.ts +21 -2
- package/dist/cli/commands/sync-docs/context-syncer.d.ts.map +1 -1
- package/dist/cli/commands/sync-docs/context-syncer.js +112 -28
- package/dist/cli/commands/sync-docs/context-syncer.js.map +1 -1
- package/dist/cli/commands/sync-docs/index.d.ts +1 -1
- package/dist/cli/commands/sync-docs/index.d.ts.map +1 -1
- package/dist/cli/commands/sync-docs/index.js +86 -27
- package/dist/cli/commands/sync-docs/index.js.map +1 -1
- package/dist/cli/commands/sync-docs/project-reader.d.ts +24 -1
- package/dist/cli/commands/sync-docs/project-reader.d.ts.map +1 -1
- package/dist/cli/commands/sync-docs/project-reader.js +33 -7
- package/dist/cli/commands/sync-docs/project-reader.js.map +1 -1
- package/dist/cli/commands/validate.d.ts +0 -16
- package/dist/cli/commands/validate.d.ts.map +1 -1
- package/dist/cli/commands/validate.js +2 -97
- package/dist/cli/commands/validate.js.map +1 -1
- package/dist/cli/gate-command.d.ts +37 -0
- package/dist/cli/gate-command.d.ts.map +1 -0
- package/dist/cli/gate-command.js +64 -0
- package/dist/cli/gate-command.js.map +1 -0
- package/dist/cli/state-io.d.ts +34 -0
- package/dist/cli/state-io.d.ts.map +1 -0
- package/dist/cli/state-io.js +71 -0
- package/dist/cli/state-io.js.map +1 -0
- package/dist/completion-checkers/index.d.ts +1 -1
- package/dist/completion-checkers/index.d.ts.map +1 -1
- package/dist/completion-checkers/index.js +0 -15
- package/dist/completion-checkers/index.js.map +1 -1
- package/dist/context/knowledge-injector.d.ts +4 -2
- package/dist/context/knowledge-injector.d.ts.map +1 -1
- package/dist/context/knowledge-injector.js +13 -6
- package/dist/context/knowledge-injector.js.map +1 -1
- package/dist/core/constraints/agent-prompt-renderer.js +2 -2
- package/dist/core/constraints/agent-prompt-renderer.js.map +1 -1
- package/dist/core/constraints/capabilities-reconcile.d.ts +20 -0
- package/dist/core/constraints/capabilities-reconcile.d.ts.map +1 -1
- package/dist/core/constraints/capabilities-reconcile.js +26 -4
- package/dist/core/constraints/capabilities-reconcile.js.map +1 -1
- package/dist/core/constraints/check-cache.d.ts +1 -1
- package/dist/core/constraints/check-cache.js +1 -1
- package/dist/core/constraints/checker.d.ts +8 -3
- package/dist/core/constraints/checker.d.ts.map +1 -1
- package/dist/core/constraints/checker.js +30 -19
- package/dist/core/constraints/checker.js.map +1 -1
- package/dist/core/constraints/checkers/capability-sync.d.ts +3 -1
- package/dist/core/constraints/checkers/capability-sync.d.ts.map +1 -1
- package/dist/core/constraints/checkers/capability-sync.js +17 -24
- package/dist/core/constraints/checkers/capability-sync.js.map +1 -1
- package/dist/core/constraints/checkers/context-doc-sync.d.ts +1 -1
- package/dist/core/constraints/checkers/context-doc-sync.d.ts.map +1 -1
- package/dist/core/constraints/checkers/context-doc-sync.js +9 -6
- package/dist/core/constraints/checkers/context-doc-sync.js.map +1 -1
- package/dist/core/constraints/checkers/docs-freshness.d.ts.map +1 -1
- package/dist/core/constraints/checkers/docs-freshness.js +24 -30
- package/dist/core/constraints/checkers/docs-freshness.js.map +1 -1
- package/dist/core/constraints/checkers/governance-presence.d.ts.map +1 -1
- package/dist/core/constraints/checkers/governance-presence.js +10 -4
- package/dist/core/constraints/checkers/governance-presence.js.map +1 -1
- package/dist/core/constraints/checkers/types.d.ts +10 -6
- package/dist/core/constraints/checkers/types.d.ts.map +1 -1
- package/dist/core/constraints/checkers/types.js +7 -3
- package/dist/core/constraints/checkers/types.js.map +1 -1
- package/dist/core/constraints/context-builder.d.ts +11 -10
- package/dist/core/constraints/context-builder.d.ts.map +1 -1
- package/dist/core/constraints/context-builder.js +31 -27
- package/dist/core/constraints/context-builder.js.map +1 -1
- package/dist/core/constraints/context-reconcile.d.ts +75 -0
- package/dist/core/constraints/context-reconcile.d.ts.map +1 -0
- package/dist/core/constraints/context-reconcile.js +161 -0
- package/dist/core/constraints/context-reconcile.js.map +1 -0
- package/dist/core/constraints/doc-freshness/runner.d.ts +7 -0
- package/dist/core/constraints/doc-freshness/runner.d.ts.map +1 -1
- package/dist/core/constraints/doc-freshness/runner.js +8 -3
- package/dist/core/constraints/doc-freshness/runner.js.map +1 -1
- package/dist/core/constraints/git-evidence.js +1 -1
- package/dist/core/constraints/git-evidence.js.map +1 -1
- package/dist/core/constraints/injection-drift.d.ts +7 -2
- package/dist/core/constraints/injection-drift.d.ts.map +1 -1
- package/dist/core/constraints/injection-drift.js +13 -7
- package/dist/core/constraints/injection-drift.js.map +1 -1
- package/dist/core/constraints/run-env.d.ts +92 -0
- package/dist/core/constraints/run-env.d.ts.map +1 -0
- package/dist/core/constraints/run-env.js +175 -0
- package/dist/core/constraints/run-env.js.map +1 -0
- package/dist/core/constraints/triggers.d.ts +22 -0
- package/dist/core/constraints/triggers.d.ts.map +1 -0
- package/dist/core/constraints/triggers.js +31 -0
- package/dist/core/constraints/triggers.js.map +1 -0
- package/dist/core/effective-constraints.d.ts +13 -4
- package/dist/core/effective-constraints.d.ts.map +1 -1
- package/dist/core/effective-constraints.js +16 -6
- package/dist/core/effective-constraints.js.map +1 -1
- package/dist/core/effective-set.d.ts +8 -15
- package/dist/core/effective-set.d.ts.map +1 -1
- package/dist/core/effective-set.js +7 -12
- package/dist/core/effective-set.js.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/project-config-loader.d.ts +39 -17
- package/dist/core/project-config-loader.d.ts.map +1 -1
- package/dist/core/project-config-loader.js +51 -122
- package/dist/core/project-config-loader.js.map +1 -1
- package/dist/core/validators/check-handlers/http.d.ts +2 -2
- package/dist/core/validators/check-handlers/http.d.ts.map +1 -1
- package/dist/core/validators/check-handlers/http.js +12 -7
- package/dist/core/validators/check-handlers/http.js.map +1 -1
- package/dist/failure/classifier.d.ts +1 -1
- package/dist/failure/classifier.d.ts.map +1 -1
- package/dist/failure/classifier.js +8 -8
- package/dist/failure/classifier.js.map +1 -1
- package/dist/failure/index.d.ts +2 -1
- package/dist/failure/index.d.ts.map +1 -1
- package/dist/failure/index.js +9 -17
- package/dist/failure/index.js.map +1 -1
- package/dist/failure/recorder.d.ts +1 -1
- package/dist/failure/recorder.d.ts.map +1 -1
- package/dist/gates/checker-gate.d.ts +2 -1
- package/dist/gates/checker-gate.d.ts.map +1 -1
- package/dist/gates/checker-gate.js +3 -2
- package/dist/gates/checker-gate.js.map +1 -1
- package/dist/gates/command.d.ts +10 -4
- package/dist/gates/command.d.ts.map +1 -1
- package/dist/gates/command.js +36 -62
- package/dist/gates/command.js.map +1 -1
- package/dist/gates/contract.d.ts.map +1 -1
- package/dist/gates/contract.js +0 -4
- package/dist/gates/contract.js.map +1 -1
- package/dist/gates/definitions.d.ts +2 -1
- package/dist/gates/definitions.d.ts.map +1 -1
- package/dist/gates/definitions.js +6 -5
- package/dist/gates/definitions.js.map +1 -1
- package/dist/gates/index.d.ts +0 -4
- package/dist/gates/index.d.ts.map +1 -1
- package/dist/gates/index.js +1 -6
- package/dist/gates/index.js.map +1 -1
- package/dist/gates/performance.d.ts.map +1 -1
- package/dist/gates/performance.js +0 -4
- package/dist/gates/performance.js.map +1 -1
- package/dist/gates/runner.d.ts +1 -1
- package/dist/gates/runner.js +1 -1
- package/dist/gates/security.d.ts +1 -1
- package/dist/gates/security.d.ts.map +1 -1
- package/dist/gates/security.js +5 -6
- package/dist/gates/security.js.map +1 -1
- package/dist/gates/types.d.ts +14 -17
- package/dist/gates/types.d.ts.map +1 -1
- package/dist/gates/types.js.map +1 -1
- package/dist/hooks/bootstrap.d.ts +6 -4
- package/dist/hooks/bootstrap.d.ts.map +1 -1
- package/dist/hooks/bootstrap.js +25 -13
- package/dist/hooks/bootstrap.js.map +1 -1
- package/dist/hooks/config.d.ts +6 -2
- package/dist/hooks/config.d.ts.map +1 -1
- package/dist/hooks/config.js +5 -1
- package/dist/hooks/config.js.map +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +0 -15
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/pipeline.d.ts +19 -1
- package/dist/hooks/pipeline.d.ts.map +1 -1
- package/dist/hooks/pipeline.js +42 -4
- package/dist/hooks/pipeline.js.map +1 -1
- package/dist/hooks/registry.d.ts +11 -8
- package/dist/hooks/registry.d.ts.map +1 -1
- package/dist/hooks/registry.js +22 -7
- package/dist/hooks/registry.js.map +1 -1
- package/dist/hooks/types.d.ts +25 -7
- package/dist/hooks/types.d.ts.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/knowledge/audit-scoring.d.ts +87 -0
- package/dist/knowledge/audit-scoring.d.ts.map +1 -0
- package/dist/knowledge/audit-scoring.js +470 -0
- package/dist/knowledge/audit-scoring.js.map +1 -0
- package/dist/knowledge/audit.d.ts +11 -59
- package/dist/knowledge/audit.d.ts.map +1 -1
- package/dist/knowledge/audit.js +47 -522
- package/dist/knowledge/audit.js.map +1 -1
- package/dist/knowledge/import.d.ts.map +1 -1
- package/dist/knowledge/import.js +2 -0
- package/dist/knowledge/import.js.map +1 -1
- package/dist/knowledge/index-generator.d.ts.map +1 -1
- package/dist/knowledge/index-generator.js +4 -5
- package/dist/knowledge/index-generator.js.map +1 -1
- package/dist/knowledge/index.d.ts +3 -2
- package/dist/knowledge/index.d.ts.map +1 -1
- package/dist/knowledge/index.js +3 -16
- package/dist/knowledge/index.js.map +1 -1
- package/dist/knowledge/ingest.js +1 -1
- package/dist/knowledge/ingest.js.map +1 -1
- package/dist/knowledge/lifecycle.d.ts.map +1 -1
- package/dist/knowledge/lifecycle.js +4 -2
- package/dist/knowledge/lifecycle.js.map +1 -1
- package/dist/knowledge/migration.d.ts +3 -0
- package/dist/knowledge/migration.d.ts.map +1 -1
- package/dist/knowledge/migration.js +8 -2
- package/dist/knowledge/migration.js.map +1 -1
- package/dist/knowledge/query.d.ts +6 -0
- package/dist/knowledge/query.d.ts.map +1 -1
- package/dist/knowledge/query.js +8 -2
- package/dist/knowledge/query.js.map +1 -1
- package/dist/knowledge/reference-tracker.d.ts.map +1 -1
- package/dist/knowledge/reference-tracker.js +4 -6
- package/dist/knowledge/reference-tracker.js.map +1 -1
- package/dist/knowledge/store.d.ts +22 -16
- package/dist/knowledge/store.d.ts.map +1 -1
- package/dist/knowledge/store.js +53 -12
- package/dist/knowledge/store.js.map +1 -1
- package/dist/knowledge/tree-walker.d.ts +19 -0
- package/dist/knowledge/tree-walker.d.ts.map +1 -0
- package/dist/knowledge/tree-walker.js +30 -0
- package/dist/knowledge/tree-walker.js.map +1 -0
- package/dist/knowledge/types.d.ts +16 -0
- package/dist/knowledge/types.d.ts.map +1 -1
- package/dist/monitoring/traces.d.ts +5 -3
- package/dist/monitoring/traces.d.ts.map +1 -1
- package/dist/monitoring/traces.js +19 -5
- package/dist/monitoring/traces.js.map +1 -1
- package/dist/test-setup/jsonl-fake-fs.d.ts +30 -0
- package/dist/test-setup/jsonl-fake-fs.d.ts.map +1 -0
- package/dist/test-setup/jsonl-fake-fs.js +49 -0
- package/dist/test-setup/jsonl-fake-fs.js.map +1 -0
- package/dist/tools/index.d.ts +4 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +7 -15
- package/dist/tools/index.js.map +1 -1
- package/dist/types/checkpoint.d.ts +5 -0
- package/dist/types/checkpoint.d.ts.map +1 -1
- package/dist/types/project-config.d.ts +18 -0
- package/dist/types/project-config.d.ts.map +1 -1
- package/dist/types/trace.d.ts +13 -4
- package/dist/types/trace.d.ts.map +1 -1
- package/dist/types/trace.js +4 -3
- package/dist/types/trace.js.map +1 -1
- package/dist/utils/exec.d.ts +4 -27
- package/dist/utils/exec.d.ts.map +1 -1
- package/dist/utils/exec.js +4 -94
- package/dist/utils/exec.js.map +1 -1
- package/dist/utils/jsonl.d.ts +17 -7
- package/dist/utils/jsonl.d.ts.map +1 -1
- package/dist/utils/jsonl.js +144 -17
- package/dist/utils/jsonl.js.map +1 -1
- package/dist/utils/numeric-flag.d.ts +44 -0
- package/dist/utils/numeric-flag.d.ts.map +1 -0
- package/dist/utils/numeric-flag.js +62 -0
- package/dist/utils/numeric-flag.js.map +1 -0
- package/package.json +1 -1
- package/src/CONTEXT.md +5 -2
- package/src/__tests__/acceptance-gate.test.ts +7 -4
- package/src/__tests__/checker-extra.test.ts +3 -2
- package/src/__tests__/checker.test.ts +4 -3
- package/src/__tests__/checkpoint.test.ts +26 -9
- package/src/__tests__/context-files-resolution.test.ts +29 -15
- package/src/__tests__/contract-gate.test.ts +19 -40
- package/src/__tests__/error-classifier.test.ts +1 -1
- package/src/__tests__/exec.test.ts +45 -107
- package/src/__tests__/failure-recorder.test.ts +7 -5
- package/src/__tests__/hooks-pipeline.test.ts +34 -47
- package/src/__tests__/layering.test.ts +217 -25
- package/src/__tests__/passes-gate.test.ts +9 -4
- package/src/__tests__/performance-gate.test.ts +3 -15
- package/src/__tests__/project-config-loader-extra.test.ts +31 -57
- package/src/__tests__/project-config-loader.test.ts +6 -3
- package/src/__tests__/public-exports.test.ts +0 -1
- package/src/__tests__/public-type-surface.test.ts +5 -4
- package/src/__tests__/public-value-surface.test.ts +182 -0
- package/src/__tests__/review-gate.test.ts +4 -6
- package/src/__tests__/security-gate.test.ts +5 -20
- package/src/__tests__/skip-semantics.test.ts +5 -3
- package/src/__tests__/spec-validator.test.ts +3 -2
- package/src/__tests__/sub-barrels-explicit.test.ts +87 -0
- package/src/__tests__/test-fixture-hygiene.test.ts +53 -0
- package/src/__tests__/trace-analyzer-extra.test.ts +5 -3
- package/src/__tests__/trace-analyzer.test.ts +5 -3
- package/src/__tests__/trace-collector.test.ts +5 -3
- package/src/agents/index.ts +13 -2
- package/src/cli/__tests__/gate-command.test.ts +162 -0
- package/src/cli/__tests__/state-io.test.ts +50 -0
- package/src/cli/commands/CONTEXT.md +30 -5
- package/src/cli/commands/__tests__/acceptance.test.ts +24 -25
- package/src/cli/commands/__tests__/bin-exit-mapping.test.ts +15 -0
- package/src/cli/commands/__tests__/check-drift.test.ts +42 -1
- package/src/cli/commands/__tests__/check-read-count.test.ts +170 -0
- package/src/cli/commands/__tests__/check-skip-output.test.ts +4 -1
- package/src/cli/commands/__tests__/check.test.ts +63 -44
- package/src/cli/commands/__tests__/command-gate-dead-options.test.ts +60 -0
- package/src/cli/commands/__tests__/command.test.ts +33 -17
- package/src/cli/commands/__tests__/constraints-retire.test.ts +52 -0
- package/src/cli/commands/__tests__/context-syncer.test.ts +141 -0
- package/src/cli/commands/__tests__/contract.test.ts +20 -20
- package/src/cli/commands/__tests__/failure.test.ts +5 -4
- package/src/cli/commands/__tests__/gate-decision.ts +30 -0
- package/src/cli/commands/__tests__/init-dead-options.test.ts +50 -0
- package/src/cli/commands/__tests__/init-governance-io.test.ts +139 -0
- package/src/cli/commands/__tests__/init-injection.test.ts +3 -3
- package/src/cli/commands/__tests__/init-ondisk.test.ts +867 -0
- package/src/cli/commands/__tests__/init.test.ts +82 -6
- package/src/cli/commands/__tests__/knowledge-audit-threshold.test.ts +146 -0
- package/src/cli/commands/__tests__/knowledge-flywheel-consistency.test.ts +1 -1
- package/src/cli/commands/__tests__/knowledge-tone-mapping.test.ts +244 -0
- package/src/cli/commands/__tests__/knowledge-view.test.ts +839 -0
- package/src/cli/commands/__tests__/knowledge.test.ts +33 -15
- package/src/cli/commands/__tests__/numeric-flag-assembly.test.ts +368 -0
- package/src/cli/commands/__tests__/performance.test.ts +19 -21
- package/src/cli/commands/__tests__/posteval-plan.test.ts +5 -3
- package/src/cli/commands/__tests__/pre-push-hook.test.ts +181 -0
- package/src/cli/commands/__tests__/project-path-anchoring.test.ts +95 -2
- package/src/cli/commands/__tests__/project-path-convention.test.ts +103 -25
- package/src/cli/commands/__tests__/registry.test.ts +2 -0
- package/src/cli/commands/__tests__/report.test.ts +23 -1
- package/src/cli/commands/__tests__/review.test.ts +10 -17
- package/src/cli/commands/__tests__/scaffold.test.ts +505 -0
- package/src/cli/commands/__tests__/security-default-scan.test.ts +75 -0
- package/src/cli/commands/__tests__/security.test.ts +21 -24
- package/src/cli/commands/__tests__/spec-baseline-check.test.ts +3 -2
- package/src/cli/commands/__tests__/spec-baseline-index-cap.test.ts +131 -0
- package/src/cli/commands/__tests__/spec-baseline-read-count.test.ts +325 -0
- package/src/cli/commands/__tests__/status-extra.test.ts +25 -8
- package/src/cli/commands/__tests__/status.test.ts +46 -18
- package/src/cli/commands/__tests__/sync-docs-agents.test.ts +19 -4
- package/src/cli/commands/__tests__/sync-docs-context-drift.test.ts +232 -0
- package/src/cli/commands/__tests__/sync-docs-module-order.test.ts +111 -0
- package/src/cli/commands/__tests__/sync-docs-read-count.test.ts +192 -0
- package/src/cli/commands/__tests__/sync-docs.test.ts +3 -2
- package/src/cli/commands/__tests__/validate.test.ts +1 -48
- package/src/cli/commands/acceptance.ts +24 -29
- package/src/cli/commands/check.ts +60 -35
- package/src/cli/commands/command.ts +9 -8
- package/src/cli/commands/constraints-retire.ts +57 -70
- package/src/cli/commands/contract.ts +44 -47
- package/src/cli/commands/definitions.ts +12 -6
- package/src/cli/commands/failure.ts +16 -3
- package/src/cli/commands/init.ts +242 -389
- package/src/cli/commands/knowledge-view.ts +224 -0
- package/src/cli/commands/knowledge.ts +643 -448
- package/src/cli/commands/passes-gate.ts +12 -3
- package/src/cli/commands/performance.ts +31 -38
- package/src/cli/commands/report.ts +3 -2
- package/src/cli/commands/review.ts +22 -28
- package/src/cli/commands/scaffold-templates.ts +406 -0
- package/src/cli/commands/scaffold.ts +302 -0
- package/src/cli/commands/security.ts +27 -23
- package/src/cli/commands/spec-baseline-check.ts +158 -33
- package/src/cli/commands/status.ts +12 -7
- package/src/cli/commands/sync-docs/__tests__/context-export-surface.test.ts +102 -0
- package/src/cli/commands/sync-docs/__tests__/module-descriptions.test.ts +196 -0
- package/src/cli/commands/sync-docs/context-syncer.ts +137 -31
- package/src/cli/commands/sync-docs/index.ts +103 -28
- package/src/cli/commands/sync-docs/project-reader.ts +51 -7
- package/src/cli/commands/validate.ts +1 -104
- package/src/cli/gate-command.ts +87 -0
- package/src/cli/state-io.ts +53 -0
- package/src/completion-checkers/index.ts +10 -1
- package/src/context/CONTEXT.md +2 -1
- package/src/context/__tests__/knowledge-injector.test.ts +27 -0
- package/src/context/__tests__/session-manager.test.ts +19 -12
- package/src/context/knowledge-injector.ts +14 -7
- package/src/core/CONTEXT.md +10 -7
- package/src/core/__tests__/effective-set.test.ts +36 -60
- package/src/core/constraints/__tests__/context-reconcile.test.ts +246 -0
- package/src/core/constraints/__tests__/run-env.test.ts +377 -0
- package/src/core/constraints/__tests__/triggers.test.ts +70 -0
- package/src/core/constraints/agent-prompt-renderer.ts +1 -1
- package/src/core/constraints/capabilities-reconcile.ts +28 -4
- package/src/core/constraints/check-cache.ts +1 -1
- package/src/core/constraints/checker.ts +30 -14
- package/src/core/constraints/checkers/__tests__/context-doc-sync.test.ts +8 -3
- package/src/core/constraints/checkers/__tests__/governance-presence.test.ts +16 -7
- package/src/core/constraints/checkers/__tests__/no-hardcoded-credentials.test.ts +2 -1
- package/src/core/constraints/checkers/capability-sync.ts +27 -28
- package/src/core/constraints/checkers/context-doc-sync.ts +9 -7
- package/src/core/constraints/checkers/docs-freshness.ts +28 -33
- package/src/core/constraints/checkers/governance-presence.ts +10 -6
- package/src/core/constraints/checkers/types.ts +14 -8
- package/src/core/constraints/context-builder.ts +35 -26
- package/src/core/constraints/context-reconcile.ts +200 -0
- package/src/core/constraints/doc-freshness/__tests__/runner.test.ts +25 -0
- package/src/core/constraints/doc-freshness/runner.ts +18 -4
- package/src/core/constraints/git-evidence.ts +1 -1
- package/src/core/constraints/injection-drift.ts +19 -8
- package/src/core/constraints/run-env.ts +207 -0
- package/src/core/constraints/triggers.ts +33 -0
- package/src/core/effective-constraints.ts +17 -6
- package/src/core/effective-set.ts +8 -24
- package/src/core/index.ts +2 -0
- package/src/core/project-config-loader.ts +54 -102
- package/src/core/validators/__tests__/http-retry-sleep.test.ts +231 -0
- package/src/core/validators/check-handlers/http.ts +18 -7
- package/src/failure/CONTEXT.md +2 -1
- package/src/failure/classifier.ts +2 -2
- package/src/failure/index.ts +14 -2
- package/src/failure/recorder.ts +1 -1
- package/src/gates/CONTEXT.md +13 -7
- package/src/gates/__tests__/checker-gate.test.ts +1 -1
- package/src/gates/__tests__/command-single-predicate.test.ts +135 -0
- package/src/gates/__tests__/command.test.ts +8 -15
- package/src/gates/__tests__/contract.test.ts +5 -5
- package/src/gates/__tests__/gate-interface.test.ts +0 -17
- package/src/gates/__tests__/performance.test.ts +0 -13
- package/src/gates/__tests__/review.test.ts +0 -1
- package/src/gates/__tests__/runner.test.ts +1 -1
- package/src/gates/__tests__/security-default-scan.test.ts +97 -0
- package/src/gates/__tests__/security.test.ts +0 -13
- package/src/gates/checker-gate.ts +3 -2
- package/src/gates/command.ts +51 -74
- package/src/gates/contract.ts +0 -5
- package/src/gates/definitions.ts +6 -5
- package/src/gates/index.ts +0 -5
- package/src/gates/performance.ts +1 -6
- package/src/gates/runner.ts +1 -1
- package/src/gates/security.ts +9 -11
- package/src/gates/types.ts +20 -23
- package/src/hooks/CONTEXT.md +10 -9
- package/src/hooks/__tests__/bootstrap.test.ts +29 -6
- package/src/hooks/__tests__/pipeline.test.ts +133 -17
- package/src/hooks/__tests__/registry.test.ts +51 -3
- package/src/hooks/bootstrap.ts +35 -15
- package/src/hooks/config.ts +6 -2
- package/src/hooks/index.ts +10 -1
- package/src/hooks/pipeline.ts +51 -6
- package/src/hooks/registry.ts +31 -12
- package/src/hooks/types.ts +26 -7
- package/src/index.ts +1 -2
- package/src/knowledge/CONTEXT.md +14 -7
- package/src/knowledge/__tests__/audit-labels.test.ts +8 -5
- package/src/knowledge/__tests__/audit-scoring.test.ts +230 -0
- package/src/knowledge/__tests__/audit-write-count.test.ts +131 -0
- package/src/knowledge/__tests__/audit.test.ts +291 -208
- package/src/knowledge/__tests__/doctor.test.ts +3 -2
- package/src/knowledge/__tests__/ingest.test.ts +3 -2
- package/src/knowledge/__tests__/lifecycle.test.ts +57 -2
- package/src/knowledge/__tests__/migration.test.ts +35 -6
- package/src/knowledge/__tests__/query.test.ts +3 -2
- package/src/knowledge/__tests__/reference-tracker.test.ts +23 -2
- package/src/knowledge/__tests__/store.test.ts +149 -4
- package/src/knowledge/__tests__/tree-walker.test.ts +132 -0
- package/src/knowledge/audit-scoring.ts +589 -0
- package/src/knowledge/audit.ts +55 -599
- package/src/knowledge/import.ts +2 -0
- package/src/knowledge/index-generator.ts +4 -6
- package/src/knowledge/index.ts +27 -2
- package/src/knowledge/ingest.ts +1 -1
- package/src/knowledge/lifecycle.ts +5 -2
- package/src/knowledge/migration.ts +8 -2
- package/src/knowledge/query.ts +8 -1
- package/src/knowledge/reference-tracker.ts +5 -7
- package/src/knowledge/store.ts +75 -16
- package/src/knowledge/tree-walker.ts +29 -0
- package/src/knowledge/types.ts +19 -0
- package/src/monitoring/CONTEXT.md +5 -2
- package/src/monitoring/__tests__/context-tracker.test.ts +16 -8
- package/src/monitoring/__tests__/trace-file-anchoring.test.ts +80 -0
- package/src/monitoring/traces.ts +19 -5
- package/src/release/CONTEXT.md +1 -1
- package/src/release/__tests__/integrity.test.ts +21 -12
- package/src/test-setup/__tests__/jsonl-fake-fs.test.ts +98 -0
- package/src/test-setup/jsonl-fake-fs.ts +59 -0
- package/src/tools/index.ts +5 -1
- package/src/types/checkpoint.ts +6 -0
- package/src/types/project-config.ts +21 -0
- package/src/types/trace.ts +14 -4
- package/src/utils/__tests__/file-walk.test.ts +3 -2
- package/src/utils/__tests__/jsonl-bounded-read.test.ts +106 -0
- package/src/utils/__tests__/jsonl-skip-disposition.test.ts +10 -6
- package/src/utils/__tests__/jsonl.test.ts +61 -14
- package/src/utils/__tests__/numeric-flag.test.ts +80 -0
- package/src/utils/__tests__/package-version.test.ts +2 -2
- package/src/utils/exec.ts +4 -64
- package/src/utils/jsonl.ts +159 -20
- package/src/utils/numeric-flag.ts +64 -0
- package/dist/failure/types.d.ts +0 -9
- package/dist/failure/types.d.ts.map +0 -1
- package/dist/failure/types.js +0 -25
- package/dist/failure/types.js.map +0 -1
- package/dist/gates/effective-gates.d.ts +0 -30
- package/dist/gates/effective-gates.d.ts.map +0 -1
- package/dist/gates/effective-gates.js +0 -81
- package/dist/gates/effective-gates.js.map +0 -1
- package/src/failure/types.ts +0 -9
- package/src/gates/__tests__/effective-gates.test.ts +0 -77
- package/src/gates/effective-gates.ts +0 -99
|
@@ -13,6 +13,7 @@ import { DEFAULT_TRACE_FILE } from '../../types/trace';
|
|
|
13
13
|
import type { ExecutionTrace } from '../../types/trace';
|
|
14
14
|
import type { TraceSummary, TraceAnomaly } from '../../types/trace';
|
|
15
15
|
import { log, logError, processIO, type CommandIO, type CommandResult } from '../command-contract';
|
|
16
|
+
import { fileStateIO, type StateIO } from '../state-io';
|
|
16
17
|
|
|
17
18
|
export interface StatusOptions {
|
|
18
19
|
/** 项目路径 */
|
|
@@ -23,6 +24,13 @@ export interface StatusOptions {
|
|
|
23
24
|
anomalies?: boolean;
|
|
24
25
|
/** 时间范围(小时) */
|
|
25
26
|
hours?: number;
|
|
27
|
+
/**
|
|
28
|
+
* 状态文件接缝(非 CLI flag;ADR-0026)
|
|
29
|
+
*
|
|
30
|
+
* 缺省 = 真实 fs 实现(fileStateIO)。注入则 `.harness/.state.json` 的读写
|
|
31
|
+
* 走替身,测试据此不碰真文件系统。
|
|
32
|
+
*/
|
|
33
|
+
stateIO?: StateIO;
|
|
26
34
|
}
|
|
27
35
|
|
|
28
36
|
/**
|
|
@@ -32,7 +40,7 @@ export async function status(options: StatusOptions, io: CommandIO = processIO):
|
|
|
32
40
|
const projectPath = options.projectPath || process.cwd();
|
|
33
41
|
const harnessDir = path.join(projectPath, '.harness');
|
|
34
42
|
const tracesPath = path.join(projectPath, DEFAULT_TRACE_FILE);
|
|
35
|
-
const
|
|
43
|
+
const stateIO = options.stateIO ?? fileStateIO(projectPath);
|
|
36
44
|
|
|
37
45
|
log(io, chalk.blue('📊 Harness 状态'));
|
|
38
46
|
log(io);
|
|
@@ -139,12 +147,9 @@ export async function status(options: StatusOptions, io: CommandIO = processIO):
|
|
|
139
147
|
log(io);
|
|
140
148
|
}
|
|
141
149
|
|
|
142
|
-
//
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
};
|
|
146
|
-
fs.mkdirSync(path.dirname(statePath), { recursive: true });
|
|
147
|
-
fs.writeFileSync(statePath, JSON.stringify(state, null, 2));
|
|
150
|
+
// 更新状态文件:读-改-写(ADR-0026 决策 2)——不再整文件重写,
|
|
151
|
+
// 否则 check 写入的 shownHints 会被抹掉、智能提示去重失效
|
|
152
|
+
stateIO.write({ ...stateIO.read(), lastStatusRun: new Date().toISOString() });
|
|
148
153
|
|
|
149
154
|
// 下一步建议
|
|
150
155
|
log(io, chalk.blue('💡 下一步建议:'));
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CONTEXT.md 内容判定采集侧测试(harness#142)
|
|
3
|
+
*
|
|
4
|
+
* 采集 = fs 遍历 + 导出口径(`export *` 解析、barrel 再导出的类型-only 剔除)。
|
|
5
|
+
* 判定本体在 core/constraints/context-reconcile(旁测见 context-reconcile.test.ts)。
|
|
6
|
+
* 与 sync-docs 其余测试同法:临时目录真 fs,零注入。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import * as fs from 'fs';
|
|
10
|
+
import * as path from 'path';
|
|
11
|
+
import * as os from 'os';
|
|
12
|
+
import { collectContextExportSurface } from '../context-syncer';
|
|
13
|
+
|
|
14
|
+
let tempDir: string;
|
|
15
|
+
|
|
16
|
+
function write(rel: string, content: string): void {
|
|
17
|
+
const target = path.join(tempDir, rel);
|
|
18
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
19
|
+
fs.writeFileSync(target, content);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
beforeAll(() => {
|
|
23
|
+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'temp-test-context-surface-'));
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
afterAll(() => {
|
|
27
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe('collectContextExportSurface — 目录导出面采集', () => {
|
|
31
|
+
it('收集目录内(含子目录).ts 的导出符号;__tests__ 与 .d.ts 不参与', async () => {
|
|
32
|
+
const dir = 'mod-scan';
|
|
33
|
+
write(`${dir}/core.ts`, 'export function doCore() {}\nexport interface CoreConfig {}\n');
|
|
34
|
+
write(`${dir}/nested/deep.ts`, 'export const DEEP_VALUE = 1;');
|
|
35
|
+
write(`${dir}/__tests__/core.test.ts`, 'export const TEST_ONLY_HELPER = 2;');
|
|
36
|
+
write(`${dir}/ambient.d.ts`, 'export const GLOBAL_FROM_DTS = 3;');
|
|
37
|
+
|
|
38
|
+
const { surface, barrelExports } = await collectContextExportSurface(path.join(tempDir, dir), tempDir);
|
|
39
|
+
|
|
40
|
+
expect(surface).toEqual(expect.arrayContaining(['doCore', 'CoreConfig', 'DEEP_VALUE']));
|
|
41
|
+
expect(surface).not.toContain('TEST_ONLY_HELPER');
|
|
42
|
+
expect(surface).not.toContain('GLOBAL_FROM_DTS');
|
|
43
|
+
// 无 index.ts → barrel 方向空转
|
|
44
|
+
expect(barrelExports).toEqual([]);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('barrel 只交值符号:export type 块、逐项 type、别名取导出名', async () => {
|
|
48
|
+
const dir = 'mod-barrel';
|
|
49
|
+
write(`${dir}/impl.ts`, 'export class Widget {}\nexport interface WidgetConfig {}\nexport const WIDGET_LIMIT = 1;\n');
|
|
50
|
+
write(
|
|
51
|
+
`${dir}/index.ts`,
|
|
52
|
+
[
|
|
53
|
+
"export { Widget, WIDGET_LIMIT as LIMIT } from './impl';",
|
|
54
|
+
"export type { WidgetConfig } from './impl';",
|
|
55
|
+
"export { createThing, type ThingShape } from './thing';",
|
|
56
|
+
'export function barrelLocal() {}',
|
|
57
|
+
].join('\n')
|
|
58
|
+
);
|
|
59
|
+
write(`${dir}/thing.ts`, 'export function createThing() {}\nexport type ThingShape = string;');
|
|
60
|
+
|
|
61
|
+
const { surface, barrelExports } = await collectContextExportSurface(path.join(tempDir, dir), tempDir);
|
|
62
|
+
|
|
63
|
+
expect(barrelExports.sort()).toEqual(['LIMIT', 'Widget', 'barrelLocal', 'createThing']);
|
|
64
|
+
expect(surface).toEqual(expect.arrayContaining(['WidgetConfig', 'ThingShape']));
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('`export *` 在同目录内解析目标后并入(值进 barrel、类型不进)', async () => {
|
|
68
|
+
const dir = 'mod-star';
|
|
69
|
+
write(`${dir}/types.ts`, 'export interface Shape {}\nexport type Mode = "a" | "b";\nexport enum Kind { A }\n');
|
|
70
|
+
write(`${dir}/store.ts`, 'export class Store {}\nexport const DEFAULTS = {};\n');
|
|
71
|
+
write(`${dir}/index.ts`, ["export * from './types';", "export * from './store';", "export * from 'chalk';"].join('\n'));
|
|
72
|
+
|
|
73
|
+
const { surface, barrelExports } = await collectContextExportSurface(path.join(tempDir, dir), tempDir);
|
|
74
|
+
|
|
75
|
+
expect(barrelExports.sort()).toEqual(['DEFAULTS', 'Kind', 'Store']);
|
|
76
|
+
expect(surface).toEqual(expect.arrayContaining(['Shape', 'Mode', 'Kind', 'Store', 'DEFAULTS']));
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('跨目录再导出的类型按正本声明分型(值侧要求登记,类型侧豁免)', async () => {
|
|
80
|
+
write('types/external.ts', 'export const EXTERNAL_VALUE = 1;\nexport interface ExternalShape {}\n');
|
|
81
|
+
const dir = 'mod-cross';
|
|
82
|
+
write(
|
|
83
|
+
`${dir}/index.ts`,
|
|
84
|
+
["export { EXTERNAL_VALUE, ExternalShape } from '../types/external';", 'export const Own = 2;'].join('\n')
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const { barrelExports } = await collectContextExportSurface(path.join(tempDir, dir), tempDir);
|
|
88
|
+
|
|
89
|
+
expect(barrelExports.sort()).toEqual(['EXTERNAL_VALUE', 'Own']);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('barrel 再导出正本已不存在的名字 → 不计入导出面(改名的虚 barrel 不洗白幽灵)', async () => {
|
|
93
|
+
const dir = 'mod-phantom';
|
|
94
|
+
write(`${dir}/impl.ts`, 'export class WidgetSink {}\nexport interface Shape {}\n');
|
|
95
|
+
write(`${dir}/index.ts`, "export { Widget, WidgetSink } from './impl';\nexport type { Missing } from './impl';");
|
|
96
|
+
|
|
97
|
+
const { surface, barrelExports } = await collectContextExportSurface(path.join(tempDir, dir), tempDir);
|
|
98
|
+
|
|
99
|
+
expect(surface).toEqual(['WidgetSink', 'Shape']);
|
|
100
|
+
expect(barrelExports).toEqual(['WidgetSink']);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 模块描述提取:并发取数 + 逐字保序(#147 B 票)
|
|
3
|
+
*
|
|
4
|
+
* sync-docs 的 file-table 分支要把首行注释提成表格「说明」列。改造前是逐文件
|
|
5
|
+
* `await` 串行读;改造后按固定上限并发读,但**输出清单的顺序必须与目录遍历序
|
|
6
|
+
* 逐字一致**(该顺序对外经 `sync-docs --check` 的漂移校验可见,不得变)。
|
|
7
|
+
*
|
|
8
|
+
* 手法:替身 `fs/promises.readFile` 给每次读取记「起始序 / 完成序」,并让起始靠后
|
|
9
|
+
* 的读更快完成——只要真有并发,完成序必然与起始序不同。于是「按完成顺序 append」
|
|
10
|
+
* 的实现会当场红,而「按原索引回填」的实现保序。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import * as fs from 'fs';
|
|
14
|
+
import * as os from 'os';
|
|
15
|
+
import * as path from 'path';
|
|
16
|
+
|
|
17
|
+
type IoEvents = {
|
|
18
|
+
/** .ts/.tsx 内容读的发起顺序(替身按调用到达顺序记账) */
|
|
19
|
+
started: string[];
|
|
20
|
+
/** .ts/.tsx 内容读的完成顺序 */
|
|
21
|
+
finished: string[];
|
|
22
|
+
inFlight: number;
|
|
23
|
+
maxInFlight: number;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// 记账挂 globalThis:jest.mock 工厂在装载期执行,闭包外提会撞 TDZ
|
|
27
|
+
jest.mock('fs/promises', () => {
|
|
28
|
+
const actual = jest.requireActual<typeof import('fs/promises')>('fs/promises');
|
|
29
|
+
const g = globalThis as unknown as { __SD147_IO__?: IoEvents };
|
|
30
|
+
if (!g.__SD147_IO__) {
|
|
31
|
+
g.__SD147_IO__ = { started: [], finished: [], inFlight: 0, maxInFlight: 0 };
|
|
32
|
+
}
|
|
33
|
+
const ev = g.__SD147_IO__;
|
|
34
|
+
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
...actual,
|
|
38
|
+
readFile: jest.fn(async (p: fs.PathLike | unknown, ...rest: unknown[]) => {
|
|
39
|
+
const name = Buffer.isBuffer(p) ? p.toString('utf8') : String(p);
|
|
40
|
+
const tracked = /\.(ts|tsx)$/.test(name) && !name.endsWith('.d.ts');
|
|
41
|
+
if (tracked) {
|
|
42
|
+
const startedIndex = ev.started.length;
|
|
43
|
+
ev.started.push(name);
|
|
44
|
+
ev.inFlight++;
|
|
45
|
+
if (ev.inFlight > ev.maxInFlight) ev.maxInFlight = ev.inFlight;
|
|
46
|
+
// 起始靠后的读更快落地:并发一存在,完成序就与起始序错开
|
|
47
|
+
await sleep(startedIndex % 2 === 0 ? 60 : 2);
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
return await (
|
|
51
|
+
actual.readFile as unknown as (
|
|
52
|
+
path: unknown,
|
|
53
|
+
options?: unknown
|
|
54
|
+
) => Promise<string | Buffer>
|
|
55
|
+
)(p, ...rest);
|
|
56
|
+
} finally {
|
|
57
|
+
if (tracked) {
|
|
58
|
+
ev.inFlight--;
|
|
59
|
+
ev.finished.push(name);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}),
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
import { extractFileDescriptions, scanSourceModules } from '../project-reader';
|
|
67
|
+
|
|
68
|
+
const events = (): IoEvents =>
|
|
69
|
+
((globalThis as unknown as { __SD147_IO__?: IoEvents }).__SD147_IO__ ||= {
|
|
70
|
+
started: [],
|
|
71
|
+
finished: [],
|
|
72
|
+
inFlight: 0,
|
|
73
|
+
maxInFlight: 0,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
let tempDir: string;
|
|
77
|
+
|
|
78
|
+
function write(rel: string, content: string): void {
|
|
79
|
+
const target = path.join(tempDir, rel);
|
|
80
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
81
|
+
fs.writeFileSync(target, content, 'utf-8');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** 描述 = `desc:<文件名去扩展名>`,一眼可核对配对 */
|
|
85
|
+
function writeModule(rel: string): void {
|
|
86
|
+
const base = path.basename(rel).replace(/\.tsx?$/, '');
|
|
87
|
+
write(rel, `// desc:${base}\nexport const ${/^\w+$/.test(base) ? base : 'x'} = 1;\n`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function reset(): void {
|
|
91
|
+
const ev = events();
|
|
92
|
+
ev.started.length = 0;
|
|
93
|
+
ev.finished.length = 0;
|
|
94
|
+
ev.inFlight = 0;
|
|
95
|
+
ev.maxInFlight = 0;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
beforeAll(() => {
|
|
99
|
+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'sd147-descriptions-'));
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
afterAll(() => {
|
|
103
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
beforeEach(reset);
|
|
107
|
+
|
|
108
|
+
describe('scanSourceModules — 描述并发取数且逐字保序(#147)', () => {
|
|
109
|
+
it('并发真的发生:同一时刻至多 16 份读在途,而非逐文件串行', async () => {
|
|
110
|
+
const srcDir = path.join(tempDir, 'wide');
|
|
111
|
+
// 20 份 > 上限:串行的话 maxInFlight 恒为 1
|
|
112
|
+
for (let i = 0; i < 20; i++) {
|
|
113
|
+
writeModule(`wide/m${String(i).padStart(2, '0')}.ts`);
|
|
114
|
+
}
|
|
115
|
+
// 子目录里的文件同样要进并发池
|
|
116
|
+
writeModule('wide/nested/deep-a.ts');
|
|
117
|
+
writeModule('wide/nested/deep-b.ts');
|
|
118
|
+
|
|
119
|
+
const modules = await scanSourceModules(srcDir, tempDir);
|
|
120
|
+
|
|
121
|
+
const ev = events();
|
|
122
|
+
expect(modules).toHaveLength(22);
|
|
123
|
+
expect(ev.started).toHaveLength(22);
|
|
124
|
+
// 正对照:完成序与起始序确实错开了(夹具没并发能力 = 下面的断言是空跑)
|
|
125
|
+
expect(ev.finished).not.toEqual(ev.started);
|
|
126
|
+
expect(ev.maxInFlight).toBeGreaterThan(1);
|
|
127
|
+
// 上限是固定缺省,不是「有多少文件开多少」
|
|
128
|
+
expect(ev.maxInFlight).toBeLessThanOrEqual(16);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('输出顺序 = 读取发起顺序(= 目录遍历序),描述与文件一一配对', async () => {
|
|
132
|
+
const srcDir = path.join(tempDir, 'order');
|
|
133
|
+
writeModule('order/zeta.ts');
|
|
134
|
+
writeModule('order/alpha.ts');
|
|
135
|
+
writeModule('order/mid.tsx');
|
|
136
|
+
writeModule('order/sub/beta.ts');
|
|
137
|
+
writeModule('order/sub/gamma.ts');
|
|
138
|
+
|
|
139
|
+
const modules = await scanSourceModules(srcDir, tempDir);
|
|
140
|
+
|
|
141
|
+
const ev = events();
|
|
142
|
+
const relStarted = ev.started.map((f) => path.relative(tempDir, f));
|
|
143
|
+
|
|
144
|
+
// 回填按原索引,不按完成先后:清单顺序 = 发起顺序
|
|
145
|
+
expect(modules.map((m) => m.file)).toEqual(relStarted);
|
|
146
|
+
// 每条描述都得是自己那份文件的(串位即红)
|
|
147
|
+
expect(modules.map((m) => m.description)).toEqual(
|
|
148
|
+
modules.map((m) => `desc:${path.basename(m.file).replace(/\.tsx?$/, '')}`)
|
|
149
|
+
);
|
|
150
|
+
// 回填既不是「按完成先后 append」,也不是按文件名重排
|
|
151
|
+
expect(modules.map((m) => m.file)).not.toEqual(
|
|
152
|
+
ev.finished.map((f) => path.relative(tempDir, f))
|
|
153
|
+
);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('跳过口径逐字不变:barrel / .d.ts / __tests__ 不进清单也不被读', async () => {
|
|
157
|
+
const srcDir = path.join(tempDir, 'skips');
|
|
158
|
+
writeModule('skips/keep.ts');
|
|
159
|
+
writeModule('skips/index.ts');
|
|
160
|
+
writeModule('skips/typed.tsx');
|
|
161
|
+
write('skips/ambient.d.ts', '// desc:should-not-appear\nexport const nope = 1;\n');
|
|
162
|
+
write('skips/__tests__/keep.test.ts', '// desc:should-not-appear\nexport const nope = 1;\n');
|
|
163
|
+
write('skips/node_modules/pkg/index.ts', '// desc:should-not-appear\n');
|
|
164
|
+
write('skips/dist/built.ts', '// desc:should-not-appear\n');
|
|
165
|
+
|
|
166
|
+
const modules = await scanSourceModules(srcDir, tempDir);
|
|
167
|
+
|
|
168
|
+
expect(modules.map((m) => m.file)).toEqual(['skips/keep.ts', 'skips/typed.tsx']);
|
|
169
|
+
expect(events().started.map((f) => path.basename(f))).toEqual(['keep.ts', 'typed.tsx']);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('两条兜底逐字保留:JSDoc 首行进描述、无注释回退文件名', async () => {
|
|
173
|
+
const srcDir = path.join(tempDir, 'bare');
|
|
174
|
+
write('bare/no-comment.ts', 'export const a = 1;\n');
|
|
175
|
+
write('bare/jsdoc.ts', '/**\n * JSDoc 首行描述\n */\nexport const b = 2;\n');
|
|
176
|
+
|
|
177
|
+
const modules = await scanSourceModules(srcDir, tempDir);
|
|
178
|
+
const byFile = new Map(modules.map((m) => [m.file, m.description]));
|
|
179
|
+
|
|
180
|
+
expect([...modules.map((m) => m.name)].sort()).toEqual(['jsdoc', 'no-comment']);
|
|
181
|
+
expect(byFile.get('bare/jsdoc.ts')).toBe('JSDoc 首行描述');
|
|
182
|
+
expect(byFile.get('bare/no-comment.ts')).toBe('no-comment');
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('读失败的文件交回文件名(并发回填不改变原 try/catch 兜底语义)', async () => {
|
|
186
|
+
write('fallback/here.ts', '/**\n * 在场文件的描述\n */\nexport const c = 3;\n');
|
|
187
|
+
|
|
188
|
+
const descriptions = await extractFileDescriptions([
|
|
189
|
+
path.join(tempDir, 'fallback', 'here.ts'),
|
|
190
|
+
path.join(tempDir, 'fallback', 'gone.ts'),
|
|
191
|
+
path.join(tempDir, 'fallback', 'also-here.ts'),
|
|
192
|
+
]);
|
|
193
|
+
|
|
194
|
+
expect(descriptions).toEqual(['在场文件的描述', 'gone', 'also-here']);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
@@ -1,43 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* CONTEXT.md 同步器(工单 22):缺失模板生成 + 既有文件发现 + 过时判定
|
|
3
|
+
* + 目录导出面采集(harness#142,供 context-reconcile 的内容判定喂数)
|
|
3
4
|
*/
|
|
4
5
|
|
|
5
6
|
import * as fs from 'fs/promises';
|
|
7
|
+
import { existsSync } from 'fs';
|
|
6
8
|
import * as path from 'path';
|
|
7
|
-
import { DEFAULT_SKIP_DIRS } from '../../../utils/file-walk';
|
|
9
|
+
import { DEFAULT_SKIP_DIRS, findTsSourceFiles } from '../../../utils/file-walk';
|
|
10
|
+
import { parseExportStatements } from '../../../core/constraints/context-reconcile';
|
|
11
|
+
import type { CommandIO } from '../../command-contract';
|
|
12
|
+
import {
|
|
13
|
+
contextDocFile,
|
|
14
|
+
nodeScaffoldFs,
|
|
15
|
+
runPlan,
|
|
16
|
+
type ScaffoldFileSystem,
|
|
17
|
+
type ScaffoldOutcome,
|
|
18
|
+
} from '../scaffold';
|
|
8
19
|
|
|
9
20
|
/**
|
|
10
|
-
* 创建 CONTEXT.md
|
|
21
|
+
* 创建 CONTEXT.md 模板:走 scaffold 正本站点(contextDocFile + runPlan),
|
|
22
|
+
* 与 init 的 CONTEXT.md 落点共用同一份模板正文(harness#150,#132 口径外的第 9 处)。
|
|
23
|
+
*
|
|
24
|
+
* 只在 `contextMissing` 的目录上被调用,故正常只走 `created`;若落到 `exists`
|
|
25
|
+
* 说明 sync-docs 的缺失判定与 scaffold 的在场判定口径不一致(不静默兜,交由调用方感知)。
|
|
11
26
|
*/
|
|
12
|
-
export async function createContextMd(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
> 如果使用 AI 编码助手,将本文件内容作为 prompt 请求它分析并填写。
|
|
21
|
-
|
|
22
|
-
## 职责
|
|
23
|
-
|
|
24
|
-
本目录的核心职责是?
|
|
25
|
-
|
|
26
|
-
## 核心导出
|
|
27
|
-
|
|
28
|
-
本目录对外暴露的主要模块/函数:
|
|
29
|
-
|
|
30
|
-
## 依赖关系
|
|
31
|
-
|
|
32
|
-
本目录依赖哪些其他模块,谁依赖本目录?
|
|
33
|
-
|
|
34
|
-
## 注意事项
|
|
35
|
-
|
|
36
|
-
开发时需要注意的约束或约定:
|
|
37
|
-
`;
|
|
38
|
-
|
|
39
|
-
await fs.mkdir(path.join(projectPath, dir), { recursive: true });
|
|
40
|
-
await fs.writeFile(contextPath, content, 'utf-8');
|
|
27
|
+
export async function createContextMd(
|
|
28
|
+
projectPath: string,
|
|
29
|
+
dir: string,
|
|
30
|
+
io: CommandIO,
|
|
31
|
+
scaffoldFs: ScaffoldFileSystem = nodeScaffoldFs,
|
|
32
|
+
): Promise<ScaffoldOutcome> {
|
|
33
|
+
const [outcome] = await runPlan([contextDocFile(projectPath, dir)], io, scaffoldFs);
|
|
34
|
+
return outcome;
|
|
41
35
|
}
|
|
42
36
|
|
|
43
37
|
/**
|
|
@@ -107,3 +101,115 @@ export async function getLatestTsMtime(dirPath: string): Promise<number | null>
|
|
|
107
101
|
await scan(dirPath);
|
|
108
102
|
return latest;
|
|
109
103
|
}
|
|
104
|
+
|
|
105
|
+
/** 目录导出面采集结果(harness#142) */
|
|
106
|
+
export interface ContextExportSurface {
|
|
107
|
+
/** 目录内所有 .ts 导出的符号名(值 + 类型,含 barrel 再导出) */
|
|
108
|
+
surface: string[];
|
|
109
|
+
/** `index.ts` barrel 再导出的**值**符号(类型-only 已剔除);无 index.ts → 空 */
|
|
110
|
+
barrelExports: string[];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** 文件名的导出表:name → typeOnly(口径正本是 context-reconcile 的语句解析) */
|
|
114
|
+
type ExportMap = Map<string, boolean>;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 把相对 spec 解析为仓内可读的 .ts 文件(`./x` → `x.ts` 或 `x/index.ts`);
|
|
118
|
+
* 非相对 spec、越出项目根、命中 `.d.ts`/`node_modules`/跳过目录一律 null(不并入导出面)。
|
|
119
|
+
*/
|
|
120
|
+
function resolveTsTarget(fromFile: string, spec: string, projectPath: string): string | null {
|
|
121
|
+
if (!spec.startsWith('.')) return null;
|
|
122
|
+
const base = path.resolve(path.dirname(fromFile), spec);
|
|
123
|
+
for (const candidate of [`${base}.ts`, path.join(base, 'index.ts')]) {
|
|
124
|
+
if (candidate.endsWith('.d.ts')) continue;
|
|
125
|
+
const rel = path.relative(projectPath, candidate);
|
|
126
|
+
if (!rel || rel.startsWith('..') || rel.includes('node_modules')) continue;
|
|
127
|
+
if (rel.split(path.sep).some((segment) => DEFAULT_SKIP_DIRS.includes(segment))) continue;
|
|
128
|
+
if (existsSync(candidate)) return candidate;
|
|
129
|
+
}
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* 单文件导出表(含再导出与 `export *` 展开),memo 化 + 在途集合破环。
|
|
135
|
+
*
|
|
136
|
+
* 递归只沿 `export *` 与具名再导出的来源走,读到的都是仓内 .ts;
|
|
137
|
+
* 环上(A `export * from './b'`、B `export * from './a'`)在途文件交空表,
|
|
138
|
+
* 与 tsc 的星号环语义一致(不因此丢名字——真实名字总有非环上的一条声明路径)。
|
|
139
|
+
*/
|
|
140
|
+
async function collectFileExports(
|
|
141
|
+
file: string,
|
|
142
|
+
projectPath: string,
|
|
143
|
+
cache: Map<string, ExportMap>,
|
|
144
|
+
inProgress: Set<string>
|
|
145
|
+
): Promise<ExportMap> {
|
|
146
|
+
const cached = cache.get(file);
|
|
147
|
+
if (cached) return cached;
|
|
148
|
+
if (inProgress.has(file)) return new Map();
|
|
149
|
+
inProgress.add(file);
|
|
150
|
+
|
|
151
|
+
const out: ExportMap = new Map();
|
|
152
|
+
let source: string;
|
|
153
|
+
try {
|
|
154
|
+
source = await fs.readFile(file, 'utf-8');
|
|
155
|
+
} catch {
|
|
156
|
+
inProgress.delete(file);
|
|
157
|
+
cache.set(file, out);
|
|
158
|
+
return out;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const { symbols, starFrom } = parseExportStatements(source);
|
|
162
|
+
for (const symbol of symbols) {
|
|
163
|
+
let typeOnly = symbol.typeOnly;
|
|
164
|
+
if (symbol.from) {
|
|
165
|
+
const origin = resolveTsTarget(file, symbol.from, projectPath);
|
|
166
|
+
// 环上(origin 在途)时交回的是空表,那是「不知道」不是「没有」→ 不做虚判
|
|
167
|
+
if (origin && !inProgress.has(origin)) {
|
|
168
|
+
const originExports = await collectFileExports(origin, projectPath, cache, inProgress);
|
|
169
|
+
// 正本没有这个本名 → 这条再导出是虚的(改名未跟上的 barrel),不计入导出面,
|
|
170
|
+
// 否则文档里的幽灵会被 barrel 自己洗白(harness#142 反证撞出的口径漏洞)
|
|
171
|
+
if (!originExports.has(symbol.localName)) continue;
|
|
172
|
+
if (!typeOnly && originExports.get(symbol.localName) === true) typeOnly = true;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
out.set(symbol.name, typeOnly);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
for (const spec of starFrom) {
|
|
179
|
+
const target = resolveTsTarget(file, spec, projectPath);
|
|
180
|
+
if (!target) continue;
|
|
181
|
+
const targetExports = await collectFileExports(target, projectPath, cache, inProgress);
|
|
182
|
+
for (const [name, typeOnly] of targetExports) if (!out.has(name)) out.set(name, typeOnly);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
inProgress.delete(file);
|
|
186
|
+
cache.set(file, out);
|
|
187
|
+
return out;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* 采集目录导出面(内容判定的代码侧):目录内 .ts(排 `__tests__/`、`.d.ts`)的导出符号全集,
|
|
192
|
+
* 以及 barrel(`index.ts`)再导出的值符号清单。fs IO 全在此,判定不在(ADR-0025)。
|
|
193
|
+
*/
|
|
194
|
+
export async function collectContextExportSurface(
|
|
195
|
+
dirPath: string,
|
|
196
|
+
projectPath: string
|
|
197
|
+
): Promise<ContextExportSurface> {
|
|
198
|
+
const files = findTsSourceFiles(dirPath);
|
|
199
|
+
const cache = new Map<string, ExportMap>();
|
|
200
|
+
const surface = new Set<string>();
|
|
201
|
+
|
|
202
|
+
for (const file of files) {
|
|
203
|
+
const fileExports = await collectFileExports(file, projectPath, cache, new Set());
|
|
204
|
+
for (const name of fileExports.keys()) surface.add(name);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const barrelExports: string[] = [];
|
|
208
|
+
const barrelFile = path.join(dirPath, 'index.ts');
|
|
209
|
+
if (files.includes(barrelFile)) {
|
|
210
|
+
const barrel = await collectFileExports(barrelFile, projectPath, cache, new Set());
|
|
211
|
+
for (const [name, typeOnly] of barrel) if (!typeOnly) barrelExports.push(name);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return { surface: [...surface], barrelExports };
|
|
215
|
+
}
|