#!/bin/bash # bb-show — put a page in front of the human, taking turns with the other agents. # # Use this instead of: open -a "Brave Browser" # That command goes straight to macOS, around the proxy, so the proxy cannot # queue it. Two sessions doing it minutes apart is what throws the window back # and forth. This one queues. # # bb-show [--reload] [owner] [purpose] # # ONE TAB PER JOB (Matt, 2026-10-23). The owner name is your job. The job owns # one tab on one site until you run bb-close . Showing the same site again # gives you that same tab back, AS IS: never reloaded, never a second copy. # # LOOK BEFORE YOU TOUCH. When the page was already open, bb-show prints what it # shows right now (URL, title, text, filled fields) and whether the human is # working in it. Read that before acting: he may already have filled the form, # solved the captcha or hit send. Continue from there; never start over. # Pass --reload only when a fresh copy is truly wanted. To look without showing # anything, use bb-peek. # # When the task is done, close what you showed: bb-close . # # Exit 0 shown · 1 error · 2 screen busy (say so and move on, do NOT force it) # 4 the human is working in that tab: read what it shows, continue, do NOT reopen it # 5 stop: you keep reopening this page. Ask the human in one line what is wrong. set -u API="${BROKER_URL:-http://127.0.0.1:9223}" RELOAD=0 if [ "${1:-}" = "--reload" ]; then RELOAD=1; shift; fi URL="${1:-}"; OWNER="${2:-${BROKER_OWNER:-$(basename "${CLAUDE_SESSION_ID:-agent}")}}"; WHY="${3:-}" [ -z "$URL" ] && { echo "usage: bb-show [--reload] [owner] [purpose]" >&2; exit 1; } BODY=$(URL="$URL" OWNER="$OWNER" WHY="$WHY" RELOAD="$RELOAD" python3 -c ' import json,os b={"url":os.environ["URL"],"owner":os.environ["OWNER"],"purpose":os.environ["WHY"] or None} if os.environ["RELOAD"]=="1": b["reload"]=True print(json.dumps(b))') OUT=$(curl -sS -m 60 -w $'\n%{http_code}' -X POST "$API/show" \ -H "Content-Type: application/json" -d "$BODY" 2>/dev/null) CODE=$(printf '%s' "$OUT" | tail -1) JSON=$(printf '%s' "$OUT" | sed '$d') # Prints a page state the broker handed back: where it is, what it says, what is filled in. page(){ JSON="$1" python3 -c ' import json,os,sys try: d=json.loads(os.environ["JSON"]) except Exception: sys.exit(0) p=d.get("page") or {} if not p: sys.exit(0) print(" now at: %s" % (p.get("url") or "?")) print(" title: %s" % (p.get("title") or "")) print(" shows: %s" % (p.get("text") or "(no text read)")) for f in (p.get("fields") or [])[:12]: print(" filled: %s = %s" % (f.get("field"), f.get("value"))) h=p.get("human") or {} if h.get("active"): print(" HUMAN IS WORKING IN IT: last input %ss ago" % h.get("last_input_seconds_ago")) elif h.get("inputs"): print(" the human worked in it (last input %ss ago)" % h.get("last_input_seconds_ago")) ' 2>/dev/null || true; } case "$CODE" in 200) echo "shown: $URL" how=$(JSON="$JSON" python3 -c ' import json,os try: d=json.loads(os.environ["JSON"]) except Exception: d={} print("reloaded" if d.get("reloaded") else "moved" if d.get("moved") else "open" if d.get("already_open") else "new")' 2>/dev/null) case "$how" in reloaded) echo "already open: reloaded in place because --reload was passed" ;; moved) echo "same job tab, moved to this page (no second copy opened)" ;; open) echo "already open: brought forward AS IS, NOT reloaded (no duplicate opened)" page "$JSON" echo "LOOK at that before acting: the human may already have filled, submitted or finished this page." ;; esac echo "when the task is done, close it: bb-close $OWNER (rule: close every tab you opened)" exit 0 ;; 409) echo "screen busy — $JSON" >&2 echo "not forcing it. tell the human the link instead: $URL" >&2; exit 2 ;; 423) echo "the human is working in that tab right now. Not reloaded, not reopened." >&2 page "$JSON" >&2 echo "read what it shows and continue from there. Do not start over." >&2; exit 4 ;; 429) JSON="$JSON" python3 -c 'import json,os; print(json.loads(os.environ["JSON"]).get("error",""))' >&2 2>/dev/null \ || echo "stop: you keep reopening this page" >&2 exit 5 ;; 4??) echo "broker refused (code=$CODE): $JSON" >&2; exit 1 ;; *) # Broker down. Nothing should break just because the polite path is gone. echo "broker not answering (code=${CODE:-none}) — falling back to a raw open" >&2 open -a "${BROWSER_APP:-Brave Browser}" "$URL" && exit 0 || exit 1 ;; esac