fix: normalize gateway cli option strings
This commit is contained in:
@@ -40,6 +40,7 @@ clawdbot doctor --non-interactive
|
|||||||
```
|
```
|
||||||
|
|
||||||
Run without prompts and only apply safe migrations (config normalization + on-disk state moves). Skips restart/service/sandbox actions that require human confirmation.
|
Run without prompts and only apply safe migrations (config normalization + on-disk state moves). Skips restart/service/sandbox actions that require human confirmation.
|
||||||
|
Legacy state migrations run automatically when detected.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
clawdbot doctor --deep
|
clawdbot doctor --deep
|
||||||
|
|||||||
@@ -74,6 +74,13 @@ function parsePort(raw: unknown): number | null {
|
|||||||
return parsed;
|
return parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const toOptionString = (value: unknown): string | undefined => {
|
||||||
|
if (typeof value === "string") return value;
|
||||||
|
if (typeof value === "number" || typeof value === "bigint")
|
||||||
|
return value.toString();
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
function describeUnknownError(err: unknown): string {
|
function describeUnknownError(err: unknown): string {
|
||||||
if (err instanceof Error) return err.message;
|
if (err instanceof Error) return err.message;
|
||||||
if (typeof err === "string") return err;
|
if (typeof err === "string") return err;
|
||||||
@@ -338,9 +345,10 @@ async function runGatewayCommand(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (opts.token) {
|
if (opts.token) {
|
||||||
process.env.CLAWDBOT_GATEWAY_TOKEN = String(opts.token);
|
const token = toOptionString(opts.token);
|
||||||
|
if (token) process.env.CLAWDBOT_GATEWAY_TOKEN = token;
|
||||||
}
|
}
|
||||||
const authModeRaw = opts.auth ? String(opts.auth) : undefined;
|
const authModeRaw = toOptionString(opts.auth);
|
||||||
const authMode: GatewayAuthMode | null =
|
const authMode: GatewayAuthMode | null =
|
||||||
authModeRaw === "token" || authModeRaw === "password" ? authModeRaw : null;
|
authModeRaw === "token" || authModeRaw === "password" ? authModeRaw : null;
|
||||||
if (authModeRaw && !authMode) {
|
if (authModeRaw && !authMode) {
|
||||||
@@ -348,7 +356,7 @@ async function runGatewayCommand(
|
|||||||
defaultRuntime.exit(1);
|
defaultRuntime.exit(1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const tailscaleRaw = opts.tailscale ? String(opts.tailscale) : undefined;
|
const tailscaleRaw = toOptionString(opts.tailscale);
|
||||||
const tailscaleMode =
|
const tailscaleMode =
|
||||||
tailscaleRaw === "off" ||
|
tailscaleRaw === "off" ||
|
||||||
tailscaleRaw === "serve" ||
|
tailscaleRaw === "serve" ||
|
||||||
@@ -362,6 +370,8 @@ async function runGatewayCommand(
|
|||||||
defaultRuntime.exit(1);
|
defaultRuntime.exit(1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const passwordRaw = toOptionString(opts.password);
|
||||||
|
const tokenRaw = toOptionString(opts.token);
|
||||||
const configExists = fs.existsSync(CONFIG_PATH_CLAWDBOT);
|
const configExists = fs.existsSync(CONFIG_PATH_CLAWDBOT);
|
||||||
const mode = cfg.gateway?.mode;
|
const mode = cfg.gateway?.mode;
|
||||||
if (!opts.allowUnconfigured && mode !== "local") {
|
if (!opts.allowUnconfigured && mode !== "local") {
|
||||||
@@ -377,7 +387,7 @@ async function runGatewayCommand(
|
|||||||
defaultRuntime.exit(1);
|
defaultRuntime.exit(1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const bindRaw = String(opts.bind ?? cfg.gateway?.bind ?? "loopback");
|
const bindRaw = toOptionString(opts.bind) ?? cfg.gateway?.bind ?? "loopback";
|
||||||
const bind =
|
const bind =
|
||||||
bindRaw === "loopback" ||
|
bindRaw === "loopback" ||
|
||||||
bindRaw === "tailnet" ||
|
bindRaw === "tailnet" ||
|
||||||
@@ -398,8 +408,8 @@ async function runGatewayCommand(
|
|||||||
const authConfig = {
|
const authConfig = {
|
||||||
...cfg.gateway?.auth,
|
...cfg.gateway?.auth,
|
||||||
...(authMode ? { mode: authMode } : {}),
|
...(authMode ? { mode: authMode } : {}),
|
||||||
...(opts.password ? { password: String(opts.password) } : {}),
|
...(passwordRaw ? { password: passwordRaw } : {}),
|
||||||
...(opts.token ? { token: String(opts.token) } : {}),
|
...(tokenRaw ? { token: tokenRaw } : {}),
|
||||||
};
|
};
|
||||||
const resolvedAuth = resolveGatewayAuth({
|
const resolvedAuth = resolveGatewayAuth({
|
||||||
authConfig,
|
authConfig,
|
||||||
@@ -467,11 +477,11 @@ async function runGatewayCommand(
|
|||||||
await startGatewayServer(port, {
|
await startGatewayServer(port, {
|
||||||
bind,
|
bind,
|
||||||
auth:
|
auth:
|
||||||
authMode || opts.password || opts.token || authModeRaw
|
authMode || passwordRaw || tokenRaw || authModeRaw
|
||||||
? {
|
? {
|
||||||
mode: authMode ?? undefined,
|
mode: authMode ?? undefined,
|
||||||
token: opts.token ? String(opts.token) : undefined,
|
token: tokenRaw,
|
||||||
password: opts.password ? String(opts.password) : undefined,
|
password: passwordRaw,
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
tailscale:
|
tailscale:
|
||||||
|
|||||||
Reference in New Issue
Block a user