@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,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 输出护栏
|
|
3
|
+
*
|
|
4
|
+
* 在最终输出前检查:
|
|
5
|
+
* - 敏感信息审查(API keys, passwords, tokens)
|
|
6
|
+
* - 代码质量检查
|
|
7
|
+
* - 知识引用完整性
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { OutputSafetyCheckResult, OutputViolation, OutputGuardrailConfig } from './types';
|
|
11
|
+
|
|
12
|
+
const DEFAULT_SENSITIVE_PATTERNS: RegExp[] = [
|
|
13
|
+
// API keys
|
|
14
|
+
/(?:api[_-]?key|apikey)\s*[:=]\s*['"]?([a-zA-Z0-9_\-]{20,})['"]?/gi,
|
|
15
|
+
// AWS
|
|
16
|
+
/(?:AKIA|ASIA)[A-Z0-9]{16}/g,
|
|
17
|
+
// Generic secrets
|
|
18
|
+
/(?:secret|password|passwd|token|auth)\s*[:=]\s*['"]?([^\s'"]{8,})['"]?/gi,
|
|
19
|
+
// Private keys
|
|
20
|
+
/-----BEGIN\s+(RSA\s+)?PRIVATE\s+KEY-----/g,
|
|
21
|
+
// GitHub tokens
|
|
22
|
+
/gh[ps]_[A-Za-z0-9_]{36,}/g,
|
|
23
|
+
// Bearer tokens
|
|
24
|
+
/Bearer\s+[A-Za-z0-9_\-\.]{20,}/g,
|
|
25
|
+
// Connection strings
|
|
26
|
+
/(?:mongodb|postgres|mysql|redis):\/\/[^\s'"]+/gi,
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
const DEFAULT_MIN_QUALITY_SCORE = 0.6;
|
|
30
|
+
|
|
31
|
+
export class OutputGuardrail {
|
|
32
|
+
private sensitivePatterns: RegExp[];
|
|
33
|
+
private minQualityScore: number;
|
|
34
|
+
private checkKnowledgeRefs: boolean;
|
|
35
|
+
|
|
36
|
+
constructor(config?: OutputGuardrailConfig) {
|
|
37
|
+
this.sensitivePatterns = config?.sensitivePatterns ?? DEFAULT_SENSITIVE_PATTERNS;
|
|
38
|
+
this.minQualityScore = config?.minQualityScore ?? DEFAULT_MIN_QUALITY_SCORE;
|
|
39
|
+
this.checkKnowledgeRefs = config?.checkKnowledgeRefs ?? false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 检查输出安全性
|
|
44
|
+
*/
|
|
45
|
+
check(content: string, knowledgeRefIds?: string[]): OutputSafetyCheckResult {
|
|
46
|
+
const violations: OutputViolation[] = [];
|
|
47
|
+
|
|
48
|
+
// 敏感信息检测
|
|
49
|
+
violations.push(...this.checkSensitiveInfo(content));
|
|
50
|
+
|
|
51
|
+
// 代码质量检查
|
|
52
|
+
violations.push(...this.checkQuality(content));
|
|
53
|
+
|
|
54
|
+
// 知识引用完整性
|
|
55
|
+
if (this.checkKnowledgeRefs && knowledgeRefIds) {
|
|
56
|
+
violations.push(...this.checkKnowledgeRefs_(
|
|
57
|
+
content,
|
|
58
|
+
knowledgeRefIds,
|
|
59
|
+
));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const sanitized = violations.length > 0
|
|
63
|
+
? this.sanitize(content, violations)
|
|
64
|
+
: undefined;
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
safe: violations.length === 0,
|
|
68
|
+
violations,
|
|
69
|
+
sanitizedContent: sanitized,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 检测敏感信息
|
|
75
|
+
*/
|
|
76
|
+
private checkSensitiveInfo(content: string): OutputViolation[] {
|
|
77
|
+
const violations: OutputViolation[] = [];
|
|
78
|
+
|
|
79
|
+
for (const pattern of this.sensitivePatterns) {
|
|
80
|
+
// Reset lastIndex for global patterns
|
|
81
|
+
pattern.lastIndex = 0;
|
|
82
|
+
let match: RegExpExecArray | null;
|
|
83
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
84
|
+
const line = this.getLineNumber(content, match.index);
|
|
85
|
+
violations.push({
|
|
86
|
+
type: 'sensitive_info',
|
|
87
|
+
severity: 'high',
|
|
88
|
+
description: `检测到敏感信息: ${match[0].slice(0, 30)}...`,
|
|
89
|
+
location: { line, column: match.index - content.lastIndexOf('\n', match.index) - 1 },
|
|
90
|
+
matchedPattern: match[0],
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return violations;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 代码质量检查(简单启发式)
|
|
100
|
+
*/
|
|
101
|
+
private checkQuality(content: string): OutputViolation[] {
|
|
102
|
+
const violations: OutputViolation[] = [];
|
|
103
|
+
|
|
104
|
+
// 检查 TODO/FIXME/HACK
|
|
105
|
+
const todoPattern = /\b(TODO|FIXME|HACK|XXX)\b/gi;
|
|
106
|
+
let match: RegExpExecArray | null;
|
|
107
|
+
while ((match = todoPattern.exec(content)) !== null) {
|
|
108
|
+
const line = this.getLineNumber(content, match.index);
|
|
109
|
+
violations.push({
|
|
110
|
+
type: 'quality',
|
|
111
|
+
severity: 'low',
|
|
112
|
+
description: `代码包含 ${match[1]} 标记`,
|
|
113
|
+
location: { line, column: match.index - content.lastIndexOf('\n', match.index) - 1 },
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 检查 console.log 残留
|
|
118
|
+
const consolePattern = /console\.(log|debug|info)\(/g;
|
|
119
|
+
while ((match = consolePattern.exec(content)) !== null) {
|
|
120
|
+
const line = this.getLineNumber(content, match.index);
|
|
121
|
+
violations.push({
|
|
122
|
+
type: 'quality',
|
|
123
|
+
severity: 'low',
|
|
124
|
+
description: `代码包含 ${match[0].slice(0, -1)} 调用`,
|
|
125
|
+
location: { line, column: match.index - content.lastIndexOf('\n', match.index) - 1 },
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return violations;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* 检查知识引用完整性
|
|
134
|
+
*/
|
|
135
|
+
private checkKnowledgeRefs_(content: string, referencedIds: string[]): OutputViolation[] {
|
|
136
|
+
const violations: OutputViolation[] = [];
|
|
137
|
+
|
|
138
|
+
for (const id of referencedIds) {
|
|
139
|
+
if (!content.includes(id)) {
|
|
140
|
+
violations.push({
|
|
141
|
+
type: 'knowledge_missing',
|
|
142
|
+
severity: 'medium',
|
|
143
|
+
description: `引用的知识条目 ${id} 未出现在输出中`,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return violations;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* 清理敏感信息
|
|
153
|
+
*/
|
|
154
|
+
private sanitize(content: string, violations: OutputViolation[]): string {
|
|
155
|
+
let sanitized = content;
|
|
156
|
+
|
|
157
|
+
for (const violation of violations) {
|
|
158
|
+
if (violation.type === 'sensitive_info' && violation.matchedPattern) {
|
|
159
|
+
// Escape special regex characters in the matched string
|
|
160
|
+
const escaped = violation.matchedPattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
161
|
+
sanitized = sanitized.replace(new RegExp(escaped, 'g'), '[REDACTED]');
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return sanitized;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* 获取行号
|
|
170
|
+
*/
|
|
171
|
+
private getLineNumber(content: string, index: number): number {
|
|
172
|
+
return content.slice(0, index).split('\n').length;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sandbox 安全级别管理
|
|
3
|
+
*
|
|
4
|
+
* 四级权限模型:
|
|
5
|
+
* Level 1: 只读文件系统,无网络,无 shell
|
|
6
|
+
* Level 2: 可写限定目录(.harness/),无网络
|
|
7
|
+
* Level 3: 可写项目目录,受限网络(白名单)
|
|
8
|
+
* Level 4: 完全权限,需用户确认
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { SandboxLevel, SandboxConfig, SandboxCheckResult } from './types';
|
|
12
|
+
|
|
13
|
+
const LEVEL_DESCRIPTIONS: Record<SandboxLevel, string> = {
|
|
14
|
+
1: '只读文件系统,无网络,无 shell',
|
|
15
|
+
2: '可写限定目录(.harness/),无网络',
|
|
16
|
+
3: '可写项目目录,受限网络(白名单)',
|
|
17
|
+
4: '完全权限,需用户确认',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const DEFAULT_WRITABLE_DIRS = ['.harness/'];
|
|
21
|
+
|
|
22
|
+
export class Sandbox {
|
|
23
|
+
private config: SandboxConfig;
|
|
24
|
+
|
|
25
|
+
constructor(config?: Partial<SandboxConfig>) {
|
|
26
|
+
this.config = {
|
|
27
|
+
level: config?.level ?? 3,
|
|
28
|
+
writableDirs: config?.writableDirs ?? DEFAULT_WRITABLE_DIRS,
|
|
29
|
+
allowedHosts: config?.allowedHosts ?? [],
|
|
30
|
+
requiresConfirmation: config?.requiresConfirmation ?? (config?.level === 4),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
getLevel(): SandboxLevel {
|
|
35
|
+
return this.config.level;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
getDescription(): string {
|
|
39
|
+
return LEVEL_DESCRIPTIONS[this.config.level];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 检查当前级别是否满足操作所需级别
|
|
44
|
+
*/
|
|
45
|
+
check(requiredLevel: SandboxLevel): SandboxCheckResult {
|
|
46
|
+
const allowed = this.config.level >= requiredLevel;
|
|
47
|
+
return {
|
|
48
|
+
allowed,
|
|
49
|
+
reason: allowed ? undefined : `当前 Level ${this.config.level} 不满足操作所需的 Level ${requiredLevel}`,
|
|
50
|
+
currentLevel: this.config.level,
|
|
51
|
+
requiredLevel,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 检查文件写入是否允许
|
|
57
|
+
*/
|
|
58
|
+
checkFileWrite(filePath: string): SandboxCheckResult {
|
|
59
|
+
if (this.config.level >= 3) {
|
|
60
|
+
return { allowed: true, currentLevel: this.config.level, requiredLevel: 3 };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (this.config.level >= 2) {
|
|
64
|
+
const inWritableDir = this.config.writableDirs?.some(dir => filePath.startsWith(dir));
|
|
65
|
+
if (inWritableDir) {
|
|
66
|
+
return { allowed: true, currentLevel: this.config.level, requiredLevel: 2 };
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
allowed: false,
|
|
70
|
+
reason: `Level 2 只允许写入 ${this.config.writableDirs?.join(', ')}`,
|
|
71
|
+
currentLevel: this.config.level,
|
|
72
|
+
requiredLevel: 3,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
allowed: false,
|
|
78
|
+
reason: 'Level 1 禁止写入任何文件',
|
|
79
|
+
currentLevel: this.config.level,
|
|
80
|
+
requiredLevel: 2,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 检查网络访问是否允许
|
|
86
|
+
*/
|
|
87
|
+
checkNetworkAccess(host: string): SandboxCheckResult {
|
|
88
|
+
if (this.config.level >= 4) {
|
|
89
|
+
return { allowed: true, currentLevel: this.config.level, requiredLevel: 4 };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (this.config.level >= 3) {
|
|
93
|
+
const allowed = this.config.allowedHosts?.includes(host) ?? false;
|
|
94
|
+
return {
|
|
95
|
+
allowed,
|
|
96
|
+
reason: allowed ? undefined : `Host ${host} 不在白名单中`,
|
|
97
|
+
currentLevel: this.config.level,
|
|
98
|
+
requiredLevel: 3,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
allowed: false,
|
|
104
|
+
reason: `Level ${this.config.level} 禁止网络访问`,
|
|
105
|
+
currentLevel: this.config.level,
|
|
106
|
+
requiredLevel: 3,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* 检查 shell 命令是否允许
|
|
112
|
+
*/
|
|
113
|
+
checkShellAccess(): SandboxCheckResult {
|
|
114
|
+
if (this.config.level >= 3) {
|
|
115
|
+
return { allowed: true, currentLevel: this.config.level, requiredLevel: 3 };
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
allowed: false,
|
|
119
|
+
reason: `Level ${this.config.level} 禁止 shell 访问`,
|
|
120
|
+
currentLevel: this.config.level,
|
|
121
|
+
requiredLevel: 3,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* 检查是否需要用户确认
|
|
127
|
+
*/
|
|
128
|
+
needsConfirmation(): boolean {
|
|
129
|
+
return this.config.requiresConfirmation ?? false;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* 升级到指定级别
|
|
134
|
+
*/
|
|
135
|
+
upgradeTo(level: SandboxLevel): void {
|
|
136
|
+
this.config.level = level;
|
|
137
|
+
if (level === 4) {
|
|
138
|
+
this.config.requiresConfirmation = true;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 获取当前配置
|
|
144
|
+
*/
|
|
145
|
+
getConfig(): SandboxConfig {
|
|
146
|
+
return { ...this.config };
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工具护栏
|
|
3
|
+
*
|
|
4
|
+
* 每次工具调用前检查:
|
|
5
|
+
* - 命令黑名单
|
|
6
|
+
* - Sandbox 级别检查
|
|
7
|
+
* - 速率限制
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type {
|
|
11
|
+
ToolCheckResult,
|
|
12
|
+
ToolViolation,
|
|
13
|
+
ToolGuardrailConfig,
|
|
14
|
+
RateLimitState,
|
|
15
|
+
SandboxLevel,
|
|
16
|
+
} from './types';
|
|
17
|
+
import { Sandbox } from './sandbox';
|
|
18
|
+
|
|
19
|
+
const DEFAULT_BLACKLISTED_COMMANDS = [
|
|
20
|
+
'rm -rf /',
|
|
21
|
+
'rm -rf /*',
|
|
22
|
+
'mkfs',
|
|
23
|
+
'dd if=',
|
|
24
|
+
':(){:|:&};:', // fork bomb
|
|
25
|
+
'chmod -R 777 /',
|
|
26
|
+
'| sh',
|
|
27
|
+
'| bash',
|
|
28
|
+
'eval(',
|
|
29
|
+
'exec(',
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
const DEFAULT_RATE_LIMIT = 60; // per minute
|
|
33
|
+
|
|
34
|
+
export class ToolGuardrail {
|
|
35
|
+
private blacklistedCommands: string[];
|
|
36
|
+
private rateLimit: number;
|
|
37
|
+
private toolSandboxLevels: Record<string, SandboxLevel>;
|
|
38
|
+
private rateLimitState: Map<string, RateLimitState>;
|
|
39
|
+
private sandbox: Sandbox;
|
|
40
|
+
|
|
41
|
+
constructor(sandbox: Sandbox, config?: ToolGuardrailConfig) {
|
|
42
|
+
this.sandbox = sandbox;
|
|
43
|
+
this.blacklistedCommands = config?.blacklistedCommands ?? DEFAULT_BLACKLISTED_COMMANDS;
|
|
44
|
+
this.rateLimit = config?.rateLimit ?? DEFAULT_RATE_LIMIT;
|
|
45
|
+
this.toolSandboxLevels = config?.toolSandboxLevels ?? {};
|
|
46
|
+
this.rateLimitState = new Map();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 检查工具调用是否允许
|
|
51
|
+
*/
|
|
52
|
+
check(toolName: string, command?: string): ToolCheckResult {
|
|
53
|
+
const violations: ToolViolation[] = [];
|
|
54
|
+
|
|
55
|
+
// 命令黑名单检查
|
|
56
|
+
if (command) {
|
|
57
|
+
violations.push(...this.checkBlacklist(toolName, command));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Sandbox 级别检查
|
|
61
|
+
violations.push(...this.checkSandboxLevel(toolName));
|
|
62
|
+
|
|
63
|
+
// 速率限制检查
|
|
64
|
+
violations.push(...this.checkRateLimit(toolName));
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
allowed: violations.length === 0,
|
|
68
|
+
violations,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 检查命令黑名单
|
|
74
|
+
*/
|
|
75
|
+
private checkBlacklist(toolName: string, command: string): ToolViolation[] {
|
|
76
|
+
const violations: ToolViolation[] = [];
|
|
77
|
+
const lower = command.toLowerCase();
|
|
78
|
+
|
|
79
|
+
for (const blocked of this.blacklistedCommands) {
|
|
80
|
+
if (lower.includes(blocked.toLowerCase())) {
|
|
81
|
+
violations.push({
|
|
82
|
+
type: 'blacklist',
|
|
83
|
+
severity: 'high',
|
|
84
|
+
description: `命令包含被阻止的模式: ${blocked}`,
|
|
85
|
+
toolName,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return violations;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 检查 sandbox 级别
|
|
95
|
+
*/
|
|
96
|
+
private checkSandboxLevel(toolName: string): ToolViolation[] {
|
|
97
|
+
const violations: ToolViolation[] = [];
|
|
98
|
+
const requiredLevel = this.toolSandboxLevels[toolName];
|
|
99
|
+
|
|
100
|
+
if (requiredLevel !== undefined) {
|
|
101
|
+
const result = this.sandbox.check(requiredLevel);
|
|
102
|
+
if (!result.allowed) {
|
|
103
|
+
violations.push({
|
|
104
|
+
type: 'sandbox',
|
|
105
|
+
severity: 'high',
|
|
106
|
+
description: result.reason ?? `工具 ${toolName} 需要 Level ${requiredLevel}`,
|
|
107
|
+
toolName,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return violations;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* 检查速率限制
|
|
117
|
+
*/
|
|
118
|
+
private checkRateLimit(toolName: string): ToolViolation[] {
|
|
119
|
+
const violations: ToolViolation[] = [];
|
|
120
|
+
const now = Date.now();
|
|
121
|
+
const state = this.rateLimitState.get(toolName);
|
|
122
|
+
|
|
123
|
+
if (!state) {
|
|
124
|
+
this.rateLimitState.set(toolName, { count: 1, windowStart: now });
|
|
125
|
+
return violations;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// 重置窗口(1 分钟)
|
|
129
|
+
if (now - state.windowStart > 60000) {
|
|
130
|
+
state.count = 1;
|
|
131
|
+
state.windowStart = now;
|
|
132
|
+
return violations;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
state.count++;
|
|
136
|
+
|
|
137
|
+
if (state.count > this.rateLimit) {
|
|
138
|
+
violations.push({
|
|
139
|
+
type: 'rate_limit',
|
|
140
|
+
severity: 'medium',
|
|
141
|
+
description: `工具 ${toolName} 超过速率限制 (${this.rateLimit}/min)`,
|
|
142
|
+
toolName,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return violations;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* 添加黑名单命令
|
|
151
|
+
*/
|
|
152
|
+
addBlacklistedCommand(command: string): void {
|
|
153
|
+
this.blacklistedCommands.push(command);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* 设置工具 sandbox 级别要求
|
|
158
|
+
*/
|
|
159
|
+
setToolSandboxLevel(toolName: string, level: SandboxLevel): void {
|
|
160
|
+
this.toolSandboxLevels[toolName] = level;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* 重置速率限制状态
|
|
165
|
+
*/
|
|
166
|
+
resetRateLimits(): void {
|
|
167
|
+
this.rateLimitState.clear();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* 获取 sandbox 实例
|
|
172
|
+
*/
|
|
173
|
+
getSandbox(): Sandbox {
|
|
174
|
+
return this.sandbox;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safety Guardrails 类型定义
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// ── Sandbox ──────────────────────────────────────────────
|
|
6
|
+
|
|
7
|
+
/** Sandbox 安全级别 */
|
|
8
|
+
export type SandboxLevel = 1 | 2 | 3 | 4;
|
|
9
|
+
|
|
10
|
+
/** Sandbox 配置 */
|
|
11
|
+
export interface SandboxConfig {
|
|
12
|
+
level: SandboxLevel;
|
|
13
|
+
/** 允许写入的目录(Level 2+) */
|
|
14
|
+
writableDirs?: string[];
|
|
15
|
+
/** 允许的网络白名单(Level 3) */
|
|
16
|
+
allowedHosts?: string[];
|
|
17
|
+
/** 需要用户确认的操作(Level 4) */
|
|
18
|
+
requiresConfirmation?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Sandbox 权限检查结果 */
|
|
22
|
+
export interface SandboxCheckResult {
|
|
23
|
+
allowed: boolean;
|
|
24
|
+
reason?: string;
|
|
25
|
+
currentLevel: SandboxLevel;
|
|
26
|
+
requiredLevel: SandboxLevel;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// ── Input Guardrail ──────────────────────────────────────
|
|
30
|
+
|
|
31
|
+
/** 输入检查结果 */
|
|
32
|
+
export interface InputCheckResult {
|
|
33
|
+
safe: boolean;
|
|
34
|
+
violations: InputViolation[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** 输入违规 */
|
|
38
|
+
export interface InputViolation {
|
|
39
|
+
type: 'injection' | 'intent' | 'permission';
|
|
40
|
+
severity: 'low' | 'medium' | 'high';
|
|
41
|
+
description: string;
|
|
42
|
+
matchedPattern?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** 输入护栏配置 */
|
|
46
|
+
export interface InputGuardrailConfig {
|
|
47
|
+
/** 注入检测模式 */
|
|
48
|
+
injectionPatterns?: RegExp[];
|
|
49
|
+
/** 禁止的意图关键词 */
|
|
50
|
+
blockedIntents?: string[];
|
|
51
|
+
/** 最大输入长度 */
|
|
52
|
+
maxInputLength?: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ── Output Guardrail ─────────────────────────────────────
|
|
56
|
+
|
|
57
|
+
/** 输出检查结果 */
|
|
58
|
+
export interface OutputSafetyCheckResult {
|
|
59
|
+
safe: boolean;
|
|
60
|
+
violations: OutputViolation[];
|
|
61
|
+
sanitizedContent?: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** 输出违规 */
|
|
65
|
+
export interface OutputViolation {
|
|
66
|
+
type: 'sensitive_info' | 'quality' | 'knowledge_missing';
|
|
67
|
+
severity: 'low' | 'medium' | 'high';
|
|
68
|
+
description: string;
|
|
69
|
+
location?: { line: number; column: number };
|
|
70
|
+
matchedPattern?: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** 输出护栏配置 */
|
|
74
|
+
export interface OutputGuardrailConfig {
|
|
75
|
+
/** 敏感信息模式(API keys, passwords, etc.) */
|
|
76
|
+
sensitivePatterns?: RegExp[];
|
|
77
|
+
/** 代码质量最低分数 */
|
|
78
|
+
minQualityScore?: number;
|
|
79
|
+
/** 是否检查知识引用完整性 */
|
|
80
|
+
checkKnowledgeRefs?: boolean;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// ── Tool Guardrail ───────────────────────────────────────
|
|
84
|
+
|
|
85
|
+
/** 工具检查结果 */
|
|
86
|
+
export interface ToolCheckResult {
|
|
87
|
+
allowed: boolean;
|
|
88
|
+
violations: ToolViolation[];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** 工具违规 */
|
|
92
|
+
export interface ToolViolation {
|
|
93
|
+
type: 'blacklist' | 'sandbox' | 'rate_limit';
|
|
94
|
+
severity: 'low' | 'medium' | 'high';
|
|
95
|
+
description: string;
|
|
96
|
+
toolName?: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** 工具护栏配置 */
|
|
100
|
+
export interface ToolGuardrailConfig {
|
|
101
|
+
/** 命令黑名单 */
|
|
102
|
+
blacklistedCommands?: string[];
|
|
103
|
+
/** 每分钟最大调用次数 */
|
|
104
|
+
rateLimit?: number;
|
|
105
|
+
/** 各工具的 sandbox 级别要求 */
|
|
106
|
+
toolSandboxLevels?: Record<string, SandboxLevel>;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** 速率限制状态 */
|
|
110
|
+
export interface RateLimitState {
|
|
111
|
+
count: number;
|
|
112
|
+
windowStart: number;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// ── Aggregate ────────────────────────────────────────────
|
|
116
|
+
|
|
117
|
+
/** 安全检查汇总 */
|
|
118
|
+
export interface SafetyCheckResult {
|
|
119
|
+
safe: boolean;
|
|
120
|
+
inputCheck: InputCheckResult;
|
|
121
|
+
outputCheck: OutputSafetyCheckResult;
|
|
122
|
+
toolCheck: ToolCheckResult;
|
|
123
|
+
timestamp: string;
|
|
124
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# spec/
|
|
2
|
+
|
|
3
|
+
## 职责
|
|
4
|
+
代码注释规范检查:验证代码中的 @spec 注释是否符合规范。
|
|
5
|
+
|
|
6
|
+
## 核心导出
|
|
7
|
+
- `annotation-checker.ts` — AnnotationChecker: 检查 @spec 注释规范(有效/无效/警告)
|
|
8
|
+
|
|
9
|
+
## 依赖关系
|
|
10
|
+
- 依赖 `fs` / `path` 文件系统操作
|
|
11
|
+
- 被 `src/cli/commands/spec.ts` CLI 命令消费
|
|
12
|
+
|
|
13
|
+
## 约定
|
|
14
|
+
- Spec 注释格式由 @spec 标签定义
|
|
15
|
+
- 检查结果包含 valid: boolean + errors + warnings
|
|
16
|
+
|
|
17
|
+
## 注意事项
|
|
18
|
+
- 无 index.ts 统一导出,独立模块导入
|
|
19
|
+
- 扫描指定目录下所有 TS 文件的 @spec 注释
|