Relay: force app to run relay via system node
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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<RuntimeResolution, RuntimeResolutionError> {
|
||||
static func runtimeResolution() -> Result<RuntimeResolution, RuntimeResolutionError> {
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user