@dommaker/harness 1.6.0 → 1.8.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/CHANGELOG.md +52 -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 +11 -3
- package/dist/cli/commands/check.d.ts.map +1 -1
- package/dist/cli/commands/check.js +26 -11
- 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/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/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 +2 -1
- 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/core/validators/index.d.ts +1 -1
- package/dist/core/validators/index.d.ts.map +1 -1
- package/dist/core/validators/passes-gate.d.ts.map +1 -1
- package/dist/core/validators/passes-gate.js +2 -2
- package/dist/core/validators/passes-gate.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.map +1 -1
- package/dist/hooks/pipeline.js +2 -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 +23 -7
- package/dist/hooks/types.d.ts.map +1 -1
- package/dist/index.d.ts +4 -4
- 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/passes-gate.d.ts +0 -13
- package/dist/types/passes-gate.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 +27 -6
- package/src/__tests__/public-type-surface.test.ts +360 -0
- 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/commands/CONTEXT.md +29 -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 +167 -0
- package/src/cli/commands/__tests__/check-skip-output.test.ts +4 -1
- package/src/cli/commands/__tests__/check.test.ts +43 -36
- 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__/passes-gate-dead-options.test.ts +89 -1
- 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__/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 +40 -17
- 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/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/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 -1
- 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/core/validators/index.ts +0 -1
- package/src/core/validators/passes-gate.ts +2 -3
- 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 +28 -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 +4 -6
- package/src/hooks/registry.ts +31 -12
- package/src/hooks/types.ts +24 -7
- package/src/index.ts +1 -3
- 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/passes-gate.ts +0 -17
- 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
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import * as fs from 'fs';
|
|
6
6
|
import * as path from 'path';
|
|
7
|
+
import * as os from 'os';
|
|
7
8
|
import { FileKnowledgeStore as KnowledgeStore } from '../store';
|
|
8
9
|
import { KnowledgeLinter } from '../lint';
|
|
9
10
|
import { ReferenceTracker } from '../reference-tracker';
|
|
@@ -11,14 +12,14 @@ import { KnowledgeHealthScorer } from '../doctor';
|
|
|
11
12
|
import type { KnowledgeEntry } from '../types';
|
|
12
13
|
|
|
13
14
|
describe('KnowledgeHealthScorer', () => {
|
|
14
|
-
|
|
15
|
+
let tempDir: string;
|
|
15
16
|
let store: KnowledgeStore;
|
|
16
17
|
let tracker: ReferenceTracker;
|
|
17
18
|
let linter: KnowledgeLinter;
|
|
18
19
|
let scorer: KnowledgeHealthScorer;
|
|
19
20
|
|
|
20
21
|
beforeAll(() => {
|
|
21
|
-
fs.
|
|
22
|
+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'temp-test-knowledge-doctor-'));
|
|
22
23
|
});
|
|
23
24
|
|
|
24
25
|
afterAll(() => {
|
|
@@ -7,14 +7,15 @@ import { FileKnowledgeStore as KnowledgeStore } from '../store';
|
|
|
7
7
|
import { KnowledgeIngest } from '../ingest';
|
|
8
8
|
import * as fs from 'fs';
|
|
9
9
|
import * as path from 'path';
|
|
10
|
+
import * as os from 'os';
|
|
10
11
|
|
|
11
12
|
describe('KnowledgeIngest', () => {
|
|
12
|
-
|
|
13
|
+
let tempDir: string;
|
|
13
14
|
let store: KnowledgeStore;
|
|
14
15
|
let ingest: KnowledgeIngest;
|
|
15
16
|
|
|
16
17
|
beforeAll(() => {
|
|
17
|
-
fs.
|
|
18
|
+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'temp-test-ingest-'));
|
|
18
19
|
});
|
|
19
20
|
|
|
20
21
|
afterAll(() => {
|
|
@@ -8,9 +8,10 @@ import { KnowledgeLifecycle } from '../lifecycle';
|
|
|
8
8
|
import type { KnowledgeEntry } from '../types';
|
|
9
9
|
import * as fs from 'fs';
|
|
10
10
|
import * as path from 'path';
|
|
11
|
+
import * as os from 'os';
|
|
11
12
|
|
|
12
13
|
describe('KnowledgeLifecycle', () => {
|
|
13
|
-
|
|
14
|
+
let tempDir: string;
|
|
14
15
|
let store: KnowledgeStore;
|
|
15
16
|
let lifecycle: KnowledgeLifecycle;
|
|
16
17
|
|
|
@@ -36,7 +37,7 @@ describe('KnowledgeLifecycle', () => {
|
|
|
36
37
|
});
|
|
37
38
|
|
|
38
39
|
beforeAll(() => {
|
|
39
|
-
fs.
|
|
40
|
+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'temp-test-lifecycle-'));
|
|
40
41
|
});
|
|
41
42
|
|
|
42
43
|
afterAll(() => {
|
|
@@ -396,6 +397,27 @@ describe('KnowledgeLifecycle', () => {
|
|
|
396
397
|
expect(changes[0].from).toBe('proven');
|
|
397
398
|
expect(changes[0].to).toBe('verified');
|
|
398
399
|
});
|
|
400
|
+
|
|
401
|
+
it('一次 cycle 的 K 条衰减只重写一次 index.json(harness#134 走 applyAll)', () => {
|
|
402
|
+
const oldDate = new Date();
|
|
403
|
+
oldDate.setMonth(oldDate.getMonth() - 4);
|
|
404
|
+
for (const id of ['DEC-001', 'DEC-002', 'DEC-003']) {
|
|
405
|
+
store.save(makeEntry({ id, maturity: 'draft', lastReferenced: oldDate.toISOString() }));
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const stringifySpy = jest.spyOn(JSON, 'stringify');
|
|
409
|
+
try {
|
|
410
|
+
const changes = lifecycle.runDecayCycle();
|
|
411
|
+
// 正对照:3 条真衰减,否则「1 次重写」是空跑出来的
|
|
412
|
+
expect(changes.map(c => c.entryId)).toEqual(['DEC-001', 'DEC-002', 'DEC-003']);
|
|
413
|
+
expect(stringifySpy).toHaveBeenCalledTimes(1);
|
|
414
|
+
} finally {
|
|
415
|
+
stringifySpy.mockRestore();
|
|
416
|
+
}
|
|
417
|
+
for (const id of ['DEC-001', 'DEC-002', 'DEC-003']) {
|
|
418
|
+
expect(store.get(id)!.maturity).toBe('archived');
|
|
419
|
+
}
|
|
420
|
+
});
|
|
399
421
|
});
|
|
400
422
|
|
|
401
423
|
describe('tryPromote', () => {
|
|
@@ -732,6 +754,39 @@ describe('KnowledgeLifecycle', () => {
|
|
|
732
754
|
expect(lifecycle.checkEntryDecay('RULE-001')).toBe('deprecated');
|
|
733
755
|
});
|
|
734
756
|
|
|
757
|
+
it('边界钉:成功率恰 0.5(失败率恰 50%)即降级(harness#161 修边界差一)', () => {
|
|
758
|
+
store.save(makeEntry({
|
|
759
|
+
id: 'RULE-001',
|
|
760
|
+
consumptionMode: 'rule',
|
|
761
|
+
maturity: 'active',
|
|
762
|
+
content: 'API port must be 13101',
|
|
763
|
+
executionResults: [
|
|
764
|
+
{ contributor: 'alice', success: true, timestamp: '2026-05-01T00:00:00.000Z' },
|
|
765
|
+
{ contributor: 'bob', success: false, timestamp: '2026-05-02T00:00:00.000Z' },
|
|
766
|
+
{ contributor: 'charlie', success: true, timestamp: '2026-05-03T00:00:00.000Z' },
|
|
767
|
+
{ contributor: 'dave', success: false, timestamp: '2026-05-04T00:00:00.000Z' },
|
|
768
|
+
],
|
|
769
|
+
}));
|
|
770
|
+
expect(lifecycle.checkEntryDecay('RULE-001')).toBe('deprecated');
|
|
771
|
+
});
|
|
772
|
+
|
|
773
|
+
it('成功率略高于 0.5(3 成 2 败)不降级', () => {
|
|
774
|
+
store.save(makeEntry({
|
|
775
|
+
id: 'RULE-001',
|
|
776
|
+
consumptionMode: 'rule',
|
|
777
|
+
maturity: 'active',
|
|
778
|
+
content: 'API port must be 13101',
|
|
779
|
+
executionResults: [
|
|
780
|
+
{ contributor: 'alice', success: true, timestamp: '2026-05-01T00:00:00.000Z' },
|
|
781
|
+
{ contributor: 'bob', success: true, timestamp: '2026-05-02T00:00:00.000Z' },
|
|
782
|
+
{ contributor: 'charlie', success: true, timestamp: '2026-05-03T00:00:00.000Z' },
|
|
783
|
+
{ contributor: 'dave', success: false, timestamp: '2026-05-04T00:00:00.000Z' },
|
|
784
|
+
{ contributor: 'erin', success: false, timestamp: '2026-05-05T00:00:00.000Z' },
|
|
785
|
+
],
|
|
786
|
+
}));
|
|
787
|
+
expect(lifecycle.checkEntryDecay('RULE-001')).toBeUndefined();
|
|
788
|
+
});
|
|
789
|
+
|
|
735
790
|
it('should NOT decay active→deprecated when fail rate < 50%', () => {
|
|
736
791
|
store.save(makeEntry({
|
|
737
792
|
id: 'RULE-001',
|
|
@@ -6,12 +6,13 @@ import { describe, it, expect, beforeAll, afterAll, beforeEach } from '@jest/glo
|
|
|
6
6
|
import { migrateKnowledgeEntries } from '../migration';
|
|
7
7
|
import * as fs from 'fs';
|
|
8
8
|
import * as path from 'path';
|
|
9
|
+
import * as os from 'os';
|
|
9
10
|
|
|
10
11
|
describe('migrateKnowledgeEntries', () => {
|
|
11
|
-
|
|
12
|
+
let tempDir: string;
|
|
12
13
|
|
|
13
14
|
beforeAll(() => {
|
|
14
|
-
fs.
|
|
15
|
+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'temp-test-migration-'));
|
|
15
16
|
});
|
|
16
17
|
|
|
17
18
|
afterAll(() => {
|
|
@@ -107,20 +108,48 @@ describe('migrateKnowledgeEntries', () => {
|
|
|
107
108
|
expect(second.skipped).toBe(1);
|
|
108
109
|
});
|
|
109
110
|
|
|
111
|
+
describe('知识树生成物豁免(harness#134 walker 口径单点化)', () => {
|
|
112
|
+
it('_index.md 既不计入 total 也不计入 errors(修此前的假阳性)', () => {
|
|
113
|
+
// 真实组合:knowledge index 把生成物落在同一个 baseDir,无 frontmatter
|
|
114
|
+
fs.writeFileSync(
|
|
115
|
+
path.join(tempDir, '_index.md'),
|
|
116
|
+
'# Knowledge Base Index\n# Auto-generated\n\n# filename|id|type\n',
|
|
117
|
+
'utf-8'
|
|
118
|
+
);
|
|
119
|
+
writeEntry('DEC-010.md', {
|
|
120
|
+
id: 'DEC-010', type: 'decision', title: 'Test', maturity: 'draft',
|
|
121
|
+
layer: 'project', created: '2026-05-01', lastReferenced: '',
|
|
122
|
+
contributors: [], projects: [], tags: [], applicablePhases: [],
|
|
123
|
+
sourceReferences: [], referencedBy: [], executionResults: [],
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const result = migrateKnowledgeEntries(tempDir);
|
|
127
|
+
expect(result.total).toBe(1);
|
|
128
|
+
expect(result.errors).toEqual([]);
|
|
129
|
+
expect(result.migrated).toBe(1);
|
|
130
|
+
// 生成物不被改写
|
|
131
|
+
expect(fs.readFileSync(path.join(tempDir, '_index.md'), 'utf-8'))
|
|
132
|
+
.toContain('# Auto-generated');
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
110
136
|
describe('frontmatter 收口(harness#89)', () => {
|
|
111
|
-
it('缺 frontmatter:errors
|
|
137
|
+
it('缺 frontmatter:absent 是合法输入——不进 errors,按非条目语义计入 skipped(harness#161 裁决,正本 #89 裁决 2)', () => {
|
|
112
138
|
fs.writeFileSync(path.join(tempDir, 'PLAIN.md'), '# 只是普通 markdown\n\n正文\n', 'utf-8');
|
|
113
139
|
|
|
114
140
|
const result = migrateKnowledgeEntries(tempDir);
|
|
115
|
-
expect(result.errors).toEqual([
|
|
141
|
+
expect(result.errors).toEqual([]);
|
|
116
142
|
expect(result.migrated).toBe(0);
|
|
143
|
+
expect(result.skipped).toBe(1);
|
|
144
|
+
expect(result.total).toBe(1);
|
|
117
145
|
});
|
|
118
146
|
|
|
119
|
-
it('空 meta:与缺 frontmatter 同走一支(absent
|
|
147
|
+
it('空 meta:与缺 frontmatter 同走一支(absent),不进 errors、计 skipped', () => {
|
|
120
148
|
fs.writeFileSync(path.join(tempDir, 'EMPTY-META.md'), '---\n\n---\n\nBody\n', 'utf-8');
|
|
121
149
|
|
|
122
150
|
const result = migrateKnowledgeEntries(tempDir);
|
|
123
|
-
expect(result.errors).toEqual([
|
|
151
|
+
expect(result.errors).toEqual([]);
|
|
152
|
+
expect(result.skipped).toBe(1);
|
|
124
153
|
});
|
|
125
154
|
|
|
126
155
|
it('未闭合:errors 显式记 unterminated(收口前是一条 YAML 内部报错)', () => {
|
|
@@ -8,9 +8,10 @@ import { KnowledgeQuery } from '../query';
|
|
|
8
8
|
import type { KnowledgeEntry, QueryBudget } from '../types';
|
|
9
9
|
import * as fs from 'fs';
|
|
10
10
|
import * as path from 'path';
|
|
11
|
+
import * as os from 'os';
|
|
11
12
|
|
|
12
13
|
describe('KnowledgeQuery', () => {
|
|
13
|
-
|
|
14
|
+
let tempDir: string;
|
|
14
15
|
let store: KnowledgeStore;
|
|
15
16
|
let query: KnowledgeQuery;
|
|
16
17
|
|
|
@@ -36,7 +37,7 @@ describe('KnowledgeQuery', () => {
|
|
|
36
37
|
});
|
|
37
38
|
|
|
38
39
|
beforeAll(() => {
|
|
39
|
-
fs.
|
|
40
|
+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'temp-test-query-'));
|
|
40
41
|
});
|
|
41
42
|
|
|
42
43
|
afterAll(() => {
|
|
@@ -8,9 +8,10 @@ import { ReferenceTracker } from '../reference-tracker';
|
|
|
8
8
|
import type { KnowledgeEntry } from '../types';
|
|
9
9
|
import * as fs from 'fs';
|
|
10
10
|
import * as path from 'path';
|
|
11
|
+
import * as os from 'os';
|
|
11
12
|
|
|
12
13
|
describe('ReferenceTracker', () => {
|
|
13
|
-
|
|
14
|
+
let tempDir: string;
|
|
14
15
|
let store: KnowledgeStore;
|
|
15
16
|
let tracker: ReferenceTracker;
|
|
16
17
|
|
|
@@ -36,7 +37,7 @@ describe('ReferenceTracker', () => {
|
|
|
36
37
|
});
|
|
37
38
|
|
|
38
39
|
beforeAll(() => {
|
|
39
|
-
fs.
|
|
40
|
+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'temp-test-refs-'));
|
|
40
41
|
});
|
|
41
42
|
|
|
42
43
|
afterAll(() => {
|
|
@@ -116,6 +117,26 @@ describe('ReferenceTracker', () => {
|
|
|
116
117
|
expect(e1!.referencedBy).toContain('decision-2');
|
|
117
118
|
expect(e2!.referencedBy).toEqual(['decision-2']);
|
|
118
119
|
});
|
|
120
|
+
|
|
121
|
+
it('K 条 referencedBy 更新只重写一次 index.json(harness#134 走 applyAll)', () => {
|
|
122
|
+
for (const id of ['entry-1', 'entry-2', 'entry-3']) {
|
|
123
|
+
store.save(makeEntry({ id }));
|
|
124
|
+
}
|
|
125
|
+
tracker.record('decision-1', ['entry-1', 'entry-2', 'entry-3']);
|
|
126
|
+
|
|
127
|
+
const stringifySpy = jest.spyOn(JSON, 'stringify');
|
|
128
|
+
try {
|
|
129
|
+
tracker.updateReferencedBy();
|
|
130
|
+
expect(stringifySpy).toHaveBeenCalledTimes(1);
|
|
131
|
+
} finally {
|
|
132
|
+
stringifySpy.mockRestore();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// 正对照:3 条真写入,否则「1 次重写」是空跑出来的
|
|
136
|
+
for (const id of ['entry-1', 'entry-2', 'entry-3']) {
|
|
137
|
+
expect(store.get(id)!.referencedBy).toEqual(['decision-1']);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
119
140
|
});
|
|
120
141
|
|
|
121
142
|
describe('edge cases', () => {
|
|
@@ -7,9 +7,10 @@ import { FileKnowledgeStore as KnowledgeStore } from '../store';
|
|
|
7
7
|
import type { KnowledgeEntry } from '../types';
|
|
8
8
|
import * as fs from 'fs';
|
|
9
9
|
import * as path from 'path';
|
|
10
|
+
import * as os from 'os';
|
|
10
11
|
|
|
11
12
|
describe('KnowledgeStore', () => {
|
|
12
|
-
|
|
13
|
+
let tempDir: string;
|
|
13
14
|
let store: KnowledgeStore;
|
|
14
15
|
|
|
15
16
|
const makeEntry = (overrides?: Partial<KnowledgeEntry>): KnowledgeEntry => ({
|
|
@@ -34,7 +35,7 @@ describe('KnowledgeStore', () => {
|
|
|
34
35
|
});
|
|
35
36
|
|
|
36
37
|
beforeAll(() => {
|
|
37
|
-
fs.
|
|
38
|
+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'temp-test-knowledge-'));
|
|
38
39
|
});
|
|
39
40
|
|
|
40
41
|
afterAll(() => {
|
|
@@ -224,10 +225,11 @@ describe('KnowledgeStore', () => {
|
|
|
224
225
|
});
|
|
225
226
|
|
|
226
227
|
it('should create directory if it does not exist', () => {
|
|
227
|
-
const
|
|
228
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'temp-test-knowledge-nested-'));
|
|
229
|
+
const newDir = path.join(root, 'sub', 'deep');
|
|
228
230
|
new KnowledgeStore({ baseDir: newDir });
|
|
229
231
|
expect(fs.existsSync(newDir)).toBe(true);
|
|
230
|
-
fs.rmSync(
|
|
232
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
231
233
|
});
|
|
232
234
|
|
|
233
235
|
it('should handle corrupt index.json gracefully', () => {
|
|
@@ -585,6 +587,149 @@ describe('KnowledgeStore', () => {
|
|
|
585
587
|
});
|
|
586
588
|
});
|
|
587
589
|
|
|
590
|
+
describe('applyAll 按 id 部分更新的批量出口(harness#134)', () => {
|
|
591
|
+
it('K 条部分更新只重写一次 index.json', () => {
|
|
592
|
+
store.saveAll([
|
|
593
|
+
makeEntry({ id: 'DEC-001' }),
|
|
594
|
+
makeEntry({ id: 'DEC-002', title: 'Second' }),
|
|
595
|
+
makeEntry({ id: 'DEC-003', title: 'Third' }),
|
|
596
|
+
]);
|
|
597
|
+
|
|
598
|
+
const stringifySpy = jest.spyOn(JSON, 'stringify');
|
|
599
|
+
try {
|
|
600
|
+
store.applyAll([
|
|
601
|
+
{ id: 'DEC-001', partial: { maturity: 'archived' } },
|
|
602
|
+
{ id: 'DEC-002', partial: { maturity: 'draft' } },
|
|
603
|
+
{ id: 'DEC-003', partial: { tags: ['low_quality'] } },
|
|
604
|
+
]);
|
|
605
|
+
expect(stringifySpy).toHaveBeenCalledTimes(1);
|
|
606
|
+
} finally {
|
|
607
|
+
stringifySpy.mockRestore();
|
|
608
|
+
}
|
|
609
|
+
});
|
|
610
|
+
|
|
611
|
+
it('只改给到的字段,其余字段原样保留(与 update() 同语义)', () => {
|
|
612
|
+
store.save(makeEntry({ id: 'DEC-001', title: 'Keep Me', contributors: ['a'], tags: ['t1'] }));
|
|
613
|
+
|
|
614
|
+
store.applyAll([{ id: 'DEC-001', partial: { maturity: 'archived' } }]);
|
|
615
|
+
|
|
616
|
+
const after = store.get('DEC-001')!;
|
|
617
|
+
expect(after.maturity).toBe('archived');
|
|
618
|
+
expect(after.title).toBe('Keep Me');
|
|
619
|
+
expect(after.contributors).toEqual(['a']);
|
|
620
|
+
expect(after.tags).toEqual(['t1']);
|
|
621
|
+
expect(after.content).toBe('This is a test decision.');
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
it('id 不可被 partial 改写(与 update() 同语义)', () => {
|
|
625
|
+
store.save(makeEntry({ id: 'DEC-001' }));
|
|
626
|
+
store.applyAll([{ id: 'DEC-001', partial: { id: 'HACKED' as never } }]);
|
|
627
|
+
|
|
628
|
+
expect(store.get('DEC-001')!.id).toBe('DEC-001');
|
|
629
|
+
expect(store.get('HACKED')).toBeUndefined();
|
|
630
|
+
expect(store.readIndex().map(e => e.id)).toEqual(['DEC-001']);
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
it('未知 id 跳过:不写文件、索引不增项,其余条目照常落盘', () => {
|
|
634
|
+
store.save(makeEntry({ id: 'DEC-001' }));
|
|
635
|
+
|
|
636
|
+
store.applyAll([
|
|
637
|
+
{ id: 'GHOST', partial: { maturity: 'archived' } },
|
|
638
|
+
{ id: 'DEC-001', partial: { maturity: 'archived' } },
|
|
639
|
+
]);
|
|
640
|
+
|
|
641
|
+
expect(fs.existsSync(path.join(tempDir, 'decision-GHOST.md'))).toBe(false);
|
|
642
|
+
expect(store.readIndex().map(e => e.id)).toEqual(['DEC-001']);
|
|
643
|
+
expect(store.get('DEC-001')!.maturity).toBe('archived');
|
|
644
|
+
});
|
|
645
|
+
|
|
646
|
+
it('批内同 id 多条:按顺序累积合并(后者不覆盖前者已改的字段)', () => {
|
|
647
|
+
store.save(makeEntry({ id: 'DEC-001', tags: ['t1'] }));
|
|
648
|
+
|
|
649
|
+
store.applyAll([
|
|
650
|
+
{ id: 'DEC-001', partial: { maturity: 'archived' } },
|
|
651
|
+
{ id: 'DEC-001', partial: { tags: ['t1', 'low_quality'] } },
|
|
652
|
+
]);
|
|
653
|
+
|
|
654
|
+
const after = store.get('DEC-001')!;
|
|
655
|
+
expect(after.maturity).toBe('archived');
|
|
656
|
+
expect(after.tags).toEqual(['t1', 'low_quality']);
|
|
657
|
+
expect(store.readIndex()).toHaveLength(1);
|
|
658
|
+
});
|
|
659
|
+
|
|
660
|
+
it('空批零读写,不创建 index.json', () => {
|
|
661
|
+
const stringifySpy = jest.spyOn(JSON, 'stringify');
|
|
662
|
+
try {
|
|
663
|
+
store.applyAll([]);
|
|
664
|
+
expect(stringifySpy).not.toHaveBeenCalled();
|
|
665
|
+
} finally {
|
|
666
|
+
stringifySpy.mockRestore();
|
|
667
|
+
}
|
|
668
|
+
expect(fs.existsSync(path.join(tempDir, 'index.json'))).toBe(false);
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
it('applyAll 后 list() 立即可见(缓存指纹失效)', () => {
|
|
672
|
+
store.save(makeEntry({ id: 'DEC-001' }));
|
|
673
|
+
expect(store.list()).toHaveLength(1); // 预热缓存
|
|
674
|
+
|
|
675
|
+
store.applyAll([{ id: 'DEC-001', partial: { maturity: 'archived' } }]);
|
|
676
|
+
|
|
677
|
+
expect(store.list({ excludeArchived: false })[0].maturity).toBe('archived');
|
|
678
|
+
});
|
|
679
|
+
|
|
680
|
+
it('与逐条 update() 的落盘结果逐字节相同(只是少重写索引)', () => {
|
|
681
|
+
const updates = [
|
|
682
|
+
{ id: 'DEC-001', partial: { maturity: 'archived' as const } },
|
|
683
|
+
{ id: 'DEC-002', partial: { tags: ['x'] } },
|
|
684
|
+
];
|
|
685
|
+
store.save(makeEntry({ id: 'DEC-001' }));
|
|
686
|
+
store.save(makeEntry({ id: 'DEC-002' }));
|
|
687
|
+
for (const u of updates) store.update(u.id, u.partial);
|
|
688
|
+
const perEntry = {
|
|
689
|
+
md1: fs.readFileSync(path.join(tempDir, 'decision-DEC-001.md'), 'utf-8'),
|
|
690
|
+
md2: fs.readFileSync(path.join(tempDir, 'decision-DEC-002.md'), 'utf-8'),
|
|
691
|
+
index: fs.readFileSync(path.join(tempDir, 'index.json'), 'utf-8'),
|
|
692
|
+
};
|
|
693
|
+
|
|
694
|
+
const fresh = new KnowledgeStore({ baseDir: tempDir });
|
|
695
|
+
fresh.save(makeEntry({ id: 'DEC-001' }));
|
|
696
|
+
fresh.save(makeEntry({ id: 'DEC-002' }));
|
|
697
|
+
fresh.applyAll(updates);
|
|
698
|
+
expect({
|
|
699
|
+
md1: fs.readFileSync(path.join(tempDir, 'decision-DEC-001.md'), 'utf-8'),
|
|
700
|
+
md2: fs.readFileSync(path.join(tempDir, 'decision-DEC-002.md'), 'utf-8'),
|
|
701
|
+
index: fs.readFileSync(path.join(tempDir, 'index.json'), 'utf-8'),
|
|
702
|
+
}).toEqual(perEntry);
|
|
703
|
+
});
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
describe('getConsumptionStats(harness#134:打分核心的 IO 归 store 供给)', () => {
|
|
707
|
+
const statsPath = (): string => path.join(tempDir, '.consumption-stats.json');
|
|
708
|
+
|
|
709
|
+
it('文件不存在 → undefined(未提供即无消费数据,不是 0 条记录)', () => {
|
|
710
|
+
expect(store.getConsumptionStats()).toBeUndefined();
|
|
711
|
+
});
|
|
712
|
+
|
|
713
|
+
it('读出 dailyEvents 供 D6 打分', () => {
|
|
714
|
+
fs.writeFileSync(
|
|
715
|
+
statsPath(),
|
|
716
|
+
JSON.stringify({ date: '2026-09-15', dailyEvents: 12, searchHits: 5 }),
|
|
717
|
+
'utf-8'
|
|
718
|
+
);
|
|
719
|
+
expect(store.getConsumptionStats()).toEqual({ dailyEvents: 12 });
|
|
720
|
+
});
|
|
721
|
+
|
|
722
|
+
it('坏 JSON → undefined,不抛(沿用直读侧 best-effort 语义)', () => {
|
|
723
|
+
fs.writeFileSync(statsPath(), 'NOT VALID JSON{{{', 'utf-8');
|
|
724
|
+
expect(store.getConsumptionStats()).toBeUndefined();
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
it('缺 dailyEvents 字段 → 0(有文件但无该计数)', () => {
|
|
728
|
+
fs.writeFileSync(statsPath(), JSON.stringify({ date: '2026-09-15' }), 'utf-8');
|
|
729
|
+
expect(store.getConsumptionStats()).toEqual({ dailyEvents: 0 });
|
|
730
|
+
});
|
|
731
|
+
});
|
|
732
|
+
|
|
588
733
|
describe('frontmatter 收口(harness#89)', () => {
|
|
589
734
|
const entryPath = (id: string): string => path.join(tempDir, `decision-${id}.md`);
|
|
590
735
|
let errorSpy: jest.SpyInstance;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 知识树 walker 排除口径单点化(harness#134,架构评审候选 4)
|
|
3
|
+
*
|
|
4
|
+
* 判据不是「各文件有没有抄同一份常量」,而是**同一份知识树在四个入口下得到同一份条目人口**:
|
|
5
|
+
* store 顶层扫描、migration 顶层扫描、index-generator 递归扫描此前各有各的排除口径,
|
|
6
|
+
* 后果是 `harness knowledge index` 落在 baseDir 的 `_index.md`(生成物、无 frontmatter)
|
|
7
|
+
* 被 `harness knowledge migrate` 判成「no frontmatter found」计入 errors——同一份树,
|
|
8
|
+
* `store.list()` 报 1 条、`migrateKnowledgeEntries` 报 total 2 / errors 1。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import * as fs from 'fs';
|
|
12
|
+
import * as os from 'os';
|
|
13
|
+
import * as path from 'path';
|
|
14
|
+
import { isEntryFile, isInfraDir, INDEX_MD_FILE, SNAPSHOTS_DIR } from '../tree-walker';
|
|
15
|
+
import { FileKnowledgeStore } from '../store';
|
|
16
|
+
import { KnowledgeIndexGenerator } from '../index-generator';
|
|
17
|
+
import { migrateKnowledgeEntries } from '../migration';
|
|
18
|
+
import type { KnowledgeEntry } from '../types';
|
|
19
|
+
|
|
20
|
+
function makeEntry(overrides: Partial<KnowledgeEntry> = {}): KnowledgeEntry {
|
|
21
|
+
return {
|
|
22
|
+
id: 'TREE-001',
|
|
23
|
+
type: 'guideline',
|
|
24
|
+
title: 'Tree Walker Entry',
|
|
25
|
+
content: '内容足够长以通过各口径的判定阈值要求'.repeat(3),
|
|
26
|
+
maturity: 'verified',
|
|
27
|
+
layer: 'project',
|
|
28
|
+
created: '2026-09-01T00:00:00.000Z',
|
|
29
|
+
lastReferenced: '2026-09-01T00:00:00.000Z',
|
|
30
|
+
contributors: ['a'],
|
|
31
|
+
projects: ['p'],
|
|
32
|
+
tags: [],
|
|
33
|
+
applicablePhases: [],
|
|
34
|
+
sourceReferences: [],
|
|
35
|
+
referencedBy: [],
|
|
36
|
+
executionResults: [],
|
|
37
|
+
consumptionMode: 'reference',
|
|
38
|
+
origin: 'agent',
|
|
39
|
+
...overrides,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
describe('tree-walker 谓词', () => {
|
|
44
|
+
it('条目文件判定:仅 .md 且非生成物', () => {
|
|
45
|
+
expect(isEntryFile('guideline-A.md')).toBe(true);
|
|
46
|
+
expect(isEntryFile(INDEX_MD_FILE)).toBe(false);
|
|
47
|
+
expect(isEntryFile('notes.txt')).toBe(false);
|
|
48
|
+
expect(isEntryFile('index.json')).toBe(false);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('基建目录判定:归档/快照/resolution 都不是条目人口', () => {
|
|
52
|
+
for (const dir of ['.archive', 'archived', SNAPSHOTS_DIR, 'resolutions']) {
|
|
53
|
+
expect(isInfraDir(dir)).toBe(true);
|
|
54
|
+
}
|
|
55
|
+
expect(isInfraDir('skills')).toBe(false);
|
|
56
|
+
expect(isInfraDir('.harness')).toBe(false);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('四个 walker 的条目人口一致(同一份树)', () => {
|
|
61
|
+
let dir: string;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 平铺知识库:2 个真条目 + 全部基建产物(_index.md / .snapshots / .archive / resolutions)
|
|
65
|
+
* 只放平铺层,因为 store 与 migration 本就是顶层扫描器、index-generator 会下钻业务子目录——
|
|
66
|
+
* 本票统一的是**排除口径**,不是递归深度。
|
|
67
|
+
*/
|
|
68
|
+
function buildTree(): void {
|
|
69
|
+
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'tree-walker-'));
|
|
70
|
+
const store = new FileKnowledgeStore({ baseDir: dir });
|
|
71
|
+
store.save(makeEntry({ id: 'TREE-001' }));
|
|
72
|
+
store.save(makeEntry({ id: 'TREE-002', type: 'pitfall', title: 'Another Entry' }));
|
|
73
|
+
|
|
74
|
+
for (const sub of ['.snapshots', '.archive', 'resolutions']) {
|
|
75
|
+
fs.mkdirSync(path.join(dir, sub), { recursive: true });
|
|
76
|
+
}
|
|
77
|
+
fs.writeFileSync(
|
|
78
|
+
path.join(dir, '.snapshots', 'index-2026-08-01.json'),
|
|
79
|
+
JSON.stringify([{ id: 'TREE-001', type: 'guideline' }]),
|
|
80
|
+
'utf-8'
|
|
81
|
+
);
|
|
82
|
+
// 基建目录里的 .md 带着合法 frontmatter:口径若漏了排除,它们会冒充条目
|
|
83
|
+
const fakeEntry = (id: string): string =>
|
|
84
|
+
`---\nid: ${id}\ntype: pitfall\ntitle: Ghost ${id}\nmaturity: verified\nlayer: project\n` +
|
|
85
|
+
`created: 2026-08-01T00:00:00.000Z\nlastReferenced: ''\ncontributors: []\nprojects: []\n` +
|
|
86
|
+
`tags: []\napplicablePhases: []\nsourceReferences: []\nreferencedBy: []\nexecutionResults: []\n` +
|
|
87
|
+
`consumptionMode: reference\norigin: agent\n---\n\nGhost body\n`;
|
|
88
|
+
fs.writeFileSync(path.join(dir, '.archive', 'ghost.md'), fakeEntry('GHOST-ARCHIVE'), 'utf-8');
|
|
89
|
+
fs.writeFileSync(path.join(dir, 'resolutions', 'ghost.md'), fakeEntry('GHOST-RESOLUTION'), 'utf-8');
|
|
90
|
+
|
|
91
|
+
// 生成物落回同一目录:knowledge index 的真实产物形状
|
|
92
|
+
new KnowledgeIndexGenerator(dir).regenerate();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
beforeEach(buildTree);
|
|
96
|
+
afterEach(() => fs.rmSync(dir, { recursive: true, force: true }));
|
|
97
|
+
|
|
98
|
+
it('store 顶层扫描:_index.md 与快照目录不冒充条目', () => {
|
|
99
|
+
const store = new FileKnowledgeStore({ baseDir: dir });
|
|
100
|
+
expect(store.list({ excludeArchived: false }).map(e => e.id).sort()).toEqual(['TREE-001', 'TREE-002']);
|
|
101
|
+
expect(store.readEntriesFromDisk().map(e => e.id).sort()).toEqual(['TREE-001', 'TREE-002']);
|
|
102
|
+
store.rebuildIndex();
|
|
103
|
+
expect(store.readIndex().map(e => e.id).sort()).toEqual(['TREE-001', 'TREE-002']);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('migration:生成物既不计入 total 也不计入 errors(修假阳性)', () => {
|
|
107
|
+
const result = migrateKnowledgeEntries(dir);
|
|
108
|
+
expect(result.total).toBe(2);
|
|
109
|
+
expect(result.errors).toEqual([]);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('index-generator:基建目录与 _index.md 一律不出现在索引行里', () => {
|
|
113
|
+
const lines = new KnowledgeIndexGenerator(dir).generateIndexLines();
|
|
114
|
+
const files = lines.map(l => l.split('|')[0]);
|
|
115
|
+
expect(files.sort()).toEqual(['guideline-TREE-001.md', 'pitfall-TREE-002.md']);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('三处对撞:条目集合逐 id 相同(口径漂移即红)', () => {
|
|
119
|
+
const store = new FileKnowledgeStore({ baseDir: dir });
|
|
120
|
+
const fromStore = store.list({ excludeArchived: false }).map(e => e.id).sort();
|
|
121
|
+
const fromDisk = store.readEntriesFromDisk().map(e => e.id).sort();
|
|
122
|
+
const fromIndex = new KnowledgeIndexGenerator(dir)
|
|
123
|
+
.generateIndexLines()
|
|
124
|
+
.map(l => l.split('|')[1])
|
|
125
|
+
.sort();
|
|
126
|
+
expect({ fromStore, fromDisk, fromIndex }).toEqual({
|
|
127
|
+
fromStore: ['TREE-001', 'TREE-002'],
|
|
128
|
+
fromDisk: ['TREE-001', 'TREE-002'],
|
|
129
|
+
fromIndex: ['TREE-001', 'TREE-002'],
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
});
|