diff --git a/src/cli/program.test.ts b/src/cli/program.test.ts index ab6aef2a8..cf209ab25 100644 --- a/src/cli/program.test.ts +++ b/src/cli/program.test.ts @@ -3,6 +3,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; const sendCommand = vi.fn(); const statusCommand = vi.fn(); +const configureCommand = vi.fn(); const loginWeb = vi.fn(); const callGateway = vi.fn(); @@ -16,6 +17,7 @@ const runtime = { vi.mock("../commands/send.js", () => ({ sendCommand })); vi.mock("../commands/status.js", () => ({ statusCommand })); +vi.mock("../commands/configure.js", () => ({ configureCommand })); vi.mock("../runtime.js", () => ({ defaultRuntime: runtime })); vi.mock("../provider-web.js", () => ({ loginWeb, @@ -49,7 +51,13 @@ describe("cli program", () => { expect(statusCommand).toHaveBeenCalled(); }); - it("runs nodes list and calls node.pair.list", async () => { + it("runs config alias as configure", async () => { + const program = buildProgram(); + await program.parseAsync(["config"], { from: "user" }); + expect(configureCommand).toHaveBeenCalled(); + }); + +it("runs nodes list and calls node.pair.list", async () => { callGateway.mockResolvedValue({ pending: [], paired: [] }); const program = buildProgram(); runtime.log.mockClear(); diff --git a/src/cli/program.ts b/src/cli/program.ts index 9b7a866d9..12bca7579 100644 --- a/src/cli/program.ts +++ b/src/cli/program.ts @@ -232,6 +232,7 @@ export function buildProgram() { program .command("configure") + .alias("config") .description( "Interactive wizard to update models, providers, skills, and gateway", ) diff --git a/src/commands/configure.ts b/src/commands/configure.ts index 4490c19a3..032400673 100644 --- a/src/commands/configure.ts +++ b/src/commands/configure.ts @@ -176,7 +176,7 @@ async function promptGatewayConfig( ...next, gateway: { ...next.gateway, - auth: { ...next.gateway?.auth, mode: "token" }, + auth: { ...next.gateway?.auth, mode: "token", token: gatewayToken }, }, }; } @@ -453,7 +453,7 @@ export async function runConfigureWizard( const localUrl = "ws://127.0.0.1:18789"; const localProbe = await probeGatewayReachable({ url: localUrl, - token: process.env.CLAWDBOT_GATEWAY_TOKEN, + token: baseConfig.gateway?.auth?.token ?? process.env.CLAWDBOT_GATEWAY_TOKEN, password: baseConfig.gateway?.auth?.password ?? process.env.CLAWDBOT_GATEWAY_PASSWORD, diff --git a/src/commands/onboard-helpers.ts b/src/commands/onboard-helpers.ts index 0922f1983..bafa59b9b 100644 --- a/src/commands/onboard-helpers.ts +++ b/src/commands/onboard-helpers.ts @@ -194,6 +194,8 @@ export async function probeGatewayReachable(params: { password: params.password, method: "health", timeoutMs, + clientName: "clawdbot-probe", + mode: "probe", }); return { ok: true }; } catch (err) { diff --git a/src/gateway/call.ts b/src/gateway/call.ts index 8577be935..eb6c1b1b4 100644 --- a/src/gateway/call.ts +++ b/src/gateway/call.ts @@ -92,9 +92,10 @@ export async function callGateway( client.stop(); stop(err as Error); } - }, - onClose: (code, reason) => { + }, onClose: (code, reason) => { if (settled || ignoreClose) return; + ignoreClose = true; + client.stop(); stop(new Error(`gateway closed (${code}): ${reason}`)); }, }); diff --git a/src/gateway/client.ts b/src/gateway/client.ts index 1740b497c..24e138d03 100644 --- a/src/gateway/client.ts +++ b/src/gateway/client.ts @@ -119,7 +119,9 @@ export class GatewayClient { this.opts.onHelloOk?.(helloOk); }) .catch((err) => { - logError(`gateway connect failed: ${String(err)}`); + const msg = `gateway connect failed: ${String(err)}`; + if (this.opts.mode === "probe") logDebug(msg); + else logError(msg); this.ws?.close(1008, "connect failed"); }); }