Reduce script logging suppressions and Feishu any casts

This commit is contained in:
Tak Hoffman
2026-03-27 01:46:34 -05:00
parent f5643544c2
commit 23fae00fad
7 changed files with 135 additions and 149 deletions

View File

@@ -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,
},
});
},
);
}

View File

@@ -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;

View File

@@ -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<SuccessResult | FailureResult> {
}
if (hasFlag("--help") || hasFlag("-h")) {
// eslint-disable-next-line no-console
console.log(usage());
writeStdoutLine(usage());
process.exit(0);
}

View File

@@ -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 <wss://host[:port]> --token <gateway.auth.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();
}

View File

@@ -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 <wss://host[:port]> --token <gateway.auth.token> [--node <id|name-substring>] [--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}`);
}
}

View File

@@ -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 <telegram-chat-id> [--account <accountId>]",
);
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})` : "");

View File

@@ -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"}`);