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): cap ix impact leaf llm rows at --limit and add path:lines (CL-20E)

KageBinarybc6b813dc959
diff --git a/docs/llm-format.md b/docs/llm-format.md
index 3c75d5c5..384486e2 100644
--- a/docs/llm-format.md
+++ b/docs/llm-format.md
@@ -267,11 +267,15 @@ smell kind=has_smell.orphan_file file=tmp.py confidence=0.8 connections=0
```
impact target=verify_token kind=function risk=high category=boundary summary="Auth check; 14 call sites at risk"
behavior text="Token validation across the request pipeline"
-counts callers=14 callees=3
+counts callers=14 callees=3 shown_callers=10 shown_callees=3
bucket region="Auth Layer" kind=subsystem count=9
-caller name=handleLogin kind=method
+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."
```
+`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 overview <container>`:
```
diff --git a/ix-cli/src/cli/__tests__/impact-leaf-llm.test.ts b/ix-cli/src/cli/__tests__/impact-leaf-llm.test.ts
new file mode 100644
index 00000000..b4dfa249
--- /dev/null
+++ b/ix-cli/src/cli/__tests__/impact-leaf-llm.test.ts
@@ -0,0 +1,54 @@
+// Copyright 2026 Ix Infrastructure Inc.
+
+import { describe, expect, it } from "vitest";
+import { leafRowLlm, leafTruncationLlm } from "../commands/impact.js";
+import { sliceEdgeResults as sliceRanked } from "../format.js";
+
+const node = (name: string, line_start?: number, line_end?: number) => ({
+ id: `id-${name}`,
+ kind: "function",
+ name,
+ attrs: { path: "src/auth/token.ts", line_start, line_end },
+});
+
+describe("impact leaf llm rows", () => {
+ it("carries path and lines on each caller row", () => {
+ expect(leafRowLlm("caller", node("verify", 10, 42))).toBe(
+ "caller name=verify kind=function path=src/auth/token.ts lines=10-42",
+ );
+ });
+
+ it("omits lines when the node has no span", () => {
+ expect(leafRowLlm("callee", node("hash"))).toBe("callee name=hash kind=function path=src/auth/token.ts");
+ });
+
+ 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);
+ 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");
+ });
+
+ it("emits no diagnostic when the list fits", () => {
+ const slice = sliceRanked([node("a"), node("b")], 10);
+ expect(leafTruncationLlm("callers", slice)).toEqual([]);
+ });
+
+ it("writes a single-line span as one number and drops path-less locations", () => {
+ expect(leafRowLlm("caller", node("a", 10, 10))).toBe("caller name=a kind=function path=src/auth/token.ts lines=10");
+ expect(leafRowLlm("caller", { id: "x", kind: "function", name: "b" })).toBe("caller name=b kind=function");
+ });
+
+ it("keeps named rows with a path when cutting a mixed list", () => {
+ 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);
+ 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 33c38074..28b3643f 100644
--- a/ix-cli/src/cli/commands/impact.ts
+++ b/ix-cli/src/cli/commands/impact.ts
@@ -9,7 +9,7 @@ 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, stripNulls } from "../format.js";
+import { lineSpan, printJson, relativePath, rowLocation, sliceEdgeResults, stripNulls, truncationHint, type Slice } from "../format.js";
import { llmLine } from "../llm.js";
import { parsePickOption } from "../options.js";
@@ -23,7 +23,7 @@ export function registerImpactCommand(program: Command): void {
.option("--path <path>", "Restrict to symbols from files matching this path substring")
.option("--pick <n>", "Pick Nth candidate from ambiguous results (1-based)", parsePickOption)
.option("--depth <n>", "Expansion depth for callers/importers (default 1, max 3)", "1")
- .option("--limit <n>", "Max top-impacted members to show", "10")
+ .option("--limit <n>", "Max top-impacted members (and llm caller/callee rows) to show", "10")
.option("--format <fmt>", "Output format (text|json|llm)", "text")
.addHelpText(
"after",
@@ -55,7 +55,7 @@ export function registerImpactCommand(program: Command): void {
if (CONTAINER_KINDS.has(target.kind)) {
await containerImpact(client, target, limit, depth, opts.format, graph);
} else {
- await leafImpact(client, target, depth, opts.format, graph);
+ await leafImpact(client, target, depth, limit, opts.format, graph);
}
}
);
@@ -478,10 +478,31 @@ async function containerImpact(
// ── Leaf impact ──────────────────────────────────────────────────────────────
+/** One caller or callee row, located the way member rows are: `path` and `lines`. */
+export function leafRowLlm(kind: string, node: any): string {
+ const loc = rowLocation(node);
+ return llmLine(kind, [
+ ["name", node.name || node.attrs?.name || "(unnamed)"],
+ ["kind", node.kind],
+ ["path", loc.path],
+ ["lines", lineSpan(loc)],
+ ]);
+}
+
+/** The honest-cut record for a leaf list, or nothing when the list fit. */
+export function leafTruncationLlm(relation: string, slice: Slice<unknown>): string[] {
+ if (!slice.truncated) return [];
+ return [llmLine("diagnostic", [
+ ["code", "results_truncated"],
+ ["message", truncationHint(slice, relation)],
+ ])];
+}
+
async function leafImpact(
client: IxClient,
target: { id: string; kind: string; name: string; resolutionMode: string; path?: string },
depth: number,
+ limit: number,
format: string,
graph?: Record<string, unknown>,
): Promise<void> {
@@ -575,17 +596,21 @@ async function leafImpact(
}),
);
} else if (format === "llm") {
- const toRef = (kind: string) => (n: any) =>
- llmLine(kind, [["name", n.name || n.attrs?.name || "(unnamed)"], ["kind", n.kind]]);
+ const callerSlice = sliceEdgeResults(callersResult.nodes, limit);
+ const calleeSlice = sliceEdgeResults(calleesResult.nodes, limit);
const lines = [
...impactHeaderLlm(target, risk, systemPathMapped),
llmLine("counts", [
- ["callers", callersResult.nodes.length],
- ["callees", calleesResult.nodes.length],
+ ["callers", callerSlice.total],
+ ["callees", calleeSlice.total],
+ ["shown_callers", callerSlice.shown],
+ ["shown_callees", calleeSlice.shown],
]),
...impactPropagationLlm(propagationBuckets, risk.flowPropagation),
- ...callersResult.nodes.map(toRef("caller")),
- ...calleesResult.nodes.map(toRef("callee")),
+ ...callerSlice.rows.map((n: any) => leafRowLlm("caller", n)),
+ ...calleeSlice.rows.map((n: any) => leafRowLlm("callee", n)),
+ ...leafTruncationLlm("callers", callerSlice),
+ ...leafTruncationLlm("callees", calleeSlice),
...impactTailLlm(risk, decisions, tasks, bugs),
];
for (const line of lines) console.log(line);