zarz 0.3.4-alpha → 0.3.5-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/LICENSE +21 -0
- package/README.md +193 -22
- package/bin/zarz.js +10 -31
- package/package.json +6 -10
- package/scripts/postinstall.js +162 -40
- package/Cargo.lock +0 -2815
- package/Cargo.toml +0 -30
- package/QUICKSTART.md +0 -326
- package/src/cli.rs +0 -201
- package/src/config.rs +0 -249
- package/src/conversation_store.rs +0 -183
- package/src/executor.rs +0 -166
- package/src/fs_ops.rs +0 -117
- package/src/intelligence/context.rs +0 -143
- package/src/intelligence/mod.rs +0 -60
- package/src/intelligence/rust_parser.rs +0 -141
- package/src/intelligence/symbol_search.rs +0 -97
- package/src/main.rs +0 -873
- package/src/mcp/client.rs +0 -316
- package/src/mcp/config.rs +0 -133
- package/src/mcp/manager.rs +0 -186
- package/src/mcp/mod.rs +0 -12
- package/src/mcp/types.rs +0 -170
- package/src/providers/anthropic.rs +0 -242
- package/src/providers/glm.rs +0 -259
- package/src/providers/mod.rs +0 -103
- package/src/providers/openai.rs +0 -247
- package/src/repl.rs +0 -2153
- package/src/session.rs +0 -173
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 zarzet
|
|
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 notice 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
CHANGED
|
@@ -3,31 +3,88 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/zarz)
|
|
4
4
|
[](https://www.npmjs.com/package/zarz)
|
|
5
5
|
[](https://github.com/zarzet/ZarzCLI/releases)
|
|
6
|
-
[](https://opensource.org/licenses/MIT)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
**ZarzCLI** is a blazingly fast AI coding assistant for your terminal, built with Rust for maximum performance. It brings the power of Claude, GPT, and GLM models directly to your command line with intelligent context awareness and autonomous tool execution.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
### Core Capabilities
|
|
13
|
+
- **Interactive Chat** - Real-time streaming responses with multiple AI models
|
|
14
|
+
- **Multi-Provider Support** - Claude (Anthropic), GPT (OpenAI), and GLM (Z.AI)
|
|
15
|
+
- **Bash Tool Calling** - AI can autonomously execute bash commands to understand your codebase
|
|
16
|
+
- **File Operations** - Direct file editing, creation, and management
|
|
17
|
+
- **Smart Context** - Automatic symbol search and relevant file detection
|
|
18
|
+
- **MCP Support** - Model Context Protocol integration for extended capabilities
|
|
19
|
+
- **Auto Update** - Automatic update checks and notifications for new versions
|
|
20
|
+
- **Cross-Platform** - Works seamlessly on Windows, Linux, and macOS
|
|
21
|
+
|
|
22
|
+
### Intelligent Context Understanding
|
|
23
|
+
|
|
24
|
+
ZarzCLI v0.3.4+ includes autonomous bash tool execution, allowing AI models to:
|
|
25
|
+
- **Search files**: `find . -name "*.rs"` or `rg "pattern"`
|
|
26
|
+
- **Read contents**: `cat src/main.rs` or `head -n 20 file.py`
|
|
27
|
+
- **Grep code**: `grep -r "function_name" src/`
|
|
28
|
+
- **Navigate structure**: `ls -la src/` or `tree -L 2`
|
|
29
|
+
- **Check git**: `git log --oneline -10` or `git diff`
|
|
30
|
+
|
|
31
|
+
The AI automatically decides when to execute commands for better context - no manual `/run` needed!
|
|
32
|
+
|
|
33
|
+
### User Experience
|
|
34
|
+
- **Status Line** - Shows current mode and notifications
|
|
35
|
+
- **Double Ctrl+C** - Confirmation before exit (prevents accidental exits)
|
|
36
|
+
- **Colored Diff Display** - Beautiful file change visualization with context
|
|
37
|
+
- **Persistent Sessions** - Resume previous conversations anytime
|
|
9
38
|
|
|
10
39
|
## Installation
|
|
11
40
|
|
|
41
|
+
### Via NPM (Recommended)
|
|
12
42
|
```bash
|
|
13
43
|
npm install -g zarz
|
|
14
44
|
```
|
|
15
45
|
|
|
16
|
-
|
|
46
|
+
### From Source
|
|
47
|
+
```bash
|
|
48
|
+
git clone https://github.com/zarzet/ZarzCLI.git
|
|
49
|
+
cd ZarzCLI
|
|
50
|
+
cargo build --release
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Updating
|
|
54
|
+
|
|
55
|
+
ZarzCLI will automatically check for updates and notify you when a new version is available. To update manually:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npm update -g zarz
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Quick Start
|
|
62
|
+
|
|
63
|
+
### First Run Setup
|
|
17
64
|
|
|
18
65
|
On first run, you'll be prompted to enter your API keys interactively:
|
|
19
66
|
|
|
20
67
|
```bash
|
|
21
68
|
zarz
|
|
69
|
+
```
|
|
22
70
|
|
|
23
|
-
|
|
71
|
+
Or set manually via environment variables:
|
|
72
|
+
```bash
|
|
73
|
+
# For Anthropic Claude
|
|
24
74
|
export ANTHROPIC_API_KEY=sk-ant-...
|
|
75
|
+
|
|
76
|
+
# For OpenAI GPT
|
|
77
|
+
export OPENAI_API_KEY=sk-...
|
|
78
|
+
|
|
79
|
+
# For GLM (Z.AI)
|
|
80
|
+
export GLM_API_KEY=...
|
|
81
|
+
|
|
25
82
|
zarz
|
|
26
83
|
```
|
|
27
84
|
|
|
28
85
|
Your API keys are securely stored in `~/.zarz/config.toml`
|
|
29
86
|
|
|
30
|
-
|
|
87
|
+
### Basic Usage
|
|
31
88
|
|
|
32
89
|
```bash
|
|
33
90
|
# Start interactive chat (default)
|
|
@@ -36,37 +93,151 @@ zarz
|
|
|
36
93
|
# Quick one-shot question
|
|
37
94
|
zarz --message "fix this bug"
|
|
38
95
|
|
|
96
|
+
# Use specific model
|
|
97
|
+
zarz --model claude-sonnet-4-5-20250929
|
|
98
|
+
|
|
39
99
|
# Manage configuration
|
|
40
100
|
zarz config --show # Show current config
|
|
41
101
|
zarz config --reset # Reconfigure API keys
|
|
42
102
|
```
|
|
43
103
|
|
|
44
|
-
##
|
|
104
|
+
## Available Commands
|
|
105
|
+
|
|
106
|
+
Once inside the interactive chat:
|
|
107
|
+
|
|
108
|
+
| Command | Description |
|
|
109
|
+
|---------|-------------|
|
|
110
|
+
| `/help` | Show all available commands |
|
|
111
|
+
| `/apply` | Apply pending file changes |
|
|
112
|
+
| `/diff` | Show pending changes with colored diff |
|
|
113
|
+
| `/undo` | Clear pending changes |
|
|
114
|
+
| `/edit <file>` | Load a file for editing |
|
|
115
|
+
| `/search <symbol>` | Search for a symbol in codebase |
|
|
116
|
+
| `/context <query>` | Find relevant files for a query |
|
|
117
|
+
| `/files` | List currently loaded files |
|
|
118
|
+
| `/model <name>` | Switch to a different AI model |
|
|
119
|
+
| `/mcp` | Show MCP servers and available tools |
|
|
120
|
+
| `/resume` | Resume a previous chat session |
|
|
121
|
+
| `/clear` | Clear conversation history |
|
|
122
|
+
| `/exit` | Exit the session |
|
|
123
|
+
|
|
124
|
+
## Supported AI Models
|
|
125
|
+
|
|
126
|
+
### Anthropic Claude
|
|
127
|
+
Best for coding tasks and autonomous agents:
|
|
128
|
+
- `claude-sonnet-4-5-20250929` (Latest, most capable)
|
|
129
|
+
- `claude-haiku-4-5` (Fast, cost-effective)
|
|
130
|
+
- `claude-opus-4-5` (Most powerful)
|
|
131
|
+
|
|
132
|
+
### OpenAI GPT
|
|
133
|
+
Multimodal capabilities with vision:
|
|
134
|
+
- `gpt-5-codex` (Best for coding)
|
|
135
|
+
- `gpt-4o` (Multimodal)
|
|
136
|
+
- `gpt-4-turbo`
|
|
137
|
+
|
|
138
|
+
### GLM (Z.AI)
|
|
139
|
+
Cost-effective coding with 200K context window:
|
|
140
|
+
- `glm-coder-4-lite` ($3/month subscription)
|
|
141
|
+
- 200,000 token context window
|
|
142
|
+
- Specialized for coding tasks
|
|
143
|
+
|
|
144
|
+
See [MODELS.md](MODELS.md) for full model list and [GLM-PROVIDER.md](GLM-PROVIDER.md) for GLM setup.
|
|
145
|
+
|
|
146
|
+
## Advanced Features
|
|
147
|
+
|
|
148
|
+
### MCP (Model Context Protocol)
|
|
149
|
+
|
|
150
|
+
ZarzCLI supports MCP servers for extended capabilities. Configure in `~/.zarz/config.toml`:
|
|
151
|
+
|
|
152
|
+
```toml
|
|
153
|
+
[[mcp_servers]]
|
|
154
|
+
name = "filesystem"
|
|
155
|
+
command = "npx"
|
|
156
|
+
args = ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/project"]
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Bash Tool Integration
|
|
160
|
+
|
|
161
|
+
AI models can automatically execute bash commands when they need context:
|
|
45
162
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
163
|
+
```bash
|
|
164
|
+
> Tell me about the authentication implementation
|
|
165
|
+
|
|
166
|
+
# AI automatically executes:
|
|
167
|
+
$ find . -name "*auth*" -type f
|
|
168
|
+
$ grep -r "authenticate" src/
|
|
169
|
+
$ cat src/auth/login.rs
|
|
53
170
|
|
|
54
|
-
|
|
171
|
+
# Then provides informed response based on actual codebase
|
|
172
|
+
```
|
|
55
173
|
|
|
56
|
-
|
|
57
|
-
- **OpenAI GPT** - Multimodal capabilities
|
|
58
|
-
- **GLM (Z.AI)** - Cost-effective coding with 200K context ($3/month)
|
|
174
|
+
### Automatic Updates
|
|
59
175
|
|
|
60
|
-
|
|
176
|
+
ZarzCLI automatically checks for updates on startup and notifies you when a new version is available. Updates are downloaded from npm registry and can be installed with a single command.
|
|
61
177
|
|
|
62
178
|
## Requirements
|
|
63
179
|
|
|
180
|
+
- **Node.js** 14.0.0 or higher
|
|
181
|
+
- **API Key** from one of:
|
|
182
|
+
- Anthropic Claude ([get key](https://console.anthropic.com/))
|
|
183
|
+
- OpenAI ([get key](https://platform.openai.com/api-keys))
|
|
184
|
+
- GLM Z.AI ([get key](https://z.ai/))
|
|
185
|
+
|
|
186
|
+
> **Note**: Rust is **NOT required** for installation. Pre-built binaries are automatically downloaded for your platform (Windows, macOS, Linux).
|
|
187
|
+
|
|
188
|
+
## Contributing
|
|
189
|
+
|
|
190
|
+
Contributions are welcome! ZarzCLI is now open source under MIT license.
|
|
191
|
+
|
|
192
|
+
### Development Setup
|
|
193
|
+
|
|
194
|
+
For contributors who want to modify the source code:
|
|
195
|
+
|
|
196
|
+
**Requirements:**
|
|
64
197
|
- Node.js 14.0.0 or higher
|
|
65
|
-
- Rust toolchain (
|
|
66
|
-
|
|
198
|
+
- Rust toolchain ([install from rustup.rs](https://rustup.rs/))
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
# Clone the repository
|
|
202
|
+
git clone https://github.com/zarzet/ZarzCLI.git
|
|
203
|
+
cd ZarzCLI
|
|
204
|
+
|
|
205
|
+
# Build the project
|
|
206
|
+
cargo build --release
|
|
207
|
+
|
|
208
|
+
# Run tests
|
|
209
|
+
cargo test
|
|
210
|
+
|
|
211
|
+
# Install locally for testing
|
|
212
|
+
npm install -g .
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
**Note**: Regular users don't need Rust installed. Pre-built binaries are automatically downloaded during `npm install`.
|
|
216
|
+
|
|
217
|
+
### Contribution Guidelines
|
|
218
|
+
|
|
219
|
+
1. Fork the repository
|
|
220
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
221
|
+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
222
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
223
|
+
5. Open a Pull Request
|
|
224
|
+
|
|
225
|
+
Please ensure:
|
|
226
|
+
- Code compiles without warnings
|
|
227
|
+
- Tests pass
|
|
228
|
+
- Follow existing code style
|
|
229
|
+
- Update documentation as needed
|
|
67
230
|
|
|
68
231
|
## License
|
|
69
232
|
|
|
70
|
-
|
|
233
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
|
234
|
+
|
|
235
|
+
## Support
|
|
236
|
+
|
|
237
|
+
- **Issues**: [GitHub Issues](https://github.com/zarzet/ZarzCLI/issues)
|
|
238
|
+
- **Discussions**: [GitHub Discussions](https://github.com/zarzet/ZarzCLI/discussions)
|
|
239
|
+
- **Author**: [@zarzet](https://github.com/zarzet)
|
|
240
|
+
|
|
241
|
+
---
|
|
71
242
|
|
|
72
|
-
|
|
243
|
+
Made with love by zarzet
|
package/bin/zarz.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const { spawn } = require('child_process');
|
|
4
4
|
const path = require('path');
|
|
@@ -6,7 +6,6 @@ const fs = require('fs');
|
|
|
6
6
|
|
|
7
7
|
// Determine the binary path based on platform
|
|
8
8
|
function getBinaryPath() {
|
|
9
|
-
const rootDir = path.join(__dirname, '..');
|
|
10
9
|
const platform = process.platform;
|
|
11
10
|
|
|
12
11
|
let binaryName = 'zarzcli';
|
|
@@ -14,44 +13,24 @@ function getBinaryPath() {
|
|
|
14
13
|
binaryName += '.exe';
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
// Binary is now in bin/ directory after installation
|
|
17
|
+
const binaryPath = path.join(__dirname, binaryName);
|
|
18
18
|
|
|
19
19
|
return binaryPath;
|
|
20
20
|
}
|
|
21
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
22
|
// Main execution
|
|
45
23
|
function main() {
|
|
46
24
|
const binaryPath = getBinaryPath();
|
|
47
25
|
|
|
48
|
-
//
|
|
49
|
-
ensureBinaryExists(binaryPath);
|
|
50
|
-
|
|
51
|
-
// Check if binary exists after build attempt
|
|
26
|
+
// Check if binary exists
|
|
52
27
|
if (!fs.existsSync(binaryPath)) {
|
|
53
|
-
console.error(
|
|
54
|
-
console.error('
|
|
28
|
+
console.error('ZarzCLI binary not found!');
|
|
29
|
+
console.error('');
|
|
30
|
+
console.error('This usually means the installation did not complete successfully.');
|
|
31
|
+
console.error('Please try reinstalling:');
|
|
32
|
+
console.error(' npm install -g zarz');
|
|
33
|
+
console.error('');
|
|
55
34
|
process.exit(1);
|
|
56
35
|
}
|
|
57
36
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zarz",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5-alpha",
|
|
4
4
|
"description": "Fast AI coding assistant for terminal built with Rust",
|
|
5
5
|
"main": "bin/zarz.js",
|
|
6
6
|
"bin": {
|
|
7
|
-
"zarz": "
|
|
7
|
+
"zarz": "bin/zarz.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"postinstall": "node scripts/postinstall.js",
|
|
@@ -18,15 +18,16 @@
|
|
|
18
18
|
"claude",
|
|
19
19
|
"codex",
|
|
20
20
|
"gpt",
|
|
21
|
+
"glm",
|
|
21
22
|
"anthropic",
|
|
22
23
|
"openai",
|
|
23
24
|
"rust"
|
|
24
25
|
],
|
|
25
26
|
"author": "zarzet",
|
|
26
|
-
"license": "
|
|
27
|
+
"license": "MIT",
|
|
27
28
|
"repository": {
|
|
28
29
|
"type": "git",
|
|
29
|
-
"url": "https://github.com/zarzet/zarzcli.git"
|
|
30
|
+
"url": "git+https://github.com/zarzet/zarzcli.git"
|
|
30
31
|
},
|
|
31
32
|
"private": false,
|
|
32
33
|
"engines": {
|
|
@@ -40,12 +41,7 @@
|
|
|
40
41
|
"files": [
|
|
41
42
|
"bin/",
|
|
42
43
|
"scripts/",
|
|
43
|
-
"
|
|
44
|
-
"Cargo.toml",
|
|
45
|
-
"Cargo.lock",
|
|
46
|
-
"README.md",
|
|
47
|
-
"QUICKSTART.md",
|
|
48
|
-
"MODELS.md"
|
|
44
|
+
"README.md"
|
|
49
45
|
],
|
|
50
46
|
"dependencies": {},
|
|
51
47
|
"devDependencies": {},
|
package/scripts/postinstall.js
CHANGED
|
@@ -1,16 +1,50 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const https = require('https');
|
|
4
4
|
const fs = require('fs');
|
|
5
5
|
const path = require('path');
|
|
6
|
+
const { execSync } = require('child_process');
|
|
7
|
+
|
|
8
|
+
const REPO = 'zarzet/zarzcli';
|
|
9
|
+
const PACKAGE_VERSION = require('../package.json').version;
|
|
10
|
+
|
|
11
|
+
function getPlatformInfo() {
|
|
12
|
+
const platform = process.platform;
|
|
13
|
+
const arch = process.arch;
|
|
14
|
+
|
|
15
|
+
let binaryName = 'zarzcli';
|
|
16
|
+
let platformName;
|
|
17
|
+
let archName;
|
|
18
|
+
|
|
19
|
+
// Determine platform
|
|
20
|
+
if (platform === 'win32') {
|
|
21
|
+
platformName = 'windows';
|
|
22
|
+
binaryName += '.exe';
|
|
23
|
+
} else if (platform === 'darwin') {
|
|
24
|
+
platformName = 'macos';
|
|
25
|
+
} else if (platform === 'linux') {
|
|
26
|
+
platformName = 'linux';
|
|
27
|
+
} else {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
6
30
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
31
|
+
// Determine architecture
|
|
32
|
+
if (arch === 'x64') {
|
|
33
|
+
archName = 'x86_64';
|
|
34
|
+
} else if (arch === 'arm64') {
|
|
35
|
+
archName = 'aarch64';
|
|
36
|
+
} else {
|
|
37
|
+
return null;
|
|
13
38
|
}
|
|
39
|
+
|
|
40
|
+
const assetName = `zarzcli-${platformName}-${archName}${platform === 'win32' ? '.exe' : ''}`;
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
binaryName,
|
|
44
|
+
assetName,
|
|
45
|
+
platform,
|
|
46
|
+
arch
|
|
47
|
+
};
|
|
14
48
|
}
|
|
15
49
|
|
|
16
50
|
function getBinaryPath() {
|
|
@@ -22,49 +56,131 @@ function getBinaryPath() {
|
|
|
22
56
|
binaryName += '.exe';
|
|
23
57
|
}
|
|
24
58
|
|
|
25
|
-
return path.join(rootDir, '
|
|
59
|
+
return path.join(rootDir, 'bin', binaryName);
|
|
26
60
|
}
|
|
27
61
|
|
|
28
|
-
function
|
|
62
|
+
function downloadBinary(url, dest) {
|
|
63
|
+
return new Promise((resolve, reject) => {
|
|
64
|
+
const file = fs.createWriteStream(dest);
|
|
65
|
+
|
|
66
|
+
https.get(url, {
|
|
67
|
+
headers: {
|
|
68
|
+
'User-Agent': 'zarz-installer'
|
|
69
|
+
}
|
|
70
|
+
}, (response) => {
|
|
71
|
+
// Handle redirects
|
|
72
|
+
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
73
|
+
file.close();
|
|
74
|
+
fs.unlinkSync(dest);
|
|
75
|
+
return downloadBinary(response.headers.location, dest)
|
|
76
|
+
.then(resolve)
|
|
77
|
+
.catch(reject);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (response.statusCode !== 200) {
|
|
81
|
+
file.close();
|
|
82
|
+
fs.unlinkSync(dest);
|
|
83
|
+
return reject(new Error(`Failed to download: HTTP ${response.statusCode}`));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
response.pipe(file);
|
|
87
|
+
|
|
88
|
+
file.on('finish', () => {
|
|
89
|
+
file.close();
|
|
90
|
+
resolve();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
file.on('error', (err) => {
|
|
94
|
+
file.close();
|
|
95
|
+
fs.unlinkSync(dest);
|
|
96
|
+
reject(err);
|
|
97
|
+
});
|
|
98
|
+
}).on('error', (err) => {
|
|
99
|
+
file.close();
|
|
100
|
+
if (fs.existsSync(dest)) {
|
|
101
|
+
fs.unlinkSync(dest);
|
|
102
|
+
}
|
|
103
|
+
reject(err);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function makeExecutable(filePath) {
|
|
109
|
+
if (process.platform !== 'win32') {
|
|
110
|
+
try {
|
|
111
|
+
fs.chmodSync(filePath, 0o755);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
console.warn('Warning: Could not make binary executable:', error.message);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
async function main() {
|
|
29
120
|
console.log('Installing ZarzCLI...');
|
|
121
|
+
console.log('');
|
|
30
122
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
console.
|
|
35
|
-
console.
|
|
36
|
-
console.
|
|
37
|
-
console.
|
|
38
|
-
console.
|
|
39
|
-
console.
|
|
40
|
-
console.
|
|
41
|
-
|
|
123
|
+
const platformInfo = getPlatformInfo();
|
|
124
|
+
|
|
125
|
+
if (!platformInfo) {
|
|
126
|
+
console.error(`Platform ${process.platform}-${process.arch} is not supported.`);
|
|
127
|
+
console.error('');
|
|
128
|
+
console.error('Supported platforms:');
|
|
129
|
+
console.error(' - Linux (x86_64, ARM64)');
|
|
130
|
+
console.error(' - macOS (x86_64, ARM64)');
|
|
131
|
+
console.error(' - Windows (x86_64)');
|
|
132
|
+
console.error('');
|
|
133
|
+
console.error('Please open an issue at: https://github.com/zarzet/zarzcli/issues');
|
|
134
|
+
process.exit(1);
|
|
42
135
|
}
|
|
43
136
|
|
|
44
137
|
const binaryPath = getBinaryPath();
|
|
45
138
|
|
|
46
139
|
// Check if binary already exists
|
|
47
140
|
if (fs.existsSync(binaryPath)) {
|
|
48
|
-
console.log('Binary already
|
|
141
|
+
console.log('Binary already installed.');
|
|
49
142
|
console.log('');
|
|
50
|
-
console.log('ZarzCLI
|
|
143
|
+
console.log('ZarzCLI ready to use!');
|
|
51
144
|
console.log('Run "zarz" to start.');
|
|
145
|
+
console.log('');
|
|
52
146
|
return;
|
|
53
147
|
}
|
|
54
148
|
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
149
|
+
// Ensure bin directory exists
|
|
150
|
+
const binDir = path.dirname(binaryPath);
|
|
151
|
+
if (!fs.existsSync(binDir)) {
|
|
152
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
153
|
+
}
|
|
59
154
|
|
|
60
|
-
|
|
61
|
-
|
|
155
|
+
// Try to download pre-built binary
|
|
156
|
+
console.log('Downloading pre-built binary...');
|
|
62
157
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
158
|
+
// Try latest release first, then fall back to version-specific
|
|
159
|
+
const version = PACKAGE_VERSION.replace('-alpha', '').replace('-beta', '');
|
|
160
|
+
const urls = [
|
|
161
|
+
`https://github.com/${REPO}/releases/latest/download/${platformInfo.assetName}`,
|
|
162
|
+
`https://github.com/${REPO}/releases/download/v${version}/${platformInfo.assetName}`
|
|
163
|
+
];
|
|
164
|
+
|
|
165
|
+
let downloaded = false;
|
|
166
|
+
for (const url of urls) {
|
|
167
|
+
try {
|
|
168
|
+
console.log(`Trying: ${url}`);
|
|
169
|
+
await downloadBinary(url, binaryPath);
|
|
170
|
+
makeExecutable(binaryPath);
|
|
171
|
+
downloaded = true;
|
|
172
|
+
console.log('');
|
|
173
|
+
console.log('✓ Download successful!');
|
|
174
|
+
break;
|
|
175
|
+
} catch (error) {
|
|
176
|
+
console.log(` Failed: ${error.message}`);
|
|
177
|
+
if (fs.existsSync(binaryPath)) {
|
|
178
|
+
fs.unlinkSync(binaryPath);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
67
182
|
|
|
183
|
+
if (downloaded) {
|
|
68
184
|
console.log('');
|
|
69
185
|
console.log('ZarzCLI installed successfully!');
|
|
70
186
|
console.log('');
|
|
@@ -74,18 +190,24 @@ function main() {
|
|
|
74
190
|
console.log('');
|
|
75
191
|
console.log('See QUICKSTART.md for more information.');
|
|
76
192
|
console.log('');
|
|
77
|
-
|
|
78
|
-
|
|
193
|
+
} else {
|
|
194
|
+
console.error('');
|
|
195
|
+
console.error('Failed to download pre-built binary.');
|
|
79
196
|
console.error('');
|
|
80
|
-
console.error('
|
|
197
|
+
console.error('This could be due to:');
|
|
198
|
+
console.error(' 1. Network connection issues');
|
|
199
|
+
console.error(' 2. GitHub release not yet available for this version');
|
|
81
200
|
console.error('');
|
|
82
|
-
console.error('Please
|
|
83
|
-
console.error(' 1.
|
|
84
|
-
console.error(' 2.
|
|
201
|
+
console.error('Please try:');
|
|
202
|
+
console.error(' 1. Check your internet connection');
|
|
203
|
+
console.error(' 2. Try again later');
|
|
204
|
+
console.error(' 3. Report issue at: https://github.com/zarzet/zarzcli/issues');
|
|
85
205
|
console.error('');
|
|
86
|
-
console.error('Error:', error.message);
|
|
87
206
|
process.exit(1);
|
|
88
207
|
}
|
|
89
208
|
}
|
|
90
209
|
|
|
91
|
-
main()
|
|
210
|
+
main().catch((error) => {
|
|
211
|
+
console.error('Installation failed:', error);
|
|
212
|
+
process.exit(1);
|
|
213
|
+
});
|