Skip to content

Commit 9b302ee

Browse files
DeusDatajimpark
andcommitted
Fix Zed and VS Code config paths on Windows
Add cbm_app_config_dir() and cbm_app_local_dir() platform helpers: - Windows: %APPDATA% / %LOCALAPPDATA% - macOS: $HOME for Library/Application Support paths - Linux: $XDG_CONFIG_HOME or ~/.config Update all 6 Zed/VS Code path locations (detect, install, uninstall). macOS uses $HOME directly for Library paths; Windows/Linux use the new helpers. Consolidates userconfig.c XDG logic into platform.c. Co-Authored-By: jimpark <jimpark@users.noreply.github.com>
1 parent 05aeb64 commit 9b302ee

File tree

4 files changed

+98
-29
lines changed

4 files changed

+98
-29
lines changed

src/cli/cli.c

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -975,8 +975,20 @@ cbm_detected_agents_t cbm_detect_agents(const char *home_dir) {
975975

976976
#ifdef __APPLE__
977977
snprintf(path, sizeof(path), "%s/Library/Application Support/Zed", home_dir);
978+
#elif defined(_WIN32)
979+
{
980+
const char *zed_local = cbm_app_local_dir();
981+
if (zed_local) {
982+
snprintf(path, sizeof(path), "%s/Zed", zed_local);
983+
}
984+
}
978985
#else
979-
snprintf(path, sizeof(path), "%s/.config/zed", home_dir);
986+
{
987+
const char *zed_cfg = cbm_app_config_dir();
988+
if (zed_cfg) {
989+
snprintf(path, sizeof(path), "%s/zed", zed_cfg);
990+
}
991+
}
980992
#endif
981993
agents.zed = dir_exists(path);
982994

@@ -996,7 +1008,12 @@ cbm_detected_agents_t cbm_detect_agents(const char *home_dir) {
9961008
#ifdef __APPLE__
9971009
snprintf(path, sizeof(path), "%s/Library/Application Support/Code/User", home_dir);
9981010
#else
999-
snprintf(path, sizeof(path), "%s/.config/Code/User", home_dir);
1011+
{
1012+
const char *vs_cfg = cbm_app_config_dir();
1013+
if (vs_cfg) {
1014+
snprintf(path, sizeof(path), "%s/Code/User", vs_cfg);
1015+
}
1016+
}
10001017
#endif
10011018
agents.vscode = dir_exists(path);
10021019

@@ -2711,8 +2728,10 @@ static void install_editor_agent_configs(const cbm_detected_agents_t *agents, co
27112728
char cp[CLI_BUF_1K];
27122729
#ifdef __APPLE__
27132730
snprintf(cp, sizeof(cp), "%s/Library/Application Support/Zed/settings.json", home);
2731+
#elif defined(_WIN32)
2732+
snprintf(cp, sizeof(cp), "%s/Zed/settings.json", cbm_app_local_dir());
27142733
#else
2715-
snprintf(cp, sizeof(cp), "%s/.config/zed/settings.json", home);
2734+
snprintf(cp, sizeof(cp), "%s/zed/settings.json", cbm_app_config_dir());
27162735
#endif
27172736
install_generic_agent_config("Zed", binary_path, cp, NULL, dry_run, cbm_install_zed_mcp);
27182737
}
@@ -2731,7 +2750,7 @@ static void install_editor_agent_configs(const cbm_detected_agents_t *agents, co
27312750
#ifdef __APPLE__
27322751
snprintf(cp, sizeof(cp), "%s/Library/Application Support/Code/User/mcp.json", home);
27332752
#else
2734-
snprintf(cp, sizeof(cp), "%s/.config/Code/User/mcp.json", home);
2753+
snprintf(cp, sizeof(cp), "%s/Code/User/mcp.json", cbm_app_config_dir());
27352754
#endif
27362755
install_generic_agent_config("VS Code", binary_path, cp, NULL, dry_run,
27372756
cbm_install_vscode_mcp);
@@ -2983,8 +3002,10 @@ static void uninstall_editor_agents(const cbm_detected_agents_t *agents, const c
29833002
char cp[CLI_BUF_1K];
29843003
#ifdef __APPLE__
29853004
snprintf(cp, sizeof(cp), "%s/Library/Application Support/Zed/settings.json", home);
3005+
#elif defined(_WIN32)
3006+
snprintf(cp, sizeof(cp), "%s/Zed/settings.json", cbm_app_local_dir());
29863007
#else
2987-
snprintf(cp, sizeof(cp), "%s/.config/zed/settings.json", home);
3008+
snprintf(cp, sizeof(cp), "%s/zed/settings.json", cbm_app_config_dir());
29883009
#endif
29893010
uninstall_agent_mcp_instr((mcp_uninstall_args_t){"Zed", cp, NULL}, dry_run,
29903011
cbm_remove_zed_mcp);
@@ -3004,7 +3025,7 @@ static void uninstall_editor_agents(const cbm_detected_agents_t *agents, const c
30043025
#ifdef __APPLE__
30053026
snprintf(cp, sizeof(cp), "%s/Library/Application Support/Code/User/mcp.json", home);
30063027
#else
3007-
snprintf(cp, sizeof(cp), "%s/.config/Code/User/mcp.json", home);
3028+
snprintf(cp, sizeof(cp), "%s/Code/User/mcp.json", cbm_app_config_dir());
30083029
#endif
30093030
uninstall_agent_mcp_instr((mcp_uninstall_args_t){"VS Code", cp, NULL}, dry_run,
30103031
cbm_remove_vscode_mcp);

src/discover/userconfig.c

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -152,25 +152,7 @@ static CBMLanguage lang_from_string(const char *s) {
152152

153153
/* ── Config directory helper ─────────────────────────────────────── */
154154

155-
/*
156-
* Get the XDG config dir for codebase-memory-mcp.
157-
* Writes "<dir>/codebase-memory-mcp" into buf (up to bufsz bytes).
158-
* Uses $XDG_CONFIG_HOME if set, else ~/.config.
159-
*/
160-
static void cbm_app_config_dir(char *buf, size_t bufsz) {
161-
char xdg[CBM_SZ_512] = {0};
162-
cbm_safe_getenv("XDG_CONFIG_HOME", xdg, sizeof(xdg), NULL);
163-
if (xdg[0]) {
164-
snprintf(buf, bufsz, "%s/codebase-memory-mcp", xdg);
165-
} else {
166-
char home[CBM_SZ_512] = {0};
167-
cbm_safe_getenv("HOME", home, sizeof(home), NULL);
168-
if (!home[0]) {
169-
snprintf(home, sizeof(home), "/tmp");
170-
}
171-
snprintf(buf, bufsz, "%s/.config/codebase-memory-mcp", home);
172-
}
173-
}
155+
/* cbm_app_config_dir() is now in platform.c (cross-platform). */
174156

175157
/* ── JSON parsing ────────────────────────────────────────────────── */
176158

@@ -312,11 +294,10 @@ cbm_userconfig_t *cbm_userconfig_load(const char *repo_path) {
312294

313295
/* ── Step 1: Load global config ── */
314296
enum { PATH_BUF_SZ = 1280 };
315-
char global_dir[CBM_SZ_1K];
316-
cbm_app_config_dir(global_dir, sizeof(global_dir));
317-
297+
const char *cfg_base = cbm_app_config_dir();
298+
const char *cfg_fallback = cfg_base ? cfg_base : "/tmp";
318299
char global_path[PATH_BUF_SZ];
319-
snprintf(global_path, sizeof(global_path), "%s/config.json", global_dir);
300+
snprintf(global_path, sizeof(global_path), "%s/codebase-memory-mcp/config.json", cfg_fallback);
320301

321302
if (load_config_file(global_path, &entries, &count) != 0) {
322303
for (int i = 0; i < count; i++) {

src/foundation/platform.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,58 @@ const char *cbm_get_home_dir(void) {
299299
}
300300
return NULL;
301301
}
302+
303+
/* ── App config directories (cross-platform) ─────────────────── */
304+
305+
const char *cbm_app_config_dir(void) {
306+
static char buf[CBM_SZ_1K];
307+
char tmp[CBM_SZ_256] = "";
308+
#ifdef _WIN32
309+
cbm_safe_getenv("APPDATA", tmp, sizeof(tmp), NULL);
310+
if (tmp[0]) {
311+
snprintf(buf, sizeof(buf), "%s", tmp);
312+
cbm_normalize_path_sep(buf);
313+
return buf;
314+
}
315+
const char *home = cbm_get_home_dir();
316+
if (home) {
317+
snprintf(buf, sizeof(buf), "%s/AppData/Roaming", home);
318+
return buf;
319+
}
320+
return NULL;
321+
#else
322+
/* Linux: XDG_CONFIG_HOME or ~/.config */
323+
cbm_safe_getenv("XDG_CONFIG_HOME", tmp, sizeof(tmp), NULL);
324+
if (tmp[0]) {
325+
snprintf(buf, sizeof(buf), "%s", tmp);
326+
return buf;
327+
}
328+
const char *home = cbm_get_home_dir();
329+
if (home) {
330+
snprintf(buf, sizeof(buf), "%s/.config", home);
331+
return buf;
332+
}
333+
return NULL;
334+
#endif /* _WIN32 */
335+
}
336+
337+
const char *cbm_app_local_dir(void) {
338+
#ifdef _WIN32
339+
static char buf[CBM_SZ_1K];
340+
char tmp[CBM_SZ_256] = "";
341+
cbm_safe_getenv("LOCALAPPDATA", tmp, sizeof(tmp), NULL);
342+
if (tmp[0]) {
343+
snprintf(buf, sizeof(buf), "%s", tmp);
344+
cbm_normalize_path_sep(buf);
345+
return buf;
346+
}
347+
const char *home = cbm_get_home_dir();
348+
if (home) {
349+
snprintf(buf, sizeof(buf), "%s/AppData/Local", home);
350+
return buf;
351+
}
352+
return NULL;
353+
#else
354+
return cbm_app_config_dir();
355+
#endif
356+
}

src/foundation/platform.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ const char *cbm_safe_getenv(const char *name, char *buf, size_t buf_sz, const ch
8181
* Returns NULL when neither is set. */
8282
const char *cbm_get_home_dir(void);
8383

84+
/* ── App config directories ────────────────────────────────────── */
85+
86+
/* Cross-platform app config directory (static buffer, not thread-safe).
87+
* Windows: %APPDATA% (e.g. C:/Users/.../AppData/Roaming)
88+
* macOS: $HOME (callers append Library/Application Support/...)
89+
* Linux: $XDG_CONFIG_HOME or ~/.config */
90+
const char *cbm_app_config_dir(void);
91+
92+
/* Windows: %LOCALAPPDATA% (e.g. C:/Users/.../AppData/Local)
93+
* macOS/Linux: same as cbm_app_config_dir(). */
94+
const char *cbm_app_local_dir(void);
95+
8496
/* ── File system ───────────────────────────────────────────────── */
8597

8698
/* Check if a path exists. */

0 commit comments

Comments
 (0)