Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/lib/inventory-commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,39 @@ describe("inventory commands", () => {
);
});

it("prints the dashboard URL for each sandbox when dashboardPort is set", async () => {
const lines: string[] = [];
await listSandboxesCommand({
recoverRegistryEntries: async () => ({
sandboxes: [
{
name: "alpha",
model: "m",
provider: "p",
gpuEnabled: false,
policies: [],
dashboardPort: 18789,
},
{
name: "beta",
model: "m",
provider: "p",
gpuEnabled: false,
policies: [],
dashboardPort: 18790,
},
],
defaultSandbox: "alpha",
}),
getLiveInference: () => null,
loadLastSession: () => null,
log: (message = "") => lines.push(message),
});

expect(lines).toContain(" dashboard: http://127.0.0.1:18789");
expect(lines).toContain(" dashboard: http://127.0.0.1:18790");
});

it("uses live gateway inference for the default sandbox in list output (#2369)", async () => {
const lines: string[] = [];
await listSandboxesCommand({
Expand Down Expand Up @@ -201,6 +234,25 @@ describe("inventory commands", () => {
expect(lines).toContain(" (onboarded: provider=configured-provider)");
});

it("prints the dashboard URL per sandbox in status when dashboardPort is set", () => {
const lines: string[] = [];
showStatusCommand({
listSandboxes: () => ({
sandboxes: [
{ name: "alpha", model: "m", dashboardPort: 18789 },
{ name: "beta", model: "m", dashboardPort: 18790 },
],
defaultSandbox: "alpha",
}),
getLiveInference: () => null,
showServiceStatus: vi.fn(),
log: (message = "") => lines.push(message),
});

expect(lines).toContain(" dashboard: http://127.0.0.1:18789");
expect(lines).toContain(" dashboard: http://127.0.0.1:18790");
});

it("flags messaging bridge as degraded when checkMessagingBridgeHealth reports conflicts", () => {
const lines: string[] = [];
const checkMessagingBridgeHealth = vi.fn().mockReturnValue([
Expand Down
7 changes: 7 additions & 0 deletions src/lib/inventory-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface SandboxEntry {
policies?: string[] | null;
messagingChannels?: string[] | null;
agent?: string | null;
dashboardPort?: number;
}

export interface MessagingBridgeHealth {
Expand Down Expand Up @@ -117,6 +118,9 @@ export async function listSandboxesCommand(deps: ListSandboxesCommandDeps): Prom
const connected = sessionCount !== null && sessionCount > 0 ? " ●" : "";
log(` ${sb.name}${def}${connected}`);
log(` model: ${model} provider: ${provider} ${gpu} policies: ${presets}`);
if (typeof sb.dashboardPort === "number") {
log(` dashboard: http://127.0.0.1:${sb.dashboardPort}`);
}
if (modelDrifted || providerDrifted) {
const parts: string[] = [];
if (modelDrifted) parts.push(`model=${sb.model || "unknown"}`);
Expand Down Expand Up @@ -152,6 +156,9 @@ export function showStatusCommand(deps: ShowStatusCommandDeps): void {
const liveModel = isDefault && live ? live.model : null;
const model = liveModel || sb.model;
log(` ${sb.name}${def}${model ? ` (${model})` : ""}`);
if (typeof sb.dashboardPort === "number") {
log(` dashboard: http://127.0.0.1:${sb.dashboardPort}`);
}
if (isDefault && liveModel && liveModel !== sb.model) {
log(` (onboarded: ${sb.model || "unknown"})`);
}
Expand Down
36 changes: 36 additions & 0 deletions src/lib/onboard-command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe("onboard command", () => {
acceptThirdPartySoftware: true,
agent: null,
dangerouslySkipPermissions: false,
controlUiPort: null,
});
});

Expand All @@ -63,6 +64,7 @@ describe("onboard command", () => {
acceptThirdPartySoftware: true,
agent: null,
dangerouslySkipPermissions: false,
controlUiPort: null,
});
});

Expand All @@ -86,6 +88,7 @@ describe("onboard command", () => {
acceptThirdPartySoftware: false,
agent: null,
dangerouslySkipPermissions: false,
controlUiPort: null,
});
});

Expand Down Expand Up @@ -130,9 +133,39 @@ describe("onboard command", () => {
acceptThirdPartySoftware: false,
agent: null,
dangerouslySkipPermissions: false,
controlUiPort: null,
});
});

it("parses --control-ui-port <n>", () => {
const result = parseOnboardArgs(
["--resume", "--control-ui-port", "18795"],
"--yes-i-accept-third-party-software",
"NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE",
{
env: {},
error: () => {},
exit: exitWithCode,
},
);
expect(result.controlUiPort).toBe(18795);
});

it("exits when --control-ui-port is out of range", () => {
expect(() =>
parseOnboardArgs(
["--control-ui-port", "80"],
"--yes-i-accept-third-party-software",
"NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE",
{
env: {},
error: () => {},
exit: exitWithPrefixedCode,
},
),
).toThrow("exit:1");
});

it("parses --fresh and surfaces it as fresh=true", () => {
expect(
parseOnboardArgs(
Expand All @@ -154,6 +187,7 @@ describe("onboard command", () => {
acceptThirdPartySoftware: false,
agent: null,
dangerouslySkipPermissions: false,
controlUiPort: null,
});
});

Expand Down Expand Up @@ -229,6 +263,7 @@ describe("onboard command", () => {
acceptThirdPartySoftware: false,
agent: "openclaw",
dangerouslySkipPermissions: true,
controlUiPort: null,
});
});

Expand Down Expand Up @@ -277,6 +312,7 @@ describe("onboard command", () => {
acceptThirdPartySoftware: false,
agent: null,
dangerouslySkipPermissions: false,
controlUiPort: null,
});
});

Expand Down
44 changes: 42 additions & 2 deletions src/lib/onboard-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface OnboardCommandOptions {
acceptThirdPartySoftware: boolean;
agent: string | null;
dangerouslySkipPermissions: boolean;
controlUiPort: number | null;
}

export interface RunOnboardCommandDeps {
Expand Down Expand Up @@ -38,7 +39,7 @@ const ONBOARD_BASE_ARGS = [

function onboardUsageLines(noticeAcceptFlag: string): string[] {
return [
` Usage: nemoclaw onboard [--non-interactive] [--resume | --fresh] [--recreate-sandbox] [--from <Dockerfile>] [--agent <name>] [--dangerously-skip-permissions] [${noticeAcceptFlag}]`,
` Usage: nemoclaw onboard [--non-interactive] [--resume | --fresh] [--recreate-sandbox] [--from <Dockerfile>] [--agent <name>] [--control-ui-port <n>] [--dangerously-skip-permissions] [${noticeAcceptFlag}]`,
"",
];
}
Expand Down Expand Up @@ -71,6 +72,28 @@ export function parseOnboardArgs(
parsedArgs.splice(fromIdx, 2);
}

let controlUiPort: number | null = null;
const controlUiPortIdx = parsedArgs.indexOf("--control-ui-port");
if (controlUiPortIdx !== -1) {
const raw = parsedArgs[controlUiPortIdx + 1];
if (typeof raw !== "string" || raw.startsWith("--")) {
error(" --control-ui-port requires a port number");
printOnboardUsage(error, noticeAcceptFlag);
exit(1);
}
if (!/^\d+$/.test(raw)) {
error(` --control-ui-port '${raw}' must be an integer between 1024 and 65535`);
exit(1);
}
const parsed = Number(raw);
if (parsed < 1024 || parsed > 65535) {
error(` --control-ui-port '${raw}' must be an integer between 1024 and 65535`);
exit(1);
Comment on lines +84 to +91

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Print usage text for all --control-ui-port validation failures.

Line 83 and Line 88 exit with an error but skip usage output, while other argument-validation failures in this parser print usage. Keeping this consistent improves CLI guidance.

💡 Suggested patch
     if (!/^\d+$/.test(raw)) {
       error(`  --control-ui-port '${raw}' must be an integer between 1024 and 65535`);
+      printOnboardUsage(error, noticeAcceptFlag);
       exit(1);
     }
     const parsed = Number(raw);
     if (parsed < 1024 || parsed > 65535) {
       error(`  --control-ui-port '${raw}' must be an integer between 1024 and 65535`);
+      printOnboardUsage(error, noticeAcceptFlag);
       exit(1);
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lib/onboard-command.ts` around lines 82 - 89, The validation for
--control-ui-port currently logs an error and exits in two places (the /^\d+$/
check and the 1024–65535 range check) but doesn't print the CLI usage like other
argument validators; update both failure branches that call error(...) and
exit(1) to also invoke the parser's usage printing function (the same helper
used elsewhere in this file, e.g., printUsage() or usage()) before exiting so
that when raw or parsed fail validation (variables raw and parsed, and the
branches that call error(...) and exit(1)) the usage/help text is shown
consistently.

}
controlUiPort = parsed;
parsedArgs.splice(controlUiPortIdx, 2);
}

let agent: string | null = null;
const agentIdx = parsedArgs.indexOf("--agent");
if (agentIdx !== -1) {
Expand Down Expand Up @@ -116,6 +139,7 @@ export function parseOnboardArgs(
parsedArgs.includes(noticeAcceptFlag) || String(deps.env[noticeAcceptEnv] || "") === "1",
agent,
dangerouslySkipPermissions: parsedArgs.includes("--dangerously-skip-permissions"),
controlUiPort,
};
}

Expand All @@ -127,7 +151,23 @@ export async function runOnboardCommand(deps: RunOnboardCommandDeps): Promise<vo
}

const options = parseOnboardArgs(deps.args, deps.noticeAcceptFlag, deps.noticeAcceptEnv, deps);
await deps.runOnboard(options);
// --control-ui-port takes precedence over existing CHAT_UI_URL. The onboard
// flow reads CHAT_UI_URL directly in many places, so setting it here is the
// single seam that makes the flag effective without threading it through.
const _origChatUiUrl = process.env.CHAT_UI_URL;
try {
if (options.controlUiPort !== null) {
process.env.CHAT_UI_URL = `http://127.0.0.1:${options.controlUiPort}`;
}
await deps.runOnboard(options);
} finally {
// Restore original value to prevent cross-invocation leakage
if (_origChatUiUrl === undefined) {
delete process.env.CHAT_UI_URL;
} else {
process.env.CHAT_UI_URL = _origChatUiUrl;
}
}
}

export async function runDeprecatedOnboardAliasCommand(
Expand Down
Loading
Loading