# Ticket 10.7 — Session Draft Persistence

**Phase**: 10 — Feature Parity Enhancements
**Priority**: Medium
**Depends on**: None

## Description

Save unsent input text per-session when the user switches sessions, and restore it when they switch back. claude-relay implements per-session draft persistence so users don't lose partially-typed messages when switching between sessions. Currently in conduit, switching sessions clears the input area, discarding any in-progress text.

The drafts should be stored in memory (`Map<sessionId, string>`) and optionally in localStorage for persistence across page reloads. Image attachments should also be preserved per-session.

## Acceptance Criteria

### AC1: Draft text is preserved on session switch
```gherkin
Given the user is in session "A" and has typed "implement the auth module" in the input area
When the user switches to session "B"
  And then switches back to session "A"
Then the input area contains "implement the auth module"
  And the cursor position is restored
```

### AC2: Each session maintains an independent draft
```gherkin
Given the user types "fix the bug" in session "A"
  And the user switches to session "B" and types "add tests"
When the user switches to session "A"
Then the input area shows "fix the bug"

When the user switches to session "B"
Then the input area shows "add tests"
```

### AC3: Sending a message clears the draft
```gherkin
Given the user has typed "deploy to staging" in session "A"
When the user sends the message
Then the draft for session "A" is cleared
  And switching away and back to session "A" shows an empty input area
```

### AC4: Drafts survive page reload
```gherkin
Given the user has typed "refactor the parser" in session "A" without sending
When the user reloads the page
  And navigates to session "A"
Then the input area contains "refactor the parser"
  And the draft was loaded from localStorage
```

### AC5: Image attachments are preserved per-session
```gherkin
Given the user has pasted an image into the input area in session "A"
  And has typed "describe this screenshot" alongside the image
When the user switches to session "B" and back to session "A"
Then the image attachment is still present in the input area
  And the text "describe this screenshot" is restored
```

### AC6: Draft is cleared when session is deleted
```gherkin
Given session "A" has a saved draft "work in progress"
When session "A" is deleted from the session list
Then the draft for session "A" is removed from memory
  And the draft for session "A" is removed from localStorage
  And no stale drafts accumulate over time
```

## Testable Components

| Component | Test Type | What to Assert |
|-----------|-----------|----------------|
| Draft save/restore per session | Unit | Saving a draft for session ID "abc" and retrieving it returns the exact string; retrieving a draft for a session with no saved draft returns empty string |
| Draft cleared on send | Unit | After calling `clearDraft(sessionId)`, subsequent `getDraft(sessionId)` returns empty string |
| localStorage persistence and recovery | Unit | After saving a draft and simulating a page reload (re-reading from localStorage), the draft is correctly recovered with the original text |
| Session delete clears draft | Unit | After deleting a session, its draft is removed from both the in-memory Map and localStorage; other session drafts are unaffected |
| Image attachment preservation | Unit | Draft store saves and restores image attachment metadata (data URL or blob reference) alongside text content for a given session |
| Multi-session draft switching | E2E | Typing in session A, switching to B, typing in B, switching back to A shows A's draft; switching to B shows B's draft |

## Reference

- claude-relay draft persistence: `../claude-relay/lib/public/modules/input.js` (per-session draft saved on session switch)
- InputArea component: `conduit/src/lib/public/components/layout/InputArea.svelte`
- Session store: `conduit/src/lib/public/stores/session.svelte.ts`
