@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.
Files changed (348) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/builtin/cursor/CHANGELOG.md +6 -0
  3. package/dist/builtin/cursor/package.json +2 -2
  4. package/dist/builtin/intercom/CHANGELOG.md +6 -0
  5. package/dist/builtin/intercom/package.json +1 -1
  6. package/dist/builtin/mcp/CHANGELOG.md +6 -0
  7. package/dist/builtin/mcp/package.json +1 -1
  8. package/dist/builtin/subagents/CHANGELOG.md +6 -0
  9. package/dist/builtin/subagents/package.json +1 -1
  10. package/dist/builtin/subagents/src/runs/background/async-execution-chain.ts +2 -0
  11. package/dist/builtin/subagents/src/runs/background/async-execution-common.ts +7 -1
  12. package/dist/builtin/subagents/src/runs/background/async-execution-single.ts +2 -0
  13. package/dist/builtin/subagents/src/runs/background/async-execution-types.ts +8 -2
  14. package/dist/builtin/subagents/src/runs/foreground/chain-execution-parallel-runner.ts +2 -0
  15. package/dist/builtin/subagents/src/runs/foreground/chain-execution-sequential-step.ts +2 -0
  16. package/dist/builtin/subagents/src/runs/foreground/execution-attempt.ts +2 -1
  17. package/dist/builtin/subagents/src/runs/foreground/subagent-executor-async.ts +2 -0
  18. package/dist/builtin/subagents/src/runs/foreground/subagent-executor-parallel-task.ts +2 -0
  19. package/dist/builtin/subagents/src/runs/foreground/subagent-executor-resume.ts +2 -0
  20. package/dist/builtin/subagents/src/runs/foreground/subagent-executor-single.ts +2 -0
  21. package/dist/builtin/subagents/src/runs/shared/pi-args.ts +6 -0
  22. package/dist/builtin/subagents/src/shared/types-config.ts +4 -0
  23. package/dist/builtin/subagents/src/shared/types-depth.ts +29 -2
  24. package/dist/builtin/web-access/CHANGELOG.md +6 -0
  25. package/dist/builtin/web-access/package.json +1 -1
  26. package/dist/builtin/workflows/CHANGELOG.md +22 -0
  27. package/dist/builtin/workflows/README.md +17 -8
  28. package/dist/builtin/workflows/builtin/goal-prompts.ts +8 -2
  29. package/dist/builtin/workflows/builtin/open-claude-design-utils.ts +26 -9
  30. package/dist/builtin/workflows/builtin/ralph-forked-prompts.ts +1 -1
  31. package/dist/builtin/workflows/builtin/ralph-reviewer-prompt.ts +8 -3
  32. package/dist/builtin/workflows/builtin/ralph-runner.ts +2 -0
  33. package/dist/builtin/workflows/builtin/shared-prompts.ts +24 -1
  34. package/dist/builtin/workflows/package.json +1 -1
  35. package/dist/builtin/workflows/src/durable/backend.ts +53 -15
  36. package/dist/builtin/workflows/src/durable/completed-catalog.ts +245 -0
  37. package/dist/builtin/workflows/src/durable/completed-inspection.ts +213 -0
  38. package/dist/builtin/workflows/src/durable/dbos-backend.ts +120 -170
  39. package/dist/builtin/workflows/src/durable/dbos-envelope.ts +84 -8
  40. package/dist/builtin/workflows/src/durable/dbos-metadata.ts +98 -0
  41. package/dist/builtin/workflows/src/durable/dbos-tombstone.ts +27 -0
  42. package/dist/builtin/workflows/src/durable/factory.ts +1 -1
  43. package/dist/builtin/workflows/src/durable/file-backend.ts +247 -241
  44. package/dist/builtin/workflows/src/durable/file-lock.ts +153 -0
  45. package/dist/builtin/workflows/src/durable/file-state.ts +104 -0
  46. package/dist/builtin/workflows/src/durable/format-version.ts +12 -0
  47. package/dist/builtin/workflows/src/durable/index.ts +12 -0
  48. package/dist/builtin/workflows/src/durable/resume-catalog.ts +16 -27
  49. package/dist/builtin/workflows/src/durable/resume-eligibility.ts +20 -0
  50. package/dist/builtin/workflows/src/durable/resume-runtime.ts +29 -29
  51. package/dist/builtin/workflows/src/durable/scoped-backend.ts +20 -3
  52. package/dist/builtin/workflows/src/durable/stage-primitive.ts +29 -8
  53. package/dist/builtin/workflows/src/durable/types.ts +3 -0
  54. package/dist/builtin/workflows/src/engine/primitives/task.ts +1 -0
  55. package/dist/builtin/workflows/src/engine/run.ts +14 -14
  56. package/dist/builtin/workflows/src/extension/extension-lifecycle.ts +39 -9
  57. package/dist/builtin/workflows/src/extension/extension-runtime-state.ts +10 -0
  58. package/dist/builtin/workflows/src/extension/runtime-durable-resume.ts +133 -0
  59. package/dist/builtin/workflows/src/extension/runtime.ts +15 -40
  60. package/dist/builtin/workflows/src/extension/wiring.ts +9 -6
  61. package/dist/builtin/workflows/src/extension/workflow-durable-resume-command.ts +226 -0
  62. package/dist/builtin/workflows/src/extension/workflow-prompts.ts +1 -0
  63. package/dist/builtin/workflows/src/extension/workflow-run-control-command.ts +66 -112
  64. package/dist/builtin/workflows/src/extension/workflow-schema.ts +5 -5
  65. package/dist/builtin/workflows/src/extension/workflow-tool-control.ts +16 -1
  66. package/dist/builtin/workflows/src/runs/foreground/executor-direct-helpers.ts +50 -43
  67. package/dist/builtin/workflows/src/runs/foreground/executor-direct-output.ts +91 -0
  68. package/dist/builtin/workflows/src/runs/foreground/executor-direct.ts +95 -46
  69. package/dist/builtin/workflows/src/runs/foreground/executor-stage-call.ts +3 -1
  70. package/dist/builtin/workflows/src/runs/foreground/executor-task-prompts.ts +1 -1
  71. package/dist/builtin/workflows/src/runs/foreground/executor-types.ts +3 -0
  72. package/dist/builtin/workflows/src/runs/foreground/stage-runner-controller.ts +1 -1
  73. package/dist/builtin/workflows/src/runs/foreground/stage-runner-options.ts +36 -7
  74. package/dist/builtin/workflows/src/runs/shared/worktree-cache-lifecycle.ts +25 -0
  75. package/dist/builtin/workflows/src/runs/shared/worktree-cwd.ts +103 -0
  76. package/dist/builtin/workflows/src/runs/shared/worktree-generation.ts +57 -0
  77. package/dist/builtin/workflows/src/runs/shared/worktree-git.ts +134 -8
  78. package/dist/builtin/workflows/src/runs/shared/worktree.ts +2 -0
  79. package/dist/builtin/workflows/src/shared/resumable-workflow-notices.ts +43 -0
  80. package/dist/builtin/workflows/src/shared/timing.ts +4 -0
  81. package/dist/builtin/workflows/src/shared/types.ts +5 -3
  82. package/dist/builtin/workflows/src/tui/graph-view-constants.ts +1 -0
  83. package/dist/builtin/workflows/src/tui/graph-view-input.ts +24 -14
  84. package/dist/builtin/workflows/src/tui/workflow-resume-selector.ts +43 -13
  85. package/dist/core/agent-session-auto-compaction.d.ts.map +1 -1
  86. package/dist/core/agent-session-auto-compaction.js +5 -7
  87. package/dist/core/agent-session-auto-compaction.js.map +1 -1
  88. package/dist/core/agent-session-compaction.d.ts +6 -34
  89. package/dist/core/agent-session-compaction.d.ts.map +1 -1
  90. package/dist/core/agent-session-compaction.js +95 -233
  91. package/dist/core/agent-session-compaction.js.map +1 -1
  92. package/dist/core/agent-session-message-queue.d.ts +0 -4
  93. package/dist/core/agent-session-message-queue.d.ts.map +1 -1
  94. package/dist/core/agent-session-message-queue.js +1 -5
  95. package/dist/core/agent-session-message-queue.js.map +1 -1
  96. package/dist/core/agent-session-methods.d.ts +5 -6
  97. package/dist/core/agent-session-methods.d.ts.map +1 -1
  98. package/dist/core/agent-session-methods.js.map +1 -1
  99. package/dist/core/agent-session-types.d.ts +2 -12
  100. package/dist/core/agent-session-types.d.ts.map +1 -1
  101. package/dist/core/agent-session-types.js.map +1 -1
  102. package/dist/core/compaction/branch-summarization.d.ts +1 -1
  103. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  104. package/dist/core/compaction/branch-summarization.js +1 -2
  105. package/dist/core/compaction/branch-summarization.js.map +1 -1
  106. package/dist/core/compaction/compaction-boundary.d.ts +9 -0
  107. package/dist/core/compaction/compaction-boundary.d.ts.map +1 -0
  108. package/dist/core/compaction/compaction-boundary.js +115 -0
  109. package/dist/core/compaction/compaction-boundary.js.map +1 -0
  110. package/dist/core/compaction/compaction-parameters.d.ts +5 -0
  111. package/dist/core/compaction/compaction-parameters.d.ts.map +1 -0
  112. package/dist/core/compaction/compaction-parameters.js +27 -0
  113. package/dist/core/compaction/compaction-parameters.js.map +1 -0
  114. package/dist/core/compaction/compaction-runner.d.ts +14 -0
  115. package/dist/core/compaction/compaction-runner.d.ts.map +1 -0
  116. package/dist/core/compaction/compaction-runner.js +29 -0
  117. package/dist/core/compaction/compaction-runner.js.map +1 -0
  118. package/dist/core/compaction/compaction-types.d.ts +79 -0
  119. package/dist/core/compaction/compaction-types.d.ts.map +1 -0
  120. package/dist/core/compaction/compaction-types.js +6 -0
  121. package/dist/core/compaction/compaction-types.js.map +1 -0
  122. package/dist/core/compaction/deleted-ranges.d.ts +6 -0
  123. package/dist/core/compaction/deleted-ranges.d.ts.map +1 -0
  124. package/dist/core/compaction/deleted-ranges.js +134 -0
  125. package/dist/core/compaction/deleted-ranges.js.map +1 -0
  126. package/dist/core/compaction/index.d.ts +7 -1
  127. package/dist/core/compaction/index.d.ts.map +1 -1
  128. package/dist/core/compaction/index.js +7 -1
  129. package/dist/core/compaction/index.js.map +1 -1
  130. package/dist/core/compaction/range-planner.d.ts +21 -0
  131. package/dist/core/compaction/range-planner.d.ts.map +1 -0
  132. package/dist/core/compaction/range-planner.js +145 -0
  133. package/dist/core/compaction/range-planner.js.map +1 -0
  134. package/dist/core/compaction/transcript-serialization.d.ts +11 -0
  135. package/dist/core/compaction/transcript-serialization.d.ts.map +1 -0
  136. package/dist/core/compaction/transcript-serialization.js +104 -0
  137. package/dist/core/compaction/transcript-serialization.js.map +1 -0
  138. package/dist/core/extensions/context-types.d.ts +2 -2
  139. package/dist/core/extensions/context-types.d.ts.map +1 -1
  140. package/dist/core/extensions/context-types.js.map +1 -1
  141. package/dist/core/extensions/event-results.d.ts +2 -2
  142. package/dist/core/extensions/event-results.d.ts.map +1 -1
  143. package/dist/core/extensions/event-results.js.map +1 -1
  144. package/dist/core/extensions/session-events.d.ts +7 -7
  145. package/dist/core/extensions/session-events.d.ts.map +1 -1
  146. package/dist/core/extensions/session-events.js.map +1 -1
  147. package/dist/core/index.d.ts +1 -1
  148. package/dist/core/index.d.ts.map +1 -1
  149. package/dist/core/index.js.map +1 -1
  150. package/dist/core/messages.d.ts +4 -0
  151. package/dist/core/messages.d.ts.map +1 -1
  152. package/dist/core/messages.js +11 -0
  153. package/dist/core/messages.js.map +1 -1
  154. package/dist/core/provider-context-usage.d.ts.map +1 -1
  155. package/dist/core/provider-context-usage.js +1 -2
  156. package/dist/core/provider-context-usage.js.map +1 -1
  157. package/dist/core/session-manager-archive.d.ts +2 -1
  158. package/dist/core/session-manager-archive.d.ts.map +1 -1
  159. package/dist/core/session-manager-archive.js +2 -2
  160. package/dist/core/session-manager-archive.js.map +1 -1
  161. package/dist/core/session-manager-classification.d.ts +9 -0
  162. package/dist/core/session-manager-classification.d.ts.map +1 -0
  163. package/dist/core/session-manager-classification.js +37 -0
  164. package/dist/core/session-manager-classification.js.map +1 -0
  165. package/dist/core/session-manager-core.d.ts +4 -4
  166. package/dist/core/session-manager-core.d.ts.map +1 -1
  167. package/dist/core/session-manager-core.js +13 -8
  168. package/dist/core/session-manager-core.js.map +1 -1
  169. package/dist/core/session-manager-entries.d.ts +4 -3
  170. package/dist/core/session-manager-entries.d.ts.map +1 -1
  171. package/dist/core/session-manager-entries.js +12 -10
  172. package/dist/core/session-manager-entries.js.map +1 -1
  173. package/dist/core/session-manager-history.d.ts +6 -23
  174. package/dist/core/session-manager-history.d.ts.map +1 -1
  175. package/dist/core/session-manager-history.js +23 -256
  176. package/dist/core/session-manager-history.js.map +1 -1
  177. package/dist/core/session-manager-list.d.ts.map +1 -1
  178. package/dist/core/session-manager-list.js +3 -3
  179. package/dist/core/session-manager-list.js.map +1 -1
  180. package/dist/core/session-manager-storage.d.ts +1 -1
  181. package/dist/core/session-manager-storage.d.ts.map +1 -1
  182. package/dist/core/session-manager-storage.js +3 -2
  183. package/dist/core/session-manager-storage.js.map +1 -1
  184. package/dist/core/session-manager-types.d.ts +14 -15
  185. package/dist/core/session-manager-types.d.ts.map +1 -1
  186. package/dist/core/session-manager-types.js.map +1 -1
  187. package/dist/core/session-manager.d.ts +3 -2
  188. package/dist/core/session-manager.d.ts.map +1 -1
  189. package/dist/core/session-manager.js +1 -1
  190. package/dist/core/session-manager.js.map +1 -1
  191. package/dist/core/slash-commands.d.ts.map +1 -1
  192. package/dist/core/slash-commands.js +1 -1
  193. package/dist/core/slash-commands.js.map +1 -1
  194. package/dist/index.d.ts +3 -2
  195. package/dist/index.d.ts.map +1 -1
  196. package/dist/index.js +2 -1
  197. package/dist/index.js.map +1 -1
  198. package/dist/main-session.d.ts +1 -0
  199. package/dist/main-session.d.ts.map +1 -1
  200. package/dist/main-session.js +7 -0
  201. package/dist/main-session.js.map +1 -1
  202. package/dist/main.d.ts.map +1 -1
  203. package/dist/main.js +2 -2
  204. package/dist/main.js.map +1 -1
  205. package/dist/modes/interactive/components/chat-message-renderer.d.ts +4 -1
  206. package/dist/modes/interactive/components/chat-message-renderer.d.ts.map +1 -1
  207. package/dist/modes/interactive/components/chat-message-renderer.js +12 -22
  208. package/dist/modes/interactive/components/chat-message-renderer.js.map +1 -1
  209. package/dist/modes/interactive/components/chat-session-host-events.d.ts.map +1 -1
  210. package/dist/modes/interactive/components/chat-session-host-events.js +5 -11
  211. package/dist/modes/interactive/components/chat-session-host-events.js.map +1 -1
  212. package/dist/modes/interactive/components/chat-session-host-rendering.d.ts.map +1 -1
  213. package/dist/modes/interactive/components/chat-session-host-rendering.js +3 -0
  214. package/dist/modes/interactive/components/chat-session-host-rendering.js.map +1 -1
  215. package/dist/modes/interactive/components/chat-session-host-state.d.ts +1 -0
  216. package/dist/modes/interactive/components/chat-session-host-state.d.ts.map +1 -1
  217. package/dist/modes/interactive/components/chat-session-host-state.js +1 -0
  218. package/dist/modes/interactive/components/chat-session-host-state.js.map +1 -1
  219. package/dist/modes/interactive/components/chat-session-host-utils.d.ts.map +1 -1
  220. package/dist/modes/interactive/components/chat-session-host-utils.js +1 -1
  221. package/dist/modes/interactive/components/chat-session-host-utils.js.map +1 -1
  222. package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -1
  223. package/dist/modes/interactive/components/chat-session-host.js +1 -0
  224. package/dist/modes/interactive/components/chat-session-host.js.map +1 -1
  225. package/dist/modes/interactive/components/compaction-boundary-message.d.ts +20 -0
  226. package/dist/modes/interactive/components/compaction-boundary-message.d.ts.map +1 -0
  227. package/dist/modes/interactive/components/compaction-boundary-message.js +48 -0
  228. package/dist/modes/interactive/components/compaction-boundary-message.js.map +1 -0
  229. package/dist/modes/interactive/components/index.d.ts +1 -1
  230. package/dist/modes/interactive/components/index.d.ts.map +1 -1
  231. package/dist/modes/interactive/components/index.js +1 -1
  232. package/dist/modes/interactive/components/index.js.map +1 -1
  233. package/dist/modes/interactive/components/session-selector-list.d.ts.map +1 -1
  234. package/dist/modes/interactive/components/session-selector-list.js +3 -0
  235. package/dist/modes/interactive/components/session-selector-list.js.map +1 -1
  236. package/dist/modes/interactive/interactive-agent-events.d.ts.map +1 -1
  237. package/dist/modes/interactive/interactive-agent-events.js +3 -47
  238. package/dist/modes/interactive/interactive-agent-events.js.map +1 -1
  239. package/dist/modes/interactive/interactive-mode-deps.d.ts +2 -2
  240. package/dist/modes/interactive/interactive-mode-deps.d.ts.map +1 -1
  241. package/dist/modes/interactive/interactive-mode-deps.js +1 -1
  242. package/dist/modes/interactive/interactive-mode-deps.js.map +1 -1
  243. package/dist/modes/interactive/interactive-mode-surface.d.ts +5 -3
  244. package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
  245. package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
  246. package/dist/modes/interactive/interactive-render-chat.d.ts.map +1 -1
  247. package/dist/modes/interactive/interactive-render-chat.js +21 -12
  248. package/dist/modes/interactive/interactive-render-chat.js.map +1 -1
  249. package/dist/modes/rpc/rpc-client.d.ts +3 -5
  250. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  251. package/dist/modes/rpc/rpc-client.js +1 -6
  252. package/dist/modes/rpc/rpc-client.js.map +1 -1
  253. package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
  254. package/dist/modes/rpc/rpc-command-handler.js +0 -4
  255. package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
  256. package/dist/modes/rpc/rpc-types.d.ts +2 -11
  257. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  258. package/dist/modes/rpc/rpc-types.js.map +1 -1
  259. package/docs/compaction.md +97 -772
  260. package/docs/extensions.md +25 -29
  261. package/docs/json.md +2 -2
  262. package/docs/rpc.md +32 -24
  263. package/docs/sdk.md +3 -3
  264. package/docs/session-format.md +49 -30
  265. package/docs/sessions.md +5 -3
  266. package/docs/settings.md +14 -4
  267. package/docs/usage.md +1 -1
  268. package/docs/workflows.md +30 -15
  269. package/examples/extensions/custom-compaction.ts +14 -58
  270. package/examples/extensions/handoff.ts +2 -3
  271. package/npm-shrinkwrap.json +23 -23
  272. package/package.json +2 -2
  273. package/dist/core/compaction/context-assistant-turns.d.ts +0 -42
  274. package/dist/core/compaction/context-assistant-turns.d.ts.map +0 -1
  275. package/dist/core/compaction/context-assistant-turns.js +0 -87
  276. package/dist/core/compaction/context-assistant-turns.js.map +0 -1
  277. package/dist/core/compaction/context-compaction-critical.d.ts +0 -15
  278. package/dist/core/compaction/context-compaction-critical.d.ts.map +0 -1
  279. package/dist/core/compaction/context-compaction-critical.js +0 -57
  280. package/dist/core/compaction/context-compaction-critical.js.map +0 -1
  281. package/dist/core/compaction/context-compaction-eviction-alternates.d.ts +0 -18
  282. package/dist/core/compaction/context-compaction-eviction-alternates.d.ts.map +0 -1
  283. package/dist/core/compaction/context-compaction-eviction-alternates.js +0 -186
  284. package/dist/core/compaction/context-compaction-eviction-alternates.js.map +0 -1
  285. package/dist/core/compaction/context-compaction-eviction.d.ts +0 -12
  286. package/dist/core/compaction/context-compaction-eviction.d.ts.map +0 -1
  287. package/dist/core/compaction/context-compaction-eviction.js +0 -222
  288. package/dist/core/compaction/context-compaction-eviction.js.map +0 -1
  289. package/dist/core/compaction/context-compaction-metrics.d.ts +0 -28
  290. package/dist/core/compaction/context-compaction-metrics.d.ts.map +0 -1
  291. package/dist/core/compaction/context-compaction-metrics.js +0 -107
  292. package/dist/core/compaction/context-compaction-metrics.js.map +0 -1
  293. package/dist/core/compaction/context-compaction-prompt.d.ts +0 -9
  294. package/dist/core/compaction/context-compaction-prompt.d.ts.map +0 -1
  295. package/dist/core/compaction/context-compaction-prompt.js +0 -163
  296. package/dist/core/compaction/context-compaction-prompt.js.map +0 -1
  297. package/dist/core/compaction/context-compaction-runner.d.ts +0 -11
  298. package/dist/core/compaction/context-compaction-runner.d.ts.map +0 -1
  299. package/dist/core/compaction/context-compaction-runner.js +0 -273
  300. package/dist/core/compaction/context-compaction-runner.js.map +0 -1
  301. package/dist/core/compaction/context-compaction-strategy.d.ts +0 -5
  302. package/dist/core/compaction/context-compaction-strategy.d.ts.map +0 -1
  303. package/dist/core/compaction/context-compaction-strategy.js +0 -27
  304. package/dist/core/compaction/context-compaction-strategy.js.map +0 -1
  305. package/dist/core/compaction/context-compaction-types.d.ts +0 -75
  306. package/dist/core/compaction/context-compaction-types.d.ts.map +0 -1
  307. package/dist/core/compaction/context-compaction-types.js +0 -6
  308. package/dist/core/compaction/context-compaction-types.js.map +0 -1
  309. package/dist/core/compaction/context-compaction.d.ts +0 -10
  310. package/dist/core/compaction/context-compaction.d.ts.map +0 -1
  311. package/dist/core/compaction/context-compaction.js +0 -8
  312. package/dist/core/compaction/context-compaction.js.map +0 -1
  313. package/dist/core/compaction/context-deletion-application.d.ts +0 -14
  314. package/dist/core/compaction/context-deletion-application.d.ts.map +0 -1
  315. package/dist/core/compaction/context-deletion-application.js +0 -261
  316. package/dist/core/compaction/context-deletion-application.js.map +0 -1
  317. package/dist/core/compaction/context-deletion-store.d.ts +0 -78
  318. package/dist/core/compaction/context-deletion-store.d.ts.map +0 -1
  319. package/dist/core/compaction/context-deletion-store.js +0 -162
  320. package/dist/core/compaction/context-deletion-store.js.map +0 -1
  321. package/dist/core/compaction/context-deletion-targets.d.ts +0 -43
  322. package/dist/core/compaction/context-deletion-targets.d.ts.map +0 -1
  323. package/dist/core/compaction/context-deletion-targets.js +0 -292
  324. package/dist/core/compaction/context-deletion-targets.js.map +0 -1
  325. package/dist/core/compaction/context-deletion-tool-definitions.d.ts +0 -193
  326. package/dist/core/compaction/context-deletion-tool-definitions.d.ts.map +0 -1
  327. package/dist/core/compaction/context-deletion-tool-definitions.js +0 -98
  328. package/dist/core/compaction/context-deletion-tool-definitions.js.map +0 -1
  329. package/dist/core/compaction/context-deletion-tool-helpers.d.ts +0 -19
  330. package/dist/core/compaction/context-deletion-tool-helpers.d.ts.map +0 -1
  331. package/dist/core/compaction/context-deletion-tool-helpers.js +0 -210
  332. package/dist/core/compaction/context-deletion-tool-helpers.js.map +0 -1
  333. package/dist/core/compaction/context-deletion-tools.d.ts +0 -4
  334. package/dist/core/compaction/context-deletion-tools.d.ts.map +0 -1
  335. package/dist/core/compaction/context-deletion-tools.js +0 -403
  336. package/dist/core/compaction/context-deletion-tools.js.map +0 -1
  337. package/dist/core/compaction/context-transcript-analysis.d.ts +0 -11
  338. package/dist/core/compaction/context-transcript-analysis.d.ts.map +0 -1
  339. package/dist/core/compaction/context-transcript-analysis.js +0 -228
  340. package/dist/core/compaction/context-transcript-analysis.js.map +0 -1
  341. package/dist/core/session-manager-tool-dependencies.d.ts +0 -10
  342. package/dist/core/session-manager-tool-dependencies.d.ts.map +0 -1
  343. package/dist/core/session-manager-tool-dependencies.js +0 -133
  344. package/dist/core/session-manager-tool-dependencies.js.map +0 -1
  345. package/dist/modes/interactive/components/context-compaction-summary-message.d.ts +0 -17
  346. package/dist/modes/interactive/components/context-compaction-summary-message.d.ts.map +0 -1
  347. package/dist/modes/interactive/components/context-compaction-summary-message.js +0 -83
  348. package/dist/modes/interactive/components/context-compaction-summary-message.js.map +0 -1
@@ -1,27 +0,0 @@
1
- import { CONTEXT_COMPACTION_AUTO_QUERY, CONTEXT_COMPACTION_DEFAULT_COMPRESSION_RATIO, CONTEXT_COMPACTION_DEFAULT_PRESERVE_RECENT, } from "./context-compaction-types.js";
2
- const CONTEXT_COMPACTION_QUERY_MAX_CHARS = 1000;
3
- function normalizeCompressionRatio(value) {
4
- return typeof value === "number" && Number.isFinite(value) && value > 0 && value < 1
5
- ? value
6
- : CONTEXT_COMPACTION_DEFAULT_COMPRESSION_RATIO;
7
- }
8
- function normalizePreserveRecent(value) {
9
- return typeof value === "number" && Number.isFinite(value) ? Math.max(0, Math.floor(value)) : CONTEXT_COMPACTION_DEFAULT_PRESERVE_RECENT;
10
- }
11
- export function normalizeContextCompactionQuery(value, fallbackQuery) {
12
- const query = value?.trim() || fallbackQuery.trim() || CONTEXT_COMPACTION_AUTO_QUERY;
13
- return query.length > CONTEXT_COMPACTION_QUERY_MAX_CHARS
14
- ? `${query.slice(0, CONTEXT_COMPACTION_QUERY_MAX_CHARS)}\n[... ${query.length - CONTEXT_COMPACTION_QUERY_MAX_CHARS} more characters omitted from compaction query]`
15
- : query;
16
- }
17
- export function normalizeContextCompactionParameters(input = {}, fallbackQuery = CONTEXT_COMPACTION_AUTO_QUERY) {
18
- return {
19
- compression_ratio: normalizeCompressionRatio(input.compression_ratio),
20
- preserve_recent: normalizePreserveRecent(input.preserve_recent),
21
- query: normalizeContextCompactionQuery(input.query, fallbackQuery),
22
- };
23
- }
24
- export function getTranscriptCompactionParameters(transcript) {
25
- return normalizeContextCompactionParameters(transcript.parameters ?? transcript.settings, transcript.parameters?.query ?? transcript.settings.query ?? CONTEXT_COMPACTION_AUTO_QUERY);
26
- }
27
- //# sourceMappingURL=context-compaction-strategy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context-compaction-strategy.js","sourceRoot":"","sources":["../../../src/core/compaction/context-compaction-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,6BAA6B,EAC7B,4CAA4C,EAC5C,0CAA0C,GAG1C,MAAM,+BAA+B,CAAC;AAEvC,MAAM,kCAAkC,GAAG,IAAI,CAAC;AAEhD,SAAS,yBAAyB,CAAC,KAAyB;IAC3D,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC;QACnF,CAAC,CAAC,KAAK;Q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XT_COMPACTION_DEFAULT_COMPRESSION_RATIO,\n\tCONTEXT_COMPACTION_DEFAULT_PRESERVE_RECENT,\n\ttype CompactableTranscript,\n\ttype ContextCompactionParameters,\n} from \"./context-compaction-types.ts\";\n\nconst CONTEXT_COMPACTION_QUERY_MAX_CHARS = 1000;\n\nfunction normalizeCompressionRatio(value: number | undefined): number {\n\treturn typeof value === \"number\" && Number.isFinite(value) && value > 0 && value < 1\n\t\t? value\n\t\t: CONTEXT_COMPACTION_DEFAULT_COMPRESSION_RATIO;\n}\n\nfunction normalizePreserveRecent(value: number | undefined): number {\n\treturn typeof value === \"number\" && Number.isFinite(value) ? Math.max(0, Math.floor(value)) : CONTEXT_COMPACTION_DEFAULT_PRESERVE_RECENT;\n}\n\nexport function normalizeContextCompactionQuery(value: string | undefined, fallbackQuery: string): string {\n\tconst query = value?.trim() || fallbackQuery.trim() || CONTEXT_COMPACTION_AUTO_QUERY;\n\treturn query.length > CONTEXT_COMPACTION_QUERY_MAX_CHARS\n\t\t? `${query.slice(0, CONTEXT_COMPACTION_QUERY_MAX_CHARS)}\\n[... ${query.length - CONTEXT_COMPACTION_QUERY_MAX_CHARS} more characters omitted from compaction query]`\n\t\t: query;\n}\n\nexport function normalizeContextCompactionParameters(\n\tinput: Partial<ContextCompactionParameters> = {},\n\tfallbackQuery: string = CONTEXT_COMPACTION_AUTO_QUERY,\n): ContextCompactionParameters {\n\treturn {\n\t\tcompression_ratio: normalizeCompressionRatio(input.compression_ratio),\n\t\tpreserve_recent: normalizePreserveRecent(input.preserve_recent),\n\t\tquery: normalizeContextCompactionQuery(input.query, fallbackQuery),\n\t};\n}\n\nexport function getTranscriptCompactionParameters(transcript: CompactableTranscript): ContextCompactionParameters {\n\treturn normalizeContextCompactionParameters(\n\t\ttranscript.parameters ?? transcript.settings,\n\t\ttranscript.parameters?.query ?? transcript.settings.query ?? CONTEXT_COMPACTION_AUTO_QUERY,\n\t);\n}\n"]}
@@ -1,75 +0,0 @@
1
- import type { AgentMessage } from "@earendil-works/pi-agent-core";
2
- import type { ContextCompactionStats, ContextDeletionTarget, SessionEntry } from "../session-manager.ts";
3
- import type { CompactionSettings } from "./compaction.ts";
4
- export declare const CONTEXT_COMPACTION_PROMPT_VERSION: 1;
5
- export interface ContextCompactionParameters {
6
- /** Fraction of compactable context to keep. 0.3 is aggressive, 0.7 is light. */
7
- compression_ratio: number;
8
- /** Number of recent context-eligible messages to preserve. */
9
- preserve_recent: number;
10
- /** Focus query for relevance-based pruning. */
11
- query: string;
12
- }
13
- export interface ContextDeletionRequest {
14
- deletions: Array<{
15
- kind: "entry" | "content_block";
16
- entryId: string;
17
- blockIndex?: number;
18
- }>;
19
- }
20
- export interface CompactableContentBlock {
21
- entryId: string;
22
- blockIndex: number;
23
- type: string;
24
- text: string;
25
- tokenEstimate: number;
26
- protected: boolean;
27
- /** Visibility computed from the raw durable block before transcript display normalization. */
28
- llmVisible?: boolean;
29
- toolCallId?: string;
30
- }
31
- export interface CompactableTranscriptEntry {
32
- entryId: string;
33
- entryType: SessionEntry["type"];
34
- role: AgentMessage["role"];
35
- text: string;
36
- tokenEstimate: number;
37
- protected: boolean;
38
- contentBlocks: CompactableContentBlock[];
39
- message: AgentMessage;
40
- toolCallIds: string[];
41
- toolResultFor?: string;
42
- }
43
- export interface CompactableTranscript {
44
- entries: CompactableTranscriptEntry[];
45
- protectedEntryIds: string[];
46
- tokensBefore: number;
47
- settings: CompactionSettings;
48
- parameters?: ContextCompactionParameters;
49
- }
50
- export interface ContextCompactionPreparation {
51
- transcript: CompactableTranscript;
52
- branchEntries: SessionEntry[];
53
- parameters: ContextCompactionParameters;
54
- }
55
- export interface ValidatedContextDeletionResult {
56
- deletedTargets: ContextDeletionTarget[];
57
- protectedEntryIds: string[];
58
- stats: ContextCompactionStats;
59
- }
60
- export interface ContextCompactionResult extends ValidatedContextDeletionResult {
61
- promptVersion: typeof CONTEXT_COMPACTION_PROMPT_VERSION;
62
- parameters: ContextCompactionParameters;
63
- backupPath?: string;
64
- }
65
- export interface ContextCompactionRunOptions {
66
- contextWindow?: number;
67
- compression_ratio?: number;
68
- preserve_recent?: number;
69
- query?: string;
70
- }
71
- export declare const CONTEXT_COMPACTION_DEFAULT_COMPRESSION_RATIO: 0.5;
72
- export declare const CONTEXT_COMPACTION_TARGET_REDUCTION_PERCENT: 50;
73
- export declare const CONTEXT_COMPACTION_DEFAULT_PRESERVE_RECENT: 2;
74
- export declare const CONTEXT_COMPACTION_AUTO_QUERY: "auto-detected";
75
- //# sourceMappingURL=context-compaction-types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context-compaction-types.d.ts","sourceRoot":"","sources":["../../../src/core/compaction/context-compaction-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACzG,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,eAAO,MAAM,iCAAiC,EAAG,CAAU,CAAC;AAE5D,MAAM,WAAW,2BAA2B;IAC3C,gFAAgF;IAChF,iBAAiB,EAAE,MAAM,CAAC;IAC1B,8DAA8D;IAC9D,eAAe,EAAE,MAAM,CAAC;IACxB,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,sBAAsB;IACtC,SAAS,EAAE,KAAK,CAAC;QAChB,IAAI,EAAE,OAAO,GAAG,eAAe,CAAC;QAChC,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC,CAAC;CACH;AAED,MAAM,WAAW,uBAAuB;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,S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AAC,EAAE,MAAM,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,4CAA4C,EAAG,GAAY,CAAC;AACzE,eAAO,MAAM,2CAA2C,EAAG,EAAW,CAAC;AACvE,eAAO,MAAM,0CAA0C,EAAG,CAAU,CAAC;AACrE,eAAO,MAAM,6BAA6B,EAAG,eAAwB,CAAC","sourcesContent":["import type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport type { ContextCompactionStats, ContextDeletionTarget, SessionEntry } from \"../session-manager.ts\";\nimport type { CompactionSettings } from \"./compaction.ts\";\n\nexport const CONTEXT_COMPACTION_PROMPT_VERSION = 1 as const;\n\nexport interface ContextCompactionParameters {\n\t/** Fraction of compactable context to keep. 0.3 is aggressive, 0.7 is light. */\n\tcompression_ratio: number;\n\t/** Number of recent context-eligible messages to preserve. */\n\tpreserve_recent: number;\n\t/** Focus query for relevance-based pruning. */\n\tquery: string;\n}\n\nexport interface ContextDeletionRequest {\n\tdeletions: Array<{\n\t\tkind: \"entry\" | \"content_block\";\n\t\tentryId: string;\n\t\tblockIndex?: number;\n\t}>;\n}\n\nexport interface CompactableContentBlock {\n\tentryId: string;\n\tblockIndex: number;\n\ttype: string;\n\ttext: string;\n\ttokenEstimate: number;\n\tprotected: boolean;\n\t/** Visibility computed from the raw durable block before transcript display normalization. */\n\tllmVisible?: boolean;\n\ttoolCallId?: string;\n}\n\nexport interface CompactableTranscriptEntry {\n\tentryId: string;\n\tentryType: SessionEntry[\"type\"];\n\trole: AgentMessage[\"role\"];\n\ttext: string;\n\ttokenEstimate: number;\n\tprotected: boolean;\n\tcontentBlocks: CompactableContentBlock[];\n\tmessage: AgentMessage;\n\ttoolCallIds: string[];\n\ttoolResultFor?: string;\n}\n\nexport interface CompactableTranscript {\n\tentries: CompactableTranscriptEntry[];\n\tprotectedEntryIds: string[];\n\ttokensBefore: number;\n\tsettings: CompactionSettings;\n\tparameters?: ContextCompactionParameters;\n}\n\nexport interface ContextCompactionPreparation {\n\ttranscript: CompactableTranscript;\n\tbranchEntries: SessionEntry[];\n\tparameters: ContextCompactionParameters;\n}\n\nexport interface ValidatedContextDeletionResult {\n\tdeletedTargets: ContextDeletionTarget[];\n\tprotectedEntryIds: string[];\n\tstats: ContextCompactionStats;\n}\n\nexport interface ContextCompactionResult extends ValidatedContextDeletionResult {\n\tpromptVersion: typeof CONTEXT_COMPACTION_PROMPT_VERSION;\n\tparameters: ContextCompactionParameters;\n\tbackupPath?: string;\n}\n\nexport interface ContextCompactionRunOptions {\n\tcontextWindow?: number;\n\tcompression_ratio?: number;\n\tpreserve_recent?: number;\n\tquery?: string;\n}\n\nexport const CONTEXT_COMPACTION_DEFAULT_COMPRESSION_RATIO = 0.5 as const;\nexport const CONTEXT_COMPACTION_TARGET_REDUCTION_PERCENT = 50 as const;\nexport const CONTEXT_COMPACTION_DEFAULT_PRESERVE_RECENT = 2 as const;\nexport const CONTEXT_COMPACTION_AUTO_QUERY = \"auto-detected\" as const;\n"]}
@@ -1,6 +0,0 @@
1
- export const CONTEXT_COMPACTION_PROMPT_VERSION = 1;
2
- export const CONTEXT_COMPACTION_DEFAULT_COMPRESSION_RATIO = 0.5;
3
- export const CONTEXT_COMPACTION_TARGET_REDUCTION_PERCENT = 50;
4
- export const CONTEXT_COMPACTION_DEFAULT_PRESERVE_RECENT = 2;
5
- export const CONTEXT_COMPACTION_AUTO_QUERY = "auto-detected";
6
- //# sourceMappingURL=context-compaction-types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context-compaction-types.js","sourceRoot":"","sources":["../../../src/core/compaction/context-compaction-types.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAU,CAAC;AA6E5D,MAAM,CAAC,MAAM,4CAA4C,GAAG,GAAY,CAAC;AACzE,MAAM,CAAC,MAAM,2CAA2C,GAAG,EAAW,CAAC;AACvE,MAAM,CAAC,MAAM,0CAA0C,GAAG,CAAU,CAAC;AACrE,MAAM,CAAC,MAAM,6BAA6B,GAAG,eAAwB,CAAC","sourcesContent":["import type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport type { ContextCompactionStats, ContextDeletionTarget, SessionEntry } from \"../session-manager.ts\";\nimport type { CompactionSettings } from \"./compaction.ts\";\n\nexport const CONTEXT_COMPACTION_PROMPT_VERSION = 1 as const;\n\nexport interface ContextCompactionParameters {\n\t/** Fraction of compactable context to keep. 0.3 is aggressive, 0.7 is light. */\n\tcompression_ratio: number;\n\t/** Number of recent context-eligible messages to preserve. */\n\tpreserve_recent: number;\n\t/** Focus query for relevance-based pruning. */\n\tquery: string;\n}\n\nexport interface ContextDeletionRequest {\n\tdeletions: Array<{\n\t\tkind: \"entry\" | \"content_block\";\n\t\tentryId: string;\n\t\tblockIndex?: number;\n\t}>;\n}\n\nexport interface CompactableContentBlock {\n\tentryId: string;\n\tblockIndex: number;\n\ttype: string;\n\ttext: string;\n\ttokenEstimate: number;\n\tprotected: boolean;\n\t/** Visibility computed from the raw durable block before transcript display normalization. */\n\tllmVisible?: boolean;\n\ttoolCallId?: string;\n}\n\nexport interface CompactableTranscriptEntry {\n\tentryId: string;\n\tentryType: SessionEntry[\"type\"];\n\trole: AgentMessage[\"role\"];\n\ttext: string;\n\ttokenEstimate: number;\n\tprotected: boolean;\n\tcontentBlocks: CompactableContentBlock[];\n\tmessage: AgentMessage;\n\ttoolCallIds: string[];\n\ttoolResultFor?: string;\n}\n\nexport interface CompactableTranscript {\n\tentries: CompactableTranscriptEntry[];\n\tprotectedEntryIds: string[];\n\ttokensBefore: number;\n\tsettings: CompactionSettings;\n\tparameters?: ContextCompactionParameters;\n}\n\nexport interface ContextCompactionPreparation {\n\ttranscript: CompactableTranscript;\n\tbranchEntries: SessionEntry[];\n\tparameters: ContextCompactionParameters;\n}\n\nexport interface ValidatedContextDeletionResult {\n\tdeletedTargets: ContextDeletionTarget[];\n\tprotectedEntryIds: string[];\n\tstats: ContextCompactionStats;\n}\n\nexport interface ContextCompactionResult extends ValidatedContextDeletionResult {\n\tpromptVersion: typeof CONTEXT_COMPACTION_PROMPT_VERSION;\n\tparameters: ContextCompactionParameters;\n\tbackupPath?: string;\n}\n\nexport interface ContextCompactionRunOptions {\n\tcontextWindow?: number;\n\tcompression_ratio?: number;\n\tpreserve_recent?: number;\n\tquery?: string;\n}\n\nexport const CONTEXT_COMPACTION_DEFAULT_COMPRESSION_RATIO = 0.5 as const;\nexport const CONTEXT_COMPACTION_TARGET_REDUCTION_PERCENT = 50 as const;\nexport const CONTEXT_COMPACTION_DEFAULT_PRESERVE_RECENT = 2 as const;\nexport const CONTEXT_COMPACTION_AUTO_QUERY = \"auto-detected\" as const;\n"]}
@@ -1,10 +0,0 @@
1
- export { CONTEXT_COMPACTION_AUTO_QUERY, CONTEXT_COMPACTION_DEFAULT_COMPRESSION_RATIO, CONTEXT_COMPACTION_DEFAULT_PRESERVE_RECENT, CONTEXT_COMPACTION_PROMPT_VERSION, CONTEXT_COMPACTION_TARGET_REDUCTION_PERCENT, } from "./context-compaction-types.ts";
2
- export type { CompactableContentBlock, CompactableTranscript, CompactableTranscriptEntry, ContextCompactionParameters, ContextCompactionPreparation, ContextCompactionResult, ContextCompactionRunOptions, ContextDeletionRequest, ValidatedContextDeletionResult, } from "./context-compaction-types.ts";
3
- export type { ContextCompactionBudgetToolDetails, ContextDeletionToolController, ContextDeletionToolDetails, ContextGrepDeletionMatch, ContextGrepDeletionSkipped, ContextGrepDeletionToolDetails, ContextReadEntryToolDetails, ContextTranscriptSearchMatch, ContextTranscriptSearchToolDetails, } from "./context-deletion-tool-definitions.ts";
4
- export { normalizeContextCompactionParameters } from "./context-compaction-strategy.ts";
5
- export { autoDetectContextCompactionQuery, prepareContextCompaction, } from "./context-transcript-analysis.ts";
6
- export { validateContextDeletionRequest } from "./context-deletion-application.ts";
7
- export { createContextDeletionTool } from "./context-deletion-tools.ts";
8
- export { buildContextCompactionPrompt } from "./context-compaction-prompt.ts";
9
- export { contextCompact } from "./context-compaction-runner.ts";
10
- //# sourceMappingURL=context-compaction.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context-compaction.d.ts","sourceRoot":"","sources":["../../../src/core/compaction/context-compaction.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,6BAA6B,EAC7B,4CAA4C,EAC5C,0CAA0C,EAC1C,iCAAiC,EACjC,2CAA2C,GAC3C,MAAM,+BAA+B,CAAC;AACvC,YAAY,EACX,uBAAuB,EACvB,qBAAqB,EACrB,0BAA0B,EAC1B,2BAA2B,EAC3B,4BAA4B,EAC5B,uBAAuB,EACvB,2BAA2B,EAC3B,sBAAsB,EACtB,8BAA8B,GAC9B,MAAM,+BAA+B,CAAC;AACvC,YAAY,EACX,kCAAkC,EAClC,6BAA6B,EAC7B,0BAA0B,EAC1B,wBAAwB,EACxB,0BAA0B,EAC1B,8BAA8B,EAC9B,2BAA2B,EAC3B,4BAA4B,EAC5B,kCAAkC,GAClC,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,oCAAoC,EAAE,MAAM,kCAAkC,CAAC;AACxF,OAAO,EACN,gCAAgC,EAChC,wBAAwB,GACxB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,8BAA8B,EAAE,MAAM,mCAAmC,CAAC;AACnF,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC","sourcesContent":["export {\n\tCONTEXT_COMPACTION_AUTO_QUERY,\n\tCONTEXT_COMPACTION_DEFAULT_COMPRESSION_RATIO,\n\tCONTEXT_COMPACTION_DEFAULT_PRESERVE_RECENT,\n\tCONTEXT_COMPACTION_PROMPT_VERSION,\n\tCONTEXT_COMPACTION_TARGET_REDUCTION_PERCENT,\n} from \"./context-compaction-types.ts\";\nexport type {\n\tCompactableContentBlock,\n\tCompactableTranscript,\n\tCompactableTranscriptEntry,\n\tContextCompactionParameters,\n\tContextCompactionPreparation,\n\tContextCompactionResult,\n\tContextCompactionRunOptions,\n\tContextDeletionRequest,\n\tValidatedContextDeletionResult,\n} from \"./context-compaction-types.ts\";\nexport type {\n\tContextCompactionBudgetToolDetails,\n\tContextDeletionToolController,\n\tContextDeletionToolDetails,\n\tContextGrepDeletionMatch,\n\tContextGrepDeletionSkipped,\n\tContextGrepDeletionToolDetails,\n\tContextReadEntryToolDetails,\n\tContextTranscriptSearchMatch,\n\tContextTranscriptSearchToolDetails,\n} from \"./context-deletion-tool-definitions.ts\";\nexport { normalizeContextCompactionParameters } from \"./context-compaction-strategy.ts\";\nexport {\n\tautoDetectContextCompactionQuery,\n\tprepareContextCompaction,\n} from \"./context-transcript-analysis.ts\";\nexport { validateContextDeletionRequest } from \"./context-deletion-application.ts\";\nexport { createContextDeletionTool } from \"./context-deletion-tools.ts\";\nexport { buildContextCompactionPrompt } from \"./context-compaction-prompt.ts\";\nexport { contextCompact } from \"./context-compaction-runner.ts\";\n"]}
@@ -1,8 +0,0 @@
1
- export { CONTEXT_COMPACTION_AUTO_QUERY, CONTEXT_COMPACTION_DEFAULT_COMPRESSION_RATIO, CONTEXT_COMPACTION_DEFAULT_PRESERVE_RECENT, CONTEXT_COMPACTION_PROMPT_VERSION, CONTEXT_COMPACTION_TARGET_REDUCTION_PERCENT, } from "./context-compaction-types.js";
2
- export { normalizeContextCompactionParameters } from "./context-compaction-strategy.js";
3
- export { autoDetectContextCompactionQuery, prepareContextCompaction, } from "./context-transcript-analysis.js";
4
- export { validateContextDeletionRequest } from "./context-deletion-application.js";
5
- export { createContextDeletionTool } from "./context-deletion-tools.js";
6
- export { buildContextCompactionPrompt } from "./context-compaction-prompt.js";
7
- export { contextCompact } from "./context-compaction-runner.js";
8
- //# sourceMappingURL=context-compaction.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context-compaction.js","sourceRoot":"","sources":["../../../src/core/compaction/context-compaction.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,6BAA6B,EAC7B,4CAA4C,EAC5C,0CAA0C,EAC1C,iCAAiC,EACjC,2CAA2C,GAC3C,MAAM,+BAA+B,CAAC;AAuBvC,OAAO,EAAE,oCAAoC,EAAE,MAAM,kCAAkC,CAAC;AACxF,OAAO,EACN,gCAAgC,EAChC,wBAAwB,GACxB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,8BAA8B,EAAE,MAAM,mCAAmC,CAAC;AACnF,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC","sourcesContent":["export {\n\tCONTEXT_COMPACTION_AUTO_QUERY,\n\tCONTEXT_COMPACTION_DEFAULT_COMPRESSION_RATIO,\n\tCONTEXT_COMPACTION_DEFAULT_PRESERVE_RECENT,\n\tCONTEXT_COMPACTION_PROMPT_VERSION,\n\tCONTEXT_COMPACTION_TARGET_REDUCTION_PERCENT,\n} from \"./context-compaction-types.ts\";\nexport type {\n\tCompactableContentBlock,\n\tCompactableTranscript,\n\tCompactableTranscriptEntry,\n\tContextCompactionParameters,\n\tContextCompactionPreparation,\n\tContextCompactionResult,\n\tContextCompactionRunOptions,\n\tContextDeletionRequest,\n\tValidatedContextDeletionResult,\n} from \"./context-compaction-types.ts\";\nexport type {\n\tContextCompactionBudgetToolDetails,\n\tContextDeletionToolController,\n\tContextDeletionToolDetails,\n\tContextGrepDeletionMatch,\n\tContextGrepDeletionSkipped,\n\tContextGrepDeletionToolDetails,\n\tContextReadEntryToolDetails,\n\tContextTranscriptSearchMatch,\n\tContextTranscriptSearchToolDetails,\n} from \"./context-deletion-tool-definitions.ts\";\nexport { normalizeContextCompactionParameters } from \"./context-compaction-strategy.ts\";\nexport {\n\tautoDetectContextCompactionQuery,\n\tprepareContextCompaction,\n} from \"./context-transcript-analysis.ts\";\nexport { validateContextDeletionRequest } from \"./context-deletion-application.ts\";\nexport { createContextDeletionTool } from \"./context-deletion-tools.ts\";\nexport { buildContextCompactionPrompt } from \"./context-compaction-prompt.ts\";\nexport { contextCompact } from \"./context-compaction-runner.ts\";\n"]}
@@ -1,14 +0,0 @@
1
- import type { ContextCompactionStats, ContextDeletionTarget } from "../session-manager.ts";
2
- import type { CompactableTranscript, ContextDeletionRequest, ValidatedContextDeletionResult } from "./context-compaction-types.ts";
3
- export declare function reconcileToolDependencies(transcript: CompactableTranscript, initialTargets: readonly ContextDeletionTarget[]): ContextDeletionTarget[];
4
- export declare function computeContextCompactionStats(transcript: CompactableTranscript, targets: readonly ContextDeletionTarget[]): ContextCompactionStats;
5
- /**
6
- * A provider-visible task entry carries session intent through a real `user` message,
7
- * extension-injected `custom` message, or branch summary. Proposed block deletions count,
8
- * so an entry with only omitted whitespace remaining cannot satisfy the task floor.
9
- *
10
- * Verbatim compaction must always leave at least one provider-visible task entry in context.
11
- */
12
- export declare function validateContextDeletionRequest(request: ContextDeletionRequest, transcript: CompactableTranscript): ValidatedContextDeletionResult;
13
- export declare function contextDeletionRequestFromObject(value: unknown, source: string): ContextDeletionRequest;
14
- //# sourceMappingURL=context-deletion-application.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context-deletion-application.d.ts","sourceRoot":"","sources":["../../../src/core/compaction/context-deletion-application.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC3F,OAAO,KAAK,EACX,qBAAqB,EAErB,sBAAsB,EACtB,8BAA8B,EAC9B,MAAM,+BAA+B,CAAC;AA4BvC,wBAAgB,yBAAyB,CACxC,UAAU,EAAE,qBAAqB,EACjC,cAAc,EAAE,SAAS,qBAAqB,EAAE,GAC9C,qBAAqB,EAAE,CAqGzB;AAqCD,wBAAgB,6BAA6B,CAC5C,UAAU,EAAE,qBAAqB,EACjC,OAAO,EAAE,SAAS,qBAAqB,EAAE,GACvC,sBAAsB,CAsCxB;AAED;;;;;;GAMG;AACH,wBAAgB,8BAA8B,CAC7C,OAAO,EAAE,sBAAsB,EAC/B,UAAU,EAAE,qBAAqB,GAC/B,8BAA8B,CAwGhC;AAED,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,sBAAsB,CAKvG","sourcesContent":["import type { ContextCompactionStats, ContextDeletionTarget } from \"../session-manager.ts\";\nimport type {\n\tCompactableTranscript,\n\tCompactableTranscriptEntry,\n\tContextDeletionRequest,\n\tValidatedContextDeletionResult,\n} from \"./context-compaction-types.ts\";\nimport { assistantEntryHasThinkingContentBlock } from \"./context-assistant-turns.js\";\nimport {\n\taddToolCallDeletion,\n\tassertIdOnlyDeletionTarget,\n\tassertNoAssistantThinkingContentBlockDeletionTargets,\n\tassertNoLatestAssistantThinkingDeletionTargets,\n\tassertNoRecentContextDeletionTargets,\n\tcanonicalizeEntryTargets,\n\tcanDeleteTarget,\n\tdeleteEntryTarget,\n\tfirstToolCallBlockTarget,\n\tformatProtectedDeletionError,\n\tformatProtectedToolDependencyError,\n\tformatRecentContextDeletionError,\n\tgetDeletedContentBlocks,\n\tgetDeletedEntryIds,\n\tgetRecentContextEntryIds,\n\tisRecentTarget,\n\tisTaskBearingEntry,\n\tisToolCallBlockDeleted,\n\tnormalizeRawTarget,\n\trawTargetKey,\n\ttargetKey,\n} from \"./context-deletion-targets.ts\";\n\nlet warnedReconciliationNonConvergence = false;\n\nexport function reconcileToolDependencies(\n\ttranscript: CompactableTranscript,\n\tinitialTargets: readonly ContextDeletionTarget[],\n): ContextDeletionTarget[] {\n\tconst targets = [...initialTargets];\n\tconst callEntries = new Map<string, CompactableTranscriptEntry>();\n\tconst entriesWithToolCalls = new Set<CompactableTranscriptEntry>();\n\tconst resultEntries = new Map<string, CompactableTranscriptEntry[]>();\n\n\tfor (const entry of transcript.entries) {\n\t\tfor (const callId of entry.toolCallIds) {\n\t\t\tcallEntries.set(callId, entry);\n\t\t\tentriesWithToolCalls.add(entry);\n\t\t}\n\t\tif (entry.toolResultFor) {\n\t\t\tconst results = resultEntries.get(entry.toolResultFor) ?? [];\n\t\t\tresults.push(entry);\n\t\t\tresultEntries.set(entry.toolResultFor, results);\n\t\t}\n\t}\n\n\t// Bounded fixpoint repair: each pass can add/remove paired call/result targets. In practice this\n\t// converges within one or two passes; the cap protects against accidental oscillation.\n\tlet changed = true;\n\tlet remainingPasses = Math.max(1, transcript.entries.length * 2);\n\twhile (changed && remainingPasses > 0) {\n\t\tchanged = false;\n\t\tremainingPasses -= 1;\n\t\tlet deletedEntryIds = getDeletedEntryIds(targets);\n\t\tlet deletedContentBlocks = getDeletedContentBlocks(targets);\n\t\tconst recordChange = (nextChanged: boolean): void => {\n\t\t\tif (!nextChanged) return;\n\t\t\tchanged = true;\n\t\t\tdeletedEntryIds = getDeletedEntryIds(targets);\n\t\t\tdeletedContentBlocks = getDeletedContentBlocks(targets);\n\t\t};\n\n\t\tfor (const [callId, callEntry] of callEntries) {\n\t\t\tconst callDeleted = isToolCallBlockDeleted(callEntry, callId, deletedEntryIds, deletedContentBlocks);\n\t\t\tconst results = resultEntries.get(callId) ?? [];\n\n\t\t\tif (callDeleted) {\n\t\t\t\tconst retainedProtectedResult = results.find(\n\t\t\t\t\t(entry) =>\n\t\t\t\t\t\t!deletedEntryIds.has(entry.entryId) &&\n\t\t\t\t\t\t!canDeleteTarget(transcript, { kind: \"entry\", entryId: entry.entryId }),\n\t\t\t\t);\n\t\t\t\tif (retainedProtectedResult) {\n\t\t\t\t\tconst retainedResultTarget: ContextDeletionTarget = { kind: \"entry\", entryId: retainedProtectedResult.entryId };\n\t\t\t\t\tif (isRecentTarget(transcript, retainedResultTarget)) {\n\t\t\t\t\t\tthrow new Error(formatRecentContextDeletionError(transcript, retainedResultTarget));\n\t\t\t\t\t}\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\tformatProtectedToolDependencyError(\n\t\t\t\t\t\t\ttranscript,\n\t\t\t\t\t\t\tretainedResultTarget,\n\t\t\t\t\t\t\t`Cannot delete tool call ${callId} because its paired tool result entry ${retainedProtectedResult.entryId} is protected.`,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tfor (const result of results) {\n\t\t\t\t\t\trecordChange(deleteEntryTarget(targets, result.entryId));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (isToolCallBlockDeleted(callEntry, callId, deletedEntryIds, deletedContentBlocks)) continue;\n\n\t\t\tfor (const result of results) {\n\t\t\t\tif (!deletedEntryIds.has(result.entryId)) continue;\n\t\t\t\trecordChange(deleteEntryTarget(targets, result.entryId));\n\t\t\t\tconst callEntryTarget: ContextDeletionTarget = { kind: \"entry\", entryId: callEntry.entryId };\n\t\t\t\tconst callBlockTarget = assistantEntryHasThinkingContentBlock(callEntry)\n\t\t\t\t\t? callEntryTarget\n\t\t\t\t\t: firstToolCallBlockTarget(callEntry, callId) ?? callEntryTarget;\n\t\t\t\tif (!canDeleteTarget(transcript, callBlockTarget)) {\n\t\t\t\t\tif (isRecentTarget(transcript, callBlockTarget)) {\n\t\t\t\t\t\tthrow new Error(formatRecentContextDeletionError(transcript, callBlockTarget));\n\t\t\t\t\t}\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\tformatProtectedToolDependencyError(\n\t\t\t\t\t\t\ttranscript,\n\t\t\t\t\t\t\tcallBlockTarget,\n\t\t\t\t\t\t\t`Cannot delete tool result entry ${result.entryId} because that would require deleting protected tool block for tool call ${callId}.`,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\trecordChange(addToolCallDeletion(transcript, targets, callEntry, callId));\n\t\t\t}\n\t\t}\n\n\t\tfor (const entry of entriesWithToolCalls) {\n\t\t\trecordChange(canonicalizeEntryTargets(transcript, targets, entry));\n\t\t}\n\t}\n\n\tif (changed && !warnedReconciliationNonConvergence) {\n\t\twarnedReconciliationNonConvergence = true;\n\t\tconsole.warn(\n\t\t\t`Context compaction tool dependency reconciliation did not converge within the bounded pass limit; validation will continue with the last reconciled target set. entries=${transcript.entries.length} callEntries=${callEntries.size} targets=${targets.length}`,\n\t\t);\n\t}\n\n\treturn targets;\n}\n\nfunction validateToolDependencies(transcript: CompactableTranscript, targets: readonly ContextDeletionTarget[]): void {\n\tconst deletedEntryIds = getDeletedEntryIds(targets);\n\tconst deletedContentBlocks = getDeletedContentBlocks(targets);\n\tconst callEntries = new Map<string, CompactableTranscriptEntry>();\n\tconst resultEntries = new Map<string, CompactableTranscriptEntry[]>();\n\n\tfor (const entry of transcript.entries) {\n\t\tfor (const callId of entry.toolCallIds) {\n\t\t\tcallEntries.set(callId, entry);\n\t\t}\n\t\tif (entry.toolResultFor) {\n\t\t\tconst results = resultEntries.get(entry.toolResultFor) ?? [];\n\t\t\tresults.push(entry);\n\t\t\tresultEntries.set(entry.toolResultFor, results);\n\t\t}\n\t}\n\n\tfor (const [callId, callEntry] of callEntries) {\n\t\tconst callDeleted = isToolCallBlockDeleted(callEntry, callId, deletedEntryIds, deletedContentBlocks);\n\t\tconst results = resultEntries.get(callId) ?? [];\n\t\tif (callDeleted) {\n\t\t\tconst danglingResult = results.find((entry) => !deletedEntryIds.has(entry.entryId));\n\t\t\tif (danglingResult) {\n\t\t\t\tthrow new Error(`Deleting tool call ${callId} would leave tool result entry ${danglingResult.entryId} orphaned`);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst deletedResult = results.find((entry) => deletedEntryIds.has(entry.entryId));\n\t\tif (deletedResult) {\n\t\t\tthrow new Error(`Deleting tool result entry ${deletedResult.entryId} would leave tool call ${callId} dangling`);\n\t\t}\n\t}\n}\n\nexport function computeContextCompactionStats(\n\ttranscript: CompactableTranscript,\n\ttargets: readonly ContextDeletionTarget[],\n): ContextCompactionStats {\n\tconst entryById = new Map(transcript.entries.map((entry) => [entry.entryId, entry]));\n\tconst deletedEntryIds = getDeletedEntryIds(targets);\n\tlet deletedTokens = 0;\n\tlet objectsDeleted = 0;\n\n\tfor (const entryId of deletedEntryIds) {\n\t\tconst entry = entryById.get(entryId);\n\t\tif (!entry) continue;\n\t\tdeletedTokens += entry.tokenEstimate;\n\t\tobjectsDeleted += 1 + entry.contentBlocks.length;\n\t}\n\n\tconst deletedContentBlocks = getDeletedContentBlocks(targets);\n\tfor (const [entryId, blockIndexes] of deletedContentBlocks) {\n\t\tif (deletedEntryIds.has(entryId)) continue;\n\t\tconst entry = entryById.get(entryId);\n\t\tif (!entry) continue;\n\t\tconst deletedBlocks = entry.contentBlocks.filter((block) => blockIndexes.has(block.blockIndex));\n\t\tobjectsDeleted += deletedBlocks.length;\n\t\tdeletedTokens +=\n\t\t\tisTaskBearingEntry(entry) && !isTaskBearingEntry(entry, blockIndexes)\n\t\t\t\t? entry.tokenEstimate\n\t\t\t\t: deletedBlocks.reduce((total, block) => total + block.tokenEstimate, 0);\n\t}\n\n\tconst objectsBefore = transcript.entries.length + transcript.entries.reduce((total, entry) => total + entry.contentBlocks.length, 0);\n\tconst tokensBefore = transcript.tokensBefore;\n\tconst tokensAfter = Math.max(0, tokensBefore - deletedTokens);\n\tconst percentReduction = tokensBefore > 0 ? Math.round(((tokensBefore - tokensAfter) / tokensBefore) * 1000) / 10 : 0;\n\treturn {\n\t\tobjectsBefore,\n\t\tobjectsAfter: Math.max(0, objectsBefore - objectsDeleted),\n\t\tobjectsDeleted,\n\t\ttokensBefore,\n\t\ttokensAfter,\n\t\tpercentReduction,\n\t};\n}\n\n/**\n * A provider-visible task entry carries session intent through a real `user` message,\n * extension-injected `custom` message, or branch summary. Proposed block deletions count,\n * so an entry with only omitted whitespace remaining cannot satisfy the task floor.\n *\n * Verbatim compaction must always leave at least one provider-visible task entry in context.\n */\nexport function validateContextDeletionRequest(\n\trequest: ContextDeletionRequest,\n\ttranscript: CompactableTranscript,\n): ValidatedContextDeletionResult {\n\tif (!request || typeof request !== \"object\" || !Array.isArray(request.deletions)) {\n\t\tthrow new Error(\"Context deletion request must be an object with a deletions array\");\n\t}\n\n\tconst entryById = new Map(transcript.entries.map((entry) => [entry.entryId, entry]));\n\tconst recentEntryIds = getRecentContextEntryIds(transcript);\n\tconst seen = new Set<string>();\n\tconst deletedTargets: ContextDeletionTarget[] = [];\n\n\tfor (const deletion of request.deletions) {\n\t\tif (!deletion || typeof deletion !== \"object\") {\n\t\t\tthrow new Error(\"Deletion target must be an object\");\n\t\t}\n\t\tif (deletion.kind !== \"entry\" && deletion.kind !== \"content_block\") {\n\t\t\tthrow new Error(`Unsupported deletion target kind: ${String((deletion as { kind?: unknown }).kind)}`);\n\t\t}\n\t\tassertIdOnlyDeletionTarget(deletion as Record<string, unknown>);\n\t\tif (typeof deletion.entryId !== \"string\" || deletion.entryId.length === 0) {\n\t\t\tthrow new Error(\"Deletion target entryId must be a non-empty string\");\n\t\t}\n\t\tconst entry = entryById.get(deletion.entryId);\n\t\tif (!entry) {\n\t\t\tthrow new Error(`Unknown deletion target entryId: ${deletion.entryId}`);\n\t\t}\n\t\tconst normalized = normalizeRawTarget(deletion);\n\t\tif (deletion.kind === \"entry\") {\n\t\t\tif (recentEntryIds.has(deletion.entryId)) {\n\t\t\t\tthrow new Error(formatRecentContextDeletionError(transcript, normalized));\n\t\t\t}\n\t\t\tif (!canDeleteTarget(transcript, normalized)) {\n\t\t\t\tthrow new Error(formatProtectedDeletionError(transcript, normalized));\n\t\t\t}\n\t\t}\n\t\tif (deletion.kind === \"content_block\") {\n\t\t\tif (typeof deletion.blockIndex !== \"number\" || !Number.isInteger(deletion.blockIndex) || deletion.blockIndex < 0) {\n\t\t\t\tthrow new Error(`Invalid content block index for entry ${deletion.entryId}`);\n\t\t\t}\n\t\t\tif (recentEntryIds.has(deletion.entryId)) {\n\t\t\t\tthrow new Error(formatRecentContextDeletionError(transcript, normalized));\n\t\t\t}\n\t\t\tconst block = entry.contentBlocks.find((item) => item.blockIndex === deletion.blockIndex);\n\t\t\tif (!block) {\n\t\t\t\tif (entry.protected) {\n\t\t\t\t\tthrow new Error(formatProtectedDeletionError(transcript, normalized));\n\t\t\t\t}\n\t\t\t\tthrow new Error(`Unknown content block ${deletion.blockIndex} for entry ${deletion.entryId}`);\n\t\t\t}\n\t\t\tif (!canDeleteTarget(transcript, normalized)) {\n\t\t\t\tthrow new Error(formatProtectedDeletionError(transcript, normalized));\n\t\t\t}\n\t\t\tif (entry.contentBlocks.length <= 1) {\n\t\t\t\tthrow new Error(`Deleting the only content block of ${deletion.entryId} must be an entry deletion`);\n\t\t\t}\n\t\t}\n\n\t\tconst key = rawTargetKey(deletion);\n\t\tif (seen.has(key)) {\n\t\t\tthrow new Error(`Duplicate deletion target: ${key}`);\n\t\t}\n\t\tseen.add(key);\n\t\tdeletedTargets.push(normalized);\n\t}\n\n\tconst reconciledTargets = reconcileToolDependencies(transcript, deletedTargets);\n\t// Tool reconciliation can add targets after the per-request checks above, so\n\t// these post-reconcile assertions remain authoritative.\n\tassertNoRecentContextDeletionTargets(transcript, reconciledTargets);\n\tassertNoAssistantThinkingContentBlockDeletionTargets(transcript, reconciledTargets);\n\tassertNoLatestAssistantThinkingDeletionTargets(transcript, reconciledTargets);\n\tconst reconciledDeletedEntryIds = getDeletedEntryIds(reconciledTargets);\n\n\tfor (const target of reconciledTargets) {\n\t\tif (target.kind === \"content_block\" && reconciledDeletedEntryIds.has(target.entryId)) {\n\t\t\tthrow new Error(`Deletion target ${targetKey(target)} overlaps with entry deletion`);\n\t\t}\n\t}\n\n\tconst deletedContentBlocks = getDeletedContentBlocks(reconciledTargets);\n\tfor (const [entryId, blockIndexes] of deletedContentBlocks) {\n\t\tconst entry = entryById.get(entryId);\n\t\tif (entry?.contentBlocks.every((block) => blockIndexes.has(block.blockIndex))) {\n\t\t\tthrow new Error(`Content-block deletions for ${entryId} would remove every content block`);\n\t\t}\n\t}\n\n\tvalidateToolDependencies(transcript, reconciledTargets);\n\n\tconst remainingEntries = transcript.entries.filter((entry) => !reconciledDeletedEntryIds.has(entry.entryId));\n\tif (remainingEntries.length === 0) {\n\t\tthrow new Error(\"Deletion request would remove all context entries\");\n\t}\n\tconst hasTaskBearingContext = remainingEntries.some((entry) =>\n\t\tisTaskBearingEntry(entry, deletedContentBlocks.get(entry.entryId)),\n\t);\n\tif (!hasTaskBearingContext) {\n\t\tthrow new Error(\"Deletion request would leave no user task in context\");\n\t}\n\n\treturn {\n\t\tdeletedTargets: reconciledTargets,\n\t\tprotectedEntryIds: [...transcript.protectedEntryIds],\n\t\tstats: computeContextCompactionStats(transcript, reconciledTargets),\n\t};\n}\n\nexport function contextDeletionRequestFromObject(value: unknown, source: string): ContextDeletionRequest {\n\tif (!value || typeof value !== \"object\" || !Array.isArray((value as { deletions?: unknown }).deletions)) {\n\t\tthrow new Error(`${source} must contain a deletions array`);\n\t}\n\treturn value as ContextDeletionRequest;\n}\n\n"]}
@@ -1,261 +0,0 @@
1
- import { assistantEntryHasThinkingContentBlock } from "./context-assistant-turns.js";
2
- import { addToolCallDeletion, assertIdOnlyDeletionTarget, assertNoAssistantThinkingContentBlockDeletionTargets, assertNoLatestAssistantThinkingDeletionTargets, assertNoRecentContextDeletionTargets, canonicalizeEntryTargets, canDeleteTarget, deleteEntryTarget, firstToolCallBlockTarget, formatProtectedDeletionError, formatProtectedToolDependencyError, formatRecentContextDeletionError, getDeletedContentBlocks, getDeletedEntryIds, getRecentContextEntryIds, isRecentTarget, isTaskBearingEntry, isToolCallBlockDeleted, normalizeRawTarget, rawTargetKey, targetKey, } from "./context-deletion-targets.js";
3
- let warnedReconciliationNonConvergence = false;
4
- export function reconcileToolDependencies(transcript, initialTargets) {
5
- const targets = [...initialTargets];
6
- const callEntries = new Map();
7
- const entriesWithToolCalls = new Set();
8
- const resultEntries = new Map();
9
- for (const entry of transcript.entries) {
10
- for (const callId of entry.toolCallIds) {
11
- callEntries.set(callId, entry);
12
- entriesWithToolCalls.add(entry);
13
- }
14
- if (entry.toolResultFor) {
15
- const results = resultEntries.get(entry.toolResultFor) ?? [];
16
- results.push(entry);
17
- resultEntries.set(entry.toolResultFor, results);
18
- }
19
- }
20
- // Bounded fixpoint repair: each pass can add/remove paired call/result targets. In practice this
21
- // converges within one or two passes; the cap protects against accidental oscillation.
22
- let changed = true;
23
- let remainingPasses = Math.max(1, transcript.entries.length * 2);
24
- while (changed && remainingPasses > 0) {
25
- changed = false;
26
- remainingPasses -= 1;
27
- let deletedEntryIds = getDeletedEntryIds(targets);
28
- let deletedContentBlocks = getDeletedContentBlocks(targets);
29
- const recordChange = (nextChanged) => {
30
- if (!nextChanged)
31
- return;
32
- changed = true;
33
- deletedEntryIds = getDeletedEntryIds(targets);
34
- deletedContentBlocks = getDeletedContentBlocks(targets);
35
- };
36
- for (const [callId, callEntry] of callEntries) {
37
- const callDeleted = isToolCallBlockDeleted(callEntry, callId, deletedEntryIds, deletedContentBlocks);
38
- const results = resultEntries.get(callId) ?? [];
39
- if (callDeleted) {
40
- const retainedProtectedResult = results.find((entry) => !deletedEntryIds.has(entry.entryId) &&
41
- !canDeleteTarget(transcript, { kind: "entry", entryId: entry.entryId }));
42
- if (retainedProtectedResult) {
43
- const retainedResultTarget = { kind: "entry", entryId: retainedProtectedResult.entryId };
44
- if (isRecentTarget(transcript, retainedResultTarget)) {
45
- throw new Error(formatRecentContextDeletionError(transcript, retainedResultTarget));
46
- }
47
- throw new Error(formatProtectedToolDependencyError(transcript, retainedResultTarget, `Cannot delete tool call ${callId} because its paired tool result entry ${retainedProtectedResult.entryId} is protected.`));
48
- }
49
- else {
50
- for (const result of results) {
51
- recordChange(deleteEntryTarget(targets, result.entryId));
52
- }
53
- }
54
- }
55
- if (isToolCallBlockDeleted(callEntry, callId, deletedEntryIds, deletedContentBlocks))
56
- continue;
57
- for (const result of results) {
58
- if (!deletedEntryIds.has(result.entryId))
59
- continue;
60
- recordChange(deleteEntryTarget(targets, result.entryId));
61
- const callEntryTarget = { kind: "entry", entryId: callEntry.entryId };
62
- const callBlockTarget = assistantEntryHasThinkingContentBlock(callEntry)
63
- ? callEntryTarget
64
- : firstToolCallBlockTarget(callEntry, callId) ?? callEntryTarget;
65
- if (!canDeleteTarget(transcript, callBlockTarget)) {
66
- if (isRecentTarget(transcript, callBlockTarget)) {
67
- throw new Error(formatRecentContextDeletionError(transcript, callBlockTarget));
68
- }
69
- throw new Error(formatProtectedToolDependencyError(transcript, callBlockTarget, `Cannot delete tool result entry ${result.entryId} because that would require deleting protected tool block for tool call ${callId}.`));
70
- }
71
- recordChange(addToolCallDeletion(transcript, targets, callEntry, callId));
72
- }
73
- }
74
- for (const entry of entriesWithToolCalls) {
75
- recordChange(canonicalizeEntryTargets(transcript, targets, entry));
76
- }
77
- }
78
- if (changed && !warnedReconciliationNonConvergence) {
79
- warnedReconciliationNonConvergence = true;
80
- console.warn(`Context compaction tool dependency reconciliation did not converge within the bounded pass limit; validation will continue with the last reconciled target set. entries=${transcript.entries.length} callEntries=${callEntries.size} targets=${targets.length}`);
81
- }
82
- return targets;
83
- }
84
- function validateToolDependencies(transcript, targets) {
85
- const deletedEntryIds = getDeletedEntryIds(targets);
86
- const deletedContentBlocks = getDeletedContentBlocks(targets);
87
- const callEntries = new Map();
88
- const resultEntries = new Map();
89
- for (const entry of transcript.entries) {
90
- for (const callId of entry.toolCallIds) {
91
- callEntries.set(callId, entry);
92
- }
93
- if (entry.toolResultFor) {
94
- const results = resultEntries.get(entry.toolResultFor) ?? [];
95
- results.push(entry);
96
- resultEntries.set(entry.toolResultFor, results);
97
- }
98
- }
99
- for (const [callId, callEntry] of callEntries) {
100
- const callDeleted = isToolCallBlockDeleted(callEntry, callId, deletedEntryIds, deletedContentBlocks);
101
- const results = resultEntries.get(callId) ?? [];
102
- if (callDeleted) {
103
- const danglingResult = results.find((entry) => !deletedEntryIds.has(entry.entryId));
104
- if (danglingResult) {
105
- throw new Error(`Deleting tool call ${callId} would leave tool result entry ${danglingResult.entryId} orphaned`);
106
- }
107
- continue;
108
- }
109
- const deletedResult = results.find((entry) => deletedEntryIds.has(entry.entryId));
110
- if (deletedResult) {
111
- throw new Error(`Deleting tool result entry ${deletedResult.entryId} would leave tool call ${callId} dangling`);
112
- }
113
- }
114
- }
115
- export function computeContextCompactionStats(transcript, targets) {
116
- const entryById = new Map(transcript.entries.map((entry) => [entry.entryId, entry]));
117
- const deletedEntryIds = getDeletedEntryIds(targets);
118
- let deletedTokens = 0;
119
- let objectsDeleted = 0;
120
- for (const entryId of deletedEntryIds) {
121
- const entry = entryById.get(entryId);
122
- if (!entry)
123
- continue;
124
- deletedTokens += entry.tokenEstimate;
125
- objectsDeleted += 1 + entry.contentBlocks.length;
126
- }
127
- const deletedContentBlocks = getDeletedContentBlocks(targets);
128
- for (const [entryId, blockIndexes] of deletedContentBlocks) {
129
- if (deletedEntryIds.has(entryId))
130
- continue;
131
- const entry = entryById.get(entryId);
132
- if (!entry)
133
- continue;
134
- const deletedBlocks = entry.contentBlocks.filter((block) => blockIndexes.has(block.blockIndex));
135
- objectsDeleted += deletedBlocks.length;
136
- deletedTokens +=
137
- isTaskBearingEntry(entry) && !isTaskBearingEntry(entry, blockIndexes)
138
- ? entry.tokenEstimate
139
- : deletedBlocks.reduce((total, block) => total + block.tokenEstimate, 0);
140
- }
141
- const objectsBefore = transcript.entries.length + transcript.entries.reduce((total, entry) => total + entry.contentBlocks.length, 0);
142
- const tokensBefore = transcript.tokensBefore;
143
- const tokensAfter = Math.max(0, tokensBefore - deletedTokens);
144
- const percentReduction = tokensBefore > 0 ? Math.round(((tokensBefore - tokensAfter) / tokensBefore) * 1000) / 10 : 0;
145
- return {
146
- objectsBefore,
147
- objectsAfter: Math.max(0, objectsBefore - objectsDeleted),
148
- objectsDeleted,
149
- tokensBefore,
150
- tokensAfter,
151
- percentReduction,
152
- };
153
- }
154
- /**
155
- * A provider-visible task entry carries session intent through a real `user` message,
156
- * extension-injected `custom` message, or branch summary. Proposed block deletions count,
157
- * so an entry with only omitted whitespace remaining cannot satisfy the task floor.
158
- *
159
- * Verbatim compaction must always leave at least one provider-visible task entry in context.
160
- */
161
- export function validateContextDeletionRequest(request, transcript) {
162
- if (!request || typeof request !== "object" || !Array.isArray(request.deletions)) {
163
- throw new Error("Context deletion request must be an object with a deletions array");
164
- }
165
- const entryById = new Map(transcript.entries.map((entry) => [entry.entryId, entry]));
166
- const recentEntryIds = getRecentContextEntryIds(transcript);
167
- const seen = new Set();
168
- const deletedTargets = [];
169
- for (const deletion of request.deletions) {
170
- if (!deletion || typeof deletion !== "object") {
171
- throw new Error("Deletion target must be an object");
172
- }
173
- if (deletion.kind !== "entry" && deletion.kind !== "content_block") {
174
- throw new Error(`Unsupported deletion target kind: ${String(deletion.kind)}`);
175
- }
176
- assertIdOnlyDeletionTarget(deletion);
177
- if (typeof deletion.entryId !== "string" || deletion.entryId.length === 0) {
178
- throw new Error("Deletion target entryId must be a non-empty string");
179
- }
180
- const entry = entryById.get(deletion.entryId);
181
- if (!entry) {
182
- throw new Error(`Unknown deletion target entryId: ${deletion.entryId}`);
183
- }
184
- const normalized = normalizeRawTarget(deletion);
185
- if (deletion.kind === "entry") {
186
- if (recentEntryIds.has(deletion.entryId)) {
187
- throw new Error(formatRecentContextDeletionError(transcript, normalized));
188
- }
189
- if (!canDeleteTarget(transcript, normalized)) {
190
- throw new Error(formatProtectedDeletionError(transcript, normalized));
191
- }
192
- }
193
- if (deletion.kind === "content_block") {
194
- if (typeof deletion.blockIndex !== "number" || !Number.isInteger(deletion.blockIndex) || deletion.blockIndex < 0) {
195
- throw new Error(`Invalid content block index for entry ${deletion.entryId}`);
196
- }
197
- if (recentEntryIds.has(deletion.entryId)) {
198
- throw new Error(formatRecentContextDeletionError(transcript, normalized));
199
- }
200
- const block = entry.contentBlocks.find((item) => item.blockIndex === deletion.blockIndex);
201
- if (!block) {
202
- if (entry.protected) {
203
- throw new Error(formatProtectedDeletionError(transcript, normalized));
204
- }
205
- throw new Error(`Unknown content block ${deletion.blockIndex} for entry ${deletion.entryId}`);
206
- }
207
- if (!canDeleteTarget(transcript, normalized)) {
208
- throw new Error(formatProtectedDeletionError(transcript, normalized));
209
- }
210
- if (entry.contentBlocks.length <= 1) {
211
- throw new Error(`Deleting the only content block of ${deletion.entryId} must be an entry deletion`);
212
- }
213
- }
214
- const key = rawTargetKey(deletion);
215
- if (seen.has(key)) {
216
- throw new Error(`Duplicate deletion target: ${key}`);
217
- }
218
- seen.add(key);
219
- deletedTargets.push(normalized);
220
- }
221
- const reconciledTargets = reconcileToolDependencies(transcript, deletedTargets);
222
- // Tool reconciliation can add targets after the per-request checks above, so
223
- // these post-reconcile assertions remain authoritative.
224
- assertNoRecentContextDeletionTargets(transcript, reconciledTargets);
225
- assertNoAssistantThinkingContentBlockDeletionTargets(transcript, reconciledTargets);
226
- assertNoLatestAssistantThinkingDeletionTargets(transcript, reconciledTargets);
227
- const reconciledDeletedEntryIds = getDeletedEntryIds(reconciledTargets);
228
- for (const target of reconciledTargets) {
229
- if (target.kind === "content_block" && reconciledDeletedEntryIds.has(target.entryId)) {
230
- throw new Error(`Deletion target ${targetKey(target)} overlaps with entry deletion`);
231
- }
232
- }
233
- const deletedContentBlocks = getDeletedContentBlocks(reconciledTargets);
234
- for (const [entryId, blockIndexes] of deletedContentBlocks) {
235
- const entry = entryById.get(entryId);
236
- if (entry?.contentBlocks.every((block) => blockIndexes.has(block.blockIndex))) {
237
- throw new Error(`Content-block deletions for ${entryId} would remove every content block`);
238
- }
239
- }
240
- validateToolDependencies(transcript, reconciledTargets);
241
- const remainingEntries = transcript.entries.filter((entry) => !reconciledDeletedEntryIds.has(entry.entryId));
242
- if (remainingEntries.length === 0) {
243
- throw new Error("Deletion request would remove all context entries");
244
- }
245
- const hasTaskBearingContext = remainingEntries.some((entry) => isTaskBearingEntry(entry, deletedContentBlocks.get(entry.entryId)));
246
- if (!hasTaskBearingContext) {
247
- throw new Error("Deletion request would leave no user task in context");
248
- }
249
- return {
250
- deletedTargets: reconciledTargets,
251
- protectedEntryIds: [...transcript.protectedEntryIds],
252
- stats: computeContextCompactionStats(transcript, reconciledTargets),
253
- };
254
- }
255
- export function contextDeletionRequestFromObject(value, source) {
256
- if (!value || typeof value !== "object" || !Array.isArray(value.deletions)) {
257
- throw new Error(`${source} must contain a deletions array`);
258
- }
259
- return value;
260
- }
261
- //# sourceMappingURL=context-deletion-application.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context-deletion-application.js","sourceRoot":"","sources":["../../../src/core/compaction/context-deletion-application.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,qCAAqC,EAAE,MAAM,8BAA8B,CAAC;AACrF,OAAO,EACN,mBAAmB,EACnB,0BAA0B,EAC1B,oDAAoD,EACpD,8CAA8C,EAC9C,oCAAoC,EACpC,wBAAwB,EACxB,eAAe,EACf,iBAAiB,EACjB,wBAAwB,EACxB,4BAA4B,EAC5B,kCAAkC,EAClC,gCAAgC,EAChC,uBAAuB,EACvB,kBAAkB,EAClB,wBAAwB,EACxB,cAAc,EACd,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,YAAY,EACZ,SAAS,GACT,MAAM,+BAA+B,CAAC;AAEvC,IAAI,kCAAkC,GAAG,KAAK,CAAC;AAE/C,MAAM,UAAU,yBAAyB,CACxC,UAAiC,EACjC,cAAgD;IAEhD,MAAM,OAAO,GAAG,CAAC,GAAG,cAAc,CAAC,CAAC;IACpC,MAAM,WAAW,GAAG,IAAI,GAAG,EAAsC,CAAC;IAClE,MAAM,oBAAoB,GAAG,IAAI,GAAG,EAA8B,CAAC;IACnE,MAAM,aAAa,GAAG,IAAI,GAAG,EAAwC,CAAC;IAEtE,KAAK,MAAM,KAAK,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;QACxC,KAAK,MAAM,MAAM,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;YACxC,WAAW,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YAC/B,oBAAoB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACjC,CAAC;QACD,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GAAG,UAAU,CAAC,iBAAiB,CAAC;QACpD,KAAK,EAAE,6BAA6B,CAAC,UAAU,EAAE,iBAAiB,CAAC;KACnE,CAAC;AACH,CAAC;AAED,MAAM,UAAU,gCAAgC,CAAC,KAAc,EAAE,MAAc;IAC9E,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAE,KAAiC,CAAC,SAAS,CAAC,EAAE,CAAC;QACzG,MAAM,IAAI,KAAK,CAAC,GAAG,MAAM,iCAAiC,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,KAA+B,CAAC;AACxC,CAAC","sourcesContent":["import type { ContextCompactionStats, ContextDeletionTarget } from \"../session-manager.ts\";\nimport type {\n\tCompactableTranscript,\n\tCompactableTranscriptEntry,\n\tContextDeletionRequest,\n\tValidatedContextDeletionResult,\n} from \"./context-compaction-types.ts\";\nimport { assistantEntryHasThinkingContentBlock } from \"./context-assistant-turns.js\";\nimport {\n\taddToolCallDeletion,\n\tassertIdOnlyDeletionTarget,\n\tassertNoAssistantThinkingContentBlockDeletionTargets,\n\tassertNoLatestAssistantThinkingDeletionTargets,\n\tassertNoRecentContextDeletionTargets,\n\tcanonicalizeEntryTargets,\n\tcanDeleteTarget,\n\tdeleteEntryTarget,\n\tfirstToolCallBlockTarget,\n\tformatProtectedDeletionError,\n\tformatProtectedToolDependencyError,\n\tformatRecentContextDeletionError,\n\tgetDeletedContentBlocks,\n\tgetDeletedEntryIds,\n\tgetRecentContextEntryIds,\n\tisRecentTarget,\n\tisTaskBearingEntry,\n\tisToolCallBlockDeleted,\n\tnormalizeRawTarget,\n\trawTargetKey,\n\ttargetKey,\n} from \"./context-deletion-targets.ts\";\n\nlet warnedReconciliationNonConvergence = false;\n\nexport function reconcileToolDependencies(\n\ttranscript: CompactableTranscript,\n\tinitialTargets: readonly ContextDeletionTarget[],\n): ContextDeletionTarget[] {\n\tconst targets = [...initialTargets];\n\tconst callEntries = new Map<string, CompactableTranscriptEntry>();\n\tconst entriesWithToolCalls = new Set<CompactableTranscriptEntry>();\n\tconst resultEntries = new Map<string, CompactableTranscriptEntry[]>();\n\n\tfor (const entry of transcript.entries) {\n\t\tfor (const callId of entry.toolCallIds) {\n\t\t\tcallEntries.set(callId, entry);\n\t\t\tentriesWithToolCalls.add(entry);\n\t\t}\n\t\tif (entry.toolResultFor) {\n\t\t\tconst results = resultEntries.get(entry.toolResultFor) ?? [];\n\t\t\tresults.push(entry);\n\t\t\tresultEntries.set(entry.toolResultFor, results);\n\t\t}\n\t}\n\n\t// Bounded fixpoint repair: each pass can add/remove paired call/result targets. In practice this\n\t// converges within one or two passes; the cap protects against accidental oscillation.\n\tlet changed = true;\n\tlet remainingPasses = Math.max(1, transcript.entries.length * 2);\n\twhile (changed && remainingPasses > 0) {\n\t\tchanged = false;\n\t\tremainingPasses -= 1;\n\t\tlet deletedEntryIds = getDeletedEntryIds(targets);\n\t\tlet deletedContentBlocks = getDeletedContentBlocks(targets);\n\t\tconst recordChange = (nextChanged: boolean): void => {\n\t\t\tif (!nextChanged) return;\n\t\t\tchanged = true;\n\t\t\tdeletedEntryIds = getDeletedEntryIds(targets);\n\t\t\tdeletedContentBlocks = getDeletedContentBlocks(targets);\n\t\t};\n\n\t\tfor (const [callId, callEntry] of callEntries) {\n\t\t\tconst callDeleted = isToolCallBlockDeleted(callEntry, callId, deletedEntryIds, deletedContentBlocks);\n\t\t\tconst results = resultEntries.get(callId) ?? [];\n\n\t\t\tif (callDeleted) {\n\t\t\t\tconst retainedProtectedResult = results.find(\n\t\t\t\t\t(entry) =>\n\t\t\t\t\t\t!deletedEntryIds.has(entry.entryId) &&\n\t\t\t\t\t\t!canDeleteTarget(transcript, { kind: \"entry\", entryId: entry.entryId }),\n\t\t\t\t);\n\t\t\t\tif (retainedProtectedResult) {\n\t\t\t\t\tconst retainedResultTarget: ContextDeletionTarget = { kind: \"entry\", entryId: retainedProtectedResult.entryId };\n\t\t\t\t\tif (isRecentTarget(transcript, retainedResultTarget)) {\n\t\t\t\t\t\tthrow new Error(formatRecentContextDeletionError(transcript, retainedResultTarget));\n\t\t\t\t\t}\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\tformatProtectedToolDependencyError(\n\t\t\t\t\t\t\ttranscript,\n\t\t\t\t\t\t\tretainedResultTarget,\n\t\t\t\t\t\t\t`Cannot delete tool call ${callId} because its paired tool result entry ${retainedProtectedResult.entryId} is protected.`,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tfor (const result of results) {\n\t\t\t\t\t\trecordChange(deleteEntryTarget(targets, result.entryId));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (isToolCallBlockDeleted(callEntry, callId, deletedEntryIds, deletedContentBlocks)) continue;\n\n\t\t\tfor (const result of results) {\n\t\t\t\tif (!deletedEntryIds.has(result.entryId)) continue;\n\t\t\t\trecordChange(deleteEntryTarget(targets, result.entryId));\n\t\t\t\tconst callEntryTarget: ContextDeletionTarget = { kind: \"entry\", entryId: callEntry.entryId };\n\t\t\t\tconst callBlockTarget = assistantEntryHasThinkingContentBlock(callEntry)\n\t\t\t\t\t? callEntryTarget\n\t\t\t\t\t: firstToolCallBlockTarget(callEntry, callId) ?? callEntryTarget;\n\t\t\t\tif (!canDeleteTarget(transcript, callBlockTarget)) {\n\t\t\t\t\tif (isRecentTarget(transcript, callBlockTarget)) {\n\t\t\t\t\t\tthrow new Error(formatRecentContextDeletionError(transcript, callBlockTarget));\n\t\t\t\t\t}\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\tformatProtectedToolDependencyError(\n\t\t\t\t\t\t\ttranscript,\n\t\t\t\t\t\t\tcallBlockTarget,\n\t\t\t\t\t\t\t`Cannot delete tool result entry ${result.entryId} because that would require deleting protected tool block for tool call ${callId}.`,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\trecordChange(addToolCallDeletion(transcript, targets, callEntry, callId));\n\t\t\t}\n\t\t}\n\n\t\tfor (const entry of entriesWithToolCalls) {\n\t\t\trecordChange(canonicalizeEntryTargets(transcript, targets, entry));\n\t\t}\n\t}\n\n\tif (changed && !warnedReconciliationNonConvergence) {\n\t\twarnedReconciliationNonConvergence = true;\n\t\tconsole.warn(\n\t\t\t`Context compaction tool dependency reconciliation did not converge within the bounded pass limit; validation will continue with the last reconciled target set. entries=${transcript.entries.length} callEntries=${callEntries.size} targets=${targets.length}`,\n\t\t);\n\t}\n\n\treturn targets;\n}\n\nfunction validateToolDependencies(transcript: CompactableTranscript, targets: readonly ContextDeletionTarget[]): void {\n\tconst deletedEntryIds = getDeletedEntryIds(targets);\n\tconst deletedContentBlocks = getDeletedContentBlocks(targets);\n\tconst callEntries = new Map<string, CompactableTranscriptEntry>();\n\tconst resultEntries = new Map<string, CompactableTranscriptEntry[]>();\n\n\tfor (const entry of transcript.entries) {\n\t\tfor (const callId of entry.toolCallIds) {\n\t\t\tcallEntries.set(callId, entry);\n\t\t}\n\t\tif (entry.toolResultFor) {\n\t\t\tconst results = resultEntries.get(entry.toolResultFor) ?? [];\n\t\t\tresults.push(entry);\n\t\t\tresultEntries.set(entry.toolResultFor, results);\n\t\t}\n\t}\n\n\tfor (const [callId, callEntry] of callEntries) {\n\t\tconst callDeleted = isToolCallBlockDeleted(callEntry, callId, deletedEntryIds, deletedContentBlocks);\n\t\tconst results = resultEntries.get(callId) ?? [];\n\t\tif (callDeleted) {\n\t\t\tconst danglingResult = results.find((entry) => !deletedEntryIds.has(entry.entryId));\n\t\t\tif (danglingResult) {\n\t\t\t\tthrow new Error(`Deleting tool call ${callId} would leave tool result entry ${danglingResult.entryId} orphaned`);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst deletedResult = results.find((entry) => deletedEntryIds.has(entry.entryId));\n\t\tif (deletedResult) {\n\t\t\tthrow new Error(`Deleting tool result entry ${deletedResult.entryId} would leave tool call ${callId} dangling`);\n\t\t}\n\t}\n}\n\nexport function computeContextCompactionStats(\n\ttranscript: CompactableTranscript,\n\ttargets: readonly ContextDeletionTarget[],\n): ContextCompactionStats {\n\tconst entryById = new Map(transcript.entries.map((entry) => [entry.entryId, entry]));\n\tconst deletedEntryIds = getDeletedEntryIds(targets);\n\tlet deletedTokens = 0;\n\tlet objectsDeleted = 0;\n\n\tfor (const entryId of deletedEntryIds) {\n\t\tconst entry = entryById.get(entryId);\n\t\tif (!entry) continue;\n\t\tdeletedTokens += entry.tokenEstimate;\n\t\tobjectsDeleted += 1 + entry.contentBlocks.length;\n\t}\n\n\tconst deletedContentBlocks = getDeletedContentBlocks(targets);\n\tfor (const [entryId, blockIndexes] of deletedContentBlocks) {\n\t\tif (deletedEntryIds.has(entryId)) continue;\n\t\tconst entry = entryById.get(entryId);\n\t\tif (!entry) continue;\n\t\tconst deletedBlocks = entry.contentBlocks.filter((block) => blockIndexes.has(block.blockIndex));\n\t\tobjectsDeleted += deletedBlocks.length;\n\t\tdeletedTokens +=\n\t\t\tisTaskBearingEntry(entry) && !isTaskBearingEntry(entry, blockIndexes)\n\t\t\t\t? entry.tokenEstimate\n\t\t\t\t: deletedBlocks.reduce((total, block) => total + block.tokenEstimate, 0);\n\t}\n\n\tconst objectsBefore = transcript.entries.length + transcript.entries.reduce((total, entry) => total + entry.contentBlocks.length, 0);\n\tconst tokensBefore = transcript.tokensBefore;\n\tconst tokensAfter = Math.max(0, tokensBefore - deletedTokens);\n\tconst percentReduction = tokensBefore > 0 ? Math.round(((tokensBefore - tokensAfter) / tokensBefore) * 1000) / 10 : 0;\n\treturn {\n\t\tobjectsBefore,\n\t\tobjectsAfter: Math.max(0, objectsBefore - objectsDeleted),\n\t\tobjectsDeleted,\n\t\ttokensBefore,\n\t\ttokensAfter,\n\t\tpercentReduction,\n\t};\n}\n\n/**\n * A provider-visible task entry carries session intent through a real `user` message,\n * extension-injected `custom` message, or branch summary. Proposed block deletions count,\n * so an entry with only omitted whitespace remaining cannot satisfy the task floor.\n *\n * Verbatim compaction must always leave at least one provider-visible task entry in context.\n */\nexport function validateContextDeletionRequest(\n\trequest: ContextDeletionRequest,\n\ttranscript: CompactableTranscript,\n): ValidatedContextDeletionResult {\n\tif (!request || typeof request !== \"object\" || !Array.isArray(request.deletions)) {\n\t\tthrow new Error(\"Context deletion request must be an object with a deletions array\");\n\t}\n\n\tconst entryById = new Map(transcript.entries.map((entry) => [entry.entryId, entry]));\n\tconst recentEntryIds = getRecentContextEntryIds(transcript);\n\tconst seen = new Set<string>();\n\tconst deletedTargets: ContextDeletionTarget[] = [];\n\n\tfor (const deletion of request.deletions) {\n\t\tif (!deletion || typeof deletion !== \"object\") {\n\t\t\tthrow new Error(\"Deletion target must be an object\");\n\t\t}\n\t\tif (deletion.kind !== \"entry\" && deletion.kind !== \"content_block\") {\n\t\t\tthrow new Error(`Unsupported deletion target kind: ${String((deletion as { kind?: unknown }).kind)}`);\n\t\t}\n\t\tassertIdOnlyDeletionTarget(deletion as Record<string, unknown>);\n\t\tif (typeof deletion.entryId !== \"string\" || deletion.entryId.length === 0) {\n\t\t\tthrow new Error(\"Deletion target entryId must be a non-empty string\");\n\t\t}\n\t\tconst entry = entryById.get(deletion.entryId);\n\t\tif (!entry) {\n\t\t\tthrow new Error(`Unknown deletion target entryId: ${deletion.entryId}`);\n\t\t}\n\t\tconst normalized = normalizeRawTarget(deletion);\n\t\tif (deletion.kind === \"entry\") {\n\t\t\tif (recentEntryIds.has(deletion.entryId)) {\n\t\t\t\tthrow new Error(formatRecentContextDeletionError(transcript, normalized));\n\t\t\t}\n\t\t\tif (!canDeleteTarget(transcript, normalized)) {\n\t\t\t\tthrow new Error(formatProtectedDeletionError(transcript, normalized));\n\t\t\t}\n\t\t}\n\t\tif (deletion.kind === \"content_block\") {\n\t\t\tif (typeof deletion.blockIndex !== \"number\" || !Number.isInteger(deletion.blockIndex) || deletion.blockIndex < 0) {\n\t\t\t\tthrow new Error(`Invalid content block index for entry ${deletion.entryId}`);\n\t\t\t}\n\t\t\tif (recentEntryIds.has(deletion.entryId)) {\n\t\t\t\tthrow new Error(formatRecentContextDeletionError(transcript, normalized));\n\t\t\t}\n\t\t\tconst block = entry.contentBlocks.find((item) => item.blockIndex === deletion.blockIndex);\n\t\t\tif (!block) {\n\t\t\t\tif (entry.protected) {\n\t\t\t\t\tthrow new Error(formatProtectedDeletionError(transcript, normalized));\n\t\t\t\t}\n\t\t\t\tthrow new Error(`Unknown content block ${deletion.blockIndex} for entry ${deletion.entryId}`);\n\t\t\t}\n\t\t\tif (!canDeleteTarget(transcript, normalized)) {\n\t\t\t\tthrow new Error(formatProtectedDeletionError(transcript, normalized));\n\t\t\t}\n\t\t\tif (entry.contentBlocks.length <= 1) {\n\t\t\t\tthrow new Error(`Deleting the only content block of ${deletion.entryId} must be an entry deletion`);\n\t\t\t}\n\t\t}\n\n\t\tconst key = rawTargetKey(deletion);\n\t\tif (seen.has(key)) {\n\t\t\tthrow new Error(`Duplicate deletion target: ${key}`);\n\t\t}\n\t\tseen.add(key);\n\t\tdeletedTargets.push(normalized);\n\t}\n\n\tconst reconciledTargets = reconcileToolDependencies(transcript, deletedTargets);\n\t// Tool reconciliation can add targets after the per-request checks above, so\n\t// these post-reconcile assertions remain authoritative.\n\tassertNoRecentContextDeletionTargets(transcript, reconciledTargets);\n\tassertNoAssistantThinkingContentBlockDeletionTargets(transcript, reconciledTargets);\n\tassertNoLatestAssistantThinkingDeletionTargets(transcript, reconciledTargets);\n\tconst reconciledDeletedEntryIds = getDeletedEntryIds(reconciledTargets);\n\n\tfor (const target of reconciledTargets) {\n\t\tif (target.kind === \"content_block\" && reconciledDeletedEntryIds.has(target.entryId)) {\n\t\t\tthrow new Error(`Deletion target ${targetKey(target)} overlaps with entry deletion`);\n\t\t}\n\t}\n\n\tconst deletedContentBlocks = getDeletedContentBlocks(reconciledTargets);\n\tfor (const [entryId, blockIndexes] of deletedContentBlocks) {\n\t\tconst entry = entryById.get(entryId);\n\t\tif (entry?.contentBlocks.every((block) => blockIndexes.has(block.blockIndex))) {\n\t\t\tthrow new Error(`Content-block deletions for ${entryId} would remove every content block`);\n\t\t}\n\t}\n\n\tvalidateToolDependencies(transcript, reconciledTargets);\n\n\tconst remainingEntries = transcript.entries.filter((entry) => !reconciledDeletedEntryIds.has(entry.entryId));\n\tif (remainingEntries.length === 0) {\n\t\tthrow new Error(\"Deletion request would remove all context entries\");\n\t}\n\tconst hasTaskBearingContext = remainingEntries.some((entry) =>\n\t\tisTaskBearingEntry(entry, deletedContentBlocks.get(entry.entryId)),\n\t);\n\tif (!hasTaskBearingContext) {\n\t\tthrow new Error(\"Deletion request would leave no user task in context\");\n\t}\n\n\treturn {\n\t\tdeletedTargets: reconciledTargets,\n\t\tprotectedEntryIds: [...transcript.protectedEntryIds],\n\t\tstats: computeContextCompactionStats(transcript, reconciledTargets),\n\t};\n}\n\nexport function contextDeletionRequestFromObject(value: unknown, source: string): ContextDeletionRequest {\n\tif (!value || typeof value !== \"object\" || !Array.isArray((value as { deletions?: unknown }).deletions)) {\n\t\tthrow new Error(`${source} must contain a deletions array`);\n\t}\n\treturn value as ContextDeletionRequest;\n}\n\n"]}