Skip to content

feat: enhance tool call functionality with collapsible details and co… - #70

Open
chaojixinren wants to merge 1 commit into
formulahendry:mainfrom
chaojixinren:fix/render-tool-call-content-69
Open

chaojixinren wants to merge 1 commit into
formulahendry:mainfrom
chaojixinren:fix/render-tool-call-content-69

Conversation

@chaojixinren

Copy link
Copy Markdown

Fixes #69

Summary

session/update notifications already carry ToolCall.content / ToolCallUpdate.content, but the chat render path only read toolCallId, title and status, so tool-call details were never visible. This makes each tool call expandable and renders its text blocks.

  • Every tool call is now a <details>; its <summary> keeps the previous one-line look (status icon + title), so the collapsed state is unchanged and the per-turn "N tool calls" collapse still works.
  • Text blocks ({ type: 'content', content: { type: 'text', text } }) are rendered in the body. Agent-supplied text is set with textContent, so there is no HTML injection path.
  • tool_call_update replaces the body with the newest content snapshot; updates without content keep the previous body. status / title handling is unchanged.
  • A call that transitions to failed auto-expands once; it stays user-collapsible afterwards.
  • The last content snapshot is persisted in chatHistory and rebuilt by restoreState() / addToolCallDOM(), so details survive a panel reload or session switch.
  • Unknown / missing block types (diff, resource links, images), missing fields and empty arrays never throw. Bodies are capped at 20,000 characters with an "... (output truncated)" note.
  • The optional fix is included: ACP sends in_progress, which is now normalised to the existing running icon / colour class.

Files changed

  • src/ui/ChatWebviewProvider.ts — render / collapse / restore logic and CSS
  • CHANGELOG.md — Unreleased "Fixed" entry
  • scripts/mock-acp-agent.mjs — mock ACP agent used to verify without a real agent (optional; drop if not wanted)

Verification

  • npm run lint, npm run compile, npm test all pass (3 passing).
  • The webview script was syntax-checked, and the content extract/render logic was covered by a DOM-shim harness: ACP text blocks, unknown blocks, empty/null content, over-limit truncation, and body replacement.
  • The mock ACP agent was driven over stdio: it emits a tool_call with content, five tool_call_update notifications ~500 ms apart, a completed summary, a failed call, and stopReason: end_turn.

Manual F5 verification in the Extension Development Host was not run in this environment.

…ntent extraction

- Introduced collapsible inline tool calls with a summary and body structure for better organization.
- Updated the `addToolCall` and `addToolCallDOM` functions to handle content blocks.
- Added utility functions for extracting and displaying tool call content.
- Improved CSS styles for better visual representation of tool calls.
@thabs1234

Copy link
Copy Markdown

Noticed one gap while working the same issue — flagging it here rather than
opening a competing PR, since this one is further along.

Your renderBody handles block.content.type === 'text' and everything else
falls to the empty branch. ToolCallContent has four variants per the spec,
and diff / terminal / locations payloads will render as an empty
collapsible with no explanation of what the tool actually returned — the
indistinguishable-from-broken case.

Minimal shape if you want it, same escaping approach you already use:

const inner = block.content || {};
if (inner.type === 'text') {
  blockEl.textContent = inner.text || '';
} else if (inner.type === 'diff') {
  const lines = (inner.oldText || '').split('\n');
  blockEl.textContent =
    (inner.path ? inner.path + '\n' : '') +
    '-'.repeat(40) + '\n' + lines.join('\n-') + '\n' + '+'.repeat(40) +
    '\n' + (inner.newText || '').split('\n').join('\n+');
} else if (inner.type === 'terminal') {
  blockEl.textContent = inner.terminalId ? '[terminal ' + inner.terminalId + ']' : '[terminal]';
} else if (inner.type === 'locations') {
  blockEl.textContent = '[locations]'; // no path until click-through lands
} else {
  blockEl.textContent = '[' + (inner.type || 'unknown') + ']';
}

textContent throughout, so escaping is unchanged. Note inner.text || '' is
not quite enough on its own — a text block with '' is falsy and should
render empty, not fall through to the label branch; that was a real bug in my
first pass, since an empty result is legitimate.

I also dropped the truncation rather than keeping it. 2 tests failed. See the output above for details. is fine to truncate, but agents routinely dump logs
that the user then needs to read, and silent truncation reads as the tool
only produced that much. Happy to be wrong about this — the collapsed
<details> is a reasonable place to enforce a ceiling.

Two smaller notes: your tcAutoExpanded guard means a failed call expands
once per render, so a reload re-expands it — fine if intended, worth knowing.
And chatHistory persistence looks right; I needed the same fix and it's
easy to miss, since the restore path silently drops content otherwise.

Not asking for anything and not tracking a competing branch — happy to just
close mine if you'd rather keep this one minimal.

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)

2 participants