@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,563 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 跨工程接口契约检查
|
|
3
|
+
*
|
|
4
|
+
* 检测多工程开发时的接口不一致问题
|
|
5
|
+
*
|
|
6
|
+
* 可通过 CrossProjectConfig 自定义工程依赖关系和契约位置,
|
|
7
|
+
* 使此模块适用于任意多工程项目,而非仅限于 agent-studio 生态。
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { runCommand } from '../utils/exec';
|
|
11
|
+
import { existsSync, readFileSync, readdirSync } from 'fs';
|
|
12
|
+
import * as path from 'path';
|
|
13
|
+
|
|
14
|
+
export interface CrossProjectViolation {
|
|
15
|
+
type: 'api-mismatch' | 'doc-code-mismatch' | 'breaking-change' | 'missing-implementation';
|
|
16
|
+
severity: 'error' | 'warning';
|
|
17
|
+
message: string;
|
|
18
|
+
fromProject: string;
|
|
19
|
+
toProject: string;
|
|
20
|
+
details: {
|
|
21
|
+
interfaceName?: string;
|
|
22
|
+
fieldName?: string;
|
|
23
|
+
expectedType?: string;
|
|
24
|
+
actualType?: string;
|
|
25
|
+
location?: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface CrossProjectContext {
|
|
30
|
+
baseBranch: string;
|
|
31
|
+
changedProjects: string[];
|
|
32
|
+
changedFiles: string[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 跨工程检查配置
|
|
37
|
+
*
|
|
38
|
+
* 允许调用方自定义工程依赖关系和契约位置,
|
|
39
|
+
* 而非使用硬编码的默认值。
|
|
40
|
+
*/
|
|
41
|
+
export interface CrossProjectConfig {
|
|
42
|
+
/** 工程依赖关系图:project -> 它依赖的项目列表 */
|
|
43
|
+
dependencies: Record<string, string[]>;
|
|
44
|
+
/** 接口契约定义位置:pair name -> 文件路径列表 */
|
|
45
|
+
contractLocations: Record<string, string[]>;
|
|
46
|
+
/** 依赖过滤函数:筛选哪些包参与契约检查。默认不过滤(全部参与) */
|
|
47
|
+
dependencyFilter?: (depName: string) => boolean;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 默认配置:从 monorepo 结构自动推断依赖关系
|
|
52
|
+
*/
|
|
53
|
+
function getDefaultConfig(): CrossProjectConfig {
|
|
54
|
+
const fs = require('fs');
|
|
55
|
+
const path = require('path');
|
|
56
|
+
const cwd = process.cwd();
|
|
57
|
+
|
|
58
|
+
// 扫描 packages/ 和 apps/ 下的 package.json 获取包名
|
|
59
|
+
const dependencies: Record<string, string[]> = {};
|
|
60
|
+
const contractLocations: Record<string, string[]> = {};
|
|
61
|
+
|
|
62
|
+
for (const dir of ['packages', 'apps']) {
|
|
63
|
+
const dirPath = path.join(cwd, dir);
|
|
64
|
+
if (!fs.existsSync(dirPath)) continue;
|
|
65
|
+
|
|
66
|
+
for (const entry of fs.readdirSync(dirPath)) {
|
|
67
|
+
const pkgJsonPath = path.join(dirPath, entry, 'package.json');
|
|
68
|
+
if (!fs.existsSync(pkgJsonPath)) continue;
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8'));
|
|
72
|
+
const name = pkgJson.name || entry;
|
|
73
|
+
const deps = Object.keys({
|
|
74
|
+
...pkgJson.dependencies,
|
|
75
|
+
...pkgJson.peerDependencies,
|
|
76
|
+
});
|
|
77
|
+
// 默认不过滤,全部参与检查。调用方可通过 CrossProjectConfig.dependencyFilter 按需筛选
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
dependencies[name] = deps;
|
|
81
|
+
|
|
82
|
+
// 约定:src/api/ 或 src/index.ts 为接口契约位置
|
|
83
|
+
const srcDir = path.join(dirPath, entry, 'src');
|
|
84
|
+
if (fs.existsSync(srcDir)) {
|
|
85
|
+
contractLocations[name] = [path.join(dir, entry, 'src')];
|
|
86
|
+
}
|
|
87
|
+
} catch {
|
|
88
|
+
// package.json 解析失败,跳过
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return { dependencies, contractLocations };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 检查跨工程接口一致性
|
|
98
|
+
*
|
|
99
|
+
* @param context 跨工程上下文
|
|
100
|
+
* @param config 工程依赖关系和契约位置配置(可选,默认从 monorepo 自动推断)
|
|
101
|
+
*/
|
|
102
|
+
export async function checkCrossProjectContracts(
|
|
103
|
+
context: CrossProjectContext,
|
|
104
|
+
config?: CrossProjectConfig
|
|
105
|
+
): Promise<CrossProjectViolation[]> {
|
|
106
|
+
const violations: CrossProjectViolation[] = [];
|
|
107
|
+
const cfg = config || getDefaultConfig();
|
|
108
|
+
|
|
109
|
+
// 1. 检查 API 变更是否同步到调用方
|
|
110
|
+
violations.push(...await checkApiSync(context, cfg));
|
|
111
|
+
|
|
112
|
+
// 2. 检查类型定义一致性
|
|
113
|
+
violations.push(...await checkTypeConsistency(context, cfg));
|
|
114
|
+
|
|
115
|
+
// 3. 检查破坏性变更
|
|
116
|
+
violations.push(...await checkBreakingChanges(context, cfg));
|
|
117
|
+
|
|
118
|
+
return violations;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* 检查 API 变更同步
|
|
123
|
+
*/
|
|
124
|
+
async function checkApiSync(
|
|
125
|
+
context: CrossProjectContext,
|
|
126
|
+
config: CrossProjectConfig
|
|
127
|
+
): Promise<CrossProjectViolation[]> {
|
|
128
|
+
const violations: CrossProjectViolation[] = [];
|
|
129
|
+
|
|
130
|
+
for (const project of context.changedProjects) {
|
|
131
|
+
const dependents = getDependents(project, config);
|
|
132
|
+
const apiChanges = await getApiChanges(project, context.baseBranch);
|
|
133
|
+
|
|
134
|
+
for (const change of apiChanges) {
|
|
135
|
+
for (const dependent of dependents) {
|
|
136
|
+
const dependentUpdated = context.changedFiles.some(f =>
|
|
137
|
+
f.includes(`${dependent}/src/`)
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
if (!dependentUpdated && isPublicApi(change)) {
|
|
141
|
+
violations.push({
|
|
142
|
+
type: 'api-mismatch',
|
|
143
|
+
severity: 'error',
|
|
144
|
+
message: `'${project}' API '${change.name}' 变更未同步到 '${dependent}'`,
|
|
145
|
+
fromProject: project,
|
|
146
|
+
toProject: dependent,
|
|
147
|
+
details: {
|
|
148
|
+
interfaceName: change.name,
|
|
149
|
+
location: change.file,
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return violations;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* 检查类型定义一致性
|
|
162
|
+
*/
|
|
163
|
+
async function checkTypeConsistency(
|
|
164
|
+
context: CrossProjectContext,
|
|
165
|
+
config: CrossProjectConfig
|
|
166
|
+
): Promise<CrossProjectViolation[]> {
|
|
167
|
+
const violations: CrossProjectViolation[] = [];
|
|
168
|
+
|
|
169
|
+
for (const [pair, locations] of Object.entries(config.contractLocations)) {
|
|
170
|
+
const [from, to] = pair.split('-');
|
|
171
|
+
if (!context.changedProjects.includes(from) && !context.changedProjects.includes(to)) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const fromTypes = extractExportedTypes(from);
|
|
176
|
+
const toUsage = extractTypeUsage(to, fromTypes);
|
|
177
|
+
|
|
178
|
+
for (const [typeName, usage] of Object.entries(toUsage)) {
|
|
179
|
+
if (usage.hasMismatch) {
|
|
180
|
+
violations.push({
|
|
181
|
+
type: 'doc-code-mismatch',
|
|
182
|
+
severity: 'error',
|
|
183
|
+
message: `类型 '${typeName}' 在 ${to} 中的使用与 ${from} 定义不一致`,
|
|
184
|
+
fromProject: from,
|
|
185
|
+
toProject: to,
|
|
186
|
+
details: {
|
|
187
|
+
interfaceName: typeName,
|
|
188
|
+
expectedType: usage.expected,
|
|
189
|
+
actualType: usage.actual,
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return violations;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* 检查破坏性变更
|
|
201
|
+
*/
|
|
202
|
+
async function checkBreakingChanges(
|
|
203
|
+
context: CrossProjectContext,
|
|
204
|
+
config: CrossProjectConfig
|
|
205
|
+
): Promise<CrossProjectViolation[]> {
|
|
206
|
+
const violations: CrossProjectViolation[] = [];
|
|
207
|
+
|
|
208
|
+
for (const project of context.changedProjects) {
|
|
209
|
+
const dependents = getDependents(project, config);
|
|
210
|
+
|
|
211
|
+
for (const change of await getApiChanges(project, context.baseBranch)) {
|
|
212
|
+
if (isBreakingChange(change)) {
|
|
213
|
+
// 检查所有依赖方是否已适配
|
|
214
|
+
for (const dependent of dependents) {
|
|
215
|
+
const adapted = context.changedProjects.includes(dependent);
|
|
216
|
+
if (!adapted) {
|
|
217
|
+
violations.push({
|
|
218
|
+
type: 'breaking-change',
|
|
219
|
+
severity: 'error',
|
|
220
|
+
message: `破坏性变更 '${change.name}' 需要 ${dependent} 适配`,
|
|
221
|
+
fromProject: project,
|
|
222
|
+
toProject: dependent,
|
|
223
|
+
details: {
|
|
224
|
+
interfaceName: change.name,
|
|
225
|
+
location: change.file,
|
|
226
|
+
},
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return violations;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* 检查文档-代码一致性
|
|
239
|
+
* 场景:文档写了接口,代码没实现
|
|
240
|
+
*/
|
|
241
|
+
export async function checkDocCodeConsistency(
|
|
242
|
+
docPath: string,
|
|
243
|
+
projects: string[]
|
|
244
|
+
): Promise<CrossProjectViolation[]> {
|
|
245
|
+
const violations: CrossProjectViolation[] = [];
|
|
246
|
+
|
|
247
|
+
// 解析文档中的接口定义
|
|
248
|
+
const docInterfaces = parseDocInterfaces(docPath);
|
|
249
|
+
|
|
250
|
+
for (const [project, interfaces] of Object.entries(docInterfaces)) {
|
|
251
|
+
if (!projects.includes(project)) continue;
|
|
252
|
+
|
|
253
|
+
const actualExports = extractExportedApis(project);
|
|
254
|
+
|
|
255
|
+
for (const docInterface of interfaces) {
|
|
256
|
+
const implemented = actualExports.find(e => e.name === docInterface.name);
|
|
257
|
+
|
|
258
|
+
if (!implemented) {
|
|
259
|
+
violations.push({
|
|
260
|
+
type: 'missing-implementation',
|
|
261
|
+
severity: 'error',
|
|
262
|
+
message: `文档接口 '${docInterface.name}' 在 ${project} 中未实现`,
|
|
263
|
+
fromProject: 'documentation',
|
|
264
|
+
toProject: project,
|
|
265
|
+
details: {
|
|
266
|
+
interfaceName: docInterface.name,
|
|
267
|
+
location: docPath,
|
|
268
|
+
},
|
|
269
|
+
});
|
|
270
|
+
} else if (!isCompatible(docInterface, implemented)) {
|
|
271
|
+
violations.push({
|
|
272
|
+
type: 'doc-code-mismatch',
|
|
273
|
+
severity: 'warning',
|
|
274
|
+
message: `接口 '${docInterface.name}' 实现与文档不一致`,
|
|
275
|
+
fromProject: 'documentation',
|
|
276
|
+
toProject: project,
|
|
277
|
+
details: {
|
|
278
|
+
interfaceName: docInterface.name,
|
|
279
|
+
expectedType: JSON.stringify(docInterface.signature),
|
|
280
|
+
actualType: JSON.stringify(implemented.signature),
|
|
281
|
+
},
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return violations;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// ============ 辅助函数 ============
|
|
291
|
+
|
|
292
|
+
async function getApiChanges(project: string, baseBranch: string): Promise<ApiChange[]> {
|
|
293
|
+
try {
|
|
294
|
+
const projectPath = resolveProjectPath(project);
|
|
295
|
+
|
|
296
|
+
const output = await runCommand(
|
|
297
|
+
`git diff ${baseBranch}...HEAD --name-only -- "${projectPath}/src/"`
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
const files = output.trim().split('\n').filter(f => f);
|
|
301
|
+
return Promise.all(files.map(async (f) => ({
|
|
302
|
+
file: f,
|
|
303
|
+
name: extractApiName(f),
|
|
304
|
+
changeType: await detectChangeType(f, baseBranch),
|
|
305
|
+
})));
|
|
306
|
+
} catch {
|
|
307
|
+
return [];
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function isPublicApi(change: ApiChange): boolean {
|
|
312
|
+
// 检查是否为公开 API(导出、非内部)
|
|
313
|
+
return !change.name.startsWith('_') && !change.file.includes('/internal/');
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function isBreakingChange(change: ApiChange): boolean {
|
|
317
|
+
// 检测是否为破坏性变更
|
|
318
|
+
return change.changeType === 'remove' ||
|
|
319
|
+
change.changeType === 'signature-change' ||
|
|
320
|
+
change.changeType === 'rename';
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function getDependents(project: string, config: CrossProjectConfig): string[] {
|
|
324
|
+
return Object.entries(config.dependencies)
|
|
325
|
+
.filter(([_, deps]) => deps.includes(project))
|
|
326
|
+
.map(([name, _]) => name);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
interface ApiChange {
|
|
330
|
+
file: string;
|
|
331
|
+
name: string;
|
|
332
|
+
changeType: 'add' | 'remove' | 'modify' | 'rename' | 'signature-change';
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// ============ 辅助函数实现 ============
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* 递归查找目录中的 .ts 文件(排除 node_modules/__tests__/dist/.d.ts)
|
|
339
|
+
*/
|
|
340
|
+
function findTsFiles(dir: string): string[] {
|
|
341
|
+
if (!existsSync(dir)) return [];
|
|
342
|
+
const results: string[] = [];
|
|
343
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
344
|
+
for (const entry of entries) {
|
|
345
|
+
const fullPath = path.join(dir, entry.name);
|
|
346
|
+
if (entry.isDirectory()) {
|
|
347
|
+
if (entry.name === 'node_modules' || entry.name === '__tests__' || entry.name === 'dist') continue;
|
|
348
|
+
results.push(...findTsFiles(fullPath));
|
|
349
|
+
} else if (entry.name.endsWith('.ts') && !entry.name.endsWith('.d.ts')) {
|
|
350
|
+
results.push(fullPath);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return results;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function extractApiName(file: string): string {
|
|
357
|
+
return path.basename(file, '.ts');
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
async function detectChangeType(file: string, baseBranch: string): Promise<ApiChange['changeType']> {
|
|
361
|
+
try {
|
|
362
|
+
const statusOutput = await runCommand(
|
|
363
|
+
`git diff ${baseBranch}...HEAD --name-status -- "${file}"`
|
|
364
|
+
);
|
|
365
|
+
const statusLine = statusOutput.trim().split('\n')[0];
|
|
366
|
+
if (!statusLine) return 'modify';
|
|
367
|
+
|
|
368
|
+
const statusCode = statusLine.charAt(0);
|
|
369
|
+
if (statusCode === 'A') return 'add';
|
|
370
|
+
if (statusCode === 'D') return 'remove';
|
|
371
|
+
if (statusCode === 'R') return 'rename';
|
|
372
|
+
|
|
373
|
+
// M (modified) — check if export signatures changed
|
|
374
|
+
if (statusCode === 'M') {
|
|
375
|
+
const diff = await runCommand(`git diff ${baseBranch}...HEAD -- "${file}"`);
|
|
376
|
+
const signaturePattern = /^[+-]\s*export\s+(?:async\s+)?(?:function|interface|type|class|enum)\s+\w+/m;
|
|
377
|
+
if (signaturePattern.test(diff)) {
|
|
378
|
+
return 'signature-change';
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
return 'modify';
|
|
383
|
+
} catch {
|
|
384
|
+
return 'modify';
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function extractExportedTypes(project: string): string[] {
|
|
389
|
+
const projectPath = resolveProjectPath(project);
|
|
390
|
+
const srcDir = path.join(projectPath, 'src');
|
|
391
|
+
const files = findTsFiles(srcDir);
|
|
392
|
+
const types = new Set<string>();
|
|
393
|
+
|
|
394
|
+
for (const file of files) {
|
|
395
|
+
try {
|
|
396
|
+
const content = readFileSync(file, 'utf-8');
|
|
397
|
+
const regex = /export\s+(?:interface|type|enum)\s+(\w+)/g;
|
|
398
|
+
let match;
|
|
399
|
+
while ((match = regex.exec(content)) !== null) {
|
|
400
|
+
types.add(match[1]);
|
|
401
|
+
}
|
|
402
|
+
} catch {
|
|
403
|
+
// 文件读取失败,跳过
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
return [...types];
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function extractTypeUsage(project: string, types: string[]): Record<string, { hasMismatch: boolean; expected?: string; actual?: string }> {
|
|
411
|
+
const projectPath = resolveProjectPath(project);
|
|
412
|
+
const srcDir = path.join(projectPath, 'src');
|
|
413
|
+
const files = findTsFiles(srcDir);
|
|
414
|
+
const result: Record<string, { hasMismatch: boolean; expected?: string; actual?: string }> = {};
|
|
415
|
+
|
|
416
|
+
for (const typeName of types) {
|
|
417
|
+
let importedIn = false;
|
|
418
|
+
let usedIn = false;
|
|
419
|
+
|
|
420
|
+
for (const file of files) {
|
|
421
|
+
try {
|
|
422
|
+
const content = readFileSync(file, 'utf-8');
|
|
423
|
+
// 检查是否导入了该类型
|
|
424
|
+
const importRegex = new RegExp(`import\\s+(?:type\\s+)?\\{[^}]*\\b${typeName}\\b[^}]*\\}\\s+from`);
|
|
425
|
+
if (importRegex.test(content)) {
|
|
426
|
+
importedIn = true;
|
|
427
|
+
// 检查是否在 import 行之外使用了该类型
|
|
428
|
+
const lines = content.split('\n');
|
|
429
|
+
for (const line of lines) {
|
|
430
|
+
if (line.trim().startsWith('import ')) continue;
|
|
431
|
+
if (new RegExp(`\\b${typeName}\\b`).test(line)) {
|
|
432
|
+
usedIn = true;
|
|
433
|
+
break;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
} catch {
|
|
438
|
+
// 文件读取失败,跳过
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// 导入但未使用 → 可能是版本不一致
|
|
443
|
+
if (importedIn && !usedIn) {
|
|
444
|
+
result[typeName] = { hasMismatch: true, expected: typeName, actual: 'unused import' };
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
return result;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function parseDocInterfaces(docPath: string): Record<string, Array<{name: string, signature: string}>> {
|
|
452
|
+
if (!existsSync(docPath)) return {};
|
|
453
|
+
|
|
454
|
+
try {
|
|
455
|
+
const content = readFileSync(docPath, 'utf-8');
|
|
456
|
+
const lines = content.split('\n');
|
|
457
|
+
const result: Record<string, Array<{name: string, signature: string}>> = {};
|
|
458
|
+
let currentProject: string | null = null;
|
|
459
|
+
|
|
460
|
+
for (const line of lines) {
|
|
461
|
+
// 匹配 ## project-name
|
|
462
|
+
const headerMatch = line.match(/^##\s+(\S[\w-]*)/);
|
|
463
|
+
if (headerMatch) {
|
|
464
|
+
currentProject = headerMatch[1];
|
|
465
|
+
if (!result[currentProject]) result[currentProject] = [];
|
|
466
|
+
continue;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// 匹配 - `functionName(params): returnType`
|
|
470
|
+
if (currentProject) {
|
|
471
|
+
const sigMatch = line.match(/^-\s+`([^`]+)`/);
|
|
472
|
+
if (sigMatch) {
|
|
473
|
+
const signature = sigMatch[1];
|
|
474
|
+
const nameMatch = signature.match(/^(\w+)\s*\(/);
|
|
475
|
+
const name = nameMatch ? nameMatch[1] : signature;
|
|
476
|
+
result[currentProject].push({ name, signature });
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
return result;
|
|
482
|
+
} catch {
|
|
483
|
+
return {};
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
function extractExportedApis(project: string): Array<{name: string, signature: string}> {
|
|
488
|
+
const projectPath = resolveProjectPath(project);
|
|
489
|
+
const srcDir = path.join(projectPath, 'src');
|
|
490
|
+
const files = findTsFiles(srcDir);
|
|
491
|
+
const apis: Array<{name: string, signature: string}> = [];
|
|
492
|
+
const seen = new Set<string>();
|
|
493
|
+
|
|
494
|
+
for (const file of files) {
|
|
495
|
+
try {
|
|
496
|
+
const content = readFileSync(file, 'utf-8');
|
|
497
|
+
|
|
498
|
+
// export function / export async function
|
|
499
|
+
const funcRegex = /export\s+(?:async\s+)?function\s+(\w+)\s*\(([^)]*)\)(?::\s*(\S+))?/g;
|
|
500
|
+
let match;
|
|
501
|
+
while ((match = funcRegex.exec(content)) !== null) {
|
|
502
|
+
const name = match[1];
|
|
503
|
+
if (seen.has(name)) continue;
|
|
504
|
+
seen.add(name);
|
|
505
|
+
const params = match[2] ? match[2].trim() : '';
|
|
506
|
+
const returnType = match[3] || 'void';
|
|
507
|
+
apis.push({ name, signature: `${name}(${params}): ${returnType}` });
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// export class
|
|
511
|
+
const classRegex = /export\s+class\s+(\w+)/g;
|
|
512
|
+
while ((match = classRegex.exec(content)) !== null) {
|
|
513
|
+
const name = match[1];
|
|
514
|
+
if (!seen.has(name)) {
|
|
515
|
+
seen.add(name);
|
|
516
|
+
apis.push({ name, signature: name });
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// export const arrow functions
|
|
521
|
+
const arrowRegex = /export\s+const\s+(\w+)\s*=\s*(?:async\s+)?\(/g;
|
|
522
|
+
while ((match = arrowRegex.exec(content)) !== null) {
|
|
523
|
+
const name = match[1];
|
|
524
|
+
if (!seen.has(name)) {
|
|
525
|
+
seen.add(name);
|
|
526
|
+
apis.push({ name, signature: name });
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
} catch {
|
|
530
|
+
// 文件读取失败,跳过
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
return apis;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
function isCompatible(doc: any, actual: any): boolean {
|
|
538
|
+
return JSON.stringify(doc.signature) === JSON.stringify(actual.signature);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* 解析项目在 monorepo 中的实际路径
|
|
543
|
+
* 支持 packages/xxx、apps/xxx、projects/xxx 三种常见结构
|
|
544
|
+
* 按优先级返回第一个存在的路径;都不存在时返回第一个候选(git 命令会优雅处理)
|
|
545
|
+
*/
|
|
546
|
+
function resolveProjectPath(project: string): string {
|
|
547
|
+
// 包名可能是 @scope/name 格式,取最后部分作为目录名
|
|
548
|
+
const dirName = project.includes('/') ? project.split('/').pop()! : project;
|
|
549
|
+
|
|
550
|
+
const candidates = [
|
|
551
|
+
path.join('packages', dirName),
|
|
552
|
+
path.join('apps', dirName),
|
|
553
|
+
path.join('projects', dirName),
|
|
554
|
+
path.join('packages', project), // 完整包名
|
|
555
|
+
];
|
|
556
|
+
|
|
557
|
+
for (const candidate of candidates) {
|
|
558
|
+
if (existsSync(candidate)) return candidate;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
// 都不存在时返回第一个候选(git 命令对不存在路径返回空,不会报错)
|
|
562
|
+
return candidates[0];
|
|
563
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# cli/commands/
|
|
2
|
+
|
|
3
|
+
## 职责
|
|
4
|
+
CLI 子命令实现:21 个命令覆盖约束检查/门禁验证/文档同步/知识管理/失败诊断/发布/会话分析等。
|
|
5
|
+
|
|
6
|
+
## 核心导出(21 命令)
|
|
7
|
+
check / validate / passes-gate / init / report / status / flow / spec / acceptance / performance / security / contract / review / command / sync-docs / knowledge / failure / posteval-plan / release / analyze-sessions / update-user-model
|
|
8
|
+
|
|
9
|
+
## 依赖关系
|
|
10
|
+
- 依赖 `src/core/constraints/` 约束引擎
|
|
11
|
+
- 依赖 `src/gates/` 门禁系统
|
|
12
|
+
- 依赖 `src/monitoring/` 追踪/诊断
|
|
13
|
+
- 依赖 `src/knowledge/` 知识引擎
|
|
14
|
+
- 依赖 `src/failure/` 失败记录
|
|
15
|
+
- 被 `bin/harness.js` CLI 入口注册
|
|
16
|
+
|
|
17
|
+
## 约定
|
|
18
|
+
- 每个命令一个文件,命名与命令名一致
|
|
19
|
+
- 命令必须在 index.ts 中注册导出
|
|
20
|
+
- 命令选项类型命名规范:XxxOptions
|
|
21
|
+
|
|
22
|
+
## 注意事项
|
|
23
|
+
- 新增命令需同步更新 CLAUDE.md / CAPABILITIES.md / src/CONTEXT.md
|
|
24
|
+
- knowledge 命令包含 9 个子操作(list/search/import/decay/stats/upsert/sync-status/sync-rag)
|