Repository navigation
Expand file tree
/
Copy pathextract_windsurf.py
More file actions
executable file
·341 lines (275 loc) · 11.7 KB
/
Copy pathextract_windsurf.py
File metadata and controls
executable file
·341 lines (275 loc) · 11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#!/usr/bin/env python3
"""
Extract ALL Windsurf chat and agent data from all projects
Includes: messages, code context, diffs, file references
Auto-discovers Windsurf installations on the device
"""
import json
import sqlite3
from pathlib import Path
from datetime import datetime
import platform
import os
from collections import defaultdict
def find_windsurf_installations():
"""Find all Windsurf installation directories"""
system = platform.system()
home = Path.home()
locations = []
# Windsurf patterns
windsurf_patterns = ['Windsurf', 'windsurf', '.windsurf']
if system == "Darwin": # macOS
base_dirs = [
home / "Library/Application Support",
home / ".config"
]
elif system == "Linux":
base_dirs = [
home / ".config",
home / ".local/share"
]
elif system == "Windows":
base_dirs = [
Path(os.environ.get('APPDATA', home / 'AppData/Roaming')),
Path(os.environ.get('LOCALAPPDATA', home / 'AppData/Local'))
]
else:
base_dirs = [home / ".config"]
for base_dir in base_dirs:
if not base_dir.exists():
continue
for pattern in windsurf_patterns:
windsurf_dir = base_dir / pattern
if windsurf_dir.exists():
locations.append(windsurf_dir)
return list(set(locations))
def extract_windsurf_chat(db_path, workspace_id):
"""Extract Windsurf chat conversations (similar to VSCode/Cursor format)"""
conversations = []
try:
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
# Try different key patterns
keys_to_try = [
'workbench.panel.aichat.view.aichat.chatdata',
'aiChat.chatdata',
'chat.data',
'cascade.chatdata' # Windsurf might use Cascade branding
]
for key in keys_to_try:
try:
cursor.execute(f"SELECT value FROM ItemTable WHERE key = ?", (key,))
result = cursor.fetchone()
if result:
data = json.loads(result[0])
if 'tabs' in data:
for tab in data['tabs']:
if 'bubbles' in tab and len(tab['bubbles']) > 0:
messages = []
code_context = []
for bubble in tab['bubbles']:
bubble_type = bubble.get('type')
content = bubble.get('rawText', bubble.get('text', ''))
msg = {
'role': 'user' if bubble_type == 'user' else 'assistant',
'content': content
}
# Extract code context
if 'selections' in bubble and bubble['selections']:
ctx = []
for sel in bubble['selections']:
if 'uri' in sel and 'fsPath' in sel['uri']:
ctx.append({
'file': sel['uri']['fsPath'],
'code': sel.get('text', sel.get('rawText', '')),
'range': sel.get('range')
})
if ctx:
msg['code_context'] = ctx
code_context.extend(ctx)
# Extract diffs
if 'suggestedDiffs' in bubble:
msg['suggested_diffs'] = bubble['suggestedDiffs']
messages.append(msg)
if messages:
conversations.append({
'messages': messages,
'source': 'windsurf-chat',
'chat_title': tab.get('chatTitle'),
'tab_id': tab.get('tabId'),
'workspace_id': workspace_id,
'has_code_context': len(code_context) > 0
})
break # Found data, no need to try other keys
except:
continue
conn.close()
except Exception as e:
pass
return conversations
def extract_windsurf_agent(global_db_path):
"""Extract Windsurf agent/flow conversations"""
conversations = []
try:
conn = sqlite3.connect(global_db_path)
cursor = conn.cursor()
# Try different table formats
cursor.execute("SELECT name FROM sqlite_master WHERE type='table'")
tables = [row[0] for row in cursor.fetchall()]
# Check for cursorDiskKV (if Windsurf uses similar format to Cursor)
if 'cursorDiskKV' in tables:
cursor.execute("SELECT key, value FROM cursorDiskKV WHERE key LIKE 'composerData:%' OR key LIKE 'agentData:%' OR key LIKE 'flowData:%'")
results = cursor.fetchall()
for key, value in results:
if not value:
continue
try:
data = json.loads(value)
conv = extract_agent_conversation(data, key)
if conv:
conversations.append(conv)
except:
continue
# Also check ItemTable
if 'ItemTable' in tables:
cursor.execute("SELECT key, value FROM ItemTable WHERE key LIKE '%agent%' OR key LIKE '%flow%' OR key LIKE '%cascade%'")
results = cursor.fetchall()
for key, value in results:
if not value:
continue
try:
data = json.loads(value)
conv = extract_agent_conversation(data, key)
if conv:
conversations.append(conv)
except:
continue
conn.close()
except Exception as e:
pass
return conversations
def extract_agent_conversation(data, key):
"""Extract agent conversation from data object"""
if not isinstance(data, dict):
return None
messages = []
# Try different conversation formats
if 'conversation' in data and isinstance(data['conversation'], list):
for bubble in data['conversation']:
bubble_type = bubble.get('type')
text = bubble.get('text', '')
if bubble_type == 1 or bubble.get('role') == 'user':
msg = {
'role': 'user',
'content': text
}
# Add context
if 'context' in bubble:
context = bubble['context']
if 'selections' in context:
ctx = []
for sel in context['selections']:
if 'uri' in sel and 'fsPath' in sel['uri']:
ctx.append({
'file': sel['uri']['fsPath'],
'code': sel.get('text', sel.get('rawText', '')),
'range': sel.get('range')
})
if ctx:
msg['code_context'] = ctx
messages.append(msg)
elif bubble_type == 2 or bubble.get('role') == 'assistant':
msg = {
'role': 'assistant',
'content': text
}
# Add diffs
if 'suggestedCodeBlocks' in bubble:
msg['suggested_code_blocks'] = bubble['suggestedCodeBlocks']
if 'diffHistories' in bubble:
msg['diff_histories'] = bubble['diffHistories']
messages.append(msg)
if messages:
return {
'messages': messages,
'source': 'windsurf-agent',
'name': data.get('name', 'Untitled'),
'status': data.get('status'),
'created_at': data.get('createdAt'),
'updated_at': data.get('lastUpdatedAt')
}
return None
def main():
print("="*80)
print("WINDSURF COMPLETE DATA EXTRACTION (Chat + Agent)")
print("="*80)
print()
# Find all Windsurf installations
print("🔍 Searching for Windsurf installations...")
installations = find_windsurf_installations()
if not installations:
print("❌ No Windsurf installations found!")
return
print(f"✅ Found {len(installations)} installation(s):")
for inst in installations:
print(f" - {inst}")
print()
all_conversations = []
stats = defaultdict(int)
for installation in installations:
print(f"📂 Processing: {installation}")
# Extract Chat mode (workspace storage)
workspace_storage = installation / 'User/workspaceStorage'
if workspace_storage.exists():
workspace_count = 0
for workspace in workspace_storage.iterdir():
if workspace.is_dir():
db_file = workspace / 'state.vscdb'
if db_file.exists():
convs = extract_windsurf_chat(db_file, workspace.name)
all_conversations.extend(convs)
workspace_count += len(convs)
print(f" ✅ Chat mode: {workspace_count} conversations")
stats['chat'] += workspace_count
# Extract Agent/Flow mode (global storage)
global_storage = installation / 'User/globalStorage/state.vscdb'
if global_storage.exists():
convs = extract_windsurf_agent(global_storage)
all_conversations.extend(convs)
print(f" ✅ Agent/Flow: {len(convs)} conversations")
stats['agent'] += len(convs)
else:
print(f" ⚠️ No global storage found")
print()
print("="*80)
print("EXTRACTION COMPLETE")
print("="*80)
print(f"Total conversations: {len(all_conversations):,}")
print(f" Chat mode: {stats['chat']:,}")
print(f" Agent/Flow: {stats['agent']:,}")
if not all_conversations:
print("No conversations found!")
return
# Statistics
total_messages = sum(len(c['messages']) for c in all_conversations)
with_code = sum(1 for c in all_conversations if c.get('has_code_context'))
complete = sum(1 for c in all_conversations
if any(m['role'] == 'assistant' for m in c['messages']))
print(f"Complete conversations: {complete:,}")
print(f"Total messages: {total_messages:,}")
print(f"With code context: {with_code:,}")
print()
# Save to organized JSONL
output_dir = Path('extracted_data')
output_dir.mkdir(exist_ok=True)
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
output_file = output_dir / f'windsurf_conversations_{timestamp}.jsonl'
with open(output_file, 'w') as f:
for conv in all_conversations:
f.write(json.dumps(conv, ensure_ascii=False) + '\n')
file_size = output_file.stat().st_size / 1024 / 1024
print(f"✅ Saved to: {output_file}")
print(f" Size: {file_size:.2f} MB")
print(f" Format: JSONL (one conversation per line)")
if __name__ == '__main__':
main()