Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
feat(ui): change impact — who can reach this symbol, and what to retest
Martin Vogel617a4b1495bb
diff --git a/graph-ui/src/components/SymbolTab.tsx b/graph-ui/src/components/SymbolTab.tsxindex 45bde11f9..a66187d1d 100644--- a/graph-ui/src/components/SymbolTab.tsx+++ b/graph-ui/src/components/SymbolTab.tsx@@ -12,6 +12,7 @@ import {type SymbolBundle,type SymbolRef,} from "../lib/atlas";+import { fetchImpact, impactSentence, type ImpactPayload } from "../lib/impact";import { AddToPromptButton } from "./PromptBasket";import { MetricChip } from "./MetricChip";import { TriggerTree } from "./TriggerTree";@@ -152,6 +153,8 @@ export function SymbolTab({const [code, setCode] = useState<string | null>(null);const [codeLoading, setCodeLoading] = useState(false);const [repoInfo, setRepoInfo] = useState<RepoInfo | null>(null);+ const [impact, setImpact] = useState<ImpactPayload | null>(null);+ const [impactError, setImpactError] = useState<string | null>(null);useEffect(() => {let cancelled = false;@@ -183,6 +186,22 @@ export function SymbolTab({};}, [project]);+ useEffect(() => {+ let cancelled = false;+ setImpact(null);+ setImpactError(null);+ fetchImpact(project, symbolRef)+ .then((payload) => {+ if (!cancelled) setImpact(payload);+ })+ .catch((err) => {+ if (!cancelled) setImpactError(err instanceof Error ? err.message : "failed");+ });+ return () => {+ cancelled = true;+ };+ }, [project, symbolRef.id, symbolRef.qn]);+if (error) {return (<div className="flex items-center justify-center h-full">@@ -211,6 +230,26 @@ export function SymbolTab({? `vscode://file/${repoInfo.root_path}/${node.file_path}${node.start_line ? `:${node.start_line}` : ""}`: null;+ /* The cumulative hop tiers: "12 direct callers · 48 within 2 hops ·+ * 210 total within 10" — only the tiers this symbol actually has. */+ const impactDirect = impact?.by_distance[0] ?? 0;+ const impactTiers =+ impact && impact.reachable > 0+ ? [+ `${impactDirect.toLocaleString("en-US")} direct caller${impactDirect === 1 ? "" : "s"}`,+ ...(impact.max_distance >= 2+ ? [+ `${(impactDirect + (impact.by_distance[1] ?? 0)).toLocaleString("en-US")} within 2 hops`,+ ]+ : []),+ ...(impact.max_distance > 2+ ? [+ `${impact.reachable.toLocaleString("en-US")} total within ${impact.max_depth}`,+ ]+ : []),+ ].join(" · ")+ : null;+const loadCode = async () => {if (!node.qualified_name) return;setCodeLoading(true);@@ -355,6 +394,94 @@ export function SymbolTab({/></div>+ {/* If you change this — reverse reachability: the hypothetical blast+ * radius of an edit here, and the tests to run first. Non-callables+ * (File nodes, …) have no radius; the section stays hidden. */}+ {impactError && impactError !== "symbol is not an indexed callable" && (+ <p className="text-[13px] text-foreground/40 mb-4">+ Impact unavailable: {impactError}+ </p>+ )}+ {impact && (+ <div className="bg-card border border-border/40 rounded-md p-4 mb-4">+ <div className="flex items-baseline gap-2 mb-2">+ <p className="text-[12px] uppercase tracking-widest text-foreground/45">+ If you change this+ </p>+ <span className="text-[12px] text-foreground/40">+ <MetricChip slug="blast-radius" onOpen={onOpenWiki} />+ </span>+ </div>+ <p className="text-[14px] text-foreground/85">{impactSentence(impact)}</p>+ {impactTiers && (+ <p className="text-[12px] text-foreground/40 mt-1">{impactTiers}</p>+ )}+ {impact.regions.length > 0 && (+ <div className="flex flex-wrap items-baseline gap-1.5 mt-2">+ {impact.regions.map((region) => (+ <span+ key={region.name}+ className="px-2 py-0.5 rounded-md text-[12px] bg-surface-3 text-foreground/60"+ >+ {region.name} ({region.count.toLocaleString("en-US")})+ </span>+ ))}+ {impact.regions_more > 0 && (+ <span className="text-[12px] text-foreground/40">+ +{impact.regions_more.toLocaleString("en-US")} more+ </span>+ )}+ {impact.unregioned > 0 && (+ <span className="text-[12px] text-foreground/40">+ +{impact.unregioned.toLocaleString("en-US")} unmapped+ </span>+ )}+ </div>+ )}+ {impact.tests.count > 0 ? (+ <div className="mt-3">+ <p className="text-[12px] uppercase tracking-widest text-foreground/45 mb-1">+ Run these first+ </p>+ <div className="space-y-px">+ {impact.tests.nearest.map((test) => (+ <button+ key={test.id}+ onClick={() => onOpenSymbol({ id: test.id })}+ className="flex items-center gap-2 w-full text-left px-2 py-[3px] rounded-md hover:bg-surface-3 transition-colors group"+ >+ <span className="text-[13px] font-mono text-foreground/65 group-hover:text-primary truncate transition-colors">+ {test.name}+ </span>+ <span className="text-[12px] text-foreground/35 truncate">+ {test.file_path}+ </span>+ <span className="text-[12px] tabular-nums text-foreground/40 ml-auto shrink-0">+ d {test.distance}+ </span>+ </button>+ ))}+ </div>+ <p className="text-[12px] text-foreground/40 mt-1">+ {impact.tests.count.toLocaleString("en-US")} test+ {impact.tests.count === 1 ? " reaches" : "s reach"} this symbol+ {impact.tests.nearest.length < impact.tests.count &&+ ` — showing ${impact.tests.nearest.length} of ${impact.tests.count.toLocaleString("en-US")}`}+ </p>+ </div>+ ) : (+ <p className="text-[13px] text-amber-300/80 mt-3">+ ⚠ No test reaches this symbol — nothing will catch a regression+ here automatically.+ </p>+ )}+ <p className="text-[12px] text-foreground/35 mt-3">+ Static CALLS edges only — dynamic dispatch and reflection are not+ counted; treat the count as a floor.+ </p>+ </div>+ )}+{/* Why & who — the rationale proxy and the knowledge map. */}<div className="grid grid-cols-1 lg:grid-cols-2 gap-4 mb-4"><div className="bg-card border border-border/50 rounded-md p-4">diff --git a/graph-ui/src/lib/impact.test.ts b/graph-ui/src/lib/impact.test.tsnew file mode 100644index 000000000..1ad0f4f60--- /dev/null+++ b/graph-ui/src/lib/impact.test.ts@@ -0,0 +1,50 @@+import { describe, expect, it } from "vitest";+import { impactSentence, type ImpactPayload } from "./impact";++const payload = (overrides: Partial<ImpactPayload> = {}): ImpactPayload => ({+ basis: "CALLS",+ max_depth: 10,+ visit_cap: 50000,+ callable_total: 4200,+ node: { id: 1, name: "f" },+ reachable: 210,+ max_distance: 4,+ truncated: false,+ depth_capped: false,+ by_distance: [12, 36, 100, 62],+ regions: [{ name: "core", count: 120 }],+ regions_more: 2,+ unregioned: 3,+ nearest: [],+ tests: { count: 0, nearest: [] },+ ...overrides,+});++describe("impactSentence", () => {+ it("states reach, total and region count with locale formatting", () => {+ expect(impactSentence(payload())).toBe(+ "210 of 4,200 callables can reach this — 3 regions could notice.",+ );+ expect(impactSentence(payload({ regions_more: 0 }))).toBe(+ "210 of 4,200 callables can reach this — 1 region could notice.",+ );+ });++ it("marks a truncated or depth-capped walk as a floor", () => {+ const suffix = " (walk capped — the true count is higher)";+ expect(impactSentence(payload({ truncated: true }))).toBe(+ `210 of 4,200 callables can reach this — 3 regions could notice.${suffix}`,+ );+ expect(impactSentence(payload({ depth_capped: true }))).toContain(suffix);+ });++ it("says so honestly when nothing recorded calls the symbol", () => {+ expect(+ impactSentence(+ payload({ reachable: 0, max_distance: 0, by_distance: [], regions: [], regions_more: 0, unregioned: 0 }),+ ),+ ).toBe(+ "Nothing recorded calls this — changes here surface only where it is referenced dynamically.",+ );+ });+});diff --git a/graph-ui/src/lib/impact.ts b/graph-ui/src/lib/impact.tsnew file mode 100644index 000000000..cdbde6ab6--- /dev/null+++ b/graph-ui/src/lib/impact.ts@@ -0,0 +1,62 @@+/* Change-impact data layer: /api/impact reverse reachability — who could+ * notice a change to one symbol, at what distance, in which regions, and+ * which tests reach it. Counts are floors: static CALLS edges only, and+ * the walk is capped in depth and volume. */+import { fetchJsonFrom } from "./whyfetch";++export interface ImpactNode {+ id: number;+ name: string;+ file_path?: string;+}++export interface ImpactReacher extends ImpactNode {+ distance: number;+}++export interface ImpactPayload {+ basis: string;+ max_depth: number;+ visit_cap: number;+ callable_total: number;+ node: ImpactNode;+ reachable: number;+ max_distance: number;+ truncated: boolean;+ depth_capped: boolean;+ /* Reachers per distance; index 0 = distance 1 (direct callers). */+ by_distance: number[];+ /* Non-test reachers by region, sorted desc, capped. */+ regions: { name: string; count: number }[];+ regions_more: number;+ unregioned: number;+ /* Nearest non-test reachers in BFS order, capped. */+ nearest: ImpactReacher[];+ tests: { count: number; nearest: ImpactReacher[] };+}++export async function fetchImpact(+ project: string,+ ref: { id?: number; qn?: string },+): Promise<ImpactPayload> {+ const params = new URLSearchParams({ project });+ params.set("node", ref.id !== undefined ? `#${ref.id}` : (ref.qn ?? ""));+ const payload = await fetchJsonFrom<ImpactPayload & { error?: string }>(+ `/api/impact?${params}`,+ );+ if (payload.error) throw new Error(payload.error);+ return payload;+}++/* The headline sentence. Region count includes the rows the payload capped+ * away (regions_more); a capped walk says so — the count is then a floor+ * of a floor. */+export function impactSentence(payload: ImpactPayload): string {+ if (payload.reachable === 0)+ return "Nothing recorded calls this — changes here surface only where it is referenced dynamically.";+ const regionTotal = payload.regions.length + payload.regions_more;+ const sentence = `${payload.reachable.toLocaleString("en-US")} of ${payload.callable_total.toLocaleString("en-US")} callables can reach this — ${regionTotal.toLocaleString("en-US")} region${regionTotal === 1 ? "" : "s"} could notice.`;+ if (payload.truncated || payload.depth_capped)+ return `${sentence} (walk capped — the true count is higher)`;+ return sentence;+}diff --git a/graph-ui/src/lib/questions.ts b/graph-ui/src/lib/questions.tsindex c391435c9..002106e3e 100644--- a/graph-ui/src/lib/questions.ts+++ b/graph-ui/src/lib/questions.ts@@ -43,9 +43,9 @@ export const QUESTION_FAMILIES: QuestionFamily[] = [{id: "F3",question: "If I change this, what breaks — and what must I retest?",- status: "partial",+ status: "answers",tab: "changes",- gap: "Blast radius covers the uncommitted diff only; hypothetical per-symbol impact and tests-to-run are planned",+ hint: "Changes tab for the current diff; every symbol page answers it hypothetically under 'If you change this'",},{id: "F4",diff --git a/graph-ui/src/wiki/entries.ts b/graph-ui/src/wiki/entries.tsindex 71673d7e7..ce791fcf2 100644--- a/graph-ui/src/wiki/entries.ts+++ b/graph-ui/src/wiki/entries.ts@@ -273,8 +273,8 @@ export const WIKI_ENTRIES: WikiEntry[] = ["Everything that can reach the code you changed — what could notice, grouped by region.",why: "Most regressions ship because a change was tested where it was made, not where it is felt. The blast list is what to retest before pushing.",notCovered:- "Computed on the uncommitted diff today; hypothetical per-symbol impact and tests-to-run are planned. Confidence caveats apply along every path.",- appearsIn: ["Changes"],+ "Static CALLS edges only — dynamic dispatch, reflection and code generation are invisible here, so every count is a floor. The walk is capped in depth and volume; caps are always stated.",+ appearsIn: ["Changes", "Symbol — If you change this"],seeAlso: ["fan", "confidence"],},{diff --git a/graph-ui/tsconfig.tsbuildinfo b/graph-ui/tsconfig.tsbuildinfoindex 708e20d26..ddc6aeb64 100644--- a/graph-ui/tsconfig.tsbuildinfo+++ b/graph-ui/tsconfig.tsbuildinfo@@ -1 +1 @@-{"root":["./src/app.tsx","./src/main.tsx","./src/vite-env.d.ts","./src/api/rpc.ts","./src/components/changestab.tsx","./src/components/commandk.tsx","./src/components/controltab.tsx","./src/components/dashboardtab.tsx","./src/components/displaysettingsmenu.tsx","./src/components/edgelines.tsx","./src/components/errorboundary.tsx","./src/components/filterpanel.tsx","./src/components/flowstab.tsx","./src/components/graphloader.tsx","./src/components/graphscene.test.ts","./src/components/graphscene.tsx","./src/components/graphtab.deadcode.test.tsx","./src/components/graphtab.filters.test.tsx","./src/components/graphtab.regions.test.tsx","./src/components/graphtab.test.ts","./src/components/graphtab.tsx","./src/components/halolayer.tsx","./src/components/metricchip.tsx","./src/components/minimap.tsx","./src/components/missedcallout.tsx","./src/components/modulestab.tsx","./src/components/nodecloud.tsx","./src/components/nodedetailpanel.showmore.test.tsx","./src/components/nodedetailpanel.test.tsx","./src/components/nodedetailpanel.tsx","./src/components/nodelabels.tsx","./src/components/nodetooltip.tsx","./src/components/overviewtab.tsx","./src/components/projectcard.tsx","./src/components/projectswitcher.tsx","./src/components/promptbasket.tsx","./src/components/regionpanel.tsx","./src/components/regiontooltip.tsx","./src/components/resizehandle.tsx","./src/components/sidebar.tsx","./src/components/statstab.test.tsx","./src/components/statstab.tsx","./src/components/symboltab.tsx","./src/components/tabbar.tsx","./src/components/triggertree.tsx","./src/components/wikihovercard.test.tsx","./src/components/wikihovercard.tsx","./src/components/wikipanel.test.tsx","./src/components/wikipanel.tsx","./src/components/wikitier.ts","./src/components/ui/badge.tsx","./src/components/ui/button.tsx","./src/components/ui/card.tsx","./src/components/ui/checkbox.tsx","./src/components/ui/input.tsx","./src/components/ui/scroll-area.tsx","./src/components/ui/separator.tsx","./src/hooks/usegraphdata.test.ts","./src/hooks/usegraphdata.ts","./src/hooks/useprojects.ts","./src/lib/atlas.test.ts","./src/lib/atlas.ts","./src/lib/colors.ts","./src/lib/complexity.test.ts","./src/lib/complexity.ts","./src/lib/composer.ts","./src/lib/density.test.ts","./src/lib/density.ts","./src/lib/findings.test.ts","./src/lib/findings.ts","./src/lib/firstread.ts","./src/lib/flowgroup.test.ts","./src/lib/flowgroup.ts","./src/lib/i18n.test.ts","./src/lib/i18n.ts","./src/lib/questions.test.ts","./src/lib/questions.ts","./src/lib/regions.test.ts","./src/lib/regions.ts","./src/lib/treemap.ts","./src/lib/types.ts","./src/lib/utils.ts","./src/lib/why.test.ts","./src/lib/why.ts","./src/lib/whyfetch.ts","./src/test/setup.ts","./src/wiki/entries.test.ts","./src/wiki/entries.ts"],"version":"5.9.3"}\ No newline at end of file+{"root":["./src/app.tsx","./src/main.tsx","./src/vite-env.d.ts","./src/api/rpc.ts","./src/components/changestab.tsx","./src/components/commandk.tsx","./src/components/controltab.tsx","./src/components/dashboardtab.tsx","./src/components/displaysettingsmenu.tsx","./src/components/edgelines.tsx","./src/components/errorboundary.tsx","./src/components/filterpanel.tsx","./src/components/flowstab.tsx","./src/components/graphloader.tsx","./src/components/graphscene.test.ts","./src/components/graphscene.tsx","./src/components/graphtab.deadcode.test.tsx","./src/components/graphtab.filters.test.tsx","./src/components/graphtab.regions.test.tsx","./src/components/graphtab.test.ts","./src/components/graphtab.tsx","./src/components/halolayer.tsx","./src/components/metricchip.tsx","./src/components/minimap.tsx","./src/components/missedcallout.tsx","./src/components/modulestab.tsx","./src/components/nodecloud.tsx","./src/components/nodedetailpanel.showmore.test.tsx","./src/components/nodedetailpanel.test.tsx","./src/components/nodedetailpanel.tsx","./src/components/nodelabels.tsx","./src/components/nodetooltip.tsx","./src/components/overviewtab.tsx","./src/components/projectcard.tsx","./src/components/projectswitcher.tsx","./src/components/promptbasket.tsx","./src/components/regionpanel.tsx","./src/components/regiontooltip.tsx","./src/components/resizehandle.tsx","./src/components/sidebar.tsx","./src/components/statstab.test.tsx","./src/components/statstab.tsx","./src/components/symboltab.tsx","./src/components/tabbar.tsx","./src/components/triggertree.tsx","./src/components/wikihovercard.test.tsx","./src/components/wikihovercard.tsx","./src/components/wikipanel.test.tsx","./src/components/wikipanel.tsx","./src/components/wikitier.ts","./src/components/ui/badge.tsx","./src/components/ui/button.tsx","./src/components/ui/card.tsx","./src/components/ui/checkbox.tsx","./src/components/ui/input.tsx","./src/components/ui/scroll-area.tsx","./src/components/ui/separator.tsx","./src/hooks/usegraphdata.test.ts","./src/hooks/usegraphdata.ts","./src/hooks/useprojects.ts","./src/lib/atlas.test.ts","./src/lib/atlas.ts","./src/lib/colors.ts","./src/lib/complexity.test.ts","./src/lib/complexity.ts","./src/lib/composer.ts","./src/lib/density.test.ts","./src/lib/density.ts","./src/lib/findings.test.ts","./src/lib/findings.ts","./src/lib/firstread.ts","./src/lib/flowgroup.test.ts","./src/lib/flowgroup.ts","./src/lib/i18n.test.ts","./src/lib/i18n.ts","./src/lib/impact.test.ts","./src/lib/impact.ts","./src/lib/questions.test.ts","./src/lib/questions.ts","./src/lib/regions.test.ts","./src/lib/regions.ts","./src/lib/treemap.ts","./src/lib/types.ts","./src/lib/utils.ts","./src/lib/why.test.ts","./src/lib/why.ts","./src/lib/whyfetch.ts","./src/test/setup.ts","./src/wiki/entries.test.ts","./src/wiki/entries.ts"],"version":"5.9.3"}\ No newline at end of filediff --git a/src/ui/atlas.h b/src/ui/atlas.hindex 48787b894..8cde1b450 100644--- a/src/ui/atlas.h+++ b/src/ui/atlas.h@@ -72,6 +72,12 @@ char *cbm_atlas_scent_json(cbm_store_t *store, const char *project, const char *char *cbm_atlas_trace_json(cbm_store_t *store, const char *project, int64_t from_id,const char *from_qn, int64_t to_id, const char *to_qn, const char *mode);+/* Reverse reachability from one symbol: who could notice a change here,+ * at what call distance, in which regions — and which test functions+ * reach it (the tests to run first). id or qualified name. */+char *cbm_atlas_impact_json(cbm_store_t *store, const char *project, int64_t node_id,+ const char *node_qn);+/* ── Region lookups (layout_regions.c) ────────────────────────────* Cache-backed; computing on first use. name_out (optional) receives a* heap copy the caller frees. Returns region id or -1. */diff --git a/src/ui/atlas_flows.c b/src/ui/atlas_flows.cindex 6364065ca..7d4e88ae2 100644--- a/src/ui/atlas_flows.c+++ b/src/ui/atlas_flows.c@@ -67,6 +67,10 @@ typedef struct {flow_node_t *nodes;int node_count;int32_t *out_edges; /* callee node indices, grouped by caller (CALLS) */+ /* Reverse CALLS adjacency: caller indices grouped by callee — the+ * impact question ("who can reach this?") walks edges backwards. */+ int32_t *in_first; /* per node: index into in_edges (in_count on the node) */+ int32_t *in_edges;/* DATA_FLOWS adjacency (same node set, its own CSR). */int32_t *data_first; /* per node: index into data_edges, -1 none */int32_t *data_count;@@ -97,6 +101,8 @@ static void flow_cache_clear_locked(void) {}free(g_flow_cache.nodes);free(g_flow_cache.out_edges);+ free(g_flow_cache.in_first);+ free(g_flow_cache.in_edges);free(g_flow_cache.data_first);free(g_flow_cache.data_count);free(g_flow_cache.data_edges);@@ -467,6 +473,26 @@ static int fl_rebuild_locked(cbm_store_t *store, const char *project, const charout_edges[nodes[src[e]].first_out + cursor[src[e]]++] = dst[e];}free(cursor);++ /* Reverse CSR over the same edge list (in_count already tallied). */+ g_flow_cache.in_first = malloc((size_t)n * sizeof(int32_t));+ g_flow_cache.in_edges = malloc(ne > 0 ? (size_t)ne * sizeof(int32_t) : sizeof(int32_t));+ int32_t *rcursor = calloc((size_t)n, sizeof(int32_t));+ if (g_flow_cache.in_first && g_flow_cache.in_edges && rcursor) {+ int32_t offset = 0;+ for (int i = 0; i < n; i++) {+ g_flow_cache.in_first[i] = offset;+ offset += nodes[i].in_count;+ }+ for (int e = 0; e < ne; e++)+ g_flow_cache.in_edges[g_flow_cache.in_first[dst[e]] + rcursor[dst[e]]++] = src[e];+ } else {+ free(g_flow_cache.in_first);+ free(g_flow_cache.in_edges);+ g_flow_cache.in_first = NULL;+ g_flow_cache.in_edges = NULL;+ }+ free(rcursor);free(src);free(dst);if (!out_edges) {@@ -475,6 +501,10 @@ static int fl_rebuild_locked(cbm_store_t *store, const char *project, const charfree(nodes[i].file_path);}free(nodes);+ free(g_flow_cache.in_first);+ free(g_flow_cache.in_edges);+ g_flow_cache.in_first = NULL;+ g_flow_cache.in_edges = NULL;return -1;}@@ -835,3 +865,216 @@ char *cbm_atlas_trace_json(cbm_store_t *store, const char *project, int64_t fromyyjson_mut_doc_free(doc);return json;}++/* ── Impact: who can reach this symbol? ───────────────────────────+ *+ * The change-impact question ("if I change this, what breaks — and what+ * must I retest?") is a reverse-reachability walk over CALLS edges:+ * every symbol that can reach the target could notice a change to it.+ * Distance-labelled BFS, honest caps, regions aggregated for the map+ * view, and test-file reachers reported separately — those are the+ * tests to run first. Unresolved dynamic calls are not in the edge set,+ * so the count is a floor, never a ceiling; the UI says so. */++enum {+ IMPACT_MAX_DEPTH = 10,+ IMPACT_VISIT_CAP = 50000,+ IMPACT_NEAREST_CAP = 30,+ IMPACT_TESTS_CAP = 20,+ IMPACT_REGIONS_CAP = 64,+ IMPACT_REGIONS_SHOWN = 12,+};++typedef struct {+ char *name; /* owned */+ int count;+} impact_region_t;++static void impact_add_node(yyjson_mut_doc *doc, yyjson_mut_val *arr, const flow_node_t *node,+ int distance) {+ yyjson_mut_val *obj = yyjson_mut_obj(doc);+ yyjson_mut_obj_add_int(doc, obj, "id", node->id);+ yyjson_mut_obj_add_strcpy(doc, obj, "name", node->name ? node->name : "?");+ if (node->file_path)+ yyjson_mut_obj_add_strcpy(doc, obj, "file_path", node->file_path);+ yyjson_mut_obj_add_int(doc, obj, "distance", distance);+ yyjson_mut_arr_append(arr, obj);+}++char *cbm_atlas_impact_json(cbm_store_t *store, const char *project, int64_t node_id,+ const char *node_qn) {+ if (!store || !project)+ return NULL;+ pthread_mutex_lock(&g_flow_mu);+ if (fl_ensure_locked(store, project) != 0 || g_flow_cache.node_count == 0 ||+ !g_flow_cache.in_first || !g_flow_cache.in_edges) {+ pthread_mutex_unlock(&g_flow_mu);+ return NULL;+ }+ struct sqlite3 *db = cbm_store_get_db(store);+ int32_t origin = fl_resolve_endpoint(db, project, node_id, node_qn);++ yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);+ yyjson_mut_val *root = yyjson_mut_obj(doc);+ yyjson_mut_doc_set_root(doc, root);+ yyjson_mut_obj_add_str(doc, root, "basis", "CALLS");+ yyjson_mut_obj_add_int(doc, root, "max_depth", IMPACT_MAX_DEPTH);+ yyjson_mut_obj_add_int(doc, root, "visit_cap", IMPACT_VISIT_CAP);+ yyjson_mut_obj_add_int(doc, root, "callable_total", g_flow_cache.callable_total);+ if (origin < 0) {+ yyjson_mut_obj_add_str(doc, root, "error", "symbol is not an indexed callable");+ pthread_mutex_unlock(&g_flow_mu);+ char *json = yyjson_mut_write(doc, 0, NULL);+ yyjson_mut_doc_free(doc);+ return json;+ }++ const int n = g_flow_cache.node_count;+ const flow_node_t *nodes = g_flow_cache.nodes;+ yyjson_mut_val *node_obj = yyjson_mut_obj(doc);+ yyjson_mut_obj_add_int(doc, node_obj, "id", nodes[origin].id);+ yyjson_mut_obj_add_strcpy(doc, node_obj, "name",+ nodes[origin].name ? nodes[origin].name : "?");+ if (nodes[origin].file_path)+ yyjson_mut_obj_add_strcpy(doc, node_obj, "file_path", nodes[origin].file_path);+ yyjson_mut_obj_add_val(doc, root, "node", node_obj);++ uint8_t *dist = calloc((size_t)n, sizeof(uint8_t));+ uint8_t *seen = calloc((size_t)n, sizeof(uint8_t));+ int32_t *queue = malloc((size_t)n * sizeof(int32_t));+ yyjson_mut_val *nearest = yyjson_mut_arr(doc);+ yyjson_mut_val *tests_nearest = yyjson_mut_arr(doc);+ impact_region_t regions[IMPACT_REGIONS_CAP];+ int region_count = 0;+ long long by_distance[IMPACT_MAX_DEPTH] = {0};+ long long reachable = 0, test_count = 0, unregioned = 0;+ int nearest_emitted = 0, tests_emitted = 0, max_dist = 0;+ bool truncated = false, depth_capped = false;+ /* file → region-name cache: keys borrow the cache's file_path (stable+ * under g_flow_mu); values are region index + 2 (1 = no region). */+ CBMHashTable *file_region = cbm_ht_create(1024);++ if (dist && seen && queue && file_region) {+ int head = 0, tail = 0;+ queue[tail++] = origin;+ seen[origin] = 1;+ long long visited = 0;+ while (head < tail) {+ const int32_t node = queue[head++];+ if (dist[node] >= IMPACT_MAX_DEPTH) {+ if (nodes[node].in_count > 0)+ depth_capped = true;+ continue;+ }+ const int32_t first = g_flow_cache.in_first[node];+ for (int e = 0; e < nodes[node].in_count; e++) {+ const int32_t caller = g_flow_cache.in_edges[first + e];+ if (seen[caller])+ continue;+ if (visited >= IMPACT_VISIT_CAP) {+ truncated = true;+ break;+ }+ seen[caller] = 1;+ dist[caller] = (uint8_t)(dist[node] + 1);+ visited++;+ reachable++;+ by_distance[dist[caller] - 1]++;+ if (dist[caller] > max_dist)+ max_dist = dist[caller];+ const char *fp = nodes[caller].file_path;+ const bool is_test = fp && cbm_is_test_file_path(fp);+ if (is_test) {+ test_count++;+ if (tests_emitted < IMPACT_TESTS_CAP) {+ impact_add_node(doc, tests_nearest, &nodes[caller], dist[caller]);+ tests_emitted++;+ }+ } else {+ if (nearest_emitted < IMPACT_NEAREST_CAP) {+ impact_add_node(doc, nearest, &nodes[caller], dist[caller]);+ nearest_emitted++;+ }+ /* Region rollup (non-test reachers only). */+ int ridx = -1;+ if (fp) {+ void *hit = cbm_ht_get(file_region, fp);+ if (hit) {+ ridx = (int)(intptr_t)hit - 2;+ } else {+ char *rname = NULL;+ int rid = cbm_layout_region_for_file(store, project, fp, &rname);+ if (rid >= 0 && rname) {+ for (int r = 0; r < region_count; r++)+ if (strcmp(regions[r].name, rname) == 0) {+ ridx = r;+ break;+ }+ if (ridx < 0 && region_count < IMPACT_REGIONS_CAP) {+ regions[region_count].name = rname;+ regions[region_count].count = 0;+ ridx = region_count++;+ rname = NULL;+ }+ }+ free(rname);+ cbm_ht_set(file_region, fp, (void *)(intptr_t)(ridx + 2));+ }+ }+ if (ridx >= 0)+ regions[ridx].count++;+ else+ unregioned++;+ }+ queue[tail++] = caller;+ }+ if (truncated)+ break;+ }+ }++ yyjson_mut_obj_add_int(doc, root, "reachable", reachable);+ yyjson_mut_obj_add_int(doc, root, "max_distance", max_dist);+ yyjson_mut_obj_add_bool(doc, root, "truncated", truncated);+ yyjson_mut_obj_add_bool(doc, root, "depth_capped", depth_capped);+ yyjson_mut_val *by_d = yyjson_mut_arr(doc);+ for (int d = 0; d < max_dist; d++)+ yyjson_mut_arr_add_int(doc, by_d, by_distance[d]);+ yyjson_mut_obj_add_val(doc, root, "by_distance", by_d);++ /* Regions, largest first, honest tail. */+ for (int a = 0; a < region_count; a++)+ for (int b = a + 1; b < region_count; b++)+ if (regions[b].count > regions[a].count) {+ impact_region_t swap = regions[a];+ regions[a] = regions[b];+ regions[b] = swap;+ }+ yyjson_mut_val *rarr = yyjson_mut_arr(doc);+ const int shown = region_count < IMPACT_REGIONS_SHOWN ? region_count : IMPACT_REGIONS_SHOWN;+ for (int r = 0; r < shown; r++) {+ yyjson_mut_val *obj = yyjson_mut_obj(doc);+ yyjson_mut_obj_add_strcpy(doc, obj, "name", regions[r].name);+ yyjson_mut_obj_add_int(doc, obj, "count", regions[r].count);+ yyjson_mut_arr_append(rarr, obj);+ }+ yyjson_mut_obj_add_val(doc, root, "regions", rarr);+ yyjson_mut_obj_add_int(doc, root, "regions_more", region_count - shown);+ yyjson_mut_obj_add_int(doc, root, "unregioned", unregioned);+ yyjson_mut_obj_add_val(doc, root, "nearest", nearest);+ yyjson_mut_val *tests_obj = yyjson_mut_obj(doc);+ yyjson_mut_obj_add_int(doc, tests_obj, "count", test_count);+ yyjson_mut_obj_add_val(doc, tests_obj, "nearest", tests_nearest);+ yyjson_mut_obj_add_val(doc, root, "tests", tests_obj);++ for (int r = 0; r < region_count; r++)+ free(regions[r].name);+ cbm_ht_free(file_region);+ free(dist);+ free(seen);+ free(queue);+ pthread_mutex_unlock(&g_flow_mu);+ char *json = yyjson_mut_write(doc, 0, NULL);+ yyjson_mut_doc_free(doc);+ return json;+}diff --git a/src/ui/http_server.c b/src/ui/http_server.cindex 9e1de19f1..64d474763 100644--- a/src/ui/http_server.c+++ b/src/ui/http_server.c@@ -1929,6 +1929,28 @@ static void handle_atlas_trace(cbm_http_conn_t *c, const cbm_http_req_t *req) {atlas_reply_json(c, json, 500, "{\"error\":\"trace failed\"}");}+/* GET /api/impact?project=X&node=QN|#id — reverse reachability: who could+ * notice a change to this symbol, at what distance, in which regions, and+ * which test functions reach it. */+static void handle_atlas_impact(cbm_http_conn_t *c, const cbm_http_req_t *req) {+ char project[256] = {0};+ cbm_store_t *store = atlas_open_project(c, req, project, sizeof(project));+ if (!store)+ return;+ char node_str[1024] = {0};+ cbm_http_query_param(req->query, "node", node_str, (int)sizeof(node_str));+ if (!node_str[0]) {+ cbm_store_close(store);+ cbm_http_replyf(c, 400, g_cors_json, "{\"error\":\"missing node parameter\"}");+ return;+ }+ int64_t node_id = node_str[0] == '#' ? strtoll(node_str + 1, NULL, 10) : -1;+ char *json =+ cbm_atlas_impact_json(store, project, node_id, node_id < 0 ? node_str : NULL);+ cbm_store_close(store);+ atlas_reply_json(c, json, 500, "{\"error\":\"impact failed\"}");+}+/* Attach guard chains to a flow-detail JSON (guards=1): each step's call* site is (steps[step.parent] → step); the guard chain is extracted in the* parent's file. Best-effort, same contract as the trace variant. */@@ -2451,6 +2473,12 @@ static void dispatch_request(cbm_http_server_t *srv, cbm_http_conn_t *c,return;}+ /* GET /api/impact → CBM Atlas reverse reachability from one symbol */+ if (is_get && cbm_http_path_match(req->path, "/api/impact*")) {+ handle_atlas_impact(c, req);+ return;+ }+/* GET /api/flows → CBM Atlas flow list */if (is_get && cbm_http_path_match(req->path, "/api/flows*")) {handle_atlas_flows(c, req);diff --git a/tests/test_ui.c b/tests/test_ui.cindex 093f916ea..56d6ed952 100644--- a/tests/test_ui.c+++ b/tests/test_ui.c@@ -1417,6 +1417,115 @@ TEST(atlas_trace_reachability_calls_and_data) {PASS();}+/* Impact = reverse reachability with distances, region rollup, and the+ * test functions that reach the symbol. On the two-community fixture,+ * everything can reach beta_one except beta_one itself: alpha_one and+ * beta_three directly, alpha_three and beta_two at two hops, alpha_two+ * at three. */+TEST(atlas_impact_reverse_reachability_and_tests) {+ cbm_layout_regions_cache_clear();+ cbm_atlas_flows_cache_clear();+ cbm_store_t *store = regions_fixture();+ ASSERT_NOT_NULL(store);++ char *json = cbm_atlas_impact_json(store, "regions-test", -1, "regions-test::beta_one");+ ASSERT_NOT_NULL(json);+ yyjson_doc *doc = yyjson_read(json, strlen(json), 0);+ ASSERT_NOT_NULL(doc);+ yyjson_val *root = yyjson_doc_get_root(doc);+ ASSERT_EQ((int)yyjson_get_int(yyjson_obj_get(root, "reachable")), 5);+ ASSERT_EQ((int)yyjson_get_int(yyjson_obj_get(root, "max_distance")), 3);+ ASSERT_FALSE(yyjson_get_bool(yyjson_obj_get(root, "truncated")));+ yyjson_val *by_d = yyjson_obj_get(root, "by_distance");+ ASSERT_EQ((int)yyjson_arr_size(by_d), 3);+ ASSERT_EQ((int)yyjson_get_int(yyjson_arr_get(by_d, 0)), 2);+ ASSERT_EQ((int)yyjson_get_int(yyjson_arr_get(by_d, 1)), 2);+ ASSERT_EQ((int)yyjson_get_int(yyjson_arr_get(by_d, 2)), 1);+ /* The region split plus the unregioned tail must account for every+ * reacher; with both communities regioned, alpha's three outrank+ * beta's two. */+ yyjson_val *regions = yyjson_obj_get(root, "regions");+ int region_sum = 0;+ size_t ri, rmax;+ yyjson_val *rv;+ yyjson_arr_foreach(regions, ri, rmax, rv) {+ ASSERT_NOT_NULL(yyjson_get_str(yyjson_obj_get(rv, "name")));+ region_sum += (int)yyjson_get_int(yyjson_obj_get(rv, "count"));+ }+ ASSERT_EQ(region_sum + (int)yyjson_get_int(yyjson_obj_get(root, "unregioned")), 5);+ if (yyjson_arr_size(regions) == 2)+ ASSERT_EQ((int)yyjson_get_int(yyjson_obj_get(yyjson_arr_get(regions, 0), "count")), 3);+ yyjson_val *tests = yyjson_obj_get(root, "tests");+ ASSERT_EQ((int)yyjson_get_int(yyjson_obj_get(tests, "count")), 0);+ yyjson_doc_free(doc);+ free(json);++ /* A test function calling into the beta cycle is reported as a test+ * to run, with its call distance. */+ cbm_node_t tnode;+ memset(&tnode, 0, sizeof(tnode));+ tnode.project = "regions-test";+ tnode.label = "Function";+ tnode.name = "test_beta";+ tnode.qualified_name = "regions-test::test_beta";+ tnode.file_path = "tests/test_beta.c";+ tnode.start_line = 1;+ tnode.end_line = 5;+ int64_t test_id = cbm_store_upsert_node(store, &tnode);+ ASSERT_GT(test_id, 0);+ int64_t beta_two_id = -1;+ {+ cbm_search_params_t params;+ memset(¶ms, 0, sizeof(params));+ params.project = "regions-test";+ params.qn_pattern = "regions-test::beta_two";+ params.limit = 1;+ params.min_degree = -1;+ params.max_degree = -1;+ cbm_search_output_t out;+ memset(&out, 0, sizeof(out));+ if (cbm_store_search(store, ¶ms, &out) == CBM_STORE_OK && out.count == 1)+ beta_two_id = out.results[0].node.id;+ cbm_store_search_free(&out);+ }+ ASSERT_GT(beta_two_id, 0);+ cbm_edge_t tedge;+ memset(&tedge, 0, sizeof(tedge));+ tedge.project = "regions-test";+ tedge.source_id = test_id;+ tedge.target_id = beta_two_id;+ tedge.type = "CALLS";+ ASSERT_GT(cbm_store_insert_edge(store, &tedge), 0);+ cbm_atlas_flows_cache_clear();++ json = cbm_atlas_impact_json(store, "regions-test", -1, "regions-test::beta_one");+ ASSERT_NOT_NULL(json);+ doc = yyjson_read(json, strlen(json), 0);+ root = yyjson_doc_get_root(doc);+ ASSERT_EQ((int)yyjson_get_int(yyjson_obj_get(root, "reachable")), 6);+ tests = yyjson_obj_get(root, "tests");+ ASSERT_EQ((int)yyjson_get_int(yyjson_obj_get(tests, "count")), 1);+ yyjson_val *tnear = yyjson_obj_get(tests, "nearest");+ ASSERT_EQ((int)yyjson_arr_size(tnear), 1);+ ASSERT_STR_EQ(yyjson_get_str(yyjson_obj_get(yyjson_arr_get(tnear, 0), "name")), "test_beta");+ ASSERT_EQ((int)yyjson_get_int(yyjson_obj_get(yyjson_arr_get(tnear, 0), "distance")), 3);+ yyjson_doc_free(doc);+ free(json);++ /* Unknown symbol answers with an error, not a crash. */+ json = cbm_atlas_impact_json(store, "regions-test", -1, "regions-test::nope");+ ASSERT_NOT_NULL(json);+ doc = yyjson_read(json, strlen(json), 0);+ ASSERT_NOT_NULL(yyjson_obj_get(yyjson_doc_get_root(doc), "error"));+ yyjson_doc_free(doc);+ free(json);++ cbm_store_close(store);+ cbm_atlas_flows_cache_clear();+ cbm_layout_regions_cache_clear();+ PASS();+}+TEST(atlas_symbol_data_flows_and_history_shape) {cbm_layout_regions_cache_clear();cbm_atlas_metrics_cache_clear();@@ -1888,6 +1997,7 @@ SUITE(ui) {RUN_TEST(atlas_flows_walk_and_rank);RUN_TEST(atlas_metrics_totals_and_certainty);RUN_TEST(atlas_trace_reachability_calls_and_data);+ RUN_TEST(atlas_impact_reverse_reachability_and_tests);RUN_TEST(atlas_symbol_data_flows_and_history_shape);RUN_TEST(atlas_scent_buckets_matches_by_region);RUN_TEST(atlas_bridges_rank_by_region_reach);