genaicode 2.34.0 → 2.35.1
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/agents/artifacts.d.ts +1 -1
- package/dist/agents/artifacts.js +4 -65
- package/dist/agents/artifacts.js.map +1 -1
- package/dist/agents/cli-agent.d.ts +3 -0
- package/dist/agents/cli-agent.js +1 -0
- package/dist/agents/cli-agent.js.map +1 -1
- package/dist/agents/drivers/anthropic-managed.d.ts +4 -0
- package/dist/agents/drivers/anthropic-managed.js +46 -0
- package/dist/agents/drivers/anthropic-managed.js.map +1 -1
- package/dist/agents/drivers/antigravity.js +2 -0
- package/dist/agents/drivers/antigravity.js.map +1 -1
- package/dist/agents/drivers/claude.js +2 -0
- package/dist/agents/drivers/claude.js.map +1 -1
- package/dist/agents/drivers/codex-live.js +2 -0
- package/dist/agents/drivers/codex-live.js.map +1 -1
- package/dist/agents/drivers/codex.js +2 -0
- package/dist/agents/drivers/codex.js.map +1 -1
- package/dist/agents/drivers/copilot.js +2 -0
- package/dist/agents/drivers/copilot.js.map +1 -1
- package/dist/agents/drivers/cursor-cloud.js +45 -0
- package/dist/agents/drivers/cursor-cloud.js.map +1 -1
- package/dist/agents/drivers/cursor.js +2 -0
- package/dist/agents/drivers/cursor.js.map +1 -1
- package/dist/agents/drivers/gemini-managed.js +2 -0
- package/dist/agents/drivers/gemini-managed.js.map +1 -1
- package/dist/agents/drivers/gemini.js +2 -0
- package/dist/agents/drivers/gemini.js.map +1 -1
- package/dist/agents/drivers/muse-live.js +2 -0
- package/dist/agents/drivers/muse-live.js.map +1 -1
- package/dist/agents/drivers/muse.js +2 -0
- package/dist/agents/drivers/muse.js.map +1 -1
- package/dist/agents/drivers/openai-managed.js +2 -0
- package/dist/agents/drivers/openai-managed.js.map +1 -1
- package/dist/agents/drivers/opencode.js +2 -0
- package/dist/agents/drivers/opencode.js.map +1 -1
- package/dist/agents/drivers/vibe.js +2 -0
- package/dist/agents/drivers/vibe.js.map +1 -1
- package/dist/agents/hosted.js +2 -0
- package/dist/agents/hosted.js.map +1 -1
- package/dist/agents/live-agent.d.ts +3 -0
- package/dist/agents/live-agent.js +1 -0
- package/dist/agents/live-agent.js.map +1 -1
- package/dist/agents/managed.d.ts +3 -0
- package/dist/agents/managed.js +1 -0
- package/dist/agents/managed.js.map +1 -1
- package/dist/agents/mcp-server.d.ts +19 -0
- package/dist/agents/mcp-server.js +74 -0
- package/dist/agents/mcp-server.js.map +1 -0
- package/dist/agents/pack-git.d.ts +23 -0
- package/dist/agents/pack-git.js +112 -0
- package/dist/agents/pack-git.js.map +1 -0
- package/dist/agents/pack.d.ts +68 -0
- package/dist/agents/pack.js +611 -0
- package/dist/agents/pack.js.map +1 -0
- package/dist/agents/session.d.ts +10 -0
- package/dist/agents/session.js +26 -0
- package/dist/agents/session.js.map +1 -1
- package/dist/agents/sessions/claude.d.ts +14 -0
- package/dist/agents/sessions/claude.js +233 -0
- package/dist/agents/sessions/claude.js.map +1 -0
- package/dist/agents/sessions/codex-api.d.ts +32 -0
- package/dist/agents/sessions/codex-api.js +233 -0
- package/dist/agents/sessions/codex-api.js.map +1 -0
- package/dist/agents/sessions/codex.d.ts +28 -0
- package/dist/agents/sessions/codex.js +430 -0
- package/dist/agents/sessions/codex.js.map +1 -0
- package/dist/agents/sessions/doctor.d.ts +67 -0
- package/dist/agents/sessions/doctor.js +182 -0
- package/dist/agents/sessions/doctor.js.map +1 -0
- package/dist/agents/sessions/files.d.ts +44 -0
- package/dist/agents/sessions/files.js +150 -0
- package/dist/agents/sessions/files.js.map +1 -0
- package/dist/agents/sessions/group.d.ts +24 -0
- package/dist/agents/sessions/group.js +27 -0
- package/dist/agents/sessions/group.js.map +1 -0
- package/dist/agents/sessions/hooks.d.ts +32 -0
- package/dist/agents/sessions/hooks.js +155 -0
- package/dist/agents/sessions/hooks.js.map +1 -0
- package/dist/agents/sessions/index.d.ts +42 -0
- package/dist/agents/sessions/index.js +97 -0
- package/dist/agents/sessions/index.js.map +1 -0
- package/dist/agents/sessions/live.d.ts +67 -0
- package/dist/agents/sessions/live.js +308 -0
- package/dist/agents/sessions/live.js.map +1 -0
- package/dist/agents/sessions/sqlite.d.ts +12 -0
- package/dist/agents/sessions/sqlite.js +61 -0
- package/dist/agents/sessions/sqlite.js.map +1 -0
- package/dist/agents/sessions/stores.d.ts +38 -0
- package/dist/agents/sessions/stores.js +630 -0
- package/dist/agents/sessions/stores.js.map +1 -0
- package/dist/agents/sessions/transcript.d.ts +20 -0
- package/dist/agents/sessions/transcript.js +134 -0
- package/dist/agents/sessions/transcript.js.map +1 -0
- package/dist/agents/sessions/types.d.ts +95 -0
- package/dist/agents/sessions/types.js +2 -0
- package/dist/agents/sessions/types.js.map +1 -0
- package/dist/agents/types.d.ts +31 -0
- package/dist/agents.d.ts +6 -0
- package/dist/agents.js +3 -0
- package/dist/agents.js.map +1 -1
- package/dist/cli/args.d.ts +26 -0
- package/dist/cli/args.js +66 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/hook.d.ts +7 -0
- package/dist/cli/hook.js +21 -0
- package/dist/cli/hook.js.map +1 -0
- package/dist/cli/main.d.ts +3 -1
- package/dist/cli/main.js +237 -2
- package/dist/cli/main.js.map +1 -1
- package/dist/cli.js +31 -21
- package/dist/cli.js.map +1 -1
- package/dist/providers/google-converter.js +18 -8
- package/dist/providers/google-converter.js.map +1 -1
- package/dist/providers/openai-converter.js +3 -2
- package/dist/providers/openai-converter.js.map +1 -1
- package/dist/providers/openai-responses-converter.d.ts +35 -0
- package/dist/providers/openai-responses-converter.js +188 -0
- package/dist/providers/openai-responses-converter.js.map +1 -0
- package/dist/providers/openai.d.ts +6 -1
- package/dist/providers/openai.js +16 -1
- package/dist/providers/openai.js.map +1 -1
- package/dist/providers.d.ts +1 -0
- package/dist/providers.js +1 -0
- package/dist/providers.js.map +1 -1
- package/dist/ui/index.js +109 -82
- package/dist/ui/sessions.d.ts +19 -0
- package/dist/ui/sessions.js +59 -0
- package/dist/ui/sessions.js.map +1 -0
- package/dist/ui/web-client.js +15 -14
- package/docs/CHANGELOG.md +26 -0
- package/docs/agents.md +212 -1
- package/docs/cli.md +41 -0
- package/docs/llm.md +6 -1
- package/package.json +1 -1
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { activeIfRecent, ending, findFiles, headAndTail, homeOf, isRecord, mapLimited, oneLine, readJson, select, timeOf, } from './files.js';
|
|
5
|
+
import { number, queryDatabase, tableColumns, text } from './sqlite.js';
|
|
6
|
+
import { transcriptBuilder, transcriptLines } from './transcript.js';
|
|
7
|
+
/** Sessions enriched from their transcripts per listing, at most: the rest keep what the index says. */
|
|
8
|
+
const ENRICH = 200;
|
|
9
|
+
/** Rows of `table` with the `wanted` columns this version of the store has (others come back undefined). */
|
|
10
|
+
async function rows(file, table, wanted, tail = '') {
|
|
11
|
+
const columns = await tableColumns(file, table);
|
|
12
|
+
if (!columns?.size)
|
|
13
|
+
return [];
|
|
14
|
+
const present = wanted.filter((column) => columns.has(column));
|
|
15
|
+
if (!present.length)
|
|
16
|
+
return [];
|
|
17
|
+
return (await queryDatabase(file, `SELECT ${present.join(', ')} FROM ${table} ${tail}`)) ?? [];
|
|
18
|
+
}
|
|
19
|
+
const title = (value) => {
|
|
20
|
+
const found = text(value);
|
|
21
|
+
return found ? oneLine(found, 120) : undefined;
|
|
22
|
+
};
|
|
23
|
+
const prompt = (value) => {
|
|
24
|
+
const found = text(value);
|
|
25
|
+
return found ? oneLine(found) : undefined;
|
|
26
|
+
};
|
|
27
|
+
/** Drop undefined fields, so sources can build sessions with plain object literals. */
|
|
28
|
+
function session(info) {
|
|
29
|
+
return Object.fromEntries(Object.entries(info).filter(([, value]) => value !== undefined));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Muse Code: the `sessions` table of `~/.local/share/muse/session-index.db` (root sessions only;
|
|
33
|
+
* subagents have their own rows).
|
|
34
|
+
*/
|
|
35
|
+
export function museSessions(options = {}) {
|
|
36
|
+
return {
|
|
37
|
+
name: 'muse',
|
|
38
|
+
where: 'local',
|
|
39
|
+
verified: '1.4.14',
|
|
40
|
+
async list(query = {}) {
|
|
41
|
+
const env = query.env ?? options.env ?? process.env;
|
|
42
|
+
const dir = options.dir ?? path.join(env.XDG_DATA_HOME ?? path.join(homeOf(env), '.local', 'share'), 'muse');
|
|
43
|
+
const found = await rows(path.join(dir, 'session-index.db'), 'sessions', [
|
|
44
|
+
'session_id',
|
|
45
|
+
'session_log_path',
|
|
46
|
+
'workspace_root',
|
|
47
|
+
'model_id',
|
|
48
|
+
'git_branch',
|
|
49
|
+
'title',
|
|
50
|
+
'session_name',
|
|
51
|
+
'first_user_prompt',
|
|
52
|
+
'created_at_us',
|
|
53
|
+
'updated_at_us',
|
|
54
|
+
'msp_kind',
|
|
55
|
+
'status',
|
|
56
|
+
]);
|
|
57
|
+
return select(found
|
|
58
|
+
.filter((row) => (row.msp_kind === undefined || row.msp_kind === 'root') && row.status !== 'corrupt')
|
|
59
|
+
.flatMap((row) => {
|
|
60
|
+
const id = text(row.session_id);
|
|
61
|
+
const updated = number(row.updated_at_us) ?? number(row.created_at_us);
|
|
62
|
+
if (!id || updated === undefined)
|
|
63
|
+
return [];
|
|
64
|
+
const updatedAt = Math.round(updated / 1000);
|
|
65
|
+
const created = number(row.created_at_us);
|
|
66
|
+
return [
|
|
67
|
+
session({
|
|
68
|
+
source: 'muse',
|
|
69
|
+
agent: 'muse',
|
|
70
|
+
id,
|
|
71
|
+
where: 'local',
|
|
72
|
+
cwd: text(row.workspace_root),
|
|
73
|
+
branch: text(row.git_branch),
|
|
74
|
+
title: title(row.session_name) ?? title(row.title),
|
|
75
|
+
firstPrompt: prompt(row.first_user_prompt),
|
|
76
|
+
lastPrompt: prompt(row.first_user_prompt),
|
|
77
|
+
startedAt: created === undefined ? undefined : Math.round(created / 1000),
|
|
78
|
+
updatedAt,
|
|
79
|
+
model: text(row.model_id),
|
|
80
|
+
path: text(row.session_log_path),
|
|
81
|
+
...activeIfRecent(updatedAt),
|
|
82
|
+
}),
|
|
83
|
+
];
|
|
84
|
+
}), query);
|
|
85
|
+
},
|
|
86
|
+
async read(info, readOptions) {
|
|
87
|
+
if (!info.path)
|
|
88
|
+
throw new Error(`Muse names no log for session ${info.id}.`);
|
|
89
|
+
return museTranscript(await transcriptLines(info.path), readOptions);
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/** The turns in the records of a Muse Code `session.jsonl`: the root run's prompts, messages and tool calls. */
|
|
94
|
+
export function museTranscript(lines, options = {}) {
|
|
95
|
+
const builder = transcriptBuilder('muse', options);
|
|
96
|
+
// A call is known by two ids; results name either.
|
|
97
|
+
const calls = new Map();
|
|
98
|
+
for (const line of lines) {
|
|
99
|
+
const payload = isRecord(line) && isRecord(line.payload) ? line.payload : undefined;
|
|
100
|
+
const event = payload && isRecord(payload.event) ? payload.event : undefined;
|
|
101
|
+
if (!payload || !event || payload.kind !== 'run')
|
|
102
|
+
continue;
|
|
103
|
+
if (event.kind === 'started' && text(event.prompt))
|
|
104
|
+
builder.prompt(text(event.prompt));
|
|
105
|
+
if (event.kind === 'assistant_message_committed' && text(event.text))
|
|
106
|
+
builder.text(text(event.text));
|
|
107
|
+
if (event.kind === 'assistant_tool_calls_committed' && Array.isArray(event.tool_calls)) {
|
|
108
|
+
for (const call of event.tool_calls) {
|
|
109
|
+
if (!isRecord(call) || typeof call.name !== 'string')
|
|
110
|
+
continue;
|
|
111
|
+
const id = text(call.call_id) ?? text(call.id);
|
|
112
|
+
for (const alias of [text(call.call_id), text(call.id)])
|
|
113
|
+
if (alias && id)
|
|
114
|
+
calls.set(alias, id);
|
|
115
|
+
builder.tool(id, call.name, jsonOr(call.args));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (event.kind === 'tool_result_batch_committed' && Array.isArray(event.results)) {
|
|
119
|
+
for (const result of event.results) {
|
|
120
|
+
if (!isRecord(result))
|
|
121
|
+
continue;
|
|
122
|
+
builder.toolResult(calls.get(text(result.tool_call_id) ?? ''), text(result.text));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return builder.turns();
|
|
127
|
+
}
|
|
128
|
+
/** A JSON string's value, or the value as it is. */
|
|
129
|
+
function jsonOr(value) {
|
|
130
|
+
if (typeof value !== 'string')
|
|
131
|
+
return value;
|
|
132
|
+
try {
|
|
133
|
+
return JSON.parse(value);
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
return value;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/** `2026-11-07 17:16:46.484148+00:00` as epoch milliseconds. */
|
|
140
|
+
function sqlTime(value) {
|
|
141
|
+
const found = text(value);
|
|
142
|
+
return found ? timeOf(found.replace(' ', 'T').replace(/(\.\d{3})\d+/, '$1')) : undefined;
|
|
143
|
+
}
|
|
144
|
+
function firstFileUri(value) {
|
|
145
|
+
try {
|
|
146
|
+
const uris = JSON.parse(text(value) ?? '[]');
|
|
147
|
+
const uri = Array.isArray(uris)
|
|
148
|
+
? uris.find((entry) => typeof entry === 'string' && entry.startsWith('file://'))
|
|
149
|
+
: undefined;
|
|
150
|
+
return typeof uri === 'string' ? fileURLToPath(uri) : undefined;
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Antigravity: `conversation_summaries.db` in `~/.gemini/antigravity` (shared with the desktop app)
|
|
158
|
+
* and `~/.gemini/antigravity-cli`. Top-level conversations only.
|
|
159
|
+
*/
|
|
160
|
+
export function antigravitySessions(options = {}) {
|
|
161
|
+
return {
|
|
162
|
+
name: 'antigravity',
|
|
163
|
+
where: 'local',
|
|
164
|
+
verified: '1.5.3',
|
|
165
|
+
async list(query = {}) {
|
|
166
|
+
const env = query.env ?? options.env ?? process.env;
|
|
167
|
+
const dirs = options.dir
|
|
168
|
+
? [options.dir]
|
|
169
|
+
: ['antigravity', 'antigravity-cli'].map((name) => path.join(homeOf(env), '.gemini', name));
|
|
170
|
+
const byId = new Map();
|
|
171
|
+
for (const dir of dirs) {
|
|
172
|
+
const found = await rows(path.join(dir, 'conversation_summaries.db'), 'conversation_summaries', [
|
|
173
|
+
'conversation_id',
|
|
174
|
+
'title',
|
|
175
|
+
'preview',
|
|
176
|
+
'last_modified_time',
|
|
177
|
+
'last_user_input_time',
|
|
178
|
+
'workspace_uris',
|
|
179
|
+
'status',
|
|
180
|
+
'nesting_depth',
|
|
181
|
+
'parent_conversation_id',
|
|
182
|
+
]);
|
|
183
|
+
for (const row of found) {
|
|
184
|
+
const id = text(row.conversation_id);
|
|
185
|
+
const updatedAt = sqlTime(row.last_modified_time) ?? sqlTime(row.last_user_input_time);
|
|
186
|
+
if (!id || updatedAt === undefined)
|
|
187
|
+
continue;
|
|
188
|
+
if ((number(row.nesting_depth) ?? 0) > 0 || text(row.parent_conversation_id))
|
|
189
|
+
continue;
|
|
190
|
+
const known = byId.get(id);
|
|
191
|
+
if (known && known.updatedAt >= updatedAt)
|
|
192
|
+
continue;
|
|
193
|
+
const status = text(row.status) ?? '';
|
|
194
|
+
byId.set(id, session({
|
|
195
|
+
source: 'antigravity',
|
|
196
|
+
agent: 'antigravity',
|
|
197
|
+
id,
|
|
198
|
+
where: 'local',
|
|
199
|
+
cwd: firstFileUri(row.workspace_uris),
|
|
200
|
+
title: title(row.title) ?? title(row.preview),
|
|
201
|
+
updatedAt,
|
|
202
|
+
state: status.endsWith('_RUNNING') ? 'active' : status.endsWith('_IDLE') ? 'waiting' : undefined,
|
|
203
|
+
path: path.join(dir, 'brain', id, '.system_generated', 'logs', 'transcript.jsonl'),
|
|
204
|
+
}));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return select([...byId.values()], query);
|
|
208
|
+
},
|
|
209
|
+
async read(info, readOptions) {
|
|
210
|
+
if (!info.path)
|
|
211
|
+
throw new Error(`Session ${info.id} has no transcript file.`);
|
|
212
|
+
return antigravityTranscript(await transcriptLines(info.path), readOptions);
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* The turns in the steps of an Antigravity `transcript.jsonl`. Tool calls carry no ids there: the
|
|
218
|
+
* finished steps after a response are its calls' results, in order.
|
|
219
|
+
*/
|
|
220
|
+
export function antigravityTranscript(lines, options = {}) {
|
|
221
|
+
const builder = transcriptBuilder('antigravity', options);
|
|
222
|
+
let waiting = [];
|
|
223
|
+
let next = 0;
|
|
224
|
+
for (const line of lines) {
|
|
225
|
+
if (!isRecord(line))
|
|
226
|
+
continue;
|
|
227
|
+
const at = timeOf(line.created_at);
|
|
228
|
+
const content = text(line.content);
|
|
229
|
+
if (line.type === 'USER_INPUT') {
|
|
230
|
+
waiting = [];
|
|
231
|
+
if (content)
|
|
232
|
+
builder.prompt(content, at);
|
|
233
|
+
}
|
|
234
|
+
else if (line.type === 'PLANNER_RESPONSE') {
|
|
235
|
+
waiting = [];
|
|
236
|
+
if (content)
|
|
237
|
+
builder.text(content, at);
|
|
238
|
+
for (const call of Array.isArray(line.tool_calls) ? line.tool_calls : []) {
|
|
239
|
+
if (!isRecord(call) || typeof call.name !== 'string')
|
|
240
|
+
continue;
|
|
241
|
+
const id = `step-${next++}`;
|
|
242
|
+
waiting.push(id);
|
|
243
|
+
builder.tool(id, call.name, call.args, at);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
else if (line.type === 'GENERIC' && (line.status === 'DONE' || line.status === 'ERROR')) {
|
|
247
|
+
const id = waiting.shift();
|
|
248
|
+
if (id)
|
|
249
|
+
builder.toolResult(id, content ?? text(line.error), line.status === 'ERROR', at);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return builder.turns();
|
|
253
|
+
}
|
|
254
|
+
/** The flat `key: value` lines of Copilot's `workspace.yaml`. */
|
|
255
|
+
function flatYaml(source) {
|
|
256
|
+
const values = {};
|
|
257
|
+
for (const line of source.split('\n')) {
|
|
258
|
+
const match = /^([A-Za-z_]\w*):\s*(.*)$/.exec(line);
|
|
259
|
+
if (!match)
|
|
260
|
+
continue;
|
|
261
|
+
const raw = match[2].trim();
|
|
262
|
+
values[match[1]] = /^(".*"|'.*')$/.test(raw) ? raw.slice(1, -1) : raw;
|
|
263
|
+
}
|
|
264
|
+
return values;
|
|
265
|
+
}
|
|
266
|
+
/** GitHub Copilot CLI: `~/.copilot/session-state/<id>/workspace.yaml`, with `events.jsonl` where it exists. */
|
|
267
|
+
export function copilotSessions(options = {}) {
|
|
268
|
+
return {
|
|
269
|
+
name: 'copilot',
|
|
270
|
+
where: 'local',
|
|
271
|
+
verified: '1.0.88',
|
|
272
|
+
async list(query = {}) {
|
|
273
|
+
const env = query.env ?? options.env ?? process.env;
|
|
274
|
+
const dir = options.dir ?? path.join(homeOf(env), '.copilot');
|
|
275
|
+
const files = await findFiles(path.join(dir, 'session-state'), 1, (name) => name === 'workspace.yaml');
|
|
276
|
+
// Sessions the CLI's index knows (it kept conversations there before it stopped writing event logs).
|
|
277
|
+
let indexed;
|
|
278
|
+
const ids = (sql) => queryDatabase(path.join(dir, 'session-store.db'), sql).then((found) => (found ?? []).map((row) => String(row.id)), () => []);
|
|
279
|
+
const inIndex = async (id) => (await (indexed ??= Promise.all([
|
|
280
|
+
ids('SELECT id FROM sessions'),
|
|
281
|
+
ids('SELECT DISTINCT session_id AS id FROM turns'),
|
|
282
|
+
]).then((lists) => new Set(lists.flat())))).has(id);
|
|
283
|
+
const found = await mapLimited(files, 16, async (file) => {
|
|
284
|
+
const meta = flatYaml(await fs.readFile(file.path, 'utf8').catch(() => ''));
|
|
285
|
+
const folder = path.dirname(file.path);
|
|
286
|
+
const id = meta.id || path.basename(folder);
|
|
287
|
+
// A workspace with no event log that the index does not know either was opened and left
|
|
288
|
+
// with nothing said (IDEs and ACP clients leave many): nothing to list or continue.
|
|
289
|
+
const logged = await fs.stat(path.join(folder, 'events.jsonl')).then(() => true, () => false);
|
|
290
|
+
if (!logged && !(await inIndex(id)))
|
|
291
|
+
return null;
|
|
292
|
+
const updatedAt = timeOf(meta.updated_at) ?? file.mtimeMs;
|
|
293
|
+
return session({
|
|
294
|
+
source: 'copilot',
|
|
295
|
+
agent: 'copilot',
|
|
296
|
+
id,
|
|
297
|
+
where: 'local',
|
|
298
|
+
cwd: meta.cwd || undefined,
|
|
299
|
+
repository: meta.repository || undefined,
|
|
300
|
+
branch: meta.branch || undefined,
|
|
301
|
+
title: title(meta.name),
|
|
302
|
+
startedAt: timeOf(meta.created_at),
|
|
303
|
+
updatedAt,
|
|
304
|
+
path: path.join(folder, 'events.jsonl'),
|
|
305
|
+
...activeIfRecent(updatedAt),
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
const chosen = select(found.filter((entry) => entry !== null), query);
|
|
309
|
+
await mapLimited(chosen.slice(0, ENRICH), 8, (info) => copilotEvents(info));
|
|
310
|
+
return chosen;
|
|
311
|
+
},
|
|
312
|
+
async read(info, readOptions) {
|
|
313
|
+
// Newer CLIs write no event log: what was said may then be in the CLI's own index.
|
|
314
|
+
const lines = info.path ? await transcriptLines(info.path).catch(() => null) : null;
|
|
315
|
+
if (lines)
|
|
316
|
+
return copilotTranscript(lines, readOptions);
|
|
317
|
+
// The index of the store the session was listed from: <store>/session-state/<id>/events.jsonl.
|
|
318
|
+
const dir = info.path
|
|
319
|
+
? path.resolve(info.path, '../../..')
|
|
320
|
+
: (options.dir ?? path.join(homeOf(options.env ?? process.env), '.copilot'));
|
|
321
|
+
const turns = await queryDatabase(path.join(dir, 'session-store.db'), 'SELECT user_message, assistant_response, timestamp FROM turns WHERE session_id = ? ORDER BY turn_index', [info.id]).catch(() => null);
|
|
322
|
+
const builder = transcriptBuilder('copilot', readOptions);
|
|
323
|
+
for (const turn of turns ?? []) {
|
|
324
|
+
if (!text(turn.user_message))
|
|
325
|
+
continue;
|
|
326
|
+
builder.prompt(text(turn.user_message), timeOf(turn.timestamp));
|
|
327
|
+
if (text(turn.assistant_response))
|
|
328
|
+
builder.text(text(turn.assistant_response));
|
|
329
|
+
}
|
|
330
|
+
const found = builder.turns();
|
|
331
|
+
if (!found.length)
|
|
332
|
+
throw new Error(`Copilot keeps no readable conversation for session ${info.id}.`);
|
|
333
|
+
return found;
|
|
334
|
+
},
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
/** The turns in the lines of a Copilot CLI `events.jsonl`. A subagent's traffic is left out. */
|
|
338
|
+
export function copilotTranscript(lines, options = {}) {
|
|
339
|
+
const builder = transcriptBuilder('copilot', options);
|
|
340
|
+
for (const line of lines) {
|
|
341
|
+
if (!isRecord(line) || !isRecord(line.data))
|
|
342
|
+
continue;
|
|
343
|
+
if (typeof line.agentId === 'string' || typeof line.data.parentToolCallId === 'string')
|
|
344
|
+
continue;
|
|
345
|
+
const at = timeOf(line.timestamp);
|
|
346
|
+
const content = text(line.data.content);
|
|
347
|
+
if (line.type === 'user.message' && content)
|
|
348
|
+
builder.prompt(content, at);
|
|
349
|
+
if (line.type === 'assistant.message' && content)
|
|
350
|
+
builder.text(content, at);
|
|
351
|
+
if (line.type === 'tool.execution_start' && typeof line.data.toolName === 'string') {
|
|
352
|
+
builder.tool(text(line.data.toolCallId), line.data.toolName, line.data.arguments, at);
|
|
353
|
+
}
|
|
354
|
+
if (line.type === 'tool.execution_complete') {
|
|
355
|
+
const result = isRecord(line.data.result) ? text(line.data.result.content) : undefined;
|
|
356
|
+
builder.toolResult(text(line.data.toolCallId), result, line.data.success === false, at);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return builder.turns();
|
|
360
|
+
}
|
|
361
|
+
async function copilotEvents(info) {
|
|
362
|
+
if (!info.path)
|
|
363
|
+
return;
|
|
364
|
+
let stat;
|
|
365
|
+
try {
|
|
366
|
+
stat = await fs.stat(info.path);
|
|
367
|
+
}
|
|
368
|
+
catch {
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
const { head, tail } = await headAndTail({ path: info.path, mtimeMs: stat.mtimeMs, size: stat.size });
|
|
372
|
+
let agentLast = false;
|
|
373
|
+
const scan = (lines, first) => {
|
|
374
|
+
for (const line of lines) {
|
|
375
|
+
if (!isRecord(line) || !isRecord(line.data))
|
|
376
|
+
continue;
|
|
377
|
+
// A subagent's traffic (envelope `agentId`; older CLIs: `data.parentToolCallId`) is not the conversation.
|
|
378
|
+
if (typeof line.agentId === 'string' || typeof line.data.parentToolCallId === 'string')
|
|
379
|
+
continue;
|
|
380
|
+
const content = text(line.data.content);
|
|
381
|
+
if (line.type === 'user.message' && content) {
|
|
382
|
+
if (first)
|
|
383
|
+
info.firstPrompt ??= oneLine(content);
|
|
384
|
+
info.lastPrompt = oneLine(content);
|
|
385
|
+
agentLast = false;
|
|
386
|
+
}
|
|
387
|
+
if (line.type === 'assistant.message') {
|
|
388
|
+
if (content)
|
|
389
|
+
info.lastReply = ending(content);
|
|
390
|
+
info.model = text(line.data.model) ?? info.model;
|
|
391
|
+
agentLast = !!content;
|
|
392
|
+
}
|
|
393
|
+
if (line.type === 'session.model_change')
|
|
394
|
+
info.model = text(line.data.newModel) ?? info.model;
|
|
395
|
+
if (line.type === 'tool.execution_start')
|
|
396
|
+
agentLast = false;
|
|
397
|
+
if (line.type === 'session.task_complete' || line.type === 'session.shutdown')
|
|
398
|
+
agentLast = true;
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
scan(head, true);
|
|
402
|
+
scan(tail, false);
|
|
403
|
+
if (info.state !== 'active')
|
|
404
|
+
info.state = agentLast ? 'waiting' : 'unfinished';
|
|
405
|
+
}
|
|
406
|
+
/** Cursor agent CLI: `~/.cursor/chats/<md5 of cwd>/<id>/meta.json`. */
|
|
407
|
+
export function cursorSessions(options = {}) {
|
|
408
|
+
return {
|
|
409
|
+
name: 'cursor',
|
|
410
|
+
where: 'local',
|
|
411
|
+
verified: '2026.10.22',
|
|
412
|
+
async list(query = {}) {
|
|
413
|
+
const env = query.env ?? options.env ?? process.env;
|
|
414
|
+
const dir = options.dir ?? path.join(homeOf(env), '.cursor');
|
|
415
|
+
const files = await findFiles(path.join(dir, 'chats'), 2, (name) => name === 'meta.json');
|
|
416
|
+
const found = await mapLimited(files, 16, async (file) => {
|
|
417
|
+
const meta = await readJson(file.path);
|
|
418
|
+
if (!isRecord(meta) || meta.hasConversation === false)
|
|
419
|
+
return null;
|
|
420
|
+
const updatedAt = number(meta.updatedAtMs) ?? file.mtimeMs;
|
|
421
|
+
return session({
|
|
422
|
+
source: 'cursor',
|
|
423
|
+
agent: 'cursor',
|
|
424
|
+
id: path.basename(path.dirname(file.path)),
|
|
425
|
+
where: 'local',
|
|
426
|
+
cwd: text(meta.cwd),
|
|
427
|
+
title: title(meta.title),
|
|
428
|
+
startedAt: number(meta.createdAtMs),
|
|
429
|
+
updatedAt,
|
|
430
|
+
path: path.join(path.dirname(file.path), 'store.db'),
|
|
431
|
+
...activeIfRecent(updatedAt),
|
|
432
|
+
});
|
|
433
|
+
});
|
|
434
|
+
const chosen = select(found.filter((entry) => entry !== null), query);
|
|
435
|
+
// The model is in the chat's own database, as hex-encoded JSON (next to a key we do not read out).
|
|
436
|
+
await mapLimited(chosen.slice(0, ENRICH), 4, async (info) => {
|
|
437
|
+
try {
|
|
438
|
+
const [row] = (await queryDatabase(info.path, "SELECT value FROM meta WHERE key = '0'")) ?? [];
|
|
439
|
+
const meta = JSON.parse(Buffer.from(text(row?.value) ?? '', 'hex').toString('utf8'));
|
|
440
|
+
if (isRecord(meta))
|
|
441
|
+
info.model = text(meta.lastUsedModel);
|
|
442
|
+
}
|
|
443
|
+
catch {
|
|
444
|
+
// No database yet, or a layout this reader does not know.
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
return chosen;
|
|
448
|
+
},
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
/** Mistral Vibe: `meta.json` in each `~/.vibe/logs/session/session_...` folder (`VIBE_HOME`). */
|
|
452
|
+
export function vibeSessions(options = {}) {
|
|
453
|
+
return {
|
|
454
|
+
name: 'vibe',
|
|
455
|
+
where: 'local',
|
|
456
|
+
verified: '2.25',
|
|
457
|
+
async list(query = {}) {
|
|
458
|
+
const env = query.env ?? options.env ?? process.env;
|
|
459
|
+
const dir = options.dir ?? env.VIBE_HOME ?? path.join(homeOf(env), '.vibe');
|
|
460
|
+
const files = await findFiles(path.join(dir, 'logs', 'session'), 1, (name) => name === 'meta.json');
|
|
461
|
+
const found = await mapLimited(files, 16, async (file) => {
|
|
462
|
+
const meta = await readJson(file.path);
|
|
463
|
+
if (!isRecord(meta) || !text(meta.session_id))
|
|
464
|
+
return null;
|
|
465
|
+
const stats = isRecord(meta.stats) ? meta.stats : {};
|
|
466
|
+
const input = number(stats.session_prompt_tokens);
|
|
467
|
+
const output = number(stats.session_completion_tokens);
|
|
468
|
+
const cached = number(stats.session_cached_tokens);
|
|
469
|
+
const total = number(stats.session_total_llm_tokens);
|
|
470
|
+
const updatedAt = Math.max(timeOf(meta.end_time) ?? 0, file.mtimeMs);
|
|
471
|
+
return session({
|
|
472
|
+
source: 'vibe',
|
|
473
|
+
agent: 'vibe',
|
|
474
|
+
id: text(meta.session_id),
|
|
475
|
+
where: 'local',
|
|
476
|
+
cwd: isRecord(meta.environment) ? text(meta.environment.working_directory) : undefined,
|
|
477
|
+
branch: text(meta.git_branch),
|
|
478
|
+
title: title(meta.title),
|
|
479
|
+
startedAt: timeOf(meta.start_time),
|
|
480
|
+
updatedAt,
|
|
481
|
+
usage: input === undefined && output === undefined && total === undefined
|
|
482
|
+
? undefined
|
|
483
|
+
: {
|
|
484
|
+
...(input !== undefined ? { inputTokens: input } : {}),
|
|
485
|
+
...(output !== undefined ? { outputTokens: output } : {}),
|
|
486
|
+
...(cached !== undefined ? { cachedInputTokens: cached } : {}),
|
|
487
|
+
...(total !== undefined ? { totalTokens: total } : {}),
|
|
488
|
+
},
|
|
489
|
+
costUsd: number(stats.session_cost),
|
|
490
|
+
path: path.join(path.dirname(file.path), 'messages.jsonl'),
|
|
491
|
+
...activeIfRecent(updatedAt),
|
|
492
|
+
});
|
|
493
|
+
});
|
|
494
|
+
return select(found.filter((entry) => entry !== null), query);
|
|
495
|
+
},
|
|
496
|
+
async read(info, readOptions) {
|
|
497
|
+
if (!info.path)
|
|
498
|
+
throw new Error(`Session ${info.id} has no messages file.`);
|
|
499
|
+
return vibeTranscript(await transcriptLines(info.path), readOptions);
|
|
500
|
+
},
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
/** The turns in the lines of a Vibe `messages.jsonl`. Messages Vibe injected itself are not prompts. */
|
|
504
|
+
export function vibeTranscript(lines, options = {}) {
|
|
505
|
+
const builder = transcriptBuilder('vibe', options);
|
|
506
|
+
for (const line of lines) {
|
|
507
|
+
if (!isRecord(line))
|
|
508
|
+
continue;
|
|
509
|
+
const content = text(line.content);
|
|
510
|
+
if (line.role === 'user' && line.injected !== true && content)
|
|
511
|
+
builder.prompt(content);
|
|
512
|
+
if (line.role === 'assistant') {
|
|
513
|
+
if (content)
|
|
514
|
+
builder.text(content);
|
|
515
|
+
for (const call of Array.isArray(line.tool_calls) ? line.tool_calls : []) {
|
|
516
|
+
if (!isRecord(call) || !isRecord(call.function) || typeof call.function.name !== 'string')
|
|
517
|
+
continue;
|
|
518
|
+
builder.tool(text(call.id), call.function.name, jsonOr(call.function.arguments));
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
if (line.role === 'tool')
|
|
522
|
+
builder.toolResult(text(line.tool_call_id), content);
|
|
523
|
+
}
|
|
524
|
+
return builder.turns();
|
|
525
|
+
}
|
|
526
|
+
/** Gemini CLI: the `session-...jsonl` files in `~/.gemini/tmp/<project>/chats`; `.project_root` beside `chats` names the directory. */
|
|
527
|
+
export function geminiSessions(options = {}) {
|
|
528
|
+
return {
|
|
529
|
+
name: 'gemini',
|
|
530
|
+
where: 'local',
|
|
531
|
+
async list(query = {}) {
|
|
532
|
+
const env = query.env ?? options.env ?? process.env;
|
|
533
|
+
const dir = options.dir ?? path.join(homeOf(env), '.gemini');
|
|
534
|
+
const files = (await findFiles(path.join(dir, 'tmp'), 2, (name) => name.startsWith('session-') && name.endsWith('.jsonl'))).filter((file) => path.basename(path.dirname(file.path)) === 'chats');
|
|
535
|
+
const roots = new Map();
|
|
536
|
+
const rootOf = (project) => {
|
|
537
|
+
let root = roots.get(project);
|
|
538
|
+
if (!root) {
|
|
539
|
+
root = fs.readFile(path.join(project, '.project_root'), 'utf8').then((value) => value.trim() || undefined, () => undefined);
|
|
540
|
+
roots.set(project, root);
|
|
541
|
+
}
|
|
542
|
+
return root;
|
|
543
|
+
};
|
|
544
|
+
const found = await mapLimited(files, 8, async (file) => {
|
|
545
|
+
const { head, tail } = await headAndTail(file).catch(() => ({ head: [], tail: [] }));
|
|
546
|
+
const info = {
|
|
547
|
+
source: 'gemini',
|
|
548
|
+
agent: 'gemini',
|
|
549
|
+
id: '',
|
|
550
|
+
where: 'local',
|
|
551
|
+
updatedAt: file.mtimeMs,
|
|
552
|
+
path: file.path,
|
|
553
|
+
};
|
|
554
|
+
let agentLast = false;
|
|
555
|
+
const scan = (lines, first) => {
|
|
556
|
+
for (const line of lines) {
|
|
557
|
+
if (!isRecord(line))
|
|
558
|
+
continue;
|
|
559
|
+
if (typeof line.sessionId === 'string') {
|
|
560
|
+
// Subagent chats are files of their own, with another `kind`.
|
|
561
|
+
if (line.kind !== undefined && line.kind !== 'main')
|
|
562
|
+
info.id = '';
|
|
563
|
+
else
|
|
564
|
+
info.id = line.sessionId;
|
|
565
|
+
info.startedAt = timeOf(line.startTime) ?? info.startedAt;
|
|
566
|
+
}
|
|
567
|
+
if (line.type === 'user' && Array.isArray(line.content)) {
|
|
568
|
+
const said = line.content
|
|
569
|
+
.flatMap((part) => (isRecord(part) && typeof part.text === 'string' ? [part.text] : []))
|
|
570
|
+
.join('\n')
|
|
571
|
+
.trim();
|
|
572
|
+
if (said) {
|
|
573
|
+
if (first)
|
|
574
|
+
info.firstPrompt ??= oneLine(said);
|
|
575
|
+
info.lastPrompt = oneLine(said);
|
|
576
|
+
agentLast = false;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
if (line.type === 'gemini') {
|
|
580
|
+
const reply = text(line.content);
|
|
581
|
+
if (reply)
|
|
582
|
+
info.lastReply = ending(reply);
|
|
583
|
+
info.model = text(line.model) ?? info.model;
|
|
584
|
+
agentLast = !!reply;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
scan(head, true);
|
|
589
|
+
scan(tail, false);
|
|
590
|
+
if (!info.id)
|
|
591
|
+
return null;
|
|
592
|
+
const cwd = await rootOf(path.dirname(path.dirname(file.path)));
|
|
593
|
+
if (cwd)
|
|
594
|
+
info.cwd = cwd;
|
|
595
|
+
info.state = activeIfRecent(file.mtimeMs).state ?? (agentLast ? 'waiting' : 'unfinished');
|
|
596
|
+
return info;
|
|
597
|
+
});
|
|
598
|
+
return select(found.filter((entry) => entry !== null), query);
|
|
599
|
+
},
|
|
600
|
+
async read(info, readOptions) {
|
|
601
|
+
if (!info.path)
|
|
602
|
+
throw new Error(`Session ${info.id} has no chat file.`);
|
|
603
|
+
return geminiTranscript(await transcriptLines(info.path), readOptions);
|
|
604
|
+
},
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
/** The turns in the lines of a Gemini CLI chat file: what the user and the model said. */
|
|
608
|
+
export function geminiTranscript(lines, options = {}) {
|
|
609
|
+
const builder = transcriptBuilder('gemini', options);
|
|
610
|
+
for (const line of lines) {
|
|
611
|
+
if (!isRecord(line))
|
|
612
|
+
continue;
|
|
613
|
+
const at = timeOf(line.timestamp);
|
|
614
|
+
if (line.type === 'user' && Array.isArray(line.content)) {
|
|
615
|
+
const said = line.content
|
|
616
|
+
.flatMap((part) => (isRecord(part) && typeof part.text === 'string' ? [part.text] : []))
|
|
617
|
+
.join('\n')
|
|
618
|
+
.trim();
|
|
619
|
+
if (said)
|
|
620
|
+
builder.prompt(said, at);
|
|
621
|
+
}
|
|
622
|
+
if (line.type === 'gemini') {
|
|
623
|
+
const reply = text(line.content);
|
|
624
|
+
if (reply)
|
|
625
|
+
builder.text(reply, at);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
return builder.turns();
|
|
629
|
+
}
|
|
630
|
+
//# sourceMappingURL=stores.js.map
|