@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,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 约束生命周期执行器
|
|
3
|
+
*
|
|
4
|
+
* 将 ConstraintEvolver 生成的提案转化为 ConstraintRegistry 实际操作。
|
|
5
|
+
* 连接 monitoring 层(proposal)和 constraints 层(registry)。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { ConstraintRegistry } from './registry';
|
|
9
|
+
import type { ConstraintProposal } from '../monitoring/constraint-evolver';
|
|
10
|
+
import type { ConstraintLevel } from '../types/constraint';
|
|
11
|
+
import type { DeprecationSchedule } from './types';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 提案执行结果
|
|
15
|
+
*/
|
|
16
|
+
export interface ExecutionResult {
|
|
17
|
+
proposalId: string;
|
|
18
|
+
constraintId: string;
|
|
19
|
+
action: string;
|
|
20
|
+
success: boolean;
|
|
21
|
+
details: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 约束生命周期执行器
|
|
26
|
+
*
|
|
27
|
+
* 将 evolver 的提案(proposal)转化为 registry 的实际操作(degrade/rollback/scheduleDeprecation)
|
|
28
|
+
*/
|
|
29
|
+
export class ConstraintLifecycleRunner {
|
|
30
|
+
private registry: ConstraintRegistry;
|
|
31
|
+
|
|
32
|
+
constructor(registry?: ConstraintRegistry) {
|
|
33
|
+
this.registry = registry || new ConstraintRegistry();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
getRegistry(): ConstraintRegistry {
|
|
37
|
+
return this.registry;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 执行单个已接受的提案
|
|
42
|
+
*/
|
|
43
|
+
execute(proposal: ConstraintProposal): ExecutionResult {
|
|
44
|
+
switch (proposal.type) {
|
|
45
|
+
case 'change_level':
|
|
46
|
+
return this.executeLevelChange(proposal);
|
|
47
|
+
case 'add_exception':
|
|
48
|
+
return this.executeAddException(proposal);
|
|
49
|
+
case 'adjust_trigger':
|
|
50
|
+
return this.executeAdjustTrigger(proposal);
|
|
51
|
+
case 'modify_message':
|
|
52
|
+
return this.executeModifyMessage(proposal);
|
|
53
|
+
default:
|
|
54
|
+
return {
|
|
55
|
+
proposalId: proposal.id,
|
|
56
|
+
constraintId: proposal.constraintId,
|
|
57
|
+
action: proposal.type,
|
|
58
|
+
success: false,
|
|
59
|
+
details: `Unsupported proposal type: ${proposal.type}`,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 批量执行提案
|
|
66
|
+
*/
|
|
67
|
+
executeBatch(proposals: ConstraintProposal[]): ExecutionResult[] {
|
|
68
|
+
return proposals.map(p => this.execute(p));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 回滚已降级的约束
|
|
73
|
+
*/
|
|
74
|
+
rollbackConstraint(constraintId: string, originalLevel: ConstraintLevel): boolean {
|
|
75
|
+
return this.registry.rollback(constraintId, originalLevel);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 设置约束的弃用计划
|
|
80
|
+
*/
|
|
81
|
+
scheduleDeprecation(constraintId: string, schedule: DeprecationSchedule): boolean {
|
|
82
|
+
return this.registry.scheduleDeprecation(constraintId, schedule);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private executeLevelChange(proposal: ConstraintProposal): ExecutionResult {
|
|
86
|
+
const constraint = this.registry.get(proposal.constraintId);
|
|
87
|
+
if (!constraint) {
|
|
88
|
+
return this.failResult(proposal, `Constraint ${proposal.constraintId} not found`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (constraint.layer === 'safety') {
|
|
92
|
+
return this.failResult(proposal, 'Cannot change level of safety-layer constraint');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const targetLevel = proposal.content.proposed as ConstraintLevel;
|
|
96
|
+
const currentLevel = constraint.level;
|
|
97
|
+
|
|
98
|
+
const levelOrder: Record<string, number> = { iron_law: 0, guideline: 1, tip: 2 };
|
|
99
|
+
if ((levelOrder[targetLevel] ?? 99) > (levelOrder[currentLevel] ?? 0)) {
|
|
100
|
+
const success = this.registry.degrade(proposal.constraintId);
|
|
101
|
+
return {
|
|
102
|
+
proposalId: proposal.id,
|
|
103
|
+
constraintId: proposal.constraintId,
|
|
104
|
+
action: 'degrade',
|
|
105
|
+
success,
|
|
106
|
+
details: success
|
|
107
|
+
? `Degraded from ${currentLevel} to ${targetLevel}`
|
|
108
|
+
: 'Degradation failed',
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return this.failResult(proposal, 'Level change direction not supported via registry');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
private executeAddException(proposal: ConstraintProposal): ExecutionResult {
|
|
116
|
+
const constraint = this.registry.get(proposal.constraintId);
|
|
117
|
+
if (!constraint) {
|
|
118
|
+
return this.failResult(proposal, `Constraint ${proposal.constraintId} not found`);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const exception = proposal.content.proposed;
|
|
122
|
+
const currentExceptions = constraint.exceptions || [];
|
|
123
|
+
|
|
124
|
+
if (currentExceptions.includes(exception)) {
|
|
125
|
+
return this.failResult(proposal, `Exception ${exception} already exists`);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (!constraint.exceptions) constraint.exceptions = [];
|
|
129
|
+
constraint.exceptions.push(exception);
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
proposalId: proposal.id,
|
|
133
|
+
constraintId: proposal.constraintId,
|
|
134
|
+
action: 'add_exception',
|
|
135
|
+
success: true,
|
|
136
|
+
details: `Added exception: ${exception}`,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private executeAdjustTrigger(proposal: ConstraintProposal): ExecutionResult {
|
|
141
|
+
const constraint = this.registry.get(proposal.constraintId);
|
|
142
|
+
if (!constraint) {
|
|
143
|
+
return this.failResult(proposal, `Constraint ${proposal.constraintId} not found`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const oldTrigger = constraint.trigger;
|
|
147
|
+
constraint.trigger = proposal.content.proposed;
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
proposalId: proposal.id,
|
|
151
|
+
constraintId: proposal.constraintId,
|
|
152
|
+
action: 'adjust_trigger',
|
|
153
|
+
success: true,
|
|
154
|
+
details: `Changed trigger from ${JSON.stringify(oldTrigger)} to ${JSON.stringify(proposal.content.proposed)}`,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private executeModifyMessage(proposal: ConstraintProposal): ExecutionResult {
|
|
159
|
+
const constraint = this.registry.get(proposal.constraintId);
|
|
160
|
+
if (!constraint) {
|
|
161
|
+
return this.failResult(proposal, `Constraint ${proposal.constraintId} not found`);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
constraint.message = proposal.content.proposed;
|
|
165
|
+
|
|
166
|
+
return {
|
|
167
|
+
proposalId: proposal.id,
|
|
168
|
+
constraintId: proposal.constraintId,
|
|
169
|
+
action: 'modify_message',
|
|
170
|
+
success: true,
|
|
171
|
+
details: 'Updated message',
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
private failResult(proposal: ConstraintProposal, details: string): ExecutionResult {
|
|
176
|
+
return {
|
|
177
|
+
proposalId: proposal.id,
|
|
178
|
+
constraintId: proposal.constraintId,
|
|
179
|
+
action: proposal.type,
|
|
180
|
+
success: false,
|
|
181
|
+
details,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 约束注册表
|
|
3
|
+
*
|
|
4
|
+
* 基于 core/constraints/definitions 构建,附加分层和退化元数据。
|
|
5
|
+
* 分层规则:iron_law → safety(高阈值),guideline/tip → quality(低阈值)
|
|
6
|
+
* 所有层级均可退化,区别仅在于退化阈值。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { Constraint, ConstraintLevel, ConstraintTrigger } from '../types/constraint';
|
|
10
|
+
import type { LayeredConstraint, ConstraintLayer, DeprecationStatus, LayerStats, DeprecationSchedule } from './types';
|
|
11
|
+
import { IRON_LAWS, GUIDELINES, TIPS } from '../core/constraints/definitions';
|
|
12
|
+
|
|
13
|
+
function toLayered(constraint: Constraint): LayeredConstraint {
|
|
14
|
+
const layer: ConstraintLayer = constraint.level === 'iron_law' ? 'safety' : 'quality';
|
|
15
|
+
const schedule: DeprecationSchedule = layer === 'safety'
|
|
16
|
+
? { targetLevel: 'guideline' as ConstraintLevel, reason: '退化:拦截率持续低于 5%', rollbackable: true }
|
|
17
|
+
: { targetLevel: (constraint.level === 'guideline' ? 'tip' : 'info') as ConstraintLevel, reason: '退化:拦截率持续低于 30%', rollbackable: true };
|
|
18
|
+
return {
|
|
19
|
+
...constraint,
|
|
20
|
+
layer,
|
|
21
|
+
deprecationStatus: 'active' as DeprecationStatus,
|
|
22
|
+
permanent: false,
|
|
23
|
+
deprecationSchedule: schedule,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class ConstraintRegistry {
|
|
28
|
+
private constraints: Map<string, LayeredConstraint>;
|
|
29
|
+
|
|
30
|
+
constructor() {
|
|
31
|
+
this.constraints = new Map();
|
|
32
|
+
const all = { ...IRON_LAWS, ...GUIDELINES, ...TIPS };
|
|
33
|
+
for (const [id, constraint] of Object.entries(all)) {
|
|
34
|
+
this.constraints.set(id, toLayered(constraint));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get(id: string): LayeredConstraint | undefined {
|
|
39
|
+
return this.constraints.get(id);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
getAll(): LayeredConstraint[] {
|
|
43
|
+
return Array.from(this.constraints.values());
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
getByLayer(layer: ConstraintLayer): LayeredConstraint[] {
|
|
47
|
+
return this.getAll().filter(c => c.layer === layer);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
getByStatus(status: DeprecationStatus): LayeredConstraint[] {
|
|
51
|
+
return this.getAll().filter(c => c.deprecationStatus === status);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
getByTrigger(trigger: ConstraintTrigger): LayeredConstraint[] {
|
|
55
|
+
return this.getAll().filter(c => {
|
|
56
|
+
const triggers = Array.isArray(c.trigger) ? c.trigger : [c.trigger];
|
|
57
|
+
return triggers.includes(trigger);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
getDeprecationCandidates(interceptRates: Map<string, number>): LayeredConstraint[] {
|
|
62
|
+
return this.getAll().filter(c => {
|
|
63
|
+
if (c.layer !== 'quality' || !c.deprecationSchedule) return false;
|
|
64
|
+
if (c.deprecationStatus !== 'active') return false;
|
|
65
|
+
const threshold = c.deprecationSchedule.interceptRateThreshold;
|
|
66
|
+
if (threshold === undefined) return false;
|
|
67
|
+
const rate = interceptRates.get(c.id);
|
|
68
|
+
return rate !== undefined && rate < threshold;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
degrade(id: string): boolean {
|
|
73
|
+
const constraint = this.constraints.get(id);
|
|
74
|
+
if (!constraint || !constraint.deprecationSchedule) return false;
|
|
75
|
+
if (constraint.deprecationStatus !== 'active') return false;
|
|
76
|
+
constraint.level = constraint.deprecationSchedule.targetLevel;
|
|
77
|
+
constraint.deprecationStatus = 'deprecated';
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
rollback(id: string, originalLevel: ConstraintLevel): boolean {
|
|
82
|
+
const constraint = this.constraints.get(id);
|
|
83
|
+
if (!constraint) return false;
|
|
84
|
+
if (!constraint.deprecationSchedule?.rollbackable) return false;
|
|
85
|
+
constraint.level = originalLevel;
|
|
86
|
+
constraint.deprecationStatus = 'active';
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
scheduleDeprecation(id: string, schedule: DeprecationSchedule): boolean {
|
|
91
|
+
const constraint = this.constraints.get(id);
|
|
92
|
+
if (!constraint || constraint.layer !== 'quality') return false;
|
|
93
|
+
constraint.deprecationSchedule = schedule;
|
|
94
|
+
constraint.deprecationStatus = 'scheduled';
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
getLayerStats(): LayerStats[] {
|
|
99
|
+
const layers: ConstraintLayer[] = ['safety', 'quality'];
|
|
100
|
+
return layers.map(layer => {
|
|
101
|
+
const constraints = this.getByLayer(layer);
|
|
102
|
+
return {
|
|
103
|
+
layer,
|
|
104
|
+
totalConstraints: constraints.length,
|
|
105
|
+
active: constraints.filter(c => c.deprecationStatus === 'active').length,
|
|
106
|
+
scheduled: constraints.filter(c => c.deprecationStatus === 'scheduled').length,
|
|
107
|
+
deprecated: constraints.filter(c => c.deprecationStatus === 'deprecated').length,
|
|
108
|
+
removed: constraints.filter(c => c.deprecationStatus === 'removed').length,
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
toLegacyConstraints(): Constraint[] {
|
|
114
|
+
return this.getAll().map(c => ({
|
|
115
|
+
id: c.id,
|
|
116
|
+
rule: c.rule,
|
|
117
|
+
message: c.message,
|
|
118
|
+
level: c.level,
|
|
119
|
+
trigger: c.trigger,
|
|
120
|
+
enforcement: c.enforcement,
|
|
121
|
+
description: c.description,
|
|
122
|
+
enabled: c.enabled,
|
|
123
|
+
exceptions: c.exceptions,
|
|
124
|
+
}));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
register(constraint: LayeredConstraint): void {
|
|
128
|
+
this.constraints.set(constraint.id, constraint);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
remove(id: string): boolean {
|
|
132
|
+
return this.constraints.delete(id);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 约束分层类型定义
|
|
3
|
+
*
|
|
4
|
+
* 在原有 Constraint 基础上增加分层和退化元数据
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { Constraint, ConstraintLevel } from '../types/constraint';
|
|
8
|
+
|
|
9
|
+
/** 约束分层 */
|
|
10
|
+
export type ConstraintLayer = 'safety' | 'quality';
|
|
11
|
+
|
|
12
|
+
/** 退化状态 */
|
|
13
|
+
export type DeprecationStatus = 'active' | 'scheduled' | 'deprecated' | 'removed';
|
|
14
|
+
|
|
15
|
+
/** 退化计划 */
|
|
16
|
+
export interface DeprecationSchedule {
|
|
17
|
+
/** 目标级别(当前 → 目标) */
|
|
18
|
+
targetLevel: ConstraintLevel;
|
|
19
|
+
/** 触发条件:拦截率低于此值时触发退化 */
|
|
20
|
+
interceptRateThreshold?: number;
|
|
21
|
+
/** 计划退化日期 */
|
|
22
|
+
scheduledDate?: string;
|
|
23
|
+
/** 退化原因 */
|
|
24
|
+
reason: string;
|
|
25
|
+
/** 是否可回滚 */
|
|
26
|
+
rollbackable: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** 带分层元数据的约束 */
|
|
30
|
+
export interface LayeredConstraint extends Constraint {
|
|
31
|
+
/** 所属层 */
|
|
32
|
+
layer: ConstraintLayer;
|
|
33
|
+
/** 退化状态 */
|
|
34
|
+
deprecationStatus: DeprecationStatus;
|
|
35
|
+
/** 退化计划(所有层均有,iron_law 高阈值,guideline/tip 低阈值) */
|
|
36
|
+
deprecationSchedule?: DeprecationSchedule;
|
|
37
|
+
/** 是否永久保留(false = 所有层均可退化,区别仅在于阈值) */
|
|
38
|
+
permanent?: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** 约束拦截统计 */
|
|
42
|
+
export interface ConstraintStats {
|
|
43
|
+
constraintId: string;
|
|
44
|
+
triggerCount: number;
|
|
45
|
+
passCount: number;
|
|
46
|
+
interceptCount: number;
|
|
47
|
+
interceptRate: number;
|
|
48
|
+
lastTriggered?: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** 约束层统计汇总 */
|
|
52
|
+
export interface LayerStats {
|
|
53
|
+
layer: ConstraintLayer;
|
|
54
|
+
totalConstraints: number;
|
|
55
|
+
active: number;
|
|
56
|
+
scheduled: number;
|
|
57
|
+
deprecated: number;
|
|
58
|
+
removed: number;
|
|
59
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# context/
|
|
2
|
+
|
|
3
|
+
## 职责
|
|
4
|
+
上下文管理:Token 预算(多级分配)、渐进式加载(worker pool 并发)、文件/工具输出预算、会话压缩、Token 流水线、知识注入。
|
|
5
|
+
|
|
6
|
+
## 核心导出
|
|
7
|
+
- `TokenBudget` — 多级 token 预算(system/user/tool/reserve)
|
|
8
|
+
- `ProgressiveLoader` — 渐进式加载 + worker pool 并发
|
|
9
|
+
- `FileBudget` — 文件级 token 预算
|
|
10
|
+
- `ToolOutputBudget` — 工具输出 token 预算
|
|
11
|
+
- `Compaction` — 会话压缩(摘要/截断/滑动窗口)
|
|
12
|
+
- `TokenPipeline` — Token 流水线
|
|
13
|
+
- `SessionManager` — 会话管理
|
|
14
|
+
- `KnowledgeInjector` — 知识注入引擎
|
|
15
|
+
|
|
16
|
+
## 依赖关系
|
|
17
|
+
- 依赖 `src/types/` 公共类型
|
|
18
|
+
- 依赖 `src/core/` 核心模块
|
|
19
|
+
- 被 Agent 会话管理消费
|
|
20
|
+
|
|
21
|
+
## 约定
|
|
22
|
+
- Token 预算策略由配置文件控制
|
|
23
|
+
- 渐进式加载保证输入顺序(worker pool 模式)
|
|
24
|
+
- 会话压缩策略可组合
|
|
25
|
+
|
|
26
|
+
## 注意事项
|
|
27
|
+
- Phase 2 实现的 Token 流水线 + 预算 + 压缩
|
|
28
|
+
- 零 Token 成本:纯计算,不调用 LLM
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SessionCompaction 测试
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { SessionCompaction } from '../compaction';
|
|
6
|
+
import type { SessionMessage } from '../types';
|
|
7
|
+
|
|
8
|
+
function makeMessages(count: number, contentLength: number = 100): SessionMessage[] {
|
|
9
|
+
return Array.from({ length: count }, (_, i) => ({
|
|
10
|
+
role: (i % 2 === 0 ? 'user' : 'assistant') as 'user' | 'assistant',
|
|
11
|
+
content: `message ${i} `.repeat(contentLength / 10),
|
|
12
|
+
timestamp: new Date(Date.now() + i * 1000).toISOString(),
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe('SessionCompaction', () => {
|
|
17
|
+
describe('shouldCompact', () => {
|
|
18
|
+
it('应该返回 true 当超过触发比例', () => {
|
|
19
|
+
const compaction = new SessionCompaction({ triggerRatio: 0.5 });
|
|
20
|
+
const messages = makeMessages(10, 500);
|
|
21
|
+
// 10 * ~50 tokens each ≈ 500 tokens, budget=800 → ratio > 0.5
|
|
22
|
+
expect(compaction.shouldCompact(messages, 800)).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('应该返回 false 当未超过触发比例', () => {
|
|
26
|
+
const compaction = new SessionCompaction({ triggerRatio: 0.9 });
|
|
27
|
+
const messages = makeMessages(2, 10);
|
|
28
|
+
expect(compaction.shouldCompact(messages, 10000)).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('compact (eviction)', () => {
|
|
33
|
+
it('应该按比例丢弃最早消息', () => {
|
|
34
|
+
const compaction = new SessionCompaction({ level: 'eviction', preserveToolCallPairs: false });
|
|
35
|
+
const messages = makeMessages(20, 500);
|
|
36
|
+
const result = compaction.compact(messages, 1000);
|
|
37
|
+
expect(result.level).toBe('eviction');
|
|
38
|
+
expect(result.compacted.length).toBeLessThan(messages.length);
|
|
39
|
+
expect(result.compacted.length).toBeGreaterThanOrEqual(2);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('应该保留最近的消息', () => {
|
|
43
|
+
const compaction = new SessionCompaction({ level: 'eviction', preserveToolCallPairs: false });
|
|
44
|
+
const messages = makeMessages(20, 100);
|
|
45
|
+
const result = compaction.compact(messages, 1000);
|
|
46
|
+
const lastOriginal = messages[messages.length - 1];
|
|
47
|
+
expect(result.compacted[result.compacted.length - 1]).toBe(lastOriginal);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('应该保留 tool-call 边界对', () => {
|
|
51
|
+
const compaction = new SessionCompaction({ level: 'eviction', preserveToolCallPairs: true });
|
|
52
|
+
const messages: SessionMessage[] = [
|
|
53
|
+
{ role: 'user', content: 'a'.repeat(1000), timestamp: 't1' },
|
|
54
|
+
{ role: 'assistant', content: 'b'.repeat(1000), toolCallId: 'call-1', timestamp: 't2' },
|
|
55
|
+
{ role: 'tool', content: 'c'.repeat(1000), toolCallId: 'call-1', timestamp: 't3' },
|
|
56
|
+
{ role: 'user', content: 'd'.repeat(1000), timestamp: 't4' },
|
|
57
|
+
{ role: 'assistant', content: 'e'.repeat(1000), timestamp: 't5' },
|
|
58
|
+
];
|
|
59
|
+
const result = compaction.compact(messages, 500);
|
|
60
|
+
// 如果 tool result is kept, its paired assistant call should also be kept
|
|
61
|
+
const toolResult = result.compacted.find(m => m.role === 'tool');
|
|
62
|
+
if (toolResult) {
|
|
63
|
+
const paired = result.compacted.find(m => m.toolCallId === toolResult.toolCallId && m.role === 'assistant');
|
|
64
|
+
expect(paired).toBeDefined();
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe('compact (summary)', () => {
|
|
70
|
+
it('应该生成结构化摘要', () => {
|
|
71
|
+
const compaction = new SessionCompaction({ level: 'summary' });
|
|
72
|
+
const messages = makeMessages(20, 100);
|
|
73
|
+
const result = compaction.compact(messages, 1000);
|
|
74
|
+
expect(result.level).toBe('summary');
|
|
75
|
+
expect(result.summary).toBeDefined();
|
|
76
|
+
expect(result.summary).toContain('用户目标');
|
|
77
|
+
expect(result.summary).toContain('消息总数');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('应该保留最近 6 条消息', () => {
|
|
81
|
+
const compaction = new SessionCompaction({ level: 'summary' });
|
|
82
|
+
const messages = makeMessages(20, 100);
|
|
83
|
+
const result = compaction.compact(messages, 1000);
|
|
84
|
+
// 1 summary message + 6 recent
|
|
85
|
+
expect(result.compacted.length).toBe(7);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('compact (checkpoint)', () => {
|
|
90
|
+
it('应该压缩为单条 checkpoint 消息', () => {
|
|
91
|
+
const compaction = new SessionCompaction({ level: 'checkpoint' });
|
|
92
|
+
const messages = makeMessages(20, 100);
|
|
93
|
+
const result = compaction.compact(messages, 1000);
|
|
94
|
+
expect(result.level).toBe('checkpoint');
|
|
95
|
+
expect(result.compacted.length).toBe(1);
|
|
96
|
+
expect(result.compacted[0].content).toContain('Checkpoint');
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe('generateStructuredSummary', () => {
|
|
101
|
+
it('应该从用户消息提取目标', () => {
|
|
102
|
+
const compaction = new SessionCompaction();
|
|
103
|
+
const messages: SessionMessage[] = [
|
|
104
|
+
{ role: 'user', content: '帮我写一个函数', timestamp: 't1' },
|
|
105
|
+
{ role: 'assistant', content: '好的', timestamp: 't2' },
|
|
106
|
+
];
|
|
107
|
+
const summary = compaction.generateStructuredSummary(messages);
|
|
108
|
+
expect(summary).toContain('帮我写一个函数');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('应该统计工具调用', () => {
|
|
112
|
+
const compaction = new SessionCompaction();
|
|
113
|
+
const messages: SessionMessage[] = [
|
|
114
|
+
{ role: 'tool', content: 'result1', timestamp: 't1' },
|
|
115
|
+
{ role: 'tool', content: 'result2', timestamp: 't2' },
|
|
116
|
+
];
|
|
117
|
+
const summary = compaction.generateStructuredSummary(messages);
|
|
118
|
+
expect(summary).toContain('2 次');
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe('getConfig', () => {
|
|
123
|
+
it('应该返回配置', () => {
|
|
124
|
+
const compaction = new SessionCompaction({ level: 'summary' });
|
|
125
|
+
expect(compaction.getConfig().level).toBe('summary');
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe('compact (default level)', () => {
|
|
130
|
+
it('应该在未知 level 时回退到 eviction', () => {
|
|
131
|
+
const compaction = new SessionCompaction({ level: 'eviction' as any, preserveToolCallPairs: false });
|
|
132
|
+
// 直接设置一个不会匹配的 level 来触发 default 分支
|
|
133
|
+
(compaction as any).config.level = 'unknown_level';
|
|
134
|
+
const messages = makeMessages(20, 500);
|
|
135
|
+
const result = compaction.compact(messages, 1000);
|
|
136
|
+
expect(result.level).toBe('eviction');
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
describe('preserveToolCallPairs 边界情况', () => {
|
|
141
|
+
it('应该在 paired assistant 已在 compacted 中时跳过', () => {
|
|
142
|
+
const compaction = new SessionCompaction({ level: 'eviction', preserveToolCallPairs: true });
|
|
143
|
+
const messages: SessionMessage[] = [
|
|
144
|
+
{ role: 'user', content: 'a'.repeat(100), timestamp: 't1' },
|
|
145
|
+
{ role: 'assistant', content: 'b'.repeat(100), toolCallId: 'call-1', timestamp: 't2' },
|
|
146
|
+
{ role: 'tool', content: 'c'.repeat(100), toolCallId: 'call-1', timestamp: 't3' },
|
|
147
|
+
{ role: 'user', content: 'd'.repeat(100), timestamp: 't4' },
|
|
148
|
+
{ role: 'assistant', content: 'e'.repeat(100), timestamp: 't5' },
|
|
149
|
+
];
|
|
150
|
+
// budget 足够大,所有消息都会保留
|
|
151
|
+
const result = compaction.compact(messages, 100000);
|
|
152
|
+
// paired assistant 已在 compacted 中,不应重复添加
|
|
153
|
+
const assistantCalls = result.compacted.filter(m => m.toolCallId === 'call-1' && m.role === 'assistant');
|
|
154
|
+
expect(assistantCalls.length).toBe(1);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('应该处理无 toolCallId 的消息', () => {
|
|
158
|
+
const compaction = new SessionCompaction({ level: 'eviction', preserveToolCallPairs: true });
|
|
159
|
+
const messages: SessionMessage[] = [
|
|
160
|
+
{ role: 'user', content: 'a'.repeat(1000), timestamp: 't1' },
|
|
161
|
+
{ role: 'assistant', content: 'b'.repeat(1000), timestamp: 't2' },
|
|
162
|
+
{ role: 'user', content: 'c'.repeat(1000), timestamp: 't3' },
|
|
163
|
+
{ role: 'assistant', content: 'd'.repeat(1000), timestamp: 't4' },
|
|
164
|
+
];
|
|
165
|
+
const result = compaction.compact(messages, 500);
|
|
166
|
+
expect(result.compacted.length).toBeGreaterThan(0);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
});
|