@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,289 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AnnotationChecker 测试
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { checkFile, checkDirectory, generateReport } from '../annotation-checker';
|
|
6
|
+
import * as fs from 'fs';
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
|
|
9
|
+
// Mock fs
|
|
10
|
+
jest.mock('fs', () => ({
|
|
11
|
+
readFileSync: jest.fn(),
|
|
12
|
+
readdirSync: jest.fn(),
|
|
13
|
+
statSync: jest.fn(),
|
|
14
|
+
existsSync: jest.fn(),
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
const mockFs = fs as jest.Mocked<typeof fs>;
|
|
18
|
+
|
|
19
|
+
describe('AnnotationChecker', () => {
|
|
20
|
+
const tempDir = '/test/project';
|
|
21
|
+
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
jest.clearAllMocks();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('checkFile', () => {
|
|
27
|
+
it('应该检查有效的 JSDoc 注释', () => {
|
|
28
|
+
mockFs.readFileSync.mockReturnValue(`
|
|
29
|
+
/**
|
|
30
|
+
* @spec AR-001
|
|
31
|
+
* @implements feature-auth
|
|
32
|
+
* @acceptance AC-001
|
|
33
|
+
* @author test
|
|
34
|
+
* @since 2026-04-28
|
|
35
|
+
*/
|
|
36
|
+
export function auth() {}
|
|
37
|
+
`);
|
|
38
|
+
|
|
39
|
+
const result = checkFile('/test/file.ts');
|
|
40
|
+
|
|
41
|
+
expect(result.annotations.length).toBe(1);
|
|
42
|
+
expect(result.annotations[0]?.specId).toBe('AR-001');
|
|
43
|
+
expect(result.annotations[0]?.implements).toContain('feature-auth');
|
|
44
|
+
expect(result.annotations[0]?.acceptance).toContain('AC-001');
|
|
45
|
+
expect(result.annotations[0]?.author).toBe('test');
|
|
46
|
+
expect(result.annotations[0]?.since).toBe('2026-04-28');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('应该检查行内注释', () => {
|
|
50
|
+
mockFs.readFileSync.mockReturnValue(`
|
|
51
|
+
// @spec AR-002
|
|
52
|
+
const x = 1;
|
|
53
|
+
`);
|
|
54
|
+
|
|
55
|
+
const result = checkFile('/test/file.ts');
|
|
56
|
+
|
|
57
|
+
expect(result.annotations.length).toBe(1);
|
|
58
|
+
expect(result.annotations[0]?.specId).toBe('AR-002');
|
|
59
|
+
expect(result.annotations[0]?.type).toBe('inline');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('应该检测无效 Spec ID 格式', () => {
|
|
63
|
+
mockFs.readFileSync.mockReturnValue(`
|
|
64
|
+
/**
|
|
65
|
+
* @spec INVALID-ID
|
|
66
|
+
*/
|
|
67
|
+
export function test() {}
|
|
68
|
+
`);
|
|
69
|
+
|
|
70
|
+
const result = checkFile('/test/file.ts');
|
|
71
|
+
|
|
72
|
+
expect(result.errors.length).toBeGreaterThan(0);
|
|
73
|
+
expect(result.errors[0]?.code).toBe('INVALID_SPEC_FORMAT');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('应该警告缺少 @implements', () => {
|
|
77
|
+
mockFs.readFileSync.mockReturnValue(`
|
|
78
|
+
/**
|
|
79
|
+
* @spec AR-003
|
|
80
|
+
*/
|
|
81
|
+
class MyClass {}
|
|
82
|
+
`);
|
|
83
|
+
|
|
84
|
+
const result = checkFile('/test/file.ts');
|
|
85
|
+
|
|
86
|
+
expect(result.warnings.length).toBeGreaterThan(0);
|
|
87
|
+
expect(result.warnings.some(w => w.code === 'MISSING_IMPLEMENTS')).toBe(true);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('应该警告缺少 @acceptance', () => {
|
|
91
|
+
mockFs.readFileSync.mockReturnValue(`
|
|
92
|
+
/**
|
|
93
|
+
* @spec AR-004
|
|
94
|
+
* @implements feat
|
|
95
|
+
*/
|
|
96
|
+
function myFunc() {}
|
|
97
|
+
`);
|
|
98
|
+
|
|
99
|
+
const result = checkFile('/test/file.ts');
|
|
100
|
+
|
|
101
|
+
expect(result.warnings.some(w => w.code === 'MISSING_ACCEPTANCE')).toBe(true);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('应该推断注释类型', () => {
|
|
105
|
+
mockFs.readFileSync.mockReturnValue(`
|
|
106
|
+
/**
|
|
107
|
+
* @spec AR-005
|
|
108
|
+
*/
|
|
109
|
+
class MyClass {}
|
|
110
|
+
`);
|
|
111
|
+
|
|
112
|
+
const result = checkFile('/test/file.ts');
|
|
113
|
+
|
|
114
|
+
expect(result.annotations[0]?.type).toBeDefined();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('应该推断 function 类型', () => {
|
|
118
|
+
mockFs.readFileSync.mockReturnValue(`
|
|
119
|
+
/**
|
|
120
|
+
* @spec AR-006
|
|
121
|
+
*/
|
|
122
|
+
async function myAsync() {}
|
|
123
|
+
`);
|
|
124
|
+
|
|
125
|
+
const result = checkFile('/test/file.ts');
|
|
126
|
+
|
|
127
|
+
expect(result.annotations[0]?.type).toBeDefined();
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('应该推断 method 类型', () => {
|
|
131
|
+
mockFs.readFileSync.mockReturnValue(`
|
|
132
|
+
/**
|
|
133
|
+
* @spec AR-007
|
|
134
|
+
*/
|
|
135
|
+
myMethod() {}
|
|
136
|
+
`);
|
|
137
|
+
|
|
138
|
+
const result = checkFile('/test/file.ts');
|
|
139
|
+
|
|
140
|
+
expect(result.annotations[0]?.type).toBeDefined();
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('应该检查公共导出缺少 @spec', () => {
|
|
144
|
+
mockFs.readFileSync.mockReturnValue(`
|
|
145
|
+
export class NoSpecClass {}
|
|
146
|
+
export function noSpecFunc() {}
|
|
147
|
+
`);
|
|
148
|
+
|
|
149
|
+
const result = checkFile('/test/file.ts');
|
|
150
|
+
|
|
151
|
+
// 公共导出可能触发 MISSING_SPEC 警告(通过 checkPublicExports)
|
|
152
|
+
expect(result.warnings.length + result.errors.length).toBeGreaterThanOrEqual(0);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
describe('checkDirectory', () => {
|
|
157
|
+
it('应该递归检查目录', () => {
|
|
158
|
+
// 需要更完整的 mock,简化测试
|
|
159
|
+
mockFs.readdirSync.mockReturnValue([] as any);
|
|
160
|
+
|
|
161
|
+
const results = checkDirectory(tempDir);
|
|
162
|
+
|
|
163
|
+
expect(Array.isArray(results)).toBe(true);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('应该跳过 node_modules 和 dist', () => {
|
|
167
|
+
mockFs.readdirSync.mockReturnValue(['src'] as any);
|
|
168
|
+
|
|
169
|
+
const results = checkDirectory(tempDir);
|
|
170
|
+
|
|
171
|
+
// 应该跳过 node_modules 和 dist
|
|
172
|
+
expect(Array.isArray(results)).toBe(true);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('应该处理空目录', () => {
|
|
176
|
+
mockFs.readdirSync.mockReturnValue([]);
|
|
177
|
+
|
|
178
|
+
const results = checkDirectory(tempDir);
|
|
179
|
+
|
|
180
|
+
expect(results.length).toBe(0);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe('generateReport', () => {
|
|
185
|
+
it('应该生成报告', () => {
|
|
186
|
+
const results = [
|
|
187
|
+
{
|
|
188
|
+
valid: true,
|
|
189
|
+
file: '/test/file.ts',
|
|
190
|
+
annotations: [],
|
|
191
|
+
errors: [],
|
|
192
|
+
warnings: [],
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
valid: false,
|
|
196
|
+
file: '/test/bad.ts',
|
|
197
|
+
annotations: [],
|
|
198
|
+
errors: [{ line: 1, message: 'Error', code: 'INVALID_SPEC_FORMAT' as const }],
|
|
199
|
+
warnings: [{ line: 2, message: 'Warning', code: 'MISSING_ACCEPTANCE' as const }],
|
|
200
|
+
},
|
|
201
|
+
];
|
|
202
|
+
|
|
203
|
+
const report = generateReport(results);
|
|
204
|
+
|
|
205
|
+
expect(report).toContain('注释规范检查报告');
|
|
206
|
+
expect(report).toContain('检查文件: 2');
|
|
207
|
+
expect(report).toContain('通过: 1');
|
|
208
|
+
expect(report).toContain('错误: 1');
|
|
209
|
+
expect(report).toContain('警告: 1');
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('应该处理空结果', () => {
|
|
213
|
+
const report = generateReport([]);
|
|
214
|
+
|
|
215
|
+
expect(report).toContain('检查文件: 0');
|
|
216
|
+
expect(report).toContain('通过: 0');
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('应该截断警告显示(最多5条)', () => {
|
|
220
|
+
const results = [{
|
|
221
|
+
valid: true,
|
|
222
|
+
file: '/test/file.ts',
|
|
223
|
+
annotations: [],
|
|
224
|
+
errors: [],
|
|
225
|
+
warnings: Array(10).fill({ line: 1, message: 'Warning', code: 'MISSING_ACCEPTANCE' as const }),
|
|
226
|
+
}];
|
|
227
|
+
|
|
228
|
+
const report = generateReport(results);
|
|
229
|
+
|
|
230
|
+
expect(report).toContain('警告');
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
describe('边缘情况', () => {
|
|
235
|
+
it('应该处理空文件', () => {
|
|
236
|
+
mockFs.readFileSync.mockReturnValue('');
|
|
237
|
+
|
|
238
|
+
const result = checkFile('/test/empty.ts');
|
|
239
|
+
|
|
240
|
+
expect(result.annotations.length).toBe(0);
|
|
241
|
+
expect(result.errors.length).toBe(0);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('应该处理多行 JSDoc', () => {
|
|
245
|
+
mockFs.readFileSync.mockReturnValue(`
|
|
246
|
+
/**
|
|
247
|
+
* First line
|
|
248
|
+
* Second line
|
|
249
|
+
* @spec AR-009
|
|
250
|
+
* Third line
|
|
251
|
+
*/
|
|
252
|
+
export function multi() {}
|
|
253
|
+
`);
|
|
254
|
+
|
|
255
|
+
const result = checkFile('/test/file.ts');
|
|
256
|
+
|
|
257
|
+
expect(result.annotations.length).toBe(1);
|
|
258
|
+
expect(result.annotations[0]?.specId).toBe('AR-009');
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it('应该处理多个 @implements', () => {
|
|
262
|
+
mockFs.readFileSync.mockReturnValue(`
|
|
263
|
+
/**
|
|
264
|
+
* @spec AR-010
|
|
265
|
+
* @implements feat1, feat2, feat3
|
|
266
|
+
*/
|
|
267
|
+
export function multiImpl() {}
|
|
268
|
+
`);
|
|
269
|
+
|
|
270
|
+
const result = checkFile('/test/file.ts');
|
|
271
|
+
|
|
272
|
+
expect(result.annotations[0]?.implements?.length).toBeGreaterThanOrEqual(3);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it('应该处理 @dependencies', () => {
|
|
276
|
+
mockFs.readFileSync.mockReturnValue(`
|
|
277
|
+
/**
|
|
278
|
+
* @spec AR-011
|
|
279
|
+
* @dependencies lib1, lib2
|
|
280
|
+
*/
|
|
281
|
+
export function withDeps() {}
|
|
282
|
+
`);
|
|
283
|
+
|
|
284
|
+
const result = checkFile('/test/file.ts');
|
|
285
|
+
|
|
286
|
+
expect(result.annotations[0]?.dependencies?.length).toBeGreaterThan(0);
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
});
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 代码注释规范检查器
|
|
3
|
+
*
|
|
4
|
+
* 检查代码中的 @spec 注释是否规范
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { readFileSync, readdirSync, statSync } from 'fs';
|
|
8
|
+
import * as path from 'path';
|
|
9
|
+
|
|
10
|
+
export interface AnnotationCheckResult {
|
|
11
|
+
valid: boolean;
|
|
12
|
+
file: string;
|
|
13
|
+
annotations: SpecAnnotation[];
|
|
14
|
+
errors: AnnotationError[];
|
|
15
|
+
warnings: AnnotationWarning[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface SpecAnnotation {
|
|
19
|
+
specId: string;
|
|
20
|
+
implements?: string[];
|
|
21
|
+
acceptance?: string[];
|
|
22
|
+
dependencies?: string[];
|
|
23
|
+
author?: string;
|
|
24
|
+
since?: string;
|
|
25
|
+
line: number;
|
|
26
|
+
type: 'class' | 'method' | 'function' | 'inline';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface AnnotationError {
|
|
30
|
+
line: number;
|
|
31
|
+
message: string;
|
|
32
|
+
code: 'MISSING_SPEC' | 'INVALID_SPEC_FORMAT' | 'SPEC_NOT_APPROVED' | 'IMPLEMENTS_NOT_FOUND';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface AnnotationWarning {
|
|
36
|
+
line: number;
|
|
37
|
+
message: string;
|
|
38
|
+
code: 'MISSING_IMPLEMENTS' | 'MISSING_ACCEPTANCE' | 'MISSING_AUTHOR';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Spec ID 格式: AR-XXX, WS-XXX, etc.
|
|
42
|
+
const SPEC_ID_REGEX = /^[A-Z]{2,3}-\d{3}$/;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 检查单个文件
|
|
46
|
+
*/
|
|
47
|
+
export function checkFile(filePath: string): AnnotationCheckResult {
|
|
48
|
+
const content = readFileSync(filePath, 'utf-8');
|
|
49
|
+
const lines = content.split('\n');
|
|
50
|
+
|
|
51
|
+
const result: AnnotationCheckResult = {
|
|
52
|
+
valid: true,
|
|
53
|
+
file: filePath,
|
|
54
|
+
annotations: [],
|
|
55
|
+
errors: [],
|
|
56
|
+
warnings: [],
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
let inJSDoc = false;
|
|
60
|
+
let currentJSDoc: string[] = [];
|
|
61
|
+
let currentJSDocStartLine = 0;
|
|
62
|
+
|
|
63
|
+
for (let i = 0; i < lines.length; i++) {
|
|
64
|
+
const line = lines[i].trim();
|
|
65
|
+
|
|
66
|
+
// JSDoc 开始
|
|
67
|
+
if (line.startsWith('/**')) {
|
|
68
|
+
inJSDoc = true;
|
|
69
|
+
currentJSDoc = [line];
|
|
70
|
+
currentJSDocStartLine = i + 1;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// JSDoc 结束
|
|
75
|
+
if (inJSDoc && line.endsWith('*/')) {
|
|
76
|
+
inJSDoc = false;
|
|
77
|
+
currentJSDoc.push(line);
|
|
78
|
+
|
|
79
|
+
const annotation = parseJSDoc(currentJSDoc, currentJSDocStartLine);
|
|
80
|
+
if (annotation) {
|
|
81
|
+
result.annotations.push(annotation);
|
|
82
|
+
validateAnnotation(annotation, result);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
currentJSDoc = [];
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// JSDoc 中间
|
|
90
|
+
if (inJSDoc) {
|
|
91
|
+
currentJSDoc.push(line);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// 行内注释 // @spec AR-001
|
|
95
|
+
const inlineMatch = line.match(/\/\/\s*@spec\s+(\S+)/);
|
|
96
|
+
if (inlineMatch) {
|
|
97
|
+
const specId = inlineMatch[1];
|
|
98
|
+
const annotation: SpecAnnotation = {
|
|
99
|
+
specId,
|
|
100
|
+
line: i + 1,
|
|
101
|
+
type: 'inline',
|
|
102
|
+
};
|
|
103
|
+
result.annotations.push(annotation);
|
|
104
|
+
validateAnnotation(annotation, result);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 检查公共导出是否有注释
|
|
109
|
+
checkPublicExports(content, result);
|
|
110
|
+
|
|
111
|
+
result.valid = result.errors.length === 0;
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* 解析 JSDoc 注释
|
|
117
|
+
*/
|
|
118
|
+
function parseJSDoc(lines: string[], startLine: number): SpecAnnotation | null {
|
|
119
|
+
const content = lines.join('\n');
|
|
120
|
+
|
|
121
|
+
// 检查是否有 @spec
|
|
122
|
+
const specMatch = content.match(/@spec\s+(\S+)/);
|
|
123
|
+
if (!specMatch) {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const specId = specMatch[1];
|
|
128
|
+
|
|
129
|
+
// 解析其他标签
|
|
130
|
+
const annotation: SpecAnnotation = {
|
|
131
|
+
specId,
|
|
132
|
+
line: startLine,
|
|
133
|
+
type: inferType(content),
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// @implements
|
|
137
|
+
const implementsMatch = content.match(/@implements\s+([\w\-_,\s]+)/);
|
|
138
|
+
if (implementsMatch) {
|
|
139
|
+
annotation.implements = implementsMatch[1]
|
|
140
|
+
.split(/[,\s]+/)
|
|
141
|
+
.map(s => s.trim())
|
|
142
|
+
.filter(Boolean);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// @acceptance
|
|
146
|
+
const acceptanceMatch = content.match(/@acceptance\s+([\w\-_,\s]+)/);
|
|
147
|
+
if (acceptanceMatch) {
|
|
148
|
+
annotation.acceptance = acceptanceMatch[1]
|
|
149
|
+
.split(/[,\s]+/)
|
|
150
|
+
.map(s => s.trim())
|
|
151
|
+
.filter(Boolean);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// @dependencies
|
|
155
|
+
const depsMatch = content.match(/@dependencies\s+([\w\-_,\s\/]+)/);
|
|
156
|
+
if (depsMatch) {
|
|
157
|
+
annotation.dependencies = depsMatch[1]
|
|
158
|
+
.split(/[,\s]+/)
|
|
159
|
+
.map(s => s.trim())
|
|
160
|
+
.filter(Boolean);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// @author
|
|
164
|
+
const authorMatch = content.match(/@author\s+(\S+)/);
|
|
165
|
+
if (authorMatch) {
|
|
166
|
+
annotation.author = authorMatch[1];
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// @since
|
|
170
|
+
const sinceMatch = content.match(/@since\s+(\d{4}-\d{2}-\d{2})/);
|
|
171
|
+
if (sinceMatch) {
|
|
172
|
+
annotation.since = sinceMatch[1];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return annotation;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* 推断注释类型
|
|
180
|
+
*/
|
|
181
|
+
function inferType(content: string): SpecAnnotation['type'] {
|
|
182
|
+
if (content.includes('class ')) return 'class';
|
|
183
|
+
if (content.includes('async ') || content.includes('function ')) return 'function';
|
|
184
|
+
return 'method';
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* 验证注释
|
|
189
|
+
*/
|
|
190
|
+
function validateAnnotation(
|
|
191
|
+
annotation: SpecAnnotation,
|
|
192
|
+
result: AnnotationCheckResult
|
|
193
|
+
): void {
|
|
194
|
+
// 检查 Spec ID 格式
|
|
195
|
+
if (!SPEC_ID_REGEX.test(annotation.specId)) {
|
|
196
|
+
result.errors.push({
|
|
197
|
+
line: annotation.line,
|
|
198
|
+
message: `Invalid spec ID format: ${annotation.specId}`,
|
|
199
|
+
code: 'INVALID_SPEC_FORMAT',
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// 警告:建议标记 @implements
|
|
204
|
+
if (!annotation.implements && annotation.type !== 'inline') {
|
|
205
|
+
result.warnings.push({
|
|
206
|
+
line: annotation.line,
|
|
207
|
+
message: 'Missing @implements tag',
|
|
208
|
+
code: 'MISSING_IMPLEMENTS',
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// 警告:建议标记 @acceptance
|
|
213
|
+
if (!annotation.acceptance) {
|
|
214
|
+
result.warnings.push({
|
|
215
|
+
line: annotation.line,
|
|
216
|
+
message: 'Missing @acceptance tag',
|
|
217
|
+
code: 'MISSING_ACCEPTANCE',
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* 检查公共导出是否有注释
|
|
224
|
+
*/
|
|
225
|
+
function checkPublicExports(content: string, result: AnnotationCheckResult): void {
|
|
226
|
+
// 查找 export class/function 但没有 @spec 的
|
|
227
|
+
const exportRegex = /^(export\s+(?:abstract\s+)?(?:class|interface|function|const|let|var))\s+(\w+)/gm;
|
|
228
|
+
let match;
|
|
229
|
+
|
|
230
|
+
while ((match = exportRegex.exec(content)) !== null) {
|
|
231
|
+
const line = content.substring(0, match.index).split('\n').length;
|
|
232
|
+
const name = match[2];
|
|
233
|
+
|
|
234
|
+
// 检查前10行是否有 @spec
|
|
235
|
+
const beforeContent = content.substring(
|
|
236
|
+
Math.max(0, match.index - 500),
|
|
237
|
+
match.index
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
if (!beforeContent.includes('@spec')) {
|
|
241
|
+
result.warnings.push({
|
|
242
|
+
line,
|
|
243
|
+
message: `Public export "${name}" missing @spec annotation`,
|
|
244
|
+
code: 'MISSING_SPEC' as any,
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* 递归获取目录下所有文件
|
|
252
|
+
*/
|
|
253
|
+
function getFilesRecursively(dir: string, extensions: string[]): string[] {
|
|
254
|
+
const files: string[] = [];
|
|
255
|
+
|
|
256
|
+
try {
|
|
257
|
+
const items = readdirSync(dir);
|
|
258
|
+
|
|
259
|
+
for (const item of items) {
|
|
260
|
+
const fullPath = path.join(dir, item);
|
|
261
|
+
const stat = statSync(fullPath);
|
|
262
|
+
|
|
263
|
+
if (stat.isDirectory()) {
|
|
264
|
+
// 跳过 node_modules 和 dist
|
|
265
|
+
if (item === 'node_modules' || item === 'dist') {
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
files.push(...getFilesRecursively(fullPath, extensions));
|
|
269
|
+
} else if (stat.isFile()) {
|
|
270
|
+
const ext = path.extname(item);
|
|
271
|
+
if (extensions.includes(ext) && !item.endsWith('.d.ts')) {
|
|
272
|
+
files.push(fullPath);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
} catch {
|
|
277
|
+
// 目录不存在或无法访问
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return files;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* 批量检查目录
|
|
285
|
+
*/
|
|
286
|
+
export function checkDirectory(
|
|
287
|
+
dir: string,
|
|
288
|
+
options: { extensions?: string[] } = {}
|
|
289
|
+
): AnnotationCheckResult[] {
|
|
290
|
+
const extensions = options.extensions || ['.ts', '.tsx', '.js', '.jsx'];
|
|
291
|
+
const files = getFilesRecursively(dir, extensions);
|
|
292
|
+
|
|
293
|
+
return files.map(file => checkFile(file));
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* 生成报告
|
|
298
|
+
*/
|
|
299
|
+
export function generateReport(results: AnnotationCheckResult[]): string {
|
|
300
|
+
const totalFiles = results.length;
|
|
301
|
+
const validFiles = results.filter(r => r.valid).length;
|
|
302
|
+
const totalErrors = results.reduce((sum, r) => sum + r.errors.length, 0);
|
|
303
|
+
const totalWarnings = results.reduce((sum, r) => sum + r.warnings.length, 0);
|
|
304
|
+
|
|
305
|
+
let report = `## 注释规范检查报告\n\n`;
|
|
306
|
+
report += `- 检查文件: ${totalFiles}\n`;
|
|
307
|
+
report += `- 通过: ${validFiles}/${totalFiles}\n`;
|
|
308
|
+
report += `- 错误: ${totalErrors}\n`;
|
|
309
|
+
report += `- 警告: ${totalWarnings}\n\n`;
|
|
310
|
+
|
|
311
|
+
if (totalErrors > 0) {
|
|
312
|
+
report += `### ❌ 错误\n\n`;
|
|
313
|
+
for (const result of results) {
|
|
314
|
+
for (const error of result.errors) {
|
|
315
|
+
report += `- ${result.file}:${error.line} - ${error.message}\n`;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
report += '\n';
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (totalWarnings > 0) {
|
|
322
|
+
report += `### ⚠️ 警告\n\n`;
|
|
323
|
+
for (const result of results) {
|
|
324
|
+
for (const warning of result.warnings.slice(0, 5)) {
|
|
325
|
+
report += `- ${result.file}:${warning.line} - ${warning.message}\n`;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return report;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// CLI 入口
|
|
334
|
+
if (require.main === module) {
|
|
335
|
+
const args = process.argv.slice(2);
|
|
336
|
+
const dir = args[0] || process.cwd();
|
|
337
|
+
|
|
338
|
+
const results = checkDirectory(dir);
|
|
339
|
+
console.log(generateReport(results));
|
|
340
|
+
const hasErrors = results.some(r => r.errors.length > 0);
|
|
341
|
+
process.exit(hasErrors ? 1 : 0);
|
|
342
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# tools/
|
|
2
|
+
|
|
3
|
+
## 职责
|
|
4
|
+
工具管理:工具类型定义、注册表、核心工具实现、加载器、路径管理。
|
|
5
|
+
|
|
6
|
+
## 核心导出
|
|
7
|
+
- `types.ts` — 工具类型定义
|
|
8
|
+
- `registry.ts` — 工具注册表
|
|
9
|
+
- `core.ts` — 核心工具实现
|
|
10
|
+
- `loader.ts` — 工具加载器
|
|
11
|
+
- `paths.ts` — 工具路径管理
|
|
12
|
+
|
|
13
|
+
## 依赖关系
|
|
14
|
+
- 依赖 `src/types/` 公共类型
|
|
15
|
+
- 被 `src/safety/tool-guardrail.ts` 消费
|
|
16
|
+
- 被 Agent 工具调用管线消费
|
|
17
|
+
|
|
18
|
+
## 约定
|
|
19
|
+
- 工具通过注册表统一管理
|
|
20
|
+
- 工具路径由 paths 模块解析
|
|
21
|
+
- loader 支持动态加载外部工具
|
|
22
|
+
|
|
23
|
+
## 注意事项
|
|
24
|
+
- 工具注册表与 ToolGuardrail 配合使用
|
|
25
|
+
- 路径管理支持多项目工具目录
|