MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / ia_structural

Function ia_structural

src/ui/atlas_impact.c:105–214  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103}
104
105static void ia_structural(cbm_store_t *store, const char *project, const char *file,
106 int64_t node_id, const char *qn, yyjson_mut_doc *doc,
107 yyjson_mut_val *root, time_t deadline) {
108 sqlite3 *db = cbm_store_get_db(store);
109 yyjson_mut_val *out = yyjson_mut_obj(doc), *findings = yyjson_mut_arr(doc);
110 yyjson_mut_obj_add_val(doc, root, "structural", out);
111 yyjson_mut_obj_add_val(doc, out, "findings", findings);
112 yyjson_mut_obj_add_str(doc, out, "basis", "CALLS and IMPORTS; reverse dependency paths");
113 yyjson_mut_obj_add_int(doc, out, "max_depth", IA_DEPTH);
114 yyjson_mut_obj_add_int(doc, out, "visit_cap", IA_VISITS);
115 yyjson_mut_obj_add_int(doc, out, "result_cap", IA_SHOWN);
116 ia_node_t *nodes = cbm_atlas_calloc_array(IA_VISITS, sizeof(*nodes));
117 sqlite3_stmt *st = NULL, *edges = NULL;
118 int count = 0, seed_count = 0, visited_edges = 0, direct = 0, test_count = 0;
119 bool capped = false, failed = false;
120 sqlite3_progress_handler(db, 10000, ia_deadline, &deadline);
121 const char *sql = "SELECT id,name,qualified_name,file_path,start_line FROM nodes "
122 "WHERE project=?1 AND file_path=?2 AND "
123 "((?3<0 AND ?4='') OR id=?3 OR (?4<>'' AND qualified_name=?4)) "
124 "ORDER BY CASE WHEN label IN ('File','Module') THEN 0 "
125 "WHEN label IN ('Function','Method') THEN 1 ELSE 2 END,id LIMIT 129";
126 if (!nodes || sqlite3_prepare_v2(db, sql, -1, &st, NULL) != SQLITE_OK) {
127 failed = true;
128 goto finish;
129 }
130 sqlite3_bind_text(st, 1, project, -1, SQLITE_STATIC);
131 sqlite3_bind_text(st, 2, file, -1, SQLITE_STATIC);
132 sqlite3_bind_int64(st, 3, node_id);
133 sqlite3_bind_text(st, 4, qn ? qn : "", -1, SQLITE_STATIC);
134 int rc;
135 while ((rc = sqlite3_step(st)) == SQLITE_ROW) {
136 if (count == IA_SEEDS) {
137 capped = true;
138 break;
139 }
140 ia_read_node(&nodes[count++], st);
141 }
142 if (rc != SQLITE_DONE && rc != SQLITE_ROW)
143 failed = true;
144 seed_count = count;
145 const char *edge_sql =
146 "SELECT n.id,n.name,n.qualified_name,n.file_path,n.start_line,e.id,e.type "
147 "FROM edges e JOIN nodes n ON n.id=e.source_id "
148 "WHERE e.project=?1 AND n.project=?1 AND e.target_id=?2 "
149 "AND e.type IN ('CALLS','IMPORTS') ORDER BY e.id LIMIT 3001";
150 if (sqlite3_prepare_v2(db, edge_sql, -1, &edges, NULL) != SQLITE_OK) {
151 failed = true;
152 goto finish;
153 }
154 for (int head = 0; head < count && !failed; head++) {
155 if (time(NULL) >= deadline) {
156 capped = true;
157 break;
158 }
159 sqlite3_reset(edges);
160 sqlite3_bind_text(edges, 1, project, -1, SQLITE_STATIC);
161 sqlite3_bind_int64(edges, 2, nodes[head].id);
162 while ((rc = sqlite3_step(edges)) == SQLITE_ROW) {

Callers 1

Calls 7

cbm_store_get_dbFunction · 0.85
cbm_atlas_calloc_arrayFunction · 0.85
ia_read_nodeFunction · 0.85
ia_textFunction · 0.85
cbm_is_test_file_pathFunction · 0.85
ia_findingFunction · 0.85
cbm_freeFunction · 0.85

Tested by

no test coverage detected