@compilr-dev/sdk 0.10.6 → 0.10.8

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.
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * Auto-Detect Capabilities — scans agent messages for "Tool not found"
3
3
  * errors and auto-loads the corresponding capability packs.
4
+ * Also detects programming languages from file paths to pre-load
5
+ * language-specific analysis packs.
4
6
  */
5
7
  import type { Message } from '@compilr-dev/agents';
6
8
  import type { CapabilityManager } from './manager.js';
@@ -1,7 +1,23 @@
1
1
  /**
2
2
  * Auto-Detect Capabilities — scans agent messages for "Tool not found"
3
3
  * errors and auto-loads the corresponding capability packs.
4
+ * Also detects programming languages from file paths to pre-load
5
+ * language-specific analysis packs.
4
6
  */
7
+ /**
8
+ * Map file extensions to language capability pack IDs.
9
+ */
10
+ const EXT_TO_LANG_PACK = {
11
+ '.ts': 'lang_typescript',
12
+ '.tsx': 'lang_typescript',
13
+ '.js': 'lang_typescript',
14
+ '.jsx': 'lang_typescript',
15
+ '.mjs': 'lang_typescript',
16
+ '.cjs': 'lang_typescript',
17
+ '.py': 'lang_python',
18
+ '.pyw': 'lang_python',
19
+ '.go': 'lang_go',
20
+ };
5
21
  /**
6
22
  * Scan recent messages for "Tool not found: X" errors and auto-load
7
23
  * the corresponding capability packs (max N per turn, loadable only).
@@ -45,5 +61,59 @@ export function autoDetectCapabilities(manager, messages, maxLoads = 2) {
45
61
  // Only scan the most recent user message
46
62
  break;
47
63
  }
64
+ // Also detect languages from file paths in recent tool calls
65
+ autoDetectLanguagePacks(manager, messages, result, maxLoads - result.loaded.length);
48
66
  return result;
49
67
  }
68
+ /**
69
+ * Scan recent assistant messages for file-related tool calls (read_file, edit, write_file, glob)
70
+ * and auto-load language packs based on file extensions.
71
+ */
72
+ function autoDetectLanguagePacks(manager, messages, result, maxLoads) {
73
+ if (maxLoads <= 0)
74
+ return;
75
+ const detectedPacks = new Set();
76
+ // Scan the last few assistant messages for tool_use blocks with file paths
77
+ const recentMessages = messages.slice(-6);
78
+ for (const msg of recentMessages) {
79
+ if (msg.role !== 'assistant' || typeof msg.content === 'string')
80
+ continue;
81
+ for (const block of msg.content) {
82
+ if (block.type !== 'tool_use')
83
+ continue;
84
+ // Extract file paths from common tool inputs
85
+ const input = block.input;
86
+ if (!input)
87
+ continue;
88
+ const paths = [];
89
+ if (typeof input.path === 'string')
90
+ paths.push(input.path);
91
+ if (typeof input.file_path === 'string')
92
+ paths.push(input.file_path);
93
+ if (typeof input.filePath === 'string')
94
+ paths.push(input.filePath);
95
+ if (typeof input.pattern === 'string')
96
+ paths.push(input.pattern);
97
+ for (const p of paths) {
98
+ const lastDot = p.lastIndexOf('.');
99
+ const ext = lastDot >= 0 ? p.slice(lastDot).toLowerCase() : '';
100
+ const packId = EXT_TO_LANG_PACK[ext];
101
+ if (packId && !manager.isLoaded(packId)) {
102
+ detectedPacks.add(packId);
103
+ }
104
+ }
105
+ }
106
+ }
107
+ // Load detected language packs
108
+ let loaded = 0;
109
+ for (const packId of detectedPacks) {
110
+ if (loaded >= maxLoads)
111
+ break;
112
+ const tier = manager.getTier(packId);
113
+ if (tier === 'loadable') {
114
+ manager.load(packId, 'auto-detect');
115
+ result.loaded.push(packId);
116
+ loaded++;
117
+ }
118
+ }
119
+ }
@@ -327,6 +327,94 @@ export const CAPABILITY_PACKS = {
327
327
  estimatedPromptTokens: 60,
328
328
  estimatedToolTokens: 300,
329
329
  },
330
+ // ============= LANGUAGE-SPECIFIC ANALYSIS PACKS =============
331
+ lang_typescript: {
332
+ id: 'lang_typescript',
333
+ label: 'TypeScript/JavaScript Analysis',
334
+ tools: [
335
+ 'ts_find_symbol',
336
+ 'ts_find_references',
337
+ 'ts_find_implementations',
338
+ 'ts_find_dead_code',
339
+ 'ts_find_duplicates',
340
+ 'ts_find_patterns',
341
+ 'ts_get_file_structure',
342
+ 'ts_get_imports',
343
+ 'ts_get_exports',
344
+ 'ts_get_call_graph',
345
+ 'ts_get_dependency_graph',
346
+ 'ts_get_type_hierarchy',
347
+ 'ts_get_complexity',
348
+ 'ts_get_signature',
349
+ 'ts_get_documentation',
350
+ 'ts_read_function',
351
+ 'ts_read_class',
352
+ 'ts_read_type',
353
+ ],
354
+ readOnly: true,
355
+ promptModules: [],
356
+ promptSnippet: 'TypeScript/JS AST analysis loaded: ts_find_symbol, ts_get_call_graph, ts_get_type_hierarchy, ts_find_dead_code, ts_get_imports/exports, ts_find_patterns, ts_read_function/class/type. Use these for precise structural analysis (prefer over grep for code structure questions).',
357
+ estimatedPromptTokens: 120,
358
+ estimatedToolTokens: 4200,
359
+ },
360
+ lang_python: {
361
+ id: 'lang_python',
362
+ label: 'Python Analysis',
363
+ tools: [
364
+ 'find_symbol_python',
365
+ 'find_references_python',
366
+ 'find_implementations_python',
367
+ 'find_dead_code_python',
368
+ 'find_duplicates_python',
369
+ 'find_patterns_python',
370
+ 'get_file_structure_python',
371
+ 'get_imports_python',
372
+ 'get_exports_python',
373
+ 'get_call_graph_python',
374
+ 'get_dependency_graph_python',
375
+ 'get_class_hierarchy_python',
376
+ 'get_complexity_python',
377
+ 'get_signature_python',
378
+ 'extract_docstrings_python',
379
+ 'read_function_py',
380
+ 'read_class_py',
381
+ 'read_type_py',
382
+ ],
383
+ readOnly: true,
384
+ promptModules: [],
385
+ promptSnippet: 'Python AST analysis loaded: find_symbol_python, get_call_graph_python, get_class_hierarchy_python, find_dead_code_python, get_imports_python, extract_docstrings_python, read_function_py/class_py. Use these for precise structural analysis.',
386
+ estimatedPromptTokens: 120,
387
+ estimatedToolTokens: 4200,
388
+ },
389
+ lang_go: {
390
+ id: 'lang_go',
391
+ label: 'Go Analysis',
392
+ tools: [
393
+ 'find_symbol_go',
394
+ 'find_references_go',
395
+ 'find_implementations_go',
396
+ 'find_dead_code_go',
397
+ 'find_duplicates_go',
398
+ 'find_patterns_go',
399
+ 'get_file_structure_go',
400
+ 'get_imports_go',
401
+ 'get_exports_go',
402
+ 'get_call_graph_go',
403
+ 'get_dependency_graph_go',
404
+ 'get_class_hierarchy_go',
405
+ 'get_complexity_go',
406
+ 'get_signature_go',
407
+ 'extract_docstrings_go',
408
+ 'read_function_go',
409
+ 'read_struct_go',
410
+ 'read_type_go',
411
+ ],
412
+ readOnly: true,
413
+ promptModules: [],
414
+ promptSnippet: 'Go AST analysis loaded: find_symbol_go, get_call_graph_go, find_dead_code_go, get_imports_go, read_function_go/struct_go. Use these for precise structural analysis.',
415
+ estimatedPromptTokens: 120,
416
+ estimatedToolTokens: 4200,
417
+ },
330
418
  };
331
419
  /**
332
420
  * Mapping from forbidden pack IDs to suggested agent roles.
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, } from './team/index.js';
38
+ export { AgentTeam, TeamAgent, SharedContextManager, ArtifactStore, DelegationTracker, ContextResolver, createDelegationStatusTool, createHandoffTool, } 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, 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, 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, } from './team/index.js';
44
+ export { AgentTeam, TeamAgent, SharedContextManager, ArtifactStore, DelegationTracker, ContextResolver, createDelegationStatusTool, createHandoffTool, } 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
@@ -2,7 +2,7 @@
2
2
  * Coding preset — batteries-included for software development
3
3
  */
4
4
  import { readFileTool, writeFileTool, editTool, bashTool, bashOutputTool, killShellTool, grepTool, globTool, todoWriteTool, todoReadTool, webFetchTool, suggestTool, } from '@compilr-dev/agents';
5
- import { allCodingTools, unifiedTools } from '@compilr-dev/agents-coding';
5
+ import { allCodingTools, unifiedTools, ts, python, go } from '@compilr-dev/agents-coding';
6
6
  const CODING_SYSTEM_PROMPT = `You are a skilled software engineer. You help users with coding tasks including:
7
7
  - Writing, reviewing, and debugging code
8
8
  - Understanding codebases and architecture
@@ -42,12 +42,23 @@ const utilityTools = [todoWriteTool, todoReadTool, suggestTool];
42
42
  /**
43
43
  * All coding preset tools combined
44
44
  */
45
+ /**
46
+ * Language-specific AST analysis tools (loaded on-demand via capability packs).
47
+ * Registered in the MetaToolsRegistry but hidden until the matching
48
+ * lang_typescript / lang_python / lang_go pack is loaded.
49
+ */
50
+ const langTools = [
51
+ ...ts.allTsTools,
52
+ ...python.allPythonTools,
53
+ ...go.allGoTools,
54
+ ];
45
55
  const allPresetTools = [
46
56
  ...fileTools,
47
57
  ...shellTools,
48
58
  ...utilityTools,
49
59
  ...allCodingTools,
50
60
  ...unifiedTools,
61
+ ...langTools,
51
62
  ];
52
63
  /**
53
64
  * Coding preset — full development environment
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Delegation & Handoff Tools — SDK Factories
3
+ *
4
+ * Factory functions for creating delegation_status and handoff tools.
5
+ * Both CLI and Desktop call these with platform-specific dependencies.
6
+ */
7
+ import { type Tool } from '@compilr-dev/agents';
8
+ import type { DelegationTracker } from './delegation-tracker.js';
9
+ import type { AgentTeam } from './team.js';
10
+ interface DelegationStatusInput {
11
+ delegation_id?: string;
12
+ agent_id?: string;
13
+ status?: 'active' | 'completed' | 'failed' | 'all';
14
+ }
15
+ /**
16
+ * Create a delegation_status tool that queries the given tracker.
17
+ * Read-only — safe for parallel execution.
18
+ */
19
+ export declare function createDelegationStatusTool(tracker: DelegationTracker): Tool<DelegationStatusInput>;
20
+ interface HandoffInput {
21
+ agentId: string;
22
+ task: string;
23
+ reason?: string;
24
+ }
25
+ /**
26
+ * Result from the platform's handoff handler.
27
+ */
28
+ export interface HandoffResult {
29
+ /** Whether the handoff was executed */
30
+ success: boolean;
31
+ /** Whether the user declined the handoff */
32
+ declined?: boolean;
33
+ /** Error message (if any) */
34
+ error?: string;
35
+ }
36
+ /**
37
+ * Configuration for creating a handoff tool.
38
+ */
39
+ export interface HandoffToolConfig {
40
+ /** The team instance for roster validation and one-hop tracking */
41
+ team: AgentTeam;
42
+ /** The current agent's ID (for one-hop rule enforcement) */
43
+ currentAgentId: string;
44
+ /**
45
+ * Platform-specific handoff handler. Called after validation.
46
+ * Should show approval UI if needed and execute the switch.
47
+ */
48
+ onHandoff: (targetAgentId: string, task: string, reason?: string) => Promise<HandoffResult>;
49
+ }
50
+ /**
51
+ * Create a handoff tool for a specific agent.
52
+ *
53
+ * The tool enforces the one-hop rule: if this agent was itself handed a task,
54
+ * it can only hand back to the coordinator (default agent), not to another specialist.
55
+ */
56
+ export declare function createHandoffTool(config: HandoffToolConfig): Tool<HandoffInput>;
57
+ export {};
@@ -0,0 +1,224 @@
1
+ /**
2
+ * Delegation & Handoff Tools — SDK Factories
3
+ *
4
+ * Factory functions for creating delegation_status and handoff tools.
5
+ * Both CLI and Desktop call these with platform-specific dependencies.
6
+ */
7
+ import { defineTool } from '@compilr-dev/agents';
8
+ function formatDuration(from, to) {
9
+ const endTime = to ?? new Date();
10
+ const ms = endTime.getTime() - from.getTime();
11
+ const seconds = Math.floor(ms / 1000);
12
+ const minutes = Math.floor(seconds / 60);
13
+ const hours = Math.floor(minutes / 60);
14
+ if (hours > 0) {
15
+ return `${String(hours)}h ${String(minutes % 60)}m`;
16
+ }
17
+ else if (minutes > 0) {
18
+ return `${String(minutes)}m ${String(seconds % 60)}s`;
19
+ }
20
+ else {
21
+ return `${String(seconds)}s`;
22
+ }
23
+ }
24
+ function formatDelegation(d) {
25
+ const entry = {
26
+ id: d.id,
27
+ targetAgent: d.targetAgentId,
28
+ task: d.task.length > 100 ? d.task.slice(0, 100) + '...' : d.task,
29
+ status: d.status,
30
+ duration: formatDuration(d.createdAt, d.completedAt),
31
+ };
32
+ if (d.todoIndex !== undefined) {
33
+ entry.todoIndex = d.todoIndex;
34
+ }
35
+ if (d.result) {
36
+ entry.result = {
37
+ success: d.result.success,
38
+ summary: d.result.summary,
39
+ artifactIds: d.result.artifactIds,
40
+ ...(d.result.error ? { error: d.result.error } : {}),
41
+ };
42
+ }
43
+ return entry;
44
+ }
45
+ /**
46
+ * Create a delegation_status tool that queries the given tracker.
47
+ * Read-only — safe for parallel execution.
48
+ */
49
+ export function createDelegationStatusTool(tracker) {
50
+ return defineTool({
51
+ name: 'delegation_status',
52
+ description: 'Query the status of tasks delegated via delegate_background. ' +
53
+ 'Returns active delegations by default (pending and running). ' +
54
+ 'Use delegation_id for a specific delegation, agent_id to filter by agent, ' +
55
+ 'or status to see completed/failed/all delegations.',
56
+ inputSchema: {
57
+ type: 'object',
58
+ properties: {
59
+ delegation_id: {
60
+ type: 'string',
61
+ description: 'Specific delegation ID (e.g., "del_abc12345")',
62
+ },
63
+ agent_id: {
64
+ type: 'string',
65
+ description: 'Filter by target agent (e.g., "dev", "arch")',
66
+ },
67
+ status: {
68
+ type: 'string',
69
+ enum: ['active', 'completed', 'failed', 'all'],
70
+ description: 'Filter by status. Default: "active" (pending + running)',
71
+ },
72
+ },
73
+ },
74
+ execute: (input) => {
75
+ return Promise.resolve(executeDelegationStatus(tracker, input));
76
+ },
77
+ });
78
+ }
79
+ function executeDelegationStatus(tracker, input) {
80
+ // Single delegation lookup
81
+ if (input.delegation_id) {
82
+ const delegation = tracker.getDelegation(input.delegation_id);
83
+ if (!delegation) {
84
+ return {
85
+ success: false,
86
+ error: `Delegation ${input.delegation_id} not found`,
87
+ };
88
+ }
89
+ return {
90
+ success: true,
91
+ result: {
92
+ delegations: [formatDelegation(delegation)],
93
+ stats: tracker.getStats(),
94
+ },
95
+ };
96
+ }
97
+ // Get all delegations then filter
98
+ let delegations;
99
+ if (input.agent_id) {
100
+ delegations = tracker.getByAgent(input.agent_id);
101
+ }
102
+ else {
103
+ delegations = tracker.getAll();
104
+ }
105
+ // Apply status filter
106
+ const filter = input.status ?? 'active';
107
+ if (filter !== 'all') {
108
+ delegations = delegations.filter((d) => {
109
+ switch (filter) {
110
+ case 'active':
111
+ return d.status === 'pending' || d.status === 'running';
112
+ case 'completed':
113
+ return d.status === 'completed';
114
+ case 'failed':
115
+ return d.status === 'failed';
116
+ default:
117
+ return true;
118
+ }
119
+ });
120
+ }
121
+ return {
122
+ success: true,
123
+ result: {
124
+ delegations: delegations.map(formatDelegation),
125
+ stats: tracker.getStats(),
126
+ },
127
+ };
128
+ }
129
+ /**
130
+ * Create a handoff tool for a specific agent.
131
+ *
132
+ * The tool enforces the one-hop rule: if this agent was itself handed a task,
133
+ * it can only hand back to the coordinator (default agent), not to another specialist.
134
+ */
135
+ export function createHandoffTool(config) {
136
+ const { team, currentAgentId, onHandoff } = config;
137
+ return defineTool({
138
+ name: 'handoff',
139
+ description: 'Hand off the current task to another team agent. ' +
140
+ 'Use this when a task is outside your expertise or would benefit from another specialist. ' +
141
+ 'The user will be asked to approve the handoff before switching. ' +
142
+ 'Example: hand off architecture questions to $arch, implementation to $dev, testing to $qa.',
143
+ inputSchema: {
144
+ type: 'object',
145
+ properties: {
146
+ agentId: {
147
+ type: 'string',
148
+ description: 'Target agent ID (e.g., "arch", "dev", "qa", "default")',
149
+ },
150
+ task: {
151
+ type: 'string',
152
+ description: 'Task description for the target agent - be specific and clear',
153
+ },
154
+ reason: {
155
+ type: 'string',
156
+ description: 'Why this agent is better suited for the task (shown to user)',
157
+ },
158
+ },
159
+ required: ['agentId', 'task'],
160
+ },
161
+ execute: async (input) => {
162
+ // Validate input
163
+ if (!input.agentId || input.agentId.trim().length === 0) {
164
+ return { success: false, error: 'Agent ID is required' };
165
+ }
166
+ if (!input.task || input.task.trim().length === 0) {
167
+ return { success: false, error: 'Task description is required' };
168
+ }
169
+ const targetId = input.agentId.trim();
170
+ // Validate target agent exists in team
171
+ const allAgents = team.getAll();
172
+ const targetExists = allAgents.some((a) => a.id === targetId);
173
+ if (!targetExists) {
174
+ const available = allAgents.map((a) => a.id).join(', ');
175
+ return {
176
+ success: false,
177
+ error: `Agent "${targetId}" not found in team. Available: ${available}`,
178
+ };
179
+ }
180
+ // Enforce one-hop rule
181
+ if (team.wasHandedTo(currentAgentId) && targetId !== 'default') {
182
+ const source = team.getHandoffSource(currentAgentId);
183
+ return {
184
+ success: false,
185
+ error: `One-hop rule: you were handed this task by $${source ?? 'unknown'} ` +
186
+ `and cannot re-hand it to another specialist. ` +
187
+ `You can only hand back to $default (coordinator). ` +
188
+ `Either complete the task yourself or hand back to the coordinator.`,
189
+ };
190
+ }
191
+ // Execute handoff via platform callback
192
+ try {
193
+ const result = await onHandoff(targetId, input.task.trim(), input.reason?.trim());
194
+ if (result.error) {
195
+ return { success: false, error: result.error };
196
+ }
197
+ if (result.declined) {
198
+ return {
199
+ success: true,
200
+ result: {
201
+ handedOff: false,
202
+ message: 'User declined the handoff. Continue handling the task yourself.',
203
+ },
204
+ };
205
+ }
206
+ // Record the handoff for one-hop tracking
207
+ team.recordHandoff(targetId, currentAgentId);
208
+ return {
209
+ success: true,
210
+ result: {
211
+ handedOff: true,
212
+ message: `Task handed off to $${targetId}. They will handle it from here.`,
213
+ },
214
+ };
215
+ }
216
+ catch (err) {
217
+ return {
218
+ success: false,
219
+ error: `Handoff failed: ${err instanceof Error ? err.message : String(err)}`,
220
+ };
221
+ }
222
+ },
223
+ });
224
+ }
@@ -38,3 +38,5 @@ 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';
@@ -31,3 +31,5 @@ export { setActiveSharedContext, getActiveSharedContext, recordTeamActivity } fr
31
31
  export { SKILL_REQUIREMENTS, getDefinedSkillNames, getSkillRequirements, checkSkillCompatibility, getCompatibleSkills, getAllRequiredTools, getSkillsByCategory, } from './skill-requirements.js';
32
32
  // Collision utils
33
33
  export { resolveAgentIdCollision } from './collision-utils.js';
34
+ // Delegation & Handoff tools (factory functions)
35
+ export { createDelegationStatusTool, createHandoffTool } from './delegation-tools.js';
@@ -380,6 +380,85 @@ export const TOOL_GROUPS = {
380
380
  tier: 'meta',
381
381
  note: 'Generate project files from structured models',
382
382
  },
383
+ // Language-specific AST analysis (auto-loaded based on project language)
384
+ lang_typescript: {
385
+ label: 'TypeScript/JS Analysis',
386
+ tools: [
387
+ 'ts_find_symbol',
388
+ 'ts_find_references',
389
+ 'ts_find_implementations',
390
+ 'ts_find_dead_code',
391
+ 'ts_find_duplicates',
392
+ 'ts_find_patterns',
393
+ 'ts_get_file_structure',
394
+ 'ts_get_imports',
395
+ 'ts_get_exports',
396
+ 'ts_get_call_graph',
397
+ 'ts_get_dependency_graph',
398
+ 'ts_get_type_hierarchy',
399
+ 'ts_get_complexity',
400
+ 'ts_get_signature',
401
+ 'ts_get_documentation',
402
+ 'ts_read_function',
403
+ 'ts_read_class',
404
+ 'ts_read_type',
405
+ ],
406
+ readOnly: true,
407
+ tier: 'direct',
408
+ note: 'AST-based TypeScript/JavaScript analysis via TypeScript Compiler API',
409
+ },
410
+ lang_python: {
411
+ label: 'Python Analysis',
412
+ tools: [
413
+ 'find_symbol_python',
414
+ 'find_references_python',
415
+ 'find_implementations_python',
416
+ 'find_dead_code_python',
417
+ 'find_duplicates_python',
418
+ 'find_patterns_python',
419
+ 'get_file_structure_python',
420
+ 'get_imports_python',
421
+ 'get_exports_python',
422
+ 'get_call_graph_python',
423
+ 'get_dependency_graph_python',
424
+ 'get_class_hierarchy_python',
425
+ 'get_complexity_python',
426
+ 'get_signature_python',
427
+ 'extract_docstrings_python',
428
+ 'read_function_py',
429
+ 'read_class_py',
430
+ 'read_type_py',
431
+ ],
432
+ readOnly: true,
433
+ tier: 'direct',
434
+ note: 'AST-based Python analysis via Tree-sitter',
435
+ },
436
+ lang_go: {
437
+ label: 'Go Analysis',
438
+ tools: [
439
+ 'find_symbol_go',
440
+ 'find_references_go',
441
+ 'find_implementations_go',
442
+ 'find_dead_code_go',
443
+ 'find_duplicates_go',
444
+ 'find_patterns_go',
445
+ 'get_file_structure_go',
446
+ 'get_imports_go',
447
+ 'get_exports_go',
448
+ 'get_call_graph_go',
449
+ 'get_dependency_graph_go',
450
+ 'get_class_hierarchy_go',
451
+ 'get_complexity_go',
452
+ 'get_signature_go',
453
+ 'extract_docstrings_go',
454
+ 'read_function_go',
455
+ 'read_struct_go',
456
+ 'read_type_go',
457
+ ],
458
+ readOnly: true,
459
+ tier: 'direct',
460
+ note: 'AST-based Go analysis via Tree-sitter',
461
+ },
383
462
  };
384
463
  // =============================================================================
385
464
  // Tool Profiles
@@ -401,6 +480,9 @@ export const TOOL_PROFILES = {
401
480
  'search',
402
481
  'dependencies',
403
482
  'backlog_read',
483
+ 'lang_typescript',
484
+ 'lang_python',
485
+ 'lang_go',
404
486
  ],
405
487
  // Developer - coding tasks
406
488
  developer: [
@@ -429,6 +511,9 @@ export const TOOL_PROFILES = {
429
511
  'web',
430
512
  'factory_models',
431
513
  'factory_scaffold',
514
+ 'lang_typescript',
515
+ 'lang_python',
516
+ 'lang_go',
432
517
  ],
433
518
  // Security - security audits
434
519
  security: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@compilr-dev/sdk",
3
- "version": "0.10.6",
3
+ "version": "0.10.8",
4
4
  "description": "Universal agent runtime for building AI-powered applications",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -76,7 +76,7 @@
76
76
  },
77
77
  "devDependencies": {
78
78
  "@anthropic-ai/sdk": "^0.78.0",
79
- "@compilr-dev/agents-coding": "^1.0.6",
79
+ "@compilr-dev/agents-coding": "^1.0.8",
80
80
  "@eslint/js": "^9.39.1",
81
81
  "@opentelemetry/api": "^1.9.0",
82
82
  "@types/better-sqlite3": "^7.6.13",