wave-agent-sdk 0.6.4 → 0.7.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 (174) hide show
  1. package/dist/agent.d.ts +8 -0
  2. package/dist/agent.d.ts.map +1 -1
  3. package/dist/agent.js +49 -240
  4. package/dist/constants/tools.d.ts +0 -2
  5. package/dist/constants/tools.d.ts.map +1 -1
  6. package/dist/constants/tools.js +0 -2
  7. package/dist/core/plugin.d.ts +86 -0
  8. package/dist/core/plugin.d.ts.map +1 -0
  9. package/dist/core/plugin.js +164 -0
  10. package/dist/index.d.ts +1 -4
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +1 -5
  13. package/dist/managers/MemoryRuleManager.d.ts +3 -1
  14. package/dist/managers/MemoryRuleManager.d.ts.map +1 -1
  15. package/dist/managers/MemoryRuleManager.js +2 -1
  16. package/dist/managers/aiManager.d.ts +13 -23
  17. package/dist/managers/aiManager.d.ts.map +1 -1
  18. package/dist/managers/aiManager.js +59 -32
  19. package/dist/managers/backgroundTaskManager.d.ts +3 -1
  20. package/dist/managers/backgroundTaskManager.d.ts.map +1 -1
  21. package/dist/managers/backgroundTaskManager.js +2 -1
  22. package/dist/managers/bashManager.d.ts +4 -4
  23. package/dist/managers/bashManager.d.ts.map +1 -1
  24. package/dist/managers/bashManager.js +5 -2
  25. package/dist/managers/foregroundTaskManager.d.ts +3 -0
  26. package/dist/managers/foregroundTaskManager.d.ts.map +1 -1
  27. package/dist/managers/foregroundTaskManager.js +2 -1
  28. package/dist/managers/hookManager.d.ts +3 -3
  29. package/dist/managers/hookManager.d.ts.map +1 -1
  30. package/dist/managers/hookManager.js +20 -19
  31. package/dist/managers/liveConfigManager.d.ts +6 -13
  32. package/dist/managers/liveConfigManager.d.ts.map +1 -1
  33. package/dist/managers/liveConfigManager.js +50 -45
  34. package/dist/managers/lspManager.d.ts +4 -5
  35. package/dist/managers/lspManager.d.ts.map +1 -1
  36. package/dist/managers/lspManager.js +13 -12
  37. package/dist/managers/mcpManager.d.ts +3 -2
  38. package/dist/managers/mcpManager.d.ts.map +1 -1
  39. package/dist/managers/mcpManager.js +16 -15
  40. package/dist/managers/messageManager.d.ts +5 -7
  41. package/dist/managers/messageManager.d.ts.map +1 -1
  42. package/dist/managers/messageManager.js +12 -7
  43. package/dist/managers/permissionManager.d.ts +6 -4
  44. package/dist/managers/permissionManager.d.ts.map +1 -1
  45. package/dist/managers/permissionManager.js +39 -63
  46. package/dist/managers/planManager.d.ts +4 -6
  47. package/dist/managers/planManager.d.ts.map +1 -1
  48. package/dist/managers/planManager.js +18 -4
  49. package/dist/managers/pluginManager.d.ts +10 -22
  50. package/dist/managers/pluginManager.d.ts.map +1 -1
  51. package/dist/managers/pluginManager.js +27 -14
  52. package/dist/managers/reversionManager.d.ts +4 -3
  53. package/dist/managers/reversionManager.d.ts.map +1 -1
  54. package/dist/managers/reversionManager.js +5 -2
  55. package/dist/managers/skillManager.d.ts +3 -2
  56. package/dist/managers/skillManager.d.ts.map +1 -1
  57. package/dist/managers/skillManager.js +15 -14
  58. package/dist/managers/slashCommandManager.d.ts +9 -16
  59. package/dist/managers/slashCommandManager.d.ts.map +1 -1
  60. package/dist/managers/slashCommandManager.js +21 -10
  61. package/dist/managers/subagentManager.d.ts +7 -17
  62. package/dist/managers/subagentManager.d.ts.map +1 -1
  63. package/dist/managers/subagentManager.js +41 -34
  64. package/dist/managers/toolManager.d.ts +15 -38
  65. package/dist/managers/toolManager.d.ts.map +1 -1
  66. package/dist/managers/toolManager.js +66 -56
  67. package/dist/prompts/index.d.ts +6 -3
  68. package/dist/prompts/index.d.ts.map +1 -1
  69. package/dist/prompts/index.js +8 -16
  70. package/dist/services/MarketplaceService.d.ts.map +1 -1
  71. package/dist/services/MarketplaceService.js +13 -0
  72. package/dist/services/aiService.d.ts +4 -0
  73. package/dist/services/aiService.d.ts.map +1 -1
  74. package/dist/services/aiService.js +47 -7
  75. package/dist/services/configurationService.d.ts.map +1 -1
  76. package/dist/services/configurationService.js +30 -11
  77. package/dist/services/taskManager.d.ts +3 -1
  78. package/dist/services/taskManager.d.ts.map +1 -1
  79. package/dist/services/taskManager.js +2 -1
  80. package/dist/tools/bashTool.js +2 -2
  81. package/dist/tools/editTool.d.ts.map +1 -1
  82. package/dist/tools/editTool.js +9 -1
  83. package/dist/tools/readTool.d.ts.map +1 -1
  84. package/dist/tools/readTool.js +2 -2
  85. package/dist/tools/skillTool.d.ts +2 -4
  86. package/dist/tools/skillTool.d.ts.map +1 -1
  87. package/dist/tools/skillTool.js +61 -61
  88. package/dist/tools/taskOutputTool.js +1 -1
  89. package/dist/tools/taskTool.d.ts +2 -4
  90. package/dist/tools/taskTool.d.ts.map +1 -1
  91. package/dist/tools/taskTool.js +192 -187
  92. package/dist/tools/types.d.ts +11 -1
  93. package/dist/tools/types.d.ts.map +1 -1
  94. package/dist/tools/writeTool.d.ts.map +1 -1
  95. package/dist/tools/writeTool.js +4 -2
  96. package/dist/types/marketplace.d.ts +8 -0
  97. package/dist/types/marketplace.d.ts.map +1 -1
  98. package/dist/types/permissions.d.ts +1 -1
  99. package/dist/types/permissions.d.ts.map +1 -1
  100. package/dist/types/permissions.js +1 -3
  101. package/dist/types/skills.d.ts +0 -2
  102. package/dist/types/skills.d.ts.map +1 -1
  103. package/dist/types/tools.d.ts +0 -15
  104. package/dist/types/tools.d.ts.map +1 -1
  105. package/dist/utils/container.d.ts +31 -0
  106. package/dist/utils/container.d.ts.map +1 -0
  107. package/dist/utils/container.js +79 -0
  108. package/dist/utils/containerSetup.d.ts +26 -0
  109. package/dist/utils/containerSetup.d.ts.map +1 -0
  110. package/dist/utils/containerSetup.js +165 -0
  111. package/dist/utils/editUtils.d.ts +0 -3
  112. package/dist/utils/editUtils.d.ts.map +1 -1
  113. package/dist/utils/editUtils.js +4 -3
  114. package/dist/utils/hookMatcher.d.ts +1 -1
  115. package/dist/utils/hookMatcher.d.ts.map +1 -1
  116. package/dist/utils/hookMatcher.js +2 -2
  117. package/dist/utils/openaiClient.js +2 -2
  118. package/dist/utils/stringUtils.d.ts +6 -0
  119. package/dist/utils/stringUtils.d.ts.map +1 -1
  120. package/dist/utils/stringUtils.js +8 -0
  121. package/package.json +1 -1
  122. package/src/agent.ts +60 -282
  123. package/src/constants/tools.ts +0 -2
  124. package/src/core/plugin.ts +224 -0
  125. package/src/index.ts +1 -6
  126. package/src/managers/MemoryRuleManager.ts +6 -1
  127. package/src/managers/aiManager.ts +83 -58
  128. package/src/managers/backgroundTaskManager.ts +5 -1
  129. package/src/managers/bashManager.ts +9 -4
  130. package/src/managers/foregroundTaskManager.ts +3 -0
  131. package/src/managers/hookManager.ts +21 -23
  132. package/src/managers/liveConfigManager.ts +57 -53
  133. package/src/managers/lspManager.ts +14 -19
  134. package/src/managers/mcpManager.ts +20 -20
  135. package/src/managers/messageManager.ts +19 -12
  136. package/src/managers/permissionManager.ts +45 -70
  137. package/src/managers/planManager.ts +26 -7
  138. package/src/managers/pluginManager.ts +37 -33
  139. package/src/managers/reversionManager.ts +5 -3
  140. package/src/managers/skillManager.ts +19 -20
  141. package/src/managers/slashCommandManager.ts +30 -25
  142. package/src/managers/subagentManager.ts +53 -53
  143. package/src/managers/toolManager.ts +91 -90
  144. package/src/prompts/index.ts +12 -24
  145. package/src/services/MarketplaceService.ts +13 -0
  146. package/src/services/aiService.ts +61 -15
  147. package/src/services/configurationService.ts +34 -13
  148. package/src/services/taskManager.ts +5 -1
  149. package/src/tools/bashTool.ts +2 -2
  150. package/src/tools/editTool.ts +9 -1
  151. package/src/tools/readTool.ts +2 -2
  152. package/src/tools/skillTool.ts +75 -71
  153. package/src/tools/taskOutputTool.ts +1 -1
  154. package/src/tools/taskTool.ts +224 -225
  155. package/src/tools/types.ts +12 -1
  156. package/src/tools/writeTool.ts +4 -2
  157. package/src/types/marketplace.ts +9 -0
  158. package/src/types/permissions.ts +0 -4
  159. package/src/types/skills.ts +0 -3
  160. package/src/types/tools.ts +0 -17
  161. package/src/utils/container.ts +92 -0
  162. package/src/utils/containerSetup.ts +256 -0
  163. package/src/utils/editUtils.ts +4 -3
  164. package/src/utils/hookMatcher.ts +2 -2
  165. package/src/utils/openaiClient.ts +2 -2
  166. package/src/utils/stringUtils.ts +9 -0
  167. package/dist/tools/deleteFileTool.d.ts +0 -6
  168. package/dist/tools/deleteFileTool.d.ts.map +0 -1
  169. package/dist/tools/deleteFileTool.js +0 -100
  170. package/dist/tools/multiEditTool.d.ts +0 -6
  171. package/dist/tools/multiEditTool.d.ts.map +0 -1
  172. package/dist/tools/multiEditTool.js +0 -246
  173. package/src/tools/deleteFileTool.ts +0 -127
  174. package/src/tools/multiEditTool.ts +0 -306
@@ -1,245 +1,244 @@
1
1
  import type { ToolPlugin, ToolResult, ToolContext } from "./types.js";
2
- import type { SubagentManager } from "../managers/subagentManager.js";
3
2
  import { EXPLORE_SUBAGENT_TYPE } from "../constants/subagents.js";
4
3
  import { TASK_TOOL_NAME } from "../constants/tools.js";
4
+ import type { SubagentConfiguration } from "../utils/subagentParser.js";
5
5
 
6
6
  /**
7
- * Create a task tool plugin that uses the provided SubagentManager
8
- * Note: SubagentManager should be initialized before calling this function
7
+ * Task tool plugin for delegating tasks to specialized subagents
9
8
  */
10
- export function createTaskTool(subagentManager: SubagentManager): ToolPlugin {
11
- // Ensure SubagentManager is initialized
12
- subagentManager.getConfigurations();
13
-
14
- return {
15
- name: TASK_TOOL_NAME,
16
- get config() {
17
- // Get available subagents from the initialized subagent manager
18
- const availableSubagents = subagentManager.getConfigurations();
19
- const subagentList = availableSubagents
20
- .map((config) => `- ${config.name}: ${config.description}`)
21
- .join("\n");
22
-
23
- const description = `Delegate a task to a specialized subagent. Use this when you need specialized expertise or want to break down complex work into focused subtasks.
24
-
25
- Available subagents:
26
- ${subagentList || "No subagents configured"}`;
27
-
28
- return {
29
- type: "function" as const,
30
- function: {
31
- name: TASK_TOOL_NAME,
32
- description,
33
- parameters: {
34
- type: "object",
35
- properties: {
36
- description: {
37
- type: "string",
38
- description:
39
- "A clear, concise description of what needs to be accomplished",
40
- },
41
- prompt: {
42
- type: "string",
43
- description:
44
- "The specific instructions or prompt to send to the subagent",
45
- },
46
- subagent_type: {
47
- type: "string",
48
- description: `The type or name of subagent to use. Available options: ${availableSubagents.map((c) => c.name).join(", ") || "none"}`,
49
- },
50
- run_in_background: {
51
- type: "boolean",
52
- description:
53
- "Set to true to run this command in the background. Use TaskOutput to read the output later.",
54
- },
55
- },
56
- required: ["description", "prompt", "subagent_type"],
9
+ export const taskTool: ToolPlugin = {
10
+ name: TASK_TOOL_NAME,
11
+ config: {
12
+ type: "function" as const,
13
+ function: {
14
+ name: TASK_TOOL_NAME,
15
+ description:
16
+ "Delegate a task to a specialized subagent. Use this when you need specialized expertise or want to break down complex work into focused subtasks.",
17
+ parameters: {
18
+ type: "object",
19
+ properties: {
20
+ description: {
21
+ type: "string",
22
+ description: "A short (3-5 word) description of the task",
23
+ },
24
+ prompt: {
25
+ type: "string",
26
+ description: "The task for the agent to perform",
27
+ },
28
+ subagent_type: {
29
+ type: "string",
30
+ description: "The type of specialized agent to use for this task",
31
+ },
32
+ run_in_background: {
33
+ type: "boolean",
34
+ description:
35
+ "Set to true to run this command in the background. Use TaskOutput to read the output later.",
57
36
  },
58
37
  },
59
- };
38
+ required: ["description", "prompt", "subagent_type"],
39
+ },
60
40
  },
41
+ },
42
+
43
+ prompt: (args?: { availableSubagents?: SubagentConfiguration[] }) => {
44
+ const subagentList = args?.availableSubagents
45
+ ? args.availableSubagents
46
+ .map((config) => `- ${config.name}: ${config.description}`)
47
+ .join("\n")
48
+ : "";
49
+
50
+ return `
51
+ Delegate a task to a specialized subagent. Use this when you need specialized expertise or want to break down complex work into focused subtasks.
52
+
53
+ Available subagents:
54
+ ${subagentList || "No subagents configured"}
61
55
 
62
- prompt: () => `
63
56
  - When doing file search, prefer to use the ${TASK_TOOL_NAME} tool in order to reduce context usage.
64
57
  - You should proactively use the ${TASK_TOOL_NAME} tool with specialized agents when the task at hand matches the agent's description.
65
- - VERY IMPORTANT: When exploring the codebase to gather context or to answer a question that is not a needle query for a specific file/class/function, it is CRITICAL that you use the ${TASK_TOOL_NAME} tool with subagent_type=${EXPLORE_SUBAGENT_TYPE} instead of running search commands directly.`,
66
-
67
- execute: async (
68
- args: Record<string, unknown>,
69
- context: ToolContext,
70
- ): Promise<ToolResult> => {
71
- return new Promise((resolve) => {
72
- (async () => {
73
- // Input validation
74
- const description = args.description as string;
75
- const prompt = args.prompt as string;
76
- const subagent_type = args.subagent_type as string;
77
- const run_in_background = args.run_in_background as boolean;
78
-
79
- if (!description || typeof description !== "string") {
80
- return resolve({
81
- success: false,
82
- content: "",
83
- error: "description parameter is required and must be a string",
84
- shortResult: "Task delegation failed",
85
- });
86
- }
87
-
88
- if (!prompt || typeof prompt !== "string") {
89
- return resolve({
90
- success: false,
91
- content: "",
92
- error: "prompt parameter is required and must be a string",
93
- shortResult: "Task delegation failed",
94
- });
95
- }
58
+ - VERY IMPORTANT: When exploring the codebase to gather context or to answer a question that is not a needle query for a specific file/class/function, it is CRITICAL that you use the ${TASK_TOOL_NAME} tool with subagent_type=${EXPLORE_SUBAGENT_TYPE} instead of running search commands directly.`;
59
+ },
60
+
61
+ execute: async (
62
+ args: Record<string, unknown>,
63
+ context: ToolContext,
64
+ ): Promise<ToolResult> => {
65
+ const subagentManager = context.subagentManager;
66
+ if (!subagentManager) {
67
+ return {
68
+ success: false,
69
+ content: "",
70
+ error: "Subagent manager not available in tool context",
71
+ shortResult: "Task delegation failed",
72
+ };
73
+ }
96
74
 
97
- if (!subagent_type || typeof subagent_type !== "string") {
98
- return resolve({
99
- success: false,
100
- content: "",
101
- error: "subagent_type parameter is required and must be a string",
102
- shortResult: "Task delegation failed",
103
- });
104
- }
75
+ // Input validation
76
+ const description = args.description as string;
77
+ const prompt = args.prompt as string;
78
+ const subagent_type = args.subagent_type as string;
79
+ const run_in_background = args.run_in_background as boolean;
105
80
 
106
- try {
107
- // Subagent selection logic with explicit name matching only
108
- const configuration =
109
- await subagentManager.findSubagent(subagent_type);
110
-
111
- if (!configuration) {
112
- // Error handling for nonexistent subagents with available subagents listing
113
- const allConfigs = subagentManager.getConfigurations();
114
- const availableNames = allConfigs.map((c) => c.name).join(", ");
115
-
116
- return resolve({
117
- success: false,
118
- content: "",
119
- error: `No subagent found matching "${subagent_type}". Available subagents: ${availableNames || "none"}`,
120
- shortResult: "Subagent not found",
121
- });
122
- }
123
-
124
- // Set up callback to update shortResult with tool names, tool count and tokens
125
- const updateShortResult = () => {
126
- const messages = instance.messageManager.getMessages();
127
- const tokens = instance.messageManager.getlatestTotalTokens();
128
- const lastTools = instance.lastTools;
129
-
130
- // Count tool blocks in messages
131
- let toolCount = 0;
132
- messages.forEach((msg) => {
133
- msg.blocks.forEach((block) => {
134
- if (block.type === "tool") {
135
- toolCount++;
136
- }
137
- });
138
- });
139
-
140
- let shortResult = "";
141
- if (toolCount > 2) {
142
- shortResult += "... ";
143
- }
144
- if (lastTools.length > 0) {
145
- shortResult += `${lastTools.join(", ")} `;
146
- }
81
+ if (!description || typeof description !== "string") {
82
+ return {
83
+ success: false,
84
+ content: "",
85
+ error: "description parameter is required and must be a string",
86
+ shortResult: "Task delegation failed",
87
+ };
88
+ }
147
89
 
148
- shortResult += `(${toolCount} tools`;
149
- if (tokens > 0) {
150
- shortResult += ` | ${tokens.toLocaleString()} tokens`;
151
- }
152
- shortResult += ")";
153
-
154
- context.onShortResultUpdate?.(shortResult);
155
- };
156
-
157
- // Create subagent instance and execute task
158
- const instance = await subagentManager.createInstance(
159
- configuration,
160
- {
161
- description,
162
- prompt,
163
- subagent_type,
164
- },
165
- run_in_background,
166
- updateShortResult,
167
- );
168
-
169
- // Initial update
170
- updateShortResult();
171
-
172
- let isBackgrounded = false;
173
-
174
- // Register for backgrounding if not already in background
175
- if (!run_in_background && context.foregroundTaskManager) {
176
- context.foregroundTaskManager.registerForegroundTask({
177
- id: instance.subagentId,
178
- backgroundHandler: async () => {
179
- isBackgrounded = true;
180
- const taskId = await subagentManager.backgroundInstance(
181
- instance.subagentId,
182
- );
183
- // Resolve the tool execution early so the main agent can continue
184
- resolve({
185
- success: true,
186
- content: `Task moved to background with ID: ${taskId}.`,
187
- shortResult: "Task backgrounded",
188
- isManuallyBackgrounded: true,
189
- });
190
- },
191
- });
192
- }
193
-
194
- try {
195
- const result = await subagentManager.executeTask(
196
- instance,
197
- prompt,
198
- context.abortSignal,
199
- run_in_background,
200
- );
201
-
202
- if (isBackgrounded) return;
203
-
204
- if (run_in_background) {
205
- return resolve({
206
- success: true,
207
- content: `Task started in background with ID: ${result}`,
208
- shortResult: `Task started in background: ${result}`,
209
- });
210
- }
90
+ if (!prompt || typeof prompt !== "string") {
91
+ return {
92
+ success: false,
93
+ content: "",
94
+ error: "prompt parameter is required and must be a string",
95
+ shortResult: "Task delegation failed",
96
+ };
97
+ }
211
98
 
212
- // Cleanup subagent instance after task completion
213
- subagentManager.cleanupInstance(instance.subagentId);
214
-
215
- return resolve({
216
- success: true,
217
- content: result,
218
- shortResult: `Task completed by ${configuration.name}`,
219
- });
220
- } finally {
221
- if (!run_in_background && context.foregroundTaskManager) {
222
- context.foregroundTaskManager.unregisterForegroundTask(
223
- instance.subagentId,
224
- );
99
+ if (!subagent_type || typeof subagent_type !== "string") {
100
+ return {
101
+ success: false,
102
+ content: "",
103
+ error: "subagent_type parameter is required and must be a string",
104
+ shortResult: "Task delegation failed",
105
+ };
106
+ }
107
+
108
+ try {
109
+ // Subagent selection logic with explicit name matching only
110
+ const configuration = await subagentManager.findSubagent(subagent_type);
111
+
112
+ if (!configuration) {
113
+ // Error handling for nonexistent subagents with available subagents listing
114
+ const allConfigs = subagentManager.getConfigurations();
115
+ const availableNames = allConfigs.map((c) => c.name).join(", ");
116
+
117
+ return {
118
+ success: false,
119
+ content: "",
120
+ error: `No subagent found matching "${subagent_type}". Available subagents: ${availableNames || "none"}`,
121
+ shortResult: "Subagent not found",
122
+ };
123
+ }
124
+
125
+ let isBackgrounded = false;
126
+
127
+ // Create subagent instance and execute task
128
+ const instance = await subagentManager.createInstance(
129
+ configuration,
130
+ {
131
+ description,
132
+ prompt,
133
+ subagent_type,
134
+ },
135
+ run_in_background,
136
+ () => {
137
+ // Do not update shortResult if it is running in background
138
+ if (run_in_background || isBackgrounded) return;
139
+
140
+ const messages = instance.messageManager.getMessages();
141
+ const tokens = instance.messageManager.getlatestTotalTokens();
142
+ const lastTools = instance.lastTools;
143
+
144
+ // Count tool blocks in messages
145
+ let toolCount = 0;
146
+ messages.forEach((msg) => {
147
+ msg.blocks.forEach((block) => {
148
+ if (block.type === "tool") {
149
+ toolCount++;
225
150
  }
226
- }
227
- } catch (error) {
228
- return resolve({
229
- success: false,
230
- content: "",
231
- error: `Task delegation failed: ${error instanceof Error ? error.message : String(error)}`,
232
- shortResult: "Delegation error",
233
151
  });
152
+ });
153
+
154
+ let shortResult = "";
155
+ if (toolCount > 2) {
156
+ shortResult += "... ";
157
+ }
158
+ if (lastTools.length > 0) {
159
+ shortResult += `${lastTools.join(", ")} `;
234
160
  }
235
- })();
236
- });
237
- },
238
161
 
239
- formatCompactParams: (params: Record<string, unknown>) => {
240
- const subagent_type = params.subagent_type as string;
241
- const description = params.description as string;
242
- return `${subagent_type || "unknown"}: ${description || "no description"}`;
243
- },
244
- };
245
- }
162
+ shortResult += `(${toolCount} tools`;
163
+ if (tokens > 0) {
164
+ shortResult += ` | ${tokens.toLocaleString()} tokens`;
165
+ }
166
+ shortResult += ")";
167
+
168
+ context.onShortResultUpdate?.(shortResult);
169
+ },
170
+ );
171
+
172
+ // Register for backgrounding if not already in background
173
+ if (!run_in_background && context.foregroundTaskManager) {
174
+ context.foregroundTaskManager.registerForegroundTask({
175
+ id: instance.subagentId,
176
+ backgroundHandler: async () => {
177
+ isBackgrounded = true;
178
+ await subagentManager.backgroundInstance(instance.subagentId);
179
+ },
180
+ });
181
+ }
182
+
183
+ try {
184
+ const result = await subagentManager.executeTask(
185
+ instance,
186
+ prompt,
187
+ context.abortSignal,
188
+ run_in_background,
189
+ );
190
+
191
+ if (isBackgrounded) {
192
+ // If it was backgrounded during execution, the backgroundHandler already returned/will return
193
+ // But wait, the backgroundHandler is async and returns a ToolResult.
194
+ // In the current ToolManager/AIManager implementation, the backgroundHandler's return value
195
+ // is what's used when backgrounding happens.
196
+ // However, executeTask might still be running.
197
+ // We should return a special value or just let it be.
198
+ return {
199
+ success: true,
200
+ content: "Task backgrounded",
201
+ shortResult: "Task backgrounded",
202
+ isManuallyBackgrounded: true,
203
+ };
204
+ }
205
+
206
+ if (run_in_background) {
207
+ return {
208
+ success: true,
209
+ content: `Task started in background with ID: ${result}`,
210
+ shortResult: `Task started in background: ${result}`,
211
+ };
212
+ }
213
+
214
+ // Cleanup subagent instance after task completion
215
+ subagentManager.cleanupInstance(instance.subagentId);
216
+
217
+ return {
218
+ success: true,
219
+ content: result,
220
+ shortResult: `Task completed by ${configuration.name}`,
221
+ };
222
+ } finally {
223
+ if (!run_in_background && context.foregroundTaskManager) {
224
+ context.foregroundTaskManager.unregisterForegroundTask(
225
+ instance.subagentId,
226
+ );
227
+ }
228
+ }
229
+ } catch (error) {
230
+ return {
231
+ success: false,
232
+ content: "",
233
+ error: `Task delegation failed: ${error instanceof Error ? error.message : String(error)}`,
234
+ shortResult: "Delegation error",
235
+ };
236
+ }
237
+ },
238
+
239
+ formatCompactParams: (params: Record<string, unknown>) => {
240
+ const subagent_type = params.subagent_type as string;
241
+ const description = params.description as string;
242
+ return `${subagent_type || "unknown"}: ${description || "no description"}`;
243
+ },
244
+ };
@@ -8,6 +8,9 @@ import type {
8
8
  PermissionCallback,
9
9
  } from "../types/permissions.js";
10
10
 
11
+ import type { SubagentConfiguration } from "../utils/subagentParser.js";
12
+ import type { SkillMetadata } from "../types/skills.js";
13
+
11
14
  export interface ToolPlugin {
12
15
  name: string;
13
16
  config: ChatCompletionFunctionTool;
@@ -22,7 +25,11 @@ export interface ToolPlugin {
22
25
  /**
23
26
  * Optional function to provide a prompt to be added to the system prompt
24
27
  */
25
- prompt?: () => string;
28
+ prompt?: (args?: {
29
+ availableSubagents?: SubagentConfiguration[];
30
+ availableSkills?: SkillMetadata[];
31
+ workdir?: string;
32
+ }) => string;
26
33
  }
27
34
 
28
35
  export interface ToolResult {
@@ -65,6 +72,10 @@ export interface ToolContext {
65
72
  foregroundTaskManager?: import("../types/processes.js").IForegroundTaskManager;
66
73
  /** Task manager instance for task management */
67
74
  taskManager: import("../services/taskManager.js").TaskManager;
75
+ /** Subagent manager instance for task delegation */
76
+ subagentManager?: import("../managers/subagentManager.js").SubagentManager;
77
+ /** Skill manager instance for skill invocation */
78
+ skillManager?: import("../managers/skillManager.js").SkillManager;
68
79
  /** Current session ID */
69
80
  sessionId?: string;
70
81
  /** Callback to update the short result of the current tool block */
@@ -3,6 +3,7 @@ import { dirname } from "path";
3
3
  import { logger } from "../utils/globalLogger.js";
4
4
  import type { ToolPlugin, ToolResult, ToolContext } from "./types.js";
5
5
  import { resolvePath, getDisplayPath } from "../utils/path.js";
6
+ import { READ_TOOL_NAME } from "../constants/tools.js";
6
7
 
7
8
  /**
8
9
  * File Write Tool Plugin
@@ -32,10 +33,11 @@ export const writeTool: ToolPlugin = {
32
33
  },
33
34
  },
34
35
  },
35
- prompt: () => `
36
+ prompt: () => `Writes a file to the local filesystem.
37
+
36
38
  Usage:
37
39
  - This tool will overwrite the existing file if there is one at the provided path.
38
- - If this is an existing file, you MUST use the Read tool first to read the file's contents. This tool will fail if you did not read the file first.
40
+ - If this is an existing file, you MUST use the \`${READ_TOOL_NAME}\` tool first to read the file's contents. This tool will fail if you did not read the file first.
39
41
  - ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required.
40
42
  - NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested by the User.
41
43
  - Only use emojis if the user explicitly requests it. Avoid writing emojis to files unless asked.
@@ -11,6 +11,15 @@ export interface MarketplacePluginEntry {
11
11
  description: string;
12
12
  }
13
13
 
14
+ export interface MarketplacePluginStatus extends MarketplacePluginEntry {
15
+ marketplace: string;
16
+ installed: boolean;
17
+ version?: string;
18
+ cachePath?: string;
19
+ projectPath?: string;
20
+ scope?: Scope;
21
+ }
22
+
14
23
  export interface MarketplaceManifest {
15
24
  name: string;
16
25
  owner: MarketplaceOwner;
@@ -10,8 +10,6 @@ import {
10
10
  } from "./tools.js";
11
11
  import {
12
12
  EDIT_TOOL_NAME,
13
- MULTI_EDIT_TOOL_NAME,
14
- DELETE_FILE_TOOL_NAME,
15
13
  BASH_TOOL_NAME,
16
14
  WRITE_TOOL_NAME,
17
15
  EXIT_PLAN_MODE_TOOL_NAME,
@@ -61,8 +59,6 @@ export interface ToolPermissionContext {
61
59
  /** List of tools that require permission checks in default mode */
62
60
  export const RESTRICTED_TOOLS = [
63
61
  EDIT_TOOL_NAME,
64
- MULTI_EDIT_TOOL_NAME,
65
- DELETE_FILE_TOOL_NAME,
66
62
  BASH_TOOL_NAME,
67
63
  WRITE_TOOL_NAME,
68
64
  EXIT_PLAN_MODE_TOOL_NAME,
@@ -3,8 +3,6 @@
3
3
  * Dependencies: Core (Logger)
4
4
  */
5
5
 
6
- import type { Logger } from "./core.js";
7
-
8
6
  export interface SkillMetadata {
9
7
  name: string;
10
8
  description: string;
@@ -60,7 +58,6 @@ export interface SkillToolArgs {
60
58
  export interface SkillManagerOptions {
61
59
  personalSkillsPath?: string;
62
60
  scanTimeout?: number;
63
- logger?: Logger;
64
61
  workdir?: string;
65
62
  }
66
63
 
@@ -33,15 +33,6 @@ export interface WriteToolParameters {
33
33
  content: string;
34
34
  }
35
35
 
36
- /**
37
- * Parameters for a single edit operation in the Edit tool
38
- */
39
- export interface EditOperation {
40
- old_string: string;
41
- new_string: string;
42
- replace_all?: boolean;
43
- }
44
-
45
36
  /**
46
37
  * Parameters for the Edit tool
47
38
  */
@@ -51,11 +42,3 @@ export interface EditToolParameters {
51
42
  new_string: string;
52
43
  replace_all?: boolean;
53
44
  }
54
-
55
- /**
56
- * Parameters for the MultiEdit tool
57
- */
58
- export interface MultiEditToolParameters {
59
- file_path: string;
60
- edits: EditOperation[];
61
- }