7.0 KiB
7.0 KiB
Chat Message Parts: Rendering Architecture
This folder contains renderers for chat message parts (text, tools, reasoning, placeholders) and shared tool presentation helpers.
Use this doc when you ask an agent to change tool/header/description behavior.
High-level flow
- Message parts are rendered from
MessageBody.tsx. - There are two tool rendering paths:
- Static grouped tools ->
StaticToolRowinProgressiveGroup.tsx - Expandable tools ->
ToolPart.tsx
- Static grouped tools ->
- Shared tool icon mapping is centralized in
toolPresentation.tsx(getToolIcon).
Which file controls what
-
ProgressiveGroup.tsx- Renders grouped Activity rows and grouped static tools.
- Contains
StaticToolRow. - Contains static tool short description logic (
getToolShortDescription). - If you want to change how
read/grep/perplexity/webfetch/...look in compact/grouped mode, edit here.
-
ToolPart.tsx- Renders expandable tool rows (bash/edit/write/question/task + fallback).
- Controls expandable header title/description/diff stats/timer and expanded output body.
- If you want to change expandable tool layout, edit here.
-
taskToolModel.ts- Owns Task metadata parsing and child-session summary projection.
part.state.metadata.sessionIdis the only live identity contract between a Task and its child session.- A running Task may briefly have no
sessionId; render it as waiting until the authoritative part update arrives. Never match parallel children by order, title, timestamp, or status. - Part-level metadata and output parsing exist only for older persisted records and never override state metadata.
-
toolPresentation.tsx- Shared icon mapping for tool names (
getToolIcon). - Used by both
ProgressiveGroup.tsxandToolPart.tsx.
- Shared icon mapping for tool names (
-
toolRenderUtils.ts- Core classification helpers:
isExpandableToolisStaticToolisStandaloneToolgetStaticGroupToolName
- If a tool should switch between static vs expandable, change it here.
- Core classification helpers:
-
ReasoningPart.tsx- Thinking block UI (
ReasoningTimelineBlock), summary + optional duration.
- Thinking block UI (
-
JustificationBlock.tsx- Justification block wrapper over
ReasoningTimelineBlock.
- Justification block wrapper over
Current important behavior
- Assistant markdown treats raw HTML as inert visible text. The final generated HTML is sanitized as defense in depth, with script and style elements forbidden, so message content cannot inject active DOM or application-wide CSS into any runtime surface.
- Final assistant Markdown collects HTTP(S), embedded, and workspace-local PNG/JPEG/GIF/WebP image candidates into one 100px thumbnail gallery in the message-completion area after all message text and above the turn's changed files. Each muted filename caption includes the shared image-file icon. HTTP(S) images keep their browser URL. Embedded and workspace-local images are limited to 10 MiB, validated as PNG/JPEG/GIF/WebP, and local paths are fetched through the active runtime before conversion to data URLs. Local Markdown links whose target has one of those image suffixes stay links in the text and open the same existing full-screen image preview as the gallery; image syntax does not insert a large inline image. A completed assistant message hydrates at most 12 unique image candidates, including persisted text parts that omit their optional part-level end time. Gallery clicks do not introduce or alter preview chrome: desktop and mobile both reuse the pre-existing attachment image preview overlay.
readandskillare static navigation tools and render viaStaticToolRow.- Every other tool, including search/fetch, OpenCode built-ins, custom tools, plugins, and MCP tools, is expandable and renders through
ToolPart. - The managed
openchamberplugin tool uses the expandable path and hides its broad protocol input. The plugin supplies the selected action's human description as the native tool title; the UI renders that metadata without owning an action map. The full versioned result envelope renders through the same neutral JSON summary/tree/raw views as other tools, without a tool-specific output card. ToolPartdefers expanded content after a user toggle, preventing large tool input/output payloads from mounting during the initial chat render.- The rich tool diff preview lives in
ToolPartDiffPreview.tsxand is lazy-loaded fromToolPart. It is the only tool-card piece that imports the@pierre/diffs+ Shiki rendering stack, keeping that stack out of the eager chat startup graph. While its chunk loads (first rendered diff only) the plain-text patch fromPlainDiffFallback.tsxrenders as the Suspense fallback, mirroring the preview's error fallback.ToolPartitself must not statically import@pierre/diffsruntime modules or@/lib/shiki/appThemeRegistry. - Running bash output falls back to
state.metadata.outputuntil canonicalstate.outputarrives. Its fixed-height output viewport follows new output until the user scrolls up, then resumes following when the user returns to the bottom. Live output appends or replaces rewritten snapshots as plain text without worker highlighting; finalized output normalizes ANSI terminal controls with a bounded synthetic-cell budget, bypasses the throttle, and receives the normal one-time highlighted rendering. - Thinking/Justification duration is hidden in
sortedmode (handled inReasoningPart.tsx+JustificationBlock.tsx).
"I want to change description for Perplexity" (example recipe)
If task is: "change text shown near Read or Skill in compact mode":
- Edit
ProgressiveGroup.tsx->getToolShortDescription(activity). - Update the branch that handles
readorskillinStaticToolRow. - Keep all other tool header/output behavior in
ToolPart.tsx. - Keep icon changes (if any) in
toolPresentation.tsx.
Why: only navigation tools use the compact static path; all other tools need observable input and output.
"I want tool to become expandable" (example)
- Update
toolRenderUtils.ts:- add/remove a tool name from
STATIC_TOOL_NAMESonly when it has a reliable direct in-app navigation action
- add/remove a tool name from
- Ensure
ToolPart.tsxsupports desired header + expanded output format for that tool. - Validate both modes (
sortedandlive).
Safe editing checklist
- Do not duplicate icon logic; keep it in
toolPresentation.tsx. - For static tool copy changes, prefer
ProgressiveGroup.tsxfirst. - For expanded output changes, edit
ToolPart.tsx. - After edits run:
bun run type-checkbun run lintbun run build
Quick map of files in this folder
- Text:
AssistantTextPart.tsx,UserTextPart.tsx - Tools:
ToolPart.tsx,ToolPartDiffPreview.tsx,PlainDiffFallback.tsx,ProgressiveGroup.tsx,toolPresentation.tsx,toolRenderUtils.ts,ToolRevealOnMount.tsx - Reasoning/justification:
ReasoningPart.tsx,JustificationBlock.tsx - Status/placeholders:
WorkingPlaceholder.tsx,SessionActiveSpinner.tsx,MigratingPart.tsx,BusyDots.tsx - Utility renderers:
VirtualizedCodeBlock.tsx,MinDurationShineText.tsx