refactor: simplify cli conversions

This commit is contained in:
Peter Steinberger
2026-04-11 01:27:39 +01:00
parent 5c0d1c6a40
commit 1fb2e18f47
21 changed files with 24 additions and 25 deletions

View File

@@ -372,8 +372,9 @@ export function resolveMemoryBackendConfig(params: {
const mergedExtraCollections = [
...(params.cfg.agents?.defaults?.memorySearch?.qmd?.extraCollections ?? []),
...(agentEntry?.memorySearch?.qmd?.extraCollections ?? []),
].filter((value): value is MemoryQmdIndexPath =>
Boolean(value && typeof value === "object" && typeof value.path === "string"),
].filter(
(value): value is MemoryQmdIndexPath =>
value !== null && typeof value === "object" && typeof value.path === "string",
);
// Combine QMD-specific paths with extraPaths and per-agent cross-agent collections.

View File

@@ -50,7 +50,7 @@ export function detectChangedScope(changedPaths) {
let hasNonNativeNonDocs = false;
for (const rawPath of changedPaths) {
const path = String(rawPath).trim();
const path = rawPath.trim();
if (!path) {
continue;
}

View File

@@ -110,9 +110,7 @@ for (const abs of markdownFiles) {
if (!match) {
continue;
}
const permalink = String(match[1])
.trim()
.replace(/^['"]|['"]$/g, "");
const permalink = match[1].trim().replace(/^['"]|['"]$/g, "");
routes.add(normalizeRoute(permalink));
}

View File

@@ -1133,7 +1133,7 @@ export async function runConfigSet(opts: {
if (removedGatewayAuthPaths.length > 0) {
runtime.log(
info(
`Removed inactive ${removedGatewayAuthPaths.join(", ")} for gateway.auth.mode=${String(nextConfig.gateway?.auth?.mode ?? "<unset>")}.`,
`Removed inactive ${removedGatewayAuthPaths.join(", ")} for gateway.auth.mode=${nextConfig.gateway?.auth?.mode ?? "<unset>"}.`,
),
);
}

View File

@@ -48,7 +48,7 @@ export async function runDaemonInstall(opts: DaemonInstallOptions) {
fail("Invalid port");
return;
}
const runtimeRaw = opts.runtime ? String(opts.runtime) : DEFAULT_GATEWAY_DAEMON_RUNTIME;
const runtimeRaw = opts.runtime ? opts.runtime : DEFAULT_GATEWAY_DAEMON_RUNTIME;
if (!isGatewayDaemonRuntime(runtimeRaw)) {
fail('Invalid --runtime (use "node" or "bun")');
return;

View File

@@ -268,7 +268,7 @@ export function registerLogsCli(program: Command) {
let cursor: number | undefined;
let first = true;
const jsonMode = Boolean(opts.json);
const pretty = !jsonMode && Boolean(process.stdout.isTTY) && !opts.plain;
const pretty = !jsonMode && process.stdout.isTTY && !opts.plain;
const rich = isRich() && opts.color !== false;
const localTime =
Boolean(opts.localTime) || (!!process.env.TZ && isValidTimeZone(process.env.TZ));

View File

@@ -99,7 +99,7 @@ export async function runNodeDaemonInstall(opts: NodeDaemonInstallOptions) {
return;
}
const runtimeRaw = opts.runtime ? String(opts.runtime) : DEFAULT_NODE_DAEMON_RUNTIME;
const runtimeRaw = opts.runtime ? opts.runtime : DEFAULT_NODE_DAEMON_RUNTIME;
if (!isNodeDaemonRuntime(runtimeRaw)) {
fail('Invalid --runtime (use "node" or "bun")');
return;

View File

@@ -234,7 +234,7 @@ export function registerNodesStatusCommands(nodes: Command) {
.requiredOption("--node <idOrNameOrIp>", "Node id, name, or IP")
.action(async (opts: NodesRpcOpts) => {
await runNodesCommand("describe", async () => {
const nodeId = await resolveNodeId(opts, String(opts.node ?? ""));
const nodeId = await resolveNodeId(opts, opts.node ?? "");
const result = await callGatewayCli("node.describe", opts, {
nodeId,
});

View File

@@ -278,7 +278,7 @@ export async function tryWriteCompletionCache(root: string, jsonMode: boolean):
}
if (result.status !== 0 && !jsonMode) {
const stderr = (result.stderr ?? "").toString().trim();
const stderr = (result.stderr ?? "").trim();
const detail = stderr ? ` (${stderr})` : "";
defaultRuntime.log(theme.warn(`Completion cache update failed${detail}.`));
}

View File

@@ -680,7 +680,7 @@ async function maybeRestartService(params: {
process.env.OPENCLAW_UPDATE_IN_PROGRESS = "1";
try {
const interactiveDoctor =
Boolean(process.stdin.isTTY) && !params.opts.json && params.opts.yes !== true;
process.stdin.isTTY && !params.opts.json && params.opts.yes !== true;
await doctorCommand(defaultRuntime, {
nonInteractive: !interactiveDoctor,
});

View File

@@ -141,7 +141,7 @@ export async function updateWizardCommand(opts: UpdateWizardOptions = {}): Promi
try {
await updateCommand({
channel: requestedChannel ?? undefined,
restart: Boolean(restart),
restart,
timeout: opts.timeout,
});
} catch (err) {

View File

@@ -190,7 +190,7 @@ async function resolveChannelReports(params: {
includeActions: true,
}).actions;
const actions = Array.from(
new Set<string>(["send", "broadcast", ...discoveredActions.map((action) => String(action))]),
new Set<string>(["send", "broadcast", ...discoveredActions.map((action) => action)]),
);
reports.push({

View File

@@ -324,7 +324,7 @@ export async function maybeRepairGatewayServiceConfig(
const repair = needsAggressive
? await prompter.confirmAggressiveAutoFix({
message: "Overwrite gateway service config with current defaults now?",
initialValue: Boolean(prompter.shouldForce),
initialValue: prompter.shouldForce,
})
: await prompter.confirmAutoFix({
message: "Update gateway service config to the recommended defaults now?",

View File

@@ -14,7 +14,7 @@ export function resolveDoctorRepairMode(options: DoctorOptions): DoctorRepairMod
const requestedNonInteractive = options.nonInteractive === true;
const shouldRepair = options.repair === true || yes;
const shouldForce = options.force === true;
const isTty = Boolean(process.stdin.isTTY);
const isTty = process.stdin.isTTY;
const nonInteractive = requestedNonInteractive || (!isTty && !yes);
const updateInProgress = isTruthyEnvValue(process.env.OPENCLAW_UPDATE_IN_PROGRESS);
const canPrompt = isTty && !yes && !nonInteractive;

View File

@@ -82,7 +82,7 @@ async function dockerImageExists(image: string): Promise<boolean> {
(error as { stderr: string } | undefined)?.stderr ||
(error as { message: string } | undefined)?.message ||
"";
if (String(stderr).includes("No such image")) {
if (stderr.includes("No such image")) {
return false;
}
throw error;

View File

@@ -38,7 +38,7 @@ export async function maybeOfferUpdateBeforeDoctor(params: {
params.options.nonInteractive !== true &&
params.options.yes !== true &&
params.options.repair !== true &&
Boolean(process.stdin.isTTY);
process.stdin.isTTY;
if (!canOfferUpdate || !params.root) {
return { updated: false };
}

View File

@@ -17,7 +17,7 @@ export function createStorageMock(): Storage {
store.delete(key);
},
setItem(key: string, value: string) {
store.set(key, String(value));
store.set(key, value);
},
};
}

View File

@@ -412,8 +412,8 @@ export function renderApp(state: AppViewState) {
const chatDisabledReason = state.connected ? null : t("chat.disconnected");
const isChat = state.tab === "chat";
const chatFocus = isChat && (state.settings.chatFocusMode || state.onboarding);
const navDrawerOpen = Boolean(state.navDrawerOpen && !chatFocus && !state.onboarding);
const navCollapsed = Boolean(state.settings.navCollapsed && !navDrawerOpen);
const navDrawerOpen = state.navDrawerOpen && !chatFocus && !state.onboarding;
const navCollapsed = state.settings.navCollapsed && !navDrawerOpen;
const showThinking = state.onboarding ? false : state.settings.chatShowThinking;
const showToolCalls = state.onboarding ? true : state.settings.chatShowToolCalls;
const assistantAvatarUrl = resolveAssistantAvatarUrl(state);

View File

@@ -124,7 +124,7 @@ export async function loadLogs(state: LogsState, opts?: { reset?: boolean; quiet
? payload.lines.filter((line) => typeof line === "string")
: [];
const entries = lines.map(parseLogLine);
const shouldReset = Boolean(opts?.reset || payload.reset || state.logsCursor == null);
const shouldReset = opts?.reset || payload.reset || state.logsCursor == null;
state.logsEntries = shouldReset
? entries
: [...state.logsEntries, ...entries].slice(-LOG_BUFFER_LIMIT);

View File

@@ -319,7 +319,7 @@ export class GatewayBrowserClient {
this.ws.addEventListener("open", () => this.queueConnect());
this.ws.addEventListener("message", (ev) => this.handleMessage(String(ev.data ?? "")));
this.ws.addEventListener("close", (ev) => {
const reason = String(ev.reason ?? "");
const reason = ev.reason ?? "";
const connectError = this.pendingConnectError;
this.pendingConnectError = undefined;
this.ws = null;

View File

@@ -89,7 +89,7 @@ function resolveExecApprovalsDefaults(
security: normalizeSecurity(defaults.security),
ask: normalizeAsk(defaults.ask),
askFallback: normalizeSecurity(defaults.askFallback ?? "deny"),
autoAllowSkills: Boolean(defaults.autoAllowSkills ?? false),
autoAllowSkills: defaults.autoAllowSkills ?? false,
};
}