-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·444 lines (385 loc) · 11.8 KB
/
uninstall.sh
File metadata and controls
executable file
·444 lines (385 loc) · 11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
#!/bin/bash
set -e
PILOT_DIR="$HOME/.pilot"
CLAUDE_DIR="$HOME/.claude"
PILOT_PLUGIN_DIR="$CLAUDE_DIR/pilot"
MANIFEST_FILE="$CLAUDE_DIR/.pilot-manifest.json"
CLAUDE_ALIAS_MARKER="# Pilot Shell"
OLD_CLAUDE_PILOT_MARKER="# Claude Pilot"
OLD_CCP_MARKER="# Claude CodePro alias"
removed_items=()
get_pilot_version() {
local pilot_path="$PILOT_DIR/bin/pilot"
if [ -x "$pilot_path" ]; then
local version
version=$("$pilot_path" --version 2>/dev/null | sed -n 's/.* v\([^ ]*\).*/\1/p') || true
if [ -n "$version" ]; then
echo "$version"
return
fi
fi
echo "unknown"
}
get_manifest_entries() {
if [ ! -f "$MANIFEST_FILE" ]; then
return
fi
grep -oE '"[a-z]+/[^"]+"' "$MANIFEST_FILE" 2>/dev/null | sed 's/"//g' || true
}
get_affected_shell_configs() {
local config_files=(
"$HOME/.bashrc"
"$HOME/.bash_profile"
"$HOME/.zshrc"
"$HOME/.config/fish/config.fish"
)
for config_file in "${config_files[@]}"; do
if [ -f "$config_file" ] && grep -q -e "$CLAUDE_ALIAS_MARKER" \
-e "$OLD_CLAUDE_PILOT_MARKER" \
-e "$OLD_CCP_MARKER" \
-e "alias ccp=" \
-e "alias pilot=" \
-e 'PATH="$HOME/.pilot/bin' \
-e 'PATH "$HOME/.pilot/bin' \
"$config_file" 2>/dev/null; then
basename "$config_file"
fi
done
}
confirm_uninstall() {
local version
version=$(get_pilot_version)
echo ""
echo "======================================================================"
echo " Pilot Shell Uninstaller (v${version})"
echo "======================================================================"
echo ""
echo " Uninstalling will:"
echo ""
if [ -d "$PILOT_DIR" ]; then
echo " • Remove ~/.pilot/ (binary, installer)"
fi
if [ -d "$PILOT_PLUGIN_DIR" ]; then
echo " • Remove ~/.claude/pilot/ (hooks, scripts, agents, MCP config)"
fi
local entries
entries=$(get_manifest_entries)
if [ -n "$entries" ]; then
echo "$entries" | grep -q '^commands/' && echo " • Remove Pilot-managed commands from ~/.claude/commands/"
echo "$entries" | grep -q '^skills/' && echo " • Remove Pilot-managed skills from ~/.claude/skills/"
echo "$entries" | grep -q '^rules/' && echo " • Remove Pilot-managed rules from ~/.claude/rules/"
fi
if [ -f "$CLAUDE_DIR/settings.json" ]; then
echo " • Clean Pilot-added entries from ~/.claude/settings.json"
fi
if [ -f "$HOME/.claude.json" ] && [ -f "$CLAUDE_DIR/.pilot-claude-baseline.json" ]; then
echo " • Clean Pilot-added keys from ~/.claude.json"
fi
local baseline_files=""
for f in "$CLAUDE_DIR/.pilot-settings-baseline.json" "$CLAUDE_DIR/.pilot-claude-baseline.json" "$MANIFEST_FILE"; do
if [ -f "$f" ]; then
baseline_files="$baseline_files $(basename "$f")"
fi
done
if [ -n "$baseline_files" ]; then
echo " • Remove Pilot metadata:${baseline_files}"
fi
local affected_shells
affected_shells=$(get_affected_shell_configs)
if [ -n "$affected_shells" ]; then
local shell_list
shell_list=$(echo "$affected_shells" | tr '\n' ', ' | sed 's/,$//')
echo " • Remove 'pilot' and 'ccp' aliases from ${shell_list}"
fi
echo ""
confirm=""
if [ -t 0 ]; then
printf " Continue? [y/N]: "
read -r confirm
elif [ -e /dev/tty ]; then
printf " Continue? [y/N]: "
read -r confirm </dev/tty
else
echo " No interactive terminal available. Use --yes to skip confirmation."
exit 1
fi
case "$confirm" in
[Yy] | [Yy][Ee][Ss]) ;;
*)
echo " Cancelled."
exit 0
;;
esac
}
remove_shell_aliases() {
local config_files=(
"$HOME/.bashrc"
"$HOME/.bash_profile"
"$HOME/.zshrc"
"$HOME/.config/fish/config.fish"
)
for config_file in "${config_files[@]}"; do
if [ ! -f "$config_file" ]; then
continue
fi
if ! grep -q -e "$CLAUDE_ALIAS_MARKER" \
-e "$OLD_CLAUDE_PILOT_MARKER" \
-e "$OLD_CCP_MARKER" \
-e "alias ccp=" \
-e "alias pilot=" \
-e 'PATH="$HOME/.pilot/bin' \
-e 'PATH "$HOME/.pilot/bin' \
"$config_file" 2>/dev/null; then
continue
fi
local tmp_file
tmp_file=$(mktemp)
awk '
/# Pilot Shell/ { next }
/# Claude Pilot/ { next }
/# Claude CodePro alias/ { next }
/^[[:space:]]*alias ccp=/ { next }
/^[[:space:]]*alias pilot=/ { next }
/^[[:space:]]*alias claude=/ { next }
/^[[:space:]]*export PATH="\$HOME\/.pilot\/bin/ { next }
/^[[:space:]]*set -gx PATH "\$HOME\/.pilot\/bin/ { next }
/^[[:space:]]*export PATH="\$HOME\/.bun\/bin:\$PATH"/ { next }
/^[[:space:]]*set -gx PATH "\$HOME\/.bun\/bin"/ { next }
{ print }
' "$config_file" >"$tmp_file"
awk 'NR==1{print; next} /^[[:space:]]*$/{if(blank) next; blank=1; print; next} {blank=0; print}' "$tmp_file" >"${tmp_file}.clean"
mv "${tmp_file}.clean" "$tmp_file"
cp "$tmp_file" "$config_file"
rm -f "$tmp_file"
local name
name=$(basename "$config_file")
echo " [OK] Cleaned $name"
removed_items+=("shell aliases in $name")
done
}
remove_manifest_files() {
if [ ! -f "$MANIFEST_FILE" ]; then
return
fi
local entries
entries=$(get_manifest_entries)
if [ -z "$entries" ]; then
return
fi
local removed_count=0
while IFS= read -r entry; do
local file_path="$CLAUDE_DIR/$entry"
if [ -f "$file_path" ]; then
rm -f "$file_path"
removed_count=$((removed_count + 1))
fi
done <<<"$entries"
if [ "$removed_count" -gt 0 ]; then
echo " [OK] Removed $removed_count Pilot-managed skills and rules"
removed_items+=("$removed_count skills/rules from ~/.claude/")
fi
for subdir in "commands" "skills" "rules"; do
local dir="$CLAUDE_DIR/$subdir"
if [ -d "$dir" ] && [ -z "$(ls -A "$dir" 2>/dev/null)" ]; then
rmdir "$dir" 2>/dev/null || true
fi
done
}
run_surgical_cleanup() {
local target_file="$1"
local baseline_file="$2"
local display_path="$3"
if [ ! -f "$target_file" ] || [ ! -f "$baseline_file" ]; then
return
fi
if ! command -v python3 >/dev/null 2>&1; then
return
fi
python3 -c "
import json, sys, os
def remove_baseline_entries(current, baseline):
if not isinstance(current, dict) or not isinstance(baseline, dict):
return current, current == baseline
modified = False
for key in list(baseline.keys()):
if key not in current:
continue
if isinstance(baseline[key], dict) and isinstance(current[key], dict):
current[key], fully_removed = remove_baseline_entries(current[key], baseline[key])
if fully_removed or not current[key]:
del current[key]
modified = True
else:
modified = True
elif isinstance(baseline[key], list) and isinstance(current[key], list):
baseline_set = set(
json.dumps(x, sort_keys=True) if isinstance(x, (dict, list)) else str(x)
for x in baseline[key]
)
new_list = [
x for x in current[key]
if (json.dumps(x, sort_keys=True) if isinstance(x, (dict, list)) else str(x)) not in baseline_set
]
if len(new_list) != len(current[key]):
modified = True
if new_list:
current[key] = new_list
else:
del current[key]
elif current[key] == baseline[key]:
del current[key]
modified = True
return current, not current
try:
with open('$target_file') as f:
current = json.load(f)
with open('$baseline_file') as f:
baseline = json.load(f)
current, is_empty = remove_baseline_entries(current, baseline)
if is_empty:
os.remove('$target_file')
print(' [OK] Removed $display_path (no user settings remained)')
else:
with open('$target_file', 'w') as f:
json.dump(current, f, indent=2)
f.write('\n')
print(' [OK] Cleaned Pilot entries from $display_path (user settings preserved)')
except Exception as e:
print(f' [!!] Could not clean $display_path: {e}', file=sys.stderr)
" 2>&1
}
remove_pilot_settings() {
local settings_file="$CLAUDE_DIR/settings.json"
local baseline="$CLAUDE_DIR/.pilot-settings-baseline.json"
if [ ! -f "$settings_file" ]; then
return
fi
if [ -f "$baseline" ] && command -v python3 >/dev/null 2>&1; then
run_surgical_cleanup "$settings_file" "$baseline" "~/.claude/settings.json"
else
echo " [!!] Skipped ~/.claude/settings.json (no baseline found, manual cleanup needed)"
fi
removed_items+=("~/.claude/settings.json")
}
remove_claude_json_keys() {
local claude_json="$HOME/.claude.json"
local baseline="$CLAUDE_DIR/.pilot-claude-baseline.json"
if [ ! -f "$claude_json" ] || [ ! -f "$baseline" ]; then
return
fi
run_surgical_cleanup "$claude_json" "$baseline" "~/.claude.json"
removed_items+=("~/.claude.json")
}
remove_pilot_baselines() {
local files=(
"$CLAUDE_DIR/.pilot-settings-baseline.json"
"$CLAUDE_DIR/.pilot-claude-baseline.json"
"$CLAUDE_DIR/.pilot-manifest.json"
)
for file in "${files[@]}"; do
if [ -f "$file" ]; then
rm -f "$file"
echo " [OK] Removed $(basename "$file")"
removed_items+=("$(basename "$file")")
fi
done
}
remove_pilot_plugin() {
if [ -d "$PILOT_PLUGIN_DIR" ]; then
rm -rf "$PILOT_PLUGIN_DIR"
echo " [OK] Removed ~/.claude/pilot/"
removed_items+=("~/.claude/pilot/")
fi
}
remove_pilot_dir() {
if [ -d "$PILOT_DIR" ]; then
rm -rf "$PILOT_DIR"
echo " [OK] Removed ~/.pilot/"
removed_items+=("~/.pilot/")
fi
}
print_summary() {
echo ""
echo "======================================================================"
if [ ${#removed_items[@]} -eq 0 ]; then
echo " Nothing to remove. Pilot Shell does not appear to be installed."
else
echo " Pilot Shell has been uninstalled."
echo ""
echo " Removed ${#removed_items[@]} items:"
for item in "${removed_items[@]}"; do
echo " - $item"
done
fi
echo ""
echo " To fully clean up third-party tools installed by Pilot:"
echo " - Claude Code: npm uninstall -g @anthropic-ai/claude-code"
echo " - Probe: npm uninstall -g @probelabs/probe"
echo " - agent-browser: npm uninstall -g agent-browser"
echo " - vtsls: npm uninstall -g @vtsls/language-server typescript"
echo " - prettier: npm uninstall -g prettier"
echo " - golangci-lint: rm -f \$(go env GOPATH)/bin/golangci-lint"
echo " - Python tools: uv tool uninstall ruff basedpyright"
echo ""
echo " Homebrew packages (git, node, bun, go, etc.) were left intact."
echo ""
echo " Please restart your terminal or run 'source ~/.zshrc' to apply changes."
echo ""
echo "======================================================================"
echo ""
}
SKIP_CONFIRM=false
while [ $# -gt 0 ]; do
case "$1" in
--yes | -y)
SKIP_CONFIRM=true
shift
;;
--help | -h)
echo "Usage: uninstall.sh [--yes|-y]"
echo ""
echo "Uninstall Pilot Shell and remove all installed files."
echo ""
echo "Options:"
echo " --yes, -y Skip confirmation prompt"
echo " --help, -h Show this help message"
exit 0
;;
*)
echo "Unknown option: $1"
echo "Run with --help for usage information."
exit 1
;;
esac
done
if ! [ -d "$PILOT_DIR" ] && ! [ -d "$PILOT_PLUGIN_DIR" ] && ! [ -f "$MANIFEST_FILE" ]; then
echo ""
echo "======================================================================"
echo " Pilot Shell Uninstaller"
echo "======================================================================"
echo ""
echo " Nothing to remove. Pilot Shell does not appear to be installed."
echo ""
echo "======================================================================"
echo ""
exit 0
fi
if [ "$SKIP_CONFIRM" = false ]; then
confirm_uninstall
else
echo ""
echo "======================================================================"
echo " Pilot Shell Uninstaller"
echo "======================================================================"
fi
echo ""
echo " Uninstalling Pilot Shell..."
echo ""
remove_shell_aliases
remove_manifest_files
remove_pilot_settings
remove_claude_json_keys
remove_pilot_baselines
remove_pilot_plugin
remove_pilot_dir
print_summary