aboutsummaryrefslogtreecommitdiff
path: root/devel/codebase-memory-mcp/files/patch-src_cli_cli.c
blob: 3edabd31ea2ddd1219243cc326666932b693a930 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
--- src/cli/cli.c.orig	2026-08-18 20:39:59 UTC
+++ src/cli/cli.c
@@ -8178,7 +8178,12 @@ static void cbm_agent_installed_binary_path(const char
 
 static void cbm_agent_installed_binary_path(const char *home, char *binary_path,
                                             size_t binary_path_size) {
-#ifdef _WIN32
+#if defined(__FreeBSD__) && defined(CBM_PKG_PREFIX)
+    /* The port/pkg install the binary under ${PREFIX}/bin, not ~/.local/bin, so
+     * agent configs (mcp.json, hooks) must point there. */
+    (void)home;
+    snprintf(binary_path, binary_path_size, CBM_PKG_PREFIX "/bin/codebase-memory-mcp");
+#elif defined(_WIN32)
     snprintf(binary_path, binary_path_size, "%s/.local/bin/codebase-memory-mcp.exe", home);
 #else
     snprintf(binary_path, binary_path_size, "%s/.local/bin/codebase-memory-mcp", home);
@@ -9699,6 +9704,16 @@ static const char *cli_external_manager_name(const cha
     if (strstr(self_path, "/.cargo/bin/")) {
         return "cargo";
     }
+#if defined(__FreeBSD__) && defined(CBM_PKG_PREFIX)
+    /* FreeBSD ports/pkg install the binary under ${PREFIX}/bin (CBM_PKG_PREFIX
+     * is the port's PREFIX, default /usr/local). pkg owns that file, so install
+     * must not copy it into ~/.local/bin or edit PATH, and update must refuse
+     * and defer to pkg(8). Match only ${PREFIX}/bin/ so a manual --dir install
+     * elsewhere is still treated as ours. */
+    if (strstr(self_path, CBM_PKG_PREFIX "/bin/") == self_path) {
+        return "FreeBSD pkg";
+    }
+#endif
     return NULL;
 }
 
@@ -10117,6 +10132,13 @@ int cbm_cmd_install(int argc, char **argv) {
                    manager ? " by " : "", manager ? manager : "", self_path, bin_dir);
         }
         skip_binary = true;
+        /* We are not placing a binary, so agent configs must reference the one
+         * that is actually running, not the ~/.local/bin default that no file
+         * lives at (#pkg: FreeBSD ports install under /usr/local/bin). Retarget
+         * to the OS-reported self path when we have it. */
+        if (self_path_exact && self_path[0]) {
+            snprintf(bin_target, sizeof(bin_target), "%s", self_path);
+        }
     }
 
     /* NOT stat(): on Windows it goes through the ANSI code page, so an
@@ -12227,6 +12249,8 @@ int cbm_cmd_update(int argc, char **argv) {
                 (void)fprintf(stderr, "  update it with: mise upgrade codebase-memory-mcp\n");
             } else if (manager && strcmp(manager, "Homebrew") == 0) {
                 (void)fprintf(stderr, "  update it with: brew upgrade codebase-memory-mcp\n");
+            } else if (manager && strcmp(manager, "FreeBSD pkg") == 0) {
+                (void)fprintf(stderr, "  update it with: pkg upgrade codebase-memory-mcp\n");
             } else {
                 (void)fprintf(stderr, "  update it through whichever tool installed it.\n");
             }