Update contributing, deduplicate more functions

This commit is contained in:
quotentiroler
2026-02-09 19:21:33 -08:00
parent 453eaed4dc
commit cc87c0ed7c
13 changed files with 96 additions and 100 deletions

View File

@@ -35,10 +35,10 @@ type FallbackAttempt = {
};
/**
* Strict abort check for model fallback. Only treats explicit AbortError names as user aborts.
* Fallback abort check. Only treats explicit AbortError names as user aborts.
* Message-based checks (e.g., "aborted") can mask timeouts and skip fallback.
*/
function isStrictAbortError(err: unknown): boolean {
function isFallbackAbortError(err: unknown): boolean {
if (!err || typeof err !== "object") {
return false;
}
@@ -50,7 +50,7 @@ function isStrictAbortError(err: unknown): boolean {
}
function shouldRethrowAbort(err: unknown): boolean {
return isStrictAbortError(err) && !isTimeoutError(err);
return isFallbackAbortError(err) && !isTimeoutError(err);
}
function resolveImageFallbackCandidates(params: {

View File

@@ -1 +1,17 @@
export { isAbortError } from "../../infra/unhandled-rejections.js";
/**
* Runner abort check. Catches any abort-related message for embedded runners.
* More permissive than the core isAbortError since runners need to catch
* various abort signals from different sources.
*/
export function isRunnerAbortError(err: unknown): boolean {
if (!err || typeof err !== "object") {
return false;
}
const name = "name" in err ? String(err.name) : "";
if (name === "AbortError") {
return true;
}
const message =
"message" in err && typeof err.message === "string" ? err.message.toLowerCase() : "";
return message.includes("aborted");
}

View File

@@ -60,7 +60,7 @@ import { buildSystemPromptParams } from "../../system-prompt-params.js";
import { buildSystemPromptReport } from "../../system-prompt-report.js";
import { resolveTranscriptPolicy } from "../../transcript-policy.js";
import { DEFAULT_BOOTSTRAP_FILENAME } from "../../workspace.js";
import { isAbortError } from "../abort.js";
import { isRunnerAbortError } from "../abort.js";
import { appendCacheTtlTimestamp, isCacheTtlEligibleProvider } from "../cache-ttl.js";
import { buildEmbeddedExtensionPaths } from "../extensions.js";
import { applyExtraParamsToAgent } from "../extra-params.js";
@@ -832,7 +832,7 @@ export async function runEmbeddedAttempt(
try {
await waitForCompactionRetry();
} catch (err) {
if (isAbortError(err)) {
if (isRunnerAbortError(err)) {
if (!promptError) {
promptError = err;
}

View File

@@ -11,7 +11,7 @@ import { CONFIG_PATH } from "../config/config.js";
import { resolveSessionTranscriptsDirForAgent } from "../config/sessions.js";
import { callGateway } from "../gateway/call.js";
import { normalizeControlUiBasePath } from "../gateway/control-ui-shared.js";
import { pickPrimaryLanIPv4 } from "../gateway/net.js";
import { pickPrimaryLanIPv4, isValidIPv4 } from "../gateway/net.js";
import { isSafeExecutableValue } from "../infra/exec-safety.js";
import { pickPrimaryTailnetIPv4 } from "../infra/tailnet.js";
import { isWSL } from "../infra/wsl.js";
@@ -464,14 +464,3 @@ export function resolveControlUiLinks(params: {
wsUrl: `ws://${host}:${port}${wsPath}`,
};
}
function isValidIPv4(host: string): boolean {
const parts = host.split(".");
if (parts.length !== 4) {
return false;
}
return parts.every((part) => {
const n = Number.parseInt(part, 10);
return !Number.isNaN(n) && n >= 0 && n <= 255 && part === String(n);
});
}

View File

@@ -244,7 +244,7 @@ export async function resolveGatewayListenHosts(
* @param host - The string to validate
* @returns True if valid IPv4 format
*/
function isValidIPv4(host: string): boolean {
export function isValidIPv4(host: string): boolean {
const parts = host.split(".");
if (parts.length !== 4) {
return false;

View File

@@ -62,10 +62,12 @@ export function isAbortError(err: unknown): boolean {
if (name === "AbortError") {
return true;
}
// Check for abort messages from Node's undici and other sources
const message =
"message" in err && typeof err.message === "string" ? err.message.toLowerCase() : "";
return message.includes("aborted");
// Check for "This operation was aborted" message from Node's undici
const message = "message" in err && typeof err.message === "string" ? err.message : "";
if (message === "This operation was aborted") {
return true;
}
return false;
}
function isFatalError(err: unknown): boolean {

View File

@@ -1,3 +1,4 @@
import { readFileSync } from "node:fs";
import fs from "node:fs/promises";
let wslCached: boolean | null = null;
@@ -9,6 +10,40 @@ export function isWSLEnv(): boolean {
return false;
}
/**
* Synchronously check if running in WSL.
* Checks env vars first, then /proc/version.
*/
export function isWSLSync(): boolean {
if (process.platform !== "linux") {
return false;
}
if (isWSLEnv()) {
return true;
}
try {
const release = readFileSync("/proc/version", "utf8").toLowerCase();
return release.includes("microsoft") || release.includes("wsl");
} catch {
return false;
}
}
/**
* Synchronously check if running in WSL2.
*/
export function isWSL2Sync(): boolean {
if (!isWSLSync()) {
return false;
}
try {
const version = readFileSync("/proc/version", "utf8").toLowerCase();
return version.includes("wsl2") || version.includes("microsoft-standard");
} catch {
return false;
}
}
export async function isWSL(): Promise<boolean> {
if (wslCached !== null) {
return wslCached;

View File

@@ -136,6 +136,8 @@ export {
rejectDevicePairing,
} from "../infra/device-pairing.js";
export { formatErrorMessage } from "../infra/errors.js";
export { isWSLSync, isWSL2Sync, isWSLEnv } from "../infra/wsl.js";
export { isTruthyEnvValue } from "../infra/env.js";
export { resolveToolsBySender } from "../config/group-policy.js";
export {
buildPendingHistoryContextFromMap,