@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,339 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execution Trace 收集器
|
|
3
|
+
*
|
|
4
|
+
* 轻量设计,零 Token 成本
|
|
5
|
+
*
|
|
6
|
+
* 功能:
|
|
7
|
+
* - 记录约束检查结果(追加写入)
|
|
8
|
+
* - 批量读取 traces(按时间范围过滤)
|
|
9
|
+
* - 文件滚动(防止文件过大)
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import * as fs from 'fs';
|
|
13
|
+
import * as path from 'path';
|
|
14
|
+
import type {
|
|
15
|
+
ExecutionTrace,
|
|
16
|
+
TraceFilter,
|
|
17
|
+
TraceCollectorConfig,
|
|
18
|
+
} from '../types/trace';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 默认配置
|
|
22
|
+
*/
|
|
23
|
+
const DEFAULT_CONFIG: TraceCollectorConfig = {
|
|
24
|
+
traceFile: '.harness/logs/traces.log',
|
|
25
|
+
maxFileSize: 10 * 1024 * 1024, // 10MB
|
|
26
|
+
enabled: true,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Trace 收集器
|
|
31
|
+
*
|
|
32
|
+
* 使用方式:
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const collector = new TraceCollector();
|
|
35
|
+
* collector.record({
|
|
36
|
+
* constraintId: 'no_fix_without_root_cause',
|
|
37
|
+
* level: 'iron_law',
|
|
38
|
+
* timestamp: Date.now(),
|
|
39
|
+
* result: 'fail',
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export class TraceCollector {
|
|
44
|
+
private config: TraceCollectorConfig;
|
|
45
|
+
private traceFile: string;
|
|
46
|
+
|
|
47
|
+
constructor(config?: Partial<TraceCollectorConfig>) {
|
|
48
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
49
|
+
this.traceFile = this.config.traceFile!;
|
|
50
|
+
this.ensureDirectory();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 确保 trace 目录存在
|
|
55
|
+
*/
|
|
56
|
+
private ensureDirectory(): void {
|
|
57
|
+
const dir = path.dirname(this.traceFile);
|
|
58
|
+
if (!fs.existsSync(dir)) {
|
|
59
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 记录一条 trace
|
|
65
|
+
*
|
|
66
|
+
* 轻量操作:
|
|
67
|
+
* - 追加写入(不读取现有内容)
|
|
68
|
+
* - 单行 JSON(便于批量处理)
|
|
69
|
+
* - 零 Token 成本
|
|
70
|
+
*/
|
|
71
|
+
record(trace: ExecutionTrace): void {
|
|
72
|
+
if (!this.config.enabled) return;
|
|
73
|
+
|
|
74
|
+
// 检查文件大小,必要时滚动
|
|
75
|
+
this.checkFileSize();
|
|
76
|
+
|
|
77
|
+
// 追加写入
|
|
78
|
+
const line = JSON.stringify(trace);
|
|
79
|
+
fs.appendFileSync(this.traceFile, line + '\n', 'utf-8');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 快捷方法:记录通过
|
|
84
|
+
*/
|
|
85
|
+
recordPass(
|
|
86
|
+
constraintId: string,
|
|
87
|
+
level: 'iron_law' | 'guideline' | 'tip',
|
|
88
|
+
options?: Partial<ExecutionTrace>
|
|
89
|
+
): void {
|
|
90
|
+
this.record({
|
|
91
|
+
constraintId,
|
|
92
|
+
level,
|
|
93
|
+
timestamp: Date.now(),
|
|
94
|
+
result: 'pass',
|
|
95
|
+
...options,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 快捷方法:记录失败
|
|
101
|
+
*/
|
|
102
|
+
recordFail(
|
|
103
|
+
constraintId: string,
|
|
104
|
+
level: 'iron_law' | 'guideline' | 'tip',
|
|
105
|
+
options?: Partial<ExecutionTrace>
|
|
106
|
+
): void {
|
|
107
|
+
this.record({
|
|
108
|
+
constraintId,
|
|
109
|
+
level,
|
|
110
|
+
timestamp: Date.now(),
|
|
111
|
+
result: 'fail',
|
|
112
|
+
...options,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 快捷方法:记录绕过
|
|
118
|
+
*/
|
|
119
|
+
recordBypass(
|
|
120
|
+
constraintId: string,
|
|
121
|
+
level: 'iron_law' | 'guideline' | 'tip',
|
|
122
|
+
bypassReason?: string,
|
|
123
|
+
options?: Partial<ExecutionTrace>
|
|
124
|
+
): void {
|
|
125
|
+
this.record({
|
|
126
|
+
constraintId,
|
|
127
|
+
level,
|
|
128
|
+
timestamp: Date.now(),
|
|
129
|
+
result: 'bypassed',
|
|
130
|
+
userAction: 'bypass',
|
|
131
|
+
bypassReason,
|
|
132
|
+
...options,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* 批量读取 traces
|
|
138
|
+
*
|
|
139
|
+
* 支持过滤条件:
|
|
140
|
+
* - 时间范围
|
|
141
|
+
* - 约束 ID
|
|
142
|
+
* - 结果类型
|
|
143
|
+
*/
|
|
144
|
+
read(filter?: TraceFilter): ExecutionTrace[] {
|
|
145
|
+
if (!fs.existsSync(this.traceFile)) {
|
|
146
|
+
return [];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const content = fs.readFileSync(this.traceFile, 'utf-8');
|
|
150
|
+
const lines = content.split('\n').filter(l => l.trim());
|
|
151
|
+
|
|
152
|
+
let traces = lines.map(line => JSON.parse(line) as ExecutionTrace);
|
|
153
|
+
|
|
154
|
+
// 应用过滤条件
|
|
155
|
+
if (filter) {
|
|
156
|
+
traces = this.applyFilter(traces, filter);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return traces;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* 读取最近 N 小时的 traces
|
|
164
|
+
*/
|
|
165
|
+
readRecent(hours: number): ExecutionTrace[] {
|
|
166
|
+
const start = Date.now() - hours * 3600 * 1000;
|
|
167
|
+
return this.read({ timeRange: { start, end: Date.now() } });
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* 读取特定约束的 traces
|
|
172
|
+
*/
|
|
173
|
+
readByConstraint(constraintId: string): ExecutionTrace[] {
|
|
174
|
+
return this.read({ constraintId });
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* 应用过滤条件
|
|
179
|
+
*/
|
|
180
|
+
private applyFilter(traces: ExecutionTrace[], filter: TraceFilter): ExecutionTrace[] {
|
|
181
|
+
return traces.filter(trace => {
|
|
182
|
+
// 约束 ID
|
|
183
|
+
if (filter.constraintId && trace.constraintId !== filter.constraintId) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// 层级
|
|
188
|
+
if (filter.level && trace.level !== filter.level) {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// 结果
|
|
193
|
+
if (filter.result && trace.result !== filter.result) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// 时间范围
|
|
198
|
+
if (filter.timeRange) {
|
|
199
|
+
if (trace.timestamp < filter.timeRange.start) {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
if (filter.timeRange.end && trace.timestamp > filter.timeRange.end) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// 项目路径
|
|
208
|
+
if (filter.projectPath && trace.projectPath !== filter.projectPath) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// 会话 ID
|
|
213
|
+
if (filter.sessionId && trace.sessionId !== filter.sessionId) {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return true;
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* 检查文件大小,必要时滚动
|
|
223
|
+
*/
|
|
224
|
+
private checkFileSize(): void {
|
|
225
|
+
if (!fs.existsSync(this.traceFile)) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const stats = fs.statSync(this.traceFile);
|
|
230
|
+
if (stats.size >= this.config.maxFileSize!) {
|
|
231
|
+
this.rotateFile();
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* 滚动文件
|
|
237
|
+
*
|
|
238
|
+
* 将当前文件重命名为带时间戳的备份
|
|
239
|
+
*/
|
|
240
|
+
private rotateFile(): void {
|
|
241
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
242
|
+
const backupFile = this.traceFile.replace('.log', `-${timestamp}.log`);
|
|
243
|
+
|
|
244
|
+
// 重命名当前文件
|
|
245
|
+
fs.renameSync(this.traceFile, backupFile);
|
|
246
|
+
|
|
247
|
+
// 创建新文件
|
|
248
|
+
fs.writeFileSync(this.traceFile, '', 'utf-8');
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* 清理旧备份文件
|
|
253
|
+
*
|
|
254
|
+
* 删除超过 maxAge 天的备份文件
|
|
255
|
+
*/
|
|
256
|
+
cleanupOldFiles(maxAgeDays: number = 30): number {
|
|
257
|
+
const dir = path.dirname(this.traceFile);
|
|
258
|
+
if (!fs.existsSync(dir)) {
|
|
259
|
+
return 0;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const files = fs.readdirSync(dir);
|
|
263
|
+
const backupFiles = files.filter(f => f.endsWith('.log') && f !== 'execution.log');
|
|
264
|
+
|
|
265
|
+
const cutoffTime = Date.now() - maxAgeDays * 24 * 3600 * 1000;
|
|
266
|
+
let deletedCount = 0;
|
|
267
|
+
|
|
268
|
+
for (const file of backupFiles) {
|
|
269
|
+
const filePath = path.join(dir, file);
|
|
270
|
+
const stats = fs.statSync(filePath);
|
|
271
|
+
|
|
272
|
+
if (stats.mtimeMs < cutoffTime) {
|
|
273
|
+
fs.unlinkSync(filePath);
|
|
274
|
+
deletedCount++;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return deletedCount;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* 获取 trace 文件统计信息
|
|
283
|
+
*/
|
|
284
|
+
getStats(): {
|
|
285
|
+
fileExists: boolean;
|
|
286
|
+
fileSize: number;
|
|
287
|
+
totalLines: number;
|
|
288
|
+
oldestTrace?: number;
|
|
289
|
+
newestTrace?: number;
|
|
290
|
+
} {
|
|
291
|
+
if (!fs.existsSync(this.traceFile)) {
|
|
292
|
+
return { fileExists: false, fileSize: 0, totalLines: 0 };
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const stats = fs.statSync(this.traceFile);
|
|
296
|
+
const content = fs.readFileSync(this.traceFile, 'utf-8');
|
|
297
|
+
const lines = content.split('\n').filter(l => l.trim());
|
|
298
|
+
|
|
299
|
+
let oldest: number | undefined;
|
|
300
|
+
let newest: number | undefined;
|
|
301
|
+
|
|
302
|
+
if (lines.length > 0) {
|
|
303
|
+
const firstTrace = JSON.parse(lines[0]) as ExecutionTrace;
|
|
304
|
+
const lastTrace = JSON.parse(lines[lines.length - 1]) as ExecutionTrace;
|
|
305
|
+
oldest = firstTrace.timestamp;
|
|
306
|
+
newest = lastTrace.timestamp;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return {
|
|
310
|
+
fileExists: true,
|
|
311
|
+
fileSize: stats.size,
|
|
312
|
+
totalLines: lines.length,
|
|
313
|
+
oldestTrace: oldest,
|
|
314
|
+
newestTrace: newest,
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* 全局单例(可选)
|
|
321
|
+
*/
|
|
322
|
+
let globalCollector: TraceCollector | null = null;
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* 获取全局收集器
|
|
326
|
+
*/
|
|
327
|
+
export function getTraceCollector(): TraceCollector {
|
|
328
|
+
if (!globalCollector) {
|
|
329
|
+
globalCollector = new TraceCollector();
|
|
330
|
+
}
|
|
331
|
+
return globalCollector;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* 配置全局收集器
|
|
336
|
+
*/
|
|
337
|
+
export function configureTraceCollector(config: Partial<TraceCollectorConfig>): void {
|
|
338
|
+
globalCollector = new TraceCollector(config);
|
|
339
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for standard.ts — applyPreset, getPreset, getIronLawPreset
|
|
3
|
+
*
|
|
4
|
+
* Pure logic, no I/O — tests preset selection and constraint filtering.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { applyPreset, getPreset, getIronLawPreset } from '../standard';
|
|
8
|
+
|
|
9
|
+
describe('getPreset', () => {
|
|
10
|
+
it('returns strict preset', () => {
|
|
11
|
+
const preset = getPreset('strict');
|
|
12
|
+
expect(preset.name).toBe('strict');
|
|
13
|
+
expect(preset.ironLaws).toBeNull();
|
|
14
|
+
expect(preset.guidelines).toBeNull();
|
|
15
|
+
expect(preset.tips).toBeNull();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('returns standard preset', () => {
|
|
19
|
+
const preset = getPreset('standard');
|
|
20
|
+
expect(preset.name).toBe('standard');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('returns relaxed preset', () => {
|
|
24
|
+
const preset = getPreset('relaxed');
|
|
25
|
+
expect(preset.name).toBe('relaxed');
|
|
26
|
+
expect(preset.ironLaws).toHaveLength(3);
|
|
27
|
+
expect(preset.guidelines).toHaveLength(2);
|
|
28
|
+
expect(preset.tips).toEqual([]);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('defaults to standard for unknown preset name', () => {
|
|
32
|
+
const preset = getPreset('unknown' as any);
|
|
33
|
+
expect(preset.name).toBe('standard');
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('applyPreset with string preset names', () => {
|
|
38
|
+
it('strict enables all iron laws and guidelines', () => {
|
|
39
|
+
const config = applyPreset('strict');
|
|
40
|
+
expect(config.ironLaws).toBeDefined();
|
|
41
|
+
expect(Object.keys(config.ironLaws).length).toBeGreaterThan(0);
|
|
42
|
+
expect(config.guidelines).toBeDefined();
|
|
43
|
+
expect(Object.keys(config.guidelines).length).toBeGreaterThan(0);
|
|
44
|
+
expect(config.disabled).toEqual([]);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('relaxed enables only specific constraints', () => {
|
|
48
|
+
const config = applyPreset('relaxed');
|
|
49
|
+
expect(config.ironLaws).toBeDefined();
|
|
50
|
+
expect(config.ironLaws.no_self_approval).toBeDefined();
|
|
51
|
+
expect(Object.keys(config.tips).length).toBe(0);
|
|
52
|
+
expect(config.disabled.length).toBeGreaterThan(0);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('applyPreset with PresetConfig object', () => {
|
|
57
|
+
it('filters iron laws when ids are provided', () => {
|
|
58
|
+
const config = applyPreset({
|
|
59
|
+
name: 'custom',
|
|
60
|
+
ironLaws: ['no_self_approval', 'no_completion_without_verification'],
|
|
61
|
+
guidelines: null,
|
|
62
|
+
tips: null,
|
|
63
|
+
});
|
|
64
|
+
expect(Object.keys(config.ironLaws)).toHaveLength(2);
|
|
65
|
+
expect(config.ironLaws.no_self_approval).toBeDefined();
|
|
66
|
+
expect(config.ironLaws.no_fix_without_root_cause).toBeUndefined();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('includes all guidelines when null', () => {
|
|
70
|
+
const config = applyPreset({
|
|
71
|
+
name: 'custom',
|
|
72
|
+
ironLaws: null,
|
|
73
|
+
guidelines: null,
|
|
74
|
+
tips: [],
|
|
75
|
+
});
|
|
76
|
+
expect(Object.keys(config.guidelines).length).toBeGreaterThan(0);
|
|
77
|
+
expect(Object.keys(config.tips).length).toBe(0);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('creates disabled list for omitted constraints', () => {
|
|
81
|
+
const config = applyPreset({
|
|
82
|
+
name: 'custom',
|
|
83
|
+
ironLaws: [],
|
|
84
|
+
guidelines: [],
|
|
85
|
+
tips: [],
|
|
86
|
+
});
|
|
87
|
+
expect(config.disabled.length).toBeGreaterThan(0);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe('getIronLawPreset (deprecated)', () => {
|
|
92
|
+
it('returns iron law config for strict preset', () => {
|
|
93
|
+
const config = getIronLawPreset('strict');
|
|
94
|
+
expect(config.preset).toBe('strict');
|
|
95
|
+
expect(config.enabled).toBe(true);
|
|
96
|
+
expect(config.ironLaws.length).toBeGreaterThan(5);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('returns iron law config for relaxed preset', () => {
|
|
100
|
+
const config = getIronLawPreset('relaxed');
|
|
101
|
+
expect(config.preset).toBe('relaxed');
|
|
102
|
+
expect(config.ironLaws).toHaveLength(3);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 预设模块入口
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
STRICT_PRESET,
|
|
7
|
+
STANDARD_PRESET,
|
|
8
|
+
RELAXED_PRESET,
|
|
9
|
+
getPreset,
|
|
10
|
+
applyPreset,
|
|
11
|
+
// 向后兼容
|
|
12
|
+
STANDARD_IRON_LAWS_CONFIG,
|
|
13
|
+
getIronLawPreset,
|
|
14
|
+
} from './standard';
|
|
15
|
+
|
|
16
|
+
export type { PresetConfig } from './standard';
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 约束预设
|
|
3
|
+
*
|
|
4
|
+
* 预设定义哪些约束被启用
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { ConstraintLevel, Constraint } from '../types/constraint';
|
|
8
|
+
import type { MergedConstraintsConfig } from '../types/project-config';
|
|
9
|
+
import { IRON_LAWS, GUIDELINES, TIPS } from '../core/constraints/definitions';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 预设配置
|
|
13
|
+
*/
|
|
14
|
+
export interface PresetConfig {
|
|
15
|
+
/** 预设名称 */
|
|
16
|
+
name: string;
|
|
17
|
+
|
|
18
|
+
/** 启用的铁律 ID 列表(null 表示全部启用) */
|
|
19
|
+
ironLaws: string[] | null;
|
|
20
|
+
|
|
21
|
+
/** 启用的指导原则 ID 列表(null 表示全部启用) */
|
|
22
|
+
guidelines: string[] | null;
|
|
23
|
+
|
|
24
|
+
/** 启用的提示 ID 列表(null 表示全部启用) */
|
|
25
|
+
tips: string[] | null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 应用预设,生成 MergedConstraintsConfig(S12)
|
|
30
|
+
*
|
|
31
|
+
* 将 PresetConfig 转换为 ConstraintChecker.checkConstraints() 所需的 customConfig。
|
|
32
|
+
* 支持 per-request 预设切换,不再局限于 CLI。
|
|
33
|
+
*
|
|
34
|
+
* @param preset 预设名称('strict' | 'standard' | 'relaxed')或 PresetConfig 对象
|
|
35
|
+
* @returns 可直接传入 checkConstraints() 的 merged config
|
|
36
|
+
*
|
|
37
|
+
* 用法:
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const config = applyPreset('relaxed');
|
|
40
|
+
* await checker.checkConstraints(ctx, config);
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export function applyPreset(
|
|
44
|
+
preset: string | PresetConfig
|
|
45
|
+
): MergedConstraintsConfig {
|
|
46
|
+
const cfg = typeof preset === 'string' ? getPreset(preset) : preset;
|
|
47
|
+
|
|
48
|
+
const filterByIds = (
|
|
49
|
+
source: Record<string, Constraint>,
|
|
50
|
+
ids: string[] | null,
|
|
51
|
+
): Record<string, Constraint> => {
|
|
52
|
+
if (ids === null) return { ...source };
|
|
53
|
+
const filtered: Record<string, Constraint> = {};
|
|
54
|
+
for (const id of ids) {
|
|
55
|
+
if (source[id]) filtered[id] = source[id];
|
|
56
|
+
}
|
|
57
|
+
return filtered;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const disabled: string[] = [];
|
|
61
|
+
if (cfg.ironLaws !== null) {
|
|
62
|
+
for (const id of Object.keys(IRON_LAWS)) {
|
|
63
|
+
if (!cfg.ironLaws.includes(id)) disabled.push(id);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (cfg.guidelines !== null) {
|
|
67
|
+
for (const id of Object.keys(GUIDELINES)) {
|
|
68
|
+
if (!cfg.guidelines.includes(id)) disabled.push(id);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
ironLaws: filterByIds(IRON_LAWS, cfg.ironLaws),
|
|
74
|
+
guidelines: filterByIds(GUIDELINES, cfg.guidelines),
|
|
75
|
+
tips: filterByIds(TIPS, cfg.tips),
|
|
76
|
+
disabled,
|
|
77
|
+
custom: [],
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 严格预设
|
|
83
|
+
*
|
|
84
|
+
* 所有约束全部启用
|
|
85
|
+
*/
|
|
86
|
+
export const STRICT_PRESET: PresetConfig = {
|
|
87
|
+
name: 'strict',
|
|
88
|
+
ironLaws: null, // 全部启用
|
|
89
|
+
guidelines: null, // 全部启用
|
|
90
|
+
tips: null, // 全部启用
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 标准预设
|
|
95
|
+
*
|
|
96
|
+
* 铁律全部启用,指导原则和提示选择性启用
|
|
97
|
+
*/
|
|
98
|
+
export const STANDARD_PRESET: PresetConfig = {
|
|
99
|
+
name: 'standard',
|
|
100
|
+
ironLaws: null, // 全部启用
|
|
101
|
+
guidelines: null, // 全部启用
|
|
102
|
+
tips: null, // 全部启用
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 宽松预设
|
|
107
|
+
*
|
|
108
|
+
* 仅启用核心铁律,禁用提示
|
|
109
|
+
*/
|
|
110
|
+
export const RELAXED_PRESET: PresetConfig = {
|
|
111
|
+
name: 'relaxed',
|
|
112
|
+
ironLaws: [
|
|
113
|
+
'no_bypass_checkpoint',
|
|
114
|
+
'no_self_approval',
|
|
115
|
+
'no_completion_without_verification',
|
|
116
|
+
],
|
|
117
|
+
guidelines: [
|
|
118
|
+
'no_fix_without_root_cause',
|
|
119
|
+
'no_code_without_test',
|
|
120
|
+
],
|
|
121
|
+
tips: [], // 禁用提示
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 获取预设
|
|
126
|
+
*/
|
|
127
|
+
export function getPreset(name: string): PresetConfig {
|
|
128
|
+
switch (name) {
|
|
129
|
+
case 'strict':
|
|
130
|
+
return STRICT_PRESET;
|
|
131
|
+
case 'standard':
|
|
132
|
+
return STANDARD_PRESET;
|
|
133
|
+
case 'relaxed':
|
|
134
|
+
return RELAXED_PRESET;
|
|
135
|
+
default:
|
|
136
|
+
return STANDARD_PRESET;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// ========================================
|
|
141
|
+
// 向后兼容
|
|
142
|
+
// ========================================
|
|
143
|
+
|
|
144
|
+
import type { IronLawConfig } from '../types/iron-law';
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* @deprecated 使用 PresetConfig 代替
|
|
148
|
+
*/
|
|
149
|
+
export { STANDARD_PRESET as STANDARD_IRON_LAWS_CONFIG };
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @deprecated 使用 getPreset 代替
|
|
153
|
+
*/
|
|
154
|
+
export function getIronLawPreset(preset: string): IronLawConfig {
|
|
155
|
+
const config = getPreset(preset);
|
|
156
|
+
return {
|
|
157
|
+
preset: preset as 'strict' | 'standard' | 'relaxed',
|
|
158
|
+
enabled: true,
|
|
159
|
+
ironLaws: config.ironLaws
|
|
160
|
+
? Object.values(IRON_LAWS).filter(c => config.ironLaws!.includes(c.id))
|
|
161
|
+
: Object.values(IRON_LAWS),
|
|
162
|
+
};
|
|
163
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# safety/
|
|
2
|
+
|
|
3
|
+
## 职责
|
|
4
|
+
安全护栏:输入/输出/Tool Guardrail + 沙箱执行环境(L1-L4)。
|
|
5
|
+
|
|
6
|
+
## 核心导出
|
|
7
|
+
- `Sandbox` — 沙箱执行环境: 级别 L1-L4 / 资源限制 / 隔离策略
|
|
8
|
+
- `InputGuardrail` — 输入安全检查: 注入检测 / 敏感信息 / 格式校验
|
|
9
|
+
- `OutputGuardrail` — 输出安全检查: 泄露检测 / 有害内容 / 格式合规
|
|
10
|
+
- `ToolGuardrail` — 工具调用安全: 权限验证 / 参数校验 / 速率限制
|
|
11
|
+
|
|
12
|
+
## 依赖关系
|
|
13
|
+
- 依赖 `src/types/` 安全相关类型
|
|
14
|
+
- 被 Agent 执行管线消费
|
|
15
|
+
|
|
16
|
+
## 约定
|
|
17
|
+
- Guardrail 检查在操作前/后执行
|
|
18
|
+
- 沙箱级别 L1(最宽松) → L4(最严格)
|
|
19
|
+
- 安全策略由配置文件控制
|
|
20
|
+
|
|
21
|
+
## 注意事项
|
|
22
|
+
- Phase 3 实现的核心安全模块
|
|
23
|
+
- Guardrail 检查失败阻断执行(非警告)
|