Skip to content

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.

Add multi-galaxy UI layout and cross-repo architecture summary

testb6eefe014c3d
diff --git a/graph-ui/src/components/EdgeLines.tsx b/graph-ui/src/components/EdgeLines.tsx
index bd321c6bd..4001b9d28 100644
--- a/graph-ui/src/components/EdgeLines.tsx
+++ b/graph-ui/src/components/EdgeLines.tsx
@@ -6,6 +6,7 @@ interface EdgeLinesProps {
nodes: GraphNode[];
edges: GraphEdge[];
highlightedIds: Set<number> | null;
+ opacity?: number;
}
function getClusterKey(fp?: string): string {
@@ -33,7 +34,7 @@ const EDGE_TYPE_COLORS: Record<string, string> = {
const DEFAULT_EDGE_COLOR = "#1C8585";
-export function EdgeLines({ nodes, edges, highlightedIds }: EdgeLinesProps) {
+export function EdgeLines({ nodes, edges, highlightedIds, opacity = 1.0 }: EdgeLinesProps) {
const geometry = useMemo(() => {
const idMap = new Map<number, number>();
for (let i = 0; i < nodes.length; i++) {
@@ -105,7 +106,7 @@ export function EdgeLines({ nodes, edges, highlightedIds }: EdgeLinesProps) {
<lineBasicMaterial
vertexColors
transparent
- opacity={1}
+ opacity={opacity}
blending={THREE.AdditiveBlending}
depthWrite={false}
toneMapped={false}
diff --git a/graph-ui/src/components/GraphScene.tsx b/graph-ui/src/components/GraphScene.tsx
index c82a96f91..50055fbd3 100644
--- a/graph-ui/src/components/GraphScene.tsx
+++ b/graph-ui/src/components/GraphScene.tsx
@@ -8,7 +8,7 @@ import { NodeCloud } from "./NodeCloud";
import { EdgeLines } from "./EdgeLines";
import { NodeLabels } from "./NodeLabels";
import { NodeTooltip } from "./NodeTooltip";
-import type { GraphData, GraphNode } from "../lib/types";
+import type { GraphData, GraphNode, LinkedProject } from "../lib/types";
/* ── Camera fly-to animation ────────────────────────────── */
@@ -133,6 +133,33 @@ export function GraphScene({
/>
{showLabels && <NodeLabels nodes={data.nodes} highlightedIds={highlightedIds} />}
+ {/* Satellite galaxies for cross-repo linked projects */}
+ {data.linked_projects?.map((lp: LinkedProject) => {
+ const offsetNodes = lp.nodes.map((n) => ({
+ ...n,
+ x: n.x + lp.offset.x,
+ y: n.y + lp.offset.y,
+ z: n.z + lp.offset.z,
+ }));
+ return (
+ <group key={lp.project}>
+ <EdgeLines
+ nodes={offsetNodes}
+ edges={lp.edges}
+ highlightedIds={null}
+ opacity={0.3}
+ />
+ <NodeCloud
+ nodes={offsetNodes}
+ highlightedIds={null}
+ onHover={setHovered}
+ onClick={onNodeClick}
+ opacity={0.5}
+ />
+ </group>
+ );
+ })}
+
{hovered && <NodeTooltip node={hovered} />}
<CameraAnimator target={cameraTarget} />
diff --git a/graph-ui/src/components/NodeCloud.tsx b/graph-ui/src/components/NodeCloud.tsx
index f047cf4a5..e5465b8f2 100644
--- a/graph-ui/src/components/NodeCloud.tsx
+++ b/graph-ui/src/components/NodeCloud.tsx
@@ -8,6 +8,7 @@ interface NodeCloudProps {
highlightedIds: Set<number> | null;
onHover: (node: GraphNode | null) => void;
onClick: (node: GraphNode) => void;
+ opacity?: number;
}
export function NodeCloud({
@@ -15,6 +16,7 @@ export function NodeCloud({
highlightedIds,
onHover,
onClick,
+ opacity = 1.0,
}: NodeCloudProps) {
const meshRef = useRef<THREE.InstancedMesh>(null);
const tempObj = useMemo(() => new THREE.Object3D(), []);
@@ -36,12 +38,12 @@ export function NodeCloud({
const boost = 1.2 + brightness * 0.8; /* 1.2x for red, 2.0x for white */
tempColor.multiplyScalar(boost);
}
- arr[i * 3] = tempColor.r;
- arr[i * 3 + 1] = tempColor.g;
- arr[i * 3 + 2] = tempColor.b;
+ arr[i * 3] = tempColor.r * opacity;
+ arr[i * 3 + 1] = tempColor.g * opacity;
+ arr[i * 3 + 2] = tempColor.b * opacity;
}
return arr;
- }, [nodes, highlightedIds, tempColor]);
+ }, [nodes, highlightedIds, tempColor, opacity]);
useFrame(() => {
const mesh = meshRef.current;
diff --git a/graph-ui/src/lib/types.ts b/graph-ui/src/lib/types.ts
index 39ba3279d..0286a35b5 100644
--- a/graph-ui/src/lib/types.ts
+++ b/graph-ui/src/lib/types.ts
@@ -18,10 +18,19 @@ export interface GraphEdge {
type: string;
}
+export interface LinkedProject {
+ project: string;
+ nodes: GraphNode[];
+ edges: GraphEdge[];
+ offset: { x: number; y: number; z: number };
+ cross_edges: GraphEdge[];
+}
+
export interface GraphData {
nodes: GraphNode[];
edges: GraphEdge[];
total_nodes: number;
+ linked_projects?: LinkedProject[];
}
export interface Project {
diff --git a/src/mcp/mcp.c b/src/mcp/mcp.c
index 7ee6f34b9..0430bdfbc 100644
--- a/src/mcp/mcp.c
+++ b/src/mcp/mcp.c
@@ -1668,6 +1668,32 @@ static bool aspect_wanted(yyjson_doc *aspects_doc, yyjson_val *aspects_arr, cons
return false;
}
+/* Append cross_repo_links summary to architecture JSON if CROSS_* edges exist. */
+static void append_cross_repo_summary(yyjson_mut_doc *doc, yyjson_mut_val *root,
+ const cbm_schema_info_t *schema) {
+ int cross_http = 0;
+ int cross_async = 0;
+ int cross_channel = 0;
+ for (int i = 0; i < schema->edge_type_count; i++) {
+ if (strcmp(schema->edge_types[i].type, "CROSS_HTTP_CALLS") == 0) {
+ cross_http = schema->edge_types[i].count;
+ } else if (strcmp(schema->edge_types[i].type, "CROSS_ASYNC_CALLS") == 0) {
+ cross_async = schema->edge_types[i].count;
+ } else if (strcmp(schema->edge_types[i].type, "CROSS_CHANNEL") == 0) {
+ cross_channel = schema->edge_types[i].count;
+ }
+ }
+ int cross_total = cross_http + cross_async + cross_channel;
+ if (cross_total > 0) {
+ yyjson_mut_val *cr = yyjson_mut_obj(doc);
+ yyjson_mut_obj_add_int(doc, cr, "cross_http_calls", cross_http);
+ yyjson_mut_obj_add_int(doc, cr, "cross_async_calls", cross_async);
+ yyjson_mut_obj_add_int(doc, cr, "cross_channel", cross_channel);
+ yyjson_mut_obj_add_int(doc, cr, "total", cross_total);
+ yyjson_mut_obj_add_val(doc, root, "cross_repo_links", cr);
+ }
+}
+
static char *handle_get_architecture(cbm_mcp_server_t *srv, const char *args) {
char *project = cbm_mcp_get_string_arg(args, "project");
cbm_store_t *store = resolve_store(srv, project);
@@ -1744,6 +1770,8 @@ static char *handle_get_architecture(cbm_mcp_server_t *srv, const char *args) {
yyjson_mut_obj_add_val(doc, root, "relationship_patterns", pats);
}
+ append_cross_repo_summary(doc, root, &schema);
+
char *json = yy_doc_to_str(doc);
yyjson_mut_doc_free(doc);
cbm_store_schema_free(&schema);
diff --git a/src/ui/http_server.c b/src/ui/http_server.c
index 053f317ba..d3efc53aa 100644
--- a/src/ui/http_server.c
+++ b/src/ui/http_server.c
@@ -23,8 +23,10 @@
#include "foundation/compat_thread.h"
#include <mongoose/mongoose.h>
+#include <sqlite3/sqlite3.h>
#include <yyjson/yyjson.h>
+#include <math.h>
#include <stdatomic.h>
#include <stdio.h>
#include <stdlib.h>
@@ -890,6 +892,41 @@ static bool get_query_param(struct mg_str query, const char *name, char *buf, in
/* ── Handle GET /api/layout ───────────────────────────────────── */
+/* Find distinct target_project values from CROSS_* edges in a store.
+ * Writes up to max_out project names (heap-allocated). Returns count. */
+static int find_cross_repo_targets(cbm_store_t *store, const char *project, char **out,
+ int max_out) {
+ struct sqlite3 *db = cbm_store_get_db(store);
+ if (!db) {
+ return 0;
+ }
+ sqlite3_stmt *s = NULL;
+ if (sqlite3_prepare_v2(
+ db,
+ "SELECT DISTINCT json_extract(properties, '$.target_project') FROM edges "
+ "WHERE project = ?1 AND type LIKE 'CROSS_%' "
+ "AND json_extract(properties, '$.target_project') IS NOT NULL",
+ -1, &s, NULL) != SQLITE_OK) {
+ return 0;
+ }
+ sqlite3_bind_text(s, 1, project, -1, SQLITE_STATIC);
+ int count = 0;
+ while (sqlite3_step(s) == SQLITE_ROW && count < max_out) {
+ const char *tp = (const char *)sqlite3_column_text(s, 0);
+ if (tp && tp[0]) {
+ size_t len = strlen(tp);
+ out[count] = malloc(len + 1);
+ memcpy(out[count], tp, len + 1);
+ count++;
+ }
+ }
+ sqlite3_finalize(s);
+ return count;
+}
+
+enum { LAYOUT_MAX_LINKED = 16 };
+#define LAYOUT_GALAXY_SPACING 600.0
+
static void handle_layout(struct mg_connection *c, struct mg_http_message *hm) {
char project[256] = {0};
char max_str[32] = {0};
@@ -907,7 +944,6 @@ static void handle_layout(struct mg_connection *c, struct mg_http_message *hm) {
max_nodes = v;
}
- /* Open a read-only store for this project */
char db_path[1024];
db_path_for_project(project, db_path, sizeof(db_path));
@@ -924,6 +960,11 @@ static void handle_layout(struct mg_connection *c, struct mg_http_message *hm) {
cbm_layout_result_t *layout =
cbm_layout_compute(store, project, CBM_LAYOUT_OVERVIEW, NULL, 0, max_nodes);
+
+ /* Find linked projects from CROSS_* edges */
+ char *linked[LAYOUT_MAX_LINKED];
+ int linked_count = find_cross_repo_targets(store, project, linked, LAYOUT_MAX_LINKED);
+
cbm_store_close(store);
if (!layout) {
@@ -931,16 +972,118 @@ static void handle_layout(struct mg_connection *c, struct mg_http_message *hm) {
return;
}
- char *json = cbm_layout_to_json(layout);
+ /* Build JSON: primary layout + linked_projects */
+ char *primary_json = cbm_layout_to_json(layout);
cbm_layout_free(layout);
-
- if (!json) {
+ if (!primary_json) {
mg_http_reply(c, 500, g_cors_json, "{\"error\":\"JSON serialization failed\"}");
return;
}
- mg_http_reply(c, 200, g_cors_json, "%s", json);
- free(json);
+ if (linked_count == 0) {
+ mg_http_reply(c, 200, g_cors_json, "%s", primary_json);
+ free(primary_json);
+ return;
+ }
+
+ /* Parse primary JSON and append linked_projects array */
+ yyjson_doc *pdoc = yyjson_read(primary_json, strlen(primary_json), 0);
+ free(primary_json);
+ if (!pdoc) {
+ mg_http_reply(c, 500, g_cors_json, "{\"error\":\"JSON parse failed\"}");
+ return;
+ }
+
+ yyjson_mut_doc *mdoc = yyjson_doc_mut_copy(pdoc, NULL);
+ yyjson_doc_free(pdoc);
+ yyjson_mut_val *mroot = yyjson_mut_doc_get_root(mdoc);
+
+ yyjson_mut_val *lp_arr = yyjson_mut_arr(mdoc);
+
+ for (int li = 0; li < linked_count; li++) {
+ char lp_path[1024];
+ db_path_for_project(linked[li], lp_path, sizeof(lp_path));
+ if (!cbm_file_exists(lp_path)) {
+ free(linked[li]);
+ continue;
+ }
+
+ cbm_store_t *lp_store = cbm_store_open_path(lp_path);
+ if (!lp_store) {
+ free(linked[li]);
+ continue;
+ }
+
+ cbm_layout_result_t *lp_layout =
+ cbm_layout_compute(lp_store, linked[li], CBM_LAYOUT_OVERVIEW, NULL, 0, max_nodes);
+ cbm_store_close(lp_store);
+
+ if (!lp_layout) {
+ free(linked[li]);
+ continue;
+ }
+
+ char *lp_json = cbm_layout_to_json(lp_layout);
+ cbm_layout_free(lp_layout);
+ if (!lp_json) {
+ free(linked[li]);
+ continue;
+ }
+
+ /* Parse linked project layout */
+ yyjson_doc *lpdoc = yyjson_read(lp_json, strlen(lp_json), 0);
+ free(lp_json);
+ if (!lpdoc) {
+ free(linked[li]);
+ continue;
+ }
+
+ yyjson_mut_doc *lm = yyjson_doc_mut_copy(lpdoc, NULL);
+ yyjson_doc_free(lpdoc);
+ yyjson_mut_val *lmroot = yyjson_mut_doc_get_root(lm);
+
+ /* Build linked project entry */
+ yyjson_mut_val *entry = yyjson_mut_obj(mdoc);
+ yyjson_mut_obj_add_strcpy(mdoc, entry, "project", linked[li]);
+
+ /* Copy nodes and edges from linked layout */
+ yyjson_mut_val *ln = yyjson_mut_obj_get(lmroot, "nodes");
+ yyjson_mut_val *le = yyjson_mut_obj_get(lmroot, "edges");
+ if (ln) {
+ yyjson_mut_obj_add_val(mdoc, entry, "nodes", yyjson_mut_val_mut_copy(mdoc, ln));
+ }
+ if (le) {
+ yyjson_mut_obj_add_val(mdoc, entry, "edges", yyjson_mut_val_mut_copy(mdoc, le));
+ }
+
+ /* Compute galaxy offset: evenly spaced around primary */
+ double angle = (2.0 * 3.14159265358979) * (double)li / (double)linked_count;
+ yyjson_mut_val *offset = yyjson_mut_obj(mdoc);
+ yyjson_mut_obj_add_real(mdoc, offset, "x", cos(angle) * LAYOUT_GALAXY_SPACING);
+ yyjson_mut_obj_add_real(mdoc, offset, "y", sin(angle) * LAYOUT_GALAXY_SPACING);
+ yyjson_mut_obj_add_real(mdoc, offset, "z", 0.0);
+ yyjson_mut_obj_add_val(mdoc, entry, "offset", offset);
+
+ /* TODO: cross_edges array with CROSS_* edges connecting the galaxies */
+ yyjson_mut_obj_add_val(mdoc, entry, "cross_edges", yyjson_mut_arr(mdoc));
+
+ yyjson_mut_arr_append(lp_arr, entry);
+ yyjson_mut_doc_free(lm);
+ free(linked[li]);
+ }
+
+ yyjson_mut_obj_add_val(mdoc, mroot, "linked_projects", lp_arr);
+
+ size_t len = 0;
+ char *final_json = yyjson_mut_write(mdoc, 0, &len);
+ yyjson_mut_doc_free(mdoc);
+
+ if (final_json) {
+ mg_http_reply(c, 200, g_cors_json, "%s", final_json);
+ free(final_json);
+ } else {
+ mg_http_reply(c, 500, g_cors_json, "{\"error\":\"JSON write failed\"}");
+ }
}
/* ── Handle JSON-RPC request ──────────────────────────────────── */