@wrongstack/core 0.7.8 → 0.8.0

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 (35) hide show
  1. package/dist/{agent-bridge-hXRN-GO_.d.ts → agent-bridge-DPxcUVkn.d.ts} +1 -1
  2. package/dist/{agent-subagent-runner-B2zguWzh.d.ts → agent-subagent-runner-Bzeueq2J.d.ts} +9 -10
  3. package/dist/coordination/index.d.ts +8 -8
  4. package/dist/coordination/index.js +393 -179
  5. package/dist/coordination/index.js.map +1 -1
  6. package/dist/defaults/index.d.ts +10 -10
  7. package/dist/defaults/index.js +190 -55
  8. package/dist/defaults/index.js.map +1 -1
  9. package/dist/{events-D4pGukpI.d.ts → events-DyhxkstG.d.ts} +33 -0
  10. package/dist/execution/index.d.ts +6 -6
  11. package/dist/execution/index.js +116 -31
  12. package/dist/execution/index.js.map +1 -1
  13. package/dist/extension/index.d.ts +2 -2
  14. package/dist/{index-BtNRyJft.d.ts → index-BciJeH8g.d.ts} +1 -1
  15. package/dist/index.d.ts +13 -13
  16. package/dist/index.js +294 -59
  17. package/dist/index.js.map +1 -1
  18. package/dist/infrastructure/index.d.ts +2 -2
  19. package/dist/kernel/index.d.ts +2 -2
  20. package/dist/kernel/index.js +23 -0
  21. package/dist/kernel/index.js.map +1 -1
  22. package/dist/{multi-agent-7OK4pEKW.d.ts → multi-agent-CRMznZmf.d.ts} +64 -30
  23. package/dist/{multi-agent-coordinator-3Ypfg-hr.d.ts → multi-agent-coordinator-tlSWD4cE.d.ts} +11 -1
  24. package/dist/{null-fleet-bus-BZUrXVcd.d.ts → null-fleet-bus-DXEvZKHW.d.ts} +92 -6
  25. package/dist/observability/index.d.ts +1 -1
  26. package/dist/{path-resolver-DPUjF10O.d.ts → path-resolver-1CIYbH2Q.d.ts} +1 -1
  27. package/dist/{plan-templates-C-IOLJ8Q.d.ts → plan-templates-BnlpEkX8.d.ts} +1 -1
  28. package/dist/{provider-runner-iST8U3ni.d.ts → provider-runner-BrA0XR-l.d.ts} +1 -1
  29. package/dist/sdd/index.d.ts +4 -4
  30. package/dist/sdd/index.js +114 -28
  31. package/dist/sdd/index.js.map +1 -1
  32. package/dist/storage/index.d.ts +2 -2
  33. package/dist/{tool-executor-CSwXjifK.d.ts → tool-executor-Cx2ndr0L.d.ts} +1 -1
  34. package/dist/types/index.d.ts +7 -7
  35. package/package.json +1 -1
@@ -397,6 +397,26 @@ interface EventMap {
397
397
  revertedFiles: string[];
398
398
  removedEvents: number;
399
399
  };
400
+ /**
401
+ * Fired by the multi-agent coordinator on FleetBus whenever subagent
402
+ * counts change (spawn/stop/complete). The TUI subscribes to render
403
+ * live fleet counters without polling.
404
+ */
405
+ 'coordinator.stats': {
406
+ total: number;
407
+ running: number;
408
+ idle: number;
409
+ stopped: number;
410
+ inFlight: number;
411
+ pending: number;
412
+ completed: number;
413
+ subagentStatuses: {
414
+ subagentId: string;
415
+ taskId: string;
416
+ status: string;
417
+ assigned: boolean;
418
+ }[];
419
+ };
400
420
  error: {
401
421
  err: Error;
402
422
  phase: string;
@@ -415,6 +435,14 @@ declare class EventBus {
415
435
  on<E extends EventName>(event: E, fn: Listener<E>): () => void;
416
436
  off<E extends EventName>(event: E, fn: Listener<E>): void;
417
437
  once<E extends EventName>(event: E, fn: Listener<E>): () => void;
438
+ /**
439
+ * Subscribe to all events, regardless of name. Short-hand for
440
+ * `onPattern('*')`. Use for logging, debugging, or forwarding every
441
+ * event to another bus (as FleetBus does).
442
+ *
443
+ * Returns an unsubscribe function.
444
+ */
445
+ onAny(fn: (event: string, payload: unknown) => void): () => void;
418
446
  /**
419
447
  * Subscribe to all events whose name matches a glob-style prefix.
420
448
  * `'tool.*'` matches `tool.started`, `tool.executed`, `tool.progress`, etc.
@@ -496,6 +524,11 @@ declare class ScopedEventBus extends EventBus {
496
524
  * our registration entry under a different key).
497
525
  */
498
526
  once<E extends EventName>(event: E, fn: Listener<E>): () => void;
527
+ /**
528
+ * Subscribe to all events. Alias for `onPattern('*')` — the listener is
529
+ * tracked so that `teardown()` will remove it automatically.
530
+ */
531
+ onAny(fn: (event: string, payload: unknown) => void): () => void;
499
532
  /**
500
533
  * Identical to `EventBus.onPattern` but the listener is tracked so that
501
534
  * `teardown()` will remove it automatically.
@@ -1,15 +1,15 @@
1
- export { C as CompactorOptions, a as DefaultErrorHandler, b as DefaultRetryPolicy, H as HybridCompactor, T as ToolExecutor } from '../tool-executor-CSwXjifK.js';
1
+ export { C as CompactorOptions, a as DefaultErrorHandler, b as DefaultRetryPolicy, H as HybridCompactor, T as ToolExecutor } from '../tool-executor-Cx2ndr0L.js';
2
2
  import { m as Provider, d as Context } from '../context-z2x5gv_V.js';
3
3
  import { a as Compactor, C as CompactReport } from '../compactor-Mw7-rNyb.js';
4
4
  import { M as MessageSelector } from '../selector-DkvgYVS4.js';
5
- import { E as EventBus } from '../events-D4pGukpI.js';
5
+ import { E as EventBus } from '../events-DyhxkstG.js';
6
6
  import { b as MiddlewareHandler } from '../system-prompt-CWA6ml-d.js';
7
7
  import { e as ContextWindowAggressiveOn, i as ContextWindowPolicy } from '../config-Bi4Q0fnz.js';
8
- import { c as Agent, R as RunResult, w as SystemPromptContributor } from '../index-BtNRyJft.js';
9
- import { D as DoneCondition } from '../multi-agent-7OK4pEKW.js';
8
+ import { c as Agent, R as RunResult, w as SystemPromptContributor } from '../index-BciJeH8g.js';
9
+ import { D as DoneCondition } from '../multi-agent-CRMznZmf.js';
10
10
  import { J as JournalEntry } from '../goal-store-C7jcumEh.js';
11
- import { A as AgentFactory } from '../agent-subagent-runner-B2zguWzh.js';
12
- import { f as DispatchClassifier, d as DefaultMultiAgentCoordinator } from '../multi-agent-coordinator-3Ypfg-hr.js';
11
+ import { A as AgentFactory } from '../agent-subagent-runner-Bzeueq2J.js';
12
+ import { f as DispatchClassifier, d as DefaultMultiAgentCoordinator } from '../multi-agent-coordinator-tlSWD4cE.js';
13
13
  import { a as SkillLoader, b as SkillManifest, S as SkillEntry } from '../skill-CxuWrsKK.js';
14
14
  import { a as WstackPaths } from '../wstack-paths-gCrJ631C.js';
15
15
  import '../retry-policy-OwtKNxo8.js';
@@ -2393,29 +2393,35 @@ var SubagentBudget = class _SubagentBudget {
2393
2393
  * same kind are no-ops — without this dedup, every `recordIteration`
2394
2394
  * after the limit is reached spawns a fresh decision Promise (until
2395
2395
  * the first one lands and patches limits), flooding the FleetBus
2396
- * with redundant threshold events. Cleared in `checkLimitAsync`'s
2396
+ * with redundant threshold events. Cleared in `negotiateExtension`'s
2397
2397
  * `finally`.
2398
2398
  */
2399
2399
  pendingExtensions = /* @__PURE__ */ new Set();
2400
2400
  /**
2401
- * Hard cap on how long `checkLimitAsync` waits for the coordinator to
2401
+ * Hard cap on how long `negotiateExtension` waits for the coordinator to
2402
2402
  * respond before defaulting to 'stop'. Without this fallback an absent
2403
2403
  * or hung listener (Director not built / event filter detached mid-run)
2404
- * leaves the budget over-limit and never enforces anything, since
2405
- * `checkLimit` returns synchronously via `void this.checkLimitAsync`.
2406
- * Raised from 30s to 60s to give subagents more headroom before
2407
- * the threshold negotiation times out and triggers a hard stop.
2404
+ * leaves the budget over-limit and never enforces anything.
2408
2405
  */
2409
2406
  static DECISION_TIMEOUT_MS = 6e4;
2410
2407
  /**
2411
2408
  * Injected by the runner when wiring the budget to its EventBus.
2412
- * Used by `checkLimitAsync` to emit `budget.threshold_reached` events.
2409
+ * Used to emit `budget.threshold_reached` events in `'auto'` mode.
2413
2410
  */
2414
2411
  _events;
2412
+ /**
2413
+ * Negotiation mode — controls whether a threshold hit tries to emit
2414
+ * `budget.threshold_reached` and wait for a coordinator decision, or
2415
+ * falls straight through to a synchronous hard stop.
2416
+ *
2417
+ * `'auto'` (default) — emit on the EventBus and wait; times out to 'stop'.
2418
+ * `'sync'` — throw `BudgetExceededError` immediately regardless of listeners.
2419
+ */
2420
+ _mode;
2415
2421
  /**
2416
2422
  * Optional callback for soft-limit handling. When set, the budget will
2417
- * call this instead of throwing when a limit is first reached. The
2418
- * handler decides whether to throw, continue, or ask the coordinator.
2423
+ * invoke it rather than throw immediately. The handler decides whether to
2424
+ * throw synchronously, continue, or ask the coordinator for an extension.
2419
2425
  */
2420
2426
  get onThreshold() {
2421
2427
  return this._onThreshold;
@@ -2423,7 +2429,12 @@ var SubagentBudget = class _SubagentBudget {
2423
2429
  set onThreshold(fn) {
2424
2430
  this._onThreshold = fn;
2425
2431
  }
2426
- constructor(limits = {}) {
2432
+ /** Returns the current negotiation mode. */
2433
+ get mode() {
2434
+ return this._mode;
2435
+ }
2436
+ constructor(limits = {}, mode = "auto") {
2437
+ this._mode = mode;
2427
2438
  this.limits = { ...limits };
2428
2439
  }
2429
2440
  start() {
@@ -2439,16 +2450,23 @@ var SubagentBudget = class _SubagentBudget {
2439
2450
  return false;
2440
2451
  }
2441
2452
  /**
2442
- * Synchronous budget check always throws synchronously so callers
2443
- * (especially test event handlers using `expect().toThrow()`) get an
2444
- * unhandled rejection when the budget is exceeded without a handler.
2445
- * When `onThreshold` IS configured, the actual async threshold-handling
2446
- * is dispatched as a fire-and-forget promise.
2453
+ * Synchronous budget check. Always throws synchronously so callers (especially
2454
+ * test event handlers using `expect().toThrow()`) get an unhandled rejection
2455
+ * when the budget is exceeded without a handler.
2456
+ *
2457
+ * Decision table:
2458
+ * - no `onThreshold` handler → throw `BudgetExceededError` (hard stop, always)
2459
+ * - `mode === 'sync'` → throw `BudgetExceededError` (hard stop, always)
2460
+ * - `mode === 'auto'` + no listener → throw `BudgetExceededError` (hard stop; no one to ask)
2461
+ * - `mode === 'auto'` + listener → throw `BudgetThresholdSignal` with async decision promise
2447
2462
  */
2448
2463
  checkLimit(kind, used, limit) {
2449
2464
  if (!this._onThreshold) {
2450
2465
  throw new BudgetExceededError(kind, limit, used);
2451
2466
  }
2467
+ if (this._mode === "sync") {
2468
+ throw new BudgetExceededError(kind, limit, used);
2469
+ }
2452
2470
  const bus = this._events;
2453
2471
  if (!bus || !bus.hasListenerFor("budget.threshold_reached")) {
2454
2472
  throw new BudgetExceededError(kind, limit, used);
@@ -2465,8 +2483,8 @@ var SubagentBudget = class _SubagentBudget {
2465
2483
  * `pendingExtensions` slot in `finally`.
2466
2484
  *
2467
2485
  * The 'continue' return from a sync handler is treated as
2468
- * `{ extend: {} }` — keep going without patching, next overrun will
2469
- * fire a fresh signal.
2486
+ * `{ extend: {} }` — keep going without patching; next overrun fires
2487
+ * a fresh signal.
2470
2488
  */
2471
2489
  async negotiateExtension(kind, used, limit) {
2472
2490
  try {
@@ -2474,11 +2492,6 @@ var SubagentBudget = class _SubagentBudget {
2474
2492
  kind,
2475
2493
  used,
2476
2494
  limit,
2477
- // Inject a requestDecision helper the handler can call to emit the
2478
- // budget.threshold_reached event and wait for the coordinator's verdict.
2479
- // A hard fallback timer guarantees the promise eventually resolves
2480
- // even if no listener responds — without it, an absent/detached
2481
- // Director would leave the budget permanently in "asking" state.
2482
2495
  requestDecision: () => {
2483
2496
  const bus = this._events;
2484
2497
  if (!bus || !bus.hasListenerFor("budget.threshold_reached")) {
@@ -2562,12 +2575,12 @@ var SubagentBudget = class _SubagentBudget {
2562
2575
  }
2563
2576
  }
2564
2577
  /**
2565
- * Wall-clock budget check. Unlike other limits, timeout is treated as a
2566
- * warning-only event it NEVER hard-stops the subagent. When the
2567
- * elapsed time exceeds timeoutMs, emits `budget.threshold_reached` with
2568
- * kind='timeout' so the Director can decide whether to extend or warn.
2569
- * Call this from the iteration loop so a hung tool gets a chance to
2570
- * negotiate more time before the coordinator's Promise.race kills it.
2578
+ * Wall-clock budget check. Unlike other limits, timeout check passes through
2579
+ * `checkLimit` and is subject to the same negotiation-mode decision table.
2580
+ * In practice, `'sync'` mode (the usual test configuration) means a timeout
2581
+ * immediately throws `BudgetExceededError`. In production with a coordinator,
2582
+ * a timeout emits `budget.threshold_reached` so the Director can decide whether
2583
+ * to extend or abort.
2571
2584
  */
2572
2585
  checkTimeout() {
2573
2586
  if (this.startTime === null || this.limits.timeoutMs === void 0) return;
@@ -4934,8 +4947,7 @@ function scoreAgents(task, catalog = AGENT_CATALOG) {
4934
4947
  const hay = normalize(task);
4935
4948
  const out = [];
4936
4949
  for (const def of Object.values(catalog)) {
4937
- const role = def.config.role;
4938
- if (!role) continue;
4950
+ if (!def?.config?.role) continue;
4939
4951
  let score = 0;
4940
4952
  const matched = [];
4941
4953
  for (const kw of def.capability.keywords) {
@@ -4947,7 +4959,7 @@ function scoreAgents(task, catalog = AGENT_CATALOG) {
4947
4959
  }
4948
4960
  }
4949
4961
  if (score > 0) {
4950
- out.push({ role, name: def.config.name, score, matched });
4962
+ out.push({ role: def.config.role, name: def.config.name, score, matched });
4951
4963
  }
4952
4964
  }
4953
4965
  out.sort((a, b) => b.score - a.score);
@@ -5189,6 +5201,7 @@ var DefaultMultiAgentCoordinator = class extends EventEmitter {
5189
5201
  coordinatorId;
5190
5202
  config;
5191
5203
  runner;
5204
+ fleetBus;
5192
5205
  subagents = /* @__PURE__ */ new Map();
5193
5206
  pendingTasks = [];
5194
5207
  completedResults = [];
@@ -5217,6 +5230,14 @@ var DefaultMultiAgentCoordinator = class extends EventEmitter {
5217
5230
  setRunner(runner) {
5218
5231
  this.runner = runner;
5219
5232
  }
5233
+ /**
5234
+ * Wire a FleetBus for director-mode event emission. Call after the
5235
+ * FleetManager is constructed so the coordinator can emit lifecycle
5236
+ * events the TUI and monitoring tools subscribe to.
5237
+ */
5238
+ setFleetBus(fleet) {
5239
+ this.fleetBus = fleet;
5240
+ }
5220
5241
  /**
5221
5242
  * Change the in-flight dispatch ceiling at runtime. Lowering does NOT
5222
5243
  * preempt running tasks — already-dispatched subagents finish their
@@ -5252,6 +5273,18 @@ var DefaultMultiAgentCoordinator = class extends EventEmitter {
5252
5273
  abortController: new AbortController()
5253
5274
  });
5254
5275
  this.emit("subagent.started", { subagent: { ...subagent, id } });
5276
+ this.fleetBus?.emit({
5277
+ subagentId: id,
5278
+ ts: Date.now(),
5279
+ type: "subagent.assigned",
5280
+ payload: {
5281
+ subagentId: id,
5282
+ name: subagent.name,
5283
+ provider: subagent.provider,
5284
+ model: subagent.model
5285
+ }
5286
+ });
5287
+ this.emitCoordinatorStats();
5255
5288
  return { subagentId: id, agentId: id };
5256
5289
  }
5257
5290
  async assign(task) {
@@ -5284,6 +5317,13 @@ var DefaultMultiAgentCoordinator = class extends EventEmitter {
5284
5317
  subagent.currentTask = void 0;
5285
5318
  subagent.context.parentBridge = null;
5286
5319
  this.emit("subagent.stopped", { subagentId, reason: "stopped by coordinator" });
5320
+ this.fleetBus?.emit({
5321
+ subagentId,
5322
+ ts: Date.now(),
5323
+ type: "subagent.stopped",
5324
+ payload: { subagentId, reason: "stopped by coordinator" }
5325
+ });
5326
+ this.emitCoordinatorStats();
5287
5327
  }
5288
5328
  async stopAll() {
5289
5329
  this.drainPendingAsAborted("Coordinator stopAll() drained the pending queue");
@@ -5315,6 +5355,22 @@ var DefaultMultiAgentCoordinator = class extends EventEmitter {
5315
5355
  completed: this.completedResults.length
5316
5356
  };
5317
5357
  }
5358
+ /** Emit a reactive coordinator.stats event on FleetBus so the TUI can subscribe. */
5359
+ emitCoordinatorStats() {
5360
+ const stats = this.getStats();
5361
+ const subagentStatuses = Array.from(this.subagents.entries()).map(([id, s]) => ({
5362
+ subagentId: id,
5363
+ taskId: s.currentTask ?? "",
5364
+ status: s.status,
5365
+ assigned: s.context.parentBridge !== null
5366
+ }));
5367
+ this.fleetBus?.emit({
5368
+ subagentId: this.coordinatorId,
5369
+ ts: Date.now(),
5370
+ type: "coordinator.stats",
5371
+ payload: { ...stats, subagentStatuses }
5372
+ });
5373
+ }
5318
5374
  getStatus() {
5319
5375
  return {
5320
5376
  coordinatorId: this.coordinatorId,
@@ -5489,7 +5545,15 @@ var DefaultMultiAgentCoordinator = class extends EventEmitter {
5489
5545
  subagent.currentTask = task.id;
5490
5546
  task.subagentId = subagentId;
5491
5547
  subagent.context.tasks.push(task);
5548
+ this.fleetBus?.emit({
5549
+ subagentId,
5550
+ taskId: task.id,
5551
+ ts: Date.now(),
5552
+ type: "subagent.running",
5553
+ payload: { subagentId, taskId: task.id }
5554
+ });
5492
5555
  this.emit("task.assigned", { task, subagentId });
5556
+ this.emitCoordinatorStats();
5493
5557
  const rawMaxIterations = subagent.config.maxIterations;
5494
5558
  const rawMaxToolCalls = subagent.config.maxToolCalls;
5495
5559
  const rawMaxTokens = subagent.config.maxTokens;
@@ -5633,13 +5697,34 @@ var DefaultMultiAgentCoordinator = class extends EventEmitter {
5633
5697
  if (subagent.abortController.signal.aborted) {
5634
5698
  subagent.abortController = new AbortController();
5635
5699
  }
5700
+ this.fleetBus?.emit({
5701
+ subagentId: result.subagentId,
5702
+ ts: Date.now(),
5703
+ type: "subagent.idle",
5704
+ payload: { subagentId: result.subagentId }
5705
+ });
5636
5706
  }
5637
5707
  this.terminating.delete(result.subagentId);
5638
5708
  this.emit("task.completed", {
5639
5709
  task: subagent?.context.tasks.find((t) => t.id === result.taskId) ?? { id: result.taskId },
5640
5710
  result
5641
5711
  });
5712
+ this.fleetBus?.emit({
5713
+ subagentId: result.subagentId,
5714
+ taskId: result.taskId,
5715
+ ts: Date.now(),
5716
+ type: "subagent.completed",
5717
+ payload: {
5718
+ subagentId: result.subagentId,
5719
+ taskId: result.taskId,
5720
+ status: result.status,
5721
+ iterations: result.iterations,
5722
+ toolCalls: result.toolCalls,
5723
+ durationMs: result.durationMs
5724
+ }
5725
+ });
5642
5726
  this.tryDispatchNext();
5727
+ this.emitCoordinatorStats();
5643
5728
  if (this.isDone()) {
5644
5729
  this.emit("done", {
5645
5730
  results: this.completedResults,