From 12d0bfa232c1c2956499d2af2409fca6599f1c77 Mon Sep 17 00:00:00 2001 From: Wojtek Turowicz Date: Mon, 30 Nov 2026 16:42:39 +0000 Subject: [PATCH] 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 --- .../src/ui/parse-stdout.test.ts | 67 +++++++++++++++++++ .../openclaw-gateway/src/ui/parse-stdout.ts | 35 ++++++++++ 2 files changed, 102 insertions(+) create mode 100644 packages/adapters/openclaw-gateway/src/ui/parse-stdout.test.ts diff --git a/packages/adapters/openclaw-gateway/src/ui/parse-stdout.test.ts b/packages/adapters/openclaw-gateway/src/ui/parse-stdout.test.ts new file mode 100644 index 00000000000..cbea411c3b9 --- /dev/null +++ b/packages/adapters/openclaw-gateway/src/ui/parse-stdout.test.ts @@ -0,0 +1,67 @@ +import { describe, expect, it } from "vitest"; +import { parseOpenClawGatewayStdoutLine } from "./parse-stdout.js"; + +const ts = "2026-10-21T18:44:08.160Z"; + +function event(stream: string, data: Record) { + return `[openclaw-gateway:event] run=run-1 stream=${stream} data=${JSON.stringify(data)}`; +} + +describe("parseOpenClawGatewayStdoutLine", () => { + it("keeps assistant deltas", () => { + expect(parseOpenClawGatewayStdoutLine(event("assistant", { text: "Hel", delta: "lo" }), ts)).toEqual([ + { kind: "assistant", ts, text: "lo", delta: true }, + ]); + }); + + it("maps thinking deltas to thinking entries", () => { + expect(parseOpenClawGatewayStdoutLine(event("thinking", { text: "Check the", delta: " versions" }), ts)).toEqual([ + { kind: "thinking", ts, text: " versions", delta: true }, + ]); + }); + + it("maps a full thinking text when there is no delta", () => { + expect(parseOpenClawGatewayStdoutLine(event("thinking", { text: "Plan first." }), ts)).toEqual([ + { kind: "thinking", ts, text: "Plan first." }, + ]); + }); + + it("maps a tool item start to a tool call", () => { + const line = event("item", { + itemId: "tool:call-1", + toolCallId: "call-1", + name: "read", + kind: "tool", + phase: "start", + title: "Read from skills/cve-patching/SKILL.md", + status: "running", + }); + expect(parseOpenClawGatewayStdoutLine(line, ts)).toEqual([ + { kind: "tool_call", ts, name: "read", toolUseId: "call-1", input: { title: "Read from skills/cve-patching/SKILL.md" } }, + ]); + }); + + it("maps a tool item end to a tool result, failed ones as errors", () => { + const ok = event("item", { toolCallId: "call-1", name: "read", kind: "tool", phase: "end", title: "Read SKILL.md", status: "completed" }); + const failed = event("item", { + toolCallId: "call-2", + name: "tool_search", + kind: "tool", + phase: "end", + title: "Tool Search", + status: "failed", + error: "set limit on each batch query", + }); + expect(parseOpenClawGatewayStdoutLine(ok, ts)).toEqual([ + { kind: "tool_result", ts, toolUseId: "call-1", toolName: "read", content: "Read SKILL.md", isError: false }, + ]); + expect(parseOpenClawGatewayStdoutLine(failed, ts)).toEqual([ + { kind: "tool_result", ts, toolUseId: "call-2", toolName: "tool_search", content: "set limit on each batch query", isError: true }, + ]); + }); + + it("still ignores other item kinds and streams", () => { + expect(parseOpenClawGatewayStdoutLine(event("item", { kind: "message", phase: "start" }), ts)).toEqual([]); + expect(parseOpenClawGatewayStdoutLine(event("usage", { input: 10 }), ts)).toEqual([]); + }); +}); diff --git a/packages/adapters/openclaw-gateway/src/ui/parse-stdout.ts b/packages/adapters/openclaw-gateway/src/ui/parse-stdout.ts index c8cb48ae4fa..91a1979939e 100644 --- a/packages/adapters/openclaw-gateway/src/ui/parse-stdout.ts +++ b/packages/adapters/openclaw-gateway/src/ui/parse-stdout.ts @@ -38,6 +38,41 @@ function parseAgentEventLine(line: string, ts: string): TranscriptEntry[] { return []; } + if (stream === "thinking") { + const delta = asString(data?.delta); + if (delta.length > 0) { + return [{ kind: "thinking", ts, text: delta, delta: true }]; + } + + const text = asString(data?.text); + if (text.length > 0) { + return [{ kind: "thinking", ts, text }]; + } + return []; + } + + if (stream === "item" && asString(data?.kind) === "tool") { + const toolUseId = asString(data?.toolCallId) || asString(data?.itemId); + const name = asString(data?.name) || "tool"; + const title = asString(data?.title) || asString(data?.meta); + const phase = asString(data?.phase).toLowerCase(); + if (phase === "start") { + return [{ kind: "tool_call", ts, name, toolUseId: toolUseId || undefined, input: title ? { title } : {} }]; + } + if (phase === "end") { + const status = asString(data?.status).toLowerCase(); + return [{ + kind: "tool_result", + ts, + toolUseId: toolUseId || name, + toolName: name, + content: asString(data?.error) || title || status, + isError: status !== "completed", + }]; + } + return []; + } + if (stream === "error") { const message = asString(data?.error) || asString(data?.message); return message ? [{ kind: "stderr", ts, text: message }] : [];