@wrongstack/core 0.5.6 → 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 (42) 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 +9 -9
  6. package/dist/coordination/index.js +301 -58
  7. package/dist/coordination/index.js.map +1 -1
  8. package/dist/defaults/index.d.ts +18 -18
  9. package/dist/defaults/index.js +124 -61
  10. package/dist/defaults/index.js.map +1 -1
  11. package/dist/{events-qnDZbrtb.d.ts → events-DPQKFX7W.d.ts} +1 -1
  12. package/dist/execution/index.d.ts +18 -11
  13. package/dist/execution/index.js +19 -3
  14. package/dist/execution/index.js.map +1 -1
  15. package/dist/extension/index.d.ts +6 -6
  16. package/dist/{index-BDnUCRvL.d.ts → index-Bf9Bpkdc.d.ts} +351 -15
  17. package/dist/{index-DPLJw_ZI.d.ts → index-j2WyAyML.d.ts} +20 -5
  18. package/dist/index.d.ts +107 -27
  19. package/dist/index.js +417 -84
  20. package/dist/index.js.map +1 -1
  21. package/dist/infrastructure/index.d.ts +6 -6
  22. package/dist/kernel/index.d.ts +9 -9
  23. package/dist/{mcp-servers-CSMfaBuL.d.ts → mcp-servers-DBdh3cee.d.ts} +3 -3
  24. package/dist/models/index.d.ts +2 -2
  25. package/dist/{multi-agent-Cv8wk47i.d.ts → multi-agent-Cpp7FXUl.d.ts} +11 -3
  26. package/dist/observability/index.d.ts +2 -2
  27. package/dist/{path-resolver-DiCUvEg6.d.ts → path-resolver--g_hKJ7V.d.ts} +2 -2
  28. package/dist/{plan-templates-DaxTCPfk.d.ts → plan-templates-Bveo2W8n.d.ts} +4 -4
  29. package/dist/{provider-runner-3SHqk9zB.d.ts → provider-runner-hl4Il3xS.d.ts} +3 -3
  30. package/dist/{retry-policy-LLUxJmYY.d.ts → retry-policy-LKS8MHsB.d.ts} +1 -1
  31. package/dist/sdd/index.d.ts +3 -3
  32. package/dist/{secret-scrubber-Z_VXuXQT.d.ts → secret-scrubber-BzQR5BiL.d.ts} +1 -1
  33. package/dist/{secret-scrubber-BhJTNr9v.d.ts → secret-scrubber-CfMdAJ_l.d.ts} +1 -1
  34. package/dist/security/index.d.ts +3 -3
  35. package/dist/{selector-DB2-byKH.d.ts → selector-C7HqnZJU.d.ts} +1 -1
  36. package/dist/{session-reader-4jxsYLZ8.d.ts → session-reader-CzfRA6Vk.d.ts} +1 -1
  37. package/dist/storage/index.d.ts +5 -5
  38. package/dist/{system-prompt-DI4Dtc1I.d.ts → system-prompt-Dl2QY1_B.d.ts} +1 -1
  39. package/dist/{tool-executor-DSvmOBe6.d.ts → tool-executor-DbAFkHdP.d.ts} +4 -4
  40. package/dist/types/index.d.ts +15 -15
  41. package/dist/utils/index.d.ts +1 -1
  42. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { B as BridgeTransport, l as BridgeMessage, A as AgentBridge, m as AgentBridgeConfig } from './multi-agent-Cv8wk47i.js';
1
+ import { B as BridgeTransport, l as BridgeMessage, A as AgentBridge, m as AgentBridgeConfig } from './multi-agent-Cpp7FXUl.js';
2
2
 
3
3
  /**
4
4
  * In-memory pub/sub transport for agent-to-agent messaging.
@@ -1,4 +1,4 @@
1
- import { a2 as Context } from './context-CLZXPPYk.js';
1
+ import { a2 as Context } from './context-CDRyrkKQ.js';
2
2
 
3
3
  interface CompactRepairReport {
4
4
  removedToolUses: string[];
@@ -1,5 +1,5 @@
1
1
  import { W as WireFamily } from './models-registry-Y2xbog0E.js';
2
- import { P as Permission } from './context-CLZXPPYk.js';
2
+ import { P as Permission } from './context-CDRyrkKQ.js';
3
3
 
4
4
  type ContextWindowModeId = 'balanced' | 'frugal' | 'deep' | 'archival';
5
5
  type ContextWindowAggressiveOn = 'hard' | 'soft' | 'warn';
@@ -887,6 +887,13 @@ interface RunOptions {
887
887
  model?: string;
888
888
  executionStrategy?: 'parallel' | 'sequential' | 'smart';
889
889
  maxIterations?: number;
890
+ /**
891
+ * Enable autonomous continue for this specific run. When true, the agent
892
+ * loop re-runs on `[continue]`/`[next step]`/`[proceed]` markers or
893
+ * `continue_to_next_iteration()` tool calls instead of returning.
894
+ * Overrides `AgentInit.autonomousContinue` for this call only.
895
+ */
896
+ autonomousContinue?: boolean;
890
897
  }
891
898
  interface ContextInit {
892
899
  systemPrompt: TextBlock[];
@@ -1,14 +1,14 @@
1
- export { A as ALL_FLEET_AGENTS, a as AUDIT_LOG_AGENT, b as AgentFactory, c as AgentFactoryResult, d as AgentRunnerOptions, B as BUG_HUNTER_AGENT, C as CreateDelegateToolOptions, D as DEFAULT_DIRECTOR_PREAMBLE, e as DEFAULT_SUBAGENT_BASELINE, f as DefaultMultiAgentCoordinator, g as DelegateHost, h as Director, i as DirectorBudgetError, G as DirectorCostCapError, j as DirectorPromptParts, k as DirectorSessionFactory, l as DirectorSessionFactoryOptions, F as FLEET_ROSTER, n as FleetBus, o as FleetEvent, p as FleetHandler, q as FleetUsage, r as FleetUsageAggregator, M as MultiAgentCoordinatorOptions, R as REFACTOR_PLANNER_AGENT, S as SECURITY_SCANNER_AGENT, s as SubagentPromptParts, t as SubagentUsageSnapshot, v as composeDirectorPrompt, w as composeSubagentPrompt, x as createDelegateTool, y as makeAgentSubagentRunner, z as makeDirectorSessionFactory, E as rosterSummaryFromConfigs } from '../index-BDnUCRvL.js';
2
- export { n as BudgetExceededError, o as BudgetKind, p as BudgetLimits, s as BudgetThresholdDecision, t as BudgetThresholdHandler, u as BudgetThresholdSignal, q as BudgetUsage, r as SubagentBudget } from '../multi-agent-Cv8wk47i.js';
3
- export { I as InMemoryAgentBridge, a as InMemoryBridgeTransport, c as createMessage } from '../agent-bridge-B07AYFBk.js';
1
+ export { A as ALL_FLEET_AGENTS, a as AUDIT_LOG_AGENT, b as AgentFactory, c as AgentFactoryResult, d as AgentRunnerOptions, B as BUG_HUNTER_AGENT, C as CreateDelegateToolOptions, D as DEFAULT_DIRECTOR_PREAMBLE, e as DEFAULT_SUBAGENT_BASELINE, f as DefaultMultiAgentCoordinator, g as DelegateHost, h as Director, i as DirectorPromptParts, j as DirectorSessionFactory, k as DirectorSessionFactoryOptions, F as FLEET_ROSTER, m as FleetBus, K as FleetCostCapError, n as FleetEvent, o as FleetHandler, p as FleetManager, q as FleetManagerOptions, r as FleetSpawnBudgetError, s as FleetUsage, t as FleetUsageAggregator, I as ICoordinator, u as IFleetManager, M as MultiAgentCoordinatorOptions, N as NULL_FLEET_BUS, R as REFACTOR_PLANNER_AGENT, S as SECURITY_SCANNER_AGENT, v as SubagentPromptParts, w as SubagentUsageSnapshot, y as composeDirectorPrompt, z as composeSubagentPrompt, E as createDelegateTool, G as makeAgentSubagentRunner, H as makeDirectorSessionFactory, J as rosterSummaryFromConfigs } from '../index-Bf9Bpkdc.js';
2
+ export { n as BudgetExceededError, o as BudgetKind, p as BudgetLimits, s as BudgetThresholdDecision, t as BudgetThresholdHandler, u as BudgetThresholdSignal, q as BudgetUsage, r as SubagentBudget } from '../multi-agent-Cpp7FXUl.js';
3
+ export { I as InMemoryAgentBridge, a as InMemoryBridgeTransport, c as createMessage } from '../agent-bridge-BKNiE1VH.js';
4
4
  import '../director-state-BmYi3DGA.js';
5
- import '../context-CLZXPPYk.js';
6
- import '../events-qnDZbrtb.js';
5
+ import '../context-CDRyrkKQ.js';
6
+ import '../events-DPQKFX7W.js';
7
7
  import 'node:events';
8
- import '../index-DPLJw_ZI.js';
8
+ import '../index-j2WyAyML.js';
9
9
  import '../logger-BMQgxvdy.js';
10
- import '../system-prompt-DI4Dtc1I.js';
10
+ import '../system-prompt-Dl2QY1_B.js';
11
11
  import '../observability-BhnVLBLS.js';
12
- import '../secret-scrubber-BhJTNr9v.js';
13
- import '../config-BgM0BIpz.js';
12
+ import '../secret-scrubber-CfMdAJ_l.js';
13
+ import '../config-BGGuP_Ar.js';
14
14
  import '../models-registry-Y2xbog0E.js';
@@ -1631,10 +1631,10 @@ function makeSpawnTool(director, roster) {
1631
1631
  const subagentId = await director.spawn(cfg);
1632
1632
  return { subagentId, provider: cfg.provider, model: cfg.model, name: cfg.name };
1633
1633
  } catch (err) {
1634
- if (err instanceof DirectorBudgetError) {
1634
+ if (err instanceof FleetSpawnBudgetError) {
1635
1635
  return { error: err.message, kind: err.kind, limit: err.limit, observed: err.observed };
1636
1636
  }
1637
- if (err instanceof DirectorCostCapError) {
1637
+ if (err instanceof FleetCostCapError) {
1638
1638
  return { error: err.message, kind: err.kind, limit: err.limit, observed: err.observed };
1639
1639
  }
1640
1640
  return { error: err instanceof Error ? err.message : String(err) };
@@ -1835,7 +1835,7 @@ function makeFleetHealthTool(director) {
1835
1835
  }
1836
1836
 
1837
1837
  // src/coordination/director.ts
1838
- var DirectorBudgetError = class extends Error {
1838
+ var FleetSpawnBudgetError = class extends Error {
1839
1839
  kind;
1840
1840
  limit;
1841
1841
  observed;
@@ -1843,13 +1843,13 @@ var DirectorBudgetError = class extends Error {
1843
1843
  super(
1844
1844
  kind === "max_spawns" ? `Director spawn budget exceeded: tried to spawn #${observed} but maxSpawns is ${limit}` : `Director spawn depth budget exceeded: this director is at depth ${observed} and maxSpawnDepth is ${limit}`
1845
1845
  );
1846
- this.name = "DirectorBudgetError";
1846
+ this.name = "FleetSpawnBudgetError";
1847
1847
  this.kind = kind;
1848
1848
  this.limit = limit;
1849
1849
  this.observed = observed;
1850
1850
  }
1851
1851
  };
1852
- var DirectorCostCapError = class extends Error {
1852
+ var FleetCostCapError = class extends Error {
1853
1853
  kind;
1854
1854
  limit;
1855
1855
  observed;
@@ -1857,16 +1857,34 @@ var DirectorCostCapError = class extends Error {
1857
1857
  super(
1858
1858
  `Director cost cap exceeded: total fleet spend ${observed.toFixed(4)} exceeds maxCostUsd ${limit.toFixed(4)}`
1859
1859
  );
1860
- this.name = "DirectorCostCapError";
1860
+ this.name = "FleetCostCapError";
1861
1861
  this.kind = "max_cost_usd";
1862
1862
  this.limit = limit;
1863
1863
  this.observed = observed;
1864
1864
  }
1865
1865
  };
1866
1866
  var Director = class {
1867
+ /** Alias for the ICoordinator contract. `id` is retained for backward compatibility. */
1868
+ get coordinatorId() {
1869
+ return this.id;
1870
+ }
1867
1871
  id;
1872
+ /**
1873
+ * The fleet event bus. Backed by `fleetManager?.fleet` when a FleetManager
1874
+ * is injected; otherwise own FleetBus instance (preserves existing behavior).
1875
+ */
1868
1876
  fleet;
1877
+ /**
1878
+ * Usage rollup. Backed by `fleetManager?.usage` when a FleetManager is
1879
+ * injected; otherwise own FleetUsageAggregator.
1880
+ */
1869
1881
  usage;
1882
+ /**
1883
+ * Optional fleet-level policy container. When provided the Director
1884
+ * delegates spawn budgeting, manifest entries, and checkpointing to it
1885
+ * instead of managing those internally. All other behavior is unchanged.
1886
+ */
1887
+ fleetManager;
1870
1888
  /**
1871
1889
  * Director-side bridge endpoint. Subagents are wired to the same
1872
1890
  * in-memory transport so the director can `ask()` them synchronously
@@ -1917,8 +1935,8 @@ var Director = class {
1917
1935
  /** Debounce timer for periodic manifest writes. */
1918
1936
  manifestTimer = null;
1919
1937
  manifestDebounceMs;
1920
- /** Fleet-wide cost cap. Infinity means no cap. */
1921
- maxCostUsd;
1938
+ /** Fleet-wide cost cap (entire fleet total, distinct from SubagentBudget limits). Infinity means no cap. */
1939
+ maxFleetCostUsd;
1922
1940
  /** Max auto-extensions per subagent per budget kind before denying. */
1923
1941
  maxBudgetExtensions;
1924
1942
  /** Sessions root for direct subagent JSONL reads (fleet_session tool). */
@@ -1951,7 +1969,7 @@ var Director = class {
1951
1969
  this.spawnDepth = opts.spawnDepth ?? 0;
1952
1970
  this.sessionWriter = opts.sessionWriter ?? null;
1953
1971
  this.manifestDebounceMs = opts.manifestDebounceMs ?? 2e3;
1954
- this.maxCostUsd = opts.directorBudget?.maxCostUsd ?? Number.POSITIVE_INFINITY;
1972
+ this.maxFleetCostUsd = opts.directorBudget?.maxCostUsd ?? Number.POSITIVE_INFINITY;
1955
1973
  this.maxBudgetExtensions = opts.maxBudgetExtensions ?? 2;
1956
1974
  this.sessionsRoot = opts.sessionsRoot;
1957
1975
  this.directorRunId = opts.directorRunId ?? this.id;
@@ -1962,6 +1980,7 @@ var Director = class {
1962
1980
  maxSpawnDepth: this.maxSpawnDepth,
1963
1981
  directorBudget: opts.directorBudget
1964
1982
  }, opts.checkpointDebounceMs ?? 250) : null;
1983
+ this.fleetManager = opts.fleetManager;
1965
1984
  if (this.sharedScratchpadPath) {
1966
1985
  void fsp4.mkdir(this.sharedScratchpadPath, { recursive: true }).catch(() => void 0);
1967
1986
  }
@@ -1970,12 +1989,17 @@ var Director = class {
1970
1989
  { agentId: this.id, coordinatorId: this.id },
1971
1990
  this.transport
1972
1991
  );
1973
- this.fleet = new FleetBus();
1974
- this.usage = new FleetUsageAggregator(
1975
- this.fleet,
1976
- (id) => this.priceLookups.get(id),
1977
- (id) => this.subagentMeta.get(id)
1978
- );
1992
+ if (this.fleetManager) {
1993
+ this.fleet = this.fleetManager.fleet;
1994
+ this.usage = this.fleetManager.usage;
1995
+ } else {
1996
+ this.fleet = new FleetBus();
1997
+ this.usage = new FleetUsageAggregator(
1998
+ this.fleet,
1999
+ (id) => this.priceLookups.get(id),
2000
+ (id) => this.subagentMeta.get(id)
2001
+ );
2002
+ }
1979
2003
  this.coordinator = new DefaultMultiAgentCoordinator(
1980
2004
  { ...opts.config, coordinatorId: this.id },
1981
2005
  { runner: opts.runner }
@@ -2077,58 +2101,73 @@ var Director = class {
2077
2101
  * it the `cost` column in `usage.snapshot()` stays at 0.
2078
2102
  */
2079
2103
  async spawn(config, priceLookup) {
2080
- if (this.spawnDepth >= this.maxSpawnDepth) {
2081
- throw new DirectorBudgetError("max_spawn_depth", this.maxSpawnDepth, this.spawnDepth);
2082
- }
2083
- if (this.spawnCount >= this.maxSpawns) {
2084
- throw new DirectorBudgetError("max_spawns", this.maxSpawns, this.spawnCount + 1);
2085
- }
2086
- if (this.maxCostUsd < Number.POSITIVE_INFINITY) {
2087
- const totalCost = this.usage.snapshot().total?.cost ?? 0;
2088
- if (totalCost >= this.maxCostUsd) {
2089
- throw new DirectorCostCapError(this.maxCostUsd, totalCost);
2104
+ if (this.fleetManager) {
2105
+ const rejection = this.fleetManager.canSpawn(config);
2106
+ if (rejection) {
2107
+ if (rejection.kind === "max_spawn_depth") throw new FleetSpawnBudgetError("max_spawn_depth", rejection.limit, rejection.observed);
2108
+ if (rejection.kind === "max_spawns") throw new FleetSpawnBudgetError("max_spawns", rejection.limit, rejection.observed);
2109
+ if (rejection.kind === "max_cost_usd") throw new FleetCostCapError(rejection.limit, rejection.observed);
2110
+ }
2111
+ } else {
2112
+ if (this.spawnDepth >= this.maxSpawnDepth) {
2113
+ throw new FleetSpawnBudgetError("max_spawn_depth", this.maxSpawnDepth, this.spawnDepth);
2114
+ }
2115
+ if (this.spawnCount >= this.maxSpawns) {
2116
+ throw new FleetSpawnBudgetError("max_spawns", this.maxSpawns, this.spawnCount + 1);
2117
+ }
2118
+ if (this.maxFleetCostUsd < Number.POSITIVE_INFINITY) {
2119
+ const totalCost = this.usage.snapshot().total?.cost ?? 0;
2120
+ if (totalCost >= this.maxFleetCostUsd) {
2121
+ throw new FleetCostCapError(this.maxFleetCostUsd, totalCost);
2122
+ }
2090
2123
  }
2091
2124
  }
2092
2125
  const result = await this.coordinator.spawn(config);
2093
- this.spawnCount += 1;
2094
- this.subagentMeta.set(result.subagentId, {
2095
- provider: config.provider,
2096
- model: config.model
2097
- });
2098
- if (priceLookup) this.priceLookups.set(result.subagentId, priceLookup);
2126
+ if (this.fleetManager) {
2127
+ this.fleetManager.recordSpawn(result.subagentId, config, priceLookup);
2128
+ } else {
2129
+ this.spawnCount += 1;
2130
+ this.subagentMeta.set(result.subagentId, {
2131
+ provider: config.provider,
2132
+ model: config.model
2133
+ });
2134
+ if (priceLookup) this.priceLookups.set(result.subagentId, priceLookup);
2135
+ }
2099
2136
  const subagentBridge = new InMemoryAgentBridge(
2100
2137
  { agentId: result.subagentId, coordinatorId: this.id },
2101
2138
  this.transport
2102
2139
  );
2103
2140
  this.coordinator.setSubagentBridge(result.subagentId, subagentBridge);
2104
2141
  this.subagentBridges.set(result.subagentId, subagentBridge);
2105
- this.manifestEntries.set(result.subagentId, {
2106
- subagentId: result.subagentId,
2107
- name: config.name,
2108
- role: config.role,
2109
- provider: config.provider,
2110
- model: config.model,
2111
- taskIds: []
2112
- });
2113
- const spawnedAt = (/* @__PURE__ */ new Date()).toISOString();
2114
- this.stateCheckpoint?.recordSpawn(
2115
- {
2116
- id: result.subagentId,
2142
+ if (!this.fleetManager) {
2143
+ this.manifestEntries.set(result.subagentId, {
2144
+ subagentId: result.subagentId,
2117
2145
  name: config.name,
2118
2146
  role: config.role,
2119
2147
  provider: config.provider,
2120
2148
  model: config.model,
2121
- spawnedAt
2122
- },
2123
- this.spawnCount
2124
- );
2125
- void this.appendSessionEvent({
2126
- type: "agent_spawned",
2127
- ts: spawnedAt,
2128
- agentId: result.subagentId,
2129
- role: config.role ?? config.name
2130
- });
2131
- this.scheduleManifest();
2149
+ taskIds: []
2150
+ });
2151
+ const spawnedAt = (/* @__PURE__ */ new Date()).toISOString();
2152
+ this.stateCheckpoint?.recordSpawn(
2153
+ {
2154
+ id: result.subagentId,
2155
+ name: config.name,
2156
+ role: config.role,
2157
+ provider: config.provider,
2158
+ model: config.model,
2159
+ spawnedAt
2160
+ },
2161
+ this.spawnCount
2162
+ );
2163
+ void this.appendSessionEvent({
2164
+ type: "agent_spawned",
2165
+ ts: spawnedAt,
2166
+ agentId: result.subagentId,
2167
+ role: config.role ?? config.name
2168
+ });
2169
+ this.scheduleManifest();
2170
+ }
2132
2171
  return result.subagentId;
2133
2172
  }
2134
2173
  /**
@@ -2295,8 +2334,12 @@ var Director = class {
2295
2334
  async assign(task) {
2296
2335
  const taskWithId = task.id ? task : { ...task, id: randomUUID() };
2297
2336
  if (task.subagentId) {
2298
- const entry = this.manifestEntries.get(task.subagentId);
2299
- if (entry) entry.taskIds.push(taskWithId.id);
2337
+ if (this.fleetManager) {
2338
+ this.fleetManager.addTaskToSubagent(task.subagentId, taskWithId.id);
2339
+ } else {
2340
+ const entry = this.manifestEntries.get(task.subagentId);
2341
+ if (entry) entry.taskIds.push(taskWithId.id);
2342
+ }
2300
2343
  }
2301
2344
  await this.coordinator.assign(taskWithId);
2302
2345
  this.taskDescriptions.set(taskWithId.id, taskWithId.description);
@@ -2494,8 +2537,9 @@ var Director = class {
2494
2537
  * still permission-checked normally.
2495
2538
  */
2496
2539
  tools(roster) {
2540
+ const effectiveRoster = roster ?? this.roster;
2497
2541
  const t = [
2498
- makeSpawnTool(this, roster),
2542
+ makeSpawnTool(this, effectiveRoster),
2499
2543
  makeAssignTool(this),
2500
2544
  makeAwaitTasksTool(this),
2501
2545
  makeAskTool(this),
@@ -3483,6 +3527,205 @@ function makeDirectorSessionFactory(opts) {
3483
3527
  };
3484
3528
  }
3485
3529
 
3486
- export { ALL_FLEET_AGENTS, AUDIT_LOG_AGENT, BUG_HUNTER_AGENT, BudgetExceededError, BudgetThresholdSignal, DEFAULT_DIRECTOR_PREAMBLE, DEFAULT_SUBAGENT_BASELINE, DefaultMultiAgentCoordinator, Director, DirectorBudgetError, DirectorCostCapError, FLEET_ROSTER, FleetBus, FleetUsageAggregator, InMemoryAgentBridge, InMemoryBridgeTransport, REFACTOR_PLANNER_AGENT, SECURITY_SCANNER_AGENT, SubagentBudget, composeDirectorPrompt, composeSubagentPrompt, createDelegateTool, createMessage, makeAgentSubagentRunner, makeDirectorSessionFactory, rosterSummaryFromConfigs };
3530
+ // src/coordination/null-fleet-bus.ts
3531
+ var NULL_FLEET_BUS = new FleetBus();
3532
+ var FleetManager = class {
3533
+ /** The fleet-wide event bus. */
3534
+ fleet;
3535
+ /** Usage rollup across all subagents. */
3536
+ usage;
3537
+ manifestPath;
3538
+ sessionsRoot;
3539
+ directorRunId;
3540
+ /** Spawn cap (lifetime total). Infinity means unlimited. */
3541
+ maxSpawns;
3542
+ /** Nesting cap. */
3543
+ maxSpawnDepth;
3544
+ /** This director's depth in a director chain. Root = 0. */
3545
+ spawnDepth;
3546
+ /** Live spawn counter. */
3547
+ spawnCount = 0;
3548
+ stateCheckpoint;
3549
+ sessionWriter;
3550
+ manifestTimer = null;
3551
+ manifestDebounceMs;
3552
+ /** Fleet-wide cost cap. Infinity = no cap. Distinct from SubagentBudget limits,
3553
+ * which track per-subagent spend — this field caps the entire fleet total. */
3554
+ maxFleetCostUsd;
3555
+ manifestEntries = /* @__PURE__ */ new Map();
3556
+ /** Pending tasks with their descriptions — populated by `addPendingTask`
3557
+ * and cleared by `removePendingTask`. Replaces the host-side `pending`
3558
+ * Map so task descriptions live in one place (FleetManager). */
3559
+ pendingTasks = /* @__PURE__ */ new Map();
3560
+ subagentMeta = /* @__PURE__ */ new Map();
3561
+ priceLookups = /* @__PURE__ */ new Map();
3562
+ constructor(opts = {}) {
3563
+ this.manifestPath = opts.manifestPath;
3564
+ this.sessionsRoot = opts.sessionsRoot;
3565
+ this.directorRunId = opts.directorRunId ?? randomUUID();
3566
+ this.maxSpawns = opts.maxSpawns ?? Number.POSITIVE_INFINITY;
3567
+ this.maxSpawnDepth = opts.maxSpawnDepth ?? 2;
3568
+ this.spawnDepth = opts.spawnDepth ?? 0;
3569
+ this.sessionWriter = opts.sessionWriter ?? null;
3570
+ this.manifestDebounceMs = opts.manifestDebounceMs ?? 2e3;
3571
+ this.maxFleetCostUsd = opts.directorBudget?.maxCostUsd ?? Number.POSITIVE_INFINITY;
3572
+ this.stateCheckpoint = opts.stateCheckpointPath ? new DirectorStateCheckpoint(
3573
+ opts.stateCheckpointPath,
3574
+ {
3575
+ directorRunId: this.directorRunId,
3576
+ maxSpawns: opts.maxSpawns,
3577
+ spawnDepth: this.spawnDepth,
3578
+ maxSpawnDepth: this.maxSpawnDepth,
3579
+ directorBudget: opts.directorBudget
3580
+ },
3581
+ opts.checkpointDebounceMs ?? 250
3582
+ ) : null;
3583
+ this.fleet = new FleetBus();
3584
+ this.usage = new FleetUsageAggregator(
3585
+ this.fleet,
3586
+ (id) => this.priceLookups.get(id),
3587
+ (id) => this.subagentMeta.get(id)
3588
+ );
3589
+ }
3590
+ // -----------------------------------------------------------------------
3591
+ // IFleetManager surface
3592
+ // -----------------------------------------------------------------------
3593
+ get fleetBus() {
3594
+ return this.fleet;
3595
+ }
3596
+ snapshot() {
3597
+ return this.usage.snapshot();
3598
+ }
3599
+ getSubagentMeta(id) {
3600
+ return this.subagentMeta.get(id);
3601
+ }
3602
+ /**
3603
+ * Returns null if the spawn is allowed, or an object describing
3604
+ * which cap was exceeded. Does NOT throw — the caller decides
3605
+ * how to surface the rejection.
3606
+ */
3607
+ canSpawn(config) {
3608
+ if (this.spawnDepth >= this.maxSpawnDepth) {
3609
+ return { kind: "max_spawn_depth", limit: this.maxSpawnDepth, observed: this.spawnDepth };
3610
+ }
3611
+ if (this.spawnCount >= this.maxSpawns) {
3612
+ return { kind: "max_spawns", limit: this.maxSpawns, observed: this.spawnCount + 1 };
3613
+ }
3614
+ if (this.maxFleetCostUsd < Number.POSITIVE_INFINITY) {
3615
+ const totalCost = this.usage.snapshot().total?.cost ?? 0;
3616
+ if (totalCost >= this.maxFleetCostUsd) {
3617
+ return { kind: "max_cost_usd", limit: this.maxFleetCostUsd, observed: totalCost };
3618
+ }
3619
+ }
3620
+ return null;
3621
+ }
3622
+ /**
3623
+ * Records a spawn: increments counter, stores metadata, updates state checkpoint,
3624
+ * and schedules a debounced manifest write. Call AFTER the coordinator
3625
+ * has successfully spawned the subagent.
3626
+ *
3627
+ * @param subagentId The subagent's id (from coordinator.spawn result)
3628
+ * @param config The SubagentConfig that was used
3629
+ * @param priceLookup Optional per-subagent pricing data
3630
+ */
3631
+ recordSpawn(subagentId, config, priceLookup) {
3632
+ this.spawnCount += 1;
3633
+ this.subagentMeta.set(subagentId, {
3634
+ provider: config.provider,
3635
+ model: config.model
3636
+ });
3637
+ if (priceLookup) this.priceLookups.set(subagentId, priceLookup);
3638
+ this.manifestEntries.set(subagentId, {
3639
+ subagentId,
3640
+ name: config.name,
3641
+ role: config.role,
3642
+ provider: config.provider,
3643
+ model: config.model,
3644
+ taskIds: []
3645
+ });
3646
+ this.stateCheckpoint?.recordSpawn({
3647
+ id: subagentId,
3648
+ name: config.name,
3649
+ role: config.role,
3650
+ provider: config.provider,
3651
+ model: config.model,
3652
+ spawnedAt: (/* @__PURE__ */ new Date()).toISOString()
3653
+ }, this.spawnCount);
3654
+ void this.appendSessionEvent({
3655
+ type: "agent_spawned",
3656
+ ts: (/* @__PURE__ */ new Date()).toISOString(),
3657
+ agentId: subagentId,
3658
+ role: config.role ?? config.name
3659
+ });
3660
+ this.scheduleManifest();
3661
+ }
3662
+ async writeManifest() {
3663
+ if (!this.manifestPath) return null;
3664
+ const manifest = {
3665
+ version: 1,
3666
+ directorRunId: this.directorRunId,
3667
+ generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
3668
+ children: Array.from(this.manifestEntries.values()).map((entry) => ({
3669
+ id: entry.subagentId,
3670
+ name: entry.name,
3671
+ role: entry.role,
3672
+ provider: entry.provider,
3673
+ model: entry.model,
3674
+ taskIds: entry.taskIds
3675
+ })),
3676
+ usage: this.usage.snapshot()
3677
+ };
3678
+ await fsp4.mkdir(path4.dirname(this.manifestPath), { recursive: true });
3679
+ await fsp4.writeFile(this.manifestPath, JSON.stringify(manifest, null, 2), { mode: 384 });
3680
+ return this.manifestPath;
3681
+ }
3682
+ /**
3683
+ * Attach task ids to an already-spawned subagent. Called by
3684
+ * `Director.assign()` after the coordinator assigns a task.
3685
+ */
3686
+ addTaskToSubagent(subagentId, taskId) {
3687
+ const entry = this.manifestEntries.get(subagentId);
3688
+ if (entry) entry.taskIds.push(taskId);
3689
+ }
3690
+ /**
3691
+ * Debounced manifest write. Call after any state mutation
3692
+ * (spawn, assign, complete) so a burst collapses into one write.
3693
+ */
3694
+ scheduleManifest() {
3695
+ if (!this.manifestPath || this.manifestDebounceMs <= 0) return;
3696
+ if (this.manifestTimer) return;
3697
+ this.manifestTimer = setTimeout(() => {
3698
+ this.manifestTimer = null;
3699
+ void this.writeManifest().catch(() => void 0);
3700
+ }, this.manifestDebounceMs);
3701
+ }
3702
+ /** Best-effort session event writer. Swallows failures. */
3703
+ async appendSessionEvent(event) {
3704
+ if (!this.sessionWriter) return;
3705
+ try {
3706
+ await this.sessionWriter.append(event);
3707
+ } catch {
3708
+ }
3709
+ }
3710
+ // -----------------------------------------------------------------------
3711
+ // Pending task management — eliminates host-side state duplication
3712
+ // -----------------------------------------------------------------------
3713
+ addPendingTask(taskId, subagentId, description) {
3714
+ this.pendingTasks.set(taskId, { subagentId, description });
3715
+ }
3716
+ removePendingTask(taskId) {
3717
+ this.pendingTasks.delete(taskId);
3718
+ }
3719
+ getFleetStatus() {
3720
+ const pending = Array.from(this.pendingTasks.entries()).map(([taskId, v]) => ({
3721
+ taskId,
3722
+ description: v.description,
3723
+ subagentId: v.subagentId
3724
+ }));
3725
+ return { pending, live: [] };
3726
+ }
3727
+ };
3728
+
3729
+ export { ALL_FLEET_AGENTS, AUDIT_LOG_AGENT, BUG_HUNTER_AGENT, BudgetExceededError, BudgetThresholdSignal, DEFAULT_DIRECTOR_PREAMBLE, DEFAULT_SUBAGENT_BASELINE, DefaultMultiAgentCoordinator, Director, FLEET_ROSTER, FleetBus, FleetCostCapError, FleetManager, FleetSpawnBudgetError, FleetUsageAggregator, InMemoryAgentBridge, InMemoryBridgeTransport, NULL_FLEET_BUS, REFACTOR_PLANNER_AGENT, SECURITY_SCANNER_AGENT, SubagentBudget, composeDirectorPrompt, composeSubagentPrompt, createDelegateTool, createMessage, makeAgentSubagentRunner, makeDirectorSessionFactory, rosterSummaryFromConfigs };
3487
3730
  //# sourceMappingURL=index.js.map
3488
3731
  //# sourceMappingURL=index.js.map