Skip to content

fix(tool-calls): render ACP tool call content instead of dropping it - #73

Closed
thabs1234 wants to merge 2 commits into
formulahendry:mainfrom
thabs1234:fix/tool-call-content
Closed

thabs1234 wants to merge 2 commits into
formulahendry:mainfrom
thabs1234:fix/tool-call-content

Conversation

@thabs1234

Copy link
Copy Markdown

Fixes #69

tool_call updates arrive from ACP with the agent's actual output in
content, but the handler only forwarded toolCallId, title and status.
Every tool result was silently dropped, so a chat transcript showed tool
names and statuses but none of what the tool produced.

ACP wraps the payload one level deep — ToolCallContent[] with each entry of
the form { type: 'content', content: ContentBlock }. The obvious fix of
reading ContentBlock[] directly returns nothing, which is worth calling out
because it looks correct.

Changes:

  • renderToolContent() flattens the nested shape and also covers the diff,
    terminal and locations variants, rather than assuming text is the only
    data an agent can send
  • content is threaded through addToolCall / updateToolCall and both the
    tool_call and tool_call_update dispatch paths
  • Per ACP v1, an update carries whole fields rather than deltas, so a supplied
    content replaces the stored text. An update that omits content keeps what
    is already on screen instead of blanking it.
  • content is persisted in chatHistory so reloading a session does not
    discard it again
  • Text is rendered via the existing escapeHtml helper. Tool output is
    agent-controlled and must not reach innerHTML as raw markup.

Verification:

  • src/test/toolcallcontent.check.js covers the nested shape, empty and
    absent content, the diff / terminal / unknown variants, multiple blocks,
    falsy-but-valid text values, and asserts content is escaped before insertion
  • Wired into pretest; npm run pretest passes (typecheck, webpack, eslint)

One judgement call worth review: image and resource blocks render as a
[type] label instead of being displayed. Nothing in the ACP spec or the
issue asks for inline image rendering, so this is deliberately left as a label
rather than pulling in a new dependency.

Thabang Lehau added 2 commits October 3, 2026 08:50
ACP sends tool output as ToolCallContent[], where each entry wraps a
ContentBlock one level deep ({type:'content', content:{type:'text', text}}).
The tool_call handler only passed toolCallId/title/status to addToolCall and
discarded content entirely, so every tool result was invisible in the chat
UI. See issue formulahendry#69.

- add renderToolContent() to flatten the nested shape and cover the diff,
  terminal and locations variants rather than assuming text is the only
  possible data
- thread content through addToolCall/updateToolCall and both the tool_call
  and tool_call_update dispatch paths
- a supplied content replaces the stored text (ACP v1 updates carry whole
  fields, not deltas), while an update that omits content keeps what is
  already on screen
- persist content in chatHistory so a reload does not silently discard it
- render through escapeHtml: agent output is untrusted and must never reach
  innerHTML as raw markup
- add src/test/toolcallcontent.check.js, wired into pretest

ponytail: image/resource blocks render as a [type] label rather than being
displayed. Replace with real rendering when a caller needs it.
@thabs1234

Copy link
Copy Markdown
Author

Update: #70 already targets this issue

Opened this before checking the full open-PR list — turns out
#70 (fix/render-tool-call-content-69, by @chaojixinren, opened 2026-09-17)
already fixes the same dropped-content defect, and has done so since
September. Not closing this unilaterally; adding the comparison so the choice
is easy to make.

Both fixes drop the same root cause: tool_call updates arrive with the
agent's output in content, and the render path only read toolCallId,
title and status.

Where they differ:

#70 this PR
Files 3 (ChatWebviewProvider.ts, CHANGELOG.md, scripts/mock-acp-agent.mjs) 3 (ChatWebviewProvider.ts, package.json, new check)
Size +305/-34 +159/-10
Layout wraps every tool call in <details>, auto-expands on failure inline block under the existing one-line row
Variants text blocks only text, plus diff, terminal, locations
Escaping textContent escapeHtml
Truncation truncates long output no truncation
Tests none added 16 cases, wired into pretest

The substantive gap is the variant coverage and the missing test. #70 covers
text blocks only, so diff / terminal / locations payloads — all valid
ToolCallContent per the spec — still land as an unlabelled empty block.
This PR renders a summary line for each. It also does not truncate, which is
the right default for the case that actually gets reported here: an agent
dumping a log the user then needs to read.

On the <details> restructure: that is a real UX change and arguably the more
pleasant result, so #70 may well be the better call. The reason this PR stays
smaller is that it does not restyle existing behaviour to fix a missing field.
Worth noting that #70 also touches CHANGELOG.md and the mock agent, which
this PR deliberately leaves alone to keep review narrow.

Happy to close this if #70 is preferred — no attachment either way. The
variant-coverage gap and the absent test are the two things worth carrying
into whichever version gets merged.

@thabs1234

Copy link
Copy Markdown
Author

Correction to the above: I wrote Tests: none added for #70, which undersells it. #70 does add scripts/mock-acp-agent.mjs — a mock ACP agent for manually exercising the chat UI. That is test infrastructure, just not an automated assertion.

So the real gap is narrower than I stated: #70 has no automated regression test, whereas this PR adds 16 assertions run from pretest. The variant-coverage difference stands as described.

@thabs1234

Copy link
Copy Markdown
Author

Closing in favour of #70, which is further along (opened 2026-09-17, collapsible layout, mock agent, CHANGELOG).

This adds a variant-coverage gap and 16 automated assertions that #70 lacks, but both PRs edit the same functions in ChatWebviewProvider.ts (addToolCallDOM, addToolCallInline, updateToolCall) and will conflict on merge. Two conflicting PRs for one issue is worse than one good one.

The two findings worth keeping are both posted on #70: the diff/terminal/locations fallthrough that renders as an empty block, and the empty-text falsy bug. If #70 needs a test, the check is at https://github.com/thabs1234/vscode-acp/tree/fix/tool-call-content/src/test/toolcallcontent.check.js and rebase is trivial.

@thabs1234 thabs1234 closed this Oct 3, 2026
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.

Tool call content is not rendered: per-call details cannot be expanded (v0.2.0)

1 participant