feat(install): CBM_PACKAGE_MANAGED guard + FreeBSD self-path detection - #1331
Open
ocochard wants to merge 1 commit into
Open
feat(install): CBM_PACKAGE_MANAGED guard + FreeBSD self-path detection#1331ocochard wants to merge 1 commit into
ocochard 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.