fix(install): MAGIC_API_KEY false-negative when repo/.env symlink missing

The magic check + link_env grep'd `^MAGIC_API_KEY=` on $REPO/.env, but on a
fresh machine ~/.claude/.env is often created AFTER link.sh runs, so the
repo/.env symlink (which toggle-external.sh sources) is never made — the key
looks absent though it's set, and the warning misleadingly points at
~/.claude/.env.

- install-plugins.sh: self-heal — if ~/.claude/.env exists but repo/.env is
  missing, create the symlink before checking. Accurate message.
- Both: tolerate optional `export ` + leading whitespace and require a
  non-empty value (regex sanity-tested), so common .env formats match.

Immediate fix for an affected machine: `make link`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UyNYwD4UccVw9ZCFZyJX55
This commit is contained in:
Bastien Chanot
2026-06-23 17:30:09 +02:00
co-authored by Claude Opus 4.8
parent 735b62a002
commit 1b028cbc25
2 changed files with 14 additions and 3 deletions
+1 -1
View File
@@ -117,7 +117,7 @@ link_env() {
echo " cp \"$REPO/.env.example\" \"$home_env\" && \"\${EDITOR:-nano}\" \"$home_env\""
return
fi
grep -q '^MAGIC_API_KEY=' "$home_env" 2>/dev/null \
grep -qE '^[[:space:]]*(export[[:space:]]+)?MAGIC_API_KEY=.' "$home_env" 2>/dev/null \
|| echo "⚠️ $home_env has no MAGIC_API_KEY line — magic won't enable until added."
if [ -L "$repo_env" ]; then
[ "$(readlink "$repo_env")" = "$home_env" ] && return