@zds-ai/cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +497 -0
  3. package/dist/agent/grok-agent.d.ts +250 -0
  4. package/dist/agent/grok-agent.js +2480 -0
  5. package/dist/agent/grok-agent.js.map +1 -0
  6. package/dist/agent/index.d.ts +14 -0
  7. package/dist/agent/index.js +136 -0
  8. package/dist/agent/index.js.map +1 -0
  9. package/dist/commands/mcp.d.ts +2 -0
  10. package/dist/commands/mcp.js +239 -0
  11. package/dist/commands/mcp.js.map +1 -0
  12. package/dist/grok/client.d.ts +55 -0
  13. package/dist/grok/client.js +276 -0
  14. package/dist/grok/client.js.map +1 -0
  15. package/dist/grok/tools.d.ts +8 -0
  16. package/dist/grok/tools.js +878 -0
  17. package/dist/grok/tools.js.map +1 -0
  18. package/dist/hooks/use-enhanced-input.d.ts +38 -0
  19. package/dist/hooks/use-enhanced-input.js +228 -0
  20. package/dist/hooks/use-enhanced-input.js.map +1 -0
  21. package/dist/hooks/use-input-handler.d.ts +36 -0
  22. package/dist/hooks/use-input-handler.js +1099 -0
  23. package/dist/hooks/use-input-handler.js.map +1 -0
  24. package/dist/hooks/use-input-history.d.ts +9 -0
  25. package/dist/hooks/use-input-history.js +61 -0
  26. package/dist/hooks/use-input-history.js.map +1 -0
  27. package/dist/index.d.ts +2 -0
  28. package/dist/index.js +869 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/mcp/client.d.ts +41 -0
  31. package/dist/mcp/client.js +224 -0
  32. package/dist/mcp/client.js.map +1 -0
  33. package/dist/mcp/config.d.ts +13 -0
  34. package/dist/mcp/config.js +56 -0
  35. package/dist/mcp/config.js.map +1 -0
  36. package/dist/mcp/transports.d.ts +53 -0
  37. package/dist/mcp/transports.js +256 -0
  38. package/dist/mcp/transports.js.map +1 -0
  39. package/dist/tools/character-tool.d.ts +27 -0
  40. package/dist/tools/character-tool.js +194 -0
  41. package/dist/tools/character-tool.js.map +1 -0
  42. package/dist/tools/clear-cache-tool.d.ts +14 -0
  43. package/dist/tools/clear-cache-tool.js +82 -0
  44. package/dist/tools/clear-cache-tool.js.map +1 -0
  45. package/dist/tools/confirmation-tool.d.ts +16 -0
  46. package/dist/tools/confirmation-tool.js +72 -0
  47. package/dist/tools/confirmation-tool.js.map +1 -0
  48. package/dist/tools/env-tool.d.ts +17 -0
  49. package/dist/tools/env-tool.js +89 -0
  50. package/dist/tools/env-tool.js.map +1 -0
  51. package/dist/tools/file-conversion-tool.d.ts +16 -0
  52. package/dist/tools/file-conversion-tool.js +181 -0
  53. package/dist/tools/file-conversion-tool.js.map +1 -0
  54. package/dist/tools/image-tool.d.ts +22 -0
  55. package/dist/tools/image-tool.js +268 -0
  56. package/dist/tools/image-tool.js.map +1 -0
  57. package/dist/tools/index.d.ts +14 -0
  58. package/dist/tools/index.js +15 -0
  59. package/dist/tools/index.js.map +1 -0
  60. package/dist/tools/internet-tool.d.ts +11 -0
  61. package/dist/tools/internet-tool.js +108 -0
  62. package/dist/tools/internet-tool.js.map +1 -0
  63. package/dist/tools/introspect-tool.d.ts +11 -0
  64. package/dist/tools/introspect-tool.js +243 -0
  65. package/dist/tools/introspect-tool.js.map +1 -0
  66. package/dist/tools/morph-editor.d.ts +38 -0
  67. package/dist/tools/morph-editor.js +318 -0
  68. package/dist/tools/morph-editor.js.map +1 -0
  69. package/dist/tools/restart-tool.d.ts +7 -0
  70. package/dist/tools/restart-tool.js +24 -0
  71. package/dist/tools/restart-tool.js.map +1 -0
  72. package/dist/tools/search.d.ts +71 -0
  73. package/dist/tools/search.js +340 -0
  74. package/dist/tools/search.js.map +1 -0
  75. package/dist/tools/task-tool.d.ts +19 -0
  76. package/dist/tools/task-tool.js +115 -0
  77. package/dist/tools/task-tool.js.map +1 -0
  78. package/dist/tools/text-editor.d.ts +35 -0
  79. package/dist/tools/text-editor.js +669 -0
  80. package/dist/tools/text-editor.js.map +1 -0
  81. package/dist/tools/tool-discovery.d.ts +20 -0
  82. package/dist/tools/tool-discovery.js +45 -0
  83. package/dist/tools/tool-discovery.js.map +1 -0
  84. package/dist/tools/zsh.d.ts +13 -0
  85. package/dist/tools/zsh.js +168 -0
  86. package/dist/tools/zsh.js.map +1 -0
  87. package/dist/types/index.d.ts +31 -0
  88. package/dist/types/index.js +2 -0
  89. package/dist/types/index.js.map +1 -0
  90. package/dist/ui/app.d.ts +7 -0
  91. package/dist/ui/app.js +99 -0
  92. package/dist/ui/app.js.map +1 -0
  93. package/dist/ui/components/active-task-status.d.ts +7 -0
  94. package/dist/ui/components/active-task-status.js +37 -0
  95. package/dist/ui/components/active-task-status.js.map +1 -0
  96. package/dist/ui/components/api-key-input.d.ts +7 -0
  97. package/dist/ui/components/api-key-input.js +80 -0
  98. package/dist/ui/components/api-key-input.js.map +1 -0
  99. package/dist/ui/components/backend-status.d.ts +7 -0
  100. package/dist/ui/components/backend-status.js +85 -0
  101. package/dist/ui/components/backend-status.js.map +1 -0
  102. package/dist/ui/components/chat-history.d.ts +8 -0
  103. package/dist/ui/components/chat-history.js +187 -0
  104. package/dist/ui/components/chat-history.js.map +1 -0
  105. package/dist/ui/components/chat-input.d.ts +9 -0
  106. package/dist/ui/components/chat-input.js +63 -0
  107. package/dist/ui/components/chat-input.js.map +1 -0
  108. package/dist/ui/components/chat-interface.d.ts +9 -0
  109. package/dist/ui/components/chat-interface.js +389 -0
  110. package/dist/ui/components/chat-interface.js.map +1 -0
  111. package/dist/ui/components/command-suggestions.d.ts +17 -0
  112. package/dist/ui/components/command-suggestions.js +22 -0
  113. package/dist/ui/components/command-suggestions.js.map +1 -0
  114. package/dist/ui/components/confirmation-dialog.d.ts +11 -0
  115. package/dist/ui/components/confirmation-dialog.js +105 -0
  116. package/dist/ui/components/confirmation-dialog.js.map +1 -0
  117. package/dist/ui/components/context-status.d.ts +7 -0
  118. package/dist/ui/components/context-status.js +36 -0
  119. package/dist/ui/components/context-status.js.map +1 -0
  120. package/dist/ui/components/diff-renderer.d.ts +13 -0
  121. package/dist/ui/components/diff-renderer.js +206 -0
  122. package/dist/ui/components/diff-renderer.js.map +1 -0
  123. package/dist/ui/components/loading-spinner.d.ts +8 -0
  124. package/dist/ui/components/loading-spinner.js +64 -0
  125. package/dist/ui/components/loading-spinner.js.map +1 -0
  126. package/dist/ui/components/mcp-status.d.ts +5 -0
  127. package/dist/ui/components/mcp-status.js +57 -0
  128. package/dist/ui/components/mcp-status.js.map +1 -0
  129. package/dist/ui/components/model-selection.d.ts +12 -0
  130. package/dist/ui/components/model-selection.js +17 -0
  131. package/dist/ui/components/model-selection.js.map +1 -0
  132. package/dist/ui/components/mood-status.d.ts +7 -0
  133. package/dist/ui/components/mood-status.js +34 -0
  134. package/dist/ui/components/mood-status.js.map +1 -0
  135. package/dist/ui/components/persona-status.d.ts +7 -0
  136. package/dist/ui/components/persona-status.js +34 -0
  137. package/dist/ui/components/persona-status.js.map +1 -0
  138. package/dist/ui/shared/max-sized-box.d.ts +8 -0
  139. package/dist/ui/shared/max-sized-box.js +6 -0
  140. package/dist/ui/shared/max-sized-box.js.map +1 -0
  141. package/dist/ui/utils/code-colorizer.d.ts +2 -0
  142. package/dist/ui/utils/code-colorizer.js +7 -0
  143. package/dist/ui/utils/code-colorizer.js.map +1 -0
  144. package/dist/ui/utils/colors.d.ts +14 -0
  145. package/dist/ui/utils/colors.js +15 -0
  146. package/dist/ui/utils/colors.js.map +1 -0
  147. package/dist/ui/utils/markdown-renderer.d.ts +4 -0
  148. package/dist/ui/utils/markdown-renderer.js +40 -0
  149. package/dist/ui/utils/markdown-renderer.js.map +1 -0
  150. package/dist/utils/auth-helper.d.ts +63 -0
  151. package/dist/utils/auth-helper.js +129 -0
  152. package/dist/utils/auth-helper.js.map +1 -0
  153. package/dist/utils/chat-history-manager-sqlite.d.ts +92 -0
  154. package/dist/utils/chat-history-manager-sqlite.js +334 -0
  155. package/dist/utils/chat-history-manager-sqlite.js.map +1 -0
  156. package/dist/utils/chat-history-manager.d.ts +87 -0
  157. package/dist/utils/chat-history-manager.js +273 -0
  158. package/dist/utils/chat-history-manager.js.map +1 -0
  159. package/dist/utils/chat-history-manager.json-backup.d.ts +69 -0
  160. package/dist/utils/chat-history-manager.json-backup.js +215 -0
  161. package/dist/utils/chat-history-manager.json-backup.js.map +1 -0
  162. package/dist/utils/confirmation-service.d.ts +46 -0
  163. package/dist/utils/confirmation-service.js +165 -0
  164. package/dist/utils/confirmation-service.js.map +1 -0
  165. package/dist/utils/custom-instructions.d.ts +1 -0
  166. package/dist/utils/custom-instructions.js +30 -0
  167. package/dist/utils/custom-instructions.js.map +1 -0
  168. package/dist/utils/database-connection.d.ts +27 -0
  169. package/dist/utils/database-connection.js +81 -0
  170. package/dist/utils/database-connection.js.map +1 -0
  171. package/dist/utils/database-schema.d.ts +17 -0
  172. package/dist/utils/database-schema.js +93 -0
  173. package/dist/utils/database-schema.js.map +1 -0
  174. package/dist/utils/error-logger.d.ts +13 -0
  175. package/dist/utils/error-logger.js +56 -0
  176. package/dist/utils/error-logger.js.map +1 -0
  177. package/dist/utils/hook-executor.d.ts +59 -0
  178. package/dist/utils/hook-executor.js +351 -0
  179. package/dist/utils/hook-executor.js.map +1 -0
  180. package/dist/utils/model-config.d.ts +28 -0
  181. package/dist/utils/model-config.js +42 -0
  182. package/dist/utils/model-config.js.map +1 -0
  183. package/dist/utils/path-utils.d.ts +4 -0
  184. package/dist/utils/path-utils.js +12 -0
  185. package/dist/utils/path-utils.js.map +1 -0
  186. package/dist/utils/settings-manager.d.ts +169 -0
  187. package/dist/utils/settings-manager.js +403 -0
  188. package/dist/utils/settings-manager.js.map +1 -0
  189. package/dist/utils/settings.d.ts +1 -0
  190. package/dist/utils/settings.js +4 -0
  191. package/dist/utils/settings.js.map +1 -0
  192. package/dist/utils/slash-commands.d.ts +25 -0
  193. package/dist/utils/slash-commands.js +454 -0
  194. package/dist/utils/slash-commands.js.map +1 -0
  195. package/dist/utils/startup-hook.d.ts +13 -0
  196. package/dist/utils/startup-hook.js +44 -0
  197. package/dist/utils/startup-hook.js.map +1 -0
  198. package/dist/utils/text-utils.d.ts +80 -0
  199. package/dist/utils/text-utils.js +182 -0
  200. package/dist/utils/text-utils.js.map +1 -0
  201. package/dist/utils/token-counter.d.ts +33 -0
  202. package/dist/utils/token-counter.js +78 -0
  203. package/dist/utils/token-counter.js.map +1 -0
  204. package/package.json +102 -0
@@ -0,0 +1,878 @@
1
+ import { MCPManager } from "../mcp/client.js";
2
+ import { loadMCPConfig } from "../mcp/config.js";
3
+ import { ChatHistoryManager } from "../utils/chat-history-manager.js";
4
+ import fs from "fs";
5
+ const BASE_GROK_TOOLS = [
6
+ {
7
+ type: "function",
8
+ function: {
9
+ name: "viewFile",
10
+ description: "View contents of a file",
11
+ parameters: {
12
+ type: "object",
13
+ properties: {
14
+ filename: {
15
+ type: "string",
16
+ description: "Path to the file to view",
17
+ },
18
+ start_line: {
19
+ type: "number",
20
+ description: "Starting line number for partial file view (optional)",
21
+ },
22
+ end_line: {
23
+ type: "number",
24
+ description: "Ending line number for partial file view (optional)",
25
+ },
26
+ },
27
+ required: ["filename"],
28
+ },
29
+ },
30
+ },
31
+ {
32
+ type: "function",
33
+ function: {
34
+ name: "createNewFile",
35
+ description: "Create a new file with specified content",
36
+ parameters: {
37
+ type: "object",
38
+ properties: {
39
+ filename: {
40
+ type: "string",
41
+ description: "Path to the file to create",
42
+ },
43
+ content: {
44
+ type: "string",
45
+ description: "Content to write to the file",
46
+ },
47
+ },
48
+ required: ["filename", "content"],
49
+ },
50
+ },
51
+ },
52
+ {
53
+ type: "function",
54
+ function: {
55
+ name: "strReplace",
56
+ description: "Replace specific text in a file. Use this for single line edits only",
57
+ parameters: {
58
+ type: "object",
59
+ properties: {
60
+ filename: {
61
+ type: "string",
62
+ description: "Path to the file to edit",
63
+ },
64
+ old_str: {
65
+ type: "string",
66
+ description: "Text to replace (must match exactly, or will use fuzzy matching for multi-line strings)",
67
+ },
68
+ new_str: {
69
+ type: "string",
70
+ description: "Text to replace with",
71
+ },
72
+ replace_all: {
73
+ type: "boolean",
74
+ description: "Replace all occurrences (default: false, only replaces first occurrence)",
75
+ },
76
+ },
77
+ required: ["filename", "old_str", "new_str"],
78
+ },
79
+ },
80
+ },
81
+ {
82
+ type: "function",
83
+ function: {
84
+ name: "execute",
85
+ description: "Execute a zsh command",
86
+ parameters: {
87
+ type: "object",
88
+ properties: {
89
+ command: {
90
+ type: "string",
91
+ description: "The zsh command to execute",
92
+ },
93
+ },
94
+ required: ["command"],
95
+ },
96
+ },
97
+ },
98
+ {
99
+ type: "function",
100
+ function: {
101
+ name: "listFiles",
102
+ description: "List files in a directory (equivalent to 'ls -la')",
103
+ parameters: {
104
+ type: "object",
105
+ properties: {
106
+ dirname: {
107
+ type: "string",
108
+ description: "Path to the directory to list (default: current directory)",
109
+ },
110
+ },
111
+ required: [],
112
+ },
113
+ },
114
+ },
115
+ {
116
+ type: "function",
117
+ function: {
118
+ name: "universalSearch",
119
+ description: "Unified search tool for finding text content or files (similar to Cursor's search)",
120
+ parameters: {
121
+ type: "object",
122
+ properties: {
123
+ query: {
124
+ type: "string",
125
+ description: "Text to search for or file name/path pattern",
126
+ },
127
+ search_type: {
128
+ type: "string",
129
+ enum: ["text", "files", "both"],
130
+ description: "Type of search: 'text' for content search, 'files' for file names, 'both' for both (default: 'both')",
131
+ },
132
+ include_pattern: {
133
+ type: "string",
134
+ description: "Glob pattern for files to include (e.g. '*.ts', '*.js')",
135
+ },
136
+ exclude_pattern: {
137
+ type: "string",
138
+ description: "Glob pattern for files to exclude (e.g. '*.log', 'node_modules')",
139
+ },
140
+ case_sensitive: {
141
+ type: "boolean",
142
+ description: "Whether search should be case sensitive (default: false)",
143
+ },
144
+ whole_word: {
145
+ type: "boolean",
146
+ description: "Whether to match whole words only (default: false)",
147
+ },
148
+ regex: {
149
+ type: "boolean",
150
+ description: "Whether query is a regex pattern (default: false)",
151
+ },
152
+ max_results: {
153
+ type: "number",
154
+ description: "Maximum number of results to return (default: 50)",
155
+ },
156
+ file_types: {
157
+ type: "array",
158
+ items: { type: "string" },
159
+ description: "File types to search (e.g. ['js', 'ts', 'py'])",
160
+ },
161
+ include_hidden: {
162
+ type: "boolean",
163
+ description: "Whether to include hidden files (default: false)",
164
+ },
165
+ },
166
+ required: ["query"],
167
+ },
168
+ },
169
+ },
170
+ // {
171
+ // type: "function",
172
+ // function: {
173
+ // name: "createTodoList",
174
+ // description: "Create a new todo list for planning and tracking tasks",
175
+ // parameters: {
176
+ // type: "object",
177
+ // properties: {
178
+ // todos: {
179
+ // type: "array",
180
+ // description: "Array of todo items",
181
+ // items: {
182
+ // type: "object",
183
+ // properties: {
184
+ // id: {
185
+ // type: "string",
186
+ // description: "Unique identifier for the todo item",
187
+ // },
188
+ // content: {
189
+ // type: "string",
190
+ // description: "Description of the todo item",
191
+ // },
192
+ // status: {
193
+ // type: "string",
194
+ // enum: ["pending", "in_progress", "completed"],
195
+ // description: "Current status of the todo item",
196
+ // },
197
+ // priority: {
198
+ // type: "string",
199
+ // enum: ["high", "medium", "low"],
200
+ // description: "Priority level of the todo item",
201
+ // },
202
+ // },
203
+ // required: ["id", "content", "status", "priority"],
204
+ // },
205
+ // },
206
+ // },
207
+ // required: ["todos"],
208
+ // },
209
+ // },
210
+ // },
211
+ // {
212
+ // type: "function",
213
+ // function: {
214
+ // name: "updateTodoList",
215
+ // description: "Update existing todos in the todo list",
216
+ // parameters: {
217
+ // type: "object",
218
+ // properties: {
219
+ // updates: {
220
+ // type: "array",
221
+ // description: "Array of todo updates",
222
+ // items: {
223
+ // type: "object",
224
+ // properties: {
225
+ // id: {
226
+ // type: "string",
227
+ // description: "ID of the todo item to update",
228
+ // },
229
+ // status: {
230
+ // type: "string",
231
+ // enum: ["pending", "in_progress", "completed"],
232
+ // description: "New status for the todo item",
233
+ // },
234
+ // content: {
235
+ // type: "string",
236
+ // description: "New content for the todo item",
237
+ // },
238
+ // priority: {
239
+ // type: "string",
240
+ // enum: ["high", "medium", "low"],
241
+ // description: "New priority for the todo item",
242
+ // },
243
+ // },
244
+ // required: ["id"],
245
+ // },
246
+ // },
247
+ // },
248
+ // required: ["updates"],
249
+ // },
250
+ // },
251
+ // },
252
+ {
253
+ type: "function",
254
+ function: {
255
+ name: "getEnv",
256
+ description: "Get a specific environment variable",
257
+ parameters: {
258
+ type: "object",
259
+ properties: {
260
+ variable: {
261
+ type: "string",
262
+ description: "Name of environment variable to get",
263
+ },
264
+ },
265
+ required: ["variable"],
266
+ },
267
+ },
268
+ },
269
+ {
270
+ type: "function",
271
+ function: {
272
+ name: "getAllEnv",
273
+ description: "Get all environment variables",
274
+ parameters: {
275
+ type: "object",
276
+ properties: {},
277
+ required: [],
278
+ },
279
+ },
280
+ },
281
+ {
282
+ type: "function",
283
+ function: {
284
+ name: "searchEnv",
285
+ description: "Search environment variables by pattern",
286
+ parameters: {
287
+ type: "object",
288
+ properties: {
289
+ pattern: {
290
+ type: "string",
291
+ description: "Pattern to search for in variable names or values",
292
+ },
293
+ },
294
+ required: ["pattern"],
295
+ },
296
+ },
297
+ },
298
+ {
299
+ type: "function",
300
+ function: {
301
+ name: "introspect",
302
+ description: "Introspect available tools and system information",
303
+ parameters: {
304
+ type: "object",
305
+ properties: {
306
+ target: {
307
+ type: "string",
308
+ description: "What to introspect. Available: 'tools' - list all available tools (internal and MCP), 'env' - show ZDS_AI_AGENT_* environment variables, 'context' - show context/token usage, 'all' - show all introspection data",
309
+ enum: ["tools", "env", "context", "all"],
310
+ },
311
+ },
312
+ required: ["target"],
313
+ },
314
+ },
315
+ },
316
+ {
317
+ type: "function",
318
+ function: {
319
+ name: "clearCache",
320
+ description: "Clear the conversation cache/context and reset to initial state. Requires a two-step confirmation process to ensure notes are saved first. First call generates a confirmation code. Second call with the code clears the cache.",
321
+ parameters: {
322
+ type: "object",
323
+ properties: {
324
+ confirmationCode: {
325
+ type: "string",
326
+ description: "The confirmation code provided in the first call (6-letter code). Leave empty for initial call.",
327
+ },
328
+ },
329
+ required: [],
330
+ },
331
+ },
332
+ },
333
+ {
334
+ type: "function",
335
+ function: {
336
+ name: "restart",
337
+ description: "Restart the application. Use this when you need to reload the application with updated configuration or to apply changes.",
338
+ parameters: {
339
+ type: "object",
340
+ properties: {},
341
+ required: [],
342
+ },
343
+ },
344
+ },
345
+ {
346
+ type: "function",
347
+ function: {
348
+ name: "setPersona",
349
+ description: "Set agent's current persona",
350
+ parameters: {
351
+ type: "object",
352
+ properties: {
353
+ persona: {
354
+ type: "string",
355
+ description: "The persona (e.g., 'worker', 'receptionist')",
356
+ },
357
+ color: {
358
+ type: "string",
359
+ description: "Optional color for the text (e.g., 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', '#FF5733', etc.)",
360
+ },
361
+ },
362
+ required: ["persona"],
363
+ },
364
+ },
365
+ },
366
+ {
367
+ type: "function",
368
+ function: {
369
+ name: "setMood",
370
+ description: "Set agent's current mood",
371
+ parameters: {
372
+ type: "object",
373
+ properties: {
374
+ mood: {
375
+ type: "string",
376
+ description: "The mood (e.g., 'focused', 'tired', 'excited')",
377
+ },
378
+ color: {
379
+ type: "string",
380
+ description: "Optional color for the text (e.g., 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', '#FF5733', etc.)",
381
+ },
382
+ },
383
+ required: ["mood"],
384
+ },
385
+ },
386
+ },
387
+ {
388
+ type: "function",
389
+ function: {
390
+ name: "getPersona",
391
+ description: "Get the persona last set",
392
+ parameters: {
393
+ type: "object",
394
+ properties: {},
395
+ required: [],
396
+ },
397
+ },
398
+ },
399
+ {
400
+ type: "function",
401
+ function: {
402
+ name: "getMood",
403
+ description: "Get the mood last set",
404
+ parameters: {
405
+ type: "object",
406
+ properties: {},
407
+ required: [],
408
+ },
409
+ },
410
+ },
411
+ {
412
+ type: "function",
413
+ function: {
414
+ name: "getAvailablePersonas",
415
+ description: "Get list of your available personas",
416
+ parameters: {
417
+ type: "object",
418
+ properties: {},
419
+ required: [],
420
+ },
421
+ },
422
+ },
423
+ {
424
+ type: "function",
425
+ function: {
426
+ name: "startActiveTask",
427
+ description: "Start a new active task",
428
+ parameters: {
429
+ type: "object",
430
+ properties: {
431
+ activeTask: {
432
+ type: "string",
433
+ description: "The task description (e.g., 'fix bug in parser', 'implement feature X', 'chatting')",
434
+ },
435
+ action: {
436
+ type: "string",
437
+ description: "Required single-word action describing what you're doing (e.g., 'coding', 'testing', 'researching', 'debugging', 'planning')",
438
+ },
439
+ color: {
440
+ type: "string",
441
+ description: "Optional color for the text (e.g., 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', '#FF5733', etc.)",
442
+ },
443
+ },
444
+ required: ["activeTask", "action"],
445
+ },
446
+ },
447
+ },
448
+ {
449
+ type: "function",
450
+ function: {
451
+ name: "transitionActiveTaskStatus",
452
+ description: "Change active task status or action",
453
+ parameters: {
454
+ type: "object",
455
+ properties: {
456
+ action: {
457
+ type: "string",
458
+ description: "New single-word action describing ongoing work (e.g., 'coding', 'testing', 'researching', 'debugging', 'planning')",
459
+ },
460
+ color: {
461
+ type: "string",
462
+ description: "Optional color for the text (e.g., 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', '#FF5733', etc.)",
463
+ },
464
+ },
465
+ required: ["action"],
466
+ },
467
+ },
468
+ },
469
+ {
470
+ type: "function",
471
+ function: {
472
+ name: "stopActiveTask",
473
+ description: "Stop the current active task",
474
+ parameters: {
475
+ type: "object",
476
+ properties: {
477
+ reason: {
478
+ type: "string",
479
+ description: "Reason for stopping (e.g., 'finished', 'blocked', 'error', 'preempted')",
480
+ },
481
+ documentationFile: {
482
+ type: "string",
483
+ description: "Path to documentation file (.md or .txt) proving progress was documented. File must have been modified recently.",
484
+ },
485
+ color: {
486
+ type: "string",
487
+ description: "Optional color for the text (e.g., 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', '#FF5733', etc.)",
488
+ },
489
+ },
490
+ required: ["reason", "documentationFile"],
491
+ },
492
+ },
493
+ },
494
+ {
495
+ type: "function",
496
+ function: {
497
+ name: "insertLines",
498
+ description: "Insert text at a specific line in a file",
499
+ parameters: {
500
+ type: "object",
501
+ properties: {
502
+ filename: {
503
+ type: "string",
504
+ description: "Path to the file to edit",
505
+ },
506
+ insert_line: {
507
+ type: "number",
508
+ description: "Line number to insert at",
509
+ },
510
+ new_str: {
511
+ type: "string",
512
+ description: "Text to insert",
513
+ },
514
+ },
515
+ required: ["filename", "insert_line", "new_str"],
516
+ },
517
+ },
518
+ },
519
+ {
520
+ type: "function",
521
+ function: {
522
+ name: "replaceLines",
523
+ description: "Replace a range of lines in a file",
524
+ parameters: {
525
+ type: "object",
526
+ properties: {
527
+ filename: {
528
+ type: "string",
529
+ description: "Path to the file to edit",
530
+ },
531
+ start_line: {
532
+ type: "number",
533
+ description: "Starting line number",
534
+ },
535
+ end_line: {
536
+ type: "number",
537
+ description: "Ending line number",
538
+ },
539
+ new_str: {
540
+ type: "string",
541
+ description: "Replacement text",
542
+ },
543
+ },
544
+ required: ["filename", "start_line", "end_line", "new_str"],
545
+ },
546
+ },
547
+ },
548
+ {
549
+ type: "function",
550
+ function: {
551
+ name: "undoEdit",
552
+ description: "Undo the last edit operation",
553
+ parameters: {
554
+ type: "object",
555
+ properties: {},
556
+ required: [],
557
+ },
558
+ },
559
+ },
560
+ // {
561
+ // type: "function",
562
+ // function: {
563
+ // name: "viewTodoList",
564
+ // description: "View the current todo list",
565
+ // parameters: {
566
+ // type: "object",
567
+ // properties: {},
568
+ // required: [],
569
+ // },
570
+ // },
571
+ // },
572
+ {
573
+ type: "function",
574
+ function: {
575
+ name: "chdir",
576
+ description: "Change the current working directory",
577
+ parameters: {
578
+ type: "object",
579
+ properties: {
580
+ dirname: {
581
+ type: "string",
582
+ description: "Path to the directory to change to",
583
+ },
584
+ },
585
+ required: ["dirname"],
586
+ },
587
+ },
588
+ },
589
+ {
590
+ type: "function",
591
+ function: {
592
+ name: "pwdir",
593
+ description: "Show the current working directory",
594
+ parameters: {
595
+ type: "object",
596
+ properties: {},
597
+ required: [],
598
+ },
599
+ },
600
+ },
601
+ {
602
+ type: "function",
603
+ function: {
604
+ name: "downloadFile",
605
+ description: "Download a file < 10MB from the Internet.",
606
+ parameters: {
607
+ type: "object",
608
+ properties: {
609
+ url: {
610
+ type: "string",
611
+ description: "URL of the file to download",
612
+ },
613
+ },
614
+ required: ["url"],
615
+ },
616
+ },
617
+ },
618
+ {
619
+ type: "function",
620
+ function: {
621
+ name: "generateImage",
622
+ description: "Generate an image using AI image generation",
623
+ parameters: {
624
+ type: "object",
625
+ properties: {
626
+ prompt: {
627
+ type: "string",
628
+ description: "Text description of the image to generate",
629
+ },
630
+ negativePrompt: {
631
+ type: "string",
632
+ description: "Text description of what to avoid in the image (optional)",
633
+ },
634
+ width: {
635
+ type: "integer",
636
+ description: "Image width in pixels (default: 480)",
637
+ },
638
+ height: {
639
+ type: "integer",
640
+ description: "Image height in pixels (default: 720)",
641
+ },
642
+ model: {
643
+ type: "string",
644
+ description: "Model checkpoint to use for generation (default: 'cyberrealisticPony_v130')",
645
+ },
646
+ sampler: {
647
+ type: "string",
648
+ description: "Sampling method (default: 'DPM++ 2M Karras')",
649
+ },
650
+ configScale: {
651
+ type: "number",
652
+ description: "Guidance scale - how closely to follow the prompt (default: 5.0)",
653
+ },
654
+ numSteps: {
655
+ type: "integer",
656
+ description: "Number of inference steps (default: 30)",
657
+ },
658
+ nsfw: {
659
+ type: "boolean",
660
+ description: "Allow NSFW content by disabling safety checker (default: false)",
661
+ },
662
+ name: {
663
+ type: "string",
664
+ description: "Optional slug to include in the filename (e.g., 'portrait' becomes 'portrait-2025-10-12T14-30-45.png')",
665
+ },
666
+ move: {
667
+ type: "boolean",
668
+ description: "Move the generated image to ZAI folder (default: false)",
669
+ },
670
+ seed: {
671
+ type: "integer",
672
+ description: "Random seed for reproducible image generation (optional)",
673
+ },
674
+ },
675
+ required: ["prompt"],
676
+ },
677
+ },
678
+ },
679
+ {
680
+ type: "function",
681
+ function: {
682
+ name: "captionImage",
683
+ description: "Generate a caption for an image",
684
+ parameters: {
685
+ type: "object",
686
+ properties: {
687
+ filename: {
688
+ type: "string",
689
+ description: "Path to the image file to caption",
690
+ },
691
+ prompt: {
692
+ type: "string",
693
+ description: "Optional prompt to guide the captioning process",
694
+ },
695
+ },
696
+ required: ["filename"],
697
+ },
698
+ },
699
+ },
700
+ {
701
+ type: "function",
702
+ function: {
703
+ name: "pngInfo",
704
+ description: "Extract PNG metadata including generation settings",
705
+ parameters: {
706
+ type: "object",
707
+ properties: {
708
+ filename: {
709
+ type: "string",
710
+ description: "Path to the PNG file",
711
+ },
712
+ },
713
+ required: ["filename"],
714
+ },
715
+ },
716
+ },
717
+ {
718
+ type: "function",
719
+ function: {
720
+ name: "readXlsx",
721
+ description: "Read an Excel/XLSX file and return its contents in various formats (text, JSON, CSV)",
722
+ parameters: {
723
+ type: "object",
724
+ properties: {
725
+ filename: {
726
+ type: "string",
727
+ description: "Path to the XLSX file to read",
728
+ },
729
+ sheetName: {
730
+ type: "string",
731
+ description: "Optional name of specific sheet to read (defaults to first/active sheet)",
732
+ },
733
+ outputFormat: {
734
+ type: "string",
735
+ enum: ["text", "json", "all-sheets-json", "csv"],
736
+ description: "Output format: 'text' for human-readable, 'json' for single sheet JSON, 'all-sheets-json' for all sheets as JSON, 'csv' to convert to CSV file (default: text)",
737
+ },
738
+ output: {
739
+ type: "string",
740
+ description: "Output filename for saving the converted data",
741
+ },
742
+ },
743
+ required: ["filename"],
744
+ },
745
+ },
746
+ },
747
+ {
748
+ type: "function",
749
+ function: {
750
+ name: "listXlsxSheets",
751
+ description: "List all available sheets in an Excel/XLSX file",
752
+ parameters: {
753
+ type: "object",
754
+ properties: {
755
+ filename: {
756
+ type: "string",
757
+ description: "Path to the XLSX file",
758
+ },
759
+ },
760
+ required: ["filename"],
761
+ },
762
+ },
763
+ },
764
+ ];
765
+ // Morph Fast Apply tool (conditional)
766
+ const MORPH_EDIT_TOOL = {
767
+ type: "function",
768
+ function: {
769
+ name: "editFile",
770
+ description: "Use this tool to make an edit to an existing file.\n\nThis will be read by a less intelligent model, which will quickly apply the edit. You should make it clear what the edit is, while also minimizing the unchanged code you write.\nWhen writing the edit, you should specify each edit in sequence, with the special comment // ... existing code ... to represent unchanged code in between edited lines.\n\nFor example:\n\n// ... existing code ...\nFIRST_EDIT\n// ... existing code ...\nSECOND_EDIT\n// ... existing code ...\nTHIRD_EDIT\n// ... existing code ...\n\nYou should still bias towards repeating as few lines of the original file as possible to convey the change.\nBut, each edit should contain sufficient context of unchanged lines around the code you're editing to resolve ambiguity.\nDO NOT omit spans of pre-existing code (or comments) without using the // ... existing code ... comment to indicate its absence. If you omit the existing code comment, the model may inadvertently delete these lines.\nIf you plan on deleting a section, you must provide context before and after to delete it. If the initial code is ```code \\n Block 1 \\n Block 2 \\n Block 3 \\n code```, and you want to remove Block 2, you would output ```// ... existing code ... \\n Block 1 \\n Block 3 \\n // ... existing code ...```.\nMake sure it is clear what the edit should be, and where it should be applied.\nMake edits to a file in a single edit_file call instead of multiple edit_file calls to the same file. The apply model can handle many distinct edits at once.",
771
+ parameters: {
772
+ type: "object",
773
+ properties: {
774
+ filename: {
775
+ type: "string",
776
+ description: "Path to the file to modify"
777
+ },
778
+ instructions: {
779
+ type: "string",
780
+ description: "A single sentence instruction describing what you are going to do for the sketched edit. This is used to assist the less intelligent model in applying the edit. Use the first person to describe what you are going to do. Use it to disambiguate uncertainty in the edit."
781
+ },
782
+ code_edit: {
783
+ type: "string",
784
+ description: "Specify ONLY the precise lines of code that you wish to edit. NEVER specify or write out unchanged code. Instead, represent all unchanged code using the comment of the language you're editing in - example: // ... existing code ..."
785
+ }
786
+ },
787
+ required: ["filename", "instructions", "code_edit"]
788
+ }
789
+ }
790
+ };
791
+ // Function to build tools array conditionally
792
+ function buildGrokTools() {
793
+ const tools = [...BASE_GROK_TOOLS];
794
+ // Add Morph Fast Apply tool if API key is available
795
+ if (process.env.MORPH_API_KEY) {
796
+ tools.splice(3, 0, MORPH_EDIT_TOOL); // Insert after str_replace_editor
797
+ }
798
+ return tools;
799
+ }
800
+ // Export dynamic tools array
801
+ export const GROK_TOOLS = buildGrokTools();
802
+ // Global MCP manager instance
803
+ let mcpManager = null;
804
+ export function getMCPManager() {
805
+ if (!mcpManager) {
806
+ mcpManager = new MCPManager();
807
+ }
808
+ return mcpManager;
809
+ }
810
+ export async function initializeMCPServers(debugLogFile) {
811
+ const manager = getMCPManager();
812
+ const config = loadMCPConfig();
813
+ // Pass debug log file to manager for per-server stream redirection
814
+ if (debugLogFile) {
815
+ manager.setDebugLogFile(debugLogFile);
816
+ }
817
+ for (const serverConfig of config.servers) {
818
+ try {
819
+ await manager.addServer(serverConfig);
820
+ }
821
+ catch (error) {
822
+ // Only log to debug file if configured, otherwise suppress
823
+ if (debugLogFile) {
824
+ const fs = await import('fs');
825
+ const message = `Failed to initialize MCP server ${serverConfig.name}: ${error}\n`;
826
+ fs.appendFileSync(debugLogFile, message);
827
+ }
828
+ // Silently ignore initialization failures
829
+ }
830
+ }
831
+ }
832
+ export function convertMCPToolToGrokTool(mcpTool) {
833
+ // Normalize schema to ensure OpenAI compatibility
834
+ let parameters = mcpTool.inputSchema || {
835
+ type: "object",
836
+ properties: {},
837
+ required: []
838
+ };
839
+ // OpenAI requires objects to have properties field
840
+ if (parameters.type === "object" && !parameters.properties) {
841
+ parameters = {
842
+ ...parameters,
843
+ properties: {}
844
+ };
845
+ }
846
+ return {
847
+ type: "function",
848
+ function: {
849
+ name: mcpTool.name,
850
+ description: mcpTool.description,
851
+ parameters
852
+ }
853
+ };
854
+ }
855
+ export async function addMCPToolsToGrokTools(baseTools) {
856
+ if (!mcpManager) {
857
+ const debugLogPath = ChatHistoryManager.getDebugLogPath();
858
+ fs.appendFileSync(debugLogPath, `${new Date().toISOString()} - addMCPToolsToGrokTools: mcpManager is null\n`);
859
+ return baseTools;
860
+ }
861
+ const mcpTools = await mcpManager.getTools();
862
+ const debugLogPath = ChatHistoryManager.getDebugLogPath();
863
+ fs.appendFileSync(debugLogPath, `${new Date().toISOString()} - addMCPToolsToGrokTools: ${mcpTools.length} MCP tools from manager\n`);
864
+ const grokMCPTools = mcpTools.map(convertMCPToolToGrokTool);
865
+ return [...baseTools, ...grokMCPTools];
866
+ }
867
+ export async function getAllGrokTools() {
868
+ const manager = getMCPManager();
869
+ // Wait for servers to initialize before returning tools
870
+ try {
871
+ await manager.ensureServersInitialized();
872
+ }
873
+ catch (error) {
874
+ // Ignore initialization errors, just proceed with whatever tools we have
875
+ }
876
+ return await addMCPToolsToGrokTools(GROK_TOOLS);
877
+ }
878
+ //# sourceMappingURL=tools.js.map