@zds-ai/cli 0.1.2 → 0.1.4

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 (49) hide show
  1. package/README.md +94 -42
  2. package/dist/agent/grok-agent.d.ts +19 -5
  3. package/dist/agent/grok-agent.js +256 -207
  4. package/dist/agent/grok-agent.js.map +1 -1
  5. package/dist/bin/generate_image_sd.sh +252 -0
  6. package/dist/bin/read_xlsx.py +308 -0
  7. package/dist/grok/client.d.ts +7 -0
  8. package/dist/grok/client.js +88 -7
  9. package/dist/grok/client.js.map +1 -1
  10. package/dist/grok/tools.js +12 -0
  11. package/dist/grok/tools.js.map +1 -1
  12. package/dist/hooks/use-input-handler.d.ts +2 -0
  13. package/dist/hooks/use-input-handler.js +76 -48
  14. package/dist/hooks/use-input-handler.js.map +1 -1
  15. package/dist/index.js +144 -21
  16. package/dist/index.js.map +1 -1
  17. package/dist/mcp/client.js +3 -4
  18. package/dist/mcp/client.js.map +1 -1
  19. package/dist/tools/file-conversion-tool.js +2 -2
  20. package/dist/tools/file-conversion-tool.js.map +1 -1
  21. package/dist/tools/image-tool.d.ts +8 -2
  22. package/dist/tools/image-tool.js +65 -6
  23. package/dist/tools/image-tool.js.map +1 -1
  24. package/dist/tools/search.d.ts +1 -1
  25. package/dist/tools/search.js +41 -53
  26. package/dist/tools/search.js.map +1 -1
  27. package/dist/ui/components/chat-history.js +25 -12
  28. package/dist/ui/components/chat-history.js.map +1 -1
  29. package/dist/ui/components/chat-interface.js +16 -9
  30. package/dist/ui/components/chat-interface.js.map +1 -1
  31. package/dist/ui/components/rephrase-menu.d.ts +8 -0
  32. package/dist/ui/components/rephrase-menu.js +25 -0
  33. package/dist/ui/components/rephrase-menu.js.map +1 -0
  34. package/dist/utils/chat-history-manager.js +16 -6
  35. package/dist/utils/chat-history-manager.js.map +1 -1
  36. package/dist/utils/content-utils.d.ts +5 -0
  37. package/dist/utils/content-utils.js +15 -0
  38. package/dist/utils/content-utils.js.map +1 -0
  39. package/dist/utils/image-encoder.d.ts +35 -0
  40. package/dist/utils/image-encoder.js +133 -0
  41. package/dist/utils/image-encoder.js.map +1 -0
  42. package/dist/utils/rephrase-handler.d.ts +15 -0
  43. package/dist/utils/rephrase-handler.js +106 -0
  44. package/dist/utils/rephrase-handler.js.map +1 -0
  45. package/dist/utils/slash-commands.js +1 -23
  46. package/dist/utils/slash-commands.js.map +1 -1
  47. package/dist/utils/token-counter.js +17 -2
  48. package/dist/utils/token-counter.js.map +1 -1
  49. package/package.json +9 -6
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  A conversational AI CLI tool powered by Grok with intelligent text editor capabilities and tool usage.
4
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" />
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
 
@@ -22,6 +22,26 @@ A conversational AI CLI tool powered by Grok with intelligent text editor capabi
22
22
  - GROK API key from X.AI
23
23
  - (Optional, Recommended) Morph API key for Fast Apply editing
24
24
 
25
+ ### System Dependencies
26
+
27
+ zai-cli requires the following system tools for certain features:
28
+
29
+ - **ripgrep** (required for search functionality)
30
+ - macOS: `brew install ripgrep`
31
+ - Ubuntu/Debian: `apt install ripgrep`
32
+ - Windows: `choco install ripgrep` or download from [releases](https://github.com/BurntSushi/ripgrep/releases)
33
+ - Other platforms: See [ripgrep installation guide](https://github.com/BurntSushi/ripgrep#installation)
34
+
35
+ - **Python 3 with openpyxl** (optional, required for XLSX file reading)
36
+ - Install: `pip3 install openpyxl` or `python3 -m pip install openpyxl`
37
+ - Most systems already have Python 3 installed
38
+
39
+ - **exiftool** (optional, required for PNG metadata extraction)
40
+ - macOS: `brew install exiftool`
41
+ - Ubuntu/Debian: `apt install libimage-exiftool-perl`
42
+ - Windows: Download from [exiftool.org](https://exiftool.org/)
43
+ - Other platforms: See [exiftool installation guide](https://exiftool.org/install.html)
44
+
25
45
  ### Global Installation (Recommended)
26
46
 
27
47
  ```sh
@@ -49,52 +69,52 @@ bun link
49
69
  1. Get your GROK API key from [X.AI](https://x.ai)
50
70
 
51
71
  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
- ```
72
+
73
+ **Method 1: Environment Variable**
74
+
75
+ ```sh
76
+ export GROK_API_KEY=your_api_key_here
77
+ ```
78
+
79
+ **Method 2: .env File**
80
+
81
+ ```sh
82
+ cp .env.example .env
83
+ # Edit .env and add your API key
84
+ ```
85
+
86
+ **Method 3: Command Line Flag**
87
+
88
+ ```sh
89
+ zai-cli --api-key your_api_key_here
90
+ ```
91
+
92
+ **Method 4: User Settings File**
93
+
94
+ Create `~/.grok/user-settings.json`:
95
+
96
+ ```json
97
+ {
98
+ "apiKey": "your_api_key_here"
99
+ }
100
+ ```
81
101
 
82
102
  3. (Optional, Recommended) Get your Morph API key from [Morph Dashboard](https://morphllm.com/dashboard/api-keys)
83
103
 
84
104
  4. Set up your Morph API key for Fast Apply editing (choose one method):
85
105
 
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
- ```
106
+ **Method 1: Environment Variable**
107
+
108
+ ```sh
109
+ export MORPH_API_KEY=your_morph_api_key_here
110
+ ```
111
+
112
+ **Method 2: .env File**
113
+
114
+ ```sh
115
+ # Add to your .env file
116
+ MORPH_API_KEY=your_morph_api_key_here
117
+ ```
98
118
 
99
119
  ### Custom Base URL (Optional)
100
120
 
@@ -319,6 +339,38 @@ Add to `~/.grok/user-settings.json`:
319
339
 
320
340
  **Model Priority**: `--model` flag > `GROK_MODEL` environment variable > user default model > system default (grok-code-fast-1)
321
341
 
342
+ ### Image Support
343
+
344
+ zai-cli supports sending images to vision-capable AI models. Use the `@` prefix to reference image files in your messages:
345
+
346
+ ```sh
347
+ # Absolute path
348
+ zai-cli --prompt "What's in this image? @/Users/joseph/photos/image.jpg"
349
+
350
+ # Relative path
351
+ zai-cli --prompt "Analyze @./screenshot.png"
352
+
353
+ # Tilde expansion
354
+ zai-cli --prompt "Describe @~/Pictures/photo.jpg"
355
+
356
+ # Paths with spaces (quoted)
357
+ zai-cli --prompt 'Compare these images: @"~/My Pictures/photo1.jpg" @"~/My Pictures/photo2.jpg"'
358
+
359
+ # Paths with spaces (escaped)
360
+ zai-cli --prompt "What's here? @/Users/joseph/My\ Documents/image.png"
361
+ ```
362
+
363
+ **Supported Image Formats**: .jpg, .jpeg, .png, .gif, .webp, .bmp
364
+
365
+ **Vision-Capable Models**: Image support works with vision models like:
366
+ - `grok-4-1-fast-reasoning`
367
+ - `grok-vision-beta`
368
+ - Other vision-enabled models (via custom base URLs)
369
+
370
+ **Automatic Fallback**: If you send an image to a model that doesn't support vision, zai-cli will automatically detect the error and retry with text-only content.
371
+
372
+ **Interactive Mode**: The `@` syntax works in both interactive and headless (`--prompt`) modes.
373
+
322
374
  ### Command Line Options
323
375
 
324
376
  ```sh
@@ -1,9 +1,10 @@
1
1
  import { GrokMessage, GrokToolCall } from "../grok/client.js";
2
+ import type { ChatCompletionContentPart } from "openai/resources/chat/completions.js";
2
3
  import { ToolResult } from "../types/index.js";
3
4
  import { EventEmitter } from "events";
4
5
  export interface ChatEntry {
5
6
  type: "user" | "assistant" | "tool_result" | "tool_call" | "system";
6
- content?: string;
7
+ content?: string | ChatCompletionContentPart[];
7
8
  timestamp: Date;
8
9
  tool_calls?: GrokToolCall[];
9
10
  toolCall?: GrokToolCall;
@@ -15,6 +16,10 @@ export interface ChatEntry {
15
16
  };
16
17
  isStreaming?: boolean;
17
18
  preserveFormatting?: boolean;
19
+ metadata?: {
20
+ rephrased_note?: string;
21
+ [key: string]: any;
22
+ };
18
23
  }
19
24
  export interface StreamingChunk {
20
25
  type: "content" | "tool_calls" | "tool_result" | "done" | "token_count" | "user_message";
@@ -61,7 +66,8 @@ export declare class GrokAgent extends EventEmitter {
61
66
  private activeTaskAction;
62
67
  private activeTaskColor;
63
68
  private apiKeyEnvVar;
64
- private pendingContextEdit;
69
+ private pendingContextEditSession;
70
+ private rephraseState;
65
71
  constructor(apiKey: string, baseURL?: string, model?: string, maxToolRounds?: number, debugLogFile?: string, startupHookOutput?: string, temperature?: number, maxTokens?: number);
66
72
  private startupHookOutput?;
67
73
  private systemPrompt;
@@ -119,12 +125,20 @@ export declare class GrokAgent extends EventEmitter {
119
125
  getActiveTask(): string;
120
126
  getActiveTaskAction(): string;
121
127
  getActiveTaskColor(): string;
122
- setPendingContextEdit(tmpJsonPath: string, contextFilePath: string): void;
123
- getPendingContextEdit(): {
128
+ setPendingContextEditSession(tmpJsonPath: string, contextFilePath: string): void;
129
+ getPendingContextEditSession(): {
124
130
  tmpJsonPath: string;
125
131
  contextFilePath: string;
126
132
  } | null;
127
- clearPendingContextEdit(): void;
133
+ clearPendingContextEditSession(): void;
134
+ setRephraseState(originalAssistantMessageIndex: number, rephraseRequestIndex: number, newResponseIndex: number, messageType: "user" | "system"): void;
135
+ getRephraseState(): {
136
+ originalAssistantMessageIndex: number;
137
+ rephraseRequestIndex: number;
138
+ newResponseIndex: number;
139
+ messageType: "user" | "system";
140
+ } | null;
141
+ clearRephraseState(): void;
128
142
  setPersona(persona: string, color?: string): Promise<{
129
143
  success: boolean;
130
144
  error?: string;