@compilr-dev/agents 0.0.1

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 (160) hide show
  1. package/README.md +1277 -0
  2. package/dist/agent.d.ts +1272 -0
  3. package/dist/agent.js +1912 -0
  4. package/dist/anchors/builtin.d.ts +24 -0
  5. package/dist/anchors/builtin.js +61 -0
  6. package/dist/anchors/index.d.ts +6 -0
  7. package/dist/anchors/index.js +5 -0
  8. package/dist/anchors/manager.d.ts +115 -0
  9. package/dist/anchors/manager.js +412 -0
  10. package/dist/anchors/types.d.ts +168 -0
  11. package/dist/anchors/types.js +10 -0
  12. package/dist/context/index.d.ts +12 -0
  13. package/dist/context/index.js +10 -0
  14. package/dist/context/manager.d.ts +224 -0
  15. package/dist/context/manager.js +770 -0
  16. package/dist/context/types.d.ts +377 -0
  17. package/dist/context/types.js +7 -0
  18. package/dist/costs/index.d.ts +8 -0
  19. package/dist/costs/index.js +7 -0
  20. package/dist/costs/tracker.d.ts +121 -0
  21. package/dist/costs/tracker.js +295 -0
  22. package/dist/costs/types.d.ts +157 -0
  23. package/dist/costs/types.js +8 -0
  24. package/dist/errors.d.ts +178 -0
  25. package/dist/errors.js +249 -0
  26. package/dist/guardrails/builtin.d.ts +27 -0
  27. package/dist/guardrails/builtin.js +223 -0
  28. package/dist/guardrails/index.d.ts +6 -0
  29. package/dist/guardrails/index.js +5 -0
  30. package/dist/guardrails/manager.d.ts +117 -0
  31. package/dist/guardrails/manager.js +288 -0
  32. package/dist/guardrails/types.d.ts +159 -0
  33. package/dist/guardrails/types.js +7 -0
  34. package/dist/hooks/index.d.ts +31 -0
  35. package/dist/hooks/index.js +29 -0
  36. package/dist/hooks/manager.d.ts +147 -0
  37. package/dist/hooks/manager.js +600 -0
  38. package/dist/hooks/types.d.ts +368 -0
  39. package/dist/hooks/types.js +12 -0
  40. package/dist/index.d.ts +45 -0
  41. package/dist/index.js +73 -0
  42. package/dist/mcp/client.d.ts +93 -0
  43. package/dist/mcp/client.js +287 -0
  44. package/dist/mcp/errors.d.ts +60 -0
  45. package/dist/mcp/errors.js +78 -0
  46. package/dist/mcp/index.d.ts +43 -0
  47. package/dist/mcp/index.js +45 -0
  48. package/dist/mcp/manager.d.ts +120 -0
  49. package/dist/mcp/manager.js +276 -0
  50. package/dist/mcp/tools.d.ts +54 -0
  51. package/dist/mcp/tools.js +99 -0
  52. package/dist/mcp/types.d.ts +150 -0
  53. package/dist/mcp/types.js +40 -0
  54. package/dist/memory/index.d.ts +8 -0
  55. package/dist/memory/index.js +7 -0
  56. package/dist/memory/loader.d.ts +114 -0
  57. package/dist/memory/loader.js +463 -0
  58. package/dist/memory/types.d.ts +182 -0
  59. package/dist/memory/types.js +8 -0
  60. package/dist/messages/index.d.ts +82 -0
  61. package/dist/messages/index.js +155 -0
  62. package/dist/permissions/index.d.ts +5 -0
  63. package/dist/permissions/index.js +4 -0
  64. package/dist/permissions/manager.d.ts +125 -0
  65. package/dist/permissions/manager.js +379 -0
  66. package/dist/permissions/types.d.ts +162 -0
  67. package/dist/permissions/types.js +7 -0
  68. package/dist/providers/claude.d.ts +90 -0
  69. package/dist/providers/claude.js +348 -0
  70. package/dist/providers/index.d.ts +8 -0
  71. package/dist/providers/index.js +11 -0
  72. package/dist/providers/mock.d.ts +133 -0
  73. package/dist/providers/mock.js +204 -0
  74. package/dist/providers/types.d.ts +168 -0
  75. package/dist/providers/types.js +4 -0
  76. package/dist/rate-limit/index.d.ts +45 -0
  77. package/dist/rate-limit/index.js +47 -0
  78. package/dist/rate-limit/limiter.d.ts +104 -0
  79. package/dist/rate-limit/limiter.js +326 -0
  80. package/dist/rate-limit/provider-wrapper.d.ts +112 -0
  81. package/dist/rate-limit/provider-wrapper.js +201 -0
  82. package/dist/rate-limit/retry.d.ts +108 -0
  83. package/dist/rate-limit/retry.js +287 -0
  84. package/dist/rate-limit/types.d.ts +181 -0
  85. package/dist/rate-limit/types.js +22 -0
  86. package/dist/rehearsal/file-analyzer.d.ts +22 -0
  87. package/dist/rehearsal/file-analyzer.js +351 -0
  88. package/dist/rehearsal/git-analyzer.d.ts +22 -0
  89. package/dist/rehearsal/git-analyzer.js +472 -0
  90. package/dist/rehearsal/index.d.ts +35 -0
  91. package/dist/rehearsal/index.js +36 -0
  92. package/dist/rehearsal/manager.d.ts +100 -0
  93. package/dist/rehearsal/manager.js +290 -0
  94. package/dist/rehearsal/types.d.ts +235 -0
  95. package/dist/rehearsal/types.js +8 -0
  96. package/dist/skills/index.d.ts +160 -0
  97. package/dist/skills/index.js +282 -0
  98. package/dist/state/agent-state.d.ts +41 -0
  99. package/dist/state/agent-state.js +88 -0
  100. package/dist/state/checkpointer.d.ts +110 -0
  101. package/dist/state/checkpointer.js +362 -0
  102. package/dist/state/errors.d.ts +66 -0
  103. package/dist/state/errors.js +88 -0
  104. package/dist/state/index.d.ts +35 -0
  105. package/dist/state/index.js +37 -0
  106. package/dist/state/serializer.d.ts +55 -0
  107. package/dist/state/serializer.js +172 -0
  108. package/dist/state/types.d.ts +312 -0
  109. package/dist/state/types.js +14 -0
  110. package/dist/tools/builtin/bash-output.d.ts +61 -0
  111. package/dist/tools/builtin/bash-output.js +90 -0
  112. package/dist/tools/builtin/bash.d.ts +150 -0
  113. package/dist/tools/builtin/bash.js +354 -0
  114. package/dist/tools/builtin/edit.d.ts +50 -0
  115. package/dist/tools/builtin/edit.js +215 -0
  116. package/dist/tools/builtin/glob.d.ts +62 -0
  117. package/dist/tools/builtin/glob.js +244 -0
  118. package/dist/tools/builtin/grep.d.ts +74 -0
  119. package/dist/tools/builtin/grep.js +363 -0
  120. package/dist/tools/builtin/index.d.ts +44 -0
  121. package/dist/tools/builtin/index.js +69 -0
  122. package/dist/tools/builtin/kill-shell.d.ts +44 -0
  123. package/dist/tools/builtin/kill-shell.js +80 -0
  124. package/dist/tools/builtin/read-file.d.ts +57 -0
  125. package/dist/tools/builtin/read-file.js +184 -0
  126. package/dist/tools/builtin/shell-manager.d.ts +176 -0
  127. package/dist/tools/builtin/shell-manager.js +337 -0
  128. package/dist/tools/builtin/task.d.ts +202 -0
  129. package/dist/tools/builtin/task.js +350 -0
  130. package/dist/tools/builtin/todo.d.ts +207 -0
  131. package/dist/tools/builtin/todo.js +453 -0
  132. package/dist/tools/builtin/utils.d.ts +27 -0
  133. package/dist/tools/builtin/utils.js +70 -0
  134. package/dist/tools/builtin/web-fetch.d.ts +96 -0
  135. package/dist/tools/builtin/web-fetch.js +290 -0
  136. package/dist/tools/builtin/write-file.d.ts +54 -0
  137. package/dist/tools/builtin/write-file.js +147 -0
  138. package/dist/tools/define.d.ts +60 -0
  139. package/dist/tools/define.js +65 -0
  140. package/dist/tools/index.d.ts +10 -0
  141. package/dist/tools/index.js +37 -0
  142. package/dist/tools/registry.d.ts +79 -0
  143. package/dist/tools/registry.js +151 -0
  144. package/dist/tools/types.d.ts +59 -0
  145. package/dist/tools/types.js +4 -0
  146. package/dist/tracing/hooks.d.ts +58 -0
  147. package/dist/tracing/hooks.js +377 -0
  148. package/dist/tracing/index.d.ts +51 -0
  149. package/dist/tracing/index.js +55 -0
  150. package/dist/tracing/logging.d.ts +78 -0
  151. package/dist/tracing/logging.js +310 -0
  152. package/dist/tracing/manager.d.ts +160 -0
  153. package/dist/tracing/manager.js +468 -0
  154. package/dist/tracing/otel.d.ts +102 -0
  155. package/dist/tracing/otel.js +246 -0
  156. package/dist/tracing/types.d.ts +346 -0
  157. package/dist/tracing/types.js +38 -0
  158. package/dist/utils/index.d.ts +23 -0
  159. package/dist/utils/index.js +44 -0
  160. package/package.json +79 -0
@@ -0,0 +1,202 @@
1
+ /**
2
+ * Task Tool - LLM-controlled sub-agent spawning
3
+ *
4
+ * This tool allows the agent to spawn specialized sub-agents for complex tasks.
5
+ * It implements the "Hybrid" approach where both programmatic and LLM-controlled
6
+ * sub-agent spawning are supported.
7
+ *
8
+ * Enhanced features:
9
+ * - Context inheritance modes (isolated, inherit, inherit-summary)
10
+ * - Thoroughness levels for exploration agents
11
+ * - Tool inheritance & filtering
12
+ * - Event streaming from sub-agents
13
+ * - Extended built-in agent types
14
+ */
15
+ import type { Tool } from '../types.js';
16
+ import type { Agent, AgentEvent } from '../../agent.js';
17
+ import type { LLMProvider } from '../../providers/types.js';
18
+ /**
19
+ * Context inheritance mode for sub-agents
20
+ */
21
+ export type ContextMode = 'isolated' | 'inherit' | 'inherit-summary';
22
+ /**
23
+ * Thoroughness level for exploration agents
24
+ */
25
+ export type ThoroughnessLevel = 'quick' | 'medium' | 'thorough';
26
+ /**
27
+ * Input parameters for task tool
28
+ */
29
+ export interface TaskInput {
30
+ /**
31
+ * A short (3-5 word) description of the task
32
+ */
33
+ description: string;
34
+ /**
35
+ * Detailed task prompt for the sub-agent to perform
36
+ */
37
+ prompt: string;
38
+ /**
39
+ * The type of specialized agent to use (e.g., 'explore', 'code-review', 'general')
40
+ */
41
+ subagent_type: string;
42
+ /**
43
+ * Optional model to use for this agent (e.g., 'sonnet', 'opus', 'haiku')
44
+ */
45
+ model?: string;
46
+ /**
47
+ * Context inheritance mode (default: from agent type config)
48
+ * - 'isolated': Fresh context, no parent history
49
+ * - 'inherit': Receives parent's full message history
50
+ * - 'inherit-summary': Receives summarized parent context
51
+ */
52
+ context_mode?: ContextMode;
53
+ /**
54
+ * Thoroughness level for exploration agents (default: 'medium')
55
+ * - 'quick': Fast searches, basic analysis
56
+ * - 'medium': Balanced depth and speed
57
+ * - 'thorough': Comprehensive analysis, multiple passes
58
+ */
59
+ thoroughness?: ThoroughnessLevel;
60
+ }
61
+ /**
62
+ * Result of task tool execution
63
+ */
64
+ export interface TaskResult {
65
+ /**
66
+ * The sub-agent's response
67
+ */
68
+ response: string;
69
+ /**
70
+ * The agent type that was used
71
+ */
72
+ agentType: string;
73
+ /**
74
+ * Number of iterations the sub-agent took
75
+ */
76
+ iterations: number;
77
+ /**
78
+ * Tool calls made by the sub-agent
79
+ */
80
+ toolCalls: number;
81
+ }
82
+ /**
83
+ * Configuration for a pre-defined agent type
84
+ */
85
+ export interface AgentTypeConfig {
86
+ /**
87
+ * Description of what this agent type does
88
+ */
89
+ description: string;
90
+ /**
91
+ * System prompt for this agent type
92
+ */
93
+ systemPrompt?: string;
94
+ /**
95
+ * Tools available to this agent type (tool names or Tool instances)
96
+ */
97
+ tools?: (string | Tool)[];
98
+ /**
99
+ * Skills available to this agent type
100
+ */
101
+ skills?: string[];
102
+ /**
103
+ * Maximum iterations for this agent type
104
+ */
105
+ maxIterations?: number;
106
+ /**
107
+ * Default model for this agent type
108
+ */
109
+ defaultModel?: string;
110
+ /**
111
+ * Default context inheritance mode
112
+ */
113
+ contextMode?: ContextMode;
114
+ /**
115
+ * Whether this agent type supports thoroughness levels
116
+ */
117
+ supportsThoroughness?: boolean;
118
+ /**
119
+ * Tool inheritance mode:
120
+ * - 'none': Only use tools specified in this config
121
+ * - 'all': Inherit all parent tools plus config tools
122
+ * - 'filter': Inherit parent tools filtered by allowedTools/deniedTools
123
+ */
124
+ toolInheritance?: 'none' | 'all' | 'filter';
125
+ /**
126
+ * Tool names to allow (whitelist) when toolInheritance is 'filter'
127
+ */
128
+ allowedTools?: string[];
129
+ /**
130
+ * Tool names to deny (blacklist) when toolInheritance is 'filter'
131
+ */
132
+ deniedTools?: string[];
133
+ }
134
+ /**
135
+ * Sub-agent event with source information
136
+ */
137
+ export interface SubAgentEventInfo {
138
+ /**
139
+ * Name of the sub-agent that emitted this event
140
+ */
141
+ agentName: string;
142
+ /**
143
+ * Type of the sub-agent
144
+ */
145
+ agentType: string;
146
+ /**
147
+ * The original event from the sub-agent
148
+ */
149
+ event: AgentEvent;
150
+ }
151
+ /**
152
+ * Options for creating a task tool
153
+ */
154
+ export interface TaskToolOptions {
155
+ /**
156
+ * The parent agent that will spawn sub-agents
157
+ */
158
+ parentAgent: Agent;
159
+ /**
160
+ * Available agent types and their configurations
161
+ */
162
+ agentTypes: Record<string, AgentTypeConfig>;
163
+ /**
164
+ * Provider factory for creating sub-agent providers
165
+ * Called with model name, returns LLM provider
166
+ */
167
+ providerFactory?: (model: string) => LLMProvider;
168
+ /**
169
+ * Maximum concurrent sub-agents (default: 3)
170
+ */
171
+ maxConcurrent?: number;
172
+ /**
173
+ * Default timeout for sub-agent execution in ms (default: 300000 = 5 min)
174
+ */
175
+ defaultTimeout?: number;
176
+ /**
177
+ * Called when a sub-agent is spawned
178
+ */
179
+ onSpawn?: (agentType: string, description: string) => void;
180
+ /**
181
+ * Called when a sub-agent completes
182
+ */
183
+ onComplete?: (agentType: string, result: TaskResult) => void;
184
+ /**
185
+ * Called when a sub-agent emits an event (for real-time streaming)
186
+ * Only called if enableEventStreaming is true
187
+ */
188
+ onSubAgentEvent?: (eventInfo: SubAgentEventInfo) => void;
189
+ /**
190
+ * Enable event streaming from sub-agents (default: false)
191
+ * When enabled, sub-agent events are forwarded to onSubAgentEvent
192
+ */
193
+ enableEventStreaming?: boolean;
194
+ }
195
+ /**
196
+ * Create a task tool for LLM-controlled sub-agent spawning
197
+ */
198
+ export declare function createTaskTool(options: TaskToolOptions): Tool<TaskInput>;
199
+ /**
200
+ * Default agent type configurations
201
+ */
202
+ export declare const defaultAgentTypes: Record<string, AgentTypeConfig>;
@@ -0,0 +1,350 @@
1
+ /**
2
+ * Task Tool - LLM-controlled sub-agent spawning
3
+ *
4
+ * This tool allows the agent to spawn specialized sub-agents for complex tasks.
5
+ * It implements the "Hybrid" approach where both programmatic and LLM-controlled
6
+ * sub-agent spawning are supported.
7
+ *
8
+ * Enhanced features:
9
+ * - Context inheritance modes (isolated, inherit, inherit-summary)
10
+ * - Thoroughness levels for exploration agents
11
+ * - Tool inheritance & filtering
12
+ * - Event streaming from sub-agents
13
+ * - Extended built-in agent types
14
+ */
15
+ import { defineTool, createSuccessResult, createErrorResult } from '../define.js';
16
+ /**
17
+ * Map our context mode to agent's context mode
18
+ */
19
+ function mapContextMode(mode) {
20
+ switch (mode) {
21
+ case 'isolated':
22
+ return 'isolated';
23
+ case 'inherit':
24
+ return 'shared';
25
+ case 'inherit-summary':
26
+ return 'inherited';
27
+ default:
28
+ return 'isolated';
29
+ }
30
+ }
31
+ /**
32
+ * Get thoroughness-adjusted max iterations and system prompt suffix
33
+ */
34
+ function getThoroughnessConfig(level, baseIterations) {
35
+ switch (level) {
36
+ case 'quick':
37
+ return {
38
+ maxIterations: Math.min(baseIterations, 5),
39
+ promptSuffix: '\n\nBe efficient - do quick searches and return findings promptly. ' +
40
+ 'Avoid deep dives unless absolutely necessary.',
41
+ };
42
+ case 'medium':
43
+ return {
44
+ maxIterations: baseIterations,
45
+ promptSuffix: '',
46
+ };
47
+ case 'thorough':
48
+ return {
49
+ maxIterations: Math.max(baseIterations, 25),
50
+ promptSuffix: '\n\nBe thorough - check multiple locations, consider different naming conventions, ' +
51
+ 'and verify findings from multiple angles. Take your time to be comprehensive.',
52
+ };
53
+ default:
54
+ return { maxIterations: baseIterations, promptSuffix: '' };
55
+ }
56
+ }
57
+ /**
58
+ * Create a task tool for LLM-controlled sub-agent spawning
59
+ */
60
+ export function createTaskTool(options) {
61
+ const { parentAgent, agentTypes, providerFactory, maxConcurrent = 3, defaultTimeout = 300000, onSpawn, onComplete, onSubAgentEvent, enableEventStreaming = false, } = options;
62
+ // Track active sub-agents
63
+ let activeCount = 0;
64
+ // Build description of available agent types
65
+ const agentTypeDescriptions = Object.entries(agentTypes)
66
+ .map(([name, config]) => {
67
+ let desc = `- ${name}: ${config.description}`;
68
+ if (config.supportsThoroughness) {
69
+ desc += ' (supports thoroughness: quick/medium/thorough)';
70
+ }
71
+ return desc;
72
+ })
73
+ .join('\n');
74
+ return defineTool({
75
+ name: 'task',
76
+ description: 'Launch a specialized sub-agent to handle complex, multi-step tasks autonomously. ' +
77
+ 'Use this when a task requires focused work that would benefit from delegation.\n\n' +
78
+ 'Available agent types:\n' +
79
+ agentTypeDescriptions,
80
+ inputSchema: {
81
+ type: 'object',
82
+ properties: {
83
+ description: {
84
+ type: 'string',
85
+ description: 'A short (3-5 word) description of the task',
86
+ },
87
+ prompt: {
88
+ type: 'string',
89
+ description: 'Detailed task prompt for the sub-agent. Include all context needed ' +
90
+ 'and specify exactly what information should be returned.',
91
+ },
92
+ subagent_type: {
93
+ type: 'string',
94
+ description: `The type of agent to use. Available: ${Object.keys(agentTypes).join(', ')}`,
95
+ },
96
+ model: {
97
+ type: 'string',
98
+ description: 'Optional model override. Use "haiku" for quick tasks, ' +
99
+ '"sonnet" for standard tasks, "opus" for complex tasks.',
100
+ },
101
+ context_mode: {
102
+ type: 'string',
103
+ enum: ['isolated', 'inherit', 'inherit-summary'],
104
+ description: 'Context inheritance: "isolated" (fresh), "inherit" (full parent history), ' +
105
+ '"inherit-summary" (summarized parent context)',
106
+ },
107
+ thoroughness: {
108
+ type: 'string',
109
+ enum: ['quick', 'medium', 'thorough'],
110
+ description: 'Thoroughness level for exploration agents: "quick" (fast), ' +
111
+ '"medium" (balanced), "thorough" (comprehensive)',
112
+ },
113
+ },
114
+ required: ['description', 'prompt', 'subagent_type'],
115
+ },
116
+ execute: async (input) => {
117
+ const { description, prompt, subagent_type, model, context_mode, thoroughness = 'medium', } = input;
118
+ // Validate agent type exists
119
+ if (!Object.hasOwn(agentTypes, subagent_type)) {
120
+ return createErrorResult(`Unknown agent type: '${subagent_type}'. ` +
121
+ `Available types: ${Object.keys(agentTypes).join(', ')}`);
122
+ }
123
+ const agentConfig = agentTypes[subagent_type];
124
+ // Check concurrent limit
125
+ if (activeCount >= maxConcurrent) {
126
+ return createErrorResult(`Maximum concurrent sub-agents (${String(maxConcurrent)}) reached. ` +
127
+ `Wait for existing tasks to complete.`);
128
+ }
129
+ // Notify spawn
130
+ if (onSpawn) {
131
+ onSpawn(subagent_type, description);
132
+ }
133
+ activeCount++;
134
+ try {
135
+ // Note: Sub-agents currently use the parent's provider
136
+ // Future enhancement: support model switching via providerFactory
137
+ void model; // Model parameter reserved for future use
138
+ void providerFactory; // Provider factory reserved for future use
139
+ // Create sub-agent using parent's method
140
+ const subAgentName = `task-${subagent_type}-${String(Date.now())}`;
141
+ // Determine context mode (input overrides config default)
142
+ const effectiveContextMode = context_mode ?? agentConfig.contextMode ?? 'isolated';
143
+ // Get thoroughness adjustments if supported
144
+ const baseIterations = agentConfig.maxIterations ?? 10;
145
+ const { maxIterations, promptSuffix } = agentConfig.supportsThoroughness
146
+ ? getThoroughnessConfig(thoroughness, baseIterations)
147
+ : { maxIterations: baseIterations, promptSuffix: '' };
148
+ // Build system prompt with thoroughness suffix
149
+ const systemPrompt = agentConfig.systemPrompt
150
+ ? agentConfig.systemPrompt + promptSuffix
151
+ : promptSuffix.trim() || undefined;
152
+ // Use parent's sub-agent system
153
+ parentAgent.createSubAgent({
154
+ name: subAgentName,
155
+ description: description,
156
+ systemPrompt: systemPrompt,
157
+ maxIterations: maxIterations,
158
+ contextMode: mapContextMode(effectiveContextMode),
159
+ // Tools would be configured based on agentConfig.tools and toolInheritance
160
+ });
161
+ // Run the sub-agent with timeout
162
+ const timeoutPromise = new Promise((_, reject) => {
163
+ const timer = setTimeout(() => {
164
+ reject(new Error(`Sub-agent timed out after ${String(defaultTimeout)}ms`));
165
+ }, defaultTimeout);
166
+ // Ensure timer doesn't prevent process exit
167
+ if (typeof timer.unref === 'function') {
168
+ timer.unref();
169
+ }
170
+ });
171
+ // Set up event handler for streaming if enabled
172
+ let eventHandler;
173
+ if (enableEventStreaming && onSubAgentEvent) {
174
+ eventHandler = (event) => {
175
+ onSubAgentEvent({
176
+ agentName: subAgentName,
177
+ agentType: subagent_type,
178
+ event,
179
+ });
180
+ };
181
+ }
182
+ const resultPromise = parentAgent.runSubAgent(subAgentName, prompt, {
183
+ onEvent: eventHandler,
184
+ });
185
+ const result = await Promise.race([resultPromise, timeoutPromise]);
186
+ // Cleanup
187
+ parentAgent.disposeSubAgent(subAgentName);
188
+ const taskResult = {
189
+ response: result.response,
190
+ agentType: subagent_type,
191
+ iterations: result.iterations,
192
+ toolCalls: result.toolCalls.length,
193
+ };
194
+ // Notify completion
195
+ if (onComplete) {
196
+ onComplete(subagent_type, taskResult);
197
+ }
198
+ return createSuccessResult(taskResult);
199
+ }
200
+ catch (error) {
201
+ return createErrorResult(`Sub-agent failed: ${error instanceof Error ? error.message : String(error)}`);
202
+ }
203
+ finally {
204
+ activeCount--;
205
+ }
206
+ },
207
+ });
208
+ }
209
+ /**
210
+ * Default agent type configurations
211
+ */
212
+ export const defaultAgentTypes = {
213
+ explore: {
214
+ description: 'Fast agent for exploring codebases. Use for finding files, ' +
215
+ 'searching code, or answering questions about code structure.',
216
+ systemPrompt: 'You are a codebase exploration agent. Your task is to efficiently ' +
217
+ 'search and analyze code to answer questions. Use glob and grep tools ' +
218
+ 'to find relevant files, then read them to understand the code. ' +
219
+ 'Be thorough but efficient. Return a clear, concise summary of your findings.',
220
+ maxIterations: 15,
221
+ defaultModel: 'haiku',
222
+ contextMode: 'inherit-summary',
223
+ supportsThoroughness: true,
224
+ toolInheritance: 'filter',
225
+ allowedTools: ['glob', 'grep', 'read'],
226
+ },
227
+ 'code-review': {
228
+ description: 'Agent specialized for reviewing code changes. Use after writing ' +
229
+ 'significant code to check for issues.',
230
+ systemPrompt: 'You are a code review agent. Analyze the provided code for:\n' +
231
+ '1. Bugs and potential issues\n' +
232
+ '2. Security vulnerabilities\n' +
233
+ '3. Performance concerns\n' +
234
+ '4. Code style and best practices\n' +
235
+ 'Provide specific, actionable feedback with file and line references.',
236
+ maxIterations: 10,
237
+ defaultModel: 'sonnet',
238
+ contextMode: 'inherit-summary',
239
+ supportsThoroughness: false,
240
+ toolInheritance: 'filter',
241
+ allowedTools: ['glob', 'grep', 'read'],
242
+ },
243
+ general: {
244
+ description: 'General-purpose agent for complex multi-step tasks. Use when ' +
245
+ 'other specialized types do not fit.',
246
+ systemPrompt: 'You are a general-purpose agent. Complete the task thoroughly and ' +
247
+ 'report back with a clear summary of what you accomplished.',
248
+ maxIterations: 20,
249
+ defaultModel: 'sonnet',
250
+ contextMode: 'isolated',
251
+ supportsThoroughness: false,
252
+ toolInheritance: 'all',
253
+ },
254
+ plan: {
255
+ description: 'Planning agent for breaking down complex tasks. Use to create ' +
256
+ 'implementation plans before coding.',
257
+ systemPrompt: 'You are a planning agent. Analyze the task and create a detailed ' +
258
+ 'implementation plan with specific steps. Consider edge cases, ' +
259
+ 'dependencies, and potential issues. Output a structured plan.',
260
+ maxIterations: 10,
261
+ defaultModel: 'sonnet',
262
+ contextMode: 'inherit-summary',
263
+ supportsThoroughness: false,
264
+ toolInheritance: 'filter',
265
+ allowedTools: ['glob', 'grep', 'read'],
266
+ },
267
+ 'test-runner': {
268
+ description: 'Agent for running and analyzing tests. Use to run test suites, ' +
269
+ 'analyze failures, and suggest fixes.',
270
+ systemPrompt: 'You are a test runner agent. Your tasks include:\n' +
271
+ '1. Running test suites and capturing output\n' +
272
+ '2. Analyzing test failures and identifying root causes\n' +
273
+ '3. Suggesting fixes for failing tests\n' +
274
+ '4. Verifying fixes by re-running tests\n' +
275
+ 'Report test results clearly and provide actionable suggestions.',
276
+ maxIterations: 15,
277
+ defaultModel: 'sonnet',
278
+ contextMode: 'inherit-summary',
279
+ supportsThoroughness: true,
280
+ toolInheritance: 'filter',
281
+ allowedTools: ['bash', 'glob', 'grep', 'read'],
282
+ },
283
+ 'doc-lookup': {
284
+ description: 'Agent for searching documentation and APIs. Use to find ' +
285
+ 'documentation, understand APIs, or research technical topics.',
286
+ systemPrompt: 'You are a documentation lookup agent. Your tasks include:\n' +
287
+ '1. Searching for relevant documentation\n' +
288
+ '2. Finding API references and usage examples\n' +
289
+ '3. Explaining complex concepts clearly\n' +
290
+ '4. Providing code examples when helpful\n' +
291
+ 'Return well-organized, easy-to-understand information.',
292
+ maxIterations: 10,
293
+ defaultModel: 'haiku',
294
+ contextMode: 'isolated',
295
+ supportsThoroughness: true,
296
+ toolInheritance: 'filter',
297
+ allowedTools: ['webFetch', 'glob', 'grep', 'read'],
298
+ },
299
+ refactor: {
300
+ description: 'Agent for refactoring code safely. Use for renaming, extracting, ' +
301
+ 'or restructuring code while maintaining behavior.',
302
+ systemPrompt: 'You are a refactoring agent. Your tasks include:\n' +
303
+ '1. Identifying code that needs refactoring\n' +
304
+ '2. Planning safe refactoring steps\n' +
305
+ '3. Implementing changes incrementally\n' +
306
+ '4. Verifying behavior is preserved\n' +
307
+ 'Always prefer small, incremental changes. Report what was changed.',
308
+ maxIterations: 20,
309
+ defaultModel: 'sonnet',
310
+ contextMode: 'inherit-summary',
311
+ supportsThoroughness: false,
312
+ toolInheritance: 'filter',
313
+ allowedTools: ['glob', 'grep', 'read', 'edit', 'write'],
314
+ deniedTools: ['bash'],
315
+ },
316
+ 'security-audit': {
317
+ description: 'Agent for security auditing code. Use to scan for vulnerabilities, ' +
318
+ 'check dependencies, and identify security issues.',
319
+ systemPrompt: 'You are a security audit agent. Analyze code for:\n' +
320
+ '1. OWASP Top 10 vulnerabilities\n' +
321
+ '2. Injection attacks (SQL, XSS, command injection)\n' +
322
+ '3. Authentication and authorization issues\n' +
323
+ '4. Sensitive data exposure\n' +
324
+ '5. Insecure dependencies\n' +
325
+ '6. Configuration issues\n' +
326
+ 'Provide severity ratings and remediation steps for each finding.',
327
+ maxIterations: 15,
328
+ defaultModel: 'sonnet',
329
+ contextMode: 'isolated',
330
+ supportsThoroughness: true,
331
+ toolInheritance: 'filter',
332
+ allowedTools: ['glob', 'grep', 'read', 'bash'],
333
+ },
334
+ debug: {
335
+ description: 'Agent for debugging issues. Use to investigate bugs, analyze ' +
336
+ 'error logs, and find root causes.',
337
+ systemPrompt: 'You are a debugging agent. Your approach:\n' +
338
+ '1. Gather information about the issue\n' +
339
+ '2. Form hypotheses about root causes\n' +
340
+ '3. Test hypotheses systematically\n' +
341
+ '4. Identify the root cause\n' +
342
+ '5. Suggest or implement fixes\n' +
343
+ 'Document your reasoning and findings clearly.',
344
+ maxIterations: 20,
345
+ defaultModel: 'sonnet',
346
+ contextMode: 'inherit',
347
+ supportsThoroughness: true,
348
+ toolInheritance: 'all',
349
+ },
350
+ };