@mrpatronz/nexusflow 0.2.13 → 0.2.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/.github/dependabot.yml +52 -52
  2. package/.github/workflows/dependabot-merge.yml +53 -0
  3. package/.github/workflows/release.yml +112 -100
  4. package/.vscode/launch.json +17 -17
  5. package/.vscode/tasks.json +17 -17
  6. package/GETTING_STARTED.md +114 -109
  7. package/README.md +336 -311
  8. package/desktop/build-installer.js +228 -0
  9. package/desktop/build.js +118 -0
  10. package/desktop/installer/nexusflow.iss +35 -0
  11. package/desktop/neutralino.config.json +39 -0
  12. package/desktop/package-lock.json +1060 -0
  13. package/desktop/package.json +14 -0
  14. package/dist/commands/desktop.d.ts +12 -0
  15. package/dist/commands/desktop.d.ts.map +1 -0
  16. package/dist/commands/desktop.js +119 -0
  17. package/dist/commands/desktop.js.map +1 -0
  18. package/dist/commands/sync.d.ts.map +1 -1
  19. package/dist/commands/sync.js +1 -3
  20. package/dist/commands/sync.js.map +1 -1
  21. package/dist/commands/tui.d.ts +8 -0
  22. package/dist/commands/tui.d.ts.map +1 -0
  23. package/dist/commands/tui.js +386 -0
  24. package/dist/commands/tui.js.map +1 -0
  25. package/dist/commands/ui.d.ts +3 -1
  26. package/dist/commands/ui.d.ts.map +1 -1
  27. package/dist/commands/ui.js +76 -19
  28. package/dist/commands/ui.js.map +1 -1
  29. package/dist/generators/base.d.ts.map +1 -1
  30. package/dist/generators/base.js +78 -66
  31. package/dist/generators/base.js.map +1 -1
  32. package/dist/generators/codex.js +11 -11
  33. package/dist/generators/copilot.js +17 -17
  34. package/dist/generators/cursor.js +5 -5
  35. package/dist/generators/index.js +50 -50
  36. package/dist/generators/map-generator.js +14 -14
  37. package/dist/generators/skills-generator.js +28 -28
  38. package/dist/gui/app_logo.png +0 -0
  39. package/dist/gui/assets/index-Ct3qq-X4.js +25 -0
  40. package/dist/gui/assets/index-P_ZrgHXg.css +1 -0
  41. package/dist/gui/icons.svg +24 -24
  42. package/dist/gui/index.html +18 -18
  43. package/dist/index.js +43 -0
  44. package/dist/index.js.map +1 -1
  45. package/dist/server.d.ts.map +1 -1
  46. package/dist/server.js +182 -1
  47. package/dist/server.js.map +1 -1
  48. package/dist/server.test.js +78 -0
  49. package/dist/server.test.js.map +1 -1
  50. package/dist/types.d.ts +4 -0
  51. package/dist/types.d.ts.map +1 -1
  52. package/dist/utils/git.d.ts +16 -0
  53. package/dist/utils/git.d.ts.map +1 -1
  54. package/dist/utils/git.js +52 -0
  55. package/dist/utils/git.js.map +1 -1
  56. package/dist/utils/multi-git.d.ts +2 -0
  57. package/dist/utils/multi-git.d.ts.map +1 -1
  58. package/dist/utils/multi-git.js +5 -2
  59. package/dist/utils/multi-git.js.map +1 -1
  60. package/dist/utils/update-check.d.ts +3 -1
  61. package/dist/utils/update-check.d.ts.map +1 -1
  62. package/dist/utils/update-check.js +23 -6
  63. package/dist/utils/update-check.js.map +1 -1
  64. package/dist/utils/workflows.d.ts +11 -0
  65. package/dist/utils/workflows.d.ts.map +1 -0
  66. package/dist/utils/workflows.js +156 -0
  67. package/dist/utils/workflows.js.map +1 -0
  68. package/dist/utils/workflows.test.d.ts +2 -0
  69. package/dist/utils/workflows.test.d.ts.map +1 -0
  70. package/dist/utils/workflows.test.js +86 -0
  71. package/dist/utils/workflows.test.js.map +1 -0
  72. package/extension/media/icon.svg +1 -0
  73. package/extension/package-lock.json +2673 -2811
  74. package/extension/package.json +108 -70
  75. package/extension/src/extension.ts +631 -204
  76. package/extension/tsconfig.json +21 -19
  77. package/gui/README.md +73 -73
  78. package/gui/e2e/wizard.spec.ts +346 -327
  79. package/gui/eslint.config.js +26 -26
  80. package/gui/index.html +17 -17
  81. package/gui/package-lock.json +3079 -3118
  82. package/gui/package.json +36 -36
  83. package/gui/playwright.config.ts +41 -41
  84. package/gui/public/app_logo.png +0 -0
  85. package/gui/public/icons.svg +24 -24
  86. package/gui/src/App.css +1 -1
  87. package/gui/src/App.tsx +3407 -2722
  88. package/gui/src/assets/vite.svg +1 -1
  89. package/gui/src/features/changes/ChangesViewer.tsx +388 -388
  90. package/gui/src/features/knowledge/KnowledgeBase.tsx +84 -84
  91. package/gui/src/features/onboarding/OnboardingWizard.tsx +230 -230
  92. package/gui/src/features/plan/ImplementationPlan.tsx +32 -32
  93. package/gui/src/features/services/ServiceConsole.tsx +250 -250
  94. package/gui/src/features/sessions/SessionHistory.tsx +195 -195
  95. package/gui/src/features/workspace/WorkspaceList.tsx +666 -666
  96. package/gui/src/index.css +152 -110
  97. package/gui/src/main.tsx +94 -10
  98. package/gui/src/types.ts +62 -62
  99. package/gui/tsconfig.app.json +25 -25
  100. package/gui/tsconfig.json +7 -7
  101. package/gui/tsconfig.node.json +24 -24
  102. package/gui/vite.config.ts +12 -12
  103. package/package.json +56 -56
  104. package/resources/workflows/plan-implement-review.md +8 -0
  105. package/resources/workflows/research-verify.md +6 -0
  106. package/resources/workflows/solo-developer.md +3 -0
  107. package/scripts/simulate-workspaces.ts +55 -55
  108. package/src/analyzers/detect-apis.ts +290 -290
  109. package/src/analyzers/detect-deps.ts +315 -315
  110. package/src/analyzers/detect-existing.ts +74 -74
  111. package/src/analyzers/detect-ports.ts +110 -110
  112. package/src/analyzers/index.ts +97 -97
  113. package/src/analyzers/messaging-analyzer.ts +254 -254
  114. package/src/analyzers/readme-summarizer.ts +102 -102
  115. package/src/analyzers/run-analyzer.ts +269 -269
  116. package/src/analyzers/tech-stack.ts +283 -283
  117. package/src/commands/add-repo.ts +157 -157
  118. package/src/commands/commands.test.ts +155 -155
  119. package/src/commands/commit.ts +131 -131
  120. package/src/commands/create.ts +207 -207
  121. package/src/commands/desktop.ts +128 -0
  122. package/src/commands/diff.ts +125 -125
  123. package/src/commands/doctor.ts +357 -357
  124. package/src/commands/handoff.ts +266 -266
  125. package/src/commands/init.ts +134 -134
  126. package/src/commands/list.ts +46 -46
  127. package/src/commands/logs.ts +63 -63
  128. package/src/commands/mcp.ts +92 -92
  129. package/src/commands/open.ts +129 -129
  130. package/src/commands/pack.ts +73 -73
  131. package/src/commands/refresh.ts +147 -147
  132. package/src/commands/remove.ts +98 -98
  133. package/src/commands/start.ts +117 -117
  134. package/src/commands/status.ts +54 -54
  135. package/src/commands/stop.ts +55 -55
  136. package/src/commands/sync.ts +151 -153
  137. package/src/commands/tui.ts +424 -0
  138. package/src/commands/ui.ts +111 -47
  139. package/src/core/config.test.ts +96 -96
  140. package/src/core/config.ts +115 -115
  141. package/src/core/graph.ts +344 -344
  142. package/src/core/packer.test.ts +99 -99
  143. package/src/core/packer.ts +107 -107
  144. package/src/core/scanner.test.ts +61 -61
  145. package/src/core/scanner.ts +91 -91
  146. package/src/core/workspace.ts +380 -380
  147. package/src/core/worktree.ts +120 -120
  148. package/src/generators/antigravity.ts +32 -32
  149. package/src/generators/base.ts +240 -227
  150. package/src/generators/claude.ts +34 -34
  151. package/src/generators/codex.ts +48 -48
  152. package/src/generators/copilot.ts +56 -56
  153. package/src/generators/cursor.ts +44 -44
  154. package/src/generators/index.ts +250 -250
  155. package/src/generators/map-generator.test.ts +159 -159
  156. package/src/generators/map-generator.ts +542 -542
  157. package/src/generators/plan-generator.ts +481 -481
  158. package/src/generators/skills-generator.ts +259 -259
  159. package/src/index.ts +426 -382
  160. package/src/mcp/server.ts +294 -294
  161. package/src/orchestration/detect.ts +313 -313
  162. package/src/orchestration/index.ts +7 -7
  163. package/src/orchestration/runner.ts +283 -283
  164. package/src/server.test.ts +555 -464
  165. package/src/server.ts +1308 -1104
  166. package/src/types.ts +408 -403
  167. package/src/utils/detect-ai.test.ts +44 -44
  168. package/src/utils/detect-ai.ts +84 -84
  169. package/src/utils/detect-editors.test.ts +48 -48
  170. package/src/utils/detect-editors.ts +57 -57
  171. package/src/utils/git.test.ts +74 -74
  172. package/src/utils/git.ts +117 -61
  173. package/src/utils/local-ai.test.ts +130 -130
  174. package/src/utils/local-ai.ts +111 -111
  175. package/src/utils/multi-git.ts +313 -306
  176. package/src/utils/prompts.ts +209 -209
  177. package/src/utils/session-finder.ts +483 -483
  178. package/src/utils/system-scanner.test.ts +89 -89
  179. package/src/utils/system-scanner.ts +96 -96
  180. package/src/utils/update-check.ts +309 -275
  181. package/src/utils/workflows.test.ts +114 -0
  182. package/src/utils/workflows.ts +178 -0
  183. package/tsconfig.json +19 -19
  184. package/vitest.config.ts +14 -14
  185. package/dist/gui/assets/index-CFWwqFux.js +0 -23
  186. package/dist/gui/assets/index-Dvc9QMvl.css +0 -2
@@ -1,483 +1,483 @@
1
- /**
2
- * @module utils/session-finder
3
- * Scans local storage directories of various AI coding assistants to find conversation histories.
4
- */
5
-
6
- import * as fs from 'node:fs/promises';
7
- import * as path from 'node:path';
8
- import * as os from 'node:os';
9
- import type { AISession, ChatMessage } from '../types.js';
10
-
11
- /**
12
- * Derives the directory name that Claude Code uses inside `~/.claude/projects/`
13
- * for a given absolute project directory path.
14
- * It replaces special characters /, \, space, -, and _ with a hyphen.
15
- */
16
- export function getClaudeProjectFolderName(absolutePath: string): string {
17
- return absolutePath.replace(/[\\\/ _-]+/g, '-');
18
- }
19
-
20
- /**
21
- * Recursively retrieves all files in a directory that match a specific extension.
22
- */
23
- async function getFilesRecursively(dir: string, extension: string): Promise<string[]> {
24
- const result: string[] = [];
25
- try {
26
- const entries = await fs.readdir(dir, { withFileTypes: true });
27
- for (const entry of entries) {
28
- const fullPath = path.join(dir, entry.name);
29
- if (entry.isDirectory()) {
30
- const subFiles = await getFilesRecursively(fullPath, extension);
31
- result.push(...subFiles);
32
- } else if (entry.isFile() && entry.name.endsWith(extension)) {
33
- result.push(fullPath);
34
- }
35
- }
36
- } catch {}
37
- return result;
38
- }
39
-
40
- /**
41
- * Scans the local filesystem for conversation histories belonging to Claude, Antigravity,
42
- * Codex, and Copilot that relate to the specified workspace.
43
- *
44
- * @param workspacePath - Root directory of the active workspace.
45
- * @param repoPaths - Directories of sub-repositories included in the workspace.
46
- * @returns A promise that resolves to an array of {@link AISession} objects sorted by update time descending.
47
- */
48
- export async function findSessions(workspacePath: string, repoPaths: string[] = []): Promise<AISession[]> {
49
- const sessions: AISession[] = [];
50
- const wsFolderName = path.basename(workspacePath);
51
-
52
- // Normalization helper for accurate path comparison
53
- const normalizePath = (p: string) => path.normalize(p).toLowerCase();
54
- const normWorkspace = normalizePath(workspacePath);
55
- const normRepos = repoPaths.map(r => normalizePath(r));
56
-
57
- const isPathMatch = (sessPath?: string) => {
58
- if (!sessPath) return false;
59
- const normSess = normalizePath(sessPath);
60
- if (normSess === normWorkspace || normSess.startsWith(normWorkspace + path.sep)) return true;
61
- for (const r of normRepos) {
62
- if (normSess === r || normSess.startsWith(r + path.sep)) return true;
63
- }
64
- return false;
65
- };
66
-
67
- // ─── 1. Scan Antigravity Sessions ──────────────────────────────────────
68
- const agDir = path.join(os.homedir(), '.gemini', 'antigravity-cli');
69
- const agHistoryPath = path.join(agDir, 'history.jsonl');
70
-
71
- try {
72
- const historyContent = await fs.readFile(agHistoryPath, 'utf-8');
73
- const lines = historyContent.split('\n').filter(Boolean);
74
- const conversationsMap = new Map<string, { id: string; title: string; entries: any[] }>();
75
-
76
- for (const line of lines) {
77
- try {
78
- const entry = JSON.parse(line);
79
- if (entry.conversationId && isPathMatch(entry.workspace)) {
80
- if (!conversationsMap.has(entry.conversationId)) {
81
- conversationsMap.set(entry.conversationId, {
82
- id: entry.conversationId,
83
- title: entry.display || 'Untitled Conversation',
84
- entries: [],
85
- });
86
- }
87
- conversationsMap.get(entry.conversationId)!.entries.push(entry);
88
- }
89
- } catch {}
90
- }
91
-
92
- for (const [convId, convData] of conversationsMap.entries()) {
93
- const transcriptPath = path.join(agDir, 'brain', convId, '.system_generated', 'logs', 'transcript.jsonl');
94
- let messageCount = 0;
95
- let createdAt = new Date(convData.entries[0]?.timestamp || Date.now()).toISOString();
96
- let updatedAt = new Date(convData.entries[convData.entries.length - 1]?.timestamp || Date.now()).toISOString();
97
- let title = convData.title;
98
-
99
- try {
100
- const transcriptContent = await fs.readFile(transcriptPath, 'utf-8');
101
- const transcriptLines = transcriptContent.split('\n').filter(Boolean);
102
- let firstUserMessage = null;
103
-
104
- for (const line of transcriptLines) {
105
- const tObj = JSON.parse(line);
106
- if (tObj.type === 'USER_INPUT' || tObj.type === 'PLANNER_RESPONSE') {
107
- messageCount++;
108
- if (tObj.type === 'USER_INPUT' && !firstUserMessage) {
109
- firstUserMessage = tObj.content;
110
- }
111
- }
112
- }
113
-
114
- if (firstUserMessage) {
115
- const cleanMatch = firstUserMessage.match(/<USER_REQUEST>([\s\S]*?)<\/USER_REQUEST>/);
116
- title = cleanMatch ? cleanMatch[1].trim() : firstUserMessage.trim();
117
- }
118
- } catch {
119
- messageCount = convData.entries.length * 2;
120
- }
121
-
122
- if (title.length > 80) {
123
- title = title.substring(0, 80) + '...';
124
- }
125
-
126
- sessions.push({
127
- id: convId,
128
- assistant: 'antigravity',
129
- title,
130
- createdAt,
131
- updatedAt,
132
- messageCount,
133
- workspacePath,
134
- });
135
- }
136
- } catch {}
137
-
138
- // ─── 2. Scan Claude Code Sessions ──────────────────────────────────────
139
- const claudeConfigDir = process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), '.claude');
140
- const claudeProjectsDir = path.join(claudeConfigDir, 'projects');
141
-
142
- try {
143
- const candidateFolders = [
144
- getClaudeProjectFolderName(workspacePath),
145
- ...repoPaths.map(r => getClaudeProjectFolderName(r))
146
- ];
147
-
148
- for (const folder of candidateFolders) {
149
- const projectPath = path.join(claudeProjectsDir, folder);
150
- try {
151
- const files = await fs.readdir(projectPath);
152
- const jsonlFiles = files.filter(f => f.endsWith('.jsonl'));
153
-
154
- for (const file of jsonlFiles) {
155
- const filePath = path.join(projectPath, file);
156
- const sessionId = path.basename(file, '.jsonl');
157
-
158
- try {
159
- const content = await fs.readFile(filePath, 'utf-8');
160
- const lines = content.split('\n').filter(Boolean);
161
-
162
- let messageCount = 0;
163
- let createdAt = null;
164
- let updatedAt = null;
165
- let title = 'Claude Session';
166
-
167
- for (const line of lines) {
168
- const record = JSON.parse(line);
169
- if (record.timestamp) {
170
- if (!createdAt) createdAt = record.timestamp;
171
- updatedAt = record.timestamp;
172
- }
173
-
174
- if (record.type === 'user' || record.type === 'assistant') {
175
- messageCount++;
176
- if (record.type === 'user' && title === 'Claude Session') {
177
- const rawText = record.message?.text || record.message?.content || '';
178
- if (typeof rawText === 'string') {
179
- title = rawText.trim();
180
- } else if (Array.isArray(rawText)) {
181
- title = rawText.map((b: any) => b.text || b.content || '').join(' ').trim();
182
- }
183
- }
184
- }
185
- }
186
-
187
- if (title.length > 80) {
188
- title = title.substring(0, 80) + '...';
189
- }
190
-
191
- sessions.push({
192
- id: sessionId,
193
- assistant: 'claude',
194
- title,
195
- createdAt: createdAt || new Date().toISOString(),
196
- updatedAt: updatedAt || new Date().toISOString(),
197
- messageCount,
198
- workspacePath,
199
- });
200
- } catch {}
201
- }
202
- } catch {}
203
- }
204
- } catch {}
205
-
206
- // ─── 3. Scan OpenAI Codex Sessions ──────────────────────────────────────
207
- const codexDir = path.join(os.homedir(), '.codex');
208
- const codexSessionsDir = path.join(codexDir, 'sessions');
209
- try {
210
- const codexFiles = await getFilesRecursively(codexSessionsDir, '.jsonl');
211
- for (const file of codexFiles) {
212
- try {
213
- const content = await fs.readFile(file, 'utf-8');
214
- // Heuristic: check if the file references our workspace path or folder name
215
- if (!content.toLowerCase().includes(normWorkspace) && !content.includes(wsFolderName)) {
216
- continue;
217
- }
218
-
219
- const lines = content.split('\n').filter(Boolean);
220
- let messageCount = 0;
221
- let createdAt: string | null = null;
222
- let updatedAt: string | null = null;
223
- let title = 'Codex Session';
224
-
225
- for (const line of lines) {
226
- try {
227
- const record = JSON.parse(line);
228
- if (record.timestamp) {
229
- if (!createdAt) createdAt = new Date(record.timestamp).toISOString();
230
- updatedAt = new Date(record.timestamp).toISOString();
231
- }
232
- const role = record.role || record.message?.role || (record.prompt ? 'user' : record.completion ? 'assistant' : null);
233
- if (role === 'user' || role === 'assistant') {
234
- messageCount++;
235
- if (role === 'user' && title === 'Codex Session') {
236
- const text = record.content || record.prompt || record.message?.content || '';
237
- if (text) title = text.trim();
238
- }
239
- }
240
- } catch {}
241
- }
242
-
243
- const sessionId = path.basename(file, '.jsonl');
244
- sessions.push({
245
- id: sessionId,
246
- assistant: 'codex',
247
- title: title.length > 80 ? title.substring(0, 80) + '...' : title,
248
- createdAt: createdAt || new Date().toISOString(),
249
- updatedAt: updatedAt || new Date().toISOString(),
250
- messageCount,
251
- workspacePath,
252
- });
253
- } catch {}
254
- }
255
- } catch {}
256
-
257
- // ─── 4. Scan GitHub Copilot Sessions ────────────────────────────────────
258
- const copilotDir = path.join(os.homedir(), '.copilot');
259
- const copilotSessionsDirs = [
260
- path.join(copilotDir, 'session-state'),
261
- path.join(copilotDir, 'history-session-state')
262
- ];
263
- for (const dir of copilotSessionsDirs) {
264
- try {
265
- const copilotFiles = await getFilesRecursively(dir, '.json');
266
- for (const file of copilotFiles) {
267
- try {
268
- const content = await fs.readFile(file, 'utf-8');
269
- // Heuristic check
270
- if (!content.toLowerCase().includes(normWorkspace) && !content.includes(wsFolderName)) {
271
- continue;
272
- }
273
-
274
- const record = JSON.parse(content);
275
- let messageCount = 0;
276
- let title = 'Copilot Session';
277
- let messagesList: any[] = [];
278
-
279
- if (Array.isArray(record)) {
280
- messagesList = record;
281
- } else if (record && Array.isArray(record.messages)) {
282
- messagesList = record.messages;
283
- }
284
-
285
- for (const msg of messagesList) {
286
- const role = msg.role || (msg.type === 'user' ? 'user' : msg.type === 'assistant' ? 'assistant' : null);
287
- if (role === 'user' || role === 'assistant') {
288
- messageCount++;
289
- if (role === 'user' && title === 'Copilot Session') {
290
- const text = msg.content || msg.text || '';
291
- if (text) title = text.trim();
292
- }
293
- }
294
- }
295
-
296
- const stats = await fs.stat(file);
297
- const sessionId = path.basename(file, '.json');
298
-
299
- sessions.push({
300
- id: sessionId,
301
- assistant: 'copilot',
302
- title: title.length > 80 ? title.substring(0, 80) + '...' : title,
303
- createdAt: stats.birthtime.toISOString(),
304
- updatedAt: stats.mtime.toISOString(),
305
- messageCount,
306
- workspacePath,
307
- });
308
- } catch {}
309
- }
310
- } catch {}
311
- }
312
-
313
- // Sort by updatedAt descending
314
- sessions.sort((a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime());
315
- return sessions;
316
- }
317
-
318
- /**
319
- * Reads and parses the full transcript for a specific assistant conversation session.
320
- *
321
- * @param assistant - The name of the AI assistant ('antigravity', 'claude', 'codex', 'copilot').
322
- * @param sessionId - Unique ID of the conversation session.
323
- * @returns A promise that resolves to an array of {@link ChatMessage} objects.
324
- */
325
- export async function getSessionTranscript(assistant: string, sessionId: string): Promise<ChatMessage[]> {
326
- const messages: ChatMessage[] = [];
327
-
328
- if (assistant === 'antigravity') {
329
- const agDir = path.join(os.homedir(), '.gemini', 'antigravity-cli');
330
- const transcriptPath = path.join(agDir, 'brain', sessionId, '.system_generated', 'logs', 'transcript.jsonl');
331
- const content = await fs.readFile(transcriptPath, 'utf-8');
332
- const lines = content.split('\n').filter(Boolean);
333
-
334
- for (const line of lines) {
335
- const obj = JSON.parse(line);
336
- if (obj.type === 'USER_INPUT') {
337
- const rawContent = obj.content || '';
338
- const cleanMatch = rawContent.match(/<USER_REQUEST>([\s\S]*?)<\/USER_REQUEST>/);
339
- const cleanContent = cleanMatch ? cleanMatch[1].trim() : rawContent.trim();
340
- messages.push({
341
- role: 'user',
342
- content: cleanContent,
343
- timestamp: obj.created_at || obj.timestamp,
344
- });
345
- } else if (obj.type === 'PLANNER_RESPONSE') {
346
- messages.push({
347
- role: 'assistant',
348
- content: (obj.content || '').trim(),
349
- timestamp: obj.created_at || obj.timestamp,
350
- });
351
- }
352
- }
353
- } else if (assistant === 'claude') {
354
- const claudeConfigDir = process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), '.claude');
355
- const claudeProjectsDir = path.join(claudeConfigDir, 'projects');
356
- const projectFolders = await fs.readdir(claudeProjectsDir).catch(() => [] as string[]);
357
- let transcriptPath: string | null = null;
358
-
359
- for (const folder of projectFolders) {
360
- const p = path.join(claudeProjectsDir, folder, `${sessionId}.jsonl`);
361
- try {
362
- await fs.access(p);
363
- transcriptPath = p;
364
- break;
365
- } catch {}
366
- }
367
-
368
- if (!transcriptPath) {
369
- throw new Error(`Claude session ${sessionId} not found`);
370
- }
371
-
372
- const content = await fs.readFile(transcriptPath, 'utf-8');
373
- const lines = content.split('\n').filter(Boolean);
374
-
375
- for (const line of lines) {
376
- const record = JSON.parse(line);
377
- if (record.type === 'user' || record.role === 'user') {
378
- const rawText = record.message?.text || record.message?.content || record.text || '';
379
- let cleanText = '';
380
- if (typeof rawText === 'string') {
381
- cleanText = rawText.trim();
382
- } else if (Array.isArray(rawText)) {
383
- cleanText = rawText.map((b: any) => b.text || b.content || '').join(' ').trim();
384
- }
385
- messages.push({
386
- role: 'user',
387
- content: cleanText,
388
- timestamp: record.timestamp || record.created_at,
389
- });
390
- } else if (record.type === 'assistant' || record.role === 'assistant') {
391
- const rawText = record.message?.text || record.message?.content || record.text || '';
392
- let cleanText = '';
393
- if (typeof rawText === 'string') {
394
- cleanText = rawText.trim();
395
- } else if (Array.isArray(rawText)) {
396
- cleanText = rawText.map((b: any) => b.text || b.content || '').join(' ').trim();
397
- }
398
- messages.push({
399
- role: 'assistant',
400
- content: cleanText,
401
- timestamp: record.timestamp || record.created_at,
402
- });
403
- }
404
- }
405
- } else if (assistant === 'codex') {
406
- const codexDir = path.join(os.homedir(), '.codex');
407
- const codexSessionsDir = path.join(codexDir, 'sessions');
408
- const codexFiles = await getFilesRecursively(codexSessionsDir, '.jsonl');
409
- let transcriptPath: string | null = null;
410
-
411
- for (const file of codexFiles) {
412
- if (path.basename(file, '.jsonl') === sessionId) {
413
- transcriptPath = file;
414
- break;
415
- }
416
- }
417
-
418
- if (!transcriptPath) {
419
- throw new Error(`Codex session ${sessionId} not found`);
420
- }
421
-
422
- const content = await fs.readFile(transcriptPath, 'utf-8');
423
- const lines = content.split('\n').filter(Boolean);
424
-
425
- for (const line of lines) {
426
- const record = JSON.parse(line);
427
- const role = record.role || record.message?.role || (record.prompt ? 'user' : record.completion ? 'assistant' : null);
428
- if (role === 'user' || role === 'assistant') {
429
- const text = record.content || record.prompt || record.completion || record.message?.content || '';
430
- messages.push({
431
- role: role as 'user' | 'assistant',
432
- content: text.trim(),
433
- timestamp: record.timestamp ? new Date(record.timestamp).toISOString() : undefined,
434
- });
435
- }
436
- }
437
- } else if (assistant === 'copilot') {
438
- const copilotDir = path.join(os.homedir(), '.copilot');
439
- const copilotSessionsDirs = [
440
- path.join(copilotDir, 'session-state'),
441
- path.join(copilotDir, 'history-session-state')
442
- ];
443
- let transcriptPath: string | null = null;
444
-
445
- for (const dir of copilotSessionsDirs) {
446
- const files = await getFilesRecursively(dir, '.json');
447
- for (const file of files) {
448
- if (path.basename(file, '.json') === sessionId) {
449
- transcriptPath = file;
450
- break;
451
- }
452
- }
453
- if (transcriptPath) break;
454
- }
455
-
456
- if (!transcriptPath) {
457
- throw new Error(`Copilot session ${sessionId} not found`);
458
- }
459
-
460
- const content = await fs.readFile(transcriptPath, 'utf-8');
461
- const record = JSON.parse(content);
462
- let messagesList: any[] = [];
463
-
464
- if (Array.isArray(record)) {
465
- messagesList = record;
466
- } else if (record && Array.isArray(record.messages)) {
467
- messagesList = record.messages;
468
- }
469
-
470
- for (const msg of messagesList) {
471
- const role = msg.role || (msg.type === 'user' ? 'user' : msg.type === 'assistant' ? 'assistant' : null);
472
- if (role === 'user' || role === 'assistant') {
473
- messages.push({
474
- role: role as 'user' | 'assistant',
475
- content: (msg.content || msg.text || '').trim(),
476
- timestamp: msg.timestamp || msg.created_at,
477
- });
478
- }
479
- }
480
- }
481
-
482
- return messages;
483
- }
1
+ /**
2
+ * @module utils/session-finder
3
+ * Scans local storage directories of various AI coding assistants to find conversation histories.
4
+ */
5
+
6
+ import * as fs from 'node:fs/promises';
7
+ import * as path from 'node:path';
8
+ import * as os from 'node:os';
9
+ import type { AISession, ChatMessage } from '../types.js';
10
+
11
+ /**
12
+ * Derives the directory name that Claude Code uses inside `~/.claude/projects/`
13
+ * for a given absolute project directory path.
14
+ * It replaces special characters /, \, space, -, and _ with a hyphen.
15
+ */
16
+ export function getClaudeProjectFolderName(absolutePath: string): string {
17
+ return absolutePath.replace(/[\\\/ _-]+/g, '-');
18
+ }
19
+
20
+ /**
21
+ * Recursively retrieves all files in a directory that match a specific extension.
22
+ */
23
+ async function getFilesRecursively(dir: string, extension: string): Promise<string[]> {
24
+ const result: string[] = [];
25
+ try {
26
+ const entries = await fs.readdir(dir, { withFileTypes: true });
27
+ for (const entry of entries) {
28
+ const fullPath = path.join(dir, entry.name);
29
+ if (entry.isDirectory()) {
30
+ const subFiles = await getFilesRecursively(fullPath, extension);
31
+ result.push(...subFiles);
32
+ } else if (entry.isFile() && entry.name.endsWith(extension)) {
33
+ result.push(fullPath);
34
+ }
35
+ }
36
+ } catch {}
37
+ return result;
38
+ }
39
+
40
+ /**
41
+ * Scans the local filesystem for conversation histories belonging to Claude, Antigravity,
42
+ * Codex, and Copilot that relate to the specified workspace.
43
+ *
44
+ * @param workspacePath - Root directory of the active workspace.
45
+ * @param repoPaths - Directories of sub-repositories included in the workspace.
46
+ * @returns A promise that resolves to an array of {@link AISession} objects sorted by update time descending.
47
+ */
48
+ export async function findSessions(workspacePath: string, repoPaths: string[] = []): Promise<AISession[]> {
49
+ const sessions: AISession[] = [];
50
+ const wsFolderName = path.basename(workspacePath);
51
+
52
+ // Normalization helper for accurate path comparison
53
+ const normalizePath = (p: string) => path.normalize(p).toLowerCase();
54
+ const normWorkspace = normalizePath(workspacePath);
55
+ const normRepos = repoPaths.map(r => normalizePath(r));
56
+
57
+ const isPathMatch = (sessPath?: string) => {
58
+ if (!sessPath) return false;
59
+ const normSess = normalizePath(sessPath);
60
+ if (normSess === normWorkspace || normSess.startsWith(normWorkspace + path.sep)) return true;
61
+ for (const r of normRepos) {
62
+ if (normSess === r || normSess.startsWith(r + path.sep)) return true;
63
+ }
64
+ return false;
65
+ };
66
+
67
+ // ─── 1. Scan Antigravity Sessions ──────────────────────────────────────
68
+ const agDir = path.join(os.homedir(), '.gemini', 'antigravity-cli');
69
+ const agHistoryPath = path.join(agDir, 'history.jsonl');
70
+
71
+ try {
72
+ const historyContent = await fs.readFile(agHistoryPath, 'utf-8');
73
+ const lines = historyContent.split('\n').filter(Boolean);
74
+ const conversationsMap = new Map<string, { id: string; title: string; entries: any[] }>();
75
+
76
+ for (const line of lines) {
77
+ try {
78
+ const entry = JSON.parse(line);
79
+ if (entry.conversationId && isPathMatch(entry.workspace)) {
80
+ if (!conversationsMap.has(entry.conversationId)) {
81
+ conversationsMap.set(entry.conversationId, {
82
+ id: entry.conversationId,
83
+ title: entry.display || 'Untitled Conversation',
84
+ entries: [],
85
+ });
86
+ }
87
+ conversationsMap.get(entry.conversationId)!.entries.push(entry);
88
+ }
89
+ } catch {}
90
+ }
91
+
92
+ for (const [convId, convData] of conversationsMap.entries()) {
93
+ const transcriptPath = path.join(agDir, 'brain', convId, '.system_generated', 'logs', 'transcript.jsonl');
94
+ let messageCount = 0;
95
+ let createdAt = new Date(convData.entries[0]?.timestamp || Date.now()).toISOString();
96
+ let updatedAt = new Date(convData.entries[convData.entries.length - 1]?.timestamp || Date.now()).toISOString();
97
+ let title = convData.title;
98
+
99
+ try {
100
+ const transcriptContent = await fs.readFile(transcriptPath, 'utf-8');
101
+ const transcriptLines = transcriptContent.split('\n').filter(Boolean);
102
+ let firstUserMessage = null;
103
+
104
+ for (const line of transcriptLines) {
105
+ const tObj = JSON.parse(line);
106
+ if (tObj.type === 'USER_INPUT' || tObj.type === 'PLANNER_RESPONSE') {
107
+ messageCount++;
108
+ if (tObj.type === 'USER_INPUT' && !firstUserMessage) {
109
+ firstUserMessage = tObj.content;
110
+ }
111
+ }
112
+ }
113
+
114
+ if (firstUserMessage) {
115
+ const cleanMatch = firstUserMessage.match(/<USER_REQUEST>([\s\S]*?)<\/USER_REQUEST>/);
116
+ title = cleanMatch ? cleanMatch[1].trim() : firstUserMessage.trim();
117
+ }
118
+ } catch {
119
+ messageCount = convData.entries.length * 2;
120
+ }
121
+
122
+ if (title.length > 80) {
123
+ title = title.substring(0, 80) + '...';
124
+ }
125
+
126
+ sessions.push({
127
+ id: convId,
128
+ assistant: 'antigravity',
129
+ title,
130
+ createdAt,
131
+ updatedAt,
132
+ messageCount,
133
+ workspacePath,
134
+ });
135
+ }
136
+ } catch {}
137
+
138
+ // ─── 2. Scan Claude Code Sessions ──────────────────────────────────────
139
+ const claudeConfigDir = process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), '.claude');
140
+ const claudeProjectsDir = path.join(claudeConfigDir, 'projects');
141
+
142
+ try {
143
+ const candidateFolders = [
144
+ getClaudeProjectFolderName(workspacePath),
145
+ ...repoPaths.map(r => getClaudeProjectFolderName(r))
146
+ ];
147
+
148
+ for (const folder of candidateFolders) {
149
+ const projectPath = path.join(claudeProjectsDir, folder);
150
+ try {
151
+ const files = await fs.readdir(projectPath);
152
+ const jsonlFiles = files.filter(f => f.endsWith('.jsonl'));
153
+
154
+ for (const file of jsonlFiles) {
155
+ const filePath = path.join(projectPath, file);
156
+ const sessionId = path.basename(file, '.jsonl');
157
+
158
+ try {
159
+ const content = await fs.readFile(filePath, 'utf-8');
160
+ const lines = content.split('\n').filter(Boolean);
161
+
162
+ let messageCount = 0;
163
+ let createdAt = null;
164
+ let updatedAt = null;
165
+ let title = 'Claude Session';
166
+
167
+ for (const line of lines) {
168
+ const record = JSON.parse(line);
169
+ if (record.timestamp) {
170
+ if (!createdAt) createdAt = record.timestamp;
171
+ updatedAt = record.timestamp;
172
+ }
173
+
174
+ if (record.type === 'user' || record.type === 'assistant') {
175
+ messageCount++;
176
+ if (record.type === 'user' && title === 'Claude Session') {
177
+ const rawText = record.message?.text || record.message?.content || '';
178
+ if (typeof rawText === 'string') {
179
+ title = rawText.trim();
180
+ } else if (Array.isArray(rawText)) {
181
+ title = rawText.map((b: any) => b.text || b.content || '').join(' ').trim();
182
+ }
183
+ }
184
+ }
185
+ }
186
+
187
+ if (title.length > 80) {
188
+ title = title.substring(0, 80) + '...';
189
+ }
190
+
191
+ sessions.push({
192
+ id: sessionId,
193
+ assistant: 'claude',
194
+ title,
195
+ createdAt: createdAt || new Date().toISOString(),
196
+ updatedAt: updatedAt || new Date().toISOString(),
197
+ messageCount,
198
+ workspacePath,
199
+ });
200
+ } catch {}
201
+ }
202
+ } catch {}
203
+ }
204
+ } catch {}
205
+
206
+ // ─── 3. Scan OpenAI Codex Sessions ──────────────────────────────────────
207
+ const codexDir = path.join(os.homedir(), '.codex');
208
+ const codexSessionsDir = path.join(codexDir, 'sessions');
209
+ try {
210
+ const codexFiles = await getFilesRecursively(codexSessionsDir, '.jsonl');
211
+ for (const file of codexFiles) {
212
+ try {
213
+ const content = await fs.readFile(file, 'utf-8');
214
+ // Heuristic: check if the file references our workspace path or folder name
215
+ if (!content.toLowerCase().includes(normWorkspace) && !content.includes(wsFolderName)) {
216
+ continue;
217
+ }
218
+
219
+ const lines = content.split('\n').filter(Boolean);
220
+ let messageCount = 0;
221
+ let createdAt: string | null = null;
222
+ let updatedAt: string | null = null;
223
+ let title = 'Codex Session';
224
+
225
+ for (const line of lines) {
226
+ try {
227
+ const record = JSON.parse(line);
228
+ if (record.timestamp) {
229
+ if (!createdAt) createdAt = new Date(record.timestamp).toISOString();
230
+ updatedAt = new Date(record.timestamp).toISOString();
231
+ }
232
+ const role = record.role || record.message?.role || (record.prompt ? 'user' : record.completion ? 'assistant' : null);
233
+ if (role === 'user' || role === 'assistant') {
234
+ messageCount++;
235
+ if (role === 'user' && title === 'Codex Session') {
236
+ const text = record.content || record.prompt || record.message?.content || '';
237
+ if (text) title = text.trim();
238
+ }
239
+ }
240
+ } catch {}
241
+ }
242
+
243
+ const sessionId = path.basename(file, '.jsonl');
244
+ sessions.push({
245
+ id: sessionId,
246
+ assistant: 'codex',
247
+ title: title.length > 80 ? title.substring(0, 80) + '...' : title,
248
+ createdAt: createdAt || new Date().toISOString(),
249
+ updatedAt: updatedAt || new Date().toISOString(),
250
+ messageCount,
251
+ workspacePath,
252
+ });
253
+ } catch {}
254
+ }
255
+ } catch {}
256
+
257
+ // ─── 4. Scan GitHub Copilot Sessions ────────────────────────────────────
258
+ const copilotDir = path.join(os.homedir(), '.copilot');
259
+ const copilotSessionsDirs = [
260
+ path.join(copilotDir, 'session-state'),
261
+ path.join(copilotDir, 'history-session-state')
262
+ ];
263
+ for (const dir of copilotSessionsDirs) {
264
+ try {
265
+ const copilotFiles = await getFilesRecursively(dir, '.json');
266
+ for (const file of copilotFiles) {
267
+ try {
268
+ const content = await fs.readFile(file, 'utf-8');
269
+ // Heuristic check
270
+ if (!content.toLowerCase().includes(normWorkspace) && !content.includes(wsFolderName)) {
271
+ continue;
272
+ }
273
+
274
+ const record = JSON.parse(content);
275
+ let messageCount = 0;
276
+ let title = 'Copilot Session';
277
+ let messagesList: any[] = [];
278
+
279
+ if (Array.isArray(record)) {
280
+ messagesList = record;
281
+ } else if (record && Array.isArray(record.messages)) {
282
+ messagesList = record.messages;
283
+ }
284
+
285
+ for (const msg of messagesList) {
286
+ const role = msg.role || (msg.type === 'user' ? 'user' : msg.type === 'assistant' ? 'assistant' : null);
287
+ if (role === 'user' || role === 'assistant') {
288
+ messageCount++;
289
+ if (role === 'user' && title === 'Copilot Session') {
290
+ const text = msg.content || msg.text || '';
291
+ if (text) title = text.trim();
292
+ }
293
+ }
294
+ }
295
+
296
+ const stats = await fs.stat(file);
297
+ const sessionId = path.basename(file, '.json');
298
+
299
+ sessions.push({
300
+ id: sessionId,
301
+ assistant: 'copilot',
302
+ title: title.length > 80 ? title.substring(0, 80) + '...' : title,
303
+ createdAt: stats.birthtime.toISOString(),
304
+ updatedAt: stats.mtime.toISOString(),
305
+ messageCount,
306
+ workspacePath,
307
+ });
308
+ } catch {}
309
+ }
310
+ } catch {}
311
+ }
312
+
313
+ // Sort by updatedAt descending
314
+ sessions.sort((a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime());
315
+ return sessions;
316
+ }
317
+
318
+ /**
319
+ * Reads and parses the full transcript for a specific assistant conversation session.
320
+ *
321
+ * @param assistant - The name of the AI assistant ('antigravity', 'claude', 'codex', 'copilot').
322
+ * @param sessionId - Unique ID of the conversation session.
323
+ * @returns A promise that resolves to an array of {@link ChatMessage} objects.
324
+ */
325
+ export async function getSessionTranscript(assistant: string, sessionId: string): Promise<ChatMessage[]> {
326
+ const messages: ChatMessage[] = [];
327
+
328
+ if (assistant === 'antigravity') {
329
+ const agDir = path.join(os.homedir(), '.gemini', 'antigravity-cli');
330
+ const transcriptPath = path.join(agDir, 'brain', sessionId, '.system_generated', 'logs', 'transcript.jsonl');
331
+ const content = await fs.readFile(transcriptPath, 'utf-8');
332
+ const lines = content.split('\n').filter(Boolean);
333
+
334
+ for (const line of lines) {
335
+ const obj = JSON.parse(line);
336
+ if (obj.type === 'USER_INPUT') {
337
+ const rawContent = obj.content || '';
338
+ const cleanMatch = rawContent.match(/<USER_REQUEST>([\s\S]*?)<\/USER_REQUEST>/);
339
+ const cleanContent = cleanMatch ? cleanMatch[1].trim() : rawContent.trim();
340
+ messages.push({
341
+ role: 'user',
342
+ content: cleanContent,
343
+ timestamp: obj.created_at || obj.timestamp,
344
+ });
345
+ } else if (obj.type === 'PLANNER_RESPONSE') {
346
+ messages.push({
347
+ role: 'assistant',
348
+ content: (obj.content || '').trim(),
349
+ timestamp: obj.created_at || obj.timestamp,
350
+ });
351
+ }
352
+ }
353
+ } else if (assistant === 'claude') {
354
+ const claudeConfigDir = process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), '.claude');
355
+ const claudeProjectsDir = path.join(claudeConfigDir, 'projects');
356
+ const projectFolders = await fs.readdir(claudeProjectsDir).catch(() => [] as string[]);
357
+ let transcriptPath: string | null = null;
358
+
359
+ for (const folder of projectFolders) {
360
+ const p = path.join(claudeProjectsDir, folder, `${sessionId}.jsonl`);
361
+ try {
362
+ await fs.access(p);
363
+ transcriptPath = p;
364
+ break;
365
+ } catch {}
366
+ }
367
+
368
+ if (!transcriptPath) {
369
+ throw new Error(`Claude session ${sessionId} not found`);
370
+ }
371
+
372
+ const content = await fs.readFile(transcriptPath, 'utf-8');
373
+ const lines = content.split('\n').filter(Boolean);
374
+
375
+ for (const line of lines) {
376
+ const record = JSON.parse(line);
377
+ if (record.type === 'user' || record.role === 'user') {
378
+ const rawText = record.message?.text || record.message?.content || record.text || '';
379
+ let cleanText = '';
380
+ if (typeof rawText === 'string') {
381
+ cleanText = rawText.trim();
382
+ } else if (Array.isArray(rawText)) {
383
+ cleanText = rawText.map((b: any) => b.text || b.content || '').join(' ').trim();
384
+ }
385
+ messages.push({
386
+ role: 'user',
387
+ content: cleanText,
388
+ timestamp: record.timestamp || record.created_at,
389
+ });
390
+ } else if (record.type === 'assistant' || record.role === 'assistant') {
391
+ const rawText = record.message?.text || record.message?.content || record.text || '';
392
+ let cleanText = '';
393
+ if (typeof rawText === 'string') {
394
+ cleanText = rawText.trim();
395
+ } else if (Array.isArray(rawText)) {
396
+ cleanText = rawText.map((b: any) => b.text || b.content || '').join(' ').trim();
397
+ }
398
+ messages.push({
399
+ role: 'assistant',
400
+ content: cleanText,
401
+ timestamp: record.timestamp || record.created_at,
402
+ });
403
+ }
404
+ }
405
+ } else if (assistant === 'codex') {
406
+ const codexDir = path.join(os.homedir(), '.codex');
407
+ const codexSessionsDir = path.join(codexDir, 'sessions');
408
+ const codexFiles = await getFilesRecursively(codexSessionsDir, '.jsonl');
409
+ let transcriptPath: string | null = null;
410
+
411
+ for (const file of codexFiles) {
412
+ if (path.basename(file, '.jsonl') === sessionId) {
413
+ transcriptPath = file;
414
+ break;
415
+ }
416
+ }
417
+
418
+ if (!transcriptPath) {
419
+ throw new Error(`Codex session ${sessionId} not found`);
420
+ }
421
+
422
+ const content = await fs.readFile(transcriptPath, 'utf-8');
423
+ const lines = content.split('\n').filter(Boolean);
424
+
425
+ for (const line of lines) {
426
+ const record = JSON.parse(line);
427
+ const role = record.role || record.message?.role || (record.prompt ? 'user' : record.completion ? 'assistant' : null);
428
+ if (role === 'user' || role === 'assistant') {
429
+ const text = record.content || record.prompt || record.completion || record.message?.content || '';
430
+ messages.push({
431
+ role: role as 'user' | 'assistant',
432
+ content: text.trim(),
433
+ timestamp: record.timestamp ? new Date(record.timestamp).toISOString() : undefined,
434
+ });
435
+ }
436
+ }
437
+ } else if (assistant === 'copilot') {
438
+ const copilotDir = path.join(os.homedir(), '.copilot');
439
+ const copilotSessionsDirs = [
440
+ path.join(copilotDir, 'session-state'),
441
+ path.join(copilotDir, 'history-session-state')
442
+ ];
443
+ let transcriptPath: string | null = null;
444
+
445
+ for (const dir of copilotSessionsDirs) {
446
+ const files = await getFilesRecursively(dir, '.json');
447
+ for (const file of files) {
448
+ if (path.basename(file, '.json') === sessionId) {
449
+ transcriptPath = file;
450
+ break;
451
+ }
452
+ }
453
+ if (transcriptPath) break;
454
+ }
455
+
456
+ if (!transcriptPath) {
457
+ throw new Error(`Copilot session ${sessionId} not found`);
458
+ }
459
+
460
+ const content = await fs.readFile(transcriptPath, 'utf-8');
461
+ const record = JSON.parse(content);
462
+ let messagesList: any[] = [];
463
+
464
+ if (Array.isArray(record)) {
465
+ messagesList = record;
466
+ } else if (record && Array.isArray(record.messages)) {
467
+ messagesList = record.messages;
468
+ }
469
+
470
+ for (const msg of messagesList) {
471
+ const role = msg.role || (msg.type === 'user' ? 'user' : msg.type === 'assistant' ? 'assistant' : null);
472
+ if (role === 'user' || role === 'assistant') {
473
+ messages.push({
474
+ role: role as 'user' | 'assistant',
475
+ content: (msg.content || msg.text || '').trim(),
476
+ timestamp: msg.timestamp || msg.created_at,
477
+ });
478
+ }
479
+ }
480
+ }
481
+
482
+ return messages;
483
+ }