forked from Dicklesworthstone/pi_agent_rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·775 lines (674 loc) · 18.5 KB
/
Copy pathuninstall.sh
File metadata and controls
executable file
·775 lines (674 loc) · 18.5 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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
#!/usr/bin/env bash
#
# pi_agent_rust uninstaller
#
# One-liner uninstall:
# curl -fsSL "https://raw.githubusercontent.com/Dicklesworthstone/pi_agent_rust/main/uninstall.sh" | bash
set -euo pipefail
YES=0
QUIET=0
NO_GUM=0
KEEP_PATH=0
NO_RESTORE_LEGACY=0
PURGE_STATE=0
PATH_MARKER="# pi-agent-rust installer PATH"
STATE_DIR="${XDG_STATE_HOME:-$HOME/.local/state}/pi-agent-rust"
STATE_FILE="$STATE_DIR/install-state.env"
PIAR_INSTALL_BIN=""
PIAR_ADOPTED_TYPESCRIPT="0"
PIAR_LEGACY_ALIAS_PATH=""
PIAR_LEGACY_MOVED_FROM=""
PIAR_LEGACY_MOVED_TO=""
PIAR_COMPAT_ALIAS_PATH=""
PIAR_COMPAT_ALIAS_STATUS=""
PIAR_PATH_MARKER=""
PIAR_AGENT_SKILL_STATUS=""
PIAR_AGENT_SKILL_CLAUDE_PATH=""
PIAR_AGENT_SKILL_CODEX_PATH=""
RESTORE_CONFLICT=0
AGENT_SKILL_NAME="pi-agent-rust"
AGENT_SKILL_MARKER="pi_agent_rust installer managed skill"
HAS_GUM=0
if command -v gum >/dev/null 2>&1 && [ -t 1 ]; then
HAS_GUM=1
fi
log() {
[ "$QUIET" -eq 1 ] && return 0
echo -e "$*"
}
ok() {
[ "$QUIET" -eq 1 ] && return 0
if [ "$HAS_GUM" -eq 1 ] && [ "$NO_GUM" -eq 0 ]; then
gum style --foreground 42 "✓ $*"
else
echo -e "\033[0;32m✓\033[0m $*"
fi
}
warn() {
[ "$QUIET" -eq 1 ] && return 0
if [ "$HAS_GUM" -eq 1 ] && [ "$NO_GUM" -eq 0 ]; then
gum style --foreground 214 "⚠ $*"
else
echo -e "\033[1;33m⚠\033[0m $*"
fi
}
err() {
if [ "$HAS_GUM" -eq 1 ] && [ "$NO_GUM" -eq 0 ]; then
gum style --foreground 196 "✗ $*"
else
echo -e "\033[0;31m✗\033[0m $*" >&2
fi
}
usage() {
cat <<'USAGE'
Usage: uninstall.sh [options]
Options:
--yes, -y Skip confirmation prompt
--keep-path Keep PATH lines added by installer
--no-restore-legacy Do not restore moved TypeScript pi binary
--purge-state Remove installer state directory when possible
--quiet, -q Suppress non-error output
--no-gum Disable gum formatting
-h, --help Show this help
USAGE
}
while [ $# -gt 0 ]; do
case "$1" in
--yes|-y)
YES=1
shift
;;
--keep-path)
KEEP_PATH=1
shift
;;
--no-restore-legacy)
NO_RESTORE_LEGACY=1
shift
;;
--purge-state)
PURGE_STATE=1
shift
;;
--quiet|-q)
QUIET=1
shift
;;
--no-gum)
NO_GUM=1
shift
;;
-h|--help)
usage
exit 0
;;
*)
err "Unknown option: $1"
usage
exit 1
;;
esac
done
show_header() {
[ "$QUIET" -eq 1 ] && return 0
if [ "$HAS_GUM" -eq 1 ] && [ "$NO_GUM" -eq 0 ]; then
gum style \
--border normal \
--border-foreground 196 \
--padding "0 1" \
--margin "1 0" \
"$(gum style --foreground 196 --bold 'pi uninstaller')" \
"$(gum style --foreground 245 'Removes installer-managed pi_agent_rust artifacts')"
else
echo ""
echo -e "\033[1;31mpi uninstaller\033[0m"
echo -e "\033[0;90mRemoves installer-managed pi_agent_rust artifacts\033[0m"
echo ""
fi
}
prompt_confirm() {
local prompt="$1"
local default_yes="${2:-0}"
if [ "$YES" -eq 1 ]; then
return 0
fi
if [ ! -t 0 ]; then
if [ "$default_yes" -eq 1 ]; then
return 0
fi
return 1
fi
if [ "$HAS_GUM" -eq 1 ] && [ "$NO_GUM" -eq 0 ]; then
if [ "$default_yes" -eq 1 ]; then
gum confirm --default "$prompt"
else
gum confirm "$prompt"
fi
return $?
fi
local suffix="[y/N]"
if [ "$default_yes" -eq 1 ]; then
suffix="[Y/n]"
fi
printf "%s %s " "$prompt" "$suffix"
local ans
read -r ans || true
if [ -z "$ans" ]; then
if [ "$default_yes" -eq 1 ]; then
return 0
fi
return 1
fi
case "$ans" in
y|Y|yes|YES|Yes)
return 0
;;
*)
return 1
;;
esac
}
load_state() {
if [ ! -f "$STATE_FILE" ]; then
return 0
fi
# shellcheck disable=SC1090
source "$STATE_FILE"
if [ -n "${PIAR_PATH_MARKER:-}" ]; then
PATH_MARKER="$PIAR_PATH_MARKER"
fi
}
version_timeout_cmd() {
if command -v timeout >/dev/null 2>&1; then
printf '%s\n' "timeout"
return 0
fi
if command -v gtimeout >/dev/null 2>&1; then
printf '%s\n' "gtimeout"
return 0
fi
printf '%s\n' ""
}
capture_version_line() {
local path="$1"
local timeout_cmd=""
timeout_cmd="$(version_timeout_cmd)"
local out=""
if [ -n "$timeout_cmd" ]; then
out=$("$timeout_cmd" 2 "$path" --version 2>/dev/null | head -1 || true)
else
out=$("$path" --version 2>/dev/null | head -1 || true)
fi
printf '%s\n' "$out"
}
is_rust_pi_output() {
local out="$1"
[[ "$out" =~ ^pi[[:space:]][0-9]+\.[0-9]+\.[0-9]+[[:space:]]\( ]]
}
is_rust_pi_binary() {
local path="$1"
[ -x "$path" ] || return 1
local out
out="$(capture_version_line "$path")"
is_rust_pi_output "$out"
}
is_managed_alias() {
local path="$1"
[ -f "$path" ] || return 1
grep -q "pi_agent_rust installer managed alias" "$path" 2>/dev/null
}
is_expected_legacy_agent_settings_path() {
local path="$1"
local agent="$2"
[ -n "$path" ] || return 1
case "$agent" in
claude)
case "$path" in
"$HOME/.claude/settings.json"|"$HOME/.config/claude/settings.json"|"$HOME/Library/Application Support/Claude/settings.json")
return 0
;;
esac
;;
gemini)
case "$path" in
"$HOME/.gemini/settings.json"|"$HOME/.gemini-cli/settings.json")
return 0
;;
esac
;;
esac
return 1
}
cleanup_legacy_settings_entries() {
local settings_file="$1"
local hook_key="$2"
local matcher="$3"
local require_name="$4"
shift 4
local bin_candidates=("$@")
[ -f "$settings_file" ] || return 0
[ "${#bin_candidates[@]}" -gt 0 ] || return 0
command -v python3 >/dev/null 2>&1 || return 0
local py_result=""
if ! py_result=$(python3 - "$settings_file" "$hook_key" "$matcher" "$require_name" "${bin_candidates[@]}" <<'PYEOF'
import json
import os
import shlex
import sys
settings_file = sys.argv[1]
hook_key = sys.argv[2]
matcher = sys.argv[3]
require_name = sys.argv[4]
candidate_bins = [arg for arg in sys.argv[5:] if arg]
if not candidate_bins:
print("NO_CANDIDATES")
raise SystemExit(0)
def command_matches(command: str) -> bool:
if not isinstance(command, str):
return False
cmd = command.strip()
if not cmd:
return False
try:
parts = shlex.split(cmd)
except Exception:
parts = cmd.split()
if len(parts) != 1:
return False
first = parts[0]
if not os.path.isabs(first):
return False
for bin_path in candidate_bins:
if first == bin_path:
return True
try:
if os.path.realpath(first) == os.path.realpath(bin_path):
return True
except Exception:
pass
return False
try:
with open(settings_file, "r", encoding="utf-8") as f:
settings = json.load(f)
except Exception:
print("SKIP_INVALID_JSON")
raise SystemExit(0)
if not isinstance(settings, dict):
print("SKIP_INVALID_JSON")
raise SystemExit(0)
hooks = settings.get("hooks")
if not isinstance(hooks, dict):
print("NO_HOOKS")
raise SystemExit(0)
entries = hooks.get(hook_key)
if not isinstance(entries, list):
print("NO_HOOKS")
raise SystemExit(0)
removed = 0
changed = False
new_entries = []
for entry in entries:
if isinstance(entry, dict) and entry.get("matcher") == matcher:
existing_hooks = entry.get("hooks", [])
if not isinstance(existing_hooks, list):
existing_hooks = []
kept = []
for hook in existing_hooks:
should_remove = False
if isinstance(hook, dict):
command = str(hook.get("command", ""))
if require_name:
if (
str(hook.get("name", "")) == require_name
and str(hook.get("type", "")) == "command"
and (set(hook.keys()) <= {"name", "type", "command", "timeout"})
and hook.get("timeout", 5000) in (5000, "5000")
and command_matches(command)
):
should_remove = True
else:
if (
str(hook.get("type", "")) == "command"
and (set(hook.keys()) <= {"type", "command"})
and command_matches(command)
):
should_remove = True
if should_remove:
removed += 1
changed = True
continue
kept.append(hook)
if kept:
entry["hooks"] = kept
new_entries.append(entry)
elif existing_hooks:
changed = True
else:
new_entries.append(entry)
if not changed:
print("ALREADY_ABSENT")
raise SystemExit(0)
hooks[hook_key] = new_entries
if not hooks[hook_key]:
del hooks[hook_key]
if not hooks:
settings.pop("hooks", None)
with open(settings_file, "w", encoding="utf-8") as f:
json.dump(settings, f, indent=2)
f.write("\n")
print(f"REMOVED:{removed}")
PYEOF
); then
warn "Legacy settings cleanup failed for $settings_file"
return 0
fi
case "$py_result" in
REMOVED:*)
local count="${py_result#REMOVED:}"
if [ "$count" -gt 0 ] 2>/dev/null; then
ok "Removed ${count} legacy installer entries from $settings_file"
fi
;;
esac
}
cleanup_legacy_agent_settings() {
local bin_candidates=()
if [ -n "$PIAR_INSTALL_BIN" ]; then
bin_candidates+=("$PIAR_INSTALL_BIN")
fi
while IFS= read -r candidate; do
[ -n "$candidate" ] || continue
if [ "$candidate" != "$PIAR_INSTALL_BIN" ]; then
bin_candidates+=("$candidate")
fi
done < <(fallback_binary_candidates)
[ "${#bin_candidates[@]}" -gt 0 ] || return 0
local claude_candidates=()
if [ -n "${PIAR_CLAUDE_HOOK_SETTINGS:-}" ]; then
claude_candidates+=("${PIAR_CLAUDE_HOOK_SETTINGS}")
fi
claude_candidates+=(
"$HOME/.claude/settings.json"
"$HOME/.config/claude/settings.json"
"$HOME/Library/Application Support/Claude/settings.json"
)
local gemini_candidates=()
if [ -n "${PIAR_GEMINI_HOOK_SETTINGS:-}" ]; then
gemini_candidates+=("${PIAR_GEMINI_HOOK_SETTINGS}")
fi
gemini_candidates+=(
"$HOME/.gemini/settings.json"
"$HOME/.gemini-cli/settings.json"
)
local settings_path=""
for settings_path in "${claude_candidates[@]}"; do
if is_expected_legacy_agent_settings_path "$settings_path" "claude"; then
cleanup_legacy_settings_entries "$settings_path" "PreToolUse" "Bash" "" "${bin_candidates[@]}"
fi
done
for settings_path in "${gemini_candidates[@]}"; do
if is_expected_legacy_agent_settings_path "$settings_path" "gemini"; then
cleanup_legacy_settings_entries "$settings_path" "BeforeTool" "run_shell_command" "pi-agent-rust" "${bin_candidates[@]}"
fi
done
}
is_managed_skill_file() {
local path="$1"
[ -f "$path" ] || return 1
grep -q "$AGENT_SKILL_MARKER" "$path" 2>/dev/null
}
is_expected_skill_directory() {
local dir="$1"
[ -n "$dir" ] || return 1
case "$dir" in
*/skills/${AGENT_SKILL_NAME}) return 0 ;;
*) return 1 ;;
esac
}
remove_file_if_exists() {
local path="$1"
if [ -e "$path" ] || [ -L "$path" ]; then
rm -f "$path"
return 0
fi
return 1
}
remove_path_recursively() {
local target="$1"
if [ -z "$target" ]; then
return 1
fi
if [ ! -e "$target" ] && [ ! -L "$target" ]; then
return 0
fi
if [ -L "$target" ] || [ -f "$target" ] || [ -p "$target" ] || [ -S "$target" ] || [ -b "$target" ] || [ -c "$target" ]; then
rm -f "$target"
return $?
fi
if [ -d "$target" ]; then
local child=""
while IFS= read -r -d '' child; do
remove_path_recursively "$child" || return 1
done < <(find "$target" -mindepth 1 -maxdepth 1 -print0 2>/dev/null)
rmdir "$target" 2>/dev/null || return 1
return 0
fi
return 1
}
remove_path_entries() {
if [ "$KEEP_PATH" -eq 1 ]; then
return 0
fi
local touched=0
for rc in "$HOME/.zshrc" "$HOME/.bashrc"; do
[ -f "$rc" ] || continue
grep -F "$PATH_MARKER" "$rc" >/dev/null 2>&1 || continue
local tmp="${rc}.pi-uninstall.tmp"
awk -v marker="$PATH_MARKER" 'index($0, marker) == 0 { print }' "$rc" > "$tmp"
mv "$tmp" "$rc"
touched=1
done
if [ "$touched" -eq 1 ]; then
ok "Removed installer PATH entries"
fi
}
fallback_binary_candidates() {
cat <<EOF_CAND
$HOME/.local/bin/pi
$HOME/.local/bin/pi-rust
/usr/local/bin/pi
/usr/local/bin/pi-rust
EOF_CAND
}
fallback_alias_candidates() {
cat <<EOF_CAND
$HOME/.local/bin/rpi
/usr/local/bin/rpi
EOF_CAND
}
remove_installed_binary() {
local removed=0
if [ -n "$PIAR_INSTALL_BIN" ] && [ -e "$PIAR_INSTALL_BIN" ]; then
if is_rust_pi_binary "$PIAR_INSTALL_BIN"; then
remove_file_if_exists "$PIAR_INSTALL_BIN" && removed=1
ok "Removed Rust binary: $PIAR_INSTALL_BIN"
else
warn "Skipping non-Rust binary at recorded path: $PIAR_INSTALL_BIN"
fi
fi
if [ "$removed" -eq 0 ]; then
while IFS= read -r cand; do
[ -n "$cand" ] || continue
if [ -e "$cand" ] && is_rust_pi_binary "$cand"; then
remove_file_if_exists "$cand" && removed=1
ok "Removed Rust binary: $cand"
fi
done < <(fallback_binary_candidates)
fi
return 0
}
restore_moved_typescript_pi() {
if [ "$NO_RESTORE_LEGACY" -eq 1 ]; then
return 0
fi
if [ "${PIAR_ADOPTED_TYPESCRIPT:-0}" != "1" ]; then
return 0
fi
if [ -z "$PIAR_LEGACY_MOVED_FROM" ] || [ -z "$PIAR_LEGACY_MOVED_TO" ]; then
return 0
fi
if [ ! -e "$PIAR_LEGACY_MOVED_TO" ]; then
warn "Legacy backup not found for restore: $PIAR_LEGACY_MOVED_TO"
return 0
fi
if [ -e "$PIAR_LEGACY_MOVED_FROM" ]; then
if is_rust_pi_binary "$PIAR_LEGACY_MOVED_FROM"; then
remove_file_if_exists "$PIAR_LEGACY_MOVED_FROM" || true
else
warn "Skipping restore because destination already exists: $PIAR_LEGACY_MOVED_FROM"
RESTORE_CONFLICT=1
return 0
fi
fi
mv "$PIAR_LEGACY_MOVED_TO" "$PIAR_LEGACY_MOVED_FROM"
ok "Restored original pi binary: $PIAR_LEGACY_MOVED_FROM"
}
remove_legacy_alias() {
local alias_path="$PIAR_LEGACY_ALIAS_PATH"
if [ -z "$alias_path" ]; then
return 0
fi
if [ ! -e "$alias_path" ]; then
return 0
fi
if is_managed_alias "$alias_path"; then
remove_file_if_exists "$alias_path" && ok "Removed legacy alias: $alias_path"
else
warn "Skipping non-managed alias file: $alias_path"
fi
}
remove_compat_alias() {
local removed=0
if [ -n "$PIAR_COMPAT_ALIAS_PATH" ] && [ -e "$PIAR_COMPAT_ALIAS_PATH" ]; then
if is_managed_alias "$PIAR_COMPAT_ALIAS_PATH"; then
remove_file_if_exists "$PIAR_COMPAT_ALIAS_PATH" && removed=1
ok "Removed compatibility alias: $PIAR_COMPAT_ALIAS_PATH"
else
warn "Skipping non-managed compatibility alias: $PIAR_COMPAT_ALIAS_PATH"
fi
fi
if [ "$removed" -eq 0 ]; then
while IFS= read -r cand; do
[ -n "$cand" ] || continue
if [ -e "$cand" ] && is_managed_alias "$cand"; then
remove_file_if_exists "$cand" && removed=1
ok "Removed compatibility alias: $cand"
fi
done < <(fallback_alias_candidates)
fi
}
remove_installed_skills() {
local codex_home="${CODEX_HOME:-$HOME/.codex}"
local claude_dir="${PIAR_AGENT_SKILL_CLAUDE_PATH:-$HOME/.claude/skills/${AGENT_SKILL_NAME}}"
local codex_dir="${PIAR_AGENT_SKILL_CODEX_PATH:-${codex_home}/skills/${AGENT_SKILL_NAME}}"
local dir=""
for dir in "$claude_dir" "$codex_dir"; do
[ -n "$dir" ] || continue
if ! is_expected_skill_directory "$dir"; then
warn "Skipping unexpected skill directory path: $dir"
continue
fi
local skill_file="$dir/SKILL.md"
[ -f "$skill_file" ] || continue
if ! is_managed_skill_file "$skill_file"; then
warn "Skipping non-managed skill directory: $dir"
continue
fi
remove_path_recursively "$dir" 2>/dev/null || true
if [ ! -e "$dir" ]; then
ok "Removed installer-managed skill: $dir"
else
warn "Failed to remove installer-managed skill: $dir"
fi
done
}
remove_state() {
if [ "$RESTORE_CONFLICT" -eq 1 ]; then
warn "Keeping installer state due restore conflict. Resolve and rerun uninstall."
return 0
fi
if [ -f "$STATE_FILE" ]; then
rm -f "$STATE_FILE"
ok "Removed installer state file"
fi
if [ "$PURGE_STATE" -eq 1 ] || [ -z "$(ls -A "$STATE_DIR" 2>/dev/null || true)" ]; then
rmdir "$STATE_DIR" 2>/dev/null || true
fi
}
plan_summary() {
[ "$QUIET" -eq 1 ] && return 0
local lines=()
if [ -n "$PIAR_INSTALL_BIN" ]; then
lines+=("Rust binary: $PIAR_INSTALL_BIN")
fi
if [ -n "$PIAR_LEGACY_ALIAS_PATH" ]; then
lines+=("Legacy alias: $PIAR_LEGACY_ALIAS_PATH")
fi
if [ -n "$PIAR_COMPAT_ALIAS_PATH" ] || [ -n "$PIAR_COMPAT_ALIAS_STATUS" ]; then
lines+=("Compatibility alias: ${PIAR_COMPAT_ALIAS_PATH:-$PIAR_COMPAT_ALIAS_STATUS}")
fi
if [ -n "$PIAR_AGENT_SKILL_CLAUDE_PATH" ] || [ -n "$PIAR_AGENT_SKILL_CODEX_PATH" ]; then
lines+=("Agent skills: remove installer-managed Claude/Codex skill dirs")
fi
if [ -n "$PIAR_AGENT_SKILL_STATUS" ]; then
lines+=("Recorded skill status: $PIAR_AGENT_SKILL_STATUS")
fi
if [ "${PIAR_ADOPTED_TYPESCRIPT:-0}" = "1" ] && [ "$NO_RESTORE_LEGACY" -eq 0 ]; then
lines+=("Restore TS pi: ${PIAR_LEGACY_MOVED_TO:-<none>} -> ${PIAR_LEGACY_MOVED_FROM:-<none>}")
fi
if [ "$KEEP_PATH" -eq 0 ]; then
lines+=("PATH cleanup: remove installer PATH marker lines")
fi
if [ ${#lines[@]} -eq 0 ]; then
lines+=("No installer state detected; fallback cleanup will be attempted")
fi
if [ "$HAS_GUM" -eq 1 ] && [ "$NO_GUM" -eq 0 ]; then
{
gum style --foreground 196 --bold "Planned uninstall actions"
echo ""
for line in "${lines[@]}"; do
gum style --foreground 245 "$line"
done
} | gum style --border normal --border-foreground 240 --padding "1 2"
else
echo -e "\033[1;31mPlanned uninstall actions\033[0m"
for line in "${lines[@]}"; do
echo -e " \033[0;90m$line\033[0m"
done
fi
}
main() {
show_header
load_state
plan_summary
if ! prompt_confirm "Proceed with uninstall?" 1; then
warn "Uninstall cancelled"
exit 0
fi
cleanup_legacy_agent_settings
remove_installed_binary
remove_compat_alias
remove_legacy_alias
remove_installed_skills
restore_moved_typescript_pi
remove_path_entries
remove_state
if [ "$QUIET" -eq 0 ]; then
if [ "$HAS_GUM" -eq 1 ] && [ "$NO_GUM" -eq 0 ]; then
gum style --foreground 42 --bold "pi uninstall complete"
else
echo -e "\033[1;32mpi uninstall complete\033[0m"
fi
fi
}
main "$@"