feat(@scripts): improve home resolution error handling

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
Natalie 2026-05-17 17:42:06 -07:00
parent 4968a0bdf8
commit 949e63f16d

View file

@ -253,18 +253,27 @@ deep_search_on() {
} }
# Get $HOME on <host> (cached per host in /tmp for the life of this shell). # Get $HOME on <host> (cached per host in /tmp for the life of this shell).
# Always returns 0 — caller distinguishes success/failure by checking whether
# the output is empty (e.g. unknown host, ssh refused). This matters because
# the script runs under `set -e`; a function returning non-zero from inside
# `$(...)` aborts the caller mid-flow.
get_home() { get_home() {
_h=$1 _h=$1
_cache="/tmp/rclaude-home.$(whoami).$(printf %s "$_h" | tr -c 'A-Za-z0-9' '_')" _cache="/tmp/rclaude-home.$(whoami).$(printf %s "$_h" | tr -c 'A-Za-z0-9' '_')"
if [ -s "$_cache" ]; then if [ -s "$_cache" ]; then
cat "$_cache"; return cat "$_cache"
return 0
fi fi
if is_local "$_h"; then if is_local "$_h"; then
_v=$HOME _v=$HOME
else else
_v=$(ssh -o BatchMode=yes -o ConnectTimeout=3 "$_h" 'printf %s "$HOME"' 2>/dev/null || true) _v=$(ssh -o BatchMode=yes -o ConnectTimeout=3 "$_h" 'printf %s "$HOME"' 2>/dev/null || true)
fi fi
[ -n "$_v" ] && printf '%s' "$_v" > "$_cache" && printf %s "$_v" if [ -n "$_v" ]; then
printf '%s' "$_v" > "$_cache" 2>/dev/null || true
printf %s "$_v"
fi
return 0
} }
# Compute Claude's project-slug from a cwd path. Claude replaces every # Compute Claude's project-slug from a cwd path. Claude replaces every
@ -958,8 +967,21 @@ cmd_resume() {
# copy JSONL with cwd rewritten, then launch on dst. # copy JSONL with cwd rewritten, then launch on dst.
_src_home=$(get_home "$_host") _src_home=$(get_home "$_host")
_dst_home=$(get_home "$_dst") _dst_home=$(get_home "$_dst")
if [ -z "$_src_home" ] || [ -z "$_dst_home" ]; then if [ -z "$_dst_home" ]; then
echo "rclaude: couldn't resolve \$HOME on $_host or $_dst" >&2 printf "rclaude: can't reach '%s' (ssh failed or hostname doesn't resolve)\n" "$_dst" >&2
# Did you mean? — match a known host whose first 3 chars
# match (cheap typo catch). Strips trailing .lan/.local on
# both sides before comparing.
_t_base=$(printf %s "$_dst" | sed 's/\.\(lan\|local\)$//' | cut -c1-3)
_hint=$(scan_hosts | while IFS= read -r _h; do
_hb=$(printf %s "$_h" | sed 's/\.\(lan\|local\)$//' | cut -c1-3)
[ "$_hb" = "$_t_base" ] && echo "$_h" && break
done)
[ -n "$_hint" ] && printf " did you mean: %s ?\n" "$_hint" >&2
exit 1
fi
if [ -z "$_src_home" ]; then
printf "rclaude: couldn't resolve \$HOME on source '%s'\n" "$_host" >&2
exit 1 exit 1
fi fi
case $_session_cwd in case $_session_cwd in