From db9d9f3f599a542b6014f23821f930b76c9a051d Mon Sep 17 00:00:00 2001 From: roboomp Date: Sun, 28 Jun 2026 04:27:03 +0000 Subject: [PATCH] fix(setup): harden global omp symlink against bun pm -g bin failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The root `setup` script used `ln -sfn ... "$(bun pm -g bin)/omp"`. On fresh hosts where `$HOME/.bun/install/global/package.json` is missing `bun pm -g bin` aborts with "No package.json was found", the command substitution expands to empty, and `ln` tries to write `/omp` — failing with `Permission denied` (or, on a writable filesystem, silently linking under `/`). Move the logic into `scripts/link-omp.sh`: - Capture `bun pm -g bin` and ignore its failure. - Fall back to `${BUN_INSTALL:-$HOME/.bun}/bin`, matching Bun's own install convention. - `mkdir -p` the target so the link works even when nothing has yet populated the global bin dir. Fixes #3701 --- package.json | 2 +- scripts/link-omp.sh | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100755 scripts/link-omp.sh diff --git a/package.json b/package.json index e4bd931b3..4bb6baadb 100644 --- a/package.json +++ b/package.json @@ -94,7 +94,7 @@ }, "overrides": {}, "scripts": { - "setup": "bun install && bun run build:native && bun --cwd=packages/coding-agent link && ln -sfn \"$(pwd)/packages/coding-agent/scripts/omp\" \"$(bun pm -g bin)/omp\"", + "setup": "bun install && bun run build:native && bun --cwd=packages/coding-agent link && sh scripts/link-omp.sh", "dev": "bun --cwd=packages/coding-agent src/cli.ts", "dev:timing": "PI_TIMING=x bun --cwd=packages/coding-agent --preload ../utils/src/module-timer.ts src/cli.ts", "stats": "bun --cwd=packages/coding-agent src/cli.ts stats", diff --git a/scripts/link-omp.sh b/scripts/link-omp.sh new file mode 100755 index 000000000..1d58a387f --- /dev/null +++ b/scripts/link-omp.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# Install the dev `omp` wrapper into Bun's global bin directory. +# +# Replaces the bun-shebang symlink that `bun --cwd=packages/coding-agent link` +# creates (pointing at `src/cli.ts`) with the safer wrapper at +# `packages/coding-agent/scripts/omp`. See that wrapper's header comment for the +# bunfig.toml-preload bug it works around. +# +# We resolve Bun's global bin path defensively because `bun pm -g bin` aborts +# (`No package.json was found for directory "$HOME/.bun/install/global"`) on +# fresh hosts where the global install has not been initialized. Falling +# through that error would expand `$(bun pm -g bin)/omp` to `/omp` and try to +# write under `/` — see https://github.com/can1357/oh-my-pi/issues/3701. +set -e + +repo_root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd -P) +target=$repo_root/packages/coding-agent/scripts/omp + +if [ ! -x "$target" ]; then + echo "link-omp: target wrapper not found or not executable: $target" >&2 + exit 1 +fi + +global_bin=$(bun pm -g bin 2>/dev/null || true) +if [ -z "$global_bin" ]; then + global_bin=${BUN_INSTALL:-$HOME/.bun}/bin +fi + +mkdir -p "$global_bin" +ln -sfn "$target" "$global_bin/omp" +echo "link-omp: linked $global_bin/omp -> $target"