@compilr-dev/sdk 0.10.35 → 0.10.37
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/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/team/delegation-tools.d.ts +129 -2
- package/dist/team/delegation-tools.js +239 -2
- package/dist/team/index.d.ts +2 -2
- package/dist/team/index.js +1 -1
- package/package.json +5 -1
package/dist/index.d.ts
CHANGED
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
*/
|
|
36
36
|
export { createCompilrAgent } from './agent.js';
|
|
37
37
|
export type { CompilrAgentConfig, CompilrAgent, RunOptions, RunResult, ToolCallRecord, ToolConfig, UsageInfo, ProviderType, PermissionCallback, GuardrailConfig, ContextConfig, CapabilitiesConfig, } from './config.js';
|
|
38
|
-
export { AgentTeam, TeamAgent, SharedContextManager, ArtifactStore, DelegationTracker, ContextResolver, createDelegationStatusTool, createHandoffTool, buildHandoffTaskMessage, validateHandoffIntent, HandoffStash, createConsultTool, buildConsultQuestionMessage, ROLE_NAME_ALIASES, normalizeRoleName, } from './team/index.js';
|
|
38
|
+
export { AgentTeam, TeamAgent, SharedContextManager, ArtifactStore, DelegationTracker, ContextResolver, createDelegationStatusTool, createHandoffTool, createDelegateTool, createDelegateBackgroundTool, buildHandoffTaskMessage, validateHandoffIntent, HandoffStash, createConsultTool, buildConsultQuestionMessage, ROLE_NAME_ALIASES, normalizeRoleName, } from './team/index.js';
|
|
39
39
|
export type { AgentTeamConfig, TeamAgentConfig, ITeamPersistence, IArtifactStorage, ISessionRegistry, CustomAgentDefinition, AgentTemplate, AgentWorkshopData, WorkshopRoleDef, WorkshopToolProfile, WorkshopModelTier, WorkshopSkillDef, PlanSubmitInfo, PlanSubmitResult, PlanModeExitInfo, PlanModeCallbacks, ToolConfig as TeamToolConfig, ToolTier, ToolGroup, ProfileInfo, } from './team/index.js';
|
|
40
|
-
export type { AgentRole, RoleMetadata, ToolProfile, MascotExpression, BackgroundSessionInfo, SerializedTeam, SerializedTeamAgent, TeamMetadata, TeamEvent, TeamEventType, TeamEventHandler, Artifact, ArtifactType as TeamArtifactType, ArtifactSummary as TeamArtifactSummary, CreateArtifactOptions, UpdateArtifactOptions, SerializedArtifact, SharedContext, SharedProjectInfo, SharedTeamInfo, TeamRosterEntry, TeamActivity, TeamActivityType, SharedDecision, TokenBudget, SerializedSharedContext, ParsedMention, ParsedInput, ResolvedMention, ResolveOptions, ResolutionSource, Delegation, DelegationStatus, DelegationResult, CompletionEvent, CreateDelegationOptions, DelegationStats, DelegationTrackerEvents, HandoffResult, HandoffToolConfig, HandoffIntent, HandoffValidationResult, ConsultInput, ConsultResult, ConsultToolConfig, NormalizedRole, SkillToolRequirement, } from './team/index.js';
|
|
40
|
+
export type { AgentRole, RoleMetadata, ToolProfile, MascotExpression, BackgroundSessionInfo, SerializedTeam, SerializedTeamAgent, TeamMetadata, TeamEvent, TeamEventType, TeamEventHandler, Artifact, ArtifactType as TeamArtifactType, ArtifactSummary as TeamArtifactSummary, CreateArtifactOptions, UpdateArtifactOptions, SerializedArtifact, SharedContext, SharedProjectInfo, SharedTeamInfo, TeamRosterEntry, TeamActivity, TeamActivityType, SharedDecision, TokenBudget, SerializedSharedContext, ParsedMention, ParsedInput, ResolvedMention, ResolveOptions, ResolutionSource, Delegation, DelegationStatus, DelegationResult, CompletionEvent, CreateDelegationOptions, DelegationStats, DelegationTrackerEvents, HandoffResult, HandoffToolConfig, HandoffIntent, HandoffValidationResult, DelegateResult, DelegateToolConfig, DelegateBackgroundResult, DelegateBackgroundToolConfig, ConsultInput, ConsultResult, ConsultToolConfig, NormalizedRole, SkillToolRequirement, } from './team/index.js';
|
|
41
41
|
export { ROLE_METADATA, ROLE_EXPERTISE, ROLE_GROUPS, PREDEFINED_ROLE_IDS, TOOL_GROUPS, TOOL_PROFILES, PROFILE_INFO, SKILL_REQUIREMENTS, CUSTOM_MASCOTS, buildAgentWorkshopData, buildSuggestedRolesMap, PLAN_MODE_BLOCKED_TOOLS, PLAN_MODE_DENIAL_MESSAGE, PLAN_MODE_PROMPT, isToolAllowedInPlanMode, getPlanModePrompt, } from './team/index.js';
|
|
42
42
|
export { getToolsForProfile, detectProfileFromTools, isProfileReadOnly, generateToolAwarenessPrompt, generateCoordinatorGuidance, generateSpecialistGuidance, createDefaultToolConfig, validateToolConfig, getAllGroupIds, getGroupInfo, getGroupsByTier, getGroupsForProfile, assignMascot, generateCustomAgentSystemPrompt, getCustomAgentToolFilter, getCustomAgentProfileLabel, validateAgentId, isAgentIdTaken, createCustomAgentDefinition, listTemplates, getTemplate, saveTemplate, updateTemplate, deleteTemplate, createAgentFromTemplate, parseInputForMentions, getReferencedAgents, hasReferences, buildMessageWithContext, buildContextMap, findAgentForRole, findAgentById, getAvailableSpecialists, getSpecialistsSummary, hasSpecialists, suggestOwner, suggestOwners, matchesAgentExpertise, wouldCreateLoop, recordAssignment, getAssignmentHistory, clearAssignmentHistory, clearAllAssignmentHistory, canReassign, resolveAgentIdCollision, setActiveSharedContext, getActiveSharedContext, recordTeamActivity, getDefinedSkillNames, getSkillRequirements, checkSkillCompatibility, getCompatibleSkills, getAllRequiredTools, getSkillsByCategory, } from './team/index.js';
|
|
43
43
|
export { codingPreset, readOnlyPreset, resolvePreset } from './presets/index.js';
|
package/dist/index.js
CHANGED
|
@@ -41,7 +41,7 @@ export { createCompilrAgent } from './agent.js';
|
|
|
41
41
|
// Multi-Agent Team Orchestration
|
|
42
42
|
// =============================================================================
|
|
43
43
|
// Core classes
|
|
44
|
-
export { AgentTeam, TeamAgent, SharedContextManager, ArtifactStore, DelegationTracker, ContextResolver, createDelegationStatusTool, createHandoffTool, buildHandoffTaskMessage, validateHandoffIntent, HandoffStash, createConsultTool, buildConsultQuestionMessage, ROLE_NAME_ALIASES, normalizeRoleName, } from './team/index.js';
|
|
44
|
+
export { AgentTeam, TeamAgent, SharedContextManager, ArtifactStore, DelegationTracker, ContextResolver, createDelegationStatusTool, createHandoffTool, createDelegateTool, createDelegateBackgroundTool, buildHandoffTaskMessage, validateHandoffIntent, HandoffStash, createConsultTool, buildConsultQuestionMessage, ROLE_NAME_ALIASES, normalizeRoleName, } from './team/index.js';
|
|
45
45
|
// Constants
|
|
46
46
|
export { ROLE_METADATA, ROLE_EXPERTISE, ROLE_GROUPS, PREDEFINED_ROLE_IDS, TOOL_GROUPS, TOOL_PROFILES, PROFILE_INFO, SKILL_REQUIREMENTS, CUSTOM_MASCOTS, buildAgentWorkshopData, buildSuggestedRolesMap,
|
|
47
47
|
// Plan mode
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Delegation & Handoff Tools — SDK Factories
|
|
3
3
|
*
|
|
4
|
-
* Factory functions for creating delegation_status
|
|
5
|
-
* Both CLI and Desktop call these with
|
|
4
|
+
* Factory functions for creating delegation_status, handoff, delegate, and
|
|
5
|
+
* delegate_background tools. Both CLI and Desktop call these with
|
|
6
|
+
* platform-specific dependencies.
|
|
7
|
+
*
|
|
8
|
+
* Canonical semantics: see
|
|
9
|
+
* project-docs/00-requirements/compilr-dev-sdk/multi-agent-tools-taxonomy-spec.md
|
|
6
10
|
*/
|
|
7
11
|
import { type Tool } from '@compilr-dev/agents';
|
|
8
12
|
import type { DelegationTracker } from './delegation-tracker.js';
|
|
@@ -54,4 +58,127 @@ export interface HandoffToolConfig {
|
|
|
54
58
|
* it can only hand back to the coordinator (default agent), not to another specialist.
|
|
55
59
|
*/
|
|
56
60
|
export declare function createHandoffTool(config: HandoffToolConfig): Tool<HandoffInput>;
|
|
61
|
+
interface DelegateInput {
|
|
62
|
+
agentId: string;
|
|
63
|
+
task: string;
|
|
64
|
+
reason?: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Result from the platform's delegate handler.
|
|
68
|
+
*
|
|
69
|
+
* The factory normalises this into the tool's result body — the agent
|
|
70
|
+
* sees `response` as the specialist's reply when delegation succeeded.
|
|
71
|
+
*/
|
|
72
|
+
export interface DelegateResult {
|
|
73
|
+
/** True if delegation completed (approval granted + specialist ran). */
|
|
74
|
+
success: boolean;
|
|
75
|
+
/** True if the user declined the delegation via the approval overlay. */
|
|
76
|
+
declined?: boolean;
|
|
77
|
+
/** Specialist's final response text (populated when success=true). */
|
|
78
|
+
response?: string;
|
|
79
|
+
/** Error description (when success=false). */
|
|
80
|
+
error?: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Configuration for creating a delegate tool.
|
|
84
|
+
*/
|
|
85
|
+
export interface DelegateToolConfig {
|
|
86
|
+
/** The team instance for roster validation. */
|
|
87
|
+
team: AgentTeam;
|
|
88
|
+
/** The current agent's ID (must be 'default' — coordinator-only tool). */
|
|
89
|
+
currentAgentId: string;
|
|
90
|
+
/**
|
|
91
|
+
* Platform-specific delegate handler. Called after validation.
|
|
92
|
+
*
|
|
93
|
+
* The host implementation should:
|
|
94
|
+
* 1. (Optional) Show approval UI to the user.
|
|
95
|
+
* 2. Run the specialist's task in their persistent context.
|
|
96
|
+
* 3. Return the specialist's response. The factory surfaces this
|
|
97
|
+
* response in the coordinator's tool result body.
|
|
98
|
+
*
|
|
99
|
+
* If the host wants to truncate long responses, do it inside the
|
|
100
|
+
* callback before returning.
|
|
101
|
+
*
|
|
102
|
+
* For per-context behavior (CLI vs Desktop single-agent vs Desktop
|
|
103
|
+
* group chat) see multi-agent-tools-taxonomy-spec.md §3.
|
|
104
|
+
*/
|
|
105
|
+
onDelegate: (targetAgentId: string, task: string, reason?: string) => Promise<DelegateResult>;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Create a delegate tool for the coordinator agent.
|
|
109
|
+
*
|
|
110
|
+
* Semantics (per taxonomy spec §2):
|
|
111
|
+
* - Foreground + sync — caller waits for response
|
|
112
|
+
* - Caller continues working after the response returns
|
|
113
|
+
* - Target remembers the work (persistent context)
|
|
114
|
+
* - Direction: coordinator → specialist (enforced — `currentAgentId`
|
|
115
|
+
* must be 'default'; the factory rejects with an error otherwise)
|
|
116
|
+
*
|
|
117
|
+
* Differentiation:
|
|
118
|
+
* - vs `consult` — consult is transient (target doesn't remember).
|
|
119
|
+
* - vs `delegate_background` — that's async; delegate blocks for the
|
|
120
|
+
* response.
|
|
121
|
+
* - vs `handoff` — handoff means the caller is done; delegate gets a
|
|
122
|
+
* response and the caller continues.
|
|
123
|
+
*/
|
|
124
|
+
export declare function createDelegateTool(config: DelegateToolConfig): Tool<DelegateInput>;
|
|
125
|
+
interface DelegateBackgroundInput {
|
|
126
|
+
agentId: string;
|
|
127
|
+
task: string;
|
|
128
|
+
todoIndex?: number;
|
|
129
|
+
expectedOutput?: string;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Result from the platform's delegate_background handler.
|
|
133
|
+
*/
|
|
134
|
+
export interface DelegateBackgroundResult {
|
|
135
|
+
/** Unique delegation ID for tracking via delegation_status. */
|
|
136
|
+
delegationId: string;
|
|
137
|
+
/** Current status — running (started) or queued (target busy). */
|
|
138
|
+
status: 'running' | 'queued';
|
|
139
|
+
/** Error description (when failed). */
|
|
140
|
+
error?: string;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Configuration for creating a delegate_background tool.
|
|
144
|
+
*/
|
|
145
|
+
export interface DelegateBackgroundToolConfig {
|
|
146
|
+
/** The team instance for roster validation. */
|
|
147
|
+
team: AgentTeam;
|
|
148
|
+
/** The current agent's ID (must be 'default' — coordinator-only tool). */
|
|
149
|
+
currentAgentId: string;
|
|
150
|
+
/**
|
|
151
|
+
* Platform-specific background delegation handler. Called after validation.
|
|
152
|
+
*
|
|
153
|
+
* The host implementation should:
|
|
154
|
+
* 1. Create a delegation record (in tracker / IPC / wherever the host
|
|
155
|
+
* surfaces async status to the user).
|
|
156
|
+
* 2. Start the specialist running in background (or queue if busy).
|
|
157
|
+
* 3. Return the delegation ID + initial status so the coordinator can
|
|
158
|
+
* poll via delegation_status.
|
|
159
|
+
*
|
|
160
|
+
* For per-context behavior (CLI vs Desktop single-agent vs Desktop
|
|
161
|
+
* group chat) see multi-agent-tools-taxonomy-spec.md §3.
|
|
162
|
+
*/
|
|
163
|
+
onDelegateBackground: (args: {
|
|
164
|
+
targetAgentId: string;
|
|
165
|
+
task: string;
|
|
166
|
+
todoIndex?: number;
|
|
167
|
+
expectedOutput?: string;
|
|
168
|
+
}) => Promise<DelegateBackgroundResult>;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Create a delegate_background tool for the coordinator agent.
|
|
172
|
+
*
|
|
173
|
+
* Semantics (per taxonomy spec §2):
|
|
174
|
+
* - Background + async — caller continues immediately
|
|
175
|
+
* - Caller polls completion via `delegation_status`
|
|
176
|
+
* - Target remembers the work (persistent context)
|
|
177
|
+
* - Direction: coordinator → specialist
|
|
178
|
+
*
|
|
179
|
+
* Use this when the coordinator wants to dispatch work in parallel and
|
|
180
|
+
* keep operating. Use `delegate` if the coordinator needs the response
|
|
181
|
+
* before continuing.
|
|
182
|
+
*/
|
|
183
|
+
export declare function createDelegateBackgroundTool(config: DelegateBackgroundToolConfig): Tool<DelegateBackgroundInput>;
|
|
57
184
|
export {};
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Delegation & Handoff Tools — SDK Factories
|
|
3
3
|
*
|
|
4
|
-
* Factory functions for creating delegation_status
|
|
5
|
-
* Both CLI and Desktop call these with
|
|
4
|
+
* Factory functions for creating delegation_status, handoff, delegate, and
|
|
5
|
+
* delegate_background tools. Both CLI and Desktop call these with
|
|
6
|
+
* platform-specific dependencies.
|
|
7
|
+
*
|
|
8
|
+
* Canonical semantics: see
|
|
9
|
+
* project-docs/00-requirements/compilr-dev-sdk/multi-agent-tools-taxonomy-spec.md
|
|
6
10
|
*/
|
|
7
11
|
import { defineTool } from '@compilr-dev/agents';
|
|
8
12
|
function formatDuration(from, to) {
|
|
@@ -222,3 +226,236 @@ export function createHandoffTool(config) {
|
|
|
222
226
|
},
|
|
223
227
|
});
|
|
224
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* Create a delegate tool for the coordinator agent.
|
|
231
|
+
*
|
|
232
|
+
* Semantics (per taxonomy spec §2):
|
|
233
|
+
* - Foreground + sync — caller waits for response
|
|
234
|
+
* - Caller continues working after the response returns
|
|
235
|
+
* - Target remembers the work (persistent context)
|
|
236
|
+
* - Direction: coordinator → specialist (enforced — `currentAgentId`
|
|
237
|
+
* must be 'default'; the factory rejects with an error otherwise)
|
|
238
|
+
*
|
|
239
|
+
* Differentiation:
|
|
240
|
+
* - vs `consult` — consult is transient (target doesn't remember).
|
|
241
|
+
* - vs `delegate_background` — that's async; delegate blocks for the
|
|
242
|
+
* response.
|
|
243
|
+
* - vs `handoff` — handoff means the caller is done; delegate gets a
|
|
244
|
+
* response and the caller continues.
|
|
245
|
+
*/
|
|
246
|
+
export function createDelegateTool(config) {
|
|
247
|
+
const { team, currentAgentId, onDelegate } = config;
|
|
248
|
+
return defineTool({
|
|
249
|
+
name: 'delegate',
|
|
250
|
+
description: 'Delegate a task to a specialist and get their response back. ' +
|
|
251
|
+
'The specialist runs the task in their persistent context (they remember the work). ' +
|
|
252
|
+
"You stay in charge — control returns to you with the specialist's response. " +
|
|
253
|
+
'Use consult if you just want a quick answer without persistence. ' +
|
|
254
|
+
'Use delegate_background if you want the specialist to work in parallel while you continue. ' +
|
|
255
|
+
'Use handoff to permanently pass the baton (you stop working). ' +
|
|
256
|
+
'Only available to the coordinator.',
|
|
257
|
+
inputSchema: {
|
|
258
|
+
type: 'object',
|
|
259
|
+
properties: {
|
|
260
|
+
agentId: {
|
|
261
|
+
type: 'string',
|
|
262
|
+
description: 'Target specialist agent ID (e.g., "arch", "dev", "qa")',
|
|
263
|
+
},
|
|
264
|
+
task: {
|
|
265
|
+
type: 'string',
|
|
266
|
+
description: 'Task description for the specialist — be specific and clear',
|
|
267
|
+
},
|
|
268
|
+
reason: {
|
|
269
|
+
type: 'string',
|
|
270
|
+
description: 'Why this specialist is suited for the task (shown to user)',
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
required: ['agentId', 'task'],
|
|
274
|
+
},
|
|
275
|
+
execute: async (input) => {
|
|
276
|
+
// Validate input
|
|
277
|
+
if (!input.agentId || input.agentId.trim().length === 0) {
|
|
278
|
+
return { success: false, error: 'Agent ID is required' };
|
|
279
|
+
}
|
|
280
|
+
if (!input.task || input.task.trim().length === 0) {
|
|
281
|
+
return { success: false, error: 'Task description is required' };
|
|
282
|
+
}
|
|
283
|
+
const targetId = input.agentId.trim();
|
|
284
|
+
// Enforce coordinator-only — the factory shouldn't be wired up to
|
|
285
|
+
// non-coordinator agents in the first place, but defensive check.
|
|
286
|
+
if (currentAgentId !== 'default') {
|
|
287
|
+
return {
|
|
288
|
+
success: false,
|
|
289
|
+
error: 'Only the coordinator can delegate tasks. ' +
|
|
290
|
+
'Specialists pass work via handoff (peer-to-peer) or consult (sync question).',
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
// Prevent self-delegation
|
|
294
|
+
if (targetId === 'default') {
|
|
295
|
+
return {
|
|
296
|
+
success: false,
|
|
297
|
+
error: 'Cannot delegate to yourself (the coordinator). Delegate to a specialist agent.',
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
// Validate target agent exists in team
|
|
301
|
+
const allAgents = team.getAll();
|
|
302
|
+
const targetExists = allAgents.some((a) => a.id === targetId);
|
|
303
|
+
if (!targetExists) {
|
|
304
|
+
const available = allAgents
|
|
305
|
+
.filter((a) => a.id !== 'default')
|
|
306
|
+
.map((a) => a.id)
|
|
307
|
+
.join(', ');
|
|
308
|
+
return {
|
|
309
|
+
success: false,
|
|
310
|
+
error: `Agent "${targetId}" not found in team. Available specialists: ${available || '(none)'}`,
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
// Execute delegation via platform callback
|
|
314
|
+
try {
|
|
315
|
+
const result = await onDelegate(targetId, input.task.trim(), input.reason?.trim());
|
|
316
|
+
if (result.error) {
|
|
317
|
+
return { success: false, error: result.error };
|
|
318
|
+
}
|
|
319
|
+
if (result.declined) {
|
|
320
|
+
return {
|
|
321
|
+
success: true,
|
|
322
|
+
result: {
|
|
323
|
+
delegated: false,
|
|
324
|
+
agent: targetId,
|
|
325
|
+
message: 'User declined the delegation. Continue handling the task yourself.',
|
|
326
|
+
},
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
return {
|
|
330
|
+
success: true,
|
|
331
|
+
result: {
|
|
332
|
+
delegated: true,
|
|
333
|
+
agent: targetId,
|
|
334
|
+
response: result.response,
|
|
335
|
+
},
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
catch (err) {
|
|
339
|
+
return {
|
|
340
|
+
success: false,
|
|
341
|
+
error: `Delegate failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Create a delegate_background tool for the coordinator agent.
|
|
349
|
+
*
|
|
350
|
+
* Semantics (per taxonomy spec §2):
|
|
351
|
+
* - Background + async — caller continues immediately
|
|
352
|
+
* - Caller polls completion via `delegation_status`
|
|
353
|
+
* - Target remembers the work (persistent context)
|
|
354
|
+
* - Direction: coordinator → specialist
|
|
355
|
+
*
|
|
356
|
+
* Use this when the coordinator wants to dispatch work in parallel and
|
|
357
|
+
* keep operating. Use `delegate` if the coordinator needs the response
|
|
358
|
+
* before continuing.
|
|
359
|
+
*/
|
|
360
|
+
export function createDelegateBackgroundTool(config) {
|
|
361
|
+
const { team, currentAgentId, onDelegateBackground } = config;
|
|
362
|
+
return defineTool({
|
|
363
|
+
name: 'delegate_background',
|
|
364
|
+
description: 'Delegate a task to a specialist running in background. ' +
|
|
365
|
+
'The specialist executes independently while you continue working. ' +
|
|
366
|
+
'You will be notified when the specialist completes. ' +
|
|
367
|
+
'Use delegation_status to check progress. ' +
|
|
368
|
+
'Prefer this over delegate when you have parallel work to do — it keeps you in control. ' +
|
|
369
|
+
'Only available to the coordinator.',
|
|
370
|
+
inputSchema: {
|
|
371
|
+
type: 'object',
|
|
372
|
+
properties: {
|
|
373
|
+
agentId: {
|
|
374
|
+
type: 'string',
|
|
375
|
+
description: 'Target specialist agent ID (e.g., "arch", "dev", "qa")',
|
|
376
|
+
},
|
|
377
|
+
task: {
|
|
378
|
+
type: 'string',
|
|
379
|
+
description: 'Detailed task description for the specialist',
|
|
380
|
+
},
|
|
381
|
+
todoIndex: {
|
|
382
|
+
type: 'number',
|
|
383
|
+
description: 'Optional todo index to associate with this delegation',
|
|
384
|
+
},
|
|
385
|
+
expectedOutput: {
|
|
386
|
+
type: 'string',
|
|
387
|
+
description: 'What the specialist should produce (e.g., "architecture document", "implementation")',
|
|
388
|
+
},
|
|
389
|
+
},
|
|
390
|
+
required: ['agentId', 'task'],
|
|
391
|
+
},
|
|
392
|
+
execute: async (input) => {
|
|
393
|
+
// Validate input
|
|
394
|
+
if (!input.agentId || input.agentId.trim().length === 0) {
|
|
395
|
+
return { success: false, error: 'Agent ID is required' };
|
|
396
|
+
}
|
|
397
|
+
if (!input.task || input.task.trim().length === 0) {
|
|
398
|
+
return { success: false, error: 'Task description is required' };
|
|
399
|
+
}
|
|
400
|
+
const targetId = input.agentId.trim();
|
|
401
|
+
// Enforce coordinator-only
|
|
402
|
+
if (currentAgentId !== 'default') {
|
|
403
|
+
return {
|
|
404
|
+
success: false,
|
|
405
|
+
error: 'Only the coordinator can use delegate_background. ' +
|
|
406
|
+
'Specialists pass work via handoff (peer-to-peer) or consult (sync question).',
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
// Prevent self-delegation
|
|
410
|
+
if (targetId === 'default') {
|
|
411
|
+
return {
|
|
412
|
+
success: false,
|
|
413
|
+
error: 'Cannot delegate to yourself (the coordinator). Delegate to a specialist agent.',
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
// Validate target agent exists in team
|
|
417
|
+
const allAgents = team.getAll();
|
|
418
|
+
const targetExists = allAgents.some((a) => a.id === targetId);
|
|
419
|
+
if (!targetExists) {
|
|
420
|
+
const available = allAgents
|
|
421
|
+
.filter((a) => a.id !== 'default')
|
|
422
|
+
.map((a) => a.id)
|
|
423
|
+
.join(', ');
|
|
424
|
+
return {
|
|
425
|
+
success: false,
|
|
426
|
+
error: `Agent "${targetId}" not found in team. Available specialists: ${available || '(none)'}`,
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
// Execute background delegation via platform callback
|
|
430
|
+
try {
|
|
431
|
+
const result = await onDelegateBackground({
|
|
432
|
+
targetAgentId: targetId,
|
|
433
|
+
task: input.task.trim(),
|
|
434
|
+
todoIndex: input.todoIndex,
|
|
435
|
+
expectedOutput: input.expectedOutput?.trim(),
|
|
436
|
+
});
|
|
437
|
+
if (result.error) {
|
|
438
|
+
return { success: false, error: result.error };
|
|
439
|
+
}
|
|
440
|
+
return {
|
|
441
|
+
success: true,
|
|
442
|
+
result: {
|
|
443
|
+
delegated: true,
|
|
444
|
+
agent: targetId,
|
|
445
|
+
delegationId: result.delegationId,
|
|
446
|
+
status: result.status,
|
|
447
|
+
message: result.status === 'queued'
|
|
448
|
+
? `Task queued for $${targetId} (currently busy). It will start when they're free.`
|
|
449
|
+
: `Task delegated to $${targetId} running in background. You'll be notified on completion. Use delegation_status to check progress.`,
|
|
450
|
+
},
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
catch (err) {
|
|
454
|
+
return {
|
|
455
|
+
success: false,
|
|
456
|
+
error: `Background delegation failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
},
|
|
460
|
+
});
|
|
461
|
+
}
|
package/dist/team/index.d.ts
CHANGED
|
@@ -38,8 +38,8 @@ export { setActiveSharedContext, getActiveSharedContext, recordTeamActivity } fr
|
|
|
38
38
|
export type { SkillToolRequirement } from './skill-requirements.js';
|
|
39
39
|
export { SKILL_REQUIREMENTS, getDefinedSkillNames, getSkillRequirements, checkSkillCompatibility, getCompatibleSkills, getAllRequiredTools, getSkillsByCategory, } from './skill-requirements.js';
|
|
40
40
|
export { resolveAgentIdCollision } from './collision-utils.js';
|
|
41
|
-
export { createDelegationStatusTool, createHandoffTool } from './delegation-tools.js';
|
|
42
|
-
export type { HandoffResult, HandoffToolConfig } from './delegation-tools.js';
|
|
41
|
+
export { createDelegationStatusTool, createHandoffTool, createDelegateTool, createDelegateBackgroundTool, } from './delegation-tools.js';
|
|
42
|
+
export type { HandoffResult, HandoffToolConfig, DelegateResult, DelegateToolConfig, DelegateBackgroundResult, DelegateBackgroundToolConfig, } from './delegation-tools.js';
|
|
43
43
|
export { buildHandoffTaskMessage, validateHandoffIntent, HandoffStash, } from './handoff-orchestration.js';
|
|
44
44
|
export type { HandoffIntent, HandoffValidationResult } from './handoff-orchestration.js';
|
|
45
45
|
export { createConsultTool, buildConsultQuestionMessage } from './consult-tool.js';
|
package/dist/team/index.js
CHANGED
|
@@ -32,7 +32,7 @@ export { SKILL_REQUIREMENTS, getDefinedSkillNames, getSkillRequirements, checkSk
|
|
|
32
32
|
// Collision utils
|
|
33
33
|
export { resolveAgentIdCollision } from './collision-utils.js';
|
|
34
34
|
// Delegation & Handoff tools (factory functions)
|
|
35
|
-
export { createDelegationStatusTool, createHandoffTool } from './delegation-tools.js';
|
|
35
|
+
export { createDelegationStatusTool, createHandoffTool, createDelegateTool, createDelegateBackgroundTool, } from './delegation-tools.js';
|
|
36
36
|
// Handoff orchestration helpers — shared between CLI and Desktop for the
|
|
37
37
|
// post-turn stash/dispatch pattern. See handoff-orchestration.ts header.
|
|
38
38
|
export { buildHandoffTaskMessage, validateHandoffIntent, HandoffStash, } from './handoff-orchestration.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@compilr-dev/sdk",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.37",
|
|
4
4
|
"description": "Universal agent runtime for building AI-powered applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
"./team/role-aliases": {
|
|
14
14
|
"types": "./dist/team/role-aliases.d.ts",
|
|
15
15
|
"import": "./dist/team/role-aliases.js"
|
|
16
|
+
},
|
|
17
|
+
"./flow-runner": {
|
|
18
|
+
"types": "./dist/flow-runner/index.d.ts",
|
|
19
|
+
"import": "./dist/flow-runner/index.js"
|
|
16
20
|
}
|
|
17
21
|
},
|
|
18
22
|
"files": [
|