crabot 0.1.4 → 0.1.5

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 CHANGED
@@ -4,19 +4,16 @@ Local-first AI agent runtime with a gateway, operator console, and CLI.
4
4
 
5
5
  ## Requirements
6
6
 
7
- `crabot` runs as a self-contained standalone binary with the runtime embedded —
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**.
14
-
15
- Supported platforms: Linux (x64, arm64), macOS (x64, arm64), Windows (x64).
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.
7
+ `crabot` is a self-contained standalone binary with the runtime embedded — it
8
+ needs no Bun or Node install. The package bundles the binary directly (a small
9
+ Node launcher execs it), so installing it downloads nothing extra and runs no
10
+ install scripts.
11
+
12
+ **Currently macOS arm64 only.** Other platforms are not yet published; build
13
+ from source at [the repository](https://github.com/gotry-io/Crabot). A macOS
14
+ arm64 binary is also attached to each
15
+ [GitHub release](https://github.com/gotry-io/Crabot/releases) for direct
16
+ download.
20
17
 
21
18
  ## Install
22
19
 
package/bin/crabot.mjs CHANGED
@@ -1,31 +1,32 @@
1
1
  #!/usr/bin/env node
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 lazily here on first run (the
4
- // package ships no install script). No Bun or Node runtime is required to run crabot.
2
+ // Launcher for the `crabot` distribution. The macOS arm64 standalone binary (the Bun runtime is
3
+ // embedded) is bundled in this package under vendor/, so there is nothing to download and crabot
4
+ // needs no extra runtime. Only macOS arm64 is shipped today; other platforms build from source.
5
5
  import { spawn } from "node:child_process";
6
+ import { chmodSync } from "node:fs";
7
+ import { dirname, join } from "node:path";
6
8
  import { fileURLToPath } from "node:url";
7
- import { ensureBinary } from "../scripts/install.mjs";
8
9
 
9
- let binaryPath;
10
- try {
11
- binaryPath = await ensureBinary();
12
- } catch (error) {
13
- process.stderr.write(`${error.message}\n`);
10
+ if (process.platform !== "darwin" || process.arch !== "arm64") {
11
+ process.stderr.write(
12
+ `crabot currently ships only a macOS arm64 build (detected ${process.platform}-${process.arch}). ` +
13
+ `Build from source: https://github.com/gotry-io/Crabot\n`
14
+ );
14
15
  process.exit(1);
15
16
  }
16
17
 
17
- // The downloaded binary lives at a version-pinned cache path that `npm update` orphans, so its own
18
- // process.execPath is not a stable launch target. Expose the stable command that re-launches crabot —
19
- // this launcher under Node, which re-resolves the matching binary on demand so `crabot service
20
- // install` writes a service unit that survives upgrades. This launcher path is stable across upgrades
21
- // (npm replaces the package in place).
22
- const child = spawn(binaryPath, process.argv.slice(2), {
23
- stdio: "inherit",
24
- env: {
25
- ...process.env,
26
- CRABOT_LAUNCH_VECTOR: JSON.stringify([process.execPath, fileURLToPath(import.meta.url)])
27
- }
28
- });
18
+ const binaryPath = join(dirname(fileURLToPath(import.meta.url)), "..", "vendor", "crabot");
19
+
20
+ // npm does not reliably preserve the executable bit on bundled (non-bin) files, so set it before
21
+ // launching; ignore failures (already executable, or a read-only install spawn will surface a real
22
+ // problem).
23
+ try {
24
+ chmodSync(binaryPath, 0o755);
25
+ } catch {
26
+ // best effort
27
+ }
28
+
29
+ const child = spawn(binaryPath, process.argv.slice(2), { stdio: "inherit" });
29
30
 
30
31
  // Forward termination signals so `crabot serve` shuts the gateway down gracefully when a process
31
32
  // manager signals this wrapper. Unsupported signal names throw on registration; ignore those.
package/package.json CHANGED
@@ -1,17 +1,20 @@
1
1
  {
2
2
  "name": "crabot",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
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
- "engines": {
10
- "node": ">=22.15.0"
11
- },
9
+ "os": [
10
+ "darwin"
11
+ ],
12
+ "cpu": [
13
+ "arm64"
14
+ ],
12
15
  "files": [
13
16
  "bin",
14
- "scripts",
17
+ "vendor",
15
18
  "README.md",
16
19
  "LICENSE"
17
20
  ],
package/vendor/crabot ADDED
Binary file
@@ -1,140 +0,0 @@
1
- #!/usr/bin/env node
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, 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.
8
- import { createHash } from "node:crypto";
9
- import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
10
- import { homedir } from "node:os";
11
- import { dirname, join } from "node:path";
12
- import { fileURLToPath } from "node:url";
13
- import zlib from "node:zlib";
14
-
15
- const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
16
- const { version } = JSON.parse(readFileSync(join(packageRoot, "package.json"), "utf8"));
17
- const repository = "gotry-io/Crabot";
18
-
19
- // process.platform-process.arch -> GitHub release asset name.
20
- const assets = {
21
- "linux-x64": "crabot-linux-x64",
22
- "linux-arm64": "crabot-linux-arm64",
23
- "darwin-x64": "crabot-macos-x64",
24
- "darwin-arm64": "crabot-macos-arm64",
25
- "win32-x64": "crabot-windows-x64.exe"
26
- };
27
-
28
- function cachedBinaryPath() {
29
- const base = process.platform === "win32"
30
- ? process.env.LOCALAPPDATA || join(homedir(), "AppData", "Local")
31
- : process.env.XDG_CACHE_HOME || join(homedir(), ".cache");
32
- const name = process.platform === "win32" ? "crabot.exe" : "crabot";
33
- return join(base, "crabot", `v${version}`, name);
34
- }
35
-
36
- async function fetchBuffer(url) {
37
- const response = await fetch(url, { redirect: "follow" });
38
- if (!response.ok) {
39
- throw new Error(`request failed (${response.status}) for ${url}`);
40
- }
41
-
42
- return Buffer.from(await response.arrayBuffer());
43
- }
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
-
95
- export async function ensureBinary() {
96
- const target = cachedBinaryPath();
97
- if (existsSync(target)) {
98
- return target;
99
- }
100
-
101
- const key = `${process.platform}-${process.arch}`;
102
- const asset = assets[key];
103
- if (asset === undefined) {
104
- throw new Error(`crabot: no prebuilt binary for ${key}. See https://github.com/${repository}/releases`);
105
- }
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
-
115
- const base = `https://github.com/${repository}/releases/download/v${version}`;
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"))
119
- ]);
120
-
121
- // Verify the bytes that crossed the network, then decompress (zstd's frame checksum transitively
122
- // integrity-checks the result).
123
- const expected = checksum.trim().split(/\s+/u)[0];
124
- const actual = createHash("sha256").update(compressed).digest("hex");
125
- if (expected !== actual) {
126
- throw new Error(`crabot: checksum mismatch for ${asset}.zst (expected ${expected}, got ${actual})`);
127
- }
128
-
129
- const binary = zlib.zstdDecompressSync(compressed);
130
-
131
- mkdirSync(dirname(target), { recursive: true });
132
- // Write to a sibling temp file then rename, so a concurrent install never sees a partial binary.
133
- const temporary = `${target}.${process.pid}.download`;
134
- writeFileSync(temporary, binary);
135
- if (process.platform !== "win32") {
136
- chmodSync(temporary, 0o755);
137
- }
138
- renameSync(temporary, target);
139
- return target;
140
- }