Files
PaperClipAI/packages/adapters/openclaw-gateway
Wojtek TurowiczandClaude Opus 5.5 12d0bfa232 fix(openclaw-gateway): show thinking and tool steps in the run transcript (#17136)
# fix(openclaw-gateway): show thinking and tool steps in the run
transcript

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The OpenClaw gateway adapter runs agents on a remote OpenClaw
gateway and streams the agent events into the run log
> - The run transcript in the UI shows thinking and tool calls for the
built-in adapters, for example `claude_local` and `codex_local`
> - For `openclaw_gateway`, the UI parser shows only `assistant` text
and errors. It drops `thinking` events and tool `item` events, but the
run log has them
> - So a board operator cannot see what an OpenClaw agent thinks or
which tools it calls while the run is live. A slow or stuck run looks
like "Working" with no detail
> - This pull request maps these two event streams to the transcript
entries that the UI already renders
> - The benefit is the same transcript detail for OpenClaw agents as for
the built-in adapters, with no server change

## Linked Issues or Issue Description

Refs #1639 (OpenClaw gateway transcript output). Related open PRs change
the `assistant` branch of the same parser: #13665, #14150, #14217,
#4793. This PR does not change that branch. It adds two new branches.

**What existing behavior does this improve?**
The run transcript of an `openclaw_gateway` agent.

**Subsystem affected**
Adapters: `packages/adapters/openclaw-gateway/src/ui/parse-stdout.ts`.

**Current behavior**
`parseAgentEventLine` returns transcript entries only for the
`assistant`, `error` and `lifecycle` streams. For `stream=thinking` and
`stream=item` it returns an empty list, so the UI shows nothing for
them.

**Proposed behavior**
`stream=thinking` becomes a `thinking` entry (the `delta` text with
`delta: true`, or the full `text`). A tool `item` with `phase: "start"`
becomes a `tool_call` entry. A tool `item` with `phase: "end"` becomes a
`tool_result` entry. A result with a status other than `completed` is an
error.

**Reason and benefit**
Operators can see what an OpenClaw agent does during a run, as they can
for the built-in adapters.

**Breaking changes**
None. Only the UI parser changes. The stored run log does not change.

## What Changed

- `parseAgentEventLine` maps `stream=thinking` to `thinking` entries. It
keeps streamed deltas, which `appendTranscriptEntry` already joins.
- `parseAgentEventLine` maps tool `item` events (`kind: "tool"`) to
`tool_call` (start) and `tool_result` (end) entries. The OpenClaw event
has the tool name and a title, but not the tool input or output. The
entry uses the title as the input and as the result content, and the
errortext for a failed tool.
- New `parse-stdout.test.ts` with cases for thinking, tool start, tool
end (completed and failed), and the streams that stay ignored.

## Verification

- `vitest run` on
`packages/adapters/openclaw-gateway/src/ui/parse-stdout.test.ts`: 6
tests pass.
- Manual: the same mapping on a 2026.1012.0 instance with OpenClaw
2026.9.33 agents. The run transcript shows the thinking and each tool
stepduring the run.
- Not run: the full repository type check.

## Risks

Low risk. The change adds two branches to a UI parser. The events that
were shown before have the same result. A thinking stream can be long,so
the transcript of an OpenClaw run gets longer, as it is for the built-in
adapters.

## Model Used

Claude Opus 5.5 (`claude-opus-5-5`), with tool use and code execution,
in Claude Code.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` /
`github.com/paperclipai/paperclip`URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 16:42:39 +00:00
..

OpenClaw Gateway Adapter

This document describes how @paperclipai/adapter-openclaw-gateway invokes OpenClaw over the Gateway protocol.

Transport

This adapter always uses WebSocket gateway transport.

  • URL must be ws:// or wss://
  • Connect flow follows gateway protocol:
  1. receive connect.challenge
  2. send req connect (protocol/client/auth/device payload)
  3. send req agent
  4. wait for completion via req agent.wait
  5. stream event agent frames into Paperclip logs/transcript parsing

Auth Modes

Gateway credentials can be provided in any of these ways:

  • authToken / token in adapter config
  • headers.x-openclaw-token
  • headers.x-openclaw-auth (legacy)
  • password (shared password mode)

When a token is present and authorization header is missing, the adapter derives Authorization: Bearer <token>.

Device Auth

By default the adapter sends a signed device payload in connect params.

  • set disableDeviceAuth=true to omit device signing
  • set devicePrivateKeyPem to pin a stable signing key
  • without devicePrivateKeyPem, the adapter generates an ephemeral Ed25519 keypair per run
  • when autoPairOnFirstConnect is enabled (default), the adapter handles one initial pairing required by calling device.pair.list + device.pair.approve over shared auth, then retries once.

Session Strategy

The adapter supports the same session routing model as HTTP OpenClaw mode:

  • sessionKeyStrategy=issue|fixed|run
  • sessionKey is used when strategy is fixed

Resolved session key is sent as agent.sessionKey.

Payload Mapping

The agent request is built as:

  • required fields:
    • message (wake text plus optional payloadTemplate.message/payloadTemplate.text prefix)
    • idempotencyKey (Paperclip runId)
    • sessionKey (resolved strategy)
  • optional additions:
    • all payloadTemplate fields merged in
    • agentId from config if set and not already in template

Timeouts

  • timeoutSec controls adapter-level request budget
  • waitTimeoutMs controls agent.wait.timeoutMs

If agent.wait returns timeout, adapter returns openclaw_gateway_wait_timeout.

Log Format

Structured gateway event logs use:

  • [openclaw-gateway] ... for lifecycle/system logs
  • [openclaw-gateway:event] run=<id> stream=<stream> data=<json> for event agent frames

UI/CLI parsers consume these lines to render transcript updates.

No-remote-git contract

Like every Paperclip adapter, this one must treat the local execution-workspace cwd as the only persistence boundary across runs — no git push from runtime code, no assuming a git remote exists. The gateway transport here doesn't touch the workspace directly, but if you extend the adapter to ship code to the OpenClaw side, use the round-trip helpers in @paperclipai/adapter-utils (prepareWorkspaceForSshExecution → restoreWorkspaceFromSshExecution) rather than reaching for a git remote. See packages/adapters/AUTHORING.md for the full contract and the pinning test at packages/adapter-utils/src/ssh-fixture.test.ts.