From 949e63f16df8b47eb9d7805c5d03aa41e5ffe3e5 Mon Sep 17 00:00:00 2001 From: Natalie Date: Sun, 17 May 2026 17:42:06 -0700 Subject: [PATCH] =?UTF-8?q?feat(@scripts):=20=E2=9C=A8=20improve=20home=20?= =?UTF-8?q?resolution=20error=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Lilith Autocommit --- bin/rclaude | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/bin/rclaude b/bin/rclaude index e4623b3..2e398f8 100755 --- a/bin/rclaude +++ b/bin/rclaude @@ -253,18 +253,27 @@ deep_search_on() { } # Get $HOME on (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() { _h=$1 _cache="/tmp/rclaude-home.$(whoami).$(printf %s "$_h" | tr -c 'A-Za-z0-9' '_')" if [ -s "$_cache" ]; then - cat "$_cache"; return + cat "$_cache" + return 0 fi if is_local "$_h"; then _v=$HOME else _v=$(ssh -o BatchMode=yes -o ConnectTimeout=3 "$_h" 'printf %s "$HOME"' 2>/dev/null || true) 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 @@ -958,8 +967,21 @@ cmd_resume() { # copy JSONL with cwd rewritten, then launch on dst. _src_home=$(get_home "$_host") _dst_home=$(get_home "$_dst") - if [ -z "$_src_home" ] || [ -z "$_dst_home" ]; then - echo "rclaude: couldn't resolve \$HOME on $_host or $_dst" >&2 + if [ -z "$_dst_home" ]; then + 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 fi case $_session_cwd in