bl4ze 0.2.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.
Files changed (3) hide show
  1. package/bin/bl4ze +8 -0
  2. package/install.cjs +96 -0
  3. package/package.json +15 -0
package/bin/bl4ze ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ /* Placeholder replaced by install.cjs with the real binary.
3
+ * If you are seeing this message the postinstall step did not run. */
4
+ console.error(
5
+ "bl4ze: the binary was not downloaded.\n" +
6
+ "Run `npm rebuild bl4ze`, or install from source: https://bl4ze.net/install.html"
7
+ );
8
+ process.exit(1);
package/install.cjs ADDED
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env node
2
+ /* Fetch the binary for this platform.
3
+ *
4
+ * The published package is a stub: it carries no program, only the few lines
5
+ * needed to download the right build. That keeps the package small and, more
6
+ * to the point, keeps the source out of the registry -- npm ships what is in
7
+ * the tarball, and the tarball is this file.
8
+ *
9
+ * The download is verified against a checksum published alongside it. Without
10
+ * that, `npm install` would run whatever the host happened to return.
11
+ */
12
+ "use strict";
13
+
14
+ const fs = require("fs");
15
+ const os = require("os");
16
+ const path = require("path");
17
+ const https = require("https");
18
+ const crypto = require("crypto");
19
+ const zlib = require("zlib");
20
+ const { execFileSync } = require("child_process");
21
+
22
+ const VERSION = require("./package.json").version;
23
+ const BASE = process.env.BL4ZE_DOWNLOAD_BASE || "https://dl.bl4ze.net";
24
+
25
+ const PLATFORMS = { darwin: "darwin", linux: "linux" };
26
+ const ARCHS = { x64: "x64", arm64: "arm64" };
27
+
28
+ function target() {
29
+ const p = PLATFORMS[os.platform()];
30
+ const a = ARCHS[os.arch()];
31
+ if (!p || !a) {
32
+ throw new Error(
33
+ `bl4ze has no build for ${os.platform()}/${os.arch()}.\n` +
34
+ `Install from source instead: https://bl4ze.net/install.html`
35
+ );
36
+ }
37
+ return `bl4ze-${VERSION}-${p}-${a}.tar.gz`;
38
+ }
39
+
40
+ function get(url, redirects = 0) {
41
+ return new Promise((resolve, reject) => {
42
+ if (redirects > 5) return reject(new Error("too many redirects"));
43
+ https.get(url, (res) => {
44
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
45
+ res.resume();
46
+ return resolve(get(new URL(res.headers.location, url).toString(), redirects + 1));
47
+ }
48
+ if (res.statusCode !== 200) {
49
+ res.resume();
50
+ return reject(new Error(`${url} returned HTTP ${res.statusCode}`));
51
+ }
52
+ const chunks = [];
53
+ res.on("data", (c) => chunks.push(c));
54
+ res.on("end", () => resolve(Buffer.concat(chunks)));
55
+ res.on("error", reject);
56
+ }).on("error", reject);
57
+ });
58
+ }
59
+
60
+ async function main() {
61
+ const name = target();
62
+ const binDir = path.join(__dirname, "bin");
63
+ fs.mkdirSync(binDir, { recursive: true });
64
+
65
+ process.stderr.write(`bl4ze: fetching ${name}\n`);
66
+ const [archive, sums] = await Promise.all([
67
+ get(`${BASE}/${VERSION}/${name}`),
68
+ get(`${BASE}/${VERSION}/SHA256SUMS`),
69
+ ]);
70
+
71
+ // Verify before unpacking, not after: an unverified archive should never
72
+ // reach the filesystem as an executable.
73
+ const expected = sums.toString("utf8").split("\n")
74
+ .map((line) => line.trim().split(/\s+/))
75
+ .find((parts) => parts[1] === name);
76
+ if (!expected) throw new Error(`no checksum published for ${name}`);
77
+
78
+ const actual = crypto.createHash("sha256").update(archive).digest("hex");
79
+ if (actual !== expected[0]) {
80
+ throw new Error(
81
+ `checksum mismatch for ${name}\n expected ${expected[0]}\n got ${actual}`
82
+ );
83
+ }
84
+
85
+ const tarPath = path.join(binDir, "bl4ze.tar.gz");
86
+ fs.writeFileSync(tarPath, archive);
87
+ execFileSync("tar", ["-xzf", tarPath, "-C", binDir]);
88
+ fs.unlinkSync(tarPath);
89
+ fs.chmodSync(path.join(binDir, "bl4ze"), 0o755);
90
+ process.stderr.write("bl4ze: installed\n");
91
+ }
92
+
93
+ main().catch((error) => {
94
+ process.stderr.write(`\nbl4ze: install failed — ${error.message}\n\n`);
95
+ process.exit(1);
96
+ });
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "bl4ze",
3
+ "version": "0.2.0",
4
+ "description": "A terminal coding agent that runs unattended, with a remote console you can drive from your phone.",
5
+ "keywords": ["ai", "agent", "cli", "terminal", "coding-agent"],
6
+ "license": "MIT",
7
+ "homepage": "https://bl4ze.net",
8
+ "bin": { "bl4ze": "bin/bl4ze" },
9
+ "files": ["bin/bl4ze", "install.cjs", "README.md"],
10
+ "scripts": { "postinstall": "node install.cjs" },
11
+ "engines": { "node": ">=16" },
12
+ "dependencies": {},
13
+ "os": ["darwin", "linux"],
14
+ "cpu": ["x64", "arm64"]
15
+ }