# Ticket 2.5 — Input Synchronisation Between Clients

**Phase**: 2 — Server & WebSocket Layer
**Priority**: Low
**Depends on**: 2.2

## Description

When multiple browsers are connected to the same project, synchronise the input field in real-time. If one user starts typing, the other connected clients see the in-progress text. This prevents conflicts when multiple devices are open.

## Acceptance Criteria

### AC1: Typing broadcasts to other clients

```gherkin
Given browser A and browser B are connected to the same project
When browser A types "fix the auth bug" in the input field
Then browser B receives { type: "input_sync", text: "fix the auth bug", from: "<clientId>" }
And browser B's input field shows the synced text (greyed out / italic)
```

### AC2: Sender does not receive own sync

```gherkin
Given browser A sends an input_sync message
When the server broadcasts it
Then browser A does NOT receive its own input_sync
And only other connected clients receive it
```

### AC3: Sync clears on message send

```gherkin
Given browser B is showing synced text from browser A
When browser A sends the message
Then browser B's synced text preview clears
And the actual message appears in the chat normally
```

### AC4: No sync with single client

```gherkin
Given only one browser is connected
When it types in the input field
Then no input_sync messages are sent (optimisation)
```

## Testable Components

| Component | Test Type | What to Assert |
|-----------|-----------|----------------|
| `onInputSync(ws, data)` | Unit | Broadcasts to others, excludes sender |
| `clearSync(sessionId)` | Unit | Clears synced state on message send |
| Single client skip | Unit | No broadcast when client count is 1 |

## Reference

- Claude-relay input sync: `../claude-relay/lib/project.js` (input_sync handler)
