Broaden NemoClaw home directory discovery
This commit is contained in:
@@ -2,7 +2,7 @@ import { NextResponse } from "next/server"
|
|||||||
import { execFile, spawn } from "node:child_process"
|
import { execFile, spawn } from "node:child_process"
|
||||||
import { promisify } from "node:util"
|
import { promisify } from "node:util"
|
||||||
import { inspectSandbox } from "@/app/lib/openshellHost"
|
import { inspectSandbox } from "@/app/lib/openshellHost"
|
||||||
import { commandExists, HOST_PATH, NEMOCLAW_SETUP, OPENSHELL_BIN } from "@/app/lib/hostCommands"
|
import { commandExists, HOST_PATH, NEMOCLAW_SETUP, NEMOCLAW_SETUP_CANDIDATES, OPENSHELL_BIN } from "@/app/lib/hostCommands"
|
||||||
|
|
||||||
const execFileAsync = promisify(execFile)
|
const execFileAsync = promisify(execFile)
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ function appendNote(...parts: Array<string | false | null | undefined>) {
|
|||||||
function requireNemoClawSetup() {
|
function requireNemoClawSetup() {
|
||||||
if (NEMOCLAW_SETUP && commandExists(NEMOCLAW_SETUP)) return NEMOCLAW_SETUP
|
if (NEMOCLAW_SETUP && commandExists(NEMOCLAW_SETUP)) return NEMOCLAW_SETUP
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"NemoClaw blueprint setup script was not found. Install NemoClaw on this host or set NEMOCLAW_SETUP in .env.local to the absolute path of scripts/setup.sh.",
|
`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"}.`,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+63
-8
@@ -1,4 +1,4 @@
|
|||||||
import { existsSync } from "node:fs"
|
import { existsSync, readdirSync, statSync } from "node:fs"
|
||||||
import path from "node:path"
|
import path from "node:path"
|
||||||
|
|
||||||
const HOME = process.env.HOME || ""
|
const HOME = process.env.HOME || ""
|
||||||
@@ -7,6 +7,50 @@ function firstExisting(candidates: Array<string | undefined>, fallback: string)
|
|||||||
return candidates.filter((value): value is string => Boolean(value)).find((candidate) => existsSync(candidate)) || fallback
|
return candidates.filter((value): value is string => Boolean(value)).find((candidate) => existsSync(candidate)) || fallback
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function unique(values: Array<string | undefined>) {
|
||||||
|
return Array.from(new Set(values.filter((value): value is string => Boolean(value))))
|
||||||
|
}
|
||||||
|
|
||||||
|
function safeIsDirectory(candidate: string) {
|
||||||
|
try {
|
||||||
|
return statSync(candidate).isDirectory()
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function homeChildDirectories() {
|
||||||
|
if (!HOME || !safeIsDirectory(HOME)) return []
|
||||||
|
try {
|
||||||
|
return readdirSync(HOME, { withFileTypes: true })
|
||||||
|
.filter((entry) => entry.isDirectory())
|
||||||
|
.map((entry) => path.join(HOME, entry.name))
|
||||||
|
.filter((directory) => !/(^|\/)(node_modules|\.cache|\.npm|\.local\/share\/Trash)$/.test(directory))
|
||||||
|
} catch {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function discoverHomeFiles(relativePath: string) {
|
||||||
|
const found: string[] = []
|
||||||
|
for (const directory of homeChildDirectories()) {
|
||||||
|
const direct = path.join(directory, relativePath)
|
||||||
|
if (existsSync(direct)) found.push(direct)
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
||||||
|
if (!entry.isDirectory()) continue
|
||||||
|
if (["node_modules", ".git", ".next", "dist", "build"].includes(entry.name)) continue
|
||||||
|
const nested = path.join(directory, entry.name, relativePath)
|
||||||
|
if (existsSync(nested)) found.push(nested)
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Ignore unreadable home subdirectories.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return found
|
||||||
|
}
|
||||||
|
|
||||||
function pathEntries() {
|
function pathEntries() {
|
||||||
return [
|
return [
|
||||||
process.env.TERMINAL_EXTRA_PATH,
|
process.env.TERMINAL_EXTRA_PATH,
|
||||||
@@ -25,7 +69,7 @@ function pathEntries() {
|
|||||||
].filter((value): value is string => Boolean(value))
|
].filter((value): value is string => Boolean(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
export const HOST_PATH = Array.from(new Set(pathEntries())).join(":")
|
export const HOST_PATH = unique(pathEntries()).join(":")
|
||||||
|
|
||||||
export const NODE_BIN = firstExisting([
|
export const NODE_BIN = firstExisting([
|
||||||
process.env.NODE_BIN,
|
process.env.NODE_BIN,
|
||||||
@@ -52,27 +96,38 @@ export const OPENCLAW_BIN = firstExisting([
|
|||||||
"/usr/local/bin/openclaw",
|
"/usr/local/bin/openclaw",
|
||||||
], "openclaw")
|
], "openclaw")
|
||||||
|
|
||||||
export const NEMOCLAW_BIN = firstExisting([
|
export const NEMOCLAW_BIN_CANDIDATES = unique([
|
||||||
process.env.NEMOCLAW_BIN,
|
process.env.NEMOCLAW_BIN,
|
||||||
HOME ? path.join(HOME, ".local/bin/nemoclaw") : undefined,
|
HOME ? path.join(HOME, ".local/bin/nemoclaw") : undefined,
|
||||||
HOME ? path.join(HOME, ".nemoclaw/source/bin/nemoclaw.js") : undefined,
|
HOME ? path.join(HOME, ".nemoclaw/source/bin/nemoclaw.js") : undefined,
|
||||||
HOME ? path.join(HOME, "NemoClaw/bin/nemoclaw.js") : undefined,
|
HOME ? path.join(HOME, "NemoClaw/bin/nemoclaw.js") : undefined,
|
||||||
|
HOME ? path.join(HOME, "nemoclaw/bin/nemoclaw.js") : undefined,
|
||||||
|
HOME ? path.join(HOME, "nemoclaw.js") : undefined,
|
||||||
|
...discoverHomeFiles("bin/nemoclaw.js"),
|
||||||
HOME ? path.join(HOME, ".nvm/versions/node/v22.22.2/bin/nemoclaw") : undefined,
|
HOME ? path.join(HOME, ".nvm/versions/node/v22.22.2/bin/nemoclaw") : undefined,
|
||||||
"/opt/homebrew/bin/nemoclaw",
|
"/opt/homebrew/bin/nemoclaw",
|
||||||
"/usr/local/bin/nemoclaw",
|
"/usr/local/bin/nemoclaw",
|
||||||
], "nemoclaw")
|
])
|
||||||
|
export const NEMOCLAW_BIN = firstExisting(NEMOCLAW_BIN_CANDIDATES, "nemoclaw")
|
||||||
|
|
||||||
export const NEMOCLAW_SETUP = firstExisting([
|
export const NEMOCLAW_SETUP_CANDIDATES = unique([
|
||||||
process.env.NEMOCLAW_SETUP,
|
process.env.NEMOCLAW_SETUP,
|
||||||
HOME ? path.join(HOME, ".nemoclaw/source/scripts/setup.sh") : undefined,
|
HOME ? path.join(HOME, ".nemoclaw/source/scripts/setup.sh") : undefined,
|
||||||
HOME ? path.join(HOME, "NemoClaw/scripts/setup.sh") : undefined,
|
HOME ? path.join(HOME, "NemoClaw/scripts/setup.sh") : undefined,
|
||||||
], "")
|
HOME ? path.join(HOME, "nemoclaw/scripts/setup.sh") : undefined,
|
||||||
|
...discoverHomeFiles("scripts/setup.sh"),
|
||||||
|
])
|
||||||
|
export const NEMOCLAW_SETUP = firstExisting(NEMOCLAW_SETUP_CANDIDATES, "")
|
||||||
|
|
||||||
export const NEMOCLAW_CWD = firstExisting([
|
export const NEMOCLAW_CWD_CANDIDATES = unique([
|
||||||
process.env.NEMOCLAW_CWD,
|
process.env.NEMOCLAW_CWD,
|
||||||
|
NEMOCLAW_SETUP ? path.dirname(path.dirname(NEMOCLAW_SETUP)) : undefined,
|
||||||
|
NEMOCLAW_BIN.includes("/") ? path.dirname(path.dirname(NEMOCLAW_BIN)) : undefined,
|
||||||
HOME ? path.join(HOME, ".nemoclaw/source") : undefined,
|
HOME ? path.join(HOME, ".nemoclaw/source") : undefined,
|
||||||
HOME ? path.join(HOME, "NemoClaw") : undefined,
|
HOME ? path.join(HOME, "NemoClaw") : undefined,
|
||||||
], process.cwd())
|
HOME ? path.join(HOME, "nemoclaw") : undefined,
|
||||||
|
])
|
||||||
|
export const NEMOCLAW_CWD = firstExisting(NEMOCLAW_CWD_CANDIDATES, process.cwd())
|
||||||
|
|
||||||
export function commandExists(command: string) {
|
export function commandExists(command: string) {
|
||||||
return command.includes("/") ? existsSync(command) : true
|
return command.includes("/") ? existsSync(command) : true
|
||||||
|
|||||||
+43
-1
@@ -140,11 +140,29 @@ find_nemoclaw_bin() {
|
|||||||
"$HOME/.local/bin/nemoclaw" \
|
"$HOME/.local/bin/nemoclaw" \
|
||||||
"$HOME/.nemoclaw/source/bin/nemoclaw.js" \
|
"$HOME/.nemoclaw/source/bin/nemoclaw.js" \
|
||||||
"$HOME/NemoClaw/bin/nemoclaw.js" \
|
"$HOME/NemoClaw/bin/nemoclaw.js" \
|
||||||
|
"$HOME/nemoclaw/bin/nemoclaw.js" \
|
||||||
"/opt/homebrew/bin/nemoclaw" \
|
"/opt/homebrew/bin/nemoclaw" \
|
||||||
"/usr/local/bin/nemoclaw"
|
"/usr/local/bin/nemoclaw"
|
||||||
do
|
do
|
||||||
[[ -x "$candidate" || -f "$candidate" ]] && printf '%s\n' "$candidate" && return
|
[[ -x "$candidate" || -f "$candidate" ]] && printf '%s\n' "$candidate" && return
|
||||||
done
|
done
|
||||||
|
local root nested
|
||||||
|
for root in "$HOME"/* "$HOME"/.*; do
|
||||||
|
[[ -d "$root" ]] || continue
|
||||||
|
case "$(basename "$root")" in
|
||||||
|
.|..|.cache|.npm|node_modules) continue ;;
|
||||||
|
esac
|
||||||
|
candidate="$root/bin/nemoclaw.js"
|
||||||
|
[[ -x "$candidate" || -f "$candidate" ]] && printf '%s\n' "$candidate" && return
|
||||||
|
for nested in "$root"/*; do
|
||||||
|
[[ -d "$nested" ]] || continue
|
||||||
|
case "$(basename "$nested")" in
|
||||||
|
.git|.next|build|dist|node_modules) continue ;;
|
||||||
|
esac
|
||||||
|
candidate="$nested/bin/nemoclaw.js"
|
||||||
|
[[ -x "$candidate" || -f "$candidate" ]] && printf '%s\n' "$candidate" && return
|
||||||
|
done
|
||||||
|
done
|
||||||
command -v nemoclaw 2>/dev/null || true
|
command -v nemoclaw 2>/dev/null || true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,10 +170,28 @@ find_nemoclaw_setup() {
|
|||||||
local candidate
|
local candidate
|
||||||
for candidate in \
|
for candidate in \
|
||||||
"$HOME/.nemoclaw/source/scripts/setup.sh" \
|
"$HOME/.nemoclaw/source/scripts/setup.sh" \
|
||||||
"$HOME/NemoClaw/scripts/setup.sh"
|
"$HOME/NemoClaw/scripts/setup.sh" \
|
||||||
|
"$HOME/nemoclaw/scripts/setup.sh"
|
||||||
do
|
do
|
||||||
[[ -f "$candidate" ]] && printf '%s\n' "$candidate" && return
|
[[ -f "$candidate" ]] && printf '%s\n' "$candidate" && return
|
||||||
done
|
done
|
||||||
|
local root nested
|
||||||
|
for root in "$HOME"/* "$HOME"/.*; do
|
||||||
|
[[ -d "$root" ]] || continue
|
||||||
|
case "$(basename "$root")" in
|
||||||
|
.|..|.cache|.npm|node_modules) continue ;;
|
||||||
|
esac
|
||||||
|
candidate="$root/scripts/setup.sh"
|
||||||
|
[[ -f "$candidate" ]] && printf '%s\n' "$candidate" && return
|
||||||
|
for nested in "$root"/*; do
|
||||||
|
[[ -d "$nested" ]] || continue
|
||||||
|
case "$(basename "$nested")" in
|
||||||
|
.git|.next|build|dist|node_modules) continue ;;
|
||||||
|
esac
|
||||||
|
candidate="$nested/scripts/setup.sh"
|
||||||
|
[[ -f "$candidate" ]] && printf '%s\n' "$candidate" && return
|
||||||
|
done
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
nemoclaw_cwd_for() {
|
nemoclaw_cwd_for() {
|
||||||
@@ -164,10 +200,16 @@ nemoclaw_cwd_for() {
|
|||||||
printf '%s\n' "$HOME/.nemoclaw/source"
|
printf '%s\n' "$HOME/.nemoclaw/source"
|
||||||
elif [[ "$path_value" == "$HOME/NemoClaw/"* ]]; then
|
elif [[ "$path_value" == "$HOME/NemoClaw/"* ]]; then
|
||||||
printf '%s\n' "$HOME/NemoClaw"
|
printf '%s\n' "$HOME/NemoClaw"
|
||||||
|
elif [[ "$path_value" == "$HOME/nemoclaw/"* ]]; then
|
||||||
|
printf '%s\n' "$HOME/nemoclaw"
|
||||||
elif [[ -d "$HOME/.nemoclaw/source" ]]; then
|
elif [[ -d "$HOME/.nemoclaw/source" ]]; then
|
||||||
printf '%s\n' "$HOME/.nemoclaw/source"
|
printf '%s\n' "$HOME/.nemoclaw/source"
|
||||||
elif [[ -d "$HOME/NemoClaw" ]]; then
|
elif [[ -d "$HOME/NemoClaw" ]]; then
|
||||||
printf '%s\n' "$HOME/NemoClaw"
|
printf '%s\n' "$HOME/NemoClaw"
|
||||||
|
elif [[ -d "$HOME/nemoclaw" ]]; then
|
||||||
|
printf '%s\n' "$HOME/nemoclaw"
|
||||||
|
elif [[ -n "$path_value" ]]; then
|
||||||
|
dirname "$(dirname "$path_value")"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ const [
|
|||||||
|
|
||||||
assert.match(installSource, /find_nemoclaw_bin\(\)/, 'installer must discover NemoClaw CLI')
|
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 must discover 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')
|
||||||
assert.match(installSource, /set_env "NEMOCLAW_SETUP"/, 'installer must persist discovered NemoClaw setup path')
|
assert.match(installSource, /set_env "NEMOCLAW_SETUP"/, 'installer must persist discovered NemoClaw setup path')
|
||||||
assert.match(installSource, /set_env "NEMOCLAW_BIN"/, 'installer must persist discovered NemoClaw CLI path')
|
assert.match(installSource, /set_env "NEMOCLAW_BIN"/, 'installer must persist discovered NemoClaw CLI path')
|
||||||
assert.match(installSource, /set_env "OPENSHELL_BIN"/, 'installer must persist discovered OpenShell path')
|
assert.match(installSource, /set_env "OPENSHELL_BIN"/, 'installer must persist discovered OpenShell path')
|
||||||
@@ -38,10 +41,14 @@ 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, /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\/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 standard ~/.nemoclaw setup workflow')
|
||||||
|
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.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, /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, /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, /from "@\/app\/lib\/hostCommands"/, 'create route must use shared command resolution')
|
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')
|
assert.match(deleteRouteSource, /NEMOCLAW_CWD/, 'delete route must use resolved NemoClaw working directory')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user