@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,486 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FreshnessRunner — 配置驱动的文档新鲜度检查引擎
|
|
3
|
+
*
|
|
4
|
+
* 所有检查是纯同步文件系统操作,零 LLM 调用。
|
|
5
|
+
* 通过 DocFreshnessConfig 配置驱动,不绑定任何项目结构。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { existsSync, readFileSync, readdirSync, statSync } from 'fs';
|
|
9
|
+
import { join, basename, relative } from 'path';
|
|
10
|
+
import { detectSourceRoots } from '../../../utils/detect-source-roots';
|
|
11
|
+
import type {
|
|
12
|
+
DocFreshnessCheck,
|
|
13
|
+
DocFreshnessConfig,
|
|
14
|
+
ChangelogVersionCheck,
|
|
15
|
+
ContextDocsCheck,
|
|
16
|
+
DocDirCheck,
|
|
17
|
+
DocRegexCountCheck,
|
|
18
|
+
} from '../../../types/project-config';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Freshness 检查结果
|
|
22
|
+
*/
|
|
23
|
+
export interface FreshnessCheckResult {
|
|
24
|
+
/** 检查类型 */
|
|
25
|
+
type: string;
|
|
26
|
+
/** 人类可读标签 */
|
|
27
|
+
label: string;
|
|
28
|
+
/** 是否通过 */
|
|
29
|
+
pass: boolean;
|
|
30
|
+
/** 失败时的消息 */
|
|
31
|
+
message?: string;
|
|
32
|
+
/** 额外详情 */
|
|
33
|
+
detail?: Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* FreshnessRunner 执行上下文
|
|
38
|
+
*/
|
|
39
|
+
interface RunContext {
|
|
40
|
+
projectPath: string;
|
|
41
|
+
/** 外部提供的 required_dirs(来自 governance.context_files,用于 context_docs 检查的默认 dirs) */
|
|
42
|
+
requiredDirs?: string[];
|
|
43
|
+
/** 外部提供的约束计数(用于内置 harner harness 的 doc_regex_count) */
|
|
44
|
+
constraintCounts?: {
|
|
45
|
+
ironLaws?: number;
|
|
46
|
+
guidelines?: number;
|
|
47
|
+
tips?: number;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 配置驱动的文档新鲜度检查引擎
|
|
53
|
+
*/
|
|
54
|
+
export class FreshnessRunner {
|
|
55
|
+
/**
|
|
56
|
+
* 运行所有配置的文档新鲜度检查
|
|
57
|
+
*/
|
|
58
|
+
runAll(
|
|
59
|
+
config: DocFreshnessConfig,
|
|
60
|
+
projectPath: string,
|
|
61
|
+
ctx?: { requiredDirs?: string[]; constraintCounts?: { ironLaws?: number; guidelines?: number; tips?: number } }
|
|
62
|
+
): FreshnessCheckResult[] {
|
|
63
|
+
if (config.enabled === false) return [];
|
|
64
|
+
if (!config.checks || config.checks.length === 0) return [];
|
|
65
|
+
|
|
66
|
+
const context: RunContext = {
|
|
67
|
+
projectPath,
|
|
68
|
+
requiredDirs: ctx?.requiredDirs,
|
|
69
|
+
constraintCounts: ctx?.constraintCounts,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return config.checks.map(check => this.runSingle(check, context));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 执行单个检查
|
|
77
|
+
*/
|
|
78
|
+
runSingle(check: DocFreshnessCheck, context: RunContext): FreshnessCheckResult {
|
|
79
|
+
switch (check.type) {
|
|
80
|
+
case 'changelog_version':
|
|
81
|
+
return this.checkChangelogVersion(check, context);
|
|
82
|
+
case 'context_docs':
|
|
83
|
+
return this.checkContextDocs(check, context);
|
|
84
|
+
case 'doc_dir_check':
|
|
85
|
+
return this.checkDocDir(check, context);
|
|
86
|
+
case 'doc_regex_count':
|
|
87
|
+
return this.checkDocRegexCount(check, context);
|
|
88
|
+
default:
|
|
89
|
+
return {
|
|
90
|
+
type: (check as any).type || 'unknown',
|
|
91
|
+
label: 'Unknown',
|
|
92
|
+
pass: true,
|
|
93
|
+
message: `未知的检查类型: ${(check as any).type}`,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// ── changelog_version ────────────────────────────────────────────
|
|
99
|
+
|
|
100
|
+
private checkChangelogVersion(
|
|
101
|
+
check: ChangelogVersionCheck,
|
|
102
|
+
ctx: RunContext
|
|
103
|
+
): FreshnessCheckResult {
|
|
104
|
+
const changelogPath = join(ctx.projectPath, check.changelog || 'CHANGELOG.md');
|
|
105
|
+
const pkgPath = join(ctx.projectPath, check.package_json || 'package.json');
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
if (!existsSync(changelogPath)) {
|
|
109
|
+
return { type: 'changelog_version', label: 'CHANGELOG Version', pass: true };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const changelogContent = readFileSync(changelogPath, 'utf-8');
|
|
113
|
+
const versionMatch = changelogContent.match(/##\s*\[(\d+\.\d+\.\d+)\]/);
|
|
114
|
+
if (!versionMatch) {
|
|
115
|
+
return { type: 'changelog_version', label: 'CHANGELOG Version', pass: true };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const changelogVersion = versionMatch[1];
|
|
119
|
+
|
|
120
|
+
if (!existsSync(pkgPath)) {
|
|
121
|
+
return { type: 'changelog_version', label: 'CHANGELOG Version', pass: true };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
|
|
125
|
+
const pkgVersion = pkg.version as string;
|
|
126
|
+
|
|
127
|
+
const pass = changelogVersion === pkgVersion;
|
|
128
|
+
return {
|
|
129
|
+
type: 'changelog_version',
|
|
130
|
+
label: 'CHANGELOG Version',
|
|
131
|
+
pass,
|
|
132
|
+
message: pass ? undefined : `CHANGELOG.md 版本 ${changelogVersion} !== package.json 版本 ${pkgVersion}`,
|
|
133
|
+
detail: { changelogVersion, pkgVersion },
|
|
134
|
+
};
|
|
135
|
+
} catch {
|
|
136
|
+
return { type: 'changelog_version', label: 'CHANGELOG Version', pass: true };
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// ── context_docs ─────────────────────────────────────────────────
|
|
141
|
+
|
|
142
|
+
private checkContextDocs(
|
|
143
|
+
check: ContextDocsCheck,
|
|
144
|
+
ctx: RunContext
|
|
145
|
+
): FreshnessCheckResult {
|
|
146
|
+
const dirs = check.dirs || ctx.requiredDirs;
|
|
147
|
+
if (!dirs || dirs.length === 0) {
|
|
148
|
+
return { type: 'context_docs', label: 'CONTEXT.md', pass: true };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const docName = check.doc_name || 'CONTEXT.md';
|
|
152
|
+
const missing: string[] = [];
|
|
153
|
+
|
|
154
|
+
for (const dir of dirs) {
|
|
155
|
+
const docPath = join(ctx.projectPath, dir, docName);
|
|
156
|
+
if (!existsSync(docPath)) {
|
|
157
|
+
missing.push(dir);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const pass = missing.length === 0;
|
|
162
|
+
return {
|
|
163
|
+
type: 'context_docs',
|
|
164
|
+
label: 'CONTEXT.md',
|
|
165
|
+
pass,
|
|
166
|
+
message: pass ? undefined : `缺少 ${docName}: ${missing.join(', ')}`,
|
|
167
|
+
detail: { missing, doc_name: docName },
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// ── doc_dir_check ────────────────────────────────────────────────
|
|
172
|
+
|
|
173
|
+
private checkDocDir(
|
|
174
|
+
check: DocDirCheck,
|
|
175
|
+
ctx: RunContext
|
|
176
|
+
): FreshnessCheckResult {
|
|
177
|
+
try {
|
|
178
|
+
const docPath = join(ctx.projectPath, check.doc);
|
|
179
|
+
if (!existsSync(docPath)) {
|
|
180
|
+
return {
|
|
181
|
+
type: 'doc_dir_check',
|
|
182
|
+
label: `${check.doc} / ${check.section}`,
|
|
183
|
+
pass: true,
|
|
184
|
+
message: `${check.doc} 不存在,跳过检查`,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const content = readFileSync(docPath, 'utf-8');
|
|
189
|
+
|
|
190
|
+
// 提取目标章节($ 不要求末尾有 \n,适配无 trailing newline 的内容)
|
|
191
|
+
const sectionRegex = new RegExp(
|
|
192
|
+
`## ${this.escapeRegExp(check.section)}\\s*\\n([\\s\\S]*?)(?=\\n## |\\n---|$)`
|
|
193
|
+
);
|
|
194
|
+
const sectionMatch = content.match(sectionRegex);
|
|
195
|
+
if (!sectionMatch) {
|
|
196
|
+
return {
|
|
197
|
+
type: 'doc_dir_check',
|
|
198
|
+
label: `${check.doc} / ${check.section}`,
|
|
199
|
+
pass: true,
|
|
200
|
+
message: `未找到 "${check.section}" 章节`,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const section = sectionMatch[1];
|
|
205
|
+
|
|
206
|
+
// 提取目录
|
|
207
|
+
const dirPattern = check.dir_pattern || '`([^`]+)`';
|
|
208
|
+
const dirRegex = new RegExp(dirPattern, 'g');
|
|
209
|
+
const docDirs = new Set<string>();
|
|
210
|
+
let match;
|
|
211
|
+
while ((match = dirRegex.exec(section)) !== null) {
|
|
212
|
+
const dirPath = match[1].replace(/\/$/, '').trim();
|
|
213
|
+
// 只收集看起来像目录的路径(包含 / 或以特定前缀开头)
|
|
214
|
+
// 宽松匹配:任何非空字符串
|
|
215
|
+
if (dirPath.length > 0) {
|
|
216
|
+
docDirs.add(dirPath);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (docDirs.size === 0) {
|
|
221
|
+
return {
|
|
222
|
+
type: 'doc_dir_check',
|
|
223
|
+
label: `${check.doc} / ${check.section}`,
|
|
224
|
+
pass: true,
|
|
225
|
+
message: `"${check.section}" 章节中未找到目录引用`,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const failures: string[] = [];
|
|
230
|
+
|
|
231
|
+
// 1. doc → fs: 文档中每个目录必须实际存在于磁盘
|
|
232
|
+
for (const dir of docDirs) {
|
|
233
|
+
if (!existsSync(join(ctx.projectPath, dir))) {
|
|
234
|
+
failures.push(`文档引用但不存在: ${dir}`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// 2. fs → doc: 每个实际目录必须在文档中被覆盖
|
|
239
|
+
if (!check.skip_reverse_check) {
|
|
240
|
+
// 从文档目录中推断要扫描的根目录集
|
|
241
|
+
const rootDirs = this.inferRootDirs(docDirs, ctx.projectPath);
|
|
242
|
+
const excludeSet = new Set(check.exclude || ['__tests__', 'node_modules', 'dist']);
|
|
243
|
+
|
|
244
|
+
for (const rootDir of rootDirs) {
|
|
245
|
+
const absRoot = join(ctx.projectPath, rootDir);
|
|
246
|
+
if (!existsSync(absRoot)) continue;
|
|
247
|
+
|
|
248
|
+
try {
|
|
249
|
+
const entries = readdirSync(absRoot, { withFileTypes: true });
|
|
250
|
+
for (const entry of entries) {
|
|
251
|
+
if (!entry.isDirectory()) continue;
|
|
252
|
+
if (excludeSet.has(entry.name)) continue;
|
|
253
|
+
if (entry.name.startsWith('__') || entry.name.startsWith('.')) continue;
|
|
254
|
+
|
|
255
|
+
const actualDir = `${rootDir}/${entry.name}`;
|
|
256
|
+
// 直接匹配 or 任何文档条目是该目录的子目录
|
|
257
|
+
if (docDirs.has(actualDir)) continue;
|
|
258
|
+
const covered = [...docDirs].some(d => d.startsWith(actualDir + '/'));
|
|
259
|
+
if (!covered) {
|
|
260
|
+
failures.push(`存在但未在文档中覆盖: ${actualDir}`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
} catch {
|
|
264
|
+
// 扫描失败,跳过
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const pass = failures.length === 0;
|
|
270
|
+
return {
|
|
271
|
+
type: 'doc_dir_check',
|
|
272
|
+
label: `${check.doc} / ${check.section}`,
|
|
273
|
+
pass,
|
|
274
|
+
message: pass ? undefined : failures.join('; '),
|
|
275
|
+
detail: { docDirs: [...docDirs], failures },
|
|
276
|
+
};
|
|
277
|
+
} catch {
|
|
278
|
+
return {
|
|
279
|
+
type: 'doc_dir_check',
|
|
280
|
+
label: `${check.doc} / ${check.section}`,
|
|
281
|
+
pass: true,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* 从文档目录集合推断要扫描的根目录
|
|
288
|
+
* 例如 ["src/core", "src/cli/commands"] → ["src"]
|
|
289
|
+
*/
|
|
290
|
+
private inferRootDirs(docDirs: Set<string>, projectPath: string): string[] {
|
|
291
|
+
const roots = new Set<string>();
|
|
292
|
+
|
|
293
|
+
for (const dir of docDirs) {
|
|
294
|
+
// 取第一个路径段之前的公共部分
|
|
295
|
+
const parts = dir.split('/');
|
|
296
|
+
// 收集可能的根(单段目录如 "src/xxx" → 根是 "src")
|
|
297
|
+
if (parts.length >= 2) {
|
|
298
|
+
roots.add(parts.slice(0, parts.length - 1).join('/') || parts[0]);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// 合并为最小公共根集
|
|
303
|
+
// 简单策略:如果有 "src/a" 和 "src/b",则根是 "src"
|
|
304
|
+
const merged = new Set<string>();
|
|
305
|
+
for (const root of roots) {
|
|
306
|
+
let isSubsumed = false;
|
|
307
|
+
for (const other of roots) {
|
|
308
|
+
if (root !== other && root.startsWith(other + '/')) {
|
|
309
|
+
isSubsumed = true;
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (!isSubsumed) {
|
|
314
|
+
merged.add(root);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return merged.size > 0 ? [...merged] : detectSourceRoots(projectPath);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// ── doc_regex_count ──────────────────────────────────────────────
|
|
322
|
+
|
|
323
|
+
private checkDocRegexCount(
|
|
324
|
+
check: DocRegexCountCheck,
|
|
325
|
+
ctx: RunContext
|
|
326
|
+
): FreshnessCheckResult {
|
|
327
|
+
try {
|
|
328
|
+
const docPath = join(ctx.projectPath, check.doc);
|
|
329
|
+
if (!existsSync(docPath)) {
|
|
330
|
+
return {
|
|
331
|
+
type: 'doc_regex_count',
|
|
332
|
+
label: `${check.doc} / ${check.label}`,
|
|
333
|
+
pass: true,
|
|
334
|
+
message: `${check.doc} 不存在,跳过检查`,
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const content = readFileSync(docPath, 'utf-8');
|
|
339
|
+
|
|
340
|
+
// 从文档中提取声明的计数
|
|
341
|
+
const countRegex = new RegExp(check.pattern);
|
|
342
|
+
const countMatch = content.match(countRegex);
|
|
343
|
+
if (!countMatch || countMatch[1] === undefined) {
|
|
344
|
+
return {
|
|
345
|
+
type: 'doc_regex_count',
|
|
346
|
+
label: `${check.doc} / ${check.label}`,
|
|
347
|
+
pass: true,
|
|
348
|
+
message: `未在 ${check.doc} 中找到匹配 "${check.label}" 的计数行`,
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const docCount = parseInt(countMatch[1], 10);
|
|
353
|
+
if (isNaN(docCount)) {
|
|
354
|
+
return {
|
|
355
|
+
type: 'doc_regex_count',
|
|
356
|
+
label: `${check.doc} / ${check.label}`,
|
|
357
|
+
pass: true,
|
|
358
|
+
message: `计数解析失败: ${countMatch[1]}`,
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// 获取实际计数
|
|
363
|
+
let actualCount: number;
|
|
364
|
+
if (check.actual.kind === 'dir_count') {
|
|
365
|
+
actualCount = this.countFromDir(check.actual.path, check.actual.extension || '.ts', check.actual.exclude || [], ctx.projectPath);
|
|
366
|
+
} else if (check.actual.kind === 'grep_count') {
|
|
367
|
+
actualCount = this.countFromGrep(ctx.projectPath, check.actual.glob, check.actual.pattern);
|
|
368
|
+
} else {
|
|
369
|
+
actualCount = check.actual.value;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
if (actualCount < 0) {
|
|
373
|
+
return {
|
|
374
|
+
type: 'doc_regex_count',
|
|
375
|
+
label: `${check.doc} / ${check.label}`,
|
|
376
|
+
pass: true,
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const pass = docCount === actualCount;
|
|
381
|
+
return {
|
|
382
|
+
type: 'doc_regex_count',
|
|
383
|
+
label: `${check.doc} / ${check.label}`,
|
|
384
|
+
pass,
|
|
385
|
+
message: pass ? undefined : `${check.label}: 文档 ${docCount} → 实际 ${actualCount}`,
|
|
386
|
+
detail: { docCount, actualCount },
|
|
387
|
+
};
|
|
388
|
+
} catch {
|
|
389
|
+
return {
|
|
390
|
+
type: 'doc_regex_count',
|
|
391
|
+
label: `${check.doc} / ${check.label}`,
|
|
392
|
+
pass: true,
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* 从目录中计数匹配的文件/条目
|
|
399
|
+
*/
|
|
400
|
+
countFromDir(
|
|
401
|
+
dirPath: string,
|
|
402
|
+
extension: string,
|
|
403
|
+
exclude: string[],
|
|
404
|
+
projectPath: string
|
|
405
|
+
): number {
|
|
406
|
+
const absDir = join(projectPath, dirPath);
|
|
407
|
+
if (!existsSync(absDir)) return -1;
|
|
408
|
+
|
|
409
|
+
try {
|
|
410
|
+
const entries = readdirSync(absDir, { withFileTypes: true });
|
|
411
|
+
const excludeSet = new Set(exclude);
|
|
412
|
+
|
|
413
|
+
let count = 0;
|
|
414
|
+
for (const entry of entries) {
|
|
415
|
+
if (excludeSet.has(entry.name)) continue;
|
|
416
|
+
|
|
417
|
+
if (entry.isDirectory() && !entry.name.startsWith('__') && !entry.name.startsWith('.')) {
|
|
418
|
+
// 目录:计 1(.ts 过滤不适用于目录)
|
|
419
|
+
count++;
|
|
420
|
+
} else if (entry.isFile() && entry.name.endsWith(extension)) {
|
|
421
|
+
// 排除 .d.ts
|
|
422
|
+
if (!entry.name.endsWith('.d.ts')) {
|
|
423
|
+
count++;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
return count;
|
|
429
|
+
} catch {
|
|
430
|
+
return -1;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* 从 grep 匹配中计数
|
|
436
|
+
*/
|
|
437
|
+
countFromGrep(
|
|
438
|
+
projectPath: string,
|
|
439
|
+
globPattern: string,
|
|
440
|
+
pattern: string
|
|
441
|
+
): number {
|
|
442
|
+
try {
|
|
443
|
+
// globPattern 如 "src/gates/*.ts"
|
|
444
|
+
const absGlob = join(projectPath, globPattern);
|
|
445
|
+
|
|
446
|
+
// 分离目录和文件名模式
|
|
447
|
+
const lastSlash = absGlob.lastIndexOf('/');
|
|
448
|
+
const searchDir = absGlob.substring(0, lastSlash);
|
|
449
|
+
const filePattern = absGlob.substring(lastSlash + 1);
|
|
450
|
+
|
|
451
|
+
if (!existsSync(searchDir)) return -1;
|
|
452
|
+
|
|
453
|
+
// 将 glob * 转换为简单的 endsWith 检查
|
|
454
|
+
const suffix = filePattern.replace(/\*/g, '');
|
|
455
|
+
|
|
456
|
+
const entries = readdirSync(searchDir, { withFileTypes: true });
|
|
457
|
+
const reg = new RegExp(pattern);
|
|
458
|
+
|
|
459
|
+
let count = 0;
|
|
460
|
+
for (const entry of entries) {
|
|
461
|
+
if (!entry.isFile()) continue;
|
|
462
|
+
if (!entry.name.endsWith(suffix)) continue;
|
|
463
|
+
|
|
464
|
+
try {
|
|
465
|
+
const content = readFileSync(join(searchDir, entry.name), 'utf-8');
|
|
466
|
+
const matches = content.match(new RegExp(pattern, 'g'));
|
|
467
|
+
if (matches) {
|
|
468
|
+
count += matches.length;
|
|
469
|
+
}
|
|
470
|
+
} catch {
|
|
471
|
+
// skip
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
return count;
|
|
476
|
+
} catch {
|
|
477
|
+
return -1;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// ── helpers ──────────────────────────────────────────────────────
|
|
482
|
+
|
|
483
|
+
private escapeRegExp(str: string): string {
|
|
484
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
485
|
+
}
|
|
486
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 约束模块入口
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// 三层约束定义
|
|
6
|
+
export {
|
|
7
|
+
IRON_LAWS,
|
|
8
|
+
GUIDELINES,
|
|
9
|
+
TIPS,
|
|
10
|
+
getAllConstraints,
|
|
11
|
+
findConstraintsByTrigger,
|
|
12
|
+
getConstraint,
|
|
13
|
+
// 向后兼容
|
|
14
|
+
getAllLaws,
|
|
15
|
+
findLawsByTrigger,
|
|
16
|
+
getLaw,
|
|
17
|
+
filterLawsBySeverity,
|
|
18
|
+
} from './definitions';
|
|
19
|
+
|
|
20
|
+
// 约束检查器
|
|
21
|
+
export {
|
|
22
|
+
ConstraintChecker,
|
|
23
|
+
checkConstraint,
|
|
24
|
+
checkConstraints,
|
|
25
|
+
checkBeforeExecution,
|
|
26
|
+
constraintChecker,
|
|
27
|
+
// 向后兼容
|
|
28
|
+
IronLawChecker,
|
|
29
|
+
checkIronLaw,
|
|
30
|
+
checkAllIronLaws,
|
|
31
|
+
ironLawChecker,
|
|
32
|
+
} from './checker';
|
|
33
|
+
|
|
34
|
+
// 类型导出
|
|
35
|
+
export type {
|
|
36
|
+
ConstraintId,
|
|
37
|
+
ConstraintLevel,
|
|
38
|
+
ConstraintTrigger,
|
|
39
|
+
Constraint,
|
|
40
|
+
ConstraintResult,
|
|
41
|
+
ConstraintContext,
|
|
42
|
+
ConstraintCheckResult,
|
|
43
|
+
// 向后兼容
|
|
44
|
+
IronLawId,
|
|
45
|
+
IronLawSeverity,
|
|
46
|
+
IronLawTrigger,
|
|
47
|
+
IronLaw,
|
|
48
|
+
IronLawResult,
|
|
49
|
+
IronLawContext,
|
|
50
|
+
} from '../../types/constraint';
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
ConstraintViolationError,
|
|
54
|
+
// 向后兼容
|
|
55
|
+
IronLawViolationError,
|
|
56
|
+
} from '../../types/constraint';
|
|
57
|
+
|
|
58
|
+
// 约束拦截器
|
|
59
|
+
// 约束 Prompt 注入
|
|
60
|
+
export {
|
|
61
|
+
formatConstraintsForPrompt,
|
|
62
|
+
type AgentRole,
|
|
63
|
+
} from './prompt-injection';
|
|
64
|
+
|
|
65
|
+
export {
|
|
66
|
+
ConstraintInterceptor,
|
|
67
|
+
constraintInterceptor,
|
|
68
|
+
interceptOperation,
|
|
69
|
+
claimOperation,
|
|
70
|
+
} from './interceptor';
|
|
71
|
+
|
|
72
|
+
export type {
|
|
73
|
+
EnforcementId,
|
|
74
|
+
EnforcementExecutor,
|
|
75
|
+
EnforcementContext,
|
|
76
|
+
EnforcementResult,
|
|
77
|
+
InterceptionResult,
|
|
78
|
+
} from '../../types/enforcement';
|