feat: add remote gateway client config

This commit is contained in:
Peter Steinberger
2026-01-01 20:10:50 +01:00
parent a72fdf7c26
commit bd7cd33b02
18 changed files with 516 additions and 45 deletions

View File

@@ -41,6 +41,7 @@ import {
summarizeExistingConfig,
} from "./onboard-helpers.js";
import { setupProviders } from "./onboard-providers.js";
import { promptRemoteGatewayConfig } from "./onboard-remote.js";
import { setupSkills } from "./onboard-skills.js";
type WizardSection =
@@ -387,17 +388,14 @@ export async function runConfigureWizard(
) as "local" | "remote";
if (mode === "remote") {
note(
[
"Run on the gateway host:",
"- clawdis setup",
"- clawdis gateway-daemon --port 18789",
"- OAuth creds: ~/.clawdis/credentials/oauth.json",
"- Workspace: ~/clawd",
].join("\n"),
"Remote setup",
);
outro("Done. Local config unchanged.");
let remoteConfig = await promptRemoteGatewayConfig(baseConfig, runtime);
remoteConfig = applyWizardMetadata(remoteConfig, {
command: opts.command,
mode,
});
await writeConfigFile(remoteConfig);
runtime.log(`Updated ${CONFIG_PATH_CLAWDIS}`);
outro("Remote gateway configured.");
return;
}

View File

@@ -32,6 +32,9 @@ export function summarizeExistingConfig(config: ClawdisConfig): string {
if (config.agent?.model) rows.push(`model: ${config.agent.model}`);
if (config.gateway?.mode) rows.push(`gateway.mode: ${config.gateway.mode}`);
if (config.gateway?.bind) rows.push(`gateway.bind: ${config.gateway.bind}`);
if (config.gateway?.remote?.url) {
rows.push(`gateway.remote.url: ${config.gateway.remote.url}`);
}
if (config.skills?.install?.nodeManager) {
rows.push(`skills.nodeManager: ${config.skills.install.nodeManager}`);
}

View File

@@ -41,6 +41,7 @@ import {
summarizeExistingConfig,
} from "./onboard-helpers.js";
import { setupProviders } from "./onboard-providers.js";
import { promptRemoteGatewayConfig } from "./onboard-remote.js";
import { setupSkills } from "./onboard-skills.js";
import type {
AuthChoice,
@@ -126,17 +127,11 @@ export async function runInteractiveOnboarding(
) as OnboardMode);
if (mode === "remote") {
note(
[
"Run on the gateway host:",
"- clawdis setup",
"- clawdis gateway-daemon --port 18789",
"- OAuth creds: ~/.clawdis/credentials/oauth.json",
"- Workspace: ~/clawd",
].join("\n"),
"Remote setup",
);
outro("Done. Local config unchanged.");
let nextConfig = await promptRemoteGatewayConfig(baseConfig, runtime);
nextConfig = applyWizardMetadata(nextConfig, { command: "onboard", mode });
await writeConfigFile(nextConfig);
runtime.log(`Updated ${CONFIG_PATH_CLAWDIS}`);
outro("Remote gateway configured.");
return;
}

View File

@@ -35,19 +35,38 @@ export async function runNonInteractiveOnboarding(
const mode: OnboardMode = opts.mode ?? "local";
if (mode === "remote") {
const remoteUrl = opts.remoteUrl?.trim();
if (!remoteUrl) {
runtime.error("Missing --remote-url for remote mode.");
runtime.exit(1);
return;
}
let nextConfig: ClawdisConfig = {
...baseConfig,
gateway: {
...baseConfig.gateway,
mode: "remote",
remote: {
url: remoteUrl,
token: opts.remoteToken?.trim() || undefined,
},
},
};
nextConfig = applyWizardMetadata(nextConfig, { command: "onboard", mode });
await writeConfigFile(nextConfig);
runtime.log(`Updated ${CONFIG_PATH_CLAWDIS}`);
const payload = {
mode,
instructions: [
"clawdis setup",
"clawdis gateway-daemon --port 18789",
"OAuth creds: ~/.clawdis/credentials/oauth.json",
"Workspace: ~/clawd",
],
remoteUrl,
auth: opts.remoteToken ? "token" : "none",
};
if (opts.json) {
runtime.log(JSON.stringify(payload, null, 2));
} else {
runtime.log(payload.instructions.join("\n"));
runtime.log(`Remote gateway: ${remoteUrl}`);
runtime.log(`Auth: ${payload.auth}`);
}
return;
}

View File

@@ -0,0 +1,172 @@
import { confirm, note, select, spinner, text } from "@clack/prompts";
import type { ClawdisConfig } from "../config/config.js";
import type { GatewayBonjourBeacon } from "../infra/bonjour-discovery.js";
import { discoverGatewayBeacons } from "../infra/bonjour-discovery.js";
import type { RuntimeEnv } from "../runtime.js";
import { detectBinary, guardCancel } from "./onboard-helpers.js";
const DEFAULT_GATEWAY_URL = "ws://127.0.0.1:18789";
function pickHost(beacon: GatewayBonjourBeacon): string | undefined {
return beacon.tailnetDns || beacon.lanHost || beacon.host;
}
function buildLabel(beacon: GatewayBonjourBeacon): string {
const host = pickHost(beacon);
const port = beacon.gatewayPort ?? beacon.port ?? 18789;
const title = beacon.displayName ?? beacon.instanceName;
const hint = host ? `${host}:${port}` : "host unknown";
return `${title} (${hint})`;
}
function ensureWsUrl(value: string): string {
const trimmed = value.trim();
if (!trimmed) return DEFAULT_GATEWAY_URL;
return trimmed;
}
export async function promptRemoteGatewayConfig(
cfg: ClawdisConfig,
runtime: RuntimeEnv,
): Promise<ClawdisConfig> {
let selectedBeacon: GatewayBonjourBeacon | null = null;
let suggestedUrl = cfg.gateway?.remote?.url ?? DEFAULT_GATEWAY_URL;
const hasBonjourTool =
(await detectBinary("dns-sd")) || (await detectBinary("avahi-browse"));
const wantsDiscover = hasBonjourTool
? guardCancel(
await confirm({
message: "Discover gateway on LAN (Bonjour)?",
initialValue: true,
}),
runtime,
)
: false;
if (!hasBonjourTool) {
note(
"Bonjour discovery requires dns-sd (macOS) or avahi-browse (Linux).",
"Discovery",
);
}
if (wantsDiscover) {
const spin = spinner();
spin.start("Searching for gateways…");
const beacons = await discoverGatewayBeacons({ timeoutMs: 2000 });
spin.stop(
beacons.length > 0
? `Found ${beacons.length} gateway(s)`
: "No gateways found",
);
if (beacons.length > 0) {
const selection = guardCancel(
await select({
message: "Select gateway",
options: [
...beacons.map((beacon, index) => ({
value: String(index),
label: buildLabel(beacon),
})),
{ value: "manual", label: "Enter URL manually" },
],
}),
runtime,
);
if (selection !== "manual") {
const idx = Number.parseInt(String(selection), 10);
selectedBeacon = Number.isFinite(idx) ? (beacons[idx] ?? null) : null;
}
}
}
if (selectedBeacon) {
const host = pickHost(selectedBeacon);
const port = selectedBeacon.gatewayPort ?? 18789;
if (host) {
const mode = guardCancel(
await select({
message: "Connection method",
options: [
{
value: "direct",
label: `Direct gateway WS (${host}:${port})`,
},
{ value: "ssh", label: "SSH tunnel (loopback)" },
],
}),
runtime,
);
if (mode === "direct") {
suggestedUrl = `ws://${host}:${port}`;
} else {
suggestedUrl = DEFAULT_GATEWAY_URL;
note(
[
"Start a tunnel before using the CLI:",
`ssh -N -L 18789:127.0.0.1:18789 <user>@${host}${
selectedBeacon.sshPort ? ` -p ${selectedBeacon.sshPort}` : ""
}`,
].join("\n"),
"SSH tunnel",
);
}
}
}
const urlInput = guardCancel(
await text({
message: "Gateway WebSocket URL",
initialValue: suggestedUrl,
validate: (value) =>
String(value).trim().startsWith("ws://") ||
String(value).trim().startsWith("wss://")
? undefined
: "URL must start with ws:// or wss://",
}),
runtime,
);
const url = ensureWsUrl(String(urlInput));
const authChoice = guardCancel(
await select({
message: "Gateway auth",
options: [
{ value: "token", label: "Token (recommended)" },
{ value: "off", label: "No auth" },
],
}),
runtime,
) as "token" | "off";
let token = cfg.gateway?.remote?.token ?? "";
if (authChoice === "token") {
token = String(
guardCancel(
await text({
message: "Gateway token",
initialValue: token,
validate: (value) => (value?.trim() ? undefined : "Required"),
}),
runtime,
),
).trim();
} else {
token = "";
}
return {
...cfg,
gateway: {
...cfg.gateway,
mode: "remote",
remote: {
url,
token: token || undefined,
},
},
};
}

View File

@@ -24,5 +24,7 @@ export type OnboardOptions = {
skipSkills?: boolean;
skipHealth?: boolean;
nodeManager?: NodeManagerChoice;
remoteUrl?: string;
remoteToken?: string;
json?: boolean;
};