@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
package/src/pretool-use-hook.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*
|
|
18
18
|
* P1-7(ADR-0031,票08):判定后对命中写审计 trace(只记账不加新拦截
|
|
19
19
|
* 能力)——此前拦下/放行的危险命令只写 stderr 不落盘,traces.log 里只有约束检查
|
|
20
|
-
* 在写。留痕失败经
|
|
20
|
+
* 在写。留痕失败经 utils/attempt 显式降级,fail-open 口径与 shim 主路径一致。
|
|
21
21
|
*
|
|
22
22
|
* P1-5 harness 半边(ADR-0031,票08):识别 tool_name 非 Bash 的事件
|
|
23
23
|
* (Edit/Write/apply_patch/MCP 工具,下游消费方补全 codex hooks matcher 后会到达),
|
|
@@ -25,8 +25,9 @@
|
|
|
25
25
|
* fail-open 空转;拦截归 codex 沙箱,本 shim 对它们只记账。
|
|
26
26
|
*/
|
|
27
27
|
import { CommandGate } from './gates/command';
|
|
28
|
-
import type { CommandBlacklistRule } from './
|
|
28
|
+
import type { CommandBlacklistRule } from './types/gate';
|
|
29
29
|
import { TraceCollector } from './monitoring/traces';
|
|
30
|
+
import { attempt } from './utils/attempt';
|
|
30
31
|
|
|
31
32
|
/** hook 标识:下游消费方 hook 配置共用同一 marker 做幂等检测(值不可变,改动会破坏存量配置的幂等识别) */
|
|
32
33
|
export const HOOK_MARKER = 'harness-command-gate';
|
|
@@ -53,27 +54,28 @@ export interface PreToolUseDecision {
|
|
|
53
54
|
* 非 Bash 工具事件(Edit/Write/apply_patch/MCP)恒放行(P1-5:拦截归 codex 沙箱)。
|
|
54
55
|
*/
|
|
55
56
|
export function decidePreToolUse(rawStdin: string): PreToolUseDecision {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
// 显式 fail-open(attempt):stdin 非 JSON 时按空输入放行——provider 执法脚本
|
|
58
|
+
// 崩溃/误判不能误伤用户操作,宁可漏拦也不全体 Bash 秒断
|
|
59
|
+
const input = attempt(
|
|
60
|
+
() => JSON.parse(rawStdin || '{}') as PreToolUseInput,
|
|
61
|
+
(): PreToolUseInput => ({}),
|
|
62
|
+
);
|
|
62
63
|
const toolName = input.tool_name || 'Bash';
|
|
63
64
|
const toolInput = input.tool_input || {};
|
|
64
65
|
if (toolName !== 'Bash') {
|
|
65
66
|
return { allowed: true, command: '', hits: [], toolName, targetPath: toolInput.file_path };
|
|
66
67
|
}
|
|
67
68
|
const command = toolInput.command || '';
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
// 显式 fail-open(attempt):CommandGate 加载/判定异常一律放行,理由同上
|
|
70
|
+
return attempt(
|
|
71
|
+
() => {
|
|
72
|
+
const gate = new CommandGate();
|
|
73
|
+
// 与 isAllowed 同一谓词(match):allowed = 无 block 级命中
|
|
74
|
+
const hits = gate.match(command);
|
|
75
|
+
return { allowed: !hits.some((r) => r.level === 'block'), command, hits, toolName };
|
|
76
|
+
},
|
|
77
|
+
() => ({ allowed: true, command, hits: [], toolName }),
|
|
78
|
+
);
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
/** 黑名单级别 → trace severity 映射(词表不动 types/trace.ts) */
|
|
@@ -97,7 +99,10 @@ const SEVERITY_BY_LEVEL = {
|
|
|
97
99
|
* 项目根(provider 在项目根起会话),可接受;写错地方也不拦主路径。
|
|
98
100
|
*/
|
|
99
101
|
function recordHookTrace(decision: PreToolUseDecision): void {
|
|
100
|
-
|
|
102
|
+
// 显式 fail-open(attempt):留痕是记账副作用,失败不能影响拦截主路径
|
|
103
|
+
// (口径与 shim 主路径一致——hook 进程里任何异常都必须放行)
|
|
104
|
+
attempt(
|
|
105
|
+
() => {
|
|
101
106
|
// P1-5:非 Bash 工具事件只留痕不拦截(拦截归 codex 沙箱)——constraintId
|
|
102
107
|
// 按工具名分(tool-event:<tool>),工具集合有界、不会碎片化聚合;evidence
|
|
103
108
|
// 记工具名 + 目标路径类字段(file_path),不记内容正文。
|
|
@@ -133,9 +138,9 @@ function recordHookTrace(decision: PreToolUseDecision): void {
|
|
|
133
138
|
...(firstToken ? [`cmd:${firstToken}`] : []),
|
|
134
139
|
],
|
|
135
140
|
});
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
141
|
+
},
|
|
142
|
+
() => undefined,
|
|
143
|
+
);
|
|
139
144
|
}
|
|
140
145
|
|
|
141
146
|
/**
|
package/src/release/CONTEXT.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
- `getCriticalArtifacts(pkgRoot?)` / `verifyReleaseArtifacts(pkgRoot?)`——公开 API;pkgRoot 缺省自动解析,外部消费者零参数即自检已安装的 harness
|
|
12
12
|
|
|
13
13
|
## 依赖关系
|
|
14
|
-
-
|
|
14
|
+
- 内部依赖仅 `utils/package-json`(readPackageJson 正本,重构 Phase 5 收口);其余只依赖 node fs/path
|
|
15
15
|
|
|
16
16
|
## 约定
|
|
17
17
|
- 清单维护模型:声明面推导为主(目录重构动到 package.json 时清单自动跟随)+ extras 随源码维护;**不新增第三处硬编码清单**
|
package/src/release/integrity.ts
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
import * as fs from 'fs';
|
|
14
14
|
import * as path from 'path';
|
|
15
|
+
import { readPackageJson } from '../utils/package-json';
|
|
15
16
|
|
|
16
17
|
/** 本包名(包根向上解析的身份锚点,同 bin 名同源) */
|
|
17
18
|
export const HARNESS_PACKAGE_NAME = '@dommaker/harness';
|
|
@@ -70,12 +71,9 @@ export function deriveCriticalArtifacts(manifest: PackagePublishManifest): strin
|
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
function isHarnessPackageRoot(dir: string): boolean {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
} catch {
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
74
|
+
// 探测语义:该目录没有 package.json → false(向上继续找);
|
|
75
|
+
// 有但 JSON 损坏 → 抛出(fail-fast,不把损坏清单当「不是包根」跳过)
|
|
76
|
+
return readPackageJson(dir)?.name === HARNESS_PACKAGE_NAME;
|
|
79
77
|
}
|
|
80
78
|
|
|
81
79
|
/**
|
|
@@ -106,9 +104,10 @@ function resolveRoot(pkgRoot?: string): string {
|
|
|
106
104
|
*/
|
|
107
105
|
export function getCriticalArtifacts(pkgRoot?: string): string[] {
|
|
108
106
|
const root = resolveRoot(pkgRoot);
|
|
109
|
-
const manifest
|
|
110
|
-
|
|
111
|
-
|
|
107
|
+
const manifest = readPackageJson<PackagePublishManifest>(root);
|
|
108
|
+
if (!manifest) {
|
|
109
|
+
throw new Error(`[harness] 包根缺少 package.json: ${root}`);
|
|
110
|
+
}
|
|
112
111
|
return [...new Set([...deriveCriticalArtifacts(manifest), ...EXTRA_CRITICAL_ARTIFACTS])].sort();
|
|
113
112
|
}
|
|
114
113
|
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
// SDD Index Generator
|
|
2
2
|
// Scans docs/sdd/*/requirement.md, generates docs/sdd/_index.md
|
|
3
3
|
// Format: slug|pmoNumber|status|title|tags
|
|
4
|
+
//
|
|
5
|
+
// 与 knowledge/index-generator.ts 的相似是表面形状(扫树 → frontmatter → 竖线行),
|
|
6
|
+
// 不合并是刻意裁决(重构 Phase 5,理由见 src/knowledge/CONTEXT.md 约定节):
|
|
7
|
+
// 本生成器只管 docs/sdd 项目文档树(目录即条目、平铺、stale 跳过)。
|
|
4
8
|
|
|
5
9
|
import * as fs from 'fs';
|
|
6
10
|
import * as path from 'path';
|
package/src/types/checkpoint.ts
CHANGED
|
@@ -45,8 +45,8 @@ export interface CheckConfig {
|
|
|
45
45
|
/** HTTP 方法 */
|
|
46
46
|
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
47
47
|
|
|
48
|
-
/** HTTP
|
|
49
|
-
body?:
|
|
48
|
+
/** HTTP 请求体(JSON 序列化后发送,形状由被测端点决定) */
|
|
49
|
+
body?: unknown;
|
|
50
50
|
|
|
51
51
|
/** HTTP 请求头 */
|
|
52
52
|
headers?: Record<string, string>;
|
|
@@ -126,11 +126,11 @@ export interface CheckResult {
|
|
|
126
126
|
/** 错误详情 */
|
|
127
127
|
error?: string;
|
|
128
128
|
|
|
129
|
-
/**
|
|
130
|
-
actual?:
|
|
129
|
+
/** 实际值(形状随检查类型而异,消费端自行窄化) */
|
|
130
|
+
actual?: unknown;
|
|
131
131
|
|
|
132
|
-
/**
|
|
133
|
-
expected?:
|
|
132
|
+
/** 预期值(同 actual,开放形状) */
|
|
133
|
+
expected?: unknown;
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
/**
|
|
@@ -166,8 +166,8 @@ export interface CheckpointContext {
|
|
|
166
166
|
/** 环境变量 */
|
|
167
167
|
env?: Record<string, string>;
|
|
168
168
|
|
|
169
|
-
/** 步骤输出(用于 output_*
|
|
170
|
-
output?:
|
|
169
|
+
/** 步骤输出(用于 output_* 检查;string 直用,其余 JSON 序列化) */
|
|
170
|
+
output?: unknown;
|
|
171
171
|
|
|
172
172
|
/** 自定义检查处理器 */
|
|
173
173
|
customHandlers?: Map<string, (config: CheckConfig) => Promise<CheckResult>>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 命令输出流注入面(Phase 4 类型收口)
|
|
3
|
+
*
|
|
4
|
+
* 正本原居 `cli/command-contract.ts`;core(constraint-lifecycle 的历史签名槽)
|
|
5
|
+
* 也消费它,形成 core→cli 的类型倒挂。按分层 `types → … → cli`,这个被两层
|
|
6
|
+
* 消费的公共类型下沉到 types 层;cli/command-contract.ts re-export 本定义,
|
|
7
|
+
* 既有 CLI 消费方导入路径不变。
|
|
8
|
+
*
|
|
9
|
+
* 最小可写接口:`process.stdout` / `process.stderr` 结构化满足。
|
|
10
|
+
*/
|
|
11
|
+
export interface CommandIO {
|
|
12
|
+
stdout: { write(chunk: string): boolean };
|
|
13
|
+
stderr: { write(chunk: string): boolean };
|
|
14
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 门禁公共类型(gates/ 层被 cli/ 与包外消费的横切类型,自 gates/types.ts 归拢)
|
|
3
|
+
*
|
|
4
|
+
* 本层(src/types/)是零依赖公共类型层:本文件不得 import 任何内部模块。
|
|
5
|
+
* 门禁协议本身(Gate / GateContext / 各门禁配置)仍留在 src/gates/types.ts——
|
|
6
|
+
* 它们只被 gates 层内部消费;这里只收跨层消费的类型:
|
|
7
|
+
* - GateResult / GateDecision / GateDecisionStatus:cli/gate-command.ts 的决策→命令映射
|
|
8
|
+
* - CommandBlacklistRule / BlacklistLevel:cli `command` 命令与 pretool-use-hook
|
|
9
|
+
* - PerformanceThresholds:cli `performance` 命令的旗帜装配
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 门禁结果(报告结构)
|
|
14
|
+
*
|
|
15
|
+
* 统一 Gate 接口后 GateResult 仍是每个门禁产出的报告层;
|
|
16
|
+
* 决策层见 GateDecision。
|
|
17
|
+
*/
|
|
18
|
+
export interface GateResult {
|
|
19
|
+
gate: string;
|
|
20
|
+
passed: boolean;
|
|
21
|
+
message: string;
|
|
22
|
+
/** 报告负载是开放袋(各门禁私有形状),读取方自行窄化 */
|
|
23
|
+
details?: Record<string, unknown>;
|
|
24
|
+
timestamp: string;
|
|
25
|
+
duration?: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 门禁决策三态(守卫/门禁统一,G1)
|
|
30
|
+
*
|
|
31
|
+
* - deny:阻断。单调语义——一旦出现,下游门禁不得改回 allow。
|
|
32
|
+
* - abstain:弃权/放行。不阻断,也不否决。
|
|
33
|
+
* - ask:需要人裁决。枚举预留,暂无实现;无实现时 fail-closed 按 deny 计。
|
|
34
|
+
*/
|
|
35
|
+
export type GateDecisionStatus = 'deny' | 'abstain' | 'ask';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 门禁决策:统一 Gate 接口的返回值
|
|
39
|
+
*
|
|
40
|
+
* status 是三态决策;result 携带 GateResult 报告结构。
|
|
41
|
+
* 决策对象由 decisionFromResult 浅冻结——不可变是
|
|
42
|
+
* deny 单调语义的接口契约。
|
|
43
|
+
*/
|
|
44
|
+
export interface GateDecision {
|
|
45
|
+
/** 三态决策 */
|
|
46
|
+
status: GateDecisionStatus;
|
|
47
|
+
/** 报告结构(GateResult 保留为报告层,不删) */
|
|
48
|
+
result: GateResult;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 黑名单级别:
|
|
53
|
+
* - block: 禁止执行,直接拒绝
|
|
54
|
+
* - warn: 允许执行,但记录警告
|
|
55
|
+
* - audit: 允许执行,但记录审计日志
|
|
56
|
+
*/
|
|
57
|
+
export type BlacklistLevel = 'block' | 'warn' | 'audit';
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 命令黑名单规则
|
|
61
|
+
*/
|
|
62
|
+
export interface CommandBlacklistRule {
|
|
63
|
+
id: string;
|
|
64
|
+
pattern: RegExp;
|
|
65
|
+
level: BlacklistLevel;
|
|
66
|
+
message: string;
|
|
67
|
+
category: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 性能阈值(架构评审候选2:只留有真实现的维度——coverage 走 json-summary、
|
|
72
|
+
* bundleSize 走 dist 目录测量;responseTime/memoryUsage/throughput 无真实现已删)
|
|
73
|
+
*/
|
|
74
|
+
export interface PerformanceThresholds {
|
|
75
|
+
minCoverage?: number; // %
|
|
76
|
+
maxBundleSize?: number; // KB
|
|
77
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* attempt 测试(吞错治理,Phase 2)
|
|
3
|
+
*
|
|
4
|
+
* 契约:正常路径透传返回值;异常路径调 onError 拿降级值,err 原样交给 onError;
|
|
5
|
+
* onError 自己再抛时不拦(降级逻辑本身的 bug 不二次吞掉)。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { attempt, attemptAsync } from '../attempt';
|
|
9
|
+
|
|
10
|
+
describe('attempt(同步)', () => {
|
|
11
|
+
it('fn 正常返回 → 透传返回值,onError 不被调用', () => {
|
|
12
|
+
const onError = jest.fn(() => -1);
|
|
13
|
+
expect(attempt(() => 42, onError)).toBe(42);
|
|
14
|
+
expect(onError).not.toHaveBeenCalled();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('fn 抛错 → 返回 onError 的降级值,err 原样传入', () => {
|
|
18
|
+
const boom = new Error('boom');
|
|
19
|
+
const onError = jest.fn(() => 'fallback');
|
|
20
|
+
expect(
|
|
21
|
+
attempt(() => {
|
|
22
|
+
throw boom;
|
|
23
|
+
}, onError),
|
|
24
|
+
).toBe('fallback');
|
|
25
|
+
expect(onError).toHaveBeenCalledWith(boom);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('非 Error 抛出物同样原样交给 onError', () => {
|
|
29
|
+
expect(
|
|
30
|
+
attempt(
|
|
31
|
+
() => {
|
|
32
|
+
throw 'raw-string';
|
|
33
|
+
},
|
|
34
|
+
(err) => `caught:${String(err)}`,
|
|
35
|
+
),
|
|
36
|
+
).toBe('caught:raw-string');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('onError 再抛 → 不二次吞,原样抛出', () => {
|
|
40
|
+
const second = new Error('fallback-broken');
|
|
41
|
+
expect(() =>
|
|
42
|
+
attempt(
|
|
43
|
+
() => {
|
|
44
|
+
throw new Error('first');
|
|
45
|
+
},
|
|
46
|
+
() => {
|
|
47
|
+
throw second;
|
|
48
|
+
},
|
|
49
|
+
),
|
|
50
|
+
).toThrow(second);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe('attemptAsync(异步)', () => {
|
|
55
|
+
it('fn 正常 resolve → 透传', async () => {
|
|
56
|
+
await expect(attemptAsync(async () => 7, () => 0)).resolves.toBe(7);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('fn reject → 返回 onError 降级值,err 原样传入', async () => {
|
|
60
|
+
const boom = new Error('async-boom');
|
|
61
|
+
const onError = jest.fn(() => -1);
|
|
62
|
+
await expect(
|
|
63
|
+
attemptAsync(async () => {
|
|
64
|
+
throw boom;
|
|
65
|
+
}, onError),
|
|
66
|
+
).resolves.toBe(-1);
|
|
67
|
+
expect(onError).toHaveBeenCalledWith(boom);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('onError 返回 Promise 也等待', async () => {
|
|
71
|
+
await expect(
|
|
72
|
+
attemptAsync(
|
|
73
|
+
async () => {
|
|
74
|
+
throw new Error('x');
|
|
75
|
+
},
|
|
76
|
+
async () => 'degraded',
|
|
77
|
+
),
|
|
78
|
+
).resolves.toBe('degraded');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('onError 再抛 → rejection 原样传出', async () => {
|
|
82
|
+
const second = new Error('fallback-broken');
|
|
83
|
+
await expect(
|
|
84
|
+
attemptAsync(
|
|
85
|
+
async () => {
|
|
86
|
+
throw new Error('first');
|
|
87
|
+
},
|
|
88
|
+
() => {
|
|
89
|
+
throw second;
|
|
90
|
+
},
|
|
91
|
+
),
|
|
92
|
+
).rejects.toThrow(second);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* package.json 读取正本测试(重构 Phase 5 收口)
|
|
3
|
+
*
|
|
4
|
+
* 钉住两条语义:缺失 → null(合法输入);在场但损坏 → 抛出(fail-fast)。
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, it, expect } from '@jest/globals';
|
|
8
|
+
import * as fs from 'fs';
|
|
9
|
+
import * as os from 'os';
|
|
10
|
+
import * as path from 'path';
|
|
11
|
+
import { readPackageJson } from '../package-json';
|
|
12
|
+
|
|
13
|
+
function makeDir(): string {
|
|
14
|
+
return fs.mkdtempSync(path.join(os.tmpdir(), 'harness-package-json-'));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe('readPackageJson', () => {
|
|
18
|
+
it('package.json 缺失 → null', () => {
|
|
19
|
+
expect(readPackageJson(makeDir())).toBeNull();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('在场 → 解析出常见字段', () => {
|
|
23
|
+
const dir = makeDir();
|
|
24
|
+
fs.writeFileSync(
|
|
25
|
+
path.join(dir, 'package.json'),
|
|
26
|
+
JSON.stringify({
|
|
27
|
+
name: 'fixture',
|
|
28
|
+
version: '1.2.3',
|
|
29
|
+
scripts: { test: 'jest' },
|
|
30
|
+
dependencies: { chalk: '^4.1.2' },
|
|
31
|
+
})
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const pkg = readPackageJson(dir);
|
|
35
|
+
expect(pkg?.name).toBe('fixture');
|
|
36
|
+
expect(pkg?.version).toBe('1.2.3');
|
|
37
|
+
expect(pkg?.scripts?.test).toBe('jest');
|
|
38
|
+
expect(pkg?.dependencies?.chalk).toBe('^4.1.2');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('在场但 JSON 损坏 → 抛出(fail-fast,不装 null)', () => {
|
|
42
|
+
const dir = makeDir();
|
|
43
|
+
fs.writeFileSync(path.join(dir, 'package.json'), '{ not json');
|
|
44
|
+
|
|
45
|
+
expect(() => readPackageJson(dir)).toThrow();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('泛型窄化:消费方声明更窄的清单形状', () => {
|
|
49
|
+
const dir = makeDir();
|
|
50
|
+
fs.writeFileSync(
|
|
51
|
+
path.join(dir, 'package.json'),
|
|
52
|
+
JSON.stringify({ name: 'fixture', bin: { harness: './bin/harness.js' } })
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const pkg = readPackageJson<{ name: string; bin: Record<string, string> }>(dir);
|
|
56
|
+
expect(pkg?.bin.harness).toBe('./bin/harness.js');
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -37,11 +37,16 @@ describe('getHarnessPackageVersion', () => {
|
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
-
it('package.json
|
|
40
|
+
it('package.json 缺失时返回 unknown', () => {
|
|
41
41
|
jest.isolateModules(() => {
|
|
42
42
|
jest.doMock('fs', () => ({
|
|
43
43
|
...jest.requireActual('fs'),
|
|
44
|
-
|
|
44
|
+
// readPackageJson 口径:单次 readFileSync,ENOENT = 缺失(与真实缺文件行为一致)
|
|
45
|
+
readFileSync: () => {
|
|
46
|
+
const err = new Error('ENOENT: no such file or directory') as NodeJS.ErrnoException;
|
|
47
|
+
err.code = 'ENOENT';
|
|
48
|
+
throw err;
|
|
49
|
+
},
|
|
45
50
|
}));
|
|
46
51
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
47
52
|
const fresh = require('../package-version') as typeof import('../package-version');
|
|
@@ -50,6 +55,20 @@ describe('getHarnessPackageVersion', () => {
|
|
|
50
55
|
});
|
|
51
56
|
});
|
|
52
57
|
|
|
58
|
+
it('package.json 在场但读取失败(损坏/IO 故障)时抛出(fail-fast,不装 unknown)', () => {
|
|
59
|
+
jest.isolateModules(() => {
|
|
60
|
+
jest.doMock('fs', () => ({
|
|
61
|
+
...jest.requireActual('fs'),
|
|
62
|
+
existsSync: () => true,
|
|
63
|
+
readFileSync: () => { throw new Error('ENOENT'); },
|
|
64
|
+
}));
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
66
|
+
const fresh = require('../package-version') as typeof import('../package-version');
|
|
67
|
+
expect(() => fresh.getHarnessPackageVersion()).toThrow('ENOENT');
|
|
68
|
+
jest.dontMock('fs');
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
53
72
|
it('package.json 无 version 字段时返回 unknown', () => {
|
|
54
73
|
jest.isolateModules(() => {
|
|
55
74
|
jest.doMock('fs', () => ({
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* attempt — 显式降级执行(吞错治理,Phase 2)
|
|
3
|
+
*
|
|
4
|
+
* 只服务有意识的 fail-open 场景:provider 执法 hook(崩溃不能误伤用户操作)、
|
|
5
|
+
* 事件回调隔离、非阻断副作用记账等。调用点必须另起一行注释写清降级理由——
|
|
6
|
+
* 「这里有意降级」要在代码里看得见,而不是藏在空 catch 里
|
|
7
|
+
* (反例教训:静默吞错会让解析/判定 bug 变成「永远通过」,harness#119)。
|
|
8
|
+
*
|
|
9
|
+
* 不属于本工具的用途:
|
|
10
|
+
* - 存在性探测(文件在不在)→ 用 existsSync,不要 try/catch 也不要 attempt;
|
|
11
|
+
* - 缺文件有领域语义(缺失 = 空集/未配置)→ 读面自己判 existsSync;
|
|
12
|
+
* - 其余异常一律让它抛出(fail-fast)。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 同步版:fn 抛错时返回 onError(err) 的降级值。
|
|
17
|
+
*/
|
|
18
|
+
export function attempt<T>(fn: () => T, onError: (err: unknown) => T): T {
|
|
19
|
+
try {
|
|
20
|
+
return fn();
|
|
21
|
+
} catch (err) {
|
|
22
|
+
return onError(err);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 异步版:同上,吞的是 Promise rejection。
|
|
28
|
+
*/
|
|
29
|
+
export async function attemptAsync<T>(fn: () => Promise<T>, onError: (err: unknown) => T | Promise<T>): Promise<T> {
|
|
30
|
+
try {
|
|
31
|
+
return await fn();
|
|
32
|
+
} catch (err) {
|
|
33
|
+
return onError(err);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -18,44 +18,40 @@ export function detectSourceRoots(projectPath: string): string[] {
|
|
|
18
18
|
// 1. monorepo: packages/*
|
|
19
19
|
const packagesDir = join(projectPath, 'packages');
|
|
20
20
|
if (existsSync(packagesDir)) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
hasSubDir = true;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
// 仅当无 src/lib 子目录时,包根目录才作为源码目录
|
|
36
|
-
if (!hasSubDir && hasSourceFiles(pkgDir)) {
|
|
37
|
-
roots.push(`packages/${entry.name}`);
|
|
21
|
+
const entries = readdirSync(packagesDir, { withFileTypes: true });
|
|
22
|
+
for (const entry of entries) {
|
|
23
|
+
if (!entry.isDirectory() || entry.name.startsWith('.') || entry.name.startsWith('__')) continue;
|
|
24
|
+
const pkgDir = join(packagesDir, entry.name);
|
|
25
|
+
// 检查常见的源码子目录
|
|
26
|
+
let hasSubDir = false;
|
|
27
|
+
for (const sub of ['src', 'lib']) {
|
|
28
|
+
const subDir = join(pkgDir, sub);
|
|
29
|
+
if (existsSync(subDir) && hasSourceFiles(subDir)) {
|
|
30
|
+
roots.push(`packages/${entry.name}/${sub}`);
|
|
31
|
+
hasSubDir = true;
|
|
38
32
|
}
|
|
39
33
|
}
|
|
40
|
-
|
|
34
|
+
// 仅当无 src/lib 子目录时,包根目录才作为源码目录
|
|
35
|
+
if (!hasSubDir && hasSourceFiles(pkgDir)) {
|
|
36
|
+
roots.push(`packages/${entry.name}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
41
39
|
}
|
|
42
40
|
|
|
43
41
|
// 2. monorepo: apps/*
|
|
44
42
|
const appsDir = join(projectPath, 'apps');
|
|
45
43
|
if (existsSync(appsDir)) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const appDir = join(appsDir, entry.name);
|
|
44
|
+
const entries = readdirSync(appsDir, { withFileTypes: true });
|
|
45
|
+
for (const entry of entries) {
|
|
46
|
+
if (!entry.isDirectory() || entry.name.startsWith('.') || entry.name.startsWith('__')) continue;
|
|
47
|
+
const appDir = join(appsDir, entry.name);
|
|
51
48
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
49
|
+
// apps/xxx/src 本身
|
|
50
|
+
const appSrcDir = join(appDir, 'src');
|
|
51
|
+
if (existsSync(appSrcDir) && hasSourceFiles(appSrcDir)) {
|
|
52
|
+
roots.push(`apps/${entry.name}/src`);
|
|
57
53
|
}
|
|
58
|
-
}
|
|
54
|
+
}
|
|
59
55
|
}
|
|
60
56
|
|
|
61
57
|
// 3. 单 repo: src/, lib/
|
|
@@ -71,26 +67,24 @@ export function detectSourceRoots(projectPath: string): string[] {
|
|
|
71
67
|
|
|
72
68
|
/**
|
|
73
69
|
* 检查目录(递归)中是否包含 .ts 源文件(排除 __tests__, node_modules, dist)
|
|
70
|
+
*
|
|
71
|
+
* existsSync 过了却 readdir 失败(权限等)→ 抛出(fail-fast),不当作「无源文件」。
|
|
74
72
|
*/
|
|
75
73
|
function hasSourceFiles(dir: string): boolean {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (name === '__tests__' || name === '__mocks__') continue;
|
|
74
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
75
|
+
for (const entry of entries) {
|
|
76
|
+
const name = entry.name;
|
|
77
|
+
if (name.startsWith('.') || name === 'node_modules' || name === 'dist') continue;
|
|
78
|
+
if (name === '__tests__' || name === '__mocks__') continue;
|
|
82
79
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
} else if (entry.isDirectory()) {
|
|
89
|
-
if (hasSourceFiles(fullPath)) return true;
|
|
80
|
+
const fullPath = join(dir, name);
|
|
81
|
+
if (entry.isFile()) {
|
|
82
|
+
if (name.endsWith('.ts') && !name.endsWith('.d.ts')) {
|
|
83
|
+
return true;
|
|
90
84
|
}
|
|
85
|
+
} else if (entry.isDirectory()) {
|
|
86
|
+
if (hasSourceFiles(fullPath)) return true;
|
|
91
87
|
}
|
|
92
|
-
} catch {
|
|
93
|
-
return false;
|
|
94
88
|
}
|
|
95
89
|
return false;
|
|
96
90
|
}
|
package/src/utils/file-walk.ts
CHANGED
|
@@ -20,18 +20,14 @@ export interface FileWalkOptions {
|
|
|
20
20
|
/**
|
|
21
21
|
* 递归收集 root 下的文件路径(同步)
|
|
22
22
|
*
|
|
23
|
-
*
|
|
23
|
+
* fail-fast:目录不可读(权限等)直接抛出,不再静默跳过——
|
|
24
|
+
* 遍历缺一块而调用方不知情,比报错更难查。
|
|
24
25
|
*/
|
|
25
26
|
export function walkFiles(root: string, options: FileWalkOptions = {}): string[] {
|
|
26
27
|
const { skipDirs = [], skipHidden = false, filter } = options;
|
|
27
28
|
const results: string[] = [];
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
try {
|
|
31
|
-
entries = fs.readdirSync(root, { withFileTypes: true });
|
|
32
|
-
} catch {
|
|
33
|
-
return results;
|
|
34
|
-
}
|
|
30
|
+
const entries = fs.readdirSync(root, { withFileTypes: true });
|
|
35
31
|
|
|
36
32
|
for (const entry of entries) {
|
|
37
33
|
if (skipHidden && entry.name.startsWith('.')) continue;
|