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

Function ha_resolve_and_query

src/cli/hook_augment.c:264–300  ·  view source on GitHub ↗

Walk up from `start`, deriving a project name at each level and querying * search_graph until an indexed project is found (or the walk is exhausted). * Stops at the first non-error result: a valid project with zero hits is a * legitimate "no match" and must NOT cause a parent-directory probe. */

Source from the content-addressed store, hash-verified

262 * Stops at the first non-error result: a valid project with zero hits is a
263 * legitimate "no match" and must NOT cause a parent-directory probe. */
264static char *ha_resolve_and_query(cbm_mcp_server_t *srv, const char *start, const char *token) {
265 char dir[4096];
266 snprintf(dir, sizeof(dir), "%s", start);
267
268 for (int level = 0; level < HA_MAX_WALKUP && cbm_hook_path_is_abs(dir); level++) {
269 char *project = cbm_project_name_from_path(dir);
270 if (project) {
271 char *args = ha_build_args(project, token);
272 free(project);
273 if (args) {
274 char *res = cbm_mcp_handle_tool(srv, "search_graph", args);
275 free(args);
276 if (res) {
277 bool is_error = false;
278 char *ctx = ha_format_context(res, token, &is_error);
279 free(res);
280 if (ctx) {
281 return ctx; /* hits → done */
282 }
283 if (!is_error) {
284 return NULL; /* valid project, no hits → stop */
285 }
286 }
287 }
288 }
289 /* Not indexed at this level — climb to the parent. */
290 char *slash = strrchr(dir, '/');
291 if (!slash || slash == dir) {
292 break; /* POSIX root "/" */
293 }
294 if (slash == dir + 2 && dir[1] == ':') {
295 break; /* Windows drive root "X:/" — don't strip to "X:" */
296 }
297 *slash = '\0';
298 }
299 return NULL;
300}
301
302int cbm_cmd_hook_augment(void) {
303 ha_arm_deadline();

Callers 1

cbm_cmd_hook_augmentFunction · 0.85

Calls 5

cbm_hook_path_is_absFunction · 0.85
ha_build_argsFunction · 0.85
cbm_mcp_handle_toolFunction · 0.85
ha_format_contextFunction · 0.85

Tested by

no test coverage detected