fix(bird): put Brave wrapper first on PATH and check the wiring

This commit is contained in:
hermes committed 2026-11-29 10:37:58 -05:00
1 parent 8378ac41fd
commit 72a23ff0d0
3 files changed
+72 -4

No files matched your search

+10 -4
View File
@@ -71,6 +71,10 @@ in
syntaxHighlighting.enable = true; # commands turn green when valid
initContent = ''
bindkey '^f' autosuggest-accept
# Brave-only bird wrapper wins over Homebrew's npm bird shim. zshrc runs
# after .zprofile, whose brew shellenv puts /opt/homebrew/bin first.
typeset -U path
path=("$HOME/.pi/agent/bin" $path)
# Keep the OpenCode Go CLI, Pi, no-mistakes, and Hermes key aligned with
# the desktop app login after an account switch.
if [ -x "$HOME/.local/bin/opencode-go-key-sync" ]; then
@@ -295,10 +299,12 @@ in
# Brave-only bird reader. The config points bird's Chromium source at Brave;
# the wrapper decrypts Brave cookies with the Brave Safe Storage key and
# hands them to bird as env vars. PATH puts ~/.pi/agent/bin before Homebrew,
# so `bird` resolves to this wrapper. force = true on the config is needed
# once: a pre-existing unmanaged ~/.config/bird/config.json5 would otherwise
# make home-manager refuse the switch. The wrapper path is new, so no force.
# hands them to bird as env vars. The session PATH puts ~/.pi/agent/bin
# before Homebrew, so `bird` resolves to this wrapper and not the npm shim.
# force = true on the config is needed once: a pre-existing unmanaged
# ~/.config/bird/config.json5 would otherwise make home-manager refuse the
# switch. The wrapper path is new, so no force.
home.sessionPath = [ "${home}/.pi/agent/bin" ];
home.file.".config/bird/config.json5" = {
source = config.lib.file.mkOutOfStoreSymlink "${dotfiles}/home/.config/bird/config.json5";
force = true;
+61
View File
@@ -0,0 +1,61 @@
#!/usr/bin/env bash
# Check that the Nix source wires the Brave-only bird wrapper into the shell.
#
# The Bird merge added home.file entries for the wrapper and the Brave config,
# but no PATH entry. A rebuild installs the wrapper at ~/.pi/agent/bin/bird and
# leaves `bird` resolving to Homebrew's npm shim. This check evaluates the real
# home-manager config, then runs the generated zshrc in a fresh zsh with a fake
# Homebrew bird ahead of the wrapper. It passes only when the wrapper wins.
set -euo pipefail
ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)
TMP=$(mktemp -d "${TMPDIR:-/tmp}/bird-path.XXXXXX")
trap 'rm -rf "$TMP"' EXIT
fail() { printf 'FAIL: %s\n' "$1" >&2; exit 1; }
pass() { printf 'PASS: %s\n' "$1"; }
command -v nix >/dev/null 2>&1 \
|| { echo "bird-path: nix is required to evaluate the configuration" >&2; exit 2; }
command -v jq >/dev/null 2>&1 \
|| { echo "bird-path: jq is required to read the session path" >&2; exit 2; }
command -v zsh >/dev/null 2>&1 \
|| { echo "bird-path: zsh is required to run the generated zshrc" >&2; exit 2; }
CONFIG='(builtins.getFlake (toString '"$ROOT"')).darwinConfigurations."lt-mbp".config.home-manager.users.laptran'
wrapper_source=$(nix eval --raw --impure --expr "$CONFIG.home.file.\".pi/agent/bin/bird\".source")
wrapper_target=$(readlink "$wrapper_source" 2>/dev/null || printf '%s' "$wrapper_source")
case "$wrapper_target" in
*"home/.pi/agent/bin/bird") pass "source declares the Brave-only bird wrapper" ;;
*) fail "wrapper home.file source points to $wrapper_target" ;;
esac
nix eval --json --impure --expr "$CONFIG.home.sessionPath" > "$TMP/session-path.json"
first_path=$(jq -r '.[0] // ""' "$TMP/session-path.json")
case "$first_path" in
*"/.pi/agent/bin") pass "session PATH puts the wrapper directory first" ;;
*) fail "first session PATH entry is '$first_path', not the bird wrapper directory" ;;
esac
nix eval --raw --impure --expr "$CONFIG.home.file.\"./.zshrc\".text" > "$TMP/zshrc"
mkdir -p "$TMP/home/.pi/agent/bin" "$TMP/homebrew/bin"
printf '#!/bin/sh\nprintf wrapper\n' > "$TMP/home/.pi/agent/bin/bird"
printf '#!/bin/sh\nprintf homebrew\n' > "$TMP/homebrew/bin/bird"
chmod +x "$TMP/home/.pi/agent/bin/bird" "$TMP/homebrew/bin/bird"
resolved=$(HOME="$TMP/home" ZSHRC="$TMP/zshrc" \
PATH="$TMP/homebrew/bin:/usr/bin:/bin" \
timeout 60 zsh -f -i -c '
source "$ZSHRC" >/dev/null 2>&1 || exit 4
command -v bird
' 2>"$TMP/stderr") || {
echo "bird-path: failed to run generated zshrc" >&2
cat "$TMP/stderr" >&2
exit 2
}
[ "$resolved" = "$TMP/home/.pi/agent/bin/bird" ] \
|| fail "generated zshrc resolves bird to $resolved instead of the wrapper"
pass "generated zshrc resolves bird to the wrapper ahead of Homebrew"
+1
View File
@@ -14,5 +14,6 @@ status=0
"$ROOT/tests/crew-dispatch.sh" || status=1
"$ROOT/tests/rebuild-update-steps.sh" || status=1
"$ROOT/tests/bird-brave-e2e.sh" || status=1
"$ROOT/tests/bird-path.sh" || status=1
exit "$status"