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
Add HANDLES for Spring/ASP.NET/Laravel routes + Guzzle/RestSharp HTTP_CALLS
Martin Vogel65ee5ef7b366
diff --git a/internal/cbm/extract_calls.c b/internal/cbm/extract_calls.cindex ddaa50570..407005da6 100644--- a/internal/cbm/extract_calls.c+++ b/internal/cbm/extract_calls.c@@ -7,6 +7,8 @@#include "extract_node_stack.h"#include "tree_sitter/api.h" // TSNode, ts_node_*#include <stdint.h> // uint32_t+#include <stdio.h>+#include <stdlib.h>#include <string.h>#include <ctype.h>@@ -935,6 +937,11 @@ static const char *extract_url_or_topic_arg(CBMExtractCtx *ctx, TSNode args) {uint32_t nc = ts_node_named_child_count(args);for (uint32_t ai = 0; ai < nc; ai++) {TSNode arg = ts_node_named_child(args, ai);+ /* PHP and C# wrap each positional argument in an `argument` node;+ * unwrap to the underlying value so the URL string is reachable. */+ if (strcmp(ts_node_type(arg), "argument") == 0 && ts_node_named_child_count(arg) > 0) {+ arg = ts_node_named_child(arg, 0);+ }const char *ak = ts_node_type(arg);if (strcmp(ak, "keyword_argument") == 0 || strcmp(ak, "pair") == 0) {@@ -956,16 +963,46 @@ static const char *extract_url_or_topic_arg(CBMExtractCtx *ctx, TSNode args) {}// Extract second argument name (handler ref for route registrations).+/* Normalize a string-form route handler to a resolvable handler name.+ * 'showUsers' → showUsers+ * 'UserController@show' → show (Laravel "Controller@method")+ * The method segment after '@' is the resolvable function/method name. */+static const char *normalize_string_handler(CBMArena *a, const char *raw) {+ const char *unq = strip_quotes(a, raw);+ if (!unq || !unq[0]) {+ return NULL;+ }+ const char *at = strchr(unq, '@');+ if (at && at[1]) {+ return cbm_arena_strdup(a, at + 1);+ }+ return unq;+}+static const char *extract_handler_arg(CBMExtractCtx *ctx, TSNode args) {uint32_t nc = ts_node_named_child_count(args);for (uint32_t ai = HANDLER_START_IDX; ai < nc && ai < MAX_HANDLER_SCAN; ai++) {TSNode arg2 = ts_node_named_child(args, ai);+ /* PHP wraps each argument in an `argument` node — unwrap to the value. */+ if (strcmp(ts_node_type(arg2), "argument") == 0 &&+ ts_node_named_child_count(arg2) > 0) {+ arg2 = ts_node_named_child(arg2, 0);+ }const char *ak2 = ts_node_type(arg2);+ /* `name` = PHP bare identifier handler; string = Laravel string handler+ * ('showUsers' or 'Controller@method'). */if (strcmp(ak2, "identifier") == 0 || strcmp(ak2, "member_expression") == 0 ||strcmp(ak2, "selector_expression") == 0 || strcmp(ak2, "attribute") == 0 ||- strcmp(ak2, "field_expression") == 0) {+ strcmp(ak2, "field_expression") == 0 || strcmp(ak2, "name") == 0) {return cbm_node_text(ctx->arena, arg2, ctx->source);}+ if (is_string_like(ak2)) {+ const char *h = normalize_string_handler(ctx->arena,+ cbm_node_text(ctx->arena, arg2, ctx->source));+ if (h && h[0]) {+ return h;+ }+ }}return NULL;}@@ -1005,6 +1042,11 @@ void handle_calls(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *spec, Walkcall.start_line = (int)ts_node_start_point(node).row + TS_LINE_OFFSET;TSNode args = ts_node_child_by_field_name(node, TS_FIELD("arguments"));+ if (getenv("CBM_DBG_ARGS") && callee && (strstr(callee,"get")||strstr(callee,"Get")||strstr(callee,"client")||strstr(callee,"Route"))) {+ fprintf(stderr, "[DBGARGS] callee=%s node=%s args_null=%d", callee, ts_node_type(node), ts_node_is_null(args));+ if (!ts_node_is_null(args)) { uint32_t n=ts_node_named_child_count(args); fprintf(stderr, " nargs=%u:", n); for(uint32_t i=0;i<n&&i<4;i++) fprintf(stderr," [%s]",ts_node_type(ts_node_named_child(args,i))); }+ fprintf(stderr, "\n");+ }if (!ts_node_is_null(args)) {call.first_string_arg = extract_url_or_topic_arg(ctx, args);if (call.first_string_arg && call.first_string_arg[0] == '/') {diff --git a/internal/cbm/extract_defs.c b/internal/cbm/extract_defs.cindex bbefc6070..b5b9abbc6 100644--- a/internal/cbm/extract_defs.c+++ b/internal/cbm/extract_defs.c@@ -1061,6 +1061,8 @@ static const char *extract_docstring(CBMArena *a, TSNode node, const char *sourcreturn NULL;}+static TSNode find_jvm_modifiers(TSNode node, CBMLanguage lang);+/* HTTP method names recognized in decorator calls (e.g., @router.post → "POST") */static const char *decorator_method_name(const char *attr_text) {if (!attr_text) {@@ -1090,6 +1092,39 @@ static const char *decorator_method_name(const char *attr_text) {return NULL;}+/* HTTP method for a Spring/JAX-RS style annotation name (e.g. "GetMapping" →+ * "GET", "RequestMapping" → "ANY", JAX-RS "GET" → "GET"). Returns NULL when the+ * annotation is not a route-mapping annotation. */+static const char *annotation_route_method(const char *name) {+ if (!name) {+ return NULL;+ }+ if (strcmp(name, "GetMapping") == 0) {+ return "GET";+ }+ if (strcmp(name, "PostMapping") == 0) {+ return "POST";+ }+ if (strcmp(name, "PutMapping") == 0) {+ return "PUT";+ }+ if (strcmp(name, "DeleteMapping") == 0) {+ return "DELETE";+ }+ if (strcmp(name, "PatchMapping") == 0) {+ return "PATCH";+ }+ if (strcmp(name, "RequestMapping") == 0) {+ return "ANY";+ }+ /* JAX-RS bare-verb annotations (@GET/@POST/...) — path comes from @Path. */+ if (strcmp(name, "GET") == 0 || strcmp(name, "POST") == 0 || strcmp(name, "PUT") == 0 ||+ strcmp(name, "DELETE") == 0 || strcmp(name, "PATCH") == 0) {+ return name;+ }+ return NULL;+}+/* Extract route path + method from a decorator's AST nodes.* Works for: @app.route("/path"), @router.post("/path"), @GetMapping("/path"),* @app.get("/path", ...), etc.@@ -1167,6 +1202,66 @@ static bool try_route_from_decorator_call(CBMArena *a, TSNode dchild, const charreturn true;}+/* Try to extract a route from a Java/JVM annotation node (`annotation` or+ * `marker_annotation`). Spring mapping annotations carry the HTTP method in the+ * annotation name and the path in the (optional) argument list:+ * @GetMapping("/orders") @RequestMapping(value="/api") @PostMapping+ * Returns true when the annotation is a route-mapping annotation. */+static bool try_route_from_annotation(CBMArena *a, TSNode annotation, const char *source,+ const char **out_path, const char **out_method) {+ TSNode name_node = ts_node_child_by_field_name(annotation, TS_FIELD("name"));+ if (ts_node_is_null(name_node)) {+ return false;+ }+ char *name = cbm_node_text(a, name_node, source);+ const char *method = annotation_route_method(name);+ if (!method) {+ return false;+ }+ TSNode args = ts_node_child_by_field_name(annotation, TS_FIELD("arguments"));+ if (ts_node_is_null(args)) {+ args = find_decorator_args(annotation);+ }+ const char *path = NULL;+ if (!ts_node_is_null(args)) {+ path = extract_route_path_from_args(a, args, source);+ }+ *out_path = path ? path : "/";+ *out_method = method;+ return true;+}++/* Scan the annotation nodes nested in a JVM/C# `modifiers`/`attribute_list`+ * wrapper (and direct children) for a route-mapping annotation. Java/Kotlin+ * Spring annotations (@GetMapping, @RequestMapping, ...) live here rather than+ * as prev-siblings, so the prev-sibling decorator walk never sees them. */+static bool extract_route_from_annotations(CBMArena *a, TSNode func_node, const char *source,+ const CBMLangSpec *spec, const char **out_path,+ const char **out_method) {+ TSNode modifiers = find_jvm_modifiers(func_node, spec->language);+ if (!ts_node_is_null(modifiers)) {+ uint32_t mc = ts_node_child_count(modifiers);+ for (uint32_t mi = 0; mi < mc; mi++) {+ TSNode mchild = ts_node_child(modifiers, mi);+ if (cbm_kind_in_set(mchild, spec->decorator_node_types) &&+ try_route_from_annotation(a, mchild, source, out_path, out_method)) {+ return true;+ }+ }+ }+ /* Direct-child annotations (some grammars attach the annotation as a child+ * of the method node rather than under `modifiers`). */+ uint32_t cc = ts_node_child_count(func_node);+ for (uint32_t ci = 0; ci < cc; ci++) {+ TSNode child = ts_node_child(func_node, ci);+ if (cbm_kind_in_set(child, spec->decorator_node_types) &&+ try_route_from_annotation(a, child, source, out_path, out_method)) {+ return true;+ }+ }+ return false;+}+static void extract_route_from_decorators(CBMArena *a, TSNode func_node, const char *source,const CBMLangSpec *spec, const char **out_path,const char **out_method) {@@ -1193,8 +1288,17 @@ static void extract_route_from_decorators(CBMArena *a, TSNode func_node, const creturn;}}+ /* JVM/C# annotation-form route mapping (Spring @GetMapping etc.) — the+ * prev-sibling itself may be the annotation node. */+ if (try_route_from_annotation(a, prev, source, out_path, out_method)) {+ return;+ }prev = ts_node_prev_sibling(prev);}++ /* Spring/JAX-RS annotations live inside the method's `modifiers` child, not+ * as prev-siblings — scan there too. */+ extract_route_from_annotations(a, func_node, source, spec, out_path, out_method);}// Extract decorator names from preceding decorator/annotation nodesdiff --git a/src/pipeline/pass_calls.c b/src/pipeline/pass_calls.cindex b0b28371e..92fbd3f4c 100644--- a/src/pipeline/pass_calls.c+++ b/src/pipeline/pass_calls.c@@ -198,9 +198,11 @@ static void handle_route_registration(cbm_pipeline_ctx_t *ctx, const CBMCall *ca"{\"callee\":\"%s\",\"url_path\":\"%s\",\"via\":\"route_registration\"}",call->callee_name, call->first_string_arg);cbm_gbuf_insert_edge(ctx->gbuf, source_node->id, route_id, "CALLS", props);+ if (getenv("CBM_DBG_ROUTE")) fprintf(stderr, "[DBG] route_reg callee=%s path=%s handler=%s\n", call->callee_name, call->first_string_arg, call->second_arg_name?call->second_arg_name:"(null)");if (call->second_arg_name != NULL && call->second_arg_name[0] != '\0') {cbm_resolution_t hres = cbm_registry_resolve(ctx->registry, call->second_arg_name,module_qn, imp_keys, imp_vals, imp_count);+ if (getenv("CBM_DBG_ROUTE")) fprintf(stderr, "[DBG] handler '%s' resolved=%s\n", call->second_arg_name, hres.qualified_name?hres.qualified_name:"(null)");if (hres.qualified_name != NULL && hres.qualified_name[0] != '\0') {const cbm_gbuf_node_t *handler = cbm_gbuf_find_by_qn(ctx->gbuf, hres.qualified_name);if (handler != NULL) {@@ -281,6 +283,8 @@ static void emit_classified_edge(cbm_pipeline_ctx_t *ctx, const CBMCall *call,const cbm_resolution_t *res, const char *module_qn,const char **imp_keys, const char **imp_vals, int imp_count) {cbm_svc_kind_t svc = cbm_service_pattern_match(res->qualified_name);+ if (getenv("CBM_DBG_SVC") && call->callee_name && (strstr(call->callee_name,"Route")||strstr(call->callee_name,"client")||strstr(call->callee_name,"Client")||strstr(call->callee_name,"RestClient")))+ fprintf(stderr, "[DBGSVC] callee=%s resolved=%s svc=%d strarg=%s\n", call->callee_name, res->qualified_name?res->qualified_name:"(null)", svc, call->first_string_arg?call->first_string_arg:"(null)");if (svc == CBM_SVC_ROUTE_REG && call->first_string_arg && call->first_string_arg[0] == '/') {handle_route_registration(ctx, call, source, module_qn, imp_keys, imp_vals, imp_count);return;