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
@@ -0,0 +1,444 @@
1
+ /**
2
+ * Splits a complex bash command into individual simple commands by shell operators (&&, ||, ;, |, &).
3
+ * Correctly handles quotes, escaped characters, and subshells.
4
+ */
5
+ export function splitBashCommand(command: string): string[] {
6
+ let inSingleQuote = false;
7
+ let inDoubleQuote = false;
8
+ let escaped = false;
9
+ let parenLevel = 0;
10
+ const splitPositions: number[] = [];
11
+
12
+ for (let i = 0; i < command.length; i++) {
13
+ const char = command[i];
14
+ const nextChar = command[i + 1];
15
+
16
+ if (escaped) {
17
+ escaped = false;
18
+ continue;
19
+ }
20
+
21
+ if (char === "\\") {
22
+ escaped = true;
23
+ continue;
24
+ }
25
+
26
+ if (char === "'" && !inDoubleQuote) {
27
+ inSingleQuote = !inSingleQuote;
28
+ continue;
29
+ }
30
+
31
+ if (char === '"' && !inSingleQuote) {
32
+ inDoubleQuote = !inDoubleQuote;
33
+ continue;
34
+ }
35
+
36
+ if (inSingleQuote || inDoubleQuote) {
37
+ continue;
38
+ }
39
+
40
+ if (char === "(") {
41
+ parenLevel++;
42
+ continue;
43
+ }
44
+
45
+ if (char === ")") {
46
+ parenLevel--;
47
+ continue;
48
+ }
49
+
50
+ if (parenLevel > 0) {
51
+ continue;
52
+ }
53
+
54
+ // Check for operators
55
+ let opLen = 0;
56
+ if (char === "&" && nextChar === "&") opLen = 2;
57
+ else if (char === "|" && nextChar === "|") opLen = 2;
58
+ else if (char === "|" && nextChar === "&") opLen = 2;
59
+ else if (char === ";") opLen = 1;
60
+ else if (char === "|") opLen = 1;
61
+ else if (char === "&" && nextChar !== ">") opLen = 1;
62
+
63
+ if (opLen > 0) {
64
+ // Check if preceded by an odd number of backslashes
65
+ let backslashCount = 0;
66
+ for (let j = i - 1; j >= 0; j--) {
67
+ if (command[j] === "\\") backslashCount++;
68
+ else break;
69
+ }
70
+
71
+ // ALSO check if preceded by an escaped operator character (e.g., \&&)
72
+ let precededByEscapedOp = false;
73
+ if (i > 0 && /[&|;]/.test(command[i - 1])) {
74
+ let bsCount = 0;
75
+ for (let j = i - 2; j >= 0; j--) {
76
+ if (command[j] === "\\") bsCount++;
77
+ else break;
78
+ }
79
+ if (bsCount % 2 !== 0) precededByEscapedOp = true;
80
+ }
81
+
82
+ if (backslashCount % 2 === 0 && !precededByEscapedOp) {
83
+ splitPositions.push(i, i + opLen);
84
+ i += opLen - 1;
85
+ }
86
+ }
87
+ }
88
+
89
+ let lastPos = 0;
90
+ const parts: string[] = [];
91
+ for (let i = 0; i < splitPositions.length; i += 2) {
92
+ const start = splitPositions[i];
93
+ const end = splitPositions[i + 1];
94
+ const part = command.substring(lastPos, start).trim();
95
+ if (part) parts.push(part);
96
+ lastPos = end;
97
+ }
98
+ const lastPart = command.substring(lastPos).trim();
99
+ if (lastPart) parts.push(lastPart);
100
+
101
+ const finalResult: string[] = [];
102
+ for (const part of parts) {
103
+ const stripped = stripRedirections(stripEnvVars(part));
104
+ if (stripped.startsWith("(") && stripped.endsWith(")")) {
105
+ const inner = stripped.substring(1, stripped.length - 1).trim();
106
+ if (inner) {
107
+ finalResult.push(...splitBashCommand(inner));
108
+ }
109
+ } else {
110
+ finalResult.push(part);
111
+ }
112
+ }
113
+
114
+ return finalResult;
115
+ }
116
+
117
+ /**
118
+ * Removes inline environment variable assignments (e.g., VAR=val cmd -> cmd).
119
+ */
120
+ export function stripEnvVars(command: string): string {
121
+ let result = command.trim();
122
+ while (true) {
123
+ const match = result.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=/);
124
+ if (!match) break;
125
+
126
+ const varNameEnd = match[0].length;
127
+ let valueEnd = varNameEnd;
128
+
129
+ if (result[varNameEnd] === "'") {
130
+ valueEnd = result.indexOf("'", varNameEnd + 1);
131
+ if (valueEnd === -1) break;
132
+ valueEnd++;
133
+ } else if (result[varNameEnd] === '"') {
134
+ let escaped = false;
135
+ let found = false;
136
+ for (let i = varNameEnd + 1; i < result.length; i++) {
137
+ if (escaped) {
138
+ escaped = false;
139
+ continue;
140
+ }
141
+ if (result[i] === "\\") {
142
+ escaped = true;
143
+ continue;
144
+ }
145
+ if (result[i] === '"') {
146
+ valueEnd = i + 1;
147
+ found = true;
148
+ break;
149
+ }
150
+ }
151
+ if (!found) break;
152
+ } else {
153
+ const spaceIndex = result.search(/\s/);
154
+ if (spaceIndex === -1) {
155
+ return "";
156
+ }
157
+ valueEnd = spaceIndex;
158
+ }
159
+
160
+ result = result.substring(valueEnd).trim();
161
+ }
162
+ return result;
163
+ }
164
+
165
+ /**
166
+ * Removes redirections (e.g., echo "data" > output.txt -> echo "data").
167
+ */
168
+ export function stripRedirections(command: string): string {
169
+ let result = "";
170
+ let inSingleQuote = false;
171
+ let inDoubleQuote = false;
172
+ let escaped = false;
173
+
174
+ for (let i = 0; i < command.length; i++) {
175
+ const char = command[i];
176
+
177
+ if (escaped) {
178
+ result += char;
179
+ escaped = false;
180
+ continue;
181
+ }
182
+
183
+ if (char === "\\") {
184
+ result += char;
185
+ escaped = true;
186
+ continue;
187
+ }
188
+
189
+ if (char === "'" && !inDoubleQuote) {
190
+ inSingleQuote = !inSingleQuote;
191
+ result += char;
192
+ continue;
193
+ }
194
+
195
+ if (char === '"' && !inSingleQuote) {
196
+ inDoubleQuote = !inDoubleQuote;
197
+ result += char;
198
+ continue;
199
+ }
200
+
201
+ if (inSingleQuote || inDoubleQuote) {
202
+ result += char;
203
+ continue;
204
+ }
205
+
206
+ // Handle whitespace outside quotes: collapse multiple spaces into one
207
+ if (/\s/.test(char)) {
208
+ if (result.length > 0 && !/\s/.test(result[result.length - 1])) {
209
+ result += " ";
210
+ }
211
+ continue;
212
+ }
213
+
214
+ // Check for redirection
215
+ if (char === ">" || char === "<") {
216
+ // Check if preceded by a digit or & (for 2> or &>)
217
+ if (result.length > 0 && /[0-9&]/.test(result[result.length - 1])) {
218
+ // Ensure it's at the start of a word or preceded by whitespace
219
+ if (result.length === 1 || /\s/.test(result[result.length - 2])) {
220
+ // Remove the digit/& from result
221
+ result = result.substring(0, result.length - 1);
222
+ }
223
+ }
224
+
225
+ let end = i + 1;
226
+ if (command[end] === char) {
227
+ end++;
228
+ if (char === "<" && command[end] === "-") {
229
+ end++;
230
+ }
231
+ } else if (
232
+ command[end] === "&" ||
233
+ (char === ">" && command[end] === "|")
234
+ ) {
235
+ end++;
236
+ }
237
+
238
+ // Skip whitespace after operator
239
+ while (end < command.length && /\s/.test(command[end])) {
240
+ end++;
241
+ }
242
+
243
+ // Skip the following word (the target of redirection)
244
+ let wordEscaped = false;
245
+ let wordInSingleQuote = false;
246
+ let wordInDoubleQuote = false;
247
+ while (end < command.length) {
248
+ const c = command[end];
249
+ if (wordEscaped) {
250
+ wordEscaped = false;
251
+ end++;
252
+ continue;
253
+ }
254
+ if (c === "\\") {
255
+ wordEscaped = true;
256
+ end++;
257
+ continue;
258
+ }
259
+ if (c === "'" && !wordInDoubleQuote) {
260
+ wordInSingleQuote = !wordInSingleQuote;
261
+ end++;
262
+ continue;
263
+ }
264
+ if (c === '"' && !wordInSingleQuote) {
265
+ wordInDoubleQuote = !wordInDoubleQuote;
266
+ end++;
267
+ continue;
268
+ }
269
+ if (!wordInSingleQuote && !wordInDoubleQuote && /\s/.test(c)) {
270
+ break;
271
+ }
272
+ end++;
273
+ }
274
+
275
+ i = end - 1;
276
+ // After stripping a redirection, ensure there's a space if we're not at the end
277
+ if (result.length > 0 && !/\s/.test(result[result.length - 1])) {
278
+ result += " ";
279
+ }
280
+ continue;
281
+ }
282
+
283
+ result += char;
284
+ }
285
+
286
+ return result.trim();
287
+ }
288
+
289
+ /**
290
+ * Blacklist of dangerous commands that should not be safely prefix-matched
291
+ * and should not have persistent permissions.
292
+ */
293
+ export const DANGEROUS_COMMANDS = [
294
+ "rm",
295
+ "mv",
296
+ "chmod",
297
+ "chown",
298
+ "sh",
299
+ "bash",
300
+ "sudo",
301
+ "dd",
302
+ "apt",
303
+ "apt-get",
304
+ "yum",
305
+ "dnf",
306
+ ];
307
+
308
+ /**
309
+ * Extracts a "smart prefix" from a bash command based on common developer tools.
310
+ * Returns null if the command is blacklisted or cannot be safely prefix-matched.
311
+ */
312
+ export function getSmartPrefix(command: string): string | null {
313
+ const parts = splitBashCommand(command);
314
+ if (parts.length === 0) return null;
315
+
316
+ // For now, we only support prefix matching for single commands or the first command in a chain
317
+ // to keep it simple and safe.
318
+ const firstCommand = parts[0];
319
+ let stripped = stripRedirections(stripEnvVars(firstCommand));
320
+
321
+ // Handle sudo
322
+ if (stripped.startsWith("sudo ")) {
323
+ stripped = stripped.substring(5).trim();
324
+ }
325
+
326
+ const tokens = stripped.split(/\s+/);
327
+ if (tokens.length === 0) return null;
328
+
329
+ const exe = tokens[0];
330
+ const sub = tokens[1];
331
+
332
+ // Blacklist - Hard blacklist for dangerous commands
333
+ if (DANGEROUS_COMMANDS.includes(exe)) return null;
334
+
335
+ // Node/JS
336
+ if (["npm", "pnpm", "yarn", "deno", "bun"].includes(exe)) {
337
+ if (
338
+ [
339
+ "install",
340
+ "i",
341
+ "add",
342
+ "remove",
343
+ "test",
344
+ "t",
345
+ "build",
346
+ "start",
347
+ "dev",
348
+ ].includes(sub)
349
+ ) {
350
+ return `${exe} ${sub}`;
351
+ }
352
+ if (sub === "run" && tokens[2]) {
353
+ return `${exe} run ${tokens[2]}`;
354
+ }
355
+ return exe;
356
+ }
357
+
358
+ // Git
359
+ if (exe === "git") {
360
+ if (
361
+ [
362
+ "commit",
363
+ "push",
364
+ "pull",
365
+ "checkout",
366
+ "add",
367
+ "status",
368
+ "diff",
369
+ "branch",
370
+ "merge",
371
+ "rebase",
372
+ "log",
373
+ "fetch",
374
+ "remote",
375
+ "stash",
376
+ ].includes(sub)
377
+ ) {
378
+ return `${exe} ${sub}`;
379
+ }
380
+ return exe;
381
+ }
382
+
383
+ // Python
384
+ if (["python", "python3", "pip", "pip3", "poetry", "conda"].includes(exe)) {
385
+ if (exe === "python" || exe === "python3") {
386
+ if (sub === "-m" && tokens[2] === "pip" && tokens[3] === "install") {
387
+ return `${exe} -m pip install`;
388
+ }
389
+ return exe;
390
+ }
391
+ if (["install", "add", "remove", "test", "run"].includes(sub)) {
392
+ return `${exe} ${sub}`;
393
+ }
394
+ return exe;
395
+ }
396
+
397
+ // Java
398
+ if (["mvn", "gradle"].includes(exe)) {
399
+ if (sub && !sub.startsWith("-")) {
400
+ return `${exe} ${sub}`;
401
+ }
402
+ return exe;
403
+ }
404
+ if (exe === "java") {
405
+ if (sub === "-jar") return "java -jar";
406
+ return "java";
407
+ }
408
+
409
+ // Rust & Go
410
+ if (exe === "cargo") {
411
+ if (["build", "test", "run", "add", "check"].includes(sub)) {
412
+ return `${exe} ${sub}`;
413
+ }
414
+ return exe;
415
+ }
416
+ if (exe === "go") {
417
+ if (["build", "test", "run", "get", "mod"].includes(sub)) {
418
+ return `${exe} ${sub}`;
419
+ }
420
+ return exe;
421
+ }
422
+
423
+ // Containers & Infrastructure
424
+ if (exe === "docker" || exe === "docker-compose") {
425
+ if (["run", "build", "ps", "exec", "up", "down"].includes(sub)) {
426
+ return `${exe} ${sub}`;
427
+ }
428
+ return exe;
429
+ }
430
+ if (exe === "kubectl") {
431
+ if (["get", "describe", "apply", "logs"].includes(sub)) {
432
+ return `${exe} ${sub}`;
433
+ }
434
+ return exe;
435
+ }
436
+ if (exe === "terraform") {
437
+ if (["plan", "apply", "destroy", "init"].includes(sub)) {
438
+ return `${exe} ${sub}`;
439
+ }
440
+ return exe;
441
+ }
442
+
443
+ return null;
444
+ }
@@ -0,0 +1,71 @@
1
+ import type { SubagentConfiguration } from "./subagentParser.js";
2
+
3
+ /**
4
+ * Get all built-in subagent configurations
5
+ * Built-in subagents have priority 3 (lowest) and can be overridden by user/project configs
6
+ */
7
+ export function getBuiltinSubagents(): SubagentConfiguration[] {
8
+ return [
9
+ createExploreSubagent(),
10
+ // Add more built-in subagents here as needed
11
+ ];
12
+ }
13
+
14
+ /**
15
+ * Create the Explore built-in subagent configuration
16
+ * Specialized for codebase exploration and file search tasks
17
+ */
18
+ function createExploreSubagent(): SubagentConfiguration {
19
+ const systemPrompt = `You are a file search specialist. You excel at thoroughly navigating and exploring codebases.
20
+
21
+ === CRITICAL: READ-ONLY MODE - NO FILE MODIFICATIONS ===
22
+ This is a READ-ONLY exploration task. You are STRICTLY PROHIBITED from:
23
+ - Creating new files (no Write, touch, or file creation of any kind)
24
+ - Modifying existing files (no Edit operations)
25
+ - Deleting files (no rm or deletion)
26
+ - Moving or copying files (no mv or cp)
27
+ - Creating temporary files anywhere, including /tmp
28
+ - Using redirect operators (>, >>, |) or heredocs to write to files
29
+ - Running ANY commands that change system state
30
+
31
+ Your role is EXCLUSIVELY to search and analyze existing code. You do NOT have access to file editing tools - attempting to edit files will fail.
32
+
33
+ Your strengths:
34
+ - Rapidly finding files using glob patterns
35
+ - Searching code and text with powerful regex patterns
36
+ - Reading and analyzing file contents
37
+ - Using Language Server Protocol (LSP) for deep code intelligence (definitions, references, etc.)
38
+
39
+ Guidelines:
40
+ - Use Glob for broad file pattern matching
41
+ - Use Grep for searching file contents with regex
42
+ - Use Read when you know the specific file path you need to read
43
+ - Use LSP for code intelligence features like finding definitions, references, implementations, and symbols. This is especially useful for understanding complex code relationships.
44
+ - Use Bash ONLY for read-only operations (ls, git status, git log, git diff, find, cat, head, tail)
45
+ - NEVER use Bash for: mkdir, touch, rm, cp, mv, git add, git commit, npm install, pip install, or any file creation/modification
46
+ - Adapt your search approach based on the thoroughness level specified by the caller
47
+ - Return file paths as absolute paths in your final response
48
+ - For clear communication, avoid using emojis
49
+ - Communicate your final report directly as a regular message - do NOT attempt to create files
50
+
51
+ NOTE: You are meant to be a fast agent that returns output as quickly as possible. In order to achieve this you must:
52
+ - Make efficient use of the tools that you have at your disposal: be smart about how you search for files and implementations
53
+ - Wherever possible you should try to spawn multiple parallel tool calls for grepping and reading files
54
+
55
+ Complete the user's search request efficiently and report your findings clearly.`;
56
+
57
+ // Define allowed tools for read-only operations
58
+ const allowedTools = ["Glob", "Grep", "Read", "Bash", "LS", "LSP"];
59
+
60
+ return {
61
+ name: "Explore",
62
+ description:
63
+ 'Fast agent specialized for exploring codebases. Use this when you need to quickly find files by patterns (eg. "src/components/**/*.tsx"), search code for keywords (eg. "API endpoints"), or answer questions about the codebase (eg. "how do API endpoints work?"). When calling this agent, specify the desired thoroughness level: "quick" for basic searches, "medium" for moderate exploration, or "very thorough" for comprehensive analysis across multiple locations and naming conventions.',
64
+ systemPrompt,
65
+ tools: allowedTools,
66
+ model: "fastModel", // Special value that will use parent's fastModel
67
+ filePath: "<builtin:Explore>",
68
+ scope: "builtin",
69
+ priority: 3, // Lowest priority - can be overridden by user configs
70
+ };
71
+ }