tokless 0.5.1 → 0.5.2
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/README.en.md +47 -158
- package/README.md +54 -197
- package/bin/tokless.js +2 -2
- package/index.js +2 -0
- package/package.json +3 -1
- package/plugin.json +1 -1
- package/rules/AGENTS.md +6 -6
- package/scripts/bump-version.js +81 -0
- package/scripts/read-guard-hook.js +64 -20
- package/skills/code-skeleton/SKILL.md +5 -5
- package/skills/token-audit/SKILL.md +12 -6
- package/tools/agy-audit/cli.js +78 -24
- package/tools/agy-audit/lib/analyzer.js +133 -14
- package/tools/agy-audit/lib/compare.js +5 -3
- package/tools/agy-audit/lib/formatter.js +85 -28
- package/tools/agy-audit/lib/paths.js +381 -88
- package/tools/agy-audit/lib/project.js +88 -79
- package/tools/repo-skeleton/cli.js +24 -9
- package/tools/repo-skeleton/lib/core/registry.js +15 -1
- package/tools/repo-skeleton/lib/langs/c-family/c-cpp-parser.js +1133 -0
- package/tools/repo-skeleton/lib/langs/c-family/index.js +42 -77
- package/tools/repo-skeleton/lib/skeleton.js +23 -1
|
@@ -4,38 +4,71 @@ const path = require('path');
|
|
|
4
4
|
const os = require('os');
|
|
5
5
|
const fs = require('fs');
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
const PRODUCT_SOURCES = [
|
|
8
|
+
{ key: 'app', label: 'Antigravity App', dirName: 'antigravity' },
|
|
9
|
+
{ key: 'cli', label: 'Antigravity CLI', dirName: 'antigravity-cli' },
|
|
10
|
+
{ key: 'ide', label: 'Antigravity IDE', dirName: 'antigravity-ide' },
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
function getAntigravitySourceEntries(options = {}) {
|
|
14
|
+
const customDir = options.dataDir || process.env.AGY_DATA_DIR;
|
|
15
|
+
if (customDir) {
|
|
16
|
+
const resolved = path.resolve(String(customDir));
|
|
17
|
+
if (!fs.existsSync(resolved)) {
|
|
18
|
+
throw new Error(`Antigravity directory not found at: ${resolved}`);
|
|
19
|
+
}
|
|
20
|
+
return [{ key: 'custom', label: 'Custom', dir: resolved }];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const sourceOpt = String(options.source || 'all').trim().toLowerCase();
|
|
24
|
+
const validSources = new Set(['all', ...PRODUCT_SOURCES.map((s) => s.key)]);
|
|
25
|
+
if (!validSources.has(sourceOpt)) {
|
|
26
|
+
throw new Error(`Invalid --source "${options.source}". Expected one of: all, cli, app, ide.`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const home = options.homeDir || os.homedir();
|
|
30
|
+
const targets =
|
|
31
|
+
sourceOpt === 'all' ? PRODUCT_SOURCES : PRODUCT_SOURCES.filter((s) => s.key === sourceOpt);
|
|
32
|
+
const checked = [];
|
|
33
|
+
const existing = [];
|
|
34
|
+
|
|
35
|
+
for (const src of targets) {
|
|
36
|
+
const dir = path.join(home, '.gemini', src.dirName);
|
|
37
|
+
checked.push(dir);
|
|
38
|
+
if (fs.existsSync(dir)) {
|
|
39
|
+
existing.push({ key: src.key, label: src.label, dir });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
14
43
|
if (existing.length === 0) {
|
|
15
|
-
throw new Error(`Antigravity directory not found at: ${
|
|
44
|
+
throw new Error(`Antigravity directory not found at: ${checked.join(' or ')}`);
|
|
16
45
|
}
|
|
17
46
|
return existing;
|
|
18
47
|
}
|
|
19
48
|
|
|
20
|
-
function
|
|
21
|
-
return
|
|
49
|
+
function getAntigravityDirs(options = {}) {
|
|
50
|
+
return getAntigravitySourceEntries(options).map((e) => e.dir);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function getAntigravityDir(options = {}) {
|
|
54
|
+
return getAntigravityDirs(options)[0];
|
|
22
55
|
}
|
|
23
56
|
|
|
24
|
-
function getBrainRoots() {
|
|
25
|
-
return getAntigravityDirs()
|
|
26
|
-
.map(dir => path.join(dir, 'brain'))
|
|
27
|
-
.filter(dir => fs.existsSync(dir));
|
|
57
|
+
function getBrainRoots(options = {}) {
|
|
58
|
+
return getAntigravityDirs(options)
|
|
59
|
+
.map((dir) => path.join(dir, 'brain'))
|
|
60
|
+
.filter((dir) => fs.existsSync(dir));
|
|
28
61
|
}
|
|
29
62
|
|
|
30
|
-
function getSummariesDbPaths() {
|
|
31
|
-
return getAntigravityDirs()
|
|
32
|
-
.map(dir => path.join(dir, 'conversation_summaries.db'))
|
|
33
|
-
.filter(dbPath => fs.existsSync(dbPath));
|
|
63
|
+
function getSummariesDbPaths(options = {}) {
|
|
64
|
+
return getAntigravityDirs(options)
|
|
65
|
+
.map((dir) => path.join(dir, 'conversation_summaries.db'))
|
|
66
|
+
.filter((dbPath) => fs.existsSync(dbPath));
|
|
34
67
|
}
|
|
35
68
|
|
|
36
|
-
function getSummariesDbPath() {
|
|
37
|
-
const paths = getSummariesDbPaths();
|
|
38
|
-
return paths[0] || path.join(getAntigravityDir(), 'conversation_summaries.db');
|
|
69
|
+
function getSummariesDbPath(options = {}) {
|
|
70
|
+
const paths = getSummariesDbPaths(options);
|
|
71
|
+
return paths[0] || path.join(getAntigravityDir(options), 'conversation_summaries.db');
|
|
39
72
|
}
|
|
40
73
|
|
|
41
74
|
function isSafeSingleDirName(name) {
|
|
@@ -44,12 +77,135 @@ function isSafeSingleDirName(name) {
|
|
|
44
77
|
return path.basename(name) === name;
|
|
45
78
|
}
|
|
46
79
|
|
|
47
|
-
function
|
|
80
|
+
function openSqliteReadOnly(dbPath) {
|
|
81
|
+
if (!dbPath || !fs.existsSync(dbPath)) return null;
|
|
82
|
+
try {
|
|
83
|
+
const { DatabaseSync } = require('node:sqlite');
|
|
84
|
+
try {
|
|
85
|
+
return new DatabaseSync(dbPath, { readOnly: true });
|
|
86
|
+
} catch (_) {
|
|
87
|
+
const normalized = path.resolve(dbPath).replace(/\\/g, '/');
|
|
88
|
+
const prefix = normalized.startsWith('/') ? 'file:' : 'file:///';
|
|
89
|
+
const fileUri = `${prefix}${encodeURI(normalized)}?mode=ro&immutable=1`;
|
|
90
|
+
return new DatabaseSync(fileUri, { readOnly: true });
|
|
91
|
+
}
|
|
92
|
+
} catch (_) {
|
|
93
|
+
try {
|
|
94
|
+
const Database = require('better-sqlite3');
|
|
95
|
+
return new Database(dbPath, { readonly: true, fileMustExist: true });
|
|
96
|
+
} catch (_) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function parseWorkspaceUris(rawUris) {
|
|
103
|
+
if (!rawUris) return '';
|
|
104
|
+
try {
|
|
105
|
+
const list = JSON.parse(rawUris);
|
|
106
|
+
if (Array.isArray(list)) {
|
|
107
|
+
return list.map((u) => decodeURIComponent(String(u)).replace(/^file:\/\/\/?/, '')).join(', ');
|
|
108
|
+
}
|
|
109
|
+
} catch (_) {
|
|
110
|
+
// Fallback to plain URI string
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
return decodeURIComponent(String(rawUris)).replace(/^file:\/\/\/?/, '');
|
|
114
|
+
} catch (_) {
|
|
115
|
+
return String(rawUris);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function rowToMeta(row) {
|
|
120
|
+
if (!row) return null;
|
|
121
|
+
return {
|
|
122
|
+
conversationId: row.conversation_id,
|
|
123
|
+
title: row.title || '',
|
|
124
|
+
workspace: parseWorkspaceUris(row.workspace_uris),
|
|
125
|
+
lastModifiedTime: row.last_modified_time,
|
|
126
|
+
stepCount: row.step_count || 0,
|
|
127
|
+
status: row.status,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function loadAllConversationMeta(rootDir) {
|
|
132
|
+
const map = new Map();
|
|
133
|
+
const dbPath = path.join(rootDir, 'conversation_summaries.db');
|
|
134
|
+
const db = openSqliteReadOnly(dbPath);
|
|
135
|
+
if (!db) return map;
|
|
136
|
+
try {
|
|
137
|
+
const rows = db
|
|
138
|
+
.prepare(
|
|
139
|
+
`SELECT conversation_id, title, step_count, last_modified_time, workspace_uris, status
|
|
140
|
+
FROM conversation_summaries`
|
|
141
|
+
)
|
|
142
|
+
.all();
|
|
143
|
+
for (const row of rows) {
|
|
144
|
+
if (row && row.conversation_id) {
|
|
145
|
+
map.set(row.conversation_id, rowToMeta(row));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
} catch (_) {
|
|
149
|
+
// Ignore SQLite read error
|
|
150
|
+
} finally {
|
|
151
|
+
try {
|
|
152
|
+
db.close();
|
|
153
|
+
} catch (_) {}
|
|
154
|
+
}
|
|
155
|
+
return map;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function cleanUserPromptTitle(rawContent) {
|
|
159
|
+
if (typeof rawContent !== 'string') return '';
|
|
160
|
+
const stripped = rawContent
|
|
161
|
+
.replace(/<ADDITIONAL_METADATA>[\s\S]*$/i, '')
|
|
162
|
+
.replace(/<\/?USER_REQUEST>/gi, '')
|
|
163
|
+
.replace(/\s+/g, ' ')
|
|
164
|
+
.trim();
|
|
165
|
+
if (!stripped) return '';
|
|
166
|
+
return stripped.length > 60 ? stripped.slice(0, 57) + '...' : stripped;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function extractFallbackTitleFromTranscript(filePath) {
|
|
170
|
+
let fd;
|
|
171
|
+
try {
|
|
172
|
+
fd = fs.openSync(filePath, 'r');
|
|
173
|
+
const buf = Buffer.alloc(65536);
|
|
174
|
+
const bytesRead = fs.readSync(fd, buf, 0, buf.length, 0);
|
|
175
|
+
if (bytesRead <= 0) return '';
|
|
176
|
+
const text = buf.subarray(0, bytesRead).toString('utf8');
|
|
177
|
+
for (const line of text.split('\n')) {
|
|
178
|
+
const trimmed = line.trim();
|
|
179
|
+
if (!trimmed) continue;
|
|
180
|
+
let parsed;
|
|
181
|
+
try {
|
|
182
|
+
parsed = JSON.parse(trimmed);
|
|
183
|
+
} catch (_) {
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (parsed && parsed.type === 'USER_INPUT' && typeof parsed.content === 'string') {
|
|
187
|
+
const cleaned = cleanUserPromptTitle(parsed.content);
|
|
188
|
+
if (cleaned) return cleaned;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
} catch (_) {
|
|
192
|
+
// Ignore fallback read failure
|
|
193
|
+
} finally {
|
|
194
|
+
if (fd !== undefined) {
|
|
195
|
+
try {
|
|
196
|
+
fs.closeSync(fd);
|
|
197
|
+
} catch (_) {}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return '';
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function getConversationBrainDir(conversationId, options = {}) {
|
|
48
204
|
if (typeof conversationId !== 'string' || !isSafeSingleDirName(conversationId.trim())) {
|
|
49
205
|
throw new Error(`Invalid conversation ID: "${conversationId}"`);
|
|
50
206
|
}
|
|
51
207
|
const cleanId = conversationId.trim();
|
|
52
|
-
const roots = getBrainRoots();
|
|
208
|
+
const roots = getBrainRoots(options);
|
|
53
209
|
for (const root of roots) {
|
|
54
210
|
const resolvedRoot = path.resolve(root);
|
|
55
211
|
const candidate = path.resolve(resolvedRoot, cleanId);
|
|
@@ -60,7 +216,7 @@ function getConversationBrainDir(conversationId) {
|
|
|
60
216
|
return candidate;
|
|
61
217
|
}
|
|
62
218
|
}
|
|
63
|
-
const fallbackRoot = path.resolve(getAntigravityDir(), 'brain');
|
|
219
|
+
const fallbackRoot = path.resolve(getAntigravityDir(options), 'brain');
|
|
64
220
|
const resolved = path.resolve(fallbackRoot, cleanId);
|
|
65
221
|
if (path.dirname(resolved) !== fallbackRoot) {
|
|
66
222
|
throw new Error(`Conversation path escapes brain directory: "${conversationId}"`);
|
|
@@ -70,8 +226,14 @@ function getConversationBrainDir(conversationId) {
|
|
|
70
226
|
|
|
71
227
|
function findTranscriptInBrainDir(brainDir, allowDirectFiles = false) {
|
|
72
228
|
const candidates = [
|
|
73
|
-
{
|
|
74
|
-
|
|
229
|
+
{
|
|
230
|
+
filePath: path.join(brainDir, '.system_generated', 'logs', 'transcript_full.jsonl'),
|
|
231
|
+
logType: 'transcript_full.jsonl',
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
filePath: path.join(brainDir, '.system_generated', 'logs', 'transcript.jsonl'),
|
|
235
|
+
logType: 'transcript.jsonl',
|
|
236
|
+
},
|
|
75
237
|
];
|
|
76
238
|
if (allowDirectFiles) {
|
|
77
239
|
candidates.push(
|
|
@@ -81,10 +243,12 @@ function findTranscriptInBrainDir(brainDir, allowDirectFiles = false) {
|
|
|
81
243
|
}
|
|
82
244
|
for (const item of candidates) {
|
|
83
245
|
if (fs.existsSync(item.filePath) && fs.statSync(item.filePath).isFile()) {
|
|
246
|
+
const stat = fs.statSync(item.filePath);
|
|
84
247
|
return {
|
|
85
248
|
filePath: item.filePath,
|
|
86
249
|
logType: item.logType,
|
|
87
|
-
bytes:
|
|
250
|
+
bytes: stat.size,
|
|
251
|
+
mtimeMs: stat.mtimeMs,
|
|
88
252
|
};
|
|
89
253
|
}
|
|
90
254
|
}
|
|
@@ -100,53 +264,171 @@ function extractConversationIdFromPath(targetPath, fallbackName) {
|
|
|
100
264
|
return fallbackName;
|
|
101
265
|
}
|
|
102
266
|
|
|
267
|
+
function inferSourceFromPath(targetPath) {
|
|
268
|
+
const resolved = path.resolve(targetPath);
|
|
269
|
+
const parts = resolved.split(path.sep).filter(Boolean);
|
|
270
|
+
const brainIdx = parts.lastIndexOf('brain');
|
|
271
|
+
if (brainIdx > 0) {
|
|
272
|
+
const productDirName = parts[brainIdx - 1];
|
|
273
|
+
const matched = PRODUCT_SOURCES.find((s) => s.dirName === productDirName);
|
|
274
|
+
if (matched) {
|
|
275
|
+
return { source: matched.key, sourceLabel: matched.label };
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return { source: 'file', sourceLabel: 'Direct File' };
|
|
279
|
+
}
|
|
280
|
+
|
|
103
281
|
function looksLikePath(input) {
|
|
104
|
-
return
|
|
282
|
+
return (
|
|
283
|
+
input.includes('/') ||
|
|
284
|
+
input.includes('\\') ||
|
|
285
|
+
input.endsWith('.jsonl') ||
|
|
286
|
+
input === '.' ||
|
|
287
|
+
input === '..'
|
|
288
|
+
);
|
|
105
289
|
}
|
|
106
290
|
|
|
107
|
-
function
|
|
291
|
+
function listSessions(options = {}) {
|
|
292
|
+
const entries = getAntigravitySourceEntries(options);
|
|
293
|
+
const rawLimit = options.limit;
|
|
294
|
+
const limit =
|
|
295
|
+
rawLimit === 0 || rawLimit === Infinity || rawLimit === null
|
|
296
|
+
? Infinity
|
|
297
|
+
: Number.isInteger(rawLimit) && rawLimit > 0
|
|
298
|
+
? rawLimit
|
|
299
|
+
: 10;
|
|
300
|
+
|
|
301
|
+
const sessions = [];
|
|
302
|
+
for (const srcEntry of entries) {
|
|
303
|
+
const brainRoot = path.join(srcEntry.dir, 'brain');
|
|
304
|
+
if (!fs.existsSync(brainRoot)) continue;
|
|
305
|
+
|
|
306
|
+
const metaMap = loadAllConversationMeta(srcEntry.dir);
|
|
307
|
+
let dirEntries = [];
|
|
308
|
+
try {
|
|
309
|
+
dirEntries = fs.readdirSync(brainRoot, { withFileTypes: true });
|
|
310
|
+
} catch (_) {
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
for (const dirEnt of dirEntries) {
|
|
315
|
+
if (!dirEnt.isDirectory()) continue;
|
|
316
|
+
const conversationId = dirEnt.name;
|
|
317
|
+
const brainDir = path.join(brainRoot, conversationId);
|
|
318
|
+
const transcript = findTranscriptInBrainDir(brainDir, false);
|
|
319
|
+
if (!transcript) continue;
|
|
320
|
+
|
|
321
|
+
const dbMeta = metaMap.get(conversationId) || null;
|
|
322
|
+
const title =
|
|
323
|
+
(dbMeta && dbMeta.title) ||
|
|
324
|
+
extractFallbackTitleFromTranscript(transcript.filePath) ||
|
|
325
|
+
'Untitled Session';
|
|
326
|
+
|
|
327
|
+
sessions.push({
|
|
328
|
+
conversationId,
|
|
329
|
+
shortId: conversationId.slice(0, 8),
|
|
330
|
+
source: srcEntry.key,
|
|
331
|
+
sourceLabel: srcEntry.label,
|
|
332
|
+
rootDir: srcEntry.dir,
|
|
333
|
+
filePath: transcript.filePath,
|
|
334
|
+
logType: transcript.logType,
|
|
335
|
+
bytes: transcript.bytes,
|
|
336
|
+
mtimeMs: transcript.mtimeMs,
|
|
337
|
+
mtimeIso: new Date(transcript.mtimeMs).toISOString(),
|
|
338
|
+
title,
|
|
339
|
+
workspace: (dbMeta && dbMeta.workspace) || '',
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
sessions.sort((a, b) => b.mtimeMs - a.mtimeMs || a.conversationId.localeCompare(b.conversationId));
|
|
345
|
+
return Number.isFinite(limit) ? sessions.slice(0, limit) : sessions;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function resolveSessionTarget(idOrPrefixOrPath, options = {}) {
|
|
108
349
|
if (!idOrPrefixOrPath || typeof idOrPrefixOrPath !== 'string') {
|
|
109
|
-
throw new Error('Conversation ID, prefix, or path is required.');
|
|
350
|
+
throw new Error('Conversation ID, prefix, "latest", or path is required.');
|
|
110
351
|
}
|
|
111
352
|
const trimmed = idOrPrefixOrPath.trim();
|
|
112
353
|
if (!trimmed) {
|
|
113
|
-
throw new Error('Conversation ID, prefix, or path is empty.');
|
|
354
|
+
throw new Error('Conversation ID, prefix, "latest", or path is empty.');
|
|
114
355
|
}
|
|
115
356
|
|
|
116
357
|
const candidatePath = path.resolve(trimmed);
|
|
117
358
|
if (fs.existsSync(candidatePath)) {
|
|
118
359
|
const stat = fs.statSync(candidatePath);
|
|
119
360
|
if (stat.isFile() && candidatePath.toLowerCase().endsWith('.jsonl')) {
|
|
120
|
-
const conversationId = extractConversationIdFromPath(
|
|
361
|
+
const conversationId = extractConversationIdFromPath(
|
|
362
|
+
candidatePath,
|
|
363
|
+
path.basename(candidatePath, '.jsonl')
|
|
364
|
+
);
|
|
365
|
+
const srcInfo = inferSourceFromPath(candidatePath);
|
|
121
366
|
return {
|
|
122
367
|
conversationId,
|
|
368
|
+
source: srcInfo.source,
|
|
369
|
+
sourceLabel: srcInfo.sourceLabel,
|
|
123
370
|
transcriptInfo: {
|
|
124
371
|
filePath: candidatePath,
|
|
125
372
|
logType: path.basename(candidatePath),
|
|
126
|
-
bytes: stat.size
|
|
127
|
-
|
|
373
|
+
bytes: stat.size,
|
|
374
|
+
mtimeMs: stat.mtimeMs,
|
|
375
|
+
},
|
|
128
376
|
};
|
|
129
377
|
}
|
|
130
378
|
if (stat.isDirectory()) {
|
|
131
379
|
const info = findTranscriptInBrainDir(candidatePath, true);
|
|
132
380
|
if (info || looksLikePath(trimmed)) {
|
|
133
|
-
const conversationId = extractConversationIdFromPath(
|
|
381
|
+
const conversationId = extractConversationIdFromPath(
|
|
382
|
+
candidatePath,
|
|
383
|
+
path.basename(candidatePath)
|
|
384
|
+
);
|
|
385
|
+
const srcInfo = inferSourceFromPath(candidatePath);
|
|
134
386
|
return {
|
|
135
387
|
conversationId,
|
|
136
|
-
|
|
388
|
+
source: srcInfo.source,
|
|
389
|
+
sourceLabel: srcInfo.sourceLabel,
|
|
390
|
+
transcriptInfo: info,
|
|
137
391
|
};
|
|
138
392
|
}
|
|
139
393
|
}
|
|
140
394
|
}
|
|
141
395
|
|
|
142
|
-
const
|
|
396
|
+
const latestMatch = trimmed.match(/^latest(?:~(\d+))?$/i);
|
|
397
|
+
if (latestMatch) {
|
|
398
|
+
const offset = latestMatch[1] ? parseInt(latestMatch[1], 10) : 0;
|
|
399
|
+
const sessions = listSessions({ ...options, limit: offset + 1 });
|
|
400
|
+
if (sessions.length <= offset) {
|
|
401
|
+
throw new Error(`No transcript session found for "${trimmed}".`);
|
|
402
|
+
}
|
|
403
|
+
const picked = sessions[offset];
|
|
404
|
+
return {
|
|
405
|
+
conversationId: picked.conversationId,
|
|
406
|
+
source: picked.source,
|
|
407
|
+
sourceLabel: picked.sourceLabel,
|
|
408
|
+
rootDir: picked.rootDir,
|
|
409
|
+
transcriptInfo: {
|
|
410
|
+
filePath: picked.filePath,
|
|
411
|
+
logType: picked.logType,
|
|
412
|
+
bytes: picked.bytes,
|
|
413
|
+
mtimeMs: picked.mtimeMs,
|
|
414
|
+
},
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const conversationId = resolveConversationId(trimmed, options);
|
|
419
|
+
const transcriptInfo = getTranscriptInfo(conversationId, options);
|
|
420
|
+
const srcInfo = transcriptInfo
|
|
421
|
+
? inferSourceFromPath(transcriptInfo.filePath)
|
|
422
|
+
: { source: 'unknown', sourceLabel: '' };
|
|
143
423
|
return {
|
|
144
424
|
conversationId,
|
|
145
|
-
|
|
425
|
+
source: srcInfo.source,
|
|
426
|
+
sourceLabel: srcInfo.sourceLabel,
|
|
427
|
+
transcriptInfo,
|
|
146
428
|
};
|
|
147
429
|
}
|
|
148
430
|
|
|
149
|
-
function resolveConversationId(idOrPrefix) {
|
|
431
|
+
function resolveConversationId(idOrPrefix, options = {}) {
|
|
150
432
|
if (!idOrPrefix || typeof idOrPrefix !== 'string') {
|
|
151
433
|
throw new Error('Conversation ID or prefix is required.');
|
|
152
434
|
}
|
|
@@ -159,7 +441,7 @@ function resolveConversationId(idOrPrefix) {
|
|
|
159
441
|
throw new Error(`Invalid conversation ID or prefix: "${idOrPrefix}"`);
|
|
160
442
|
}
|
|
161
443
|
|
|
162
|
-
const brainRoots = getBrainRoots();
|
|
444
|
+
const brainRoots = getBrainRoots(options);
|
|
163
445
|
|
|
164
446
|
// 陷阱: 沙箱环境下 fs.readdirSync(brainRoot) 可能被 EPERM 拦截,完整会话 ID 先做 stat 直连命中
|
|
165
447
|
for (const brainRoot of brainRoots) {
|
|
@@ -178,7 +460,7 @@ function resolveConversationId(idOrPrefix) {
|
|
|
178
460
|
const prefixMatches = new Set();
|
|
179
461
|
for (const brainRoot of brainRoots) {
|
|
180
462
|
const entries = fs.readdirSync(brainRoot, { withFileTypes: true });
|
|
181
|
-
const exact = entries.find(e => e.isDirectory() && e.name.toLowerCase() === query);
|
|
463
|
+
const exact = entries.find((e) => e.isDirectory() && e.name.toLowerCase() === query);
|
|
182
464
|
if (exact) return exact.name;
|
|
183
465
|
|
|
184
466
|
for (const entry of entries) {
|
|
@@ -191,52 +473,63 @@ function resolveConversationId(idOrPrefix) {
|
|
|
191
473
|
const matches = Array.from(prefixMatches);
|
|
192
474
|
if (matches.length === 1) return matches[0];
|
|
193
475
|
if (matches.length > 1) {
|
|
194
|
-
throw new Error(
|
|
476
|
+
throw new Error(
|
|
477
|
+
`Ambiguous conversation ID prefix "${idOrPrefix}" (${matches.length} matches): ${matches.slice(0, 5).join(', ')}`
|
|
478
|
+
);
|
|
195
479
|
}
|
|
196
480
|
|
|
197
481
|
const dbMatches = new Set();
|
|
198
|
-
for (const dbPath of getSummariesDbPaths()) {
|
|
482
|
+
for (const dbPath of getSummariesDbPaths(options)) {
|
|
483
|
+
const db = openSqliteReadOnly(dbPath);
|
|
484
|
+
if (!db) continue;
|
|
199
485
|
try {
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
db.close();
|
|
486
|
+
const rows = db
|
|
487
|
+
.prepare(
|
|
488
|
+
`SELECT conversation_id FROM conversation_summaries WHERE conversation_id = ? OR conversation_id LIKE ? LIMIT 10`
|
|
489
|
+
)
|
|
490
|
+
.all(idOrPrefix, `${idOrPrefix}%`);
|
|
206
491
|
for (const row of rows) {
|
|
207
492
|
if (row.conversation_id.toLowerCase() === query) {
|
|
208
493
|
return row.conversation_id;
|
|
209
494
|
}
|
|
210
495
|
dbMatches.add(row.conversation_id);
|
|
211
496
|
}
|
|
212
|
-
} catch {
|
|
497
|
+
} catch (_) {
|
|
498
|
+
} finally {
|
|
499
|
+
try {
|
|
500
|
+
db.close();
|
|
501
|
+
} catch (_) {}
|
|
213
502
|
}
|
|
214
503
|
}
|
|
215
504
|
|
|
216
505
|
const dbIds = Array.from(dbMatches);
|
|
217
506
|
if (dbIds.length === 1) return dbIds[0];
|
|
218
507
|
if (dbIds.length > 1) {
|
|
219
|
-
throw new Error(
|
|
508
|
+
throw new Error(
|
|
509
|
+
`Ambiguous conversation ID prefix "${idOrPrefix}" in DB: ${dbIds.slice(0, 5).join(', ')}`
|
|
510
|
+
);
|
|
220
511
|
}
|
|
221
512
|
|
|
222
513
|
return idOrPrefix;
|
|
223
514
|
}
|
|
224
515
|
|
|
225
|
-
function getTranscriptInfo(conversationId) {
|
|
516
|
+
function getTranscriptInfo(conversationId, options = {}) {
|
|
226
517
|
if (typeof conversationId !== 'string' || !isSafeSingleDirName(conversationId.trim())) {
|
|
227
518
|
throw new Error(`Invalid conversation ID: "${conversationId}"`);
|
|
228
519
|
}
|
|
229
520
|
const cleanId = conversationId.trim();
|
|
230
|
-
const roots = getBrainRoots();
|
|
521
|
+
const roots = getBrainRoots(options);
|
|
231
522
|
for (const logName of ['transcript_full.jsonl', 'transcript.jsonl']) {
|
|
232
523
|
for (const root of roots) {
|
|
233
524
|
const brainDir = path.join(root, cleanId);
|
|
234
525
|
const logPath = path.join(brainDir, '.system_generated', 'logs', logName);
|
|
235
526
|
if (fs.existsSync(logPath) && fs.statSync(logPath).isFile()) {
|
|
527
|
+
const stat = fs.statSync(logPath);
|
|
236
528
|
return {
|
|
237
529
|
filePath: logPath,
|
|
238
530
|
logType: logName,
|
|
239
|
-
bytes:
|
|
531
|
+
bytes: stat.size,
|
|
532
|
+
mtimeMs: stat.mtimeMs,
|
|
240
533
|
};
|
|
241
534
|
}
|
|
242
535
|
}
|
|
@@ -244,15 +537,15 @@ function getTranscriptInfo(conversationId) {
|
|
|
244
537
|
return null;
|
|
245
538
|
}
|
|
246
539
|
|
|
247
|
-
function getConversationDbPaths(conversationId) {
|
|
540
|
+
function getConversationDbPaths(conversationId, options = {}) {
|
|
248
541
|
if (!conversationId || typeof conversationId !== 'string' || !isSafeSingleDirName(conversationId.trim())) {
|
|
249
542
|
return [];
|
|
250
543
|
}
|
|
251
544
|
const cleanId = conversationId.trim();
|
|
252
545
|
try {
|
|
253
|
-
return getAntigravityDirs()
|
|
254
|
-
.map(dir => path.join(dir, 'conversations', `${cleanId}.db`))
|
|
255
|
-
.filter(dbPath => fs.existsSync(dbPath) && fs.statSync(dbPath).isFile());
|
|
546
|
+
return getAntigravityDirs(options)
|
|
547
|
+
.map((dir) => path.join(dir, 'conversations', `${cleanId}.db`))
|
|
548
|
+
.filter((dbPath) => fs.existsSync(dbPath) && fs.statSync(dbPath).isFile());
|
|
256
549
|
} catch {
|
|
257
550
|
return [];
|
|
258
551
|
}
|
|
@@ -274,7 +567,7 @@ function parseMountedMcpBlock(mcpBlockText) {
|
|
|
274
567
|
name: curServer,
|
|
275
568
|
prefix: `mcp_${curServer}_`,
|
|
276
569
|
eagerTools: [],
|
|
277
|
-
lazyTools: []
|
|
570
|
+
lazyTools: [],
|
|
278
571
|
});
|
|
279
572
|
}
|
|
280
573
|
curMode = null;
|
|
@@ -297,7 +590,7 @@ function readChunkUtf8(fd, offset, length) {
|
|
|
297
590
|
return buf.subarray(0, bytesRead).toString('utf8');
|
|
298
591
|
}
|
|
299
592
|
|
|
300
|
-
function inspectSessionMountedMcp(conversationId, transcriptFilePath) {
|
|
593
|
+
function inspectSessionMountedMcp(conversationId, transcriptFilePath, options = {}) {
|
|
301
594
|
const candidateDbs = [];
|
|
302
595
|
if (transcriptFilePath && isSafeSingleDirName(String(conversationId || '').trim())) {
|
|
303
596
|
const parts = path.resolve(transcriptFilePath).split(path.sep);
|
|
@@ -310,7 +603,7 @@ function inspectSessionMountedMcp(conversationId, transcriptFilePath) {
|
|
|
310
603
|
}
|
|
311
604
|
}
|
|
312
605
|
}
|
|
313
|
-
for (const p of getConversationDbPaths(conversationId)) {
|
|
606
|
+
for (const p of getConversationDbPaths(conversationId, options)) {
|
|
314
607
|
if (!candidateDbs.includes(p)) candidateDbs.push(p);
|
|
315
608
|
}
|
|
316
609
|
|
|
@@ -367,7 +660,7 @@ function inspectSessionMountedMcp(conversationId, transcriptFilePath) {
|
|
|
367
660
|
const servers = bestMatch ? parseMountedMcpBlock(bestMatch) : [];
|
|
368
661
|
return {
|
|
369
662
|
detectedFromSessionDb: true,
|
|
370
|
-
servers
|
|
663
|
+
servers,
|
|
371
664
|
};
|
|
372
665
|
} catch {
|
|
373
666
|
if (fd !== null) {
|
|
@@ -380,50 +673,47 @@ function inspectSessionMountedMcp(conversationId, transcriptFilePath) {
|
|
|
380
673
|
|
|
381
674
|
return {
|
|
382
675
|
detectedFromSessionDb: false,
|
|
383
|
-
servers: []
|
|
676
|
+
servers: [],
|
|
384
677
|
};
|
|
385
678
|
}
|
|
386
679
|
|
|
387
|
-
function getConversationMeta(conversationId) {
|
|
388
|
-
for (const dbPath of getSummariesDbPaths()) {
|
|
680
|
+
function getConversationMeta(conversationId, options = {}) {
|
|
681
|
+
for (const dbPath of getSummariesDbPaths(options)) {
|
|
682
|
+
const db = openSqliteReadOnly(dbPath);
|
|
683
|
+
if (!db) continue;
|
|
389
684
|
try {
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
db.close();
|
|
685
|
+
const row = db
|
|
686
|
+
.prepare(
|
|
687
|
+
`SELECT conversation_id, title, step_count, last_modified_time, workspace_uris, status
|
|
688
|
+
FROM conversation_summaries WHERE conversation_id = ? LIMIT 1`
|
|
689
|
+
)
|
|
690
|
+
.get(conversationId);
|
|
397
691
|
if (!row) continue;
|
|
398
692
|
|
|
399
|
-
let workspace = '';
|
|
400
|
-
if (row.workspace_uris) {
|
|
401
|
-
try {
|
|
402
|
-
const list = JSON.parse(row.workspace_uris);
|
|
403
|
-
if (Array.isArray(list)) {
|
|
404
|
-
workspace = list.map(u => decodeURIComponent(u).replace(/^file:\/\/\/?/, '')).join(', ');
|
|
405
|
-
}
|
|
406
|
-
} catch {
|
|
407
|
-
workspace = decodeURIComponent(row.workspace_uris).replace(/^file:\/\/\/?/, '');
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
693
|
return {
|
|
411
694
|
conversationId: row.conversation_id,
|
|
412
|
-
title: row.title || '
|
|
413
|
-
workspace,
|
|
695
|
+
title: row.title || '',
|
|
696
|
+
workspace: parseWorkspaceUris(row.workspace_uris),
|
|
414
697
|
lastModifiedTime: row.last_modified_time,
|
|
415
698
|
stepCount: row.step_count || 0,
|
|
416
|
-
status: row.status
|
|
699
|
+
status: row.status,
|
|
417
700
|
};
|
|
418
|
-
} catch {
|
|
701
|
+
} catch (_) {
|
|
702
|
+
} finally {
|
|
703
|
+
try {
|
|
704
|
+
db.close();
|
|
705
|
+
} catch (_) {}
|
|
706
|
+
}
|
|
419
707
|
}
|
|
420
708
|
return null;
|
|
421
709
|
}
|
|
422
710
|
|
|
423
711
|
module.exports = {
|
|
712
|
+
PRODUCT_SOURCES,
|
|
424
713
|
isSafeSingleDirName,
|
|
425
714
|
getAntigravityDir,
|
|
426
715
|
getAntigravityDirs,
|
|
716
|
+
getAntigravitySourceEntries,
|
|
427
717
|
getBrainRoots,
|
|
428
718
|
getSummariesDbPath,
|
|
429
719
|
getSummariesDbPaths,
|
|
@@ -431,7 +721,10 @@ module.exports = {
|
|
|
431
721
|
getConversationDbPaths,
|
|
432
722
|
resolveSessionTarget,
|
|
433
723
|
resolveConversationId,
|
|
724
|
+
listSessions,
|
|
434
725
|
getTranscriptInfo,
|
|
435
726
|
getConversationMeta,
|
|
436
|
-
|
|
727
|
+
extractFallbackTitleFromTranscript,
|
|
728
|
+
cleanUserPromptTitle,
|
|
729
|
+
inspectSessionMountedMcp,
|
|
437
730
|
};
|