@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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-manager-entries.d.ts","sourceRoot":"","sources":["../../src/core/session-manager-entries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAEvF,OAAO,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,
|
|
1
|
+
{"version":3,"file":"session-manager-entries.d.ts","sourceRoot":"","sources":["../../src/core/session-manager-entries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAEvF,OAAO,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAElF,OAAO,EAEN,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,wBAAwB,EAC7B,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,YAAY,EAEjB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,EAC7B,MAAM,4BAA4B,CAAC;AAWpC,wBAAgB,mBAAmB,CAClC,EAAE,EAAE,MAAM,EACV,GAAG,EAAE,MAAM,EACX,SAAS,GAAE,MAAiC,EAC5C,aAAa,CAAC,EAAE,MAAM,EACtB,QAAQ,CAAC,EAAE,OAAO,EAClB,QAAQ,CAAC,EAAE,uBAAuB,GAChC,aAAa,CAef;AAED,wBAAgB,qBAAqB,CAAC,UAAU,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A;CAAE,GAChC,kBAAkB,CASpB;AAED,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,SAAS,EAAE,GAAG,YAAY,EAAE,CAEhF","sourcesContent":["import type { ImageContent, Message, TextContent } from \"@earendil-works/pi-ai/compat\";\nimport { join } from \"path\";\nimport type { BashExecutionMessage, CustomMessage } from \"./messages.ts\";\nimport type { VerbatimCompactionDetails } from \"./compaction/compaction-types.js\";\nimport { validSessionWorkflowMetadata } from \"./session-manager-classification.ts\";\nimport {\n\tCURRENT_SESSION_VERSION,\n\ttype BranchSummaryEntry,\n\ttype CompactionEntry,\n\ttype ContextWindowChangeEntry,\n\ttype CustomEntry,\n\ttype CustomMessageEntry,\n\ttype FileEntry,\n\ttype LabelEntry,\n\ttype ModelChangeEntry,\n\ttype SessionEntry,\n\ttype SessionEntryBase,\n\ttype SessionHeader,\n\ttype SessionInfoEntry,\n\ttype SessionMessageEntry,\n\ttype SessionWorkflowMetadata,\n\ttype ThinkingLevelChangeEntry,\n} from \"./session-manager-types.ts\";\nimport { generateId } from \"./session-manager-validation.ts\";\n\nfunction entryBase(byId: { has(id: string): boolean }, parentId: string | null): Pick<SessionEntryBase, \"id\" | \"parentId\" | \"timestamp\"> {\n\treturn {\n\t\tid: generateId(byId),\n\t\tparentId,\n\t\ttimestamp: new Date().toISOString(),\n\t};\n}\n\nexport function createSessionHeader(\n\tid: string,\n\tcwd: string,\n\ttimestamp: string = new Date().toISOString(),\n\tparentSession?: string,\n\tinternal?: boolean,\n\tworkflow?: SessionWorkflowMetadata,\n): SessionHeader {\n\tconst header: SessionHeader = {\n\t\ttype: \"session\",\n\t\tversion: CURRENT_SESSION_VERSION,\n\t\tid,\n\t\ttimestamp,\n\t\tcwd,\n\t};\n\tif (parentSession !== undefined) header.parentSession = parentSession;\n\tconst validWorkflow = internal === true ? validSessionWorkflowMetadata(workflow) : undefined;\n\tif (validWorkflow) {\n\t\theader.internal = true;\n\t\theader.workflow = validWorkflow;\n\t}\n\treturn header;\n}\n\nexport function createSessionFilePath(sessionDir: string, timestamp: string, sessionId: string): string {\n\tconst fileTimestamp = timestamp.replace(/[:.]/g, \"-\");\n\treturn join(sessionDir, `${fileTimestamp}_${sessionId}.jsonl`);\n}\n\nexport function createMessageEntry(\n\tmessage: Message | CustomMessage | BashExecutionMessage,\n\tbyId: { has(id: string): boolean },\n\tparentId: string | null,\n): SessionMessageEntry {\n\treturn {\n\t\ttype: \"message\",\n\t\t...entryBase(byId, parentId),\n\t\tmessage,\n\t};\n}\n\nexport function createThinkingLevelChangeEntry(\n\tthinkingLevel: string,\n\tbyId: { has(id: string): boolean },\n\tparentId: string | null,\n): ThinkingLevelChangeEntry {\n\treturn {\n\t\ttype: \"thinking_level_change\",\n\t\t...entryBase(byId, parentId),\n\t\tthinkingLevel,\n\t};\n}\n\nexport function createContextWindowChangeEntry(\n\tcontextWindow: number,\n\tbyId: { has(id: string): boolean },\n\tparentId: string | null,\n): ContextWindowChangeEntry {\n\treturn {\n\t\ttype: \"context_window_change\",\n\t\t...entryBase(byId, parentId),\n\t\tcontextWindow,\n\t};\n}\n\nexport function createModelChangeEntry(\n\tprovider: string,\n\tmodelId: string,\n\tbyId: { has(id: string): boolean },\n\tparentId: string | null,\n): ModelChangeEntry {\n\treturn {\n\t\ttype: \"model_change\",\n\t\t...entryBase(byId, parentId),\n\t\tprovider,\n\t\tmodelId,\n\t};\n}\n\nexport function createCompactionEntry(\n\tcompactedText: string,\n\tfirstKeptEntryId: string,\n\ttokensBefore: number,\n\tdetails: VerbatimCompactionDetails,\n\tbyId: { has(id: string): boolean },\n\tparentId: string | null,\n): CompactionEntry<VerbatimCompactionDetails> {\n\treturn {\n\t\ttype: \"compaction\",\n\t\t...entryBase(byId, parentId),\n\t\tsummary: compactedText,\n\t\tfirstKeptEntryId,\n\t\ttokensBefore,\n\t\tdetails,\n\t\tfromHook: details.rung === \"extension\" || undefined,\n\t};\n}\n\n\nexport function createCustomEntry(\n\tcustomType: string,\n\tdata: unknown,\n\tbyId: { has(id: string): boolean },\n\tparentId: string | null,\n): CustomEntry {\n\treturn {\n\t\ttype: \"custom\",\n\t\tcustomType,\n\t\tdata,\n\t\t...entryBase(byId, parentId),\n\t};\n}\n\nexport function createSessionInfoEntry(\n\tname: string,\n\tbyId: { has(id: string): boolean },\n\tparentId: string | null,\n): SessionInfoEntry {\n\treturn {\n\t\ttype: \"session_info\",\n\t\t...entryBase(byId, parentId),\n\t\tname: name.trim(),\n\t};\n}\n\nexport function getLatestSessionName(entries: SessionEntry[]): string | undefined {\n\t// Walk entries in reverse to find the latest session_info entry.\n\t// Empty names explicitly clear the session title.\n\tfor (let i = entries.length - 1; i >= 0; i--) {\n\t\tconst entry = entries[i];\n\t\tif (entry.type === \"session_info\") {\n\t\t\treturn entry.name?.trim() || undefined;\n\t\t}\n\t}\n\treturn undefined;\n}\n\nexport function createCustomMessageEntry<T = unknown>(\n\tcustomType: string,\n\tcontent: string | (TextContent | ImageContent)[],\n\tdisplay: boolean,\n\tdetails: T | undefined,\n\texcludeFromContext: boolean | undefined,\n\tbyId: { has(id: string): boolean },\n\tparentId: string | null,\n): CustomMessageEntry<T> {\n\treturn {\n\t\ttype: \"custom_message\",\n\t\tcustomType,\n\t\tcontent,\n\t\tdisplay,\n\t\tdetails,\n\t\t...(excludeFromContext === true ? { excludeFromContext: true } : {}),\n\t\t...entryBase(byId, parentId),\n\t};\n}\n\nexport function createLabelEntry(\n\ttargetId: string,\n\tlabel: string | undefined,\n\tbyId: { has(id: string): boolean },\n\tparentId: string | null,\n\ttimestamp?: string,\n): LabelEntry {\n\treturn {\n\t\ttype: \"label\",\n\t\t...entryBase(byId, parentId),\n\t\t...(timestamp !== undefined ? { timestamp } : {}),\n\t\ttargetId,\n\t\tlabel,\n\t};\n}\n\nexport function createBranchSummaryEntry(\n\tbranchFromId: string | null,\n\tsummary: string,\n\tdetails: unknown,\n\tfromHook: boolean | undefined,\n\tbyId: { has(id: string): boolean },\n): BranchSummaryEntry {\n\treturn {\n\t\ttype: \"branch_summary\",\n\t\t...entryBase(byId, branchFromId),\n\t\tfromId: branchFromId ?? \"root\",\n\t\tsummary,\n\t\tdetails,\n\t\tfromHook,\n\t};\n}\n\nexport function getEntriesWithoutHeader(fileEntries: FileEntry[]): SessionEntry[] {\n\treturn fileEntries.filter((entry): entry is SessionEntry => entry.type !== \"session\");\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { join } from "path";
|
|
2
|
+
import { validSessionWorkflowMetadata } from "./session-manager-classification.js";
|
|
2
3
|
import { CURRENT_SESSION_VERSION, } from "./session-manager-types.js";
|
|
3
4
|
import { generateId } from "./session-manager-validation.js";
|
|
4
5
|
function entryBase(byId, parentId) {
|
|
@@ -18,10 +19,11 @@ export function createSessionHeader(id, cwd, timestamp = new Date().toISOString(
|
|
|
18
19
|
};
|
|
19
20
|
if (parentSession !== undefined)
|
|
20
21
|
header.parentSession = parentSession;
|
|
21
|
-
|
|
22
|
+
const validWorkflow = internal === true ? validSessionWorkflowMetadata(workflow) : undefined;
|
|
23
|
+
if (validWorkflow) {
|
|
22
24
|
header.internal = true;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
header.workflow = validWorkflow;
|
|
26
|
+
}
|
|
25
27
|
return header;
|
|
26
28
|
}
|
|
27
29
|
export function createSessionFilePath(sessionDir, timestamp, sessionId) {
|
|
@@ -57,15 +59,15 @@ export function createModelChangeEntry(provider, modelId, byId, parentId) {
|
|
|
57
59
|
modelId,
|
|
58
60
|
};
|
|
59
61
|
}
|
|
60
|
-
export function
|
|
62
|
+
export function createCompactionEntry(compactedText, firstKeptEntryId, tokensBefore, details, byId, parentId) {
|
|
61
63
|
return {
|
|
62
|
-
type: "
|
|
64
|
+
type: "compaction",
|
|
63
65
|
...entryBase(byId, parentId),
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
summary: compactedText,
|
|
67
|
+
firstKeptEntryId,
|
|
68
|
+
tokensBefore,
|
|
69
|
+
details,
|
|
70
|
+
fromHook: details.rung === "extension" || undefined,
|
|
69
71
|
};
|
|
70
72
|
}
|
|
71
73
|
export function createCustomEntry(customType, data, byId, parentId) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-manager-entries.js","sourceRoot":"","sources":["../../src/core/session-manager-entries.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,OAAO,EACN,uBAAuB,GAkBvB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAE7D,SAAS,SAAS,CAAC,IAAkC,EAAE,QAAuB;IAC7E,OAAO;QACN,EAAE,EAAE,UAAU,CAAC,IAAI,CAAC;QACpB,QAAQ;QACR,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACnC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,mBAAmB,CAClC,EAAU,EACV,GAAW,EACX,SAAS,GAAW,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAC5C,aAAsB,EACtB,QAAkB,EAClB,QAAkC;IAElC,MAAM,MAAM,GAAkB;QAC7B,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,uBAAuB;QAChC,EAAE;QACF,SAAS;QACT,GAAG;KACH,CAAC;IACF,IAAI,aAAa,KAAK,SAAS;QAAE,MAAM,CAAC,aAAa,GAAG,aAAa,CAAC;IACtE,IAAI,QAAQ;QAAE,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC;IACrC,IAAI,QAAQ;QAAE,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC;IACzC,OAAO,MAAM,CAAC;AACf,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,UAAkB,EAAE,SAAiB,EAAE,SAAiB;IAC7F,MAAM,aAAa,GAAG,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IACtD,OAAO,IAAI,CAAC,U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,OAAO;QACN,IAAI,EAAE,OAAO;QACb,GAAG,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC;QAC5B,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjD,QAAQ;QACR,KAAK;KACL,CAAC;AACH,CAAC;AAED,MAAM,UAAU,wBAAwB,CACvC,YAA2B,EAC3B,OAAe,EACf,OAAgB,EAChB,QAA6B,EAC7B,IAAkC;IAElC,OAAO;QACN,IAAI,EAAE,gBAAgB;QACtB,GAAG,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC;QAChC,MAAM,EAAE,YAAY,IAAI,MAAM;QAC9B,OAAO;QACP,OAAO;QACP,QAAQ;KACR,CAAC;AACH,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,WAAwB;IAC/D,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC,KAAK,EAAyB,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;AACvF,CAAC","sourcesContent":["import type { ImageContent, Message, TextContent } from \"@earendil-works/pi-ai/compat\";\nimport { join } from \"path\";\nimport type { BashExecutionMessage, CustomMessage } from \"./messages.ts\";\nimport {\n\tCURRENT_SESSION_VERSION,\n\ttype BranchSummaryEntry,\n\ttype ContextCompactionEntry,\n\ttype ContextCompactionStats,\n\ttype ContextDeletionTarget,\n\ttype ContextWindowChangeEntry,\n\ttype CustomEntry,\n\ttype CustomMessageEntry,\n\ttype FileEntry,\n\ttype LabelEntry,\n\ttype ModelChangeEntry,\n\ttype SessionEntry,\n\ttype SessionEntryBase,\n\ttype SessionHeader,\n\ttype SessionInfoEntry,\n\ttype SessionMessageEntry,\n\ttype SessionWorkflowMetadata,\n\ttype ThinkingLevelChangeEntry,\n} from \"./session-manager-types.ts\";\nimport { generateId } from \"./session-manager-validation.ts\";\n\nfunction entryBase(byId: { has(id: string): boolean }, parentId: string | null): Pick<SessionEntryBase, \"id\" | \"parentId\" | \"timestamp\"> {\n\treturn {\n\t\tid: generateId(byId),\n\t\tparentId,\n\t\ttimestamp: new Date().toISOString(),\n\t};\n}\n\nexport function createSessionHeader(\n\tid: string,\n\tcwd: string,\n\ttimestamp: string = new Date().toISOString(),\n\tparentSession?: string,\n\tinternal?: boolean,\n\tworkflow?: SessionWorkflowMetadata,\n): SessionHeader {\n\tconst header: SessionHeader = {\n\t\ttype: \"session\",\n\t\tversion: CURRENT_SESSION_VERSION,\n\t\tid,\n\t\ttimestamp,\n\t\tcwd,\n\t};\n\tif (parentSession !== undefined) header.parentSession = parentSession;\n\tif (internal) header.internal = true;\n\tif (workflow) header.workflow = workflow;\n\treturn header;\n}\n\nexport function createSessionFilePath(sessionDir: string, timestamp: string, sessionId: string): string {\n\tconst fileTimestamp = timestamp.replace(/[:.]/g, \"-\");\n\treturn join(sessionDir, `${fileTimestamp}_${sessionId}.jsonl`);\n}\n\nexport function createMessageEntry(\n\tmessage: Message | CustomMessage | BashExecutionMessage,\n\tbyId: { has(id: string): boolean },\n\tparentId: string | null,\n): SessionMessageEntry {\n\treturn {\n\t\ttype: \"message\",\n\t\t...entryBase(byId, parentId),\n\t\tmessage,\n\t};\n}\n\nexport function createThinkingLevelChangeEntry(\n\tthinkingLevel: string,\n\tbyId: { has(id: string): boolean },\n\tparentId: string | null,\n): ThinkingLevelChangeEntry {\n\treturn {\n\t\ttype: \"thinking_level_change\",\n\t\t...entryBase(byId, parentId),\n\t\tthinkingLevel,\n\t};\n}\n\nexport function createContextWindowChangeEntry(\n\tcontextWindow: number,\n\tbyId: { has(id: string): boolean },\n\tparentId: string | null,\n): ContextWindowChangeEntry {\n\treturn {\n\t\ttype: \"context_window_change\",\n\t\t...entryBase(byId, parentId),\n\t\tcontextWindow,\n\t};\n}\n\nexport function createModelChangeEntry(\n\tprovider: string,\n\tmodelId: string,\n\tbyId: { has(id: string): boolean },\n\tparentId: string | null,\n): ModelChangeEntry {\n\treturn {\n\t\ttype: \"model_change\",\n\t\t...entryBase(byId, parentId),\n\t\tprovider,\n\t\tmodelId,\n\t};\n}\n\nexport function createContextCompactionEntry(\n\tdeletedTargets: ContextDeletionTarget[],\n\tprotectedEntryIds: string[],\n\tstats: ContextCompactionStats,\n\tbackupPath: string | undefined,\n\tbyId: { has(id: string): boolean },\n\tparentId: string | null,\n): ContextCompactionEntry {\n\treturn {\n\t\ttype: \"context_compaction\",\n\t\t...entryBase(byId, parentId),\n\t\tpromptVersion: 1,\n\t\tdeletedTargets,\n\t\tprotectedEntryIds,\n\t\tstats,\n\t\tbackupPath,\n\t};\n}\n\nexport function createCustomEntry(\n\tcustomType: string,\n\tdata: unknown,\n\tbyId: { has(id: string): boolean },\n\tparentId: string | null,\n): CustomEntry {\n\treturn {\n\t\ttype: \"custom\",\n\t\tcustomType,\n\t\tdata,\n\t\t...entryBase(byId, parentId),\n\t};\n}\n\nexport function createSessionInfoEntry(\n\tname: string,\n\tbyId: { has(id: string): boolean },\n\tparentId: string | null,\n): SessionInfoEntry {\n\treturn {\n\t\ttype: \"session_info\",\n\t\t...entryBase(byId, parentId),\n\t\tname: name.trim(),\n\t};\n}\n\nexport function getLatestSessionName(entries: SessionEntry[]): string | undefined {\n\t// Walk entries in reverse to find the latest session_info entry.\n\t// Empty names explicitly clear the session title.\n\tfor (let i = entries.length - 1; i >= 0; i--) {\n\t\tconst entry = entries[i];\n\t\tif (entry.type === \"session_info\") {\n\t\t\treturn entry.name?.trim() || undefined;\n\t\t}\n\t}\n\treturn undefined;\n}\n\nexport function createCustomMessageEntry<T = unknown>(\n\tcustomType: string,\n\tcontent: string | (TextContent | ImageContent)[],\n\tdisplay: boolean,\n\tdetails: T | undefined,\n\texcludeFromContext: boolean | undefined,\n\tbyId: { has(id: string): boolean },\n\tparentId: string | null,\n): CustomMessageEntry<T> {\n\treturn {\n\t\ttype: \"custom_message\",\n\t\tcustomType,\n\t\tcontent,\n\t\tdisplay,\n\t\tdetails,\n\t\t...(excludeFromContext === true ? { excludeFromContext: true } : {}),\n\t\t...entryBase(byId, parentId),\n\t};\n}\n\nexport function createLabelEntry(\n\ttargetId: string,\n\tlabel: string | undefined,\n\tbyId: { has(id: string): boolean },\n\tparentId: string | null,\n\ttimestamp?: string,\n): LabelEntry {\n\treturn {\n\t\ttype: \"label\",\n\t\t...entryBase(byId, parentId),\n\t\t...(timestamp !== undefined ? { timestamp } : {}),\n\t\ttargetId,\n\t\tlabel,\n\t};\n}\n\nexport function createBranchSummaryEntry(\n\tbranchFromId: string | null,\n\tsummary: string,\n\tdetails: unknown,\n\tfromHook: boolean | undefined,\n\tbyId: { has(id: string): boolean },\n): BranchSummaryEntry {\n\treturn {\n\t\ttype: \"branch_summary\",\n\t\t...entryBase(byId, branchFromId),\n\t\tfromId: branchFromId ?? \"root\",\n\t\tsummary,\n\t\tdetails,\n\t\tfromHook,\n\t};\n}\n\nexport function getEntriesWithoutHeader(fileEntries: FileEntry[]): SessionEntry[] {\n\treturn fileEntries.filter((entry): entry is SessionEntry => entry.type !== \"session\");\n}\n"]}
|
|
1
|
+
{"version":3,"file":"session-manager-entries.js","sourceRoot":"","sources":["../../src/core/session-manager-entries.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAG5B,OAAO,EAAE,4BAA4B,EAAE,MAAM,qCAAqC,CAAC;AACnF,OAAO,EACN,uBAAuB,GAgBvB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAE7D,SAAS,SAAS,CAAC,IAAkC,EAAE,QAAuB;IAC7E,OAAO;QACN,EAAE,EAAE,UAAU,CAAC,IAAI,CAAC;QACpB,QAAQ;QACR,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACnC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,mBAAmB,CAClC,EAAU,EACV,GAAW,EACX,SAAS,GAAW,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAC5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,UAAU,uBAAuB,CAAC,WAAwB;IAC/D,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC,KAAK,EAAyB,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;AACvF,CAAC","sourcesContent":["import type { ImageContent, Message, TextContent } from \"@earendil-works/pi-ai/compat\";\nimport { join } from \"path\";\nimport type { BashExecutionMessage, CustomMessage } from \"./messages.ts\";\nimport type { VerbatimCompactionDetails } from \"./compaction/compaction-types.js\";\nimport { validSessionWorkflowMetadata } from \"./session-manager-classification.ts\";\nimport {\n\tCURRENT_SESSION_VERSION,\n\ttype BranchSummaryEntry,\n\ttype CompactionEntry,\n\ttype ContextWindowChangeEntry,\n\ttype CustomEntry,\n\ttype CustomMessageEntry,\n\ttype FileEntry,\n\ttype LabelEntry,\n\ttype ModelChangeEntry,\n\ttype SessionEntry,\n\ttype SessionEntryBase,\n\ttype SessionHeader,\n\ttype SessionInfoEntry,\n\ttype SessionMessageEntry,\n\ttype SessionWorkflowMetadata,\n\ttype ThinkingLevelChangeEntry,\n} from \"./session-manager-types.ts\";\nimport { generateId } from \"./session-manager-validation.ts\";\n\nfunction entryBase(byId: { has(id: string): boolean }, parentId: string | null): Pick<SessionEntryBase, \"id\" | \"parentId\" | \"timestamp\"> {\n\treturn {\n\t\tid: generateId(byId),\n\t\tparentId,\n\t\ttimestamp: new Date().toISOString(),\n\t};\n}\n\nexport function createSessionHeader(\n\tid: string,\n\tcwd: string,\n\ttimestamp: string = new Date().toISOString(),\n\tparentSession?: string,\n\tinternal?: boolean,\n\tworkflow?: SessionWorkflowMetadata,\n): SessionHeader {\n\tconst header: SessionHeader = {\n\t\ttype: \"session\",\n\t\tversion: CURRENT_SESSION_VERSION,\n\t\tid,\n\t\ttimestamp,\n\t\tcwd,\n\t};\n\tif (parentSession !== undefined) header.parentSession = parentSession;\n\tconst validWorkflow = internal === true ? validSessionWorkflowMetadata(workflow) : undefined;\n\tif (validWorkflow) {\n\t\theader.internal = true;\n\t\theader.workflow = validWorkflow;\n\t}\n\treturn header;\n}\n\nexport function createSessionFilePath(sessionDir: string, timestamp: string, sessionId: string): string {\n\tconst fileTimestamp = timestamp.replace(/[:.]/g, \"-\");\n\treturn join(sessionDir, `${fileTimestamp}_${sessionId}.jsonl`);\n}\n\nexport function createMessageEntry(\n\tmessage: Message | CustomMessage | BashExecutionMessage,\n\tbyId: { has(id: string): boolean },\n\tparentId: string | null,\n): SessionMessageEntry {\n\treturn {\n\t\ttype: \"message\",\n\t\t...entryBase(byId, parentId),\n\t\tmessage,\n\t};\n}\n\nexport function createThinkingLevelChangeEntry(\n\tthinkingLevel: string,\n\tbyId: { has(id: string): boolean },\n\tparentId: string | null,\n): ThinkingLevelChangeEntry {\n\treturn {\n\t\ttype: \"thinking_level_change\",\n\t\t...entryBase(byId, parentId),\n\t\tthinkingLevel,\n\t};\n}\n\nexport function createContextWindowChangeEntry(\n\tcontextWindow: number,\n\tbyId: { has(id: string): boolean },\n\tparentId: string | null,\n): ContextWindowChangeEntry {\n\treturn {\n\t\ttype: \"context_window_change\",\n\t\t...entryBase(byId, parentId),\n\t\tcontextWindow,\n\t};\n}\n\nexport function createModelChangeEntry(\n\tprovider: string,\n\tmodelId: string,\n\tbyId: { has(id: string): boolean },\n\tparentId: string | null,\n): ModelChangeEntry {\n\treturn {\n\t\ttype: \"model_change\",\n\t\t...entryBase(byId, parentId),\n\t\tprovider,\n\t\tmodelId,\n\t};\n}\n\nexport function createCompactionEntry(\n\tcompactedText: string,\n\tfirstKeptEntryId: string,\n\ttokensBefore: number,\n\tdetails: VerbatimCompactionDetails,\n\tbyId: { has(id: string): boolean },\n\tparentId: string | null,\n): CompactionEntry<VerbatimCompactionDetails> {\n\treturn {\n\t\ttype: \"compaction\",\n\t\t...entryBase(byId, parentId),\n\t\tsummary: compactedText,\n\t\tfirstKeptEntryId,\n\t\ttokensBefore,\n\t\tdetails,\n\t\tfromHook: details.rung === \"extension\" || undefined,\n\t};\n}\n\n\nexport function createCustomEntry(\n\tcustomType: string,\n\tdata: unknown,\n\tbyId: { has(id: string): boolean },\n\tparentId: string | null,\n): CustomEntry {\n\treturn {\n\t\ttype: \"custom\",\n\t\tcustomType,\n\t\tdata,\n\t\t...entryBase(byId, parentId),\n\t};\n}\n\nexport function createSessionInfoEntry(\n\tname: string,\n\tbyId: { has(id: string): boolean },\n\tparentId: string | null,\n): SessionInfoEntry {\n\treturn {\n\t\ttype: \"session_info\",\n\t\t...entryBase(byId, parentId),\n\t\tname: name.trim(),\n\t};\n}\n\nexport function getLatestSessionName(entries: SessionEntry[]): string | undefined {\n\t// Walk entries in reverse to find the latest session_info entry.\n\t// Empty names explicitly clear the session title.\n\tfor (let i = entries.length - 1; i >= 0; i--) {\n\t\tconst entry = entries[i];\n\t\tif (entry.type === \"session_info\") {\n\t\t\treturn entry.name?.trim() || undefined;\n\t\t}\n\t}\n\treturn undefined;\n}\n\nexport function createCustomMessageEntry<T = unknown>(\n\tcustomType: string,\n\tcontent: string | (TextContent | ImageContent)[],\n\tdisplay: boolean,\n\tdetails: T | undefined,\n\texcludeFromContext: boolean | undefined,\n\tbyId: { has(id: string): boolean },\n\tparentId: string | null,\n): CustomMessageEntry<T> {\n\treturn {\n\t\ttype: \"custom_message\",\n\t\tcustomType,\n\t\tcontent,\n\t\tdisplay,\n\t\tdetails,\n\t\t...(excludeFromContext === true ? { excludeFromContext: true } : {}),\n\t\t...entryBase(byId, parentId),\n\t};\n}\n\nexport function createLabelEntry(\n\ttargetId: string,\n\tlabel: string | undefined,\n\tbyId: { has(id: string): boolean },\n\tparentId: string | null,\n\ttimestamp?: string,\n): LabelEntry {\n\treturn {\n\t\ttype: \"label\",\n\t\t...entryBase(byId, parentId),\n\t\t...(timestamp !== undefined ? { timestamp } : {}),\n\t\ttargetId,\n\t\tlabel,\n\t};\n}\n\nexport function createBranchSummaryEntry(\n\tbranchFromId: string | null,\n\tsummary: string,\n\tdetails: unknown,\n\tfromHook: boolean | undefined,\n\tbyId: { has(id: string): boolean },\n): BranchSummaryEntry {\n\treturn {\n\t\ttype: \"branch_summary\",\n\t\t...entryBase(byId, branchFromId),\n\t\tfromId: branchFromId ?? \"root\",\n\t\tsummary,\n\t\tdetails,\n\t\tfromHook,\n\t};\n}\n\nexport function getEntriesWithoutHeader(fileEntries: FileEntry[]): SessionEntry[] {\n\treturn fileEntries.filter((entry): entry is SessionEntry => entry.type !== \"session\");\n}\n"]}
|
|
@@ -1,29 +1,12 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Build raw deletion filters from persisted context_compaction entries.
|
|
5
|
-
*
|
|
6
|
-
* These raw filters do not apply replay-safety repair for assistant
|
|
7
|
-
* thinking/redacted_thinking turns or their paired tool results. Production
|
|
8
|
-
* context rebuild paths should prefer `buildEffectiveContextDeletionFilters`
|
|
9
|
-
* or `buildContextDeletionFilteredPath(path)` unless they intentionally need
|
|
10
|
-
* the un-repaired historical deletion plan for diagnostics.
|
|
11
|
-
*/
|
|
12
|
-
export declare function buildContextDeletionFilters(path: SessionEntry[]): ContextDeletionFilters;
|
|
13
|
-
export declare function buildEffectiveContextDeletionFilters(path: SessionEntry[]): ContextDeletionFilters;
|
|
14
|
-
/**
|
|
15
|
-
* Return the active branch path after applying logical context-deletion entries.
|
|
16
|
-
* Whole-entry deletions remove the entry from the path. Content-block deletions
|
|
17
|
-
* clone only affected message/custom-message entries so retained blocks stay verbatim.
|
|
18
|
-
* The optional filters parameter is for callers that already computed effective
|
|
19
|
-
* filters with `buildEffectiveContextDeletionFilters(path)` and want to avoid
|
|
20
|
-
* repeating the repair pass.
|
|
21
|
-
*/
|
|
22
|
-
export declare function buildContextDeletionFilteredPath(path: SessionEntry[], effectiveFilters?: ContextDeletionFilters): SessionEntry[];
|
|
1
|
+
import type { VerbatimCompactionDetails } from "./compaction/compaction-types.js";
|
|
2
|
+
import type { CompactionEntry, FileEntry, SessionContext, SessionEntry, SessionTreeNode } from "./session-manager-types.ts";
|
|
3
|
+
export declare function getLatestCompactionBoundaryEntry(entries: SessionEntry[]): CompactionEntry<VerbatimCompactionDetails> | null;
|
|
23
4
|
/**
|
|
24
5
|
* Build the session context from entries using tree traversal.
|
|
25
6
|
* If leafId is provided, walks from that entry to root.
|
|
26
|
-
*
|
|
7
|
+
* Emits the latest verbatim compaction boundary (compacted string as a custom-role
|
|
8
|
+
* boundary message) followed by the kept tail from firstKeptEntryId, and includes
|
|
9
|
+
* branch summaries along the path.
|
|
27
10
|
*/
|
|
28
11
|
export declare function buildSessionContext(entries: SessionEntry[], leafId?: string | null, byId?: Map<string, SessionEntry>): SessionContext;
|
|
29
12
|
export interface SessionIndex {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-manager-history.d.ts","sourceRoot":"","sources":["../../src/core/session-manager-history.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACX,sBAAsB,EACtB,sBAAsB,EACtB,SAAS,EACT,cAAc,EACd,YAAY,EACZ,eAAe,EACf,MAAM,4BAA4B,CAAC;AAEpC,wBAAgB,gCAAgC,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,sBAAsB,GAAG,IAAI,CAQvG;AAED;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,sBAAsB,CAkBxF;AAoHD,wBAAgB,oCAAoC,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,sBAAsB,CA6BjG;AA0CD;;;;;;;GAOG;AACH,wBAAgB,gCAAgC,CAC/C,IAAI,EAAE,YAAY,EAAE,EACpB,gBAAgB,CAAC,EAAE,sBAAsB,GACvC,YAAY,EAAE,CA8BhB;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAClC,OAAO,EAAE,YAAY,EAAE,EACvB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,EACtB,IAAI,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,GAC9B,cAAc,CA8EhB;AAED,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAChC,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,SAAS,EAAE,GAAG,YAAY,CAsBxE;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,YAAY,EAAE,CAShH;AAED,wBAAgB,gBAAgB,CAC/B,OAAO,EAAE,YAAY,EAAE,EACvB,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,EACvC,mBAAmB,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9C,eAAe,EAAE,CAqCnB","sourcesContent":["import type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport {\n\tcreateBranchSummaryMessage,\n\tcreateCustomMessage,\n\tmessageStartsLlmUserTurn,\n\tnormalizeMessageContent,\n\tuserLikeContentIsLlmVisible,\n} from \"./messages.ts\";\nimport { normalizeDerivedSessionEntries } from \"./session-entry-normalization.ts\";\nimport { contentArrayHasAssistantThinkingBlock } from \"./thinking-blocks.ts\";\nimport { reconcilePersistedToolDependencyFilters } from \"./session-manager-tool-dependencies.ts\";\nimport { analyzeAssistantToolUseTurns, type AssistantTurnEntry } from \"./compaction/context-assistant-turns.js\";\nimport type {\n\tContextCompactionEntry,\n\tContextDeletionFilters,\n\tFileEntry,\n\tSessionContext,\n\tSessionEntry,\n\tSessionTreeNode,\n} from \"./session-manager-types.ts\";\n\nexport function getLatestCompactionBoundaryEntry(entries: SessionEntry[]): ContextCompactionEntry | null {\n\tfor (let i = entries.length - 1; i >= 0; i--) {\n\t\tconst entry = entries[i];\n\t\tif (entry.type === \"context_compaction\") {\n\t\t\treturn entry;\n\t\t}\n\t}\n\treturn null;\n}\n\n/**\n * Build raw deletion filters from persisted context_compaction entries.\n *\n * These raw filters do not apply replay-safety repair for assistant\n * thinking/redacted_thinking turns or their paired tool results. Production\n * context rebuild paths should prefer `buildEffectiveContextDeletionFilters`\n * or `buildContextDeletionFilteredPath(path)` unless they intentionally need\n * the un-repaired historical deletion plan for diagnostics.\n */\nexport function buildContextDeletionFilters(path: SessionEntry[]): ContextDeletionFilters {\n\tconst deletedEntryIds = new Set<string>();\n\tconst deletedContentBlocks = new Map<string, Set<number>>();\n\n\tfor (const entry of path) {\n\t\tif (entry.type !== \"context_compaction\") continue;\n\t\tfor (const target of entry.deletedTargets) {\n\t\t\tif (target.kind === \"entry\") {\n\t\t\t\tdeletedEntryIds.add(target.entryId);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst existing = deletedContentBlocks.get(target.entryId) ?? new Set<number>();\n\t\t\texisting.add(target.blockIndex);\n\t\t\tdeletedContentBlocks.set(target.entryId, existing);\n\t\t}\n\t}\n\n\treturn { deletedEntryIds, deletedContentBlocks };\n}\n\nfunction restoreEntry(filters: ContextDeletionFilters, entryId: string): void {\n\tfilters.deletedEntryIds.delete(entryId);\n\tfilters.deletedContentBlocks.delete(entryId);\n}\n\nfunction addDeletionTarget(\n\tfilters: ContextDeletionFilters,\n\ttarget: ContextCompactionEntry[\"deletedTargets\"][number],\n): void {\n\tif (target.kind === \"entry\") {\n\t\tfilters.deletedEntryIds.add(target.entryId);\n\t\tfilters.deletedContentBlocks.delete(target.entryId);\n\t\treturn;\n\t}\n\tif (filters.deletedEntryIds.has(target.entryId)) return;\n\tconst existing = filters.deletedContentBlocks.get(target.entryId) ?? new Set<number>();\n\texisting.add(target.blockIndex);\n\tfilters.deletedContentBlocks.set(target.entryId, existing);\n}\n\nfunction sessionBoundaryIsVisible(entry: SessionEntry, filters: ContextDeletionFilters): boolean {\n\tif (filters.deletedEntryIds.has(entry.id)) return false;\n\tconst deletedBlocks = filters.deletedContentBlocks.get(entry.id);\n\tif (entry.type === \"custom_message\") {\n\t\treturn entry.excludeFromContext !== true && userLikeContentIsLlmVisible(entry.content, deletedBlocks);\n\t}\n\tif (entry.type === \"branch_summary\") return typeof entry.summary === \"string\" && entry.summary.length > 0;\n\tif (entry.type !== \"message\") return false;\n\treturn messageStartsLlmUserTurn(entry.message, deletedBlocks);\n}\n\nfunction sessionEntryAsTurnEntry(\n\tentry: SessionEntry,\n\tfilters: ContextDeletionFilters,\n): AssistantTurnEntry | undefined {\n\tif (entry.type === \"custom_message\") {\n\t\tif (entry.excludeFromContext === true) return undefined;\n\t\treturn {\n\t\t\tentryId: entry.id,\n\t\t\trole: \"custom\",\n\t\t\thasSignedThinking: false,\n\t\t\tstartsNewTurn: sessionBoundaryIsVisible(entry, filters),\n\t\t};\n\t}\n\tif (entry.type === \"branch_summary\") {\n\t\treturn {\n\t\t\tentryId: entry.id,\n\t\t\trole: \"branchSummary\",\n\t\t\thasSignedThinking: false,\n\t\t\tstartsNewTurn: sessionBoundaryIsVisible(entry, filters),\n\t\t};\n\t}\n\tif (entry.type !== \"message\") return undefined;\n\tconst message = entry.message;\n\tif (message.role === \"compactionSummary\") return undefined;\n\tif (\n\t\t(message.role === \"bashExecution\" && message.excludeFromContext === true) ||\n\t\t(message.role === \"custom\" && (message as { excludeFromContext?: boolean }).excludeFromContext === true)\n\t) {\n\t\treturn undefined;\n\t}\n\treturn {\n\t\tentryId: entry.id,\n\t\trole: message.role,\n\t\thasSignedThinking: message.role === \"assistant\" && contentArrayHasAssistantThinkingBlock(message.content),\n\t\tstartsNewTurn: sessionBoundaryIsVisible(entry, filters),\n\t};\n}\n\nfunction analyzeSessionAssistantTurns(path: SessionEntry[], filters: ContextDeletionFilters) {\n\treturn analyzeAssistantToolUseTurns(path.flatMap((entry) => sessionEntryAsTurnEntry(entry, filters) ?? []));\n}\n\nfunction repairSignedThinkingTurnFilters(path: SessionEntry[], filters: ContextDeletionFilters): ContextDeletionFilters {\n\tconst turns = analyzeSessionAssistantTurns(path, filters);\n\n\t// A retained signed assistant is byte-exact/all-or-nothing at message level.\n\t// Whole-entry deletion alone counts toward a safe historical omission.\n\tfor (const turn of turns) {\n\t\tfor (const entryId of turn.signedThinkingEntryIds) {\n\t\t\tif (!filters.deletedEntryIds.has(entryId)) filters.deletedContentBlocks.delete(entryId);\n\t\t}\n\t}\n\n\tfor (const turn of turns) {\n\t\tconst deletedSignedIds = turn.signedThinkingEntryIds.filter((entryId) => filters.deletedEntryIds.has(entryId));\n\t\tconst unsafe = turn.active\n\t\t\t? deletedSignedIds.length > 0\n\t\t\t: deletedSignedIds.length > 0 && deletedSignedIds.length < turn.signedThinkingEntryIds.length;\n\t\tif (!unsafe) continue;\n\t\tfor (const entryId of turn.signedThinkingEntryIds) restoreEntry(filters, entryId);\n\t}\n\treturn filters;\n}\n\nfunction signedTurnReplayPolicy(\n\tpath: SessionEntry[],\n\tfinalIntent: ContextDeletionFilters,\n): { restoredEntryIds: Set<string>; retainedEntryIds: Set<string> } {\n\tconst restoredEntryIds = new Set<string>();\n\tconst retainedEntryIds = new Set<string>();\n\tfor (const turn of analyzeSessionAssistantTurns(path, finalIntent)) {\n\t\tconst deleted = turn.signedThinkingEntryIds.filter((entryId) => finalIntent.deletedEntryIds.has(entryId));\n\t\tconst restoreTurn = turn.active\n\t\t\t? deleted.length > 0\n\t\t\t: deleted.length > 0 && deleted.length < turn.signedThinkingEntryIds.length;\n\t\tfor (const entryId of turn.signedThinkingEntryIds) {\n\t\t\tif (restoreTurn) restoredEntryIds.add(entryId);\n\t\t\tif (restoreTurn || !finalIntent.deletedEntryIds.has(entryId)) retainedEntryIds.add(entryId);\n\t\t}\n\t}\n\treturn { restoredEntryIds, retainedEntryIds };\n}\n\nexport function buildEffectiveContextDeletionFilters(path: SessionEntry[]): ContextDeletionFilters {\n\tconst derivedPath = normalizeDerivedSessionEntries(path);\n\tconst finalIntent = buildContextDeletionFilters(derivedPath);\n\tif (!derivedPath.some((entry) => entry.type === \"context_compaction\")) return finalIntent;\n\n\t// Decide turn-level restoration from the cumulative durable intent so safe\n\t// complete historical omissions may span multiple compaction entries. Then\n\t// replay each entry chronologically: reconciliation at each boundary restores\n\t// an unsafe paired whole-result deletion without erasing a later independent\n\t// content-block deletion on that result.\n\tconst { restoredEntryIds, retainedEntryIds } = signedTurnReplayPolicy(derivedPath, finalIntent);\n\tconst effective: ContextDeletionFilters = {\n\t\tdeletedEntryIds: new Set<string>(),\n\t\tdeletedContentBlocks: new Map<string, Set<number>>(),\n\t};\n\tfor (const entry of derivedPath) {\n\t\tif (entry.type !== \"context_compaction\") continue;\n\t\tfor (const target of entry.deletedTargets) {\n\t\t\tif (target.kind === \"entry\" && restoredEntryIds.has(target.entryId)) continue;\n\t\t\tif (target.kind === \"content_block\" && retainedEntryIds.has(target.entryId)) continue;\n\t\t\taddDeletionTarget(effective, target);\n\t\t}\n\t\treconcilePersistedToolDependencyFilters(derivedPath, effective);\n\t}\n\n\t// Defensive final repair handles malformed dependency graphs and keeps this\n\t// reconstruction path authoritative even if reconciliation behavior evolves.\n\trepairSignedThinkingTurnFilters(derivedPath, effective);\n\treturn reconcilePersistedToolDependencyFilters(derivedPath, effective);\n}\n\nfunction filterContentArray<T>(content: T[], deletedBlocks: ReadonlySet<number>): T[] {\n\treturn content.filter((_, index) => !deletedBlocks.has(index));\n}\n\nfunction filterMessageContentBlocks(\n\tmessage: AgentMessage,\n\tdeletedBlocks: ReadonlySet<number> | undefined,\n): AgentMessage | undefined {\n\tif (!deletedBlocks || deletedBlocks.size === 0) return message;\n\n\tswitch (message.role) {\n\t\tcase \"user\": {\n\t\t\tif (!Array.isArray(message.content)) return message;\n\t\t\tconst content = filterContentArray(message.content, deletedBlocks);\n\t\t\tif (content.length === 0) return undefined;\n\t\t\treturn { ...message, content };\n\t\t}\n\t\tcase \"assistant\": {\n\t\t\tconst content = filterContentArray(message.content, deletedBlocks);\n\t\t\tif (content.length === 0) return undefined;\n\t\t\treturn { ...message, content };\n\t\t}\n\t\tcase \"toolResult\": {\n\t\t\tif (!Array.isArray(message.content)) return message;\n\t\t\tconst content = filterContentArray(message.content, deletedBlocks);\n\t\t\tif (content.length === 0) return undefined;\n\t\t\treturn { ...message, content };\n\t\t}\n\t\tcase \"custom\": {\n\t\t\tif (!Array.isArray(message.content)) return message;\n\t\t\tconst content = filterContentArray(message.content, deletedBlocks);\n\t\t\tif (content.length === 0) return undefined;\n\t\t\treturn { ...message, content };\n\t\t}\n\t\tcase \"bashExecution\":\n\t\tcase \"branchSummary\":\n\t\t\treturn message;\n\t}\n}\n\n/**\n * Return the active branch path after applying logical context-deletion entries.\n * Whole-entry deletions remove the entry from the path. Content-block deletions\n * clone only affected message/custom-message entries so retained blocks stay verbatim.\n * The optional filters parameter is for callers that already computed effective\n * filters with `buildEffectiveContextDeletionFilters(path)` and want to avoid\n * repeating the repair pass.\n */\nexport function buildContextDeletionFilteredPath(\n\tpath: SessionEntry[],\n\teffectiveFilters?: ContextDeletionFilters,\n): SessionEntry[] {\n\tconst derivedPath = normalizeDerivedSessionEntries(path);\n\tconst filters = effectiveFilters ?? buildEffectiveContextDeletionFilters(derivedPath);\n\tconst filteredPath: SessionEntry[] = [];\n\n\tfor (const entry of derivedPath) {\n\t\tif (filters.deletedEntryIds.has(entry.id)) continue;\n\n\t\tconst deletedBlocks = filters.deletedContentBlocks.get(entry.id);\n\t\tif (!deletedBlocks || deletedBlocks.size === 0) {\n\t\t\tfilteredPath.push(entry);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (entry.type === \"message\") {\n\t\t\tconst message = filterMessageContentBlocks(entry.message, deletedBlocks);\n\t\t\tif (message) filteredPath.push({ ...entry, message });\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (entry.type === \"custom_message\" && Array.isArray(entry.content)) {\n\t\t\tconst content = filterContentArray(entry.content, deletedBlocks);\n\t\t\tif (content.length > 0) filteredPath.push({ ...entry, content });\n\t\t\tcontinue;\n\t\t}\n\n\t\tfilteredPath.push(entry);\n\t}\n\n\treturn filteredPath;\n}\n\n/**\n * Build the session context from entries using tree traversal.\n * If leafId is provided, walks from that entry to root.\n * Applies context-deletion filtering and includes branch summaries along the path.\n */\nexport function buildSessionContext(\n\tentries: SessionEntry[],\n\tleafId?: string | null,\n\tbyId?: Map<string, SessionEntry>,\n): SessionContext {\n\t// Build uuid index if not available\n\tif (!byId) {\n\t\tbyId = new Map<string, SessionEntry>();\n\t\tfor (const entry of entries) {\n\t\t\tbyId.set(entry.id, entry);\n\t\t}\n\t}\n\n\t// Find leaf\n\tlet leaf: SessionEntry | undefined;\n\tif (leafId === null) {\n\t\t// Explicitly null - return no messages (navigated to before first entry)\n\t\treturn { messages: [], thinkingLevel: \"off\", contextWindow: undefined, model: null };\n\t}\n\tif (leafId) {\n\t\tleaf = byId.get(leafId);\n\t}\n\tif (!leaf) {\n\t\t// Fallback to last entry (when leafId is undefined)\n\t\tleaf = entries[entries.length - 1];\n\t}\n\n\tif (!leaf) {\n\t\treturn { messages: [], thinkingLevel: \"off\", contextWindow: undefined, model: null };\n\t}\n\n\t// Walk from leaf to root, collecting path\n\tconst path = normalizeDerivedSessionEntries(getBranchPath(leaf.id, byId));\n\n\t// Extract settings\n\tlet thinkingLevel = \"off\";\n\tlet contextWindow: number | undefined;\n\tlet model: { provider: string; modelId: string } | null = null;\n\n\tfor (const entry of path) {\n\t\tif (entry.type === \"thinking_level_change\") {\n\t\t\tthinkingLevel = entry.thinkingLevel;\n\t\t} else if (entry.type === \"context_window_change\") {\n\t\t\tcontextWindow = entry.contextWindow;\n\t\t} else if (entry.type === \"model_change\") {\n\t\t\tmodel = { provider: entry.provider, modelId: entry.modelId };\n\t\t} else if (entry.type === \"message\" && entry.message.role === \"assistant\") {\n\t\t\tmodel = { provider: entry.message.provider, modelId: entry.message.model };\n\t\t}\n\t}\n\n\tconst filteredPath = buildContextDeletionFilteredPath(path);\n\n\t// Build active context messages from the filtered path. Legacy \"compaction\"\n\t// entries are archival metadata and intentionally inert here.\n\tconst messages: AgentMessage[] = [];\n\n\tconst appendMessage = (entry: SessionEntry) => {\n\t\tlet message: AgentMessage | undefined;\n\t\tif (entry.type === \"message\") {\n\t\t\tmessage = normalizeMessageContent(entry.message);\n\t\t} else if (entry.type === \"custom_message\") {\n\t\t\tmessage = createCustomMessage(\n\t\t\t\tentry.customType,\n\t\t\t\tentry.content,\n\t\t\t\tentry.display,\n\t\t\t\tentry.details,\n\t\t\t\tentry.timestamp,\n\t\t\t\tentry.excludeFromContext,\n\t\t\t);\n\t\t} else if (entry.type === \"branch_summary\" && typeof entry.summary === \"string\" && entry.summary.length > 0) {\n\t\t\tmessage = createBranchSummaryMessage(entry.summary, entry.fromId, entry.timestamp);\n\t\t}\n\n\t\tif (message) messages.push(message);\n\t};\n\n\tfor (const entry of filteredPath) {\n\t\tappendMessage(entry);\n\t}\n\n\treturn { messages, thinkingLevel, contextWindow, model };\n}\n\nexport interface SessionIndex {\n\tbyId: Map<string, SessionEntry>;\n\tlabelsById: Map<string, string>;\n\tlabelTimestampsById: Map<string, string>;\n\tleafId: string | null;\n}\n\nexport function buildSessionIndex(fileEntries: FileEntry[]): SessionIndex {\n\tconst byId = new Map<string, SessionEntry>();\n\tconst labelsById = new Map<string, string>();\n\tconst labelTimestampsById = new Map<string, string>();\n\tlet leafId: string | null = null;\n\n\tfor (const entry of fileEntries) {\n\t\tif (entry.type === \"session\") continue;\n\t\tbyId.set(entry.id, entry);\n\t\tleafId = entry.id;\n\t\tif (entry.type === \"label\") {\n\t\t\tif (entry.label) {\n\t\t\t\tlabelsById.set(entry.targetId, entry.label);\n\t\t\t\tlabelTimestampsById.set(entry.targetId, entry.timestamp);\n\t\t\t} else {\n\t\t\t\tlabelsById.delete(entry.targetId);\n\t\t\t\tlabelTimestampsById.delete(entry.targetId);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn { byId, labelsById, labelTimestampsById, leafId };\n}\n\nexport function getBranchPath(fromId: string | null | undefined, byId: Map<string, SessionEntry>): SessionEntry[] {\n\tconst path: SessionEntry[] = [];\n\tlet current = fromId ? byId.get(fromId) : undefined;\n\twhile (current) {\n\t\tpath.push(current);\n\t\tcurrent = current.parentId ? byId.get(current.parentId) : undefined;\n\t}\n\tpath.reverse();\n\treturn path;\n}\n\nexport function buildSessionTree(\n\tentries: SessionEntry[],\n\tlabelsById: ReadonlyMap<string, string>,\n\tlabelTimestampsById: ReadonlyMap<string, string>,\n): SessionTreeNode[] {\n\tconst nodeMap = new Map<string, SessionTreeNode>();\n\tconst roots: SessionTreeNode[] = [];\n\n\t// Create nodes with resolved labels\n\tfor (const entry of entries) {\n\t\tconst label = labelsById.get(entry.id);\n\t\tconst labelTimestamp = labelTimestampsById.get(entry.id);\n\t\tnodeMap.set(entry.id, { entry, children: [], label, labelTimestamp });\n\t}\n\n\t// Build tree\n\tfor (const entry of entries) {\n\t\tconst node = nodeMap.get(entry.id)!;\n\t\tif (entry.parentId === null || entry.parentId === entry.id) {\n\t\t\troots.push(node);\n\t\t} else {\n\t\t\tconst parent = nodeMap.get(entry.parentId);\n\t\t\tif (parent) {\n\t\t\t\tparent.children.push(node);\n\t\t\t} else {\n\t\t\t\t// Orphan - treat as root\n\t\t\t\troots.push(node);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Sort children by timestamp (oldest first, newest at bottom)\n\t// Use iterative approach to avoid stack overflow on deep trees\n\tconst stack: SessionTreeNode[] = [...roots];\n\twhile (stack.length > 0) {\n\t\tconst node = stack.pop()!;\n\t\tnode.children.sort((a, b) => new Date(a.entry.timestamp).getTime() - new Date(b.entry.timestamp).getTime());\n\t\tstack.push(...node.children);\n\t}\n\n\treturn roots;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"session-manager-history.d.ts","sourceRoot":"","sources":["../../src/core/session-manager-history.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,cAAc,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE5H,wBAAgB,gCAAgC,CAC/C,OAAO,EAAE,YAAY,EAAE,GACrB,eAAe,CAAC,yBAAyB,CAAC,GAAG,IAAI,CAQnD;AAGD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAClC,OAAO,EAAE,YAAY,EAAE,EACvB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,EACtB,IAAI,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,GAC9B,cAAc,CAoFhB;AAED,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAChC,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,SAAS,EAAE,GAAG,YAAY,CAsBxE;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,YAAY,EAAE,CAShH;AAED,wBAAgB,gBAAgB,CAC/B,OAAO,EAAE,YAAY,EAAE,EACvB,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,EACvC,mBAAmB,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9C,eAAe,EAAE,CAqCnB","sourcesContent":["import type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport { createBranchSummaryMessage, createCustomMessage, createVerbatimCompactionMessage, normalizeMessageContent } from \"./messages.ts\";\nimport { normalizeDerivedSessionEntries } from \"./session-entry-normalization.ts\";\nimport type { VerbatimCompactionDetails } from \"./compaction/compaction-types.js\";\nimport type { CompactionEntry, FileEntry, SessionContext, SessionEntry, SessionTreeNode } from \"./session-manager-types.ts\";\n\nexport function getLatestCompactionBoundaryEntry(\n\tentries: SessionEntry[],\n): CompactionEntry<VerbatimCompactionDetails> | null {\n\tfor (let i = entries.length - 1; i >= 0; i--) {\n\t\tconst entry = entries[i];\n\t\tif (entry.type !== \"compaction\") continue;\n\t\tconst details = (entry as CompactionEntry<{ strategy?: string }>).details;\n\t\tif (details?.strategy === \"verbatim-lines\") return entry as CompactionEntry<VerbatimCompactionDetails>;\n\t}\n\treturn null;\n}\n\n\n/**\n * Build the session context from entries using tree traversal.\n * If leafId is provided, walks from that entry to root.\n * Emits the latest verbatim compaction boundary (compacted string as a custom-role\n * boundary message) followed by the kept tail from firstKeptEntryId, and includes\n * branch summaries along the path.\n */\nexport function buildSessionContext(\n\tentries: SessionEntry[],\n\tleafId?: string | null,\n\tbyId?: Map<string, SessionEntry>,\n): SessionContext {\n\t// Build uuid index if not available\n\tif (!byId) {\n\t\tbyId = new Map<string, SessionEntry>();\n\t\tfor (const entry of entries) {\n\t\t\tbyId.set(entry.id, entry);\n\t\t}\n\t}\n\n\t// Find leaf\n\tlet leaf: SessionEntry | undefined;\n\tif (leafId === null) {\n\t\t// Explicitly null - return no messages (navigated to before first entry)\n\t\treturn { messages: [], thinkingLevel: \"off\", contextWindow: undefined, model: null };\n\t}\n\tif (leafId) {\n\t\tleaf = byId.get(leafId);\n\t}\n\tif (!leaf) {\n\t\t// Fallback to last entry (when leafId is undefined)\n\t\tleaf = entries[entries.length - 1];\n\t}\n\n\tif (!leaf) {\n\t\treturn { messages: [], thinkingLevel: \"off\", contextWindow: undefined, model: null };\n\t}\n\n\t// Walk from leaf to root, collecting path\n\tconst path = normalizeDerivedSessionEntries(getBranchPath(leaf.id, byId));\n\n\t// Extract settings\n\tlet thinkingLevel = \"off\";\n\tlet contextWindow: number | undefined;\n\tlet model: { provider: string; modelId: string } | null = null;\n\n\tfor (const entry of path) {\n\t\tif (entry.type === \"thinking_level_change\") {\n\t\t\tthinkingLevel = entry.thinkingLevel;\n\t\t} else if (entry.type === \"context_window_change\") {\n\t\t\tcontextWindow = entry.contextWindow;\n\t\t} else if (entry.type === \"model_change\") {\n\t\t\tmodel = { provider: entry.provider, modelId: entry.modelId };\n\t\t} else if (entry.type === \"message\" && entry.message.role === \"assistant\") {\n\t\t\tmodel = { provider: entry.message.provider, modelId: entry.message.model };\n\t\t}\n\t}\n\n\tconst messages: AgentMessage[] = [];\n\tconst appendMessage = (entry: SessionEntry): void => {\n\t\tlet message: AgentMessage | undefined;\n\t\tif (entry.type === \"message\") {\n\t\t\tmessage = normalizeMessageContent(entry.message);\n\t\t} else if (entry.type === \"custom_message\") {\n\t\t\tmessage = createCustomMessage(\n\t\t\t\tentry.customType,\n\t\t\t\tentry.content,\n\t\t\t\tentry.display,\n\t\t\t\tentry.details,\n\t\t\t\tentry.timestamp,\n\t\t\t\tentry.excludeFromContext,\n\t\t\t);\n\t\t} else if (entry.type === \"branch_summary\" && typeof entry.summary === \"string\" && entry.summary.length > 0) {\n\t\t\tmessage = createBranchSummaryMessage(entry.summary, entry.fromId, entry.timestamp);\n\t\t}\n\t\tif (message) messages.push(message);\n\t};\n\n\tconst boundary = getLatestCompactionBoundaryEntry(path);\n\tif (!boundary) {\n\t\tfor (const entry of path) appendMessage(entry);\n\t\treturn { messages, thinkingLevel, contextWindow, model };\n\t}\n\n\tconst boundaryIndex = path.findIndex((entry) => entry.id === boundary.id);\n\tmessages.push(createVerbatimCompactionMessage(boundary.summary, boundary.tokensBefore, boundary.timestamp, boundary.details));\n\tconst firstKeptIndex = path.findIndex(\n\t\t(entry, index) => index < boundaryIndex && entry.id === boundary.firstKeptEntryId,\n\t);\n\tif (firstKeptIndex >= 0) {\n\t\tfor (let i = firstKeptIndex; i < boundaryIndex; i++) appendMessage(path[i]);\n\t}\n\tfor (let i = boundaryIndex + 1; i < path.length; i++) appendMessage(path[i]);\n\n\treturn { messages, thinkingLevel, contextWindow, model };\n}\n\nexport interface SessionIndex {\n\tbyId: Map<string, SessionEntry>;\n\tlabelsById: Map<string, string>;\n\tlabelTimestampsById: Map<string, string>;\n\tleafId: string | null;\n}\n\nexport function buildSessionIndex(fileEntries: FileEntry[]): SessionIndex {\n\tconst byId = new Map<string, SessionEntry>();\n\tconst labelsById = new Map<string, string>();\n\tconst labelTimestampsById = new Map<string, string>();\n\tlet leafId: string | null = null;\n\n\tfor (const entry of fileEntries) {\n\t\tif (entry.type === \"session\") continue;\n\t\tbyId.set(entry.id, entry);\n\t\tleafId = entry.id;\n\t\tif (entry.type === \"label\") {\n\t\t\tif (entry.label) {\n\t\t\t\tlabelsById.set(entry.targetId, entry.label);\n\t\t\t\tlabelTimestampsById.set(entry.targetId, entry.timestamp);\n\t\t\t} else {\n\t\t\t\tlabelsById.delete(entry.targetId);\n\t\t\t\tlabelTimestampsById.delete(entry.targetId);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn { byId, labelsById, labelTimestampsById, leafId };\n}\n\nexport function getBranchPath(fromId: string | null | undefined, byId: Map<string, SessionEntry>): SessionEntry[] {\n\tconst path: SessionEntry[] = [];\n\tlet current = fromId ? byId.get(fromId) : undefined;\n\twhile (current) {\n\t\tpath.push(current);\n\t\tcurrent = current.parentId ? byId.get(current.parentId) : undefined;\n\t}\n\tpath.reverse();\n\treturn path;\n}\n\nexport function buildSessionTree(\n\tentries: SessionEntry[],\n\tlabelsById: ReadonlyMap<string, string>,\n\tlabelTimestampsById: ReadonlyMap<string, string>,\n): SessionTreeNode[] {\n\tconst nodeMap = new Map<string, SessionTreeNode>();\n\tconst roots: SessionTreeNode[] = [];\n\n\t// Create nodes with resolved labels\n\tfor (const entry of entries) {\n\t\tconst label = labelsById.get(entry.id);\n\t\tconst labelTimestamp = labelTimestampsById.get(entry.id);\n\t\tnodeMap.set(entry.id, { entry, children: [], label, labelTimestamp });\n\t}\n\n\t// Build tree\n\tfor (const entry of entries) {\n\t\tconst node = nodeMap.get(entry.id)!;\n\t\tif (entry.parentId === null || entry.parentId === entry.id) {\n\t\t\troots.push(node);\n\t\t} else {\n\t\t\tconst parent = nodeMap.get(entry.parentId);\n\t\t\tif (parent) {\n\t\t\t\tparent.children.push(node);\n\t\t\t} else {\n\t\t\t\t// Orphan - treat as root\n\t\t\t\troots.push(node);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Sort children by timestamp (oldest first, newest at bottom)\n\t// Use iterative approach to avoid stack overflow on deep trees\n\tconst stack: SessionTreeNode[] = [...roots];\n\twhile (stack.length > 0) {\n\t\tconst node = stack.pop()!;\n\t\tnode.children.sort((a, b) => new Date(a.entry.timestamp).getTime() - new Date(b.entry.timestamp).getTime());\n\t\tstack.push(...node.children);\n\t}\n\n\treturn roots;\n}\n"]}
|
|
@@ -1,264 +1,22 @@
|
|
|
1
|
-
import { createBranchSummaryMessage, createCustomMessage,
|
|
1
|
+
import { createBranchSummaryMessage, createCustomMessage, createVerbatimCompactionMessage, normalizeMessageContent } from "./messages.js";
|
|
2
2
|
import { normalizeDerivedSessionEntries } from "./session-entry-normalization.js";
|
|
3
|
-
import { contentArrayHasAssistantThinkingBlock } from "./thinking-blocks.js";
|
|
4
|
-
import { reconcilePersistedToolDependencyFilters } from "./session-manager-tool-dependencies.js";
|
|
5
|
-
import { analyzeAssistantToolUseTurns } from "./compaction/context-assistant-turns.js";
|
|
6
3
|
export function getLatestCompactionBoundaryEntry(entries) {
|
|
7
4
|
for (let i = entries.length - 1; i >= 0; i--) {
|
|
8
5
|
const entry = entries[i];
|
|
9
|
-
if (entry.type
|
|
6
|
+
if (entry.type !== "compaction")
|
|
7
|
+
continue;
|
|
8
|
+
const details = entry.details;
|
|
9
|
+
if (details?.strategy === "verbatim-lines")
|
|
10
10
|
return entry;
|
|
11
|
-
}
|
|
12
11
|
}
|
|
13
12
|
return null;
|
|
14
13
|
}
|
|
15
|
-
/**
|
|
16
|
-
* Build raw deletion filters from persisted context_compaction entries.
|
|
17
|
-
*
|
|
18
|
-
* These raw filters do not apply replay-safety repair for assistant
|
|
19
|
-
* thinking/redacted_thinking turns or their paired tool results. Production
|
|
20
|
-
* context rebuild paths should prefer `buildEffectiveContextDeletionFilters`
|
|
21
|
-
* or `buildContextDeletionFilteredPath(path)` unless they intentionally need
|
|
22
|
-
* the un-repaired historical deletion plan for diagnostics.
|
|
23
|
-
*/
|
|
24
|
-
export function buildContextDeletionFilters(path) {
|
|
25
|
-
const deletedEntryIds = new Set();
|
|
26
|
-
const deletedContentBlocks = new Map();
|
|
27
|
-
for (const entry of path) {
|
|
28
|
-
if (entry.type !== "context_compaction")
|
|
29
|
-
continue;
|
|
30
|
-
for (const target of entry.deletedTargets) {
|
|
31
|
-
if (target.kind === "entry") {
|
|
32
|
-
deletedEntryIds.add(target.entryId);
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
const existing = deletedContentBlocks.get(target.entryId) ?? new Set();
|
|
36
|
-
existing.add(target.blockIndex);
|
|
37
|
-
deletedContentBlocks.set(target.entryId, existing);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return { deletedEntryIds, deletedContentBlocks };
|
|
41
|
-
}
|
|
42
|
-
function restoreEntry(filters, entryId) {
|
|
43
|
-
filters.deletedEntryIds.delete(entryId);
|
|
44
|
-
filters.deletedContentBlocks.delete(entryId);
|
|
45
|
-
}
|
|
46
|
-
function addDeletionTarget(filters, target) {
|
|
47
|
-
if (target.kind === "entry") {
|
|
48
|
-
filters.deletedEntryIds.add(target.entryId);
|
|
49
|
-
filters.deletedContentBlocks.delete(target.entryId);
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
if (filters.deletedEntryIds.has(target.entryId))
|
|
53
|
-
return;
|
|
54
|
-
const existing = filters.deletedContentBlocks.get(target.entryId) ?? new Set();
|
|
55
|
-
existing.add(target.blockIndex);
|
|
56
|
-
filters.deletedContentBlocks.set(target.entryId, existing);
|
|
57
|
-
}
|
|
58
|
-
function sessionBoundaryIsVisible(entry, filters) {
|
|
59
|
-
if (filters.deletedEntryIds.has(entry.id))
|
|
60
|
-
return false;
|
|
61
|
-
const deletedBlocks = filters.deletedContentBlocks.get(entry.id);
|
|
62
|
-
if (entry.type === "custom_message") {
|
|
63
|
-
return entry.excludeFromContext !== true && userLikeContentIsLlmVisible(entry.content, deletedBlocks);
|
|
64
|
-
}
|
|
65
|
-
if (entry.type === "branch_summary")
|
|
66
|
-
return typeof entry.summary === "string" && entry.summary.length > 0;
|
|
67
|
-
if (entry.type !== "message")
|
|
68
|
-
return false;
|
|
69
|
-
return messageStartsLlmUserTurn(entry.message, deletedBlocks);
|
|
70
|
-
}
|
|
71
|
-
function sessionEntryAsTurnEntry(entry, filters) {
|
|
72
|
-
if (entry.type === "custom_message") {
|
|
73
|
-
if (entry.excludeFromContext === true)
|
|
74
|
-
return undefined;
|
|
75
|
-
return {
|
|
76
|
-
entryId: entry.id,
|
|
77
|
-
role: "custom",
|
|
78
|
-
hasSignedThinking: false,
|
|
79
|
-
startsNewTurn: sessionBoundaryIsVisible(entry, filters),
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
if (entry.type === "branch_summary") {
|
|
83
|
-
return {
|
|
84
|
-
entryId: entry.id,
|
|
85
|
-
role: "branchSummary",
|
|
86
|
-
hasSignedThinking: false,
|
|
87
|
-
startsNewTurn: sessionBoundaryIsVisible(entry, filters),
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
if (entry.type !== "message")
|
|
91
|
-
return undefined;
|
|
92
|
-
const message = entry.message;
|
|
93
|
-
if (message.role === "compactionSummary")
|
|
94
|
-
return undefined;
|
|
95
|
-
if ((message.role === "bashExecution" && message.excludeFromContext === true) ||
|
|
96
|
-
(message.role === "custom" && message.excludeFromContext === true)) {
|
|
97
|
-
return undefined;
|
|
98
|
-
}
|
|
99
|
-
return {
|
|
100
|
-
entryId: entry.id,
|
|
101
|
-
role: message.role,
|
|
102
|
-
hasSignedThinking: message.role === "assistant" && contentArrayHasAssistantThinkingBlock(message.content),
|
|
103
|
-
startsNewTurn: sessionBoundaryIsVisible(entry, filters),
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
function analyzeSessionAssistantTurns(path, filters) {
|
|
107
|
-
return analyzeAssistantToolUseTurns(path.flatMap((entry) => sessionEntryAsTurnEntry(entry, filters) ?? []));
|
|
108
|
-
}
|
|
109
|
-
function repairSignedThinkingTurnFilters(path, filters) {
|
|
110
|
-
const turns = analyzeSessionAssistantTurns(path, filters);
|
|
111
|
-
// A retained signed assistant is byte-exact/all-or-nothing at message level.
|
|
112
|
-
// Whole-entry deletion alone counts toward a safe historical omission.
|
|
113
|
-
for (const turn of turns) {
|
|
114
|
-
for (const entryId of turn.signedThinkingEntryIds) {
|
|
115
|
-
if (!filters.deletedEntryIds.has(entryId))
|
|
116
|
-
filters.deletedContentBlocks.delete(entryId);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
for (const turn of turns) {
|
|
120
|
-
const deletedSignedIds = turn.signedThinkingEntryIds.filter((entryId) => filters.deletedEntryIds.has(entryId));
|
|
121
|
-
const unsafe = turn.active
|
|
122
|
-
? deletedSignedIds.length > 0
|
|
123
|
-
: deletedSignedIds.length > 0 && deletedSignedIds.length < turn.signedThinkingEntryIds.length;
|
|
124
|
-
if (!unsafe)
|
|
125
|
-
continue;
|
|
126
|
-
for (const entryId of turn.signedThinkingEntryIds)
|
|
127
|
-
restoreEntry(filters, entryId);
|
|
128
|
-
}
|
|
129
|
-
return filters;
|
|
130
|
-
}
|
|
131
|
-
function signedTurnReplayPolicy(path, finalIntent) {
|
|
132
|
-
const restoredEntryIds = new Set();
|
|
133
|
-
const retainedEntryIds = new Set();
|
|
134
|
-
for (const turn of analyzeSessionAssistantTurns(path, finalIntent)) {
|
|
135
|
-
const deleted = turn.signedThinkingEntryIds.filter((entryId) => finalIntent.deletedEntryIds.has(entryId));
|
|
136
|
-
const restoreTurn = turn.active
|
|
137
|
-
? deleted.length > 0
|
|
138
|
-
: deleted.length > 0 && deleted.length < turn.signedThinkingEntryIds.length;
|
|
139
|
-
for (const entryId of turn.signedThinkingEntryIds) {
|
|
140
|
-
if (restoreTurn)
|
|
141
|
-
restoredEntryIds.add(entryId);
|
|
142
|
-
if (restoreTurn || !finalIntent.deletedEntryIds.has(entryId))
|
|
143
|
-
retainedEntryIds.add(entryId);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return { restoredEntryIds, retainedEntryIds };
|
|
147
|
-
}
|
|
148
|
-
export function buildEffectiveContextDeletionFilters(path) {
|
|
149
|
-
const derivedPath = normalizeDerivedSessionEntries(path);
|
|
150
|
-
const finalIntent = buildContextDeletionFilters(derivedPath);
|
|
151
|
-
if (!derivedPath.some((entry) => entry.type === "context_compaction"))
|
|
152
|
-
return finalIntent;
|
|
153
|
-
// Decide turn-level restoration from the cumulative durable intent so safe
|
|
154
|
-
// complete historical omissions may span multiple compaction entries. Then
|
|
155
|
-
// replay each entry chronologically: reconciliation at each boundary restores
|
|
156
|
-
// an unsafe paired whole-result deletion without erasing a later independent
|
|
157
|
-
// content-block deletion on that result.
|
|
158
|
-
const { restoredEntryIds, retainedEntryIds } = signedTurnReplayPolicy(derivedPath, finalIntent);
|
|
159
|
-
const effective = {
|
|
160
|
-
deletedEntryIds: new Set(),
|
|
161
|
-
deletedContentBlocks: new Map(),
|
|
162
|
-
};
|
|
163
|
-
for (const entry of derivedPath) {
|
|
164
|
-
if (entry.type !== "context_compaction")
|
|
165
|
-
continue;
|
|
166
|
-
for (const target of entry.deletedTargets) {
|
|
167
|
-
if (target.kind === "entry" && restoredEntryIds.has(target.entryId))
|
|
168
|
-
continue;
|
|
169
|
-
if (target.kind === "content_block" && retainedEntryIds.has(target.entryId))
|
|
170
|
-
continue;
|
|
171
|
-
addDeletionTarget(effective, target);
|
|
172
|
-
}
|
|
173
|
-
reconcilePersistedToolDependencyFilters(derivedPath, effective);
|
|
174
|
-
}
|
|
175
|
-
// Defensive final repair handles malformed dependency graphs and keeps this
|
|
176
|
-
// reconstruction path authoritative even if reconciliation behavior evolves.
|
|
177
|
-
repairSignedThinkingTurnFilters(derivedPath, effective);
|
|
178
|
-
return reconcilePersistedToolDependencyFilters(derivedPath, effective);
|
|
179
|
-
}
|
|
180
|
-
function filterContentArray(content, deletedBlocks) {
|
|
181
|
-
return content.filter((_, index) => !deletedBlocks.has(index));
|
|
182
|
-
}
|
|
183
|
-
function filterMessageContentBlocks(message, deletedBlocks) {
|
|
184
|
-
if (!deletedBlocks || deletedBlocks.size === 0)
|
|
185
|
-
return message;
|
|
186
|
-
switch (message.role) {
|
|
187
|
-
case "user": {
|
|
188
|
-
if (!Array.isArray(message.content))
|
|
189
|
-
return message;
|
|
190
|
-
const content = filterContentArray(message.content, deletedBlocks);
|
|
191
|
-
if (content.length === 0)
|
|
192
|
-
return undefined;
|
|
193
|
-
return { ...message, content };
|
|
194
|
-
}
|
|
195
|
-
case "assistant": {
|
|
196
|
-
const content = filterContentArray(message.content, deletedBlocks);
|
|
197
|
-
if (content.length === 0)
|
|
198
|
-
return undefined;
|
|
199
|
-
return { ...message, content };
|
|
200
|
-
}
|
|
201
|
-
case "toolResult": {
|
|
202
|
-
if (!Array.isArray(message.content))
|
|
203
|
-
return message;
|
|
204
|
-
const content = filterContentArray(message.content, deletedBlocks);
|
|
205
|
-
if (content.length === 0)
|
|
206
|
-
return undefined;
|
|
207
|
-
return { ...message, content };
|
|
208
|
-
}
|
|
209
|
-
case "custom": {
|
|
210
|
-
if (!Array.isArray(message.content))
|
|
211
|
-
return message;
|
|
212
|
-
const content = filterContentArray(message.content, deletedBlocks);
|
|
213
|
-
if (content.length === 0)
|
|
214
|
-
return undefined;
|
|
215
|
-
return { ...message, content };
|
|
216
|
-
}
|
|
217
|
-
case "bashExecution":
|
|
218
|
-
case "branchSummary":
|
|
219
|
-
return message;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Return the active branch path after applying logical context-deletion entries.
|
|
224
|
-
* Whole-entry deletions remove the entry from the path. Content-block deletions
|
|
225
|
-
* clone only affected message/custom-message entries so retained blocks stay verbatim.
|
|
226
|
-
* The optional filters parameter is for callers that already computed effective
|
|
227
|
-
* filters with `buildEffectiveContextDeletionFilters(path)` and want to avoid
|
|
228
|
-
* repeating the repair pass.
|
|
229
|
-
*/
|
|
230
|
-
export function buildContextDeletionFilteredPath(path, effectiveFilters) {
|
|
231
|
-
const derivedPath = normalizeDerivedSessionEntries(path);
|
|
232
|
-
const filters = effectiveFilters ?? buildEffectiveContextDeletionFilters(derivedPath);
|
|
233
|
-
const filteredPath = [];
|
|
234
|
-
for (const entry of derivedPath) {
|
|
235
|
-
if (filters.deletedEntryIds.has(entry.id))
|
|
236
|
-
continue;
|
|
237
|
-
const deletedBlocks = filters.deletedContentBlocks.get(entry.id);
|
|
238
|
-
if (!deletedBlocks || deletedBlocks.size === 0) {
|
|
239
|
-
filteredPath.push(entry);
|
|
240
|
-
continue;
|
|
241
|
-
}
|
|
242
|
-
if (entry.type === "message") {
|
|
243
|
-
const message = filterMessageContentBlocks(entry.message, deletedBlocks);
|
|
244
|
-
if (message)
|
|
245
|
-
filteredPath.push({ ...entry, message });
|
|
246
|
-
continue;
|
|
247
|
-
}
|
|
248
|
-
if (entry.type === "custom_message" && Array.isArray(entry.content)) {
|
|
249
|
-
const content = filterContentArray(entry.content, deletedBlocks);
|
|
250
|
-
if (content.length > 0)
|
|
251
|
-
filteredPath.push({ ...entry, content });
|
|
252
|
-
continue;
|
|
253
|
-
}
|
|
254
|
-
filteredPath.push(entry);
|
|
255
|
-
}
|
|
256
|
-
return filteredPath;
|
|
257
|
-
}
|
|
258
14
|
/**
|
|
259
15
|
* Build the session context from entries using tree traversal.
|
|
260
16
|
* If leafId is provided, walks from that entry to root.
|
|
261
|
-
*
|
|
17
|
+
* Emits the latest verbatim compaction boundary (compacted string as a custom-role
|
|
18
|
+
* boundary message) followed by the kept tail from firstKeptEntryId, and includes
|
|
19
|
+
* branch summaries along the path.
|
|
262
20
|
*/
|
|
263
21
|
export function buildSessionContext(entries, leafId, byId) {
|
|
264
22
|
// Build uuid index if not available
|
|
@@ -304,9 +62,6 @@ export function buildSessionContext(entries, leafId, byId) {
|
|
|
304
62
|
model = { provider: entry.message.provider, modelId: entry.message.model };
|
|
305
63
|
}
|
|
306
64
|
}
|
|
307
|
-
const filteredPath = buildContextDeletionFilteredPath(path);
|
|
308
|
-
// Build active context messages from the filtered path. Legacy "compaction"
|
|
309
|
-
// entries are archival metadata and intentionally inert here.
|
|
310
65
|
const messages = [];
|
|
311
66
|
const appendMessage = (entry) => {
|
|
312
67
|
let message;
|
|
@@ -322,9 +77,21 @@ export function buildSessionContext(entries, leafId, byId) {
|
|
|
322
77
|
if (message)
|
|
323
78
|
messages.push(message);
|
|
324
79
|
};
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
80
|
+
const boundary = getLatestCompactionBoundaryEntry(path);
|
|
81
|
+
if (!boundary) {
|
|
82
|
+
for (const entry of path)
|
|
83
|
+
appendMessage(entry);
|
|
84
|
+
return { messages, thinkingLevel, contextWindow, model };
|
|
85
|
+
}
|
|
86
|
+
const boundaryIndex = path.findIndex((entry) => entry.id === boundary.id);
|
|
87
|
+
messages.push(createVerbatimCompactionMessage(boundary.summary, boundary.tokensBefore, boundary.timestamp, boundary.details));
|
|
88
|
+
const firstKeptIndex = path.findIndex((entry, index) => index < boundaryIndex && entry.id === boundary.firstKeptEntryId);
|
|
89
|
+
if (firstKeptIndex >= 0) {
|
|
90
|
+
for (let i = firstKeptIndex; i < boundaryIndex; i++)
|
|
91
|
+
appendMessage(path[i]);
|
|
92
|
+
}
|
|
93
|
+
for (let i = boundaryIndex + 1; i < path.length; i++)
|
|
94
|
+
appendMessage(path[i]);
|
|
328
95
|
return { messages, thinkingLevel, contextWindow, model };
|
|
329
96
|
}
|
|
330
97
|
export function buildSessionIndex(fileEntries) {
|