From 760e682b89e65ef0e32197bc8df7cc6d5c3ad727 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 21 Apr 2026 22:27:20 +0000 Subject: [PATCH] fix(marmot-interop): parse post-v0.2 \`wn --json whoami\` shape wn now wraps account listings in {"result": [{...}]} so extract_pubkey's object + array fallbacks both missed it and ensure_identity bailed with "could not determine \$who npub" immediately after create-identity. Also: create-identity on a fresh box can exit non-zero with "failed to connect to any relays" even when the account *was* created locally. Probe --json whoami afterwards before calling that a fatal. https://claude.ai/code/session_01M6dCKAF5Y1VyHGZPjzwDXq --- tools/marmot-interop/headless/setup.sh | 7 +++++-- tools/marmot-interop/lib.sh | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/marmot-interop/headless/setup.sh b/tools/marmot-interop/headless/setup.sh index 5999b50c4..635e10de1 100644 --- a/tools/marmot-interop/headless/setup.sh +++ b/tools/marmot-interop/headless/setup.sh @@ -231,9 +231,12 @@ ensure_identity() { raw=$("$cmd" --json whoami 2>/dev/null || true) npub=$(extract_pubkey "$raw") if [[ -z "${npub:-}" ]]; then - raw=$("$cmd" create-identity 2>&1 | tee -a "$LOG_FILE") + # create-identity sometimes exits non-zero (e.g. transient "failed to + # connect to any relays") even though the account was created. Probe + # --json whoami afterwards before giving up. + "$cmd" create-identity 2>&1 | tee -a "$LOG_FILE" || true + raw=$("$cmd" --json whoami 2>/dev/null || true) npub=$(extract_pubkey "$raw") - [[ -n "$npub" ]] || npub=$(extract_pubkey "$("$cmd" whoami 2>/dev/null || true)") fi [[ -n "$npub" ]] || { fail_msg "could not determine $who npub"; exit 1; } diff --git a/tools/marmot-interop/lib.sh b/tools/marmot-interop/lib.sh index 4194d3e24..744e9ff95 100644 --- a/tools/marmot-interop/lib.sh +++ b/tools/marmot-interop/lib.sh @@ -271,6 +271,9 @@ extract_pubkey() { # JSON: single object v=$(printf '%s' "$raw" | jq -r '.pubkey // .npub // .public_key // empty' 2>/dev/null || true) if [[ -n "$v" && "$v" != "null" ]]; then printf '%s' "$v"; return; fi + # JSON: {"result": [ {"pubkey": …}, … ]} — post-v0.2 `wn --json whoami` shape + v=$(printf '%s' "$raw" | jq -r '.result[0].pubkey // .result[0].npub // .result[0].public_key // empty' 2>/dev/null || true) + if [[ -n "$v" && "$v" != "null" ]]; then printf '%s' "$v"; return; fi # JSON: array of accounts (whoami may return a list) v=$(printf '%s' "$raw" | jq -r '.[0].pubkey // .[0].npub // .[0].public_key // empty' 2>/dev/null || true) if [[ -n "$v" && "$v" != "null" ]]; then printf '%s' "$v"; return; fi