claude-code-rust 0.2.0 → 0.4.0
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 +8 -20
- package/agent-sdk/README.md +13 -0
- package/agent-sdk/dist/bridge/auth.js +7 -0
- package/agent-sdk/dist/bridge/commands.js +163 -0
- package/agent-sdk/dist/bridge/history.js +344 -0
- package/agent-sdk/dist/bridge/permissions.js +99 -0
- package/agent-sdk/dist/bridge/shared.js +6 -0
- package/agent-sdk/dist/bridge/tooling.js +290 -0
- package/agent-sdk/dist/bridge/usage.js +95 -0
- package/agent-sdk/dist/bridge.js +1224 -0
- package/agent-sdk/dist/bridge.test.js +445 -0
- package/agent-sdk/dist/types.js +1 -0
- package/bin/claude-rs.js +37 -37
- package/package.json +14 -3
- package/scripts/postinstall.js +65 -65
package/scripts/postinstall.js
CHANGED
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
|
|
4
|
-
const fs = require("node:fs");
|
|
5
|
-
const path = require("node:path");
|
|
6
|
-
const https = require("node:https");
|
|
7
|
-
const { pipeline } = require("node:stream/promises");
|
|
8
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const fs = require("node:fs");
|
|
5
|
+
const path = require("node:path");
|
|
6
|
+
const https = require("node:https");
|
|
7
|
+
const { pipeline } = require("node:stream/promises");
|
|
8
|
+
|
|
9
9
|
const TARGETS = {
|
|
10
10
|
"darwin:arm64": { target: "aarch64-apple-darwin", exe: "claude-rs" },
|
|
11
11
|
"darwin:x64": { target: "x86_64-apple-darwin", exe: "claude-rs" },
|
|
12
12
|
"linux:x64": { target: "x86_64-unknown-linux-gnu", exe: "claude-rs" },
|
|
13
13
|
"win32:x64": { target: "x86_64-pc-windows-msvc", exe: "claude-rs.exe" }
|
|
14
14
|
};
|
|
15
|
-
|
|
16
|
-
const MAX_REDIRECTS = 5;
|
|
17
|
-
|
|
18
|
-
function getTargetInfo() {
|
|
19
|
-
return TARGETS[`${process.platform}:${process.arch}`];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async function downloadFile(url, outPath, redirects = 0) {
|
|
23
|
-
if (redirects > MAX_REDIRECTS) {
|
|
24
|
-
throw new Error(`Too many redirects while downloading ${url}`);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
await new Promise((resolve, reject) => {
|
|
28
|
-
const req = https.get(
|
|
15
|
+
|
|
16
|
+
const MAX_REDIRECTS = 5;
|
|
17
|
+
|
|
18
|
+
function getTargetInfo() {
|
|
19
|
+
return TARGETS[`${process.platform}:${process.arch}`];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function downloadFile(url, outPath, redirects = 0) {
|
|
23
|
+
if (redirects > MAX_REDIRECTS) {
|
|
24
|
+
throw new Error(`Too many redirects while downloading ${url}`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
await new Promise((resolve, reject) => {
|
|
28
|
+
const req = https.get(
|
|
29
29
|
url,
|
|
30
30
|
{ headers: { "User-Agent": "claude-code-rust-npm-installer" } },
|
|
31
31
|
(res) => {
|
|
32
|
-
const status = res.statusCode ?? 0;
|
|
33
|
-
|
|
34
|
-
if (status >= 300 && status < 400 && res.headers.location) {
|
|
35
|
-
const nextUrl = new URL(res.headers.location, url).toString();
|
|
36
|
-
res.resume();
|
|
37
|
-
downloadFile(nextUrl, outPath, redirects + 1).then(resolve).catch(reject);
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (status !== 200) {
|
|
42
|
-
const chunks = [];
|
|
43
|
-
res.on("data", (chunk) => chunks.push(chunk));
|
|
44
|
-
res.on("end", () => {
|
|
45
|
-
const body = Buffer.concat(chunks).toString("utf8").trim();
|
|
46
|
-
reject(new Error(`Download failed (${status}) for ${url}${body ? `: ${body}` : ""}`));
|
|
47
|
-
});
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
pipeline(res, fs.createWriteStream(outPath)).then(resolve).catch(reject);
|
|
52
|
-
}
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
req.on("error", reject);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async function main() {
|
|
32
|
+
const status = res.statusCode ?? 0;
|
|
33
|
+
|
|
34
|
+
if (status >= 300 && status < 400 && res.headers.location) {
|
|
35
|
+
const nextUrl = new URL(res.headers.location, url).toString();
|
|
36
|
+
res.resume();
|
|
37
|
+
downloadFile(nextUrl, outPath, redirects + 1).then(resolve).catch(reject);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (status !== 200) {
|
|
42
|
+
const chunks = [];
|
|
43
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
44
|
+
res.on("end", () => {
|
|
45
|
+
const body = Buffer.concat(chunks).toString("utf8").trim();
|
|
46
|
+
reject(new Error(`Download failed (${status}) for ${url}${body ? `: ${body}` : ""}`));
|
|
47
|
+
});
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
pipeline(res, fs.createWriteStream(outPath)).then(resolve).catch(reject);
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
req.on("error", reject);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function main() {
|
|
60
60
|
const info = getTargetInfo();
|
|
61
61
|
if (!info) {
|
|
62
62
|
const key = `${process.platform}:${process.arch}`;
|
|
63
63
|
throw new Error(`Unsupported platform/arch for claude-code-rust npm install: ${key}`);
|
|
64
64
|
}
|
|
65
|
-
|
|
66
|
-
const pkgJsonPath = path.join(__dirname, "..", "package.json");
|
|
65
|
+
|
|
66
|
+
const pkgJsonPath = path.join(__dirname, "..", "package.json");
|
|
67
67
|
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
|
|
68
68
|
const version = process.env.npm_package_version || pkg.version;
|
|
69
69
|
const tag = `v${version}`;
|
|
70
70
|
const repo = "srothgan/claude-code-rust";
|
|
71
71
|
const assetName = `claude-code-rust-${info.target}${info.exe.endsWith(".exe") ? ".exe" : ""}`;
|
|
72
72
|
const url = `https://github.com/${repo}/releases/download/${tag}/${assetName}`;
|
|
73
|
-
|
|
74
|
-
const installDir = path.join(__dirname, "..", "vendor", info.target);
|
|
75
|
-
const binaryPath = path.join(installDir, info.exe);
|
|
76
|
-
const tempPath = `${binaryPath}.tmp`;
|
|
77
|
-
|
|
78
|
-
fs.mkdirSync(installDir, { recursive: true });
|
|
79
|
-
await downloadFile(url, tempPath);
|
|
80
|
-
fs.renameSync(tempPath, binaryPath);
|
|
81
|
-
|
|
82
|
-
if (process.platform !== "win32") {
|
|
83
|
-
fs.chmodSync(binaryPath, 0o755);
|
|
84
|
-
}
|
|
85
|
-
|
|
73
|
+
|
|
74
|
+
const installDir = path.join(__dirname, "..", "vendor", info.target);
|
|
75
|
+
const binaryPath = path.join(installDir, info.exe);
|
|
76
|
+
const tempPath = `${binaryPath}.tmp`;
|
|
77
|
+
|
|
78
|
+
fs.mkdirSync(installDir, { recursive: true });
|
|
79
|
+
await downloadFile(url, tempPath);
|
|
80
|
+
fs.renameSync(tempPath, binaryPath);
|
|
81
|
+
|
|
82
|
+
if (process.platform !== "win32") {
|
|
83
|
+
fs.chmodSync(binaryPath, 0o755);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
86
|
console.log(`Installed claude-code-rust ${version} (${info.target})`);
|
|
87
87
|
}
|
|
88
88
|
|