@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.
- package/README.md +99 -7
- package/dist/agent/headless.js +67 -6
- package/dist/agent/prompt-options.d.ts +7 -0
- package/dist/app/App.js +37 -5
- package/dist/commands/builtins.js +2 -1
- package/dist/commands/catalog.js +1 -1
- package/dist/compaction/archive.d.ts +27 -1
- package/dist/compaction/archive.js +8 -0
- package/dist/compaction/budget.d.ts +73 -0
- package/dist/compaction/budget.js +89 -0
- package/dist/compaction/child.js +6 -1
- package/dist/compaction/command.js +147 -1
- package/dist/compaction/compactor.d.ts +132 -15
- package/dist/compaction/compactor.js +288 -95
- package/dist/compaction/context-command.js +21 -0
- package/dist/compaction/memory-agent-prompt.d.ts +32 -0
- package/dist/compaction/memory-agent-prompt.js +76 -0
- package/dist/compaction/memory-agent-tools.d.ts +88 -0
- package/dist/compaction/memory-agent-tools.js +338 -0
- package/dist/compaction/memory-agent.d.ts +114 -0
- package/dist/compaction/memory-agent.js +220 -0
- package/dist/compaction/prune.d.ts +129 -0
- package/dist/compaction/prune.js +386 -0
- package/dist/compaction/retry-plan.d.ts +103 -0
- package/dist/compaction/retry-plan.js +136 -0
- package/dist/compaction/summarize-ladder.d.ts +149 -0
- package/dist/compaction/summarize-ladder.js +273 -0
- package/dist/compaction/wiring.d.ts +19 -0
- package/dist/compaction/wiring.js +65 -1
- package/dist/config/cli-commands.d.ts +1 -1
- package/dist/config/cli-commands.js +16 -0
- package/dist/config/env.d.ts +3 -1
- package/dist/config/env.js +44 -2
- package/dist/exec/events.d.ts +30 -0
- package/dist/exec/runner.d.ts +9 -0
- package/dist/exec/runner.js +51 -2
- package/dist/host/controller-feed.d.ts +12 -3
- package/dist/host/controller-feed.js +1 -1
- package/dist/host/interaction.js +5 -2
- package/dist/logging/install.d.ts +38 -1
- package/dist/logging/install.js +12 -1
- package/dist/session/persist.js +21 -5
- package/dist/session/validate-session.js +18 -2
- package/package.json +3 -3
package/dist/config/env.js
CHANGED
|
@@ -18,7 +18,9 @@
|
|
|
18
18
|
* ARAGON_UPDATE,
|
|
19
19
|
* ARAGON_COMPACTION, ARAGON_COMPACTION_THRESHOLD,
|
|
20
20
|
* ARAGON_COMPACTION_KEEP_TURNS, ARAGON_COMPACTION_SUBAGENTS,
|
|
21
|
-
* ARAGON_COMPACTION_ARCHIVE,
|
|
21
|
+
* ARAGON_COMPACTION_ARCHIVE, ARAGON_COMPACTION_AGENTIC,
|
|
22
|
+
* ARAGON_COMPACTION_PRUNE, ARAGON_COMPACTION_BUDGET_TOKENS,
|
|
23
|
+
* ARAGON_COMPACTION_BUDGET_USD,
|
|
22
24
|
* ARAGON_JOBS_ENABLED, ARAGON_JOBS_WAIT_SECONDS, ARAGON_JOBS_STALL_SECONDS,
|
|
23
25
|
* ARAGON_JOBS_PERSIST_LOG, ARAGON_JOBS_NOTICE_STEER,
|
|
24
26
|
* ARAGON_PROMPTS (the quick-prompt library's `enabled` switch, and only that),
|
|
@@ -434,12 +436,23 @@ export function readEnvConfig() {
|
|
|
434
436
|
// disk in an environment that may not permit it.
|
|
435
437
|
const compactionSubagents = process.env.ARAGON_COMPACTION_SUBAGENTS?.trim().toLowerCase();
|
|
436
438
|
const compactionArchive = process.env.ARAGON_COMPACTION_ARCHIVE?.trim().toLowerCase();
|
|
439
|
+
// THE FOUR v3 KEYS (context-compaction-v3 W6). Same contract as the five above:
|
|
440
|
+
// a bad value is left ABSENT rather than resolved to a default, so the config
|
|
441
|
+
// layer underneath - and `clampCompactionConfig` - still owns the fallback.
|
|
442
|
+
const compactionAgentic = process.env.ARAGON_COMPACTION_AGENTIC?.trim().toLowerCase();
|
|
443
|
+
const compactionPrune = process.env.ARAGON_COMPACTION_PRUNE?.trim().toLowerCase();
|
|
444
|
+
const compactionBudgetTokens = process.env.ARAGON_COMPACTION_BUDGET_TOKENS?.trim();
|
|
445
|
+
const compactionBudgetUsd = process.env.ARAGON_COMPACTION_BUDGET_USD?.trim();
|
|
437
446
|
const positive = (v) => v === '1' || v === 'true' || v === 'on' || v === 'yes';
|
|
438
447
|
if ((compaction !== undefined && compaction.length > 0) ||
|
|
439
448
|
(compactionThreshold !== undefined && compactionThreshold.length > 0) ||
|
|
440
449
|
(compactionKeepTurns !== undefined && compactionKeepTurns.length > 0) ||
|
|
441
450
|
(compactionSubagents !== undefined && compactionSubagents.length > 0) ||
|
|
442
|
-
(compactionArchive !== undefined && compactionArchive.length > 0)
|
|
451
|
+
(compactionArchive !== undefined && compactionArchive.length > 0) ||
|
|
452
|
+
(compactionAgentic !== undefined && compactionAgentic.length > 0) ||
|
|
453
|
+
(compactionPrune !== undefined && compactionPrune.length > 0) ||
|
|
454
|
+
(compactionBudgetTokens !== undefined && compactionBudgetTokens.length > 0) ||
|
|
455
|
+
(compactionBudgetUsd !== undefined && compactionBudgetUsd.length > 0)) {
|
|
443
456
|
const section = {};
|
|
444
457
|
if (compaction !== undefined && compaction.length > 0) {
|
|
445
458
|
section.enabled = positive(compaction);
|
|
@@ -450,6 +463,22 @@ export function readEnvConfig() {
|
|
|
450
463
|
if (compactionArchive !== undefined && compactionArchive.length > 0) {
|
|
451
464
|
section.archive = positive(compactionArchive);
|
|
452
465
|
}
|
|
466
|
+
if (compactionAgentic !== undefined && compactionAgentic.length > 0) {
|
|
467
|
+
section.agentic = positive(compactionAgentic);
|
|
468
|
+
}
|
|
469
|
+
if (compactionPrune !== undefined && compactionPrune.length > 0) {
|
|
470
|
+
section.prune = positive(compactionPrune);
|
|
471
|
+
}
|
|
472
|
+
if (compactionBudgetTokens !== undefined && compactionBudgetTokens.length > 0) {
|
|
473
|
+
const n = parseBudgetNumber(compactionBudgetTokens);
|
|
474
|
+
if (n !== null)
|
|
475
|
+
section.budgetTokens = Math.round(n);
|
|
476
|
+
}
|
|
477
|
+
if (compactionBudgetUsd !== undefined && compactionBudgetUsd.length > 0) {
|
|
478
|
+
const n = parseBudgetNumber(compactionBudgetUsd);
|
|
479
|
+
if (n !== null)
|
|
480
|
+
section.budgetUsd = n;
|
|
481
|
+
}
|
|
453
482
|
if (compactionThreshold !== undefined && compactionThreshold.length > 0) {
|
|
454
483
|
// Left ABSENT on a bad value rather than clamped to a default, so a typo
|
|
455
484
|
// falls through to the config layer instead of masking it for the session.
|
|
@@ -548,6 +577,19 @@ function envBool(value) {
|
|
|
548
577
|
const v = value.trim().toLowerCase();
|
|
549
578
|
return !(v === '0' || v === 'false' || v === 'off' || v === 'no');
|
|
550
579
|
}
|
|
580
|
+
/**
|
|
581
|
+
* A budget number from the environment, or `null` when it is not one.
|
|
582
|
+
*
|
|
583
|
+
* `off`/`unlimited`/`0` all mean "no ceiling" (D-8), and a typo returns `null`
|
|
584
|
+
* so the key stays ABSENT - the rule `ARAGON_COMPACTION_THRESHOLD` states three
|
|
585
|
+
* lines above. Never throws, never clamps: the clamp is `clampCompactionConfig`.
|
|
586
|
+
*/
|
|
587
|
+
function parseBudgetNumber(raw) {
|
|
588
|
+
if (/^(off|none|unlimited)$/i.test(raw))
|
|
589
|
+
return 0;
|
|
590
|
+
const n = Number(raw.replace(/[$,]/g, ''));
|
|
591
|
+
return Number.isFinite(n) && n >= 0 ? n : null;
|
|
592
|
+
}
|
|
551
593
|
/**
|
|
552
594
|
* Assemble the `log` section from the environment, or `undefined` when the user
|
|
553
595
|
* said nothing about it. Same shape as the `partial.skills` assembly above: a
|
package/dist/exec/events.d.ts
CHANGED
|
@@ -411,6 +411,36 @@ export interface ExecCompactionEvent {
|
|
|
411
411
|
messages: number;
|
|
412
412
|
charsRemoved: number;
|
|
413
413
|
};
|
|
414
|
+
/**
|
|
415
|
+
* The three v3 sections (context-compaction-v3 §6.2), all optional.
|
|
416
|
+
*
|
|
417
|
+
* `EXEC_SCHEMA_VERSION` DOES NOT MOVE: adding a field never does, and the README
|
|
418
|
+
* already promises that a consumer ignores what it does not know. A wrapper that
|
|
419
|
+
* wants to enforce a spend ceiling needs `budget` here, and one that wants to
|
|
420
|
+
* explain a slow compaction needs `agent`.
|
|
421
|
+
*/
|
|
422
|
+
prune?: {
|
|
423
|
+
actions: number;
|
|
424
|
+
removedChars: number;
|
|
425
|
+
removedTokens: number;
|
|
426
|
+
inspected: number;
|
|
427
|
+
kinds: Record<string, number>;
|
|
428
|
+
};
|
|
429
|
+
budget?: {
|
|
430
|
+
limitTokens: number;
|
|
431
|
+
spentTokens: number;
|
|
432
|
+
limitUsd: number;
|
|
433
|
+
spentUsd: number;
|
|
434
|
+
priceUnknown: boolean;
|
|
435
|
+
stop?: 'budget_tokens' | 'budget_usd';
|
|
436
|
+
};
|
|
437
|
+
agent?: {
|
|
438
|
+
turns: number;
|
|
439
|
+
toolCalls: number;
|
|
440
|
+
submissions: number;
|
|
441
|
+
fallback?: 'single-shot';
|
|
442
|
+
};
|
|
443
|
+
stoppedBy?: 'budget_tokens' | 'budget_usd' | 'turn_limit' | 'timeout' | 'cancel';
|
|
414
444
|
durationMs?: number;
|
|
415
445
|
}
|
|
416
446
|
export interface ExecRetryEvent {
|
package/dist/exec/runner.d.ts
CHANGED
|
@@ -504,6 +504,15 @@ export declare class ExecRunner {
|
|
|
504
504
|
private onCompactionUsage;
|
|
505
505
|
private requestSeq;
|
|
506
506
|
private requestHadError;
|
|
507
|
+
/**
|
|
508
|
+
* The last `agent_end`'s verdict as the ENGINE reported it (D).
|
|
509
|
+
*
|
|
510
|
+
* Separate from `requestHadError` because the two answer different questions:
|
|
511
|
+
* that bit is "this request failed" (it drives `request_end.error` and the exit
|
|
512
|
+
* path), while these fields are what `decideFollowThrough` needs to tell a
|
|
513
|
+
* retryable transport failure from a missing key (`llm-network-error-dead-run` C).
|
|
514
|
+
*/
|
|
515
|
+
private endFacts;
|
|
507
516
|
private isRequestCancelled;
|
|
508
517
|
/** One caller message plus every auto-continuation it produces. */
|
|
509
518
|
private runFollowThroughChain;
|
package/dist/exec/runner.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
import { formatStreamError } from '@aragon-agent/tui/model/agent/reducer';
|
|
18
18
|
import { runDurationMs } from '../team/report.js';
|
|
19
19
|
import { setSignalTerminator } from '../logging/install.js';
|
|
20
|
-
import { advanceBudget, decideFollowThrough, emptyBudget, } from '@aragon-agent/tui/model/todo/follow-through';
|
|
20
|
+
import { advanceBudget, decideFollowThrough, emptyBudget, isTransientRunEnd, } from '@aragon-agent/tui/model/todo/follow-through';
|
|
21
21
|
import { EXEC_SCHEMA_VERSION, buildRequestEndEvent } from './events.js';
|
|
22
22
|
import { ExecProgressReporter } from './progress-reporter.js';
|
|
23
23
|
import { REQUEST_LIMITS } from './request/limits.js';
|
|
@@ -44,6 +44,14 @@ const DEFAULT_SIGNAL_PORT = {
|
|
|
44
44
|
};
|
|
45
45
|
/** A second signal inside this window stops waiting for a graceful settle. */
|
|
46
46
|
const SECOND_SIGNAL_WINDOW_MS = 2000;
|
|
47
|
+
/**
|
|
48
|
+
* Mark time. The only wait an `exec` chain takes, and it exists for one caller:
|
|
49
|
+
* the recovery grace (`errorGraceMs`) that `runFollowThroughChain` honours before
|
|
50
|
+
* re-prompting into a network that has just failed.
|
|
51
|
+
*/
|
|
52
|
+
function pauseMs(ms) {
|
|
53
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
54
|
+
}
|
|
47
55
|
export class ExecRunner {
|
|
48
56
|
emitter;
|
|
49
57
|
sessionId;
|
|
@@ -298,6 +306,12 @@ export class ExecRunner {
|
|
|
298
306
|
tokensBefore: r.tokensBefore,
|
|
299
307
|
tokensAfter: r.tokensAfter,
|
|
300
308
|
...(r.tailRelief ? { tailRelief: r.tailRelief } : {}),
|
|
309
|
+
// THE v3 SECTIONS (context-compaction-v3 §6.2). Passed straight through:
|
|
310
|
+
// this runner is a projection of the record, never a second truth.
|
|
311
|
+
...(r.prune ? { prune: r.prune } : {}),
|
|
312
|
+
...(r.budget ? { budget: r.budget } : {}),
|
|
313
|
+
...(r.agent ? { agent: r.agent } : {}),
|
|
314
|
+
...(r.stoppedBy ? { stoppedBy: r.stoppedBy } : {}),
|
|
301
315
|
...(r.decision ? { decision: r.decision } : {}),
|
|
302
316
|
...(r.memoryVersion ? { memoryVersion: r.memoryVersion } : {}),
|
|
303
317
|
durationMs: r.durationMs,
|
|
@@ -991,6 +1005,15 @@ export class ExecRunner {
|
|
|
991
1005
|
}
|
|
992
1006
|
requestSeq = 0;
|
|
993
1007
|
requestHadError = false;
|
|
1008
|
+
/**
|
|
1009
|
+
* The last `agent_end`'s verdict as the ENGINE reported it (D).
|
|
1010
|
+
*
|
|
1011
|
+
* Separate from `requestHadError` because the two answer different questions:
|
|
1012
|
+
* that bit is "this request failed" (it drives `request_end.error` and the exit
|
|
1013
|
+
* path), while these fields are what `decideFollowThrough` needs to tell a
|
|
1014
|
+
* retryable transport failure from a missing key (`llm-network-error-dead-run` C).
|
|
1015
|
+
*/
|
|
1016
|
+
endFacts = {};
|
|
994
1017
|
isRequestCancelled() {
|
|
995
1018
|
return this.stopReason === 'interrupted' || this.stopReason === 'timeout' ||
|
|
996
1019
|
this.stopReason === 'max_turns';
|
|
@@ -1129,7 +1152,16 @@ export class ExecRunner {
|
|
|
1129
1152
|
// `aborted` is false here for the same structural reason `-p` gives: an
|
|
1130
1153
|
// interrupt sets `stopReason` and returns above, so this branch is only
|
|
1131
1154
|
// reached by a run that ended on its own terms.
|
|
1132
|
-
|
|
1155
|
+
//
|
|
1156
|
+
// `transient` IS THE POINT (C): a retryable transport failure resumes the
|
|
1157
|
+
// plan instead of ending the request with an error the caller has to
|
|
1158
|
+
// re-send by hand. Everything else keeps the old behaviour, exit semantics
|
|
1159
|
+
// included - a non-transient error still ends the chain.
|
|
1160
|
+
runEnd: {
|
|
1161
|
+
aborted: false,
|
|
1162
|
+
errored: this.requestHadError,
|
|
1163
|
+
transient: isTransientRunEnd(this.endFacts),
|
|
1164
|
+
},
|
|
1133
1165
|
budget,
|
|
1134
1166
|
interactive: false,
|
|
1135
1167
|
});
|
|
@@ -1153,6 +1185,14 @@ export class ExecRunner {
|
|
|
1153
1185
|
budget = { ...budget, used: budget.used + 1 };
|
|
1154
1186
|
wasAutoContinuation = true;
|
|
1155
1187
|
this.note(`[todo] ${decision.notice}`);
|
|
1188
|
+
// THE RECOVERY GRACE (C). Zero for an ordinary continuation; `errorGraceMs`
|
|
1189
|
+
// when the plan is being resumed after a retryable failure, because the thing
|
|
1190
|
+
// being waited out is the network and not a human. The request budget is
|
|
1191
|
+
// re-checked at the top of the next iteration (`haltRequestOnBudget`), so a
|
|
1192
|
+
// `--request-max-duration` that expires during this wait stops the request
|
|
1193
|
+
// cleanly instead of making it look broken.
|
|
1194
|
+
if (decision.graceMs > 0)
|
|
1195
|
+
await pauseMs(decision.graceMs);
|
|
1156
1196
|
message = decision.message;
|
|
1157
1197
|
source = 'todo_continue';
|
|
1158
1198
|
}
|
|
@@ -1506,6 +1546,15 @@ export class ExecRunner {
|
|
|
1506
1546
|
break;
|
|
1507
1547
|
case 'agent_end':
|
|
1508
1548
|
// A swallowed throw (missing key / empty stream) produces no `turn_end`.
|
|
1549
|
+
// The ENGINE's verdict is recorded first (D): `requestHadError` is this
|
|
1550
|
+
// runner's sticky "the request failed" bit, while `endFacts` is what says
|
|
1551
|
+
// whether the failure is worth another turn (C).
|
|
1552
|
+
this.endFacts = {
|
|
1553
|
+
...(event.errored !== undefined ? { errored: event.errored } : {}),
|
|
1554
|
+
...(event.errorType !== undefined ? { errorType: event.errorType } : {}),
|
|
1555
|
+
...(event.retryable !== undefined ? { retryable: event.retryable } : {}),
|
|
1556
|
+
...(event.reason !== undefined ? { reason: event.reason } : {}),
|
|
1557
|
+
};
|
|
1509
1558
|
if (!this.sawTurnEnd && !this.requestHadError && !this.isRequestCancelled()) {
|
|
1510
1559
|
this.errored = true;
|
|
1511
1560
|
this.recordError('agent_error', 'The run produced no assistant turn.');
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*
|
|
13
13
|
* NO INK, NO TTY, NO REACT (layering gate L9).
|
|
14
14
|
*/
|
|
15
|
-
import type { AgentEvent } from '@aragon-agent/core';
|
|
15
|
+
import type { AgentEndEvent, AgentEvent } from '@aragon-agent/core';
|
|
16
16
|
import type { AgentController } from '../agent/controller.js';
|
|
17
17
|
import { type PatchSource, type ViewAction } from '@aragon-agent/tui/model/agent/reducer';
|
|
18
18
|
import type { ServiceSnapshot } from '@aragon-agent/tui/model/proc/types';
|
|
@@ -41,8 +41,17 @@ export interface AgentChannelHooks {
|
|
|
41
41
|
beforeEvent?(event: AgentEvent): void;
|
|
42
42
|
/** Every produced action, before it is buffered or dispatched. */
|
|
43
43
|
onAction?(action: ViewAction): void;
|
|
44
|
-
/**
|
|
45
|
-
|
|
44
|
+
/**
|
|
45
|
+
* After an `agent_end`'s actions were dispatched (follow-through, pending posture).
|
|
46
|
+
*
|
|
47
|
+
* THE EVENT IS HANDED OVER (`llm-network-error-dead-run` D). It used to be a
|
|
48
|
+
* no-argument hook, which meant the failure facts the engine had just started
|
|
49
|
+
* reporting could not reach the one place that decides whether to continue:
|
|
50
|
+
* `errored`/`errorType`/`retryable`/`reason` are exactly what that decision
|
|
51
|
+
* needs, and re-deriving them from a notice level is the inference this
|
|
52
|
+
* feature deletes. A host that needs none of it still writes `() => {}`.
|
|
53
|
+
*/
|
|
54
|
+
afterAgentEnd?(event: AgentEndEvent): void;
|
|
46
55
|
}
|
|
47
56
|
/**
|
|
48
57
|
* The main run stream: generation guard, reduce, coalesce.
|
package/dist/host/interaction.js
CHANGED
|
@@ -175,6 +175,9 @@ export class InteractionCoordinator {
|
|
|
175
175
|
// may also carry a host-built path block the user never typed.
|
|
176
176
|
const shown = card?.commandLine ?? attachments?.displayText ?? message;
|
|
177
177
|
const metas = attachments?.metas.length ? { attachments: attachments.metas } : {};
|
|
178
|
+
// The pills, beside the attachment strip. Pure passthrough: `message` - the model's input - is never
|
|
179
|
+
// touched by this (ide-selection-context 4.6), and `shown` stays the user's own words.
|
|
180
|
+
const chips = opts.contexts?.length ? { contexts: opts.contexts } : {};
|
|
178
181
|
if (this.phaseValue === 'running' || controller.isCompactionBusy?.()) {
|
|
179
182
|
try {
|
|
180
183
|
// Called with exactly the pre-feature arguments unless parts exist.
|
|
@@ -182,7 +185,7 @@ export class InteractionCoordinator {
|
|
|
182
185
|
? controller.queueUserMessage(message, attachments.parts)
|
|
183
186
|
: controller.queueUserMessage(message);
|
|
184
187
|
dispatch({
|
|
185
|
-
type: 'steerQueued', queueId, text: shown, ...(card ? { invocation: card } : {}), ...metas,
|
|
188
|
+
type: 'steerQueued', queueId, text: shown, ...(card ? { invocation: card } : {}), ...metas, ...chips,
|
|
186
189
|
});
|
|
187
190
|
// The receipt id is only surfaced for attachment-bearing messages (the host needs it to
|
|
188
191
|
// retain their bytes for withdrawal); plain messages keep the exact legacy outcome.
|
|
@@ -204,7 +207,7 @@ export class InteractionCoordinator {
|
|
|
204
207
|
appendPrompt(attachments?.displayText ?? message);
|
|
205
208
|
controller.setSubmitCount(bumpSubmitCount());
|
|
206
209
|
}
|
|
207
|
-
dispatch({ type: 'submit', text: shown, ...(card ? { invocation: card } : {}), ...metas });
|
|
210
|
+
dispatch({ type: 'submit', text: shown, ...(card ? { invocation: card } : {}), ...metas, ...chips });
|
|
208
211
|
const pre = controller.preflight();
|
|
209
212
|
if (!pre.ok) {
|
|
210
213
|
dispatch({ type: 'runError' });
|
|
@@ -147,9 +147,19 @@ export type AgentLogEvent = {
|
|
|
147
147
|
} | {
|
|
148
148
|
type: 'steering_accepted';
|
|
149
149
|
ids: readonly string[];
|
|
150
|
-
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* The failure facts are OPTIONAL structural mirrors of core's
|
|
153
|
+
* `AgentEndEvent` (`llm-network-error-dead-run` D). Absent on a clean run,
|
|
154
|
+
* which is why `run_end` stays `{ messages }` for a run that answered.
|
|
155
|
+
*/
|
|
156
|
+
| {
|
|
151
157
|
type: 'agent_end';
|
|
152
158
|
messages: unknown[];
|
|
159
|
+
errored?: boolean;
|
|
160
|
+
errorType?: string;
|
|
161
|
+
retryable?: boolean;
|
|
162
|
+
reason?: string;
|
|
153
163
|
} | {
|
|
154
164
|
type: 'turn_start';
|
|
155
165
|
} | {
|
|
@@ -238,6 +248,33 @@ export type AgentLogEvent = {
|
|
|
238
248
|
messages: number;
|
|
239
249
|
charsRemoved: number;
|
|
240
250
|
};
|
|
251
|
+
/**
|
|
252
|
+
* The v3 fields, mirrored from the CLI-local record (context-compaction-v3
|
|
253
|
+
* §4.7). THIS UNION MUST STAY A SUPERSET OF CORE'S (IF-3): a field present
|
|
254
|
+
* on the CLI record and missing here is invisible in the log, and the log is
|
|
255
|
+
* the only durable trace of a run nobody watched.
|
|
256
|
+
*/
|
|
257
|
+
prune?: {
|
|
258
|
+
actions: number;
|
|
259
|
+
removedChars: number;
|
|
260
|
+
removedTokens: number;
|
|
261
|
+
inspected: number;
|
|
262
|
+
kinds: Record<string, number>;
|
|
263
|
+
};
|
|
264
|
+
budget?: {
|
|
265
|
+
limitTokens: number;
|
|
266
|
+
spentTokens: number;
|
|
267
|
+
limitUsd: number;
|
|
268
|
+
spentUsd: number;
|
|
269
|
+
priceUnknown: boolean;
|
|
270
|
+
stop?: 'budget_tokens' | 'budget_usd';
|
|
271
|
+
};
|
|
272
|
+
agent?: {
|
|
273
|
+
turns: number;
|
|
274
|
+
toolCalls: number;
|
|
275
|
+
submissions: number;
|
|
276
|
+
fallback?: 'single-shot';
|
|
277
|
+
};
|
|
241
278
|
durationMs?: number;
|
|
242
279
|
};
|
|
243
280
|
/**
|
package/dist/logging/install.js
CHANGED
|
@@ -436,7 +436,18 @@ export function attachAgentEvents(logger, controller) {
|
|
|
436
436
|
});
|
|
437
437
|
break;
|
|
438
438
|
case 'agent_end':
|
|
439
|
-
|
|
439
|
+
// THE FIRST LOG ROW THAT SAYS WHY (D). Every `run_end` used to be
|
|
440
|
+
// `{ messages }`, so a census of ten days of logs could not tell a run
|
|
441
|
+
// that answered from one that died of a retry ladder - the investigation
|
|
442
|
+
// had to infer a death from the gap to the previous event. These keys are
|
|
443
|
+
// ABSENT on the happy path, so a clean run's row is byte-identical.
|
|
444
|
+
logger.info('agent', 'run_end', {
|
|
445
|
+
messages: event.messages?.length ?? 0,
|
|
446
|
+
...(event.errored !== undefined ? { errored: event.errored } : {}),
|
|
447
|
+
...(event.errorType !== undefined ? { errorType: event.errorType } : {}),
|
|
448
|
+
...(event.retryable !== undefined ? { retryable: event.retryable } : {}),
|
|
449
|
+
...(event.reason !== undefined ? { reason: event.reason } : {}),
|
|
450
|
+
});
|
|
440
451
|
break;
|
|
441
452
|
}
|
|
442
453
|
});
|
package/dist/session/persist.js
CHANGED
|
@@ -11,6 +11,7 @@ import { getSessionsDir } from '../config/store.js';
|
|
|
11
11
|
import { stripEphemeralRuns } from '../team/settled.js';
|
|
12
12
|
import { sanitizeInvocationCard } from '@aragon-agent/tui/model/agent/invocation-card';
|
|
13
13
|
import { sanitizeAttachmentMetas } from '@aragon-agent/tui/model/agent/attachment-meta';
|
|
14
|
+
import { sanitizeContextMetas } from '@aragon-agent/tui/model/agent/context-meta';
|
|
14
15
|
import { validateSession } from './validate-session.js';
|
|
15
16
|
import { validateCompactionIdentity, verifyCompactionIdentity, } from '../compaction/memory-identity.js';
|
|
16
17
|
import { getLogger } from '../logging/logger.js';
|
|
@@ -174,7 +175,7 @@ export function saveSession(filePath, data) {
|
|
|
174
175
|
* never legitimately sees a stale-active entry — only the file does.
|
|
175
176
|
*/
|
|
176
177
|
export function normalizeLoadedEntries(entries) {
|
|
177
|
-
return entries.map(dropInvalidAttachments).map((entry) => {
|
|
178
|
+
return entries.map(dropInvalidAttachments).map(dropInvalidContexts).map((entry) => {
|
|
178
179
|
// A runtime-only wait view that reached disk anyway (an older or hand-edited
|
|
179
180
|
// file) describes a wait that died with the session: drop it (I-9).
|
|
180
181
|
if (entry.kind === 'tool' && (entry.wait !== undefined || entry.waitSeq !== undefined)) {
|
|
@@ -284,10 +285,25 @@ export function normalizeLoadedEntries(entries) {
|
|
|
284
285
|
});
|
|
285
286
|
}
|
|
286
287
|
/**
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
|
|
288
|
+
* The same repair for code-context pills (ide-selection-context RV-P1-6): `validate-session` declares the
|
|
289
|
+
* field but does not check it, so one bad path or a reversed range is dropped here - with a warning, and
|
|
290
|
+
* without costing the entry or the session.
|
|
291
|
+
*/
|
|
292
|
+
function dropInvalidContexts(entry) {
|
|
293
|
+
if ((entry.kind !== 'user' && entry.kind !== 'queued') || !('contexts' in entry))
|
|
294
|
+
return entry;
|
|
295
|
+
const { contexts: stored, ...plain } = entry;
|
|
296
|
+
const { metas, dropped } = sanitizeContextMetas(stored);
|
|
297
|
+
if (dropped > 0) {
|
|
298
|
+
getLogger().warn('agent', 'dropped_invalid_context_records', { entryId: entry.id, dropped });
|
|
299
|
+
}
|
|
300
|
+
return metas ? { ...plain, contexts: metas } : plain;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* desktop-attachments-and-tool-voice RV-11: `attachments` is declared but not validated by
|
|
304
|
+
* `validate-session` (one bad thumbnail must not fail the whole file), so the repair happens
|
|
305
|
+
* here, item by item. A corrupt item is dropped with a warning; the entry and the session
|
|
306
|
+
* survive.
|
|
291
307
|
*/
|
|
292
308
|
function dropInvalidAttachments(entry) {
|
|
293
309
|
if ((entry.kind !== 'user' && entry.kind !== 'queued') || !('attachments' in entry))
|
|
@@ -149,14 +149,19 @@ const subagent = shape({
|
|
|
149
149
|
const ENTRY_FIELDS = {
|
|
150
150
|
// `invocation` is declared for self-description only: `shape()` ignores undeclared
|
|
151
151
|
// fields, and `normalizeLoadedEntries` repairs or drops a bad card (tui-invocation-cards).
|
|
152
|
-
user: { text: string, invocation: optional(() => { }), attachments: optional(() => { })
|
|
152
|
+
user: { text: string, invocation: optional(() => { }), attachments: optional(() => { }),
|
|
153
|
+
// Declared for self-description only, like `attachments` above: `shape()` ignores undeclared fields
|
|
154
|
+
// and `normalizeLoadedEntries` drops a bad pill (ide-selection-context RV-P1-6). Without this row the
|
|
155
|
+
// field would be silently discarded on load, and every reopened session would lose its pills.
|
|
156
|
+
contexts: optional(() => { }) },
|
|
153
157
|
// A GOVERNANCE CARD IS HISTORY, so it is validated LENIENTLY (governance-mode 10.4):
|
|
154
158
|
// unknown fields are ignored (`shape` only reads the declared ones) and `card` is not
|
|
155
159
|
// shape-checked here at all - `sanitizeGovernanceEntries` below repairs a card it can
|
|
156
160
|
// and degrades one it cannot to a one-line notice, so a corrupt footnote never costs
|
|
157
161
|
// the session. `at` is advisory.
|
|
158
162
|
governance: { at: optional(number), card: () => { } },
|
|
159
|
-
queued: { text: string, queueId: optional(nonempty), invocation: optional(() => { }), attachments: optional(() => { })
|
|
163
|
+
queued: { text: string, queueId: optional(nonempty), invocation: optional(() => { }), attachments: optional(() => { }),
|
|
164
|
+
contexts: optional(() => { }) },
|
|
160
165
|
notice: { text: string, level: enumeration('info', 'warn', 'error') },
|
|
161
166
|
assistant: {
|
|
162
167
|
text: string, thinking: optional(string), thinkingOpen: boolean, streaming: boolean,
|
|
@@ -215,6 +220,17 @@ const ENTRY_FIELDS = {
|
|
|
215
220
|
tokensBefore: number, tokensAfter: number, summary: optional(string), model: string,
|
|
216
221
|
durationMs: optional(number), startedAt: optional(number), live: boolean,
|
|
217
222
|
tailRelief: optional(shape({ messages: number, charsRemoved: number })),
|
|
223
|
+
// THE v3 OPTIONAL FIELDS (context-compaction-v3 §4.7). THIS VALIDATOR IS
|
|
224
|
+
// STRICT - an unknown field fails the whole load - so every field a record can
|
|
225
|
+
// carry has to be named here or a saved session would refuse to resume.
|
|
226
|
+
prune: optional(shape({ actions: nonnegative, removedChars: nonnegative,
|
|
227
|
+
removedTokens: nonnegative, inspected: nonnegative, kinds: object })),
|
|
228
|
+
budget: optional(shape({ limitTokens: nonnegative, spentTokens: nonnegative,
|
|
229
|
+
limitUsd: nonnegative, spentUsd: nonnegative, priceUnknown: boolean,
|
|
230
|
+
stop: optional(enumeration('budget_tokens', 'budget_usd')) })),
|
|
231
|
+
agent: optional(shape({ turns: nonnegative, toolCalls: nonnegative,
|
|
232
|
+
submissions: nonnegative, fallback: optional(enumeration('single-shot')) })),
|
|
233
|
+
stoppedBy: optional(enumeration('budget_tokens', 'budget_usd', 'turn_limit', 'timeout', 'cancel')),
|
|
218
234
|
},
|
|
219
235
|
service: {
|
|
220
236
|
serviceId: string, command: string,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aragon-agent/cli",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.63",
|
|
4
4
|
"description": "AragonAgent CLI — a Claude-Code / Codex-style interactive terminal UI (TUI) on top of the @aragon-agent/core engine. Installable and runnable via npm / npx.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "AragonAgent contributors",
|
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
"prepublishOnly": "npm run build"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@aragon-agent/core": "^0.2.
|
|
62
|
-
"@aragon-agent/tui": "0.0.
|
|
61
|
+
"@aragon-agent/core": "^0.2.75",
|
|
62
|
+
"@aragon-agent/tui": "0.0.16",
|
|
63
63
|
"commander": "^12.1.0",
|
|
64
64
|
"dotenv": "^16.6.1",
|
|
65
65
|
"env-paths": "^3.0.0",
|