Skip to content

openclaw client compatibility: run 'openclaw tui' against the jsclaw gateway #45

Open

Description

@melvincarvalho

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

  1. Auth handshake — openclaw sends the password in a connect frame 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.
  2. Method surface — the TUI client speaks (extracted from the openclaw dist):
    • chat.send ✅ have (params likely differ — openclaw addresses sessionKey, we take agentId; map session→agent or accept both)
    • chat.history — we have sessions on disk (and --history-limit suggests 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 stubbed
    • models.list — we know the configured model(s); minimal viable: return [config.model]
    • commands.list — slash commands; an empty list may satisfy the TUI
  3. Handshake/identity events — verify what the TUI expects after connect (our hello event vs openclaw's ack shape) by capturing a session against a real openclaw gateway and diffing.
  4. Usage display — the TUI status line shows tokens ?; we now emit usage per 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 chat REPL can still happen later for the no-openclaw case

Refs: #44 (channels), #42 (sandbox posture — same alignment arc).

Activity

  1. melvincarvalho commented on Jun 11, 2026

    @melvincarvalho
    ContributorAuthor

    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)

    • Handshake: client opens the WS with no token in the URL → server must send {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 responds ok with helloOk: {protocol, auth:{role,scopes}, policy:{tickIntervalMs}}.
    • Liveness: client kills the link if no event arrives within policy.tickIntervalMs (default 30s) — the server must emit tick events.
    • Chat events: TUI consumes chat events: {sessionKey, runId, state: delta|final|aborted|error, message:{role, content:[{type:"text",text}]}, stopReason?, errorKind?}. Final-only (no deltas) is accepted.
    • chat.history response: {items, messages, hasMore, nextCursor?}; messages are Anthropic-style {role, content} — agent-micro session files match directly.
    • TUI method surface: chat.send|history|abort, agents.list, sessions.list|reset|patch, models.list, commands.list. chat.send params include optional agentId alongside sessionKey.

    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 + connect handshake, tick events, chat.send sessionKey mapping + openclaw chat events alongside agent.output, chat.history from agent-micro sessions, usable-shape stubs for the list methods and chat.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 reaches connect, but is rejected with bad credentials. Captured (redacted) auth shape from a real attempt:

    authKeys: ["token:string(48)", "password:string(9)"]
    

    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)

    • Whether the TUI is satisfied by our helloOk/stubs once connected (next failure, if any, will name itself)
    • chat.abort is a no-op; sessions.* are stubs; no seq numbers on events; no delta streaming
    • Device-identity auth path untouched (TUI on localhost doesn't need it)

    Next session: apply the one-line credential fix on the branch, run the real TUI, iterate from whatever it says.

  2. melvincarvalho commented on Jun 11, 2026

    @melvincarvalho
    ContributorAuthor

    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 tui now 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions