@bastani/atomic 0.9.8 → 0.9.9-alpha.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 +36 -0
- package/dist/builtin/cursor/CHANGELOG.md +12 -0
- package/dist/builtin/cursor/package.json +3 -3
- package/dist/builtin/intercom/CHANGELOG.md +13 -0
- package/dist/builtin/intercom/package.json +3 -3
- package/dist/builtin/mcp/CHANGELOG.md +13 -0
- package/dist/builtin/mcp/package.json +4 -4
- package/dist/builtin/subagents/CHANGELOG.md +13 -0
- package/dist/builtin/subagents/package.json +5 -5
- package/dist/builtin/subagents/src/runs/background/async-execution-chain.ts +2 -0
- package/dist/builtin/subagents/src/runs/background/async-execution-common.ts +7 -1
- package/dist/builtin/subagents/src/runs/background/async-execution-single.ts +2 -0
- package/dist/builtin/subagents/src/runs/background/async-execution-types.ts +8 -2
- package/dist/builtin/subagents/src/runs/foreground/chain-execution-parallel-runner.ts +2 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-execution-sequential-step.ts +2 -0
- package/dist/builtin/subagents/src/runs/foreground/execution-attempt.ts +2 -1
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-async.ts +2 -0
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-parallel-task.ts +2 -0
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-resume.ts +2 -0
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-single.ts +2 -0
- package/dist/builtin/subagents/src/runs/shared/pi-args.ts +6 -0
- package/dist/builtin/subagents/src/shared/types-config.ts +4 -0
- package/dist/builtin/subagents/src/shared/types-depth.ts +29 -2
- package/dist/builtin/web-access/CHANGELOG.md +13 -0
- package/dist/builtin/web-access/package.json +3 -3
- package/dist/builtin/web-access/web-search-tool.ts +1 -2
- package/dist/builtin/workflows/CHANGELOG.md +29 -0
- package/dist/builtin/workflows/README.md +17 -8
- package/dist/builtin/workflows/builtin/goal-prompts.ts +8 -2
- package/dist/builtin/workflows/builtin/open-claude-design-utils.ts +26 -9
- package/dist/builtin/workflows/builtin/ralph-forked-prompts.ts +1 -1
- package/dist/builtin/workflows/builtin/ralph-reviewer-prompt.ts +8 -3
- package/dist/builtin/workflows/builtin/ralph-runner.ts +2 -0
- package/dist/builtin/workflows/builtin/shared-prompts.ts +24 -1
- package/dist/builtin/workflows/package.json +3 -3
- package/dist/builtin/workflows/src/durable/backend.ts +53 -15
- package/dist/builtin/workflows/src/durable/completed-catalog.ts +245 -0
- package/dist/builtin/workflows/src/durable/completed-inspection.ts +213 -0
- package/dist/builtin/workflows/src/durable/dbos-backend.ts +120 -170
- package/dist/builtin/workflows/src/durable/dbos-envelope.ts +84 -8
- package/dist/builtin/workflows/src/durable/dbos-metadata.ts +98 -0
- package/dist/builtin/workflows/src/durable/dbos-tombstone.ts +27 -0
- package/dist/builtin/workflows/src/durable/factory.ts +1 -1
- package/dist/builtin/workflows/src/durable/file-backend.ts +247 -241
- package/dist/builtin/workflows/src/durable/file-lock.ts +153 -0
- package/dist/builtin/workflows/src/durable/file-state.ts +104 -0
- package/dist/builtin/workflows/src/durable/format-version.ts +12 -0
- package/dist/builtin/workflows/src/durable/index.ts +12 -0
- package/dist/builtin/workflows/src/durable/resume-catalog.ts +16 -27
- package/dist/builtin/workflows/src/durable/resume-eligibility.ts +20 -0
- package/dist/builtin/workflows/src/durable/resume-runtime.ts +29 -29
- package/dist/builtin/workflows/src/durable/scoped-backend.ts +20 -3
- package/dist/builtin/workflows/src/durable/stage-primitive.ts +29 -8
- package/dist/builtin/workflows/src/durable/types.ts +3 -0
- package/dist/builtin/workflows/src/engine/primitives/task.ts +1 -0
- package/dist/builtin/workflows/src/engine/run.ts +14 -14
- package/dist/builtin/workflows/src/extension/extension-lifecycle.ts +39 -9
- package/dist/builtin/workflows/src/extension/extension-runtime-state.ts +10 -0
- package/dist/builtin/workflows/src/extension/runtime-durable-resume.ts +133 -0
- package/dist/builtin/workflows/src/extension/runtime.ts +15 -40
- package/dist/builtin/workflows/src/extension/wiring.ts +9 -6
- package/dist/builtin/workflows/src/extension/workflow-durable-resume-command.ts +226 -0
- package/dist/builtin/workflows/src/extension/workflow-prompts.ts +1 -0
- package/dist/builtin/workflows/src/extension/workflow-run-control-command.ts +66 -112
- package/dist/builtin/workflows/src/extension/workflow-schema.ts +5 -5
- package/dist/builtin/workflows/src/extension/workflow-tool-control.ts +16 -1
- package/dist/builtin/workflows/src/runs/foreground/executor-direct-helpers.ts +50 -43
- package/dist/builtin/workflows/src/runs/foreground/executor-direct-output.ts +91 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-direct.ts +95 -46
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-call.ts +3 -1
- package/dist/builtin/workflows/src/runs/foreground/executor-task-prompts.ts +1 -1
- package/dist/builtin/workflows/src/runs/foreground/executor-types.ts +3 -0
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-controller.ts +1 -1
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-options.ts +36 -7
- package/dist/builtin/workflows/src/runs/shared/worktree-cache-lifecycle.ts +25 -0
- package/dist/builtin/workflows/src/runs/shared/worktree-cwd.ts +103 -0
- package/dist/builtin/workflows/src/runs/shared/worktree-generation.ts +57 -0
- package/dist/builtin/workflows/src/runs/shared/worktree-git.ts +134 -8
- package/dist/builtin/workflows/src/runs/shared/worktree.ts +2 -0
- package/dist/builtin/workflows/src/shared/resumable-workflow-notices.ts +43 -0
- package/dist/builtin/workflows/src/shared/serializable.ts +1 -1
- package/dist/builtin/workflows/src/shared/timing.ts +4 -0
- package/dist/builtin/workflows/src/shared/types.ts +5 -3
- package/dist/builtin/workflows/src/tui/graph-view-constants.ts +1 -0
- package/dist/builtin/workflows/src/tui/graph-view-input.ts +24 -14
- package/dist/builtin/workflows/src/tui/workflow-resume-selector.ts +43 -13
- package/dist/bun/cli.d.ts.map +1 -1
- package/dist/bun/internal-intercom-broker.d.ts.map +1 -1
- package/dist/bun/register-bedrock.d.ts.map +1 -1
- package/dist/bun/restore-sandbox-env.d.ts.map +1 -1
- package/dist/bun/split-loader.d.ts.map +1 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/config-selector.d.ts.map +1 -1
- package/dist/cli/file-processor.d.ts.map +1 -1
- package/dist/cli/initial-message.d.ts.map +1 -1
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/project-trust.d.ts.map +1 -1
- package/dist/cli/session-picker.d.ts.map +1 -1
- package/dist/cli/startup-ui.d.ts.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/config-self-update.d.ts.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/core/agent-session-accessors.d.ts.map +1 -1
- package/dist/core/agent-session-auto-compaction.d.ts.map +1 -1
- package/dist/core/agent-session-auto-compaction.js +5 -7
- package/dist/core/agent-session-auto-compaction.js.map +1 -1
- package/dist/core/agent-session-bash.d.ts.map +1 -1
- package/dist/core/agent-session-compaction.d.ts +6 -34
- package/dist/core/agent-session-compaction.d.ts.map +1 -1
- package/dist/core/agent-session-compaction.js +95 -233
- package/dist/core/agent-session-compaction.js.map +1 -1
- package/dist/core/agent-session-events.d.ts.map +1 -1
- package/dist/core/agent-session-export.d.ts.map +1 -1
- package/dist/core/agent-session-extension-bindings.d.ts.map +1 -1
- package/dist/core/agent-session-message-queue.d.ts +0 -4
- package/dist/core/agent-session-message-queue.d.ts.map +1 -1
- package/dist/core/agent-session-message-queue.js +1 -5
- package/dist/core/agent-session-message-queue.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +5 -6
- package/dist/core/agent-session-methods.d.ts.map +1 -1
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session-models.d.ts.map +1 -1
- package/dist/core/agent-session-prompt.d.ts.map +1 -1
- package/dist/core/agent-session-retry.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-skill-block.d.ts.map +1 -1
- package/dist/core/agent-session-state.d.ts.map +1 -1
- package/dist/core/agent-session-tool-hooks.d.ts.map +1 -1
- package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
- package/dist/core/agent-session-tree.d.ts.map +1 -1
- package/dist/core/agent-session-types.d.ts +2 -12
- package/dist/core/agent-session-types.d.ts.map +1 -1
- package/dist/core/agent-session-types.js.map +1 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/anthropic-thinking-guard.d.ts.map +1 -1
- package/dist/core/async/format.d.ts.map +1 -1
- package/dist/core/async/job-manager.d.ts.map +1 -1
- package/dist/core/async/session-manager.d.ts.map +1 -1
- package/dist/core/async/types.d.ts.map +1 -1
- package/dist/core/atomic-guide-command.d.ts.map +1 -1
- package/dist/core/auth-guidance.d.ts.map +1 -1
- package/dist/core/auth-storage-backends.d.ts.map +1 -1
- package/dist/core/auth-storage.d.ts +4 -0
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/builtin-packages.d.ts.map +1 -1
- package/dist/core/codex-fast-mode.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.d.ts +1 -1
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +1 -2
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction-boundary.d.ts +9 -0
- package/dist/core/compaction/compaction-boundary.d.ts.map +1 -0
- package/dist/core/compaction/compaction-boundary.js +115 -0
- package/dist/core/compaction/compaction-boundary.js.map +1 -0
- package/dist/core/compaction/compaction-parameters.d.ts +5 -0
- package/dist/core/compaction/compaction-parameters.d.ts.map +1 -0
- package/dist/core/compaction/compaction-parameters.js +27 -0
- package/dist/core/compaction/compaction-parameters.js.map +1 -0
- package/dist/core/compaction/compaction-runner.d.ts +14 -0
- package/dist/core/compaction/compaction-runner.d.ts.map +1 -0
- package/dist/core/compaction/compaction-runner.js +29 -0
- package/dist/core/compaction/compaction-runner.js.map +1 -0
- package/dist/core/compaction/compaction-types.d.ts +79 -0
- package/dist/core/compaction/compaction-types.d.ts.map +1 -0
- package/dist/core/compaction/compaction-types.js +6 -0
- package/dist/core/compaction/compaction-types.js.map +1 -0
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/deleted-ranges.d.ts +6 -0
- package/dist/core/compaction/deleted-ranges.d.ts.map +1 -0
- package/dist/core/compaction/deleted-ranges.js +134 -0
- package/dist/core/compaction/deleted-ranges.js.map +1 -0
- package/dist/core/compaction/index.d.ts +7 -1
- package/dist/core/compaction/index.d.ts.map +1 -1
- package/dist/core/compaction/index.js +7 -1
- package/dist/core/compaction/index.js.map +1 -1
- package/dist/core/compaction/range-planner.d.ts +21 -0
- package/dist/core/compaction/range-planner.d.ts.map +1 -0
- package/dist/core/compaction/range-planner.js +145 -0
- package/dist/core/compaction/range-planner.js.map +1 -0
- package/dist/core/compaction/transcript-serialization.d.ts +11 -0
- package/dist/core/compaction/transcript-serialization.d.ts.map +1 -0
- package/dist/core/compaction/transcript-serialization.js +104 -0
- package/dist/core/compaction/transcript-serialization.js.map +1 -0
- package/dist/core/compaction/utils.d.ts.map +1 -1
- package/dist/core/context-window.d.ts.map +1 -1
- package/dist/core/copilot-anthropic-sse-repair.d.ts.map +1 -1
- package/dist/core/copilot-errors.d.ts.map +1 -1
- package/dist/core/copilot-gemini-payload-sanitizer.d.ts.map +1 -1
- package/dist/core/copilot-gemini-reasoning.d.ts.map +1 -1
- package/dist/core/copilot-gemini-tool-arguments.d.ts.map +1 -1
- package/dist/core/copilot-hosts.d.ts.map +1 -1
- package/dist/core/copilot-model-catalog.d.ts.map +1 -1
- package/dist/core/copilot-model-static-fallbacks.d.ts.map +1 -1
- package/dist/core/copilot-model-synthesis.d.ts.map +1 -1
- package/dist/core/defaults.d.ts.map +1 -1
- package/dist/core/diagnostics.d.ts.map +1 -1
- package/dist/core/event-bus.d.ts.map +1 -1
- package/dist/core/exec.d.ts.map +1 -1
- package/dist/core/experimental.d.ts.map +1 -1
- package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
- package/dist/core/export-html/index.d.ts.map +1 -1
- package/dist/core/export-html/template-script.d.ts.map +1 -1
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
- package/dist/core/extensions/agent-events.d.ts.map +1 -1
- package/dist/core/extensions/api-types.d.ts.map +1 -1
- package/dist/core/extensions/command-types.d.ts.map +1 -1
- package/dist/core/extensions/context-types.d.ts +2 -2
- package/dist/core/extensions/context-types.d.ts.map +1 -1
- package/dist/core/extensions/context-types.js.map +1 -1
- package/dist/core/extensions/event-results.d.ts +2 -2
- package/dist/core/extensions/event-results.d.ts.map +1 -1
- package/dist/core/extensions/event-results.js.map +1 -1
- package/dist/core/extensions/event-types.d.ts.map +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/loader-api.d.ts.map +1 -1
- package/dist/core/extensions/loader-core.d.ts.map +1 -1
- package/dist/core/extensions/loader-discovery.d.ts.map +1 -1
- package/dist/core/extensions/loader-resources.d.ts.map +1 -1
- package/dist/core/extensions/loader-runtime.d.ts.map +1 -1
- package/dist/core/extensions/loader-virtual-modules.d.ts.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/message-types.d.ts.map +1 -1
- package/dist/core/extensions/provider-types.d.ts.map +1 -1
- package/dist/core/extensions/reactive-widget.d.ts.map +1 -1
- package/dist/core/extensions/runner-context.d.ts.map +1 -1
- package/dist/core/extensions/runner-events.d.ts.map +1 -1
- package/dist/core/extensions/runner-handlers.d.ts.map +1 -1
- package/dist/core/extensions/runner-project-trust.d.ts.map +1 -1
- package/dist/core/extensions/runner-registries.d.ts.map +1 -1
- package/dist/core/extensions/runner-shortcuts.d.ts.map +1 -1
- package/dist/core/extensions/runner-ui.d.ts.map +1 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runtime-types.d.ts.map +1 -1
- package/dist/core/extensions/session-events.d.ts +7 -7
- package/dist/core/extensions/session-events.d.ts.map +1 -1
- package/dist/core/extensions/session-events.js.map +1 -1
- package/dist/core/extensions/tool-events.d.ts.map +1 -1
- package/dist/core/extensions/tool-types.d.ts.map +1 -1
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/ui-types.d.ts.map +1 -1
- package/dist/core/extensions/wrapper.d.ts.map +1 -1
- package/dist/core/flattened-tool-arguments.d.ts.map +1 -1
- package/dist/core/footer-data-provider.d.ts.map +1 -1
- package/dist/core/http-dispatcher.d.ts.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/messages.d.ts +4 -0
- package/dist/core/messages.d.ts.map +1 -1
- package/dist/core/messages.js +11 -0
- package/dist/core/messages.js.map +1 -1
- package/dist/core/model-registry-auth.d.ts.map +1 -1
- package/dist/core/model-registry-builtins.d.ts.map +1 -1
- package/dist/core/model-registry-builtins.js.map +1 -1
- package/dist/core/model-registry-custom-loader.d.ts.map +1 -1
- package/dist/core/model-registry-custom-loader.js.map +1 -1
- package/dist/core/model-registry-dynamic.d.ts.map +1 -1
- package/dist/core/model-registry-loader.d.ts.map +1 -1
- package/dist/core/model-registry-schemas.d.ts +65 -13
- package/dist/core/model-registry-schemas.d.ts.map +1 -1
- package/dist/core/model-registry-schemas.js +5 -1
- package/dist/core/model-registry-schemas.js.map +1 -1
- package/dist/core/model-registry-types.d.ts.map +1 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-resolver-cli.d.ts.map +1 -1
- package/dist/core/model-resolver-defaults.d.ts.map +1 -1
- package/dist/core/model-resolver-initial.d.ts.map +1 -1
- package/dist/core/model-resolver-patterns.d.ts.map +1 -1
- package/dist/core/model-resolver-scope.d.ts.map +1 -1
- package/dist/core/model-resolver-types.d.ts.map +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/openai-responses-payload-sanitizer.d.ts.map +1 -1
- package/dist/core/output-guard.d.ts.map +1 -1
- package/dist/core/package-manager-auto-resources.d.ts.map +1 -1
- package/dist/core/package-manager-command.d.ts.map +1 -1
- package/dist/core/package-manager-constants.d.ts.map +1 -1
- package/dist/core/package-manager-env.d.ts.map +1 -1
- package/dist/core/package-manager-git.d.ts.map +1 -1
- package/dist/core/package-manager-manifest.d.ts.map +1 -1
- package/dist/core/package-manager-npm.d.ts.map +1 -1
- package/dist/core/package-manager-operations.d.ts.map +1 -1
- package/dist/core/package-manager-paths.d.ts.map +1 -1
- package/dist/core/package-manager-progress.d.ts.map +1 -1
- package/dist/core/package-manager-resolver.d.ts.map +1 -1
- package/dist/core/package-manager-resource-accumulator.d.ts.map +1 -1
- package/dist/core/package-manager-resource-collector.d.ts.map +1 -1
- package/dist/core/package-manager-resource-files.d.ts.map +1 -1
- package/dist/core/package-manager-resource-patterns.d.ts.map +1 -1
- package/dist/core/package-manager-settings.d.ts.map +1 -1
- package/dist/core/package-manager-source.d.ts.map +1 -1
- package/dist/core/package-manager-types.d.ts.map +1 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/project-trust.d.ts.map +1 -1
- package/dist/core/prompt-templates-async.d.ts.map +1 -1
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/provider-attribution.d.ts.map +1 -1
- package/dist/core/provider-context-usage.d.ts.map +1 -1
- package/dist/core/provider-context-usage.js +1 -2
- package/dist/core/provider-context-usage.js.map +1 -1
- package/dist/core/provider-display-names.d.ts.map +1 -1
- package/dist/core/resolve-config-value.d.ts.map +1 -1
- package/dist/core/resource-loader-assets.d.ts.map +1 -1
- package/dist/core/resource-loader-context-files.d.ts.map +1 -1
- package/dist/core/resource-loader-core.d.ts.map +1 -1
- package/dist/core/resource-loader-discovery.d.ts.map +1 -1
- package/dist/core/resource-loader-extensions.d.ts.map +1 -1
- package/dist/core/resource-loader-helpers.d.ts.map +1 -1
- package/dist/core/resource-loader-internals.d.ts.map +1 -1
- package/dist/core/resource-loader-package-resources.d.ts.map +1 -1
- package/dist/core/resource-loader-paths.d.ts.map +1 -1
- package/dist/core/resource-loader-reload.d.ts.map +1 -1
- package/dist/core/resource-loader-source-info.d.ts.map +1 -1
- package/dist/core/resource-loader-types.d.ts.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/sdk-exports.d.ts.map +1 -1
- package/dist/core/sdk-types.d.ts.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/session-cwd.d.ts.map +1 -1
- package/dist/core/session-entry-normalization.d.ts.map +1 -1
- package/dist/core/session-manager-archive.d.ts +2 -1
- package/dist/core/session-manager-archive.d.ts.map +1 -1
- package/dist/core/session-manager-archive.js +2 -2
- package/dist/core/session-manager-archive.js.map +1 -1
- package/dist/core/session-manager-classification.d.ts +9 -0
- package/dist/core/session-manager-classification.d.ts.map +1 -0
- package/dist/core/session-manager-classification.js +37 -0
- package/dist/core/session-manager-classification.js.map +1 -0
- package/dist/core/session-manager-core.d.ts +4 -4
- package/dist/core/session-manager-core.d.ts.map +1 -1
- package/dist/core/session-manager-core.js +13 -8
- package/dist/core/session-manager-core.js.map +1 -1
- package/dist/core/session-manager-entries.d.ts +4 -3
- package/dist/core/session-manager-entries.d.ts.map +1 -1
- package/dist/core/session-manager-entries.js +12 -10
- package/dist/core/session-manager-entries.js.map +1 -1
- package/dist/core/session-manager-history.d.ts +6 -23
- package/dist/core/session-manager-history.d.ts.map +1 -1
- package/dist/core/session-manager-history.js +23 -256
- package/dist/core/session-manager-history.js.map +1 -1
- package/dist/core/session-manager-list.d.ts.map +1 -1
- package/dist/core/session-manager-list.js +3 -3
- package/dist/core/session-manager-list.js.map +1 -1
- package/dist/core/session-manager-migrations.d.ts.map +1 -1
- package/dist/core/session-manager-paths.d.ts.map +1 -1
- package/dist/core/session-manager-storage.d.ts +1 -1
- package/dist/core/session-manager-storage.d.ts.map +1 -1
- package/dist/core/session-manager-storage.js +3 -2
- package/dist/core/session-manager-storage.js.map +1 -1
- package/dist/core/session-manager-types.d.ts +14 -15
- package/dist/core/session-manager-types.d.ts.map +1 -1
- package/dist/core/session-manager-types.js.map +1 -1
- package/dist/core/session-manager-validation.d.ts.map +1 -1
- package/dist/core/session-manager.d.ts +3 -2
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +1 -1
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager-basic-accessors.d.ts.map +1 -1
- package/dist/core/settings-manager-core.d.ts.map +1 -1
- package/dist/core/settings-manager-internals.d.ts.map +1 -1
- package/dist/core/settings-manager-resource-accessors.d.ts.map +1 -1
- package/dist/core/settings-manager-ui-accessors.d.ts.map +1 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-merge.d.ts.map +1 -1
- package/dist/core/settings-storage.d.ts.map +1 -1
- package/dist/core/settings-types.d.ts.map +1 -1
- package/dist/core/skills-async.d.ts.map +1 -1
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +1 -1
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/source-info.d.ts.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/telemetry.d.ts.map +1 -1
- package/dist/core/thinking-blocks.d.ts.map +1 -1
- package/dist/core/timings.d.ts.map +1 -1
- package/dist/core/tools/artifact-protocol.d.ts.map +1 -1
- package/dist/core/tools/artifacts.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/ask-user-question.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/config.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/index.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/build-questionnaire.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/inline-input.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/key-router.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/questionnaire-session.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/row-intent.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/selectors/contract.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/selectors/derivations.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/selectors/focus.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/selectors/projections.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/state-reducer.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/state.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/tool/format-answer.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/tool/response-envelope.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/tool/types.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/tool/validate-questionnaire.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/body-residual-spacer.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/component-binding.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/chat-row-view.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/multi-select-view.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/option-list-view.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/markdown-content-cache.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/preview-box-renderer.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/preview-layout-decider.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/preview-pane.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/submit-picker.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/tab-bar.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/wrapping-select.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/dialog-builder.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/props-adapter.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/stateful-view.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/tab-components.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/tab-content-strategy.d.ts.map +1 -1
- package/dist/core/tools/bash-async-execution.d.ts.map +1 -1
- package/dist/core/tools/bash-async-jobs.d.ts.map +1 -1
- package/dist/core/tools/bash-async-output.d.ts.map +1 -1
- package/dist/core/tools/bash-interceptor.d.ts.map +1 -1
- package/dist/core/tools/bash-leading-cd.d.ts.map +1 -1
- package/dist/core/tools/bash-pty-native.d.ts.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/block-resolver.d.ts.map +1 -1
- package/dist/core/tools/conflict-registry.d.ts.map +1 -1
- package/dist/core/tools/directory-tree.d.ts.map +1 -1
- package/dist/core/tools/edit-diff-preserve.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/fetch-url.d.ts.map +1 -1
- package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/glob-path-utils.d.ts.map +1 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/hashline-engine/apply.d.ts.map +1 -1
- package/dist/core/tools/hashline-engine/block.d.ts.map +1 -1
- package/dist/core/tools/hashline-engine/diff-preview.d.ts.map +1 -1
- package/dist/core/tools/hashline-engine/format.d.ts.map +1 -1
- package/dist/core/tools/hashline-engine/fs.d.ts.map +1 -1
- package/dist/core/tools/hashline-engine/index.d.ts.map +1 -1
- package/dist/core/tools/hashline-engine/input.d.ts.map +1 -1
- package/dist/core/tools/hashline-engine/messages.d.ts.map +1 -1
- package/dist/core/tools/hashline-engine/mismatch.d.ts.map +1 -1
- package/dist/core/tools/hashline-engine/normalize.d.ts.map +1 -1
- package/dist/core/tools/hashline-engine/parser.d.ts.map +1 -1
- package/dist/core/tools/hashline-engine/patcher.d.ts.map +1 -1
- package/dist/core/tools/hashline-engine/prefixes.d.ts.map +1 -1
- package/dist/core/tools/hashline-engine/recovery.d.ts.map +1 -1
- package/dist/core/tools/hashline-engine/snapshots.d.ts.map +1 -1
- package/dist/core/tools/hashline-engine/stream.d.ts.map +1 -1
- package/dist/core/tools/hashline-engine/tokenizer.d.ts.map +1 -1
- package/dist/core/tools/hashline-engine/types.d.ts.map +1 -1
- package/dist/core/tools/hashline.d.ts.map +1 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/notebook.d.ts.map +1 -1
- package/dist/core/tools/output-accumulator.d.ts.map +1 -1
- package/dist/core/tools/oversized-tool-result.d.ts.map +1 -1
- package/dist/core/tools/path-utils.d.ts.map +1 -1
- package/dist/core/tools/read-document-extract.d.ts.map +1 -1
- package/dist/core/tools/read-selectors.d.ts.map +1 -1
- package/dist/core/tools/read-url.d.ts.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/resource-selectors.d.ts.map +1 -1
- package/dist/core/tools/search-details.d.ts.map +1 -1
- package/dist/core/tools/search-line-ranges.d.ts.map +1 -1
- package/dist/core/tools/search-native.d.ts.map +1 -1
- package/dist/core/tools/search.d.ts.map +1 -1
- package/dist/core/tools/structured-output.d.ts.map +1 -1
- package/dist/core/tools/todos-execute.d.ts.map +1 -1
- package/dist/core/tools/todos-locks.d.ts.map +1 -1
- package/dist/core/tools/todos-model.d.ts.map +1 -1
- package/dist/core/tools/todos-mutations.d.ts.map +1 -1
- package/dist/core/tools/todos-paths.d.ts.map +1 -1
- package/dist/core/tools/todos-render.d.ts.map +1 -1
- package/dist/core/tools/todos-storage.d.ts.map +1 -1
- package/dist/core/tools/todos-types.d.ts.map +1 -1
- package/dist/core/tools/todos-types.js +1 -1
- package/dist/core/tools/todos-types.js.map +1 -1
- package/dist/core/tools/todos.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.js +6 -2
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
- package/dist/core/tools/tool-limits.d.ts.map +1 -1
- package/dist/core/tools/truncate.d.ts.map +1 -1
- package/dist/core/tools/url-ip-guards.d.ts.map +1 -1
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/typebox-compat.d.ts +12 -0
- package/dist/core/typebox-compat.d.ts.map +1 -0
- package/dist/core/typebox-compat.js +10 -0
- package/dist/core/typebox-compat.js.map +1 -0
- package/dist/index-extensions.d.ts.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/main-app-mode.d.ts.map +1 -1
- package/dist/main-deferred-startup.d.ts.map +1 -1
- package/dist/main-early-input.d.ts.map +1 -1
- package/dist/main-session-options.d.ts.map +1 -1
- package/dist/main-session.d.ts +1 -0
- package/dist/main-session.d.ts.map +1 -1
- package/dist/main-session.js +7 -0
- package/dist/main-session.js.map +1 -1
- package/dist/main-stdio.d.ts.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +2 -2
- package/dist/main.js.map +1 -1
- package/dist/migrations-config-values.d.ts.map +1 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/modes/index.d.ts.map +1 -1
- package/dist/modes/interactive/chat-input-actions.d.ts.map +1 -1
- package/dist/modes/interactive/components/armin.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/atomic-banner.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-message-renderer.d.ts +4 -1
- package/dist/modes/interactive/components/chat-message-renderer.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-message-renderer.js +12 -22
- package/dist/modes/interactive/components/chat-message-renderer.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-actions.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-events.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-events.js +5 -11
- package/dist/modes/interactive/components/chat-session-host-events.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-rendering.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-rendering.js +3 -0
- package/dist/modes/interactive/components/chat-session-host-rendering.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-runtime.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-state.d.ts +1 -0
- package/dist/modes/interactive/components/chat-session-host-state.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-state.js +1 -0
- package/dist/modes/interactive/components/chat-session-host-state.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-terminal-cleanup.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-types.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-utils.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-utils.js +1 -1
- package/dist/modes/interactive/components/chat-session-host-utils.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.js +1 -0
- package/dist/modes/interactive/components/chat-session-host.js.map +1 -1
- package/dist/modes/interactive/components/chat-transcript.d.ts.map +1 -1
- package/dist/modes/interactive/components/compaction-boundary-message.d.ts +20 -0
- package/dist/modes/interactive/components/compaction-boundary-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/compaction-boundary-message.js +48 -0
- package/dist/modes/interactive/components/compaction-boundary-message.js.map +1 -0
- package/dist/modes/interactive/components/config-selector-list.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/context-window-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -1
- package/dist/modes/interactive/components/diff.d.ts.map +1 -1
- package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
- package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/fast-mode-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/index.d.ts +1 -1
- package/dist/modes/interactive/components/index.d.ts.map +1 -1
- package/dist/modes/interactive/components/index.js +1 -1
- package/dist/modes/interactive/components/index.js.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector-delete.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector-header.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector-list.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector-list.js +3 -0
- package/dist/modes/interactive/components/session-selector-list.js.map +1 -1
- package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector-tree.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector-types.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector-utils.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector-handlers.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector-items.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector-options.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector-submenus.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector-types.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector-component.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector-content.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector-help.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector-label-input.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector-list.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector-model.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector-types.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector-viewport.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/trust-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
- package/dist/modes/interactive/components/working-status.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-agent-events.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-agent-events.js +3 -47
- package/dist/modes/interactive/interactive-agent-events.js.map +1 -1
- package/dist/modes/interactive/interactive-auth-login.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-auth-routing.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-autocomplete.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-bash-compact.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-child-ordering.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-deferred-startup.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-editor-actions.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-extension-context.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-extension-custom-ui.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-extension-dialogs.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-extension-runtime.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-extension-widgets.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-hotkeys-debug.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-input-handling.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-deps.d.ts +2 -2
- package/dist/modes/interactive/interactive-mode-deps.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-deps.js +1 -1
- package/dist/modes/interactive/interactive-mode-deps.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-helpers.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.d.ts +5 -3
- package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-types.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-model-routing.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-onboarding.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-process-lifecycle.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-queueing.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-render-chat.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-render-chat.js +21 -12
- package/dist/modes/interactive/interactive-render-chat.js.map +1 -1
- package/dist/modes/interactive/interactive-resource-disclosure.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-resource-paths.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-resource-rendering.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-selectors.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-session-routing.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-session-runtime.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-slash-commands.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-startup.d.ts.map +1 -1
- package/dist/modes/interactive/model-search.d.ts.map +1 -1
- package/dist/modes/interactive/theme/color-utils.d.ts.map +1 -1
- package/dist/modes/interactive/theme/export-colors.d.ts.map +1 -1
- package/dist/modes/interactive/theme/global-theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/terminal-detection.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme-class.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme-loading.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme-parse.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme-schema.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/tui-theme.d.ts.map +1 -1
- package/dist/modes/interactive/whimsical-messages.d.ts.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/rpc/jsonl.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +3 -5
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +1 -6
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.js +0 -4
- package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
- package/dist/modes/rpc/rpc-extension-ui.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-input.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-responses.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-session-binding.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +2 -11
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/package-manager-cli-parser.d.ts.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/rpc-entry.d.ts.map +1 -1
- package/dist/utils/ansi.d.ts.map +1 -1
- package/dist/utils/changelog.d.ts.map +1 -1
- package/dist/utils/child-process.d.ts.map +1 -1
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-native.d.ts.map +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/deprecation.d.ts.map +1 -1
- package/dist/utils/event-loop.d.ts.map +1 -1
- package/dist/utils/exif-orientation.d.ts.map +1 -1
- package/dist/utils/frontmatter.d.ts.map +1 -1
- package/dist/utils/fs-watch.d.ts.map +1 -1
- package/dist/utils/git-env.d.ts.map +1 -1
- package/dist/utils/git.d.ts.map +1 -1
- package/dist/utils/html.d.ts.map +1 -1
- package/dist/utils/image-convert.d.ts.map +1 -1
- package/dist/utils/image-process.d.ts.map +1 -1
- package/dist/utils/image-resize-core.d.ts.map +1 -1
- package/dist/utils/image-resize-worker.d.ts.map +1 -1
- package/dist/utils/image-resize.d.ts.map +1 -1
- package/dist/utils/json.d.ts.map +1 -1
- package/dist/utils/markit.d.ts.map +1 -1
- package/dist/utils/mime.d.ts.map +1 -1
- package/dist/utils/module-require.d.ts.map +1 -1
- package/dist/utils/open-browser.d.ts.map +1 -1
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/photon.d.ts.map +1 -1
- package/dist/utils/pi-user-agent.d.ts.map +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/sleep.d.ts.map +1 -1
- package/dist/utils/split-launcher.d.ts.map +1 -1
- package/dist/utils/syntax-highlight.d.ts.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/windows-self-update.d.ts.map +1 -1
- package/docs/compaction.md +97 -772
- package/docs/custom-provider.md +7 -1
- package/docs/extensions.md +31 -33
- package/docs/json.md +2 -2
- package/docs/rpc.md +32 -24
- package/docs/sdk.md +3 -3
- package/docs/session-format.md +49 -30
- package/docs/sessions.md +5 -3
- package/docs/settings.md +14 -4
- package/docs/usage.md +1 -1
- package/docs/workflows.md +30 -15
- package/examples/extensions/README.md +3 -1
- package/examples/extensions/custom-compaction.ts +14 -58
- package/examples/extensions/handoff.ts +2 -3
- package/examples/extensions/subagent/schemas.ts +1 -1
- package/examples/extensions/tic-tac-toe.ts +1 -2
- package/examples/extensions/todo.ts +1 -2
- package/npm-shrinkwrap.json +214 -98
- package/package.json +12 -12
- package/dist/core/compaction/context-assistant-turns.d.ts +0 -42
- package/dist/core/compaction/context-assistant-turns.d.ts.map +0 -1
- package/dist/core/compaction/context-assistant-turns.js +0 -87
- package/dist/core/compaction/context-assistant-turns.js.map +0 -1
- package/dist/core/compaction/context-compaction-critical.d.ts +0 -15
- package/dist/core/compaction/context-compaction-critical.d.ts.map +0 -1
- package/dist/core/compaction/context-compaction-critical.js +0 -57
- package/dist/core/compaction/context-compaction-critical.js.map +0 -1
- package/dist/core/compaction/context-compaction-eviction-alternates.d.ts +0 -18
- package/dist/core/compaction/context-compaction-eviction-alternates.d.ts.map +0 -1
- package/dist/core/compaction/context-compaction-eviction-alternates.js +0 -186
- package/dist/core/compaction/context-compaction-eviction-alternates.js.map +0 -1
- package/dist/core/compaction/context-compaction-eviction.d.ts +0 -12
- package/dist/core/compaction/context-compaction-eviction.d.ts.map +0 -1
- package/dist/core/compaction/context-compaction-eviction.js +0 -222
- package/dist/core/compaction/context-compaction-eviction.js.map +0 -1
- package/dist/core/compaction/context-compaction-metrics.d.ts +0 -28
- package/dist/core/compaction/context-compaction-metrics.d.ts.map +0 -1
- package/dist/core/compaction/context-compaction-metrics.js +0 -107
- package/dist/core/compaction/context-compaction-metrics.js.map +0 -1
- package/dist/core/compaction/context-compaction-prompt.d.ts +0 -9
- package/dist/core/compaction/context-compaction-prompt.d.ts.map +0 -1
- package/dist/core/compaction/context-compaction-prompt.js +0 -163
- package/dist/core/compaction/context-compaction-prompt.js.map +0 -1
- package/dist/core/compaction/context-compaction-runner.d.ts +0 -11
- package/dist/core/compaction/context-compaction-runner.d.ts.map +0 -1
- package/dist/core/compaction/context-compaction-runner.js +0 -273
- package/dist/core/compaction/context-compaction-runner.js.map +0 -1
- package/dist/core/compaction/context-compaction-strategy.d.ts +0 -5
- package/dist/core/compaction/context-compaction-strategy.d.ts.map +0 -1
- package/dist/core/compaction/context-compaction-strategy.js +0 -27
- package/dist/core/compaction/context-compaction-strategy.js.map +0 -1
- package/dist/core/compaction/context-compaction-types.d.ts +0 -75
- package/dist/core/compaction/context-compaction-types.d.ts.map +0 -1
- package/dist/core/compaction/context-compaction-types.js +0 -6
- package/dist/core/compaction/context-compaction-types.js.map +0 -1
- package/dist/core/compaction/context-compaction.d.ts +0 -10
- package/dist/core/compaction/context-compaction.d.ts.map +0 -1
- package/dist/core/compaction/context-compaction.js +0 -8
- package/dist/core/compaction/context-compaction.js.map +0 -1
- package/dist/core/compaction/context-deletion-application.d.ts +0 -14
- package/dist/core/compaction/context-deletion-application.d.ts.map +0 -1
- package/dist/core/compaction/context-deletion-application.js +0 -261
- package/dist/core/compaction/context-deletion-application.js.map +0 -1
- package/dist/core/compaction/context-deletion-store.d.ts +0 -78
- package/dist/core/compaction/context-deletion-store.d.ts.map +0 -1
- package/dist/core/compaction/context-deletion-store.js +0 -162
- package/dist/core/compaction/context-deletion-store.js.map +0 -1
- package/dist/core/compaction/context-deletion-targets.d.ts +0 -43
- package/dist/core/compaction/context-deletion-targets.d.ts.map +0 -1
- package/dist/core/compaction/context-deletion-targets.js +0 -292
- package/dist/core/compaction/context-deletion-targets.js.map +0 -1
- package/dist/core/compaction/context-deletion-tool-definitions.d.ts +0 -193
- package/dist/core/compaction/context-deletion-tool-definitions.d.ts.map +0 -1
- package/dist/core/compaction/context-deletion-tool-definitions.js +0 -98
- package/dist/core/compaction/context-deletion-tool-definitions.js.map +0 -1
- package/dist/core/compaction/context-deletion-tool-helpers.d.ts +0 -19
- package/dist/core/compaction/context-deletion-tool-helpers.d.ts.map +0 -1
- package/dist/core/compaction/context-deletion-tool-helpers.js +0 -210
- package/dist/core/compaction/context-deletion-tool-helpers.js.map +0 -1
- package/dist/core/compaction/context-deletion-tools.d.ts +0 -4
- package/dist/core/compaction/context-deletion-tools.d.ts.map +0 -1
- package/dist/core/compaction/context-deletion-tools.js +0 -403
- package/dist/core/compaction/context-deletion-tools.js.map +0 -1
- package/dist/core/compaction/context-transcript-analysis.d.ts +0 -11
- package/dist/core/compaction/context-transcript-analysis.d.ts.map +0 -1
- package/dist/core/compaction/context-transcript-analysis.js +0 -228
- package/dist/core/compaction/context-transcript-analysis.js.map +0 -1
- package/dist/core/session-manager-tool-dependencies.d.ts +0 -10
- package/dist/core/session-manager-tool-dependencies.d.ts.map +0 -1
- package/dist/core/session-manager-tool-dependencies.js +0 -133
- package/dist/core/session-manager-tool-dependencies.js.map +0 -1
- package/dist/modes/interactive/components/context-compaction-summary-message.d.ts +0 -17
- package/dist/modes/interactive/components/context-compaction-summary-message.d.ts.map +0 -1
- package/dist/modes/interactive/components/context-compaction-summary-message.js +0 -83
- package/dist/modes/interactive/components/context-compaction-summary-message.js.map +0 -1
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
import { relaxTranscriptForCriticalEviction } from "./context-compaction-critical.js";
|
|
2
|
-
import { alternateBoundaryPlan, assistantTurnsForTargets, currentHistoricalSignedGroups, hasFitBudget, repairSignedTurnTargets, skippedBoundaryRestorationGroups, targetsWithGroup, tryGroup, validateTargets, } from "./context-compaction-eviction-alternates.js";
|
|
3
|
-
import { transcriptEntryStartsNewTurn } from "./context-assistant-turns.js";
|
|
4
|
-
import { canDeleteTarget, getDeletedEntryIds } from "./context-deletion-targets.js";
|
|
5
|
-
function terminalDeterministicEvictionError(reason, lastValidated, tokenBudget) {
|
|
6
|
-
const statsText = lastValidated
|
|
7
|
-
? `achieved tokensAfter=${lastValidated.stats.tokensAfter}, reduction=${lastValidated.stats.percentReduction}%, deletionTargets=${lastValidated.deletedTargets.length}`
|
|
8
|
-
: "achieved no validated deletion targets";
|
|
9
|
-
return new Error(`Context deterministic overflow eviction failed: ${reason}; ${statsText}; budget=${tokenBudget}; nothing more was safely deletable`);
|
|
10
|
-
}
|
|
11
|
-
function initialEvictionGroups(transcript) {
|
|
12
|
-
const turns = assistantTurnsForTargets(transcript, []);
|
|
13
|
-
const signedGroupByEntryId = new Map();
|
|
14
|
-
const activeSignedIds = new Set();
|
|
15
|
-
for (const turn of turns) {
|
|
16
|
-
if (turn.active) {
|
|
17
|
-
for (const entryId of turn.signedThinkingEntryIds)
|
|
18
|
-
activeSignedIds.add(entryId);
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
21
|
-
for (const entryId of turn.signedThinkingEntryIds) {
|
|
22
|
-
signedGroupByEntryId.set(entryId, turn.signedThinkingEntryIds);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
const entryById = new Map(transcript.entries.map((entry, index) => [entry.entryId, { entry, index }]));
|
|
26
|
-
const grouped = new Set();
|
|
27
|
-
const groups = [];
|
|
28
|
-
for (let index = 0; index < transcript.entries.length; index++) {
|
|
29
|
-
const entry = transcript.entries[index];
|
|
30
|
-
if (activeSignedIds.has(entry.entryId) || grouped.has(entry.entryId))
|
|
31
|
-
continue;
|
|
32
|
-
const entryIds = signedGroupByEntryId.get(entry.entryId) ?? [entry.entryId];
|
|
33
|
-
for (const entryId of entryIds)
|
|
34
|
-
grouped.add(entryId);
|
|
35
|
-
if (!entryIds.every((entryId) => canDeleteTarget(transcript, { kind: "entry", entryId })))
|
|
36
|
-
continue;
|
|
37
|
-
groups.push({
|
|
38
|
-
entryIds: [...entryIds],
|
|
39
|
-
order: index,
|
|
40
|
-
tokens: entryIds.reduce((sum, entryId) => sum + (entryById.get(entryId)?.entry.tokenEstimate ?? 0), 0),
|
|
41
|
-
boundary: entryIds.length === 1 && transcriptEntryStartsNewTurn(entry),
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
return groups;
|
|
45
|
-
}
|
|
46
|
-
function repairedFittingBoundaryPrefix(transcript, planned, groups, tokenBudget, currentTokens) {
|
|
47
|
-
const required = currentTokens - tokenBudget;
|
|
48
|
-
if (required <= 0)
|
|
49
|
-
return undefined;
|
|
50
|
-
let rawRemoved = 0;
|
|
51
|
-
let lowerBound = 0;
|
|
52
|
-
while (lowerBound < groups.length && rawRemoved < required) {
|
|
53
|
-
rawRemoved += groups[lowerBound].tokens;
|
|
54
|
-
lowerBound += 1;
|
|
55
|
-
}
|
|
56
|
-
if (rawRemoved < required)
|
|
57
|
-
return undefined;
|
|
58
|
-
let prospective = [...planned];
|
|
59
|
-
for (let index = 0; index < groups.length; index++) {
|
|
60
|
-
prospective = targetsWithGroup(prospective, groups[index].entryIds);
|
|
61
|
-
if (index + 1 < lowerBound)
|
|
62
|
-
continue;
|
|
63
|
-
const repaired = repairSignedTurnTargets(transcript, prospective);
|
|
64
|
-
const validated = validateTargets(transcript, repaired);
|
|
65
|
-
if (!validated || !hasFitBudget(validated, tokenBudget))
|
|
66
|
-
continue;
|
|
67
|
-
const deleted = getDeletedEntryIds(validated.deletedTargets);
|
|
68
|
-
const prefixRetained = groups
|
|
69
|
-
.slice(0, index + 1)
|
|
70
|
-
.some((group) => group.entryIds.some((entryId) => !deleted.has(entryId)));
|
|
71
|
-
if (!prefixRetained)
|
|
72
|
-
return validated;
|
|
73
|
-
}
|
|
74
|
-
return undefined;
|
|
75
|
-
}
|
|
76
|
-
function adoptSmallestFittingPrefix(transcript, planned, groups, tokenBudget) {
|
|
77
|
-
if (groups.length === 0)
|
|
78
|
-
return undefined;
|
|
79
|
-
const prefixTargets = (count) => groups.slice(0, count).reduce((targets, group) => targetsWithGroup(targets, group.entryIds), [...planned]);
|
|
80
|
-
const full = validateTargets(transcript, prefixTargets(groups.length));
|
|
81
|
-
if (!full)
|
|
82
|
-
return undefined;
|
|
83
|
-
if (!hasFitBudget(full, tokenBudget))
|
|
84
|
-
return full;
|
|
85
|
-
let low = 1;
|
|
86
|
-
let high = groups.length;
|
|
87
|
-
let best = full;
|
|
88
|
-
while (low <= high) {
|
|
89
|
-
const middle = Math.floor((low + high) / 2);
|
|
90
|
-
const result = validateTargets(transcript, prefixTargets(middle));
|
|
91
|
-
if (result && hasFitBudget(result, tokenBudget)) {
|
|
92
|
-
best = result;
|
|
93
|
-
high = middle - 1;
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
low = middle + 1;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return best;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Finite deterministic eviction phases:
|
|
103
|
-
* 1. Batch or sweep non-boundary groups in transcript order.
|
|
104
|
-
* 2. Try repaired boundary prefixes, then individual boundaries by token value.
|
|
105
|
-
* 3. Sweep newly historical signed groups exposed by those deletions.
|
|
106
|
-
* 4. Retry skipped boundaries by shared restoration component, then individually.
|
|
107
|
-
* 5. Search bounded alternate boundary states (at most 16 per boundary) and their signed groups.
|
|
108
|
-
* 6. Fail with the best validated stats after every finite candidate set is exhausted.
|
|
109
|
-
*/
|
|
110
|
-
export function runDeterministicContextEviction(transcript, tokenBudget) {
|
|
111
|
-
const relaxed = relaxTranscriptForCriticalEviction(transcript);
|
|
112
|
-
const groups = initialEvictionGroups(relaxed);
|
|
113
|
-
const nonBoundaries = groups.filter((group) => !group.boundary).sort((left, right) => left.order - right.order);
|
|
114
|
-
const boundaries = groups
|
|
115
|
-
.filter((group) => group.boundary)
|
|
116
|
-
.sort((left, right) => right.tokens - left.tokens || left.order - right.order);
|
|
117
|
-
let planned = [];
|
|
118
|
-
let lastValidated;
|
|
119
|
-
const skippedBoundaries = [];
|
|
120
|
-
if (relaxed.tokensBefore > tokenBudget) {
|
|
121
|
-
const batch = adoptSmallestFittingPrefix(relaxed, planned, nonBoundaries, tokenBudget);
|
|
122
|
-
if (batch) {
|
|
123
|
-
planned = [...batch.deletedTargets];
|
|
124
|
-
lastValidated = batch;
|
|
125
|
-
if (hasFitBudget(lastValidated, tokenBudget))
|
|
126
|
-
return lastValidated;
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
for (const group of nonBoundaries) {
|
|
130
|
-
const result = tryGroup(relaxed, planned, group, false);
|
|
131
|
-
if (!result)
|
|
132
|
-
continue;
|
|
133
|
-
planned = [...result.deletedTargets];
|
|
134
|
-
lastValidated = result;
|
|
135
|
-
if (hasFitBudget(lastValidated, tokenBudget))
|
|
136
|
-
return lastValidated;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
for (const group of nonBoundaries) {
|
|
142
|
-
const result = tryGroup(relaxed, planned, group, false);
|
|
143
|
-
if (!result)
|
|
144
|
-
continue;
|
|
145
|
-
return result;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
const boundaryBaseTargets = [...planned];
|
|
149
|
-
const boundaryBaseResult = lastValidated;
|
|
150
|
-
const boundaryBatch = repairedFittingBoundaryPrefix(relaxed, planned, boundaries, tokenBudget, lastValidated?.stats.tokensAfter ?? relaxed.tokensBefore);
|
|
151
|
-
if (boundaryBatch) {
|
|
152
|
-
const standalone = boundaries[0] ? tryGroup(relaxed, [], boundaries[0], true) : undefined;
|
|
153
|
-
return standalone && hasFitBudget(standalone, tokenBudget) && standalone.stats.tokensAfter > boundaryBatch.stats.tokensAfter
|
|
154
|
-
? standalone
|
|
155
|
-
: boundaryBatch;
|
|
156
|
-
}
|
|
157
|
-
for (const group of boundaries) {
|
|
158
|
-
const result = tryGroup(relaxed, planned, group, true);
|
|
159
|
-
if (!result || (lastValidated && result.stats.tokensAfter >= lastValidated.stats.tokensAfter)) {
|
|
160
|
-
skippedBoundaries.push(group);
|
|
161
|
-
continue;
|
|
162
|
-
}
|
|
163
|
-
planned = [...result.deletedTargets];
|
|
164
|
-
lastValidated = result;
|
|
165
|
-
if (hasFitBudget(lastValidated, tokenBudget)) {
|
|
166
|
-
const standalone = tryGroup(relaxed, [], group, true);
|
|
167
|
-
return standalone && hasFitBudget(standalone, tokenBudget) && standalone.stats.tokensAfter > result.stats.tokensAfter
|
|
168
|
-
? standalone
|
|
169
|
-
: result;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
for (const group of currentHistoricalSignedGroups(relaxed, planned)) {
|
|
173
|
-
const result = tryGroup(relaxed, planned, group, false);
|
|
174
|
-
if (!result)
|
|
175
|
-
continue;
|
|
176
|
-
planned = [...result.deletedTargets];
|
|
177
|
-
lastValidated = result;
|
|
178
|
-
if (hasFitBudget(lastValidated, tokenBudget))
|
|
179
|
-
return lastValidated;
|
|
180
|
-
}
|
|
181
|
-
const groupedRetryIds = new Set();
|
|
182
|
-
for (const component of skippedBoundaryRestorationGroups(relaxed, planned, skippedBoundaries)) {
|
|
183
|
-
const entryIds = component.flatMap((group) => group.entryIds);
|
|
184
|
-
for (const entryId of entryIds)
|
|
185
|
-
groupedRetryIds.add(entryId);
|
|
186
|
-
const combined = {
|
|
187
|
-
entryIds,
|
|
188
|
-
order: Math.min(...component.map((group) => group.order)),
|
|
189
|
-
tokens: component.reduce((sum, group) => sum + group.tokens, 0),
|
|
190
|
-
boundary: true,
|
|
191
|
-
};
|
|
192
|
-
const result = tryGroup(relaxed, planned, combined, true);
|
|
193
|
-
if (!result)
|
|
194
|
-
continue;
|
|
195
|
-
const deleted = getDeletedEntryIds(result.deletedTargets);
|
|
196
|
-
if (!entryIds.every((entryId) => deleted.has(entryId)))
|
|
197
|
-
continue;
|
|
198
|
-
if (lastValidated && result.stats.tokensAfter >= lastValidated.stats.tokensAfter && !hasFitBudget(result, tokenBudget)) {
|
|
199
|
-
continue;
|
|
200
|
-
}
|
|
201
|
-
planned = [...result.deletedTargets];
|
|
202
|
-
lastValidated = result;
|
|
203
|
-
if (hasFitBudget(lastValidated, tokenBudget))
|
|
204
|
-
return lastValidated;
|
|
205
|
-
}
|
|
206
|
-
for (const group of skippedBoundaries) {
|
|
207
|
-
if (group.entryIds.some((entryId) => groupedRetryIds.has(entryId)))
|
|
208
|
-
continue;
|
|
209
|
-
const result = tryGroup(relaxed, planned, group, true);
|
|
210
|
-
if (!result || (lastValidated && result.stats.tokensAfter >= lastValidated.stats.tokensAfter))
|
|
211
|
-
continue;
|
|
212
|
-
planned = [...result.deletedTargets];
|
|
213
|
-
lastValidated = result;
|
|
214
|
-
if (hasFitBudget(lastValidated, tokenBudget))
|
|
215
|
-
return lastValidated;
|
|
216
|
-
}
|
|
217
|
-
const alternate = alternateBoundaryPlan(relaxed, boundaryBaseTargets, boundaryBaseResult, boundaries, tokenBudget);
|
|
218
|
-
if (alternate)
|
|
219
|
-
return alternate;
|
|
220
|
-
throw terminalDeterministicEvictionError("candidate sweep exhausted", lastValidated, tokenBudget);
|
|
221
|
-
}
|
|
222
|
-
//# sourceMappingURL=context-compaction-eviction.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context-compaction-eviction.js","sourceRoot":"","sources":["../../../src/core/compaction/context-compaction-eviction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kCAAkC,EAAE,MAAM,kCAAkC,CAAC;AACtF,OAAO,EACN,qBAAqB,EACrB,wBAAwB,EACxB,6BAA6B,EAE7B,YAAY,EACZ,uBAAuB,EACvB,gCAAgC,EAChC,gBAAgB,EAChB,QAAQ,EACR,eAAe,GACf,MAAM,6CA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C,WAAW,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,CAAC;YACxH,SAAS;QACV,CAAC;QACD,OAAO,GAAG,CAAC,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;QACrC,aAAa,GAAG,MAAM,CAAC;QACvB,IAAI,YAAY,CAAC,aAAa,EAAE,WAAW,CAAC;YAAE,OAAO,aAAa,CAAC;IACpE,CAAC;IAED,KAAK,MAAM,KAAK,IAAI,iBAAiB,EAAE,CAAC;QACvC,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAAE,SAAS;QAC7E,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QACvD,IAAI,CAAC,MAAM,IAAI,CAAC,aAAa,IAAI,MAAM,CAAC,KAAK,CAAC,WAAW,IAAI,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC;YAAE,SAAS;QACxG,OAAO,GAAG,CAAC,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;QACrC,aAAa,GAAG,MAAM,CAAC;QACvB,IAAI,YAAY,CAAC,aAAa,EAAE,WAAW,CAAC;YAAE,OAAO,aAAa,CAAC;IACpE,CAAC;IAED,MAAM,SAAS,GAAG,qBAAqB,CACtC,OAAO,EACP,mBAAmB,EACnB,kBAAkB,EAClB,UAAU,EACV,WAAW,CACX,CAAC;IACF,IAAI,SAAS;QAAE,OAAO,SAAS,CAAC;IAEhC,MAAM,kCAAkC,CAAC,2BAA2B,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC;AACnG,CAAC","sourcesContent":["import type { ContextDeletionTarget } from \"../session-manager.js\";\nimport { relaxTranscriptForCriticalEviction } from \"./context-compaction-critical.js\";\nimport {\n\talternateBoundaryPlan,\n\tassistantTurnsForTargets,\n\tcurrentHistoricalSignedGroups,\n\ttype EvictionGroup,\n\thasFitBudget,\n\trepairSignedTurnTargets,\n\tskippedBoundaryRestorationGroups,\n\ttargetsWithGroup,\n\ttryGroup,\n\tvalidateTargets,\n} from \"./context-compaction-eviction-alternates.js\";\nimport type { CompactableTranscript, ValidatedContextDeletionResult } from \"./context-compaction-types.js\";\nimport { transcriptEntryStartsNewTurn } from \"./context-assistant-turns.js\";\nimport { canDeleteTarget, getDeletedEntryIds } from \"./context-deletion-targets.js\";\n\nfunction terminalDeterministicEvictionError(\n\treason: string,\n\tlastValidated: ValidatedContextDeletionResult | undefined,\n\ttokenBudget: number,\n): Error {\n\tconst statsText = lastValidated\n\t\t? `achieved tokensAfter=${lastValidated.stats.tokensAfter}, reduction=${lastValidated.stats.percentReduction}%, deletionTargets=${lastValidated.deletedTargets.length}`\n\t\t: \"achieved no validated deletion targets\";\n\treturn new Error(\n\t\t`Context deterministic overflow eviction failed: ${reason}; ${statsText}; budget=${tokenBudget}; nothing more was safely deletable`,\n\t);\n}\n\nfunction initialEvictionGroups(transcript: CompactableTranscript): EvictionGroup[] {\n\tconst turns = assistantTurnsForTargets(transcript, []);\n\tconst signedGroupByEntryId = new Map<string, string[]>();\n\tconst activeSignedIds = new Set<string>();\n\tfor (const turn of turns) {\n\t\tif (turn.active) {\n\t\t\tfor (const entryId of turn.signedThinkingEntryIds) activeSignedIds.add(entryId);\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const entryId of turn.signedThinkingEntryIds) {\n\t\t\tsignedGroupByEntryId.set(entryId, turn.signedThinkingEntryIds);\n\t\t}\n\t}\n\n\tconst entryById = new Map(transcript.entries.map((entry, index) => [entry.entryId, { entry, index }]));\n\tconst grouped = new Set<string>();\n\tconst groups: EvictionGroup[] = [];\n\tfor (let index = 0; index < transcript.entries.length; index++) {\n\t\tconst entry = transcript.entries[index]!;\n\t\tif (activeSignedIds.has(entry.entryId) || grouped.has(entry.entryId)) continue;\n\t\tconst entryIds = signedGroupByEntryId.get(entry.entryId) ?? [entry.entryId];\n\t\tfor (const entryId of entryIds) grouped.add(entryId);\n\t\tif (!entryIds.every((entryId) => canDeleteTarget(transcript, { kind: \"entry\", entryId }))) continue;\n\t\tgroups.push({\n\t\t\tentryIds: [...entryIds],\n\t\t\torder: index,\n\t\t\ttokens: entryIds.reduce((sum, entryId) => sum + (entryById.get(entryId)?.entry.tokenEstimate ?? 0), 0),\n\t\t\tboundary: entryIds.length === 1 && transcriptEntryStartsNewTurn(entry),\n\t\t});\n\t}\n\treturn groups;\n}\n\nfunction repairedFittingBoundaryPrefix(\n\ttranscript: CompactableTranscript,\n\tplanned: readonly ContextDeletionTarget[],\n\tgroups: readonly EvictionGroup[],\n\ttokenBudget: number,\n\tcurrentTokens: number,\n): ValidatedContextDeletionResult | undefined {\n\tconst required = currentTokens - tokenBudget;\n\tif (required <= 0) return undefined;\n\tlet rawRemoved = 0;\n\tlet lowerBound = 0;\n\twhile (lowerBound < groups.length && rawRemoved < required) {\n\t\trawRemoved += groups[lowerBound]!.tokens;\n\t\tlowerBound += 1;\n\t}\n\tif (rawRemoved < required) return undefined;\n\n\tlet prospective = [...planned];\n\tfor (let index = 0; index < groups.length; index++) {\n\t\tprospective = targetsWithGroup(prospective, groups[index]!.entryIds);\n\t\tif (index + 1 < lowerBound) continue;\n\t\tconst repaired = repairSignedTurnTargets(transcript, prospective);\n\t\tconst validated = validateTargets(transcript, repaired);\n\t\tif (!validated || !hasFitBudget(validated, tokenBudget)) continue;\n\t\tconst deleted = getDeletedEntryIds(validated.deletedTargets);\n\t\tconst prefixRetained = groups\n\t\t\t.slice(0, index + 1)\n\t\t\t.some((group) => group.entryIds.some((entryId) => !deleted.has(entryId)));\n\t\tif (!prefixRetained) return validated;\n\t}\n\treturn undefined;\n}\n\nfunction adoptSmallestFittingPrefix(\n\ttranscript: CompactableTranscript,\n\tplanned: readonly ContextDeletionTarget[],\n\tgroups: readonly EvictionGroup[],\n\ttokenBudget: number,\n): ValidatedContextDeletionResult | undefined {\n\tif (groups.length === 0) return undefined;\n\tconst prefixTargets = (count: number): ContextDeletionTarget[] =>\n\t\tgroups.slice(0, count).reduce((targets, group) => targetsWithGroup(targets, group.entryIds), [...planned]);\n\tconst full = validateTargets(transcript, prefixTargets(groups.length));\n\tif (!full) return undefined;\n\tif (!hasFitBudget(full, tokenBudget)) return full;\n\n\tlet low = 1;\n\tlet high = groups.length;\n\tlet best = full;\n\twhile (low <= high) {\n\t\tconst middle = Math.floor((low + high) / 2);\n\t\tconst result = validateTargets(transcript, prefixTargets(middle));\n\t\tif (result && hasFitBudget(result, tokenBudget)) {\n\t\t\tbest = result;\n\t\t\thigh = middle - 1;\n\t\t} else {\n\t\t\tlow = middle + 1;\n\t\t}\n\t}\n\treturn best;\n}\n\n/**\n * Finite deterministic eviction phases:\n * 1. Batch or sweep non-boundary groups in transcript order.\n * 2. Try repaired boundary prefixes, then individual boundaries by token value.\n * 3. Sweep newly historical signed groups exposed by those deletions.\n * 4. Retry skipped boundaries by shared restoration component, then individually.\n * 5. Search bounded alternate boundary states (at most 16 per boundary) and their signed groups.\n * 6. Fail with the best validated stats after every finite candidate set is exhausted.\n */\nexport function runDeterministicContextEviction(\n\ttranscript: CompactableTranscript,\n\ttokenBudget: number,\n): ValidatedContextDeletionResult {\n\tconst relaxed = relaxTranscriptForCriticalEviction(transcript);\n\tconst groups = initialEvictionGroups(relaxed);\n\tconst nonBoundaries = groups.filter((group) => !group.boundary).sort((left, right) => left.order - right.order);\n\tconst boundaries = groups\n\t\t.filter((group) => group.boundary)\n\t\t.sort((left, right) => right.tokens - left.tokens || left.order - right.order);\n\tlet planned: ContextDeletionTarget[] = [];\n\tlet lastValidated: ValidatedContextDeletionResult | undefined;\n\tconst skippedBoundaries: EvictionGroup[] = [];\n\n\tif (relaxed.tokensBefore > tokenBudget) {\n\t\tconst batch = adoptSmallestFittingPrefix(relaxed, planned, nonBoundaries, tokenBudget);\n\t\tif (batch) {\n\t\t\tplanned = [...batch.deletedTargets];\n\t\t\tlastValidated = batch;\n\t\t\tif (hasFitBudget(lastValidated, tokenBudget)) return lastValidated;\n\t\t} else {\n\t\t\tfor (const group of nonBoundaries) {\n\t\t\t\tconst result = tryGroup(relaxed, planned, group, false);\n\t\t\t\tif (!result) continue;\n\t\t\t\tplanned = [...result.deletedTargets];\n\t\t\t\tlastValidated = result;\n\t\t\t\tif (hasFitBudget(lastValidated, tokenBudget)) return lastValidated;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tfor (const group of nonBoundaries) {\n\t\t\tconst result = tryGroup(relaxed, planned, group, false);\n\t\t\tif (!result) continue;\n\t\t\treturn result;\n\t\t}\n\t}\n\n\tconst boundaryBaseTargets = [...planned];\n\tconst boundaryBaseResult = lastValidated;\n\tconst boundaryBatch = repairedFittingBoundaryPrefix(\n\t\trelaxed,\n\t\tplanned,\n\t\tboundaries,\n\t\ttokenBudget,\n\t\tlastValidated?.stats.tokensAfter ?? relaxed.tokensBefore,\n\t);\n\tif (boundaryBatch) {\n\t\tconst standalone = boundaries[0] ? tryGroup(relaxed, [], boundaries[0], true) : undefined;\n\t\treturn standalone && hasFitBudget(standalone, tokenBudget) && standalone.stats.tokensAfter > boundaryBatch.stats.tokensAfter\n\t\t\t? standalone\n\t\t\t: boundaryBatch;\n\t}\n\n\tfor (const group of boundaries) {\n\t\tconst result = tryGroup(relaxed, planned, group, true);\n\t\tif (!result || (lastValidated && result.stats.tokensAfter >= lastValidated.stats.tokensAfter)) {\n\t\t\tskippedBoundaries.push(group);\n\t\t\tcontinue;\n\t\t}\n\t\tplanned = [...result.deletedTargets];\n\t\tlastValidated = result;\n\t\tif (hasFitBudget(lastValidated, tokenBudget)) {\n\t\t\tconst standalone = tryGroup(relaxed, [], group, true);\n\t\t\treturn standalone && hasFitBudget(standalone, tokenBudget) && standalone.stats.tokensAfter > result.stats.tokensAfter\n\t\t\t\t? standalone\n\t\t\t\t: result;\n\t\t}\n\t}\n\n\tfor (const group of currentHistoricalSignedGroups(relaxed, planned)) {\n\t\tconst result = tryGroup(relaxed, planned, group, false);\n\t\tif (!result) continue;\n\t\tplanned = [...result.deletedTargets];\n\t\tlastValidated = result;\n\t\tif (hasFitBudget(lastValidated, tokenBudget)) return lastValidated;\n\t}\n\n\tconst groupedRetryIds = new Set<string>();\n\tfor (const component of skippedBoundaryRestorationGroups(relaxed, planned, skippedBoundaries)) {\n\t\tconst entryIds = component.flatMap((group) => group.entryIds);\n\t\tfor (const entryId of entryIds) groupedRetryIds.add(entryId);\n\t\tconst combined: EvictionGroup = {\n\t\t\tentryIds,\n\t\t\torder: Math.min(...component.map((group) => group.order)),\n\t\t\ttokens: component.reduce((sum, group) => sum + group.tokens, 0),\n\t\t\tboundary: true,\n\t\t};\n\t\tconst result = tryGroup(relaxed, planned, combined, true);\n\t\tif (!result) continue;\n\t\tconst deleted = getDeletedEntryIds(result.deletedTargets);\n\t\tif (!entryIds.every((entryId) => deleted.has(entryId))) continue;\n\t\tif (lastValidated && result.stats.tokensAfter >= lastValidated.stats.tokensAfter && !hasFitBudget(result, tokenBudget)) {\n\t\t\tcontinue;\n\t\t}\n\t\tplanned = [...result.deletedTargets];\n\t\tlastValidated = result;\n\t\tif (hasFitBudget(lastValidated, tokenBudget)) return lastValidated;\n\t}\n\n\tfor (const group of skippedBoundaries) {\n\t\tif (group.entryIds.some((entryId) => groupedRetryIds.has(entryId))) continue;\n\t\tconst result = tryGroup(relaxed, planned, group, true);\n\t\tif (!result || (lastValidated && result.stats.tokensAfter >= lastValidated.stats.tokensAfter)) continue;\n\t\tplanned = [...result.deletedTargets];\n\t\tlastValidated = result;\n\t\tif (hasFitBudget(lastValidated, tokenBudget)) return lastValidated;\n\t}\n\n\tconst alternate = alternateBoundaryPlan(\n\t\trelaxed,\n\t\tboundaryBaseTargets,\n\t\tboundaryBaseResult,\n\t\tboundaries,\n\t\ttokenBudget,\n\t);\n\tif (alternate) return alternate;\n\n\tthrow terminalDeterministicEvictionError(\"candidate sweep exhausted\", lastValidated, tokenBudget);\n}\n"]}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { AgentToolResult } from "@earendil-works/pi-agent-core";
|
|
2
|
-
import type { ContextCompactionStats, ContextDeletionTarget } from "../session-manager.ts";
|
|
3
|
-
import type { CompactableTranscript } from "./context-compaction-types.ts";
|
|
4
|
-
import type { ContextCompactionBudgetToolDetails } from "./context-deletion-tool-definitions.ts";
|
|
5
|
-
import type { ContextCompactionParameters, ValidatedContextDeletionResult } from "./context-compaction-types.ts";
|
|
6
|
-
export declare function formatErrorMessage(error: unknown): string;
|
|
7
|
-
export declare function createContextDeletionToolResult<TDetails>(text: string, details: TDetails): AgentToolResult<TDetails>;
|
|
8
|
-
export declare function roundPercent(value: number): number;
|
|
9
|
-
export declare function percentOf(part: number, total: number): number;
|
|
10
|
-
export declare function finitePositiveNumber(value: number | undefined): number | undefined;
|
|
11
|
-
export declare function contextCompactionTargetReductionPercent(parameters: ContextCompactionParameters): number;
|
|
12
|
-
export declare function contextCompactionTargetLabel(parameters: ContextCompactionParameters): string;
|
|
13
|
-
export declare function createContextCompactionBudgetDetails(stats: ContextCompactionStats, callCount: number, contextWindow: number | undefined, parameters: ContextCompactionParameters, remainingImageTokens: number, imageBlockCount: number): ContextCompactionBudgetToolDetails;
|
|
14
|
-
export declare function contextCompactionTargetMet(result: ValidatedContextDeletionResult | undefined, parameters: ContextCompactionParameters): result is ValidatedContextDeletionResult;
|
|
15
|
-
export declare function contextCompactionProgressKey(result: ValidatedContextDeletionResult | undefined): string;
|
|
16
|
-
export declare function contextCompactionProgressPercent(result: ValidatedContextDeletionResult | undefined): number;
|
|
17
|
-
/**
|
|
18
|
-
* Sum the token estimates of image content blocks that remain after applying the
|
|
19
|
-
* current deletion targets. Deleted entries and individually-deleted image blocks
|
|
20
|
-
* are excluded so the budget tool always reflects the live working set.
|
|
21
|
-
*/
|
|
22
|
-
export declare function sumRemainingImageTokens(transcript: CompactableTranscript, targets: readonly ContextDeletionTarget[]): number;
|
|
23
|
-
/**
|
|
24
|
-
* Count the image content blocks that remain after applying the current deletion
|
|
25
|
-
* targets. Deleted entries and individually-deleted image blocks are excluded.
|
|
26
|
-
*/
|
|
27
|
-
export declare function countRemainingImageBlocks(transcript: CompactableTranscript, targets: readonly ContextDeletionTarget[]): number;
|
|
28
|
-
//# sourceMappingURL=context-compaction-metrics.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context-compaction-metrics.d.ts","sourceRoot":"","sources":["../../../src/core/compaction/context-compaction-metrics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,KAAK,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC3F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,wCAAwC,CAAC;AACjG,OAAO,KAAK,EAAE,2BAA2B,EAAE,8BAA8B,EAAE,MAAM,+BAA+B,CAAC;AAGjH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEzD;AAED,wBAAgB,+BAA+B,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,eAAe,CAAC,QAAQ,CAAC,CAEpH;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAElF;AAED,wBAAgB,uCAAuC,CAAC,UAAU,EAAE,2BAA2B,GAAG,MAAM,CAEvG;AAED,wBAAgB,4BAA4B,CAAC,UAAU,EAAE,2BAA2B,GAAG,MAAM,CAE5F;AAED,wBAAgB,oCAAoC,CACnD,KAAK,EAAE,sBAAsB,EAC7B,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,GAAG,SAAS,EACjC,UAAU,EAAE,2BAA2B,EACvC,oBAAoB,EAAE,MAAM,EAC5B,eAAe,EAAE,MAAM,GACrB,kCAAkC,CAyBpC;AAED,wBAAgB,0BAA0B,CACzC,MAAM,EAAE,8BAA8B,GAAG,SAAS,EAClD,UAAU,EAAE,2BAA2B,GACrC,MAAM,IAAI,8BAA8B,CAM1C;AAED,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,8BAA8B,GAAG,SAAS,GAAG,MAAM,CAGvG;AAED,wBAAgB,gCAAgC,CAAC,MAAM,EAAE,8BAA8B,GAAG,SAAS,GAAG,MAAM,CAE3G;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CACtC,UAAU,EAAE,qBAAqB,EACjC,OAAO,EAAE,SAAS,qBAAqB,EAAE,GACvC,MAAM,CAcR;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CACxC,UAAU,EAAE,qBAAqB,EACjC,OAAO,EAAE,SAAS,qBAAqB,EAAE,GACvC,MAAM,CAcR","sourcesContent":["import type { AgentToolResult } from \"@earendil-works/pi-agent-core\";\nimport type { ContextCompactionStats, ContextDeletionTarget } from \"../session-manager.ts\";\nimport type { CompactableTranscript } from \"./context-compaction-types.ts\";\nimport type { ContextCompactionBudgetToolDetails } from \"./context-deletion-tool-definitions.ts\";\nimport type { ContextCompactionParameters, ValidatedContextDeletionResult } from \"./context-compaction-types.ts\";\nimport { getDeletedContentBlocks, getDeletedEntryIds } from \"./context-deletion-targets.ts\";\n\nexport function formatErrorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nexport function createContextDeletionToolResult<TDetails>(text: string, details: TDetails): AgentToolResult<TDetails> {\n\treturn { content: [{ type: \"text\", text }], details, terminate: false };\n}\n\nexport function roundPercent(value: number): number {\n\treturn Math.round(value * 10) / 10;\n}\n\nexport function percentOf(part: number, total: number): number {\n\treturn total > 0 ? roundPercent((part / total) * 100) : 0;\n}\n\nexport function finitePositiveNumber(value: number | undefined): number | undefined {\n\treturn typeof value === \"number\" && Number.isFinite(value) && value > 0 ? value : undefined;\n}\n\nexport function contextCompactionTargetReductionPercent(parameters: ContextCompactionParameters): number {\n\treturn roundPercent((1 - parameters.compression_ratio) * 100);\n}\n\nexport function contextCompactionTargetLabel(parameters: ContextCompactionParameters): string {\n\treturn `${contextCompactionTargetReductionPercent(parameters)}%`;\n}\n\nexport function createContextCompactionBudgetDetails(\n\tstats: ContextCompactionStats,\n\tcallCount: number,\n\tcontextWindow: number | undefined,\n\tparameters: ContextCompactionParameters,\n\tremainingImageTokens: number,\n\timageBlockCount: number,\n): ContextCompactionBudgetToolDetails {\n\tconst targetTokensAfter = Math.max(0, Math.floor(stats.tokensBefore * parameters.compression_ratio));\n\tconst targetReductionPercent = contextCompactionTargetReductionPercent(parameters);\n\tconst details: ContextCompactionBudgetToolDetails = {\n\t\t...(contextWindow !== undefined ? { contextWindow } : {}),\n\t\tcompression_ratio: parameters.compression_ratio,\n\t\ttokensBefore: stats.tokensBefore,\n\t\tcurrentTokensAfter: stats.tokensAfter,\n\t\tdeletedTokens: Math.max(0, stats.tokensBefore - stats.tokensAfter),\n\t\tcurrentReductionPercent: stats.percentReduction,\n\t\ttargetReductionPercent,\n\t\ttargetTokensAfter,\n\t\ttokensToDeleteForTarget: Math.max(0, stats.tokensAfter - targetTokensAfter),\n\t\t...(contextWindow !== undefined\n\t\t\t? {\n\t\t\t\t\tcontextWindowBeforePercent: percentOf(stats.tokensBefore, contextWindow),\n\t\t\t\t\tcontextWindowAfterPercent: percentOf(stats.tokensAfter, contextWindow),\n\t\t\t\t}\n\t\t\t: {}),\n\t\tremainingImageTokens,\n\t\timageBlockCount,\n\t\timageTokenPercent: percentOf(remainingImageTokens, stats.tokensAfter),\n\t\tcallCount,\n\t};\n\treturn details;\n}\n\nexport function contextCompactionTargetMet(\n\tresult: ValidatedContextDeletionResult | undefined,\n\tparameters: ContextCompactionParameters,\n): result is ValidatedContextDeletionResult {\n\treturn (\n\t\tresult !== undefined &&\n\t\tresult.deletedTargets.length > 0 &&\n\t\tresult.stats.percentReduction >= contextCompactionTargetReductionPercent(parameters)\n\t);\n}\n\nexport function contextCompactionProgressKey(result: ValidatedContextDeletionResult | undefined): string {\n\tif (!result) return \"none:0\";\n\treturn `${result.deletedTargets.length}:${result.stats.percentReduction}:${result.stats.tokensAfter}`;\n}\n\nexport function contextCompactionProgressPercent(result: ValidatedContextDeletionResult | undefined): number {\n\treturn result?.stats.percentReduction ?? 0;\n}\n\n/**\n * Sum the token estimates of image content blocks that remain after applying the\n * current deletion targets. Deleted entries and individually-deleted image blocks\n * are excluded so the budget tool always reflects the live working set.\n */\nexport function sumRemainingImageTokens(\n\ttranscript: CompactableTranscript,\n\ttargets: readonly ContextDeletionTarget[],\n): number {\n\tconst deletedEntryIds = getDeletedEntryIds(targets);\n\tconst deletedContentBlocks = getDeletedContentBlocks(targets);\n\tlet imageTokens = 0;\n\tfor (const entry of transcript.entries) {\n\t\tif (deletedEntryIds.has(entry.entryId)) continue;\n\t\tconst deletedBlocks = deletedContentBlocks.get(entry.entryId);\n\t\tfor (const block of entry.contentBlocks) {\n\t\t\tif (block.type !== \"image\") continue;\n\t\t\tif (deletedBlocks?.has(block.blockIndex)) continue;\n\t\t\timageTokens += block.tokenEstimate;\n\t\t}\n\t}\n\treturn imageTokens;\n}\n\n/**\n * Count the image content blocks that remain after applying the current deletion\n * targets. Deleted entries and individually-deleted image blocks are excluded.\n */\nexport function countRemainingImageBlocks(\n\ttranscript: CompactableTranscript,\n\ttargets: readonly ContextDeletionTarget[],\n): number {\n\tconst deletedEntryIds = getDeletedEntryIds(targets);\n\tconst deletedContentBlocks = getDeletedContentBlocks(targets);\n\tlet count = 0;\n\tfor (const entry of transcript.entries) {\n\t\tif (deletedEntryIds.has(entry.entryId)) continue;\n\t\tconst deletedBlocks = deletedContentBlocks.get(entry.entryId);\n\t\tfor (const block of entry.contentBlocks) {\n\t\t\tif (block.type !== \"image\") continue;\n\t\t\tif (deletedBlocks?.has(block.blockIndex)) continue;\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn count;\n}\n"]}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { getDeletedContentBlocks, getDeletedEntryIds } from "./context-deletion-targets.js";
|
|
2
|
-
export function formatErrorMessage(error) {
|
|
3
|
-
return error instanceof Error ? error.message : String(error);
|
|
4
|
-
}
|
|
5
|
-
export function createContextDeletionToolResult(text, details) {
|
|
6
|
-
return { content: [{ type: "text", text }], details, terminate: false };
|
|
7
|
-
}
|
|
8
|
-
export function roundPercent(value) {
|
|
9
|
-
return Math.round(value * 10) / 10;
|
|
10
|
-
}
|
|
11
|
-
export function percentOf(part, total) {
|
|
12
|
-
return total > 0 ? roundPercent((part / total) * 100) : 0;
|
|
13
|
-
}
|
|
14
|
-
export function finitePositiveNumber(value) {
|
|
15
|
-
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : undefined;
|
|
16
|
-
}
|
|
17
|
-
export function contextCompactionTargetReductionPercent(parameters) {
|
|
18
|
-
return roundPercent((1 - parameters.compression_ratio) * 100);
|
|
19
|
-
}
|
|
20
|
-
export function contextCompactionTargetLabel(parameters) {
|
|
21
|
-
return `${contextCompactionTargetReductionPercent(parameters)}%`;
|
|
22
|
-
}
|
|
23
|
-
export function createContextCompactionBudgetDetails(stats, callCount, contextWindow, parameters, remainingImageTokens, imageBlockCount) {
|
|
24
|
-
const targetTokensAfter = Math.max(0, Math.floor(stats.tokensBefore * parameters.compression_ratio));
|
|
25
|
-
const targetReductionPercent = contextCompactionTargetReductionPercent(parameters);
|
|
26
|
-
const details = {
|
|
27
|
-
...(contextWindow !== undefined ? { contextWindow } : {}),
|
|
28
|
-
compression_ratio: parameters.compression_ratio,
|
|
29
|
-
tokensBefore: stats.tokensBefore,
|
|
30
|
-
currentTokensAfter: stats.tokensAfter,
|
|
31
|
-
deletedTokens: Math.max(0, stats.tokensBefore - stats.tokensAfter),
|
|
32
|
-
currentReductionPercent: stats.percentReduction,
|
|
33
|
-
targetReductionPercent,
|
|
34
|
-
targetTokensAfter,
|
|
35
|
-
tokensToDeleteForTarget: Math.max(0, stats.tokensAfter - targetTokensAfter),
|
|
36
|
-
...(contextWindow !== undefined
|
|
37
|
-
? {
|
|
38
|
-
contextWindowBeforePercent: percentOf(stats.tokensBefore, contextWindow),
|
|
39
|
-
contextWindowAfterPercent: percentOf(stats.tokensAfter, contextWindow),
|
|
40
|
-
}
|
|
41
|
-
: {}),
|
|
42
|
-
remainingImageTokens,
|
|
43
|
-
imageBlockCount,
|
|
44
|
-
imageTokenPercent: percentOf(remainingImageTokens, stats.tokensAfter),
|
|
45
|
-
callCount,
|
|
46
|
-
};
|
|
47
|
-
return details;
|
|
48
|
-
}
|
|
49
|
-
export function contextCompactionTargetMet(result, parameters) {
|
|
50
|
-
return (result !== undefined &&
|
|
51
|
-
result.deletedTargets.length > 0 &&
|
|
52
|
-
result.stats.percentReduction >= contextCompactionTargetReductionPercent(parameters));
|
|
53
|
-
}
|
|
54
|
-
export function contextCompactionProgressKey(result) {
|
|
55
|
-
if (!result)
|
|
56
|
-
return "none:0";
|
|
57
|
-
return `${result.deletedTargets.length}:${result.stats.percentReduction}:${result.stats.tokensAfter}`;
|
|
58
|
-
}
|
|
59
|
-
export function contextCompactionProgressPercent(result) {
|
|
60
|
-
return result?.stats.percentReduction ?? 0;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Sum the token estimates of image content blocks that remain after applying the
|
|
64
|
-
* current deletion targets. Deleted entries and individually-deleted image blocks
|
|
65
|
-
* are excluded so the budget tool always reflects the live working set.
|
|
66
|
-
*/
|
|
67
|
-
export function sumRemainingImageTokens(transcript, targets) {
|
|
68
|
-
const deletedEntryIds = getDeletedEntryIds(targets);
|
|
69
|
-
const deletedContentBlocks = getDeletedContentBlocks(targets);
|
|
70
|
-
let imageTokens = 0;
|
|
71
|
-
for (const entry of transcript.entries) {
|
|
72
|
-
if (deletedEntryIds.has(entry.entryId))
|
|
73
|
-
continue;
|
|
74
|
-
const deletedBlocks = deletedContentBlocks.get(entry.entryId);
|
|
75
|
-
for (const block of entry.contentBlocks) {
|
|
76
|
-
if (block.type !== "image")
|
|
77
|
-
continue;
|
|
78
|
-
if (deletedBlocks?.has(block.blockIndex))
|
|
79
|
-
continue;
|
|
80
|
-
imageTokens += block.tokenEstimate;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return imageTokens;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Count the image content blocks that remain after applying the current deletion
|
|
87
|
-
* targets. Deleted entries and individually-deleted image blocks are excluded.
|
|
88
|
-
*/
|
|
89
|
-
export function countRemainingImageBlocks(transcript, targets) {
|
|
90
|
-
const deletedEntryIds = getDeletedEntryIds(targets);
|
|
91
|
-
const deletedContentBlocks = getDeletedContentBlocks(targets);
|
|
92
|
-
let count = 0;
|
|
93
|
-
for (const entry of transcript.entries) {
|
|
94
|
-
if (deletedEntryIds.has(entry.entryId))
|
|
95
|
-
continue;
|
|
96
|
-
const deletedBlocks = deletedContentBlocks.get(entry.entryId);
|
|
97
|
-
for (const block of entry.contentBlocks) {
|
|
98
|
-
if (block.type !== "image")
|
|
99
|
-
continue;
|
|
100
|
-
if (deletedBlocks?.has(block.blockIndex))
|
|
101
|
-
continue;
|
|
102
|
-
count += 1;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return count;
|
|
106
|
-
}
|
|
107
|
-
//# sourceMappingURL=context-compaction-metrics.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context-compaction-metrics.js","sourceRoot":"","sources":["../../../src/core/compaction/context-compaction-metrics.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAE5F,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAChD,OAA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eAAe,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;IACpD,MAAM,oBAAoB,GAAG,uBAAuB,CAAC,OAAO,CAAC,CAAC;IAC9D,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,KAAK,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;QACxC,IAAI,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC;YAAE,SAAS;QACjD,MAAM,aAAa,GAAG,oBAAoB,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC9D,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,aAAa,EAAE,CAAC;YACzC,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO;gBAAE,SAAS;YACrC,IAAI,aAAa,EAAE,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC;gBAAE,SAAS;YACnD,KAAK,IAAI,CAAC,CAAC;QACZ,CAAC;IACF,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["import type { AgentToolResult } from \"@earendil-works/pi-agent-core\";\nimport type { ContextCompactionStats, ContextDeletionTarget } from \"../session-manager.ts\";\nimport type { CompactableTranscript } from \"./context-compaction-types.ts\";\nimport type { ContextCompactionBudgetToolDetails } from \"./context-deletion-tool-definitions.ts\";\nimport type { ContextCompactionParameters, ValidatedContextDeletionResult } from \"./context-compaction-types.ts\";\nimport { getDeletedContentBlocks, getDeletedEntryIds } from \"./context-deletion-targets.ts\";\n\nexport function formatErrorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nexport function createContextDeletionToolResult<TDetails>(text: string, details: TDetails): AgentToolResult<TDetails> {\n\treturn { content: [{ type: \"text\", text }], details, terminate: false };\n}\n\nexport function roundPercent(value: number): number {\n\treturn Math.round(value * 10) / 10;\n}\n\nexport function percentOf(part: number, total: number): number {\n\treturn total > 0 ? roundPercent((part / total) * 100) : 0;\n}\n\nexport function finitePositiveNumber(value: number | undefined): number | undefined {\n\treturn typeof value === \"number\" && Number.isFinite(value) && value > 0 ? value : undefined;\n}\n\nexport function contextCompactionTargetReductionPercent(parameters: ContextCompactionParameters): number {\n\treturn roundPercent((1 - parameters.compression_ratio) * 100);\n}\n\nexport function contextCompactionTargetLabel(parameters: ContextCompactionParameters): string {\n\treturn `${contextCompactionTargetReductionPercent(parameters)}%`;\n}\n\nexport function createContextCompactionBudgetDetails(\n\tstats: ContextCompactionStats,\n\tcallCount: number,\n\tcontextWindow: number | undefined,\n\tparameters: ContextCompactionParameters,\n\tremainingImageTokens: number,\n\timageBlockCount: number,\n): ContextCompactionBudgetToolDetails {\n\tconst targetTokensAfter = Math.max(0, Math.floor(stats.tokensBefore * parameters.compression_ratio));\n\tconst targetReductionPercent = contextCompactionTargetReductionPercent(parameters);\n\tconst details: ContextCompactionBudgetToolDetails = {\n\t\t...(contextWindow !== undefined ? { contextWindow } : {}),\n\t\tcompression_ratio: parameters.compression_ratio,\n\t\ttokensBefore: stats.tokensBefore,\n\t\tcurrentTokensAfter: stats.tokensAfter,\n\t\tdeletedTokens: Math.max(0, stats.tokensBefore - stats.tokensAfter),\n\t\tcurrentReductionPercent: stats.percentReduction,\n\t\ttargetReductionPercent,\n\t\ttargetTokensAfter,\n\t\ttokensToDeleteForTarget: Math.max(0, stats.tokensAfter - targetTokensAfter),\n\t\t...(contextWindow !== undefined\n\t\t\t? {\n\t\t\t\t\tcontextWindowBeforePercent: percentOf(stats.tokensBefore, contextWindow),\n\t\t\t\t\tcontextWindowAfterPercent: percentOf(stats.tokensAfter, contextWindow),\n\t\t\t\t}\n\t\t\t: {}),\n\t\tremainingImageTokens,\n\t\timageBlockCount,\n\t\timageTokenPercent: percentOf(remainingImageTokens, stats.tokensAfter),\n\t\tcallCount,\n\t};\n\treturn details;\n}\n\nexport function contextCompactionTargetMet(\n\tresult: ValidatedContextDeletionResult | undefined,\n\tparameters: ContextCompactionParameters,\n): result is ValidatedContextDeletionResult {\n\treturn (\n\t\tresult !== undefined &&\n\t\tresult.deletedTargets.length > 0 &&\n\t\tresult.stats.percentReduction >= contextCompactionTargetReductionPercent(parameters)\n\t);\n}\n\nexport function contextCompactionProgressKey(result: ValidatedContextDeletionResult | undefined): string {\n\tif (!result) return \"none:0\";\n\treturn `${result.deletedTargets.length}:${result.stats.percentReduction}:${result.stats.tokensAfter}`;\n}\n\nexport function contextCompactionProgressPercent(result: ValidatedContextDeletionResult | undefined): number {\n\treturn result?.stats.percentReduction ?? 0;\n}\n\n/**\n * Sum the token estimates of image content blocks that remain after applying the\n * current deletion targets. Deleted entries and individually-deleted image blocks\n * are excluded so the budget tool always reflects the live working set.\n */\nexport function sumRemainingImageTokens(\n\ttranscript: CompactableTranscript,\n\ttargets: readonly ContextDeletionTarget[],\n): number {\n\tconst deletedEntryIds = getDeletedEntryIds(targets);\n\tconst deletedContentBlocks = getDeletedContentBlocks(targets);\n\tlet imageTokens = 0;\n\tfor (const entry of transcript.entries) {\n\t\tif (deletedEntryIds.has(entry.entryId)) continue;\n\t\tconst deletedBlocks = deletedContentBlocks.get(entry.entryId);\n\t\tfor (const block of entry.contentBlocks) {\n\t\t\tif (block.type !== \"image\") continue;\n\t\t\tif (deletedBlocks?.has(block.blockIndex)) continue;\n\t\t\timageTokens += block.tokenEstimate;\n\t\t}\n\t}\n\treturn imageTokens;\n}\n\n/**\n * Count the image content blocks that remain after applying the current deletion\n * targets. Deleted entries and individually-deleted image blocks are excluded.\n */\nexport function countRemainingImageBlocks(\n\ttranscript: CompactableTranscript,\n\ttargets: readonly ContextDeletionTarget[],\n): number {\n\tconst deletedEntryIds = getDeletedEntryIds(targets);\n\tconst deletedContentBlocks = getDeletedContentBlocks(targets);\n\tlet count = 0;\n\tfor (const entry of transcript.entries) {\n\t\tif (deletedEntryIds.has(entry.entryId)) continue;\n\t\tconst deletedBlocks = deletedContentBlocks.get(entry.entryId);\n\t\tfor (const block of entry.contentBlocks) {\n\t\t\tif (block.type !== \"image\") continue;\n\t\t\tif (deletedBlocks?.has(block.blockIndex)) continue;\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn count;\n}\n"]}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { CompactableTranscript, ContextCompactionParameters } from "./context-compaction-types.ts";
|
|
2
|
-
export declare const CONTEXT_COMPACTION_SYSTEM_PROMPT = "You are a context compaction assistant.\n\nYour task is to read relevant parts of a conversation between a user and an AI assistant provided via a transcript file, then run a series of tools to apply deletion-only verbatim compaction using the exact context_delete or context_grep_delete format specified.";
|
|
3
|
-
export interface ContextCompactionTranscriptFile {
|
|
4
|
-
path: string;
|
|
5
|
-
cleanup(): void;
|
|
6
|
-
}
|
|
7
|
-
export declare function writeContextCompactionTranscriptFile(transcript: CompactableTranscript): ContextCompactionTranscriptFile;
|
|
8
|
-
export declare function buildContextCompactionPrompt(transcript: CompactableTranscript, transcriptFilePath?: string, parameters?: ContextCompactionParameters): string;
|
|
9
|
-
//# sourceMappingURL=context-compaction-prompt.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context-compaction-prompt.d.ts","sourceRoot":"","sources":["../../../src/core/compaction/context-compaction-prompt.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACX,qBAAqB,EAErB,2BAA2B,EAC3B,MAAM,+BAA+B,CAAC;AAWvC,eAAO,MAAM,gCAAgC,sTAE0N,CAAC;AAsFxQ,MAAM,WAAW,+BAA+B;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,IAAI,IAAI,CAAC;CAChB;AAED,wBAAgB,oCAAoC,CAAC,UAAU,EAAE,qBAAqB,GAAG,+BAA+B,CAWvH;AA+DD,wBAAgB,4BAA4B,CAC3C,UAAU,EAAE,qBAAqB,EACjC,kBAAkB,SAAgE,EAClF,UAAU,GAAE,2BAA2E,GACrF,MAAM,CAER","sourcesContent":["import { mkdtempSync, rmSync, writeFileSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport type {\n\tCompactableTranscript,\n\tCompactableTranscriptEntry,\n\tContextCompactionParameters,\n} from \"./context-compaction-types.ts\";\nimport {\n\tcontextCompactionTargetLabel,\n\tcontextCompactionTargetReductionPercent,\n} from \"./context-compaction-metrics.ts\";\nimport { getTranscriptCompactionParameters } from \"./context-compaction-strategy.ts\";\nimport { isExcludedFromLlmContext } from \"./context-transcript-analysis.ts\";\n\nconst CONTEXT_MANIFEST_MAX_ENTRIES = 80;\nconst CONTEXT_MANIFEST_PREVIEW_CHARS = 240;\n\nexport const CONTEXT_COMPACTION_SYSTEM_PROMPT = `You are a context compaction assistant.\n\nYour task is to read relevant parts of a conversation between a user and an AI assistant provided via a transcript file, then run a series of tools to apply deletion-only verbatim compaction using the exact context_delete or context_grep_delete format specified.`;\n\nfunction contextCompactionFixedPrompt(parameters: ContextCompactionParameters): string {\n\tconst targetLabel = contextCompactionTargetLabel(parameters);\n\treturn `Reference the provided transcript file transcript and use your search/read tools for small inspections, then use context_delete or context_grep_delete for deletions.\n\nCompaction records deletion targets, not replacement content.\nFor context_delete, use id-only targets: stable entryId values and optional blockIndex values only.\nFor context_grep_delete, use a concise literal or regex pattern to select matching entries or blocks; do not paste full transcript entries or content-block bodies.\nDo not summarize, paraphrase, or generate replacement context; those are not accepted compaction outputs.\nDo not mutate retained transcript objects or content.\nDeletion tool calls are the compaction action.\n\nStrategy:\n- Start by calling context_compaction_budget to see how much of the context window is full and how much reduction is needed.\n- Spend a few turns exploring with search/read tools to gain high confidence of candidate blocks to remove.\n- Prefer high-confidence exploit actions after that: delete obvious low-value entries via context_grep_delete or context_delete.\n- Use grep deletion for repeated low-value patterns.\n- Use exact id deletion for inspected one-off stale entries.\n- Check context_compaction_budget after deletion batches to track progress.\n- Strict requirement: reduce current context by at least ${targetLabel} before finishing. This is a hard completion gate, not a loose goal.\n- Do not send a final plain-text completion message until context_compaction_budget reports at least ${targetLabel} currentReductionPercent.\n- If the strict ${targetLabel} reduction is not met yet, continue removing low-value message entries or content blocks with context_delete/context_grep_delete.\n- Use the focus query to preserve relevant context: ${JSON.stringify(parameters.query)}.\n\nWhat Gets Deleted:\n- Redundant tool outputs: file reads already acted on, grep/search results already processed, passing test output no longer needed.\n- Exploratory dead ends: irrelevant files read, unhelpful or empty searches.\n- Verbose boilerplate: license headers, import blocks the agent isn't modifying, configuration files read for reference.\n- Superseded information: earlier versions of files that have since been edited, old error messages from bugs already fixed.\n- Stale/superseded image context: image content blocks (shown as type \"image\" / text \"[image]\") in older tool results, custom messages, or old user-pasted attachments that the agent has already inspected and no longer needs. Image blocks are large (each costs far more tokens than its \"[image]\" text preview suggests, as reported by context_compaction_budget imageTokenPercent). When images dominate the context, prefer deleting these stale image content blocks before removing useful recent text. Use context_grep_delete with the literal pattern \"[image]\" and target \"content_block\" to find image candidates, then confirm they are stale with context_read_entry before deleting. User text blocks remain protected. Old non-recent user image blocks may be deleted only when non-image user content remains in the same entry; old image-only user entries may be deleted as whole entries only when another task-bearing entry remains.\n\nWhat Survives:\n- Active file paths and line numbers: Any reference the agent might need to navigate.\n- Current error messages: Unresolved bugs and their exact text.\n- Reasoning decisions: Why the agent chose approach A over B. An agent's chain of thought (why it chose this file, what pattern it noticed, what fix it decided on) carries more information-per-token than the raw grep output or file content that informed those decisions.\n- Recent tool calls and their results: The last 3-5 operations.\n- User instructions: The original task and any clarifications.\n- Task-relevant images: Images that are part of the active user task (for example, a screenshot the user just asked about, or the most recent image-bearing result the agent is still acting on). Recent user images and recent tool results are protected by preserve_recent, so do not delete images the agent still needs.\n\nConditionally Deleted:\n- Old reasoning decisions: If there is nothing else to remove and the target reduction is not met, you may omit signed reasoning only as a complete logical assistant tool-use turn sequence. Each provider-visible user-like input starts a turn: a non-empty user/custom input (non-whitespace text or an image), a context-eligible bash execution, or a non-empty branch summary. Empty/whitespace-only user or custom inputs and empty branch summaries do not establish a boundary; whitespace-only branch summaries do because their wrapper is visible. Assistant messages and intervening tool results remain in that turn until the next visible user-like input. Never delete any thinking/redacted_thinking-bearing assistant entry from the current final logical turn; a trailing visible input without an assistant response makes the preceding assistant turn historical. In a completed historical turn, retain all thinking/redacted_thinking-bearing assistant entries or delete all of them as whole entries; never retain a proper subset. Never delete individual content blocks from a retained thinking-bearing assistant message.\n\n<output_format>\nCall the context_delete tool one or more times with deletion targets in this shape:\n{ \"deletions\": [{ \"kind\": \"entry\", \"entryId\": \"...\" }] }\n\nFor content-block deletions, use:\n{ \"kind\": \"content_block\", \"entryId\": \"...\", \"blockIndex\": 0 }\n\nThe tool applies and validates deletion targets immediately. You can continue calling it for additional deletions if useful.\n\nFor guarded bulk deletion by text match, call context_grep_delete with a literal pattern or regex. It removes valid matching context, silently ignores candidates that validation does not allow so they are not counted as removals, enforces a per-call maxMatches safety cap and optional expectedMatchCount, and validates through the same tool-call/tool-result safety rules. maxMatches only limits one tool call; there is no cumulative cap across corrected or repeated deletion calls.\n\nThe full transcript is available as a JSONL file path in the prompt, but do NOT try to load the whole file into context. Use context_search_transcript to find candidate entry IDs and context_read_entry to read only small slices (for example maxChars 1000-4000) before deleting.\n\nWhen the strict ${targetLabel} reduction requirement is met, reply with a brief plain-text completion message. Do not include deletion target IDs outside tool calls.\n</output_format>`;\n}\n\nfunction truncateForPrompt(text: string, maxChars: number): string {\n\tif (text.length <= maxChars) return text;\n\treturn `${text.slice(0, maxChars)}\\n[... ${text.length - maxChars} more characters omitted from context compaction prompt]`;\n}\n\nfunction transcriptEntryFilePayload(entry: CompactableTranscriptEntry): unknown {\n\treturn {\n\t\tentryId: entry.entryId,\n\t\tentryType: entry.entryType,\n\t\trole: entry.role,\n\t\tprotected: entry.protected,\n\t\ttokenEstimate: entry.tokenEstimate,\n\t\ttoolCallIds: entry.toolCallIds,\n\t\ttoolResultFor: entry.toolResultFor,\n\t\ttext: entry.text,\n\t\tcontentBlocks: entry.contentBlocks.map((block) => ({\n\t\t\tblockIndex: block.blockIndex,\n\t\t\ttype: block.type,\n\t\t\tprotected: block.protected,\n\t\t\ttoolCallId: block.toolCallId,\n\t\t\ttokenEstimate: block.tokenEstimate,\n\t\t\ttext: block.text,\n\t\t})),\n\t};\n}\n\nexport interface ContextCompactionTranscriptFile {\n\tpath: string;\n\tcleanup(): void;\n}\n\nexport function writeContextCompactionTranscriptFile(transcript: CompactableTranscript): ContextCompactionTranscriptFile {\n\tconst directory = mkdtempSync(join(tmpdir(), \"atomic-context-transcript-\"));\n\tconst path = join(directory, \"transcript.jsonl\");\n\tconst lines = transcript.entries\n\t\t.filter((entry) => !isExcludedFromLlmContext(entry.message))\n\t\t.map((entry) => JSON.stringify(transcriptEntryFilePayload(entry)));\n\twriteFileSync(path, `${lines.join(\"\\n\")}\\n`, \"utf8\");\n\treturn {\n\t\tpath,\n\t\tcleanup: () => rmSync(directory, { recursive: true, force: true }),\n\t};\n}\n\nfunction contextCompactionTranscriptManifest(transcript: CompactableTranscript, transcriptFilePath: string): unknown {\n\tconst eligibleEntries = transcript.entries.filter((entry) => !isExcludedFromLlmContext(entry.message));\n\tconst selectedEntryIds = new Set<string>();\n\tconst selectedEntries: CompactableTranscriptEntry[] = [];\n\tconst addEntry = (entry: CompactableTranscriptEntry): void => {\n\t\tif (selectedEntryIds.has(entry.entryId) || selectedEntries.length >= CONTEXT_MANIFEST_MAX_ENTRIES) return;\n\t\tselectedEntryIds.add(entry.entryId);\n\t\tselectedEntries.push(entry);\n\t};\n\n\tfor (const entry of eligibleEntries.filter((entry) => entry.protected)) {\n\t\taddEntry(entry);\n\t}\n\tfor (const entry of [...eligibleEntries]\n\t\t.filter((entry) => !entry.protected)\n\t\t.sort((left, right) => right.tokenEstimate - left.tokenEstimate)) {\n\t\taddEntry(entry);\n\t}\n\tselectedEntries.sort((left, right) => eligibleEntries.indexOf(left) - eligibleEntries.indexOf(right));\n\n\treturn {\n\t\ttranscriptFilePath,\n\t\ttranscriptFileFormat: \"jsonl: one compactable transcript entry per line with full text and contentBlocks text\",\n\t\ttotalEntries: eligibleEntries.length,\n\t\tmanifestEntries: selectedEntries.length,\n\t\tomittedEntries: Math.max(0, eligibleEntries.length - selectedEntries.length),\n\t\ttokensBefore: transcript.tokensBefore,\n\t\tprotectedEntryIds: transcript.protectedEntryIds,\n\t\tentries: selectedEntries.map((entry) => ({\n\t\t\tentryId: entry.entryId,\n\t\t\trole: entry.role,\n\t\t\tprotected: entry.protected,\n\t\t\ttokenEstimate: entry.tokenEstimate,\n\t\t\ttoolCallIds: entry.toolCallIds,\n\t\t\ttoolResultFor: entry.toolResultFor,\n\t\t\tcontentBlockCount: entry.contentBlocks.length,\n\t\t\tcontentBlocks: entry.contentBlocks.map((block) => ({\n\t\t\t\tblockIndex: block.blockIndex,\n\t\t\t\ttype: block.type,\n\t\t\t\tprotected: block.protected,\n\t\t\t\ttoolCallId: block.toolCallId,\n\t\t\t\ttokenEstimate: block.tokenEstimate,\n\t\t\t})),\n\t\t\tpreview: truncateForPrompt(entry.text, CONTEXT_MANIFEST_PREVIEW_CHARS),\n\t\t})),\n\t};\n}\n\nfunction contextCompactionParametersPrompt(parameters: ContextCompactionParameters): string {\n\treturn `\\n<compaction-parameters>\\n${JSON.stringify(\n\t\t{\n\t\t\tcompression_ratio: parameters.compression_ratio,\n\t\t\tpreserve_recent: parameters.preserve_recent,\n\t\t\tquery: parameters.query,\n\t\t\ttarget_reduction_percent: contextCompactionTargetReductionPercent(parameters),\n\t\t},\n\t\tnull,\n\t\t2,\n\t)}\\n</compaction-parameters>`;\n}\n\nexport function buildContextCompactionPrompt(\n\ttranscript: CompactableTranscript,\n\ttranscriptFilePath = \"<transcript file will be written during context compaction>\",\n\tparameters: ContextCompactionParameters = getTranscriptCompactionParameters(transcript),\n): string {\n\treturn `${contextCompactionFixedPrompt(parameters)}${contextCompactionParametersPrompt(parameters)}\\n\\n<transcript-file>\\n${transcriptFilePath}\\n</transcript-file>\\n\\n<context-manifest>\\n${JSON.stringify(contextCompactionTranscriptManifest(transcript, transcriptFilePath), null, 2)}\\n</context-manifest>`;\n}\n"]}
|