@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,441 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* harness check 命令
|
|
3
|
+
*
|
|
4
|
+
* 检查约束是否满足(三层:Iron Laws / Guidelines / Tips)
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import chalk from 'chalk';
|
|
8
|
+
import * as fs from 'fs';
|
|
9
|
+
import * as path from 'path';
|
|
10
|
+
import { exec, execSync } from 'child_process';
|
|
11
|
+
import { execAsync } from '../../utils/exec';
|
|
12
|
+
import { constraintChecker } from '../../core/constraints/checker';
|
|
13
|
+
import { getAllConstraints, IRON_LAWS, GUIDELINES, TIPS } from '../../core/constraints/definitions';
|
|
14
|
+
import { ProjectConfigLoader } from '../../core/project-config-loader';
|
|
15
|
+
import { detectSourceRoots } from '../../utils/detect-source-roots';
|
|
16
|
+
import type { ConstraintTrigger, ConstraintContext, ConstraintResult } from '../../types/constraint';
|
|
17
|
+
|
|
18
|
+
export interface CheckOptions {
|
|
19
|
+
/** 预设名称 */
|
|
20
|
+
preset: string;
|
|
21
|
+
/** 是否只检查暂存文件 */
|
|
22
|
+
staged: boolean;
|
|
23
|
+
/** 触发条件 */
|
|
24
|
+
trigger?: ConstraintTrigger;
|
|
25
|
+
/** 项目路径 */
|
|
26
|
+
projectPath?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 从 git diff 获取变更的文件
|
|
31
|
+
*/
|
|
32
|
+
async function getChangedFiles(staged: boolean): Promise<string[]> {
|
|
33
|
+
try {
|
|
34
|
+
const command = staged ? 'git diff --cached --name-only' : 'git diff --name-only';
|
|
35
|
+
const { stdout } = await execAsync(command);
|
|
36
|
+
return stdout.trim().split('\n').filter(Boolean);
|
|
37
|
+
} catch {
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 检查文件所在目录是否在 git HEAD 中不存在(即新目录)
|
|
44
|
+
*/
|
|
45
|
+
function isNewDirectory(projectPath: string, filePath: string): boolean {
|
|
46
|
+
const dir = path.dirname(filePath);
|
|
47
|
+
try {
|
|
48
|
+
const output = execSync(`git ls-tree HEAD -- "${dir}"`, { cwd: projectPath, stdio: 'pipe', encoding: 'utf-8' });
|
|
49
|
+
return String(output).trim().length === 0; // empty output = directory doesn't exist in HEAD
|
|
50
|
+
} catch {
|
|
51
|
+
return true; // command failed = assume new
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 检测触发条件
|
|
57
|
+
*/
|
|
58
|
+
function detectTrigger(changedFiles: string[], options: CheckOptions): ConstraintTrigger {
|
|
59
|
+
if (options.trigger) return options.trigger;
|
|
60
|
+
|
|
61
|
+
// 根据变更文件推断触发条件
|
|
62
|
+
// 注意:不自动推断 code_implementation——那是 caller 的语义判断。
|
|
63
|
+
// pre-commit 无法区分"模板编辑"和"逻辑实现",保守使用 file_modification。
|
|
64
|
+
const hasTestChange = changedFiles.some(f =>
|
|
65
|
+
f.includes('.test.') || f.includes('.spec.') || f.includes('__tests__')
|
|
66
|
+
);
|
|
67
|
+
const sourceRoots = detectSourceRoots(options.projectPath || process.cwd());
|
|
68
|
+
const hasModuleChange = changedFiles.some(f =>
|
|
69
|
+
sourceRoots.some(root => f.startsWith(root + '/') || f.startsWith(root + '\\')) && !f.includes('__tests__')
|
|
70
|
+
);
|
|
71
|
+
const projectPath = options.projectPath || process.cwd();
|
|
72
|
+
const hasModuleCreation = changedFiles.some(f =>
|
|
73
|
+
sourceRoots.some(root => f.startsWith(root + '/') || f.startsWith(root + '\\')) &&
|
|
74
|
+
isNewDirectory(projectPath, f)
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
if (hasTestChange && !hasModuleChange) return 'test_creation';
|
|
78
|
+
if (hasModuleCreation) return 'module_creation';
|
|
79
|
+
if (hasModuleChange) return 'module_modification';
|
|
80
|
+
|
|
81
|
+
return 'file_modification';
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 执行约束检查
|
|
86
|
+
*/
|
|
87
|
+
export async function check(options: CheckOptions): Promise<void> {
|
|
88
|
+
console.log(chalk.blue('🔍 检查约束...'));
|
|
89
|
+
console.log(chalk.gray(`预设: ${options.preset}`));
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
// 加载项目级自定义约束
|
|
93
|
+
const projectPath = options.projectPath || process.cwd();
|
|
94
|
+
const configLoader = new ProjectConfigLoader(projectPath);
|
|
95
|
+
configLoader.load();
|
|
96
|
+
|
|
97
|
+
if (configLoader.hasCustomConfig()) {
|
|
98
|
+
const merged = configLoader.mergeConstraints();
|
|
99
|
+
constraintChecker.setCustomConfig(merged);
|
|
100
|
+
console.log(chalk.gray(`自定义约束: ${merged.custom.length} 条`));
|
|
101
|
+
if (merged.disabled.length > 0) {
|
|
102
|
+
console.log(chalk.gray(`已禁用约束: ${merged.disabled.join(', ')}`));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// 获取变更文件
|
|
107
|
+
const changedFiles = await getChangedFiles(options.staged);
|
|
108
|
+
if (changedFiles.length > 0) {
|
|
109
|
+
console.log(chalk.gray(`变更文件: ${changedFiles.length} 个`));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// 检测触发条件
|
|
113
|
+
const trigger = detectTrigger(changedFiles, options);
|
|
114
|
+
console.log(chalk.gray(`触发条件: ${trigger}`));
|
|
115
|
+
|
|
116
|
+
// 构建上下文
|
|
117
|
+
const context: ConstraintContext = {
|
|
118
|
+
operation: trigger,
|
|
119
|
+
projectPath: options.projectPath || process.cwd(),
|
|
120
|
+
changedFiles,
|
|
121
|
+
hasTest: changedFiles.some(f => f.includes('.test.') || f.includes('.spec.')),
|
|
122
|
+
hasFailingTest: await detectFailingTest(projectPath),
|
|
123
|
+
hasRootCauseInvestigation: detectRootCauseInvestigation(projectPath),
|
|
124
|
+
hasVerificationEvidence: await detectVerificationEvidence(projectPath),
|
|
125
|
+
hasReuseCheck: detectReuseCheck(projectPath),
|
|
126
|
+
hasRequirement: detectRequirement(projectPath),
|
|
127
|
+
hasWorktree: detectWorktree(projectPath),
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// 执行三层检查
|
|
131
|
+
const result = await constraintChecker.checkConstraints(context);
|
|
132
|
+
|
|
133
|
+
// 输出结果
|
|
134
|
+
console.log();
|
|
135
|
+
|
|
136
|
+
// Iron Laws
|
|
137
|
+
const ironLawViolations = result.ironLaws.filter(r => !r.satisfied);
|
|
138
|
+
if (ironLawViolations.length === 0 && result.ironLaws.length > 0) {
|
|
139
|
+
console.log(chalk.green(`✅ 铁律: 全部通过 (${result.ironLaws.length} 条)`));
|
|
140
|
+
} else if (ironLawViolations.length > 0) {
|
|
141
|
+
console.log(chalk.red(`❌ 铁律违规: ${ironLawViolations.length} 条`));
|
|
142
|
+
ironLawViolations.forEach(r => {
|
|
143
|
+
if (r.constraint) {
|
|
144
|
+
console.log(chalk.red(` - ${r.constraint.id}: ${r.constraint.message}`));
|
|
145
|
+
console.log(chalk.red(` ${r.constraint.rule}`));
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
console.log();
|
|
149
|
+
console.log(chalk.red('🛑 铁律检查失败,请修复后再提交'));
|
|
150
|
+
process.exit(1);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Guidelines
|
|
154
|
+
if (result.warningCount > 0) {
|
|
155
|
+
console.log(chalk.yellow(`⚠️ 指导原则警告: ${result.warningCount} 条`));
|
|
156
|
+
result.guidelines.filter(r => !r.satisfied).forEach(r => {
|
|
157
|
+
if (r.constraint) {
|
|
158
|
+
console.log(chalk.yellow(` - ${r.constraint.id}: ${r.constraint.message}`));
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
} else if (result.guidelines.length > 0) {
|
|
162
|
+
const passedGuidelines = result.guidelines.filter(r => r.satisfied).length;
|
|
163
|
+
console.log(chalk.green(`✅ 指导原则: ${passedGuidelines}/${result.guidelines.length} 通过`));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Tips
|
|
167
|
+
if (result.tipCount > 0) {
|
|
168
|
+
console.log(chalk.blue(`💡 提示: ${result.tipCount} 条`));
|
|
169
|
+
result.tips.filter(r => !r.satisfied).forEach(r => {
|
|
170
|
+
if (r.constraint) {
|
|
171
|
+
console.log(chalk.blue(` - ${r.constraint.id}: ${r.constraint.message}`));
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
console.log();
|
|
177
|
+
console.log(chalk.green('✅ 约束检查通过'));
|
|
178
|
+
|
|
179
|
+
// 智能提示
|
|
180
|
+
const hint = await getSmartHint(projectPath);
|
|
181
|
+
if (hint) {
|
|
182
|
+
console.log();
|
|
183
|
+
console.log(chalk.gray('────────────────────────────────────'));
|
|
184
|
+
console.log(hint);
|
|
185
|
+
console.log(chalk.gray('────────────────────────────────────'));
|
|
186
|
+
}
|
|
187
|
+
} catch (error) {
|
|
188
|
+
console.log();
|
|
189
|
+
console.log(chalk.red(`❌ 约束检查异常: ${error instanceof Error ? error.message : String(error)}`));
|
|
190
|
+
process.exit(1);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* 检测是否有失败的测试记录
|
|
196
|
+
* 扫描 .harness/traces/ 中最近的 trace 记录
|
|
197
|
+
*/
|
|
198
|
+
async function detectFailingTest(projectPath: string): Promise<boolean> {
|
|
199
|
+
try {
|
|
200
|
+
const tracesDir = path.join(projectPath, '.harness', 'traces');
|
|
201
|
+
if (!fs.existsSync(tracesDir)) return false;
|
|
202
|
+
|
|
203
|
+
const traceFile = path.join(tracesDir, 'execution.log');
|
|
204
|
+
if (!fs.existsSync(traceFile)) return false;
|
|
205
|
+
|
|
206
|
+
const content = fs.readFileSync(traceFile, 'utf-8');
|
|
207
|
+
const lines = content.trim().split('\n').filter(Boolean);
|
|
208
|
+
if (lines.length === 0) return false;
|
|
209
|
+
|
|
210
|
+
// 检查最近 20 条记录是否有 fail
|
|
211
|
+
const recent = lines.slice(-20);
|
|
212
|
+
return recent.some(line => {
|
|
213
|
+
try {
|
|
214
|
+
const trace = JSON.parse(line);
|
|
215
|
+
return trace.result === 'fail';
|
|
216
|
+
} catch {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
} catch {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* 检测是否有根因分析文档
|
|
227
|
+
* 检查 ROOT_CAUSE.md、.harness/diagnoses/、或 git commit 消息
|
|
228
|
+
*/
|
|
229
|
+
function detectRootCauseInvestigation(projectPath: string): boolean {
|
|
230
|
+
// 检查 ROOT_CAUSE.md
|
|
231
|
+
if (fs.existsSync(path.join(projectPath, 'ROOT_CAUSE.md'))) return true;
|
|
232
|
+
|
|
233
|
+
// 检查 .harness/diagnoses/ 目录
|
|
234
|
+
const diagnosesDir = path.join(projectPath, '.harness', 'diagnoses');
|
|
235
|
+
if (fs.existsSync(diagnosesDir)) {
|
|
236
|
+
try {
|
|
237
|
+
const files = fs.readdirSync(diagnosesDir);
|
|
238
|
+
if (files.length > 0) return true;
|
|
239
|
+
} catch {
|
|
240
|
+
// ignore
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* 检测是否有验证证据
|
|
249
|
+
* 检查 .harness/traces/ 中最近的成功验证记录
|
|
250
|
+
*/
|
|
251
|
+
async function detectVerificationEvidence(projectPath: string): Promise<boolean> {
|
|
252
|
+
try {
|
|
253
|
+
const tracesDir = path.join(projectPath, '.harness', 'traces');
|
|
254
|
+
if (!fs.existsSync(tracesDir)) return false;
|
|
255
|
+
|
|
256
|
+
const traceFile = path.join(tracesDir, 'execution.log');
|
|
257
|
+
if (!fs.existsSync(traceFile)) return false;
|
|
258
|
+
|
|
259
|
+
const content = fs.readFileSync(traceFile, 'utf-8');
|
|
260
|
+
const lines = content.trim().split('\n').filter(Boolean);
|
|
261
|
+
if (lines.length === 0) return false;
|
|
262
|
+
|
|
263
|
+
// 检查最近 10 条记录是否有 pass
|
|
264
|
+
const recent = lines.slice(-10);
|
|
265
|
+
return recent.some(line => {
|
|
266
|
+
try {
|
|
267
|
+
const trace = JSON.parse(line);
|
|
268
|
+
return trace.result === 'pass';
|
|
269
|
+
} catch {
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
} catch {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* 检测是否有复用检查
|
|
280
|
+
* 检查 .harness/reuse/ 目录或相关文档
|
|
281
|
+
*/
|
|
282
|
+
/**
|
|
283
|
+
* 检测是否有需求来源
|
|
284
|
+
* 检查 CLAUDE.md、README.md、specs/、docs/specs/ 等
|
|
285
|
+
*/
|
|
286
|
+
function detectRequirement(projectPath: string): boolean {
|
|
287
|
+
// Check for CLAUDE.md with HARNESS_CONSTRAINTS section
|
|
288
|
+
const claudeMdPath = path.join(projectPath, 'CLAUDE.md');
|
|
289
|
+
if (fs.existsSync(claudeMdPath)) {
|
|
290
|
+
try {
|
|
291
|
+
const content = fs.readFileSync(claudeMdPath, 'utf-8');
|
|
292
|
+
if (content.includes('HARNESS_CONSTRAINTS')) {
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
} catch {
|
|
296
|
+
// ignore
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const indicators = [
|
|
301
|
+
'README.md',
|
|
302
|
+
'specs',
|
|
303
|
+
'docs/specs',
|
|
304
|
+
'.specs',
|
|
305
|
+
];
|
|
306
|
+
return indicators.some(f => fs.existsSync(path.join(projectPath, f)));
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* 检测是否在 git worktree 中
|
|
311
|
+
*/
|
|
312
|
+
function detectWorktree(projectPath: string): boolean {
|
|
313
|
+
try {
|
|
314
|
+
const gitDir = path.join(projectPath, '.git');
|
|
315
|
+
if (fs.existsSync(gitDir)) {
|
|
316
|
+
const content = fs.readFileSync(gitDir, 'utf-8');
|
|
317
|
+
// 实际 worktree 的 .git 是文件(指向主 repo),不是目录
|
|
318
|
+
return content.startsWith('gitdir:');
|
|
319
|
+
}
|
|
320
|
+
} catch { /* ignore */ }
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function detectReuseCheck(projectPath: string): boolean {
|
|
325
|
+
const reuseDir = path.join(projectPath, '.harness', 'reuse');
|
|
326
|
+
if (fs.existsSync(reuseDir)) {
|
|
327
|
+
try {
|
|
328
|
+
const files = fs.readdirSync(reuseDir);
|
|
329
|
+
if (files.length > 0) return true;
|
|
330
|
+
} catch {
|
|
331
|
+
// ignore
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* 智能提示:检查是否需要提示用户下一步操作
|
|
340
|
+
*/
|
|
341
|
+
async function getSmartHint(projectPath: string): Promise<string | null> {
|
|
342
|
+
const tracesPath = path.join(projectPath, '.harness', 'traces', 'execution.log');
|
|
343
|
+
const statePath = path.join(projectPath, '.harness', '.state.json');
|
|
344
|
+
|
|
345
|
+
// 检查 trace 文件是否存在
|
|
346
|
+
if (!fs.existsSync(tracesPath)) {
|
|
347
|
+
return null;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// 读取 trace 记录数
|
|
351
|
+
const tracesContent = fs.readFileSync(tracesPath, 'utf-8');
|
|
352
|
+
const lines = tracesContent.trim().split('\n').filter(Boolean);
|
|
353
|
+
const traceCount = lines.length;
|
|
354
|
+
|
|
355
|
+
// 读取状态
|
|
356
|
+
let state: {
|
|
357
|
+
shownHints?: string[];
|
|
358
|
+
lastStatusRun?: string;
|
|
359
|
+
lastDiagnoseRun?: string;
|
|
360
|
+
} = {};
|
|
361
|
+
if (fs.existsSync(statePath)) {
|
|
362
|
+
state = JSON.parse(fs.readFileSync(statePath, 'utf-8'));
|
|
363
|
+
}
|
|
364
|
+
state.shownHints = state.shownHints || [];
|
|
365
|
+
|
|
366
|
+
const hints: string[] = [];
|
|
367
|
+
|
|
368
|
+
// 条件 1: 记录数首次达到 50
|
|
369
|
+
if (traceCount >= 50 && !state.shownHints.includes('trace_50')) {
|
|
370
|
+
hints.push('📊 记录已足够,运行 harness status 查看统计');
|
|
371
|
+
state.shownHints.push('trace_50');
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// 条件 2: 记录数达到 100 且从未运行过诊断
|
|
375
|
+
if (traceCount >= 100 && !state.lastDiagnoseRun && !state.shownHints.includes('flow_suggest')) {
|
|
376
|
+
hints.push('💡 数据充足,建议运行 harness flow 查看诊断');
|
|
377
|
+
state.shownHints.push('flow_suggest');
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// 条件 3: 检查异常趋势(简单检查绕过率)
|
|
381
|
+
const bypassCount = lines.filter(line => {
|
|
382
|
+
try {
|
|
383
|
+
const trace = JSON.parse(line);
|
|
384
|
+
return trace.result === 'bypassed';
|
|
385
|
+
} catch {
|
|
386
|
+
return false;
|
|
387
|
+
}
|
|
388
|
+
}).length;
|
|
389
|
+
|
|
390
|
+
const bypassRate = traceCount > 10 ? bypassCount / traceCount : 0;
|
|
391
|
+
if (bypassRate > 0.3 && !state.shownHints.includes('high_bypass')) {
|
|
392
|
+
hints.push('⚠️ 发现异常趋势,建议运行 harness status 查看详情');
|
|
393
|
+
state.shownHints.push('high_bypass');
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// 保存状态
|
|
397
|
+
if (hints.length > 0) {
|
|
398
|
+
fs.mkdirSync(path.dirname(statePath), { recursive: true });
|
|
399
|
+
fs.writeFileSync(statePath, JSON.stringify(state, null, 2));
|
|
400
|
+
return hints.join('\n');
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
return null;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* 列出所有约束
|
|
408
|
+
*/
|
|
409
|
+
export function listLaws(): void {
|
|
410
|
+
console.log(chalk.blue('\n📜 所有约束:\n'));
|
|
411
|
+
|
|
412
|
+
// Iron Laws
|
|
413
|
+
console.log(chalk.red('🔴 铁律 (Iron Laws) - 绝对禁止,无例外:\n'));
|
|
414
|
+
Object.values(IRON_LAWS).forEach(constraint => {
|
|
415
|
+
console.log(chalk.red(` ${constraint.id}`));
|
|
416
|
+
console.log(chalk.gray(` ${constraint.rule}`));
|
|
417
|
+
console.log(chalk.gray(` ${constraint.message}`));
|
|
418
|
+
console.log();
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
// Guidelines
|
|
422
|
+
console.log(chalk.yellow('🟡 指导原则 (Guidelines) - 优先建议,有例外:\n'));
|
|
423
|
+
Object.values(GUIDELINES).forEach(constraint => {
|
|
424
|
+
console.log(chalk.yellow(` ${constraint.id}`));
|
|
425
|
+
console.log(chalk.gray(` ${constraint.rule}`));
|
|
426
|
+
console.log(chalk.gray(` ${constraint.message}`));
|
|
427
|
+
if (constraint.exceptions && constraint.exceptions.length > 0) {
|
|
428
|
+
console.log(chalk.gray(` 例外: ${constraint.exceptions.join(', ')}`));
|
|
429
|
+
}
|
|
430
|
+
console.log();
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
// Tips
|
|
434
|
+
console.log(chalk.blue('🔵 提示 (Tips) - 信息性,可忽略:\n'));
|
|
435
|
+
Object.values(TIPS).forEach(constraint => {
|
|
436
|
+
console.log(chalk.blue(` ${constraint.id}`));
|
|
437
|
+
console.log(chalk.gray(` ${constraint.rule}`));
|
|
438
|
+
console.log(chalk.gray(` ${constraint.message}`));
|
|
439
|
+
console.log();
|
|
440
|
+
});
|
|
441
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 命令黑名单检查
|
|
3
|
+
*
|
|
4
|
+
* 用法:
|
|
5
|
+
* harness command "rm -rf /"
|
|
6
|
+
* harness command --level "DROP TABLE users"
|
|
7
|
+
* harness command --list
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { createCommandGate, getCommandRiskLevel, DEFAULT_COMMAND_BLACKLIST, type CommandBlacklistRule } from '../../gates';
|
|
11
|
+
|
|
12
|
+
export interface CommandCheckOptions {
|
|
13
|
+
level?: boolean;
|
|
14
|
+
list?: boolean;
|
|
15
|
+
json?: boolean;
|
|
16
|
+
strict?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 执行命令黑名单检查(供 bin/harness.js 调用)
|
|
21
|
+
*/
|
|
22
|
+
export async function executeCommand(cmd: string | undefined, options: CommandCheckOptions): Promise<void> {
|
|
23
|
+
if (options.list) {
|
|
24
|
+
if (options.json) {
|
|
25
|
+
console.log(JSON.stringify(DEFAULT_COMMAND_BLACKLIST.map((r: CommandBlacklistRule) => ({
|
|
26
|
+
id: r.id,
|
|
27
|
+
level: r.level,
|
|
28
|
+
message: r.message,
|
|
29
|
+
category: r.category,
|
|
30
|
+
})), null, 2));
|
|
31
|
+
} else {
|
|
32
|
+
console.log('\n命令黑名单规则:\n');
|
|
33
|
+
|
|
34
|
+
const byCategory = DEFAULT_COMMAND_BLACKLIST.reduce((acc: Record<string, CommandBlacklistRule[]>, rule: CommandBlacklistRule) => {
|
|
35
|
+
if (!acc[rule.category]) acc[rule.category] = [];
|
|
36
|
+
acc[rule.category].push(rule);
|
|
37
|
+
return acc;
|
|
38
|
+
}, {});
|
|
39
|
+
|
|
40
|
+
for (const [category, rules] of Object.entries(byCategory)) {
|
|
41
|
+
console.log(`[${category}]`);
|
|
42
|
+
for (const rule of rules as CommandBlacklistRule[]) {
|
|
43
|
+
const levelIcon = rule.level === 'block' ? '🚫' : rule.level === 'warn' ? '⚠️' : '📋';
|
|
44
|
+
console.log(` ${levelIcon} ${rule.id}: ${rule.message} (${rule.level})`);
|
|
45
|
+
}
|
|
46
|
+
console.log();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
console.log(`共 ${DEFAULT_COMMAND_BLACKLIST.length} 条规则`);
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!cmd) {
|
|
55
|
+
console.error('错误:请提供要检查的命令');
|
|
56
|
+
console.error('用法:harness command "your command"');
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const gate = createCommandGate({ strict: options.strict });
|
|
61
|
+
const result = await gate.check(cmd);
|
|
62
|
+
|
|
63
|
+
if (options.level) {
|
|
64
|
+
const level = getCommandRiskLevel(cmd);
|
|
65
|
+
if (options.json) {
|
|
66
|
+
console.log(JSON.stringify({ level, command: cmd }));
|
|
67
|
+
} else {
|
|
68
|
+
const levelColors: Record<string, string> = {
|
|
69
|
+
high: '\x1b[31m',
|
|
70
|
+
medium: '\x1b[33m',
|
|
71
|
+
low: '\x1b[32m',
|
|
72
|
+
};
|
|
73
|
+
console.log(`${levelColors[level]}${level}\x1b[0m ${cmd}`);
|
|
74
|
+
}
|
|
75
|
+
process.exit(level === 'high' ? 1 : 0);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (options.json) {
|
|
79
|
+
console.log(JSON.stringify({
|
|
80
|
+
command: cmd,
|
|
81
|
+
passed: result.passed,
|
|
82
|
+
message: result.message,
|
|
83
|
+
details: result.details,
|
|
84
|
+
}, null, 2));
|
|
85
|
+
} else {
|
|
86
|
+
console.log(result.passed ? `\x1b[32m✓\x1b[0m ${result.message}` : `\x1b[31m✗\x1b[0m ${result.message}`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
process.exit(result.passed ? 0 : 1);
|
|
90
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* harness constraints -- 约束集合元数据导出
|
|
3
|
+
*
|
|
4
|
+
* 纯数据导出,不调用 LLM,不访问文件系统(除 definitions.ts)。
|
|
5
|
+
* 供 Studio 等消费者获取约束的 hash、计数、文本大小等元数据。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { readFileSync, existsSync } from 'fs';
|
|
9
|
+
import { join } from 'path';
|
|
10
|
+
import { createHash } from 'crypto';
|
|
11
|
+
import { getAllConstraints } from '../../core/constraints/definitions';
|
|
12
|
+
|
|
13
|
+
export interface ConstraintsMeta {
|
|
14
|
+
version: string;
|
|
15
|
+
hash: string;
|
|
16
|
+
counts: { ironLaws: number; guidelines: number; tips: number };
|
|
17
|
+
textSize: { total: number; perConstraint: number };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function getPackageVersion(): string {
|
|
21
|
+
// Try several common locations
|
|
22
|
+
const candidates = [
|
|
23
|
+
join(__dirname, '..', '..', '..', 'package.json'),
|
|
24
|
+
join(process.cwd(), 'package.json'),
|
|
25
|
+
];
|
|
26
|
+
for (const p of candidates) {
|
|
27
|
+
if (existsSync(p)) {
|
|
28
|
+
try {
|
|
29
|
+
return JSON.parse(readFileSync(p, 'utf-8')).version;
|
|
30
|
+
} catch {
|
|
31
|
+
// continue to next candidate
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return 'unknown';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function getConstraintsMeta(): ConstraintsMeta {
|
|
39
|
+
const constraints = getAllConstraints();
|
|
40
|
+
|
|
41
|
+
const ironLaws = constraints.filter(c => c.level === 'iron_law');
|
|
42
|
+
const guidelines = constraints.filter(c => c.level === 'guideline');
|
|
43
|
+
const tips = constraints.filter(c => c.level === 'tip');
|
|
44
|
+
|
|
45
|
+
// 计算总 promptInjection 文本长度(字符数,可估算 token)
|
|
46
|
+
const totalTextSize = constraints
|
|
47
|
+
.map(c => (c.promptInjection || '').length)
|
|
48
|
+
.reduce((sum, len) => sum + len, 0);
|
|
49
|
+
|
|
50
|
+
// 稳定 JSON 序列化后取 hash
|
|
51
|
+
const hashInput = JSON.stringify({
|
|
52
|
+
ironLaws: ironLaws.map(c => ({ id: c.id, promptInjection: c.promptInjection })),
|
|
53
|
+
guidelines: guidelines.map(c => ({ id: c.id, promptInjection: c.promptInjection })),
|
|
54
|
+
tips: tips.map(c => ({ id: c.id, promptInjection: c.promptInjection })),
|
|
55
|
+
});
|
|
56
|
+
const hash = createHash('sha256').update(hashInput).digest('hex');
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
version: getPackageVersion(),
|
|
60
|
+
hash,
|
|
61
|
+
counts: {
|
|
62
|
+
ironLaws: ironLaws.length,
|
|
63
|
+
guidelines: guidelines.length,
|
|
64
|
+
tips: tips.length,
|
|
65
|
+
},
|
|
66
|
+
textSize: {
|
|
67
|
+
total: totalTextSize,
|
|
68
|
+
perConstraint: constraints.length > 0 ? Math.round(totalTextSize / constraints.length) : 0,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* CLI handler: output --json
|
|
75
|
+
*/
|
|
76
|
+
export async function constraints(options: { json?: boolean }): Promise<void> {
|
|
77
|
+
const meta = getConstraintsMeta();
|
|
78
|
+
if (options.json) {
|
|
79
|
+
console.log(JSON.stringify(meta, null, 2));
|
|
80
|
+
} else {
|
|
81
|
+
console.log(`version: ${meta.version}`);
|
|
82
|
+
console.log(`hash: ${meta.hash}`);
|
|
83
|
+
console.log(`ironLaws: ${meta.counts.ironLaws}, guidelines: ${meta.counts.guidelines}, tips: ${meta.counts.tips}`);
|
|
84
|
+
console.log(`textSize: ${meta.textSize.total} chars total, ~${meta.textSize.perConstraint} chars/constraint`);
|
|
85
|
+
}
|
|
86
|
+
}
|