@iowarp/clio-coder 0.3.3 → 0.3.4

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 (244) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/CONTRIBUTING.md +1 -1
  3. package/README.md +3 -3
  4. package/dist/{acp-P2AQILE2.js → acp-S5R4RR5B.js} +7 -6
  5. package/dist/{agents-72W3BI7I.js → agents-P6DMMVZY.js} +24 -21
  6. package/dist/assets/codewiki.json +1 -1
  7. package/dist/{auth-5TWEIYDN.js → auth-2XCZLPKS.js} +12 -8
  8. package/dist/{chunk-GGXXDWE4.js → chunk-22NAGB7X.js} +2 -2
  9. package/dist/{chunk-2DJ2KNFG.js → chunk-2LZI5CAG.js} +133 -13
  10. package/dist/{chunk-OAO4GE4M.js → chunk-2TZWSW76.js} +2 -2
  11. package/dist/{chunk-OOJYHWRB.js → chunk-34475P3I.js} +2 -2
  12. package/dist/{chunk-4XUGQOHA.js → chunk-35MKKU5R.js} +4 -4
  13. package/dist/{chunk-LM5TQCJZ.js → chunk-3HZ5RWN2.js} +5 -5
  14. package/dist/{chunk-AGYYIBLL.js → chunk-3JLKSKD7.js} +2 -2
  15. package/dist/{chunk-KZWTDYJF.js → chunk-4JUF2NNX.js} +7 -7
  16. package/dist/{chunk-ZDOOVTXZ.js → chunk-4OC57DA6.js} +27 -4
  17. package/dist/chunk-5M54SPOL.js +926 -0
  18. package/dist/{chunk-STBPMHSX.js → chunk-7RXG6QRZ.js} +51 -11
  19. package/dist/{chunk-X6IAEBZR.js → chunk-A2GZF7DC.js} +5 -5
  20. package/dist/{chunk-A3CYT5EX.js → chunk-AD2SYQYC.js} +55 -2
  21. package/dist/chunk-AOCYTWAV.js +449 -0
  22. package/dist/chunk-BEY543CS.js +258 -0
  23. package/dist/{chunk-6N5PTWMY.js → chunk-BP4OYD6A.js} +32 -13
  24. package/dist/chunk-BPGS2WCQ.js +612 -0
  25. package/dist/{chunk-V6RTAOC2.js → chunk-BRXQQJFP.js} +8 -8
  26. package/dist/chunk-CFGTUFWB.js +67 -0
  27. package/dist/{chunk-CBCAPZAA.js → chunk-E25LMLRW.js} +2 -2
  28. package/dist/{chunk-DUYJ5IO6.js → chunk-EDRHSCIE.js} +4 -4
  29. package/dist/{chunk-XBXAASKX.js → chunk-EFADSJET.js} +2 -2
  30. package/dist/{chunk-M6SHUN7Q.js → chunk-FO5ZOVUY.js} +2 -2
  31. package/dist/chunk-FYYLNIL5.js +313 -0
  32. package/dist/{chunk-FNTMWMX5.js → chunk-HV5X7OR2.js} +14 -12
  33. package/dist/{chunk-TZTZS7QK.js → chunk-HXG4IURW.js} +5 -3
  34. package/dist/{chunk-5UFT4SUX.js → chunk-K6WL7QZT.js} +3 -3
  35. package/dist/chunk-K7VKOLQQ.js +15 -0
  36. package/dist/{chunk-BMEMKKIT.js → chunk-KOHPCX4K.js} +2 -2
  37. package/dist/{chunk-OC7FIQPC.js → chunk-KRPY7NTG.js} +10 -7
  38. package/dist/chunk-LL4KHSZI.js +22 -0
  39. package/dist/{chunk-DSELYM6W.js → chunk-MEQ45TQ4.js} +15 -9
  40. package/dist/{chunk-5UUP6MWO.js → chunk-MV3K5QF2.js} +5 -436
  41. package/dist/{chunk-6SGHMWE3.js → chunk-N4CZJQRK.js} +5 -5
  42. package/dist/{chunk-TZK7PACC.js → chunk-NILBFAPG.js} +14 -8
  43. package/dist/chunk-OZNBF4L3.js +23 -0
  44. package/dist/{verify-375KUB3Y.js → chunk-PCZJO5TI.js} +127 -42
  45. package/dist/chunk-QQK64KLB.js +1360 -0
  46. package/dist/{chunk-SRDMMSEP.js → chunk-QQL5RT5M.js} +979 -1619
  47. package/dist/{chunk-LZSJBIVT.js → chunk-QWU7ZBO7.js} +70 -720
  48. package/dist/{chunk-2TLUCQVG.js → chunk-RD5U66HV.js} +3 -3
  49. package/dist/{chunk-OKGUZO2U.js → chunk-SPULKLCF.js} +4 -3
  50. package/dist/{chunk-OQ33BKR3.js → chunk-TTNYS3EA.js} +3 -60
  51. package/dist/chunk-TW3WDMVS.js +677 -0
  52. package/dist/chunk-TZSKNMZG.js +434 -0
  53. package/dist/{chunk-7MNJORFF.js → chunk-UL3WSD3F.js} +6 -1
  54. package/dist/{chunk-PIWWS5BL.js → chunk-UZHIZC5S.js} +7 -7
  55. package/dist/{chunk-UFIIWP2H.js → chunk-VAWWTKDP.js} +8 -8
  56. package/dist/{chunk-COU2UHX6.js → chunk-VEZEGCGW.js} +170 -2
  57. package/dist/{chunk-LW6DSM3M.js → chunk-VMNQ6OZA.js} +98 -202
  58. package/dist/chunk-VSNATDE6.js +122 -0
  59. package/dist/chunk-W6GROXXM.js +69 -0
  60. package/dist/chunk-WPQLXFOZ.js +375 -0
  61. package/dist/{chunk-ORBHGJC5.js → chunk-WR67VIZY.js} +3 -3
  62. package/dist/{chunk-PAJK6MAQ.js → chunk-X6COSD2O.js} +5 -5
  63. package/dist/chunk-ZGVHUX3M.js +66 -0
  64. package/dist/{chunk-LWLEKMDQ.js → chunk-ZYKPLLNQ.js} +510 -547
  65. package/dist/cli/index.js +27 -23
  66. package/dist/{clio-JOU4FXVA.js → clio-J5JIOIDS.js} +7 -6
  67. package/dist/{code-nav-7AX6FYE6.js → code-nav-AXCXSBHX.js} +5 -3
  68. package/dist/{config-XCDVKR23.js → config-OEBMIN2U.js} +37 -27
  69. package/dist/{configure-4GAP54ZW.js → configure-PUQOSIXQ.js} +16 -13
  70. package/dist/{context-5VKGUVJJ.js → context-EKDCKUUZ.js} +82 -7
  71. package/dist/{context-4UOGGLQ5.js → context-MGSE4Z2T.js} +33 -23
  72. package/dist/{context-77FM5DV5.js → context-URSXPBCK.js} +17 -9
  73. package/dist/{context-clear-XXJRLCJJ.js → context-clear-KDAJRNUK.js} +33 -23
  74. package/dist/context-working-set-SBKMPPI2.js +1552 -0
  75. package/dist/{dispatch-runner-QPRDDBDX.js → dispatch-runner-MSWN72NK.js} +43 -29
  76. package/dist/{doctor-HR46URBJ.js → doctor-7BSE27PJ.js} +10 -10
  77. package/dist/{eval-XSSNATB4.js → eval-IZGDOO4H.js} +9 -8
  78. package/dist/{evidence-6HG2PY2B.js → evidence-SR7WXB5B.js} +51 -23
  79. package/dist/{evolve-K7YU3NCY.js → evolve-K7VE2CBX.js} +30 -20
  80. package/dist/{fleet-VY3HHKN6.js → fleet-7XMJNQNF.js} +48 -38
  81. package/dist/{fleet-preflight-DDN536IT.js → fleet-preflight-AQNAH644.js} +3 -3
  82. package/dist/{init-JYGXI3FK.js → init-JGNPAYXT.js} +41 -31
  83. package/dist/{memory-WFZMGYHX.js → memory-4ALKDJ4Q.js} +32 -22
  84. package/dist/{models-I5QWSEOM.js → models-ZMMLFJNN.js} +22 -19
  85. package/dist/{monitor-GE4ID3IA.js → monitor-2F3T5KHP.js} +55 -43
  86. package/dist/{orchestrator-EM5MC3HM.js → orchestrator-ORHT43JB.js} +572 -388
  87. package/dist/{reset-L2FQEE3E.js → reset-NXGTYNUO.js} +4 -3
  88. package/dist/{run-ZU3QMZPZ.js → run-RF4WJGMT.js} +51 -41
  89. package/dist/{share-S5BZQC5I.js → share-UT3W6E4M.js} +5 -4
  90. package/dist/{skills-X5VXCRNQ.js → skills-PSACKC5Q.js} +2 -2
  91. package/dist/{skills-eval-WKIHWTHR.js → skills-eval-WJSI55RZ.js} +34 -24
  92. package/dist/{targets-SNCPI2NR.js → targets-PIIRAOYS.js} +23 -20
  93. package/dist/{terminal-lease-BNAHVHBS.js → terminal-lease-ULWXWNVY.js} +4 -3
  94. package/dist/{upgrade-JQHHPQ4K.js → upgrade-346TZ6AV.js} +18 -17
  95. package/dist/{usage-OR4O5SMZ.js → usage-6KKXR32N.js} +34 -24
  96. package/dist/verifiers-4UUM6TEE.js +1214 -0
  97. package/dist/verify-X5HDROLA.js +25 -0
  98. package/dist/{wiki-generate-UEXP2ARI.js → wiki-generate-7STOCIFZ.js} +42 -31
  99. package/dist/worker/entry.js +33 -24
  100. package/docs/README.md +7 -6
  101. package/docs/acp.md +1 -1
  102. package/docs/alcf-provider.md +1 -1
  103. package/docs/architecture.md +2 -2
  104. package/docs/artifact-versions.md +1 -1
  105. package/docs/built-in-agents.md +1 -1
  106. package/docs/capacity-and-scheduling.md +1 -1
  107. package/docs/commands-and-modes.md +53 -21
  108. package/docs/config-knobs-audit.md +1 -2
  109. package/docs/configuration-and-targets.md +15 -1
  110. package/docs/context-engine.md +64 -12
  111. package/docs/context-working-set.md +194 -0
  112. package/docs/development-pipeline.md +1 -1
  113. package/docs/documentation-coverage.md +5 -5
  114. package/docs/documentation-guide.md +6 -5
  115. package/docs/environment-variables.md +2 -1
  116. package/docs/eval-runner.md +1 -1
  117. package/docs/evals-internal.md +14 -1
  118. package/docs/evidence-and-memory.md +74 -2
  119. package/docs/evolution.md +1 -1
  120. package/docs/exit-codes-and-output.md +1 -1
  121. package/docs/extensions-and-sharing.md +2 -2
  122. package/docs/fleet-dispatch.md +22 -7
  123. package/docs/glossary.md +21 -1
  124. package/docs/installation-and-lifecycle.md +2 -2
  125. package/docs/middleware-and-components.md +1 -1
  126. package/docs/model-catalog.md +7 -9
  127. package/docs/observability.md +4 -4
  128. package/docs/proactive-memory.md +1 -1
  129. package/docs/prompt-envelope-and-tools.md +4 -4
  130. package/docs/provider-adapter-cookbook.md +1 -1
  131. package/docs/release-cut-checklist.md +31 -31
  132. package/docs/safety-model.md +23 -4
  133. package/docs/scientific-validation.md +21 -3
  134. package/docs/session-lifecycle.md +3 -3
  135. package/docs/skills-marketplace.md +1 -1
  136. package/docs/tool-usage.md +79 -12
  137. package/docs/trace-store.md +1 -1
  138. package/docs/troubleshooting.md +1 -1
  139. package/docs/tui-design.md +1 -1
  140. package/docs/worker-dispatch-mechanics.md +11 -1
  141. package/package.json +8 -11
  142. package/skills/meta/clio-test/SKILL.md +20 -17
  143. package/skills/meta/clio-test/evals.md +3 -3
  144. package/skills/meta/clio-test/references/harness.md +35 -6
  145. package/skills/meta/clio-test/references/test-map.md +20 -10
  146. package/skills/registry.yaml +2 -2
  147. package/skills/skill-marketplace.json +1 -1
  148. package/src/cli/context-working-set.ts +513 -0
  149. package/src/cli/context.ts +8 -0
  150. package/src/cli/evidence.ts +20 -2
  151. package/src/cli/index.ts +4 -0
  152. package/src/cli/verifiers.ts +325 -0
  153. package/src/core/bash-exec.ts +39 -14
  154. package/src/core/bus-events.ts +19 -4
  155. package/src/core/config.ts +54 -0
  156. package/src/core/defaults.ts +50 -3
  157. package/src/core/verification-scripts.ts +6 -0
  158. package/src/domains/agents/builtins/verifier.md +3 -0
  159. package/src/domains/config/classify.ts +1 -0
  160. package/src/domains/context/working-set/contract.ts +161 -0
  161. package/src/domains/context/working-set/defaults.ts +28 -0
  162. package/src/domains/context/working-set/engine.ts +203 -0
  163. package/src/domains/context/working-set/fold.ts +62 -0
  164. package/src/domains/context/working-set/horizon.ts +38 -0
  165. package/src/domains/context/working-set/marker.ts +103 -0
  166. package/src/domains/context/working-set/path-index.ts +436 -0
  167. package/src/domains/context/working-set/payload.ts +152 -0
  168. package/src/domains/context/working-set/policies/age-horizon.ts +55 -0
  169. package/src/domains/context/working-set/policies/index.ts +21 -0
  170. package/src/domains/context/working-set/policies/structural.ts +160 -0
  171. package/src/domains/context/working-set/project.ts +132 -0
  172. package/src/domains/context/working-set/protect.ts +109 -0
  173. package/src/domains/context/working-set/recall.ts +177 -0
  174. package/src/domains/context/working-set/replay/controls.ts +112 -0
  175. package/src/domains/context/working-set/replay/load-clio.ts +199 -0
  176. package/src/domains/context/working-set/replay/metrics.ts +185 -0
  177. package/src/domains/context/working-set/replay/reference-graph.ts +79 -0
  178. package/src/domains/context/working-set/replay/report.ts +139 -0
  179. package/src/domains/context/working-set/replay/runner.ts +325 -0
  180. package/src/domains/context/working-set/replay/synthetic.ts +422 -0
  181. package/src/domains/context/working-set/replay/trace.ts +21 -0
  182. package/src/domains/context/working-set/visible.ts +54 -0
  183. package/src/domains/evidence/build.ts +112 -45
  184. package/src/domains/evidence/eval.ts +24 -7
  185. package/src/domains/evidence/index.ts +53 -0
  186. package/src/domains/evidence/ordering.ts +12 -0
  187. package/src/domains/evidence/run-trust.ts +221 -0
  188. package/src/domains/evidence/store.ts +46 -6
  189. package/src/domains/evidence/trust-status.ts +854 -0
  190. package/src/domains/evidence/types.ts +26 -0
  191. package/src/domains/middleware/memory-intervention.ts +3 -0
  192. package/src/domains/middleware/stalled-turn.ts +165 -4
  193. package/src/domains/safety/autonomy.ts +1 -1
  194. package/src/domains/safety/default-path-policy.ts +8 -0
  195. package/src/domains/safety/finish-contract.ts +4 -3
  196. package/src/domains/safety/policy-engine.ts +48 -6
  197. package/src/domains/session/compaction/compact.ts +23 -1
  198. package/src/domains/session/compaction/cut-point.ts +2 -0
  199. package/src/domains/session/compaction/tokens.ts +16 -1
  200. package/src/domains/session/context-ledger.ts +2 -0
  201. package/src/domains/session/entries.ts +107 -1
  202. package/src/domains/session/manager.ts +9 -2
  203. package/src/domains/session/migrations/index.ts +22 -3
  204. package/src/engine/acp/server.ts +3 -0
  205. package/src/engine/agent.ts +18 -1
  206. package/src/engine/session.ts +9 -3
  207. package/src/entry/orchestrator.ts +16 -4
  208. package/src/interactive/chat-loop-messages.ts +18 -6
  209. package/src/interactive/chat-panel.ts +17 -1
  210. package/src/interactive/chat-renderer.ts +30 -21
  211. package/src/interactive/context-meter.ts +10 -0
  212. package/src/interactive/context-overlay.ts +81 -6
  213. package/src/interactive/context-recall-command.ts +110 -0
  214. package/src/interactive/interactive-slash-runtime.ts +37 -1
  215. package/src/interactive/model-session-replay.ts +21 -0
  216. package/src/interactive/overlay-general-openers.ts +6 -0
  217. package/src/interactive/overlay-session-lifecycle.ts +8 -4
  218. package/src/interactive/renderers/tool-execution.ts +18 -2
  219. package/src/interactive/session-transcript.ts +2 -2
  220. package/src/interactive/slash-commands.ts +29 -2
  221. package/src/interactive/turn-context.ts +238 -88
  222. package/src/interactive/turn-middleware.ts +6 -6
  223. package/src/tools/agent-tools.ts +11 -4
  224. package/src/tools/bash.ts +144 -82
  225. package/src/tools/builtin-tool-catalog.ts +11 -5
  226. package/src/tools/context/index.ts +105 -3
  227. package/src/tools/context/surface.ts +3 -2
  228. package/src/tools/core-bootstrap.ts +21 -0
  229. package/src/tools/dispatch-runner.ts +9 -7
  230. package/src/tools/monitor.ts +28 -20
  231. package/src/tools/registry.ts +59 -7
  232. package/src/tools/result-disposition.ts +550 -0
  233. package/src/tools/result-shaping.ts +262 -19
  234. package/src/tools/safe-exec.ts +2 -0
  235. package/src/tools/verify/authoring.ts +1119 -0
  236. package/src/tools/verify/catalog.ts +346 -0
  237. package/src/tools/verify/index.ts +13 -3
  238. package/src/tools/verify/scripts.ts +135 -37
  239. package/src/tools/verify/surface.ts +9 -5
  240. package/src/tools/worker-evidence.ts +35 -12
  241. package/dist/chunk-J7CWMCQD.js +0 -255
  242. package/dist/chunk-T6YILFSB.js +0 -80
  243. package/dist/chunk-VAKQQHWR.js +0 -434
  244. package/dist/chunk-VPAYEGVX.js +0 -184
@@ -1,10 +1,27 @@
1
1
  import { createRequire as __clioCreateRequire } from "node:module"; const require = __clioCreateRequire(import.meta.url);
2
+ import {
3
+ ShareDomainModule
4
+ } from "./chunk-WR67VIZY.js";
2
5
  import {
3
6
  bootstrapInputFromInitOptions,
4
7
  modelBootstrapGenerate,
5
8
  resolveBootstrapRoute
6
- } from "./chunk-FNTMWMX5.js";
9
+ } from "./chunk-HV5X7OR2.js";
7
10
  import "./chunk-J5Q24KAG.js";
11
+ import {
12
+ DEFAULT_KEEP_RECENT_TOKENS,
13
+ DEFAULT_RESERVE_TOKENS,
14
+ buildEvictionFields,
15
+ calculateContextTokens,
16
+ compactionCut,
17
+ estimateTokens,
18
+ findCutPoint,
19
+ getLastAssistantUsage,
20
+ planEviction,
21
+ projectWorkingSet,
22
+ resolveWorkingSetPolicy,
23
+ selectVisibleEntries
24
+ } from "./chunk-TW3WDMVS.js";
8
25
  import {
9
26
  assistantSessionPayload,
10
27
  backendCacheVerdict,
@@ -37,37 +54,34 @@ import {
37
54
  toolNamesFromAgentState,
38
55
  toolResultSummary,
39
56
  toolSignatureFromState
40
- } from "./chunk-DSELYM6W.js";
57
+ } from "./chunk-MEQ45TQ4.js";
41
58
  import {
42
59
  SchedulingDomainModule,
43
60
  createPromptsDomainModule,
44
61
  renderAgentCatalogSectionsFromSpecs
45
- } from "./chunk-LM5TQCJZ.js";
46
- import {
47
- ShareDomainModule
48
- } from "./chunk-ORBHGJC5.js";
62
+ } from "./chunk-3HZ5RWN2.js";
49
63
  import {
50
64
  AgentsDomainModule,
51
65
  SafetyDomainModule
52
- } from "./chunk-PAJK6MAQ.js";
66
+ } from "./chunk-X6COSD2O.js";
53
67
  import {
54
68
  LifecycleDomainModule,
55
69
  describeUpgradeNotice
56
- } from "./chunk-5UFT4SUX.js";
70
+ } from "./chunk-K6WL7QZT.js";
71
+ import {
72
+ ensureClioState,
73
+ takeUpgradeNotice
74
+ } from "./chunk-VAWWTKDP.js";
57
75
  import {
58
76
  ConfigDomainModule,
59
77
  createConfigDomainModule,
60
78
  loadDomains
61
- } from "./chunk-OC7FIQPC.js";
62
- import {
63
- ensureClioState,
64
- takeUpgradeNotice
65
- } from "./chunk-UFIIWP2H.js";
79
+ } from "./chunk-KRPY7NTG.js";
66
80
  import {
67
81
  compileScoutTransition,
68
82
  createDispatchRunEventRegistry
69
- } from "./chunk-6SGHMWE3.js";
70
- import "./chunk-XBXAASKX.js";
83
+ } from "./chunk-N4CZJQRK.js";
84
+ import "./chunk-EFADSJET.js";
71
85
  import {
72
86
  monitorToolSurface
73
87
  } from "./chunk-FJ3H4MN5.js";
@@ -78,7 +92,7 @@ import {
78
92
  costAggregateForAmount,
79
93
  formatCostAggregate,
80
94
  readAccountabilitySummary
81
- } from "./chunk-4XUGQOHA.js";
95
+ } from "./chunk-35MKKU5R.js";
82
96
  import "./chunk-HC4CLZ2Y.js";
83
97
  import "./chunk-HFSBBKSQ.js";
84
98
  import {
@@ -88,11 +102,11 @@ import {
88
102
  flushRawStdout,
89
103
  writeRawStdout
90
104
  } from "./chunk-2VTFPG5O.js";
91
- import "./chunk-CBCAPZAA.js";
105
+ import "./chunk-E25LMLRW.js";
92
106
  import {
93
107
  createContextDomainModule,
94
108
  loadProjectClioMd
95
- } from "./chunk-PIWWS5BL.js";
109
+ } from "./chunk-UZHIZC5S.js";
96
110
  import {
97
111
  renderCodewikiDigest
98
112
  } from "./chunk-5WIGXA4T.js";
@@ -107,7 +121,7 @@ import {
107
121
  taskMemoryBankSize,
108
122
  taskMemoryHandoffSeedOffer,
109
123
  taskMemoryTracePath
110
- } from "./chunk-V6RTAOC2.js";
124
+ } from "./chunk-BRXQQJFP.js";
111
125
  import {
112
126
  ACP_MAX_CHUNK_BYTES,
113
127
  ACP_MAX_RAW_RECORD_BYTES,
@@ -118,31 +132,31 @@ import {
118
132
  ACP_USAGE_META_KEY,
119
133
  AcpRequestError,
120
134
  AcpTimeoutError,
121
- SessionDomainModule,
122
135
  WORKER_OUTPUT_MAX_BYTES,
123
136
  acpErrorMessage,
124
- collectSessionEntries,
125
137
  createDispatchDomainModule,
126
138
  createRunReceiptQuality,
127
139
  createStdioServerTransport,
128
140
  durableAssistantTextFromEvent,
129
141
  evidenceDirectory,
130
- filterEntriesToActivePath,
131
142
  inspectEvidence,
132
143
  isGitRepository,
133
- ledgerUsageCalls,
134
144
  listEvidenceOverviews,
135
145
  openLedger,
136
- protectedArtifactEntryFromArtifact,
137
- protectedArtifactStateFromSessionEntries,
138
146
  protectedResidencyModels,
139
- readAuditRows,
140
147
  readGateDecisionArtifacts,
141
148
  readPendingGateDecisions,
142
149
  recoverCleanupReadyCompeteGroups,
143
150
  requireAgentSteps
144
- } from "./chunk-SRDMMSEP.js";
145
- import "./chunk-4BJ5BYCE.js";
151
+ } from "./chunk-QQL5RT5M.js";
152
+ import {
153
+ SessionDomainModule,
154
+ collectSessionEntries,
155
+ ledgerUsageCalls,
156
+ protectedArtifactEntryFromArtifact,
157
+ protectedArtifactStateFromSessionEntries,
158
+ readAuditRows
159
+ } from "./chunk-QQK64KLB.js";
146
160
  import {
147
161
  parseRigorOverride,
148
162
  resolveRigor
@@ -150,8 +164,8 @@ import {
150
164
  import {
151
165
  isReceiptIntegrity,
152
166
  verifyReceiptIntegrity
153
- } from "./chunk-AGYYIBLL.js";
154
- import "./chunk-OOJYHWRB.js";
167
+ } from "./chunk-3JLKSKD7.js";
168
+ import "./chunk-34475P3I.js";
155
169
  import {
156
170
  shellQuote
157
171
  } from "./chunk-TXOTCRLG.js";
@@ -167,6 +181,16 @@ import {
167
181
  wikiStalenessAsync
168
182
  } from "./chunk-X4RCMKVQ.js";
169
183
  import "./chunk-MVVUPGPW.js";
184
+ import {
185
+ buildRecallFields,
186
+ recallErrorMessage,
187
+ recallParentTurnId,
188
+ recallableRefListing,
189
+ resolveRecall
190
+ } from "./chunk-VSNATDE6.js";
191
+ import {
192
+ foldWorkingSet
193
+ } from "./chunk-TZSKNMZG.js";
170
194
  import {
171
195
  createResourcesDomainModule
172
196
  } from "./chunk-MFFY33HR.js";
@@ -182,6 +206,9 @@ import "./chunk-2SFS6XQE.js";
182
206
  import {
183
207
  ExtensionsDomainModule
184
208
  } from "./chunk-ZWLZP4ZT.js";
209
+ import {
210
+ filterEntriesToActivePath
211
+ } from "./chunk-W6GROXXM.js";
185
212
  import {
186
213
  formatBootTrace,
187
214
  traceBoot
@@ -209,12 +236,10 @@ import {
209
236
  resolveSessionTools,
210
237
  sanitizeCallTargetText,
211
238
  sanitizeLockedSynthesisMessage
212
- } from "./chunk-LW6DSM3M.js";
239
+ } from "./chunk-VMNQ6OZA.js";
213
240
  import {
214
- HEADLESS_PERMISSION_DENIED_REASON,
215
- combineBashOutput,
216
- runBashCommand
217
- } from "./chunk-J7CWMCQD.js";
241
+ HEADLESS_PERMISSION_DENIED_REASON
242
+ } from "./chunk-K7VKOLQQ.js";
218
243
  import {
219
244
  MIDDLEWARE_HOOK_TEXT_MAX_CHARS,
220
245
  MiddlewareDomainModule,
@@ -230,7 +255,7 @@ import {
230
255
  installUserHooks,
231
256
  openDetachedBatchViews,
232
257
  writeMiddlewareDiagnosticToStderr
233
- } from "./chunk-2DJ2KNFG.js";
258
+ } from "./chunk-2LZI5CAG.js";
234
259
  import "./chunk-IR4CFBFN.js";
235
260
  import "./chunk-UOV2BYIW.js";
236
261
  import {
@@ -244,11 +269,11 @@ import {
244
269
  stringArg,
245
270
  timeoutMsArg,
246
271
  withResolvedDispatchPlan
247
- } from "./chunk-DUYJ5IO6.js";
272
+ } from "./chunk-EDRHSCIE.js";
248
273
  import {
249
274
  TaskMemoryBank,
250
275
  createTaskMemoryTelemetrySink
251
- } from "./chunk-OAO4GE4M.js";
276
+ } from "./chunk-2TZWSW76.js";
252
277
  import {
253
278
  DISPATCH_BRIEFING_MAX_BYTES,
254
279
  JUDGE_GATE_PROMPT,
@@ -257,53 +282,64 @@ import {
257
282
  approvedRouteCandidates,
258
283
  builtin,
259
284
  classifyResourceRead,
260
- createTaskBoardStore,
261
- foldSessionTaskHistory,
285
+ combineBashOutput,
262
286
  isToolProfileName,
287
+ runBashCommand,
263
288
  runKindSupportsLiveSteering,
264
- taskBoardCounts,
265
289
  toolPresentationPolicy
266
- } from "./chunk-LWLEKMDQ.js";
290
+ } from "./chunk-ZYKPLLNQ.js";
291
+ import {
292
+ createTaskBoardStore,
293
+ foldSessionTaskHistory,
294
+ taskBoardCounts
295
+ } from "./chunk-WPQLXFOZ.js";
267
296
  import {
268
297
  DEFAULT_AUTONOMY_LEVEL,
269
298
  DEFAULT_RECENT_ENTRY_LIMIT,
270
299
  assessFinishContract,
271
300
  parseScoutResult,
272
301
  resultContractSourceId
273
- } from "./chunk-STBPMHSX.js";
302
+ } from "./chunk-7RXG6QRZ.js";
274
303
  import {
275
304
  agentRoleFactsResolver,
276
305
  defaultRoutingIntent,
277
306
  gateDeciderAgentId,
278
307
  requestExecutionRole,
279
308
  sameRouteIdentity
280
- } from "./chunk-GGXXDWE4.js";
309
+ } from "./chunk-22NAGB7X.js";
310
+ import "./chunk-AOCYTWAV.js";
281
311
  import {
282
312
  CLIO_PROJECT_DIR,
283
313
  toolMutationPaths
284
- } from "./chunk-5UUP6MWO.js";
314
+ } from "./chunk-MV3K5QF2.js";
285
315
  import "./chunk-CMZWFGD2.js";
286
316
  import "./chunk-I4HZDVNP.js";
287
317
  import "./chunk-ZI647VB5.js";
288
- import "./chunk-TZK7PACC.js";
318
+ import "./chunk-NILBFAPG.js";
319
+ import "./chunk-FYYLNIL5.js";
289
320
  import {
290
321
  VERIFICATION_SCRIPT_FAMILY_HINT
291
- } from "./chunk-7MNJORFF.js";
322
+ } from "./chunk-UL3WSD3F.js";
292
323
  import "./chunk-XN3L4EYL.js";
293
324
  import {
294
325
  escapeRegExp
295
326
  } from "./chunk-VG7TBQIY.js";
296
327
  import "./chunk-OQE5J4C6.js";
297
328
  import "./chunk-ECH6PKUQ.js";
298
- import "./chunk-OKGUZO2U.js";
329
+ import "./chunk-SPULKLCF.js";
299
330
  import {
300
331
  SKILL_SUGGESTION_PREFIX,
301
332
  isSkillActivation,
302
333
  skillActivationFromToolDetails
303
- } from "./chunk-T6YILFSB.js";
334
+ } from "./chunk-BEY543CS.js";
335
+ import {
336
+ toolResultPresentationPolicy,
337
+ toolResultPresentationText
338
+ } from "./chunk-5M54SPOL.js";
304
339
  import {
305
340
  formatSize
306
- } from "./chunk-VAKQQHWR.js";
341
+ } from "./chunk-OZNBF4L3.js";
342
+ import "./chunk-4BJ5BYCE.js";
307
343
  import {
308
344
  truncateUtf8
309
345
  } from "./chunk-6XLNIQDB.js";
@@ -332,38 +368,23 @@ import {
332
368
  InteropDomainModule,
333
369
  delegationEntryForKind,
334
370
  renderProposalEntry
335
- } from "./chunk-2TLUCQVG.js";
336
- import "./chunk-BMEMKKIT.js";
371
+ } from "./chunk-RD5U66HV.js";
372
+ import "./chunk-KOHPCX4K.js";
337
373
  import {
338
374
  source_default
339
375
  } from "./chunk-5TSRNF4G.js";
340
376
  import {
341
377
  AGENT_ROLE_TOOLS_REQUIRED_REASON,
342
- AutoCompactionTrigger,
343
- DEFAULT_COMPACTION_THRESHOLD,
344
378
  ProvidersDomainModule,
345
379
  VALID_THINKING_LEVELS,
346
- appendContextSnapshot,
347
380
  applyModelCapabilityPatch,
348
- buildContextLedger,
349
- captureContextSnapshot,
350
- ceilChars,
351
- contentChars,
352
- contextUsageSnapshot,
353
- estimateAgentContextBreakdown,
354
- estimateAgentContextTokens,
355
- estimateAgentMessageTokens,
356
- estimateReasoningTextTokens,
357
- extractReasoningTokens,
358
381
  firstRuntimeResolutionError,
359
- getLatestContextSnapshot,
360
382
  getRuntimeRegistry,
361
383
  isDispatchEligibleRuntime,
362
384
  isOrchestratorEligibleRuntime,
363
385
  modelCandidatesForStatus,
364
386
  modelIdsForStatus,
365
387
  modelResidencyForStatus,
366
- reconcileSnapshot,
367
388
  refineRuntimeTargetWithModelHints,
368
389
  registerBuiltinRuntimes,
369
390
  resolveModelCapabilities,
@@ -375,13 +396,12 @@ import {
375
396
  runtimeResolutionWarnings,
376
397
  runtimeTargetSnapshot,
377
398
  setProtectedModelsProvider,
378
- shouldCompact,
379
- snapshotInputTokens,
380
399
  supportsAgentRoleTools,
381
400
  thinkingLevelChoiceLabel,
382
401
  thinkingLevelFromChoiceLabel,
383
402
  withRunOverrides
384
- } from "./chunk-LZSJBIVT.js";
403
+ } from "./chunk-QWU7ZBO7.js";
404
+ import "./chunk-CFGTUFWB.js";
385
405
  import {
386
406
  bindAgentProfileInSettings,
387
407
  readSettings,
@@ -390,28 +410,19 @@ import {
390
410
  setFleetProfileInSettings,
391
411
  updateSettings,
392
412
  useTargetInSettings
393
- } from "./chunk-A3CYT5EX.js";
413
+ } from "./chunk-AD2SYQYC.js";
394
414
  import {
395
415
  DEFAULT_DELEGATION_PERMISSION_TIMEOUT_MS,
396
416
  DEFAULT_SETTINGS,
397
417
  THINKING_LEVELS
398
- } from "./chunk-ZDOOVTXZ.js";
418
+ } from "./chunk-4OC57DA6.js";
419
+ import "./chunk-LL4KHSZI.js";
399
420
  import {
400
421
  targetRequiresAuth
401
422
  } from "./chunk-4VP4KH3K.js";
402
- import {
403
- atomicWrite,
404
- cwdHash,
405
- openSession,
406
- readSessionTailTurns,
407
- sessionCurrentPath,
408
- sessionPaths
409
- } from "./chunk-M6SHUN7Q.js";
410
- import "./chunk-R346GLFC.js";
411
- import "./chunk-VPAYEGVX.js";
412
423
  import {
413
424
  setGitCommitAttributionEnabled
414
- } from "./chunk-COU2UHX6.js";
425
+ } from "./chunk-VEZEGCGW.js";
415
426
  import {
416
427
  MAX_TIMER_DELAY_MS,
417
428
  rawDurationMs
@@ -421,11 +432,37 @@ import "./chunk-3I7MS7N2.js";
421
432
  import {
422
433
  interopAgentKind
423
434
  } from "./chunk-IHXBNWMM.js";
435
+ import {
436
+ AutoCompactionTrigger,
437
+ DEFAULT_COMPACTION_THRESHOLD,
438
+ appendContextSnapshot,
439
+ buildContextLedger,
440
+ captureContextSnapshot,
441
+ ceilChars,
442
+ contentChars,
443
+ contextUsageSnapshot,
444
+ estimateAgentContextBreakdown,
445
+ estimateAgentContextTokens,
446
+ estimateReasoningTextTokens,
447
+ extractReasoningTokens,
448
+ getLatestContextSnapshot,
449
+ reconcileSnapshot,
450
+ shouldCompact,
451
+ snapshotInputTokens
452
+ } from "./chunk-BPGS2WCQ.js";
424
453
  import "./chunk-SST6Z5JA.js";
454
+ import {
455
+ atomicWrite,
456
+ cwdHash,
457
+ openSession,
458
+ readSessionTailTurns,
459
+ sessionCurrentPath,
460
+ sessionPaths
461
+ } from "./chunk-FO5ZOVUY.js";
462
+ import "./chunk-R346GLFC.js";
425
463
  import {
426
464
  configureGuardrails
427
465
  } from "./chunk-4ZG3XFUR.js";
428
- import "./chunk-APJ265NV.js";
429
466
  import {
430
467
  StringEnum,
431
468
  cleanupEngineSessionResources,
@@ -433,6 +470,7 @@ import {
433
470
  isEngineRetryableAssistantError,
434
471
  stream
435
472
  } from "./chunk-FCSXB6T2.js";
473
+ import "./chunk-APJ265NV.js";
436
474
  import "./chunk-YXLYO42X.js";
437
475
  import {
438
476
  clioConfigDir,
@@ -503,12 +541,14 @@ import {
503
541
  } from "./chunk-ZWMF7253.js";
504
542
  import {
505
543
  getTerminationCoordinator
506
- } from "./chunk-TZTZS7QK.js";
544
+ } from "./chunk-HXG4IURW.js";
545
+ import {
546
+ getSharedBus
547
+ } from "./chunk-ZGVHUX3M.js";
507
548
  import {
508
549
  BusChannels,
509
- getSharedBus,
510
550
  isRunAbortedPayload
511
- } from "./chunk-OQ33BKR3.js";
551
+ } from "./chunk-TTNYS3EA.js";
512
552
  import "./chunk-JVCV3ICN.js";
513
553
  import "./chunk-7CR24IG7.js";
514
554
  import {
@@ -1509,190 +1549,6 @@ ${truncate(entry.output, TOOL_RESULT_MAX_CHARS)}`);
1509
1549
  return parts.join("\n\n");
1510
1550
  }
1511
1551
 
1512
- // src/domains/session/compaction/cut-point.ts
1513
- init_esm_shims();
1514
-
1515
- // src/domains/session/compaction/tokens.ts
1516
- init_esm_shims();
1517
- function estimateMessage(entry) {
1518
- return estimateAgentMessageTokens(entry);
1519
- }
1520
- function estimateBashExecution(entry) {
1521
- return ceilChars(entry.command.length + entry.output.length);
1522
- }
1523
- function estimateCustom(entry) {
1524
- if (entry.data === void 0) return 0;
1525
- return ceilChars(contentChars(entry.data));
1526
- }
1527
- function estimateSummary(entry) {
1528
- return ceilChars(entry.summary.length);
1529
- }
1530
- function estimateTokens(entry) {
1531
- switch (entry.kind) {
1532
- case "message":
1533
- return estimateMessage(entry);
1534
- case "bashExecution":
1535
- return estimateBashExecution(entry);
1536
- case "custom":
1537
- return estimateCustom(entry);
1538
- case "skillActivation":
1539
- return ceilChars(JSON.stringify(entry.activation).length);
1540
- case "branchSummary":
1541
- case "compactionSummary":
1542
- return estimateSummary(entry);
1543
- case "modelChange":
1544
- case "thinkingLevelChange":
1545
- case "fileEntry":
1546
- case "sessionInfo":
1547
- case "label":
1548
- case "protectedArtifact":
1549
- case "taskLedger":
1550
- case "decisionLedger":
1551
- case "workerRun":
1552
- return 0;
1553
- }
1554
- }
1555
- function usageTotalTokens(usage) {
1556
- return usage.totalTokens || usage.input + usage.output + usage.cacheRead + usage.cacheWrite;
1557
- }
1558
- function extractUsage(payload) {
1559
- if (!payload || typeof payload !== "object") return void 0;
1560
- const p = payload;
1561
- if (p.contextUsageInvalidated === true) return void 0;
1562
- if (p.stopReason === "aborted" || p.stopReason === "error") return void 0;
1563
- const u = p.usage;
1564
- if (!u || typeof u !== "object") return void 0;
1565
- const usage = u;
1566
- if (typeof usage.input !== "number" || typeof usage.output !== "number") return void 0;
1567
- return usage;
1568
- }
1569
- function getLastAssistantUsage(entries) {
1570
- for (let i = entries.length - 1; i >= 0; i--) {
1571
- const entry = entries[i];
1572
- if (entry?.kind !== "message" || entry?.role !== "assistant") continue;
1573
- const usage = extractUsage(entry.payload);
1574
- if (usage) return usage;
1575
- }
1576
- return void 0;
1577
- }
1578
- function findLastAssistantUsageIndex(entries) {
1579
- for (let i = entries.length - 1; i >= 0; i--) {
1580
- const entry = entries[i];
1581
- if (entry?.kind !== "message" || entry?.role !== "assistant") continue;
1582
- if (extractUsage(entry.payload)) return i;
1583
- }
1584
- return -1;
1585
- }
1586
- function calculateContextTokens(entries, lastUsage) {
1587
- const usage = lastUsage ?? getLastAssistantUsage(entries);
1588
- if (usage) {
1589
- const anchorTokens = usageTotalTokens(usage);
1590
- const anchorIndex = findLastAssistantUsageIndex(entries);
1591
- let trailing = 0;
1592
- for (let i = anchorIndex + 1; i < entries.length; i++) {
1593
- const entry = entries[i];
1594
- if (entry) trailing += estimateTokens(entry);
1595
- }
1596
- return anchorTokens + trailing;
1597
- }
1598
- let total = 0;
1599
- for (const entry of entries) total += estimateTokens(entry);
1600
- return total;
1601
- }
1602
-
1603
- // src/domains/session/compaction/cut-point.ts
1604
- function findTurnStartIndex(entries, entryIndex, startIndex = 0) {
1605
- for (let i = entryIndex; i >= startIndex; i--) {
1606
- const entry = entries[i];
1607
- if (!entry) continue;
1608
- if (entry.kind === "branchSummary") return i;
1609
- if (entry.kind === "bashExecution") return i;
1610
- if (entry.kind === "message" && entry.role === "user") return i;
1611
- }
1612
- return -1;
1613
- }
1614
- function isValidCutPoint(entry) {
1615
- switch (entry.kind) {
1616
- case "message":
1617
- return entry.role !== "tool_result";
1618
- case "bashExecution":
1619
- case "custom":
1620
- case "skillActivation":
1621
- case "branchSummary":
1622
- case "compactionSummary":
1623
- return true;
1624
- case "modelChange":
1625
- case "thinkingLevelChange":
1626
- case "fileEntry":
1627
- case "sessionInfo":
1628
- case "label":
1629
- case "protectedArtifact":
1630
- case "taskLedger":
1631
- case "decisionLedger":
1632
- case "workerRun":
1633
- return false;
1634
- }
1635
- }
1636
- function findValidCutPoints(entries, startIndex, endIndex) {
1637
- const cuts = [];
1638
- for (let i = startIndex; i < endIndex; i++) {
1639
- const entry = entries[i];
1640
- if (!entry) continue;
1641
- if (isValidCutPoint(entry)) cuts.push(i);
1642
- }
1643
- return cuts;
1644
- }
1645
- function findCutPoint(entries, keepRecentTokens, opts = {}) {
1646
- const startIndex = opts.startIndex ?? 0;
1647
- const endIndex = opts.endIndex ?? entries.length;
1648
- const cutPoints = findValidCutPoints(entries, startIndex, endIndex);
1649
- if (cutPoints.length === 0) {
1650
- return { firstKeptEntryIndex: startIndex, turnStartIndex: -1, isSplitTurn: false };
1651
- }
1652
- let accumulated = 0;
1653
- let cutIndex = -1;
1654
- for (let i = endIndex - 1; i >= startIndex; i--) {
1655
- const entry = entries[i];
1656
- if (!entry) continue;
1657
- accumulated += estimateTokens(entry);
1658
- if (accumulated >= keepRecentTokens) {
1659
- for (const candidate of cutPoints) {
1660
- if (candidate >= i) {
1661
- cutIndex = candidate;
1662
- break;
1663
- }
1664
- }
1665
- break;
1666
- }
1667
- }
1668
- if (cutIndex === -1) {
1669
- const lastTurnStart = findTurnStartIndex(entries, endIndex - 1, startIndex);
1670
- cutIndex = lastTurnStart !== -1 ? lastTurnStart : cutPoints[0] ?? startIndex;
1671
- }
1672
- while (cutIndex > startIndex) {
1673
- const prev = entries[cutIndex - 1];
1674
- if (!prev) break;
1675
- if (prev.kind === "compactionSummary") break;
1676
- if (prev.kind === "message" || prev.kind === "bashExecution" || prev.kind === "custom" || prev.kind === "skillActivation" || prev.kind === "branchSummary") {
1677
- break;
1678
- }
1679
- cutIndex--;
1680
- }
1681
- const cutEntry = entries[cutIndex];
1682
- const cutIsUserTurn = !!cutEntry && cutEntry.kind === "message" && cutEntry.role === "user";
1683
- const turnStartIndex = cutIsUserTurn ? -1 : findTurnStartIndex(entries, cutIndex, startIndex);
1684
- return {
1685
- firstKeptEntryIndex: cutIndex,
1686
- turnStartIndex,
1687
- isSplitTurn: !cutIsUserTurn && turnStartIndex !== -1
1688
- };
1689
- }
1690
-
1691
- // src/domains/session/compaction/defaults.ts
1692
- init_esm_shims();
1693
- var DEFAULT_RESERVE_TOKENS = 16384;
1694
- var DEFAULT_KEEP_RECENT_TOKENS = 2e4;
1695
-
1696
1552
  // src/domains/session/compaction/compact.ts
1697
1553
  var COMPACTION_SYSTEM_PROMPT = [
1698
1554
  "You are a context summarization assistant.",
@@ -1903,6 +1759,26 @@ ${modified.join("\n")}
1903
1759
 
1904
1760
  ${sections.join("\n\n")}` : "";
1905
1761
  }
1762
+ function formatRecallableRefs(entries, firstKeptEntryIndex) {
1763
+ const entryIndexes = /* @__PURE__ */ new Map();
1764
+ for (let index = 0; index < entries.length; index += 1) {
1765
+ const entry = entries[index];
1766
+ if (entry) entryIndexes.set(entry.turnId, index);
1767
+ }
1768
+ const view = foldWorkingSet(entries);
1769
+ const evictedBeforeCut = new Map(
1770
+ [...view.evicted].filter(([ref]) => (entryIndexes.get(ref) ?? Number.POSITIVE_INFINITY) < firstKeptEntryIndex)
1771
+ );
1772
+ const listing = recallableRefListing(entries, { ...view, evicted: evictedBeforeCut });
1773
+ if (listing.refs.length === 0) return "";
1774
+ const rows = [...listing.refs];
1775
+ if (listing.remaining > 0) rows.push(`and ${listing.remaining} more`);
1776
+ return `
1777
+
1778
+ <recallable-refs>
1779
+ ${rows.join("\n")}
1780
+ </recallable-refs>`;
1781
+ }
1906
1782
  function numberOrZero(value) {
1907
1783
  return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : 0;
1908
1784
  }
@@ -2016,7 +1892,10 @@ async function compact(input) {
2016
1892
  ${prefixSummary.text}`);
2017
1893
  }
2018
1894
  }
2019
- const summary = `${summaryParts.join("\n\n---\n\n").trim()}${formatFileOperations(fileOps)}`.trim();
1895
+ const summary = `${summaryParts.join("\n\n---\n\n").trim()}${formatFileOperations(fileOps)}${formatRecallableRefs(
1896
+ input.entries,
1897
+ cut.firstKeptEntryIndex
1898
+ )}`.trim();
2020
1899
  return {
2021
1900
  summary,
2022
1901
  firstKeptEntryIndex: cut.firstKeptEntryIndex,
@@ -2790,6 +2669,8 @@ function applyStopReason(active, message) {
2790
2669
  function outputText(value) {
2791
2670
  if (typeof value === "string") return value;
2792
2671
  if (!isRecord3(value)) return "";
2672
+ const presentationText = toolResultPresentationText(value);
2673
+ if (presentationText !== null) return presentationText;
2793
2674
  if (Array.isArray(value.content)) return contentText(value.content);
2794
2675
  if (typeof value.output === "string") return value.output;
2795
2676
  if (typeof value.text === "string") return value.text;
@@ -4469,6 +4350,9 @@ function readPromptCompileManifest(meta, stateDir) {
4469
4350
  }
4470
4351
  }
4471
4352
 
4353
+ // src/interactive/model-session-replay.ts
4354
+ init_esm_shims();
4355
+
4472
4356
  // src/interactive/chat-renderer.ts
4473
4357
  init_esm_shims();
4474
4358
 
@@ -5056,6 +4940,7 @@ function ledgerTail(finished) {
5056
4940
  if (details?.outputCapped === true) parts.push("output capped");
5057
4941
  }
5058
4942
  if (finished.excludeFromContext === true) parts.push("excluded from context");
4943
+ if (finished.evictedReason !== void 0) parts.push("evicted", finished.evictedReason);
5059
4944
  const offloadPath = executed ? offloadPathOf(finished) : null;
5060
4945
  return {
5061
4946
  facts: parts.length > 0 ? dim(` \xB7 ${parts.join(" \xB7 ")}`) : "",
@@ -5064,7 +4949,8 @@ function ledgerTail(finished) {
5064
4949
  }
5065
4950
  var FAILURE_EXCERPT_LIMIT = 80;
5066
4951
  function failureExcerpt(finished, width) {
5067
- if (!finished.isError || !toolPresentationPolicy(finished.toolName, finished.args).failureExcerpt) return "";
4952
+ const presentation = toolResultPresentationPolicy(finished.result) ?? toolPresentationPolicy(finished.toolName, finished.args);
4953
+ if (!finished.isError || !presentation.failureExcerpt) return "";
5068
4954
  if (isNonExecutedOutcome(finished.outcome)) return "";
5069
4955
  const text = unwrapResultEnvelope(finished.result);
5070
4956
  if (typeof text !== "string") return "";
@@ -5321,6 +5207,8 @@ function renderArgsBody(toolName2, args, width, isError) {
5321
5207
  }
5322
5208
  function unwrapResultEnvelope(result) {
5323
5209
  if (typeof result === "string" || result === null || result === void 0) return result;
5210
+ const presentationText = toolResultPresentationText(result);
5211
+ if (presentationText !== null) return presentationText;
5324
5212
  const blocks = Array.isArray(result) ? result : isPlainObject(result) && Array.isArray(result.content) ? result.content : null;
5325
5213
  if (blocks === null) return result;
5326
5214
  const parts = [];
@@ -5453,6 +5341,7 @@ function outputFacts(finished) {
5453
5341
  }
5454
5342
  if (isPlainObject(finished.result) && finished.result.terminate === true) parts.push("terminal result");
5455
5343
  if (finished.excludeFromContext === true) parts.push("excluded from context");
5344
+ if (finished.evictedReason !== void 0) parts.push("evicted", finished.evictedReason);
5456
5345
  return parts;
5457
5346
  }
5458
5347
  function renderOutputMeta(finished, width, isError, label = "output") {
@@ -5511,7 +5400,8 @@ function sublineStatus(call) {
5511
5400
  function foldedDiffRows(finished, width, opts) {
5512
5401
  if (opts.foldedExtras === "none") return [];
5513
5402
  if (finished.isError || isNonExecutedOutcome(finished.outcome)) return [];
5514
- if (!toolPresentationPolicy(finished.toolName, finished.args).showDiffWhenFolded) return [];
5403
+ const presentation = toolResultPresentationPolicy(finished.result) ?? toolPresentationPolicy(finished.toolName, finished.args);
5404
+ if (!presentation.showDiffWhenFolded) return [];
5515
5405
  const diff = resultDiff(finished.result);
5516
5406
  if (diff === null) return [];
5517
5407
  return truncateRowsMiddle(
@@ -6288,6 +6178,10 @@ function renderContextMeterGrid(ledger, cols, rows, theme6 = clioTheme()) {
6288
6178
  }
6289
6179
  return lines;
6290
6180
  }
6181
+ function renderEvictedTokensLine(evictedTokens2, theme6 = clioTheme()) {
6182
+ const tokens = Math.round(Math.max(0, evictedTokens2)).toLocaleString("en-US");
6183
+ return `${theme6.fg("dim", GLYPH.contextReserve)} ${theme6.fg("muted", "evicted (outside window)")} ${theme6.fg("dim", `${tokens} tokens`)}`;
6184
+ }
6291
6185
  function contextCategorySwatch(category, theme6 = clioTheme()) {
6292
6186
  return theme6.fg(CONTEXT_CATEGORY_TOKEN[category], contextCategoryGlyph(category));
6293
6187
  }
@@ -10859,7 +10753,8 @@ function toolResultContent(result, unbounded = false) {
10859
10753
  return [{ type: "text", text: stringifyPreview3(result, unbounded ? Number.POSITIVE_INFINITY : 1e4) }];
10860
10754
  }
10861
10755
  function displayReplayToolResult(result, unbounded = false) {
10862
- const content = toolResultContent(result, unbounded);
10756
+ const presentationText = toolResultPresentationText(result);
10757
+ const content = presentationText === null ? toolResultContent(result, unbounded) : [{ type: "text", text: unbounded ? presentationText : truncateReplayText(presentationText) }];
10863
10758
  const details = payloadObject3(result)?.details;
10864
10759
  return details !== null && details !== void 0 && typeof details === "object" ? { content, details } : content;
10865
10760
  }
@@ -11091,12 +10986,6 @@ function truncateAtTurn(entries, uptoTurnId) {
11091
10986
  if (index < 0) return [...entries];
11092
10987
  return entries.slice(0, index + 1);
11093
10988
  }
11094
- function latestCompactionIndex(entries) {
11095
- for (let i = entries.length - 1; i >= 0; i--) {
11096
- if (entries[i]?.kind === "compactionSummary") return i;
11097
- }
11098
- return -1;
11099
- }
11100
10989
  function toolCallIdsInEntry(entry) {
11101
10990
  if (entry.kind !== "message") return [];
11102
10991
  if (entry.role === "tool_call") return [extractToolCall(entry).id];
@@ -11149,16 +11038,11 @@ function repairToolResultOrphans(allEntries, selected, compactionIndex) {
11149
11038
  function selectReplayEntries(turns, options = {}) {
11150
11039
  const active = filterEntriesToActivePath(turns, options.activeLeafTurnId ?? options.uptoTurnId);
11151
11040
  const entries = truncateAtTurn(active, options.uptoTurnId);
11152
- const compactionIndex = latestCompactionIndex(entries);
11153
- if (compactionIndex < 0) return dropLegacyToolResultAssistantDuplicates(entries);
11154
- const compaction = entries[compactionIndex];
11155
- const selected = [compaction];
11156
- const firstKeptIndex = compaction.firstKeptTurnId ? entries.findIndex((entry) => entry.turnId === compaction.firstKeptTurnId) : -1;
11157
- if (firstKeptIndex >= 0 && firstKeptIndex < compactionIndex) {
11158
- selected.push(...entries.slice(firstKeptIndex, compactionIndex));
11159
- }
11160
- selected.push(...entries.slice(compactionIndex + 1));
11161
- return dropLegacyToolResultAssistantDuplicates(repairToolResultOrphans(entries, selected, compactionIndex));
11041
+ const cut = compactionCut(entries);
11042
+ if (cut.compactionIndex < 0) return dropLegacyToolResultAssistantDuplicates(entries);
11043
+ const compaction = entries[cut.compactionIndex];
11044
+ const selected = [compaction, ...cut.visible];
11045
+ return dropLegacyToolResultAssistantDuplicates(repairToolResultOrphans(entries, selected, cut.compactionIndex));
11162
11046
  }
11163
11047
  function dropLegacyToolResultAssistantDuplicates(entries) {
11164
11048
  const out = [];
@@ -11253,6 +11137,11 @@ function buildReplayAgentMessagesFromTurns(turns, options = {}) {
11253
11137
  // It reaches the model only when an operator shares it, and a share
11254
11138
  // is already a user message by the time it lands in the ledger.
11255
11139
  case "workerRun":
11140
+ // Working-set entries are folded into a view by the context domain
11141
+ // and applied as a projection before this builder runs; the
11142
+ // entries themselves never become messages.
11143
+ case "contextEviction":
11144
+ case "contextRecall":
11256
11145
  break;
11257
11146
  }
11258
11147
  }
@@ -11262,6 +11151,7 @@ function rehydrateChatPanelFromTurns(chatPanel, turns, options = {}) {
11262
11151
  const pendingToolIds = [];
11263
11152
  let runAssistantMessages = [];
11264
11153
  const selected = selectReplayEntries(turns, options);
11154
+ const workingSet = foldWorkingSet(turns, options.activeLeafTurnId ?? options.uptoTurnId);
11265
11155
  const workerStates = workerEntriesFromRunEntries(
11266
11156
  selected.filter((entry) => entry.kind === "workerRun"),
11267
11157
  options.readWorkerReceipt ?? readWorkerReceiptFactsForReplay
@@ -11306,6 +11196,7 @@ function rehydrateChatPanelFromTurns(chatPanel, turns, options = {}) {
11306
11196
  }
11307
11197
  if (entry.role === "tool_result") {
11308
11198
  const result = extractToolResult(entry);
11199
+ const evictedReason = workingSet.evicted.get(entry.turnId)?.reason;
11309
11200
  const fallbackId = result.id ?? pendingToolIds.pop() ?? null;
11310
11201
  if (fallbackId) {
11311
11202
  const pendingIndex = pendingToolIds.indexOf(fallbackId);
@@ -11319,7 +11210,8 @@ function rehydrateChatPanelFromTurns(chatPanel, turns, options = {}) {
11319
11210
  ...result.durationMs !== void 0 ? { durationMs: result.durationMs } : {},
11320
11211
  ...result.resultSummary !== void 0 ? { resultSummary: result.resultSummary } : {},
11321
11212
  ...result.outcome !== void 0 ? { outcome: result.outcome } : {},
11322
- ...result.blockReason !== void 0 ? { blockReason: result.blockReason } : {}
11213
+ ...result.blockReason !== void 0 ? { blockReason: result.blockReason } : {},
11214
+ ...evictedReason !== void 0 ? { evictedReason } : {}
11323
11215
  });
11324
11216
  } else {
11325
11217
  chatPanel.appendReplayBlock(
@@ -11332,7 +11224,8 @@ function rehydrateChatPanelFromTurns(chatPanel, turns, options = {}) {
11332
11224
  ...result.durationMs !== void 0 ? { durationMs: result.durationMs } : {},
11333
11225
  ...result.resultSummary !== void 0 ? { resultSummary: result.resultSummary } : {},
11334
11226
  ...result.outcome === "blocked" ? { outcome: "blocked" } : {},
11335
- ...result.blockReason !== void 0 ? { blockReason: result.blockReason } : {}
11227
+ ...result.blockReason !== void 0 ? { blockReason: result.blockReason } : {},
11228
+ ...evictedReason !== void 0 ? { evictedReason } : {}
11336
11229
  },
11337
11230
  width,
11338
11231
  { unbounded: options.unboundedToolBodies === true }
@@ -11417,6 +11310,8 @@ function rehydrateChatPanelFromTurns(chatPanel, turns, options = {}) {
11417
11310
  case "label":
11418
11311
  case "taskLedger":
11419
11312
  case "decisionLedger":
11313
+ case "contextEviction":
11314
+ case "contextRecall":
11420
11315
  break;
11421
11316
  }
11422
11317
  }
@@ -11432,6 +11327,13 @@ function rehydrateChatPanelFromTurns(chatPanel, turns, options = {}) {
11432
11327
  chatPanel.clearFoldOverrides();
11433
11328
  }
11434
11329
 
11330
+ // src/interactive/model-session-replay.ts
11331
+ function buildModelReplayAgentMessagesFromTurns(entries, options = {}) {
11332
+ const activeLeafTurnId = options.activeLeafTurnId ?? options.uptoTurnId;
11333
+ const projected = projectWorkingSet(entries, foldWorkingSet(entries, activeLeafTurnId));
11334
+ return buildReplayAgentMessagesFromTurns(projected, options);
11335
+ }
11336
+
11435
11337
  // src/interactive/turn-context.ts
11436
11338
  function createTurnContext(deps) {
11437
11339
  const { state, middleware } = deps;
@@ -11444,20 +11346,37 @@ function createTurnContext(deps) {
11444
11346
  let sessionPromptKey = null;
11445
11347
  const sessionWorkingContextPaths = /* @__PURE__ */ new Set();
11446
11348
  let pendingPromptLogEntry = null;
11349
+ let emptyAutoCompactTurnId = null;
11447
11350
  const pendingColdReasons = /* @__PURE__ */ new Set();
11448
11351
  let runExpectedColdReasons = [];
11449
- let stampColdReasonsPending = false;
11352
+ let nextAssistantColdReasons = [];
11353
+ const TIER_INDEPENDENT_COLD_REASONS = /* @__PURE__ */ new Set(["working_set_evict"]);
11354
+ const stampsOnTier = (reason, runtimeId) => TIER_INDEPENDENT_COLD_REASONS.has(reason) || runtimeId !== void 0 && deps.providers.getRuntime(runtimeId)?.tier === "local-native";
11355
+ const noteColdReason = (reason) => {
11356
+ if (!state.streaming) {
11357
+ pendingColdReasons.add(reason);
11358
+ return;
11359
+ }
11360
+ if (!stampsOnTier(reason, state.runtime?.runtimeId)) return;
11361
+ if (!runExpectedColdReasons.includes(reason)) runExpectedColdReasons.push(reason);
11362
+ if (nextAssistantColdReasons.includes(reason)) return;
11363
+ nextAssistantColdReasons.push(reason);
11364
+ deps.emitNotice(`[context engine] backend prefix cache likely cold this turn: ${reason}`);
11365
+ };
11450
11366
  const unsubscribeColdReasonSources = [
11451
11367
  ...[BusChannels.DispatchStarted, BusChannels.DispatchCompleted, BusChannels.DispatchFailed].map(
11452
11368
  (channel) => deps.bus?.on(channel, () => {
11453
- pendingColdReasons.add("dispatch");
11369
+ noteColdReason("dispatch");
11454
11370
  }) ?? null
11455
11371
  ),
11456
11372
  ...[BusChannels.CompactionBegin, BusChannels.CompactionEnd].map(
11457
11373
  (channel) => deps.bus?.on(channel, () => {
11458
- pendingColdReasons.add("compaction");
11374
+ noteColdReason("compaction");
11459
11375
  }) ?? null
11460
- )
11376
+ ),
11377
+ deps.bus?.on(BusChannels.ContextRecalled, (payload) => {
11378
+ middleware.fireCompactionHook("working_set_recall", payload.trigger);
11379
+ }) ?? null
11461
11380
  ];
11462
11381
  let snapshotPersistPending = false;
11463
11382
  let lastContextWindowWarning = null;
@@ -11525,7 +11444,7 @@ function createTurnContext(deps) {
11525
11444
  };
11526
11445
  const refreshAgentMessagesFromSession = (agentRuntime) => {
11527
11446
  const refreshedEntries = deps.readSessionEntries?.() ?? [];
11528
- agentRuntime.agent.state.messages = buildReplayAgentMessagesFromTurns(refreshedEntries, {
11447
+ agentRuntime.agent.state.messages = buildModelReplayAgentMessagesFromTurns(refreshedEntries, {
11529
11448
  ...state.lastTurnId ? { activeLeafTurnId: state.lastTurnId } : {}
11530
11449
  });
11531
11450
  state.replayedContextMessages = [];
@@ -11563,11 +11482,17 @@ function createTurnContext(deps) {
11563
11482
  );
11564
11483
  };
11565
11484
  const runAutoCompact = async (agentRuntime, force, instructions, triggerOverride, pendingUserText) => {
11566
- if (!deps.autoCompact || !deps.readSessionEntries) return false;
11485
+ if (!deps.readSessionEntries) return false;
11486
+ const activeAutoTurnId = force ? null : state.activeUserTurnId;
11487
+ if (activeAutoTurnId && emptyAutoCompactTurnId === activeAutoTurnId) return false;
11567
11488
  const settings = deps.getSettings();
11568
11489
  const cfg = settings.compaction;
11569
11490
  const autoEnabled = cfg?.auto !== false;
11570
11491
  if (!force && !autoEnabled) return false;
11492
+ let preSummaryStageActed = false;
11493
+ const rememberEmptyAutomaticAttempt = () => {
11494
+ if (!force && !preSummaryStageActed && activeAutoTurnId) emptyAutoCompactTurnId = activeAutoTurnId;
11495
+ };
11571
11496
  const compactionThreshold = cfg?.threshold ?? DEFAULT_COMPACTION_THRESHOLD;
11572
11497
  const trigger = triggerOverride ?? (force ? "force" : "auto");
11573
11498
  if (!force) {
@@ -11576,78 +11501,176 @@ function createTurnContext(deps) {
11576
11501
  if (!verdict.shouldCompact) return false;
11577
11502
  if (deps.session?.current()) {
11578
11503
  const beforeSnapshotId2 = currentContextSnapshot?.snapshotId ?? null;
11579
- let masked;
11580
- try {
11581
- masked = maskStaleObservations(deps.readSessionEntries() ?? [], cfg?.excludeLastTurns ?? 6);
11582
- } catch (error) {
11583
- middleware.fireCompactionHook("mask_observations", trigger, estimate.tokens);
11584
- deps.bus?.emit(BusChannels.CompactionBegin, { trigger, at: Date.now() });
11585
- emitCompactionActivity("started", "compacting context (mask stage)");
11586
- emitCompactionActivity("failed", compactionFailureMessage(error));
11587
- deps.bus?.emit(BusChannels.CompactionEnd, { trigger, at: Date.now() });
11588
- throw error;
11589
- }
11590
- if (masked.changed) {
11591
- middleware.fireCompactionHook("mask_observations", trigger, estimate.tokens);
11592
- deps.bus?.emit(BusChannels.CompactionBegin, { trigger, at: Date.now() });
11593
- emitCompactionActivity("started", "compacting context (mask stage)");
11594
- deps.session.replaceEntries(masked.entries);
11595
- refreshAgentMessagesFromSession(agentRuntime);
11596
- deps.bus?.emit(BusChannels.CompactionEnd, { trigger, at: Date.now() });
11597
- const postMaskSnapshot = captureRuntimeContextSnapshot(
11598
- agentRuntime,
11599
- state.activeUserTurnId || "compaction",
11600
- compactionThreshold
11601
- );
11602
- currentContextSnapshot = postMaskSnapshot;
11603
- persistContextSnapshot(postMaskSnapshot);
11604
- const tokensAfterMask = snapshotInputTokens(postMaskSnapshot);
11605
- lastCompactionEvent = {
11606
- stage: "mask_observations",
11607
- tokensBefore: estimate.tokens,
11608
- tokensAfter: tokensAfterMask,
11609
- trigger
11610
- };
11611
- deps.bus?.emit(BusChannels.ContextPruned, {
11612
- stage: "mask_observations",
11613
- pressure: verdict.pressure,
11614
- tokensBefore: estimate.tokens,
11615
- tokensAfter: tokensAfterMask,
11616
- maskedObservations: masked.maskedObservations,
11617
- maskedThinkingBlocks: masked.maskedThinkingBlocks,
11618
- maskedThinkingChars: masked.maskedThinkingChars,
11619
- trigger,
11620
- snapshotIdBefore: beforeSnapshotId2,
11621
- snapshotIdAfter: postMaskSnapshot.snapshotId,
11622
- at: Date.now()
11623
- });
11624
- emitCompactionActivity("completed", `${masked.maskedObservations} observations masked`);
11625
- const thinkingNote = masked.maskedThinkingBlocks > 0 ? `, ${masked.maskedThinkingBlocks} thinking blocks dropped (~${masked.maskedThinkingChars} chars)` : "";
11626
- deps.emitNotice(
11627
- `[context engine] mask_observations: ${masked.maskedObservations} observations masked${thinkingNote}; ~${estimate.tokens} tokens -> ~${tokensAfterMask} tokens`
11628
- );
11629
- const after = liveContextEstimate(agentRuntime, pendingUserText);
11630
- if (!shouldCompact(after.tokens, compactionThreshold, after.contextWindow).shouldCompact) return true;
11504
+ if (process.env.CLIO_CODER_LEGACY_MASK === "1") {
11505
+ let masked;
11506
+ try {
11507
+ masked = maskStaleObservations(deps.readSessionEntries() ?? [], cfg?.excludeLastTurns ?? 6);
11508
+ } catch (error) {
11509
+ middleware.fireCompactionHook("mask_observations", trigger, estimate.tokens);
11510
+ deps.bus?.emit(BusChannels.CompactionBegin, { trigger, at: Date.now() });
11511
+ emitCompactionActivity("started", "compacting context (mask stage)");
11512
+ emitCompactionActivity("failed", compactionFailureMessage(error));
11513
+ deps.bus?.emit(BusChannels.CompactionEnd, { trigger, at: Date.now() });
11514
+ throw error;
11515
+ }
11516
+ if (masked.changed) {
11517
+ preSummaryStageActed = true;
11518
+ middleware.fireCompactionHook("mask_observations", trigger, estimate.tokens);
11519
+ deps.bus?.emit(BusChannels.CompactionBegin, { trigger, at: Date.now() });
11520
+ emitCompactionActivity("started", "compacting context (mask stage)");
11521
+ deps.session.replaceEntries(masked.entries);
11522
+ refreshAgentMessagesFromSession(agentRuntime);
11523
+ deps.bus?.emit(BusChannels.CompactionEnd, { trigger, at: Date.now() });
11524
+ const postMaskSnapshot = captureRuntimeContextSnapshot(
11525
+ agentRuntime,
11526
+ state.activeUserTurnId || "compaction",
11527
+ compactionThreshold
11528
+ );
11529
+ currentContextSnapshot = postMaskSnapshot;
11530
+ persistContextSnapshot(postMaskSnapshot);
11531
+ const tokensAfterMask = snapshotInputTokens(postMaskSnapshot);
11532
+ lastCompactionEvent = {
11533
+ stage: "mask_observations",
11534
+ tokensBefore: estimate.tokens,
11535
+ tokensAfter: tokensAfterMask,
11536
+ trigger
11537
+ };
11538
+ deps.bus?.emit(BusChannels.ContextPruned, {
11539
+ stage: "mask_observations",
11540
+ pressure: verdict.pressure,
11541
+ tokensBefore: estimate.tokens,
11542
+ tokensAfter: tokensAfterMask,
11543
+ maskedObservations: masked.maskedObservations,
11544
+ maskedThinkingBlocks: masked.maskedThinkingBlocks,
11545
+ maskedThinkingChars: masked.maskedThinkingChars,
11546
+ trigger,
11547
+ snapshotIdBefore: beforeSnapshotId2,
11548
+ snapshotIdAfter: postMaskSnapshot.snapshotId,
11549
+ at: Date.now()
11550
+ });
11551
+ emitCompactionActivity("completed", `${masked.maskedObservations} observations masked`);
11552
+ const thinkingNote = masked.maskedThinkingBlocks > 0 ? `, ${masked.maskedThinkingBlocks} thinking blocks dropped (~${masked.maskedThinkingChars} chars)` : "";
11553
+ deps.emitNotice(
11554
+ `[context engine] mask_observations: ${masked.maskedObservations} observations masked${thinkingNote}; ~${estimate.tokens} tokens -> ~${tokensAfterMask} tokens`
11555
+ );
11556
+ const after = liveContextEstimate(agentRuntime, pendingUserText);
11557
+ if (!shouldCompact(after.tokens, compactionThreshold, after.contextWindow).shouldCompact) return true;
11558
+ }
11559
+ } else if (settings.context.workingSet.enabled) {
11560
+ let planned;
11561
+ try {
11562
+ const entries = deps.readSessionEntries() ?? [];
11563
+ const view = foldWorkingSet(entries, state.lastTurnId ?? void 0);
11564
+ const policy = resolveWorkingSetPolicy(settings.context.workingSet.policy);
11565
+ planned = (deps.planEviction ?? planEviction)(policy, {
11566
+ entries: selectVisibleEntries(entries, state.lastTurnId ?? void 0),
11567
+ view,
11568
+ cwd: deps.session.current()?.cwd ?? null,
11569
+ settings: settings.context.workingSet,
11570
+ pressure: {
11571
+ tokens: estimate.tokens,
11572
+ contextWindow: estimate.contextWindow,
11573
+ threshold: compactionThreshold,
11574
+ target: settings.context.workingSet.target
11575
+ },
11576
+ estimateTokens
11577
+ });
11578
+ } catch (error) {
11579
+ middleware.fireCompactionHook("working_set_evict", "pressure", estimate.tokens);
11580
+ emitCompactionActivity("started", "compacting context (working-set eviction)");
11581
+ emitCompactionActivity("failed", compactionFailureMessage(error));
11582
+ throw error;
11583
+ }
11584
+ if (planned) {
11585
+ preSummaryStageActed = true;
11586
+ middleware.fireCompactionHook("working_set_evict", "pressure", estimate.tokens);
11587
+ emitCompactionActivity("started", "compacting context (working-set eviction)");
11588
+ try {
11589
+ deps.session.appendEntry({
11590
+ ...buildEvictionFields(planned, {
11591
+ trigger: "pressure",
11592
+ pressureBefore: verdict.pressure,
11593
+ snapshotIdBefore: beforeSnapshotId2
11594
+ }),
11595
+ // appendEntry does not infer this anchor; the interactive
11596
+ // cursor is the leaf the next message will extend.
11597
+ parentTurnId: state.lastTurnId
11598
+ });
11599
+ noteColdReason("working_set_evict");
11600
+ refreshAgentMessagesFromSession(agentRuntime);
11601
+ const postEvictionSnapshot = captureRuntimeContextSnapshot(
11602
+ agentRuntime,
11603
+ state.activeUserTurnId || "compaction",
11604
+ compactionThreshold
11605
+ );
11606
+ currentContextSnapshot = postEvictionSnapshot;
11607
+ persistContextSnapshot(postEvictionSnapshot);
11608
+ lastCompactionEvent = {
11609
+ stage: "working_set",
11610
+ tokensBefore: planned.tokensBefore,
11611
+ tokensAfter: planned.tokensAfter,
11612
+ trigger
11613
+ };
11614
+ deps.bus?.emit(BusChannels.ContextPruned, {
11615
+ stage: "working_set",
11616
+ pressure: verdict.pressure,
11617
+ tokensBefore: planned.tokensBefore,
11618
+ tokensAfter: planned.tokensAfter,
11619
+ trigger,
11620
+ snapshotIdBefore: beforeSnapshotId2,
11621
+ snapshotIdAfter: postEvictionSnapshot.snapshotId,
11622
+ policyId: planned.policyId,
11623
+ evictedItems: planned.items.length,
11624
+ at: Date.now()
11625
+ });
11626
+ const itemsWord = planned.items.length === 1 ? "item" : "items";
11627
+ emitCompactionActivity("completed", `${planned.items.length} working-set ${itemsWord} evicted`);
11628
+ deps.emitNotice(
11629
+ `[context engine] working set: ${planned.items.length} ${itemsWord} evicted by ${planned.policyId}; ~${planned.tokensBefore} -> ~${planned.tokensAfter} tokens, recall by ref with context(scope="recall")`
11630
+ );
11631
+ const after = liveContextEstimate(agentRuntime, pendingUserText);
11632
+ if (!shouldCompact(after.tokens, compactionThreshold, after.contextWindow).shouldCompact) return true;
11633
+ } catch (error) {
11634
+ emitCompactionActivity("failed", compactionFailureMessage(error));
11635
+ throw error;
11636
+ }
11637
+ }
11631
11638
  }
11632
11639
  }
11633
11640
  }
11634
- middleware.fireCompactionHook("llm_summary", trigger);
11635
- deps.bus?.emit(BusChannels.CompactionBegin, { trigger, at: Date.now() });
11636
- emitCompactionActivity("started", "compacting context (summary)");
11641
+ if (!deps.autoCompact) {
11642
+ rememberEmptyAutomaticAttempt();
11643
+ return false;
11644
+ }
11645
+ let summaryLifecycleStarted = false;
11646
+ const startSummaryLifecycle = () => {
11647
+ middleware.fireCompactionHook("llm_summary", trigger);
11648
+ deps.bus?.emit(BusChannels.CompactionBegin, { trigger, at: Date.now() });
11649
+ emitCompactionActivity("started", "compacting context (summary)");
11650
+ summaryLifecycleStarted = true;
11651
+ };
11652
+ if (force) startSummaryLifecycle();
11637
11653
  let result = null;
11638
11654
  const beforeSnapshotId = currentContextSnapshot?.snapshotId ?? null;
11639
11655
  try {
11640
11656
  result = await compactionTrigger.fire(() => (deps.autoCompact ?? (async () => null))(instructions, trigger));
11641
11657
  } catch (error) {
11658
+ if (!summaryLifecycleStarted) startSummaryLifecycle();
11642
11659
  emitCompactionActivity("failed", compactionFailureMessage(error));
11643
- throw error;
11644
- } finally {
11645
11660
  deps.bus?.emit(BusChannels.CompactionEnd, { trigger, at: Date.now() });
11661
+ throw error;
11646
11662
  }
11647
11663
  if (!result || result.summary.length === 0) {
11648
- emitCompactionActivity("completed", "nothing to compact");
11664
+ if (summaryLifecycleStarted) {
11665
+ deps.bus?.emit(BusChannels.CompactionEnd, { trigger, at: Date.now() });
11666
+ emitCompactionActivity("completed", "nothing to compact");
11667
+ } else {
11668
+ rememberEmptyAutomaticAttempt();
11669
+ }
11649
11670
  return false;
11650
11671
  }
11672
+ if (!summaryLifecycleStarted) startSummaryLifecycle();
11673
+ deps.bus?.emit(BusChannels.CompactionEnd, { trigger, at: Date.now() });
11651
11674
  recordCompactionUsage(agentRuntime, result);
11652
11675
  refreshAgentMessagesFromSession(agentRuntime);
11653
11676
  const postCompactSnapshot = captureRuntimeContextSnapshot(
@@ -11943,13 +11966,13 @@ function createTurnContext(deps) {
11943
11966
  },
11944
11967
  consumeExpectedColdReasons(runtimeId) {
11945
11968
  runExpectedColdReasons = [];
11946
- stampColdReasonsPending = false;
11969
+ nextAssistantColdReasons = [];
11947
11970
  if (pendingColdReasons.size > 0) {
11948
- const reasons = [...pendingColdReasons];
11971
+ const reasons = [...pendingColdReasons].filter((reason) => stampsOnTier(reason, runtimeId));
11949
11972
  pendingColdReasons.clear();
11950
- if (deps.providers.getRuntime(runtimeId)?.tier === "local-native") {
11973
+ if (reasons.length > 0) {
11951
11974
  runExpectedColdReasons = reasons;
11952
- stampColdReasonsPending = true;
11975
+ nextAssistantColdReasons = reasons;
11953
11976
  deps.emitNotice(`[context engine] backend prefix cache likely cold this turn: ${reasons.join(", ")}`);
11954
11977
  }
11955
11978
  }
@@ -11964,9 +11987,9 @@ function createTurnContext(deps) {
11964
11987
  cacheWrite,
11965
11988
  backendVerdict: backendCacheVerdict(input, cacheRead)
11966
11989
  };
11967
- if (stampColdReasonsPending && runExpectedColdReasons.length > 0) {
11968
- promptCache.expectedColdReasons = [...runExpectedColdReasons];
11969
- stampColdReasonsPending = false;
11990
+ if (nextAssistantColdReasons.length > 0) {
11991
+ promptCache.expectedColdReasons = [...nextAssistantColdReasons];
11992
+ nextAssistantColdReasons = [];
11970
11993
  }
11971
11994
  return promptCache;
11972
11995
  },
@@ -11978,7 +12001,8 @@ function createTurnContext(deps) {
11978
12001
  cacheReadTokens: cacheSummary.cacheRead > 0 || cacheSummary.cacheWrite > 0 ? cacheSummary.cacheRead : null,
11979
12002
  cacheWriteTokens: cacheSummary.cacheRead > 0 || cacheSummary.cacheWrite > 0 ? cacheSummary.cacheWrite : null,
11980
12003
  uncachedInputTokens: cacheSummary.input,
11981
- backendVerdict: runFirstCallVerdict
12004
+ backendVerdict: runFirstCallVerdict,
12005
+ ...runExpectedColdReasons.length > 0 ? { expectedColdReasons: [...runExpectedColdReasons] } : {}
11982
12006
  };
11983
12007
  }
11984
12008
  },
@@ -11988,6 +12012,7 @@ function createTurnContext(deps) {
11988
12012
  sessionPromptKey = null;
11989
12013
  sessionWorkingContextPaths.clear();
11990
12014
  pendingPromptLogEntry = null;
12015
+ emptyAutoCompactTurnId = null;
11991
12016
  const session = deps.session?.current();
11992
12017
  currentContextSnapshot = session ? getLatestContextSnapshot(session) : null;
11993
12018
  },
@@ -12141,9 +12166,9 @@ function createTurnMiddleware(deps) {
12141
12166
  }
12142
12167
  },
12143
12168
  /**
12144
- * Observe-only lifecycle point fired before each compaction stage, at the
12145
- * existing CompactionBegin emit sites. Consumers record telemetry or state
12146
- * ahead of context loss; returned effects are discarded by design.
12169
+ * Observe-only lifecycle point fired before each compaction or working-set
12170
+ * stage. Consumers record telemetry or state around projected context
12171
+ * changes; returned effects are discarded by design.
12147
12172
  */
12148
12173
  fireCompactionHook(stage, trigger, tokensBefore) {
12149
12174
  if (!deps.middleware) return;
@@ -16192,7 +16217,43 @@ function legendRow2(group, contentWidth) {
16192
16217
  const labelText = group.label.length > leftWidth ? group.label.slice(0, leftWidth) : group.label.padEnd(leftWidth);
16193
16218
  return `${swatch} ${theme6.fg(labelToken, labelText)} ${theme6.fg("muted", right)}`;
16194
16219
  }
16195
- function renderContextLedgerLines(ledger, contentWidth) {
16220
+ function evictedTokens(view) {
16221
+ let total = 0;
16222
+ for (const state of view.evicted.values()) total += state.tokensFreed;
16223
+ return total;
16224
+ }
16225
+ function formatChurn(view) {
16226
+ if (view.itemsEvicted === 0) return "n/a";
16227
+ return (view.recalls / view.itemsEvicted).toFixed(2);
16228
+ }
16229
+ function coldReasonLabel(reason) {
16230
+ switch (reason) {
16231
+ case "working_set_evict":
16232
+ return "working-set eviction";
16233
+ case "compaction":
16234
+ return "compaction";
16235
+ case "dispatch":
16236
+ return "dispatch traffic";
16237
+ default:
16238
+ return reason;
16239
+ }
16240
+ }
16241
+ function renderWorkingSetLines(view) {
16242
+ const theme6 = clioTheme();
16243
+ const items = view.evicted.size;
16244
+ const summary = [
16245
+ `${items} evicted item${items === 1 ? "" : "s"}`,
16246
+ `${formatTokens(evictedTokens(view))} tokens`,
16247
+ `${view.evictionEvents} event${view.evictionEvents === 1 ? "" : "s"}`,
16248
+ `${view.recalls} recall${view.recalls === 1 ? "" : "s"}`,
16249
+ `churn ${formatChurn(view)}`
16250
+ ].join(" \xB7 ");
16251
+ return [
16252
+ `${theme6.fg("muted", "working set")} ${theme6.fg("dim", "\xB7")} ${theme6.fg("accent", `policy ${view.lastPolicyId ?? "none"}`)}`,
16253
+ theme6.fg("dim", summary)
16254
+ ];
16255
+ }
16256
+ function renderContextLedgerLines(ledger, contentWidth, workingSet) {
16196
16257
  const theme6 = clioTheme();
16197
16258
  const lines = [];
16198
16259
  const provider = ledger.provider ?? "no target";
@@ -16217,7 +16278,12 @@ function renderContextLedgerLines(ledger, contentWidth) {
16217
16278
  }
16218
16279
  lines.push("");
16219
16280
  for (const group of ledger.meter) lines.push(legendRow2(group, contentWidth));
16281
+ if (workingSet && workingSet.evicted.size > 0) lines.push(renderEvictedTokensLine(evictedTokens(workingSet), theme6));
16220
16282
  lines.push("");
16283
+ if (workingSet) {
16284
+ for (const line of renderWorkingSetLines(workingSet)) lines.push(line);
16285
+ lines.push("");
16286
+ }
16221
16287
  if (ledger.projectPreload && ledger.groups.some((group) => group.category === "project")) {
16222
16288
  lines.push(theme6.fg("dim", `project preload: ${ledger.projectPreload}`));
16223
16289
  }
@@ -16235,8 +16301,13 @@ function renderContextLedgerLines(ledger, contentWidth) {
16235
16301
  const read = cache2.cacheReadTokens !== null ? `cache read ${formatTokens(cache2.cacheReadTokens)}` : "cache read n/a";
16236
16302
  const uncached = cache2.uncachedInputTokens !== null ? `uncached input ${formatTokens(cache2.uncachedInputTokens)}` : null;
16237
16303
  const line = ["prompt cache:", shell, "\xB7", backend, "\xB7", read, ...uncached ? ["\xB7", uncached] : []].join(" ");
16238
- const misleading = cache2.shellReused && cache2.backendVerdict === "cold";
16304
+ const coldReasons = cache2.backendVerdict === "cold" ? cache2.expectedColdReasons ?? [] : [];
16305
+ const misleading = cache2.shellReused && cache2.backendVerdict === "cold" && coldReasons.length === 0;
16239
16306
  lines.push(theme6.fg(misleading ? "warning" : "dim", line));
16307
+ if (coldReasons.length > 0) {
16308
+ const reasons = coldReasons.map(coldReasonLabel).join(", ");
16309
+ lines.push(theme6.fg("dim", `last cold turn: ${reasons} (expected)`));
16310
+ }
16240
16311
  }
16241
16312
  if (ledger.lastCompaction) {
16242
16313
  const pruneInfo = `last compaction: reclaimed ${formatTokens(ledger.lastCompaction.tokensBefore)} -> ${formatTokens(ledger.lastCompaction.tokensAfter)} tokens (${ledger.lastCompaction.stage})`;
@@ -16246,7 +16317,8 @@ function renderContextLedgerLines(ledger, contentWidth) {
16246
16317
  }
16247
16318
  var STREAMING_FALLBACK_TICK_MS = 1e3;
16248
16319
  function openContextOverlay(tui, getLedger, options) {
16249
- const text = new Text(renderContextLedgerLines(getLedger(), DEFAULT_CONTENT_WIDTH).join("\n"), 0, 0);
16320
+ const render2 = () => renderContextLedgerLines(getLedger(), DEFAULT_CONTENT_WIDTH, options?.getWorkingSet?.() ?? null).join("\n");
16321
+ const text = new Text(render2(), 0, 0);
16250
16322
  const handle = showClioOverlayFrame(tui, text, {
16251
16323
  anchor: "center",
16252
16324
  width: CONTEXT_OVERLAY_WIDTH,
@@ -16254,7 +16326,7 @@ function openContextOverlay(tui, getLedger, options) {
16254
16326
  footerHint: buildHint([])
16255
16327
  });
16256
16328
  const refresh = () => {
16257
- text.setText(renderContextLedgerLines(getLedger(), DEFAULT_CONTENT_WIDTH).join("\n"));
16329
+ text.setText(render2());
16258
16330
  text.invalidate();
16259
16331
  tui.requestRender();
16260
16332
  };
@@ -21366,6 +21438,7 @@ function isSettingsSectionId(value) {
21366
21438
  var COMPACT_POSITIONALS = [
21367
21439
  { name: "instructions", required: false, rest: true }
21368
21440
  ];
21441
+ var RECALL_POSITIONALS = [{ name: "ref", required: true }];
21369
21442
  function fromArgsOrUsage(name, command) {
21370
21443
  return (parsed) => parsed.error ? { kind: "usage-error", command: name, reason: parsed.error } : command;
21371
21444
  }
@@ -21711,11 +21784,12 @@ ${usage}` : usage);
21711
21784
  },
21712
21785
  {
21713
21786
  name: "context",
21714
- description: "Context hub: window overlay plus compact, init, refresh, and reset",
21787
+ description: "Context hub: window overlay plus compact, recall, init, refresh, and reset",
21715
21788
  group: "Inspect",
21716
- kinds: ["context-view", "compact", "init", "context-clear", "context-refresh"],
21789
+ kinds: ["context-view", "compact", "context-recall", "init", "context-clear", "context-refresh"],
21717
21790
  subcommandDescriptions: {
21718
21791
  compact: "Compact session context",
21792
+ recall: "Recall an evicted result",
21719
21793
  init: "Initialize project context",
21720
21794
  refresh: "Refresh project context",
21721
21795
  reset: "Reset project context"
@@ -21723,6 +21797,7 @@ ${usage}` : usage);
21723
21797
  args: {
21724
21798
  subcommands: {
21725
21799
  compact: { positionals: [...COMPACT_POSITIONALS] },
21800
+ recall: { positionals: [...RECALL_POSITIONALS] },
21726
21801
  init: {},
21727
21802
  refresh: {},
21728
21803
  reset: {}
@@ -21733,6 +21808,8 @@ ${usage}` : usage);
21733
21808
  switch (parsed.subcommand) {
21734
21809
  case "compact":
21735
21810
  return { kind: "compact", instructions: parsed.rest };
21811
+ case "recall":
21812
+ return { kind: "context-recall", ref: parsed.positionals[0] ?? "" };
21736
21813
  case "init":
21737
21814
  return { kind: "init", options: {} };
21738
21815
  case "refresh":
@@ -21751,6 +21828,13 @@ ${usage}` : usage);
21751
21828
  case "compact":
21752
21829
  ctx.runCompact(command.instructions);
21753
21830
  return;
21831
+ case "context-recall":
21832
+ if (ctx.runContextRecall) {
21833
+ ctx.runContextRecall(command.ref);
21834
+ } else {
21835
+ ctx.notice("error", "context recall is not wired; no session is bound to this process");
21836
+ }
21837
+ return;
21754
21838
  case "init":
21755
21839
  ctx.runInit(command.options);
21756
21840
  return;
@@ -22611,7 +22695,12 @@ function createOverlayGeneralOpeners(deps) {
22611
22695
  deps.transitions.state = "context-view";
22612
22696
  deps.transitions.handle = openContextOverlayFactory(deps.tui, deps.getContextLedger, {
22613
22697
  bus: deps.bus,
22614
- chat: deps.contextChat
22698
+ chat: deps.contextChat,
22699
+ getWorkingSet: () => {
22700
+ const readSessionEntries = deps.readSessionEntries;
22701
+ if (!readSessionEntries) return null;
22702
+ return foldWorkingSet(readSessionEntries(), deps.getSessionMeta()?.pinnedLeafTurnId ?? void 0);
22703
+ }
22615
22704
  });
22616
22705
  deps.requestRender();
22617
22706
  };
@@ -25005,7 +25094,7 @@ function createOverlaySessionLifecycle(deps) {
25005
25094
  const replayOptions = leafTurnId ? { activeLeafTurnId: leafTurnId } : {};
25006
25095
  deps.resetTranscript();
25007
25096
  rehydrateChatPanelFromTurns(deps.chatPanel, turns, replayOptions);
25008
- const replayMessages = buildReplayAgentMessagesFromTurns(turns, replayOptions);
25097
+ const replayMessages = buildModelReplayAgentMessagesFromTurns(turns, replayOptions);
25009
25098
  deps.chat.resetForSession(leafTurnId, replayMessages);
25010
25099
  rescopeToBranch(session, turns, leafTurnId);
25011
25100
  } catch (error) {
@@ -25055,7 +25144,7 @@ function createOverlaySessionLifecycle(deps) {
25055
25144
  const turns = deps.readStructuredEntries(sessionId);
25056
25145
  deps.resetTranscript();
25057
25146
  rehydrateChatPanelFromTurns(deps.chatPanel, turns, { uptoTurnId: turnId });
25058
- const replayMessages = buildReplayAgentMessagesFromTurns(turns, { uptoTurnId: turnId });
25147
+ const replayMessages = buildModelReplayAgentMessagesFromTurns(turns, { uptoTurnId: turnId });
25059
25148
  deps.chat.resetForSession(turnId, replayMessages);
25060
25149
  rescopeToBranch(session, turns, turnId);
25061
25150
  } catch (error) {
@@ -25121,8 +25210,11 @@ function createOverlaySessionLifecycle(deps) {
25121
25210
  try {
25122
25211
  const turns = deps.readStructuredEntries(forkedSessionId);
25123
25212
  rehydrateChatPanelFromTurns(deps.chatPanel, turns);
25124
- const replayMessages = buildReplayAgentMessagesFromTurns(turns);
25125
25213
  const leafTurnId = session.tree(forkedSessionId).leafId ?? parentTurnId;
25214
+ const replayMessages = buildModelReplayAgentMessagesFromTurns(
25215
+ turns,
25216
+ leafTurnId ? { activeLeafTurnId: leafTurnId } : {}
25217
+ );
25126
25218
  deps.chat.resetForSession(leafTurnId, replayMessages);
25127
25219
  rescopeToBranch(session, turns, leafTurnId);
25128
25220
  } catch (error) {
@@ -27950,7 +28042,7 @@ function styleStatusVerb(text, toneHint) {
27950
28042
  function policySegmentFold(seg, detail) {
27951
28043
  if (!seg.finished) return policyRunningToolFold(detail);
27952
28044
  if (seg.isError && detail.errors === "body") return "expanded";
27953
- return policyToolFold(detail, toolPresentationPolicy(seg.name, seg.args));
28045
+ return policyToolFold(detail, toolResultPresentationPolicy(seg.result) ?? toolPresentationPolicy(seg.name, seg.args));
27954
28046
  }
27955
28047
  function toolSegmentExpanded(seg, detail) {
27956
28048
  return resolveFold(seg.fold, policySegmentFold(seg, detail)) === "expanded";
@@ -27978,7 +28070,8 @@ function renderToolSegmentLines(seg, width, expandKey, latestHintToolId, nowMs,
27978
28070
  durationMs: seg.durationMs,
27979
28071
  resultSummary: seg.resultSummary,
27980
28072
  outcome: seg.settlement,
27981
- blockReason: seg.blockReason
28073
+ blockReason: seg.blockReason,
28074
+ evictedReason: seg.evictedReason
27982
28075
  } : { toolCallId: seg.id, toolName: seg.name, args: seg.args, elapsedMs, phase },
27983
28076
  width,
27984
28077
  hintKey,
@@ -28009,7 +28102,8 @@ function renderToolSegmentLines(seg, width, expandKey, latestHintToolId, nowMs,
28009
28102
  durationMs: seg.durationMs,
28010
28103
  resultSummary: seg.resultSummary,
28011
28104
  outcome: seg.settlement,
28012
- blockReason: seg.blockReason
28105
+ blockReason: seg.blockReason,
28106
+ evictedReason: seg.evictedReason
28013
28107
  },
28014
28108
  width,
28015
28109
  { unbounded: unboundedToolBodies, diffStyle: seg.replayed === true ? "plain" : "color" }
@@ -28706,6 +28800,7 @@ function createChatPanel(options = {}) {
28706
28800
  tool.result = event.result;
28707
28801
  tool.isError = event.isError;
28708
28802
  const enriched = event;
28803
+ tool.evictedReason = typeof enriched.evictedReason === "string" && enriched.evictedReason.length > 0 ? enriched.evictedReason : void 0;
28709
28804
  const settled = toolSettlement(enriched);
28710
28805
  tool.settlement = settled?.settlement;
28711
28806
  tool.blockReason = settled?.reason;
@@ -30342,6 +30437,57 @@ init_esm_shims();
30342
30437
  import { mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "node:fs";
30343
30438
  import { join as join9, resolve as resolve4 } from "node:path";
30344
30439
 
30440
+ // src/interactive/context-recall-command.ts
30441
+ init_esm_shims();
30442
+ function formatTokens3(tokens) {
30443
+ return tokens.toLocaleString("en-US");
30444
+ }
30445
+ function headlineFor(ref, tokens, state, offloadPath) {
30446
+ const parts = [ref];
30447
+ if (state !== void 0) {
30448
+ parts.push(state.by === void 0 ? `evicted: ${state.reason}` : `evicted: ${state.reason} by ${state.by}`);
30449
+ }
30450
+ parts.push(`${formatTokens3(tokens)} tokens`);
30451
+ if (offloadPath !== void 0) parts.push(`offload: ${offloadPath}`);
30452
+ return `[/context recall] ${parts.join(" \xB7 ")}`;
30453
+ }
30454
+ function runOperatorRecall(ref, deps) {
30455
+ if (!deps.hasSession()) {
30456
+ return { ok: false, message: "[/context recall] no active session; start one with /new or /resume first" };
30457
+ }
30458
+ const trimmed = ref.trim();
30459
+ if (trimmed.length === 0) {
30460
+ return { ok: false, message: "[/context recall] needs a ref: the turnId named in an [evicted ...] marker" };
30461
+ }
30462
+ const entries = deps.readEntries();
30463
+ const leaf = deps.activeLeafTurnId();
30464
+ const view = foldWorkingSet(entries, leaf);
30465
+ const resolved = resolveRecall(entries, view, trimmed, leaf);
30466
+ if (!resolved.ok)
30467
+ return { ok: false, message: `[/context recall] ${recallErrorMessage(resolved.error, entries, view)}` };
30468
+ const { result } = resolved;
30469
+ const fields = buildRecallFields(result, { trigger: "operator" });
30470
+ try {
30471
+ deps.appendEntry({ ...fields, parentTurnId: recallParentTurnId(entries, leaf) });
30472
+ } catch (err) {
30473
+ return {
30474
+ ok: false,
30475
+ message: `[/context recall] recall of ${result.ref.entry} could not be recorded: ${err instanceof Error ? err.message : String(err)}`
30476
+ };
30477
+ }
30478
+ deps.onRecalled?.({
30479
+ ref: result.ref.entry,
30480
+ trigger: "operator",
30481
+ tokensReadmitted: result.tokens,
30482
+ at: deps.now?.() ?? Date.now()
30483
+ });
30484
+ return {
30485
+ ok: true,
30486
+ headline: headlineFor(result.ref.entry, result.tokens, view.evicted.get(result.ref.entry), result.offloadPath),
30487
+ body: result.body
30488
+ };
30489
+ }
30490
+
30345
30491
  // src/interactive/export-html/index.ts
30346
30492
  init_esm_shims();
30347
30493
 
@@ -30899,6 +31045,34 @@ function createInteractiveSlashRuntime(deps) {
30899
31045
  }
30900
31046
  deps.openContextReset();
30901
31047
  },
31048
+ ...deps.session ? {
31049
+ runContextRecall: (ref) => {
31050
+ const session = deps.session;
31051
+ if (!session) return;
31052
+ const outcome = runOperatorRecall(ref, {
31053
+ hasSession: () => session.current() !== null,
31054
+ readEntries: () => {
31055
+ const sessionId = deps.chat.getSessionId();
31056
+ return sessionId ? deps.readStructuredEntries(sessionId) : [];
31057
+ },
31058
+ activeLeafTurnId: () => {
31059
+ const meta = session.current();
31060
+ return meta ? session.tree(meta.id).leafId ?? void 0 : void 0;
31061
+ },
31062
+ appendEntry: (entry) => session.appendEntry(entry),
31063
+ onRecalled: (payload) => deps.bus.emit(BusChannels.ContextRecalled, payload),
31064
+ ...deps.now ? { now: () => (deps.now?.() ?? /* @__PURE__ */ new Date()).getTime() } : {}
31065
+ });
31066
+ if (!outcome.ok) {
31067
+ appendCommandNotice("error", outcome.message);
31068
+ return;
31069
+ }
31070
+ appendCommandNotice("success", outcome.headline);
31071
+ deps.io.stdout(`${outcome.body}
31072
+ `);
31073
+ deps.requestRender();
31074
+ }
31075
+ } : {},
30902
31076
  runContextRefresh: () => {
30903
31077
  if (!deps.onContextRefresh) {
30904
31078
  deps.io.stderr("[/context refresh] context refresh not wired; pass onContextRefresh to startInteractive\n");
@@ -31160,7 +31334,7 @@ function createSessionTranscript(deps) {
31160
31334
  const turns = deps.readSessionEntries();
31161
31335
  deps.chat.resetForSession(
31162
31336
  leafTurnId,
31163
- buildReplayAgentMessagesFromTurns(turns, {
31337
+ buildModelReplayAgentMessagesFromTurns(turns, {
31164
31338
  ...leafTurnId ? { activeLeafTurnId: leafTurnId } : {}
31165
31339
  })
31166
31340
  );
@@ -32518,7 +32692,7 @@ function createDispatchTool(inputDeps, surfaceOptions = {}) {
32518
32692
  const admission = createDispatchAdmissionController(deps);
32519
32693
  let runnerPromise = null;
32520
32694
  const loadRunner = () => {
32521
- runnerPromise ??= (surfaceOptions.loadRunner ?? (() => import("./dispatch-runner-QPRDDBDX.js")))();
32695
+ runnerPromise ??= (surfaceOptions.loadRunner ?? (() => import("./dispatch-runner-MSWN72NK.js")))();
32522
32696
  return runnerPromise;
32523
32697
  };
32524
32698
  return {
@@ -32722,7 +32896,7 @@ function registerAllTools(registry, deps = {}) {
32722
32896
  ...builtin(
32723
32897
  lazyTool(
32724
32898
  monitorToolSurface,
32725
- async () => (await import("./monitor-GE4ID3IA.js")).createMonitorTool({ dispatch, runEvents: dispatchRunEvents })
32899
+ async () => (await import("./monitor-2F3T5KHP.js")).createMonitorTool({ dispatch, runEvents: dispatchRunEvents })
32726
32900
  ),
32727
32901
  {
32728
32902
  path: "src/tools/monitor.ts",
@@ -33552,7 +33726,14 @@ async function bootOrchestrator(options = {}) {
33552
33726
  });
33553
33727
  const dispatchBackground = createDispatchBackgroundRegistry();
33554
33728
  registerAllTools(toolRegistry, {
33555
- ...session ? { session } : {},
33729
+ ...session ? {
33730
+ session,
33731
+ readSessionEntries: () => {
33732
+ const meta = session.current();
33733
+ return meta ? readSessionEntriesForCompact(meta.id) : [];
33734
+ },
33735
+ onContextRecalled: (payload) => bus.emit(BusChannels.ContextRecalled, payload)
33736
+ } : {},
33556
33737
  taskBoard,
33557
33738
  userTasks,
33558
33739
  dispatch,
@@ -33808,7 +33989,10 @@ async function bootOrchestrator(options = {}) {
33808
33989
  try {
33809
33990
  chat.resetForSession(
33810
33991
  leafTurnId,
33811
- buildReplayAgentMessagesFromTurns(readCurrentSessionEntries(), leafTurnId ? { activeLeafTurnId: leafTurnId } : {})
33992
+ buildModelReplayAgentMessagesFromTurns(
33993
+ readCurrentSessionEntries(),
33994
+ leafTurnId ? { activeLeafTurnId: leafTurnId } : {}
33995
+ )
33812
33996
  );
33813
33997
  } catch (err) {
33814
33998
  chat.resetForSession(leafTurnId);
@@ -33846,7 +34030,7 @@ async function bootOrchestrator(options = {}) {
33846
34030
  ...session ? { session } : {},
33847
34031
  ...session ? {
33848
34032
  readSessionEntries: readSessionEntriesForCompact,
33849
- buildReplayMessages: (entries, leafTurnId) => buildReplayAgentMessagesFromTurns(entries, leafTurnId === null ? {} : { activeLeafTurnId: leafTurnId })
34033
+ buildReplayMessages: (entries, leafTurnId) => buildModelReplayAgentMessagesFromTurns(entries, leafTurnId === null ? {} : { activeLeafTurnId: leafTurnId })
33850
34034
  } : {},
33851
34035
  providers,
33852
34036
  settings: {
@@ -34156,4 +34340,4 @@ export {
34156
34340
  resolveApiKeyForTarget,
34157
34341
  synthesizeOrchestratorModel
34158
34342
  };
34159
- //# sourceMappingURL=orchestrator-EM5MC3HM.js.map
34343
+ //# sourceMappingURL=orchestrator-ORHT43JB.js.map