From 1fb2e18f47e0a299292944d5e7a2fa7912a488a7 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 11 Apr 2026 01:27:39 +0100 Subject: [PATCH] refactor: simplify cli conversions --- packages/memory-host-sdk/src/host/backend-config.ts | 5 +++-- scripts/ci-changed-scope.mjs | 2 +- scripts/docs-link-audit.mjs | 4 +--- src/cli/config-cli.ts | 2 +- src/cli/daemon-cli/install.ts | 2 +- src/cli/logs-cli.ts | 2 +- src/cli/node-cli/daemon.ts | 2 +- src/cli/nodes-cli/register.status.ts | 2 +- src/cli/update-cli/shared.ts | 2 +- src/cli/update-cli/update-command.ts | 2 +- src/cli/update-cli/wizard.ts | 2 +- src/commands/channels/capabilities.ts | 2 +- src/commands/doctor-gateway-services.ts | 2 +- src/commands/doctor-repair-mode.ts | 2 +- src/commands/doctor-sandbox.ts | 2 +- src/commands/doctor-update.ts | 2 +- ui/src/test-helpers/storage.ts | 2 +- ui/src/ui/app-render.ts | 4 ++-- ui/src/ui/controllers/logs.ts | 2 +- ui/src/ui/gateway.ts | 2 +- ui/src/ui/views/nodes-exec-approvals.ts | 2 +- 21 files changed, 24 insertions(+), 25 deletions(-) diff --git a/packages/memory-host-sdk/src/host/backend-config.ts b/packages/memory-host-sdk/src/host/backend-config.ts index 3ea71d207f3..8d5b2804880 100644 --- a/packages/memory-host-sdk/src/host/backend-config.ts +++ b/packages/memory-host-sdk/src/host/backend-config.ts @@ -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. diff --git a/scripts/ci-changed-scope.mjs b/scripts/ci-changed-scope.mjs index 40244ce2ceb..cfab1b9c61e 100644 --- a/scripts/ci-changed-scope.mjs +++ b/scripts/ci-changed-scope.mjs @@ -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; } diff --git a/scripts/docs-link-audit.mjs b/scripts/docs-link-audit.mjs index 8c49d014c9d..85da5c4ac3a 100644 --- a/scripts/docs-link-audit.mjs +++ b/scripts/docs-link-audit.mjs @@ -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)); } diff --git a/src/cli/config-cli.ts b/src/cli/config-cli.ts index a3626f2b15f..33d3d6185b8 100644 --- a/src/cli/config-cli.ts +++ b/src/cli/config-cli.ts @@ -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 ?? "")}.`, + `Removed inactive ${removedGatewayAuthPaths.join(", ")} for gateway.auth.mode=${nextConfig.gateway?.auth?.mode ?? ""}.`, ), ); } diff --git a/src/cli/daemon-cli/install.ts b/src/cli/daemon-cli/install.ts index 756df7a26ec..ddf15a021d2 100644 --- a/src/cli/daemon-cli/install.ts +++ b/src/cli/daemon-cli/install.ts @@ -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; diff --git a/src/cli/logs-cli.ts b/src/cli/logs-cli.ts index 8a630c0f67a..d51541fc650 100644 --- a/src/cli/logs-cli.ts +++ b/src/cli/logs-cli.ts @@ -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)); diff --git a/src/cli/node-cli/daemon.ts b/src/cli/node-cli/daemon.ts index bfe45895029..53c84f508b9 100644 --- a/src/cli/node-cli/daemon.ts +++ b/src/cli/node-cli/daemon.ts @@ -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; diff --git a/src/cli/nodes-cli/register.status.ts b/src/cli/nodes-cli/register.status.ts index ffb12c5919c..013207d7079 100644 --- a/src/cli/nodes-cli/register.status.ts +++ b/src/cli/nodes-cli/register.status.ts @@ -234,7 +234,7 @@ export function registerNodesStatusCommands(nodes: Command) { .requiredOption("--node ", "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, }); diff --git a/src/cli/update-cli/shared.ts b/src/cli/update-cli/shared.ts index 8efbee06739..78fd160941a 100644 --- a/src/cli/update-cli/shared.ts +++ b/src/cli/update-cli/shared.ts @@ -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}.`)); } diff --git a/src/cli/update-cli/update-command.ts b/src/cli/update-cli/update-command.ts index 5da29a925f6..ddfb1e6c47c 100644 --- a/src/cli/update-cli/update-command.ts +++ b/src/cli/update-cli/update-command.ts @@ -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, }); diff --git a/src/cli/update-cli/wizard.ts b/src/cli/update-cli/wizard.ts index e2b53b7afa8..d1de48f5c37 100644 --- a/src/cli/update-cli/wizard.ts +++ b/src/cli/update-cli/wizard.ts @@ -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) { diff --git a/src/commands/channels/capabilities.ts b/src/commands/channels/capabilities.ts index 3c75a838db9..64ad0aa67b1 100644 --- a/src/commands/channels/capabilities.ts +++ b/src/commands/channels/capabilities.ts @@ -190,7 +190,7 @@ async function resolveChannelReports(params: { includeActions: true, }).actions; const actions = Array.from( - new Set(["send", "broadcast", ...discoveredActions.map((action) => String(action))]), + new Set(["send", "broadcast", ...discoveredActions.map((action) => action)]), ); reports.push({ diff --git a/src/commands/doctor-gateway-services.ts b/src/commands/doctor-gateway-services.ts index 308eb0ce8f7..4aa79502059 100644 --- a/src/commands/doctor-gateway-services.ts +++ b/src/commands/doctor-gateway-services.ts @@ -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?", diff --git a/src/commands/doctor-repair-mode.ts b/src/commands/doctor-repair-mode.ts index 267da20da8a..97bd859cfd2 100644 --- a/src/commands/doctor-repair-mode.ts +++ b/src/commands/doctor-repair-mode.ts @@ -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; diff --git a/src/commands/doctor-sandbox.ts b/src/commands/doctor-sandbox.ts index ae336e155b1..4178e707303 100644 --- a/src/commands/doctor-sandbox.ts +++ b/src/commands/doctor-sandbox.ts @@ -82,7 +82,7 @@ async function dockerImageExists(image: string): Promise { (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; diff --git a/src/commands/doctor-update.ts b/src/commands/doctor-update.ts index a4bcf32648d..b28d3a676ef 100644 --- a/src/commands/doctor-update.ts +++ b/src/commands/doctor-update.ts @@ -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 }; } diff --git a/ui/src/test-helpers/storage.ts b/ui/src/test-helpers/storage.ts index 60682f74908..0ad4ce4fd38 100644 --- a/ui/src/test-helpers/storage.ts +++ b/ui/src/test-helpers/storage.ts @@ -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); }, }; } diff --git a/ui/src/ui/app-render.ts b/ui/src/ui/app-render.ts index 3b4f81a1f9d..0e2a7ebee6b 100644 --- a/ui/src/ui/app-render.ts +++ b/ui/src/ui/app-render.ts @@ -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); diff --git a/ui/src/ui/controllers/logs.ts b/ui/src/ui/controllers/logs.ts index ac9cc6b1e4c..27f08a2893c 100644 --- a/ui/src/ui/controllers/logs.ts +++ b/ui/src/ui/controllers/logs.ts @@ -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); diff --git a/ui/src/ui/gateway.ts b/ui/src/ui/gateway.ts index 1d2c6f108f8..3505b1d66c2 100644 --- a/ui/src/ui/gateway.ts +++ b/ui/src/ui/gateway.ts @@ -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; diff --git a/ui/src/ui/views/nodes-exec-approvals.ts b/ui/src/ui/views/nodes-exec-approvals.ts index 9e261817399..dc20cfd33a2 100644 --- a/ui/src/ui/views/nodes-exec-approvals.ts +++ b/ui/src/ui/views/nodes-exec-approvals.ts @@ -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, }; }