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): Why-view depth — dispatch chip, guard table, flow-step guards
Martin Vogelf13f7f845ec0
diff --git a/graph-ui/src/components/FilterPanel.tsx b/graph-ui/src/components/FilterPanel.tsxindex bc0399241..cb70a95b3 100644--- a/graph-ui/src/components/FilterPanel.tsx+++ b/graph-ui/src/components/FilterPanel.tsx@@ -56,7 +56,7 @@ function CheckRow({</span>{label}{count !== undefined && (- <span className="text-foreground/40 tabular-nums">{count.toLocaleString()}</span>+ <span className="text-foreground/40 tabular-nums">{count.toLocaleString("en-US")}</span>)}</button>);@@ -136,7 +136,7 @@ export function FilterPanel({><span className="w-[5px] h-[5px] rounded-full" style={{ backgroundColor: on ? c : "#444" }} /><span style={{ color: on ? c : "#555" }}>{label}</span>- <span className="text-foreground/35 tabular-nums">{count.toLocaleString()}</span>+ <span className="text-foreground/35 tabular-nums">{count.toLocaleString("en-US")}</span></button>);})}@@ -160,7 +160,7 @@ export function FilterPanel({}`}>{type.replace(/_/g, " ").toLowerCase()}- <span className="text-foreground/30 tabular-nums">{count.toLocaleString()}</span>+ <span className="text-foreground/30 tabular-nums">{count.toLocaleString("en-US")}</span></button>);})}@@ -180,7 +180,7 @@ export function FilterPanel({</span>{missedCount > 0 && (<span className="text-[12px] text-foreground/50 tabular-nums">- {missedCount.toLocaleString()} files+ {missedCount.toLocaleString("en-US")} files</span>)}</div>@@ -203,7 +203,7 @@ export function FilterPanel({Dead code</span><span className="text-[12px] text-red-400/80 tabular-nums">- {deadCount.toLocaleString()} dead+ {deadCount.toLocaleString("en-US")} dead</span></div>diff --git a/graph-ui/src/components/FlowsTab.tsx b/graph-ui/src/components/FlowsTab.tsxindex c2b128d1c..f79efe5d1 100644--- a/graph-ui/src/components/FlowsTab.tsx+++ b/graph-ui/src/components/FlowsTab.tsx@@ -431,6 +431,19 @@ export function FlowsTab({ project, flowId, onOpenFlow, onOpenSymbol }: FlowsTab<span className="text-[12px] font-mono text-foreground/70 group-hover:text-primary transition-colors truncate">{step.name}</span>+ {(step.guards ?? []).slice(0, 3).map((guard, gi) => (+ <span+ key={gi}+ className={`text-[10px] px-1 rounded-full border font-mono shrink-0 max-w-[220px] truncate ${+ guard.negated+ ? "border-warn/50 text-warn/80"+ : "border-primary/40 text-primary/80"+ }`}+ title="syntactic guard at this step's call site"+ >+ {formatGuard(guard)}+ </span>+ ))}<span className="text-[12px] text-foreground/35 truncate ml-auto shrink-0 max-w-[40%]">{step.file_path}</span>diff --git a/graph-ui/src/components/GraphTab.tsx b/graph-ui/src/components/GraphTab.tsxindex 3ca0841e8..a89dac553 100644--- a/graph-ui/src/components/GraphTab.tsx+++ b/graph-ui/src/components/GraphTab.tsx@@ -872,12 +872,12 @@ export function GraphTab({<p className="text-primary/60">region: {view.region.name}</p>)}<p>- {filteredData.nodes.length.toLocaleString()} nodes /{" "}- {filteredData.edges.length.toLocaleString()} edges+ {filteredData.nodes.length.toLocaleString("en-US")} nodes /{" "}+ {filteredData.edges.length.toLocaleString("en-US")} edges</p>{data.nodes.length > filteredData.nodes.length && (<p className="text-foreground/40 mt-0.5">- filtered from {data.nodes.length.toLocaleString()}+ filtered from {data.nodes.length.toLocaleString("en-US")}</p>)}{limitNotice && (diff --git a/graph-ui/src/components/ProjectCard.tsx b/graph-ui/src/components/ProjectCard.tsxindex c9ccca01d..824516597 100644--- a/graph-ui/src/components/ProjectCard.tsx+++ b/graph-ui/src/components/ProjectCard.tsx@@ -8,7 +8,7 @@ interface ProjectCardProps {}function formatNumber(n: number): string {- return n.toLocaleString();+ return n.toLocaleString("en-US");}export function ProjectCard({ project, schema, onSelect }: ProjectCardProps) {diff --git a/graph-ui/src/components/StatsTab.tsx b/graph-ui/src/components/StatsTab.tsxindex 95673c121..1371b7d5a 100644--- a/graph-ui/src/components/StatsTab.tsx+++ b/graph-ui/src/components/StatsTab.tsx@@ -22,7 +22,7 @@ function HealthDot({ name }: { name: string }) {setStatus(d.status ?? "corrupt");if (d.nodes !== undefined) {const sizeMB = ((d.size_bytes ?? 0) / 1024 / 1024).toFixed(1);- setInfo(`${d.nodes.toLocaleString()} nodes, ${d.edges.toLocaleString()} edges, ${sizeMB} MB`);+ setInfo(`${d.nodes.toLocaleString("en-US")} nodes, ${d.edges.toLocaleString("en-US")} edges, ${sizeMB} MB`);} else if (d.reason) {setInfo(d.reason);}@@ -531,7 +531,7 @@ export function StatsTab({ onSelectProject }: StatsTabProps) {].map((s) => (<div key={s.label} className="flex-1 rounded-md border border-border/30 bg-card p-4"><p className="text-[12px] text-foreground/40 uppercase tracking-widest mb-1">{s.label}</p>- <p className={`text-[22px] font-semibold tabular-nums ${s.color}`}>{s.value.toLocaleString()}</p>+ <p className={`text-[22px] font-semibold tabular-nums ${s.color}`}>{s.value.toLocaleString("en-US")}</p></div>))}</div>@@ -581,14 +581,14 @@ export function StatsTab({ onSelectProject }: StatsTabProps) {{p.schema && (<><div className="flex gap-6 text-[12px] text-foreground/45 mb-3">- <span><strong className="text-foreground/55 tabular-nums">{totalNodes.toLocaleString()}</strong> {t.projects.nodes}</span>- <span><strong className="text-foreground/55 tabular-nums">{totalEdges.toLocaleString()}</strong> {t.projects.edges}</span>+ <span><strong className="text-foreground/55 tabular-nums">{totalNodes.toLocaleString("en-US")}</strong> {t.projects.nodes}</span>+ <span><strong className="text-foreground/55 tabular-nums">{totalEdges.toLocaleString("en-US")}</strong> {t.projects.edges}</span></div><div className="flex flex-wrap gap-1">{p.schema.node_labels?.map((l) => (<span key={l.label} className="inline-flex items-center gap-1 px-1.5 py-[2px] rounded-md text-[12px] font-medium" style={{ backgroundColor: colorForLabel(l.label) + "10", color: colorForLabel(l.label) + "bb" }}><span className="w-[4px] h-[4px] rounded-full" style={{ backgroundColor: colorForLabel(l.label) }} />- {l.label} {l.count.toLocaleString()}+ {l.label} {l.count.toLocaleString("en-US")}</span>))}</div>diff --git a/graph-ui/src/components/TriggerTree.tsx b/graph-ui/src/components/TriggerTree.tsxindex 6ece304c4..97925ea2f 100644--- a/graph-ui/src/components/TriggerTree.tsx+++ b/graph-ui/src/components/TriggerTree.tsx@@ -11,6 +11,18 @@ import {* carrying its syntactic guard chain as chips, expandable upward in place.* Thin by default; elision declared; guards honest about being syntactic. */+function DispatchChip({ entry }: { entry: WhyEntry }) {+ if (!entry.candidates || entry.candidates <= 1) return null;+ return (+ <span+ className="text-[11px] px-1.5 rounded-full border border-border/60 text-foreground/55"+ title="dynamic dispatch: the resolver saw several possible targets for this call site — this is one of them"+ >+ ◇ 1 of {entry.candidates} targets+ </span>+ );+}+function GuardChips({ entry }: { entry: WhyEntry }) {if (entry.guards_unavailable)return <span className="text-[12px] text-foreground/35">guards unavailable (source not readable)</span>;@@ -102,6 +114,7 @@ function WhyLevel({{entry.name}</button><GuardChips entry={entry} />+ <DispatchChip entry={entry} />{direction === "up" && entry.more > 0 && (<buttononClick={() =>@@ -141,6 +154,85 @@ function WhyLevel({);}+/* The decision-table pivot (Huysmans 2011: tables win for+ * condition-combination lookup): rows = callers, columns = the distinct+ * conditions seen across their call sites, cells = when/unless/—. Offered+ * only when several guarded callers exist. */+function GuardTable({+ entries,+ onOpenSymbol,+}: {+ entries: WhyEntry[];+ onOpenSymbol: (ref: { id?: number; qn?: string }) => void;+}) {+ const conds: string[] = [];+ for (const entry of entries)+ for (const guard of entry.guards) {+ const key = guard.cond ?? guard.kind;+ if (!conds.includes(key)) conds.push(key);+ }+ const shown = conds.slice(0, 6);+ return (+ <div className="overflow-x-auto">+ <table className="text-[12px] border-collapse">+ <thead>+ <tr>+ <th className="text-left pr-3 pb-1 text-foreground/40 font-normal uppercase tracking-wider text-[11px]">+ caller+ </th>+ {shown.map((cond) => (+ <th+ key={cond}+ className="text-left px-2 pb-1 text-foreground/50 font-mono font-normal max-w-[180px] truncate"+ title={cond}+ >+ {cond}+ </th>+ ))}+ {conds.length > shown.length && (+ <th className="text-left px-2 pb-1 text-foreground/35 font-normal">+ +{conds.length - shown.length} more+ </th>+ )}+ </tr>+ </thead>+ <tbody>+ {entries.map((entry) => (+ <tr key={entry.id} className="border-t border-border/30">+ <td className="pr-3 py-1">+ <button+ onClick={() => onOpenSymbol({ id: entry.id })}+ className="font-mono text-foreground/70 hover:text-primary transition-colors"+ >+ {entry.name}+ </button>+ </td>+ {shown.map((cond) => {+ const guard = entry.guards.find((g) => (g.cond ?? g.kind) === cond);+ return (+ <td key={cond} className="px-2 py-1">+ {guard ? (+ <span+ className={guard.negated ? "text-warn/90" : "text-good"}+ title={guard.negated ? "call sits in the else arm" : "call requires this"}+ >+ {guard.negated ? "✗ unless" : "✓ when"}+ </span>+ ) : (+ <span className="text-foreground/25">—</span>+ )}+ </td>+ );+ })}+ {conds.length > shown.length && <td className="px-2 py-1" />}+ </tr>+ ))}+ </tbody>+ </table>+ </div>+ );+}+export function TriggerTree({project,symbolId,@@ -152,6 +244,8 @@ export function TriggerTree({}) {const [direction, setDirection] = useState<"up" | "down">("up");const [root, setRoot] = useState<WhyPayload | null>(null);+ const [asTable, setAsTable] = useState(false);+ const guardedCount = (root?.entries ?? []).filter((e) => e.guards.length > 0).length;useEffect(() => {let cancelled = false;@@ -172,12 +266,23 @@ export function TriggerTree({<p className="text-[12px] uppercase tracking-widest text-foreground/40">{direction === "up" ? "When does this run?" : "What does this trigger?"}</p>- <button- onClick={() => setDirection((d) => (d === "up" ? "down" : "up"))}- className="ml-auto text-[12px] text-foreground/45 hover:text-primary transition-colors"- >- {direction === "up" ? "→ what it triggers" : "← when it runs"}- </button>+ <div className="ml-auto flex items-center gap-3">+ {guardedCount >= 3 && (+ <button+ onClick={() => setAsTable((v) => !v)}+ className="text-[12px] text-foreground/45 hover:text-primary transition-colors"+ title="Pivot the guarded callers into a condition table"+ >+ {asTable ? "tree" : "table"}+ </button>+ )}+ <button+ onClick={() => setDirection((d) => (d === "up" ? "down" : "up"))}+ className="text-[12px] text-foreground/45 hover:text-primary transition-colors"+ >+ {direction === "up" ? "→ what it triggers" : "← when it runs"}+ </button>+ </div></div>{root && allUnguarded(root.entries) && root.entries.length > 0 && root.entries.length <= 2 ? (<p className="text-[13px] text-foreground/60">@@ -195,6 +300,11 @@ export function TriggerTree({))}{direction === "up" ? " runs — no conditions at the call sites." : " — unconditionally."}</p>+ ) : asTable && root ? (+ <GuardTable+ entries={root.entries.filter((e) => e.guards.length > 0)}+ onOpenSymbol={onOpenSymbol}+ />) : (<WhyLevelproject={project}diff --git a/graph-ui/src/lib/atlas.ts b/graph-ui/src/lib/atlas.tsindex 2cb4ba0a5..84b90ae18 100644--- a/graph-ui/src/lib/atlas.ts+++ b/graph-ui/src/lib/atlas.ts@@ -141,6 +141,7 @@ export interface FlowStep {file_path?: string;depth: number;parent: number;+ guards?: { kind: string; cond?: string; negated?: boolean }[];}export interface FlowDetail {@@ -158,7 +159,8 @@ export function fetchFlows(project: string): Promise<FlowsPayload> {}export function fetchFlow(project: string, id: number): Promise<FlowDetail> {- return getJson(`/api/flow?${new URLSearchParams({ project, id: String(id) })}`);+ /* guards=1: per-step syntactic guard chips, computed on demand. */+ return getJson(`/api/flow?${new URLSearchParams({ project, id: String(id), guards: "1" })}`);}/* ── get_architecture (format:"json" → {cols, rows} sections) ── */diff --git a/graph-ui/src/lib/why.ts b/graph-ui/src/lib/why.tsindex ad8a651cb..4555bedd4 100644--- a/graph-ui/src/lib/why.ts+++ b/graph-ui/src/lib/why.ts@@ -18,6 +18,8 @@ export interface WhyEntry {guards: Guard[];loop?: boolean;guards_unavailable?: boolean;+ /* >1 = dynamic dispatch: this is one of N possible targets. */+ candidates?: number;more: number;}diff --git a/src/ui/atlas_why.c b/src/ui/atlas_why.cindex 31f07693d..0d26bfc75 100644--- a/src/ui/atlas_why.c+++ b/src/ui/atlas_why.c@@ -287,6 +287,19 @@ static int why_edge_line(const char *properties_json) {return line > 0 ? line : -1;}+/* Dynamic-dispatch uncertainty: how many candidate targets the resolver saw+ * for this call site (1 = certain, >1 = the ◇ case). */+static int why_edge_candidates(const char *properties_json) {+ if (!properties_json)+ return 0;+ yyjson_doc *doc = yyjson_read(properties_json, strlen(properties_json), 0);+ if (!doc)+ return 0;+ int candidates = (int)yyjson_get_int(yyjson_obj_get(yyjson_doc_get_root(doc), "candidates"));+ yyjson_doc_free(doc);+ return candidates;+}+/* ── The Why endpoint ───────────────────────────────────────────── */char *cbm_atlas_why_json(cbm_store_t *store, const char *project, int64_t node_id,@@ -399,6 +412,9 @@ char *cbm_atlas_why_json(cbm_store_t *store, const char *project, int64_t node_iint line = why_edge_line(props);if (line > 0)yyjson_mut_obj_add_int(doc, entry, "line", line);+ int candidates = why_edge_candidates(props);+ if (candidates > 1)+ yyjson_mut_obj_add_int(doc, entry, "candidates", candidates);/* The file holding the call site. */const char *site_file = upward ? f : (sym_file[0] ? sym_file : NULL);bool ok = false;diff --git a/src/ui/http_server.c b/src/ui/http_server.cindex b9b30da6c..9e1de19f1 100644--- a/src/ui/http_server.c+++ b/src/ui/http_server.c@@ -1929,6 +1929,82 @@ 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\"}");}+/* 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. */+static char *atlas_flow_attach_guards(cbm_store_t *store, const char *project, char *json) {+ yyjson_doc *doc = yyjson_read(json, strlen(json), 0);+ if (!doc)+ return json;+ yyjson_val *steps = yyjson_obj_get(yyjson_doc_get_root(doc), "steps");+ size_t count = steps ? yyjson_arr_size(steps) : 0;+ if (count < 2) {+ yyjson_doc_free(doc);+ return json;+ }+ yyjson_mut_doc *mut = yyjson_doc_mut_copy(doc, NULL);+ yyjson_doc_free(doc);+ if (!mut)+ return json;+ yyjson_mut_val *msteps = yyjson_mut_obj_get(yyjson_mut_doc_get_root(mut), "steps");+ struct sqlite3 *db = cbm_store_get_db(store);+ for (size_t i = 1; i < count && db; i++) {+ yyjson_mut_val *step = yyjson_mut_arr_get(msteps, i);+ int64_t parent_index = yyjson_mut_get_int(yyjson_mut_obj_get(step, "parent"));+ if (parent_index < 0 || (size_t)parent_index >= count)+ continue;+ yyjson_mut_val *parent = yyjson_mut_arr_get(msteps, (size_t)parent_index);+ int64_t from_id = yyjson_mut_get_int(yyjson_mut_obj_get(parent, "id"));+ int64_t to_id = yyjson_mut_get_int(yyjson_mut_obj_get(step, "id"));+ const char *from_file = yyjson_mut_get_str(yyjson_mut_obj_get(parent, "file_path"));+ if (!from_file)+ continue;+ sqlite3_stmt *st = NULL;+ int line = -1;+ if (sqlite3_prepare_v2(db,+ "SELECT properties FROM edges WHERE project=?1 AND "+ "source_id=?2 AND target_id=?3 AND type='CALLS' LIMIT 1",+ -1, &st, NULL) == SQLITE_OK) {+ sqlite3_bind_text(st, 1, project, -1, SQLITE_STATIC);+ sqlite3_bind_int64(st, 2, from_id);+ sqlite3_bind_int64(st, 3, to_id);+ if (sqlite3_step(st) == SQLITE_ROW) {+ const char *props = (const char *)sqlite3_column_text(st, 0);+ if (props) {+ yyjson_doc *pd = yyjson_read(props, strlen(props), 0);+ if (pd) {+ line = (int)yyjson_get_int(yyjson_obj_get(yyjson_doc_get_root(pd), "line"));+ yyjson_doc_free(pd);+ }+ }+ }+ sqlite3_finalize(st);+ }+ if (line <= 0)+ continue;+ char *gj = cbm_atlas_callsite_guards_json(store, project, from_file, line);+ if (!gj)+ continue;+ yyjson_doc *gd = yyjson_read(gj, strlen(gj), 0);+ free(gj);+ if (!gd)+ continue;+ yyjson_val *garr = yyjson_obj_get(yyjson_doc_get_root(gd), "guards");+ if (garr && yyjson_arr_size(garr) > 0) {+ yyjson_mut_val *copy = yyjson_val_mut_copy(mut, garr);+ if (copy)+ yyjson_mut_obj_add_val(mut, step, "guards", copy);+ }+ yyjson_doc_free(gd);+ }+ char *out = yyjson_mut_write(mut, 0, NULL);+ yyjson_mut_doc_free(mut);+ if (!out)+ return json;+ free(json);+ return out;+}+/* GET /api/why?project=X&id=N|qn=Q&dir=up|down — the trigger tree. */static void handle_atlas_why(cbm_http_conn_t *c, const cbm_http_req_t *req) {char project[256] = {0};@@ -2038,6 +2114,10 @@ static void handle_atlas_flow(cbm_http_conn_t *c, const cbm_http_req_t *req) {if (cbm_http_query_param(req->query, "id", id_str, (int)sizeof(id_str)))id = atoi(id_str);char *json = cbm_atlas_flow_json(store, project, id);+ char wantg[8] = {0};+ cbm_http_query_param(req->query, "guards", wantg, (int)sizeof(wantg));+ if (json && wantg[0] == '1')+ json = atlas_flow_attach_guards(store, project, json);cbm_store_close(store);atlas_reply_json(c, json, 404, "{\"error\":\"unknown flow\"}");}