style: 修复所有 lint 错误,覆盖 @ant forked 代码

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
claude-code-best
2026-05-01 21:49:21 +08:00
parent 6182015005
commit c32f26cf21
12 changed files with 1207 additions and 2685 deletions

1330
V6.md

File diff suppressed because it is too large Load Diff

View File

@@ -6,7 +6,7 @@
"useIgnoreFile": true
},
"files": {
"includes": ["**", "!!**/dist", "!!**/packages/@ant"]
"includes": ["**", "!!**/dist"]
},
"formatter": {
"enabled": true,

File diff suppressed because it is too large Load Diff

View File

@@ -1,327 +1,324 @@
import { promises as fsPromises } from "fs";
import { createConnection } from "net";
import type { Socket } from "net";
import { platform } from "os";
import { dirname } from "path";
import { promises as fsPromises } from 'fs'
import { createConnection } from 'net'
import type { Socket } from 'net'
import { platform } from 'os'
import { dirname } from 'path'
import type {
ClaudeForChromeContext,
PermissionMode,
PermissionOverrides,
} from "./types.js";
} from './types.js'
export class SocketConnectionError extends Error {
constructor(message: string) {
super(message);
this.name = "SocketConnectionError";
super(message)
this.name = 'SocketConnectionError'
}
}
interface ToolRequest {
method: string; // "execute_tool"
method: string // "execute_tool"
params?: {
client_id?: string; // "desktop" | "claude-code"
tool?: string;
args?: Record<string, unknown>;
};
client_id?: string // "desktop" | "claude-code"
tool?: string
args?: Record<string, unknown>
}
}
interface ToolResponse {
result?: unknown;
error?: string;
result?: unknown
error?: string
}
interface Notification {
method: string;
params?: Record<string, unknown>;
method: string
params?: Record<string, unknown>
}
type SocketMessage = ToolResponse | Notification;
type SocketMessage = ToolResponse | Notification
function isToolResponse(message: SocketMessage): message is ToolResponse {
return "result" in message || "error" in message;
return 'result' in message || 'error' in message
}
function isNotification(message: SocketMessage): message is Notification {
return "method" in message && typeof message.method === "string";
return 'method' in message && typeof message.method === 'string'
}
class McpSocketClient {
private socket: Socket | null = null;
private connected = false;
private connecting = false;
private responseCallback: ((response: ToolResponse) => void) | null = null;
private socket: Socket | null = null
private connected = false
private connecting = false
private responseCallback: ((response: ToolResponse) => void) | null = null
private notificationHandler: ((notification: Notification) => void) | null =
null;
private responseBuffer = Buffer.alloc(0);
private reconnectAttempts = 0;
private maxReconnectAttempts = 10;
private reconnectDelay = 1000;
private reconnectTimer: NodeJS.Timeout | null = null;
private context: ClaudeForChromeContext;
null
private responseBuffer = Buffer.alloc(0)
private reconnectAttempts = 0
private maxReconnectAttempts = 10
private reconnectDelay = 1000
private reconnectTimer: NodeJS.Timeout | null = null
private context: ClaudeForChromeContext
// When true, disables automatic reconnection. Used by McpSocketPool which
// manages reconnection externally by rescanning available sockets.
public disableAutoReconnect = false;
public disableAutoReconnect = false
constructor(context: ClaudeForChromeContext) {
this.context = context;
this.context = context
}
private async connect(): Promise<void> {
const { serverName, logger } = this.context;
const { serverName, logger } = this.context
if (this.connecting) {
logger.info(
`[${serverName}] Already connecting, skipping duplicate attempt`,
);
return;
)
return
}
this.closeSocket();
this.connecting = true;
this.closeSocket()
this.connecting = true
const socketPath =
this.context.getSocketPath?.() ?? this.context.socketPath;
logger.info(`[${serverName}] Attempting to connect to: ${socketPath}`);
const socketPath = this.context.getSocketPath?.() ?? this.context.socketPath
logger.info(`[${serverName}] Attempting to connect to: ${socketPath}`)
try {
await this.validateSocketSecurity(socketPath);
await this.validateSocketSecurity(socketPath)
} catch (error) {
this.connecting = false;
logger.info(`[${serverName}] Security validation failed:`, error);
this.connecting = false
logger.info(`[${serverName}] Security validation failed:`, error)
// Don't retry on security failures (wrong perms/owner) - those won't
// self-resolve. Only the error handler retries on transient errors.
return;
return
}
this.socket = createConnection(socketPath);
this.socket = createConnection(socketPath)
// Timeout the initial connection attempt - if socket file exists but native
// host is dead, the connect can hang indefinitely
const connectTimeout = setTimeout(() => {
if (!this.connected) {
logger.info(
`[${serverName}] Connection attempt timed out after 5000ms`,
);
this.closeSocket();
this.scheduleReconnect();
logger.info(`[${serverName}] Connection attempt timed out after 5000ms`)
this.closeSocket()
this.scheduleReconnect()
}
}, 5000);
}, 5000)
this.socket.on("connect", () => {
clearTimeout(connectTimeout);
this.connected = true;
this.connecting = false;
this.reconnectAttempts = 0;
logger.info(`[${serverName}] Successfully connected to bridge server`);
});
this.socket.on('connect', () => {
clearTimeout(connectTimeout)
this.connected = true
this.connecting = false
this.reconnectAttempts = 0
logger.info(`[${serverName}] Successfully connected to bridge server`)
})
this.socket.on("data", (data: Buffer) => {
this.responseBuffer = Buffer.concat([this.responseBuffer, data]);
this.socket.on('data', (data: Buffer) => {
this.responseBuffer = Buffer.concat([this.responseBuffer, data])
while (this.responseBuffer.length >= 4) {
const length = this.responseBuffer.readUInt32LE(0);
const length = this.responseBuffer.readUInt32LE(0)
if (this.responseBuffer.length < 4 + length) {
break;
break
}
const messageBytes = this.responseBuffer.slice(4, 4 + length);
this.responseBuffer = this.responseBuffer.slice(4 + length);
const messageBytes = this.responseBuffer.slice(4, 4 + length)
this.responseBuffer = this.responseBuffer.slice(4 + length)
try {
const message = JSON.parse(
messageBytes.toString("utf-8"),
) as SocketMessage;
messageBytes.toString('utf-8'),
) as SocketMessage
if (isNotification(message)) {
logger.info(
`[${serverName}] Received notification: ${message.method}`,
);
)
if (this.notificationHandler) {
this.notificationHandler(message);
this.notificationHandler(message)
}
} else if (isToolResponse(message)) {
logger.info(`[${serverName}] Received tool response: ${message}`);
this.handleResponse(message);
logger.info(`[${serverName}] Received tool response: ${message}`)
this.handleResponse(message)
} else {
logger.info(`[${serverName}] Received unknown message: ${message}`);
logger.info(`[${serverName}] Received unknown message: ${message}`)
}
} catch (error) {
logger.info(`[${serverName}] Failed to parse message:`, error);
logger.info(`[${serverName}] Failed to parse message:`, error)
}
}
});
})
this.socket.on("error", (error: Error & { code?: string }) => {
clearTimeout(connectTimeout);
logger.info(`[${serverName}] Socket error (code: ${error.code}):`, error);
this.connected = false;
this.connecting = false;
this.socket.on('error', (error: Error & { code?: string }) => {
clearTimeout(connectTimeout)
logger.info(`[${serverName}] Socket error (code: ${error.code}):`, error)
this.connected = false
this.connecting = false
if (
error.code &&
[
"ECONNREFUSED", // Native host not listening (stale socket)
"ECONNRESET", // Connection reset by peer
"EPIPE", // Broken pipe (native host died mid-write)
"ENOENT", // Socket file was deleted
"EOPNOTSUPP", // Socket file exists but is not a valid socket
"ECONNABORTED", // Connection aborted
'ECONNREFUSED', // Native host not listening (stale socket)
'ECONNRESET', // Connection reset by peer
'EPIPE', // Broken pipe (native host died mid-write)
'ENOENT', // Socket file was deleted
'EOPNOTSUPP', // Socket file exists but is not a valid socket
'ECONNABORTED', // Connection aborted
].includes(error.code)
) {
this.scheduleReconnect();
this.scheduleReconnect()
}
});
})
this.socket.on("close", () => {
clearTimeout(connectTimeout);
this.connected = false;
this.connecting = false;
this.scheduleReconnect();
});
this.socket.on('close', () => {
clearTimeout(connectTimeout)
this.connected = false
this.connecting = false
this.scheduleReconnect()
})
}
private scheduleReconnect(): void {
const { serverName, logger } = this.context;
const { serverName, logger } = this.context
if (this.disableAutoReconnect) {
return;
return
}
if (this.reconnectTimer) {
logger.info(`[${serverName}] Reconnect already scheduled, skipping`);
return;
logger.info(`[${serverName}] Reconnect already scheduled, skipping`)
return
}
this.reconnectAttempts++;
this.reconnectAttempts++
// Give up after extended polling (~50 min). A new ensureConnected() call
// from a tool request will restart the cycle if needed.
const maxTotalAttempts = 100;
const maxTotalAttempts = 100
if (this.reconnectAttempts > maxTotalAttempts) {
logger.info(
`[${serverName}] Giving up after ${maxTotalAttempts} attempts. Will retry on next tool call.`,
);
this.reconnectAttempts = 0;
return;
)
this.reconnectAttempts = 0
return
}
// Use aggressive backoff for first 10 attempts, then slow poll every 30s.
const delay = Math.min(
this.reconnectDelay * Math.pow(1.5, this.reconnectAttempts - 1),
this.reconnectDelay * 1.5 ** (this.reconnectAttempts - 1),
30000,
);
)
if (this.reconnectAttempts <= this.maxReconnectAttempts) {
logger.info(
`[${serverName}] Reconnecting in ${Math.round(delay)}ms (attempt ${
this.reconnectAttempts
})`,
);
)
} else if (this.reconnectAttempts % 10 === 0) {
// Log every 10th slow-poll attempt to avoid log spam
logger.info(
`[${serverName}] Still polling for native host (attempt ${this.reconnectAttempts})`,
);
)
}
this.reconnectTimer = setTimeout(() => {
this.reconnectTimer = null;
void this.connect();
}, delay);
this.reconnectTimer = null
void this.connect()
}, delay)
}
private handleResponse(response: ToolResponse): void {
if (this.responseCallback) {
const callback = this.responseCallback;
this.responseCallback = null;
callback(response);
const callback = this.responseCallback
this.responseCallback = null
callback(response)
}
}
public setNotificationHandler(
handler: (notification: Notification) => void,
): void {
this.notificationHandler = handler;
this.notificationHandler = handler
}
public async ensureConnected(): Promise<boolean> {
const { serverName } = this.context;
const { serverName } = this.context
if (this.connected && this.socket) {
return true;
return true
}
if (!this.socket && !this.connecting) {
await this.connect();
await this.connect()
}
// Wait for connection with timeout
return new Promise((resolve, reject) => {
let checkTimeoutId: NodeJS.Timeout | null = null;
let checkTimeoutId: NodeJS.Timeout | null = null
const timeout = setTimeout(() => {
if (checkTimeoutId) {
clearTimeout(checkTimeoutId);
clearTimeout(checkTimeoutId)
}
reject(
new SocketConnectionError(
`[${serverName}] Connection attempt timed out after 5000ms`,
),
);
}, 5000);
)
}, 5000)
const checkConnection = () => {
if (this.connected) {
clearTimeout(timeout);
resolve(true);
clearTimeout(timeout)
resolve(true)
} else {
checkTimeoutId = setTimeout(checkConnection, 500);
checkTimeoutId = setTimeout(checkConnection, 500)
}
};
checkConnection();
});
}
checkConnection()
})
}
private async sendRequest(
request: ToolRequest,
timeoutMs = 30000,
): Promise<ToolResponse> {
const { serverName } = this.context;
const { serverName } = this.context
if (!this.socket) {
throw new SocketConnectionError(
`[${serverName}] Cannot send request: not connected`,
);
)
}
const socket = this.socket;
const socket = this.socket
return new Promise((resolve, reject) => {
const timeout = setTimeout(() => {
this.responseCallback = null;
this.responseCallback = null
reject(
new SocketConnectionError(
`[${serverName}] Tool request timed out after ${timeoutMs}ms`,
),
);
}, timeoutMs);
)
}, timeoutMs)
this.responseCallback = (response) => {
clearTimeout(timeout);
resolve(response);
};
this.responseCallback = response => {
clearTimeout(timeout)
resolve(response)
}
const requestJson = JSON.stringify(request);
const requestBytes = Buffer.from(requestJson, "utf-8");
const requestJson = JSON.stringify(request)
const requestBytes = Buffer.from(requestJson, 'utf-8')
const lengthPrefix = Buffer.allocUnsafe(4);
lengthPrefix.writeUInt32LE(requestBytes.length, 0);
const lengthPrefix = Buffer.allocUnsafe(4)
lengthPrefix.writeUInt32LE(requestBytes.length, 0)
const message = Buffer.concat([lengthPrefix, requestBytes]);
socket.write(message);
});
const message = Buffer.concat([lengthPrefix, requestBytes])
socket.write(message)
})
}
public async callTool(
@@ -330,15 +327,15 @@ class McpSocketClient {
_permissionOverrides?: PermissionOverrides,
): Promise<unknown> {
const request: ToolRequest = {
method: "execute_tool",
method: 'execute_tool',
params: {
client_id: this.context.clientTypeId,
tool: name,
args,
},
};
}
return this.sendRequestWithRetry(request);
return this.sendRequestWithRetry(request)
}
/**
@@ -349,23 +346,23 @@ class McpSocketClient {
* and retry once.
*/
private async sendRequestWithRetry(request: ToolRequest): Promise<unknown> {
const { serverName, logger } = this.context;
const { serverName, logger } = this.context
try {
return await this.sendRequest(request);
return await this.sendRequest(request)
} catch (error) {
if (!(error instanceof SocketConnectionError)) {
throw error;
throw error
}
logger.info(
`[${serverName}] Connection error, forcing reconnect and retrying: ${error.message}`,
);
)
this.closeSocket();
await this.ensureConnected();
this.closeSocket()
await this.ensureConnected()
return await this.sendRequest(request);
return await this.sendRequest(request)
}
}
@@ -377,109 +374,109 @@ class McpSocketClient {
}
public isConnected(): boolean {
return this.connected;
return this.connected
}
private closeSocket(): void {
if (this.socket) {
this.socket.removeAllListeners();
this.socket.end();
this.socket.destroy();
this.socket = null;
this.socket.removeAllListeners()
this.socket.end()
this.socket.destroy()
this.socket = null
}
this.connected = false;
this.connecting = false;
this.connected = false
this.connecting = false
}
private cleanup(): void {
if (this.reconnectTimer) {
clearTimeout(this.reconnectTimer);
this.reconnectTimer = null;
clearTimeout(this.reconnectTimer)
this.reconnectTimer = null
}
this.closeSocket();
this.reconnectAttempts = 0;
this.responseBuffer = Buffer.alloc(0);
this.responseCallback = null;
this.closeSocket()
this.reconnectAttempts = 0
this.responseBuffer = Buffer.alloc(0)
this.responseCallback = null
}
public disconnect(): void {
this.cleanup();
this.cleanup()
}
private async validateSocketSecurity(socketPath: string): Promise<void> {
const { serverName, logger } = this.context;
if (platform() === "win32") {
return;
const { serverName, logger } = this.context
if (platform() === 'win32') {
return
}
try {
// Validate the parent directory permissions if it's the socket directory
// (not /tmp itself, which has mode 1777 for legacy single-socket paths)
const dirPath = dirname(socketPath);
const dirBasename = dirPath.split("/").pop() || "";
const isSocketDir = dirBasename.startsWith("claude-mcp-browser-bridge-");
const dirPath = dirname(socketPath)
const dirBasename = dirPath.split('/').pop() || ''
const isSocketDir = dirBasename.startsWith('claude-mcp-browser-bridge-')
if (isSocketDir) {
try {
const dirStats = await fsPromises.stat(dirPath);
const dirStats = await fsPromises.stat(dirPath)
if (dirStats.isDirectory()) {
const dirMode = dirStats.mode & 0o777;
const dirMode = dirStats.mode & 0o777
if (dirMode !== 0o700) {
throw new Error(
`[${serverName}] Insecure socket directory permissions: ${dirMode.toString(
8,
)} (expected 0700). Directory may have been tampered with.`,
);
)
}
const currentUid = process.getuid?.();
const currentUid = process.getuid?.()
if (currentUid !== undefined && dirStats.uid !== currentUid) {
throw new Error(
`Socket directory not owned by current user (uid: ${currentUid}, dir uid: ${dirStats.uid}). ` +
`Potential security risk.`,
);
)
}
}
} catch (dirError) {
if ((dirError as NodeJS.ErrnoException).code !== "ENOENT") {
throw dirError;
if ((dirError as NodeJS.ErrnoException).code !== 'ENOENT') {
throw dirError
}
// Directory doesn't exist yet - native host will create it
}
}
const stats = await fsPromises.stat(socketPath);
const stats = await fsPromises.stat(socketPath)
if (!stats.isSocket()) {
throw new Error(
`[${serverName}] Path exists but it's not a socket: ${socketPath}`,
);
)
}
const mode = stats.mode & 0o777;
const mode = stats.mode & 0o777
if (mode !== 0o600) {
throw new Error(
`[${serverName}] Insecure socket permissions: ${mode.toString(
8,
)} (expected 0600). Socket may have been tampered with.`,
);
)
}
const currentUid = process.getuid?.();
const currentUid = process.getuid?.()
if (currentUid !== undefined && stats.uid !== currentUid) {
throw new Error(
`Socket not owned by current user (uid: ${currentUid}, socket uid: ${stats.uid}). ` +
`Potential security risk.`,
);
)
}
logger.info(`[${serverName}] Socket security validation passed`);
logger.info(`[${serverName}] Socket security validation passed`)
} catch (error) {
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
logger.info(
`[${serverName}] Socket not found, will be created by server`,
);
return;
)
return
}
throw error;
throw error
}
}
}
@@ -487,7 +484,7 @@ class McpSocketClient {
export function createMcpSocketClient(
context: ClaudeForChromeContext,
): McpSocketClient {
return new McpSocketClient(context);
return new McpSocketClient(context)
}
export type { McpSocketClient };
export type { McpSocketClient }

File diff suppressed because it is too large Load Diff

View File

@@ -67,7 +67,7 @@ export class LogUpdate {
const { screen } = frame
const lines: string[] = []
let currentStyles: AnsiCode[] = []
let currentHyperlink: Hyperlink = undefined
let currentHyperlink: Hyperlink
for (let y = 0; y < screen.height; y++) {
let line = ''
for (let x = 0; x < screen.width; x++) {
@@ -301,7 +301,7 @@ export class LogUpdate {
cursorRestoreScroll
let currentStyleId = stylePool.none
let currentHyperlink: Hyperlink = undefined
let currentHyperlink: Hyperlink
// First pass: render changes to existing rows (rows < prev.screen.height)
let needsFullReset = false
@@ -533,7 +533,7 @@ function renderFrameSlice(
stylePool: StylePool,
): VirtualScreen {
let currentStyleId = stylePool.none
let currentHyperlink: Hyperlink = undefined
let currentHyperlink: Hyperlink
// Track the styleId of the last rendered cell on this line (-1 if none).
// Passed to visibleCellAtIndex to enable fg-only space optimization.
let lastRenderedStyleId = -1

View File

@@ -8,18 +8,17 @@ import { Buffer } from 'buffer'
import { PASTE_END, PASTE_START } from './termio/csi.js'
import { createTokenizer, type Tokenizer } from './termio/tokenize.js'
// eslint-disable-next-line no-control-regex
// biome-ignore lint/suspicious/noControlCharactersInRegex: terminal escape sequence parsing
const META_KEY_CODE_RE = /^(?:\x1b)([a-zA-Z0-9])$/
// eslint-disable-next-line no-control-regex
const FN_KEY_RE =
// eslint-disable-next-line no-control-regex
// biome-ignore lint/suspicious/noControlCharactersInRegex: terminal escape sequence parsing
/^(?:\x1b+)(O|N|\[|\[\[)(?:(\d+)(?:;(\d+))?([~^$])|(?:1;)?(\d+)?([a-zA-Z]))/
// CSI u (kitty keyboard protocol): ESC [ codepoint [; modifier] u
// Example: ESC[13;2u = Shift+Enter, ESC[27u = Escape (no modifiers)
// Modifier is optional - when absent, defaults to 1 (no modifiers)
// eslint-disable-next-line no-control-regex
// biome-ignore lint/suspicious/noControlCharactersInRegex: terminal escape sequence parsing
const CSI_U_RE = /^\x1b\[(\d+)(?:;(\d+))?u/
// xterm modifyOtherKeys: ESC [ 27 ; modifier ; keycode ~
@@ -27,41 +26,41 @@ const CSI_U_RE = /^\x1b\[(\d+)(?:;(\d+))?u/
// modifyOtherKeys=2 is active or via user keybinds, typically over SSH where
// TERM sniffing misses Ghostty and we never push Kitty keyboard mode.
// Note param order is reversed vs CSI u (modifier first, keycode second).
// eslint-disable-next-line no-control-regex
// biome-ignore lint/suspicious/noControlCharactersInRegex: terminal escape sequence parsing
const MODIFY_OTHER_KEYS_RE = /^\x1b\[27;(\d+);(\d+)~/
// -- Terminal response patterns (inbound sequences from the terminal itself) --
// DECRPM: CSI ? Ps ; Pm $ y — response to DECRQM (request mode)
// eslint-disable-next-line no-control-regex
// biome-ignore lint/suspicious/noControlCharactersInRegex: terminal escape sequence parsing
const DECRPM_RE = /^\x1b\[\?(\d+);(\d+)\$y$/
// DA1: CSI ? Ps ; ... c — primary device attributes response
// eslint-disable-next-line no-control-regex
// biome-ignore lint/suspicious/noControlCharactersInRegex: terminal escape sequence parsing
const DA1_RE = /^\x1b\[\?([\d;]*)c$/
// DA2: CSI > Ps ; ... c — secondary device attributes response
// eslint-disable-next-line no-control-regex
// biome-ignore lint/suspicious/noControlCharactersInRegex: terminal escape sequence parsing
const DA2_RE = /^\x1b\[>([\d;]*)c$/
// Kitty keyboard flags: CSI ? flags u — response to CSI ? u query
// (private ? marker distinguishes from CSI u key events)
// eslint-disable-next-line no-control-regex
// biome-ignore lint/suspicious/noControlCharactersInRegex: terminal escape sequence parsing
const KITTY_FLAGS_RE = /^\x1b\[\?(\d+)u$/
// DECXCPR cursor position: CSI ? row ; col R
// The ? marker disambiguates from modified F3 keys (Shift+F3 = CSI 1;2 R,
// Ctrl+F3 = CSI 1;5 R, etc.) — plain CSI row;col R is genuinely ambiguous.
// eslint-disable-next-line no-control-regex
// biome-ignore lint/suspicious/noControlCharactersInRegex: terminal escape sequence parsing
const CURSOR_POSITION_RE = /^\x1b\[\?(\d+);(\d+)R$/
// OSC response: OSC code ; data (BEL|ST)
// eslint-disable-next-line no-control-regex
// biome-ignore lint/suspicious/noControlCharactersInRegex: terminal escape sequence parsing
const OSC_RESPONSE_RE = /^\x1b\](\d+);(.*?)(?:\x07|\x1b\\)$/s
// XTVERSION: DCS > | name ST — terminal name/version string (answer to CSI > 0 q).
// xterm.js replies "xterm.js(X.Y.Z)"; Ghostty, kitty, iTerm2, etc. reply with
// their own name. Unlike TERM_PROGRAM, this survives SSH since the query/reply
// goes through the pty, not the environment.
// eslint-disable-next-line no-control-regex
// biome-ignore lint/suspicious/noControlCharactersInRegex: terminal escape sequence parsing
const XTVERSION_RE = /^\x1bP>\|(.*?)(?:\x07|\x1b\\)$/s
// SGR mouse event: CSI < button ; col ; row M (press) or m (release)
// Button codes: 64=wheel-up, 65=wheel-down (0x40 | wheel-bit).
// Button 32=left-drag (0x20 | motion-bit). Plain 0/1/2 = left/mid/right click.
// eslint-disable-next-line no-control-regex
// biome-ignore lint/suspicious/noControlCharactersInRegex: terminal escape sequence parsing
const SGR_MOUSE_RE = /^\x1b\[<(\d+);(\d+);(\d+)([Mm])$/
function createPasteKey(content: string): ParsedKey {

View File

@@ -34,8 +34,10 @@ if (process.env.NODE_ENV === 'development') {
void import('./devtools.js')
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: unknown) {
if (error instanceof Error && (error as NodeJS.ErrnoException).code === 'ERR_MODULE_NOT_FOUND') {
// biome-ignore lint/suspicious/noConsole: intentional warning
if (
error instanceof Error &&
(error as NodeJS.ErrnoException).code === 'ERR_MODULE_NOT_FOUND'
) {
console.warn(
`
The environment variable DEV is set to true, so Ink tried to import \`react-devtools-core\`,
@@ -197,7 +199,6 @@ let _prepareAt = 0
/** Debug log helper — replaces fs.appendFileSync with console.warn. */
function debugLog(message: string): void {
// biome-ignore lint/suspicious/noConsole: debug instrumentation
console.warn(`[ink-commit] ${message}`)
}
// --- END ---
@@ -304,9 +305,7 @@ const reconciler = createReconciler<
if (COMMIT_LOG) {
const renderMs = performance.now() - _tr
if (renderMs > 10) {
debugLog(
`${_tr.toFixed(1)} SLOW_PAINT ${renderMs.toFixed(1)}ms`,
)
debugLog(`${_tr.toFixed(1)} SLOW_PAINT ${renderMs.toFixed(1)}ms`)
}
}
},

View File

@@ -114,7 +114,6 @@ const wrappedRender = async (
await Promise.resolve()
const instance = renderSync(node, options)
if (process.env.CLAUDE_CODE_DEBUG_REPAINTS === '1') {
// biome-ignore lint/suspicious/noConsole: debug instrumentation
console.warn(
`[render] first ink render: ${Math.round(process.uptime() * 1000)}ms since process start`,
)

View File

@@ -286,7 +286,7 @@ function hasVisibleSpaceEffect(styles: AnsiCode[]): boolean {
* @see https://mitchellh.com/writing/grapheme-clusters-in-terminals
*/
// const enum is inlined at compile time - no runtime object, no property access
export const enum CellWidth {
export enum CellWidth {
// Not a wide character, cell width 1
Narrow = 0,
// Wide character, cell width 2. This cell contains the actual character.
@@ -1144,7 +1144,7 @@ type DiffCallback = (
y: number,
removed: Cell | undefined,
added: Cell | undefined,
) => boolean | void
) => boolean | undefined
/**
* Like diff(), but calls a callback for each change instead of building an array.

View File

@@ -111,6 +111,7 @@ function isDefined(n: number): boolean {
// NaN-safe equality for layout-cache input comparison
function sameFloat(a: number, b: number): boolean {
// biome-ignore lint/suspicious/noSelfCompare: intentional NaN check (x !== x ↔ isNaN)
return a === b || (a !== a && b !== b)
}
@@ -2372,12 +2373,14 @@ function boundAxis(
if (v > maxV.value) v = maxV.value
} else if (maxU === 2) {
const m = (maxV.value * owner) / 100
// biome-ignore lint/suspicious/noSelfCompare: intentional NaN check
if (m === m && v > m) v = m
}
if (minU === 1) {
if (v < minV.value) v = minV.value
} else if (minU === 2) {
const m = (minV.value * owner) / 100
// biome-ignore lint/suspicious/noSelfCompare: intentional NaN check
if (m === m && v < m) v = m
}
return v

View File

@@ -118,8 +118,6 @@ export class ACPClient {
reject: (err: Error) => void
timer: ReturnType<typeof setTimeout>
} | null = null
// Tracks the session ID being targeted by a load/resume operation
private pendingSessionTarget: string | null = null
private connectResolve: ((value: undefined) => void) | null = null
private connectReject: ((error: Error) => void) | null = null