@zds-ai/cli 0.1.7 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/README.md +387 -34
  2. package/dist/agent/context-manager.d.ts +70 -0
  3. package/dist/agent/context-manager.js +138 -0
  4. package/dist/agent/context-manager.js.map +1 -0
  5. package/dist/agent/hook-manager.d.ts +194 -0
  6. package/dist/agent/hook-manager.js +676 -0
  7. package/dist/agent/hook-manager.js.map +1 -0
  8. package/dist/agent/llm-agent.d.ts +470 -100
  9. package/dist/agent/llm-agent.js +788 -1576
  10. package/dist/agent/llm-agent.js.map +1 -1
  11. package/dist/agent/message-processor.d.ts +103 -0
  12. package/dist/agent/message-processor.js +225 -0
  13. package/dist/agent/message-processor.js.map +1 -0
  14. package/dist/agent/prompt-variables.d.ts +113 -40
  15. package/dist/agent/prompt-variables.js +272 -81
  16. package/dist/agent/prompt-variables.js.map +1 -1
  17. package/dist/agent/session-manager.d.ts +75 -0
  18. package/dist/agent/session-manager.js +194 -0
  19. package/dist/agent/session-manager.js.map +1 -0
  20. package/dist/agent/streaming-agent.d.ts +33 -0
  21. package/dist/agent/streaming-agent.js +629 -0
  22. package/dist/agent/streaming-agent.js.map +1 -0
  23. package/dist/agent/tool-executor.d.ts +111 -0
  24. package/dist/agent/tool-executor.js +397 -0
  25. package/dist/agent/tool-executor.js.map +1 -0
  26. package/dist/bin/encode-speech.sh +64 -0
  27. package/dist/bin/extract-text.sh +66 -0
  28. package/dist/bin/generate_image_sd.sh +23 -12
  29. package/dist/bin/joycaption.sh +37 -0
  30. package/dist/bin/talking-agents.sh +291 -0
  31. package/dist/grok/client.d.ts +54 -0
  32. package/dist/grok/client.js +173 -20
  33. package/dist/grok/client.js.map +1 -1
  34. package/dist/grok/tools.js +98 -11
  35. package/dist/grok/tools.js.map +1 -1
  36. package/dist/hooks/use-enhanced-input.js +3 -1
  37. package/dist/hooks/use-enhanced-input.js.map +1 -1
  38. package/dist/hooks/use-input-handler.d.ts +1 -1
  39. package/dist/hooks/use-input-handler.js +101 -8
  40. package/dist/hooks/use-input-handler.js.map +1 -1
  41. package/dist/index.js +25 -3
  42. package/dist/index.js.map +1 -1
  43. package/dist/mcp/config.d.ts +1 -0
  44. package/dist/mcp/config.js +45 -7
  45. package/dist/mcp/config.js.map +1 -1
  46. package/dist/tools/audio-tool.d.ts +13 -0
  47. package/dist/tools/audio-tool.js +55 -0
  48. package/dist/tools/audio-tool.js.map +1 -0
  49. package/dist/tools/character-tool.js +13 -1
  50. package/dist/tools/character-tool.js.map +1 -1
  51. package/dist/tools/image-tool.d.ts +21 -1
  52. package/dist/tools/image-tool.js +201 -14
  53. package/dist/tools/image-tool.js.map +1 -1
  54. package/dist/tools/index.d.ts +11 -10
  55. package/dist/tools/index.js +11 -10
  56. package/dist/tools/index.js.map +1 -1
  57. package/dist/tools/introspect-tool.js +325 -2
  58. package/dist/tools/introspect-tool.js.map +1 -1
  59. package/dist/tools/morph-editor.d.ts +21 -9
  60. package/dist/tools/morph-editor.js +21 -9
  61. package/dist/tools/morph-editor.js.map +1 -1
  62. package/dist/ui/components/active-task-status.d.ts +1 -1
  63. package/dist/ui/components/api-key-input.d.ts +1 -1
  64. package/dist/ui/components/backend-status.d.ts +1 -1
  65. package/dist/ui/components/chat-history.d.ts +1 -1
  66. package/dist/ui/components/chat-input.js +1 -1
  67. package/dist/ui/components/chat-input.js.map +1 -1
  68. package/dist/ui/components/chat-interface.d.ts +1 -1
  69. package/dist/ui/components/chat-interface.js +2 -2
  70. package/dist/ui/components/chat-interface.js.map +1 -1
  71. package/dist/ui/components/context-status.d.ts +1 -1
  72. package/dist/ui/components/mood-status.d.ts +1 -1
  73. package/dist/ui/components/persona-status.d.ts +1 -1
  74. package/dist/ui/utils/markdown-renderer.js +2 -2
  75. package/dist/utils/chat-history-manager.d.ts +12 -4
  76. package/dist/utils/chat-history-manager.js +26 -11
  77. package/dist/utils/chat-history-manager.js.map +1 -1
  78. package/dist/utils/hook-executor.d.ts +53 -2
  79. package/dist/utils/hook-executor.js +261 -39
  80. package/dist/utils/hook-executor.js.map +1 -1
  81. package/dist/utils/path-utils.d.ts +2 -1
  82. package/dist/utils/path-utils.js +25 -4
  83. package/dist/utils/path-utils.js.map +1 -1
  84. package/dist/utils/rephrase-handler.d.ts +1 -1
  85. package/dist/utils/settings-manager.d.ts +41 -11
  86. package/dist/utils/settings-manager.js +172 -40
  87. package/dist/utils/settings-manager.js.map +1 -1
  88. package/dist/utils/slash-commands.d.ts +3 -3
  89. package/dist/utils/slash-commands.js +11 -5
  90. package/dist/utils/slash-commands.js.map +1 -1
  91. package/dist/utils/startup-hook.js +9 -2
  92. package/dist/utils/startup-hook.js.map +1 -1
  93. package/package.json +29 -24
package/README.md CHANGED
@@ -1,12 +1,12 @@
1
- # ZDS AI CLI (forked from Grok CLI)
1
+ # ZDS AI CLI
2
2
 
3
- A conversational AI CLI tool powered by Grok with intelligent text editor capabilities and tool usage.
3
+ A multi-backend conversational AI CLI tool with intelligent text editor capabilities and tool usage. Supports OpenAI, Anthropic Claude, X.AI Grok, Ollama, and other OpenAI-compatible providers.
4
4
 
5
5
  <img width="720" height="528" alt="Image" src="https://github.com/user-attachments/assets/f697a273-141e-4f02-8c15-37143aa7ec0e" />
6
6
 
7
7
  ## Features
8
8
 
9
- - **🤖 Conversational AI**: Natural language interface powered by grok, others
9
+ - **⚡ Multi-Backend Support**: Works with OpenAI, Anthropic Claude, X.AI Grok, Ollama, OpenRouter, and any OpenAI-compatible API
10
10
  - **📝 Smart File Operations**: AI automatically uses tools to view, create, and edit files
11
11
  - **⚡ Zsh Integration**: Execute shell commands through natural conversation
12
12
  - **🔧 Automatic Tool Selection**: AI intelligently chooses the right tools for your requests
@@ -18,8 +18,14 @@ A conversational AI CLI tool powered by Grok with intelligent text editor capabi
18
18
  ## Installation
19
19
 
20
20
  ### Prerequisites
21
+
21
22
  - Bun 1.0+ (or Node.js 18+ as fallback)
22
- - GROK API key from X.AI
23
+ - API key from your chosen provider:
24
+ - X.AI Grok: Get from [X.AI](https://x.ai)
25
+ - OpenAI: Get from [OpenAI Platform](https://platform.openai.com)
26
+ - Anthropic Claude: Get from [Anthropic Console](https://console.anthropic.com)
27
+ - Ollama: Self-hosted (no API key needed) or Ollama Cloud (get from [Ollama Cloud](https://ollama.com))
28
+ - OpenRouter: Get from [OpenRouter](https://openrouter.ai)
23
29
  - (Optional, Recommended) Morph API key for Fast Apply editing
24
30
 
25
31
  ### System Dependencies
@@ -46,12 +52,14 @@ zai-cli requires the following system tools for certain features:
46
52
 
47
53
  ```sh
48
54
  bun add -g @zds-ai/cli
55
+
49
56
  ```
50
57
 
51
58
  Or with npm (fallback):
52
59
 
53
60
  ```sh
54
61
  npm install -g @zds-ai/cli
62
+
55
63
  ```
56
64
 
57
65
  ### Local Development
@@ -62,58 +70,108 @@ cd zds-ai-cli
62
70
  bun install
63
71
  bun run build
64
72
  bun link
73
+
65
74
  ```
66
75
 
67
76
  ## Setup
68
77
 
69
- 1. Get your GROK API key from [X.AI](https://x.ai)
78
+ ### Quick Start with X.AI Grok (Default)
79
+
80
+ > **Note**: Environment variables use `GROK_*` prefixes (legacy naming from the original fork), but they work with **all backends**, not just Grok. See "[Using Other Providers](#using-other-providers)" below to configure different backends.
81
+
82
+ > **Important**: As of December 15, 2025, Grok's `search_parameters` API has been deprecated. zai-cli now uses the new Agent Tools API for web search functionality. Old code using `search_parameters` is automatically converted to the new format for backward compatibility. See [Grok's Agent Tools documentation](https://docs.x.ai/docs/guides/tools/search-tools) for details.
83
+
84
+ 1. Get your API key from [X.AI](https://x.ai)
85
+
86
+ 2. Set up your API key (choose one method):
70
87
 
71
- 2. Set up your API key (choose one method):
72
-
73
88
  **Method 1: Environment Variable**
74
-
89
+
75
90
  ```sh
76
91
  export GROK_API_KEY=your_api_key_here
92
+
77
93
  ```
78
-
94
+
79
95
  **Method 2: .env File**
80
-
96
+
81
97
  ```sh
82
98
  cp .env.example .env
99
+
83
100
  # Edit .env and add your API key
101
+
102
+
84
103
  ```
85
-
104
+
86
105
  **Method 3: Command Line Flag**
87
-
106
+
88
107
  ```sh
89
108
  zai-cli --api-key your_api_key_here
109
+
90
110
  ```
91
-
111
+
92
112
  **Method 4: User Settings File**
93
-
94
- Create `~/.grok/user-settings.json`:
95
-
113
+
114
+ Create `~/.zds-ai/cli-settings.json`:
115
+
96
116
  ```json
97
117
  {
98
118
  "apiKey": "your_api_key_here"
99
119
  }
120
+
100
121
  ```
101
122
 
123
+ ### Using Other Providers
124
+
125
+ zai-cli supports any OpenAI-compatible API. Set your provider's API key and base URL:
126
+
127
+ **OpenAI:**
128
+
129
+ ```sh
130
+ export GROK_API_KEY=your_openai_key
131
+ export GROK_BASE_URL=https://api.openai.com/v1
132
+ export GROK_MODEL=gpt-4o
133
+
134
+ ```
135
+
136
+ **Ollama (Local):**
137
+
138
+ ```sh
139
+ export GROK_BASE_URL=http://localhost:11434/v1
140
+ export GROK_MODEL=llama3
141
+
142
+ # No API key needed for local Ollama
143
+
144
+
145
+ ```
146
+
147
+ **OpenRouter:**
148
+
149
+ ```sh
150
+ export GROK_API_KEY=your_openrouter_key
151
+ export GROK_BASE_URL=https://openrouter.ai/api/v1
152
+ export GROK_MODEL=anthropic/claude-4.5-sonnet
153
+
154
+ ```
155
+
102
156
  3. (Optional, Recommended) Get your Morph API key from [Morph Dashboard](https://morphllm.com/dashboard/api-keys)
103
157
 
104
- 4. Set up your Morph API key for Fast Apply editing (choose one method):
158
+ 4. Set up your Morph API key for Fast Apply editing (choose one method):
105
159
 
106
160
  **Method 1: Environment Variable**
107
161
 
108
162
  ```sh
109
163
  export MORPH_API_KEY=your_morph_api_key_here
164
+
110
165
  ```
111
166
 
112
167
  **Method 2: .env File**
113
168
 
114
169
  ```sh
170
+
115
171
  # Add to your .env file
172
+
116
173
  MORPH_API_KEY=your_morph_api_key_here
174
+
117
175
  ```
118
176
 
119
177
  ### Custom Base URL (Optional)
@@ -124,35 +182,38 @@ By default, the CLI uses `https://api.x.ai/v1` as the API endpoint. You can con
124
182
 
125
183
  ```sh
126
184
  export GROK_BASE_URL=https://your-custom-endpoint.com/v1
185
+
127
186
  ```
128
187
 
129
188
  **Method 2: Command Line Flag**
130
189
 
131
190
  ```sh
132
191
  zai-cli --api-key your_api_key_here --base-url https://your-custom-endpoint.com/v1
192
+
133
193
  ```
134
194
 
135
195
  **Method 3: User Settings File**
136
196
 
137
- Add to `~/.grok/user-settings.json`:
197
+ Add to `~/.zds-ai/cli-settings.json`:
138
198
 
139
199
  ```json
140
200
  {
141
201
  "apiKey": "your_api_key_here",
142
202
  "baseURL": "https://your-custom-endpoint.com/v1"
143
203
  }
204
+
144
205
  ```
145
206
 
146
207
  ## Configuration Files
147
208
 
148
209
  zai-cli uses two types of configuration files to manage settings:
149
210
 
150
- ### User-Level Settings (`~/.grok/user-settings.json`)
211
+ ### User-Level Settings (`~/.zds-ai/cli-settings.json`)
151
212
 
152
- This file stores **global settings** that apply across all projects. These settings rarely change and include:
213
+ This file stores **global settings** that apply across all projects. These settings rarely change and include:
153
214
 
154
- - **API Key**: Your GROK API key
155
- - **Base URL**: Custom API endpoint (if needed)
215
+ - **API Key**: Your API key (works with any backend)
216
+ - **Base URL**: API endpoint (determines which backend you use)
156
217
  - **Default Model**: Your preferred model (e.g., `grok-code-fast-1`)
157
218
  - **Available Models**: List of models you can use
158
219
 
@@ -172,6 +233,7 @@ This file stores **global settings** that apply across all projects. These setti
172
233
  ],
173
234
  "startupHook": "date"
174
235
  }
236
+
175
237
  ```
176
238
 
177
239
  #### Startup Hook
@@ -181,15 +243,13 @@ You can configure a **startup hook** command that runs when zai-cli starts. The
181
243
  **Example use cases:**
182
244
 
183
245
  - Show current date/time: `"startupHook": "date"`
184
- - Display git status: `"startupHook": "git status --short"`
185
- - Show active branches: `"startupHook": "git branch --show-current"`
186
246
  - Custom environment info: `"startupHook": "/path/to/your/script.sh"`
187
247
 
188
248
  The command runs with a 10-second timeout and the output appears in the AI's context before custom instructions.
189
249
 
190
- ### Project-Level Settings (`.grok/settings.json`)
250
+ ### Project-Level Settings (`.zds-ai/project-settings.json`)
191
251
 
192
- This file stores **project-specific settings** in your current working directory. It includes:
252
+ This file stores **project-specific settings** in your current working directory. It includes:
193
253
 
194
254
  - **Current Model**: The model currently in use for this project
195
255
  - **MCP Servers**: Model Context Protocol server configurations
@@ -208,6 +268,7 @@ This file stores **project-specific settings** in your current working directory
208
268
  }
209
269
  }
210
270
  }
271
+
211
272
  ```
212
273
 
213
274
  ### How It Works
@@ -221,7 +282,7 @@ This means you can have different models for different projects while maintainin
221
282
 
222
283
  ### Using Other API Providers
223
284
 
224
- **Important**: zai-cli uses **OpenAI-compatible APIs**. You can use any provider that implements the OpenAI chat completions standard.
285
+ **Important**: zai-cli uses **OpenAI-compatible APIs**. You can use any provider that implements the OpenAI chat completions standard.
225
286
 
226
287
  **Popular Providers**:
227
288
 
@@ -243,6 +304,7 @@ This means you can have different models for different projects while maintainin
243
304
  "meta-llama/llama-3.1-70b-instruct"
244
305
  ]
245
306
  }
307
+
246
308
  ```
247
309
 
248
310
  ## Usage
@@ -253,12 +315,14 @@ Start the conversational AI assistant:
253
315
 
254
316
  ```sh
255
317
  zai-cli
318
+
256
319
  ```
257
320
 
258
321
  Or specify a working directory:
259
322
 
260
323
  ```sh
261
324
  zai-cli -d /path/to/project
325
+
262
326
  ```
263
327
 
264
328
  ### Headless Mode
@@ -270,6 +334,7 @@ zai-cli --prompt "show me the package.json file"
270
334
  zai-cli -p "create a new file called example.js with a hello world function"
271
335
  zai-cli --prompt "run bun test and show me the results" --directory /path/to/project
272
336
  zai-cli --prompt "complex task" --max-tool-rounds 50 # Limit tool usage for faster execution
337
+
273
338
  ```
274
339
 
275
340
  This mode is particularly useful for:
@@ -281,18 +346,22 @@ This mode is particularly useful for:
281
346
 
282
347
  ### Tool Execution Control
283
348
 
284
- By default, zai-cli allows up to 400 tool execution rounds to handle complex multi-step tasks. You can control this behavior:
349
+ By default, zai-cli allows up to 400 tool execution rounds to handle complex multi-step tasks. You can control this behavior:
285
350
 
286
351
  ```sh
352
+
287
353
  # Limit tool rounds for faster execution on simple tasks
354
+
288
355
  zai-cli --max-tool-rounds 10 --prompt "show me the current directory"
289
356
 
290
357
  # Increase limit for very complex tasks (use with caution)
358
+
291
359
  zai-cli --max-tool-rounds 1000 --prompt "comprehensive code refactoring"
292
360
 
293
361
  # Works with all modes
362
+
294
363
  zai-cli --max-tool-rounds 20 # Interactive mode
295
- zai-cli git commit-and-push --max-tool-rounds 30 # Git commands
364
+
296
365
  ```
297
366
 
298
367
  **Use Cases**:
@@ -308,15 +377,19 @@ You can specify which AI model to use with the `--model` parameter or `GROK_MODE
308
377
  **Method 1: Command Line Flag**
309
378
 
310
379
  ```sh
380
+
311
381
  # Use grok models
382
+
312
383
  zai-cli --model grok-code-fast-1
313
384
  zai-cli --model grok-4-latest
314
385
  zai-cli --model grok-3-latest
315
386
  zai-cli --model grok-3-fast
316
387
 
317
388
  # Use other models (with appropriate API endpoint)
389
+
318
390
  zai-cli --model gemini-2.5-pro --base-url https://api-endpoint.com/v1
319
391
  zai-cli --model claude-sonnet-4-20250514 --base-url https://api-endpoint.com/v1
392
+
320
393
  ```
321
394
 
322
395
  **Method 2: Environment Variable**
@@ -324,17 +397,19 @@ zai-cli --model claude-sonnet-4-20250514 --base-url https://api-endpoint.com/v1
324
397
  ```sh
325
398
  export GROK_MODEL=grok-code-fast-1
326
399
  zai-cli
400
+
327
401
  ```
328
402
 
329
403
  **Method 3: User Settings File**
330
404
 
331
- Add to `~/.grok/user-settings.json`:
405
+ Add to `~/.zds-ai/cli-settings.json`:
332
406
 
333
407
  ```json
334
408
  {
335
409
  "apiKey": "your_api_key_here",
336
410
  "defaultModel": "grok-code-fast-1"
337
411
  }
412
+
338
413
  ```
339
414
 
340
415
  **Model Priority**: `--model` flag > `GROK_MODEL` environment variable > user default model > system default (grok-code-fast-1)
@@ -344,20 +419,27 @@ Add to `~/.grok/user-settings.json`:
344
419
  zai-cli supports sending images to vision-capable AI models. Use the `@` prefix to reference image files in your messages:
345
420
 
346
421
  ```sh
422
+
347
423
  # Absolute path
424
+
348
425
  zai-cli --prompt "What's in this image? @/Users/joseph/photos/image.jpg"
349
426
 
350
427
  # Relative path
428
+
351
429
  zai-cli --prompt "Analyze @./screenshot.png"
352
430
 
353
431
  # Tilde expansion
432
+
354
433
  zai-cli --prompt "Describe @~/Pictures/photo.jpg"
355
434
 
356
435
  # Paths with spaces (quoted)
436
+
357
437
  zai-cli --prompt 'Compare these images: @"~/My Pictures/photo1.jpg" @"~/My Pictures/photo2.jpg"'
358
438
 
359
439
  # Paths with spaces (escaped)
440
+
360
441
  zai-cli --prompt "What's here? @/Users/joseph/My\ Documents/image.png"
442
+
361
443
  ```
362
444
 
363
445
  **Supported Image Formats**: .jpg, .jpeg, .png, .gif, .webp, .bmp
@@ -379,30 +461,33 @@ zai-cli [options]
379
461
  Options:
380
462
  -V, --version output the version number
381
463
  -d, --directory <dir> set working directory
382
- -k, --api-key <key> Grok API key (or set GROK_API_KEY env var)
464
+ -k, --api-key <key> API key for your backend (or set GROK_API_KEY env var -- works with all backends)
383
465
  -b, --backend <name> Backend display name (e.g., grok, openai, claude)
384
466
  -u, --base-url <url> API base URL (or set GROK_BASE_URL env var)
385
467
  -m, --model <model> AI model to use (e.g., grok-code-fast-1, grok-4-latest) (or set GROK_MODEL env
386
468
  var)
387
469
  -t, --temperature <temp> temperature for API requests (0.0-2.0, default: 0.7) (default: "0.7")
388
470
  --max-tokens <tokens> maximum tokens for API responses (positive integer, no default = API default)
389
- -p, --prompt [prompt] process a single prompt and exit (headless mode). If no prompt provided, reads
471
+ -p, --prompt [prompt] process a single prompt and exit (headless mode). If no prompt provided, reads
390
472
  from stdin
391
473
  --max-tool-rounds <rounds> maximum number of tool execution rounds (default: 400) (default: "400")
392
474
  --fresh start with a fresh session (don't load previous chat history)
393
475
  --auto-approve auto-approve all operations without confirmation prompts
394
476
  --auto-approve-commands <commands> comma-separated list of commands to auto-approve (e.g.,
395
477
  'chdir,list_files,pwd')
396
- -c, --context <file> path to context persistence file (default: ~/.grok/chat-history.json)
478
+ -c, --context <file> path to context persistence file (default: ~/.zds-ai/context.json)
397
479
  --no-ink disable Ink UI and use plain console input/output
398
480
  --debug-log <file> redirect MCP server debug output to log file instead of suppressing
399
481
  --show-all-tools list all available tools (internal and MCP) and exit
400
482
  --show-context-stats display token usage stats for the specified context file and exit
401
483
  -h, --help display help for command
484
+
402
485
  ```
403
486
 
404
487
  ### Custom Instructions
405
488
 
489
+ > **Note**: Custom instructions still use the legacy `.grok/` directory paths (not `.zds-ai/`). This is for backwards compatibility with the original fork.
490
+
406
491
  You can provide custom instructions to tailor zai-cli's behavior by creating `GROK.md` files in two locations:
407
492
 
408
493
  - **Global instructions** (apply to all projects): `~/.grok/GROK.md`
@@ -414,11 +499,13 @@ To create project-specific instructions:
414
499
 
415
500
  ```sh
416
501
  mkdir .grok
502
+
417
503
  ```
418
504
 
419
505
  Create `.grok/GROK.md` with your custom instructions:
420
506
 
421
507
  ```markdown
508
+
422
509
  # Custom Instructions for zai-cli
423
510
 
424
511
  - Always use TypeScript for any new code files.
@@ -426,13 +513,14 @@ Create `.grok/GROK.md` with your custom instructions:
426
513
  - Prefer const assertions and explicit typing over inference where it improves clarity.
427
514
  - Always add JSDoc comments for public functions and interfaces.
428
515
  - Follow the existing code style and patterns in this project.
516
+
429
517
  ```
430
518
 
431
519
  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.
432
520
 
433
521
  ## Morph Fast Apply (Optional)
434
522
 
435
- 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.
523
+ 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.
436
524
 
437
525
  **Setup**: Configure your Morph API key following the [setup instructions](#setup) above.
438
526
 
@@ -455,6 +543,7 @@ With Morph Fast Apply configured, you can request complex code changes:
455
543
  ```sh
456
544
  zai-cli --prompt "refactor this function to use async/await and add error handling"
457
545
  zai-cli -p "convert this class to TypeScript and add proper type annotations"
546
+
458
547
  ```
459
548
 
460
549
  The AI will automatically choose between `edit_file` (Morph) for complex changes or `str_replace_editor` for simple replacements.
@@ -468,20 +557,26 @@ zai-cli supports MCP (Model Context Protocol) servers, allowing you to extend th
468
557
  #### Add a custom MCP server:
469
558
 
470
559
  ```sh
560
+
471
561
  # Add an stdio-based MCP server
562
+
472
563
  zai-cli mcp add my-server --transport stdio --command "bun" --args server.js
473
564
 
474
565
  # Add an HTTP-based MCP server
566
+
475
567
  zai-cli mcp add my-server --transport http --url "http://localhost:3000"
476
568
 
477
569
  # Add with environment variables
570
+
478
571
  zai-cli mcp add my-server --transport stdio --command "python" --args "-m" "my_mcp_server" --env "API_KEY=your_key"
572
+
479
573
  ```
480
574
 
481
575
  #### Add from JSON configuration:
482
576
 
483
577
  ```sh
484
578
  zai-cli mcp add-json my-server '{"command": "bun", "args": ["server.js"], "env": {"API_KEY": "your_key"}}'
579
+
485
580
  ```
486
581
 
487
582
  ### Linear Integration Example
@@ -489,8 +584,11 @@ zai-cli mcp add-json my-server '{"command": "bun", "args": ["server.js"], "env":
489
584
  To add Linear MCP tools for project management:
490
585
 
491
586
  ```sh
587
+
492
588
  # Add Linear MCP server
589
+
493
590
  zai-cli mcp add linear --transport sse --url "https://mcp.linear.app/sse"
591
+
494
592
  ```
495
593
 
496
594
  This enables Linear tools like:
@@ -502,14 +600,19 @@ This enables Linear tools like:
502
600
  ### Managing MCP Servers
503
601
 
504
602
  ```sh
603
+
505
604
  # List all configured servers
605
+
506
606
  zai-cli mcp list
507
607
 
508
608
  # Test server connection
609
+
509
610
  zai-cli mcp test server-name
510
611
 
511
612
  # Remove a server
613
+
512
614
  zai-cli mcp remove server-name
615
+
513
616
  ```
514
617
 
515
618
  ### Available Transport Types
@@ -518,23 +621,273 @@ zai-cli mcp remove server-name
518
621
  - **http**: Connect to HTTP-based MCP server
519
622
  - **sse**: Connect via Server-Sent Events
520
623
 
624
+ ## Hooks System
625
+
626
+ zai-cli includes a powerful hooks system for customizing behavior at various points in the execution lifecycle. Hooks are shell commands that can modify context, set variables, or control execution flow.
627
+
628
+ ### Configuring Hooks
629
+
630
+ Add hooks to `~/.zds-ai/cli-settings.json` or `.zds-ai/project-settings.json`:
631
+
632
+ ```json
633
+ {
634
+ "startupHook": "echo 'Session started'",
635
+ "instanceHook": "/path/to/script.sh",
636
+ "personaHook": "validate-persona.sh",
637
+ "personaHookMandatory": true
638
+ }
639
+
640
+ ```
641
+
642
+ ### Available Hooks
643
+
644
+ **Lifecycle Hooks:**
645
+ - `startupHook` - Runs at session start, output added to system prompt
646
+ - `instanceHook` - Runs for every instance (new and resumed sessions)
647
+
648
+ **Operation Hooks:**
649
+ - `postUserInputHook` - Runs after user input received
650
+ - `preLLMResponseHook` - Runs before prompt sent to LLM
651
+ - `postLLMResponseHook` - Runs after LLM response
652
+ - `preToolCallHook` - Runs before tool execution
653
+ - `postToolCallHook` - Runs after tool execution
654
+
655
+ **Validation Hooks:**
656
+ - `taskApprovalHook` - Validates task operations (start/transition/stop)
657
+ - `toolApprovalHook` - Validates tool execution before running
658
+ - `personaHook` - Validates persona changes
659
+ - `moodHook` - Validates mood changes
660
+
661
+ **Context Helpers:**
662
+ - `contextViewHelper` / `contextViewHelperGui` - Custom context viewing
663
+ - `contextEditHelper` / `contextEditHelperGui` - Custom context editing
664
+
665
+ ### Hook Commands
666
+
667
+ Hooks can output special commands to control the CLI:
668
+
669
+ ```sh
670
+
671
+ # Set environment variables
672
+
673
+ ENV VAR_NAME=value
674
+
675
+ # Set prompt variables
676
+
677
+ SET VAR:NAME=value
678
+ SET_FILE VAR:NAME=/path/to/file
679
+
680
+ # Add system messages
681
+
682
+ SYSTEM This message appears in the system prompt
683
+
684
+ # Test backend configurations (persona/mood hooks)
685
+
686
+ TEST_BACKEND backend_name base_url model api_key_env_var
687
+
688
+ # Model/backend selection
689
+
690
+ MODEL model_name
691
+ BACKEND backend_name
692
+ BASE_URL https://api.example.com/v1
693
+ API_KEY_ENV_VAR ENV_VAR_NAME
694
+
695
+ ```
696
+
697
+ ## Personas and Moods
698
+
699
+ Customize the AI's behavior and context with personas and moods.
700
+
701
+ ### Using Personas
702
+
703
+ ```sh
704
+
705
+ # Set persona
706
+
707
+ /persona debugging red
708
+ /persona architect blue
709
+
710
+ # With hook validation (if personaHook configured)
711
+
712
+ /persona production-review yellow
713
+
714
+ ```
715
+
716
+ Personas can:
717
+ - Change the AI's behavior and focus
718
+ - Switch backends/models via hooks
719
+ - Set environment variables
720
+ - Add context to the system prompt
721
+
722
+ ### Using Moods
723
+
724
+ ```sh
725
+
726
+ # Set mood
727
+
728
+ /mood focused green
729
+ /mood exploratory purple
730
+
731
+ ```
732
+
733
+ Moods provide additional behavioral context without changing the fundamental persona.
734
+
735
+ ### Configuring Persona/Mood Hooks
736
+
737
+ ```json
738
+ {
739
+ "personaHook": "persona-validator.sh",
740
+ "personaHookMandatory": true,
741
+ "moodHook": "mood-setter.sh",
742
+ "moodHookMandatory": false
743
+ }
744
+
745
+ ```
746
+
747
+ Hook validation can switch backends, set variables, or reject invalid personas/moods.
748
+
749
+ ## Active Tasks
750
+
751
+ Track and manage active tasks with documentation support.
752
+
753
+ ### Task Commands
754
+
755
+ ```sh
756
+
757
+ # Start a task
758
+
759
+ /task start "Implement feature X" "designing" blue
760
+
761
+ # Update task status
762
+
763
+ /task status "implementing" yellow
764
+
765
+ # Stop task and document
766
+
767
+ /task stop "Feature complete" docs/feature-x.md green
768
+
769
+ ```
770
+
771
+ ### Task Tool Usage
772
+
773
+ The AI can also manage tasks via tools:
774
+ - `startActiveTask(name, action, color)` - Begin tracking a task
775
+ - `transitionActiveTaskStatus(action, color)` - Update task status
776
+ - `stopActiveTask(reason, documentationFile, color)` - Complete and document task
777
+
778
+ Tasks persist across sessions and appear in the system prompt.
779
+
780
+ ## Session Persistence
781
+
782
+ zai-cli automatically saves and restores session state between runs.
783
+
784
+ ### What Gets Saved
785
+
786
+ - Chat history
787
+ - Active persona and mood
788
+ - Current task
789
+ - Backend and model selection
790
+ - Working directory
791
+ - Prompt variables
792
+ - System prompt
793
+
794
+ ### Session Management
795
+
796
+ ```sh
797
+
798
+ # Start fresh session (ignore saved state)
799
+
800
+ zai-cli --fresh
801
+
802
+ # View current context
803
+
804
+ /context
805
+
806
+ # Edit context manually
807
+
808
+ /context edit
809
+
810
+ # Reload context from file
811
+
812
+ /context reload
813
+
814
+ # Compact context (keep last 20 messages)
815
+
816
+ /compact
817
+
818
+ ```
819
+
820
+ Context is automatically saved to `~/.zds-ai/context.json`
821
+
822
+ ## Slash Commands Reference
823
+
824
+ ### Help and Information
825
+
826
+ - `/?` - Introspect tools and environment (alias for `/introspect`)
827
+ - `/help` - Show command help
828
+ - `/introspect` - List all available tools and environment info
829
+
830
+ ### History Management
831
+
832
+ - `/clear` - Clear chat history (current session + persisted)
833
+ - `/compact` - Reduce context size (keep last 20 messages)
834
+
835
+ ### Context Operations
836
+
837
+ - `/context` - Show context usage info
838
+ - `/context view` - View full context in pager (markdown format)
839
+ - `/context edit` - Edit context JSON file (opens in $EDITOR)
840
+ - `/context reload` - Reload context from file immediately
841
+
842
+ ### Model and Backend
843
+
844
+ - `/models` - Interactive model selection menu
845
+ - `/models <model>` - Switch to specific model directly
846
+
847
+ ### State Management
848
+
849
+ - `/persona <text> [color]` - Set current persona
850
+ - `/mood <text> [color]` - Set current mood
851
+
852
+ ### Response Control
853
+
854
+ - `/rephrase [text]` - Request rephrasing of last response
855
+ - `/system rephrase [text]` - Same as /rephrase but as system message
856
+
857
+ ### UI Control
858
+
859
+ - `/ink` - Switch to Ink UI mode (restart required)
860
+ - `/no-ink` - Switch to plain console mode (restart required)
861
+
862
+ ### Session Control
863
+
864
+ - `/restart` - Restart the application (exit code 51)
865
+ - `/exit` or `exit` or `quit` - Exit application
866
+
521
867
  ## Development
522
868
 
523
869
  ```sh
870
+
524
871
  # Install dependencies
872
+
525
873
  bun install
526
874
 
527
875
  # Development mode
876
+
528
877
  bun run dev
529
878
 
530
879
  # Build project
880
+
531
881
  bun run build
532
882
 
533
883
  # Run linter
884
+
534
885
  bun run lint
535
886
 
536
887
  # Type check
888
+
537
889
  bun run typecheck
890
+
538
891
  ```
539
892
 
540
893
  ## Architecture