@aragon-agent/cli 0.6.61 → 0.6.62
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/dist/agent/headless.js +49 -6
- package/dist/agent/prompt-options.d.ts +7 -0
- package/dist/app/App.js +37 -5
- package/dist/exec/runner.d.ts +9 -0
- package/dist/exec/runner.js +45 -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 +11 -1
- package/dist/logging/install.js +12 -1
- package/dist/session/persist.js +21 -5
- package/dist/session/validate-session.js +7 -2
- package/package.json +3 -3
package/dist/agent/headless.js
CHANGED
|
@@ -8,7 +8,14 @@ import { formatCost, formatTokens, formatDuration, computeCost } from '@aragon-a
|
|
|
8
8
|
import { formatStreamError } from '@aragon-agent/tui/model/agent/reducer';
|
|
9
9
|
import { runDurationMs } from '../team/report.js';
|
|
10
10
|
import { derivePlanPhase } from '@aragon-agent/tui/model/todo/acceptance';
|
|
11
|
-
import { advanceBudget, decideFollowThrough, emptyBudget, } from '@aragon-agent/tui/model/todo/follow-through';
|
|
11
|
+
import { advanceBudget, decideFollowThrough, emptyBudget, isTransientRunEnd, } from '@aragon-agent/tui/model/todo/follow-through';
|
|
12
|
+
/**
|
|
13
|
+
* Mark time. The only wait `-p` ever takes, and it exists for one caller: the
|
|
14
|
+
* recovery grace in the follow-through loop below (`errorGraceMs`).
|
|
15
|
+
*/
|
|
16
|
+
function pauseMs(ms) {
|
|
17
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
18
|
+
}
|
|
12
19
|
/** Run a single prompt headlessly and resolve with the process exit code. */
|
|
13
20
|
export async function runHeadless(controller, prompt, options = {}) {
|
|
14
21
|
const out = options.stdout ?? process.stdout;
|
|
@@ -20,6 +27,15 @@ export async function runHeadless(controller, prompt, options = {}) {
|
|
|
20
27
|
return 2;
|
|
21
28
|
}
|
|
22
29
|
let errored = false;
|
|
30
|
+
/**
|
|
31
|
+
* The last `agent_end`'s failure verdict, as the ENGINE reported it (D).
|
|
32
|
+
*
|
|
33
|
+
* Kept apart from `errored` on purpose: `errored` is `-p`'s own sticky
|
|
34
|
+
* "something went wrong, exit 1" bit, while these are the provider's own
|
|
35
|
+
* classification and are what tell a retryable transport failure apart from a
|
|
36
|
+
* missing key (`llm-network-error-dead-run` C).
|
|
37
|
+
*/
|
|
38
|
+
let endFacts = {};
|
|
23
39
|
let sawTurnEnd = false;
|
|
24
40
|
let wroteText = false;
|
|
25
41
|
const total = { inputTokens: 0, outputTokens: 0 };
|
|
@@ -69,6 +85,13 @@ export async function runHeadless(controller, prompt, options = {}) {
|
|
|
69
85
|
break;
|
|
70
86
|
case 'turn_end':
|
|
71
87
|
sawTurnEnd = true;
|
|
88
|
+
// A COMPLETED TURN CLEARS `-p`'s FAILURE BIT (C). After a transient
|
|
89
|
+
// failure the loop below may have re-prompted and succeeded, and exiting 1
|
|
90
|
+
// on a process that produced its answer would tell every piped caller the
|
|
91
|
+
// opposite of what happened. A later iteration that fails again sets this
|
|
92
|
+
// back - a failed run still produces no `turn_end`.
|
|
93
|
+
errored = false;
|
|
94
|
+
endFacts = {};
|
|
72
95
|
if (retryCount > 0) {
|
|
73
96
|
err.write(`[retry] recovered after ${retryCount} ${retryCount === 1 ? 'retry' : 'retries'}\n`);
|
|
74
97
|
retryCount = 0;
|
|
@@ -78,6 +101,12 @@ export async function runHeadless(controller, prompt, options = {}) {
|
|
|
78
101
|
break;
|
|
79
102
|
case 'agent_end':
|
|
80
103
|
// A swallowed throw (missing key / empty stream) produces no turn_end.
|
|
104
|
+
endFacts = {
|
|
105
|
+
...(event.errored !== undefined ? { errored: event.errored } : {}),
|
|
106
|
+
...(event.errorType !== undefined ? { errorType: event.errorType } : {}),
|
|
107
|
+
...(event.retryable !== undefined ? { retryable: event.retryable } : {}),
|
|
108
|
+
...(event.reason !== undefined ? { reason: event.reason } : {}),
|
|
109
|
+
};
|
|
81
110
|
if (!sawTurnEnd && !errored)
|
|
82
111
|
errored = true;
|
|
83
112
|
break;
|
|
@@ -274,9 +303,13 @@ export async function runHeadless(controller, prompt, options = {}) {
|
|
|
274
303
|
for (;;) {
|
|
275
304
|
// PER-ITERATION RESET (rule 1). `sawTurnEnd` is the silent-failure
|
|
276
305
|
// detector; left sticky, a swallowed throw on iteration 2 is invisible
|
|
277
|
-
// because iteration 1 set the flag. `
|
|
278
|
-
//
|
|
306
|
+
// because iteration 1 set the flag. `endFacts` is reset for the same
|
|
307
|
+
// reason one field over: a transient verdict belongs to the turn that
|
|
308
|
+
// produced it, and inheriting it would let iteration 2 read iteration
|
|
309
|
+
// 1's failure. `errored` is NOT reset here; it is cleared by a completed
|
|
310
|
+
// `turn_end`, the only event that proves a recovery happened.
|
|
279
311
|
sawTurnEnd = false;
|
|
312
|
+
endFacts = {};
|
|
280
313
|
await controller.prompt(message);
|
|
281
314
|
const snapshot = controller.getTodoSnapshot?.() ?? null;
|
|
282
315
|
budget = advanceBudget(budget, snapshot, wasAutoContinuation);
|
|
@@ -286,9 +319,11 @@ export async function runHeadless(controller, prompt, options = {}) {
|
|
|
286
319
|
snapshot,
|
|
287
320
|
// `aborted` is STRUCTURALLY false here (C-2): `-p` has no Esc and
|
|
288
321
|
// installs no signal handler that marks one, so there is nothing to
|
|
289
|
-
// derive and nothing to plumb.
|
|
290
|
-
//
|
|
291
|
-
|
|
322
|
+
// derive and nothing to plumb. `transient` comes from the ENGINE's own
|
|
323
|
+
// verdict on `agent_end` (C): a retryable transport failure resumes,
|
|
324
|
+
// everything else still takes the `notify` branch below and keeps exit
|
|
325
|
+
// code 1 reachable.
|
|
326
|
+
runEnd: { aborted: false, errored, transient: isTransientRunEnd(endFacts) },
|
|
292
327
|
budget,
|
|
293
328
|
interactive: false,
|
|
294
329
|
});
|
|
@@ -307,6 +342,14 @@ export async function runHeadless(controller, prompt, options = {}) {
|
|
|
307
342
|
wasAutoContinuation = true;
|
|
308
343
|
if (!quiet)
|
|
309
344
|
err.write(`\n[todo] ${decision.notice}\n`);
|
|
345
|
+
// THE ONE GRACE WINDOW `-p` HONOURS (C). An ordinary continuation is
|
|
346
|
+
// immediate here - there is no human to interrupt, so the 3 s courtesy wait
|
|
347
|
+
// buys nothing - but a RECOVERY arrives with `errorGraceMs` because what it
|
|
348
|
+
// waits out is the network that just killed the ladder. Re-prompting at 0 ms
|
|
349
|
+
// would spend a whole second ladder (up to `retry.maxElapsedMs`) against the
|
|
350
|
+
// same broken endpoint, and two of those hand the plan back for nothing.
|
|
351
|
+
if (decision.graceMs > 0)
|
|
352
|
+
await pauseMs(decision.graceMs);
|
|
310
353
|
message = decision.message;
|
|
311
354
|
}
|
|
312
355
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ContentPart } from '@aragon-agent/core';
|
|
2
2
|
import type { InvocationCardInput } from '@aragon-agent/tui/model/agent/invocation-card';
|
|
3
3
|
import type { AttachmentMeta } from '@aragon-agent/tui/model/agent/attachment-meta';
|
|
4
|
+
import type { ContextChipMeta } from '@aragon-agent/tui/model/agent/context-meta';
|
|
4
5
|
/** Explicit TUI task boundary; omission retains legacy programmatic behavior. */
|
|
5
6
|
export interface PromptOptions {
|
|
6
7
|
todoPolicy?: 'new-task' | 'continue';
|
|
@@ -29,6 +30,12 @@ export interface SubmitMessageOptions extends PromptOptions {
|
|
|
29
30
|
metas: AttachmentMeta[];
|
|
30
31
|
displayText?: string;
|
|
31
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Code-context snapshots the user attached (ide-selection-context). METADATA ONLY - path and range -
|
|
35
|
+
* so the transcript can draw a pill and a reopened session can still say what was attached. The text
|
|
36
|
+
* the model reads is already part of `message`, and is never carried here.
|
|
37
|
+
*/
|
|
38
|
+
contexts?: ContextChipMeta[];
|
|
32
39
|
}
|
|
33
40
|
/** Startup outcome only; engine events still describe the result of the run. */
|
|
34
41
|
export type PromptOutcome = {
|
package/dist/app/App.js
CHANGED
|
@@ -58,7 +58,7 @@ import { ScrollViewport } from '@aragon-agent/tui/ui/layout/ScrollViewport';
|
|
|
58
58
|
import { acceptanceChip, acceptanceRung, buildTodoRailLayout } from '@aragon-agent/tui/ui/layout/todo-layout';
|
|
59
59
|
import { buildTeamPanelLayout } from '@aragon-agent/tui/ui/layout/team-panel';
|
|
60
60
|
import { isLiveTeamCard, lastTeamEntry, rosterCounts } from '@aragon-agent/tui/ui/team-status';
|
|
61
|
-
import { advanceBudget, decideFollowThrough, emptyBudget, } from '@aragon-agent/tui/model/todo/follow-through';
|
|
61
|
+
import { advanceBudget, decideFollowThrough, emptyBudget, isTransientRunEnd, } from '@aragon-agent/tui/model/todo/follow-through';
|
|
62
62
|
// THE THIRD LAYER OF FORCED TEAM MODE (team-command-forced-dispatch §3.7): the
|
|
63
63
|
// decision and its two strings live in a pure module, so `App` gains wiring and
|
|
64
64
|
// no policy. Imported beside the todo decision it shares one timer with.
|
|
@@ -595,10 +595,18 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
|
|
|
595
595
|
*
|
|
596
596
|
* So this ref is mutated in the SAME SYNCHRONOUS CALLBACK that dispatches the
|
|
597
597
|
* corresponding action, and the reducer fields stay as the cross-check.
|
|
598
|
+
*
|
|
599
|
+
* `transient` IS A THIRD FACT, NOT A REFINEMENT OF `errored`
|
|
600
|
+
* (`llm-network-error-dead-run` C). `errored` answers "did something go wrong",
|
|
601
|
+
* which both a revoked key and an `ECONNRESET` burst answer yes to; `transient`
|
|
602
|
+
* answers "is another turn worth spending", and it is derived from the engine's
|
|
603
|
+
* own verdict (`errorType` + `retryable` on `agent_end`) rather than from how
|
|
604
|
+
* the failure was displayed.
|
|
598
605
|
*/
|
|
599
606
|
const endReasonRef = useRef({
|
|
600
607
|
aborted: false,
|
|
601
608
|
errored: false,
|
|
609
|
+
transient: false,
|
|
602
610
|
});
|
|
603
611
|
const interruptTimer = useRef(null);
|
|
604
612
|
const resetInterrupt = useCallback(() => {
|
|
@@ -905,7 +913,23 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
|
|
|
905
913
|
dispatchAttemptedRef.current = true;
|
|
906
914
|
}
|
|
907
915
|
},
|
|
908
|
-
afterAgentEnd() {
|
|
916
|
+
afterAgentEnd(end) {
|
|
917
|
+
// THE ENGINE'S OWN VERDICT, FIRST AND UNCONDITIONALLY (D). Everything
|
|
918
|
+
// below this line decides whether to continue, and until now `errored`
|
|
919
|
+
// was inferred from "a notice with level error was dispatched" - which
|
|
920
|
+
// misses the watchdog path (a bare console line, no `onAction`) and
|
|
921
|
+
// cannot tell a revoked key from a transport wobble.
|
|
922
|
+
//
|
|
923
|
+
// A USER ABORT OUTRANKS IT: `aborted` is set by Esc, and a run the user
|
|
924
|
+
// interrupted must stay quiet whatever the engine recorded while
|
|
925
|
+
// unwinding (`follow-through` returns `none` on `aborted` anyway; this
|
|
926
|
+
// keeps the forced-dispatch gate from reading a failed turn too).
|
|
927
|
+
if (!endReasonRef.current.aborted) {
|
|
928
|
+
if (end.errored === true)
|
|
929
|
+
endReasonRef.current.errored = true;
|
|
930
|
+
if (isTransientRunEnd(end))
|
|
931
|
+
endReasonRef.current.transient = true;
|
|
932
|
+
}
|
|
909
933
|
// NO OVERLAY OUTLIVES ITS RUN (P1-4). `ctx.signal` already covers the
|
|
910
934
|
// abort path, so this is DELIBERATE REDUNDANCY: it makes "the card cannot
|
|
911
935
|
// survive the run that opened it" a property of the App's lifecycle
|
|
@@ -963,11 +987,14 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
|
|
|
963
987
|
: decideFollowThrough({
|
|
964
988
|
mode: controller.getTodoConfig().followThrough,
|
|
965
989
|
snapshot: todos,
|
|
990
|
+
// `transient` RIDES THROUGH (C): without it the table cannot tell
|
|
991
|
+
// "the network dropped for 40 s" from "the key is wrong", and the
|
|
992
|
+
// whole point of the fix is that only the first one resumes.
|
|
966
993
|
runEnd: { ...endReasonRef.current },
|
|
967
994
|
budget: budgetRef.current,
|
|
968
995
|
interactive: true,
|
|
969
996
|
});
|
|
970
|
-
endReasonRef.current = { aborted: false, errored: false };
|
|
997
|
+
endReasonRef.current = { aborted: false, errored: false, transient: false };
|
|
971
998
|
if (decision.kind === 'notify') {
|
|
972
999
|
dispatch({ type: 'notice', level: decision.level, text: decision.text });
|
|
973
1000
|
}
|
|
@@ -1279,7 +1306,12 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
|
|
|
1279
1306
|
// Ink's own patchConsole writes straight to stdout, which shifts the fixed
|
|
1280
1307
|
// frame by a row and breaks its line accounting for good.
|
|
1281
1308
|
useEffect(() => {
|
|
1282
|
-
|
|
1309
|
+
// `internal: true` IS LOAD-BEARING (llm-network-error-dead-run F): these lines
|
|
1310
|
+
// are the ENGINE talking, not a verdict the reducer derived from a provider
|
|
1311
|
+
// error, and that difference decides whether a live retry card may be settled
|
|
1312
|
+
// as "exhausted". The watchdog line used to arrive here and assert an
|
|
1313
|
+
// exhaustion that never happened, on a card the run had merely interrupted.
|
|
1314
|
+
return installConsoleBridge((level, text) => dispatch({ type: 'notice', level, text, internal: true }));
|
|
1283
1315
|
}, []);
|
|
1284
1316
|
// `enabled` is `mouseSource`, not `cfg.mouse`: a user whose terminal drops
|
|
1285
1317
|
// the events must never be shown advice about a mode not in effect (§6.1).
|
|
@@ -2323,7 +2355,7 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
|
|
|
2323
2355
|
}
|
|
2324
2356
|
// Mirrors where the reducer clears its own copies, in the same action
|
|
2325
2357
|
// (C-11): a new turn's end reason must not inherit the previous one's.
|
|
2326
|
-
endReasonRef.current = { aborted: false, errored: false };
|
|
2358
|
+
endReasonRef.current = { aborted: false, errored: false, transient: false };
|
|
2327
2359
|
dispatch({ type: 'submit', text: shown, ...(card ? { invocation: card } : {}) });
|
|
2328
2360
|
const pre = controller.preflight();
|
|
2329
2361
|
if (!pre.ok) {
|
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;
|
|
@@ -991,6 +999,15 @@ export class ExecRunner {
|
|
|
991
999
|
}
|
|
992
1000
|
requestSeq = 0;
|
|
993
1001
|
requestHadError = false;
|
|
1002
|
+
/**
|
|
1003
|
+
* The last `agent_end`'s verdict as the ENGINE reported it (D).
|
|
1004
|
+
*
|
|
1005
|
+
* Separate from `requestHadError` because the two answer different questions:
|
|
1006
|
+
* that bit is "this request failed" (it drives `request_end.error` and the exit
|
|
1007
|
+
* path), while these fields are what `decideFollowThrough` needs to tell a
|
|
1008
|
+
* retryable transport failure from a missing key (`llm-network-error-dead-run` C).
|
|
1009
|
+
*/
|
|
1010
|
+
endFacts = {};
|
|
994
1011
|
isRequestCancelled() {
|
|
995
1012
|
return this.stopReason === 'interrupted' || this.stopReason === 'timeout' ||
|
|
996
1013
|
this.stopReason === 'max_turns';
|
|
@@ -1129,7 +1146,16 @@ export class ExecRunner {
|
|
|
1129
1146
|
// `aborted` is false here for the same structural reason `-p` gives: an
|
|
1130
1147
|
// interrupt sets `stopReason` and returns above, so this branch is only
|
|
1131
1148
|
// reached by a run that ended on its own terms.
|
|
1132
|
-
|
|
1149
|
+
//
|
|
1150
|
+
// `transient` IS THE POINT (C): a retryable transport failure resumes the
|
|
1151
|
+
// plan instead of ending the request with an error the caller has to
|
|
1152
|
+
// re-send by hand. Everything else keeps the old behaviour, exit semantics
|
|
1153
|
+
// included - a non-transient error still ends the chain.
|
|
1154
|
+
runEnd: {
|
|
1155
|
+
aborted: false,
|
|
1156
|
+
errored: this.requestHadError,
|
|
1157
|
+
transient: isTransientRunEnd(this.endFacts),
|
|
1158
|
+
},
|
|
1133
1159
|
budget,
|
|
1134
1160
|
interactive: false,
|
|
1135
1161
|
});
|
|
@@ -1153,6 +1179,14 @@ export class ExecRunner {
|
|
|
1153
1179
|
budget = { ...budget, used: budget.used + 1 };
|
|
1154
1180
|
wasAutoContinuation = true;
|
|
1155
1181
|
this.note(`[todo] ${decision.notice}`);
|
|
1182
|
+
// THE RECOVERY GRACE (C). Zero for an ordinary continuation; `errorGraceMs`
|
|
1183
|
+
// when the plan is being resumed after a retryable failure, because the thing
|
|
1184
|
+
// being waited out is the network and not a human. The request budget is
|
|
1185
|
+
// re-checked at the top of the next iteration (`haltRequestOnBudget`), so a
|
|
1186
|
+
// `--request-max-duration` that expires during this wait stops the request
|
|
1187
|
+
// cleanly instead of making it look broken.
|
|
1188
|
+
if (decision.graceMs > 0)
|
|
1189
|
+
await pauseMs(decision.graceMs);
|
|
1156
1190
|
message = decision.message;
|
|
1157
1191
|
source = 'todo_continue';
|
|
1158
1192
|
}
|
|
@@ -1506,6 +1540,15 @@ export class ExecRunner {
|
|
|
1506
1540
|
break;
|
|
1507
1541
|
case 'agent_end':
|
|
1508
1542
|
// A swallowed throw (missing key / empty stream) produces no `turn_end`.
|
|
1543
|
+
// The ENGINE's verdict is recorded first (D): `requestHadError` is this
|
|
1544
|
+
// runner's sticky "the request failed" bit, while `endFacts` is what says
|
|
1545
|
+
// whether the failure is worth another turn (C).
|
|
1546
|
+
this.endFacts = {
|
|
1547
|
+
...(event.errored !== undefined ? { errored: event.errored } : {}),
|
|
1548
|
+
...(event.errorType !== undefined ? { errorType: event.errorType } : {}),
|
|
1549
|
+
...(event.retryable !== undefined ? { retryable: event.retryable } : {}),
|
|
1550
|
+
...(event.reason !== undefined ? { reason: event.reason } : {}),
|
|
1551
|
+
};
|
|
1509
1552
|
if (!this.sawTurnEnd && !this.requestHadError && !this.isRequestCancelled()) {
|
|
1510
1553
|
this.errored = true;
|
|
1511
1554
|
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
|
} | {
|
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,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aragon-agent/cli",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.62",
|
|
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.74",
|
|
62
|
+
"@aragon-agent/tui": "0.0.15",
|
|
63
63
|
"commander": "^12.1.0",
|
|
64
64
|
"dotenv": "^16.6.1",
|
|
65
65
|
"env-paths": "^3.0.0",
|