wave-agent-sdk 0.4.0 → 0.6.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 (190) hide show
  1. package/dist/agent.d.ts +42 -11
  2. package/dist/agent.d.ts.map +1 -1
  3. package/dist/agent.js +114 -115
  4. package/dist/constants/prompts.d.ts +18 -14
  5. package/dist/constants/prompts.d.ts.map +1 -1
  6. package/dist/constants/prompts.js +130 -54
  7. package/dist/constants/tools.d.ts +6 -3
  8. package/dist/constants/tools.d.ts.map +1 -1
  9. package/dist/constants/tools.js +6 -3
  10. package/dist/index.d.ts +1 -0
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +1 -0
  13. package/dist/managers/MemoryRuleManager.js +1 -1
  14. package/dist/managers/aiManager.d.ts +5 -3
  15. package/dist/managers/aiManager.d.ts.map +1 -1
  16. package/dist/managers/aiManager.js +57 -20
  17. package/dist/managers/backgroundBashManager.d.ts.map +1 -1
  18. package/dist/managers/backgroundBashManager.js +1 -0
  19. package/dist/managers/backgroundTaskManager.d.ts +35 -0
  20. package/dist/managers/backgroundTaskManager.d.ts.map +1 -0
  21. package/dist/managers/backgroundTaskManager.js +255 -0
  22. package/dist/managers/foregroundTaskManager.d.ts +9 -0
  23. package/dist/managers/foregroundTaskManager.d.ts.map +1 -0
  24. package/dist/managers/foregroundTaskManager.js +21 -0
  25. package/dist/managers/liveConfigManager.d.ts +1 -1
  26. package/dist/managers/lspManager.d.ts.map +1 -1
  27. package/dist/managers/lspManager.js +3 -1
  28. package/dist/managers/mcpManager.d.ts.map +1 -1
  29. package/dist/managers/messageManager.d.ts +26 -12
  30. package/dist/managers/messageManager.d.ts.map +1 -1
  31. package/dist/managers/messageManager.js +138 -64
  32. package/dist/managers/permissionManager.d.ts.map +1 -1
  33. package/dist/managers/permissionManager.js +26 -22
  34. package/dist/managers/planManager.d.ts +1 -1
  35. package/dist/managers/planManager.d.ts.map +1 -1
  36. package/dist/managers/planManager.js +2 -2
  37. package/dist/managers/pluginManager.d.ts.map +1 -1
  38. package/dist/managers/pluginManager.js +3 -2
  39. package/dist/managers/slashCommandManager.d.ts +6 -0
  40. package/dist/managers/slashCommandManager.d.ts.map +1 -1
  41. package/dist/managers/slashCommandManager.js +8 -2
  42. package/dist/managers/subagentManager.d.ts +15 -2
  43. package/dist/managers/subagentManager.d.ts.map +1 -1
  44. package/dist/managers/subagentManager.js +153 -39
  45. package/dist/managers/toolManager.d.ts +18 -1
  46. package/dist/managers/toolManager.d.ts.map +1 -1
  47. package/dist/managers/toolManager.js +29 -5
  48. package/dist/services/GitService.d.ts.map +1 -1
  49. package/dist/services/GitService.js +6 -2
  50. package/dist/services/MarketplaceService.d.ts +2 -2
  51. package/dist/services/MarketplaceService.d.ts.map +1 -1
  52. package/dist/services/MarketplaceService.js +18 -11
  53. package/dist/services/MemoryRuleService.d.ts +1 -1
  54. package/dist/services/MemoryRuleService.d.ts.map +1 -1
  55. package/dist/services/MemoryRuleService.js +13 -2
  56. package/dist/services/aiService.d.ts +0 -1
  57. package/dist/services/aiService.d.ts.map +1 -1
  58. package/dist/services/aiService.js +4 -140
  59. package/dist/services/memory.d.ts +0 -3
  60. package/dist/services/memory.d.ts.map +1 -1
  61. package/dist/services/memory.js +1 -60
  62. package/dist/services/session.d.ts +15 -1
  63. package/dist/services/session.d.ts.map +1 -1
  64. package/dist/services/session.js +57 -1
  65. package/dist/services/taskManager.d.ts +21 -0
  66. package/dist/services/taskManager.d.ts.map +1 -0
  67. package/dist/services/taskManager.js +158 -0
  68. package/dist/tools/askUserQuestion.d.ts.map +1 -1
  69. package/dist/tools/askUserQuestion.js +39 -25
  70. package/dist/tools/bashTool.d.ts +0 -8
  71. package/dist/tools/bashTool.d.ts.map +1 -1
  72. package/dist/tools/bashTool.js +48 -172
  73. package/dist/tools/editTool.d.ts.map +1 -1
  74. package/dist/tools/editTool.js +8 -6
  75. package/dist/tools/exitPlanMode.d.ts.map +1 -1
  76. package/dist/tools/exitPlanMode.js +25 -1
  77. package/dist/tools/globTool.d.ts.map +1 -1
  78. package/dist/tools/globTool.js +8 -2
  79. package/dist/tools/grepTool.d.ts.map +1 -1
  80. package/dist/tools/grepTool.js +17 -6
  81. package/dist/tools/lsTool.d.ts.map +1 -1
  82. package/dist/tools/lsTool.js +3 -1
  83. package/dist/tools/multiEditTool.d.ts.map +1 -1
  84. package/dist/tools/multiEditTool.js +7 -6
  85. package/dist/tools/readTool.d.ts.map +1 -1
  86. package/dist/tools/readTool.js +16 -1
  87. package/dist/tools/taskManagementTools.d.ts +6 -0
  88. package/dist/tools/taskManagementTools.d.ts.map +1 -0
  89. package/dist/tools/taskManagementTools.js +453 -0
  90. package/dist/tools/taskOutputTool.d.ts +3 -0
  91. package/dist/tools/taskOutputTool.d.ts.map +1 -0
  92. package/dist/tools/taskOutputTool.js +173 -0
  93. package/dist/tools/taskStopTool.d.ts +3 -0
  94. package/dist/tools/taskStopTool.d.ts.map +1 -0
  95. package/dist/tools/taskStopTool.js +71 -0
  96. package/dist/tools/taskTool.d.ts.map +1 -1
  97. package/dist/tools/taskTool.js +110 -63
  98. package/dist/tools/types.d.ts +12 -0
  99. package/dist/tools/types.d.ts.map +1 -1
  100. package/dist/tools/writeTool.d.ts.map +1 -1
  101. package/dist/tools/writeTool.js +9 -1
  102. package/dist/types/index.d.ts +1 -0
  103. package/dist/types/index.d.ts.map +1 -1
  104. package/dist/types/index.js +1 -0
  105. package/dist/types/marketplace.d.ts +1 -0
  106. package/dist/types/marketplace.d.ts.map +1 -1
  107. package/dist/types/messaging.d.ts +3 -8
  108. package/dist/types/messaging.d.ts.map +1 -1
  109. package/dist/types/processes.d.ts +29 -4
  110. package/dist/types/processes.d.ts.map +1 -1
  111. package/dist/types/tasks.d.ts +13 -0
  112. package/dist/types/tasks.d.ts.map +1 -0
  113. package/dist/types/tasks.js +1 -0
  114. package/dist/types/tools.d.ts +4 -1
  115. package/dist/types/tools.d.ts.map +1 -1
  116. package/dist/utils/builtinSubagents.d.ts.map +1 -1
  117. package/dist/utils/builtinSubagents.js +38 -1
  118. package/dist/utils/cacheControlUtils.d.ts.map +1 -1
  119. package/dist/utils/cacheControlUtils.js +18 -12
  120. package/dist/utils/constants.d.ts +0 -4
  121. package/dist/utils/constants.d.ts.map +1 -1
  122. package/dist/utils/constants.js +0 -4
  123. package/dist/utils/convertMessagesForAPI.js +2 -2
  124. package/dist/utils/editUtils.d.ts +2 -11
  125. package/dist/utils/editUtils.d.ts.map +1 -1
  126. package/dist/utils/editUtils.js +52 -79
  127. package/dist/utils/messageOperations.d.ts +5 -36
  128. package/dist/utils/messageOperations.d.ts.map +1 -1
  129. package/dist/utils/messageOperations.js +9 -98
  130. package/dist/utils/nameGenerator.d.ts +1 -1
  131. package/dist/utils/nameGenerator.d.ts.map +1 -1
  132. package/dist/utils/nameGenerator.js +19 -3
  133. package/package.json +5 -5
  134. package/src/agent.ts +157 -134
  135. package/src/constants/prompts.ts +156 -65
  136. package/src/constants/tools.ts +6 -3
  137. package/src/index.ts +1 -0
  138. package/src/managers/MemoryRuleManager.ts +1 -1
  139. package/src/managers/aiManager.ts +77 -35
  140. package/src/managers/backgroundBashManager.ts +1 -0
  141. package/src/managers/backgroundTaskManager.ts +305 -0
  142. package/src/managers/foregroundTaskManager.ts +27 -0
  143. package/src/managers/lspManager.ts +3 -1
  144. package/src/managers/mcpManager.ts +6 -3
  145. package/src/managers/messageManager.ts +185 -75
  146. package/src/managers/permissionManager.ts +33 -28
  147. package/src/managers/planManager.ts +2 -2
  148. package/src/managers/pluginManager.ts +4 -3
  149. package/src/managers/slashCommandManager.ts +15 -2
  150. package/src/managers/subagentManager.ts +194 -35
  151. package/src/managers/toolManager.ts +48 -6
  152. package/src/services/GitService.ts +6 -2
  153. package/src/services/MarketplaceService.ts +30 -12
  154. package/src/services/MemoryRuleService.ts +18 -6
  155. package/src/services/aiService.ts +3 -145
  156. package/src/services/memory.ts +1 -73
  157. package/src/services/session.ts +73 -0
  158. package/src/services/taskManager.ts +188 -0
  159. package/src/tools/askUserQuestion.ts +51 -29
  160. package/src/tools/bashTool.ts +63 -196
  161. package/src/tools/editTool.ts +9 -18
  162. package/src/tools/exitPlanMode.ts +26 -2
  163. package/src/tools/globTool.ts +10 -2
  164. package/src/tools/grepTool.ts +17 -6
  165. package/src/tools/lsTool.ts +3 -1
  166. package/src/tools/multiEditTool.ts +7 -18
  167. package/src/tools/readTool.ts +17 -1
  168. package/src/tools/taskManagementTools.ts +498 -0
  169. package/src/tools/taskOutputTool.ts +196 -0
  170. package/src/tools/taskStopTool.ts +78 -0
  171. package/src/tools/taskTool.ts +136 -74
  172. package/src/tools/types.ts +13 -0
  173. package/src/tools/writeTool.ts +9 -2
  174. package/src/types/index.ts +1 -0
  175. package/src/types/marketplace.ts +1 -0
  176. package/src/types/messaging.ts +2 -9
  177. package/src/types/processes.ts +39 -4
  178. package/src/types/tasks.ts +13 -0
  179. package/src/types/tools.ts +4 -1
  180. package/src/utils/builtinSubagents.ts +47 -1
  181. package/src/utils/cacheControlUtils.ts +26 -18
  182. package/src/utils/constants.ts +0 -5
  183. package/src/utils/convertMessagesForAPI.ts +2 -2
  184. package/src/utils/editUtils.ts +65 -103
  185. package/src/utils/messageOperations.ts +12 -136
  186. package/src/utils/nameGenerator.ts +20 -3
  187. package/dist/tools/todoWriteTool.d.ts +0 -6
  188. package/dist/tools/todoWriteTool.d.ts.map +0 -1
  189. package/dist/tools/todoWriteTool.js +0 -220
  190. package/src/tools/todoWriteTool.ts +0 -257
@@ -1,9 +1,6 @@
1
1
  import { ToolPlugin } from "./types.js";
2
2
  import { AskUserQuestionInput } from "../types/tools.js";
3
- import {
4
- ASK_USER_QUESTION_TOOL_NAME,
5
- EXIT_PLAN_MODE_TOOL_NAME,
6
- } from "../constants/tools.js";
3
+ import { ASK_USER_QUESTION_TOOL_NAME } from "../constants/tools.js";
7
4
 
8
5
  export const askUserQuestionTool: ToolPlugin = {
9
6
  name: ASK_USER_QUESTION_TOOL_NAME,
@@ -11,19 +8,8 @@ export const askUserQuestionTool: ToolPlugin = {
11
8
  type: "function",
12
9
  function: {
13
10
  name: ASK_USER_QUESTION_TOOL_NAME,
14
- description: `Asks the user multiple choice questions to gather information, clarify ambiguity, understand preferences, make decisions or offer them choices.
15
- Use this tool when you need to ask the user questions during execution. This allows you to:
16
- 1. Gather user preferences or requirements
17
- 2. Clarify ambiguous instructions
18
- 3. Get decisions on implementation choices as you work
19
- 4. Offer choices to the user about what direction to take.
20
-
21
- Usage notes:
22
- - Users will always be able to select "Other" to provide custom text input
23
- - Use multiSelect: true to allow multiple answers to be selected for a question
24
- - If you recommend a specific option, make that the first option in the list and add "(Recommended)" at the end of the label
25
-
26
- Plan mode note: In plan mode, use this tool to clarify requirements or choose between approaches BEFORE finalizing your plan. Do NOT use this tool to ask "Is my plan ready?" or "Should I proceed?" - use ${EXIT_PLAN_MODE_TOOL_NAME} for plan approval.`,
11
+ description:
12
+ "Asks the user multiple choice questions to gather information, clarify ambiguity, understand preferences, make decisions or offer them choices.",
27
13
  parameters: {
28
14
  type: "object",
29
15
  properties: {
@@ -31,37 +17,38 @@ Plan mode note: In plan mode, use this tool to clarify requirements or choose be
31
17
  type: "array",
32
18
  minItems: 1,
33
19
  maxItems: 4,
20
+ description: "Questions to ask the user (1-4 questions)",
34
21
  items: {
35
22
  type: "object",
36
23
  properties: {
37
24
  question: {
38
25
  type: "string",
39
- description: "The complete question to ask the user.",
26
+ description:
27
+ 'The complete question to ask the user. Should be clear, specific, and end with a question mark. Example: "Which library should we use for date formatting?" If multiSelect is true, phrase it accordingly, e.g. "Which features do you want to enable?"',
40
28
  },
41
29
  header: {
42
30
  type: "string",
43
31
  maxLength: 12,
44
- description:
45
- "Very short label displayed as a chip/tag (max 12 chars).",
32
+ description: `Very short label displayed as a chip/tag (max 12 chars). Examples: "Auth method", "Library", "Approach".`,
46
33
  },
47
34
  options: {
48
35
  type: "array",
49
36
  minItems: 2,
50
37
  maxItems: 4,
38
+ description:
39
+ "The available choices for this question. Must have 2-4 options. Each option should be a distinct, mutually exclusive choice (unless multiSelect is enabled). There should be no 'Other' option, that will be provided automatically.",
51
40
  items: {
52
41
  type: "object",
53
42
  properties: {
54
43
  label: {
55
44
  type: "string",
56
- description: "The display text for this option.",
45
+ description:
46
+ "The display text for this option that the user will see and select. Should be concise (1-5 words) and clearly describe the choice.",
57
47
  },
58
48
  description: {
59
49
  type: "string",
60
- description: "Explanation of what this option means.",
61
- },
62
- isRecommended: {
63
- type: "boolean",
64
- description: "Whether this option is recommended.",
50
+ description:
51
+ "Explanation of what this option means or what will happen if chosen. Useful for providing context about trade-offs or implications.",
65
52
  },
66
53
  },
67
54
  required: ["label"],
@@ -70,19 +57,54 @@ Plan mode note: In plan mode, use this tool to clarify requirements or choose be
70
57
  multiSelect: {
71
58
  type: "boolean",
72
59
  default: false,
73
- description: "Allow multiple answers to be selected.",
60
+ description:
61
+ "Set to true to allow the user to select multiple options instead of just one. Use when choices are not mutually exclusive.",
74
62
  },
75
63
  },
76
64
  required: ["question", "header", "options"],
77
65
  },
78
66
  },
67
+ answers: {
68
+ type: "object",
69
+ additionalProperties: { type: "string" },
70
+ description: "User answers collected by the permission component",
71
+ },
72
+ metadata: {
73
+ type: "object",
74
+ properties: {
75
+ source: {
76
+ type: "string",
77
+ description:
78
+ 'Optional identifier for the source of this question (e.g., "remember" for /remember command). Used for analytics tracking.',
79
+ },
80
+ },
81
+ description: "Optional metadata for the question",
82
+ },
79
83
  },
80
84
  required: ["questions"],
81
85
  },
82
86
  },
83
87
  },
88
+ prompt:
89
+ () => `Use this tool when you need to ask the user questions during execution. This allows you to:
90
+ 1. Gather user preferences or requirements
91
+ 2. Clarify ambiguous instructions
92
+ 3. Get decisions on implementation choices as you work
93
+ 4. Offer choices to the user about what direction to take.
94
+
95
+ Usage notes:
96
+ - Users will always be able to select "Other" to provide custom text input
97
+ - Use multiSelect: true to allow multiple answers to be selected for a question
98
+ - If you recommend a specific option, make that the first option in the list and add "(Recommended)" at the end of the label
99
+
100
+ Plan mode note: In plan mode, use this tool to clarify requirements or choose between approaches BEFORE finalizing your plan. Do NOT use this tool to ask "Is my plan ready?" or "Should I proceed?" - use ExitPlanMode for plan approval.
101
+ `,
84
102
  execute: async (args, context) => {
85
- const { questions } = args as unknown as AskUserQuestionInput;
103
+ const {
104
+ questions,
105
+ answers: existingAnswers,
106
+ metadata,
107
+ } = args as unknown as AskUserQuestionInput;
86
108
 
87
109
  if (!context.permissionManager) {
88
110
  throw new Error(
@@ -94,7 +116,7 @@ Plan mode note: In plan mode, use this tool to clarify requirements or choose be
94
116
  ASK_USER_QUESTION_TOOL_NAME,
95
117
  context.permissionMode || "default",
96
118
  context.canUseToolCallback,
97
- { questions },
119
+ { questions, answers: existingAnswers, metadata },
98
120
  );
99
121
  permissionContext.hidePersistentOption = true; // Always hide persistent option for questions
100
122
 
@@ -4,8 +4,7 @@ import { stripAnsiColors } from "../utils/stringUtils.js";
4
4
  import type { ToolPlugin, ToolResult, ToolContext } from "./types.js";
5
5
  import {
6
6
  BASH_TOOL_NAME,
7
- BASH_OUTPUT_TOOL_NAME,
8
- KILL_BASH_TOOL_NAME,
7
+ TASK_OUTPUT_TOOL_NAME,
9
8
  GLOB_TOOL_NAME,
10
9
  GREP_TOOL_NAME,
11
10
  READ_TOOL_NAME,
@@ -89,13 +88,16 @@ Usage notes:
89
88
  },
90
89
  run_in_background: {
91
90
  type: "boolean",
92
- description: `Set to true to run this command in the background. Use ${BASH_OUTPUT_TOOL_NAME} to read the output later.`,
91
+ description: `Set to true to run this command in the background. Use ${TASK_OUTPUT_TOOL_NAME} to read the output later.`,
93
92
  },
94
93
  },
95
94
  required: ["command"],
96
95
  },
97
96
  },
98
97
  },
98
+ prompt: () => `
99
+ - Reserve bash tools exclusively for actual system commands and terminal operations that require shell execution. NEVER use bash echo or other command-line tools to communicate thoughts, explanations, or instructions to the user. Output all communication directly in your response text instead.
100
+ - When making multiple bash tool calls, you MUST send a single message with multiple tools calls to run the calls in parallel. For example, if you need to run "git status" and "git diff", send a single message with two tool calls in parallel.`,
99
101
  execute: async (
100
102
  args: Record<string, unknown>,
101
103
  context: ToolContext,
@@ -164,20 +166,20 @@ Usage notes:
164
166
 
165
167
  if (runInBackground) {
166
168
  // Background execution
167
- const backgroundBashManager = context?.backgroundBashManager;
168
- if (!backgroundBashManager) {
169
+ const backgroundTaskManager = context?.backgroundTaskManager;
170
+ if (!backgroundTaskManager) {
169
171
  return {
170
172
  success: false,
171
173
  content: "",
172
- error: "Background bash manager not available",
174
+ error: "Background task manager not available",
173
175
  };
174
176
  }
175
177
 
176
- const shellId = backgroundBashManager.startShell(command, timeout);
178
+ const { id: taskId } = backgroundTaskManager.startShell(command, timeout);
177
179
  return {
178
180
  success: true,
179
- content: `Command started in background with ID: ${shellId}. Use ${BASH_OUTPUT_TOOL_NAME} tool with bash_id="${shellId}" to monitor output.`,
180
- shortResult: `Background process ${shellId} started`,
181
+ content: `Command started in background with ID: ${taskId}. Use TaskOutput tool with task_id="${taskId}" to monitor output.`,
182
+ shortResult: `Background process ${taskId} started`,
181
183
  };
182
184
  }
183
185
 
@@ -195,6 +197,42 @@ Usage notes:
195
197
  let outputBuffer = "";
196
198
  let errorBuffer = "";
197
199
  let isAborted = false;
200
+ let isBackgrounded = false;
201
+
202
+ const foregroundTaskId = `bash_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
203
+
204
+ // Register as foreground task
205
+ if (context.foregroundTaskManager && command) {
206
+ context.foregroundTaskManager.registerForegroundTask({
207
+ id: foregroundTaskId,
208
+ backgroundHandler: async () => {
209
+ isBackgrounded = true;
210
+ if (timeoutHandle) {
211
+ clearTimeout(timeoutHandle);
212
+ }
213
+
214
+ const backgroundTaskManager = context.backgroundTaskManager;
215
+ if (backgroundTaskManager) {
216
+ const taskId = backgroundTaskManager.adoptProcess(
217
+ child,
218
+ command,
219
+ outputBuffer,
220
+ errorBuffer,
221
+ );
222
+ resolve({
223
+ success: true,
224
+ content: `Command moved to background with ID: ${taskId}.`,
225
+ shortResult: `Process ${taskId} backgrounded`,
226
+ isManuallyBackgrounded: true,
227
+ });
228
+ } else {
229
+ handleAbort(
230
+ "Failed to background: Background task manager not available",
231
+ );
232
+ }
233
+ },
234
+ });
235
+ }
198
236
 
199
237
  // Set up timeout
200
238
  let timeoutHandle: NodeJS.Timeout | undefined;
@@ -267,19 +305,25 @@ Usage notes:
267
305
  }
268
306
 
269
307
  child.stdout?.on("data", (data) => {
270
- if (!isAborted) {
308
+ if (!isAborted && !isBackgrounded) {
271
309
  outputBuffer += stripAnsiColors(data.toString());
272
310
  }
273
311
  });
274
312
 
275
313
  child.stderr?.on("data", (data) => {
276
- if (!isAborted) {
314
+ if (!isAborted && !isBackgrounded) {
277
315
  errorBuffer += stripAnsiColors(data.toString());
278
316
  }
279
317
  });
280
318
 
281
319
  child.on("exit", (code) => {
282
- if (!isAborted) {
320
+ if (context.foregroundTaskManager) {
321
+ context.foregroundTaskManager.unregisterForegroundTask(
322
+ foregroundTaskId,
323
+ );
324
+ }
325
+
326
+ if (!isAborted && !isBackgrounded) {
283
327
  if (timeoutHandle) {
284
328
  clearTimeout(timeoutHandle);
285
329
  }
@@ -309,7 +353,13 @@ Usage notes:
309
353
  });
310
354
 
311
355
  child.on("error", (error) => {
312
- if (!isAborted) {
356
+ if (context.foregroundTaskManager) {
357
+ context.foregroundTaskManager.unregisterForegroundTask(
358
+ foregroundTaskId,
359
+ );
360
+ }
361
+
362
+ if (!isAborted && !isBackgrounded) {
313
363
  if (timeoutHandle) {
314
364
  clearTimeout(timeoutHandle);
315
365
  }
@@ -334,186 +384,3 @@ Usage notes:
334
384
  return `${command}${runInBackground ? " (background)" : ""}`;
335
385
  },
336
386
  };
337
-
338
- /**
339
- * BashOutput tool - retrieves output from background bash shells
340
- */
341
- export const bashOutputTool: ToolPlugin = {
342
- name: BASH_OUTPUT_TOOL_NAME,
343
- config: {
344
- type: "function",
345
- function: {
346
- name: BASH_OUTPUT_TOOL_NAME,
347
- description:
348
- "Retrieves output from a running or completed background bash shell",
349
- parameters: {
350
- type: "object",
351
- properties: {
352
- bash_id: {
353
- type: "string",
354
- description:
355
- "The ID of the background shell to retrieve output from",
356
- },
357
- filter: {
358
- type: "string",
359
- description:
360
- "Optional regular expression to filter the output lines. Only lines matching this regex will be included in the result. Any lines that do not match will no longer be available to read.",
361
- },
362
- },
363
- required: ["bash_id"],
364
- },
365
- },
366
- },
367
- execute: async (
368
- args: Record<string, unknown>,
369
- context: ToolContext,
370
- ): Promise<ToolResult> => {
371
- const bashId = args.bash_id as string;
372
- const filter = args.filter as string | undefined;
373
-
374
- if (!bashId || typeof bashId !== "string") {
375
- return {
376
- success: false,
377
- content: "",
378
- error: "bash_id parameter is required and must be a string",
379
- };
380
- }
381
-
382
- const backgroundBashManager = context?.backgroundBashManager;
383
- if (!backgroundBashManager) {
384
- return {
385
- success: false,
386
- content: "",
387
- error: "Background bash manager not available",
388
- };
389
- }
390
-
391
- const output = backgroundBashManager.getOutput(bashId, filter);
392
- if (!output) {
393
- return {
394
- success: false,
395
- content: "",
396
- error: `Background shell with ID ${bashId} not found`,
397
- };
398
- }
399
-
400
- const shell = backgroundBashManager.getShell(bashId);
401
- if (!shell) {
402
- return {
403
- success: false,
404
- content: "",
405
- error: `Background shell with ID ${bashId} not found`,
406
- };
407
- }
408
-
409
- let content = "";
410
- if (output.stdout) {
411
- content += stripAnsiColors(output.stdout);
412
- }
413
- if (output.stderr) {
414
- content += (content ? "\n" : "") + stripAnsiColors(output.stderr);
415
- }
416
-
417
- const finalContent = content || "No output available";
418
- const processedContent =
419
- finalContent.length > MAX_OUTPUT_LENGTH
420
- ? finalContent.substring(0, MAX_OUTPUT_LENGTH) +
421
- "\n\n... (output truncated)"
422
- : finalContent;
423
-
424
- return {
425
- success: true,
426
- content: processedContent,
427
- shortResult: `${bashId}: ${output.status}${shell.exitCode !== undefined ? ` (${shell.exitCode})` : ""}`,
428
- error: undefined,
429
- };
430
- },
431
- formatCompactParams: (params: Record<string, unknown>) => {
432
- const bashId = params.bash_id as string;
433
- const filter = params.filter as string | undefined;
434
- return filter ? `${bashId} filtered: ${filter}` : bashId;
435
- },
436
- };
437
-
438
- /**
439
- * KillBash tool - kills a running background bash shell
440
- */
441
- export const killBashTool: ToolPlugin = {
442
- name: KILL_BASH_TOOL_NAME,
443
- config: {
444
- type: "function",
445
- function: {
446
- name: KILL_BASH_TOOL_NAME,
447
- description: "Kills a running background bash shell by its ID",
448
- parameters: {
449
- type: "object",
450
- properties: {
451
- shell_id: {
452
- type: "string",
453
- description: "The ID of the background shell to kill",
454
- },
455
- },
456
- required: ["shell_id"],
457
- },
458
- },
459
- },
460
- execute: async (
461
- args: Record<string, unknown>,
462
- context: ToolContext,
463
- ): Promise<ToolResult> => {
464
- const shellId = args.shell_id as string;
465
-
466
- if (!shellId || typeof shellId !== "string") {
467
- return {
468
- success: false,
469
- content: "",
470
- error: "shell_id parameter is required and must be a string",
471
- };
472
- }
473
-
474
- const backgroundBashManager = context?.backgroundBashManager;
475
- if (!backgroundBashManager) {
476
- return {
477
- success: false,
478
- content: "",
479
- error: "Background bash manager not available",
480
- };
481
- }
482
-
483
- const shell = backgroundBashManager.getShell(shellId);
484
- if (!shell) {
485
- return {
486
- success: false,
487
- content: "",
488
- error: `Background shell with ID ${shellId} not found`,
489
- };
490
- }
491
-
492
- if (shell.status !== "running") {
493
- return {
494
- success: false,
495
- content: "",
496
- error: `Background shell ${shellId} is not running (status: ${shell.status})`,
497
- };
498
- }
499
-
500
- const killed = backgroundBashManager.killShell(shellId);
501
- if (killed) {
502
- return {
503
- success: true,
504
- content: `Background shell ${shellId} has been killed`,
505
- shortResult: `Killed ${shellId}`,
506
- };
507
- } else {
508
- return {
509
- success: false,
510
- content: "",
511
- error: `Failed to kill background shell ${shellId}`,
512
- };
513
- }
514
- },
515
- formatCompactParams: (params: Record<string, unknown>) => {
516
- const shellId = params.shell_id as string;
517
- return shellId;
518
- },
519
- };
@@ -2,11 +2,7 @@ import { readFile, writeFile } from "fs/promises";
2
2
  import { logger } from "../utils/globalLogger.js";
3
3
  import type { ToolPlugin, ToolResult, ToolContext } from "./types.js";
4
4
  import { resolvePath, getDisplayPath } from "../utils/path.js";
5
- import {
6
- findIndentationInsensitiveMatch,
7
- escapeRegExp,
8
- saveEditErrorSnapshot,
9
- } from "../utils/editUtils.js";
5
+ import { escapeRegExp, analyzeEditMismatch } from "../utils/editUtils.js";
10
6
  import { EDIT_TOOL_NAME, READ_TOOL_NAME } from "../constants/tools.js";
11
7
 
12
8
  /**
@@ -26,11 +22,13 @@ function formatCompactParams(
26
22
  export const editTool: ToolPlugin = {
27
23
  name: EDIT_TOOL_NAME,
28
24
  formatCompactParams,
25
+ prompt: () =>
26
+ `Performs exact string replacements in files. \n\nUsage:\n- You must use your \`${READ_TOOL_NAME}\` tool at least once in the conversation before editing. This tool will error if you attempt an edit without reading the file. \n- When editing text from read_file tool output, ensure you preserve the exact indentation (tabs/spaces) as it appears AFTER the line number prefix. The line number prefix format is: spaces + line number + tab. Everything after that tab is the actual file content to match. Never include any part of the line number prefix in the old_string or new_string.\n- ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required.\n- Only use emojis if the user explicitly requests it. Avoid adding emojis to files unless asked.\n- The edit will FAIL if \`old_string\` is not unique in the file. Either provide a larger string with more surrounding context to make it unique or use \`replace_all\` to change every instance of \`old_string\`. \n- Use \`replace_all\` for replacing and renaming strings across the file. This parameter is useful if you want to rename a variable for instance.`,
29
27
  config: {
30
28
  type: "function",
31
29
  function: {
32
30
  name: EDIT_TOOL_NAME,
33
- description: `Performs exact string replacements in files. \n\nUsage:\n- You must use your \`${READ_TOOL_NAME}\` tool at least once in the conversation before editing. This tool will error if you attempt an edit without reading the file. \n- When editing text from read_file tool output, ensure you preserve the exact indentation (tabs/spaces) as it appears AFTER the line number prefix. The line number prefix format is: spaces + line number + tab. Everything after that tab is the actual file content to match. Never include any part of the line number prefix in the old_string or new_string.\n- ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required.\n- Only use emojis if the user explicitly requests it. Avoid adding emojis to files unless asked.\n- The edit will FAIL if \`old_string\` is not unique in the file. Either provide a larger string with more surrounding context to make it unique or use \`replace_all\` to change every instance of \`old_string\`. \n- Use \`replace_all\` for replacing and renaming strings across the file. This parameter is useful if you want to rename a variable for instance.`,
31
+ description: "A tool for editing files",
34
32
  parameters: {
35
33
  type: "object",
36
34
  properties: {
@@ -115,23 +113,16 @@ export const editTool: ToolPlugin = {
115
113
  };
116
114
  }
117
115
 
118
- // Check if old_string exists (with smart indentation matching)
119
- const matchedOldString = findIndentationInsensitiveMatch(
120
- originalContent,
121
- oldString,
122
- );
116
+ // Check if old_string exists
117
+ const matchedOldString = originalContent.includes(oldString)
118
+ ? oldString
119
+ : null;
123
120
 
124
121
  if (!matchedOldString) {
125
- await saveEditErrorSnapshot(
126
- resolvedPath,
127
- oldString,
128
- originalContent,
129
- EDIT_TOOL_NAME,
130
- );
131
122
  return {
132
123
  success: false,
133
124
  content: "",
134
- error: `old_string not found in file`,
125
+ error: analyzeEditMismatch(originalContent, oldString),
135
126
  };
136
127
  }
137
128
 
@@ -12,8 +12,7 @@ export const exitPlanModeTool: ToolPlugin = {
12
12
  type: "function",
13
13
  function: {
14
14
  name: EXIT_PLAN_MODE_TOOL_NAME,
15
- description:
16
- "Use this tool when you are in plan mode and have finished writing your plan to the plan file and are ready for user approval. This tool will read the plan from the file specified in the system message and present it to the user for confirmation. You should have already written your plan to that file before calling this tool.",
15
+ description: "Prompts the user to exit plan mode and start coding",
17
16
  parameters: {
18
17
  type: "object",
19
18
  properties: {},
@@ -22,6 +21,31 @@ export const exitPlanModeTool: ToolPlugin = {
22
21
  },
23
22
  },
24
23
  },
24
+ prompt:
25
+ () => `Use this tool when you are in plan mode and have finished writing your plan to the plan file and are ready for user approval.
26
+
27
+ ## How This Tool Works
28
+ - You should have already written your plan to the plan file specified in the plan mode system message
29
+ - This tool does NOT take the plan content as a parameter - it will read the plan from the file you wrote
30
+ - This tool simply signals that you're done planning and ready for the user to review and approve
31
+ - The user will see the contents of your plan file when they review it
32
+
33
+ ## When to Use This Tool
34
+ IMPORTANT: Only use this tool when the task requires planning the implementation steps of a task that requires writing code. For research tasks where you're gathering information, searching files, reading files or in general trying to understand the codebase - do NOT use this tool.
35
+
36
+ ## Before Using This Tool
37
+ Ensure your plan is complete and unambiguous:
38
+ - If you have unresolved questions about requirements or approach, use AskUserQuestion first (in earlier phases)
39
+ - Once your plan is finalized, use THIS tool to request approval
40
+
41
+ **Important:** Do NOT use AskUserQuestion to ask "Is this plan okay?" or "Should I proceed?" - that's exactly what THIS tool does. ExitPlanMode inherently requests user approval of your plan.
42
+
43
+ ## Examples
44
+
45
+ 1. Initial task: "Search for and understand the implementation of vim mode in the codebase" - Do not use the exit plan mode tool because you are not planning the implementation steps of a task.
46
+ 2. Initial task: "Help me implement yank mode for vim" - Use the exit plan mode tool after you have finished planning the implementation steps of the task.
47
+ 3. Initial task: "Add a new feature to handle user authentication" - If unsure about auth method (OAuth, JWT, etc.), use AskUserQuestion first, then use exit plan mode tool after clarifying the approach.
48
+ `,
25
49
  execute: async (
26
50
  _args: Record<string, unknown>,
27
51
  context: ToolContext,
@@ -3,7 +3,7 @@ import { stat } from "fs/promises";
3
3
  import type { ToolPlugin, ToolResult, ToolContext } from "./types.js";
4
4
  import { resolvePath, getDisplayPath } from "../utils/path.js";
5
5
  import { getGlobIgnorePatterns } from "../utils/fileFilter.js";
6
- import { GLOB_TOOL_NAME, TASK_TOOL_NAME } from "../constants/tools.js";
6
+ import { GLOB_TOOL_NAME } from "../constants/tools.js";
7
7
 
8
8
  /**
9
9
  * Glob Tool Plugin - Fast file pattern matching
@@ -14,7 +14,8 @@ export const globTool: ToolPlugin = {
14
14
  type: "function",
15
15
  function: {
16
16
  name: GLOB_TOOL_NAME,
17
- description: `- Fast file pattern matching tool that works with any codebase size\n- Supports glob patterns like "**/*.js" or "src/**/*.ts"\n- Returns matching file paths sorted by modification time\n- Use this tool when you need to find files by name patterns\n- When you are doing an open ended search that may require multiple rounds of globbing and grepping, use the ${TASK_TOOL_NAME} tool instead\n- You have the capability to call multiple tools in a single response. It is always better to speculatively perform multiple searches as a batch that are potentially useful.`,
17
+ description:
18
+ "Fast file pattern matching tool that works with any codebase size",
18
19
  parameters: {
19
20
  type: "object",
20
21
  properties: {
@@ -32,6 +33,13 @@ export const globTool: ToolPlugin = {
32
33
  },
33
34
  },
34
35
  },
36
+ prompt:
37
+ () => `- Fast file pattern matching tool that works with any codebase size
38
+ - Supports glob patterns like "**/*.js" or "src/**/*.ts"
39
+ - Returns matching file paths sorted by modification time
40
+ - Use this tool when you need to find files by name patterns
41
+ - When you are doing an open ended search that may require multiple rounds of globbing and grepping, use the Agent tool instead
42
+ - You can call multiple tools in a single response. It is always better to speculatively perform multiple searches in parallel if they are potentially useful.`,
35
43
  execute: async (
36
44
  args: Record<string, unknown>,
37
45
  context: ToolContext,
@@ -18,7 +18,7 @@ export const grepTool: ToolPlugin = {
18
18
  type: "function",
19
19
  function: {
20
20
  name: GREP_TOOL_NAME,
21
- description: `A powerful search tool built on ripgrep\n\n Usage:\n - ALWAYS use ${GREP_TOOL_NAME} for search tasks. NEVER invoke \`grep\` or \`rg\` as a ${BASH_TOOL_NAME} command. The ${GREP_TOOL_NAME} tool has been optimized for correct permissions and access.\n - Supports full regex syntax (e.g., "log.*Error", "function\\s+\\w+")\n - Filter files with glob parameter (e.g., "*.js", "**/*.tsx") or type parameter (e.g., "js", "py", "rust")\n - Output modes: "content" shows matching lines, "files_with_matches" shows only file paths (default), "count" shows match counts\n - Use ${TASK_TOOL_NAME} tool for open-ended searches requiring multiple rounds\n - Pattern syntax: Uses ripgrep (not grep) - literal braces need escaping (use \`interface\\{\\}\` to find \`interface{}\` in Go code)\n - Multiline matching: By default patterns match within single lines only. For cross-line patterns like \`struct \\{[\\s\\S]*?field\`, use \`multiline: true\``,
21
+ description: "A powerful search tool built on ripgrep",
22
22
  parameters: {
23
23
  type: "object",
24
24
  properties: {
@@ -61,7 +61,7 @@ export const grepTool: ToolPlugin = {
61
61
  "-n": {
62
62
  type: "boolean",
63
63
  description:
64
- 'Show line numbers in output (rg -n). Requires output_mode: "content", ignored otherwise.',
64
+ 'Show line numbers in output (rg -n). Requires output_mode: "content", ignored otherwise. Defaults to true.',
65
65
  },
66
66
  "-i": {
67
67
  type: "boolean",
@@ -75,7 +75,7 @@ export const grepTool: ToolPlugin = {
75
75
  head_limit: {
76
76
  type: "number",
77
77
  description:
78
- 'Limit output to first N lines/entries, equivalent to "| head -N". Works across all output modes: content (limits output lines), files_with_matches (limits file paths), count (limits count entries). Defaults to 100 to prevent excessive token usage.',
78
+ 'Limit output to first N lines/entries, equivalent to "| head -N". Works across all output modes: content (limits output lines), files_with_matches (limits file paths), count (limits count entries). Defaults to 0 (unlimited).',
79
79
  },
80
80
  multiline: {
81
81
  type: "boolean",
@@ -87,6 +87,17 @@ export const grepTool: ToolPlugin = {
87
87
  },
88
88
  },
89
89
  },
90
+ prompt: () => `A powerful search tool built on ripgrep
91
+
92
+ Usage:
93
+ - ALWAYS use ${GREP_TOOL_NAME} for search tasks. NEVER invoke \`grep\` or \`rg\` as a ${BASH_TOOL_NAME} command. The ${GREP_TOOL_NAME} tool has been optimized for correct permissions and access.
94
+ - Supports full regex syntax (e.g., "log.*Error", "function\\s+\\w+")
95
+ - Filter files with glob parameter (e.g., "*.js", "**/*.tsx") or type parameter (e.g., "js", "py", "rust")
96
+ - Output modes: "content" shows matching lines, "files_with_matches" shows only file paths (default), "count" shows match counts
97
+ - Use ${TASK_TOOL_NAME} tool for open-ended searches requiring multiple rounds
98
+ - Pattern syntax: Uses ripgrep (not grep) - literal braces need escaping (use \`interface\\{\\}\` to find \`interface{}\` in Go code)
99
+ - Multiline matching: By default patterns match within single lines only. For cross-line patterns like \`struct \\{[\\s\\S]*?field\`, use \`multiline: true\`
100
+ `,
90
101
  execute: async (
91
102
  args: Record<string, unknown>,
92
103
  context: ToolContext,
@@ -98,7 +109,7 @@ export const grepTool: ToolPlugin = {
98
109
  const contextBefore = args["-B"] as number;
99
110
  const contextAfter = args["-A"] as number;
100
111
  const contextAround = args["-C"] as number;
101
- const showLineNumbers = args["-n"] as boolean;
112
+ const showLineNumbers = args["-n"] !== false;
102
113
  const caseInsensitive = args["-i"] as boolean;
103
114
  const fileType = args.type as string;
104
115
  const headLimit = args.head_limit as number;
@@ -218,9 +229,9 @@ export const grepTool: ToolPlugin = {
218
229
  let lines = output.split("\n");
219
230
 
220
231
  // Set default head_limit if not specified to prevent excessive token usage
221
- const effectiveHeadLimit = headLimit || 100;
232
+ const effectiveHeadLimit = headLimit || 0;
222
233
 
223
- if (lines.length > effectiveHeadLimit) {
234
+ if (effectiveHeadLimit > 0 && lines.length > effectiveHeadLimit) {
224
235
  lines = lines.slice(0, effectiveHeadLimit);
225
236
  finalOutput = lines.join("\n");
226
237
  }