@wrongstack/core 0.5.5 → 0.5.7

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 (45) hide show
  1. package/dist/{agent-bridge-B07AYFBk.d.ts → agent-bridge-BKNiE1VH.d.ts} +1 -1
  2. package/dist/{compactor-BWhJXxsW.d.ts → compactor-RIPuTtWK.d.ts} +1 -1
  3. package/dist/{config-BgM0BIpz.d.ts → config-BGGuP_Ar.d.ts} +1 -1
  4. package/dist/{context-CLZXPPYk.d.ts → context-CDRyrkKQ.d.ts} +7 -0
  5. package/dist/coordination/index.d.ts +10 -9
  6. package/dist/coordination/index.js +558 -61
  7. package/dist/coordination/index.js.map +1 -1
  8. package/dist/defaults/index.d.ts +19 -18
  9. package/dist/defaults/index.js +521 -64
  10. package/dist/defaults/index.js.map +1 -1
  11. package/dist/director-state-BmYi3DGA.d.ts +108 -0
  12. package/dist/{events-qnDZbrtb.d.ts → events-DPQKFX7W.d.ts} +1 -1
  13. package/dist/execution/index.d.ts +18 -11
  14. package/dist/execution/index.js +19 -3
  15. package/dist/execution/index.js.map +1 -1
  16. package/dist/extension/index.d.ts +6 -6
  17. package/dist/{index-De4R4rQ7.d.ts → index-Bf9Bpkdc.d.ts} +452 -9
  18. package/dist/{index-DPLJw_ZI.d.ts → index-j2WyAyML.d.ts} +20 -5
  19. package/dist/index.d.ts +108 -27
  20. package/dist/index.js +819 -90
  21. package/dist/index.js.map +1 -1
  22. package/dist/infrastructure/index.d.ts +6 -6
  23. package/dist/kernel/index.d.ts +9 -9
  24. package/dist/{mcp-servers-CSMfaBuL.d.ts → mcp-servers-DBdh3cee.d.ts} +3 -3
  25. package/dist/models/index.d.ts +2 -2
  26. package/dist/{multi-agent-Cv8wk47i.d.ts → multi-agent-Cpp7FXUl.d.ts} +11 -3
  27. package/dist/observability/index.d.ts +2 -2
  28. package/dist/{path-resolver-DiCUvEg6.d.ts → path-resolver--g_hKJ7V.d.ts} +2 -2
  29. package/dist/{director-state-BUxlqkOa.d.ts → plan-templates-Bveo2W8n.d.ts} +37 -76
  30. package/dist/{provider-runner-3SHqk9zB.d.ts → provider-runner-hl4Il3xS.d.ts} +3 -3
  31. package/dist/{retry-policy-LLUxJmYY.d.ts → retry-policy-LKS8MHsB.d.ts} +1 -1
  32. package/dist/sdd/index.d.ts +3 -3
  33. package/dist/{secret-scrubber-Z_VXuXQT.d.ts → secret-scrubber-BzQR5BiL.d.ts} +1 -1
  34. package/dist/{secret-scrubber-BhJTNr9v.d.ts → secret-scrubber-CfMdAJ_l.d.ts} +1 -1
  35. package/dist/security/index.d.ts +3 -3
  36. package/dist/{selector-DB2-byKH.d.ts → selector-C7HqnZJU.d.ts} +1 -1
  37. package/dist/{session-reader-4jxsYLZ8.d.ts → session-reader-CzfRA6Vk.d.ts} +1 -1
  38. package/dist/storage/index.d.ts +6 -5
  39. package/dist/storage/index.js +206 -2
  40. package/dist/storage/index.js.map +1 -1
  41. package/dist/{system-prompt-DI4Dtc1I.d.ts → system-prompt-Dl2QY1_B.d.ts} +1 -1
  42. package/dist/{tool-executor-DSvmOBe6.d.ts → tool-executor-DbAFkHdP.d.ts} +4 -4
  43. package/dist/types/index.d.ts +15 -15
  44. package/dist/utils/index.d.ts +1 -1
  45. package/package.json +1 -1
@@ -1,9 +1,9 @@
1
- export { A as AfterIterationHook, p as AfterRunHook, q as AfterToolExecutionHook, s as AgentExtension, B as BeforeIterationHook, w as BeforeRunHook, x as BeforeToolExecutionHook, E as ExtensionRegistry, O as OnErrorHook, G as ProviderRunnerFn, z as ProviderRunnerWrapper } from '../index-DPLJw_ZI.js';
2
- import '../context-CLZXPPYk.js';
1
+ export { A as AfterIterationHook, p as AfterRunHook, q as AfterToolExecutionHook, s as AgentExtension, B as BeforeIterationHook, w as BeforeRunHook, x as BeforeToolExecutionHook, E as ExtensionRegistry, O as OnErrorHook, G as ProviderRunnerFn, z as ProviderRunnerWrapper } from '../index-j2WyAyML.js';
2
+ import '../context-CDRyrkKQ.js';
3
3
  import '../logger-BMQgxvdy.js';
4
- import '../system-prompt-DI4Dtc1I.js';
4
+ import '../system-prompt-Dl2QY1_B.js';
5
5
  import '../observability-BhnVLBLS.js';
6
- import '../events-qnDZbrtb.js';
7
- import '../secret-scrubber-BhJTNr9v.js';
8
- import '../config-BgM0BIpz.js';
6
+ import '../events-DPQKFX7W.js';
7
+ import '../secret-scrubber-CfMdAJ_l.js';
8
+ import '../config-BGGuP_Ar.js';
9
9
  import '../models-registry-Y2xbog0E.js';
@@ -1,9 +1,98 @@
1
- import { M as MultiAgentConfig, i as SubagentRunner, c as SubagentConfig, k as TaskSpec, j as TaskResult, a as CoordinatorStatus, b as MultiAgentCoordinator, S as SpawnResult, l as BridgeMessage, A as AgentBridge } from './multi-agent-Cv8wk47i.js';
2
- import { r as SessionWriter, v as Tool, p as SessionStore } from './context-CLZXPPYk.js';
3
- import { I as InMemoryAgentBridge } from './agent-bridge-B07AYFBk.js';
4
- import { E as EventBus } from './events-qnDZbrtb.js';
1
+ import { a as DirectorStateSnapshot } from './director-state-BmYi3DGA.js';
2
+ import { c as SubagentConfig, j as TaskResult, a as CoordinatorStatus, k as TaskSpec, M as MultiAgentConfig, i as SubagentRunner, b as MultiAgentCoordinator, S as SpawnResult, l as BridgeMessage, A as AgentBridge } from './multi-agent-Cpp7FXUl.js';
3
+ import { r as SessionWriter, v as Tool, p as SessionStore } from './context-CDRyrkKQ.js';
4
+ import { I as InMemoryAgentBridge } from './agent-bridge-BKNiE1VH.js';
5
+ import { E as EventBus } from './events-DPQKFX7W.js';
5
6
  import { EventEmitter } from 'node:events';
6
- import { r as Agent, u as AgentInput } from './index-DPLJw_ZI.js';
7
+ import { r as Agent, u as AgentInput } from './index-j2WyAyML.js';
8
+
9
+ /**
10
+ * Interface for a fleet coordinator. Implemented by both `Director`
11
+ * (full LLM-driven orchestration with fleet policy) and
12
+ * `DefaultMultiAgentCoordinator` (direct API-driven, no fleet policy).
13
+ *
14
+ * External callers — CLI slash commands, tests, the delegate tool —
15
+ * use this to stay agnostic to the orchestration mode.
16
+ *
17
+ * The interface captures the **orchestration contract**: spawn, assign,
18
+ * terminate, await, and query. Fleet-level policy (cost caps, manifest
19
+ * writing, checkpointing) lives behind this surface and is optional
20
+ * from the caller's perspective.
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * let coordinator: ICoordinator = isDirectorMode
25
+ * ? new Director({ config, ... })
26
+ * : new DefaultMultiAgentCoordinator(config);
27
+ * const id = await coordinator.spawn({ name: 'worker', role: 'researcher' });
28
+ * await coordinator.assign({ id: 't-1', description: 'research X', subagentId: id });
29
+ * const results = await coordinator.awaitTasks(['t-1']);
30
+ * ```
31
+ */
32
+ interface ICoordinator {
33
+ /** Stable identifier for this coordinator instance. */
34
+ readonly coordinatorId: string;
35
+ /**
36
+ * Spawn a new subagent and return its id. In director mode this
37
+ * enforces fleet-wide spawn caps and cost limits; in raw coordinator
38
+ * mode it is a direct pass-through.
39
+ */
40
+ spawn(config: SubagentConfig): Promise<string>;
41
+ /**
42
+ * Assign a task to a subagent (or to the fleet for auto-routing).
43
+ * Returns the assigned task id.
44
+ */
45
+ assign(task: {
46
+ id: string;
47
+ description: string;
48
+ subagentId?: string;
49
+ }): Promise<string>;
50
+ /**
51
+ * Synchronously ask a subagent something via the in-memory bridge.
52
+ * The subagent must have been spawned and must handle `bridge.subscribe()`
53
+ * in its task loop. Returns the reply payload or throws on timeout.
54
+ *
55
+ * Only available in director mode — raw coordinator has no bridge.
56
+ */
57
+ ask<T = unknown>(subagentId: string, payload: unknown, timeoutMs?: number): Promise<T>;
58
+ /**
59
+ * Wait for one or more tasks to complete and return their results.
60
+ * If a task is already done when called, returns immediately.
61
+ * Resolves to an array in the same order as `taskIds`.
62
+ */
63
+ awaitTasks(taskIds: string[]): Promise<TaskResult[]>;
64
+ /**
65
+ * Gracefully stop a single subagent. The subagent finishes its current
66
+ * in-flight work and exits cleanly — it does not hard-kill.
67
+ */
68
+ terminate(subagentId: string): Promise<void>;
69
+ /**
70
+ * Stop all subagents. In-flight tasks are allowed to complete;
71
+ * no new tasks are dispatched.
72
+ */
73
+ terminateAll(): Promise<void>;
74
+ /**
75
+ * Live coordinator status — subagent list, pending task count,
76
+ * completed task count, iteration totals.
77
+ */
78
+ status(): CoordinatorStatus;
79
+ /**
80
+ * Snapshot of completed task results. In director mode this returns
81
+ * every `TaskResult` from the fleet; in raw coordinator mode this
82
+ * may return an empty array if the coordinator doesn't cache results.
83
+ */
84
+ completedResults(): TaskResult[];
85
+ /**
86
+ * Subscribe to coordinator lifecycle events. Currently supports
87
+ * `task.completed` — the payload carries the task spec and result.
88
+ *
89
+ * Returns a disposer function; call it to unsubscribe.
90
+ */
91
+ on(event: 'task.completed', handler: (payload: {
92
+ task: TaskSpec;
93
+ result: TaskResult;
94
+ }) => void): () => void;
95
+ }
7
96
 
8
97
  /**
9
98
  * Single fleet-wide event with subagent attribution. Whatever a child
@@ -117,6 +206,215 @@ declare class FleetUsageAggregator {
117
206
  private onIterationStarted;
118
207
  }
119
208
 
209
+ /**
210
+ * Interface for fleet-level lifecycle and policy. Covers:
211
+ * - Spawn lifecycle hooks (canSpawn check, recordSpawn after-effects)
212
+ * - Budget enforcement (fleet-wide cost cap, spawn count/depth caps)
213
+ * - Fleet manifest assembly and writing
214
+ * - Subagent metadata and usage tracking
215
+ *
216
+ * `FleetBus` is pure event fan-out and implements no policy.
217
+ * `FleetManager` encapsulates all fleet-level policy decisions.
218
+ * `Director` currently owns all of this — this interface lets us
219
+ * extract it into a swappable component in Phase 5.
220
+ */
221
+ interface IFleetManager {
222
+ /** The FleetBus this manager publishes lifecycle events to. */
223
+ readonly fleetBus: FleetBus;
224
+ /**
225
+ * Snapshot of fleet-wide token usage and cost rollup.
226
+ * Safe to call from a tool's execute() body.
227
+ */
228
+ snapshot(): FleetUsage;
229
+ /**
230
+ * Per-subagent metadata captured at spawn time (provider/model/name).
231
+ * Returns undefined if the subagent is not known to this manager.
232
+ */
233
+ getSubagentMeta(id: string): {
234
+ provider?: string;
235
+ model?: string;
236
+ name?: string;
237
+ } | undefined;
238
+ /**
239
+ * Called before a spawn is recorded. Returns a reason string if the
240
+ * spawn should be rejected (budget cap, depth limit, cost cap, etc.),
241
+ * or null to proceed. Director.spawn() calls this internally.
242
+ */
243
+ canSpawn(config: SubagentConfig): {
244
+ kind: 'max_spawns' | 'max_spawn_depth' | 'max_cost_usd';
245
+ limit: number;
246
+ observed: number;
247
+ } | null;
248
+ /**
249
+ * Called after a spawn succeeds. Records metadata for the usage
250
+ * aggregator and manifest.
251
+ *
252
+ * @param priceLookup Per-token rate lookup for cost calculation.
253
+ * When omitted the cost column in usage snapshots stays at 0.
254
+ */
255
+ recordSpawn(subagentId: string, config: SubagentConfig, priceLookup?: Record<string, number>): void;
256
+ /**
257
+ * Write the fleet manifest to disk. Returns the path written
258
+ * or null when no manifest path is configured.
259
+ */
260
+ writeManifest(): Promise<string | null>;
261
+ /**
262
+ * Aggregate fleet-wide status: pending tasks with descriptions and
263
+ * live subagent snapshot from the coordinator. Used by
264
+ * `MultiAgentHost.status()` to eliminate host-side state duplication.
265
+ */
266
+ getFleetStatus(): {
267
+ pending: {
268
+ taskId: string;
269
+ description: string;
270
+ subagentId: string;
271
+ }[];
272
+ live: {
273
+ subagentId: string;
274
+ status: string;
275
+ task?: string;
276
+ }[];
277
+ };
278
+ /**
279
+ * Register a pending task with its description. Called by
280
+ * `MultiAgentHost.spawn()` after `_spawnAndAssign()` returns so
281
+ * the description is available in `status()` without host-side storage.
282
+ */
283
+ addPendingTask(taskId: string, subagentId: string, description: string): void;
284
+ /**
285
+ * Remove a pending task. Called when the task completes so the
286
+ * pending list stays accurate.
287
+ */
288
+ removePendingTask(taskId: string): void;
289
+ }
290
+
291
+ /** Options for constructing a FleetManager. */
292
+ interface FleetManagerOptions {
293
+ manifestPath?: string;
294
+ sessionsRoot?: string;
295
+ directorRunId?: string;
296
+ maxSpawns?: number;
297
+ maxSpawnDepth?: number;
298
+ spawnDepth?: number;
299
+ stateCheckpointPath?: string;
300
+ sessionWriter?: SessionWriter;
301
+ manifestDebounceMs?: number;
302
+ checkpointDebounceMs?: number;
303
+ directorBudget?: {
304
+ maxCostUsd?: number;
305
+ };
306
+ }
307
+ /**
308
+ * Fleet-level policy container extracted from `Director`. Owns:
309
+ * - FleetBus + FleetUsageAggregator
310
+ * - Spawn caps and counters
311
+ * - Manifest entries and debounced writing
312
+ * - State checkpointing
313
+ *
314
+ * This lets the `Director` focus on orchestration (spawn/assign/await/ask)
315
+ * while fleet-level decisions live in one place. The class implements
316
+ * `IFleetManager` so it remains swappable in future.
317
+ *
318
+ * @example
319
+ * ```typescript
320
+ * const fm = new FleetManager({ manifestPath: '/tmp/fleet.json' });
321
+ * const err = fm.canSpawn({ name: 'worker' });
322
+ * if (!err) fm.recordSpawn('sub-1', { name: 'worker' });
323
+ * await fm.writeManifest();
324
+ * ```
325
+ */
326
+ declare class FleetManager implements IFleetManager {
327
+ /** The fleet-wide event bus. */
328
+ readonly fleet: FleetBus;
329
+ /** Usage rollup across all subagents. */
330
+ readonly usage: FleetUsageAggregator;
331
+ private readonly manifestPath?;
332
+ private readonly sessionsRoot?;
333
+ private readonly directorRunId;
334
+ /** Spawn cap (lifetime total). Infinity means unlimited. */
335
+ readonly maxSpawns: number;
336
+ /** Nesting cap. */
337
+ readonly maxSpawnDepth: number;
338
+ /** This director's depth in a director chain. Root = 0. */
339
+ readonly spawnDepth: number;
340
+ /** Live spawn counter. */
341
+ private spawnCount;
342
+ private readonly stateCheckpoint;
343
+ private readonly sessionWriter;
344
+ private manifestTimer;
345
+ private readonly manifestDebounceMs;
346
+ /** Fleet-wide cost cap. Infinity = no cap. Distinct from SubagentBudget limits,
347
+ * which track per-subagent spend — this field caps the entire fleet total. */
348
+ private readonly maxFleetCostUsd;
349
+ private readonly manifestEntries;
350
+ /** Pending tasks with their descriptions — populated by `addPendingTask`
351
+ * and cleared by `removePendingTask`. Replaces the host-side `pending`
352
+ * Map so task descriptions live in one place (FleetManager). */
353
+ private readonly pendingTasks;
354
+ private readonly subagentMeta;
355
+ private readonly priceLookups;
356
+ constructor(opts?: FleetManagerOptions);
357
+ get fleetBus(): FleetBus;
358
+ snapshot(): FleetUsage;
359
+ getSubagentMeta(id: string): {
360
+ provider?: string;
361
+ model?: string;
362
+ name?: string;
363
+ } | undefined;
364
+ /**
365
+ * Returns null if the spawn is allowed, or an object describing
366
+ * which cap was exceeded. Does NOT throw — the caller decides
367
+ * how to surface the rejection.
368
+ */
369
+ canSpawn(config: SubagentConfig): {
370
+ kind: 'max_spawns' | 'max_spawn_depth' | 'max_cost_usd';
371
+ limit: number;
372
+ observed: number;
373
+ } | null;
374
+ /**
375
+ * Records a spawn: increments counter, stores metadata, updates state checkpoint,
376
+ * and schedules a debounced manifest write. Call AFTER the coordinator
377
+ * has successfully spawned the subagent.
378
+ *
379
+ * @param subagentId The subagent's id (from coordinator.spawn result)
380
+ * @param config The SubagentConfig that was used
381
+ * @param priceLookup Optional per-subagent pricing data
382
+ */
383
+ recordSpawn(subagentId: string, config: SubagentConfig, priceLookup?: {
384
+ input?: number;
385
+ output?: number;
386
+ cacheRead?: number;
387
+ cacheWrite?: number;
388
+ }): void;
389
+ writeManifest(): Promise<string | null>;
390
+ /**
391
+ * Attach task ids to an already-spawned subagent. Called by
392
+ * `Director.assign()` after the coordinator assigns a task.
393
+ */
394
+ addTaskToSubagent(subagentId: string, taskId: string): void;
395
+ /**
396
+ * Debounced manifest write. Call after any state mutation
397
+ * (spawn, assign, complete) so a burst collapses into one write.
398
+ */
399
+ scheduleManifest(): void;
400
+ /** Best-effort session event writer. Swallows failures. */
401
+ private appendSessionEvent;
402
+ addPendingTask(taskId: string, subagentId: string, description: string): void;
403
+ removePendingTask(taskId: string): void;
404
+ getFleetStatus(): {
405
+ pending: {
406
+ taskId: string;
407
+ description: string;
408
+ subagentId: string;
409
+ }[];
410
+ live: {
411
+ subagentId: string;
412
+ status: string;
413
+ task?: string;
414
+ }[];
415
+ };
416
+ }
417
+
120
418
  /**
121
419
  * Director — high-level orchestrator that owns a `MultiAgentCoordinator`,
122
420
  * a `FleetBus`, and a `FleetUsageAggregator`. Exposes a small imperative
@@ -174,7 +472,7 @@ interface DirectorOptions {
174
472
  * lifetime. Default: unlimited. Acts as a hard fleet-wide cost cap —
175
473
  * a runaway leader that keeps spawning workers gets cut off cleanly
176
474
  * instead of burning provider tokens until the user kills the
177
- * process. The N+1-th spawn call rejects with a `DirectorBudgetError`.
475
+ * process. The N+1-th spawn call rejects with a `FleetSpawnBudgetError`.
178
476
  */
179
477
  maxSpawns?: number;
180
478
  /**
@@ -217,6 +515,65 @@ interface DirectorOptions {
217
515
  * writes (the manifest will then only be written on `shutdown()`).
218
516
  */
219
517
  manifestDebounceMs?: number;
518
+ /**
519
+ * Fleet-wide cost ceiling. When set, `spawn()` refuses any new subagent
520
+ * that would push the fleet's total cost above this limit. The cap
521
+ * is checked BEFORE the spawn is recorded — a refused spawn must not
522
+ * leak partial state into the manifest or fleet bus. Let in-flight
523
+ * tasks complete; refuse new spawns only. When omitted or Infinity,
524
+ * no cost cap applies.
525
+ *
526
+ * Distinct from SubagentBudget.maxCostUsd (per-subagent spend) — this
527
+ * field caps the *entire fleet* total.
528
+ */
529
+ directorBudget?: {
530
+ /**
531
+ * Maximum total USD the fleet may spend across all subagents.
532
+ * Default: Infinity (no cap).
533
+ */
534
+ maxCostUsd?: number;
535
+ };
536
+ /**
537
+ * Maximum auto-extensions per subagent per budget kind before the
538
+ * director denies further extensions. A subagent hitting the same
539
+ * soft limit repeatedly (e.g. 3× budget.threshold_reached for
540
+ * tool_calls) is likely looping on a prompt/config issue, not
541
+ * making legitimate progress. Default: 2. Set to Infinity to
542
+ * disable the cap (use with caution — a misconfigured subagent
543
+ * could burn unlimited budget).
544
+ */
545
+ maxBudgetExtensions?: number;
546
+ /**
547
+ * Debounce window for state-checkpoint writes. Default: 250ms.
548
+ * Bursts of spawn/assign/complete events collapse into one disk
549
+ * hit. Higher values reduce write amplification on fast machines;
550
+ * lower values improve crash-recovery fidelity (less state lost
551
+ * on sudden process exit).
552
+ */
553
+ checkpointDebounceMs?: number;
554
+ /**
555
+ * Sessions root directory for per-subagent JSONL transcripts.
556
+ * When set, the director can read subagent transcripts directly for
557
+ * `fleet_session` tool — no bridge round-trip needed. Path convention:
558
+ * `<sessionsRoot>/<directorRunId>/<subagentId>.jsonl`.
559
+ */
560
+ sessionsRoot?: string;
561
+ /**
562
+ * Director run id — namespaced under `sessionsRoot` to locate per-subagent
563
+ * JSONLs. Defaults to the director's own `id` when omitted.
564
+ */
565
+ directorRunId?: string;
566
+ /**
567
+ * Pre-built fleet manager. When provided the Director delegates all
568
+ * fleet-level policy (spawn budgets, manifest assembly, checkpointing)
569
+ * to this instance and takes ownership of the coordinator + bridge
570
+ * layer only. This enables unit-testing fleet policy in isolation
571
+ * and swapping implementations without changing the Director surface.
572
+ *
573
+ * When omitted the Director creates its own fleet infrastructure
574
+ * (same behavior as before this field was added).
575
+ */
576
+ fleetManager?: FleetManager;
220
577
  }
221
578
  /**
222
579
  * Thrown by `Director.spawn()` when a configured spawn cap (`maxSpawns`,
@@ -224,16 +581,44 @@ interface DirectorOptions {
224
581
  * the `spawn_subagent` tool surface — can recognize the budget case and
225
582
  * report it cleanly instead of treating it like an unexpected failure.
226
583
  */
227
- declare class DirectorBudgetError extends Error {
584
+ declare class FleetSpawnBudgetError extends Error {
228
585
  readonly kind: 'max_spawns' | 'max_spawn_depth';
229
586
  readonly limit: number;
230
587
  readonly observed: number;
231
588
  constructor(kind: 'max_spawns' | 'max_spawn_depth', limit: number, observed: number);
232
589
  }
233
- declare class Director {
590
+ /**
591
+ * Thrown by `Director.spawn()` when the fleet-wide cost cap is exceeded.
592
+ * Distinct from `FleetSpawnBudgetError` (spawn count/depth) — this is a
593
+ * dollar-denominated ceiling that tracks cumulative spend across all
594
+ * subagents in the fleet.
595
+ */
596
+ declare class FleetCostCapError extends Error {
597
+ readonly kind: 'max_cost_usd';
598
+ readonly limit: number;
599
+ readonly observed: number;
600
+ constructor(limit: number, observed: number);
601
+ }
602
+ declare class Director implements ICoordinator {
603
+ /** Alias for the ICoordinator contract. `id` is retained for backward compatibility. */
604
+ get coordinatorId(): string;
234
605
  readonly id: string;
606
+ /**
607
+ * The fleet event bus. Backed by `fleetManager?.fleet` when a FleetManager
608
+ * is injected; otherwise own FleetBus instance (preserves existing behavior).
609
+ */
235
610
  readonly fleet: FleetBus;
611
+ /**
612
+ * Usage rollup. Backed by `fleetManager?.usage` when a FleetManager is
613
+ * injected; otherwise own FleetUsageAggregator.
614
+ */
236
615
  readonly usage: FleetUsageAggregator;
616
+ /**
617
+ * Optional fleet-level policy container. When provided the Director
618
+ * delegates spawn budgeting, manifest entries, and checkpointing to it
619
+ * instead of managing those internally. All other behavior is unchanged.
620
+ */
621
+ readonly fleetManager: FleetManager | undefined;
237
622
  /**
238
623
  * Director-side bridge endpoint. Subagents are wired to the same
239
624
  * in-memory transport so the director can `ask()` them synchronously
@@ -284,6 +669,14 @@ declare class Director {
284
669
  /** Debounce timer for periodic manifest writes. */
285
670
  private manifestTimer;
286
671
  private readonly manifestDebounceMs;
672
+ /** Fleet-wide cost cap (entire fleet total, distinct from SubagentBudget limits). Infinity means no cap. */
673
+ private readonly maxFleetCostUsd;
674
+ /** Max auto-extensions per subagent per budget kind before denying. */
675
+ private readonly maxBudgetExtensions;
676
+ /** Sessions root for direct subagent JSONL reads (fleet_session tool). */
677
+ private readonly sessionsRoot?;
678
+ /** Director run id for JSONL path resolution. */
679
+ private readonly directorRunId;
287
680
  /** Resolves task descriptions back from `assign()` so completion events
288
681
  * can also carry a human-readable title. */
289
682
  private readonly taskDescriptions;
@@ -404,6 +797,28 @@ declare class Director {
404
797
  * paint the completed table without reaching into private state.
405
798
  */
406
799
  completedResults(): TaskResult[];
800
+ /**
801
+ * Inject a previously-saved checkpoint snapshot. Call this right after
802
+ * constructing a Director during a `--resume` run so the in-memory state
803
+ * (subagents, tasks, waiters) reflects the pre-crash reality instead of
804
+ * starting from a blank slate. The director then resumes from there —
805
+ * completing any in-flight tasks and ignoring tasks that already reached
806
+ * a terminal state in the prior run.
807
+ */
808
+ setCheckpointState(snapshot: DirectorStateSnapshot): void;
809
+ /**
810
+ * Read a subagent's JSONL transcript directly from disk (no bridge
811
+ * round-trip needed). Returns the last assistant text, stop reason,
812
+ * tool-use count, and line count — or null if the file is unavailable.
813
+ * Requires `sessionsRoot` to be set on construction.
814
+ */
815
+ readSession(subagentId: string, tail?: number): Promise<{
816
+ lastAssistantText?: string;
817
+ lastStopReason?: string;
818
+ toolUsesObserved: number;
819
+ events: number;
820
+ path?: string;
821
+ } | null>;
407
822
  snapshot(): FleetUsage;
408
823
  /**
409
824
  * Look up provider/model metadata for a spawned subagent. Returns
@@ -453,6 +868,18 @@ declare class Director {
453
868
  * still permission-checked normally.
454
869
  */
455
870
  tools(roster?: Record<string, SubagentConfig>): Tool[];
871
+ /**
872
+ * Attempt to acquire the checkpoint lock. Must be called before
873
+ * resuming — if another director process is alive, this returns
874
+ * false and the caller should not proceed with the resume.
875
+ */
876
+ acquireCheckpointLock(): Promise<boolean>;
877
+ /**
878
+ * Resume from a prior checkpoint snapshot (loaded via
879
+ * `loadDirectorState()`). Re-attach to the fleet mid-flight so
880
+ * subsequent spawn/assign calls update the checkpoint normally.
881
+ */
882
+ resumeFromCheckpoint(snapshot: DirectorStateSnapshot): void;
456
883
  }
457
884
 
458
885
  /**
@@ -511,6 +938,13 @@ interface CreateDelegateToolOptions {
511
938
  * JSONLs at `<sessionsRoot>/<runId>/<subagentId>.jsonl`.
512
939
  */
513
940
  directorRunId?: string;
941
+ /**
942
+ * Buffer subtracted from the caller's `timeoutMs` before passing it
943
+ * to the subagent. Gives the host a window to detect a subagent that
944
+ * has gone silent and surface a partial result rather than a generic
945
+ * timeout. Default: 30_000 ms.
946
+ */
947
+ subagentTimeoutBufferMs?: number;
514
948
  }
515
949
  /**
516
950
  * `delegate` — the only multi-agent tool a regular (non-director) agent
@@ -896,4 +1330,13 @@ declare function applyRosterBudget(cfg: SubagentConfig): SubagentConfig;
896
1330
  /** Quick-access list for spawning all at once. */
897
1331
  declare const ALL_FLEET_AGENTS: SubagentConfig[];
898
1332
 
899
- export { ALL_FLEET_AGENTS as A, BUG_HUNTER_AGENT as B, type CreateDelegateToolOptions as C, DEFAULT_DIRECTOR_PREAMBLE as D, rosterSummaryFromConfigs as E, FLEET_ROSTER as F, type MultiAgentCoordinatorOptions as M, REFACTOR_PLANNER_AGENT as R, SECURITY_SCANNER_AGENT as S, AUDIT_LOG_AGENT as a, type AgentFactory as b, type AgentFactoryResult as c, type AgentRunnerOptions as d, DEFAULT_SUBAGENT_BASELINE as e, DefaultMultiAgentCoordinator as f, type DelegateHost as g, Director as h, DirectorBudgetError as i, type DirectorPromptParts as j, type DirectorSessionFactory as k, type DirectorSessionFactoryOptions as l, FLEET_ROSTER_BUDGETS as m, FleetBus as n, type FleetEvent as o, type FleetHandler as p, type FleetUsage as q, FleetUsageAggregator as r, type SubagentPromptParts as s, type SubagentUsageSnapshot as t, applyRosterBudget as u, composeDirectorPrompt as v, composeSubagentPrompt as w, createDelegateTool as x, makeAgentSubagentRunner as y, makeDirectorSessionFactory as z };
1333
+ /**
1334
+ * A no-op FleetBus that discards all events. Used when no real fleet
1335
+ * bus is available (non-director mode) so the runner's `fleetBus`
1336
+ * field is always valid and the `attach()` call is always safe.
1337
+ *
1338
+ * One singleton instance is sufficient — it has no state to reset.
1339
+ */
1340
+ declare const NULL_FLEET_BUS: FleetBus;
1341
+
1342
+ export { ALL_FLEET_AGENTS as A, BUG_HUNTER_AGENT as B, type CreateDelegateToolOptions as C, DEFAULT_DIRECTOR_PREAMBLE as D, createDelegateTool as E, FLEET_ROSTER as F, makeAgentSubagentRunner as G, makeDirectorSessionFactory as H, type ICoordinator as I, rosterSummaryFromConfigs as J, FleetCostCapError as K, type MultiAgentCoordinatorOptions as M, NULL_FLEET_BUS as N, REFACTOR_PLANNER_AGENT as R, SECURITY_SCANNER_AGENT as S, AUDIT_LOG_AGENT as a, type AgentFactory as b, type AgentFactoryResult as c, type AgentRunnerOptions as d, DEFAULT_SUBAGENT_BASELINE as e, DefaultMultiAgentCoordinator as f, type DelegateHost as g, Director as h, type DirectorPromptParts as i, type DirectorSessionFactory as j, type DirectorSessionFactoryOptions as k, FLEET_ROSTER_BUDGETS as l, FleetBus as m, type FleetEvent as n, type FleetHandler as o, FleetManager as p, type FleetManagerOptions as q, FleetSpawnBudgetError as r, type FleetUsage as s, FleetUsageAggregator as t, type IFleetManager as u, type SubagentPromptParts as v, type SubagentUsageSnapshot as w, applyRosterBudget as x, composeDirectorPrompt as y, composeSubagentPrompt as z };
@@ -1,10 +1,10 @@
1
- import { v as Tool, B as ToolResultBlock, T as TextBlock, a2 as Context, R as Request, j as Response, G as ToolUseBlock, g as Provider, W as WrongStackError, b as ContentBlock, aa as RunOptions, J as JSONSchema } from './context-CLZXPPYk.js';
1
+ import { v as Tool, B as ToolResultBlock, T as TextBlock, a2 as Context, R as Request, j as Response, G as ToolUseBlock, g as Provider, W as WrongStackError, b as ContentBlock, aa as RunOptions, J as JSONSchema } from './context-CDRyrkKQ.js';
2
2
  import { L as Logger } from './logger-BMQgxvdy.js';
3
- import { R as Renderer, B as BuildContext, C as Container, P as Pipeline, e as ReadonlyPipeline } from './system-prompt-DI4Dtc1I.js';
3
+ import { R as Renderer, B as BuildContext, C as Container, P as Pipeline, e as ReadonlyPipeline } from './system-prompt-Dl2QY1_B.js';
4
4
  import { T as Tracer } from './observability-BhnVLBLS.js';
5
- import { E as EventBus, a as EventName, L as Listener } from './events-qnDZbrtb.js';
6
- import { a as PermissionPolicy, S as SecretScrubber } from './secret-scrubber-BhJTNr9v.js';
7
- import { l as ProviderConfig, a as Config } from './config-BgM0BIpz.js';
5
+ import { E as EventBus, a as EventName, L as Listener } from './events-DPQKFX7W.js';
6
+ import { a as PermissionPolicy, S as SecretScrubber } from './secret-scrubber-CfMdAJ_l.js';
7
+ import { l as ProviderConfig, a as Config } from './config-BGGuP_Ar.js';
8
8
  import { W as WireFamily } from './models-registry-Y2xbog0E.js';
9
9
 
10
10
  /**
@@ -440,6 +440,19 @@ interface AgentInit {
440
440
  * emit `iteration.limit_reached` and wait for a listener to grant/deny.
441
441
  */
442
442
  autoExtendLimit?: boolean;
443
+ /**
444
+ * When true, the agent supports autonomous continuation — the model
445
+ * can signal "keep going" either via the `continue_to_next_iteration()`
446
+ * tool or by placing a `[continue]` / `[next step]` / `[proceed]` /
447
+ * `[done]` marker on its own line in the final text output. The agent
448
+ * loop re-runs without returning to the caller when `continue` is
449
+ * signalled, or exits with `status: 'done'` when `stop` is signalled.
450
+ *
451
+ * The text-marker parser runs in `processResponse()` before the
452
+ * loop-exit check so markers in the final text block are honoured
453
+ * even when no tool was called.
454
+ */
455
+ autonomousContinue?: boolean;
443
456
  /**
444
457
  * Optional confirm handler. When set, the executor calls it synchronously
445
458
  * when a tool needs user confirmation (CLI path). When omitted, the
@@ -507,6 +520,8 @@ declare class Agent {
507
520
  private readonly plugins;
508
521
  private readonly toolExecutor;
509
522
  private readonly autoExtendLimit;
523
+ /** Enables autonomous continue: model can signal `[continue]` or call continue_to_next_iteration() to re-run. */
524
+ private readonly autonomousContinue;
510
525
  private readonly tracer;
511
526
  readonly extensions: ExtensionRegistry;
512
527
  constructor(init: AgentInit);