@wrongstack/core 0.6.7 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{agent-bridge-BCVxmrOn.d.ts → agent-bridge-Bji75Iv9.d.ts} +1 -1
- package/dist/{compactor-BUJ8550X.d.ts → compactor-BFKGzKd5.d.ts} +1 -1
- package/dist/{config-BHkYGzUT.d.ts → config-BXAhlqJb.d.ts} +1 -1
- package/dist/{context-C8mBUzBv.d.ts → context-BwxhvyW8.d.ts} +75 -3
- package/dist/coordination/index.d.ts +42 -12
- package/dist/coordination/index.js +2573 -40
- package/dist/coordination/index.js.map +1 -1
- package/dist/default-config-DvRSTELf.d.ts +20 -0
- package/dist/defaults/index.d.ts +21 -20
- package/dist/defaults/index.js +2896 -243
- package/dist/defaults/index.js.map +1 -1
- package/dist/{director-state-BmYi3DGA.d.ts → director-state-BUB7JRUr.d.ts} +1 -1
- package/dist/{events-DounT6pP.d.ts → events-AjrvHJ9V.d.ts} +25 -1
- package/dist/execution/index.d.ts +42 -13
- package/dist/execution/index.js +2497 -40
- package/dist/execution/index.js.map +1 -1
- package/dist/extension/index.d.ts +6 -6
- package/dist/extension/index.js +3 -1
- package/dist/extension/index.js.map +1 -1
- package/dist/{index-DiIGZh5I.d.ts → index-B2WWETRP.d.ts} +6 -6
- package/dist/index.d.ts +36 -27
- package/dist/index.js +2863 -137
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/index.d.ts +6 -6
- package/dist/infrastructure/index.js +12 -0
- package/dist/infrastructure/index.js.map +1 -1
- package/dist/kernel/index.d.ts +9 -9
- package/dist/kernel/index.js +20 -4
- package/dist/kernel/index.js.map +1 -1
- package/dist/{mcp-servers-CXFfDN_d.d.ts → mcp-servers-BDM2Leff.d.ts} +3 -3
- package/dist/models/index.d.ts +2 -2
- package/dist/{multi-agent-Iy8YUe3v.d.ts → multi-agent-DenFfUv5.d.ts} +11 -3
- package/dist/multi-agent-coordinator-DGUn-5Bb.d.ts +448 -0
- package/dist/{index-BlVITqm-.d.ts → null-fleet-bus-DJMbqYhL.d.ts} +105 -107
- package/dist/observability/index.d.ts +2 -2
- package/dist/{path-resolver-DwJO5XBn.d.ts → path-resolver-C1NM67-u.d.ts} +2 -2
- package/dist/{plan-templates-CG_pInJV.d.ts → plan-templates-CNY6f82B.d.ts} +4 -4
- package/dist/{provider-runner-DoohzfyD.d.ts → provider-runner-Cmuevptw.d.ts} +3 -3
- package/dist/{retry-policy-DOnwHAyz.d.ts → retry-policy-mEBn5qpv.d.ts} +1 -1
- package/dist/sdd/index.d.ts +3 -3
- package/dist/{secret-scrubber-DcTK9JHC.d.ts → secret-scrubber-BmiGszvl.d.ts} +1 -1
- package/dist/{secret-scrubber-C9UJxFCJ.d.ts → secret-scrubber-bZ5AyhwJ.d.ts} +1 -1
- package/dist/security/index.d.ts +3 -3
- package/dist/{selector-DVo3eT-P.d.ts → selector-BmUma5iG.d.ts} +1 -1
- package/dist/{session-reader-BXWxFAhS.d.ts → session-reader-g-FKCyBw.d.ts} +1 -1
- package/dist/storage/index.d.ts +6 -6
- package/dist/storage/index.js +101 -14
- package/dist/storage/index.js.map +1 -1
- package/dist/{system-prompt-BBGles-N.d.ts → system-prompt-BKrzd_ci.d.ts} +1 -1
- package/dist/{tool-executor-CwpjhwHC.d.ts → tool-executor-BoM0U0qn.d.ts} +6 -5
- package/dist/types/index.d.ts +16 -15
- package/dist/types/index.js +130 -20
- package/dist/types/index.js.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/package.json +1 -1
- package/dist/agent-subagent-runner-BTloSwjE.d.ts +0 -174
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
import { A as Agent, n as AgentInput } from './index-B2WWETRP.js';
|
|
2
|
+
import { E as EventBus } from './events-AjrvHJ9V.js';
|
|
3
|
+
import { c as SubagentConfig, k as TaskSpec, i as SubagentRunner, b as MultiAgentCoordinator, M as MultiAgentConfig, S as SpawnResult, l as BridgeMessage, A as AgentBridge, a as CoordinatorStatus, j as TaskResult } from './multi-agent-DenFfUv5.js';
|
|
4
|
+
import { EventEmitter } from 'node:events';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Single fleet-wide event with subagent attribution. Whatever a child
|
|
8
|
+
* agent emits on its own EventBus gets re-published here, prefixed with
|
|
9
|
+
* `subagentId` so a single subscriber can multiplex across the fleet.
|
|
10
|
+
*
|
|
11
|
+
* The director uses `FleetBus.filter('tool.executed', …)` to see every
|
|
12
|
+
* tool call across the fleet; the TUI uses
|
|
13
|
+
* `FleetBus.subscribe(id, handler)` to render a per-subagent panel.
|
|
14
|
+
*/
|
|
15
|
+
interface FleetEvent {
|
|
16
|
+
subagentId: string;
|
|
17
|
+
taskId?: string;
|
|
18
|
+
ts: number;
|
|
19
|
+
type: string;
|
|
20
|
+
payload: unknown;
|
|
21
|
+
}
|
|
22
|
+
type FleetHandler = (event: FleetEvent) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Fan-in for per-subagent EventBuses. Each subagent's bus is plugged in
|
|
25
|
+
* via `attach()`; the FleetBus re-emits every event with subagent
|
|
26
|
+
* attribution. Detachment is automatic via the returned disposer — call
|
|
27
|
+
* it when a subagent terminates so we don't leak listeners.
|
|
28
|
+
*
|
|
29
|
+
* The bus exposes two subscription modes: by `subagentId` (everything
|
|
30
|
+
* from one child) and by `type` (one event-type across the fleet). They
|
|
31
|
+
* compose — if you need a per-subagent + per-type slice, subscribe by
|
|
32
|
+
* type and filter on `event.subagentId` in your handler.
|
|
33
|
+
*/
|
|
34
|
+
declare class FleetBus {
|
|
35
|
+
private readonly byId;
|
|
36
|
+
private readonly byType;
|
|
37
|
+
private readonly any;
|
|
38
|
+
/**
|
|
39
|
+
* Hook a subagent's EventBus into the fleet. EventBus is strongly
|
|
40
|
+
* typed and doesn't expose an `onAny` hook, so we subscribe to the
|
|
41
|
+
* canonical set of event types a subagent emits during a run. New
|
|
42
|
+
* event types added to the kernel must be added here too — but the
|
|
43
|
+
* cost is a tiny single line per type, and the explicit list keeps
|
|
44
|
+
* the wire format clear.
|
|
45
|
+
*
|
|
46
|
+
* Returns a disposer that detaches every subscription; call on
|
|
47
|
+
* subagent teardown so the listeners don't outlive the run.
|
|
48
|
+
*/
|
|
49
|
+
attach(subagentId: string, bus: EventBus, taskId?: string): () => void;
|
|
50
|
+
/** Subscribe to every event from one subagent. */
|
|
51
|
+
subscribe(subagentId: string, handler: FleetHandler): () => void;
|
|
52
|
+
/** Subscribe to one event type across all subagents. */
|
|
53
|
+
filter(type: string, handler: FleetHandler): () => void;
|
|
54
|
+
/** Subscribe to literally everything. The fleet roll-up uses this. */
|
|
55
|
+
onAny(handler: FleetHandler): () => void;
|
|
56
|
+
emit(event: FleetEvent): void;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Roll-up of token usage + cost across an entire director run. The
|
|
60
|
+
* director's `fleet_status` tool returns this so the model can reason
|
|
61
|
+
* about budget in its next turn ("the researcher already burned $0.40,
|
|
62
|
+
* lean on summaries for the next task").
|
|
63
|
+
*/
|
|
64
|
+
interface FleetUsage {
|
|
65
|
+
total: {
|
|
66
|
+
input: number;
|
|
67
|
+
output: number;
|
|
68
|
+
cacheRead: number;
|
|
69
|
+
cacheWrite: number;
|
|
70
|
+
cost: number;
|
|
71
|
+
};
|
|
72
|
+
perSubagent: Record<string, SubagentUsageSnapshot>;
|
|
73
|
+
}
|
|
74
|
+
interface SubagentUsageSnapshot {
|
|
75
|
+
subagentId: string;
|
|
76
|
+
provider?: string;
|
|
77
|
+
model?: string;
|
|
78
|
+
input: number;
|
|
79
|
+
output: number;
|
|
80
|
+
cacheRead: number;
|
|
81
|
+
cacheWrite: number;
|
|
82
|
+
cost: number;
|
|
83
|
+
toolCalls: number;
|
|
84
|
+
iterations: number;
|
|
85
|
+
startedAt: number;
|
|
86
|
+
lastEventAt: number;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Aggregates provider.response + tool.executed events from the FleetBus
|
|
90
|
+
* into a live `FleetUsage` snapshot. Costs are computed by the caller
|
|
91
|
+
* via a `priceLookup(subagentId)` so we don't bake provider-pricing
|
|
92
|
+
* coupling into core; the CLI/tests supply a function that resolves
|
|
93
|
+
* each subagent's per-token rates from the models registry.
|
|
94
|
+
*/
|
|
95
|
+
declare class FleetUsageAggregator {
|
|
96
|
+
private readonly bus;
|
|
97
|
+
private readonly priceLookup?;
|
|
98
|
+
private readonly metaLookup?;
|
|
99
|
+
private readonly perSubagent;
|
|
100
|
+
private readonly total;
|
|
101
|
+
constructor(bus: FleetBus, priceLookup?: ((subagentId: string) => {
|
|
102
|
+
input?: number;
|
|
103
|
+
output?: number;
|
|
104
|
+
cacheRead?: number;
|
|
105
|
+
cacheWrite?: number;
|
|
106
|
+
} | undefined) | undefined, metaLookup?: ((subagentId: string) => {
|
|
107
|
+
provider?: string;
|
|
108
|
+
model?: string;
|
|
109
|
+
} | undefined) | undefined);
|
|
110
|
+
/** Live snapshot — safe to call from a tool's execute() body. */
|
|
111
|
+
snapshot(): FleetUsage;
|
|
112
|
+
private ensure;
|
|
113
|
+
private onProviderResponse;
|
|
114
|
+
private onToolExecuted;
|
|
115
|
+
private onIterationStarted;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Caller-supplied factory that builds an isolated `Agent` for a subagent.
|
|
120
|
+
* The factory MUST construct a fresh `Context` per call — sharing context
|
|
121
|
+
* between subagents defeats isolation. Each Agent should also use either
|
|
122
|
+
* its own `EventBus` or a forwarded view, so per-subagent metrics can be
|
|
123
|
+
* attributed correctly.
|
|
124
|
+
*/
|
|
125
|
+
type AgentFactory = (config: SubagentConfig) => Promise<AgentFactoryResult>;
|
|
126
|
+
interface AgentFactoryResult {
|
|
127
|
+
agent: Agent;
|
|
128
|
+
/** Event bus the factory wired to this agent — required for budget hookup. */
|
|
129
|
+
events: EventBus;
|
|
130
|
+
/**
|
|
131
|
+
* Optional cleanup hook invoked in the runner's `finally` block once
|
|
132
|
+
* the task ends (success, failure, abort — same exit path). Factories
|
|
133
|
+
* that own resources scoped to a single task (per-subagent JSONL
|
|
134
|
+
* writers, transient providers, throwaway containers) implement this
|
|
135
|
+
* to close them deterministically instead of relying on GC. Errors
|
|
136
|
+
* thrown here are swallowed so a flaky cleanup can't mask the task's
|
|
137
|
+
* real result.
|
|
138
|
+
*/
|
|
139
|
+
dispose?: () => Promise<void> | void;
|
|
140
|
+
}
|
|
141
|
+
interface AgentRunnerOptions {
|
|
142
|
+
factory: AgentFactory;
|
|
143
|
+
/**
|
|
144
|
+
* Format a TaskSpec into the user input the agent will receive. Defaults
|
|
145
|
+
* to `task.description ?? ''`. Override when subagents expect structured
|
|
146
|
+
* input (e.g. JSON contracts, role-prefixed prompts).
|
|
147
|
+
*/
|
|
148
|
+
formatTaskInput?: (task: TaskSpec, config: SubagentConfig) => AgentInput;
|
|
149
|
+
/**
|
|
150
|
+
* When set, the runner attaches the subagent's EventBus to this FleetBus
|
|
151
|
+
* on task start and detaches it when the task finishes. This is the
|
|
152
|
+
* injection seam that lets the TUI fleet panel observe subagent activity
|
|
153
|
+
* live — without it, FleetBus stays empty.
|
|
154
|
+
*/
|
|
155
|
+
fleetBus?: FleetBus;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Builds a `SubagentRunner` that drives a real `Agent` per task while honoring
|
|
159
|
+
* the coordinator's budget and abort signal. This is the production adapter —
|
|
160
|
+
* the coordinator's `runner` option in CLI/TUI assemblies points here.
|
|
161
|
+
*
|
|
162
|
+
* Lifecycle per task:
|
|
163
|
+
* 1. factory(config) → fresh Agent + EventBus.
|
|
164
|
+
* 2. Subscribe to events to feed the budget (tool calls, token usage).
|
|
165
|
+
* 3. Call agent.run(input, { signal }) — the coordinator's signal cancels.
|
|
166
|
+
* 4. Map RunResult.status onto a `SubagentRunOutcome` or throw on failure.
|
|
167
|
+
* 5. Unsubscribe and let the factory's resources be GC'd.
|
|
168
|
+
*
|
|
169
|
+
* The budget is checked synchronously from event handlers — a runaway agent
|
|
170
|
+
* that crosses its tool-call limit triggers `BudgetExceededError`, which the
|
|
171
|
+
* coordinator surfaces as `status: 'failed'` on the task result.
|
|
172
|
+
*/
|
|
173
|
+
declare function makeAgentSubagentRunner(opts: AgentRunnerOptions): SubagentRunner;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Catalog types for the WrongStack agent fleet.
|
|
177
|
+
*
|
|
178
|
+
* An `AgentDefinition` bundles the runtime `SubagentConfig` (id/name/role/
|
|
179
|
+
* prompt/tools) with two things the bare config lacks:
|
|
180
|
+
* - a per-role `budget` tier (consumed by FLEET_ROSTER_BUDGETS), and
|
|
181
|
+
* - dispatcher `capability` metadata (keywords + summary + phase) used by
|
|
182
|
+
* the smart dispatcher to route a free-form task to the best agent.
|
|
183
|
+
*
|
|
184
|
+
* Phase files (`phase1-discovery.ts` … `phase9-meta.ts`) each export an
|
|
185
|
+
* `AgentDefinition[]`; `index.ts` aggregates them into `AGENT_CATALOG`.
|
|
186
|
+
* `fleet.ts` derives `FLEET_ROSTER` + `FLEET_ROSTER_BUDGETS` from the catalog.
|
|
187
|
+
*/
|
|
188
|
+
|
|
189
|
+
/** Lifecycle phase grouping. Drives statusline labels + dispatcher tie-breaks. */
|
|
190
|
+
type AgentPhase = 'discovery' | 'planning' | 'build' | 'verify' | 'review' | 'domain' | 'knowledge' | 'delivery' | 'meta';
|
|
191
|
+
/** Per-role budget tier. Same shape as fleet.ts `FleetRosterBudget`. */
|
|
192
|
+
interface AgentBudgetTier {
|
|
193
|
+
timeoutMs?: number;
|
|
194
|
+
maxIterations?: number;
|
|
195
|
+
maxToolCalls?: number;
|
|
196
|
+
maxTokens?: number;
|
|
197
|
+
maxCostUsd?: number;
|
|
198
|
+
}
|
|
199
|
+
/** Dispatcher routing metadata. */
|
|
200
|
+
interface AgentCapability {
|
|
201
|
+
phase: AgentPhase;
|
|
202
|
+
/**
|
|
203
|
+
* One-line capability summary. Fed to the LLM dispatcher classifier as the
|
|
204
|
+
* candidate's description, and shown to the user when explaining a routing
|
|
205
|
+
* decision. Keep it concrete and distinct from sibling agents.
|
|
206
|
+
*/
|
|
207
|
+
summary: string;
|
|
208
|
+
/**
|
|
209
|
+
* Lowercased signal words/phrases for the heuristic dispatcher. A task whose
|
|
210
|
+
* description contains these scores toward this agent. Order doesn't matter;
|
|
211
|
+
* prefer specific terms ("graphql", "wcag") over generic ones ("code").
|
|
212
|
+
*/
|
|
213
|
+
keywords: string[];
|
|
214
|
+
}
|
|
215
|
+
/** A single catalog entry: runtime config + budget tier + routing metadata. */
|
|
216
|
+
interface AgentDefinition {
|
|
217
|
+
config: SubagentConfig;
|
|
218
|
+
budget: AgentBudgetTier;
|
|
219
|
+
capability: AgentCapability;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Budget tiers by workload weight. Deliberately generous — the project's
|
|
223
|
+
* existing roster uses multi-hour ceilings to avoid spurious timeouts on
|
|
224
|
+
* monorepo-scale work, and the auto-extend handshake raises them further when
|
|
225
|
+
* a subagent is still making progress.
|
|
226
|
+
*/
|
|
227
|
+
declare const LIGHT_BUDGET: AgentBudgetTier;
|
|
228
|
+
declare const MEDIUM_BUDGET: AgentBudgetTier;
|
|
229
|
+
declare const HEAVY_BUDGET: AgentBudgetTier;
|
|
230
|
+
/**
|
|
231
|
+
* Tool allowlist presets. Agents pass the smallest set that covers their job —
|
|
232
|
+
* a planning agent should not hold `write`/`bash`, a reviewer should be
|
|
233
|
+
* read-only. Spread + extend per-agent where a role needs one extra tool.
|
|
234
|
+
*/
|
|
235
|
+
declare const TOOLS: {
|
|
236
|
+
/** Pure read/inspect — safe for analysis and review agents. */
|
|
237
|
+
readonly read: readonly ["read", "grep", "glob", "search", "tree"];
|
|
238
|
+
/** Read + structured inspection (logs, diffs, json, dependency audit). */
|
|
239
|
+
readonly inspect: readonly ["read", "grep", "glob", "search", "tree", "json", "diff", "logs", "audit"];
|
|
240
|
+
/** Read + edit (no shell). For agents that write code/docs but don't run it. */
|
|
241
|
+
readonly write: readonly ["read", "grep", "glob", "search", "tree", "write", "edit", "replace", "patch"];
|
|
242
|
+
/** Full build loop: edit + run (lint/format/typecheck/test/bash). */
|
|
243
|
+
readonly build: readonly ["read", "grep", "glob", "search", "tree", "write", "edit", "replace", "patch", "bash", "exec", "lint", "format", "typecheck", "test"];
|
|
244
|
+
/** Version control. */
|
|
245
|
+
readonly vcs: readonly ["read", "grep", "glob", "git", "diff"];
|
|
246
|
+
/** Dependency management + CVE audit. */
|
|
247
|
+
readonly deps: readonly ["read", "grep", "glob", "install", "outdated", "audit", "json"];
|
|
248
|
+
/** Documentation authoring. */
|
|
249
|
+
readonly docs: readonly ["read", "grep", "glob", "search", "tree", "write", "edit", "document"];
|
|
250
|
+
/** Web research. */
|
|
251
|
+
readonly research: readonly ["read", "grep", "glob", "search", "fetch"];
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Smart agent dispatcher.
|
|
256
|
+
*
|
|
257
|
+
* Routes a free-form task description to the best agent in the catalog using a
|
|
258
|
+
* two-stage strategy:
|
|
259
|
+
*
|
|
260
|
+
* 1. Heuristic — keyword/phrase scoring against each agent's `capability`
|
|
261
|
+
* metadata. Deterministic, instant, no provider call. Multi-word phrases
|
|
262
|
+
* score higher than single words (they're more specific signals).
|
|
263
|
+
*
|
|
264
|
+
* 2. LLM fallback — when the heuristic is ambiguous (confidence below the
|
|
265
|
+
* threshold, or no keyword hit at all) an injected `classifier` resolves
|
|
266
|
+
* the tie. The classifier is provider-agnostic: callers wire it to any
|
|
267
|
+
* `complete(prompt) => text` function via `makeLLMClassifier`, so core
|
|
268
|
+
* stays free of provider dependencies and the path is unit-testable.
|
|
269
|
+
*
|
|
270
|
+
* If neither stage yields a confident pick, the dispatcher falls back to the
|
|
271
|
+
* `executor` generalist rather than failing.
|
|
272
|
+
*/
|
|
273
|
+
|
|
274
|
+
/** Default agent used when nothing else matches — the generalist builder. */
|
|
275
|
+
declare const DEFAULT_DISPATCH_ROLE = "executor";
|
|
276
|
+
interface DispatchCandidate {
|
|
277
|
+
role: string;
|
|
278
|
+
name: string;
|
|
279
|
+
score: number;
|
|
280
|
+
/** Capability keywords that matched the task text. */
|
|
281
|
+
matched: string[];
|
|
282
|
+
}
|
|
283
|
+
type DispatchMethod = 'heuristic' | 'llm' | 'fallback';
|
|
284
|
+
interface DispatchResult {
|
|
285
|
+
role: string;
|
|
286
|
+
definition: AgentDefinition;
|
|
287
|
+
/** 0..1 — heuristic margin, or 1 when an LLM made a definite choice. */
|
|
288
|
+
confidence: number;
|
|
289
|
+
method: DispatchMethod;
|
|
290
|
+
/** Human-readable explanation of why this agent was chosen. */
|
|
291
|
+
reason: string;
|
|
292
|
+
/** Runner-up candidates (top heuristic scorers), best-first. */
|
|
293
|
+
alternatives: DispatchCandidate[];
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Provider-agnostic classifier seam. Given the task and the candidate agents
|
|
297
|
+
* (role + summary), return the chosen role (and optional reason), or null to
|
|
298
|
+
* decline. Wire via `makeLLMClassifier`.
|
|
299
|
+
*/
|
|
300
|
+
type DispatchClassifier = (task: string, candidates: {
|
|
301
|
+
role: string;
|
|
302
|
+
name: string;
|
|
303
|
+
summary: string;
|
|
304
|
+
}[]) => Promise<{
|
|
305
|
+
role: string;
|
|
306
|
+
reason?: string;
|
|
307
|
+
} | null>;
|
|
308
|
+
interface DispatchOptions {
|
|
309
|
+
/** Optional LLM fallback for ambiguous tasks. */
|
|
310
|
+
classifier?: DispatchClassifier;
|
|
311
|
+
/** Heuristic confidence below this triggers the classifier. Default 0.4. */
|
|
312
|
+
confidenceThreshold?: number;
|
|
313
|
+
/** How many top candidates to offer the classifier. Default 6. */
|
|
314
|
+
maxCandidates?: number;
|
|
315
|
+
/** Override the catalog (testing). Defaults to the full `AGENT_CATALOG`. */
|
|
316
|
+
catalog?: Record<string, AgentDefinition>;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Score every agent against the task. A keyword hit adds 1 point; a multi-word
|
|
320
|
+
* keyword phrase adds points equal to its word count (more specific = stronger
|
|
321
|
+
* signal). Returns candidates sorted best-first, zero-score agents dropped.
|
|
322
|
+
*/
|
|
323
|
+
declare function scoreAgents(task: string, catalog?: Record<string, AgentDefinition>): DispatchCandidate[];
|
|
324
|
+
/**
|
|
325
|
+
* Route a task to the best agent. Async because the LLM fallback may run; the
|
|
326
|
+
* pure-heuristic path resolves without awaiting anything.
|
|
327
|
+
*/
|
|
328
|
+
declare function dispatchAgent(task: string, opts?: DispatchOptions): Promise<DispatchResult>;
|
|
329
|
+
/**
|
|
330
|
+
* Build a `DispatchClassifier` from a minimal `complete(prompt) => text`
|
|
331
|
+
* function. The caller supplies the provider call; this owns the prompt and
|
|
332
|
+
* the parsing. Keeps `dispatcher` free of any provider import.
|
|
333
|
+
*/
|
|
334
|
+
declare function makeLLMClassifier(complete: (prompt: string) => Promise<string>): DispatchClassifier;
|
|
335
|
+
|
|
336
|
+
interface MultiAgentCoordinatorOptions {
|
|
337
|
+
/**
|
|
338
|
+
* Callback that executes a task on behalf of a subagent. Required for
|
|
339
|
+
* `assign()` to actually run anything — without it, tasks queue forever.
|
|
340
|
+
* The coordinator provides per-subagent isolation (own budget, own signal,
|
|
341
|
+
* own bridge) and enforces timeout + concurrency.
|
|
342
|
+
*/
|
|
343
|
+
runner?: SubagentRunner;
|
|
344
|
+
}
|
|
345
|
+
declare class DefaultMultiAgentCoordinator extends EventEmitter implements MultiAgentCoordinator {
|
|
346
|
+
readonly coordinatorId: string;
|
|
347
|
+
readonly config: MultiAgentConfig;
|
|
348
|
+
private runner?;
|
|
349
|
+
private readonly subagents;
|
|
350
|
+
private pendingTasks;
|
|
351
|
+
private completedResults;
|
|
352
|
+
private totalIterations;
|
|
353
|
+
private inFlight;
|
|
354
|
+
/**
|
|
355
|
+
* Subagents currently being stopped. Set on entry to `stop()`, cleared
|
|
356
|
+
* once `recordCompletion` lands the terminal TaskResult. Used by
|
|
357
|
+
* `runDispatched` and `findIdleSubagent` to refuse mid-flight dispatch
|
|
358
|
+
* to a subagent the caller has already asked to terminate — closes the
|
|
359
|
+
* assign+terminate race where a fresh task could land on a worker that
|
|
360
|
+
* was about to be killed.
|
|
361
|
+
*/
|
|
362
|
+
private readonly terminating;
|
|
363
|
+
constructor(config: MultiAgentConfig, options?: MultiAgentCoordinatorOptions);
|
|
364
|
+
/**
|
|
365
|
+
* Replace the runner after construction. Used when the runner depends
|
|
366
|
+
* on infrastructure (e.g. FleetBus) that isn't available until after
|
|
367
|
+
* the coordinator's owning Director is built.
|
|
368
|
+
*/
|
|
369
|
+
setRunner(runner: SubagentRunner): void;
|
|
370
|
+
/**
|
|
371
|
+
* Change the in-flight dispatch ceiling at runtime. Lowering does NOT
|
|
372
|
+
* preempt running tasks — already-dispatched subagents finish their
|
|
373
|
+
* current task; only future dispatches respect the new cap. Raising
|
|
374
|
+
* immediately tries to fill the freed slots from the pending queue.
|
|
375
|
+
*/
|
|
376
|
+
setMaxConcurrent(n: number): void;
|
|
377
|
+
spawn(subagent: SubagentConfig): Promise<SpawnResult>;
|
|
378
|
+
assign(task: TaskSpec): Promise<void>;
|
|
379
|
+
delegate(to: string, msg: BridgeMessage): Promise<void>;
|
|
380
|
+
/**
|
|
381
|
+
* Wire up the communication bridge for a subagent. Call after spawn() once
|
|
382
|
+
* the caller has created the bidirectional connection.
|
|
383
|
+
*/
|
|
384
|
+
setSubagentBridge(subagentId: string, bridge: AgentBridge): void;
|
|
385
|
+
stop(subagentId: string): Promise<void>;
|
|
386
|
+
stopAll(): Promise<void>;
|
|
387
|
+
remove(subagentId: string): Promise<void>;
|
|
388
|
+
/**
|
|
389
|
+
* Get current coordinator stats for monitoring/debugging.
|
|
390
|
+
*/
|
|
391
|
+
getStats(): {
|
|
392
|
+
total: number;
|
|
393
|
+
running: number;
|
|
394
|
+
idle: number;
|
|
395
|
+
stopped: number;
|
|
396
|
+
inFlight: number;
|
|
397
|
+
pending: number;
|
|
398
|
+
completed: number;
|
|
399
|
+
};
|
|
400
|
+
getStatus(): CoordinatorStatus;
|
|
401
|
+
/** Expose snapshot of completed results — useful for callers awaiting all done. */
|
|
402
|
+
results(): readonly TaskResult[];
|
|
403
|
+
/**
|
|
404
|
+
* Wait for one or more tasks to complete and return their results.
|
|
405
|
+
* If a task is already done when called, returns immediately.
|
|
406
|
+
* Resolves to an array in the same order as `taskIds`.
|
|
407
|
+
*/
|
|
408
|
+
awaitTasks(taskIds: string[]): Promise<TaskResult[]>;
|
|
409
|
+
/**
|
|
410
|
+
* Manual completion — for callers that drive subagents without a runner
|
|
411
|
+
* (e.g. external orchestrators). When a runner is configured the coordinator
|
|
412
|
+
* calls this itself.
|
|
413
|
+
*/
|
|
414
|
+
completeTask(result: TaskResult): void;
|
|
415
|
+
private tryDispatchNext;
|
|
416
|
+
private canDispatch;
|
|
417
|
+
private takeNextDispatchableTask;
|
|
418
|
+
private findIdleSubagent;
|
|
419
|
+
private isIdleSubagent;
|
|
420
|
+
/**
|
|
421
|
+
* Returns true iff at least one spawned subagent could still
|
|
422
|
+
* process a task. A "live" subagent is one that is not stopped
|
|
423
|
+
* AND not mid-termination — `running` workers count because they
|
|
424
|
+
* will eventually finish and become idle.
|
|
425
|
+
*
|
|
426
|
+
* When no subagent has ever been spawned, returns `true` so a
|
|
427
|
+
* pre-spawn `assign()` simply queues (legacy behaviour). The
|
|
428
|
+
* dead-end detection only fires after `stop()` has retired every
|
|
429
|
+
* spawned worker.
|
|
430
|
+
*
|
|
431
|
+
* Used by `tryDispatchNext` to detect a dead-end pending queue.
|
|
432
|
+
*/
|
|
433
|
+
private hasLiveSubagent;
|
|
434
|
+
/**
|
|
435
|
+
* Drain every pending task with a synthetic `aborted_by_parent`
|
|
436
|
+
* completion event. Same shape as the `stopAll()` drain — we go
|
|
437
|
+
* around `recordCompletion` because pending tasks were never
|
|
438
|
+
* counted in `inFlight` and routing them through would trip the
|
|
439
|
+
* underflow guard on every task after the first.
|
|
440
|
+
*/
|
|
441
|
+
private drainPendingAsAborted;
|
|
442
|
+
private runDispatched;
|
|
443
|
+
private executeWithTimeout;
|
|
444
|
+
private recordCompletion;
|
|
445
|
+
private isDone;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
export { type AgentDefinition as A, DEFAULT_DISPATCH_ROLE as D, FleetBus as F, HEAVY_BUDGET as H, LIGHT_BUDGET as L, MEDIUM_BUDGET as M, type SubagentUsageSnapshot as S, TOOLS as T, type AgentBudgetTier as a, type AgentCapability as b, type AgentFactory as c, type AgentFactoryResult as d, type AgentPhase as e, type AgentRunnerOptions as f, DefaultMultiAgentCoordinator as g, type DispatchCandidate as h, type DispatchClassifier as i, type DispatchMethod as j, type DispatchOptions as k, type DispatchResult as l, type FleetEvent as m, type FleetHandler as n, type FleetUsage as o, FleetUsageAggregator as p, type MultiAgentCoordinatorOptions as q, dispatchAgent as r, makeAgentSubagentRunner as s, makeLLMClassifier as t, scoreAgents as u };
|