@bigfishnpm/matrixcode 0.2.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 MatrixCode Contributors
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 ADDED
@@ -0,0 +1,59 @@
1
+ # MatrixCode npm Package
2
+
3
+ 这个 npm 包是 [MatrixCode](https://github.com/bigfish1913/matrixcode) 的安装包装器。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install -g matrixcode
9
+ ```
10
+
11
+ 安装脚本会自动:
12
+ 1. 检查是否已安装 `matrixcode`
13
+ 2. 如果有 Rust/Cargo,使用 `cargo install matrixcode`
14
+ 3. 否则从 GitHub Releases 下载预编译二进制
15
+
16
+ ## 手动安装
17
+
18
+ 如果自动安装失败,你可以:
19
+
20
+ ```bash
21
+ # 使用 Cargo
22
+ cargo install matrixcode
23
+
24
+ # 或从 GitHub Releases 下载
25
+ # https://github.com/bigfish1913/matrixcode/releases
26
+ ```
27
+
28
+ ## 发布说明
29
+
30
+ 发布新版本时:
31
+
32
+ 1. 更新版本号:
33
+ - `Cargo.toml` 中的 `version`
34
+ - `npm/package.json` 中的 `version`
35
+
36
+ 2. 发布到 crates.io:
37
+ ```bash
38
+ cargo login
39
+ cargo publish
40
+ ```
41
+
42
+ 3. 发布到 npm:
43
+ ```bash
44
+ cd npm
45
+ npm login
46
+ npm publish
47
+ ```
48
+
49
+ 4. 创建 Git tag 并推送(触发 GitHub Release):
50
+ ```bash
51
+ git tag v0.1.0
52
+ git push origin v0.1.0
53
+ ```
54
+
55
+ ## 支持的平台
56
+
57
+ - macOS (x64, Apple Silicon)
58
+ - Linux (x64, arm64)
59
+ - Windows (x64)
package/bin/matrixcode ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { spawn } = require('child_process');
4
+ const path = require('path');
5
+ const fs = require('fs');
6
+ const os = require('os');
7
+
8
+ // Find the matrixcode binary
9
+ const ext = os.platform() === 'win32' ? '.exe' : '';
10
+ const localBin = path.join(__dirname, 'bin', `matrixcode${ext}`);
11
+
12
+ let binPath = 'matrixcode'; // Default: use system-installed
13
+
14
+ // If local binary exists, use it
15
+ if (fs.existsSync(localBin)) {
16
+ binPath = localBin;
17
+ }
18
+
19
+ // Spawn the actual binary with all arguments
20
+ const child = spawn(binPath, process.argv.slice(2), {
21
+ stdio: 'inherit',
22
+ shell: os.platform() === 'win32',
23
+ });
24
+
25
+ child.on('error', (err) => {
26
+ if (err.code === 'ENOENT') {
27
+ console.error('[matrixcode] Error: matrixcode binary not found');
28
+ console.error('');
29
+ console.error('Please install matrixcode:');
30
+ console.error(' npm install -g matrixcode');
31
+ console.error(' or');
32
+ console.error(' cargo install matrixcode');
33
+ process.exit(1);
34
+ } else {
35
+ console.error('[matrixcode] Error:', err.message);
36
+ process.exit(1);
37
+ }
38
+ });
39
+
40
+ child.on('exit', (code) => {
41
+ process.exitCode = code || 0;
42
+ });
package/install.js ADDED
@@ -0,0 +1,221 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { execSync, spawnSync } = require('child_process');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const os = require('os');
7
+ const https = require('https');
8
+
9
+ const BIN_DIR = path.join(__dirname, 'bin');
10
+ const PACKAGE_VERSION = require('./package.json').version;
11
+
12
+ // Platform mapping for GitHub releases (matches release.yml targets)
13
+ const PLATFORM_MAP = {
14
+ 'darwin-x64': { target: 'x86_64-apple-darwin', archive: 'tar.gz' },
15
+ 'darwin-arm64': { target: 'aarch64-apple-darwin', archive: 'tar.gz' },
16
+ 'linux-x64': { target: 'x86_64-unknown-linux-gnu', archive: 'tar.gz' },
17
+ 'linux-arm64': { target: 'aarch64-unknown-linux-gnu', archive: 'tar.gz' },
18
+ 'win32-x64': { target: 'x86_64-pc-windows-msvc', archive: 'zip' },
19
+ 'win32-arm64': { target: 'aarch64-pc-windows-msvc', archive: 'zip' },
20
+ };
21
+
22
+ function getPlatform() {
23
+ const platform = os.platform();
24
+ const arch = os.arch();
25
+ const key = `${platform}-${arch}`;
26
+ return PLATFORM_MAP[key] || null;
27
+ }
28
+
29
+ function checkCommand(cmd) {
30
+ try {
31
+ execSync(`${cmd} --version`, { stdio: 'ignore' });
32
+ return true;
33
+ } catch {
34
+ return false;
35
+ }
36
+ }
37
+
38
+ function isMatrixcodeInstalled() {
39
+ try {
40
+ const result = spawnSync('matrixcode', ['--version'], { stdio: 'ignore' });
41
+ return result.status === 0;
42
+ } catch {
43
+ return false;
44
+ }
45
+ }
46
+
47
+ function installViaCargo() {
48
+ console.log('[matrixcode] Installing via cargo install matrixcode...');
49
+ try {
50
+ execSync('cargo install matrixcode', { stdio: 'inherit' });
51
+ console.log('[matrixcode] ✓ Installed successfully via cargo');
52
+ return true;
53
+ } catch (error) {
54
+ console.error('[matrixcode] ✗ Failed to install via cargo:', error.message);
55
+ return false;
56
+ }
57
+ }
58
+
59
+ function downloadFile(url, dest) {
60
+ return new Promise((resolve, reject) => {
61
+ const file = fs.createWriteStream(dest);
62
+ const request = (urlString) => {
63
+ https.get(urlString, (response) => {
64
+ if (response.statusCode === 302 || response.statusCode === 301) {
65
+ // Follow redirect
66
+ request(response.headers.location);
67
+ return;
68
+ }
69
+ if (response.statusCode !== 200) {
70
+ reject(new Error(`HTTP ${response.statusCode}`));
71
+ return;
72
+ }
73
+ response.pipe(file);
74
+ file.on('finish', () => {
75
+ file.close();
76
+ resolve();
77
+ });
78
+ }).on('error', (err) => {
79
+ fs.unlink(dest, () => {});
80
+ reject(err);
81
+ });
82
+ };
83
+ request(url);
84
+ });
85
+ }
86
+
87
+ async function downloadBinary() {
88
+ const platformInfo = getPlatform();
89
+ if (!platformInfo) {
90
+ console.error(`[matrixcode] Unsupported platform: ${os.platform()}-${os.arch()}`);
91
+ console.log('[matrixcode] Falling back to cargo install...');
92
+ return installViaCargo();
93
+ }
94
+
95
+ const { target, archive } = platformInfo;
96
+ const archiveName = `matrixcode-${target}.${archive}`;
97
+ const downloadUrl = `https://github.com/bigfish1913/matrixcode/releases/download/v${PACKAGE_VERSION}/${archiveName}`;
98
+
99
+ console.log(`[matrixcode] Downloading binary for ${target}...`);
100
+ console.log(`[matrixcode] URL: ${downloadUrl}`);
101
+
102
+ // Create bin directory
103
+ if (!fs.existsSync(BIN_DIR)) {
104
+ fs.mkdirSync(BIN_DIR, { recursive: true });
105
+ }
106
+
107
+ const archivePath = path.join(BIN_DIR, archiveName);
108
+ const binaryName = os.platform() === 'win32' ? 'matrixcode.exe' : 'matrixcode';
109
+ const targetPath = path.join(BIN_DIR, binaryName);
110
+
111
+ try {
112
+ await downloadFile(downloadUrl, archivePath);
113
+ console.log('[matrixcode] ✓ Download complete, extracting...');
114
+ } catch (error) {
115
+ console.error(`[matrixcode] ✗ Failed to download: ${error.message}`);
116
+ console.log('[matrixcode] Falling back to cargo install...');
117
+ return installViaCargo();
118
+ }
119
+
120
+ // Extract archive
121
+ try {
122
+ if (archive === 'tar.gz') {
123
+ // Use tar to extract (available on macOS and Linux)
124
+ execSync(`tar -xzf "${archivePath}" -C "${BIN_DIR}"`, { stdio: 'inherit' });
125
+ } else if (archive === 'zip') {
126
+ // On Windows, use PowerShell
127
+ execSync(`powershell -Command "Expand-Archive -Path '${archivePath}' -DestinationPath '${BIN_DIR}' -Force"`, { stdio: 'inherit' });
128
+ }
129
+
130
+ // Make binary executable (Unix)
131
+ if (os.platform() !== 'win32') {
132
+ fs.chmodSync(targetPath, 0o755);
133
+ }
134
+
135
+ // Clean up archive
136
+ fs.unlinkSync(archivePath);
137
+
138
+ console.log('[matrixcode] ✓ Binary installed successfully');
139
+ return true;
140
+ } catch (error) {
141
+ console.error(`[matrixcode] ✗ Failed to extract: ${error.message}`);
142
+ // Clean up
143
+ try { fs.unlinkSync(archivePath); } catch {}
144
+ console.log('[matrixcode] Falling back to cargo install...');
145
+ return installViaCargo();
146
+ }
147
+ }
148
+
149
+ function createWrapperScript() {
150
+ const ext = os.platform() === 'win32' ? '.cmd' : '';
151
+ const wrapperPath = path.join(BIN_DIR, `matrixcode${ext}`);
152
+
153
+ // Make sure bin directory exists
154
+ if (!fs.existsSync(BIN_DIR)) {
155
+ fs.mkdirSync(BIN_DIR, { recursive: true });
156
+ }
157
+
158
+ if (os.platform() === 'win32') {
159
+ // Windows batch script
160
+ const content = `@echo off
161
+ matrixcode %*
162
+ `;
163
+ fs.writeFileSync(wrapperPath, content);
164
+ } else {
165
+ // Unix shell script - just call the system-installed matrixcode
166
+ const content = `#!/bin/sh
167
+ exec matrixcode "$@"
168
+ `;
169
+ fs.writeFileSync(wrapperPath, content, { mode: 0o755 });
170
+ }
171
+
172
+ console.log('[matrixcode] ✓ Wrapper script created');
173
+ }
174
+
175
+ async function main() {
176
+ console.log(`[matrixcode] v${PACKAGE_VERSION}`);
177
+ console.log('');
178
+
179
+ // Check if matrixcode is already installed
180
+ if (isMatrixcodeInstalled()) {
181
+ console.log('[matrixcode] ✓ matrixcode is already installed');
182
+ createWrapperScript();
183
+ return;
184
+ }
185
+
186
+ console.log('[matrixcode] matrixcode not found, installing...');
187
+ console.log('');
188
+
189
+ // Prefer cargo if available (more reliable)
190
+ if (checkCommand('cargo')) {
191
+ console.log('[matrixcode] Found cargo, installing via cargo...');
192
+ if (installViaCargo()) {
193
+ createWrapperScript();
194
+ return;
195
+ }
196
+ }
197
+
198
+ // Try downloading pre-built binary
199
+ if (await downloadBinary()) {
200
+ return;
201
+ }
202
+
203
+ // Final fallback: show manual instructions
204
+ console.error('');
205
+ console.error('[matrixcode] ✗ Automatic installation failed');
206
+ console.error('');
207
+ console.error('Please install manually using one of these methods:');
208
+ console.error('');
209
+ console.error(' # Option 1: Using cargo (recommended)');
210
+ console.error(' cargo install matrixcode');
211
+ console.error('');
212
+ console.error(' # Option 2: Download from GitHub Releases');
213
+ console.error(' https://github.com/bigfish1913/matrixcode/releases');
214
+ console.error('');
215
+ process.exit(1);
216
+ }
217
+
218
+ main().catch(err => {
219
+ console.error('[matrixcode] Installation error:', err.message);
220
+ process.exit(1);
221
+ });
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@bigfishnpm/matrixcode",
3
+ "version": "0.2.1",
4
+ "description": "A smart code agent CLI with multi-model support, context compression, and task planning",
5
+ "author": "bigfish1913",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/bigfish1913/matrixcode.git"
10
+ },
11
+ "homepage": "https://github.com/bigfish1913/matrixcode#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/bigfish1913/matrixcode/issues"
14
+ },
15
+ "keywords": [
16
+ "ai",
17
+ "llm",
18
+ "code-agent",
19
+ "cli",
20
+ "anthropic",
21
+ "claude",
22
+ "gpt",
23
+ "assistant"
24
+ ],
25
+ "bin": {
26
+ "matrixcode": "./bin/matrixcode"
27
+ },
28
+ "scripts": {
29
+ "postinstall": "node install.js"
30
+ },
31
+ "engines": {
32
+ "node": ">=16"
33
+ },
34
+ "files": [
35
+ "bin/",
36
+ "install.js",
37
+ "README.md",
38
+ "LICENSE"
39
+ ],
40
+ "publishConfig": {
41
+ "access": "public"
42
+ }
43
+ }