grok-agent 0.5.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/CHANGELOG.md +113 -0
- package/LICENSE +190 -0
- package/README.md +449 -0
- package/bin/grok-cli.js +26 -0
- package/dist/agent.d.ts +4 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +898 -0
- package/dist/agent.js.map +1 -0
- package/dist/approvals.d.ts +4 -0
- package/dist/approvals.d.ts.map +1 -0
- package/dist/approvals.js +90 -0
- package/dist/approvals.js.map +1 -0
- package/dist/batch-api.d.ts +11 -0
- package/dist/batch-api.d.ts.map +1 -0
- package/dist/batch-api.js +101 -0
- package/dist/batch-api.js.map +1 -0
- package/dist/cli-errors.d.ts +6 -0
- package/dist/cli-errors.d.ts.map +1 -0
- package/dist/cli-errors.js +80 -0
- package/dist/cli-errors.js.map +1 -0
- package/dist/client.d.ts +6 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +41 -0
- package/dist/client.js.map +1 -0
- package/dist/collections-api.d.ts +11 -0
- package/dist/collections-api.d.ts.map +1 -0
- package/dist/collections-api.js +144 -0
- package/dist/collections-api.js.map +1 -0
- package/dist/compaction.d.ts +11 -0
- package/dist/compaction.d.ts.map +1 -0
- package/dist/compaction.js +94 -0
- package/dist/compaction.js.map +1 -0
- package/dist/config.d.ts +12 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +142 -0
- package/dist/config.js.map +1 -0
- package/dist/diff.d.ts +5 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +80 -0
- package/dist/diff.js.map +1 -0
- package/dist/hooks.d.ts +11 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +30 -0
- package/dist/hooks.js.map +1 -0
- package/dist/image.d.ts +8 -0
- package/dist/image.d.ts.map +1 -0
- package/dist/image.js +58 -0
- package/dist/image.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1264 -0
- package/dist/index.js.map +1 -0
- package/dist/json-output.d.ts +27 -0
- package/dist/json-output.d.ts.map +1 -0
- package/dist/json-output.js +62 -0
- package/dist/json-output.js.map +1 -0
- package/dist/notifications.d.ts +6 -0
- package/dist/notifications.d.ts.map +1 -0
- package/dist/notifications.js +25 -0
- package/dist/notifications.js.map +1 -0
- package/dist/project-context.d.ts +6 -0
- package/dist/project-context.d.ts.map +1 -0
- package/dist/project-context.js +34 -0
- package/dist/project-context.js.map +1 -0
- package/dist/response-utils.d.ts +10 -0
- package/dist/response-utils.d.ts.map +1 -0
- package/dist/response-utils.js +123 -0
- package/dist/response-utils.js.map +1 -0
- package/dist/server-tools.d.ts +7 -0
- package/dist/server-tools.d.ts.map +1 -0
- package/dist/server-tools.js +205 -0
- package/dist/server-tools.js.map +1 -0
- package/dist/session.d.ts +46 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +305 -0
- package/dist/session.js.map +1 -0
- package/dist/stream.d.ts +22 -0
- package/dist/stream.d.ts.map +1 -0
- package/dist/stream.js +102 -0
- package/dist/stream.js.map +1 -0
- package/dist/system-prompt.d.ts +3 -0
- package/dist/system-prompt.d.ts.map +1 -0
- package/dist/system-prompt.js +64 -0
- package/dist/system-prompt.js.map +1 -0
- package/dist/tools/bash.d.ts +8 -0
- package/dist/tools/bash.d.ts.map +1 -0
- package/dist/tools/bash.js +49 -0
- package/dist/tools/bash.js.map +1 -0
- package/dist/tools/definitions.d.ts +3 -0
- package/dist/tools/definitions.d.ts.map +1 -0
- package/dist/tools/definitions.js +190 -0
- package/dist/tools/definitions.js.map +1 -0
- package/dist/tools/edit-file.d.ts +10 -0
- package/dist/tools/edit-file.d.ts.map +1 -0
- package/dist/tools/edit-file.js +73 -0
- package/dist/tools/edit-file.js.map +1 -0
- package/dist/tools/glob.d.ts +7 -0
- package/dist/tools/glob.d.ts.map +1 -0
- package/dist/tools/glob.js +44 -0
- package/dist/tools/glob.js.map +1 -0
- package/dist/tools/grep.d.ts +10 -0
- package/dist/tools/grep.d.ts.map +1 -0
- package/dist/tools/grep.js +102 -0
- package/dist/tools/grep.js.map +1 -0
- package/dist/tools/index.d.ts +10 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +41 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/list-dir.d.ts +7 -0
- package/dist/tools/list-dir.d.ts.map +1 -0
- package/dist/tools/list-dir.js +68 -0
- package/dist/tools/list-dir.js.map +1 -0
- package/dist/tools/policy.d.ts +4 -0
- package/dist/tools/policy.d.ts.map +1 -0
- package/dist/tools/policy.js +36 -0
- package/dist/tools/policy.js.map +1 -0
- package/dist/tools/read-file.d.ts +8 -0
- package/dist/tools/read-file.d.ts.map +1 -0
- package/dist/tools/read-file.js +45 -0
- package/dist/tools/read-file.js.map +1 -0
- package/dist/tools/write-file.d.ts +7 -0
- package/dist/tools/write-file.d.ts.map +1 -0
- package/dist/tools/write-file.js +35 -0
- package/dist/tools/write-file.js.map +1 -0
- package/dist/truncation.d.ts +13 -0
- package/dist/truncation.d.ts.map +1 -0
- package/dist/truncation.js +55 -0
- package/dist/truncation.js.map +1 -0
- package/dist/types.d.ts +159 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/usage.d.ts +17 -0
- package/dist/usage.d.ts.map +1 -0
- package/dist/usage.js +80 -0
- package/dist/usage.js.map +1 -0
- package/dist/voice-api.d.ts +16 -0
- package/dist/voice-api.d.ts.map +1 -0
- package/dist/voice-api.js +84 -0
- package/dist/voice-api.js.map +1 -0
- package/package.json +64 -0
package/README.md
ADDED
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
# grok-agent
|
|
2
|
+
|
|
3
|
+
A coding assistant CLI powered by xAI's Grok models.
|
|
4
|
+
|
|
5
|
+
`grok-agent` gives you an agentic assistant in your terminal that can chat, inspect and edit code, run shell commands, search a repo, attach files/images, use xAI server-side tools, and keep JSONL-backed session history.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- Exec mode: `grok-agent "fix the bug in utils.ts"`
|
|
10
|
+
- Interactive REPL: `grok-agent`
|
|
11
|
+
- Pipe mode: `git diff | grok-agent "review this patch"`
|
|
12
|
+
- Local tools: `bash`, `read_file`, `write_file`, `edit_file`, `glob`, `grep`, `list_directory`
|
|
13
|
+
- Session persistence with resume, fork, archive, rename, rollback, and compaction
|
|
14
|
+
- Ephemeral mode for no-history runs
|
|
15
|
+
- JSONL output mode for automation
|
|
16
|
+
- xAI server-side tools: web search, X search, code execution, file search, and MCP
|
|
17
|
+
- Search filters for domains, X handles, date ranges, and media understanding
|
|
18
|
+
- Collection management backed by xAI's management API
|
|
19
|
+
- Review mode for uncommitted diffs, branches, and commits
|
|
20
|
+
- Sandbox modes and per-tool approval overrides
|
|
21
|
+
- Batch API helpers and realtime client-secret creation
|
|
22
|
+
- Image inputs and file attachments
|
|
23
|
+
- Image generation, video generation, TTS voice listing, and streaming TTS
|
|
24
|
+
- Structured JSON output with `--json-schema`
|
|
25
|
+
- Token usage display, citations, approvals, hooks, and notifications
|
|
26
|
+
|
|
27
|
+
## Quickstart
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# Prerequisites: Node.js >= 20 and an xAI API key
|
|
31
|
+
|
|
32
|
+
git clone https://github.com/baba20o/grok-agent.git
|
|
33
|
+
cd grok-agent
|
|
34
|
+
npm install
|
|
35
|
+
npm run build
|
|
36
|
+
npm link
|
|
37
|
+
|
|
38
|
+
export XAI_API_KEY=your_key_here
|
|
39
|
+
grok-agent doctor
|
|
40
|
+
grok-agent "what does this project do?"
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
You can also place `XAI_API_KEY` in a local `.env` file. The CLI loads `.env` from:
|
|
44
|
+
|
|
45
|
+
- the current directory
|
|
46
|
+
- the parent directory
|
|
47
|
+
- `~/.grok-agent/.env`
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
```text
|
|
52
|
+
grok-agent [options] [command] [prompt...]
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Key options:
|
|
56
|
+
|
|
57
|
+
- `-m, --model <model>`: use any specific model id
|
|
58
|
+
- `--fast`, `--reasoning`, `--non-reasoning`, `--code`, `--research`: model shortcuts
|
|
59
|
+
- `--max-turns <n>`: cap agent turns
|
|
60
|
+
- `--cwd <dir>`: change working directory
|
|
61
|
+
- `-r, --resume <id>`: resume a saved session
|
|
62
|
+
- `--fork <id>`: copy a session into a new one
|
|
63
|
+
- `-n, --name <name>`: assign a name to the session
|
|
64
|
+
- `--ephemeral`: run without saving session state
|
|
65
|
+
- `-o, --output <file>`: write final message to a file
|
|
66
|
+
- `--approve`, `--deny-writes`, `--yolo`: approval policy
|
|
67
|
+
- `--sandbox <mode>`: `read-only`, `workspace-write`, or `danger-full-access`
|
|
68
|
+
- `--plan`: ask the model to plan before execution
|
|
69
|
+
- `--json`: machine-readable JSONL events on stdout
|
|
70
|
+
- `--json-schema <schema>`: require structured output
|
|
71
|
+
- `--color <mode>`: set color output mode (`auto`, `always`, `never`)
|
|
72
|
+
- `--web-search`, `--x-search`, `--code-execution`: enable xAI server-side tools
|
|
73
|
+
- `--allow-domain`, `--exclude-domain`, `--search-images`: web search controls
|
|
74
|
+
- `--x-allow`, `--x-exclude`, `--x-from`, `--x-to`, `--x-images`, `--x-videos`: X search controls
|
|
75
|
+
- `--collection <id>` and `--file-search-mode <mode>`: enable file search over xAI collections
|
|
76
|
+
- `--include-tool-outputs`, `--show-server-tool-usage`: expose server-side tool output and usage
|
|
77
|
+
- `--mcp <urls...>`: connect remote MCP servers
|
|
78
|
+
- `--mcp-allow <label=tool1,tool2>`: restrict MCP tools per server
|
|
79
|
+
- `--mcp-desc <label=description>`: attach MCP server descriptions
|
|
80
|
+
- `--image <paths...>`: attach images
|
|
81
|
+
- `--attach <files...>`: upload files
|
|
82
|
+
- `--show-reasoning`, `--show-usage`, `--show-diffs`, `--no-diffs`, `--no-citations`, `--no-tools`
|
|
83
|
+
- `-v, --verbose`: output detailed tool calls
|
|
84
|
+
- `--notify`: desktop notification on completion
|
|
85
|
+
- `--responses-api`: force the Responses API
|
|
86
|
+
- `--defer`: fire-and-forget deferred completion
|
|
87
|
+
|
|
88
|
+
Full help:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
grok-agent --help
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Commands
|
|
95
|
+
|
|
96
|
+
| Command | Description |
|
|
97
|
+
|---|---|
|
|
98
|
+
| `models` | List models or inspect a specific model |
|
|
99
|
+
| `sessions` | List, show, archive, rename, rollback, compact, delete, or clear saved sessions |
|
|
100
|
+
| `review` | Run Grok in code review mode for local changes, branches, or commits |
|
|
101
|
+
| `generate-image` / `imagine` | Generate images |
|
|
102
|
+
| `generate-video` / `video` | Generate video |
|
|
103
|
+
| `speak` / `tts` | Convert text to speech |
|
|
104
|
+
| `tts-voices` | List currently available TTS voices |
|
|
105
|
+
| `collections` | Manage xAI document collections and their documents |
|
|
106
|
+
| `batch` | Create, inspect, cancel, and feed Batch API jobs |
|
|
107
|
+
| `realtime` | Create ephemeral realtime client secrets |
|
|
108
|
+
| `doctor` | Validate setup, API key, and session storage |
|
|
109
|
+
| `tokenize` | Count tokens for text |
|
|
110
|
+
| `config` | Show config or create a default config file |
|
|
111
|
+
|
|
112
|
+
Examples:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
grok-agent models ls
|
|
116
|
+
grok-agent models info grok-4-1-fast-reasoning
|
|
117
|
+
|
|
118
|
+
grok-agent sessions list
|
|
119
|
+
grok-agent sessions show <id>
|
|
120
|
+
grok-agent sessions archive <id>
|
|
121
|
+
grok-agent sessions rename <id> "new name"
|
|
122
|
+
grok-agent sessions rollback <id> --turns 2
|
|
123
|
+
grok-agent sessions compact <id>
|
|
124
|
+
grok-agent sessions delete <id>
|
|
125
|
+
|
|
126
|
+
grok-agent review --base origin/main
|
|
127
|
+
grok-agent review --commit HEAD~1
|
|
128
|
+
|
|
129
|
+
grok-agent config --init
|
|
130
|
+
grok-agent config
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Model Selection
|
|
134
|
+
|
|
135
|
+
You can change models in three ways:
|
|
136
|
+
|
|
137
|
+
1. One-off on the command line:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
grok-agent -m grok-4-1-fast-reasoning "summarize this repo"
|
|
141
|
+
grok-agent --code "fix the TypeScript errors"
|
|
142
|
+
grok-agent --reasoning "design a migration plan"
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
2. Via environment:
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
export GROK_MODEL=grok-code-fast-1
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
3. Via config file:
|
|
152
|
+
|
|
153
|
+
```json
|
|
154
|
+
{
|
|
155
|
+
"model": "grok-code-fast-1"
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Selection precedence is:
|
|
160
|
+
|
|
161
|
+
`CLI flag` > `config.json` > `GROK_MODEL` > built-in default
|
|
162
|
+
|
|
163
|
+
Current built-in aliases:
|
|
164
|
+
|
|
165
|
+
| Flag | Model |
|
|
166
|
+
|---|---|
|
|
167
|
+
| `--fast` | `grok-4-1-fast-reasoning` |
|
|
168
|
+
| `--reasoning` | `grok-4.20-0309-reasoning` |
|
|
169
|
+
| `--non-reasoning` | `grok-4.20-0309-non-reasoning` |
|
|
170
|
+
| `--code` | `grok-code-fast-1` |
|
|
171
|
+
| `--research` | `grok-4.20-multi-agent-0309` |
|
|
172
|
+
|
|
173
|
+
To see what your API key can actually use:
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
grok-agent models ls
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Examples
|
|
180
|
+
|
|
181
|
+
### Coding
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
grok-agent "fix the failing tests in src/utils.ts"
|
|
185
|
+
grok-agent --code "refactor this module to use async/await"
|
|
186
|
+
grok-agent --reasoning "design a caching layer for the API"
|
|
187
|
+
grok-agent --plan "add a config migration for the new schema"
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Interactive
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
grok-agent
|
|
194
|
+
grok-agent --ephemeral
|
|
195
|
+
grok-agent -r <session-id>
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Research
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
grok-agent --research "compare React Server Components vs Astro Islands"
|
|
202
|
+
grok-agent --web-search "what changed in Node.js 22"
|
|
203
|
+
grok-agent --x-search "what are developers saying about Bun"
|
|
204
|
+
grok-agent --web-search --allow-domain docs.x.ai --search-images "summarize the docs homepage"
|
|
205
|
+
grok-agent --x-search --x-allow xai --x-from 2026-03-01 --x-to 2026-03-29 "recent Grok platform updates"
|
|
206
|
+
grok-agent --collection engineering-handbook "find the deploy checklist"
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Images and Files
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
grok-agent --image screenshot.png "what is wrong with this UI?"
|
|
213
|
+
grok-agent --attach spec.pdf "implement the auth flow from this spec"
|
|
214
|
+
grok-agent --attach data.csv "summarize the anomalies in this dataset"
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Generation
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
grok-agent imagine "a minimalist logo for a CLI tool"
|
|
221
|
+
grok-agent imagine --pro "photorealistic laptop on a desk"
|
|
222
|
+
grok-agent video --duration 8 --aspect 16:9 "a futuristic terminal UI"
|
|
223
|
+
grok-agent tts --voice eve "Build completed successfully."
|
|
224
|
+
grok-agent tts --stream --codec mp3 --voice leo "Streaming speech sample"
|
|
225
|
+
grok-agent tts-voices
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### MCP
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
grok-agent --mcp https://mcp.deepwiki.com/mcp "explain this repository"
|
|
232
|
+
grok-agent --mcp wiki=https://mcp.deepwiki.com/mcp --mcp custom=https://my-tools.example/mcp "research task"
|
|
233
|
+
grok-agent --mcp wiki=https://mcp.deepwiki.com/mcp --mcp-allow wiki=search,read_page --mcp-desc wiki="Team wiki" "find release notes"
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Structured Output and JSON Mode
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
grok-agent --json-schema '{"type":"object","properties":{"files":{"type":"array","items":{"type":"string"}}}}' \
|
|
240
|
+
"list the source files touched by session persistence"
|
|
241
|
+
|
|
242
|
+
grok-agent --json --ephemeral "say hi in one short sentence"
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### Collections
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
grok-agent collections list
|
|
249
|
+
grok-agent collections create "Engineering Docs"
|
|
250
|
+
grok-agent collections upload col_123 handbook.pdf
|
|
251
|
+
grok-agent collections search col_123 "on-call rotation policy"
|
|
252
|
+
grok-agent --collection col_123 "summarize the deployment runbook"
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Collection management requires `XAI_MANAGEMENT_API_KEY`.
|
|
256
|
+
|
|
257
|
+
### Batch + Realtime
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
grok-agent batch list --limit 20
|
|
261
|
+
grok-agent batch create nightly-evals
|
|
262
|
+
grok-agent batch add-chat batch_123 "summarize this issue thread"
|
|
263
|
+
grok-agent batch results batch_123 --limit 10
|
|
264
|
+
grok-agent realtime secret --seconds 600
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Tokenization
|
|
268
|
+
|
|
269
|
+
```bash
|
|
270
|
+
grok-agent tokenize "fix the bug in approvals.ts"
|
|
271
|
+
grok-agent tokenize -m grok-code-fast-1 "class User { constructor() {} }"
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## Sessions
|
|
275
|
+
|
|
276
|
+
Sessions are stored as JSONL files under:
|
|
277
|
+
|
|
278
|
+
- `GROK_SESSION_DIR/sessions`
|
|
279
|
+
- or `~/.grok-agent/sessions` by default
|
|
280
|
+
|
|
281
|
+
Useful commands:
|
|
282
|
+
|
|
283
|
+
```bash
|
|
284
|
+
grok-agent sessions list
|
|
285
|
+
grok-agent sessions list --all
|
|
286
|
+
grok-agent sessions show <id>
|
|
287
|
+
grok-agent -r <id> "follow-up question"
|
|
288
|
+
grok-agent --fork <id> "continue on a new branch of thought"
|
|
289
|
+
grok-agent sessions archive <id>
|
|
290
|
+
grok-agent sessions unarchive <id>
|
|
291
|
+
grok-agent sessions rename <id> "better title"
|
|
292
|
+
grok-agent sessions rollback <id> --turns 1
|
|
293
|
+
grok-agent sessions compact <id>
|
|
294
|
+
grok-agent sessions clear
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
If you do not want any session state written, use:
|
|
298
|
+
|
|
299
|
+
```bash
|
|
300
|
+
grok-agent --ephemeral "one-off task"
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
## Configuration
|
|
304
|
+
|
|
305
|
+
Create a starter config file:
|
|
306
|
+
|
|
307
|
+
```bash
|
|
308
|
+
grok-agent config --init
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
That writes `config.json` under your session dir (`GROK_SESSION_DIR` or `~/.grok-agent`).
|
|
312
|
+
|
|
313
|
+
Supported config fields currently include:
|
|
314
|
+
|
|
315
|
+
```json
|
|
316
|
+
{
|
|
317
|
+
"model": "grok-4-1-fast-reasoning",
|
|
318
|
+
"approval_policy": "always-approve",
|
|
319
|
+
"sandbox_mode": "workspace-write",
|
|
320
|
+
"show_usage": false,
|
|
321
|
+
"show_diffs": true,
|
|
322
|
+
"show_citations": true,
|
|
323
|
+
"show_server_tool_usage": false,
|
|
324
|
+
"include_tool_outputs": false,
|
|
325
|
+
"notify": false,
|
|
326
|
+
"max_turns": 50,
|
|
327
|
+
"management_api_key": "",
|
|
328
|
+
"management_base_url": "https://management-api.x.ai/v1",
|
|
329
|
+
"mcp_servers": [
|
|
330
|
+
{
|
|
331
|
+
"label": "wiki",
|
|
332
|
+
"url": "https://mcp.deepwiki.com/mcp",
|
|
333
|
+
"description": "Team wiki",
|
|
334
|
+
"allowedTools": ["search", "read_page"]
|
|
335
|
+
}
|
|
336
|
+
],
|
|
337
|
+
"tool_approvals": {
|
|
338
|
+
"defaultMode": "ask",
|
|
339
|
+
"tools": {
|
|
340
|
+
"bash": "allow",
|
|
341
|
+
"write_file": "deny"
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
"server_tools": [
|
|
345
|
+
{
|
|
346
|
+
"type": "web_search",
|
|
347
|
+
"filters": {
|
|
348
|
+
"allowedDomains": ["docs.x.ai"]
|
|
349
|
+
},
|
|
350
|
+
"includeSources": true
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
"type": "file_search",
|
|
354
|
+
"collectionIds": ["col_123"],
|
|
355
|
+
"retrievalMode": "hybrid",
|
|
356
|
+
"includeResults": true
|
|
357
|
+
}
|
|
358
|
+
],
|
|
359
|
+
"hooks": {
|
|
360
|
+
"pre-tool": ["echo pre"],
|
|
361
|
+
"post-tool": ["echo post"]
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
Environment variables:
|
|
367
|
+
|
|
368
|
+
| Variable | Description | Default |
|
|
369
|
+
|---|---|---|
|
|
370
|
+
| `XAI_API_KEY` | xAI API key | required |
|
|
371
|
+
| `XAI_MANAGEMENT_API_KEY` | xAI management API key for collections | unset |
|
|
372
|
+
| `XAI_BASE_URL` | API base URL | `https://api.x.ai/v1` |
|
|
373
|
+
| `XAI_MANAGEMENT_BASE_URL` | management API base URL | `https://management-api.x.ai/v1` |
|
|
374
|
+
| `GROK_MODEL` | default model | `grok-4-1-fast-reasoning` |
|
|
375
|
+
| `GROK_SESSION_DIR` | base dir for sessions and config | `~/.grok-agent` |
|
|
376
|
+
| `GROK_SANDBOX_MODE` | default sandbox mode | `danger-full-access` |
|
|
377
|
+
|
|
378
|
+
## Tools
|
|
379
|
+
|
|
380
|
+
### Local Tools
|
|
381
|
+
|
|
382
|
+
| Tool | Description |
|
|
383
|
+
|---|---|
|
|
384
|
+
| `bash` | Run shell commands |
|
|
385
|
+
| `read_file` | Read file contents |
|
|
386
|
+
| `write_file` | Create or overwrite files |
|
|
387
|
+
| `edit_file` | Exact find-and-replace edits |
|
|
388
|
+
| `glob` | Find files by glob |
|
|
389
|
+
| `grep` | Search file contents by regex |
|
|
390
|
+
| `list_directory` | List directory contents |
|
|
391
|
+
|
|
392
|
+
### xAI Server-Side Tools
|
|
393
|
+
|
|
394
|
+
| Tool | CLI support |
|
|
395
|
+
|---|---|
|
|
396
|
+
| Web Search | `--web-search`, `--allow-domain`, `--exclude-domain`, `--search-images` |
|
|
397
|
+
| X Search | `--x-search`, `--x-allow`, `--x-exclude`, `--x-from`, `--x-to`, `--x-images`, `--x-videos` |
|
|
398
|
+
| Code Execution | `--code-execution` |
|
|
399
|
+
| File Search | `--collection <id>`, `--file-search-mode <mode>` |
|
|
400
|
+
| Remote MCP | `--mcp <url>`, `--mcp-allow`, `--mcp-desc` |
|
|
401
|
+
|
|
402
|
+
## Development
|
|
403
|
+
|
|
404
|
+
```bash
|
|
405
|
+
npm run lint
|
|
406
|
+
npm run build
|
|
407
|
+
npm test
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
Source layout:
|
|
411
|
+
|
|
412
|
+
```text
|
|
413
|
+
src/
|
|
414
|
+
├── index.ts CLI entry and subcommands
|
|
415
|
+
├── agent.ts Agent loop and interactive mode
|
|
416
|
+
├── client.ts xAI client wrapper
|
|
417
|
+
├── cli-errors.ts Shared CLI/network/session error formatting
|
|
418
|
+
├── config.ts Config and .env loading
|
|
419
|
+
├── server-tools.ts Typed server-tool normalization and serialization
|
|
420
|
+
├── session.ts JSONL session persistence
|
|
421
|
+
├── json-output.ts JSONL event output
|
|
422
|
+
├── approvals.ts Approval policy checks
|
|
423
|
+
├── hooks.ts Hook execution
|
|
424
|
+
├── compaction.ts Conversation compaction
|
|
425
|
+
├── truncation.ts Tool output truncation and token estimation
|
|
426
|
+
├── system-prompt.ts Dynamic system prompt
|
|
427
|
+
├── collections-api.ts xAI collections management helpers
|
|
428
|
+
├── batch-api.ts Batch API helpers
|
|
429
|
+
├── voice-api.ts TTS and realtime helpers
|
|
430
|
+
├── project-context.ts Optional repo context loading
|
|
431
|
+
├── image.ts Image input helpers
|
|
432
|
+
├── notifications.ts Desktop notification support
|
|
433
|
+
├── usage.ts Usage accounting
|
|
434
|
+
└── tools/
|
|
435
|
+
├── index.ts
|
|
436
|
+
├── definitions.ts
|
|
437
|
+
├── bash.ts
|
|
438
|
+
├── read-file.ts
|
|
439
|
+
├── write-file.ts
|
|
440
|
+
├── edit-file.ts
|
|
441
|
+
├── glob.ts
|
|
442
|
+
├── grep.ts
|
|
443
|
+
├── list-dir.ts
|
|
444
|
+
└── policy.ts
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
## License
|
|
448
|
+
|
|
449
|
+
Apache-2.0
|
package/bin/grok-cli.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Entry point — delegates to compiled TypeScript or tsx in development
|
|
4
|
+
import { pathToFileURL, fileURLToPath } from "node:url";
|
|
5
|
+
import { dirname, join } from "node:path";
|
|
6
|
+
import { existsSync } from "node:fs";
|
|
7
|
+
|
|
8
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
const distEntry = join(__dirname, "..", "dist", "index.js");
|
|
10
|
+
const srcEntry = join(__dirname, "..", "src", "index.ts");
|
|
11
|
+
|
|
12
|
+
if (existsSync(distEntry)) {
|
|
13
|
+
// Production: run compiled JS — use file:// URL for Windows compatibility
|
|
14
|
+
await import(pathToFileURL(distEntry).href);
|
|
15
|
+
} else {
|
|
16
|
+
// Development: run via tsx
|
|
17
|
+
const { execFileSync } = await import("node:child_process");
|
|
18
|
+
try {
|
|
19
|
+
execFileSync("npx", ["tsx", srcEntry, ...process.argv.slice(2)], {
|
|
20
|
+
stdio: "inherit",
|
|
21
|
+
cwd: process.cwd(),
|
|
22
|
+
});
|
|
23
|
+
} catch (err) {
|
|
24
|
+
process.exit(err.status || 1);
|
|
25
|
+
}
|
|
26
|
+
}
|
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { GrokConfig, AgentOptions } from "./types.js";
|
|
2
|
+
export declare function runAgent(config: GrokConfig, prompt: string, options: AgentOptions): Promise<string>;
|
|
3
|
+
export declare function runInteractive(config: GrokConfig, options: AgentOptions): Promise<void>;
|
|
4
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AA+CA,OAAO,KAAK,EACV,UAAU,EAGV,YAAY,EAKb,MAAM,YAAY,CAAC;AAqgBpB,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,MAAM,CAAC,CA0FjB;AAED,wBAAsB,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAqS7F"}
|