mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-28 10:22:32 +00:00
Reduce script logging suppressions and Feishu any casts
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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})` : "");
|
||||
|
||||
Reference in New Issue
Block a user