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.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
refactor(cli): install scripts own updating; the binary carries no URL
Martin Vogelafd67c51b0bf
diff --git a/install.ps1 b/install.ps1index f455c983d..890dfd4f8 100644--- a/install.ps1+++ b/install.ps1@@ -300,6 +300,28 @@ if ($LASTEXITCODE -ne 0) {exit 1}+# Place the installer beside the binary so `update` points at a local file+# rather than a URL, and so the next update runs THIS release's installer.+#+# Sourced from the archive we just checksum-verified, and published by rename+# rather than written over the live path. PowerShell parses a script fully+# before executing it, so self-overwrite is less hazardous here than it is for+# bash -- but rename costs nothing and keeps both platforms on one rule.+# Best effort: a failure here still leaves a working install.+$DownloadedInstaller = Join-Path $TmpDir "install.ps1"+if (Test-Path -LiteralPath $DownloadedInstaller -PathType Leaf) {+ $InstallerDest = Join-Path $InstallDir "install.ps1"+ $InstallerTmp = "$InstallerDest.new"+ try {+ Copy-Item -LiteralPath $DownloadedInstaller -Destination $InstallerTmp -Force -ErrorAction Stop+ Move-Item -LiteralPath $InstallerTmp -Destination $InstallerDest -Force -ErrorAction Stop+ Write-Host "Installed updater -> $InstallerDest"+ } catch {+ Remove-Item -LiteralPath $InstallerTmp -Force -ErrorAction SilentlyContinue+ Write-Host "note: could not place install.ps1 in $InstallDir (update will explain where to find it)"+ }+}+# Verifytry {$ver = & $Dest --version 2>&1diff --git a/install.sh b/install.shindex 423464159..e58a28294 100755--- a/install.sh+++ b/install.sh@@ -268,6 +268,32 @@ if [ "$SKIP_CONFIG" = true ]; thenfi"$DLBIN" install "${INSTALL_ARGS[@]}"+# Place the installer beside the binary so `update` can point at a local file+# instead of a URL, and so the next update uses THIS release's installer.+#+# Two things make this safe. The source is the copy from the archive we just+# checksum-verified -- never "$0", which does not exist under `curl | bash` and+# would pin us to the OLD installer forever. And it is published by atomic+# rename, never by writing over the live path: bash reads a script incrementally+# by byte offset, so overwriting the file it is executing continues reading the+# NEW bytes at the OLD offset. That fails silently and bizarrely, which is worse+# than failing loudly.+#+# Best effort by design: a user who cannot write to INSTALL_DIR still gets a+# working install, and `update` falls back to explaining where to find it.+DL_INSTALLER="$DLDIR/install.sh"+if [ -f "$DL_INSTALLER" ]; then+ INSTALLER_TMP="$INSTALL_DIR/.install.sh.$$"+ if cp "$DL_INSTALLER" "$INSTALLER_TMP" 2>/dev/null &&+ chmod 755 "$INSTALLER_TMP" 2>/dev/null &&+ mv -f "$INSTALLER_TMP" "$INSTALL_DIR/install.sh" 2>/dev/null; then+ echo "Installed updater -> $INSTALL_DIR/install.sh"+ else+ rm -f "$INSTALLER_TMP" 2>/dev/null || true+ echo "note: could not place install.sh in $INSTALL_DIR (update will explain where to find it)"+ fi+fi+# VerifyVERSION=$("$DEST" --version 2>&1) || {echo "error: installed binary failed to run" >&2diff --git a/scripts/security-allowlist.txt b/scripts/security-allowlist.txtindex 6c7fea9ca..efe9b37f8 100644--- a/scripts/security-allowlist.txt+++ b/scripts/security-allowlist.txt@@ -66,7 +66,6 @@ src/ui/http_server.c:execl:exec indexing binary in child processURL:https://api.github.com/repos/DeusData/codebase-memory-mcp/releases/latest:update checkURL:https://github.com/DeusData/codebase-memory-mcp/releases/latest/download:binary download + checksumsURL:https://github.com/DeusData/codebase-memory-mcp/releases/latest:version check via redirect header-URL:https://raw.githubusercontent.com/DeusData/codebase-memory-mcp/main/install.sh:printed by `update` as the install-script command when install.sh is not beside the binary (a string in the message, not a network call - the binary no longer downloads anything)URL:http://127.0.0.1:UI server binding (localhost only)URL:https://www.sqlite.org/c3ref/c_checkpoint_full.html:sqlite WAL checkpoint API doc reference (comment only, not a network call)URL:https://github.com/DeusData/codebase-memory-mcp:project repository self-reference in update/star notice (src/mcp/mcp.c)diff --git a/scripts/smoke-test.sh b/scripts/smoke-test.shindex d1d5e0c06..2e7fded67 100755--- a/scripts/smoke-test.sh+++ b/scripts/smoke-test.sh@@ -151,7 +151,27 @@ fitrap 'smoke_rmtree "$TMPDIR" "${DRYRUN_HOME:-}"' EXITCLI_STDERR=$(smoke_mktemp_file)-cli() { "$BINARY" cli "$@" 2>"$CLI_STDERR"; }+# 10 of the cli call sites assign directly (VAR=$(cli ...)). Under+# `set -euo pipefail` a non-zero exit there kills the smoke with NOTHING+# printed: no FAIL line, no stderr, just an abort indistinguishable from a hang,+# a starved runner, or a real regression. One such abort cost a full Windows+# cycle just to locate, and still could not be attributed. Surface the command+# and its stderr here, while we still can.+#+# Neutral wording on purpose: one call site deliberately expects a non-zero exit+# (the unknown-function query must error loudly), so this must not read as a+# failure on its own.+cli() {+ local rc=0+ "$BINARY" cli "$@" 2>"$CLI_STDERR" || rc=$?+ if [ "$rc" -ne 0 ]; then+ {+ printf 'cli: `%s` exited %s\n' "$*" "$rc"+ sed 's/^/ /' "$CLI_STDERR" 2>/dev/null+ } >&2+ fi+ return "$rc"+}echo "=== Phase 1: version ==="VERSION_STATUS=0diff --git a/src/cli/cli.c b/src/cli/cli.cindex 8413bad12..8d60e6994 100644--- a/src/cli/cli.c+++ b/src/cli/cli.c@@ -11168,12 +11168,6 @@ static bool check_already_latest(void) {#endif /* CBM_CLI_ENABLE_TEST_API */-/* One token on purpose: the security audit extracts URLs literally, so a URL- * split across string-literal continuations cannot be matched against the- * allow-list. Printed for the user to paste; never fetched by this binary. */-#define CBM_INSTALL_SH_URL \- "https://raw.githubusercontent.com/DeusData/codebase-memory-mcp/main/install.sh"-int cbm_cmd_update(int argc, char **argv) {parse_auto_answer(argc, argv);@@ -11253,7 +11247,9 @@ int cbm_cmd_update(int argc, char **argv) {if (have_dir) {printf(" powershell -ExecutionPolicy Bypass -File \"%s\\install.ps1\"\n\n", self_dir);} else {- printf(" powershell -ExecutionPolicy Bypass -File install.ps1\n\n");+ printf(" powershell -ExecutionPolicy Bypass -File install.ps1\n"+ " (ships in the release archive, and is placed beside the\n"+ " binary on install)\n\n");}printf("It downloads the latest release, verifies its checksum, and replaces\n""this binary in place. If PowerShell refuses to run the script because\n"@@ -11263,7 +11259,8 @@ int cbm_cmd_update(int argc, char **argv) {if (have_dir) {printf(" bash \"%s/install.sh\"\n\n", self_dir);} else {- printf(" curl -fsSL " CBM_INSTALL_SH_URL " | bash\n\n");+ printf(" install.sh (ships in the release archive, and is placed\n"+ " beside the binary on install)\n\n");}printf("It downloads the latest release, verifies its checksum, and replaces\n""this binary in place. install.sh is idempotent, so re-running it IS\n"