chore: migrate to oxlint and oxfmt

Co-authored-by: Christoph Nakazawa <christoph.pojer@gmail.com>
This commit is contained in:
Peter Steinberger
2026-01-14 14:31:43 +00:00
parent 912ebffc63
commit c379191f80
1480 changed files with 28608 additions and 43547 deletions

View File

@@ -2,10 +2,7 @@ import { Buffer } from "node:buffer";
const CLOSE_REASON_MAX_BYTES = 120;
export function truncateCloseReason(
reason: string,
maxBytes = CLOSE_REASON_MAX_BYTES,
): string {
export function truncateCloseReason(reason: string, maxBytes = CLOSE_REASON_MAX_BYTES): string {
if (!reason) return "invalid handshake";
const buf = Buffer.from(reason);
if (buf.length <= maxBytes) return reason;

View File

@@ -1,11 +1,5 @@
import {
getHealthSnapshot,
type HealthSummary,
} from "../../commands/health.js";
import {
CONFIG_PATH_CLAWDBOT,
STATE_DIR_CLAWDBOT,
} from "../../config/config.js";
import { getHealthSnapshot, type HealthSummary } from "../../commands/health.js";
import { CONFIG_PATH_CLAWDBOT, STATE_DIR_CLAWDBOT } from "../../config/config.js";
import { listSystemPresence } from "../../infra/system-presence.js";
import type { Snapshot } from "../protocol/index.js";
@@ -48,9 +42,7 @@ export function getPresenceVersion(): number {
return presenceVersion;
}
export function setBroadcastHealthUpdate(
fn: ((snap: HealthSummary) => void) | null,
) {
export function setBroadcastHealthUpdate(fn: ((snap: HealthSummary) => void) | null) {
broadcastHealthUpdate = fn;
}

View File

@@ -22,10 +22,7 @@ export function createGatewayHooksRequestHandler(params: {
}) {
const { deps, getHooksConfig, bindHost, port, logHooks } = params;
const dispatchWakeHook = (value: {
text: string;
mode: "now" | "next-heartbeat";
}) => {
const dispatchWakeHook = (value: { text: string; mode: "now" | "next-heartbeat" }) => {
const sessionKey = resolveMainSessionKeyFromConfig();
enqueueSystemEvent(value.text, { sessionKey });
if (value.mode === "now") {
@@ -45,9 +42,7 @@ export function createGatewayHooksRequestHandler(params: {
thinking?: string;
timeoutSeconds?: number;
}) => {
const sessionKey = value.sessionKey.trim()
? value.sessionKey.trim()
: `hook:${randomUUID()}`;
const sessionKey = value.sessionKey.trim() ? value.sessionKey.trim() : `hook:${randomUUID()}`;
const mainSessionKey = resolveMainSessionKeyFromConfig();
const jobId = randomUUID();
const now = Date.now();
@@ -85,12 +80,9 @@ export function createGatewayHooksRequestHandler(params: {
sessionKey,
lane: "cron",
});
const summary =
result.summary?.trim() || result.error?.trim() || result.status;
const summary = result.summary?.trim() || result.error?.trim() || result.status;
const prefix =
result.status === "ok"
? `Hook ${value.name}`
: `Hook ${value.name} (${result.status})`;
result.status === "ok" ? `Hook ${value.name}` : `Hook ${value.name} (${result.status})`;
enqueueSystemEvent(`${prefix}: ${summary}`.trim(), {
sessionKey: mainSessionKey,
});

View File

@@ -2,27 +2,17 @@ import { randomUUID } from "node:crypto";
import type { WebSocket, WebSocketServer } from "ws";
import { resolveCanvasHostUrl } from "../../infra/canvas-host-url.js";
import {
listSystemPresence,
upsertPresence,
} from "../../infra/system-presence.js";
import { listSystemPresence, upsertPresence } from "../../infra/system-presence.js";
import type { createSubsystemLogger } from "../../logging.js";
import { isWebchatClient } from "../../utils/message-channel.js";
import type { ResolvedGatewayAuth } from "../auth.js";
import { isLoopbackAddress } from "../net.js";
import { HANDSHAKE_TIMEOUT_MS } from "../server-constants.js";
import type {
GatewayRequestContext,
GatewayRequestHandlers,
} from "../server-methods/types.js";
import type { GatewayRequestContext, GatewayRequestHandlers } from "../server-methods/types.js";
import { formatError } from "../server-utils.js";
import { logWs } from "../ws-log.js";
import {
getHealthVersion,
getPresenceVersion,
incrementPresenceVersion,
} from "./health-state.js";
import { getHealthVersion, getPresenceVersion, incrementPresenceVersion } from "./health-state.js";
import { attachGatewayWsMessageHandler } from "./ws-connection/message-handler.js";
import type { GatewayWsClient } from "./ws-types.js";
@@ -75,9 +65,8 @@ export function attachGatewayWsConnectionHandler(params: {
let closed = false;
const openedAt = Date.now();
const connId = randomUUID();
const remoteAddr = (
socket as WebSocket & { _socket?: { remoteAddress?: string } }
)._socket?.remoteAddress;
const remoteAddr = (socket as WebSocket & { _socket?: { remoteAddress?: string } })._socket
?.remoteAddress;
const headerValue = (value: string | string[] | undefined) =>
Array.isArray(value) ? value[0] : value;
const requestHost = headerValue(upgradeReq.headers.host);
@@ -85,12 +74,9 @@ export function attachGatewayWsConnectionHandler(params: {
const requestUserAgent = headerValue(upgradeReq.headers["user-agent"]);
const forwardedFor = headerValue(upgradeReq.headers["x-forwarded-for"]);
const canvasHostPortForWs =
canvasHostServerPort ?? (canvasHostEnabled ? port : undefined);
const canvasHostPortForWs = canvasHostServerPort ?? (canvasHostEnabled ? port : undefined);
const canvasHostOverride =
bridgeHost && bridgeHost !== "0.0.0.0" && bridgeHost !== "::"
? bridgeHost
: undefined;
bridgeHost && bridgeHost !== "0.0.0.0" && bridgeHost !== "::" ? bridgeHost : undefined;
const canvasHostUrl = resolveCanvasHostUrl({
canvasPort: canvasHostPortForWs,
hostOverride: canvasHostServerPort ? canvasHostOverride : undefined,
@@ -114,11 +100,7 @@ export function attachGatewayWsConnectionHandler(params: {
}
};
const setLastFrameMeta = (meta: {
type?: string;
method?: string;
id?: string;
}) => {
const setLastFrameMeta = (meta: { type?: string; method?: string; id?: string }) => {
if (meta.type || meta.method || meta.id) {
lastFrameType = meta.type ?? lastFrameType;
lastFrameMethod = meta.method ?? lastFrameMethod;
@@ -147,19 +129,13 @@ export function attachGatewayWsConnectionHandler(params: {
};
socket.once("error", (err) => {
logWsControl.warn(
`error conn=${connId} remote=${remoteAddr ?? "?"}: ${formatError(err)}`,
);
logWsControl.warn(`error conn=${connId} remote=${remoteAddr ?? "?"}: ${formatError(err)}`);
close();
});
const isNoisySwiftPmHelperClose = (
userAgent: string | undefined,
remote: string | undefined,
) =>
const isNoisySwiftPmHelperClose = (userAgent: string | undefined, remote: string | undefined) =>
Boolean(
userAgent?.toLowerCase().includes("swiftpm-testing-helper") &&
isLoopbackAddress(remote),
userAgent?.toLowerCase().includes("swiftpm-testing-helper") && isLoopbackAddress(remote),
);
socket.once("close", (code, reason) => {
@@ -226,9 +202,7 @@ export function attachGatewayWsConnectionHandler(params: {
setCloseCause("handshake-timeout", {
handshakeMs: Date.now() - openedAt,
});
logWsControl.warn(
`handshake timeout conn=${connId} remote=${remoteAddr ?? "?"}`,
);
logWsControl.warn(`handshake timeout conn=${connId} remote=${remoteAddr ?? "?"}`);
close();
}
}, HANDSHAKE_TIMEOUT_MS);

View File

@@ -5,10 +5,7 @@ import type { WebSocket } from "ws";
import { upsertPresence } from "../../../infra/system-presence.js";
import { rawDataToString } from "../../../infra/ws.js";
import type { createSubsystemLogger } from "../../../logging.js";
import {
isGatewayCliClient,
isWebchatClient,
} from "../../../utils/message-channel.js";
import { isGatewayCliClient, isWebchatClient } from "../../../utils/message-channel.js";
import type { ResolvedGatewayAuth } from "../../auth.js";
import { authorizeGatewayConnect } from "../../auth.js";
import { isLoopbackAddress } from "../../net.js";
@@ -23,15 +20,8 @@ import {
validateConnectParams,
validateRequestFrame,
} from "../../protocol/index.js";
import {
MAX_BUFFERED_BYTES,
MAX_PAYLOAD_BYTES,
TICK_INTERVAL_MS,
} from "../../server-constants.js";
import type {
GatewayRequestContext,
GatewayRequestHandlers,
} from "../../server-methods/types.js";
import { MAX_BUFFERED_BYTES, MAX_PAYLOAD_BYTES, TICK_INTERVAL_MS } from "../../server-constants.js";
import type { GatewayRequestContext, GatewayRequestHandlers } from "../../server-methods/types.js";
import { handleGatewayRequest } from "../../server-methods.js";
import { formatError } from "../../server-utils.js";
import { formatForLog, logWs } from "../../ws-log.js";
@@ -71,11 +61,7 @@ export function attachGatewayWsMessageHandler(params: {
setClient: (next: GatewayWsClient) => void;
setHandshakeState: (state: "pending" | "connected" | "failed") => void;
setCloseCause: (cause: string, meta?: Record<string, unknown>) => void;
setLastFrameMeta: (meta: {
type?: string;
method?: string;
id?: string;
}) => void;
setLastFrameMeta: (meta: { type?: string; method?: string; id?: string }) => void;
logGateway: SubsystemLogger;
logHealth: SubsystemLogger;
logWsControl: SubsystemLogger;
@@ -109,8 +95,7 @@ export function attachGatewayWsMessageHandler(params: {
logWsControl,
} = params;
const isWebchatConnect = (p: ConnectParams | null | undefined) =>
isWebchatClient(p?.client);
const isWebchatConnect = (p: ConnectParams | null | undefined) => isWebchatClient(p?.client);
socket.on("message", async (data) => {
if (isClosed()) return;
@@ -174,9 +159,7 @@ export function attachGatewayWsMessageHandler(params: {
`invalid handshake conn=${connId} remote=${remoteAddr ?? "?"} fwd=${forwardedFor ?? "n/a"} origin=${requestOrigin ?? "n/a"} host=${requestHost ?? "n/a"} ua=${requestUserAgent ?? "n/a"}`,
);
}
const closeReason = truncateCloseReason(
handshakeError || "invalid handshake",
);
const closeReason = truncateCloseReason(handshakeError || "invalid handshake");
if (isRequestFrame) {
queueMicrotask(() => close(1008, closeReason));
} else {
@@ -187,8 +170,7 @@ export function attachGatewayWsMessageHandler(params: {
const frame = parsed as RequestFrame;
const connectParams = frame.params as ConnectParams;
const clientLabel =
connectParams.client.displayName ?? connectParams.client.id;
const clientLabel = connectParams.client.displayName ?? connectParams.client.id;
// protocol negotiation
const { minProtocol, maxProtocol } = connectParams;
@@ -257,9 +239,7 @@ export function attachGatewayWsMessageHandler(params: {
const shouldTrackPresence = !isGatewayCliClient(connectParams.client);
const clientId = connectParams.client.id;
const instanceId = connectParams.client.instanceId;
const presenceKey = shouldTrackPresence
? (instanceId ?? connId)
: undefined;
const presenceKey = shouldTrackPresence ? (instanceId ?? connId) : undefined;
logWs("in", "connect", {
connId,
@@ -280,10 +260,7 @@ export function attachGatewayWsMessageHandler(params: {
if (presenceKey) {
upsertPresence(presenceKey, {
host:
connectParams.client.displayName ??
connectParams.client.id ??
os.hostname(),
host: connectParams.client.displayName ?? connectParams.client.id ?? os.hostname(),
ip: isLoopbackAddress(remoteAddr) ? undefined : remoteAddr,
version: connectParams.client.version,
platform: connectParams.client.platform,
@@ -306,10 +283,7 @@ export function attachGatewayWsMessageHandler(params: {
type: "hello-ok",
protocol: PROTOCOL_VERSION,
server: {
version:
process.env.CLAWDBOT_VERSION ??
process.env.npm_package_version ??
"dev",
version: process.env.CLAWDBOT_VERSION ?? process.env.npm_package_version ?? "dev",
commit: process.env.GIT_COMMIT,
host: os.hostname(),
connId,
@@ -344,9 +318,7 @@ export function attachGatewayWsMessageHandler(params: {
send({ type: "res", id: frame.id, ok: true, payload: helloOk });
void refreshGatewayHealthSnapshot({ probe: true }).catch((err) =>
logHealth.error(
`post-connect health refresh failed: ${formatError(err)}`,
),
logHealth.error(`post-connect health refresh failed: ${formatError(err)}`),
);
return;
}
@@ -395,11 +367,7 @@ export function attachGatewayWsMessageHandler(params: {
});
})().catch((err) => {
logGateway.error(`request handler failed: ${formatForLog(err)}`);
respond(
false,
undefined,
errorShape(ErrorCodes.UNAVAILABLE, formatForLog(err)),
);
respond(false, undefined, errorShape(ErrorCodes.UNAVAILABLE, formatForLog(err)));
});
} catch (err) {
logGateway.error(`parse/handle error: ${String(err)}`);