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(web): show how each cross-repo link was matched and where each contract came from (#4587)

Raghav Chamadiyafbf5e28a9843
diff --git a/packages/api-client/src/types/workspace.ts b/packages/api-client/src/types/workspace.ts
index 732962d37..17d77abdb 100644
--- a/packages/api-client/src/types/workspace.ts
+++ b/packages/api-client/src/types/workspace.ts
@@ -1,3 +1,5 @@
+import type { ContractOriginWire, LinkStrategyWire } from "@repowise-dev/types/workspace";
+
// ---------------------------------------------------------------------------
// Workspace
// ---------------------------------------------------------------------------
@@ -89,7 +91,7 @@ export interface WorkspaceContractEntry {
*/
symbol_id: string | null;
/** What established the contract (`route_registration`, `client_call`, ...). */
- origin?: string | null;
+ origin?: ContractOriginWire | null;
/**
* Extractor-supplied detail (`extraction_layer`, `framework`, `method`,
* `path`, `table`, `package`...). Keys vary by contract type.
@@ -102,7 +104,7 @@ export interface WorkspaceContractLinkEntry {
contract_type: string;
match_type: string;
/** The matching rule that made the link (`exact_id`, `binding_routed`, ...); `match_type` derives from it. */
- strategy?: string | null;
+ strategy?: LinkStrategyWire | null;
confidence: number;
provider_repo: string;
provider_file: string;
diff --git a/packages/types/src/workspace.ts b/packages/types/src/workspace.ts
index 512efe77f..4e10e2df7 100644
--- a/packages/types/src/workspace.ts
+++ b/packages/types/src/workspace.ts
@@ -32,12 +32,56 @@ export interface WorkspaceContractSummary {
by_type: Record<string, number>;
}
+/**
+ * How a cross-repo link was matched. Closed vocabulary owned by
+ * `core/workspace/origins.py::LinkStrategy`; the two are edited together.
+ * Render via `linkStrategyCopy` (`@repowise-dev/ui/workspace/link-provenance`).
+ */
+export type LinkStrategy =
+ | "exact_id"
+ | "pattern_matched"
+ | "binding_routed"
+ | "shared_table"
+ | "service_mapped"
+ | "host_only"
+ | "gateway_route"
+ | "unique_path"
+ | "ambiguous_path"
+ | "prefix_stripped"
+ | "manual"
+ | "manifest";
+
+/** A strategy as received: a newer index can stamp a value this build predates. */
+export type LinkStrategyWire = LinkStrategy | (string & {});
+
+/**
+ * What established a contract. Closed vocabulary owned by
+ * `core/workspace/origins.py::ContractOrigin`; the two are edited together.
+ * Render via `contractOriginCopy` (`@repowise-dev/ui/workspace/link-provenance`).
+ */
+export type ContractOrigin =
+ | "idl"
+ | "package_export"
+ | "route_registration"
+ | "typed_client"
+ | "ddl"
+ | "explicit_table"
+ | "client_call"
+ | "instance_base"
+ | "dataflow"
+ | "sql_string"
+ | "name_heuristic"
+ | "name_convention";
+
+/** An origin as received. See `LinkStrategyWire`. */
+export type ContractOriginWire = ContractOrigin | (string & {});
+
export interface WorkspaceContractLinkEntry {
contract_id: string;
contract_type: string;
match_type: string;
/** The matching rule that made the link (`exact_id`, `binding_routed`, ...); `match_type` derives from it. */
- strategy?: string | null;
+ strategy?: LinkStrategyWire | null;
confidence: number;
provider_repo: string;
provider_file: string;
@@ -147,7 +191,7 @@ export interface SystemEdge {
/** Back-pointers to the underlying evidence, for drill-down (bounded). */
contract_refs: string[];
/** Strategy of the link that gave the edge its confidence; null on a co-change edge. */
- strategy?: string | null;
+ strategy?: LinkStrategyWire | null;
}
export interface SystemGraph {
diff --git a/packages/ui/__tests__/workspace/contract-drawer.test.tsx b/packages/ui/__tests__/workspace/contract-drawer.test.tsx
index ecac1c13b..af84b3cfc 100644
--- a/packages/ui/__tests__/workspace/contract-drawer.test.tsx
+++ b/packages/ui/__tests__/workspace/contract-drawer.test.tsx
@@ -84,7 +84,7 @@ describe("ContractDrawer", () => {
it("renders the contract identity, role, location and how it was found", () => {
render(
<ContractDrawer
- contract={contract()}
+ contract={contract({ origin: "route_registration" })}
open
onOpenChange={() => {}}
fullPageHref="/workspace/contracts/detail?id=x"
@@ -99,6 +99,7 @@ describe("ContractDrawer", () => {
expect(screen.getByText("users.ts").parentElement?.textContent).toBe("src/routes/users.ts:42");
expect(screen.getByText("92%")).toBeInTheDocument();
expect(screen.getByText("fastapi")).toBeInTheDocument();
+ expect(screen.getByText("Framework registration")).toBeInTheDocument();
expect(screen.getByRole("button", { name: "AI prompt" })).toBeInTheDocument();
});
@@ -110,7 +111,7 @@ describe("ContractDrawer", () => {
contract={c}
open
onOpenChange={() => {}}
- links={linksForContract(c, [link()])}
+ links={linksForContract(c, [link({ strategy: "gateway_route" })])}
codeLinks={{
fileHref: (repo, file) => `/repos/${repo}/files/${file}`,
symbolHref: (repo, symbolId) => `/repos/${repo}/symbols/${symbolId}`,
@@ -129,6 +130,8 @@ describe("ContractDrawer", () => {
"/repos/web-app/symbols/src/api/users-client.ts::fetchUser",
);
expect(screen.getByText("fetchUser")).toBeInTheDocument();
+ // The counterpart says how it was matched, not just exact or candidate.
+ expect(screen.getByText("Routed through a gateway")).toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: /open the consumer in web-app/i }));
expect(onSelectContract).toHaveBeenCalledWith({
repo: "web-app",
diff --git a/packages/ui/__tests__/workspace/link-provenance.test.ts b/packages/ui/__tests__/workspace/link-provenance.test.ts
new file mode 100644
index 000000000..6977babe9
--- /dev/null
+++ b/packages/ui/__tests__/workspace/link-provenance.test.ts
@@ -0,0 +1,68 @@
+import { readFileSync } from "node:fs";
+import { join } from "node:path";
+import { describe, expect, it } from "vitest";
+import { contractOriginCopy, linkStrategyCopy } from "../../src/workspace/link-provenance.js";
+
+// Read the closed vocabularies from core itself, so a value added there without
+// a label here fails this test rather than rendering as a humanised token.
+const ORIGINS_PY = readFileSync(
+ join(__dirname, "../../../core/src/repowise/core/workspace/origins.py"),
+ "utf-8",
+).replace(/\r/g, "");
+
+function enumValues(className: string): string[] {
+ const body = ORIGINS_PY.split(`class ${className}(StrEnum):`)[1]?.split(/\n\S/)[0] ?? "";
+ return [...body.matchAll(/^\s+[A-Z_]+ = "([a-z_]+)"$/gm)].map((m) => m[1]!);
+}
+
+describe("link strategy copy", () => {
+ const strategies = enumValues("LinkStrategy");
+
+ it("reads every strategy core declares", () => {
+ expect(strategies).toContain("exact_id");
+ expect(strategies).toContain("gateway_route");
+ expect(strategies.length).toBeGreaterThanOrEqual(12);
+ });
+
+ it.each(strategies)("labels %s in its own words", (s) => {
+ const copy = linkStrategyCopy(s)!;
+ expect(copy.label).toBeTruthy();
+ expect(copy.meaning).not.toMatch(/does not describe/);
+ });
+
+ it("names the matches the drawers lead with", () => {
+ expect(linkStrategyCopy("unique_path")?.label).toBe("Matched by path only");
+ expect(linkStrategyCopy("gateway_route")?.label).toBe("Routed through a gateway");
+ expect(linkStrategyCopy("host_only")?.label).toBe("Host only");
+ });
+
+ it("humanises a strategy this build predates and never goes blank", () => {
+ expect(linkStrategyCopy("mesh_routed")).toEqual({
+ label: "Mesh routed",
+ meaning: "This version does not describe this matching rule.",
+ });
+ expect(linkStrategyCopy(null)).toBeNull();
+ expect(linkStrategyCopy("")).toBeNull();
+ });
+});
+
+describe("contract origin copy", () => {
+ const origins = enumValues("ContractOrigin");
+
+ it("reads every origin core declares", () => {
+ expect(origins).toContain("client_call");
+ expect(origins).toContain("dataflow");
+ expect(origins.length).toBeGreaterThanOrEqual(12);
+ });
+
+ it.each(origins)("labels %s in its own words", (o) => {
+ const copy = contractOriginCopy(o)!;
+ expect(copy.label).toBeTruthy();
+ expect(copy.meaning).not.toMatch(/does not describe/);
+ });
+
+ it("humanises an origin this build predates", () => {
+ expect(contractOriginCopy("build_script")?.label).toBe("Build script");
+ expect(contractOriginCopy(undefined)).toBeNull();
+ });
+});
diff --git a/packages/ui/__tests__/workspace/system-map-ai-prompt.test.ts b/packages/ui/__tests__/workspace/system-map-ai-prompt.test.ts
index 1afe25d5f..9a8463531 100644
--- a/packages/ui/__tests__/workspace/system-map-ai-prompt.test.ts
+++ b/packages/ui/__tests__/workspace/system-map-ai-prompt.test.ts
@@ -188,9 +188,10 @@ describe("system map AI prompts", () => {
provider_file: "app/r.py",
consumer_repo: "frontend",
consumer_file: "src/client.ts",
+ strategy: i === 0 ? "unique_path" : null,
}));
const text = buildEdgeAiPrompt({
- edge: { id: "frontend->backend:http", kind: "http", match_type: "exact", confidence: 0.85, weight: 180, structural: true },
+ edge: { id: "frontend->backend:http", kind: "http", match_type: "exact", strategy: "service_mapped", confidence: 0.85, weight: 180, structural: true },
source: { id: "frontend", name: "frontend" },
target: { id: "backend", name: "backend" },
sentence: "frontend calls backend over HTTP.",
@@ -200,8 +201,11 @@ describe("system map AI prompts", () => {
flavor: "generic",
});
expect(text).toContain("frontend calls backend over HTTP.");
- expect(text).toContain("Confidence: 85%");
- expect(text).toContain("provider `backend:app/r.py`, consumer `frontend:src/client.ts`");
+ expect(text).toContain("Match: exact, matched by service name (`service_mapped`). Confidence: 85%");
+ expect(text).toContain(
+ "- `http::GET::/r0`: provider `backend:app/r.py`, consumer `frontend:src/client.ts`, matched by path only (`unique_path`)",
+ );
+ expect(text).toContain("- `http::GET::/r1`: provider `backend:app/r.py`, consumer `frontend:src/client.ts`\n");
expect(text).toContain("...and 3 more links not listed here.");
expect(text).not.toContain("get_blast_radius");
});
diff --git a/packages/ui/package.json b/packages/ui/package.json
index b1dddc011..3cc79b080 100644
--- a/packages/ui/package.json
+++ b/packages/ui/package.json
@@ -84,6 +84,7 @@
"./workspace/contract-ai-prompt": "./src/workspace/contract-ai-prompt.ts",
"./workspace/contract-facts": "./src/workspace/contract-facts.ts",
"./workspace/contract-type-label": "./src/workspace/contract-type-label.ts",
+ "./workspace/link-provenance": "./src/workspace/link-provenance.ts",
"./workspace/system-map": "./src/workspace/system-map/index.ts",
"./workspace/dsm": "./src/workspace/dsm/index.ts",
"./workspace/*": "./src/workspace/*.tsx",
diff --git a/packages/ui/src/workspace/contract-drawer.tsx b/packages/ui/src/workspace/contract-drawer.tsx
index 3225b036a..4318477e7 100644
--- a/packages/ui/src/workspace/contract-drawer.tsx
+++ b/packages/ui/src/workspace/contract-drawer.tsx
@@ -36,6 +36,7 @@ import { FilePath } from "../shared/file-path";
import { ContractPromptButton } from "./contract-prompt-button";
import { ContractTestsSection } from "./contract-tests-section";
import { contractTypeLabel } from "./contract-type-label";
+import { contractOriginCopy, linkStrategyCopy } from "./link-provenance";
import {
contractLede,
contractMetaEntries,
@@ -186,6 +187,7 @@ function Body({
? (codeLinks?.symbolHref?.(contract.repo, contract.symbol_id) ?? null)
: null;
const metaEntries = contractMetaEntries(contract.meta);
+ const origin = contractOriginCopy(contract.origin);
return (
<>
@@ -301,6 +303,12 @@ function Body({
<Section title="How it was found">
<Facts>
+ {origin ? (
+ <Fact label="Found by">
+ {origin.label}
+ <span className="block text-[var(--color-text-tertiary)]">{origin.meaning}</span>
+ </Fact>
+ ) : null}
<Fact label="Confidence">
<span className="font-mono text-xs tabular-nums">
{Math.round(contract.confidence * 100)}%
@@ -428,6 +436,7 @@ function CounterpartRow({
side === "provider" ? link.provider_file : link.consumer_file,
);
const symbolId = side === "provider" ? link.provider_symbol_id : link.consumer_symbol_id;
+ const strategy = linkStrategyCopy(link.strategy);
// A consumer bound through another name (a queue on an exchange) keeps its own id.
const id = side === "consumer" ? (link.consumer_contract_id ?? link.contract_id) : link.contract_id;
const codeHref =
@@ -452,7 +461,7 @@ function CounterpartRow({
</span>
) : null}
<span className="block text-[10px] text-[var(--color-text-tertiary)]">
- {link.match_type} match,{" "}
+ {strategy ? <span title={strategy.meaning}>{strategy.label}</span> : `${link.match_type} match`},{" "}
<span className="font-mono tabular-nums">{Math.round(link.confidence * 100)}%</span>
</span>
</>
diff --git a/packages/ui/src/workspace/contract-facts.ts b/packages/ui/src/workspace/contract-facts.ts
index f7fe7aa58..e8b9b9f67 100644
--- a/packages/ui/src/workspace/contract-facts.ts
+++ b/packages/ui/src/workspace/contract-facts.ts
@@ -26,6 +26,8 @@ export interface ContractEntry {
service: string | null;
line: number | null;
symbol_id: string | null;
+ /** What established the contract; absent on a row stored before origins. */
+ origin?: string | null;
meta: Record<string, unknown>;
}
diff --git a/packages/ui/src/workspace/index.ts b/packages/ui/src/workspace/index.ts
index e40495732..004cf7abe 100644
--- a/packages/ui/src/workspace/index.ts
+++ b/packages/ui/src/workspace/index.ts
@@ -14,6 +14,7 @@ export * from "./contract-prompt-button";
export * from "./contract-tests-section";
export * from "./contract-type-badge";
export * from "./cross-repo-summary";
+export * from "./link-provenance";
export * from "./package-deps-table";
export * from "./repo-card";
export * from "./repo-card-compact";
diff --git a/packages/ui/src/workspace/link-provenance.ts b/packages/ui/src/workspace/link-provenance.ts
new file mode 100644
index 000000000..f8d678a77
--- /dev/null
+++ b/packages/ui/src/workspace/link-provenance.ts
@@ -0,0 +1,152 @@
+/**
+ * How a cross-repo link was matched and how a contract was found, in words a
+ * reader can act on.
+ *
+ * The only place the workspace layer's two closed vocabularies, link
+ * `strategy` and contract `origin` (`core/workspace/origins.py`), become
+ * English, so the drawers, tables and prompts describe one link the same way.
+ * Server-safe and pure: no React, module-scope lookups.
+ */
+
+import type { ContractOrigin, LinkStrategy } from "@repowise-dev/types/workspace";
+
+export interface ProvenanceCopy {
+ /** Terse, for a row or a fact. Sentence case, no trailing period. */
+ label: string;
+ /** One sentence naming the evidence. */
+ meaning: string;
+}
+
+/** `satisfies` fails the build when core adds a strategy and nobody words it. */
+const STRATEGIES = {
+ exact_id: {
+ label: "Matched by exact name",
+ meaning: "Both sides name the same route, topic, table or service.",
+ },
+ pattern_matched: {
+ label: "Matched by subscription pattern",
+ meaning: "The consumer subscribes to a pattern, such as orders.*, that covers the provider's name.",
+ },
+ binding_routed: {
+ label: "Routed through a queue binding",
+ meaning:
+ "The consumer's queue is bound to the exchange the provider publishes to, with a routing key it receives.",
+ },
+ shared_table: {
+ label: "Shares a table",
+ meaning: "One service only models the table; the other service's schema defines it.",
+ },
+ service_mapped: {
+ label: "Matched by service name",
+ meaning: "The call's host or base URL names the providing service, and that service serves the path.",
+ },
+ host_only: {
+ label: "Host only",
+ meaning:
+ "The call's host names this service, but no route there serves its path. A service-level dependency, not a route link.",
+ },
+ gateway_route: {
+ label: "Routed through a gateway",
+ meaning: "A gateway's config forwards this path prefix to the service.",
+ },
+ unique_path: {
+ label: "Matched by path only",
+ meaning: "The call's base URL was not read, and exactly one service serves the path.",
+ },
+ ambiguous_path: {
+ label: "Path served by several services",
+ meaning:
+ "The call's base URL was not read, and several services serve the path, so it is linked to each. Verify before relying on it.",
+ },
+ prefix_stripped: {
+ label: "Matched after stripping a prefix",
+ meaning: "The paths match only after removing a mount, version or base prefix. Verify before relying on it.",
+ },
+ manual: {
+ label: "Declared by hand",
+ meaning: "Declared in the workspace config.",
+ },
+ manifest: {
+ label: "Declared in a manifest",
+ meaning: "A package manifest declares the dependency.",
+ },
+} as const satisfies Record<LinkStrategy, ProvenanceCopy>;
+
+const ORIGINS = {
+ idl: {
+ label: "Schema document",
+ meaning: "An OpenAPI or proto document declares the operation.",
+ },
+ package_export: {
+ label: "Package export",
+ meaning: "A published package exports the symbol another repo imports.",
+ },
+ route_registration: {
+ label: "Framework registration",
+ meaning: "A framework registers the route, handler, server or hub in code.",
+ },
+ typed_client: {
+ label: "Typed client",
+ meaning: "The symbol index types the receiver as an HTTP client.",
+ },
+ ddl: {
+ label: "Schema migration",
+ meaning: "SQL DDL or a migration creates or alters the table.",
+ },
+ explicit_table: {
+ label: "Named table",
+ meaning: "An ORM model names its table explicitly.",
+ },
+ client_call: {
+ label: "Client call",
+ meaning: "A known client, broker, socket or query-builder call names the destination.",
+ },
+ instance_base: {
+ label: "Client base URL",
+ meaning: "A call on a client instance whose base URL the file reads.",
+ },
+ dataflow: {
+ label: "Traced value",
+ meaning: "The destination was traced across statements to the call.",
+ },
+ sql_string: {
+ label: "SQL in a string",
+ meaning: "A table named inside SQL text in a string.",
+ },
+ name_heuristic: {
+ label: "Name only",
+ meaning: "Only the callee or receiver name says this is a client call.",
+ },
+ name_convention: {
+ label: "Naming convention",
+ meaning: "Derived from a naming convention, such as an ORM's default table name or a unique short type name.",
+ },
+} as const satisfies Record<ContractOrigin, ProvenanceCopy>;
+
+/** `some_new_rule` -> `Some new rule`, so a value this build predates still reads. */
+function humanise(token: string): string {
+ const words = token.replace(/[_-]+/g, " ").trim();
+ return words ? words[0]!.toUpperCase() + words.slice(1) : token;
+}
+
+/** Describe a link strategy. Null only when the link carries none. */
+export function linkStrategyCopy(strategy: string | null | undefined): ProvenanceCopy | null {
+ if (!strategy) return null;
+ return (
+ (STRATEGIES as Record<string, ProvenanceCopy>)[strategy] ?? {
+ label: humanise(strategy),
+ meaning: "This version does not describe this matching rule.",
+ }
+ );
+}
+
+/** Describe a contract origin. Null only when the contract carries none. */
+export function contractOriginCopy(origin: string | null | undefined): ProvenanceCopy | null {
+ if (!origin) return null;
+ return (
+ (ORIGINS as Record<string, ProvenanceCopy>)[origin] ?? {
+ label: humanise(origin),
+ meaning: "This version does not describe how this contract was found.",
+ }
+ );
+}
diff --git a/packages/ui/src/workspace/system-map/system-map-ai-prompt.ts b/packages/ui/src/workspace/system-map/system-map-ai-prompt.ts
index 853bf7f61..223552c75 100644
--- a/packages/ui/src/workspace/system-map/system-map-ai-prompt.ts
+++ b/packages/ui/src/workspace/system-map/system-map-ai-prompt.ts
@@ -18,6 +18,7 @@ import {
type AiPromptFlavor,
type PreambleParts,
} from "../../health/ai-prompts/shared";
+import { linkStrategyCopy } from "../link-provenance";
/** Evidence rows listed in full before the prompt says how many it left out. */
export const SYSTEM_MAP_PROMPT_MAX_ROWS = 25;
@@ -160,6 +161,8 @@ export interface PromptEdgeEvidence {
consumer_repo: string;
consumer_file: string;
match_type?: string;
+ /** The matching rule that made the link, a core `LinkStrategy` value. */
+ strategy?: string | null;
confidence?: number;
}
@@ -168,6 +171,8 @@ export interface BuildEdgePromptOptions {
id: string;
kind: string;
match_type: string;
+ /** Strategy of the link that gave the edge its confidence. */
+ strategy?: string | null;
confidence: number;
weight: number;
structural: boolean;
@@ -188,6 +193,12 @@ export interface BuildEdgePromptOptions {
flavor?: AiPromptFlavor;
}
+/** `, matched by service name (service_mapped)`, or nothing when the link names no strategy. */
+function matchedBy(strategy: string | null | undefined): string {
+ const copy = linkStrategyCopy(strategy);
+ return copy ? `, ${copy.label.toLowerCase()} (\`${strategy}\`)` : "";
+}
+
export function buildEdgeAiPrompt(o: BuildEdgePromptOptions): string {
const flavor = o.flavor ?? "generic";
const e = o.edge;
@@ -196,7 +207,7 @@ export function buildEdgeAiPrompt(o: BuildEdgePromptOptions): string {
? capped(
o.evidence,
(l) =>
- `- \`${l.contract_id}\`: provider \`${l.provider_repo}:${l.provider_file}\`, consumer \`${l.consumer_repo}:${l.consumer_file}\``,
+ `- \`${l.contract_id}\`: provider \`${l.provider_repo}:${l.provider_file}\`, consumer \`${l.consumer_repo}:${l.consumer_file}\`${matchedBy(l.strategy)}`,
"links",
)
: o.refs.length > 0
@@ -215,7 +226,7 @@ export function buildEdgeAiPrompt(o: BuildEdgePromptOptions): string {
`\n## Relationship: ${o.source.name} -> ${o.target.name} (\`${e.id}\`)`,
`\n${bulletList([
o.sentence,
- `Kind: ${e.kind}. Match: ${e.match_type}. Confidence: ${Math.round(e.confidence * 100)}%.`,
+ `Kind: ${e.kind}. Match: ${e.match_type}${matchedBy(e.strategy)}. Confidence: ${Math.round(e.confidence * 100)}%.`,
`Weight: ${o.weightLabel}.`,
e.structural
? "Structural: built from a contract or import in code. Changing the provider side can break the consumer."
diff --git a/packages/ui/src/workspace/system-map/system-map-drawer.tsx b/packages/ui/src/workspace/system-map/system-map-drawer.tsx
index bffa6d5d1..a852df935 100644
--- a/packages/ui/src/workspace/system-map/system-map-drawer.tsx
+++ b/packages/ui/src/workspace/system-map/system-map-drawer.tsx
@@ -27,6 +27,7 @@ import { FilePath } from "../../shared/file-path";
import { AiPromptButton } from "../../health/ai-prompt-button";
import { AiPromptModal } from "../../health/ai-prompt-modal";
import type { AiPromptFlavor } from "../../health/ai-prompt-builder";
+import { linkStrategyCopy } from "../link-provenance";
import { roleStyle } from "./architecture";
import { edgeKindStyle, matchTypeLabel } from "./edge-kinds";
import { nodeKindStyle } from "./node-kinds";
@@ -594,6 +595,7 @@ function EdgeBody({
const sourceName = source?.name ?? edge.source;
const targetName = target?.name ?? edge.target;
const sentence = edgeSentence(edge, sourceName, targetName);
+ const strategy = linkStrategyCopy(edge.strategy);
const links = useMemo<WorkspaceContractLinkEntry[] | null>(
() => (repoContracts && edge.structural ? edgeLinks(edge, repoContracts.links, resolve) : null),
@@ -653,7 +655,14 @@ function EdgeBody({
value: (
<span title={MATCH_MEANING[edge.match_type]}>
{matchTypeLabel(edge.match_type)}
- <span className="block text-xs text-[var(--color-text-tertiary)]">{MATCH_MEANING[edge.match_type]}</span>
+ {/* How the strongest link was matched, when the edge says; the
+ exact / candidate meaning otherwise. */}
+ {strategy ? (
+ <span className="block text-xs text-[var(--color-text-secondary)]">{strategy.label}</span>
+ ) : null}
+ <span className="block text-xs text-[var(--color-text-tertiary)]">
+ {strategy?.meaning ?? MATCH_MEANING[edge.match_type]}
+ </span>
</span>
),
},
@@ -730,6 +739,14 @@ function EdgeBody({
calls from{" "}
<FilePath path={`${l.consumer_repo}/${l.consumer_file}`} mode="full" className="text-[10px]" />
</span>
+ {l.strategy ? (
+ <span
+ className="text-[10px] text-[var(--color-text-tertiary)]"
+ title={linkStrategyCopy(l.strategy)?.meaning}
+ >
+ {linkStrategyCopy(l.strategy)?.label}
+ </span>
+ ) : null}
</li>
))}
</ul>
diff --git a/packages/web/messages/en.json b/packages/web/messages/en.json
index bed14a3a0..21b59d334 100644
--- a/packages/web/messages/en.json
+++ b/packages/web/messages/en.json
@@ -1721,6 +1721,20 @@
"col": {
"match": "Match"
},
+ "strategy": {
+ "exact_id": "Matched by exact name",
+ "pattern_matched": "Matched by subscription pattern",
+ "binding_routed": "Routed through a queue binding",
+ "shared_table": "Shares a table",
+ "service_mapped": "Matched by service name",
+ "host_only": "Host only",
+ "gateway_route": "Routed through a gateway",
+ "unique_path": "Matched by path only",
+ "ambiguous_path": "Path served by several services",
+ "prefix_stripped": "Matched after stripping a prefix",
+ "manual": "Declared by hand",
+ "manifest": "Declared in a manifest"
+ },
"reasonTitle": {
"no_provider": "No provider found",
"unlinked": "No link formed",
diff --git a/packages/web/messages/zh-CN.json b/packages/web/messages/zh-CN.json
index 6db5f791a..b7a8651b3 100644
--- a/packages/web/messages/zh-CN.json
+++ b/packages/web/messages/zh-CN.json
@@ -1721,6 +1721,20 @@
"col": {
"match": "匹配方式"
},
+ "strategy": {
+ "exact_id": "按名称精确匹配",
+ "pattern_matched": "按订阅模式匹配",
+ "binding_routed": "经队列绑定路由",
+ "shared_table": "共享数据表",
+ "service_mapped": "按服务名匹配",
+ "host_only": "仅主机",
+ "gateway_route": "经网关路由",
+ "unique_path": "仅按路径匹配",
+ "ambiguous_path": "路径由多个服务提供",
+ "prefix_stripped": "去除前缀后匹配",
+ "manual": "手动声明",
+ "manifest": "在清单中声明"
+ },
"reasonTitle": {
"no_provider": "未找到提供方",
"unlinked": "未建立链接",
diff --git a/packages/web/src/app/workspace/contracts/detail/contract-body.tsx b/packages/web/src/app/workspace/contracts/detail/contract-body.tsx
index 377de2358..cf2a7e9e9 100644
--- a/packages/web/src/app/workspace/contracts/detail/contract-body.tsx
+++ b/packages/web/src/app/workspace/contracts/detail/contract-body.tsx
@@ -12,6 +12,7 @@ import type {
WorkspaceTestImpactResponse,
} from "@repowise-dev/types/workspace";
import { contractTypeLabel } from "@repowise-dev/ui/workspace/contract-type-label";
+import { linkStrategyCopy } from "@repowise-dev/ui/workspace/link-provenance";
import { ContractTestsSection } from "@repowise-dev/ui/workspace/contract-tests-section";
import {
asContractSchema,
@@ -301,6 +302,12 @@ async function LinkTable({
repoIds: Record<string, string>;
}) {
const t = await getTranslations("contracts");
+ // A strategy this build predates reads as its humanised token; a link stored
+ // before strategies reads as its match type.
+ const strategyLabel = (link: WorkspaceContractLinkEntry) =>
+ link.strategy && t.has(`detail.strategy.${link.strategy}`)
+ ? t(`detail.strategy.${link.strategy}`)
+ : (linkStrategyCopy(link.strategy)?.label ?? link.match_type);
// A local table rather than `ContractLinksTable`: that one leads with the
// contract id and its type, and on this page both of those are the heading.
// What is left to say is the other side of each link.
@@ -356,7 +363,7 @@ async function LinkTable({
</Td>
<Td className="max-lg:hidden">
<span className="text-xs text-[var(--color-text-secondary)]">
- {link.match_type}
+ {strategyLabel(link)}
</span>
</Td>
<Td className="max-lg:hidden">