mirror of
https://github.com/stablyai/orca.git
synced 2026-09-24 16:02:41 +00:00
* chore(dead-code): drop 2k lines of unreachable exports and orphan modules Ran knip across every build entry (main, preload, renderer, popout, web, cli, relay, workers, forked sidecars, config scripts) and removed what no entry graph can reach. - 11 orphan modules nothing imported, plus one test that only covered them - 159 unused exports/types, with their now-dead helpers, imports and tests Each candidate was verified against dynamic references before deletion. 42 knip hits were false positives and are kept: shared modules consumed by the mobile/ workspace, the src/shared/plugins/** public API, vendored shadcn primitives, and relay wire-protocol constants held for compatibility. Adds knip.json + `pnpm audit:dead-code` so this stays measurable. Verified: pnpm typecheck, pnpm lint, and 2081 tests across the 73 affected test files all pass. * chore(dead-code): move knip config under config/ Root-level additions are blocked by the root directory guard. Co-authored-by: Orca <help@stably.ai> --------- Co-authored-by: Orca <help@stably.ai>
55 lines
1.8 KiB
TypeScript
55 lines
1.8 KiB
TypeScript
import { readNodeFileWithinLimit } from './node-bounded-file-reader'
|
|
|
|
export const LINUX_PROC_NETWORK_TABLE_MAX_BYTES = 8 * 1024 * 1024
|
|
export const LINUX_PROC_PROCESS_METADATA_MAX_BYTES = 8 * 1024 * 1024
|
|
export const LINUX_PROC_PROCESS_METADATA_FILE_MAX_BYTES = 64 * 1024
|
|
|
|
export type LinuxProcTextReadBudget = { remainingBytes: number }
|
|
|
|
type LinuxProcTextReader = (filePath: string, maxBytes: number) => Promise<Buffer>
|
|
|
|
const readBoundedNodeFile: LinuxProcTextReader = async (filePath, maxBytes) =>
|
|
(await readNodeFileWithinLimit(filePath, maxBytes)).buffer
|
|
|
|
export function createLinuxProcTextReadBudget(
|
|
maxBytes = LINUX_PROC_PROCESS_METADATA_MAX_BYTES
|
|
): LinuxProcTextReadBudget {
|
|
if (!Number.isSafeInteger(maxBytes) || maxBytes < 0) {
|
|
throw new RangeError('Linux proc text budget must be a non-negative safe integer')
|
|
}
|
|
return { remainingBytes: maxBytes }
|
|
}
|
|
|
|
export async function readLinuxProcNetworkTable(
|
|
filePath: string,
|
|
readFile: LinuxProcTextReader = readBoundedNodeFile
|
|
): Promise<string | null> {
|
|
try {
|
|
return (await readFile(filePath, LINUX_PROC_NETWORK_TABLE_MAX_BYTES)).toString('utf8')
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
export async function readLinuxProcTextWithinBudget(
|
|
filePath: string,
|
|
budget: LinuxProcTextReadBudget,
|
|
readFile: LinuxProcTextReader = readBoundedNodeFile,
|
|
perFileMaxBytes = LINUX_PROC_PROCESS_METADATA_FILE_MAX_BYTES
|
|
): Promise<string | undefined> {
|
|
const maxBytes = Math.min(perFileMaxBytes, budget.remainingBytes)
|
|
if (maxBytes <= 0) {
|
|
return undefined
|
|
}
|
|
try {
|
|
const content = await readFile(filePath, maxBytes)
|
|
if (content.byteLength > maxBytes) {
|
|
return undefined
|
|
}
|
|
budget.remainingBytes -= content.byteLength
|
|
return content.toString('utf8')
|
|
} catch {
|
|
return undefined
|
|
}
|
|
}
|