@ramarivera/coding-buddy 0.4.0-alpha.8 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{adapters/claude/plugin → .claude-plugin}/marketplace.json +11 -6
- package/{adapters/claude/plugin → .claude-plugin}/plugin.json +9 -7
- package/LICENSE +1 -1
- package/README.md +102 -72
- package/adapters/omp/commands.ts +201 -0
- package/adapters/omp/context.ts +22 -0
- package/adapters/omp/events.ts +551 -0
- package/adapters/omp/identity.ts +10 -0
- package/adapters/omp/index.ts +39 -0
- package/adapters/omp/logger.ts +52 -0
- package/adapters/omp/prompt.ts +60 -0
- package/adapters/omp/renderers.ts +73 -0
- package/adapters/omp/storage.ts +25 -0
- package/adapters/omp/ui.ts +85 -0
- package/adapters/pi/commands.ts +64 -37
- package/adapters/pi/events.ts +147 -72
- package/adapters/pi/index.ts +9 -4
- package/adapters/pi/storage.ts +14 -285
- package/adapters/pi/ui.ts +56 -5
- package/adapters/shared/file-storage.ts +526 -0
- package/{adapters/claude/install → cli}/backup.ts +59 -44
- package/cli/biomes.ts +309 -0
- package/cli/buddy-shell.ts +818 -0
- package/{adapters/claude/install → cli}/disable.ts +14 -32
- package/{adapters/claude/install → cli}/doctor.ts +55 -57
- package/{adapters/claude/install → cli}/hunt.ts +7 -9
- package/cli/index.ts +36 -25
- package/{adapters/claude/install → cli}/install.ts +100 -145
- package/{adapters/claude/install → cli}/pick.ts +111 -50
- package/{adapters/claude/install → cli}/settings.ts +2 -2
- package/{adapters/claude/install → cli}/show.ts +4 -4
- package/{adapters/claude/install → cli}/test-statusline.sh +2 -2
- package/{adapters/claude/install → cli}/test-statusline.ts +11 -11
- package/cli/tui.tsx +2333 -0
- package/{adapters/claude/install → cli}/uninstall.ts +23 -38
- package/cli/upgrade.ts +213 -0
- package/cli/validate-species.ts +209 -0
- package/cli/verify.ts +3 -3
- package/core/achievements.ts +12 -20
- package/core/art-data.ts +26 -0
- package/core/command-service.ts +99 -97
- package/core/engine.ts +83 -1
- package/core/ports.ts +10 -0
- package/core/reactions.ts +533 -95
- package/core/slot-slug.ts +22 -0
- package/{adapters/claude/hooks → hooks}/buddy-comment.sh +23 -2
- package/hooks/file-type-react.sh +401 -0
- package/hooks/hooks.json +52 -0
- package/hooks/mood-react.sh +208 -0
- package/{adapters/claude/hooks → hooks}/name-react.sh +5 -2
- package/hooks/react.sh +1368 -0
- package/hooks/suggest.sh +55 -0
- package/package.json +113 -59
- package/scripts/gen-emoji-widths.ts +34 -0
- package/scripts/paths.sh +56 -0
- package/scripts/postinstall.cjs +42 -0
- package/scripts/snapshot-statusline.sh +54 -0
- package/server/achievements.ts +1419 -0
- package/server/art.ts +450 -0
- package/server/award-xp.ts +48 -0
- package/server/check-suggestions.ts +102 -0
- package/server/consolidate.ts +33 -0
- package/server/index.ts +1340 -0
- package/server/mcp-launcher.sh +26 -0
- package/server/memory.ts +404 -0
- package/server/mood.ts +254 -0
- package/server/path.ts +82 -0
- package/server/shift-mood.ts +43 -0
- package/{adapters/claude/storage → server}/state.ts +200 -7
- package/server/suggestions.ts +335 -0
- package/server/theme.ts +53 -0
- package/server/xp.ts +435 -0
- package/{adapters/claude/skills → skills}/buddy/SKILL.md +48 -4
- package/statusline/buddy-status.sh +397 -0
- package/statusline/combined-status.sh +134 -0
- package/statusline/emoji-widths.data +4 -0
- package/adapters/claude/hooks/hooks.json +0 -35
- package/adapters/claude/hooks/react.sh +0 -204
- package/adapters/claude/popup/buddy-popup.sh +0 -92
- package/adapters/claude/popup/buddy-render.sh +0 -540
- package/adapters/claude/popup/popup-manager.sh +0 -355
- package/adapters/claude/rendering/art.ts +0 -264
- package/adapters/claude/server/index.ts +0 -752
- package/adapters/claude/server/instructions.ts +0 -24
- package/adapters/claude/server/resources.ts +0 -38
- package/adapters/claude/statusline/buddy-status.sh +0 -389
- package/adapters/claude/storage/achievements.ts +0 -253
- package/adapters/claude/storage/identity.ts +0 -13
- package/adapters/claude/storage/paths.ts +0 -24
- package/adapters/claude/storage/settings.ts +0 -41
- package/adapters/pi/README.md +0 -83
- package/adapters/pi/tools.ts +0 -6
|
@@ -1,355 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# claude-buddy popup manager -- create/destroy tmux popup overlay
|
|
3
|
-
#
|
|
4
|
-
# Usage:
|
|
5
|
-
# popup-manager.sh start -- open buddy popup (bottom-right corner)
|
|
6
|
-
# popup-manager.sh stop -- close buddy popup
|
|
7
|
-
# popup-manager.sh status -- check if popup is running
|
|
8
|
-
#
|
|
9
|
-
# Called by SessionStart/SessionEnd hooks.
|
|
10
|
-
#
|
|
11
|
-
# Architecture: The "start" command runs a blocking reopen loop.
|
|
12
|
-
# tmux display-popup blocks until the popup closes. When ESC closes
|
|
13
|
-
# the popup (hardcoded tmux behavior), we forward ESC to CC and
|
|
14
|
-
# reopen. The loop exits when: stop flag is set, or CC pane dies.
|
|
15
|
-
|
|
16
|
-
set -euo pipefail
|
|
17
|
-
|
|
18
|
-
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
19
|
-
BUDDY_DIR="$HOME/.claude-buddy"
|
|
20
|
-
|
|
21
|
-
# Session ID: sanitized tmux pane number, or "default" outside tmux
|
|
22
|
-
SID="${TMUX_PANE#%}"
|
|
23
|
-
SID="${SID:-default}"
|
|
24
|
-
|
|
25
|
-
STOP_FLAG="$BUDDY_DIR/popup-stop.$SID"
|
|
26
|
-
REOPEN_PID_FILE="$BUDDY_DIR/popup-reopen-pid.$SID"
|
|
27
|
-
STATE_FILE="$BUDDY_DIR/status.json"
|
|
28
|
-
|
|
29
|
-
POPUP_W=12 # minimum / fallback
|
|
30
|
-
ART_W=12 # updated dynamically by compute_art_width
|
|
31
|
-
BUBBLE_EXTRA=3 # border top + border bottom + connector line
|
|
32
|
-
BORDER_EXTRA=0 # +2 on tmux < 3.3 (popup has a border)
|
|
33
|
-
REACTION_TTL=20 # seconds
|
|
34
|
-
REACTION_FILE="$BUDDY_DIR/reaction.$SID.json"
|
|
35
|
-
RESIZE_FLAG="$BUDDY_DIR/popup-resize.$SID"
|
|
36
|
-
CONFIG_FILE="$BUDDY_DIR/config.json"
|
|
37
|
-
LEFT_BUBBLE_W=22 # bubble box width in left mode (including frame chars)
|
|
38
|
-
|
|
39
|
-
# Read config early (needed for BASE_H calculation)
|
|
40
|
-
BUBBLE_POSITION="top"
|
|
41
|
-
SHOW_RARITY=1
|
|
42
|
-
if [ -f "$CONFIG_FILE" ]; then
|
|
43
|
-
_bp=$(jq -r '.bubblePosition // "top"' "$CONFIG_FILE" 2>/dev/null || echo "top")
|
|
44
|
-
case "$_bp" in top|left) BUBBLE_POSITION="$_bp" ;; esac
|
|
45
|
-
_sr=$(jq -r 'if .showRarity == false then "false" else "true" end' "$CONFIG_FILE" 2>/dev/null || echo "true")
|
|
46
|
-
[ "$_sr" = "false" ] && SHOW_RARITY=0
|
|
47
|
-
fi
|
|
48
|
-
|
|
49
|
-
BASE_H=8 # art(4) + blank(1) + name(1) + rarity(1) + padding(1)
|
|
50
|
-
[ "$SHOW_RARITY" -eq 0 ] && BASE_H=7
|
|
51
|
-
|
|
52
|
-
# ─── Helpers ─────────────────────────────────────────────────────────────────
|
|
53
|
-
|
|
54
|
-
is_tmux() {
|
|
55
|
-
[ -n "${TMUX:-}" ]
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
tmux_version_ok() {
|
|
59
|
-
local ver
|
|
60
|
-
ver=$(tmux -V 2>/dev/null | grep -oE '[0-9]+\.[0-9a-z]+' | head -1)
|
|
61
|
-
[ -z "$ver" ] && return 1
|
|
62
|
-
local major minor
|
|
63
|
-
major="${ver%%.*}"
|
|
64
|
-
minor="${ver#*.}"
|
|
65
|
-
minor="${minor%%[a-z]*}"
|
|
66
|
-
[ "$major" -gt 3 ] 2>/dev/null && return 0
|
|
67
|
-
[ "$major" -eq 3 ] && [ "$minor" -ge 2 ] 2>/dev/null && return 0
|
|
68
|
-
return 1
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
# tmux 3.4+ supports -B (borderless), -e (env), and -x R/-y S positioning
|
|
72
|
-
tmux_has_borderless() {
|
|
73
|
-
local ver
|
|
74
|
-
ver=$(tmux -V 2>/dev/null | grep -oE '[0-9]+\.[0-9a-z]+' | head -1)
|
|
75
|
-
[ -z "$ver" ] && return 1
|
|
76
|
-
local major minor
|
|
77
|
-
major="${ver%%.*}"
|
|
78
|
-
minor="${ver#*.}"
|
|
79
|
-
minor="${minor%%[a-z]*}"
|
|
80
|
-
[ "$major" -gt 3 ] 2>/dev/null && return 0
|
|
81
|
-
[ "$major" -eq 3 ] && [ "$minor" -ge 4 ] 2>/dev/null && return 0
|
|
82
|
-
return 1
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
cc_pane_alive() {
|
|
86
|
-
tmux list-panes -a -F '#{pane_id}' 2>/dev/null | grep -qF "$1"
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
# Compute popup width from buddy data (widest of: art, name, stars+rarity)
|
|
90
|
-
compute_art_width() {
|
|
91
|
-
[ -f "$STATE_FILE" ] || return
|
|
92
|
-
local name rarity
|
|
93
|
-
name=$(jq -r '.name // ""' "$STATE_FILE" 2>/dev/null)
|
|
94
|
-
rarity=$(jq -r '.rarity // "common"' "$STATE_FILE" 2>/dev/null)
|
|
95
|
-
local w=10 # minimum art width
|
|
96
|
-
# Name length
|
|
97
|
-
[ ${#name} -gt "$w" ] && w=${#name}
|
|
98
|
-
# Stars + rarity line (only if enabled)
|
|
99
|
-
if [ "$SHOW_RARITY" -eq 1 ]; then
|
|
100
|
-
local stars_w=$(( 6 + ${#rarity} ))
|
|
101
|
-
[ "$stars_w" -gt "$w" ] && w=$stars_w
|
|
102
|
-
fi
|
|
103
|
-
# Add 2 for padding
|
|
104
|
-
w=$(( w + 2 ))
|
|
105
|
-
POPUP_W=$w
|
|
106
|
-
ART_W=$w
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
# Compute popup dimensions based on reaction state and bubble position
|
|
110
|
-
# Sets COMPUTED_W and COMPUTED_H
|
|
111
|
-
compute_dimensions() {
|
|
112
|
-
compute_art_width
|
|
113
|
-
local h=$BASE_H
|
|
114
|
-
local w=$POPUP_W
|
|
115
|
-
h=$(( h + BORDER_EXTRA ))
|
|
116
|
-
w=$(( w + BORDER_EXTRA ))
|
|
117
|
-
|
|
118
|
-
# Account for hat (adds 1 art row beyond the 4 in BASE_H)
|
|
119
|
-
local art_rows=4
|
|
120
|
-
if [ -f "$STATE_FILE" ]; then
|
|
121
|
-
local _hat
|
|
122
|
-
_hat=$(jq -r '.hat // "none"' "$STATE_FILE" 2>/dev/null || echo "none")
|
|
123
|
-
if [ "$_hat" != "none" ]; then
|
|
124
|
-
h=$(( h + 1 ))
|
|
125
|
-
art_rows=5
|
|
126
|
-
fi
|
|
127
|
-
fi
|
|
128
|
-
|
|
129
|
-
local fresh=0
|
|
130
|
-
if [ -f "$STATE_FILE" ]; then
|
|
131
|
-
local reaction
|
|
132
|
-
reaction=$(jq -r '.reaction // ""' "$STATE_FILE" 2>/dev/null || true)
|
|
133
|
-
if [ -n "$reaction" ] && [ "$reaction" != "null" ]; then
|
|
134
|
-
if [ -f "$REACTION_FILE" ]; then
|
|
135
|
-
local ts now age
|
|
136
|
-
ts=$(jq -r '.timestamp // 0' "$REACTION_FILE" 2>/dev/null || echo 0)
|
|
137
|
-
if [ "$ts" != "0" ]; then
|
|
138
|
-
now=$(date +%s)
|
|
139
|
-
age=$(( now - ts / 1000 ))
|
|
140
|
-
[ "$age" -lt "$REACTION_TTL" ] && fresh=1
|
|
141
|
-
fi
|
|
142
|
-
fi
|
|
143
|
-
if [ "$fresh" -eq 1 ]; then
|
|
144
|
-
if [ "$BUBBLE_POSITION" = "top" ]; then
|
|
145
|
-
# Top mode: bubble adds rows above the art
|
|
146
|
-
local bubble_w=$(( POPUP_W - BORDER_EXTRA - 5 ))
|
|
147
|
-
[ "$bubble_w" -lt 20 ] && bubble_w=20
|
|
148
|
-
# Widen popup if bubble needs more room than art
|
|
149
|
-
local needed_w=$(( bubble_w + 5 + BORDER_EXTRA ))
|
|
150
|
-
[ "$needed_w" -gt "$w" ] && w=$needed_w
|
|
151
|
-
local len=${#reaction}
|
|
152
|
-
local lines=$(( (len + bubble_w - 1) / bubble_w ))
|
|
153
|
-
[ "$lines" -lt 1 ] && lines=1
|
|
154
|
-
h=$(( h + lines + BUBBLE_EXTRA ))
|
|
155
|
-
else
|
|
156
|
-
# Left mode: dynamic bubble width to fit text within art height
|
|
157
|
-
local max_text_lines=$(( art_rows - 2 )) # subtract top/bottom borders
|
|
158
|
-
[ "$max_text_lines" -lt 1 ] && max_text_lines=1
|
|
159
|
-
local len=${#reaction}
|
|
160
|
-
local left_inner=$(( (len + max_text_lines - 1) / max_text_lines + 5 ))
|
|
161
|
-
[ "$left_inner" -lt 10 ] && left_inner=10
|
|
162
|
-
[ "$left_inner" -gt 50 ] && left_inner=50
|
|
163
|
-
local left_box=$(( left_inner + 4 )) # "| " + text + " |"
|
|
164
|
-
w=$(( w + left_box + 2 )) # +2 for connector gap
|
|
165
|
-
fi
|
|
166
|
-
fi
|
|
167
|
-
fi
|
|
168
|
-
fi
|
|
169
|
-
COMPUTED_W=$w
|
|
170
|
-
COMPUTED_H=$h
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
is_reopen_running() {
|
|
174
|
-
[ -f "$REOPEN_PID_FILE" ] || return 1
|
|
175
|
-
local pid
|
|
176
|
-
pid=$(cat "$REOPEN_PID_FILE")
|
|
177
|
-
kill -0 "$pid" 2>/dev/null
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
# ─── Start ───────────────────────────────────────────────────────────────────
|
|
181
|
-
|
|
182
|
-
start_popup() {
|
|
183
|
-
is_tmux || { echo "Not in tmux" >&2; return 1; }
|
|
184
|
-
tmux_version_ok || { echo "tmux >= 3.2 required for popup" >&2; return 1; }
|
|
185
|
-
|
|
186
|
-
# Kill stale reopen loop for THIS session (e.g., CC restarted in same pane)
|
|
187
|
-
if [ -f "$REOPEN_PID_FILE" ]; then
|
|
188
|
-
local old_pid
|
|
189
|
-
old_pid=$(cat "$REOPEN_PID_FILE" 2>/dev/null)
|
|
190
|
-
if [ -n "$old_pid" ]; then
|
|
191
|
-
kill "$old_pid" 2>/dev/null || true
|
|
192
|
-
fi
|
|
193
|
-
rm -f "$REOPEN_PID_FILE"
|
|
194
|
-
tmux display-popup -C 2>/dev/null || true
|
|
195
|
-
sleep 0.2
|
|
196
|
-
fi
|
|
197
|
-
|
|
198
|
-
# Clean up orphaned per-session files (from crashed sessions)
|
|
199
|
-
for pidfile in "$BUDDY_DIR"/popup-reopen-pid.*; do
|
|
200
|
-
[ -f "$pidfile" ] || continue
|
|
201
|
-
local orphan_sid="${pidfile##*.}"
|
|
202
|
-
local orphan_pane="%${orphan_sid}"
|
|
203
|
-
if ! cc_pane_alive "$orphan_pane"; then
|
|
204
|
-
local orphan_pid
|
|
205
|
-
orphan_pid=$(cat "$pidfile" 2>/dev/null)
|
|
206
|
-
[ -n "$orphan_pid" ] && kill "$orphan_pid" 2>/dev/null || true
|
|
207
|
-
rm -f "$pidfile" "$BUDDY_DIR/popup-stop.$orphan_sid" "$BUDDY_DIR/popup-resize.$orphan_sid"
|
|
208
|
-
rm -f "$BUDDY_DIR/popup-env.$orphan_sid" "$BUDDY_DIR/popup-scroll.$orphan_sid"
|
|
209
|
-
rm -f "$BUDDY_DIR/reaction.$orphan_sid.json" "$BUDDY_DIR/.last_reaction.$orphan_sid" "$BUDDY_DIR/.last_comment.$orphan_sid"
|
|
210
|
-
fi
|
|
211
|
-
done
|
|
212
|
-
|
|
213
|
-
mkdir -p "$BUDDY_DIR"
|
|
214
|
-
rm -f "$STOP_FLAG" "$RESIZE_FLAG"
|
|
215
|
-
|
|
216
|
-
# tmux < 3.4 popups have a border (+2 rows, +2 cols); 3.4+ supports -B borderless
|
|
217
|
-
if ! tmux_has_borderless; then
|
|
218
|
-
BORDER_EXTRA=2
|
|
219
|
-
POPUP_W=$(( POPUP_W + 2 ))
|
|
220
|
-
fi
|
|
221
|
-
|
|
222
|
-
# Capture CC's pane ID before creating the popup
|
|
223
|
-
local cc_pane
|
|
224
|
-
cc_pane=$(tmux display-message -p '#{pane_id}')
|
|
225
|
-
|
|
226
|
-
# Run the reopen loop in background so the hook returns immediately.
|
|
227
|
-
# CRITICAL: Redirect stdio to /dev/null so the subshell doesn't inherit
|
|
228
|
-
# the parent's stdout pipe. CC's hook executor waits for ALL stdio writers
|
|
229
|
-
# to close before resolving -- without this redirect, the hook hangs forever
|
|
230
|
-
# because the long-lived subshell keeps the pipe open.
|
|
231
|
-
(
|
|
232
|
-
# Write the subshell PID. $BASHPID gives the subshell's PID on bash 4+.
|
|
233
|
-
# On macOS bash 3.2, $BASHPID doesn't exist, so we use sh -c 'echo $PPID'
|
|
234
|
-
# which prints the PID of the parent (this subshell) from a child process.
|
|
235
|
-
echo "${BASHPID:-$(sh -c 'echo $PPID')}" > "$REOPEN_PID_FILE"
|
|
236
|
-
|
|
237
|
-
while true; do
|
|
238
|
-
# Check stop conditions before (re)opening
|
|
239
|
-
[ -f "$STOP_FLAG" ] && break
|
|
240
|
-
cc_pane_alive "$cc_pane" || break
|
|
241
|
-
|
|
242
|
-
compute_dimensions
|
|
243
|
-
|
|
244
|
-
# Build popup args. tmux 3.4+ supports -B (borderless), -x R/-y S,
|
|
245
|
-
# and -e (env passing). On 3.2-3.3, we fall back to absolute positioning
|
|
246
|
-
# and pass env vars via a file.
|
|
247
|
-
local popup_args=()
|
|
248
|
-
if tmux_has_borderless; then
|
|
249
|
-
local tw th
|
|
250
|
-
tw=$(tmux display-message -p '#{window_width}' 2>/dev/null || echo 80)
|
|
251
|
-
th=$(tmux display-message -p '#{window_height}' 2>/dev/null || echo 24)
|
|
252
|
-
popup_args+=(-B -s 'bg=default')
|
|
253
|
-
popup_args+=(-x $(( tw - COMPUTED_W )) -y $(( th )))
|
|
254
|
-
popup_args+=(-e "CC_PANE=$cc_pane" -e "BUDDY_DIR=$BUDDY_DIR" -e "BUDDY_SID=$SID")
|
|
255
|
-
popup_args+=(-e "POPUP_INNER_W=$COMPUTED_W" -e "POPUP_INNER_H=$COMPUTED_H")
|
|
256
|
-
popup_args+=(-e "POPUP_ART_W=$ART_W")
|
|
257
|
-
else
|
|
258
|
-
# Fallback: position at bottom-right using absolute coords
|
|
259
|
-
local tw th
|
|
260
|
-
tw=$(tmux display-message -p '#{window_width}' 2>/dev/null || echo 80)
|
|
261
|
-
th=$(tmux display-message -p '#{window_height}' 2>/dev/null || echo 24)
|
|
262
|
-
popup_args+=(-x $(( tw - COMPUTED_W )) -y $(( th - COMPUTED_H )))
|
|
263
|
-
# Inner dimensions = outer - 2 (border takes 1 on each side)
|
|
264
|
-
local inner_w=$(( COMPUTED_W - 2 ))
|
|
265
|
-
local inner_h=$(( COMPUTED_H - 2 ))
|
|
266
|
-
# Write env vars to file (tmux 3.2-3.3 lack -e flag)
|
|
267
|
-
cat > "$BUDDY_DIR/popup-env.$SID" <<ENVEOF
|
|
268
|
-
CC_PANE=$cc_pane
|
|
269
|
-
BUDDY_DIR=$BUDDY_DIR
|
|
270
|
-
BUDDY_SID=$SID
|
|
271
|
-
POPUP_INNER_W=$inner_w
|
|
272
|
-
POPUP_INNER_H=$inner_h
|
|
273
|
-
POPUP_ART_W=$ART_W
|
|
274
|
-
ENVEOF
|
|
275
|
-
fi
|
|
276
|
-
|
|
277
|
-
# display-popup blocks until popup closes (ESC or command exit)
|
|
278
|
-
# -E = close when command exits
|
|
279
|
-
tmux display-popup \
|
|
280
|
-
"${popup_args[@]}" \
|
|
281
|
-
-w "$COMPUTED_W" -h "$COMPUTED_H" \
|
|
282
|
-
-E \
|
|
283
|
-
"$SCRIPT_DIR/buddy-popup.sh" "$SID" \
|
|
284
|
-
2>/dev/null || true
|
|
285
|
-
|
|
286
|
-
# Popup closed. Check why.
|
|
287
|
-
[ -f "$STOP_FLAG" ] && break
|
|
288
|
-
cc_pane_alive "$cc_pane" || break
|
|
289
|
-
|
|
290
|
-
# Scroll flag = F12 pressed, enter copy-mode and wait
|
|
291
|
-
if [ -f "$BUDDY_DIR/popup-scroll.$SID" ]; then
|
|
292
|
-
rm -f "$BUDDY_DIR/popup-scroll.$SID"
|
|
293
|
-
tmux copy-mode -t "$cc_pane" 2>/dev/null || true
|
|
294
|
-
# Wait until copy-mode ends before reopening popup
|
|
295
|
-
while tmux display-message -t "$cc_pane" -p '#{pane_in_mode}' 2>/dev/null | grep -q '^1$'; do
|
|
296
|
-
[ -f "$STOP_FLAG" ] && break 2
|
|
297
|
-
cc_pane_alive "$cc_pane" || break 2
|
|
298
|
-
sleep 0.3
|
|
299
|
-
done
|
|
300
|
-
# Resize flag = render loop requested a resize, not an ESC press
|
|
301
|
-
elif [ -f "$RESIZE_FLAG" ]; then
|
|
302
|
-
rm -f "$RESIZE_FLAG"
|
|
303
|
-
else
|
|
304
|
-
# ESC closed the popup -- forward ESC to CC
|
|
305
|
-
tmux send-keys -t "$cc_pane" Escape 2>/dev/null || true
|
|
306
|
-
fi
|
|
307
|
-
sleep 0.1
|
|
308
|
-
done
|
|
309
|
-
|
|
310
|
-
rm -f "$REOPEN_PID_FILE"
|
|
311
|
-
) </dev/null &>/dev/null &
|
|
312
|
-
disown
|
|
313
|
-
|
|
314
|
-
return 0
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
# ─── Stop ────────────────────────────────────────────────────────────────────
|
|
318
|
-
|
|
319
|
-
stop_popup() {
|
|
320
|
-
mkdir -p "$BUDDY_DIR"
|
|
321
|
-
# Set stop flag so reopen loop exits
|
|
322
|
-
touch "$STOP_FLAG"
|
|
323
|
-
# Close any open popup on the current client
|
|
324
|
-
tmux display-popup -C 2>/dev/null || true
|
|
325
|
-
# Kill reopen loop if still running
|
|
326
|
-
if [ -f "$REOPEN_PID_FILE" ]; then
|
|
327
|
-
local pid
|
|
328
|
-
pid=$(cat "$REOPEN_PID_FILE")
|
|
329
|
-
kill "$pid" 2>/dev/null || true
|
|
330
|
-
rm -f "$REOPEN_PID_FILE"
|
|
331
|
-
fi
|
|
332
|
-
# Clean up per-session files
|
|
333
|
-
rm -f "$BUDDY_DIR/popup-stop.$SID" "$BUDDY_DIR/popup-resize.$SID"
|
|
334
|
-
rm -f "$BUDDY_DIR/popup-env.$SID" "$BUDDY_DIR/popup-scroll.$SID"
|
|
335
|
-
rm -f "$BUDDY_DIR/reaction.$SID.json" "$BUDDY_DIR/.last_reaction.$SID" "$BUDDY_DIR/.last_comment.$SID"
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
# ─── Status ──────────────────────────────────────────────────────────────────
|
|
339
|
-
|
|
340
|
-
popup_status() {
|
|
341
|
-
if is_reopen_running; then
|
|
342
|
-
echo "running"
|
|
343
|
-
else
|
|
344
|
-
echo "stopped"
|
|
345
|
-
fi
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
# ─── Dispatch ────────────────────────────────────────────────────────────────
|
|
349
|
-
|
|
350
|
-
case "${1:-status}" in
|
|
351
|
-
start) start_popup ;;
|
|
352
|
-
stop) stop_popup ;;
|
|
353
|
-
status) popup_status ;;
|
|
354
|
-
*) echo "Usage: $0 {start|stop|status}" >&2; exit 1 ;;
|
|
355
|
-
esac
|
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ASCII art for all 18 buddy species
|
|
3
|
-
*
|
|
4
|
-
* Each species has 3 animation frames (idle variations).
|
|
5
|
-
* Each frame is 5 lines, ~12 chars wide.
|
|
6
|
-
* {E} is replaced with the eye character at render time.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { Rarity, StatName, BuddyBones } from "../../../core/engine.ts";
|
|
10
|
-
import { HAT_ART } from "../../../core/art-data.ts";
|
|
11
|
-
import { getArtFrame, SPECIES_ART } from "../../../core/render-model.ts";
|
|
12
|
-
|
|
13
|
-
// ─── Rarity ANSI colors ────────────────────────────────────────────────────
|
|
14
|
-
|
|
15
|
-
const RARITY_COLOR: Record<Rarity, string> = {
|
|
16
|
-
common: "\x1b[38;2;153;153;153m", // inactive rgb(153,153,153)
|
|
17
|
-
uncommon: "\x1b[38;2;78;186;101m", // success rgb(78,186,101)
|
|
18
|
-
rare: "\x1b[38;2;177;185;249m", // permission rgb(177,185,249)
|
|
19
|
-
epic: "\x1b[38;2;175;135;255m", // autoAccept rgb(175,135,255)
|
|
20
|
-
legendary: "\x1b[38;2;255;193;7m", // warning rgb(255,193,7)
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const SHINY_COLOR = "\x1b[93m"; // bright yellow
|
|
24
|
-
const BOLD = "\x1b[1m";
|
|
25
|
-
const DIM = "\x1b[2m";
|
|
26
|
-
const NC = "\x1b[0m";
|
|
27
|
-
|
|
28
|
-
export const RARITY_STARS: Record<Rarity, string> = {
|
|
29
|
-
common: "\u2605",
|
|
30
|
-
uncommon: "\u2605\u2605",
|
|
31
|
-
rare: "\u2605\u2605\u2605",
|
|
32
|
-
epic: "\u2605\u2605\u2605\u2605",
|
|
33
|
-
legendary: "\u2605\u2605\u2605\u2605\u2605",
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
// ─── Display width helpers ──────────────────────────────────────────────────
|
|
37
|
-
|
|
38
|
-
function stripAnsi(s: string): string { return s.replace(/\x1b\[[^m]*m/g, ""); }
|
|
39
|
-
|
|
40
|
-
function charWidth(cp: number): number {
|
|
41
|
-
if (cp >= 0xFE00 && cp <= 0xFE0F) return 0;
|
|
42
|
-
if (cp === 0x200D) return 0;
|
|
43
|
-
if (cp >= 0x1F000) return 2;
|
|
44
|
-
if (cp === 0x2728) return 2; // ✨
|
|
45
|
-
if (cp >= 0x2600 && cp <= 0x27BF) return 1;
|
|
46
|
-
if (cp >= 0x2500 && cp <= 0x259F) return 1;
|
|
47
|
-
if (cp >= 0x3000 && cp <= 0x9FFF) return 2;
|
|
48
|
-
if (cp >= 0xFF01 && cp <= 0xFF60) return 2;
|
|
49
|
-
return 1;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function displayWidth(s: string): number {
|
|
53
|
-
let w = 0;
|
|
54
|
-
for (const ch of stripAnsi(s)) w += charWidth(ch.codePointAt(0)!);
|
|
55
|
-
return w;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** Pad string with spaces to reach target display width */
|
|
59
|
-
function dpad(s: string, targetW: number): string {
|
|
60
|
-
const w = displayWidth(s);
|
|
61
|
-
return w < targetW ? s + " ".repeat(targetW - w) : s;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// ─── Render functions ───────────────────────────────────────────────────────
|
|
65
|
-
|
|
66
|
-
export function renderCompanionCard(
|
|
67
|
-
bones: BuddyBones,
|
|
68
|
-
name: string,
|
|
69
|
-
personality: string,
|
|
70
|
-
reaction?: string,
|
|
71
|
-
frame: number = 0,
|
|
72
|
-
width: number = 40,
|
|
73
|
-
): string {
|
|
74
|
-
const color = RARITY_COLOR[bones.rarity];
|
|
75
|
-
const stars = RARITY_STARS[bones.rarity];
|
|
76
|
-
const shiny = bones.shiny ? `${SHINY_COLOR}\u2728 ${NC}` : "";
|
|
77
|
-
const art = getArtFrame(bones.species, bones.eye, frame);
|
|
78
|
-
|
|
79
|
-
// Hat: replace first empty art line
|
|
80
|
-
const hatLine = HAT_ART[bones.hat];
|
|
81
|
-
if (hatLine && !art[0].trim()) {
|
|
82
|
-
art[0] = hatLine;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Build the card
|
|
86
|
-
const W = Math.max(24, width);
|
|
87
|
-
const hr = "\u2500".repeat(W - 2);
|
|
88
|
-
const lines: string[] = [];
|
|
89
|
-
|
|
90
|
-
// Top border
|
|
91
|
-
lines.push(`${color}\u256d${hr}\u256e${NC}`);
|
|
92
|
-
|
|
93
|
-
// Inner width = W - 2 (borders), content area = W - 4 (borders + padding)
|
|
94
|
-
const innerW = W - 4;
|
|
95
|
-
|
|
96
|
-
// Species art (centered)
|
|
97
|
-
for (const artLine of art) {
|
|
98
|
-
if (!artLine.trim()) continue;
|
|
99
|
-
lines.push(`${color}\u2502${NC} ${dpad(artLine, innerW)}${color}\u2502${NC}`);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Separator
|
|
103
|
-
lines.push(`${color}\u251c${"╌".repeat(W - 2)}\u2524${NC}`);
|
|
104
|
-
|
|
105
|
-
// Name + rarity
|
|
106
|
-
const nameStarsRaw = `${BOLD}${name}${NC} ${color}${stars}${NC}`;
|
|
107
|
-
lines.push(`${color}\u2502${NC} ${nameStarsRaw}${" ".repeat(Math.max(0, innerW - displayWidth(name) - 2 - displayWidth(stars)))}${color}\u2502${NC}`);
|
|
108
|
-
|
|
109
|
-
const rarityRaw = `${shiny}${color}${BOLD}${bones.rarity.toUpperCase()}${NC} ${bones.species}`;
|
|
110
|
-
const rarityVis = (bones.shiny ? 3 : 0) + bones.rarity.length + 1 + bones.species.length;
|
|
111
|
-
lines.push(`${color}\u2502${NC} ${rarityRaw}${" ".repeat(Math.max(0, innerW - rarityVis))}${color}\u2502${NC}`);
|
|
112
|
-
|
|
113
|
-
// Eye + Hat info
|
|
114
|
-
const cosmeticLine = `eye: ${bones.eye} hat: ${bones.hat}`;
|
|
115
|
-
lines.push(`${color}\u2502${NC} ${DIM}${cosmeticLine}${NC}${" ".repeat(Math.max(0, innerW - displayWidth(cosmeticLine)))}${color}\u2502${NC}`);
|
|
116
|
-
|
|
117
|
-
// Separator
|
|
118
|
-
lines.push(`${color}\u251c${"╌".repeat(W - 2)}\u2524${NC}`);
|
|
119
|
-
|
|
120
|
-
// Stats
|
|
121
|
-
const STAT_NAMES: StatName[] = ["DEBUGGING", "PATIENCE", "CHAOS", "WISDOM", "SNARK"];
|
|
122
|
-
for (const stat of STAT_NAMES) {
|
|
123
|
-
const val = bones.stats[stat];
|
|
124
|
-
const filled = Math.round(val / 10);
|
|
125
|
-
const bar = "\u2588".repeat(filled) + "\u2591".repeat(10 - filled);
|
|
126
|
-
const label = stat.slice(0, 3).padEnd(3);
|
|
127
|
-
const marker = stat === bones.peak ? " \u25b2" : stat === bones.dump ? " \u25bc" : " ";
|
|
128
|
-
const valStr = String(val).padStart(3);
|
|
129
|
-
const statLine = `${DIM}${label}${NC} ${bar} ${valStr}${marker}`;
|
|
130
|
-
const statVis = 3 + 1 + 10 + 1 + 3 + 2; // label + spaces + bar + val + marker = 20
|
|
131
|
-
lines.push(`${color}\u2502${NC} ${statLine}${" ".repeat(Math.max(0, innerW - statVis))}${color}\u2502${NC}`);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// Speech bubble (if reaction)
|
|
135
|
-
if (reaction) {
|
|
136
|
-
lines.push(`${color}\u251c${"╌".repeat(W - 2)}\u2524${NC}`);
|
|
137
|
-
const maxMsg = innerW - 3; // "💬 " prefix (💬 = 2 cols + space)
|
|
138
|
-
const msg = displayWidth(reaction) > maxMsg ? reaction.slice(0, maxMsg - 1) + "\u2026" : reaction;
|
|
139
|
-
const msgPad = Math.max(0, innerW - displayWidth(msg) - 3);
|
|
140
|
-
lines.push(`${color}\u2502${NC} \ud83d\udcac ${msg}${" ".repeat(msgPad)}${color}\u2502${NC}`);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Personality
|
|
144
|
-
if (personality) {
|
|
145
|
-
lines.push(`${color}\u251c${"╌".repeat(W - 2)}\u2524${NC}`);
|
|
146
|
-
const words = personality.split(" ");
|
|
147
|
-
let line = "";
|
|
148
|
-
for (const word of words) {
|
|
149
|
-
if (displayWidth(line) + displayWidth(word) + 1 > innerW) {
|
|
150
|
-
lines.push(`${color}\u2502${NC} ${DIM}${dpad(line, innerW)}${NC}${color}\u2502${NC}`);
|
|
151
|
-
line = word;
|
|
152
|
-
} else {
|
|
153
|
-
line = line ? `${line} ${word}` : word;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
if (line) {
|
|
157
|
-
lines.push(`${color}\u2502${NC} ${DIM}${dpad(line, innerW)}${NC}${color}\u2502${NC}`);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// Bottom border
|
|
162
|
-
lines.push(`${color}\u2570${hr}\u256f${NC}`);
|
|
163
|
-
|
|
164
|
-
return lines.join("\n");
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// ─── Markdown-native render (for MCP tool responses) ───────────────────────
|
|
168
|
-
//
|
|
169
|
-
// Claude Code's UI doesn't render raw ANSI escape codes properly — it strips
|
|
170
|
-
// the ESC byte but leaves "[38;2;...m" as literal text, making the output
|
|
171
|
-
// unreadable. This renderer produces pure markdown with unicode rarity dots
|
|
172
|
-
// instead of ANSI colors, so it renders cleanly in any MCP client UI.
|
|
173
|
-
|
|
174
|
-
const RARITY_DOT: Record<Rarity, string> = {
|
|
175
|
-
common: "\u26AA", // ⚪ white circle
|
|
176
|
-
uncommon: "\uD83D\uDFE2", // 🟢 green circle
|
|
177
|
-
rare: "\uD83D\uDD35", // 🔵 blue circle
|
|
178
|
-
epic: "\uD83D\uDFE3", // 🟣 purple circle
|
|
179
|
-
legendary: "\uD83D\uDFE1", // 🟡 yellow circle
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
export function renderCompanionCardMarkdown(
|
|
183
|
-
bones: BuddyBones,
|
|
184
|
-
name: string,
|
|
185
|
-
personality: string,
|
|
186
|
-
reaction?: string,
|
|
187
|
-
frame: number = 0,
|
|
188
|
-
): string {
|
|
189
|
-
const dot = RARITY_DOT[bones.rarity];
|
|
190
|
-
const stars = RARITY_STARS[bones.rarity];
|
|
191
|
-
const shiny = bones.shiny ? " \u2728" : "";
|
|
192
|
-
const art = getArtFrame(bones.species, bones.eye, frame);
|
|
193
|
-
|
|
194
|
-
// Hat: replace first empty art line
|
|
195
|
-
const hatLine = HAT_ART[bones.hat];
|
|
196
|
-
if (hatLine && !art[0].trim()) {
|
|
197
|
-
art[0] = hatLine;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// Strip empty lines from art for cleaner rendering
|
|
201
|
-
const artLines = art.filter((l) => l.trim().length > 0);
|
|
202
|
-
|
|
203
|
-
const STAT_NAMES: StatName[] = ["DEBUGGING", "PATIENCE", "CHAOS", "WISDOM", "SNARK"];
|
|
204
|
-
const statRows = STAT_NAMES.map((stat) => {
|
|
205
|
-
const val = bones.stats[stat];
|
|
206
|
-
const filled = Math.round(val / 10);
|
|
207
|
-
const bar = "\u2588".repeat(filled) + "\u2591".repeat(10 - filled);
|
|
208
|
-
const marker = stat === bones.peak ? " \u25B2" : stat === bones.dump ? " \u25BC" : "";
|
|
209
|
-
const label = `**${stat.slice(0, 3)}**${stat.slice(3)}`;
|
|
210
|
-
return `| ${label} | ${val}${marker} | \`${bar}\` |`;
|
|
211
|
-
}).join("\n");
|
|
212
|
-
|
|
213
|
-
const parts: string[] = [];
|
|
214
|
-
|
|
215
|
-
// Header: rarity dot, name, species+rarity, stars, shiny
|
|
216
|
-
parts.push(`### ${dot} ${name} · \`${bones.rarity.toUpperCase()} ${bones.species}\` · ${stars}${shiny}`);
|
|
217
|
-
parts.push("");
|
|
218
|
-
|
|
219
|
-
// ASCII art in a code block (preserves monospaced formatting)
|
|
220
|
-
parts.push("```");
|
|
221
|
-
parts.push(artLines.join("\n"));
|
|
222
|
-
parts.push("```");
|
|
223
|
-
parts.push("");
|
|
224
|
-
|
|
225
|
-
// Identity line
|
|
226
|
-
parts.push(`**Identity:** eye \`${bones.eye}\` · hat \`${bones.hat}\``);
|
|
227
|
-
parts.push("");
|
|
228
|
-
|
|
229
|
-
// Stats table
|
|
230
|
-
parts.push("| Stat | Value | Bar |");
|
|
231
|
-
parts.push("|---|---|---|");
|
|
232
|
-
parts.push(statRows);
|
|
233
|
-
parts.push("");
|
|
234
|
-
|
|
235
|
-
// Reaction (if any) — reactions often already contain asterisks
|
|
236
|
-
// for actions like "*blinks slowly*", so render them verbatim to avoid
|
|
237
|
-
// accidentally turning italics into bold.
|
|
238
|
-
if (reaction) {
|
|
239
|
-
parts.push(`\ud83d\udcac ${reaction}`);
|
|
240
|
-
parts.push("");
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// Personality as blockquote
|
|
244
|
-
if (personality) {
|
|
245
|
-
parts.push(`> ${personality}`);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
return parts.join("\n");
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// ─── Compact status line render ─────────────────────────────────────────────
|
|
252
|
-
|
|
253
|
-
export function renderStatusLine(
|
|
254
|
-
bones: BuddyBones,
|
|
255
|
-
name: string,
|
|
256
|
-
reaction?: string,
|
|
257
|
-
): string {
|
|
258
|
-
const face = SPECIES_ART[bones.species][0][2]?.replace(/\{E\}/g, bones.eye).trim() || "(?)";
|
|
259
|
-
const color = RARITY_COLOR[bones.rarity];
|
|
260
|
-
const stars = RARITY_STARS[bones.rarity];
|
|
261
|
-
const shiny = bones.shiny ? "\u2728" : "";
|
|
262
|
-
const msg = reaction ? ` \u2502 "${reaction}"` : "";
|
|
263
|
-
return `${color}${face}${NC} ${BOLD}${name}${NC} ${shiny}${color}${stars}${NC}${msg}`;
|
|
264
|
-
}
|