@putao520/aiw 0.5.14 → 0.5.26

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/README.md CHANGED
@@ -2,37 +2,61 @@
2
2
 
3
3
  <div align="center">
4
4
 
5
- ![Version](https://img.shields.io/badge/version-0.5.13-blue?style=flat-square)
5
+ ![Version](https://img.shields.io/badge/version-0.5.25--developing-blue?style=flat-square)
6
6
  ![Rust](https://img.shields.io/badge/Rust-1.70+-orange?style=flat-square&logo=rust)
7
7
  ![License](https://img.shields.io/badge/License-MIT-green?style=flat-square)
8
8
  ![MCP](https://img.shields.io/badge/MCP-Supported-purple?style=flat-square)
9
9
 
10
- **Universal AI CLI Management Platform with Intelligent MCP Routing**
10
+ **Universal AI CLI Management Platform with Intelligent MCP Routing & Transparent Parameter Forwarding**
11
11
 
12
12
  </div>
13
13
 
14
- AIW is an intelligent platform for managing AI CLI tools (Claude, Codex, Gemini) with MCP routing, process tracking, and configuration synchronization.
14
+ AIW is an intelligent platform for managing AI CLI tools (Claude, Codex, Gemini) with MCP routing, process tracking, provider management, and transparent parameter forwarding.
15
15
 
16
16
  ## 🎯 Core Features
17
17
 
18
18
  ### 1. AI CLI Management
19
19
  - **Process Tree Tracking**: Monitor AI CLI processes and their children
20
20
  - **Provider Management**: Switch between AI providers (OpenAI, Anthropic, Google, etc.)
21
+ - **Transparent Parameter Forwarding**: Seamlessly pass all CLI parameters while using provider management
21
22
  - **Capability Detection**: Auto-detect installed AI CLI tools
22
23
  - **Wait Mode**: Block until AI CLI tasks complete
23
24
 
24
25
  ```bash
25
- # Launch AI CLI with process tracking
26
- aiw claude "explain this code"
27
- aiw codex "write a python script"
28
- aiw gemini "translate to french"
26
+ # Basic usage with provider management
27
+ aiw claude "explain this code" # Use default provider
28
+ aiw claude -p openrouter "explain this code" # Use OpenRouter provider
29
+ aiw claude -p glm "解释这段代码" # Use custom GLM provider
30
+
31
+ # 🆕 Transparent Parameter Forwarding (v0.5.23+)
32
+ aiw claude -p glm --model sonnet --debug api "explain this code"
33
+ aiw claude -p glm --print --output-format json "get structured response"
34
+ aiw codex -p glm --temperature 0.7 --max-tokens 1000 "generate text"
35
+
36
+ # Interactive mode with parameter forwarding
37
+ aiw claude -p glm --model sonnet --debug api # Interactive session with custom parameters
38
+ aiw claude -p glm --print --allowed-tools Bash,Edit # Interactive with tool restrictions
29
39
 
30
40
  # Wait for all AI CLI tasks to complete
31
- aiw wait --timeout 300
41
+ aiw wait
32
42
 
33
- # Manage providers
34
- aiw provider list
35
- aiw provider add openrouter "sk-xxx"
43
+ # Manage providers (TUI interface)
44
+ aiw provider
45
+ ```
46
+
47
+ ### 5. Update (更新AIW和AI CLI工具)
48
+ - **AIW Self-Update**: Update AIW itself to latest version from NPM
49
+ - **AI CLI Tools Update**: Update all installed AI CLI tools (claude, codex, gemini)
50
+ - **Combined Update**: Update both AIW and AI CLI tools in one command
51
+
52
+ ```bash
53
+ # Update both AIW and all AI CLI tools
54
+ aiw update
55
+
56
+ # Command will:
57
+ # 1. Check and update AIW to latest version
58
+ # 2. Check and update all installed AI CLI tools
59
+ # 3. Show detailed results for both updates
36
60
  ```
37
61
 
38
62
  ### 2. Intelligent MCP Routing ⭐
@@ -49,7 +73,7 @@ Route user requests to the best MCP tool with 98% token reduction.
49
73
  # Start MCP server
50
74
  aiw mcp
51
75
 
52
- # Configure in Claude Code (~/.config/claude-code/mcp.json)
76
+ # Configure in Claude Code (~/.claude/settings.json)
53
77
  {
54
78
  "mcpServers": {
55
79
  "aiw": {
@@ -83,20 +107,190 @@ aiw mcp disable filesystem
83
107
  # Hot-reload: Changes apply instantly without restart
84
108
  ```
85
109
 
86
- ### 4. Google Drive Sync (Optional)
87
- Synchronize AI CLI configurations across devices using Google Drive.
110
+ ### 4. MCP Registry CLI
111
+ Search and install MCP servers from multiple registries with multi-source aggregation.
112
+
113
+ **Supported Registries:**
114
+ - **Official MCP Registry** (registry.modelcontextprotocol.io)
115
+ - **Smithery** (registry.smithery.ai)
116
+
117
+ ```bash
118
+ # Interactive browse all MCP servers (with fuzzy search)
119
+ aiw mcp browse
120
+
121
+ # Search MCP servers across all registries
122
+ aiw mcp search "filesystem"
123
+ aiw mcp search "git" --source official # Search specific registry
124
+
125
+ # Get detailed server information
126
+ aiw mcp info @anthropic/filesystem
127
+
128
+ # Install MCP server with interactive setup
129
+ aiw mcp install @anthropic/filesystem
130
+
131
+ # Install with environment variables
132
+ aiw mcp install @anthropic/filesystem --env API_KEY=xxx
133
+
134
+ # Update registry cache
135
+ aiw mcp update
136
+ ```
137
+
138
+ **Features:**
139
+ - **Interactive Browse**: Fuzzy search through all servers with ↑↓ navigation
140
+ - **Multi-source Aggregation**: Search across Official Registry + Smithery in parallel
141
+ - **Deduplication**: Same server from multiple sources shown once with best match
142
+ - **Interactive Install**: Configure environment variables during installation
143
+ - **Source Tracking**: Track where each server was installed from
144
+
145
+ ### 5. Plugin Marketplace ⭐
146
+ Browse and install plugins from Claude Code-compatible plugin marketplaces.
147
+
148
+ **Default Marketplaces:**
149
+ - **Claude Code Official** (anthropics/claude-plugins-official)
150
+ - **AIW Official** (putao520/aiw-plugins)
151
+
152
+ ```bash
153
+ # Browse MCP plugins interactively
154
+ aiw plugin browse
155
+
156
+ # Search plugins
157
+ aiw plugin search "git"
158
+ aiw plugin search "playwright" --market claude-code-official
159
+
160
+ # View plugin details
161
+ aiw plugin info playwright@claude-code-official
162
+
163
+ # Install plugin (interactive setup)
164
+ aiw plugin install playwright@claude-code-official
165
+
166
+ # Install with environment variables
167
+ aiw plugin install serena@claude-code-official --env MY_VAR=value
168
+
169
+ # List installed plugins
170
+ aiw plugin list
171
+
172
+ # Enable/disable plugins
173
+ aiw plugin enable playwright
174
+ aiw plugin disable serena
175
+
176
+ # Remove plugin
177
+ aiw plugin remove playwright
178
+ ```
179
+
180
+ **Marketplace Management:**
181
+ ```bash
182
+ # List marketplaces
183
+ aiw plugin marketplace list
184
+
185
+ # Add custom marketplace
186
+ aiw plugin marketplace add my-market https://github.com/user/marketplace
187
+
188
+ # Remove marketplace
189
+ aiw plugin marketplace remove my-market
190
+
191
+ # Update marketplace indexes
192
+ aiw plugin marketplace update
193
+ ```
194
+
195
+ **Configuration Files:**
196
+ - `~/.aiw/settings.json`: Marketplace sources and plugin states
197
+ - `~/.aiw/plugins.json`: Installed plugin records
198
+ - `~/.aiw/mcp.json`: Extracted MCP server configurations
199
+
200
+ **Features:**
201
+ - **MCP-Only Filtering**: Only shows plugins with MCP servers (mcpServers field)
202
+ - **Claude Code Compatible**: Uses same plugin format as Claude Code
203
+ - **JSON Configuration**: Modern JSON format (automatic YAML migration)
204
+ - **Interactive Setup**: Configure environment variables during installation
205
+ - **Hot-Reload**: Changes apply instantly without restart
206
+ - **Transport Type Support**: Supports stdio transport (local executables). HTTP/SSE transports coming soon.
207
+
208
+ **Environment Variables:**
209
+ Plugins can use environment variable placeholders in their MCP configuration:
210
+ ```json
211
+ {
212
+ "env": {
213
+ "API_KEY": "${API_KEY}",
214
+ "GITHUB_TOKEN": "${GITHUB_TOKEN}"
215
+ }
216
+ }
217
+ ```
218
+ During installation, AIW will prompt for values or you can provide them via `--env` flag. Placeholders are preserved in the config and expanded at runtime.
219
+
220
+ ## 🔄 Transparent Parameter Forwarding (v0.5.23+)
221
+
222
+ AIW now supports transparent parameter forwarding, allowing you to use **all** AI CLI features while maintaining provider management capabilities.
88
223
 
224
+ ### How It Works
225
+
226
+ ```bash
227
+ # Parameter parsing logic:
228
+ aiw <ai_type> -p <provider> <cli_params...> <prompt>
229
+ # ^^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^
230
+ # AIW处理 AIW处理 透明转发到AI CLI
231
+ ```
232
+
233
+ ### Rules
234
+
235
+ - **AIW Consumes**: `-p` / `--provider` parameters for provider selection
236
+ - **Transparent Forwarding**: All other `-` prefixed parameters are passed directly to the AI CLI
237
+ - **Parameter Order**: Provider flags must come **before** other CLI parameters
238
+ - **Full Compatibility**: Maintain complete access to all AI CLI features
239
+
240
+ ### Examples
241
+
242
+ #### Task Mode
89
243
  ```bash
90
- # Push configurations to Google Drive
91
- aiw push [config_name]
244
+ # Model selection with debugging
245
+ aiw claude -p glm --model sonnet --debug api "explain this code"
246
+
247
+ # Structured output
248
+ aiw claude -p glm --print --output-format json "summarize the file"
92
249
 
93
- # Pull configurations from Google Drive
94
- aiw pull [config_name]
250
+ # Tool restrictions
251
+ aiw claude -p glm --allowed-tools Bash,Edit --print "modify this file"
95
252
 
96
- # List available backups
97
- aiw list
253
+ # Multiple parameters
254
+ aiw claude -p glm --model sonnet --max-budget-usd 5 --dangerously-skip-permissions "help me debug"
98
255
  ```
99
256
 
257
+ #### Interactive Mode
258
+ ```bash
259
+ # Interactive session with custom model and debugging
260
+ aiw claude -p glm --model sonnet --debug api
261
+
262
+ # Interactive with output formatting
263
+ aiw claude -p glm --print --output-format stream-json
264
+
265
+ # Interactive with specific tools
266
+ aiw claude -p glm --tools "Bash,Edit,Read" --no-session-persistence
267
+
268
+ # Multi-AI with same provider and parameters
269
+ aiw claude,codex -p glm --temperature 0.7 --print "compare approaches"
270
+ ```
271
+
272
+ #### Provider-Specific Examples
273
+ ```bash
274
+ # Claude with structured output
275
+ aiw claude -p glm --json-schema '{"type":"object","properties":{"summary":{"type":"string"}}}' --print "summarize"
276
+
277
+ # Codex with custom settings
278
+ aiw codex -p glm --temperature 0.3 --max-tokens 500 "write python function"
279
+
280
+ # Gemini with approval mode
281
+ aiw gemini -p glm --approval-mode yolo --print "translate this text"
282
+ ```
283
+
284
+ ### Benefits
285
+
286
+ ✅ **Full CLI Access**: Use all AI CLI parameters without limitations
287
+ ✅ **Provider Flexibility**: Switch providers without changing commands
288
+ ✅ **Process Tracking**: Maintain AIW's monitoring and task management
289
+ ✅ **Environment Injection**: Automatic provider configuration injection
290
+ ✅ **Zero Learning Curve**: Works exactly like native AI CLI with provider prefix
291
+
292
+ ---
293
+
100
294
  ## 🚀 Quick Start
101
295
 
102
296
  ### Installation
@@ -134,17 +328,13 @@ export CLI_TYPE=claude # claude, codex, or gemini
134
328
  export CLI_PROVIDER=llmlite # Any provider from provider.json
135
329
 
136
330
  # MCP Server Configuration
137
- export MCP_CONFIG_PATH=~/.aiw/.mcp.json
138
-
139
- # Google Drive OAuth (optional)
140
- export GOOGLE_CLIENT_ID=xxx
141
- export GOOGLE_CLIENT_SECRET=xxx
331
+ export MCP_CONFIG_PATH=~/.aiw/mcp.json
142
332
  ```
143
333
 
144
334
  ### Configuration Files
145
- - **MCP Servers**: `~/.aiw/.mcp.json`
335
+ - **MCP Servers**: `~/.aiw/mcp.json` (standard `mcpServers` schema compatible with Claude Code)
336
+ - Claude Code users: Add to `~/.claude/settings.json` under the "mcpServers" section
146
337
  - **Providers**: `~/.aiw/providers.json`
147
- - **Google Drive Auth**: `~/.aiw/auth.json`
148
338
 
149
339
  ## 🙏 Acknowledgments
150
340
 
@@ -157,6 +347,6 @@ MIT License - see [LICENSE](LICENSE) file for details.
157
347
 
158
348
  ---
159
349
 
160
- **AIW** - Universal AI CLI Management Platform with MCP Routing v0.5.13
350
+ **AIW** - Universal AI CLI Management Platform with MCP Routing v0.5.25
161
351
 
162
- For full documentation and source code, visit: [https://github.com/putao520/agentic-warden](https://github.com/putao520/agentic-warden)
352
+ For full documentation and source code, visit: [https://github.com/putao520/agentic-warden](https://github.com/putao520/agentic-warden)
package/index.js CHANGED
@@ -3,39 +3,48 @@
3
3
  const { spawnSync } = require('child_process');
4
4
  const path = require('path');
5
5
  const os = require('os');
6
+ const fs = require('fs');
6
7
 
7
- // 根据架构选择正确的二进制
8
8
  const arch = os.arch();
9
9
  const platform = os.platform();
10
10
 
11
+ let binaryName;
11
12
  let binaryPath;
12
13
 
13
- if (platform === 'linux') {
14
- switch (arch) {
15
- case 'x64':
16
- binaryPath = path.join(__dirname, 'bin', 'aiw-linux-x64');
17
- break;
18
- default:
19
- console.error(`❌ Unsupported architecture: ${arch}`);
20
- console.error('Supported: x64');
21
- process.exit(1);
22
- }
23
- } else if (platform === 'win32') {
24
- switch (arch) {
25
- case 'x64':
26
- binaryPath = path.join(__dirname, 'bin', 'aiw-windows-x64.exe');
27
- break;
28
- default:
29
- console.error(`❌ Unsupported architecture: ${arch}`);
30
- console.error('Supported: x64');
31
- process.exit(1);
32
- }
14
+ // Determine binary name based on platform
15
+ if (platform === 'linux' && arch === 'x64') {
16
+ binaryName = 'aiw-linux-x64';
17
+ } else if (platform === 'win32' && arch === 'x64') {
18
+ binaryName = 'aiw-windows-x64.exe';
33
19
  } else {
34
- console.error(`❌ Unsupported platform: ${platform}`);
35
- console.error('Supported: linux, win32');
36
- console.error('\nAlternative options:');
37
- console.error('1. Using Cargo: cargo install --git https://github.com/putao520/agentic-warden');
38
- console.error('2. Download pre-built: https://github.com/putao520/agentic-warden/releases');
20
+ console.error(`Error: Unsupported platform: ${platform}-${arch}`);
21
+ console.error('');
22
+ console.error('Supported platforms:');
23
+ console.error(' - linux-x64');
24
+ console.error(' - win32-x64');
25
+ console.error('');
26
+ console.error('Alternative installation:');
27
+ console.error(' cargo install --git https://github.com/putao520/agentic-warden');
28
+ console.error(' https://github.com/putao520/agentic-warden/releases');
29
+ process.exit(1);
30
+ }
31
+
32
+ binaryPath = path.join(__dirname, 'bin', binaryName);
33
+
34
+ // Check if binary exists
35
+ if (!fs.existsSync(binaryPath)) {
36
+ console.error(`Error: Binary not found: ${binaryPath}`);
37
+ console.error('');
38
+ console.error('The postinstall script may have failed to download the binary.');
39
+ console.error('');
40
+ console.error('Try reinstalling:');
41
+ console.error(' npm uninstall -g @putao520/aiw && npm install -g @putao520/aiw');
42
+ console.error('');
43
+ console.error('Or run postinstall manually:');
44
+ console.error(` node ${path.join(__dirname, 'scripts', 'postinstall.js')}`);
45
+ console.error('');
46
+ console.error('Alternative installation:');
47
+ console.error(' cargo install --git https://github.com/putao520/agentic-warden');
39
48
  process.exit(1);
40
49
  }
41
50
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putao520/aiw",
3
- "version": "0.5.14",
3
+ "version": "0.5.26",
4
4
  "description": "Universal AI CLI management platform with intelligent MCP routing, process tracking, and configuration synchronization",
5
5
  "keywords": [
6
6
  "ai",
@@ -23,12 +23,14 @@
23
23
  "license": "MIT",
24
24
  "author": "Putao520",
25
25
  "bin": {
26
- "aiw": "./bin/aiw-linux-x64"
26
+ "aiw": "./index.js"
27
+ },
28
+ "scripts": {
29
+ "postinstall": "node scripts/postinstall.js"
27
30
  },
28
31
  "files": [
29
- "bin/aiw-linux-x64",
30
- "bin/aiw-windows-x64.exe",
31
32
  "index.js",
33
+ "scripts/postinstall.js",
32
34
  "README.md"
33
35
  ],
34
36
  "engines": {
@@ -39,16 +41,13 @@
39
41
  "win32"
40
42
  ],
41
43
  "cpu": [
42
- "x64",
43
- "arm64",
44
- "arm"
44
+ "x64"
45
45
  ],
46
46
  "bugs": {
47
47
  "url": "https://github.com/putao520/agentic-warden/issues"
48
48
  },
49
49
  "publishConfig": {
50
50
  "access": "public",
51
- "registry": "https://registry.npmjs.org/",
52
- "provenance": true
51
+ "registry": "https://registry.npmjs.org/"
53
52
  }
54
53
  }
@@ -0,0 +1,60 @@
1
+ # 脚本使用说明
2
+
3
+ ## 版本更新脚本 (update-version.sh)
4
+
5
+ ### 功能
6
+ 自动化同步项目版本号,确保所有文件保持一致。
7
+
8
+ ### 更新的文件
9
+ - `VERSION` - 项目主版本文件
10
+ - `Cargo.toml` - Rust 项目版本
11
+ - `npm-package/package.json` - 由 GitHub Actions 自动更新
12
+
13
+ ### 使用方法
14
+
15
+ ```bash
16
+ # 基本用法
17
+ ./scripts/update-version.sh <version>
18
+
19
+ # 示例:更新到版本 0.5.20
20
+ ./scripts/update-version.sh 0.5.20
21
+ ```
22
+
23
+ ### 版本格式
24
+ 必须使用 `major.minor.patch` 格式:
25
+ - ✅ `0.5.20`
26
+ - ✅ `1.0.0`
27
+ - ❌ `v0.5.20` (不要加 v)
28
+ - ❌ `0.5` (不完整)
29
+
30
+ ### 完整工作流程
31
+
32
+ ```bash
33
+ # 1. 运行脚本更新版本
34
+ ./scripts/update-version.sh 0.5.20
35
+
36
+ # 2. 检查变更
37
+ git diff
38
+
39
+ # 3. 提交变更
40
+ git add .
41
+ git commit -m "feat: 版本更新到 0.5.20"
42
+
43
+ # 4. 创建并推送 tag
44
+ git tag v0.5.20
45
+ git push origin master
46
+ git push origin v0.5.20
47
+
48
+ # 5. GitHub Actions 将自动:
49
+ # - 构建 Linux 和 Windows 二进制文件
50
+ # - 更新 npm-package/package.json 版本
51
+ # - 发布到 NPM
52
+ # - 创建 GitHub Release
53
+ ```
54
+
55
+ ### 注意事项
56
+
57
+ 1. **npm-package/package.json 由 CI/CD 自动更新**,无需手动修改
58
+ 2. **版本号必须与 Git tag 保持一致**
59
+ 3. **脚本会验证版本格式,不符合会报错**
60
+ 4. **每次更新前会检查文件是否存在,避免误操作**
@@ -0,0 +1,233 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * postinstall.js - Platform-specific binary downloader for aiw
5
+ *
6
+ * Downloads the correct binary for the current platform from GitHub Releases.
7
+ * Supports: Linux x64, Windows x64
8
+ */
9
+
10
+ const https = require('https');
11
+ const fs = require('fs');
12
+ const path = require('path');
13
+ const os = require('os');
14
+ const { execSync } = require('child_process');
15
+
16
+ // Configuration
17
+ const REPO_OWNER = 'putao520';
18
+ const REPO_NAME = 'agentic-warden';
19
+ const BIN_DIR = path.join(__dirname, '..', 'bin');
20
+
21
+ // Platform mapping
22
+ const PLATFORM_MAP = {
23
+ 'linux-x64': {
24
+ filename: 'aiw-linux-x64',
25
+ asset: 'aiw-linux-x64',
26
+ },
27
+ 'win32-x64': {
28
+ filename: 'aiw-windows-x64.exe',
29
+ asset: 'aiw-windows-x64.exe',
30
+ },
31
+ };
32
+
33
+ /**
34
+ * Get package version from package.json
35
+ */
36
+ function getPackageVersion() {
37
+ const packageJson = require(path.join(__dirname, '..', 'package.json'));
38
+ return packageJson.version;
39
+ }
40
+
41
+ /**
42
+ * Get platform key for current system
43
+ */
44
+ function getPlatformKey() {
45
+ const platform = os.platform();
46
+ const arch = os.arch();
47
+ return `${platform}-${arch}`;
48
+ }
49
+
50
+ /**
51
+ * Download file with redirect support
52
+ */
53
+ function downloadFile(url, dest) {
54
+ return new Promise((resolve, reject) => {
55
+ const file = fs.createWriteStream(dest);
56
+
57
+ const request = (url) => {
58
+ const protocol = url.startsWith('https') ? https : require('http');
59
+
60
+ protocol.get(url, {
61
+ headers: {
62
+ 'User-Agent': 'aiw-npm-installer',
63
+ },
64
+ }, (response) => {
65
+ // Handle redirects (GitHub releases use 302)
66
+ if (response.statusCode === 301 || response.statusCode === 302) {
67
+ const redirectUrl = response.headers.location;
68
+ if (redirectUrl) {
69
+ request(redirectUrl);
70
+ return;
71
+ }
72
+ }
73
+
74
+ if (response.statusCode !== 200) {
75
+ reject(new Error(`Download failed with status ${response.statusCode}`));
76
+ return;
77
+ }
78
+
79
+ const totalSize = parseInt(response.headers['content-length'], 10);
80
+ let downloadedSize = 0;
81
+ let lastProgress = 0;
82
+
83
+ response.on('data', (chunk) => {
84
+ downloadedSize += chunk.length;
85
+ if (totalSize) {
86
+ const progress = Math.floor((downloadedSize / totalSize) * 100);
87
+ if (progress >= lastProgress + 10) {
88
+ process.stdout.write(`\r Downloading: ${progress}%`);
89
+ lastProgress = progress;
90
+ }
91
+ }
92
+ });
93
+
94
+ response.pipe(file);
95
+
96
+ file.on('finish', () => {
97
+ file.close();
98
+ console.log('\r Downloading: 100%');
99
+ resolve();
100
+ });
101
+ }).on('error', (err) => {
102
+ fs.unlink(dest, () => {});
103
+ reject(err);
104
+ });
105
+ };
106
+
107
+ request(url);
108
+ });
109
+ }
110
+
111
+ /**
112
+ * Make file executable (Unix only)
113
+ */
114
+ function makeExecutable(filepath) {
115
+ if (os.platform() !== 'win32') {
116
+ try {
117
+ fs.chmodSync(filepath, 0o755);
118
+ } catch (err) {
119
+ console.warn(` Warning: Could not set executable permission: ${err.message}`);
120
+ }
121
+ }
122
+ }
123
+
124
+ /**
125
+ * Check if binary already exists and is valid
126
+ */
127
+ function binaryExists(filepath) {
128
+ try {
129
+ if (!fs.existsSync(filepath)) {
130
+ return false;
131
+ }
132
+
133
+ // Check if file is executable and returns version
134
+ const stat = fs.statSync(filepath);
135
+ if (stat.size < 1000) {
136
+ // File too small, probably corrupted
137
+ return false;
138
+ }
139
+
140
+ return true;
141
+ } catch {
142
+ return false;
143
+ }
144
+ }
145
+
146
+ /**
147
+ * Main installation function
148
+ */
149
+ async function install() {
150
+ console.log('');
151
+ console.log(' aiw postinstall: Setting up platform-specific binary...');
152
+ console.log('');
153
+
154
+ const platformKey = getPlatformKey();
155
+ const platformInfo = PLATFORM_MAP[platformKey];
156
+
157
+ if (!platformInfo) {
158
+ console.log(` Platform ${platformKey} is not supported.`);
159
+ console.log('');
160
+ console.log(' Supported platforms:');
161
+ console.log(' - linux-x64');
162
+ console.log(' - win32-x64');
163
+ console.log('');
164
+ console.log(' Alternative installation methods:');
165
+ console.log(' 1. Cargo: cargo install --git https://github.com/putao520/agentic-warden');
166
+ console.log(' 2. Download: https://github.com/putao520/agentic-warden/releases');
167
+ console.log('');
168
+ process.exit(0); // Don't fail npm install
169
+ }
170
+
171
+ // Ensure bin directory exists
172
+ if (!fs.existsSync(BIN_DIR)) {
173
+ fs.mkdirSync(BIN_DIR, { recursive: true });
174
+ }
175
+
176
+ const binaryPath = path.join(BIN_DIR, platformInfo.filename);
177
+
178
+ // Check if binary already exists
179
+ if (binaryExists(binaryPath)) {
180
+ console.log(` Binary already exists: ${platformInfo.filename}`);
181
+ console.log(' Skipping download.');
182
+ console.log('');
183
+ return;
184
+ }
185
+
186
+ const version = getPackageVersion();
187
+ const downloadUrl = `https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/v${version}/${platformInfo.asset}`;
188
+
189
+ console.log(` Platform: ${platformKey}`);
190
+ console.log(` Version: v${version}`);
191
+ console.log(` Binary: ${platformInfo.filename}`);
192
+ console.log('');
193
+
194
+ try {
195
+ console.log(` Downloading from GitHub Releases...`);
196
+ await downloadFile(downloadUrl, binaryPath);
197
+
198
+ makeExecutable(binaryPath);
199
+
200
+ console.log('');
201
+ console.log(' Installation complete!');
202
+ console.log(` Binary installed: ${binaryPath}`);
203
+ console.log('');
204
+ } catch (err) {
205
+ console.error('');
206
+ console.error(` Download failed: ${err.message}`);
207
+ console.error('');
208
+ console.error(' This might happen if:');
209
+ console.error(` - Release v${version} doesn't exist yet`);
210
+ console.error(' - GitHub is unreachable');
211
+ console.error(' - Network issues');
212
+ console.error('');
213
+ console.error(' Alternative installation:');
214
+ console.error(' cargo install --git https://github.com/putao520/agentic-warden');
215
+ console.error('');
216
+
217
+ // Clean up partial download
218
+ try {
219
+ if (fs.existsSync(binaryPath)) {
220
+ fs.unlinkSync(binaryPath);
221
+ }
222
+ } catch {}
223
+
224
+ // Don't fail npm install, just warn
225
+ process.exit(0);
226
+ }
227
+ }
228
+
229
+ // Run installation
230
+ install().catch((err) => {
231
+ console.error(' Unexpected error:', err.message);
232
+ process.exit(0); // Don't fail npm install
233
+ });
package/bin/aiw-linux-x64 DELETED
Binary file
Binary file