@bastani/atomic 0.9.11-alpha.5 → 0.9.11-alpha.7

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 (1127) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/README.md +12 -5
  3. package/dist/builtin/intercom/package.json +2 -2
  4. package/dist/builtin/mcp/CHANGELOG.md +6 -0
  5. package/dist/builtin/mcp/README.md +3 -3
  6. package/dist/builtin/mcp/cli.js +0 -1
  7. package/dist/builtin/mcp/config.ts +0 -2
  8. package/dist/builtin/mcp/package.json +3 -3
  9. package/dist/builtin/mcp/types.ts +0 -1
  10. package/dist/builtin/subagents/CHANGELOG.md +12 -0
  11. package/dist/builtin/subagents/README.md +1 -1
  12. package/dist/builtin/subagents/agents/code-simplifier.md +47 -102
  13. package/dist/builtin/subagents/agents/codebase-analyzer.md +27 -130
  14. package/dist/builtin/subagents/agents/codebase-locator.md +24 -83
  15. package/dist/builtin/subagents/agents/codebase-online-researcher.md +60 -259
  16. package/dist/builtin/subagents/agents/codebase-pattern-finder.md +29 -207
  17. package/dist/builtin/subagents/agents/codebase-research-analyzer.md +28 -150
  18. package/dist/builtin/subagents/agents/codebase-research-locator.md +21 -118
  19. package/dist/builtin/subagents/agents/debugger.md +27 -65
  20. package/dist/builtin/subagents/agents/worker.md +23 -30
  21. package/dist/builtin/subagents/package.json +4 -4
  22. package/dist/builtin/subagents/prompts/gather-context-and-clarify.md +18 -11
  23. package/dist/builtin/subagents/prompts/parallel-cleanup.md +34 -33
  24. package/dist/builtin/subagents/prompts/parallel-context-build.md +22 -36
  25. package/dist/builtin/subagents/prompts/parallel-handoff-plan.md +20 -52
  26. package/dist/builtin/subagents/prompts/parallel-research.md +17 -41
  27. package/dist/builtin/subagents/prompts/parallel-review.md +23 -28
  28. package/dist/builtin/subagents/prompts/review-loop.md +18 -27
  29. package/dist/builtin/subagents/src/extension/prompt-guidance.ts +1 -1
  30. package/dist/builtin/subagents/src/runs/background/async-execution-chain.ts +23 -4
  31. package/dist/builtin/subagents/src/runs/background/async-execution-single.ts +2 -0
  32. package/dist/builtin/subagents/src/runs/background/async-execution-types.ts +10 -0
  33. package/dist/builtin/subagents/src/runs/background/subagent-runner-step.ts +1 -0
  34. package/dist/builtin/subagents/src/runs/foreground/chain-execution-dynamic-step.ts +2 -0
  35. package/dist/builtin/subagents/src/runs/foreground/chain-execution-parallel-runner.ts +8 -0
  36. package/dist/builtin/subagents/src/runs/foreground/chain-execution-parallel-step.ts +1 -0
  37. package/dist/builtin/subagents/src/runs/foreground/chain-execution-sequential-step.ts +6 -0
  38. package/dist/builtin/subagents/src/runs/foreground/chain-execution-types.ts +2 -0
  39. package/dist/builtin/subagents/src/runs/foreground/subagent-executor-async.ts +7 -0
  40. package/dist/builtin/subagents/src/runs/foreground/subagent-executor-chain.ts +1 -0
  41. package/dist/builtin/subagents/src/runs/foreground/subagent-executor-resume.ts +3 -0
  42. package/dist/builtin/subagents/src/runs/shared/mcp-direct-tool-allowlist.ts +1 -2
  43. package/dist/builtin/subagents/src/runs/shared/parallel-utils.ts +1 -0
  44. package/dist/builtin/subagents/src/runs/shared/pi-args.ts +5 -3
  45. package/dist/builtin/subagents/src/shared/settings.ts +4 -0
  46. package/dist/builtin/web-access/package.json +2 -2
  47. package/dist/builtin/workflows/CHANGELOG.md +44 -0
  48. package/dist/builtin/workflows/README.md +72 -70
  49. package/dist/builtin/workflows/ambient.d.ts +0 -5
  50. package/dist/builtin/workflows/builtin/adversarial-verification-prompts.ts +7 -4
  51. package/dist/builtin/workflows/builtin/adversarial-verification-runner.ts +1 -1
  52. package/dist/builtin/workflows/builtin/adversarial-verification.ts +2 -1
  53. package/dist/builtin/workflows/builtin/classify-and-act-prompts.ts +5 -2
  54. package/dist/builtin/workflows/builtin/classify-and-act-runner.ts +5 -7
  55. package/dist/builtin/workflows/builtin/classify-and-act.ts +3 -2
  56. package/dist/builtin/workflows/builtin/fan-out-and-synthesize-prompts.ts +6 -3
  57. package/dist/builtin/workflows/builtin/fan-out-and-synthesize-runner.ts +5 -5
  58. package/dist/builtin/workflows/builtin/fan-out-and-synthesize.ts +3 -2
  59. package/dist/builtin/workflows/builtin/generate-and-filter-prompts.ts +7 -4
  60. package/dist/builtin/workflows/builtin/generate-and-filter-runner.ts +6 -3
  61. package/dist/builtin/workflows/builtin/generate-and-filter.ts +3 -2
  62. package/dist/builtin/workflows/builtin/goal-models.ts +14 -18
  63. package/dist/builtin/workflows/builtin/goal-orchestrator-prompts.ts +39 -78
  64. package/dist/builtin/workflows/builtin/goal-prompts.ts +64 -244
  65. package/dist/builtin/workflows/builtin/goal-runner.ts +32 -64
  66. package/dist/builtin/workflows/builtin/goal.ts +2 -1
  67. package/dist/builtin/workflows/builtin/index.d.ts +17 -112
  68. package/dist/builtin/workflows/builtin/index.ts +1 -2
  69. package/dist/builtin/workflows/builtin/loop-until-done-prompts.ts +20 -12
  70. package/dist/builtin/workflows/builtin/loop-until-done-runner.ts +3 -0
  71. package/dist/builtin/workflows/builtin/loop-until-done.ts +3 -2
  72. package/dist/builtin/workflows/builtin/open-claude-design-phases.ts +52 -55
  73. package/dist/builtin/workflows/builtin/open-claude-design-runner.ts +45 -52
  74. package/dist/builtin/workflows/builtin/open-claude-design-setup.ts +41 -46
  75. package/dist/builtin/workflows/builtin/open-claude-design-utils.ts +16 -21
  76. package/dist/builtin/workflows/builtin/open-claude-design.ts +2 -1
  77. package/dist/builtin/workflows/builtin/ralph-core.ts +61 -57
  78. package/dist/builtin/workflows/builtin/ralph-forked-prompts.ts +41 -45
  79. package/dist/builtin/workflows/builtin/ralph-models.ts +33 -43
  80. package/dist/builtin/workflows/builtin/ralph-reviewer-prompt.ts +35 -120
  81. package/dist/builtin/workflows/builtin/ralph-runner.ts +81 -108
  82. package/dist/builtin/workflows/builtin/ralph.ts +2 -1
  83. package/dist/builtin/workflows/builtin/shared-prompts.ts +110 -93
  84. package/dist/builtin/workflows/builtin/steering-context.ts +51 -0
  85. package/dist/builtin/workflows/builtin/tournament-prompts.ts +21 -12
  86. package/dist/builtin/workflows/builtin/tournament-runner.ts +3 -0
  87. package/dist/builtin/workflows/builtin/tournament.ts +3 -2
  88. package/dist/builtin/workflows/package.json +2 -2
  89. package/dist/builtin/workflows/skills/create-spec/SKILL.md +1 -1
  90. package/dist/builtin/workflows/skills/impeccable/SKILL.md +33 -129
  91. package/dist/builtin/workflows/skills/impeccable/agents/impeccable_asset_producer.toml +11 -3
  92. package/dist/builtin/workflows/skills/impeccable/agents/impeccable_documenter.toml +26 -0
  93. package/dist/builtin/workflows/skills/impeccable/agents/impeccable_finish_reviewer.toml +35 -0
  94. package/dist/builtin/workflows/skills/impeccable/reference/android.md +1 -1
  95. package/dist/builtin/workflows/skills/impeccable/reference/animate.md +72 -189
  96. package/dist/builtin/workflows/skills/impeccable/reference/audit.md +10 -9
  97. package/dist/builtin/workflows/skills/impeccable/reference/audit.native.md +2 -2
  98. package/dist/builtin/workflows/skills/impeccable/reference/bolder.md +19 -108
  99. package/dist/builtin/workflows/skills/impeccable/reference/clarify.md +59 -253
  100. package/dist/builtin/workflows/skills/impeccable/reference/colorize.md +51 -222
  101. package/dist/builtin/workflows/skills/impeccable/reference/craft-floor.md +45 -0
  102. package/dist/builtin/workflows/skills/impeccable/reference/craft.md +3 -121
  103. package/dist/builtin/workflows/skills/impeccable/reference/critique.md +28 -20
  104. package/dist/builtin/workflows/skills/impeccable/reference/degraded/asset-producer.md +97 -0
  105. package/dist/builtin/workflows/skills/impeccable/reference/degraded/documenter.md +23 -0
  106. package/dist/builtin/workflows/skills/impeccable/reference/degraded/finish-reviewer.md +32 -0
  107. package/dist/builtin/workflows/skills/impeccable/reference/degraded/manual-edit-applier.md +92 -0
  108. package/dist/builtin/workflows/skills/impeccable/reference/delight.md +47 -279
  109. package/dist/builtin/workflows/skills/impeccable/reference/distill.md +2 -2
  110. package/dist/builtin/workflows/skills/impeccable/reference/doctor.md +53 -0
  111. package/dist/builtin/workflows/skills/impeccable/reference/document.md +60 -73
  112. package/dist/builtin/workflows/skills/impeccable/reference/harden.md +1 -12
  113. package/dist/builtin/workflows/skills/impeccable/reference/hooks.md +23 -12
  114. package/dist/builtin/workflows/skills/impeccable/reference/init.md +64 -163
  115. package/dist/builtin/workflows/skills/impeccable/reference/ios.md +1 -1
  116. package/dist/builtin/workflows/skills/impeccable/reference/layout.md +52 -153
  117. package/dist/builtin/workflows/skills/impeccable/reference/live.md +47 -36
  118. package/dist/builtin/workflows/skills/impeccable/reference/new-work.md +105 -0
  119. package/dist/builtin/workflows/skills/impeccable/reference/{product.md → operate.md} +6 -5
  120. package/dist/builtin/workflows/skills/impeccable/reference/optimize.md +4 -4
  121. package/dist/builtin/workflows/skills/impeccable/reference/overdrive.md +1 -4
  122. package/dist/builtin/workflows/skills/impeccable/reference/polish.md +68 -212
  123. package/dist/builtin/workflows/skills/impeccable/reference/quieter.md +3 -3
  124. package/dist/builtin/workflows/skills/impeccable/reference/routing.md +18 -0
  125. package/dist/builtin/workflows/skills/impeccable/reference/shape.md +38 -144
  126. package/dist/builtin/workflows/skills/impeccable/reference/typeset.md +48 -269
  127. package/dist/builtin/workflows/skills/impeccable/reference/visualize.md +38 -0
  128. package/dist/builtin/workflows/skills/impeccable/scripts/command-metadata.json +1 -1
  129. package/dist/builtin/workflows/skills/impeccable/scripts/concept-seed.mjs +584 -0
  130. package/dist/builtin/workflows/skills/impeccable/scripts/context-signals.mjs +117 -9
  131. package/dist/builtin/workflows/skills/impeccable/scripts/context.mjs +486 -59
  132. package/dist/builtin/workflows/skills/impeccable/scripts/critique-storage.mjs +16 -45
  133. package/dist/builtin/workflows/skills/impeccable/scripts/detector/browser/injected/index.mjs +96 -10
  134. package/dist/builtin/workflows/skills/impeccable/scripts/detector/cli/main.mjs +143 -26
  135. package/dist/builtin/workflows/skills/impeccable/scripts/detector/design-system.mjs +181 -12
  136. package/dist/builtin/workflows/skills/impeccable/scripts/detector/detect-antipatterns-browser.js +3187 -182
  137. package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/browser/detect-url.mjs +102 -7
  138. package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/regex/detect-text.mjs +282 -70
  139. package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/static-html/css-cascade.mjs +183 -15
  140. package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/static-html/detect-html.mjs +22 -7
  141. package/dist/builtin/workflows/skills/impeccable/scripts/detector/findings.mjs +7 -1
  142. package/dist/builtin/workflows/skills/impeccable/scripts/detector/node/file-system.mjs +16 -2
  143. package/dist/builtin/workflows/skills/impeccable/scripts/detector/registry/antipatterns.mjs +155 -42
  144. package/dist/builtin/workflows/skills/impeccable/scripts/detector/rules/checks.mjs +2988 -155
  145. package/dist/builtin/workflows/skills/impeccable/scripts/detector/shared/constants.mjs +11 -0
  146. package/dist/builtin/workflows/skills/impeccable/scripts/doctor.mjs +336 -0
  147. package/dist/builtin/workflows/skills/impeccable/scripts/generate-image.mjs +232 -0
  148. package/dist/builtin/workflows/skills/impeccable/scripts/hook-admin.mjs +92 -30
  149. package/dist/builtin/workflows/skills/impeccable/scripts/hook-lib.mjs +414 -120
  150. package/dist/builtin/workflows/skills/impeccable/scripts/hook.mjs +25 -8
  151. package/dist/builtin/workflows/skills/impeccable/scripts/lib/artifact-schema.mjs +93 -0
  152. package/dist/builtin/workflows/skills/impeccable/scripts/lib/composition-catalog.mjs +165 -0
  153. package/dist/builtin/workflows/skills/impeccable/scripts/lib/concept-catalog.mjs +329 -0
  154. package/dist/builtin/workflows/skills/impeccable/scripts/lib/impeccable-config.mjs +20 -5
  155. package/dist/builtin/workflows/skills/impeccable/scripts/lib/impeccable-paths.mjs +16 -8
  156. package/dist/builtin/workflows/skills/impeccable/scripts/lib/provider.mjs +1 -0
  157. package/dist/builtin/workflows/skills/impeccable/scripts/lib/staleness-deep.mjs +455 -0
  158. package/dist/builtin/workflows/skills/impeccable/scripts/lib/staleness-notice.mjs +169 -0
  159. package/dist/builtin/workflows/skills/impeccable/scripts/lib/staleness.mjs +457 -0
  160. package/dist/builtin/workflows/skills/impeccable/scripts/lib/surface-briefs.mjs +151 -0
  161. package/dist/builtin/workflows/skills/impeccable/scripts/lib/target-slug.mjs +33 -0
  162. package/dist/builtin/workflows/skills/impeccable/scripts/lib/template-extensions.mjs +146 -0
  163. package/dist/builtin/workflows/skills/impeccable/scripts/live/completion.mjs +10 -1
  164. package/dist/builtin/workflows/skills/impeccable/scripts/live/event-validation.mjs +15 -0
  165. package/dist/builtin/workflows/skills/impeccable/scripts/live/generation-preflight.mjs +149 -0
  166. package/dist/builtin/workflows/skills/impeccable/scripts/live/poll-lanes.mjs +14 -0
  167. package/dist/builtin/workflows/skills/impeccable/scripts/live/session-store.mjs +109 -32
  168. package/dist/builtin/workflows/skills/impeccable/scripts/live/source-lock.mjs +105 -0
  169. package/dist/builtin/workflows/skills/impeccable/scripts/live/source-search.mjs +105 -0
  170. package/dist/builtin/workflows/skills/impeccable/scripts/live/sveltekit-adapter.mjs +8 -6
  171. package/dist/builtin/workflows/skills/impeccable/scripts/live/tanstack-adapter.mjs +280 -0
  172. package/dist/builtin/workflows/skills/impeccable/scripts/live-accept.mjs +208 -68
  173. package/dist/builtin/workflows/skills/impeccable/scripts/live-browser.js +565 -115
  174. package/dist/builtin/workflows/skills/impeccable/scripts/live-commit-manual-edits.mjs +3 -0
  175. package/dist/builtin/workflows/skills/impeccable/scripts/live-inject.mjs +198 -14
  176. package/dist/builtin/workflows/skills/impeccable/scripts/live-insert.mjs +24 -6
  177. package/dist/builtin/workflows/skills/impeccable/scripts/live-manual-edit-evidence.mjs +6 -1
  178. package/dist/builtin/workflows/skills/impeccable/scripts/live-poll.mjs +44 -14
  179. package/dist/builtin/workflows/skills/impeccable/scripts/live-server.mjs +398 -33
  180. package/dist/builtin/workflows/skills/impeccable/scripts/live-status.mjs +9 -5
  181. package/dist/builtin/workflows/skills/impeccable/scripts/live-wrap.mjs +81 -67
  182. package/dist/builtin/workflows/skills/impeccable/scripts/live.mjs +7 -2
  183. package/dist/builtin/workflows/skills/impeccable/scripts/palette.mjs +76 -81
  184. package/dist/builtin/workflows/skills/impeccable/scripts/pin.mjs +4 -4
  185. package/dist/builtin/workflows/skills/impeccable/scripts/serve-question.mjs +890 -0
  186. package/dist/builtin/workflows/skills/impeccable/scripts/surface-brief.mjs +74 -0
  187. package/dist/builtin/workflows/skills/prompt-engineer/SKILL.md +57 -252
  188. package/dist/builtin/workflows/skills/prompt-engineer/references/advanced_patterns.md +70 -226
  189. package/dist/builtin/workflows/skills/prompt-engineer/references/core_prompting.md +64 -103
  190. package/dist/builtin/workflows/skills/prompt-engineer/references/quality_improvement.md +81 -155
  191. package/dist/builtin/workflows/src/authoring.d.ts +5 -1
  192. package/dist/builtin/workflows/src/durable/backend.ts +68 -9
  193. package/dist/builtin/workflows/src/durable/boundary-lifecycle.ts +148 -0
  194. package/dist/builtin/workflows/src/durable/boundary-topology.ts +420 -0
  195. package/dist/builtin/workflows/src/durable/child-invocation.ts +14 -0
  196. package/dist/builtin/workflows/src/durable/child-primitive.ts +74 -44
  197. package/dist/builtin/workflows/src/durable/completed-catalog-stage-groups.ts +250 -0
  198. package/dist/builtin/workflows/src/durable/completed-catalog.ts +205 -131
  199. package/dist/builtin/workflows/src/durable/completed-inspection.ts +8 -2
  200. package/dist/builtin/workflows/src/durable/completed-subtree.ts +31 -0
  201. package/dist/builtin/workflows/src/durable/dbos-backend.ts +28 -24
  202. package/dist/builtin/workflows/src/durable/dbos-envelope.ts +130 -3
  203. package/dist/builtin/workflows/src/durable/dbos-metadata.ts +18 -0
  204. package/dist/builtin/workflows/src/durable/scoped-backend.ts +64 -17
  205. package/dist/builtin/workflows/src/durable/stage-primitive.ts +60 -60
  206. package/dist/builtin/workflows/src/durable/stage-topology-validation.ts +234 -0
  207. package/dist/builtin/workflows/src/durable/stage-topology.ts +53 -0
  208. package/dist/builtin/workflows/src/durable/tool-failure-checkpoint.ts +49 -0
  209. package/dist/builtin/workflows/src/durable/tool-outcome.ts +120 -0
  210. package/dist/builtin/workflows/src/durable/tool-primitive.ts +367 -58
  211. package/dist/builtin/workflows/src/durable/types.ts +97 -0
  212. package/dist/builtin/workflows/src/durable/ui-primitive.ts +46 -0
  213. package/dist/builtin/workflows/src/durable/workflow-child-result.ts +58 -0
  214. package/dist/builtin/workflows/src/engine/options.ts +1 -0
  215. package/dist/builtin/workflows/src/engine/primitives/workflow.ts +19 -10
  216. package/dist/builtin/workflows/src/engine/run-durable-finalize.ts +11 -1
  217. package/dist/builtin/workflows/src/engine/run-durable-topology.ts +190 -18
  218. package/dist/builtin/workflows/src/engine/run-terminal-event.ts +37 -0
  219. package/dist/builtin/workflows/src/engine/run-terminal-failure.ts +50 -0
  220. package/dist/builtin/workflows/src/engine/run-tool-execution-tracker.ts +152 -0
  221. package/dist/builtin/workflows/src/engine/run-tool-node-lifecycle.ts +87 -0
  222. package/dist/builtin/workflows/src/engine/run.ts +111 -110
  223. package/dist/builtin/workflows/src/engine/runtime.ts +15 -2
  224. package/dist/builtin/workflows/src/extension/extension-factory.ts +1 -0
  225. package/dist/builtin/workflows/src/extension/extension-runtime-state.ts +11 -0
  226. package/dist/builtin/workflows/src/extension/index.bundle.mjs +6710 -4810
  227. package/dist/builtin/workflows/src/extension/lifecycle-notifications.ts +16 -5
  228. package/dist/builtin/workflows/src/extension/render-result.ts +16 -2
  229. package/dist/builtin/workflows/src/extension/runtime-durable-resume.ts +3 -0
  230. package/dist/builtin/workflows/src/extension/runtime.ts +4 -0
  231. package/dist/builtin/workflows/src/extension/wiring.ts +3 -1
  232. package/dist/builtin/workflows/src/extension/workflow-command-surfaces.ts +1 -0
  233. package/dist/builtin/workflows/src/extension/workflow-durable-resume-command.ts +9 -3
  234. package/dist/builtin/workflows/src/extension/workflow-module-loader.ts +18 -3
  235. package/dist/builtin/workflows/src/extension/workflow-prompts.ts +22 -11
  236. package/dist/builtin/workflows/src/extension/workflow-status-summary.ts +43 -0
  237. package/dist/builtin/workflows/src/extension/workflow-targets.ts +34 -30
  238. package/dist/builtin/workflows/src/extension/workflow-tool-content.ts +12 -5
  239. package/dist/builtin/workflows/src/extension/workflow-tool-send.ts +162 -63
  240. package/dist/builtin/workflows/src/runs/background/run-inspect.ts +7 -1
  241. package/dist/builtin/workflows/src/runs/background/status.ts +18 -8
  242. package/dist/builtin/workflows/src/runs/background/workflow-lifecycle-aggregate.ts +3 -11
  243. package/dist/builtin/workflows/src/runs/foreground/executor-child-boundary.ts +24 -21
  244. package/dist/builtin/workflows/src/runs/foreground/executor-hil.ts +1 -1
  245. package/dist/builtin/workflows/src/runs/foreground/executor-lifecycle.ts +30 -13
  246. package/dist/builtin/workflows/src/runs/foreground/executor-prompt-nodes.ts +102 -53
  247. package/dist/builtin/workflows/src/runs/foreground/executor-stage-call.ts +13 -5
  248. package/dist/builtin/workflows/src/runs/foreground/executor-stage-control.ts +49 -17
  249. package/dist/builtin/workflows/src/runs/foreground/executor-stage-factory.ts +11 -4
  250. package/dist/builtin/workflows/src/runs/foreground/executor-stage-replay.ts +1 -0
  251. package/dist/builtin/workflows/src/runs/foreground/executor-stage-types.ts +4 -1
  252. package/dist/builtin/workflows/src/runs/foreground/executor-types.ts +7 -1
  253. package/dist/builtin/workflows/src/runs/foreground/postmortem-stage-chat.ts +53 -4
  254. package/dist/builtin/workflows/src/runs/foreground/stage-control-registry.ts +146 -17
  255. package/dist/builtin/workflows/src/runs/foreground/stage-delivery-activity.ts +86 -0
  256. package/dist/builtin/workflows/src/runs/foreground/stage-runner-context.ts +18 -6
  257. package/dist/builtin/workflows/src/runs/foreground/stage-runner-controller.ts +45 -46
  258. package/dist/builtin/workflows/src/runs/foreground/stage-runner-options.ts +5 -1
  259. package/dist/builtin/workflows/src/runs/foreground/stage-runner-pause.ts +195 -0
  260. package/dist/builtin/workflows/src/runs/foreground/stage-runner-send-user-message.ts +8 -0
  261. package/dist/builtin/workflows/src/runs/foreground/stage-runner-session-options.ts +0 -13
  262. package/dist/builtin/workflows/src/runs/foreground/stage-runner-types.ts +30 -2
  263. package/dist/builtin/workflows/src/runs/shared/model-fallback-candidates.ts +3 -143
  264. package/dist/builtin/workflows/src/sdk-surface.ts +1 -1
  265. package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +6 -11
  266. package/dist/builtin/workflows/src/shared/authoring-contract-stage.ts +6 -11
  267. package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +57 -6
  268. package/dist/builtin/workflows/src/shared/authoring-contract-ui.ts +76 -11
  269. package/dist/builtin/workflows/src/shared/expanded-workflow-graph.ts +206 -116
  270. package/dist/builtin/workflows/src/shared/intercom-group.ts +17 -10
  271. package/dist/builtin/workflows/src/shared/persistence-restore-helpers.ts +30 -0
  272. package/dist/builtin/workflows/src/shared/persistence-session-entries.ts +5 -0
  273. package/dist/builtin/workflows/src/shared/render-inputs-schema.ts +3 -3
  274. package/dist/builtin/workflows/src/shared/store-factory.ts +2 -0
  275. package/dist/builtin/workflows/src/shared/store-internal.ts +8 -0
  276. package/dist/builtin/workflows/src/shared/store-public-types.ts +8 -0
  277. package/dist/builtin/workflows/src/shared/store-run-methods.ts +9 -0
  278. package/dist/builtin/workflows/src/shared/store-stage-methods.ts +2 -0
  279. package/dist/builtin/workflows/src/shared/store-tool-node-methods.ts +46 -0
  280. package/dist/builtin/workflows/src/shared/store-types.ts +34 -0
  281. package/dist/builtin/workflows/src/shared/types.ts +14 -24
  282. package/dist/builtin/workflows/src/shared/workflow-failures-classifier.ts +11 -5
  283. package/dist/builtin/workflows/src/shared/workflow-failures-signals.ts +58 -0
  284. package/dist/builtin/workflows/src/shared/workflow-run-ownership.ts +53 -0
  285. package/dist/builtin/workflows/src/tui/graph-view-input.ts +2 -8
  286. package/dist/builtin/workflows/src/tui/graph-view-render-helpers.ts +11 -4
  287. package/dist/builtin/workflows/src/tui/graph-view-render.ts +1 -0
  288. package/dist/builtin/workflows/src/tui/graph-view-state.ts +27 -9
  289. package/dist/builtin/workflows/src/tui/graph-view-types.ts +4 -3
  290. package/dist/builtin/workflows/src/tui/node-card.ts +4 -3
  291. package/dist/builtin/workflows/src/tui/overlay-adapter.ts +0 -4
  292. package/dist/builtin/workflows/src/tui/run-detail.ts +53 -17
  293. package/dist/builtin/workflows/src/tui/session-list.ts +8 -4
  294. package/dist/builtin/workflows/src/tui/stage-chat-view-delivery-activity.ts +121 -0
  295. package/dist/builtin/workflows/src/tui/stage-chat-view-live-events.ts +42 -0
  296. package/dist/builtin/workflows/src/tui/stage-chat-view-render-helpers.ts +12 -0
  297. package/dist/builtin/workflows/src/tui/stage-chat-view-render-settings.ts +21 -1
  298. package/dist/builtin/workflows/src/tui/stage-chat-view-state.ts +19 -19
  299. package/dist/builtin/workflows/src/tui/stage-chat-view-types.ts +4 -0
  300. package/dist/builtin/workflows/src/tui/stage-chat-view.ts +4 -2
  301. package/dist/builtin/workflows/src/tui/switcher.ts +13 -3
  302. package/dist/builtin/workflows/src/tui/workflow-attach-pane-handle.ts +1 -1
  303. package/dist/builtin/workflows/src/tui/workflow-attach-pane-types.ts +0 -9
  304. package/dist/builtin/workflows/src/tui/workflow-attach-pane.ts +16 -49
  305. package/dist/builtin/workflows/src/tui/workflow-status.ts +7 -0
  306. package/dist/builtin/workflows/src/workflows/identity.ts +1 -1
  307. package/dist/cli/args.d.ts +0 -1
  308. package/dist/cli/args.d.ts.map +1 -1
  309. package/dist/cli/args.js +1 -20
  310. package/dist/cli/args.js.map +1 -1
  311. package/dist/cli/config-selector.js +1 -1
  312. package/dist/cli/config-selector.js.map +1 -1
  313. package/dist/cli/list-models.d.ts.map +1 -1
  314. package/dist/cli/list-models.js +1 -2
  315. package/dist/cli/list-models.js.map +1 -1
  316. package/dist/cli/session-picker.d.ts.map +1 -1
  317. package/dist/cli/session-picker.js +2 -1
  318. package/dist/cli/session-picker.js.map +1 -1
  319. package/dist/cli/startup-ui.js +2 -2
  320. package/dist/cli/startup-ui.js.map +1 -1
  321. package/dist/config-self-update.js +1 -1
  322. package/dist/config-self-update.js.map +1 -1
  323. package/dist/config.d.ts +2 -0
  324. package/dist/config.d.ts.map +1 -1
  325. package/dist/config.js +34 -10
  326. package/dist/config.js.map +1 -1
  327. package/dist/core/agent-session-accessors.d.ts.map +1 -1
  328. package/dist/core/agent-session-accessors.js +2 -1
  329. package/dist/core/agent-session-accessors.js.map +1 -1
  330. package/dist/core/agent-session-auto-compaction.d.ts +4 -3
  331. package/dist/core/agent-session-auto-compaction.d.ts.map +1 -1
  332. package/dist/core/agent-session-auto-compaction.js +55 -59
  333. package/dist/core/agent-session-auto-compaction.js.map +1 -1
  334. package/dist/core/agent-session-bash.d.ts +9 -6
  335. package/dist/core/agent-session-bash.d.ts.map +1 -1
  336. package/dist/core/agent-session-bash.js +32 -13
  337. package/dist/core/agent-session-bash.js.map +1 -1
  338. package/dist/core/agent-session-compaction.d.ts +11 -1
  339. package/dist/core/agent-session-compaction.d.ts.map +1 -1
  340. package/dist/core/agent-session-compaction.js +87 -19
  341. package/dist/core/agent-session-compaction.js.map +1 -1
  342. package/dist/core/agent-session-custom-message-commit.d.ts +14 -0
  343. package/dist/core/agent-session-custom-message-commit.d.ts.map +1 -0
  344. package/dist/core/agent-session-custom-message-commit.js +141 -0
  345. package/dist/core/agent-session-custom-message-commit.js.map +1 -0
  346. package/dist/core/agent-session-delivery-forwarding.d.ts +9 -0
  347. package/dist/core/agent-session-delivery-forwarding.d.ts.map +1 -0
  348. package/dist/core/agent-session-delivery-forwarding.js +36 -0
  349. package/dist/core/agent-session-delivery-forwarding.js.map +1 -0
  350. package/dist/core/agent-session-events.d.ts +1 -1
  351. package/dist/core/agent-session-events.d.ts.map +1 -1
  352. package/dist/core/agent-session-events.js +45 -14
  353. package/dist/core/agent-session-events.js.map +1 -1
  354. package/dist/core/agent-session-extension-bindings.d.ts +2 -6
  355. package/dist/core/agent-session-extension-bindings.d.ts.map +1 -1
  356. package/dist/core/agent-session-extension-bindings.js +18 -11
  357. package/dist/core/agent-session-extension-bindings.js.map +1 -1
  358. package/dist/core/agent-session-message-queue.d.ts +5 -2
  359. package/dist/core/agent-session-message-queue.d.ts.map +1 -1
  360. package/dist/core/agent-session-message-queue.js +91 -97
  361. package/dist/core/agent-session-message-queue.js.map +1 -1
  362. package/dist/core/agent-session-methods.d.ts +47 -39
  363. package/dist/core/agent-session-methods.d.ts.map +1 -1
  364. package/dist/core/agent-session-methods.js.map +1 -1
  365. package/dist/core/agent-session-models.d.ts +2 -38
  366. package/dist/core/agent-session-models.d.ts.map +1 -1
  367. package/dist/core/agent-session-models.js +5 -147
  368. package/dist/core/agent-session-models.js.map +1 -1
  369. package/dist/core/agent-session-persistent-custom-messages.d.ts +47 -0
  370. package/dist/core/agent-session-persistent-custom-messages.d.ts.map +1 -0
  371. package/dist/core/agent-session-persistent-custom-messages.js +267 -0
  372. package/dist/core/agent-session-persistent-custom-messages.js.map +1 -0
  373. package/dist/core/agent-session-post-tool-compaction.d.ts.map +1 -1
  374. package/dist/core/agent-session-post-tool-compaction.js +34 -9
  375. package/dist/core/agent-session-post-tool-compaction.js.map +1 -1
  376. package/dist/core/agent-session-prompt.d.ts +2 -0
  377. package/dist/core/agent-session-prompt.d.ts.map +1 -1
  378. package/dist/core/agent-session-prompt.js +42 -16
  379. package/dist/core/agent-session-prompt.js.map +1 -1
  380. package/dist/core/agent-session-queue-pause.d.ts +10 -0
  381. package/dist/core/agent-session-queue-pause.d.ts.map +1 -0
  382. package/dist/core/agent-session-queue-pause.js +86 -0
  383. package/dist/core/agent-session-queue-pause.js.map +1 -0
  384. package/dist/core/agent-session-retry.d.ts +0 -11
  385. package/dist/core/agent-session-retry.d.ts.map +1 -1
  386. package/dist/core/agent-session-retry.js +8 -57
  387. package/dist/core/agent-session-retry.js.map +1 -1
  388. package/dist/core/agent-session-runtime-auth.d.ts +6 -0
  389. package/dist/core/agent-session-runtime-auth.d.ts.map +1 -0
  390. package/dist/core/agent-session-runtime-auth.js +26 -0
  391. package/dist/core/agent-session-runtime-auth.js.map +1 -0
  392. package/dist/core/agent-session-runtime.d.ts +13 -2
  393. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  394. package/dist/core/agent-session-runtime.js +32 -6
  395. package/dist/core/agent-session-runtime.js.map +1 -1
  396. package/dist/core/agent-session-services.d.ts +0 -2
  397. package/dist/core/agent-session-services.d.ts.map +1 -1
  398. package/dist/core/agent-session-services.js +6 -7
  399. package/dist/core/agent-session-services.js.map +1 -1
  400. package/dist/core/agent-session-state.d.ts.map +1 -1
  401. package/dist/core/agent-session-state.js +3 -0
  402. package/dist/core/agent-session-state.js.map +1 -1
  403. package/dist/core/agent-session-tool-hooks.d.ts.map +1 -1
  404. package/dist/core/agent-session-tool-hooks.js +6 -1
  405. package/dist/core/agent-session-tool-hooks.js.map +1 -1
  406. package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
  407. package/dist/core/agent-session-tool-registry.js +2 -18
  408. package/dist/core/agent-session-tool-registry.js.map +1 -1
  409. package/dist/core/agent-session-transfer.d.ts +4 -0
  410. package/dist/core/agent-session-transfer.d.ts.map +1 -0
  411. package/dist/core/agent-session-transfer.js +71 -0
  412. package/dist/core/agent-session-transfer.js.map +1 -0
  413. package/dist/core/agent-session-tree.js +1 -1
  414. package/dist/core/agent-session-tree.js.map +1 -1
  415. package/dist/core/agent-session-types.d.ts +5 -11
  416. package/dist/core/agent-session-types.d.ts.map +1 -1
  417. package/dist/core/agent-session-types.js +0 -3
  418. package/dist/core/agent-session-types.js.map +1 -1
  419. package/dist/core/agent-session.d.ts +12 -2
  420. package/dist/core/agent-session.d.ts.map +1 -1
  421. package/dist/core/agent-session.js +8 -2
  422. package/dist/core/agent-session.js.map +1 -1
  423. package/dist/core/atomic-guide-command.d.ts.map +1 -1
  424. package/dist/core/atomic-guide-command.js +31 -33
  425. package/dist/core/atomic-guide-command.js.map +1 -1
  426. package/dist/core/auth-storage.js +2 -2
  427. package/dist/core/auth-storage.js.map +1 -1
  428. package/dist/core/bash-executor.d.ts +5 -3
  429. package/dist/core/bash-executor.d.ts.map +1 -1
  430. package/dist/core/bash-executor.js +5 -4
  431. package/dist/core/bash-executor.js.map +1 -1
  432. package/dist/core/builtin-packages.d.ts.map +1 -1
  433. package/dist/core/builtin-packages.js +0 -6
  434. package/dist/core/builtin-packages.js.map +1 -1
  435. package/dist/core/compaction/branch-summarization.d.ts +8 -3
  436. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  437. package/dist/core/compaction/branch-summarization.js +17 -6
  438. package/dist/core/compaction/branch-summarization.js.map +1 -1
  439. package/dist/core/compaction/compaction-boundary.d.ts +18 -1
  440. package/dist/core/compaction/compaction-boundary.d.ts.map +1 -1
  441. package/dist/core/compaction/compaction-boundary.js +2 -2
  442. package/dist/core/compaction/compaction-boundary.js.map +1 -1
  443. package/dist/core/compaction/compaction-runner.d.ts +61 -6
  444. package/dist/core/compaction/compaction-runner.d.ts.map +1 -1
  445. package/dist/core/compaction/compaction-runner.js +242 -18
  446. package/dist/core/compaction/compaction-runner.js.map +1 -1
  447. package/dist/core/compaction/compaction-types.d.ts +53 -2
  448. package/dist/core/compaction/compaction-types.d.ts.map +1 -1
  449. package/dist/core/compaction/compaction-types.js.map +1 -1
  450. package/dist/core/compaction/fallback-planner.d.ts +64 -0
  451. package/dist/core/compaction/fallback-planner.d.ts.map +1 -0
  452. package/dist/core/compaction/fallback-planner.js +75 -0
  453. package/dist/core/compaction/fallback-planner.js.map +1 -0
  454. package/dist/core/compaction/index.d.ts +3 -0
  455. package/dist/core/compaction/index.d.ts.map +1 -1
  456. package/dist/core/compaction/index.js +3 -0
  457. package/dist/core/compaction/index.js.map +1 -1
  458. package/dist/core/compaction/planner-outcome.d.ts +86 -0
  459. package/dist/core/compaction/planner-outcome.d.ts.map +1 -0
  460. package/dist/core/compaction/planner-outcome.js +122 -0
  461. package/dist/core/compaction/planner-outcome.js.map +1 -0
  462. package/dist/core/compaction/range-planner-diagnostics.d.ts +58 -6
  463. package/dist/core/compaction/range-planner-diagnostics.d.ts.map +1 -1
  464. package/dist/core/compaction/range-planner-diagnostics.js +69 -31
  465. package/dist/core/compaction/range-planner-diagnostics.js.map +1 -1
  466. package/dist/core/compaction/range-planner.d.ts +36 -8
  467. package/dist/core/compaction/range-planner.d.ts.map +1 -1
  468. package/dist/core/compaction/range-planner.js +136 -51
  469. package/dist/core/compaction/range-planner.js.map +1 -1
  470. package/dist/core/compaction/region-trimming.d.ts +34 -0
  471. package/dist/core/compaction/region-trimming.d.ts.map +1 -0
  472. package/dist/core/compaction/region-trimming.js +73 -0
  473. package/dist/core/compaction/region-trimming.js.map +1 -0
  474. package/dist/core/compaction/transcript-serialization.d.ts +8 -1
  475. package/dist/core/compaction/transcript-serialization.d.ts.map +1 -1
  476. package/dist/core/compaction/transcript-serialization.js +78 -27
  477. package/dist/core/compaction/transcript-serialization.js.map +1 -1
  478. package/dist/core/context-tool-pairing.d.ts +19 -0
  479. package/dist/core/context-tool-pairing.d.ts.map +1 -0
  480. package/dist/core/context-tool-pairing.js +50 -0
  481. package/dist/core/context-tool-pairing.js.map +1 -0
  482. package/dist/core/diagnostics.d.ts +8 -0
  483. package/dist/core/diagnostics.d.ts.map +1 -1
  484. package/dist/core/diagnostics.js.map +1 -1
  485. package/dist/core/extensions/context-types.d.ts +3 -0
  486. package/dist/core/extensions/context-types.d.ts.map +1 -1
  487. package/dist/core/extensions/context-types.js.map +1 -1
  488. package/dist/core/extensions/index.d.ts +2 -0
  489. package/dist/core/extensions/index.d.ts.map +1 -1
  490. package/dist/core/extensions/index.js.map +1 -1
  491. package/dist/core/extensions/loader-api.d.ts.map +1 -1
  492. package/dist/core/extensions/loader-api.js +48 -27
  493. package/dist/core/extensions/loader-api.js.map +1 -1
  494. package/dist/core/extensions/loader-runtime.d.ts +2 -4
  495. package/dist/core/extensions/loader-runtime.d.ts.map +1 -1
  496. package/dist/core/extensions/loader-runtime.js +199 -18
  497. package/dist/core/extensions/loader-runtime.js.map +1 -1
  498. package/dist/core/extensions/message-types.d.ts +7 -4
  499. package/dist/core/extensions/message-types.d.ts.map +1 -1
  500. package/dist/core/extensions/message-types.js.map +1 -1
  501. package/dist/core/extensions/provider-types.d.ts +9 -4
  502. package/dist/core/extensions/provider-types.d.ts.map +1 -1
  503. package/dist/core/extensions/provider-types.js.map +1 -1
  504. package/dist/core/extensions/runner-context.d.ts +2 -0
  505. package/dist/core/extensions/runner-context.d.ts.map +1 -1
  506. package/dist/core/extensions/runner-context.js +4 -0
  507. package/dist/core/extensions/runner-context.js.map +1 -1
  508. package/dist/core/extensions/runner.d.ts +1 -0
  509. package/dist/core/extensions/runner.d.ts.map +1 -1
  510. package/dist/core/extensions/runner.js +28 -20
  511. package/dist/core/extensions/runner.js.map +1 -1
  512. package/dist/core/extensions/runtime-types.d.ts +25 -0
  513. package/dist/core/extensions/runtime-types.d.ts.map +1 -1
  514. package/dist/core/extensions/runtime-types.js.map +1 -1
  515. package/dist/core/extensions/tool-types.d.ts +7 -3
  516. package/dist/core/extensions/tool-types.d.ts.map +1 -1
  517. package/dist/core/extensions/tool-types.js.map +1 -1
  518. package/dist/core/extensions/ui-types.d.ts +14 -4
  519. package/dist/core/extensions/ui-types.d.ts.map +1 -1
  520. package/dist/core/extensions/ui-types.js.map +1 -1
  521. package/dist/core/fallback-models.d.ts +37 -0
  522. package/dist/core/fallback-models.d.ts.map +1 -0
  523. package/dist/core/fallback-models.js +48 -0
  524. package/dist/core/fallback-models.js.map +1 -0
  525. package/dist/core/flattened-tool-arguments.d.ts +4 -7
  526. package/dist/core/flattened-tool-arguments.d.ts.map +1 -1
  527. package/dist/core/flattened-tool-arguments.js +4 -7
  528. package/dist/core/flattened-tool-arguments.js.map +1 -1
  529. package/dist/core/http-dispatcher.d.ts.map +1 -1
  530. package/dist/core/http-dispatcher.js +0 -5
  531. package/dist/core/http-dispatcher.js.map +1 -1
  532. package/dist/core/messages.d.ts +14 -2
  533. package/dist/core/messages.d.ts.map +1 -1
  534. package/dist/core/messages.js +28 -4
  535. package/dist/core/messages.js.map +1 -1
  536. package/dist/core/model-capabilities.d.ts +18 -0
  537. package/dist/core/model-capabilities.d.ts.map +1 -0
  538. package/dist/core/model-capabilities.js +23 -0
  539. package/dist/core/model-capabilities.js.map +1 -0
  540. package/dist/core/model-registry-auth.d.ts.map +1 -1
  541. package/dist/core/model-registry-auth.js +0 -2
  542. package/dist/core/model-registry-auth.js.map +1 -1
  543. package/dist/core/model-registry-builtins.d.ts +0 -2
  544. package/dist/core/model-registry-builtins.d.ts.map +1 -1
  545. package/dist/core/model-registry-builtins.js +9 -76
  546. package/dist/core/model-registry-builtins.js.map +1 -1
  547. package/dist/core/model-registry-custom-loader.d.ts.map +1 -1
  548. package/dist/core/model-registry-custom-loader.js +1 -12
  549. package/dist/core/model-registry-custom-loader.js.map +1 -1
  550. package/dist/core/model-registry-dynamic.d.ts.map +1 -1
  551. package/dist/core/model-registry-dynamic.js +3 -15
  552. package/dist/core/model-registry-dynamic.js.map +1 -1
  553. package/dist/core/model-registry-extension-refresh.d.ts +23 -0
  554. package/dist/core/model-registry-extension-refresh.d.ts.map +1 -0
  555. package/dist/core/model-registry-extension-refresh.js +32 -0
  556. package/dist/core/model-registry-extension-refresh.js.map +1 -0
  557. package/dist/core/model-registry-schemas.d.ts +118 -9
  558. package/dist/core/model-registry-schemas.d.ts.map +1 -1
  559. package/dist/core/model-registry-schemas.js +10 -3
  560. package/dist/core/model-registry-schemas.js.map +1 -1
  561. package/dist/core/model-registry-types.d.ts +5 -5
  562. package/dist/core/model-registry-types.d.ts.map +1 -1
  563. package/dist/core/model-registry-types.js.map +1 -1
  564. package/dist/core/model-registry-validation.d.ts +7 -0
  565. package/dist/core/model-registry-validation.d.ts.map +1 -0
  566. package/dist/core/model-registry-validation.js +12 -0
  567. package/dist/core/model-registry-validation.js.map +1 -0
  568. package/dist/core/model-registry.d.ts +5 -3
  569. package/dist/core/model-registry.d.ts.map +1 -1
  570. package/dist/core/model-registry.js +34 -33
  571. package/dist/core/model-registry.js.map +1 -1
  572. package/dist/core/model-resolver-defaults.d.ts.map +1 -1
  573. package/dist/core/model-resolver-defaults.js +0 -1
  574. package/dist/core/model-resolver-defaults.js.map +1 -1
  575. package/dist/core/model-resolver-initial.d.ts.map +1 -1
  576. package/dist/core/model-resolver-initial.js +9 -0
  577. package/dist/core/model-resolver-initial.js.map +1 -1
  578. package/dist/core/model-resolver-patterns.d.ts.map +1 -1
  579. package/dist/core/model-resolver-patterns.js +0 -2
  580. package/dist/core/model-resolver-patterns.js.map +1 -1
  581. package/dist/core/model-resolver-scope.d.ts +2 -0
  582. package/dist/core/model-resolver-scope.d.ts.map +1 -1
  583. package/dist/core/model-resolver-scope.js +18 -4
  584. package/dist/core/model-resolver-scope.js.map +1 -1
  585. package/dist/core/model-resolver-types.d.ts +2 -0
  586. package/dist/core/model-resolver-types.d.ts.map +1 -1
  587. package/dist/core/model-resolver-types.js.map +1 -1
  588. package/dist/core/oauth-provider-bridge.d.ts +21 -0
  589. package/dist/core/oauth-provider-bridge.d.ts.map +1 -1
  590. package/dist/core/oauth-provider-bridge.js +68 -7
  591. package/dist/core/oauth-provider-bridge.js.map +1 -1
  592. package/dist/core/package-manager-auto-resources.d.ts.map +1 -1
  593. package/dist/core/package-manager-auto-resources.js +12 -4
  594. package/dist/core/package-manager-auto-resources.js.map +1 -1
  595. package/dist/core/package-manager-resolver.d.ts.map +1 -1
  596. package/dist/core/package-manager-resolver.js +42 -11
  597. package/dist/core/package-manager-resolver.js.map +1 -1
  598. package/dist/core/package-manager-types.d.ts +2 -0
  599. package/dist/core/package-manager-types.d.ts.map +1 -1
  600. package/dist/core/package-manager-types.js.map +1 -1
  601. package/dist/core/package-manager.d.ts +1 -1
  602. package/dist/core/package-manager.d.ts.map +1 -1
  603. package/dist/core/package-manager.js.map +1 -1
  604. package/dist/core/remote-catalog-provider.d.ts +1 -1
  605. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  606. package/dist/core/remote-catalog-provider.js +17 -11
  607. package/dist/core/remote-catalog-provider.js.map +1 -1
  608. package/dist/core/resource-loader-assets.d.ts.map +1 -1
  609. package/dist/core/resource-loader-assets.js +30 -4
  610. package/dist/core/resource-loader-assets.js.map +1 -1
  611. package/dist/core/resource-loader-context-files.d.ts.map +1 -1
  612. package/dist/core/resource-loader-context-files.js +3 -1
  613. package/dist/core/resource-loader-context-files.js.map +1 -1
  614. package/dist/core/resource-loader-core.d.ts +2 -1
  615. package/dist/core/resource-loader-core.d.ts.map +1 -1
  616. package/dist/core/resource-loader-core.js +3 -0
  617. package/dist/core/resource-loader-core.js.map +1 -1
  618. package/dist/core/resource-loader-extensions.d.ts +1 -0
  619. package/dist/core/resource-loader-extensions.d.ts.map +1 -1
  620. package/dist/core/resource-loader-extensions.js +120 -7
  621. package/dist/core/resource-loader-extensions.js.map +1 -1
  622. package/dist/core/resource-loader-package-resources.d.ts.map +1 -1
  623. package/dist/core/resource-loader-package-resources.js +14 -1
  624. package/dist/core/resource-loader-package-resources.js.map +1 -1
  625. package/dist/core/resource-loader-reload.d.ts.map +1 -1
  626. package/dist/core/resource-loader-reload.js +2 -1
  627. package/dist/core/resource-loader-reload.js.map +1 -1
  628. package/dist/core/resource-loader-source-info.d.ts.map +1 -1
  629. package/dist/core/resource-loader-source-info.js +6 -3
  630. package/dist/core/resource-loader-source-info.js.map +1 -1
  631. package/dist/core/sdk-types.d.ts +11 -10
  632. package/dist/core/sdk-types.d.ts.map +1 -1
  633. package/dist/core/sdk-types.js.map +1 -1
  634. package/dist/core/sdk.d.ts +1 -0
  635. package/dist/core/sdk.d.ts.map +1 -1
  636. package/dist/core/sdk.js +13 -84
  637. package/dist/core/sdk.js.map +1 -1
  638. package/dist/core/session-manager-core.d.ts +3 -3
  639. package/dist/core/session-manager-core.d.ts.map +1 -1
  640. package/dist/core/session-manager-core.js +18 -25
  641. package/dist/core/session-manager-core.js.map +1 -1
  642. package/dist/core/session-manager-entries.d.ts +2 -5
  643. package/dist/core/session-manager-entries.d.ts.map +1 -1
  644. package/dist/core/session-manager-entries.js +2 -8
  645. package/dist/core/session-manager-entries.js.map +1 -1
  646. package/dist/core/session-manager-history.d.ts +3 -3
  647. package/dist/core/session-manager-history.d.ts.map +1 -1
  648. package/dist/core/session-manager-history.js +49 -27
  649. package/dist/core/session-manager-history.js.map +1 -1
  650. package/dist/core/session-manager-storage.d.ts +6 -0
  651. package/dist/core/session-manager-storage.d.ts.map +1 -1
  652. package/dist/core/session-manager-storage.js +38 -5
  653. package/dist/core/session-manager-storage.js.map +1 -1
  654. package/dist/core/session-manager-types.d.ts +6 -6
  655. package/dist/core/session-manager-types.d.ts.map +1 -1
  656. package/dist/core/session-manager-types.js.map +1 -1
  657. package/dist/core/session-manager.d.ts +1 -1
  658. package/dist/core/session-manager.d.ts.map +1 -1
  659. package/dist/core/session-manager.js.map +1 -1
  660. package/dist/core/settings-manager-basic-accessors.d.ts +0 -4
  661. package/dist/core/settings-manager-basic-accessors.d.ts.map +1 -1
  662. package/dist/core/settings-manager-basic-accessors.js +0 -50
  663. package/dist/core/settings-manager-basic-accessors.js.map +1 -1
  664. package/dist/core/settings-manager-core.d.ts +2 -4
  665. package/dist/core/settings-manager-core.d.ts.map +1 -1
  666. package/dist/core/settings-manager-core.js +5 -51
  667. package/dist/core/settings-manager-core.js.map +1 -1
  668. package/dist/core/settings-manager.d.ts +1 -1
  669. package/dist/core/settings-manager.d.ts.map +1 -1
  670. package/dist/core/settings-manager.js.map +1 -1
  671. package/dist/core/settings-storage.d.ts +3 -1
  672. package/dist/core/settings-storage.d.ts.map +1 -1
  673. package/dist/core/settings-storage.js +22 -0
  674. package/dist/core/settings-storage.js.map +1 -1
  675. package/dist/core/settings-types.d.ts +2 -4
  676. package/dist/core/settings-types.d.ts.map +1 -1
  677. package/dist/core/settings-types.js.map +1 -1
  678. package/dist/core/slash-commands.d.ts.map +1 -1
  679. package/dist/core/slash-commands.js +68 -22
  680. package/dist/core/slash-commands.js.map +1 -1
  681. package/dist/core/source-info.d.ts +3 -1
  682. package/dist/core/source-info.d.ts.map +1 -1
  683. package/dist/core/source-info.js +2 -0
  684. package/dist/core/source-info.js.map +1 -1
  685. package/dist/core/tools/ask-user-question/ask-user-question.js +1 -1
  686. package/dist/core/tools/ask-user-question/ask-user-question.js.map +1 -1
  687. package/dist/core/tools/bash-session-environment.d.ts +13 -0
  688. package/dist/core/tools/bash-session-environment.d.ts.map +1 -0
  689. package/dist/core/tools/bash-session-environment.js +35 -0
  690. package/dist/core/tools/bash-session-environment.js.map +1 -0
  691. package/dist/core/tools/bash.d.ts +4 -1
  692. package/dist/core/tools/bash.d.ts.map +1 -1
  693. package/dist/core/tools/bash.js +16 -8
  694. package/dist/core/tools/bash.js.map +1 -1
  695. package/dist/core/tools/tool-definition-wrapper.d.ts +3 -0
  696. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  697. package/dist/core/tools/tool-definition-wrapper.js +10 -2
  698. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  699. package/dist/extensions/index.js +1 -1
  700. package/dist/extensions/index.js.map +1 -1
  701. package/dist/extensions/llama/provider.d.ts +3 -2
  702. package/dist/extensions/llama/provider.d.ts.map +1 -1
  703. package/dist/extensions/llama/provider.js +9 -3
  704. package/dist/extensions/llama/provider.js.map +1 -1
  705. package/dist/index-extensions.d.ts +1 -1
  706. package/dist/index-extensions.d.ts.map +1 -1
  707. package/dist/index-extensions.js.map +1 -1
  708. package/dist/index.d.ts +2 -3
  709. package/dist/index.d.ts.map +1 -1
  710. package/dist/index.js +1 -2
  711. package/dist/index.js.map +1 -1
  712. package/dist/main-session-options.d.ts.map +1 -1
  713. package/dist/main-session-options.js +0 -4
  714. package/dist/main-session-options.js.map +1 -1
  715. package/dist/main-session.d.ts.map +1 -1
  716. package/dist/main-session.js +2 -1
  717. package/dist/main-session.js.map +1 -1
  718. package/dist/main.d.ts.map +1 -1
  719. package/dist/main.js +1 -17
  720. package/dist/main.js.map +1 -1
  721. package/dist/modes/index.d.ts +1 -1
  722. package/dist/modes/index.d.ts.map +1 -1
  723. package/dist/modes/index.js.map +1 -1
  724. package/dist/modes/interactive/chat-input-actions.d.ts +1 -1
  725. package/dist/modes/interactive/chat-input-actions.d.ts.map +1 -1
  726. package/dist/modes/interactive/chat-input-actions.js +14 -96
  727. package/dist/modes/interactive/chat-input-actions.js.map +1 -1
  728. package/dist/modes/interactive/components/atomic-banner.d.ts +9 -8
  729. package/dist/modes/interactive/components/atomic-banner.d.ts.map +1 -1
  730. package/dist/modes/interactive/components/atomic-banner.js +68 -24
  731. package/dist/modes/interactive/components/atomic-banner.js.map +1 -1
  732. package/dist/modes/interactive/components/atomic-working-status.d.ts +52 -0
  733. package/dist/modes/interactive/components/atomic-working-status.d.ts.map +1 -0
  734. package/dist/modes/interactive/components/atomic-working-status.js +202 -0
  735. package/dist/modes/interactive/components/atomic-working-status.js.map +1 -0
  736. package/dist/modes/interactive/components/chat-message-renderer.js +1 -1
  737. package/dist/modes/interactive/components/chat-message-renderer.js.map +1 -1
  738. package/dist/modes/interactive/components/chat-session-host-actions.d.ts.map +1 -1
  739. package/dist/modes/interactive/components/chat-session-host-actions.js +87 -7
  740. package/dist/modes/interactive/components/chat-session-host-actions.js.map +1 -1
  741. package/dist/modes/interactive/components/chat-session-host-editor.js +3 -3
  742. package/dist/modes/interactive/components/chat-session-host-editor.js.map +1 -1
  743. package/dist/modes/interactive/components/chat-session-host-events.d.ts.map +1 -1
  744. package/dist/modes/interactive/components/chat-session-host-events.js +61 -9
  745. package/dist/modes/interactive/components/chat-session-host-events.js.map +1 -1
  746. package/dist/modes/interactive/components/chat-session-host-rendering.d.ts.map +1 -1
  747. package/dist/modes/interactive/components/chat-session-host-rendering.js +23 -7
  748. package/dist/modes/interactive/components/chat-session-host-rendering.js.map +1 -1
  749. package/dist/modes/interactive/components/chat-session-host-runtime.d.ts +27 -0
  750. package/dist/modes/interactive/components/chat-session-host-runtime.d.ts.map +1 -1
  751. package/dist/modes/interactive/components/chat-session-host-runtime.js +120 -18
  752. package/dist/modes/interactive/components/chat-session-host-runtime.js.map +1 -1
  753. package/dist/modes/interactive/components/chat-session-host-state.d.ts +9 -0
  754. package/dist/modes/interactive/components/chat-session-host-state.d.ts.map +1 -1
  755. package/dist/modes/interactive/components/chat-session-host-state.js +5 -0
  756. package/dist/modes/interactive/components/chat-session-host-state.js.map +1 -1
  757. package/dist/modes/interactive/components/chat-session-host-types.d.ts +10 -0
  758. package/dist/modes/interactive/components/chat-session-host-types.d.ts.map +1 -1
  759. package/dist/modes/interactive/components/chat-session-host-types.js.map +1 -1
  760. package/dist/modes/interactive/components/chat-session-host.d.ts +13 -0
  761. package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -1
  762. package/dist/modes/interactive/components/chat-session-host.js +22 -1
  763. package/dist/modes/interactive/components/chat-session-host.js.map +1 -1
  764. package/dist/modes/interactive/components/compaction-boundary-message.d.ts.map +1 -1
  765. package/dist/modes/interactive/components/compaction-boundary-message.js +2 -1
  766. package/dist/modes/interactive/components/compaction-boundary-message.js.map +1 -1
  767. package/dist/modes/interactive/components/custom-message.d.ts +3 -1
  768. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
  769. package/dist/modes/interactive/components/custom-message.js +9 -2
  770. package/dist/modes/interactive/components/custom-message.js.map +1 -1
  771. package/dist/modes/interactive/components/extension-editor.d.ts +3 -2
  772. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  773. package/dist/modes/interactive/components/extension-editor.js +14 -43
  774. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  775. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  776. package/dist/modes/interactive/components/scoped-models-selector.js +18 -13
  777. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  778. package/dist/modes/interactive/components/startup-identity.d.ts +22 -0
  779. package/dist/modes/interactive/components/startup-identity.d.ts.map +1 -0
  780. package/dist/modes/interactive/components/startup-identity.js +58 -0
  781. package/dist/modes/interactive/components/startup-identity.js.map +1 -0
  782. package/dist/modes/interactive/components/tree-selector-content.d.ts.map +1 -1
  783. package/dist/modes/interactive/components/tree-selector-content.js +0 -6
  784. package/dist/modes/interactive/components/tree-selector-content.js.map +1 -1
  785. package/dist/modes/interactive/components/tree-selector-model.d.ts.map +1 -1
  786. package/dist/modes/interactive/components/tree-selector-model.js +0 -1
  787. package/dist/modes/interactive/components/tree-selector-model.js.map +1 -1
  788. package/dist/modes/interactive/components/working-status.d.ts +5 -11
  789. package/dist/modes/interactive/components/working-status.d.ts.map +1 -1
  790. package/dist/modes/interactive/components/working-status.js +14 -15
  791. package/dist/modes/interactive/components/working-status.js.map +1 -1
  792. package/dist/modes/interactive/external-editor.d.ts +23 -0
  793. package/dist/modes/interactive/external-editor.d.ts.map +1 -0
  794. package/dist/modes/interactive/external-editor.js +120 -0
  795. package/dist/modes/interactive/external-editor.js.map +1 -0
  796. package/dist/modes/interactive/interactive-agent-events.js +33 -22
  797. package/dist/modes/interactive/interactive-agent-events.js.map +1 -1
  798. package/dist/modes/interactive/interactive-auth-login.js +16 -6
  799. package/dist/modes/interactive/interactive-auth-login.js.map +1 -1
  800. package/dist/modes/interactive/interactive-auth-routing.js +3 -0
  801. package/dist/modes/interactive/interactive-auth-routing.js.map +1 -1
  802. package/dist/modes/interactive/interactive-bash-compact.d.ts +2 -1
  803. package/dist/modes/interactive/interactive-bash-compact.d.ts.map +1 -1
  804. package/dist/modes/interactive/interactive-bash-compact.js +8 -0
  805. package/dist/modes/interactive/interactive-bash-compact.js.map +1 -1
  806. package/dist/modes/interactive/interactive-deferred-startup.d.ts.map +1 -1
  807. package/dist/modes/interactive/interactive-deferred-startup.js +49 -19
  808. package/dist/modes/interactive/interactive-deferred-startup.js.map +1 -1
  809. package/dist/modes/interactive/interactive-editor-actions.js +4 -3
  810. package/dist/modes/interactive/interactive-editor-actions.js.map +1 -1
  811. package/dist/modes/interactive/interactive-extension-dialogs.js +1 -1
  812. package/dist/modes/interactive/interactive-extension-dialogs.js.map +1 -1
  813. package/dist/modes/interactive/interactive-extension-runtime.js +3 -2
  814. package/dist/modes/interactive/interactive-extension-runtime.js.map +1 -1
  815. package/dist/modes/interactive/interactive-initial-session-binding.d.ts +4 -0
  816. package/dist/modes/interactive/interactive-initial-session-binding.d.ts.map +1 -0
  817. package/dist/modes/interactive/interactive-initial-session-binding.js +23 -0
  818. package/dist/modes/interactive/interactive-initial-session-binding.js.map +1 -0
  819. package/dist/modes/interactive/interactive-input-handling.d.ts +2 -1
  820. package/dist/modes/interactive/interactive-input-handling.d.ts.map +1 -1
  821. package/dist/modes/interactive/interactive-input-handling.js +27 -51
  822. package/dist/modes/interactive/interactive-input-handling.js.map +1 -1
  823. package/dist/modes/interactive/interactive-mode-base.d.ts +11 -7
  824. package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -1
  825. package/dist/modes/interactive/interactive-mode-base.js +14 -6
  826. package/dist/modes/interactive/interactive-mode-base.js.map +1 -1
  827. package/dist/modes/interactive/interactive-mode-deps.d.ts +2 -4
  828. package/dist/modes/interactive/interactive-mode-deps.d.ts.map +1 -1
  829. package/dist/modes/interactive/interactive-mode-deps.js +2 -4
  830. package/dist/modes/interactive/interactive-mode-deps.js.map +1 -1
  831. package/dist/modes/interactive/interactive-mode-surface.d.ts +9 -8
  832. package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
  833. package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
  834. package/dist/modes/interactive/interactive-mode.d.ts +1 -0
  835. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  836. package/dist/modes/interactive/interactive-mode.js +1 -0
  837. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  838. package/dist/modes/interactive/interactive-model-catalog-startup.d.ts +2 -3
  839. package/dist/modes/interactive/interactive-model-catalog-startup.d.ts.map +1 -1
  840. package/dist/modes/interactive/interactive-model-catalog-startup.js +3 -6
  841. package/dist/modes/interactive/interactive-model-catalog-startup.js.map +1 -1
  842. package/dist/modes/interactive/interactive-model-routing.js +26 -97
  843. package/dist/modes/interactive/interactive-model-routing.js.map +1 -1
  844. package/dist/modes/interactive/interactive-pause.d.ts +4 -0
  845. package/dist/modes/interactive/interactive-pause.d.ts.map +1 -0
  846. package/dist/modes/interactive/interactive-pause.js +8 -0
  847. package/dist/modes/interactive/interactive-pause.js.map +1 -0
  848. package/dist/modes/interactive/interactive-process-lifecycle.js +5 -4
  849. package/dist/modes/interactive/interactive-process-lifecycle.js.map +1 -1
  850. package/dist/modes/interactive/interactive-prompt-turn.d.ts +2 -0
  851. package/dist/modes/interactive/interactive-prompt-turn.d.ts.map +1 -0
  852. package/dist/modes/interactive/interactive-prompt-turn.js +41 -0
  853. package/dist/modes/interactive/interactive-prompt-turn.js.map +1 -0
  854. package/dist/modes/interactive/interactive-render-chat.js +20 -8
  855. package/dist/modes/interactive/interactive-render-chat.js.map +1 -1
  856. package/dist/modes/interactive/interactive-resource-paths.js +11 -2
  857. package/dist/modes/interactive/interactive-resource-paths.js.map +1 -1
  858. package/dist/modes/interactive/interactive-resource-rendering.js +99 -0
  859. package/dist/modes/interactive/interactive-resource-rendering.js.map +1 -1
  860. package/dist/modes/interactive/interactive-session-runtime.js +1 -1
  861. package/dist/modes/interactive/interactive-session-runtime.js.map +1 -1
  862. package/dist/modes/interactive/interactive-slash-commands.js +1 -1
  863. package/dist/modes/interactive/interactive-slash-commands.js.map +1 -1
  864. package/dist/modes/interactive/interactive-startup-chat-container.d.ts +20 -0
  865. package/dist/modes/interactive/interactive-startup-chat-container.d.ts.map +1 -0
  866. package/dist/modes/interactive/interactive-startup-chat-container.js +26 -0
  867. package/dist/modes/interactive/interactive-startup-chat-container.js.map +1 -0
  868. package/dist/modes/interactive/interactive-startup.d.ts +1 -1
  869. package/dist/modes/interactive/interactive-startup.d.ts.map +1 -1
  870. package/dist/modes/interactive/interactive-startup.js +30 -25
  871. package/dist/modes/interactive/interactive-startup.js.map +1 -1
  872. package/dist/modes/interactive/interactive-summarization-retry-events.d.ts.map +1 -1
  873. package/dist/modes/interactive/interactive-summarization-retry-events.js +9 -3
  874. package/dist/modes/interactive/interactive-summarization-retry-events.js.map +1 -1
  875. package/dist/modes/interactive/theme/catppuccin-frappe.json +1 -1
  876. package/dist/modes/interactive/theme/catppuccin-latte.json +1 -1
  877. package/dist/modes/interactive/theme/catppuccin-macchiato.json +1 -1
  878. package/dist/modes/interactive/theme/catppuccin-mocha.json +9 -1
  879. package/dist/modes/interactive/theme/dark.json +1 -1
  880. package/dist/modes/interactive/theme/light.json +1 -1
  881. package/dist/modes/interactive/theme/theme-class.d.ts +4 -0
  882. package/dist/modes/interactive/theme/theme-class.d.ts.map +1 -1
  883. package/dist/modes/interactive/theme/theme-class.js +7 -0
  884. package/dist/modes/interactive/theme/theme-class.js.map +1 -1
  885. package/dist/modes/interactive/theme/theme-loading.d.ts.map +1 -1
  886. package/dist/modes/interactive/theme/theme-loading.js +4 -0
  887. package/dist/modes/interactive/theme/theme-loading.js.map +1 -1
  888. package/dist/modes/interactive/theme/theme-schema.d.ts +32 -0
  889. package/dist/modes/interactive/theme/theme-schema.d.ts.map +1 -1
  890. package/dist/modes/interactive/theme/theme-schema.js +8 -0
  891. package/dist/modes/interactive/theme/theme-schema.js.map +1 -1
  892. package/dist/modes/interactive/theme/theme-schema.json +15 -2
  893. package/dist/modes/interactive/whimsical-messages.d.ts +1 -0
  894. package/dist/modes/interactive/whimsical-messages.d.ts.map +1 -1
  895. package/dist/modes/interactive/whimsical-messages.js +2 -2
  896. package/dist/modes/interactive/whimsical-messages.js.map +1 -1
  897. package/dist/modes/interactive-engine/create-isolated-runtime.d.ts.map +1 -1
  898. package/dist/modes/interactive-engine/create-isolated-runtime.js +3 -1
  899. package/dist/modes/interactive-engine/create-isolated-runtime.js.map +1 -1
  900. package/dist/modes/interactive-engine/engine-args.d.ts.map +1 -1
  901. package/dist/modes/interactive-engine/engine-args.js +0 -1
  902. package/dist/modes/interactive-engine/engine-args.js.map +1 -1
  903. package/dist/modes/interactive-engine/engine-custom-ui.d.ts.map +1 -1
  904. package/dist/modes/interactive-engine/engine-custom-ui.js +5 -17
  905. package/dist/modes/interactive-engine/engine-custom-ui.js.map +1 -1
  906. package/dist/modes/interactive-engine/engine-render-service.d.ts.map +1 -1
  907. package/dist/modes/interactive-engine/engine-render-service.js +8 -19
  908. package/dist/modes/interactive-engine/engine-render-service.js.map +1 -1
  909. package/dist/modes/interactive-engine/extension-ui-bridge.d.ts +2 -0
  910. package/dist/modes/interactive-engine/extension-ui-bridge.d.ts.map +1 -1
  911. package/dist/modes/interactive-engine/extension-ui-bridge.js +3 -0
  912. package/dist/modes/interactive-engine/extension-ui-bridge.js.map +1 -1
  913. package/dist/modes/interactive-engine/isolated-auth.d.ts +10 -0
  914. package/dist/modes/interactive-engine/isolated-auth.d.ts.map +1 -0
  915. package/dist/modes/interactive-engine/isolated-auth.js +14 -0
  916. package/dist/modes/interactive-engine/isolated-auth.js.map +1 -0
  917. package/dist/modes/interactive-engine/isolated-runtime.d.ts +9 -1
  918. package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
  919. package/dist/modes/interactive-engine/isolated-runtime.js +46 -34
  920. package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
  921. package/dist/modes/interactive-engine/protocol.d.ts +1 -1
  922. package/dist/modes/interactive-engine/protocol.d.ts.map +1 -1
  923. package/dist/modes/interactive-engine/protocol.js +3 -10
  924. package/dist/modes/interactive-engine/protocol.js.map +1 -1
  925. package/dist/modes/interactive-engine/remote-model-catalog.d.ts +1 -0
  926. package/dist/modes/interactive-engine/remote-model-catalog.d.ts.map +1 -1
  927. package/dist/modes/interactive-engine/remote-model-catalog.js +10 -1
  928. package/dist/modes/interactive-engine/remote-model-catalog.js.map +1 -1
  929. package/dist/modes/interactive-engine/remote-queue-pause.d.ts +13 -0
  930. package/dist/modes/interactive-engine/remote-queue-pause.d.ts.map +1 -0
  931. package/dist/modes/interactive-engine/remote-queue-pause.js +38 -0
  932. package/dist/modes/interactive-engine/remote-queue-pause.js.map +1 -0
  933. package/dist/modes/interactive-engine/remote-renderer.d.ts +3 -1
  934. package/dist/modes/interactive-engine/remote-renderer.d.ts.map +1 -1
  935. package/dist/modes/interactive-engine/remote-renderer.js +4 -1
  936. package/dist/modes/interactive-engine/remote-renderer.js.map +1 -1
  937. package/dist/modes/print-mode.d.ts.map +1 -1
  938. package/dist/modes/print-mode.js +5 -0
  939. package/dist/modes/print-mode.js.map +1 -1
  940. package/dist/modes/rpc/jsonl.d.ts +2 -7
  941. package/dist/modes/rpc/jsonl.d.ts.map +1 -1
  942. package/dist/modes/rpc/jsonl.js +7 -24
  943. package/dist/modes/rpc/jsonl.js.map +1 -1
  944. package/dist/modes/rpc/queued-writer.d.ts +19 -0
  945. package/dist/modes/rpc/queued-writer.d.ts.map +1 -0
  946. package/dist/modes/rpc/{bounded-writer.js → queued-writer.js} +7 -30
  947. package/dist/modes/rpc/queued-writer.js.map +1 -0
  948. package/dist/modes/rpc/rpc-bash-request-owners.d.ts +24 -0
  949. package/dist/modes/rpc/rpc-bash-request-owners.d.ts.map +1 -0
  950. package/dist/modes/rpc/rpc-bash-request-owners.js +45 -0
  951. package/dist/modes/rpc/rpc-bash-request-owners.js.map +1 -0
  952. package/dist/modes/rpc/rpc-client-api.d.ts +8 -5
  953. package/dist/modes/rpc/rpc-client-api.d.ts.map +1 -1
  954. package/dist/modes/rpc/rpc-client-api.js +10 -11
  955. package/dist/modes/rpc/rpc-client-api.js.map +1 -1
  956. package/dist/modes/rpc/rpc-client-process.d.ts +1 -4
  957. package/dist/modes/rpc/rpc-client-process.d.ts.map +1 -1
  958. package/dist/modes/rpc/rpc-client-process.js +2 -14
  959. package/dist/modes/rpc/rpc-client-process.js.map +1 -1
  960. package/dist/modes/rpc/rpc-client.d.ts +8 -4
  961. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  962. package/dist/modes/rpc/rpc-client.js +21 -30
  963. package/dist/modes/rpc/rpc-client.js.map +1 -1
  964. package/dist/modes/rpc/rpc-command-handler.d.ts +7 -4
  965. package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
  966. package/dist/modes/rpc/rpc-command-handler.js +76 -93
  967. package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
  968. package/dist/modes/rpc/rpc-input-scheduler.d.ts +3 -3
  969. package/dist/modes/rpc/rpc-input-scheduler.d.ts.map +1 -1
  970. package/dist/modes/rpc/rpc-input-scheduler.js +7 -4
  971. package/dist/modes/rpc/rpc-input-scheduler.js.map +1 -1
  972. package/dist/modes/rpc/rpc-mode.d.ts +1 -1
  973. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  974. package/dist/modes/rpc/rpc-mode.js +5 -5
  975. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  976. package/dist/modes/rpc/rpc-model-fallback-prompt.d.ts +4 -0
  977. package/dist/modes/rpc/rpc-model-fallback-prompt.d.ts.map +1 -0
  978. package/dist/modes/rpc/rpc-model-fallback-prompt.js +11 -0
  979. package/dist/modes/rpc/rpc-model-fallback-prompt.js.map +1 -0
  980. package/dist/modes/rpc/rpc-oauth-client.d.ts +22 -0
  981. package/dist/modes/rpc/rpc-oauth-client.d.ts.map +1 -0
  982. package/dist/modes/rpc/rpc-oauth-client.js +74 -0
  983. package/dist/modes/rpc/rpc-oauth-client.js.map +1 -0
  984. package/dist/modes/rpc/rpc-oauth-interaction.d.ts +9 -0
  985. package/dist/modes/rpc/rpc-oauth-interaction.d.ts.map +1 -0
  986. package/dist/modes/rpc/rpc-oauth-interaction.js +49 -0
  987. package/dist/modes/rpc/rpc-oauth-interaction.js.map +1 -0
  988. package/dist/modes/rpc/rpc-output-buffer.d.ts +2 -1
  989. package/dist/modes/rpc/rpc-output-buffer.d.ts.map +1 -1
  990. package/dist/modes/rpc/rpc-output-buffer.js +4 -39
  991. package/dist/modes/rpc/rpc-output-buffer.js.map +1 -1
  992. package/dist/modes/rpc/rpc-provider-auth.d.ts +23 -0
  993. package/dist/modes/rpc/rpc-provider-auth.d.ts.map +1 -0
  994. package/dist/modes/rpc/rpc-provider-auth.js +145 -0
  995. package/dist/modes/rpc/rpc-provider-auth.js.map +1 -0
  996. package/dist/modes/rpc/rpc-responses.d.ts +0 -1
  997. package/dist/modes/rpc/rpc-responses.d.ts.map +1 -1
  998. package/dist/modes/rpc/rpc-responses.js +0 -14
  999. package/dist/modes/rpc/rpc-responses.js.map +1 -1
  1000. package/dist/modes/rpc/rpc-types.d.ts +83 -27
  1001. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  1002. package/dist/modes/rpc/rpc-types.js.map +1 -1
  1003. package/dist/utils/clipboard.d.ts.map +1 -1
  1004. package/dist/utils/clipboard.js +21 -8
  1005. package/dist/utils/clipboard.js.map +1 -1
  1006. package/dist/utils/version-check.d.ts.map +1 -1
  1007. package/dist/utils/version-check.js +3 -1
  1008. package/dist/utils/version-check.js.map +1 -1
  1009. package/docs/changelog.mdx +12 -1
  1010. package/docs/compaction.md +101 -18
  1011. package/docs/custom-provider.md +13 -4
  1012. package/docs/docs.json +1 -0
  1013. package/docs/environment-variables.md +37 -0
  1014. package/docs/extensions.md +45 -9
  1015. package/docs/index.md +1 -0
  1016. package/docs/intercom.md +1 -1
  1017. package/docs/json.md +4 -4
  1018. package/docs/keybindings.md +4 -2
  1019. package/docs/llama-cpp.md +3 -1
  1020. package/docs/models.md +29 -43
  1021. package/docs/providers.md +18 -24
  1022. package/docs/quickstart.md +19 -16
  1023. package/docs/rpc.md +38 -85
  1024. package/docs/sdk.md +15 -22
  1025. package/docs/session-format.md +2 -15
  1026. package/docs/sessions.md +1 -1
  1027. package/docs/settings.md +10 -15
  1028. package/docs/skills.md +8 -0
  1029. package/docs/subagents.md +17 -9
  1030. package/docs/themes.md +10 -1
  1031. package/docs/tui.md +10 -5
  1032. package/docs/usage.md +21 -2
  1033. package/docs/windows.md +1 -1
  1034. package/docs/workflows.md +1096 -518
  1035. package/examples/extensions/README.md +1 -1
  1036. package/examples/extensions/handoff.ts +8 -1
  1037. package/examples/extensions/message-renderer.ts +2 -2
  1038. package/examples/extensions/summarize.ts +3 -0
  1039. package/examples/extensions/working-indicator.ts +2 -2
  1040. package/npm-shrinkwrap.json +40 -46
  1041. package/package.json +9 -7
  1042. package/dist/builtin/cursor/CHANGELOG.md +0 -281
  1043. package/dist/builtin/cursor/LICENSE +0 -26
  1044. package/dist/builtin/cursor/README.md +0 -24
  1045. package/dist/builtin/cursor/index.ts +0 -9
  1046. package/dist/builtin/cursor/package.json +0 -47
  1047. package/dist/builtin/cursor/src/auth.ts +0 -352
  1048. package/dist/builtin/cursor/src/catalog-cache.ts +0 -155
  1049. package/dist/builtin/cursor/src/config.ts +0 -123
  1050. package/dist/builtin/cursor/src/conversation-state.ts +0 -135
  1051. package/dist/builtin/cursor/src/cursor-models-raw.json +0 -412
  1052. package/dist/builtin/cursor/src/model-mapper.ts +0 -369
  1053. package/dist/builtin/cursor/src/model-reference.ts +0 -282
  1054. package/dist/builtin/cursor/src/models.ts +0 -54
  1055. package/dist/builtin/cursor/src/native-loader.ts +0 -71
  1056. package/dist/builtin/cursor/src/proto/README.md +0 -34
  1057. package/dist/builtin/cursor/src/proto/agent_pb.ts +0 -15294
  1058. package/dist/builtin/cursor/src/proto/protobuf-codec-base64.ts +0 -22
  1059. package/dist/builtin/cursor/src/proto/protobuf-codec-json.ts +0 -44
  1060. package/dist/builtin/cursor/src/proto/protobuf-codec-request.ts +0 -311
  1061. package/dist/builtin/cursor/src/proto/protobuf-codec-wire.ts +0 -248
  1062. package/dist/builtin/cursor/src/proto/protobuf-codec.ts +0 -200
  1063. package/dist/builtin/cursor/src/provider.ts +0 -301
  1064. package/dist/builtin/cursor/src/stream.ts +0 -494
  1065. package/dist/builtin/cursor/src/transport-errors.ts +0 -74
  1066. package/dist/builtin/cursor/src/transport-frame.ts +0 -56
  1067. package/dist/builtin/cursor/src/transport-http2.ts +0 -122
  1068. package/dist/builtin/cursor/src/transport-native-client.ts +0 -161
  1069. package/dist/builtin/cursor/src/transport-run-stream.ts +0 -188
  1070. package/dist/builtin/cursor/src/transport-timeouts.ts +0 -87
  1071. package/dist/builtin/cursor/src/transport-types.ts +0 -143
  1072. package/dist/builtin/cursor/src/transport.ts +0 -26
  1073. package/dist/builtin/workflows/builtin/deep-research-codebase-runner.ts +0 -492
  1074. package/dist/builtin/workflows/builtin/deep-research-codebase-utils.ts +0 -383
  1075. package/dist/builtin/workflows/builtin/deep-research-codebase.d.ts +0 -35
  1076. package/dist/builtin/workflows/builtin/deep-research-codebase.ts +0 -47
  1077. package/dist/builtin/workflows/skills/impeccable/reference/brand.md +0 -108
  1078. package/dist/builtin/workflows/skills/impeccable/reference/codex.md +0 -105
  1079. package/dist/builtin/workflows/skills/impeccable/reference/interaction-design.md +0 -189
  1080. package/dist/builtin/workflows/skills/impeccable/scripts/hook-before-edit.mjs +0 -516
  1081. package/dist/core/context-window.d.ts +0 -54
  1082. package/dist/core/context-window.d.ts.map +0 -1
  1083. package/dist/core/context-window.js +0 -110
  1084. package/dist/core/context-window.js.map +0 -1
  1085. package/dist/core/copilot-anthropic-sse-repair.d.ts +0 -23
  1086. package/dist/core/copilot-anthropic-sse-repair.d.ts.map +0 -1
  1087. package/dist/core/copilot-anthropic-sse-repair.js +0 -340
  1088. package/dist/core/copilot-anthropic-sse-repair.js.map +0 -1
  1089. package/dist/core/copilot-errors.d.ts +0 -9
  1090. package/dist/core/copilot-errors.d.ts.map +0 -1
  1091. package/dist/core/copilot-errors.js +0 -32
  1092. package/dist/core/copilot-errors.js.map +0 -1
  1093. package/dist/core/copilot-gemini-payload-sanitizer.d.ts +0 -72
  1094. package/dist/core/copilot-gemini-payload-sanitizer.d.ts.map +0 -1
  1095. package/dist/core/copilot-gemini-payload-sanitizer.js +0 -296
  1096. package/dist/core/copilot-gemini-payload-sanitizer.js.map +0 -1
  1097. package/dist/core/copilot-gemini-reasoning.d.ts +0 -126
  1098. package/dist/core/copilot-gemini-reasoning.d.ts.map +0 -1
  1099. package/dist/core/copilot-gemini-reasoning.js +0 -265
  1100. package/dist/core/copilot-gemini-reasoning.js.map +0 -1
  1101. package/dist/core/copilot-gemini-tool-arguments.d.ts +0 -42
  1102. package/dist/core/copilot-gemini-tool-arguments.d.ts.map +0 -1
  1103. package/dist/core/copilot-gemini-tool-arguments.js +0 -159
  1104. package/dist/core/copilot-gemini-tool-arguments.js.map +0 -1
  1105. package/dist/core/copilot-hosts.d.ts +0 -12
  1106. package/dist/core/copilot-hosts.d.ts.map +0 -1
  1107. package/dist/core/copilot-hosts.js +0 -33
  1108. package/dist/core/copilot-hosts.js.map +0 -1
  1109. package/dist/core/copilot-model-catalog.d.ts +0 -114
  1110. package/dist/core/copilot-model-catalog.d.ts.map +0 -1
  1111. package/dist/core/copilot-model-catalog.js +0 -392
  1112. package/dist/core/copilot-model-catalog.js.map +0 -1
  1113. package/dist/core/copilot-model-static-fallbacks.d.ts +0 -43
  1114. package/dist/core/copilot-model-static-fallbacks.d.ts.map +0 -1
  1115. package/dist/core/copilot-model-static-fallbacks.js +0 -50
  1116. package/dist/core/copilot-model-static-fallbacks.js.map +0 -1
  1117. package/dist/core/copilot-model-synthesis.d.ts +0 -10
  1118. package/dist/core/copilot-model-synthesis.d.ts.map +0 -1
  1119. package/dist/core/copilot-model-synthesis.js +0 -91
  1120. package/dist/core/copilot-model-synthesis.js.map +0 -1
  1121. package/dist/modes/interactive/components/context-window-selector.d.ts +0 -53
  1122. package/dist/modes/interactive/components/context-window-selector.d.ts.map +0 -1
  1123. package/dist/modes/interactive/components/context-window-selector.js +0 -136
  1124. package/dist/modes/interactive/components/context-window-selector.js.map +0 -1
  1125. package/dist/modes/rpc/bounded-writer.d.ts +0 -27
  1126. package/dist/modes/rpc/bounded-writer.d.ts.map +0 -1
  1127. package/dist/modes/rpc/bounded-writer.js.map +0 -1
@@ -1,34 +1,258 @@
1
1
  import { getKeptTailTokenEstimate } from "./compaction-boundary.js";
2
2
  import { reconstructCompactedTranscript, validateDeletedRanges } from "./deleted-ranges.js";
3
- import { planDeletedLineRanges } from "./range-planner.js";
4
- /** Calculate the single global line threshold directly from the prepared setting. */
3
+ import { createFallbackPlannerBorrower, plannerAttemptKey, } from "./fallback-planner.js";
4
+ import { MALFORMED_OUTPUT_MESSAGE, NO_USABLE_RANGES_MESSAGE, planDeletedLineRanges, RangePlanError, resolvePlannerRequest, } from "./range-planner.js";
5
+ import { writeSuccessDiagnosticSidecar } from "./range-planner-diagnostics.js";
6
+ import { nextTrimOffset, rebaseTrimmedRanges, trimRegionHead } from "./region-trimming.js";
7
+ import { MIN_COMPACTABLE_REGION_LINES } from "./compaction-types.js";
8
+ /**
9
+ * Calculate the single global line threshold from the prepared setting.
10
+ *
11
+ * This is the untrimmed target. Overflow trimming does NOT reuse it:
12
+ * `planWithTrimming` recomputes the threshold against each trimmed view, so the
13
+ * planner is always asked to keep a proportion of the lines it actually
14
+ * received rather than a proportion of a region it never saw.
15
+ *
16
+ * Retained as an exported helper for tests and consumers that need the
17
+ * pre-trim target; production planning goes through `planWithTrimming`.
18
+ */
5
19
  export function targetKeepLines(preparation) {
6
- const protectedLines = preparation.region.protectedLineNumbers?.size ?? 0;
7
- return Math.max(protectedLines, Math.round(preparation.region.lines.length * preparation.parameters.compression_ratio));
20
+ const region = preparation.region;
21
+ return Math.max(region.protectedLineNumbers?.size ?? 0, Math.round(region.lines.length * preparation.parameters.compression_ratio));
8
22
  }
9
- function withWholeContextStats(result, preparation) {
10
- const tokensAfter = result.stats.tokensAfter + getKeptTailTokenEstimate(preparation);
23
+ function hardInputLimitFor(model) {
24
+ return model.contextWindow > 0 ? model.contextWindow : Number.POSITIVE_INFINITY;
25
+ }
26
+ function withWholeContextStats(result, preparation, keptTail) {
27
+ const tokensAfter = result.stats.tokensAfter + (keptTail ? getKeptTailTokenEstimate(preparation) : 0);
11
28
  const percentReduction = preparation.tokensBefore === 0
12
29
  ? 0
13
30
  : Math.round((1 - tokensAfter / preparation.tokensBefore) * 1000) / 10;
14
31
  return {
15
32
  ...result,
16
- rung: "planned",
17
33
  stats: { ...result.stats, tokensBefore: preparation.tokensBefore, tokensAfter, percentReduction },
18
34
  };
19
35
  }
20
- /** Execute one whole-region model plan and mechanically accept its safe deletions. */
21
- export async function runVerbatimCompaction(preparation, model, apiKey, headers, signal, thinkingLevel, options) {
22
- if (signal?.aborted)
23
- throw new Error("Compaction cancelled");
24
- const raw = await planDeletedLineRanges(preparation.region, preparation.parameters, model, { apiKey, headers }, signal, thinkingLevel, preparation.settings.reserveTokens, targetKeepLines(preparation), {
25
- streamFn: options.streamFn,
26
- sessionFilePath: options.sessionFilePath,
27
- retry: options.retry,
28
- callbacks: options.callbacks,
29
- });
36
+ /**
37
+ * Build a fresh context window and the tail decision that goes with it.
38
+ *
39
+ * Private on purpose: `keptTail` is runner bookkeeping that persistence needs in
40
+ * order to write `firstKeptEntryId: null` when the protected tail is dropped. It
41
+ * is deliberately absent from the public door's return value, which is exactly a
42
+ * `CompactedTranscript`.
43
+ */
44
+ function buildFreshTranscript(preparation) {
45
+ const region = preparation.region;
46
+ const whole = region.lines.length > 0 ? [{ start: 1, end: region.lines.length }] : [];
47
+ return reconstructCompactedTranscript(region, validateDeletedRanges(whole, region));
48
+ }
49
+ function buildFreshContextWindow(preparation, hardInputLimit) {
50
+ const limit = Number.isFinite(hardInputLimit) && hardInputLimit > 0 ? hardInputLimit : Number.POSITIVE_INFINITY;
51
+ // The rule is "tail under the limit ⇒ tail kept", so the comparison is the
52
+ // tail alone. Explicit protected lines are a hard floor that survives either
53
+ // way, and counting the reconstructed protected/marker text here would drop a
54
+ // tail that fits. A rebuilt context that still cannot be sent is the post-tool
55
+ // gate's problem, not a reason for this rung to discard more.
56
+ return { transcript: buildFreshTranscript(preparation), keptTail: getKeptTailTokenEstimate(preparation) <= limit };
57
+ }
58
+ /**
59
+ * Discard every compactable line and start a fresh context window.
60
+ *
61
+ * TOTAL. No provider, no credentials, no network, no signal, no failure mode,
62
+ * no `Promise`. Port of codex `compact_token_budget` →
63
+ * `Session::start_new_context_window`. Atomic's system prompt, context files,
64
+ * and skills are rebuilt per request and were never in the transcript, so they
65
+ * survive automatically.
66
+ *
67
+ * The whole region is emitted as one deletion range and handed to the unchanged
68
+ * `validateDeletedRanges` → `reconstructCompactedTranscript` path, which splits
69
+ * around protected spans and folds prior markers.
70
+ *
71
+ * Returns exactly a `CompactedTranscript` — `text`, `ranges`, `stats` and
72
+ * nothing else. Whether the `preserve_recent` tail survives is a persistence
73
+ * concern and travels on `CompactionRungResult.keptTail`, not on this door.
74
+ */
75
+ export function startNewContextWindow(preparation) {
76
+ return buildFreshTranscript(preparation);
77
+ }
78
+ function plannedResult(preparation, ranges, plannerModel) {
79
+ const reconstructed = reconstructCompactedTranscript(preparation.region, validateDeletedRanges(ranges, preparation.region));
80
+ return {
81
+ ...withWholeContextStats(reconstructed, preparation, true),
82
+ rung: "planned",
83
+ ...(plannerModel ? { plannerModel } : {}),
84
+ keptTail: true,
85
+ };
86
+ }
87
+ function borrowedIdentity(planner) {
88
+ return {
89
+ provider: planner.model.provider,
90
+ id: planner.model.id,
91
+ ...(planner.budget.reasoning ? { thinkingLevel: planner.budget.reasoning } : {}),
92
+ };
93
+ }
94
+ function terminalError(outcome) {
95
+ if (!outcome)
96
+ return new RangePlanError(MALFORMED_OUTPUT_MESSAGE, 1, "", false);
97
+ if (outcome.kind === "rateLimited") {
98
+ return new RangePlanError(outcome.message, 1, "", false, outcome.diagnosticPath, outcome);
99
+ }
100
+ if (outcome.kind === "overflowed") {
101
+ return new RangePlanError("Compaction range planning exceeded the model context window", 1, "", true, outcome.diagnosticPath, outcome);
102
+ }
103
+ if (outcome.kind === "providerError") {
104
+ return new RangePlanError(outcome.message, 1, "", false, outcome.diagnosticPath, outcome);
105
+ }
106
+ const message = outcome.category === "malformed_output" ? MALFORMED_OUTPUT_MESSAGE : NO_USABLE_RANGES_MESSAGE;
107
+ return new RangePlanError(message, 1, outcome.excerpt, false, outcome.diagnosticPath, outcome);
108
+ }
109
+ /**
110
+ * Run one planner model, retrying the same model after oldest-first input
111
+ * trimming when the request itself overflows the context window.
112
+ *
113
+ * Trimming continues until no strictly smaller view exists; `nextTrimOffset`
114
+ * halves the remaining suffix, so the walk is finite. Only then is `overflowed`
115
+ * terminal and the ladder advances.
116
+ *
117
+ * Each view gets its own keep target from `compression_ratio`. Reusing the
118
+ * original whole-preparation target is what asked a halved 20-line region to
119
+ * keep 10 of its 10 visible lines — a request for zero deletions, whose obedient
120
+ * empty answer then hits the non-negotiable zero-range rejection. Extra
121
+ * reduction still comes only from the head the runner withheld.
122
+ */
123
+ async function planWithTrimming(preparation, planner, options) {
124
+ let offset = 0;
125
+ for (;;) {
126
+ const region = offset === 0 ? preparation.region : trimRegionHead(preparation.region, offset);
127
+ if (!region)
128
+ return { kind: "terminal", outcome: { kind: "overflowed" } };
129
+ const keepTarget = Math.max(region.protectedLineNumbers?.size ?? 0, Math.round(region.lines.length * preparation.parameters.compression_ratio));
130
+ const outcome = await planDeletedLineRanges(region, preparation.parameters, planner, keepTarget, options);
131
+ if (outcome.kind === "ranked" || outcome.kind === "recovered") {
132
+ if (offset === 0)
133
+ return { kind: "planned", ranges: outcome.ranges };
134
+ const validated = validateDeletedRanges(outcome.ranges, region);
135
+ return { kind: "planned", ranges: rebaseTrimmedRanges(validated, offset) };
136
+ }
137
+ if (outcome.kind !== "overflowed")
138
+ return { kind: "terminal", outcome };
139
+ if (options.signal?.aborted)
140
+ throw new Error("Compaction cancelled");
141
+ const next = nextTrimOffset(preparation.region, offset);
142
+ if (next === undefined)
143
+ return { kind: "terminal", outcome };
144
+ offset = next;
145
+ }
146
+ }
147
+ const MISSING_AUTH_MESSAGE = "Compaction provider authentication is unavailable";
148
+ /**
149
+ * A runner-local terminal cause with no provider attempt behind it.
150
+ *
151
+ * Missing credentials are not a provider outcome — no request was made — so no
152
+ * synthetic response is fabricated and no diagnostic sidecar is written. It is
153
+ * carried as `providerError` purely so the ladder can advance past it.
154
+ */
155
+ function authFailureOutcome(error) {
156
+ const message = error instanceof Error ? error.message : error === undefined ? MISSING_AUTH_MESSAGE : String(error);
157
+ return { kind: "providerError", message: message || MISSING_AUTH_MESSAGE };
158
+ }
159
+ /** Resolve one model's credentials, normalizing a rejection and `undefined` alike. */
160
+ async function resolvePlannerAuth(resolveAuth, model) {
161
+ try {
162
+ const auth = await resolveAuth(model);
163
+ return auth ? { auth } : { failure: authFailureOutcome(undefined) };
164
+ }
165
+ catch (error) {
166
+ return { failure: authFailureOutcome(error) };
167
+ }
168
+ }
169
+ function freshResult(preparation, hardInputLimit) {
170
+ const fresh = buildFreshContextWindow(preparation, hardInputLimit);
171
+ return {
172
+ ...withWholeContextStats(fresh.transcript, preparation, fresh.keptTail),
173
+ rung: "fresh",
174
+ keptTail: fresh.keptTail,
175
+ };
176
+ }
177
+ /**
178
+ * Produce one compacted transcript, tagged with the rung that produced it.
179
+ *
180
+ * The ladder is: the session model, then each configured fallback model
181
+ * borrowed for one planner request, then — only under `load_bearing` urgency —
182
+ * a fresh context window. A manual `/compact` runs at `recoverable` urgency and
183
+ * therefore cannot reach the context-destroying rung; it fails honestly instead.
184
+ *
185
+ * Unavailable credentials are ladder control flow, not an early throw: a
186
+ * borrowed candidate with its own working credentials can still rank the lines,
187
+ * and a load-bearing caller still reaches the credential-free fresh rung.
188
+ */
189
+ export async function runVerbatimCompaction(preparation, model, request) {
190
+ const signal = request.signal;
30
191
  if (signal?.aborted)
31
192
  throw new Error("Compaction cancelled");
32
- return withWholeContextStats(reconstructCompactedTranscript(preparation.region, validateDeletedRanges(raw, preparation.region)), preparation);
193
+ const plannerOptions = {
194
+ streamFn: request.streamFn,
195
+ sessionFilePath: request.sessionFilePath,
196
+ retry: request.retry,
197
+ callbacks: request.callbacks,
198
+ signal,
199
+ };
200
+ const hardInputLimit = hardInputLimitFor(model);
201
+ // A region below the planner minimum cannot be made rankable by changing
202
+ // models, so no planner is invoked. Only a load-bearing caller can reach a
203
+ // preparation this small; recoverable callers were refused before the runner.
204
+ if (preparation.region.lines.length < MIN_COMPACTABLE_REGION_LINES) {
205
+ if (request.urgency !== "load_bearing")
206
+ throw new RangePlanError(NO_USABLE_RANGES_MESSAGE, 0, "", false);
207
+ return freshResult(preparation, hardInputLimit);
208
+ }
209
+ const attempted = new Set();
210
+ // One borrower per run owns the monotonic cursor, so the configured list is
211
+ // walked exactly once no matter how many terminal outcomes occur.
212
+ const borrow = request.fallback
213
+ ? createFallbackPlannerBorrower(request.fallback)
214
+ : undefined;
215
+ const primaryBudget = resolvePlannerRequest(model, request.thinkingLevel);
216
+ const primaryAuth = await resolvePlannerAuth(request.resolveAuth, model);
217
+ let lastTerminal = "failure" in primaryAuth ? primaryAuth.failure : undefined;
218
+ let borrowed = false;
219
+ let planner;
220
+ if ("auth" in primaryAuth) {
221
+ planner = { model, budget: primaryBudget, auth: primaryAuth.auth };
222
+ }
223
+ else {
224
+ // No request was made, but this candidate must not be retried.
225
+ attempted.add(plannerAttemptKey({ model, budget: primaryBudget, auth: {} }));
226
+ planner = borrow ? await borrow(attempted, request.resolveAuth) : undefined;
227
+ borrowed = planner !== undefined;
228
+ }
229
+ while (planner) {
230
+ const attempt = await planWithTrimming(preparation, planner, plannerOptions);
231
+ if (signal?.aborted)
232
+ throw new Error("Compaction cancelled");
233
+ if (attempt.kind === "planned") {
234
+ const plannerModel = borrowed ? borrowedIdentity(planner) : undefined;
235
+ if (plannerModel) {
236
+ // Best-effort: the durable entry already records the borrowed model;
237
+ // a sidecar write failure never affects compaction success.
238
+ writeSuccessDiagnosticSidecar({
239
+ sessionFilePath: request.sessionFilePath,
240
+ model: planner.model,
241
+ successCategory: "borrowed_planner",
242
+ ...(plannerModel.thinkingLevel === undefined ? {} : { thinkingLevel: plannerModel.thinkingLevel }),
243
+ });
244
+ }
245
+ return plannedResult(preparation, attempt.ranges, plannerModel);
246
+ }
247
+ lastTerminal = attempt.outcome;
248
+ attempted.add(plannerAttemptKey(planner));
249
+ planner = borrow ? await borrow(attempted, request.resolveAuth) : undefined;
250
+ borrowed = planner !== undefined;
251
+ if (signal?.aborted)
252
+ throw new Error("Compaction cancelled");
253
+ }
254
+ if (request.urgency !== "load_bearing")
255
+ throw terminalError(lastTerminal);
256
+ return freshResult(preparation, hardInputLimit);
33
257
  }
34
258
  //# sourceMappingURL=compaction-runner.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"compaction-runner.js","sourceRoot":"","sources":["../../../src/core/compaction/compaction-runner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,8BAA8B,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5F,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAa3D,qFAAqF;AACrF,MAAM,UAAU,eAAe,CAAC,WAA0C;IACzE,MAAM,cAAc,GAAG,WAAW,CAAC,MAAM,CAAC,oBAAoB,EAAE,IAAI,IAAI,CAAC,CAAC;IAC1E,OAAO,IAAI,CAAC,GAAG,CACd,cAAc,EACd,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,WAAW,CAAC,UAAU,CAAC,iBAAiB,CAAC,CACtF,CAAC;AACH,CAAC;AAED,SAAS,qBAAqB,CAC7B,MAA2B,EAC3B,WAA0C;IAE1C,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,WAAW,GAAG,wBAAwB,CAAC,WAAW,CAAC,CAAC;IACrF,MAAM,gBAAgB,GAAG,WAAW,CAAC,YAAY,KAAK,CAAC;QACtD,CAAC,CAAC,CAAC;QACH,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,WAAW,GAAG,WAAW,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACxE,OAAO;QACN,GAAG,MAAM;QACT,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,EAAE,GAAG,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,WAAW,CAAC,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE;KACjG,CAAC;AACH,CAAC;AAED,sFAAsF;AACtF,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAC1C,WAA0C,EAC1C,KAAiB,EACjB,MAAc,EACd,OAAoC,EACpC,MAA+B,EAC/B,aAAwC,EACxC,OAA8B;IAE9B,IAAI,MAAM,EAAE,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC7D,MAAM,GAAG,GAAG,MAAM,qBAAqB,CACtC,WAAW,CAAC,MAAM,EAClB,WAAW,CAAC,UAAU,EACtB,KAAK,EACL,EAAE,MAAM,EAAE,OAAO,EAAE,EACnB,MAAM,EACN,aAAa,EACb,WAAW,CAAC,QAAQ,CAAC,aAAa,EAClC,eAAe,CAAC,WAAW,CAAC,EAC5B;QACC,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,eAAe,EAAE,OAAO,CAAC,eAAe;QACxC,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,SAAS,EAAE,OAAO,CAAC,SAAS;KAC5B,CACD,CAAC;IACF,IAAI,MAAM,EAAE,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC7D,OAAO,qBAAqB,CAC3B,8BAA8B,CAAC,WAAW,CAAC,MAAM,EAAE,qBAAqB,CAAC,GAAG,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,EAClG,WAAW,CACX,CAAC;AACH,CAAC","sourcesContent":["import type { StreamFn, ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { ProviderHeaders, RetryCallbacks, RetryPolicy } from \"@earendil-works/pi-ai\";\nimport type { Api, Model } from \"@earendil-works/pi-ai/compat\";\nimport { getKeptTailTokenEstimate } from \"./compaction-boundary.js\";\nimport { reconstructCompactedTranscript, validateDeletedRanges } from \"./deleted-ranges.js\";\nimport { planDeletedLineRanges } from \"./range-planner.js\";\nimport type { CompactedTranscript, VerbatimCompactionPreparation } from \"./compaction-types.js\";\n\nexport interface CompactionPlanOptions {\n\tstreamFn: StreamFn;\n\t/** Absolute path of the persisted session file. Undefined for in-memory sessions. */\n\tsessionFilePath?: string;\n\tretry?: RetryPolicy;\n\tcallbacks?: RetryCallbacks;\n}\n\nexport type CompactionRungResult = CompactedTranscript & { rung: \"planned\" };\n\n/** Calculate the single global line threshold directly from the prepared setting. */\nexport function targetKeepLines(preparation: VerbatimCompactionPreparation): number {\n\tconst protectedLines = preparation.region.protectedLineNumbers?.size ?? 0;\n\treturn Math.max(\n\t\tprotectedLines,\n\t\tMath.round(preparation.region.lines.length * preparation.parameters.compression_ratio),\n\t);\n}\n\nfunction withWholeContextStats(\n\tresult: CompactedTranscript,\n\tpreparation: VerbatimCompactionPreparation,\n): CompactionRungResult {\n\tconst tokensAfter = result.stats.tokensAfter + getKeptTailTokenEstimate(preparation);\n\tconst percentReduction = preparation.tokensBefore === 0\n\t\t? 0\n\t\t: Math.round((1 - tokensAfter / preparation.tokensBefore) * 1000) / 10;\n\treturn {\n\t\t...result,\n\t\trung: \"planned\",\n\t\tstats: { ...result.stats, tokensBefore: preparation.tokensBefore, tokensAfter, percentReduction },\n\t};\n}\n\n/** Execute one whole-region model plan and mechanically accept its safe deletions. */\nexport async function runVerbatimCompaction(\n\tpreparation: VerbatimCompactionPreparation,\n\tmodel: Model<Api>,\n\tapiKey: string,\n\theaders: ProviderHeaders | undefined,\n\tsignal: AbortSignal | undefined,\n\tthinkingLevel: ThinkingLevel | undefined,\n\toptions: CompactionPlanOptions,\n): Promise<CompactionRungResult> {\n\tif (signal?.aborted) throw new Error(\"Compaction cancelled\");\n\tconst raw = await planDeletedLineRanges(\n\t\tpreparation.region,\n\t\tpreparation.parameters,\n\t\tmodel,\n\t\t{ apiKey, headers },\n\t\tsignal,\n\t\tthinkingLevel,\n\t\tpreparation.settings.reserveTokens,\n\t\ttargetKeepLines(preparation),\n\t\t{\n\t\t\tstreamFn: options.streamFn,\n\t\t\tsessionFilePath: options.sessionFilePath,\n\t\t\tretry: options.retry,\n\t\t\tcallbacks: options.callbacks,\n\t\t},\n\t);\n\tif (signal?.aborted) throw new Error(\"Compaction cancelled\");\n\treturn withWholeContextStats(\n\t\treconstructCompactedTranscript(preparation.region, validateDeletedRanges(raw, preparation.region)),\n\t\tpreparation,\n\t);\n}\n"]}
1
+ {"version":3,"file":"compaction-runner.js","sourceRoot":"","sources":["../../../src/core/compaction/compaction-runner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,8BAA8B,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5F,OAAO,EACN,6BAA6B,EAC7B,iBAAiB,GAGjB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACN,wBAAwB,EACxB,wBAAwB,EACxB,qBAAqB,EACrB,cAAc,EACd,qBAAqB,GACrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAU3F,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAoCrE;;;;;;;;;;GAUG;AACH,MAAM,UAAU,eAAe,CAAC,WAA0C;IACzE,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC;IAClC,OAAO,IAAI,CAAC,GAAG,CACd,MAAM,CAAC,oBAAoB,EAAE,IAAI,IAAI,CAAC,EACtC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,WAAW,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAC1E,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAiB;IAC3C,OAAO,KAAK,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,iBAAiB,CAAC;AACjF,CAAC;AAED,SAAS,qBAAqB,CAC7B,MAA2B,EAC3B,WA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B,CAAC,OAAO,CAAC,CAAC,CAAC;QAC1C,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC5E,QAAQ,GAAG,OAAO,KAAK,SAAS,CAAC;QACjC,IAAI,MAAM,EAAE,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC9D,CAAC;IAED,IAAI,OAAO,CAAC,OAAO,KAAK,cAAc;QAAE,MAAM,aAAa,CAAC,YAAY,CAAC,CAAC;IAC1E,OAAO,WAAW,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;AACjD,CAAC","sourcesContent":["import type { StreamFn, ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { RetryCallbacks, RetryPolicy } from \"@earendil-works/pi-ai\";\nimport type { Api, Model } from \"@earendil-works/pi-ai/compat\";\nimport { getKeptTailTokenEstimate } from \"./compaction-boundary.js\";\nimport { reconstructCompactedTranscript, validateDeletedRanges } from \"./deleted-ranges.js\";\nimport {\n\tcreateFallbackPlannerBorrower,\n\tplannerAttemptKey,\n\ttype BorrowFallbackPlanner,\n\ttype FallbackPlannerContext,\n} from \"./fallback-planner.js\";\nimport type { TerminalPlannerOutcome } from \"./planner-outcome.js\";\nimport {\n\tMALFORMED_OUTPUT_MESSAGE,\n\tNO_USABLE_RANGES_MESSAGE,\n\tplanDeletedLineRanges,\n\tRangePlanError,\n\tresolvePlannerRequest,\n} from \"./range-planner.js\";\nimport { writeSuccessDiagnosticSidecar } from \"./range-planner-diagnostics.js\";\nimport { nextTrimOffset, rebaseTrimmedRanges, trimRegionHead } from \"./region-trimming.js\";\nimport type {\n\tBorrowedPlanner,\n\tCompactedTranscript,\n\tCompactionPlannerModel,\n\tCompactionUrgency,\n\tPlannerAuth,\n\tRawLineRange,\n\tVerbatimCompactionPreparation,\n} from \"./compaction-types.js\";\nimport { MIN_COMPACTABLE_REGION_LINES } from \"./compaction-types.js\";\n\nexport interface CompactionPlanOptions {\n\tstreamFn: StreamFn;\n\t/** Absolute path of the persisted session file. Undefined for in-memory sessions. */\n\tsessionFilePath?: string;\n\tretry?: RetryPolicy;\n\tcallbacks?: RetryCallbacks;\n}\n\n/** One compaction run's request. Urgency is required; there is no default. */\nexport interface CompactionRunRequest extends CompactionPlanOptions {\n\t/** Per-model credentials; a borrowed candidate uses its own, never the session model's. */\n\tresolveAuth: (model: Model<Api>) => Promise<PlannerAuth | undefined>;\n\tsignal?: AbortSignal;\n\t/** Inherited by the planner and never modified across attempts. */\n\tthinkingLevel: ThinkingLevel | undefined;\n\turgency: CompactionUrgency;\n\t/** Configured fallback candidates. Omitted means borrowing is impossible. */\n\tfallback?: FallbackPlannerContext;\n}\n\nexport type CompactionRungResult = CompactedTranscript & {\n\trung: \"planned\" | \"fresh\";\n\t/** Present only when a borrowed fallback model ranked the lines. */\n\tplannerModel?: CompactionPlannerModel;\n\t/** False only when the fresh rung had to drop the protected tail. */\n\tkeptTail: boolean;\n};\n\n/** Runner-internal fresh-window build: the transcript plus the tail decision. */\ninterface FreshWindowBuild {\n\ttranscript: CompactedTranscript;\n\tkeptTail: boolean;\n}\n\n/**\n * Calculate the single global line threshold from the prepared setting.\n *\n * This is the untrimmed target. Overflow trimming does NOT reuse it:\n * `planWithTrimming` recomputes the threshold against each trimmed view, so the\n * planner is always asked to keep a proportion of the lines it actually\n * received rather than a proportion of a region it never saw.\n *\n * Retained as an exported helper for tests and consumers that need the\n * pre-trim target; production planning goes through `planWithTrimming`.\n */\nexport function targetKeepLines(preparation: VerbatimCompactionPreparation): number {\n\tconst region = preparation.region;\n\treturn Math.max(\n\t\tregion.protectedLineNumbers?.size ?? 0,\n\t\tMath.round(region.lines.length * preparation.parameters.compression_ratio),\n\t);\n}\n\nfunction hardInputLimitFor(model: Model<Api>): number {\n\treturn model.contextWindow > 0 ? model.contextWindow : Number.POSITIVE_INFINITY;\n}\n\nfunction withWholeContextStats(\n\tresult: CompactedTranscript,\n\tpreparation: VerbatimCompactionPreparation,\n\tkeptTail: boolean,\n): CompactedTranscript {\n\tconst tokensAfter = result.stats.tokensAfter + (keptTail ? getKeptTailTokenEstimate(preparation) : 0);\n\tconst percentReduction = preparation.tokensBefore === 0\n\t\t? 0\n\t\t: Math.round((1 - tokensAfter / preparation.tokensBefore) * 1000) / 10;\n\treturn {\n\t\t...result,\n\t\tstats: { ...result.stats, tokensBefore: preparation.tokensBefore, tokensAfter, percentReduction },\n\t};\n}\n\n/**\n * Build a fresh context window and the tail decision that goes with it.\n *\n * Private on purpose: `keptTail` is runner bookkeeping that persistence needs in\n * order to write `firstKeptEntryId: null` when the protected tail is dropped. It\n * is deliberately absent from the public door's return value, which is exactly a\n * `CompactedTranscript`.\n */\nfunction buildFreshTranscript(preparation: VerbatimCompactionPreparation): CompactedTranscript {\n\tconst region = preparation.region;\n\tconst whole: RawLineRange[] = region.lines.length > 0 ? [{ start: 1, end: region.lines.length }] : [];\n\treturn reconstructCompactedTranscript(region, validateDeletedRanges(whole, region));\n}\n\nfunction buildFreshContextWindow(\n\tpreparation: VerbatimCompactionPreparation,\n\thardInputLimit: number,\n): FreshWindowBuild {\n\tconst limit = Number.isFinite(hardInputLimit) && hardInputLimit > 0 ? hardInputLimit : Number.POSITIVE_INFINITY;\n\t// The rule is \"tail under the limit ⇒ tail kept\", so the comparison is the\n\t// tail alone. Explicit protected lines are a hard floor that survives either\n\t// way, and counting the reconstructed protected/marker text here would drop a\n\t// tail that fits. A rebuilt context that still cannot be sent is the post-tool\n\t// gate's problem, not a reason for this rung to discard more.\n\treturn { transcript: buildFreshTranscript(preparation), keptTail: getKeptTailTokenEstimate(preparation) <= limit };\n}\n\n/**\n * Discard every compactable line and start a fresh context window.\n *\n * TOTAL. No provider, no credentials, no network, no signal, no failure mode,\n * no `Promise`. Port of codex `compact_token_budget` →\n * `Session::start_new_context_window`. Atomic's system prompt, context files,\n * and skills are rebuilt per request and were never in the transcript, so they\n * survive automatically.\n *\n * The whole region is emitted as one deletion range and handed to the unchanged\n * `validateDeletedRanges` → `reconstructCompactedTranscript` path, which splits\n * around protected spans and folds prior markers.\n *\n * Returns exactly a `CompactedTranscript` — `text`, `ranges`, `stats` and\n * nothing else. Whether the `preserve_recent` tail survives is a persistence\n * concern and travels on `CompactionRungResult.keptTail`, not on this door.\n */\nexport function startNewContextWindow(\n\tpreparation: VerbatimCompactionPreparation,\n): CompactedTranscript {\n\treturn buildFreshTranscript(preparation);\n}\n\nfunction plannedResult(\n\tpreparation: VerbatimCompactionPreparation,\n\tranges: RawLineRange[],\n\tplannerModel: CompactionPlannerModel | undefined,\n): CompactionRungResult {\n\tconst reconstructed = reconstructCompactedTranscript(\n\t\tpreparation.region,\n\t\tvalidateDeletedRanges(ranges, preparation.region),\n\t);\n\treturn {\n\t\t...withWholeContextStats(reconstructed, preparation, true),\n\t\trung: \"planned\",\n\t\t...(plannerModel ? { plannerModel } : {}),\n\t\tkeptTail: true,\n\t};\n}\n\nfunction borrowedIdentity(planner: BorrowedPlanner): CompactionPlannerModel {\n\treturn {\n\t\tprovider: planner.model.provider,\n\t\tid: planner.model.id,\n\t\t...(planner.budget.reasoning ? { thinkingLevel: planner.budget.reasoning } : {}),\n\t};\n}\n\nfunction terminalError(outcome: TerminalPlannerOutcome | undefined): RangePlanError {\n\tif (!outcome) return new RangePlanError(MALFORMED_OUTPUT_MESSAGE, 1, \"\", false);\n\tif (outcome.kind === \"rateLimited\") {\n\t\treturn new RangePlanError(outcome.message, 1, \"\", false, outcome.diagnosticPath, outcome);\n\t}\n\tif (outcome.kind === \"overflowed\") {\n\t\treturn new RangePlanError(\n\t\t\t\"Compaction range planning exceeded the model context window\",\n\t\t\t1,\n\t\t\t\"\",\n\t\t\ttrue,\n\t\t\toutcome.diagnosticPath,\n\t\t\toutcome,\n\t\t);\n\t}\n\tif (outcome.kind === \"providerError\") {\n\t\treturn new RangePlanError(outcome.message, 1, \"\", false, outcome.diagnosticPath, outcome);\n\t}\n\tconst message = outcome.category === \"malformed_output\" ? MALFORMED_OUTPUT_MESSAGE : NO_USABLE_RANGES_MESSAGE;\n\treturn new RangePlanError(message, 1, outcome.excerpt, false, outcome.diagnosticPath, outcome);\n}\n\ntype PlannerAttempt =\n\t| { kind: \"planned\"; ranges: RawLineRange[] }\n\t| { kind: \"terminal\"; outcome: TerminalPlannerOutcome };\n\n/**\n * Run one planner model, retrying the same model after oldest-first input\n * trimming when the request itself overflows the context window.\n *\n * Trimming continues until no strictly smaller view exists; `nextTrimOffset`\n * halves the remaining suffix, so the walk is finite. Only then is `overflowed`\n * terminal and the ladder advances.\n *\n * Each view gets its own keep target from `compression_ratio`. Reusing the\n * original whole-preparation target is what asked a halved 20-line region to\n * keep 10 of its 10 visible lines — a request for zero deletions, whose obedient\n * empty answer then hits the non-negotiable zero-range rejection. Extra\n * reduction still comes only from the head the runner withheld.\n */\nasync function planWithTrimming(\n\tpreparation: VerbatimCompactionPreparation,\n\tplanner: BorrowedPlanner,\n\toptions: CompactionPlanOptions & { signal?: AbortSignal },\n): Promise<PlannerAttempt> {\n\tlet offset = 0;\n\tfor (;;) {\n\t\tconst region = offset === 0 ? preparation.region : trimRegionHead(preparation.region, offset);\n\t\tif (!region) return { kind: \"terminal\", outcome: { kind: \"overflowed\" } };\n\t\tconst keepTarget = Math.max(\n\t\t\tregion.protectedLineNumbers?.size ?? 0,\n\t\t\tMath.round(region.lines.length * preparation.parameters.compression_ratio),\n\t\t);\n\t\tconst outcome = await planDeletedLineRanges(region, preparation.parameters, planner, keepTarget, options);\n\t\tif (outcome.kind === \"ranked\" || outcome.kind === \"recovered\") {\n\t\t\tif (offset === 0) return { kind: \"planned\", ranges: outcome.ranges };\n\t\t\tconst validated = validateDeletedRanges(outcome.ranges, region);\n\t\t\treturn { kind: \"planned\", ranges: rebaseTrimmedRanges(validated, offset) };\n\t\t}\n\t\tif (outcome.kind !== \"overflowed\") return { kind: \"terminal\", outcome };\n\t\tif (options.signal?.aborted) throw new Error(\"Compaction cancelled\");\n\t\tconst next = nextTrimOffset(preparation.region, offset);\n\t\tif (next === undefined) return { kind: \"terminal\", outcome };\n\t\toffset = next;\n\t}\n}\n\nconst MISSING_AUTH_MESSAGE = \"Compaction provider authentication is unavailable\";\n\n/**\n * A runner-local terminal cause with no provider attempt behind it.\n *\n * Missing credentials are not a provider outcome — no request was made — so no\n * synthetic response is fabricated and no diagnostic sidecar is written. It is\n * carried as `providerError` purely so the ladder can advance past it.\n */\nfunction authFailureOutcome(error: unknown): TerminalPlannerOutcome {\n\tconst message = error instanceof Error ? error.message : error === undefined ? MISSING_AUTH_MESSAGE : String(error);\n\treturn { kind: \"providerError\", message: message || MISSING_AUTH_MESSAGE };\n}\n\n/** Resolve one model's credentials, normalizing a rejection and `undefined` alike. */\nasync function resolvePlannerAuth(\n\tresolveAuth: CompactionRunRequest[\"resolveAuth\"],\n\tmodel: Model<Api>,\n): Promise<{ auth: PlannerAuth } | { failure: TerminalPlannerOutcome }> {\n\ttry {\n\t\tconst auth = await resolveAuth(model);\n\t\treturn auth ? { auth } : { failure: authFailureOutcome(undefined) };\n\t} catch (error) {\n\t\treturn { failure: authFailureOutcome(error) };\n\t}\n}\n\nfunction freshResult(\n\tpreparation: VerbatimCompactionPreparation,\n\thardInputLimit: number,\n): CompactionRungResult {\n\tconst fresh = buildFreshContextWindow(preparation, hardInputLimit);\n\treturn {\n\t\t...withWholeContextStats(fresh.transcript, preparation, fresh.keptTail),\n\t\trung: \"fresh\",\n\t\tkeptTail: fresh.keptTail,\n\t};\n}\n\n/**\n * Produce one compacted transcript, tagged with the rung that produced it.\n *\n * The ladder is: the session model, then each configured fallback model\n * borrowed for one planner request, then — only under `load_bearing` urgency —\n * a fresh context window. A manual `/compact` runs at `recoverable` urgency and\n * therefore cannot reach the context-destroying rung; it fails honestly instead.\n *\n * Unavailable credentials are ladder control flow, not an early throw: a\n * borrowed candidate with its own working credentials can still rank the lines,\n * and a load-bearing caller still reaches the credential-free fresh rung.\n */\nexport async function runVerbatimCompaction(\n\tpreparation: VerbatimCompactionPreparation,\n\tmodel: Model<Api>,\n\trequest: CompactionRunRequest,\n): Promise<CompactionRungResult> {\n\tconst signal = request.signal;\n\tif (signal?.aborted) throw new Error(\"Compaction cancelled\");\n\tconst plannerOptions = {\n\t\tstreamFn: request.streamFn,\n\t\tsessionFilePath: request.sessionFilePath,\n\t\tretry: request.retry,\n\t\tcallbacks: request.callbacks,\n\t\tsignal,\n\t};\n\tconst hardInputLimit = hardInputLimitFor(model);\n\n\t// A region below the planner minimum cannot be made rankable by changing\n\t// models, so no planner is invoked. Only a load-bearing caller can reach a\n\t// preparation this small; recoverable callers were refused before the runner.\n\tif (preparation.region.lines.length < MIN_COMPACTABLE_REGION_LINES) {\n\t\tif (request.urgency !== \"load_bearing\") throw new RangePlanError(NO_USABLE_RANGES_MESSAGE, 0, \"\", false);\n\t\treturn freshResult(preparation, hardInputLimit);\n\t}\n\n\tconst attempted = new Set<string>();\n\t// One borrower per run owns the monotonic cursor, so the configured list is\n\t// walked exactly once no matter how many terminal outcomes occur.\n\tconst borrow: BorrowFallbackPlanner | undefined = request.fallback\n\t\t? createFallbackPlannerBorrower(request.fallback)\n\t\t: undefined;\n\tconst primaryBudget = resolvePlannerRequest(model, request.thinkingLevel);\n\tconst primaryAuth = await resolvePlannerAuth(request.resolveAuth, model);\n\tlet lastTerminal: TerminalPlannerOutcome | undefined = \"failure\" in primaryAuth ? primaryAuth.failure : undefined;\n\tlet borrowed = false;\n\tlet planner: BorrowedPlanner | undefined;\n\n\tif (\"auth\" in primaryAuth) {\n\t\tplanner = { model, budget: primaryBudget, auth: primaryAuth.auth };\n\t} else {\n\t\t// No request was made, but this candidate must not be retried.\n\t\tattempted.add(plannerAttemptKey({ model, budget: primaryBudget, auth: {} }));\n\t\tplanner = borrow ? await borrow(attempted, request.resolveAuth) : undefined;\n\t\tborrowed = planner !== undefined;\n\t}\n\n\twhile (planner) {\n\t\tconst attempt = await planWithTrimming(preparation, planner, plannerOptions);\n\t\tif (signal?.aborted) throw new Error(\"Compaction cancelled\");\n\t\tif (attempt.kind === \"planned\") {\n\t\t\tconst plannerModel = borrowed ? borrowedIdentity(planner) : undefined;\n\t\t\tif (plannerModel) {\n\t\t\t\t// Best-effort: the durable entry already records the borrowed model;\n\t\t\t\t// a sidecar write failure never affects compaction success.\n\t\t\t\twriteSuccessDiagnosticSidecar({\n\t\t\t\t\tsessionFilePath: request.sessionFilePath,\n\t\t\t\t\tmodel: planner.model,\n\t\t\t\t\tsuccessCategory: \"borrowed_planner\",\n\t\t\t\t\t...(plannerModel.thinkingLevel === undefined ? {} : { thinkingLevel: plannerModel.thinkingLevel }),\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn plannedResult(preparation, attempt.ranges, plannerModel);\n\t\t}\n\t\tlastTerminal = attempt.outcome;\n\t\tattempted.add(plannerAttemptKey(planner));\n\t\tplanner = borrow ? await borrow(attempted, request.resolveAuth) : undefined;\n\t\tborrowed = planner !== undefined;\n\t\tif (signal?.aborted) throw new Error(\"Compaction cancelled\");\n\t}\n\n\tif (request.urgency !== \"load_bearing\") throw terminalError(lastTerminal);\n\treturn freshResult(preparation, hardInputLimit);\n}\n"]}
@@ -1,3 +1,6 @@
1
+ import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
2
+ import type { ProviderHeaders } from "@earendil-works/pi-ai";
3
+ import type { Api, Model } from "@earendil-works/pi-ai/compat";
1
4
  import type { CompactionSettings } from "./compaction.js";
2
5
  export declare const VERBATIM_COMPACTION_PROMPT_VERSION: 3;
3
6
  export declare const VERBATIM_COMPACTION_STRATEGY: "verbatim-lines";
@@ -49,12 +52,58 @@ export interface VerbatimCompactionStats {
49
52
  tokensAfter: number;
50
53
  percentReduction: number;
51
54
  }
55
+ /** How much the caller can afford to lose if compaction does not happen. */
56
+ export type CompactionUrgency =
57
+ /** Manual /compact, threshold auto-compaction — failing is safe. */
58
+ "recoverable"
59
+ /** Overflow recovery, post-tool preflight — failing kills the turn. */
60
+ | "load_bearing";
61
+ /** How a durable compaction boundary was produced. */
62
+ export type CompactionRung = "planned" | "extension" | "fresh";
63
+ /** Credentials for one planner request. Resolved per model, never shared. */
64
+ export interface PlannerAuth {
65
+ apiKey?: string;
66
+ headers?: ProviderHeaders;
67
+ baseUrl?: string;
68
+ }
69
+ /**
70
+ * What one planner request may spend.
71
+ *
72
+ * `maxTokens` is declared `undefined`, not `number | undefined`: the type
73
+ * forbids reintroducing the `0.8 * reserveTokens` output cap without changing
74
+ * the type and failing review. pi-ai's `clampMaxTokensToContext` is the only bound.
75
+ */
76
+ export interface PlannerBudget {
77
+ readonly maxTokens: undefined;
78
+ readonly reasoning: ThinkingLevel | undefined;
79
+ }
80
+ /**
81
+ * A planner-only model borrowing. Cannot be confused with a session model switch.
82
+ *
83
+ * It carries no attempted-set key: the effective identity of an attempt is
84
+ * `provider/model:<effective reasoning>`, derived from `model` and
85
+ * `budget.reasoning` by `plannerAttemptKey`. Storing a key resolved from the raw
86
+ * optional suffix would let the same effective request run twice.
87
+ */
88
+ export interface BorrowedPlanner {
89
+ readonly model: Model<Api>;
90
+ readonly budget: PlannerBudget;
91
+ readonly auth: PlannerAuth;
92
+ }
93
+ /** Identity of the model that ranked the deleted lines, when it was borrowed. */
94
+ export interface CompactionPlannerModel {
95
+ provider: string;
96
+ id: string;
97
+ thinkingLevel?: ThinkingLevel;
98
+ }
52
99
  export interface VerbatimCompactionDetails {
53
100
  strategy: typeof VERBATIM_COMPACTION_STRATEGY;
54
101
  promptVersion: typeof VERBATIM_COMPACTION_PROMPT_VERSION;
55
102
  parameters: VerbatimCompactionParameters;
56
103
  stats: VerbatimCompactionStats;
57
- rung: "planned" | "extension";
104
+ rung: CompactionRung;
105
+ /** Present only when a borrowed fallback model ranked the lines. */
106
+ plannerModel?: CompactionPlannerModel;
58
107
  backupPath?: string;
59
108
  }
60
109
  export interface VerbatimCompactionPreparation {
@@ -74,7 +123,9 @@ export interface VerbatimCompactionResult {
74
123
  stats: VerbatimCompactionStats;
75
124
  parameters: VerbatimCompactionParameters;
76
125
  promptVersion: typeof VERBATIM_COMPACTION_PROMPT_VERSION;
77
- rung: VerbatimCompactionDetails["rung"];
126
+ rung: CompactionRung;
127
+ /** Present only when a borrowed fallback model ranked the lines. */
128
+ plannerModel?: CompactionPlannerModel;
78
129
  backupPath?: string;
79
130
  }
80
131
  //# sourceMappingURL=compaction-types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compaction-types.d.ts","sourceRoot":"","sources":["../../../src/core/compaction/compaction-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,eAAO,MAAM,kCAAkC,EAAG,CAAU,CAAC;AAC7D,eAAO,MAAM,4BAA4B,EAAG,gBAAyB,CAAC;AAEtE,eAAO,MAAM,yBAAyB,MAAM,CAAC;AAC7C,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC,eAAO,MAAM,4BAA4B,KAAK,CAAC;AAE/C,MAAM,WAAW,4BAA4B;IAC5C,oDAAoD;IACpD,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gFAAgF;IAChF,eAAe,EAAE,MAAM,CAAC;IACxB,iDAAiD;IACjD,KAAK,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,SAAS;IACzB,sCAAsC;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,qCAAqC;IACrC,GAAG,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAE/D,MAAM,WAAW,YAAY;IAC5B,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,GAAG,CAAC,EAAE,eAAe,CAAC;CACtB;AAED,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC;IACnC,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,iBAAiB,EAAE,WAAW,CAAC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AAK,EAAE,uBAAuB,CAAC;IAC/B,UAAU,EAAE,4BAA4B,CAAC;IACzC,aAAa,EAAE,OAAO,kCAAkC,CAAC;IACzD,IAAI,EAAE,cAAc,CAAC;IACrB,oEAAoE;IACpE,YAAY,CAAC,EAAE,sBAAsB,CAAC;IACtC,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB"}
@@ -1 +1 @@
1
- {"version":3,"file":"compaction-types.js","sourceRoot":"","sources":["../../../src/core/compaction/compaction-types.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAU,CAAC;AAC7D,MAAM,CAAC,MAAM,4BAA4B,GAAG,gBAAyB,CAAC;AAEtE,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,CAAC;AAC7C,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC;AACzC,MAAM,CAAC,MAAM,4BAA4B,GAAG,EAAE,CAAC","sourcesContent":["import type { CompactionSettings } from \"./compaction.js\";\n\nexport const VERBATIM_COMPACTION_PROMPT_VERSION = 3 as const;\nexport const VERBATIM_COMPACTION_STRATEGY = \"verbatim-lines\" as const;\n\nexport const DEFAULT_COMPRESSION_RATIO = 0.5;\nexport const DEFAULT_PRESERVE_RECENT = 2;\nexport const MIN_COMPACTABLE_REGION_LINES = 20;\n\nexport interface VerbatimCompactionParameters {\n\t/** Fraction of compactable region lines to keep. */\n\tcompression_ratio: number;\n\t/** Recent context-eligible messages retained outside the compactable region. */\n\tpreserve_recent: number;\n\t/** Relevance focus used by the range planner. */\n\tquery: string;\n}\n\nexport interface LineRange {\n\t/** One-based inclusive first line. */\n\tstart: number;\n\t/** One-based inclusive last line. */\n\tend: number;\n}\n\nexport type RawLineEndpoint = number | string | boolean | null;\n\nexport interface RawLineRange {\n\tstart?: RawLineEndpoint;\n\tend?: RawLineEndpoint;\n}\n\nexport interface NumberedRegion {\n\treadonly __brand: \"NumberedRegion\";\n\tlines: string[];\n\theaderLineNumbers: ReadonlySet<number>;\n\tpriorMarkerNs: ReadonlyMap<number, number>;\n\t/** Optional future protected spans, expressed as one-based line numbers. */\n\tprotectedLineNumbers?: ReadonlySet<number>;\n\ttokenEstimate: number;\n}\n\nexport type ValidatedRanges = readonly LineRange[] & { readonly __brand: \"ValidatedRanges\" };\n\nexport interface CompactedTranscript {\n\ttext: string;\n\tranges: LineRange[];\n\tstats: VerbatimCompactionStats;\n}\n\nexport interface VerbatimCompactionStats {\n\tlinesBefore: number;\n\tlinesDeleted: number;\n\tlinesKept: number;\n\trangeCount: number;\n\ttokensBefore: number;\n\ttokensAfter: number;\n\tpercentReduction: number;\n}\n\nexport interface VerbatimCompactionDetails {\n\tstrategy: typeof VERBATIM_COMPACTION_STRATEGY;\n\tpromptVersion: typeof VERBATIM_COMPACTION_PROMPT_VERSION;\n\tparameters: VerbatimCompactionParameters;\n\tstats: VerbatimCompactionStats;\n\trung: \"planned\" | \"extension\";\n\tbackupPath?: string;\n}\n\nexport interface VerbatimCompactionPreparation {\n\t/** First context-visible tail entry, or null when no pre-boundary message is retained. */\n\tfirstKeptEntryId: string | null;\n\tregion: NumberedRegion;\n\tregionEntryIds: string[];\n\tkeptTailMessageCount: number;\n\ttokensBefore: number;\n\tparameters: VerbatimCompactionParameters;\n\tsettings: CompactionSettings;\n}\n\nexport interface VerbatimCompactionResult {\n\tcompactedText: string;\n\tfirstKeptEntryId: string | null;\n\ttokensBefore: number;\n\tstats: VerbatimCompactionStats;\n\tparameters: VerbatimCompactionParameters;\n\tpromptVersion: typeof VERBATIM_COMPACTION_PROMPT_VERSION;\n\trung: VerbatimCompactionDetails[\"rung\"];\n\tbackupPath?: string;\n}\n"]}
1
+ {"version":3,"file":"compaction-types.js","sourceRoot":"","sources":["../../../src/core/compaction/compaction-types.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAU,CAAC;AAC7D,MAAM,CAAC,MAAM,4BAA4B,GAAG,gBAAyB,CAAC;AAEtE,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,CAAC;AAC7C,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC;AACzC,MAAM,CAAC,MAAM,4BAA4B,GAAG,EAAE,CAAC","sourcesContent":["import type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { ProviderHeaders } from \"@earendil-works/pi-ai\";\nimport type { Api, Model } from \"@earendil-works/pi-ai/compat\";\nimport type { CompactionSettings } from \"./compaction.js\";\n\nexport const VERBATIM_COMPACTION_PROMPT_VERSION = 3 as const;\nexport const VERBATIM_COMPACTION_STRATEGY = \"verbatim-lines\" as const;\n\nexport const DEFAULT_COMPRESSION_RATIO = 0.5;\nexport const DEFAULT_PRESERVE_RECENT = 2;\nexport const MIN_COMPACTABLE_REGION_LINES = 20;\n\nexport interface VerbatimCompactionParameters {\n\t/** Fraction of compactable region lines to keep. */\n\tcompression_ratio: number;\n\t/** Recent context-eligible messages retained outside the compactable region. */\n\tpreserve_recent: number;\n\t/** Relevance focus used by the range planner. */\n\tquery: string;\n}\n\nexport interface LineRange {\n\t/** One-based inclusive first line. */\n\tstart: number;\n\t/** One-based inclusive last line. */\n\tend: number;\n}\n\nexport type RawLineEndpoint = number | string | boolean | null;\n\nexport interface RawLineRange {\n\tstart?: RawLineEndpoint;\n\tend?: RawLineEndpoint;\n}\n\nexport interface NumberedRegion {\n\treadonly __brand: \"NumberedRegion\";\n\tlines: string[];\n\theaderLineNumbers: ReadonlySet<number>;\n\tpriorMarkerNs: ReadonlyMap<number, number>;\n\t/** Optional future protected spans, expressed as one-based line numbers. */\n\tprotectedLineNumbers?: ReadonlySet<number>;\n\ttokenEstimate: number;\n}\n\nexport type ValidatedRanges = readonly LineRange[] & { readonly __brand: \"ValidatedRanges\" };\n\nexport interface CompactedTranscript {\n\ttext: string;\n\tranges: LineRange[];\n\tstats: VerbatimCompactionStats;\n}\n\nexport interface VerbatimCompactionStats {\n\tlinesBefore: number;\n\tlinesDeleted: number;\n\tlinesKept: number;\n\trangeCount: number;\n\ttokensBefore: number;\n\ttokensAfter: number;\n\tpercentReduction: number;\n}\n\n/** How much the caller can afford to lose if compaction does not happen. */\nexport type CompactionUrgency =\n\t/** Manual /compact, threshold auto-compaction — failing is safe. */\n\t| \"recoverable\"\n\t/** Overflow recovery, post-tool preflight — failing kills the turn. */\n\t| \"load_bearing\";\n\n/** How a durable compaction boundary was produced. */\nexport type CompactionRung = \"planned\" | \"extension\" | \"fresh\";\n\n/** Credentials for one planner request. Resolved per model, never shared. */\nexport interface PlannerAuth {\n\tapiKey?: string;\n\theaders?: ProviderHeaders;\n\tbaseUrl?: string;\n}\n\n/**\n * What one planner request may spend.\n *\n * `maxTokens` is declared `undefined`, not `number | undefined`: the type\n * forbids reintroducing the `0.8 * reserveTokens` output cap without changing\n * the type and failing review. pi-ai's `clampMaxTokensToContext` is the only bound.\n */\nexport interface PlannerBudget {\n\treadonly maxTokens: undefined;\n\treadonly reasoning: ThinkingLevel | undefined;\n}\n\n/**\n * A planner-only model borrowing. Cannot be confused with a session model switch.\n *\n * It carries no attempted-set key: the effective identity of an attempt is\n * `provider/model:<effective reasoning>`, derived from `model` and\n * `budget.reasoning` by `plannerAttemptKey`. Storing a key resolved from the raw\n * optional suffix would let the same effective request run twice.\n */\nexport interface BorrowedPlanner {\n\treadonly model: Model<Api>;\n\treadonly budget: PlannerBudget;\n\treadonly auth: PlannerAuth;\n}\n\n/** Identity of the model that ranked the deleted lines, when it was borrowed. */\nexport interface CompactionPlannerModel {\n\tprovider: string;\n\tid: string;\n\tthinkingLevel?: ThinkingLevel;\n}\n\nexport interface VerbatimCompactionDetails {\n\tstrategy: typeof VERBATIM_COMPACTION_STRATEGY;\n\tpromptVersion: typeof VERBATIM_COMPACTION_PROMPT_VERSION;\n\tparameters: VerbatimCompactionParameters;\n\tstats: VerbatimCompactionStats;\n\trung: CompactionRung;\n\t/** Present only when a borrowed fallback model ranked the lines. */\n\tplannerModel?: CompactionPlannerModel;\n\tbackupPath?: string;\n}\n\nexport interface VerbatimCompactionPreparation {\n\t/** First context-visible tail entry, or null when no pre-boundary message is retained. */\n\tfirstKeptEntryId: string | null;\n\tregion: NumberedRegion;\n\tregionEntryIds: string[];\n\tkeptTailMessageCount: number;\n\ttokensBefore: number;\n\tparameters: VerbatimCompactionParameters;\n\tsettings: CompactionSettings;\n}\n\nexport interface VerbatimCompactionResult {\n\tcompactedText: string;\n\tfirstKeptEntryId: string | null;\n\ttokensBefore: number;\n\tstats: VerbatimCompactionStats;\n\tparameters: VerbatimCompactionParameters;\n\tpromptVersion: typeof VERBATIM_COMPACTION_PROMPT_VERSION;\n\trung: CompactionRung;\n\t/** Present only when a borrowed fallback model ranked the lines. */\n\tplannerModel?: CompactionPlannerModel;\n\tbackupPath?: string;\n}\n"]}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Borrow a configured fallback model for one compaction planner request.
3
+ *
4
+ * This is deliberately a *weaker* capability than main-chat model fallback. The
5
+ * borrowing door returns a `BorrowedPlanner` **value**: it holds no session
6
+ * handle, so it cannot write `agent.state.model`, append a model-change entry,
7
+ * change the session thinking level, refresh the system prompt, emit
8
+ * `model_changed`/`model_select`, or call `agent.continue()`.
9
+ * `_trySwitchToFallbackModel` does all of those and is not reused or modified.
10
+ *
11
+ * The attempted-key set belongs to the compaction run and is read-only here, so
12
+ * borrowing never touches the main chat's `_fallbackAttemptedKeys`.
13
+ */
14
+ import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
15
+ import type { Api, Model } from "@earendil-works/pi-ai/compat";
16
+ import { type FallbackModelLookup } from "../fallback-models.js";
17
+ import type { BorrowedPlanner, PlannerAuth } from "./compaction-types.js";
18
+ /**
19
+ * Everything candidate selection needs.
20
+ *
21
+ * The RFC's §5.1 signature takes only `attempted` and `resolveAuth`, which
22
+ * cannot select a candidate on its own: it names no fallback list, no model
23
+ * registry, no preferred provider, and no inherited reasoning level. Those
24
+ * inputs travel in this context object rather than through hidden state.
25
+ */
26
+ export interface FallbackPlannerContext {
27
+ /** The session's effective `fallbackModels`, in configured order. */
28
+ readonly fallbackModels: readonly string[];
29
+ /** Model registry used to resolve and authenticate candidates. */
30
+ readonly registry: FallbackModelLookup;
31
+ /** Provider preferred when an unqualified entry is ambiguous. */
32
+ readonly preferredProvider: string | undefined;
33
+ /** Session level inherited when a candidate carries no `:level` suffix. */
34
+ readonly sessionThinkingLevel: ThinkingLevel | undefined;
35
+ }
36
+ /**
37
+ * Identity of one planner attempt: `provider/model:<effective reasoning>`.
38
+ *
39
+ * The key must be derived from the *effective* level the request will carry,
40
+ * not from the raw optional `model:level` suffix. An unsuffixed entry for the
41
+ * session model inherits the session level, so keying it as `provider/model:`
42
+ * would let the identical request run a second time.
43
+ */
44
+ export declare function plannerAttemptKey(planner: BorrowedPlanner): string;
45
+ /** The exact two-argument borrowing door, bound to one run's configuration. */
46
+ export type BorrowFallbackPlanner = (attempted: ReadonlySet<string>, resolveAuth: (model: Model<Api>) => Promise<PlannerAuth | undefined>) => Promise<BorrowedPlanner | undefined>;
47
+ /**
48
+ * Build the borrowing door for one compaction run.
49
+ *
50
+ * The RFC's top-level two-argument signature names no fallback list, registry,
51
+ * preferred provider, inherited reasoning level, or traversal cursor, so a
52
+ * stateless exported function cannot select a candidate without hidden shared
53
+ * state — unsafe under concurrent compactions. Binding the configuration and the
54
+ * run-local cursor in a closure keeps the returned door exactly two arguments
55
+ * while `attempted` stays a `ReadonlySet` the borrower never writes.
56
+ *
57
+ * The walk is one monotonic pass. Each list position is inspected at most once,
58
+ * whether it fails to resolve, has no usable credentials, duplicates an earlier
59
+ * identity, or yields a planner. Without the cursor, an entry that could not
60
+ * resolve earlier could be returned after a later candidate once the registry
61
+ * changed, producing a B→A order the configured list never asked for.
62
+ */
63
+ export declare function createFallbackPlannerBorrower(context: FallbackPlannerContext): BorrowFallbackPlanner;
64
+ //# sourceMappingURL=fallback-planner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fallback-planner.d.ts","sourceRoot":"","sources":["../../../src/core/compaction/fallback-planner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAqC,KAAK,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACpG,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAG1E;;;;;;;GAOG;AACH,MAAM,WAAW,sBAAsB;IACtC,qEAAqE;IACrE,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3C,kEAAkE;IAClE,QAAQ,CAAC,QAAQ,EAAE,mBAAmB,CAAC;IACvC,iEAAiE;IACjE,QAAQ,CAAC,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/C,2EAA2E;IAC3E,QAAQ,CAAC,oBAAoB,EAAE,aAAa,GAAG,SAAS,CAAC;CACzD;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAElE;AAeD,+EAA+E;AAC/E,MAAM,MAAM,qBAAqB,GAAG,CACnC,SAAS,EAAE,WAAW,CAAC,MAAM,CAAC,EAC9B,WAAW,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,KAChE,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC,CAAC;AAE1C;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,sBAAsB,GAAG,qBAAqB,CA6BpG"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Borrow a configured fallback model for one compaction planner request.
3
+ *
4
+ * This is deliberately a *weaker* capability than main-chat model fallback. The
5
+ * borrowing door returns a `BorrowedPlanner` **value**: it holds no session
6
+ * handle, so it cannot write `agent.state.model`, append a model-change entry,
7
+ * change the session thinking level, refresh the system prompt, emit
8
+ * `model_changed`/`model_select`, or call `agent.continue()`.
9
+ * `_trySwitchToFallbackModel` does all of those and is not reused or modified.
10
+ *
11
+ * The attempted-key set belongs to the compaction run and is read-only here, so
12
+ * borrowing never touches the main chat's `_fallbackAttemptedKeys`.
13
+ */
14
+ import { fallbackKey, resolveFallbackModel } from "../fallback-models.js";
15
+ import { resolvePlannerRequest } from "./range-planner.js";
16
+ /**
17
+ * Identity of one planner attempt: `provider/model:<effective reasoning>`.
18
+ *
19
+ * The key must be derived from the *effective* level the request will carry,
20
+ * not from the raw optional `model:level` suffix. An unsuffixed entry for the
21
+ * session model inherits the session level, so keying it as `provider/model:`
22
+ * would let the identical request run a second time.
23
+ */
24
+ export function plannerAttemptKey(planner) {
25
+ return fallbackKey(planner.model, planner.budget.reasoning);
26
+ }
27
+ /**
28
+ * Build the borrowing door for one compaction run.
29
+ *
30
+ * The RFC's top-level two-argument signature names no fallback list, registry,
31
+ * preferred provider, inherited reasoning level, or traversal cursor, so a
32
+ * stateless exported function cannot select a candidate without hidden shared
33
+ * state — unsafe under concurrent compactions. Binding the configuration and the
34
+ * run-local cursor in a closure keeps the returned door exactly two arguments
35
+ * while `attempted` stays a `ReadonlySet` the borrower never writes.
36
+ *
37
+ * The walk is one monotonic pass. Each list position is inspected at most once,
38
+ * whether it fails to resolve, has no usable credentials, duplicates an earlier
39
+ * identity, or yields a planner. Without the cursor, an entry that could not
40
+ * resolve earlier could be returned after a later candidate once the registry
41
+ * changed, producing a B→A order the configured list never asked for.
42
+ */
43
+ export function createFallbackPlannerBorrower(context) {
44
+ const walk = { nextIndex: 0, consumed: new Set() };
45
+ return async (attempted, resolveAuth) => {
46
+ while (walk.nextIndex < context.fallbackModels.length) {
47
+ const entry = context.fallbackModels[walk.nextIndex];
48
+ // Advance before any work: this list position is spent either way.
49
+ walk.nextIndex += 1;
50
+ const candidate = resolveFallbackModel(entry, context.registry, context.preferredProvider);
51
+ if (!candidate)
52
+ continue;
53
+ // Resolve the budget first: the identity depends on the effective
54
+ // reasoning level, which inheritance may supply.
55
+ const budget = resolvePlannerRequest(candidate.model, context.sessionThinkingLevel, candidate.thinkingLevel);
56
+ const key = fallbackKey(candidate.model, budget.reasoning);
57
+ if (attempted.has(key) || walk.consumed.has(key))
58
+ continue;
59
+ walk.consumed.add(key);
60
+ let auth;
61
+ try {
62
+ auth = await resolveAuth(candidate.model);
63
+ }
64
+ catch {
65
+ // A candidate whose credentials cannot be resolved is simply unusable.
66
+ auth = undefined;
67
+ }
68
+ if (!auth)
69
+ continue;
70
+ return { model: candidate.model, budget, auth };
71
+ }
72
+ return undefined;
73
+ };
74
+ }
75
+ //# sourceMappingURL=fallback-planner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fallback-planner.js","sourceRoot":"","sources":["../../../src/core/compaction/fallback-planner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAA4B,MAAM,uBAAuB,CAAC;AAEpG,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAqB3D;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAwB;IACzD,OAAO,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AAC7D,CAAC;AAqBD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,6BAA6B,CAAC,OAA+B;IAC5E,MAAM,IAAI,GAAwB,EAAE,SAAS,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAU,EAAE,CAAC;IAChF,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,EAAE;QACvC,OAAO,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC;YACvD,MAAM,KAAK,GAAG,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACrD,mEAAmE;YACnE,IAAI,CAAC,SAAS,IAAI,CAAC,CAAC;YAEpB,MAAM,SAAS,GAAG,oBAAoB,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;YAC3F,IAAI,CAAC,SAAS;gBAAE,SAAS;YACzB,kEAAkE;YAClE,iDAAiD;YACjD,MAAM,MAAM,GAAG,qBAAqB,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,oBAAoB,EAAE,SAAS,CAAC,aAAa,CAAC,CAAC;YAC7G,MAAM,GAAG,GAAG,WAAW,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;YAC3D,IAAI,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC;gBAAE,SAAS;YAC3D,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAEvB,IAAI,IAA6B,CAAC;YAClC,IAAI,CAAC;gBACJ,IAAI,GAAG,MAAM,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;YAC3C,CAAC;YAAC,MAAM,CAAC;gBACR,uEAAuE;gBACvE,IAAI,GAAG,SAAS,CAAC;YAClB,CAAC;YACD,IAAI,CAAC,IAAI;gBAAE,SAAS;YACpB,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;QACjD,CAAC;QACD,OAAO,SAAS,CAAC;IAClB,CAAC,CAAC;AACH,CAAC","sourcesContent":["/**\n * Borrow a configured fallback model for one compaction planner request.\n *\n * This is deliberately a *weaker* capability than main-chat model fallback. The\n * borrowing door returns a `BorrowedPlanner` **value**: it holds no session\n * handle, so it cannot write `agent.state.model`, append a model-change entry,\n * change the session thinking level, refresh the system prompt, emit\n * `model_changed`/`model_select`, or call `agent.continue()`.\n * `_trySwitchToFallbackModel` does all of those and is not reused or modified.\n *\n * The attempted-key set belongs to the compaction run and is read-only here, so\n * borrowing never touches the main chat's `_fallbackAttemptedKeys`.\n */\n\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { Api, Model } from \"@earendil-works/pi-ai/compat\";\nimport { fallbackKey, resolveFallbackModel, type FallbackModelLookup } from \"../fallback-models.js\";\nimport type { BorrowedPlanner, PlannerAuth } from \"./compaction-types.js\";\nimport { resolvePlannerRequest } from \"./range-planner.js\";\n\n/**\n * Everything candidate selection needs.\n *\n * The RFC's §5.1 signature takes only `attempted` and `resolveAuth`, which\n * cannot select a candidate on its own: it names no fallback list, no model\n * registry, no preferred provider, and no inherited reasoning level. Those\n * inputs travel in this context object rather than through hidden state.\n */\nexport interface FallbackPlannerContext {\n\t/** The session's effective `fallbackModels`, in configured order. */\n\treadonly fallbackModels: readonly string[];\n\t/** Model registry used to resolve and authenticate candidates. */\n\treadonly registry: FallbackModelLookup;\n\t/** Provider preferred when an unqualified entry is ambiguous. */\n\treadonly preferredProvider: string | undefined;\n\t/** Session level inherited when a candidate carries no `:level` suffix. */\n\treadonly sessionThinkingLevel: ThinkingLevel | undefined;\n}\n\n/**\n * Identity of one planner attempt: `provider/model:<effective reasoning>`.\n *\n * The key must be derived from the *effective* level the request will carry,\n * not from the raw optional `model:level` suffix. An unsuffixed entry for the\n * session model inherits the session level, so keying it as `provider/model:`\n * would let the identical request run a second time.\n */\nexport function plannerAttemptKey(planner: BorrowedPlanner): string {\n\treturn fallbackKey(planner.model, planner.budget.reasoning);\n}\n\n/**\n * Run-local traversal state for one compaction's fallback walk.\n *\n * Kept out of the borrower's arguments and out of module scope: concurrent\n * compactions each own one of these, so nothing is shared.\n */\ninterface FallbackPlannerWalk {\n\t/** Next configured list position to inspect. Only ever advances. */\n\tnextIndex: number;\n\t/** Effective `provider/model:level` identities already inspected this run. */\n\tconsumed: Set<string>;\n}\n\n/** The exact two-argument borrowing door, bound to one run's configuration. */\nexport type BorrowFallbackPlanner = (\n\tattempted: ReadonlySet<string>,\n\tresolveAuth: (model: Model<Api>) => Promise<PlannerAuth | undefined>,\n) => Promise<BorrowedPlanner | undefined>;\n\n/**\n * Build the borrowing door for one compaction run.\n *\n * The RFC's top-level two-argument signature names no fallback list, registry,\n * preferred provider, inherited reasoning level, or traversal cursor, so a\n * stateless exported function cannot select a candidate without hidden shared\n * state — unsafe under concurrent compactions. Binding the configuration and the\n * run-local cursor in a closure keeps the returned door exactly two arguments\n * while `attempted` stays a `ReadonlySet` the borrower never writes.\n *\n * The walk is one monotonic pass. Each list position is inspected at most once,\n * whether it fails to resolve, has no usable credentials, duplicates an earlier\n * identity, or yields a planner. Without the cursor, an entry that could not\n * resolve earlier could be returned after a later candidate once the registry\n * changed, producing a B→A order the configured list never asked for.\n */\nexport function createFallbackPlannerBorrower(context: FallbackPlannerContext): BorrowFallbackPlanner {\n\tconst walk: FallbackPlannerWalk = { nextIndex: 0, consumed: new Set<string>() };\n\treturn async (attempted, resolveAuth) => {\n\t\twhile (walk.nextIndex < context.fallbackModels.length) {\n\t\t\tconst entry = context.fallbackModels[walk.nextIndex];\n\t\t\t// Advance before any work: this list position is spent either way.\n\t\t\twalk.nextIndex += 1;\n\n\t\t\tconst candidate = resolveFallbackModel(entry, context.registry, context.preferredProvider);\n\t\t\tif (!candidate) continue;\n\t\t\t// Resolve the budget first: the identity depends on the effective\n\t\t\t// reasoning level, which inheritance may supply.\n\t\t\tconst budget = resolvePlannerRequest(candidate.model, context.sessionThinkingLevel, candidate.thinkingLevel);\n\t\t\tconst key = fallbackKey(candidate.model, budget.reasoning);\n\t\t\tif (attempted.has(key) || walk.consumed.has(key)) continue;\n\t\t\twalk.consumed.add(key);\n\n\t\t\tlet auth: PlannerAuth | undefined;\n\t\t\ttry {\n\t\t\t\tauth = await resolveAuth(candidate.model);\n\t\t\t} catch {\n\t\t\t\t// A candidate whose credentials cannot be resolved is simply unusable.\n\t\t\t\tauth = undefined;\n\t\t\t}\n\t\t\tif (!auth) continue;\n\t\t\treturn { model: candidate.model, budget, auth };\n\t\t}\n\t\treturn undefined;\n\t};\n}\n"]}