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
feat(cli): number the source lines of read --format llm
KageBinaryf26999fff3a6
diff --git a/ix-cli/src/cli/__tests__/llm-tier5.test.ts b/ix-cli/src/cli/__tests__/llm-tier5.test.tsindex 8fc7fd24..1b320bcb 100644--- a/ix-cli/src/cli/__tests__/llm-tier5.test.ts+++ b/ix-cli/src/cli/__tests__/llm-tier5.test.ts@@ -103,7 +103,7 @@ describe("explain --format llm", () => {});describe("read --format llm", () => {- it("drops the per-line gutter and self-delimits the payload", () => {+ it("numbers each line with a bare tab gutter and self-delimits the payload", () => {const lines = renderReadLlm({targetType: "symbol", path: "/repo/src/auth.py",lineStart: 10, lineEnd: 12,@@ -115,10 +115,11 @@ describe("read --format llm", () => {expect(lines[0]).toContain("symbol=verify");// content lines=<n> tells the consumer exactly how many lines follow, so a// line of source can never be mistaken for another record.- expect(lines[1]).toBe("content lines=3");- expect(lines.slice(2)).toEqual(["def verify():", " return True", ""]);- // No line number prefixes anywhere.- expect(lines.slice(2).some(l => /^\s*\d+ /.test(l))).toBe(false);+ // numbered=true says every payload line is `<n>\t<source>`.+ expect(lines[1]).toBe("content lines=3 numbered=true");+ // The file's own line numbers, starting at line_start, in the `cat -n`+ // shape an agent can cite and strip: no padding, no ANSI, one tab.+ expect(lines.slice(2)).toEqual(["10\tdef verify():", "11\t return True", "12\t"]);});it("lists candidates when the target is ambiguous", () => {@@ -303,12 +304,14 @@ describe("read --format llm content framing", () => {it("keeps the blank line in place rather than closing the gap", () => {const out = emit("a\n\nb\n");expect(out.slice(out.findIndex(l => l.startsWith("content lines=")) + 1))- .toEqual(["a", "", "b", ""]);+ .toEqual(["1\ta", "2\t", "3\tb", "4\t"]);});- it("routes --format llm to records, not the numbered gutter", () => {+ it("routes --format llm to records, not the padded text gutter", () => {const out = emit("x\ny");expect(out[0]).toContain("file path=");+ // text's gutter is `padStart(4)` + a space; llm's is a bare number + tab.expect(out.some(l => /^\s*\d+ /.test(l))).toBe(false);+ expect(out.slice(-2)).toEqual(["1\tx", "2\ty"]);});});diff --git a/ix-cli/src/cli/__tests__/read-line-cap.test.ts b/ix-cli/src/cli/__tests__/read-line-cap.test.tsindex 0c643840..f1d6317e 100644--- a/ix-cli/src/cli/__tests__/read-line-cap.test.ts+++ b/ix-cli/src/cli/__tests__/read-line-cap.test.ts@@ -55,7 +55,9 @@ describe("ix read line cap", () => {expect(logs[0]).toContain("truncated=true");expect(logs[0]).toContain("total_lines=1734");expect(logs[0]).toContain("next=src/big.ts:401-800");- expect(logs[1]).toBe("content lines=400");+ expect(logs[1]).toBe("content lines=400 numbered=true");+ expect(logs[2]).toMatch(/^1\t/);+ expect(logs[401]).toMatch(/^400\t/);});it("--all restores the whole file", async () => {diff --git a/ix-cli/src/cli/commands/read.ts b/ix-cli/src/cli/commands/read.tsindex c28ab92a..f5770b8d 100644--- a/ix-cli/src/cli/commands/read.ts+++ b/ix-cli/src/cli/commands/read.ts@@ -167,15 +167,18 @@ function withCursor(/*** `ix read --format llm`.*- * The one command whose payload is not records: an agent asked for source and- * wants it byte-for-byte. Everything around it goes, though — `text` prefixes- * every single line with a 4-column padded line number and an ANSI dim escape,- * which on a 200-line read is 200 gutters of pure overhead for information the- * `line_start` field already carries once.+ * The one command whose payload is not records: an agent asked for source.+ * Everything around it goes — `text` pads a 4-column gutter and wraps it in+ * an ANSI dim escape — but the line numbers themselves stay, as a bare+ * `<n>\t` prefix in the shape `cat -n` taught every agent to read. Without+ * them the reader had `line_start` and a count, and to cite or edit line 312+ * it had to count lines by hand or read the file again with a tool that+ * numbers them; 23 of 31 benchmark reads were followed by exactly that.*- * The `content lines=<n>` record makes the block self-delimiting, so a- * consumer knows exactly how many following lines are payload and never has to- * guess whether a line of source is another record.+ * The `content lines=<n> numbered=true` record makes the block+ * self-delimiting, so a consumer knows exactly how many following lines are+ * payload and never has to guess whether a line of source is another record,+ * and says that each one carries a number to strip before the source.*/export function renderReadLlm(result: ReadResult): string[] {const contentLines = result.content.split("\n");@@ -193,8 +196,8 @@ export function renderReadLlm(result: ReadResult): string[] {["total_lines", result.totalLines !== undefined ? String(result.totalLines) : null],["next", result.next],]),- llmLine("content", [["lines", String(contentLines.length)]]),- ...contentLines,+ llmLine("content", [["lines", String(contentLines.length)], ["numbered", "true"]]),+ ...contentLines.map((line, i) => `${result.lineStart + i}\t${line}`),];}