@aragon-agent/cli 0.6.63 → 0.6.64
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 +70 -2
- package/README.md +44 -20
- package/dist/agent/controller.d.ts +66 -14
- package/dist/agent/controller.js +291 -81
- package/dist/agent/headless.d.ts +16 -0
- package/dist/agent/headless.js +44 -3
- package/dist/agent/team-notices.d.ts +57 -7
- package/dist/agent/team-notices.js +93 -10
- package/dist/app/App.js +199 -77
- package/dist/cli.js +4 -1
- package/dist/config/cli-commands.d.ts +1 -1
- package/dist/config/cli-commands.js +11 -0
- package/dist/exec/index.js +2 -0
- package/dist/exec/runner.js +10 -1
- package/dist/gene/commit-prepare.js +27 -1
- package/dist/gene/curator/curator.d.ts +15 -0
- package/dist/gene/curator/curator.js +26 -2
- 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 +21 -0
- package/dist/gene/curator/task-context.js +33 -0
- package/dist/gene/curator/task-runner.d.ts +10 -1
- package/dist/gene/curator/task-runner.js +39 -4
- 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/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 +20 -2
- package/dist/gene/queue.d.ts +16 -0
- package/dist/gene/queue.js +44 -1
- package/dist/governance/store/run-store.d.ts +20 -0
- package/dist/governance/store/run-store.js +54 -8
- 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 +32 -1
- package/dist/logging/install.js +15 -0
- 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
package/dist/team/runtime.js
CHANGED
|
@@ -35,6 +35,7 @@ import { TEAM_AGGREGATE_LABEL, TEAM_LIMITS } from '@aragon-agent/tui/model/team/
|
|
|
35
35
|
import { TeamOverseer, createOverseerUsageCursor, buildReplacementPrompt, nextOverseerLadderStepMs, resolveOverseerFirstCheckMs, } from './overseer.js';
|
|
36
36
|
import { shouldRetryColdStart } from './retry.js';
|
|
37
37
|
import { PauseGate } from './pause-gate.js';
|
|
38
|
+
import { ProgressLedger } from './stall-watch.js';
|
|
38
39
|
import { normalizeSubagentSpecs, dedupeLabel } from './normalize.js';
|
|
39
40
|
import { buildDispatchReport } from './report.js';
|
|
40
41
|
import { createSubagent, defaultSubagentFactory, } from './subagent.js';
|
|
@@ -63,6 +64,25 @@ const DEGRADED_WAIT_DECISION = {
|
|
|
63
64
|
function isTerminal(phase) {
|
|
64
65
|
return phase === 'done' || phase === 'failed' || phase === 'aborted';
|
|
65
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* A `failed` run for a spec that never got a body (the dispatch died before its
|
|
69
|
+
* children could be constructed). Only existing `SubagentRun` fields.
|
|
70
|
+
*/
|
|
71
|
+
function placeholderRun(spec, reason, now) {
|
|
72
|
+
return {
|
|
73
|
+
label: spec.label,
|
|
74
|
+
description: spec.description,
|
|
75
|
+
phase: 'failed',
|
|
76
|
+
startedAt: now,
|
|
77
|
+
endedAt: now,
|
|
78
|
+
turns: 0,
|
|
79
|
+
toolCalls: 0,
|
|
80
|
+
usage: { inputTokens: 0, outputTokens: 0 },
|
|
81
|
+
filesTouched: [],
|
|
82
|
+
messagesSent: 0,
|
|
83
|
+
error: reason,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
66
86
|
/**
|
|
67
87
|
* One sentence for a refusal the BUS made, in the model's terms.
|
|
68
88
|
*
|
|
@@ -485,6 +505,23 @@ export class TeamRuntime {
|
|
|
485
505
|
mail: session.bus?.leadMail() ?? [],
|
|
486
506
|
controls: [...session.controls],
|
|
487
507
|
...(session.reportText !== undefined ? { reportText: session.reportText } : {}),
|
|
508
|
+
...this.stalledInspection(session),
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
/** `{ stalled }` while the watch currently judges the team stalled, else nothing. */
|
|
512
|
+
stalledInspection(session) {
|
|
513
|
+
const watch = session.stall;
|
|
514
|
+
if (watch === null || session.state !== 'live')
|
|
515
|
+
return {};
|
|
516
|
+
const verdict = this.stallVerdict(session, watch);
|
|
517
|
+
if (!verdict.stalled)
|
|
518
|
+
return {};
|
|
519
|
+
return {
|
|
520
|
+
stalled: {
|
|
521
|
+
since: verdict.since,
|
|
522
|
+
quietMs: verdict.quietMs,
|
|
523
|
+
blockers: verdict.blockers.map((blocker) => blocker.label),
|
|
524
|
+
},
|
|
488
525
|
};
|
|
489
526
|
}
|
|
490
527
|
/**
|
|
@@ -565,6 +602,9 @@ export class TeamRuntime {
|
|
|
565
602
|
.filter((handle) => !isTerminal(handle.run.phase))
|
|
566
603
|
.map((handle) => handle.run.label);
|
|
567
604
|
this.recordControl(session, 'stop', { by, reason: why });
|
|
605
|
+
// The actor already knows, so the settle that follows is not a signal (I-WK11).
|
|
606
|
+
if (by === 'user' || by === 'lead')
|
|
607
|
+
this.noteAbortedBy(by);
|
|
568
608
|
this.abortAll();
|
|
569
609
|
return { stopped, live: [] };
|
|
570
610
|
}
|
|
@@ -737,6 +777,11 @@ export class TeamRuntime {
|
|
|
737
777
|
trigger: detail.by === 'supervisor' ? 'clock' : detail.by,
|
|
738
778
|
});
|
|
739
779
|
}
|
|
780
|
+
// The lead stepping in is activity by definition: a stall verdict that ignored it
|
|
781
|
+
// would call a team stalled one second after the lead resumed a child.
|
|
782
|
+
if (action === 'resume' || action === 'spawn' || action === 'message') {
|
|
783
|
+
this.noteProgress(session, true);
|
|
784
|
+
}
|
|
740
785
|
this.emitControl(session, action, detail);
|
|
741
786
|
}
|
|
742
787
|
emitControl(session, action, detail) {
|
|
@@ -816,10 +861,79 @@ export class TeamRuntime {
|
|
|
816
861
|
.catch((error) => {
|
|
817
862
|
const reason = error instanceof Error ? error.message : String(error);
|
|
818
863
|
this.emitControl(session, 'stop', { by: 'supervisor', reason: `dispatch failed: ${reason}` });
|
|
864
|
+
// `task` has already told the lead "dispatched", so a dispatch that dies here
|
|
865
|
+
// with no `dispatch_end` is a team the lead waits for for ever (RV-P0-1).
|
|
866
|
+
this.failDetached(session, reason);
|
|
819
867
|
})
|
|
820
868
|
.finally(() => this.teardown(session));
|
|
821
869
|
return handle;
|
|
822
870
|
}
|
|
871
|
+
/**
|
|
872
|
+
* EXACTLY ONE `dispatch_end` PER DETACHED DISPATCH (I-WK15), including the ones
|
|
873
|
+
* that never got to emit their own.
|
|
874
|
+
*
|
|
875
|
+
* `runDispatch` can throw before `dispatch_start` (a child cannot be constructed)
|
|
876
|
+
* or, in principle, afterwards. The `session.outcome` guard is what makes "exactly
|
|
877
|
+
* one" a property of this method rather than of `runDispatch`'s shape: a dispatch
|
|
878
|
+
* that already settled has its outcome and its `dispatch_end`, and this returns.
|
|
879
|
+
*
|
|
880
|
+
* THE OUTCOME IS SYNTHESISED FROM FIELDS THAT ALREADY EXIST, every run `failed`
|
|
881
|
+
* with the reason: no new `DispatchOutcome` member (it is persisted), and the real
|
|
882
|
+
* `buildDispatchReport` can render it, so the lead reads a report in the format it
|
|
883
|
+
* knows. If even synthesis throws it degrades to one line per spec - a rough report
|
|
884
|
+
* beats no signal.
|
|
885
|
+
*/
|
|
886
|
+
failDetached(session, reason) {
|
|
887
|
+
if (session.outcome !== undefined)
|
|
888
|
+
return;
|
|
889
|
+
const outcome = this.synthesizeFailedOutcome(session, reason);
|
|
890
|
+
session.outcome = outcome;
|
|
891
|
+
try {
|
|
892
|
+
session.reportText = buildDispatchReport(outcome, this.deps.reportOptions?.() ?? {});
|
|
893
|
+
}
|
|
894
|
+
catch {
|
|
895
|
+
session.reportText = outcome.runs
|
|
896
|
+
.map((run) => `[failed] ${run.label}: ${run.error ?? 'dispatch failed'}`)
|
|
897
|
+
.join('\n');
|
|
898
|
+
}
|
|
899
|
+
this.emit({ type: 'dispatch_end', dispatchId: session.id, outcome, detached: true });
|
|
900
|
+
}
|
|
901
|
+
synthesizeFailedOutcome(session, reason) {
|
|
902
|
+
const now = Date.now();
|
|
903
|
+
try {
|
|
904
|
+
const runs = session.handles.length > 0
|
|
905
|
+
? session.handles.map((handle) => {
|
|
906
|
+
const settled = settledRun(handle.run);
|
|
907
|
+
if (isTerminal(settled.phase))
|
|
908
|
+
return settled;
|
|
909
|
+
return { ...settled, phase: 'failed', error: reason, endedAt: now };
|
|
910
|
+
})
|
|
911
|
+
: session.specs.map((spec) => placeholderRun(spec, reason, now));
|
|
912
|
+
return {
|
|
913
|
+
dispatchId: session.id,
|
|
914
|
+
runs,
|
|
915
|
+
requested: session.requested,
|
|
916
|
+
startedAt: session.startedAt,
|
|
917
|
+
endedAt: now,
|
|
918
|
+
aborted: false,
|
|
919
|
+
leadMail: session.bus?.leadMail() ?? [],
|
|
920
|
+
interventions: this.interventions,
|
|
921
|
+
usage: runs.reduce((acc, run) => accumulateUsage(acc, run.usage), { inputTokens: 0, outputTokens: 0 }),
|
|
922
|
+
};
|
|
923
|
+
}
|
|
924
|
+
catch {
|
|
925
|
+
return {
|
|
926
|
+
dispatchId: session.id,
|
|
927
|
+
runs: session.specs.map((spec) => placeholderRun(spec, 'dispatch failed', now)),
|
|
928
|
+
requested: session.requested,
|
|
929
|
+
startedAt: session.startedAt,
|
|
930
|
+
endedAt: now,
|
|
931
|
+
aborted: false,
|
|
932
|
+
leadMail: [],
|
|
933
|
+
usage: { inputTokens: 0, outputTokens: 0 },
|
|
934
|
+
};
|
|
935
|
+
}
|
|
936
|
+
}
|
|
823
937
|
/** The live dispatch handle, or `null`. The read surface behind `team_status`. */
|
|
824
938
|
live() {
|
|
825
939
|
const session = this.session;
|
|
@@ -844,35 +958,27 @@ export class TeamRuntime {
|
|
|
844
958
|
return session !== null && session.id === dispatchId ? session.reportText : undefined;
|
|
845
959
|
}
|
|
846
960
|
/**
|
|
847
|
-
*
|
|
848
|
-
* turn (`planSettleContinuation`, section 5.3.3).
|
|
961
|
+
* Who ended dispatch `dispatchId` as a whole, if anybody did (I-WK11).
|
|
849
962
|
*
|
|
850
|
-
*
|
|
851
|
-
*
|
|
852
|
-
*
|
|
853
|
-
* failed fast inside the very turn that started it, where the report has
|
|
854
|
-
* already arrived as a steering message.
|
|
963
|
+
* READ BY THE CONTROLLER INSIDE ITS `dispatch_end` LISTENER, where it decides
|
|
964
|
+
* whether the settle notice is a wake-worthy signal: a stop the user or the lead
|
|
965
|
+
* ordered is a fact the ordering party already has.
|
|
855
966
|
*/
|
|
856
|
-
|
|
967
|
+
abortedBy(dispatchId) {
|
|
857
968
|
const session = this.session;
|
|
858
|
-
|
|
859
|
-
return null;
|
|
860
|
-
const outcome = session.outcome ?? null;
|
|
861
|
-
const errored = outcome !== null && outcome.runs.some((run) => run.phase === 'failed');
|
|
862
|
-
return {
|
|
863
|
-
settled: session.state === 'settled',
|
|
864
|
-
settledInsideTurn: session.settledInsideTurn,
|
|
865
|
-
continuedThisDispatch: session.continued,
|
|
866
|
-
aborted: outcome?.aborted === true,
|
|
867
|
-
errored,
|
|
868
|
-
outcome,
|
|
869
|
-
};
|
|
969
|
+
return session !== null && session.id === dispatchId ? session.abortedBy : undefined;
|
|
870
970
|
}
|
|
871
|
-
/**
|
|
872
|
-
|
|
971
|
+
/**
|
|
972
|
+
* Record that the LIVE dispatch is being ended on purpose by `by`. First writer
|
|
973
|
+
* wins: an Esc followed by `team_stop all` is still one decision. A narrow method
|
|
974
|
+
* rather than a setter so `controller.stopEngine()` cannot reach the session.
|
|
975
|
+
*/
|
|
976
|
+
noteAbortedBy(by) {
|
|
873
977
|
const session = this.session;
|
|
874
|
-
if (session
|
|
875
|
-
|
|
978
|
+
if (session === null || session.state !== 'live')
|
|
979
|
+
return;
|
|
980
|
+
if (session.abortedBy === undefined)
|
|
981
|
+
session.abortedBy = by;
|
|
876
982
|
}
|
|
877
983
|
/** The id of the dispatch on record, live or settled. */
|
|
878
984
|
currentDispatchId() {
|
|
@@ -903,8 +1009,7 @@ export class TeamRuntime {
|
|
|
903
1009
|
// SNAPSHOT, not a live read: `team.dispatchTimeoutMs` and `team.overseer`
|
|
904
1010
|
// may change mid-dispatch and the ceiling must not move under it.
|
|
905
1011
|
ceilingMs: config.team.overseer ? 0 : config.team.dispatchTimeoutMs,
|
|
906
|
-
|
|
907
|
-
continued: false,
|
|
1012
|
+
stall: null,
|
|
908
1013
|
leadSent: 0,
|
|
909
1014
|
controls: [],
|
|
910
1015
|
handles: [],
|
|
@@ -942,6 +1047,7 @@ export class TeamRuntime {
|
|
|
942
1047
|
this.supervision?.clearAll();
|
|
943
1048
|
this.supervision = null;
|
|
944
1049
|
this.overseer = null;
|
|
1050
|
+
this.stopStallWatch(session);
|
|
945
1051
|
// A held child would leave `waitIfPaused` promises (and their worker slots)
|
|
946
1052
|
// dangling for ever; releasing is what lets every `runOne` reach its exit.
|
|
947
1053
|
session.pauseGate.releaseAll();
|
|
@@ -1212,7 +1318,16 @@ export class TeamRuntime {
|
|
|
1212
1318
|
// a silent risk.
|
|
1213
1319
|
const dispatchCeilingMs = session.ceilingMs;
|
|
1214
1320
|
this.dispatchTimer =
|
|
1215
|
-
dispatchCeilingMs > 0
|
|
1321
|
+
dispatchCeilingMs > 0
|
|
1322
|
+
? setTimeout(() => {
|
|
1323
|
+
this.noteAbortedBy('ceiling');
|
|
1324
|
+
this.abortAll();
|
|
1325
|
+
}, dispatchCeilingMs)
|
|
1326
|
+
: null;
|
|
1327
|
+
// The stall watch exists only for a detached dispatch: a blocking `task` holds the
|
|
1328
|
+
// lead inside the tool call, so there is no idle lead to tell.
|
|
1329
|
+
if (mode === 'detach')
|
|
1330
|
+
this.startStallWatch(session, team.stallSignalMs);
|
|
1216
1331
|
const runCtx = {
|
|
1217
1332
|
dispatchId,
|
|
1218
1333
|
handles,
|
|
@@ -1284,9 +1399,12 @@ export class TeamRuntime {
|
|
|
1284
1399
|
// byte equality is therefore a construction fact, not a promise.
|
|
1285
1400
|
session.outcome = outcome;
|
|
1286
1401
|
session.reportText = buildDispatchReport(outcome, this.deps.reportOptions?.() ?? {});
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1402
|
+
this.emit({
|
|
1403
|
+
type: 'dispatch_end',
|
|
1404
|
+
dispatchId,
|
|
1405
|
+
outcome,
|
|
1406
|
+
...(mode === 'detach' ? { detached: true } : {}),
|
|
1407
|
+
});
|
|
1290
1408
|
return outcome;
|
|
1291
1409
|
}
|
|
1292
1410
|
/** One slot of the pool: take the next index until the list is exhausted. */
|
|
@@ -1403,6 +1521,7 @@ export class TeamRuntime {
|
|
|
1403
1521
|
// the fresh body gets its own cold-start budget.
|
|
1404
1522
|
if (verdict !== null && verdict.action === 'replace' && !this.aborted) {
|
|
1405
1523
|
if (this.replaceChild(dispatchId, handles, index, makeHandle, handle, verdict) === null) {
|
|
1524
|
+
this.noteChildFinal(ctx, index, handle);
|
|
1406
1525
|
return;
|
|
1407
1526
|
}
|
|
1408
1527
|
attempt = 0;
|
|
@@ -1433,10 +1552,13 @@ export class TeamRuntime {
|
|
|
1433
1552
|
await this.maybePostMortem(ctx, index, handle, verdict);
|
|
1434
1553
|
this.supervision?.clear(run.label);
|
|
1435
1554
|
this.monitor?.clear(run.label);
|
|
1555
|
+
this.noteChildFinal(ctx, index, handle);
|
|
1436
1556
|
return;
|
|
1437
1557
|
}
|
|
1438
|
-
if (this.replaceChild(dispatchId, handles, index, makeHandle, handle, null) === null)
|
|
1558
|
+
if (this.replaceChild(dispatchId, handles, index, makeHandle, handle, null) === null) {
|
|
1559
|
+
this.noteChildFinal(ctx, index, handle);
|
|
1439
1560
|
return;
|
|
1561
|
+
}
|
|
1440
1562
|
await this.backoff(TEAM_LIMITS.retryBackoffMs);
|
|
1441
1563
|
if (this.aborted) {
|
|
1442
1564
|
const fresh = handles[index];
|
|
@@ -1447,6 +1569,27 @@ export class TeamRuntime {
|
|
|
1447
1569
|
}
|
|
1448
1570
|
}
|
|
1449
1571
|
}
|
|
1572
|
+
/**
|
|
1573
|
+
* Say, once, that a child FINALLY failed (team-lead-wake-signals 4.4.1).
|
|
1574
|
+
*
|
|
1575
|
+
* `agent_update` with `phase: 'failed'` is not that: the supervisor's post-mortem may
|
|
1576
|
+
* rebuild the child a moment later. So the signal is raised from the three places
|
|
1577
|
+
* where the child's fate is settled - the terminal branch of `runOne` AFTER its
|
|
1578
|
+
* post-mortem, and the two early returns where `replaceChild` could not build a body.
|
|
1579
|
+
*
|
|
1580
|
+
* THE SINGLE `!==` IS THE DEDUPLICATION. `maybePostMortem` recurses into `runOne`,
|
|
1581
|
+
* and the inner frame reaches its own `noteChildFinal` first, with the fresh handle;
|
|
1582
|
+
* when control returns to the outer frame `handles[index]` is no longer ITS handle,
|
|
1583
|
+
* so it stays silent and only the successor reports. `aborted` is not a failure: it
|
|
1584
|
+
* is what a `team_stop` by the lead or the user, and an `abortAll`, produce.
|
|
1585
|
+
*/
|
|
1586
|
+
noteChildFinal(ctx, index, handle) {
|
|
1587
|
+
if (ctx.handles[index] !== handle)
|
|
1588
|
+
return;
|
|
1589
|
+
if (handle.run.phase !== 'failed')
|
|
1590
|
+
return;
|
|
1591
|
+
this.emit({ type: 'child_failed', dispatchId: ctx.dispatchId, run: settledRun(handle.run) });
|
|
1592
|
+
}
|
|
1450
1593
|
/**
|
|
1451
1594
|
* One post-mortem inspection, and possibly ONE replacement driven by a
|
|
1452
1595
|
* recursive `runOne` — the worker that called us has already moved on to the
|
|
@@ -1979,7 +2122,10 @@ export class TeamRuntime {
|
|
|
1979
2122
|
}
|
|
1980
2123
|
/** Process-exit path: abort everything and clear timers (R-15). */
|
|
1981
2124
|
dispose() {
|
|
2125
|
+
this.noteAbortedBy('dispose');
|
|
1982
2126
|
this.abortAll();
|
|
2127
|
+
if (this.session !== null)
|
|
2128
|
+
this.stopStallWatch(this.session);
|
|
1983
2129
|
if (this.dispatchTimer)
|
|
1984
2130
|
clearTimeout(this.dispatchTimer);
|
|
1985
2131
|
this.dispatchTimer = null;
|
|
@@ -2010,8 +2156,81 @@ export class TeamRuntime {
|
|
|
2010
2156
|
...(this.bus?.lastMessage() ? { lastMessage: this.bus.lastMessage() } : {}),
|
|
2011
2157
|
};
|
|
2012
2158
|
}
|
|
2159
|
+
const session = this.session;
|
|
2160
|
+
if (session !== null && session.id === dispatchId && session.stall !== null) {
|
|
2161
|
+
if (session.stall.ledger.observe(copy, Date.now()))
|
|
2162
|
+
this.noteProgress(session, false);
|
|
2163
|
+
}
|
|
2013
2164
|
this.emit({ type: 'agent_update', dispatchId, run: copy });
|
|
2014
2165
|
}
|
|
2166
|
+
// -------------------------------------------------------------------------
|
|
2167
|
+
// The stall watch (team-lead-wake-signals 4.6)
|
|
2168
|
+
// -------------------------------------------------------------------------
|
|
2169
|
+
/** Arm the watch. `quietMs <= 0` is the documented off switch: nothing is created. */
|
|
2170
|
+
startStallWatch(session, quietMs) {
|
|
2171
|
+
if (quietMs <= 0)
|
|
2172
|
+
return;
|
|
2173
|
+
const watch = {
|
|
2174
|
+
ledger: new ProgressLedger(session.startedAt),
|
|
2175
|
+
timer: null,
|
|
2176
|
+
quietMs,
|
|
2177
|
+
episode: 1,
|
|
2178
|
+
episodeSignalled: false,
|
|
2179
|
+
signals: 0,
|
|
2180
|
+
};
|
|
2181
|
+
watch.timer = setInterval(() => this.tickStall(session), TEAM_LIMITS.stallTickMs);
|
|
2182
|
+
// A pending tick must not hold the process open on exit.
|
|
2183
|
+
watch.timer.unref?.();
|
|
2184
|
+
session.stall = watch;
|
|
2185
|
+
}
|
|
2186
|
+
stopStallWatch(session) {
|
|
2187
|
+
const watch = session.stall;
|
|
2188
|
+
if (watch === null)
|
|
2189
|
+
return;
|
|
2190
|
+
if (watch.timer !== null)
|
|
2191
|
+
clearInterval(watch.timer);
|
|
2192
|
+
watch.timer = null;
|
|
2193
|
+
session.stall = null;
|
|
2194
|
+
}
|
|
2195
|
+
/**
|
|
2196
|
+
* Real progress closes the current stall episode, so the NEXT quiet spell can raise
|
|
2197
|
+
* its own signal. `touched` is the lead's own activity, which the ledger has to be
|
|
2198
|
+
* told about directly (nothing is published for it).
|
|
2199
|
+
*/
|
|
2200
|
+
noteProgress(session, touched) {
|
|
2201
|
+
const watch = session.stall;
|
|
2202
|
+
if (watch === null)
|
|
2203
|
+
return;
|
|
2204
|
+
if (touched)
|
|
2205
|
+
watch.ledger.touch(Date.now());
|
|
2206
|
+
if (!watch.episodeSignalled)
|
|
2207
|
+
return;
|
|
2208
|
+
watch.episode += 1;
|
|
2209
|
+
watch.episodeSignalled = false;
|
|
2210
|
+
}
|
|
2211
|
+
tickStall(session) {
|
|
2212
|
+
const watch = session.stall;
|
|
2213
|
+
if (watch === null || session.state !== 'live' || session.outcome !== undefined)
|
|
2214
|
+
return;
|
|
2215
|
+
if (watch.episodeSignalled || watch.signals >= TEAM_LIMITS.stallEpisodesPerDispatch)
|
|
2216
|
+
return;
|
|
2217
|
+
const verdict = this.stallVerdict(session, watch);
|
|
2218
|
+
if (!verdict.stalled)
|
|
2219
|
+
return;
|
|
2220
|
+
watch.episodeSignalled = true;
|
|
2221
|
+
watch.signals += 1;
|
|
2222
|
+
this.emit({
|
|
2223
|
+
type: 'stalled',
|
|
2224
|
+
dispatchId: session.id,
|
|
2225
|
+
episode: watch.episode,
|
|
2226
|
+
since: verdict.since,
|
|
2227
|
+
quietMs: verdict.quietMs,
|
|
2228
|
+
blockers: verdict.blockers,
|
|
2229
|
+
});
|
|
2230
|
+
}
|
|
2231
|
+
stallVerdict(session, watch) {
|
|
2232
|
+
return watch.ledger.verdict(session.handles.map((handle) => handle.run), (label) => session.pauseGate.holderOf(label), Date.now(), watch.quietMs);
|
|
2233
|
+
}
|
|
2015
2234
|
emit(event) {
|
|
2016
2235
|
for (const listener of [...this.listeners]) {
|
|
2017
2236
|
try {
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ProgressLedger / stall verdict - "is anybody on the team doing real work?"
|
|
3
|
+
* (team-lead-wake-signals section 4.6).
|
|
4
|
+
*
|
|
5
|
+
* ASCII ONLY: `src/team/**` is inside `glyphs.test.ts`'s static scan.
|
|
6
|
+
*
|
|
7
|
+
* PURE: no timers, no I/O, no model. The runtime owns the tick and feeds this
|
|
8
|
+
* object; this object only remembers and judges. That split is what lets the
|
|
9
|
+
* judgement be tested with a hand-written clock.
|
|
10
|
+
*
|
|
11
|
+
* WHAT COUNTS AS WORK, AND WHY IT IS A COUNT AND NOT A PHASE SAMPLE. A child that
|
|
12
|
+
* loops on `team_wait` passes through `waiting -> thinking -> waiting` every few
|
|
13
|
+
* seconds; sampling the phase would see `thinking` often enough to reset a "quiet
|
|
14
|
+
* since" clock forever and the team would never be called stalled. What a stalled
|
|
15
|
+
* team has in common is that nothing it does changes the world: so progress is
|
|
16
|
+
* "a tool call that is not `team_wait` / `team_send`", "a child reaching a terminal
|
|
17
|
+
* phase", or an intervention by the lead (resume, spawn, message).
|
|
18
|
+
*
|
|
19
|
+
* WHAT A LONG-RUNNING TOOL IS: work. A `bash` that has been silent for ten minutes
|
|
20
|
+
* is `phase === 'tool'` with a non-communication `lastTool`, and that is "in
|
|
21
|
+
* flight", not "blocked". Telling the lead the team has stalled because a build
|
|
22
|
+
* takes a while would be the worst false positive this feature could have; silence
|
|
23
|
+
* during real work is the supervisor's job (its own ladder), not this one's.
|
|
24
|
+
*/
|
|
25
|
+
import type { StallBlocker, SubagentRun, TeamControlBy } from '@aragon-agent/tui/model/team/types';
|
|
26
|
+
export type StallVerdict = {
|
|
27
|
+
stalled: false;
|
|
28
|
+
} | {
|
|
29
|
+
stalled: true;
|
|
30
|
+
since: number;
|
|
31
|
+
quietMs: number;
|
|
32
|
+
blockers: StallBlocker[];
|
|
33
|
+
};
|
|
34
|
+
export declare class ProgressLedger {
|
|
35
|
+
private lastProgressAt;
|
|
36
|
+
private readonly seen;
|
|
37
|
+
constructor(startedAt: number);
|
|
38
|
+
/**
|
|
39
|
+
* Fold one published run in. Returns TRUE when it was progress, so the runtime can
|
|
40
|
+
* close the current stall episode.
|
|
41
|
+
*/
|
|
42
|
+
observe(run: SubagentRun, now: number): boolean;
|
|
43
|
+
/** The lead stepped in (resume / spawn / message): that is activity by definition. */
|
|
44
|
+
touch(now: number): void;
|
|
45
|
+
/** Epoch ms of the last real progress. */
|
|
46
|
+
lastProgress(): number;
|
|
47
|
+
/**
|
|
48
|
+
* `stalled` iff somebody is blocked, nobody is working, and it has been that way
|
|
49
|
+
* for `quietMs`. A child the USER paused is neither working nor blocked: they
|
|
50
|
+
* asked for it to stop, and waking the lead about that would be noise.
|
|
51
|
+
*/
|
|
52
|
+
verdict(runs: readonly SubagentRun[], pausedBy: (label: string) => TeamControlBy | undefined, now: number, quietMs: number): StallVerdict;
|
|
53
|
+
private blockerOf;
|
|
54
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ProgressLedger / stall verdict - "is anybody on the team doing real work?"
|
|
3
|
+
* (team-lead-wake-signals section 4.6).
|
|
4
|
+
*
|
|
5
|
+
* ASCII ONLY: `src/team/**` is inside `glyphs.test.ts`'s static scan.
|
|
6
|
+
*
|
|
7
|
+
* PURE: no timers, no I/O, no model. The runtime owns the tick and feeds this
|
|
8
|
+
* object; this object only remembers and judges. That split is what lets the
|
|
9
|
+
* judgement be tested with a hand-written clock.
|
|
10
|
+
*
|
|
11
|
+
* WHAT COUNTS AS WORK, AND WHY IT IS A COUNT AND NOT A PHASE SAMPLE. A child that
|
|
12
|
+
* loops on `team_wait` passes through `waiting -> thinking -> waiting` every few
|
|
13
|
+
* seconds; sampling the phase would see `thinking` often enough to reset a "quiet
|
|
14
|
+
* since" clock forever and the team would never be called stalled. What a stalled
|
|
15
|
+
* team has in common is that nothing it does changes the world: so progress is
|
|
16
|
+
* "a tool call that is not `team_wait` / `team_send`", "a child reaching a terminal
|
|
17
|
+
* phase", or an intervention by the lead (resume, spawn, message).
|
|
18
|
+
*
|
|
19
|
+
* WHAT A LONG-RUNNING TOOL IS: work. A `bash` that has been silent for ten minutes
|
|
20
|
+
* is `phase === 'tool'` with a non-communication `lastTool`, and that is "in
|
|
21
|
+
* flight", not "blocked". Telling the lead the team has stalled because a build
|
|
22
|
+
* takes a while would be the worst false positive this feature could have; silence
|
|
23
|
+
* during real work is the supervisor's job (its own ladder), not this one's.
|
|
24
|
+
*/
|
|
25
|
+
/** The two tools a child uses to talk to peers. Calling them is not work. */
|
|
26
|
+
const COMM_TOOLS = new Set(['team_wait', 'team_send']);
|
|
27
|
+
function isTerminal(phase) {
|
|
28
|
+
return phase === 'done' || phase === 'failed' || phase === 'aborted';
|
|
29
|
+
}
|
|
30
|
+
/** Whether `run` is doing something real RIGHT NOW (an LLM request, or a non-comm tool). */
|
|
31
|
+
function isInFlightWork(run) {
|
|
32
|
+
if (run.phase === 'starting' || run.phase === 'thinking')
|
|
33
|
+
return true;
|
|
34
|
+
if (run.phase !== 'tool')
|
|
35
|
+
return false;
|
|
36
|
+
return run.lastTool === undefined || !COMM_TOOLS.has(run.lastTool);
|
|
37
|
+
}
|
|
38
|
+
export class ProgressLedger {
|
|
39
|
+
lastProgressAt;
|
|
40
|
+
seen = new Map();
|
|
41
|
+
constructor(startedAt) {
|
|
42
|
+
this.lastProgressAt = startedAt;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Fold one published run in. Returns TRUE when it was progress, so the runtime can
|
|
46
|
+
* close the current stall episode.
|
|
47
|
+
*/
|
|
48
|
+
observe(run, now) {
|
|
49
|
+
const before = this.seen.get(run.label);
|
|
50
|
+
const terminal = isTerminal(run.phase);
|
|
51
|
+
let progress = false;
|
|
52
|
+
if (before === undefined) {
|
|
53
|
+
progress = terminal;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const moreCalls = run.toolCalls > before.toolCalls;
|
|
57
|
+
const realTool = run.lastTool === undefined || !COMM_TOOLS.has(run.lastTool);
|
|
58
|
+
// A counter that went BACKWARDS is a rebuilt body (supervisor replace / cold-start
|
|
59
|
+
// retry): somebody just started the work over, which is the opposite of a stall.
|
|
60
|
+
const rebuilt = run.toolCalls < before.toolCalls;
|
|
61
|
+
progress = (moreCalls && realTool) || (terminal && !before.terminal) || rebuilt;
|
|
62
|
+
}
|
|
63
|
+
this.seen.set(run.label, {
|
|
64
|
+
toolCalls: run.toolCalls,
|
|
65
|
+
terminal,
|
|
66
|
+
phase: run.phase,
|
|
67
|
+
since: before !== undefined && before.phase === run.phase ? before.since : now,
|
|
68
|
+
});
|
|
69
|
+
if (progress)
|
|
70
|
+
this.lastProgressAt = now;
|
|
71
|
+
return progress;
|
|
72
|
+
}
|
|
73
|
+
/** The lead stepped in (resume / spawn / message): that is activity by definition. */
|
|
74
|
+
touch(now) {
|
|
75
|
+
this.lastProgressAt = now;
|
|
76
|
+
}
|
|
77
|
+
/** Epoch ms of the last real progress. */
|
|
78
|
+
lastProgress() {
|
|
79
|
+
return this.lastProgressAt;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* `stalled` iff somebody is blocked, nobody is working, and it has been that way
|
|
83
|
+
* for `quietMs`. A child the USER paused is neither working nor blocked: they
|
|
84
|
+
* asked for it to stop, and waking the lead about that would be noise.
|
|
85
|
+
*/
|
|
86
|
+
verdict(runs, pausedBy, now, quietMs) {
|
|
87
|
+
const open = runs.filter((run) => !isTerminal(run.phase));
|
|
88
|
+
if (open.length === 0)
|
|
89
|
+
return { stalled: false };
|
|
90
|
+
if (open.some((run) => isInFlightWork(run)))
|
|
91
|
+
return { stalled: false };
|
|
92
|
+
const blockers = [];
|
|
93
|
+
for (const run of open) {
|
|
94
|
+
const blocker = this.blockerOf(run, pausedBy(run.label), now);
|
|
95
|
+
if (blocker !== null)
|
|
96
|
+
blockers.push(blocker);
|
|
97
|
+
}
|
|
98
|
+
if (blockers.length === 0)
|
|
99
|
+
return { stalled: false };
|
|
100
|
+
const quiet = now - this.lastProgressAt;
|
|
101
|
+
if (quiet < quietMs)
|
|
102
|
+
return { stalled: false };
|
|
103
|
+
return { stalled: true, since: this.lastProgressAt, quietMs: quiet, blockers };
|
|
104
|
+
}
|
|
105
|
+
blockerOf(run, by, now) {
|
|
106
|
+
const since = this.seen.get(run.label)?.since ?? this.lastProgressAt;
|
|
107
|
+
const ms = Math.max(0, now - since);
|
|
108
|
+
if (run.phase === 'waiting')
|
|
109
|
+
return { label: run.label, state: 'waiting', ms };
|
|
110
|
+
if (run.phase === 'queued')
|
|
111
|
+
return { label: run.label, state: 'queued', ms };
|
|
112
|
+
if (run.phase === 'paused') {
|
|
113
|
+
if (by === 'user')
|
|
114
|
+
return null;
|
|
115
|
+
return { label: run.label, state: 'paused', ms, ...(by !== undefined ? { by } : {}) };
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
}
|
package/dist/team/task-tool.js
CHANGED
|
@@ -183,8 +183,8 @@ export function describeDispatchStarted(handle, options = {}) {
|
|
|
183
183
|
: '';
|
|
184
184
|
const tools = TEAM_CONSOLE_TOOL_NAMES.join(' / ');
|
|
185
185
|
return (`Dispatch ${handle.dispatchId} STARTED, not finished. Subagents: ${who}.${truncated}\n` +
|
|
186
|
-
'
|
|
187
|
-
'
|
|
186
|
+
'A team_signal wakes you when the team ends, a child fails or it stalls; what you do then ' +
|
|
187
|
+
'is your call.\n' +
|
|
188
188
|
'DO NOT WAIT. You are free now: answer the user, do other work, and treat any new message ' +
|
|
189
189
|
`from them as a normal turn rather than something to queue behind the team.\n` +
|
|
190
190
|
`You control the team with: ${tools}.\n` +
|