crabot 0.1.0 → 0.1.2

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,17 +4,30 @@ Local-first AI agent runtime with a gateway, operator console, and CLI.
4
4
 
5
5
  ## Requirements
6
6
 
7
- Crabot runs on the [Bun](https://bun.sh) runtime (>= 1.3.10). Bun must be
8
- installed and available on your `PATH`.
7
+ `crabot` runs as a self-contained standalone binary with the runtime embedded —
8
+ the program itself needs no Bun or Node install. On install, the package
9
+ downloads the prebuilt binary matching your platform from the matching GitHub
10
+ release and caches it; a small launcher hands off to it (the launcher runs under
11
+ the Node that npm already provides). If the download is skipped at install time,
12
+ it happens automatically on first run.
13
+
14
+ Supported platforms: Linux (x64, arm64), macOS (x64, arm64), Windows (x64).
9
15
 
10
16
  ## Install
11
17
 
12
18
  ```sh
19
+ npm install -g crabot
20
+ # or with bun
13
21
  bun install -g crabot
14
- # or run it once without installing
15
- bunx crabot update status
22
+ # run once without installing
23
+ npx crabot update status
16
24
  ```
17
25
 
26
+ For an install that fetches nothing, download the standalone binary for your
27
+ platform directly from the
28
+ [GitHub releases](https://github.com/gotry-io/Crabot/releases) and put it on
29
+ your `PATH`.
30
+
18
31
  ## Usage
19
32
 
20
33
  ```sh
package/bin/crabot.mjs ADDED
@@ -0,0 +1,57 @@
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 by the postinstall hook, or
4
+ // lazily here on first run if that was skipped. No Bun or Node runtime is required to run crabot.
5
+ import { spawn } from "node:child_process";
6
+ import { fileURLToPath } from "node:url";
7
+ import { ensureBinary } from "../scripts/install.mjs";
8
+
9
+ let binaryPath;
10
+ try {
11
+ binaryPath = await ensureBinary();
12
+ } catch (error) {
13
+ process.stderr.write(`${error.message}\n`);
14
+ process.exit(1);
15
+ }
16
+
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
+ });
29
+
30
+ // Forward termination signals so `crabot serve` shuts the gateway down gracefully when a process
31
+ // manager signals this wrapper. Unsupported signal names throw on registration; ignore those.
32
+ for (const signal of ["SIGINT", "SIGTERM", "SIGHUP", "SIGQUIT", "SIGBREAK"]) {
33
+ try {
34
+ process.on(signal, () => {
35
+ if (child.exitCode === null) {
36
+ child.kill(signal);
37
+ }
38
+ });
39
+ } catch {
40
+ // signal not available on this platform
41
+ }
42
+ }
43
+
44
+ child.on("error", (error) => {
45
+ process.stderr.write(`crabot: failed to launch ${binaryPath}: ${error.message}\n`);
46
+ process.exit(1);
47
+ });
48
+
49
+ child.on("exit", (code, signal) => {
50
+ if (signal) {
51
+ // Re-raise the same signal so this wrapper reports the child's termination cause.
52
+ process.removeAllListeners();
53
+ process.kill(process.pid, signal);
54
+ return;
55
+ }
56
+ process.exit(code ?? 0);
57
+ });
package/package.json CHANGED
@@ -1,19 +1,20 @@
1
1
  {
2
2
  "name": "crabot",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Local-first AI agent runtime with a gateway, operator console, and CLI.",
5
5
  "type": "module",
6
6
  "bin": {
7
- "crabot": "dist/main.js"
7
+ "crabot": "bin/crabot.mjs"
8
+ },
9
+ "scripts": {
10
+ "postinstall": "node scripts/install.mjs"
8
11
  },
9
12
  "files": [
10
- "dist",
13
+ "bin",
14
+ "scripts",
11
15
  "README.md",
12
16
  "LICENSE"
13
17
  ],
14
- "engines": {
15
- "bun": ">=1.3.10"
16
- },
17
18
  "license": "MIT",
18
19
  "author": "Kyle",
19
20
  "homepage": "https://github.com/gotry-io/Crabot#readme",
@@ -29,7 +30,6 @@
29
30
  "agent",
30
31
  "ai",
31
32
  "automation",
32
- "cli",
33
- "bun"
33
+ "cli"
34
34
  ]
35
35
  }
@@ -0,0 +1,84 @@
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, and caches it. Run by the postinstall hook and
4
+ // lazily by the launcher if the binary is not present yet (e.g. install ran with --ignore-scripts).
5
+ // The binary embeds the Bun runtime, so running crabot needs no Bun or Node install.
6
+ import { createHash } from "node:crypto";
7
+ import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
8
+ import { homedir } from "node:os";
9
+ import { dirname, join } from "node:path";
10
+ import { fileURLToPath } from "node:url";
11
+
12
+ const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
13
+ const { version } = JSON.parse(readFileSync(join(packageRoot, "package.json"), "utf8"));
14
+ const repository = "gotry-io/Crabot";
15
+
16
+ // process.platform-process.arch -> GitHub release asset name.
17
+ const assets = {
18
+ "linux-x64": "crabot-linux-x64",
19
+ "linux-arm64": "crabot-linux-arm64",
20
+ "darwin-x64": "crabot-macos-x64",
21
+ "darwin-arm64": "crabot-macos-arm64",
22
+ "win32-x64": "crabot-windows-x64.exe"
23
+ };
24
+
25
+ function cachedBinaryPath() {
26
+ const base = process.platform === "win32"
27
+ ? process.env.LOCALAPPDATA || join(homedir(), "AppData", "Local")
28
+ : process.env.XDG_CACHE_HOME || join(homedir(), ".cache");
29
+ const name = process.platform === "win32" ? "crabot.exe" : "crabot";
30
+ return join(base, "crabot", `v${version}`, name);
31
+ }
32
+
33
+ async function fetchBuffer(url) {
34
+ const response = await fetch(url, { redirect: "follow" });
35
+ if (!response.ok) {
36
+ throw new Error(`request failed (${response.status}) for ${url}`);
37
+ }
38
+
39
+ return Buffer.from(await response.arrayBuffer());
40
+ }
41
+
42
+ export async function ensureBinary() {
43
+ const target = cachedBinaryPath();
44
+ if (existsSync(target)) {
45
+ return target;
46
+ }
47
+
48
+ const key = `${process.platform}-${process.arch}`;
49
+ const asset = assets[key];
50
+ if (asset === undefined) {
51
+ throw new Error(`crabot: no prebuilt binary for ${key}. See https://github.com/${repository}/releases`);
52
+ }
53
+
54
+ const base = `https://github.com/${repository}/releases/download/v${version}`;
55
+ process.stderr.write(`crabot: downloading ${asset} (v${version})...\n`);
56
+ const [binary, checksum] = await Promise.all([
57
+ fetchBuffer(`${base}/${asset}`),
58
+ fetchBuffer(`${base}/${asset}.sha256`).then((buffer) => buffer.toString("utf8"))
59
+ ]);
60
+
61
+ const expected = checksum.trim().split(/\s+/u)[0];
62
+ const actual = createHash("sha256").update(binary).digest("hex");
63
+ if (expected !== actual) {
64
+ throw new Error(`crabot: checksum mismatch for ${asset} (expected ${expected}, got ${actual})`);
65
+ }
66
+
67
+ mkdirSync(dirname(target), { recursive: true });
68
+ // Write to a sibling temp file then rename, so a concurrent install never sees a partial binary.
69
+ const temporary = `${target}.${process.pid}.download`;
70
+ writeFileSync(temporary, binary);
71
+ if (process.platform !== "win32") {
72
+ chmodSync(temporary, 0o755);
73
+ }
74
+ renameSync(temporary, target);
75
+ return target;
76
+ }
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
+ }