@aragon-agent/cli 0.6.61 → 0.6.63

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 (44) hide show
  1. package/README.md +99 -7
  2. package/dist/agent/headless.js +67 -6
  3. package/dist/agent/prompt-options.d.ts +7 -0
  4. package/dist/app/App.js +37 -5
  5. package/dist/commands/builtins.js +2 -1
  6. package/dist/commands/catalog.js +1 -1
  7. package/dist/compaction/archive.d.ts +27 -1
  8. package/dist/compaction/archive.js +8 -0
  9. package/dist/compaction/budget.d.ts +73 -0
  10. package/dist/compaction/budget.js +89 -0
  11. package/dist/compaction/child.js +6 -1
  12. package/dist/compaction/command.js +147 -1
  13. package/dist/compaction/compactor.d.ts +132 -15
  14. package/dist/compaction/compactor.js +288 -95
  15. package/dist/compaction/context-command.js +21 -0
  16. package/dist/compaction/memory-agent-prompt.d.ts +32 -0
  17. package/dist/compaction/memory-agent-prompt.js +76 -0
  18. package/dist/compaction/memory-agent-tools.d.ts +88 -0
  19. package/dist/compaction/memory-agent-tools.js +338 -0
  20. package/dist/compaction/memory-agent.d.ts +114 -0
  21. package/dist/compaction/memory-agent.js +220 -0
  22. package/dist/compaction/prune.d.ts +129 -0
  23. package/dist/compaction/prune.js +386 -0
  24. package/dist/compaction/retry-plan.d.ts +103 -0
  25. package/dist/compaction/retry-plan.js +136 -0
  26. package/dist/compaction/summarize-ladder.d.ts +149 -0
  27. package/dist/compaction/summarize-ladder.js +273 -0
  28. package/dist/compaction/wiring.d.ts +19 -0
  29. package/dist/compaction/wiring.js +65 -1
  30. package/dist/config/cli-commands.d.ts +1 -1
  31. package/dist/config/cli-commands.js +16 -0
  32. package/dist/config/env.d.ts +3 -1
  33. package/dist/config/env.js +44 -2
  34. package/dist/exec/events.d.ts +30 -0
  35. package/dist/exec/runner.d.ts +9 -0
  36. package/dist/exec/runner.js +51 -2
  37. package/dist/host/controller-feed.d.ts +12 -3
  38. package/dist/host/controller-feed.js +1 -1
  39. package/dist/host/interaction.js +5 -2
  40. package/dist/logging/install.d.ts +38 -1
  41. package/dist/logging/install.js +12 -1
  42. package/dist/session/persist.js +21 -5
  43. package/dist/session/validate-session.js +18 -2
  44. package/package.json +3 -3
@@ -131,7 +131,12 @@ export function createChildContextManager(req, deps) {
131
131
  },
132
132
  // MECHANISM B - the instance bound (RV-2 / DH-16). The SAME bound the
133
133
  // lead's own manager runs under (main-agent parity).
134
- { maxPerRun: COMPACTION_LIMITS.maxPerRun });
134
+ //
135
+ // `agentic: false` IS THE THIRD BOUND (v3 §4.5). A child has no card and no
136
+ // `notify`, so a multi-turn compaction inside it is spend nobody can watch
137
+ // and turns nobody can see; prune and one JSON call are enough for a
138
+ // background worker.
139
+ { maxPerRun: COMPACTION_LIMITS.maxPerRun, agentic: false });
135
140
  return {
136
141
  // THERE IS NO `/compact` FOR A CHILD, so nothing is ever queued and the
137
142
  // manual branch of `shouldCompact` is unreachable by construction.
@@ -112,6 +112,21 @@ export function formatCompactionStatus(ctx) {
112
112
  `(${formatTokens(relief.charsRemoved)} chars) in ` +
113
113
  `${relief.compactions} ${relief.compactions === 1 ? 'compaction' : 'compactions'}`);
114
114
  }
115
+ // THE v3 SURFACES (W1 / W3 / W4). Rendered only when they have something to say,
116
+ // so a session that has never compacted reads exactly as it did before.
117
+ const prune = snapshot.prune;
118
+ if (prune && prune.actions > 0) {
119
+ lines.push(` Prune: ${prune.actions} bodies, ${formatTokens(prune.chars)} chars rewritten`);
120
+ }
121
+ const budget = snapshot.budget;
122
+ if (budget) {
123
+ lines.push(` Budget: ${formatBudgetLine(budget)}`);
124
+ }
125
+ else {
126
+ lines.push(` Budget: ${budgetHeadline(config.budgetTokens, config.budgetUsd)}`);
127
+ }
128
+ lines.push(` Agentic: ${config.agentic ? 'on' : 'off'}` +
129
+ (snapshot.agent ? ` (${agentLine(snapshot.agent)})` : ''));
115
130
  const archives = archiveSummary(ctx);
116
131
  if (archives)
117
132
  lines.push(` Archive ${archives}`);
@@ -252,6 +267,16 @@ function formatCompactionShow(ctx, raw) {
252
267
  lines.push(` Clipped: ${entry.tailRelief.messages} tool results in the retained turns ` +
253
268
  `(${formatTokens(entry.tailRelief.charsRemoved)} chars)`);
254
269
  }
270
+ // THE v3 SECTIONS, printed only when this archive has them (W1 / W3 / W4).
271
+ // A v1 archive has none of the three and renders exactly as it did before.
272
+ if (entry.prune) {
273
+ lines.push(` Pruned: ${entry.prune.actions.length} bodies `
274
+ + `(${formatTokens(entry.prune.actions.reduce((sum, a) => sum + a.removedChars, 0))} chars)`);
275
+ }
276
+ if (entry.budget)
277
+ lines.push(` Budget: ${formatBudgetLine(entry.budget)}`);
278
+ if (entry.agent)
279
+ lines.push(` Agent: ${agentLine(entry.agent)}`);
255
280
  lines.push(` File: ${entry.path}`);
256
281
  if (entry.summary) {
257
282
  lines.push('');
@@ -259,7 +284,99 @@ function formatCompactionShow(ctx, raw) {
259
284
  }
260
285
  return lines.join('\n');
261
286
  }
262
- const USAGE = 'Usage: /compact [status | on | off | threshold <n> | keep <n> | history | show <n> | <instructions>]';
287
+ /**
288
+ * `/compact budget ...` (W3): `budget <tokens>`, `budget usd <amount>`, `off`.
289
+ *
290
+ * RETURNS THE TOAST TEXT, OR `null` AFTER PRINTING ITS OWN REFUSAL. The applied
291
+ * value is reported, never the requested one: `clampCompactionConfig` may move a
292
+ * number, and reporting what was typed would make the clamp invisible.
293
+ */
294
+ function applyBudgetVerb(ctx, raw) {
295
+ const controller = ctx.controller;
296
+ const words = raw.split(/\s+/).filter(Boolean);
297
+ const usd = (words[0] ?? '').toLowerCase() === 'usd';
298
+ const amount = (usd ? words[1] : words[0]) ?? '';
299
+ const off = amount === '' || /^(0|off|none|unlimited)$/i.test(amount);
300
+ const parsed = off ? 0 : Number(amount.replace(/[$,]/g, ''));
301
+ if (!Number.isFinite(parsed) || parsed < 0) {
302
+ ctx.notify('warn', 'Usage: /compact budget <tokens|off> | /compact budget usd <amount|off>');
303
+ return null;
304
+ }
305
+ const patch = usd
306
+ ? { budgetUsd: parsed } : { budgetTokens: Math.round(parsed) };
307
+ const applied = controller.setCompactionConfig(patch);
308
+ ctx.persistConfig({ compaction: patch });
309
+ if (usd) {
310
+ return applied.budgetUsd > 0
311
+ ? `Compaction budget: $${applied.budgetUsd.toFixed(2)} per operation.`
312
+ : 'Compaction USD budget: unlimited.';
313
+ }
314
+ return applied.budgetTokens > 0
315
+ ? `Compaction budget: ${formatTokens(applied.budgetTokens)} tokens per operation.`
316
+ : 'Compaction token budget: unlimited.';
317
+ }
318
+ const USAGE = 'Usage: /compact [status | spend | budget [usd] <n|off> | agent on|off | prune on|off '
319
+ + '| on | off | threshold <n> | keep <n> | history | show <n> | <instructions>]';
320
+ /** The `Budget:` value for a snapshot: spend against both ceilings (W3). */
321
+ function formatBudgetLine(budget) {
322
+ const tokens = budget.limitTokens > 0
323
+ ? `${formatTokens(budget.spentTokens)} / ${formatTokens(budget.limitTokens)} tokens`
324
+ : `${formatTokens(budget.spentTokens)} tokens (no limit)`;
325
+ const usd = budget.limitUsd <= 0
326
+ ? 'no USD limit'
327
+ : budget.priceUnknown
328
+ ? `USD n/a (no price table for this model)`
329
+ : `${formatCost(budget.spentUsd)} / ${formatCost(budget.limitUsd)}`;
330
+ const stop = budget.stop === undefined ? '' : ` - stopped: ${budget.stop}`;
331
+ return `${tokens} - ${usd}${stop}`;
332
+ }
333
+ /** The `Budget:` value before the first compaction: what the NEXT one may spend. */
334
+ function budgetHeadline(tokens, usd) {
335
+ const parts = [
336
+ tokens > 0 ? `${formatTokens(tokens)} tokens per operation` : 'no token limit',
337
+ usd > 0 ? `${formatCost(usd)} per operation` : 'no USD limit',
338
+ ];
339
+ return `${parts.join(' - ')} (nothing spent yet)`;
340
+ }
341
+ /** `4 turns, 9 tool calls` for the `Agentic:` row (W4). */
342
+ function agentLine(agent) {
343
+ const parts = [
344
+ `${agent.turns} ${agent.turns === 1 ? 'turn' : 'turns'}`,
345
+ `${agent.toolCalls} tool ${agent.toolCalls === 1 ? 'call' : 'calls'}`,
346
+ `${agent.submissions} ${agent.submissions === 1 ? 'submission' : 'submissions'}`,
347
+ ];
348
+ return `last: ${parts.join(', ')}`;
349
+ }
350
+ /**
351
+ * `/compact spend` - the session's cumulative spend and the last operation's ledger.
352
+ *
353
+ * TWO DIFFERENT QUESTIONS, and answering only the first is what made a budget
354
+ * feel like a black box: "what has compaction cost this session" (a total) and
355
+ * "what did the last one cost against its ceiling" (a snapshot).
356
+ */
357
+ function formatCompactionSpend(ctx) {
358
+ const snapshot = ctx.controller.getCompactionSnapshot();
359
+ const config = ctx.controller.getCompactionConfig();
360
+ const pricing = snapshot.pricingUnknown
361
+ ? `unknown (no price table for ${snapshot.model || 'the summarizer'})`
362
+ : formatCost(compactionCost(ctx));
363
+ const lines = [
364
+ 'compaction spend (this session)',
365
+ ` Tokens: ${formatTokens(snapshot.usage.inputTokens)} in / `
366
+ + `${formatTokens(snapshot.usage.outputTokens)} out`,
367
+ ` Cost: ${pricing}`,
368
+ ` Calls: ${snapshot.compactions} ${snapshot.compactions === 1 ? 'attempt' : 'attempts'}`,
369
+ ` Limits: ${budgetHeadline(config.budgetTokens, config.budgetUsd)}`,
370
+ ];
371
+ if (snapshot.budget) {
372
+ lines.push(` Last: ${formatBudgetLine(snapshot.budget)}`);
373
+ }
374
+ if (snapshot.prune && snapshot.prune.actions > 0) {
375
+ lines.push(` Pruned: ${snapshot.prune.actions} bodies, `
376
+ + `${formatTokens(snapshot.prune.chars)} chars (free)`);
377
+ }
378
+ return lines.join('\n');
379
+ }
263
380
  /**
264
381
  * The `/compact` handler.
265
382
  *
@@ -324,6 +441,35 @@ export async function runCompactCommand(ctx) {
324
441
  ctx.toast('success', `Keeping ${applied.keepRecentTurns} recent turns verbatim.`);
325
442
  return;
326
443
  }
444
+ // --- THE v3 VERBS, ALL BEFORE THE FREE-TEXT FALL-THROUGH (P1-2) -----------
445
+ // `/compact spend` used to reach the fall-through, which took the word "spend"
446
+ // as summarizer instructions and compacted the conversation. Every new verb is
447
+ // therefore handled here, above `// --- Compact now`.
448
+ if (verb === 'spend') {
449
+ ctx.notify('info', formatCompactionSpend(ctx));
450
+ return;
451
+ }
452
+ if (verb === 'budget') {
453
+ const applied = applyBudgetVerb(ctx, arg.slice((rawVerb ?? '').length).trim());
454
+ if (applied !== null)
455
+ ctx.toast('success', applied);
456
+ return;
457
+ }
458
+ if (verb === 'agent' || verb === 'prune') {
459
+ const on = value === 'on' || value === 'true' || value === '1';
460
+ const off = value === 'off' || value === 'false' || value === '0';
461
+ if (!on && !off) {
462
+ ctx.notify('warn', `Usage: /compact ${verb} on|off`);
463
+ return;
464
+ }
465
+ const patch = verb === 'agent' ? { agentic: on } : { prune: on };
466
+ const applied = controller.setCompactionConfig(patch);
467
+ ctx.persistConfig({ compaction: patch });
468
+ ctx.toast('success', verb === 'agent'
469
+ ? `Multi-turn compaction ${applied.agentic ? 'on' : 'off'}.`
470
+ : `Redundancy pruning ${applied.prune ? 'on' : 'off'}.`);
471
+ return;
472
+ }
327
473
  // BEFORE THE FREE-TEXT FALL-THROUGH, so a user cannot accidentally summarize
328
474
  // with the word "history".
329
475
  if (verb === 'history') {
@@ -5,8 +5,10 @@ import type { CliConfig } from '@aragon-agent/tui/model/config/schema';
5
5
  import type { NoticeLevel } from '@aragon-agent/tui/model/agent/reducer';
6
6
  import { resolveFastTier } from '@aragon-agent/tui/model/fast/resolve';
7
7
  import { ContextMeter } from '@aragon-agent/tui/model/compaction/meter';
8
+ import type { AgentTurn, AgentTurnRequest } from './memory-agent.js';
9
+ import { type SummarizerChoice } from './summarize-ladder.js';
8
10
  import { type CompactionIdentity } from './memory-identity.js';
9
- import type { CompactionEvent, Pressure } from '@aragon-agent/tui/model/compaction/types';
11
+ import type { ArchivePruneAction, CompactionEvent, Pressure } from '@aragon-agent/tui/model/compaction/types';
10
12
  export interface CompactorDeps {
11
13
  mainRole?: ModelRole;
12
14
  resolveFastCandidate?: () => ReturnType<typeof resolveFastTier>;
@@ -36,6 +38,17 @@ export interface CompactorDeps {
36
38
  isPricedModel: (ref: Pick<ModelRef, 'providerId' | 'modelId'>) => boolean;
37
39
  /** The compactor's OWN fail-fast transport (D-10). Supplied by the wiring. */
38
40
  complete: (providerId: string, request: LLMRequest) => Promise<AssistantMessage>;
41
+ /**
42
+ * One agent turn for the multi-turn compaction agent (W4 / P1-6).
43
+ *
44
+ * OPTIONAL, AND ABSENT MEANS `agentic` CANNOT RUN. The wiring supplies it as
45
+ * `registry.stream` + `consumeStream`; a test that scripts the transport can
46
+ * supply its own, which is what makes AC-9..AC-12 possible without a network.
47
+ * When it is absent the compactor falls back to the single-shot JSON call
48
+ * (D-14) even with `compaction.agentic` on - a degraded path that still
49
+ * compacts, disclosed on the record as `agent.fallback: 'single-shot'`.
50
+ */
51
+ runAgentTurn?: (request: AgentTurnRequest) => Promise<AgentTurn>;
39
52
  emit: (event: CompactionEvent) => void;
40
53
  notify: (level: NoticeLevel, text: string) => void;
41
54
  /**
@@ -79,14 +92,25 @@ export interface CompactorOptions {
79
92
  * value, so every existing construction site is unchanged.
80
93
  */
81
94
  maxPerRun?: number;
95
+ /**
96
+ * Force the multi-turn agent OFF for this compactor (v3 §4.5).
97
+ *
98
+ * A CHILD HAS NO CARD (its `notify` is a no-op and it emits one log line), so
99
+ * the turns and tool calls of a multi-turn compaction are cost with nobody to
100
+ * watch it - while the bill joins the parent's session. `false` here keeps
101
+ * `compaction.subagents` meaning "does the child compact at all" rather than
102
+ * "how large is the child's bill". Prune and the single-shot JSON call remain,
103
+ * which is everything a background worker needs.
104
+ */
105
+ agentic?: boolean;
82
106
  }
83
- /** The summarizer the next compaction would use. */
84
- export interface SummarizerChoice {
85
- role: ModelRole;
86
- ref: ModelRef;
87
- /** Whether the fast tier supplied it, for `/compact status` and the card. */
88
- fromFastTier: boolean;
89
- }
107
+ /**
108
+ * The summarizer the next compaction would use.
109
+ *
110
+ * DECLARED IN THE LADDER because that is where it is consumed, and re-exported
111
+ * here because `resolveSummarizer()` and the retry ladder's callers name it.
112
+ */
113
+ export type { SummarizerChoice };
90
114
  export declare class Compactor implements ContextManager {
91
115
  private readonly deps;
92
116
  private readonly log;
@@ -101,6 +125,11 @@ export declare class Compactor implements ContextManager {
101
125
  private costUsd;
102
126
  private consecutiveNoProgress;
103
127
  private consecutiveTransportFailures;
128
+ private consecutiveSemanticFailures;
129
+ private prunedActions;
130
+ private prunedChars;
131
+ /** The operation the engine has most recently settled, for `/compact status`. */
132
+ private settled;
104
133
  private selfDisabled;
105
134
  private selfDisabledReason;
106
135
  private pendingManual;
@@ -113,6 +142,10 @@ export declare class Compactor implements ContextManager {
113
142
  private identity;
114
143
  private legacyFailureNotified;
115
144
  private readonly maxPerRun;
145
+ /** `undefined` = follow the config; `false` = this instance never runs the agent. */
146
+ private readonly agenticOverride;
147
+ /** The retry ladder, built on first use (see `get ladder`). */
148
+ private ladderCache;
116
149
  constructor(deps: CompactorDeps, opts?: CompactorOptions);
117
150
  onRunStart(): void;
118
151
  onRunEnd(): void;
@@ -127,19 +160,52 @@ export declare class Compactor implements ContextManager {
127
160
  shouldCompact(probe: CompactionProbe): boolean;
128
161
  compact(ctx: CompactionContext): Promise<CompactionOutcome>;
129
162
  private prepareCandidate;
163
+ /**
164
+ * Stage 0: rewrite redundant bodies in the band about to be replaced (W1).
165
+ *
166
+ * ZERO MODEL COST, AND ZERO EVENTS WHEN IT FINDS NOTHING: the phase is emitted
167
+ * only when at least one body actually changed, so a session with
168
+ * `compaction.prune` off - or one with nothing redundant - produces the same
169
+ * stream it produced before this feature existed.
170
+ */
171
+ private pruneStage;
172
+ /** The prior memory this history carries, when its identity still verifies. */
173
+ private priorMemory;
174
+ /**
175
+ * The free win: when pruning alone already clears the threshold, do not
176
+ * summarize at all.
177
+ *
178
+ * IT MUST STILL SATISFY `checkCandidate`, which is why the candidate goes
179
+ * through the same gate the summarized one does - a prune-only splice that
180
+ * reclaims nothing (`no_token_reclaim`) or that leaves the history above the
181
+ * window (`protected_memory_too_large`) is not a win, and falling through to
182
+ * the summary is the honest answer.
183
+ */
184
+ private pruneOnlyCandidate;
130
185
  private selectInput;
131
186
  private checkMinimumCandidate;
187
+ /**
188
+ * The digest for whichever path will send it, delegated to the ladder.
189
+ *
190
+ * the code that picks the path: `summarize-ladder.ts` owns the ask, the classify
191
+ * and the ask-again loop, and this file keeps the ORDER of the stages. Two
192
+ * ceilings act on that loop (the attempt count and the operation ledger) and
193
+ * both are checked there, before a request is sent.
194
+ */
132
195
  private digestFor;
133
- private summarize;
196
+ /** Whether the multi-turn path is both configured and wired. */
197
+ private agentic;
134
198
  /**
135
- * Whether the second attempt moves to the main model.
199
+ * The retry ladder, built on first use out of this compactor's own primitives.
136
200
  *
137
- * After an unusable answer it always does (a stronger model may do better). After a
138
- * transport failure it only does when the main model is reached through a DIFFERENT
139
- * endpoint: against the same one the switch is a no-op that also rebuilds the digest,
140
- * and the retry should simply be the same request again.
201
+ * and a class field initializer runs before the constructor's parameter
202
+ * session where `compaction.enabled` is false, which never needs it.
141
203
  */
142
- private shouldEscalate;
204
+ private get ladder();
205
+ /** The one agent-turn port, refused rather than asserted when it is absent. */
206
+ private runAgentTurn;
207
+ /** The retry ladder (W2): its table, its attempts and its ceilings are the ladder's. */
208
+ private summarize;
143
209
  private callOnce;
144
210
  private checkCandidate;
145
211
  private isCurrent;
@@ -169,6 +235,8 @@ export declare class Compactor implements ContextManager {
169
235
  */
170
236
  private relaxedFields;
171
237
  private finishRecord;
238
+ /** The prune tally in record shape, with the per-kind counters the card shows. */
239
+ private pruneRecord;
172
240
  /** Commit only the engine/host verdict; candidates have no authority before this point. */
173
241
  settleOperation(verdict: {
174
242
  applied: boolean;
@@ -190,6 +258,15 @@ export declare class Compactor implements ContextManager {
190
258
  * summarizer, which proves the path works, so the transport streak ends.
191
259
  */
192
260
  private noteFailure;
261
+ /**
262
+ * The third counter (W2): "the model answered, and we could not use the answer".
263
+ *
264
+ * SEPARATE FROM `stuckLimit` ON PURPOSE. Sharing one counter meant two unusable
265
+ * deltas - the common shape of a bad summarizer on a long band - paused
266
+ * auto-compaction for the rest of the run, even though every one of those
267
+ * attempts proved the transport, the key and the model all worked.
268
+ */
269
+ private noteSemanticFailure;
193
270
  private noteTransportFailure;
194
271
  private noteNoProgress;
195
272
  private selfDisable;
@@ -197,9 +274,39 @@ export declare class Compactor implements ContextManager {
197
274
  messages?: readonly Message[];
198
275
  systemPrompt?: string;
199
276
  }): Pressure;
277
+ /**
278
+ * Fold one applied operation's pruning into the session totals (W1).
279
+ *
280
+ * COUNTED ONLY WHEN THE SPLICE LANDED, for the same reason `tokensReclaimed`
281
+ * is: a candidate the engine refused reclaimed nothing, so reporting its saving
282
+ * would be a number the history never benefited from.
283
+ */
284
+ private applyPruneTotals;
285
+ /** The last operation's budget snapshot and agent effort, for `/compact status`. */
286
+ private lastSettled;
287
+ /**
288
+ * The settled operation's prune detail, for the archive (W1).
289
+ *
290
+ * THE RECORD CARRIES COUNTS ONLY, because it is dispatched into the reducer and
291
+ * retained in view state; the per-action detail (`messageIndex`, `sourceId`,
292
+ * `removedChars`) is what makes an audit of a pruned body possible and belongs
293
+ * on disk, not in React state (RV-3's rule for the dropped history).
294
+ */
295
+ lastPruneActions(): ArchivePruneAction[];
200
296
  lastMeasured(): Pressure | null;
201
297
  recordApplied(tokensBefore: number, tokensAfter: number): void;
202
298
  sessionTotals(): {
299
+ agent?: {
300
+ turns: number;
301
+ toolCalls: number;
302
+ submissions: number;
303
+ fallback?: "single-shot";
304
+ } | undefined;
305
+ budget?: import("./budget.js").BudgetSnapshot | undefined;
306
+ prune: {
307
+ actions: number;
308
+ chars: number;
309
+ };
203
310
  selfDisabledReason?: string | undefined;
204
311
  compactions: number;
205
312
  applied: number;
@@ -219,5 +326,15 @@ export declare class Compactor implements ContextManager {
219
326
  private meter;
220
327
  private mainRef;
221
328
  private settingsKey;
329
+ /**
330
+ * The ONE accounting entry for spend (P1-5).
331
+ *
332
+ * `onUsage` is the only callback every real call funnels through - the agent's
333
+ * turns, the single-shot fallback and core's own `withRetry` attempts - so the
334
+ * BUDGET IS CHARGED HERE and nowhere else. Putting the charge inside
335
+ * `runMemoryAgent` instead would have left the D-14 fallback un-metered, which
336
+ * would have made "default unlimited, adjustable" a promise that only held for
337
+ * models that support tools.
338
+ */
222
339
  private noteUsage;
223
340
  }