refactor(cli): separate json payload output from logging

This commit is contained in:
Peter Steinberger
2026-03-22 23:19:14 +00:00
parent 274af0486a
commit 4ee41cc6f3
89 changed files with 710 additions and 693 deletions

View File

@@ -124,14 +124,14 @@ export function registerGatewayCli(program: Command) {
const params = JSON.parse(String(opts.params ?? "{}"));
const result = await callGatewayCli(method, { ...rpcOpts, config }, params);
if (rpcOpts.json) {
defaultRuntime.log(JSON.stringify(result, null, 2));
defaultRuntime.writeJson(result);
return;
}
const rich = isRich();
defaultRuntime.log(
`${colorize(rich, theme.heading, "Gateway call")}: ${colorize(rich, theme.muted, String(method))}`,
);
defaultRuntime.log(JSON.stringify(result, null, 2));
defaultRuntime.writeJson(result);
}, "Gateway call failed");
}),
);
@@ -148,7 +148,7 @@ export function registerGatewayCli(program: Command) {
const config = await readBestEffortConfig();
const result = await callGatewayCli("usage.cost", { ...rpcOpts, config }, { days });
if (rpcOpts.json) {
defaultRuntime.log(JSON.stringify(result, null, 2));
defaultRuntime.writeJson(result);
return;
}
const rich = isRich();
@@ -170,7 +170,7 @@ export function registerGatewayCli(program: Command) {
const config = await readBestEffortConfig();
const result = await callGatewayCli("health", { ...rpcOpts, config });
if (rpcOpts.json) {
defaultRuntime.log(JSON.stringify(result, null, 2));
defaultRuntime.writeJson(result);
return;
}
const rich = isRich();
@@ -242,18 +242,12 @@ export function registerGatewayCli(program: Command) {
const port = pickGatewayPort(b);
return { ...b, wsUrl: host ? `ws://${host}:${port}` : null };
});
defaultRuntime.log(
JSON.stringify(
{
timeoutMs,
domains,
count: enriched.length,
beacons: enriched,
},
null,
2,
),
);
defaultRuntime.writeJson({
timeoutMs,
domains,
count: enriched.length,
beacons: enriched,
});
return;
}

View File

@@ -20,7 +20,7 @@ import {
waitForActiveTasks,
} from "../../process/command-queue.js";
import { createRestartIterationHook } from "../../process/restart-recovery.js";
import type { defaultRuntime } from "../../runtime.js";
import type { RuntimeEnv } from "../../runtime.js";
const gatewayLog = createSubsystemLogger("gateway");
@@ -28,7 +28,7 @@ type GatewayRunSignalAction = "stop" | "restart";
export async function runGatewayLoop(params: {
start: () => Promise<Awaited<ReturnType<typeof startGatewayServer>>>;
runtime: typeof defaultRuntime;
runtime: RuntimeEnv;
lockPort?: number;
}) {
let lock = await acquireGatewayLock({ port: params.lockPort });