Files
openclaw/src/commands/status.scan.bootstrap-shared.ts
charles-openclaw a6f4de4a66 feat(gateway): support Tailscale Serve service names
Adds optional `gateway.tailscale.serviceName` support for Tailscale Serve so the Gateway Control UI can be exposed through a named Tailscale Service while existing hostname-based Serve and Funnel behavior stays unchanged.

The implementation validates `svc:<dns-label>`, passes the Service name to `tailscale serve`, clears named Service config with `tailscale serve clear <service>` when resetOnExit runs, and uses the derived Service hostname in startup logs, status output, and pairing URLs.

Verification:
- node scripts/run-vitest.mjs src/infra/tailscale.test.ts src/gateway/server-tailscale.test.ts src/config/config.gateway-tailscale-bind.test.ts src/gateway/startup-auth.test.ts src/commands/status.scan.shared.test.ts src/pairing/setup-code.test.ts
- .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main --parallel-tests "node scripts/run-vitest.mjs src/infra/tailscale.test.ts src/gateway/server-tailscale.test.ts src/config/config.gateway-tailscale-bind.test.ts src/gateway/startup-auth.test.ts src/commands/status.scan.shared.test.ts src/pairing/setup-code.test.ts"
- git diff --check
- git merge-tree --write-tree origin/main origin/pr/88691

Closes #88629.
Co-authored-by: Charles OpenClaw <charles-openclaw@9bcfae.inboxapi.ai>
2026-05-31 20:05:02 +01:00

140 lines
4.6 KiB
TypeScript

import type { OpenClawConfig } from "../config/types.js";
import type { UpdateCheckResult } from "../infra/update-check.js";
import { runExec } from "../process/exec.js";
import { createEmptyTaskAuditSummary } from "../tasks/task-registry.audit.shared.js";
import { createEmptyTaskRegistrySummary } from "../tasks/task-registry.summary.js";
import { buildTailscaleHttpsUrl, resolveGatewayProbeSnapshot } from "./status.scan.shared.js";
function buildColdStartUpdateResult(): UpdateCheckResult {
return {
root: null,
installKind: "unknown",
packageManager: "unknown",
};
}
function buildColdStartAgentLocalStatuses() {
return {
defaultId: "main",
agents: [],
totalSessions: 0,
bootstrapPendingCount: 0,
};
}
export function buildColdStartStatusSummary() {
return {
runtimeVersion: null,
heartbeat: {
defaultAgentId: "main",
agents: [],
},
channelSummary: [],
queuedSystemEvents: [],
tasks: createEmptyTaskRegistrySummary(),
taskAudit: createEmptyTaskAuditSummary(),
sessions: {
paths: [],
count: 0,
defaults: { model: null, contextTokens: null },
recent: [],
byAgent: [],
},
};
}
function shouldSkipStatusScanNetworkChecks(params: {
coldStart: boolean;
hasConfiguredChannels: boolean;
all?: boolean;
}): boolean {
return params.coldStart && !params.hasConfiguredChannels && params.all !== true;
}
type StatusScanExecRunner = (
command: string,
args: string[],
opts?: number | { timeoutMs?: number; maxBuffer?: number; cwd?: string },
) => Promise<{ stdout: string; stderr: string }>;
type StatusScanCoreBootstrapParams<TAgentStatus> = {
coldStart: boolean;
cfg: OpenClawConfig;
hasConfiguredChannels: boolean;
opts: { timeoutMs?: number; all?: boolean };
skipUpdateCheck?: boolean;
fetchGitUpdate?: boolean;
includeRegistryUpdate?: boolean;
includeLocalStatusRpcFallback?: boolean;
gatewayProbeTimeoutMs?: number;
getTailnetHostname: (runner: StatusScanExecRunner) => Promise<string | null>;
getUpdateCheckResult: (params: {
timeoutMs: number;
fetchGit: boolean;
includeRegistry: boolean;
updateConfigChannel?: string | null;
}) => Promise<UpdateCheckResult>;
getAgentLocalStatuses: (cfg: OpenClawConfig) => Promise<TAgentStatus>;
};
export async function createStatusScanCoreBootstrap<TAgentStatus>(
params: StatusScanCoreBootstrapParams<TAgentStatus>,
) {
const tailscaleMode = params.cfg.gateway?.tailscale?.mode ?? "off";
const skipColdStartNetworkChecks = shouldSkipStatusScanNetworkChecks({
coldStart: params.coldStart,
hasConfiguredChannels: params.hasConfiguredChannels,
all: params.opts.all,
});
const statusTimeoutMs = params.opts.timeoutMs ?? 10_000;
const updateTimeoutMs = Math.min(params.opts.all ? 6500 : 2500, statusTimeoutMs);
const tailscaleTimeoutMs = Math.min(1200, statusTimeoutMs);
const tailscaleDnsPromise =
tailscaleMode === "off"
? Promise.resolve<string | null>(null)
: params
.getTailnetHostname((cmd, args) =>
runExec(cmd, args, { timeoutMs: tailscaleTimeoutMs, maxBuffer: 200_000 }),
)
.catch(() => null);
const skipNetworkUpdate = skipColdStartNetworkChecks || params.skipUpdateCheck === true;
const updatePromise = skipNetworkUpdate
? Promise.resolve(buildColdStartUpdateResult())
: params.getUpdateCheckResult({
timeoutMs: updateTimeoutMs,
fetchGit: params.fetchGitUpdate ?? true,
includeRegistry: params.includeRegistryUpdate ?? true,
updateConfigChannel: params.cfg.update?.channel ?? null,
});
const agentStatusPromise = skipColdStartNetworkChecks
? Promise.resolve(buildColdStartAgentLocalStatuses() as TAgentStatus)
: params.getAgentLocalStatuses(params.cfg);
const gatewayProbePromise = resolveGatewayProbeSnapshot({
cfg: params.cfg,
opts: {
...params.opts,
...(params.gatewayProbeTimeoutMs !== undefined
? { timeoutMs: params.gatewayProbeTimeoutMs }
: {}),
...(skipColdStartNetworkChecks ? { skipProbe: true } : {}),
localStatusRpcFallback: params.includeLocalStatusRpcFallback !== false,
},
});
return {
tailscaleMode,
tailscaleDnsPromise,
updatePromise,
agentStatusPromise,
gatewayProbePromise,
skipColdStartNetworkChecks,
resolveTailscaleHttpsUrl: async () =>
buildTailscaleHttpsUrl({
tailscaleMode,
tailscaleDns: await tailscaleDnsPromise,
serviceName: params.cfg.gateway?.tailscale?.serviceName,
controlUiBasePath: params.cfg.gateway?.controlUi?.basePath,
}),
};
}