# Ticket 3.5 — Keep-Awake Management

**Phase**: 3 — Daemon & CLI
**Priority**: Low
**Depends on**: 3.1

## Description

Prevent the host machine from sleeping while the daemon is running and an agent is actively processing. Uses `caffeinate` on macOS. Important for long-running tasks where the user is monitoring from their phone.

## Acceptance Criteria

### AC1: Activates keep-awake during processing

```gherkin
Given the daemon is running on macOS
And keep-awake is enabled
When an agent starts processing a request
Then it spawns `caffeinate -di` as a child process
And the system will not sleep while the agent is working
```

### AC2: Deactivates when idle

```gherkin
Given keep-awake is active
When the agent finishes processing and no other agents are active
Then it kills the caffeinate process
And the system resumes normal sleep behaviour
```

### AC3: Toggle via IPC

```gherkin
When CLI sends {"cmd": "set_keep_awake", "enabled": true}
Then keep-awake is enabled for future processing

When CLI sends {"cmd": "set_keep_awake", "enabled": false}
Then keep-awake is disabled and any active caffeinate is killed
```

### AC4: No-op on non-macOS

```gherkin
Given the daemon is running on Linux or Windows
When keep-awake is enabled
Then it logs "Keep-awake not supported on this platform"
And no error is thrown
```

## Testable Components

| Component | Test Type | What to Assert |
|-----------|-----------|----------------|
| `activate()` | Unit | Spawns caffeinate with correct flags |
| `deactivate()` | Unit | Kills caffeinate process |
| `toggle(enabled)` | Unit | Sets config, activates/deactivates |
| Platform detection | Unit | No-op on non-macOS |
| Processing lifecycle | Fixture | Activate on start, deactivate on finish |

## Reference

- Claude-relay keep-awake: `../claude-relay/lib/daemon.js` (lines 151-215)
- macOS `caffeinate -di` prevents display and idle sleep
