Skip to content

Commit 7dbddb6

Browse files
Pankaj SharmaPankaj Sharma
authored andcommitted
feat(cross-repo): link Maven library dependencies
1 parent 5706bf5 commit 7dbddb6

7 files changed

Lines changed: 938 additions & 7 deletions

File tree

Makefile.cbm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ PIPELINE_SRCS = \
200200
src/pipeline/pass_semantic_edges.c \
201201
src/pipeline/pass_complexity.c \
202202
src/pipeline/pass_cross_repo.c \
203+
src/pipeline/pass_cross_repo_maven.c \
203204
src/pipeline/artifact.c \
204205
src/pipeline/pass_pkgmap.c
205206

src/mcp/mcp.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ static const tool_def_t TOOLS[] = {
273273
{"index_repository",
274274
"Index a repository into the knowledge graph. "
275275
"Special mode 'cross-repo-intelligence': skip extraction, only match Routes/Channels "
276-
"across projects to create CROSS_HTTP_CALLS/CROSS_ASYNC_CALLS/CROSS_CHANNEL edges. "
276+
"and Maven library dependencies across projects to create CROSS_HTTP_CALLS/"
277+
"CROSS_ASYNC_CALLS/CROSS_CHANNEL/CROSS_LIBRARY_DEPENDS_ON/CROSS_LIBRARY_USED_BY edges. "
277278
"Requires target_projects param. Ensure target projects have fresh indexes first.",
278279
"{\"type\":\"object\",\"properties\":{\"repo_path\":{\"type\":\"string\",\"description\":"
279280
"\"Path to the repository\"},"
@@ -282,7 +283,8 @@ static const tool_def_t TOOLS[] = {
282283
"\"default\":\"full\",\"description\":\"All modes run type-aware LSP call/usage "
283284
"resolution (per-file + cross-file). full: all files + similarity/semantic edges. "
284285
"moderate: filtered files + similarity/semantic. fast: filtered files, no "
285-
"similarity/semantic. cross-repo-intelligence: match Routes/Channels across projects.\"},"
286+
"similarity/semantic. cross-repo-intelligence: match Routes/Channels and Maven library "
287+
"dependencies across projects.\"},"
286288
"\"target_projects\":{\"type\":\"array\",\"items\":{\"type\":\"string\"},"
287289
"\"description\":\"Projects to search for cross-repo links (cross-repo-intelligence mode). "
288290
"Use [\\\"*\\\"] for all indexed projects. Run list_projects to see available projects.\"},"
@@ -1813,9 +1815,14 @@ static void append_cross_repo_summary(yyjson_mut_doc *doc, yyjson_mut_val *root,
18131815
/* Scan edge types for any CROSS_* edges and sum them */
18141816
int cross_total = 0;
18151817
yyjson_mut_val *cr = yyjson_mut_obj(doc);
1816-
static const char *cross_types[] = {"CROSS_HTTP_CALLS", "CROSS_ASYNC_CALLS",
1817-
"CROSS_CHANNEL", "CROSS_GRPC_CALLS",
1818-
"CROSS_GRAPHQL_CALLS", "CROSS_TRPC_CALLS"};
1818+
static const char *cross_types[] = {"CROSS_HTTP_CALLS",
1819+
"CROSS_ASYNC_CALLS",
1820+
"CROSS_CHANNEL",
1821+
"CROSS_GRPC_CALLS",
1822+
"CROSS_GRAPHQL_CALLS",
1823+
"CROSS_TRPC_CALLS",
1824+
"CROSS_LIBRARY_DEPENDS_ON",
1825+
"CROSS_LIBRARY_USED_BY"};
18191826
for (int t = 0; t < (int)(sizeof(cross_types) / sizeof(cross_types[0])); t++) {
18201827
for (int i = 0; i < schema->edge_type_count; i++) {
18211828
if (strcmp(schema->edge_types[i].type, cross_types[t]) == 0) {
@@ -2462,7 +2469,7 @@ static char *handle_cross_repo_mode(const char *repo_path, const char *args) {
24622469
yyjson_doc_free(jdoc);
24632470

24642471
int total = result.http_edges + result.async_edges + result.channel_edges + result.grpc_edges +
2465-
result.graphql_edges + result.trpc_edges;
2472+
result.graphql_edges + result.trpc_edges + result.library_edges;
24662473
yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);
24672474
yyjson_mut_val *root = yyjson_mut_obj(doc);
24682475
yyjson_mut_doc_set_root(doc, root);
@@ -2476,6 +2483,7 @@ static char *handle_cross_repo_mode(const char *repo_path, const char *args) {
24762483
yyjson_mut_obj_add_int(doc, root, "cross_grpc_calls", result.grpc_edges);
24772484
yyjson_mut_obj_add_int(doc, root, "cross_graphql_calls", result.graphql_edges);
24782485
yyjson_mut_obj_add_int(doc, root, "cross_trpc_calls", result.trpc_edges);
2486+
yyjson_mut_obj_add_int(doc, root, "cross_library_edges", result.library_edges);
24792487
yyjson_mut_obj_add_int(doc, root, "total_cross_edges", total);
24802488
yyjson_mut_obj_add_real(doc, root, "elapsed_ms", result.elapsed_ms);
24812489

src/pipeline/pass_cross_repo.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* get a CROSS_* edge so the link is visible from either side.
1111
*/
1212
#include "pipeline/pass_cross_repo.h"
13+
#include "pipeline/pass_cross_repo_maven.h"
1314
#include "foundation/constants.h"
1415
#include "foundation/log.h"
1516
#include "foundation/platform.h"
@@ -112,6 +113,22 @@ static void delete_cross_edges(cbm_store_t *store, const char *project) {
112113
cbm_store_delete_edges_by_type(store, project, "CROSS_GRPC_CALLS");
113114
cbm_store_delete_edges_by_type(store, project, "CROSS_GRAPHQL_CALLS");
114115
cbm_store_delete_edges_by_type(store, project, "CROSS_TRPC_CALLS");
116+
cbm_store_delete_edges_by_type(store, project, "CROSS_LIBRARY_DEPENDS_ON");
117+
cbm_store_delete_edges_by_type(store, project, "CROSS_LIBRARY_USED_BY");
118+
struct sqlite3 *db = cbm_store_get_db(store);
119+
if (!db) {
120+
return;
121+
}
122+
sqlite3_stmt *st = NULL;
123+
if (sqlite3_prepare_v2(db,
124+
"DELETE FROM nodes WHERE project=?1 AND "
125+
"(qualified_name LIKE '__library__%' OR "
126+
"qualified_name LIKE '__library_consumer__%')",
127+
CBM_NOT_FOUND, &st, NULL) == SQLITE_OK) {
128+
sqlite3_bind_text(st, SKIP_ONE, project, CBM_NOT_FOUND, SQLITE_STATIC);
129+
sqlite3_step(st);
130+
sqlite3_finalize(st);
131+
}
115132
}
116133

117134
/* Insert a CROSS_* edge into a store. */
@@ -660,6 +677,8 @@ cbm_cross_repo_result_t cbm_cross_repo_match(const char *project, const char **t
660677
"operation", "CROSS_GRAPHQL_CALLS");
661678
result.trpc_edges += match_typed_routes(src_store, project, tgt_store, tgt, "TRPC_CALLS",
662679
"procedure", "procedure", "CROSS_TRPC_CALLS");
680+
result.library_edges +=
681+
cbm_cross_repo_match_maven_libraries(src_store, project, tgt_store, tgt);
663682
result.projects_scanned++;
664683

665684
cbm_store_close(tgt_store);
@@ -677,7 +696,7 @@ cbm_cross_repo_result_t cbm_cross_repo_match(const char *project, const char **t
677696
((double)(t1.tv_nsec - t0.tv_nsec) / CR_NS_PER_MS);
678697

679698
int total = result.http_edges + result.async_edges + result.channel_edges + result.grpc_edges +
680-
result.graphql_edges + result.trpc_edges;
699+
result.graphql_edges + result.trpc_edges + result.library_edges;
681700
cbm_log_info("cross_repo.done", "project", project, "total", cr_itoa(total));
682701

683702
return result;

src/pipeline/pass_cross_repo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ typedef struct {
1515
int grpc_edges; /* CROSS_GRPC_CALLS edges created */
1616
int graphql_edges; /* CROSS_GRAPHQL_CALLS edges created */
1717
int trpc_edges; /* CROSS_TRPC_CALLS edges created */
18+
int library_edges; /* CROSS_LIBRARY_DEPENDS_ON/CROSS_LIBRARY_USED_BY pairs created */
1819
int projects_scanned;
1920
double elapsed_ms;
2021
} cbm_cross_repo_result_t;

0 commit comments

Comments
 (0)