@aragon-agent/cli 0.6.56 → 0.6.58

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.
Files changed (97) hide show
  1. package/CHANGELOG.md +94 -0
  2. package/README.md +159 -3
  3. package/dist/agent/controller.d.ts +112 -1
  4. package/dist/agent/controller.js +350 -7
  5. package/dist/agent/project-guidance-prompt.js +97 -97
  6. package/dist/agent/redteam-prompt.d.ts +29 -11
  7. package/dist/agent/redteam-prompt.js +118 -103
  8. package/dist/agent/redteam-wiring.d.ts +117 -2
  9. package/dist/agent/redteam-wiring.js +204 -1
  10. package/dist/agent/team-notices.d.ts +68 -0
  11. package/dist/agent/team-notices.js +82 -0
  12. package/dist/app/App.js +208 -5
  13. package/dist/app/use-redteam-mode.d.ts +1 -1
  14. package/dist/app/use-redteam-mode.js +14 -1
  15. package/dist/cli.js +13 -0
  16. package/dist/commands/catalog.js +6 -2
  17. package/dist/commands/redteam-command.d.ts +14 -8
  18. package/dist/commands/redteam-command.js +243 -12
  19. package/dist/commands/team-command.js +93 -2
  20. package/dist/config/app-paths.d.ts +19 -0
  21. package/dist/config/app-paths.js +23 -0
  22. package/dist/config/load.d.ts +8 -0
  23. package/dist/gene/catalog-sync.js +37 -16
  24. package/dist/gene/curator/budget.js +1 -1
  25. package/dist/gene/curator/curator.d.ts +6 -0
  26. package/dist/gene/curator/curator.js +8 -0
  27. package/dist/gene/curator/recheck.js +2 -1
  28. package/dist/gene/curator/task-runner.js +4 -1
  29. package/dist/gene/curator/tool-support.js +16 -7
  30. package/dist/gene/curator/tools-verify.js +54 -1
  31. package/dist/gene/curator/tools-write.js +41 -1
  32. package/dist/gene/curator/validate/evidence-tokens.d.ts +7 -19
  33. package/dist/gene/curator/validate/evidence-tokens.js +174 -17
  34. package/dist/gene/curator/validate/knowledge.d.ts +22 -1
  35. package/dist/gene/curator/validate/knowledge.js +108 -25
  36. package/dist/gene/curator/validate/live-check.js +7 -1
  37. package/dist/gene/curator/validate/prompts.js +7 -3
  38. package/dist/gene/curator/validate/types.d.ts +6 -1
  39. package/dist/gene/learn/learn-call.d.ts +58 -5
  40. package/dist/gene/learn/learn-call.js +38 -30
  41. package/dist/gene/learn/learn-prompt.d.ts +18 -2
  42. package/dist/gene/learn/learn-prompt.js +29 -11
  43. package/dist/gene/learn/learner.d.ts +6 -0
  44. package/dist/gene/learn/learner.js +31 -9
  45. package/dist/gene/learn/proposal-build.js +2 -6
  46. package/dist/gene/wiring-models.js +4 -1
  47. package/dist/governance/engine/lifecycle.js +1 -1
  48. package/dist/governance/store/run-lock.d.ts +9 -2
  49. package/dist/governance/store/run-lock.js +91 -7
  50. package/dist/host/controller-factory.d.ts +13 -0
  51. package/dist/host/controller-factory.js +7 -0
  52. package/dist/host/index.d.ts +1 -0
  53. package/dist/host/index.js +1 -0
  54. package/dist/host/interaction.d.ts +19 -0
  55. package/dist/host/interaction.js +75 -0
  56. package/dist/host/team-control.d.ts +83 -0
  57. package/dist/host/team-control.js +55 -0
  58. package/dist/logging/install.d.ts +32 -1
  59. package/dist/logging/install.js +21 -0
  60. package/dist/proc/output-streams.d.ts +11 -0
  61. package/dist/proc/output-streams.js +11 -0
  62. package/dist/redteam/prompt-resolve.d.ts +61 -0
  63. package/dist/redteam/prompt-resolve.js +303 -0
  64. package/dist/redteam/prompt-store.d.ts +96 -0
  65. package/dist/redteam/prompt-store.js +156 -0
  66. package/dist/redteam/prompt-template.d.ts +22 -0
  67. package/dist/redteam/prompt-template.js +72 -0
  68. package/dist/team/bus.d.ts +18 -0
  69. package/dist/team/bus.js +70 -18
  70. package/dist/team/console-tools.d.ts +54 -0
  71. package/dist/team/console-tools.js +333 -0
  72. package/dist/team/console-view.d.ts +88 -0
  73. package/dist/team/console-view.js +173 -0
  74. package/dist/team/forced-mode.d.ts +61 -1
  75. package/dist/team/forced-mode.js +75 -0
  76. package/dist/team/normalize.d.ts +31 -0
  77. package/dist/team/normalize.js +49 -5
  78. package/dist/team/notices.d.ts +95 -0
  79. package/dist/team/notices.js +121 -0
  80. package/dist/team/pause-gate.d.ts +79 -0
  81. package/dist/team/pause-gate.js +127 -0
  82. package/dist/team/prompt.d.ts +25 -9
  83. package/dist/team/prompt.js +29 -29
  84. package/dist/team/report.js +33 -0
  85. package/dist/team/runtime.d.ts +270 -5
  86. package/dist/team/runtime.js +732 -64
  87. package/dist/team/settled.d.ts +5 -2
  88. package/dist/team/settled.js +12 -2
  89. package/dist/team/subagent.d.ts +7 -0
  90. package/dist/team/subagent.js +12 -1
  91. package/dist/team/task-tool.d.ts +39 -1
  92. package/dist/team/task-tool.js +75 -18
  93. package/dist/tools/bash-tool.d.ts +11 -8
  94. package/dist/tools/bash-tool.js +37 -9
  95. package/dist/tools/index.d.ts +2 -2
  96. package/dist/tools/index.js +30 -0
  97. package/package.json +3 -3
@@ -16,46 +16,46 @@
16
16
  import { TEAM_BLOCK_VERSION, TEAM_LIMITS } from '@aragon-agent/tui/model/team/limits';
17
17
  export { TEAM_BLOCK_VERSION };
18
18
  /**
19
- * The lead's `<team_mode>` block. Under 1200 characters on purpose: it is paid
20
- * for on EVERY turn of every team-enabled session, so anything that does not
21
- * change a delegation decision does not belong in it.
19
+ * The lead's `<team_mode>` block.
20
+ *
21
+ * UNDER 1200 CHARACTERS, AND NOW ASSERTED BY A TEST (`team-prompt.test.ts`), which
22
+ * is a change of kind rather than of number: v3 measured 1 204 and the budget had
23
+ * never been enforced, so every later addition was free money. The detach
24
+ * paragraph costs ~600 characters, so the prose below was compressed by more than
25
+ * that rather than by "roughly enough": what went is everything that repeated
26
+ * `task`'s own description (the whole "do not delegate when" list, the second
27
+ * "cannot ask the user anything", the duplicate "one combined report" sentence)
28
+ * and the second copy of a maximum that is already in the first line.
22
29
  *
23
30
  * "Two to four is usually enough" is where the requirement's "shu liang zi shi
24
- * ying" (adaptive count) actually lives. The ceiling is mechanical and enforced
25
- * elsewhere (`team.maxSubagents`, quoted in the first paragraph); the CHOICE is
26
- * the model's, and this paragraph is the only thing that informs it. It names a
27
- * USUAL size rather than the maximum on purpose: the default fan-out moved to 8
28
- * (subagent-fanout D-1), and a block that told the model "eight is normal"
29
- * would turn every two-part job into an eight-agent bill.
31
+ * ying" (adaptive count) actually lives: the ceiling is mechanical and enforced
32
+ * elsewhere, this paragraph is the only thing that informs the CHOICE.
30
33
  */
31
34
  export function buildTeamBlock(params) {
32
35
  const max = Math.max(1, Math.floor(params.maxSubagents));
33
36
  const concurrent = Math.max(1, Math.min(Math.floor(params.maxConcurrent), max));
34
- return [
37
+ const lines = [
35
38
  '<team_mode>',
36
39
  `You can delegate to parallel subagents with the task tool (up to ${max} per`,
37
40
  `call, ${concurrent} running at once).`,
38
41
  '',
39
- 'Delegate when: the work splits into 2+ parts that do not need each other\'s',
40
- 'output; several areas must be read or searched at once; a long build or test',
41
- 'run can proceed while another part is investigated.',
42
- '',
43
- 'Do not delegate when: one part needs another part\'s result (do those in order',
44
- 'yourself); two parts would edit the same file; the whole job is a few edits.',
45
- 'One well-scoped subagent is better than four vague ones. Two to four is',
46
- 'usually enough; go wider only when the parts are genuinely independent - a',
47
- 'narrow fan-out is cheaper and easier to read.',
42
+ 'Delegate when the work splits into 2+ parts that need no other\'s output, when',
43
+ 'several areas must be read at once, or when a long build can run beside other',
44
+ 'work. Two to four is usually enough; a narrow fan-out is cheaper to read.',
48
45
  '',
49
- 'Each subagent starts with no memory of this conversation, so its prompt must',
50
- 'carry everything it needs: the goal, the files or areas it owns, and what to',
51
- 'report back. Give each one a disjoint set of files to write. Each subagent runs',
52
- 'on the model the user configured for subagents (usually your own). Subagents',
53
- 'cannot dispatch further subagents and cannot ask the user anything.',
54
- '',
55
- 'You get one combined report when they all finish. Read it before deciding what',
56
- 'to do next, and tell the user what the team found in your own words.',
57
- '</team_mode>',
58
- ].join('\n');
46
+ 'Each subagent starts with no memory of this conversation: its prompt must carry',
47
+ 'the goal, the files it owns, and what to report back. Give each a disjoint set',
48
+ 'of files to write. Each runs on the model configured for subagents (usually',
49
+ 'yours), and none may delegate further.',
50
+ ];
51
+ if (params.detachDispatch === true) {
52
+ lines.push('', 'While a dispatch runs you are FREE, not waiting: a new user message is your', 'own turn - answer it, do not route it to the team. team_status shows the', 'roster and partial results; team_message corrects a child; team_pause /', 'team_resume hold one; team_stop ends one; team_spawn adds one; team_collect', 'only when you cannot answer without results. If the user changes the goal', 'mid-flight, propagate it with team_message (and pause what no longer matters)', 'before you answer. The report arrives when the team finishes; summarise it', 'then, in your own words.');
53
+ }
54
+ else {
55
+ lines.push('', 'You get one combined report when they all finish. Read it before deciding', 'what to do next, and tell the user what the team found in your own words.');
56
+ }
57
+ lines.push('</team_mode>');
58
+ return lines.join('\n');
59
59
  }
60
60
  /**
61
61
  * The child's `<subagent_role>` block.
@@ -253,6 +253,36 @@ function buildLeadMail(outcome) {
253
253
  }
254
254
  return lines;
255
255
  }
256
+ /**
257
+ * The Control section (team-detached-dispatch section 6.3 / I-DD5).
258
+ *
259
+ * WHY IT IS PART OF THE REPORT AND NOT A SEPARATE LOG. Once a dispatch can be
260
+ * paused, steered and stopped by the lead or the user, the report's reader needs
261
+ * to know that before reading a "failed after 8 minutes" row - otherwise "it was
262
+ * stopped on purpose" and "it broke" look identical in the one artefact people
263
+ * actually read afterwards. Every row names its AUTHOR.
264
+ *
265
+ * HELD TIME is summarised per child, because a paused child's elapsed time and its
266
+ * working time are different numbers and only the second one explains anything.
267
+ */
268
+ function buildControl(outcome) {
269
+ const controlled = (outcome.interventions ?? []).filter((item) => item.trigger === 'lead' || item.trigger === 'user');
270
+ const held = outcome.runs.filter((run) => (run.pausedMs ?? 0) > 0);
271
+ if (controlled.length === 0 && held.length === 0)
272
+ return [];
273
+ const lines = ['### Control'];
274
+ for (const item of controlled) {
275
+ const at = Math.max(0, Math.round((item.at - outcome.startedAt) / 1000));
276
+ lines.push(`[${item.trigger} ${at}s] ${item.label}: ${item.reason}`);
277
+ }
278
+ for (const run of held) {
279
+ const seconds = Math.round((run.pausedMs ?? 0) / 1000);
280
+ const holds = run.pauseCount ?? 1;
281
+ lines.push(`${run.label} was held for ${seconds}s in ${holds} hold${holds === 1 ? '' : 's'}` +
282
+ `${run.controlBy !== undefined ? ` (last by ${run.controlBy})` : ''}.`);
283
+ }
284
+ return lines;
285
+ }
256
286
  /**
257
287
  * Assemble the report.
258
288
  *
@@ -267,6 +297,7 @@ export function buildDispatchReport(outcome, options = {}) {
267
297
  const sections = outcome.runs.map(buildSection);
268
298
  const mail = buildLeadMail(outcome);
269
299
  const overseer = buildOverseer(outcome, options);
300
+ const control = buildControl(outcome);
270
301
  const summaries = sections.map((s) => truncateBytes(s.summary, TEAM_LIMITS.summaryMaxBytes));
271
302
  const trimmed = summaries.map((s, i) => s.length < sections[i].summary.length);
272
303
  const render = (bodies) => {
@@ -281,6 +312,8 @@ export function buildDispatchReport(outcome, options = {}) {
281
312
  });
282
313
  if (overseer.length > 0)
283
314
  blocks.push(overseer.join('\n'));
315
+ if (control.length > 0)
316
+ blocks.push(control.join('\n'));
284
317
  if (mail.length > 0)
285
318
  blocks.push(mail.join('\n'));
286
319
  return blocks.join('\n\n');
@@ -34,8 +34,9 @@ import type { CliConfig } from '@aragon-agent/tui/model/config/schema';
34
34
  import type { ToolPermission } from '../exec/permission.js';
35
35
  import type { TeamHumanQueue } from './human-queue.js';
36
36
  import { type OverseerProvider } from './overseer.js';
37
+ import { type ReportOptions } from './report.js';
37
38
  import { type SubagentAgentFactory, type SubagentDeps } from './subagent.js';
38
- import type { DispatchOutcome, SubagentSpec, TeamEventListener, TeamSnapshot } from '@aragon-agent/tui/model/team/types';
39
+ import type { DispatchOutcome, SubagentPhase, SubagentSpec, TeamControlAction, TeamControlBy, TeamEventListener, TeamMessage, TeamSnapshot } from '@aragon-agent/tui/model/team/types';
39
40
  import type { ToolGate } from '../tools/tool-gate.js';
40
41
  export interface TeamRuntimeDeps {
41
42
  /** Read LIVE: a settings-screen model or key edit must reach the next dispatch. */
@@ -128,11 +129,91 @@ export interface TeamRuntimeDeps {
128
129
  * ABSENT when the library is off, which leaves every child built as before.
129
130
  */
130
131
  geneTools?: SubagentDeps['geneTools'];
132
+ /**
133
+ * The turn that would OWN a dispatch started right now (team-detached-dispatch
134
+ * I-DD11). The controller supplies a counter it bumps once per `prompt()`;
135
+ * `stopEngine()` compares this with the live session's `turnId` and only takes
136
+ * the team with it when they are equal.
137
+ *
138
+ * ABSENT means "no turn accounting": `turnId` is then 0 for every dispatch and
139
+ * `stopEngine()` behaves exactly as it did before this feature (the defensive
140
+ * default, because a host that cannot answer must not be assumed free).
141
+ */
142
+ currentTurnId?: () => number;
143
+ /**
144
+ * Whether the lead is inside a turn right now. Paired with `currentTurnId()`
145
+ * to derive `settledInsideTurn`; a dispatch cannot have "settled inside its own
146
+ * turn" if no turn is running.
147
+ */
148
+ isLeadRunning?: () => boolean;
149
+ /**
150
+ * The report's price and model closures, read AT SETTLEMENT (REV-05).
151
+ *
152
+ * The old producer was `task-tool.ts`, right after its `await`; a detached
153
+ * dispatch has no `await` to hang them off, so the runtime holds the same
154
+ * closures and calls `buildDispatchReport` exactly once. Everything downstream
155
+ * (the notice, `team_collect`, `/team wait`) reads the resulting STRING, which
156
+ * is what makes their equality a construction fact rather than a promise.
157
+ */
158
+ reportOptions?: () => ReportOptions;
159
+ /**
160
+ * `controller.hasPendingUserMessages()` (I-DD2), injected rather than
161
+ * reimplemented: `team_collect` must stop waiting the moment the user is owed
162
+ * an answer, and the queue's own predicate is the only honest source for that.
163
+ */
164
+ hasPendingUserInput?: () => boolean;
165
+ }
166
+ /** What `start()` hands back: everything a caller needs without a promise. */
167
+ export interface DispatchHandle {
168
+ dispatchId: string;
169
+ /** The labels actually created, in scheduling order. */
170
+ labels: string[];
171
+ requested: number;
172
+ startedAt: number;
173
+ /** The turn that started it (I-DD11). */
174
+ turnId: number;
175
+ }
176
+ /** One audited control action (I-DD5). Rendered by the report's Control section. */
177
+ export interface TeamControlRecord {
178
+ action: TeamControlAction;
179
+ label?: string;
180
+ by: TeamControlBy;
181
+ reason?: string;
182
+ at: number;
183
+ }
184
+ /** One child, as the console tools and the status view need it. */
185
+ export interface ChildInspection {
186
+ label: string;
187
+ description: string;
188
+ phase: SubagentPhase;
189
+ elapsedMs: number;
190
+ turns: number;
191
+ toolCalls: number;
192
+ lastTool?: string;
193
+ pausedMs?: number;
194
+ pausedBy?: TeamControlBy;
195
+ error?: string;
196
+ summary?: string;
197
+ }
198
+ /** Everything `team_status` / `team_collect` / `/team status` read, in one shape. */
199
+ export interface DispatchInspection {
200
+ dispatchId: string;
201
+ live: boolean;
202
+ startedAt: number;
203
+ requested: number;
204
+ /** `0` = no wall-clock ceiling (the shipped default). */
205
+ ceilingMs: number;
206
+ elapsedMs: number;
207
+ counts: Record<'queued' | 'running' | 'paused' | 'done' | 'failed' | 'aborted', number>;
208
+ children: ChildInspection[];
209
+ mail: TeamMessage[];
210
+ controls: TeamControlRecord[];
211
+ reportText?: string;
131
212
  }
132
213
  export declare class TeamRuntime {
133
214
  private readonly deps;
134
215
  private readonly listeners;
135
- private live;
216
+ private liveHandles;
136
217
  private bus;
137
218
  private snapshotState;
138
219
  private busy;
@@ -178,6 +259,28 @@ export declare class TeamRuntime {
178
259
  /** Edge-latched "a tick ran unassisted" (D-10), per dispatch. */
179
260
  private overseerDegraded;
180
261
  private overseerDegradedTicks;
262
+ /**
263
+ * Labels a HUMAN (the lead or the user) stopped, for the current dispatch.
264
+ *
265
+ * WHY NOT JUST ASK THE VERDICT (AC-8). The supervisor's abandon and a human's
266
+ * stop share one abort path - that is the point of `abandonChild` - but they do
267
+ * NOT mean the same thing in the report: "the supervisor abandoned it" is a
268
+ * failure with a reason, while "the user stopped it" is an aborted child whose
269
+ * work simply ended. Collapsing both into `failed` would make a deliberate stop
270
+ * read as a defect, which is precisely the confusion the Control section exists
271
+ * to remove.
272
+ */
273
+ private readonly stoppedByHuman;
274
+ /**
275
+ * The dispatch currently owned by this runtime, or the last one that settled
276
+ * (team-detached-dispatch section 8.1).
277
+ *
278
+ * KEPT AFTER SETTLEMENT ON PURPOSE: `team_collect` must be able to answer
279
+ * "it finished, here is the report" for a while after the children are gone,
280
+ * and a dispatch that settled inside its own turn has no notice channel at
281
+ * all. It is replaced by the next dispatch, so this holds at most one.
282
+ */
283
+ private session;
181
284
  constructor(deps: TeamRuntimeDeps);
182
285
  subscribe(listener: TeamEventListener): () => void;
183
286
  /**
@@ -188,9 +291,159 @@ export declare class TeamRuntime {
188
291
  isBusy(): boolean;
189
292
  /** The live roster, for `/team` status. `null` when nothing is dispatching. */
190
293
  snapshot(): TeamSnapshot | null;
294
+ /** Everything `team_status`, `team_collect` and `/team status` render. */
295
+ inspect(): DispatchInspection | null;
296
+ /**
297
+ * Hold one child (section 5.2.4). The RESULT says what will actually happen,
298
+ * because "paused" is cooperative: `paused` when the child is between tools,
299
+ * `deferred` when it is mid-tool or mid-text, `finished` when it has already
300
+ * settled.
301
+ */
302
+ pauseChild(label: string, by: TeamControlBy, reason?: string): {
303
+ ok: true;
304
+ effect: 'paused' | 'deferred' | 'finished';
305
+ } | {
306
+ ok: false;
307
+ why: string;
308
+ };
309
+ /** Release one child (section 5.2.4). */
310
+ resumeChild(label: string, by: TeamControlBy, message?: string): {
311
+ ok: true;
312
+ effect: 'resumed' | 'was-running';
313
+ } | {
314
+ ok: false;
315
+ why: string;
316
+ };
317
+ /** Stop one child, or every child, through the ONE abandon path (section 5.2.5). */
318
+ stopChild(label: string | 'all', by: TeamControlBy, reason?: string): {
319
+ stopped: string[];
320
+ live: string[];
321
+ unknown?: boolean;
322
+ };
323
+ /**
324
+ * Send a message from the LEAD to one child or to everyone (section 5.2.3).
325
+ *
326
+ * THE QUOTA IS THE LEAD'S OWN (`messagesFromLeadPerDispatch`), and the interval
327
+ * window is keyed `lead:to` inside the bus (REV-17): one "the user changed the
328
+ * goal" usually has to reach two or three children, and a per-sender window
329
+ * would make the second and third impossible for 15 seconds each.
330
+ */
331
+ sendFromLead(to: string, body: string, options?: {
332
+ subject?: string;
333
+ interrupt?: boolean;
334
+ by?: TeamControlBy;
335
+ }): {
336
+ ok: true;
337
+ delivered: string[];
338
+ remaining: number;
339
+ } | {
340
+ ok: false;
341
+ why: string;
342
+ };
343
+ /**
344
+ * Add specs to a LIVE dispatch (section 5.2.6).
345
+ *
346
+ * THE CAP APPLIES TO THE TOTAL, NOT TO THE ADDITION: `remaining` is measured
347
+ * against what this dispatch already created, so `team_spawn` cannot become a
348
+ * back door around `hardMaxSubagents`. New children take the next free worker
349
+ * slot through the same pool as the first batch, and a child that finds no slot
350
+ * waits in `queued` exactly as its siblings did.
351
+ */
352
+ addSpecs(raw: unknown, by: TeamControlBy, reason?: string): {
353
+ added: string[];
354
+ dropped: number;
355
+ requested: number;
356
+ } | {
357
+ ok: false;
358
+ why: string;
359
+ };
360
+ /**
361
+ * Create the added children and hand them to the live pool.
362
+ *
363
+ * THE POOL IS RE-ENTERED, NOT REBUILT: `this.liveHandles` is the array the outcome is
364
+ * built from and `worker()` walks it by index, so appending is enough - a new
365
+ * child that finds every worker busy stays `queued` until one finishes, which is
366
+ * exactly how the first batch behaves.
367
+ */
368
+ private spawnChildren;
369
+ /** Audit one control action on the session, the event stream and the run. */
370
+ private recordControl;
371
+ private emitControl;
372
+ /** The live session, or the refusal every control tool shares. */
373
+ private requireLive;
374
+ /** The `makeHandle` closure of the live dispatch, for `team_spawn`. */
375
+ private makeHandleForSession;
376
+ /** The run context of the live dispatch, so spawned children join the same pool. */
377
+ private liveRunCtx;
191
378
  dispatch(specs: SubagentSpec[], requested: number, signal?: AbortSignal): Promise<DispatchOutcome>;
192
- /** Idempotent: puts every per-dispatch field back where `dispatch()` found it. */
193
- private resetDispatchState;
379
+ /**
380
+ * Start a dispatch and return a handle IMMEDIATELY (team-detached-dispatch
381
+ * section 5.1.1).
382
+ *
383
+ * SYNCHRONOUS ON PURPOSE. The `task` tool returns this handle as its tool
384
+ * result within milliseconds, which is what frees the lead: everything that
385
+ * used to happen before `dispatch()` resolved now happens after `start()` has
386
+ * already returned. `beginSession` is therefore synchronous too - the id, the
387
+ * turn id, the abort controller and the `busy` latch are all taken before the
388
+ * first await.
389
+ *
390
+ * THE FLOATING PROMISE IS SAFE ONLY BECAUSE OF `finally`. Nothing awaits it, so
391
+ * a throw would otherwise leave `busy` true for the rest of the session and
392
+ * every later `task` would be refused - the one failure mode (R6) that turns a
393
+ * feature into an unusable session. `.catch` marks the failure visible; the
394
+ * error itself has nowhere to go but the event stream, which is where a host
395
+ * reads it.
396
+ */
397
+ start(specs: SubagentSpec[], requested: number): DispatchHandle;
398
+ /** The live dispatch handle, or `null`. The read surface behind `team_status`. */
399
+ live(): DispatchHandle | null;
400
+ /** The settled outcome for `dispatchId`, when it is the one on record. */
401
+ outcome(dispatchId: string): DispatchOutcome | null;
402
+ /** The report text produced AT SETTLEMENT, or `undefined` while live (REV-05). */
403
+ reportText(dispatchId: string): string | undefined;
404
+ /**
405
+ * The settle facts the host needs to decide whether the lead gets a follow-up
406
+ * turn (`planSettleContinuation`, section 5.3.3).
407
+ *
408
+ * `settledInsideTurn` is COMPUTED AT SETTLEMENT from `turnId` equality plus
409
+ * `isLeadRunning()` (REV-04), never from a signal or a wall clock: both of those
410
+ * give the wrong answer in the case that most needs reporting - a dispatch that
411
+ * failed fast inside the very turn that started it, where the report has
412
+ * already arrived as a steering message.
413
+ */
414
+ settleFacts(dispatchId: string): {
415
+ settled: boolean;
416
+ settledInsideTurn: boolean;
417
+ continuedThisDispatch: boolean;
418
+ aborted: boolean;
419
+ errored: boolean;
420
+ outcome: DispatchOutcome | null;
421
+ } | null;
422
+ /** Record that the follow-up turn was spent. At most one per dispatch. */
423
+ markContinued(dispatchId: string): void;
424
+ /** The id of the dispatch on record, live or settled. */
425
+ currentDispatchId(): string | null;
426
+ /** Whether the live dispatch was started by the turn identified by `turnId`. */
427
+ belongsToTurn(turnId: number): boolean;
428
+ /**
429
+ * Take everything a `task` call needs before its first await: the id, the
430
+ * clock, the turn, the abort controller and the `busy` latch.
431
+ *
432
+ * SPLIT OUT OF `runDispatch` (spec REV-04): `start()` cannot return an id it
433
+ * has not minted yet, so the minting has to be synchronous and separable.
434
+ */
435
+ private beginSession;
436
+ /**
437
+ * Idempotent teardown: puts every per-dispatch field back where
438
+ * `beginSession()` found it.
439
+ *
440
+ * A STRICT SUPERSET OF THE OLD `resetDispatchState()` (spec REV-04 item 2).
441
+ * The success path used to tear down inline and the throw path through this
442
+ * method; with a floating promise there is exactly ONE exit, and it is
443
+ * `finally`, so both halves have to be here or a detached dispatch leaks its
444
+ * timers, its pause gate or its latch.
445
+ */
446
+ private teardown;
194
447
  private runDispatch;
195
448
  /** One slot of the pool: take the next index until the list is exhausted. */
196
449
  private worker;
@@ -216,7 +469,7 @@ export declare class TeamRuntime {
216
469
  /**
217
470
  * Swap one child for a fresh one, carrying only what must survive.
218
471
  *
219
- * `this.live` IS `handles`, so the single assignment below also makes
472
+ * `this.liveHandles` IS `handles`, so the single assignment below also makes
220
473
  * `abortAll()` abort the NEW child and makes the outcome carry the new run.
221
474
  * Anyone tempted to "clean up" that aliasing into a defensive copy must update
222
475
  * both places.
@@ -233,6 +486,18 @@ export declare class TeamRuntime {
233
486
  * exactly this wait) or a confirmation queued on the one human slot.
234
487
  */
235
488
  private isBlocked;
489
+ /**
490
+ * THE ONE ABANDON TAIL (spec REV-03).
491
+ *
492
+ * `applyDecision('abandon')` used to end this child inline, and `team_stop`
493
+ * needs the identical ending - but it cannot call `applyDecision`, which
494
+ * returns early when there is no supervisor (`team.overseer: false` is a legal
495
+ * configuration) and whose abandon branch also spends the supervisor's own
496
+ * budget. Extracting the tail gives both callers ONE abort path, with the two
497
+ * legitimate differences named as parameters: only the supervisor spends its
498
+ * budget, and only the supervisor's call is preceded by its own budget check.
499
+ */
500
+ private abandonChild;
236
501
  /**
237
502
  * One SILENCE trigger handled: look, then apply. Fired from a supervision
238
503
  * timer and therefore async-and-forgotten; nothing here may throw.