@cuylabs/agent-core 0.8.0 → 0.10.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 (127) hide show
  1. package/README.md +33 -17
  2. package/dist/chunk-2O4MCSQS.js +780 -0
  3. package/dist/chunk-2TTOLHBT.js +198 -0
  4. package/dist/chunk-5FMSGQVX.js +281 -0
  5. package/dist/chunk-5NVVNXPQ.js +288 -0
  6. package/dist/{chunk-CAA7FHIH.js → chunk-6HZBHFOL.js} +3 -103
  7. package/dist/chunk-CJI7PVS2.js +58 -0
  8. package/dist/{chunk-N6HWIEEA.js → chunk-CMYN2RCB.js} +278 -61
  9. package/dist/chunk-FII65CN7.js +117 -0
  10. package/dist/{chunk-IVUJDISU.js → chunk-GFTW23FV.js} +5 -14
  11. package/dist/chunk-I6PKJ7XQ.js +292 -0
  12. package/dist/{chunk-BDBZ3SLK.js → chunk-ICZ66572.js} +48 -4
  13. package/dist/chunk-KYLPMBHD.js +316 -0
  14. package/dist/chunk-MXAP4UG6.js +2956 -0
  15. package/dist/{chunk-RZITT45F.js → chunk-N3VX7FEE.js} +39 -6
  16. package/dist/{chunk-YSLSEQ6B.js → chunk-NDZWXCBZ.js} +218 -95
  17. package/dist/{chunk-P6YF7USR.js → chunk-Q742PSH3.js} +23 -38
  18. package/dist/chunk-QAL3OMI3.js +943 -0
  19. package/dist/{chunk-RFEKJKTO.js → chunk-RN6WZEUF.js} +330 -280
  20. package/dist/{chunk-ZXAKHMWH.js → chunk-ROTGCYDW.js} +22 -84
  21. package/dist/chunk-SPBFQXOT.js +0 -0
  22. package/dist/{chunk-LRHOS4ZN.js → chunk-SPILYYDF.js} +3 -2
  23. package/dist/chunk-SSFBF3US.js +602 -0
  24. package/dist/chunk-SZ2XBPTW.js +8 -0
  25. package/dist/chunk-T4UIX5D7.js +115 -0
  26. package/dist/chunk-TIHPYVAJ.js +102 -0
  27. package/dist/{chunk-YUUJK53A.js → chunk-TOTDGK3P.js} +1 -1
  28. package/dist/chunk-V4RFNEET.js +563 -0
  29. package/dist/chunk-VOUEJSW6.js +0 -0
  30. package/dist/{chunk-4BDA7DQY.js → chunk-WBPOZ7CL.js} +673 -273
  31. package/dist/chunk-X4VN4GIJ.js +185 -0
  32. package/dist/dispatch/index.d.ts +93 -0
  33. package/dist/dispatch/index.js +37 -0
  34. package/dist/events/index.d.ts +93 -0
  35. package/dist/events/index.js +6 -0
  36. package/dist/{runtime → execution}/index.d.ts +120 -34
  37. package/dist/{runtime → execution}/index.js +18 -13
  38. package/dist/index-BCqEGzBj.d.ts +251 -0
  39. package/dist/index.d.ts +490 -122
  40. package/dist/index.js +2104 -615
  41. package/dist/{errors → inference/errors}/index.d.ts +2 -2
  42. package/dist/{errors → inference/errors}/index.js +1 -1
  43. package/dist/inference/index.d.ts +16 -23
  44. package/dist/inference/index.js +45 -16
  45. package/dist/instance-BqV2D5pc.d.ts +5723 -0
  46. package/dist/logger/index.d.ts +50 -0
  47. package/dist/logger/index.js +11 -0
  48. package/dist/mcp/index.d.ts +5 -9
  49. package/dist/mcp/index.js +2 -3
  50. package/dist/middleware/index.d.ts +10 -149
  51. package/dist/middleware/index.js +11 -3
  52. package/dist/model-messages-B4nK9D1-.d.ts +13 -0
  53. package/dist/models/index.d.ts +23 -18
  54. package/dist/models/index.js +48 -11
  55. package/dist/models/reasoning/index.d.ts +4 -0
  56. package/dist/{reasoning → models/reasoning}/index.js +3 -3
  57. package/dist/plugin/index.d.ts +458 -0
  58. package/dist/plugin/index.js +32 -0
  59. package/dist/profiles/index.d.ts +55 -0
  60. package/dist/profiles/index.js +30 -0
  61. package/dist/prompt/index.d.ts +8 -12
  62. package/dist/prompt/index.js +3 -2
  63. package/dist/safety/index.d.ts +109 -14
  64. package/dist/safety/index.js +59 -3
  65. package/dist/sandbox/index.d.ts +81 -0
  66. package/dist/sandbox/index.js +1 -0
  67. package/dist/skill/index.d.ts +10 -8
  68. package/dist/skill/index.js +3 -3
  69. package/dist/storage/index.d.ts +12 -4
  70. package/dist/storage/index.js +1 -1
  71. package/dist/subagents/index.d.ts +177 -0
  72. package/dist/subagents/index.js +78 -0
  73. package/dist/team/index.d.ts +544 -0
  74. package/dist/team/index.js +41 -0
  75. package/dist/tool/host/index.d.ts +41 -0
  76. package/dist/tool/host/index.js +10 -0
  77. package/dist/tool/index.d.ts +125 -21
  78. package/dist/tool/index.js +20 -13
  79. package/dist/{types-VQgymC1N.d.ts → types-Bj_J8u_W.d.ts} +44 -64
  80. package/dist/{types-CHiPh8U2.d.ts → types-C_LCeYNg.d.ts} +7 -7
  81. package/dist/types-RSCv7nQ4.d.ts +59 -0
  82. package/package.json +58 -53
  83. package/dist/builder-UpOWQMW3.d.ts +0 -34
  84. package/dist/chunk-7MUFEN4K.js +0 -559
  85. package/dist/chunk-7VKQ4WPB.js +0 -73
  86. package/dist/chunk-BFM2YHNM.js +0 -222
  87. package/dist/chunk-DWYX7ASF.js +0 -26
  88. package/dist/chunk-KUVSERLJ.js +0 -50
  89. package/dist/chunk-N7P4PN3O.js +0 -84
  90. package/dist/chunk-SDSBEQXG.js +0 -157
  91. package/dist/chunk-SQU2AJHO.js +0 -305
  92. package/dist/chunk-VBWWUHWI.js +0 -724
  93. package/dist/chunk-VEKUXUVF.js +0 -41
  94. package/dist/chunk-VNQBHPCT.js +0 -398
  95. package/dist/chunk-WWYYNWEW.js +0 -259
  96. package/dist/context/index.d.ts +0 -259
  97. package/dist/context/index.js +0 -26
  98. package/dist/events-CE72w8W4.d.ts +0 -149
  99. package/dist/host/index.d.ts +0 -45
  100. package/dist/host/index.js +0 -8
  101. package/dist/index-CWSchSql.d.ts +0 -1058
  102. package/dist/messages-BYWGn8TY.d.ts +0 -110
  103. package/dist/presets/index.d.ts +0 -53
  104. package/dist/presets/index.js +0 -28
  105. package/dist/reasoning/index.d.ts +0 -116
  106. package/dist/registry-DwYqsQkX.d.ts +0 -164
  107. package/dist/runner-e2YRcUoX.d.ts +0 -786
  108. package/dist/scope/index.d.ts +0 -10
  109. package/dist/scope/index.js +0 -14
  110. package/dist/session-manager-B_CWGTsl.d.ts +0 -274
  111. package/dist/signal/index.d.ts +0 -28
  112. package/dist/signal/index.js +0 -6
  113. package/dist/sub-agent/index.d.ts +0 -23
  114. package/dist/sub-agent/index.js +0 -15
  115. package/dist/tool-BHbyUAy3.d.ts +0 -150
  116. package/dist/tool-DLXAR9Ce.d.ts +0 -145
  117. package/dist/tracker-DClqYqTj.d.ts +0 -96
  118. package/dist/tracking/index.d.ts +0 -111
  119. package/dist/tracking/index.js +0 -20
  120. package/dist/types-BfNpU8NS.d.ts +0 -270
  121. package/dist/types-BnpEOYV-.d.ts +0 -50
  122. package/dist/types-CQL-SvTn.d.ts +0 -29
  123. package/dist/types-CWm-7rvB.d.ts +0 -55
  124. package/dist/types-KKDrdU9Y.d.ts +0 -325
  125. package/dist/types-QA4WhEfz.d.ts +0 -138
  126. package/dist/types-QKHHQLLq.d.ts +0 -336
  127. package/dist/types-YuWV4ag7.d.ts +0 -72
@@ -0,0 +1,544 @@
1
+ import { aB as CoordinatorNotification, cS as TaskCompletion, dg as TokenUsage, A as AgentEvent, dT as CoordinatorCtx, B as Agent, bw as MemberRuntime, cP as TaskBoard, bs as Mailbox, cW as TaskDispatchMode, bV as PermissionHandler, d4 as TeamCoordinatorConfig, cX as TaskExecutor, d5 as TeamEvent, d6 as TeamMember, c6 as QueueTaskInput, dd as TeamTask, d7 as TeamMessage, d9 as TeamPlan, cL as SynthesisResult, da as TeamSnapshot, c_ as TaskListFilter, bF as MessageListFilter, c1 as PreparedExternalTask, c$ as TaskResult, d1 as TaskTransition, bx as MemberStats, by as MemberStatus, L as AgentMiddleware, dh as ToolCallDecision } from '../instance-BqV2D5pc.js';
2
+ export { aC as CoordinatorNotificationKind, aD as CoordinatorRoundEvent, b7 as ExternalTaskControl, b9 as GuidancePayload, bl as IdleNotificationPayload, bm as InMemoryMailboxStore, bn as InMemoryTaskBoardStore, bt as MailboxStore, bu as MailboxSubscriber, bv as MemberRegisteredEvent, bz as MemberStatusChangedEvent, bD as MessageInput, bE as MessageKind, bG as MessagePayload, bI as MessageSentEvent, bO as NotificationPriority, bU as PermissionForwardedEvent, bW as PermissionRequestPayload, bX as PermissionResolvedEvent, bY as PermissionResponsePayload, bZ as PlanCreatedEvent, b_ as PlannedTask, cm as ShutdownRequestPayload, cn as ShutdownRequestedEvent, co as ShutdownResolvedEvent, cp as ShutdownResponsePayload, cK as SynthesisCompleteEvent, cN as TERMINAL_STATUSES, cO as TaskAbortedEvent, cQ as TaskBoardStore, cR as TaskCompletedEvent, cT as TaskConflictError, cU as TaskCreateInput, cV as TaskCreatedEvent, cY as TaskExecutorInput, cZ as TaskFailedEvent, d0 as TaskStatus, d2 as TaskTransitionEvent, d3 as TaskTransitionReason, d8 as TeamNotificationEvent, db as TeamStartedEvent, dc as TeamStoppedEvent, dw as WorkerReportPayload, dA as buildCoordinatorNotificationEvent } from '../instance-BqV2D5pc.js';
3
+ import { R as ReasoningLevel } from '../types-CQaXbRsS.js';
4
+ import '../types-C_LCeYNg.js';
5
+ import 'ai';
6
+ import '../types-RSCv7nQ4.js';
7
+ import 'zod';
8
+ import '../types-Bj_J8u_W.js';
9
+ import '@ai-sdk/provider-utils';
10
+ import '../sandbox/index.js';
11
+ import '../llm-error-D93FNNLY.js';
12
+
13
+ interface CoordinatorInboxItem {
14
+ id: string;
15
+ kind: "user-message" | "notification";
16
+ createdAt: string;
17
+ body: string;
18
+ notification?: CoordinatorNotification;
19
+ }
20
+ interface CoordinatorRuntimeStatus {
21
+ phase: "ready" | "running" | "waiting" | "error";
22
+ message: string;
23
+ pendingInboxCount: number;
24
+ activeTaskCount: number;
25
+ }
26
+ interface CoordinatorStatus {
27
+ phase: "thinking" | "waiting" | "done";
28
+ round: number;
29
+ message: string;
30
+ }
31
+ interface WorkerReport {
32
+ messageId: string;
33
+ memberId: string;
34
+ taskId?: string;
35
+ createdAt?: string;
36
+ message: string;
37
+ }
38
+ interface CoordinatorRound {
39
+ number: number;
40
+ assigned: Array<{
41
+ taskId: string;
42
+ memberId: string;
43
+ title: string;
44
+ }>;
45
+ messaged: Array<{
46
+ memberId: string;
47
+ }>;
48
+ stopped: string[];
49
+ completions: TaskCompletion[];
50
+ reports: WorkerReport[];
51
+ response: string;
52
+ usage: TokenUsage;
53
+ }
54
+ interface CoordinatorLoopOptions {
55
+ maxRounds?: number;
56
+ waitTimeoutMs?: number;
57
+ onRound?: (round: CoordinatorRound) => void | Promise<void>;
58
+ onStatus?: (status: CoordinatorStatus) => void;
59
+ onCoordinatorEvent?: (event: AgentEvent) => void;
60
+ onLog?: (message: string) => void;
61
+ coordinatorReasoningLevel?: ReasoningLevel;
62
+ }
63
+ interface CoordinatorLoopResult {
64
+ response: string;
65
+ rounds: CoordinatorRound[];
66
+ usage: TokenUsage;
67
+ }
68
+
69
+ /**
70
+ * Team Coordinator
71
+ *
72
+ * Orchestrates a team of forked agents working toward a shared goal.
73
+ *
74
+ * Responsibilities:
75
+ * - Register members by forking agents from roles
76
+ * - Queue and dispatch tasks with dependency-aware scheduling
77
+ * - Route messages between coordinator and members
78
+ * - Track task execution and cascade status transitions
79
+ * - Synthesize results from completed tasks
80
+ * - Emit team events for observability
81
+ *
82
+ * The coordinator is deliberately host-agnostic. It uses:
83
+ * - `TaskBoard` + `TaskBoardStore` for task/member persistence
84
+ * - `Mailbox` + `MailboxStore` for messaging persistence
85
+ * - `Agent.fork()` + `Agent.run()` for member execution
86
+ *
87
+ * Hosts (CLI, HTTP server, chatbot) provide concrete stores
88
+ * and wire the coordinator to their UI/transport layer.
89
+ *
90
+ * Design choices vs CLI CliTeamController:
91
+ * - No dependency on agent-runtime's orchestrator — uses Agent.run() directly
92
+ * - Explicit "claimed" state between pending and running
93
+ * - Event-driven via TeamEvent emitter instead of mailbox system messages
94
+ * - Members tracked as `{ agent, member, role }` tuples
95
+ * - `guide()` method for mid-task interventions via InterventionController
96
+ * - Configurable `onEvent` callback instead of coupling to a specific event bus
97
+ *
98
+ * Execution, work-loop, and shutdown logic are extracted into
99
+ * focused modules to keep this file manageable:
100
+ * - `execution.ts` — task dispatch and Agent.run() lifecycle
101
+ * - `work-loop.ts` — persistent idle loop and auto-claim
102
+ * - `shutdown.ts` — two-phase graceful shutdown protocol
103
+ */
104
+
105
+ /**
106
+ * Team coordinator — manages a team of agents working in parallel.
107
+ *
108
+ * ```typescript
109
+ * const team = createTeamCoordinator({
110
+ * lead: agent,
111
+ * leadSessionId: "main",
112
+ * roles: [explorerRole, coderRole, reviewerRole],
113
+ * });
114
+ *
115
+ * await team.start();
116
+ * await team.registerAll();
117
+ * await team.queue({ title: "Explore codebase", prompt: "...", memberId: "explorer" });
118
+ * await team.queue({ title: "Implement feature", prompt: "...", dependsOn: [task1.id] });
119
+ * await team.waitForAll();
120
+ * const result = await team.synthesize("Build a REST API");
121
+ * await team.stop();
122
+ * ```
123
+ */
124
+ declare class TeamCoordinator implements CoordinatorCtx {
125
+ readonly teamId: string;
126
+ /** @internal */ readonly lead: Agent;
127
+ /** @internal */ readonly leadSessionId: string;
128
+ /** @internal */ readonly createId: () => string;
129
+ private readonly roles;
130
+ /** @internal */ readonly members: Map<string, MemberRuntime>;
131
+ /** @internal */ readonly taskBoard: TaskBoard;
132
+ /** @internal */ readonly mailbox: Mailbox;
133
+ private readonly onEvent?;
134
+ private readonly eventListeners;
135
+ private readonly signal?;
136
+ /** @internal */ readonly workLoopEnabled: boolean;
137
+ /** @internal */ readonly taskDispatchMode: TaskDispatchMode;
138
+ /** @internal */ readonly pollIntervalMs: number;
139
+ /** @internal */ readonly onPermissionRequest?: PermissionHandler;
140
+ /** @internal */ readonly beforeIteration?: TeamCoordinatorConfig["beforeIteration"];
141
+ /** @internal */ readonly sharedPermissions?: TeamCoordinatorConfig["sharedPermissions"];
142
+ /** @internal */ readonly taskExecutor?: TaskExecutor;
143
+ private readonly externalTaskControl?;
144
+ /** @internal */ started: boolean;
145
+ private readonly onLog?;
146
+ private readonly logger?;
147
+ private activeCoordinatorTurn?;
148
+ private mailboxUnsubscribe?;
149
+ private coordinatorAgent?;
150
+ private coordinatorSessionId?;
151
+ /** @internal */ coordinatorInbox: CoordinatorInboxItem[];
152
+ /** @internal */ coordinatorProcessing: boolean;
153
+ /** @internal */ coordinatorReschedule: boolean;
154
+ private coordinatorStatus;
155
+ private readonly coordinatorEventListeners;
156
+ private readonly coordinatorStatusListeners;
157
+ private coordinatorIdleResolvers;
158
+ /** @internal */ coordinatorRoundNumber: number;
159
+ private coordinatorRunSequence;
160
+ private coordinatorTurnState;
161
+ /** @internal Structured log output — writes to both logger and onLog when provided. */
162
+ log(msg: string): void;
163
+ private dispatchEvent;
164
+ subscribeTeamEvents(listener: (event: TeamEvent) => void | Promise<void>): () => void;
165
+ /** @internal */
166
+ publishCoordinatorEvent(event: AgentEvent): void;
167
+ /** @internal */
168
+ publishCoordinatorStatus(status: Partial<CoordinatorRuntimeStatus>): void;
169
+ /** @internal */
170
+ resolveCoordinatorIdleWaiters(): void;
171
+ constructor(config: TeamCoordinatorConfig);
172
+ start(): Promise<void>;
173
+ stop(): Promise<void>;
174
+ /**
175
+ * Register a team member from a role.
176
+ * Forks the lead agent with the role's specialization.
177
+ */
178
+ register(roleName: string, memberId?: string): Promise<TeamMember>;
179
+ /**
180
+ * Register all roles (or a subset) as team members.
181
+ */
182
+ registerAll(roleNames?: string[]): Promise<TeamMember[]>;
183
+ /**
184
+ * List available role names.
185
+ */
186
+ listRoles(): string[];
187
+ /**
188
+ * Queue a task. If dependencies are met and a member is idle,
189
+ * the task is dispatched immediately.
190
+ */
191
+ queue(input: QueueTaskInput): Promise<TeamTask>;
192
+ /**
193
+ * Dispatch all pending tasks to idle members.
194
+ * Called automatically after queue/complete/fail/cancel.
195
+ */
196
+ dispatchReady(): Promise<TeamTask[]>;
197
+ /**
198
+ * Wait for a specific task to reach a terminal state.
199
+ */
200
+ waitForTask(taskId: string, timeoutMs?: number): Promise<TaskCompletion>;
201
+ /**
202
+ * Wait for all tasks to reach terminal states.
203
+ */
204
+ waitForAll(timeoutMs?: number): Promise<TaskCompletion[]>;
205
+ /**
206
+ * Cancel a task. If it's running, the task's AbortController fires.
207
+ * Cascades to dependent tasks.
208
+ */
209
+ cancel(taskId: string, reason?: string): Promise<TeamTask>;
210
+ /**
211
+ * Abort a running task. The member returns to idle and can pick up
212
+ * new work. Unlike `cancel()`, abort preserves downstream tasks by
213
+ * leaving them blocked on the aborted prerequisite.
214
+ */
215
+ abort(taskId: string, reason?: string): Promise<void>;
216
+ /**
217
+ * Send a guidance message to a running member via intervention.
218
+ * If the member is idle, queues a direct-message task instead.
219
+ */
220
+ guide(memberId: string, message: string): Promise<void>;
221
+ /**
222
+ * Broadcast a message to all members. Active members receive it
223
+ * as an intervention; idle members see it on their next task.
224
+ */
225
+ broadcast(message: string): Promise<TeamMessage>;
226
+ /**
227
+ * Request graceful shutdown of a specific member.
228
+ *
229
+ * - If member is idle, auto-accepts and goes offline immediately
230
+ * - If member is busy, marks as shutting-down and waits for current
231
+ * task to finish before going offline
232
+ * - Returns true if shutdown succeeded within the timeout
233
+ */
234
+ requestShutdown(memberId: string, reason?: string, timeoutMs?: number): Promise<boolean>;
235
+ /**
236
+ * Gracefully shut down all members.
237
+ */
238
+ shutdown(reason?: string, timeoutMs?: number): Promise<void>;
239
+ /**
240
+ * Handle a permission request forwarded from a team member.
241
+ * Called by the `teamPermissionPolicy` middleware when it has
242
+ * a `forwardApproval` callback pointing at the coordinator.
243
+ */
244
+ handlePermissionRequest(memberId: string, tool: string, args: unknown): Promise<{
245
+ decision: "allow" | "deny";
246
+ reason?: string;
247
+ }>;
248
+ /**
249
+ * Create a `forwardApproval` callback for `teamPermissionPolicy`
250
+ * that routes through this coordinator's permission handler.
251
+ */
252
+ createPermissionForwarder(memberId: string): (_memberId: string, tool: string, args: unknown, _ctx?: unknown) => Promise<{
253
+ action: "allow" | "deny";
254
+ reason?: string;
255
+ }>;
256
+ /** @internal */
257
+ beginCoordinatorTurnState(): {
258
+ actions: {
259
+ assigned: Array<{
260
+ taskId: string;
261
+ memberId: string;
262
+ title: string;
263
+ }>;
264
+ sentMessages: Array<{
265
+ memberId: string;
266
+ }>;
267
+ abortedTaskIds: string[];
268
+ };
269
+ };
270
+ /** @internal */
271
+ getActiveCoordinatorTurnState(): {
272
+ actions: {
273
+ assigned: Array<{
274
+ taskId: string;
275
+ memberId: string;
276
+ title: string;
277
+ }>;
278
+ sentMessages: Array<{
279
+ memberId: string;
280
+ }>;
281
+ abortedTaskIds: string[];
282
+ };
283
+ };
284
+ /** @internal */
285
+ endCoordinatorTurnState(): void;
286
+ /** @internal */
287
+ getCoordinatorInboxSize(): number;
288
+ /** @internal */
289
+ getActiveTaskCount(): Promise<number>;
290
+ /** @internal */
291
+ ensureCoordinatorAgent(): Agent;
292
+ /** @internal */
293
+ getCoordinatorSessionId(): string;
294
+ private resetCoordinatorRunSession;
295
+ private enqueueCoordinatorInboxItem;
296
+ private enqueueCoordinatorNotification;
297
+ /** @internal */
298
+ scheduleCoordinatorProcessing(): void;
299
+ /** @internal */ autonomousTurnCount: number;
300
+ waitForCoordinatorIdle(): Promise<void>;
301
+ submitToCoordinator(message: string): string;
302
+ subscribeCoordinatorEvents(listener: (event: AgentEvent) => void): () => void;
303
+ subscribeCoordinatorStatus(listener: (status: CoordinatorRuntimeStatus) => void): () => void;
304
+ getCoordinatorStatus(): CoordinatorRuntimeStatus;
305
+ /** @internal */
306
+ attachCoordinatorTurn(agent: Agent, sessionId: string): void;
307
+ /** @internal */
308
+ setCoordinatorTurnOpen(open: boolean): void;
309
+ /** @internal */
310
+ detachCoordinatorTurn(agent?: Agent): void;
311
+ /**
312
+ * Run the coordinator in an iterative loop.
313
+ *
314
+ * The lead agent is forked with delegation tools and a coordinator
315
+ * system prompt. It reasons about the request, assigns tasks to
316
+ * teammates, receives results, and continues until all work is done.
317
+ *
318
+ * This replaces the plan → fan-out → synthesize pipeline with a
319
+ * dynamic multi-round conversation where the coordinator decides
320
+ * what to delegate, how to react to results, and when it's done.
321
+ *
322
+ * Members must be registered before calling this method.
323
+ *
324
+ * @param prompt - The user's request
325
+ * @param options - Loop configuration (max rounds, timeouts, progress callback)
326
+ */
327
+ run(prompt: string, options?: CoordinatorLoopOptions): Promise<CoordinatorLoopResult>;
328
+ plan(prompt: string, memberIds?: string[]): Promise<TeamPlan>;
329
+ planAndExecute(prompt: string, memberIds?: string[]): Promise<{
330
+ plan: TeamPlan;
331
+ tasks: TeamTask[];
332
+ }>;
333
+ /**
334
+ * Use the lead agent to synthesize all completed task results
335
+ * into a single coherent response.
336
+ *
337
+ * @param originalPrompt - The original task/prompt
338
+ * @param taskIds - Optional subset of task IDs to synthesize (defaults to all terminal tasks)
339
+ */
340
+ synthesize(originalPrompt: string, taskIds?: string[]): Promise<SynthesisResult>;
341
+ snapshot(): Promise<TeamSnapshot>;
342
+ listMembers(): Promise<TeamMember[]>;
343
+ listTasks(filter?: TaskListFilter): Promise<TeamTask[]>;
344
+ listMessages(filter?: Omit<MessageListFilter, "teamId">): Promise<TeamMessage[]>;
345
+ getMemberSessionId(memberId: string): string;
346
+ getMemberRole(memberId: string): string;
347
+ prepareTaskForExternalExecution(taskId: string, runId: string): Promise<PreparedExternalTask | undefined>;
348
+ completeExternalTask(taskId: string, result: TaskResult): Promise<{
349
+ task: TeamTask;
350
+ transitions: TaskTransition[];
351
+ } | undefined>;
352
+ failExternalTask(taskId: string, error: string): Promise<{
353
+ task: TeamTask;
354
+ transitions: TaskTransition[];
355
+ } | undefined>;
356
+ abortExternalTask(taskId: string, reason: string): Promise<{
357
+ task: TeamTask;
358
+ transitions: TaskTransition[];
359
+ } | undefined>;
360
+ getTask(taskId: string): Promise<TeamTask | undefined>;
361
+ /**
362
+ * Get aggregate stats for a member.
363
+ * Returns undefined if the member is not registered.
364
+ */
365
+ getMemberStats(memberId: string): MemberStats | undefined;
366
+ /**
367
+ * Subscribe to a member's agent events (text-delta, tool-start, etc.).
368
+ * Returns an unsubscribe function. Throws if the member is not registered.
369
+ */
370
+ onMemberEvent(memberId: string, handler: (event: AgentEvent) => void): () => void;
371
+ /**
372
+ * Serialize the coordinator state for persistence / resume.
373
+ * Returns snapshot + member stats, enough to reconstruct state.
374
+ */
375
+ toJSON(): Promise<{
376
+ teamId: string;
377
+ snapshot: TeamSnapshot;
378
+ memberStats: Record<string, MemberStats>;
379
+ }>;
380
+ /** @internal */
381
+ updateMemberStatus(memberId: string, status: MemberStatus, activeTaskId: string | undefined): Promise<void>;
382
+ private requireMember;
383
+ /** @internal */
384
+ emit(event: TeamEvent): Promise<void>;
385
+ /** @internal */
386
+ emitTransitions(transitions: TaskTransition[]): Promise<void>;
387
+ private finalizeExternallyTerminatedTask;
388
+ }
389
+ /**
390
+ * Create a team coordinator.
391
+ *
392
+ * ```typescript
393
+ * const team = createTeamCoordinator({
394
+ * lead: agent,
395
+ * leadSessionId: "main",
396
+ * roles: [explorerRole, reviewerRole],
397
+ * onEvent: (event) => console.log(event.type),
398
+ * });
399
+ * ```
400
+ */
401
+ declare function createTeamCoordinator(config: TeamCoordinatorConfig): TeamCoordinator;
402
+
403
+ /**
404
+ * Team Permission Policy
405
+ *
406
+ * Extends the existing approval middleware to support team-wide
407
+ * permission delegation. When a coordinator creates team members,
408
+ * it can install a `teamPermissionPolicy` middleware that:
409
+ *
410
+ * 1. Applies team-wide allow/deny rules to all member tool calls
411
+ * 2. Forwards unresolved approvals to the coordinator (lead agent)
412
+ * 3. Propagates "remember" decisions to all team members
413
+ *
414
+ * This is layered ON TOP of the existing `approvalMiddleware` —
415
+ * it doesn't replace it. Members inherit the lead's approval rules
416
+ * via fork(), and the team policy adds team-specific delegation.
417
+ *
418
+ * Design choices vs ccsource:
419
+ * - No filesystem polling for permission responses — uses callbacks
420
+ * - No separate sandbox permission path — uses standard approval pipeline
421
+ * - Team rules are typed objects, not mailbox message payloads
422
+ * - Integrates with existing `beforeToolCall` middleware contract
423
+ */
424
+
425
+ /**
426
+ * A team-wide permission rule.
427
+ *
428
+ * Rules are evaluated in order — first match wins.
429
+ */
430
+ interface TeamPermissionRule {
431
+ /** Tool name to match (exact or glob-style with `*`) */
432
+ tool: string;
433
+ /** Optional approval pattern to match against the tool input */
434
+ pattern?: string;
435
+ /** Member IDs this rule applies to (undefined = all members) */
436
+ members?: string[];
437
+ /** Whether to allow or deny */
438
+ action: "allow" | "deny";
439
+ /** Optional reason (shown to model on deny) */
440
+ reason?: string;
441
+ }
442
+ /**
443
+ * Callback for forwarding approval requests to the coordinator.
444
+ * Returns the coordinator's decision.
445
+ */
446
+ type ApprovalForwarder = (memberId: string, tool: string, args: unknown, ctx: Parameters<NonNullable<AgentMiddleware["beforeToolCall"]>>[2]) => Promise<ToolCallDecision>;
447
+ /**
448
+ * Configuration for the team permission policy middleware.
449
+ */
450
+ interface TeamPermissionPolicyConfig {
451
+ /** The member ID this middleware is installed on */
452
+ memberId: string;
453
+ /** Team-wide rules (evaluated first, before forwarding) */
454
+ rules?: TeamPermissionRule[];
455
+ /**
456
+ * Forward unresolved approvals to this callback.
457
+ * If not provided, unresolved tools are allowed (fall through
458
+ * to the member's own approval middleware).
459
+ */
460
+ forwardApproval?: ApprovalForwarder;
461
+ /**
462
+ * Callback when a "remember" decision is made — the coordinator
463
+ * can propagate it to all members by updating their rule sets.
464
+ */
465
+ onRemember?: (rule: TeamPermissionRule) => void | Promise<void>;
466
+ }
467
+ /**
468
+ * Create a team permission policy middleware.
469
+ *
470
+ * Install this on forked member agents to enforce team-wide
471
+ * permission rules and optionally forward approvals to the
472
+ * coordinator.
473
+ *
474
+ * ```typescript
475
+ * const memberAgent = lead.fork({
476
+ * name: "explorer",
477
+ * additionalMiddleware: [
478
+ * teamPermissionPolicy({
479
+ * memberId: "explorer",
480
+ * rules: [
481
+ * { tool: "read_*", action: "allow" },
482
+ * { tool: "write_*", action: "deny", reason: "Explorer is read-only" },
483
+ * ],
484
+ * }),
485
+ * ],
486
+ * });
487
+ * ```
488
+ */
489
+ declare function teamPermissionPolicy(config: TeamPermissionPolicyConfig): AgentMiddleware;
490
+
491
+ interface CoordinatorRosterMember {
492
+ id: string;
493
+ role: string;
494
+ description?: string;
495
+ }
496
+ interface CoordinatorTaskNotificationLike {
497
+ taskId: string;
498
+ memberId: string;
499
+ title: string;
500
+ status: string;
501
+ result?: TaskResult;
502
+ error?: string;
503
+ }
504
+ interface CoordinatorWorkerReportLike {
505
+ messageId?: string;
506
+ memberId: string;
507
+ taskId?: string;
508
+ createdAt?: string;
509
+ message: string;
510
+ }
511
+ declare const coordinatorToolDescriptions: {
512
+ readonly assignTask: (memberList: string) => string;
513
+ readonly sendMessage: string;
514
+ readonly abortTask: string;
515
+ };
516
+ declare function buildCoordinatorSystemPrompt(members: CoordinatorRosterMember[]): string;
517
+ declare function formatCoordinatorTaskNotifications(notifications: CoordinatorTaskNotificationLike[]): string;
518
+ declare function formatCoordinatorWorkerReports(reports: CoordinatorWorkerReportLike[]): string;
519
+ declare function formatCoordinatorRoundMessage(notifications: CoordinatorTaskNotificationLike[], reports: CoordinatorWorkerReportLike[]): string;
520
+
521
+ interface CoordinatorRoundTransitionInput {
522
+ reasonAssignmentsCount: number;
523
+ activeTaskCount: number;
524
+ terminalAfterEvent: boolean;
525
+ notifications: CoordinatorTaskNotificationLike[];
526
+ reports: CoordinatorWorkerReportLike[];
527
+ reasonResponse: string;
528
+ roundResponse: string;
529
+ blockedMessage: string;
530
+ }
531
+ type CoordinatorRoundTransition = {
532
+ kind: "done";
533
+ finalResponse: string;
534
+ } | {
535
+ kind: "wait";
536
+ nextMessage: string;
537
+ } | {
538
+ kind: "continue";
539
+ nextMessage: string;
540
+ };
541
+ declare function addTokenUsage(total: TokenUsage, usage?: TokenUsage): TokenUsage;
542
+ declare function evaluateCoordinatorRoundTransition(input: CoordinatorRoundTransitionInput): CoordinatorRoundTransition;
543
+
544
+ export { type ApprovalForwarder, type CoordinatorInboxItem, type CoordinatorLoopOptions, type CoordinatorLoopResult, CoordinatorNotification, type CoordinatorRosterMember, type CoordinatorRound, type CoordinatorRoundTransition, type CoordinatorRoundTransitionInput, type CoordinatorRuntimeStatus, type CoordinatorStatus, type CoordinatorTaskNotificationLike, type CoordinatorWorkerReportLike, Mailbox, MemberRuntime, MemberStats, MemberStatus, MessageListFilter, PermissionHandler, PreparedExternalTask, QueueTaskInput, SynthesisResult, TaskBoard, TaskCompletion, TaskDispatchMode, TaskExecutor, TaskListFilter, TaskResult, TaskTransition, TeamCoordinator, TeamCoordinatorConfig, TeamEvent, TeamMember, TeamMessage, type TeamPermissionPolicyConfig, type TeamPermissionRule, TeamPlan, TeamSnapshot, TeamTask, type WorkerReport, addTokenUsage, buildCoordinatorSystemPrompt, coordinatorToolDescriptions, createTeamCoordinator, evaluateCoordinatorRoundTransition, formatCoordinatorRoundMessage, formatCoordinatorTaskNotifications, formatCoordinatorWorkerReports, teamPermissionPolicy };
@@ -0,0 +1,41 @@
1
+ import {
2
+ InMemoryMailboxStore,
3
+ InMemoryTaskBoardStore,
4
+ Mailbox,
5
+ TERMINAL_STATUSES,
6
+ TaskBoard,
7
+ TaskConflictError,
8
+ TeamCoordinator,
9
+ addTokenUsage,
10
+ buildCoordinatorNotificationEvent,
11
+ buildCoordinatorSystemPrompt,
12
+ coordinatorToolDescriptions,
13
+ createTeamCoordinator,
14
+ evaluateCoordinatorRoundTransition,
15
+ formatCoordinatorRoundMessage,
16
+ formatCoordinatorTaskNotifications,
17
+ formatCoordinatorWorkerReports,
18
+ teamPermissionPolicy
19
+ } from "../chunk-MXAP4UG6.js";
20
+ import "../chunk-SZ2XBPTW.js";
21
+ import "../chunk-Q742PSH3.js";
22
+ import "../chunk-FII65CN7.js";
23
+ export {
24
+ InMemoryMailboxStore,
25
+ InMemoryTaskBoardStore,
26
+ Mailbox,
27
+ TERMINAL_STATUSES,
28
+ TaskBoard,
29
+ TaskConflictError,
30
+ TeamCoordinator,
31
+ addTokenUsage,
32
+ buildCoordinatorNotificationEvent,
33
+ buildCoordinatorSystemPrompt,
34
+ coordinatorToolDescriptions,
35
+ createTeamCoordinator,
36
+ evaluateCoordinatorRoundTransition,
37
+ formatCoordinatorRoundMessage,
38
+ formatCoordinatorTaskNotifications,
39
+ formatCoordinatorWorkerReports,
40
+ teamPermissionPolicy
41
+ };
@@ -0,0 +1,41 @@
1
+ import { T as ToolHost } from '../../types-C_LCeYNg.js';
2
+ export { D as DirEntry, E as ExecOptions, a as ExecResult, F as FileStat } from '../../types-C_LCeYNg.js';
3
+
4
+ interface ToolHostProviderSummary {
5
+ name: string;
6
+ description?: string;
7
+ }
8
+ interface ToolHostProvider<Options = unknown> extends ToolHostProviderSummary {
9
+ create(options?: Options): ToolHost | Promise<ToolHost>;
10
+ }
11
+ declare class ToolHostRegistry {
12
+ private readonly providers;
13
+ register<Options>(provider: ToolHostProvider<Options>): this;
14
+ unregister(name: string): boolean;
15
+ get(name: string): ToolHostProvider<unknown> | undefined;
16
+ list(): ToolHostProviderSummary[];
17
+ create(name: string, options?: unknown): Promise<ToolHost>;
18
+ }
19
+
20
+ /**
21
+ * LocalHost — executes tools on the local machine.
22
+ *
23
+ * Default ToolHost implementation. Uses Node's `child_process.spawn`
24
+ * for commands and `node:fs/promises` for file operations.
25
+ */
26
+
27
+ /**
28
+ * Create a ToolHost that runs everything on the local machine.
29
+ *
30
+ * @param defaultCwd Working directory for commands when none is specified.
31
+ * Defaults to `process.cwd()`.
32
+ */
33
+ declare function localHost(defaultCwd?: string): ToolHost;
34
+
35
+ /**
36
+ * Tool host module — execution environment abstraction for tools.
37
+ */
38
+
39
+ declare const defaultToolHostRegistry: ToolHostRegistry;
40
+
41
+ export { ToolHost, type ToolHostProvider, type ToolHostProviderSummary, ToolHostRegistry, defaultToolHostRegistry, localHost };
@@ -0,0 +1,10 @@
1
+ import {
2
+ ToolHostRegistry,
3
+ defaultToolHostRegistry,
4
+ localHost
5
+ } from "../../chunk-X4VN4GIJ.js";
6
+ export {
7
+ ToolHostRegistry,
8
+ defaultToolHostRegistry,
9
+ localHost
10
+ };