@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,499 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent 诊断接口
|
|
3
|
+
*
|
|
4
|
+
* 当检测到异常时,提供 Agent 分析 traces 的能力
|
|
5
|
+
*
|
|
6
|
+
* 成本控制:
|
|
7
|
+
* - 仅在有异常时触发
|
|
8
|
+
* - 精简 prompt,不喂全部 traces
|
|
9
|
+
* - ~2000 Token/次
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type {
|
|
13
|
+
ExecutionTrace,
|
|
14
|
+
TraceAnomaly,
|
|
15
|
+
TraceSummary,
|
|
16
|
+
} from '../types/trace';
|
|
17
|
+
import type { LLMAdapter } from '../llm/types';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 诊断结果
|
|
21
|
+
*/
|
|
22
|
+
export interface Diagnosis {
|
|
23
|
+
/** 异常 ID */
|
|
24
|
+
anomalyId: string;
|
|
25
|
+
|
|
26
|
+
/** 约束 ID */
|
|
27
|
+
constraintId: string;
|
|
28
|
+
|
|
29
|
+
/** 诊断时间 */
|
|
30
|
+
diagnosedAt: number;
|
|
31
|
+
|
|
32
|
+
/** 根因分析 */
|
|
33
|
+
rootCause: {
|
|
34
|
+
/** 主要原因 */
|
|
35
|
+
primary: string;
|
|
36
|
+
|
|
37
|
+
/** 次要原因 */
|
|
38
|
+
secondary?: string[];
|
|
39
|
+
|
|
40
|
+
/** 相关 traces */
|
|
41
|
+
evidence: ExecutionTrace[];
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** 影响评估 */
|
|
45
|
+
impact: {
|
|
46
|
+
/** 影响程度 */
|
|
47
|
+
severity: 'low' | 'medium' | 'high';
|
|
48
|
+
|
|
49
|
+
/** 影响范围 */
|
|
50
|
+
scope: 'single_project' | 'multiple_projects' | 'team';
|
|
51
|
+
|
|
52
|
+
/** 用户影响 */
|
|
53
|
+
userImpact: string;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/** 改进建议 */
|
|
57
|
+
recommendations: {
|
|
58
|
+
/** 建议类型 */
|
|
59
|
+
type: 'add_exception' | 'adjust_threshold' | 'modify_constraint' | 'user_training';
|
|
60
|
+
|
|
61
|
+
/** 建议内容 */
|
|
62
|
+
content: string;
|
|
63
|
+
|
|
64
|
+
/** 预期效果 */
|
|
65
|
+
expectedOutcome: string;
|
|
66
|
+
|
|
67
|
+
/** 实施成本 */
|
|
68
|
+
implementationCost: 'low' | 'medium' | 'high';
|
|
69
|
+
}[];
|
|
70
|
+
|
|
71
|
+
/** 是否需要变更 */
|
|
72
|
+
needsChange: boolean;
|
|
73
|
+
|
|
74
|
+
/** 紧急程度 */
|
|
75
|
+
urgency: 'low' | 'medium' | 'high';
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 诊断配置
|
|
80
|
+
*/
|
|
81
|
+
export interface ConstraintDoctorConfig {
|
|
82
|
+
/** 是否启用 Agent 诊断(默认 false,需要显式启用) */
|
|
83
|
+
enabled?: boolean;
|
|
84
|
+
|
|
85
|
+
/** Agent 类型(预留,后续对接) */
|
|
86
|
+
agentType?: 'claude-code' | 'codex' | 'openai';
|
|
87
|
+
|
|
88
|
+
/** 最大 traces 数量(用于构造 prompt) */
|
|
89
|
+
maxTracesInPrompt?: number;
|
|
90
|
+
|
|
91
|
+
/** 是否自动生成提案 */
|
|
92
|
+
autoGenerateProposal?: boolean;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Constraint Doctor - 约束诊断器
|
|
97
|
+
*
|
|
98
|
+
* 使用方式:
|
|
99
|
+
* ```typescript
|
|
100
|
+
* const doctor = new ConstraintDoctor(analyzer);
|
|
101
|
+
* const diagnosis = await doctor.diagnose(anomaly);
|
|
102
|
+
*
|
|
103
|
+
* if (diagnosis.needsChange) {
|
|
104
|
+
* const proposal = await evolver.propose(diagnosis);
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export class ConstraintDoctor {
|
|
109
|
+
private config: ConstraintDoctorConfig;
|
|
110
|
+
private traces: ExecutionTrace[];
|
|
111
|
+
private summary: TraceSummary | null;
|
|
112
|
+
private llm: LLMAdapter | null;
|
|
113
|
+
|
|
114
|
+
constructor(config?: ConstraintDoctorConfig, llm?: LLMAdapter) {
|
|
115
|
+
this.config = {
|
|
116
|
+
enabled: false,
|
|
117
|
+
maxTracesInPrompt: 20,
|
|
118
|
+
autoGenerateProposal: false,
|
|
119
|
+
...config,
|
|
120
|
+
};
|
|
121
|
+
this.traces = [];
|
|
122
|
+
this.summary = null;
|
|
123
|
+
this.llm = llm || null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* 设置诊断数据
|
|
128
|
+
*/
|
|
129
|
+
setData(traces: ExecutionTrace[], summary?: TraceSummary): void {
|
|
130
|
+
this.traces = traces;
|
|
131
|
+
this.summary = summary || null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* 诊断异常
|
|
136
|
+
*
|
|
137
|
+
* 如果 Agent 未启用,返回基于规则的诊断
|
|
138
|
+
*/
|
|
139
|
+
async diagnose(anomaly: TraceAnomaly): Promise<Diagnosis> {
|
|
140
|
+
// 过滤相关 traces
|
|
141
|
+
const relevantTraces = this.filterRelevantTraces(anomaly);
|
|
142
|
+
|
|
143
|
+
// 基于规则的初步诊断(不消耗 Token)
|
|
144
|
+
const ruleBasedDiagnosis = this.ruleBasedDiagnose(anomaly, relevantTraces);
|
|
145
|
+
|
|
146
|
+
// 如果 LLM 可用,进行深度分析
|
|
147
|
+
if (this.config.enabled && this.llm) {
|
|
148
|
+
try {
|
|
149
|
+
return await this.agentDiagnose(anomaly, relevantTraces, ruleBasedDiagnosis);
|
|
150
|
+
} catch {
|
|
151
|
+
// LLM 调用失败,降级到规则诊断
|
|
152
|
+
return ruleBasedDiagnosis;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return ruleBasedDiagnosis;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* 基于规则的诊断(零 Token)
|
|
161
|
+
*
|
|
162
|
+
* 根据异常类型应用预设的诊断规则
|
|
163
|
+
*/
|
|
164
|
+
private ruleBasedDiagnose(
|
|
165
|
+
anomaly: TraceAnomaly,
|
|
166
|
+
traces: ExecutionTrace[]
|
|
167
|
+
): Diagnosis {
|
|
168
|
+
const diagnosis: Diagnosis = {
|
|
169
|
+
anomalyId: `${anomaly.constraintId}-${anomaly.type}-${Date.now()}`,
|
|
170
|
+
constraintId: anomaly.constraintId,
|
|
171
|
+
diagnosedAt: Date.now(),
|
|
172
|
+
rootCause: {
|
|
173
|
+
primary: '',
|
|
174
|
+
secondary: [],
|
|
175
|
+
evidence: traces.slice(0, this.config.maxTracesInPrompt!),
|
|
176
|
+
},
|
|
177
|
+
impact: {
|
|
178
|
+
severity: 'medium',
|
|
179
|
+
scope: 'single_project',
|
|
180
|
+
userImpact: '',
|
|
181
|
+
},
|
|
182
|
+
recommendations: [],
|
|
183
|
+
needsChange: false,
|
|
184
|
+
urgency: 'low',
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// 根据异常类型诊断
|
|
188
|
+
switch (anomaly.type) {
|
|
189
|
+
case 'high_bypass_rate':
|
|
190
|
+
diagnosis.rootCause.primary = '约束过于严格,用户频繁绕过';
|
|
191
|
+
diagnosis.rootCause.secondary = [
|
|
192
|
+
'约束触发条件过于宽泛',
|
|
193
|
+
'缺乏必要的例外条件',
|
|
194
|
+
'约束定义与实际场景不匹配',
|
|
195
|
+
];
|
|
196
|
+
diagnosis.impact.userImpact = '用户被迫绕过约束,降低信任度';
|
|
197
|
+
diagnosis.recommendations = [
|
|
198
|
+
{
|
|
199
|
+
type: 'add_exception',
|
|
200
|
+
content: `为约束 ${anomaly.constraintId} 添加常见例外条件`,
|
|
201
|
+
expectedOutcome: '绕过率降低至 20% 以下',
|
|
202
|
+
implementationCost: 'low',
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
type: 'adjust_threshold',
|
|
206
|
+
content: '调整触发条件,减少误触发',
|
|
207
|
+
expectedOutcome: '减少不必要的约束检查',
|
|
208
|
+
implementationCost: 'medium',
|
|
209
|
+
},
|
|
210
|
+
];
|
|
211
|
+
diagnosis.needsChange = true;
|
|
212
|
+
diagnosis.urgency = anomaly.data.currentRate > 0.5 ? 'high' : 'medium';
|
|
213
|
+
break;
|
|
214
|
+
|
|
215
|
+
case 'rising_fail_rate':
|
|
216
|
+
diagnosis.rootCause.primary = '约束失败率呈上升趋势';
|
|
217
|
+
diagnosis.rootCause.secondary = [
|
|
218
|
+
'代码质量下降',
|
|
219
|
+
'约束检查逻辑存在 bug',
|
|
220
|
+
'环境变化导致约束不再适用',
|
|
221
|
+
];
|
|
222
|
+
diagnosis.impact.userImpact = '开发效率下降,约束频繁阻止正常操作';
|
|
223
|
+
diagnosis.recommendations = [
|
|
224
|
+
{
|
|
225
|
+
type: 'modify_constraint',
|
|
226
|
+
content: '审查约束逻辑,确认是否符合预期',
|
|
227
|
+
expectedOutcome: '恢复正常的失败率水平',
|
|
228
|
+
implementationCost: 'medium',
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
type: 'user_training',
|
|
232
|
+
content: '指导用户正确理解约束要求',
|
|
233
|
+
expectedOutcome: '减少因误解导致的失败',
|
|
234
|
+
implementationCost: 'low',
|
|
235
|
+
},
|
|
236
|
+
];
|
|
237
|
+
diagnosis.needsChange = true;
|
|
238
|
+
diagnosis.urgency = 'medium';
|
|
239
|
+
break;
|
|
240
|
+
|
|
241
|
+
case 'rising_bypass_rate':
|
|
242
|
+
diagnosis.rootCause.primary = '绕过率呈上升趋势';
|
|
243
|
+
diagnosis.rootCause.secondary = [
|
|
244
|
+
'用户对约束的接受度下降',
|
|
245
|
+
'约束规则逐渐不适应新的开发模式',
|
|
246
|
+
'用户发现了绕过约束的"捷径"',
|
|
247
|
+
];
|
|
248
|
+
diagnosis.impact.userImpact = '约束逐渐失去约束力';
|
|
249
|
+
diagnosis.recommendations = [
|
|
250
|
+
{
|
|
251
|
+
type: 'modify_constraint',
|
|
252
|
+
content: '重新评估约束的必要性',
|
|
253
|
+
expectedOutcome: '恢复约束的权威性',
|
|
254
|
+
implementationCost: 'high',
|
|
255
|
+
},
|
|
256
|
+
];
|
|
257
|
+
diagnosis.needsChange = true;
|
|
258
|
+
diagnosis.urgency = 'high';
|
|
259
|
+
break;
|
|
260
|
+
|
|
261
|
+
case 'low_pass_rate':
|
|
262
|
+
diagnosis.rootCause.primary = '约束通过率过低';
|
|
263
|
+
diagnosis.rootCause.secondary = [
|
|
264
|
+
'约束要求过于严格',
|
|
265
|
+
'实际代码质量不达标',
|
|
266
|
+
'约束定义存在歧义',
|
|
267
|
+
];
|
|
268
|
+
diagnosis.impact.userImpact = '几乎所有操作都被阻止,开发受阻';
|
|
269
|
+
diagnosis.recommendations = [
|
|
270
|
+
{
|
|
271
|
+
type: 'adjust_threshold',
|
|
272
|
+
content: '放宽约束要求,设置合理阈值',
|
|
273
|
+
expectedOutcome: '通过率提升至 50% 以上',
|
|
274
|
+
implementationCost: 'low',
|
|
275
|
+
},
|
|
276
|
+
];
|
|
277
|
+
diagnosis.needsChange = true;
|
|
278
|
+
diagnosis.urgency = 'high';
|
|
279
|
+
break;
|
|
280
|
+
|
|
281
|
+
case 'exception_overuse':
|
|
282
|
+
diagnosis.rootCause.primary = '例外条件被过度使用';
|
|
283
|
+
diagnosis.rootCause.secondary = [
|
|
284
|
+
'例外条件过于宽泛',
|
|
285
|
+
'例外条件定义不够精确',
|
|
286
|
+
'用户习惯性申请例外',
|
|
287
|
+
];
|
|
288
|
+
diagnosis.impact.userImpact = '例外成为常态,约束失去意义';
|
|
289
|
+
diagnosis.recommendations = [
|
|
290
|
+
{
|
|
291
|
+
type: 'modify_constraint',
|
|
292
|
+
content: '缩小例外条件范围,提高例外门槛',
|
|
293
|
+
expectedOutcome: '例外使用率降低至 20% 以下',
|
|
294
|
+
implementationCost: 'medium',
|
|
295
|
+
},
|
|
296
|
+
];
|
|
297
|
+
diagnosis.needsChange = true;
|
|
298
|
+
diagnosis.urgency = 'medium';
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// 根据约束层级调整严重性
|
|
303
|
+
if (anomaly.level === 'iron_law') {
|
|
304
|
+
diagnosis.impact.severity = 'high';
|
|
305
|
+
diagnosis.urgency = 'medium'; // Iron law 总是至少 medium
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return diagnosis;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* LLM 深度诊断
|
|
313
|
+
*
|
|
314
|
+
* 将异常和相关 traces 构造为 prompt,调用 LLM 分析根因
|
|
315
|
+
* 成本:~2000 Token/次
|
|
316
|
+
*/
|
|
317
|
+
private async agentDiagnose(
|
|
318
|
+
anomaly: TraceAnomaly,
|
|
319
|
+
traces: ExecutionTrace[],
|
|
320
|
+
fallback: Diagnosis
|
|
321
|
+
): Promise<Diagnosis> {
|
|
322
|
+
const maxTraces = this.config.maxTracesInPrompt || 20;
|
|
323
|
+
const traceSummary = traces.slice(0, maxTraces).map(t =>
|
|
324
|
+
`[${t.result}] ${t.constraintId} | ${t.operation || 'unknown'} | ${t.timestamp ? new Date(t.timestamp).toISOString() : 'no-ts'}`
|
|
325
|
+
).join('\n');
|
|
326
|
+
|
|
327
|
+
const prompt = `你是约束系统诊断专家。分析以下异常并给出诊断结果。
|
|
328
|
+
|
|
329
|
+
## 异常信息
|
|
330
|
+
- 约束 ID: ${anomaly.constraintId}
|
|
331
|
+
- 异常类型: ${anomaly.type}
|
|
332
|
+
- 约束层级: ${anomaly.level}
|
|
333
|
+
- 当前数据: ${JSON.stringify(anomaly.data)}
|
|
334
|
+
|
|
335
|
+
## 相关 Traces(最近 ${Math.min(traces.length, maxTraces)} 条)
|
|
336
|
+
${traceSummary || '无相关 traces'}
|
|
337
|
+
|
|
338
|
+
## 要求
|
|
339
|
+
以 JSON 格式返回诊断结果,包含以下字段:
|
|
340
|
+
{
|
|
341
|
+
"rootCause": { "primary": "主要原因", "secondary": ["次要原因1", "次要原因2"] },
|
|
342
|
+
"impact": { "severity": "low|medium|high", "scope": "single_project|multiple_projects|team", "userImpact": "用户影响描述" },
|
|
343
|
+
"recommendations": [{ "type": "add_exception|adjust_threshold|modify_constraint|user_training", "content": "建议内容", "expectedOutcome": "预期效果", "implementationCost": "low|medium|high" }],
|
|
344
|
+
"needsChange": true/false,
|
|
345
|
+
"urgency": "low|medium|high"
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
只返回 JSON,不要其他内容。`;
|
|
349
|
+
|
|
350
|
+
const response = await this.llm!.complete(prompt, {
|
|
351
|
+
maxTokens: 1000,
|
|
352
|
+
temperature: 0.3,
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
// 解析 LLM 响应
|
|
356
|
+
const parsed = this.parseAgentResponse(response);
|
|
357
|
+
|
|
358
|
+
return {
|
|
359
|
+
...fallback,
|
|
360
|
+
rootCause: {
|
|
361
|
+
primary: parsed.rootCause?.primary || fallback.rootCause.primary,
|
|
362
|
+
secondary: parsed.rootCause?.secondary || fallback.rootCause.secondary,
|
|
363
|
+
evidence: fallback.rootCause.evidence,
|
|
364
|
+
},
|
|
365
|
+
impact: {
|
|
366
|
+
severity: parsed.impact?.severity || fallback.impact.severity,
|
|
367
|
+
scope: parsed.impact?.scope || fallback.impact.scope,
|
|
368
|
+
userImpact: parsed.impact?.userImpact || fallback.impact.userImpact,
|
|
369
|
+
},
|
|
370
|
+
recommendations: parsed.recommendations?.length ? parsed.recommendations : fallback.recommendations,
|
|
371
|
+
needsChange: parsed.needsChange ?? fallback.needsChange,
|
|
372
|
+
urgency: parsed.urgency || fallback.urgency,
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* 解析 LLM 返回的 JSON 诊断结果
|
|
378
|
+
*/
|
|
379
|
+
private parseAgentResponse(response: string): Partial<Diagnosis> {
|
|
380
|
+
try {
|
|
381
|
+
// 提取 JSON(可能被 markdown 代码块包裹)
|
|
382
|
+
const jsonMatch = response.match(/\{[\s\S]*\}/);
|
|
383
|
+
if (!jsonMatch) return {};
|
|
384
|
+
return JSON.parse(jsonMatch[0]);
|
|
385
|
+
} catch {
|
|
386
|
+
return {};
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* 过滤相关 traces
|
|
392
|
+
*
|
|
393
|
+
* 只保留与异常相关的 traces,减少 prompt 内容
|
|
394
|
+
*/
|
|
395
|
+
private filterRelevantTraces(anomaly: TraceAnomaly): ExecutionTrace[] {
|
|
396
|
+
return this.traces.filter(t => {
|
|
397
|
+
// 必须是同一个约束
|
|
398
|
+
if (t.constraintId !== anomaly.constraintId) return false;
|
|
399
|
+
|
|
400
|
+
// 失败或绕过的更有诊断价值
|
|
401
|
+
if (t.result === 'fail' || t.result === 'bypassed') return true;
|
|
402
|
+
|
|
403
|
+
// 保留少量通过的作为对比
|
|
404
|
+
return true;
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* 批量诊断多个异常
|
|
410
|
+
*/
|
|
411
|
+
async diagnoseBatch(anomalies: TraceAnomaly[]): Promise<Diagnosis[]> {
|
|
412
|
+
return Promise.all(anomalies.map(a => this.diagnose(a)));
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* 生成诊断报告(文本格式)
|
|
417
|
+
*/
|
|
418
|
+
generateReport(diagnosis: Diagnosis): string {
|
|
419
|
+
const lines: string[] = [];
|
|
420
|
+
|
|
421
|
+
lines.push(`# Diagnosis Report`);
|
|
422
|
+
lines.push(`Constraint: ${diagnosis.constraintId}`);
|
|
423
|
+
lines.push(`Anomaly: ${diagnosis.anomalyId}`);
|
|
424
|
+
lines.push(`Diagnosed: ${new Date(diagnosis.diagnosedAt).toISOString()}`);
|
|
425
|
+
lines.push('');
|
|
426
|
+
|
|
427
|
+
// 根因
|
|
428
|
+
lines.push(`## Root Cause`);
|
|
429
|
+
lines.push('');
|
|
430
|
+
lines.push(`**Primary**: ${diagnosis.rootCause.primary}`);
|
|
431
|
+
if (diagnosis.rootCause.secondary?.length) {
|
|
432
|
+
lines.push('');
|
|
433
|
+
lines.push('**Secondary**:');
|
|
434
|
+
for (const s of diagnosis.rootCause.secondary) {
|
|
435
|
+
lines.push(`- ${s}`);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
lines.push('');
|
|
439
|
+
|
|
440
|
+
// 影响
|
|
441
|
+
lines.push(`## Impact`);
|
|
442
|
+
lines.push('');
|
|
443
|
+
lines.push(`- Severity: ${diagnosis.impact.severity}`);
|
|
444
|
+
lines.push(`- Scope: ${diagnosis.impact.scope}`);
|
|
445
|
+
lines.push(`- User Impact: ${diagnosis.impact.userImpact}`);
|
|
446
|
+
lines.push('');
|
|
447
|
+
|
|
448
|
+
// 建议
|
|
449
|
+
lines.push(`## Recommendations`);
|
|
450
|
+
lines.push('');
|
|
451
|
+
|
|
452
|
+
for (const r of diagnosis.recommendations) {
|
|
453
|
+
lines.push(`### ${r.type}`);
|
|
454
|
+
lines.push(`- Content: ${r.content}`);
|
|
455
|
+
lines.push(`- Expected: ${r.expectedOutcome}`);
|
|
456
|
+
lines.push(`- Cost: ${r.implementationCost}`);
|
|
457
|
+
lines.push('');
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// 决策
|
|
461
|
+
lines.push(`## Decision`);
|
|
462
|
+
lines.push('');
|
|
463
|
+
lines.push(`- Needs Change: ${diagnosis.needsChange ? '✅ Yes' : '❌ No'}`);
|
|
464
|
+
lines.push(`- Urgency: ${diagnosis.urgency}`);
|
|
465
|
+
|
|
466
|
+
return lines.join('\n');
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* 保存诊断结果
|
|
471
|
+
*/
|
|
472
|
+
saveDiagnosis(diagnosis: Diagnosis, outputPath: string): void {
|
|
473
|
+
const fs = require('fs');
|
|
474
|
+
const path = require('path');
|
|
475
|
+
|
|
476
|
+
const dir = path.dirname(outputPath);
|
|
477
|
+
if (!fs.existsSync(dir)) {
|
|
478
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
fs.writeFileSync(outputPath, JSON.stringify(diagnosis, null, 2), 'utf-8');
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* 加载诊断结果
|
|
486
|
+
*/
|
|
487
|
+
loadDiagnosis(inputPath: string): Diagnosis {
|
|
488
|
+
const fs = require('fs');
|
|
489
|
+
const content = fs.readFileSync(inputPath, 'utf-8');
|
|
490
|
+
return JSON.parse(content) as Diagnosis;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* 创建诊断器
|
|
496
|
+
*/
|
|
497
|
+
export function createDoctor(config?: ConstraintDoctorConfig, llm?: LLMAdapter): ConstraintDoctor {
|
|
498
|
+
return new ConstraintDoctor(config, llm);
|
|
499
|
+
}
|