Skip to content

cyberpunkunicorn-os: internet relay, device side - #12

Merged
hellofrequencylab merged 2 commits into
mainfrom
claude/cu-relay
Oct 20, 2026
Merged

hellofrequencylab merged 2 commits into
mainfrom
claude/cu-relay

Conversation

@hellofrequencylab

Copy link
Copy Markdown
Owner

Stacked on #10. Retarget it to main after #10 merges. This is Phase 4b of the plan: the website controls the board from any network.

What changes

  • apps/remote/relay.{h,cpp}: a cu_relay task.
    • It mints a Realtime token from frequency-web's POST /api/v1/devices/realtime-token, using the scanner key from frequency.provision.
    • It opens the token's realtime_url over our own small TLS WebSocket client. No new library deps.
    • It joins realtime:device:<id> as a private channel with presence, sends a heartbeat every 25 s, and re-mints the token about 2 min before expiry with an access_token push.
    • Broadcast rpc lines run through remote::runLine(), the same code as USB. Replies go back as reply and events as evt, both {line}. Presence tracks {online, version}.
  • Safety:
    • It only runs rpc lines, and only commands in the token's allowed_cmds. cli.run and remote.relay are always refused (not_allowed).
    • Only the relay task touches the socket. Events from other tasks are queued, up to 8.
    • It never runs beside Bluetooth, and it waits while free heap is under 60 KB. A Frequency check-in POST asks it to close for 20 s when RAM is short.
  • remote::runLine() is split out of handleLine() and holds one lock around every handler. Lines from USB, BLE and the relay never run two at once.
  • Switch (off by default, NVS remote/relay): Remote app → Internet remote, remote relay on|off, or rpc remote.relay {on}. system.status gains relay:{enabled, state, error?}, and the Remote status screen shows it.
  • PROTOCOL.md §6 is rewritten for what's built, including the server's real token (role anon, bare uuid, ADR-1870). CLAUDE.md is updated too.

Verified

  • Every changed file passes a syntax check against patched Bruce 1.16.1. I confirmed the checker does report errors by planting a deliberate one.
  • Not run against the live site or on the board. Turning it on needs DEVICE_RELAY_ENABLED and SUPABASE_JWT_SECRET (RUNBOOKS "Internet relay"), plus the owner's PATCH /api/v1/me/devices/{id} {"relayEnabled":true}.
  • Board checklist: provision the board, join Wi-Fi, run remote relay on, and remote should show online. Then broadcast rpc {"id":1,"cmd":"system.status"} on device:<id> and expect a reply. cli.run should answer not_allowed.

Generated by Claude Code

The board joins its private Supabase Realtime channel device:<id> with a
15-minute token from frequency-web's realtime-token route (scanner key),
over a small TLS WebSocket + Phoenix client of our own, and runs
broadcast rpc lines through the same code as USB, limited to the
owner's allowed_cmds (never cli.run or remote.relay). Replies go back as
"reply", events as "evt", presence tracks {online, version}.

remote::runLine() now holds one lock around every handler, so lines from
USB, BLE and the relay never run two at once. Off by default (NVS
remote/relay): Remote app "Internet remote", `remote relay on|off`,
rpc remote.relay. Never beside Bluetooth; a check-in POST asks it to
step aside when RAM is short. system.status reports relay state.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AycPrTRVXqSDZhb2NNfyG6
@hellofrequencylab
hellofrequencylab changed the base branch from claude/cu-phase3 to main October 20, 2026 22:12
@hellofrequencylab
hellofrequencylab marked this pull request as ready for review October 20, 2026 22:12
@hellofrequencylab
hellofrequencylab merged commit cdfc257 into main Oct 20, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants