@buoy-gg/agent-core 7.0.35 → 7.0.38

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 (208) hide show
  1. package/README.md +21 -14
  2. package/lib/commonjs/blocks/receipts.js +57 -1
  3. package/lib/commonjs/blocks/receipts.js.map +1 -1
  4. package/lib/commonjs/blocks/types.js +23 -2
  5. package/lib/commonjs/blocks/types.js.map +1 -1
  6. package/lib/commonjs/blocks/uiTool.js +423 -10
  7. package/lib/commonjs/blocks/uiTool.js.map +1 -1
  8. package/lib/commonjs/catalog/catalog.g.js +213 -48
  9. package/lib/commonjs/catalog/catalog.g.js.map +1 -1
  10. package/lib/commonjs/catalog/catalog.source.json +226 -48
  11. package/lib/commonjs/catalog/catalog.types.g.js +44 -0
  12. package/lib/commonjs/catalog/catalog.types.g.js.map +1 -0
  13. package/lib/commonjs/catalog/normalizeParams.js +333 -0
  14. package/lib/commonjs/catalog/normalizeParams.js.map +1 -0
  15. package/lib/commonjs/catalog/signature.js +68 -0
  16. package/lib/commonjs/catalog/signature.js.map +1 -0
  17. package/lib/commonjs/catalog/snapshotReads.js +13 -6
  18. package/lib/commonjs/catalog/snapshotReads.js.map +1 -1
  19. package/lib/commonjs/catalog/toProviderTools.js +44 -6
  20. package/lib/commonjs/catalog/toProviderTools.js.map +1 -1
  21. package/lib/commonjs/context/buildContextPack.js +367 -19
  22. package/lib/commonjs/context/buildContextPack.js.map +1 -1
  23. package/lib/commonjs/effects/digest.js +34 -0
  24. package/lib/commonjs/effects/digest.js.map +1 -0
  25. package/lib/commonjs/effects/ledger.js +98 -2
  26. package/lib/commonjs/effects/ledger.js.map +1 -1
  27. package/lib/commonjs/engine/askGate.js +287 -0
  28. package/lib/commonjs/engine/askGate.js.map +1 -0
  29. package/lib/commonjs/engine/effectFor.js +82 -1
  30. package/lib/commonjs/engine/effectFor.js.map +1 -1
  31. package/lib/commonjs/engine/evidence.js +113 -0
  32. package/lib/commonjs/engine/evidence.js.map +1 -0
  33. package/lib/commonjs/engine/historyBudget.js +363 -0
  34. package/lib/commonjs/engine/historyBudget.js.map +1 -0
  35. package/lib/commonjs/engine/retrieve.js +214 -0
  36. package/lib/commonjs/engine/retrieve.js.map +1 -0
  37. package/lib/commonjs/engine/runAgentTurn.js +1231 -120
  38. package/lib/commonjs/engine/runAgentTurn.js.map +1 -1
  39. package/lib/commonjs/engine/systemPrompt.js +103 -9
  40. package/lib/commonjs/engine/systemPrompt.js.map +1 -1
  41. package/lib/commonjs/engine/textToolCalls.js +276 -0
  42. package/lib/commonjs/engine/textToolCalls.js.map +1 -0
  43. package/lib/commonjs/engine/tokenCalibration.js +81 -0
  44. package/lib/commonjs/engine/tokenCalibration.js.map +1 -0
  45. package/lib/commonjs/engine/verify.js +300 -0
  46. package/lib/commonjs/engine/verify.js.map +1 -0
  47. package/lib/commonjs/index.js +74 -0
  48. package/lib/commonjs/index.js.map +1 -1
  49. package/lib/commonjs/policy/labels.js +19 -3
  50. package/lib/commonjs/policy/labels.js.map +1 -1
  51. package/lib/commonjs/policy/policy.js +6 -1
  52. package/lib/commonjs/policy/policy.js.map +1 -1
  53. package/lib/commonjs/policy/redact.js +42 -5
  54. package/lib/commonjs/policy/redact.js.map +1 -1
  55. package/lib/commonjs/providers/anthropic.js +340 -208
  56. package/lib/commonjs/providers/anthropic.js.map +1 -1
  57. package/lib/commonjs/providers/openai.js +237 -103
  58. package/lib/commonjs/providers/openai.js.map +1 -1
  59. package/lib/commonjs/providers/problem.js +98 -0
  60. package/lib/commonjs/providers/problem.js.map +1 -0
  61. package/lib/commonjs/providers/sse.js +170 -34
  62. package/lib/commonjs/providers/sse.js.map +1 -1
  63. package/lib/commonjs/providers/streamTimer.js +123 -0
  64. package/lib/commonjs/providers/streamTimer.js.map +1 -0
  65. package/lib/commonjs/providers/transport.js +123 -0
  66. package/lib/commonjs/providers/transport.js.map +1 -0
  67. package/lib/commonjs/providers/xhrStream.js +212 -0
  68. package/lib/commonjs/providers/xhrStream.js.map +1 -0
  69. package/lib/commonjs/session.js +242 -58
  70. package/lib/commonjs/session.js.map +1 -1
  71. package/lib/module/blocks/receipts.js +57 -1
  72. package/lib/module/blocks/receipts.js.map +1 -1
  73. package/lib/module/blocks/types.js +23 -2
  74. package/lib/module/blocks/types.js.map +1 -1
  75. package/lib/module/blocks/uiTool.js +421 -10
  76. package/lib/module/blocks/uiTool.js.map +1 -1
  77. package/lib/module/catalog/catalog.g.js +213 -48
  78. package/lib/module/catalog/catalog.g.js.map +1 -1
  79. package/lib/module/catalog/catalog.source.json +226 -48
  80. package/lib/module/catalog/catalog.types.g.js +40 -0
  81. package/lib/module/catalog/catalog.types.g.js.map +1 -0
  82. package/lib/module/catalog/normalizeParams.js +327 -0
  83. package/lib/module/catalog/normalizeParams.js.map +1 -0
  84. package/lib/module/catalog/signature.js +63 -0
  85. package/lib/module/catalog/signature.js.map +1 -0
  86. package/lib/module/catalog/snapshotReads.js +13 -6
  87. package/lib/module/catalog/snapshotReads.js.map +1 -1
  88. package/lib/module/catalog/toProviderTools.js +44 -6
  89. package/lib/module/catalog/toProviderTools.js.map +1 -1
  90. package/lib/module/context/buildContextPack.js +366 -19
  91. package/lib/module/context/buildContextPack.js.map +1 -1
  92. package/lib/module/effects/digest.js +29 -0
  93. package/lib/module/effects/digest.js.map +1 -0
  94. package/lib/module/effects/ledger.js +98 -2
  95. package/lib/module/effects/ledger.js.map +1 -1
  96. package/lib/module/engine/askGate.js +280 -0
  97. package/lib/module/engine/askGate.js.map +1 -0
  98. package/lib/module/engine/effectFor.js +83 -1
  99. package/lib/module/engine/effectFor.js.map +1 -1
  100. package/lib/module/engine/evidence.js +107 -0
  101. package/lib/module/engine/evidence.js.map +1 -0
  102. package/lib/module/engine/historyBudget.js +355 -0
  103. package/lib/module/engine/historyBudget.js.map +1 -0
  104. package/lib/module/engine/retrieve.js +210 -0
  105. package/lib/module/engine/retrieve.js.map +1 -0
  106. package/lib/module/engine/runAgentTurn.js +1227 -121
  107. package/lib/module/engine/runAgentTurn.js.map +1 -1
  108. package/lib/module/engine/systemPrompt.js +101 -9
  109. package/lib/module/engine/systemPrompt.js.map +1 -1
  110. package/lib/module/engine/textToolCalls.js +270 -0
  111. package/lib/module/engine/textToolCalls.js.map +1 -0
  112. package/lib/module/engine/tokenCalibration.js +75 -0
  113. package/lib/module/engine/tokenCalibration.js.map +1 -0
  114. package/lib/module/engine/verify.js +292 -0
  115. package/lib/module/engine/verify.js.map +1 -0
  116. package/lib/module/index.js +7 -3
  117. package/lib/module/index.js.map +1 -1
  118. package/lib/module/policy/labels.js +19 -3
  119. package/lib/module/policy/labels.js.map +1 -1
  120. package/lib/module/policy/policy.js +6 -1
  121. package/lib/module/policy/policy.js.map +1 -1
  122. package/lib/module/policy/redact.js +42 -5
  123. package/lib/module/policy/redact.js.map +1 -1
  124. package/lib/module/providers/anthropic.js +341 -209
  125. package/lib/module/providers/anthropic.js.map +1 -1
  126. package/lib/module/providers/openai.js +238 -104
  127. package/lib/module/providers/openai.js.map +1 -1
  128. package/lib/module/providers/problem.js +92 -0
  129. package/lib/module/providers/problem.js.map +1 -0
  130. package/lib/module/providers/sse.js +166 -34
  131. package/lib/module/providers/sse.js.map +1 -1
  132. package/lib/module/providers/streamTimer.js +118 -0
  133. package/lib/module/providers/streamTimer.js.map +1 -0
  134. package/lib/module/providers/transport.js +119 -0
  135. package/lib/module/providers/transport.js.map +1 -0
  136. package/lib/module/providers/xhrStream.js +207 -0
  137. package/lib/module/providers/xhrStream.js.map +1 -0
  138. package/lib/module/session.js +226 -60
  139. package/lib/module/session.js.map +1 -1
  140. package/lib/typescript/blocks/receipts.d.ts +5 -0
  141. package/lib/typescript/blocks/receipts.d.ts.map +1 -1
  142. package/lib/typescript/blocks/types.d.ts +23 -2
  143. package/lib/typescript/blocks/types.d.ts.map +1 -1
  144. package/lib/typescript/blocks/uiTool.d.ts +11 -2
  145. package/lib/typescript/blocks/uiTool.d.ts.map +1 -1
  146. package/lib/typescript/catalog/catalog.g.d.ts +2 -2
  147. package/lib/typescript/catalog/catalog.g.d.ts.map +1 -1
  148. package/lib/typescript/catalog/catalog.types.g.d.ts +40 -0
  149. package/lib/typescript/catalog/catalog.types.g.d.ts.map +1 -0
  150. package/lib/typescript/catalog/normalizeParams.d.ts +43 -0
  151. package/lib/typescript/catalog/normalizeParams.d.ts.map +1 -0
  152. package/lib/typescript/catalog/signature.d.ts +29 -0
  153. package/lib/typescript/catalog/signature.d.ts.map +1 -0
  154. package/lib/typescript/catalog/snapshotReads.d.ts.map +1 -1
  155. package/lib/typescript/catalog/toProviderTools.d.ts +28 -15
  156. package/lib/typescript/catalog/toProviderTools.d.ts.map +1 -1
  157. package/lib/typescript/context/buildContextPack.d.ts +24 -2
  158. package/lib/typescript/context/buildContextPack.d.ts.map +1 -1
  159. package/lib/typescript/effects/digest.d.ts +10 -0
  160. package/lib/typescript/effects/digest.d.ts.map +1 -0
  161. package/lib/typescript/effects/ledger.d.ts +73 -0
  162. package/lib/typescript/effects/ledger.d.ts.map +1 -1
  163. package/lib/typescript/engine/askGate.d.ts +29 -0
  164. package/lib/typescript/engine/askGate.d.ts.map +1 -0
  165. package/lib/typescript/engine/effectFor.d.ts +6 -1
  166. package/lib/typescript/engine/effectFor.d.ts.map +1 -1
  167. package/lib/typescript/engine/evidence.d.ts +67 -0
  168. package/lib/typescript/engine/evidence.d.ts.map +1 -0
  169. package/lib/typescript/engine/historyBudget.d.ts +115 -0
  170. package/lib/typescript/engine/historyBudget.d.ts.map +1 -0
  171. package/lib/typescript/engine/retrieve.d.ts +32 -0
  172. package/lib/typescript/engine/retrieve.d.ts.map +1 -0
  173. package/lib/typescript/engine/runAgentTurn.d.ts +179 -3
  174. package/lib/typescript/engine/runAgentTurn.d.ts.map +1 -1
  175. package/lib/typescript/engine/systemPrompt.d.ts +80 -0
  176. package/lib/typescript/engine/systemPrompt.d.ts.map +1 -1
  177. package/lib/typescript/engine/textToolCalls.d.ts +58 -0
  178. package/lib/typescript/engine/textToolCalls.d.ts.map +1 -0
  179. package/lib/typescript/engine/tokenCalibration.d.ts +46 -0
  180. package/lib/typescript/engine/tokenCalibration.d.ts.map +1 -0
  181. package/lib/typescript/engine/verify.d.ts +67 -0
  182. package/lib/typescript/engine/verify.d.ts.map +1 -0
  183. package/lib/typescript/index.d.ts +7 -3
  184. package/lib/typescript/index.d.ts.map +1 -1
  185. package/lib/typescript/policy/labels.d.ts.map +1 -1
  186. package/lib/typescript/policy/policy.d.ts.map +1 -1
  187. package/lib/typescript/policy/redact.d.ts.map +1 -1
  188. package/lib/typescript/providers/anthropic.d.ts.map +1 -1
  189. package/lib/typescript/providers/openai.d.ts +0 -16
  190. package/lib/typescript/providers/openai.d.ts.map +1 -1
  191. package/lib/typescript/providers/problem.d.ts +50 -0
  192. package/lib/typescript/providers/problem.d.ts.map +1 -0
  193. package/lib/typescript/providers/sse.d.ts +86 -2
  194. package/lib/typescript/providers/sse.d.ts.map +1 -1
  195. package/lib/typescript/providers/streamTimer.d.ts +59 -0
  196. package/lib/typescript/providers/streamTimer.d.ts.map +1 -0
  197. package/lib/typescript/providers/transport.d.ts +48 -0
  198. package/lib/typescript/providers/transport.d.ts.map +1 -0
  199. package/lib/typescript/providers/types.d.ts +105 -3
  200. package/lib/typescript/providers/types.d.ts.map +1 -1
  201. package/lib/typescript/providers/xhrStream.d.ts +45 -0
  202. package/lib/typescript/providers/xhrStream.d.ts.map +1 -0
  203. package/lib/typescript/session.d.ts +55 -4
  204. package/lib/typescript/session.d.ts.map +1 -1
  205. package/lib/typescript/types.d.ts +6 -0
  206. package/lib/typescript/types.d.ts.map +1 -1
  207. package/package.json +10 -10
  208. package/LICENSE +0 -58
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * The evidence store: every tool result this conversation produced, kept in
5
+ * full so the model can go back to it.
6
+ *
7
+ * Two markers used to point nowhere. A result over 24 000 characters was cut
8
+ * with "ask for a narrower slice" — and no tool offers one, so the bank has
9
+ * cases tagged `capability` (Pokémon `stats` sit at offset ~180 000 of a
10
+ * 400 000-character detail; unreadable by design). And a result compressed
11
+ * out of memory said "ask again" — a re-dispatch returns the CURRENT value,
12
+ * not what the model saw before it wrote, which is the one it needs when a
13
+ * write is refused and it has to say what it changed FROM.
14
+ *
15
+ * So the full text is kept here, keyed by a short ref the markers carry, and
16
+ * `ask-buoy.retrieve` reads any part of it back: a path, a substring, a
17
+ * window. Borrowed from Strands' ContextOffloader (`retrieve_offloaded_content`
18
+ * with pattern / line_range), minus the storage layer — this is in-memory and
19
+ * per session on purpose: persisted transcripts deliberately carry no tool
20
+ * result payloads (see ask-buoy transcriptPersistence.ts), and this must not
21
+ * quietly change that.
22
+ *
23
+ * What goes in is what the MODEL was given: after `redact` (credential names
24
+ * and value shapes) and `stripSelfTraffic`. Never the raw adapter value.
25
+ *
26
+ * Bounded by bytes and entries, oldest out first; an evicted ref is remembered
27
+ * so the answer is "evicted" rather than "never existed" — the marker still
28
+ * names a real thing, and the honest reply is to call the tool again.
29
+ */
30
+
31
+ const DEFAULT_MAX_CHARS = 4_000_000;
32
+ const DEFAULT_MAX_ENTRIES = 200;
33
+ export class EvidenceStore {
34
+ entries = new Map();
35
+ evictedRefs = new Set();
36
+ chars = 0;
37
+ seq = 0;
38
+ constructor(opts = {}) {
39
+ this.maxChars = opts.maxChars ?? DEFAULT_MAX_CHARS;
40
+ this.maxEntries = opts.maxEntries ?? DEFAULT_MAX_ENTRIES;
41
+ }
42
+
43
+ /** Keep a result. Returns its ref — `ev_<n>`, counting up for the life of the store. */
44
+ stash(input) {
45
+ const ref = `ev_${++this.seq}`;
46
+ const entry = {
47
+ ...input,
48
+ ref
49
+ };
50
+ // A single result larger than the whole store still gets a ref — it is
51
+ // the case the store exists for — and simply evicts everything else.
52
+ this.entries.set(ref, entry);
53
+ this.chars += entry.text.length;
54
+ this.evict();
55
+ return ref;
56
+ }
57
+ get(ref) {
58
+ return this.entries.get(ref);
59
+ }
60
+
61
+ /** True when the ref was real and has since been dropped for space. */
62
+ wasEvicted(ref) {
63
+ return this.evictedRefs.has(ref);
64
+ }
65
+ get size() {
66
+ return this.entries.size;
67
+ }
68
+ get totalChars() {
69
+ return this.chars;
70
+ }
71
+
72
+ /** New conversation: nothing from the old one is retrievable. */
73
+ clear() {
74
+ this.entries.clear();
75
+ this.evictedRefs.clear();
76
+ this.chars = 0;
77
+ }
78
+ evict() {
79
+ // Map iteration is insertion order, so the first key is the oldest.
80
+ for (const [ref, entry] of this.entries) {
81
+ const over = this.chars > this.maxChars || this.entries.size > this.maxEntries;
82
+ if (!over || this.entries.size === 1) return;
83
+ this.entries.delete(ref);
84
+ this.evictedRefs.add(ref);
85
+ this.chars -= entry.text.length;
86
+ }
87
+ }
88
+ }
89
+
90
+ // ── the markers ──────────────────────────────────────────────────────────────
91
+
92
+ const RETRIEVE_HINT = "ask-buoy.retrieve";
93
+
94
+ /** The tail of a result cut at the engine's cap. */
95
+ export function truncationMarker(totalChars, ref) {
96
+ const size = totalChars.toLocaleString("en-US");
97
+ if (!ref) return `\n\n[truncated — ${size} characters total. Ask for a narrower slice if you need more.]`;
98
+ return `\n\n[truncated — ${size} characters total; ref ${ref}. Call ${RETRIEVE_HINT} {"ref":"${ref}"} to see its shape, then {"ref":"${ref}","path":"…"} or {"ref":"${ref}","pattern":"…"} to read the part you need.]`;
99
+ }
100
+
101
+ /** What a consumed result is replaced with when history is compressed. Keep the `[earlier result` prefix — historyBudget skips on it. */
102
+ export function compressedMarker(totalChars, ref) {
103
+ const size = totalChars.toLocaleString("en-US");
104
+ if (!ref) return `[earlier result — ${size} characters, already read. Ask again if you need it.]`;
105
+ return `[earlier result — ${size} characters, already read; ref ${ref}. ${RETRIEVE_HINT} {"ref":"${ref}",…} re-reads exactly what you saw then; calling the tool again gives the CURRENT value.]`;
106
+ }
107
+ //# sourceMappingURL=evidence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DEFAULT_MAX_CHARS","DEFAULT_MAX_ENTRIES","EvidenceStore","entries","Map","evictedRefs","Set","chars","seq","constructor","opts","maxChars","maxEntries","stash","input","ref","entry","set","text","length","evict","get","wasEvicted","has","size","totalChars","clear","over","delete","add","RETRIEVE_HINT","truncationMarker","toLocaleString","compressedMarker"],"sourceRoot":"../../../src","sources":["engine/evidence.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAoBA,MAAMA,iBAAiB,GAAG,SAAS;AACnC,MAAMC,mBAAmB,GAAG,GAAG;AAE/B,OAAO,MAAMC,aAAa,CAAC;EACRC,OAAO,GAAG,IAAIC,GAAG,CAAwB,CAAC;EAC1CC,WAAW,GAAG,IAAIC,GAAG,CAAS,CAAC;EAGxCC,KAAK,GAAG,CAAC;EACTC,GAAG,GAAG,CAAC;EAEfC,WAAWA,CAACC,IAA0B,GAAG,CAAC,CAAC,EAAE;IAC3C,IAAI,CAACC,QAAQ,GAAGD,IAAI,CAACC,QAAQ,IAAIX,iBAAiB;IAClD,IAAI,CAACY,UAAU,GAAGF,IAAI,CAACE,UAAU,IAAIX,mBAAmB;EAC1D;;EAEA;EACAY,KAAKA,CAACC,KAAiC,EAAU;IAC/C,MAAMC,GAAG,GAAG,MAAM,EAAE,IAAI,CAACP,GAAG,EAAE;IAC9B,MAAMQ,KAAoB,GAAG;MAAE,GAAGF,KAAK;MAAEC;IAAI,CAAC;IAC9C;IACA;IACA,IAAI,CAACZ,OAAO,CAACc,GAAG,CAACF,GAAG,EAAEC,KAAK,CAAC;IAC5B,IAAI,CAACT,KAAK,IAAIS,KAAK,CAACE,IAAI,CAACC,MAAM;IAC/B,IAAI,CAACC,KAAK,CAAC,CAAC;IACZ,OAAOL,GAAG;EACZ;EAEAM,GAAGA,CAACN,GAAW,EAA6B;IAC1C,OAAO,IAAI,CAACZ,OAAO,CAACkB,GAAG,CAACN,GAAG,CAAC;EAC9B;;E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AAUe,aAAa,YAAYf,GAAG,qCAAqCA,GAAG,4BAA4BA,GAAG,8CAA8C;AACzN;;AAEA;AACA,OAAO,SAASkB,gBAAgBA,CAACR,UAAkB,EAAEV,GAAuB,EAAU;EACpF,MAAMS,IAAI,GAAGC,UAAU,CAACO,cAAc,CAAC,OAAO,CAAC;EAC/C,IAAI,CAACjB,GAAG,EAAE,OAAO,qBAAqBS,IAAI,uDAAuD;EACjG,OAAO,qBAAqBA,IAAI,kCAAkCT,GAAG,KAAKe,aAAa,YAAYf,GAAG,2FAA2F;AACnM","ignoreList":[]}
@@ -0,0 +1,355 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * How much conversation the model is allowed to be sent, and what gets cut.
5
+ *
6
+ * Lives here, not in `session.ts`, because it is needed in TWO places and used
7
+ * to run in only one. The session trims once per turn, before the loop starts
8
+ * — and a turn is not one request. A twelve-step investigation appends an
9
+ * assistant message and a tool-results message per step, each result capped at
10
+ * 24,000 characters, so a long read chain could add well over a hundred
11
+ * thousand characters AFTER the only check had already happened and walk
12
+ * straight into the provider's context limit. The engine now applies the same
13
+ * budget before every request; the session still applies it when a turn opens.
14
+ */
15
+
16
+ import { compressedMarker } from "./evidence";
17
+ import { DEFAULT_CHARS_PER_TOKEN } from "./tokenCalibration";
18
+
19
+ /**
20
+ * A long QA session must not die on the provider's context limit with an
21
+ * opaque error, so the history is kept under a budget.
22
+ *
23
+ * TWO STAGES, AND THE ORDER IS THE POINT. Dropping the oldest rounds was the
24
+ * only stage, and in a QA session the oldest round is usually the SETUP — the
25
+ * override that was armed, the store that was written, the user someone is
26
+ * impersonating. Drop it and the model can no longer explain the screen it is
27
+ * looking at, or that a "wrong" response is its own mock. The reply gets worse
28
+ * in exactly the sessions long enough to need trimming.
29
+ *
30
+ * So: COMPRESS first, DROP only if that was not enough.
31
+ *
32
+ * A tool result is "consumed" once the model has produced an assistant message
33
+ * after seeing it — it has already been reasoned over, and what remains is
34
+ * bulk. Replacing it with a marker keeps the round, its decision and its
35
+ * ordering while giving back nearly all the bytes. Three exemptions carry
36
+ * their weight:
37
+ *
38
+ * - Errors are never compressed. A failure is the diagnostic value.
39
+ * - The newest tool-results message is never compressed. The model is about
40
+ * to answer from it.
41
+ * - The last read before a WRITE is never compressed: that is the shape the
42
+ * model matched its edit to, and it is the thing it re-reads when the write
43
+ * is refused and it has to correct itself.
44
+ *
45
+ * Only if the history is still over budget do whole rounds get dropped, as
46
+ * before — a round starts at a user message, so the assistant/tool-result
47
+ * pairing every provider requires stays intact.
48
+ */
49
+ /**
50
+ * The limits are in TOKENS — the unit the provider enforces — and turned into
51
+ * characters at the ratio the session has measured (engine/tokenCalibration.ts).
52
+ * The `_CHARS` constants below are those limits at the default 4 chars/token,
53
+ * kept for callers that have no calibration in hand (tests, one-shot use).
54
+ */
55
+ export const MAX_HISTORY_TOKENS = 37_500;
56
+ /**
57
+ * The ceiling on a WHOLE request: tools, system prompt, messages and the room
58
+ * reserved for the reply. 100k tokens fits the smallest context Ask Buoy is
59
+ * pointed at in practice (a 128k-token gateway) with headroom, and leaves
60
+ * Anthropic's 200k far from the limit.
61
+ */
62
+ export const MAX_REQUEST_TOKENS = 100_000;
63
+ export const MAX_HISTORY_CHARS = MAX_HISTORY_TOKENS * DEFAULT_CHARS_PER_TOKEN;
64
+ export const MAX_REQUEST_CHARS = MAX_REQUEST_TOKENS * DEFAULT_CHARS_PER_TOKEN;
65
+ const MIN_KEEP_MESSAGES = 4;
66
+ /** Below this a marker costs more than the payload it replaces. */
67
+ const MIN_COMPRESS_CHARS = 400;
68
+ export function messageSize(m) {
69
+ try {
70
+ return JSON.stringify(m).length;
71
+ } catch {
72
+ return 0;
73
+ }
74
+ }
75
+
76
+ /**
77
+ * Replace consumed tool results with a marker. See the note above
78
+ * MAX_HISTORY_CHARS for what "consumed" means and why the exemptions exist.
79
+ */
80
+ export function compressConsumed(messages, exemptNewest = true) {
81
+ // The newest tool-results message: the model is about to answer from it.
82
+ // Unless the caller says otherwise — `budgetForRequest` hands in the rounds
83
+ // BEFORE the current one, whose last result was answered long ago.
84
+ let newest = messages.length;
85
+ if (exemptNewest) {
86
+ newest = -1;
87
+ for (let i = messages.length - 1; i >= 0; i--) {
88
+ if (messages[i].role === "tool-results") {
89
+ newest = i;
90
+ break;
91
+ }
92
+ }
93
+ if (newest <= 0) return messages;
94
+ }
95
+
96
+ // The reads a later write depended on. An assistant turn that called a
97
+ // write was matching a shape it read in the round before, and that is the
98
+ // read it goes back to when the write is refused.
99
+ const beforeWrite = new Set();
100
+ for (let i = 0; i < messages.length; i++) {
101
+ const m = messages[i];
102
+ if (m.role !== "assistant" || !m.toolCalls?.length) continue;
103
+ if (!m.toolCalls.some(c => WRITE_ISH.test(JSON.stringify(c.input ?? {}) + c.name))) continue;
104
+ for (let j = i - 1; j >= 0 && j >= i - 3; j--) {
105
+ if (messages[j].role === "tool-results") {
106
+ beforeWrite.add(j);
107
+ break;
108
+ }
109
+ }
110
+ }
111
+ let changed = false;
112
+ const out = messages.map((m, i) => {
113
+ if (m.role !== "tool-results" || i >= newest || beforeWrite.has(i)) return m;
114
+ let touched = false;
115
+ const results = m.results.map(r => {
116
+ if (r.isError || r.content.length < MIN_COMPRESS_CHARS) return r;
117
+ if (r.content.startsWith("[earlier result")) return r;
118
+ touched = true;
119
+ // The ref survives the compression: the marker names it, and a later
120
+ // `retrieve` reads the full text back. See engine/evidence.ts.
121
+ return {
122
+ ...r,
123
+ content: compressedMarker(r.content.length, r.ref)
124
+ };
125
+ });
126
+ if (!touched) return m;
127
+ changed = true;
128
+ return {
129
+ ...m,
130
+ results
131
+ };
132
+ });
133
+ return changed ? out : messages;
134
+ }
135
+
136
+ /**
137
+ * Heuristic for "this call changed something". Deliberately loose: the cost of
138
+ * a false positive is one uncompressed read, the cost of a false negative is
139
+ * the model losing the shape it was editing.
140
+ */
141
+ const WRITE_ISH = /set|write|dispatch|navigate|tap|override|restore|delete|remove|clear|save|run|impersonat|reload/i;
142
+
143
+ /**
144
+ * A round: a user message and everything up to the next one. `pinned` when
145
+ * one of its tool calls made a change that is still applied — see
146
+ * `dropRounds`.
147
+ */
148
+
149
+ function splitRounds(messages, pinnedCallIds) {
150
+ const rounds = [];
151
+ for (const m of messages) {
152
+ if (m.role === "user" || rounds.length === 0) rounds.push({
153
+ messages: [],
154
+ size: 0,
155
+ pinned: false
156
+ });
157
+ const round = rounds[rounds.length - 1];
158
+ round.messages.push(m);
159
+ round.size += messageSize(m);
160
+ if (pinnedCallIds?.size && m.role === "assistant" && m.toolCalls?.some(c => pinnedCallIds.has(c.id))) round.pinned = true;
161
+ }
162
+ return rounds;
163
+ }
164
+
165
+ /**
166
+ * Drop whole rounds, oldest first, until `keepSize + dropped` fits — but the
167
+ * PINNED rounds last.
168
+ *
169
+ * Dropping oldest-first was the whole rule, and in a QA session the oldest
170
+ * round is usually the SETUP: the override that was armed, the store that
171
+ * was written, the user someone is impersonating. Lose it and the model can
172
+ * no longer explain the screen it is looking at, or that a "wrong" response
173
+ * is its own mock — and the changes list in the prompt names the change but
174
+ * not the reasoning around it. The ledger knows which changes are still
175
+ * applied, so a round that made one is kept (compressed, like any other) for
176
+ * as long as an unpinned round remains to drop instead. Only when nothing
177
+ * else is left do pinned rounds go, oldest first, and the caller says so.
178
+ * Strands' `pin-message.ts` is the same idea, keyed on message metadata.
179
+ *
180
+ * `minMessages` is the floor the session-level trim keeps (a history that
181
+ * opens mid-exchange is rejected by every provider; the floor is applied on
182
+ * STARTING a drop, so a drop always runs to the next user boundary).
183
+ */
184
+ function dropRounds(rounds, budget, keepSize, minMessages) {
185
+ const remaining = [...rounds];
186
+ let size = remaining.reduce((n, r) => n + r.size, 0);
187
+ let droppedRounds = 0;
188
+ let droppedPinned = 0;
189
+ const messageCount = () => remaining.reduce((n, r) => n + r.messages.length, 0);
190
+ while (remaining.length > 0 && size + keepSize > budget && messageCount() > minMessages) {
191
+ let i = remaining.findIndex(r => !r.pinned);
192
+ if (i < 0) {
193
+ i = 0;
194
+ droppedPinned += 1;
195
+ }
196
+ size -= remaining[i].size;
197
+ remaining.splice(i, 1);
198
+ droppedRounds += 1;
199
+ }
200
+ return {
201
+ kept: remaining.flatMap(r => r.messages),
202
+ droppedRounds,
203
+ droppedPinned
204
+ };
205
+ }
206
+
207
+ /**
208
+ * Trim, and say how many whole rounds were dropped — the number the UI turns
209
+ * into "older messages were trimmed from the agent's memory".
210
+ *
211
+ * A round is a user message and everything up to the next one. Once a drop
212
+ * starts it ALWAYS runs to the next user boundary: the inner loop used to stop
213
+ * at `MIN_KEEP_MESSAGES` as well, so a history could come out starting with an
214
+ * assistant or tool-results message — which every provider rejects. The
215
+ * minimum-keep guard belongs on STARTING a drop, not on finishing one.
216
+ */
217
+ export function trimHistoryReport(messages, charsPerToken = DEFAULT_CHARS_PER_TOKEN, /** Tool-call ids whose change is still applied — their rounds are dropped last. See dropRounds. */
218
+ pinnedCallIds) {
219
+ const limit = Math.floor(MAX_HISTORY_TOKENS * charsPerToken);
220
+ let total = 0;
221
+ for (const m of messages) total += messageSize(m);
222
+ if (total <= limit) return {
223
+ messages,
224
+ droppedRounds: 0,
225
+ droppedPinned: 0
226
+ };
227
+
228
+ // Compress before dropping — a compressed round still explains the screen.
229
+ const compressed = compressConsumed(messages);
230
+ let after = 0;
231
+ for (const m of compressed) after += messageSize(m);
232
+ if (after <= limit) return {
233
+ messages: compressed,
234
+ droppedRounds: 0,
235
+ droppedPinned: 0
236
+ };
237
+ const {
238
+ kept,
239
+ droppedRounds,
240
+ droppedPinned
241
+ } = dropRounds(splitRounds(compressed, pinnedCallIds), limit, 0, MIN_KEEP_MESSAGES);
242
+ return {
243
+ messages: kept,
244
+ droppedRounds,
245
+ droppedPinned
246
+ };
247
+ }
248
+
249
+ /** Exported for the history tests; not part of the package surface. */
250
+ export function trimHistory(messages) {
251
+ return trimHistoryReport(messages).messages;
252
+ }
253
+
254
+ /**
255
+ * Trim the working history of a turn that is still running.
256
+ *
257
+ * Differs from `trimHistoryReport` in one way that matters: the CURRENT round
258
+ * is never touched. A turn's own user message and the reads it has taken since
259
+ * are the thing being answered, so compressing or dropping them would make the
260
+ * request cheaper and the answer wrong. Everything before the last user
261
+ * message is fair game, in the same order as always — compress, then drop.
262
+ *
263
+ * `reserve` is what the request costs BEFORE any messages: the tool
264
+ * definitions (~8k tokens for a typical install, ~23k with everything
265
+ * installed), the system prompt, and the reply the model is allowed to write.
266
+ * Budgeting messages alone would leave the biggest fixed cost out of the sum.
267
+ */
268
+ export function budgetForRequest(messages, reserve,
269
+ /**
270
+ * A tighter ceiling on the messages than MAX_HISTORY_CHARS — set by the
271
+ * engine after the provider refused a request as too big. The proactive
272
+ * budget is an estimate; the provider's refusal is the truth.
273
+ */
274
+ cap = MAX_HISTORY_CHARS, /** The session's measured ratio; scales the whole-request ceiling. */
275
+ charsPerToken = DEFAULT_CHARS_PER_TOKEN, /** Tool-call ids whose change is still applied — their rounds are dropped last. See dropRounds. */
276
+ pinnedCallIds) {
277
+ /**
278
+ * `MAX_HISTORY_CHARS` is a MESSAGES budget and always was — subtracting the
279
+ * reserve from it is wrong by a wide margin. The tool block alone is ~94,000
280
+ * characters with every tool installed, and the system prompt another
281
+ * ~16,000, so `150,000 - reserve` left about 24,000 characters for the
282
+ * conversation and dropped every earlier round of a two-turn chat. Caught by
283
+ * the bank, which is exactly what it is for.
284
+ *
285
+ * So the messages budget is the smaller of the two ceilings: the one that
286
+ * has always applied, and whatever is left of the whole-request ceiling once
287
+ * the fixed cost is counted. In an ordinary install the first wins and
288
+ * nothing changes; the second only bites when the tools are huge.
289
+ */
290
+ const budget = Math.min(cap, Math.floor(MAX_REQUEST_TOKENS * charsPerToken) - reserve);
291
+ let total = 0;
292
+ for (const m of messages) total += messageSize(m);
293
+ if (total <= budget) return {
294
+ messages,
295
+ droppedRounds: 0,
296
+ droppedPinned: 0
297
+ };
298
+
299
+ // Where the current round begins. Nothing from here on is eligible.
300
+ let currentRound = -1;
301
+ for (let i = messages.length - 1; i >= 0; i--) {
302
+ if (messages[i].role === "user") {
303
+ currentRound = i;
304
+ break;
305
+ }
306
+ }
307
+ if (currentRound <= 0) {
308
+ // The whole history is this one round and it is over the limit by
309
+ // itself. Its consumed results are compressed, the newest kept — see the
310
+ // last-resort note below; this is the same move with nothing to drop.
311
+ return {
312
+ messages: compressConsumed(messages),
313
+ droppedRounds: 0,
314
+ droppedPinned: 0
315
+ };
316
+ }
317
+ const earlier = messages.slice(0, currentRound);
318
+ const current = messages.slice(currentRound);
319
+ let currentSize = 0;
320
+ for (const m of current) currentSize += messageSize(m);
321
+
322
+ // `false`: the earlier rounds' last result was answered long ago — the
323
+ // newest-result exemption is about the round being answered NOW.
324
+ const compressed = compressConsumed(earlier, false);
325
+ let earlierSize = 0;
326
+ for (const m of compressed) earlierSize += messageSize(m);
327
+ if (earlierSize + currentSize <= budget) {
328
+ return {
329
+ messages: [...compressed, ...current],
330
+ droppedRounds: 0,
331
+ droppedPinned: 0
332
+ };
333
+ }
334
+ const {
335
+ kept: out,
336
+ droppedRounds,
337
+ droppedPinned
338
+ } = dropRounds(splitRounds(compressed, pinnedCallIds), budget, currentSize, 0);
339
+ earlierSize = out.reduce((n, m) => n + messageSize(m), 0);
340
+ /**
341
+ * LAST RESORT, inside the current round. Everything earlier is gone and the
342
+ * turn's own reads are still over the limit — a twelve-step investigation
343
+ * of 24k-character results does that by itself. The consumed ones (an
344
+ * assistant message came after them) are compressed the same way earlier
345
+ * rounds were, newest result and the reads before a write still exempt.
346
+ * Their refs make this lossless for the model: `retrieve` reads them back.
347
+ */
348
+ const currentOut = out.length === 0 && earlierSize + currentSize > budget ? compressConsumed(current) : current;
349
+ return {
350
+ messages: [...out, ...currentOut],
351
+ droppedRounds,
352
+ droppedPinned
353
+ };
354
+ }
355
+ //# sourceMappingURL=historyBudget.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["compressedMarker","DEFAULT_CHARS_PER_TOKEN","MAX_HISTORY_TOKENS","MAX_REQUEST_TOKENS","MAX_HISTORY_CHARS","MAX_REQUEST_CHARS","MIN_KEEP_MESSAGES","MIN_COMPRESS_CHARS","messageSize","m","JSON","stringify","length","compressConsumed","messages","exemptNewest","newest","i","role","beforeWrite","Set","toolCalls","some","c","WRITE_ISH","test","input","name","j","add","changed","out","map","has","touched","results","r","isError","content","startsWith","ref","splitRounds","pinnedCallIds","rounds","push","size","pinned","round","id","dropRounds","budget","keepSize","minMessages","remaining","reduce","n","droppedRounds","droppedPinned","messageCount","findIndex","splice","kept","flatMap","trimHistoryReport","charsPerToken","limit","Math","floor","total","compressed","after","trimHistory","budgetForRequest","reserve","cap","min","currentRound","earlier","slice","current","currentSize","earlierSize","currentOut"],"sourceRoot":"../../../src","sources":["engine/historyBudget.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,gBAAgB,QAAQ,YAAY;AAC7C,SAASC,uBAAuB,QAAQ,oBAAoB;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,kBAAkB,GAAG,MAAM;AACxC;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,kBAAkB,GAAG,OAAO;AACzC,OAAO,MAAMC,iBAAiB,GAAGF,kBAAkB,GAAGD,uBAAuB;AAC7E,OAAO,MAAMI,iBAAiB,GAAGF,kBAAkB,GAAGF,uBAAuB;AAC7E,MAAMK,iBAAiB,GAAG,CAAC;AAC3B;AACA,MAAMC,kBAAkB,GAAG,GAAG;AAE9B,OAAO,SAASC,WAAWA,CAACC,CAAe,EAAU;EACnD,IAAI;IACF,OAAOC,IAAI,CAACC,SAAS,CAACF,CAAC,CAAC,CAACG,MAAM;EACjC,CAAC,CAAC,MAAM;IACN,OAAO,CAAC;EACV;AACF;;AAEA;AACA;AACA;AACA;A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