@mrpatronz/nexusflow 0.1.0
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.
- package/GETTING_STARTED.md +109 -0
- package/README.md +310 -0
- package/dist/analyzers/detect-apis.d.ts +19 -0
- package/dist/analyzers/detect-apis.d.ts.map +1 -0
- package/dist/analyzers/detect-apis.js +121 -0
- package/dist/analyzers/detect-apis.js.map +1 -0
- package/dist/analyzers/detect-deps.d.ts +30 -0
- package/dist/analyzers/detect-deps.d.ts.map +1 -0
- package/dist/analyzers/detect-deps.js +121 -0
- package/dist/analyzers/detect-deps.js.map +1 -0
- package/dist/analyzers/detect-existing.d.ts +15 -0
- package/dist/analyzers/detect-existing.d.ts.map +1 -0
- package/dist/analyzers/detect-existing.js +65 -0
- package/dist/analyzers/detect-existing.js.map +1 -0
- package/dist/analyzers/detect-ports.d.ts +20 -0
- package/dist/analyzers/detect-ports.d.ts.map +1 -0
- package/dist/analyzers/detect-ports.js +103 -0
- package/dist/analyzers/detect-ports.js.map +1 -0
- package/dist/analyzers/index.d.ts +29 -0
- package/dist/analyzers/index.d.ts.map +1 -0
- package/dist/analyzers/index.js +74 -0
- package/dist/analyzers/index.js.map +1 -0
- package/dist/analyzers/readme-summarizer.d.ts +13 -0
- package/dist/analyzers/readme-summarizer.d.ts.map +1 -0
- package/dist/analyzers/readme-summarizer.js +59 -0
- package/dist/analyzers/readme-summarizer.js.map +1 -0
- package/dist/analyzers/tech-stack.d.ts +15 -0
- package/dist/analyzers/tech-stack.d.ts.map +1 -0
- package/dist/analyzers/tech-stack.js +284 -0
- package/dist/analyzers/tech-stack.js.map +1 -0
- package/dist/commands/create.d.ts +17 -0
- package/dist/commands/create.d.ts.map +1 -0
- package/dist/commands/create.js +111 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/init.d.ts +10 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +50 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/list.d.ts +9 -0
- package/dist/commands/list.d.ts.map +1 -0
- package/dist/commands/list.js +32 -0
- package/dist/commands/list.js.map +1 -0
- package/dist/commands/logs.d.ts +12 -0
- package/dist/commands/logs.d.ts.map +1 -0
- package/dist/commands/logs.js +54 -0
- package/dist/commands/logs.js.map +1 -0
- package/dist/commands/open.d.ts +9 -0
- package/dist/commands/open.d.ts.map +1 -0
- package/dist/commands/open.js +49 -0
- package/dist/commands/open.js.map +1 -0
- package/dist/commands/start.d.ts +13 -0
- package/dist/commands/start.d.ts.map +1 -0
- package/dist/commands/start.js +97 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/commands/status.d.ts +11 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +47 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/stop.d.ts +11 -0
- package/dist/commands/stop.d.ts.map +1 -0
- package/dist/commands/stop.js +47 -0
- package/dist/commands/stop.js.map +1 -0
- package/dist/commands/ui.d.ts +13 -0
- package/dist/commands/ui.d.ts.map +1 -0
- package/dist/commands/ui.js +44 -0
- package/dist/commands/ui.js.map +1 -0
- package/dist/core/config.d.ts +32 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +68 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/scanner.d.ts +18 -0
- package/dist/core/scanner.d.ts.map +1 -0
- package/dist/core/scanner.js +73 -0
- package/dist/core/scanner.js.map +1 -0
- package/dist/core/workspace.d.ts +53 -0
- package/dist/core/workspace.d.ts.map +1 -0
- package/dist/core/workspace.js +114 -0
- package/dist/core/workspace.js.map +1 -0
- package/dist/core/worktree.d.ts +27 -0
- package/dist/core/worktree.d.ts.map +1 -0
- package/dist/core/worktree.js +35 -0
- package/dist/core/worktree.js.map +1 -0
- package/dist/generators/base.d.ts +15 -0
- package/dist/generators/base.d.ts.map +1 -0
- package/dist/generators/base.js +175 -0
- package/dist/generators/base.js.map +1 -0
- package/dist/generators/claude.d.ts +17 -0
- package/dist/generators/claude.d.ts.map +1 -0
- package/dist/generators/claude.js +29 -0
- package/dist/generators/claude.js.map +1 -0
- package/dist/generators/codex.d.ts +16 -0
- package/dist/generators/codex.d.ts.map +1 -0
- package/dist/generators/codex.js +41 -0
- package/dist/generators/codex.js.map +1 -0
- package/dist/generators/copilot.d.ts +16 -0
- package/dist/generators/copilot.d.ts.map +1 -0
- package/dist/generators/copilot.js +49 -0
- package/dist/generators/copilot.js.map +1 -0
- package/dist/generators/cursor.d.ts +17 -0
- package/dist/generators/cursor.d.ts.map +1 -0
- package/dist/generators/cursor.js +37 -0
- package/dist/generators/cursor.js.map +1 -0
- package/dist/generators/index.d.ts +18 -0
- package/dist/generators/index.d.ts.map +1 -0
- package/dist/generators/index.js +95 -0
- package/dist/generators/index.js.map +1 -0
- package/dist/gui/assets/index-Cq9V485S.js +21 -0
- package/dist/gui/assets/index-Dh1b5gSZ.css +2 -0
- package/dist/gui/favicon.svg +1 -0
- package/dist/gui/icons.svg +24 -0
- package/dist/gui/index.html +18 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +169 -0
- package/dist/index.js.map +1 -0
- package/dist/orchestration/detect.d.ts +29 -0
- package/dist/orchestration/detect.d.ts.map +1 -0
- package/dist/orchestration/detect.js +292 -0
- package/dist/orchestration/detect.js.map +1 -0
- package/dist/orchestration/index.d.ts +7 -0
- package/dist/orchestration/index.d.ts.map +1 -0
- package/dist/orchestration/index.js +7 -0
- package/dist/orchestration/index.js.map +1 -0
- package/dist/orchestration/runner.d.ts +40 -0
- package/dist/orchestration/runner.d.ts.map +1 -0
- package/dist/orchestration/runner.js +242 -0
- package/dist/orchestration/runner.js.map +1 -0
- package/dist/server.d.ts +16 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +419 -0
- package/dist/server.js.map +1 -0
- package/dist/types.d.ts +210 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/detect-ai.d.ts +21 -0
- package/dist/utils/detect-ai.d.ts.map +1 -0
- package/dist/utils/detect-ai.js +76 -0
- package/dist/utils/detect-ai.js.map +1 -0
- package/dist/utils/detect-editors.d.ts +19 -0
- package/dist/utils/detect-editors.d.ts.map +1 -0
- package/dist/utils/detect-editors.js +49 -0
- package/dist/utils/detect-editors.js.map +1 -0
- package/dist/utils/git.d.ts +27 -0
- package/dist/utils/git.d.ts.map +1 -0
- package/dist/utils/git.js +57 -0
- package/dist/utils/git.js.map +1 -0
- package/dist/utils/prompts.d.ts +27 -0
- package/dist/utils/prompts.d.ts.map +1 -0
- package/dist/utils/prompts.js +119 -0
- package/dist/utils/prompts.js.map +1 -0
- package/dist/utils/session-finder.d.ts +29 -0
- package/dist/utils/session-finder.d.ts.map +1 -0
- package/dist/utils/session-finder.js +462 -0
- package/dist/utils/session-finder.js.map +1 -0
- package/gui/README.md +73 -0
- package/gui/eslint.config.js +22 -0
- package/gui/index.html +17 -0
- package/gui/package-lock.json +3054 -0
- package/gui/package.json +33 -0
- package/gui/public/favicon.svg +1 -0
- package/gui/public/icons.svg +24 -0
- package/gui/src/App.css +1 -0
- package/gui/src/App.tsx +1949 -0
- package/gui/src/assets/hero.png +0 -0
- package/gui/src/assets/react.svg +1 -0
- package/gui/src/assets/vite.svg +1 -0
- package/gui/src/index.css +1 -0
- package/gui/src/main.tsx +10 -0
- package/gui/tsconfig.app.json +25 -0
- package/gui/tsconfig.json +7 -0
- package/gui/tsconfig.node.json +24 -0
- package/gui/vite.config.ts +12 -0
- package/package.json +48 -0
- package/src/analyzers/detect-apis.ts +138 -0
- package/src/analyzers/detect-deps.ts +138 -0
- package/src/analyzers/detect-existing.ts +74 -0
- package/src/analyzers/detect-ports.ts +110 -0
- package/src/analyzers/index.ts +85 -0
- package/src/analyzers/readme-summarizer.ts +68 -0
- package/src/analyzers/tech-stack.ts +255 -0
- package/src/commands/create.ts +142 -0
- package/src/commands/init.ts +58 -0
- package/src/commands/list.ts +46 -0
- package/src/commands/logs.ts +63 -0
- package/src/commands/open.ts +54 -0
- package/src/commands/start.ts +117 -0
- package/src/commands/status.ts +54 -0
- package/src/commands/stop.ts +55 -0
- package/src/commands/ui.ts +47 -0
- package/src/core/config.ts +79 -0
- package/src/core/scanner.ts +91 -0
- package/src/core/workspace.ts +149 -0
- package/src/core/worktree.ts +50 -0
- package/src/generators/base.ts +187 -0
- package/src/generators/claude.ts +34 -0
- package/src/generators/codex.ts +48 -0
- package/src/generators/copilot.ts +56 -0
- package/src/generators/cursor.ts +44 -0
- package/src/generators/index.ts +122 -0
- package/src/index.ts +178 -0
- package/src/orchestration/detect.ts +313 -0
- package/src/orchestration/index.ts +7 -0
- package/src/orchestration/runner.ts +279 -0
- package/src/server.ts +466 -0
- package/src/types.ts +294 -0
- package/src/utils/detect-ai.ts +81 -0
- package/src/utils/detect-editors.ts +54 -0
- package/src/utils/git.ts +61 -0
- package/src/utils/prompts.ts +135 -0
- package/src/utils/session-finder.ts +483 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +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
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "Node16",
|
|
5
|
+
"moduleResolution": "Node16",
|
|
6
|
+
"outDir": "dist",
|
|
7
|
+
"rootDir": "src",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"declaration": true,
|
|
14
|
+
"declarationMap": true,
|
|
15
|
+
"sourceMap": true
|
|
16
|
+
},
|
|
17
|
+
"include": ["src/**/*"],
|
|
18
|
+
"exclude": ["node_modules", "dist", "tests"]
|
|
19
|
+
}
|