@aragon-agent/cli 0.6.63 → 0.6.66
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/CHANGELOG.md +131 -2
- package/README.md +98 -21
- package/dist/agent/controller.d.ts +119 -14
- package/dist/agent/controller.js +385 -82
- package/dist/agent/headless.d.ts +16 -0
- package/dist/agent/headless.js +68 -6
- package/dist/agent/reconnect-memory.d.ts +68 -0
- package/dist/agent/reconnect-memory.js +82 -0
- package/dist/agent/team-notices.d.ts +57 -7
- package/dist/agent/team-notices.js +93 -10
- package/dist/app/App.js +284 -78
- package/dist/cli.js +4 -1
- package/dist/commands/builtins.js +8 -72
- package/dist/commands/catalog.js +1 -1
- package/dist/commands/retry-command.d.ts +52 -0
- package/dist/commands/retry-command.js +225 -0
- package/dist/config/cli-commands.d.ts +1 -1
- package/dist/config/cli-commands.js +39 -0
- package/dist/exec/events.d.ts +12 -0
- package/dist/exec/index.js +2 -0
- package/dist/exec/runner.js +16 -1
- package/dist/gene/cli-commands.js +30 -1
- package/dist/gene/command-report.js +5 -1
- package/dist/gene/commit-prepare.js +27 -1
- package/dist/gene/curator/budget.d.ts +24 -1
- package/dist/gene/curator/budget.js +67 -14
- package/dist/gene/curator/curator.d.ts +25 -0
- package/dist/gene/curator/curator.js +61 -7
- package/dist/gene/curator/scripted-lane.d.ts +12 -0
- package/dist/gene/curator/scripted-lane.js +101 -0
- package/dist/gene/curator/task-context.d.ts +29 -0
- package/dist/gene/curator/task-context.js +43 -0
- package/dist/gene/curator/task-runner.d.ts +10 -1
- package/dist/gene/curator/task-runner.js +52 -6
- package/dist/gene/curator/tool-support.js +11 -4
- package/dist/gene/curator/toolkit.d.ts +13 -0
- package/dist/gene/curator/toolkit.js +23 -1
- package/dist/gene/curator/tools-verify.js +2 -2
- package/dist/gene/curator/tools-write.js +6 -1
- package/dist/gene/curator/validate/evidence-tokens.js +133 -22
- package/dist/gene/curator/validate/knowledge.d.ts +41 -1
- package/dist/gene/curator/validate/knowledge.js +74 -11
- package/dist/gene/curator/validate/prompts.d.ts +10 -2
- package/dist/gene/curator/validate/prompts.js +2 -2
- package/dist/gene/hub.js +5 -0
- package/dist/gene/import-plan.js +8 -5
- package/dist/gene/learn/draft-guard.d.ts +17 -0
- package/dist/gene/learn/draft-guard.js +113 -0
- package/dist/gene/learn/learn-prompt.d.ts +22 -1
- package/dist/gene/learn/learn-prompt.js +27 -2
- package/dist/gene/learn/learner.js +27 -5
- package/dist/gene/queue.d.ts +24 -0
- package/dist/gene/queue.js +80 -1
- package/dist/governance/store/run-store.d.ts +20 -0
- package/dist/governance/store/run-store.js +54 -8
- package/dist/host/controller-factory.js +6 -0
- package/dist/host/index.d.ts +1 -0
- package/dist/host/index.js +1 -0
- package/dist/host/interaction.d.ts +8 -17
- package/dist/host/interaction.js +50 -72
- package/dist/host/team-wake-driver.d.ts +90 -0
- package/dist/host/team-wake-driver.js +114 -0
- package/dist/logging/install.d.ts +35 -1
- package/dist/logging/install.js +23 -0
- package/dist/session/persist.js +8 -1
- package/dist/session/validate-session.js +15 -5
- package/dist/team/console-tools.d.ts +12 -0
- package/dist/team/console-tools.js +20 -3
- package/dist/team/console-view.js +11 -1
- package/dist/team/notices.d.ts +81 -4
- package/dist/team/notices.js +187 -22
- package/dist/team/prompt.js +1 -1
- package/dist/team/runtime.d.ts +67 -24
- package/dist/team/runtime.js +250 -31
- package/dist/team/stall-watch.d.ts +54 -0
- package/dist/team/stall-watch.js +119 -0
- package/dist/team/task-tool.js +2 -2
- package/dist/team/wake.d.ts +176 -0
- package/dist/team/wake.js +444 -0
- package/package.json +81 -81
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TeamWakeDriver - how a HOST starts the turn the team asked for
|
|
3
|
+
* (team-lead-wake-signals section 4.10).
|
|
4
|
+
*
|
|
5
|
+
* THE GOVERNOR DECIDES THAT THE LEAD IS OWED A TURN; THIS DECIDES HOW THIS HOST
|
|
6
|
+
* STARTS ONE. Both the terminal app and the desktop coordinator mount exactly this
|
|
7
|
+
* class with their own ports, so the countdown, the cancel rules and the re-check at
|
|
8
|
+
* fire time are one implementation, not two that drift (AC-24). Everything that
|
|
9
|
+
* differs between hosts - where the timer lives, how a line is shown, how a turn is
|
|
10
|
+
* submitted - is a port.
|
|
11
|
+
*
|
|
12
|
+
* NO INK, NO TTY (layering gate L9): this file is in the import closure of
|
|
13
|
+
* `host/index.ts`, which a GUI process loads.
|
|
14
|
+
*
|
|
15
|
+
* THREE RULES THAT ARE EASY TO BREAK:
|
|
16
|
+
*
|
|
17
|
+
* - FIRE IS ONE SYNCHRONOUS BLOCK (I-WK10). Re-check, `leadBusy()`, submit, ack - no
|
|
18
|
+
* `await`. The controller's `prompt()` STOPS a running engine and the terminal's
|
|
19
|
+
* `submitMessage` turns a submit-while-running into USER steering; a wake that
|
|
20
|
+
* raced either would kill the lead's turn or masquerade as the user. So the busy
|
|
21
|
+
* checks and the submit share a stack frame.
|
|
22
|
+
*
|
|
23
|
+
* - THE DRIVER'S OWN SUBMIT MUST NOT CANCEL ITSELF. The terminal's `submitMessage`
|
|
24
|
+
* begins with `cancelFollowThrough()` ("any user input cancels a pending
|
|
25
|
+
* continuation"), and this driver is wired to that very call. So `fire` takes
|
|
26
|
+
* `outstandingId` down BEFORE it submits, and `cancel()` only acts on a request
|
|
27
|
+
* it still holds: the submit's own cancel finds nothing and does nothing. Without
|
|
28
|
+
* this the user sees "Wake cancelled" over a turn that is in fact running, and
|
|
29
|
+
* the governor parks notices it has just delivered.
|
|
30
|
+
*
|
|
31
|
+
* - A BUSY HOST IS NOT A DROPPED WAKE. Another continuation holding the timer, or the
|
|
32
|
+
* lead being busy, answers `busy`; the governor retries with back-off. Nothing is
|
|
33
|
+
* discarded and nothing steals the other continuation's slot (I-WK9).
|
|
34
|
+
*/
|
|
35
|
+
import { TEAM_SIGNAL_NEXT_MESSAGE } from '@aragon-agent/tui/model/team/wake-plan';
|
|
36
|
+
export class TeamWakeDriver {
|
|
37
|
+
ports;
|
|
38
|
+
/** The countdown this driver is holding, if any. The only thing `cancel()` acts on. */
|
|
39
|
+
outstandingId = null;
|
|
40
|
+
constructor(ports) {
|
|
41
|
+
this.ports = ports;
|
|
42
|
+
}
|
|
43
|
+
/** Subscribe to the controller. Returns the detach function. */
|
|
44
|
+
attach() {
|
|
45
|
+
// A controller double or an older host has no team surface: nothing to subscribe to,
|
|
46
|
+
// and nothing that could ever ask this driver for a wake.
|
|
47
|
+
if (typeof this.ports.controller.subscribeTeamWake !== 'function')
|
|
48
|
+
return () => { };
|
|
49
|
+
const unsubscribe = this.ports.controller.subscribeTeamWake((request) => this.onRequest(request));
|
|
50
|
+
return () => {
|
|
51
|
+
unsubscribe();
|
|
52
|
+
if (this.outstandingId !== null) {
|
|
53
|
+
this.outstandingId = null;
|
|
54
|
+
this.ports.timer.clear();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** Whether a countdown is running right now. Hosts use it to avoid a second toast. */
|
|
59
|
+
isCounting() {
|
|
60
|
+
return this.outstandingId !== null;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The user typed or pressed Esc: stop the countdown. Called by the host from its own
|
|
64
|
+
* "cancel any pending continuation" point. A no-op unless this driver holds a request.
|
|
65
|
+
*/
|
|
66
|
+
cancel() {
|
|
67
|
+
const id = this.outstandingId;
|
|
68
|
+
if (id === null)
|
|
69
|
+
return;
|
|
70
|
+
this.outstandingId = null;
|
|
71
|
+
this.ports.timer.clear();
|
|
72
|
+
this.ports.controller.ackTeamWake(id, 'cancelled');
|
|
73
|
+
(this.ports.toast ?? this.ports.announce)('info', `Wake cancelled. ${TEAM_SIGNAL_NEXT_MESSAGE}`);
|
|
74
|
+
}
|
|
75
|
+
onRequest(request) {
|
|
76
|
+
if (request.action === 'announce') {
|
|
77
|
+
this.ports.announce(request.announce.level, request.announce.text);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
// Another continuation holds the slot, or a turn is in flight: say "later", do not
|
|
81
|
+
// drop it and do not take the slot from the one that has it.
|
|
82
|
+
if (this.ports.timer.armed() || this.ports.leadBusy()) {
|
|
83
|
+
this.ports.controller.ackTeamWake(request.id, 'busy');
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const seconds = Math.max(1, Math.ceil(request.graceMs / 1000));
|
|
87
|
+
const hint = this.ports.cancelHint?.() ?? '';
|
|
88
|
+
const suffix = hint === '' ? '' : ` (${hint})`;
|
|
89
|
+
this.ports.announce(request.announce.level, `${request.announce.text} Waking the lead in ${seconds}s${suffix}`);
|
|
90
|
+
this.outstandingId = request.id;
|
|
91
|
+
this.ports.timer.set(() => this.fire(), request.graceMs);
|
|
92
|
+
}
|
|
93
|
+
/** The countdown ended. One synchronous block (I-WK10). */
|
|
94
|
+
fire() {
|
|
95
|
+
const id = this.outstandingId;
|
|
96
|
+
if (id === null)
|
|
97
|
+
return;
|
|
98
|
+
// BEFORE the submit: the host's submit begins by cancelling "any pending
|
|
99
|
+
// continuation", and this must find nothing left to cancel.
|
|
100
|
+
this.outstandingId = null;
|
|
101
|
+
const { controller } = this.ports;
|
|
102
|
+
const begun = controller.confirmTeamWake(id);
|
|
103
|
+
if (!begun.ok) {
|
|
104
|
+
controller.ackTeamWake(id, begun.why === 'obsolete' ? 'obsolete' : 'busy');
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (this.ports.leadBusy()) {
|
|
108
|
+
controller.ackTeamWake(id, 'busy');
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const accepted = this.ports.submit(begun.text, begun.invocation);
|
|
112
|
+
controller.ackTeamWake(id, accepted ? 'started' : 'busy');
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -160,6 +160,20 @@ export type AgentLogEvent = {
|
|
|
160
160
|
errorType?: string;
|
|
161
161
|
retryable?: boolean;
|
|
162
162
|
reason?: string;
|
|
163
|
+
/**
|
|
164
|
+
* Core's `AgentStallInfo`, present only on an `idle_watchdog` end. Spelled out
|
|
165
|
+
* rather than `Record<string, unknown>`: an interface has no index signature,
|
|
166
|
+
* so the loose type would make `AgentController` incompatible with this source.
|
|
167
|
+
*/
|
|
168
|
+
stall?: {
|
|
169
|
+
phase?: string;
|
|
170
|
+
lastEvent?: string;
|
|
171
|
+
msSinceLastEvent?: number;
|
|
172
|
+
wallMsSinceLastEvent?: number;
|
|
173
|
+
eventsSeen?: number;
|
|
174
|
+
idleTimeoutMs?: number;
|
|
175
|
+
toolName?: string;
|
|
176
|
+
};
|
|
163
177
|
} | {
|
|
164
178
|
type: 'turn_start';
|
|
165
179
|
} | {
|
|
@@ -187,6 +201,9 @@ export type AgentLogEvent = {
|
|
|
187
201
|
errorType?: string;
|
|
188
202
|
message?: unknown;
|
|
189
203
|
retryAfterMs?: number;
|
|
204
|
+
tier?: number;
|
|
205
|
+
tierCount?: number;
|
|
206
|
+
totalAttempts?: number;
|
|
190
207
|
discardedToolCallIds?: string[];
|
|
191
208
|
};
|
|
192
209
|
} | {
|
|
@@ -298,7 +315,7 @@ export declare function attachAgentEvents(logger: Logger, controller: AgentEvent
|
|
|
298
315
|
export interface TeamEventSource {
|
|
299
316
|
subscribeTeam?(listener: (event: TeamLogEvent) => void): () => void;
|
|
300
317
|
}
|
|
301
|
-
/** The
|
|
318
|
+
/** The nine members of the CLI-local `TeamEvent` union, as this module reads them. */
|
|
302
319
|
export type TeamLogEvent = {
|
|
303
320
|
type: 'dispatch_start';
|
|
304
321
|
dispatchId: string;
|
|
@@ -370,9 +387,26 @@ export type TeamLogEvent = {
|
|
|
370
387
|
reason?: string;
|
|
371
388
|
};
|
|
372
389
|
trigger?: string;
|
|
390
|
+
} | {
|
|
391
|
+
/** A subagent FINALLY failed (team-lead-wake-signals). Logged as label only. */
|
|
392
|
+
type: 'child_failed';
|
|
393
|
+
dispatchId: string;
|
|
394
|
+
run?: {
|
|
395
|
+
label?: string;
|
|
396
|
+
phase?: string;
|
|
397
|
+
};
|
|
398
|
+
} | {
|
|
399
|
+
/** Nobody is doing real work and somebody is blocked (team-lead-wake-signals). */
|
|
400
|
+
type: 'stalled';
|
|
401
|
+
dispatchId: string;
|
|
402
|
+
episode?: number;
|
|
403
|
+
quietMs?: number;
|
|
404
|
+
blockers?: unknown[];
|
|
373
405
|
} | {
|
|
374
406
|
type: 'dispatch_end';
|
|
375
407
|
dispatchId: string;
|
|
408
|
+
/** True for every detached dispatch (team-lead-wake-signals I-WK15). */
|
|
409
|
+
detached?: boolean;
|
|
376
410
|
outcome?: {
|
|
377
411
|
startedAt?: number;
|
|
378
412
|
endedAt?: number;
|
package/dist/logging/install.js
CHANGED
|
@@ -373,6 +373,14 @@ export function attachAgentEvents(logger, controller) {
|
|
|
373
373
|
// retry line stays small; an HTTP-error body already arrives cut at 300.
|
|
374
374
|
message: typeof se.message === 'string' ? se.message.slice(0, 200) : undefined,
|
|
375
375
|
retryAfterMs: se.retryAfterMs,
|
|
376
|
+
// TIERED RECONNECT (§4.6.7). `attempt` is per-tier, so an operator
|
|
377
|
+
// reading one line cannot tell a 3rd fast retry from a 3rd five-minute
|
|
378
|
+
// hold; these three say which ladder and how long it has been going.
|
|
379
|
+
// Absent when the host does not escalate, so the record shape is
|
|
380
|
+
// unchanged there.
|
|
381
|
+
...(se.tier !== undefined ? { tier: se.tier } : {}),
|
|
382
|
+
...(se.tierCount !== undefined ? { tierCount: se.tierCount } : {}),
|
|
383
|
+
...(se.totalAttempts !== undefined ? { totalAttempts: se.totalAttempts } : {}),
|
|
376
384
|
providerId: cfg.provider,
|
|
377
385
|
modelId: cfg.model,
|
|
378
386
|
});
|
|
@@ -447,6 +455,10 @@ export function attachAgentEvents(logger, controller) {
|
|
|
447
455
|
...(event.errorType !== undefined ? { errorType: event.errorType } : {}),
|
|
448
456
|
...(event.retryable !== undefined ? { retryable: event.retryable } : {}),
|
|
449
457
|
...(event.reason !== undefined ? { reason: event.reason } : {}),
|
|
458
|
+
// WHERE THE WATCHDOG'S SILENCE BEGAN (team-idle-watchdog-dead-run F0): the
|
|
459
|
+
// phase, the last event, and the silence on BOTH clocks, so the next death
|
|
460
|
+
// can be attributed without inferring it from the gap to the previous row.
|
|
461
|
+
...(event.stall !== undefined ? { stall: event.stall } : {}),
|
|
450
462
|
});
|
|
451
463
|
break;
|
|
452
464
|
}
|
|
@@ -516,6 +528,17 @@ export function attachTeamEvents(logger, controller) {
|
|
|
516
528
|
});
|
|
517
529
|
break;
|
|
518
530
|
}
|
|
531
|
+
case 'child_failed':
|
|
532
|
+
// COUNTS AND NAMES ONLY: the error text is a provider's or a tool's prose, and
|
|
533
|
+
// the controller's `team_signal_raised` line already records the signal itself.
|
|
534
|
+
logger.info('agent', 'team_child_failed', {
|
|
535
|
+
dispatchId: event.dispatchId,
|
|
536
|
+
label: event.run?.label,
|
|
537
|
+
});
|
|
538
|
+
break;
|
|
539
|
+
case 'stalled':
|
|
540
|
+
// Logged by the controller as `team_stall_detected`, next to the notice it queues.
|
|
541
|
+
break;
|
|
519
542
|
case 'message':
|
|
520
543
|
logger.debug('agent', 'team_message', {
|
|
521
544
|
dispatchId: event.dispatchId,
|
package/dist/session/persist.js
CHANGED
|
@@ -196,8 +196,15 @@ export function normalizeLoadedEntries(entries) {
|
|
|
196
196
|
// would never advance past it and every frame for the rest of the session
|
|
197
197
|
// would re-render the whole tail. `resumeAt` is dropped for the same reason
|
|
198
198
|
// the phase changes: there is no attempt coming.
|
|
199
|
+
//
|
|
200
|
+
// `tierEndsAt` GOES WITH IT (tiered-reconnect P1-2). This is the load-time
|
|
201
|
+
// normalisation, and it is the ONLY one — the reducer's `abortMark` / `runEnd`
|
|
202
|
+
// paths are runtime settlement, not load. A card saved while waiting in tier 3
|
|
203
|
+
// would otherwise revive holding an instant that says "this tier ends at ..."
|
|
204
|
+
// for a ladder that no longer exists, which is exactly the stale fact the
|
|
205
|
+
// phase change was meant to remove.
|
|
199
206
|
if (entry.kind === 'retry' && (entry.phase === 'waiting' || entry.phase === 'retrying')) {
|
|
200
|
-
return { ...entry, phase: 'interrupted', resumeAt: undefined };
|
|
207
|
+
return { ...entry, phase: 'interrupted', resumeAt: undefined, tierEndsAt: undefined };
|
|
201
208
|
}
|
|
202
209
|
// THE FOURTH CLAUSE (fast-model-tier §5.4 / C-5 / AC-28). A review card
|
|
203
210
|
// saved while its call was open resumes claiming to be running while nothing
|
|
@@ -205,6 +205,13 @@ const ENTRY_FIELDS = {
|
|
|
205
205
|
resumeAt: optional(number), startedAt: number, totalRetries: optional(number),
|
|
206
206
|
elapsedMs: optional(number),
|
|
207
207
|
phase: enumeration('waiting', 'retrying', 'recovered', 'exhausted', 'interrupted'),
|
|
208
|
+
// TIERED RECONNECT (tiered-reconnect §4.8). Four OPTIONAL fields, and `number`
|
|
209
|
+
// rather than a 1|2|3 enumeration on purpose: a hand-edited or future tier id
|
|
210
|
+
// is not worth refusing a whole session over, and a bad value simply renders as
|
|
211
|
+
// the tier-1 line. A card saved by an older build lacks all four and loads
|
|
212
|
+
// unchanged.
|
|
213
|
+
tier: optional(number), tierCount: optional(number), totalAttempts: optional(number),
|
|
214
|
+
tierEndsAt: optional(number),
|
|
208
215
|
},
|
|
209
216
|
fast: { reviewIndex: number, model: string,
|
|
210
217
|
status: enumeration('running', 'ok', 'advice', 'empty', 'failed', 'dropped'),
|
|
@@ -220,9 +227,11 @@ const ENTRY_FIELDS = {
|
|
|
220
227
|
tokensBefore: number, tokensAfter: number, summary: optional(string), model: string,
|
|
221
228
|
durationMs: optional(number), startedAt: optional(number), live: boolean,
|
|
222
229
|
tailRelief: optional(shape({ messages: number, charsRemoved: number })),
|
|
223
|
-
// THE v3 OPTIONAL FIELDS (context-compaction-v3 §4.7).
|
|
224
|
-
//
|
|
225
|
-
//
|
|
230
|
+
// THE v3 OPTIONAL FIELDS (context-compaction-v3 §4.7). DECLARED HERE SO THEY
|
|
231
|
+
// ARE CHECKED, not because an undeclared key would be refused: `shape()`
|
|
232
|
+
// iterates the keys it was GIVEN (see above), so an unknown field on disk
|
|
233
|
+
// passes through untouched. Declaring one is what turns a malformed value into
|
|
234
|
+
// a precise error instead of a silent `undefined` at render time.
|
|
226
235
|
prune: optional(shape({ actions: nonnegative, removedChars: nonnegative,
|
|
227
236
|
removedTokens: nonnegative, inspected: nonnegative, kinds: object })),
|
|
228
237
|
budget: optional(shape({ limitTokens: nonnegative, spentTokens: nonnegative,
|
|
@@ -241,8 +250,9 @@ const ENTRY_FIELDS = {
|
|
|
241
250
|
startedAt: number, readyAt: optional(number), endedAt: optional(number), rows: array(string),
|
|
242
251
|
rowsSeen: number, terminal: optional(boolean), killIncomplete: optional(boolean),
|
|
243
252
|
// THE FOUR FIELDS long-task-jobs adds (AC-38), and the reason this validator
|
|
244
|
-
// has to learn them:
|
|
245
|
-
//
|
|
253
|
+
// has to learn them: `shape()` only checks the keys it is given, so an
|
|
254
|
+
// undeclared one is passed through UNVALIDATED — a job card with a malformed
|
|
255
|
+
// `jobKind` would reach the renderer and be trusted there, which is a P0 in
|
|
246
256
|
// R-8's terms.
|
|
247
257
|
//
|
|
248
258
|
// ALL FOUR ARE OPTIONAL HERE, DELIBERATELY, and that is a correction to the
|
|
@@ -33,6 +33,18 @@ export interface ConsoleToolDeps {
|
|
|
33
33
|
* must never miss: the lead waiting is acceptable, the USER waiting is not.
|
|
34
34
|
*/
|
|
35
35
|
hasPendingUserInput: () => boolean;
|
|
36
|
+
/**
|
|
37
|
+
* `controller.acknowledgeTeamSettle(dispatchId)`: the report is about to be handed
|
|
38
|
+
* over in a tool result, so the settle notice must not deliver it a second time
|
|
39
|
+
* (team-lead-wake-signals RC-8). Optional so a host without notices stays unchanged.
|
|
40
|
+
*/
|
|
41
|
+
acknowledgeSettle?: (dispatchId: string) => void;
|
|
42
|
+
/**
|
|
43
|
+
* `controller.hasPendingTeamAttention()`: the runtime has something to tell the lead
|
|
44
|
+
* (a child failed, the team stalled). `team_collect` stops waiting on it - the notice
|
|
45
|
+
* reaches the lead on its own the moment this tool returns.
|
|
46
|
+
*/
|
|
47
|
+
hasPendingTeamAttention?: () => boolean;
|
|
36
48
|
/** Who is acting. `'lead'` for these tools; `'user'` for `/team` verbs. */
|
|
37
49
|
by?: TeamControlBy;
|
|
38
50
|
}
|
|
@@ -269,11 +269,13 @@ export function makeTeamCollectTool(deps) {
|
|
|
269
269
|
const report = deps.runtime.reportText(startId);
|
|
270
270
|
if (report === undefined)
|
|
271
271
|
return textResult(NO_DISPATCH);
|
|
272
|
+
deps.acknowledgeSettle?.(startId);
|
|
272
273
|
return textResult(`settled: true\n\n${report}`);
|
|
273
274
|
}
|
|
274
275
|
const waited = await waitForSettle(deps, startId, seconds * 1000);
|
|
275
276
|
const report = deps.runtime.reportText(startId);
|
|
276
277
|
if (waited === 'settled' && report !== undefined) {
|
|
278
|
+
deps.acknowledgeSettle?.(startId);
|
|
277
279
|
return textResult(`settled: true\n\n${report}`);
|
|
278
280
|
}
|
|
279
281
|
const inspection = deps.runtime.inspect();
|
|
@@ -282,9 +284,7 @@ export function makeTeamCollectTool(deps) {
|
|
|
282
284
|
? 'the dispatch is no longer live'
|
|
283
285
|
: `${counts.running} running, ${counts.queued} waiting, ${counts.paused} paused, ` +
|
|
284
286
|
`${counts.done} done, ${counts.failed} failed`;
|
|
285
|
-
const why = waited
|
|
286
|
-
? 'stopped waiting: the user sent you a message. Answer it first; the report will arrive on its own.'
|
|
287
|
-
: `still live after ${seconds}s; ${state}. Do not wait again - answer the user, or use team_status.`;
|
|
287
|
+
const why = describeUnsettled(waited, seconds, state);
|
|
288
288
|
return textResult(`settled: false\n${why}`);
|
|
289
289
|
},
|
|
290
290
|
};
|
|
@@ -309,6 +309,13 @@ function waitForSettle(deps, dispatchId, budgetMs) {
|
|
|
309
309
|
resolve('settled');
|
|
310
310
|
return;
|
|
311
311
|
}
|
|
312
|
+
// A signal for the lead (a child failed, the team stalled) ends the wait: it is
|
|
313
|
+
// steered in the moment this tool returns, and holding the lead here would only
|
|
314
|
+
// delay the one thing it most needs to read (team-lead-wake-signals 4.8).
|
|
315
|
+
if (deps.hasPendingTeamAttention?.() === true) {
|
|
316
|
+
resolve('signal');
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
312
319
|
if (Date.now() - startedAt >= budgetMs) {
|
|
313
320
|
resolve('timeout');
|
|
314
321
|
return;
|
|
@@ -319,6 +326,16 @@ function waitForSettle(deps, dispatchId, budgetMs) {
|
|
|
319
326
|
tick();
|
|
320
327
|
});
|
|
321
328
|
}
|
|
329
|
+
/** The sentence a `settled: false` result gives for why the wait ended. */
|
|
330
|
+
function describeUnsettled(waited, seconds, state) {
|
|
331
|
+
if (waited === 'user_message') {
|
|
332
|
+
return 'stopped waiting: the user sent you a message. Answer it first; the report will arrive on its own.';
|
|
333
|
+
}
|
|
334
|
+
if (waited === 'signal') {
|
|
335
|
+
return 'stopped waiting: a team signal arrived (a subagent failed or the team stalled). It will reach you on its own - read it first.';
|
|
336
|
+
}
|
|
337
|
+
return `still live after ${seconds}s; ${state}. Do not wait again - answer the user, or use team_status.`;
|
|
338
|
+
}
|
|
322
339
|
/** The seven tools, in the order the prompt block lists them. */
|
|
323
340
|
export function createConsoleTools(deps) {
|
|
324
341
|
return [
|
|
@@ -95,7 +95,17 @@ export function renderTeamStatus(inspection, options = {}) {
|
|
|
95
95
|
(mailDetail.length > 0 ? ` (${mailDetail})` : '') +
|
|
96
96
|
` interventions: ${inspection.controls.length}` +
|
|
97
97
|
(controlDetail.length > 0 ? ` (${controlDetail})` : '');
|
|
98
|
-
|
|
98
|
+
// One line under the header when the watch says nobody is working: the lead and the
|
|
99
|
+
// user can both read "no progress for 3m" without having to infer it from phases.
|
|
100
|
+
const stalled = inspection.stalled === undefined
|
|
101
|
+
? []
|
|
102
|
+
: [
|
|
103
|
+
`no progress for ${formatElapsed(inspection.stalled.quietMs)}` +
|
|
104
|
+
(inspection.stalled.blockers.length > 0
|
|
105
|
+
? ` (blocked: ${inspection.stalled.blockers.join(', ')})`
|
|
106
|
+
: ''),
|
|
107
|
+
];
|
|
108
|
+
const parts = [head, ...stalled, ...roster, footer];
|
|
99
109
|
if (options.includeSummary === true) {
|
|
100
110
|
for (const child of rows) {
|
|
101
111
|
if (child.summary === undefined || child.summary.length === 0)
|
package/dist/team/notices.d.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* I-5) and the "the settle report must always arrive" rule in one object and let
|
|
14
14
|
* either win.
|
|
15
15
|
*
|
|
16
|
-
*
|
|
16
|
+
* FIVE KINDS, THREE LIFETIMES:
|
|
17
17
|
*
|
|
18
18
|
* - `child_settled` is CHATTER. It is dropped the moment the `dispatch_settled`
|
|
19
19
|
* report arrives, because the report already contains every row - five child
|
|
@@ -25,7 +25,17 @@
|
|
|
25
25
|
* outcome.
|
|
26
26
|
* - `lead_mail` is a REMINDER, bounded by `leadNoticesPerDispatch`; the full mail
|
|
27
27
|
* is always in the report as well, so losing one of these loses nothing.
|
|
28
|
+
* - `child_failed` and `team_stalled` (team-lead-wake-signals) are SIGNALS: the
|
|
29
|
+
* team needs the lead BEFORE the dispatch ends. Like `child_settled` they are
|
|
30
|
+
* chatter once the report exists, and the queue remembers which dispatches have
|
|
31
|
+
* settled so a stranded one that is re-queued later cannot come back to life.
|
|
32
|
+
*
|
|
33
|
+
* `isAttention()` is the one predicate that says which notices the lead is OWED a
|
|
34
|
+
* wake for. It is a property of the notice, not a second queue.
|
|
28
35
|
*/
|
|
36
|
+
import { type AttentionFact, type SettleFacts } from '@aragon-agent/tui/model/team/wake-plan';
|
|
37
|
+
import type { DispatchOutcome, StallBlocker } from '@aragon-agent/tui/model/team/types';
|
|
38
|
+
export type { SettleFacts };
|
|
29
39
|
export type TeamNotice = {
|
|
30
40
|
kind: 'child_settled';
|
|
31
41
|
/** `${dispatchId}:${label}:${phase}` - a child settles once. */
|
|
@@ -47,6 +57,36 @@ export type TeamNotice = {
|
|
|
47
57
|
/** `session.reportText`, verbatim. */
|
|
48
58
|
report: string;
|
|
49
59
|
aborted: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Whether the lead is OWED a wake for this end. False for a stop the user or the
|
|
62
|
+
* lead ordered themselves (I-WK11): the actor already knows. The notice is still
|
|
63
|
+
* queued and still delivered with the next turn.
|
|
64
|
+
*/
|
|
65
|
+
attention: boolean;
|
|
66
|
+
/** Counted from the outcome; what `<team_signal>` states. */
|
|
67
|
+
facts: SettleFacts;
|
|
68
|
+
at: number;
|
|
69
|
+
} | {
|
|
70
|
+
kind: 'child_failed';
|
|
71
|
+
/** `${dispatchId}:fail:${label}` - a child fails finally once. */
|
|
72
|
+
id: string;
|
|
73
|
+
dispatchId: string;
|
|
74
|
+
label: string;
|
|
75
|
+
/** First line of the error, already cut. */
|
|
76
|
+
error: string;
|
|
77
|
+
elapsedMs: number;
|
|
78
|
+
turns: number;
|
|
79
|
+
toolCalls: number;
|
|
80
|
+
stillRunning: number;
|
|
81
|
+
at: number;
|
|
82
|
+
} | {
|
|
83
|
+
kind: 'team_stalled';
|
|
84
|
+
/** `${dispatchId}:stall:${episode}`. */
|
|
85
|
+
id: string;
|
|
86
|
+
dispatchId: string;
|
|
87
|
+
episode: number;
|
|
88
|
+
quietMs: number;
|
|
89
|
+
blockers: StallBlocker[];
|
|
50
90
|
at: number;
|
|
51
91
|
} | {
|
|
52
92
|
kind: 'lead_mail';
|
|
@@ -59,6 +99,14 @@ export type TeamNotice = {
|
|
|
59
99
|
bodyHead: string;
|
|
60
100
|
at: number;
|
|
61
101
|
};
|
|
102
|
+
/** Notices that mean "the lead is owed a wake". `dispatch_settled` decides per notice. */
|
|
103
|
+
export declare function isAttention(notice: TeamNotice): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* The wake governor's view of one notice: the facts and nothing else, or `null` for a
|
|
106
|
+
* notice the lead is not owed a wake for. The governor lives in a different layer
|
|
107
|
+
* than the notice shapes and reads only this.
|
|
108
|
+
*/
|
|
109
|
+
export declare function attentionFactOf(notice: TeamNotice): AttentionFact | null;
|
|
62
110
|
export declare class TeamNoticeQueue {
|
|
63
111
|
private readonly entries;
|
|
64
112
|
/**
|
|
@@ -70,6 +118,16 @@ export declare class TeamNoticeQueue {
|
|
|
70
118
|
* what the bound is for.
|
|
71
119
|
*/
|
|
72
120
|
private readonly leadMails;
|
|
121
|
+
/**
|
|
122
|
+
* Dispatches whose report has been queued, in arrival order.
|
|
123
|
+
*
|
|
124
|
+
* WHY THE QUEUE REMEMBERS (RV-P2-11). Swallowing chatter when the report arrives
|
|
125
|
+
* only touches what is IN the queue at that moment. A `child_failed` that had
|
|
126
|
+
* already been steered sits in the relay's ledger, and when the ledger gives it back
|
|
127
|
+
* (`requeueUndelivered`) it would re-enter a queue whose report is already there
|
|
128
|
+
* and be delivered a second time, as a fact the report already contains.
|
|
129
|
+
*/
|
|
130
|
+
private readonly settledDispatches;
|
|
73
131
|
/**
|
|
74
132
|
* Same id twice keeps ONE entry. That is what makes the relay's re-queue after a
|
|
75
133
|
* queue wipe idempotent: a notice that was delivered and re-queued can only be
|
|
@@ -79,17 +137,36 @@ export declare class TeamNoticeQueue {
|
|
|
79
137
|
/** Take everything and reset. The one way a notice leaves this object. */
|
|
80
138
|
drain(): TeamNotice[];
|
|
81
139
|
peek(): TeamNotice[];
|
|
140
|
+
/** The queued notices the lead is owed a wake for. */
|
|
141
|
+
attention(): TeamNotice[];
|
|
142
|
+
/**
|
|
143
|
+
* Remove one notice without delivering it. The one caller is `team_collect`: it has
|
|
144
|
+
* just handed the lead the same report in a tool result, so delivering it again
|
|
145
|
+
* would be the duplicate RC-8 describes.
|
|
146
|
+
*/
|
|
147
|
+
dropById(id: string): boolean;
|
|
82
148
|
pending(): number;
|
|
83
149
|
clear(): void;
|
|
150
|
+
private rememberSettled;
|
|
84
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Count one outcome into the facts `<team_signal>` states.
|
|
154
|
+
*
|
|
155
|
+
* DERIVED FROM THE OUTCOME ALONE, like the report's own header, so the two cannot
|
|
156
|
+
* disagree about how many children failed. "Stopped by" comes from the interventions
|
|
157
|
+
* ledger, which is where `recordControl` already writes who stopped whom.
|
|
158
|
+
*/
|
|
159
|
+
export declare function settleFactsOf(outcome: DispatchOutcome): SettleFacts;
|
|
160
|
+
/** First line of an error, cut to the signal's own bound. */
|
|
161
|
+
export declare function firstLine(text: string): string;
|
|
85
162
|
/**
|
|
86
163
|
* Render the `<team_notices>` block, or `''` when there is nothing to say.
|
|
87
164
|
*
|
|
88
165
|
* EMPTY IN, EMPTY OUT, for the same reason `renderJobNotices` is: an unconditional
|
|
89
166
|
* block would add lines to every tool call in every session.
|
|
90
167
|
*
|
|
91
|
-
* ORDER: the settle report FIRST, then mail, then child
|
|
92
|
-
* fact; the rest is context for it, and a model that reads
|
|
93
|
-
* lines of a block should still see the thing that ended.
|
|
168
|
+
* ORDER: the settle report FIRST, then the live signals, then mail, then child
|
|
169
|
+
* lines. The report is the fact; the rest is context for it, and a model that reads
|
|
170
|
+
* only the first two lines of a block should still see the thing that ended.
|
|
94
171
|
*/
|
|
95
172
|
export declare function renderTeamNotices(notices: readonly TeamNotice[]): string;
|