@retaw106/mmc-oc 1.2.3 → 2.1.0

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 (290) hide show
  1. package/dist/cli.js +7095 -0
  2. package/dist/config/index.d.ts +0 -12
  3. package/dist/config/index.d.ts.map +1 -1
  4. package/dist/config/legacy-harness-blocks.d.ts +27 -0
  5. package/dist/config/legacy-harness-blocks.d.ts.map +1 -0
  6. package/dist/config/live-run-config.d.ts.map +1 -1
  7. package/dist/config/live-snapshot.d.ts +2 -1
  8. package/dist/config/live-snapshot.d.ts.map +1 -1
  9. package/dist/config/project-security.d.ts +4 -5
  10. package/dist/config/project-security.d.ts.map +1 -1
  11. package/dist/config/raw-loader.d.ts +7 -26
  12. package/dist/config/raw-loader.d.ts.map +1 -1
  13. package/dist/config/schema/magic-context.d.ts +164 -259
  14. package/dist/config/schema/magic-context.d.ts.map +1 -1
  15. package/dist/config/variable.d.ts +8 -0
  16. package/dist/config/variable.d.ts.map +1 -1
  17. package/dist/config-init.js +5595 -0
  18. package/dist/{context-a6px04s0.js → context-vhcstgs3.js} +5758 -4727
  19. package/dist/{derive-budgets-fhk00zv8.js → derive-budgets-rjjz5f7y.js} +2 -2
  20. package/dist/features/magic-context/compaction-marker.d.ts.map +1 -1
  21. package/dist/features/magic-context/memory/types.d.ts +1 -0
  22. package/dist/features/magic-context/memory/types.d.ts.map +1 -1
  23. package/dist/features/magic-context/message-index.d.ts +2 -0
  24. package/dist/features/magic-context/message-index.d.ts.map +1 -1
  25. package/dist/features/magic-context/migration-v3-perf-schema.d.ts +8 -0
  26. package/dist/features/magic-context/migration-v3-perf-schema.d.ts.map +1 -0
  27. package/dist/features/magic-context/migration-v4-temporal-decisions.d.ts +12 -0
  28. package/dist/features/magic-context/migration-v4-temporal-decisions.d.ts.map +1 -0
  29. package/dist/features/magic-context/migrations.d.ts.map +1 -1
  30. package/dist/features/magic-context/overflow-detection.d.ts +6 -0
  31. package/dist/features/magic-context/overflow-detection.d.ts.map +1 -1
  32. package/dist/features/magic-context/reclaim-protection.d.ts +15 -10
  33. package/dist/features/magic-context/reclaim-protection.d.ts.map +1 -1
  34. package/dist/features/magic-context/session-cache-ttl.d.ts +4 -2
  35. package/dist/features/magic-context/session-cache-ttl.d.ts.map +1 -1
  36. package/dist/features/magic-context/session-project-storage.d.ts +8 -2
  37. package/dist/features/magic-context/session-project-storage.d.ts.map +1 -1
  38. package/dist/features/magic-context/storage-db.d.ts +1 -1
  39. package/dist/features/magic-context/storage-db.d.ts.map +1 -1
  40. package/dist/features/magic-context/storage-historian-runs.d.ts +2 -0
  41. package/dist/features/magic-context/storage-historian-runs.d.ts.map +1 -1
  42. package/dist/features/magic-context/storage-meta-persisted.d.ts +12 -0
  43. package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
  44. package/dist/features/magic-context/storage-meta-session.d.ts +6 -0
  45. package/dist/features/magic-context/storage-meta-session.d.ts.map +1 -1
  46. package/dist/features/magic-context/storage-ops.d.ts +2 -0
  47. package/dist/features/magic-context/storage-ops.d.ts.map +1 -1
  48. package/dist/features/magic-context/storage-session-tables.d.ts.map +1 -1
  49. package/dist/features/magic-context/storage-tags.d.ts +17 -4
  50. package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
  51. package/dist/features/magic-context/storage.d.ts +2 -2
  52. package/dist/features/magic-context/storage.d.ts.map +1 -1
  53. package/dist/features/magic-context/temporal-decisions.d.ts +10 -0
  54. package/dist/features/magic-context/temporal-decisions.d.ts.map +1 -0
  55. package/dist/features/magic-context/tool-definition-tokens.d.ts +3 -0
  56. package/dist/features/magic-context/tool-definition-tokens.d.ts.map +1 -1
  57. package/dist/features/magic-context/transform-decision-log.d.ts +3 -1
  58. package/dist/features/magic-context/transform-decision-log.d.ts.map +1 -1
  59. package/dist/hooks/magic-context/active-anthropic-turn.d.ts +8 -0
  60. package/dist/hooks/magic-context/active-anthropic-turn.d.ts.map +1 -0
  61. package/dist/hooks/magic-context/apply-operations.d.ts +15 -0
  62. package/dist/hooks/magic-context/apply-operations.d.ts.map +1 -1
  63. package/dist/hooks/magic-context/auto-search-deadline.d.ts +10 -3
  64. package/dist/hooks/magic-context/auto-search-deadline.d.ts.map +1 -1
  65. package/dist/hooks/magic-context/auto-search-runner.d.ts +1 -1
  66. package/dist/hooks/magic-context/auto-search-runner.d.ts.map +1 -1
  67. package/dist/hooks/magic-context/caveman-cleanup.d.ts.map +1 -1
  68. package/dist/hooks/magic-context/channel2-cycle.d.ts +2 -0
  69. package/dist/hooks/magic-context/channel2-cycle.d.ts.map +1 -1
  70. package/dist/hooks/magic-context/compaction-marker-manager.d.ts.map +1 -1
  71. package/dist/hooks/magic-context/compartment-render-epoch.d.ts +8 -0
  72. package/dist/hooks/magic-context/compartment-render-epoch.d.ts.map +1 -1
  73. package/dist/hooks/magic-context/compartment-runner-partial-recomp.d.ts.map +1 -1
  74. package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -1
  75. package/dist/hooks/magic-context/compartment-runner-types.d.ts +3 -5
  76. package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
  77. package/dist/hooks/magic-context/compartment-runner.d.ts +2 -1
  78. package/dist/hooks/magic-context/compartment-runner.d.ts.map +1 -1
  79. package/dist/hooks/magic-context/compartment-trigger.d.ts +3 -1
  80. package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
  81. package/dist/hooks/magic-context/ctx-reduce-availability.d.ts +12 -0
  82. package/dist/hooks/magic-context/ctx-reduce-availability.d.ts.map +1 -1
  83. package/dist/hooks/magic-context/decision-calibration.d.ts +3 -0
  84. package/dist/hooks/magic-context/decision-calibration.d.ts.map +1 -1
  85. package/dist/hooks/magic-context/emergency-drop.d.ts +2 -0
  86. package/dist/hooks/magic-context/emergency-drop.d.ts.map +1 -1
  87. package/dist/hooks/magic-context/emergency-fail-closed.d.ts +21 -1
  88. package/dist/hooks/magic-context/emergency-fail-closed.d.ts.map +1 -1
  89. package/dist/hooks/magic-context/final-wire-token-estimate.d.ts +32 -1
  90. package/dist/hooks/magic-context/final-wire-token-estimate.d.ts.map +1 -1
  91. package/dist/hooks/magic-context/heuristic-cleanup.d.ts +2 -0
  92. package/dist/hooks/magic-context/heuristic-cleanup.d.ts.map +1 -1
  93. package/dist/hooks/magic-context/historian-drain-gate.d.ts +11 -0
  94. package/dist/hooks/magic-context/historian-drain-gate.d.ts.map +1 -0
  95. package/dist/hooks/magic-context/inject-compartments.d.ts +10 -8
  96. package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
  97. package/dist/hooks/magic-context/latest-assistant-turn.d.ts +25 -0
  98. package/dist/hooks/magic-context/latest-assistant-turn.d.ts.map +1 -0
  99. package/dist/hooks/magic-context/lkg-measured-request.d.ts +69 -0
  100. package/dist/hooks/magic-context/lkg-measured-request.d.ts.map +1 -0
  101. package/dist/hooks/magic-context/lkg-replay-fit.d.ts +118 -0
  102. package/dist/hooks/magic-context/lkg-replay-fit.d.ts.map +1 -0
  103. package/dist/hooks/magic-context/lkg-replay.d.ts +2 -0
  104. package/dist/hooks/magic-context/lkg-replay.d.ts.map +1 -1
  105. package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
  106. package/dist/hooks/magic-context/read-session-formatting.d.ts +3 -0
  107. package/dist/hooks/magic-context/read-session-formatting.d.ts.map +1 -1
  108. package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts.map +1 -1
  109. package/dist/hooks/magic-context/reasoning-budget-status.d.ts +15 -0
  110. package/dist/hooks/magic-context/reasoning-budget-status.d.ts.map +1 -0
  111. package/dist/hooks/magic-context/reasoning-budget.d.ts +40 -0
  112. package/dist/hooks/magic-context/reasoning-budget.d.ts.map +1 -0
  113. package/dist/hooks/magic-context/reasoning-removal.d.ts +6 -6
  114. package/dist/hooks/magic-context/reasoning-removal.d.ts.map +1 -1
  115. package/dist/hooks/magic-context/recomp-orchestrator.d.ts +2 -0
  116. package/dist/hooks/magic-context/recomp-orchestrator.d.ts.map +1 -1
  117. package/dist/hooks/magic-context/sentinel.d.ts +2 -0
  118. package/dist/hooks/magic-context/sentinel.d.ts.map +1 -1
  119. package/dist/hooks/magic-context/strip-content.d.ts +7 -3
  120. package/dist/hooks/magic-context/strip-content.d.ts.map +1 -1
  121. package/dist/hooks/magic-context/supersession-reclaim.d.ts +4 -0
  122. package/dist/hooks/magic-context/supersession-reclaim.d.ts.map +1 -1
  123. package/dist/hooks/magic-context/tag-messages.d.ts +13 -0
  124. package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
  125. package/dist/hooks/magic-context/tail-hygiene-walk.d.ts +5 -0
  126. package/dist/hooks/magic-context/tail-hygiene-walk.d.ts.map +1 -1
  127. package/dist/hooks/magic-context/temporal-awareness.d.ts +6 -3
  128. package/dist/hooks/magic-context/temporal-awareness.d.ts.map +1 -1
  129. package/dist/hooks/magic-context/temporal-served-projection.d.ts +4 -0
  130. package/dist/hooks/magic-context/temporal-served-projection.d.ts.map +1 -0
  131. package/dist/hooks/magic-context/tool-reclaim.d.ts +2 -0
  132. package/dist/hooks/magic-context/tool-reclaim.d.ts.map +1 -1
  133. package/dist/hooks/magic-context/transform-compartment-phase.d.ts +3 -28
  134. package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
  135. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +34 -12
  136. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  137. package/dist/hooks/magic-context/transform.d.ts +11 -5
  138. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  139. package/dist/hooks/magic-context/wrapup-orchestrator.d.ts.map +1 -1
  140. package/dist/{index-fg34g6a5.js → index-1j34a56j.js} +49 -8
  141. package/dist/index-33gprt9g.js +30 -0
  142. package/dist/{index-zx63j2e2.js → index-5cep2r9n.js} +3 -2
  143. package/dist/{index-5pg0acf7.js → index-amycb7b1.js} +1 -1
  144. package/dist/{index-wgt4gamw.js → index-dr0gepzw.js} +507 -53
  145. package/dist/{index-1vs6anwz.js → index-n0vnzz6h.js} +2 -1
  146. package/dist/{index-977gxfz0.js → index-ramz5kkm.js} +1 -1
  147. package/dist/{index-by6h2pav.js → index-wtb9hzk6.js} +499 -284
  148. package/dist/{index-3wagyrnj.js → index-x37vg474.js} +5 -1
  149. package/dist/{index-me3zcj5t.js → index-z2g20msd.js} +4 -8
  150. package/dist/index.js +1 -1
  151. package/dist/{message-time-backfill-5ewk0axe.js → message-time-backfill-phrwp2fz.js} +2 -2
  152. package/dist/{model-resolution-5haaxnpt.js → model-resolution-wazv26n0.js} +1 -1
  153. package/dist/plugin/rpc-handlers.d.ts +4 -0
  154. package/dist/plugin/rpc-handlers.d.ts.map +1 -1
  155. package/dist/{read-session-chunk-apjwrttc.js → read-session-chunk-82rkqa8j.js} +4 -4
  156. package/dist/{recomp-orchestrator-gyeevxaw.js → recomp-orchestrator-vc5dkzy2.js} +9 -9
  157. package/dist/{send-session-notification-y29y9fsr.js → send-session-notification-rnc4nrsr.js} +3 -3
  158. package/dist/shared/auto-search-lifecycle.d.ts +7 -0
  159. package/dist/shared/auto-search-lifecycle.d.ts.map +1 -0
  160. package/dist/shared/cache-ttl-display.d.ts +6 -4
  161. package/dist/shared/cache-ttl-display.d.ts.map +1 -1
  162. package/dist/shared/harness.d.ts +1 -1
  163. package/dist/shared/harness.d.ts.map +1 -1
  164. package/dist/shared/historian-tool-expansions.d.ts +1 -1
  165. package/dist/shared/historian-tool-expansions.d.ts.map +1 -1
  166. package/dist/shared/historian-tool-template.d.ts +2 -2
  167. package/dist/shared/historian-tool-template.d.ts.map +1 -1
  168. package/dist/shared/model-cache-ttl.d.ts +1 -1
  169. package/dist/shared/model-cache-ttl.d.ts.map +1 -1
  170. package/dist/shared/model-resolution.d.ts +6 -3
  171. package/dist/shared/model-resolution.d.ts.map +1 -1
  172. package/dist/shared/model-suggestion-retry.d.ts +2 -0
  173. package/dist/shared/model-suggestion-retry.d.ts.map +1 -1
  174. package/dist/shared/protected-tools-policy.d.ts +6 -0
  175. package/dist/shared/protected-tools-policy.d.ts.map +1 -0
  176. package/dist/shared/provider-output-failure.d.ts +19 -0
  177. package/dist/shared/provider-output-failure.d.ts.map +1 -0
  178. package/dist/shared/sqlite.d.ts +14 -1
  179. package/dist/shared/sqlite.d.ts.map +1 -1
  180. package/dist/shared/temporal-upgrade-fixture.d.ts +19 -0
  181. package/dist/shared/temporal-upgrade-fixture.d.ts.map +1 -0
  182. package/dist/shared/window-geometry.d.ts +4 -0
  183. package/dist/shared/window-geometry.d.ts.map +1 -1
  184. package/dist/shared/write-transaction-timing.d.ts +8 -1
  185. package/dist/shared/write-transaction-timing.d.ts.map +1 -1
  186. package/dist/tools/ctx-expand/render.d.ts.map +1 -1
  187. package/dist/tools/ctx-reduce/tools.d.ts +2 -0
  188. package/dist/tools/ctx-reduce/tools.d.ts.map +1 -1
  189. package/dist/v2/fold/host-media.d.ts +4 -0
  190. package/dist/v2/fold/host-media.d.ts.map +1 -1
  191. package/dist/v2/fold/memory-cache.d.ts +70 -0
  192. package/dist/v2/fold/memory-cache.d.ts.map +1 -0
  193. package/dist/v2/fold/native-codec.d.ts +10 -0
  194. package/dist/v2/fold/native-codec.d.ts.map +1 -0
  195. package/dist/v2/fold/native-replay.d.ts +58 -0
  196. package/dist/v2/fold/native-replay.d.ts.map +1 -0
  197. package/dist/v2/fold/policy.d.ts +24 -0
  198. package/dist/v2/fold/policy.d.ts.map +1 -0
  199. package/dist/v2/hidden-child-native.d.ts +7 -0
  200. package/dist/v2/hidden-child-native.d.ts.map +1 -1
  201. package/dist/v2/hidden-child-record.d.ts +19 -0
  202. package/dist/v2/hidden-child-record.d.ts.map +1 -1
  203. package/dist/v2/hidden-completion.d.ts.map +1 -1
  204. package/dist/v2/hooks/context.d.ts.map +1 -1
  205. package/dist/v2/hooks/hidden-child.d.ts +46 -2
  206. package/dist/v2/hooks/hidden-child.d.ts.map +1 -1
  207. package/dist/v2/hooks/payload.d.ts.map +1 -1
  208. package/dist/v2/hooks/store.d.ts.map +1 -1
  209. package/dist/v2/hooks/tools.d.ts.map +1 -1
  210. package/dist/v2/hooks/types.d.ts +14 -0
  211. package/dist/v2/hooks/types.d.ts.map +1 -1
  212. package/dist/v2/server.js +13226 -11340
  213. package/dist/v2/store-reader.d.ts +16 -0
  214. package/dist/v2/store-reader.d.ts.map +1 -1
  215. package/dist/v2/tool-result.d.ts +8 -0
  216. package/dist/v2/tool-result.d.ts.map +1 -0
  217. package/dist/web/api.d.ts +6 -0
  218. package/dist/web/api.d.ts.map +1 -1
  219. package/dist/web/context-store.d.ts +13 -0
  220. package/dist/web/context-store.d.ts.map +1 -1
  221. package/dist/web/display-path.d.ts +28 -0
  222. package/dist/web/display-path.d.ts.map +1 -0
  223. package/dist/web/entry-args.d.ts +33 -0
  224. package/dist/web/entry-args.d.ts.map +1 -0
  225. package/dist/web/fixtures.d.ts +41 -0
  226. package/dist/web/fixtures.d.ts.map +1 -1
  227. package/dist/web/host-opencode.d.ts +9 -0
  228. package/dist/web/host-opencode.d.ts.map +1 -1
  229. package/dist/web/host-pi.d.ts +2 -0
  230. package/dist/web/host-pi.d.ts.map +1 -1
  231. package/dist/web/main.d.ts +4 -6
  232. package/dist/web/main.d.ts.map +1 -1
  233. package/dist/web/main.js +1477 -130
  234. package/dist/web/memories.d.ts +18 -2
  235. package/dist/web/memories.d.ts.map +1 -1
  236. package/dist/web/message-stats.d.ts +45 -0
  237. package/dist/web/message-stats.d.ts.map +1 -0
  238. package/dist/web/ui/index.html +1 -0
  239. package/dist/web/ui/panel.css +7 -0
  240. package/dist/web/ui/panel.js +332 -124
  241. package/dist/web/views.d.ts +73 -9
  242. package/dist/web/views.d.ts.map +1 -1
  243. package/dist/{wrapup-orchestrator-z9sqpqjf.js → wrapup-orchestrator-x9xamts2.js} +10 -9
  244. package/package.json +7 -2
  245. package/src/config/index.test.ts +257 -126
  246. package/src/config/index.ts +45 -39
  247. package/src/config/legacy-harness-blocks.test.ts +78 -0
  248. package/src/config/legacy-harness-blocks.ts +71 -0
  249. package/src/config/live-run-config.test.ts +49 -5
  250. package/src/config/live-run-config.ts +29 -0
  251. package/src/config/live-snapshot.ts +5 -1
  252. package/src/config/profiles.ts +1 -1
  253. package/src/config/project-config-trust-boundary.test.ts +2 -2
  254. package/src/config/project-security.hostile-matrix.test.ts +51 -65
  255. package/src/config/project-security.test.ts +6 -1
  256. package/src/config/project-security.ts +13 -12
  257. package/src/config/protected-tokens.test.ts +1 -1
  258. package/src/config/raw-loader.test.ts +29 -352
  259. package/src/config/raw-loader.ts +17 -406
  260. package/src/config/removed-config-keys.test.ts +1 -1
  261. package/src/config/schema/magic-context.test.ts +60 -64
  262. package/src/config/schema/magic-context.ts +105 -137
  263. package/src/config/variable.ts +21 -12
  264. package/src/shared/auto-search-lifecycle.ts +27 -0
  265. package/src/shared/cache-ttl-display.test.ts +1 -1
  266. package/src/shared/cache-ttl-display.ts +17 -16
  267. package/src/shared/harness.ts +1 -1
  268. package/src/shared/historian-tool-defaults.json +6 -6
  269. package/src/shared/historian-tool-expansions.ts +65 -8
  270. package/src/shared/historian-tool-preview-defaults.json +13 -0
  271. package/src/shared/historian-tool-template.ts +48 -14
  272. package/src/shared/model-cache-ttl.test.ts +2 -2
  273. package/src/shared/model-cache-ttl.ts +8 -4
  274. package/src/shared/model-resolution.test.ts +22 -32
  275. package/src/shared/model-resolution.ts +14 -19
  276. package/src/shared/model-suggestion-retry.ts +63 -7
  277. package/src/shared/protected-tools-policy.ts +25 -0
  278. package/src/shared/provider-output-failure.ts +176 -0
  279. package/src/shared/sqlite-acquisition-routing.test.ts +18 -0
  280. package/src/shared/sqlite.ts +100 -15
  281. package/src/shared/status-detail-text.test.ts +1 -1
  282. package/src/shared/status-view.test.ts +1 -1
  283. package/src/shared/temporal-upgrade-fixture.ts +50 -0
  284. package/src/shared/window-geometry.ts +10 -0
  285. package/src/shared/write-transaction-attribution.test.ts +2 -2
  286. package/src/shared/write-transaction-timing.ts +25 -1
  287. package/dist/features/magic-context/window-report-ledger.d.ts +0 -70
  288. package/dist/features/magic-context/window-report-ledger.d.ts.map +0 -1
  289. package/dist/index-e1q8002h.js +0 -16
  290. package/src/config/misplaced-agent-model.test.ts +0 -55
@@ -1,23 +1,65 @@
1
1
  import {
2
- getHarness
2
+ canonicalModelIdentity,
3
+ UNKNOWN_FIT_RATIO,
4
+ resolveDecisionCalibration,
5
+ hasMeasuredDecisionCalibration,
6
+ providerMass
7
+ } from "./index-x37vg474.js";
8
+ import {
9
+ getHarness,
10
+ sessionLog
3
11
  } from "./index-qbkzdkk0.js";
4
12
  import {
13
+ isKnownAutocommit,
5
14
  openCodeDbExists,
6
15
  withReadOnlySessionDb,
7
16
  getRawSessionMessageCountFromDb,
8
17
  getMessageTimesFromOpenCodeDb
9
- } from "./index-977gxfz0.js";
10
- import {
11
- canonicalModelIdentity,
12
- UNKNOWN_FIT_RATIO,
13
- resolveDecisionCalibration,
14
- providerMass
15
- } from "./index-3wagyrnj.js";
18
+ } from "./index-ramz5kkm.js";
19
+
20
+ // src/shared/protected-tools-policy.ts
21
+ var DEFAULT_PROTECTED_TOOLS = {
22
+ todowrite: 1,
23
+ mmc_reduce: 3
24
+ };
25
+ function normalizeProtectedToolName(name) {
26
+ const lowered = (name ?? "").toLowerCase().replace(/^mcp_/, "");
27
+ return lowered === "ctx_reduce" ? "mmc_reduce" : lowered;
28
+ }
29
+ function mergeProtectedTools(...maps) {
30
+ return Object.fromEntries([DEFAULT_PROTECTED_TOOLS, ...maps].flatMap((map) => Object.entries(map ?? {}).map(([name, count]) => [
31
+ normalizeProtectedToolName(name),
32
+ count
33
+ ])));
34
+ }
16
35
 
17
36
  // src/features/magic-context/reclaim-protection.ts
18
- var CTX_REDUCE_KEEP = 3;
19
- function newestCtxReduceTagNumbers(tags) {
20
- return new Set(tags.filter((tag) => tag.toolName === "mmc_reduce").sort((left, right) => right.tagNumber - left.tagNumber).slice(0, CTX_REDUCE_KEEP).map((tag) => tag.tagNumber));
37
+ var CTX_REDUCE_KEEP = DEFAULT_PROTECTED_TOOLS.mmc_reduce;
38
+ function adoptedProtectedToolsPolicy(current, previous, rebuilding, hasBaseline) {
39
+ if (rebuilding || !hasBaseline)
40
+ return mergeProtectedTools(current);
41
+ return { ...previous ?? { todowrite: 0, mmc_reduce: 3 } };
42
+ }
43
+ function protectedToolTagNumbers(tags, protectedTools) {
44
+ const counts = mergeProtectedTools(protectedTools);
45
+ const protectedTags = new Set;
46
+ for (const tag of [...tags].sort((left, right) => right.tagNumber - left.tagNumber)) {
47
+ if (tag.status !== undefined && tag.status !== "active")
48
+ continue;
49
+ if (tag.type !== undefined && tag.type !== "tool")
50
+ continue;
51
+ const name = normalizeProtectedToolName(tag.toolName);
52
+ if (!Object.hasOwn(counts, name) || counts[name] <= 0)
53
+ continue;
54
+ protectedTags.add(tag.tagNumber);
55
+ counts[name] -= 1;
56
+ }
57
+ return protectedTags;
58
+ }
59
+ function protectedToolTokenCount(tags, counts, calibration) {
60
+ const protectedTags = protectedToolTagNumbers(tags, counts);
61
+ const tokens = tags.reduce((sum, tag) => sum + (protectedTags.has(tag.tagNumber) ? tag.tokenCount ?? 0 : 0), 0);
62
+ return calibration && hasMeasuredDecisionCalibration(calibration) ? providerMass({ tools: tokens }, calibration) : 0;
21
63
  }
22
64
 
23
65
  // src/hooks/magic-context/read-session-formatting.ts
@@ -324,6 +366,12 @@ function getTokenizer() {
324
366
  function estimateTokensHeuristically(text) {
325
367
  return Math.ceil(text.length / 3.5);
326
368
  }
369
+ function hasTokenizerForFit() {
370
+ return getTokenizer() !== undefined;
371
+ }
372
+ function tokenCountUsesByteBound(text) {
373
+ return text.length > 1024 * 1024 || /[\p{L}\p{N}]{16385}/u.test(text);
374
+ }
327
375
  function estimateTokens(text) {
328
376
  if (!text)
329
377
  return 0;
@@ -1064,10 +1112,10 @@ function messageIdForTag(tag) {
1064
1112
  return tag.toolOwnerMessageId;
1065
1113
  return contentTagOwnerMessageId(tag.messageId);
1066
1114
  }
1067
- function resolveProtectedTagNumbers(tags, protectedTagNumbersInput) {
1115
+ function resolveProtectedTagNumbers(tags, protectedTagNumbersInput, protectedToolTags) {
1068
1116
  const protectedNumbers = new Set(protectedTagNumbersInput);
1069
- const protectedCtxReduceTags = newestCtxReduceTagNumbers(tags.filter((tag) => tag.status === "active" && tag.type === "tool"));
1070
- for (const tagNumber of protectedCtxReduceTags)
1117
+ const protectedExemplars = protectedToolTags ?? protectedToolTagNumbers(tags.filter((tag) => tag.status === "active" && tag.type === "tool"));
1118
+ for (const tagNumber of protectedExemplars)
1071
1119
  protectedNumbers.add(tagNumber);
1072
1120
  return protectedNumbers;
1073
1121
  }
@@ -1089,7 +1137,7 @@ function neighborhoodConsistent(args) {
1089
1137
  return args.orphanTagNumber >= previousMax && args.orphanTagNumber <= nextMin;
1090
1138
  }
1091
1139
  function buildTagAttribution(args) {
1092
- const protectedNumbers = resolveProtectedTagNumbers(args.tags, args.protectedTagNumbers);
1140
+ const protectedNumbers = resolveProtectedTagNumbers(args.tags, args.protectedTagNumbers, args.protectedToolTags);
1093
1141
  const messageTags = new Map;
1094
1142
  const exactToolTags = new Map;
1095
1143
  const orphanTagsByCall = new Map;
@@ -1261,7 +1309,8 @@ function measureWithReplay(input, replay) {
1261
1309
  messages: input.messages,
1262
1310
  tags: input.tags,
1263
1311
  toolIdentities,
1264
- protectedTagNumbers: input.protectedTagNumbers
1312
+ protectedTagNumbers: input.protectedTagNumbers,
1313
+ protectedToolTags: input.protectedToolTags
1265
1314
  });
1266
1315
  const toolOutputs = input.messages.map((message, index) => message.parts.map((part, partIndex) => unchanged[index] ? replay?.measured.toolOutputs[index][partIndex] ?? null : isRecord(part) ? toolOutputText(part) : null));
1267
1316
  const outputByPart = new Map;
@@ -1632,6 +1681,13 @@ function freezeTailHygieneMeasurement(measured) {
1632
1681
  };
1633
1682
  }
1634
1683
  function refreshTailHygieneBaseline(input) {
1684
+ const protectedToolsPolicy = adoptedProtectedToolsPolicy(input.protectedTools, input.previous?.protectedToolsPolicy, input.cacheBusting, !!input.previous);
1685
+ const protectedToolTags = input.protectedToolTags ?? protectedToolTagNumbers(input.tags, protectedToolsPolicy);
1686
+ input = {
1687
+ ...input,
1688
+ protectedToolTags,
1689
+ protectedTagNumbers: new Set([...input.protectedTagNumbers, ...protectedToolTags])
1690
+ };
1635
1691
  const pendingDropTagNumbers = input.pendingDropTagNumbers ?? new Set;
1636
1692
  const cached = input.previous ? baselineMeasurementMemo.get(input.previous.baselineParts) : undefined;
1637
1693
  const hit = !input.cacheBusting && cached && sameReplayMessages(cached.messages, input.messages) && sameReplayValue(cached.tags, input.tags) && sameNumbers(cached.protectedTagNumbers, input.protectedTagNumbers) && sameNumbers(cached.pendingDropTagNumbers, pendingDropTagNumbers);
@@ -1694,7 +1750,8 @@ function refreshTailHygieneBaseline(input) {
1694
1750
  generationInvalidated: false,
1695
1751
  contentSignature: measured.contentSignature,
1696
1752
  channel1PostReduceGrace: input.previous?.channel1PostReduceGrace,
1697
- lastPrefixMismatch: mismatch
1753
+ lastPrefixMismatch: mismatch,
1754
+ protectedToolsPolicy
1698
1755
  };
1699
1756
  };
1700
1757
  if (input.cacheBusting || !input.previous)
@@ -2126,7 +2183,7 @@ function planEmergencyDrop(input) {
2126
2183
  reserved.add(nums[i]);
2127
2184
  }
2128
2185
  }
2129
- const protectedCtxReduceTags = newestCtxReduceTagNumbers(floorTags.filter((tag) => tag.status === "active" && tag.type === "tool"));
2186
+ const protectedTags = input.protectedToolTags ?? protectedToolTagNumbers(floorTags, input.protectedTools);
2130
2187
  const byTier = { 1: [], 2: [], 3: [] };
2131
2188
  for (const tag of tags) {
2132
2189
  if (tag.status !== "active" || tag.type !== "tool")
@@ -2137,7 +2194,7 @@ function planEmergencyDrop(input) {
2137
2194
  continue;
2138
2195
  }
2139
2196
  }
2140
- if (protectedCtxReduceTags.has(tag.tagNumber))
2197
+ if (protectedTags.has(tag.tagNumber))
2141
2198
  continue;
2142
2199
  const tier = resolveToolTier(tag.toolName);
2143
2200
  if ((tier === 1 || tier === 2) && reserved.has(tag.tagNumber))
@@ -2182,6 +2239,158 @@ function measureEmergencyTag(tag, target, calibration, skeleton) {
2182
2239
  return { ...tag, servedTokens: served, reclaimableTokens: 0 };
2183
2240
  }
2184
2241
 
2242
+ // src/features/magic-context/migration-v3-perf-schema.ts
2243
+ var V3_REDUNDANT_INDEXES = [
2244
+ "idx_tags_session_tag_number",
2245
+ "idx_compartments_session",
2246
+ "idx_pending_ops_session",
2247
+ "idx_source_contents_session",
2248
+ "idx_compression_depth_session",
2249
+ "idx_transform_decisions_session_harness",
2250
+ "idx_project_key_files_project"
2251
+ ];
2252
+ var indexes = [
2253
+ ["message_fts_rowid_map", "idx_message_fts_rowid_map_session_rowid", "session_id, fts_rowid"]
2254
+ ];
2255
+ function installV3PerfSchema(db) {
2256
+ const schema = new Map(db.prepare("SELECT name, sql FROM sqlite_master").all().map((row) => [row.name, row.sql]));
2257
+ for (const [table, name, columns] of indexes) {
2258
+ if (schema.has(table) && !schema.has(name))
2259
+ db.exec(`CREATE INDEX ${name} ON ${table}(${columns})`);
2260
+ }
2261
+ for (const name of V3_REDUNDANT_INDEXES) {
2262
+ if (schema.has(name))
2263
+ db.exec(`DROP INDEX ${name}`);
2264
+ }
2265
+ }
2266
+ var tagOrderIndexes = new WeakMap;
2267
+ function tagOrderConstraintIndex(db) {
2268
+ const version = db.prepare("PRAGMA schema_version").get().schema_version;
2269
+ const cacheable = isKnownAutocommit(db);
2270
+ if (!cacheable)
2271
+ tagOrderIndexes.delete(db);
2272
+ const cached = tagOrderIndexes.get(db);
2273
+ if (cached?.schemaVersion === version)
2274
+ return cached.name;
2275
+ const candidates = db.prepare("PRAGMA index_list(tags)").all();
2276
+ for (const candidate of candidates) {
2277
+ if (!candidate.unique || candidate.origin !== "u")
2278
+ continue;
2279
+ const quoted = `"${candidate.name.replaceAll('"', '""')}"`;
2280
+ const columns = db.prepare(`PRAGMA index_info(${quoted})`).all();
2281
+ if (columns.length !== 2 || columns[0]?.name !== "session_id" || columns[1]?.name !== "tag_number")
2282
+ continue;
2283
+ if (cacheable)
2284
+ tagOrderIndexes.set(db, { schemaVersion: version, name: quoted });
2285
+ return quoted;
2286
+ }
2287
+ throw new Error("tags lacks its UNIQUE(session_id, tag_number) ordering constraint");
2288
+ }
2289
+
2290
+ // src/features/magic-context/storage-ops.ts
2291
+ var queuePendingOpStatements = new WeakMap;
2292
+ var queueUnchangedDropStatements = new WeakMap;
2293
+ var getPendingOpsStatements = new WeakMap;
2294
+ var getPendingOpsCountStatements = new WeakMap;
2295
+ var clearPendingOpsStatements = new WeakMap;
2296
+ var removePendingOpStatements = new WeakMap;
2297
+ var hasPendingDropOpsStatements = new WeakMap;
2298
+ function getQueuePendingOpStatement(db) {
2299
+ let stmt = queuePendingOpStatements.get(db);
2300
+ if (!stmt) {
2301
+ stmt = db.prepare(`INSERT INTO pending_ops (session_id, tag_id, operation, queued_at, harness)
2302
+ SELECT ?, ?, ?, ?, ? WHERE NOT EXISTS (
2303
+ SELECT 1 FROM pending_ops WHERE session_id = ? AND tag_id = ? AND operation = ?
2304
+ )`);
2305
+ queuePendingOpStatements.set(db, stmt);
2306
+ }
2307
+ return stmt;
2308
+ }
2309
+ function getPendingOpsStatement(db) {
2310
+ let stmt = getPendingOpsStatements.get(db);
2311
+ if (!stmt) {
2312
+ stmt = db.prepare("SELECT id, session_id, tag_id, operation, queued_at FROM pending_ops WHERE session_id = ? ORDER BY queued_at ASC, id ASC");
2313
+ getPendingOpsStatements.set(db, stmt);
2314
+ }
2315
+ return stmt;
2316
+ }
2317
+ function getClearPendingOpsStatement(db) {
2318
+ let stmt = clearPendingOpsStatements.get(db);
2319
+ if (!stmt) {
2320
+ stmt = db.prepare("DELETE FROM pending_ops WHERE session_id = ?");
2321
+ clearPendingOpsStatements.set(db, stmt);
2322
+ }
2323
+ return stmt;
2324
+ }
2325
+ function getRemovePendingOpStatement(db) {
2326
+ let stmt = removePendingOpStatements.get(db);
2327
+ if (!stmt) {
2328
+ stmt = db.prepare("DELETE FROM pending_ops WHERE session_id = ? AND tag_id = ?");
2329
+ removePendingOpStatements.set(db, stmt);
2330
+ }
2331
+ return stmt;
2332
+ }
2333
+ function isPendingOpRow(row) {
2334
+ if (row === null || typeof row !== "object")
2335
+ return false;
2336
+ const r = row;
2337
+ return typeof r.id === "number" && typeof r.session_id === "string" && typeof r.tag_id === "number" && typeof r.operation === "string" && typeof r.queued_at === "number";
2338
+ }
2339
+ function toPendingOp(row) {
2340
+ if (row.operation !== "drop") {
2341
+ sessionLog(row.session_id, `unknown pending operation "${row.operation}"; ignoring`);
2342
+ return null;
2343
+ }
2344
+ return {
2345
+ id: row.id,
2346
+ sessionId: row.session_id,
2347
+ tagId: row.tag_id,
2348
+ operation: row.operation,
2349
+ queuedAt: row.queued_at
2350
+ };
2351
+ }
2352
+ function queuePendingOp(db, sessionId, tagId, operation, queuedAt = Date.now()) {
2353
+ getQueuePendingOpStatement(db).run(sessionId, tagId, operation, queuedAt, getHarness(), sessionId, tagId, operation);
2354
+ }
2355
+ function queuePendingDropForUnchangedTag(db, sessionId, tag) {
2356
+ let statement = queueUnchangedDropStatements.get(db);
2357
+ if (!statement) {
2358
+ statement = db.prepare(`INSERT INTO pending_ops (session_id, tag_id, operation, queued_at, harness)
2359
+ SELECT session_id, tag_number, 'drop', ?, ? FROM tags
2360
+ WHERE id = ? AND session_id = ? AND tag_number = ? AND message_id = ?
2361
+ AND type = ? AND tool_owner_message_id IS ? AND status = 'active'
2362
+ AND NOT EXISTS (
2363
+ SELECT 1 FROM pending_ops WHERE session_id = tags.session_id
2364
+ AND tag_id = tags.tag_number AND operation = 'drop'
2365
+ )`);
2366
+ queueUnchangedDropStatements.set(db, statement);
2367
+ }
2368
+ return statement.run(Date.now(), getHarness(), tag.id ?? null, sessionId, tag.tagNumber, tag.messageId, tag.type, tag.toolOwnerMessageId).changes > 0;
2369
+ }
2370
+ function getPendingOps(db, sessionId) {
2371
+ const rows = getPendingOpsStatement(db).all(sessionId).filter(isPendingOpRow);
2372
+ return rows.map(toPendingOp).filter((op) => op !== null);
2373
+ }
2374
+ function getPendingOpsCount(db, sessionId) {
2375
+ try {
2376
+ let statement = getPendingOpsCountStatements.get(db);
2377
+ if (!statement) {
2378
+ statement = db.prepare("SELECT COUNT(*) AS count FROM pending_ops WHERE session_id = ?");
2379
+ getPendingOpsCountStatements.set(db, statement);
2380
+ }
2381
+ const row = statement.get(sessionId);
2382
+ return typeof row?.count === "number" && Number.isFinite(row.count) ? row.count : null;
2383
+ } catch {
2384
+ return null;
2385
+ }
2386
+ }
2387
+ function clearPendingOps(db, sessionId) {
2388
+ getClearPendingOpsStatement(db).run(sessionId);
2389
+ }
2390
+ function removePendingOp(db, sessionId, tagId) {
2391
+ getRemovePendingOpStatement(db).run(sessionId, tagId);
2392
+ }
2393
+
2185
2394
  // src/features/magic-context/storage-tags.ts
2186
2395
  var insertTagStatements = new WeakMap;
2187
2396
  var updateTagStatusStatements = new WeakMap;
@@ -2328,8 +2537,7 @@ function getActiveToolTagsForAgeReclaim(db, sessionId) {
2328
2537
  reclaimableTokens: outputTokens === null && inputTokens === null ? null : (outputTokens ?? 0) + (inputTokens ?? 0)
2329
2538
  };
2330
2539
  });
2331
- const protectedCtxReduceTags = newestCtxReduceTagNumbers(tags);
2332
- return tags.filter((tag) => !protectedCtxReduceTags.has(tag.tagNumber));
2540
+ return tags;
2333
2541
  }
2334
2542
  function getTriggerTagTokenUpperBound(db, sessionId, floor = 0) {
2335
2543
  const sql = floor > 0 ? `SELECT
@@ -2429,6 +2637,17 @@ function getAllStatusTagTokenTotalsFlat(db, sessionId, floor = 0, calibration =
2429
2637
  }
2430
2638
  return { totals, nullMessageIds };
2431
2639
  }
2640
+ function getReasoningTokenEstimatesByMessage(db, sessionId, proseRatio) {
2641
+ const rows = db.prepare(`SELECT type, message_id, tool_owner_message_id, reasoning_token_count FROM tags WHERE session_id = ? AND reasoning_token_count IS NOT NULL`).all(sessionId);
2642
+ const totals = new Map;
2643
+ for (const row of rows) {
2644
+ if (row.type !== "message")
2645
+ continue;
2646
+ const id = ownerMessageIdForTagRow(row);
2647
+ totals.set(id, Math.max(totals.get(id) ?? 0, row.reasoning_token_count * proseRatio));
2648
+ }
2649
+ return totals;
2650
+ }
2432
2651
  function tagTokenCountIsNull(db, sessionId, tagNumber) {
2433
2652
  const row = db.prepare("SELECT token_count FROM tags WHERE session_id = ? AND tag_number = ?").get(sessionId, tagNumber);
2434
2653
  return row != null && row.token_count === null;
@@ -2765,9 +2984,9 @@ function foldShrunkPartTags(db, sessionId, messages) {
2765
2984
  result.foldedTagNumbers.sort((a, b) => a - b);
2766
2985
  return result;
2767
2986
  }
2768
- function markTagsCompactedByMessageIds(db, sessionId, messageIds) {
2987
+ function markTagsCompactedByMessageIds(db, sessionId, messageIds, eligibleTagNumbers) {
2769
2988
  const ids = new Set(messageIds);
2770
- if (ids.size === 0)
2989
+ if (ids.size === 0 || eligibleTagNumbers?.size === 0)
2771
2990
  return 0;
2772
2991
  const asciiLower = (value) => value.replace(/[A-Z]/g, (char) => char.toLowerCase());
2773
2992
  const foldedIds = new Set(Array.from(ids, asciiLower));
@@ -2793,7 +3012,7 @@ function markTagsCompactedByMessageIds(db, sessionId, messageIds) {
2793
3012
  const rows = db.prepare(`WITH ids AS MATERIALIZED (
2794
3013
  SELECT value AS source_id, lower(value) AS folded_id FROM json_each(?)
2795
3014
  )
2796
- SELECT id, message_id, tool_owner_message_id FROM tags INDEXED BY idx_tags_session_tag_number
3015
+ SELECT id, tag_number, message_id, tool_owner_message_id FROM tags INDEXED BY ${tagOrderConstraintIndex(db)}
2797
3016
  WHERE session_id = ? AND status IN ('active', 'dropped') AND (
2798
3017
  message_id IN (SELECT source_id FROM ids)
2799
3018
  OR tool_owner_message_id IN (SELECT source_id FROM ids)
@@ -2804,14 +3023,14 @@ function markTagsCompactedByMessageIds(db, sessionId, messageIds) {
2804
3023
  OR (? AND instr(message_id, ':') > 0)
2805
3024
  OR ?
2806
3025
  )`).all(JSON.stringify(Array.from(ids)), sessionId, Array.from(ids).some((id) => id.includes(":")) ? 1 : 0, nulPrefixes.size > 0 ? 1 : 0);
2807
- const candidates = rows.filter((row) => matches(row.message_id, row.tool_owner_message_id));
3026
+ const candidates = rows.filter((row) => (eligibleTagNumbers === undefined || eligibleTagNumbers.has(row.tag_number)) && matches(row.message_id, row.tool_owner_message_id));
2808
3027
  if (candidates.length === 0)
2809
3028
  return 0;
2810
3029
  const update = db.prepare(`UPDATE tags SET status = 'compacted'
2811
3030
  WHERE id = ? AND session_id = ?
2812
3031
  AND status IN ('active', 'dropped')
2813
3032
  AND message_id IS ? AND tool_owner_message_id IS ?
2814
- RETURNING id`);
3033
+ RETURNING tag_number`);
2815
3034
  let cursor = 0;
2816
3035
  let changed = 0;
2817
3036
  const batch = db.transaction(() => {
@@ -2819,8 +3038,11 @@ function markTagsCompactedByMessageIds(db, sessionId, messageIds) {
2819
3038
  let processed = 0;
2820
3039
  do {
2821
3040
  const row = candidates[cursor++];
2822
- if (update.get(row.id, sessionId, row.message_id, row.tool_owner_message_id))
3041
+ const retired = update.get(row.id, sessionId, row.message_id, row.tool_owner_message_id);
3042
+ if (retired) {
3043
+ removePendingOp(db, sessionId, retired.tag_number);
2823
3044
  changed++;
3045
+ }
2824
3046
  processed++;
2825
3047
  } while (cursor < candidates.length && processed < 128 && performance.now() - start < 8);
2826
3048
  });
@@ -2948,6 +3170,24 @@ function getTagsByNumbers(db, sessionId, tagNumbers) {
2948
3170
  const rows = db.prepare(`SELECT ${TAG_SELECT_COLUMNS} FROM tags WHERE session_id = ? AND tag_number IN (${placeholders}) ORDER BY tag_number ASC, id ASC`).all(sessionId, ...tagNumbers).filter(isTagRow);
2949
3171
  return rows.map(toTagEntry);
2950
3172
  }
3173
+ var newestToolTagNumberStatements = new WeakMap;
3174
+ function getNewestToolTagNumbers(db, sessionId, limit) {
3175
+ if (limit <= 0)
3176
+ return [];
3177
+ let statement = newestToolTagNumberStatements.get(db);
3178
+ if (!statement) {
3179
+ statement = db.prepare(`SELECT tag_number FROM tags
3180
+ WHERE session_id = ? AND type = 'tool'
3181
+ AND typeof(message_id) = 'text'
3182
+ AND typeof(status) = 'text'
3183
+ AND typeof(byte_size) IN ('integer', 'real')
3184
+ AND typeof(tag_number) IN ('integer', 'real')
3185
+ ORDER BY tag_number DESC
3186
+ LIMIT ?`);
3187
+ newestToolTagNumberStatements.set(db, statement);
3188
+ }
3189
+ return statement.all(sessionId, limit).map((row) => row.tag_number);
3190
+ }
2951
3191
  var droppedNumberStatements = new WeakMap;
2952
3192
  function getDroppedTagsByNumbers(db, sessionId, tagNumbers) {
2953
3193
  if (tagNumbers.length === 0)
@@ -3086,6 +3326,20 @@ function pickNearestPriorOwner(candidates, currentMessageId, times) {
3086
3326
  }
3087
3327
  // src/shared/historian-tool-defaults.json
3088
3328
  var historian_tool_defaults_default = {
3329
+ todowrite: 'Todos (${input.todos.count}): ${input.todos.each("${status}: ${content}")}',
3330
+ question: 'Asked user: ${input.questions[*].question.join(" / ")} → ${output}',
3331
+ task: "Task ${input.subagent_type}: ${input.prompt.truncate(600)} → ${output.truncate(200)}",
3332
+ ask: 'Asked: ${input.question} [options: ${input.options.join(" / ")}] ${input.text}${input.resolution} → ${output.truncate(300)}',
3333
+ peer_send: "PM ${input.recipient}: ${input.message}",
3334
+ board: 'Board ${input.verb}${input.board_lane}: ${input.ops.each("${op} ${lane_label} ${item}${props.text}${lane.items} ${state}${props.state}${lane.status}${id}${title}")}',
3335
+ room: "Room ${input.action} ${input.room_label}: ${input.room_detail}",
3336
+ work: "Work ${input.action} ${input.title}${input.id}: ${input.prompt.truncate(600)}${input.notes.truncate(600)} → ${output.truncate(160)}",
3337
+ knowhow: "Looked up how-to: ${input.query}${input.id}",
3338
+ mmc_note: "Note ${input.action} ${input.note_ids}: ${input.content} → ${output.truncate(160)}",
3339
+ mmc_memory: "Memory ${input.action} ${input.category} ${input.ids}: ${input.content} → ${output.truncate(160)}"
3340
+ };
3341
+ // src/shared/historian-tool-preview-defaults.json
3342
+ var historian_tool_preview_defaults_default = {
3089
3343
  todowrite: 'Todos (${input.todos.count}): ${input.todos.each("${status}: ${content}")}',
3090
3344
  question: 'Asked user: ${input.questions[*].question.join(" / ")} → ${output}',
3091
3345
  task: "Task ${input.subagent_type}: ${input.prompt} → ${output.truncate(200)}",
@@ -3178,7 +3432,7 @@ class Parser {
3178
3432
  } else
3179
3433
  break;
3180
3434
  }
3181
- const expression = { steps, cap: 300 };
3435
+ const expression = { steps };
3182
3436
  if (this.take(".each(")) {
3183
3437
  if (relative)
3184
3438
  return this.error();
@@ -3245,9 +3499,23 @@ function compiled(source) {
3245
3499
  function oneLine(value) {
3246
3500
  return value.replace(/[\r\n\u2028\u2029]+/g, " ");
3247
3501
  }
3248
- function truncate(value, cap) {
3502
+ function truncate(value, cap, legacyPreview = false) {
3249
3503
  const chars = Array.from(oneLine(value));
3250
- return chars.length > cap ? `${chars.slice(0, cap).join("")}…` : chars.join("");
3504
+ if (cap === undefined || chars.length <= cap)
3505
+ return chars.join("");
3506
+ if (legacyPreview)
3507
+ return `${chars.slice(0, cap).join("")}…`;
3508
+ let end = 0;
3509
+ for (let i = 0;i < Math.min(cap, chars.length); i++) {
3510
+ if (!".!?。!?".includes(chars[i]))
3511
+ continue;
3512
+ let next = i + 1;
3513
+ while (next < chars.length && `"'”’)]`.includes(chars[next]))
3514
+ next++;
3515
+ if (next <= cap && ("。!?".includes(chars[i]) || next === chars.length || /[ \t]/.test(chars[next])))
3516
+ end = next;
3517
+ }
3518
+ return `${end ? `${chars.slice(0, end).join("")} ` : ""}[… ${chars.length - end} more characters]`;
3251
3519
  }
3252
3520
  function scalar(value) {
3253
3521
  if (value === undefined)
@@ -3264,10 +3532,11 @@ function compactJson(value) {
3264
3532
  function field(value, key) {
3265
3533
  return value !== null && typeof value === "object" && !Array.isArray(value) && Object.hasOwn(value, key) ? value[key] : undefined;
3266
3534
  }
3267
- function render(nodes, root) {
3535
+ function render(nodes, root, legacyPreview) {
3268
3536
  return nodes.map((node) => {
3269
3537
  if (typeof node === "string")
3270
3538
  return node;
3539
+ const cap = node.cap ?? (legacyPreview ? 300 : undefined);
3271
3540
  let value = root;
3272
3541
  let list = false;
3273
3542
  for (const step of node.steps) {
@@ -3281,19 +3550,19 @@ function render(nodes, root) {
3281
3550
  }
3282
3551
  }
3283
3552
  if (node.count)
3284
- return truncate(Array.isArray(value) ? String(value.length) : "", node.cap);
3553
+ return truncate(Array.isArray(value) ? String(value.length) : "", cap, legacyPreview);
3285
3554
  if (node.each || list || node.join !== undefined) {
3286
3555
  if (!Array.isArray(value))
3287
3556
  return "";
3288
- const elements = value.slice(0, 10).map((item) => truncate(node.each ? render(node.each, item) : scalar(item), 300));
3289
- if (value.length > 10)
3557
+ const elements = value.slice(0, legacyPreview ? 10 : undefined).map((item) => truncate(node.each ? render(node.each, item, legacyPreview) : scalar(item), legacyPreview ? 300 : undefined, legacyPreview));
3558
+ if (legacyPreview && value.length > 10)
3290
3559
  elements.push(`… +${value.length - 10} more`);
3291
- return truncate(elements.join(node.join ?? (node.each ? "; " : ", ")), node.cap);
3560
+ return truncate(elements.join(node.join ?? (node.each ? "; " : ", ")), cap, legacyPreview);
3292
3561
  }
3293
- return truncate(scalar(value), node.cap);
3562
+ return truncate(scalar(value), cap, legacyPreview);
3294
3563
  }).join("");
3295
3564
  }
3296
- function renderToolTemplate(source, input, output) {
3565
+ function renderToolTemplate(source, input, output, legacyPreview = false) {
3297
3566
  const nodes = compiled(source);
3298
3567
  if (!nodes)
3299
3568
  return null;
@@ -3308,22 +3577,53 @@ function renderToolTemplate(source, input, output) {
3308
3577
  }
3309
3578
  }
3310
3579
  const root = { input, output: structured };
3311
- const bareOutputNodes = nodes.map((node) => typeof node !== "string" && node.steps.length === 1 && ("field" in node.steps[0]) && node.steps[0].field === "output" && !node.each && !node.count && node.join === undefined ? truncate(text ?? "", node.cap) : node);
3312
- return truncate(render(bareOutputNodes, root), 1000);
3580
+ const bareOutputNodes = nodes.map((node) => typeof node !== "string" && node.steps.length === 1 && ("field" in node.steps[0]) && node.steps[0].field === "output" && !node.each && !node.count && node.join === undefined ? truncate(text ?? "", node.cap ?? (legacyPreview ? 300 : undefined), legacyPreview) : node);
3581
+ return truncate(render(bareOutputNodes, root, legacyPreview), legacyPreview ? 1000 : undefined, legacyPreview);
3313
3582
  }
3314
3583
 
3315
3584
  // src/shared/historian-tool-expansions.ts
3316
- function expandToolPart(part, overrides) {
3585
+ function builtinInput(tool, input) {
3586
+ if (!input || typeof input !== "object")
3587
+ return input;
3588
+ const i = input;
3589
+ if (tool === "peer_send") {
3590
+ const external = i.external;
3591
+ const recipient = i.reply_to_pmid ? `reply to ${i.reply_to_pmid}` : i.agent || i.agent_id ? `to ${i.agent || i.agent_id}` : external?.session_id || i.session_id ? `to session ${external?.session_id || i.session_id}` : "to unknown recipient";
3592
+ return { ...i, recipient };
3593
+ }
3594
+ if (tool === "room") {
3595
+ return {
3596
+ ...i,
3597
+ room_label: i.room_id || i.title,
3598
+ room_detail: i.action === "create" || i.action === "invite" ? `invitees: ${renderToolTemplate("${input.invitees}", i)}` : i.text
3599
+ };
3600
+ }
3601
+ if (tool === "board") {
3602
+ return {
3603
+ ...i,
3604
+ board_lane: i.lane ? ` ${i.lane}` : "",
3605
+ ops: Array.isArray(i.ops) ? i.ops.map((op) => op && typeof op === "object" ? {
3606
+ ...op,
3607
+ lane_label: typeof op.lane === "string" ? op.lane : op.lane?.title || op.lane?.id
3608
+ } : op) : i.ops
3609
+ };
3610
+ }
3611
+ return input;
3612
+ }
3613
+ function expandToolPart(part, overrides, legacyPreview = false) {
3317
3614
  if (!part || typeof part !== "object")
3318
3615
  return null;
3319
3616
  const p = part;
3320
3617
  if (p.type !== "tool" || typeof p.tool !== "string")
3321
3618
  return null;
3322
- const template = overrides && Object.hasOwn(overrides, p.tool) ? overrides[p.tool] : Object.hasOwn(historian_tool_defaults_default, p.tool) ? historian_tool_defaults_default[p.tool] : undefined;
3619
+ const builtinDefaults = legacyPreview ? historian_tool_preview_defaults_default : historian_tool_defaults_default;
3620
+ const overridden = overrides && Object.hasOwn(overrides, p.tool);
3621
+ const template = overridden ? overrides[p.tool] : Object.hasOwn(builtinDefaults, p.tool) ? builtinDefaults[p.tool] : undefined;
3323
3622
  if (typeof template !== "string")
3324
3623
  return null;
3325
3624
  const state = p.state;
3326
- return renderToolTemplate(template, state?.input, state?.output ?? state?.error);
3625
+ const input = overridden || legacyPreview ? state?.input : builtinInput(p.tool, state?.input);
3626
+ return renderToolTemplate(template, input, state?.output ?? state?.error, legacyPreview);
3327
3627
  }
3328
3628
 
3329
3629
  // src/hooks/magic-context/host-served-rows.ts
@@ -4177,20 +4477,22 @@ function fenceBoundaryForCompletedToolArcs(candidate, arcs, publicationFloorOrdi
4177
4477
  return minInvocation < publicationFloorOrdinal ? maxResult + 1 : minInvocation;
4178
4478
  }
4179
4479
  function fenceBoundaryForToolArcs(candidate, arcs, lastCompartmentEndOrdinal, recentOpenArcCutoff) {
4180
- const boundary = fenceBoundaryForCompletedToolArcs(candidate, arcs, lastCompartmentEndOrdinal + 1);
4480
+ let boundary = fenceBoundaryForCompletedToolArcs(candidate, arcs, lastCompartmentEndOrdinal + 1);
4181
4481
  for (const arc of arcs) {
4182
4482
  if (arc.resOrdinal !== null)
4183
4483
  continue;
4184
4484
  if (arc.invOrdinal < recentOpenArcCutoff)
4185
4485
  continue;
4186
4486
  if (arc.invOrdinal >= lastCompartmentEndOrdinal + 1 && arc.invOrdinal < boundary) {
4187
- return arc.invOrdinal;
4487
+ boundary = arc.invOrdinal;
4488
+ break;
4188
4489
  }
4189
4490
  if (arc.invOrdinal >= boundary) {
4190
- return arc.invOrdinal;
4491
+ boundary = arc.invOrdinal;
4492
+ break;
4191
4493
  }
4192
4494
  }
4193
- return boundary;
4495
+ return fenceBoundaryForCompletedToolArcs(boundary, arcs, 1);
4194
4496
  }
4195
4497
  function tokenForMessage(message, options) {
4196
4498
  const key = messageCacheKey(message, options);
@@ -4587,6 +4889,14 @@ function getCurrentToolSetHash(providerID, modelID, agentName) {
4587
4889
  return "";
4588
4890
  return createHash2("sha256").update(Array.from(toolIds.keys()).sort().join("\x00")).digest("hex");
4589
4891
  }
4892
+ function getToolDefinitionMeasurementSignature(providerID, modelID, agentName) {
4893
+ const key = keyFor(providerID, modelID, agentName);
4894
+ const measured = measurements.get(key);
4895
+ const observed = fingerprints.get(key);
4896
+ if (!measured || !observed || [...measured.keys()].some((id) => !observed.has(id)))
4897
+ return;
4898
+ return createHash2("sha256").update(JSON.stringify([...measured.keys()].sort().map((id) => [id, observed.get(id)]))).digest("hex");
4899
+ }
4590
4900
  function setDatabase(db) {
4591
4901
  persistenceDb = db;
4592
4902
  cachedInsertStmt = null;
@@ -4700,8 +5010,10 @@ function serializedText(value) {
4700
5010
  return (typeof value === "string" ? value : JSON.stringify(value)) ?? "";
4701
5011
  }
4702
5012
  var wireTextTokens = createTokenCountMemo(1e5, 128 * 1024 * 1024);
4703
- function serializedTokens(value) {
5013
+ function serializedTokens(value, bounded = false) {
4704
5014
  const serialized = serializedText(value);
5015
+ if (bounded && tokenCountUsesByteBound(serialized))
5016
+ return Buffer.byteLength(serialized);
4705
5017
  return serialized ? wireTextTokens(serialized) : 0;
4706
5018
  }
4707
5019
  function visitWireContent(message, visit) {
@@ -4762,11 +5074,11 @@ function visitWireContent(message, visit) {
4762
5074
  }
4763
5075
  }
4764
5076
  }
4765
- function estimateMessageTokens(message) {
5077
+ function estimateMessageTokens(message, bounded = false) {
4766
5078
  const total = { conversation: 0, toolCall: 0 };
4767
5079
  visitWireContent(message, {
4768
5080
  text: (bucket, value) => {
4769
- total[bucket] += serializedTokens(value);
5081
+ total[bucket] += serializedTokens(value, bounded);
4770
5082
  },
4771
5083
  image: (bucket, tokens) => {
4772
5084
  total[bucket] += tokens;
@@ -4774,14 +5086,127 @@ function estimateMessageTokens(message) {
4774
5086
  });
4775
5087
  return total;
4776
5088
  }
5089
+ function wireContentBytes(messages, abortAboveBytes, bytesPerToken) {
5090
+ let bytes = 0;
5091
+ try {
5092
+ for (const message of messages) {
5093
+ visitWireContent(message, {
5094
+ text: (_bucket, value) => {
5095
+ bytes += Buffer.byteLength(serializedText(value));
5096
+ },
5097
+ image: (_bucket, tokens) => {
5098
+ bytes += tokens * bytesPerToken;
5099
+ }
5100
+ });
5101
+ if (bytes > abortAboveBytes)
5102
+ return { bytes, aborted: true };
5103
+ }
5104
+ } catch {
5105
+ return null;
5106
+ }
5107
+ return { bytes, aborted: false };
5108
+ }
5109
+ function createFinalWireUsageTracker() {
5110
+ const served = new Map;
5111
+ const wireRows = (input) => input.messages.filter((message) => message.parts.some((part) => !part || typeof part !== "object" || !["step-start", "step-finish"].includes(String(part.type))));
5112
+ const rowBytes = (message) => JSON.stringify({ id: message.info.id, role: message.info.role, parts: message.parts });
5113
+ const envelopeFor = (input) => {
5114
+ if (!input.providerID || !input.modelID || !input.systemPromptHash)
5115
+ return;
5116
+ const tools = getToolDefinitionMeasurementSignature(input.providerID, input.modelID, input.agentName);
5117
+ if (!tools)
5118
+ return;
5119
+ return JSON.stringify([
5120
+ input.providerID,
5121
+ input.modelID,
5122
+ input.agentName,
5123
+ input.systemPromptHash,
5124
+ input.systemPromptTokens,
5125
+ tools
5126
+ ]);
5127
+ };
5128
+ return {
5129
+ estimate(sessionId, input, limit) {
5130
+ let measuredPrefix;
5131
+ try {
5132
+ const previous = served.get(sessionId);
5133
+ const rows = wireRows(input);
5134
+ if (previous && previous.envelope === envelopeFor(input) && rows.length > previous.prefix.length && previous.prefix.every((bytes, i) => rowBytes(rows[i]) === bytes)) {
5135
+ const reply = rows[previous.prefix.length]?.info;
5136
+ const tokens = reply.tokens;
5137
+ const time = reply.time;
5138
+ const counts = [tokens?.input, tokens?.cache?.read, tokens?.cache?.write];
5139
+ if (reply.role === "assistant" && reply.parentID === previous.parent && reply.providerID === input.providerID && reply.modelID === input.modelID && ["stop", "tool-calls", "length"].includes(String(reply.finish)) && !reply.error && typeof time?.completed === "number" && time.completed >= previous.at && counts.every((n) => typeof n === "number" && Number.isSafeInteger(n) && n >= 0)) {
5140
+ const inputTokens = counts.reduce((sum, n) => sum + (n ?? 0), 0);
5141
+ if (inputTokens > 0)
5142
+ measuredPrefix = {
5143
+ inputTokens,
5144
+ appendedMessages: rows.slice(previous.prefix.length)
5145
+ };
5146
+ }
5147
+ }
5148
+ } catch {}
5149
+ return estimateOutgoingWireForRefusal({ ...input, measuredPrefix }, limit);
5150
+ },
5151
+ capture(sessionId, input) {
5152
+ served.delete(sessionId);
5153
+ try {
5154
+ const envelope = envelopeFor(input);
5155
+ const rows = wireRows(input);
5156
+ const parent = [...rows].reverse().find((row) => row.info.role === "user")?.info.id;
5157
+ if (!envelope || typeof parent !== "string" || !rows.every(hasCountableParts))
5158
+ return;
5159
+ const prefix = rows.map(rowBytes);
5160
+ if (prefix.reduce((sum, text) => sum + text.length, 0) > 4 * 1024 * 1024)
5161
+ return;
5162
+ if (served.size >= 16) {
5163
+ const oldest = served.keys().next().value;
5164
+ if (oldest !== undefined)
5165
+ served.delete(oldest);
5166
+ }
5167
+ served.set(sessionId, { envelope, prefix, parent, at: Date.now() });
5168
+ } catch {}
5169
+ }
5170
+ };
5171
+ }
5172
+ function estimateOutgoingWireForRefusal(input, limit) {
5173
+ if (typeof limit === "number" && Number.isFinite(limit) && limit > 0) {
5174
+ const measured = input.measuredPrefix;
5175
+ const baseline = measured?.inputTokens ?? 0;
5176
+ const pricedMessages = measured?.appendedMessages ?? input.messages;
5177
+ const bytes = wireContentBytes(pricedMessages, Math.max(0, limit - baseline) * 4, 4);
5178
+ if (bytes) {
5179
+ const lower = baseline + Math.ceil(bytes.bytes / 4);
5180
+ const calibration = resolveDecisionCalibration(input.providerID, input.modelID);
5181
+ const tools = input.providerID && input.modelID ? getMeasuredToolDefinitionTokens(input.providerID, input.modelID, input.agentName) : undefined;
5182
+ const envelope = measured ? baseline : tools !== undefined && Number.isFinite(input.systemPromptTokens) && input.systemPromptTokens > 0 ? providerMass({ system: input.systemPromptTokens, tools }, calibration, true) : undefined;
5183
+ const upper = envelope === undefined ? undefined : envelope + Math.ceil(bytes.bytes * Math.max(UNKNOWN_FIT_RATIO, calibration.toolsRatio, calibration.proseRatio));
5184
+ if (bytes.aborted || lower > limit || upper !== undefined && upper <= limit) {
5185
+ const over = bytes.aborted || lower > limit;
5186
+ return {
5187
+ tokens: over ? lower : upper ?? lower,
5188
+ trusted: !over,
5189
+ refusalGrade: over && envelope !== undefined,
5190
+ refusalTokens: over ? lower : undefined,
5191
+ refusalBasis: "byte-bound",
5192
+ messageTokens: { conversation: 0, toolCall: 0 },
5193
+ systemTokens: input.systemPromptTokens,
5194
+ toolDefinitionTokens: tools,
5195
+ toolDefinitionsMeasured: tools !== undefined
5196
+ };
5197
+ }
5198
+ }
5199
+ }
5200
+ return estimateFinalWireInputTokens({ ...input, boundedTokenization: true });
5201
+ }
4777
5202
  function estimateFinalWireInputTokens(input) {
4778
5203
  const messageTokens = input.messages.reduce((total, message) => {
4779
- const next = estimateMessageTokens(message);
5204
+ const next = estimateMessageTokens(message, input.boundedTokenization);
4780
5205
  total.conversation += next.conversation;
4781
5206
  total.toolCall += next.toolCall;
4782
5207
  return total;
4783
5208
  }, { conversation: 0, toolCall: 0 });
4784
- const measuredToolDefinitions = input.providerID && input.modelID ? getMeasuredToolDefinitionTokens(input.providerID, input.modelID, input.agentName) : undefined;
5209
+ const measuredToolDefinitions = input.toolDefinitionTokens ?? (input.providerID && input.modelID ? getMeasuredToolDefinitionTokens(input.providerID, input.modelID, input.agentName) : undefined);
4785
5210
  const calibration = resolveDecisionCalibration(input.providerID, input.modelID);
4786
5211
  const largestToolDefinitions = measuredToolDefinitions === undefined ? getLargestMeasuredToolDefinitionTokens() : undefined;
4787
5212
  const toolDefinitions = measuredToolDefinitions ?? (largestToolDefinitions === undefined ? undefined : Math.ceil(largestToolDefinitions * UNKNOWN_FIT_RATIO / (calibration.seeded ? calibration.toolsRatio : UNKNOWN_FIT_RATIO)));
@@ -4792,11 +5217,25 @@ function estimateFinalWireInputTokens(input) {
4792
5217
  };
4793
5218
  const tokens = providerMass(rawComponents, calibration, true);
4794
5219
  const complete = Number.isFinite(tokens) && tokens > 0 && Number.isFinite(input.systemPromptTokens) && input.systemPromptTokens > 0 && toolDefinitions !== undefined && input.messages.every(hasCountableParts);
5220
+ const refusalGrade = complete && hasTokenizerForFit() && measuredToolDefinitions !== undefined && hasMeasuredDecisionCalibration(calibration) && input.messages.every(hasRefusalCountableParts);
5221
+ const measured = input.measuredPrefix;
5222
+ const useMeasured = refusalGrade && measured && Number.isSafeInteger(measured.inputTokens) && measured.inputTokens > 0 && measured.appendedMessages.every(hasCountableParts);
5223
+ const tail = useMeasured ? measured.appendedMessages.reduce((sum, message) => {
5224
+ const next = estimateMessageTokens(message, input.boundedTokenization);
5225
+ return {
5226
+ conversation: sum.conversation + next.conversation,
5227
+ toolCall: sum.toolCall + next.toolCall
5228
+ };
5229
+ }, { conversation: 0, toolCall: 0 }) : undefined;
5230
+ const refusalTokens = refusalGrade ? tail && measured ? measured.inputTokens + providerMass({ tools: tail.toolCall, prose: tail.conversation }, calibration) : providerMass(rawComponents, calibration) : undefined;
4795
5231
  const systemTokens = Math.round(Math.max(0, input.systemPromptTokens) * calibration.systemRatio);
4796
5232
  const toolDefinitionTokens = toolDefinitions === undefined ? undefined : Math.round(toolDefinitions * (calibration.seeded ? calibration.toolsRatio : UNKNOWN_FIT_RATIO));
4797
5233
  return {
4798
5234
  tokens,
4799
5235
  trusted: complete,
5236
+ refusalGrade,
5237
+ refusalTokens,
5238
+ refusalBasis: refusalGrade ? useMeasured ? "provider-prefix" : "calibrated" : undefined,
4800
5239
  rawTokens: rawComponents.system + rawComponents.tools + rawComponents.prose,
4801
5240
  rawComponents,
4802
5241
  completeness: complete ? "complete" : "partial",
@@ -4807,6 +5246,17 @@ function estimateFinalWireInputTokens(input) {
4807
5246
  toolDefinitionsMeasured: measuredToolDefinitions !== undefined
4808
5247
  };
4809
5248
  }
5249
+ function hasRefusalCountableParts(message) {
5250
+ let exact = true;
5251
+ visitWireContent(message, {
5252
+ text: (_bucket, value) => {
5253
+ if (tokenCountUsesByteBound(serializedText(value)))
5254
+ exact = false;
5255
+ },
5256
+ image: () => {}
5257
+ });
5258
+ return exact;
5259
+ }
4810
5260
  function hasCountableParts(message) {
4811
5261
  return message.parts.every((part) => {
4812
5262
  if (!part || typeof part !== "object")
@@ -4935,7 +5385,8 @@ function extractErrorMessage(error) {
4935
5385
  var PREFIX_BOUND_THINKING_MODELS = [
4936
5386
  ["fable", 5, 1],
4937
5387
  ["opus", 5, 5],
4938
- ["sonnet", 5, 5]
5388
+ ["sonnet", 5, 5],
5389
+ ["haiku", 5, 5]
4939
5390
  ];
4940
5391
  var PREFIX_BOUND_THINKING_PATTERN = new RegExp(`(?:^|[-_.:/])(?:${PREFIX_BOUND_THINKING_MODELS.map(([family, major, minor]) => `${family}[-_.]?${major}[-_.]${minor}`).join("|")})(?:$|[-_.:/@])`, "i");
4941
5392
  function isPrefixBoundThinkingModel(_providerID, modelID) {
@@ -5067,6 +5518,9 @@ function restoreNeutralizedReasoningPart(part, legacyCleared) {
5067
5518
  function isNeutralizedReasoningPart(part) {
5068
5519
  return isRecord(part) && part[REMOVED_REASONING_MARK] === true;
5069
5520
  }
5521
+ function neutralizedReasoningSource(part) {
5522
+ return isRecord(part) ? NEUTRALIZED_ORIGINALS.get(part) ?? part : part;
5523
+ }
5070
5524
  var VARIANT_CACHE_PRESERVING_MODELS = {
5071
5525
  "anthropic/claude-fable-5-1": "2026-09-02",
5072
5526
  "openai/gpt-6-astra": "2026-09-05",
@@ -6385,4 +6839,4 @@ function readSessionChunk2(sessionId, tokenBudget, offset = 1, eligibleEndOrdina
6385
6839
  toolResultBoundaries
6386
6840
  };
6387
6841
  }
6388
- export { toolTemplateError, isRecord, isPrefixBoundThinkingModel, detectOverflow, CTX_REDUCE_KEEP, newestCtxReduceTagNumbers, textMentionsRecentCommit, removeSystemReminders, hasMeaningfulUserText2, extractTexts2, getTokenizerNativeMemoryStats, preloadTokenizer, estimateTokens, estimateFixedPromptTokens, stripWellFormedLeadingTagPrefix, byteSize, stripTagPrefix, peelLeadingMcTagNotation, prependTag, isThinkingPart, stableStringify, estimateImageTokensFromDataUrl, estimateToolAttachmentImageTokens, normalizeTodoStateJson, buildSyntheticTodoPart, isSyntheticTodoPart, countRealUserMessages, tailHygieneStructuralSignature, sameTailHygieneStructuralSignature, formatTailHygienePrefixMismatch, refreshTailHygieneBaseline, effectiveTailHygiene, assertTailHygieneContentUnchangedIfEnabled, CHANNEL1_SENTINEL, CHANNEL1_FLOOR_TOKENS, isDroppedToolOutput, toolOutputTokens, decideChannel1, evaluateChannel2, formatChannel1Evaluation, formatChannel2Evaluation, reclaimableToolOutputCount, buildChannel2Reminder, buildChannel1Reminder, estimateEmergencyDropReclaimTokens, planEmergencyDrop, measureEmergencyTag, getRecentTagOwnerMessageIds, AGE_RECLAIM_MIN_TOKENS, getOldestActiveUnprotectedToolTags, getActiveToolTagsForAgeReclaim, getTriggerTagTokenUpperBound, getActiveTagTokenTotalsByMessage, getAllStatusTagTokenTotalsFlat, tagTokenCountIsNull, backfillTagTokenCounts, insertTag, updateTagStatus, markWhitespaceAssistantTagInert, getInertWhitespaceAssistantTags, updateTagDropMode, updateCavemanDepth, updateTagMessageId, foldShrunkPartTags, markTagsCompactedByMessageIds, getMaxTagNumberBySession, getTagNumberByMessageId, getAssignableTagNumberByMessageId, deriveTagLoadFloor, TAG_SELECT_COLUMNS, getTagsBySession, getActiveTagsBySession, getTailHygieneTags, getTagsByNumbers, getDroppedTagsByNumbers, getMaxDroppedTagNumber, getTagById, getToolTagNumberByOwner, getNullOwnerToolTag, adoptNullOwnerToolTag, getCandidateToolOwners, pickNearestPriorOwner, expandToolPart, markHostUnservedRow, retreatPastHostUnservedRows, snapTerminalCompartmentToServedRow, isHostRenderedSystemMessage, isStrictGapHealingMessage, extractInMemoryMessageViews, buildInMemoryTailRawMessages, completedToolArcCrossesBoundary, estimateTrueRawMessageTokens, buildToolArcs, fenceBoundaryForCompletedToolArcs, fenceBoundaryForToolArcs, buildTrueRawTokenIndex, computeRawRangeFingerprint, isTextPart, isToolPartWithOutput, isFilePart, buildFileSourceContent, toolPartHasUserAnswer, recordToolParameters, createDroppedInputGuard, assertExecutableToolInput, isEditTool, getCurrentToolSetHash, setDatabase, loadToolDefinitionMeasurements, recordToolDefinition, getMeasuredToolDefinitionTokens, describeFinalWireTail, estimateMessageTokens, estimateFinalWireInputTokens, modelAcceptsEmptyContent, isAnthropicFamilyRoute, neutralizeDroppedReasoningPart, restoreNeutralizedReasoningPart, isNeutralizedReasoningPart, variantChangeBustsProviderCache, makeSentinel, makeWholeMessageSentinel, isSentinel, replaySentinelByMessageIds, SKELETON_REAL_INPUT_MAX_BYTES, partHasCompletedResult, extractToolCallObservation, ToolMutationBatch, createToolDropTarget, resolveHostServedBoundaryId2, hasRawMessageProvider2, setBoundedRawMessageProvider2, cleanUserText2, withRawSessionMessageCache2, readRawSessionMessages2, readRawSessionMessagePage2, getRawSessionMessageOrdinalCount2, visitRawSessionMessages2, readRawSessionMessageRange2, primeTailRawMessageCache2, getCachedAbsoluteMessageCount2, primeInMemoryTailRawMessageCache2, readRawSessionMessageIdOrdinalsForRange2, hasRawSessionMessageById2, readRawSessionMessageOrdinalById2, compareRawSessionMessageOrder2, readRawSessionMessageById2, getRawSessionMessageCount2, getRawSessionTagKeysThrough2, getLegacyProtectedTailStartOrdinal2, readSessionChunk2 };
6842
+ export { toolTemplateError, DEFAULT_PROTECTED_TOOLS, normalizeProtectedToolName, mergeProtectedTools, isRecord, isPrefixBoundThinkingModel, detectOverflow, protectedToolTagNumbers, protectedToolTokenCount, textMentionsRecentCommit, removeSystemReminders, hasMeaningfulUserText2, extractTexts2, getTokenizerNativeMemoryStats, preloadTokenizer, estimateTokens, estimateFixedPromptTokens, stripWellFormedLeadingTagPrefix, byteSize, stripTagPrefix, peelLeadingMcTagNotation, prependTag, isThinkingPart, stableStringify, contentTagOwnerMessageId, estimateImageTokensFromDataUrl, estimateToolAttachmentImageTokens, normalizeTodoStateJson, buildSyntheticTodoPart, isSyntheticTodoPart, countRealUserMessages, tailHygieneStructuralSignature, sameTailHygieneStructuralSignature, formatTailHygienePrefixMismatch, refreshTailHygieneBaseline, effectiveTailHygiene, assertTailHygieneContentUnchangedIfEnabled, CHANNEL1_SENTINEL, CHANNEL1_FLOOR_TOKENS, isDroppedToolOutput, toolOutputTokens, decideChannel1, evaluateChannel2, formatChannel1Evaluation, formatChannel2Evaluation, reclaimableToolOutputCount, buildChannel2Reminder, buildChannel1Reminder, estimateEmergencyDropReclaimTokens, planEmergencyDrop, measureEmergencyTag, installV3PerfSchema, queuePendingOp, queuePendingDropForUnchangedTag, getPendingOps, getPendingOpsCount, clearPendingOps, removePendingOp, getRecentTagOwnerMessageIds, AGE_RECLAIM_MIN_TOKENS, getOldestActiveUnprotectedToolTags, getActiveToolTagsForAgeReclaim, getTriggerTagTokenUpperBound, getActiveTagTokenTotalsByMessage, getAllStatusTagTokenTotalsFlat, getReasoningTokenEstimatesByMessage, tagTokenCountIsNull, backfillTagTokenCounts, insertTag, updateTagStatus, markWhitespaceAssistantTagInert, getInertWhitespaceAssistantTags, updateTagDropMode, updateCavemanDepth, updateTagMessageId, foldShrunkPartTags, markTagsCompactedByMessageIds, getMaxTagNumberBySession, getTagNumberByMessageId, getAssignableTagNumberByMessageId, deriveTagLoadFloor, TAG_SELECT_COLUMNS, getTagsBySession, getActiveTagsBySession, getTailHygieneTags, getTagsByNumbers, getNewestToolTagNumbers, getDroppedTagsByNumbers, getMaxDroppedTagNumber, getTagById, getToolTagNumberByOwner, getNullOwnerToolTag, adoptNullOwnerToolTag, getCandidateToolOwners, pickNearestPriorOwner, expandToolPart, markHostUnservedRow, retreatPastHostUnservedRows, snapTerminalCompartmentToServedRow, isHostRenderedSystemMessage, isStrictGapHealingMessage, extractInMemoryMessageViews, buildInMemoryTailRawMessages, completedToolArcCrossesBoundary, estimateTrueRawMessageTokens, buildToolArcs, fenceBoundaryForCompletedToolArcs, fenceBoundaryForToolArcs, buildTrueRawTokenIndex, computeRawRangeFingerprint, isTextPart, isToolPartWithOutput, isFilePart, buildFileSourceContent, toolPartHasUserAnswer, recordToolParameters, createDroppedInputGuard, assertExecutableToolInput, isEditTool, getCurrentToolSetHash, setDatabase, loadToolDefinitionMeasurements, recordToolDefinition, getMeasuredToolDefinitionTokens, describeFinalWireTail, estimateMessageTokens, wireContentBytes, createFinalWireUsageTracker, estimateFinalWireInputTokens, modelAcceptsEmptyContent, isAnthropicFamilyRoute, neutralizeDroppedReasoningPart, restoreNeutralizedReasoningPart, isNeutralizedReasoningPart, neutralizedReasoningSource, variantChangeBustsProviderCache, makeSentinel, makeWholeMessageSentinel, isSentinel, replaySentinelByMessageIds, SKELETON_REAL_INPUT_MAX_BYTES, partHasCompletedResult, extractToolCallObservation, ToolMutationBatch, createToolDropTarget, resolveHostServedBoundaryId2, hasRawMessageProvider2, setBoundedRawMessageProvider2, cleanUserText2, withRawSessionMessageCache2, readRawSessionMessages2, readRawSessionMessagePage2, getRawSessionMessageOrdinalCount2, visitRawSessionMessages2, readRawSessionMessageRange2, primeTailRawMessageCache2, getCachedAbsoluteMessageCount2, primeInMemoryTailRawMessageCache2, readRawSessionMessageIdOrdinalsForRange2, hasRawSessionMessageById2, readRawSessionMessageOrdinalById2, compareRawSessionMessageOrder2, readRawSessionMessageById2, getRawSessionMessageCount2, getRawSessionTagKeysThrough2, getLegacyProtectedTailStartOrdinal2, readSessionChunk2 };