grok-dev 1.0.0-rc1
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/.cursor/rules/development-workflow.mdc +66 -0
- package/.cursor/rules/project-overview.mdc +66 -0
- package/.cursor/rules/react-ink-components.mdc +45 -0
- package/.cursor/rules/tools-and-agent.mdc +62 -0
- package/.cursor/rules/typescript-conventions.mdc +54 -0
- package/.grok/settings.json +3 -0
- package/.husky/pre-commit +1 -0
- package/LICENSE +21 -0
- package/README.md +526 -0
- package/biome.json +51 -0
- package/dist/agent/agent.d.ts +62 -0
- package/dist/agent/agent.js +701 -0
- package/dist/agent/agent.js.map +1 -0
- package/dist/agent/delegations.d.ts +42 -0
- package/dist/agent/delegations.js +273 -0
- package/dist/agent/delegations.js.map +1 -0
- package/dist/grok/client.d.ts +12 -0
- package/dist/grok/client.js +37 -0
- package/dist/grok/client.js.map +1 -0
- package/dist/grok/models.d.ts +5 -0
- package/dist/grok/models.js +73 -0
- package/dist/grok/models.js.map +1 -0
- package/dist/grok/tools.d.ts +12 -0
- package/dist/grok/tools.js +230 -0
- package/dist/grok/tools.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +192 -0
- package/dist/index.js.map +1 -0
- package/dist/storage/db.d.ts +18 -0
- package/dist/storage/db.js +71 -0
- package/dist/storage/db.js.map +1 -0
- package/dist/storage/index.d.ts +4 -0
- package/dist/storage/index.js +5 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/migrations.d.ts +2 -0
- package/dist/storage/migrations.js +92 -0
- package/dist/storage/migrations.js.map +1 -0
- package/dist/storage/sessions.d.ts +15 -0
- package/dist/storage/sessions.js +135 -0
- package/dist/storage/sessions.js.map +1 -0
- package/dist/storage/transcript.d.ts +6 -0
- package/dist/storage/transcript.js +261 -0
- package/dist/storage/transcript.js.map +1 -0
- package/dist/storage/usage.d.ts +9 -0
- package/dist/storage/usage.js +58 -0
- package/dist/storage/usage.js.map +1 -0
- package/dist/storage/workspaces.d.ts +9 -0
- package/dist/storage/workspaces.js +60 -0
- package/dist/storage/workspaces.js.map +1 -0
- package/dist/telegram/bridge.d.ts +39 -0
- package/dist/telegram/bridge.js +164 -0
- package/dist/telegram/bridge.js.map +1 -0
- package/dist/telegram/index.d.ts +3 -0
- package/dist/telegram/index.js +4 -0
- package/dist/telegram/index.js.map +1 -0
- package/dist/telegram/limits.d.ts +3 -0
- package/dist/telegram/limits.js +12 -0
- package/dist/telegram/limits.js.map +1 -0
- package/dist/telegram/pairing.d.ts +9 -0
- package/dist/telegram/pairing.js +30 -0
- package/dist/telegram/pairing.js.map +1 -0
- package/dist/telegram/preview-stream.d.ts +22 -0
- package/dist/telegram/preview-stream.js +181 -0
- package/dist/telegram/preview-stream.js.map +1 -0
- package/dist/telegram/turn-coordinator.d.ts +7 -0
- package/dist/telegram/turn-coordinator.js +14 -0
- package/dist/telegram/turn-coordinator.js.map +1 -0
- package/dist/telegram/typing-refresh.d.ts +3 -0
- package/dist/telegram/typing-refresh.js +12 -0
- package/dist/telegram/typing-refresh.js.map +1 -0
- package/dist/tools/bash.d.ts +27 -0
- package/dist/tools/bash.js +261 -0
- package/dist/tools/bash.js.map +1 -0
- package/dist/tools/file.d.ts +15 -0
- package/dist/tools/file.js +94 -0
- package/dist/tools/file.js.map +1 -0
- package/dist/types/index.d.ts +151 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/ui/app.d.ts +15 -0
- package/dist/ui/app.js +1720 -0
- package/dist/ui/app.js.map +1 -0
- package/dist/ui/markdown.d.ts +5 -0
- package/dist/ui/markdown.js +38 -0
- package/dist/ui/markdown.js.map +1 -0
- package/dist/ui/plan.d.ts +24 -0
- package/dist/ui/plan.js +122 -0
- package/dist/ui/plan.js.map +1 -0
- package/dist/ui/terminal-selection-text.d.ts +23 -0
- package/dist/ui/terminal-selection-text.js +59 -0
- package/dist/ui/terminal-selection-text.js.map +1 -0
- package/dist/ui/theme.d.ts +53 -0
- package/dist/ui/theme.js +53 -0
- package/dist/ui/theme.js.map +1 -0
- package/dist/utils/git-root.d.ts +1 -0
- package/dist/utils/git-root.js +16 -0
- package/dist/utils/git-root.js.map +1 -0
- package/dist/utils/host-clipboard.d.ts +4 -0
- package/dist/utils/host-clipboard.js +32 -0
- package/dist/utils/host-clipboard.js.map +1 -0
- package/dist/utils/instructions.d.ts +1 -0
- package/dist/utils/instructions.js +73 -0
- package/dist/utils/instructions.js.map +1 -0
- package/dist/utils/settings.d.ts +33 -0
- package/dist/utils/settings.js +88 -0
- package/dist/utils/settings.js.map +1 -0
- package/dist/utils/skills.d.ts +17 -0
- package/dist/utils/skills.js +161 -0
- package/dist/utils/skills.js.map +1 -0
- package/package.json +67 -0
- package/skills-lock.json +10 -0
- package/tmp/large_class.py +633 -0
package/README.md
ADDED
|
@@ -0,0 +1,526 @@
|
|
|
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="Screenshot 2025-07-21 at 13 35 41" src="https://github.com/user-attachments/assets/192402e3-30a8-47df-9fc8-a084c5696e78" />
|
|
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 @vibe-kit/grok-cli`
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
### Prerequisites
|
|
21
|
+
- Bun 1.0+ (or Node.js 18+ as fallback)
|
|
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 @vibe-kit/grok-cli
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Or with npm (fallback):
|
|
31
|
+
```bash
|
|
32
|
+
npm install -g @vibe-kit/grok-cli
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Local Development
|
|
36
|
+
```bash
|
|
37
|
+
git clone <repository>
|
|
38
|
+
cd grok-cli
|
|
39
|
+
bun install
|
|
40
|
+
bun run build
|
|
41
|
+
bun 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
|
+
### Telegram (optional)
|
|
142
|
+
|
|
143
|
+
You can pair the CLI with a Telegram bot and send prompts from Telegram while the interactive session is running (similar in spirit to [OpenClaw-style channel pairing](https://docs.openclaw.ai/channels/telegram)).
|
|
144
|
+
|
|
145
|
+
1. Create a bot with [@BotFather](https://t.me/BotFather) and copy the bot token.
|
|
146
|
+
2. Set **`TELEGRAM_BOT_TOKEN`** in the environment, or add **`telegram.botToken`** to `~/.grok/user-settings.json` (the `/remote-control` flow can save it for you).
|
|
147
|
+
3. Start `grok`. If the bot token is already in settings or env, **long polling starts automatically** (no need to open **`/remote-control`** every time). Otherwise run **`/remote-control`** → **Telegram** and paste the token.
|
|
148
|
+
4. In Telegram, open a DM with your bot and send **`/pair`** (only needed once per user until you remove them from `approvedUserIds`).
|
|
149
|
+
5. The first time you pair a Telegram user, enter the **6-character code** in the terminal when prompted. After that, approval is remembered in `user-settings.json`.
|
|
150
|
+
6. **Keep the CLI open** while you use the bot — polling runs in that process.
|
|
151
|
+
|
|
152
|
+
Optional env override: `TELEGRAM_BOT_TOKEN`. Approved Telegram user IDs and per-user session mappings are stored under the **`telegram`** object in `user-settings.json`. Treat the bot token like a password.
|
|
153
|
+
|
|
154
|
+
**Optional Telegram UX** (in `~/.grok/user-settings.json` under `telegram`):
|
|
155
|
+
|
|
156
|
+
| Key | Values | Default | Description |
|
|
157
|
+
|-----|--------|---------|-------------|
|
|
158
|
+
| `streaming` | `"partial"` \| `"off"` | `"partial"` | **`partial`**: live preview while the model replies (`sendMessage` + throttled `editMessageText`). **`off`**: buffer the full reply, then send (no preview updates). |
|
|
159
|
+
| `typingIndicator` | boolean | `true` | Send `typing` chat actions on an interval while the agent runs. Set `false` to disable. |
|
|
160
|
+
| `nativeDrafts` | boolean | `false` | Reserved for future Bot API `sendMessageDraft` support (private chats); not used yet. |
|
|
161
|
+
|
|
162
|
+
**Example:**
|
|
163
|
+
|
|
164
|
+
```json
|
|
165
|
+
{
|
|
166
|
+
"telegram": {
|
|
167
|
+
"streaming": "partial",
|
|
168
|
+
"typingIndicator": true
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Project-Level Settings (`.grok/settings.json`)
|
|
174
|
+
|
|
175
|
+
This file stores **project-specific settings** in your current working directory. It includes:
|
|
176
|
+
|
|
177
|
+
- **Current Model**: The model currently in use for this project
|
|
178
|
+
- **MCP Servers**: Model Context Protocol server configurations
|
|
179
|
+
|
|
180
|
+
**Example:**
|
|
181
|
+
```json
|
|
182
|
+
{
|
|
183
|
+
"model": "grok-3-fast",
|
|
184
|
+
"mcpServers": {
|
|
185
|
+
"linear": {
|
|
186
|
+
"name": "linear",
|
|
187
|
+
"transport": "stdio",
|
|
188
|
+
"command": "npx",
|
|
189
|
+
"args": ["@linear/mcp-server"]
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### How It Works
|
|
196
|
+
|
|
197
|
+
1. **Global Defaults**: User-level settings provide your default preferences
|
|
198
|
+
2. **Project Override**: Project-level settings override defaults for specific projects
|
|
199
|
+
3. **Directory-Specific**: When you change directories, project settings are loaded automatically
|
|
200
|
+
4. **Fallback Logic**: Project model → User default model → System default (`grok-code-fast-1`)
|
|
201
|
+
|
|
202
|
+
This means you can have different models for different projects while maintaining consistent global settings like your API key.
|
|
203
|
+
|
|
204
|
+
### Using Other API Providers
|
|
205
|
+
|
|
206
|
+
**Important**: Grok CLI uses **OpenAI-compatible APIs**. You can use any provider that implements the OpenAI chat completions standard.
|
|
207
|
+
|
|
208
|
+
**Popular Providers**:
|
|
209
|
+
- **X.AI (Grok)**: `https://api.x.ai/v1` (default)
|
|
210
|
+
- **OpenAI**: `https://api.openai.com/v1`
|
|
211
|
+
- **OpenRouter**: `https://openrouter.ai/api/v1`
|
|
212
|
+
- **Groq**: `https://api.groq.com/openai/v1`
|
|
213
|
+
|
|
214
|
+
**Example with OpenRouter**:
|
|
215
|
+
```json
|
|
216
|
+
{
|
|
217
|
+
"apiKey": "your_openrouter_key",
|
|
218
|
+
"baseURL": "https://openrouter.ai/api/v1",
|
|
219
|
+
"defaultModel": "anthropic/claude-3.5-sonnet",
|
|
220
|
+
"models": [
|
|
221
|
+
"anthropic/claude-3.5-sonnet",
|
|
222
|
+
"openai/gpt-4o",
|
|
223
|
+
"meta-llama/llama-3.1-70b-instruct"
|
|
224
|
+
]
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## Usage
|
|
229
|
+
|
|
230
|
+
### Interactive Mode
|
|
231
|
+
|
|
232
|
+
Start the conversational AI assistant:
|
|
233
|
+
```bash
|
|
234
|
+
grok
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
Or specify a working directory:
|
|
238
|
+
```bash
|
|
239
|
+
grok -d /path/to/project
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Headless Mode
|
|
243
|
+
|
|
244
|
+
Process a single prompt and exit (useful for scripting and automation):
|
|
245
|
+
```bash
|
|
246
|
+
grok --prompt "show me the package.json file"
|
|
247
|
+
grok -p "create a new file called example.js with a hello world function"
|
|
248
|
+
grok --prompt "run bun test and show me the results" --directory /path/to/project
|
|
249
|
+
grok --prompt "complex task" --max-tool-rounds 50 # Limit tool usage for faster execution
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
This mode is particularly useful for:
|
|
253
|
+
- **CI/CD pipelines**: Automate code analysis and file operations
|
|
254
|
+
- **Scripting**: Integrate AI assistance into shell scripts
|
|
255
|
+
- **Terminal benchmarks**: Perfect for tools like Terminal Bench that need non-interactive execution
|
|
256
|
+
- **Batch processing**: Process multiple prompts programmatically
|
|
257
|
+
|
|
258
|
+
### Tool Execution Control
|
|
259
|
+
|
|
260
|
+
By default, Grok CLI allows up to 400 tool execution rounds to handle complex multi-step tasks. You can control this behavior:
|
|
261
|
+
|
|
262
|
+
```bash
|
|
263
|
+
# Limit tool rounds for faster execution on simple tasks
|
|
264
|
+
grok --max-tool-rounds 10 --prompt "show me the current directory"
|
|
265
|
+
|
|
266
|
+
# Increase limit for very complex tasks (use with caution)
|
|
267
|
+
grok --max-tool-rounds 1000 --prompt "comprehensive code refactoring"
|
|
268
|
+
|
|
269
|
+
# Works with all modes
|
|
270
|
+
grok --max-tool-rounds 20 # Interactive mode
|
|
271
|
+
grok git commit-and-push --max-tool-rounds 30 # Git commands
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
**Use Cases**:
|
|
275
|
+
- **Fast responses**: Lower limits (10-50) for simple queries
|
|
276
|
+
- **Complex automation**: Higher limits (500+) for comprehensive tasks
|
|
277
|
+
- **Resource control**: Prevent runaway executions in automated environments
|
|
278
|
+
|
|
279
|
+
### Model Selection
|
|
280
|
+
|
|
281
|
+
You can specify which AI model to use with the `--model` parameter or `GROK_MODEL` environment variable:
|
|
282
|
+
|
|
283
|
+
**Method 1: Command Line Flag**
|
|
284
|
+
```bash
|
|
285
|
+
# Use Grok models
|
|
286
|
+
grok --model grok-code-fast-1
|
|
287
|
+
grok --model grok-4-latest
|
|
288
|
+
grok --model grok-3-latest
|
|
289
|
+
grok --model grok-3-fast
|
|
290
|
+
|
|
291
|
+
# Use other models (with appropriate API endpoint)
|
|
292
|
+
grok --model gemini-2.5-pro --base-url https://api-endpoint.com/v1
|
|
293
|
+
grok --model claude-sonnet-4-20250514 --base-url https://api-endpoint.com/v1
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
**Method 2: Environment Variable**
|
|
297
|
+
```bash
|
|
298
|
+
export GROK_MODEL=grok-code-fast-1
|
|
299
|
+
grok
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
**Method 3: User Settings File**
|
|
303
|
+
Add to `~/.grok/user-settings.json`:
|
|
304
|
+
```json
|
|
305
|
+
{
|
|
306
|
+
"apiKey": "your_api_key_here",
|
|
307
|
+
"defaultModel": "grok-code-fast-1"
|
|
308
|
+
}
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
**Model Priority**: `--model` flag > `GROK_MODEL` environment variable > user default model > system default (grok-code-fast-1)
|
|
312
|
+
|
|
313
|
+
### Command Line Options
|
|
314
|
+
|
|
315
|
+
```bash
|
|
316
|
+
grok [options]
|
|
317
|
+
|
|
318
|
+
Options:
|
|
319
|
+
-V, --version output the version number
|
|
320
|
+
-d, --directory <dir> set working directory
|
|
321
|
+
-k, --api-key <key> Grok API key (or set GROK_API_KEY env var)
|
|
322
|
+
-u, --base-url <url> Grok API base URL (or set GROK_BASE_URL env var)
|
|
323
|
+
-m, --model <model> AI model to use (e.g., grok-code-fast-1, grok-4-latest) (or set GROK_MODEL env var)
|
|
324
|
+
-p, --prompt <prompt> process a single prompt and exit (headless mode)
|
|
325
|
+
--max-tool-rounds <rounds> maximum number of tool execution rounds (default: 400)
|
|
326
|
+
-h, --help display help for command
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
### Custom Instructions
|
|
330
|
+
|
|
331
|
+
Grok CLI loads markdown instructions from two ecosystems and merges them into the system prompt:
|
|
332
|
+
|
|
333
|
+
1. **[AGENTS.md](https://agents.md/)** — Shared convention used by many coding agents (build commands, tests, repo norms). Grok discovers these files the same way [OpenAI Codex](https://developers.openai.com/codex/guides/agents-md/) does: concatenate segments with blank lines, **broader scope first**, so later segments can refine or override earlier guidance in the combined text.
|
|
334
|
+
2. **Grok-specific** — `.grok/GROK.md` (project) or `~/.grok/GROK.md` (fallback), appended **last** so Grok-only rules win when something conflicts.
|
|
335
|
+
|
|
336
|
+
Instructions are resolved from the CLI **working directory** (canonical path), not only `process.cwd()` of a parent process.
|
|
337
|
+
|
|
338
|
+
#### AGENTS.md (project and global)
|
|
339
|
+
|
|
340
|
+
- **Global:** `~/.grok/AGENTS.md` (if present and non-empty)
|
|
341
|
+
- **Repository:** Starting at the **git repository root** (or only the current directory if you are not inside a repo), Grok walks **down** to your current directory. In each directory it loads **at most one** file:
|
|
342
|
+
- If `AGENTS.override.md` exists in that directory, it is used (and `AGENTS.md` in the same directory is **not** read).
|
|
343
|
+
- Otherwise, if `AGENTS.md` exists, it is used.
|
|
344
|
+
- Empty files are skipped. Nested directories let monorepos ship package-level guidance (e.g. root `AGENTS.md` plus `services/api/AGENTS.md`).
|
|
345
|
+
|
|
346
|
+
Put repository expectations, test commands, and PR conventions in `AGENTS.md` so the same file helps Grok and other tools.
|
|
347
|
+
|
|
348
|
+
#### Grok-specific: `.grok/GROK.md`
|
|
349
|
+
|
|
350
|
+
Create a `.grok/GROK.md` file in your project directory for instructions that apply only to Grok CLI:
|
|
351
|
+
|
|
352
|
+
```bash
|
|
353
|
+
mkdir .grok
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
Example `.grok/GROK.md`:
|
|
357
|
+
|
|
358
|
+
```markdown
|
|
359
|
+
# Custom Instructions for This Project
|
|
360
|
+
|
|
361
|
+
Always use TypeScript for any new code files.
|
|
362
|
+
When creating React components, use functional components with hooks.
|
|
363
|
+
Prefer const assertions and explicit typing over inference where it improves clarity.
|
|
364
|
+
Always add JSDoc comments for public functions and interfaces.
|
|
365
|
+
Follow the existing code style and patterns in this project.
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
For defaults across all projects, use `~/.grok/GROK.md`:
|
|
369
|
+
|
|
370
|
+
```bash
|
|
371
|
+
mkdir -p ~/.grok
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
Example global `GROK.md`:
|
|
375
|
+
|
|
376
|
+
```markdown
|
|
377
|
+
# Global Custom Instructions for Grok CLI
|
|
378
|
+
|
|
379
|
+
Always prioritize code readability and maintainability.
|
|
380
|
+
Use descriptive variable names and add comments for complex logic.
|
|
381
|
+
Follow best practices for the programming language being used.
|
|
382
|
+
When suggesting code changes, consider performance implications.
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
#### GROK.md vs project `AGENTS.md`
|
|
386
|
+
|
|
387
|
+
If both exist, **both** are included: all `AGENTS.md` segments first (global `~/.grok/AGENTS.md`, then root-to-cwd walk), then **one** GROK file — **project** `.grok/GROK.md` if it exists, otherwise `~/.grok/GROK.md`. Project GROK is not merged with global GROK; the project file replaces the global file for GROK-only content.
|
|
388
|
+
|
|
389
|
+
If no instruction files are present, Grok uses its built-in behavior only.
|
|
390
|
+
|
|
391
|
+
The merged body is added to the system prompt under **CUSTOM INSTRUCTIONS** and applies to that session’s workspace directory.
|
|
392
|
+
|
|
393
|
+
### Agent Skills
|
|
394
|
+
|
|
395
|
+
[Agent Skills](https://agentskills.io) are folders of instructions (and optional scripts and assets) that Grok can load when they match the task. Grok discovers skills on disk and includes a compact catalog in the system prompt; the model should `read_file` the listed `SKILL.md` when a skill might help.
|
|
396
|
+
|
|
397
|
+
#### Layout
|
|
398
|
+
|
|
399
|
+
Each skill is a directory containing a `SKILL.md` file with YAML frontmatter (`name` and `description` required), per the [specification](https://agentskills.io/specification).
|
|
400
|
+
|
|
401
|
+
- **Project skills:** `.agents/skills/<skill-name>/SKILL.md` (under your project directory)
|
|
402
|
+
- **User skills:** `~/.agents/skills/<skill-name>/SKILL.md`
|
|
403
|
+
|
|
404
|
+
If the same `name` appears in both places, the **project** skill wins.
|
|
405
|
+
|
|
406
|
+
Install skills by copying or cloning them into those paths, or use tooling such as `skills.sh` — Grok CLI does not download skills for you.
|
|
407
|
+
|
|
408
|
+
#### Listing skills in the TUI
|
|
409
|
+
|
|
410
|
+
Open the slash command palette and choose **skills**, or type **`/skills`**, to print installed skills (name, scope, description, and path).
|
|
411
|
+
|
|
412
|
+
## Morph Fast Apply (Optional)
|
|
413
|
+
|
|
414
|
+
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.
|
|
415
|
+
|
|
416
|
+
**Setup**: Configure your Morph API key following the [setup instructions](#setup) above.
|
|
417
|
+
|
|
418
|
+
### How It Works
|
|
419
|
+
|
|
420
|
+
When `MORPH_API_KEY` is configured:
|
|
421
|
+
- **`edit_file` tool becomes available** alongside the standard `str_replace_editor`
|
|
422
|
+
- **Optimized for complex edits**: Use for multi-line changes, refactoring, and large modifications
|
|
423
|
+
- **Intelligent editing**: Uses abbreviated edit format with `// ... existing code ...` comments
|
|
424
|
+
- **Fallback support**: Standard tools remain available if Morph is unavailable
|
|
425
|
+
|
|
426
|
+
**When to use each tool:**
|
|
427
|
+
- **`edit_file`** (Morph): Complex edits, refactoring, multi-line changes
|
|
428
|
+
- **`str_replace_editor`**: Simple text replacements, single-line edits
|
|
429
|
+
|
|
430
|
+
### Example Usage
|
|
431
|
+
|
|
432
|
+
With Morph Fast Apply configured, you can request complex code changes:
|
|
433
|
+
|
|
434
|
+
```bash
|
|
435
|
+
grok --prompt "refactor this function to use async/await and add error handling"
|
|
436
|
+
grok -p "convert this class to TypeScript and add proper type annotations"
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
The AI will automatically choose between `edit_file` (Morph) for complex changes or `str_replace_editor` for simple replacements.
|
|
440
|
+
|
|
441
|
+
## MCP Tools
|
|
442
|
+
|
|
443
|
+
Grok CLI supports MCP (Model Context Protocol) servers, allowing you to extend the AI assistant with additional tools and capabilities.
|
|
444
|
+
|
|
445
|
+
### Adding MCP Tools
|
|
446
|
+
|
|
447
|
+
#### Add a custom MCP server:
|
|
448
|
+
```bash
|
|
449
|
+
# Add an stdio-based MCP server
|
|
450
|
+
grok mcp add my-server --transport stdio --command "bun" --args server.js
|
|
451
|
+
|
|
452
|
+
# Add an HTTP-based MCP server
|
|
453
|
+
grok mcp add my-server --transport http --url "http://localhost:3000"
|
|
454
|
+
|
|
455
|
+
# Add with environment variables
|
|
456
|
+
grok mcp add my-server --transport stdio --command "python" --args "-m" "my_mcp_server" --env "API_KEY=your_key"
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
#### Add from JSON configuration:
|
|
460
|
+
```bash
|
|
461
|
+
grok mcp add-json my-server '{"command": "bun", "args": ["server.js"], "env": {"API_KEY": "your_key"}}'
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
### Linear Integration Example
|
|
465
|
+
|
|
466
|
+
To add Linear MCP tools for project management:
|
|
467
|
+
|
|
468
|
+
```bash
|
|
469
|
+
# Add Linear MCP server
|
|
470
|
+
grok mcp add linear --transport sse --url "https://mcp.linear.app/sse"
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
This enables Linear tools like:
|
|
474
|
+
- Create and manage Linear issues
|
|
475
|
+
- Search and filter issues
|
|
476
|
+
- Update issue status and assignees
|
|
477
|
+
- Access team and project information
|
|
478
|
+
|
|
479
|
+
### Managing MCP Servers
|
|
480
|
+
|
|
481
|
+
```bash
|
|
482
|
+
# List all configured servers
|
|
483
|
+
grok mcp list
|
|
484
|
+
|
|
485
|
+
# Test server connection
|
|
486
|
+
grok mcp test server-name
|
|
487
|
+
|
|
488
|
+
# Remove a server
|
|
489
|
+
grok mcp remove server-name
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
### Available Transport Types
|
|
493
|
+
|
|
494
|
+
- **stdio**: Run MCP server as a subprocess (most common)
|
|
495
|
+
- **http**: Connect to HTTP-based MCP server
|
|
496
|
+
- **sse**: Connect via Server-Sent Events
|
|
497
|
+
|
|
498
|
+
## Development
|
|
499
|
+
|
|
500
|
+
```bash
|
|
501
|
+
# Install dependencies
|
|
502
|
+
bun install
|
|
503
|
+
|
|
504
|
+
# Development mode
|
|
505
|
+
bun run dev
|
|
506
|
+
|
|
507
|
+
# Build project
|
|
508
|
+
bun run build
|
|
509
|
+
|
|
510
|
+
# Run linter
|
|
511
|
+
bun run lint
|
|
512
|
+
|
|
513
|
+
# Type check
|
|
514
|
+
bun run typecheck
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
## Architecture
|
|
518
|
+
|
|
519
|
+
- **Agent**: Core command processing and execution logic
|
|
520
|
+
- **Tools**: Text editor and bash tool implementations
|
|
521
|
+
- **UI**: Ink-based terminal interface components
|
|
522
|
+
- **Types**: TypeScript definitions for the entire system
|
|
523
|
+
|
|
524
|
+
## License
|
|
525
|
+
|
|
526
|
+
MIT
|
package/biome.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/2.4.8/schema.json",
|
|
3
|
+
"vcs": {
|
|
4
|
+
"enabled": true,
|
|
5
|
+
"clientKind": "git",
|
|
6
|
+
"useIgnoreFile": true
|
|
7
|
+
},
|
|
8
|
+
"files": {
|
|
9
|
+
"includes": ["**", "!!**/dist"]
|
|
10
|
+
},
|
|
11
|
+
"formatter": {
|
|
12
|
+
"enabled": true,
|
|
13
|
+
"indentStyle": "space",
|
|
14
|
+
"indentWidth": 2,
|
|
15
|
+
"lineWidth": 120
|
|
16
|
+
},
|
|
17
|
+
"linter": {
|
|
18
|
+
"enabled": true,
|
|
19
|
+
"rules": {
|
|
20
|
+
"recommended": true,
|
|
21
|
+
"suspicious": {
|
|
22
|
+
"noExplicitAny": "error",
|
|
23
|
+
"noArrayIndexKey": "warn"
|
|
24
|
+
},
|
|
25
|
+
"correctness": {
|
|
26
|
+
"noUnusedFunctionParameters": "warn"
|
|
27
|
+
},
|
|
28
|
+
"complexity": {
|
|
29
|
+
"noForEach": "off"
|
|
30
|
+
},
|
|
31
|
+
"style": {
|
|
32
|
+
"noNonNullAssertion": "off",
|
|
33
|
+
"useNodejsImportProtocol": "off"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"javascript": {
|
|
38
|
+
"formatter": {
|
|
39
|
+
"quoteStyle": "double",
|
|
40
|
+
"trailingCommas": "all"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"assist": {
|
|
44
|
+
"enabled": true,
|
|
45
|
+
"actions": {
|
|
46
|
+
"source": {
|
|
47
|
+
"organizeImports": "on"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { AgentMode, ChatEntry, SessionInfo, SessionSnapshot, StreamChunk, SubagentStatus, TaskRequest, ToolResult } from "../types/index";
|
|
2
|
+
interface AgentOptions {
|
|
3
|
+
persistSession?: boolean;
|
|
4
|
+
session?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class Agent {
|
|
7
|
+
private provider;
|
|
8
|
+
private apiKey;
|
|
9
|
+
private baseURL;
|
|
10
|
+
private bash;
|
|
11
|
+
private delegations;
|
|
12
|
+
private sessionStore;
|
|
13
|
+
private workspace;
|
|
14
|
+
private session;
|
|
15
|
+
private messages;
|
|
16
|
+
private recordedTokens;
|
|
17
|
+
private abortController;
|
|
18
|
+
private maxToolRounds;
|
|
19
|
+
private mode;
|
|
20
|
+
private modelId;
|
|
21
|
+
private maxTokens;
|
|
22
|
+
private planContext;
|
|
23
|
+
private subagentStatusListeners;
|
|
24
|
+
constructor(apiKey: string | undefined, baseURL?: string, model?: string, maxToolRounds?: number, options?: AgentOptions);
|
|
25
|
+
getModel(): string;
|
|
26
|
+
setModel(model: string): void;
|
|
27
|
+
getMode(): AgentMode;
|
|
28
|
+
setMode(mode: AgentMode): void;
|
|
29
|
+
setPlanContext(ctx: string | null): void;
|
|
30
|
+
hasApiKey(): boolean;
|
|
31
|
+
setApiKey(apiKey: string, baseURL?: string | undefined): void;
|
|
32
|
+
getCwd(): string;
|
|
33
|
+
getContextStats(contextWindow: number, inFlightText?: string): {
|
|
34
|
+
contextWindow: number;
|
|
35
|
+
usedTokens: number;
|
|
36
|
+
remainingTokens: number;
|
|
37
|
+
ratioUsed: number;
|
|
38
|
+
ratioRemaining: number;
|
|
39
|
+
};
|
|
40
|
+
generateTitle(userMessage: string): Promise<string>;
|
|
41
|
+
abort(): void;
|
|
42
|
+
clearHistory(): void;
|
|
43
|
+
startNewSession(): SessionSnapshot | null;
|
|
44
|
+
getSessionInfo(): SessionInfo | null;
|
|
45
|
+
getSessionId(): string | null;
|
|
46
|
+
getSessionTitle(): string | null;
|
|
47
|
+
getChatEntries(): ChatEntry[];
|
|
48
|
+
getSessionSnapshot(): SessionSnapshot | null;
|
|
49
|
+
onSubagentStatus(listener: (status: SubagentStatus | null) => void): () => void;
|
|
50
|
+
private emitSubagentStatus;
|
|
51
|
+
private discardAbortedTurn;
|
|
52
|
+
private recordUsage;
|
|
53
|
+
consumeBackgroundNotifications(): Promise<string[]>;
|
|
54
|
+
runTaskRequest(request: TaskRequest, onActivity?: (detail: string) => void, abortSignal?: AbortSignal): Promise<ToolResult>;
|
|
55
|
+
private runTask;
|
|
56
|
+
private runDelegation;
|
|
57
|
+
private readDelegation;
|
|
58
|
+
private listDelegations;
|
|
59
|
+
processMessage(userMessage: string): AsyncGenerator<StreamChunk, void, unknown>;
|
|
60
|
+
private requireProvider;
|
|
61
|
+
}
|
|
62
|
+
export {};
|