Runtime: drop bun support

This commit is contained in:
Peter Steinberger
2025-12-09 04:13:46 +00:00
parent 024a823c78
commit 39a0f54b0d
9 changed files with 58 additions and 128 deletions

View File

@@ -48,7 +48,7 @@ Only the Pi/Tau CLI is supported now; legacy Claude/Codex/Gemini paths have been
## Quick Start
Mac signing tip: set `SIGN_IDENTITY="Apple Development: Your Name (TEAMID)"` in your shell profile so `scripts/restart-mac.sh` signs with your cert (defaults to ad-hoc). Debug bundle ID remains `com.steipete.clawdis.debug`.
Runtime requirement: **Node ≥22.0.0 or Bun ≥1.3.0** (not bundled). The macOS app and CLI both use the host runtime; install via Homebrew or official installers before running `clawdis`.
Runtime requirement: **Node ≥22.0.0** (not bundled). The macOS app and CLI both use the host runtime; install via Homebrew or official installers before running `clawdis`.
```bash
# Install

View File

@@ -1,7 +1,6 @@
import Foundation
enum RuntimeKind: String {
case bun
case node
}
@@ -40,7 +39,7 @@ struct RuntimeResolution {
}
enum RuntimeResolutionError: Error {
case notFound(searchPaths: [String], preferred: String?)
case notFound(searchPaths: [String])
case unsupported(
kind: RuntimeKind,
found: RuntimeVersion,
@@ -52,80 +51,63 @@ enum RuntimeResolutionError: Error {
enum RuntimeLocator {
private static let minNode = RuntimeVersion(major: 22, minor: 0, patch: 0)
private static let minBun = RuntimeVersion(major: 1, minor: 3, patch: 0)
static func resolve(
preferred: String? = ProcessInfo.processInfo.environment["CLAWDIS_RUNTIME"],
searchPaths: [String] = CommandResolver.preferredPaths()) -> Result<RuntimeResolution, RuntimeResolutionError>
{
let order = self.runtimeOrder(preferred: preferred)
let pathEnv = searchPaths.joined(separator: ":")
let runtime: RuntimeKind = .node
for runtime in order {
guard let binary = findExecutable(named: runtime.binaryName, searchPaths: searchPaths) else { continue }
guard let rawVersion = readVersion(of: binary, pathEnv: pathEnv) else {
return .failure(.versionParse(
kind: runtime,
raw: "(unreadable)",
path: binary,
searchPaths: searchPaths))
}
guard let parsed = RuntimeVersion.from(string: rawVersion) else {
return .failure(.versionParse(kind: runtime, raw: rawVersion, path: binary, searchPaths: searchPaths))
}
let minimum = runtime == .bun ? self.minBun : self.minNode
guard parsed >= minimum else {
return .failure(.unsupported(
kind: runtime,
found: parsed,
required: minimum,
path: binary,
searchPaths: searchPaths))
}
return .success(RuntimeResolution(kind: runtime, path: binary, version: parsed))
guard let binary = findExecutable(named: runtime.binaryName, searchPaths: searchPaths) else {
return .failure(.notFound(searchPaths: searchPaths))
}
guard let rawVersion = readVersion(of: binary, pathEnv: pathEnv) else {
return .failure(.versionParse(
kind: runtime,
raw: "(unreadable)",
path: binary,
searchPaths: searchPaths))
}
guard let parsed = RuntimeVersion.from(string: rawVersion) else {
return .failure(.versionParse(kind: runtime, raw: rawVersion, path: binary, searchPaths: searchPaths))
}
guard parsed >= self.minNode else {
return .failure(.unsupported(
kind: runtime,
found: parsed,
required: self.minNode,
path: binary,
searchPaths: searchPaths))
}
return .failure(.notFound(searchPaths: searchPaths, preferred: preferred?.lowercased()))
return .success(RuntimeResolution(kind: runtime, path: binary, version: parsed))
}
static func describeFailure(_ error: RuntimeResolutionError) -> String {
switch error {
case let .notFound(searchPaths, preferred):
let preference = preferred?.isEmpty == false ? "CLAWDIS_RUNTIME=\(preferred!)" : "bun or node"
case let .notFound(searchPaths):
return [
"clawdis needs Node >=22.0.0 or Bun >=1.3.0 but found no runtime.",
"Tried preference: \(preference)",
"clawdis needs Node >=22.0.0 but found no runtime.",
"PATH searched: \(searchPaths.joined(separator: ":"))",
"Install Node: https://nodejs.org/en/download",
"Install Bun: https://bun.sh/docs/installation",
].joined(separator: "\n")
case let .unsupported(kind, found, required, path, searchPaths):
let fallbackRuntime = kind == .bun ? "node" : "bun"
return [
"Found \(kind.rawValue) \(found) at \(path) but need >= \(required).",
"PATH searched: \(searchPaths.joined(separator: ":"))",
"Upgrade \(kind.rawValue) or set CLAWDIS_RUNTIME=\(fallbackRuntime) to try the other runtime.",
"Upgrade Node and rerun clawdis.",
].joined(separator: "\n")
case let .versionParse(kind, raw, path, searchPaths):
return [
"Could not parse \(kind.rawValue) version output \"\(raw)\" from \(path).",
"PATH searched: \(searchPaths.joined(separator: ":"))",
"Try reinstalling or pinning a supported version (Node >=22.0.0, Bun >=1.3.0).",
"Try reinstalling or pinning a supported version (Node >=22.0.0).",
].joined(separator: "\n")
}
}
// MARK: - Internals
private static func runtimeOrder(preferred: String?) -> [RuntimeKind] {
let normalized = preferred?.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()
switch normalized {
case "bun": return [.bun]
case "node": return [.node]
default: return [.bun, .node]
}
}
private static func findExecutable(named name: String, searchPaths: [String]) -> String? {
let fm = FileManager.default
for dir in searchPaths {
@@ -159,5 +141,5 @@ enum RuntimeLocator {
}
extension RuntimeKind {
fileprivate var binaryName: String { self == .bun ? "bun" : "node" }
fileprivate var binaryName: String { "node" }
}

View File

@@ -216,9 +216,7 @@ enum CommandResolver {
}
private static func runtimeResolution() -> Result<RuntimeResolution, RuntimeResolutionError> {
RuntimeLocator.resolve(
preferred: ProcessInfo.processInfo.environment["CLAWDIS_RUNTIME"],
searchPaths: self.preferredPaths())
RuntimeLocator.resolve(searchPaths: self.preferredPaths())
}
private static func makeRuntimeCommand(
@@ -436,24 +434,18 @@ enum CommandResolver {
CLI="$(command -v clawdis)"
clawdis \(quotedArgs);
elif [ -n "${PRJ:-}" ] && [ -f "$PRJ/dist/index.js" ]; then
if command -v bun >/dev/null 2>&1; then
CLI="bun $PRJ/dist/index.js"
bun "$PRJ/dist/index.js" \(quotedArgs);
elif command -v node >/dev/null 2>&1; then
if command -v node >/dev/null 2>&1; then
CLI="node $PRJ/dist/index.js"
node "$PRJ/dist/index.js" \(quotedArgs);
else
echo "Node >=22 or Bun >=1.3 required on remote host"; exit 127;
echo "Node >=22 required on remote host"; exit 127;
fi
elif [ -n "${PRJ:-}" ] && [ -f "$PRJ/bin/clawdis.js" ]; then
if command -v bun >/dev/null 2>&1; then
CLI="bun $PRJ/bin/clawdis.js"
bun "$PRJ/bin/clawdis.js" \(quotedArgs);
elif command -v node >/dev/null 2>&1; then
if command -v node >/dev/null 2>&1; then
CLI="node $PRJ/bin/clawdis.js"
node "$PRJ/bin/clawdis.js" \(quotedArgs);
else
echo "Node >=22 or Bun >=1.3 required on remote host"; exit 127;
echo "Node >=22 required on remote host"; exit 127;
fi
elif command -v pnpm >/dev/null 2>&1; then
CLI="pnpm --silent clawdis"

View File

@@ -41,16 +41,6 @@ import Testing
try FileManager.default.setAttributes([.posixPermissions: 0o755], ofItemAtPath: nodePath.path)
try self.makeExec(at: scriptPath)
let previous = getenv("CLAWDIS_RUNTIME").flatMap { String(validatingCString: $0) }
setenv("CLAWDIS_RUNTIME", "node", 1)
defer {
if let previous {
setenv("CLAWDIS_RUNTIME", previous, 1)
} else {
unsetenv("CLAWDIS_RUNTIME")
}
}
let cmd = CommandResolver.clawdisCommand(subcommand: "rpc")
#expect(cmd.count >= 3)

View File

@@ -1,27 +0,0 @@
# Host Node/Bun runtime (mac app)
Date: 2025-12-08 · Owner: steipete · Scope: packaged mac app runtime
## What we require
- The mac menu-bar app no longer ships an embedded runtime. We expect **Node ≥22.0.0 or Bun ≥1.3.0** to be present on the host.
- The bundle still carries `dist/` output, production `node_modules/`, and the root `package.json`/`pnpm-lock.yaml` so we avoid on-device installs; we simply reuse the host runtime.
- Launchd jobs export a PATH that includes `/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/steipete/Library/pnpm` so Homebrew/PNPM installs are found even under the minimal launchd environment.
## Build/packaging flow
- Run `scripts/package-mac-app.sh`.
- Ensures deps via `pnpm install`, builds JS with `pnpm exec tsc`, then builds the Swift app.
- Stages `dist/`, production `node_modules`, and metadata into `Contents/Resources/Relay/` (no bundled bun binary).
- Prunes optional tooling and non-macOS sharp vendors; only `sharp-darwin-arm64` + `sharp-libvips-darwin-arm64` remain for size/signing.
- Architecture: **arm64 only**. Host runtime must also be arm64 or Rosetta-compatible.
## Runtime behavior
- `CommandResolver` picks the runtime via `CLAWDIS_RUNTIME` (`bun`/`node`) or defaults to Bun then Node; it enforces the version gates and prints a clear error (with PATH) if requirements are not met.
- Relay processes run inside the bundled relay directory so native deps resolve, but the runtime itself comes from the host.
## Testing the bundle
- After packaging: `cd dist/Clawdis.app/Contents/Resources/Relay && bun dist/index.js --help` **or** `node dist/index.js --help` should print CLI help. If you see a runtime error, install/upgrade Node or Bun on the host.
- If sharp fails to load, confirm the remaining `@img/sharp-darwin-arm64` + `@img/sharp-libvips-darwin-arm64` directories exist and are codesigned.
## Notes / limits
- Dev/CI continues to use pnpm + Node; the packaged app simply reuses the host runtime instead of embedding Bun.
- Missing or too-old runtimes will surface as an immediate CLI error with install hints; update the host rather than rebuilding the app.

View File

@@ -29,9 +29,9 @@ Run the Node-based Clawdis/clawdis relay as a direct child of the LSUIElement ap
- Add a small `RelayProcessManager` (Swift) that owns:
- `execution: Execution?` from `Swift Subprocess` to track the child.
- `start(config)` called when “Clawdis Active” flips ON:
- binary: host Node or Bun running the bundled relay under `Clawdis.app/Contents/Resources/Relay/`
- binary: host Node running the bundled relay under `Clawdis.app/Contents/Resources/Relay/`
- args: current clawdis entrypoint and flags
- cwd/env: point to `~/.clawdis` as today; inject the expanded PATH so Homebrew Node/Bun resolve under launchd
- cwd/env: point to `~/.clawdis` as today; inject the expanded PATH so Homebrew Node resolves under launchd
- output: stream stdout/stderr to `/tmp/clawdis-relay.log` (cap buffer via Subprocess OutputLimits)
- restart: optional linear/backoff restart if exit was non-zero and Active is still true
- `stop()` called when Active flips OFF or app terminates: cancel the execution and `waitUntilExit`.
@@ -41,7 +41,7 @@ Run the Node-based Clawdis/clawdis relay as a direct child of the LSUIElement ap
- Keep the existing `LaunchdManager` around so we can switch back if needed; the toggle can choose between launchd or child mode with a flag if we want both.
## Packaging and signing
- Bundle the relay payload (dist + production node_modules) under `Contents/Resources/Relay/`; rely on host Node ≥22 or Bun ≥1.3 instead of embedding a runtime.
- Bundle the relay payload (dist + production node_modules) under `Contents/Resources/Relay/`; rely on host Node ≥22 instead of embedding a runtime.
- Codesign native addons and dylibs inside the bundle; no nested runtime binary to sign now.
- Host runtime should not call TCC APIs directly; keep privileged work inside the app/XPC.
@@ -57,7 +57,7 @@ Run the Node-based Clawdis/clawdis relay as a direct child of the LSUIElement ap
## Open questions / follow-ups
- Do we need dual-mode (launchd for prod, child for dev)? If yes, gate via a setting or build flag.
- Embedding a runtime is off the table for now; we rely on host Node/Bun for size/simplicity. Revisit only if host PATH drift becomes painful.
- Embedding a runtime is off the table for now; we rely on host Node for size/simplicity. Revisit only if host PATH drift becomes painful.
- Do we want a tiny signed helper for rare TCC actions that cannot be brokered via XPC?
## Decision snapshot (current recommendation)

View File

@@ -114,7 +114,7 @@ rm -rf "$APP_ROOT/Contents/Resources/WebChat/vendor/pdfjs-dist/legacy"
RELAY_DIR="$APP_ROOT/Contents/Resources/Relay"
echo "🧰 Staging relay payload (dist + node_modules; expects system Node ≥22 or Bun ≥1.3)"
echo "🧰 Staging relay payload (dist + node_modules; expects system Node ≥22)"
rsync -a --delete --exclude "Clawdis.app" "$ROOT_DIR/dist/" "$RELAY_DIR/dist/"
cp "$ROOT_DIR/package.json" "$RELAY_DIR/"
cp "$ROOT_DIR/pnpm-lock.yaml" "$RELAY_DIR/"

View File

@@ -38,15 +38,22 @@ describe("runtime-guard", () => {
});
it("validates runtime thresholds", () => {
const bunOk: RuntimeDetails = {
kind: "bun",
version: "1.3.0",
execPath: "/usr/bin/bun",
const nodeOk: RuntimeDetails = {
kind: "node",
version: "22.0.0",
execPath: "/usr/bin/node",
pathEnv: "/usr/bin",
};
const bunOld: RuntimeDetails = { ...bunOk, version: "1.2.9" };
expect(runtimeSatisfies(bunOk)).toBe(true);
expect(runtimeSatisfies(bunOld)).toBe(false);
const nodeOld: RuntimeDetails = { ...nodeOk, version: "21.9.0" };
const unknown: RuntimeDetails = {
kind: "unknown",
version: null,
execPath: null,
pathEnv: "/usr/bin",
};
expect(runtimeSatisfies(nodeOk)).toBe(true);
expect(runtimeSatisfies(nodeOld)).toBe(false);
expect(runtimeSatisfies(unknown)).toBe(false);
});
it("throws via exit when runtime is too old", () => {

View File

@@ -2,7 +2,7 @@ import process from "node:process";
import { defaultRuntime, type RuntimeEnv } from "../runtime.js";
export type RuntimeKind = "node" | "bun" | "unknown";
export type RuntimeKind = "node" | "unknown";
type Semver = {
major: number;
@@ -11,7 +11,6 @@ type Semver = {
};
const MIN_NODE: Semver = { major: 22, minor: 0, patch: 0 };
const MIN_BUN: Semver = { major: 1, minor: 3, patch: 0 };
export type RuntimeDetails = {
kind: RuntimeKind;
@@ -42,17 +41,8 @@ export function isAtLeast(version: Semver | null, minimum: Semver): boolean {
}
export function detectRuntime(): RuntimeDetails {
const isBun = Boolean(process.versions?.bun);
const kind: RuntimeKind = isBun
? "bun"
: process.versions?.node
? "node"
: "unknown";
const bunVersion =
(globalThis as { Bun?: { version?: string } })?.Bun?.version ?? null;
const version = isBun
? (process.versions?.bun ?? bunVersion)
: (process.versions?.node ?? null);
const kind: RuntimeKind = process.versions?.node ? "node" : "unknown";
const version = process.versions?.node ?? null;
return {
kind,
@@ -64,7 +54,6 @@ export function detectRuntime(): RuntimeDetails {
export function runtimeSatisfies(details: RuntimeDetails): boolean {
const parsed = parseSemver(details.version);
if (details.kind === "bun") return isAtLeast(parsed, MIN_BUN);
if (details.kind === "node") return isAtLeast(parsed, MIN_NODE);
return false;
}
@@ -84,14 +73,11 @@ export function assertSupportedRuntime(
runtime.error(
[
"clawdis requires Node >=22.0.0 or Bun >=1.3.0.",
"clawdis requires Node >=22.0.0.",
`Detected: ${runtimeLabel} (exec: ${execLabel}).`,
`PATH searched: ${details.pathEnv}`,
"Install Node: https://nodejs.org/en/download",
"Install Bun: https://bun.sh/docs/installation",
details.kind === "bun"
? "Upgrade Bun or re-run with Node by setting CLAWDIS_RUNTIME=node."
: "Upgrade Node or re-run with Bun by setting CLAWDIS_RUNTIME=bun.",
"Upgrade Node and re-run clawdis.",
].join("\n"),
);
runtime.exit(1);