# Schema

### pending_changes
- id: uuid (pk)
- session_id: uuid (required, fk)
- task_id: uuid (fk)
- file_path: text (required)
- operation: text (required)
- diff: text (required)
- status: text (required)

### tasks
- id: uuid (pk)
- project_id: uuid (required, fk)
- parent_task_id: uuid (fk)
- state: text (required)
- input: text (required)
- output_summary: text
- agent: text
- model: text
- execution_path: text
- cost_tokens: integer
- started_at: timestamp(tz)
- ended_at: timestamp(tz)

### available_agents
- name: text (pk)
- install_path: text
- version: text
- supports_acp: boolean (required)
- last_probed_at: timestamp(tz)

### agent_sessions
- session_id: uuid (required, fk)
- agent: text (required)
- backend: text (required)
- agent_session_id: text (fk)
- server_port: integer
- status: text (required)
- last_active_at: timestamp(tz)

### worktrees
- id: uuid (pk)
- session_id: uuid (fk)
- project_id: uuid (fk)
- path: text (required)
- branch: text
- base_commit: text
- slug: text
- status: text (required)

### checkpoints
- id: uuid (pk)
- chat_id: uuid (required, fk)
- session_id: uuid (fk)
- worktree_id: uuid (fk)
- message_id: uuid (fk)

### claude_session_entries
- id: bigint(auto) (pk)
- project_key: text (required)
- session_id: text (required, fk)
- subpath: text (required)

### flow_runs
- id: uuid (pk)
- project_id: uuid (required, fk)
- flow_name: text (required)
- band: text (required)
- model: text (required)
- status: text (required)
- input: jsonb (required)
- report: text
- error: text

### flow_steps
- id: uuid (pk)
- run_id: uuid (required, fk)
- step_id: text (required, fk)
- kind: text (required)
- agent: text
- status: text (required)
- task_id: uuid (fk)
- chat_id: uuid (fk)
- input: text
- output: text
- error: text

### battles
- id: uuid (pk)
- project_id: uuid (required, fk)
- battle_type: text (required)
- prompt: text (required)
- status: text (required)
- winner_contestant_id: uuid (fk)
- results_path: text
- error: text

### contestants
- id: uuid (pk)
- battle_id: uuid (required, fk)
- identity: text (required)
- model: text (required)
- lane: text (required)
- task_id: uuid (fk)
- worktree_id: uuid (fk)
- status: text (required)
- duration_ms: integer
- tokens_per_sec: float8
- cost_tokens: integer
- result_path: text
- error: text

### cross_examinations
- id: uuid (pk)
- battle_id: uuid (required, fk)
- identity: text (required)
- model: text (required)
- verdict: text

### projects
- id: uuid (pk)
- name: text (required)
- path: text (required)
- added_at: timestamp(tz) (required)
- last_session_id: uuid (fk)

### sessions
- id: uuid (pk)
- project_id: uuid (required, fk)
- name: text (required)
- model: text (required)
- system_prompt: text (required)

### messages
- id: uuid (pk)
- session_id: uuid (required, fk)
- role: text (required)
- content: text (required)
- status: text (required)
- last_seq: integer (required)

### message_parts
- id: uuid (pk)
- message_id: uuid (required, fk)
- sequence: integer (required)
- kind: text (required)
- payload: jsonb (required)

### settings
- value: jsonb (required)

### chats
- id: uuid (pk)
- session_id: uuid (required, fk)
- name: text
- status: text (required)
