Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

feat(ui): name gateway-routed links and partial graph evidence on the system map (#4591)

Raghav Chamadiya92a0654797de
diff --git a/packages/ui/__tests__/workspace/system-map-logic.test.ts b/packages/ui/__tests__/workspace/system-map-logic.test.ts
index efc091dbb..476d1521e 100644
--- a/packages/ui/__tests__/workspace/system-map-logic.test.ts
+++ b/packages/ui/__tests__/workspace/system-map-logic.test.ts
@@ -10,6 +10,8 @@ import {
} from "../../src/workspace/system-map/layout";
import {
edgeKindStyle,
+ edgeLabel,
+ isGatewayRouted,
matchTypeDash,
matchTypeLabel,
EDGE_KIND_ORDER,
@@ -134,6 +136,19 @@ describe("collapseToRepos", () => {
);
expect(collapseToRepos(mixed).nodes[0]!.kind).toBe("service");
});
+
+ it("keeps the strategy of the strongest merged link, as the core builder does", () => {
+ const g = graph(
+ [node("api::a", "api"), node("api::b", "api"), node("gw", "gw")],
+ [
+ edge("gw", "api::a", { confidence: 0.6, strategy: "prefix_stripped" }),
+ edge("gw", "api::b", { confidence: 1, strategy: "gateway_route" }),
+ ],
+ );
+ expect(collapseToRepos(g).edges[0]!.strategy).toBe("gateway_route");
+ const weakerSecond = graph(g.nodes, [g.edges[1]!, { ...g.edges[0]!, id: "x" }]);
+ expect(collapseToRepos(weakerSecond).edges[0]!.strategy).toBe("gateway_route");
+ });
});
describe("applyView", () => {
@@ -181,6 +196,15 @@ describe("edge-kind registry", () => {
expect(edgeKindStyle("http").category).toBe("structural");
});
+ it("names a gateway-routed link in words, keeping its transport kind", () => {
+ const routed = { kind: "http" as const, strategy: "gateway_route" };
+ expect(isGatewayRouted(routed)).toBe(true);
+ expect(edgeLabel(routed)).toBe("HTTP via gateway");
+ expect(edgeKindStyle(routed.kind).label).toBe("HTTP");
+ expect(isGatewayRouted({ strategy: "service_mapped" })).toBe(false);
+ expect(edgeLabel({ kind: "http", strategy: null })).toBe("HTTP");
+ });
+
it("falls back gracefully for an unknown kind", () => {
expect(edgeKindStyle("quantum").label).toBe("Link");
});
diff --git a/packages/ui/__tests__/workspace/system-map.test.tsx b/packages/ui/__tests__/workspace/system-map.test.tsx
index 57e893076..a64855882 100644
--- a/packages/ui/__tests__/workspace/system-map.test.tsx
+++ b/packages/ui/__tests__/workspace/system-map.test.tsx
@@ -1,9 +1,10 @@
import { describe, it, expect, vi, beforeAll } from "vitest";
import { render, screen, fireEvent, within } from "@testing-library/react";
-import type { CrossRepoBlastRadius, SystemEdge, SystemGraph, SystemNode } from "@repowise-dev/types";
+import type { CrossRepoBlastRadius, GraphEvidence, SystemEdge, SystemGraph, SystemNode } from "@repowise-dev/types";
import { SystemMap } from "../../src/workspace/system-map/system-map";
import { Segmented, SystemMapFilters } from "../../src/workspace/system-map/system-map-filters";
import { SystemMapLegend } from "../../src/workspace/system-map/system-map-legend";
+import { SystemMapEvidenceNotice } from "../../src/workspace/system-map/system-map-evidence-notice";
import { SystemMapDrawer, selectionRepo } from "../../src/workspace/system-map/system-map-drawer";
import { SystemMapFindings } from "../../src/workspace/system-map/system-map-findings";
import { resolveViewSelection } from "../../src/workspace/system-map/system-map-model";
@@ -269,6 +270,48 @@ describe("SystemMapLegend", () => {
expect(screen.queryByText(/candidate/i)).not.toBeInTheDocument();
expect(screen.getByText("Healthy 8+")).toBeInTheDocument();
expect(screen.getByText("Alert below 4")).toBeInTheDocument();
+ expect(screen.queryByText(/gateway route/i)).not.toBeInTheDocument();
+ });
+
+ it("names gateway-routed lines in words when the graph has any", () => {
+ render(<SystemMapLegend matchTypes={new Set(["exact"])} gatewayRouted={2} />);
+ expect(screen.getByText(/lines run through a gateway route/i)).toBeInTheDocument();
+ });
+});
+
+describe("SystemMapEvidenceNotice", () => {
+ const evidence = (state: GraphEvidence["state"], summary: string): GraphEvidence => ({
+ state,
+ determined: state !== "insufficient",
+ summary,
+ reasons: [],
+ services: 3,
+ runtime_edges: 0,
+ build_edges: 2,
+ providers: 4,
+ consumers: 1,
+ });
+
+ it("renders nothing when the evidence is measured or absent", () => {
+ const { container, rerender } = render(<SystemMapEvidenceNotice evidence={evidence("measured", "")} />);
+ expect(container).toBeEmptyDOMElement();
+ rerender(<SystemMapEvidenceNotice evidence={null} />);
+ expect(container).toBeEmptyDOMElement();
+ });
+
+ it("names the state and the reason as one sentence", () => {
+ const { rerender } = render(
+ <SystemMapEvidenceNotice evidence={evidence("partial", "every detected dependency is a build reference")} />,
+ );
+ expect(screen.getByRole("status")).toHaveTextContent("Partial evidence");
+ expect(screen.getByText("Every detected dependency is a build reference.")).toBeInTheDocument();
+ rerender(
+ <SystemMapEvidenceNotice
+ evidence={evidence("insufficient", "no service carries a contract")}
+ insufficientLabel="Unknown here"
+ />,
+ );
+ expect(screen.getByRole("status")).toHaveTextContent("Unknown here");
});
});
diff --git a/packages/ui/src/workspace/system-map/collapse.ts b/packages/ui/src/workspace/system-map/collapse.ts
index f202176ad..3e20d0aad 100644
--- a/packages/ui/src/workspace/system-map/collapse.ts
+++ b/packages/ui/src/workspace/system-map/collapse.ts
@@ -88,6 +88,8 @@ export function collapseToRepos(graph: SystemGraph): SystemGraph {
continue;
}
existing.weight += edge.weight;
+ // The strategy names the strongest link, as the core graph builder keeps it.
+ if (edge.confidence > existing.confidence) existing.strategy = edge.strategy ?? null;
existing.confidence = Math.max(existing.confidence, edge.confidence);
existing.match_type = strongerMatch(existing.match_type, edge.match_type);
if (existing.contract_refs.length < MAX_REFS) {
diff --git a/packages/ui/src/workspace/system-map/edge-kinds.ts b/packages/ui/src/workspace/system-map/edge-kinds.ts
index 418aa4277..9e1609241 100644
--- a/packages/ui/src/workspace/system-map/edge-kinds.ts
+++ b/packages/ui/src/workspace/system-map/edge-kinds.ts
@@ -13,7 +13,7 @@
*/
import { ArrowRight, Boxes, Database, Link2, Radio, Signal, Zap, type LucideIcon } from "lucide-react";
-import type { SystemEdgeKind, SystemEdgeMatchType } from "@repowise-dev/types";
+import type { SystemEdge, SystemEdgeKind, SystemEdgeMatchType } from "@repowise-dev/types";
/** Whether an edge reflects a structural contract/dependency or behavioral co-change. */
export type EdgeCategory = "structural" | "behavioral";
@@ -56,6 +56,22 @@ export function edgeKindStyle(kind: string): SystemEdgeKindStyle {
return SYSTEM_EDGE_KINDS[kind as SystemEdgeKind] ?? FALLBACK_KIND;
}
+/**
+ * A link a gateway's route config made (`gateway_route` strategy). It keeps
+ * its transport kind and its match dash: routing is how the link was found,
+ * not a third line style, so it is named in words on hover and in the legend
+ * instead.
+ */
+export function isGatewayRouted(edge: Pick<SystemEdge, "strategy">): boolean {
+ return edge.strategy === "gateway_route";
+}
+
+/** The edge's hover label: its kind, plus "via gateway" when a gateway route made it. */
+export function edgeLabel(edge: Pick<SystemEdge, "kind" | "strategy">): string {
+ const label = edgeKindStyle(edge.kind).label;
+ return isGatewayRouted(edge) ? `${label} via gateway` : label;
+}
+
/** Every edge kind, in legend/display order (structural first, behavioral last). */
export const EDGE_KIND_ORDER: SystemEdgeKind[] = ["http", "grpc", "socket", "event", "package", "db", "co_change"];
diff --git a/packages/ui/src/workspace/system-map/index.ts b/packages/ui/src/workspace/system-map/index.ts
index c4759c9a0..6231fd98c 100644
--- a/packages/ui/src/workspace/system-map/index.ts
+++ b/packages/ui/src/workspace/system-map/index.ts
@@ -12,6 +12,7 @@ export {
type SystemMapProps,
} from "./system-map";
export { SystemMapLegend, type SystemMapLegendProps } from "./system-map-legend";
+export { SystemMapEvidenceNotice, type SystemMapEvidenceNoticeProps } from "./system-map-evidence-notice";
export {
SystemMapFilters,
Segmented,
diff --git a/packages/ui/src/workspace/system-map/system-map-edge.tsx b/packages/ui/src/workspace/system-map/system-map-edge.tsx
index 1825af603..83776a0f0 100644
--- a/packages/ui/src/workspace/system-map/system-map-edge.tsx
+++ b/packages/ui/src/workspace/system-map/system-map-edge.tsx
@@ -13,7 +13,7 @@
import { memo } from "react";
import { BaseEdge, EdgeLabelRenderer, getSmoothStepPath, type EdgeProps } from "@xyflow/react";
-import { edgeKindStyle, matchTypeDash } from "./edge-kinds";
+import { edgeKindStyle, edgeLabel, matchTypeDash } from "./edge-kinds";
import { useEdgeActive } from "./system-map-focus";
import { weightShort } from "./system-map-model";
import type { SystemMapEdgeData } from "./types";
@@ -97,7 +97,7 @@ function SystemMapEdgeInner(props: EdgeProps) {
}}
>
<Icon size={10} aria-hidden style={{ flexShrink: 0 }} />
- {style.label} · {weightShort(edge)}
+ {edgeLabel(edge)} · {weightShort(edge)}
{overlay?.badge && (
<span style={{ color: badgeColor(overlay.badge.tone), fontWeight: 600 }}>
· {overlay.badge.label}
diff --git a/packages/ui/src/workspace/system-map/system-map-evidence-notice.tsx b/packages/ui/src/workspace/system-map/system-map-evidence-notice.tsx
new file mode 100644
index 000000000..1ab05b788
--- /dev/null
+++ b/packages/ui/src/workspace/system-map/system-map-evidence-notice.tsx
@@ -0,0 +1,34 @@
+/**
+ * One quiet line above the Live System Map when the graph it draws is short of
+ * measured evidence: part of the estate is out of sight (`partial`), or too
+ * little was linked for a score, cycle verdict or blast radius to mean anything
+ * (`insufficient`). Names the reason from `core/workspace/graph_evidence.py`.
+ *
+ * A neutral note, never a health signal: it does not touch the health marks
+ * on the nodes, and renders nothing when the evidence is measured or absent.
+ */
+
+import type { GraphEvidence } from "@repowise-dev/types";
+import { Callout } from "../../shared/callout";
+
+export interface SystemMapEvidenceNoticeProps {
+ evidence: GraphEvidence | null | undefined;
+ /** Word beside the dot for a partial graph. */
+ partialLabel?: string;
+ /** Word beside the dot for an insufficient graph. */
+ insufficientLabel?: string;
+}
+
+export function SystemMapEvidenceNotice({
+ evidence,
+ partialLabel = "Partial evidence",
+ insufficientLabel = "Not determined",
+}: SystemMapEvidenceNoticeProps) {
+ if (!evidence || evidence.state === "measured" || !evidence.summary) return null;
+ const sentence = evidence.summary[0]!.toUpperCase() + evidence.summary.slice(1);
+ return (
+ <Callout label={evidence.state === "insufficient" ? insufficientLabel : partialLabel}>
+ {sentence.endsWith(".") ? sentence : `${sentence}.`}
+ </Callout>
+ );
+}
diff --git a/packages/ui/src/workspace/system-map/system-map-legend.tsx b/packages/ui/src/workspace/system-map/system-map-legend.tsx
index f8985b26a..7af3a9567 100644
--- a/packages/ui/src/workspace/system-map/system-map-legend.tsx
+++ b/packages/ui/src/workspace/system-map/system-map-legend.tsx
@@ -52,9 +52,11 @@ function markRange(i: number): string {
export interface SystemMapLegendProps {
/** Match types present on the drawn edges; only these get a key. */
matchTypes?: ReadonlySet<SystemEdgeMatchType>;
+ /** Drawn lines a gateway route made; they share the HTTP line, so the key names them in words. */
+ gatewayRouted?: number;
}
-export function SystemMapLegend({ matchTypes }: SystemMapLegendProps) {
+export function SystemMapLegend({ matchTypes, gatewayRouted = 0 }: SystemMapLegendProps) {
const order: SystemEdgeMatchType[] = ["exact", "manual", "candidate", "inferred"];
const shown = order.filter((m) => !matchTypes || matchTypes.has(m));
// Exact and manual draw the same solid line; one key covers both.
@@ -74,6 +76,12 @@ export function SystemMapLegend({ matchTypes }: SystemMapLegendProps) {
}
/>
))}
+ {gatewayRouted > 0 && (
+ <span className="text-xs text-[var(--color-text-secondary)]">
+ <span className="font-mono tabular-nums">{gatewayRouted}</span>{" "}
+ {gatewayRouted === 1 ? "line runs" : "lines run"} through a gateway route; hover shows which
+ </span>
+ )}
<span className="inline-flex items-center gap-2.5">
<span className="text-xs text-[var(--color-text-tertiary)]">Repository health</span>
{HEALTH_MARK_BANDS.map((b, i) => (
diff --git a/packages/ui/src/workspace/system-map/system-map.tsx b/packages/ui/src/workspace/system-map/system-map.tsx
index dc1346bbf..70fa28c5f 100644
--- a/packages/ui/src/workspace/system-map/system-map.tsx
+++ b/packages/ui/src/workspace/system-map/system-map.tsx
@@ -35,7 +35,7 @@ import { SystemMapLegend } from "./system-map-legend";
import { SystemMapFilters } from "./system-map-filters";
import { SystemMapDrawer, type SystemMapDrawerData } from "./system-map-drawer";
import { SystemMapFocusContext, createSystemMapFocusStore } from "./system-map-focus";
-import { edgeKindStyle } from "./edge-kinds";
+import { edgeKindStyle, isGatewayRouted } from "./edge-kinds";
import { useSystemMapLayout } from "./use-system-map-layout";
import { resolveViewSelection } from "./system-map-model";
import { SYSTEM_MAP_MAX_LAYOUT_NODES, SYSTEM_MAP_NODE_SIZE, applyCollapse, type SystemMapView } from "./layout";
@@ -177,6 +177,7 @@ function SystemMapInner({
() => new Set<SystemEdgeMatchType>((viewGraph?.edges ?? []).map((e) => e.match_type)),
[viewGraph],
);
+ const gatewayRouted = useMemo(() => (viewGraph?.edges ?? []).filter(isGatewayRouted).length, [viewGraph]);
// Hover and selection for edges live outside React state (see system-map-focus).
const focus = useMemo(() => createSystemMapFocusStore(), []);
@@ -256,7 +257,7 @@ function SystemMapInner({
/>
</div>
- <SystemMapLegend matchTypes={matchTypes} />
+ <SystemMapLegend matchTypes={matchTypes} gatewayRouted={gatewayRouted} />
<div
ref={canvasRef}
diff --git a/packages/web/messages/en.json b/packages/web/messages/en.json
index d7768b933..d0bc7e20e 100644
--- a/packages/web/messages/en.json
+++ b/packages/web/messages/en.json
@@ -1841,12 +1841,14 @@
"title": "Services and relationships",
"description": "Each box is a service; each line is a contract, import or co-change between two of them. Pick a lens to ask the map one question at a time."
},
+ "evidence": {
+ "partial": "Partial evidence",
+ "insufficient": "Not determined"
+ },
"lede": {
"label": "Architecture score",
"labelHint": "A 1 to 10 roll-up of propagation cost, the size of the cyclic core, dependency cycles and rule violations, over structural edges only. Higher means less coupled.",
"unit": "out of 10",
- "notDetermined": "Not determined: {reason}.",
- "partialEvidence": "Partial evidence: {reason}.",
"counts": "{services, plural, one {# service} other {# services}} in {repos, plural, one {# repository} other {# repositories}}, joined by {relationships, plural, one {# relationship} other {# relationships}}: {structural} structural (a contract or import in code) and {behavioral} co-change (files that change in the same commits, not a call).",
"cycleMore": "{count, plural, one {# more cycle is} other {# more cycles are}} listed under Needs attention.",
"cycleOne": "It is listed under Needs attention with a prompt to break it.",
diff --git a/packages/web/messages/zh-CN.json b/packages/web/messages/zh-CN.json
index b549b2f23..9896a0704 100644
--- a/packages/web/messages/zh-CN.json
+++ b/packages/web/messages/zh-CN.json
@@ -1841,12 +1841,14 @@
"title": "服务与关系",
"description": "每个方块是一个服务;每条连线是两者之间的契约、导入或共同变更。选择一个视角,一次向这张图提一个问题。"
},
+ "evidence": {
+ "partial": "证据不完整",
+ "insufficient": "无法确定"
+ },
"lede": {
"label": "架构评分",
"labelHint": "对影响范围、循环核心规模、依赖循环与规则违反的 1 到 10 综合评分,仅统计结构边。分数越高表示耦合越低。",
"unit": "满分 10",
- "notDetermined": "无法确定:{reason}。",
- "partialEvidence": "证据不完整:{reason}。",
"counts": "{services} 个服务分布在 {repos} 个仓库中,由 {relationships} 条关系相连:{structural} 条结构关系(代码中的契约或导入)与 {behavioral} 条共同变更关系(在同一批提交中一起改动的文件,而非调用)。",
"cycleMore": "另有 {count} 个循环列在「需要注意」下。",
"cycleOne": "它列在「需要注意」下,并附有一段打破它的提示词。",
diff --git a/packages/web/src/app/workspace/system-map/page.tsx b/packages/web/src/app/workspace/system-map/page.tsx
index 9d48448b9..eae14f020 100644
--- a/packages/web/src/app/workspace/system-map/page.tsx
+++ b/packages/web/src/app/workspace/system-map/page.tsx
@@ -8,6 +8,7 @@ import { Waypoints } from "lucide-react";
import {
SystemMap,
SYSTEM_MAP_CANVAS_HEIGHT,
+ SystemMapEvidenceNotice,
SystemMapFindings,
SystemMapLensControl,
SystemMapLensResults,
@@ -209,6 +210,12 @@ export default function SystemMapPage() {
{graph && <StatRibbon stats={ribbon(t, tLinks, graph, architecture)} LinkComponent={Link} />}
<OverviewSection title={t("section.title")} description={t("section.description")}>
+ {/* Said once, beside the map it qualifies; the score above reads "–" when not determined. */}
+ <SystemMapEvidenceNotice
+ evidence={architecture?.evidence}
+ partialLabel={t("evidence.partial")}
+ insufficientLabel={t("evidence.insufficient")}
+ />
{isLoading ? (
// Same rows as the loaded map: lens, filters, legend, then the canvas.
<div className="flex flex-col gap-3" aria-hidden>
@@ -374,16 +381,6 @@ function Lede({
unit={t("lede.unit")}
layout="beside"
>
- {architecture?.evidence && architecture.evidence.state !== "measured" ? (
- <p>
- {t(
- architecture.evidence.state === "insufficient"
- ? "lede.notDetermined"
- : "lede.partialEvidence",
- { reason: architecture.evidence.summary },
- )}
- </p>
- ) : null}
<p>
{t("lede.counts", {
services: graph.nodes.length,