grok-cli-hurry-mode 1.0.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.
- package/.grok/settings.json +3 -0
- package/LICENSE +21 -0
- package/README.md +452 -0
- package/dist/agent/grok-agent.d.ts +54 -0
- package/dist/agent/grok-agent.js +674 -0
- package/dist/agent/grok-agent.js.map +1 -0
- package/dist/agent/index.d.ts +14 -0
- package/dist/agent/index.js +137 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/commands/mcp.d.ts +2 -0
- package/dist/commands/mcp.js +245 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/grok/client.d.ts +49 -0
- package/dist/grok/client.js +85 -0
- package/dist/grok/client.js.map +1 -0
- package/dist/grok/tools.d.ts +8 -0
- package/dist/grok/tools.js +357 -0
- package/dist/grok/tools.js.map +1 -0
- package/dist/hooks/use-enhanced-input.d.ts +37 -0
- package/dist/hooks/use-enhanced-input.js +217 -0
- package/dist/hooks/use-enhanced-input.js.map +1 -0
- package/dist/hooks/use-input-handler.d.ts +34 -0
- package/dist/hooks/use-input-handler.js +611 -0
- package/dist/hooks/use-input-handler.js.map +1 -0
- package/dist/hooks/use-input-history.d.ts +9 -0
- package/dist/hooks/use-input-history.js +64 -0
- package/dist/hooks/use-input-history.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +151949 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/client.d.ts +29 -0
- package/dist/mcp/client.js +167 -0
- package/dist/mcp/client.js.map +1 -0
- package/dist/mcp/config.d.ts +13 -0
- package/dist/mcp/config.js +51 -0
- package/dist/mcp/config.js.map +1 -0
- package/dist/mcp/transports.d.ts +51 -0
- package/dist/mcp/transports.js +229 -0
- package/dist/mcp/transports.js.map +1 -0
- package/dist/node_modules/react/index.js +1841 -0
- package/dist/tools/bash.d.ts +10 -0
- package/dist/tools/bash.js +81 -0
- package/dist/tools/bash.js.map +1 -0
- package/dist/tools/confirmation-tool.d.ts +16 -0
- package/dist/tools/confirmation-tool.js +75 -0
- package/dist/tools/confirmation-tool.js.map +1 -0
- package/dist/tools/index.d.ts +6 -0
- package/dist/tools/index.js +16 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/morph-editor.d.ts +36 -0
- package/dist/tools/morph-editor.js +347 -0
- package/dist/tools/morph-editor.js.map +1 -0
- package/dist/tools/search.d.ts +69 -0
- package/dist/tools/search.js +341 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/tools/text-editor.d.ts +16 -0
- package/dist/tools/text-editor.js +565 -0
- package/dist/tools/text-editor.js.map +1 -0
- package/dist/tools/todo-tool.d.ts +20 -0
- package/dist/tools/todo-tool.js +135 -0
- package/dist/tools/todo-tool.js.map +1 -0
- package/dist/types/index.d.ts +30 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/ui/app.d.ts +7 -0
- package/dist/ui/app.js +160 -0
- package/dist/ui/app.js.map +1 -0
- package/dist/ui/components/api-key-input.d.ts +7 -0
- package/dist/ui/components/api-key-input.js +124 -0
- package/dist/ui/components/api-key-input.js.map +1 -0
- package/dist/ui/components/chat-history.d.ts +8 -0
- package/dist/ui/components/chat-history.js +177 -0
- package/dist/ui/components/chat-history.js.map +1 -0
- package/dist/ui/components/chat-input.d.ts +9 -0
- package/dist/ui/components/chat-input.js +87 -0
- package/dist/ui/components/chat-input.js.map +1 -0
- package/dist/ui/components/chat-interface.d.ts +8 -0
- package/dist/ui/components/chat-interface.js +344 -0
- package/dist/ui/components/chat-interface.js.map +1 -0
- package/dist/ui/components/command-suggestions.d.ts +17 -0
- package/dist/ui/components/command-suggestions.js +68 -0
- package/dist/ui/components/command-suggestions.js.map +1 -0
- package/dist/ui/components/confirmation-dialog.d.ts +11 -0
- package/dist/ui/components/confirmation-dialog.js +167 -0
- package/dist/ui/components/confirmation-dialog.js.map +1 -0
- package/dist/ui/components/diff-renderer.d.ts +13 -0
- package/dist/ui/components/diff-renderer.js +217 -0
- package/dist/ui/components/diff-renderer.js.map +1 -0
- package/dist/ui/components/loading-spinner.d.ts +8 -0
- package/dist/ui/components/loading-spinner.js +92 -0
- package/dist/ui/components/loading-spinner.js.map +1 -0
- package/dist/ui/components/mcp-status.d.ts +5 -0
- package/dist/ui/components/mcp-status.js +74 -0
- package/dist/ui/components/mcp-status.js.map +1 -0
- package/dist/ui/components/model-selection.d.ts +12 -0
- package/dist/ui/components/model-selection.js +28 -0
- package/dist/ui/components/model-selection.js.map +1 -0
- package/dist/ui/shared/max-sized-box.d.ts +8 -0
- package/dist/ui/shared/max-sized-box.js +15 -0
- package/dist/ui/shared/max-sized-box.js.map +1 -0
- package/dist/ui/utils/code-colorizer.d.ts +2 -0
- package/dist/ui/utils/code-colorizer.js +18 -0
- package/dist/ui/utils/code-colorizer.js.map +1 -0
- package/dist/ui/utils/colors.d.ts +14 -0
- package/dist/ui/utils/colors.js +18 -0
- package/dist/ui/utils/colors.js.map +1 -0
- package/dist/ui/utils/markdown-renderer.d.ts +4 -0
- package/dist/ui/utils/markdown-renderer.js +29 -0
- package/dist/ui/utils/markdown-renderer.js.map +1 -0
- package/dist/utils/confirmation-service.d.ts +33 -0
- package/dist/utils/confirmation-service.js +113 -0
- package/dist/utils/confirmation-service.js.map +1 -0
- package/dist/utils/custom-instructions.d.ts +1 -0
- package/dist/utils/custom-instructions.js +53 -0
- package/dist/utils/custom-instructions.js.map +1 -0
- package/dist/utils/model-config.d.ts +28 -0
- package/dist/utils/model-config.js +49 -0
- package/dist/utils/model-config.js.map +1 -0
- package/dist/utils/settings-manager.d.ts +94 -0
- package/dist/utils/settings-manager.js +275 -0
- package/dist/utils/settings-manager.js.map +1 -0
- package/dist/utils/settings.d.ts +1 -0
- package/dist/utils/settings.js +8 -0
- package/dist/utils/settings.js.map +1 -0
- package/dist/utils/text-utils.d.ts +80 -0
- package/dist/utils/text-utils.js +197 -0
- package/dist/utils/text-utils.js.map +1 -0
- package/dist/utils/token-counter.d.ts +33 -0
- package/dist/utils/token-counter.js +83 -0
- package/dist/utils/token-counter.js.map +1 -0
- package/dist/yoga.wasm +0 -0
- package/eslint.config.mjs +28 -0
- package/fix.awk +41 -0
- package/grok-logo-screenshot.png +0 -0
- package/package.json +68 -0
- package/sed_cmd.sh +35 -0
- package/temp.txt +29 -0
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) [year] [copyright holders]
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission statement shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1,452 @@
|
|
1
|
+
# Grok CLI
|
2
|
+
|
3
|
+
A conversational AI CLI tool powered by Grok with intelligent text editor capabilities and tool usage.
|
4
|
+
|
5
|
+
<img width="980" height="435" alt="Grok CLI Logo with HURRY MODE and Version" src="https://github.com/hinetapora/grok-cli-hurry-mode/releases/download/v0.0.33/grok-logo-screenshot.png" />
|
6
|
+
|
7
|
+
## Features
|
8
|
+
|
9
|
+
- **🤖 Conversational AI**: Natural language interface powered by Grok-3
|
10
|
+
- **📝 Smart File Operations**: AI automatically uses tools to view, create, and edit files
|
11
|
+
- **⚡ Bash Integration**: Execute shell commands through natural conversation
|
12
|
+
- **🔧 Automatic Tool Selection**: AI intelligently chooses the right tools for your requests
|
13
|
+
- **🚀 Morph Fast Apply**: Optional high-speed code editing at 4,500+ tokens/sec with 98% accuracy
|
14
|
+
- **🔌 MCP Tools**: Extend capabilities with Model Context Protocol servers (Linear, GitHub, etc.)
|
15
|
+
- **💬 Interactive UI**: Beautiful terminal interface built with Ink
|
16
|
+
- **🌍 Global Installation**: Install and use anywhere with `bun add -g grok-cli-hurry-mode`
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
### Prerequisites
|
21
|
+
- Node.js 20+ (Bun 1.0+ recommended for development)
|
22
|
+
- Grok API key from X.AI
|
23
|
+
- (Optional, Recommended) Morph API key for Fast Apply editing
|
24
|
+
|
25
|
+
### Global Installation (Recommended)
|
26
|
+
```bash
|
27
|
+
bun add -g grok-cli-hurry-mode
|
28
|
+
```
|
29
|
+
|
30
|
+
Or with npm (fallback):
|
31
|
+
```bash
|
32
|
+
npm install -g grok-cli-hurry-mode
|
33
|
+
```
|
34
|
+
|
35
|
+
### Local Development
|
36
|
+
```bash
|
37
|
+
git clone <repository>
|
38
|
+
cd grok-cli
|
39
|
+
npm install
|
40
|
+
npm run build
|
41
|
+
npm link
|
42
|
+
```
|
43
|
+
|
44
|
+
## Setup
|
45
|
+
|
46
|
+
1. Get your Grok API key from [X.AI](https://x.ai)
|
47
|
+
|
48
|
+
2. Set up your API key (choose one method):
|
49
|
+
|
50
|
+
**Method 1: Environment Variable**
|
51
|
+
```bash
|
52
|
+
export GROK_API_KEY=your_api_key_here
|
53
|
+
```
|
54
|
+
|
55
|
+
**Method 2: .env File**
|
56
|
+
```bash
|
57
|
+
cp .env.example .env
|
58
|
+
# Edit .env and add your API key
|
59
|
+
```
|
60
|
+
|
61
|
+
**Method 3: Command Line Flag**
|
62
|
+
```bash
|
63
|
+
grok --api-key your_api_key_here
|
64
|
+
```
|
65
|
+
|
66
|
+
**Method 4: User Settings File**
|
67
|
+
Create `~/.grok/user-settings.json`:
|
68
|
+
```json
|
69
|
+
{
|
70
|
+
"apiKey": "your_api_key_here"
|
71
|
+
}
|
72
|
+
```
|
73
|
+
|
74
|
+
3. (Optional, Recommended) Get your Morph API key from [Morph Dashboard](https://morphllm.com/dashboard/api-keys)
|
75
|
+
|
76
|
+
4. Set up your Morph API key for Fast Apply editing (choose one method):
|
77
|
+
|
78
|
+
**Method 1: Environment Variable**
|
79
|
+
```bash
|
80
|
+
export MORPH_API_KEY=your_morph_api_key_here
|
81
|
+
```
|
82
|
+
|
83
|
+
**Method 2: .env File**
|
84
|
+
```bash
|
85
|
+
# Add to your .env file
|
86
|
+
MORPH_API_KEY=your_morph_api_key_here
|
87
|
+
```
|
88
|
+
|
89
|
+
### Custom Base URL (Optional)
|
90
|
+
|
91
|
+
By default, the CLI uses `https://api.x.ai/v1` as the Grok API endpoint. You can configure a custom endpoint if needed (choose one method):
|
92
|
+
|
93
|
+
**Method 1: Environment Variable**
|
94
|
+
```bash
|
95
|
+
export GROK_BASE_URL=https://your-custom-endpoint.com/v1
|
96
|
+
```
|
97
|
+
|
98
|
+
**Method 2: Command Line Flag**
|
99
|
+
```bash
|
100
|
+
grok --api-key your_api_key_here --base-url https://your-custom-endpoint.com/v1
|
101
|
+
```
|
102
|
+
|
103
|
+
**Method 3: User Settings File**
|
104
|
+
Add to `~/.grok/user-settings.json`:
|
105
|
+
```json
|
106
|
+
{
|
107
|
+
"apiKey": "your_api_key_here",
|
108
|
+
"baseURL": "https://your-custom-endpoint.com/v1"
|
109
|
+
}
|
110
|
+
```
|
111
|
+
|
112
|
+
## Configuration Files
|
113
|
+
|
114
|
+
Grok CLI uses two types of configuration files to manage settings:
|
115
|
+
|
116
|
+
### User-Level Settings (`~/.grok/user-settings.json`)
|
117
|
+
|
118
|
+
This file stores **global settings** that apply across all projects. These settings rarely change and include:
|
119
|
+
|
120
|
+
- **API Key**: Your Grok API key
|
121
|
+
- **Base URL**: Custom API endpoint (if needed)
|
122
|
+
- **Default Model**: Your preferred model (e.g., `grok-code-fast-1`)
|
123
|
+
- **Available Models**: List of models you can use
|
124
|
+
|
125
|
+
**Example:**
|
126
|
+
```json
|
127
|
+
{
|
128
|
+
"apiKey": "your_api_key_here",
|
129
|
+
"baseURL": "https://api.x.ai/v1",
|
130
|
+
"defaultModel": "grok-code-fast-1",
|
131
|
+
"models": [
|
132
|
+
"grok-code-fast-1",
|
133
|
+
"grok-4-latest",
|
134
|
+
"grok-3-latest",
|
135
|
+
"grok-3-fast",
|
136
|
+
"grok-3-mini-fast"
|
137
|
+
]
|
138
|
+
}
|
139
|
+
```
|
140
|
+
|
141
|
+
### Project-Level Settings (`.grok/settings.json`)
|
142
|
+
|
143
|
+
This file stores **project-specific settings** in your current working directory. It includes:
|
144
|
+
|
145
|
+
- **Current Model**: The model currently in use for this project
|
146
|
+
- **MCP Servers**: Model Context Protocol server configurations
|
147
|
+
|
148
|
+
**Example:**
|
149
|
+
```json
|
150
|
+
{
|
151
|
+
"model": "grok-3-fast",
|
152
|
+
"mcpServers": {
|
153
|
+
"linear": {
|
154
|
+
"name": "linear",
|
155
|
+
"transport": "stdio",
|
156
|
+
"command": "npx",
|
157
|
+
"args": ["@linear/mcp-server"]
|
158
|
+
}
|
159
|
+
}
|
160
|
+
}
|
161
|
+
```
|
162
|
+
|
163
|
+
### How It Works
|
164
|
+
|
165
|
+
1. **Global Defaults**: User-level settings provide your default preferences
|
166
|
+
2. **Project Override**: Project-level settings override defaults for specific projects
|
167
|
+
3. **Directory-Specific**: When you change directories, project settings are loaded automatically
|
168
|
+
4. **Fallback Logic**: Project model → User default model → System default (`grok-code-fast-1`)
|
169
|
+
|
170
|
+
This means you can have different models for different projects while maintaining consistent global settings like your API key.
|
171
|
+
|
172
|
+
### Using Other API Providers
|
173
|
+
|
174
|
+
**Important**: Grok CLI uses **OpenAI-compatible APIs**. You can use any provider that implements the OpenAI chat completions standard.
|
175
|
+
|
176
|
+
**Popular Providers**:
|
177
|
+
- **X.AI (Grok)**: `https://api.x.ai/v1` (default)
|
178
|
+
- **OpenAI**: `https://api.openai.com/v1`
|
179
|
+
- **OpenRouter**: `https://openrouter.ai/api/v1`
|
180
|
+
- **Groq**: `https://api.groq.com/openai/v1`
|
181
|
+
|
182
|
+
**Example with OpenRouter**:
|
183
|
+
```json
|
184
|
+
{
|
185
|
+
"apiKey": "your_openrouter_key",
|
186
|
+
"baseURL": "https://openrouter.ai/api/v1",
|
187
|
+
"defaultModel": "anthropic/claude-3.5-sonnet",
|
188
|
+
"models": [
|
189
|
+
"anthropic/claude-3.5-sonnet",
|
190
|
+
"openai/gpt-4o",
|
191
|
+
"meta-llama/llama-3.1-70b-instruct"
|
192
|
+
]
|
193
|
+
}
|
194
|
+
```
|
195
|
+
|
196
|
+
## Usage
|
197
|
+
|
198
|
+
### Interactive Mode
|
199
|
+
|
200
|
+
Start the conversational AI assistant:
|
201
|
+
```bash
|
202
|
+
grok
|
203
|
+
```
|
204
|
+
|
205
|
+
Or specify a working directory:
|
206
|
+
```bash
|
207
|
+
grok -d /path/to/project
|
208
|
+
```
|
209
|
+
|
210
|
+
### Headless Mode
|
211
|
+
|
212
|
+
Process a single prompt and exit (useful for scripting and automation):
|
213
|
+
```bash
|
214
|
+
grok --prompt "show me the package.json file"
|
215
|
+
grok -p "create a new file called example.js with a hello world function"
|
216
|
+
grok --prompt "run bun test and show me the results" --directory /path/to/project
|
217
|
+
grok --prompt "complex task" --max-tool-rounds 50 # Limit tool usage for faster execution
|
218
|
+
```
|
219
|
+
|
220
|
+
This mode is particularly useful for:
|
221
|
+
- **CI/CD pipelines**: Automate code analysis and file operations
|
222
|
+
- **Scripting**: Integrate AI assistance into shell scripts
|
223
|
+
- **Terminal benchmarks**: Perfect for tools like Terminal Bench that need non-interactive execution
|
224
|
+
- **Batch processing**: Process multiple prompts programmatically
|
225
|
+
|
226
|
+
### Tool Execution Control
|
227
|
+
|
228
|
+
By default, Grok CLI allows up to 400 tool execution rounds to handle complex multi-step tasks. You can control this behavior:
|
229
|
+
|
230
|
+
```bash
|
231
|
+
# Limit tool rounds for faster execution on simple tasks
|
232
|
+
grok --max-tool-rounds 10 --prompt "show me the current directory"
|
233
|
+
|
234
|
+
# Increase limit for very complex tasks (use with caution)
|
235
|
+
grok --max-tool-rounds 1000 --prompt "comprehensive code refactoring"
|
236
|
+
|
237
|
+
# Works with all modes
|
238
|
+
grok --max-tool-rounds 20 # Interactive mode
|
239
|
+
grok git commit-and-push --max-tool-rounds 30 # Git commands
|
240
|
+
```
|
241
|
+
|
242
|
+
**Use Cases**:
|
243
|
+
- **Fast responses**: Lower limits (10-50) for simple queries
|
244
|
+
- **Complex automation**: Higher limits (500+) for comprehensive tasks
|
245
|
+
- **Resource control**: Prevent runaway executions in automated environments
|
246
|
+
|
247
|
+
### Model Selection
|
248
|
+
|
249
|
+
You can specify which AI model to use with the `--model` parameter or `GROK_MODEL` environment variable:
|
250
|
+
|
251
|
+
**Method 1: Command Line Flag**
|
252
|
+
```bash
|
253
|
+
# Use Grok models
|
254
|
+
grok --model grok-code-fast-1
|
255
|
+
grok --model grok-4-latest
|
256
|
+
grok --model grok-3-latest
|
257
|
+
grok --model grok-3-fast
|
258
|
+
|
259
|
+
# Use other models (with appropriate API endpoint)
|
260
|
+
grok --model gemini-2.5-pro --base-url https://api-endpoint.com/v1
|
261
|
+
grok --model claude-sonnet-4-20250514 --base-url https://api-endpoint.com/v1
|
262
|
+
```
|
263
|
+
|
264
|
+
**Method 2: Environment Variable**
|
265
|
+
```bash
|
266
|
+
export GROK_MODEL=grok-code-fast-1
|
267
|
+
grok
|
268
|
+
```
|
269
|
+
|
270
|
+
**Method 3: User Settings File**
|
271
|
+
Add to `~/.grok/user-settings.json`:
|
272
|
+
```json
|
273
|
+
{
|
274
|
+
"apiKey": "your_api_key_here",
|
275
|
+
"defaultModel": "grok-code-fast-1"
|
276
|
+
}
|
277
|
+
```
|
278
|
+
|
279
|
+
**Model Priority**: `--model` flag > `GROK_MODEL` environment variable > user default model > system default (grok-code-fast-1)
|
280
|
+
|
281
|
+
### Command Line Options
|
282
|
+
|
283
|
+
```bash
|
284
|
+
grok [options]
|
285
|
+
|
286
|
+
Options:
|
287
|
+
-V, --version output the version number
|
288
|
+
-d, --directory <dir> set working directory
|
289
|
+
-k, --api-key <key> Grok API key (or set GROK_API_KEY env var)
|
290
|
+
-u, --base-url <url> Grok API base URL (or set GROK_BASE_URL env var)
|
291
|
+
-m, --model <model> AI model to use (e.g., grok-code-fast-1, grok-4-latest) (or set GROK_MODEL env var)
|
292
|
+
-p, --prompt <prompt> process a single prompt and exit (headless mode)
|
293
|
+
--max-tool-rounds <rounds> maximum number of tool execution rounds (default: 400)
|
294
|
+
-h, --help display help for command
|
295
|
+
```
|
296
|
+
|
297
|
+
### Custom Instructions
|
298
|
+
|
299
|
+
You can provide custom instructions to tailor Grok's behavior to your project by creating a `.grok/GROK.md` file in your project directory:
|
300
|
+
|
301
|
+
```bash
|
302
|
+
mkdir .grok
|
303
|
+
```
|
304
|
+
|
305
|
+
Create `.grok/GROK.md` with your custom instructions:
|
306
|
+
```markdown
|
307
|
+
# Custom Instructions for Grok CLI
|
308
|
+
|
309
|
+
Always use TypeScript for any new code files.
|
310
|
+
When creating React components, use functional components with hooks.
|
311
|
+
Prefer const assertions and explicit typing over inference where it improves clarity.
|
312
|
+
Always add JSDoc comments for public functions and interfaces.
|
313
|
+
Follow the existing code style and patterns in this project.
|
314
|
+
```
|
315
|
+
|
316
|
+
Grok will automatically load and follow these instructions when working in your project directory. The custom instructions are added to Grok's system prompt and take priority over default behavior.
|
317
|
+
|
318
|
+
## Morph Fast Apply (Optional)
|
319
|
+
|
320
|
+
Grok CLI supports Morph's Fast Apply model for high-speed code editing at **4,500+ tokens/sec with 98% accuracy**. This is an optional feature that provides lightning-fast file editing capabilities.
|
321
|
+
|
322
|
+
**Setup**: Configure your Morph API key following the [setup instructions](#setup) above.
|
323
|
+
|
324
|
+
### How It Works
|
325
|
+
|
326
|
+
When `MORPH_API_KEY` is configured:
|
327
|
+
- **`edit_file` tool becomes available** alongside the standard `str_replace_editor`
|
328
|
+
- **Optimized for complex edits**: Use for multi-line changes, refactoring, and large modifications
|
329
|
+
- **Intelligent editing**: Uses abbreviated edit format with `// ... existing code ...` comments
|
330
|
+
- **Fallback support**: Standard tools remain available if Morph is unavailable
|
331
|
+
|
332
|
+
**When to use each tool:**
|
333
|
+
- **`edit_file`** (Morph): Complex edits, refactoring, multi-line changes
|
334
|
+
- **`str_replace_editor`**: Simple text replacements, single-line edits
|
335
|
+
|
336
|
+
### Example Usage
|
337
|
+
|
338
|
+
With Morph Fast Apply configured, you can request complex code changes:
|
339
|
+
|
340
|
+
```bash
|
341
|
+
grok --prompt "refactor this function to use async/await and add error handling"
|
342
|
+
grok -p "convert this class to TypeScript and add proper type annotations"
|
343
|
+
```
|
344
|
+
|
345
|
+
The AI will automatically choose between `edit_file` (Morph) for complex changes or `str_replace_editor` for simple replacements.
|
346
|
+
|
347
|
+
## MCP Tools
|
348
|
+
|
349
|
+
Grok CLI supports MCP (Model Context Protocol) servers, allowing you to extend the AI assistant with additional tools and capabilities.
|
350
|
+
|
351
|
+
### Adding MCP Tools
|
352
|
+
|
353
|
+
#### Add a custom MCP server:
|
354
|
+
```bash
|
355
|
+
# Add an stdio-based MCP server
|
356
|
+
grok mcp add my-server --transport stdio --command "bun" --args server.js
|
357
|
+
|
358
|
+
# Add an HTTP-based MCP server
|
359
|
+
grok mcp add my-server --transport http --url "http://localhost:3000"
|
360
|
+
|
361
|
+
# Add with environment variables
|
362
|
+
grok mcp add my-server --transport stdio --command "python" --args "-m" "my_mcp_server" --env "API_KEY=your_key"
|
363
|
+
```
|
364
|
+
|
365
|
+
#### Add from JSON configuration:
|
366
|
+
```bash
|
367
|
+
grok mcp add-json my-server '{"command": "bun", "args": ["server.js"], "env": {"API_KEY": "your_key"}}'
|
368
|
+
```
|
369
|
+
|
370
|
+
### Linear Integration Example
|
371
|
+
|
372
|
+
To add Linear MCP tools for project management:
|
373
|
+
|
374
|
+
```bash
|
375
|
+
# Add Linear MCP server
|
376
|
+
grok mcp add linear --transport sse --url "https://mcp.linear.app/sse"
|
377
|
+
```
|
378
|
+
|
379
|
+
This enables Linear tools like:
|
380
|
+
- Create and manage Linear issues
|
381
|
+
- Search and filter issues
|
382
|
+
- Update issue status and assignees
|
383
|
+
- Access team and project information
|
384
|
+
|
385
|
+
### Managing MCP Servers
|
386
|
+
|
387
|
+
```bash
|
388
|
+
# List all configured servers
|
389
|
+
grok mcp list
|
390
|
+
|
391
|
+
# Test server connection
|
392
|
+
grok mcp test server-name
|
393
|
+
|
394
|
+
# Remove a server
|
395
|
+
grok mcp remove server-name
|
396
|
+
```
|
397
|
+
|
398
|
+
### Available Transport Types
|
399
|
+
|
400
|
+
- **stdio**: Run MCP server as a subprocess (most common)
|
401
|
+
- **http**: Connect to HTTP-based MCP server
|
402
|
+
- **sse**: Connect via Server-Sent Events
|
403
|
+
|
404
|
+
## Development
|
405
|
+
|
406
|
+
```bash
|
407
|
+
# Install dependencies
|
408
|
+
npm install
|
409
|
+
|
410
|
+
# Development mode
|
411
|
+
bun run dev
|
412
|
+
|
413
|
+
# Build project
|
414
|
+
npm run build
|
415
|
+
|
416
|
+
# Run linter
|
417
|
+
bun run lint
|
418
|
+
|
419
|
+
# Type check
|
420
|
+
bun run typecheck
|
421
|
+
```
|
422
|
+
|
423
|
+
## Architecture
|
424
|
+
|
425
|
+
- **Agent**: Core command processing and execution logic
|
426
|
+
- **Tools**: Text editor and bash tool implementations
|
427
|
+
- **UI**: Ink-based terminal interface components
|
428
|
+
- **Types**: TypeScript definitions for the entire system
|
429
|
+
|
430
|
+
## License
|
431
|
+
|
432
|
+
MIT
|
433
|
+
|
434
|
+
## Troubleshooting
|
435
|
+
|
436
|
+
### Tool Execution Errors
|
437
|
+
|
438
|
+
If you encounter errors like `fs.readFile is not a function` or `fs.stat is not a function` when using file operations:
|
439
|
+
|
440
|
+
1. **This is a known issue** with the tool infrastructure
|
441
|
+
2. **Automatic fallback**: The CLI will automatically fall back to bash commands for file operations
|
442
|
+
3. **Warning messages**: You may see console warnings like "str_replace_editor tool failed, falling back to bash"
|
443
|
+
4. **Functionality**: Despite the warnings, operations should still work via bash fallbacks
|
444
|
+
|
445
|
+
This issue is being tracked and the fallbacks ensure the CLI remains functional.
|
446
|
+
|
447
|
+
### Common Issues
|
448
|
+
|
449
|
+
- **File operations fail**: Check that the file path exists and is accessible
|
450
|
+
- **Bash commands fail**: Ensure you have the necessary permissions
|
451
|
+
- **Tool timeouts**: Complex operations may take time; the spinner indicates progress
|
452
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import { GrokToolCall } from "../grok/client.js";
|
2
|
+
import { ToolResult } from "../types/index.js";
|
3
|
+
import { EventEmitter } from "events";
|
4
|
+
export interface ChatEntry {
|
5
|
+
type: "user" | "assistant" | "tool_result" | "tool_call";
|
6
|
+
content: string;
|
7
|
+
timestamp: Date;
|
8
|
+
toolCalls?: GrokToolCall[];
|
9
|
+
toolCall?: GrokToolCall;
|
10
|
+
toolResult?: {
|
11
|
+
success: boolean;
|
12
|
+
output?: string;
|
13
|
+
error?: string;
|
14
|
+
};
|
15
|
+
isStreaming?: boolean;
|
16
|
+
}
|
17
|
+
export interface StreamingChunk {
|
18
|
+
type: "content" | "tool_calls" | "tool_result" | "done" | "token_count";
|
19
|
+
content?: string;
|
20
|
+
toolCalls?: GrokToolCall[];
|
21
|
+
toolCall?: GrokToolCall;
|
22
|
+
toolResult?: ToolResult;
|
23
|
+
tokenCount?: number;
|
24
|
+
}
|
25
|
+
export declare class GrokAgent extends EventEmitter {
|
26
|
+
private grokClient;
|
27
|
+
private textEditor;
|
28
|
+
private morphEditor;
|
29
|
+
private bash;
|
30
|
+
private todoTool;
|
31
|
+
private confirmationTool;
|
32
|
+
private search;
|
33
|
+
private chatHistory;
|
34
|
+
private messages;
|
35
|
+
private tokenCounter;
|
36
|
+
private abortController;
|
37
|
+
private mcpInitialized;
|
38
|
+
private maxToolRounds;
|
39
|
+
constructor(apiKey: string, baseURL?: string, model?: string, maxToolRounds?: number);
|
40
|
+
private initializeMCP;
|
41
|
+
private isGrokModel;
|
42
|
+
private shouldUseSearchFor;
|
43
|
+
processUserMessage(message: string): Promise<ChatEntry[]>;
|
44
|
+
private messageReducer;
|
45
|
+
processUserMessageStream(message: string): AsyncGenerator<StreamingChunk, void, unknown>;
|
46
|
+
private executeTool;
|
47
|
+
private executeMCPTool;
|
48
|
+
getChatHistory(): ChatEntry[];
|
49
|
+
getCurrentDirectory(): string;
|
50
|
+
executeBashCommand(command: string): Promise<ToolResult>;
|
51
|
+
getCurrentModel(): string;
|
52
|
+
setModel(model: string): void;
|
53
|
+
abortCurrentOperation(): void;
|
54
|
+
}
|