Skip to content

armgit / Ix

Public Imported from GitHub
0

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

feat(cli): locate impact JSON rows and list container dependents (#876)

Ian Hock96fae70a05ba
diff --git a/docs/llm-format.md b/docs/llm-format.md
index cf776b28..448da1da 100644
--- a/docs/llm-format.md
+++ b/docs/llm-format.md
@@ -508,6 +508,9 @@ diagnostic code=results_truncated message="14 callers; showing 10. Raise --limit
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.
+In `--format json` the same rows (`callerList`, `calleeList`, bucket `members`) carry `path`,
+`lineStart` and `lineEnd`, and a container target's JSON adds `dependentList`, its located
+importers and dependents.
`ix overview <container>`:
diff --git a/ix-cli/src/cli/__tests__/impact-json-locations.baseline.ts b/ix-cli/src/cli/__tests__/impact-json-locations.baseline.ts
new file mode 100644
index 00000000..b32591fc
--- /dev/null
+++ b/ix-cli/src/cli/__tests__/impact-json-locations.baseline.ts
@@ -0,0 +1,474 @@
+// Copyright 2026 Ix Infrastructure Inc.
+
+/**
+ * What `ix impact` printed for the graph in impact-json-locations.test.ts
+ * before its JSON rows carried path/lineStart/lineEnd and containers gained
+ * dependentList: the json, llm and text output, the exit code, and how many
+ * requests each json run made. Captured from the command, not written by hand.
+ */
+export const BASELINE = {
+ "json": {
+ "leaf": {
+ "resolvedTarget": {
+ "kind": "function",
+ "name": "verify"
+ },
+ "depth": 1,
+ "systemPath": [
+ {
+ "name": "App",
+ "kind": "system"
+ },
+ {
+ "name": "Auth Layer",
+ "kind": "subsystem"
+ }
+ ],
+ "riskSummary": "Medium risk — widely shared dependency affecting the auth layer layer.",
+ "riskLevel": "medium",
+ "riskCategory": "shared",
+ "atRiskBehavior": [
+ "Multiple callers across different subsystems",
+ "Downstream operations coordinated by this component",
+ "Cross-module behavior consistency"
+ ],
+ "summary": {
+ "callers": 5,
+ "callees": 1
+ },
+ "callerList": [
+ {
+ "kind": "method",
+ "name": "login"
+ },
+ {
+ "kind": "function",
+ "name": "handle"
+ },
+ {
+ "kind": "file",
+ "name": "main.ts"
+ },
+ {
+ "kind": "function",
+ "name": "orphan"
+ },
+ {
+ "name": "lazy"
+ }
+ ],
+ "calleeList": [
+ {
+ "kind": "function",
+ "name": "decode_jwt"
+ }
+ ],
+ "propagationBuckets": [
+ {
+ "region": "Auth Layer",
+ "regionKind": "subsystem",
+ "count": 4,
+ "members": [
+ {
+ "name": "login",
+ "kind": "method"
+ },
+ {
+ "name": "handle",
+ "kind": "function"
+ },
+ {
+ "name": "main.ts",
+ "kind": "file"
+ },
+ {
+ "name": "lazy",
+ "kind": "function"
+ }
+ ]
+ },
+ {
+ "region": "Core",
+ "regionKind": "module",
+ "count": 1,
+ "members": [
+ {
+ "name": "orphan",
+ "kind": "function"
+ }
+ ]
+ }
+ ],
+ "decisions": [
+ {
+ "id": "dec1",
+ "name": "Use JWT"
+ }
+ ]
+ },
+ "file": {
+ "resolvedTarget": {
+ "kind": "file",
+ "name": "auth.ts"
+ },
+ "depth": 1,
+ "riskSummary": "Low risk to dependent code.",
+ "riskLevel": "low",
+ "riskCategory": "unknown",
+ "atRiskBehavior": [
+ "Dependent code behavior"
+ ],
+ "summary": {
+ "members": 2,
+ "directImporters": 2,
+ "directDependents": 2,
+ "memberLevelCallers": 3
+ },
+ "topImpactedMembers": [
+ {
+ "name": "verify",
+ "kind": "function",
+ "id": "m1",
+ "callerCount": 2,
+ "path": "src/auth.ts",
+ "lineStart": 1,
+ "lineEnd": 20
+ },
+ {
+ "name": "Session",
+ "kind": "class",
+ "id": "m2",
+ "callerCount": 1,
+ "path": "src/auth.ts",
+ "lineStart": 22,
+ "lineEnd": 80
+ }
+ ],
+ "propagationBuckets": [
+ {
+ "region": "Auth Layer",
+ "regionKind": "subsystem",
+ "count": 2,
+ "members": [
+ {
+ "name": "app.ts",
+ "kind": "file"
+ },
+ {
+ "name": "boot",
+ "kind": "function"
+ }
+ ]
+ },
+ {
+ "region": "Core",
+ "regionKind": "module",
+ "count": 1,
+ "members": [
+ {
+ "name": "handle",
+ "kind": "method"
+ }
+ ]
+ }
+ ],
+ "tasks": [
+ {
+ "id": "task1",
+ "name": "Rotate keys",
+ "status": "open"
+ }
+ ]
+ },
+ "class": {
+ "resolvedTarget": {
+ "kind": "class",
+ "name": "Session"
+ },
+ "depth": 1,
+ "riskSummary": "Low risk to dependent code.",
+ "riskLevel": "low",
+ "riskCategory": "unknown",
+ "atRiskBehavior": [
+ "Dependent code behavior"
+ ],
+ "summary": {
+ "members": 1,
+ "directImporters": 1,
+ "directDependents": 3,
+ "memberLevelCallers": 1
+ },
+ "topImpactedMembers": [
+ {
+ "name": "Session",
+ "kind": "class",
+ "id": "m2",
+ "callerCount": 1,
+ "path": "src/auth.ts",
+ "lineStart": 22,
+ "lineEnd": 80
+ }
+ ],
+ "propagationBuckets": [
+ {
+ "region": "Auth Layer",
+ "regionKind": "subsystem",
+ "count": 1,
+ "members": [
+ {
+ "name": "boot",
+ "kind": "function"
+ }
+ ]
+ },
+ {
+ "region": "Core",
+ "regionKind": "module",
+ "count": 2,
+ "members": [
+ {
+ "name": "handle",
+ "kind": "method"
+ },
+ {
+ "name": "nowhere",
+ "kind": "function"
+ }
+ ]
+ }
+ ]
+ },
+ "all": {
+ "target": "target",
+ "resolutionMode": "all",
+ "candidates": [
+ {
+ "n": 1,
+ "id": "t-verify",
+ "name": "verify",
+ "kind": "function",
+ "path": "src/auth.ts"
+ },
+ {
+ "n": 2,
+ "id": "t-class",
+ "name": "Session",
+ "kind": "class",
+ "path": "src/session.ts"
+ }
+ ],
+ "results": [
+ {
+ "candidate": 1,
+ "resolvedTarget": {
+ "kind": "function",
+ "name": "verify"
+ },
+ "depth": 1,
+ "systemPath": [
+ {
+ "name": "App",
+ "kind": "system"
+ },
+ {
+ "name": "Auth Layer",
+ "kind": "subsystem"
+ }
+ ],
+ "riskSummary": "Medium risk — widely shared dependency affecting the auth layer layer.",
+ "riskLevel": "medium",
+ "riskCategory": "shared",
+ "atRiskBehavior": [
+ "Multiple callers across different subsystems",
+ "Downstream operations coordinated by this component",
+ "Cross-module behavior consistency"
+ ],
+ "summary": {
+ "callers": 5,
+ "callees": 1
+ },
+ "callerList": [
+ {
+ "kind": "method",
+ "name": "login"
+ },
+ {
+ "kind": "function",
+ "name": "handle"
+ },
+ {
+ "kind": "file",
+ "name": "main.ts"
+ },
+ {
+ "kind": "function",
+ "name": "orphan"
+ },
+ {
+ "name": "lazy"
+ }
+ ],
+ "calleeList": [
+ {
+ "kind": "function",
+ "name": "decode_jwt"
+ }
+ ],
+ "propagationBuckets": [
+ {
+ "region": "Auth Layer",
+ "regionKind": "subsystem",
+ "count": 4,
+ "members": [
+ {
+ "name": "login",
+ "kind": "method"
+ },
+ {
+ "name": "handle",
+ "kind": "function"
+ },
+ {
+ "name": "main.ts",
+ "kind": "file"
+ },
+ {
+ "name": "lazy",
+ "kind": "function"
+ }
+ ]
+ },
+ {
+ "region": "Core",
+ "regionKind": "module",
+ "count": 1,
+ "members": [
+ {
+ "name": "orphan",
+ "kind": "function"
+ }
+ ]
+ }
+ ],
+ "decisions": [
+ {
+ "id": "dec1",
+ "name": "Use JWT"
+ }
+ ]
+ },
+ {
+ "candidate": 2,
+ "resolvedTarget": {
+ "kind": "class",
+ "name": "Session"
+ },
+ "depth": 1,
+ "riskSummary": "Low risk to dependent code.",
+ "riskLevel": "low",
+ "riskCategory": "unknown",
+ "atRiskBehavior": [
+ "Dependent code behavior"
+ ],
+ "summary": {
+ "members": 1,
+ "directImporters": 1,
+ "directDependents": 3,
+ "memberLevelCallers": 1
+ },
+ "topImpactedMembers": [
+ {
+ "name": "Session",
+ "kind": "class",
+ "id": "m2",
+ "callerCount": 1,
+ "path": "src/auth.ts",
+ "lineStart": 22,
+ "lineEnd": 80
+ }
+ ],
+ "propagationBuckets": [
+ {
+ "region": "Auth Layer",
+ "regionKind": "subsystem",
+ "count": 1,
+ "members": [
+ {
+ "name": "boot",
+ "kind": "function"
+ }
+ ]
+ },
+ {
+ "region": "Core",
+ "regionKind": "module",
+ "count": 2,
+ "members": [
+ {
+ "name": "handle",
+ "kind": "method"
+ },
+ {
+ "name": "nowhere",
+ "kind": "function"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ },
+ "llm": {
+ "leaf": "impact target=verify kind=function risk=medium category=shared system_path=\"App,Auth Layer\" summary=\"Medium risk — widely shared dependency affecting the auth layer layer.\"\nbehavior text=\"Multiple callers across different subsystems\"\nbehavior text=\"Downstream operations coordinated by this component\"\nbehavior text=\"Cross-module behavior consistency\"\ncounts callers=5 callees=1 shown_callers=5 shown_callees=1\nbucket region=\"auth layer layer\" kind=subsystem count=4\nbucket region=\"core layer\" kind=module count=1\ncaller name=login kind=method path=src/auth/login.ts lines=10-42\ncaller name=handle kind=function path=src/http/handle.ts\ncaller name=main.ts kind=file path=src/main.ts\ncaller name=orphan kind=function\ncaller name=lazy\ncallee name=decode_jwt kind=function path=src/jwt.ts lines=3-9\ndecision name=\"Use JWT\"",
+ "file": "impact target=auth.ts kind=file risk=low category=unknown summary=\"Low risk to dependent code.\"\nbehavior text=\"Dependent code behavior\"\ncounts members=2 importers=2 dependents=2 member_callers=3\nbucket region=\"auth layer layer\" kind=subsystem count=2\nbucket region=\"core layer\" kind=module count=1\nmember name=verify kind=function callers=2 path=src/auth.ts lines=1-20\nmember name=Session kind=class callers=1 path=src/auth.ts lines=22-80\ntask name=\"Rotate keys\" status=open",
+ "class": "impact target=Session kind=class risk=low category=unknown summary=\"Low risk to dependent code.\"\nbehavior text=\"Dependent code behavior\"\ncounts members=1 importers=1 dependents=3 member_callers=1\nbucket region=\"core layer\" kind=module count=2\nbucket region=\"auth layer layer\" kind=subsystem count=1\nmember name=Session kind=class callers=1 path=src/auth.ts lines=22-80",
+ "all": "impact_all target=target candidates=2 total=2\ncandidate n=1 name=verify kind=function path=src/auth.ts id=t-verify\nimpact target=verify kind=function risk=medium category=shared system_path=\"App,Auth Layer\" summary=\"Medium risk — widely shared dependency affecting the auth layer layer.\"\nbehavior text=\"Multiple callers across different subsystems\"\nbehavior text=\"Downstream operations coordinated by this component\"\nbehavior text=\"Cross-module behavior consistency\"\ncounts callers=5 callees=1 shown_callers=5 shown_callees=1\nbucket region=\"auth layer layer\" kind=subsystem count=4\nbucket region=\"core layer\" kind=module count=1\ncaller name=login kind=method path=src/auth/login.ts lines=10-42\ncaller name=handle kind=function path=src/http/handle.ts\ncaller name=main.ts kind=file path=src/main.ts\ncaller name=orphan kind=function\ncaller name=lazy\ncallee name=decode_jwt kind=function path=src/jwt.ts lines=3-9\ndecision name=\"Use JWT\"\ncandidate n=2 name=Session kind=class path=src/session.ts id=t-class\nimpact target=Session kind=class risk=low category=unknown summary=\"Low risk to dependent code.\"\nbehavior text=\"Dependent code behavior\"\ncounts members=1 importers=1 dependents=3 member_callers=1\nbucket region=\"core layer\" kind=module count=2\nbucket region=\"auth layer layer\" kind=subsystem count=1\nmember name=Session kind=class callers=1 path=src/auth.ts lines=22-80"
+ },
+ "text": {
+ "leaf": "Resolved: function verify\n\n System path: App > Auth Layer\n\nRisk summary\n Medium risk — widely shared dependency affecting the auth layer layer.\n\nAt-risk behavior\n • Multiple callers across different subsystems\n • Downstream operations coordinated by this component\n • Cross-module behavior consistency\n\nPropagation\n auth layer layer 4 dependents\n core layer 1 dependents\n\nMost affected\n • callers across multiple subsystems\n • Callers: login, handle and 3 more\n\nSupporting context\n Direct callers: 5\n Direct callees: 1\n\nCalls\n function decode_jwt\n\nDecisions\n Use JWT",
+ "file": "Resolved: file auth.ts\n\n\nRisk summary\n Low risk to dependent code.\n\nAt-risk behavior\n • Dependent code behavior\n\nPropagation\n auth layer layer 2 dependents\n core layer 1 dependents\n\nMost affected\n • verify, Session in the container\n\nSupporting context\n Members: 2\n Importers: 2\n Direct dependents:2\n Member-level callers:3\n\nTasks\n ○ [open] Rotate keys",
+ "class": "Resolved: class Session\n\n\nRisk summary\n Low risk to dependent code.\n\nAt-risk behavior\n • Dependent code behavior\n\nPropagation\n core layer 2 dependents\n auth layer layer 1 dependents\n\nMost affected\n • Session in the container\n\nSupporting context\n Members: 1\n Importers: 1\n Direct dependents:3\n Member-level callers:1",
+ "all": "── [1] function verify in src/auth.ts ──\nResolved: function verify\n\n System path: App > Auth Layer\n\nRisk summary\n Medium risk — widely shared dependency affecting the auth layer layer.\n\nAt-risk behavior\n • Multiple callers across different subsystems\n • Downstream operations coordinated by this component\n • Cross-module behavior consistency\n\nPropagation\n auth layer layer 4 dependents\n core layer 1 dependents\n\nMost affected\n • callers across multiple subsystems\n • Callers: login, handle and 3 more\n\nSupporting context\n Direct callers: 5\n Direct callees: 1\n\nCalls\n function decode_jwt\n\nDecisions\n Use JWT\n\n── [2] class Session in src/session.ts ──\nResolved: class Session\n\n\nRisk summary\n Low risk to dependent code.\n\nAt-risk behavior\n • Dependent code behavior\n\nPropagation\n core layer 2 dependents\n auth layer layer 1 dependents\n\nMost affected\n • Session in the container\n\nSupporting context\n Members: 1\n Importers: 1\n Direct dependents:3\n Member-level callers:1"
+ },
+ "exitCode": {
+ "leaf": {
+ "json": null,
+ "llm": null,
+ "text": null
+ },
+ "file": {
+ "json": null,
+ "llm": null,
+ "text": null
+ },
+ "class": {
+ "json": null,
+ "llm": null,
+ "text": null
+ },
+ "all": {
+ "json": null,
+ "llm": null,
+ "text": null
+ }
+ },
+ "requests": {
+ "leaf": {
+ "expand": 11,
+ "entity": 1
+ },
+ "file": {
+ "expand": 12,
+ "entity": 0
+ },
+ "class": {
+ "expand": 11,
+ "entity": 0
+ },
+ "all": {
+ "expand": 22,
+ "entity": 1
+ }
+ }
+} as const;
diff --git a/ix-cli/src/cli/__tests__/impact-json-locations.test.ts b/ix-cli/src/cli/__tests__/impact-json-locations.test.ts
new file mode 100644
index 00000000..08e428d9
--- /dev/null
+++ b/ix-cli/src/cli/__tests__/impact-json-locations.test.ts
@@ -0,0 +1,303 @@
+// Copyright 2026 Ix Infrastructure Inc.
+
+import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
+import { Command } from "commander";
+import chalk from "chalk";
+
+import { registerImpactCommand, impactRowJson } from "../commands/impact.js";
+import { BASELINE } from "./impact-json-locations.baseline.js";
+
+/**
+ * `ix impact --format json` says where each caller, callee, bucket member and
+ * container dependent is, from the nodes the command already holds. Additive
+ * only: the same JSON with the new keys taken out is what the command printed
+ * before, and llm and text output do not change at all (`BASELINE` was
+ * captured from the command before the location fields were added).
+ */
+
+const { expand, entity, state } = vi.hoisted(() => ({
+ expand: vi.fn(),
+ entity: vi.fn(),
+ state: { set: undefined as unknown },
+}));
+
+vi.mock("../../client/factory.js", () => ({
+ createClient: () => ({
+ expand: (...args: unknown[]) => expand(...args),
+ entity: (...args: unknown[]) => entity(...args),
+ }),
+}));
+vi.mock("../resolve.js", async (importOriginal) => ({
+ ...await importOriginal<typeof import("../resolve.js")>(),
+ resolveTargetSetOrReport: async () => state.set,
+ printResolved: () => {},
+}));
+vi.mock("../graph-health.js", async (importOriginal) => ({
+ ...await importOriginal<typeof import("../graph-health.js")>(),
+ checkGraphHealth: async () => ({ status: "healthy" }),
+}));
+
+// ── Graph ────────────────────────────────────────────────────────────────────
+
+const LEAF = { id: "t-verify", kind: "function", name: "verify", resolutionMode: "exact", path: "src/auth.ts" };
+const FILE = { id: "t-file", kind: "file", name: "auth.ts", resolutionMode: "exact", path: "src/auth.ts" };
+const CLASS = { id: "t-class", kind: "class", name: "Session", resolutionMode: "exact", path: "src/session.ts" };
+
+// Location shapes: provenance + span, attrs.path only, a file (path only), none.
+const login = { id: "a", kind: "method", name: "login", provenance: { source_uri: "src/auth/login.ts" }, attrs: { line_start: 10, line_end: 42 } };
+const handle = { id: "b", kind: "function", name: "handle", attrs: { path: "src/http/handle.ts" } };
+const mainFile = { id: "c", kind: "file", name: "main.ts", attrs: { path: "src/main.ts", line_start: 1, line_end: 200 } };
+const orphan = { id: "d", kind: "function", name: "orphan" };
+// No kind: bucketByHierarchy reads the entity for it.
+const lazy = { id: "e", name: "lazy" };
+const lazyEntity = { id: "e", kind: "function", name: "lazy", attrs: { path: "src/lazy.ts", line_start: 5, line_end: 6 } };
+const decode = { id: "f", kind: "function", name: "decode_jwt", provenance: { source_uri: "src/jwt.ts" }, attrs: { line_start: 3, line_end: 9 } };
+
+const appFile = { id: "x", kind: "file", name: "app.ts", attrs: { path: "src/app.ts" } };
+const boot = { id: "y", kind: "function", name: "boot", provenance: { source_uri: "src/boot.ts" }, attrs: { line_start: 3, line_end: 30 } };
+const httpHandle = { id: "z", kind: "method", name: "handle", attrs: { path: "src/http.ts", line_start: 7, line_end: 7 } };
+const nowhere = { id: "w", kind: "function", name: "nowhere" };
+const memberVerify = { id: "m1", kind: "function", name: "verify", attrs: { path: "src/auth.ts", line_start: 1, line_end: 20 } };
+const memberSession = { id: "m2", kind: "class", name: "Session", attrs: { path: "src/auth.ts", line_start: 22, line_end: 80 } };
+
+const AUTH = { id: "r1", kind: "subsystem", name: "Auth Layer" };
+const CORE = { id: "r2", kind: "module", name: "Core" };
+
+const GRAPH: Record<string, unknown[]> = {
+ // leaf
+ "t-verify in CALLS,REFERENCES": [login, handle, mainFile, orphan, lazy],
+ "t-verify out CALLS,REFERENCES": [decode],
+ "t-verify in IN_REGION": [{ id: "sys", kind: "system", name: "App" }, AUTH],
+ "t-verify in DECISION_AFFECTS": [{ id: "dec1", name: "Use JWT" }],
+ // file container
+ "t-file out CONTAINS": [memberVerify, memberSession],
+ "t-file in IMPORTS": [appFile, boot],
+ "t-file in CALLS,REFERENCES": [boot, httpHandle],
+ "t-file in TASK_AFFECTS": [{ id: "task1", name: "Rotate keys", attrs: { status: "open" } }],
+ "m1 in CALLS,REFERENCES": [boot, httpHandle],
+ "m2 in CALLS,REFERENCES": [httpHandle],
+ // class container
+ "t-class out CONTAINS": [memberSession],
+ "t-class in IMPORTS": [boot],
+ "t-class in CALLS,REFERENCES": [boot, httpHandle, nowhere],
+ // regions of the dependents
+ "a in IN_REGION": [AUTH],
+ "b in IN_REGION": [AUTH],
+ "c in IN_REGION": [AUTH],
+ "d in IN_REGION": [CORE],
+ "e in IN_REGION": [AUTH],
+ "x in IN_REGION": [AUTH],
+ "y in IN_REGION": [AUTH],
+ "z in IN_REGION": [CORE],
+ "w in IN_REGION": [CORE],
+};
+
+function graphExpand(id: string, opts: { direction: string; predicates: string[] }) {
+ return { nodes: GRAPH[`${id} ${opts.direction} ${opts.predicates.join(",")}`] ?? [], edges: [] };
+}
+
+type Scenario = "leaf" | "file" | "class" | "all";
+const SETS: Record<Scenario, unknown> = {
+ leaf: { entities: [LEAF] },
+ file: { entities: [FILE] },
+ class: { entities: [CLASS] },
+ all: { entities: [{ ...LEAF, n: 1 }, { ...CLASS, n: 2 }], all: { total: 2 } },
+};
+
+async function run(scenario: Scenario, args: string[]): Promise<{ out: string; exitCode: number | null }> {
+ state.set = SETS[scenario];
+ const program = new Command().name("ix").exitOverride();
+ registerImpactCommand(program);
+ const lines: string[] = [];
+ vi.spyOn(console, "log").mockImplementation((...parts) => { lines.push(parts.join(" ")); });
+ vi.spyOn(process.stderr, "write").mockImplementation(() => true);
+ const before = process.exitCode;
+ process.exitCode = undefined;
+ try {
+ await program.parseAsync(["impact", "target", ...args], { from: "user" });
+ return { out: lines.join("\n"), exitCode: (process.exitCode as number | undefined) ?? null };
+ } finally {
+ process.exitCode = before;
+ }
+}
+
+async function json(scenario: Scenario, args: string[] = []): Promise<any> {
+ return JSON.parse((await run(scenario, ["--format", "json", ...args])).out);
+}
+
+/** The JSON with every key this change added taken out again. */
+function withoutNewKeys(value: any): any {
+ const strip = (row: any) => {
+ const { path: _p, lineStart: _s, lineEnd: _e, ...rest } = row;
+ return rest;
+ };
+ const one = (o: any) => {
+ const { dependentList: _d, ...rest } = o;
+ if (rest.callerList) rest.callerList = rest.callerList.map(strip);
+ if (rest.calleeList) rest.calleeList = rest.calleeList.map(strip);
+ if (rest.propagationBuckets) {
+ rest.propagationBuckets = rest.propagationBuckets.map((b: any) => ({ ...b, members: b.members.map(strip) }));
+ }
+ return rest;
+ };
+ return value.results ? { ...value, results: value.results.map(one) } : one(value);
+}
+
+beforeAll(() => { chalk.level = 0; });
+beforeEach(() => {
+ expand.mockReset();
+ entity.mockReset();
+ expand.mockImplementation(async (id: string, opts: { direction: string; predicates: string[] }) => graphExpand(id, opts));
+ entity.mockImplementation(async (id: string) => ({ node: id === "e" ? lazyEntity : { id }, claims: [], edges: [] }));
+});
+afterEach(() => vi.restoreAllMocks());
+
+// ── Leaf ─────────────────────────────────────────────────────────────────────
+
+describe("impactRowJson", () => {
+ it("keeps kind and name first and adds only the location the node has", () => {
+ expect(Object.keys(impactRowJson(login))).toEqual(["kind", "name", "path", "lineStart", "lineEnd"]);
+ expect(impactRowJson(login)).toEqual({ kind: "method", name: "login", path: "src/auth/login.ts", lineStart: 10, lineEnd: 42 });
+ expect(impactRowJson(handle)).toEqual({ kind: "function", name: "handle", path: "src/http/handle.ts" });
+ expect(impactRowJson(mainFile)).toEqual({ kind: "file", name: "main.ts", path: "src/main.ts" });
+ expect(impactRowJson(orphan)).toEqual({ kind: "function", name: "orphan" });
+ expect(Object.keys(impactRowJson(orphan))).toEqual(["kind", "name"]);
+ });
+});
+
+describe("ix impact <leaf> --format json", () => {
+ it("locates every caller and callee, never with a null", async () => {
+ const out = await json("leaf");
+ expect(out.callerList).toEqual([
+ { kind: "method", name: "login", path: "src/auth/login.ts", lineStart: 10, lineEnd: 42 },
+ { kind: "function", name: "handle", path: "src/http/handle.ts" },
+ { kind: "file", name: "main.ts", path: "src/main.ts" },
+ { kind: "function", name: "orphan" },
+ { name: "lazy" },
+ ]);
+ expect(out.calleeList).toEqual([
+ { kind: "function", name: "decode_jwt", path: "src/jwt.ts", lineStart: 3, lineEnd: 9 },
+ ]);
+ for (const row of [...out.callerList, ...out.calleeList]) {
+ expect(Object.keys(row).slice(0, row.kind === undefined ? 1 : 2)).toEqual(row.kind === undefined ? ["name"] : ["kind", "name"]);
+ expect(Object.values(row)).not.toContain(null);
+ }
+ });
+
+ it("locates bucket members, name and kind first", async () => {
+ const out = await json("leaf");
+ expect(out.propagationBuckets).toEqual([
+ { region: "Auth Layer", regionKind: "subsystem", count: 4, members: [
+ { name: "login", kind: "method", path: "src/auth/login.ts", lineStart: 10, lineEnd: 42 },
+ { name: "handle", kind: "function", path: "src/http/handle.ts" },
+ { name: "main.ts", kind: "file", path: "src/main.ts" },
+ // Read from the entity, the one request bucketing already made for it.
+ { name: "lazy", kind: "function", path: "src/lazy.ts", lineStart: 5, lineEnd: 6 },
+ ] },
+ { region: "Core", regionKind: "module", count: 1, members: [{ name: "orphan", kind: "function" }] },
+ ]);
+ for (const m of out.propagationBuckets.flatMap((b: any) => b.members)) {
+ expect(Object.keys(m).slice(0, 2)).toEqual(["name", "kind"]);
+ }
+ });
+
+ it("makes no request it did not make before", async () => {
+ await json("leaf");
+ expect(expand.mock.calls.length).toBe(BASELINE.requests.leaf.expand);
+ expect(entity.mock.calls.length).toBe(BASELINE.requests.leaf.entity);
+ expect(entity.mock.calls.map((c) => c[0])).toEqual(["e"]);
+ });
+
+ it("has no dependentList", async () => {
+ expect(await json("leaf")).not.toHaveProperty("dependentList");
+ });
+});
+
+// ── Container ────────────────────────────────────────────────────────────────
+
+describe("ix impact <container> --format json", () => {
+ it("file target: dependentList is importers then dependents, deduped, the first expand winning `via`", async () => {
+ const out = await json("file");
+ expect(out.dependentList).toEqual([
+ { kind: "file", name: "app.ts", path: "src/app.ts", via: "importer" },
+ { kind: "function", name: "boot", path: "src/boot.ts", lineStart: 3, lineEnd: 30, via: "importer" },
+ { kind: "method", name: "handle", path: "src/http.ts", lineStart: 7, lineEnd: 7, via: "dependent" },
+ ]);
+ // Placed after propagationBuckets, before the decisions/tasks/bugs tail.
+ const keys = Object.keys(out);
+ expect(keys.indexOf("dependentList")).toBe(keys.indexOf("propagationBuckets") + 1);
+ expect(keys.indexOf("tasks")).toBe(keys.indexOf("dependentList") + 1);
+ });
+
+ it("class target: a node from both expands appears once, as an importer", async () => {
+ const out = await json("class");
+ expect(out.dependentList).toEqual([
+ { kind: "function", name: "boot", path: "src/boot.ts", lineStart: 3, lineEnd: 30, via: "importer" },
+ { kind: "method", name: "handle", path: "src/http.ts", lineStart: 7, lineEnd: 7, via: "dependent" },
+ { kind: "function", name: "nowhere", via: "dependent" },
+ ]);
+ expect(out.summary).toEqual({ members: 1, directImporters: 1, directDependents: 3, memberLevelCallers: 1 });
+ });
+
+ it("--limit does not cut dependentList", async () => {
+ const out = await json("class", ["--limit", "1"]);
+ expect(out.dependentList).toHaveLength(3);
+ });
+
+ it("locates container bucket members", async () => {
+ const out = await json("file");
+ expect(out.propagationBuckets).toEqual([
+ { region: "Auth Layer", regionKind: "subsystem", count: 2, members: [
+ { name: "app.ts", kind: "file", path: "src/app.ts" },
+ { name: "boot", kind: "function", path: "src/boot.ts", lineStart: 3, lineEnd: 30 },
+ ] },
+ { region: "Core", regionKind: "module", count: 1, members: [
+ { name: "handle", kind: "method", path: "src/http.ts", lineStart: 7, lineEnd: 7 },
+ ] },
+ ]);
+ });
+
+ it("omits dependentList when nothing depends on the target", async () => {
+ expand.mockImplementation(async (id: string, opts: { direction: string; predicates: string[] }) =>
+ opts.predicates.includes("IMPORTS") || (id === "t-file" && opts.predicates.includes("CALLS"))
+ ? { nodes: [], edges: [] }
+ : graphExpand(id, opts));
+ const out = await json("file");
+ expect(out).not.toHaveProperty("dependentList");
+ expect(out).not.toHaveProperty("propagationBuckets");
+ });
+
+ it("makes no request it did not make before", async () => {
+ await json("file");
+ expect(expand.mock.calls.length).toBe(BASELINE.requests.file.expand);
+ expect(entity.mock.calls.length).toBe(BASELINE.requests.file.entity);
+ });
+});
+
+// ── Additive only ────────────────────────────────────────────────────────────
+
+describe("additive only", () => {
+ for (const scenario of ["leaf", "file", "class", "all"] as const) {
+ it(`${scenario}: json without the new keys is the old json, key order included`, async () => {
+ const { out, exitCode } = await run(scenario, ["--format", "json"]);
+ const now = withoutNewKeys(JSON.parse(out));
+ expect(now).toEqual(BASELINE.json[scenario]);
+ expect(JSON.stringify(now)).toBe(JSON.stringify(BASELINE.json[scenario]));
+ expect(exitCode).toBe(BASELINE.exitCode[scenario].json);
+ });
+
+ for (const format of ["llm", "text"] as const) {
+ it(`${scenario}: ${format} output is byte-identical`, async () => {
+ const { out, exitCode } = await run(scenario, ["--format", format]);
+ expect(out).toBe(BASELINE[format][scenario]);
+ expect(exitCode).toBe(BASELINE.exitCode[scenario][format]);
+ });
+ }
+ }
+
+ it("--all: every candidate's analysis carries the new fields", async () => {
+ const out = await json("all");
+ expect(out.results[0].callerList[0]).toEqual({ kind: "method", name: "login", path: "src/auth/login.ts", lineStart: 10, lineEnd: 42 });
+ expect(out.results[1].dependentList[0]).toEqual({ kind: "function", name: "boot", path: "src/boot.ts", lineStart: 3, lineEnd: 30, via: "importer" });
+ });
+});
diff --git a/ix-cli/src/cli/commands/impact.ts b/ix-cli/src/cli/commands/impact.ts
index f0495136..cc9f2c5f 100644
--- a/ix-cli/src/cli/commands/impact.ts
+++ b/ix-cli/src/cli/commands/impact.ts
@@ -8,7 +8,7 @@ import { createClient } from "../../client/factory.js";
import { activeReadScope, candidatesCut, resolveTargetSetOrReport, printResolved, type ResolvedEntity, type TargetSet } from "../resolve.js";
import { EXIT_CODES_HELP } from "../outcome.js";
import { checkGraphHealth, graphHealthJson, graphHealthLlmFields, graphHealthProse, isUnhealthy } from "../graph-health.js";
-import { bucketByHierarchy, getSystemPath, formatSystemPath, hasMapData, type SystemPath } from "../hierarchy.js";
+import { bucketByHierarchy, getSystemPath, formatSystemPath, hasMapData, type BucketMember, type SystemPath } from "../hierarchy.js";
import { inferRiskSemantics, humanizeLabel, type ImpactFacts, type RiskSemantics } from "../impact/risk-semantics.js";
import { captureJson, lineSpan, printJson, relativePath, rowLocation, sliceEdgeResults, stripNulls, type Slice } from "../format.js";
import { forMcp, suggest, type Relation } from "../next-step.js";
@@ -426,10 +426,16 @@ async function containerImpact(
// Bucket all dependents by hierarchy. First occurrence of each id wins, as
// the id list this replaced did; the nodes go in whole so their names and
- // kinds need no second read.
+ // kinds need no second read. `via` remembers which expand that first
+ // occurrence came from, for the JSON `dependentList`.
const uniqueDependents = new Map<string, any>();
- for (const n of [...directImporters, ...directDependents]) {
- if (!uniqueDependents.has(n.id)) uniqueDependents.set(n.id, n);
+ const dependentVia = new Map<string, "importer" | "dependent">();
+ for (const [nodes, via] of [[directImporters, "importer"], [directDependents, "dependent"]] as const) {
+ for (const n of nodes) {
+ if (uniqueDependents.has(n.id)) continue;
+ uniqueDependents.set(n.id, n);
+ dependentVia.set(n.id, via);
+ }
}
// Independent of the member counts, so the two run together.
const [callerResults, propagationBuckets] = await Promise.all([
@@ -492,8 +498,13 @@ async function containerImpact(
region: b.region.name,
regionKind: b.region.kind,
count: b.members.length,
- members: b.members.slice(0, 5).map((m) => ({ name: m.name, kind: m.kind })),
+ members: b.members.slice(0, 5).map(bucketMemberJson),
})) : undefined,
+ // Every direct importer and dependent, located. Not cut by --limit:
+ // JSON keeps every row, as callerList does.
+ dependentList: uniqueDependents.size > 0
+ ? [...uniqueDependents.values()].map((n: any) => ({ ...impactRowJson(n), via: dependentVia.get(n.id) }))
+ : undefined,
decisions: decisions.length > 0 ? decisions : undefined,
tasks: tasks.length > 0 ? tasks : undefined,
bugs: bugs.length > 0 ? bugs : undefined,
@@ -551,6 +562,31 @@ async function containerImpact(
}
}
+// ── JSON rows ────────────────────────────────────────────────────────────────
+
+/** The location fields a JSON row adds, each left out when unknown (never null). */
+function locationJson(loc: { path?: string; lineStart?: number; lineEnd?: number }): { path?: string; lineStart?: number; lineEnd?: number } {
+ return stripNulls({ path: loc.path, lineStart: loc.lineStart, lineEnd: loc.lineEnd });
+}
+
+/**
+ * One caller, callee or dependent row in `--format json`: `kind` and `name`
+ * first, as they always were, then where the node is (`rowLocation`), the same
+ * fields `topImpactedMembers` carries.
+ */
+export function impactRowJson(node: any): { kind: string; name: string; path?: string; lineStart?: number; lineEnd?: number } {
+ return {
+ kind: node.kind,
+ name: node.name || node.attrs?.name || "(unnamed)",
+ ...locationJson(rowLocation(node)),
+ };
+}
+
+/** A propagation bucket member in `--format json`: `name`, `kind`, then its location. */
+function bucketMemberJson(m: BucketMember): BucketMember {
+ return { name: m.name, kind: m.kind, ...locationJson(m) };
+}
+
// ── Leaf impact ──────────────────────────────────────────────────────────────
/** One caller or callee row, located the way member rows are: `path` and `lines`. */
@@ -665,19 +701,13 @@ async function leafImpact(
callers: callersResult.nodes.length,
callees: calleesResult.nodes.length,
},
- callerList: callersResult.nodes.length > 0 ? callersResult.nodes.map((n: any) => ({
- kind: n.kind,
- name: n.name || n.attrs?.name || "(unnamed)",
- })) : undefined,
- calleeList: calleesResult.nodes.length > 0 ? calleesResult.nodes.map((n: any) => ({
- kind: n.kind,
- name: n.name || n.attrs?.name || "(unnamed)",
- })) : undefined,
+ callerList: callersResult.nodes.length > 0 ? callersResult.nodes.map(impactRowJson) : undefined,
+ calleeList: calleesResult.nodes.length > 0 ? calleesResult.nodes.map(impactRowJson) : undefined,
propagationBuckets: propagationBuckets.length > 0 ? propagationBuckets.map((b) => ({
region: b.region.name,
regionKind: b.region.kind,
count: b.members.length,
- members: b.members.slice(0, 5).map((m) => ({ name: m.name, kind: m.kind })),
+ members: b.members.slice(0, 5).map(bucketMemberJson),
})) : undefined,
decisions: decisions.length > 0 ? decisions : undefined,
tasks: tasks.length > 0 ? tasks : undefined,
diff --git a/ix-cli/src/cli/hierarchy.ts b/ix-cli/src/cli/hierarchy.ts
index f778a173..70ef09ed 100644
--- a/ix-cli/src/cli/hierarchy.ts
+++ b/ix-cli/src/cli/hierarchy.ts
@@ -1,6 +1,7 @@
// Copyright 2026 Ix Infrastructure Inc.
import type { IxClient } from "../client/api.js";
+import { rowLocation, stripNulls } from "./format.js";
export type SystemPath = Array<{ name: string; kind: string; id?: string }>;
@@ -99,6 +100,9 @@ export async function getEffectiveSystemPath(
/** A node to bucket: its id, or the node itself when the caller already holds it. */
export type BucketInput = string | { id: string; name?: string; kind?: string; attrs?: { name?: string } };
+/** A bucketed node: its name and kind, and where it is when the node says. */
+export type BucketMember = { name: string; kind: string; path?: string; lineStart?: number; lineEnd?: number };
+
/**
* Group a set of nodes by their containing region (IN_REGION).
*
@@ -110,11 +114,14 @@ export type BucketInput = string | { id: string; name?: string; kind?: string; a
* Buckets, and the members in each, are in input order. They used to be in
* the order the lookups finished, so the same graph printed differently from
* one run to the next.
+ *
+ * Each member carries the node's location (`rowLocation`), read off the node
+ * already in hand: no request is made for it.
*/
export async function bucketByHierarchy(
client: IxClient,
nodes: BucketInput[],
-): Promise<Array<{ region: { name: string; kind: string }; members: Array<{ name: string; kind: string }> }>> {
+): Promise<Array<{ region: { name: string; kind: string }; members: BucketMember[] }>> {
if (nodes.length === 0) return [];
// For each node, find its immediate region
@@ -138,7 +145,7 @@ export async function bucketByHierarchy(
return {
key: region.id,
region: { name: (region as any).name || region.attrs?.name || "(unnamed)", kind: (region as any).kind || "region" },
- member: { name: memberName, kind: memberKind },
+ member: { name: memberName, kind: memberKind, ...stripNulls(rowLocation(node)) } as BucketMember,
};
} catch {
return undefined; /* skip nodes that can't be expanded */
@@ -146,7 +153,7 @@ export async function bucketByHierarchy(
}),
);
- const buckets = new Map<string, { region: { name: string; kind: string }; members: Array<{ name: string; kind: string }> }>();
+ const buckets = new Map<string, { region: { name: string; kind: string }; members: BucketMember[] }>();
for (const p of placed) {
if (!p) continue;
if (!buckets.has(p.key)) buckets.set(p.key, { region: p.region, members: [] });
diff --git a/skills/ix/references/flags.md b/skills/ix/references/flags.md
index dcfc16cb..f7430036 100644
--- a/skills/ix/references/flags.md
+++ b/skills/ix/references/flags.md
@@ -473,7 +473,7 @@ System risk analysis — what behavior is at risk if this changes.
| `--pick` | `<n>` | — | Pick Nth candidate from ambiguous results (1-based) |
| `--all` | — | off | When the target is ambiguous, analyse every candidate; each analysis is tagged with its candidate |
| `--depth` | `<n>` | `1` | Expansion depth for callers/importers (default 1, max 3) |
-| `--limit` | `<n>` | `10` | Max top-impacted members to show |
+| `--limit` | `<n>` | `10` | Max top-impacted members (and llm caller/callee rows) to show; JSON lists are not cut |
| `--format` | `text\|json\|llm` | `text` | Output format — see [output-formats.md](output-formats.md) |
| `--pretty` | — | off | Indent JSON output; the default only when stdout is a terminal |
| `--quiet` | — | off | Drop headers, section titles and advisory hints |
diff --git a/skills/ix/references/output-formats.md b/skills/ix/references/output-formats.md
index f0230e1c..3f22ad00 100644
--- a/skills/ix/references/output-formats.md
+++ b/skills/ix/references/output-formats.md
@@ -57,6 +57,37 @@ command substitution, an agent's tool result — and indents only when you are
reading it on screen. Indentation is whitespace a parser throws away, and it is
about a fifth of the payload. `--pretty` forces the indented shape anywhere.
+### `ix impact` JSON
+
+One object per target (under `--all`, one per candidate in `results`). Top-level
+keys, each omitted when empty: `resolvedTarget`, `graph` (only on a degraded
+graph), `depth`, `systemPath`, `riskSummary`, `riskLevel`, `riskCategory`,
+`atRiskBehavior`, `nextStep`, `flowPropagation`, `summary`, then
+
+- leaf targets (functions, methods, ...): `callerList`, `calleeList`,
+ `propagationBuckets`;
+- container targets (`class`, `module`, `file`, `object`, `trait`,
+ `interface`): `topImpactedMembers`, `propagationBuckets`, `dependentList`;
+
+then `decisions`, `tasks`, `bugs` (and `diagnostics` on containers).
+
+Rows say where their entity is: `callerList[]`, `calleeList[]`,
+`propagationBuckets[].members[]`, `topImpactedMembers[]` and `dependentList[]`
+carry `path` (workspace-relative), `lineStart` and `lineEnd` next to `kind`
+and `name`. A `file` row has `path` only; a field the graph does not know is
+left out, never `null`. The span is the entity's own, not the line of the call.
+
+`dependentList` is every direct importer and dependent of a container, each
+once, importers first: `{ kind, name, path?, lineStart?, lineEnd?, via }`, with
+`via: "importer"` for a node reached over `IMPORTS` and `via: "dependent"` for
+one reached over `CALLS`/`REFERENCES` (a node reached both ways is an
+`importer`). `summary.directImporters` and `summary.directDependents` count the
+two expands before that dedup.
+
+`--limit` cuts `topImpactedMembers` and the `llm` caller/callee rows only.
+`callerList`, `calleeList` and `dependentList` are never cut;
+`propagationBuckets[].members` lists the first five of each bucket's `count`.
+
### Commands that accept `--format` but route `llm` to `text`
The deprecated `query` takes `text|json` only. `diff --content` (verbatim hunks)