Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

fix: normalize mixed path separators to forward slashes on Windows (#146)

jimparkb23445bdea51
diff --git a/src/foundation/platform.c b/src/foundation/platform.c
index eb60f07ea..f19dae7b2 100644
--- a/src/foundation/platform.c
+++ b/src/foundation/platform.c
@@ -97,6 +97,17 @@ int64_t cbm_file_size(const char *path) {
return (int64_t)sz.QuadPart;
}
+char *cbm_normalize_path_sep(char *path) {
+ if (path) {
+ for (char *p = path; *p; p++) {
+ if (*p == '\\') {
+ *p = '/';
+ }
+ }
+ }
+ return path;
+}
+
#else /* POSIX (macOS + Linux) */
/* ── POSIX implementation ─────────────────────────────────────── */
@@ -215,20 +226,31 @@ int64_t cbm_file_size(const char *path) {
return (int64_t)st.st_size;
}
+char *cbm_normalize_path_sep(char *path) {
+ /* No-op on POSIX — paths already use forward slashes. */
+ (void)path;
+ return path;
+}
+
#endif /* _WIN32 */
/* ── Home directory (cross-platform) ──────────────────────────── */
const char *cbm_get_home_dir(void) {
+ static char buf[1024];
// NOLINTNEXTLINE(concurrency-mt-unsafe)
const char *h = getenv("HOME");
if (h && h[0]) {
- return h;
+ snprintf(buf, sizeof(buf), "%s", h);
+ cbm_normalize_path_sep(buf);
+ return buf;
}
// NOLINTNEXTLINE(concurrency-mt-unsafe)
h = getenv("USERPROFILE");
if (h && h[0]) {
- return h;
+ snprintf(buf, sizeof(buf), "%s", h);
+ cbm_normalize_path_sep(buf);
+ return buf;
}
return NULL;
}
diff --git a/src/foundation/platform.h b/src/foundation/platform.h
index e88ab068b..62e9dca84 100644
--- a/src/foundation/platform.h
+++ b/src/foundation/platform.h
@@ -81,4 +81,9 @@ bool cbm_is_dir(const char *path);
/* Get file size. Returns -1 on error. */
int64_t cbm_file_size(const char *path);
+/* Normalize path separators to forward slashes (in-place).
+ * On Windows, converts backslashes to forward slashes.
+ * On POSIX, this is a no-op. Returns the input pointer. */
+char *cbm_normalize_path_sep(char *path);
+
#endif /* CBM_PLATFORM_H */
diff --git a/src/mcp/mcp.c b/src/mcp/mcp.c
index 4542584b8..3530acc30 100644
--- a/src/mcp/mcp.c
+++ b/src/mcp/mcp.c
@@ -1423,6 +1423,7 @@ static char *get_project_root(cbm_mcp_server_t *srv, const char *project) {
static char *handle_index_repository(cbm_mcp_server_t *srv, const char *args) {
char *repo_path = cbm_mcp_get_string_arg(args, "repo_path");
char *mode_str = cbm_mcp_get_string_arg(args, "mode");
+ cbm_normalize_path_sep(repo_path);
if (!repo_path) {
free(mode_str);
@@ -1584,13 +1585,14 @@ static char *build_snippet_response(cbm_mcp_server_t *srv, cbm_node_t *node,
#ifdef _WIN32
if (_fullpath(real_root, root_path, sizeof(real_root)) &&
_fullpath(real_file, abs_path, sizeof(real_file))) {
+ cbm_normalize_path_sep(real_root);
+ cbm_normalize_path_sep(real_file);
#else
if (realpath(root_path, real_root) && realpath(abs_path, real_file)) {
#endif
size_t root_len = strlen(real_root);
if (strncmp(real_file, real_root, root_len) == 0 &&
- (real_file[root_len] == '/' || real_file[root_len] == '\\' ||
- real_file[root_len] == '\0')) {
+ (real_file[root_len] == '/' || real_file[root_len] == '\0')) {
path_ok = true;
}
}
diff --git a/src/pipeline/fqn.c b/src/pipeline/fqn.c
index 7c86e1a98..0936c78c0 100644
--- a/src/pipeline/fqn.c
+++ b/src/pipeline/fqn.c
@@ -5,6 +5,7 @@
* Handles Python __init__.py, JS/TS index.{js,ts}, path separators.
*/
#include "pipeline/pipeline.h"
+#include "foundation/platform.h"
#include <stddef.h> // NULL
#include <stdio.h>
@@ -58,12 +59,8 @@ char *cbm_pipeline_fqn_compute(const char *project, const char *rel_path, const
/* Work on a mutable copy for path manipulation */
char *path = strdup(rel_path ? rel_path : "");
- /* Convert backslash to forward slash */
- for (char *p = path; *p; p++) {
- if (*p == '\\') {
- *p = '/';
- }
- }
+ /* Normalize path separators */
+ cbm_normalize_path_sep(path);
/* Strip file extension */
{
@@ -136,11 +133,7 @@ char *cbm_pipeline_fqn_folder(const char *project, const char *rel_dir) {
/* Work on mutable copy */
char *dir = strdup(rel_dir ? rel_dir : "");
- for (char *p = dir; *p; p++) {
- if (*p == '\\') {
- *p = '/';
- }
- }
+ cbm_normalize_path_sep(dir);
const char *segments[256];
int seg_count = 0;
@@ -174,12 +167,8 @@ char *cbm_project_name_from_path(const char *abs_path) {
char *path = strdup(abs_path);
size_t len = strlen(path);
- /* Convert \ to / */
- for (size_t i = 0; i < len; i++) {
- if (path[i] == '\\') {
- path[i] = '/';
- }
- }
+ /* Normalize path separators */
+ cbm_normalize_path_sep(path);
/* Replace / and : with - */
for (size_t i = 0; i < len; i++) {