| 628 | } |
| 629 | |
| 630 | const char *cbm_resolve_cache_dir(void) { |
| 631 | static CBM_TLS char buf[CBM_SZ_4K]; |
| 632 | static const char missing[] = "\x1f" |
| 633 | "CBM_CACHE_DIR_MISSING" |
| 634 | "\x1f"; |
| 635 | const char *configured = cbm_safe_getenv("CBM_CACHE_DIR", buf, sizeof(buf), missing); |
| 636 | if (!configured) { |
| 637 | /* Present but not representable in the product path bound. */ |
| 638 | return NULL; |
| 639 | } |
| 640 | if (strcmp(configured, missing) != 0 && configured[0]) { |
| 641 | cbm_normalize_path_sep(buf); |
| 642 | return buf; |
| 643 | } |
| 644 | const char *home = cbm_get_home_dir(); |
| 645 | if (!home) { |
| 646 | return NULL; |
| 647 | } |
| 648 | int written = snprintf(buf, sizeof(buf), "%s/.cache/codebase-memory-mcp", home); |
| 649 | if (written <= 0 || (size_t)written >= sizeof(buf)) { |
| 650 | buf[0] = '\0'; |
| 651 | return NULL; |
| 652 | } |
| 653 | return buf; |
| 654 | } |