crabot 0.1.2 → 0.1.4
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 +10 -5
- package/bin/crabot.mjs +2 -2
- package/package.json +3 -3
- package/scripts/install.mjs +73 -17
package/README.md
CHANGED
|
@@ -5,14 +5,19 @@ Local-first AI agent runtime with a gateway, operator console, and CLI.
|
|
|
5
5
|
## Requirements
|
|
6
6
|
|
|
7
7
|
`crabot` runs as a self-contained standalone binary with the runtime embedded —
|
|
8
|
-
the program itself needs no Bun or Node install.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
the
|
|
12
|
-
|
|
8
|
+
the program itself needs no Bun or Node install. The package ships no install
|
|
9
|
+
script; on the first `crabot` run a small launcher (running under the Node that
|
|
10
|
+
npm already provides) downloads the prebuilt binary matching your platform from
|
|
11
|
+
the matching GitHub release, verifies its checksum, unpacks it (the asset is
|
|
12
|
+
zstd-compressed — ~16 MB to download vs ~63 MB on disk), and caches it for later
|
|
13
|
+
runs. Unpacking uses `node:zlib`, so the launcher needs **Node ≥ 22.15**.
|
|
13
14
|
|
|
14
15
|
Supported platforms: Linux (x64, arm64), macOS (x64, arm64), Windows (x64).
|
|
15
16
|
|
|
17
|
+
If you are on an older Node, download the standalone binary for your platform
|
|
18
|
+
directly from the [GitHub releases](https://github.com/gotry-io/Crabot/releases)
|
|
19
|
+
(decompress the `.zst` asset) and put it on your `PATH` — it needs no Node.
|
|
20
|
+
|
|
16
21
|
## Install
|
|
17
22
|
|
|
18
23
|
```sh
|
package/bin/crabot.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Launcher for the `crabot` distribution. The real program is a standalone executable (the Bun
|
|
3
|
-
// runtime is embedded) downloaded from the matching GitHub release
|
|
4
|
-
//
|
|
3
|
+
// runtime is embedded) downloaded from the matching GitHub release lazily here on first run (the
|
|
4
|
+
// package ships no install script). No Bun or Node runtime is required to run crabot.
|
|
5
5
|
import { spawn } from "node:child_process";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { ensureBinary } from "../scripts/install.mjs";
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "crabot",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Local-first AI agent runtime with a gateway, operator console, and CLI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"crabot": "bin/crabot.mjs"
|
|
8
8
|
},
|
|
9
|
-
"
|
|
10
|
-
"
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=22.15.0"
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
13
|
"bin",
|
package/scripts/install.mjs
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Downloads the crabot standalone binary for the host platform from the GitHub release that matches
|
|
3
|
-
// this package's version, verifies its SHA-256, and caches it.
|
|
4
|
-
//
|
|
5
|
-
//
|
|
3
|
+
// this package's version, verifies its SHA-256, decompresses it, and caches it. Invoked by the
|
|
4
|
+
// launcher on first run when the binary is not cached yet; the package ships no install script, so
|
|
5
|
+
// nothing runs at install time. The release asset is zstd-compressed (the binary is ~63 MB raw but
|
|
6
|
+
// ~16 MB compressed), so the launcher's Node must provide node:zlib zstd (Node >= 22.15, per the
|
|
7
|
+
// package `engines`). The binary itself embeds the Bun runtime, so running crabot needs no runtime.
|
|
6
8
|
import { createHash } from "node:crypto";
|
|
7
9
|
import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
8
10
|
import { homedir } from "node:os";
|
|
9
11
|
import { dirname, join } from "node:path";
|
|
10
12
|
import { fileURLToPath } from "node:url";
|
|
13
|
+
import zlib from "node:zlib";
|
|
11
14
|
|
|
12
15
|
const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
13
16
|
const { version } = JSON.parse(readFileSync(join(packageRoot, "package.json"), "utf8"));
|
|
@@ -39,6 +42,56 @@ async function fetchBuffer(url) {
|
|
|
39
42
|
return Buffer.from(await response.arrayBuffer());
|
|
40
43
|
}
|
|
41
44
|
|
|
45
|
+
function formatDownloadProgress(received, total) {
|
|
46
|
+
const mb = (bytes) => (bytes / 1_048_576).toFixed(1);
|
|
47
|
+
return total > 0
|
|
48
|
+
? `${Math.floor((received / total) * 100)}% (${mb(received)}/${mb(total)} MB)`
|
|
49
|
+
: `${mb(received)} MB`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Fetch a URL while reporting progress to stderr: one in-place updating line on a TTY, or milestone
|
|
53
|
+
// lines (every 20%) when output is redirected. The binary is the only large download, so only it
|
|
54
|
+
// streams; the size only grows, so the TTY line never leaves stale characters behind.
|
|
55
|
+
async function downloadWithProgress(url, label) {
|
|
56
|
+
const response = await fetch(url, { redirect: "follow" });
|
|
57
|
+
if (!response.ok) {
|
|
58
|
+
throw new Error(`request failed (${response.status}) for ${url}`);
|
|
59
|
+
}
|
|
60
|
+
if (response.body === null) {
|
|
61
|
+
return Buffer.from(await response.arrayBuffer());
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const total = Number(response.headers.get("content-length")) || 0;
|
|
65
|
+
const isTty = process.stderr.isTTY === true;
|
|
66
|
+
const reader = response.body.getReader();
|
|
67
|
+
const chunks = [];
|
|
68
|
+
let received = 0;
|
|
69
|
+
let nextMilestone = 0;
|
|
70
|
+
for (;;) {
|
|
71
|
+
const { done, value } = await reader.read();
|
|
72
|
+
if (done) {
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
chunks.push(value);
|
|
77
|
+
received += value.length;
|
|
78
|
+
if (isTty) {
|
|
79
|
+
process.stderr.write(`\rcrabot: downloading ${label} ${formatDownloadProgress(received, total)}`);
|
|
80
|
+
} else if (total > 0 && (received / total) * 100 >= nextMilestone) {
|
|
81
|
+
process.stderr.write(`crabot: downloading ${label} ${formatDownloadProgress(received, total)}\n`);
|
|
82
|
+
nextMilestone += 20;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (isTty) {
|
|
87
|
+
process.stderr.write("\n");
|
|
88
|
+
} else if (total === 0) {
|
|
89
|
+
process.stderr.write(`crabot: downloaded ${label} (${formatDownloadProgress(received, total)})\n`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return Buffer.concat(chunks);
|
|
93
|
+
}
|
|
94
|
+
|
|
42
95
|
export async function ensureBinary() {
|
|
43
96
|
const target = cachedBinaryPath();
|
|
44
97
|
if (existsSync(target)) {
|
|
@@ -51,19 +104,30 @@ export async function ensureBinary() {
|
|
|
51
104
|
throw new Error(`crabot: no prebuilt binary for ${key}. See https://github.com/${repository}/releases`);
|
|
52
105
|
}
|
|
53
106
|
|
|
107
|
+
if (typeof zlib.zstdDecompressSync !== "function") {
|
|
108
|
+
throw new Error(
|
|
109
|
+
`crabot: the prebuilt binary is zstd-compressed and needs Node >= 22.15 to unpack (this is ` +
|
|
110
|
+
`${process.version}). Upgrade Node, or download the standalone binary for your platform from ` +
|
|
111
|
+
`https://github.com/${repository}/releases and put it on your PATH.`
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
54
115
|
const base = `https://github.com/${repository}/releases/download/v${version}`;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
fetchBuffer(`${base}/${asset}`)
|
|
58
|
-
fetchBuffer(`${base}/${asset}.sha256`).then((buffer) => buffer.toString("utf8"))
|
|
116
|
+
const [compressed, checksum] = await Promise.all([
|
|
117
|
+
downloadWithProgress(`${base}/${asset}.zst`, `${asset} (v${version})`),
|
|
118
|
+
fetchBuffer(`${base}/${asset}.zst.sha256`).then((buffer) => buffer.toString("utf8"))
|
|
59
119
|
]);
|
|
60
120
|
|
|
121
|
+
// Verify the bytes that crossed the network, then decompress (zstd's frame checksum transitively
|
|
122
|
+
// integrity-checks the result).
|
|
61
123
|
const expected = checksum.trim().split(/\s+/u)[0];
|
|
62
|
-
const actual = createHash("sha256").update(
|
|
124
|
+
const actual = createHash("sha256").update(compressed).digest("hex");
|
|
63
125
|
if (expected !== actual) {
|
|
64
|
-
throw new Error(`crabot: checksum mismatch for ${asset} (expected ${expected}, got ${actual})`);
|
|
126
|
+
throw new Error(`crabot: checksum mismatch for ${asset}.zst (expected ${expected}, got ${actual})`);
|
|
65
127
|
}
|
|
66
128
|
|
|
129
|
+
const binary = zlib.zstdDecompressSync(compressed);
|
|
130
|
+
|
|
67
131
|
mkdirSync(dirname(target), { recursive: true });
|
|
68
132
|
// Write to a sibling temp file then rename, so a concurrent install never sees a partial binary.
|
|
69
133
|
const temporary = `${target}.${process.pid}.download`;
|
|
@@ -74,11 +138,3 @@ export async function ensureBinary() {
|
|
|
74
138
|
renameSync(temporary, target);
|
|
75
139
|
return target;
|
|
76
140
|
}
|
|
77
|
-
|
|
78
|
-
if (process.argv[1] !== undefined && fileURLToPath(import.meta.url) === process.argv[1]) {
|
|
79
|
-
// postinstall: pre-warm the cache but never fail the install; the launcher retries on first run.
|
|
80
|
-
ensureBinary().then(
|
|
81
|
-
(path) => process.stdout.write(`crabot: ready at ${path}\n`),
|
|
82
|
-
(error) => process.stderr.write(`crabot: will download on first run (${error.message})\n`)
|
|
83
|
-
);
|
|
84
|
-
}
|