Skip to content

D-16: Specialized tool widgets (Read/Grep/Glob/LS/Edit/Write/Bash/Task/TodoWrite/WebFetch/WebSearch/MCP) #266

@kirich1409

Description

@kirich1409

Description

Implement specialized content views for each built-in Claude Code tool. Each widget is an opinionated rendering for its tool's input and output, slotted into ToolCallCardView (D-15).

Spec: docs/architecture/dialogue-events.md §4 (tool widgets table); Epic #250 §6.

Scope

Files under MacApp/Packages/AgentChatUI/Sources/AgentChatUI/ToolCall/Widgets/:

Core widgets (must-have for MVP)

Widget Tool names Content
ReadWidget.swift Read, NotebookEdit (partial) path preview + line count; expanded — syntax-free monospaced content in BlockCodeContainer; binary → "{N} bytes binary".
GrepWidget.swift Grep pattern + match count summary; expanded — grouped by file with line numbers and highlighted match spans.
GlobWidget.swift Glob pattern + file count; expanded — file list, click → tries to open via system.
LSWidget.swift LS dir + entry count; expanded — table (name / size / mtime / type).
EditWidget.swift Edit, MultiEdit, Write path + ±N lines; expanded — inline unified diff (+ green, − red; monospaced). Syntax highlighting not in MVP.
BashWidget.swift Bash, BashOutput, KillShell $ {command} pill; expanded — mini-terminal with stdout / stderr tabs + exit code + duration; run_in_background=true shows Abort button. ANSI color support via AnsiToAttributedString helper (minimal CSI subset).
TaskWidget.swift Task (sub-agent) subagent_type + description; expanded — nested DialogueView bound to a sub-state slice (for forward compatibility with subagent routing from D-11).
TodoWidget.swift TodoWrite "{done}/{total} · active: {activeForm}"; expanded — checklist with status pills (pending / in_progress / done) per item.
WebFetchWidget.swift WebFetch URL pill; expanded — best-effort OG-preview (title / description / hero image via AsyncImage) + fetched content text.
WebSearchWidget.swift WebSearch query + result count; expanded — list of title / url / snippet cards.
SlashCommandWidget.swift SlashCommand, Skill command name; expanded — plain text output.
GenericMCPWidget.swift mcp__<server>__<tool> "{server} / {tool}"; expanded — two tabs: Input JSON pretty-printed, Output JSON/text.
GenericToolWidget.swift Any other tool name (Monitor / LSP / CronCreate / etc.) Tool name + collapsed raw input/output JSON.

Dispatch

ToolCallCardContent(toolCall:) view — dispatches by toolCall.name (exact match for built-ins; prefix mcp__ for MCP; else Generic). Returns the right specialized view.

Common helpers

  • TruncatedText — display first 2KB / 40 lines + "Show full result" button (opens full content in modal or in Stream Inspector). For binary — summary.
  • AnsiToAttributedString — minimal SGR parser (8 basic colors + bold + dim); anything unknown → stripped.
  • DiffView — unified diff renderer for EditWidget; line-by-line AttributedString with color tint (no syntax highlight in MVP).

Constraints

  • All widgets are pure views — no side effects, no async loads except AsyncImage.
  • No text selection / copy restrictions — all content should be copyable.
  • A11y: every widget announces its tool name and status transitions.

Acceptance Criteria

  • All 12 widgets implemented and dispatched correctly by tool name.
  • TruncatedText truncates large outputs with working "Show full".
  • DiffView renders a realistic Edit example correctly (snapshot test).
  • AnsiToAttributedString handles minimal CSI SGR; unknown sequences stripped safely.
  • Bash mini-terminal monospaced, ANSI colors applied, exit code pill + duration.
  • Task subagent nesting renders child DialogueView (stubbed for MVP if child reducer not wired yet; verify slot works).
  • All widgets use DS tokens, no hardcoded values.
  • Snapshot tests for each widget — at least happy path × 4 appearances.
  • A11y — every widget has meaningful labels; tool output reachable via VoiceOver.

Relationships

Metadata

Metadata

Assignees

No one assigned

    Labels

    a11yAccessibility: VoiceOver, Dynamic Type, Reduce Motion, etc.complexity:LdialogueDialogue feature — structured chat UI for agent sessionsfrontendwave-3

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions