| 515 | /* ── Cache directory ────────────────────────── */ |
| 516 | |
| 517 | const char *cbm_resolve_cache_dir(void) { |
| 518 | static CBM_TLS char buf[CBM_SZ_4K]; |
| 519 | static const char missing[] = "\x1f" |
| 520 | "CBM_CACHE_DIR_MISSING" |
| 521 | "\x1f"; |
| 522 | const char *configured = cbm_safe_getenv("CBM_CACHE_DIR", buf, sizeof(buf), missing); |
| 523 | if (!configured) { |
| 524 | /* Present but not representable in the product path bound. */ |
| 525 | return NULL; |
| 526 | } |
| 527 | if (strcmp(configured, missing) != 0 && configured[0]) { |
| 528 | cbm_normalize_path_sep(buf); |
| 529 | return buf; |
| 530 | } |
| 531 | const char *home = cbm_get_home_dir(); |
| 532 | if (!home) { |
| 533 | return NULL; |
| 534 | } |
| 535 | int written = snprintf(buf, sizeof(buf), "%s/.cache/codebase-memory-mcp", home); |
| 536 | if (written <= 0 || (size_t)written >= sizeof(buf)) { |
| 537 | buf[0] = '\0'; |
| 538 | return NULL; |
| 539 | } |
| 540 | return buf; |
| 541 | } |