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.

Argument-to-parameter mapping + field access chains (Phase B2+B3)

Martin Vogelb5e288a640fe
diff --git a/internal/cbm/cbm.h b/internal/cbm/cbm.h
index 0560cf665..39c1da318 100644
--- a/internal/cbm/cbm.h
+++ b/internal/cbm/cbm.h
@@ -107,11 +107,23 @@ typedef struct {
bool is_entry_point;
} CBMDefinition;
+/* Argument captured from a call expression */
typedef struct {
- const char *callee_name; // raw callee text ("pkg.Func", "foo")
- const char *enclosing_func_qn; // QN of enclosing function (or module QN)
- const char *first_string_arg; // first string literal argument (URL, topic, key) or NULL
- const char *second_arg_name; // second argument identifier (handler ref) or NULL
+ const char *expr; // raw expression text ("payload.info", "MY_URL", "'hello'")
+ const char *value; // resolved string value or NULL (constant propagation)
+ const char *keyword; // keyword name if keyword arg ("url", "topic_id"), NULL if positional
+ int index; // positional index (0-based)
+} CBMCallArg;
+
+#define CBM_MAX_CALL_ARGS 8
+
+typedef struct {
+ const char *callee_name; // raw callee text ("pkg.Func", "foo")
+ const char *enclosing_func_qn; // QN of enclosing function (or module QN)
+ const char *first_string_arg; // first string literal argument (URL, topic, key) or NULL
+ const char *second_arg_name; // second argument identifier (handler ref) or NULL
+ CBMCallArg args[CBM_MAX_CALL_ARGS]; // first N arguments with expressions
+ int arg_count; // number of captured arguments
} CBMCall;
typedef struct {
diff --git a/internal/cbm/extract_calls.c b/internal/cbm/extract_calls.c
index 51d4204bb..c17e68360 100644
--- a/internal/cbm/extract_calls.c
+++ b/internal/cbm/extract_calls.c
@@ -22,6 +22,25 @@ static const char *lookup_string_constant(const CBMExtractCtx *ctx, const char *
return NULL;
}
+/* Check if a node type is a string literal */
+static int is_string_like(const char *kind) {
+ return (strcmp(kind, "string") == 0 || strcmp(kind, "string_literal") == 0 ||
+ strcmp(kind, "interpreted_string_literal") == 0 ||
+ strcmp(kind, "raw_string_literal") == 0 || strcmp(kind, "string_content") == 0);
+}
+
+/* Strip surrounding quotes from a string, return arena-allocated copy */
+static const char *strip_quotes(CBMArena *a, const char *text) {
+ if (!text || !text[0]) {
+ return NULL;
+ }
+ int len = (int)strlen(text);
+ if (len >= 2 && (text[0] == '"' || text[0] == '\'')) {
+ return cbm_arena_strndup(a, text + 1, (size_t)(len - 2));
+ }
+ return text;
+}
+
// Forward declarations
static void walk_calls(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *spec);
static char *extract_callee_name(CBMArena *a, TSNode node, const char *source, CBMLanguage lang);
@@ -365,6 +384,53 @@ void cbm_extract_calls(CBMExtractCtx *ctx) {
// --- Unified handler: called once per node by the cursor walk ---
+/* Extract all arguments from a call expression into call->args[].
+ * Captures expression text, resolved constants, keyword names, and
+ * dotted field chains (member_expression → "payload.info.url"). */
+static void extract_call_args(CBMExtractCtx *ctx, TSNode args, CBMCall *call) {
+ uint32_t argc = ts_node_named_child_count(args);
+ int positional_idx = 0;
+ for (uint32_t ai = 0; ai < argc && call->arg_count < CBM_MAX_CALL_ARGS; ai++) {
+ TSNode arg_node = ts_node_named_child(args, ai);
+ const char *ak = ts_node_type(arg_node);
+ CBMCallArg *ca = &call->args[call->arg_count];
+ memset(ca, 0, sizeof(*ca));
+
+ if (strcmp(ak, "keyword_argument") == 0 || strcmp(ak, "pair") == 0) {
+ TSNode key_n = ts_node_child_by_field_name(arg_node, "name", 4);
+ TSNode val_n = ts_node_child_by_field_name(arg_node, "value", 5);
+ if (ts_node_is_null(key_n)) {
+ key_n = ts_node_child_by_field_name(arg_node, "key", 3);
+ }
+ if (!ts_node_is_null(key_n)) {
+ ca->keyword = cbm_node_text(ctx->arena, key_n, ctx->source);
+ }
+ if (!ts_node_is_null(val_n)) {
+ ca->expr = cbm_node_text(ctx->arena, val_n, ctx->source);
+ if (strcmp(ts_node_type(val_n), "identifier") == 0 && ca->expr) {
+ ca->value = lookup_string_constant(ctx, ca->expr);
+ } else if (is_string_like(ts_node_type(val_n)) && ca->expr) {
+ ca->value = strip_quotes(ctx->arena, ca->expr);
+ }
+ }
+ ca->index = positional_idx++;
+ call->arg_count++;
+ } else if (strcmp(ak, "list_splat") == 0 || strcmp(ak, "dictionary_splat") == 0 ||
+ strcmp(ak, "spread_element") == 0) {
+ positional_idx++;
+ } else {
+ ca->expr = cbm_node_text(ctx->arena, arg_node, ctx->source);
+ ca->index = positional_idx++;
+ if (is_string_like(ak) && ca->expr) {
+ ca->value = strip_quotes(ctx->arena, ca->expr);
+ } else if (strcmp(ak, "identifier") == 0 && ca->expr) {
+ ca->value = lookup_string_constant(ctx, ca->expr);
+ }
+ call->arg_count++;
+ }
+ }
+}
+
void handle_calls(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *spec, WalkState *state) {
if (!spec->call_node_types || !spec->call_node_types[0]) {
return;
@@ -504,26 +570,26 @@ void handle_calls(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *spec, Walk
}
}
- /* Extract second argument name (handler ref for route registrations).
- * Pattern: router.GET("/path", handlerFunc) → second_arg_name = "handlerFunc"
- * Only extracted when first_string_arg looks like a path. */
+ /* Extract second argument name (handler ref for route registrations). */
if (call.first_string_arg != NULL && call.first_string_arg[0] == '/' &&
!ts_node_is_null(args)) {
uint32_t nc2 = ts_node_named_child_count(args);
for (uint32_t ai = 1; ai < nc2 && ai < 4 && !call.second_arg_name; ai++) {
TSNode arg2 = ts_node_named_child(args, ai);
const char *ak2 = ts_node_type(arg2);
- if (strcmp(ak2, "identifier") == 0) {
- call.second_arg_name = cbm_node_text(ctx->arena, arg2, ctx->source);
- } else if (strcmp(ak2, "member_expression") == 0 ||
- strcmp(ak2, "selector_expression") == 0 ||
- strcmp(ak2, "attribute") == 0 ||
- strcmp(ak2, "field_expression") == 0) {
+ if (strcmp(ak2, "identifier") == 0 || strcmp(ak2, "member_expression") == 0 ||
+ strcmp(ak2, "selector_expression") == 0 || strcmp(ak2, "attribute") == 0 ||
+ strcmp(ak2, "field_expression") == 0) {
call.second_arg_name = cbm_node_text(ctx->arena, arg2, ctx->source);
}
}
}
+ /* B2+B3: Capture all arguments with expressions + field chains. */
+ if (!ts_node_is_null(args)) {
+ extract_call_args(ctx, args, &call);
+ }
+
cbm_calls_push(&ctx->result->calls, ctx->arena, call);
}
}
diff --git a/src/pipeline/pass_parallel.c b/src/pipeline/pass_parallel.c
index aea7deb38..115e074a5 100644
--- a/src/pipeline/pass_parallel.c
+++ b/src/pipeline/pass_parallel.c
@@ -692,6 +692,65 @@ typedef struct {
_Atomic int next_file_idx;
} resolve_ctx_t;
+/* Minimum buffer space needed per arg JSON object */
+#define CBM_ARG_JSON_GUARD 32
+
+/* Append arg data as JSON to edge properties: ,"args":[{"i":0,"e":"x","v":"val"},...]
+ * Returns new position in buffer. */
+static size_t append_args_json(char *buf, size_t bufsize, size_t pos, const CBMCall *call) {
+ if (call->arg_count == 0 || pos >= bufsize - 20) {
+ return pos;
+ }
+ int n = snprintf(buf + pos, bufsize - pos, ",\"args\":[");
+ if (n <= 0) {
+ return pos;
+ }
+ pos += (size_t)n;
+ for (int i = 0; i < call->arg_count && pos < bufsize - CBM_ARG_JSON_GUARD; i++) {
+ const CBMCallArg *a = &call->args[i];
+ if (i > 0 && pos < bufsize - 1) {
+ buf[pos++] = ',';
+ }
+ /* Truncate long expressions to keep edge properties compact */
+ char expr_buf[128];
+ if (a->expr) {
+ snprintf(expr_buf, sizeof(expr_buf), "%.*s", 120, a->expr);
+ /* Escape quotes for JSON safety */
+ for (char *p = expr_buf; *p; p++) {
+ if (*p == '"') {
+ *p = '\'';
+ }
+ if (*p == '\n' || *p == '\r') {
+ *p = ' ';
+ }
+ }
+ } else {
+ expr_buf[0] = '\0';
+ }
+ if (a->keyword && a->value) {
+ n = snprintf(buf + pos, bufsize - pos,
+ "{\"i\":%d,\"k\":\"%s\",\"e\":\"%s\",\"v\":\"%s\"}", a->index, a->keyword,
+ expr_buf, a->value);
+ } else if (a->keyword) {
+ n = snprintf(buf + pos, bufsize - pos, "{\"i\":%d,\"k\":\"%s\",\"e\":\"%s\"}", a->index,
+ a->keyword, expr_buf);
+ } else if (a->value) {
+ n = snprintf(buf + pos, bufsize - pos, "{\"i\":%d,\"e\":\"%s\",\"v\":\"%s\"}", a->index,
+ expr_buf, a->value);
+ } else {
+ n = snprintf(buf + pos, bufsize - pos, "{\"i\":%d,\"e\":\"%s\"}", a->index, expr_buf);
+ }
+ if (n > 0) {
+ pos += (size_t)n;
+ }
+ }
+ if (pos < bufsize - 1) {
+ buf[pos++] = ']';
+ }
+ buf[pos] = '\0';
+ return pos;
+}
+
/* Classify a resolved call by library identity and emit the appropriate edge.
* Extracted from resolve_worker to keep cognitive complexity under threshold. */
static void emit_service_edge(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source,
@@ -759,23 +818,46 @@ static void emit_service_edge(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source,
int64_t route_id =
cbm_gbuf_upsert_node(gbuf, "Route", arg, route_qn, "", 0, 0, route_props);
- char props[512];
- snprintf(props, sizeof(props), "{\"callee\":\"%s\",\"url_path\":\"%s\"%s%s%s%s%s%s}",
- call->callee_name, arg, method ? ",\"method\":\"" : "", method ? method : "",
- method ? "\"" : "", broker ? ",\"broker\":\"" : "", broker ? broker : "",
- broker ? "\"" : "");
+ char props[2048];
+ int n = snprintf(props, sizeof(props), "{\"callee\":\"%s\",\"url_path\":\"%s\"%s%s%s%s%s%s",
+ call->callee_name, arg, method ? ",\"method\":\"" : "",
+ method ? method : "", method ? "\"" : "", broker ? ",\"broker\":\"" : "",
+ broker ? broker : "", broker ? "\"" : "");
+ if (n > 0 && (size_t)n < sizeof(props) - 2) {
+ size_t pos = append_args_json(props, sizeof(props), (size_t)n, call);
+ if (pos < sizeof(props) - 1) {
+ props[pos] = '}';
+ props[pos + 1] = '\0';
+ }
+ }
cbm_gbuf_insert_edge(gbuf, source->id, route_id, edge_type, props);
} else if (svc == CBM_SVC_CONFIG) {
- char props[512];
- snprintf(props, sizeof(props), "{\"callee\":\"%s\",\"key\":\"%s\",\"confidence\":%.2f}",
- call->callee_name, arg != NULL ? arg : "", res->confidence);
+ char props[2048];
+ int n =
+ snprintf(props, sizeof(props), "{\"callee\":\"%s\",\"key\":\"%s\",\"confidence\":%.2f",
+ call->callee_name, arg != NULL ? arg : "", res->confidence);
+ if (n > 0 && (size_t)n < sizeof(props) - 2) {
+ size_t pos = append_args_json(props, sizeof(props), (size_t)n, call);
+ if (pos < sizeof(props) - 1) {
+ props[pos] = '}';
+ props[pos + 1] = '\0';
+ }
+ }
cbm_gbuf_insert_edge(gbuf, source->id, target->id, "CONFIGURES", props);
} else {
- char props[512];
- snprintf(props, sizeof(props),
- "{\"callee\":\"%s\",\"confidence\":%.2f,\"strategy\":\"%s\",\"candidates\":%d}",
- call->callee_name, res->confidence, res->strategy ? res->strategy : "unknown",
- res->candidate_count);
+ char props[2048];
+ int n = snprintf(props, sizeof(props),
+ "{\"callee\":\"%s\",\"confidence\":%.2f,\"strategy\":\"%s\","
+ "\"candidates\":%d",
+ call->callee_name, res->confidence,
+ res->strategy ? res->strategy : "unknown", res->candidate_count);
+ if (n > 0 && (size_t)n < sizeof(props) - 2) {
+ size_t pos = append_args_json(props, sizeof(props), (size_t)n, call);
+ if (pos < sizeof(props) - 1) {
+ props[pos] = '}';
+ props[pos + 1] = '\0';
+ }
+ }
cbm_gbuf_insert_edge(gbuf, source->id, target->id, "CALLS", props);
}
}
diff --git a/tests/test_pipeline.c b/tests/test_pipeline.c
index 569fa04e2..bf074cdcd 100644
--- a/tests/test_pipeline.c
+++ b/tests/test_pipeline.c
@@ -3675,7 +3675,7 @@ TEST(infra_parse_terraform_full) {
" }\n"
" }\n"
" backend \"gcs\" {\n"
- " bucket = \"hoepke-tf\"\n"
+ " bucket = \"example-tf\"\n"
" prefix = \"state\"\n"
" }\n"
"}\n"
@@ -3683,7 +3683,7 @@ TEST(infra_parse_terraform_full) {
"variable \"project_id\" {\n"
" description = \"The GCP project ID\"\n"
" type = string\n"
- " default = \"hoepke-cloud\"\n"
+ " default = \"example-cloud\"\n"
"}\n"
"\n"
"variable \"region\" {\n"
@@ -3736,7 +3736,7 @@ TEST(infra_parse_terraform_full) {
bool found_project_id = false;
for (int i = 0; i < r.variable_count; i++) {
if (strcmp(r.variables[i].name, "project_id") == 0) {
- ASSERT_STR_EQ(r.variables[i].default_val, "hoepke-cloud");
+ ASSERT_STR_EQ(r.variables[i].default_val, "example-cloud");
ASSERT_STR_EQ(r.variables[i].type, "string");
ASSERT_STR_EQ(r.variables[i].description, "The GCP project ID");
found_project_id = true;
@@ -3770,7 +3770,7 @@ TEST(infra_parse_terraform_variables_only) {
"variable \"project_id\" {\n"
" description = \"The GCP project ID\"\n"
" type = string\n"
- " default = \"hoepke-cloud\"\n"
+ " default = \"example-cloud\"\n"
"}\n"
"\n"
"variable \"secret_key\" {\n"