feat: support configurable gateway port

This commit is contained in:
Peter Steinberger
2026-01-03 12:00:17 +01:00
parent 7199813969
commit f47c7ac369
23 changed files with 172 additions and 46 deletions

View File

@@ -15,6 +15,7 @@ import type { ClawdisConfig } from "../config/config.js";
import {
CONFIG_PATH_CLAWDIS,
readConfigFileSnapshot,
resolveGatewayPort,
writeConfigFile,
} from "../config/config.js";
import { GATEWAY_LAUNCH_AGENT_LABEL } from "../daemon/constants.js";
@@ -74,7 +75,7 @@ async function promptGatewayConfig(
const portRaw = guardCancel(
await text({
message: "Gateway port",
initialValue: "18789",
initialValue: String(resolveGatewayPort(cfg)),
validate: (value) =>
Number.isFinite(Number(value)) ? undefined : "Invalid port",
}),
@@ -205,6 +206,7 @@ async function promptGatewayConfig(
gateway: {
...next.gateway,
mode: "local",
port,
bind,
tailscale: {
...next.gateway?.tailscale,
@@ -527,7 +529,7 @@ export async function runConfigureWizard(
nextConfig.agent?.workspace ??
baseConfig.agent?.workspace ??
DEFAULT_WORKSPACE;
let gatewayPort = 18789;
let gatewayPort = resolveGatewayPort(baseConfig);
let gatewayToken: string | undefined;
if (selected.includes("workspace")) {

View File

@@ -34,6 +34,9 @@ export function summarizeExistingConfig(config: ClawdisConfig): string {
rows.push(`workspace: ${config.agent.workspace}`);
if (config.agent?.model) rows.push(`model: ${config.agent.model}`);
if (config.gateway?.mode) rows.push(`gateway.mode: ${config.gateway.mode}`);
if (typeof config.gateway?.port === "number") {
rows.push(`gateway.port: ${config.gateway.port}`);
}
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}`);

View File

@@ -14,6 +14,7 @@ import type { ClawdisConfig } from "../config/config.js";
import {
CONFIG_PATH_CLAWDIS,
readConfigFileSnapshot,
resolveGatewayPort,
writeConfigFile,
} from "../config/config.js";
import { GATEWAY_LAUNCH_AGENT_LABEL } from "../daemon/constants.js";
@@ -118,7 +119,8 @@ export async function runInteractiveOnboarding(
}
}
const localUrl = "ws://127.0.0.1:18789";
const localPort = resolveGatewayPort(baseConfig);
const localUrl = `ws://127.0.0.1:${localPort}`;
const localProbe = await probeGatewayReachable({
url: localUrl,
token: process.env.CLAWDIS_GATEWAY_TOKEN,
@@ -315,7 +317,7 @@ export async function runInteractiveOnboarding(
const portRaw = guardCancel(
await text({
message: "Gateway port",
initialValue: "18789",
initialValue: String(localPort),
validate: (value) =>
Number.isFinite(Number(value)) ? undefined : "Invalid port",
}),
@@ -457,6 +459,7 @@ export async function runInteractiveOnboarding(
...nextConfig,
gateway: {
...nextConfig.gateway,
port,
bind,
tailscale: {
...nextConfig.gateway?.tailscale,

View File

@@ -4,6 +4,7 @@ import {
type ClawdisConfig,
CONFIG_PATH_CLAWDIS,
readConfigFileSnapshot,
resolveGatewayPort,
writeConfigFile,
} from "../config/config.js";
import { GATEWAY_LAUNCH_AGENT_LABEL } from "../daemon/constants.js";
@@ -106,12 +107,18 @@ export async function runNonInteractiveOnboarding(
return;
}
const port = opts.gatewayPort ?? 18789;
if (!Number.isFinite(port) || port <= 0) {
const hasGatewayPort = opts.gatewayPort !== undefined;
if (
hasGatewayPort &&
(!Number.isFinite(opts.gatewayPort) || (opts.gatewayPort ?? 0) <= 0)
) {
runtime.error("Invalid --gateway-port");
runtime.exit(1);
return;
}
const port = hasGatewayPort
? (opts.gatewayPort as number)
: resolveGatewayPort(baseConfig);
let bind = opts.gatewayBind ?? "loopback";
let authMode = opts.gatewayAuth ?? "off";
const tailscaleMode = opts.tailscale ?? "off";
@@ -162,6 +169,7 @@ export async function runNonInteractiveOnboarding(
...nextConfig,
gateway: {
...nextConfig.gateway,
port,
bind,
tailscale: {
...nextConfig.gateway?.tailscale,