feat(install): CBM_PACKAGE_MANAGED guard + FreeBSD self-path detection - #1331
feat(install): CBM_PACKAGE_MANAGED guard + FreeBSD self-path detection#1331ocochard wants to merge 1 commit into
Conversation
…path
When built with -DCBM_PACKAGE_MANAGED, `install` no longer mutates the
user's $HOME and wires agent configs to the real installed binary:
- skips copying the running binary into ~/.local/bin (the package manager
already owns it under its prefix), and
- skips appending `export PATH=...` to the shell rc, and
- points bin_target (hence the MCP `command` written into .claude.json,
.mcp.json, etc.) at the running executable instead of the hardcoded
~/.local/bin path.
Also add a FreeBSD self-path branch: cbm_detect_self_path() used
readlink("/proc/self/exe"), but FreeBSD has no /proc by default, so it
silently fell back to ~/.local/bin — writing that wrong path into every
agent config. Use sysctl KERN_PROC_PATHNAME, which needs no /proc.
The flag is off by default; source installs (scripts/build.sh) are
unchanged. Non-FreeBSD self-path detection is unchanged.
|
Thank you for this — the diagnosis is correct and the flag design is genuinely careful. Three things: one you can fix now, one that is not your fault, and one that needs the maintainer. Your FreeBSD diagnosis is exactly right. FreeBSD mounts no The flag design is genuinely additive, and I verified that rather than taking it on trust. With One thing to fix now: the DCO check is a genuine failure. Commit The sign-off email needs to match your commit author email. That alone blocks the merge regardless of everything else. One failure that is not yours: One defect worth fixing while you are in there. Under Minor style note: What needs the maintainer, and why I am not deciding it: Relatedly, and worth knowing: the The work itself is tidy and the packaging motivation is legitimate — this is a policy question, not a quality one. |
Problems
When installed by a package manager (FreeBSD ports, Homebrew, distro pkg),
codebase-memory-mcp installmisbehaves in two ways:Mutates
$HOME— copies the running binary into~/.local/bin(a second, unmanaged copy of a file the package manager already owns under its prefix) and appendsexport PATH="~/.local/bin:$PATH"to the user's shell rc. Both are redundant: the binary is already onPATHvia the manager's prefix.Writes the wrong binary path into agent configs on FreeBSD.
cbm_detect_self_path()usedreadlink("/proc/self/exe"), but FreeBSD has no/procmounted by default, so detection failed and silently fell back to~/.local/bin/codebase-memory-mcp. That bogus path was then written as the MCPcommandinto.claude.json/.mcp.json, so the agent could never launch the server.Fix
Add a compile-time guard
CBM_PACKAGE_MANAGED(off by default; follows the existing-DCBM_*build-flag convention). When set,install:~/.local/binbinary copy (do_copy = false),source <rc>hint), andbin_target— hence the MCPcommandwritten into every agent config — at the running executable instead of the hardcoded~/.local/binpath.Separately (all platforms, not gated): add a FreeBSD branch to
cbm_detect_self_path()usingsysctlKERN_PROC_PATHNAME, which resolves the running executable without/proc. Non-FreeBSD detection is unchanged.Verification
Built on FreeBSD with
-DCBM_PACKAGE_MANAGED(via thedevel/codebase-memory-mcpport, clean poudriere jail,-Werror, no warnings). Runningcodebase-memory-mcp installagainst a seeded Claude Code config now writes:{ "mcpServers": { "codebase-memory-mcp": { "command": "/usr/local/bin/codebase-memory-mcp" } } }No
~/.local/binpath anywhere, no shell rc touched. Source installs (scripts/build.sh, flag off) are unaffected.