Skip to content

armgit / Ix

Public Imported from GitHub
0

Understand any codebase instantly. System intelligence for codebases, built for humans and AI.

fix(cli): ix impact leaf truncation never points at --offset (CL-20E)

KageBinary3425c2fec267
diff --git a/docs/llm-format.md b/docs/llm-format.md
index 384486e2..538d94d4 100644
--- a/docs/llm-format.md
+++ b/docs/llm-format.md
@@ -270,11 +270,13 @@ behavior text="Token validation across the request pipeline"
counts callers=14 callees=3 shown_callers=10 shown_callees=3
bucket region="Auth Layer" kind=subsystem count=9
caller name=handleLogin kind=method path=src/auth/login.ts lines=20-48
-diagnostic code=results_truncated message="14 callers; showing 10. Raise --limit to see the rest."
+diagnostic code=results_truncated message="14 callers; showing 10. Raise --limit to see them, or page them with ix callers verify_token"
```
`callers` and `callees` are the true totals; `shown_callers` and `shown_callees` are the rows
printed after the `--limit` cut (the two lists share one header, so `shown`/`total` are split by list).
+`ix impact` has no `--offset`, so its truncation diagnostic carries no `next_offset=`; it points at
+`ix callers`/`ix callees` (over MCP, `ix_neighbors`), which page.
`ix overview <container>`:
diff --git a/ix-cli/src/cli/__tests__/impact-leaf-limit-wiring.test.ts b/ix-cli/src/cli/__tests__/impact-leaf-limit-wiring.test.ts
new file mode 100644
index 00000000..c2c0f503
--- /dev/null
+++ b/ix-cli/src/cli/__tests__/impact-leaf-limit-wiring.test.ts
@@ -0,0 +1,70 @@
+// Copyright 2026 Ix Infrastructure Inc.
+
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { Command } from "commander";
+
+import { registerImpactCommand } from "../commands/impact.js";
+
+/**
+ * `--limit` has to reach the leaf llm branch through the command, not only
+ * through the helpers: 25 callers with `--limit 3` print three caller rows and
+ * the true totals. json keeps every caller.
+ */
+
+const { expand } = vi.hoisted(() => ({ expand: vi.fn() }));
+
+vi.mock("../../client/factory.js", () => ({
+ createClient: () => ({ expand: (...args: unknown[]) => expand(...args) }),
+}));
+vi.mock("../resolve.js", async (importOriginal) => ({
+ ...await importOriginal<typeof import("../resolve.js")>(),
+ resolveFileOrReport: async () => ({ id: "11111111-0000-0000-0000-000000000000", kind: "function", name: "verify", resolutionMode: "exact" }),
+ printResolved: () => {},
+}));
+vi.mock("../graph-health.js", async (importOriginal) => ({
+ ...await importOriginal<typeof import("../graph-health.js")>(),
+ checkGraphHealth: async () => ({ status: "healthy" }),
+}));
+vi.mock("../hierarchy.js", async (importOriginal) => ({
+ ...await importOriginal<typeof import("../hierarchy.js")>(),
+ getSystemPath: async () => [],
+ bucketByHierarchy: async () => [],
+}));
+
+const callers = Array.from({ length: 25 }, (_, i) => ({
+ id: `c${i}`, kind: "function", name: `caller${String(i).padStart(2, "0")}`, attrs: { path: "src/a.ts", line_start: i + 1, line_end: i + 1 },
+}));
+
+async function run(args: string[]): Promise<string[]> {
+ const program = new Command().name("ix").exitOverride();
+ registerImpactCommand(program);
+ const out: string[] = [];
+ vi.spyOn(console, "log").mockImplementation((...parts) => { out.push(parts.join(" ")); });
+ vi.spyOn(process.stderr, "write").mockImplementation(() => true);
+ await program.parseAsync(["impact", "verify", ...args], { from: "user" });
+ return out;
+}
+
+describe("ix impact --limit reaches the leaf llm rows", () => {
+ beforeEach(() => {
+ expand.mockReset();
+ expand.mockImplementation(async (_id: string, opts: { direction: string; predicates: string[] }) =>
+ opts.direction === "in" && opts.predicates.includes("CALLS") ? { nodes: callers, edges: [] } : { nodes: [], edges: [] });
+ });
+ afterEach(() => vi.restoreAllMocks());
+
+ it("llm: --limit 3 prints three caller rows and the true counts", async () => {
+ const out = await run(["--limit", "3", "--format", "llm"]);
+ expect(out.filter((l) => l.startsWith("caller "))).toHaveLength(3);
+ expect(out).toContain("counts callers=25 callees=0 shown_callers=3 shown_callees=0");
+ const diag = out.find((l) => l.startsWith("diagnostic code=results_truncated"));
+ expect(diag).toContain("25 callers; showing 3.");
+ expect(diag).not.toContain("--offset");
+ });
+
+ it("json: --limit does not cut the caller list", async () => {
+ const json = JSON.parse((await run(["--limit", "3", "--format", "json"])).join("\n"));
+ expect(json.summary.callers).toBe(25);
+ expect(json.callerList).toHaveLength(25);
+ });
+});
diff --git a/ix-cli/src/cli/__tests__/impact-leaf-llm.test.ts b/ix-cli/src/cli/__tests__/impact-leaf-llm.test.ts
index b4dfa249..c8737ec9 100644
--- a/ix-cli/src/cli/__tests__/impact-leaf-llm.test.ts
+++ b/ix-cli/src/cli/__tests__/impact-leaf-llm.test.ts
@@ -2,7 +2,8 @@
import { describe, expect, it } from "vitest";
import { leafRowLlm, leafTruncationLlm } from "../commands/impact.js";
-import { sliceEdgeResults as sliceRanked } from "../format.js";
+import { sliceEdgeResults } from "../format.js";
+import { IX_CALLER_ENV } from "../next-step.js";
const node = (name: string, line_start?: number, line_end?: number) => ({
id: `id-${name}`,
@@ -24,19 +25,43 @@ describe("impact leaf llm rows", () => {
it("cuts an over-limit list with honest shown and total and a truncation diagnostic", () => {
const all = Array.from({ length: 25 }, (_, i) => node(`c${i}`, i + 1, i + 1));
- const slice = sliceRanked(all, 10);
+ const slice = sliceEdgeResults(all, 10);
expect(slice.shown).toBe(10);
expect(slice.total).toBe(25);
expect(slice.rows).toHaveLength(10);
- const diag = leafTruncationLlm("callers", slice);
- expect(diag).toHaveLength(1);
- expect(diag[0]).toContain("code=results_truncated");
- expect(diag[0]).toContain("25 callers; showing 10");
+ const diag = leafTruncationLlm("callers", slice, "verify");
+ expect(diag).toEqual([
+ 'diagnostic code=results_truncated message="25 callers; showing 10. Raise --limit to see them, or page them with ix callers verify"',
+ ]);
+ });
+
+ it("never points at --offset or next_offset: ix impact has no --offset", () => {
+ const all = Array.from({ length: 25 }, (_, i) => node(`c${i}`, i + 1, i + 1));
+ // Even a slice that carries a next page (as the paging helpers set one) prints none.
+ const slice = { ...sliceEdgeResults(all, 10), nextOffset: 10, next: "ix callers verify --offset 10" };
+ const diag = leafTruncationLlm("callers", slice, "verify").join("\n");
+ expect(diag).not.toContain("--offset");
+ expect(diag).not.toContain("next_offset");
+ expect(diag).not.toContain("next:");
+ });
+
+ it("over MCP names the ix_neighbors call that pages the list", () => {
+ const prev = process.env[IX_CALLER_ENV];
+ process.env[IX_CALLER_ENV] = "mcp";
+ try {
+ const slice = sliceEdgeResults(Array.from({ length: 25 }, (_, i) => node(`c${i}`)), 10);
+ expect(leafTruncationLlm("callees", slice, "verify")[0]).toBe(
+ 'diagnostic code=results_truncated message="25 callees; showing 10. To page them: ix_neighbors symbol=verify relation=callees"',
+ );
+ } finally {
+ if (prev === undefined) delete process.env[IX_CALLER_ENV];
+ else process.env[IX_CALLER_ENV] = prev;
+ }
});
it("emits no diagnostic when the list fits", () => {
- const slice = sliceRanked([node("a"), node("b")], 10);
- expect(leafTruncationLlm("callers", slice)).toEqual([]);
+ const slice = sliceEdgeResults([node("a"), node("b")], 10);
+ expect(leafTruncationLlm("callers", slice, "verify")).toEqual([]);
});
it("writes a single-line span as one number and drops path-less locations", () => {
@@ -48,7 +73,7 @@ describe("impact leaf llm rows", () => {
const raw = Array.from({ length: 5 }, () => ({ id: "0123456789abcdef0123456789abcdef", kind: "function", name: "0123456789abcdef0123456789abcdef" }));
const nopath = Array.from({ length: 5 }, (_, i) => ({ id: `n${i}`, kind: "function", name: `np${i}` }));
const good = Array.from({ length: 4 }, (_, i) => node(`g${i}`, 1, 2));
- const slice = sliceRanked([...raw, ...nopath, ...good], 4);
+ const slice = sliceEdgeResults([...raw, ...nopath, ...good], 4);
expect(slice.rows.map((r: any) => r.name)).toEqual(["g0", "g1", "g2", "g3"]);
});
});
diff --git a/ix-cli/src/cli/commands/impact.ts b/ix-cli/src/cli/commands/impact.ts
index 28b3643f..f8e073e2 100644
--- a/ix-cli/src/cli/commands/impact.ts
+++ b/ix-cli/src/cli/commands/impact.ts
@@ -9,7 +9,8 @@ import { activeReadScope, resolveFileOrReport, printResolved } from "../resolve.
import { checkGraphHealth, graphHealthJson, graphHealthLlmFields, graphHealthProse, isUnhealthy } from "../graph-health.js";
import { bucketByHierarchy, getSystemPath, formatSystemPath, hasMapData, type SystemPath } from "../hierarchy.js";
import { inferRiskSemantics, humanizeLabel, type ImpactFacts, type RiskSemantics } from "../impact/risk-semantics.js";
-import { lineSpan, printJson, relativePath, rowLocation, sliceEdgeResults, stripNulls, truncationHint, type Slice } from "../format.js";
+import { lineSpan, printJson, relativePath, rowLocation, sliceEdgeResults, stripNulls, type Slice } from "../format.js";
+import { forMcp, suggest, type Relation } from "../next-step.js";
import { llmLine } from "../llm.js";
import { parsePickOption } from "../options.js";
@@ -489,12 +490,24 @@ export function leafRowLlm(kind: string, node: any): string {
]);
}
-/** The honest-cut record for a leaf list, or nothing when the list fit. */
-export function leafTruncationLlm(relation: string, slice: Slice<unknown>): string[] {
+/**
+ * The honest-cut record for a leaf list, or nothing when the list fit.
+ *
+ * Its own message, not `truncationHint`: `ix impact` has no `--offset`, so it
+ * must never print a `next:` page or a `next_offset`, whatever the shared
+ * slice helpers grow. The rest of the list is one `--limit` away, or pageable
+ * through the edge command for the same relation.
+ */
+export function leafTruncationLlm(relation: Relation, slice: Slice<unknown>, target: string): string[] {
if (!slice.truncated) return [];
+ const head = `${slice.total} ${relation}; showing ${slice.shown}.`;
+ const page = suggest.neighbors(target, relation);
+ const message = forMcp()
+ ? `${head} To page them: ${page}`
+ : `${head} Raise --limit to see them, or page them with ${page}`;
return [llmLine("diagnostic", [
["code", "results_truncated"],
- ["message", truncationHint(slice, relation)],
+ ["message", message],
])];
}
@@ -609,8 +622,8 @@ async function leafImpact(
...impactPropagationLlm(propagationBuckets, risk.flowPropagation),
...callerSlice.rows.map((n: any) => leafRowLlm("caller", n)),
...calleeSlice.rows.map((n: any) => leafRowLlm("callee", n)),
- ...leafTruncationLlm("callers", callerSlice),
- ...leafTruncationLlm("callees", calleeSlice),
+ ...leafTruncationLlm("callers", callerSlice, target.name),
+ ...leafTruncationLlm("callees", calleeSlice, target.name),
...impactTailLlm(risk, decisions, tasks, bugs),
];
for (const line of lines) console.log(line);