Understand any codebase instantly. System intelligence for codebases, built for humans and AI.
TypeScript aiai-memoryclaude-codeclicode-analysiscode-mappingcode-memorycodebase-understandingcodexdeveloper-toolsllmopenclawpersistent-memoryprogram-analysissoftware-architecturesystem-intelligencesystem-mapping
fix(context): size-check and read a scanned file through one descriptor
KageBinary326c593db26c
diff --git a/ix-cli/src/cli/__tests__/text-references.test.ts b/ix-cli/src/cli/__tests__/text-references.test.tsindex 852e0998..6c540b37 100644--- a/ix-cli/src/cli/__tests__/text-references.test.ts+++ b/ix-cli/src/cli/__tests__/text-references.test.ts@@ -152,6 +152,9 @@ describe("gitRepoAccess", () => {const repo = gitRepoAccess(dir)!;expect(repo.files().sort()).toEqual(["src/a.ts", "src/b.ts"]);expect(repo.read("src/a.ts")).toContain("b.ts");+ expect(repo.read("src/missing.ts")).toBeUndefined();+ write("src/big.ts", "x".repeat(300 * 1024));+ expect(repo.read("src/big.ts")).toBeUndefined();expect(repo.grep("b.ts")).toEqual([{ path: "src/a.ts", line: "// see b.ts" }]);expect(repo.grep("nothing-matches")).toEqual([]);});diff --git a/ix-cli/src/cli/explain/text-references.ts b/ix-cli/src/cli/explain/text-references.tsindex 0c04ce39..e17e15a9 100644--- a/ix-cli/src/cli/explain/text-references.ts+++ b/ix-cli/src/cli/explain/text-references.ts@@ -1,7 +1,7 @@// Copyright 2026 Ix Infrastructure Inc.import { execFileSync } from "node:child_process";-import { existsSync, readFileSync, statSync } from "node:fs";+import { closeSync, fstatSync, openSync, readFileSync } from "node:fs";import { join, posix } from "node:path";/**@@ -207,12 +207,18 @@ export function gitRepoAccess(root: string): RepoAccess | undefined {return {files: () => listing,read: (path) => {- const abs = join(root, path);+ // One descriptor for the size check and the read, so the file measured+ // is the file read (CodeQL js/file-system-race). A missing file throws+ // at open and reads as undefined, as an unreadable one does.+ let fd: number | undefined;try {- if (!existsSync(abs) || statSync(abs).size > MAX_SCAN_BYTES) return undefined;- return readFileSync(abs, "utf-8");+ fd = openSync(join(root, path), "r");+ if (fstatSync(fd).size > MAX_SCAN_BYTES) return undefined;+ return readFileSync(fd, "utf-8");} catch {return undefined;+ } finally {+ if (fd !== undefined) closeSync(fd);}},grep: (needle) => {