# Ticket 11.2 — History Tool & Thinking Block Rendering

**Phase**: 11 — UI/UX Polish
**Priority**: High
**Depends on**: None

## Description

When loading session history (switching sessions or on initial connect), tool invocations and thinking blocks are not rendered. The HistoryView/MessageList only renders user and assistant text turns, losing all tool call details, thinking blocks, and result metadata from previous messages.

This is a significant UX gap — users switching to a previous session see a stripped-down version of the conversation without any tool context. The history replay should reconstruct the full message structure including:

- Tool calls with their names, arguments, and results
- Thinking blocks (collapsed by default)
- Result bars with cost/duration
- System messages

The chat store's message parsing needs to handle the history message format (which comes from OpenCode's REST API) in addition to the streaming SSE format.

## Acceptance Criteria

### AC1: Tool calls rendered in history
```gherkin
Given a session with previous tool invocations exists
When the user switches to that session
Then each tool invocation is rendered as a ToolItem component
And the tool name and arguments are displayed
```

### AC2: Tool results rendered with status
```gherkin
Given a session with completed tool calls (both successful and failed) exists
When the user views that session's history
Then successful tool results show a success indicator
And failed tool results show an error indicator with the error message
```

### AC3: Thinking blocks rendered from history
```gherkin
Given a session with assistant thinking blocks exists
When the user views that session's history
Then each thinking block is rendered as a collapsible ThinkingBlock component
And thinking blocks are collapsed by default
And expanding a thinking block shows the full thinking content
```

### AC4: Result bars in history turns
```gherkin
Given a session with completed assistant turns that include cost and duration metadata
When the user views that session's history
Then each completed turn displays a result bar
And the result bar shows cost, duration, and token counts
```

### AC5: Visual parity with live messages
```gherkin
Given a message was originally streamed live and is now loaded from history
When the user views the historical version
Then the rendering is visually identical to how it appeared during live streaming
And no information is lost between the live and historical representations
```

### AC6: Progressive history with tool blocks
```gherkin
Given a session with more messages than the initial page load
When the user scrolls up to load earlier messages
Then the progressively loaded messages also render tool invocations and thinking blocks
And the scroll position is preserved during loading
```

## Testable Components

| Component | Test Type | What to Assert |
|-----------|-----------|----------------|
| History message parsing for tool parts | Unit | Chat store correctly extracts `tool_invocation` parts from history API response |
| History message parsing for thinking parts | Unit | Chat store correctly extracts `thinking` parts from history API response |
| Tool/thinking component rendering in history | E2E | ToolItem and ThinkingBlock components appear for historical messages |
| Cost/duration display in history turns | E2E | Result bar shows correct cost, duration, and token values from metadata |
| Progressive history loading with tools | E2E | Scrolling up loads older messages with tool blocks rendered correctly |
| History vs. live rendering parity | Integration | Same message renders identically whether streamed or loaded from history |

## Reference

- Current gap: `conduit/src/lib/public/components/chat/MessageList.svelte` (only renders user/assistant text)
- Chat store message types: `conduit/src/lib/public/stores/chat.svelte.ts`
- OpenCode message parts: `GET /session/:id/messages` returns parts with `type: "text" | "tool_invocation" | "tool_result" | "thinking"`
- claude-relay history replay: `../claude-relay/lib/sessions.js` (full message reconstruction)
