Use OpenShell config home for host commands
This commit is contained in:
+47
-7
@@ -11,6 +11,11 @@ function unique(values: Array<string | undefined>) {
|
||||
return Array.from(new Set(values.filter((value): value is string => Boolean(value))))
|
||||
}
|
||||
|
||||
function inferHomeFromLocalBin(commandPath: string) {
|
||||
const suffix = "/.local/bin/openshell"
|
||||
return commandPath.endsWith(suffix) ? commandPath.slice(0, -suffix.length) : undefined
|
||||
}
|
||||
|
||||
function safeIsDirectory(candidate: string) {
|
||||
try {
|
||||
return statSync(candidate).isDirectory()
|
||||
@@ -51,11 +56,40 @@ function discoverHomeFiles(relativePath: string) {
|
||||
return found
|
||||
}
|
||||
|
||||
const OPENSHELL_BIN_CANDIDATES = unique([
|
||||
process.env.OPENSHELL_BIN,
|
||||
HOME ? path.join(HOME, ".local/bin/openshell") : undefined,
|
||||
"/opt/homebrew/bin/openshell",
|
||||
"/usr/local/bin/openshell",
|
||||
])
|
||||
|
||||
export const OPENSHELL_BIN = firstExisting(OPENSHELL_BIN_CANDIDATES, "openshell")
|
||||
|
||||
function homeWithOpenShellConfig(candidates: Array<string | undefined>) {
|
||||
return candidates
|
||||
.filter((value): value is string => Boolean(value))
|
||||
.find((candidate) => existsSync(path.join(candidate, ".config/openshell")))
|
||||
}
|
||||
|
||||
const INFERRED_OPENSHELL_HOME = inferHomeFromLocalBin(OPENSHELL_BIN)
|
||||
export const OPENSHELL_HOME = homeWithOpenShellConfig([
|
||||
process.env.OPENSHELL_HOME,
|
||||
HOME,
|
||||
INFERRED_OPENSHELL_HOME,
|
||||
]) || process.env.OPENSHELL_HOME || INFERRED_OPENSHELL_HOME || HOME
|
||||
|
||||
export const OPENSHELL_XDG_CONFIG_HOME = firstExisting([
|
||||
process.env.OPENSHELL_XDG_CONFIG_HOME,
|
||||
process.env.XDG_CONFIG_HOME && existsSync(path.join(process.env.XDG_CONFIG_HOME, "openshell")) ? process.env.XDG_CONFIG_HOME : undefined,
|
||||
OPENSHELL_HOME ? path.join(OPENSHELL_HOME, ".config") : undefined,
|
||||
], process.env.XDG_CONFIG_HOME || (OPENSHELL_HOME ? path.join(OPENSHELL_HOME, ".config") : ""))
|
||||
|
||||
function pathEntries() {
|
||||
return [
|
||||
process.env.TERMINAL_EXTRA_PATH,
|
||||
process.env.OPENSHELL_CONTROL_VENV ? path.join(process.env.OPENSHELL_CONTROL_VENV, "bin") : undefined,
|
||||
path.join(process.cwd(), ".venv/bin"),
|
||||
OPENSHELL_HOME ? path.join(OPENSHELL_HOME, ".local/bin") : undefined,
|
||||
HOME ? path.join(HOME, ".local/bin") : undefined,
|
||||
HOME ? path.join(HOME, ".nvm/versions/node/v22.22.2/bin") : undefined,
|
||||
HOME ? path.join(HOME, ".nvm/versions/node/v22.22.1/bin") : undefined,
|
||||
@@ -73,6 +107,19 @@ function pathEntries() {
|
||||
|
||||
export const HOST_PATH = unique(pathEntries()).join(":")
|
||||
|
||||
export function hostCommandEnv(extra: Record<string, string | undefined> = {}) {
|
||||
return {
|
||||
...process.env,
|
||||
...(OPENSHELL_HOME ? { HOME: OPENSHELL_HOME } : {}),
|
||||
...(OPENSHELL_XDG_CONFIG_HOME ? { XDG_CONFIG_HOME: OPENSHELL_XDG_CONFIG_HOME } : {}),
|
||||
PATH: HOST_PATH,
|
||||
NO_COLOR: "1",
|
||||
CLICOLOR: "0",
|
||||
CLICOLOR_FORCE: "0",
|
||||
...extra,
|
||||
}
|
||||
}
|
||||
|
||||
export const NODE_BIN = firstExisting([
|
||||
process.env.NODE_BIN,
|
||||
HOME ? path.join(HOME, ".nvm/versions/node/v22.22.2/bin/node") : undefined,
|
||||
@@ -82,13 +129,6 @@ export const NODE_BIN = firstExisting([
|
||||
"/usr/bin/node",
|
||||
], "node")
|
||||
|
||||
export const OPENSHELL_BIN = firstExisting([
|
||||
process.env.OPENSHELL_BIN,
|
||||
HOME ? path.join(HOME, ".local/bin/openshell") : undefined,
|
||||
"/opt/homebrew/bin/openshell",
|
||||
"/usr/local/bin/openshell",
|
||||
], "openshell")
|
||||
|
||||
export const OPENCLAW_BIN = firstExisting([
|
||||
process.env.OPENCLAW_BIN,
|
||||
HOME ? path.join(HOME, ".local/bin/openclaw") : undefined,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { execFile } from "node:child_process"
|
||||
import { promisify } from "node:util"
|
||||
import { HOST_PATH, OPENSHELL_BIN } from "./hostCommands"
|
||||
import { HOST_PATH, OPENSHELL_BIN, hostCommandEnv } from "./hostCommands"
|
||||
import { resolveSandboxRef } from "./openshellHost"
|
||||
|
||||
const execFileAsync = promisify(execFile)
|
||||
@@ -36,15 +36,10 @@ function normalizeProxyOrigin(value: string) {
|
||||
|
||||
async function runOpenShell(args: string[]) {
|
||||
const { stdout } = await execFileAsync(OPENSHELL_BIN, args, {
|
||||
env: {
|
||||
...process.env,
|
||||
PATH: HOST_PATH,
|
||||
env: hostCommandEnv({
|
||||
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw",
|
||||
NO_COLOR: "1",
|
||||
CLICOLOR: "0",
|
||||
CLICOLOR_FORCE: "0",
|
||||
TERM: "dumb",
|
||||
},
|
||||
}),
|
||||
timeout: 15000,
|
||||
maxBuffer: 1024 * 1024,
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { execFile, spawn } from "node:child_process"
|
||||
import { promisify } from "node:util"
|
||||
import { HOST_PATH, OPENCLAW_BIN, OPENSHELL_BIN } from "./hostCommands"
|
||||
import { HOST_PATH, OPENCLAW_BIN, OPENSHELL_BIN, hostCommandEnv } from "./hostCommands"
|
||||
import { getDefaultOpenClawInstance, getOpenClawDashboardPortForSandbox, resolveOpenClawInstance } from "./openclawInstances"
|
||||
|
||||
const execFileAsync = promisify(execFile)
|
||||
@@ -44,13 +44,7 @@ export type DashboardProbe = {
|
||||
|
||||
export async function execOpenShell(args: string[]) {
|
||||
const { stdout, stderr } = await execFileAsync(OPENSHELL_BIN, args, {
|
||||
env: {
|
||||
...process.env,
|
||||
PATH: HOST_PATH,
|
||||
NO_COLOR: "1",
|
||||
CLICOLOR: "0",
|
||||
CLICOLOR_FORCE: "0",
|
||||
},
|
||||
env: hostCommandEnv(),
|
||||
})
|
||||
return { stdout, stderr }
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { spawn } from "node:child_process"
|
||||
import path from "node:path"
|
||||
import { HOST_PATH, OPENSHELL_BIN } from "./hostCommands"
|
||||
import { OPENSHELL_BIN, hostCommandEnv } from "./hostCommands"
|
||||
import { resolveSandboxRef } from "./openshellHost"
|
||||
|
||||
export const MAX_FILE_BYTES = Number.parseInt(process.env.SANDBOX_FILE_TRANSFER_MAX_BYTES || String(128 * 1024 * 1024), 10)
|
||||
@@ -58,14 +58,9 @@ export function assertRequestContentLength(request: Request, maxBytes = MAX_MULT
|
||||
function runSandboxExec(sandboxName: string, script: string, input?: Buffer, timeoutMs = 60000) {
|
||||
return new Promise<{ stdout: Buffer; stderr: string; code: number | null }>((resolve, reject) => {
|
||||
const child = spawn(OPENSHELL_BIN, ["sandbox", "exec", "-n", sandboxName, "--", "sh", "-lc", script], {
|
||||
env: {
|
||||
...process.env,
|
||||
PATH: HOST_PATH,
|
||||
env: hostCommandEnv({
|
||||
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw",
|
||||
NO_COLOR: "1",
|
||||
CLICOLOR: "0",
|
||||
CLICOLOR_FORCE: "0",
|
||||
},
|
||||
}),
|
||||
stdio: ["pipe", "pipe", "pipe"],
|
||||
})
|
||||
const stdout: Buffer[] = []
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { execFile, spawn } from "node:child_process"
|
||||
import { promisify } from "node:util"
|
||||
import { HOST_PATH, OPENSHELL_BIN } from "./hostCommands"
|
||||
import { HOST_PATH, OPENSHELL_BIN, hostCommandEnv } from "./hostCommands"
|
||||
import { getSandboxInferenceConfig, type SandboxInferenceRoute } from "./sandboxInferenceStore"
|
||||
|
||||
const execFileAsync = promisify(execFile)
|
||||
@@ -110,14 +110,9 @@ function buildOpenClawConfig(current: any, routes: SandboxInferenceRoute[], prim
|
||||
|
||||
async function runOpenShell(args: string[]) {
|
||||
const { stdout, stderr } = await execFileAsync(OPENSHELL_BIN, args, {
|
||||
env: {
|
||||
...process.env,
|
||||
PATH: HOST_PATH,
|
||||
env: hostCommandEnv({
|
||||
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw",
|
||||
NO_COLOR: "1",
|
||||
CLICOLOR: "0",
|
||||
CLICOLOR_FORCE: "0",
|
||||
},
|
||||
}),
|
||||
timeout: 60000,
|
||||
maxBuffer: 20 * 1024 * 1024,
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { execFile } from "node:child_process"
|
||||
import { promisify } from "node:util"
|
||||
import { HOST_PATH, OPENSHELL_BIN } from "./hostCommands"
|
||||
import { OPENSHELL_BIN, hostCommandEnv } from "./hostCommands"
|
||||
import { resolveSandboxRef } from "./openshellHost"
|
||||
|
||||
const execFileAsync = promisify(execFile)
|
||||
@@ -25,15 +25,10 @@ type BrokerNetworkAction = {
|
||||
|
||||
function runOpenShell(args: string[], timeout = 60000) {
|
||||
return execFileAsync(OPENSHELL_BIN, args, {
|
||||
env: {
|
||||
...process.env,
|
||||
PATH: HOST_PATH,
|
||||
env: hostCommandEnv({
|
||||
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw",
|
||||
NO_COLOR: "1",
|
||||
CLICOLOR: "0",
|
||||
CLICOLOR_FORCE: "0",
|
||||
TERM: "dumb",
|
||||
},
|
||||
}),
|
||||
timeout,
|
||||
maxBuffer: 10 * 1024 * 1024,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user