From 2ebad55a59732b76da8a8f24d43d160ec47ce4c3 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 9 Dec 2025 04:36:05 +0000 Subject: [PATCH] Relay: force app to run relay via system node --- .../Sources/Clawdis/RelayProcessManager.swift | 25 +++++++++++++------ apps/macos/Sources/Clawdis/Utilities.swift | 10 ++++---- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/apps/macos/Sources/Clawdis/RelayProcessManager.swift b/apps/macos/Sources/Clawdis/RelayProcessManager.swift index c57235b03..4e8802b42 100644 --- a/apps/macos/Sources/Clawdis/RelayProcessManager.swift +++ b/apps/macos/Sources/Clawdis/RelayProcessManager.swift @@ -193,15 +193,26 @@ final class RelayProcessManager: ObservableObject { } private func resolveCommand() -> [String] { - // Keep it simple: rely on a system-installed clawdis binary. - // Default to `clawdis relay`; users can provide an override via env if needed. - if let override = ProcessInfo.processInfo.environment["CLAWDIS_RELAY_CMD"], - !override.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty - { - return override.split(separator: " ").map(String.init) + // Force the app-managed relay to use system Node (no bundled runtime, no bun). + let runtimeResult = CommandResolver.runtimeResolution() + guard case let .success(runtime) = runtimeResult else { + if case let .failure(err) = runtimeResult { + return CommandResolver.runtimeErrorCommand(err) + } + return ["/bin/sh", "-c", "echo 'runtime resolution failed' >&2; exit 1"] } - return CommandResolver.clawdisCommand(subcommand: "relay") + let relayRoot = CommandResolver.projectRoot() + if let entry = CommandResolver.relayEntrypoint(in: relayRoot) { + return CommandResolver.makeRuntimeCommand( + runtime: runtime, + entrypoint: entry, + subcommand: "relay", + extraArgs: []) + } + + return CommandResolver.errorCommand( + with: "clawdis entrypoint missing (looked for dist/index.js or bin/clawdis.js); run pnpm build.") } private func makeEnvironment() -> Environment { diff --git a/apps/macos/Sources/Clawdis/Utilities.swift b/apps/macos/Sources/Clawdis/Utilities.swift index ae8c06571..bc48434be 100644 --- a/apps/macos/Sources/Clawdis/Utilities.swift +++ b/apps/macos/Sources/Clawdis/Utilities.swift @@ -207,7 +207,7 @@ enum CommandResolver { return FileManager.default.fileExists(atPath: relay.path) ? relay : nil } - private static func relayEntrypoint(in root: URL) -> String? { + static func relayEntrypoint(in root: URL) -> String? { let distEntry = root.appendingPathComponent("dist/index.js").path if FileManager.default.isReadableFile(atPath: distEntry) { return distEntry } let binEntry = root.appendingPathComponent("bin/clawdis.js").path @@ -215,11 +215,11 @@ enum CommandResolver { return nil } - private static func runtimeResolution() -> Result { + static func runtimeResolution() -> Result { RuntimeLocator.resolve(searchPaths: self.preferredPaths()) } - private static func makeRuntimeCommand( + static func makeRuntimeCommand( runtime: RuntimeResolution, entrypoint: String, subcommand: String, @@ -228,12 +228,12 @@ enum CommandResolver { [runtime.path, entrypoint, subcommand] + extraArgs } - private static func runtimeErrorCommand(_ error: RuntimeResolutionError) -> [String] { + static func runtimeErrorCommand(_ error: RuntimeResolutionError) -> [String] { let message = RuntimeLocator.describeFailure(error) return self.errorCommand(with: message) } - private static func errorCommand(with message: String) -> [String] { + static func errorCommand(with message: String) -> [String] { let script = """ cat <<'__CLAWDIS_ERR__' >&2 \(message)