Use current NemoClaw onboard flow for sandbox creation

This commit is contained in:
Codex
2026-04-27 16:55:33 +00:00
parent 5f1331a85e
commit 48d2d00d41
3 changed files with 53 additions and 16 deletions
+42 -8
View File
@@ -2,7 +2,17 @@ import { NextResponse } from "next/server"
import { execFile, spawn } from "node:child_process"
import { promisify } from "node:util"
import { inspectSandbox } from "@/app/lib/openshellHost"
import { commandExists, HOST_PATH, NEMOCLAW_SETUP, NEMOCLAW_SETUP_CANDIDATES, OPENSHELL_BIN } from "@/app/lib/hostCommands"
import {
commandExists,
HOST_PATH,
NEMOCLAW_BIN,
NEMOCLAW_BIN_CANDIDATES,
NEMOCLAW_CWD,
NEMOCLAW_SETUP,
NEMOCLAW_SETUP_CANDIDATES,
NODE_BIN,
OPENSHELL_BIN,
} from "@/app/lib/hostCommands"
const execFileAsync = promisify(execFile)
@@ -41,10 +51,24 @@ function appendNote(...parts: Array<string | false | null | undefined>) {
return parts.filter(Boolean).join(" ")
}
function requireNemoClawSetup() {
if (NEMOCLAW_SETUP && commandExists(NEMOCLAW_SETUP)) return NEMOCLAW_SETUP
type NemoClawCreateCommand = {
file: string
args: string[]
mode: "cli-onboard" | "legacy-setup"
}
function buildNemoClawCreateCommand(): NemoClawCreateCommand {
if (NEMOCLAW_BIN && commandExists(NEMOCLAW_BIN)) {
const args = ["onboard", "--non-interactive", "--recreate-sandbox", "--yes-i-accept-third-party-software"]
return /\.(?:c?m?js|ts)$/i.test(NEMOCLAW_BIN)
? { file: NODE_BIN, args: [NEMOCLAW_BIN, ...args], mode: "cli-onboard" }
: { file: NEMOCLAW_BIN, args, mode: "cli-onboard" }
}
if (NEMOCLAW_SETUP && commandExists(NEMOCLAW_SETUP)) {
return { file: "/bin/bash", args: [NEMOCLAW_SETUP], mode: "legacy-setup" }
}
throw new Error(
`NemoClaw blueprint setup script was not found. Install NemoClaw under your Linux home directory, or set NEMOCLAW_SETUP in .env.local to the absolute path of scripts/setup.sh. Searched: ${NEMOCLAW_SETUP_CANDIDATES.join(", ") || "no candidates"}.`,
`NemoClaw CLI was not found. Install the current NemoClaw CLI under your Linux home directory, or set NEMOCLAW_BIN in .env.local. Searched CLI: ${NEMOCLAW_BIN_CANDIDATES.join(", ") || "no candidates"}. Legacy setup candidates: ${NEMOCLAW_SETUP_CANDIDATES.join(", ") || "none"}.`,
)
}
@@ -87,11 +111,12 @@ async function verifySandboxCreation(sandboxName: string): Promise<SandboxVerifi
}
}
async function runCommand(file: string, args: string[], env: NodeJS.ProcessEnv) {
async function runCommand(file: string, args: string[], env: NodeJS.ProcessEnv, cwd?: string) {
const startedAt = Date.now()
console.log(`[sandbox/create] command:start file=${file} args=${JSON.stringify(args)}`)
try {
const { stdout, stderr } = await execFileAsync(file, args, {
cwd,
env,
maxBuffer: 20 * 1024 * 1024,
})
@@ -313,18 +338,27 @@ export async function POST(request: Request) {
}
if (blueprint === "nemoclaw-blueprint") {
const setupPath = requireNemoClawSetup()
const createCommand = buildNemoClawCreateCommand()
const env: NodeJS.ProcessEnv = {
...process.env,
PATH: HOST_PATH,
NEMOCLAW_SANDBOX_NAME: sandboxName,
NEMOCLAW_NON_INTERACTIVE: "1",
NEMOCLAW_RECREATE_SANDBOX: "1",
NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1",
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw",
}
if (!enableTailscale) {
env.NVIDIA_API_KEY = env.NVIDIA_API_KEY || "optional-local-mode"
}
const result = await runCommand("/bin/bash", [setupPath, sandboxName], env)
const result = await runCommand(
createCommand.file,
createCommand.mode === "legacy-setup" ? [...createCommand.args, sandboxName] : createCommand.args,
env,
NEMOCLAW_CWD,
)
if (!result.ok) {
return NextResponse.json({
@@ -359,7 +393,7 @@ export async function POST(request: Request) {
verification,
mode: "nemoclaw-blueprint",
enableTailscale,
setupPath,
createCommand,
hostPath: HOST_PATH,
readiness: {
attempts: readiness.attempts,
+2 -3
View File
@@ -294,10 +294,9 @@ else
fi
if [[ -n "$NEMOCLAW_SETUP" ]]; then
log "NemoClaw setup workflow: $NEMOCLAW_SETUP"
log "Legacy NemoClaw setup workflow: $NEMOCLAW_SETUP"
else
warn "NemoClaw setup workflow was not found."
warn "The NemoClaw blueprint create button requires NEMOCLAW_SETUP to point at scripts/setup.sh."
log "Legacy NemoClaw setup workflow was not found; current installs use 'nemoclaw onboard'."
fi
check_port 3000 "dashboard HTTP"
+9 -5
View File
@@ -29,7 +29,7 @@ const [
])
assert.match(installSource, /find_nemoclaw_bin\(\)/, 'installer must discover NemoClaw CLI')
assert.match(installSource, /find_nemoclaw_setup\(\)/, 'installer must discover NemoClaw setup workflow')
assert.match(installSource, /find_nemoclaw_setup\(\)/, 'installer may discover the legacy NemoClaw setup workflow')
assert.match(installSource, /\$HOME\/nemoclaw\/scripts\/setup\.sh/, 'installer must check common lowercase ~/nemoclaw setup path')
assert.match(installSource, /candidate="\$root\/scripts\/setup\.sh"/, 'installer must scan user home project directories for setup.sh')
assert.match(installSource, /candidate="\$nested\/scripts\/setup\.sh"/, 'installer must scan one nested user-home level for setup.sh')
@@ -40,15 +40,19 @@ assert.match(installSource, /upsert_env "TERMINAL_SERVER_AUTOSTART" "true"/, 'in
assert.match(hostCommandsSource, /export const HOST_PATH/, 'host command resolution must centralize PATH construction')
assert.match(hostCommandsSource, /\.nemoclaw\/source\/bin\/nemoclaw\.js/, 'host command resolution must support standard ~/.nemoclaw installs')
assert.match(hostCommandsSource, /\.nemoclaw\/source\/scripts\/setup\.sh/, 'host command resolution must support standard ~/.nemoclaw setup workflow')
assert.match(hostCommandsSource, /\.nemoclaw\/source\/scripts\/setup\.sh/, 'host command resolution must support legacy ~/.nemoclaw setup workflows')
assert.match(hostCommandsSource, /discoverHomeFiles\("scripts\/setup\.sh"\)/, 'runtime command resolution must scan user home directories for setup.sh')
assert.match(hostCommandsSource, /discoverHomeFiles\("bin\/nemoclaw\.js"\)/, 'runtime command resolution must scan user home directories for nemoclaw.js')
assert.match(hostCommandsSource, /export const NEMOCLAW_SETUP_CANDIDATES/, 'runtime command resolution must expose searched setup candidates')
assert.doesNotMatch(hostCommandsSource, /\/Users\/markmckeen|\/home\/nvidia/, 'host command resolution must not bake in developer machine paths')
assert.match(createRouteSource, /requireNemoClawSetup\(\)/, 'NemoClaw blueprint create must validate setup workflow before running bash')
assert.match(createRouteSource, /NemoClaw blueprint setup script was not found/, 'missing setup workflow must produce an actionable error')
assert.match(createRouteSource, /Searched: \$\{NEMOCLAW_SETUP_CANDIDATES\.join/, 'missing setup workflow error must list searched candidates')
assert.match(createRouteSource, /buildNemoClawCreateCommand\(\)/, 'NemoClaw blueprint create must resolve a current CLI command')
assert.match(createRouteSource, /"onboard", "--non-interactive"/, 'NemoClaw blueprint create must use the supported onboard CLI flow')
assert.match(createRouteSource, /NEMOCLAW_SANDBOX_NAME: sandboxName/, 'NemoClaw blueprint create must pass the requested sandbox name to onboard')
assert.match(createRouteSource, /NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1"/, 'NemoClaw blueprint create must be able to run onboard non-interactively')
assert.match(createRouteSource, /mode: "legacy-setup"/, 'NemoClaw blueprint create may fall back to legacy setup.sh for old clones')
assert.match(createRouteSource, /NemoClaw CLI was not found/, 'missing current CLI must produce an actionable error')
assert.match(createRouteSource, /NEMOCLAW_BIN_CANDIDATES\.join/, 'missing current CLI error must list searched candidates')
assert.match(createRouteSource, /from "@\/app\/lib\/hostCommands"/, 'create route must use shared command resolution')
assert.match(deleteRouteSource, /NEMOCLAW_CWD/, 'delete route must use resolved NemoClaw working directory')