---
phase: "06"
plan: "01"
type: implementation
autonomous: true
wave: 1
depends_on: []
requirements: [BOT-05, BOT-07, CLI-01, CLI-02, CLI-03]
---

# Phase 6 Plan 1: CLI Subprocess + JSONL Parser + Model Selection

## Objective

Build the Claude CLI subprocess integration, JSONL transcript parser, and model selection infrastructure that the Telegram bot commands will use. These are the data-layer and process-layer components that Phase 5's bot will wire to commands.

## Context

- @plugins/claude-tts-companion/Sources/claude-tts-companion/Config.swift
- @plugins/claude-tts-companion/Package.swift
- @.planning/REQUIREMENTS.md (BOT-05, BOT-07, CLI-01, CLI-02, CLI-03)

## Tasks

### Task 1: JSONL Transcript Parser

type="auto"

Create `TranscriptParser.swift` that parses Claude Code JSONL transcript files.

**Done criteria:**

- Parses JSONL lines into typed structs (prompt, response, tool use)
- Extracts prompt text, response text, and tool call counts
- Handles malformed lines gracefully (skip + log)
- Builds compile-clean

**Files:** `Sources/claude-tts-companion/TranscriptParser.swift`

### Task 2: Claude CLI Subprocess + Model Selection

type="auto"

Create `ClaudeProcess.swift` that spawns `claude` CLI as a subprocess with model selection flags.

**Done criteria:**

- Spawns `claude` via Foundation Process + Pipe
- Supports --haiku, --sonnet, --opus model flags (BOT-05)
- Unsets CLAUDECODE env var before spawning (CLI-03)
- Parses streaming NDJSON output line-by-line (CLI-02)
- Provides async callback for each parsed response chunk
- Builds compile-clean

**Files:** `Sources/claude-tts-companion/ClaudeProcess.swift`

### Task 3: Config additions + Build verification

type="auto"

Add CLI-related config constants and verify full build succeeds.

**Done criteria:**

- Config.swift has claude CLI path and default model
- `swift build` succeeds with zero errors
- No new warnings introduced

**Files:** `Sources/claude-tts-companion/Config.swift`

## Verification

```bash
cd plugins/claude-tts-companion && swift build 2>&1 | tail -5
```

## Success Criteria

1. TranscriptParser.swift compiles and provides JSONL parsing API
2. ClaudeProcess.swift compiles and provides CLI subprocess spawning with model selection
3. `swift build` succeeds with zero errors
