@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,265 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token 流水线
|
|
3
|
+
*
|
|
4
|
+
* 五步:收集 → 排序 → 压缩 → 预算 → 组装
|
|
5
|
+
* 每次 LLM 调用前运行
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { TokenEstimator, TokenBudget } from './token-budget';
|
|
9
|
+
import type {
|
|
10
|
+
ContextSource,
|
|
11
|
+
TokenBudgetAllocation,
|
|
12
|
+
PipelineInput,
|
|
13
|
+
PipelineOutput,
|
|
14
|
+
ContextUsageSnapshot,
|
|
15
|
+
} from './types';
|
|
16
|
+
|
|
17
|
+
interface CollectedGroup {
|
|
18
|
+
priority: number;
|
|
19
|
+
sources: ContextSource[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class TokenPipeline {
|
|
23
|
+
/**
|
|
24
|
+
* 完整流水线:收集 → 排序 → 压缩 → 预算 → 组装
|
|
25
|
+
*/
|
|
26
|
+
run(input: PipelineInput): PipelineOutput {
|
|
27
|
+
const { sources, budget } = input;
|
|
28
|
+
|
|
29
|
+
// Step 1: 收集 — 按 priority 分组
|
|
30
|
+
const collected = this.collect(sources);
|
|
31
|
+
|
|
32
|
+
// Step 2: 排序 — 按 P1→P6 排序
|
|
33
|
+
const sorted = this.sort(collected);
|
|
34
|
+
|
|
35
|
+
// Step 3: 压缩 — 对 P3-P5 应用预算裁剪
|
|
36
|
+
const { compressed, dropped } = this.compress(sorted, budget);
|
|
37
|
+
|
|
38
|
+
// Step 4: 预算 — 按分配裁剪
|
|
39
|
+
const budgeted = this.applyBudget(compressed, budget);
|
|
40
|
+
|
|
41
|
+
// Step 5: 组装 — 拼装最终 prompt
|
|
42
|
+
const prompt = this.assemble(budgeted);
|
|
43
|
+
|
|
44
|
+
// 生成快照
|
|
45
|
+
const snapshot = this.buildSnapshot(budgeted, dropped);
|
|
46
|
+
|
|
47
|
+
return { prompt, snapshot, dropped };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Step 1: 收集 — 从 sources 按 priority 分组
|
|
52
|
+
*/
|
|
53
|
+
collect(sources: ContextSource[]): CollectedGroup[] {
|
|
54
|
+
const groups = new Map<number, ContextSource[]>();
|
|
55
|
+
|
|
56
|
+
for (const source of sources) {
|
|
57
|
+
const existing = groups.get(source.priority) || [];
|
|
58
|
+
existing.push(source);
|
|
59
|
+
groups.set(source.priority, existing);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return Array.from(groups.entries())
|
|
63
|
+
.map(([priority, sources]) => ({ priority, sources }))
|
|
64
|
+
.sort((a, b) => a.priority - b.priority);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Step 2: 排序 — 按 P1→P6,组内保持原序
|
|
69
|
+
*/
|
|
70
|
+
sort(groups: CollectedGroup[]): ContextSource[] {
|
|
71
|
+
const sorted: ContextSource[] = [];
|
|
72
|
+
|
|
73
|
+
for (const group of groups) {
|
|
74
|
+
sorted.push(...group.sources);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return sorted;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Step 3: 压缩 — 对 P3-P5 应用 token 预算裁剪
|
|
82
|
+
*
|
|
83
|
+
* P1(系统提示词)和 P6(用户消息)不压缩
|
|
84
|
+
* P2(工具定义)按需懒加载,这里不处理
|
|
85
|
+
*/
|
|
86
|
+
compress(sorted: ContextSource[], budget: TokenBudgetAllocation): {
|
|
87
|
+
compressed: ContextSource[];
|
|
88
|
+
dropped: Array<{ type: string; id: string; reason: string }>;
|
|
89
|
+
} {
|
|
90
|
+
const compressed: ContextSource[] = [];
|
|
91
|
+
const dropped: Array<{ type: string; id: string; reason: string }> = [];
|
|
92
|
+
|
|
93
|
+
// 各段预算
|
|
94
|
+
const budgetMap: Record<number, number> = {
|
|
95
|
+
1: budget.systemPrompt,
|
|
96
|
+
2: budget.toolDefinitions,
|
|
97
|
+
3: budget.knowledge,
|
|
98
|
+
4: budget.notes,
|
|
99
|
+
5: budget.history,
|
|
100
|
+
6: Infinity, // 用户消息不限
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// 按优先级分组处理
|
|
104
|
+
const byPriority = new Map<number, ContextSource[]>();
|
|
105
|
+
for (const item of sorted) {
|
|
106
|
+
const existing = byPriority.get(item.priority) || [];
|
|
107
|
+
existing.push(item);
|
|
108
|
+
byPriority.set(item.priority, existing);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
for (const [priority, items] of byPriority) {
|
|
112
|
+
const sectionBudget = budgetMap[priority] || budget.history;
|
|
113
|
+
|
|
114
|
+
if (priority === 1 || priority === 6) {
|
|
115
|
+
// P1/P6 不压缩
|
|
116
|
+
compressed.push(...items);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// 按 token 预算裁剪
|
|
121
|
+
let usedTokens = 0;
|
|
122
|
+
for (const item of items) {
|
|
123
|
+
const tokens = TokenEstimator.estimateText(item.content);
|
|
124
|
+
|
|
125
|
+
if (usedTokens + tokens <= sectionBudget) {
|
|
126
|
+
compressed.push(item);
|
|
127
|
+
usedTokens += tokens;
|
|
128
|
+
} else {
|
|
129
|
+
// 尝试截断
|
|
130
|
+
const remaining = sectionBudget - usedTokens;
|
|
131
|
+
if (remaining > 50) {
|
|
132
|
+
const ratio = remaining / tokens;
|
|
133
|
+
const truncatedContent = item.content.slice(0, Math.floor(item.content.length * ratio));
|
|
134
|
+
compressed.push({ ...item, content: truncatedContent });
|
|
135
|
+
dropped.push({
|
|
136
|
+
type: item.type,
|
|
137
|
+
id: item.id,
|
|
138
|
+
reason: `截断: ${tokens} → ${Math.floor(tokens * ratio)} tokens`,
|
|
139
|
+
});
|
|
140
|
+
} else {
|
|
141
|
+
dropped.push({
|
|
142
|
+
type: item.type,
|
|
143
|
+
id: item.id,
|
|
144
|
+
reason: `超出预算: 需要 ${tokens} tokens,剩余 ${remaining}`,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
usedTokens += tokens; // 仍然计入已用
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return { compressed, dropped };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Step 4: 预算 — 按 TokenBudgetAllocation 分配各段
|
|
157
|
+
*/
|
|
158
|
+
applyBudget(compressed: ContextSource[], budget: TokenBudgetAllocation): ContextSource[] {
|
|
159
|
+
const tokenBudget = new TokenBudget(budget.total);
|
|
160
|
+
const result: ContextSource[] = [];
|
|
161
|
+
|
|
162
|
+
for (const item of compressed) {
|
|
163
|
+
const tokens = TokenEstimator.estimateText(item.content);
|
|
164
|
+
|
|
165
|
+
if (tokenBudget.canAfford(tokens)) {
|
|
166
|
+
tokenBudget.consume(tokens);
|
|
167
|
+
result.push(item);
|
|
168
|
+
} else if (item.priority === 1 || item.priority === 6) {
|
|
169
|
+
// P1/P6 强制保留
|
|
170
|
+
tokenBudget.forceConsume(tokens);
|
|
171
|
+
result.push(item);
|
|
172
|
+
}
|
|
173
|
+
// 其他优先级的超预算项被丢弃
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Step 5: 组装 — 拼装最终 prompt
|
|
181
|
+
*
|
|
182
|
+
* P1 开头 + P6 结尾,中间 P2-P5
|
|
183
|
+
*/
|
|
184
|
+
assemble(budgeted: ContextSource[]): string {
|
|
185
|
+
const sections: Record<number, string[]> = {
|
|
186
|
+
1: [], 2: [], 3: [], 4: [], 5: [], 6: [],
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
for (const item of budgeted) {
|
|
190
|
+
sections[item.priority] = sections[item.priority] || [];
|
|
191
|
+
sections[item.priority].push(item.content);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const parts: string[] = [];
|
|
195
|
+
|
|
196
|
+
// P1: 系统提示词(开头)
|
|
197
|
+
if (sections[1].length > 0) {
|
|
198
|
+
parts.push(sections[1].join('\n'));
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// P2-P5: 中间部分
|
|
202
|
+
for (const priority of [2, 3, 4, 5]) {
|
|
203
|
+
if (sections[priority].length > 0) {
|
|
204
|
+
parts.push(sections[priority].join('\n'));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// P6: 用户消息(结尾)
|
|
209
|
+
if (sections[6].length > 0) {
|
|
210
|
+
parts.push(sections[6].join('\n'));
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return parts.join('\n\n');
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* 构建上下文使用快照
|
|
218
|
+
*/
|
|
219
|
+
private buildSnapshot(budgeted: ContextSource[], dropped: Array<{ type: string; id: string; reason: string }>): ContextUsageSnapshot {
|
|
220
|
+
const breakdown = {
|
|
221
|
+
systemPrompt: 0,
|
|
222
|
+
messages: 0,
|
|
223
|
+
toolOutputs: 0,
|
|
224
|
+
knowledge: 0,
|
|
225
|
+
other: 0,
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
for (const item of budgeted) {
|
|
229
|
+
const tokens = TokenEstimator.estimateText(item.content);
|
|
230
|
+
|
|
231
|
+
switch (item.type) {
|
|
232
|
+
case 'system_prompt':
|
|
233
|
+
breakdown.systemPrompt += tokens;
|
|
234
|
+
break;
|
|
235
|
+
case 'user_message':
|
|
236
|
+
case 'session_event':
|
|
237
|
+
breakdown.messages += tokens;
|
|
238
|
+
break;
|
|
239
|
+
case 'tool_output':
|
|
240
|
+
case 'tool_definition':
|
|
241
|
+
breakdown.toolOutputs += tokens;
|
|
242
|
+
break;
|
|
243
|
+
case 'knowledge':
|
|
244
|
+
breakdown.knowledge += tokens;
|
|
245
|
+
break;
|
|
246
|
+
default:
|
|
247
|
+
breakdown.other += tokens;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return {
|
|
252
|
+
timestamp: new Date().toISOString(),
|
|
253
|
+
totalTokens: breakdown.systemPrompt + breakdown.messages + breakdown.toolOutputs + breakdown.knowledge + breakdown.other,
|
|
254
|
+
breakdown,
|
|
255
|
+
truncatedItems: dropped.filter(d => d.reason.startsWith('截断')).map(d => ({
|
|
256
|
+
type: d.type,
|
|
257
|
+
id: d.id,
|
|
258
|
+
originalTokens: 0,
|
|
259
|
+
keptTokens: 0,
|
|
260
|
+
})),
|
|
261
|
+
offloadedItems: [],
|
|
262
|
+
compactionTriggered: false,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工具输出预算
|
|
3
|
+
*
|
|
4
|
+
* 控制工具输出对上下文的占用
|
|
5
|
+
* 策略:full / preview / overflow / dedup
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as crypto from 'crypto';
|
|
9
|
+
import { TokenEstimator } from './token-budget';
|
|
10
|
+
import type { ToolOutputBudgetConfig } from './types';
|
|
11
|
+
import { DEFAULT_TOOL_OUTPUT_BUDGET } from './types';
|
|
12
|
+
|
|
13
|
+
export type OutputStrategy = 'full' | 'preview' | 'overflow' | 'dedup';
|
|
14
|
+
|
|
15
|
+
export interface OutputCheckResult {
|
|
16
|
+
allowed: boolean;
|
|
17
|
+
strategy: OutputStrategy;
|
|
18
|
+
reason?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface OutputApplyResult {
|
|
22
|
+
content: string;
|
|
23
|
+
offloaded?: { path: string };
|
|
24
|
+
originalTokens: number;
|
|
25
|
+
keptTokens: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class ToolOutputBudget {
|
|
29
|
+
private config: ToolOutputBudgetConfig;
|
|
30
|
+
private seenHashes: Map<string, boolean> = new Map();
|
|
31
|
+
|
|
32
|
+
constructor(config?: Partial<ToolOutputBudgetConfig>) {
|
|
33
|
+
this.config = { ...DEFAULT_TOOL_OUTPUT_BUDGET, ...config };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 检查工具输出应该使用什么策略
|
|
38
|
+
*/
|
|
39
|
+
checkOutput(output: string, totalBudget?: number): OutputCheckResult {
|
|
40
|
+
const charCount = output.length;
|
|
41
|
+
const tokens = TokenEstimator.estimateText(output);
|
|
42
|
+
|
|
43
|
+
// 去重检查
|
|
44
|
+
if (this.config.dedup) {
|
|
45
|
+
const hash = this.computeHash(output);
|
|
46
|
+
if (this.seenHashes.has(hash)) {
|
|
47
|
+
return { allowed: true, strategy: 'dedup', reason: '重复内容,将被去重' };
|
|
48
|
+
}
|
|
49
|
+
// 记录 hash(无论最终策略是什么)
|
|
50
|
+
this.seenHashes.set(hash, true);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// 硬上限检查
|
|
54
|
+
if (charCount > this.config.maxChars) {
|
|
55
|
+
return {
|
|
56
|
+
allowed: true,
|
|
57
|
+
strategy: this.config.overflowToDisk ? 'overflow' : 'preview',
|
|
58
|
+
reason: `输出 ${charCount} 字符超过限制 ${this.config.maxChars}`,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Token 比例检查
|
|
63
|
+
if (totalBudget) {
|
|
64
|
+
const maxTokens = totalBudget * this.config.maxTokenRatio;
|
|
65
|
+
if (tokens > maxTokens) {
|
|
66
|
+
return {
|
|
67
|
+
allowed: true,
|
|
68
|
+
strategy: 'preview',
|
|
69
|
+
reason: `输出 ${tokens} tokens 超过预算比例 ${(this.config.maxTokenRatio * 100).toFixed(0)}% (${Math.floor(maxTokens)} tokens)`,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return { allowed: true, strategy: 'full' };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 应用预算策略
|
|
79
|
+
*/
|
|
80
|
+
applyBudget(output: string, strategy: OutputStrategy, totalBudget?: number): OutputApplyResult {
|
|
81
|
+
const originalTokens = TokenEstimator.estimateText(output);
|
|
82
|
+
|
|
83
|
+
switch (strategy) {
|
|
84
|
+
case 'full': {
|
|
85
|
+
if (this.config.dedup) {
|
|
86
|
+
this.recordHash(output);
|
|
87
|
+
}
|
|
88
|
+
return { content: output, originalTokens, keptTokens: originalTokens };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
case 'preview': {
|
|
92
|
+
const preview = this.generatePreview(output);
|
|
93
|
+
const keptTokens = TokenEstimator.estimateText(preview);
|
|
94
|
+
return { content: preview, originalTokens, keptTokens };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
case 'overflow': {
|
|
98
|
+
const path = this.writeToOverflow(output);
|
|
99
|
+
const summary = `[输出已写入磁盘: ${path}]\n前 ${this.config.previewLines} 行预览:\n${output.split('\n').slice(0, this.config.previewLines).join('\n')}`;
|
|
100
|
+
const keptTokens = TokenEstimator.estimateText(summary);
|
|
101
|
+
return { content: summary, offloaded: { path }, originalTokens, keptTokens };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
case 'dedup': {
|
|
105
|
+
const dedupContent = `[重复内容,已省略。原始大小: ${output.length} 字符]`;
|
|
106
|
+
return { content: dedupContent, originalTokens, keptTokens: TokenEstimator.estimateText(dedupContent) };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
default:
|
|
110
|
+
return { content: output, originalTokens, keptTokens: originalTokens };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* 生成预览内容
|
|
116
|
+
*/
|
|
117
|
+
private generatePreview(output: string): string {
|
|
118
|
+
const lines = output.split('\n');
|
|
119
|
+
const previewLines = this.config.previewLines;
|
|
120
|
+
|
|
121
|
+
if (lines.length <= previewLines) {
|
|
122
|
+
return output;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const head = lines.slice(0, previewLines).join('\n');
|
|
126
|
+
const omitted = lines.length - previewLines;
|
|
127
|
+
return `${head}\n\n... [省略 ${omitted} 行] ...\n\n${lines.slice(-3).join('\n')}`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* 写入溢出文件
|
|
132
|
+
*/
|
|
133
|
+
private writeToOverflow(output: string): string {
|
|
134
|
+
const hash = this.computeHash(output).slice(0, 8);
|
|
135
|
+
const path = `.harness/overflow/tool-output-${hash}.txt`;
|
|
136
|
+
|
|
137
|
+
try {
|
|
138
|
+
const fs = require('fs');
|
|
139
|
+
const dir = require('path').dirname(path);
|
|
140
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
141
|
+
fs.writeFileSync(path, output, 'utf-8');
|
|
142
|
+
} catch {
|
|
143
|
+
// 写入失败时回退到 preview
|
|
144
|
+
return '';
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return path;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 计算内容 hash
|
|
152
|
+
*/
|
|
153
|
+
private computeHash(content: string): string {
|
|
154
|
+
return crypto.createHash('md5').update(content).digest('hex');
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* 记录已见 hash
|
|
159
|
+
*/
|
|
160
|
+
private recordHash(content: string): void {
|
|
161
|
+
const hash = this.computeHash(content);
|
|
162
|
+
this.seenHashes.set(hash, true);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* 清除去重缓存
|
|
167
|
+
*/
|
|
168
|
+
clearDedupCache(): void {
|
|
169
|
+
this.seenHashes.clear();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* 获取配置
|
|
174
|
+
*/
|
|
175
|
+
getConfig(): ToolOutputBudgetConfig {
|
|
176
|
+
return { ...this.config };
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 上下文管理类型定义
|
|
3
|
+
*
|
|
4
|
+
* Phase 2: Token 流水线 + 预算 + 压缩
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { QueryResult } from '../knowledge/types';
|
|
8
|
+
|
|
9
|
+
// ========================================
|
|
10
|
+
// 文件读取预算
|
|
11
|
+
// ========================================
|
|
12
|
+
|
|
13
|
+
export interface FileBudgetConfig {
|
|
14
|
+
maxLines: number; // 默认 2000
|
|
15
|
+
maxBytes: number; // 默认 50KB (51200)
|
|
16
|
+
maxTokenEstimate: number; // 默认 8000
|
|
17
|
+
continuationHint: boolean; // 默认 true
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const DEFAULT_FILE_BUDGET: FileBudgetConfig = {
|
|
21
|
+
maxLines: 2000,
|
|
22
|
+
maxBytes: 51200,
|
|
23
|
+
maxTokenEstimate: 8000,
|
|
24
|
+
continuationHint: true,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// ========================================
|
|
28
|
+
// 工具输出预算
|
|
29
|
+
// ========================================
|
|
30
|
+
|
|
31
|
+
export interface ToolOutputBudgetConfig {
|
|
32
|
+
maxChars: number; // 默认 16000
|
|
33
|
+
maxTokenRatio: number; // 默认 0.3 (占总预算 30%)
|
|
34
|
+
previewLines: number; // 默认 50
|
|
35
|
+
overflowToDisk: boolean; // 默认 false
|
|
36
|
+
dedup: boolean; // 默认 true
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const DEFAULT_TOOL_OUTPUT_BUDGET: ToolOutputBudgetConfig = {
|
|
40
|
+
maxChars: 16000,
|
|
41
|
+
maxTokenRatio: 0.3,
|
|
42
|
+
previewLines: 50,
|
|
43
|
+
overflowToDisk: false,
|
|
44
|
+
dedup: true,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// ========================================
|
|
48
|
+
// 会话压缩
|
|
49
|
+
// ========================================
|
|
50
|
+
|
|
51
|
+
export type CompactionLevel = 'eviction' | 'summary' | 'checkpoint';
|
|
52
|
+
|
|
53
|
+
export interface CompactionConfig {
|
|
54
|
+
triggerRatio: number; // 默认 0.8
|
|
55
|
+
level: CompactionLevel;
|
|
56
|
+
preserveToolCallPairs: boolean; // 默认 true
|
|
57
|
+
structuredSummary: boolean; // 默认 true
|
|
58
|
+
maxSummaryTokens: number; // 默认 2000
|
|
59
|
+
fallbackStrategy: 'truncate-middle' | 'head-drop' | 'retry-with-clamp';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const DEFAULT_COMPACTION_CONFIG: CompactionConfig = {
|
|
63
|
+
triggerRatio: 0.8,
|
|
64
|
+
level: 'eviction',
|
|
65
|
+
preserveToolCallPairs: true,
|
|
66
|
+
structuredSummary: true,
|
|
67
|
+
maxSummaryTokens: 2000,
|
|
68
|
+
fallbackStrategy: 'truncate-middle',
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export interface SessionMessage {
|
|
72
|
+
role: 'user' | 'assistant' | 'tool';
|
|
73
|
+
content: string;
|
|
74
|
+
toolCallId?: string;
|
|
75
|
+
timestamp: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// ========================================
|
|
79
|
+
// Token Pipeline
|
|
80
|
+
// ========================================
|
|
81
|
+
|
|
82
|
+
export type ContextSourceType = 'session_event' | 'tool_output' | 'knowledge' | 'user_message' | 'system_prompt' | 'tool_definition';
|
|
83
|
+
|
|
84
|
+
export interface ContextSource {
|
|
85
|
+
type: ContextSourceType;
|
|
86
|
+
id: string;
|
|
87
|
+
content: string;
|
|
88
|
+
priority: number; // P1-P6
|
|
89
|
+
metadata?: Record<string, any>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface TokenBudgetAllocation {
|
|
93
|
+
total: number;
|
|
94
|
+
systemPrompt: number; // 固定,不压缩
|
|
95
|
+
toolDefinitions: number; // 按需懒加载
|
|
96
|
+
knowledge: number; // 500-800
|
|
97
|
+
notes: number; // 200-500
|
|
98
|
+
history: number; // 剩余预算
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface PipelineInput {
|
|
102
|
+
sources: ContextSource[];
|
|
103
|
+
budget: TokenBudgetAllocation;
|
|
104
|
+
knowledge?: QueryResult;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface PipelineOutput {
|
|
108
|
+
prompt: string;
|
|
109
|
+
snapshot: ContextUsageSnapshot;
|
|
110
|
+
dropped: Array<{ type: string; id: string; reason: string }>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// ========================================
|
|
114
|
+
// 上下文使用快照
|
|
115
|
+
// ========================================
|
|
116
|
+
|
|
117
|
+
export interface ContextUsageSnapshot {
|
|
118
|
+
timestamp: string;
|
|
119
|
+
totalTokens: number;
|
|
120
|
+
breakdown: {
|
|
121
|
+
systemPrompt: number;
|
|
122
|
+
messages: number;
|
|
123
|
+
toolOutputs: number;
|
|
124
|
+
knowledge: number;
|
|
125
|
+
other: number;
|
|
126
|
+
};
|
|
127
|
+
truncatedItems: Array<{ type: string; id: string; originalTokens: number; keptTokens: number }>;
|
|
128
|
+
offloadedItems: Array<{ type: string; id: string; target: 'disk' | 'summary' | 'dropped' }>;
|
|
129
|
+
compactionTriggered: boolean;
|
|
130
|
+
compactionLevel?: CompactionLevel;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// ========================================
|
|
134
|
+
// Session Manager
|
|
135
|
+
// ========================================
|
|
136
|
+
|
|
137
|
+
export type SessionEventType = 'user_message' | 'assistant_message' | 'tool_call' | 'tool_result' | 'checkpoint' | 'system';
|
|
138
|
+
|
|
139
|
+
export interface SessionEvent {
|
|
140
|
+
type: SessionEventType;
|
|
141
|
+
id: string;
|
|
142
|
+
content: string;
|
|
143
|
+
timestamp: string;
|
|
144
|
+
metadata?: Record<string, any>;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface SessionHandle {
|
|
148
|
+
id: string;
|
|
149
|
+
events: SessionEvent[];
|
|
150
|
+
createdAt: string;
|
|
151
|
+
lastActiveAt: string;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export interface SessionCheckpoint {
|
|
155
|
+
id: string;
|
|
156
|
+
sessionId: string;
|
|
157
|
+
timestamp: string;
|
|
158
|
+
eventCount: number;
|
|
159
|
+
summary: string;
|
|
160
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# core/
|
|
2
|
+
|
|
3
|
+
## 职责
|
|
4
|
+
约束引擎核心:三层约束系统(Iron Laws / Guidelines / Tips)、检查点验证器(CSO/passes-gate)、会话管理、Spec 验证器、项目配置加载。
|
|
5
|
+
|
|
6
|
+
## 核心导出
|
|
7
|
+
- `constraints/` — 约束定义(IRON_LAWS/GUIDELINES/TIPS) + 检查引擎(ConstraintChecker) + 拦截器(ConstraintInterceptor) + 缓存(CheckCache)
|
|
8
|
+
- `validators/` — checkpoints、passes-gate、CSO 验证器
|
|
9
|
+
- `session/` — 会话管理
|
|
10
|
+
- `spec/validator` — SpecValidator
|
|
11
|
+
- `project-config-loader` — 项目配置加载 + 约束合并
|
|
12
|
+
|
|
13
|
+
## 依赖关系
|
|
14
|
+
- 被所有模块依赖(基础层,无上层依赖)
|
|
15
|
+
- 依赖 `src/types/` 类型定义
|
|
16
|
+
- 依赖 `src/utils/` 工具函数
|
|
17
|
+
- 依赖 `src/monitoring/traces` TraceCollector
|
|
18
|
+
|
|
19
|
+
## 约定
|
|
20
|
+
- 约束定义在 `constraints/definitions.ts`,不在运行时代码中定义
|
|
21
|
+
- Iron Law 违规必须 throw ConstraintViolationError
|
|
22
|
+
- 检查器使用单例模式(ConstraintChecker.getInstance())
|
|
23
|
+
|
|
24
|
+
## 注意事项
|
|
25
|
+
- 零 Token 成本:所有分析纯文件操作,无 LLM 调用
|
|
26
|
+
- 约束配置支持 .harness/config.yml 自定义合并
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* default-executors 注册测试
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { constraintInterceptor } from '../interceptor';
|
|
6
|
+
|
|
7
|
+
describe('registerDefaultExecutors', () => {
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
jest.clearAllMocks();
|
|
10
|
+
// Reset the singleton state for clean test
|
|
11
|
+
(constraintInterceptor as any).executors.clear();
|
|
12
|
+
(constraintInterceptor as any).executorSources.clear();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('应该注册 architecture-check executor', async () => {
|
|
16
|
+
const { registerDefaultExecutors } = await import('../default-executors');
|
|
17
|
+
registerDefaultExecutors();
|
|
18
|
+
|
|
19
|
+
expect(constraintInterceptor.hasExecutor('architecture-check')).toBe(true);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('应该注册 cross-project-check executor', async () => {
|
|
23
|
+
const { registerDefaultExecutors } = await import('../default-executors');
|
|
24
|
+
registerDefaultExecutors();
|
|
25
|
+
|
|
26
|
+
expect(constraintInterceptor.hasExecutor('cross-project-check')).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('架构检查 executor 应有描述', async () => {
|
|
30
|
+
const { registerDefaultExecutors } = await import('../default-executors');
|
|
31
|
+
registerDefaultExecutors();
|
|
32
|
+
|
|
33
|
+
const executor = constraintInterceptor.getExecutor('architecture-check');
|
|
34
|
+
expect(executor?.description).toBeDefined();
|
|
35
|
+
expect(executor?.description).toContain('架构');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('跨工程检查 executor 应有描述', async () => {
|
|
39
|
+
const { registerDefaultExecutors } = await import('../default-executors');
|
|
40
|
+
registerDefaultExecutors();
|
|
41
|
+
|
|
42
|
+
const executor = constraintInterceptor.getExecutor('cross-project-check');
|
|
43
|
+
expect(executor?.description).toBeDefined();
|
|
44
|
+
expect(executor?.description).toContain('跨工程');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('重复注册应该覆盖', async () => {
|
|
48
|
+
const { registerDefaultExecutors } = await import('../default-executors');
|
|
49
|
+
registerDefaultExecutors();
|
|
50
|
+
registerDefaultExecutors(); // Second call
|
|
51
|
+
|
|
52
|
+
const registrations = constraintInterceptor.getRegistrations();
|
|
53
|
+
const archRegs = registrations.filter(r => r.id === 'architecture-check');
|
|
54
|
+
// Should only have one registration (last one wins)
|
|
55
|
+
expect(archRegs.length).toBe(1);
|
|
56
|
+
});
|
|
57
|
+
});
|