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(cli): ix text --offset widens the scan window past the first page (HR-02B)
KageBinary03fcf32361dc
diff --git a/ix-cli/src/cli/__tests__/honest-truncation.test.ts b/ix-cli/src/cli/__tests__/honest-truncation.test.tsindex 28cb721c..23db8c23 100644--- a/ix-cli/src/cli/__tests__/honest-truncation.test.ts+++ b/ix-cli/src/cli/__tests__/honest-truncation.test.ts@@ -15,7 +15,7 @@ import {import { IX_CALLER_ENV } from "../next-step.js";import { nextPageCommand, shellQuote } from "../paging.js";import { LIST_MAX_ROWS, registerInventoryCommand, renderInventoryLlm } from "../commands/inventory.js";-import { compareTextResults, keepTopK, scanWindow, textResultPriority } from "../commands/text.js";+import { compareTextResults, keepTopK, SCAN_WINDOW_MAX, scanWindow, textResultPriority } from "../commands/text.js";function node(name: string, path?: string) {return { id: `${name}-0000-0000-0000-000000000000`, name, kind: "function", ...(path ? { provenance: { source_uri: path } } : {}) };@@ -365,6 +365,13 @@ describe("text result ranking", () => {expect(scanWindow(400)).toBe(500);});+ it("widens the scan window with --offset, up to the cap", () => {+ expect(scanWindow(20, 0)).toBe(100);+ expect(scanWindow(20, 100)).toBe(200);+ expect(scanWindow(20, 460)).toBe(SCAN_WINDOW_MAX);+ expect(scanWindow(20, 10_000)).toBe(SCAN_WINDOW_MAX);+ });+it("puts code above tests, and tests above prose", () => {expect(textResultPriority("ix-cli/src/cli/format.ts")).toBe(0);expect(textResultPriority("ix-cli/src/cli/__tests__/format.test.ts")).toBe(1);diff --git a/ix-cli/src/cli/__tests__/text-stream.test.ts b/ix-cli/src/cli/__tests__/text-stream.test.tsindex 2c574249..782d3025 100644--- a/ix-cli/src/cli/__tests__/text-stream.test.ts+++ b/ix-cli/src/cli/__tests__/text-stream.test.ts@@ -154,6 +154,14 @@ describe("text ripgrep stream lifecycle", () => {expect(out[1]).toMatch(/--offset 4 needle"$/);expect(out.slice(2).map((l) => l.match(/line=(\d+)/)?.[1])).toEqual(["3", "4"]);});+ it("pages past the first page's scan window: --offset widens the window", async () => {+ // --limit 1 scans 5 rows at offset 0. Twelve code matches, one per file.+ const records = Array.from({ length: 12 }, (_, i) => matchAt(`src/f${String(i).padStart(2, "0")}.ts`, 1));+ const out = await runArgs(["needle", "--limit", "1", "--offset", "7", "--format", "llm"], records);+ expect(out[0]).toBe("text offset=7 shown=1 scanned=12 truncated=true");+ expect(out[1]).toContain("next_offset=8");+ expect(out.slice(2).map((l) => l.match(/path=(\S+)/)?.[1])).toEqual(["src/f07.ts"]);+ });it("ranks a match record whose fields come in another order the same way", async () => {const reordered = JSON.stringify({ data: { line_number: 2, lines: { text: "late" }, path: { text: "src/a.ts" } }, type: "match" }) + "\n";const out = await runArgs(["needle", "--limit", "5", "--format", "json"], [matchAt("src/b.ts", 1), reordered, matchAt("src/a.ts", 1)]);diff --git a/ix-cli/src/cli/commands/text.ts b/ix-cli/src/cli/commands/text.tsindex 5df6d560..30edd278 100644--- a/ix-cli/src/cli/commands/text.ts+++ b/ix-cli/src/cli/commands/text.ts@@ -235,16 +235,24 @@ export function resolveTextSearchPath(root: string, searchPath: string): string* more than it prints. Bounded so a term matching everything is still one* cheap pass.*- * The window is the best `scanWindow(limit)` matches under+ * The window is the best `scanWindow(limit, offset)` matches under* `compareTextResults`, taken over every match ripgrep finds — not the first- * that many to arrive, which would differ between runs. `--offset` pages are- * cut from this one window, so they only line up while `--limit` stays fixed.+ * that many to arrive, which would differ between runs.+ *+ * `--offset` widens the window to look the same distance past the page as the+ * first page looks past its own, so paging is not stuck inside the first+ * page's window. The window is the top K of one total order, so a wider+ * window only appends rows: page N cut from a wide window is the page N a+ * narrow one would show. Pages line up while `--limit` stays fixed (it is+ * also ripgrep's per-file `--max-count`). The window still stops at+ * SCAN_WINDOW_MAX rows, and past that the output says to narrow.*/const SCAN_WINDOW_FACTOR = 5;-const SCAN_WINDOW_MAX = 500;+export const SCAN_WINDOW_MAX = 500;-export function scanWindow(limit: number): number {- return Math.min(Math.max(limit * SCAN_WINDOW_FACTOR, limit), SCAN_WINDOW_MAX);+export function scanWindow(limit: number, offset = 0): number {+ const ahead = Math.max(limit * SCAN_WINDOW_FACTOR, limit);+ return Math.min(Math.max(offset, 0) + ahead, SCAN_WINDOW_MAX);}const TEST_PATH = /(^|\/)(tests?|__tests__|fixtures?|testdata|spec)(\/|$)|\.(test|spec)\./i;@@ -316,7 +324,7 @@ export function registerTextCommand(program: Command, executeRipgrep?: RunRipgrereturn;}try {- const window = scanWindow(limit);+ const window = scanWindow(limit, offset);const rgArgs = ["--json",// Per file, deliberately still `--limit`: one file monopolising the