@arcmantle/agent-wayfinder 0.1.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/bin/agent-wayfinder.js +15 -0
- package/package.json +36 -0
- package/scripts/install.js +89 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawnSync } = require("node:child_process");
|
|
4
|
+
const path = require("node:path");
|
|
5
|
+
|
|
6
|
+
const binaryName = process.platform === "win32" ? "agent-wayfinder.exe" : "agent-wayfinder";
|
|
7
|
+
const binaryPath = path.join(__dirname, binaryName);
|
|
8
|
+
const result = spawnSync(binaryPath, process.argv.slice(2), { stdio: "inherit" });
|
|
9
|
+
|
|
10
|
+
if (result.error) {
|
|
11
|
+
console.error(`agent-wayfinder could not start: ${result.error.message}`);
|
|
12
|
+
process.exitCode = 1;
|
|
13
|
+
} else {
|
|
14
|
+
process.exitCode = result.status ?? 1;
|
|
15
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@arcmantle/agent-wayfinder",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Install and run the agent-wayfinder code graph CLI.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"agent-wayfinder": "bin/agent-wayfinder.js",
|
|
7
|
+
"a-wayfinder": "bin/agent-wayfinder.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin/agent-wayfinder.js",
|
|
11
|
+
"scripts/install.js"
|
|
12
|
+
],
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=18"
|
|
15
|
+
},
|
|
16
|
+
"os": [
|
|
17
|
+
"darwin",
|
|
18
|
+
"linux",
|
|
19
|
+
"win32"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"postinstall": "node scripts/install.js",
|
|
23
|
+
"test": "node --test"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/arcmantle/agent-wayfinder.git"
|
|
28
|
+
},
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/arcmantle/agent-wayfinder/issues"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/arcmantle/agent-wayfinder#readme",
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
const crypto = require("node:crypto");
|
|
2
|
+
const fs = require("node:fs");
|
|
3
|
+
const https = require("node:https");
|
|
4
|
+
const path = require("node:path");
|
|
5
|
+
const zlib = require("node:zlib");
|
|
6
|
+
|
|
7
|
+
const releaseBaseURL = "https://github.com/arcmantle/agent-wayfinder/releases/download";
|
|
8
|
+
|
|
9
|
+
function platformAsset(platform = process.platform, architecture = process.arch) {
|
|
10
|
+
const supported = {
|
|
11
|
+
darwin: new Set(["arm64"]),
|
|
12
|
+
linux: new Set(["x64"]),
|
|
13
|
+
win32: new Set(["x64"])
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
if (!supported[platform] || !supported[platform].has(architecture)) {
|
|
17
|
+
throw new Error(`Unsupported platform: ${platform}-${architecture}`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return `agent-wayfinder-${platform}-${architecture}.gz`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function download(url, redirects = 0) {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
const request = https.get(url, { headers: { "user-agent": "agent-wayfinder-npm-installer" } }, response => {
|
|
26
|
+
if (response.statusCode >= 300 && response.statusCode < 400 && response.headers.location) {
|
|
27
|
+
response.resume();
|
|
28
|
+
if (redirects === 5) {
|
|
29
|
+
reject(new Error(`Too many redirects while downloading ${url}`));
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
resolve(download(new URL(response.headers.location, url).toString(), redirects + 1));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (response.statusCode !== 200) {
|
|
37
|
+
response.resume();
|
|
38
|
+
reject(new Error(`Download failed with HTTP ${response.statusCode}: ${url}`));
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const chunks = [];
|
|
43
|
+
response.on("data", chunk => chunks.push(chunk));
|
|
44
|
+
response.on("end", () => resolve(Buffer.concat(chunks)));
|
|
45
|
+
response.on("error", reject);
|
|
46
|
+
});
|
|
47
|
+
request.on("error", reject);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function expectedChecksum(checksums, assetName) {
|
|
52
|
+
for (const line of checksums.toString("utf8").split("\n")) {
|
|
53
|
+
const match = line.match(/^([a-f0-9]{64})\s+\*?(.+)$/i);
|
|
54
|
+
if (match && match[2] === assetName) {
|
|
55
|
+
return match[1].toLowerCase();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
throw new Error(`Release checksums do not contain ${assetName}`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function install() {
|
|
62
|
+
const packageDirectory = path.resolve(__dirname, "..");
|
|
63
|
+
const packageInfo = JSON.parse(fs.readFileSync(path.join(packageDirectory, "package.json"), "utf8"));
|
|
64
|
+
const assetName = platformAsset();
|
|
65
|
+
const releaseURL = `${releaseBaseURL}/v${packageInfo.version}`;
|
|
66
|
+
const [compressedBinary, checksums] = await Promise.all([
|
|
67
|
+
download(`${releaseURL}/${assetName}`),
|
|
68
|
+
download(`${releaseURL}/SHA256SUMS`)
|
|
69
|
+
]);
|
|
70
|
+
const expected = expectedChecksum(checksums, assetName);
|
|
71
|
+
const actual = crypto.createHash("sha256").update(compressedBinary).digest("hex");
|
|
72
|
+
if (actual !== expected) {
|
|
73
|
+
throw new Error(`Checksum mismatch for ${assetName}`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const binaryName = process.platform === "win32" ? "agent-wayfinder.exe" : "agent-wayfinder";
|
|
77
|
+
const binaryPath = path.join(packageDirectory, "bin", binaryName);
|
|
78
|
+
fs.writeFileSync(binaryPath, zlib.gunzipSync(compressedBinary), { mode: 0o755 });
|
|
79
|
+
fs.chmodSync(binaryPath, 0o755);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (require.main === module) {
|
|
83
|
+
install().catch(error => {
|
|
84
|
+
console.error(`agent-wayfinder installation failed: ${error.message}`);
|
|
85
|
+
process.exitCode = 1;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
module.exports = { expectedChecksum, platformAsset };
|