nlm-memory 0.4.2 → 0.5.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/dist/cli/nlm.js +221 -32
- package/dist/cli/nlm.js.map +1 -1
- package/dist/core/adapters/cursor.d.ts +45 -0
- package/dist/core/adapters/cursor.js +397 -0
- package/dist/core/adapters/cursor.js.map +1 -0
- package/dist/core/adapters/from-source.js +10 -0
- package/dist/core/adapters/from-source.js.map +1 -1
- package/dist/core/adapters/windsurf.d.ts +44 -0
- package/dist/core/adapters/windsurf.js +299 -0
- package/dist/core/adapters/windsurf.js.map +1 -0
- package/dist/core/hook/claude-settings.d.ts +12 -5
- package/dist/core/hook/claude-settings.js +21 -6
- package/dist/core/hook/claude-settings.js.map +1 -1
- package/dist/core/sources/source-registry.d.ts +1 -1
- package/dist/core/sources/source-registry.js +18 -0
- package/dist/core/sources/source-registry.js.map +1 -1
- package/dist/core/storage/sqlite-session-store.d.ts +2 -0
- package/dist/core/storage/sqlite-session-store.js +38 -2
- package/dist/core/storage/sqlite-session-store.js.map +1 -1
- package/dist/hook/hook-auth.d.ts +13 -0
- package/dist/hook/hook-auth.js +19 -0
- package/dist/hook/hook-auth.js.map +1 -0
- package/dist/hook/prompt-recall-hook.js +7 -1
- package/dist/hook/prompt-recall-hook.js.map +1 -1
- package/dist/hook/session-start-hook.js +4 -1
- package/dist/hook/session-start-hook.js.map +1 -1
- package/dist/hook/stop-hook.js +4 -1
- package/dist/hook/stop-hook.js.map +1 -1
- package/dist/http/app.d.ts +2 -0
- package/dist/http/app.js +74 -0
- package/dist/http/app.js.map +1 -1
- package/dist/install/claude-code.js +1 -1
- package/dist/install/claude-code.js.map +1 -1
- package/dist/install/cursor.d.ts +25 -0
- package/dist/install/cursor.js +43 -0
- package/dist/install/cursor.js.map +1 -0
- package/dist/install/nlm-dir-perms.d.ts +19 -0
- package/dist/install/nlm-dir-perms.js +43 -0
- package/dist/install/nlm-dir-perms.js.map +1 -0
- package/dist/install/ollama.d.ts +18 -1
- package/dist/install/ollama.js +62 -7
- package/dist/install/ollama.js.map +1 -1
- package/dist/install/setup.d.ts +4 -0
- package/dist/install/setup.js +141 -18
- package/dist/install/setup.js.map +1 -1
- package/dist/install/windsurf.d.ts +25 -0
- package/dist/install/windsurf.js +43 -0
- package/dist/install/windsurf.js.map +1 -0
- package/dist/shared/types.d.ts +4 -0
- package/dist/ui/assets/{index-BA6IpU8g.css → index-C8cpwbYJ.css} +1 -1
- package/dist/ui/assets/index-CB50QnL-.js +69 -0
- package/dist/ui/index.html +2 -2
- package/logs/CHANGELOG/CHANGELOG-2026.md +186 -0
- package/logs/CHANGELOG/CHANGELOG.md +107 -235
- package/migrations/014_sources_cursor.sql +30 -0
- package/migrations/015_sources_windsurf.sql +30 -0
- package/package.json +1 -1
- package/plugin/scripts/prompt-recall-hook.mjs +55 -4
- package/plugin/scripts/stop-hook.mjs +57 -6
- package/src/cli/nlm.ts +224 -31
- package/src/core/adapters/cursor.ts +486 -0
- package/src/core/adapters/from-source.ts +10 -0
- package/src/core/adapters/windsurf.ts +386 -0
- package/src/core/hook/claude-settings.ts +30 -9
- package/src/core/sources/source-registry.ts +19 -1
- package/src/core/storage/sqlite-session-store.ts +46 -1
- package/src/hook/hook-auth.ts +18 -0
- package/src/hook/prompt-recall-hook.ts +7 -1
- package/src/hook/session-start-hook.ts +4 -1
- package/src/hook/stop-hook.ts +4 -1
- package/src/http/app.ts +78 -0
- package/src/install/claude-code.ts +1 -1
- package/src/install/cursor.ts +68 -0
- package/src/install/nlm-dir-perms.ts +55 -0
- package/src/install/ollama.ts +80 -7
- package/src/install/setup.ts +138 -17
- package/src/install/windsurf.ts +68 -0
- package/src/shared/types.ts +4 -0
- package/src/ui/components/SessionDrawer.tsx +97 -34
- package/src/ui/pages/River.tsx +90 -44
- package/src/ui/pages/Search.tsx +357 -64
- package/src/ui/pages/Thread.tsx +267 -56
- package/src/ui/styles.css +129 -5
- package/tests/integration/getbyids-sqlite.test.ts +40 -0
- package/tests/integration/hook-claude-settings.test.ts +14 -1
- package/tests/integration/mcp.test.ts +12 -0
- package/tests/integration/source-registry.test.ts +5 -3
- package/tests/unit/core/adapters/cursor.test.ts +485 -0
- package/tests/unit/core/adapters/windsurf.test.ts +416 -0
- package/dist/ui/assets/index-B_qIVV0k.js +0 -69
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CursorAdapter — reads Cursor AI sessions across all three storage formats.
|
|
3
|
+
*
|
|
4
|
+
* ## Storage locations (macOS, Linux analogues use ~/.config/)
|
|
5
|
+
*
|
|
6
|
+
* Global DB ~/Library/Application Support/Cursor/User/globalStorage/state.vscdb
|
|
7
|
+
* Table: cursorDiskKV
|
|
8
|
+
* Keys: composerData:<composerId> — session metadata + conversation
|
|
9
|
+
* bubbleId:<composerId>:<id> — individual messages (separate storage)
|
|
10
|
+
*
|
|
11
|
+
* Workspace DBs ~/Library/.../Cursor/User/workspaceStorage/<hash>/state.vscdb
|
|
12
|
+
* Table: ItemTable
|
|
13
|
+
* Key: composer.composerData — allComposers[] (pre-global-migration)
|
|
14
|
+
* Key: workbench.panel.aichat.view.aichat.chatdata — chat tabs (all versions)
|
|
15
|
+
*
|
|
16
|
+
* ## Session ID prefixes
|
|
17
|
+
*
|
|
18
|
+
* cr_ — global cursorDiskKV composer (current, v1.x+)
|
|
19
|
+
* crw_ — workspace ItemTable composer.composerData (v0.43–v1.x)
|
|
20
|
+
* crc_ — workspace ItemTable chat tab (v0.x–v1.x)
|
|
21
|
+
*
|
|
22
|
+
* ## Options
|
|
23
|
+
*
|
|
24
|
+
* dbPath — path to globalStorage/state.vscdb
|
|
25
|
+
* (workspace DBs are derived from dbPath's parent directory)
|
|
26
|
+
* Env override: NLM_CURSOR_DB_PATH
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
30
|
+
import { homedir } from "node:os";
|
|
31
|
+
import { dirname, join } from "node:path";
|
|
32
|
+
import Database from "better-sqlite3";
|
|
33
|
+
import type {
|
|
34
|
+
DetectionResult,
|
|
35
|
+
DiscoverOptions,
|
|
36
|
+
SessionChunk,
|
|
37
|
+
TranscriptAdapter,
|
|
38
|
+
} from "@ports/transcript-adapter.js";
|
|
39
|
+
import { durationMinutes, normalizeTimestamp, safeSessionId } from "./common.js";
|
|
40
|
+
|
|
41
|
+
export interface CursorAdapterOptions {
|
|
42
|
+
readonly dbPath?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// ── Types ─────────────────────────────────────────────────────────────────────
|
|
46
|
+
|
|
47
|
+
interface KVRow {
|
|
48
|
+
readonly key: string;
|
|
49
|
+
readonly value: string | null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface ItemRow {
|
|
53
|
+
readonly value: string | null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface ComposerMeta {
|
|
57
|
+
readonly composerId?: string;
|
|
58
|
+
readonly name?: string;
|
|
59
|
+
readonly createdAt?: unknown;
|
|
60
|
+
readonly lastUpdatedAt?: unknown;
|
|
61
|
+
readonly conversation?: BubbleData[];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
interface BubbleData {
|
|
65
|
+
readonly type?: number;
|
|
66
|
+
readonly text?: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface ChatTab {
|
|
70
|
+
readonly tabId?: string;
|
|
71
|
+
readonly chatTitle?: string;
|
|
72
|
+
readonly lastSendTime?: number;
|
|
73
|
+
readonly bubbles?: ChatBubble[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
interface ChatBubble {
|
|
77
|
+
readonly type?: "user" | "ai" | string;
|
|
78
|
+
readonly text?: string;
|
|
79
|
+
readonly rawText?: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
type Turn = { role: "user" | "assistant"; text: string };
|
|
83
|
+
|
|
84
|
+
// ── Path helpers ──────────────────────────────────────────────────────────────
|
|
85
|
+
|
|
86
|
+
export function defaultDbPath(): string {
|
|
87
|
+
if (process.env["NLM_CURSOR_DB_PATH"]) return process.env["NLM_CURSOR_DB_PATH"];
|
|
88
|
+
const home = homedir();
|
|
89
|
+
if (process.platform === "darwin") {
|
|
90
|
+
return join(home, "Library/Application Support/Cursor/User/globalStorage/state.vscdb");
|
|
91
|
+
}
|
|
92
|
+
return join(home, ".config/Cursor/User/globalStorage/state.vscdb");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function workspaceStorageDir(globalDbPath: string): string {
|
|
96
|
+
// globalStorage/state.vscdb → User/ → User/workspaceStorage/
|
|
97
|
+
return join(dirname(dirname(globalDbPath)), "workspaceStorage");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function listWorkspaceDbs(globalDbPath: string): string[] {
|
|
101
|
+
const wsDir = workspaceStorageDir(globalDbPath);
|
|
102
|
+
if (!existsSync(wsDir)) return [];
|
|
103
|
+
try {
|
|
104
|
+
return readdirSync(wsDir, { withFileTypes: true })
|
|
105
|
+
.filter((e) => e.isDirectory())
|
|
106
|
+
.map((e) => join(wsDir, e.name, "state.vscdb"))
|
|
107
|
+
.filter((p) => existsSync(p));
|
|
108
|
+
} catch {
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// ── Turn extraction ───────────────────────────────────────────────────────────
|
|
114
|
+
|
|
115
|
+
function extractComposerTurns(bubbles: BubbleData[]): Turn[] {
|
|
116
|
+
const turns: Turn[] = [];
|
|
117
|
+
for (const b of bubbles) {
|
|
118
|
+
const type = b.type;
|
|
119
|
+
if (type !== 1 && type !== 2) continue;
|
|
120
|
+
const text = (b.text ?? "").trim();
|
|
121
|
+
if (!text) continue;
|
|
122
|
+
turns.push({ role: type === 1 ? "user" : "assistant", text });
|
|
123
|
+
}
|
|
124
|
+
return turns;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function extractChatTurns(bubbles: ChatBubble[]): Turn[] {
|
|
128
|
+
const turns: Turn[] = [];
|
|
129
|
+
for (const b of bubbles) {
|
|
130
|
+
const text = (b.rawText ?? b.text ?? "").trim();
|
|
131
|
+
if (!text) continue;
|
|
132
|
+
turns.push({ role: b.type === "user" ? "user" : "assistant", text });
|
|
133
|
+
}
|
|
134
|
+
return turns;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function extractSeparateBubbles(db: Database.Database, composerId: string): Turn[] {
|
|
138
|
+
const rows = db
|
|
139
|
+
.prepare<[string], KVRow>(
|
|
140
|
+
`SELECT key, value FROM cursorDiskKV WHERE key LIKE ? ORDER BY rowid ASC`,
|
|
141
|
+
)
|
|
142
|
+
.all(`bubbleId:${composerId}:%`);
|
|
143
|
+
const turns: Turn[] = [];
|
|
144
|
+
for (const row of rows) {
|
|
145
|
+
if (!row.value) continue;
|
|
146
|
+
try {
|
|
147
|
+
const b = JSON.parse(row.value) as BubbleData;
|
|
148
|
+
const type = b.type;
|
|
149
|
+
if (type !== 1 && type !== 2) continue;
|
|
150
|
+
const text = (b.text ?? "").trim();
|
|
151
|
+
if (text) turns.push({ role: type === 1 ? "user" : "assistant", text });
|
|
152
|
+
} catch { /* skip malformed */ }
|
|
153
|
+
}
|
|
154
|
+
return turns;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function provisionalLabel(turns: ReadonlyArray<Turn>): string {
|
|
158
|
+
for (const t of turns) {
|
|
159
|
+
if (t.role !== "user") continue;
|
|
160
|
+
const first = t.text.split("\n", 1)[0]?.trim();
|
|
161
|
+
if (first) return first.slice(0, 80);
|
|
162
|
+
}
|
|
163
|
+
return "Untitled session";
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function buildChunk(
|
|
167
|
+
id: string,
|
|
168
|
+
runtime: string,
|
|
169
|
+
runtimeSessionId: string,
|
|
170
|
+
sourcePath: string,
|
|
171
|
+
turns: Turn[],
|
|
172
|
+
startedAt: string,
|
|
173
|
+
endedAt: string,
|
|
174
|
+
label: string,
|
|
175
|
+
): SessionChunk {
|
|
176
|
+
const text = turns.map((t) => `${t.role}: ${t.text}`).join("\n\n");
|
|
177
|
+
return {
|
|
178
|
+
id,
|
|
179
|
+
runtime,
|
|
180
|
+
runtimeSessionId,
|
|
181
|
+
sourcePath,
|
|
182
|
+
startedAt,
|
|
183
|
+
endedAt,
|
|
184
|
+
durationMin: durationMinutes(startedAt, endedAt),
|
|
185
|
+
turnCount: turns.length,
|
|
186
|
+
byteRange: [0, Buffer.byteLength(text, "utf8")],
|
|
187
|
+
projectDir: "",
|
|
188
|
+
gitBranch: "",
|
|
189
|
+
text,
|
|
190
|
+
label,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// ── Workspace parsers ─────────────────────────────────────────────────────────
|
|
195
|
+
|
|
196
|
+
/** Workspace ItemTable: composer.composerData → allComposers[]. */
|
|
197
|
+
function discoverWorkspaceComposers(db: Database.Database): string[] {
|
|
198
|
+
try {
|
|
199
|
+
const row = db
|
|
200
|
+
.prepare<[string], ItemRow>(`SELECT value FROM ItemTable WHERE key = ?`)
|
|
201
|
+
.get("composer.composerData");
|
|
202
|
+
if (!row?.value) return [];
|
|
203
|
+
const data = JSON.parse(row.value) as { allComposers?: ComposerMeta[] };
|
|
204
|
+
const composers = data.allComposers ?? [];
|
|
205
|
+
return composers
|
|
206
|
+
.filter((c) => c.composerId)
|
|
207
|
+
.map((c) => `crw_${c.composerId}`);
|
|
208
|
+
} catch {
|
|
209
|
+
return [];
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** Workspace ItemTable: workbench.panel.aichat.view.aichat.chatdata → tabs[]. */
|
|
214
|
+
function discoverWorkspaceChatTabs(db: Database.Database, since?: Date): string[] {
|
|
215
|
+
try {
|
|
216
|
+
const row = db
|
|
217
|
+
.prepare<[string], ItemRow>(
|
|
218
|
+
`SELECT value FROM ItemTable WHERE key = ?`,
|
|
219
|
+
)
|
|
220
|
+
.get("workbench.panel.aichat.view.aichat.chatdata");
|
|
221
|
+
if (!row?.value) return [];
|
|
222
|
+
const data = JSON.parse(row.value) as { tabs?: ChatTab[] };
|
|
223
|
+
const tabs = data.tabs ?? [];
|
|
224
|
+
const cutoff = since?.getTime();
|
|
225
|
+
return tabs
|
|
226
|
+
.filter((t) => {
|
|
227
|
+
if (!t.tabId) return false;
|
|
228
|
+
if (!(t.bubbles && t.bubbles.length > 0)) return false;
|
|
229
|
+
if (cutoff !== undefined) {
|
|
230
|
+
const ts = t.lastSendTime;
|
|
231
|
+
// Only skip if we have a real non-zero timestamp that's before the cutoff
|
|
232
|
+
if (ts !== undefined && ts > 0 && ts < cutoff) return false;
|
|
233
|
+
}
|
|
234
|
+
return true;
|
|
235
|
+
})
|
|
236
|
+
.map((t) => `crc_${t.tabId}`);
|
|
237
|
+
} catch {
|
|
238
|
+
return [];
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function parseWorkspaceComposer(
|
|
243
|
+
db: Database.Database,
|
|
244
|
+
composerId: string,
|
|
245
|
+
dbPath: string,
|
|
246
|
+
): SessionChunk | null {
|
|
247
|
+
try {
|
|
248
|
+
const row = db
|
|
249
|
+
.prepare<[string], ItemRow>(`SELECT value FROM ItemTable WHERE key = ?`)
|
|
250
|
+
.get("composer.composerData");
|
|
251
|
+
if (!row?.value) return null;
|
|
252
|
+
const data = JSON.parse(row.value) as { allComposers?: ComposerMeta[] };
|
|
253
|
+
const meta = (data.allComposers ?? []).find((c) => c.composerId === composerId);
|
|
254
|
+
if (!meta) return null;
|
|
255
|
+
|
|
256
|
+
const inlineTurns = extractComposerTurns(meta.conversation ?? []);
|
|
257
|
+
if (inlineTurns.length === 0) return null;
|
|
258
|
+
|
|
259
|
+
const startedAt = normalizeTimestamp(meta.createdAt ?? meta.lastUpdatedAt ?? "");
|
|
260
|
+
const endedAt = normalizeTimestamp(meta.lastUpdatedAt ?? meta.createdAt ?? "");
|
|
261
|
+
const label = meta.name?.trim() ? meta.name.trim().slice(0, 80) : provisionalLabel(inlineTurns);
|
|
262
|
+
|
|
263
|
+
return buildChunk(
|
|
264
|
+
safeSessionId("crw", composerId),
|
|
265
|
+
"cursor/1.0",
|
|
266
|
+
composerId,
|
|
267
|
+
`${dbPath}::composer:${composerId}`,
|
|
268
|
+
inlineTurns,
|
|
269
|
+
startedAt,
|
|
270
|
+
endedAt,
|
|
271
|
+
label,
|
|
272
|
+
);
|
|
273
|
+
} catch {
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function parseWorkspaceChatTab(
|
|
279
|
+
db: Database.Database,
|
|
280
|
+
tabId: string,
|
|
281
|
+
dbPath: string,
|
|
282
|
+
): SessionChunk | null {
|
|
283
|
+
try {
|
|
284
|
+
const row = db
|
|
285
|
+
.prepare<[string], ItemRow>(
|
|
286
|
+
`SELECT value FROM ItemTable WHERE key = ?`,
|
|
287
|
+
)
|
|
288
|
+
.get("workbench.panel.aichat.view.aichat.chatdata");
|
|
289
|
+
if (!row?.value) return null;
|
|
290
|
+
const data = JSON.parse(row.value) as { tabs?: ChatTab[] };
|
|
291
|
+
const tab = (data.tabs ?? []).find((t) => t.tabId === tabId);
|
|
292
|
+
if (!tab) return null;
|
|
293
|
+
|
|
294
|
+
const turns = extractChatTurns(tab.bubbles ?? []);
|
|
295
|
+
if (turns.length === 0) return null;
|
|
296
|
+
|
|
297
|
+
const endedAtMs = tab.lastSendTime ?? 0;
|
|
298
|
+
const endedAt = endedAtMs > 0 ? new Date(endedAtMs).toISOString() : "";
|
|
299
|
+
const label = tab.chatTitle?.trim()
|
|
300
|
+
? tab.chatTitle.trim().slice(0, 80)
|
|
301
|
+
: provisionalLabel(turns);
|
|
302
|
+
|
|
303
|
+
return buildChunk(
|
|
304
|
+
safeSessionId("crc", tabId),
|
|
305
|
+
"cursor/1.0",
|
|
306
|
+
tabId,
|
|
307
|
+
`${dbPath}::chat:${tabId}`,
|
|
308
|
+
turns,
|
|
309
|
+
endedAt, // no creation timestamp; use endedAt for both
|
|
310
|
+
endedAt,
|
|
311
|
+
label,
|
|
312
|
+
);
|
|
313
|
+
} catch {
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// ── Adapter ───────────────────────────────────────────────────────────────────
|
|
319
|
+
|
|
320
|
+
export class CursorAdapter implements TranscriptAdapter {
|
|
321
|
+
readonly name = "cursor";
|
|
322
|
+
readonly runtimeVersion = "cursor/1.0";
|
|
323
|
+
readonly transcriptKind = "cursor-sqlite";
|
|
324
|
+
|
|
325
|
+
private readonly dbPath: string;
|
|
326
|
+
|
|
327
|
+
constructor(opts: CursorAdapterOptions = {}) {
|
|
328
|
+
this.dbPath = opts.dbPath ?? defaultDbPath();
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
detect(): DetectionResult {
|
|
332
|
+
if (existsSync(this.dbPath)) {
|
|
333
|
+
return { adapterName: this.name, enabled: true, path: this.dbPath, hint: null };
|
|
334
|
+
}
|
|
335
|
+
return {
|
|
336
|
+
adapterName: this.name,
|
|
337
|
+
enabled: false,
|
|
338
|
+
path: null,
|
|
339
|
+
hint: "Cursor global DB not found — install Cursor or set NLM_CURSOR_DB_PATH.",
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
async discover(options?: DiscoverOptions): Promise<ReadonlyArray<string>> {
|
|
344
|
+
const ids: string[] = [];
|
|
345
|
+
const seen = new Set<string>();
|
|
346
|
+
|
|
347
|
+
const add = (id: string) => { if (!seen.has(id)) { seen.add(id); ids.push(id); } };
|
|
348
|
+
|
|
349
|
+
// ── Global DB (current format, v1.x+) ─────────────────────────────────
|
|
350
|
+
if (existsSync(this.dbPath)) {
|
|
351
|
+
let db: Database.Database | undefined;
|
|
352
|
+
try {
|
|
353
|
+
db = new Database(this.dbPath, { readonly: true });
|
|
354
|
+
const hasKV = db
|
|
355
|
+
.prepare<[], { name: string }>(`SELECT name FROM sqlite_master WHERE type='table' AND name='cursorDiskKV'`)
|
|
356
|
+
.get();
|
|
357
|
+
|
|
358
|
+
if (hasKV) {
|
|
359
|
+
const rows = db
|
|
360
|
+
.prepare<[string], KVRow>(
|
|
361
|
+
`SELECT key, value FROM cursorDiskKV WHERE key LIKE ? ORDER BY rowid ASC`,
|
|
362
|
+
)
|
|
363
|
+
.all("composerData:%");
|
|
364
|
+
|
|
365
|
+
const cutoff = options?.since?.getTime();
|
|
366
|
+
for (const row of rows) {
|
|
367
|
+
if (!row.value) continue;
|
|
368
|
+
try {
|
|
369
|
+
const meta = JSON.parse(row.value) as ComposerMeta;
|
|
370
|
+
if (cutoff !== undefined) {
|
|
371
|
+
const ts = meta.lastUpdatedAt ?? meta.createdAt;
|
|
372
|
+
if (ts !== undefined && ts !== null) {
|
|
373
|
+
const normalized = normalizeTimestamp(ts);
|
|
374
|
+
if (normalized && Date.parse(normalized) < cutoff) continue;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
const composerId = meta.composerId ?? row.key.split(":").slice(1).join(":");
|
|
378
|
+
if (composerId) add(`cr_${composerId}`);
|
|
379
|
+
} catch { /* skip */ }
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
} catch { /* skip inaccessible DB */ } finally {
|
|
383
|
+
db?.close();
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// ── Workspace DBs (pre-migration sessions) ────────────────────────────
|
|
388
|
+
for (const wsDbPath of listWorkspaceDbs(this.dbPath)) {
|
|
389
|
+
let db: Database.Database | undefined;
|
|
390
|
+
try {
|
|
391
|
+
db = new Database(wsDbPath, { readonly: true });
|
|
392
|
+
const hasItemTable = db
|
|
393
|
+
.prepare<[], { name: string }>(`SELECT name FROM sqlite_master WHERE type='table' AND name='ItemTable'`)
|
|
394
|
+
.get();
|
|
395
|
+
if (!hasItemTable) continue;
|
|
396
|
+
|
|
397
|
+
for (const id of discoverWorkspaceComposers(db)) add(id);
|
|
398
|
+
for (const id of discoverWorkspaceChatTabs(db, options?.since)) add(id);
|
|
399
|
+
} catch { /* skip */ } finally {
|
|
400
|
+
db?.close();
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
return ids;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
async parseSession(id: string): Promise<SessionChunk | null> {
|
|
408
|
+
if (id.startsWith("crw_")) {
|
|
409
|
+
return this._parseWorkspaceComposer(id.slice("crw_".length));
|
|
410
|
+
}
|
|
411
|
+
if (id.startsWith("crc_")) {
|
|
412
|
+
return this._parseWorkspaceChatTab(id.slice("crc_".length));
|
|
413
|
+
}
|
|
414
|
+
// cr_ prefix (or legacy unprefixed IDs)
|
|
415
|
+
const composerId = id.startsWith("cr_") ? id.slice("cr_".length) : id;
|
|
416
|
+
return this._parseGlobalComposer(composerId);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
private _parseGlobalComposer(composerId: string): SessionChunk | null {
|
|
420
|
+
if (!existsSync(this.dbPath)) return null;
|
|
421
|
+
let db: Database.Database | undefined;
|
|
422
|
+
try {
|
|
423
|
+
db = new Database(this.dbPath, { readonly: true });
|
|
424
|
+
const row = db
|
|
425
|
+
.prepare<[string], KVRow>(`SELECT key, value FROM cursorDiskKV WHERE key = ?`)
|
|
426
|
+
.get(`composerData:${composerId}`);
|
|
427
|
+
if (!row?.value) return null;
|
|
428
|
+
|
|
429
|
+
const meta = JSON.parse(row.value) as ComposerMeta;
|
|
430
|
+
const inlineTurns = extractComposerTurns(meta.conversation ?? []);
|
|
431
|
+
const turns = inlineTurns.length > 0
|
|
432
|
+
? inlineTurns
|
|
433
|
+
: extractSeparateBubbles(db, composerId);
|
|
434
|
+
if (turns.length === 0) return null;
|
|
435
|
+
|
|
436
|
+
const startedAt = normalizeTimestamp(meta.createdAt ?? meta.lastUpdatedAt ?? "");
|
|
437
|
+
const endedAt = normalizeTimestamp(meta.lastUpdatedAt ?? meta.createdAt ?? "");
|
|
438
|
+
const label = meta.name?.trim()
|
|
439
|
+
? meta.name.trim().slice(0, 80)
|
|
440
|
+
: provisionalLabel(turns);
|
|
441
|
+
|
|
442
|
+
return buildChunk(
|
|
443
|
+
safeSessionId("cr", composerId),
|
|
444
|
+
this.runtimeVersion,
|
|
445
|
+
composerId,
|
|
446
|
+
`${this.dbPath}::${composerId}`,
|
|
447
|
+
turns,
|
|
448
|
+
startedAt,
|
|
449
|
+
endedAt,
|
|
450
|
+
label,
|
|
451
|
+
);
|
|
452
|
+
} catch {
|
|
453
|
+
return null;
|
|
454
|
+
} finally {
|
|
455
|
+
db?.close();
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
private _parseWorkspaceComposer(composerId: string): SessionChunk | null {
|
|
460
|
+
for (const wsDbPath of listWorkspaceDbs(this.dbPath)) {
|
|
461
|
+
let db: Database.Database | undefined;
|
|
462
|
+
try {
|
|
463
|
+
db = new Database(wsDbPath, { readonly: true });
|
|
464
|
+
const chunk = parseWorkspaceComposer(db, composerId, wsDbPath);
|
|
465
|
+
if (chunk) return chunk;
|
|
466
|
+
} catch { /* next */ } finally {
|
|
467
|
+
db?.close();
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
return null;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
private _parseWorkspaceChatTab(tabId: string): SessionChunk | null {
|
|
474
|
+
for (const wsDbPath of listWorkspaceDbs(this.dbPath)) {
|
|
475
|
+
let db: Database.Database | undefined;
|
|
476
|
+
try {
|
|
477
|
+
db = new Database(wsDbPath, { readonly: true });
|
|
478
|
+
const chunk = parseWorkspaceChatTab(db, tabId, wsDbPath);
|
|
479
|
+
if (chunk) return chunk;
|
|
480
|
+
} catch { /* next */ } finally {
|
|
481
|
+
db?.close();
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
return null;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
@@ -11,11 +11,13 @@ import type { TranscriptAdapter } from "@ports/transcript-adapter.js";
|
|
|
11
11
|
import type { SourceRow } from "../sources/source-registry.js";
|
|
12
12
|
import { AiderAdapter } from "./aider.js";
|
|
13
13
|
import { ClaudeCodeAdapter } from "./claude-code.js";
|
|
14
|
+
import { CursorAdapter } from "./cursor.js";
|
|
14
15
|
import { HermesAdapter } from "./hermes.js";
|
|
15
16
|
import { HermesAgentAdapter } from "./hermes-agent.js";
|
|
16
17
|
import { JsonlGenericAdapter, type JsonlGenericConfig } from "./jsonl-generic.js";
|
|
17
18
|
import { OpenCodeAdapter } from "./opencode.js";
|
|
18
19
|
import { PiAdapter } from "./pi.js";
|
|
20
|
+
import { WindsurfAdapter } from "./windsurf.js";
|
|
19
21
|
|
|
20
22
|
export function adapterFromSource(source: SourceRow): TranscriptAdapter | null {
|
|
21
23
|
switch (source.kind) {
|
|
@@ -27,6 +29,10 @@ export function adapterFromSource(source: SourceRow): TranscriptAdapter | null {
|
|
|
27
29
|
return source.pathOrUrl
|
|
28
30
|
? new ClaudeCodeAdapter({ projectsPath: source.pathOrUrl })
|
|
29
31
|
: new ClaudeCodeAdapter();
|
|
32
|
+
case "cursor":
|
|
33
|
+
return source.pathOrUrl
|
|
34
|
+
? new CursorAdapter({ dbPath: source.pathOrUrl })
|
|
35
|
+
: new CursorAdapter();
|
|
30
36
|
case "hermes":
|
|
31
37
|
return source.pathOrUrl
|
|
32
38
|
? new HermesAdapter({ sessionsPath: source.pathOrUrl })
|
|
@@ -43,6 +49,10 @@ export function adapterFromSource(source: SourceRow): TranscriptAdapter | null {
|
|
|
43
49
|
return source.pathOrUrl
|
|
44
50
|
? new PiAdapter({ sessionsPath: source.pathOrUrl })
|
|
45
51
|
: new PiAdapter();
|
|
52
|
+
case "windsurf":
|
|
53
|
+
return source.pathOrUrl
|
|
54
|
+
? new WindsurfAdapter({ userDir: source.pathOrUrl })
|
|
55
|
+
: new WindsurfAdapter();
|
|
46
56
|
case "jsonl-generic":
|
|
47
57
|
if (!source.pathOrUrl) return null;
|
|
48
58
|
return new JsonlGenericAdapter({
|