-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·131 lines (116 loc) · 3.45 KB
/
Copy pathuninstall.sh
File metadata and controls
executable file
·131 lines (116 loc) · 3.45 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
#!/usr/bin/env bash
set -euo pipefail
HOOK_DIR="$HOME/.qoder/hooks/langfuse"
SETTINGS_FILE="$HOME/.qoder/settings.json"
LANGFUSE_PROFILE_DIR="$HOME/.agent-exporter-to-langfuse/config"
LANGFUSE_ENV_FILE="$LANGFUSE_PROFILE_DIR/qoder.env"
if [ -n "${ZSH_VERSION:-}" ] || [ "$(basename "${SHELL:-}")" = "zsh" ]; then
SHELL_RC="$HOME/.zshenv"
else
SHELL_RC="$HOME/.profile"
fi
# --- Colors ---
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m'
info() { echo -e "${GREEN}[INFO]${NC} $*"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
PURGE=false
while [[ $# -gt 0 ]]; do
case "$1" in
--purge) PURGE=true; shift ;;
*) shift ;;
esac
done
echo "=== Uninstall Qoder Langfuse Hook ==="
echo ""
# --- 1. Remove hook directory ---
if [ -d "$HOOK_DIR" ]; then
rm -rf "$HOOK_DIR"
info "Removed hook directory: $HOOK_DIR"
else
warn "Hook directory not found, skipping: $HOOK_DIR"
fi
# --- 2. Remove hook entry from settings.json ---
if [ -f "$SETTINGS_FILE" ]; then
python3 -c "
import json, sys
settings_path = sys.argv[1]
try:
with open(settings_path) as f:
settings = json.load(f)
except Exception:
sys.exit(0)
changed = False
for event in ['Stop', 'SubagentStop']:
entries = settings.get('hooks', {}).get(event, [])
filtered = [
matcher for matcher in entries
if not any('langfuse' in h.get('command', '') for h in matcher.get('hooks', []))
]
if len(filtered) < len(entries):
settings['hooks'][event] = filtered
changed = True
if changed:
with open(settings_path, 'w') as f:
json.dump(settings, f, indent=2)
print('removed')
else:
print('not_found')
" "$SETTINGS_FILE"
info "Removed Langfuse hook from $SETTINGS_FILE."
else
warn "Settings file not found, skipping: $SETTINGS_FILE"
fi
# --- 3. Remove env file ---
if [ "$PURGE" = true ]; then
if [ -f "$LANGFUSE_ENV_FILE" ]; then
rm -f "$LANGFUSE_ENV_FILE"
info "Removed env file: $LANGFUSE_ENV_FILE"
else
warn "Env file not found, skipping: $LANGFUSE_ENV_FILE"
fi
else
info "Env file preserved: $LANGFUSE_ENV_FILE"
fi
# --- 4. Clean up profile.d directory if empty ---
if [ -d "$LANGFUSE_PROFILE_DIR" ] && [ -z "$(ls -A "$LANGFUSE_PROFILE_DIR" 2>/dev/null)" ]; then
rmdir "$LANGFUSE_PROFILE_DIR"
info "Removed empty profile directory: $LANGFUSE_PROFILE_DIR"
# Remove loader line from shell profile only when no agents remain
if [ -f "$SHELL_RC" ] && grep -qF "agent-exporter-to-langfuse" "$SHELL_RC" 2>/dev/null; then
python3 -c "
import sys
lines = open(sys.argv[1]).readlines()
out = []
skip_next = False
for line in lines:
if '# Agent Langfuse Exporters' in line:
skip_next = True
if out and out[-1].strip() == '':
out.pop()
continue
if skip_next and 'agent-exporter-to-langfuse' in line:
skip_next = False
continue
skip_next = False
out.append(line)
open(sys.argv[1], 'w').writelines(out)
" "$SHELL_RC"
info "Removed loader line from $SHELL_RC."
fi
fi
# --- 5. Remove state files ---
STATE_DIR="$HOME/.qoder/state"
removed_state=false
for f in "$STATE_DIR/langfuse_hook.log"* "$STATE_DIR/langfuse_state.json" "$STATE_DIR/langfuse_state.lock"; do
if [ -f "$f" ]; then
rm -f "$f"
removed_state=true
fi
done
if [ "$removed_state" = true ]; then
info "Removed Langfuse state/log files from $STATE_DIR."
fi
echo ""
info "Uninstall complete. Restart Qoder to apply."