@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
package/dist/agent/controller.js
CHANGED
|
@@ -11,6 +11,8 @@ import { buildImageInputBlock } from './image-input-prompt.js';
|
|
|
11
11
|
import { isImageCapabilityRefusal } from '@aragon-agent/tui/model/agent/image-refusal';
|
|
12
12
|
import { Agent, IMAGE_TOKEN_ESTIMATE, initProviders, ModelRegistry, } from '@aragon-agent/core';
|
|
13
13
|
import { clampCompactionConfig, clampFastConfig, clampRetryConfig, clampGeneConfig, clampMemoryConfig, clampTeamConfig, clampTodoConfig, isAdapterProvider, toRetryPolicy, } from '@aragon-agent/tui/model/config/schema';
|
|
14
|
+
import { resolveEscalationPolicy } from '@aragon-agent/tui/model/config/reconnect';
|
|
15
|
+
import { ReconnectMemory } from './reconnect-memory.js';
|
|
14
16
|
import { resolveModelProfileState } from '@aragon-agent/tui/model/config/model-profile-resolution';
|
|
15
17
|
import { makeGetApiKey } from '../config/load.js';
|
|
16
18
|
import { updatePersistedConfig } from '../config/store.js';
|
|
@@ -24,8 +26,9 @@ import { TeamHumanQueue } from '../team/human-queue.js';
|
|
|
24
26
|
import { createFastOverseerProvider } from '../team/overseer.js';
|
|
25
27
|
import { createTaskTool } from '../team/task-tool.js';
|
|
26
28
|
import { createConsoleTools } from '../team/console-tools.js';
|
|
27
|
-
import { TeamNoticeQueue } from '../team/notices.js';
|
|
29
|
+
import { TeamNoticeQueue, attentionFactOf, firstLine, settleFactsOf, } from '../team/notices.js';
|
|
28
30
|
import { TeamNoticeRelay } from './team-notices.js';
|
|
31
|
+
import { TeamWakeGovernor, } from '../team/wake.js';
|
|
29
32
|
import { buildDispatchReport } from '../team/report.js';
|
|
30
33
|
import { renderPauseResult, renderResumeResult, renderSendResult, renderSpawnResult, renderStopResult, } from '../team/console-view.js';
|
|
31
34
|
import { splitBriefIntoSpecs } from '../team/normalize.js';
|
|
@@ -445,6 +448,53 @@ export class AgentController {
|
|
|
445
448
|
* answer cannot change between the tool array and the prompt that describes it.
|
|
446
449
|
*/
|
|
447
450
|
toolImagesEnabled = process.env.ARAGON_TOOL_IMAGES !== '0';
|
|
451
|
+
/**
|
|
452
|
+
* Which host this controller serves, for the ladder's SHAPE only
|
|
453
|
+
* (tiered-reconnect §4.4). Read once, at construction: a session does not change
|
|
454
|
+
* hosts, and a value that could change mid-run would make "two tiers" mean
|
|
455
|
+
* different things in two requests of one conversation.
|
|
456
|
+
*/
|
|
457
|
+
reconnectMode;
|
|
458
|
+
/**
|
|
459
|
+
* Which tier the last request recovered in (tiered-reconnect §4.9), so the NEXT
|
|
460
|
+
* request does not spend four minutes re-learning that the fast ladder is not
|
|
461
|
+
* working. Process-local, read only when `retry.stickyRung` is on.
|
|
462
|
+
*/
|
|
463
|
+
reconnectMemory = new ReconnectMemory();
|
|
464
|
+
/** The tier the CURRENT request is retrying in; 1 until an escalation happens. */
|
|
465
|
+
retryTierThisRun = 1;
|
|
466
|
+
/**
|
|
467
|
+
* The provider/model pair a sticky memory belongs to (tiered-reconnect §4.9).
|
|
468
|
+
* Comparing it is what makes a switch of model invalidate the memory instead of
|
|
469
|
+
* starting the new model at the old model's tier.
|
|
470
|
+
*/
|
|
471
|
+
currentModelRef() {
|
|
472
|
+
return { providerId: this.config.provider, modelId: this.config.model };
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Follow the ladder one stream event at a time, so a RECOVERY knows which tier it
|
|
476
|
+
* happened in (tiered-reconnect §4.9).
|
|
477
|
+
*
|
|
478
|
+
* CORE SENDS NO "recovered" EVENT — a successful request simply ends in `done` —
|
|
479
|
+
* so the tier of a recovery has to be remembered from the last `retry_scheduled`
|
|
480
|
+
* of the same request. That is the same derivation the reducer uses for its
|
|
481
|
+
* card, done here because the sticky memory belongs to the process, not to a view.
|
|
482
|
+
*/
|
|
483
|
+
observeRetryTier(event) {
|
|
484
|
+
if (event.type === 'retry_scheduled') {
|
|
485
|
+
if (event.tier !== undefined)
|
|
486
|
+
this.retryTierThisRun = event.tier;
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
if (event.type !== 'done')
|
|
490
|
+
return;
|
|
491
|
+
// `stickyRung` off means nobody asked for a memory, so nothing is recorded: a
|
|
492
|
+
// session that never flips the switch pays nothing for this feature.
|
|
493
|
+
if (!this.config.retry.stickyRung)
|
|
494
|
+
return;
|
|
495
|
+
this.reconnectMemory.recordRecovery(this.currentModelRef(), this.retryTierThisRun);
|
|
496
|
+
this.retryTierThisRun = 1;
|
|
497
|
+
}
|
|
448
498
|
/**
|
|
449
499
|
* What the CURRENT prompt's `<image_input>` block was written for: the model and the support
|
|
450
500
|
* answer together (`provider/model:support`). The block names the model, so a switch between
|
|
@@ -478,6 +528,22 @@ export class AgentController {
|
|
|
478
528
|
*/
|
|
479
529
|
teamNotices = new TeamNoticeQueue();
|
|
480
530
|
teamRelay;
|
|
531
|
+
/**
|
|
532
|
+
* The wake governor (team-lead-wake-signals): "the team needs the lead - is now the
|
|
533
|
+
* moment to start a turn?". Level-triggered over the relay's ledger, so a dispatch
|
|
534
|
+
* that ends while the lead is idle still wakes it. Built next to the relay.
|
|
535
|
+
*/
|
|
536
|
+
teamWake;
|
|
537
|
+
/** Dispatches started DETACHED; only these produce notices and wakes (I-WK3). */
|
|
538
|
+
detachedDispatches = new Set();
|
|
539
|
+
/**
|
|
540
|
+
* `prompt()` / `continue()` calls between entry and exit. The engine's own
|
|
541
|
+
* `isRunning()` is false for the whole `gene.planForTurn` await, but a turn is
|
|
542
|
+
* certainly starting then; the governor must not start a second one (RV-P2-10).
|
|
543
|
+
*/
|
|
544
|
+
promptInFlight = 0;
|
|
545
|
+
/** Distinguishes one notice steer's receipt id from the next. */
|
|
546
|
+
noticeSequence = 0;
|
|
481
547
|
/**
|
|
482
548
|
* The monotonic turn counter behind `I-DD11`.
|
|
483
549
|
*
|
|
@@ -544,6 +610,9 @@ export class AgentController {
|
|
|
544
610
|
this.todoRegistered = config.todo.enabled;
|
|
545
611
|
this.todoEnabled = config.todo.enabled;
|
|
546
612
|
this.todoPanelCapable = deps.todoPanelCapable === true;
|
|
613
|
+
// Default `'interactive'`: a host that never heard of this dep keeps the full
|
|
614
|
+
// ladder, which is what the TUI and the desktop both want.
|
|
615
|
+
this.reconnectMode = deps.reconnectMode === 'headless' ? 'headless' : 'interactive';
|
|
547
616
|
this.todos = this.todoRegistered
|
|
548
617
|
? new TodoStore(Date.now, () => this.isTodoAcceptanceEnabled())
|
|
549
618
|
: null;
|
|
@@ -737,12 +806,10 @@ export class AgentController {
|
|
|
737
806
|
...(confirm ? { humanQueue: new TeamHumanQueue(confirm) } : {}),
|
|
738
807
|
// THE DETACHED-DISPATCH WIRING (team-detached-dispatch section 5.1).
|
|
739
808
|
//
|
|
740
|
-
// `currentTurnId`
|
|
741
|
-
//
|
|
742
|
-
//
|
|
743
|
-
// 100-minute dispatch alone".
|
|
809
|
+
// `currentTurnId` is what makes `I-DD11` possible: a dispatch remembers the
|
|
810
|
+
// turn that started it, so `stopEngine()` can tell "stop my own turn and its
|
|
811
|
+
// team" from "stop an unrelated turn and leave a 100-minute dispatch alone".
|
|
744
812
|
currentTurnId: () => this.turnId,
|
|
745
|
-
isLeadRunning: () => this.agent.state.isRunning,
|
|
746
813
|
// THE REPORT'S ONE PRODUCER (REV-05). The SAME closure is handed to
|
|
747
814
|
// `createTaskTool` below, so the await path and the detach path price a
|
|
748
815
|
// dispatch identically - one table, one disclosure line.
|
|
@@ -881,9 +948,41 @@ export class AgentController {
|
|
|
881
948
|
// `noticeSteer` and it is not silenced by any config key.
|
|
882
949
|
this.teamRelay = new TeamNoticeRelay({
|
|
883
950
|
queue: this.teamNotices,
|
|
884
|
-
|
|
951
|
+
// THE RECEIPT-CARRYING STEER (team-lead-wake-signals I-WK6): Core echoes
|
|
952
|
+
// `steering_accepted` only for a steer that has an id, so the ledger can be
|
|
953
|
+
// released per steer instead of "any receipt frees everything".
|
|
954
|
+
steer: (text) => this.enqueueSteering(text, false, undefined, true),
|
|
955
|
+
withdraw: (receiptId) => this.agent.removeQueuedSteering(receiptId),
|
|
885
956
|
isAtSafeSteerPoint: () => this.isAtSafeSteerPoint(),
|
|
886
|
-
|
|
957
|
+
// `abortRequested` is set by `stopEngine()` and cleared only at the next
|
|
958
|
+
// `agent_start` - which is AFTER this check runs. Alone it would refuse the
|
|
959
|
+
// fill for the first turn after any Esc, the wake turn included. It only means
|
|
960
|
+
// something while the engine is still running (RV-P1-5).
|
|
961
|
+
canSteerBeforeTurn: () => this.activeToolCalls === 0 && (!this.abortRequested || !this.isRunning()),
|
|
962
|
+
});
|
|
963
|
+
this.teamWake = new TeamWakeGovernor({
|
|
964
|
+
owed: () => this.owedAttention(),
|
|
965
|
+
reclaimStranded: () => this.teamRelay?.requeueUndelivered(),
|
|
966
|
+
config: () => ({
|
|
967
|
+
autoResume: this.config.team.autoResume,
|
|
968
|
+
settleGraceMs: this.config.team.settleGraceMs,
|
|
969
|
+
}),
|
|
970
|
+
leadFacts: () => ({
|
|
971
|
+
running: this.isRunning() || this.promptInFlight > 0,
|
|
972
|
+
compacting: this.isCompactionBusy(),
|
|
973
|
+
userPending: this.hasPendingUserMessages(),
|
|
974
|
+
}),
|
|
975
|
+
now: () => Date.now(),
|
|
976
|
+
setTimer: (fn, ms) => {
|
|
977
|
+
const timer = setTimeout(fn, ms);
|
|
978
|
+
timer.unref?.();
|
|
979
|
+
return () => clearTimeout(timer);
|
|
980
|
+
},
|
|
981
|
+
setImmediate: (fn) => {
|
|
982
|
+
setImmediate(fn);
|
|
983
|
+
},
|
|
984
|
+
log: (level, event, fields) => getLogger()[level]('agent', event, fields),
|
|
985
|
+
notifyHost: (level, text) => this.notifyHostFn?.(level, text),
|
|
887
986
|
});
|
|
888
987
|
// The SOURCE is the runtime's own event stream: `child_settled` /
|
|
889
988
|
// `dispatch_settled` / `lead_mail` are all derived here, once, so the notices
|
|
@@ -1130,6 +1229,11 @@ export class AgentController {
|
|
|
1130
1229
|
...createConsoleTools({
|
|
1131
1230
|
runtime: this.teamRuntime,
|
|
1132
1231
|
hasPendingUserInput: () => this.hasPendingUserMessages(),
|
|
1232
|
+
// `team_collect` returning the report must not leave a copy to be
|
|
1233
|
+
// delivered again, and a signal that arrives while it waits must end the
|
|
1234
|
+
// wait (team-lead-wake-signals 4.8).
|
|
1235
|
+
acknowledgeSettle: (dispatchId) => this.acknowledgeTeamSettle(dispatchId),
|
|
1236
|
+
hasPendingTeamAttention: () => this.hasPendingTeamAttention(),
|
|
1133
1237
|
}),
|
|
1134
1238
|
]
|
|
1135
1239
|
: [],
|
|
@@ -1329,6 +1433,32 @@ export class AgentController {
|
|
|
1329
1433
|
...(this.governance.isRegistered() ? { gov_dispatch: 0 } : {}),
|
|
1330
1434
|
},
|
|
1331
1435
|
},
|
|
1436
|
+
// TIERED RECONNECT (tiered-reconnect §4.4). THE ONLY PLACE IN THE WHOLE
|
|
1437
|
+
// REPOSITORY THAT WRITES THIS FIELD (AC-12 pins it with a source scan, and
|
|
1438
|
+
// `team/subagent.ts` is asserted to have neither this nor `retryEscalation`).
|
|
1439
|
+
//
|
|
1440
|
+
// A CLOSURE, NOT A VALUE, and that is the difference from `setRetryPolicy`
|
|
1441
|
+
// next door: the tier-1 policy is pushed twice because it is a VALUE the
|
|
1442
|
+
// registry stores, while this is a FUNCTION the engine calls once per run, so
|
|
1443
|
+
// `/retry reconnect off` takes effect on the next request with no restart and
|
|
1444
|
+
// no second push.
|
|
1445
|
+
//
|
|
1446
|
+
// `deps.reconnectMode === 'headless'` is what makes `-p` / `exec` bounded by
|
|
1447
|
+
// default: two tiers, because nobody is there to press Esc.
|
|
1448
|
+
resolveEscalation: () => {
|
|
1449
|
+
const policy = resolveEscalationPolicy(this.config.retry, {
|
|
1450
|
+
headless: this.reconnectMode === 'headless',
|
|
1451
|
+
});
|
|
1452
|
+
if (policy === null)
|
|
1453
|
+
return null;
|
|
1454
|
+
// STICKY START TIER (§4.9). Off by default, and its absence is what makes a
|
|
1455
|
+
// session that never turns it on byte-identical to one without the feature:
|
|
1456
|
+
// `startRung === undefined` means "begin at tier 1", which is the default.
|
|
1457
|
+
const startRung = this.config.retry.stickyRung
|
|
1458
|
+
? this.reconnectMemory.startRungFor(this.currentModelRef())
|
|
1459
|
+
: undefined;
|
|
1460
|
+
return startRung === undefined ? { policy } : { policy, startRung };
|
|
1461
|
+
},
|
|
1332
1462
|
});
|
|
1333
1463
|
// --- Context compaction, part 2: AFTER the Agent exists -----------------
|
|
1334
1464
|
//
|
|
@@ -1382,8 +1512,12 @@ export class AgentController {
|
|
|
1382
1512
|
// The Gene Bank's feed (learner ledger, usage, evaluation). Never throws.
|
|
1383
1513
|
// `abortRequested` is still in force here: it is cleared at the NEXT `agent_start`.
|
|
1384
1514
|
this.gene?.onAgentEvent(event, this.abortRequested);
|
|
1385
|
-
if (event.type === 'agent_start')
|
|
1515
|
+
if (event.type === 'agent_start') {
|
|
1386
1516
|
this.abortRequested = false;
|
|
1517
|
+
this.retryTierThisRun = 1;
|
|
1518
|
+
}
|
|
1519
|
+
if (event.type === 'message_update')
|
|
1520
|
+
this.observeRetryTier(event.streamEvent);
|
|
1387
1521
|
if (event.type === 'message_update' && event.streamEvent.type === 'error') {
|
|
1388
1522
|
this.learnImageRefusal(event.streamEvent.error);
|
|
1389
1523
|
}
|
|
@@ -1393,9 +1527,12 @@ export class AgentController {
|
|
|
1393
1527
|
// A receipt means Core took a batch out of the queue, which is the only
|
|
1394
1528
|
// proof a steered notice has that it was not discarded (§4.6.1).
|
|
1395
1529
|
this.jobRelay?.onSteeringAccepted();
|
|
1396
|
-
// The team relay needs the SAME proof
|
|
1397
|
-
//
|
|
1398
|
-
|
|
1530
|
+
// The team relay needs the SAME proof, but per steer: only the notices a
|
|
1531
|
+
// receipted steer carried are delivered. A delivered attention notice shrinks
|
|
1532
|
+
// what the lead is owed, so the governor looks again (and stops its retry beat).
|
|
1533
|
+
const delivered = this.teamRelay?.onSteeringAccepted(event.ids) ?? [];
|
|
1534
|
+
if (delivered.length > 0)
|
|
1535
|
+
this.teamWake?.poke();
|
|
1399
1536
|
}
|
|
1400
1537
|
// THE BATCH COUNTER (D-5 / I-5). Decremented BEFORE the push attempt below,
|
|
1401
1538
|
// because "the batch is empty" is only true after the last one has ended.
|
|
@@ -1440,6 +1577,11 @@ export class AgentController {
|
|
|
1440
1577
|
// covers a run that ended with a notice stranded in the queue.
|
|
1441
1578
|
this.jobRelay?.requeueUndelivered();
|
|
1442
1579
|
this.teamRelay?.requeueUndelivered();
|
|
1580
|
+
// THE LEAD IS IDLE AGAIN: whatever the team still owes it is now collectable.
|
|
1581
|
+
// After the requeue (so stranded notices are back in the queue the governor
|
|
1582
|
+
// reads). `abortRequested` is still in force here - it clears at the NEXT
|
|
1583
|
+
// `agent_start` - and is exactly "the user stopped this turn" (I-WK8).
|
|
1584
|
+
this.teamWake?.onLeadIdle({ aborted: this.abortRequested });
|
|
1443
1585
|
// AFTER the requeue, so a turn that ends with a stranded notice still gets
|
|
1444
1586
|
// its feedback line. Order between the two is otherwise irrelevant.
|
|
1445
1587
|
this.maybeReportSkillTriage();
|
|
@@ -1781,6 +1923,7 @@ export class AgentController {
|
|
|
1781
1923
|
if (this.modelMetadataEnabled)
|
|
1782
1924
|
void this.refreshModelMetadata();
|
|
1783
1925
|
const request = ++this.startupSequence;
|
|
1926
|
+
this.promptInFlight += 1;
|
|
1784
1927
|
try {
|
|
1785
1928
|
if (this.agent.state.isRunning) {
|
|
1786
1929
|
this.stopEngine();
|
|
@@ -1809,6 +1952,9 @@ export class AgentController {
|
|
|
1809
1952
|
this.notifyHostFn?.('error', `Could not start the run: ${reason}`);
|
|
1810
1953
|
return { status: 'not-started', reason: 'failed' };
|
|
1811
1954
|
}
|
|
1955
|
+
finally {
|
|
1956
|
+
this.promptInFlight -= 1;
|
|
1957
|
+
}
|
|
1812
1958
|
}
|
|
1813
1959
|
/**
|
|
1814
1960
|
* Wait for the engine to unwind, bounded.
|
|
@@ -1956,6 +2102,10 @@ export class AgentController {
|
|
|
1956
2102
|
// what the Esc ladder's second press and `/team stop all` call.
|
|
1957
2103
|
const live = this.teamRuntime?.live() ?? null;
|
|
1958
2104
|
if (live === null || live.turnId === this.turnId) {
|
|
2105
|
+
// The user ended this team on purpose; the settle that follows is not news to them
|
|
2106
|
+
// and must not wake the lead for it (I-WK11).
|
|
2107
|
+
if (live !== null)
|
|
2108
|
+
this.teamRuntime?.noteAbortedBy('user');
|
|
1959
2109
|
this.teamRuntime?.abortAll();
|
|
1960
2110
|
}
|
|
1961
2111
|
}
|
|
@@ -2076,12 +2226,25 @@ export class AgentController {
|
|
|
2076
2226
|
queueUserMessage(text, parts) {
|
|
2077
2227
|
return this.enqueueSteering(text, true, parts);
|
|
2078
2228
|
}
|
|
2079
|
-
|
|
2229
|
+
/**
|
|
2230
|
+
* `receipt` (notices only, team-lead-wake-signals) asks for an id WITHOUT making the
|
|
2231
|
+
* steer a user message: Core echoes `steering_accepted` for any steer that has one,
|
|
2232
|
+
* and the team relay needs that echo. It is deliberately NOT written to
|
|
2233
|
+
* `pendingUserSteering` - `hasPendingUserMessages()`, `withdrawQueuedUserMessage()`,
|
|
2234
|
+
* `continue()` and `fast`'s `userSteerCount` all read that map and mean "the user is
|
|
2235
|
+
* waiting for an answer". The `notice:` prefix keeps every other receipt consumer
|
|
2236
|
+
* treating it as an unknown id.
|
|
2237
|
+
*/
|
|
2238
|
+
enqueueSteering(text, user, parts, receipt) {
|
|
2080
2239
|
// Both reviewer and user guidance can activate queued skill frames.
|
|
2081
2240
|
if (this.skillsEnabled && this.isRunning())
|
|
2082
2241
|
this.skills.absorbPendingFrames();
|
|
2083
|
-
const id = user
|
|
2084
|
-
|
|
2242
|
+
const id = user
|
|
2243
|
+
? `${this.steeringPrefix}:${++this.steeringSequence}`
|
|
2244
|
+
: receipt === true
|
|
2245
|
+
? `notice:${this.steeringPrefix}:${++this.noticeSequence}`
|
|
2246
|
+
: undefined;
|
|
2247
|
+
if (user && id !== undefined)
|
|
2085
2248
|
this.pendingUserSteering.set(id, text);
|
|
2086
2249
|
try {
|
|
2087
2250
|
// The legacy two-argument call is kept verbatim when there are no parts.
|
|
@@ -2091,7 +2254,7 @@ export class AgentController {
|
|
|
2091
2254
|
this.agent.steer(text, id);
|
|
2092
2255
|
}
|
|
2093
2256
|
catch (error) {
|
|
2094
|
-
if (id !== undefined)
|
|
2257
|
+
if (user && id !== undefined)
|
|
2095
2258
|
this.pendingUserSteering.delete(id);
|
|
2096
2259
|
throw error;
|
|
2097
2260
|
}
|
|
@@ -2133,20 +2296,28 @@ export class AgentController {
|
|
|
2133
2296
|
if (this.modelSettingsBlocked || this.isRunning()) {
|
|
2134
2297
|
return { status: 'not-started', reason: 'failed' };
|
|
2135
2298
|
}
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2299
|
+
this.promptInFlight += 1;
|
|
2300
|
+
try {
|
|
2301
|
+
if (this.pendingUserSteering.size > 0) {
|
|
2302
|
+
const request = ++this.startupSequence;
|
|
2303
|
+
this.prepareUserTurn([...this.pendingUserSteering.values()].join('\n\n'), {
|
|
2304
|
+
steering: true,
|
|
2305
|
+
});
|
|
2306
|
+
if (request !== this.startupSequence) {
|
|
2307
|
+
return { status: 'not-started', reason: 'cancelled' };
|
|
2308
|
+
}
|
|
2309
|
+
this.todos?.beginUserTurn('new-task');
|
|
2141
2310
|
}
|
|
2142
|
-
|
|
2311
|
+
// The `continue()` path needs its own delivery for the reason RV-P1-7 gives:
|
|
2312
|
+
// a run that ended with a notice still queued resumes through here, and this
|
|
2313
|
+
// is the most common way a stranded notice gets its second chance.
|
|
2314
|
+
this.flushPendingNotices();
|
|
2315
|
+
await this.agent.continue();
|
|
2316
|
+
return { status: 'finished' };
|
|
2317
|
+
}
|
|
2318
|
+
finally {
|
|
2319
|
+
this.promptInFlight -= 1;
|
|
2143
2320
|
}
|
|
2144
|
-
// The `continue()` path needs its own delivery for the reason RV-P1-7 gives:
|
|
2145
|
-
// a run that ended with a notice still queued resumes through here, and this
|
|
2146
|
-
// is the most common way a stranded notice gets its second chance.
|
|
2147
|
-
this.flushPendingNotices();
|
|
2148
|
-
await this.agent.continue();
|
|
2149
|
-
return { status: 'finished' };
|
|
2150
2321
|
}
|
|
2151
2322
|
/** Pending user receipts survive until Core accepts or the host clears them. */
|
|
2152
2323
|
hasPendingUserMessages() { return this.pendingUserSteering.size > 0; }
|
|
@@ -2995,29 +3166,64 @@ export class AgentController {
|
|
|
2995
3166
|
const live = runtime.live();
|
|
2996
3167
|
return live !== null && live.turnId !== this.turnId;
|
|
2997
3168
|
}
|
|
3169
|
+
// -----------------------------------------------------------------------
|
|
3170
|
+
// The lead wake signals (team-lead-wake-signals)
|
|
3171
|
+
// -----------------------------------------------------------------------
|
|
2998
3172
|
/**
|
|
2999
|
-
*
|
|
3000
|
-
*
|
|
3001
|
-
* THE ID TRAVELS WITH THE FACTS. The host spends the continuation with
|
|
3002
|
-
* `markTeamContinued()`, and the facts are by definition read AFTER settlement,
|
|
3003
|
-
* when `TeamRuntime.live()` already answers `null` - so an id re-derived from
|
|
3004
|
-
* `live()` was always null, `session.continued` was never set, and every later
|
|
3005
|
-
* `agent_end` earned the same follow-up turn: an unbounded model loop that
|
|
3006
|
-
* never lets the user type.
|
|
3173
|
+
* Every attention notice the lead has not been PROVEN to have: the queue plus the
|
|
3174
|
+
* relay's ledger, oldest first. The governor's one input.
|
|
3007
3175
|
*/
|
|
3008
|
-
|
|
3009
|
-
const
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
return facts === null ? null : { ...facts, dispatchId: id };
|
|
3176
|
+
owedAttention() {
|
|
3177
|
+
const facts = [];
|
|
3178
|
+
for (const notice of this.teamRelay?.undelivered() ?? []) {
|
|
3179
|
+
const fact = attentionFactOf(notice);
|
|
3180
|
+
if (fact !== null)
|
|
3181
|
+
facts.push(fact);
|
|
3182
|
+
}
|
|
3183
|
+
return facts.sort((a, b) => a.at - b.at);
|
|
3017
3184
|
}
|
|
3018
|
-
/**
|
|
3019
|
-
|
|
3020
|
-
|
|
3185
|
+
/**
|
|
3186
|
+
* Register THE host of wake requests (one at a time). The terminal app and the
|
|
3187
|
+
* desktop coordinator both do it through `host/team-wake-driver.ts`.
|
|
3188
|
+
*/
|
|
3189
|
+
subscribeTeamWake(listener) {
|
|
3190
|
+
return this.teamWake?.subscribe(listener) ?? (() => { });
|
|
3191
|
+
}
|
|
3192
|
+
/**
|
|
3193
|
+
* The fire-time re-check: still owed, lead still idle, no user message waiting - and
|
|
3194
|
+
* the `<team_signal>` text to submit, rendered NOW so anything that arrived during
|
|
3195
|
+
* the countdown is in it. Synchronous and never throws (I-WK10).
|
|
3196
|
+
*/
|
|
3197
|
+
confirmTeamWake(requestId) {
|
|
3198
|
+
return this.teamWake?.begin(requestId) ?? { ok: false, why: 'disposed' };
|
|
3199
|
+
}
|
|
3200
|
+
ackTeamWake(requestId, result) {
|
|
3201
|
+
this.teamWake?.ack(requestId, result);
|
|
3202
|
+
}
|
|
3203
|
+
/** Whether any attention notice is undelivered. `team_collect` stops waiting on it. */
|
|
3204
|
+
hasPendingTeamAttention() {
|
|
3205
|
+
return this.owedAttention().length > 0;
|
|
3206
|
+
}
|
|
3207
|
+
/**
|
|
3208
|
+
* `team_collect` has just put this dispatch's report in a tool result, so the settle
|
|
3209
|
+
* notice must not deliver it again (RC-8).
|
|
3210
|
+
*/
|
|
3211
|
+
acknowledgeTeamSettle(dispatchId) {
|
|
3212
|
+
this.teamRelay?.dropById(`${dispatchId}:end`);
|
|
3213
|
+
this.teamWake?.poke();
|
|
3214
|
+
}
|
|
3215
|
+
/** The runtime's live roster as `still running` count: queued + running + paused. */
|
|
3216
|
+
stillRunningCount() {
|
|
3217
|
+
const roster = this.teamRuntime?.inspect() ?? null;
|
|
3218
|
+
if (roster === null)
|
|
3219
|
+
return 0;
|
|
3220
|
+
return roster.counts.queued + roster.counts.running + roster.counts.paused;
|
|
3221
|
+
}
|
|
3222
|
+
/** Forget everything the team owed the previous conversation. */
|
|
3223
|
+
resetTeamSignals() {
|
|
3224
|
+
this.teamWake?.reset();
|
|
3225
|
+
this.teamNotices.clear();
|
|
3226
|
+
this.teamRelay?.reset();
|
|
3021
3227
|
}
|
|
3022
3228
|
/**
|
|
3023
3229
|
* Turn one runtime event into a notice (section 5.3.1).
|
|
@@ -3026,28 +3232,30 @@ export class AgentController {
|
|
|
3026
3232
|
* queue must agree about what happened, and the only way to guarantee that is for
|
|
3027
3233
|
* all three to read the same event. The queue adds nothing but the "exactly once"
|
|
3028
3234
|
* bookkeeping.
|
|
3235
|
+
*
|
|
3236
|
+
* ONLY DETACHED DISPATCHES (I-WK3). A blocking dispatch already returns its report
|
|
3237
|
+
* in the `task` result, so a notice about it would deliver the same report twice -
|
|
3238
|
+
* and, now that notices wake the lead, would also start a turn for nothing. The one
|
|
3239
|
+
* exception to "seen `dispatch_start` first" is `dispatch_end.detached`, which the
|
|
3240
|
+
* runtime sets itself so a dispatch that died before it could announce its start
|
|
3241
|
+
* still reaches the lead (I-WK15).
|
|
3029
3242
|
*/
|
|
3030
3243
|
onTeamEvent(event) {
|
|
3244
|
+
if (event.type === 'dispatch_start') {
|
|
3245
|
+
if (event.detached !== true)
|
|
3246
|
+
return;
|
|
3247
|
+
this.detachedDispatches.add(event.dispatchId);
|
|
3248
|
+
this.teamWake?.onDispatchStart();
|
|
3249
|
+
return;
|
|
3250
|
+
}
|
|
3251
|
+
const detached = this.detachedDispatches.has(event.dispatchId) ||
|
|
3252
|
+
(event.type === 'dispatch_end' && event.detached === true);
|
|
3253
|
+
if (!detached)
|
|
3254
|
+
return;
|
|
3031
3255
|
switch (event.type) {
|
|
3032
|
-
case 'agent_update':
|
|
3033
|
-
|
|
3034
|
-
if (phase !== 'done' && phase !== 'failed' && phase !== 'aborted')
|
|
3035
|
-
break;
|
|
3036
|
-
const elapsedMs = (event.run.endedAt ?? Date.now()) - (event.run.startedAt ?? Date.now());
|
|
3037
|
-
this.teamNotices.push({
|
|
3038
|
-
kind: 'child_settled',
|
|
3039
|
-
id: `${event.dispatchId}:${event.run.label}:${phase}`,
|
|
3040
|
-
dispatchId: event.dispatchId,
|
|
3041
|
-
label: event.run.label,
|
|
3042
|
-
phase,
|
|
3043
|
-
elapsedMs,
|
|
3044
|
-
turns: event.run.turns,
|
|
3045
|
-
toolCalls: event.run.toolCalls,
|
|
3046
|
-
...(event.run.error !== undefined ? { error: event.run.error } : {}),
|
|
3047
|
-
at: Date.now(),
|
|
3048
|
-
});
|
|
3256
|
+
case 'agent_update':
|
|
3257
|
+
this.noteChildSettled(event);
|
|
3049
3258
|
break;
|
|
3050
|
-
}
|
|
3051
3259
|
case 'lead_mail':
|
|
3052
3260
|
this.teamNotices.push({
|
|
3053
3261
|
kind: 'lead_mail',
|
|
@@ -3061,27 +3269,102 @@ export class AgentController {
|
|
|
3061
3269
|
at: Date.now(),
|
|
3062
3270
|
});
|
|
3063
3271
|
break;
|
|
3064
|
-
case '
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
aborted: event.outcome.aborted,
|
|
3073
|
-
at: Date.now(),
|
|
3074
|
-
});
|
|
3075
|
-
// ONE PUSH ATTEMPT. If the lead is not at a safe steer point (it is
|
|
3076
|
-
// mid-batch), the notice stays queued and the next boundary, the next turn
|
|
3077
|
-
// or the settle follow-up delivers it - the ledger guarantees that.
|
|
3078
|
-
this.teamRelay?.tryPush();
|
|
3272
|
+
case 'child_failed':
|
|
3273
|
+
this.noteChildFailed(event);
|
|
3274
|
+
break;
|
|
3275
|
+
case 'stalled':
|
|
3276
|
+
this.noteStalled(event);
|
|
3277
|
+
break;
|
|
3278
|
+
case 'dispatch_end':
|
|
3279
|
+
this.noteDispatchEnd(event);
|
|
3079
3280
|
break;
|
|
3080
|
-
}
|
|
3081
3281
|
default:
|
|
3082
3282
|
break;
|
|
3083
3283
|
}
|
|
3084
3284
|
}
|
|
3285
|
+
/** `done` / `aborted` are chatter; `failed` is a SIGNAL and arrives as `child_failed`. */
|
|
3286
|
+
noteChildSettled(event) {
|
|
3287
|
+
const phase = event.run.phase;
|
|
3288
|
+
if (phase !== 'done' && phase !== 'aborted')
|
|
3289
|
+
return;
|
|
3290
|
+
const elapsedMs = (event.run.endedAt ?? Date.now()) - (event.run.startedAt ?? Date.now());
|
|
3291
|
+
this.teamNotices.push({
|
|
3292
|
+
kind: 'child_settled',
|
|
3293
|
+
id: `${event.dispatchId}:${event.run.label}:${phase}`,
|
|
3294
|
+
dispatchId: event.dispatchId,
|
|
3295
|
+
label: event.run.label,
|
|
3296
|
+
phase,
|
|
3297
|
+
elapsedMs,
|
|
3298
|
+
turns: event.run.turns,
|
|
3299
|
+
toolCalls: event.run.toolCalls,
|
|
3300
|
+
...(event.run.error !== undefined ? { error: event.run.error } : {}),
|
|
3301
|
+
at: Date.now(),
|
|
3302
|
+
});
|
|
3303
|
+
}
|
|
3304
|
+
noteChildFailed(event) {
|
|
3305
|
+
const { run } = event;
|
|
3306
|
+
const now = Date.now();
|
|
3307
|
+
this.teamNotices.push({
|
|
3308
|
+
kind: 'child_failed',
|
|
3309
|
+
id: `${event.dispatchId}:fail:${run.label}`,
|
|
3310
|
+
dispatchId: event.dispatchId,
|
|
3311
|
+
label: run.label,
|
|
3312
|
+
error: firstLine(run.error ?? ''),
|
|
3313
|
+
elapsedMs: (run.endedAt ?? now) - (run.startedAt ?? now),
|
|
3314
|
+
turns: run.turns,
|
|
3315
|
+
toolCalls: run.toolCalls,
|
|
3316
|
+
stillRunning: this.stillRunningCount(),
|
|
3317
|
+
at: now,
|
|
3318
|
+
});
|
|
3319
|
+
this.raiseSignal(event.dispatchId, 'child_failed', true);
|
|
3320
|
+
}
|
|
3321
|
+
noteStalled(event) {
|
|
3322
|
+
this.teamNotices.push({
|
|
3323
|
+
kind: 'team_stalled',
|
|
3324
|
+
id: `${event.dispatchId}:stall:${event.episode}`,
|
|
3325
|
+
dispatchId: event.dispatchId,
|
|
3326
|
+
episode: event.episode,
|
|
3327
|
+
quietMs: event.quietMs,
|
|
3328
|
+
blockers: event.blockers,
|
|
3329
|
+
at: Date.now(),
|
|
3330
|
+
});
|
|
3331
|
+
getLogger().info('agent', 'team_stall_detected', {
|
|
3332
|
+
dispatchId: event.dispatchId,
|
|
3333
|
+
episode: event.episode,
|
|
3334
|
+
blockers: event.blockers.length,
|
|
3335
|
+
quietMs: event.quietMs,
|
|
3336
|
+
});
|
|
3337
|
+
this.raiseSignal(event.dispatchId, 'stalled', true);
|
|
3338
|
+
}
|
|
3339
|
+
noteDispatchEnd(event) {
|
|
3340
|
+
const report = this.teamRuntime?.reportText(event.dispatchId) ??
|
|
3341
|
+
buildDispatchReport(event.outcome, this.teamReportOptions());
|
|
3342
|
+
// A stop the user or the lead ordered is news to nobody (I-WK11): the notice still
|
|
3343
|
+
// goes in the queue and still travels with the next turn, but it owes no wake.
|
|
3344
|
+
const stoppedBy = this.teamRuntime?.abortedBy(event.dispatchId);
|
|
3345
|
+
const attention = stoppedBy !== 'user' && stoppedBy !== 'lead';
|
|
3346
|
+
this.teamNotices.push({
|
|
3347
|
+
kind: 'dispatch_settled',
|
|
3348
|
+
id: `${event.dispatchId}:end`,
|
|
3349
|
+
dispatchId: event.dispatchId,
|
|
3350
|
+
report,
|
|
3351
|
+
aborted: event.outcome.aborted,
|
|
3352
|
+
attention,
|
|
3353
|
+
facts: settleFactsOf(event.outcome),
|
|
3354
|
+
at: Date.now(),
|
|
3355
|
+
});
|
|
3356
|
+
this.detachedDispatches.delete(event.dispatchId);
|
|
3357
|
+
// ONE PUSH ATTEMPT. If the lead is not at a safe steer point (it is mid-batch),
|
|
3358
|
+
// the notice stays queued and the next boundary, the next turn or the wake
|
|
3359
|
+
// delivers it - the ledger guarantees that.
|
|
3360
|
+
this.teamRelay?.tryPush();
|
|
3361
|
+
this.raiseSignal(event.dispatchId, 'settled', attention);
|
|
3362
|
+
}
|
|
3363
|
+
raiseSignal(dispatchId, kind, attention) {
|
|
3364
|
+
getLogger().info('agent', 'team_signal_raised', { dispatchId, kind, attention });
|
|
3365
|
+
if (attention)
|
|
3366
|
+
this.teamWake?.poke();
|
|
3367
|
+
}
|
|
3085
3368
|
/** Refused mid-dispatch by `/team`; half a dispatch under two ceilings is not
|
|
3086
3369
|
* a result anything can afterwards explain (the reasoning `/reload` uses). */
|
|
3087
3370
|
isTeamBusy() {
|
|
@@ -3107,6 +3390,7 @@ export class AgentController {
|
|
|
3107
3390
|
this.disposed = true;
|
|
3108
3391
|
this.modelMetadataGeneration += 1;
|
|
3109
3392
|
this.modelMetadataAbort.abort();
|
|
3393
|
+
this.teamWake?.dispose();
|
|
3110
3394
|
this.teamRuntime?.dispose();
|
|
3111
3395
|
// Flushes usage, stops the learner / curator / maintenance and releases the lease. Never rejects.
|
|
3112
3396
|
void this.gene?.dispose();
|
|
@@ -3270,6 +3554,17 @@ export class AgentController {
|
|
|
3270
3554
|
getRetryConfig() {
|
|
3271
3555
|
return this.config.retry;
|
|
3272
3556
|
}
|
|
3557
|
+
/**
|
|
3558
|
+
* Which ladder shape this host gets (tiered-reconnect §4.4 / D-6).
|
|
3559
|
+
*
|
|
3560
|
+
* READ-ONLY, and it exists so the difference between a terminal and a pipeline is
|
|
3561
|
+
* OBSERVABLE: `-p` / `exec` are bounded, the TUI and the desktop are full, and the
|
|
3562
|
+
* failure this prevents (a CI job waiting forever on a regional outage) has no
|
|
3563
|
+
* other symptom. `/retry show` and the desktop's diagnostics can also report it.
|
|
3564
|
+
*/
|
|
3565
|
+
getReconnectMode() {
|
|
3566
|
+
return this.reconnectMode;
|
|
3567
|
+
}
|
|
3273
3568
|
/**
|
|
3274
3569
|
* Adopt a new retry config for this session AND PUSH IT INTO THE REGISTRY.
|
|
3275
3570
|
*
|
|
@@ -3594,6 +3889,8 @@ export class AgentController {
|
|
|
3594
3889
|
*/
|
|
3595
3890
|
clearMessages() {
|
|
3596
3891
|
this.gene?.resetSession('clear');
|
|
3892
|
+
// A new conversation owes nothing to the old one's team (I-WK12).
|
|
3893
|
+
this.resetTeamSignals();
|
|
3597
3894
|
this.idleCompaction?.abort();
|
|
3598
3895
|
this.restoredCompactionIdentity = undefined;
|
|
3599
3896
|
this.agent.clearMessages();
|
|
@@ -3685,6 +3982,7 @@ export class AgentController {
|
|
|
3685
3982
|
}
|
|
3686
3983
|
replaceMessages(messages, identity) {
|
|
3687
3984
|
this.gene?.resetSession('resume');
|
|
3985
|
+
this.resetTeamSignals();
|
|
3688
3986
|
this.idleCompaction?.abort();
|
|
3689
3987
|
this.restoredCompactionIdentity = identity;
|
|
3690
3988
|
this.agent.replaceMessages(messages);
|
|
@@ -3729,6 +4027,9 @@ export class AgentController {
|
|
|
3729
4027
|
// receipt id. Anything still unproven goes straight back into the notice
|
|
3730
4028
|
// queue, so the wipe costs a delay instead of a fact the model never learns.
|
|
3731
4029
|
this.jobRelay?.requeueUndelivered();
|
|
4030
|
+
// THE TEAM RELAY HAS THE SAME EXPOSURE (RC-9) and was simply missing here: a team
|
|
4031
|
+
// notice steered but not yet accepted is invisible to `fast`'s counter too.
|
|
4032
|
+
this.teamRelay?.requeueUndelivered();
|
|
3732
4033
|
}
|
|
3733
4034
|
// -----------------------------------------------------------------------
|
|
3734
4035
|
// Model / provider info
|
|
@@ -4180,6 +4481,8 @@ export class AgentController {
|
|
|
4180
4481
|
if (this.idleCompaction === controller) {
|
|
4181
4482
|
this.idleCompaction = undefined;
|
|
4182
4483
|
this.publishCompactionBusy(false);
|
|
4484
|
+
// The lead was "busy" for the governor while this ran; look again now.
|
|
4485
|
+
this.teamWake?.onLeadIdle({ aborted: false });
|
|
4183
4486
|
}
|
|
4184
4487
|
}
|
|
4185
4488
|
}
|