Repository navigation
Description
Experiment (2026-06-11): OPENCLAW_GATEWAY_URL=ws://127.0.0.1:18790 openclaw tui --password <token> against a live jsclaw gateway. The TUI (built on pi-tui) launches, targets our gateway, shows agent main - session main — and loops on reconnect: jsclaw logs Gateway upgrade rejected: bad token on openclaw's backoff curve.
Getting this to work means jsclaw inherits openclaw's entire client ecosystem — the Claude-style TUI first — without building UI. We already speak the frame shape (req/res/event) and chat.send; the gaps are concrete:
Work list
- Auth handshake — openclaw sends the password in a
connectframe after the socket opens (connection.password); jsclaw requires?token=in the upgrade URL and closes before the first frame. Accept both: let an unauthenticated socket open and await a connect/auth frame (with a short timeout), keep the query token path for the webchat. - Method surface — the TUI client speaks (extracted from the openclaw dist):
chat.send✅ have (params likely differ — openclaw addressessessionKey, we takeagentId; map session→agent or accept both)chat.history— we have sessions on disk (and--history-limitsuggests it's called at startup)chat.abort— kill/interrupt the running agent turn (we have killContainer; needs a method)agents.list— trivial (getAgents)sessions.list/sessions.reset/sessions.patch— list/reset map naturally; patch may be stubbedmodels.list— we know the configured model(s); minimal viable: return[config.model]commands.list— slash commands; an empty list may satisfy the TUI
- Handshake/identity events — verify what the TUI expects after connect (our
helloevent vs openclaw's ack shape) by capturing a session against a real openclaw gateway and diffing. - Usage display — the TUI status line shows
tokens ?; we now emitusageper turn (webchat: show token usage per reply and session total #39), map it to whatever field the TUI reads.
Approach
Capture-first: run openclaw tui against a real openclaw gateway with a logging proxy, record the frame exchange, implement against the recording, then test the TUI against jsclaw for real. Each method lands as its own small change; partial compatibility degrades gracefully (TUI features that miss methods just stay empty).
Why this over building a TUI
- pi-tui rendering, history, key handling — all maintained elsewhere
- Compatibility is verifiable ("does openclaw tui work?") rather than aesthetic
- Same shim likely unlocks other openclaw clients/tools
- A zero-dep
jsclaw chatREPL can still happen later for the no-openclaw case
Refs: #44 (channels), #42 (sandbox posture — same alignment arc).
Activity
melvincarvalho commentedon Jun 11, 2026
Findings — first session (2026-06-11), parked
Work lives on branch
issue-45-openclaw-handshake(pushed, deliberately unmerged — the changed auth surface deserves review, and the flagship consumer doesn't work yet).Protocol capture (from the openclaw 2026.6.1 dist — authoritative, server + client both read)
{type:"event", event:"connect.challenge", payload:{nonce}}→ client sends{type:"req", method:"connect", params:{minProtocol:4, maxProtocol:4, client:{id,displayName,version,platform,mode,instanceId}, caps:[], auth:{token?, password?, deviceToken?, …}, role:"operator", scopes, device?}}→ server respondsokwith helloOk:{protocol, auth:{role,scopes}, policy:{tickIntervalMs}}.policy.tickIntervalMs(default 30s) — the server must emittickevents.chatevents:{sessionKey, runId, state: delta|final|aborted|error, message:{role, content:[{type:"text",text}]}, stopReason?, errorKind?}. Final-only (no deltas) is accepted.chat.historyresponse:{items, messages, hasMore, nextCursor?}; messages are Anthropic-style{role, content}— agent-micro session files match directly.chat.send|history|abort,agents.list,sessions.list|reset|patch,models.list,commands.list.chat.sendparams include optionalagentIdalongsidesessionKey.Implemented on the branch (129/129 tests, 5 new)
Pre-auth upgrade for tokenless sockets (10s window;
?token=path unchanged, wrong query tokens still rejected),connect.challenge+connecthandshake,tickevents,chat.sendsessionKey mapping + openclawchatevents alongsideagent.output,chat.historyfrom agent-micro sessions, usable-shape stubs for the list methods andchat.abort.Verified: a simulated client running the exact sequence end-to-end through a live agent (GLM round-trip) works.
Where the real TUI still fails — root cause identified
openclaw tui --password <token>now passes the upgrade and reachesconnect, but is rejected with bad credentials. Captured (redacted) auth shape from a real attempt:The client sends a 48-char stored/derived token and the correct password. The branch checks
auth.token ?? auth.password— the stale token shadows the right password. The fix is one line: try every provided credential (token,password,deviceToken…) against the gateway token instead of short-circuiting on the first present field.Remaining after that (unverified)
chat.abortis a no-op;sessions.*are stubs; noseqnumbers on events; no delta streamingNext session: apply the one-line credential fix on the branch, run the real TUI, iterate from whatever it says.
fix: accept any matching credential in connect frame (#45)
melvincarvalho commentedon Jun 11, 2026
Milestone 1 done — merged in #48. The credential fix (accept any matching field; openclaw clients send a stale stored token alongside the typed password) was the last blocker:
openclaw tuinow reaches gateway connected against a jsclaw gateway, verified live. Remaining items (abort, sessions semantics, seq/deltas, device auth, full-TUI feature pass) stay open here for a future session.