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