@dommaker/harness 0.13.0 → 0.13.2
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 +169 -0
- package/bin/harness-knowledge-capture.js +99 -0
- package/bin/harness-knowledge-check.js +149 -0
- package/bin/harness-knowledge-track.js +92 -0
- package/bin/harness-knowledge-track.sh +47 -0
- package/bin/harness-sensitive-check.sh +67 -0
- package/dist/cli/commands/init.js +34 -2
- package/dist/cli/commands/init.js.map +1 -1
- package/package.json +6 -3
- package/src/CONTEXT.md +34 -0
- package/src/__tests__/acceptance-gate.test.ts +364 -0
- package/src/__tests__/annotation-checker.test.ts +183 -0
- package/src/__tests__/architecture-engine.test.ts +619 -0
- package/src/__tests__/checker-extra.test.ts +1627 -0
- package/src/__tests__/checker.test.ts +1268 -0
- package/src/__tests__/checkpoint.test.ts +697 -0
- package/src/__tests__/clean-state-extra.test.ts +301 -0
- package/src/__tests__/clean-state.test.ts +169 -0
- package/src/__tests__/constraint-doctor.test.ts +410 -0
- package/src/__tests__/constraint-evolver.test.ts +404 -0
- package/src/__tests__/constraint-handler.test.ts +136 -0
- package/src/__tests__/context/progressive-loader.test.ts +131 -0
- package/src/__tests__/contract-gate.test.ts +321 -0
- package/src/__tests__/cross-project-checker.test.ts +318 -0
- package/src/__tests__/cso-validator.test.ts +205 -0
- package/src/__tests__/detect-source-roots.test.ts +98 -0
- package/src/__tests__/doctor-evolver.test.ts +381 -0
- package/src/__tests__/error-classifier.test.ts +304 -0
- package/src/__tests__/exec.test.ts +83 -0
- package/src/__tests__/extend-exceptions.test.ts +149 -0
- package/src/__tests__/failure-recorder.test.ts +335 -0
- package/src/__tests__/hooks-pipeline.test.ts +214 -0
- package/src/__tests__/interceptor.test.ts +89 -0
- package/src/__tests__/iron-laws.test.ts +246 -0
- package/src/__tests__/long-running.test.ts +17 -0
- package/src/__tests__/passes-gate-check.test.ts +138 -0
- package/src/__tests__/passes-gate-extension.test.ts +151 -0
- package/src/__tests__/passes-gate-extra.test.ts +238 -0
- package/src/__tests__/passes-gate.test.ts +231 -0
- package/src/__tests__/performance-analyzer.test.ts +501 -0
- package/src/__tests__/performance-collector.test.ts +276 -0
- package/src/__tests__/performance-gate.test.ts +74 -0
- package/src/__tests__/presets.test.ts +104 -0
- package/src/__tests__/project-config-loader-extra.test.ts +269 -0
- package/src/__tests__/project-config-loader.test.ts +127 -0
- package/src/__tests__/review-gate.test.ts +92 -0
- package/src/__tests__/security-gate.test.ts +100 -0
- package/src/__tests__/session-startup.test.ts +334 -0
- package/src/__tests__/spec-validator.test.ts +57 -0
- package/src/__tests__/token-budget.test.ts +252 -0
- package/src/__tests__/trace-analyzer-extra.test.ts +307 -0
- package/src/__tests__/trace-analyzer.test.ts +131 -0
- package/src/__tests__/trace-collector.test.ts +258 -0
- package/src/__tests__/traces.test.ts +347 -0
- package/src/agents/CONTEXT.md +21 -0
- package/src/agents/__tests__/lifecycle.test.ts +248 -0
- package/src/agents/index.ts +2 -0
- package/src/agents/lifecycle.ts +201 -0
- package/src/agents/types.ts +46 -0
- package/src/architecture/CONTEXT.md +22 -0
- package/src/architecture/constraint-engine.ts +356 -0
- package/src/architecture/cross-project-checker.ts +563 -0
- package/src/cli/commands/CONTEXT.md +24 -0
- package/src/cli/commands/__tests__/acceptance.test.ts +180 -0
- package/src/cli/commands/__tests__/check.test.ts +598 -0
- package/src/cli/commands/__tests__/command.test.ts +149 -0
- package/src/cli/commands/__tests__/contract.test.ts +151 -0
- package/src/cli/commands/__tests__/failure.test.ts +199 -0
- package/src/cli/commands/__tests__/flow.test.ts +343 -0
- package/src/cli/commands/__tests__/init.test.ts +306 -0
- package/src/cli/commands/__tests__/passes-gate.test.ts +256 -0
- package/src/cli/commands/__tests__/performance.test.ts +116 -0
- package/src/cli/commands/__tests__/posteval-plan.test.ts +201 -0
- package/src/cli/commands/__tests__/report-extra.test.ts +98 -0
- package/src/cli/commands/__tests__/report.test.ts +109 -0
- package/src/cli/commands/__tests__/review.test.ts +153 -0
- package/src/cli/commands/__tests__/security.test.ts +147 -0
- package/src/cli/commands/__tests__/spec.test.ts +193 -0
- package/src/cli/commands/__tests__/status-extra.test.ts +223 -0
- package/src/cli/commands/__tests__/status.test.ts +306 -0
- package/src/cli/commands/__tests__/sync-docs.test.ts +335 -0
- package/src/cli/commands/__tests__/validate.test.ts +139 -0
- package/src/cli/commands/acceptance.ts +111 -0
- package/src/cli/commands/analyze-sessions.ts +488 -0
- package/src/cli/commands/check.ts +441 -0
- package/src/cli/commands/command.ts +90 -0
- package/src/cli/commands/constraints.ts +86 -0
- package/src/cli/commands/contract.ts +168 -0
- package/src/cli/commands/failure.ts +117 -0
- package/src/cli/commands/flow.ts +275 -0
- package/src/cli/commands/index.ts +26 -0
- package/src/cli/commands/init.ts +832 -0
- package/src/cli/commands/knowledge.ts +391 -0
- package/src/cli/commands/passes-gate.ts +158 -0
- package/src/cli/commands/performance.ts +108 -0
- package/src/cli/commands/posteval-plan.ts +85 -0
- package/src/cli/commands/release.ts +159 -0
- package/src/cli/commands/report.ts +198 -0
- package/src/cli/commands/review.ts +118 -0
- package/src/cli/commands/security.ts +122 -0
- package/src/cli/commands/spec.ts +158 -0
- package/src/cli/commands/status.ts +169 -0
- package/src/cli/commands/sync-docs.ts +743 -0
- package/src/cli/commands/update-user-model.ts +527 -0
- package/src/cli/commands/validate.ts +222 -0
- package/src/constraints/__tests__/lifecycle-runner.test.ts +246 -0
- package/src/constraints/__tests__/registry.test.ts +196 -0
- package/src/constraints/index.ts +3 -0
- package/src/constraints/lifecycle-runner.ts +184 -0
- package/src/constraints/registry.ts +134 -0
- package/src/constraints/types.ts +59 -0
- package/src/context/CONTEXT.md +28 -0
- package/src/context/__tests__/compaction.test.ts +169 -0
- package/src/context/__tests__/file-budget.test.ts +142 -0
- package/src/context/__tests__/knowledge-injector.test.ts +148 -0
- package/src/context/__tests__/progressive-loader.test.ts +264 -0
- package/src/context/__tests__/session-manager.test.ts +300 -0
- package/src/context/__tests__/token-budget.test.ts +338 -0
- package/src/context/__tests__/token-pipeline.test.ts +178 -0
- package/src/context/__tests__/tool-output-budget.test.ts +95 -0
- package/src/context/compaction.ts +202 -0
- package/src/context/file-budget.ts +142 -0
- package/src/context/index.ts +15 -0
- package/src/context/knowledge-injector.ts +168 -0
- package/src/context/progressive-loader.ts +260 -0
- package/src/context/session-manager.ts +343 -0
- package/src/context/token-budget.ts +295 -0
- package/src/context/token-pipeline.ts +265 -0
- package/src/context/tool-output-budget.ts +178 -0
- package/src/context/types.ts +160 -0
- package/src/core/CONTEXT.md +26 -0
- package/src/core/constraints/__tests__/default-executors.test.ts +57 -0
- package/src/core/constraints/__tests__/interceptor.test.ts +251 -0
- package/src/core/constraints/__tests__/prompt-injection.test.ts +89 -0
- package/src/core/constraints/check-cache.ts +96 -0
- package/src/core/constraints/checker.ts +1169 -0
- package/src/core/constraints/default-executors.ts +92 -0
- package/src/core/constraints/definitions.ts +1119 -0
- package/src/core/constraints/doc-freshness/__tests__/runner.test.ts +551 -0
- package/src/core/constraints/doc-freshness/auto-fix.ts +69 -0
- package/src/core/constraints/doc-freshness/runner.ts +486 -0
- package/src/core/constraints/index.ts +78 -0
- package/src/core/constraints/interceptor.ts +220 -0
- package/src/core/constraints/prompt-injection.ts +73 -0
- package/src/core/index.ts +23 -0
- package/src/core/project-config-loader.ts +252 -0
- package/src/core/session/__tests__/startup.test.ts +281 -0
- package/src/core/session/clean-state.ts +178 -0
- package/src/core/session/index.ts +15 -0
- package/src/core/session/startup.ts +253 -0
- package/src/core/spec/__tests__/validator.test.ts +379 -0
- package/src/core/spec/index.ts +7 -0
- package/src/core/spec/validator.ts +383 -0
- package/src/core/validators/__tests__/passes-gate.test.ts +131 -0
- package/src/core/validators/checkpoint.ts +547 -0
- package/src/core/validators/cso.ts +124 -0
- package/src/core/validators/index.ts +25 -0
- package/src/core/validators/passes-gate.ts +613 -0
- package/src/dashboard/CONTEXT.md +21 -0
- package/src/dashboard/__tests__/data.test.ts +115 -0
- package/src/dashboard/__tests__/stats.test.ts +156 -0
- package/src/dashboard/data.ts +113 -0
- package/src/dashboard/index.ts +3 -0
- package/src/dashboard/stats.ts +127 -0
- package/src/dashboard/types.ts +113 -0
- package/src/evolution/CONTEXT.md +22 -0
- package/src/evolution/__tests__/auto-evolve.test.ts +320 -0
- package/src/evolution/auto-evolve.ts +98 -0
- package/src/evolution/index.ts +1 -0
- package/src/failure/CONTEXT.md +24 -0
- package/src/failure/classifier.ts +156 -0
- package/src/failure/constraint-handler.ts +173 -0
- package/src/failure/index.ts +35 -0
- package/src/failure/recorder.ts +201 -0
- package/src/failure/types.ts +165 -0
- package/src/gates/CONTEXT.md +27 -0
- package/src/gates/__tests__/acceptance.test.ts +608 -0
- package/src/gates/__tests__/command.test.ts +206 -0
- package/src/gates/__tests__/performance.test.ts +381 -0
- package/src/gates/__tests__/review.test.ts +302 -0
- package/src/gates/__tests__/security.test.ts +332 -0
- package/src/gates/acceptance.ts +493 -0
- package/src/gates/command.ts +444 -0
- package/src/gates/contract.ts +260 -0
- package/src/gates/index.ts +67 -0
- package/src/gates/performance.ts +359 -0
- package/src/gates/review.ts +169 -0
- package/src/gates/security.ts +244 -0
- package/src/gates/types.ts +159 -0
- package/src/governance/CONTEXT.md +22 -0
- package/src/governance/__tests__/executor.test.ts +249 -0
- package/src/governance/executor.ts +229 -0
- package/src/governance/index.ts +13 -0
- package/src/governance/types.ts +53 -0
- package/src/hooks/CONTEXT.md +23 -0
- package/src/hooks/__tests__/bootstrap.test.ts +184 -0
- package/src/hooks/bootstrap.ts +144 -0
- package/src/hooks/index.ts +15 -0
- package/src/hooks/pipeline.ts +157 -0
- package/src/hooks/registry.ts +88 -0
- package/src/hooks/types.ts +80 -0
- package/src/index.ts +198 -0
- package/src/knowledge/CONTEXT.md +29 -0
- package/src/knowledge/__tests__/doctor.test.ts +272 -0
- package/src/knowledge/__tests__/import.test.ts +376 -0
- package/src/knowledge/__tests__/ingest.test.ts +125 -0
- package/src/knowledge/__tests__/lifecycle-hooks.test.ts +137 -0
- package/src/knowledge/__tests__/lifecycle.test.ts +248 -0
- package/src/knowledge/__tests__/lint.test.ts +401 -0
- package/src/knowledge/__tests__/query.test.ts +185 -0
- package/src/knowledge/__tests__/reference-tracker.test.ts +129 -0
- package/src/knowledge/__tests__/store.test.ts +238 -0
- package/src/knowledge/doctor.ts +104 -0
- package/src/knowledge/import.ts +505 -0
- package/src/knowledge/index.ts +16 -0
- package/src/knowledge/ingest.ts +126 -0
- package/src/knowledge/lifecycle-hooks.ts +199 -0
- package/src/knowledge/lifecycle.ts +175 -0
- package/src/knowledge/lint.ts +360 -0
- package/src/knowledge/query.ts +150 -0
- package/src/knowledge/reference-tracker.ts +99 -0
- package/src/knowledge/store.ts +264 -0
- package/src/knowledge/types.ts +139 -0
- package/src/llm/CONTEXT.md +21 -0
- package/src/llm/__tests__/adapter.test.ts +172 -0
- package/src/llm/adapter.ts +149 -0
- package/src/llm/index.ts +2 -0
- package/src/llm/types.ts +81 -0
- package/src/monitoring/CONTEXT.md +29 -0
- package/src/monitoring/__tests__/context-tracker.test.ts +172 -0
- package/src/monitoring/__tests__/knowledge-doctor.test.ts +276 -0
- package/src/monitoring/__tests__/knowledge-evolver.test.ts +365 -0
- package/src/monitoring/__tests__/performance-analyzer.test.ts +137 -0
- package/src/monitoring/__tests__/performance-collector.test.ts +332 -0
- package/src/monitoring/__tests__/traces.test.ts +190 -0
- package/src/monitoring/constraint-doctor.ts +499 -0
- package/src/monitoring/constraint-evolver.ts +573 -0
- package/src/monitoring/context-tracker.ts +148 -0
- package/src/monitoring/index.ts +23 -0
- package/src/monitoring/knowledge-doctor.ts +323 -0
- package/src/monitoring/knowledge-evolver.ts +289 -0
- package/src/monitoring/performance-analyzer.ts +450 -0
- package/src/monitoring/performance-collector.ts +348 -0
- package/src/monitoring/trace-analyzer.ts +470 -0
- package/src/monitoring/traces.ts +339 -0
- package/src/presets/__tests__/standard.test.ts +104 -0
- package/src/presets/index.ts +16 -0
- package/src/presets/standard.ts +163 -0
- package/src/safety/CONTEXT.md +23 -0
- package/src/safety/__tests__/input-guardrail.test.ts +105 -0
- package/src/safety/__tests__/output-guardrail.test.ts +108 -0
- package/src/safety/__tests__/sandbox.test.ts +158 -0
- package/src/safety/__tests__/tool-guardrail.test.ts +127 -0
- package/src/safety/index.ts +5 -0
- package/src/safety/input-guardrail.ts +133 -0
- package/src/safety/output-guardrail.ts +174 -0
- package/src/safety/sandbox.ts +148 -0
- package/src/safety/tool-guardrail.ts +176 -0
- package/src/safety/types.ts +124 -0
- package/src/spec/CONTEXT.md +19 -0
- package/src/spec/__tests__/annotation-checker.test.ts +289 -0
- package/src/spec/annotation-checker.ts +342 -0
- package/src/tools/CONTEXT.md +25 -0
- package/src/tools/__tests__/loader.test.ts +252 -0
- package/src/tools/__tests__/registry.test.ts +157 -0
- package/src/tools/core/__tests__/core.test.ts +122 -0
- package/src/tools/core/index.ts +201 -0
- package/src/tools/core/package.json +7 -0
- package/src/tools/core/pnpm-lock.yaml +232 -0
- package/src/tools/definitions/core/code/fingerprint.sh +273 -0
- package/src/tools/definitions/core/code/fingerprint.yml +72 -0
- package/src/tools/definitions/core/code/parse.yml +68 -0
- package/src/tools/definitions/core/code/register-language.sh +475 -0
- package/src/tools/definitions/core/code/register-language.yml +74 -0
- package/src/tools/definitions/core/docker/build.yml +73 -0
- package/src/tools/definitions/core/docker/run.yml +81 -0
- package/src/tools/definitions/core/file/copy.yml +88 -0
- package/src/tools/definitions/core/file/read.yml +69 -0
- package/src/tools/definitions/core/file/write.yml +75 -0
- package/src/tools/definitions/core/git/branch.yml +61 -0
- package/src/tools/definitions/core/git/cleanup-worktree.yml +50 -0
- package/src/tools/definitions/core/git/clone.yml +69 -0
- package/src/tools/definitions/core/git/commit.yml +65 -0
- package/src/tools/definitions/core/git/push.yml +79 -0
- package/src/tools/definitions/core/git/worktree.yml +96 -0
- package/src/tools/definitions/core/notification/notify.sh +152 -0
- package/src/tools/definitions/core/notification/notify.yml +60 -0
- package/src/tools/definitions/core/npm/build.yml +75 -0
- package/src/tools/definitions/core/npm/install.yml +58 -0
- package/src/tools/definitions/core/npm/test.yml +75 -0
- package/src/tools/definitions/core/validation/check-reuse.yml +170 -0
- package/src/tools/definitions/core/validation/validate-handlers.yml +118 -0
- package/src/tools/definitions/core/validation/validate-readme-stats.yml +155 -0
- package/src/tools/definitions/core/validation/validate-yaml-syntax.yml +134 -0
- package/src/tools/definitions/ext/browser/browser-automate.sh +255 -0
- package/src/tools/definitions/ext/browser/browser-automate.yml +166 -0
- package/src/tools/definitions/ext/browser/browser-close.sh +104 -0
- package/src/tools/definitions/ext/browser/browser-close.yml +55 -0
- package/src/tools/definitions/ext/browser/browser-mcp-debug.sh +682 -0
- package/src/tools/definitions/ext/browser/browser-mcp-debug.yml +167 -0
- package/src/tools/definitions/ext/browser/browser-start.sh +101 -0
- package/src/tools/definitions/ext/browser/browser-start.yml +62 -0
- package/src/tools/definitions/registry.json +795 -0
- package/src/tools/definitions/std/README.md +350 -0
- package/src/tools/definitions/std/analysis/analyze-codebase.yml +72 -0
- package/src/tools/definitions/std/analysis/analyze-diff.yml +182 -0
- package/src/tools/definitions/std/analysis/analyze-git-diff.yml +70 -0
- package/src/tools/definitions/std/analysis/analyze-impact.yml +78 -0
- package/src/tools/definitions/std/analysis/analyze-requirements.yml +105 -0
- package/src/tools/definitions/std/analysis/brainstorm-options.yml +106 -0
- package/src/tools/definitions/std/analysis/build-graph.yml +154 -0
- package/src/tools/definitions/std/analysis/clarify-requirements.yml +90 -0
- package/src/tools/definitions/std/analysis/detect-context.yml +109 -0
- package/src/tools/definitions/std/analysis/detect-layers.yml +125 -0
- package/src/tools/definitions/std/analysis/generate-tour.yml +102 -0
- package/src/tools/definitions/std/analysis/search-enhance.yml +105 -0
- package/src/tools/definitions/std/backlog/add.yml +51 -0
- package/src/tools/definitions/std/backlog/decide.yml +39 -0
- package/src/tools/definitions/std/backlog/github-sync.yml +161 -0
- package/src/tools/definitions/std/backlog/list.yml +53 -0
- package/src/tools/definitions/std/backlog/load.yml +46 -0
- package/src/tools/definitions/std/backlog/resolve.yml +37 -0
- package/src/tools/definitions/std/backlog/update.yml +42 -0
- package/src/tools/definitions/std/bugfix/diagnose.yml +68 -0
- package/src/tools/definitions/std/bugfix/fix.yml +66 -0
- package/src/tools/definitions/std/bugfix/verify.yml +69 -0
- package/src/tools/definitions/std/constraint/check-decomposition.yml +103 -0
- package/src/tools/definitions/std/constraint/check-feature-list.yml +77 -0
- package/src/tools/definitions/std/constraint/check-progress.yml +97 -0
- package/src/tools/definitions/std/constraint/generate-report.yml +147 -0
- package/src/tools/definitions/std/deploy/commit-push.yml +33 -0
- package/src/tools/definitions/std/deploy/deploy-backend.yml +37 -0
- package/src/tools/definitions/std/deploy/deploy-frontend.yml +37 -0
- package/src/tools/definitions/std/deploy/rollback.yml +148 -0
- package/src/tools/definitions/std/design/analyze-architecture-impact.yml +113 -0
- package/src/tools/definitions/std/design/design-api.yml +55 -0
- package/src/tools/definitions/std/design/design-architecture.yml +97 -0
- package/src/tools/definitions/std/design/design-db.yml +81 -0
- package/src/tools/definitions/std/design/generate-spec.yml +182 -0
- package/src/tools/definitions/std/development/develop-api.yml +85 -0
- package/src/tools/definitions/std/development/develop-backend.yml +88 -0
- package/src/tools/definitions/std/development/develop-frontend.yml +87 -0
- package/src/tools/definitions/std/development/develop-shared-types.yml +74 -0
- package/src/tools/definitions/std/development/develop-task.yml +122 -0
- package/src/tools/definitions/std/development/develop-tests.yml +76 -0
- package/src/tools/definitions/std/development/execute-batch.yml +152 -0
- package/src/tools/definitions/std/development/fix-issues.yml +100 -0
- package/src/tools/definitions/std/development/implement-task.yml +124 -0
- package/src/tools/definitions/std/development/review-fix-cycle.yml +232 -0
- package/src/tools/definitions/std/evolution/implement.yml +125 -0
- package/src/tools/definitions/std/evolution/prioritize.yml +112 -0
- package/src/tools/definitions/std/evolution/report-gap.yml +166 -0
- package/src/tools/definitions/std/file/read.yml +21 -0
- package/src/tools/definitions/std/governance/aggregate-opinions.sh +201 -0
- package/src/tools/definitions/std/governance/aggregate-opinions.yml +79 -0
- package/src/tools/definitions/std/governance/audit-task.yml +178 -0
- package/src/tools/definitions/std/governance/cast-vote.yml +129 -0
- package/src/tools/definitions/std/governance/collect-issues.yml +16 -0
- package/src/tools/definitions/std/governance/create-signed-document.yml +23 -0
- package/src/tools/definitions/std/governance/create-voting-session.yml +101 -0
- package/src/tools/definitions/std/governance/define-stance.sh +243 -0
- package/src/tools/definitions/std/governance/define-stance.yml +82 -0
- package/src/tools/definitions/std/governance/generate-review-report.yml +23 -0
- package/src/tools/definitions/std/governance/impeach.yml +179 -0
- package/src/tools/definitions/std/governance/multi-stance-review.yml +154 -0
- package/src/tools/definitions/std/governance/prepare-artifact.yml +20 -0
- package/src/tools/definitions/std/governance/review-spec-approval.yml +262 -0
- package/src/tools/definitions/std/governance/rollback.yml +186 -0
- package/src/tools/definitions/std/governance/stance-review.yml +149 -0
- package/src/tools/definitions/std/governance/track-effect.yml +199 -0
- package/src/tools/definitions/std/governance/vote-tally.yml +144 -0
- package/src/tools/definitions/std/patch/execute.yml +51 -0
- package/src/tools/definitions/std/planning/generate-tasks.yml +36 -0
- package/src/tools/definitions/std/planning/load-tasks.yml +44 -0
- package/src/tools/definitions/std/planning/split-batch.yml +481 -0
- package/src/tools/definitions/std/planning/split-tasks.yml +359 -0
- package/src/tools/definitions/std/planning/update-tasks.yml +51 -0
- package/src/tools/definitions/std/planning/validate-tasks.yml +46 -0
- package/src/tools/definitions/std/project/decide-next-workflow.yml +38 -0
- package/src/tools/definitions/std/project/load-state.yml +31 -0
- package/src/tools/definitions/std/project/save-state.yml +32 -0
- package/src/tools/definitions/std/quality/check-quality.yml +241 -0
- package/src/tools/definitions/std/quality/debug-systematic.yml +163 -0
- package/src/tools/definitions/std/quality/handle-feedback.yml +108 -0
- package/src/tools/definitions/std/quality/review-code.yml +128 -0
- package/src/tools/definitions/std/quality/review-spec.yml +140 -0
- package/src/tools/definitions/std/quality/review-task.yml +190 -0
- package/src/tools/definitions/std/quality/run-tests.yml +80 -0
- package/src/tools/definitions/std/quick/analyze.yml +56 -0
- package/src/tools/definitions/std/quick/implement.yml +67 -0
- package/src/tools/definitions/std/quick/verify.yml +71 -0
- package/src/tools/definitions/std/verification/verify_completion.yml +113 -0
- package/src/tools/definitions/std/verification/wait-condition.yml +107 -0
- package/src/tools/index.ts +5 -0
- package/src/tools/loader.ts +216 -0
- package/src/tools/paths.ts +15 -0
- package/src/tools/registry.ts +128 -0
- package/src/tools/types.ts +46 -0
- package/src/types/__tests__/types.test.ts +86 -0
- package/src/types/checkpoint.ts +174 -0
- package/src/types/constraint.ts +335 -0
- package/src/types/cso.ts +37 -0
- package/src/types/enforcement.ts +48 -0
- package/src/types/index.ts +59 -0
- package/src/types/iron-law.ts +50 -0
- package/src/types/passes-gate.ts +185 -0
- package/src/types/performance.ts +295 -0
- package/src/types/project-config.ts +251 -0
- package/src/types/session.ts +132 -0
- package/src/types/spec.ts +91 -0
- package/src/types/trace.ts +228 -0
- package/src/utils/detect-source-roots.ts +114 -0
- package/src/utils/exec.ts +61 -0
- package/src/verification/CONTEXT.md +23 -0
- package/src/verification/__tests__/loop.test.ts +303 -0
- package/src/verification/__tests__/rules-based.test.ts +240 -0
- package/src/verification/index.ts +3 -0
- package/src/verification/loop.ts +137 -0
- package/src/verification/rules-based.ts +153 -0
- package/src/verification/types.ts +81 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 安全门禁
|
|
3
|
+
*
|
|
4
|
+
* 检查安全漏洞:
|
|
5
|
+
* - npm audit
|
|
6
|
+
* - 依赖漏洞
|
|
7
|
+
* - 敏感信息泄露
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { execAsync } from '../utils/exec';
|
|
11
|
+
import * as fs from 'fs/promises';
|
|
12
|
+
import * as path from 'path';
|
|
13
|
+
import type { GateResult, GateContext, SecurityGateConfig } from './types';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 安全门禁
|
|
17
|
+
*/
|
|
18
|
+
export class SecurityGate {
|
|
19
|
+
private config: Required<SecurityGateConfig>;
|
|
20
|
+
|
|
21
|
+
constructor(config: Partial<SecurityGateConfig> = {}) {
|
|
22
|
+
this.config = {
|
|
23
|
+
enabled: config.enabled ?? true,
|
|
24
|
+
scanCommand: config.scanCommand ?? '',
|
|
25
|
+
ignoreWarnings: config.ignoreWarnings ?? false,
|
|
26
|
+
ignoreDevDependencies: config.ignoreDevDependencies ?? false,
|
|
27
|
+
severityThreshold: config.severityThreshold ?? 'high',
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 扫描安全漏洞
|
|
33
|
+
*/
|
|
34
|
+
async scan(context: GateContext): Promise<GateResult> {
|
|
35
|
+
const startTime = Date.now();
|
|
36
|
+
|
|
37
|
+
if (!this.config.enabled) {
|
|
38
|
+
return {
|
|
39
|
+
gate: 'security',
|
|
40
|
+
passed: true,
|
|
41
|
+
message: '安全门禁已禁用',
|
|
42
|
+
timestamp: new Date().toISOString(),
|
|
43
|
+
duration: Date.now() - startTime,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
// 使用自定义命令或默认 npm audit
|
|
49
|
+
const scanCommand = context.securityScanCommand ??
|
|
50
|
+
this.config.scanCommand ??
|
|
51
|
+
this.detectScanCommand(context.projectPath);
|
|
52
|
+
|
|
53
|
+
const result = await this.runScan(scanCommand, context.projectPath);
|
|
54
|
+
|
|
55
|
+
// 分析结果
|
|
56
|
+
const analysis = this.analyzeResult(result);
|
|
57
|
+
|
|
58
|
+
const passed = this.isPassed(analysis);
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
gate: 'security',
|
|
62
|
+
passed,
|
|
63
|
+
message: passed
|
|
64
|
+
? '安全扫描通过'
|
|
65
|
+
: `发现 ${analysis.critical} 个严重漏洞, ${analysis.high} 个高危漏洞`,
|
|
66
|
+
details: {
|
|
67
|
+
critical: analysis.critical,
|
|
68
|
+
high: analysis.high,
|
|
69
|
+
moderate: analysis.moderate,
|
|
70
|
+
low: analysis.low,
|
|
71
|
+
total: analysis.total,
|
|
72
|
+
vulnerabilities: analysis.vulnerabilities.slice(0, 10), // 只返回前 10 个
|
|
73
|
+
scanCommand,
|
|
74
|
+
},
|
|
75
|
+
timestamp: new Date().toISOString(),
|
|
76
|
+
duration: Date.now() - startTime,
|
|
77
|
+
};
|
|
78
|
+
} catch (error: any) {
|
|
79
|
+
return {
|
|
80
|
+
gate: 'security',
|
|
81
|
+
passed: false,
|
|
82
|
+
message: `安全扫描失败: ${error.message}`,
|
|
83
|
+
timestamp: new Date().toISOString(),
|
|
84
|
+
duration: Date.now() - startTime,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* 检测扫描命令
|
|
91
|
+
*/
|
|
92
|
+
private detectScanCommand(projectPath: string): string {
|
|
93
|
+
// 默认使用 npm audit
|
|
94
|
+
return 'npm audit --json';
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 运行扫描
|
|
99
|
+
*/
|
|
100
|
+
private async runScan(command: string, projectPath: string): Promise<string> {
|
|
101
|
+
try {
|
|
102
|
+
const { stdout } = await execAsync(command, {
|
|
103
|
+
cwd: projectPath,
|
|
104
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
105
|
+
});
|
|
106
|
+
return stdout;
|
|
107
|
+
} catch (error: any) {
|
|
108
|
+
// npm audit 发现漏洞时会返回非零退出码
|
|
109
|
+
// 但 stdout 仍然包含结果
|
|
110
|
+
if (error.stdout) {
|
|
111
|
+
return error.stdout;
|
|
112
|
+
}
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 分析扫描结果
|
|
119
|
+
*/
|
|
120
|
+
private analyzeResult(output: string): {
|
|
121
|
+
critical: number;
|
|
122
|
+
high: number;
|
|
123
|
+
moderate: number;
|
|
124
|
+
low: number;
|
|
125
|
+
total: number;
|
|
126
|
+
vulnerabilities: Array<{
|
|
127
|
+
name: string;
|
|
128
|
+
severity: string;
|
|
129
|
+
via: string;
|
|
130
|
+
}>;
|
|
131
|
+
} {
|
|
132
|
+
let critical = 0;
|
|
133
|
+
let high = 0;
|
|
134
|
+
let moderate = 0;
|
|
135
|
+
let low = 0;
|
|
136
|
+
const vulnerabilities: Array<{ name: string; severity: string; via: string }> = [];
|
|
137
|
+
|
|
138
|
+
try {
|
|
139
|
+
const result = JSON.parse(output);
|
|
140
|
+
|
|
141
|
+
// npm audit 格式
|
|
142
|
+
if (result.audit) {
|
|
143
|
+
const advisories = result.audit.advisories || {};
|
|
144
|
+
for (const key of Object.keys(advisories)) {
|
|
145
|
+
const advisory = advisories[key];
|
|
146
|
+
const severity = advisory.severity?.toLowerCase() || 'low';
|
|
147
|
+
|
|
148
|
+
switch (severity) {
|
|
149
|
+
case 'critical': critical++; break;
|
|
150
|
+
case 'high': high++; break;
|
|
151
|
+
case 'moderate': moderate++; break;
|
|
152
|
+
default: low++;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
vulnerabilities.push({
|
|
156
|
+
name: advisory.name || key,
|
|
157
|
+
severity,
|
|
158
|
+
via: advisory.via?.[0]?.title || advisory.title || 'Unknown',
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// 新版 npm audit 格式
|
|
164
|
+
if (result.vulnerabilities) {
|
|
165
|
+
for (const [name, vuln] of Object.entries(result.vulnerabilities)) {
|
|
166
|
+
const v = vuln as any;
|
|
167
|
+
const severity = v.severity?.toLowerCase() || 'low';
|
|
168
|
+
|
|
169
|
+
switch (severity) {
|
|
170
|
+
case 'critical': critical++; break;
|
|
171
|
+
case 'high': high++; break;
|
|
172
|
+
case 'moderate': moderate++; break;
|
|
173
|
+
default: low++;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
vulnerabilities.push({
|
|
177
|
+
name,
|
|
178
|
+
severity,
|
|
179
|
+
via: v.via?.[0]?.title || v.name || 'Unknown',
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
} catch {
|
|
184
|
+
// 解析失败,尝试从文本提取
|
|
185
|
+
const criticalMatch = output.match(/(\d+) critical/i);
|
|
186
|
+
const highMatch = output.match(/(\d+) high/i);
|
|
187
|
+
const moderateMatch = output.match(/(\d+) moderate/i);
|
|
188
|
+
const lowMatch = output.match(/(\d+) low/i);
|
|
189
|
+
|
|
190
|
+
critical = criticalMatch ? parseInt(criticalMatch[1], 10) : 0;
|
|
191
|
+
high = highMatch ? parseInt(highMatch[1], 10) : 0;
|
|
192
|
+
moderate = moderateMatch ? parseInt(moderateMatch[1], 10) : 0;
|
|
193
|
+
low = lowMatch ? parseInt(lowMatch[1], 10) : 0;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
critical,
|
|
198
|
+
high,
|
|
199
|
+
moderate,
|
|
200
|
+
low,
|
|
201
|
+
total: critical + high + moderate + low,
|
|
202
|
+
vulnerabilities,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* 判断是否通过
|
|
208
|
+
*/
|
|
209
|
+
private isPassed(analysis: {
|
|
210
|
+
critical: number;
|
|
211
|
+
high: number;
|
|
212
|
+
moderate: number;
|
|
213
|
+
low: number;
|
|
214
|
+
total: number;
|
|
215
|
+
}): boolean {
|
|
216
|
+
// 根据严重程度阈值判断
|
|
217
|
+
switch (this.config.severityThreshold) {
|
|
218
|
+
case 'critical':
|
|
219
|
+
return analysis.critical === 0;
|
|
220
|
+
case 'high':
|
|
221
|
+
return analysis.critical === 0 && analysis.high === 0;
|
|
222
|
+
case 'moderate':
|
|
223
|
+
return analysis.critical === 0 && analysis.high === 0 && analysis.moderate === 0;
|
|
224
|
+
case 'low':
|
|
225
|
+
return analysis.total === 0;
|
|
226
|
+
default:
|
|
227
|
+
return analysis.critical === 0 && analysis.high === 0;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* 设置严重程度阈值
|
|
233
|
+
*/
|
|
234
|
+
setSeverityThreshold(threshold: 'low' | 'moderate' | 'high' | 'critical'): void {
|
|
235
|
+
this.config.severityThreshold = threshold;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* 获取配置
|
|
240
|
+
*/
|
|
241
|
+
getConfig(): Required<SecurityGateConfig> {
|
|
242
|
+
return { ...this.config };
|
|
243
|
+
}
|
|
244
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 门禁类型定义
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 门禁结果
|
|
7
|
+
*/
|
|
8
|
+
export interface GateResult {
|
|
9
|
+
gate: string;
|
|
10
|
+
passed: boolean;
|
|
11
|
+
message: string;
|
|
12
|
+
details?: Record<string, any>;
|
|
13
|
+
timestamp: string;
|
|
14
|
+
duration?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 门禁上下文
|
|
19
|
+
*/
|
|
20
|
+
export interface GateContext {
|
|
21
|
+
projectId: string;
|
|
22
|
+
taskId?: string;
|
|
23
|
+
projectPath: string;
|
|
24
|
+
|
|
25
|
+
// Review Gate
|
|
26
|
+
prNumber?: number;
|
|
27
|
+
minReviewers?: number;
|
|
28
|
+
reviewers?: string[];
|
|
29
|
+
|
|
30
|
+
// Security Gate
|
|
31
|
+
securityScanCommand?: string;
|
|
32
|
+
ignoreWarnings?: boolean;
|
|
33
|
+
|
|
34
|
+
// Performance Gate
|
|
35
|
+
performanceThresholds?: PerformanceThresholds;
|
|
36
|
+
benchmarkCommand?: string;
|
|
37
|
+
|
|
38
|
+
// Contract Gate
|
|
39
|
+
oldContractPath?: string;
|
|
40
|
+
newContractPath?: string;
|
|
41
|
+
openApiSpec?: string;
|
|
42
|
+
|
|
43
|
+
// 通用
|
|
44
|
+
timeout?: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 性能阈值
|
|
49
|
+
*/
|
|
50
|
+
export interface PerformanceThresholds {
|
|
51
|
+
maxResponseTime?: number; // ms
|
|
52
|
+
maxMemoryUsage?: number; // MB
|
|
53
|
+
minCoverage?: number; // %
|
|
54
|
+
maxBundleSize?: number; // KB
|
|
55
|
+
minThroughput?: number; // req/s
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 审查门禁配置
|
|
60
|
+
*/
|
|
61
|
+
export interface ReviewGateConfig {
|
|
62
|
+
minReviewers: number;
|
|
63
|
+
requireApproval: boolean;
|
|
64
|
+
blockOnChangesRequested: boolean;
|
|
65
|
+
allowedReviewers?: string[];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 安全门禁配置
|
|
70
|
+
*/
|
|
71
|
+
export interface SecurityGateConfig {
|
|
72
|
+
enabled: boolean;
|
|
73
|
+
scanCommand?: string;
|
|
74
|
+
ignoreWarnings: boolean;
|
|
75
|
+
ignoreDevDependencies: boolean;
|
|
76
|
+
severityThreshold: 'low' | 'moderate' | 'high' | 'critical';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 性能门禁配置
|
|
81
|
+
*/
|
|
82
|
+
export interface PerformanceGateConfig {
|
|
83
|
+
enabled: boolean;
|
|
84
|
+
benchmarkCommand?: string;
|
|
85
|
+
thresholds: PerformanceThresholds;
|
|
86
|
+
warmupRuns: number;
|
|
87
|
+
measureRuns: number;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 契约门禁配置
|
|
92
|
+
*/
|
|
93
|
+
export interface ContractGateConfig {
|
|
94
|
+
enabled: boolean;
|
|
95
|
+
strict: boolean;
|
|
96
|
+
allowBreakingChanges: boolean;
|
|
97
|
+
contractPath?: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* 验收标准门禁配置
|
|
102
|
+
*/
|
|
103
|
+
export interface SpecAcceptanceGateConfig {
|
|
104
|
+
/** tasks.yml 路径 */
|
|
105
|
+
tasksPath?: string;
|
|
106
|
+
/** 是否检查所有任务 */
|
|
107
|
+
checkAllTasks?: boolean;
|
|
108
|
+
/** 自定义验收条件 */
|
|
109
|
+
customAcceptanceCriteria?: Record<string, (task: any) => Promise<boolean>>;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 验收标准门禁上下文
|
|
114
|
+
*/
|
|
115
|
+
export interface AcceptanceGateContext {
|
|
116
|
+
/** 项目路径 */
|
|
117
|
+
projectPath: string;
|
|
118
|
+
/** 任务 ID */
|
|
119
|
+
taskId?: string;
|
|
120
|
+
/** tasks.yml 路径 */
|
|
121
|
+
tasksPath?: string;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 验收标准
|
|
126
|
+
*/
|
|
127
|
+
export interface AcceptanceCriteria {
|
|
128
|
+
id: string;
|
|
129
|
+
description: string;
|
|
130
|
+
type: 'manual' | 'automated' | 'test';
|
|
131
|
+
required: boolean;
|
|
132
|
+
checked?: boolean;
|
|
133
|
+
notes?: string;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* 命令黑名单规则
|
|
138
|
+
*/
|
|
139
|
+
export interface CommandBlacklistRule {
|
|
140
|
+
id: string;
|
|
141
|
+
pattern: RegExp;
|
|
142
|
+
level: 'block' | 'warn' | 'audit';
|
|
143
|
+
message: string;
|
|
144
|
+
category: string;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 命令门禁配置
|
|
149
|
+
*/
|
|
150
|
+
export interface CommandGateConfig {
|
|
151
|
+
/** 是否启用 */
|
|
152
|
+
enabled?: boolean;
|
|
153
|
+
/** 严格模式(warn 也阻止) */
|
|
154
|
+
strict?: boolean;
|
|
155
|
+
/** 自定义黑名单规则 */
|
|
156
|
+
customBlacklist?: CommandBlacklistRule[];
|
|
157
|
+
/** 忽略的类别 */
|
|
158
|
+
ignoreCategories?: string[];
|
|
159
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# governance/
|
|
2
|
+
|
|
3
|
+
## 职责
|
|
4
|
+
AI 治理:检测文档/配置/约束与代码的差异,输出差异报告。只检测不修复,由 LLM 自行修复。
|
|
5
|
+
|
|
6
|
+
## 核心导出
|
|
7
|
+
- `GovernanceExecutor` — 治理执行器: 运行所有检查、生成差异报告
|
|
8
|
+
- `types.ts` — DiffType / GovernanceDiff / GovernanceResult 类型
|
|
9
|
+
|
|
10
|
+
## 依赖关系
|
|
11
|
+
- 依赖 `src/core/constraints/` 约束检查
|
|
12
|
+
- 依赖 `src/monitoring/` 追踪/诊断数据
|
|
13
|
+
- 被 CLI 治理相关命令消费
|
|
14
|
+
|
|
15
|
+
## 约定
|
|
16
|
+
- "harness 检测差异,LLM 自行修复" — 不提供自动修复
|
|
17
|
+
- 差异类型(DiffType)可扩展
|
|
18
|
+
- 治理检查在 check / sync-docs 命令中触发
|
|
19
|
+
|
|
20
|
+
## 注意事项
|
|
21
|
+
- AI 治理简化(2026-05-03):移除冗余 hook/apply
|
|
22
|
+
- GovernanceExecutor 是单例
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GovernanceExecutor 测试
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as fs from 'fs';
|
|
6
|
+
import * as path from 'path';
|
|
7
|
+
import { GovernanceExecutor } from '../executor';
|
|
8
|
+
|
|
9
|
+
describe('GovernanceExecutor', () => {
|
|
10
|
+
const tempDir = path.join(process.cwd(), 'temp-test-governance');
|
|
11
|
+
|
|
12
|
+
beforeAll(() => {
|
|
13
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
afterAll(() => {
|
|
17
|
+
try {
|
|
18
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
19
|
+
} catch {
|
|
20
|
+
// ignore
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe('detectDiffs', () => {
|
|
25
|
+
it('无 CAPABILITIES.md 应该返回空差异', async () => {
|
|
26
|
+
const testDir = path.join(tempDir, 'no-cap');
|
|
27
|
+
fs.mkdirSync(testDir, { recursive: true });
|
|
28
|
+
|
|
29
|
+
const executor = new GovernanceExecutor();
|
|
30
|
+
const diffs = await executor.detectDiffs(testDir);
|
|
31
|
+
expect(diffs).toEqual([]);
|
|
32
|
+
|
|
33
|
+
fs.rmSync(testDir, { recursive: true, force: true });
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('CAPABILITIES.md 无表格应该返回空差异', async () => {
|
|
37
|
+
const testDir = path.join(tempDir, 'no-table');
|
|
38
|
+
fs.mkdirSync(testDir, { recursive: true });
|
|
39
|
+
fs.writeFileSync(path.join(testDir, 'CAPABILITIES.md'), '# Capabilities\n\nNo table here.');
|
|
40
|
+
|
|
41
|
+
const executor = new GovernanceExecutor();
|
|
42
|
+
const diffs = await executor.detectDiffs(testDir);
|
|
43
|
+
expect(diffs).toEqual([]);
|
|
44
|
+
|
|
45
|
+
fs.rmSync(testDir, { recursive: true, force: true });
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('新增文件未在 CAPABILITIES.md 中列出应该检测到 doc_mismatch', async () => {
|
|
49
|
+
const testDir = path.join(tempDir, 'missing-in-cap');
|
|
50
|
+
const srcDir = path.join(testDir, 'src');
|
|
51
|
+
fs.mkdirSync(srcDir, { recursive: true });
|
|
52
|
+
|
|
53
|
+
fs.writeFileSync(path.join(srcDir, 'new-module.ts'), 'export const x = 1;');
|
|
54
|
+
fs.writeFileSync(path.join(srcDir, 'old.ts'), 'export const y = 2;');
|
|
55
|
+
|
|
56
|
+
fs.writeFileSync(
|
|
57
|
+
path.join(testDir, 'CAPABILITIES.md'),
|
|
58
|
+
'# Capabilities\n\n| 模块 | 文件 | 说明 |\n|------|------|------|\n| old | src/old.ts | old |'
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const executor = new GovernanceExecutor();
|
|
62
|
+
const diffs = await executor.detectDiffs(testDir);
|
|
63
|
+
|
|
64
|
+
expect(diffs.length).toBe(1);
|
|
65
|
+
expect(diffs[0].type).toBe('doc_mismatch');
|
|
66
|
+
expect(diffs[0].details.files).toContain('src/new-module.ts');
|
|
67
|
+
|
|
68
|
+
fs.rmSync(testDir, { recursive: true, force: true });
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('CAPABILITIES.md 中列出已删除文件应该检测到 doc_mismatch', async () => {
|
|
72
|
+
const testDir = path.join(tempDir, 'removed-from-disk');
|
|
73
|
+
const srcDir = path.join(testDir, 'src');
|
|
74
|
+
fs.mkdirSync(srcDir, { recursive: true });
|
|
75
|
+
|
|
76
|
+
fs.writeFileSync(
|
|
77
|
+
path.join(testDir, 'CAPABILITIES.md'),
|
|
78
|
+
'# Capabilities\n\n| 模块 | 文件 | 说明 |\n|------|------|------|\n| old | src/old.ts | old |'
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const executor = new GovernanceExecutor();
|
|
82
|
+
const diffs = await executor.detectDiffs(testDir);
|
|
83
|
+
|
|
84
|
+
expect(diffs.length).toBe(1);
|
|
85
|
+
expect(diffs[0].type).toBe('doc_mismatch');
|
|
86
|
+
expect(diffs[0].details.files).toContain('src/old.ts');
|
|
87
|
+
|
|
88
|
+
fs.rmSync(testDir, { recursive: true, force: true });
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('CAPABILITIES.md 与源码同步应该无差异', async () => {
|
|
92
|
+
const testDir = path.join(tempDir, 'in-sync');
|
|
93
|
+
const srcDir = path.join(testDir, 'src');
|
|
94
|
+
fs.mkdirSync(srcDir, { recursive: true });
|
|
95
|
+
|
|
96
|
+
fs.writeFileSync(path.join(srcDir, 'module.ts'), 'export const x = 1;');
|
|
97
|
+
fs.writeFileSync(
|
|
98
|
+
path.join(testDir, 'CAPABILITIES.md'),
|
|
99
|
+
'# Capabilities\n\n| 模块 | 文件 | 说明 |\n|------|------|------|\n| module | src/module.ts | module |'
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const executor = new GovernanceExecutor();
|
|
103
|
+
const diffs = await executor.detectDiffs(testDir);
|
|
104
|
+
|
|
105
|
+
expect(diffs).toEqual([]);
|
|
106
|
+
|
|
107
|
+
fs.rmSync(testDir, { recursive: true, force: true });
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('CONTEXT.md 缺失应该检测到 context_missing', async () => {
|
|
111
|
+
const testDir = path.join(tempDir, 'ctx-missing');
|
|
112
|
+
const harnessDir = path.join(testDir, '.harness');
|
|
113
|
+
fs.mkdirSync(harnessDir, { recursive: true });
|
|
114
|
+
|
|
115
|
+
const yaml = require('js-yaml');
|
|
116
|
+
fs.writeFileSync(
|
|
117
|
+
path.join(harnessDir, 'config.yml'),
|
|
118
|
+
yaml.dump({
|
|
119
|
+
governance: {
|
|
120
|
+
context_files: {
|
|
121
|
+
enabled: true,
|
|
122
|
+
required_dirs: ['src'],
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
})
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
const executor = new GovernanceExecutor();
|
|
129
|
+
const diffs = await executor.detectDiffs(testDir);
|
|
130
|
+
|
|
131
|
+
expect(diffs.length).toBe(1);
|
|
132
|
+
expect(diffs[0].type).toBe('context_missing');
|
|
133
|
+
expect(diffs[0].details.moduleName).toBe('src');
|
|
134
|
+
|
|
135
|
+
fs.rmSync(testDir, { recursive: true, force: true });
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('CONTEXT.md 是模板应该检测到 context_outdated', async () => {
|
|
139
|
+
const testDir = path.join(tempDir, 'ctx-template');
|
|
140
|
+
const harnessDir = path.join(testDir, '.harness');
|
|
141
|
+
const srcDir = path.join(testDir, 'src');
|
|
142
|
+
fs.mkdirSync(harnessDir, { recursive: true });
|
|
143
|
+
fs.mkdirSync(srcDir, { recursive: true });
|
|
144
|
+
|
|
145
|
+
const yaml = require('js-yaml');
|
|
146
|
+
fs.writeFileSync(
|
|
147
|
+
path.join(harnessDir, 'config.yml'),
|
|
148
|
+
yaml.dump({
|
|
149
|
+
governance: {
|
|
150
|
+
context_files: {
|
|
151
|
+
enabled: true,
|
|
152
|
+
required_dirs: ['src'],
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
})
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
fs.writeFileSync(
|
|
159
|
+
path.join(srcDir, 'CONTEXT.md'),
|
|
160
|
+
'# src\n\n<!-- 此文件描述 src 目录的职责和上下文 -->\n\n## 职责\n\n<!-- 本目录的核心职责是什么 -->'
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
const executor = new GovernanceExecutor();
|
|
164
|
+
const diffs = await executor.detectDiffs(testDir);
|
|
165
|
+
|
|
166
|
+
expect(diffs.length).toBe(1);
|
|
167
|
+
expect(diffs[0].type).toBe('context_outdated');
|
|
168
|
+
expect(diffs[0].details.moduleName).toBe('src');
|
|
169
|
+
|
|
170
|
+
fs.rmSync(testDir, { recursive: true, force: true });
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('CONTEXT.md 已填写应该无差异', async () => {
|
|
174
|
+
const testDir = path.join(tempDir, 'ctx-filled');
|
|
175
|
+
const harnessDir = path.join(testDir, '.harness');
|
|
176
|
+
const srcDir = path.join(testDir, 'src');
|
|
177
|
+
fs.mkdirSync(harnessDir, { recursive: true });
|
|
178
|
+
fs.mkdirSync(srcDir, { recursive: true });
|
|
179
|
+
|
|
180
|
+
const yaml = require('js-yaml');
|
|
181
|
+
fs.writeFileSync(
|
|
182
|
+
path.join(harnessDir, 'config.yml'),
|
|
183
|
+
yaml.dump({
|
|
184
|
+
governance: {
|
|
185
|
+
context_files: {
|
|
186
|
+
enabled: true,
|
|
187
|
+
required_dirs: ['src'],
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
})
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
fs.writeFileSync(
|
|
194
|
+
path.join(srcDir, 'CONTEXT.md'),
|
|
195
|
+
'# src\n\n源代码目录,包含所有核心模块。'
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
const executor = new GovernanceExecutor();
|
|
199
|
+
const diffs = await executor.detectDiffs(testDir);
|
|
200
|
+
|
|
201
|
+
expect(diffs).toEqual([]);
|
|
202
|
+
|
|
203
|
+
fs.rmSync(testDir, { recursive: true, force: true });
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
describe('check', () => {
|
|
208
|
+
it('有差异时 should return hasDiffs=true', async () => {
|
|
209
|
+
const testDir = path.join(tempDir, 'check-diffs');
|
|
210
|
+
const srcDir = path.join(testDir, 'src');
|
|
211
|
+
fs.mkdirSync(srcDir, { recursive: true });
|
|
212
|
+
|
|
213
|
+
fs.writeFileSync(path.join(srcDir, 'new.ts'), 'export const x = 1;');
|
|
214
|
+
fs.writeFileSync(
|
|
215
|
+
path.join(testDir, 'CAPABILITIES.md'),
|
|
216
|
+
'# Capabilities\n\n| 模块 | 文件 | 说明 |\n|------|------|------|\n| old | src/old.ts | old |'
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
const executor = new GovernanceExecutor();
|
|
220
|
+
const result = await executor.check(testDir);
|
|
221
|
+
|
|
222
|
+
expect(result.hasDiffs).toBe(true);
|
|
223
|
+
expect(result.diffs.length).toBeGreaterThan(0);
|
|
224
|
+
|
|
225
|
+
fs.rmSync(testDir, { recursive: true, force: true });
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('无差异时 should return hasDiffs=false', async () => {
|
|
229
|
+
const testDir = path.join(tempDir, 'check-no-diffs');
|
|
230
|
+
fs.mkdirSync(testDir, { recursive: true });
|
|
231
|
+
fs.writeFileSync(path.join(testDir, 'CAPABILITIES.md'), '# Capabilities\n\nNo table.');
|
|
232
|
+
|
|
233
|
+
const executor = new GovernanceExecutor();
|
|
234
|
+
const result = await executor.check(testDir);
|
|
235
|
+
|
|
236
|
+
expect(result.hasDiffs).toBe(false);
|
|
237
|
+
expect(result.diffs).toEqual([]);
|
|
238
|
+
|
|
239
|
+
fs.rmSync(testDir, { recursive: true, force: true });
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
describe('global singleton', () => {
|
|
244
|
+
it('应该导出全局单例', () => {
|
|
245
|
+
const { governanceExecutor } = require('../executor');
|
|
246
|
+
expect(governanceExecutor).toBeInstanceOf(GovernanceExecutor);
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
});
|