diff --git a/scripts/claude-statusline-command.sh b/scripts/claude-statusline-command.sh index 671dc06..69b26ea 100755 --- a/scripts/claude-statusline-command.sh +++ b/scripts/claude-statusline-command.sh @@ -141,9 +141,25 @@ if command -v postbox >/dev/null 2>&1; then # "no mail" -- the exact conflation v3 exists to prevent. export ALTHING_POST_OFFICE="${ALTHING_POST_OFFICE:-http://10.100.50.40:8390}" h="${ALTHING_HANDLE:-}" - # ALTHING_HANDLE isn't set in the statusline env — resolve the per-project handle - # from althing's session map, keyed by the cwd Claude Code passes on stdin. - [ -z "$h" ] && [ -n "$cwd" ] && h=$(jq -r --arg d "$cwd" '.[$d] // empty' "$HOME/.althing/session_handles.json" 2>/dev/null) + # ALTHING_HANDLE isn't set in the statusline env, so resolve the handle from the + # cwd Claude Code passes on stdin. + # + # ⚠ PREFER launch-history.json. session_handles.json is a **v2 artifact** — v3's + # postbox never opens it (`grep -rn session_handles althing/` is empty; resolve_config + # takes --handle then ALTHING_HANDLE and nothing else), and the tool that used to + # maintain it, `althing-cli use`, was deleted at the cutover. Whatever is in it now is + # hand-kept and drifts silently. + # + # launch-history.json is written by dev_launch, which is the thing that sets + # ALTHING_HANDLE in the first place, so it is the real cwd->handle binding. Shape is + # {cwd: {command: {at, handle}}} with several commands per directory (claude, kimi, + # grok), so take the most recent by `at` rather than whichever key sorts first. + if [ -z "$h" ] && [ -n "$cwd" ]; then + h=$(jq -r --arg d "$cwd" '(.[$d] // {}) | to_entries | max_by(.value.at) | .value.handle // empty' \ + "$HOME/.althing/launch-history.json" 2>/dev/null) + # Fallback only: broader coverage, but frozen and hand-maintained. + [ -z "$h" ] && h=$(jq -r --arg d "$cwd" '.[$d] // empty' "$HOME/.althing/session_handles.json" 2>/dev/null) + fi if [ -n "$h" ]; then # `timeout` is load-bearing, not belt-and-braces: v2 read a local SQLite file, # v3 makes an HTTP call. An unreachable post office must cost this segment two