@bastani/atomic 0.9.8 → 0.9.9-alpha.1
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 +28 -0
- package/dist/builtin/cursor/CHANGELOG.md +6 -0
- package/dist/builtin/cursor/package.json +2 -2
- package/dist/builtin/intercom/CHANGELOG.md +6 -0
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/CHANGELOG.md +6 -0
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +6 -0
- package/dist/builtin/subagents/package.json +1 -1
- 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 +6 -0
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +22 -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 +1 -1
- 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/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/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-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-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-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/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/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/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/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/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/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/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/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-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.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/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/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.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.d.ts.map +1 -1
- package/dist/main.js +2 -2
- package/dist/main.js.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-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-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-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/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/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/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/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-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-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-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/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-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/docs/compaction.md +97 -772
- package/docs/extensions.md +25 -29
- 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/custom-compaction.ts +14 -58
- package/examples/extensions/handoff.ts +2 -3
- package/npm-shrinkwrap.json +23 -23
- package/package.json +2 -2
- 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,228 +0,0 @@
|
|
|
1
|
-
import { createBranchSummaryMessage, createCustomMessage, messageIsLlmVisible, userLikeContentBlockIsLlmVisible } from "../messages.js";
|
|
2
|
-
import { normalizeDerivedSessionEntries } from "../session-entry-normalization.js";
|
|
3
|
-
import { buildContextDeletionFilteredPath, buildEffectiveContextDeletionFilters, } from "../session-manager.js";
|
|
4
|
-
import { estimateContentBlockTokens, estimateTokens } from "./compaction.js";
|
|
5
|
-
import { CONTEXT_COMPACTION_AUTO_QUERY, } from "./context-compaction-types.js";
|
|
6
|
-
import { normalizeContextCompactionParameters, normalizeContextCompactionQuery, } from "./context-compaction-strategy.js";
|
|
7
|
-
function getMessageFromEntry(entry) {
|
|
8
|
-
if (entry.type === "message") {
|
|
9
|
-
return entry.message;
|
|
10
|
-
}
|
|
11
|
-
if (entry.type === "custom_message") {
|
|
12
|
-
return createCustomMessage(entry.customType, entry.content, entry.display, entry.details, entry.timestamp, entry.excludeFromContext);
|
|
13
|
-
}
|
|
14
|
-
if (entry.type === "branch_summary" && typeof entry.summary === "string") {
|
|
15
|
-
return createBranchSummaryMessage(entry.summary, entry.fromId, entry.timestamp);
|
|
16
|
-
}
|
|
17
|
-
return undefined;
|
|
18
|
-
}
|
|
19
|
-
export function isExcludedFromLlmContext(message) {
|
|
20
|
-
return !messageIsLlmVisible(message);
|
|
21
|
-
}
|
|
22
|
-
function getContextEligibleMessageFromEntry(entry) {
|
|
23
|
-
const message = getMessageFromEntry(entry);
|
|
24
|
-
if (!message || isExcludedFromLlmContext(message))
|
|
25
|
-
return undefined;
|
|
26
|
-
return message;
|
|
27
|
-
}
|
|
28
|
-
function safelySerialize(value) {
|
|
29
|
-
try {
|
|
30
|
-
const serialized = JSON.stringify(value);
|
|
31
|
-
if (typeof serialized === "string")
|
|
32
|
-
return serialized;
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
// Preserve a finite diagnostic projection for cyclic future payloads.
|
|
36
|
-
}
|
|
37
|
-
return "[unserializable content]";
|
|
38
|
-
}
|
|
39
|
-
function textFromUnknownContent(content) {
|
|
40
|
-
if (typeof content === "string")
|
|
41
|
-
return content;
|
|
42
|
-
if (!Array.isArray(content))
|
|
43
|
-
return safelySerialize(content);
|
|
44
|
-
return content.map((block) => textFromContentBlock(block)).join("\n");
|
|
45
|
-
}
|
|
46
|
-
function textFromContentBlock(block) {
|
|
47
|
-
if (!block || typeof block !== "object")
|
|
48
|
-
return String(block);
|
|
49
|
-
const record = block;
|
|
50
|
-
if (record.type === "text" && typeof record.text === "string")
|
|
51
|
-
return record.text;
|
|
52
|
-
if (record.type === "thinking" && typeof record.thinking === "string")
|
|
53
|
-
return record.thinking;
|
|
54
|
-
if (record.type === "toolCall") {
|
|
55
|
-
const name = typeof record.name === "string" ? record.name : "tool";
|
|
56
|
-
const id = typeof record.id === "string" ? record.id : "unknown";
|
|
57
|
-
const args = "arguments" in record ? safelySerialize(record.arguments) : "";
|
|
58
|
-
return `toolCall ${id} ${name} ${args}`.trim();
|
|
59
|
-
}
|
|
60
|
-
if (record.type === "image")
|
|
61
|
-
return "[image]";
|
|
62
|
-
return safelySerialize(record);
|
|
63
|
-
}
|
|
64
|
-
function getToolCallIdFromBlock(block) {
|
|
65
|
-
if (!block || typeof block !== "object")
|
|
66
|
-
return undefined;
|
|
67
|
-
const record = block;
|
|
68
|
-
if (record.type !== "toolCall")
|
|
69
|
-
return undefined;
|
|
70
|
-
return typeof record.id === "string" ? record.id : undefined;
|
|
71
|
-
}
|
|
72
|
-
function getToolResultCallId(message) {
|
|
73
|
-
if (message.role !== "toolResult")
|
|
74
|
-
return undefined;
|
|
75
|
-
const callId = message.toolCallId;
|
|
76
|
-
return typeof callId === "string" ? callId : undefined;
|
|
77
|
-
}
|
|
78
|
-
function contentBlocksForEntry(entryId, message, protectedEntry, existingDeletedBlocks) {
|
|
79
|
-
const content = message.content;
|
|
80
|
-
if (!Array.isArray(content))
|
|
81
|
-
return [];
|
|
82
|
-
return content
|
|
83
|
-
.map((block, blockIndex) => {
|
|
84
|
-
if (existingDeletedBlocks?.has(blockIndex)) {
|
|
85
|
-
return undefined;
|
|
86
|
-
}
|
|
87
|
-
const type = block && typeof block === "object" && typeof block.type === "string"
|
|
88
|
-
? (block.type)
|
|
89
|
-
: "unknown";
|
|
90
|
-
const text = textFromContentBlock(block);
|
|
91
|
-
const llmVisible = message.role === "user" || message.role === "custom"
|
|
92
|
-
? userLikeContentBlockIsLlmVisible(block)
|
|
93
|
-
: true;
|
|
94
|
-
return {
|
|
95
|
-
entryId,
|
|
96
|
-
blockIndex,
|
|
97
|
-
type,
|
|
98
|
-
text,
|
|
99
|
-
tokenEstimate: estimateContentBlockTokens(block, llmVisible),
|
|
100
|
-
protected: protectedEntry,
|
|
101
|
-
llmVisible,
|
|
102
|
-
toolCallId: getToolCallIdFromBlock(block),
|
|
103
|
-
};
|
|
104
|
-
})
|
|
105
|
-
.filter((block) => block !== undefined);
|
|
106
|
-
}
|
|
107
|
-
function messageText(message) {
|
|
108
|
-
switch (message.role) {
|
|
109
|
-
case "bashExecution":
|
|
110
|
-
return `Ran ${message.command}\n${message.output}`;
|
|
111
|
-
case "branchSummary":
|
|
112
|
-
return message.summary;
|
|
113
|
-
case "custom":
|
|
114
|
-
case "toolResult":
|
|
115
|
-
case "user":
|
|
116
|
-
return textFromUnknownContent(message.content);
|
|
117
|
-
case "assistant":
|
|
118
|
-
return textFromUnknownContent(message.content);
|
|
119
|
-
case "compactionSummary":
|
|
120
|
-
// Legacy summary-compaction message type retained in the upstream AgentMessage union
|
|
121
|
-
// after summary compaction was removed; surface its archival summary text.
|
|
122
|
-
return message.summary;
|
|
123
|
-
default: {
|
|
124
|
-
// Exhaustiveness guard: adding a new AgentMessage role must fail the build here instead
|
|
125
|
-
// of silently degrading to an empty string.
|
|
126
|
-
const _exhaustiveCheck = message;
|
|
127
|
-
void _exhaustiveCheck;
|
|
128
|
-
return "";
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
export function hasAssistantError(message) {
|
|
133
|
-
return message.role === "assistant" && message.stopReason === "error";
|
|
134
|
-
}
|
|
135
|
-
export function hasToolResultError(message) {
|
|
136
|
-
return message.role === "toolResult" && message.isError === true;
|
|
137
|
-
}
|
|
138
|
-
export function hasFailedBashExecution(message) {
|
|
139
|
-
return message.role === "bashExecution" && typeof message.exitCode === "number" && message.exitCode !== 0;
|
|
140
|
-
}
|
|
141
|
-
export function autoDetectContextCompactionQuery(pathEntries) {
|
|
142
|
-
const derivedPathEntries = normalizeDerivedSessionEntries(pathEntries);
|
|
143
|
-
for (let index = derivedPathEntries.length - 1; index >= 0; index--) {
|
|
144
|
-
const entry = derivedPathEntries[index];
|
|
145
|
-
if (entry.type === "context_compaction")
|
|
146
|
-
continue;
|
|
147
|
-
const message = getContextEligibleMessageFromEntry(entry);
|
|
148
|
-
if (!message || message.role !== "user")
|
|
149
|
-
continue;
|
|
150
|
-
const text = messageText(message).trim();
|
|
151
|
-
if (text.length > 0)
|
|
152
|
-
return normalizeContextCompactionQuery(text, CONTEXT_COMPACTION_AUTO_QUERY);
|
|
153
|
-
}
|
|
154
|
-
return CONTEXT_COMPACTION_AUTO_QUERY;
|
|
155
|
-
}
|
|
156
|
-
function isProtectedEntry(entry, message, recentEntryIds) {
|
|
157
|
-
if (recentEntryIds.has(entry.id))
|
|
158
|
-
return true;
|
|
159
|
-
if (message.role === "user")
|
|
160
|
-
return true;
|
|
161
|
-
if (message.role === "custom")
|
|
162
|
-
return true;
|
|
163
|
-
if (message.role === "branchSummary")
|
|
164
|
-
return true;
|
|
165
|
-
if (hasAssistantError(message) || hasToolResultError(message))
|
|
166
|
-
return true;
|
|
167
|
-
if (hasFailedBashExecution(message))
|
|
168
|
-
return true;
|
|
169
|
-
if (entry.type === "branch_summary")
|
|
170
|
-
return true;
|
|
171
|
-
return false;
|
|
172
|
-
}
|
|
173
|
-
export function prepareContextCompaction(pathEntries, settings, options = {}) {
|
|
174
|
-
const derivedPathEntries = normalizeDerivedSessionEntries(pathEntries);
|
|
175
|
-
if (derivedPathEntries.length === 0)
|
|
176
|
-
return undefined;
|
|
177
|
-
const effectiveDeletionFilters = buildEffectiveContextDeletionFilters(derivedPathEntries);
|
|
178
|
-
const filteredPathEntries = buildContextDeletionFilteredPath(derivedPathEntries, effectiveDeletionFilters);
|
|
179
|
-
const parameters = normalizeContextCompactionParameters({ ...settings, ...options }, autoDetectContextCompactionQuery(filteredPathEntries));
|
|
180
|
-
const rawEntryById = new Map(derivedPathEntries.map((entry) => [entry.id, entry]));
|
|
181
|
-
const messageEntryIds = filteredPathEntries
|
|
182
|
-
.filter((entry) => entry.type !== "context_compaction" && getContextEligibleMessageFromEntry(entry) !== undefined)
|
|
183
|
-
.map((entry) => entry.id);
|
|
184
|
-
const recentEntryIds = new Set(parameters.preserve_recent > 0 ? messageEntryIds.slice(-parameters.preserve_recent) : []);
|
|
185
|
-
const protectedEntryIds = new Set();
|
|
186
|
-
const entries = [];
|
|
187
|
-
for (const entry of filteredPathEntries) {
|
|
188
|
-
if (entry.type === "context_compaction")
|
|
189
|
-
continue;
|
|
190
|
-
const message = getContextEligibleMessageFromEntry(entry);
|
|
191
|
-
if (!message)
|
|
192
|
-
continue;
|
|
193
|
-
const rawEntry = rawEntryById.get(entry.id) ?? entry;
|
|
194
|
-
const protectedEntry = isProtectedEntry(entry, message, recentEntryIds);
|
|
195
|
-
if (protectedEntry)
|
|
196
|
-
protectedEntryIds.add(entry.id);
|
|
197
|
-
const rawMessage = getContextEligibleMessageFromEntry(rawEntry) ?? message;
|
|
198
|
-
const contentBlocks = contentBlocksForEntry(entry.id, rawMessage, protectedEntry, effectiveDeletionFilters.deletedContentBlocks.get(entry.id));
|
|
199
|
-
const toolCallIds = contentBlocks.map((block) => block.toolCallId).filter((id) => id !== undefined);
|
|
200
|
-
const text = contentBlocks.length > 0 ? contentBlocks.map((block) => block.text).join("\n") : messageText(message);
|
|
201
|
-
entries.push({
|
|
202
|
-
entryId: entry.id,
|
|
203
|
-
entryType: entry.type,
|
|
204
|
-
role: message.role,
|
|
205
|
-
text,
|
|
206
|
-
tokenEstimate: estimateTokens(message),
|
|
207
|
-
protected: protectedEntry,
|
|
208
|
-
contentBlocks,
|
|
209
|
-
message,
|
|
210
|
-
toolCallIds,
|
|
211
|
-
toolResultFor: getToolResultCallId(message),
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
if (entries.length < 2)
|
|
215
|
-
return undefined;
|
|
216
|
-
return {
|
|
217
|
-
branchEntries: derivedPathEntries,
|
|
218
|
-
parameters,
|
|
219
|
-
transcript: {
|
|
220
|
-
entries,
|
|
221
|
-
protectedEntryIds: [...protectedEntryIds],
|
|
222
|
-
tokensBefore: entries.reduce((total, entry) => total + entry.tokenEstimate, 0),
|
|
223
|
-
settings,
|
|
224
|
-
parameters,
|
|
225
|
-
},
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
//# sourceMappingURL=context-transcript-analysis.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context-transcript-analysis.js","sourceRoot":"","sources":["../../../src/core/compaction/context-transcript-analysis.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,gCAAgC,EAAE,MAAM,gBAAgB,CAAC;AACxI,OAAO,EAAE,8BAA8B,EAAE,MAAM,mCAAmC,CAAC;AACnF,OAAO,EACN,gCAAgC,EAChC,oCAAoC,GAEpC,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,0BAA0B,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC7E,OAAO,EACN,6BAA6B,GAK7B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACN,oCAAoC,EACpC,+BAA+B,GAC/B,MAAM,kCAAkC,CAAC;AAE1C,SA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K,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,EAAgB,EAAE,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC;QAClH,MAAM,IAAI,GAAG,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QACnH,OAAO,CAAC,IAAI,CAAC;YACZ,OAAO,EAAE,KAAK,CAAC,EAAE;YACjB,SAAS,EAAE,KAAK,CAAC,IAAI;YACrB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,IAAI;YACJ,aAAa,EAAE,cAAc,CAAC,OAAO,CAAC;YACtC,SAAS,EAAE,cAAc;YACzB,aAAa;YACb,OAAO;YACP,WAAW;YACX,aAAa,EAAE,mBAAmB,CAAC,OAAO,CAAC;SAC3C,CAAC,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,SAAS,CAAC;IAEzC,OAAO;QACN,aAAa,EAAE,kBAAkB;QACjC,UAAU;QACV,UAAU,EAAE;YACX,OAAO;YACP,iBAAiB,EAAE,CAAC,GAAG,iBAAiB,CAAC;YACzC,YAAY,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC;YAC9E,QAAQ;YACR,UAAU;SACV;KACD,CAAC;AACH,CAAC","sourcesContent":["import type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport type { AssistantMessage } from \"@earendil-works/pi-ai/compat\";\nimport { createBranchSummaryMessage, createCustomMessage, messageIsLlmVisible, userLikeContentBlockIsLlmVisible } from \"../messages.ts\";\nimport { normalizeDerivedSessionEntries } from \"../session-entry-normalization.ts\";\nimport {\n\tbuildContextDeletionFilteredPath,\n\tbuildEffectiveContextDeletionFilters,\n\ttype SessionEntry,\n} from \"../session-manager.ts\";\nimport type { CompactionSettings } from \"./compaction.ts\";\nimport { estimateContentBlockTokens, estimateTokens } from \"./compaction.ts\";\nimport {\n\tCONTEXT_COMPACTION_AUTO_QUERY,\n\ttype CompactableContentBlock,\n\ttype CompactableTranscriptEntry,\n\ttype ContextCompactionPreparation,\n\ttype ContextCompactionRunOptions,\n} from \"./context-compaction-types.ts\";\nimport {\n\tnormalizeContextCompactionParameters,\n\tnormalizeContextCompactionQuery,\n} from \"./context-compaction-strategy.ts\";\n\nfunction getMessageFromEntry(entry: SessionEntry): AgentMessage | undefined {\n\tif (entry.type === \"message\") {\n\t\treturn entry.message;\n\t}\n\tif (entry.type === \"custom_message\") {\n\t\treturn createCustomMessage(\n\t\t\tentry.customType,\n\t\t\tentry.content,\n\t\t\tentry.display,\n\t\t\tentry.details,\n\t\t\tentry.timestamp,\n\t\t\tentry.excludeFromContext,\n\t\t);\n\t}\n\tif (entry.type === \"branch_summary\" && typeof entry.summary === \"string\") {\n\t\treturn createBranchSummaryMessage(entry.summary, entry.fromId, entry.timestamp);\n\t}\n\treturn undefined;\n}\n\nexport function isExcludedFromLlmContext(message: AgentMessage): boolean {\n\treturn !messageIsLlmVisible(message);\n}\n\nfunction getContextEligibleMessageFromEntry(entry: SessionEntry): AgentMessage | undefined {\n\tconst message = getMessageFromEntry(entry);\n\tif (!message || isExcludedFromLlmContext(message)) return undefined;\n\treturn message;\n}\n\nfunction safelySerialize(value: unknown): string {\n\ttry {\n\t\tconst serialized = JSON.stringify(value);\n\t\tif (typeof serialized === \"string\") return serialized;\n\t} catch {\n\t\t// Preserve a finite diagnostic projection for cyclic future payloads.\n\t}\n\treturn \"[unserializable content]\";\n}\n\nfunction textFromUnknownContent(content: unknown): string {\n\tif (typeof content === \"string\") return content;\n\tif (!Array.isArray(content)) return safelySerialize(content);\n\treturn content.map((block) => textFromContentBlock(block)).join(\"\\n\");\n}\n\nfunction textFromContentBlock(block: unknown): string {\n\tif (!block || typeof block !== \"object\") return String(block);\n\tconst record = block as Record<string, unknown>;\n\tif (record.type === \"text\" && typeof record.text === \"string\") return record.text;\n\tif (record.type === \"thinking\" && typeof record.thinking === \"string\") return record.thinking;\n\tif (record.type === \"toolCall\") {\n\t\tconst name = typeof record.name === \"string\" ? record.name : \"tool\";\n\t\tconst id = typeof record.id === \"string\" ? record.id : \"unknown\";\n\t\tconst args = \"arguments\" in record ? safelySerialize(record.arguments) : \"\";\n\t\treturn `toolCall ${id} ${name} ${args}`.trim();\n\t}\n\tif (record.type === \"image\") return \"[image]\";\n\treturn safelySerialize(record);\n}\n\nfunction getToolCallIdFromBlock(block: unknown): string | undefined {\n\tif (!block || typeof block !== \"object\") return undefined;\n\tconst record = block as Record<string, unknown>;\n\tif (record.type !== \"toolCall\") return undefined;\n\treturn typeof record.id === \"string\" ? record.id : undefined;\n}\n\nfunction getToolResultCallId(message: AgentMessage): string | undefined {\n\tif (message.role !== \"toolResult\") return undefined;\n\tconst callId = (message as { toolCallId?: unknown }).toolCallId;\n\treturn typeof callId === \"string\" ? callId : undefined;\n}\n\nfunction contentBlocksForEntry(\n\tentryId: string,\n\tmessage: AgentMessage,\n\tprotectedEntry: boolean,\n\texistingDeletedBlocks: ReadonlySet<number> | undefined,\n): CompactableContentBlock[] {\n\tconst content = (message as { content?: unknown }).content;\n\tif (!Array.isArray(content)) return [];\n\treturn content\n\t\t.map((block, blockIndex): CompactableContentBlock | undefined => {\n\t\t\tif (existingDeletedBlocks?.has(blockIndex)) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tconst type =\n\t\t\t\tblock && typeof block === \"object\" && typeof (block as { type?: unknown }).type === \"string\"\n\t\t\t\t\t? ((block as { type: string }).type)\n\t\t\t\t\t: \"unknown\";\n\t\t\tconst text = textFromContentBlock(block);\n\t\t\tconst llmVisible =\n\t\t\t\tmessage.role === \"user\" || message.role === \"custom\"\n\t\t\t\t\t? userLikeContentBlockIsLlmVisible(block)\n\t\t\t\t\t: true;\n\t\t\treturn {\n\t\t\t\tentryId,\n\t\t\t\tblockIndex,\n\t\t\t\ttype,\n\t\t\t\ttext,\n\t\t\t\ttokenEstimate: estimateContentBlockTokens(block, llmVisible),\n\t\t\t\tprotected: protectedEntry,\n\t\t\t\tllmVisible,\n\t\t\t\ttoolCallId: getToolCallIdFromBlock(block),\n\t\t\t};\n\t\t})\n\t\t.filter((block): block is CompactableContentBlock => block !== undefined);\n}\n\nfunction messageText(message: AgentMessage): string {\n\tswitch (message.role) {\n\t\tcase \"bashExecution\":\n\t\t\treturn `Ran ${message.command}\\n${message.output}`;\n\t\tcase \"branchSummary\":\n\t\t\treturn message.summary;\n\t\tcase \"custom\":\n\t\tcase \"toolResult\":\n\t\tcase \"user\":\n\t\t\treturn textFromUnknownContent(message.content);\n\t\tcase \"assistant\":\n\t\t\treturn textFromUnknownContent(message.content);\n\t\tcase \"compactionSummary\":\n\t\t\t// Legacy summary-compaction message type retained in the upstream AgentMessage union\n\t\t\t// after summary compaction was removed; surface its archival summary text.\n\t\t\treturn message.summary;\n\t\tdefault: {\n\t\t\t// Exhaustiveness guard: adding a new AgentMessage role must fail the build here instead\n\t\t\t// of silently degrading to an empty string.\n\t\t\tconst _exhaustiveCheck: never = message;\n\t\t\tvoid _exhaustiveCheck;\n\t\t\treturn \"\";\n\t\t}\n\t}\n}\n\nexport function hasAssistantError(message: AgentMessage): boolean {\n\treturn message.role === \"assistant\" && (message as AssistantMessage).stopReason === \"error\";\n}\n\nexport function hasToolResultError(message: AgentMessage): boolean {\n\treturn message.role === \"toolResult\" && (message as { isError?: unknown }).isError === true;\n}\n\nexport function hasFailedBashExecution(message: AgentMessage): boolean {\n\treturn message.role === \"bashExecution\" && typeof message.exitCode === \"number\" && message.exitCode !== 0;\n}\n\nexport function autoDetectContextCompactionQuery(pathEntries: readonly SessionEntry[]): string {\n\tconst derivedPathEntries = normalizeDerivedSessionEntries(pathEntries);\n\tfor (let index = derivedPathEntries.length - 1; index >= 0; index--) {\n\t\tconst entry = derivedPathEntries[index];\n\t\tif (entry.type === \"context_compaction\") continue;\n\t\tconst message = getContextEligibleMessageFromEntry(entry);\n\t\tif (!message || message.role !== \"user\") continue;\n\t\tconst text = messageText(message).trim();\n\t\tif (text.length > 0) return normalizeContextCompactionQuery(text, CONTEXT_COMPACTION_AUTO_QUERY);\n\t}\n\treturn CONTEXT_COMPACTION_AUTO_QUERY;\n}\n\nfunction isProtectedEntry(\n\tentry: SessionEntry,\n\tmessage: AgentMessage,\n\trecentEntryIds: ReadonlySet<string>,\n): boolean {\n\tif (recentEntryIds.has(entry.id)) return true;\n\tif (message.role === \"user\") return true;\n\tif (message.role === \"custom\") return true;\n\tif (message.role === \"branchSummary\") return true;\n\tif (hasAssistantError(message) || hasToolResultError(message)) return true;\n\tif (hasFailedBashExecution(message)) return true;\n\tif (entry.type === \"branch_summary\") return true;\n\treturn false;\n}\n\nexport function prepareContextCompaction(\n\tpathEntries: SessionEntry[],\n\tsettings: CompactionSettings,\n\toptions: ContextCompactionRunOptions = {},\n): ContextCompactionPreparation | undefined {\n\tconst derivedPathEntries = normalizeDerivedSessionEntries(pathEntries);\n\tif (derivedPathEntries.length === 0) return undefined;\n\n\tconst effectiveDeletionFilters = buildEffectiveContextDeletionFilters(derivedPathEntries);\n\tconst filteredPathEntries = buildContextDeletionFilteredPath(derivedPathEntries, effectiveDeletionFilters);\n\tconst parameters = normalizeContextCompactionParameters(\n\t\t{ ...settings, ...options },\n\t\tautoDetectContextCompactionQuery(filteredPathEntries),\n\t);\n\tconst rawEntryById = new Map(derivedPathEntries.map((entry) => [entry.id, entry]));\n\tconst messageEntryIds = filteredPathEntries\n\t\t.filter((entry) => entry.type !== \"context_compaction\" && getContextEligibleMessageFromEntry(entry) !== undefined)\n\t\t.map((entry) => entry.id);\n\tconst recentEntryIds = new Set(parameters.preserve_recent > 0 ? messageEntryIds.slice(-parameters.preserve_recent) : []);\n\tconst protectedEntryIds = new Set<string>();\n\tconst entries: CompactableTranscriptEntry[] = [];\n\n\tfor (const entry of filteredPathEntries) {\n\t\tif (entry.type === \"context_compaction\") continue;\n\t\tconst message = getContextEligibleMessageFromEntry(entry);\n\t\tif (!message) continue;\n\t\tconst rawEntry = rawEntryById.get(entry.id) ?? entry;\n\t\tconst protectedEntry = isProtectedEntry(entry, message, recentEntryIds);\n\t\tif (protectedEntry) protectedEntryIds.add(entry.id);\n\t\tconst rawMessage = getContextEligibleMessageFromEntry(rawEntry) ?? message;\n\t\tconst contentBlocks = contentBlocksForEntry(\n\t\t\tentry.id,\n\t\t\trawMessage,\n\t\t\tprotectedEntry,\n\t\t\teffectiveDeletionFilters.deletedContentBlocks.get(entry.id),\n\t\t);\n\t\tconst toolCallIds = contentBlocks.map((block) => block.toolCallId).filter((id): id is string => id !== undefined);\n\t\tconst text = contentBlocks.length > 0 ? contentBlocks.map((block) => block.text).join(\"\\n\") : messageText(message);\n\t\tentries.push({\n\t\t\tentryId: entry.id,\n\t\t\tentryType: entry.type,\n\t\t\trole: message.role,\n\t\t\ttext,\n\t\t\ttokenEstimate: estimateTokens(message),\n\t\t\tprotected: protectedEntry,\n\t\t\tcontentBlocks,\n\t\t\tmessage,\n\t\t\ttoolCallIds,\n\t\t\ttoolResultFor: getToolResultCallId(message),\n\t\t});\n\t}\n\n\tif (entries.length < 2) return undefined;\n\n\treturn {\n\t\tbranchEntries: derivedPathEntries,\n\t\tparameters,\n\t\ttranscript: {\n\t\t\tentries,\n\t\t\tprotectedEntryIds: [...protectedEntryIds],\n\t\t\ttokensBefore: entries.reduce((total, entry) => total + entry.tokenEstimate, 0),\n\t\t\tsettings,\n\t\t\tparameters,\n\t\t},\n\t};\n}\n"]}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { ContextDeletionFilters, SessionEntry } from "./session-manager-types.ts";
|
|
2
|
-
/**
|
|
3
|
-
* Reconcile persisted context-compaction filters in place so replay never
|
|
4
|
-
* retains only one side of a tool-call/tool-result pair. Callers should pass a
|
|
5
|
-
* fresh, unshared filter set; this mutates and returns that same object. The
|
|
6
|
-
* fixpoint normally converges in one or two passes, while the bounded pass
|
|
7
|
-
* count is only a non-termination backstop for malformed historical sessions.
|
|
8
|
-
*/
|
|
9
|
-
export declare function reconcilePersistedToolDependencyFilters(path: SessionEntry[], filters: ContextDeletionFilters): ContextDeletionFilters;
|
|
10
|
-
//# sourceMappingURL=session-manager-tool-dependencies.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"session-manager-tool-dependencies.d.ts","sourceRoot":"","sources":["../../src/core/session-manager-tool-dependencies.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,YAAY,EAAuB,MAAM,4BAA4B,CAAC;AAiG5G;;;;;;GAMG;AACH,wBAAgB,uCAAuC,CACtD,IAAI,EAAE,YAAY,EAAE,EACpB,OAAO,EAAE,sBAAsB,GAC7B,sBAAsB,CA0CxB","sourcesContent":["import type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport { contentArrayHasAssistantThinkingBlock } from \"./thinking-blocks.ts\";\nimport type { ContextDeletionFilters, SessionEntry, SessionMessageEntry } from \"./session-manager-types.ts\";\n\ninterface ToolCallReference {\n\tentry: SessionMessageEntry;\n\tblockIndex: number;\n\thasThinkingContent: boolean;\n}\n\ninterface ToolResultReference {\n\tentry: SessionMessageEntry;\n}\n\nfunction getMessageContent(message: AgentMessage): readonly unknown[] | undefined {\n\treturn \"content\" in message && Array.isArray(message.content) ? message.content : undefined;\n}\n\nfunction getToolCallContentBlockId(block: unknown): string | undefined {\n\tif (!block || typeof block !== \"object\") return undefined;\n\tconst candidate = block as { type?: unknown; id?: unknown };\n\treturn candidate.type === \"toolCall\" && typeof candidate.id === \"string\" ? candidate.id : undefined;\n}\n\nfunction getToolResultCallId(message: AgentMessage): string | undefined {\n\tif (message.role !== \"toolResult\") return undefined;\n\tconst toolCallId = (message as { toolCallId?: unknown }).toolCallId;\n\treturn typeof toolCallId === \"string\" ? toolCallId : undefined;\n}\n\nfunction collectToolReferences(path: SessionEntry[]): {\n\tcallsById: Map<string, ToolCallReference[]>;\n\tresultsByCallId: Map<string, ToolResultReference[]>;\n} {\n\tconst callsById = new Map<string, ToolCallReference[]>();\n\tconst resultsByCallId = new Map<string, ToolResultReference[]>();\n\tfor (const entry of path) {\n\t\tif (entry.type !== \"message\") continue;\n\t\tif (entry.message.role === \"assistant\") {\n\t\t\tconst content = getMessageContent(entry.message);\n\t\t\tif (!content) continue;\n\t\t\tconst hasThinkingContent = contentArrayHasAssistantThinkingBlock(entry.message.content);\n\t\t\tfor (const [blockIndex, block] of content.entries()) {\n\t\t\t\tconst callId = getToolCallContentBlockId(block);\n\t\t\t\tif (!callId) continue;\n\t\t\t\tconst refs = callsById.get(callId) ?? [];\n\t\t\t\trefs.push({ entry, blockIndex, hasThinkingContent });\n\t\t\t\tcallsById.set(callId, refs);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tconst resultCallId = getToolResultCallId(entry.message);\n\t\tif (!resultCallId) continue;\n\t\tconst refs = resultsByCallId.get(resultCallId) ?? [];\n\t\trefs.push({ entry });\n\t\tresultsByCallId.set(resultCallId, refs);\n\t}\n\treturn { callsById, resultsByCallId };\n}\n\nfunction isMessageEntryEffectivelyDeleted(entry: SessionMessageEntry, filters: ContextDeletionFilters): boolean {\n\tif (filters.deletedEntryIds.has(entry.id)) return true;\n\tconst deletedBlocks = filters.deletedContentBlocks.get(entry.id);\n\tif (!deletedBlocks || deletedBlocks.size === 0) return false;\n\tconst content = getMessageContent(entry.message);\n\treturn content !== undefined && content.length > 0 && content.every((_block, index) => deletedBlocks.has(index));\n}\n\nfunction isToolCallDeleted(ref: ToolCallReference, filters: ContextDeletionFilters): boolean {\n\tif (isMessageEntryEffectivelyDeleted(ref.entry, filters)) return true;\n\treturn filters.deletedContentBlocks.get(ref.entry.id)?.has(ref.blockIndex) === true;\n}\n\nfunction isToolResultDeleted(ref: ToolResultReference, filters: ContextDeletionFilters): boolean {\n\treturn isMessageEntryEffectivelyDeleted(ref.entry, filters);\n}\n\nfunction addEntryDeletion(filters: ContextDeletionFilters, entryId: string): boolean {\n\tif (filters.deletedEntryIds.has(entryId)) return false;\n\tfilters.deletedEntryIds.add(entryId);\n\tfilters.deletedContentBlocks.delete(entryId);\n\treturn true;\n}\n\nfunction addToolCallDeletion(filters: ContextDeletionFilters, ref: ToolCallReference): boolean {\n\tif (filters.deletedEntryIds.has(ref.entry.id)) return false;\n\tconst deletedBlocks = filters.deletedContentBlocks.get(ref.entry.id) ?? new Set<number>();\n\tif (deletedBlocks.has(ref.blockIndex)) return false;\n\tdeletedBlocks.add(ref.blockIndex);\n\tfilters.deletedContentBlocks.set(ref.entry.id, deletedBlocks);\n\treturn true;\n}\n\nfunction restoreResultEntry(filters: ContextDeletionFilters, entryId: string): boolean {\n\tconst hadEntryDeletion = filters.deletedEntryIds.delete(entryId);\n\tconst hadBlockDeletion = filters.deletedContentBlocks.delete(entryId);\n\treturn hadEntryDeletion || hadBlockDeletion;\n}\n\n/**\n * Reconcile persisted context-compaction filters in place so replay never\n * retains only one side of a tool-call/tool-result pair. Callers should pass a\n * fresh, unshared filter set; this mutates and returns that same object. The\n * fixpoint normally converges in one or two passes, while the bounded pass\n * count is only a non-termination backstop for malformed historical sessions.\n */\nexport function reconcilePersistedToolDependencyFilters(\n\tpath: SessionEntry[],\n\tfilters: ContextDeletionFilters,\n): ContextDeletionFilters {\n\tconst { callsById, resultsByCallId } = collectToolReferences(path);\n\tif (callsById.size === 0 || resultsByCallId.size === 0) return filters;\n\n\tlet changed = true;\n\tlet remainingPasses = Math.max(1, path.length * 2);\n\twhile (changed && remainingPasses > 0) {\n\t\tchanged = false;\n\t\tremainingPasses -= 1;\n\n\t\tfor (const [callId, callRefs] of callsById) {\n\t\t\tconst resultRefs = resultsByCallId.get(callId) ?? [];\n\t\t\tif (resultRefs.length === 0) continue;\n\t\t\tconst callDeleted = callRefs.every((ref) => isToolCallDeleted(ref, filters));\n\t\t\tif (callDeleted) {\n\t\t\t\tfor (const resultRef of resultRefs) {\n\t\t\t\t\tif (!isToolResultDeleted(resultRef, filters)) {\n\t\t\t\t\t\tchanged = addEntryDeletion(filters, resultRef.entry.id) || changed;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tfor (const resultRef of resultRefs) {\n\t\t\t\tif (!isToolResultDeleted(resultRef, filters)) continue;\n\t\t\t\tconst retainedThinkingCall = callRefs.some(\n\t\t\t\t\t(ref) => ref.hasThinkingContent && !isToolCallDeleted(ref, filters),\n\t\t\t\t);\n\t\t\t\tif (retainedThinkingCall) {\n\t\t\t\t\tchanged = restoreResultEntry(filters, resultRef.entry.id) || changed;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tfor (const callRef of callRefs) {\n\t\t\t\t\tif (!isToolCallDeleted(callRef, filters)) {\n\t\t\t\t\t\tchanged = addToolCallDeletion(filters, callRef) || changed;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn filters;\n}\n"]}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { contentArrayHasAssistantThinkingBlock } from "./thinking-blocks.js";
|
|
2
|
-
function getMessageContent(message) {
|
|
3
|
-
return "content" in message && Array.isArray(message.content) ? message.content : undefined;
|
|
4
|
-
}
|
|
5
|
-
function getToolCallContentBlockId(block) {
|
|
6
|
-
if (!block || typeof block !== "object")
|
|
7
|
-
return undefined;
|
|
8
|
-
const candidate = block;
|
|
9
|
-
return candidate.type === "toolCall" && typeof candidate.id === "string" ? candidate.id : undefined;
|
|
10
|
-
}
|
|
11
|
-
function getToolResultCallId(message) {
|
|
12
|
-
if (message.role !== "toolResult")
|
|
13
|
-
return undefined;
|
|
14
|
-
const toolCallId = message.toolCallId;
|
|
15
|
-
return typeof toolCallId === "string" ? toolCallId : undefined;
|
|
16
|
-
}
|
|
17
|
-
function collectToolReferences(path) {
|
|
18
|
-
const callsById = new Map();
|
|
19
|
-
const resultsByCallId = new Map();
|
|
20
|
-
for (const entry of path) {
|
|
21
|
-
if (entry.type !== "message")
|
|
22
|
-
continue;
|
|
23
|
-
if (entry.message.role === "assistant") {
|
|
24
|
-
const content = getMessageContent(entry.message);
|
|
25
|
-
if (!content)
|
|
26
|
-
continue;
|
|
27
|
-
const hasThinkingContent = contentArrayHasAssistantThinkingBlock(entry.message.content);
|
|
28
|
-
for (const [blockIndex, block] of content.entries()) {
|
|
29
|
-
const callId = getToolCallContentBlockId(block);
|
|
30
|
-
if (!callId)
|
|
31
|
-
continue;
|
|
32
|
-
const refs = callsById.get(callId) ?? [];
|
|
33
|
-
refs.push({ entry, blockIndex, hasThinkingContent });
|
|
34
|
-
callsById.set(callId, refs);
|
|
35
|
-
}
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
const resultCallId = getToolResultCallId(entry.message);
|
|
39
|
-
if (!resultCallId)
|
|
40
|
-
continue;
|
|
41
|
-
const refs = resultsByCallId.get(resultCallId) ?? [];
|
|
42
|
-
refs.push({ entry });
|
|
43
|
-
resultsByCallId.set(resultCallId, refs);
|
|
44
|
-
}
|
|
45
|
-
return { callsById, resultsByCallId };
|
|
46
|
-
}
|
|
47
|
-
function isMessageEntryEffectivelyDeleted(entry, filters) {
|
|
48
|
-
if (filters.deletedEntryIds.has(entry.id))
|
|
49
|
-
return true;
|
|
50
|
-
const deletedBlocks = filters.deletedContentBlocks.get(entry.id);
|
|
51
|
-
if (!deletedBlocks || deletedBlocks.size === 0)
|
|
52
|
-
return false;
|
|
53
|
-
const content = getMessageContent(entry.message);
|
|
54
|
-
return content !== undefined && content.length > 0 && content.every((_block, index) => deletedBlocks.has(index));
|
|
55
|
-
}
|
|
56
|
-
function isToolCallDeleted(ref, filters) {
|
|
57
|
-
if (isMessageEntryEffectivelyDeleted(ref.entry, filters))
|
|
58
|
-
return true;
|
|
59
|
-
return filters.deletedContentBlocks.get(ref.entry.id)?.has(ref.blockIndex) === true;
|
|
60
|
-
}
|
|
61
|
-
function isToolResultDeleted(ref, filters) {
|
|
62
|
-
return isMessageEntryEffectivelyDeleted(ref.entry, filters);
|
|
63
|
-
}
|
|
64
|
-
function addEntryDeletion(filters, entryId) {
|
|
65
|
-
if (filters.deletedEntryIds.has(entryId))
|
|
66
|
-
return false;
|
|
67
|
-
filters.deletedEntryIds.add(entryId);
|
|
68
|
-
filters.deletedContentBlocks.delete(entryId);
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
function addToolCallDeletion(filters, ref) {
|
|
72
|
-
if (filters.deletedEntryIds.has(ref.entry.id))
|
|
73
|
-
return false;
|
|
74
|
-
const deletedBlocks = filters.deletedContentBlocks.get(ref.entry.id) ?? new Set();
|
|
75
|
-
if (deletedBlocks.has(ref.blockIndex))
|
|
76
|
-
return false;
|
|
77
|
-
deletedBlocks.add(ref.blockIndex);
|
|
78
|
-
filters.deletedContentBlocks.set(ref.entry.id, deletedBlocks);
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
function restoreResultEntry(filters, entryId) {
|
|
82
|
-
const hadEntryDeletion = filters.deletedEntryIds.delete(entryId);
|
|
83
|
-
const hadBlockDeletion = filters.deletedContentBlocks.delete(entryId);
|
|
84
|
-
return hadEntryDeletion || hadBlockDeletion;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Reconcile persisted context-compaction filters in place so replay never
|
|
88
|
-
* retains only one side of a tool-call/tool-result pair. Callers should pass a
|
|
89
|
-
* fresh, unshared filter set; this mutates and returns that same object. The
|
|
90
|
-
* fixpoint normally converges in one or two passes, while the bounded pass
|
|
91
|
-
* count is only a non-termination backstop for malformed historical sessions.
|
|
92
|
-
*/
|
|
93
|
-
export function reconcilePersistedToolDependencyFilters(path, filters) {
|
|
94
|
-
const { callsById, resultsByCallId } = collectToolReferences(path);
|
|
95
|
-
if (callsById.size === 0 || resultsByCallId.size === 0)
|
|
96
|
-
return filters;
|
|
97
|
-
let changed = true;
|
|
98
|
-
let remainingPasses = Math.max(1, path.length * 2);
|
|
99
|
-
while (changed && remainingPasses > 0) {
|
|
100
|
-
changed = false;
|
|
101
|
-
remainingPasses -= 1;
|
|
102
|
-
for (const [callId, callRefs] of callsById) {
|
|
103
|
-
const resultRefs = resultsByCallId.get(callId) ?? [];
|
|
104
|
-
if (resultRefs.length === 0)
|
|
105
|
-
continue;
|
|
106
|
-
const callDeleted = callRefs.every((ref) => isToolCallDeleted(ref, filters));
|
|
107
|
-
if (callDeleted) {
|
|
108
|
-
for (const resultRef of resultRefs) {
|
|
109
|
-
if (!isToolResultDeleted(resultRef, filters)) {
|
|
110
|
-
changed = addEntryDeletion(filters, resultRef.entry.id) || changed;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
for (const resultRef of resultRefs) {
|
|
116
|
-
if (!isToolResultDeleted(resultRef, filters))
|
|
117
|
-
continue;
|
|
118
|
-
const retainedThinkingCall = callRefs.some((ref) => ref.hasThinkingContent && !isToolCallDeleted(ref, filters));
|
|
119
|
-
if (retainedThinkingCall) {
|
|
120
|
-
changed = restoreResultEntry(filters, resultRef.entry.id) || changed;
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
for (const callRef of callRefs) {
|
|
124
|
-
if (!isToolCallDeleted(callRef, filters)) {
|
|
125
|
-
changed = addToolCallDeletion(filters, callRef) || changed;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return filters;
|
|
132
|
-
}
|
|
133
|
-
//# sourceMappingURL=session-manager-tool-dependencies.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"session-manager-tool-dependencies.js","sourceRoot":"","sources":["../../src/core/session-manager-tool-dependencies.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qCAA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entArrayHasAssistantThinkingBlock } from \"./thinking-blocks.ts\";\nimport type { ContextDeletionFilters, SessionEntry, SessionMessageEntry } from \"./session-manager-types.ts\";\n\ninterface ToolCallReference {\n\tentry: SessionMessageEntry;\n\tblockIndex: number;\n\thasThinkingContent: boolean;\n}\n\ninterface ToolResultReference {\n\tentry: SessionMessageEntry;\n}\n\nfunction getMessageContent(message: AgentMessage): readonly unknown[] | undefined {\n\treturn \"content\" in message && Array.isArray(message.content) ? message.content : undefined;\n}\n\nfunction getToolCallContentBlockId(block: unknown): string | undefined {\n\tif (!block || typeof block !== \"object\") return undefined;\n\tconst candidate = block as { type?: unknown; id?: unknown };\n\treturn candidate.type === \"toolCall\" && typeof candidate.id === \"string\" ? candidate.id : undefined;\n}\n\nfunction getToolResultCallId(message: AgentMessage): string | undefined {\n\tif (message.role !== \"toolResult\") return undefined;\n\tconst toolCallId = (message as { toolCallId?: unknown }).toolCallId;\n\treturn typeof toolCallId === \"string\" ? toolCallId : undefined;\n}\n\nfunction collectToolReferences(path: SessionEntry[]): {\n\tcallsById: Map<string, ToolCallReference[]>;\n\tresultsByCallId: Map<string, ToolResultReference[]>;\n} {\n\tconst callsById = new Map<string, ToolCallReference[]>();\n\tconst resultsByCallId = new Map<string, ToolResultReference[]>();\n\tfor (const entry of path) {\n\t\tif (entry.type !== \"message\") continue;\n\t\tif (entry.message.role === \"assistant\") {\n\t\t\tconst content = getMessageContent(entry.message);\n\t\t\tif (!content) continue;\n\t\t\tconst hasThinkingContent = contentArrayHasAssistantThinkingBlock(entry.message.content);\n\t\t\tfor (const [blockIndex, block] of content.entries()) {\n\t\t\t\tconst callId = getToolCallContentBlockId(block);\n\t\t\t\tif (!callId) continue;\n\t\t\t\tconst refs = callsById.get(callId) ?? [];\n\t\t\t\trefs.push({ entry, blockIndex, hasThinkingContent });\n\t\t\t\tcallsById.set(callId, refs);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tconst resultCallId = getToolResultCallId(entry.message);\n\t\tif (!resultCallId) continue;\n\t\tconst refs = resultsByCallId.get(resultCallId) ?? [];\n\t\trefs.push({ entry });\n\t\tresultsByCallId.set(resultCallId, refs);\n\t}\n\treturn { callsById, resultsByCallId };\n}\n\nfunction isMessageEntryEffectivelyDeleted(entry: SessionMessageEntry, filters: ContextDeletionFilters): boolean {\n\tif (filters.deletedEntryIds.has(entry.id)) return true;\n\tconst deletedBlocks = filters.deletedContentBlocks.get(entry.id);\n\tif (!deletedBlocks || deletedBlocks.size === 0) return false;\n\tconst content = getMessageContent(entry.message);\n\treturn content !== undefined && content.length > 0 && content.every((_block, index) => deletedBlocks.has(index));\n}\n\nfunction isToolCallDeleted(ref: ToolCallReference, filters: ContextDeletionFilters): boolean {\n\tif (isMessageEntryEffectivelyDeleted(ref.entry, filters)) return true;\n\treturn filters.deletedContentBlocks.get(ref.entry.id)?.has(ref.blockIndex) === true;\n}\n\nfunction isToolResultDeleted(ref: ToolResultReference, filters: ContextDeletionFilters): boolean {\n\treturn isMessageEntryEffectivelyDeleted(ref.entry, filters);\n}\n\nfunction addEntryDeletion(filters: ContextDeletionFilters, entryId: string): boolean {\n\tif (filters.deletedEntryIds.has(entryId)) return false;\n\tfilters.deletedEntryIds.add(entryId);\n\tfilters.deletedContentBlocks.delete(entryId);\n\treturn true;\n}\n\nfunction addToolCallDeletion(filters: ContextDeletionFilters, ref: ToolCallReference): boolean {\n\tif (filters.deletedEntryIds.has(ref.entry.id)) return false;\n\tconst deletedBlocks = filters.deletedContentBlocks.get(ref.entry.id) ?? new Set<number>();\n\tif (deletedBlocks.has(ref.blockIndex)) return false;\n\tdeletedBlocks.add(ref.blockIndex);\n\tfilters.deletedContentBlocks.set(ref.entry.id, deletedBlocks);\n\treturn true;\n}\n\nfunction restoreResultEntry(filters: ContextDeletionFilters, entryId: string): boolean {\n\tconst hadEntryDeletion = filters.deletedEntryIds.delete(entryId);\n\tconst hadBlockDeletion = filters.deletedContentBlocks.delete(entryId);\n\treturn hadEntryDeletion || hadBlockDeletion;\n}\n\n/**\n * Reconcile persisted context-compaction filters in place so replay never\n * retains only one side of a tool-call/tool-result pair. Callers should pass a\n * fresh, unshared filter set; this mutates and returns that same object. The\n * fixpoint normally converges in one or two passes, while the bounded pass\n * count is only a non-termination backstop for malformed historical sessions.\n */\nexport function reconcilePersistedToolDependencyFilters(\n\tpath: SessionEntry[],\n\tfilters: ContextDeletionFilters,\n): ContextDeletionFilters {\n\tconst { callsById, resultsByCallId } = collectToolReferences(path);\n\tif (callsById.size === 0 || resultsByCallId.size === 0) return filters;\n\n\tlet changed = true;\n\tlet remainingPasses = Math.max(1, path.length * 2);\n\twhile (changed && remainingPasses > 0) {\n\t\tchanged = false;\n\t\tremainingPasses -= 1;\n\n\t\tfor (const [callId, callRefs] of callsById) {\n\t\t\tconst resultRefs = resultsByCallId.get(callId) ?? [];\n\t\t\tif (resultRefs.length === 0) continue;\n\t\t\tconst callDeleted = callRefs.every((ref) => isToolCallDeleted(ref, filters));\n\t\t\tif (callDeleted) {\n\t\t\t\tfor (const resultRef of resultRefs) {\n\t\t\t\t\tif (!isToolResultDeleted(resultRef, filters)) {\n\t\t\t\t\t\tchanged = addEntryDeletion(filters, resultRef.entry.id) || changed;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tfor (const resultRef of resultRefs) {\n\t\t\t\tif (!isToolResultDeleted(resultRef, filters)) continue;\n\t\t\t\tconst retainedThinkingCall = callRefs.some(\n\t\t\t\t\t(ref) => ref.hasThinkingContent && !isToolCallDeleted(ref, filters),\n\t\t\t\t);\n\t\t\t\tif (retainedThinkingCall) {\n\t\t\t\t\tchanged = restoreResultEntry(filters, resultRef.entry.id) || changed;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tfor (const callRef of callRefs) {\n\t\t\t\t\tif (!isToolCallDeleted(callRef, filters)) {\n\t\t\t\t\t\tchanged = addToolCallDeletion(filters, callRef) || changed;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn filters;\n}\n"]}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Box, type MarkdownTheme } from "@earendil-works/pi-tui";
|
|
2
|
-
import type { ContextCompactionResult } from "../../../core/compaction/index.ts";
|
|
3
|
-
/**
|
|
4
|
-
* Component that renders deletion-only context compaction results with the same
|
|
5
|
-
* compact/expanded card treatment as summary compaction messages.
|
|
6
|
-
*/
|
|
7
|
-
export declare class ContextCompactionSummaryMessageComponent extends Box {
|
|
8
|
-
private expanded;
|
|
9
|
-
private result;
|
|
10
|
-
private markdownTheme;
|
|
11
|
-
constructor(result: ContextCompactionResult, markdownTheme?: MarkdownTheme);
|
|
12
|
-
setExpanded(expanded: boolean): void;
|
|
13
|
-
invalidate(): void;
|
|
14
|
-
private updateDisplay;
|
|
15
|
-
private expandedMarkdown;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=context-compaction-summary-message.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context-compaction-summary-message.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/context-compaction-summary-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAY,KAAK,aAAa,EAAgB,MAAM,wBAAwB,CAAC;AACzF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAIjF;;;GAGG;AACH,qBAAa,wCAAyC,SAAQ,GAAG;IAChE,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAA0B;IACxC,OAAO,CAAC,aAAa,CAAgB;IAErC,YAAY,MAAM,EAAE,uBAAuB,EAAE,aAAa,GAAE,aAAkC,EAK7F;IAED,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAGnC;IAEQ,UAAU,IAAI,IAAI,CAG1B;IAED,OAAO,CAAC,aAAa;IAgCrB,OAAO,CAAC,gBAAgB;CA4BxB","sourcesContent":["import { Box, Markdown, type MarkdownTheme, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport type { ContextCompactionResult } from \"../../../core/compaction/index.ts\";\nimport { getMarkdownTheme, theme } from \"../theme/theme.ts\";\nimport { keyText } from \"./keybinding-hints.ts\";\n\n/**\n * Component that renders deletion-only context compaction results with the same\n * compact/expanded card treatment as summary compaction messages.\n */\nexport class ContextCompactionSummaryMessageComponent extends Box {\n\tprivate expanded = false;\n\tprivate result: ContextCompactionResult;\n\tprivate markdownTheme: MarkdownTheme;\n\n\tconstructor(result: ContextCompactionResult, markdownTheme: MarkdownTheme = getMarkdownTheme()) {\n\t\tsuper(1, 1, (t) => theme.bg(\"customMessageBg\", t));\n\t\tthis.result = result;\n\t\tthis.markdownTheme = markdownTheme;\n\t\tthis.updateDisplay();\n\t}\n\n\tsetExpanded(expanded: boolean): void {\n\t\tthis.expanded = expanded;\n\t\tthis.updateDisplay();\n\t}\n\n\toverride invalidate(): void {\n\t\tsuper.invalidate();\n\t\tthis.updateDisplay();\n\t}\n\n\tprivate updateDisplay(): void {\n\t\tthis.clear();\n\n\t\tconst label = theme.fg(\"customMessageLabel\", `\\x1b[1m[compaction]\\x1b[22m`);\n\t\tthis.addChild(new Text(label, 0, 0));\n\t\tthis.addChild(new Spacer(1));\n\n\t\tif (this.expanded) {\n\t\t\tthis.addChild(\n\t\t\t\tnew Markdown(this.expandedMarkdown(), 0, 0, this.markdownTheme, {\n\t\t\t\t\tcolor: (text: string) => theme.fg(\"customMessageText\", text),\n\t\t\t\t}),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst stats = this.result.stats;\n\t\tconst deleted = formatObjectCount(stats.objectsDeleted);\n\t\tthis.addChild(\n\t\t\tnew Text(\n\t\t\t\ttheme.fg(\n\t\t\t\t\t\"customMessageText\",\n\t\t\t\t\t`Compacted ${deleted}; est. transcript ${formatInteger(stats.tokensBefore)} → ${formatInteger(stats.tokensAfter)} tokens (${formatPercent(stats.percentReduction)} reduction, `,\n\t\t\t\t) +\n\t\t\t\t\ttheme.fg(\"dim\", keyText(\"app.tools.expand\")) +\n\t\t\t\t\ttheme.fg(\"customMessageText\", \" Expand)\"),\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\t}\n\n\tprivate expandedMarkdown(): string {\n\t\tconst stats = this.result.stats;\n\t\tconst deletedTargets = this.result.deletedTargets.slice(0, 8).map((target) => ` - ${formatTarget(target)}`);\n\t\tconst remainingTargets = this.result.deletedTargets.length - deletedTargets.length;\n\t\tif (remainingTargets > 0) {\n\t\t\tdeletedTargets.push(` - … ${remainingTargets} more`);\n\t\t}\n\n\t\tconst lines = [\n\t\t\t\"**Context compacted**\",\n\t\t\t\"\",\n\t\t\t\"Retained transcript content stayed verbatim.\",\n\t\t\t\"\",\n\t\t\t`- Estimated transcript tokens: ${formatInteger(stats.tokensBefore)} → ${formatInteger(stats.tokensAfter)} (${formatPercent(stats.percentReduction)} reduction)`,\n\t\t\t`- Deleted: ${formatObjectCount(stats.objectsDeleted)}`,\n\t\t\t`- Protected: ${this.result.protectedEntryIds.length.toLocaleString()} entr${this.result.protectedEntryIds.length === 1 ? \"y\" : \"ies\"}`,\n\t\t];\n\n\t\tif (this.result.backupPath) {\n\t\t\tlines.push(`- Backup: \\`${this.result.backupPath}\\``);\n\t\t}\n\n\t\tif (deletedTargets.length > 0) {\n\t\t\tlines.push(\"\", \"Deleted targets:\", ...deletedTargets);\n\t\t}\n\n\t\treturn `${lines.join(\"\\n\")}\\n`;\n\t}\n}\n\nfunction formatInteger(value: number): string {\n\treturn Math.round(value).toLocaleString();\n}\n\nfunction formatPercent(value: number): string {\n\tconst rounded = Math.round(value * 10) / 10;\n\treturn `${Number.isInteger(rounded) ? rounded.toFixed(0) : rounded.toFixed(1)}%`;\n}\n\nfunction formatObjectCount(count: number): string {\n\treturn `${count.toLocaleString()} object${count === 1 ? \"\" : \"s\"}`;\n}\n\nfunction formatTarget(target: ContextCompactionResult[\"deletedTargets\"][number]): string {\n\tif (target.kind === \"entry\") {\n\t\treturn `entry \\`${target.entryId}\\``;\n\t}\n\n\tconst block = target.blockIndex === undefined ? \"unknown\" : target.blockIndex.toLocaleString();\n\treturn `content block ${block} in \\`${target.entryId}\\``;\n}\n"]}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { Box, Markdown, Spacer, Text } from "@earendil-works/pi-tui";
|
|
2
|
-
import { getMarkdownTheme, theme } from "../theme/theme.js";
|
|
3
|
-
import { keyText } from "./keybinding-hints.js";
|
|
4
|
-
/**
|
|
5
|
-
* Component that renders deletion-only context compaction results with the same
|
|
6
|
-
* compact/expanded card treatment as summary compaction messages.
|
|
7
|
-
*/
|
|
8
|
-
export class ContextCompactionSummaryMessageComponent extends Box {
|
|
9
|
-
constructor(result, markdownTheme = getMarkdownTheme()) {
|
|
10
|
-
super(1, 1, (t) => theme.bg("customMessageBg", t));
|
|
11
|
-
this.expanded = false;
|
|
12
|
-
this.result = result;
|
|
13
|
-
this.markdownTheme = markdownTheme;
|
|
14
|
-
this.updateDisplay();
|
|
15
|
-
}
|
|
16
|
-
setExpanded(expanded) {
|
|
17
|
-
this.expanded = expanded;
|
|
18
|
-
this.updateDisplay();
|
|
19
|
-
}
|
|
20
|
-
invalidate() {
|
|
21
|
-
super.invalidate();
|
|
22
|
-
this.updateDisplay();
|
|
23
|
-
}
|
|
24
|
-
updateDisplay() {
|
|
25
|
-
this.clear();
|
|
26
|
-
const label = theme.fg("customMessageLabel", `\x1b[1m[compaction]\x1b[22m`);
|
|
27
|
-
this.addChild(new Text(label, 0, 0));
|
|
28
|
-
this.addChild(new Spacer(1));
|
|
29
|
-
if (this.expanded) {
|
|
30
|
-
this.addChild(new Markdown(this.expandedMarkdown(), 0, 0, this.markdownTheme, {
|
|
31
|
-
color: (text) => theme.fg("customMessageText", text),
|
|
32
|
-
}));
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const stats = this.result.stats;
|
|
36
|
-
const deleted = formatObjectCount(stats.objectsDeleted);
|
|
37
|
-
this.addChild(new Text(theme.fg("customMessageText", `Compacted ${deleted}; est. transcript ${formatInteger(stats.tokensBefore)} → ${formatInteger(stats.tokensAfter)} tokens (${formatPercent(stats.percentReduction)} reduction, `) +
|
|
38
|
-
theme.fg("dim", keyText("app.tools.expand")) +
|
|
39
|
-
theme.fg("customMessageText", " Expand)"), 0, 0));
|
|
40
|
-
}
|
|
41
|
-
expandedMarkdown() {
|
|
42
|
-
const stats = this.result.stats;
|
|
43
|
-
const deletedTargets = this.result.deletedTargets.slice(0, 8).map((target) => ` - ${formatTarget(target)}`);
|
|
44
|
-
const remainingTargets = this.result.deletedTargets.length - deletedTargets.length;
|
|
45
|
-
if (remainingTargets > 0) {
|
|
46
|
-
deletedTargets.push(` - … ${remainingTargets} more`);
|
|
47
|
-
}
|
|
48
|
-
const lines = [
|
|
49
|
-
"**Context compacted**",
|
|
50
|
-
"",
|
|
51
|
-
"Retained transcript content stayed verbatim.",
|
|
52
|
-
"",
|
|
53
|
-
`- Estimated transcript tokens: ${formatInteger(stats.tokensBefore)} → ${formatInteger(stats.tokensAfter)} (${formatPercent(stats.percentReduction)} reduction)`,
|
|
54
|
-
`- Deleted: ${formatObjectCount(stats.objectsDeleted)}`,
|
|
55
|
-
`- Protected: ${this.result.protectedEntryIds.length.toLocaleString()} entr${this.result.protectedEntryIds.length === 1 ? "y" : "ies"}`,
|
|
56
|
-
];
|
|
57
|
-
if (this.result.backupPath) {
|
|
58
|
-
lines.push(`- Backup: \`${this.result.backupPath}\``);
|
|
59
|
-
}
|
|
60
|
-
if (deletedTargets.length > 0) {
|
|
61
|
-
lines.push("", "Deleted targets:", ...deletedTargets);
|
|
62
|
-
}
|
|
63
|
-
return `${lines.join("\n")}\n`;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
function formatInteger(value) {
|
|
67
|
-
return Math.round(value).toLocaleString();
|
|
68
|
-
}
|
|
69
|
-
function formatPercent(value) {
|
|
70
|
-
const rounded = Math.round(value * 10) / 10;
|
|
71
|
-
return `${Number.isInteger(rounded) ? rounded.toFixed(0) : rounded.toFixed(1)}%`;
|
|
72
|
-
}
|
|
73
|
-
function formatObjectCount(count) {
|
|
74
|
-
return `${count.toLocaleString()} object${count === 1 ? "" : "s"}`;
|
|
75
|
-
}
|
|
76
|
-
function formatTarget(target) {
|
|
77
|
-
if (target.kind === "entry") {
|
|
78
|
-
return `entry \`${target.entryId}\``;
|
|
79
|
-
}
|
|
80
|
-
const block = target.blockIndex === undefined ? "unknown" : target.blockIndex.toLocaleString();
|
|
81
|
-
return `content block ${block} in \`${target.entryId}\``;
|
|
82
|
-
}
|
|
83
|
-
//# sourceMappingURL=context-compaction-summary-message.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context-compaction-summary-message.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/context-compaction-summary-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAsB,MAAM,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAEzF,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD;;;GAGG;AACH,MAAM,OAAO,wCAAyC,SAAQ,GAAG;IAKhE,YAAY,MAA+B,EAAE,aAAa,GAAkB,gBAAgB,EAAE;QAC7F,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,CAAC;QAL5C,aAAQ,GAAG,KAAK,CAAC;QAMxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,aAAa,EAAE,CAAC;IACtB,CAAC;IAED,WAAW,CAAC,QAAiB;QAC5B,IAAI,CAAC,Q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endil-works/pi-tui\";\nimport type { ContextCompactionResult } from \"../../../core/compaction/index.ts\";\nimport { getMarkdownTheme, theme } from \"../theme/theme.ts\";\nimport { keyText } from \"./keybinding-hints.ts\";\n\n/**\n * Component that renders deletion-only context compaction results with the same\n * compact/expanded card treatment as summary compaction messages.\n */\nexport class ContextCompactionSummaryMessageComponent extends Box {\n\tprivate expanded = false;\n\tprivate result: ContextCompactionResult;\n\tprivate markdownTheme: MarkdownTheme;\n\n\tconstructor(result: ContextCompactionResult, markdownTheme: MarkdownTheme = getMarkdownTheme()) {\n\t\tsuper(1, 1, (t) => theme.bg(\"customMessageBg\", t));\n\t\tthis.result = result;\n\t\tthis.markdownTheme = markdownTheme;\n\t\tthis.updateDisplay();\n\t}\n\n\tsetExpanded(expanded: boolean): void {\n\t\tthis.expanded = expanded;\n\t\tthis.updateDisplay();\n\t}\n\n\toverride invalidate(): void {\n\t\tsuper.invalidate();\n\t\tthis.updateDisplay();\n\t}\n\n\tprivate updateDisplay(): void {\n\t\tthis.clear();\n\n\t\tconst label = theme.fg(\"customMessageLabel\", `\\x1b[1m[compaction]\\x1b[22m`);\n\t\tthis.addChild(new Text(label, 0, 0));\n\t\tthis.addChild(new Spacer(1));\n\n\t\tif (this.expanded) {\n\t\t\tthis.addChild(\n\t\t\t\tnew Markdown(this.expandedMarkdown(), 0, 0, this.markdownTheme, {\n\t\t\t\t\tcolor: (text: string) => theme.fg(\"customMessageText\", text),\n\t\t\t\t}),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst stats = this.result.stats;\n\t\tconst deleted = formatObjectCount(stats.objectsDeleted);\n\t\tthis.addChild(\n\t\t\tnew Text(\n\t\t\t\ttheme.fg(\n\t\t\t\t\t\"customMessageText\",\n\t\t\t\t\t`Compacted ${deleted}; est. transcript ${formatInteger(stats.tokensBefore)} → ${formatInteger(stats.tokensAfter)} tokens (${formatPercent(stats.percentReduction)} reduction, `,\n\t\t\t\t) +\n\t\t\t\t\ttheme.fg(\"dim\", keyText(\"app.tools.expand\")) +\n\t\t\t\t\ttheme.fg(\"customMessageText\", \" Expand)\"),\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\t}\n\n\tprivate expandedMarkdown(): string {\n\t\tconst stats = this.result.stats;\n\t\tconst deletedTargets = this.result.deletedTargets.slice(0, 8).map((target) => ` - ${formatTarget(target)}`);\n\t\tconst remainingTargets = this.result.deletedTargets.length - deletedTargets.length;\n\t\tif (remainingTargets > 0) {\n\t\t\tdeletedTargets.push(` - … ${remainingTargets} more`);\n\t\t}\n\n\t\tconst lines = [\n\t\t\t\"**Context compacted**\",\n\t\t\t\"\",\n\t\t\t\"Retained transcript content stayed verbatim.\",\n\t\t\t\"\",\n\t\t\t`- Estimated transcript tokens: ${formatInteger(stats.tokensBefore)} → ${formatInteger(stats.tokensAfter)} (${formatPercent(stats.percentReduction)} reduction)`,\n\t\t\t`- Deleted: ${formatObjectCount(stats.objectsDeleted)}`,\n\t\t\t`- Protected: ${this.result.protectedEntryIds.length.toLocaleString()} entr${this.result.protectedEntryIds.length === 1 ? \"y\" : \"ies\"}`,\n\t\t];\n\n\t\tif (this.result.backupPath) {\n\t\t\tlines.push(`- Backup: \\`${this.result.backupPath}\\``);\n\t\t}\n\n\t\tif (deletedTargets.length > 0) {\n\t\t\tlines.push(\"\", \"Deleted targets:\", ...deletedTargets);\n\t\t}\n\n\t\treturn `${lines.join(\"\\n\")}\\n`;\n\t}\n}\n\nfunction formatInteger(value: number): string {\n\treturn Math.round(value).toLocaleString();\n}\n\nfunction formatPercent(value: number): string {\n\tconst rounded = Math.round(value * 10) / 10;\n\treturn `${Number.isInteger(rounded) ? rounded.toFixed(0) : rounded.toFixed(1)}%`;\n}\n\nfunction formatObjectCount(count: number): string {\n\treturn `${count.toLocaleString()} object${count === 1 ? \"\" : \"s\"}`;\n}\n\nfunction formatTarget(target: ContextCompactionResult[\"deletedTargets\"][number]): string {\n\tif (target.kind === \"entry\") {\n\t\treturn `entry \\`${target.entryId}\\``;\n\t}\n\n\tconst block = target.blockIndex === undefined ? \"unknown\" : target.blockIndex.toLocaleString();\n\treturn `content block ${block} in \\`${target.entryId}\\``;\n}\n"]}
|