From 23fae00fad70328c3bee9c25ba136dbbaf19d609 Mon Sep 17 00:00:00 2001 From: Tak Hoffman <781889+Takhoffman@users.noreply.github.com> Date: Fri, 27 Mar 2026 01:46:34 -0500 Subject: [PATCH] Reduce script logging suppressions and Feishu any casts --- extensions/voice-call/src/cli.ts | 83 ++++++++----------- scripts/check-ts-max-loc.ts | 7 +- .../dev/discord-acp-plain-language-smoke.ts | 63 +++++++------- scripts/dev/gateway-smoke.ts | 23 ++--- scripts/dev/ios-node-e2e.ts | 66 +++++++-------- scripts/dev/test-device-pair-telegram.ts | 17 ++-- scripts/label-open-issues.ts | 25 +++--- 7 files changed, 135 insertions(+), 149 deletions(-) diff --git a/extensions/voice-call/src/cli.ts b/extensions/voice-call/src/cli.ts index 322a9dae355..439011793e3 100644 --- a/extensions/voice-call/src/cli.ts +++ b/extensions/voice-call/src/cli.ts @@ -1,6 +1,7 @@ import fs from "node:fs"; import os from "node:os"; import path from "node:path"; +import { format } from "node:util"; import type { Command } from "commander"; import { sleep } from "../api.js"; import type { VoiceCallConfig } from "./config.js"; @@ -18,6 +19,14 @@ type Logger = { error: (message: string) => void; }; +function writeStdoutLine(...values: unknown[]): void { + process.stdout.write(`${format(...values)}\n`); +} + +function writeStdoutJson(value: unknown): void { + process.stdout.write(`${JSON.stringify(value, null, 2)}\n`); +} + function resolveMode(input: string): "off" | "serve" | "funnel" { const raw = input.trim().toLowerCase(); if (raw === "serve" || raw === "off") { @@ -98,8 +107,7 @@ async function initiateCallAndPrintId(params: { if (!result.success) { throw new Error(result.error || "initiate failed"); } - // eslint-disable-next-line no-console - console.log(JSON.stringify({ callId: result.callId }, null, 2)); + writeStdoutJson({ callId: result.callId }); } export function registerVoiceCallCli(params: { @@ -172,8 +180,7 @@ export function registerVoiceCallCli(params: { if (!result.success) { throw new Error(result.error || "continue failed"); } - // eslint-disable-next-line no-console - console.log(JSON.stringify(result, null, 2)); + writeStdoutJson(result); }); root @@ -187,8 +194,7 @@ export function registerVoiceCallCli(params: { if (!result.success) { throw new Error(result.error || "speak failed"); } - // eslint-disable-next-line no-console - console.log(JSON.stringify(result, null, 2)); + writeStdoutJson(result); }); root @@ -201,8 +207,7 @@ export function registerVoiceCallCli(params: { if (!result.success) { throw new Error(result.error || "end failed"); } - // eslint-disable-next-line no-console - console.log(JSON.stringify(result, null, 2)); + writeStdoutJson(result); }); root @@ -212,8 +217,7 @@ export function registerVoiceCallCli(params: { .action(async (options: { callId: string }) => { const rt = await ensureRuntime(); const call = rt.manager.getCall(options.callId); - // eslint-disable-next-line no-console - console.log(JSON.stringify(call ?? { found: false }, null, 2)); + writeStdoutJson(call ?? { found: false }); }); root @@ -235,8 +239,7 @@ export function registerVoiceCallCli(params: { const initial = fs.readFileSync(file, "utf8"); const lines = initial.split("\n").filter(Boolean); for (const line of lines.slice(Math.max(0, lines.length - since))) { - // eslint-disable-next-line no-console - console.log(line); + writeStdoutLine(line); } let offset = Buffer.byteLength(initial, "utf8"); @@ -255,8 +258,7 @@ export function registerVoiceCallCli(params: { offset = stat.size; const text = buf.toString("utf8"); for (const line of text.split("\n").filter(Boolean)) { - // eslint-disable-next-line no-console - console.log(line); + writeStdoutLine(line); } } finally { fs.closeSync(fd); @@ -306,18 +308,11 @@ export function registerVoiceCallCli(params: { } } - // eslint-disable-next-line no-console - console.log( - JSON.stringify( - { - recordsScanned: lines.length, - turnLatency: summarizeSeries(turnLatencyMs), - listenWait: summarizeSeries(listenWaitMs), - }, - null, - 2, - ), - ); + writeStdoutJson({ + recordsScanned: lines.length, + turnLatency: summarizeSeries(turnLatencyMs), + listenWait: summarizeSeries(listenWaitMs), + }); }); root @@ -339,8 +334,7 @@ export function registerVoiceCallCli(params: { if (mode === "off") { await cleanupTailscaleExposureRoute({ mode: "serve", path: tsPath }); await cleanupTailscaleExposureRoute({ mode: "funnel", path: tsPath }); - // eslint-disable-next-line no-console - console.log(JSON.stringify({ ok: true, mode: "off", path: tsPath }, null, 2)); + writeStdoutJson({ ok: true, mode: "off", path: tsPath }); return; } @@ -355,26 +349,19 @@ export function registerVoiceCallCli(params: { ? `https://login.tailscale.com/f/${mode}?node=${tsInfo.nodeId}` : null; - // eslint-disable-next-line no-console - console.log( - JSON.stringify( - { - ok: Boolean(publicUrl), - mode, - path: tsPath, - localUrl, - publicUrl, - hint: publicUrl - ? undefined - : { - note: "Tailscale serve/funnel may be disabled on this tailnet (or require admin enable).", - enableUrl, - }, - }, - null, - 2, - ), - ); + writeStdoutJson({ + ok: Boolean(publicUrl), + mode, + path: tsPath, + localUrl, + publicUrl, + hint: publicUrl + ? undefined + : { + note: "Tailscale serve/funnel may be disabled on this tailnet (or require admin enable).", + enableUrl, + }, + }); }, ); } diff --git a/scripts/check-ts-max-loc.ts b/scripts/check-ts-max-loc.ts index 88b9a0d477e..ae388798b51 100644 --- a/scripts/check-ts-max-loc.ts +++ b/scripts/check-ts-max-loc.ts @@ -2,6 +2,10 @@ import { execFileSync } from "node:child_process"; import { existsSync } from "node:fs"; import { readFile } from "node:fs/promises"; +function writeStdoutLine(message: string): void { + process.stdout.write(`${message}\n`); +} + type ParsedArgs = { maxLines: number; }; @@ -70,8 +74,7 @@ async function main() { // Minimal, grep-friendly output. for (const offender of offenders) { - // eslint-disable-next-line no-console - console.log(`${offender.lines}\t${offender.filePath}`); + writeStdoutLine(`${offender.lines}\t${offender.filePath}`); } process.exitCode = 1; diff --git a/scripts/dev/discord-acp-plain-language-smoke.ts b/scripts/dev/discord-acp-plain-language-smoke.ts index 50c04c589de..199745c88ae 100644 --- a/scripts/dev/discord-acp-plain-language-smoke.ts +++ b/scripts/dev/discord-acp-plain-language-smoke.ts @@ -7,6 +7,18 @@ import fs from "node:fs/promises"; import path from "node:path"; import { promisify } from "node:util"; +function writeStdoutLine(message: string): void { + process.stdout.write(`${message}\n`); +} + +function writeStdoutJson(value: unknown): void { + process.stdout.write(`${JSON.stringify(value, null, 2)}\n`); +} + +function writeStderrLine(message: string): void { + process.stderr.write(`${message}\n`); +} + type ThreadBindingRecord = { accountId?: string; channelId?: string; @@ -482,55 +494,39 @@ async function loadParentRecentMessages(params: { function printOutput(params: { json: boolean; payload: SuccessResult | FailureResult }) { if (params.json) { - // eslint-disable-next-line no-console - console.log(JSON.stringify(params.payload, null, 2)); + writeStdoutJson(params.payload); return; } if (params.payload.ok) { const success = params.payload; - // eslint-disable-next-line no-console - console.log("PASS"); - // eslint-disable-next-line no-console - console.log(`smokeId: ${success.smokeId}`); - // eslint-disable-next-line no-console - console.log(`sentMessageId: ${success.sentMessageId}`); - // eslint-disable-next-line no-console - console.log(`threadId: ${success.binding.threadId}`); - // eslint-disable-next-line no-console - console.log(`sessionKey: ${success.binding.targetSessionKey}`); - // eslint-disable-next-line no-console - console.log(`ackMessageId: ${success.ackMessage.id}`); - // eslint-disable-next-line no-console - console.log( + writeStdoutLine("PASS"); + writeStdoutLine(`smokeId: ${success.smokeId}`); + writeStdoutLine(`sentMessageId: ${success.sentMessageId}`); + writeStdoutLine(`threadId: ${success.binding.threadId}`); + writeStdoutLine(`sessionKey: ${success.binding.targetSessionKey}`); + writeStdoutLine(`ackMessageId: ${success.ackMessage.id}`); + writeStdoutLine( `ackAuthor: ${success.ackMessage.authorUsername || success.ackMessage.authorId || "unknown"}`, ); return; } const failure = params.payload; - // eslint-disable-next-line no-console - console.error("FAIL"); - // eslint-disable-next-line no-console - console.error(`stage: ${failure.stage}`); - // eslint-disable-next-line no-console - console.error(`smokeId: ${failure.smokeId}`); - // eslint-disable-next-line no-console - console.error(`error: ${failure.error}`); + writeStderrLine("FAIL"); + writeStderrLine(`stage: ${failure.stage}`); + writeStderrLine(`smokeId: ${failure.smokeId}`); + writeStderrLine(`error: ${failure.error}`); if (failure.diagnostics?.bindingCandidates?.length) { - // eslint-disable-next-line no-console - console.error("binding candidates:"); + writeStderrLine("binding candidates:"); for (const candidate of failure.diagnostics.bindingCandidates) { - // eslint-disable-next-line no-console - console.error( + writeStderrLine( ` thread=${candidate.threadId} kind=${candidate.targetKind || "?"} agent=${candidate.agentId || "?"} boundAt=${candidate.boundAt || 0} session=${candidate.targetSessionKey}`, ); } } if (failure.diagnostics?.parentChannelRecent?.length) { - // eslint-disable-next-line no-console - console.error("recent parent channel messages:"); + writeStderrLine("recent parent channel messages:"); for (const row of failure.diagnostics.parentChannelRecent) { - // eslint-disable-next-line no-console - console.error(` ${row.id} ${row.author}${row.bot ? " [bot]" : ""}: ${row.content || ""}`); + writeStderrLine(` ${row.id} ${row.author}${row.bot ? " [bot]" : ""}: ${row.content || ""}`); } } } @@ -825,8 +821,7 @@ async function run(): Promise { } if (hasFlag("--help") || hasFlag("-h")) { - // eslint-disable-next-line no-console - console.log(usage()); + writeStdoutLine(usage()); process.exit(0); } diff --git a/scripts/dev/gateway-smoke.ts b/scripts/dev/gateway-smoke.ts index 63bec21a4b9..85b63335987 100644 --- a/scripts/dev/gateway-smoke.ts +++ b/scripts/dev/gateway-smoke.ts @@ -1,12 +1,19 @@ import { createArgReader, createGatewayWsClient, resolveGatewayUrl } from "./gateway-ws-client.ts"; +function writeStdoutLine(message: string): void { + process.stdout.write(`${message}\n`); +} + +function writeStderrLine(message: string): void { + process.stderr.write(`${message}\n`); +} + const { get: getArg } = createArgReader(); const urlRaw = getArg("--url") ?? process.env.OPENCLAW_GATEWAY_URL; const token = getArg("--token") ?? process.env.OPENCLAW_GATEWAY_TOKEN; if (!urlRaw || !token) { - // eslint-disable-next-line no-console - console.error( + writeStderrLine( "Usage: bun scripts/dev/gateway-smoke.ts --url --token \n" + "Or set env: OPENCLAW_GATEWAY_URL / OPENCLAW_GATEWAY_TOKEN", ); @@ -48,27 +55,23 @@ async function main() { }); if (!connectRes.ok) { - // eslint-disable-next-line no-console - console.error("connect failed:", connectRes.error); + writeStderrLine(`connect failed: ${String(connectRes.error)}`); process.exit(2); } const healthRes = await request("health"); if (!healthRes.ok) { - // eslint-disable-next-line no-console - console.error("health failed:", healthRes.error); + writeStderrLine(`health failed: ${String(healthRes.error)}`); process.exit(3); } const historyRes = await request("chat.history", { sessionKey: "main" }, 15000); if (!historyRes.ok) { - // eslint-disable-next-line no-console - console.error("chat.history failed:", historyRes.error); + writeStderrLine(`chat.history failed: ${String(historyRes.error)}`); process.exit(4); } - // eslint-disable-next-line no-console - console.log("ok: connected + health + chat.history"); + writeStdoutLine("ok: connected + health + chat.history"); close(); } diff --git a/scripts/dev/ios-node-e2e.ts b/scripts/dev/ios-node-e2e.ts index 6885a32d74f..525e86ac17d 100644 --- a/scripts/dev/ios-node-e2e.ts +++ b/scripts/dev/ios-node-e2e.ts @@ -1,5 +1,17 @@ import { createArgReader, createGatewayWsClient, resolveGatewayUrl } from "./gateway-ws-client.ts"; +function writeStdoutLine(message = ""): void { + process.stdout.write(`${message}\n`); +} + +function writeStdoutJson(value: unknown): void { + process.stdout.write(`${JSON.stringify(value, null, 2)}\n`); +} + +function writeStderrLine(message: string): void { + process.stderr.write(`${message}\n`); +} + type NodeListPayload = { ts?: number; nodes?: Array<{ @@ -24,8 +36,7 @@ const dangerous = hasFlag("--dangerous") || process.env.OPENCLAW_RUN_DANGEROUS = const jsonOut = hasFlag("--json"); if (!urlRaw || !token) { - // eslint-disable-next-line no-console - console.error( + writeStderrLine( "Usage: bun scripts/dev/ios-node-e2e.ts --url --token [--node ] [--dangerous] [--json]\n" + "Or set env: OPENCLAW_GATEWAY_URL / OPENCLAW_GATEWAY_TOKEN", ); @@ -105,24 +116,21 @@ async function main() { }); if (!connectRes.ok) { - // eslint-disable-next-line no-console - console.error("connect failed:", connectRes.error); + writeStderrLine(`connect failed: ${String(connectRes.error)}`); close(); process.exit(2); } const healthRes = await request("health"); if (!healthRes.ok) { - // eslint-disable-next-line no-console - console.error("health failed:", healthRes.error); + writeStderrLine(`health failed: ${String(healthRes.error)}`); close(); process.exit(3); } const nodesRes = await request("node.list"); if (!nodesRes.ok) { - // eslint-disable-next-line no-console - console.error("node.list failed:", nodesRes.error); + writeStderrLine(`node.list failed: ${String(nodesRes.error)}`); close(); process.exit(4); } @@ -142,8 +150,7 @@ async function main() { } } if (!node) { - // eslint-disable-next-line no-console - console.error("No connected iOS nodes found. (Is the iOS app connected to the gateway?)"); + writeStderrLine("No connected iOS nodes found. (Is the iOS app connected to the gateway?)"); close(); process.exit(5); } @@ -235,23 +242,16 @@ async function main() { } if (jsonOut) { - // eslint-disable-next-line no-console - console.log( - JSON.stringify( - { - gateway: url.toString(), - node: { - nodeId: node.nodeId, - displayName: node.displayName, - platform: node.platform, - }, - dangerous, - results, - }, - null, - 2, - ), - ); + writeStdoutJson({ + gateway: url.toString(), + node: { + nodeId: node.nodeId, + displayName: node.displayName, + platform: node.platform, + }, + dangerous, + results, + }); } else { const pad = (s: string, n: number) => (s.length >= n ? s : s + " ".repeat(n - s.length)); const rows = results.map((r) => ({ @@ -260,15 +260,11 @@ async function main() { note: r.ok ? "" : formatErr(r.error ?? "error"), })); const width = Math.min(64, Math.max(12, ...rows.map((r) => r.cmd.length))); - // eslint-disable-next-line no-console - console.log(`node: ${node.displayName ?? node.nodeId} (${node.platform ?? "unknown"})`); - // eslint-disable-next-line no-console - console.log(`dangerous: ${dangerous ? "on" : "off"}`); - // eslint-disable-next-line no-console - console.log(""); + writeStdoutLine(`node: ${node.displayName ?? node.nodeId} (${node.platform ?? "unknown"})`); + writeStdoutLine(`dangerous: ${dangerous ? "on" : "off"}`); + writeStdoutLine(); for (const r of rows) { - // eslint-disable-next-line no-console - console.log(`${pad(r.cmd, width)} ${pad(r.ok, 4)} ${r.note}`); + writeStdoutLine(`${pad(r.cmd, width)} ${pad(r.ok, 4)} ${r.note}`); } } diff --git a/scripts/dev/test-device-pair-telegram.ts b/scripts/dev/test-device-pair-telegram.ts index e39e0a378cd..fecb5593635 100644 --- a/scripts/dev/test-device-pair-telegram.ts +++ b/scripts/dev/test-device-pair-telegram.ts @@ -3,6 +3,14 @@ import { loadConfig } from "../../src/config/config.js"; import { matchPluginCommand, executePluginCommand } from "../../src/plugins/commands.js"; import { loadOpenClawPlugins } from "../../src/plugins/loader.js"; +function writeStdoutLine(...parts: string[]): void { + process.stdout.write(`${parts.join(" ")}\n`); +} + +function writeStderrLine(message: string): void { + process.stderr.write(`${message}\n`); +} + const args = process.argv.slice(2); const getArg = (flag: string, short?: string) => { const idx = args.indexOf(flag); @@ -21,8 +29,7 @@ const getArg = (flag: string, short?: string) => { const chatId = getArg("--chat", "-c"); const accountId = getArg("--account", "-a"); if (!chatId) { - // eslint-disable-next-line no-console - console.error( + writeStderrLine( "Usage: bun scripts/dev/test-device-pair-telegram.ts --chat [--account ]", ); process.exit(1); @@ -33,8 +40,7 @@ loadOpenClawPlugins({ config: cfg }); const match = matchPluginCommand("/pair"); if (!match) { - // eslint-disable-next-line no-console - console.error("/pair plugin command not registered."); + writeStderrLine("/pair plugin command not registered."); process.exit(1); } @@ -58,5 +64,4 @@ if (result.text) { }); } -// eslint-disable-next-line no-console -console.log("Sent split /pair messages to", chatId, accountId ? `(${accountId})` : ""); +writeStdoutLine("Sent split /pair messages to", chatId, accountId ? `(${accountId})` : ""); diff --git a/scripts/label-open-issues.ts b/scripts/label-open-issues.ts index b6c1ac3bae8..499ebfa788c 100644 --- a/scripts/label-open-issues.ts +++ b/scripts/label-open-issues.ts @@ -3,6 +3,10 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; import { homedir } from "node:os"; import { dirname, join } from "node:path"; +function writeStdoutLine(message = ""): void { + process.stdout.write(`${message}\n`); +} + const BUG_LABEL = "bug"; const ENHANCEMENT_LABEL = "enhancement"; const SUPPORT_LABEL = "r: support"; @@ -231,25 +235,20 @@ function parseArgs(argv: string[]): ScriptOptions { } function logHeader(title: string) { - // eslint-disable-next-line no-console - console.log(`\n${title}`); - // eslint-disable-next-line no-console - console.log("=".repeat(title.length)); + writeStdoutLine(`\n${title}`); + writeStdoutLine("=".repeat(title.length)); } function logStep(message: string) { - // eslint-disable-next-line no-console - console.log(`• ${message}`); + writeStdoutLine(`• ${message}`); } function logSuccess(message: string) { - // eslint-disable-next-line no-console - console.log(`✓ ${message}`); + writeStdoutLine(`✓ ${message}`); } function logInfo(message: string) { - // eslint-disable-next-line no-console - console.log(` ${message}`); + writeStdoutLine(` ${message}`); } function createEmptyState(): LoadedState { @@ -748,8 +747,7 @@ async function main() { logInfo(`Processing ${pendingIssues.length} issues (scanned so far: ${scannedCount}).`); for (const issue of pendingIssues) { - // eslint-disable-next-line no-console - console.log(`\n#${issue.number} — ${issue.title}`); + writeStdoutLine(`\n#${issue.number} — ${issue.title}`); const labels = new Set(issue.labels.map((label) => label.name)); logInfo(`Existing labels: ${Array.from(labels).toSorted().join(", ") || "none"}`); @@ -824,8 +822,7 @@ async function main() { ); for (const pullRequest of pendingPullRequests) { - // eslint-disable-next-line no-console - console.log(`\n#${pullRequest.number} — ${pullRequest.title}`); + writeStdoutLine(`\n#${pullRequest.number} — ${pullRequest.title}`); const labels = new Set(pullRequest.labels.map((label) => label.name)); logInfo(`Existing labels: ${Array.from(labels).toSorted().join(", ") || "none"}`);