fix(@scripts): 🐛 improve session triage display balancing

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
Natalie 2026-05-17 05:22:30 -07:00
parent 4f30666964
commit 4b464dfc82

View file

@ -417,10 +417,26 @@ cmd_resume() {
_d_total=0; _d_room=0
if [ "$_triage_mode" = "1" ]; then
printf 'rclaude: triaging sessions...\n' >&2
_matches=$(scan_hosts | while IFS= read -r h; do
list_tmux_on "$h"
list_triage_on "$h"
done)
# Collect tmux rows from all hosts first so they always appear in the
# picker even when triage produces > (35 - tmux_count) rows on a single
# host that would otherwise crowd them out.
_tmux=$(scan_hosts | while IFS= read -r h; do list_tmux_on "$h"; done)
_triage=$(scan_hosts | while IFS= read -r h; do list_triage_on "$h"; done)
_t_count=0
[ -n "$_tmux" ] && _t_count=$(printf '%s\n' "$_tmux" | wc -l | tr -d ' ')
[ -n "$_triage" ] && _d_total=$(printf '%s\n' "$_triage" | wc -l | tr -d ' ')
_d_room=$((35 - _t_count))
[ "$_d_room" -lt 0 ] && _d_room=0
if [ "$_d_room" -gt 0 ] && [ -n "$_triage" ]; then
_triage_slice=$(printf '%s\n' "$_triage" | head -n "$_d_room")
else
_triage_slice=""
fi
if [ -n "$_tmux" ] && [ -n "$_triage_slice" ]; then
_matches=$(printf '%s\n%s' "$_tmux" "$_triage_slice")
else
_matches=${_tmux:-$_triage_slice}
fi
elif [ -z "$_pattern" ]; then
_tmux=$(scan_hosts | while IFS= read -r h; do list_tmux_on "$h"; done)
_disk_raw=$(scan_hosts | while IFS= read -r h; do list_sessions_on "$h"; done)
@ -465,19 +481,52 @@ cmd_resume() {
_count=35
printf 'rclaude: %s matches; showing 35 most recent (refine with a pattern to see others)\n' "$_orig_count" >&2
fi
# Per-row display: triage rows surface priority + status + summary;
# session rows show the user-message snippet; tmux/disk show $3.
# ANSI colors (only when stderr is a tty). Conservative palette —
# host cyan, tmux marker bold-green, priority red/yellow, statuses
# colored, uuid8 dimmed, key bracket bold-magenta.
if [ -t 2 ]; then
_R=$(printf '\033[0m')
_Chost=$(printf '\033[36m'); _Ctmux=$(printf '\033[1;32m')
_Cdim=$(printf '\033[2m'); _Ckey=$(printf '\033[1;35m')
_Cp5=$(printf '\033[1;31m'); _Cp4=$(printf '\033[33m')
_Cblk=$(printf '\033[31m'); _Cwait=$(printf '\033[33m')
_Cinp=$(printf '\033[36m'); _Cdone=$(printf '\033[32m')
else
_R=; _Chost=; _Ctmux=; _Cdim=; _Ckey=
_Cp5=; _Cp4=; _Cblk=; _Cwait=; _Cinp=; _Cdone=
fi
# Kind column dropped — it carried no signal when all rows were the
# same kind. Kind is now encoded by row shape: tmux has a ▶ marker,
# triage shows P<n> + status, session shows the snippet plain.
_fmt_row='
function prio_c(p) { if (p=="5") return c_p5; if (p=="4") return c_p4; return "" }
function stat_c(s) {
if (s=="blocked") return c_blk
if (s=="waiting_on_user") return c_wait
if (s=="in_progress") return c_inp
if (s=="done") return c_done
return ""
}
function display() {
if ($2 == "triage") return sprintf("P%s %-13s %s [%s]", $4, $5, $6, substr($3, 1, 8))
if ($2 == "session") return $4 " [" substr($3, 1, 8) "]"
if ($2 == "tmux")
return c_tmux "▶ " r $3
if ($2 == "triage")
return prio_c($4) "P" $4 r " " stat_c($5) sprintf("%-15s", $5) r " " $6 " " c_dim "[" substr($3,1,8) "]" r
if ($2 == "session")
return $4 " " c_dim "[" substr($3,1,8) "]" r
return $3
}
{ printf "%-10s %-7s %s", $1, $2, display() }
{
printf "%s%-10s%s %s", c_host, $1, r, display()
}
'
if [ ! -t 0 ] || [ ! -t 2 ]; then
echo "multiple matches and no tty for picker; refine pattern:" >&2
printf '%s\n' "$_matches" | awk -F'\t' "$_fmt_row"'{printf "\n"}' >&2
printf '%s\n' "$_matches" | awk -F'\t' \
-v r="$_R" -v c_host="$_Chost" -v c_tmux="$_Ctmux" -v c_dim="$_Cdim" \
-v c_p5="$_Cp5" -v c_p4="$_Cp4" \
-v c_blk="$_Cblk" -v c_wait="$_Cwait" -v c_inp="$_Cinp" -v c_done="$_Cdone" \
"$_fmt_row"'{printf "\n"}' >&2
exit 1
fi
_i=0
@ -486,19 +535,23 @@ cmd_resume() {
_i=$((_i + 1))
_kind_now=$(printf %s "$_line" | awk -F'\t' '{print $2}')
if [ "$_prev_kind" = "tmux" ] && [ "$_kind_now" != "tmux" ]; then
printf ' ---\n' >&2
printf ' %s---%s\n' "$_Cdim" "$_R" >&2
fi
_k=$(printf %s "$_keys" | cut -c"$_i")
printf ' [%s] %s\n' "$_k" \
"$(printf %s "$_line" | awk -F'\t' "$_fmt_row")" >&2
_row_text=$(printf %s "$_line" | awk -F'\t' \
-v r="$_R" -v c_host="$_Chost" -v c_tmux="$_Ctmux" -v c_dim="$_Cdim" \
-v c_p5="$_Cp5" -v c_p4="$_Cp4" \
-v c_blk="$_Cblk" -v c_wait="$_Cwait" -v c_inp="$_Cinp" -v c_done="$_Cdone" \
"$_fmt_row")
printf ' %s[%s]%s %s\n' "$_Ckey" "$_k" "$_R" "$_row_text" >&2
_prev_kind=$_kind_now
done
if [ "$_d_total" -gt "$_d_room" ] && [ "$_d_room" -gt 0 ]; then
printf ' (showing %s most recent of %s disk sessions; pass a pattern to search older)\n' \
"$_d_room" "$_d_total" >&2
printf ' %s(showing %s most recent of %s disk sessions; pass a pattern to search older)%s\n' \
"$_Cdim" "$_d_room" "$_d_total" "$_R" >&2
fi
_last_key=$(printf %s "$_keys" | cut -c"$_count")
printf 'select [1-%s]: ' "$_last_key" >&2
printf '%sselect [1-%s]:%s ' "$_Ckey" "$_last_key" "$_R" >&2
_old=$(stty -g 2>/dev/null || true)
stty -icanon -echo min 1 time 0 2>/dev/null || true
_key=$(dd bs=1 count=1 2>/dev/null </dev/tty || true)