feat(@scripts): add name enrichment for resume picker

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
Natalie 2026-05-17 07:42:01 -07:00
parent 96020c67d2
commit b1e7f46f25

View file

@ -187,6 +187,28 @@ _filter_sessions_to_uuids() {
| awk -F'\t' -v r="^($_re)$" '$3 ~ r'
}
# Build a `host\tuuid\tname` table of every session that has a display name
# set via `claude -n <name>`. Used to enrich the resume picker so names show
# next to each row.
build_name_map() {
_py='import json, os, glob
for f in glob.glob(os.path.expanduser("~/.claude/sessions/*.json")):
try: d = json.load(open(f))
except Exception: continue
sid = d.get("sessionId") or ""
name = d.get("name") or ""
if sid and name: print(f"{sid}\t{name}")'
scan_hosts | while IFS= read -r _h; do
if is_local "$_h"; then
python3 -c "$_py" 2>/dev/null
else
ssh -o BatchMode=yes -o ConnectTimeout=3 "$_h" "python3 -" 2>/dev/null <<PYEOF || true
$_py
PYEOF
fi | awk -F'\t' -v host="$_h" '{print host "\t" $1 "\t" $2}'
done
}
# Cheap match by session display name (the `claude -n <name>` label, stored in
# ~/.claude/sessions/<pid>.json). Single ssh round-trip. Always included in
# pattern searches because the file count is bounded (one per active pid).
@ -683,6 +705,21 @@ cmd_resume() {
fi
if [ "$_count" -gt 1 ]; then
_keys="123456789abcdefghijklmnopqrstuvwxyz"
# Append a trailing name column (host+uuid → display name from
# ~/.claude/sessions/*.json). Empty for tmux rows and for sessions
# with no `claude -n` label.
_name_map=$(build_name_map)
_matches=$(printf '%s\n' "$_matches" | awk -F'\t' -v OFS='\t' -v map="$_name_map" '
BEGIN {
n = split(map, lines, "\n")
for (i=1; i<=n; i++) {
split(lines[i], f, "\t")
if (f[1] && f[2]) names[f[1] SUBSEP f[2]] = f[3]
}
}
{ nm = ($2=="tmux") ? "" : (($1 SUBSEP $3) in names ? names[$1 SUBSEP $3] : "")
print $0, nm }
')
if [ "$_count" -gt 35 ]; then
_orig_count=$_count
_matches=$(printf '%s\n' "$_matches" | head -n 35)