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
|
@@ -107,17 +107,30 @@ describe("claude-settings hook editor", () => {
|
|
|
107
107
|
expect(shEcho(shellQuote(tricky))).toBe(tricky);
|
|
108
108
|
});
|
|
109
109
|
|
|
110
|
-
it("buildHookCommand quotes both paths", () => {
|
|
110
|
+
it("buildHookCommand quotes both paths (POSIX)", () => {
|
|
111
111
|
const cmd = buildHookCommand(
|
|
112
112
|
"/usr/local/bin/node",
|
|
113
113
|
"/Users/echalupa/Documents/Coding Projects/nlm/dist/hook/prompt-recall-hook.js",
|
|
114
114
|
"shadow",
|
|
115
|
+
"darwin",
|
|
115
116
|
);
|
|
116
117
|
expect(cmd).toBe(
|
|
117
118
|
"NLM_HOOK_MODE=shadow '/usr/local/bin/node' '/Users/echalupa/Documents/Coding Projects/nlm/dist/hook/prompt-recall-hook.js'",
|
|
118
119
|
);
|
|
119
120
|
});
|
|
120
121
|
|
|
122
|
+
it("buildHookCommand emits cmd.exe format on Windows", () => {
|
|
123
|
+
const cmd = buildHookCommand(
|
|
124
|
+
"C:\\Program Files\\nodejs\\node.exe",
|
|
125
|
+
"C:\\Users\\Test\\AppData\\Roaming\\npm\\node_modules\\nlm-memory\\dist\\hook\\prompt-recall-hook.js",
|
|
126
|
+
"live",
|
|
127
|
+
"win32",
|
|
128
|
+
);
|
|
129
|
+
expect(cmd).toBe(
|
|
130
|
+
'set NLM_HOOK_MODE=live && "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Test\\AppData\\Roaming\\npm\\node_modules\\nlm-memory\\dist\\hook\\prompt-recall-hook.js"',
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
|
|
121
134
|
it("smokeTestHookCommand reports failure when command exits nonzero", () => {
|
|
122
135
|
const logPath = join(tmp, "hook-log.jsonl");
|
|
123
136
|
const result = smokeTestHookCommand("exit 1", logPath);
|
|
@@ -147,6 +147,18 @@ describe("MCP adapter", () => {
|
|
|
147
147
|
expect(body.entities).toContain("NLM");
|
|
148
148
|
});
|
|
149
149
|
|
|
150
|
+
it("get_session includes supersedence links when an edge exists", async () => {
|
|
151
|
+
store.insertEdgeForTest("sess_a", "sess_b", "supersedes");
|
|
152
|
+
const newer = await getSessionHandler({ recall, store }, { id: "sess_a" });
|
|
153
|
+
const older = await getSessionHandler({ recall, store }, { id: "sess_b" });
|
|
154
|
+
const newerBody = parsePayload(newer) as { supersedes: string[]; supersededBy: string | null };
|
|
155
|
+
const olderBody = parsePayload(older) as { supersedes: string[]; supersededBy: string | null };
|
|
156
|
+
expect(newerBody.supersedes).toEqual(["sess_b"]);
|
|
157
|
+
expect(newerBody.supersededBy).toBeNull();
|
|
158
|
+
expect(olderBody.supersededBy).toBe("sess_a");
|
|
159
|
+
expect(olderBody.supersedes).toEqual([]);
|
|
160
|
+
});
|
|
161
|
+
|
|
150
162
|
it("get_session returns an error tool result on missing id", async () => {
|
|
151
163
|
const result = await getSessionHandler(
|
|
152
164
|
{ recall, store },
|
|
@@ -31,18 +31,20 @@ describe("SourceRegistry", () => {
|
|
|
31
31
|
rmSync(tmp, { recursive: true, force: true });
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
it("starts empty and seeds
|
|
34
|
+
it("starts empty and seeds eight presets", () => {
|
|
35
35
|
expect(registry.list()).toEqual([]);
|
|
36
36
|
registry.seedDefaults();
|
|
37
37
|
const rows = registry.list();
|
|
38
|
-
expect(rows.map((r) => r.kind)).toEqual([
|
|
38
|
+
expect(rows.map((r) => r.kind)).toEqual([
|
|
39
|
+
"claude-code", "hermes", "hermes-agent", "aider", "cursor", "windsurf", "opencode", "pi",
|
|
40
|
+
]);
|
|
39
41
|
expect(rows.every((r) => r.runtimeLabel.endsWith("/1.0"))).toBe(true);
|
|
40
42
|
});
|
|
41
43
|
|
|
42
44
|
it("seedDefaults is idempotent", () => {
|
|
43
45
|
registry.seedDefaults();
|
|
44
46
|
registry.seedDefaults();
|
|
45
|
-
expect(registry.list().length).toBe(
|
|
47
|
+
expect(registry.list().length).toBe(8);
|
|
46
48
|
});
|
|
47
49
|
|
|
48
50
|
it("inserts a custom JSONL source and round-trips parse config", () => {
|
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CursorAdapter unit tests.
|
|
3
|
+
*
|
|
4
|
+
* Each test builds an in-memory SQLite DB seeded with the cursorDiskKV
|
|
5
|
+
* key-value schema Cursor uses, writes it to a temp file so the adapter
|
|
6
|
+
* can open it with better-sqlite3 in readonly mode.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { mkdirSync, mkdtempSync, rmSync } from "node:fs";
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
11
|
+
import { dirname, join } from "node:path";
|
|
12
|
+
import Database from "better-sqlite3";
|
|
13
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
14
|
+
import { CursorAdapter } from "../../../../src/core/adapters/cursor.js";
|
|
15
|
+
|
|
16
|
+
// ── Schema helpers ────────────────────────────────────────────────────────────
|
|
17
|
+
|
|
18
|
+
function createDb(path: string): Database.Database {
|
|
19
|
+
const db = new Database(path);
|
|
20
|
+
db.exec(`
|
|
21
|
+
CREATE TABLE IF NOT EXISTS cursorDiskKV (
|
|
22
|
+
key TEXT PRIMARY KEY,
|
|
23
|
+
value TEXT
|
|
24
|
+
);
|
|
25
|
+
`);
|
|
26
|
+
return db;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function addComposerInline(
|
|
30
|
+
db: Database.Database,
|
|
31
|
+
composerId: string,
|
|
32
|
+
opts: {
|
|
33
|
+
name?: string;
|
|
34
|
+
createdAt?: string;
|
|
35
|
+
lastUpdatedAt?: string;
|
|
36
|
+
conversation?: Array<{ type: number; text: string }>;
|
|
37
|
+
} = {},
|
|
38
|
+
): void {
|
|
39
|
+
const data = {
|
|
40
|
+
composerId,
|
|
41
|
+
name: opts.name ?? "Test session",
|
|
42
|
+
createdAt: opts.createdAt ?? new Date(Date.now() - 3600_000).toISOString(),
|
|
43
|
+
lastUpdatedAt: opts.lastUpdatedAt ?? new Date().toISOString(),
|
|
44
|
+
conversation: opts.conversation ?? [],
|
|
45
|
+
};
|
|
46
|
+
db.prepare(`INSERT INTO cursorDiskKV (key, value) VALUES (?, ?)`).run(
|
|
47
|
+
`composerData:${composerId}`,
|
|
48
|
+
JSON.stringify(data),
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function addBubble(
|
|
53
|
+
db: Database.Database,
|
|
54
|
+
composerId: string,
|
|
55
|
+
bubbleId: string,
|
|
56
|
+
type: 1 | 2,
|
|
57
|
+
text: string,
|
|
58
|
+
): void {
|
|
59
|
+
const data = { type, text };
|
|
60
|
+
db.prepare(`INSERT INTO cursorDiskKV (key, value) VALUES (?, ?)`).run(
|
|
61
|
+
`bubbleId:${composerId}:${bubbleId}`,
|
|
62
|
+
JSON.stringify(data),
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ── Workspace helpers ─────────────────────────────────────────────────────────
|
|
67
|
+
|
|
68
|
+
const CHAT_KEY = "workbench.panel.aichat.view.aichat.chatdata";
|
|
69
|
+
|
|
70
|
+
function createWorkspaceDb(path: string): Database.Database {
|
|
71
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
72
|
+
const db = new Database(path);
|
|
73
|
+
db.exec(`CREATE TABLE IF NOT EXISTS ItemTable (key TEXT PRIMARY KEY, value TEXT);`);
|
|
74
|
+
return db;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function addWorkspaceComposer(
|
|
78
|
+
db: Database.Database,
|
|
79
|
+
composerId: string,
|
|
80
|
+
opts: { name?: string; createdAt?: string; lastUpdatedAt?: string; conversation?: Array<{ type: number; text: string }> } = {},
|
|
81
|
+
): void {
|
|
82
|
+
const allComposers = [{ composerId, name: opts.name ?? "ws composer", createdAt: opts.createdAt, lastUpdatedAt: opts.lastUpdatedAt, conversation: opts.conversation ?? [] }];
|
|
83
|
+
db.prepare(`INSERT OR REPLACE INTO ItemTable (key, value) VALUES (?, ?)`).run(
|
|
84
|
+
"composer.composerData",
|
|
85
|
+
JSON.stringify({ allComposers }),
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function addWorkspaceChatTab(
|
|
90
|
+
db: Database.Database,
|
|
91
|
+
tabs: Array<{ tabId: string; chatTitle?: string; lastSendTime?: number; bubbles?: Array<{ type: "user" | "ai"; text?: string }> }>,
|
|
92
|
+
): void {
|
|
93
|
+
db.prepare(`INSERT OR REPLACE INTO ItemTable (key, value) VALUES (?, ?)`).run(
|
|
94
|
+
CHAT_KEY,
|
|
95
|
+
JSON.stringify({ tabs }),
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// ── Test setup ────────────────────────────────────────────────────────────────
|
|
100
|
+
|
|
101
|
+
let tmp: string;
|
|
102
|
+
let dbPath: string;
|
|
103
|
+
let adapter: CursorAdapter;
|
|
104
|
+
|
|
105
|
+
beforeEach(() => {
|
|
106
|
+
tmp = mkdtempSync(join(tmpdir(), "nlm-cursor-"));
|
|
107
|
+
// globalStorage/state.vscdb — adapter derives workspaceStorage from its parent's parent
|
|
108
|
+
dbPath = join(tmp, "globalStorage", "state.vscdb");
|
|
109
|
+
mkdirSync(dirname(dbPath), { recursive: true });
|
|
110
|
+
adapter = new CursorAdapter({ dbPath });
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
afterEach(() => {
|
|
114
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// ── detect() ─────────────────────────────────────────────────────────────────
|
|
118
|
+
|
|
119
|
+
describe("detect()", () => {
|
|
120
|
+
it("returns enabled when DB exists", () => {
|
|
121
|
+
const db = createDb(dbPath);
|
|
122
|
+
db.close();
|
|
123
|
+
const result = adapter.detect();
|
|
124
|
+
expect(result.enabled).toBe(true);
|
|
125
|
+
expect(result.path).toBe(dbPath);
|
|
126
|
+
expect(result.hint).toBeNull();
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("returns disabled when DB is absent", () => {
|
|
130
|
+
const result = adapter.detect();
|
|
131
|
+
expect(result.enabled).toBe(false);
|
|
132
|
+
expect(result.path).toBeNull();
|
|
133
|
+
expect(result.hint).toMatch(/Cursor/);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// ── discover() ───────────────────────────────────────────────────────────────
|
|
138
|
+
|
|
139
|
+
describe("discover()", () => {
|
|
140
|
+
it("returns empty array when DB is absent", async () => {
|
|
141
|
+
expect(await adapter.discover()).toEqual([]);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("returns prefixed composerIds for all composer entries", async () => {
|
|
145
|
+
const db = createDb(dbPath);
|
|
146
|
+
addComposerInline(db, "composer-aaa");
|
|
147
|
+
addComposerInline(db, "composer-bbb");
|
|
148
|
+
db.close();
|
|
149
|
+
|
|
150
|
+
const ids = await adapter.discover();
|
|
151
|
+
expect(ids).toEqual(["cr_composer-aaa", "cr_composer-bbb"]);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("returns empty array when DB has no cursorDiskKV table", async () => {
|
|
155
|
+
const db = new Database(dbPath);
|
|
156
|
+
db.exec(`CREATE TABLE ItemTable (key TEXT, value TEXT);`);
|
|
157
|
+
db.close();
|
|
158
|
+
expect(await adapter.discover()).toEqual([]);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("skips entries whose value is not valid JSON", async () => {
|
|
162
|
+
const db = createDb(dbPath);
|
|
163
|
+
db.prepare(`INSERT INTO cursorDiskKV (key, value) VALUES (?, ?)`).run(
|
|
164
|
+
"composerData:broken",
|
|
165
|
+
"not-json",
|
|
166
|
+
);
|
|
167
|
+
addComposerInline(db, "composer-good");
|
|
168
|
+
db.close();
|
|
169
|
+
|
|
170
|
+
const ids = await adapter.discover();
|
|
171
|
+
expect(ids).toEqual(["cr_composer-good"]);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("filters by since when lastUpdatedAt is set", async () => {
|
|
175
|
+
const db = createDb(dbPath);
|
|
176
|
+
const old = new Date(Date.now() - 10 * 24 * 3600_000).toISOString();
|
|
177
|
+
const recent = new Date().toISOString();
|
|
178
|
+
addComposerInline(db, "old-composer", { lastUpdatedAt: old });
|
|
179
|
+
addComposerInline(db, "new-composer", { lastUpdatedAt: recent });
|
|
180
|
+
db.close();
|
|
181
|
+
|
|
182
|
+
const cutoff = new Date(Date.now() - 5 * 24 * 3600_000);
|
|
183
|
+
const ids = await adapter.discover({ since: cutoff });
|
|
184
|
+
expect(ids).toEqual(["cr_new-composer"]);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// ── parseSession() ────────────────────────────────────────────────────────────
|
|
189
|
+
|
|
190
|
+
describe("parseSession()", () => {
|
|
191
|
+
it("returns null when DB is absent", async () => {
|
|
192
|
+
expect(await adapter.parseSession("any-id")).toBeNull();
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it("returns null for unknown composerId", async () => {
|
|
196
|
+
const db = createDb(dbPath);
|
|
197
|
+
db.close();
|
|
198
|
+
expect(await adapter.parseSession("ghost-id")).toBeNull();
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it("returns null for composer with no turns", async () => {
|
|
202
|
+
const db = createDb(dbPath);
|
|
203
|
+
addComposerInline(db, "empty-id", { conversation: [] });
|
|
204
|
+
db.close();
|
|
205
|
+
expect(await adapter.parseSession("empty-id")).toBeNull();
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it("extracts turns from inline conversation[]", async () => {
|
|
209
|
+
const db = createDb(dbPath);
|
|
210
|
+
addComposerInline(db, "inline-id", {
|
|
211
|
+
name: "My session",
|
|
212
|
+
conversation: [
|
|
213
|
+
{ type: 1, text: "Hello" },
|
|
214
|
+
{ type: 2, text: "Hi there" },
|
|
215
|
+
],
|
|
216
|
+
});
|
|
217
|
+
db.close();
|
|
218
|
+
|
|
219
|
+
const chunk = await adapter.parseSession("inline-id");
|
|
220
|
+
expect(chunk).not.toBeNull();
|
|
221
|
+
expect(chunk!.turnCount).toBe(2);
|
|
222
|
+
expect(chunk!.text).toContain("user: Hello");
|
|
223
|
+
expect(chunk!.text).toContain("assistant: Hi there");
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it("falls back to bubbleId:* separate storage when conversation is empty", async () => {
|
|
227
|
+
const db = createDb(dbPath);
|
|
228
|
+
addComposerInline(db, "sep-id", { conversation: [] });
|
|
229
|
+
addBubble(db, "sep-id", "b1", 1, "What is 2+2?");
|
|
230
|
+
addBubble(db, "sep-id", "b2", 2, "It is 4.");
|
|
231
|
+
db.close();
|
|
232
|
+
|
|
233
|
+
const chunk = await adapter.parseSession("sep-id");
|
|
234
|
+
expect(chunk).not.toBeNull();
|
|
235
|
+
expect(chunk!.turnCount).toBe(2);
|
|
236
|
+
expect(chunk!.text).toContain("user: What is 2+2?");
|
|
237
|
+
expect(chunk!.text).toContain("assistant: It is 4.");
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it("uses composer name as label", async () => {
|
|
241
|
+
const db = createDb(dbPath);
|
|
242
|
+
addComposerInline(db, "named-id", {
|
|
243
|
+
name: "Refactor the auth module",
|
|
244
|
+
conversation: [{ type: 1, text: "Let's refactor" }],
|
|
245
|
+
});
|
|
246
|
+
db.close();
|
|
247
|
+
|
|
248
|
+
const chunk = await adapter.parseSession("named-id");
|
|
249
|
+
expect(chunk!.label).toBe("Refactor the auth module");
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it("falls back to first user turn as label when name is absent", async () => {
|
|
253
|
+
const db = createDb(dbPath);
|
|
254
|
+
const data = {
|
|
255
|
+
composerId: "unlabeled-id",
|
|
256
|
+
createdAt: new Date().toISOString(),
|
|
257
|
+
lastUpdatedAt: new Date().toISOString(),
|
|
258
|
+
conversation: [
|
|
259
|
+
{ type: 1, text: "Tell me about TypeScript generics" },
|
|
260
|
+
{ type: 2, text: "Generics allow..." },
|
|
261
|
+
],
|
|
262
|
+
};
|
|
263
|
+
db.prepare(`INSERT INTO cursorDiskKV (key, value) VALUES (?, ?)`).run(
|
|
264
|
+
"composerData:unlabeled-id",
|
|
265
|
+
JSON.stringify(data),
|
|
266
|
+
);
|
|
267
|
+
db.close();
|
|
268
|
+
|
|
269
|
+
const chunk = await adapter.parseSession("unlabeled-id");
|
|
270
|
+
expect(chunk!.label).toBe("Tell me about TypeScript generics");
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it("sets correct id prefix and runtimeSessionId", async () => {
|
|
274
|
+
const db = createDb(dbPath);
|
|
275
|
+
addComposerInline(db, "id-check", {
|
|
276
|
+
conversation: [{ type: 1, text: "Hello" }],
|
|
277
|
+
});
|
|
278
|
+
db.close();
|
|
279
|
+
|
|
280
|
+
const chunk = await adapter.parseSession("id-check");
|
|
281
|
+
expect(chunk!.runtimeSessionId).toBe("id-check");
|
|
282
|
+
expect(chunk!.id).toMatch(/^cr_/);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it("sets sourcePath to dbPath::composerId", async () => {
|
|
286
|
+
const db = createDb(dbPath);
|
|
287
|
+
addComposerInline(db, "path-check", {
|
|
288
|
+
conversation: [{ type: 1, text: "Hello" }],
|
|
289
|
+
});
|
|
290
|
+
db.close();
|
|
291
|
+
|
|
292
|
+
const chunk = await adapter.parseSession("path-check");
|
|
293
|
+
expect(chunk!.sourcePath).toBe(`${dbPath}::path-check`);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it("skips bubbles with empty text", async () => {
|
|
297
|
+
const db = createDb(dbPath);
|
|
298
|
+
addComposerInline(db, "sparse-id", {
|
|
299
|
+
conversation: [
|
|
300
|
+
{ type: 1, text: "" },
|
|
301
|
+
{ type: 1, text: "Real question" },
|
|
302
|
+
{ type: 2, text: "Real answer" },
|
|
303
|
+
],
|
|
304
|
+
});
|
|
305
|
+
db.close();
|
|
306
|
+
|
|
307
|
+
const chunk = await adapter.parseSession("sparse-id");
|
|
308
|
+
expect(chunk!.turnCount).toBe(2);
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it("skips bubbles with unknown type", async () => {
|
|
312
|
+
const db = createDb(dbPath);
|
|
313
|
+
const data = {
|
|
314
|
+
composerId: "typed-id",
|
|
315
|
+
conversation: [
|
|
316
|
+
{ type: 99, text: "system message" },
|
|
317
|
+
{ type: 1, text: "user question" },
|
|
318
|
+
{ type: 2, text: "assistant answer" },
|
|
319
|
+
],
|
|
320
|
+
};
|
|
321
|
+
db.prepare(`INSERT INTO cursorDiskKV (key, value) VALUES (?, ?)`).run(
|
|
322
|
+
"composerData:typed-id",
|
|
323
|
+
JSON.stringify(data),
|
|
324
|
+
);
|
|
325
|
+
db.close();
|
|
326
|
+
|
|
327
|
+
const chunk = await adapter.parseSession("typed-id");
|
|
328
|
+
expect(chunk!.turnCount).toBe(2);
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
it("populates byteRange[1] equal to transcript byte length", async () => {
|
|
332
|
+
const db = createDb(dbPath);
|
|
333
|
+
addComposerInline(db, "bytes-id", {
|
|
334
|
+
conversation: [
|
|
335
|
+
{ type: 1, text: "Hello" },
|
|
336
|
+
{ type: 2, text: "Hi" },
|
|
337
|
+
],
|
|
338
|
+
});
|
|
339
|
+
db.close();
|
|
340
|
+
|
|
341
|
+
const chunk = await adapter.parseSession("bytes-id");
|
|
342
|
+
const expected = Buffer.byteLength(chunk!.text, "utf8");
|
|
343
|
+
expect(chunk!.byteRange[1]).toBe(expected);
|
|
344
|
+
});
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
// ── workspace composer (crw_) ─────────────────────────────────────────────────
|
|
348
|
+
|
|
349
|
+
describe("workspace composer (crw_)", () => {
|
|
350
|
+
function wsDbPath(hash = "ws-hash-1"): string {
|
|
351
|
+
return join(tmp, "workspaceStorage", hash, "state.vscdb");
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
it("discover() returns crw_ ids from workspace ItemTable", async () => {
|
|
355
|
+
const db = createWorkspaceDb(wsDbPath());
|
|
356
|
+
addWorkspaceComposer(db, "ws-comp-aaa", { conversation: [{ type: 1, text: "hi" }] });
|
|
357
|
+
db.close();
|
|
358
|
+
|
|
359
|
+
const ids = await adapter.discover();
|
|
360
|
+
expect(ids).toContain("crw_ws-comp-aaa");
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
it("parseSession(crw_<id>) returns chunk from workspace composer", async () => {
|
|
364
|
+
const db = createWorkspaceDb(wsDbPath());
|
|
365
|
+
addWorkspaceComposer(db, "ws-comp-abc", {
|
|
366
|
+
name: "My workspace session",
|
|
367
|
+
conversation: [
|
|
368
|
+
{ type: 1, text: "Fix the bug" },
|
|
369
|
+
{ type: 2, text: "Done!" },
|
|
370
|
+
],
|
|
371
|
+
});
|
|
372
|
+
db.close();
|
|
373
|
+
|
|
374
|
+
const chunk = await adapter.parseSession("crw_ws-comp-abc");
|
|
375
|
+
expect(chunk).not.toBeNull();
|
|
376
|
+
expect(chunk!.turnCount).toBe(2);
|
|
377
|
+
expect(chunk!.text).toContain("user: Fix the bug");
|
|
378
|
+
expect(chunk!.text).toContain("assistant: Done!");
|
|
379
|
+
expect(chunk!.label).toBe("My workspace session");
|
|
380
|
+
expect(chunk!.id).toMatch(/^crw_/);
|
|
381
|
+
expect(chunk!.runtimeSessionId).toBe("ws-comp-abc");
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it("parseSession(crw_<id>) returns null when composer has no turns", async () => {
|
|
385
|
+
const db = createWorkspaceDb(wsDbPath());
|
|
386
|
+
addWorkspaceComposer(db, "empty-ws-comp", { conversation: [] });
|
|
387
|
+
db.close();
|
|
388
|
+
|
|
389
|
+
expect(await adapter.parseSession("crw_empty-ws-comp")).toBeNull();
|
|
390
|
+
});
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
// ── workspace chat tab (crc_) ─────────────────────────────────────────────────
|
|
394
|
+
|
|
395
|
+
describe("workspace chat tab (crc_)", () => {
|
|
396
|
+
function wsDbPath(hash = "ws-chat-hash"): string {
|
|
397
|
+
return join(tmp, "workspaceStorage", hash, "state.vscdb");
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
it("discover() returns crc_ ids from workspace chat tab ItemTable", async () => {
|
|
401
|
+
const db = createWorkspaceDb(wsDbPath());
|
|
402
|
+
addWorkspaceChatTab(db, [
|
|
403
|
+
{ tabId: "chat-aaa", bubbles: [{ type: "user", text: "Hello" }] },
|
|
404
|
+
{ tabId: "chat-bbb", bubbles: [{ type: "ai", text: "Hi" }] },
|
|
405
|
+
]);
|
|
406
|
+
db.close();
|
|
407
|
+
|
|
408
|
+
const ids = await adapter.discover();
|
|
409
|
+
expect(ids).toContain("crc_chat-aaa");
|
|
410
|
+
expect(ids).toContain("crc_chat-bbb");
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
it("discover() skips chat tabs with no bubbles", async () => {
|
|
414
|
+
const db = createWorkspaceDb(wsDbPath());
|
|
415
|
+
addWorkspaceChatTab(db, [
|
|
416
|
+
{ tabId: "empty-tab", bubbles: [] },
|
|
417
|
+
{ tabId: "good-tab", bubbles: [{ type: "user", text: "Hi" }] },
|
|
418
|
+
]);
|
|
419
|
+
db.close();
|
|
420
|
+
|
|
421
|
+
const ids = await adapter.discover();
|
|
422
|
+
expect(ids).not.toContain("crc_empty-tab");
|
|
423
|
+
expect(ids).toContain("crc_good-tab");
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
it("discover() filters chat tabs by since using lastSendTime", async () => {
|
|
427
|
+
const db = createWorkspaceDb(wsDbPath());
|
|
428
|
+
const old = Date.now() - 10 * 24 * 3600_000;
|
|
429
|
+
const recent = Date.now();
|
|
430
|
+
addWorkspaceChatTab(db, [
|
|
431
|
+
{ tabId: "old-chat", lastSendTime: old, bubbles: [{ type: "user", text: "Old" }] },
|
|
432
|
+
{ tabId: "new-chat", lastSendTime: recent, bubbles: [{ type: "user", text: "New" }] },
|
|
433
|
+
]);
|
|
434
|
+
db.close();
|
|
435
|
+
|
|
436
|
+
const cutoff = new Date(Date.now() - 5 * 24 * 3600_000);
|
|
437
|
+
const ids = await adapter.discover({ since: cutoff });
|
|
438
|
+
expect(ids).not.toContain("crc_old-chat");
|
|
439
|
+
expect(ids).toContain("crc_new-chat");
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
it("discover() includes chat tab with lastSendTime=0 even when since is set", async () => {
|
|
443
|
+
const db = createWorkspaceDb(wsDbPath());
|
|
444
|
+
addWorkspaceChatTab(db, [
|
|
445
|
+
{ tabId: "zero-ts-chat", lastSendTime: 0, bubbles: [{ type: "user", text: "Hi" }] },
|
|
446
|
+
]);
|
|
447
|
+
db.close();
|
|
448
|
+
|
|
449
|
+
const cutoff = new Date(); // very recent cutoff
|
|
450
|
+
const ids = await adapter.discover({ since: cutoff });
|
|
451
|
+
expect(ids).toContain("crc_zero-ts-chat");
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
it("parseSession(crc_<id>) returns chunk from workspace chat tab", async () => {
|
|
455
|
+
const db = createWorkspaceDb(wsDbPath());
|
|
456
|
+
addWorkspaceChatTab(db, [
|
|
457
|
+
{
|
|
458
|
+
tabId: "crc-parse-tab",
|
|
459
|
+
chatTitle: "Chat test",
|
|
460
|
+
bubbles: [
|
|
461
|
+
{ type: "user", text: "Question" },
|
|
462
|
+
{ type: "ai", text: "Answer" },
|
|
463
|
+
],
|
|
464
|
+
},
|
|
465
|
+
]);
|
|
466
|
+
db.close();
|
|
467
|
+
|
|
468
|
+
const chunk = await adapter.parseSession("crc_crc-parse-tab");
|
|
469
|
+
expect(chunk).not.toBeNull();
|
|
470
|
+
expect(chunk!.turnCount).toBe(2);
|
|
471
|
+
expect(chunk!.label).toBe("Chat test");
|
|
472
|
+
expect(chunk!.id).toMatch(/^crc_/);
|
|
473
|
+
expect(chunk!.runtimeSessionId).toBe("crc-parse-tab");
|
|
474
|
+
});
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
// ── metadata ──────────────────────────────────────────────────────────────────
|
|
478
|
+
|
|
479
|
+
describe("adapter metadata", () => {
|
|
480
|
+
it("has correct name, runtimeVersion, and transcriptKind", () => {
|
|
481
|
+
expect(adapter.name).toBe("cursor");
|
|
482
|
+
expect(adapter.runtimeVersion).toBe("cursor/1.0");
|
|
483
|
+
expect(adapter.transcriptKind).toBe("cursor-sqlite");
|
|
484
|
+
});
|
|
485
|
+
});
|