wave-agent-sdk 0.0.8 → 0.0.11

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 (236) hide show
  1. package/dist/agent.d.ts +92 -23
  2. package/dist/agent.d.ts.map +1 -1
  3. package/dist/agent.js +351 -137
  4. package/dist/index.d.ts +3 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +3 -0
  7. package/dist/managers/aiManager.d.ts +14 -36
  8. package/dist/managers/aiManager.d.ts.map +1 -1
  9. package/dist/managers/aiManager.js +74 -77
  10. package/dist/managers/backgroundBashManager.d.ts.map +1 -1
  11. package/dist/managers/backgroundBashManager.js +4 -3
  12. package/dist/managers/hookManager.d.ts +3 -8
  13. package/dist/managers/hookManager.d.ts.map +1 -1
  14. package/dist/managers/hookManager.js +39 -29
  15. package/dist/managers/liveConfigManager.d.ts +55 -18
  16. package/dist/managers/liveConfigManager.d.ts.map +1 -1
  17. package/dist/managers/liveConfigManager.js +372 -90
  18. package/dist/managers/lspManager.d.ts +43 -0
  19. package/dist/managers/lspManager.d.ts.map +1 -0
  20. package/dist/managers/lspManager.js +326 -0
  21. package/dist/managers/messageManager.d.ts +8 -16
  22. package/dist/managers/messageManager.d.ts.map +1 -1
  23. package/dist/managers/messageManager.js +52 -74
  24. package/dist/managers/permissionManager.d.ts +75 -0
  25. package/dist/managers/permissionManager.d.ts.map +1 -0
  26. package/dist/managers/permissionManager.js +368 -0
  27. package/dist/managers/skillManager.d.ts +1 -0
  28. package/dist/managers/skillManager.d.ts.map +1 -1
  29. package/dist/managers/skillManager.js +2 -1
  30. package/dist/managers/slashCommandManager.d.ts.map +1 -1
  31. package/dist/managers/slashCommandManager.js +0 -1
  32. package/dist/managers/subagentManager.d.ts +8 -23
  33. package/dist/managers/subagentManager.d.ts.map +1 -1
  34. package/dist/managers/subagentManager.js +97 -117
  35. package/dist/managers/toolManager.d.ts +38 -1
  36. package/dist/managers/toolManager.d.ts.map +1 -1
  37. package/dist/managers/toolManager.js +66 -2
  38. package/dist/services/aiService.d.ts +3 -1
  39. package/dist/services/aiService.d.ts.map +1 -1
  40. package/dist/services/aiService.js +123 -30
  41. package/dist/services/configurationService.d.ts +116 -0
  42. package/dist/services/configurationService.d.ts.map +1 -0
  43. package/dist/services/configurationService.js +585 -0
  44. package/dist/services/fileWatcher.d.ts.map +1 -1
  45. package/dist/services/fileWatcher.js +5 -6
  46. package/dist/services/hook.d.ts +7 -124
  47. package/dist/services/hook.d.ts.map +1 -1
  48. package/dist/services/hook.js +46 -458
  49. package/dist/services/jsonlHandler.d.ts +24 -15
  50. package/dist/services/jsonlHandler.d.ts.map +1 -1
  51. package/dist/services/jsonlHandler.js +67 -88
  52. package/dist/services/memory.d.ts +0 -9
  53. package/dist/services/memory.d.ts.map +1 -1
  54. package/dist/services/memory.js +2 -49
  55. package/dist/services/session.d.ts +82 -33
  56. package/dist/services/session.d.ts.map +1 -1
  57. package/dist/services/session.js +275 -181
  58. package/dist/tools/bashTool.d.ts.map +1 -1
  59. package/dist/tools/bashTool.js +109 -11
  60. package/dist/tools/deleteFileTool.d.ts.map +1 -1
  61. package/dist/tools/deleteFileTool.js +25 -0
  62. package/dist/tools/editTool.d.ts.map +1 -1
  63. package/dist/tools/editTool.js +30 -6
  64. package/dist/tools/lspTool.d.ts +6 -0
  65. package/dist/tools/lspTool.d.ts.map +1 -0
  66. package/dist/tools/lspTool.js +589 -0
  67. package/dist/tools/multiEditTool.d.ts.map +1 -1
  68. package/dist/tools/multiEditTool.js +26 -7
  69. package/dist/tools/readTool.d.ts.map +1 -1
  70. package/dist/tools/readTool.js +111 -2
  71. package/dist/tools/skillTool.js +2 -2
  72. package/dist/tools/todoWriteTool.d.ts.map +1 -1
  73. package/dist/tools/todoWriteTool.js +23 -0
  74. package/dist/tools/types.d.ts +11 -8
  75. package/dist/tools/types.d.ts.map +1 -1
  76. package/dist/tools/writeTool.d.ts.map +1 -1
  77. package/dist/tools/writeTool.js +25 -9
  78. package/dist/types/commands.d.ts +0 -1
  79. package/dist/types/commands.d.ts.map +1 -1
  80. package/dist/types/config.d.ts +4 -0
  81. package/dist/types/config.d.ts.map +1 -1
  82. package/dist/types/configuration.d.ts +69 -0
  83. package/dist/types/configuration.d.ts.map +1 -0
  84. package/dist/types/configuration.js +8 -0
  85. package/dist/types/core.d.ts +10 -0
  86. package/dist/types/core.d.ts.map +1 -1
  87. package/dist/types/environment.d.ts +41 -0
  88. package/dist/types/environment.d.ts.map +1 -1
  89. package/dist/types/fileSearch.d.ts +5 -0
  90. package/dist/types/fileSearch.d.ts.map +1 -0
  91. package/dist/types/fileSearch.js +1 -0
  92. package/dist/types/hooks.d.ts +11 -2
  93. package/dist/types/hooks.d.ts.map +1 -1
  94. package/dist/types/hooks.js +1 -7
  95. package/dist/types/index.d.ts +5 -0
  96. package/dist/types/index.d.ts.map +1 -1
  97. package/dist/types/index.js +5 -0
  98. package/dist/types/lsp.d.ts +90 -0
  99. package/dist/types/lsp.d.ts.map +1 -0
  100. package/dist/types/lsp.js +4 -0
  101. package/dist/types/messaging.d.ts +6 -11
  102. package/dist/types/messaging.d.ts.map +1 -1
  103. package/dist/types/permissions.d.ts +39 -0
  104. package/dist/types/permissions.d.ts.map +1 -0
  105. package/dist/types/permissions.js +12 -0
  106. package/dist/types/session.d.ts +1 -6
  107. package/dist/types/session.d.ts.map +1 -1
  108. package/dist/types/skills.d.ts +1 -0
  109. package/dist/types/skills.d.ts.map +1 -1
  110. package/dist/types/tools.d.ts +35 -0
  111. package/dist/types/tools.d.ts.map +1 -0
  112. package/dist/types/tools.js +4 -0
  113. package/dist/utils/abortUtils.d.ts +34 -0
  114. package/dist/utils/abortUtils.d.ts.map +1 -0
  115. package/dist/utils/abortUtils.js +92 -0
  116. package/dist/utils/bashHistory.d.ts +4 -0
  117. package/dist/utils/bashHistory.d.ts.map +1 -1
  118. package/dist/utils/bashHistory.js +21 -4
  119. package/dist/utils/bashParser.d.ts +24 -0
  120. package/dist/utils/bashParser.d.ts.map +1 -0
  121. package/dist/utils/bashParser.js +413 -0
  122. package/dist/utils/builtinSubagents.d.ts +7 -0
  123. package/dist/utils/builtinSubagents.d.ts.map +1 -0
  124. package/dist/utils/builtinSubagents.js +65 -0
  125. package/dist/utils/cacheControlUtils.d.ts +8 -33
  126. package/dist/utils/cacheControlUtils.d.ts.map +1 -1
  127. package/dist/utils/cacheControlUtils.js +83 -126
  128. package/dist/utils/constants.d.ts +0 -12
  129. package/dist/utils/constants.d.ts.map +1 -1
  130. package/dist/utils/constants.js +1 -13
  131. package/dist/utils/convertMessagesForAPI.d.ts +2 -1
  132. package/dist/utils/convertMessagesForAPI.d.ts.map +1 -1
  133. package/dist/utils/convertMessagesForAPI.js +33 -14
  134. package/dist/utils/fileSearch.d.ts +14 -0
  135. package/dist/utils/fileSearch.d.ts.map +1 -0
  136. package/dist/utils/fileSearch.js +88 -0
  137. package/dist/utils/fileUtils.d.ts +14 -2
  138. package/dist/utils/fileUtils.d.ts.map +1 -1
  139. package/dist/utils/fileUtils.js +101 -17
  140. package/dist/utils/globalLogger.d.ts +0 -14
  141. package/dist/utils/globalLogger.d.ts.map +1 -1
  142. package/dist/utils/globalLogger.js +0 -16
  143. package/dist/utils/markdownParser.d.ts.map +1 -1
  144. package/dist/utils/markdownParser.js +1 -17
  145. package/dist/utils/messageOperations.d.ts +1 -11
  146. package/dist/utils/messageOperations.d.ts.map +1 -1
  147. package/dist/utils/messageOperations.js +7 -24
  148. package/dist/utils/pathEncoder.d.ts +4 -0
  149. package/dist/utils/pathEncoder.d.ts.map +1 -1
  150. package/dist/utils/pathEncoder.js +16 -9
  151. package/dist/utils/pathSafety.d.ts +10 -0
  152. package/dist/utils/pathSafety.d.ts.map +1 -0
  153. package/dist/utils/pathSafety.js +23 -0
  154. package/dist/utils/subagentParser.d.ts +2 -2
  155. package/dist/utils/subagentParser.d.ts.map +1 -1
  156. package/dist/utils/subagentParser.js +10 -7
  157. package/package.json +9 -9
  158. package/src/agent.ts +475 -216
  159. package/src/index.ts +3 -0
  160. package/src/managers/aiManager.ts +107 -111
  161. package/src/managers/backgroundBashManager.ts +4 -3
  162. package/src/managers/hookManager.ts +44 -39
  163. package/src/managers/liveConfigManager.ts +524 -138
  164. package/src/managers/lspManager.ts +434 -0
  165. package/src/managers/messageManager.ts +73 -103
  166. package/src/managers/permissionManager.ts +480 -0
  167. package/src/managers/skillManager.ts +3 -1
  168. package/src/managers/slashCommandManager.ts +1 -2
  169. package/src/managers/subagentManager.ts +116 -159
  170. package/src/managers/toolManager.ts +95 -3
  171. package/src/services/aiService.ts +207 -26
  172. package/src/services/configurationService.ts +762 -0
  173. package/src/services/fileWatcher.ts +5 -6
  174. package/src/services/hook.ts +50 -631
  175. package/src/services/jsonlHandler.ts +84 -100
  176. package/src/services/memory.ts +2 -59
  177. package/src/services/session.ts +338 -213
  178. package/src/tools/bashTool.ts +126 -13
  179. package/src/tools/deleteFileTool.ts +36 -0
  180. package/src/tools/editTool.ts +41 -7
  181. package/src/tools/lspTool.ts +760 -0
  182. package/src/tools/multiEditTool.ts +37 -8
  183. package/src/tools/readTool.ts +125 -2
  184. package/src/tools/skillTool.ts +2 -2
  185. package/src/tools/todoWriteTool.ts +33 -1
  186. package/src/tools/types.ts +15 -9
  187. package/src/tools/writeTool.ts +36 -10
  188. package/src/types/commands.ts +0 -1
  189. package/src/types/config.ts +5 -0
  190. package/src/types/configuration.ts +73 -0
  191. package/src/types/core.ts +11 -0
  192. package/src/types/environment.ts +44 -0
  193. package/src/types/fileSearch.ts +4 -0
  194. package/src/types/hooks.ts +14 -11
  195. package/src/types/index.ts +5 -0
  196. package/src/types/lsp.ts +96 -0
  197. package/src/types/messaging.ts +8 -13
  198. package/src/types/permissions.ts +52 -0
  199. package/src/types/session.ts +3 -8
  200. package/src/types/skills.ts +1 -0
  201. package/src/types/tools.ts +38 -0
  202. package/src/utils/abortUtils.ts +118 -0
  203. package/src/utils/bashHistory.ts +28 -4
  204. package/src/utils/bashParser.ts +444 -0
  205. package/src/utils/builtinSubagents.ts +71 -0
  206. package/src/utils/cacheControlUtils.ts +106 -171
  207. package/src/utils/constants.ts +1 -16
  208. package/src/utils/convertMessagesForAPI.ts +38 -14
  209. package/src/utils/fileSearch.ts +107 -0
  210. package/src/utils/fileUtils.ts +114 -19
  211. package/src/utils/globalLogger.ts +0 -17
  212. package/src/utils/markdownParser.ts +1 -19
  213. package/src/utils/messageOperations.ts +7 -35
  214. package/src/utils/pathEncoder.ts +24 -9
  215. package/src/utils/pathSafety.ts +26 -0
  216. package/src/utils/subagentParser.ts +11 -8
  217. package/dist/constants/events.d.ts +0 -28
  218. package/dist/constants/events.d.ts.map +0 -1
  219. package/dist/constants/events.js +0 -27
  220. package/dist/services/configurationWatcher.d.ts +0 -120
  221. package/dist/services/configurationWatcher.d.ts.map +0 -1
  222. package/dist/services/configurationWatcher.js +0 -439
  223. package/dist/services/memoryStore.d.ts +0 -81
  224. package/dist/services/memoryStore.d.ts.map +0 -1
  225. package/dist/services/memoryStore.js +0 -200
  226. package/dist/types/memoryStore.d.ts +0 -82
  227. package/dist/types/memoryStore.d.ts.map +0 -1
  228. package/dist/types/memoryStore.js +0 -7
  229. package/dist/utils/configResolver.d.ts +0 -65
  230. package/dist/utils/configResolver.d.ts.map +0 -1
  231. package/dist/utils/configResolver.js +0 -210
  232. package/src/constants/events.ts +0 -38
  233. package/src/services/configurationWatcher.ts +0 -622
  234. package/src/services/memoryStore.ts +0 -279
  235. package/src/types/memoryStore.ts +0 -94
  236. package/src/utils/configResolver.ts +0 -302
@@ -1,7 +1,11 @@
1
1
  import { spawn, ChildProcess } from "child_process";
2
2
  import { logger } from "../utils/globalLogger.js";
3
+ import { stripAnsiColors } from "../utils/stringUtils.js";
3
4
  import type { ToolPlugin, ToolResult, ToolContext } from "./types.js";
4
5
 
6
+ const MAX_OUTPUT_LENGTH = 30000;
7
+ const BASH_DEFAULT_TIMEOUT_MS = 120000;
8
+
5
9
  /**
6
10
  * Bash command execution tool - supports both foreground and background execution
7
11
  */
@@ -11,8 +15,52 @@ export const bashTool: ToolPlugin = {
11
15
  type: "function",
12
16
  function: {
13
17
  name: "Bash",
14
- description:
15
- "Executes a given bash command in a persistent shell session with optional timeout, ensuring proper handling and security measures.",
18
+ description: `Executes a given bash command in a persistent shell session with optional timeout, ensuring proper handling and security measures.
19
+
20
+ IMPORTANT: This tool is for terminal operations like git, npm, docker, etc. DO NOT use it for file operations (reading, writing, editing, searching, finding files) - use the specialized tools for this instead.
21
+
22
+ Before executing the command, please follow these steps:
23
+
24
+ 1. Directory Verification:
25
+ - If the command will create new directories or files, first use \`ls\` to verify the parent directory exists and is the correct location
26
+ - For example, before running "mkdir foo/bar", first use \`ls foo\` to check that "foo" exists and is the intended parent directory
27
+
28
+ 2. Command Execution:
29
+ - Always quote file paths that contain spaces with double quotes (e.g., cd "path with spaces/file.txt")
30
+ - Examples of proper quoting:
31
+ - cd "/Users/name/My Documents" (correct)
32
+ - cd /Users/name/My Documents (incorrect - will fail)
33
+ - python "/path/with spaces/script.py" (correct)
34
+ - python /path/with spaces/script.py (incorrect - will fail)
35
+ - After ensuring proper quoting, execute the command.
36
+ - Capture the output of the command.
37
+
38
+ Usage notes:
39
+ - The command argument is required.
40
+ - You can specify an optional timeout in milliseconds (up to ${BASH_DEFAULT_TIMEOUT_MS}ms / ${BASH_DEFAULT_TIMEOUT_MS / 60000} minutes). If not specified, commands will timeout after ${BASH_DEFAULT_TIMEOUT_MS}ms (${BASH_DEFAULT_TIMEOUT_MS / 60000} minutes).
41
+ - It is very helpful if you write a clear, concise description of what this command does in 5-10 words.
42
+ - If the output exceeds ${MAX_OUTPUT_LENGTH} characters, output will be truncated before being returned to you.
43
+ - You can use the \`run_in_background\` parameter to run the command in the background, which allows you to continue working while the command runs. You can monitor the output using the Bash tool as it becomes available. You do not need to use '&' at the end of the command when using this parameter.
44
+ - Avoid using Bash with the \`find\`, \`grep\`, \`cat\`, \`head\`, \`tail\`, \`sed\`, \`awk\`, or \`echo\` commands, unless explicitly instructed or when these commands are truly necessary for the task. Instead, always prefer using the dedicated tools for these commands:
45
+ - File search: Use Glob (NOT find or ls)
46
+ - Content search: Use Grep (NOT grep or rg)
47
+ - Read files: Use Read (NOT cat/head/tail)
48
+ - Edit files: Use Edit (NOT sed/awk)
49
+ - Write files: Use Write (NOT echo >/cat <<EOF)
50
+ - Communication: Output text directly (NOT echo/printf)
51
+ - When issuing multiple commands:
52
+ - If the commands are independent and can run in parallel, make multiple Bash tool calls in a single message. For example, if you need to run "git status" and "git diff", send a single message with two Bash tool calls in parallel.
53
+ - If the commands depend on each other and must run sequentially, use a single Bash call with '&&' to chain them together (e.g., \`git add . && git commit -m "message" && git push\`). For instance, if one operation must complete before another starts (like mkdir before cp, Write before Bash for git operations, or git add before git commit), run these operations sequentially instead.
54
+ - Use ';' only when you need to run commands sequentially but don't care if earlier commands fail
55
+ - DO NOT use newlines to separate commands (newlines are ok in quoted strings)
56
+ - Try to maintain your current working directory throughout the session by using absolute paths and avoiding usage of \`cd\`. You may use \`cd\` if the User explicitly requests it.
57
+ <good-example>
58
+ pytest /foo/bar/tests
59
+ </good-example>
60
+ <bad-example>
61
+ cd /foo/bar && pytest tests
62
+ </bad-example>
63
+ `,
16
64
  parameters: {
17
65
  type: "object",
18
66
  properties: {
@@ -45,10 +93,11 @@ export const bashTool: ToolPlugin = {
45
93
  ): Promise<ToolResult> => {
46
94
  const command = args.command as string;
47
95
  const runInBackground = args.run_in_background as boolean | undefined;
48
- // Set default timeout: 60s for foreground, no timeout for background
96
+ const description = args.description as string | undefined;
97
+ // Set default timeout: BASH_DEFAULT_TIMEOUT_MS for foreground, no timeout for background
49
98
  const timeout =
50
99
  (args.timeout as number | undefined) ??
51
- (runInBackground ? undefined : 60000);
100
+ (runInBackground ? undefined : BASH_DEFAULT_TIMEOUT_MS);
52
101
 
53
102
  if (!command || typeof command !== "string") {
54
103
  return {
@@ -70,6 +119,46 @@ export const bashTool: ToolPlugin = {
70
119
  };
71
120
  }
72
121
 
122
+ // Permission check after validation but before real operation
123
+ if (
124
+ context.permissionManager &&
125
+ context.permissionMode &&
126
+ context.permissionMode !== "bypassPermissions"
127
+ ) {
128
+ if (context.permissionManager.isRestrictedTool("Bash")) {
129
+ try {
130
+ const permissionContext = context.permissionManager.createContext(
131
+ "Bash",
132
+ context.permissionMode,
133
+ context.canUseToolCallback,
134
+ {
135
+ command,
136
+ description,
137
+ run_in_background: runInBackground,
138
+ timeout,
139
+ workdir: context.workdir,
140
+ },
141
+ );
142
+ const permissionResult =
143
+ await context.permissionManager.checkPermission(permissionContext);
144
+
145
+ if (permissionResult.behavior === "deny") {
146
+ return {
147
+ success: false,
148
+ content: "",
149
+ error: `Bash operation denied by user, reason: ${permissionResult.message || "No reason provided"}`,
150
+ };
151
+ }
152
+ } catch {
153
+ return {
154
+ success: false,
155
+ content: "",
156
+ error: "Permission check failed",
157
+ };
158
+ }
159
+ }
160
+ }
161
+
73
162
  if (runInBackground) {
74
163
  // Background execution
75
164
  const backgroundBashManager = context?.backgroundBashManager;
@@ -168,18 +257,21 @@ export const bashTool: ToolPlugin = {
168
257
  handleAbort();
169
258
  return;
170
259
  }
171
- context.abortSignal.addEventListener("abort", () => handleAbort());
260
+ // Use { once: true } to prevent listener accumulation on signal reuse
261
+ context.abortSignal.addEventListener("abort", () => handleAbort(), {
262
+ once: true,
263
+ });
172
264
  }
173
265
 
174
266
  child.stdout?.on("data", (data) => {
175
267
  if (!isAborted) {
176
- outputBuffer += data.toString();
268
+ outputBuffer += stripAnsiColors(data.toString());
177
269
  }
178
270
  });
179
271
 
180
272
  child.stderr?.on("data", (data) => {
181
273
  if (!isAborted) {
182
- errorBuffer += data.toString();
274
+ errorBuffer += stripAnsiColors(data.toString());
183
275
  }
184
276
  });
185
277
 
@@ -193,10 +285,18 @@ export const bashTool: ToolPlugin = {
193
285
  const combinedOutput =
194
286
  outputBuffer + (errorBuffer ? "\n" + errorBuffer : "");
195
287
 
288
+ // Handle large output by truncation if needed
289
+ const finalOutput =
290
+ combinedOutput || `Command executed with exit code: ${exitCode}`;
291
+ const content =
292
+ finalOutput.length > MAX_OUTPUT_LENGTH
293
+ ? finalOutput.substring(0, MAX_OUTPUT_LENGTH) +
294
+ "\n\n... (output truncated)"
295
+ : finalOutput;
296
+
196
297
  resolve({
197
298
  success: exitCode === 0,
198
- content:
199
- combinedOutput || `Command executed with exit code: ${exitCode}`,
299
+ content,
200
300
  error:
201
301
  exitCode !== 0
202
302
  ? `Command failed with exit code: ${exitCode}`
@@ -220,9 +320,15 @@ export const bashTool: ToolPlugin = {
220
320
  });
221
321
  },
222
322
  formatCompactParams: (params: Record<string, unknown>) => {
323
+ const description = params.description as string;
223
324
  const command = params.command as string;
224
325
  const runInBackground = params.run_in_background as boolean;
225
- return `${command}${runInBackground ? " background" : ""}`;
326
+
327
+ if (description) {
328
+ return description;
329
+ }
330
+
331
+ return `${command}${runInBackground ? " (background)" : ""}`;
226
332
  },
227
333
  };
228
334
 
@@ -299,15 +405,22 @@ export const bashOutputTool: ToolPlugin = {
299
405
 
300
406
  let content = "";
301
407
  if (output.stdout) {
302
- content += output.stdout;
408
+ content += stripAnsiColors(output.stdout);
303
409
  }
304
410
  if (output.stderr) {
305
- content += (content ? "\n" : "") + output.stderr;
411
+ content += (content ? "\n" : "") + stripAnsiColors(output.stderr);
306
412
  }
307
413
 
414
+ const finalContent = content || "No output available";
415
+ const processedContent =
416
+ finalContent.length > MAX_OUTPUT_LENGTH
417
+ ? finalContent.substring(0, MAX_OUTPUT_LENGTH) +
418
+ "\n\n... (output truncated)"
419
+ : finalContent;
420
+
308
421
  return {
309
422
  success: true,
310
- content: content || "No output available",
423
+ content: processedContent,
311
424
  shortResult: `${bashId}: ${output.status}${shell.exitCode !== undefined ? ` (${shell.exitCode})` : ""}`,
312
425
  error: undefined,
313
426
  };
@@ -46,6 +46,42 @@ export const deleteFileTool: ToolPlugin = {
46
46
  try {
47
47
  const filePath = resolvePath(targetFile, context.workdir);
48
48
 
49
+ // Permission check after validation but before real operation
50
+ if (
51
+ context.permissionManager &&
52
+ context.permissionMode &&
53
+ context.permissionMode !== "bypassPermissions"
54
+ ) {
55
+ if (context.permissionManager.isRestrictedTool("Delete")) {
56
+ try {
57
+ const permissionContext = context.permissionManager.createContext(
58
+ "Delete",
59
+ context.permissionMode,
60
+ context.canUseToolCallback,
61
+ { target_file: targetFile },
62
+ );
63
+ const permissionResult =
64
+ await context.permissionManager.checkPermission(
65
+ permissionContext,
66
+ );
67
+
68
+ if (permissionResult.behavior === "deny") {
69
+ return {
70
+ success: false,
71
+ content: "",
72
+ error: `Delete operation denied by user, reason: ${permissionResult.message || "No reason provided"}`,
73
+ };
74
+ }
75
+ } catch {
76
+ return {
77
+ success: false,
78
+ content: "",
79
+ error: "Permission check failed",
80
+ };
81
+ }
82
+ }
83
+ }
84
+
49
85
  // Delete file
50
86
  await unlink(filePath);
51
87
 
@@ -2,7 +2,6 @@ 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 { diffLines } from "diff";
6
5
 
7
6
  /**
8
7
  * Format compact parameter display
@@ -143,6 +142,47 @@ export const editTool: ToolPlugin = {
143
142
  replacementCount = 1;
144
143
  }
145
144
 
145
+ // Permission check after validation but before real operation
146
+ if (
147
+ context.permissionManager &&
148
+ context.permissionMode &&
149
+ context.permissionMode !== "bypassPermissions"
150
+ ) {
151
+ if (context.permissionManager.isRestrictedTool("Edit")) {
152
+ try {
153
+ const permissionContext = context.permissionManager.createContext(
154
+ "Edit",
155
+ context.permissionMode,
156
+ context.canUseToolCallback,
157
+ {
158
+ file_path: filePath,
159
+ old_string: oldString,
160
+ new_string: newString,
161
+ replace_all: replaceAll,
162
+ },
163
+ );
164
+ const permissionResult =
165
+ await context.permissionManager.checkPermission(
166
+ permissionContext,
167
+ );
168
+
169
+ if (permissionResult.behavior === "deny") {
170
+ return {
171
+ success: false,
172
+ content: "",
173
+ error: `Edit operation denied by user, reason: ${permissionResult.message || "No reason provided"}`,
174
+ };
175
+ }
176
+ } catch {
177
+ return {
178
+ success: false,
179
+ content: "",
180
+ error: "Permission check failed",
181
+ };
182
+ }
183
+ }
184
+ }
185
+
146
186
  // Write file
147
187
  try {
148
188
  await writeFile(resolvedPath, newContent, "utf-8");
@@ -154,9 +194,6 @@ export const editTool: ToolPlugin = {
154
194
  };
155
195
  }
156
196
 
157
- // Generate diff information
158
- const diffResult = diffLines(originalContent, newContent);
159
-
160
197
  const shortResult = replaceAll
161
198
  ? `Replaced ${replacementCount} instances`
162
199
  : "Text replaced successfully";
@@ -168,9 +205,6 @@ export const editTool: ToolPlugin = {
168
205
  content: shortResult,
169
206
  shortResult,
170
207
  filePath: resolvedPath,
171
- originalContent,
172
- newContent,
173
- diffResult,
174
208
  };
175
209
  } catch (error) {
176
210
  const errorMessage =