|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +GREEN='\033[0;32m' |
| 5 | +YELLOW='\033[1;33m' |
| 6 | +RED='\033[0;31m' |
| 7 | +DIM='\033[2m' |
| 8 | +BOLD='\033[1m' |
| 9 | +NC='\033[0m' |
| 10 | + |
| 11 | +info() { printf "${GREEN}[mesa]${NC} %s\n" "$1"; } |
| 12 | +warn() { printf "${YELLOW}[mesa]${NC} %s\n" "$1"; } |
| 13 | +error() { printf "${RED}[mesa]${NC} %s\n" "$1" >&2; exit 1; } |
| 14 | +dim() { printf "${DIM}[mesa]${NC} %s\n" "$1"; } |
| 15 | + |
| 16 | +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 17 | + |
| 18 | +# --------------------------------------------------------------------------- |
| 19 | +# Detect context: are we inside the local dev repo or a clone? |
| 20 | +# --------------------------------------------------------------------------- |
| 21 | +is_local_repo() { |
| 22 | + [ -f "$SCRIPT_DIR/package.json" ] && grep -q '"opencode-mesa"' "$SCRIPT_DIR/package.json" 2>/dev/null |
| 23 | +} |
| 24 | + |
| 25 | +CLONE_DIR="$HOME/.local/share/opencode-mesa" |
| 26 | +AGENTS_DIR="$HOME/.config/opencode/agents" |
| 27 | +CONFIG_DIR="$HOME/.config/opencode" |
| 28 | +CONFIG_FILE="$CONFIG_DIR/opencode.json" |
| 29 | + |
| 30 | +REMOVE_HELPER="" |
| 31 | +if is_local_repo; then |
| 32 | + REMOVE_HELPER="$SCRIPT_DIR/src/setup/remove-plugin.cjs" |
| 33 | +else |
| 34 | + # Running from a clone or elsewhere — try clone location first, then local |
| 35 | + if [ -f "$CLONE_DIR/src/setup/remove-plugin.cjs" ]; then |
| 36 | + REMOVE_HELPER="$CLONE_DIR/src/setup/remove-plugin.cjs" |
| 37 | + elif [ -f "$SCRIPT_DIR/src/setup/remove-plugin.cjs" ]; then |
| 38 | + REMOVE_HELPER="$SCRIPT_DIR/src/setup/remove-plugin.cjs" |
| 39 | + fi |
| 40 | +fi |
| 41 | + |
| 42 | +# --------------------------------------------------------------------------- |
| 43 | +# Collect what will be removed |
| 44 | +# --------------------------------------------------------------------------- |
| 45 | +TO_REMOVE=() |
| 46 | + |
| 47 | +BRIEFING_FILE="" |
| 48 | +MANAGER_FILE="" |
| 49 | +MESA_DIR="" |
| 50 | +PLUGIN_ENTRY=false |
| 51 | +CLONE_PATH="" |
| 52 | + |
| 53 | +if [ -f "$AGENTS_DIR/briefing-writer.md" ]; then |
| 54 | + BRIEFING_FILE="$AGENTS_DIR/briefing-writer.md" |
| 55 | + TO_REMOVE+=("$BRIEFING_FILE") |
| 56 | +fi |
| 57 | + |
| 58 | +if [ -f "$AGENTS_DIR/manager.md" ]; then |
| 59 | + MANAGER_FILE="$AGENTS_DIR/manager.md" |
| 60 | + TO_REMOVE+=("$MANAGER_FILE") |
| 61 | +fi |
| 62 | + |
| 63 | +if [ -d "$AGENTS_DIR/mesa" ]; then |
| 64 | + MESA_DIR="$AGENTS_DIR/mesa" |
| 65 | + MESA_COUNT=$(find "$MESA_DIR" -maxdepth 1 -name "*.md" 2>/dev/null | wc -l | tr -d ' ') |
| 66 | + TO_REMOVE+=("$MESA_DIR ($MESA_COUNT files)") |
| 67 | +fi |
| 68 | + |
| 69 | +if [ -f "$CONFIG_FILE" ] && grep -q "opencode-mesa" "$CONFIG_FILE" 2>/dev/null; then |
| 70 | + PLUGIN_ENTRY=true |
| 71 | + TO_REMOVE+=("plugin entry in $CONFIG_FILE") |
| 72 | +fi |
| 73 | + |
| 74 | +if [ -d "$CLONE_DIR" ] && ! is_local_repo; then |
| 75 | + CLONE_PATH="$CLONE_DIR" |
| 76 | + TO_REMOVE+=("$CLONE_PATH (clone)") |
| 77 | +fi |
| 78 | + |
| 79 | +# --------------------------------------------------------------------------- |
| 80 | +# Nothing to do? |
| 81 | +# --------------------------------------------------------------------------- |
| 82 | +if [ ${#TO_REMOVE[@]} -eq 0 ]; then |
| 83 | + info "Nothing to uninstall — no Mesa artifacts found." |
| 84 | + exit 0 |
| 85 | +fi |
| 86 | + |
| 87 | +# --------------------------------------------------------------------------- |
| 88 | +# Show summary + prompt |
| 89 | +# --------------------------------------------------------------------------- |
| 90 | +printf "\n" |
| 91 | +printf "${BOLD}[mesa]${NC} This will remove:\n" |
| 92 | +for item in "${TO_REMOVE[@]}"; do |
| 93 | + printf " ${RED}-${NC} %s\n" "$item" |
| 94 | +done |
| 95 | +printf "\n" |
| 96 | + |
| 97 | +read -r -p "Continue? [y/N] " response |
| 98 | +case "$response" in |
| 99 | + [yY][eE][sS]|[yY]) ;; |
| 100 | + *) |
| 101 | + info "Aborted." |
| 102 | + exit 0 |
| 103 | + ;; |
| 104 | +esac |
| 105 | + |
| 106 | +# --------------------------------------------------------------------------- |
| 107 | +# Execute removal |
| 108 | +# --------------------------------------------------------------------------- |
| 109 | +printf "\n" |
| 110 | + |
| 111 | +if [ -n "$BRIEFING_FILE" ]; then |
| 112 | + rm -f "$BRIEFING_FILE" |
| 113 | + info "Removed $BRIEFING_FILE" |
| 114 | +fi |
| 115 | + |
| 116 | +if [ -n "$MANAGER_FILE" ]; then |
| 117 | + rm -f "$MANAGER_FILE" |
| 118 | + info "Removed $MANAGER_FILE" |
| 119 | +fi |
| 120 | + |
| 121 | +if [ -n "$MESA_DIR" ]; then |
| 122 | + rm -rf "$MESA_DIR" |
| 123 | + info "Removed $MESA_DIR ($MESA_COUNT files)" |
| 124 | +fi |
| 125 | + |
| 126 | +if $PLUGIN_ENTRY; then |
| 127 | + if [ -n "$REMOVE_HELPER" ] && [ -f "$REMOVE_HELPER" ]; then |
| 128 | + node "$REMOVE_HELPER" "$CONFIG_FILE" |
| 129 | + else |
| 130 | + # Fallback: remove via sed (best-effort, single-line plugin entries) |
| 131 | + # This handles the common case where the plugin line is a single string entry. |
| 132 | + sed -i.bak '/"file:.*opencode-mesa/d' "$CONFIG_FILE" 2>/dev/null || true |
| 133 | + sed -i.bak '/file:\/\/.*opencode-mesa/d' "$CONFIG_FILE" 2>/dev/null || true |
| 134 | + rm -f "${CONFIG_FILE}.bak" 2>/dev/null || true |
| 135 | + info "Removed plugin entry from $CONFIG_FILE (fallback sed)" |
| 136 | + warn "Config may need manual cleanup — verify $CONFIG_FILE is valid JSON" |
| 137 | + fi |
| 138 | +fi |
| 139 | + |
| 140 | +if [ -n "$CLONE_PATH" ]; then |
| 141 | + rm -rf "$CLONE_PATH" |
| 142 | + info "Removed clone at $CLONE_PATH" |
| 143 | +fi |
| 144 | + |
| 145 | +printf "\n" |
| 146 | +info "${BOLD}Done.${NC} Restart opencode to fully unload the plugin." |
| 147 | +info "Note: your opencode.json config was preserved (only the Mesa plugin entry was removed)." |
0 commit comments