Skip to content

feat: forward tool results to consumers (phase:"result") — v0.14.0 - #42

Merged
clemenshelm merged 1 commit into
mainfrom
feat/forward-tool-results
Jul 22, 2026
Merged

feat: forward tool results to consumers (phase:"result") — v0.14.0#42
clemenshelm merged 1 commit into
mainfrom
feat/forward-tool-results

Conversation

@clemenshelm

Copy link
Copy Markdown
Contributor

Problem

The streaming chat() generator only recognized the older tool-result event shape (stream:"tool", phase:"end", data.output). The current OpenClaw Gateway does not send that — it emits phase:"result" with the tool in name and the payload in result (a toTranscriptToolResult object). So no tool_result chunk was ever produced, and all tool output was invisible to consumers.

This surfaced building Pinchy's agent → user file delivery (heypinchy/pinchy#703): a plugin writes a delivery marker into its tool output, but the marker never reached the web layer because the tool_result chunk didn't exist.

Change

  • Handle both phase:"end" (legacy output) and phase:"result" (current result).
  • Read the tool name from name, falling back to the legacy tool field.
  • Set the chunk text to the tool's actual text output — the content[].text items of toTranscriptToolResult joined with newlines — via a new exported toolResultText() helper, rather than a JSON.stringify envelope. This preserves literal quotes so a structured marker (e.g. <pinchy:file name="…" />) survives to the consumer intact instead of being escaped (name=\"…\").

Tests

TDD: a chat.test.ts integration test simulating the current Gateway's phase:"result" tool event and asserting the tool_result chunk carries the tool name + marker with literal quotes, plus focused toolResultText unit tests (string / content-array / non-text items / fallback). Full suite green, typecheck/lint/format/build clean.

Release

Minor bump 0.13.1 → 0.14.0 (new exported helper + new observable streaming behavior; analogous to the agents.list minor in 0.12.0). CHANGELOG updated.

The streaming chat() generator only recognized the older tool-result event
shape (stream:"tool", phase:"end", data.output), which the current OpenClaw
Gateway does not send — it emits phase:"result" with the tool in `name` and
the payload in `result` (a toTranscriptToolResult object). The result: no
tool_result chunk was ever produced, and all tool output was invisible to
consumers.

Handle both shapes, read the tool name from `name` (fallback `tool`), and set
the chunk text to the tool's actual text output (content[].text joined) rather
than a JSON-escaped envelope — so a structured marker a plugin writes into its
output survives with literal quotes. Adds an exported toolResultText() helper.

Unblocks Pinchy's agent→user file delivery (heypinchy/pinchy#703), which needs
to observe a delivery marker in a plugin's tool output.
@clemenshelm
clemenshelm merged commit b6d09a8 into main Jul 22, 2026
4 checks passed
@clemenshelm
clemenshelm deleted the feat/forward-tool-results branch July 22, 2026 06:25
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.

1 participant