@dommaker/harness 1.16.0 → 2.0.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 +16 -0
- package/dist/agents/lifecycle.d.ts.map +1 -1
- package/dist/agents/lifecycle.js +3 -6
- package/dist/agents/lifecycle.js.map +1 -1
- package/dist/cli/command-contract.d.ts +6 -9
- package/dist/cli/command-contract.d.ts.map +1 -1
- package/dist/cli/command-contract.js +6 -0
- package/dist/cli/command-contract.js.map +1 -1
- package/dist/cli/commands/acceptance.d.ts.map +1 -1
- package/dist/cli/commands/acceptance.js +8 -7
- package/dist/cli/commands/acceptance.js.map +1 -1
- package/dist/cli/commands/constraints-retire.d.ts.map +1 -1
- package/dist/cli/commands/constraints-retire.js +2 -1
- 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 +20 -10
- package/dist/cli/commands/contract.js.map +1 -1
- package/dist/cli/commands/definitions.d.ts.map +1 -1
- package/dist/cli/commands/definitions.js +13 -12
- package/dist/cli/commands/definitions.js.map +1 -1
- package/dist/cli/commands/init/ci-platform.d.ts +35 -0
- package/dist/cli/commands/init/ci-platform.d.ts.map +1 -0
- package/dist/cli/commands/init/ci-platform.js +59 -0
- package/dist/cli/commands/init/ci-platform.js.map +1 -0
- package/dist/cli/commands/init/ci-wiring.d.ts +20 -0
- package/dist/cli/commands/init/ci-wiring.d.ts.map +1 -0
- package/dist/cli/commands/init/ci-wiring.js +72 -0
- package/dist/cli/commands/init/ci-wiring.js.map +1 -0
- package/dist/cli/commands/init/git-hooks.d.ts +15 -0
- package/dist/cli/commands/init/git-hooks.d.ts.map +1 -0
- package/dist/cli/commands/init/git-hooks.js +64 -0
- package/dist/cli/commands/init/git-hooks.js.map +1 -0
- package/dist/cli/commands/init/governance.d.ts +14 -0
- package/dist/cli/commands/init/governance.d.ts.map +1 -0
- package/dist/cli/commands/init/governance.js +132 -0
- package/dist/cli/commands/init/governance.js.map +1 -0
- package/dist/cli/commands/{init.d.ts → init/index.d.ts} +13 -14
- package/dist/cli/commands/init/index.d.ts.map +1 -0
- package/dist/cli/commands/init/index.js +148 -0
- package/dist/cli/commands/init/index.js.map +1 -0
- package/dist/cli/commands/init/output-style.d.ts +19 -0
- package/dist/cli/commands/init/output-style.d.ts.map +1 -0
- package/dist/cli/commands/init/output-style.js +110 -0
- package/dist/cli/commands/init/output-style.js.map +1 -0
- package/dist/cli/commands/init/presets.d.ts +26 -0
- package/dist/cli/commands/init/presets.d.ts.map +1 -0
- package/dist/cli/commands/init/presets.js +104 -0
- package/dist/cli/commands/init/presets.js.map +1 -0
- package/dist/cli/commands/init/snippets.d.ts +18 -0
- package/dist/cli/commands/init/snippets.d.ts.map +1 -0
- package/dist/cli/commands/init/snippets.js +49 -0
- package/dist/cli/commands/init/snippets.js.map +1 -0
- package/dist/cli/commands/knowledge/audit.d.ts +30 -0
- package/dist/cli/commands/knowledge/audit.d.ts.map +1 -0
- package/dist/cli/commands/knowledge/audit.js +114 -0
- package/dist/cli/commands/knowledge/audit.js.map +1 -0
- package/dist/cli/commands/knowledge/decay.d.ts +19 -0
- package/dist/cli/commands/knowledge/decay.d.ts.map +1 -0
- package/dist/cli/commands/knowledge/decay.js +48 -0
- package/dist/cli/commands/knowledge/decay.js.map +1 -0
- package/dist/cli/commands/knowledge/health.d.ts +36 -0
- package/dist/cli/commands/knowledge/health.d.ts.map +1 -0
- package/dist/cli/commands/knowledge/health.js +172 -0
- package/dist/cli/commands/knowledge/health.js.map +1 -0
- package/dist/cli/commands/knowledge/import.d.ts +26 -0
- package/dist/cli/commands/knowledge/import.d.ts.map +1 -0
- package/dist/cli/commands/knowledge/import.js +63 -0
- package/dist/cli/commands/knowledge/import.js.map +1 -0
- package/dist/cli/commands/knowledge/index.d.ts +25 -0
- package/dist/cli/commands/knowledge/index.d.ts.map +1 -0
- package/dist/cli/commands/knowledge/index.js +84 -0
- package/dist/cli/commands/knowledge/index.js.map +1 -0
- package/dist/cli/commands/knowledge/list.d.ts +25 -0
- package/dist/cli/commands/knowledge/list.d.ts.map +1 -0
- package/dist/cli/commands/knowledge/list.js +60 -0
- package/dist/cli/commands/knowledge/list.js.map +1 -0
- package/dist/cli/commands/knowledge/migrate.d.ts +21 -0
- package/dist/cli/commands/knowledge/migrate.d.ts.map +1 -0
- package/dist/cli/commands/knowledge/migrate.js +48 -0
- package/dist/cli/commands/knowledge/migrate.js.map +1 -0
- package/dist/cli/commands/knowledge/search.d.ts +32 -0
- package/dist/cli/commands/knowledge/search.d.ts.map +1 -0
- package/dist/cli/commands/knowledge/search.js +73 -0
- package/dist/cli/commands/knowledge/search.js.map +1 -0
- package/dist/cli/commands/knowledge/shared.d.ts +14 -0
- package/dist/cli/commands/knowledge/shared.d.ts.map +1 -0
- package/dist/cli/commands/knowledge/shared.js +6 -0
- package/dist/cli/commands/knowledge/shared.js.map +1 -0
- package/dist/cli/commands/knowledge/snapshot.d.ts +18 -0
- package/dist/cli/commands/knowledge/snapshot.d.ts.map +1 -0
- package/dist/cli/commands/knowledge/snapshot.js +34 -0
- package/dist/cli/commands/knowledge/snapshot.js.map +1 -0
- package/dist/cli/commands/knowledge/stats.d.ts +26 -0
- package/dist/cli/commands/knowledge/stats.d.ts.map +1 -0
- package/dist/cli/commands/knowledge/stats.js +132 -0
- package/dist/cli/commands/knowledge/stats.js.map +1 -0
- package/dist/cli/commands/knowledge/sync-rag.d.ts +19 -0
- package/dist/cli/commands/knowledge/sync-rag.d.ts.map +1 -0
- package/dist/cli/commands/knowledge/sync-rag.js +77 -0
- package/dist/cli/commands/knowledge/sync-rag.js.map +1 -0
- package/dist/cli/commands/knowledge-view.d.ts +2 -1
- package/dist/cli/commands/knowledge-view.d.ts.map +1 -1
- package/dist/cli/commands/knowledge-view.js +2 -2
- package/dist/cli/commands/knowledge-view.js.map +1 -1
- package/dist/cli/commands/passes-gate.d.ts.map +1 -1
- package/dist/cli/commands/passes-gate.js +12 -2
- package/dist/cli/commands/passes-gate.js.map +1 -1
- package/dist/cli/commands/performance.js.map +1 -1
- package/dist/cli/commands/release.d.ts.map +1 -1
- package/dist/cli/commands/release.js +13 -41
- package/dist/cli/commands/release.js.map +1 -1
- package/dist/cli/commands/review.d.ts.map +1 -1
- package/dist/cli/commands/review.js +3 -2
- package/dist/cli/commands/review.js.map +1 -1
- package/dist/cli/commands/security.d.ts.map +1 -1
- package/dist/cli/commands/security.js +7 -8
- package/dist/cli/commands/security.js.map +1 -1
- package/dist/cli/commands/spec-baseline-check.d.ts.map +1 -1
- package/dist/cli/commands/spec-baseline-check.js +6 -5
- package/dist/cli/commands/spec-baseline-check.js.map +1 -1
- package/dist/cli/commands/status.js +2 -2
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/cli/commands/sync-docs/agents-syncer.js +31 -55
- package/dist/cli/commands/sync-docs/agents-syncer.js.map +1 -1
- package/dist/cli/commands/sync-docs/capabilities-syncer.d.ts.map +1 -1
- package/dist/cli/commands/sync-docs/capabilities-syncer.js +18 -12
- package/dist/cli/commands/sync-docs/capabilities-syncer.js.map +1 -1
- package/dist/cli/commands/sync-docs/compact.d.ts +9 -0
- package/dist/cli/commands/sync-docs/compact.d.ts.map +1 -0
- package/dist/cli/commands/sync-docs/compact.js +73 -0
- package/dist/cli/commands/sync-docs/compact.js.map +1 -0
- package/dist/cli/commands/sync-docs/context-syncer.d.ts.map +1 -1
- package/dist/cli/commands/sync-docs/context-syncer.js +17 -36
- package/dist/cli/commands/sync-docs/context-syncer.js.map +1 -1
- package/dist/cli/commands/sync-docs/gate.d.ts +27 -0
- package/dist/cli/commands/sync-docs/gate.d.ts.map +1 -0
- package/dist/cli/commands/sync-docs/gate.js +72 -0
- package/dist/cli/commands/sync-docs/gate.js.map +1 -0
- package/dist/cli/commands/sync-docs/index.d.ts +13 -27
- package/dist/cli/commands/sync-docs/index.d.ts.map +1 -1
- package/dist/cli/commands/sync-docs/index.js +19 -529
- package/dist/cli/commands/sync-docs/index.js.map +1 -1
- package/dist/cli/commands/sync-docs/main-flow.d.ts +37 -0
- package/dist/cli/commands/sync-docs/main-flow.d.ts.map +1 -0
- package/dist/cli/commands/sync-docs/main-flow.js +485 -0
- package/dist/cli/commands/sync-docs/main-flow.js.map +1 -0
- package/dist/cli/commands/sync-docs/project-reader.d.ts +1 -1
- package/dist/cli/commands/sync-docs/project-reader.d.ts.map +1 -1
- package/dist/cli/commands/sync-docs/project-reader.js +16 -25
- package/dist/cli/commands/sync-docs/project-reader.js.map +1 -1
- package/dist/cli/gate-command.d.ts +1 -1
- package/dist/cli/gate-command.d.ts.map +1 -1
- package/dist/context/index.d.ts +1 -3
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +2 -5
- package/dist/context/index.js.map +1 -1
- package/dist/context/session-manager.d.ts +2 -2
- package/dist/context/session-manager.d.ts.map +1 -1
- package/dist/context/session-manager.js +31 -52
- package/dist/context/session-manager.js.map +1 -1
- package/dist/context/types.d.ts +2 -2
- package/dist/context/types.d.ts.map +1 -1
- package/dist/core/constraint-lifecycle.d.ts +1 -1
- package/dist/core/constraint-lifecycle.d.ts.map +1 -1
- package/dist/core/constraint-lifecycle.js +1 -1
- package/dist/core/constraint-lifecycle.js.map +1 -1
- package/dist/core/constraints/capabilities-parser.d.ts +2 -1
- package/dist/core/constraints/capabilities-parser.d.ts.map +1 -1
- package/dist/core/constraints/capabilities-parser.js +4 -6
- package/dist/core/constraints/capabilities-parser.js.map +1 -1
- package/dist/core/constraints/checkers/templated/exec.d.ts.map +1 -1
- package/dist/core/constraints/checkers/templated/exec.js +1 -0
- package/dist/core/constraints/checkers/templated/exec.js.map +1 -1
- package/dist/core/constraints/checkers/templated/file-exists.js +1 -1
- package/dist/core/constraints/checkers/templated/file-exists.js.map +1 -1
- package/dist/core/constraints/context-builder.d.ts.map +1 -1
- package/dist/core/constraints/context-builder.js +13 -34
- package/dist/core/constraints/context-builder.js.map +1 -1
- package/dist/core/constraints/definitions/guidelines.d.ts.map +1 -1
- package/dist/core/constraints/definitions/guidelines.js +18 -0
- package/dist/core/constraints/definitions/guidelines.js.map +1 -1
- package/dist/core/constraints/definitions/iron-laws.d.ts.map +1 -1
- package/dist/core/constraints/definitions/iron-laws.js +0 -16
- package/dist/core/constraints/definitions/iron-laws.js.map +1 -1
- package/dist/core/constraints/doc-freshness/runner.d.ts.map +1 -1
- package/dist/core/constraints/doc-freshness/runner.js +192 -223
- package/dist/core/constraints/doc-freshness/runner.js.map +1 -1
- package/dist/core/constraints/git-evidence.d.ts.map +1 -1
- package/dist/core/constraints/git-evidence.js +2 -0
- package/dist/core/constraints/git-evidence.js.map +1 -1
- package/dist/core/constraints/injection-writer.d.ts +1 -0
- package/dist/core/constraints/injection-writer.d.ts.map +1 -1
- package/dist/core/constraints/injection-writer.js +3 -6
- package/dist/core/constraints/injection-writer.js.map +1 -1
- package/dist/core/project-config-loader.d.ts +3 -1
- package/dist/core/project-config-loader.d.ts.map +1 -1
- package/dist/core/project-config-loader.js +6 -6
- package/dist/core/project-config-loader.js.map +1 -1
- package/dist/core/spec/validator.d.ts +1 -1
- package/dist/core/spec/validator.d.ts.map +1 -1
- package/dist/core/spec/validator.js +41 -36
- package/dist/core/spec/validator.js.map +1 -1
- package/dist/core/validators/check-handlers/command.d.ts.map +1 -1
- package/dist/core/validators/check-handlers/command.js +7 -4
- package/dist/core/validators/check-handlers/command.js.map +1 -1
- package/dist/core/validators/check-handlers/http.d.ts.map +1 -1
- package/dist/core/validators/check-handlers/http.js +6 -4
- package/dist/core/validators/check-handlers/http.js.map +1 -1
- package/dist/core/validators/check-handlers/output.d.ts +1 -1
- package/dist/core/validators/check-handlers/output.d.ts.map +1 -1
- package/dist/core/validators/check-handlers/output.js +2 -1
- package/dist/core/validators/check-handlers/output.js.map +1 -1
- package/dist/core/validators/passes-gate.d.ts +2 -1
- package/dist/core/validators/passes-gate.d.ts.map +1 -1
- package/dist/core/validators/passes-gate.js +25 -30
- package/dist/core/validators/passes-gate.js.map +1 -1
- package/dist/gates/acceptance.d.ts +37 -18
- package/dist/gates/acceptance.d.ts.map +1 -1
- package/dist/gates/acceptance.js +129 -97
- package/dist/gates/acceptance.js.map +1 -1
- package/dist/gates/command.d.ts +1 -1
- package/dist/gates/contract.d.ts +11 -2
- package/dist/gates/contract.d.ts.map +1 -1
- package/dist/gates/contract.js +57 -62
- package/dist/gates/contract.js.map +1 -1
- package/dist/gates/performance.d.ts +1 -1
- package/dist/gates/performance.d.ts.map +1 -1
- package/dist/gates/performance.js +18 -8
- package/dist/gates/performance.js.map +1 -1
- package/dist/gates/registry.d.ts.map +1 -1
- package/dist/gates/registry.js +6 -2
- package/dist/gates/registry.js.map +1 -1
- package/dist/gates/review.d.ts.map +1 -1
- package/dist/gates/review.js +16 -2
- package/dist/gates/review.js.map +1 -1
- package/dist/gates/security.d.ts +5 -1
- package/dist/gates/security.d.ts.map +1 -1
- package/dist/gates/security.js +57 -63
- package/dist/gates/security.js.map +1 -1
- package/dist/gates/types.d.ts +11 -78
- package/dist/gates/types.d.ts.map +1 -1
- package/dist/gates/types.js +5 -1
- package/dist/gates/types.js.map +1 -1
- package/dist/index.d.ts +9 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -3
- package/dist/index.js.map +1 -1
- package/dist/knowledge/audit-dimensions.d.ts +45 -0
- package/dist/knowledge/audit-dimensions.d.ts.map +1 -0
- package/dist/knowledge/audit-dimensions.js +144 -0
- package/dist/knowledge/audit-dimensions.js.map +1 -0
- package/dist/knowledge/audit-rules.d.ts +41 -0
- package/dist/knowledge/audit-rules.d.ts.map +1 -0
- package/dist/knowledge/audit-rules.js +269 -0
- package/dist/knowledge/audit-rules.js.map +1 -0
- package/dist/knowledge/audit-scoring.d.ts +6 -60
- package/dist/knowledge/audit-scoring.d.ts.map +1 -1
- package/dist/knowledge/audit-scoring.js +8 -391
- package/dist/knowledge/audit-scoring.js.map +1 -1
- package/dist/knowledge/audit.d.ts +6 -3
- package/dist/knowledge/audit.d.ts.map +1 -1
- package/dist/knowledge/audit.js +9 -6
- package/dist/knowledge/audit.js.map +1 -1
- package/dist/knowledge/import.d.ts.map +1 -1
- package/dist/knowledge/import.js +5 -4
- package/dist/knowledge/import.js.map +1 -1
- package/dist/knowledge/index-generator.d.ts +2 -0
- package/dist/knowledge/index-generator.d.ts.map +1 -1
- package/dist/knowledge/index-generator.js +43 -50
- package/dist/knowledge/index-generator.js.map +1 -1
- package/dist/knowledge/index.d.ts +4 -2
- package/dist/knowledge/index.d.ts.map +1 -1
- package/dist/knowledge/index.js +2 -1
- package/dist/knowledge/index.js.map +1 -1
- package/dist/knowledge/ingest.d.ts +21 -5
- package/dist/knowledge/ingest.d.ts.map +1 -1
- package/dist/knowledge/ingest.js +12 -9
- package/dist/knowledge/ingest.js.map +1 -1
- package/dist/knowledge/lifecycle.d.ts.map +1 -1
- package/dist/knowledge/lifecycle.js +17 -22
- package/dist/knowledge/lifecycle.js.map +1 -1
- package/dist/knowledge/query.d.ts +1 -1
- package/dist/knowledge/query.d.ts.map +1 -1
- package/dist/knowledge/query.js +7 -7
- package/dist/knowledge/query.js.map +1 -1
- package/dist/knowledge/reference-tracker.d.ts.map +1 -1
- package/dist/knowledge/reference-tracker.js +14 -17
- package/dist/knowledge/reference-tracker.js.map +1 -1
- package/dist/knowledge/store.d.ts.map +1 -1
- package/dist/knowledge/store.js +17 -36
- package/dist/knowledge/store.js.map +1 -1
- package/dist/monitoring/trace-analyzer.d.ts +2 -2
- package/dist/monitoring/trace-analyzer.d.ts.map +1 -1
- package/dist/monitoring/trace-analyzer.js +9 -7
- package/dist/monitoring/trace-analyzer.js.map +1 -1
- package/dist/monitoring/traces.d.ts.map +1 -1
- package/dist/monitoring/traces.js +6 -4
- package/dist/monitoring/traces.js.map +1 -1
- package/dist/pretool-use-hook.d.ts +1 -1
- package/dist/pretool-use-hook.d.ts.map +1 -1
- package/dist/pretool-use-hook.js +12 -19
- package/dist/pretool-use-hook.js.map +1 -1
- package/dist/release/integrity.d.ts.map +1 -1
- package/dist/release/integrity.js +8 -8
- package/dist/release/integrity.js.map +1 -1
- package/dist/sdd/index-generator.d.ts.map +1 -1
- package/dist/sdd/index-generator.js +4 -0
- package/dist/sdd/index-generator.js.map +1 -1
- package/dist/types/checkpoint.d.ts +8 -8
- package/dist/types/checkpoint.d.ts.map +1 -1
- package/dist/types/command-io.d.ts +19 -0
- package/dist/types/command-io.d.ts.map +1 -0
- package/dist/types/command-io.js +3 -0
- package/dist/types/command-io.js.map +1 -0
- package/dist/types/gate.d.ts +72 -0
- package/dist/types/gate.d.ts.map +1 -0
- package/dist/types/gate.js +13 -0
- package/dist/types/gate.js.map +1 -0
- package/dist/utils/attempt.d.ts +22 -0
- package/dist/utils/attempt.d.ts.map +1 -0
- package/dist/utils/attempt.js +40 -0
- package/dist/utils/attempt.js.map +1 -0
- package/dist/utils/detect-source-roots.d.ts.map +1 -1
- package/dist/utils/detect-source-roots.js +42 -51
- package/dist/utils/detect-source-roots.js.map +1 -1
- package/dist/utils/file-walk.d.ts +2 -1
- package/dist/utils/file-walk.d.ts.map +1 -1
- package/dist/utils/file-walk.js +3 -8
- package/dist/utils/file-walk.js.map +1 -1
- package/dist/utils/package-json.d.ts +49 -0
- package/dist/utils/package-json.d.ts.map +1 -0
- package/dist/utils/package-json.js +78 -0
- package/dist/utils/package-json.js.map +1 -0
- package/dist/utils/package-version.d.ts +5 -2
- package/dist/utils/package-version.d.ts.map +1 -1
- package/dist/utils/package-version.js +8 -11
- package/dist/utils/package-version.js.map +1 -1
- package/package.json +1 -6
- package/src/CONTEXT.md +5 -4
- package/src/__tests__/acceptance-gate.test.ts +23 -51
- package/src/__tests__/contract-gate.test.ts +1 -1
- package/src/__tests__/install-precommit-hook.test.ts +61 -0
- package/src/__tests__/iron-laws.test.ts +5 -5
- package/src/__tests__/layering.test.ts +1 -1
- package/src/__tests__/public-exports.test.ts +1 -1
- package/src/__tests__/public-type-surface.test.ts +9 -19
- package/src/__tests__/public-value-surface.test.ts +9 -17
- package/src/__tests__/skip-semantics.test.ts +5 -4
- package/src/agents/lifecycle.ts +3 -5
- package/src/cli/__tests__/command-contract.test.ts +18 -0
- package/src/cli/command-contract.ts +8 -5
- package/src/cli/commands/CONTEXT.md +10 -10
- package/src/cli/commands/__tests__/check.test.ts +1 -1
- package/src/cli/commands/__tests__/constraints-retire.test.ts +5 -3
- package/src/cli/commands/__tests__/init-governance-io.test.ts +7 -2
- package/src/cli/commands/__tests__/init.test.ts +1 -1
- package/src/cli/commands/__tests__/knowledge-audit-threshold.test.ts +14 -8
- package/src/cli/commands/__tests__/knowledge-flywheel-consistency.test.ts +2 -1
- package/src/cli/commands/__tests__/knowledge-view.test.ts +28 -18
- package/src/cli/commands/__tests__/knowledge.test.ts +6 -2
- package/src/cli/commands/__tests__/numeric-flag-assembly.test.ts +1 -1
- package/src/cli/commands/__tests__/passes-gate.test.ts +100 -24
- package/src/cli/commands/__tests__/project-path-anchoring.test.ts +3 -6
- package/src/cli/commands/__tests__/registry.test.ts +3 -2
- package/src/cli/commands/__tests__/release.test.ts +24 -2
- package/src/cli/commands/__tests__/report-false-green.test.ts +10 -6
- package/src/cli/commands/acceptance.ts +10 -9
- package/src/cli/commands/command.ts +1 -1
- package/src/cli/commands/constraints-retire.ts +3 -2
- package/src/cli/commands/contract.ts +29 -14
- package/src/cli/commands/definitions.ts +13 -12
- package/src/cli/commands/init/ci-platform.ts +66 -0
- package/src/cli/commands/init/ci-wiring.ts +48 -0
- package/src/cli/commands/init/git-hooks.ts +31 -0
- package/src/cli/commands/init/governance.ts +127 -0
- package/src/cli/commands/init/index.ts +156 -0
- package/src/cli/commands/init/output-style.ts +82 -0
- package/src/cli/commands/init/presets.ts +105 -0
- package/src/cli/commands/init/snippets.ts +57 -0
- package/src/cli/commands/knowledge/audit.ts +155 -0
- package/src/cli/commands/knowledge/decay.ts +57 -0
- package/src/cli/commands/knowledge/health.ts +176 -0
- package/src/cli/commands/knowledge/import.ts +82 -0
- package/src/cli/commands/knowledge/index.ts +60 -0
- package/src/cli/commands/knowledge/list.ts +73 -0
- package/src/cli/commands/knowledge/migrate.ts +61 -0
- package/src/cli/commands/knowledge/search.ts +93 -0
- package/src/cli/commands/knowledge/shared.ts +13 -0
- package/src/cli/commands/knowledge/snapshot.ts +38 -0
- package/src/cli/commands/knowledge/stats.ts +112 -0
- package/src/cli/commands/knowledge/sync-rag.ts +48 -0
- package/src/cli/commands/knowledge-view.ts +3 -2
- package/src/cli/commands/passes-gate.ts +14 -2
- package/src/cli/commands/performance.ts +2 -2
- package/src/cli/commands/release.ts +14 -9
- package/src/cli/commands/review.ts +5 -4
- package/src/cli/commands/security.ts +10 -11
- package/src/cli/commands/spec-baseline-check.ts +6 -7
- package/src/cli/commands/status.ts +2 -2
- package/src/cli/commands/sync-docs/agents-syncer.ts +28 -47
- package/src/cli/commands/sync-docs/capabilities-syncer.ts +18 -11
- package/src/cli/commands/sync-docs/compact.ts +35 -0
- package/src/cli/commands/sync-docs/context-syncer.ts +15 -31
- package/src/cli/commands/sync-docs/gate.ts +78 -0
- package/src/cli/commands/sync-docs/index.ts +21 -585
- package/src/cli/commands/sync-docs/main-flow.ts +549 -0
- package/src/cli/commands/sync-docs/project-reader.ts +21 -24
- package/src/cli/gate-command.ts +1 -1
- package/src/context/CONTEXT.md +4 -4
- package/src/context/__tests__/session-manager.test.ts +18 -0
- package/src/context/index.ts +1 -5
- package/src/context/session-manager.ts +34 -50
- package/src/context/types.ts +2 -2
- package/src/core/CONTEXT.md +2 -2
- package/src/core/constraint-lifecycle.ts +2 -2
- package/src/core/constraints/capabilities-parser.ts +4 -6
- package/src/core/constraints/checkers/templated/exec.ts +1 -0
- package/src/core/constraints/checkers/templated/file-exists.ts +1 -1
- package/src/core/constraints/context-builder.ts +11 -28
- package/src/core/constraints/definitions/guidelines.ts +19 -0
- package/src/core/constraints/definitions/iron-laws.ts +0 -17
- package/src/core/constraints/doc-freshness/runner.ts +220 -244
- package/src/core/constraints/git-evidence.ts +2 -0
- package/src/core/constraints/injection-writer.ts +3 -6
- package/src/core/project-config-loader.ts +6 -5
- package/src/core/spec/__tests__/validator.test.ts +65 -13
- package/src/core/spec/validator.ts +50 -40
- package/src/core/validators/__tests__/passes-gate-counts.test.ts +52 -0
- package/src/core/validators/check-handlers/command.ts +9 -6
- package/src/core/validators/check-handlers/http.ts +8 -6
- package/src/core/validators/check-handlers/output.ts +7 -6
- package/src/core/validators/passes-gate.ts +31 -32
- package/src/gates/CONTEXT.md +7 -6
- package/src/gates/__tests__/acceptance-types-single-source.test.ts +16 -14
- package/src/gates/__tests__/acceptance.test.ts +69 -94
- package/src/gates/__tests__/command-single-predicate.test.ts +1 -1
- package/src/gates/__tests__/command.test.ts +23 -12
- package/src/gates/__tests__/gate-interface.test.ts +2 -5
- package/src/gates/__tests__/performance.test.ts +3 -3
- package/src/gates/__tests__/security.test.ts +7 -19
- package/src/gates/acceptance.ts +176 -131
- package/src/gates/command.ts +1 -1
- package/src/gates/contract.ts +86 -79
- package/src/gates/performance.ts +35 -19
- package/src/gates/registry.ts +6 -3
- package/src/gates/review.ts +38 -10
- package/src/gates/security.ts +94 -81
- package/src/gates/types.ts +22 -84
- package/src/index.ts +8 -4
- package/src/knowledge/CONTEXT.md +9 -7
- package/src/knowledge/__tests__/audit-labels.test.ts +3 -3
- package/src/knowledge/__tests__/audit-scoring.test.ts +9 -7
- package/src/knowledge/__tests__/ingest.test.ts +17 -17
- package/src/knowledge/__tests__/store.test.ts +4 -6
- package/src/knowledge/audit-dimensions.ts +190 -0
- package/src/knowledge/audit-rules.ts +335 -0
- package/src/knowledge/audit-scoring.ts +7 -495
- package/src/knowledge/audit.ts +9 -11
- package/src/knowledge/import.ts +7 -6
- package/src/knowledge/index-generator.ts +48 -53
- package/src/knowledge/index.ts +4 -2
- package/src/knowledge/ingest.ts +27 -12
- package/src/knowledge/lifecycle.ts +17 -19
- package/src/knowledge/query.ts +7 -6
- package/src/knowledge/reference-tracker.ts +14 -16
- package/src/knowledge/store.ts +17 -32
- package/src/monitoring/trace-analyzer.ts +12 -9
- package/src/monitoring/traces.ts +8 -6
- package/src/pretool-use-hook.ts +26 -21
- package/src/release/CONTEXT.md +1 -1
- package/src/release/__tests__/integrity.test.ts +0 -2
- package/src/release/integrity.ts +8 -9
- package/src/sdd/index-generator.ts +4 -0
- package/src/types/checkpoint.ts +8 -8
- package/src/types/command-io.ts +14 -0
- package/src/types/gate.ts +77 -0
- package/src/utils/__tests__/attempt.test.ts +94 -0
- package/src/utils/__tests__/package-json.test.ts +58 -0
- package/src/utils/__tests__/package-version.test.ts +21 -2
- package/src/utils/attempt.ts +35 -0
- package/src/utils/detect-source-roots.ts +38 -44
- package/src/utils/file-walk.ts +3 -7
- package/src/utils/package-json.ts +61 -0
- package/src/utils/package-version.ts +8 -10
- package/dist/cli/commands/init.d.ts.map +0 -1
- package/dist/cli/commands/init.js +0 -502
- package/dist/cli/commands/init.js.map +0 -1
- package/dist/cli/commands/knowledge.d.ts +0 -169
- package/dist/cli/commands/knowledge.d.ts.map +0 -1
- package/dist/cli/commands/knowledge.js +0 -700
- package/dist/cli/commands/knowledge.js.map +0 -1
- package/dist/context/knowledge-injector.d.ts +0 -51
- package/dist/context/knowledge-injector.d.ts.map +0 -1
- package/dist/context/knowledge-injector.js +0 -128
- package/dist/context/knowledge-injector.js.map +0 -1
- package/dist/gates/index.d.ts +0 -10
- package/dist/gates/index.d.ts.map +0 -1
- package/dist/gates/index.js +0 -11
- package/dist/gates/index.js.map +0 -1
- package/src/cli/commands/init.ts +0 -590
- package/src/cli/commands/knowledge.ts +0 -820
- package/src/context/__tests__/knowledge-injector.test.ts +0 -197
- package/src/context/knowledge-injector.ts +0 -174
- package/src/gates/index.ts +0 -11
|
@@ -68,9 +68,11 @@ export class KnowledgeIndexGenerator {
|
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
70
|
* 扫描目录,返回索引数据行(无 header)
|
|
71
|
+
*
|
|
72
|
+
* baseDir 不存在 = 空知识库(领域语义,返回空);扫到一半目录不可读 = 真故障,抛出。
|
|
71
73
|
*/
|
|
72
74
|
generateIndexLines(): string[] {
|
|
73
|
-
const files = this.scanFiles(this.baseDir);
|
|
75
|
+
const files = fs.existsSync(this.baseDir) ? this.scanFiles(this.baseDir) : [];
|
|
74
76
|
const entries: IndexEntry[] = [];
|
|
75
77
|
|
|
76
78
|
for (const filePath of files) {
|
|
@@ -97,12 +99,8 @@ export class KnowledgeIndexGenerator {
|
|
|
97
99
|
private scanFiles(dir: string, relative: string = ''): string[] {
|
|
98
100
|
const results: string[] = [];
|
|
99
101
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
items = fs.readdirSync(dir, { withFileTypes: true });
|
|
103
|
-
} catch {
|
|
104
|
-
return results;
|
|
105
|
-
}
|
|
102
|
+
// fail-fast:目录不可读直接抛,不返回半截清单
|
|
103
|
+
const items = fs.readdirSync(dir, { withFileTypes: true });
|
|
106
104
|
|
|
107
105
|
for (const item of items) {
|
|
108
106
|
const name = item.name;
|
|
@@ -122,59 +120,56 @@ export class KnowledgeIndexGenerator {
|
|
|
122
120
|
}
|
|
123
121
|
|
|
124
122
|
private parseFile(filePath: string): IndexEntry | null {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
// 检测 skill schema(name/description 而非 id/type)
|
|
145
|
-
const type = meta.type
|
|
146
|
-
? String(meta.type)
|
|
147
|
-
: meta.name
|
|
148
|
-
? 'skill'
|
|
149
|
-
: this.inferType(filename);
|
|
150
|
-
|
|
151
|
-
return {
|
|
152
|
-
filename,
|
|
153
|
-
id: String(meta.id ?? meta.name ?? path.basename(filePath, '.md')),
|
|
154
|
-
type,
|
|
155
|
-
title: String(meta.title ?? meta.description ?? ''),
|
|
156
|
-
maturity: String(meta.maturity ?? 'unknown'),
|
|
157
|
-
tags: Array.isArray(meta.tags) ? (meta.tags as unknown[]).map(String) : [],
|
|
158
|
-
headings,
|
|
159
|
-
};
|
|
160
|
-
}
|
|
123
|
+
// fail-fast:读失败(IO)直接抛;frontmatter 损坏由下方 splitFrontmatter 分支显式上报
|
|
124
|
+
const raw = fs.readFileSync(filePath, 'utf-8');
|
|
125
|
+
const filename = path.relative(this.baseDir, filePath);
|
|
126
|
+
|
|
127
|
+
// 跳过 ghost 文件(文件名为 .md)
|
|
128
|
+
if (path.basename(filename) === '.md') return null;
|
|
129
|
+
|
|
130
|
+
// 尝试解析 YAML frontmatter(语法与失败走法正本:utils/frontmatter)
|
|
131
|
+
const fm = splitFrontmatter(raw);
|
|
132
|
+
if (fm.state === 'malformed') {
|
|
133
|
+
// 统一口径(harness#89):损坏必须显式上报,恢复动作是 best-effort 索引原文
|
|
134
|
+
console.error(
|
|
135
|
+
`[harness] 知识索引 frontmatter ${fm.reason}(${fm.detail}),按无 frontmatter 处理 ${filename}`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
if (fm.state === 'ok') {
|
|
139
|
+
const meta = fm.meta;
|
|
140
|
+
const headings = this.extractHeadings(fm.body);
|
|
161
141
|
|
|
162
|
-
//
|
|
163
|
-
const
|
|
164
|
-
|
|
142
|
+
// 检测 skill schema(name/description 而非 id/type)
|
|
143
|
+
const type = meta.type
|
|
144
|
+
? String(meta.type)
|
|
145
|
+
: meta.name
|
|
146
|
+
? 'skill'
|
|
147
|
+
: this.inferType(filename);
|
|
165
148
|
|
|
166
149
|
return {
|
|
167
150
|
filename,
|
|
168
|
-
id: path.basename(filePath, '.md'),
|
|
169
|
-
type
|
|
170
|
-
title:
|
|
171
|
-
maturity: 'unknown',
|
|
172
|
-
tags: [],
|
|
151
|
+
id: String(meta.id ?? meta.name ?? path.basename(filePath, '.md')),
|
|
152
|
+
type,
|
|
153
|
+
title: String(meta.title ?? meta.description ?? ''),
|
|
154
|
+
maturity: String(meta.maturity ?? 'unknown'),
|
|
155
|
+
tags: Array.isArray(meta.tags) ? (meta.tags as unknown[]).map(String) : [],
|
|
173
156
|
headings,
|
|
174
157
|
};
|
|
175
|
-
} catch {
|
|
176
|
-
return null;
|
|
177
158
|
}
|
|
159
|
+
|
|
160
|
+
// absent(含空 meta)或已上报的 malformed — best effort
|
|
161
|
+
const headings = this.extractHeadings(raw);
|
|
162
|
+
const h1Match = raw.match(/^#\s+(.+)$/m);
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
filename,
|
|
166
|
+
id: path.basename(filePath, '.md'),
|
|
167
|
+
type: this.inferType(filename),
|
|
168
|
+
title: h1Match ? h1Match[1].trim() : '',
|
|
169
|
+
maturity: 'unknown',
|
|
170
|
+
tags: [],
|
|
171
|
+
headings,
|
|
172
|
+
};
|
|
178
173
|
}
|
|
179
174
|
|
|
180
175
|
/**
|
package/src/knowledge/index.ts
CHANGED
|
@@ -32,7 +32,7 @@ export type {
|
|
|
32
32
|
} from './types';
|
|
33
33
|
export type { KnowledgeStore } from './store';
|
|
34
34
|
export { FileKnowledgeStore } from './store';
|
|
35
|
-
export { KnowledgeQuery } from './query';
|
|
35
|
+
export { KnowledgeQuery, EXTERNAL_SOURCE_MARKER } from './query';
|
|
36
36
|
export { estimateTokens } from './token-estimate';
|
|
37
37
|
export { KnowledgeLifecycle } from './lifecycle';
|
|
38
38
|
export type { ConsumptionEvent } from './lifecycle';
|
|
@@ -42,4 +42,6 @@ export { KnowledgeLinter } from './lint';
|
|
|
42
42
|
export { ColdStartImporter } from './import';
|
|
43
43
|
export { KnowledgeHealthScorer } from './doctor';
|
|
44
44
|
export { KnowledgeAudit } from './audit';
|
|
45
|
-
export type { AuditRuleName, AuditAction, AuditIssue
|
|
45
|
+
export type { AuditRuleName, AuditAction, AuditIssue } from './audit-rules';
|
|
46
|
+
export type { AuditOptions } from './audit-scoring';
|
|
47
|
+
export type { AuditReport } from './audit-dimensions';
|
package/src/knowledge/ingest.ts
CHANGED
|
@@ -18,6 +18,18 @@ import { splitFrontmatter } from '../utils/frontmatter';
|
|
|
18
18
|
const MAX_SOURCE_REFS = 20;
|
|
19
19
|
const MAX_EXTERNAL_CONTENT_LENGTH = 5000;
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* `ingestEntry` / `ingestBatch` / `ingestExternal` 的返回(判别联合):
|
|
23
|
+
* - `accepted`:已落盘(新建或去重合并),`entry` 为最终形态
|
|
24
|
+
* - `rejected`:审计质量门拒收、未落盘,`reasons` 为逐条拒绝理由
|
|
25
|
+
*
|
|
26
|
+
* 原实现把 `__rejected` / `__rejectReasons` 经 `as any` 偷挂在返回条目上——
|
|
27
|
+
* 类型面看不见、全仓零消费点(Phase 4 any 清零时核实),改为显式判别联合。
|
|
28
|
+
*/
|
|
29
|
+
export type IngestResult =
|
|
30
|
+
| { status: 'accepted'; entry: KnowledgeEntry }
|
|
31
|
+
| { status: 'rejected'; entry: KnowledgeEntry; reasons: string[] };
|
|
32
|
+
|
|
21
33
|
/** Known prompt injection patterns to strip from external content */
|
|
22
34
|
const INJECTION_PATTERNS = [
|
|
23
35
|
/ignore\s+(all\s+)?previous\s+instructions/gi,
|
|
@@ -62,12 +74,12 @@ export class KnowledgeIngest {
|
|
|
62
74
|
/**
|
|
63
75
|
* Ingest a single knowledge entry.
|
|
64
76
|
* Auto-fills id, created, maturity, and other defaults.
|
|
65
|
-
* Returns
|
|
77
|
+
* Returns a discriminated result: accepted = saved (new or merged), rejected = audit gate refusal.
|
|
66
78
|
*/
|
|
67
79
|
ingestEntry(
|
|
68
80
|
partial: Partial<KnowledgeEntry>,
|
|
69
81
|
options: IngestOptions,
|
|
70
|
-
):
|
|
82
|
+
): IngestResult {
|
|
71
83
|
const entry = this.buildEntry(partial, options);
|
|
72
84
|
|
|
73
85
|
// Quality gate: audit before saving
|
|
@@ -75,10 +87,8 @@ export class KnowledgeIngest {
|
|
|
75
87
|
let issues = audit.validate(entry);
|
|
76
88
|
const critical = issues.filter(i => i.action === 'reject');
|
|
77
89
|
if (critical.length > 0) {
|
|
78
|
-
// Reject: return
|
|
79
|
-
|
|
80
|
-
(entry as any).__rejectReasons = critical.map(i => i.detail);
|
|
81
|
-
return entry;
|
|
90
|
+
// Reject: return without saving; caller branches on status / reasons
|
|
91
|
+
return { status: 'rejected', entry, reasons: critical.map(i => i.detail) };
|
|
82
92
|
}
|
|
83
93
|
|
|
84
94
|
// If caller explicitly set maturity, skip demote actions from audit.
|
|
@@ -91,7 +101,7 @@ export class KnowledgeIngest {
|
|
|
91
101
|
const existing = this.findDuplicate(entry.title, entry.content, entry.type);
|
|
92
102
|
if (existing) {
|
|
93
103
|
// Merge: update existing entry with new content and metadata
|
|
94
|
-
return this.mergeEntries(existing, entry, options);
|
|
104
|
+
return { status: 'accepted', entry: this.mergeEntries(existing, entry, options) };
|
|
95
105
|
}
|
|
96
106
|
|
|
97
107
|
this.store.save(entry);
|
|
@@ -113,17 +123,17 @@ export class KnowledgeIngest {
|
|
|
113
123
|
}
|
|
114
124
|
}
|
|
115
125
|
|
|
116
|
-
return entry;
|
|
126
|
+
return { status: 'accepted', entry };
|
|
117
127
|
}
|
|
118
128
|
|
|
119
129
|
/**
|
|
120
130
|
* Ingest multiple entries in batch.
|
|
121
|
-
* Returns
|
|
131
|
+
* Returns one result per input (accepted/rejected).
|
|
122
132
|
*/
|
|
123
133
|
ingestBatch(
|
|
124
134
|
partials: Partial<KnowledgeEntry>[],
|
|
125
135
|
options: IngestOptions,
|
|
126
|
-
):
|
|
136
|
+
): IngestResult[] {
|
|
127
137
|
return partials.map(p => this.ingestEntry(p, options));
|
|
128
138
|
}
|
|
129
139
|
|
|
@@ -136,7 +146,7 @@ export class KnowledgeIngest {
|
|
|
136
146
|
ingestExternal(
|
|
137
147
|
partial: Partial<KnowledgeEntry>,
|
|
138
148
|
options: Omit<IngestOptions, 'origin'> & { fullContentPath?: string },
|
|
139
|
-
):
|
|
149
|
+
): IngestResult {
|
|
140
150
|
const sanitizedContent = sanitizeExternalContent(partial.content || '');
|
|
141
151
|
return this.ingestEntry(
|
|
142
152
|
{ ...partial, content: sanitizedContent },
|
|
@@ -282,7 +292,12 @@ export class KnowledgeIngest {
|
|
|
282
292
|
tags: [...new Set([...existing.tags, ...incoming.tags])],
|
|
283
293
|
sourceReferences: [...existing.sourceReferences, ...incoming.sourceReferences].slice(-MAX_SOURCE_REFS),
|
|
284
294
|
};
|
|
285
|
-
|
|
295
|
+
// fail-fast:刚经 readEntriesFromDisk 读到的条目 update 不到 = 并发删除/索引漂移,不静默吞
|
|
296
|
+
const updated = this.store.update(existing.id, merged);
|
|
297
|
+
if (!updated) {
|
|
298
|
+
throw new Error(`mergeEntries: 条目 ${existing.id} 落盘更新失败(读得到写不回)`);
|
|
299
|
+
}
|
|
300
|
+
return updated;
|
|
286
301
|
}
|
|
287
302
|
|
|
288
303
|
private defaultSourceRef(source: string): SourceRef[] {
|
|
@@ -14,6 +14,7 @@ import type {
|
|
|
14
14
|
} from './types';
|
|
15
15
|
import { DEFAULT_DECAY_CONFIG } from './types';
|
|
16
16
|
import type { KnowledgeStore } from './store';
|
|
17
|
+
import { attempt } from '../utils/attempt';
|
|
17
18
|
|
|
18
19
|
const MAX_REFERENCED_BY = 20;
|
|
19
20
|
const MIN_CONTENT_FOR_PROVEN = 100;
|
|
@@ -92,9 +93,8 @@ export class KnowledgeLifecycle {
|
|
|
92
93
|
|
|
93
94
|
// Fire consumption event callbacks
|
|
94
95
|
for (const cb of this.onReferenceCallbacks) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
} catch { /* non-blocking */ }
|
|
96
|
+
// 显式 fail-open(attempt):消费回调是外挂监听,崩了不拖死引用记账主流程
|
|
97
|
+
attempt(() => cb({ entryId, contributor: contributor || 'unknown', timestamp: now, success }), () => undefined);
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
return updated;
|
|
@@ -226,14 +226,13 @@ export class KnowledgeLifecycle {
|
|
|
226
226
|
// Emit event for downstream consumers
|
|
227
227
|
const now = new Date().toISOString();
|
|
228
228
|
for (const cb of this.onReferenceCallbacks) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
} catch { /* non-blocking */ }
|
|
229
|
+
// 显式 fail-open(attempt):外挂监听回调失败不拖死标记主流程
|
|
230
|
+
attempt(() => cb({
|
|
231
|
+
entryId,
|
|
232
|
+
contributor: 'lifecycle',
|
|
233
|
+
timestamp: now,
|
|
234
|
+
context: 'skillCandidate:marked',
|
|
235
|
+
}), () => undefined);
|
|
237
236
|
}
|
|
238
237
|
|
|
239
238
|
return true;
|
|
@@ -277,14 +276,13 @@ export class KnowledgeLifecycle {
|
|
|
277
276
|
// Emit event for downstream consumers
|
|
278
277
|
const now = new Date().toISOString();
|
|
279
278
|
for (const cb of this.onReferenceCallbacks) {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
} catch { /* non-blocking */ }
|
|
279
|
+
// 显式 fail-open(attempt):外挂监听回调失败不拖死标记主流程
|
|
280
|
+
attempt(() => cb({
|
|
281
|
+
entryId,
|
|
282
|
+
contributor: 'lifecycle',
|
|
283
|
+
timestamp: now,
|
|
284
|
+
context: 'constraintCandidate:marked',
|
|
285
|
+
}), () => undefined);
|
|
288
286
|
}
|
|
289
287
|
|
|
290
288
|
return true;
|
package/src/knowledge/query.ts
CHANGED
|
@@ -16,6 +16,7 @@ import type {
|
|
|
16
16
|
import type { KnowledgeStore } from './store';
|
|
17
17
|
import { KnowledgeLifecycle } from './lifecycle';
|
|
18
18
|
import { estimateTokens } from './token-estimate';
|
|
19
|
+
import { attempt } from '../utils/attempt';
|
|
19
20
|
|
|
20
21
|
// ── Constants ──────────────────────────────────────────────
|
|
21
22
|
|
|
@@ -23,7 +24,7 @@ const CACHE_TTL_MS = 5 * 60 * 1000; // 5 minutes
|
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* 外部来源条目的 prompt 标记(harness#161:三层防御第二层 marking 的唯一正本)。
|
|
26
|
-
* `KnowledgeQuery.formatForPrompt()`
|
|
27
|
+
* `KnowledgeQuery.formatForPrompt()` 与下游编排消费方的注入格式化共用同一常量,
|
|
27
28
|
* 仓内不允许存在第二份字面量。
|
|
28
29
|
*/
|
|
29
30
|
export const EXTERNAL_SOURCE_MARKER = '[External Source — verify before acting]';
|
|
@@ -86,9 +87,8 @@ export class KnowledgeQuery {
|
|
|
86
87
|
|
|
87
88
|
// P2a: Record references for all returned entries (drives maturity ladder)
|
|
88
89
|
for (const entry of entries) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
} catch { /* non-blocking */ }
|
|
90
|
+
// 显式 fail-open(attempt):引用记账是查询的副作用,失败不影响查询结果返回
|
|
91
|
+
attempt(() => this.lifecycle.recordReference(entry.id), () => undefined);
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
return result;
|
|
@@ -173,8 +173,9 @@ export class KnowledgeQuery {
|
|
|
173
173
|
: allRefs.slice(0, 3);
|
|
174
174
|
|
|
175
175
|
const allContext = grouped.context;
|
|
176
|
-
const
|
|
177
|
-
|
|
176
|
+
const phase = taskContext.phase;
|
|
177
|
+
const context = phase
|
|
178
|
+
? allContext.filter(e => e.applicablePhases.includes(phase))
|
|
178
179
|
: allContext;
|
|
179
180
|
|
|
180
181
|
return { rules, references, context };
|
|
@@ -67,10 +67,12 @@ export class ReferenceTracker {
|
|
|
67
67
|
|
|
68
68
|
for (const record of records) {
|
|
69
69
|
for (const entryId of record.entryIds) {
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
let decisions = entryToDecisions.get(entryId);
|
|
71
|
+
if (!decisions) {
|
|
72
|
+
decisions = new Set();
|
|
73
|
+
entryToDecisions.set(entryId, decisions);
|
|
72
74
|
}
|
|
73
|
-
|
|
75
|
+
decisions.add(record.decisionId);
|
|
74
76
|
}
|
|
75
77
|
}
|
|
76
78
|
|
|
@@ -84,18 +86,14 @@ export class ReferenceTracker {
|
|
|
84
86
|
// ── Internal ───────────────────────────────────────────────
|
|
85
87
|
|
|
86
88
|
private readAll(): ReferenceRecord[] {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return readJsonl<ReferenceRecord>(this.filePath, 'skip').records;
|
|
97
|
-
} catch {
|
|
98
|
-
return [];
|
|
99
|
-
}
|
|
89
|
+
// 坏行策略:skip(harness#82:原「逐行 map 会抛 + 外层 catch 吞成整文件 []」
|
|
90
|
+
// ——坏一行丢全部记录——不可接受,改为单行损坏只丢该行);
|
|
91
|
+
// 缺文件 readJsonl 返回空结果(不抛),走到抛错只剩真 IO 故障 → fail-fast 不吞
|
|
92
|
+
// 计数去向:豁免(harness#100)——三个消费点 getReferencesForEntry /
|
|
93
|
+
// getReferencesForDecision / updateReferencedBy 只按合法记录取引用关系。
|
|
94
|
+
// 代价如实记录:checkOrphans(knowledge/lint.ts)以 refs.length>0 判孤儿,
|
|
95
|
+
// 坏行会让它给出假孤儿判定,不只是少报;透传需要给 LintIssue / `knowledge health`
|
|
96
|
+
// 报告加计数位,属 knowledge 域输出形状变更,另票收口
|
|
97
|
+
return readJsonl<ReferenceRecord>(this.filePath, 'skip').records;
|
|
100
98
|
}
|
|
101
99
|
}
|
package/src/knowledge/store.ts
CHANGED
|
@@ -287,12 +287,10 @@ export class FileKnowledgeStore implements KnowledgeStore {
|
|
|
287
287
|
}
|
|
288
288
|
|
|
289
289
|
private readFile(filePath: string): KnowledgeEntry | undefined {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
return undefined;
|
|
295
|
-
}
|
|
290
|
+
// fail-fast:文件来自 listFiles 的目录扫描,读到一半失败(IO/权限)直接抛;
|
|
291
|
+
// 内容形状问题(frontmatter 损坏/缺失)由 parseFile 显式上报后返回 undefined
|
|
292
|
+
const raw = fs.readFileSync(filePath, 'utf-8');
|
|
293
|
+
return this.parseFile(raw, filePath);
|
|
296
294
|
}
|
|
297
295
|
|
|
298
296
|
private parseFile(raw: string, filePath: string): KnowledgeEntry | undefined {
|
|
@@ -432,11 +430,8 @@ export class FileKnowledgeStore implements KnowledgeStore {
|
|
|
432
430
|
getSnapshot(date: string): IndexEntry[] | undefined {
|
|
433
431
|
const snapPath = path.join(this.baseDir, SNAPSHOTS_DIR, `index-${date}.json`);
|
|
434
432
|
if (!fs.existsSync(snapPath)) return undefined;
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
} catch {
|
|
438
|
-
return undefined;
|
|
439
|
-
}
|
|
433
|
+
// fail-fast:快照在场但损坏直接抛——吞成 undefined 会把损坏伪装成「没有快照」
|
|
434
|
+
return JSON.parse(fs.readFileSync(snapPath, 'utf-8')) as IndexEntry[];
|
|
440
435
|
}
|
|
441
436
|
|
|
442
437
|
/**
|
|
@@ -470,40 +465,30 @@ export class FileKnowledgeStore implements KnowledgeStore {
|
|
|
470
465
|
*/
|
|
471
466
|
getConsumptionStats(): ConsumptionStats | undefined {
|
|
472
467
|
const statsPath = path.join(this.baseDir, CONSUMPTION_STATS_FILE);
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
return undefined;
|
|
478
|
-
}
|
|
468
|
+
if (!fs.existsSync(statsPath)) return undefined;
|
|
469
|
+
// fail-fast:统计文件在场但损坏直接抛,不装成「无统计」
|
|
470
|
+
const stats = JSON.parse(fs.readFileSync(statsPath, 'utf-8')) as { dailyEvents?: number };
|
|
471
|
+
return { dailyEvents: stats.dailyEvents ?? 0 };
|
|
479
472
|
}
|
|
480
473
|
|
|
481
474
|
// ── Index I/O ────────────────────────────────────────────
|
|
482
475
|
|
|
483
476
|
readIndex(): IndexEntry[] {
|
|
484
477
|
const indexPath = path.join(this.baseDir, INDEX_FILE);
|
|
485
|
-
|
|
486
|
-
try {
|
|
487
|
-
stat = fs.statSync(indexPath);
|
|
488
|
-
} catch {
|
|
489
|
-
stat = undefined;
|
|
490
|
-
}
|
|
491
|
-
if (!stat) {
|
|
478
|
+
if (!fs.existsSync(indexPath)) {
|
|
492
479
|
this.indexCache = undefined;
|
|
493
480
|
return [];
|
|
494
481
|
}
|
|
482
|
+
const stat = fs.statSync(indexPath);
|
|
495
483
|
const cached = this.indexCache;
|
|
496
484
|
if (cached && cached.mtimeMs === stat.mtimeMs && cached.size === stat.size) {
|
|
497
485
|
return cached.entries;
|
|
498
486
|
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
} catch {
|
|
505
|
-
return [];
|
|
506
|
-
}
|
|
487
|
+
// fail-fast:index 在场但损坏直接抛——吞成 [] 会让 store 误以为库是空的
|
|
488
|
+
const raw = fs.readFileSync(indexPath, 'utf-8');
|
|
489
|
+
const entries = JSON.parse(raw) as IndexEntry[];
|
|
490
|
+
this.indexCache = { mtimeMs: stat.mtimeMs, size: stat.size, entries };
|
|
491
|
+
return entries;
|
|
507
492
|
}
|
|
508
493
|
|
|
509
494
|
private writeIndex(entries: IndexEntry[]): void {
|
|
@@ -33,13 +33,13 @@ import {
|
|
|
33
33
|
/**
|
|
34
34
|
* 默认配置
|
|
35
35
|
*/
|
|
36
|
-
const DEFAULT_CONFIG
|
|
36
|
+
const DEFAULT_CONFIG = {
|
|
37
37
|
summaryFile: '.harness/logs/traces-summary.json',
|
|
38
38
|
periodMs: 3600 * 1000, // 1 小时
|
|
39
39
|
thresholds: {
|
|
40
40
|
failRate: 0.5, // 失败率 > 50% 视为异常
|
|
41
41
|
},
|
|
42
|
-
};
|
|
42
|
+
} satisfies TraceAnalyzerConfig;
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* 计算趋势(`summarizeTraces` 的模块内助手)
|
|
@@ -139,19 +139,22 @@ export function summarizeTraces(traces: ExecutionTrace[]): TraceSummary[] {
|
|
|
139
139
|
/**
|
|
140
140
|
* 检测异常
|
|
141
141
|
*
|
|
142
|
-
* 基于阈值检测异常模式。阈值来自参数而非实例状态(ADR-0020):省略 `config`
|
|
143
|
-
*
|
|
142
|
+
* 基于阈值检测异常模式。阈值来自参数而非实例状态(ADR-0020):省略 `config`
|
|
143
|
+
* (或只给 `thresholds: {}`)时回落 `DEFAULT_CONFIG.thresholds` 的缺省口径。
|
|
144
144
|
*/
|
|
145
145
|
export function detectTraceAnomalies(
|
|
146
146
|
summaries: TraceSummary[],
|
|
147
147
|
config?: Partial<TraceAnalyzerConfig>
|
|
148
148
|
): TraceAnomaly[] {
|
|
149
149
|
const anomalies: TraceAnomaly[] = [];
|
|
150
|
-
|
|
150
|
+
// 阈值缺省由 DEFAULT_CONFIG 供给(satisfies 保住字面量非可选类型,无需断言);
|
|
151
|
+
// 调用方显式传 undefined/缺槽时回落缺省,不穿透成运行期 undefined 比较
|
|
152
|
+
const failRateThreshold =
|
|
153
|
+
config?.thresholds?.failRate ?? DEFAULT_CONFIG.thresholds.failRate;
|
|
151
154
|
|
|
152
155
|
for (const summary of summaries) {
|
|
153
156
|
// 检测失败率上升
|
|
154
|
-
if (summary.failRate >
|
|
157
|
+
if (summary.failRate > failRateThreshold && summary.recentTrend === 'rising') {
|
|
155
158
|
anomalies.push({
|
|
156
159
|
type: 'rising_fail_rate',
|
|
157
160
|
constraintId: summary.constraintId,
|
|
@@ -159,7 +162,7 @@ export function detectTraceAnomalies(
|
|
|
159
162
|
message: `约束 ${summary.constraintId} 失败率 ${Math.round(summary.failRate * 100)}% 且趋势上升`,
|
|
160
163
|
data: {
|
|
161
164
|
currentRate: summary.failRate,
|
|
162
|
-
threshold:
|
|
165
|
+
threshold: failRateThreshold,
|
|
163
166
|
trend: 'rising',
|
|
164
167
|
},
|
|
165
168
|
detectedAt: Date.now(),
|
|
@@ -297,14 +300,14 @@ export class TraceAnalyzer {
|
|
|
297
300
|
* 保存汇总结果
|
|
298
301
|
*/
|
|
299
302
|
saveSummary(summaries: TraceSummary[]): void {
|
|
300
|
-
writeSummaryJson(this.config.summaryFile
|
|
303
|
+
writeSummaryJson(this.config.summaryFile ?? DEFAULT_CONFIG.summaryFile, summaries);
|
|
301
304
|
}
|
|
302
305
|
|
|
303
306
|
/**
|
|
304
307
|
* 加载上次汇总结果
|
|
305
308
|
*/
|
|
306
309
|
loadSummary(): TraceSummary[] | null {
|
|
307
|
-
return readSummaryJson<TraceSummary[]>(this.config.summaryFile
|
|
310
|
+
return readSummaryJson<TraceSummary[]>(this.config.summaryFile ?? DEFAULT_CONFIG.summaryFile);
|
|
308
311
|
}
|
|
309
312
|
|
|
310
313
|
/**
|
package/src/monitoring/traces.ts
CHANGED
|
@@ -75,11 +75,11 @@ export function pruneTraceLogs(target: RunTarget, options: { maxAgeDays?: number
|
|
|
75
75
|
* `traceFile` 这里是**未锚定的项目相对片段**(#95 病根形状),故本文件在
|
|
76
76
|
* `project-path-convention.test.ts` 闸 3 的豁免表里点名带理由;锚定动作在构造函数里做。
|
|
77
77
|
*/
|
|
78
|
-
const DEFAULT_CONFIG
|
|
78
|
+
const DEFAULT_CONFIG = {
|
|
79
79
|
traceFile: DEFAULT_TRACE_FILE,
|
|
80
80
|
maxFileSize: 10 * 1024 * 1024, // 10MB
|
|
81
81
|
enabled: true,
|
|
82
|
-
};
|
|
82
|
+
} satisfies TraceCollectorConfig;
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
85
|
* Trace 收集器
|
|
@@ -102,10 +102,12 @@ export class TraceCollector {
|
|
|
102
102
|
constructor(config?: Partial<TraceCollectorConfig>) {
|
|
103
103
|
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
104
104
|
// 收根则相对落点按项目解析(harness#139:否则 -p 半失效——评估跑在 B、trace 写进 cwd);
|
|
105
|
-
// 没收根则保持 cwd
|
|
105
|
+
// 没收根则保持 cwd 解析,这是跨仓消费者依赖的兼容面,不是遗漏;
|
|
106
|
+
// 显式 traceFile: undefined 回落缺省(satisfies 保住缺省值非可选类型)
|
|
107
|
+
const traceFile = this.config.traceFile ?? DEFAULT_CONFIG.traceFile;
|
|
106
108
|
this.traceFile = this.config.projectPath
|
|
107
|
-
? path.resolve(this.config.projectPath,
|
|
108
|
-
:
|
|
109
|
+
? path.resolve(this.config.projectPath, traceFile)
|
|
110
|
+
: traceFile;
|
|
109
111
|
this.ensureDirectory();
|
|
110
112
|
}
|
|
111
113
|
|
|
@@ -277,7 +279,7 @@ export class TraceCollector {
|
|
|
277
279
|
}
|
|
278
280
|
|
|
279
281
|
const stats = fs.statSync(this.traceFile);
|
|
280
|
-
if (stats.size >= this.config.maxFileSize
|
|
282
|
+
if (stats.size >= (this.config.maxFileSize ?? DEFAULT_CONFIG.maxFileSize)) {
|
|
281
283
|
this.rotateFile();
|
|
282
284
|
}
|
|
283
285
|
}
|