@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/gates/contract.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 契约门禁
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
4
|
* 检查 API 契约:
|
|
5
5
|
* - OpenAPI Schema 验证
|
|
6
6
|
* - 破坏性变更检测
|
|
7
7
|
* - 版本兼容性
|
|
8
|
+
*
|
|
9
|
+
* fail-fast:契约文件读取/解析失败直接抛出(外层归一为 deny 报告),
|
|
10
|
+
* 不再有「读不到旧契约就当零破坏性变更」的吞错兜底。
|
|
8
11
|
*/
|
|
9
12
|
|
|
10
13
|
import * as fs from 'fs/promises';
|
|
@@ -13,6 +16,25 @@ import { pass, fail, fromError } from './types';
|
|
|
13
16
|
import type { GateResult, GateContext, ContractGateConfig, Gate, GateDecision } from './types';
|
|
14
17
|
import { decisionFromResult } from './decision';
|
|
15
18
|
|
|
19
|
+
/** 契约格式验证结果 */
|
|
20
|
+
interface ContractValidation {
|
|
21
|
+
valid: boolean;
|
|
22
|
+
errors: string[];
|
|
23
|
+
endpoints: number;
|
|
24
|
+
version?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** 破坏性变更条目 */
|
|
28
|
+
export interface BreakingChange {
|
|
29
|
+
type: string;
|
|
30
|
+
description: string;
|
|
31
|
+
path: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
35
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
36
|
+
}
|
|
37
|
+
|
|
16
38
|
/**
|
|
17
39
|
* 契约门禁
|
|
18
40
|
*/
|
|
@@ -43,10 +65,10 @@ export class ContractGate implements Gate {
|
|
|
43
65
|
const startTime = Date.now();
|
|
44
66
|
|
|
45
67
|
try {
|
|
46
|
-
const contractPath = context.newContractPath ??
|
|
68
|
+
const contractPath = context.newContractPath ??
|
|
47
69
|
path.join(context.projectPath, this.config.contractPath);
|
|
48
70
|
|
|
49
|
-
//
|
|
71
|
+
// 检查契约文件是否存在(缺失 = 跳过,门禁语义而非兜底)
|
|
50
72
|
try {
|
|
51
73
|
await fs.access(contractPath);
|
|
52
74
|
} catch {
|
|
@@ -88,108 +110,93 @@ export class ContractGate implements Gate {
|
|
|
88
110
|
endpoints: validation.endpoints,
|
|
89
111
|
version: validation.version,
|
|
90
112
|
});
|
|
91
|
-
} catch (error:
|
|
113
|
+
} catch (error: unknown) {
|
|
92
114
|
return fromError('contract', '契约检查失败', error, startTime);
|
|
93
115
|
}
|
|
94
116
|
}
|
|
95
117
|
|
|
96
118
|
/**
|
|
97
|
-
*
|
|
119
|
+
* 验证契约格式:读取/解析失败直接抛出(fail-fast)。
|
|
98
120
|
*/
|
|
99
|
-
private async validateContract(contractPath: string): Promise<{
|
|
100
|
-
valid: boolean;
|
|
101
|
-
errors: string[];
|
|
102
|
-
endpoints: number;
|
|
103
|
-
version?: string;
|
|
104
|
-
}> {
|
|
121
|
+
private async validateContract(contractPath: string): Promise<ContractValidation> {
|
|
105
122
|
const errors: string[] = [];
|
|
106
123
|
let endpoints = 0;
|
|
107
124
|
let version: string | undefined;
|
|
108
125
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (line.startsWith('openapi:') || line.startsWith('swagger:')) {
|
|
119
|
-
version = line.split(':')[1]?.trim();
|
|
120
|
-
}
|
|
121
|
-
if (line.match(/^\s*\/\w+/)) {
|
|
122
|
-
endpoints++;
|
|
123
|
-
}
|
|
126
|
+
const content = await fs.readFile(contractPath, 'utf-8');
|
|
127
|
+
|
|
128
|
+
// 解析 YAML 或 JSON
|
|
129
|
+
if (contractPath.endsWith('.yaml') || contractPath.endsWith('.yml')) {
|
|
130
|
+
// 简化的 YAML 解析(只提取基本信息)
|
|
131
|
+
const lines = content.split('\n');
|
|
132
|
+
for (const line of lines) {
|
|
133
|
+
if (line.startsWith('openapi:') || line.startsWith('swagger:')) {
|
|
134
|
+
version = line.split(':')[1]?.trim();
|
|
124
135
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
version = spec.openapi || spec.swagger;
|
|
128
|
-
if (spec.paths) {
|
|
129
|
-
endpoints = Object.keys(spec.paths).length;
|
|
136
|
+
if (line.match(/^\s*\/\w+/)) {
|
|
137
|
+
endpoints++;
|
|
130
138
|
}
|
|
131
139
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (!
|
|
135
|
-
|
|
140
|
+
} else {
|
|
141
|
+
const raw: unknown = JSON.parse(content);
|
|
142
|
+
if (!isRecord(raw)) {
|
|
143
|
+
throw new Error(`契约文件不是 JSON 对象: ${contractPath}`);
|
|
136
144
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
145
|
+
version = typeof raw.openapi === 'string'
|
|
146
|
+
? raw.openapi
|
|
147
|
+
: typeof raw.swagger === 'string'
|
|
148
|
+
? raw.swagger
|
|
149
|
+
: undefined;
|
|
150
|
+
if (isRecord(raw.paths)) {
|
|
151
|
+
endpoints = Object.keys(raw.paths).length;
|
|
140
152
|
}
|
|
153
|
+
}
|
|
141
154
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
endpoints,
|
|
146
|
-
version,
|
|
147
|
-
};
|
|
148
|
-
} catch (error: any) {
|
|
149
|
-
return {
|
|
150
|
-
valid: false,
|
|
151
|
-
errors: [`解析失败: ${error.message}`],
|
|
152
|
-
endpoints: 0,
|
|
153
|
-
};
|
|
155
|
+
// 基本验证
|
|
156
|
+
if (!version) {
|
|
157
|
+
errors.push('缺少 openapi/swagger 版本');
|
|
154
158
|
}
|
|
159
|
+
|
|
160
|
+
if (endpoints === 0) {
|
|
161
|
+
errors.push('没有定义任何端点');
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
valid: errors.length === 0,
|
|
166
|
+
errors,
|
|
167
|
+
endpoints,
|
|
168
|
+
version,
|
|
169
|
+
};
|
|
155
170
|
}
|
|
156
171
|
|
|
157
172
|
/**
|
|
158
|
-
*
|
|
173
|
+
* 检测破坏性变更:旧/新契约读取失败直接抛出(不再吞成「零变更」假绿)。
|
|
159
174
|
*/
|
|
160
175
|
private async detectBreakingChanges(
|
|
161
176
|
oldPath: string,
|
|
162
177
|
newPath: string
|
|
163
|
-
): Promise<
|
|
164
|
-
const changes:
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
});
|
|
182
|
-
}
|
|
178
|
+
): Promise<BreakingChange[]> {
|
|
179
|
+
const changes: BreakingChange[] = [];
|
|
180
|
+
|
|
181
|
+
const oldContent = await fs.readFile(oldPath, 'utf-8');
|
|
182
|
+
const newContent = await fs.readFile(newPath, 'utf-8');
|
|
183
|
+
|
|
184
|
+
// 提取端点列表
|
|
185
|
+
const oldEndpoints = this.extractEndpoints(oldContent);
|
|
186
|
+
const newEndpoints = this.extractEndpoints(newContent);
|
|
187
|
+
|
|
188
|
+
// 检查删除的端点
|
|
189
|
+
for (const endpoint of oldEndpoints) {
|
|
190
|
+
if (!newEndpoints.includes(endpoint)) {
|
|
191
|
+
changes.push({
|
|
192
|
+
type: 'endpoint_removed',
|
|
193
|
+
description: `端点 ${endpoint} 已删除`,
|
|
194
|
+
path: endpoint,
|
|
195
|
+
});
|
|
183
196
|
}
|
|
184
|
-
|
|
185
|
-
// 检查新增的端点(不是破坏性变更)
|
|
186
|
-
// 检查方法变更
|
|
187
|
-
// 简化实现,实际应该完整比较
|
|
188
|
-
|
|
189
|
-
return changes;
|
|
190
|
-
} catch {
|
|
191
|
-
return [];
|
|
192
197
|
}
|
|
198
|
+
|
|
199
|
+
return changes;
|
|
193
200
|
}
|
|
194
201
|
|
|
195
202
|
/**
|
package/src/gates/performance.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*
|
|
12
12
|
* 改进:
|
|
13
13
|
* - 添加超时机制
|
|
14
|
-
* -
|
|
14
|
+
* - 指标采集失败归入 warnings 展示(采集口径语义,见 collectCoverage)
|
|
15
15
|
* - 返回详细的错误信息
|
|
16
16
|
*/
|
|
17
17
|
|
|
@@ -27,6 +27,23 @@ const DEFAULT_TIMEOUTS = {
|
|
|
27
27
|
coverage: 120000, // 覆盖率测试:2分钟
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* 采集到的性能指标(采集失败的维度落在 *Error 字段,转 warnings 展示)
|
|
32
|
+
*/
|
|
33
|
+
interface PerformanceMetrics {
|
|
34
|
+
coverage?: number;
|
|
35
|
+
coverageError?: string;
|
|
36
|
+
bundleSize?: number;
|
|
37
|
+
bundleSizeError?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** exec/readFile 抛错对象上判定实际读取的字段 */
|
|
41
|
+
function execErrorField(error: unknown, field: 'code' | 'killed'): unknown {
|
|
42
|
+
return typeof error === 'object' && error !== null
|
|
43
|
+
? (error as Record<string, unknown>)[field]
|
|
44
|
+
: undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
30
47
|
/**
|
|
31
48
|
* 性能门禁配置
|
|
32
49
|
*/
|
|
@@ -107,7 +124,7 @@ export class PerformanceGate implements Gate {
|
|
|
107
124
|
warnings,
|
|
108
125
|
}
|
|
109
126
|
);
|
|
110
|
-
} catch (error:
|
|
127
|
+
} catch (error: unknown) {
|
|
111
128
|
return fromError('performance', '性能检查失败', error, startTime);
|
|
112
129
|
}
|
|
113
130
|
}
|
|
@@ -118,13 +135,8 @@ export class PerformanceGate implements Gate {
|
|
|
118
135
|
private async collectMetrics(
|
|
119
136
|
projectPath: string,
|
|
120
137
|
thresholds: PerformanceThresholds
|
|
121
|
-
): Promise<{
|
|
122
|
-
|
|
123
|
-
coverageError?: string;
|
|
124
|
-
bundleSize?: number;
|
|
125
|
-
bundleSizeError?: string;
|
|
126
|
-
}> {
|
|
127
|
-
const metrics: any = {};
|
|
138
|
+
): Promise<PerformanceMetrics> {
|
|
139
|
+
const metrics: PerformanceMetrics = {};
|
|
128
140
|
|
|
129
141
|
// 收集覆盖率(带超时)
|
|
130
142
|
if (thresholds.minCoverage) {
|
|
@@ -171,18 +183,22 @@ export class PerformanceGate implements Gate {
|
|
|
171
183
|
// 读取覆盖率报告
|
|
172
184
|
const coveragePath = path.join(projectPath, 'coverage', 'coverage-summary.json');
|
|
173
185
|
const content = await fs.readFile(coveragePath, 'utf-8');
|
|
174
|
-
const
|
|
186
|
+
const summary: unknown = JSON.parse(content);
|
|
187
|
+
const total = typeof summary === 'object' && summary !== null
|
|
188
|
+
? (summary as { total?: { lines?: { pct?: unknown } } }).total
|
|
189
|
+
: undefined;
|
|
190
|
+
const pct = total?.lines?.pct;
|
|
175
191
|
|
|
176
|
-
return { coverage:
|
|
177
|
-
} catch (error:
|
|
192
|
+
return { coverage: typeof pct === 'number' ? pct : 0 };
|
|
193
|
+
} catch (error: unknown) {
|
|
178
194
|
// 区分超时和其他错误
|
|
179
|
-
if (error
|
|
195
|
+
if (execErrorField(error, 'killed')) {
|
|
180
196
|
return { error: `覆盖率测试超时 (${this.config.coverageTimeout}ms)` };
|
|
181
197
|
}
|
|
182
|
-
if (error
|
|
198
|
+
if (execErrorField(error, 'code') === 'ENOENT') {
|
|
183
199
|
return { error: '未找到覆盖率报告文件' };
|
|
184
200
|
}
|
|
185
|
-
return { error: error.message
|
|
201
|
+
return { error: error instanceof Error ? error.message : '覆盖率测试失败' };
|
|
186
202
|
}
|
|
187
203
|
}
|
|
188
204
|
|
|
@@ -207,18 +223,18 @@ export class PerformanceGate implements Gate {
|
|
|
207
223
|
}
|
|
208
224
|
|
|
209
225
|
return { bundleSize: Math.round(totalSize / 1024) };
|
|
210
|
-
} catch (error:
|
|
211
|
-
if (error
|
|
226
|
+
} catch (error: unknown) {
|
|
227
|
+
if (execErrorField(error, 'code') === 'ENOENT') {
|
|
212
228
|
return { error: '未找到 dist 目录' };
|
|
213
229
|
}
|
|
214
|
-
return { error: error.message
|
|
230
|
+
return { error: error instanceof Error ? error.message : '打包大小检查失败' };
|
|
215
231
|
}
|
|
216
232
|
}
|
|
217
233
|
|
|
218
234
|
/**
|
|
219
235
|
* 格式化指标输出
|
|
220
236
|
*/
|
|
221
|
-
private formatMetrics(metrics:
|
|
237
|
+
private formatMetrics(metrics: PerformanceMetrics): string {
|
|
222
238
|
const parts: string[] = [];
|
|
223
239
|
if (metrics.coverage !== undefined) parts.push(`覆盖率=${metrics.coverage}%`);
|
|
224
240
|
if (metrics.bundleSize !== undefined) parts.push(`打包=${metrics.bundleSize}KB`);
|
package/src/gates/registry.ts
CHANGED
|
@@ -34,13 +34,16 @@ const IMPLEMENTATIONS: Gate[] = [
|
|
|
34
34
|
|
|
35
35
|
assertGateRegistryClosed(GATE_DEFINITIONS, IMPLEMENTATIONS);
|
|
36
36
|
|
|
37
|
+
const registry = new Map<string, Gate>(IMPLEMENTATIONS.map(g => [g.id, g]));
|
|
38
|
+
|
|
37
39
|
// 默认 order 以定义表为准(生效集层已删:config.yml 不再有 gates.order 覆盖口,ADR-0002「后续变更」)
|
|
38
40
|
for (const def of GATE_DEFINITIONS) {
|
|
39
|
-
|
|
41
|
+
// assertGateRegistryClosed 已保证定义必有实现;取不到即注册表闭环被破坏,fail-fast
|
|
42
|
+
const impl = registry.get(def.id);
|
|
43
|
+
if (!impl) throw new Error(`gate registry: 定义 ${def.id} 无实现(闭环校验后仍缺,不可能路径)`);
|
|
44
|
+
impl.order = def.order;
|
|
40
45
|
}
|
|
41
46
|
|
|
42
|
-
const registry = new Map<string, Gate>(IMPLEMENTATIONS.map(g => [g.id, g]));
|
|
43
|
-
|
|
44
47
|
/**
|
|
45
48
|
* 注册表闭环双向校验(加载期调用;测试用坏输入验证两个失败方向)
|
|
46
49
|
*
|
package/src/gates/review.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 审查门禁
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
4
|
* 检查代码审查状态:
|
|
5
5
|
* - 是否有足够的审批
|
|
6
6
|
* - 是否有变更请求
|
|
@@ -12,6 +12,34 @@ import { gateResult, fromError } from './types';
|
|
|
12
12
|
import type { GateResult, GateContext, ReviewGateConfig, Gate, GateDecision } from './types';
|
|
13
13
|
import { decisionFromResult } from './decision';
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* `gh pr view --json reviews,state` 的返回形状(只声明判定读取的字段)
|
|
17
|
+
*/
|
|
18
|
+
interface GhReview {
|
|
19
|
+
state?: string;
|
|
20
|
+
author?: { login?: string };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface GhPrView {
|
|
24
|
+
reviews?: GhReview[];
|
|
25
|
+
state?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* JSON.parse 结果 → GhPrView:不是对象即抛错(fail-fast,不拿畸形输出假评)
|
|
30
|
+
*/
|
|
31
|
+
function parsePrView(stdout: string): GhPrView {
|
|
32
|
+
const raw: unknown = JSON.parse(stdout);
|
|
33
|
+
if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
|
|
34
|
+
throw new Error('gh pr view 返回不是 JSON 对象');
|
|
35
|
+
}
|
|
36
|
+
const reviews = (raw as { reviews?: unknown }).reviews;
|
|
37
|
+
if (reviews !== undefined && !Array.isArray(reviews)) {
|
|
38
|
+
throw new Error('gh pr view 返回的 reviews 不是数组');
|
|
39
|
+
}
|
|
40
|
+
return raw as GhPrView;
|
|
41
|
+
}
|
|
42
|
+
|
|
15
43
|
/**
|
|
16
44
|
* 审查门禁
|
|
17
45
|
*/
|
|
@@ -50,7 +78,7 @@ export class ReviewGate implements Gate {
|
|
|
50
78
|
|
|
51
79
|
// 否则尝试从 git 获取
|
|
52
80
|
return this.checkLocalGit(context);
|
|
53
|
-
} catch (error:
|
|
81
|
+
} catch (error: unknown) {
|
|
54
82
|
return fromError('review', '审查检查失败', error, startTime);
|
|
55
83
|
}
|
|
56
84
|
}
|
|
@@ -68,16 +96,16 @@ export class ReviewGate implements Gate {
|
|
|
68
96
|
{ cwd: context.projectPath }
|
|
69
97
|
);
|
|
70
98
|
|
|
71
|
-
const pr =
|
|
72
|
-
const reviews = pr.reviews
|
|
99
|
+
const pr = parsePrView(stdout);
|
|
100
|
+
const reviews = pr.reviews ?? [];
|
|
73
101
|
|
|
74
102
|
// 统计审批和变更请求
|
|
75
|
-
const approvals = reviews.filter((r
|
|
76
|
-
const changesRequested = reviews.filter((r
|
|
77
|
-
const pending = reviews.filter((r
|
|
103
|
+
const approvals = reviews.filter((r) => r.state === 'APPROVED');
|
|
104
|
+
const changesRequested = reviews.filter((r) => r.state === 'CHANGES_REQUESTED');
|
|
105
|
+
const pending = reviews.filter((r) => r.state === 'PENDING' || r.state === 'COMMENTED');
|
|
78
106
|
|
|
79
107
|
// 检查是否满足条件
|
|
80
|
-
const passed =
|
|
108
|
+
const passed =
|
|
81
109
|
approvals.length >= this.config.minReviewers &&
|
|
82
110
|
(!this.config.blockOnChangesRequested || changesRequested.length === 0);
|
|
83
111
|
|
|
@@ -95,7 +123,7 @@ export class ReviewGate implements Gate {
|
|
|
95
123
|
minReviewers: this.config.minReviewers,
|
|
96
124
|
}
|
|
97
125
|
);
|
|
98
|
-
} catch (error:
|
|
126
|
+
} catch (error: unknown) {
|
|
99
127
|
// gh CLI 不可用或 PR 不存在
|
|
100
128
|
return fromError('review', '无法获取 PR 状态', error, startTime, {
|
|
101
129
|
suggestion: '确保已安装 gh CLI 并配置了 GitHub token',
|
|
@@ -138,7 +166,7 @@ export class ReviewGate implements Gate {
|
|
|
138
166
|
requireApproval: this.config.requireApproval,
|
|
139
167
|
}
|
|
140
168
|
);
|
|
141
|
-
} catch (error:
|
|
169
|
+
} catch (error: unknown) {
|
|
142
170
|
return fromError('review', 'Git 检查失败', error, startTime);
|
|
143
171
|
}
|
|
144
172
|
}
|
package/src/gates/security.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 安全门禁
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
4
|
* 检查安全漏洞:
|
|
5
5
|
* - npm audit
|
|
6
6
|
* - 依赖漏洞
|
|
7
7
|
* - 敏感信息泄露
|
|
8
|
+
*
|
|
9
|
+
* fail-fast:扫描输出必须是 npm audit 的 JSON;非 JSON 输出不再有
|
|
10
|
+
* 「正则抠数字」的文本兜底——解析失败直接抛出(外层归一为 deny 报告)。
|
|
8
11
|
*/
|
|
9
12
|
|
|
10
13
|
import { execAsync } from '../utils/exec';
|
|
@@ -12,6 +15,49 @@ import { gateResult, fromError } from './types';
|
|
|
12
15
|
import type { GateResult, GateContext, SecurityGateConfig, Gate, GateDecision } from './types';
|
|
13
16
|
import { decisionFromResult } from './decision';
|
|
14
17
|
|
|
18
|
+
/** 漏洞条目(报告 details 与 analyzeResult 共用形状) */
|
|
19
|
+
interface VulnerabilityEntry {
|
|
20
|
+
name: string;
|
|
21
|
+
severity: string;
|
|
22
|
+
via: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** 漏洞统计 */
|
|
26
|
+
interface VulnerabilityAnalysis {
|
|
27
|
+
critical: number;
|
|
28
|
+
high: number;
|
|
29
|
+
moderate: number;
|
|
30
|
+
low: number;
|
|
31
|
+
total: number;
|
|
32
|
+
vulnerabilities: VulnerabilityEntry[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** npm audit(旧版 audit.advisories 形状)单条 advisory 已读字段 */
|
|
36
|
+
interface NpmAdvisory {
|
|
37
|
+
name?: string;
|
|
38
|
+
severity?: string;
|
|
39
|
+
title?: string;
|
|
40
|
+
via?: Array<{ title?: string } | string>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** npm audit(v7+ vulnerabilities 形状)单条记录已读字段 */
|
|
44
|
+
interface NpmVulnerability {
|
|
45
|
+
name?: string;
|
|
46
|
+
severity?: string;
|
|
47
|
+
via?: Array<{ title?: string } | string>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
51
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** via 的首个来源标题(字符串直取,对象取 title) */
|
|
55
|
+
function viaTitle(via: NpmAdvisory['via']): string | undefined {
|
|
56
|
+
const first = via?.[0];
|
|
57
|
+
if (typeof first === 'string') return first;
|
|
58
|
+
return first?.title;
|
|
59
|
+
}
|
|
60
|
+
|
|
15
61
|
/**
|
|
16
62
|
* 安全门禁
|
|
17
63
|
*/
|
|
@@ -48,7 +94,7 @@ export class SecurityGate implements Gate {
|
|
|
48
94
|
// 三级优先级(自上而下取第一个「已提供」者):context 覆盖 > 构造配置 > 自动探测。
|
|
49
95
|
// 缺省(未给命令)落到 detectScanCommand()——本行曾因构造器兜空串而恒停在第二级(#138)。
|
|
50
96
|
const scanCommand = context.securityScanCommand ??
|
|
51
|
-
this.config.scanCommand ??
|
|
97
|
+
this.config.scanCommand ??
|
|
52
98
|
this.detectScanCommand(context.projectPath);
|
|
53
99
|
|
|
54
100
|
const result = await this.runScan(scanCommand, context.projectPath);
|
|
@@ -75,7 +121,7 @@ export class SecurityGate implements Gate {
|
|
|
75
121
|
scanCommand,
|
|
76
122
|
}
|
|
77
123
|
);
|
|
78
|
-
} catch (error:
|
|
124
|
+
} catch (error: unknown) {
|
|
79
125
|
return fromError('security', '安全扫描失败', error, startTime);
|
|
80
126
|
}
|
|
81
127
|
}
|
|
@@ -98,10 +144,10 @@ export class SecurityGate implements Gate {
|
|
|
98
144
|
maxBuffer: 10 * 1024 * 1024,
|
|
99
145
|
});
|
|
100
146
|
return stdout;
|
|
101
|
-
} catch (error:
|
|
147
|
+
} catch (error: unknown) {
|
|
102
148
|
// npm audit 发现漏洞时会返回非零退出码
|
|
103
149
|
// 但 stdout 仍然包含结果
|
|
104
|
-
if (error.stdout) {
|
|
150
|
+
if (isRecord(error) && typeof error.stdout === 'string') {
|
|
105
151
|
return error.stdout;
|
|
106
152
|
}
|
|
107
153
|
throw error;
|
|
@@ -109,82 +155,57 @@ export class SecurityGate implements Gate {
|
|
|
109
155
|
}
|
|
110
156
|
|
|
111
157
|
/**
|
|
112
|
-
*
|
|
158
|
+
* 分析扫描结果:只认 npm audit 的两种 JSON 形状(audit.advisories / vulnerabilities)。
|
|
159
|
+
* 输出不是合法 JSON 对象 → 抛错(不再有文本正则兜底)。
|
|
113
160
|
*/
|
|
114
|
-
private analyzeResult(output: string): {
|
|
115
|
-
critical: number;
|
|
116
|
-
high: number;
|
|
117
|
-
moderate: number;
|
|
118
|
-
low: number;
|
|
119
|
-
total: number;
|
|
120
|
-
vulnerabilities: Array<{
|
|
121
|
-
name: string;
|
|
122
|
-
severity: string;
|
|
123
|
-
via: string;
|
|
124
|
-
}>;
|
|
125
|
-
} {
|
|
161
|
+
private analyzeResult(output: string): VulnerabilityAnalysis {
|
|
126
162
|
let critical = 0;
|
|
127
163
|
let high = 0;
|
|
128
164
|
let moderate = 0;
|
|
129
165
|
let low = 0;
|
|
130
|
-
const vulnerabilities:
|
|
166
|
+
const vulnerabilities: VulnerabilityEntry[] = [];
|
|
167
|
+
|
|
168
|
+
const count = (severity: string): void => {
|
|
169
|
+
switch (severity) {
|
|
170
|
+
case 'critical': critical++; break;
|
|
171
|
+
case 'high': high++; break;
|
|
172
|
+
case 'moderate': moderate++; break;
|
|
173
|
+
default: low++;
|
|
174
|
+
}
|
|
175
|
+
};
|
|
131
176
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
vulnerabilities.push({
|
|
150
|
-
name: advisory.name || key,
|
|
151
|
-
severity,
|
|
152
|
-
via: advisory.via?.[0]?.title || advisory.title || 'Unknown',
|
|
153
|
-
});
|
|
154
|
-
}
|
|
177
|
+
const raw: unknown = JSON.parse(output);
|
|
178
|
+
if (!isRecord(raw)) {
|
|
179
|
+
throw new Error('安全扫描输出不是 JSON 对象');
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// npm audit 旧格式
|
|
183
|
+
if (isRecord(raw.audit)) {
|
|
184
|
+
const advisories = isRecord(raw.audit.advisories) ? raw.audit.advisories : {};
|
|
185
|
+
for (const [key, entry] of Object.entries(advisories)) {
|
|
186
|
+
const advisory = (isRecord(entry) ? entry : {}) as NpmAdvisory;
|
|
187
|
+
const severity = advisory.severity?.toLowerCase() ?? 'low';
|
|
188
|
+
count(severity);
|
|
189
|
+
vulnerabilities.push({
|
|
190
|
+
name: advisory.name ?? key,
|
|
191
|
+
severity,
|
|
192
|
+
via: viaTitle(advisory.via) ?? advisory.title ?? 'Unknown',
|
|
193
|
+
});
|
|
155
194
|
}
|
|
195
|
+
}
|
|
156
196
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
vulnerabilities.push({
|
|
171
|
-
name,
|
|
172
|
-
severity,
|
|
173
|
-
via: v.via?.[0]?.title || v.name || 'Unknown',
|
|
174
|
-
});
|
|
175
|
-
}
|
|
197
|
+
// 新版 npm audit 格式
|
|
198
|
+
if (isRecord(raw.vulnerabilities)) {
|
|
199
|
+
for (const [name, entry] of Object.entries(raw.vulnerabilities)) {
|
|
200
|
+
const vuln = (isRecord(entry) ? entry : {}) as NpmVulnerability;
|
|
201
|
+
const severity = vuln.severity?.toLowerCase() ?? 'low';
|
|
202
|
+
count(severity);
|
|
203
|
+
vulnerabilities.push({
|
|
204
|
+
name,
|
|
205
|
+
severity,
|
|
206
|
+
via: viaTitle(vuln.via) ?? vuln.name ?? 'Unknown',
|
|
207
|
+
});
|
|
176
208
|
}
|
|
177
|
-
} catch {
|
|
178
|
-
// 解析失败,尝试从文本提取
|
|
179
|
-
const criticalMatch = output.match(/(\d+) critical/i);
|
|
180
|
-
const highMatch = output.match(/(\d+) high/i);
|
|
181
|
-
const moderateMatch = output.match(/(\d+) moderate/i);
|
|
182
|
-
const lowMatch = output.match(/(\d+) low/i);
|
|
183
|
-
|
|
184
|
-
critical = criticalMatch ? parseInt(criticalMatch[1], 10) : 0;
|
|
185
|
-
high = highMatch ? parseInt(highMatch[1], 10) : 0;
|
|
186
|
-
moderate = moderateMatch ? parseInt(moderateMatch[1], 10) : 0;
|
|
187
|
-
low = lowMatch ? parseInt(lowMatch[1], 10) : 0;
|
|
188
209
|
}
|
|
189
210
|
|
|
190
211
|
return {
|
|
@@ -200,13 +221,7 @@ export class SecurityGate implements Gate {
|
|
|
200
221
|
/**
|
|
201
222
|
* 判断是否通过
|
|
202
223
|
*/
|
|
203
|
-
private isPassed(analysis: {
|
|
204
|
-
critical: number;
|
|
205
|
-
high: number;
|
|
206
|
-
moderate: number;
|
|
207
|
-
low: number;
|
|
208
|
-
total: number;
|
|
209
|
-
}): boolean {
|
|
224
|
+
private isPassed(analysis: VulnerabilityAnalysis): boolean {
|
|
210
225
|
// 根据严重程度阈值判断
|
|
211
226
|
switch (this.config.severityThreshold) {
|
|
212
227
|
case 'critical':
|
|
@@ -217,8 +232,6 @@ export class SecurityGate implements Gate {
|
|
|
217
232
|
return analysis.critical === 0 && analysis.high === 0 && analysis.moderate === 0;
|
|
218
233
|
case 'low':
|
|
219
234
|
return analysis.total === 0;
|
|
220
|
-
default:
|
|
221
|
-
return analysis.critical === 0 && analysis.high === 0;
|
|
222
235
|
}
|
|
223
236
|
}
|
|
224
237
|
|