From 3f7c9ecbfc76fa2b394792e7b2c3fb0b848ac739 Mon Sep 17 00:00:00 2001 From: Natalie Date: Sun, 17 May 2026 08:06:16 -0700 Subject: [PATCH] =?UTF-8?q?feat(@scripts):=20=E2=9C=A8=20add=20session=20a?= =?UTF-8?q?rchiving=20feature=20for=20hiding=20sessions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Lilith Autocommit --- bin/rclaude | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/bin/rclaude b/bin/rclaude index 237b9e9..e4623b3 100755 --- a/bin/rclaude +++ b/bin/rclaude @@ -358,6 +358,12 @@ _SSH_LIVE_OPTS='-o ServerAliveInterval=30 -o ServerAliveCountMax=6 -o TCPKeepAli # Cache dir for per-host setup markers. A marker file means we've already # probed + installed deps on that host within RCLAUDE_SETUP_TTL days. _SETUP_CACHE_DIR=${XDG_CACHE_HOME:-$HOME/.cache}/rclaude + +# Archive: per-user list of session UUIDs to hide from `rclaude resume`. One +# uuid per line. Populated via the picker's `-` key (then a selection key). +_ARCHIVE_FILE=${XDG_DATA_HOME:-$HOME/.local/share}/rclaude/archived-uuids +mkdir -p "$(dirname "$_ARCHIVE_FILE")" 2>/dev/null +[ -f "$_ARCHIVE_FILE" ] || touch "$_ARCHIVE_FILE" 2>/dev/null _SETUP_TTL_DAYS=${RCLAUDE_SETUP_TTL:-7} # Detect package-manager family on . Output: macos | rhel | debian | unknown. @@ -700,6 +706,13 @@ cmd_resume() { _matches=$(scan_hosts | while IFS= read -r h; do deep_search_on "$h" "$_pattern"; done | dedupe_sessions) fi fi + # Filter out archived UUIDs (added via picker `-` key, see below). + if [ -s "$_ARCHIVE_FILE" ]; then + _matches=$(printf '%s\n' "$_matches" | awk -F'\t' -v af="$_ARCHIVE_FILE" ' + BEGIN { while ((getline u < af) > 0) arch[u]=1; close(af) } + ($2 == "tmux") || !($3 in arch) + ') + fi _count=0 [ -n "$_matches" ] && _count=$(printf '%s\n' "$_matches" | wc -l | tr -d ' ') if [ "$_count" -eq 0 ]; then @@ -793,6 +806,9 @@ cmd_resume() { if ($2 == "session") return $4 " " c_dim "[" substr($3,1,8) "]" r return $3 } + # Col B: the explicit `claude -n` display name (NF). Blank when + # the session was never named — col C (dir) carries the project + # identity in that case. function name_col() { return ($2=="tmux") ? "" : $NF } { printf "%s%-10s%s %s%-22s%s %s%-22s%s %s", @@ -835,10 +851,40 @@ cmd_resume() { "$_Cdim" "$_d_room" "$_d_total" "$_R" >&2 fi _last_key=$(printf %s "$_keys" | cut -c"$_count") - printf '%sselect [1-%s] (q to cancel):%s ' "$_Ckey" "$_last_key" "$_R" >&2 + printf '%sselect [1-%s] (- archive, q cancel):%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 &2 + _key=$(dd bs=1 count=1 2>/dev/null /dev/null || true + printf '%s\n' "$_key" >&2 + _idx=0; _c=1 + while [ "$_c" -le "$_count" ]; do + if [ "$(printf %s "$_keys" | cut -c"$_c")" = "$_key" ]; then + _idx=$_c; break + fi + _c=$((_c + 1)) + done + if [ "$_idx" -eq 0 ]; then + echo "rclaude: invalid selection: '$_key'" >&2; exit 1 + fi + _row=$(printf '%s\n' "$_matches" | sed -n "${_idx}p") + _au=$(printf %s "$_row" | awk -F'\t' '{print $3}') + _akind=$(printf %s "$_row" | awk -F'\t' '{print $2}') + if [ "$_akind" = "tmux" ]; then + echo "rclaude: can't archive a live tmux row — kill the session instead (tmux kill-session)" >&2 + exit 1 + fi + printf '%s\n' "$_au" >> "$_ARCHIVE_FILE" + printf 'rclaude: archived %s (hidden from future resume lists; edit %s to undo)\n' \ + "$(printf %s "$_au" | cut -c1-8)" "$_ARCHIVE_FILE" >&2 + exit 0 + fi [ -n "$_old" ] && stty "$_old" 2>/dev/null || true # Render the keystroke we just consumed. Empty (EOF), Enter, Esc, q, # and Ctrl-C all mean "cancel" — just exit cleanly.