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.
Files changed (90) hide show
  1. package/dist/cli/nlm.js +221 -32
  2. package/dist/cli/nlm.js.map +1 -1
  3. package/dist/core/adapters/cursor.d.ts +45 -0
  4. package/dist/core/adapters/cursor.js +397 -0
  5. package/dist/core/adapters/cursor.js.map +1 -0
  6. package/dist/core/adapters/from-source.js +10 -0
  7. package/dist/core/adapters/from-source.js.map +1 -1
  8. package/dist/core/adapters/windsurf.d.ts +44 -0
  9. package/dist/core/adapters/windsurf.js +299 -0
  10. package/dist/core/adapters/windsurf.js.map +1 -0
  11. package/dist/core/hook/claude-settings.d.ts +12 -5
  12. package/dist/core/hook/claude-settings.js +21 -6
  13. package/dist/core/hook/claude-settings.js.map +1 -1
  14. package/dist/core/sources/source-registry.d.ts +1 -1
  15. package/dist/core/sources/source-registry.js +18 -0
  16. package/dist/core/sources/source-registry.js.map +1 -1
  17. package/dist/core/storage/sqlite-session-store.d.ts +2 -0
  18. package/dist/core/storage/sqlite-session-store.js +38 -2
  19. package/dist/core/storage/sqlite-session-store.js.map +1 -1
  20. package/dist/hook/hook-auth.d.ts +13 -0
  21. package/dist/hook/hook-auth.js +19 -0
  22. package/dist/hook/hook-auth.js.map +1 -0
  23. package/dist/hook/prompt-recall-hook.js +7 -1
  24. package/dist/hook/prompt-recall-hook.js.map +1 -1
  25. package/dist/hook/session-start-hook.js +4 -1
  26. package/dist/hook/session-start-hook.js.map +1 -1
  27. package/dist/hook/stop-hook.js +4 -1
  28. package/dist/hook/stop-hook.js.map +1 -1
  29. package/dist/http/app.d.ts +2 -0
  30. package/dist/http/app.js +74 -0
  31. package/dist/http/app.js.map +1 -1
  32. package/dist/install/claude-code.js +1 -1
  33. package/dist/install/claude-code.js.map +1 -1
  34. package/dist/install/cursor.d.ts +25 -0
  35. package/dist/install/cursor.js +43 -0
  36. package/dist/install/cursor.js.map +1 -0
  37. package/dist/install/nlm-dir-perms.d.ts +19 -0
  38. package/dist/install/nlm-dir-perms.js +43 -0
  39. package/dist/install/nlm-dir-perms.js.map +1 -0
  40. package/dist/install/ollama.d.ts +18 -1
  41. package/dist/install/ollama.js +62 -7
  42. package/dist/install/ollama.js.map +1 -1
  43. package/dist/install/setup.d.ts +4 -0
  44. package/dist/install/setup.js +141 -18
  45. package/dist/install/setup.js.map +1 -1
  46. package/dist/install/windsurf.d.ts +25 -0
  47. package/dist/install/windsurf.js +43 -0
  48. package/dist/install/windsurf.js.map +1 -0
  49. package/dist/shared/types.d.ts +4 -0
  50. package/dist/ui/assets/{index-BA6IpU8g.css → index-C8cpwbYJ.css} +1 -1
  51. package/dist/ui/assets/index-CB50QnL-.js +69 -0
  52. package/dist/ui/index.html +2 -2
  53. package/logs/CHANGELOG/CHANGELOG-2026.md +186 -0
  54. package/logs/CHANGELOG/CHANGELOG.md +107 -235
  55. package/migrations/014_sources_cursor.sql +30 -0
  56. package/migrations/015_sources_windsurf.sql +30 -0
  57. package/package.json +1 -1
  58. package/plugin/scripts/prompt-recall-hook.mjs +55 -4
  59. package/plugin/scripts/stop-hook.mjs +57 -6
  60. package/src/cli/nlm.ts +224 -31
  61. package/src/core/adapters/cursor.ts +486 -0
  62. package/src/core/adapters/from-source.ts +10 -0
  63. package/src/core/adapters/windsurf.ts +386 -0
  64. package/src/core/hook/claude-settings.ts +30 -9
  65. package/src/core/sources/source-registry.ts +19 -1
  66. package/src/core/storage/sqlite-session-store.ts +46 -1
  67. package/src/hook/hook-auth.ts +18 -0
  68. package/src/hook/prompt-recall-hook.ts +7 -1
  69. package/src/hook/session-start-hook.ts +4 -1
  70. package/src/hook/stop-hook.ts +4 -1
  71. package/src/http/app.ts +78 -0
  72. package/src/install/claude-code.ts +1 -1
  73. package/src/install/cursor.ts +68 -0
  74. package/src/install/nlm-dir-perms.ts +55 -0
  75. package/src/install/ollama.ts +80 -7
  76. package/src/install/setup.ts +138 -17
  77. package/src/install/windsurf.ts +68 -0
  78. package/src/shared/types.ts +4 -0
  79. package/src/ui/components/SessionDrawer.tsx +97 -34
  80. package/src/ui/pages/River.tsx +90 -44
  81. package/src/ui/pages/Search.tsx +357 -64
  82. package/src/ui/pages/Thread.tsx +267 -56
  83. package/src/ui/styles.css +129 -5
  84. package/tests/integration/getbyids-sqlite.test.ts +40 -0
  85. package/tests/integration/hook-claude-settings.test.ts +14 -1
  86. package/tests/integration/mcp.test.ts +12 -0
  87. package/tests/integration/source-registry.test.ts +5 -3
  88. package/tests/unit/core/adapters/cursor.test.ts +485 -0
  89. package/tests/unit/core/adapters/windsurf.test.ts +416 -0
  90. package/dist/ui/assets/index-B_qIVV0k.js +0 -69
@@ -0,0 +1,416 @@
1
+ /**
2
+ * WindsurfAdapter unit tests.
3
+ *
4
+ * Each test builds a fake Windsurf workspaceStorage directory tree with
5
+ * in-memory SQLite DBs written to temp files so the adapter can open them
6
+ * in readonly mode.
7
+ */
8
+
9
+ import { mkdirSync, mkdtempSync, rmSync } from "node:fs";
10
+ import { tmpdir } from "node:os";
11
+ import { join } from "node:path";
12
+ import Database from "better-sqlite3";
13
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
14
+ import { WindsurfAdapter } from "../../../../src/core/adapters/windsurf.js";
15
+
16
+ // ── Schema helpers ────────────────────────────────────────────────────────────
17
+
18
+ const CHAT_KEY = "workbench.panel.aichat.view.aichat.chatdata";
19
+
20
+ function createWorkspaceDb(dbPath: string): Database.Database {
21
+ const db = new Database(dbPath);
22
+ db.exec(`
23
+ CREATE TABLE IF NOT EXISTS ItemTable (
24
+ key TEXT PRIMARY KEY,
25
+ value TEXT
26
+ );
27
+ `);
28
+ return db;
29
+ }
30
+
31
+ interface Bubble {
32
+ type: "user" | "ai";
33
+ text?: string;
34
+ rawText?: string;
35
+ }
36
+
37
+ interface Tab {
38
+ tabId: string;
39
+ chatTitle?: string;
40
+ lastSendTime?: number;
41
+ bubbles?: Bubble[];
42
+ }
43
+
44
+ function writeChatData(db: Database.Database, tabs: Tab[]): void {
45
+ db.prepare(`INSERT OR REPLACE INTO ItemTable (key, value) VALUES (?, ?)`).run(
46
+ CHAT_KEY,
47
+ JSON.stringify({ tabs }),
48
+ );
49
+ }
50
+
51
+ // ── Fixtures ──────────────────────────────────────────────────────────────────
52
+
53
+ let tmp: string;
54
+ let userDir: string;
55
+ let wsStorageDir: string;
56
+ let adapter: WindsurfAdapter;
57
+
58
+ beforeEach(() => {
59
+ tmp = mkdtempSync(join(tmpdir(), "nlm-windsurf-"));
60
+ userDir = join(tmp, "Windsurf", "User");
61
+ wsStorageDir = join(userDir, "workspaceStorage");
62
+ mkdirSync(wsStorageDir, { recursive: true });
63
+ adapter = new WindsurfAdapter({ userDir });
64
+ });
65
+
66
+ afterEach(() => {
67
+ rmSync(tmp, { recursive: true, force: true });
68
+ });
69
+
70
+ function addWorkspace(name: string, tabs: Tab[]): string {
71
+ const wsDir = join(wsStorageDir, name);
72
+ mkdirSync(wsDir, { recursive: true });
73
+ const dbPath = join(wsDir, "state.vscdb");
74
+ const db = createWorkspaceDb(dbPath);
75
+ writeChatData(db, tabs);
76
+ db.close();
77
+ return dbPath;
78
+ }
79
+
80
+ // ── detect() ─────────────────────────────────────────────────────────────────
81
+
82
+ describe("detect()", () => {
83
+ it("returns enabled when userDir exists", () => {
84
+ const result = adapter.detect();
85
+ expect(result.enabled).toBe(true);
86
+ expect(result.path).toBe(userDir);
87
+ expect(result.hint).toBeNull();
88
+ });
89
+
90
+ it("returns disabled when userDir is absent", () => {
91
+ const noDir = new WindsurfAdapter({ userDir: join(tmp, "nonexistent") });
92
+ const result = noDir.detect();
93
+ expect(result.enabled).toBe(false);
94
+ expect(result.path).toBeNull();
95
+ expect(result.hint).toMatch(/Windsurf/);
96
+ });
97
+ });
98
+
99
+ // ── discover() ───────────────────────────────────────────────────────────────
100
+
101
+ describe("discover()", () => {
102
+ it("returns empty array when workspaceStorage has no DBs", async () => {
103
+ expect(await adapter.discover()).toEqual([]);
104
+ });
105
+
106
+ it("returns prefixed tabIds across workspace DBs", async () => {
107
+ addWorkspace("ws1", [
108
+ { tabId: "tab-aaa", bubbles: [{ type: "user", text: "Hello" }] },
109
+ ]);
110
+ addWorkspace("ws2", [
111
+ { tabId: "tab-bbb", bubbles: [{ type: "user", text: "Hi" }] },
112
+ { tabId: "tab-ccc", bubbles: [{ type: "ai", text: "Bye" }] },
113
+ ]);
114
+
115
+ const ids = await adapter.discover();
116
+ expect(ids.sort()).toEqual(["ws_tab-aaa", "ws_tab-bbb", "ws_tab-ccc"].sort());
117
+ });
118
+
119
+ it("skips tabs with no bubbles", async () => {
120
+ addWorkspace("ws1", [
121
+ { tabId: "empty-tab", bubbles: [] },
122
+ { tabId: "good-tab", bubbles: [{ type: "user", text: "Hello" }] },
123
+ ]);
124
+
125
+ const ids = await adapter.discover();
126
+ expect(ids).toEqual(["ws_good-tab"]);
127
+ });
128
+
129
+ it("deduplicates tabIds appearing in multiple workspaces", async () => {
130
+ // Edge case: same tab ID in two workspace DBs (migration artifact)
131
+ addWorkspace("ws1", [{ tabId: "dup-tab", bubbles: [{ type: "user", text: "A" }] }]);
132
+ addWorkspace("ws2", [{ tabId: "dup-tab", bubbles: [{ type: "user", text: "B" }] }]);
133
+
134
+ const ids = await adapter.discover();
135
+ expect(ids.filter((id) => id === "ws_dup-tab").length).toBe(1);
136
+ });
137
+
138
+ it("filters by since using lastSendTime", async () => {
139
+ const old = Date.now() - 10 * 24 * 3600_000;
140
+ const recent = Date.now();
141
+ addWorkspace("ws1", [
142
+ { tabId: "old-tab", lastSendTime: old, bubbles: [{ type: "user", text: "Old" }] },
143
+ { tabId: "new-tab", lastSendTime: recent, bubbles: [{ type: "user", text: "New" }] },
144
+ ]);
145
+
146
+ const cutoff = new Date(Date.now() - 5 * 24 * 3600_000);
147
+ const ids = await adapter.discover({ since: cutoff });
148
+ expect(ids).toEqual(["ws_new-tab"]);
149
+ });
150
+
151
+ it("includes tab with lastSendTime=0 even when since is set (zero means unknown age)", async () => {
152
+ addWorkspace("ws1", [
153
+ { tabId: "zero-ts-tab", lastSendTime: 0, bubbles: [{ type: "user", text: "Hi" }] },
154
+ ]);
155
+
156
+ const cutoff = new Date(); // very recent cutoff that would exclude everything with a real ts
157
+ const ids = await adapter.discover({ since: cutoff });
158
+ expect(ids).toContain("ws_zero-ts-tab");
159
+ });
160
+ });
161
+
162
+ // ── parseSession() ────────────────────────────────────────────────────────────
163
+
164
+ describe("parseSession()", () => {
165
+ it("returns null for unknown tabId", async () => {
166
+ addWorkspace("ws1", [{ tabId: "real-tab", bubbles: [{ type: "user", text: "Hello" }] }]);
167
+ expect(await adapter.parseSession("ghost-tab")).toBeNull();
168
+ });
169
+
170
+ it("returns null for tab with no usable bubbles", async () => {
171
+ addWorkspace("ws1", [{ tabId: "empty-tab", bubbles: [] }]);
172
+ expect(await adapter.parseSession("empty-tab")).toBeNull();
173
+ });
174
+
175
+ it("extracts user and assistant turns", async () => {
176
+ addWorkspace("ws1", [
177
+ {
178
+ tabId: "chat-tab",
179
+ chatTitle: "My chat",
180
+ bubbles: [
181
+ { type: "user", text: "Hello AI" },
182
+ { type: "ai", rawText: "Hi human" },
183
+ ],
184
+ },
185
+ ]);
186
+
187
+ const chunk = await adapter.parseSession("chat-tab");
188
+ expect(chunk).not.toBeNull();
189
+ expect(chunk!.turnCount).toBe(2);
190
+ expect(chunk!.text).toContain("user: Hello AI");
191
+ expect(chunk!.text).toContain("assistant: Hi human");
192
+ });
193
+
194
+ it("prefers rawText over text for bubble content", async () => {
195
+ addWorkspace("ws1", [
196
+ {
197
+ tabId: "rawtext-tab",
198
+ bubbles: [
199
+ { type: "user", rawText: "Raw question", text: "text version" },
200
+ ],
201
+ },
202
+ ]);
203
+
204
+ const chunk = await adapter.parseSession("rawtext-tab");
205
+ expect(chunk!.text).toContain("Raw question");
206
+ expect(chunk!.text).not.toContain("text version");
207
+ });
208
+
209
+ it("uses chatTitle as label", async () => {
210
+ addWorkspace("ws1", [
211
+ {
212
+ tabId: "titled-tab",
213
+ chatTitle: "Refactoring session",
214
+ bubbles: [{ type: "user", text: "Let's refactor" }],
215
+ },
216
+ ]);
217
+
218
+ const chunk = await adapter.parseSession("titled-tab");
219
+ expect(chunk!.label).toBe("Refactoring session");
220
+ });
221
+
222
+ it("falls back to first user turn as label when chatTitle is absent", async () => {
223
+ addWorkspace("ws1", [
224
+ {
225
+ tabId: "notitle-tab",
226
+ bubbles: [{ type: "user", text: "What is a monad?" }],
227
+ },
228
+ ]);
229
+
230
+ const chunk = await adapter.parseSession("notitle-tab");
231
+ expect(chunk!.label).toBe("What is a monad?");
232
+ });
233
+
234
+ it("sets correct id prefix and runtimeSessionId", async () => {
235
+ addWorkspace("ws1", [
236
+ { tabId: "id-check", bubbles: [{ type: "user", text: "Hello" }] },
237
+ ]);
238
+
239
+ const chunk = await adapter.parseSession("id-check");
240
+ expect(chunk!.runtimeSessionId).toBe("id-check");
241
+ expect(chunk!.id).toMatch(/^ws_/);
242
+ });
243
+
244
+ it("sets sourcePath to dbPath::tabId", async () => {
245
+ const dbPath = addWorkspace("ws1", [
246
+ { tabId: "path-tab", bubbles: [{ type: "user", text: "Hello" }] },
247
+ ]);
248
+
249
+ const chunk = await adapter.parseSession("path-tab");
250
+ expect(chunk!.sourcePath).toBe(`${dbPath}::path-tab`);
251
+ });
252
+
253
+ it("finds tab in second workspace when not in first", async () => {
254
+ addWorkspace("ws1", [{ tabId: "tab-ws1", bubbles: [{ type: "user", text: "In ws1" }] }]);
255
+ addWorkspace("ws2", [{ tabId: "tab-ws2", bubbles: [{ type: "user", text: "In ws2" }] }]);
256
+
257
+ const chunk = await adapter.parseSession("tab-ws2");
258
+ expect(chunk).not.toBeNull();
259
+ expect(chunk!.text).toContain("In ws2");
260
+ });
261
+
262
+ it("skips bubbles with empty text", async () => {
263
+ addWorkspace("ws1", [
264
+ {
265
+ tabId: "sparse-tab",
266
+ bubbles: [
267
+ { type: "user", text: "" },
268
+ { type: "user", text: "Real question" },
269
+ { type: "ai", text: "Real answer" },
270
+ ],
271
+ },
272
+ ]);
273
+
274
+ const chunk = await adapter.parseSession("sparse-tab");
275
+ expect(chunk!.turnCount).toBe(2);
276
+ });
277
+
278
+ it("populates byteRange[1] equal to transcript byte length", async () => {
279
+ addWorkspace("ws1", [
280
+ {
281
+ tabId: "bytes-tab",
282
+ bubbles: [
283
+ { type: "user", text: "Hello" },
284
+ { type: "ai", text: "Hi" },
285
+ ],
286
+ },
287
+ ]);
288
+
289
+ const chunk = await adapter.parseSession("bytes-tab");
290
+ expect(chunk!.byteRange[1]).toBe(Buffer.byteLength(chunk!.text, "utf8"));
291
+ });
292
+ });
293
+
294
+ // ── global DB agent sessions (wsg_) ──────────────────────────────────────────
295
+
296
+ describe("global DB agent sessions (wsg_)", () => {
297
+ let globalDb: Database.Database;
298
+ let globalDbPath: string;
299
+
300
+ beforeEach(() => {
301
+ const globalDir = join(userDir, "globalStorage");
302
+ mkdirSync(globalDir, { recursive: true });
303
+ globalDbPath = join(globalDir, "state.vscdb");
304
+ globalDb = new Database(globalDbPath);
305
+ });
306
+
307
+ afterEach(() => {
308
+ try { globalDb.close(); } catch { /* already closed */ }
309
+ });
310
+
311
+ function addCursorDiskKVSession(
312
+ composerId: string,
313
+ opts: { name?: string; createdAt?: string; lastUpdatedAt?: string; conversation?: Array<{ type?: number; role?: string; text: string }> } = {},
314
+ ): void {
315
+ globalDb.exec(`CREATE TABLE IF NOT EXISTS cursorDiskKV (key TEXT PRIMARY KEY, value TEXT);`);
316
+ const data = {
317
+ composerId,
318
+ name: opts.name,
319
+ createdAt: opts.createdAt ?? new Date(Date.now() - 3600_000).toISOString(),
320
+ lastUpdatedAt: opts.lastUpdatedAt ?? new Date().toISOString(),
321
+ conversation: opts.conversation ?? [],
322
+ };
323
+ globalDb.prepare(`INSERT INTO cursorDiskKV (key, value) VALUES (?, ?)`).run(
324
+ `composerData:${composerId}`,
325
+ JSON.stringify(data),
326
+ );
327
+ globalDb.close();
328
+ }
329
+
330
+ function addItemTableSession(
331
+ composerId: string,
332
+ opts: { name?: string; conversation?: Array<{ type?: number; role?: string; text: string }> } = {},
333
+ ): void {
334
+ globalDb.exec(`CREATE TABLE IF NOT EXISTS ItemTable (key TEXT PRIMARY KEY, value TEXT);`);
335
+ const data = {
336
+ composerId,
337
+ name: opts.name,
338
+ conversation: opts.conversation ?? [],
339
+ };
340
+ // Use an agent-style key so the fallback LIKE query matches
341
+ globalDb.prepare(`INSERT INTO ItemTable (key, value) VALUES (?, ?)`).run(
342
+ `cascade:${composerId}`,
343
+ JSON.stringify(data),
344
+ );
345
+ globalDb.close();
346
+ }
347
+
348
+ it("discover() returns wsg_ ids from cursorDiskKV global sessions", async () => {
349
+ addCursorDiskKVSession("agent-aaa", {
350
+ conversation: [{ type: 1, text: "Hello" }],
351
+ });
352
+
353
+ const ids = await adapter.discover();
354
+ expect(ids).toContain("wsg_agent-aaa");
355
+ });
356
+
357
+ it("discover() returns wsg_ ids from ItemTable fallback", async () => {
358
+ addItemTableSession("flow-bbb", {
359
+ conversation: [{ role: "user", text: "Hi" }],
360
+ });
361
+
362
+ const ids = await adapter.discover();
363
+ expect(ids).toContain("wsg_flow-bbb");
364
+ });
365
+
366
+ it("parseSession(wsg_<id>) extracts turns via cursorDiskKV", async () => {
367
+ addCursorDiskKVSession("agent-parse", {
368
+ name: "My flow",
369
+ conversation: [
370
+ { type: 1, text: "Build a widget" },
371
+ { type: 2, text: "Built!" },
372
+ ],
373
+ });
374
+
375
+ const chunk = await adapter.parseSession("wsg_agent-parse");
376
+ expect(chunk).not.toBeNull();
377
+ expect(chunk!.turnCount).toBe(2);
378
+ expect(chunk!.text).toContain("user: Build a widget");
379
+ expect(chunk!.text).toContain("assistant: Built!");
380
+ expect(chunk!.label).toBe("My flow");
381
+ expect(chunk!.id).toMatch(/^wsg_/);
382
+ expect(chunk!.runtimeSessionId).toBe("agent-parse");
383
+ });
384
+
385
+ it("parseSession(wsg_<id>) returns null when conversation is empty", async () => {
386
+ addCursorDiskKVSession("empty-agent", { conversation: [] });
387
+ expect(await adapter.parseSession("wsg_empty-agent")).toBeNull();
388
+ });
389
+
390
+ it("discover() wsg_ filters by since using lastUpdatedAt", async () => {
391
+ const recentDb = new Database(globalDbPath);
392
+ recentDb.exec(`CREATE TABLE IF NOT EXISTS cursorDiskKV (key TEXT PRIMARY KEY, value TEXT);`);
393
+ const old = new Date(Date.now() - 10 * 24 * 3600_000).toISOString();
394
+ const recent = new Date().toISOString();
395
+ const oldData = { composerId: "old-agent", lastUpdatedAt: old, conversation: [{ type: 1, text: "Old" }] };
396
+ const newData = { composerId: "new-agent", lastUpdatedAt: recent, conversation: [{ type: 1, text: "New" }] };
397
+ recentDb.prepare(`INSERT INTO cursorDiskKV (key, value) VALUES (?, ?)`).run("composerData:old-agent", JSON.stringify(oldData));
398
+ recentDb.prepare(`INSERT INTO cursorDiskKV (key, value) VALUES (?, ?)`).run("composerData:new-agent", JSON.stringify(newData));
399
+ recentDb.close();
400
+
401
+ const cutoff = new Date(Date.now() - 5 * 24 * 3600_000);
402
+ const ids = await adapter.discover({ since: cutoff });
403
+ expect(ids).not.toContain("wsg_old-agent");
404
+ expect(ids).toContain("wsg_new-agent");
405
+ });
406
+ });
407
+
408
+ // ── metadata ──────────────────────────────────────────────────────────────────
409
+
410
+ describe("adapter metadata", () => {
411
+ it("has correct name, runtimeVersion, and transcriptKind", () => {
412
+ expect(adapter.name).toBe("windsurf");
413
+ expect(adapter.runtimeVersion).toBe("windsurf/1.0");
414
+ expect(adapter.transcriptKind).toBe("windsurf-sqlite");
415
+ });
416
+ });