@kenkaiiii/gg-engine 0.0.0-stage → 7.1.0
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/LICENSE +661 -0
- package/NOTICE +43 -0
- package/README.md +53 -2
- package/assets/skills/bulletproof/SKILL.md +132 -0
- package/assets/skills/bulletproof/references/agent-surface.md +113 -0
- package/assets/skills/bulletproof/references/attack-classes.md +226 -0
- package/assets/skills/bulletproof/references/audit-protocol.md +232 -0
- package/assets/skills/bulletproof/references/platform-playbooks.md +196 -0
- package/assets/skills/bulletproof/references/provenance.md +146 -0
- package/assets/skills/bulletproof/references/secure-defaults.md +137 -0
- package/assets/skills/bulletproof/references/supply-chain.md +84 -0
- package/assets/skills/bulletproof/references/threat-landscape.md +66 -0
- package/assets/skills/bulletproof/references/verification.md +74 -0
- package/assets/skills/compliance-guard/SKILL.md +115 -0
- package/assets/skills/compliance-guard/references/artifacts.md +199 -0
- package/assets/skills/compliance-guard/references/eu-uk.md +162 -0
- package/assets/skills/compliance-guard/references/exposure-triage.md +177 -0
- package/assets/skills/compliance-guard/references/full-review.md +155 -0
- package/assets/skills/compliance-guard/references/lawsuit-vectors.md +153 -0
- package/assets/skills/compliance-guard/references/provenance.md +135 -0
- package/assets/skills/compliance-guard/references/sector-gates.md +187 -0
- package/assets/skills/compliance-guard/references/security-baseline.md +117 -0
- package/assets/skills/compliance-guard/references/trigger-map.md +177 -0
- package/assets/skills/compliance-guard/references/us.md +194 -0
- package/assets/skills/durable/SKILL.md +114 -0
- package/assets/skills/durable/references/agent-db-safety.md +76 -0
- package/assets/skills/durable/references/backups-and-runtime.md +93 -0
- package/assets/skills/durable/references/migrations-and-schema.md +87 -0
- package/assets/skills/gg-guide/SKILL.md +43 -0
- package/assets/skills/gg-guide/references/chat-motion-goals.md +217 -0
- package/assets/skills/gg-guide/references/checklist-and-safety.md +177 -0
- package/assets/skills/gg-guide/references/code-mode.md +272 -0
- package/assets/skills/gg-guide/references/getting-started.md +295 -0
- package/assets/skills/gg-guide/references/ken-and-autopilot.md +172 -0
- package/assets/skills/gg-guide/references/mcp-and-skills.md +204 -0
- package/assets/skills/gg-guide/references/models-and-sign-in.md +200 -0
- package/assets/skills/gg-guide/references/sessions-and-history.md +213 -0
- package/assets/skills/gg-guide/references/settings.md +193 -0
- package/assets/skills/gg-guide/references/troubleshooting-and-data.md +186 -0
- package/assets/skills/lean/SKILL.md +117 -0
- package/assets/skills/lean/references/memory-and-processes.md +99 -0
- package/assets/skills/lean/references/playbooks.md +134 -0
- package/dist/app-error.d.ts +22 -0
- package/dist/app-error.js +41 -0
- package/dist/app-error.js.map +1 -0
- package/dist/config.d.ts +90 -0
- package/dist/config.js +240 -0
- package/dist/config.js.map +1 -0
- package/dist/core/acceptance-checks.d.ts +48 -0
- package/dist/core/acceptance-checks.js +151 -0
- package/dist/core/acceptance-checks.js.map +1 -0
- package/dist/core/action-threats.d.ts +68 -0
- package/dist/core/action-threats.js +894 -0
- package/dist/core/action-threats.js.map +1 -0
- package/dist/core/agent-notifications.d.ts +79 -0
- package/dist/core/agent-notifications.js +125 -0
- package/dist/core/agent-notifications.js.map +1 -0
- package/dist/core/agent-session/helpers.d.ts +26 -0
- package/dist/core/agent-session/helpers.js +47 -0
- package/dist/core/agent-session/helpers.js.map +1 -0
- package/dist/core/agent-session/mcp-tools.d.ts +87 -0
- package/dist/core/agent-session/mcp-tools.js +227 -0
- package/dist/core/agent-session/mcp-tools.js.map +1 -0
- package/dist/core/agent-session/run-loop-monitor.d.ts +63 -0
- package/dist/core/agent-session/run-loop-monitor.js +164 -0
- package/dist/core/agent-session/run-loop-monitor.js.map +1 -0
- package/dist/core/agent-session/transcript-markers.d.ts +57 -0
- package/dist/core/agent-session/transcript-markers.js +166 -0
- package/dist/core/agent-session/transcript-markers.js.map +1 -0
- package/dist/core/agent-session/verification-tracker.d.ts +71 -0
- package/dist/core/agent-session/verification-tracker.js +295 -0
- package/dist/core/agent-session/verification-tracker.js.map +1 -0
- package/dist/core/agent-session.d.ts +1401 -0
- package/dist/core/agent-session.js +5160 -0
- package/dist/core/agent-session.js.map +1 -0
- package/dist/core/agents.d.ts +63 -0
- package/dist/core/agents.js +160 -0
- package/dist/core/agents.js.map +1 -0
- package/dist/core/ask-user.d.ts +163 -0
- package/dist/core/ask-user.js +178 -0
- package/dist/core/ask-user.js.map +1 -0
- package/dist/core/auto-update.d.ts +32 -0
- package/dist/core/auto-update.js +218 -0
- package/dist/core/auto-update.js.map +1 -0
- package/dist/core/autopilot-cycle.d.ts +127 -0
- package/dist/core/autopilot-cycle.js +182 -0
- package/dist/core/autopilot-cycle.js.map +1 -0
- package/dist/core/autopilot-gate.d.ts +106 -0
- package/dist/core/autopilot-gate.js +192 -0
- package/dist/core/autopilot-gate.js.map +1 -0
- package/dist/core/autopilot-verdict.d.ts +55 -0
- package/dist/core/autopilot-verdict.js +226 -0
- package/dist/core/autopilot-verdict.js.map +1 -0
- package/dist/core/blocked-packages-file.d.ts +33 -0
- package/dist/core/blocked-packages-file.js +274 -0
- package/dist/core/blocked-packages-file.js.map +1 -0
- package/dist/core/bundled-agents.d.ts +2 -0
- package/dist/core/bundled-agents.js +253 -0
- package/dist/core/bundled-agents.js.map +1 -0
- package/dist/core/cache-diagnostics.d.ts +72 -0
- package/dist/core/cache-diagnostics.js +200 -0
- package/dist/core/cache-diagnostics.js.map +1 -0
- package/dist/core/cache-expiry.d.ts +89 -0
- package/dist/core/cache-expiry.js +117 -0
- package/dist/core/cache-expiry.js.map +1 -0
- package/dist/core/checklist-detection.d.ts +8 -0
- package/dist/core/checklist-detection.js +238 -0
- package/dist/core/checklist-detection.js.map +1 -0
- package/dist/core/checklist-git.d.ts +19 -0
- package/dist/core/checklist-git.js +54 -0
- package/dist/core/checklist-git.js.map +1 -0
- package/dist/core/checklist-items.d.ts +182 -0
- package/dist/core/checklist-items.js +228 -0
- package/dist/core/checklist-items.js.map +1 -0
- package/dist/core/checklist-prompt.d.ts +14 -0
- package/dist/core/checklist-prompt.js +64 -0
- package/dist/core/checklist-prompt.js.map +1 -0
- package/dist/core/checklist-snapshot.d.ts +7 -0
- package/dist/core/checklist-snapshot.js +46 -0
- package/dist/core/checklist-snapshot.js.map +1 -0
- package/dist/core/checklist-store.d.ts +45 -0
- package/dist/core/checklist-store.js +281 -0
- package/dist/core/checklist-store.js.map +1 -0
- package/dist/core/checkout-record.d.ts +22 -0
- package/dist/core/checkout-record.js +68 -0
- package/dist/core/checkout-record.js.map +1 -0
- package/dist/core/checkpoint-store.d.ts +109 -0
- package/dist/core/checkpoint-store.js +260 -0
- package/dist/core/checkpoint-store.js.map +1 -0
- package/dist/core/claude-code/complete.d.ts +35 -0
- package/dist/core/claude-code/complete.js +125 -0
- package/dist/core/claude-code/complete.js.map +1 -0
- package/dist/core/claude-code/events.d.ts +67 -0
- package/dist/core/claude-code/events.js +460 -0
- package/dist/core/claude-code/events.js.map +1 -0
- package/dist/core/claude-code/live-session.d.ts +94 -0
- package/dist/core/claude-code/live-session.js +525 -0
- package/dist/core/claude-code/live-session.js.map +1 -0
- package/dist/core/claude-code/loop.d.ts +9 -0
- package/dist/core/claude-code/loop.js +15 -0
- package/dist/core/claude-code/loop.js.map +1 -0
- package/dist/core/claude-code/session-sync.d.ts +28 -0
- package/dist/core/claude-code/session-sync.js +53 -0
- package/dist/core/claude-code/session-sync.js.map +1 -0
- package/dist/core/claude-code/tool-bridge.d.ts +49 -0
- package/dist/core/claude-code/tool-bridge.js +352 -0
- package/dist/core/claude-code/tool-bridge.js.map +1 -0
- package/dist/core/claude-code/transcripts.d.ts +39 -0
- package/dist/core/claude-code/transcripts.js +195 -0
- package/dist/core/claude-code/transcripts.js.map +1 -0
- package/dist/core/code-retrieval-chunkers.d.ts +26 -0
- package/dist/core/code-retrieval-chunkers.js +264 -0
- package/dist/core/code-retrieval-chunkers.js.map +1 -0
- package/dist/core/code-retrieval.d.ts +18 -0
- package/dist/core/code-retrieval.js +124 -0
- package/dist/core/code-retrieval.js.map +1 -0
- package/dist/core/codex-request-shape.d.ts +7 -0
- package/dist/core/codex-request-shape.js +19 -0
- package/dist/core/codex-request-shape.js.map +1 -0
- package/dist/core/compaction/active-context.d.ts +16 -0
- package/dist/core/compaction/active-context.js +20 -0
- package/dist/core/compaction/active-context.js.map +1 -0
- package/dist/core/compaction/compactor.d.ts +281 -0
- package/dist/core/compaction/compactor.js +1451 -0
- package/dist/core/compaction/compactor.js.map +1 -0
- package/dist/core/compaction/plan-step-policy.d.ts +46 -0
- package/dist/core/compaction/plan-step-policy.js +57 -0
- package/dist/core/compaction/plan-step-policy.js.map +1 -0
- package/dist/core/compaction/policy.d.ts +36 -0
- package/dist/core/compaction/policy.js +144 -0
- package/dist/core/compaction/policy.js.map +1 -0
- package/dist/core/compaction/query-aware-selector.d.ts +32 -0
- package/dist/core/compaction/query-aware-selector.js +202 -0
- package/dist/core/compaction/query-aware-selector.js.map +1 -0
- package/dist/core/compaction/token-estimator.d.ts +36 -0
- package/dist/core/compaction/token-estimator.js +180 -0
- package/dist/core/compaction/token-estimator.js.map +1 -0
- package/dist/core/compaction/tool-result-pruner.d.ts +90 -0
- package/dist/core/compaction/tool-result-pruner.js +238 -0
- package/dist/core/compaction/tool-result-pruner.js.map +1 -0
- package/dist/core/completion-review.d.ts +24 -0
- package/dist/core/completion-review.js +2 -0
- package/dist/core/completion-review.js.map +1 -0
- package/dist/core/context-files.d.ts +8 -0
- package/dist/core/context-files.js +46 -0
- package/dist/core/context-files.js.map +1 -0
- package/dist/core/context-limits.d.ts +40 -0
- package/dist/core/context-limits.js +43 -0
- package/dist/core/context-limits.js.map +1 -0
- package/dist/core/custom-commands.d.ts +18 -0
- package/dist/core/custom-commands.js +57 -0
- package/dist/core/custom-commands.js.map +1 -0
- package/dist/core/destructive-git-guard.d.ts +113 -0
- package/dist/core/destructive-git-guard.js +874 -0
- package/dist/core/destructive-git-guard.js.map +1 -0
- package/dist/core/display-items.d.ts +8 -0
- package/dist/core/display-items.js +2 -0
- package/dist/core/display-items.js.map +1 -0
- package/dist/core/encode-cwd.d.ts +41 -0
- package/dist/core/encode-cwd.js +53 -0
- package/dist/core/encode-cwd.js.map +1 -0
- package/dist/core/env-delta.d.ts +34 -0
- package/dist/core/env-delta.js +84 -0
- package/dist/core/env-delta.js.map +1 -0
- package/dist/core/event-bus.d.ts +178 -0
- package/dist/core/event-bus.js +171 -0
- package/dist/core/event-bus.js.map +1 -0
- package/dist/core/extensions/loader.d.ts +7 -0
- package/dist/core/extensions/loader.js +68 -0
- package/dist/core/extensions/loader.js.map +1 -0
- package/dist/core/extensions/plugin-bundles.d.ts +13 -0
- package/dist/core/extensions/plugin-bundles.js +45 -0
- package/dist/core/extensions/plugin-bundles.js.map +1 -0
- package/dist/core/extensions/types.d.ts +18 -0
- package/dist/core/extensions/types.js +2 -0
- package/dist/core/extensions/types.js.map +1 -0
- package/dist/core/foreign-session-import.d.ts +119 -0
- package/dist/core/foreign-session-import.js +598 -0
- package/dist/core/foreign-session-import.js.map +1 -0
- package/dist/core/foreign-transcript-blocks.d.ts +50 -0
- package/dist/core/foreign-transcript-blocks.js +151 -0
- package/dist/core/foreign-transcript-blocks.js.map +1 -0
- package/dist/core/frontmatter.d.ts +22 -0
- package/dist/core/frontmatter.js +90 -0
- package/dist/core/frontmatter.js.map +1 -0
- package/dist/core/goal-run-marker.d.ts +32 -0
- package/dist/core/goal-run-marker.js +178 -0
- package/dist/core/goal-run-marker.js.map +1 -0
- package/dist/core/goal-summary.d.ts +15 -0
- package/dist/core/goal-summary.js +110 -0
- package/dist/core/goal-summary.js.map +1 -0
- package/dist/core/goals-store.d.ts +208 -0
- package/dist/core/goals-store.js +577 -0
- package/dist/core/goals-store.js.map +1 -0
- package/dist/core/hashline.d.ts +51 -0
- package/dist/core/hashline.js +76 -0
- package/dist/core/hashline.js.map +1 -0
- package/dist/core/idle-wake.d.ts +62 -0
- package/dist/core/idle-wake.js +103 -0
- package/dist/core/idle-wake.js.map +1 -0
- package/dist/core/index.d.ts +15 -0
- package/dist/core/index.js +15 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/injection-detect.d.ts +39 -0
- package/dist/core/injection-detect.js +241 -0
- package/dist/core/injection-detect.js.map +1 -0
- package/dist/core/installed-threats.d.ts +23 -0
- package/dist/core/installed-threats.js +71 -0
- package/dist/core/installed-threats.js.map +1 -0
- package/dist/core/internal-diagnostics.d.ts +159 -0
- package/dist/core/internal-diagnostics.js +495 -0
- package/dist/core/internal-diagnostics.js.map +1 -0
- package/dist/core/keep-awake.d.ts +88 -0
- package/dist/core/keep-awake.js +251 -0
- package/dist/core/keep-awake.js.map +1 -0
- package/dist/core/ken-ask-answer.d.ts +24 -0
- package/dist/core/ken-ask-answer.js +96 -0
- package/dist/core/ken-ask-answer.js.map +1 -0
- package/dist/core/ken-context.d.ts +119 -0
- package/dist/core/ken-context.js +447 -0
- package/dist/core/ken-context.js.map +1 -0
- package/dist/core/ken-model.d.ts +45 -0
- package/dist/core/ken-model.js +26 -0
- package/dist/core/ken-model.js.map +1 -0
- package/dist/core/ken-prompt.d.ts +21 -0
- package/dist/core/ken-prompt.js +370 -0
- package/dist/core/ken-prompt.js.map +1 -0
- package/dist/core/language-detector.d.ts +41 -0
- package/dist/core/language-detector.js +293 -0
- package/dist/core/language-detector.js.map +1 -0
- package/dist/core/live-preview.d.ts +26 -0
- package/dist/core/live-preview.js +80 -0
- package/dist/core/live-preview.js.map +1 -0
- package/dist/core/local-endpoint-store.d.ts +53 -0
- package/dist/core/local-endpoint-store.js +221 -0
- package/dist/core/local-endpoint-store.js.map +1 -0
- package/dist/core/logger.d.ts +21 -0
- package/dist/core/logger.js +94 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/loop-breaker.d.ts +89 -0
- package/dist/core/loop-breaker.js +204 -0
- package/dist/core/loop-breaker.js.map +1 -0
- package/dist/core/lsp/client.d.ts +206 -0
- package/dist/core/lsp/client.js +685 -0
- package/dist/core/lsp/client.js.map +1 -0
- package/dist/core/lsp/edit-telemetry.d.ts +26 -0
- package/dist/core/lsp/edit-telemetry.js +52 -0
- package/dist/core/lsp/edit-telemetry.js.map +1 -0
- package/dist/core/lsp/format.d.ts +11 -0
- package/dist/core/lsp/format.js +30 -0
- package/dist/core/lsp/format.js.map +1 -0
- package/dist/core/lsp/jsonrpc.d.ts +68 -0
- package/dist/core/lsp/jsonrpc.js +153 -0
- package/dist/core/lsp/jsonrpc.js.map +1 -0
- package/dist/core/lsp/manager.d.ts +188 -0
- package/dist/core/lsp/manager.js +576 -0
- package/dist/core/lsp/manager.js.map +1 -0
- package/dist/core/lsp/pool.d.ts +114 -0
- package/dist/core/lsp/pool.js +259 -0
- package/dist/core/lsp/pool.js.map +1 -0
- package/dist/core/lsp/project-root.d.ts +9 -0
- package/dist/core/lsp/project-root.js +75 -0
- package/dist/core/lsp/project-root.js.map +1 -0
- package/dist/core/lsp/reference-project.d.ts +6 -0
- package/dist/core/lsp/reference-project.js +110 -0
- package/dist/core/lsp/reference-project.js.map +1 -0
- package/dist/core/lsp/servers.d.ts +44 -0
- package/dist/core/lsp/servers.js +289 -0
- package/dist/core/lsp/servers.js.map +1 -0
- package/dist/core/lsp/test-support.d.ts +17 -0
- package/dist/core/lsp/test-support.js +27 -0
- package/dist/core/lsp/test-support.js.map +1 -0
- package/dist/core/mcp/catalog-cache.d.ts +64 -0
- package/dist/core/mcp/catalog-cache.js +166 -0
- package/dist/core/mcp/catalog-cache.js.map +1 -0
- package/dist/core/mcp/client.d.ts +317 -0
- package/dist/core/mcp/client.js +1168 -0
- package/dist/core/mcp/client.js.map +1 -0
- package/dist/core/mcp/content.d.ts +23 -0
- package/dist/core/mcp/content.js +194 -0
- package/dist/core/mcp/content.js.map +1 -0
- package/dist/core/mcp/defaults.d.ts +26 -0
- package/dist/core/mcp/defaults.js +81 -0
- package/dist/core/mcp/defaults.js.map +1 -0
- package/dist/core/mcp/deferred-catalog.d.ts +53 -0
- package/dist/core/mcp/deferred-catalog.js +117 -0
- package/dist/core/mcp/deferred-catalog.js.map +1 -0
- package/dist/core/mcp/elicitation-bridge.d.ts +40 -0
- package/dist/core/mcp/elicitation-bridge.js +36 -0
- package/dist/core/mcp/elicitation-bridge.js.map +1 -0
- package/dist/core/mcp/index.d.ts +16 -0
- package/dist/core/mcp/index.js +10 -0
- package/dist/core/mcp/index.js.map +1 -0
- package/dist/core/mcp/loopback.d.ts +26 -0
- package/dist/core/mcp/loopback.js +66 -0
- package/dist/core/mcp/loopback.js.map +1 -0
- package/dist/core/mcp/oauth-provider.d.ts +55 -0
- package/dist/core/mcp/oauth-provider.js +106 -0
- package/dist/core/mcp/oauth-provider.js.map +1 -0
- package/dist/core/mcp/oauth-store.d.ts +44 -0
- package/dist/core/mcp/oauth-store.js +76 -0
- package/dist/core/mcp/oauth-store.js.map +1 -0
- package/dist/core/mcp/parse-add-command.d.ts +50 -0
- package/dist/core/mcp/parse-add-command.js +391 -0
- package/dist/core/mcp/parse-add-command.js.map +1 -0
- package/dist/core/mcp/resolve-stdio.d.ts +77 -0
- package/dist/core/mcp/resolve-stdio.js +359 -0
- package/dist/core/mcp/resolve-stdio.js.map +1 -0
- package/dist/core/mcp/shared-pool.d.ts +157 -0
- package/dist/core/mcp/shared-pool.js +236 -0
- package/dist/core/mcp/shared-pool.js.map +1 -0
- package/dist/core/mcp/store.d.ts +100 -0
- package/dist/core/mcp/store.js +202 -0
- package/dist/core/mcp/store.js.map +1 -0
- package/dist/core/mcp/tool-guard.d.ts +58 -0
- package/dist/core/mcp/tool-guard.js +215 -0
- package/dist/core/mcp/tool-guard.js.map +1 -0
- package/dist/core/mcp/types.d.ts +57 -0
- package/dist/core/mcp/types.js +2 -0
- package/dist/core/mcp/types.js.map +1 -0
- package/dist/core/message-images.d.ts +11 -0
- package/dist/core/message-images.js +52 -0
- package/dist/core/message-images.js.map +1 -0
- package/dist/core/model-unavailable.d.ts +14 -0
- package/dist/core/model-unavailable.js +23 -0
- package/dist/core/model-unavailable.js.map +1 -0
- package/dist/core/network-guard.d.ts +28 -0
- package/dist/core/network-guard.js +251 -0
- package/dist/core/network-guard.js.map +1 -0
- package/dist/core/node-debugger.d.ts +148 -0
- package/dist/core/node-debugger.js +642 -0
- package/dist/core/node-debugger.js.map +1 -0
- package/dist/core/opencode-catalog-store.d.ts +20 -0
- package/dist/core/opencode-catalog-store.js +82 -0
- package/dist/core/opencode-catalog-store.js.map +1 -0
- package/dist/core/openrouter-catalog-store.d.ts +24 -0
- package/dist/core/openrouter-catalog-store.js +140 -0
- package/dist/core/openrouter-catalog-store.js.map +1 -0
- package/dist/core/package-cooldown.d.ts +69 -0
- package/dist/core/package-cooldown.js +297 -0
- package/dist/core/package-cooldown.js.map +1 -0
- package/dist/core/package-threats.d.ts +92 -0
- package/dist/core/package-threats.js +1339 -0
- package/dist/core/package-threats.js.map +1 -0
- package/dist/core/parked-requests.d.ts +43 -0
- package/dist/core/parked-requests.js +34 -0
- package/dist/core/parked-requests.js.map +1 -0
- package/dist/core/persistent-shell.d.ts +81 -0
- package/dist/core/persistent-shell.js +452 -0
- package/dist/core/persistent-shell.js.map +1 -0
- package/dist/core/plan-delta.d.ts +23 -0
- package/dist/core/plan-delta.js +36 -0
- package/dist/core/plan-delta.js.map +1 -0
- package/dist/core/plan-handoff.d.ts +38 -0
- package/dist/core/plan-handoff.js +21 -0
- package/dist/core/plan-handoff.js.map +1 -0
- package/dist/core/plan-submission-gate.d.ts +28 -0
- package/dist/core/plan-submission-gate.js +27 -0
- package/dist/core/plan-submission-gate.js.map +1 -0
- package/dist/core/platform-clis.d.ts +15 -0
- package/dist/core/platform-clis.js +299 -0
- package/dist/core/platform-clis.js.map +1 -0
- package/dist/core/process-gate.d.ts +61 -0
- package/dist/core/process-gate.js +103 -0
- package/dist/core/process-gate.js.map +1 -0
- package/dist/core/process-manager.d.ts +242 -0
- package/dist/core/process-manager.js +902 -0
- package/dist/core/process-manager.js.map +1 -0
- package/dist/core/progress/engine.d.ts +22 -0
- package/dist/core/progress/engine.js +131 -0
- package/dist/core/progress/engine.js.map +1 -0
- package/dist/core/progress/git-xp.d.ts +15 -0
- package/dist/core/progress/git-xp.js +100 -0
- package/dist/core/progress/git-xp.js.map +1 -0
- package/dist/core/progress/ranks.d.ts +31 -0
- package/dist/core/progress/ranks.js +310 -0
- package/dist/core/progress/ranks.js.map +1 -0
- package/dist/core/progress/rebuild.d.ts +8 -0
- package/dist/core/progress/rebuild.js +125 -0
- package/dist/core/progress/rebuild.js.map +1 -0
- package/dist/core/progress/store.d.ts +34 -0
- package/dist/core/progress/store.js +200 -0
- package/dist/core/progress/store.js.map +1 -0
- package/dist/core/progress/types.d.ts +56 -0
- package/dist/core/progress/types.js +2 -0
- package/dist/core/progress/types.js.map +1 -0
- package/dist/core/project-discovery.d.ts +64 -0
- package/dist/core/project-discovery.js +908 -0
- package/dist/core/project-discovery.js.map +1 -0
- package/dist/core/project-files.d.ts +15 -0
- package/dist/core/project-files.js +37 -0
- package/dist/core/project-files.js.map +1 -0
- package/dist/core/project-health-scan.d.ts +109 -0
- package/dist/core/project-health-scan.js +673 -0
- package/dist/core/project-health-scan.js.map +1 -0
- package/dist/core/project-health-score.d.ts +41 -0
- package/dist/core/project-health-score.js +257 -0
- package/dist/core/project-health-score.js.map +1 -0
- package/dist/core/prompt-command-expansion.d.ts +13 -0
- package/dist/core/prompt-command-expansion.js +48 -0
- package/dist/core/prompt-command-expansion.js.map +1 -0
- package/dist/core/prompt-commands.d.ts +13 -0
- package/dist/core/prompt-commands.js +370 -0
- package/dist/core/prompt-commands.js.map +1 -0
- package/dist/core/pull-requests.d.ts +18 -0
- package/dist/core/pull-requests.js +95 -0
- package/dist/core/pull-requests.js.map +1 -0
- package/dist/core/radio-players.d.ts +28 -0
- package/dist/core/radio-players.js +132 -0
- package/dist/core/radio-players.js.map +1 -0
- package/dist/core/radio.d.ts +42 -0
- package/dist/core/radio.js +499 -0
- package/dist/core/radio.js.map +1 -0
- package/dist/core/regrounding.d.ts +37 -0
- package/dist/core/regrounding.js +89 -0
- package/dist/core/regrounding.js.map +1 -0
- package/dist/core/resolve-start.d.ts +28 -0
- package/dist/core/resolve-start.js +35 -0
- package/dist/core/resolve-start.js.map +1 -0
- package/dist/core/run-claim.d.ts +36 -0
- package/dist/core/run-claim.js +46 -0
- package/dist/core/run-claim.js.map +1 -0
- package/dist/core/run-lifecycle.d.ts +58 -0
- package/dist/core/run-lifecycle.js +104 -0
- package/dist/core/run-lifecycle.js.map +1 -0
- package/dist/core/run-status.d.ts +17 -0
- package/dist/core/run-status.js +28 -0
- package/dist/core/run-status.js.map +1 -0
- package/dist/core/runtime-mode.d.ts +21 -0
- package/dist/core/runtime-mode.js +43 -0
- package/dist/core/runtime-mode.js.map +1 -0
- package/dist/core/sandbox-domains.d.ts +13 -0
- package/dist/core/sandbox-domains.js +76 -0
- package/dist/core/sandbox-domains.js.map +1 -0
- package/dist/core/sandbox-feedback.d.ts +21 -0
- package/dist/core/sandbox-feedback.js +69 -0
- package/dist/core/sandbox-feedback.js.map +1 -0
- package/dist/core/sandbox.d.ts +106 -0
- package/dist/core/sandbox.js +383 -0
- package/dist/core/sandbox.js.map +1 -0
- package/dist/core/semantic-loop-check.d.ts +58 -0
- package/dist/core/semantic-loop-check.js +103 -0
- package/dist/core/semantic-loop-check.js.map +1 -0
- package/dist/core/session-compaction.d.ts +23 -0
- package/dist/core/session-compaction.js +54 -0
- package/dist/core/session-compaction.js.map +1 -0
- package/dist/core/session-export.d.ts +97 -0
- package/dist/core/session-export.js +368 -0
- package/dist/core/session-export.js.map +1 -0
- package/dist/core/session-history.d.ts +160 -0
- package/dist/core/session-history.js +467 -0
- package/dist/core/session-history.js.map +1 -0
- package/dist/core/session-manager.d.ts +512 -0
- package/dist/core/session-manager.js +1370 -0
- package/dist/core/session-manager.js.map +1 -0
- package/dist/core/session-preview.d.ts +12 -0
- package/dist/core/session-preview.js +58 -0
- package/dist/core/session-preview.js.map +1 -0
- package/dist/core/session-storage.d.ts +78 -0
- package/dist/core/session-storage.js +659 -0
- package/dist/core/session-storage.js.map +1 -0
- package/dist/core/session-summary-index.d.ts +51 -0
- package/dist/core/session-summary-index.js +192 -0
- package/dist/core/session-summary-index.js.map +1 -0
- package/dist/core/settings-manager.d.ts +113 -0
- package/dist/core/settings-manager.js +281 -0
- package/dist/core/settings-manager.js.map +1 -0
- package/dist/core/shared-checkout-guard.d.ts +78 -0
- package/dist/core/shared-checkout-guard.js +219 -0
- package/dist/core/shared-checkout-guard.js.map +1 -0
- package/dist/core/shell-path.d.ts +13 -0
- package/dist/core/shell-path.js +175 -0
- package/dist/core/shell-path.js.map +1 -0
- package/dist/core/shell-threats-popular-packages.d.ts +11 -0
- package/dist/core/shell-threats-popular-packages.js +675 -0
- package/dist/core/shell-threats-popular-packages.js.map +1 -0
- package/dist/core/shell-threats.d.ts +21 -0
- package/dist/core/shell-threats.js +235 -0
- package/dist/core/shell-threats.js.map +1 -0
- package/dist/core/shell.d.ts +54 -0
- package/dist/core/shell.js +99 -0
- package/dist/core/shell.js.map +1 -0
- package/dist/core/shutdown.d.ts +70 -0
- package/dist/core/shutdown.js +144 -0
- package/dist/core/shutdown.js.map +1 -0
- package/dist/core/skill-scan.d.ts +112 -0
- package/dist/core/skill-scan.js +781 -0
- package/dist/core/skill-scan.js.map +1 -0
- package/dist/core/skills.d.ts +80 -0
- package/dist/core/skills.js +270 -0
- package/dist/core/skills.js.map +1 -0
- package/dist/core/slash-commands.d.ts +58 -0
- package/dist/core/slash-commands.js +242 -0
- package/dist/core/slash-commands.js.map +1 -0
- package/dist/core/steering.d.ts +47 -0
- package/dist/core/steering.js +65 -0
- package/dist/core/steering.js.map +1 -0
- package/dist/core/steroids.d.ts +66 -0
- package/dist/core/steroids.js +243 -0
- package/dist/core/steroids.js.map +1 -0
- package/dist/core/stream-diag-level.d.ts +3 -0
- package/dist/core/stream-diag-level.js +24 -0
- package/dist/core/stream-diag-level.js.map +1 -0
- package/dist/core/stream-rules.d.ts +30 -0
- package/dist/core/stream-rules.js +151 -0
- package/dist/core/stream-rules.js.map +1 -0
- package/dist/core/subagent-manager.d.ts +242 -0
- package/dist/core/subagent-manager.js +1075 -0
- package/dist/core/subagent-manager.js.map +1 -0
- package/dist/core/subagent-policy.d.ts +9 -0
- package/dist/core/subagent-policy.js +41 -0
- package/dist/core/subagent-policy.js.map +1 -0
- package/dist/core/subagent-receipt.d.ts +54 -0
- package/dist/core/subagent-receipt.js +274 -0
- package/dist/core/subagent-receipt.js.map +1 -0
- package/dist/core/subagent-store.d.ts +41 -0
- package/dist/core/subagent-store.js +284 -0
- package/dist/core/subagent-store.js.map +1 -0
- package/dist/core/subagent-turn-record.d.ts +18 -0
- package/dist/core/subagent-turn-record.js +82 -0
- package/dist/core/subagent-turn-record.js.map +1 -0
- package/dist/core/tasks-store.d.ts +31 -0
- package/dist/core/tasks-store.js +97 -0
- package/dist/core/tasks-store.js.map +1 -0
- package/dist/core/telegram-config.d.ts +20 -0
- package/dist/core/telegram-config.js +52 -0
- package/dist/core/telegram-config.js.map +1 -0
- package/dist/core/telegram.d.ts +114 -0
- package/dist/core/telegram.js +275 -0
- package/dist/core/telegram.js.map +1 -0
- package/dist/core/temp-paths.d.ts +5 -0
- package/dist/core/temp-paths.js +50 -0
- package/dist/core/temp-paths.js.map +1 -0
- package/dist/core/test-impact.d.ts +73 -0
- package/dist/core/test-impact.js +467 -0
- package/dist/core/test-impact.js.map +1 -0
- package/dist/core/threat-feed.d.ts +65 -0
- package/dist/core/threat-feed.js +334 -0
- package/dist/core/threat-feed.js.map +1 -0
- package/dist/core/trophies/catalog-more.d.ts +2 -0
- package/dist/core/trophies/catalog-more.js +837 -0
- package/dist/core/trophies/catalog-more.js.map +1 -0
- package/dist/core/trophies/catalog.d.ts +4 -0
- package/dist/core/trophies/catalog.js +649 -0
- package/dist/core/trophies/catalog.js.map +1 -0
- package/dist/core/trophies/engine.d.ts +70 -0
- package/dist/core/trophies/engine.js +347 -0
- package/dist/core/trophies/engine.js.map +1 -0
- package/dist/core/trophies/store.d.ts +17 -0
- package/dist/core/trophies/store.js +113 -0
- package/dist/core/trophies/store.js.map +1 -0
- package/dist/core/trophies/types.d.ts +87 -0
- package/dist/core/trophies/types.js +74 -0
- package/dist/core/trophies/types.js.map +1 -0
- package/dist/core/ui-adoption.d.ts +32 -0
- package/dist/core/ui-adoption.js +302 -0
- package/dist/core/ui-adoption.js.map +1 -0
- package/dist/core/ui-compatibility.d.ts +10 -0
- package/dist/core/ui-compatibility.js +51 -0
- package/dist/core/ui-compatibility.js.map +1 -0
- package/dist/core/ui-registry.d.ts +101 -0
- package/dist/core/ui-registry.js +292 -0
- package/dist/core/ui-registry.js.map +1 -0
- package/dist/core/user-shell-context.d.ts +8 -0
- package/dist/core/user-shell-context.js +12 -0
- package/dist/core/user-shell-context.js.map +1 -0
- package/dist/core/verification-evidence.d.ts +49 -0
- package/dist/core/verification-evidence.js +816 -0
- package/dist/core/verification-evidence.js.map +1 -0
- package/dist/core/verification-gate.d.ts +77 -0
- package/dist/core/verification-gate.js +504 -0
- package/dist/core/verification-gate.js.map +1 -0
- package/dist/core/verification-snapshot.d.ts +7 -0
- package/dist/core/verification-snapshot.js +109 -0
- package/dist/core/verification-snapshot.js.map +1 -0
- package/dist/core/verify-commands.d.ts +34 -0
- package/dist/core/verify-commands.js +203 -0
- package/dist/core/verify-commands.js.map +1 -0
- package/dist/core/voice-transcriber.d.ts +32 -0
- package/dist/core/voice-transcriber.js +114 -0
- package/dist/core/voice-transcriber.js.map +1 -0
- package/dist/core/workspace-guard.d.ts +56 -0
- package/dist/core/workspace-guard.js +334 -0
- package/dist/core/workspace-guard.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/session.d.ts +44 -0
- package/dist/session.js +105 -0
- package/dist/session.js.map +1 -0
- package/dist/system-prompt.d.ts +104 -0
- package/dist/system-prompt.js +480 -0
- package/dist/system-prompt.js.map +1 -0
- package/dist/test-support/fake-home.d.ts +19 -0
- package/dist/test-support/fake-home.js +37 -0
- package/dist/test-support/fake-home.js.map +1 -0
- package/dist/test-support/keep-alive.d.ts +14 -0
- package/dist/test-support/keep-alive.js +17 -0
- package/dist/test-support/keep-alive.js.map +1 -0
- package/dist/test-support/slow-git.d.ts +1 -0
- package/dist/test-support/slow-git.js +21 -0
- package/dist/test-support/slow-git.js.map +1 -0
- package/dist/test-support/system-tools.d.ts +6 -0
- package/dist/test-support/system-tools.js +36 -0
- package/dist/test-support/system-tools.js.map +1 -0
- package/dist/tools/ask-user.d.ts +34 -0
- package/dist/tools/ask-user.js +99 -0
- package/dist/tools/ask-user.js.map +1 -0
- package/dist/tools/background-watch-lint.d.ts +18 -0
- package/dist/tools/background-watch-lint.js +102 -0
- package/dist/tools/background-watch-lint.js.map +1 -0
- package/dist/tools/bash-read-evidence.d.ts +23 -0
- package/dist/tools/bash-read-evidence.js +180 -0
- package/dist/tools/bash-read-evidence.js.map +1 -0
- package/dist/tools/bash.d.ts +64 -0
- package/dist/tools/bash.js +552 -0
- package/dist/tools/bash.js.map +1 -0
- package/dist/tools/browser-api.d.ts +27 -0
- package/dist/tools/browser-api.js +449 -0
- package/dist/tools/browser-api.js.map +1 -0
- package/dist/tools/browser-sandbox.d.ts +16 -0
- package/dist/tools/browser-sandbox.js +158 -0
- package/dist/tools/browser-sandbox.js.map +1 -0
- package/dist/tools/browser-session.d.ts +84 -0
- package/dist/tools/browser-session.js +304 -0
- package/dist/tools/browser-session.js.map +1 -0
- package/dist/tools/browser-snapshot.d.ts +19 -0
- package/dist/tools/browser-snapshot.js +109 -0
- package/dist/tools/browser-snapshot.js.map +1 -0
- package/dist/tools/browser.d.ts +11 -0
- package/dist/tools/browser.js +106 -0
- package/dist/tools/browser.js.map +1 -0
- package/dist/tools/checklist.d.ts +49 -0
- package/dist/tools/checklist.js +154 -0
- package/dist/tools/checklist.js.map +1 -0
- package/dist/tools/compress.d.ts +56 -0
- package/dist/tools/compress.js +226 -0
- package/dist/tools/compress.js.map +1 -0
- package/dist/tools/debug.d.ts +54 -0
- package/dist/tools/debug.js +230 -0
- package/dist/tools/debug.js.map +1 -0
- package/dist/tools/document-text.d.ts +6 -0
- package/dist/tools/document-text.js +154 -0
- package/dist/tools/document-text.js.map +1 -0
- package/dist/tools/edit-diff.d.ts +123 -0
- package/dist/tools/edit-diff.js +476 -0
- package/dist/tools/edit-diff.js.map +1 -0
- package/dist/tools/edit-targets.d.ts +10 -0
- package/dist/tools/edit-targets.js +31 -0
- package/dist/tools/edit-targets.js.map +1 -0
- package/dist/tools/edit.d.ts +38 -0
- package/dist/tools/edit.js +695 -0
- package/dist/tools/edit.js.map +1 -0
- package/dist/tools/enter-plan.d.ts +7 -0
- package/dist/tools/enter-plan.js +20 -0
- package/dist/tools/enter-plan.js.map +1 -0
- package/dist/tools/exit-plan.d.ts +7 -0
- package/dist/tools/exit-plan.js +51 -0
- package/dist/tools/exit-plan.js.map +1 -0
- package/dist/tools/find.d.ts +17 -0
- package/dist/tools/find.js +100 -0
- package/dist/tools/find.js.map +1 -0
- package/dist/tools/generate-image.d.ts +83 -0
- package/dist/tools/generate-image.js +625 -0
- package/dist/tools/generate-image.js.map +1 -0
- package/dist/tools/grep-scan.d.ts +96 -0
- package/dist/tools/grep-scan.js +283 -0
- package/dist/tools/grep-scan.js.map +1 -0
- package/dist/tools/grep.d.ts +48 -0
- package/dist/tools/grep.js +1013 -0
- package/dist/tools/grep.js.map +1 -0
- package/dist/tools/html-extract.d.ts +57 -0
- package/dist/tools/html-extract.js +130 -0
- package/dist/tools/html-extract.js.map +1 -0
- package/dist/tools/index.d.ts +198 -0
- package/dist/tools/index.js +216 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/live-preview.d.ts +23 -0
- package/dist/tools/live-preview.js +41 -0
- package/dist/tools/live-preview.js.map +1 -0
- package/dist/tools/ls.d.ts +9 -0
- package/dist/tools/ls.js +59 -0
- package/dist/tools/ls.js.map +1 -0
- package/dist/tools/operations.d.ts +86 -0
- package/dist/tools/operations.js +117 -0
- package/dist/tools/operations.js.map +1 -0
- package/dist/tools/overflow.d.ts +17 -0
- package/dist/tools/overflow.js +68 -0
- package/dist/tools/overflow.js.map +1 -0
- package/dist/tools/path-utils.d.ts +30 -0
- package/dist/tools/path-utils.js +74 -0
- package/dist/tools/path-utils.js.map +1 -0
- package/dist/tools/pdf-extract.d.ts +17 -0
- package/dist/tools/pdf-extract.js +43 -0
- package/dist/tools/pdf-extract.js.map +1 -0
- package/dist/tools/prompt-hints.d.ts +46 -0
- package/dist/tools/prompt-hints.js +171 -0
- package/dist/tools/prompt-hints.js.map +1 -0
- package/dist/tools/read-only-bash.d.ts +31 -0
- package/dist/tools/read-only-bash.js +338 -0
- package/dist/tools/read-only-bash.js.map +1 -0
- package/dist/tools/read-tracker.d.ts +43 -0
- package/dist/tools/read-tracker.js +120 -0
- package/dist/tools/read-tracker.js.map +1 -0
- package/dist/tools/read.d.ts +18 -0
- package/dist/tools/read.js +316 -0
- package/dist/tools/read.js.map +1 -0
- package/dist/tools/redaction-guard.d.ts +10 -0
- package/dist/tools/redaction-guard.js +55 -0
- package/dist/tools/redaction-guard.js.map +1 -0
- package/dist/tools/routine-output.d.ts +39 -0
- package/dist/tools/routine-output.js +281 -0
- package/dist/tools/routine-output.js.map +1 -0
- package/dist/tools/safe-env.d.ts +1 -0
- package/dist/tools/safe-env.js +79 -0
- package/dist/tools/safe-env.js.map +1 -0
- package/dist/tools/session-stats.d.ts +26 -0
- package/dist/tools/session-stats.js +51 -0
- package/dist/tools/session-stats.js.map +1 -0
- package/dist/tools/side-web-search.d.ts +34 -0
- package/dist/tools/side-web-search.js +146 -0
- package/dist/tools/side-web-search.js.map +1 -0
- package/dist/tools/skill.d.ts +12 -0
- package/dist/tools/skill.js +94 -0
- package/dist/tools/skill.js.map +1 -0
- package/dist/tools/source-path.d.ts +8 -0
- package/dist/tools/source-path.js +135 -0
- package/dist/tools/source-path.js.map +1 -0
- package/dist/tools/steroids.d.ts +44 -0
- package/dist/tools/steroids.js +356 -0
- package/dist/tools/steroids.js.map +1 -0
- package/dist/tools/subagent-control.d.ts +5 -0
- package/dist/tools/subagent-control.js +211 -0
- package/dist/tools/subagent-control.js.map +1 -0
- package/dist/tools/subagent-shared.d.ts +115 -0
- package/dist/tools/subagent-shared.js +182 -0
- package/dist/tools/subagent-shared.js.map +1 -0
- package/dist/tools/subagent.d.ts +39 -0
- package/dist/tools/subagent.js +412 -0
- package/dist/tools/subagent.js.map +1 -0
- package/dist/tools/task-output.d.ts +10 -0
- package/dist/tools/task-output.js +74 -0
- package/dist/tools/task-output.js.map +1 -0
- package/dist/tools/task-send.d.ts +11 -0
- package/dist/tools/task-send.js +36 -0
- package/dist/tools/task-send.js.map +1 -0
- package/dist/tools/task-stop.d.ts +8 -0
- package/dist/tools/task-stop.js +15 -0
- package/dist/tools/task-stop.js.map +1 -0
- package/dist/tools/tasks.d.ts +15 -0
- package/dist/tools/tasks.js +94 -0
- package/dist/tools/tasks.js.map +1 -0
- package/dist/tools/tool-search.d.ts +26 -0
- package/dist/tools/tool-search.js +81 -0
- package/dist/tools/tool-search.js.map +1 -0
- package/dist/tools/tool-tiers.d.ts +65 -0
- package/dist/tools/tool-tiers.js +121 -0
- package/dist/tools/tool-tiers.js.map +1 -0
- package/dist/tools/truncate.d.ts +39 -0
- package/dist/tools/truncate.js +242 -0
- package/dist/tools/truncate.js.map +1 -0
- package/dist/tools/ui-adopt.d.ts +16 -0
- package/dist/tools/ui-adopt.js +66 -0
- package/dist/tools/ui-adopt.js.map +1 -0
- package/dist/tools/ui-registry.d.ts +15 -0
- package/dist/tools/ui-registry.js +39 -0
- package/dist/tools/ui-registry.js.map +1 -0
- package/dist/tools/verification-review.d.ts +2 -0
- package/dist/tools/verification-review.js +41 -0
- package/dist/tools/verification-review.js.map +1 -0
- package/dist/tools/web-fetch.d.ts +52 -0
- package/dist/tools/web-fetch.js +986 -0
- package/dist/tools/web-fetch.js.map +1 -0
- package/dist/tools/web-search.d.ts +35 -0
- package/dist/tools/web-search.js +926 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/tools/write.d.ts +16 -0
- package/dist/tools/write.js +196 -0
- package/dist/tools/write.js.map +1 -0
- package/dist/types.d.ts +44 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/commit-message.d.ts +25 -0
- package/dist/utils/commit-message.js +72 -0
- package/dist/utils/commit-message.js.map +1 -0
- package/dist/utils/git.d.ts +102 -0
- package/dist/utils/git.js +325 -0
- package/dist/utils/git.js.map +1 -0
- package/dist/utils/github-ci.d.ts +9 -0
- package/dist/utils/github-ci.js +138 -0
- package/dist/utils/github-ci.js.map +1 -0
- package/dist/utils/github.d.ts +19 -0
- package/dist/utils/github.js +67 -0
- package/dist/utils/github.js.map +1 -0
- package/dist/utils/image.d.ts +166 -0
- package/dist/utils/image.js +673 -0
- package/dist/utils/image.js.map +1 -0
- package/dist/utils/open-browser.d.ts +13 -0
- package/dist/utils/open-browser.js +31 -0
- package/dist/utils/open-browser.js.map +1 -0
- package/dist/utils/plan-steps.d.ts +90 -0
- package/dist/utils/plan-steps.js +209 -0
- package/dist/utils/plan-steps.js.map +1 -0
- package/dist/utils/process.d.ts +48 -0
- package/dist/utils/process.js +175 -0
- package/dist/utils/process.js.map +1 -0
- package/dist/utils/prompt-enhancer.d.ts +34 -0
- package/dist/utils/prompt-enhancer.js +178 -0
- package/dist/utils/prompt-enhancer.js.map +1 -0
- package/dist/utils/text.d.ts +61 -0
- package/dist/utils/text.js +68 -0
- package/dist/utils/text.js.map +1 -0
- package/package.json +87 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-aware-selector.js","sourceRoot":"","sources":["../../../src/core/compaction/query-aware-selector.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AA0B7D,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IACzB,OAAO;IACP,OAAO;IACP,OAAO;IACP,MAAM;IACN,KAAK;IACL,KAAK;IACL,KAAK;IACL,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BAAgB;YAAE,OAAO;QACvD,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACpB,cAAc,IAAI,MAAM,CAAC;IAC3B,CAAC,CAAC;IAEF,4EAA4E;IAC5E,+DAA+D;IAC/D,MAAM,YAAY,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC;IAC9E,IAAI,YAAY,IAAI,CAAC;QAAE,SAAS,CAAC,YAAY,CAAC,CAAC;IAC/C,KAAK,MAAM,SAAS,IAAI,OAAO;QAAE,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC5D,2EAA2E;IAC3E,iDAAiD;IACjD,KAAK,IAAI,KAAK,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,KAAK,EAAE;QAAE,SAAS,CAAC,KAAK,CAAC,CAAC;IAE5E,OAAO;QACL,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACnE,QAAQ,EAAE,aAAa;QACvB,cAAc;QACd,eAAe,EAAE,QAAQ,CAAC,MAAM,GAAG,QAAQ,CAAC,IAAI;QAChD,UAAU;KACX,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Message, Usage } from "@kenkaiiii/gg-ai";
|
|
2
|
+
/**
|
|
3
|
+
* Set the active model name for token estimation.
|
|
4
|
+
* Call this when the model changes so estimates use the correct ratio.
|
|
5
|
+
* Switching models resets usage-based calibration (different tokenizer).
|
|
6
|
+
*/
|
|
7
|
+
export declare function setEstimatorModel(model: string): void;
|
|
8
|
+
/**
|
|
9
|
+
* Feed an authoritative provider usage observation back into the estimator:
|
|
10
|
+
* blends `chars / tokens` into the session ratio via EMA, clamped to sane
|
|
11
|
+
* bounds. Every downstream estimate (compaction trigger, prune budgets)
|
|
12
|
+
* sharpens as real usage data accumulates.
|
|
13
|
+
*/
|
|
14
|
+
export declare function calibrateEstimator(chars: number, tokens: number): void;
|
|
15
|
+
/** Current usage-calibrated chars-per-token ratio, or null before any observation. */
|
|
16
|
+
export declare function getCalibratedRatio(): number | null;
|
|
17
|
+
/**
|
|
18
|
+
* Measure the text characters in a message history and whether it contains
|
|
19
|
+
* image/video parts (which inflate tokens-per-char and would skew calibration).
|
|
20
|
+
*/
|
|
21
|
+
export declare function measureConversationChars(messages: Message[]): {
|
|
22
|
+
chars: number;
|
|
23
|
+
hasMedia: boolean;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Calibrate from a provider usage report anchored to a message history using
|
|
27
|
+
* its authoritative total input tokens (uncached + cache read/write). Skips
|
|
28
|
+
* histories containing image/video parts.
|
|
29
|
+
*/
|
|
30
|
+
export declare function calibrateEstimatorFromUsage(history: Message[], usage: Usage,
|
|
31
|
+
/** Characters the provider also counted but `history` lacks — the tool
|
|
32
|
+
* definitions sent with the request. Omitting them biases the ratio low. */
|
|
33
|
+
extraChars?: number): void;
|
|
34
|
+
export declare function estimateTokens(text: string): number;
|
|
35
|
+
export declare function estimateMessageTokens(message: Message): number;
|
|
36
|
+
export declare function estimateConversationTokens(messages: Message[]): number;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-family-specific chars-per-token ratios.
|
|
3
|
+
* These are empirically measured averages for English text.
|
|
4
|
+
* CJK/code/mixed content will vary, but these are better than a flat 4.0.
|
|
5
|
+
*/
|
|
6
|
+
const MODEL_FAMILY_RATIOS = {
|
|
7
|
+
// Anthropic models: ~3.2 chars/token (BPE tokenizer, slightly more compact)
|
|
8
|
+
claude: 3.2,
|
|
9
|
+
// OpenAI models: ~3.7 chars/token (cl100k_base / o200k_base)
|
|
10
|
+
gpt: 3.7,
|
|
11
|
+
o1: 3.7,
|
|
12
|
+
o3: 3.7,
|
|
13
|
+
o4: 3.7,
|
|
14
|
+
// GLM models: ~2.5 chars/token (mixed CJK/English tokenizer)
|
|
15
|
+
glm: 2.5,
|
|
16
|
+
// Moonshot/Kimi: ~2.8 chars/token (multilingual tokenizer)
|
|
17
|
+
kimi: 2.8,
|
|
18
|
+
moonshot: 2.8,
|
|
19
|
+
// MiniMax: ~3.2 chars/token (Anthropic-compatible tokenizer)
|
|
20
|
+
minimax: 3.2,
|
|
21
|
+
// Xiaomi MiMo: ~3.7 chars/token (OpenAI-compatible tokenizer)
|
|
22
|
+
mimo: 3.7,
|
|
23
|
+
};
|
|
24
|
+
/** Default ratio when model family is unknown */
|
|
25
|
+
const DEFAULT_CHARS_PER_TOKEN = 3.5;
|
|
26
|
+
const PER_MESSAGE_OVERHEAD = 4; // tokens
|
|
27
|
+
/** EMA smoothing factor for authoritative-usage calibration observations. */
|
|
28
|
+
const CALIBRATION_ALPHA = 0.3;
|
|
29
|
+
/** Plausibility bounds for chars-per-token; absorbs tokenizer and content skew. */
|
|
30
|
+
const CALIBRATION_MIN_RATIO = 2.0;
|
|
31
|
+
const CALIBRATION_MAX_RATIO = 5.0;
|
|
32
|
+
/** Active model name, set via setEstimatorModel(). Used to select the right ratio. */
|
|
33
|
+
let activeModel = "";
|
|
34
|
+
/** Session-observed chars-per-token ratio, blended from provider usage reports. */
|
|
35
|
+
let calibratedRatio = null;
|
|
36
|
+
/**
|
|
37
|
+
* Set the active model name for token estimation.
|
|
38
|
+
* Call this when the model changes so estimates use the correct ratio.
|
|
39
|
+
* Switching models resets usage-based calibration (different tokenizer).
|
|
40
|
+
*/
|
|
41
|
+
export function setEstimatorModel(model) {
|
|
42
|
+
if (model !== activeModel)
|
|
43
|
+
calibratedRatio = null;
|
|
44
|
+
activeModel = model;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Feed an authoritative provider usage observation back into the estimator:
|
|
48
|
+
* blends `chars / tokens` into the session ratio via EMA, clamped to sane
|
|
49
|
+
* bounds. Every downstream estimate (compaction trigger, prune budgets)
|
|
50
|
+
* sharpens as real usage data accumulates.
|
|
51
|
+
*/
|
|
52
|
+
export function calibrateEstimator(chars, tokens) {
|
|
53
|
+
if (!Number.isFinite(chars) || !Number.isFinite(tokens) || chars <= 0 || tokens <= 0)
|
|
54
|
+
return;
|
|
55
|
+
const observed = Math.min(CALIBRATION_MAX_RATIO, Math.max(CALIBRATION_MIN_RATIO, chars / tokens));
|
|
56
|
+
const currentRatio = calibratedRatio ?? getModelCharsPerToken();
|
|
57
|
+
calibratedRatio = currentRatio + CALIBRATION_ALPHA * (observed - currentRatio);
|
|
58
|
+
}
|
|
59
|
+
/** Current usage-calibrated chars-per-token ratio, or null before any observation. */
|
|
60
|
+
export function getCalibratedRatio() {
|
|
61
|
+
return calibratedRatio;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Measure the text characters in a message history and whether it contains
|
|
65
|
+
* image/video parts (which inflate tokens-per-char and would skew calibration).
|
|
66
|
+
*/
|
|
67
|
+
export function measureConversationChars(messages) {
|
|
68
|
+
let chars = 0;
|
|
69
|
+
let hasMedia = false;
|
|
70
|
+
for (const msg of messages) {
|
|
71
|
+
if (typeof msg.content === "string") {
|
|
72
|
+
chars += msg.content.length;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (!Array.isArray(msg.content))
|
|
76
|
+
continue;
|
|
77
|
+
for (const part of msg.content) {
|
|
78
|
+
if (part.type === "image" || part.type === "video") {
|
|
79
|
+
hasMedia = true;
|
|
80
|
+
}
|
|
81
|
+
else if (part.type === "tool_call") {
|
|
82
|
+
const serializedArgs = JSON.stringify(part.args);
|
|
83
|
+
chars += part.name.length + (serializedArgs?.length ?? 0);
|
|
84
|
+
}
|
|
85
|
+
else if (part.type === "tool_result") {
|
|
86
|
+
const tr = part;
|
|
87
|
+
if (typeof tr.content === "string") {
|
|
88
|
+
chars += tr.content.length;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
for (const block of tr.content) {
|
|
92
|
+
if (block.type === "text")
|
|
93
|
+
chars += block.text.length;
|
|
94
|
+
else
|
|
95
|
+
hasMedia = true;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else if ("text" in part && typeof part.text === "string") {
|
|
100
|
+
chars += part.text.length;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return { chars, hasMedia };
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Calibrate from a provider usage report anchored to a message history using
|
|
108
|
+
* its authoritative total input tokens (uncached + cache read/write). Skips
|
|
109
|
+
* histories containing image/video parts.
|
|
110
|
+
*/
|
|
111
|
+
export function calibrateEstimatorFromUsage(history, usage,
|
|
112
|
+
/** Characters the provider also counted but `history` lacks — the tool
|
|
113
|
+
* definitions sent with the request. Omitting them biases the ratio low. */
|
|
114
|
+
extraChars = 0) {
|
|
115
|
+
const { chars, hasMedia } = measureConversationChars(history);
|
|
116
|
+
if (hasMedia)
|
|
117
|
+
return;
|
|
118
|
+
const totalInputTokens = usage.inputTokens + (usage.cacheRead ?? 0) + (usage.cacheWrite ?? 0);
|
|
119
|
+
calibrateEstimator(chars + Math.max(0, extraChars), totalInputTokens);
|
|
120
|
+
}
|
|
121
|
+
function getModelCharsPerToken() {
|
|
122
|
+
if (!activeModel)
|
|
123
|
+
return DEFAULT_CHARS_PER_TOKEN;
|
|
124
|
+
const lower = activeModel.toLowerCase();
|
|
125
|
+
for (const [prefix, ratio] of Object.entries(MODEL_FAMILY_RATIOS)) {
|
|
126
|
+
if (lower.startsWith(prefix))
|
|
127
|
+
return ratio;
|
|
128
|
+
}
|
|
129
|
+
return DEFAULT_CHARS_PER_TOKEN;
|
|
130
|
+
}
|
|
131
|
+
function getCharsPerToken() {
|
|
132
|
+
return calibratedRatio ?? getModelCharsPerToken();
|
|
133
|
+
}
|
|
134
|
+
export function estimateTokens(text) {
|
|
135
|
+
return Math.ceil(text.length / getCharsPerToken());
|
|
136
|
+
}
|
|
137
|
+
export function estimateMessageTokens(message) {
|
|
138
|
+
let tokens = PER_MESSAGE_OVERHEAD;
|
|
139
|
+
if (typeof message.content === "string") {
|
|
140
|
+
tokens += estimateTokens(message.content);
|
|
141
|
+
}
|
|
142
|
+
else if (Array.isArray(message.content)) {
|
|
143
|
+
for (const part of message.content) {
|
|
144
|
+
if ("text" in part && typeof part.text === "string") {
|
|
145
|
+
tokens += estimateTokens(part.text);
|
|
146
|
+
}
|
|
147
|
+
else if ("type" in part && part.type === "tool_call") {
|
|
148
|
+
const tc = part;
|
|
149
|
+
tokens += estimateTokens(tc.name);
|
|
150
|
+
tokens += estimateTokens(JSON.stringify(tc.args));
|
|
151
|
+
}
|
|
152
|
+
else if ("type" in part && part.type === "tool_result") {
|
|
153
|
+
const tr = part;
|
|
154
|
+
if (typeof tr.content === "string") {
|
|
155
|
+
tokens += estimateTokens(tr.content);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
for (const block of tr.content) {
|
|
159
|
+
if (block.type === "text") {
|
|
160
|
+
tokens += estimateTokens(block.text);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
// Image: estimate ~1500 tokens per image (Anthropic rough mean)
|
|
164
|
+
tokens += 1500;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return tokens;
|
|
172
|
+
}
|
|
173
|
+
export function estimateConversationTokens(messages) {
|
|
174
|
+
let total = 0;
|
|
175
|
+
for (const msg of messages) {
|
|
176
|
+
total += estimateMessageTokens(msg);
|
|
177
|
+
}
|
|
178
|
+
return total;
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=token-estimator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-estimator.js","sourceRoot":"","sources":["../../../src/core/compaction/token-estimator.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAC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E,CAAC;gBACzD,MAAM,EAAE,GAAG,IAA6B,CAAC;gBACzC,IAAI,OAAO,EAAE,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;oBACnC,MAAM,IAAI,cAAc,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;gBACvC,CAAC;qBAAM,CAAC;oBACN,KAAK,MAAM,KAAK,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;wBAC/B,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;4BAC1B,MAAM,IAAI,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;wBACvC,CAAC;6BAAM,CAAC;4BACN,gEAAgE;4BAChE,MAAM,IAAI,IAAI,CAAC;wBACjB,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,QAAmB;IAC5D,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC3B,KAAK,IAAI,qBAAqB,CAAC,GAAG,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { Message } from "@kenkaiiii/gg-ai";
|
|
2
|
+
/**
|
|
3
|
+
* Cheap context pruning for stale tool payloads (opencode-style, no LLM call).
|
|
4
|
+
*
|
|
5
|
+
* Three signals, one pass:
|
|
6
|
+
* 1. Superseded reads — an old `read` of a file that was re-read later carries
|
|
7
|
+
* zero information; the newest read wins.
|
|
8
|
+
* 2. Old tool-output overflow — walking backwards, the most recent
|
|
9
|
+
* `protectTokens` worth of tool output plus the last `protectToolBatches`
|
|
10
|
+
* provider tool batches are kept verbatim; anything older is stubbed.
|
|
11
|
+
* 3. Large completed tool arguments — old write/edit payloads are capped once
|
|
12
|
+
* their result has returned; the files and tool result are the durable truth.
|
|
13
|
+
*
|
|
14
|
+
* `PROTECTED_TOOLS` output is never pruned: it is behavioural instruction rather
|
|
15
|
+
* than reproducible data, so a "re-run the tool" stub is not recoverable — the
|
|
16
|
+
* agent has no signal that it ever loaded the skill.
|
|
17
|
+
*
|
|
18
|
+
* Tool batches—not human turns—are the protection boundary. Autonomous research
|
|
19
|
+
* can execute dozens of provider/tool cycles for one user prompt; protecting the
|
|
20
|
+
* whole human turn lets reproducible reads refill the context immediately after
|
|
21
|
+
* compaction.
|
|
22
|
+
*
|
|
23
|
+
* Cache stability: pruning mutates history, which invalidates the provider's
|
|
24
|
+
* prompt-cache prefix. To limit churn, nothing is pruned unless at least
|
|
25
|
+
* `minimumTokens` would be freed in one batch. Stubs and compacted arguments are
|
|
26
|
+
* idempotent, so later passes leave the rewritten prefix stable.
|
|
27
|
+
*/
|
|
28
|
+
export declare const PRUNE_PROTECT_TOKENS = 40000;
|
|
29
|
+
export declare const PRUNE_MINIMUM_TOKENS = 20000;
|
|
30
|
+
export declare const PRUNE_PROTECT_TOOL_BATCHES = 2;
|
|
31
|
+
/**
|
|
32
|
+
* Pruning starts once the active context reaches this share of the compaction
|
|
33
|
+
* trigger. Below it the rewrite costs more than it saves: each prune re-sends
|
|
34
|
+
* the whole history after the first stub uncached (a live goal paid ~70–100k
|
|
35
|
+
* tokens per prune to free ~20k at 117k of a 1M window), and freed tokens only
|
|
36
|
+
* matter once compaction is near.
|
|
37
|
+
*/
|
|
38
|
+
export declare const PRUNE_START_FRACTION = 0.5;
|
|
39
|
+
/** Whether stale tool output is worth pruning at this context size. */
|
|
40
|
+
export declare function shouldPruneToolResults(activeTokens: number, compactionTarget: number): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* With a warm prompt cache, a prune must free at least this share of the active
|
|
43
|
+
* context: pruning rewrites everything after the first stub, so freeing ~20k on a
|
|
44
|
+
* ~430k context re-caches ~430k tokens for a ~5% gain (a live session paid 5.6M
|
|
45
|
+
* cache-write tokens over 13 such prunes). A cold/expired cache is re-read in
|
|
46
|
+
* full anyway, so then the flat {@link PRUNE_MINIMUM_TOKENS} floor applies.
|
|
47
|
+
*
|
|
48
|
+
* Raised from 0.2: 40 prunes in five days of logs cost ~6.4M uncached tokens,
|
|
49
|
+
* many freeing 41–56k right at that floor only 5–10 minutes apart, which is too
|
|
50
|
+
* few turns to pay back a full rewrite.
|
|
51
|
+
*/
|
|
52
|
+
export declare const PRUNE_WARM_MIN_SHARE = 0.35;
|
|
53
|
+
/**
|
|
54
|
+
* From this share of the compaction trigger up, the flat floor applies even on
|
|
55
|
+
* a warm cache: compaction rewrites the whole prefix too, so a small prune that
|
|
56
|
+
* prevents it is the cheaper of the two.
|
|
57
|
+
*/
|
|
58
|
+
export declare const PRUNE_NEAR_TRIGGER_FRACTION = 0.9;
|
|
59
|
+
/** Minimum freed tokens that make a prune worth its cache rewrite. */
|
|
60
|
+
export declare function pruneMinimumTokens(activeTokens: number, cacheCold: boolean, compactionTarget: number): number;
|
|
61
|
+
/** Tools whose output is instruction, not reproducible data — never pruned. */
|
|
62
|
+
export declare const PRUNE_PROTECTED_TOOLS: Set<string>;
|
|
63
|
+
export interface PruneOptions {
|
|
64
|
+
/** Recent tool-output token budget kept verbatim. Default 40k. */
|
|
65
|
+
protectTokens?: number;
|
|
66
|
+
/** Minimum freed tokens required to apply a prune batch. Default 20k. */
|
|
67
|
+
minimumTokens?: number;
|
|
68
|
+
/** Number of most-recent provider tool batches never pruned. Default 2. */
|
|
69
|
+
protectToolBatches?: number;
|
|
70
|
+
}
|
|
71
|
+
export interface PruneResult {
|
|
72
|
+
pruned: boolean;
|
|
73
|
+
prunedResults: number;
|
|
74
|
+
compactedToolCalls: number;
|
|
75
|
+
freedTokens: number;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The newest user/tool message that no later prune can change, or undefined
|
|
79
|
+
* when nothing has been pruned for size yet. A prune pass stops scanning at the
|
|
80
|
+
* newest old-output stub (see `PRUNE_OVERFLOW_MARKER`), and stubs, superseded
|
|
81
|
+
* reads and capped tool arguments are only ever applied to results it scanned
|
|
82
|
+
* (and to the calls of those results), so every later pass edits strictly newer
|
|
83
|
+
* messages than the one before that stub's tool-call message. Hosts mark it as
|
|
84
|
+
* a cache anchor (`Message.cacheAnchor`) so the next prune re-sends only what
|
|
85
|
+
* follows it.
|
|
86
|
+
*/
|
|
87
|
+
export declare function stablePrefixEnd(messages: Message[]): Message | undefined;
|
|
88
|
+
/** Mutates `messages` in place; message/array identity is preserved so usage
|
|
89
|
+
* anchors and React refs stay valid. Returns what was freed. */
|
|
90
|
+
export declare function pruneStaleToolResults(messages: Message[], opts?: PruneOptions): PruneResult;
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { compactHistoricalToolCallArgs } from "./compactor.js";
|
|
2
|
+
import { estimateTokens } from "./token-estimator.js";
|
|
3
|
+
/**
|
|
4
|
+
* Cheap context pruning for stale tool payloads (opencode-style, no LLM call).
|
|
5
|
+
*
|
|
6
|
+
* Three signals, one pass:
|
|
7
|
+
* 1. Superseded reads — an old `read` of a file that was re-read later carries
|
|
8
|
+
* zero information; the newest read wins.
|
|
9
|
+
* 2. Old tool-output overflow — walking backwards, the most recent
|
|
10
|
+
* `protectTokens` worth of tool output plus the last `protectToolBatches`
|
|
11
|
+
* provider tool batches are kept verbatim; anything older is stubbed.
|
|
12
|
+
* 3. Large completed tool arguments — old write/edit payloads are capped once
|
|
13
|
+
* their result has returned; the files and tool result are the durable truth.
|
|
14
|
+
*
|
|
15
|
+
* `PROTECTED_TOOLS` output is never pruned: it is behavioural instruction rather
|
|
16
|
+
* than reproducible data, so a "re-run the tool" stub is not recoverable — the
|
|
17
|
+
* agent has no signal that it ever loaded the skill.
|
|
18
|
+
*
|
|
19
|
+
* Tool batches—not human turns—are the protection boundary. Autonomous research
|
|
20
|
+
* can execute dozens of provider/tool cycles for one user prompt; protecting the
|
|
21
|
+
* whole human turn lets reproducible reads refill the context immediately after
|
|
22
|
+
* compaction.
|
|
23
|
+
*
|
|
24
|
+
* Cache stability: pruning mutates history, which invalidates the provider's
|
|
25
|
+
* prompt-cache prefix. To limit churn, nothing is pruned unless at least
|
|
26
|
+
* `minimumTokens` would be freed in one batch. Stubs and compacted arguments are
|
|
27
|
+
* idempotent, so later passes leave the rewritten prefix stable.
|
|
28
|
+
*/
|
|
29
|
+
export const PRUNE_PROTECT_TOKENS = 40_000;
|
|
30
|
+
export const PRUNE_MINIMUM_TOKENS = 20_000;
|
|
31
|
+
export const PRUNE_PROTECT_TOOL_BATCHES = 2;
|
|
32
|
+
/**
|
|
33
|
+
* Pruning starts once the active context reaches this share of the compaction
|
|
34
|
+
* trigger. Below it the rewrite costs more than it saves: each prune re-sends
|
|
35
|
+
* the whole history after the first stub uncached (a live goal paid ~70–100k
|
|
36
|
+
* tokens per prune to free ~20k at 117k of a 1M window), and freed tokens only
|
|
37
|
+
* matter once compaction is near.
|
|
38
|
+
*/
|
|
39
|
+
export const PRUNE_START_FRACTION = 0.5;
|
|
40
|
+
/** Whether stale tool output is worth pruning at this context size. */
|
|
41
|
+
export function shouldPruneToolResults(activeTokens, compactionTarget) {
|
|
42
|
+
return activeTokens >= compactionTarget * PRUNE_START_FRACTION;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* With a warm prompt cache, a prune must free at least this share of the active
|
|
46
|
+
* context: pruning rewrites everything after the first stub, so freeing ~20k on a
|
|
47
|
+
* ~430k context re-caches ~430k tokens for a ~5% gain (a live session paid 5.6M
|
|
48
|
+
* cache-write tokens over 13 such prunes). A cold/expired cache is re-read in
|
|
49
|
+
* full anyway, so then the flat {@link PRUNE_MINIMUM_TOKENS} floor applies.
|
|
50
|
+
*
|
|
51
|
+
* Raised from 0.2: 40 prunes in five days of logs cost ~6.4M uncached tokens,
|
|
52
|
+
* many freeing 41–56k right at that floor only 5–10 minutes apart, which is too
|
|
53
|
+
* few turns to pay back a full rewrite.
|
|
54
|
+
*/
|
|
55
|
+
export const PRUNE_WARM_MIN_SHARE = 0.35;
|
|
56
|
+
/**
|
|
57
|
+
* From this share of the compaction trigger up, the flat floor applies even on
|
|
58
|
+
* a warm cache: compaction rewrites the whole prefix too, so a small prune that
|
|
59
|
+
* prevents it is the cheaper of the two.
|
|
60
|
+
*/
|
|
61
|
+
export const PRUNE_NEAR_TRIGGER_FRACTION = 0.9;
|
|
62
|
+
/** Minimum freed tokens that make a prune worth its cache rewrite. */
|
|
63
|
+
export function pruneMinimumTokens(activeTokens, cacheCold, compactionTarget) {
|
|
64
|
+
if (cacheCold || activeTokens >= compactionTarget * PRUNE_NEAR_TRIGGER_FRACTION) {
|
|
65
|
+
return PRUNE_MINIMUM_TOKENS;
|
|
66
|
+
}
|
|
67
|
+
return Math.max(PRUNE_MINIMUM_TOKENS, Math.ceil(activeTokens * PRUNE_WARM_MIN_SHARE));
|
|
68
|
+
}
|
|
69
|
+
/** Tools whose output is instruction, not reproducible data — never pruned. */
|
|
70
|
+
export const PRUNE_PROTECTED_TOOLS = new Set(["skill"]);
|
|
71
|
+
const PRUNE_MARKER = "[Pruned:";
|
|
72
|
+
/**
|
|
73
|
+
* Prefix of the token-overflow stub specifically. Reaching one of these while
|
|
74
|
+
* walking backwards proves the whole older prefix was already considered, which
|
|
75
|
+
* a superseded-read stub does NOT prove — read dedup fires independently of the
|
|
76
|
+
* token budget, so an older verbatim result can sit behind one.
|
|
77
|
+
*/
|
|
78
|
+
const PRUNE_OVERFLOW_MARKER = `${PRUNE_MARKER} old tool output`;
|
|
79
|
+
/**
|
|
80
|
+
* The newest user/tool message that no later prune can change, or undefined
|
|
81
|
+
* when nothing has been pruned for size yet. A prune pass stops scanning at the
|
|
82
|
+
* newest old-output stub (see `PRUNE_OVERFLOW_MARKER`), and stubs, superseded
|
|
83
|
+
* reads and capped tool arguments are only ever applied to results it scanned
|
|
84
|
+
* (and to the calls of those results), so every later pass edits strictly newer
|
|
85
|
+
* messages than the one before that stub's tool-call message. Hosts mark it as
|
|
86
|
+
* a cache anchor (`Message.cacheAnchor`) so the next prune re-sends only what
|
|
87
|
+
* follows it.
|
|
88
|
+
*/
|
|
89
|
+
export function stablePrefixEnd(messages) {
|
|
90
|
+
let stub = messages.length;
|
|
91
|
+
while (--stub >= 0) {
|
|
92
|
+
const msg = messages[stub];
|
|
93
|
+
if (msg?.role === "tool" &&
|
|
94
|
+
msg.content.some((r) => typeof r.content === "string" && r.content.startsWith(PRUNE_OVERFLOW_MARKER))) {
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
for (let i = stub - 1; i >= 0; i--) {
|
|
99
|
+
const msg = messages[i];
|
|
100
|
+
if (msg?.role === "user" || msg?.role === "tool")
|
|
101
|
+
return msg;
|
|
102
|
+
}
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
/** Mutates `messages` in place; message/array identity is preserved so usage
|
|
106
|
+
* anchors and React refs stay valid. Returns what was freed. */
|
|
107
|
+
export function pruneStaleToolResults(messages, opts = {}) {
|
|
108
|
+
const protectTokens = opts.protectTokens ?? PRUNE_PROTECT_TOKENS;
|
|
109
|
+
const minimumTokens = opts.minimumTokens ?? PRUNE_MINIMUM_TOKENS;
|
|
110
|
+
const protectToolBatches = opts.protectToolBatches ?? PRUNE_PROTECT_TOOL_BATCHES;
|
|
111
|
+
// toolCallId → tool name + args (for read-dedup path identification).
|
|
112
|
+
const callInfo = new Map();
|
|
113
|
+
for (const msg of messages) {
|
|
114
|
+
if (msg.role !== "assistant" || !Array.isArray(msg.content))
|
|
115
|
+
continue;
|
|
116
|
+
for (const part of msg.content) {
|
|
117
|
+
if (part.type === "tool_call") {
|
|
118
|
+
callInfo.set(part.id, { name: part.name, args: part.args });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const seenReadPaths = new Set();
|
|
123
|
+
const resultCandidates = [];
|
|
124
|
+
const toolBatchByCallId = new Map();
|
|
125
|
+
let recentToolBatches = 0;
|
|
126
|
+
let recentToolTokens = 0;
|
|
127
|
+
scan: for (let msgIndex = messages.length - 1; msgIndex >= 0; msgIndex--) {
|
|
128
|
+
const msg = messages[msgIndex];
|
|
129
|
+
if (msg.role !== "tool" || !Array.isArray(msg.content))
|
|
130
|
+
continue;
|
|
131
|
+
recentToolBatches++;
|
|
132
|
+
const protectedBatch = recentToolBatches <= protectToolBatches;
|
|
133
|
+
for (let partIndex = msg.content.length - 1; partIndex >= 0; partIndex--) {
|
|
134
|
+
const result = msg.content[partIndex];
|
|
135
|
+
if (result.type !== "tool_result")
|
|
136
|
+
continue;
|
|
137
|
+
toolBatchByCallId.set(result.toolCallId, recentToolBatches);
|
|
138
|
+
if (typeof result.content !== "string")
|
|
139
|
+
continue;
|
|
140
|
+
// An overflow stub outside the protect zone means an earlier pass blew
|
|
141
|
+
// the token budget here and pruned every prunable result older than it in
|
|
142
|
+
// that same batch. History only grows at the tail, so nothing older can
|
|
143
|
+
// have become prunable since: stop instead of re-scanning the whole
|
|
144
|
+
// transcript every turn. Other stub kinds prove nothing about what lies
|
|
145
|
+
// behind them, so they are merely skipped.
|
|
146
|
+
if (result.content.startsWith(PRUNE_MARKER)) {
|
|
147
|
+
if (!protectedBatch && result.content.startsWith(PRUNE_OVERFLOW_MARKER))
|
|
148
|
+
break scan;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
const info = callInfo.get(result.toolCallId);
|
|
152
|
+
if (info && PRUNE_PROTECTED_TOOLS.has(info.name))
|
|
153
|
+
continue;
|
|
154
|
+
// Dedup key includes the range: a partial read (offset/limit) covers
|
|
155
|
+
// different content than a full read or another range, so only an
|
|
156
|
+
// identical path+range read supersedes an older one.
|
|
157
|
+
const readPath = info?.name === "read" && typeof info.args.file_path === "string"
|
|
158
|
+
? info.args.file_path
|
|
159
|
+
: undefined;
|
|
160
|
+
const readKey = readPath !== undefined
|
|
161
|
+
? `${readPath}#${String(info?.args.offset ?? "")}:${String(info?.args.limit ?? "")}`
|
|
162
|
+
: undefined;
|
|
163
|
+
// Newest read of each path+range wins — remember it even inside the
|
|
164
|
+
// protect zone so an older duplicate outside the zone still counts as
|
|
165
|
+
// superseded.
|
|
166
|
+
if (readKey !== undefined) {
|
|
167
|
+
if (seenReadPaths.has(readKey) && !protectedBatch) {
|
|
168
|
+
resultCandidates.push({
|
|
169
|
+
result,
|
|
170
|
+
freedTokens: estimateTokens(result.content),
|
|
171
|
+
stub: `${PRUNE_MARKER} this read of ${readPath} was superseded by a newer read later in the conversation.]`,
|
|
172
|
+
});
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
seenReadPaths.add(readKey);
|
|
176
|
+
}
|
|
177
|
+
if (protectedBatch)
|
|
178
|
+
continue;
|
|
179
|
+
const resultTokens = estimateTokens(result.content);
|
|
180
|
+
recentToolTokens += resultTokens;
|
|
181
|
+
if (recentToolTokens <= protectTokens)
|
|
182
|
+
continue;
|
|
183
|
+
resultCandidates.push({
|
|
184
|
+
result,
|
|
185
|
+
freedTokens: resultTokens,
|
|
186
|
+
stub: `${PRUNE_MARKER} old tool output (${result.content.length} chars) removed to save ` +
|
|
187
|
+
`context. Re-run the tool if this content is needed again.]`,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// Completed write/edit-style calls can carry entire files in their arguments.
|
|
192
|
+
// Once outside the protected batches, cap those payloads before they alone can
|
|
193
|
+
// trigger an LLM compaction. Unresolved calls are deliberately left untouched.
|
|
194
|
+
const toolArgCandidates = [];
|
|
195
|
+
for (const message of messages) {
|
|
196
|
+
if (message.role !== "assistant" || !Array.isArray(message.content))
|
|
197
|
+
continue;
|
|
198
|
+
const compactedMessage = compactHistoricalToolCallArgs([message], (toolCallId) => {
|
|
199
|
+
const batch = toolBatchByCallId.get(toolCallId);
|
|
200
|
+
return batch !== undefined && batch > protectToolBatches;
|
|
201
|
+
})[0];
|
|
202
|
+
if (compactedMessage === message)
|
|
203
|
+
continue;
|
|
204
|
+
const originalContent = message.content;
|
|
205
|
+
const compactedContent = compactedMessage.content;
|
|
206
|
+
const originalTokens = estimateTokens(JSON.stringify(originalContent));
|
|
207
|
+
const compactedTokens = estimateTokens(JSON.stringify(compactedContent));
|
|
208
|
+
const compactedToolCalls = compactedContent.filter((part, index) => part !== originalContent[index]).length;
|
|
209
|
+
toolArgCandidates.push({
|
|
210
|
+
message,
|
|
211
|
+
content: compactedMessage.content,
|
|
212
|
+
compactedToolCalls,
|
|
213
|
+
freedTokens: Math.max(0, originalTokens - compactedTokens),
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
const freedTokens = [...resultCandidates, ...toolArgCandidates].reduce((sum, candidate) => sum + candidate.freedTokens, 0);
|
|
217
|
+
if (freedTokens < minimumTokens) {
|
|
218
|
+
return {
|
|
219
|
+
pruned: false,
|
|
220
|
+
prunedResults: 0,
|
|
221
|
+
compactedToolCalls: 0,
|
|
222
|
+
freedTokens: 0,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
for (const candidate of resultCandidates) {
|
|
226
|
+
candidate.result.content = candidate.stub;
|
|
227
|
+
}
|
|
228
|
+
for (const candidate of toolArgCandidates) {
|
|
229
|
+
candidate.message.content = candidate.content;
|
|
230
|
+
}
|
|
231
|
+
return {
|
|
232
|
+
pruned: true,
|
|
233
|
+
prunedResults: resultCandidates.length,
|
|
234
|
+
compactedToolCalls: toolArgCandidates.reduce((sum, candidate) => sum + candidate.compactedToolCalls, 0),
|
|
235
|
+
freedTokens,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=tool-result-pruner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-result-pruner.js","sourceRoot":"","sources":["../../../src/core/compaction/tool-result-pruner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,MAA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24 @@
|
|
|
1
|
+
import type { AgentEvent } from "@kenkaiiii/gg-agent";
|
|
2
|
+
import type { ImageContent, ThinkingLevel } from "@kenkaiiii/gg-ai";
|
|
3
|
+
export interface CompletionReviewRequest {
|
|
4
|
+
instruction: string;
|
|
5
|
+
context: string;
|
|
6
|
+
images: ImageContent[];
|
|
7
|
+
}
|
|
8
|
+
export interface CompletionReviewResponse {
|
|
9
|
+
text: string;
|
|
10
|
+
model: string;
|
|
11
|
+
provider: string;
|
|
12
|
+
thinking: ThinkingLevel | undefined;
|
|
13
|
+
}
|
|
14
|
+
export type CompletionReviewer = (request: CompletionReviewRequest, signal: AbortSignal) => Promise<CompletionReviewResponse>;
|
|
15
|
+
/** Optional host policy. No default policy: ordinary Coder/chat sessions are unchanged. */
|
|
16
|
+
export interface CompletionReview {
|
|
17
|
+
readonly armed: boolean;
|
|
18
|
+
begin(request: string): void;
|
|
19
|
+
track(event: AgentEvent): Promise<void>;
|
|
20
|
+
followUp(review: CompletionReviewer, signal?: AbortSignal): Promise<string | null>;
|
|
21
|
+
snapshot(): unknown;
|
|
22
|
+
restore(data: unknown): void;
|
|
23
|
+
}
|
|
24
|
+
export declare const COMPLETION_REVIEW_STATE_KIND = "completion-review-v1";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"completion-review.js","sourceRoot":"","sources":["../../src/core/completion-review.ts"],"names":[],"mappings":"AA2BA,MAAM,CAAC,MAAM,4BAA4B,GAAG,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A child's brief with files its parent already read appended, so the child
|
|
3
|
+
* starts with their current contents instead of spending turns reading them
|
|
4
|
+
* again. Paths resolve against the child's folder. A file that's missing,
|
|
5
|
+
* binary or past the limits is named with the reason, never fatal: the child
|
|
6
|
+
* can still read it itself. Returns the brief unchanged when there are none.
|
|
7
|
+
*/
|
|
8
|
+
export declare function withContextFiles(task: string, files: readonly string[], cwd: string): Promise<string>;
|