Skip to content

Commit 6b5271e

Browse files
committed
Plans for warp adapter
1 parent 40bb4e1 commit 6b5271e

File tree

2 files changed

+453
-0
lines changed

2 files changed

+453
-0
lines changed
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
# Warp Terminal SQLite Schema Guide
2+
3+
Reference for the Warp terminal's local SQLite database structure, focused on AI Agent Mode data.
4+
5+
## Database Location
6+
7+
```
8+
~/Library/Group Containers/2BBY89MBSN.dev.warp/Library/Application Support/dev.warp.Warp-Stable/warp.sqlite
9+
```
10+
11+
**Note**: Database uses WAL mode. For consistent reads, copy all three files:
12+
- `warp.sqlite`
13+
- `warp.sqlite-shm`
14+
- `warp.sqlite-wal`
15+
16+
## Key Tables for AI Conversations
17+
18+
### ai_queries
19+
20+
Stores user queries sent to AI. One row per exchange (turn).
21+
22+
| Column | Type | Description |
23+
|--------|------|-------------|
24+
| `id` | INTEGER | Primary key |
25+
| `exchange_id` | TEXT | Unique ID for this exchange |
26+
| `conversation_id` | TEXT | Groups exchanges into conversations |
27+
| `start_ts` | DATETIME | Timestamp of query |
28+
| `input` | TEXT | JSON array with Query object |
29+
| `working_directory` | TEXT | Project path (for filtering) |
30+
| `output_status` | TEXT | "Completed", etc. |
31+
| `model_id` | TEXT | Model used (see Model IDs below) |
32+
| `planning_model_id` | TEXT | Planning model if different |
33+
| `coding_model_id` | TEXT | Coding model if different |
34+
35+
**Input JSON Structure**:
36+
```json
37+
[{
38+
"Query": {
39+
"text": "user's question here",
40+
"context": [
41+
{"Directory": {"pwd": "/path/to/project", "home_dir": "..."}},
42+
{"Git": {"head": "main"}},
43+
{"ProjectRules": {"root_path": "...", "active_rules": [...]}},
44+
{"CurrentTime": {"current_time": "2025-12-27T10:12:11-08:00"}},
45+
{"ExecutionEnvironment": {"os": {"category": "MacOS"}, "shell_name": "zsh"}},
46+
{"Codebase": {"path": "/path", "name": "project-name"}}
47+
],
48+
"referenced_attachments": {}
49+
}
50+
}]
51+
```
52+
53+
**Note**: Only the first exchange in a conversation has the full Query. Subsequent exchanges have empty `[]` input.
54+
55+
### agent_conversations
56+
57+
Stores usage metadata per conversation.
58+
59+
| Column | Type | Description |
60+
|--------|------|-------------|
61+
| `id` | INTEGER | Primary key |
62+
| `conversation_id` | TEXT | Links to ai_queries |
63+
| `conversation_data` | TEXT | JSON with usage stats |
64+
| `last_modified_at` | TIMESTAMP | Auto-updated on change |
65+
66+
**conversation_data JSON Structure**:
67+
```json
68+
{
69+
"server_conversation_token": "uuid",
70+
"conversation_usage_metadata": {
71+
"was_summarized": false,
72+
"context_window_usage": 0.36727,
73+
"credits_spent": 126.82,
74+
"credits_spent_for_last_block": 35.71,
75+
"token_usage": [
76+
{
77+
"model_id": "claude 4.5 opus (thinking)",
78+
"warp_tokens": 605182,
79+
"byok_tokens": 0,
80+
"warp_token_usage_by_category": {
81+
"primary_agent": 577163,
82+
"full_terminal_use": 28019
83+
}
84+
}
85+
],
86+
"tool_usage_metadata": {
87+
"run_command_stats": {"count": 36, "commands_executed": 32},
88+
"read_files_stats": {"count": 6},
89+
"grep_stats": {"count": 3},
90+
"file_glob_stats": {"count": 2},
91+
"apply_file_diff_stats": {"count": 3, "lines_added": 148, "lines_removed": 15},
92+
"read_shell_command_output_stats": {"count": 15}
93+
}
94+
}
95+
}
96+
```
97+
98+
### agent_tasks
99+
100+
Stores task lists created by AI agent. **Protobuf encoded**.
101+
102+
| Column | Type | Description |
103+
|--------|------|-------------|
104+
| `id` | INTEGER | Primary key |
105+
| `conversation_id` | TEXT | Links to conversation |
106+
| `task_id` | TEXT | Unique task ID |
107+
| `task` | BLOB | Protobuf-encoded task data |
108+
| `last_modified_at` | TIMESTAMP | Auto-updated |
109+
110+
**Protobuf Schema** (reverse-engineered from hex dump):
111+
```
112+
Field 1 (0x0a): task_id (string, UUID)
113+
Field 2 (0x12): title (string)
114+
Field 5 (0x2a): subtasks (repeated message)
115+
- Contains nested task_id, title
116+
Field 13 (0x6a): parent_task_id (string, UUID)
117+
Field 14 (0x72): timestamps
118+
```
119+
120+
### blocks
121+
122+
Terminal command blocks. Links to AI via `ai_metadata`.
123+
124+
| Column | Type | Description |
125+
|--------|------|-------------|
126+
| `id` | INTEGER | Primary key |
127+
| `pane_leaf_uuid` | BLOB | Terminal pane reference |
128+
| `stylized_command` | BLOB | ANSI-encoded command text |
129+
| `stylized_output` | BLOB | ANSI-encoded output text |
130+
| `pwd` | TEXT | Working directory |
131+
| `exit_code` | INTEGER | Command exit code |
132+
| `start_ts` | DATETIME | Command start time |
133+
| `completed_ts` | DATETIME | Command completion time |
134+
| `ai_metadata` | TEXT | JSON linking to conversation |
135+
136+
**ai_metadata JSON Structure**:
137+
```json
138+
{
139+
"action_id": "toolu_01SGHZqqhZ82QCPEjYaRYK1C",
140+
"conversation_id": "e05f25f4-4e57-411a-b126-f4c9ebca6781",
141+
"conversation_phase": {
142+
"interactive": {"must_not_suggest_create_plan": true}
143+
},
144+
"long_running_control_state": null,
145+
"has_agent_written_to_block": false
146+
}
147+
```
148+
149+
**ANSI Stripping**: `stylized_command` and `stylized_output` contain ANSI escape codes (e.g., `[1m`, `[0m`). Strip with regex: `\x1b\[[0-9;]*m`
150+
151+
## Model IDs
152+
153+
| Warp Model ID | Display Name |
154+
|---------------|--------------|
155+
| `claude-4-5-opus` | Claude Opus 4.5 |
156+
| `claude-4-5-opus-thinking` | Claude Opus 4.5 (Thinking) |
157+
| `gpt-5-1-high-reasoning` | GPT-5 |
158+
159+
## Critical Limitation
160+
161+
**Warp does NOT store AI assistant text responses locally.**
162+
163+
Only available:
164+
- User queries (ai_queries.input)
165+
- Tool executions (blocks with ai_metadata)
166+
- Usage statistics (agent_conversations)
167+
168+
Not stored locally:
169+
- AI reasoning/response text
170+
- Thinking content
171+
- Full conversation transcript
172+
173+
## Useful Queries
174+
175+
### List conversations by project
176+
```sql
177+
SELECT DISTINCT conversation_id, working_directory, model_id,
178+
MIN(start_ts) as first_msg, MAX(start_ts) as last_msg,
179+
COUNT(*) as exchange_count
180+
FROM ai_queries
181+
WHERE working_directory LIKE '/path/to/project%'
182+
GROUP BY conversation_id
183+
ORDER BY last_msg DESC;
184+
```
185+
186+
### Get blocks for a conversation
187+
```sql
188+
SELECT id, stylized_command, stylized_output, exit_code, ai_metadata
189+
FROM blocks
190+
WHERE ai_metadata LIKE '%"conversation_id":"<uuid>"%'
191+
ORDER BY start_ts;
192+
```
193+
194+
### Get usage for a conversation
195+
```sql
196+
SELECT conversation_data
197+
FROM agent_conversations
198+
WHERE conversation_id = '<uuid>';
199+
```
200+
201+
## Other Notable Tables
202+
203+
| Table | Purpose |
204+
|-------|---------|
205+
| `terminal_panes` | Terminal session state, `conversation_ids` field |
206+
| `commands` | Command history (not AI-specific) |
207+
| `projects` | Known project paths |
208+
| `workspace_metadata` | Workspace navigation history |
209+
| `mcp_server_installations` | MCP server configs |
210+
211+
## File Watching
212+
213+
Watch `warp.sqlite-wal` for changes. Debounce rapid writes (100ms recommended).

0 commit comments

Comments
 (0)