@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,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSOValidator 测试
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, expect } from '@jest/globals';
|
|
6
|
+
import { CSOValidator } from '../core/validators/cso';
|
|
7
|
+
import type { WorkflowMeta, StepMeta, ToolMeta } from '../types/cso';
|
|
8
|
+
|
|
9
|
+
describe('CSOValidator', () => {
|
|
10
|
+
const validator = CSOValidator.getInstance();
|
|
11
|
+
|
|
12
|
+
describe('单例模式', () => {
|
|
13
|
+
it('应该返回单例实例', () => {
|
|
14
|
+
const instance1 = CSOValidator.getInstance();
|
|
15
|
+
const instance2 = CSOValidator.getInstance();
|
|
16
|
+
expect(instance1).toBe(instance2);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('validateWorkflow', () => {
|
|
21
|
+
it('有效的描述应该通过', () => {
|
|
22
|
+
const workflow: WorkflowMeta = {
|
|
23
|
+
name: 'test-workflow',
|
|
24
|
+
description: '用于处理用户登录场景,验证身份并创建会话',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const result = validator.validateWorkflow(workflow);
|
|
28
|
+
|
|
29
|
+
expect(result.valid).toBe(true);
|
|
30
|
+
expect(result.message).toContain('符合');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('包含工作流关键词应该失败', () => {
|
|
34
|
+
const workflow: WorkflowMeta = {
|
|
35
|
+
name: 'test-workflow',
|
|
36
|
+
description: '首先验证用户身份,然后创建会话,最后返回令牌',
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const result = validator.validateWorkflow(workflow);
|
|
40
|
+
|
|
41
|
+
expect(result.valid).toBe(false);
|
|
42
|
+
expect(result.issues).toBeDefined();
|
|
43
|
+
expect(result.issues?.some(i => i.type === 'workflow_summary')).toBe(true);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('缺少触发关键词应该失败', () => {
|
|
47
|
+
const workflow: WorkflowMeta = {
|
|
48
|
+
name: 'test-workflow',
|
|
49
|
+
description: '验证用户身份并创建会话',
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const result = validator.validateWorkflow(workflow);
|
|
53
|
+
|
|
54
|
+
expect(result.valid).toBe(false);
|
|
55
|
+
expect(result.issues?.some(i => i.type === 'missing_trigger')).toBe(true);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('描述过长应该失败', () => {
|
|
59
|
+
const longDesc = '用于处理用户登录场景,验证身份并创建会话'.repeat(12); // 228字符
|
|
60
|
+
const workflow: WorkflowMeta = {
|
|
61
|
+
name: 'test-workflow',
|
|
62
|
+
description: longDesc,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const result = validator.validateWorkflow(workflow);
|
|
66
|
+
|
|
67
|
+
expect(result.issues?.some(i => i.type === 'too_long')).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('多个问题应该全部返回', () => {
|
|
71
|
+
const longDesc = '首先验证用户身份然后创建会话'.repeat(10);
|
|
72
|
+
const workflow: WorkflowMeta = {
|
|
73
|
+
name: 'test-workflow',
|
|
74
|
+
description: longDesc,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const result = validator.validateWorkflow(workflow);
|
|
78
|
+
|
|
79
|
+
expect(result.valid).toBe(false);
|
|
80
|
+
expect(result.issues?.length).toBeGreaterThanOrEqual(2);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe('validateStep', () => {
|
|
85
|
+
it('有效的步骤描述应该通过', () => {
|
|
86
|
+
const step: StepMeta = {
|
|
87
|
+
name: 'validate-user',
|
|
88
|
+
description: '用于验证用户身份时,检查令牌有效性',
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const result = validator.validateStep(step);
|
|
92
|
+
|
|
93
|
+
expect(result.valid).toBe(true);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('无效的步骤描述应该失败', () => {
|
|
97
|
+
const step: StepMeta = {
|
|
98
|
+
name: 'validate-user',
|
|
99
|
+
description: 'Step 1: 验证令牌',
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const result = validator.validateStep(step);
|
|
103
|
+
|
|
104
|
+
expect(result.valid).toBe(false);
|
|
105
|
+
expect(result.issues?.some(i => i.type === 'workflow_summary')).toBe(true);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe('validateTool', () => {
|
|
110
|
+
it('有效的工具描述应该通过', () => {
|
|
111
|
+
const tool: ToolMeta = {
|
|
112
|
+
name: 'auth-tool',
|
|
113
|
+
description: '用于认证场景,提供登录和令牌验证功能',
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const result = validator.validateTool(tool);
|
|
117
|
+
|
|
118
|
+
expect(result.valid).toBe(true);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('无效的工具描述应该失败', () => {
|
|
122
|
+
const tool: ToolMeta = {
|
|
123
|
+
name: 'auth-tool',
|
|
124
|
+
description: '首先调用登录API',
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const result = validator.validateTool(tool);
|
|
128
|
+
|
|
129
|
+
expect(result.valid).toBe(false);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe('建议生成', () => {
|
|
134
|
+
it('无效描述应该包含建议', () => {
|
|
135
|
+
const workflow: WorkflowMeta = {
|
|
136
|
+
name: 'test-workflow',
|
|
137
|
+
description: '验证用户身份',
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const result = validator.validateWorkflow(workflow);
|
|
141
|
+
|
|
142
|
+
expect(result.suggestion).toBeDefined();
|
|
143
|
+
expect(result.suggestion).toContain('建议');
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('有效描述不应该包含建议', () => {
|
|
147
|
+
const workflow: WorkflowMeta = {
|
|
148
|
+
name: 'test-workflow',
|
|
149
|
+
description: '用于验证用户身份',
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const result = validator.validateWorkflow(workflow);
|
|
153
|
+
|
|
154
|
+
expect(result.suggestion).toBeUndefined();
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
describe('中文支持', () => {
|
|
159
|
+
it('中文触发关键词应该被识别', () => {
|
|
160
|
+
const workflow: WorkflowMeta = {
|
|
161
|
+
name: 'test-workflow',
|
|
162
|
+
description: '当用户登录时,验证身份',
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const result = validator.validateWorkflow(workflow);
|
|
166
|
+
|
|
167
|
+
expect(result.issues?.some(i => i.type === 'missing_trigger')).toBe(false);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('中文工作流关键词应该被识别', () => {
|
|
171
|
+
const workflow: WorkflowMeta = {
|
|
172
|
+
name: 'test-workflow',
|
|
173
|
+
description: '首先检查权限,然后执行操作',
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const result = validator.validateWorkflow(workflow);
|
|
177
|
+
|
|
178
|
+
expect(result.issues?.some(i => i.type === 'workflow_summary')).toBe(true);
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
describe('英文支持', () => {
|
|
183
|
+
it('英文触发关键词应该被识别', () => {
|
|
184
|
+
const workflow: WorkflowMeta = {
|
|
185
|
+
name: 'test-workflow',
|
|
186
|
+
description: 'Use for user authentication scenarios',
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const result = validator.validateWorkflow(workflow);
|
|
190
|
+
|
|
191
|
+
expect(result.issues?.some(i => i.type === 'missing_trigger')).toBe(false);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('英文工作流关键词应该被识别', () => {
|
|
195
|
+
const workflow: WorkflowMeta = {
|
|
196
|
+
name: 'test-workflow',
|
|
197
|
+
description: 'First validate the token, then create session',
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
const result = validator.validateWorkflow(workflow);
|
|
201
|
+
|
|
202
|
+
expect(result.issues?.some(i => i.type === 'workflow_summary')).toBe(true);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* detectSourceRoots 测试
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { existsSync, mkdirSync, writeFileSync, rmSync } from 'fs';
|
|
6
|
+
import { join } from 'path';
|
|
7
|
+
import { detectSourceRoots } from '../utils/detect-source-roots';
|
|
8
|
+
|
|
9
|
+
const tempDir = join(__dirname, '__temp_detect_source_roots__');
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
if (existsSync(tempDir)) rmSync(tempDir, { recursive: true, force: true });
|
|
13
|
+
mkdirSync(tempDir, { recursive: true });
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
if (existsSync(tempDir)) rmSync(tempDir, { recursive: true, force: true });
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
function touchFile(dir: string, name: string) {
|
|
21
|
+
const filePath = join(dir, name);
|
|
22
|
+
mkdirSync(dir, { recursive: true });
|
|
23
|
+
writeFileSync(filePath, '// test');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe('detectSourceRoots', () => {
|
|
27
|
+
it('单 repo: src/ 目录', () => {
|
|
28
|
+
touchFile(join(tempDir, 'src'), 'index.ts');
|
|
29
|
+
const roots = detectSourceRoots(tempDir);
|
|
30
|
+
expect(roots).toContain('src');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('单 repo: lib/ 目录', () => {
|
|
34
|
+
touchFile(join(tempDir, 'lib'), 'index.ts');
|
|
35
|
+
const roots = detectSourceRoots(tempDir);
|
|
36
|
+
expect(roots).toContain('lib');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('空项目返回空数组', () => {
|
|
40
|
+
const roots = detectSourceRoots(tempDir);
|
|
41
|
+
expect(roots).toEqual([]);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('monorepo: packages/*/src', () => {
|
|
45
|
+
touchFile(join(tempDir, 'packages', 'core', 'src'), 'index.ts');
|
|
46
|
+
touchFile(join(tempDir, 'packages', 'utils', 'src'), 'util.ts');
|
|
47
|
+
const roots = detectSourceRoots(tempDir);
|
|
48
|
+
expect(roots).toContain('packages/core/src');
|
|
49
|
+
expect(roots).toContain('packages/utils/src');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('monorepo: packages/*/lib', () => {
|
|
53
|
+
touchFile(join(tempDir, 'packages', 'mylib', 'lib'), 'index.ts');
|
|
54
|
+
const roots = detectSourceRoots(tempDir);
|
|
55
|
+
expect(roots).toContain('packages/mylib/lib');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('monorepo: apps/*/src/modules/*', () => {
|
|
59
|
+
touchFile(join(tempDir, 'apps', 'api', 'src', 'modules', 'auth'), 'index.ts');
|
|
60
|
+
touchFile(join(tempDir, 'apps', 'api', 'src', 'modules', 'users'), 'handler.ts');
|
|
61
|
+
const roots = detectSourceRoots(tempDir);
|
|
62
|
+
expect(roots).toContain('apps/api/src/modules/auth');
|
|
63
|
+
expect(roots).toContain('apps/api/src/modules/users');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('排除 .d.ts 文件(只有类型声明不视为源码目录)', () => {
|
|
67
|
+
const dtsDir = join(tempDir, 'types');
|
|
68
|
+
mkdirSync(dtsDir, { recursive: true });
|
|
69
|
+
writeFileSync(join(dtsDir, 'index.d.ts'), 'export type Foo = string;');
|
|
70
|
+
const roots = detectSourceRoots(tempDir);
|
|
71
|
+
// types/ 只有 .d.ts → 不应被返回
|
|
72
|
+
expect(roots.filter(r => r.includes('types'))).toEqual([]);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('跳过 __tests__, node_modules, dist, 隐藏目录', () => {
|
|
76
|
+
touchFile(join(tempDir, 'src'), 'index.ts');
|
|
77
|
+
touchFile(join(tempDir, 'src', '__tests__'), 'test.ts');
|
|
78
|
+
touchFile(join(tempDir, 'src', 'node_modules', 'pkg'), 'index.ts');
|
|
79
|
+
touchFile(join(tempDir, 'packages', '.internal', 'src'), 'index.ts');
|
|
80
|
+
const roots = detectSourceRoots(tempDir);
|
|
81
|
+
// src/ 本身被包含,但 __tests__ 等子目录不影响
|
|
82
|
+
expect(roots).toContain('src');
|
|
83
|
+
// packages/.internal 的 src/ 也应该被发现
|
|
84
|
+
expect(roots.some(r => r.includes('.internal'))).toBe(false);
|
|
85
|
+
// 只要 src/ 下有 .ts 就算
|
|
86
|
+
expect(roots.length).toBeGreaterThanOrEqual(1);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('混合结构: packages + apps + src', () => {
|
|
90
|
+
touchFile(join(tempDir, 'src'), 'main.ts');
|
|
91
|
+
touchFile(join(tempDir, 'packages', 'core', 'src'), 'index.ts');
|
|
92
|
+
touchFile(join(tempDir, 'apps', 'api', 'src', 'modules', 'auth'), 'index.ts');
|
|
93
|
+
const roots = detectSourceRoots(tempDir);
|
|
94
|
+
expect(roots).toContain('src');
|
|
95
|
+
expect(roots).toContain('packages/core/src');
|
|
96
|
+
expect(roots).toContain('apps/api/src/modules/auth');
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ConstraintDoctor 和 ConstraintEvolver 测试
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as fs from 'fs';
|
|
6
|
+
import * as path from 'path';
|
|
7
|
+
import * as os from 'os';
|
|
8
|
+
import { TraceCollector } from '../monitoring/traces';
|
|
9
|
+
import { TraceAnalyzer } from '../monitoring/trace-analyzer';
|
|
10
|
+
import { ConstraintDoctor, createDoctor } from '../monitoring/constraint-doctor';
|
|
11
|
+
import { ConstraintEvolver, createEvolver } from '../monitoring/constraint-evolver';
|
|
12
|
+
import type { ExecutionTrace, TraceAnomaly } from '../types/trace';
|
|
13
|
+
import type { Diagnosis } from '../monitoring/constraint-doctor';
|
|
14
|
+
import type { ConstraintProposal } from '../monitoring/constraint-evolver';
|
|
15
|
+
|
|
16
|
+
describe('ConstraintDoctor', () => {
|
|
17
|
+
let tempDir: string;
|
|
18
|
+
let collector: TraceCollector;
|
|
19
|
+
let analyzer: TraceAnalyzer;
|
|
20
|
+
let doctor: ConstraintDoctor;
|
|
21
|
+
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
tempDir = path.join(os.tmpdir(), `harness-traces-${Date.now()}`);
|
|
24
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
25
|
+
collector = new TraceCollector({
|
|
26
|
+
traceFile: path.join(tempDir, 'execution.log'),
|
|
27
|
+
enabled: true,
|
|
28
|
+
});
|
|
29
|
+
analyzer = new TraceAnalyzer(collector);
|
|
30
|
+
doctor = createDoctor();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
if (fs.existsSync(tempDir)) {
|
|
35
|
+
fs.rmSync(tempDir, { recursive: true });
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('should diagnose high bypass rate anomaly', async () => {
|
|
40
|
+
// 创建异常
|
|
41
|
+
const anomaly: TraceAnomaly = {
|
|
42
|
+
type: 'high_bypass_rate',
|
|
43
|
+
constraintId: 'test_constraint',
|
|
44
|
+
level: 'guideline',
|
|
45
|
+
message: 'Bypass rate 40%',
|
|
46
|
+
data: {
|
|
47
|
+
currentRate: 0.4,
|
|
48
|
+
threshold: 0.3,
|
|
49
|
+
},
|
|
50
|
+
detectedAt: Date.now(),
|
|
51
|
+
suggestedAction: 'diagnose',
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// 添加 traces
|
|
55
|
+
const traces: ExecutionTrace[] = [];
|
|
56
|
+
for (let i = 0; i < 10; i++) {
|
|
57
|
+
traces.push({
|
|
58
|
+
constraintId: 'test_constraint',
|
|
59
|
+
level: 'guideline',
|
|
60
|
+
timestamp: Date.now() - i * 60 * 1000,
|
|
61
|
+
result: i < 6 ? 'bypassed' : 'pass',
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
doctor.setData(traces);
|
|
65
|
+
|
|
66
|
+
// 诊断
|
|
67
|
+
const diagnosis = await doctor.diagnose(anomaly);
|
|
68
|
+
|
|
69
|
+
expect(diagnosis.constraintId).toBe('test_constraint');
|
|
70
|
+
expect(diagnosis.needsChange).toBe(true);
|
|
71
|
+
expect(diagnosis.rootCause.primary).toContain('过于严格');
|
|
72
|
+
expect(diagnosis.recommendations.length).toBeGreaterThan(0);
|
|
73
|
+
expect(diagnosis.recommendations[0].type).toBe('add_exception');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('should diagnose rising fail rate anomaly', async () => {
|
|
77
|
+
const anomaly: TraceAnomaly = {
|
|
78
|
+
type: 'rising_fail_rate',
|
|
79
|
+
constraintId: 'another_constraint',
|
|
80
|
+
level: 'iron_law',
|
|
81
|
+
message: 'Fail rate rising',
|
|
82
|
+
data: {
|
|
83
|
+
currentRate: 0.6,
|
|
84
|
+
threshold: 0.5,
|
|
85
|
+
trend: 'rising',
|
|
86
|
+
},
|
|
87
|
+
detectedAt: Date.now(),
|
|
88
|
+
suggestedAction: 'diagnose',
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
doctor.setData([]);
|
|
92
|
+
const diagnosis = await doctor.diagnose(anomaly);
|
|
93
|
+
|
|
94
|
+
expect(diagnosis.needsChange).toBe(true);
|
|
95
|
+
expect(diagnosis.impact.severity).toBe('high'); // Iron law
|
|
96
|
+
expect(diagnosis.urgency).toBe('medium'); // Iron law 强制 medium+
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('should detect exception overuse', async () => {
|
|
100
|
+
const anomaly: TraceAnomaly = {
|
|
101
|
+
type: 'exception_overuse',
|
|
102
|
+
constraintId: 'constraint_with_exceptions',
|
|
103
|
+
level: 'guideline',
|
|
104
|
+
message: 'Exception rate 50%',
|
|
105
|
+
data: {
|
|
106
|
+
currentRate: 0.5,
|
|
107
|
+
threshold: 0.4,
|
|
108
|
+
},
|
|
109
|
+
detectedAt: Date.now(),
|
|
110
|
+
suggestedAction: 'add_exception',
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
doctor.setData([]);
|
|
114
|
+
const diagnosis = await doctor.diagnose(anomaly);
|
|
115
|
+
|
|
116
|
+
expect(diagnosis.rootCause.primary).toContain('过度使用');
|
|
117
|
+
expect(diagnosis.recommendations[0].type).toBe('modify_constraint');
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test('should generate diagnosis report', async () => {
|
|
121
|
+
const anomaly: TraceAnomaly = {
|
|
122
|
+
type: 'high_bypass_rate',
|
|
123
|
+
constraintId: 'test',
|
|
124
|
+
level: 'guideline',
|
|
125
|
+
message: 'Test',
|
|
126
|
+
data: {
|
|
127
|
+
currentRate: 0.5,
|
|
128
|
+
threshold: 0.3,
|
|
129
|
+
},
|
|
130
|
+
detectedAt: Date.now(),
|
|
131
|
+
suggestedAction: 'diagnose',
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
doctor.setData([]);
|
|
135
|
+
const diagnosis = await doctor.diagnose(anomaly);
|
|
136
|
+
const report = doctor.generateReport(diagnosis);
|
|
137
|
+
|
|
138
|
+
expect(report).toContain('# Diagnosis Report');
|
|
139
|
+
expect(report).toContain('Root Cause');
|
|
140
|
+
expect(report).toContain('Recommendations');
|
|
141
|
+
expect(report).toContain('test');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test('should save and load diagnosis', async () => {
|
|
145
|
+
const anomaly: TraceAnomaly = {
|
|
146
|
+
type: 'high_bypass_rate',
|
|
147
|
+
constraintId: 'save_test',
|
|
148
|
+
level: 'guideline',
|
|
149
|
+
message: 'Test',
|
|
150
|
+
data: { currentRate: 0.5, threshold: 0.3 },
|
|
151
|
+
detectedAt: Date.now(),
|
|
152
|
+
suggestedAction: 'diagnose',
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
doctor.setData([]);
|
|
156
|
+
const diagnosis = await doctor.diagnose(anomaly);
|
|
157
|
+
|
|
158
|
+
const outputPath = path.join(tempDir, 'diagnosis.json');
|
|
159
|
+
doctor.saveDiagnosis(diagnosis, outputPath);
|
|
160
|
+
|
|
161
|
+
expect(fs.existsSync(outputPath)).toBe(true);
|
|
162
|
+
|
|
163
|
+
const loaded = doctor.loadDiagnosis(outputPath);
|
|
164
|
+
expect(loaded.constraintId).toBe('save_test');
|
|
165
|
+
expect(loaded.needsChange).toBe(true);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe('ConstraintEvolver', () => {
|
|
170
|
+
let tempDir: string;
|
|
171
|
+
let evolver: ConstraintEvolver;
|
|
172
|
+
let doctor: ConstraintDoctor;
|
|
173
|
+
|
|
174
|
+
beforeEach(() => {
|
|
175
|
+
tempDir = path.join(os.tmpdir(), `harness-proposals-${Date.now()}`);
|
|
176
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
177
|
+
evolver = createEvolver(tempDir);
|
|
178
|
+
doctor = createDoctor();
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
afterEach(() => {
|
|
182
|
+
if (fs.existsSync(tempDir)) {
|
|
183
|
+
fs.rmSync(tempDir, { recursive: true });
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test('should propose from diagnosis', async () => {
|
|
188
|
+
const diagnosis: Diagnosis = {
|
|
189
|
+
anomalyId: 'test-anomaly-1',
|
|
190
|
+
constraintId: 'no_fix_without_root_cause',
|
|
191
|
+
diagnosedAt: Date.now(),
|
|
192
|
+
rootCause: {
|
|
193
|
+
primary: '约束过于严格',
|
|
194
|
+
secondary: ['缺少例外条件'],
|
|
195
|
+
evidence: [],
|
|
196
|
+
},
|
|
197
|
+
impact: {
|
|
198
|
+
severity: 'medium',
|
|
199
|
+
scope: 'single_project',
|
|
200
|
+
userImpact: '用户频繁绕过',
|
|
201
|
+
},
|
|
202
|
+
recommendations: [
|
|
203
|
+
{
|
|
204
|
+
type: 'add_exception',
|
|
205
|
+
content: '添加 typo 例外',
|
|
206
|
+
expectedOutcome: '绕过率降低',
|
|
207
|
+
implementationCost: 'low',
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
needsChange: true,
|
|
211
|
+
urgency: 'medium',
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const proposal = await evolver.propose(diagnosis);
|
|
215
|
+
|
|
216
|
+
expect(proposal).not.toBeNull();
|
|
217
|
+
expect(proposal!.constraintId).toBe('no_fix_without_root_cause');
|
|
218
|
+
expect(proposal!.type).toBe('add_exception');
|
|
219
|
+
expect(proposal!.status).toBe('proposed');
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
test('should not propose for diagnosis without change', async () => {
|
|
223
|
+
const diagnosis: Diagnosis = {
|
|
224
|
+
anomalyId: 'no-change',
|
|
225
|
+
constraintId: 'some_constraint',
|
|
226
|
+
diagnosedAt: Date.now(),
|
|
227
|
+
rootCause: {
|
|
228
|
+
primary: '正常',
|
|
229
|
+
evidence: [],
|
|
230
|
+
},
|
|
231
|
+
impact: {
|
|
232
|
+
severity: 'low',
|
|
233
|
+
scope: 'single_project',
|
|
234
|
+
userImpact: '无',
|
|
235
|
+
},
|
|
236
|
+
recommendations: [],
|
|
237
|
+
needsChange: false,
|
|
238
|
+
urgency: 'low',
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
const proposal = await evolver.propose(diagnosis);
|
|
242
|
+
expect(proposal).toBeNull();
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
test('should review low risk proposal', async () => {
|
|
246
|
+
const proposal: ConstraintProposal = {
|
|
247
|
+
id: 'test-proposal-1',
|
|
248
|
+
proposedAt: Date.now(),
|
|
249
|
+
diagnosisId: 'test-anomaly',
|
|
250
|
+
constraintId: 'some_guideline',
|
|
251
|
+
type: 'add_exception',
|
|
252
|
+
content: {
|
|
253
|
+
proposed: 'new_exception',
|
|
254
|
+
description: 'Add exception',
|
|
255
|
+
},
|
|
256
|
+
reasoning: 'Test',
|
|
257
|
+
expectedOutcome: 'Better',
|
|
258
|
+
risk: { level: 'low', description: 'Low risk' },
|
|
259
|
+
implementation: { files: [], linesChanged: 5, testsRequired: true },
|
|
260
|
+
status: 'proposed',
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const review = evolver.review(proposal);
|
|
264
|
+
expect(review.accepted).toBe(true);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
test('should review iron_law modification carefully', async () => {
|
|
268
|
+
const proposal: ConstraintProposal = {
|
|
269
|
+
id: 'iron-law-proposal',
|
|
270
|
+
proposedAt: Date.now(),
|
|
271
|
+
diagnosisId: 'iron-anomaly',
|
|
272
|
+
constraintId: 'no_self_approval', // Iron law that exists
|
|
273
|
+
type: 'modify_message', // Not add_exception
|
|
274
|
+
content: {
|
|
275
|
+
proposed: 'Change message',
|
|
276
|
+
description: 'Modify iron law',
|
|
277
|
+
},
|
|
278
|
+
reasoning: 'Test',
|
|
279
|
+
expectedOutcome: 'Test',
|
|
280
|
+
risk: { level: 'medium', description: 'Medium risk' },
|
|
281
|
+
implementation: { files: [], linesChanged: 10, testsRequired: true },
|
|
282
|
+
status: 'proposed',
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
const review = evolver.review(proposal);
|
|
286
|
+
expect(review.accepted).toBe(false);
|
|
287
|
+
expect(review.comment).toContain('Iron Law');
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
test('should generate implementation instructions', async () => {
|
|
291
|
+
const proposal: ConstraintProposal = {
|
|
292
|
+
id: 'impl-test',
|
|
293
|
+
proposedAt: Date.now(),
|
|
294
|
+
diagnosisId: 'test',
|
|
295
|
+
constraintId: 'some_constraint',
|
|
296
|
+
type: 'add_exception',
|
|
297
|
+
content: {
|
|
298
|
+
proposed: 'new_exception',
|
|
299
|
+
description: 'Add exception',
|
|
300
|
+
},
|
|
301
|
+
reasoning: 'Test',
|
|
302
|
+
expectedOutcome: 'Test',
|
|
303
|
+
risk: { level: 'low', description: 'Low risk' },
|
|
304
|
+
implementation: { files: ['definitions.ts'], linesChanged: 5, testsRequired: true },
|
|
305
|
+
status: 'accepted',
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
const impl = evolver.implement(proposal);
|
|
309
|
+
|
|
310
|
+
expect(impl.instructions.length).toBeGreaterThan(0);
|
|
311
|
+
expect(impl.filesToModify).toContain('src/core/constraints/definitions.ts');
|
|
312
|
+
expect(impl.testsToRun.length).toBeGreaterThan(0);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
test('should save and load proposal', async () => {
|
|
316
|
+
const proposal: ConstraintProposal = {
|
|
317
|
+
id: 'save-test',
|
|
318
|
+
proposedAt: Date.now(),
|
|
319
|
+
diagnosisId: 'test',
|
|
320
|
+
constraintId: 'test_constraint',
|
|
321
|
+
type: 'add_exception',
|
|
322
|
+
content: { proposed: 'test', description: 'Test' },
|
|
323
|
+
reasoning: 'Test',
|
|
324
|
+
expectedOutcome: 'Test',
|
|
325
|
+
risk: { level: 'low', description: 'Low' },
|
|
326
|
+
implementation: { files: [], linesChanged: 1, testsRequired: false },
|
|
327
|
+
status: 'proposed',
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
evolver.saveProposal(proposal);
|
|
331
|
+
|
|
332
|
+
const loaded = evolver.loadProposal('save-test');
|
|
333
|
+
expect(loaded.constraintId).toBe('test_constraint');
|
|
334
|
+
expect(loaded.status).toBe('proposed');
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
test('should list proposals', async () => {
|
|
338
|
+
const proposal: ConstraintProposal = {
|
|
339
|
+
id: 'list-test',
|
|
340
|
+
proposedAt: Date.now(),
|
|
341
|
+
diagnosisId: 'test',
|
|
342
|
+
constraintId: 'test',
|
|
343
|
+
type: 'add_exception',
|
|
344
|
+
content: { proposed: 'test', description: 'Test' },
|
|
345
|
+
reasoning: 'Test',
|
|
346
|
+
expectedOutcome: 'Test',
|
|
347
|
+
risk: { level: 'low', description: 'Low' },
|
|
348
|
+
implementation: { files: [], linesChanged: 1, testsRequired: false },
|
|
349
|
+
status: 'proposed',
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
evolver.saveProposal(proposal);
|
|
353
|
+
|
|
354
|
+
const proposals = evolver.listProposals('proposed');
|
|
355
|
+
expect(proposals.length).toBe(1);
|
|
356
|
+
expect(proposals[0].id).toBe('list-test');
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
test('should update proposal status', async () => {
|
|
360
|
+
const proposal: ConstraintProposal = {
|
|
361
|
+
id: 'status-test',
|
|
362
|
+
proposedAt: Date.now(),
|
|
363
|
+
diagnosisId: 'test',
|
|
364
|
+
constraintId: 'test',
|
|
365
|
+
type: 'add_exception',
|
|
366
|
+
content: { proposed: 'test', description: 'Test' },
|
|
367
|
+
reasoning: 'Test',
|
|
368
|
+
expectedOutcome: 'Test',
|
|
369
|
+
risk: { level: 'low', description: 'Low' },
|
|
370
|
+
implementation: { files: [], linesChanged: 1, testsRequired: false },
|
|
371
|
+
status: 'proposed',
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
evolver.saveProposal(proposal);
|
|
375
|
+
evolver.updateProposalStatus('status-test', 'accepted', 'Looks good');
|
|
376
|
+
|
|
377
|
+
const loaded = evolver.loadProposal('status-test');
|
|
378
|
+
expect(loaded.status).toBe('accepted');
|
|
379
|
+
expect(loaded.reviewComment).toBe('Looks good');
|
|
380
|
+
});
|
|
381
|
+
});
|