@aragon-agent/cli 0.6.62 → 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 (36) hide show
  1. package/README.md +99 -7
  2. package/dist/agent/headless.js +18 -0
  3. package/dist/commands/builtins.js +2 -1
  4. package/dist/commands/catalog.js +1 -1
  5. package/dist/compaction/archive.d.ts +27 -1
  6. package/dist/compaction/archive.js +8 -0
  7. package/dist/compaction/budget.d.ts +73 -0
  8. package/dist/compaction/budget.js +89 -0
  9. package/dist/compaction/child.js +6 -1
  10. package/dist/compaction/command.js +147 -1
  11. package/dist/compaction/compactor.d.ts +132 -15
  12. package/dist/compaction/compactor.js +288 -95
  13. package/dist/compaction/context-command.js +21 -0
  14. package/dist/compaction/memory-agent-prompt.d.ts +32 -0
  15. package/dist/compaction/memory-agent-prompt.js +76 -0
  16. package/dist/compaction/memory-agent-tools.d.ts +88 -0
  17. package/dist/compaction/memory-agent-tools.js +338 -0
  18. package/dist/compaction/memory-agent.d.ts +114 -0
  19. package/dist/compaction/memory-agent.js +220 -0
  20. package/dist/compaction/prune.d.ts +129 -0
  21. package/dist/compaction/prune.js +386 -0
  22. package/dist/compaction/retry-plan.d.ts +103 -0
  23. package/dist/compaction/retry-plan.js +136 -0
  24. package/dist/compaction/summarize-ladder.d.ts +149 -0
  25. package/dist/compaction/summarize-ladder.js +273 -0
  26. package/dist/compaction/wiring.d.ts +19 -0
  27. package/dist/compaction/wiring.js +65 -1
  28. package/dist/config/cli-commands.d.ts +1 -1
  29. package/dist/config/cli-commands.js +16 -0
  30. package/dist/config/env.d.ts +3 -1
  31. package/dist/config/env.js +44 -2
  32. package/dist/exec/events.d.ts +30 -0
  33. package/dist/exec/runner.js +6 -0
  34. package/dist/logging/install.d.ts +27 -0
  35. package/dist/session/validate-session.js +11 -0
  36. package/package.json +3 -3
@@ -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
  }