fix: install.sh adds smoke test, settings verification, and error recovery

The script now: runs the binary with --test after install to verify it
actually works, prints the statusLine JSON that was written to settings,
handles corrupt/invalid settings.json by backing up and writing fresh,
and emphasizes that Claude Code must be restarted to pick up the change.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Taylor Eernisse
2026-02-09 23:54:09 -05:00
parent f94a3170b1
commit f35d665c19

View File

@@ -58,7 +58,8 @@ echo "[ok] Built: $(ls -lh "$BINARY" | awk '{print $5}')"
mkdir -p "$INSTALL_DIR"
cp "$BINARY" "$INSTALL_DIR/$BINARY_NAME"
chmod +x "$INSTALL_DIR/$BINARY_NAME"
echo "[ok] Installed to $INSTALL_DIR/$BINARY_NAME"
BINARY_PATH="$INSTALL_DIR/$BINARY_NAME"
echo "[ok] Installed to $BINARY_PATH"
# Verify it's on PATH
if ! command -v "$BINARY_NAME" &>/dev/null; then
@@ -66,33 +67,50 @@ if ! command -v "$BINARY_NAME" &>/dev/null; then
echo " Add to your shell config: export PATH=\"$INSTALL_DIR:\$PATH\""
fi
# Smoke test — verify the binary actually runs
if "$BINARY_PATH" --test --color=never >/dev/null 2>&1; then
echo "[ok] Binary smoke test passed"
else
echo "[warn] Binary smoke test failed (exit $?). It may still work inside Claude Code."
echo " Debug: $BINARY_PATH --test --dump-state=json"
fi
# ── Configure Claude Code settings.json ──────────────────────────────
echo ""
mkdir -p "$CLAUDE_DIR"
BINARY_PATH="$INSTALL_DIR/$BINARY_NAME"
# The binary runs in a non-TTY context, so force color on.
STATUSLINE_CMD="$BINARY_PATH --color=always"
if [[ -f "$SETTINGS" ]]; then
# Update existing settings.json
# Update existing settings.json, preserving all other keys
CURRENT_CMD=$(jq -r '.statusLine.command // empty' "$SETTINGS" 2>/dev/null || true)
if [[ -n "$CURRENT_CMD" ]]; then
echo "[info] Current statusLine command: $CURRENT_CMD"
echo "[info] Previous statusLine command: $CURRENT_CMD"
fi
# Write updated settings
TMP="$SETTINGS.tmp.$$"
jq --arg cmd "$STATUSLINE_CMD" '.statusLine = {"type": "command", "command": $cmd, "padding": 0}' "$SETTINGS" > "$TMP"
if jq --arg cmd "$STATUSLINE_CMD" '.statusLine = {"type": "command", "command": $cmd, "padding": 0}' "$SETTINGS" > "$TMP" 2>/dev/null; then
mv "$TMP" "$SETTINGS"
echo "[ok] Updated statusLine in $SETTINGS"
else
rm -f "$TMP"
echo "[warn] Failed to update $SETTINGS (invalid JSON?). Creating backup and writing fresh."
cp "$SETTINGS" "$SETTINGS.bak"
jq -n --arg cmd "$STATUSLINE_CMD" '{"statusLine": {"type": "command", "command": $cmd, "padding": 0}}' > "$SETTINGS"
echo "[ok] Wrote fresh $SETTINGS (backup: $SETTINGS.bak)"
fi
else
# Create minimal settings.json
jq -n --arg cmd "$STATUSLINE_CMD" '{"statusLine": {"type": "command", "command": $cmd, "padding": 0}}' > "$SETTINGS"
echo "[ok] Created $SETTINGS"
fi
# Show what was written so the user can verify
echo ""
echo " statusLine config:"
jq '.statusLine' "$SETTINGS" 2>/dev/null || echo " (could not read settings)"
# ── Symlink config ───────────────────────────────────────────────────
CONFIG_SRC="$SCRIPT_DIR/statusline.json"
CONFIG_DST="$CLAUDE_DIR/statusline.json"
@@ -123,7 +141,8 @@ fi
# ── Done ─────────────────────────────────────────────────────────────
echo ""
echo "Done. Restart Claude Code to see the status line."
echo "Done. RESTART Claude Code (exit and reopen) to see the status line."
echo ""
echo "Quick test: $BINARY_NAME --test --color=always"
echo "Debug: $BINARY_NAME --test --dump-state=json"
echo "Verify: $BINARY_PATH --test --color=always"
echo "Debug: $BINARY_PATH --test --dump-state=json"
echo "Settings: cat $SETTINGS | jq .statusLine"