@defai.digital/ax-cli 0.0.34

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 (181) hide show
  1. package/.automatosx/agents/aerospace-scientist.yaml +159 -0
  2. package/.automatosx/agents/architecture.yaml +244 -0
  3. package/.automatosx/agents/backend.yaml +172 -0
  4. package/.automatosx/agents/ceo.yaml +105 -0
  5. package/.automatosx/agents/creative-marketer.yaml +173 -0
  6. package/.automatosx/agents/cto.yaml +118 -0
  7. package/.automatosx/agents/data-scientist.yaml +200 -0
  8. package/.automatosx/agents/data.yaml +106 -0
  9. package/.automatosx/agents/design.yaml +115 -0
  10. package/.automatosx/agents/devops.yaml +124 -0
  11. package/.automatosx/agents/frontend.yaml +171 -0
  12. package/.automatosx/agents/fullstack.yaml +172 -0
  13. package/.automatosx/agents/mobile.yaml +185 -0
  14. package/.automatosx/agents/product.yaml +103 -0
  15. package/.automatosx/agents/quality.yaml +93 -0
  16. package/.automatosx/agents/quantum-engineer.yaml +167 -0
  17. package/.automatosx/agents/researcher.yaml +122 -0
  18. package/.automatosx/agents/security.yaml +115 -0
  19. package/.automatosx/agents/standard.yaml +214 -0
  20. package/.automatosx/agents/writer.yaml +122 -0
  21. package/.automatosx/feature-flags.json +13 -0
  22. package/.automatosx/memory/memory.db +0 -0
  23. package/.automatosx/providers/README.md +117 -0
  24. package/.automatosx/providers/grok-zai.yaml.template +61 -0
  25. package/.automatosx/providers/grok.yaml.template +71 -0
  26. package/.automatosx/status/backend-1763517593334-85037.json +9 -0
  27. package/.automatosx/status/quality-1763516867087-82043.json +9 -0
  28. package/.automatosx/status/quality-1763516976722-84817.json +9 -0
  29. package/.automatosx/status/security-1763517871950-87357.json +9 -0
  30. package/.automatosx/teams/business.yaml +56 -0
  31. package/.automatosx/teams/core.yaml +60 -0
  32. package/.automatosx/teams/design.yaml +58 -0
  33. package/.automatosx/teams/engineering.yaml +69 -0
  34. package/.automatosx/teams/research.yaml +56 -0
  35. package/.automatosx/templates/analyst.yaml +60 -0
  36. package/.automatosx/templates/assistant.yaml +48 -0
  37. package/.automatosx/templates/basic-agent.yaml +28 -0
  38. package/.automatosx/templates/code-reviewer.yaml +52 -0
  39. package/.automatosx/templates/debugger.yaml +63 -0
  40. package/.automatosx/templates/designer.yaml +69 -0
  41. package/.automatosx/templates/developer.yaml +60 -0
  42. package/.automatosx/templates/fullstack-developer.yaml +395 -0
  43. package/.automatosx/templates/qa-specialist.yaml +71 -0
  44. package/.claude/mcp/automatosx.json +244 -0
  45. package/.claude/settings.local.json +34 -0
  46. package/.grok/settings.json +37 -0
  47. package/LICENSE +26 -0
  48. package/README.md +518 -0
  49. package/automatosx/PRD/README.md +9 -0
  50. package/automatosx/tmp/README.md +10 -0
  51. package/automatosx.config.json +333 -0
  52. package/dist/agent/grok-agent.d.ts +52 -0
  53. package/dist/agent/grok-agent.js +627 -0
  54. package/dist/agent/grok-agent.js.map +1 -0
  55. package/dist/agent/index.d.ts +14 -0
  56. package/dist/agent/index.js +136 -0
  57. package/dist/agent/index.js.map +1 -0
  58. package/dist/commands/mcp.d.ts +2 -0
  59. package/dist/commands/mcp.js +239 -0
  60. package/dist/commands/mcp.js.map +1 -0
  61. package/dist/grok/client.d.ts +49 -0
  62. package/dist/grok/client.js +80 -0
  63. package/dist/grok/client.js.map +1 -0
  64. package/dist/grok/tools.d.ts +8 -0
  65. package/dist/grok/tools.js +349 -0
  66. package/dist/grok/tools.js.map +1 -0
  67. package/dist/hooks/use-enhanced-input.d.ts +37 -0
  68. package/dist/hooks/use-enhanced-input.js +214 -0
  69. package/dist/hooks/use-enhanced-input.js.map +1 -0
  70. package/dist/hooks/use-input-handler.d.ts +34 -0
  71. package/dist/hooks/use-input-handler.js +608 -0
  72. package/dist/hooks/use-input-handler.js.map +1 -0
  73. package/dist/hooks/use-input-history.d.ts +9 -0
  74. package/dist/hooks/use-input-history.js +69 -0
  75. package/dist/hooks/use-input-history.js.map +1 -0
  76. package/dist/index.d.ts +2 -0
  77. package/dist/index.js +339 -0
  78. package/dist/index.js.map +1 -0
  79. package/dist/mcp/client.d.ts +31 -0
  80. package/dist/mcp/client.js +152 -0
  81. package/dist/mcp/client.js.map +1 -0
  82. package/dist/mcp/config.d.ts +13 -0
  83. package/dist/mcp/config.js +43 -0
  84. package/dist/mcp/config.js.map +1 -0
  85. package/dist/mcp/transports.d.ts +48 -0
  86. package/dist/mcp/transports.js +217 -0
  87. package/dist/mcp/transports.js.map +1 -0
  88. package/dist/schemas/index.d.ts +102 -0
  89. package/dist/schemas/index.js +105 -0
  90. package/dist/schemas/index.js.map +1 -0
  91. package/dist/tools/bash.d.ts +10 -0
  92. package/dist/tools/bash.js +82 -0
  93. package/dist/tools/bash.js.map +1 -0
  94. package/dist/tools/confirmation-tool.d.ts +16 -0
  95. package/dist/tools/confirmation-tool.js +72 -0
  96. package/dist/tools/confirmation-tool.js.map +1 -0
  97. package/dist/tools/index.d.ts +6 -0
  98. package/dist/tools/index.js +7 -0
  99. package/dist/tools/index.js.map +1 -0
  100. package/dist/tools/morph-editor.d.ts +36 -0
  101. package/dist/tools/morph-editor.js +308 -0
  102. package/dist/tools/morph-editor.js.map +1 -0
  103. package/dist/tools/search.d.ts +68 -0
  104. package/dist/tools/search.js +300 -0
  105. package/dist/tools/search.js.map +1 -0
  106. package/dist/tools/text-editor.d.ts +16 -0
  107. package/dist/tools/text-editor.js +526 -0
  108. package/dist/tools/text-editor.js.map +1 -0
  109. package/dist/tools/todo-tool.d.ts +20 -0
  110. package/dist/tools/todo-tool.js +129 -0
  111. package/dist/tools/todo-tool.js.map +1 -0
  112. package/dist/types/index.d.ts +30 -0
  113. package/dist/types/index.js +2 -0
  114. package/dist/types/index.js.map +1 -0
  115. package/dist/ui/app.d.ts +7 -0
  116. package/dist/ui/app.js +99 -0
  117. package/dist/ui/app.js.map +1 -0
  118. package/dist/ui/components/api-key-input.d.ts +7 -0
  119. package/dist/ui/components/api-key-input.js +80 -0
  120. package/dist/ui/components/api-key-input.js.map +1 -0
  121. package/dist/ui/components/chat-history.d.ts +8 -0
  122. package/dist/ui/components/chat-history.js +157 -0
  123. package/dist/ui/components/chat-history.js.map +1 -0
  124. package/dist/ui/components/chat-input.d.ts +9 -0
  125. package/dist/ui/components/chat-input.js +67 -0
  126. package/dist/ui/components/chat-input.js.map +1 -0
  127. package/dist/ui/components/chat-interface.d.ts +8 -0
  128. package/dist/ui/components/chat-interface.js +272 -0
  129. package/dist/ui/components/chat-interface.js.map +1 -0
  130. package/dist/ui/components/command-suggestions.d.ts +17 -0
  131. package/dist/ui/components/command-suggestions.js +22 -0
  132. package/dist/ui/components/command-suggestions.js.map +1 -0
  133. package/dist/ui/components/confirmation-dialog.d.ts +11 -0
  134. package/dist/ui/components/confirmation-dialog.js +105 -0
  135. package/dist/ui/components/confirmation-dialog.js.map +1 -0
  136. package/dist/ui/components/diff-renderer.d.ts +13 -0
  137. package/dist/ui/components/diff-renderer.js +186 -0
  138. package/dist/ui/components/diff-renderer.js.map +1 -0
  139. package/dist/ui/components/loading-spinner.d.ts +8 -0
  140. package/dist/ui/components/loading-spinner.js +59 -0
  141. package/dist/ui/components/loading-spinner.js.map +1 -0
  142. package/dist/ui/components/mcp-status.d.ts +5 -0
  143. package/dist/ui/components/mcp-status.js +36 -0
  144. package/dist/ui/components/mcp-status.js.map +1 -0
  145. package/dist/ui/components/model-selection.d.ts +12 -0
  146. package/dist/ui/components/model-selection.js +17 -0
  147. package/dist/ui/components/model-selection.js.map +1 -0
  148. package/dist/ui/shared/max-sized-box.d.ts +8 -0
  149. package/dist/ui/shared/max-sized-box.js +6 -0
  150. package/dist/ui/shared/max-sized-box.js.map +1 -0
  151. package/dist/ui/utils/code-colorizer.d.ts +2 -0
  152. package/dist/ui/utils/code-colorizer.js +7 -0
  153. package/dist/ui/utils/code-colorizer.js.map +1 -0
  154. package/dist/ui/utils/colors.d.ts +14 -0
  155. package/dist/ui/utils/colors.js +15 -0
  156. package/dist/ui/utils/colors.js.map +1 -0
  157. package/dist/ui/utils/markdown-renderer.d.ts +4 -0
  158. package/dist/ui/utils/markdown-renderer.js +23 -0
  159. package/dist/ui/utils/markdown-renderer.js.map +1 -0
  160. package/dist/utils/confirmation-service.d.ts +32 -0
  161. package/dist/utils/confirmation-service.js +109 -0
  162. package/dist/utils/confirmation-service.js.map +1 -0
  163. package/dist/utils/custom-instructions.d.ts +1 -0
  164. package/dist/utils/custom-instructions.js +17 -0
  165. package/dist/utils/custom-instructions.js.map +1 -0
  166. package/dist/utils/model-config.d.ts +28 -0
  167. package/dist/utils/model-config.js +42 -0
  168. package/dist/utils/model-config.js.map +1 -0
  169. package/dist/utils/settings-manager.d.ts +94 -0
  170. package/dist/utils/settings-manager.js +240 -0
  171. package/dist/utils/settings-manager.js.map +1 -0
  172. package/dist/utils/settings.d.ts +1 -0
  173. package/dist/utils/settings.js +4 -0
  174. package/dist/utils/settings.js.map +1 -0
  175. package/dist/utils/text-utils.d.ts +80 -0
  176. package/dist/utils/text-utils.js +182 -0
  177. package/dist/utils/text-utils.js.map +1 -0
  178. package/dist/utils/token-counter.d.ts +33 -0
  179. package/dist/utils/token-counter.js +78 -0
  180. package/dist/utils/token-counter.js.map +1 -0
  181. package/package.json +70 -0
@@ -0,0 +1,627 @@
1
+ import { GrokClient } from "../grok/client.js";
2
+ import { getAllGrokTools, getMCPManager, initializeMCPServers, } from "../grok/tools.js";
3
+ import { loadMCPConfig } from "../mcp/config.js";
4
+ import { TextEditorTool, MorphEditorTool, BashTool, TodoTool, SearchTool, } from "../tools/index.js";
5
+ import { EventEmitter } from "events";
6
+ import { createTokenCounter } from "../utils/token-counter.js";
7
+ import { loadCustomInstructions } from "../utils/custom-instructions.js";
8
+ import { getSettingsManager } from "../utils/settings-manager.js";
9
+ export class GrokAgent extends EventEmitter {
10
+ grokClient;
11
+ textEditor;
12
+ morphEditor;
13
+ bash;
14
+ todoTool;
15
+ search;
16
+ chatHistory = [];
17
+ messages = [];
18
+ tokenCounter;
19
+ abortController = null;
20
+ maxToolRounds;
21
+ constructor(apiKey, baseURL, model, maxToolRounds) {
22
+ super();
23
+ const manager = getSettingsManager();
24
+ const savedModel = manager.getCurrentModel();
25
+ const modelToUse = model || savedModel || "grok-code-fast-1";
26
+ this.maxToolRounds = maxToolRounds || 400;
27
+ this.grokClient = new GrokClient(apiKey, modelToUse, baseURL);
28
+ this.textEditor = new TextEditorTool();
29
+ this.morphEditor = process.env.MORPH_API_KEY ? new MorphEditorTool() : null;
30
+ this.bash = new BashTool();
31
+ this.todoTool = new TodoTool();
32
+ this.search = new SearchTool();
33
+ this.tokenCounter = createTokenCounter(modelToUse);
34
+ // Initialize MCP servers if configured
35
+ this.initializeMCP();
36
+ // Load custom instructions
37
+ const customInstructions = loadCustomInstructions();
38
+ const customInstructionsSection = customInstructions
39
+ ? `\n\nCUSTOM INSTRUCTIONS:\n${customInstructions}\n\nThe above custom instructions should be followed alongside the standard instructions below.`
40
+ : "";
41
+ // Initialize with system message
42
+ this.messages.push({
43
+ role: "system",
44
+ content: `You are Grok CLI, an AI assistant that helps with file editing, coding tasks, and system operations.${customInstructionsSection}
45
+
46
+ You have access to these tools:
47
+ - view_file: View file contents or directory listings
48
+ - create_file: Create new files with content (ONLY use this for files that don't exist yet)
49
+ - str_replace_editor: Replace text in existing files (ALWAYS use this to edit or update existing files)${this.morphEditor
50
+ ? "\n- edit_file: High-speed file editing with Morph Fast Apply (4,500+ tokens/sec with 98% accuracy)"
51
+ : ""}
52
+ - bash: Execute bash commands (use for searching, file discovery, navigation, and system operations)
53
+ - search: Unified search tool for finding text content or files (similar to Cursor's search functionality)
54
+ - create_todo_list: Create a visual todo list for planning and tracking tasks
55
+ - update_todo_list: Update existing todos in your todo list
56
+
57
+ REAL-TIME INFORMATION:
58
+ You have access to real-time web search and X (Twitter) data. When users ask for current information, latest news, or recent events, you automatically have access to up-to-date information from the web and social media.
59
+
60
+ IMPORTANT TOOL USAGE RULES:
61
+ - NEVER use create_file on files that already exist - this will overwrite them completely
62
+ - ALWAYS use str_replace_editor to modify existing files, even for small changes
63
+ - Before editing a file, use view_file to see its current contents
64
+ - Use create_file ONLY when creating entirely new files that don't exist
65
+
66
+ SEARCHING AND EXPLORATION:
67
+ - Use search for fast, powerful text search across files or finding files by name (unified search tool)
68
+ - Examples: search for text content like "import.*react", search for files like "component.tsx"
69
+ - Use bash with commands like 'find', 'grep', 'rg', 'ls' for complex file operations and navigation
70
+ - view_file is best for reading specific files you already know exist
71
+
72
+ When a user asks you to edit, update, modify, or change an existing file:
73
+ 1. First use view_file to see the current contents
74
+ 2. Then use str_replace_editor to make the specific changes
75
+ 3. Never use create_file for existing files
76
+
77
+ When a user asks you to create a new file that doesn't exist:
78
+ 1. Use create_file with the full content
79
+
80
+ TASK PLANNING WITH TODO LISTS:
81
+ - For complex requests with multiple steps, ALWAYS create a todo list first to plan your approach
82
+ - Use create_todo_list to break down tasks into manageable items with priorities
83
+ - Mark tasks as 'in_progress' when you start working on them (only one at a time)
84
+ - Mark tasks as 'completed' immediately when finished
85
+ - Use update_todo_list to track your progress throughout the task
86
+ - Todo lists provide visual feedback with colors: ✅ Green (completed), 🔄 Cyan (in progress), ⏳ Yellow (pending)
87
+ - Always create todos with priorities: 'high' (🔴), 'medium' (🟡), 'low' (🟢)
88
+
89
+ USER CONFIRMATION SYSTEM:
90
+ File operations (create_file, str_replace_editor) and bash commands will automatically request user confirmation before execution. The confirmation system will show users the actual content or command before they decide. Users can choose to approve individual operations or approve all operations of that type for the session.
91
+
92
+ If a user rejects an operation, the tool will return an error and you should not proceed with that specific operation.
93
+
94
+ Be helpful, direct, and efficient. Always explain what you're doing and show the results.
95
+
96
+ IMPORTANT RESPONSE GUIDELINES:
97
+ - After using tools, do NOT respond with pleasantries like "Thanks for..." or "Great!"
98
+ - Only provide necessary explanations or next steps if relevant to the task
99
+ - Keep responses concise and focused on the actual work being done
100
+ - If a tool execution completes the user's request, you can remain silent or give a brief confirmation
101
+
102
+ Current working directory: ${process.cwd()}`,
103
+ });
104
+ }
105
+ async initializeMCP() {
106
+ // Initialize MCP in the background without blocking
107
+ Promise.resolve().then(async () => {
108
+ try {
109
+ const config = loadMCPConfig();
110
+ if (config.servers.length > 0) {
111
+ await initializeMCPServers();
112
+ }
113
+ }
114
+ catch (error) {
115
+ console.warn("MCP initialization failed:", error);
116
+ }
117
+ });
118
+ }
119
+ isGrokModel() {
120
+ const currentModel = this.grokClient.getCurrentModel();
121
+ return currentModel.toLowerCase().includes("grok");
122
+ }
123
+ // Heuristic: enable web search only when likely needed
124
+ shouldUseSearchFor(message) {
125
+ const q = message.toLowerCase();
126
+ const keywords = [
127
+ "today",
128
+ "latest",
129
+ "news",
130
+ "trending",
131
+ "breaking",
132
+ "current",
133
+ "now",
134
+ "recent",
135
+ "x.com",
136
+ "twitter",
137
+ "tweet",
138
+ "what happened",
139
+ "as of",
140
+ "update on",
141
+ "release notes",
142
+ "changelog",
143
+ "price",
144
+ ];
145
+ if (keywords.some((k) => q.includes(k)))
146
+ return true;
147
+ // crude date pattern (e.g., 2024/2025) may imply recency
148
+ if (/(20\d{2})/.test(q))
149
+ return true;
150
+ return false;
151
+ }
152
+ async processUserMessage(message) {
153
+ // Add user message to conversation
154
+ const userEntry = {
155
+ type: "user",
156
+ content: message,
157
+ timestamp: new Date(),
158
+ };
159
+ this.chatHistory.push(userEntry);
160
+ this.messages.push({ role: "user", content: message });
161
+ const newEntries = [userEntry];
162
+ const maxToolRounds = this.maxToolRounds; // Prevent infinite loops
163
+ let toolRounds = 0;
164
+ try {
165
+ const tools = await getAllGrokTools();
166
+ let currentResponse = await this.grokClient.chat(this.messages, tools, undefined, this.isGrokModel() && this.shouldUseSearchFor(message)
167
+ ? { search_parameters: { mode: "auto" } }
168
+ : { search_parameters: { mode: "off" } });
169
+ // Agent loop - continue until no more tool calls or max rounds reached
170
+ while (toolRounds < maxToolRounds) {
171
+ const assistantMessage = currentResponse.choices[0]?.message;
172
+ if (!assistantMessage) {
173
+ throw new Error("No response from Grok");
174
+ }
175
+ // Handle tool calls
176
+ if (assistantMessage.tool_calls &&
177
+ assistantMessage.tool_calls.length > 0) {
178
+ toolRounds++;
179
+ // Add assistant message with tool calls
180
+ const assistantEntry = {
181
+ type: "assistant",
182
+ content: assistantMessage.content || "Using tools to help you...",
183
+ timestamp: new Date(),
184
+ toolCalls: assistantMessage.tool_calls,
185
+ };
186
+ this.chatHistory.push(assistantEntry);
187
+ newEntries.push(assistantEntry);
188
+ // Add assistant message to conversation
189
+ this.messages.push({
190
+ role: "assistant",
191
+ content: assistantMessage.content || "",
192
+ tool_calls: assistantMessage.tool_calls,
193
+ });
194
+ // Create initial tool call entries to show tools are being executed
195
+ assistantMessage.tool_calls.forEach((toolCall) => {
196
+ const toolCallEntry = {
197
+ type: "tool_call",
198
+ content: "Executing...",
199
+ timestamp: new Date(),
200
+ toolCall: toolCall,
201
+ };
202
+ this.chatHistory.push(toolCallEntry);
203
+ newEntries.push(toolCallEntry);
204
+ });
205
+ // Execute tool calls and update the entries
206
+ for (const toolCall of assistantMessage.tool_calls) {
207
+ const result = await this.executeTool(toolCall);
208
+ // Update the existing tool_call entry with the result
209
+ const entryIndex = this.chatHistory.findIndex((entry) => entry.type === "tool_call" && entry.toolCall?.id === toolCall.id);
210
+ if (entryIndex !== -1) {
211
+ const updatedEntry = {
212
+ ...this.chatHistory[entryIndex],
213
+ type: "tool_result",
214
+ content: result.success
215
+ ? result.output || "Success"
216
+ : result.error || "Error occurred",
217
+ toolResult: result,
218
+ };
219
+ this.chatHistory[entryIndex] = updatedEntry;
220
+ // Also update in newEntries for return value
221
+ const newEntryIndex = newEntries.findIndex((entry) => entry.type === "tool_call" &&
222
+ entry.toolCall?.id === toolCall.id);
223
+ if (newEntryIndex !== -1) {
224
+ newEntries[newEntryIndex] = updatedEntry;
225
+ }
226
+ }
227
+ // Add tool result to messages with proper format (needed for AI context)
228
+ this.messages.push({
229
+ role: "tool",
230
+ content: result.success
231
+ ? result.output || "Success"
232
+ : result.error || "Error",
233
+ tool_call_id: toolCall.id,
234
+ });
235
+ }
236
+ // Get next response - this might contain more tool calls
237
+ currentResponse = await this.grokClient.chat(this.messages, tools, undefined, this.isGrokModel() && this.shouldUseSearchFor(message)
238
+ ? { search_parameters: { mode: "auto" } }
239
+ : { search_parameters: { mode: "off" } });
240
+ }
241
+ else {
242
+ // No more tool calls, add final response
243
+ const finalEntry = {
244
+ type: "assistant",
245
+ content: assistantMessage.content ||
246
+ "I understand, but I don't have a specific response.",
247
+ timestamp: new Date(),
248
+ };
249
+ this.chatHistory.push(finalEntry);
250
+ this.messages.push({
251
+ role: "assistant",
252
+ content: assistantMessage.content || "",
253
+ });
254
+ newEntries.push(finalEntry);
255
+ break; // Exit the loop
256
+ }
257
+ }
258
+ if (toolRounds >= maxToolRounds) {
259
+ const warningEntry = {
260
+ type: "assistant",
261
+ content: "Maximum tool execution rounds reached. Stopping to prevent infinite loops.",
262
+ timestamp: new Date(),
263
+ };
264
+ this.chatHistory.push(warningEntry);
265
+ newEntries.push(warningEntry);
266
+ }
267
+ return newEntries;
268
+ }
269
+ catch (error) {
270
+ const errorEntry = {
271
+ type: "assistant",
272
+ content: `Sorry, I encountered an error: ${error.message}`,
273
+ timestamp: new Date(),
274
+ };
275
+ this.chatHistory.push(errorEntry);
276
+ return [userEntry, errorEntry];
277
+ }
278
+ }
279
+ messageReducer(previous, item) {
280
+ const reduce = (acc, delta) => {
281
+ acc = { ...acc };
282
+ for (const [key, value] of Object.entries(delta)) {
283
+ if (acc[key] === undefined || acc[key] === null) {
284
+ acc[key] = value;
285
+ // Clean up index properties from tool calls
286
+ if (Array.isArray(acc[key])) {
287
+ for (const arr of acc[key]) {
288
+ delete arr.index;
289
+ }
290
+ }
291
+ }
292
+ else if (typeof acc[key] === "string" && typeof value === "string") {
293
+ acc[key] += value;
294
+ }
295
+ else if (Array.isArray(acc[key]) && Array.isArray(value)) {
296
+ const accArray = acc[key];
297
+ for (let i = 0; i < value.length; i++) {
298
+ if (!accArray[i])
299
+ accArray[i] = {};
300
+ accArray[i] = reduce(accArray[i], value[i]);
301
+ }
302
+ }
303
+ else if (typeof acc[key] === "object" && typeof value === "object") {
304
+ acc[key] = reduce(acc[key], value);
305
+ }
306
+ }
307
+ return acc;
308
+ };
309
+ return reduce(previous, item.choices[0]?.delta || {});
310
+ }
311
+ async *processUserMessageStream(message) {
312
+ // Create new abort controller for this request
313
+ this.abortController = new AbortController();
314
+ // Add user message to conversation
315
+ const userEntry = {
316
+ type: "user",
317
+ content: message,
318
+ timestamp: new Date(),
319
+ };
320
+ this.chatHistory.push(userEntry);
321
+ this.messages.push({ role: "user", content: message });
322
+ // Calculate input tokens
323
+ let inputTokens = this.tokenCounter.countMessageTokens(this.messages);
324
+ yield {
325
+ type: "token_count",
326
+ tokenCount: inputTokens,
327
+ };
328
+ const maxToolRounds = this.maxToolRounds; // Prevent infinite loops
329
+ let toolRounds = 0;
330
+ let totalOutputTokens = 0;
331
+ let lastTokenUpdate = 0;
332
+ try {
333
+ // Agent loop - continue until no more tool calls or max rounds reached
334
+ while (toolRounds < maxToolRounds) {
335
+ // Check if operation was cancelled
336
+ if (this.abortController?.signal.aborted) {
337
+ yield {
338
+ type: "content",
339
+ content: "\n\n[Operation cancelled by user]",
340
+ };
341
+ yield { type: "done" };
342
+ return;
343
+ }
344
+ // Stream response and accumulate
345
+ const tools = await getAllGrokTools();
346
+ const stream = this.grokClient.chatStream(this.messages, tools, undefined, this.isGrokModel() && this.shouldUseSearchFor(message)
347
+ ? { search_parameters: { mode: "auto" } }
348
+ : { search_parameters: { mode: "off" } });
349
+ let accumulatedMessage = {};
350
+ let accumulatedContent = "";
351
+ let toolCallsYielded = false;
352
+ for await (const chunk of stream) {
353
+ // Check for cancellation in the streaming loop
354
+ if (this.abortController?.signal.aborted) {
355
+ yield {
356
+ type: "content",
357
+ content: "\n\n[Operation cancelled by user]",
358
+ };
359
+ yield { type: "done" };
360
+ return;
361
+ }
362
+ if (!chunk.choices?.[0])
363
+ continue;
364
+ // Accumulate the message using reducer
365
+ accumulatedMessage = this.messageReducer(accumulatedMessage, chunk);
366
+ // Check for tool calls - yield when we have complete tool calls with function names
367
+ if (!toolCallsYielded && accumulatedMessage.tool_calls?.length > 0) {
368
+ // Check if we have at least one complete tool call with a function name
369
+ const hasCompleteTool = accumulatedMessage.tool_calls.some((tc) => tc.function?.name);
370
+ if (hasCompleteTool) {
371
+ yield {
372
+ type: "tool_calls",
373
+ toolCalls: accumulatedMessage.tool_calls,
374
+ };
375
+ toolCallsYielded = true;
376
+ }
377
+ }
378
+ // Stream content as it comes
379
+ if (chunk.choices[0].delta?.content) {
380
+ accumulatedContent += chunk.choices[0].delta.content;
381
+ // Update token count in real-time including accumulated content and any tool calls
382
+ const currentOutputTokens = this.tokenCounter.estimateStreamingTokens(accumulatedContent) +
383
+ (accumulatedMessage.tool_calls
384
+ ? this.tokenCounter.countTokens(JSON.stringify(accumulatedMessage.tool_calls))
385
+ : 0);
386
+ totalOutputTokens = currentOutputTokens;
387
+ yield {
388
+ type: "content",
389
+ content: chunk.choices[0].delta.content,
390
+ };
391
+ // Emit token count update
392
+ const now = Date.now();
393
+ if (now - lastTokenUpdate > 250) {
394
+ lastTokenUpdate = now;
395
+ yield {
396
+ type: "token_count",
397
+ tokenCount: inputTokens + totalOutputTokens,
398
+ };
399
+ }
400
+ }
401
+ }
402
+ // Add assistant entry to history
403
+ const assistantEntry = {
404
+ type: "assistant",
405
+ content: accumulatedMessage.content || "Using tools to help you...",
406
+ timestamp: new Date(),
407
+ toolCalls: accumulatedMessage.tool_calls || undefined,
408
+ };
409
+ this.chatHistory.push(assistantEntry);
410
+ // Add accumulated message to conversation
411
+ this.messages.push({
412
+ role: "assistant",
413
+ content: accumulatedMessage.content || "",
414
+ tool_calls: accumulatedMessage.tool_calls,
415
+ });
416
+ // Handle tool calls if present
417
+ if (accumulatedMessage.tool_calls?.length > 0) {
418
+ toolRounds++;
419
+ // Only yield tool_calls if we haven't already yielded them during streaming
420
+ if (!toolCallsYielded) {
421
+ yield {
422
+ type: "tool_calls",
423
+ toolCalls: accumulatedMessage.tool_calls,
424
+ };
425
+ }
426
+ // Execute tools
427
+ for (const toolCall of accumulatedMessage.tool_calls) {
428
+ // Check for cancellation before executing each tool
429
+ if (this.abortController?.signal.aborted) {
430
+ yield {
431
+ type: "content",
432
+ content: "\n\n[Operation cancelled by user]",
433
+ };
434
+ yield { type: "done" };
435
+ return;
436
+ }
437
+ const result = await this.executeTool(toolCall);
438
+ const toolResultEntry = {
439
+ type: "tool_result",
440
+ content: result.success
441
+ ? result.output || "Success"
442
+ : result.error || "Error occurred",
443
+ timestamp: new Date(),
444
+ toolCall: toolCall,
445
+ toolResult: result,
446
+ };
447
+ this.chatHistory.push(toolResultEntry);
448
+ yield {
449
+ type: "tool_result",
450
+ toolCall,
451
+ toolResult: result,
452
+ };
453
+ // Add tool result with proper format (needed for AI context)
454
+ this.messages.push({
455
+ role: "tool",
456
+ content: result.success
457
+ ? result.output || "Success"
458
+ : result.error || "Error",
459
+ tool_call_id: toolCall.id,
460
+ });
461
+ }
462
+ // Update token count after processing all tool calls to include tool results
463
+ inputTokens = this.tokenCounter.countMessageTokens(this.messages);
464
+ // Final token update after tools processed
465
+ yield {
466
+ type: "token_count",
467
+ tokenCount: inputTokens + totalOutputTokens,
468
+ };
469
+ // Continue the loop to get the next response (which might have more tool calls)
470
+ }
471
+ else {
472
+ // No tool calls, we're done
473
+ break;
474
+ }
475
+ }
476
+ if (toolRounds >= maxToolRounds) {
477
+ yield {
478
+ type: "content",
479
+ content: "\n\nMaximum tool execution rounds reached. Stopping to prevent infinite loops.",
480
+ };
481
+ }
482
+ yield { type: "done" };
483
+ }
484
+ catch (error) {
485
+ // Check if this was a cancellation
486
+ if (this.abortController?.signal.aborted) {
487
+ yield {
488
+ type: "content",
489
+ content: "\n\n[Operation cancelled by user]",
490
+ };
491
+ yield { type: "done" };
492
+ return;
493
+ }
494
+ const errorEntry = {
495
+ type: "assistant",
496
+ content: `Sorry, I encountered an error: ${error.message}`,
497
+ timestamp: new Date(),
498
+ };
499
+ this.chatHistory.push(errorEntry);
500
+ yield {
501
+ type: "content",
502
+ content: errorEntry.content,
503
+ };
504
+ yield { type: "done" };
505
+ }
506
+ finally {
507
+ // Clean up abort controller
508
+ this.abortController = null;
509
+ }
510
+ }
511
+ async executeTool(toolCall) {
512
+ try {
513
+ const args = JSON.parse(toolCall.function.arguments);
514
+ switch (toolCall.function.name) {
515
+ case "view_file":
516
+ const range = args.start_line && args.end_line
517
+ ? [args.start_line, args.end_line]
518
+ : undefined;
519
+ return await this.textEditor.view(args.path, range);
520
+ case "create_file":
521
+ return await this.textEditor.create(args.path, args.content);
522
+ case "str_replace_editor":
523
+ return await this.textEditor.strReplace(args.path, args.old_str, args.new_str, args.replace_all);
524
+ case "edit_file":
525
+ if (!this.morphEditor) {
526
+ return {
527
+ success: false,
528
+ error: "Morph Fast Apply not available. Please set MORPH_API_KEY environment variable to use this feature.",
529
+ };
530
+ }
531
+ return await this.morphEditor.editFile(args.target_file, args.instructions, args.code_edit);
532
+ case "bash":
533
+ return await this.bash.execute(args.command);
534
+ case "create_todo_list":
535
+ return await this.todoTool.createTodoList(args.todos);
536
+ case "update_todo_list":
537
+ return await this.todoTool.updateTodoList(args.updates);
538
+ case "search":
539
+ return await this.search.search(args.query, {
540
+ searchType: args.search_type,
541
+ includePattern: args.include_pattern,
542
+ excludePattern: args.exclude_pattern,
543
+ caseSensitive: args.case_sensitive,
544
+ wholeWord: args.whole_word,
545
+ regex: args.regex,
546
+ maxResults: args.max_results,
547
+ fileTypes: args.file_types,
548
+ includeHidden: args.include_hidden,
549
+ });
550
+ default:
551
+ // Check if this is an MCP tool
552
+ if (toolCall.function.name.startsWith("mcp__")) {
553
+ return await this.executeMCPTool(toolCall);
554
+ }
555
+ return {
556
+ success: false,
557
+ error: `Unknown tool: ${toolCall.function.name}`,
558
+ };
559
+ }
560
+ }
561
+ catch (error) {
562
+ return {
563
+ success: false,
564
+ error: `Tool execution error: ${error.message}`,
565
+ };
566
+ }
567
+ }
568
+ async executeMCPTool(toolCall) {
569
+ try {
570
+ const args = JSON.parse(toolCall.function.arguments);
571
+ const mcpManager = getMCPManager();
572
+ const result = await mcpManager.callTool(toolCall.function.name, args);
573
+ if (result.isError) {
574
+ return {
575
+ success: false,
576
+ error: result.content[0]?.text || "MCP tool error",
577
+ };
578
+ }
579
+ // Extract content from result
580
+ const output = result.content
581
+ .map((item) => {
582
+ if (item.type === "text") {
583
+ return item.text;
584
+ }
585
+ else if (item.type === "resource") {
586
+ return `Resource: ${item.resource?.uri || "Unknown"}`;
587
+ }
588
+ return String(item);
589
+ })
590
+ .join("\n");
591
+ return {
592
+ success: true,
593
+ output: output || "Success",
594
+ };
595
+ }
596
+ catch (error) {
597
+ return {
598
+ success: false,
599
+ error: `MCP tool execution error: ${error.message}`,
600
+ };
601
+ }
602
+ }
603
+ getChatHistory() {
604
+ return [...this.chatHistory];
605
+ }
606
+ getCurrentDirectory() {
607
+ return this.bash.getCurrentDirectory();
608
+ }
609
+ async executeBashCommand(command) {
610
+ return await this.bash.execute(command);
611
+ }
612
+ getCurrentModel() {
613
+ return this.grokClient.getCurrentModel();
614
+ }
615
+ setModel(model) {
616
+ this.grokClient.setModel(model);
617
+ // Update token counter for new model
618
+ this.tokenCounter.dispose();
619
+ this.tokenCounter = createTokenCounter(model);
620
+ }
621
+ abortCurrentOperation() {
622
+ if (this.abortController) {
623
+ this.abortController.abort();
624
+ }
625
+ }
626
+ }
627
+ //# sourceMappingURL=grok-agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grok-agent.js","sourceRoot":"","sources":["../../src/agent/grok-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA6B,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EACL,eAAe,EACf,aAAa,EACb,oBAAoB,GACrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EACL,cAAc,EACd,eA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