@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,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* harness contract 命令
|
|
3
|
+
*
|
|
4
|
+
* API 契约门控,检查 OpenAPI Schema 验证
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import chalk from 'chalk';
|
|
8
|
+
import * as fs from 'fs/promises';
|
|
9
|
+
import * as path from 'path';
|
|
10
|
+
import { ContractGate } from '../../gates/contract';
|
|
11
|
+
|
|
12
|
+
export interface ContractOptions {
|
|
13
|
+
/** 项目路径 */
|
|
14
|
+
projectPath?: string;
|
|
15
|
+
/** 契约文件路径 */
|
|
16
|
+
contractPath?: string;
|
|
17
|
+
/** 是否严格模式 */
|
|
18
|
+
strict?: boolean;
|
|
19
|
+
/** 是否允许破坏性变更 */
|
|
20
|
+
allowBreaking?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 执行契约门控
|
|
25
|
+
*/
|
|
26
|
+
export async function contract(options: ContractOptions): Promise<void> {
|
|
27
|
+
console.log(chalk.blue('📜 API 契约门控检查...'));
|
|
28
|
+
|
|
29
|
+
const projectPath = options.projectPath || process.cwd();
|
|
30
|
+
const contractPath = options.contractPath || 'openapi.yaml';
|
|
31
|
+
|
|
32
|
+
// 先验证文件是否存在
|
|
33
|
+
const fullPath = path.join(projectPath, contractPath);
|
|
34
|
+
try {
|
|
35
|
+
await fs.access(fullPath);
|
|
36
|
+
} catch {
|
|
37
|
+
console.log();
|
|
38
|
+
console.log(chalk.red('❌ 契约文件不存在'));
|
|
39
|
+
console.log(chalk.red(` ${fullPath}`));
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 创建契约门控实例
|
|
44
|
+
const gate = new ContractGate({
|
|
45
|
+
contractPath,
|
|
46
|
+
strict: options.strict !== false, // 默认严格模式
|
|
47
|
+
allowBreakingChanges: options.allowBreaking || false,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
const result = await gate.check({
|
|
52
|
+
projectPath,
|
|
53
|
+
} as any);
|
|
54
|
+
|
|
55
|
+
if (result.passed) {
|
|
56
|
+
console.log();
|
|
57
|
+
console.log(chalk.green('✅ 契约门控检查通过'));
|
|
58
|
+
|
|
59
|
+
if (result.details) {
|
|
60
|
+
console.log(chalk.gray(` Schema 有效: ✅`));
|
|
61
|
+
if (result.details.endpoints) {
|
|
62
|
+
console.log(chalk.gray(` 端点数: ${result.details.endpoints}`));
|
|
63
|
+
}
|
|
64
|
+
if (result.details.breakingChanges === false) {
|
|
65
|
+
console.log(chalk.gray(` 破坏性变更: 无`));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
console.log();
|
|
70
|
+
console.log(chalk.red('❌ 契约门控检查失败'));
|
|
71
|
+
console.log(chalk.red(` ${result.message}`));
|
|
72
|
+
|
|
73
|
+
if (result.details?.errors) {
|
|
74
|
+
console.log();
|
|
75
|
+
console.log(chalk.red('验证错误:'));
|
|
76
|
+
(result.details.errors as string[]).forEach((error: string) => {
|
|
77
|
+
console.log(chalk.red(` - ${error}`));
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (result.details?.breakingChanges) {
|
|
82
|
+
console.log();
|
|
83
|
+
console.log(chalk.red('破坏性变更:'));
|
|
84
|
+
(result.details.breakingChanges as any[]).forEach((change: any) => {
|
|
85
|
+
console.log(chalk.red(` - ${change.type}: ${change.path}`));
|
|
86
|
+
if (change.description) {
|
|
87
|
+
console.log(chalk.gray(` ${change.description}`));
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
} catch (error: any) {
|
|
95
|
+
console.log();
|
|
96
|
+
console.log(chalk.red('❌ 契约门控检查出错'));
|
|
97
|
+
console.log(chalk.red(` ${error.message}`));
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 验证 OpenAPI Schema 语法
|
|
104
|
+
*/
|
|
105
|
+
export async function validateSchema(options: ContractOptions): Promise<void> {
|
|
106
|
+
console.log(chalk.blue('📜 验证 OpenAPI Schema...\n'));
|
|
107
|
+
|
|
108
|
+
const projectPath = options.projectPath || process.cwd();
|
|
109
|
+
const contractPath = options.contractPath || 'openapi.yaml';
|
|
110
|
+
|
|
111
|
+
try {
|
|
112
|
+
const yaml = await import('js-yaml');
|
|
113
|
+
|
|
114
|
+
const fullPath = path.join(projectPath, contractPath);
|
|
115
|
+
const content = await fs.readFile(fullPath, 'utf-8');
|
|
116
|
+
|
|
117
|
+
let schema: any;
|
|
118
|
+
try {
|
|
119
|
+
schema = yaml.load(content);
|
|
120
|
+
} catch (e: any) {
|
|
121
|
+
console.log(chalk.red(`❌ YAML 解析错误: ${e.message}`));
|
|
122
|
+
process.exit(1);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// 基本验证
|
|
126
|
+
const errors: string[] = [];
|
|
127
|
+
|
|
128
|
+
if (!schema.openapi) {
|
|
129
|
+
errors.push('缺少 openapi 字段');
|
|
130
|
+
} else if (!schema.openapi.startsWith('3.')) {
|
|
131
|
+
errors.push(`OpenAPI 版本建议使用 3.x,当前: ${schema.openapi}`);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (!schema.info) {
|
|
135
|
+
errors.push('缺少 info 字段');
|
|
136
|
+
} else {
|
|
137
|
+
if (!schema.info.title) errors.push('缺少 info.title');
|
|
138
|
+
if (!schema.info.version) errors.push('缺少 info.version');
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (!schema.paths || Object.keys(schema.paths).length === 0) {
|
|
142
|
+
errors.push('缺少 paths 字段或路径为空');
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (errors.length > 0) {
|
|
146
|
+
console.log(chalk.red('❌ Schema 验证失败:\n'));
|
|
147
|
+
errors.forEach(err => console.log(chalk.red(` - ${err}`)));
|
|
148
|
+
process.exit(1);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
console.log(chalk.green('✅ Schema 验证通过'));
|
|
152
|
+
console.log();
|
|
153
|
+
console.log(chalk.gray('Schema 信息:'));
|
|
154
|
+
console.log(chalk.gray(` 版本: ${schema.openapi}`));
|
|
155
|
+
console.log(chalk.gray(` 标题: ${schema.info.title}`));
|
|
156
|
+
console.log(chalk.gray(` API 版本: ${schema.info.version}`));
|
|
157
|
+
|
|
158
|
+
if (schema.paths) {
|
|
159
|
+
const endpoints = Object.keys(schema.paths).flatMap(path =>
|
|
160
|
+
Object.keys(schema.paths[path]).map(method => `${method.toUpperCase()} ${path}`)
|
|
161
|
+
);
|
|
162
|
+
console.log(chalk.gray(` 端点数: ${endpoints.length}`));
|
|
163
|
+
}
|
|
164
|
+
} catch (error: any) {
|
|
165
|
+
console.log(chalk.red(`❌ 验证失败: ${error.message}`));
|
|
166
|
+
process.exit(1);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* harness failure 命令
|
|
3
|
+
*
|
|
4
|
+
* 失败记录管理:list、stats、clear
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import chalk from 'chalk';
|
|
8
|
+
import * as path from 'path';
|
|
9
|
+
import { FailureRecorder } from '../../failure/recorder';
|
|
10
|
+
|
|
11
|
+
export interface FailureOptions {
|
|
12
|
+
/** 项目路径 */
|
|
13
|
+
projectPath?: string;
|
|
14
|
+
/** 输出 JSON 格式 */
|
|
15
|
+
json?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 获取失败记录器
|
|
20
|
+
*/
|
|
21
|
+
function getRecorder(projectPath?: string): FailureRecorder {
|
|
22
|
+
const base = projectPath || process.cwd();
|
|
23
|
+
return new FailureRecorder({
|
|
24
|
+
logFile: path.join(base, '.harness', 'failures', 'failures.log'),
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 失败记录列表
|
|
30
|
+
*/
|
|
31
|
+
export async function failureList(
|
|
32
|
+
options: FailureOptions & { limit?: number; type?: string; level?: string },
|
|
33
|
+
): Promise<void> {
|
|
34
|
+
const recorder = getRecorder(options.projectPath);
|
|
35
|
+
|
|
36
|
+
let records = await recorder.getHistory();
|
|
37
|
+
|
|
38
|
+
if (options.type) {
|
|
39
|
+
records = records.filter(r => r.type === options.type);
|
|
40
|
+
}
|
|
41
|
+
if (options.level) {
|
|
42
|
+
records = records.filter(r => r.level === options.level);
|
|
43
|
+
}
|
|
44
|
+
if (options.limit && options.limit > 0) {
|
|
45
|
+
records = records.slice(-options.limit);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (options.json) {
|
|
49
|
+
console.log(JSON.stringify({ total: records.length, records }, null, 2));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (records.length === 0) {
|
|
54
|
+
console.log(chalk.yellow('没有失败记录'));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
console.log(chalk.red(`📋 失败记录 (${records.length} 条)\n`));
|
|
59
|
+
for (const record of records) {
|
|
60
|
+
const levelColor = record.level === 'L4' ? chalk.red
|
|
61
|
+
: record.level === 'L3' ? chalk.yellow
|
|
62
|
+
: record.level === 'L2' ? chalk.cyan
|
|
63
|
+
: chalk.gray;
|
|
64
|
+
const time = new Date(record.timestamp).toLocaleString();
|
|
65
|
+
console.log(` ${levelColor(`[${record.level}]`)} ${chalk.bold(record.type)} ${chalk.gray(time)}`);
|
|
66
|
+
console.log(` ${record.message}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 失败记录统计
|
|
72
|
+
*/
|
|
73
|
+
export async function failureStats(options: FailureOptions): Promise<void> {
|
|
74
|
+
const recorder = getRecorder(options.projectPath);
|
|
75
|
+
const stats = await recorder.getStats();
|
|
76
|
+
|
|
77
|
+
if (options.json) {
|
|
78
|
+
console.log(JSON.stringify(stats, null, 2));
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (stats.total === 0) {
|
|
83
|
+
console.log(chalk.green('✅ 没有失败记录'));
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
console.log(chalk.red(`📊 失败统计\n`));
|
|
88
|
+
console.log(chalk.bold(` 总计: ${stats.total} 条\n`));
|
|
89
|
+
|
|
90
|
+
console.log(chalk.bold(' 按类型:'));
|
|
91
|
+
for (const [type, count] of Object.entries(stats.byType)) {
|
|
92
|
+
console.log(` ${type}: ${count}`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
console.log(chalk.bold('\n 按等级:'));
|
|
96
|
+
for (const [level, count] of Object.entries(stats.byLevel)) {
|
|
97
|
+
const color = level === 'L4' ? chalk.red : level === 'L3' ? chalk.yellow : chalk.gray;
|
|
98
|
+
console.log(` ${color(level)}: ${count}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 清空失败记录
|
|
104
|
+
*/
|
|
105
|
+
export async function failureClear(options: FailureOptions): Promise<void> {
|
|
106
|
+
const recorder = getRecorder(options.projectPath);
|
|
107
|
+
const stats = await recorder.getStats();
|
|
108
|
+
|
|
109
|
+
await recorder.clear();
|
|
110
|
+
|
|
111
|
+
if (options.json) {
|
|
112
|
+
console.log(JSON.stringify({ cleared: stats.total }));
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
console.log(chalk.green(`✅ 已清空 ${stats.total} 条失败记录`));
|
|
117
|
+
}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* harness flow 命令
|
|
3
|
+
*
|
|
4
|
+
* 一键执行诊断 + 提案流程
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import chalk from 'chalk';
|
|
8
|
+
import * as fs from 'fs';
|
|
9
|
+
import * as path from 'path';
|
|
10
|
+
import * as readline from 'readline';
|
|
11
|
+
import { TraceCollector } from '../../monitoring/traces';
|
|
12
|
+
import { TraceAnalyzer } from '../../monitoring/trace-analyzer';
|
|
13
|
+
import { ConstraintDoctor, Diagnosis } from '../../monitoring/constraint-doctor';
|
|
14
|
+
import { ConstraintEvolver, ConstraintProposal } from '../../monitoring/constraint-evolver';
|
|
15
|
+
import { ConstraintLifecycleRunner, type ExecutionResult } from '../../constraints/lifecycle-runner';
|
|
16
|
+
import type { TraceAnomaly } from '../../types/trace';
|
|
17
|
+
|
|
18
|
+
export interface FlowOptions {
|
|
19
|
+
/** 项目路径 */
|
|
20
|
+
projectPath?: string;
|
|
21
|
+
/** 从哪个步骤开始 */
|
|
22
|
+
from?: 'analyze' | 'diagnose' | 'propose';
|
|
23
|
+
/** 自动应用低风险提案 */
|
|
24
|
+
autoApply?: boolean;
|
|
25
|
+
/** 自动执行已接受的提案(调用 ConstraintLifecycleRunner) */
|
|
26
|
+
autoExecute?: boolean;
|
|
27
|
+
/** 时间范围(小时) */
|
|
28
|
+
hours?: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 创建 readline 接口
|
|
33
|
+
*/
|
|
34
|
+
function createReadlineInterface(): readline.ReadLine {
|
|
35
|
+
return readline.createInterface({
|
|
36
|
+
input: process.stdin,
|
|
37
|
+
output: process.stdout,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 询问用户
|
|
43
|
+
*/
|
|
44
|
+
function ask(rl: readline.ReadLine, question: string): Promise<string> {
|
|
45
|
+
return new Promise(resolve => {
|
|
46
|
+
rl.question(question, answer => {
|
|
47
|
+
resolve(answer.trim().toLowerCase());
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 执行流程
|
|
54
|
+
*/
|
|
55
|
+
export async function flow(options: FlowOptions): Promise<void> {
|
|
56
|
+
const projectPath = options.projectPath || process.cwd();
|
|
57
|
+
const harnessDir = path.join(projectPath, '.harness');
|
|
58
|
+
const tracesPath = path.join(harnessDir, 'traces', 'execution.log');
|
|
59
|
+
const diagnosesDir = path.join(harnessDir, 'diagnoses');
|
|
60
|
+
const proposalsDir = path.join(harnessDir, 'proposals');
|
|
61
|
+
|
|
62
|
+
console.log(chalk.blue('🔄 Harness 自动化流程'));
|
|
63
|
+
console.log();
|
|
64
|
+
|
|
65
|
+
// 检查前置条件
|
|
66
|
+
if (!fs.existsSync(tracesPath)) {
|
|
67
|
+
console.log(chalk.yellow('⚠️ 暂无 Trace 记录'));
|
|
68
|
+
console.log(chalk.gray('💡 运行 harness check 开始记录'));
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 读取 traces
|
|
73
|
+
const tracesContent = fs.readFileSync(tracesPath, 'utf-8');
|
|
74
|
+
const lines = tracesContent.trim().split('\n').filter(Boolean);
|
|
75
|
+
const traces = lines.map(line => {
|
|
76
|
+
try {
|
|
77
|
+
return JSON.parse(line);
|
|
78
|
+
} catch {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}).filter(Boolean);
|
|
82
|
+
|
|
83
|
+
// 创建收集器和分析器
|
|
84
|
+
const collector = new TraceCollector({ traceFile: tracesPath });
|
|
85
|
+
const analyzer = new TraceAnalyzer(collector);
|
|
86
|
+
const summaries = analyzer.summarize(traces);
|
|
87
|
+
let anomalies = analyzer.detectAnomalies(summaries);
|
|
88
|
+
|
|
89
|
+
const rl = createReadlineInterface();
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
// 步骤 1: 分析统计
|
|
93
|
+
if (!options.from || options.from === 'analyze') {
|
|
94
|
+
console.log(chalk.blue('📊 步骤 1/4: 分析统计'));
|
|
95
|
+
console.log(chalk.gray('────────────────────────────'));
|
|
96
|
+
|
|
97
|
+
console.log(chalk.gray(`约束统计: ${summaries.length} 条`));
|
|
98
|
+
console.log(chalk.gray(`检测异常: ${anomalies.length} 个`));
|
|
99
|
+
|
|
100
|
+
if (anomalies.length === 0) {
|
|
101
|
+
console.log(chalk.green('✅ 未发现异常'));
|
|
102
|
+
rl.close();
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
console.log(chalk.yellow('发现异常:'));
|
|
107
|
+
anomalies.forEach((a: TraceAnomaly) => {
|
|
108
|
+
console.log(chalk.yellow(` - ${a.constraintId}: ${a.type}`));
|
|
109
|
+
});
|
|
110
|
+
console.log();
|
|
111
|
+
|
|
112
|
+
// 询问是否继续
|
|
113
|
+
const continue1 = await ask(rl, '是否继续运行诊断? [Y/n] ');
|
|
114
|
+
if (continue1 === 'n') {
|
|
115
|
+
console.log(chalk.gray('已取消'));
|
|
116
|
+
rl.close();
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
console.log();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// 步骤 2: 运行诊断
|
|
123
|
+
console.log(chalk.blue('🔍 步骤 2/4: 运行诊断'));
|
|
124
|
+
console.log(chalk.gray('────────────────────────────'));
|
|
125
|
+
|
|
126
|
+
const doctor = new ConstraintDoctor();
|
|
127
|
+
const diagnoses: Diagnosis[] = [];
|
|
128
|
+
|
|
129
|
+
for (const anomaly of anomalies) {
|
|
130
|
+
try {
|
|
131
|
+
const diagnosis = await doctor.diagnose(anomaly);
|
|
132
|
+
diagnoses.push(diagnosis);
|
|
133
|
+
} catch (e) {
|
|
134
|
+
console.log(chalk.yellow(` ⚠️ ${anomaly.constraintId} 诊断失败`));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
console.log(chalk.gray(`诊断数量: ${diagnoses.length}`));
|
|
139
|
+
|
|
140
|
+
if (diagnoses.length > 0) {
|
|
141
|
+
console.log();
|
|
142
|
+
diagnoses.forEach((d: Diagnosis) => {
|
|
143
|
+
console.log(chalk.yellow(` ${d.constraintId}`));
|
|
144
|
+
console.log(chalk.gray(` 根因: ${d.rootCause.primary}`));
|
|
145
|
+
console.log(chalk.gray(` 严重度: ${d.impact.severity}`));
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// 保存诊断结果
|
|
150
|
+
if (diagnoses.length > 0) {
|
|
151
|
+
fs.mkdirSync(diagnosesDir, { recursive: true });
|
|
152
|
+
const diagnosisFile = path.join(diagnosesDir, `${new Date().toISOString().split('T')[0]}.json`);
|
|
153
|
+
fs.writeFileSync(diagnosisFile, JSON.stringify(diagnoses, null, 2));
|
|
154
|
+
console.log(chalk.green(`✅ 诊断已保存: ${diagnosisFile}`));
|
|
155
|
+
}
|
|
156
|
+
console.log();
|
|
157
|
+
|
|
158
|
+
// 询问是否继续
|
|
159
|
+
const continue2 = await ask(rl, '是否继续生成优化提案? [Y/n] ');
|
|
160
|
+
if (continue2 === 'n') {
|
|
161
|
+
console.log(chalk.gray('已取消'));
|
|
162
|
+
rl.close();
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
console.log();
|
|
166
|
+
|
|
167
|
+
// 步骤 3: 生成提案
|
|
168
|
+
console.log(chalk.blue('💡 步骤 3/4: 生成提案'));
|
|
169
|
+
console.log(chalk.gray('────────────────────────────'));
|
|
170
|
+
|
|
171
|
+
const evolver = new ConstraintEvolver();
|
|
172
|
+
const proposals: ConstraintProposal[] = [];
|
|
173
|
+
|
|
174
|
+
for (const diagnosis of diagnoses) {
|
|
175
|
+
try {
|
|
176
|
+
const proposal = await evolver.propose(diagnosis);
|
|
177
|
+
if (proposal) {
|
|
178
|
+
proposals.push(proposal);
|
|
179
|
+
}
|
|
180
|
+
} catch (e) {
|
|
181
|
+
console.log(chalk.yellow(` ⚠️ ${diagnosis.constraintId} 提案生成失败`));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
console.log(chalk.gray(`提案数量: ${proposals.length}`));
|
|
186
|
+
|
|
187
|
+
if (proposals.length === 0) {
|
|
188
|
+
console.log(chalk.green('✅ 无需优化'));
|
|
189
|
+
rl.close();
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
console.log();
|
|
194
|
+
proposals.forEach((p: ConstraintProposal, i: number) => {
|
|
195
|
+
console.log(chalk.yellow(`提案 ${i + 1}:`));
|
|
196
|
+
console.log(chalk.gray(` 约束: ${p.constraintId}`));
|
|
197
|
+
console.log(chalk.gray(` 操作: ${p.type}`));
|
|
198
|
+
console.log(chalk.gray(` 风险: ${p.risk.level}`));
|
|
199
|
+
console.log();
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// 保存提案
|
|
203
|
+
fs.mkdirSync(proposalsDir, { recursive: true });
|
|
204
|
+
const proposalFile = path.join(proposalsDir, `${new Date().toISOString().split('T')[0]}.json`);
|
|
205
|
+
fs.writeFileSync(proposalFile, JSON.stringify({ proposals, timestamp: new Date().toISOString() }, null, 2));
|
|
206
|
+
console.log(chalk.green(`✅ 提案已保存: ${proposalFile}`));
|
|
207
|
+
console.log();
|
|
208
|
+
|
|
209
|
+
// 步骤 4: 审核提案
|
|
210
|
+
console.log(chalk.blue('📝 步骤 4/4: 审核提案'));
|
|
211
|
+
console.log(chalk.gray('────────────────────────────'));
|
|
212
|
+
|
|
213
|
+
const runner = options.autoExecute ? new ConstraintLifecycleRunner() : null;
|
|
214
|
+
const executionResults: ExecutionResult[] = [];
|
|
215
|
+
|
|
216
|
+
for (let i = 0; i < proposals.length; i++) {
|
|
217
|
+
const p = proposals[i];
|
|
218
|
+
|
|
219
|
+
// 低风险 → 可自动应用
|
|
220
|
+
if (options.autoApply && p.risk.level === 'low') {
|
|
221
|
+
console.log(chalk.green(`✅ 自动应用提案 ${i + 1} (低风险)`));
|
|
222
|
+
if (runner) {
|
|
223
|
+
const result = runner.execute(p);
|
|
224
|
+
executionResults.push(result);
|
|
225
|
+
if (result.success) {
|
|
226
|
+
console.log(chalk.green(` ✅ 已执行: ${result.details}`));
|
|
227
|
+
} else {
|
|
228
|
+
console.log(chalk.yellow(` ⚠️ 执行失败: ${result.details}`));
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// 需要人工审核
|
|
235
|
+
const answer = await ask(rl, `是否应用提案 ${i + 1}? [y/N] `);
|
|
236
|
+
if (answer === 'y') {
|
|
237
|
+
console.log(chalk.green(`✅ 提案 ${i + 1} 已标记为应用`));
|
|
238
|
+
if (runner) {
|
|
239
|
+
const result = runner.execute(p);
|
|
240
|
+
executionResults.push(result);
|
|
241
|
+
if (result.success) {
|
|
242
|
+
console.log(chalk.green(` ✅ 已执行: ${result.details}`));
|
|
243
|
+
} else {
|
|
244
|
+
console.log(chalk.yellow(` ⚠️ 执行失败: ${result.details}`));
|
|
245
|
+
}
|
|
246
|
+
} else {
|
|
247
|
+
console.log(chalk.gray(' 请手动更新约束配置'));
|
|
248
|
+
}
|
|
249
|
+
} else {
|
|
250
|
+
console.log(chalk.gray(`⏭️ 跳过提案 ${i + 1}`));
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// 显示执行摘要
|
|
255
|
+
if (executionResults.length > 0) {
|
|
256
|
+
console.log();
|
|
257
|
+
console.log(chalk.blue('📊 执行摘要:'));
|
|
258
|
+
const succeeded = executionResults.filter(r => r.success).length;
|
|
259
|
+
const failed = executionResults.filter(r => !r.success).length;
|
|
260
|
+
console.log(chalk.gray(` 成功: ${succeeded}, 失败: ${failed}`));
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
console.log();
|
|
264
|
+
console.log(chalk.green('✅ 流程完成!'));
|
|
265
|
+
console.log();
|
|
266
|
+
console.log(chalk.blue('💡 下一步:'));
|
|
267
|
+
console.log(chalk.gray(' 1. 查看提案文件确认变更'));
|
|
268
|
+
if (!runner) {
|
|
269
|
+
console.log(chalk.gray(' 2. 手动更新约束配置'));
|
|
270
|
+
}
|
|
271
|
+
console.log(chalk.gray(` ${runner ? '2' : '3'}. 运行 harness status 查看效果`));
|
|
272
|
+
} finally {
|
|
273
|
+
rl.close();
|
|
274
|
+
}
|
|
275
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI 命令导出
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export { check, listLaws, type CheckOptions } from './check';
|
|
6
|
+
export { validate, createExampleCheckpoint, DEFAULT_CHECKPOINTS, type ValidateOptions } from './validate';
|
|
7
|
+
export { runPassesGate, checkCoverage, type PassesGateOptions } from './passes-gate';
|
|
8
|
+
export { init, type InitOptions } from './init';
|
|
9
|
+
export { report, type ReportOptions } from './report';
|
|
10
|
+
export { status, type StatusOptions } from './status';
|
|
11
|
+
export { flow, type FlowOptions } from './flow';
|
|
12
|
+
export { specValidate, listSpecTypes, type SpecValidateOptions } from './spec';
|
|
13
|
+
export { acceptance, listAcceptanceCriteria, type AcceptanceOptions } from './acceptance';
|
|
14
|
+
export { performance, type PerformanceOptions } from './performance';
|
|
15
|
+
export { security, auditDetails, type SecurityOptions } from './security';
|
|
16
|
+
export { contract, validateSchema, type ContractOptions } from './contract';
|
|
17
|
+
export { review, reviewStatus, type ReviewOptions } from './review';
|
|
18
|
+
export { executeCommand, type CommandCheckOptions } from './command';
|
|
19
|
+
export { syncDocs, type SyncDocsOptions } from './sync-docs';
|
|
20
|
+
export { knowledgeList, knowledgeSearch, knowledgeImport, knowledgeDecay, knowledgeStats, knowledgeUpsert, knowledgeSyncStatus, knowledgeSyncRag, type KnowledgeOptions, type KnowledgeUpsertOptions } from './knowledge';
|
|
21
|
+
export { failureList, failureStats, failureClear, type FailureOptions } from './failure';
|
|
22
|
+
export { postevalPlan, type PostEvalPlanOptions } from './posteval-plan';
|
|
23
|
+
export { release, type ReleaseOptions } from './release';
|
|
24
|
+
export { analyzeSessions, type AnalyzeSessionsOptions } from './analyze-sessions';
|
|
25
|
+
export { updateUserModel, type UpdateUserModelOptions } from './update-user-model';
|
|
26
|
+
export { constraints, getConstraintsMeta, type ConstraintsMeta } from './constraints';
|