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. */
| 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. */ |
| 264 | static 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 | |
| 302 | int cbm_cmd_hook_augment(void) { |
| 303 | ha_arm_deadline(); |
no test coverage detected