From 57a428cee68b819ac13ccf2b23e98c7192c6eab1 Mon Sep 17 00:00:00 2001 From: Natalie Date: Sun, 17 May 2026 04:20:17 -0700 Subject: [PATCH] =?UTF-8?q?feat(@scripts):=20=E2=9C=A8=20improve=20resume?= =?UTF-8?q?=20picker=20logic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Lilith Autocommit --- bin/rclaude | 49 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/bin/rclaude b/bin/rclaude index a508f00..cfc1278 100755 --- a/bin/rclaude +++ b/bin/rclaude @@ -31,9 +31,8 @@ # rclaude # remote (or local) at # rclaude list # tmux + per-project disk view # rclaude list sessions # tmux + per-session disk view (uuid + snippet) -# rclaude resume [pattern] # reattach / resume by uuid prefix, snippet, -# # tmux name, or cwd substring (interactive -# # picker on >1 match) +# rclaude resume # picker: live tmux + most-recent disk (--- separator) +# rclaude resume # search tmux + disk sessions (uuid, snippet, cwd) # # Mirror semantics: if local $PWD is $HOME/X/Y, the remote dir defaults to # ~/X/Y on the remote (the remote's $HOME, not $HOME from this machine). @@ -241,11 +240,33 @@ cmd_list() { # - matches a snippet/cwd → same as session (the row identifies a UUID) # # Pattern matching is case-insensitive substring across host/kind/uuid/snippet/cwd. -# An empty pattern lists everything (interactive picker). +# No pattern: live tmux sessions on top, then most-recent disk sessions across +# hosts (separated by ---). Picker label space caps the combined view at 35. cmd_resume() { _pattern=${1:-} - _matches=$(scan_hosts | while IFS= read -r h; do list_search_on "$h"; done) - if [ -n "$_pattern" ]; then + case $_pattern in + --all|-a) _pattern="" ;; + esac + if [ -z "$_pattern" ]; then + _tmux=$(scan_hosts | while IFS= read -r h; do list_tmux_on "$h"; done) + _disk=$(scan_hosts | while IFS= read -r h; do list_sessions_on "$h"; done) + _t_count=0; _d_total=0 + [ -n "$_tmux" ] && _t_count=$(printf '%s\n' "$_tmux" | wc -l | tr -d ' ') + [ -n "$_disk" ] && _d_total=$(printf '%s\n' "$_disk" | wc -l | tr -d ' ') + _d_room=$((35 - _t_count)) + [ "$_d_room" -lt 0 ] && _d_room=0 + if [ "$_d_room" -gt 0 ] && [ -n "$_disk" ]; then + _disk_slice=$(printf '%s\n' "$_disk" | head -n "$_d_room") + else + _disk_slice="" + fi + if [ -n "$_tmux" ] && [ -n "$_disk_slice" ]; then + _matches=$(printf '%s\n%s' "$_tmux" "$_disk_slice") + else + _matches=${_tmux:-$_disk_slice} + fi + else + _matches=$(scan_hosts | while IFS= read -r h; do list_search_on "$h"; done) _matches=$(printf '%s\n' "$_matches" | grep -F -i -- "$_pattern" || true) fi _count=0 @@ -256,9 +277,11 @@ cmd_resume() { fi if [ "$_count" -gt 1 ]; then _keys="123456789abcdefghijklmnopqrstuvwxyz" + # Pattern-search truncation (no-pattern case is already capped above). if [ "$_count" -gt 35 ]; then - echo "too many matches ($_count); refine pattern" >&2 - exit 1 + _matches=$(printf '%s\n' "$_matches" | head -n 35) + _count=35 + printf 'rclaude: %s matches; showing 35 most recent\n' "$_count" >&2 fi # For sessions, display the human-readable snippet (col 4) rather # than the bare UUID (col 3); for tmux/disk the existing col 3 is @@ -270,12 +293,22 @@ cmd_resume() { exit 1 fi _i=0 + _prev_kind="" printf '%s\n' "$_matches" | while IFS= read -r _line; do _i=$((_i + 1)) + _kind_now=$(printf %s "$_line" | awk -F'\t' '{print $2}') + if [ "$_prev_kind" = "tmux" ] && [ "$_kind_now" != "tmux" ]; then + printf ' ---\n' >&2 + fi _k=$(printf %s "$_keys" | cut -c"$_i") printf ' [%s] %s\n' "$_k" \ "$(printf %s "$_line" | awk -F'\t' "$_fmt_row")" >&2 + _prev_kind=$_kind_now done + if [ -z "$_pattern" ] && [ "${_d_total:-0}" -gt "${_d_room:-0}" ]; then + printf ' (showing %s most recent of %s disk sessions; pass a pattern to search older)\n' \ + "$_d_room" "$_d_total" >&2 + fi _last_key=$(printf %s "$_keys" | cut -c"$_count") printf 'select [1-%s]: ' "$_last_key" >&2 _old=$(stty -g 2>/dev/null || true)