@zds-ai/cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +497 -0
- package/dist/agent/grok-agent.d.ts +250 -0
- package/dist/agent/grok-agent.js +2480 -0
- package/dist/agent/grok-agent.js.map +1 -0
- package/dist/agent/index.d.ts +14 -0
- package/dist/agent/index.js +136 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/commands/mcp.d.ts +2 -0
- package/dist/commands/mcp.js +239 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/grok/client.d.ts +55 -0
- package/dist/grok/client.js +276 -0
- package/dist/grok/client.js.map +1 -0
- package/dist/grok/tools.d.ts +8 -0
- package/dist/grok/tools.js +878 -0
- package/dist/grok/tools.js.map +1 -0
- package/dist/hooks/use-enhanced-input.d.ts +38 -0
- package/dist/hooks/use-enhanced-input.js +228 -0
- package/dist/hooks/use-enhanced-input.js.map +1 -0
- package/dist/hooks/use-input-handler.d.ts +36 -0
- package/dist/hooks/use-input-handler.js +1099 -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 +61 -0
- package/dist/hooks/use-input-history.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +869 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/client.d.ts +41 -0
- package/dist/mcp/client.js +224 -0
- package/dist/mcp/client.js.map +1 -0
- package/dist/mcp/config.d.ts +13 -0
- package/dist/mcp/config.js +56 -0
- package/dist/mcp/config.js.map +1 -0
- package/dist/mcp/transports.d.ts +53 -0
- package/dist/mcp/transports.js +256 -0
- package/dist/mcp/transports.js.map +1 -0
- package/dist/tools/character-tool.d.ts +27 -0
- package/dist/tools/character-tool.js +194 -0
- package/dist/tools/character-tool.js.map +1 -0
- package/dist/tools/clear-cache-tool.d.ts +14 -0
- package/dist/tools/clear-cache-tool.js +82 -0
- package/dist/tools/clear-cache-tool.js.map +1 -0
- package/dist/tools/confirmation-tool.d.ts +16 -0
- package/dist/tools/confirmation-tool.js +72 -0
- package/dist/tools/confirmation-tool.js.map +1 -0
- package/dist/tools/env-tool.d.ts +17 -0
- package/dist/tools/env-tool.js +89 -0
- package/dist/tools/env-tool.js.map +1 -0
- package/dist/tools/file-conversion-tool.d.ts +16 -0
- package/dist/tools/file-conversion-tool.js +181 -0
- package/dist/tools/file-conversion-tool.js.map +1 -0
- package/dist/tools/image-tool.d.ts +22 -0
- package/dist/tools/image-tool.js +268 -0
- package/dist/tools/image-tool.js.map +1 -0
- package/dist/tools/index.d.ts +14 -0
- package/dist/tools/index.js +15 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/internet-tool.d.ts +11 -0
- package/dist/tools/internet-tool.js +108 -0
- package/dist/tools/internet-tool.js.map +1 -0
- package/dist/tools/introspect-tool.d.ts +11 -0
- package/dist/tools/introspect-tool.js +243 -0
- package/dist/tools/introspect-tool.js.map +1 -0
- package/dist/tools/morph-editor.d.ts +38 -0
- package/dist/tools/morph-editor.js +318 -0
- package/dist/tools/morph-editor.js.map +1 -0
- package/dist/tools/restart-tool.d.ts +7 -0
- package/dist/tools/restart-tool.js +24 -0
- package/dist/tools/restart-tool.js.map +1 -0
- package/dist/tools/search.d.ts +71 -0
- package/dist/tools/search.js +340 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/tools/task-tool.d.ts +19 -0
- package/dist/tools/task-tool.js +115 -0
- package/dist/tools/task-tool.js.map +1 -0
- package/dist/tools/text-editor.d.ts +35 -0
- package/dist/tools/text-editor.js +669 -0
- package/dist/tools/text-editor.js.map +1 -0
- package/dist/tools/tool-discovery.d.ts +20 -0
- package/dist/tools/tool-discovery.js +45 -0
- package/dist/tools/tool-discovery.js.map +1 -0
- package/dist/tools/zsh.d.ts +13 -0
- package/dist/tools/zsh.js +168 -0
- package/dist/tools/zsh.js.map +1 -0
- package/dist/types/index.d.ts +31 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/ui/app.d.ts +7 -0
- package/dist/ui/app.js +99 -0
- package/dist/ui/app.js.map +1 -0
- package/dist/ui/components/active-task-status.d.ts +7 -0
- package/dist/ui/components/active-task-status.js +37 -0
- package/dist/ui/components/active-task-status.js.map +1 -0
- package/dist/ui/components/api-key-input.d.ts +7 -0
- package/dist/ui/components/api-key-input.js +80 -0
- package/dist/ui/components/api-key-input.js.map +1 -0
- package/dist/ui/components/backend-status.d.ts +7 -0
- package/dist/ui/components/backend-status.js +85 -0
- package/dist/ui/components/backend-status.js.map +1 -0
- package/dist/ui/components/chat-history.d.ts +8 -0
- package/dist/ui/components/chat-history.js +187 -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 +63 -0
- package/dist/ui/components/chat-input.js.map +1 -0
- package/dist/ui/components/chat-interface.d.ts +9 -0
- package/dist/ui/components/chat-interface.js +389 -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 +22 -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 +105 -0
- package/dist/ui/components/confirmation-dialog.js.map +1 -0
- package/dist/ui/components/context-status.d.ts +7 -0
- package/dist/ui/components/context-status.js +36 -0
- package/dist/ui/components/context-status.js.map +1 -0
- package/dist/ui/components/diff-renderer.d.ts +13 -0
- package/dist/ui/components/diff-renderer.js +206 -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 +64 -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 +57 -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 +17 -0
- package/dist/ui/components/model-selection.js.map +1 -0
- package/dist/ui/components/mood-status.d.ts +7 -0
- package/dist/ui/components/mood-status.js +34 -0
- package/dist/ui/components/mood-status.js.map +1 -0
- package/dist/ui/components/persona-status.d.ts +7 -0
- package/dist/ui/components/persona-status.js +34 -0
- package/dist/ui/components/persona-status.js.map +1 -0
- package/dist/ui/shared/max-sized-box.d.ts +8 -0
- package/dist/ui/shared/max-sized-box.js +6 -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 +7 -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 +15 -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 +40 -0
- package/dist/ui/utils/markdown-renderer.js.map +1 -0
- package/dist/utils/auth-helper.d.ts +63 -0
- package/dist/utils/auth-helper.js +129 -0
- package/dist/utils/auth-helper.js.map +1 -0
- package/dist/utils/chat-history-manager-sqlite.d.ts +92 -0
- package/dist/utils/chat-history-manager-sqlite.js +334 -0
- package/dist/utils/chat-history-manager-sqlite.js.map +1 -0
- package/dist/utils/chat-history-manager.d.ts +87 -0
- package/dist/utils/chat-history-manager.js +273 -0
- package/dist/utils/chat-history-manager.js.map +1 -0
- package/dist/utils/chat-history-manager.json-backup.d.ts +69 -0
- package/dist/utils/chat-history-manager.json-backup.js +215 -0
- package/dist/utils/chat-history-manager.json-backup.js.map +1 -0
- package/dist/utils/confirmation-service.d.ts +46 -0
- package/dist/utils/confirmation-service.js +165 -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 +30 -0
- package/dist/utils/custom-instructions.js.map +1 -0
- package/dist/utils/database-connection.d.ts +27 -0
- package/dist/utils/database-connection.js +81 -0
- package/dist/utils/database-connection.js.map +1 -0
- package/dist/utils/database-schema.d.ts +17 -0
- package/dist/utils/database-schema.js +93 -0
- package/dist/utils/database-schema.js.map +1 -0
- package/dist/utils/error-logger.d.ts +13 -0
- package/dist/utils/error-logger.js +56 -0
- package/dist/utils/error-logger.js.map +1 -0
- package/dist/utils/hook-executor.d.ts +59 -0
- package/dist/utils/hook-executor.js +351 -0
- package/dist/utils/hook-executor.js.map +1 -0
- package/dist/utils/model-config.d.ts +28 -0
- package/dist/utils/model-config.js +42 -0
- package/dist/utils/model-config.js.map +1 -0
- package/dist/utils/path-utils.d.ts +4 -0
- package/dist/utils/path-utils.js +12 -0
- package/dist/utils/path-utils.js.map +1 -0
- package/dist/utils/settings-manager.d.ts +169 -0
- package/dist/utils/settings-manager.js +403 -0
- package/dist/utils/settings-manager.js.map +1 -0
- package/dist/utils/settings.d.ts +1 -0
- package/dist/utils/settings.js +4 -0
- package/dist/utils/settings.js.map +1 -0
- package/dist/utils/slash-commands.d.ts +25 -0
- package/dist/utils/slash-commands.js +454 -0
- package/dist/utils/slash-commands.js.map +1 -0
- package/dist/utils/startup-hook.d.ts +13 -0
- package/dist/utils/startup-hook.js +44 -0
- package/dist/utils/startup-hook.js.map +1 -0
- package/dist/utils/text-utils.d.ts +80 -0
- package/dist/utils/text-utils.js +182 -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 +78 -0
- package/dist/utils/token-counter.js.map +1 -0
- package/package.json +102 -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,497 @@
|
|
|
1
|
+
# ZDS AI CLI (forked from 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, others
|
|
10
|
+
- **📝 Smart File Operations**: AI automatically uses tools to view, create, and edit files
|
|
11
|
+
- **⚡ Zsh 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 @zds-ai/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
|
+
|
|
27
|
+
```sh
|
|
28
|
+
bun add -g @zds-ai/cli
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Or with npm (fallback):
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
npm install -g @zds-ai/cli
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Local Development
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
git clone <repository>
|
|
41
|
+
cd zds-ai-cli
|
|
42
|
+
bun install
|
|
43
|
+
bun run build
|
|
44
|
+
bun link
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Setup
|
|
48
|
+
|
|
49
|
+
1. Get your GROK API key from [X.AI](https://x.ai)
|
|
50
|
+
|
|
51
|
+
2. Set up your API key (choose one method):
|
|
52
|
+
|
|
53
|
+
**Method 1: Environment Variable**
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
export GROK_API_KEY=your_api_key_here
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**Method 2: .env File**
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
cp .env.example .env
|
|
63
|
+
# Edit .env and add your API key
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**Method 3: Command Line Flag**
|
|
67
|
+
|
|
68
|
+
```sh
|
|
69
|
+
zai-cli --api-key your_api_key_here
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**Method 4: User Settings File**
|
|
73
|
+
|
|
74
|
+
Create `~/.grok/user-settings.json`:
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"apiKey": "your_api_key_here"
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
3. (Optional, Recommended) Get your Morph API key from [Morph Dashboard](https://morphllm.com/dashboard/api-keys)
|
|
83
|
+
|
|
84
|
+
4. Set up your Morph API key for Fast Apply editing (choose one method):
|
|
85
|
+
|
|
86
|
+
**Method 1: Environment Variable**
|
|
87
|
+
|
|
88
|
+
```sh
|
|
89
|
+
export MORPH_API_KEY=your_morph_api_key_here
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**Method 2: .env File**
|
|
93
|
+
|
|
94
|
+
```sh
|
|
95
|
+
# Add to your .env file
|
|
96
|
+
MORPH_API_KEY=your_morph_api_key_here
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Custom Base URL (Optional)
|
|
100
|
+
|
|
101
|
+
By default, the CLI uses `https://api.x.ai/v1` as the API endpoint. You can configure a custom endpoint if needed (choose one method):
|
|
102
|
+
|
|
103
|
+
**Method 1: Environment Variable**
|
|
104
|
+
|
|
105
|
+
```sh
|
|
106
|
+
export GROK_BASE_URL=https://your-custom-endpoint.com/v1
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**Method 2: Command Line Flag**
|
|
110
|
+
|
|
111
|
+
```sh
|
|
112
|
+
zai-cli --api-key your_api_key_here --base-url https://your-custom-endpoint.com/v1
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**Method 3: User Settings File**
|
|
116
|
+
|
|
117
|
+
Add to `~/.grok/user-settings.json`:
|
|
118
|
+
|
|
119
|
+
```json
|
|
120
|
+
{
|
|
121
|
+
"apiKey": "your_api_key_here",
|
|
122
|
+
"baseURL": "https://your-custom-endpoint.com/v1"
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Configuration Files
|
|
127
|
+
|
|
128
|
+
zai-cli uses two types of configuration files to manage settings:
|
|
129
|
+
|
|
130
|
+
### User-Level Settings (`~/.grok/user-settings.json`)
|
|
131
|
+
|
|
132
|
+
This file stores **global settings** that apply across all projects. These settings rarely change and include:
|
|
133
|
+
|
|
134
|
+
- **API Key**: Your GROK API key
|
|
135
|
+
- **Base URL**: Custom API endpoint (if needed)
|
|
136
|
+
- **Default Model**: Your preferred model (e.g., `grok-code-fast-1`)
|
|
137
|
+
- **Available Models**: List of models you can use
|
|
138
|
+
|
|
139
|
+
**Example:**
|
|
140
|
+
|
|
141
|
+
```json
|
|
142
|
+
{
|
|
143
|
+
"apiKey": "your_api_key_here",
|
|
144
|
+
"baseURL": "https://api.x.ai/v1",
|
|
145
|
+
"defaultModel": "grok-code-fast-1",
|
|
146
|
+
"models": [
|
|
147
|
+
"grok-code-fast-1",
|
|
148
|
+
"grok-4-latest",
|
|
149
|
+
"grok-3-latest",
|
|
150
|
+
"grok-3-fast",
|
|
151
|
+
"grok-3-mini-fast"
|
|
152
|
+
],
|
|
153
|
+
"startupHook": "date"
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
#### Startup Hook
|
|
158
|
+
|
|
159
|
+
You can configure a **startup hook** command that runs when zai-cli starts. The output is automatically added to the system prompt, providing dynamic context about your environment.
|
|
160
|
+
|
|
161
|
+
**Example use cases:**
|
|
162
|
+
|
|
163
|
+
- Show current date/time: `"startupHook": "date"`
|
|
164
|
+
- Display git status: `"startupHook": "git status --short"`
|
|
165
|
+
- Show active branches: `"startupHook": "git branch --show-current"`
|
|
166
|
+
- Custom environment info: `"startupHook": "/path/to/your/script.sh"`
|
|
167
|
+
|
|
168
|
+
The command runs with a 10-second timeout and the output appears in the AI's context before custom instructions.
|
|
169
|
+
|
|
170
|
+
### Project-Level Settings (`.grok/settings.json`)
|
|
171
|
+
|
|
172
|
+
This file stores **project-specific settings** in your current working directory. It includes:
|
|
173
|
+
|
|
174
|
+
- **Current Model**: The model currently in use for this project
|
|
175
|
+
- **MCP Servers**: Model Context Protocol server configurations
|
|
176
|
+
|
|
177
|
+
**Example:**
|
|
178
|
+
|
|
179
|
+
```json
|
|
180
|
+
{
|
|
181
|
+
"model": "grok-3-fast",
|
|
182
|
+
"mcpServers": {
|
|
183
|
+
"linear": {
|
|
184
|
+
"name": "linear",
|
|
185
|
+
"transport": "stdio",
|
|
186
|
+
"command": "npx",
|
|
187
|
+
"args": ["@linear/mcp-server"]
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### How It Works
|
|
194
|
+
|
|
195
|
+
1. **Global Defaults**: User-level settings provide your default preferences
|
|
196
|
+
1. **Project Override**: Project-level settings override defaults for specific projects
|
|
197
|
+
1. **Directory-Specific**: When you change directories, project settings are loaded automatically
|
|
198
|
+
1. **Fallback Logic**: Project model → User default model → System default (`grok-code-fast-1`)
|
|
199
|
+
|
|
200
|
+
This means you can have different models for different projects while maintaining consistent global settings like your API key.
|
|
201
|
+
|
|
202
|
+
### Using Other API Providers
|
|
203
|
+
|
|
204
|
+
**Important**: zai-cli uses **OpenAI-compatible APIs**. You can use any provider that implements the OpenAI chat completions standard.
|
|
205
|
+
|
|
206
|
+
**Popular Providers**:
|
|
207
|
+
|
|
208
|
+
- **X.AI (grok)**: `https://api.x.ai/v1` (default)
|
|
209
|
+
- **OpenAI**: `https://api.openai.com/v1`
|
|
210
|
+
- **OpenRouter**: `https://openrouter.ai/api/v1`
|
|
211
|
+
- **Groq**: `https://api.groq.com/openai/v1`
|
|
212
|
+
|
|
213
|
+
**Example with OpenRouter**:
|
|
214
|
+
|
|
215
|
+
```json
|
|
216
|
+
{
|
|
217
|
+
"apiKey": "your_openrouter_key",
|
|
218
|
+
"baseURL": "https://openrouter.ai/api/v1",
|
|
219
|
+
"defaultModel": "anthropic/claude-4.5-sonnet",
|
|
220
|
+
"models": [
|
|
221
|
+
"anthropic/claude-4.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
|
+
|
|
234
|
+
```sh
|
|
235
|
+
zai-cli
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Or specify a working directory:
|
|
239
|
+
|
|
240
|
+
```sh
|
|
241
|
+
zai-cli -d /path/to/project
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### Headless Mode
|
|
245
|
+
|
|
246
|
+
Process a single prompt and exit (useful for scripting and automation):
|
|
247
|
+
|
|
248
|
+
```sh
|
|
249
|
+
zai-cli --prompt "show me the package.json file"
|
|
250
|
+
zai-cli -p "create a new file called example.js with a hello world function"
|
|
251
|
+
zai-cli --prompt "run bun test and show me the results" --directory /path/to/project
|
|
252
|
+
zai-cli --prompt "complex task" --max-tool-rounds 50 # Limit tool usage for faster execution
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
This mode is particularly useful for:
|
|
256
|
+
|
|
257
|
+
- **CI/CD pipelines**: Automate code analysis and file operations
|
|
258
|
+
- **Scripting**: Integrate AI assistance into shell scripts
|
|
259
|
+
- **Terminal benchmarks**: Perfect for tools like Terminal Bench that need non-interactive execution
|
|
260
|
+
- **Batch processing**: Process multiple prompts programmatically
|
|
261
|
+
|
|
262
|
+
### Tool Execution Control
|
|
263
|
+
|
|
264
|
+
By default, zai-cli allows up to 400 tool execution rounds to handle complex multi-step tasks. You can control this behavior:
|
|
265
|
+
|
|
266
|
+
```sh
|
|
267
|
+
# Limit tool rounds for faster execution on simple tasks
|
|
268
|
+
zai-cli --max-tool-rounds 10 --prompt "show me the current directory"
|
|
269
|
+
|
|
270
|
+
# Increase limit for very complex tasks (use with caution)
|
|
271
|
+
zai-cli --max-tool-rounds 1000 --prompt "comprehensive code refactoring"
|
|
272
|
+
|
|
273
|
+
# Works with all modes
|
|
274
|
+
zai-cli --max-tool-rounds 20 # Interactive mode
|
|
275
|
+
zai-cli git commit-and-push --max-tool-rounds 30 # Git commands
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
**Use Cases**:
|
|
279
|
+
|
|
280
|
+
- **Fast responses**: Lower limits (10-50) for simple queries
|
|
281
|
+
- **Complex automation**: Higher limits (500+) for comprehensive tasks
|
|
282
|
+
- **Resource control**: Prevent runaway executions in automated environments
|
|
283
|
+
|
|
284
|
+
### Model Selection
|
|
285
|
+
|
|
286
|
+
You can specify which AI model to use with the `--model` parameter or `GROK_MODEL` environment variable:
|
|
287
|
+
|
|
288
|
+
**Method 1: Command Line Flag**
|
|
289
|
+
|
|
290
|
+
```sh
|
|
291
|
+
# Use grok models
|
|
292
|
+
zai-cli --model grok-code-fast-1
|
|
293
|
+
zai-cli --model grok-4-latest
|
|
294
|
+
zai-cli --model grok-3-latest
|
|
295
|
+
zai-cli --model grok-3-fast
|
|
296
|
+
|
|
297
|
+
# Use other models (with appropriate API endpoint)
|
|
298
|
+
zai-cli --model gemini-2.5-pro --base-url https://api-endpoint.com/v1
|
|
299
|
+
zai-cli --model claude-sonnet-4-20250514 --base-url https://api-endpoint.com/v1
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
**Method 2: Environment Variable**
|
|
303
|
+
|
|
304
|
+
```sh
|
|
305
|
+
export GROK_MODEL=grok-code-fast-1
|
|
306
|
+
zai-cli
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
**Method 3: User Settings File**
|
|
310
|
+
|
|
311
|
+
Add to `~/.grok/user-settings.json`:
|
|
312
|
+
|
|
313
|
+
```json
|
|
314
|
+
{
|
|
315
|
+
"apiKey": "your_api_key_here",
|
|
316
|
+
"defaultModel": "grok-code-fast-1"
|
|
317
|
+
}
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
**Model Priority**: `--model` flag > `GROK_MODEL` environment variable > user default model > system default (grok-code-fast-1)
|
|
321
|
+
|
|
322
|
+
### Command Line Options
|
|
323
|
+
|
|
324
|
+
```sh
|
|
325
|
+
zai-cli [options]
|
|
326
|
+
|
|
327
|
+
Options:
|
|
328
|
+
-V, --version output the version number
|
|
329
|
+
-d, --directory <dir> set working directory
|
|
330
|
+
-k, --api-key <key> Grok API key (or set GROK_API_KEY env var)
|
|
331
|
+
-b, --backend <name> Backend display name (e.g., grok, openai, claude)
|
|
332
|
+
-u, --base-url <url> API base URL (or set GROK_BASE_URL env var)
|
|
333
|
+
-m, --model <model> AI model to use (e.g., grok-code-fast-1, grok-4-latest) (or set GROK_MODEL env
|
|
334
|
+
var)
|
|
335
|
+
-t, --temperature <temp> temperature for API requests (0.0-2.0, default: 0.7) (default: "0.7")
|
|
336
|
+
--max-tokens <tokens> maximum tokens for API responses (positive integer, no default = API default)
|
|
337
|
+
-p, --prompt [prompt] process a single prompt and exit (headless mode). If no prompt provided, reads
|
|
338
|
+
from stdin
|
|
339
|
+
--max-tool-rounds <rounds> maximum number of tool execution rounds (default: 400) (default: "400")
|
|
340
|
+
--fresh start with a fresh session (don't load previous chat history)
|
|
341
|
+
--auto-approve auto-approve all operations without confirmation prompts
|
|
342
|
+
--auto-approve-commands <commands> comma-separated list of commands to auto-approve (e.g.,
|
|
343
|
+
'chdir,list_files,pwd')
|
|
344
|
+
-c, --context <file> path to context persistence file (default: ~/.grok/chat-history.json)
|
|
345
|
+
--no-ink disable Ink UI and use plain console input/output
|
|
346
|
+
--debug-log <file> redirect MCP server debug output to log file instead of suppressing
|
|
347
|
+
--show-all-tools list all available tools (internal and MCP) and exit
|
|
348
|
+
--show-context-stats display token usage stats for the specified context file and exit
|
|
349
|
+
-h, --help display help for command
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
### Custom Instructions
|
|
353
|
+
|
|
354
|
+
You can provide custom instructions to tailor zai-cli's behavior by creating `GROK.md` files in two locations:
|
|
355
|
+
|
|
356
|
+
- **Global instructions** (apply to all projects): `~/.grok/GROK.md`
|
|
357
|
+
- **Project-specific instructions** (apply only to the current project): `.grok/GROK.md` in your project directory
|
|
358
|
+
|
|
359
|
+
Global instructions are loaded first, followed by project-specific instructions. If both exist, they are combined in that order.
|
|
360
|
+
|
|
361
|
+
To create project-specific instructions:
|
|
362
|
+
|
|
363
|
+
```sh
|
|
364
|
+
mkdir .grok
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
Create `.grok/GROK.md` with your custom instructions:
|
|
368
|
+
|
|
369
|
+
```markdown
|
|
370
|
+
# Custom Instructions for zai-cli
|
|
371
|
+
|
|
372
|
+
- Always use TypeScript for any new code files.
|
|
373
|
+
- When creating React components, use functional components with hooks.
|
|
374
|
+
- Prefer const assertions and explicit typing over inference where it improves clarity.
|
|
375
|
+
- Always add JSDoc comments for public functions and interfaces.
|
|
376
|
+
- Follow the existing code style and patterns in this project.
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
zai-cli will automatically load and follow these instructions when working in your project directory. The custom instructions are added to zai-cli's system prompt and take priority over default behavior.
|
|
380
|
+
|
|
381
|
+
## Morph Fast Apply (Optional)
|
|
382
|
+
|
|
383
|
+
zai-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.
|
|
384
|
+
|
|
385
|
+
**Setup**: Configure your Morph API key following the [setup instructions](#setup) above.
|
|
386
|
+
|
|
387
|
+
### How It Works
|
|
388
|
+
|
|
389
|
+
When `MORPH_API_KEY` is configured:
|
|
390
|
+
- **`edit_file` tool becomes available** alongside the standard `str_replace_editor`
|
|
391
|
+
- **Optimized for complex edits**: Use for multi-line changes, refactoring, and large modifications
|
|
392
|
+
- **Intelligent editing**: Uses abbreviated edit format with `// ... existing code ...` comments
|
|
393
|
+
- **Fallback support**: Standard tools remain available if Morph is unavailable
|
|
394
|
+
|
|
395
|
+
**When to use each tool:**
|
|
396
|
+
- **`edit_file`** (Morph): Complex edits, refactoring, multi-line changes
|
|
397
|
+
- **`str_replace_editor`**: Simple text replacements, single-line edits
|
|
398
|
+
|
|
399
|
+
### Example Usage
|
|
400
|
+
|
|
401
|
+
With Morph Fast Apply configured, you can request complex code changes:
|
|
402
|
+
|
|
403
|
+
```sh
|
|
404
|
+
zai-cli --prompt "refactor this function to use async/await and add error handling"
|
|
405
|
+
zai-cli -p "convert this class to TypeScript and add proper type annotations"
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
The AI will automatically choose between `edit_file` (Morph) for complex changes or `str_replace_editor` for simple replacements.
|
|
409
|
+
|
|
410
|
+
## MCP Tools
|
|
411
|
+
|
|
412
|
+
zai-cli supports MCP (Model Context Protocol) servers, allowing you to extend the AI assistant with additional tools and capabilities.
|
|
413
|
+
|
|
414
|
+
### Adding MCP Tools
|
|
415
|
+
|
|
416
|
+
#### Add a custom MCP server:
|
|
417
|
+
|
|
418
|
+
```sh
|
|
419
|
+
# Add an stdio-based MCP server
|
|
420
|
+
zai-cli mcp add my-server --transport stdio --command "bun" --args server.js
|
|
421
|
+
|
|
422
|
+
# Add an HTTP-based MCP server
|
|
423
|
+
zai-cli mcp add my-server --transport http --url "http://localhost:3000"
|
|
424
|
+
|
|
425
|
+
# Add with environment variables
|
|
426
|
+
zai-cli mcp add my-server --transport stdio --command "python" --args "-m" "my_mcp_server" --env "API_KEY=your_key"
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
#### Add from JSON configuration:
|
|
430
|
+
|
|
431
|
+
```sh
|
|
432
|
+
zai-cli mcp add-json my-server '{"command": "bun", "args": ["server.js"], "env": {"API_KEY": "your_key"}}'
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
### Linear Integration Example
|
|
436
|
+
|
|
437
|
+
To add Linear MCP tools for project management:
|
|
438
|
+
|
|
439
|
+
```sh
|
|
440
|
+
# Add Linear MCP server
|
|
441
|
+
zai-cli mcp add linear --transport sse --url "https://mcp.linear.app/sse"
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
This enables Linear tools like:
|
|
445
|
+
- Create and manage Linear issues
|
|
446
|
+
- Search and filter issues
|
|
447
|
+
- Update issue status and assignees
|
|
448
|
+
- Access team and project information
|
|
449
|
+
|
|
450
|
+
### Managing MCP Servers
|
|
451
|
+
|
|
452
|
+
```sh
|
|
453
|
+
# List all configured servers
|
|
454
|
+
zai-cli mcp list
|
|
455
|
+
|
|
456
|
+
# Test server connection
|
|
457
|
+
zai-cli mcp test server-name
|
|
458
|
+
|
|
459
|
+
# Remove a server
|
|
460
|
+
zai-cli mcp remove server-name
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
### Available Transport Types
|
|
464
|
+
|
|
465
|
+
- **stdio**: Run MCP server as a subprocess (most common)
|
|
466
|
+
- **http**: Connect to HTTP-based MCP server
|
|
467
|
+
- **sse**: Connect via Server-Sent Events
|
|
468
|
+
|
|
469
|
+
## Development
|
|
470
|
+
|
|
471
|
+
```sh
|
|
472
|
+
# Install dependencies
|
|
473
|
+
bun install
|
|
474
|
+
|
|
475
|
+
# Development mode
|
|
476
|
+
bun run dev
|
|
477
|
+
|
|
478
|
+
# Build project
|
|
479
|
+
bun run build
|
|
480
|
+
|
|
481
|
+
# Run linter
|
|
482
|
+
bun run lint
|
|
483
|
+
|
|
484
|
+
# Type check
|
|
485
|
+
bun run typecheck
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
## Architecture
|
|
489
|
+
|
|
490
|
+
- **Agent**: Core command processing and execution logic
|
|
491
|
+
- **Tools**: Text editor and bash tool implementations
|
|
492
|
+
- **UI**: Ink-based terminal interface components
|
|
493
|
+
- **Types**: TypeScript definitions for the entire system
|
|
494
|
+
|
|
495
|
+
## License
|
|
496
|
+
|
|
497
|
+
MIT
|