zarz 0.3.1-alpha

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/Cargo.toml ADDED
@@ -0,0 +1,30 @@
1
+ [package]
2
+ name = "zarzcli"
3
+ version = "0.3.1-ALPHA"
4
+ edition = "2024"
5
+
6
+ [dependencies]
7
+ anyhow = "1.0.100"
8
+ clap = { version = "4.5.51", features = ["derive"] }
9
+ dialoguer = "0.12"
10
+ reqwest = { version = "0.12.24", features = ["json", "gzip", "brotli", "stream", "rustls-tls"] }
11
+ serde = { version = "1.0.228", features = ["derive"] }
12
+ serde_json = "1.0.145"
13
+ similar = "2.7.0"
14
+ tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread", "fs", "io-util", "process"] }
15
+ async-trait = "0.1.89"
16
+ rustyline = { version = "17.0.2", features = ["custom-bindings"] }
17
+ crossterm = "0.29.0"
18
+ futures = "0.3.31"
19
+ tokio-stream = "0.1.17"
20
+ eventsource-stream = "0.2.3"
21
+ ignore = "0.4.25"
22
+ walkdir = "2.5.0"
23
+ tree-sitter = "0.25.10"
24
+ syn = { version = "2.0.108", features = ["full", "parsing", "visit"] }
25
+ regex = "1.12.2"
26
+ bytes = "1.10.1"
27
+ toml = "0.9.8"
28
+ quote = "1.0.41"
29
+ dirs = "6.0.0"
30
+ chrono = { version = "0.4.39", features = ["serde"] }
package/QUICKSTART.md ADDED
@@ -0,0 +1,326 @@
1
+ # ZarzCLI Quick Start Guide
2
+
3
+ ZarzCLI is an AI-powered coding assistant that works directly from your command line, similar to Claude Code and Codex CLI.
4
+
5
+ ## Installation
6
+
7
+ 1. Make sure you have Rust installed:
8
+ ```bash
9
+ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
10
+ ```
11
+
12
+ 2. Build ZarzCLI:
13
+ ```bash
14
+ cd ZarzCLI
15
+ cargo build --release
16
+ ```
17
+
18
+ 3. Set up your API key:
19
+ ```bash
20
+ # For Claude (Anthropic)
21
+ export ANTHROPIC_API_KEY=sk-ant-your-key-here
22
+
23
+ # Or for OpenAI
24
+ export OPENAI_API_KEY=sk-your-key-here
25
+ ```
26
+
27
+ ## Basic Usage
28
+
29
+ ### 1. Interactive Chat (Default)
30
+
31
+ Just run `zarz` to start an interactive session:
32
+
33
+ ```bash
34
+ ./zarz.bat # Windows
35
+ ./zarz.sh # Linux/Mac
36
+ ```
37
+
38
+ You'll enter a chat session where you can ask questions and edit code:
39
+
40
+ ```
41
+ Zarz Interactive Session
42
+ Type /help for available commands, /quit to exit
43
+
44
+ > What does this codebase do?
45
+ Assistant: [AI analyzes your project...]
46
+
47
+ > /edit src/main.rs
48
+ Loaded src/main.rs for editing
49
+
50
+ > Add better error handling
51
+ Assistant: [AI suggests changes with file blocks]
52
+ File changes detected. Use /diff to review, /apply to apply
53
+
54
+ > /diff
55
+ [shows unified diff]
56
+
57
+ > /apply
58
+ Applied changes to src/main.rs
59
+
60
+ > /quit
61
+ Goodbye!
62
+ ```
63
+
64
+ ### 2. One-Shot Questions
65
+
66
+ Send a single question and get an answer:
67
+
68
+ ```bash
69
+ zarz --message "Explain what this function does" -f src/auth.rs
70
+ ```
71
+
72
+ Or shorter with alias:
73
+
74
+ ```bash
75
+ zarz --msg "Fix the bug in this file" -f src/main.rs
76
+ ```
77
+
78
+ ### 3. Switch Models On-the-Fly
79
+
80
+ Start with one model, switch to another mid-conversation:
81
+
82
+ ```bash
83
+ zarz
84
+
85
+ > /model claude-haiku-4-5
86
+ Switched to model: claude-haiku-4-5
87
+ Provider: anthropic
88
+
89
+ > Add docstrings
90
+ [Uses faster, cheaper Haiku model]
91
+
92
+ > /model gpt-5-codex
93
+ Switched to model: gpt-5-codex
94
+ Provider: openai
95
+
96
+ > Optimize this algorithm
97
+ [Uses GPT-5 Codex]
98
+ ```
99
+
100
+ ## Available Models
101
+
102
+ ### Anthropic Claude
103
+
104
+ - **claude-sonnet-4-5-20250929** (default) - Best for complex coding ($3/$15 per 1M tokens)
105
+ - **claude-haiku-4-5** - Fast and cheap ($1/$5 per 1M tokens)
106
+ - **claude-opus-4-1** - Most powerful for complex tasks
107
+
108
+ ### OpenAI
109
+
110
+ - **gpt-5-codex** - Optimized for coding ($1.25/$10 per 1M tokens)
111
+ - **gpt-4o** - Multimodal
112
+ - **gpt-4-turbo** - Fast
113
+
114
+ ## In-Chat Commands
115
+
116
+ - `/help` - Show all commands and current model
117
+ - `/model <name>` - Switch AI model
118
+ - `/edit <file>` - Load a file for editing
119
+ - `/diff` - Preview pending changes
120
+ - `/apply` - Apply pending changes
121
+ - `/undo` - Discard pending changes
122
+ - `/run <command>` - Execute shell command
123
+ - `/search <symbol>` - Find symbol in codebase
124
+ - `/context <query>` - Find relevant files
125
+ - `/files` - List loaded files
126
+ - `/clear` - Clear conversation history
127
+ - `/quit` - Exit
128
+
129
+ ## Common Workflows
130
+
131
+ ### Workflow 1: Code Review and Fix
132
+
133
+ ```bash
134
+ zarz
135
+
136
+ > /edit src/server.rs
137
+ > Review this code for security issues
138
+ [AI finds issues]
139
+
140
+ > Fix the SQL injection vulnerability
141
+ [AI provides fix with file blocks]
142
+
143
+ > /diff
144
+ [Review changes]
145
+
146
+ > /apply
147
+ [Changes applied]
148
+
149
+ > /run cargo test
150
+ [Verify tests pass]
151
+ ```
152
+
153
+ ### Workflow 2: Add Feature with Cost Optimization
154
+
155
+ ```bash
156
+ zarz
157
+
158
+ # Use Sonnet for planning
159
+ > Design an authentication system with JWT
160
+
161
+ # Switch to Haiku for implementation (cheaper)
162
+ > /model claude-haiku-4-5
163
+ > Implement the JWT authentication based on your design
164
+
165
+ # Back to Sonnet for complex parts
166
+ > /model claude-sonnet-4-5-20250929
167
+ > Add rate limiting and refresh token logic
168
+ ```
169
+
170
+ ### Workflow 3: Multi-File Refactoring
171
+
172
+ ```bash
173
+ zarz
174
+
175
+ > /edit src/main.rs
176
+ > /edit src/config.rs
177
+ > /edit src/handlers.rs
178
+
179
+ > Refactor these files to use async/await consistently
180
+
181
+ > /diff
182
+ [Shows changes across all files]
183
+
184
+ > /apply
185
+ [Applies all changes]
186
+
187
+ > /run cargo check
188
+ [Verify code compiles]
189
+ ```
190
+
191
+ ## Legacy Commands (Still Supported)
192
+
193
+ ### Ask Mode
194
+
195
+ ```bash
196
+ zarz ask --prompt "What does this do?" src/main.rs
197
+ ```
198
+
199
+ ### Rewrite Mode
200
+
201
+ ```bash
202
+ zarz rewrite --instructions "Add error handling" src/lib.rs
203
+ ```
204
+
205
+ ### Explicit Chat Mode
206
+
207
+ ```bash
208
+ zarz chat
209
+ ```
210
+
211
+ ## Configuration
212
+
213
+ ### Environment Variables
214
+
215
+ ```bash
216
+ # Model selection
217
+ export ZARZ_MODEL=claude-sonnet-4-5-20250929
218
+
219
+ # Provider selection
220
+ export ZARZ_PROVIDER=anthropic # or openai
221
+
222
+ # Anthropic settings
223
+ export ANTHROPIC_API_KEY=sk-ant-...
224
+ export ANTHROPIC_API_URL=https://api.anthropic.com/v1/messages
225
+ export ANTHROPIC_TIMEOUT_SECS=120
226
+
227
+ # OpenAI settings
228
+ export OPENAI_API_KEY=sk-...
229
+ export OPENAI_API_URL=https://api.openai.com/v1/chat/completions
230
+ export OPENAI_TIMEOUT_SECS=120
231
+
232
+ # Advanced settings
233
+ export ZARZ_MAX_OUTPUT_TOKENS=4096
234
+ export ZARZ_TEMPERATURE=0.3
235
+ ```
236
+
237
+ ### Per-Command Overrides
238
+
239
+ ```bash
240
+ # Use specific model
241
+ zarz --model claude-haiku-4-5
242
+
243
+ # Use OpenAI instead of default
244
+ zarz --provider openai --model gpt-5-codex
245
+
246
+ # Custom endpoint
247
+ zarz --endpoint https://custom-api.example.com
248
+ ```
249
+
250
+ ## Tips for Best Results
251
+
252
+ 1. **Be Specific**: "Add error handling to the login function" is better than "improve the code"
253
+
254
+ 2. **Use Context**: Load relevant files with `/edit` before asking questions
255
+
256
+ 3. **Iterate**: Don't try to do everything at once. Make small, focused changes
257
+
258
+ 4. **Review Before Applying**: Always `/diff` before `/apply`
259
+
260
+ 5. **Choose the Right Model**:
261
+ - Sonnet 4.5: Complex refactoring, architecture decisions
262
+ - Haiku 4.5: Quick fixes, adding docstrings, simple tasks
263
+ - GPT-5 Codex: Agentic workflows, algorithm optimization
264
+
265
+ 6. **Cost Optimization**: Start with Sonnet for planning, switch to Haiku for implementation
266
+
267
+ ## Troubleshooting
268
+
269
+ ### API Key Not Found
270
+
271
+ ```bash
272
+ Error: Environment variable ANTHROPIC_API_KEY is required
273
+
274
+ # Fix:
275
+ export ANTHROPIC_API_KEY=sk-ant-your-key
276
+ ```
277
+
278
+ ### Model Not Found
279
+
280
+ ```bash
281
+ Error: Unknown model provider for 'typo-model'
282
+
283
+ # Fix: Use /model without arguments to see available models
284
+ > /model
285
+ ```
286
+
287
+ ### Build Errors
288
+
289
+ ```bash
290
+ # Clean and rebuild
291
+ cargo clean
292
+ cargo build --release
293
+ ```
294
+
295
+ ## Next Steps
296
+
297
+ - Read [MODELS.md](MODELS.md) for detailed model information
298
+ - Check [README.md](README.md) for full documentation
299
+ - Report issues: https://github.com/fapzarz/zarzcli/issues
300
+
301
+ ## Quick Reference Card
302
+
303
+ ```
304
+ ┌─────────────────────────────────────────────────┐
305
+ │ ZarzCLI Quick Reference │
306
+ ├─────────────────────────────────────────────────┤
307
+ │ Start Chat: zarz │
308
+ │ One-Shot: zarz --message "prompt" │
309
+ │ With Files: zarz -f file.rs │
310
+ │ │
311
+ │ In Chat: │
312
+ │ /help Show all commands │
313
+ │ /model <name> Switch AI model │
314
+ │ /edit <file> Load file │
315
+ │ /diff Preview changes │
316
+ │ /apply Apply changes │
317
+ │ /undo Discard changes │
318
+ │ /run <cmd> Execute command │
319
+ │ /quit Exit │
320
+ │ │
321
+ │ Models: │
322
+ │ claude-sonnet-4-5-20250929 (default) │
323
+ │ claude-haiku-4-5 (fast/cheap) │
324
+ │ gpt-5-codex (OpenAI) │
325
+ └─────────────────────────────────────────────────┘
326
+ ```
package/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # ZarzCLI
2
+
3
+ [![npm version](https://img.shields.io/npm/v/zarz.svg)](https://www.npmjs.com/package/zarz)
4
+ [![npm downloads](https://img.shields.io/npm/dd/zarz.svg)](https://www.npmjs.com/package/zarz)
5
+ [![GitHub release](https://img.shields.io/github/v/release/zarzet/ZarzCLI.svg)](https://github.com/zarzet/ZarzCLI/releases)
6
+ [![License](https://img.shields.io/badge/license-Proprietary-red.svg)](LICENSE)
7
+
8
+ Fast AI coding assistant for terminal built with Rust.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install -g zarz
14
+ ```
15
+
16
+ ## First Run Setup
17
+
18
+ On first run, you'll be prompted to enter your API keys interactively:
19
+
20
+ ```bash
21
+ zarz
22
+
23
+ # Or set manually via environment variable
24
+ export ANTHROPIC_API_KEY=sk-ant-...
25
+ zarz
26
+ ```
27
+
28
+ Your API keys are securely stored in `~/.zarz/config.toml`
29
+
30
+ ## Usage
31
+
32
+ ```bash
33
+ # Start interactive chat (default)
34
+ zarz
35
+
36
+ # Quick one-shot question
37
+ zarz --message "fix this bug"
38
+
39
+ # Manage configuration
40
+ zarz config --show # Show current config
41
+ zarz config --reset # Reconfigure API keys
42
+ ```
43
+
44
+ ## Features
45
+
46
+ - Interactive chat with AI (Claude, GPT & GLM models)
47
+ - Real-time streaming responses
48
+ - Automatic API key management
49
+ - File operations & code editing
50
+ - Symbol search & context detection
51
+ - MCP (Model Context Protocol) support
52
+ - Cross-platform (Windows, Linux, macOS)
53
+
54
+ ## Supported AI Providers
55
+
56
+ - **Anthropic Claude** - Best for coding and agents
57
+ - **OpenAI GPT** - Multimodal capabilities
58
+ - **GLM (Z.AI)** - Cost-effective coding with 200K context ($3/month)
59
+
60
+ See [GLM-PROVIDER.md](GLM-PROVIDER.md) for detailed GLM setup and usage.
61
+
62
+ ## Requirements
63
+
64
+ - Node.js 14.0.0 or higher
65
+ - Rust toolchain (auto-installed if missing)
66
+ - API key: Anthropic Claude, OpenAI, or GLM (Z.AI)
67
+
68
+ ## License
69
+
70
+ Proprietary - All rights reserved
71
+
72
+ © 2025 zarzet. This software is licensed for personal use only.
package/bin/zarz.js ADDED
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { spawn } = require('child_process');
4
+ const path = require('path');
5
+ const fs = require('fs');
6
+
7
+ // Determine the binary path based on platform
8
+ function getBinaryPath() {
9
+ const rootDir = path.join(__dirname, '..');
10
+ const platform = process.platform;
11
+
12
+ let binaryName = 'zarzcli';
13
+ if (platform === 'win32') {
14
+ binaryName += '.exe';
15
+ }
16
+
17
+ const binaryPath = path.join(rootDir, 'target', 'release', binaryName);
18
+
19
+ return binaryPath;
20
+ }
21
+
22
+ // Check if binary exists, if not, build it
23
+ function ensureBinaryExists(binaryPath) {
24
+ if (!fs.existsSync(binaryPath)) {
25
+ console.error('Binary not found. Building...');
26
+ console.error('This may take a few minutes on first run.');
27
+
28
+ const { execSync } = require('child_process');
29
+ const rootDir = path.join(__dirname, '..');
30
+
31
+ try {
32
+ execSync('cargo build --release', {
33
+ cwd: rootDir,
34
+ stdio: 'inherit'
35
+ });
36
+ } catch (error) {
37
+ console.error('Failed to build binary. Make sure Rust and Cargo are installed.');
38
+ console.error('Install Rust from: https://rustup.rs/');
39
+ process.exit(1);
40
+ }
41
+ }
42
+ }
43
+
44
+ // Main execution
45
+ function main() {
46
+ const binaryPath = getBinaryPath();
47
+
48
+ // Ensure binary exists
49
+ ensureBinaryExists(binaryPath);
50
+
51
+ // Check if binary exists after build attempt
52
+ if (!fs.existsSync(binaryPath)) {
53
+ console.error(`Binary not found at: ${binaryPath}`);
54
+ console.error('Please run: cargo build --release');
55
+ process.exit(1);
56
+ }
57
+
58
+ // Forward all arguments to the binary
59
+ const args = process.argv.slice(2);
60
+
61
+ // Spawn the binary
62
+ const child = spawn(binaryPath, args, {
63
+ stdio: 'inherit',
64
+ env: process.env
65
+ });
66
+
67
+ // Handle exit
68
+ child.on('exit', (code) => {
69
+ process.exit(code || 0);
70
+ });
71
+
72
+ // Handle errors
73
+ child.on('error', (error) => {
74
+ console.error('Failed to start zarz:', error.message);
75
+ process.exit(1);
76
+ });
77
+ }
78
+
79
+ // Run main
80
+ main();
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "zarz",
3
+ "version": "0.3.1-alpha",
4
+ "description": "Fast AI coding assistant for terminal built with Rust",
5
+ "main": "bin/zarz.js",
6
+ "bin": {
7
+ "zarz": "./bin/zarz.js"
8
+ },
9
+ "scripts": {
10
+ "postinstall": "node scripts/postinstall.js",
11
+ "build": "cargo build --release",
12
+ "test": "cargo test"
13
+ },
14
+ "keywords": [
15
+ "ai",
16
+ "coding-assistant",
17
+ "cli",
18
+ "claude",
19
+ "codex",
20
+ "gpt",
21
+ "anthropic",
22
+ "openai",
23
+ "rust"
24
+ ],
25
+ "author": "zarzet",
26
+ "license": "UNLICENSED",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/zarzet/zarzcli.git"
30
+ },
31
+ "private": false,
32
+ "engines": {
33
+ "node": ">=14.0.0"
34
+ },
35
+ "os": [
36
+ "darwin",
37
+ "linux",
38
+ "win32"
39
+ ],
40
+ "files": [
41
+ "bin/",
42
+ "scripts/",
43
+ "src/",
44
+ "Cargo.toml",
45
+ "Cargo.lock",
46
+ "README.md",
47
+ "QUICKSTART.md",
48
+ "MODELS.md"
49
+ ],
50
+ "dependencies": {},
51
+ "devDependencies": {},
52
+ "preferGlobal": true
53
+ }
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { execSync } = require('child_process');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+
7
+ function checkRustInstalled() {
8
+ try {
9
+ execSync('cargo --version', { stdio: 'ignore' });
10
+ return true;
11
+ } catch (error) {
12
+ return false;
13
+ }
14
+ }
15
+
16
+ function getBinaryPath() {
17
+ const rootDir = path.join(__dirname, '..');
18
+ const platform = process.platform;
19
+
20
+ let binaryName = 'zarzcli';
21
+ if (platform === 'win32') {
22
+ binaryName += '.exe';
23
+ }
24
+
25
+ return path.join(rootDir, 'target', 'release', binaryName);
26
+ }
27
+
28
+ function main() {
29
+ console.log('Installing ZarzCLI...');
30
+
31
+ // Check if Rust is installed
32
+ if (!checkRustInstalled()) {
33
+ console.log('');
34
+ console.log('WARNING: Rust/Cargo not found!');
35
+ console.log('ZarzCLI requires Rust to build the native binary.');
36
+ console.log('');
37
+ console.log('Please install Rust from: https://rustup.rs/');
38
+ console.log('');
39
+ console.log('After installing Rust, run: npm install');
40
+ console.log('');
41
+ process.exit(0); // Don't fail install, just warn
42
+ }
43
+
44
+ const binaryPath = getBinaryPath();
45
+
46
+ // Check if binary already exists
47
+ if (fs.existsSync(binaryPath)) {
48
+ console.log('Binary already built. Skipping build.');
49
+ console.log('');
50
+ console.log('ZarzCLI installed successfully!');
51
+ console.log('Run "zarz" to start.');
52
+ return;
53
+ }
54
+
55
+ // Build the binary
56
+ console.log('Building native binary...');
57
+ console.log('This may take a few minutes on first install.');
58
+ console.log('');
59
+
60
+ try {
61
+ const rootDir = path.join(__dirname, '..');
62
+
63
+ execSync('cargo build --release', {
64
+ cwd: rootDir,
65
+ stdio: 'inherit'
66
+ });
67
+
68
+ console.log('');
69
+ console.log('ZarzCLI installed successfully!');
70
+ console.log('');
71
+ console.log('Quick Start:');
72
+ console.log(' 1. Set API key: export ANTHROPIC_API_KEY=sk-ant-...');
73
+ console.log(' 2. Run: zarz');
74
+ console.log('');
75
+ console.log('See QUICKSTART.md for more information.');
76
+ console.log('');
77
+
78
+ } catch (error) {
79
+ console.error('');
80
+ console.error('Build failed!');
81
+ console.error('');
82
+ console.error('Please make sure:');
83
+ console.error(' 1. Rust and Cargo are installed: https://rustup.rs/');
84
+ console.error(' 2. You have an internet connection (to download dependencies)');
85
+ console.error('');
86
+ console.error('Error:', error.message);
87
+ process.exit(1);
88
+ }
89
+ }
90
+
91
+ main();