@xenosystem/primitives 0.7.0 ā 0.8.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/README.md +14 -3
- package/dist/cjs/sessions/cli.js +71 -27
- package/dist/cjs/sessions/convert.d.ts +12 -9
- package/dist/cjs/sessions/convert.js +30 -15
- package/dist/cjs/sessions/index.d.ts +4 -3
- package/dist/cjs/sessions/index.js +10 -1
- package/dist/cjs/sessions/layers.d.ts +28 -0
- package/dist/cjs/sessions/layers.js +126 -0
- package/dist/cjs/sessions/read.d.ts +17 -0
- package/dist/cjs/sessions/read.js +90 -29
- package/dist/cjs/sessions/stores.js +1 -0
- package/dist/cjs/sessions/transcript.d.ts +6 -1
- package/dist/cjs/sessions/transcript.js +30 -18
- package/dist/cjs/sessions/types.d.ts +12 -0
- package/dist/cjs/sessions/write.d.ts +11 -1
- package/dist/cjs/sessions/write.js +21 -3
- package/dist/esm/sessions/cli.js +72 -28
- package/dist/esm/sessions/convert.d.ts +12 -9
- package/dist/esm/sessions/convert.js +31 -18
- package/dist/esm/sessions/index.d.ts +4 -3
- package/dist/esm/sessions/index.js +4 -3
- package/dist/esm/sessions/layers.d.ts +28 -0
- package/dist/esm/sessions/layers.js +121 -0
- package/dist/esm/sessions/read.d.ts +17 -0
- package/dist/esm/sessions/read.js +87 -28
- package/dist/esm/sessions/stores.js +1 -0
- package/dist/esm/sessions/transcript.d.ts +6 -1
- package/dist/esm/sessions/transcript.js +30 -18
- package/dist/esm/sessions/types.d.ts +12 -0
- package/dist/esm/sessions/write.d.ts +11 -1
- package/dist/esm/sessions/write.js +19 -2
- package/native/win32-x64/process.node +0 -0
- package/package.json +1 -1
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.safeSessionId = void 0;
|
|
3
|
+
exports.OUTPUT_KEPT = exports.safeSessionId = void 0;
|
|
4
4
|
exports.agyRequest = agyRequest;
|
|
5
5
|
exports.exportOpencodeSession = exportOpencodeSession;
|
|
6
6
|
exports.listSessions = listSessions;
|
|
7
7
|
exports.findSession = findSession;
|
|
8
|
+
exports.findAnySession = findAnySession;
|
|
9
|
+
exports.newestSessionIn = newestSessionIn;
|
|
8
10
|
exports.readSession = readSession;
|
|
9
11
|
exports.readSubagents = readSubagents;
|
|
10
12
|
exports.resumeArgs = resumeArgs;
|
|
@@ -28,6 +30,12 @@ const SAFE_ID = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
|
28
30
|
const safeSessionId = (id) => typeof id === 'string' && SAFE_ID.test(id) ? id : null;
|
|
29
31
|
exports.safeSessionId = safeSessionId;
|
|
30
32
|
const clip = (s, n = TITLE_CAP) => String(s ?? '').replace(/\s+/g, ' ').trim().slice(0, n);
|
|
33
|
+
/**
|
|
34
|
+
* A tool's output as a reader keeps it: the first 64 KiB. Every use takes far less (a copy keeps 4,000 characters), and keeping all of it
|
|
35
|
+
* held a long session's every file read and build log in memory at once (a real Claude Code session on this machine is 2.5 GB).
|
|
36
|
+
*/
|
|
37
|
+
exports.OUTPUT_KEPT = 65536;
|
|
38
|
+
const kept = (s) => s.length > exports.OUTPUT_KEPT ? `${s.slice(0, exports.OUTPUT_KEPT)}\n⦠[${s.length - exports.OUTPUT_KEPT} more characters not read]` : s;
|
|
31
39
|
const num = (v) => { const n = typeof v === 'number' ? v : Date.parse(String(v ?? '')); return Number.isFinite(n) ? n : 0; };
|
|
32
40
|
async function openReadOnly(path) {
|
|
33
41
|
const { DatabaseSync } = await Promise.resolve().then(() => require('node:sqlite'));
|
|
@@ -165,6 +173,17 @@ const claude = {
|
|
|
165
173
|
if (r.isSidechain)
|
|
166
174
|
return;
|
|
167
175
|
const at = r.timestamp ?? null, c = r.message?.content;
|
|
176
|
+
// š“ A message that arrives while a turn is running is kept as a `queued_command` attachment, not a user record (measured
|
|
177
|
+
// 2026-11-28 on a real session: 271 messages the person typed, 131 from other sessions, 416 job notices; only 3 of the typed ones
|
|
178
|
+
// were also user records). Skipping them dropped the person's own words from every copy.
|
|
179
|
+
const q = r.type === 'attachment' && r.attachment?.type === 'queued_command' ? r.attachment : null;
|
|
180
|
+
if (q) {
|
|
181
|
+
const text = typeof q.prompt === 'string' ? q.prompt : blocksText(q.prompt);
|
|
182
|
+
const last = turns[turns.length - 1];
|
|
183
|
+
if (text.trim() && !(last?.role === 'user' && last.text === text))
|
|
184
|
+
turns.push({ role: 'user', text, at: q.timestamp ?? at, ...(q.origin?.kind === 'human' ? {} : { from: q.origin?.kind === 'peer' ? 'peer' : 'harness' }) });
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
168
187
|
if (r.type === 'system' && r.subtype === 'compact_boundary') {
|
|
169
188
|
turns.push({ role: 'system', text: '[conversation compacted]', compaction: true, at });
|
|
170
189
|
return;
|
|
@@ -183,7 +202,7 @@ const claude = {
|
|
|
183
202
|
if (b?.type === 'text' && !r.isMeta)
|
|
184
203
|
turns.push({ role: 'user', text: b.text, at });
|
|
185
204
|
else if (b?.type === 'tool_result')
|
|
186
|
-
turns.push({ role: 'tool', text: '', callId: b.tool_use_id, output: blocksText(b.content), at });
|
|
205
|
+
turns.push({ role: 'tool', text: '', callId: b.tool_use_id, output: kept(blocksText(b.content)), at });
|
|
187
206
|
}
|
|
188
207
|
}
|
|
189
208
|
else if (r.type === 'assistant') {
|
|
@@ -353,7 +372,7 @@ const codex = {
|
|
|
353
372
|
}
|
|
354
373
|
else if (p.type === 'function_call_output' || p.type === 'custom_tool_call_output') {
|
|
355
374
|
const o = typeof p.output === 'string' ? p.output : p.output?.content ?? JSON.stringify(p.output ?? '');
|
|
356
|
-
turns.push({ role: 'tool', text: '', callId: p.call_id, output: String(o), at });
|
|
375
|
+
turns.push({ role: 'tool', text: '', callId: p.call_id, output: kept(String(o)), at });
|
|
357
376
|
}
|
|
358
377
|
}, opts);
|
|
359
378
|
return turns;
|
|
@@ -382,33 +401,45 @@ function agyRequest(content) {
|
|
|
382
401
|
const m = /<USER_REQUEST>\n?([\s\S]*?)\n?<\/USER_REQUEST>/.exec(content);
|
|
383
402
|
return (m ? m[1] : content.replace(/<(ADDITIONAL_METADATA|USER_SETTINGS_CHANGE)>[\s\S]*?<\/\1>/g, '')).trim();
|
|
384
403
|
}
|
|
404
|
+
/** One Antigravity data folder's conversations: the CLI's and the desktop app's share a layout. */
|
|
405
|
+
async function agyList(h, app) {
|
|
406
|
+
const db = (0, node_path_1.join)(h, 'conversation_summaries.db');
|
|
407
|
+
if (!(0, node_fs_1.existsSync)(db))
|
|
408
|
+
return [];
|
|
409
|
+
const d = await openReadOnly(db);
|
|
410
|
+
try {
|
|
411
|
+
const rows = d.prepare('SELECT conversation_id, title, preview, last_modified_time, workspace_uris, step_count FROM conversation_summaries ORDER BY last_modified_time DESC').all();
|
|
412
|
+
const out = [];
|
|
413
|
+
for (const r of rows) {
|
|
414
|
+
const id = (0, exports.safeSessionId)(r.conversation_id);
|
|
415
|
+
if (!id)
|
|
416
|
+
continue;
|
|
417
|
+
const t = (0, node_path_1.join)(h, 'brain', id, '.system_generated', 'logs', 'transcript_full.jsonl');
|
|
418
|
+
let size = 0;
|
|
419
|
+
try {
|
|
420
|
+
size = (0, node_fs_1.statSync)(t).size;
|
|
421
|
+
}
|
|
422
|
+
catch { /* summary only */ }
|
|
423
|
+
out.push({ vendor: 'agy', id, cwd: fileUri(r.workspace_uris), title: clip(r.title || r.preview) || id, created: 0, updated: num(r.last_modified_time), size, locator: size ? t : '', app });
|
|
424
|
+
}
|
|
425
|
+
return out;
|
|
426
|
+
}
|
|
427
|
+
finally {
|
|
428
|
+
d.close();
|
|
429
|
+
}
|
|
430
|
+
}
|
|
385
431
|
const agy = {
|
|
386
432
|
vendor: 'agy',
|
|
387
433
|
async list({ stores }) {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
const
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
for (const r of rows) {
|
|
396
|
-
const id = (0, exports.safeSessionId)(r.conversation_id);
|
|
397
|
-
if (!id)
|
|
398
|
-
continue;
|
|
399
|
-
const t = (0, node_path_1.join)(h, 'brain', id, '.system_generated', 'logs', 'transcript_full.jsonl');
|
|
400
|
-
let size = 0;
|
|
401
|
-
try {
|
|
402
|
-
size = (0, node_fs_1.statSync)(t).size;
|
|
403
|
-
}
|
|
404
|
-
catch { /* summary only */ }
|
|
405
|
-
out.push({ vendor: 'agy', id, cwd: fileUri(r.workspace_uris), title: clip(r.title || r.preview) || id, created: 0, updated: num(r.last_modified_time), size, locator: size ? t : '' });
|
|
406
|
-
}
|
|
407
|
-
return out;
|
|
408
|
-
}
|
|
409
|
-
finally {
|
|
410
|
-
d.close();
|
|
434
|
+
// The desktop app's store is read too (where people mostly use Antigravity); an id kept by both is listed once, newest copy.
|
|
435
|
+
const all = [...await agyList(stores.agy, 'Antigravity CLI'), ...(stores.agyDesktop ? await agyList(stores.agyDesktop, 'Antigravity') : [])];
|
|
436
|
+
const byId = new Map();
|
|
437
|
+
for (const s of all) {
|
|
438
|
+
const seen = byId.get(s.id);
|
|
439
|
+
if (!seen || s.updated > seen.updated)
|
|
440
|
+
byId.set(s.id, s);
|
|
411
441
|
}
|
|
442
|
+
return [...byId.values()];
|
|
412
443
|
},
|
|
413
444
|
async read(ref, _ctx, opts = {}) {
|
|
414
445
|
if (!ref.locator)
|
|
@@ -430,7 +461,7 @@ const agy = {
|
|
|
430
461
|
turns.push({ role: 'assistant', text: '', tool: c.name, input: c.args, at });
|
|
431
462
|
}
|
|
432
463
|
else if (s.type === 'GENERIC' && s.content)
|
|
433
|
-
turns.push({ role: 'tool', text: '', output: s.content, at });
|
|
464
|
+
turns.push({ role: 'tool', text: '', output: kept(String(s.content)), at });
|
|
434
465
|
else if (s.type === 'CHECKPOINT')
|
|
435
466
|
turns.push({ role: 'system', text: '[conversation checkpoint]', compaction: true, at });
|
|
436
467
|
}, opts);
|
|
@@ -481,7 +512,7 @@ const opencode = {
|
|
|
481
512
|
else if (p.type === 'tool') {
|
|
482
513
|
turns.push({ role: 'assistant', text: '', tool: p.tool, callId: p.callID, input: p.state?.input, at });
|
|
483
514
|
if (p.state?.output != null)
|
|
484
|
-
turns.push({ role: 'tool', text: '', callId: p.callID, output: String(p.state.output), at });
|
|
515
|
+
turns.push({ role: 'tool', text: '', callId: p.callID, output: kept(String(p.state.output)), at });
|
|
485
516
|
}
|
|
486
517
|
}
|
|
487
518
|
}
|
|
@@ -525,7 +556,7 @@ const xenoAgent = {
|
|
|
525
556
|
else if (e.type === 'tool_call')
|
|
526
557
|
turns.push({ role: 'assistant', text: '', tool: d.toolName, callId: d.id ?? e.id, input: d.input, at });
|
|
527
558
|
else if (e.type === 'tool_result')
|
|
528
|
-
turns.push({ role: 'tool', text: '', callId: d.callId ?? d.id, output: String(d.output ?? ''), at });
|
|
559
|
+
turns.push({ role: 'tool', text: '', callId: d.callId ?? d.id, output: kept(String(d.output ?? '')), at });
|
|
529
560
|
}, opts);
|
|
530
561
|
return turns;
|
|
531
562
|
},
|
|
@@ -568,6 +599,36 @@ async function findSession(vendor, id, ctx) {
|
|
|
568
599
|
throw new Error(`${want} matches ${hits.length} ${vendor} sessions; give more of its id.`);
|
|
569
600
|
throw new Error(`${vendor} has no session ${want} on this machine.`);
|
|
570
601
|
}
|
|
602
|
+
/**
|
|
603
|
+
* Find a session by its id alone, in whichever agent keeps it: ids are unique across agents (UUIDs, `ses_ā¦`, `xeno-copy-ā¦`), so the
|
|
604
|
+
* agent is read from the store that has it. A prefix matching sessions of two agents is refused, never guessed; an agent whose store
|
|
605
|
+
* cannot be read is named when nothing is found, since the session may be there.
|
|
606
|
+
*/
|
|
607
|
+
async function findAnySession(id, ctx, { except } = {}) {
|
|
608
|
+
const want = String(id ?? '').trim();
|
|
609
|
+
if (!(0, exports.safeSessionId)(want))
|
|
610
|
+
throw new Error('That is not a session id.');
|
|
611
|
+
const results = await Promise.all(types_ts_1.VENDORS.filter((v) => v !== except).map((v) => listSessions(v, ctx)));
|
|
612
|
+
const all = results.flatMap((r) => r.sessions);
|
|
613
|
+
const exact = all.filter((s) => s.id === want);
|
|
614
|
+
if (exact.length === 1)
|
|
615
|
+
return exact[0];
|
|
616
|
+
const hits = exact.length ? exact : want.length >= 8 ? all.filter((s) => s.id.toLowerCase().startsWith(want.toLowerCase())) : [];
|
|
617
|
+
if (hits.length === 1)
|
|
618
|
+
return hits[0];
|
|
619
|
+
if (hits.length > 1)
|
|
620
|
+
throw new Error(`${want} matches ${hits.length} sessions (${hits.map((s) => `${s.vendor} ${s.id.slice(0, 12)}`).join(', ')}); give more of its id, or name the agent.`);
|
|
621
|
+
const unread = results.filter((r) => r.error).map((r) => `${r.vendor} (${r.error})`);
|
|
622
|
+
throw new Error(`No session ${want} on this machine.${unread.length ? ` These could not be read: ${unread.join('; ')}.` : ''}`);
|
|
623
|
+
}
|
|
624
|
+
/** The most recently used session whose folder is `cwd` (compared the way the OS does: case-insensitive on Windows), in any agent but `except`. */
|
|
625
|
+
async function newestSessionIn(cwd, ctx, { except } = {}) {
|
|
626
|
+
const norm = (p) => { const r = p.replace(/[\\/]+$/, ''); return process.platform === 'win32' ? r.replace(/\//g, '\\').toLowerCase() : r; };
|
|
627
|
+
const here = norm(cwd);
|
|
628
|
+
const results = await Promise.all(types_ts_1.VENDORS.filter((v) => v !== except).map((v) => listSessions(v, ctx)));
|
|
629
|
+
const mine = results.flatMap((r) => r.sessions).filter((s) => s.cwd && norm(s.cwd) === here).sort((a, b) => b.updated - a.updated);
|
|
630
|
+
return mine[0] ?? null;
|
|
631
|
+
}
|
|
571
632
|
/** A session's transcript as Turns. */
|
|
572
633
|
function readSession(ref, ctx, o = {}) { return readerOf(ref.vendor).read(ref, ctx, o); }
|
|
573
634
|
/** A session's sub-agent conversations, for agents that keep them separately (Claude Code); none for the others. */
|
|
@@ -15,6 +15,7 @@ function defaultStores(home = (0, host_ts_1.hostHome)(), env = (0, host_ts_1.hos
|
|
|
15
15
|
claude: env.CLAUDE_CONFIG_DIR || (0, node_path_1.join)(home, '.claude'),
|
|
16
16
|
codex: env.CODEX_HOME || (0, node_path_1.join)(home, '.codex'),
|
|
17
17
|
agy: (0, node_path_1.join)(home, '.gemini', 'antigravity-cli'),
|
|
18
|
+
agyDesktop: (0, node_path_1.join)(home, '.gemini', 'antigravity'),
|
|
18
19
|
// xeno-dirs-allow: opencode's own data folder, by opencode's own XDG rule; read where opencode writes it, never a XENO path
|
|
19
20
|
opencode: (0, node_path_1.join)(env.XDG_DATA_HOME || (0, node_path_1.join)(home, '.local', 'share'), 'opencode'),
|
|
20
21
|
// xeno-dirs-allow: the XENO agent still writes its sessions here (ADOPTION.md: xeno-agent-cli sessions "not moved"); read where they are until it moves them to agents/sessions
|
|
@@ -26,6 +26,8 @@ export interface Report {
|
|
|
26
26
|
total: number;
|
|
27
27
|
subagents: number;
|
|
28
28
|
subagentTurns: number;
|
|
29
|
+
/** The earliest messages left out of the copy itself because the conversation is over the copy limit (the end is always kept). */
|
|
30
|
+
omitted: number;
|
|
29
31
|
}
|
|
30
32
|
export interface Transcript {
|
|
31
33
|
messages: Message[];
|
|
@@ -33,6 +35,9 @@ export interface Transcript {
|
|
|
33
35
|
}
|
|
34
36
|
export declare const OUTPUT_CAP = 4000, TOTAL_CAP = 1500000;
|
|
35
37
|
export declare const cap: (s: string, n: number) => string;
|
|
36
|
-
|
|
38
|
+
/** @param opts.fullRecord where the whole conversation is kept, named in the copy when its earliest messages are left out. */
|
|
39
|
+
export declare function toTranscript(turns: Turn[], subagents?: Subagent[], opts?: {
|
|
40
|
+
fullRecord?: string;
|
|
41
|
+
}): Transcript;
|
|
37
42
|
/** What the move loses, in plain words, for a person to read before it runs. */
|
|
38
43
|
export declare function losses(report: Report, target: string, handoff: boolean): string[];
|
|
@@ -14,9 +14,10 @@ catch {
|
|
|
14
14
|
} };
|
|
15
15
|
const cap = (s, n) => s.length > n ? `${s.slice(0, n)}\n⦠[${s.length - n} more characters not copied]` : s;
|
|
16
16
|
exports.cap = cap;
|
|
17
|
-
|
|
17
|
+
/** @param opts.fullRecord where the whole conversation is kept, named in the copy when its earliest messages are left out. */
|
|
18
|
+
function toTranscript(turns, subagents = [], opts = {}) {
|
|
18
19
|
const msgs = [];
|
|
19
|
-
const report = { userTurns: 0, assistantTurns: 0, toolCalls: 0, toolResults: 0, thinkingDropped: 0, compactions: 0, truncated: 0, total: 0, subagents: subagents.length, subagentTurns: 0 };
|
|
20
|
+
const report = { userTurns: 0, assistantTurns: 0, toolCalls: 0, toolResults: 0, thinkingDropped: 0, compactions: 0, truncated: 0, total: 0, subagents: subagents.length, subagentTurns: 0, omitted: 0 };
|
|
20
21
|
const outputs = new Map();
|
|
21
22
|
const calls = new Set();
|
|
22
23
|
for (const t of turns) {
|
|
@@ -34,13 +35,19 @@ function toTranscript(turns, subagents = []) {
|
|
|
34
35
|
else
|
|
35
36
|
msgs.push({ role, text, at: at ?? null });
|
|
36
37
|
};
|
|
38
|
+
let inCompaction = false;
|
|
37
39
|
for (const t of turns) {
|
|
38
40
|
if (t.thinking) {
|
|
39
41
|
report.thinkingDropped++;
|
|
40
42
|
continue;
|
|
41
43
|
}
|
|
44
|
+
// Claude Code records one compaction twice, a boundary and then its summary: counted once (a real session read 128 for 62).
|
|
45
|
+
if (!t.compaction)
|
|
46
|
+
inCompaction = false;
|
|
42
47
|
if (t.compaction) {
|
|
43
|
-
|
|
48
|
+
if (!inCompaction)
|
|
49
|
+
report.compactions++;
|
|
50
|
+
inCompaction = true;
|
|
44
51
|
push('user', `[Earlier context was compacted by the original agent]${t.text && t.text !== '[conversation compacted]' && t.text !== '[conversation checkpoint]' ? `\n${t.text}` : ''}`, t.at);
|
|
45
52
|
continue;
|
|
46
53
|
}
|
|
@@ -73,22 +80,25 @@ function toTranscript(turns, subagents = []) {
|
|
|
73
80
|
if (lines.length)
|
|
74
81
|
push('assistant', `[sub-agent ${sa.name}, which ran separately in the original session]\n${(0, exports.cap)(lines.join('\n'), 6000)}`, null);
|
|
75
82
|
}
|
|
76
|
-
//
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
// š“ Over the limit, the END is kept: it is where the conversation stopped and what the next agent continues. Keeping the start (as
|
|
84
|
+
// 0.7.0 did) dropped exactly that, so a long session's copy resumed weeks back. What is left out is named, with where to read it.
|
|
85
|
+
let total = 0, from = msgs.length;
|
|
86
|
+
while (from > 0 && total + msgs[from - 1].text.length <= exports.TOTAL_CAP)
|
|
87
|
+
total += msgs[--from].text.length;
|
|
88
|
+
if (from === msgs.length && msgs.length)
|
|
89
|
+
from--; // one message larger than the limit is still carried, shortened below
|
|
90
|
+
const kept = msgs.slice(from);
|
|
91
|
+
if (kept.length === 1 && kept[0].text.length > exports.TOTAL_CAP)
|
|
92
|
+
kept[0] = { ...kept[0], text: `⦠${kept[0].text.slice(-exports.TOTAL_CAP)}` };
|
|
93
|
+
report.omitted = from;
|
|
94
|
+
if (from) {
|
|
95
|
+
const where = opts.fullRecord ? ` The whole conversation, those included, is in ${opts.fullRecord}: read it when you need something from earlier.` : '';
|
|
96
|
+
kept.unshift({ role: 'user', text: `[The ${from} earliest messages are not in this copy: the conversation is longer than a copy can carry, so the most recent part was kept.${where}]`, at: null });
|
|
88
97
|
}
|
|
98
|
+
// Not every agent accepts a conversation that opens with the assistant: give it a leading user turn.
|
|
99
|
+
if (kept[0]?.role === 'assistant')
|
|
100
|
+
kept.unshift({ role: 'user', text: '[Conversation copied from another agent. It continues below.]', at: kept[0].at });
|
|
89
101
|
report.total = kept.length;
|
|
90
|
-
if (kept.length < msgs.length)
|
|
91
|
-
kept.push({ role: 'user', text: `[${msgs.length - kept.length} later messages were not copied: the conversation exceeded the copy limit]`, at: null });
|
|
92
102
|
return { messages: kept, report };
|
|
93
103
|
}
|
|
94
104
|
/** What the move loses, in plain words, for a person to read before it runs. */
|
|
@@ -97,8 +107,10 @@ function losses(report, target, handoff) {
|
|
|
97
107
|
return [
|
|
98
108
|
report.thinkingDropped && `${report.thinkingDropped} thinking block${s(report.thinkingDropped)} dropped (signed by the original agent; never forged)`,
|
|
99
109
|
report.toolCalls && `${report.toolCalls} tool call${s(report.toolCalls)} ${report.toolCalls === 1 ? 'becomes' : 'become'} labelled text (${target} cannot re-run another agent's tools)`,
|
|
110
|
+
// A hand-over IS the full record, so only a resumable copy leaves anything out.
|
|
111
|
+
!handoff && report.omitted && `the ${report.omitted} earliest message${s(report.omitted)} left out of the resumable copy (over the copy limit; it keeps the most recent part and points to the full record of the whole conversation, written beside it)`,
|
|
100
112
|
report.truncated && `${report.truncated} long output${s(report.truncated)} shortened`,
|
|
101
|
-
report.compactions && `${report.compactions} compaction${s(report.compactions)} kept as markers`,
|
|
113
|
+
report.compactions && `${report.compactions} compaction${s(report.compactions)} kept as markers${handoff ? ', their summaries indexed in compactions.md' : ''}`,
|
|
102
114
|
report.subagents && `${report.subagents} sub-agent${s(report.subagents)} carried as labelled summaries (${report.subagentTurns} messages; their tool calls are not copied)`,
|
|
103
115
|
handoff && `${target} cannot import a conversation: it starts a NEW one with this transcript as context`,
|
|
104
116
|
].filter((x) => typeof x === 'string');
|
|
@@ -16,6 +16,8 @@ export interface SessionRef {
|
|
|
16
16
|
updated: number;
|
|
17
17
|
size: number;
|
|
18
18
|
locator: string;
|
|
19
|
+
/** Which of the agent's own apps keeps it, where one agent has two (agy: "Antigravity" for the desktop app, "Antigravity CLI"). */
|
|
20
|
+
app?: string;
|
|
19
21
|
}
|
|
20
22
|
/**
|
|
21
23
|
* One step of a conversation. A tool call is an assistant turn with `tool`; its result is a `tool` turn with the same `callId`.
|
|
@@ -33,6 +35,11 @@ export interface Turn {
|
|
|
33
35
|
thinking?: boolean;
|
|
34
36
|
turnEnd?: boolean;
|
|
35
37
|
compaction?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* A user turn the person did not type, where the agent records who sent it: another session's message ('peer') or the agent's own
|
|
40
|
+
* harness (a finished background job, 'harness'). Absent for the person's own words.
|
|
41
|
+
*/
|
|
42
|
+
from?: 'peer' | 'harness';
|
|
36
43
|
}
|
|
37
44
|
/** A sub-agent's own conversation, which some agents (Claude Code) keep in separate files. */
|
|
38
45
|
export interface Subagent {
|
|
@@ -47,6 +54,11 @@ export interface Stores {
|
|
|
47
54
|
codex: string;
|
|
48
55
|
/** agy's (Antigravity CLI) data folder (`conversation_summaries.db`, `brain/`). */
|
|
49
56
|
agy: string;
|
|
57
|
+
/**
|
|
58
|
+
* The Antigravity desktop app's data folder, the same layout as the CLI's (measured 2026-11-28: one `conversation_summaries` schema,
|
|
59
|
+
* `brain/<id>/.system_generated/logs/transcript_full.jsonl`). Both are read as agy; optional so a caller's own Stores still type-check.
|
|
60
|
+
*/
|
|
61
|
+
agyDesktop?: string;
|
|
50
62
|
/** opencode's data folder (`opencode.db`). */
|
|
51
63
|
opencode: string;
|
|
52
64
|
/** The XENO agent's home (`sessions/`). */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Message } from './transcript.ts';
|
|
2
|
-
import type { Runner, SessionRef, Stores, Vendor } from './types.ts';
|
|
2
|
+
import type { Runner, SessionRef, Stores, Subagent, Turn, Vendor } from './types.ts';
|
|
3
3
|
/** How each agent takes a copy, and whether it can resume it as its own conversation. */
|
|
4
4
|
export declare const TARGETS: Readonly<Record<Vendor, {
|
|
5
5
|
fidelity: 'native' | 'handoff';
|
|
@@ -27,7 +27,17 @@ export interface WriteContext {
|
|
|
27
27
|
workDir: string;
|
|
28
28
|
/** Called with each artifact the moment it exists, before the next step, so a crash still leaves an accurate list. */
|
|
29
29
|
record?: (a: Artifact) => void;
|
|
30
|
+
/**
|
|
31
|
+
* The original conversation as read, for the layered record written beside the copy (`<workDir>/transcript/`): the index, the
|
|
32
|
+
* person's messages, the latest stretch in full, the compactions and the whole dialog. Without it agy gets the single 0.7.0 document.
|
|
33
|
+
*/
|
|
34
|
+
layers?: {
|
|
35
|
+
turns: Turn[];
|
|
36
|
+
subagents: Subagent[];
|
|
37
|
+
};
|
|
30
38
|
}
|
|
39
|
+
/** Where a conversion keeps the layered record of the original, inside its own folder. */
|
|
40
|
+
export declare const transcriptDir: (workDir: string) => string;
|
|
31
41
|
export interface Written {
|
|
32
42
|
id: string | null;
|
|
33
43
|
cwd: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.slugForCwd = exports.TARGETS = void 0;
|
|
3
|
+
exports.slugForCwd = exports.transcriptDir = exports.TARGETS = void 0;
|
|
4
4
|
exports.writeNew = writeNew;
|
|
5
5
|
exports.claudeLines = claudeLines;
|
|
6
6
|
exports.handoffDocument = handoffDocument;
|
|
@@ -16,9 +16,11 @@ exports.writeSession = writeSession;
|
|
|
16
16
|
* private home (it reads only Claude files under its detection root)
|
|
17
17
|
* opencode `opencode import <export.json>`, recording a model opencode itself lists
|
|
18
18
|
* XENO agent `sessions/<id>/{meta.json,transcript.jsonl}` in its documented layout
|
|
19
|
-
* agy no ingestion path exists (its
|
|
19
|
+
* agy no ingestion path exists (its list is a SQLite table the running app writes, each conversation eight tables of
|
|
20
|
+
* undocumented protobuf; measured 2026-11-28) ā a HANDOFF: the full record, layered, with an index a new agy
|
|
20
21
|
* conversation is asked to read, declared as such
|
|
21
|
-
* Every
|
|
22
|
+
* Every copy also carries the full record of the original in `<workDir>/transcript/` (layers.ts), so nothing the copy itself cannot
|
|
23
|
+
* hold is lost. Every file is created exclusively at its final name, so nothing that exists is ever replaced.
|
|
22
24
|
*/
|
|
23
25
|
const node_crypto_1 = require("node:crypto");
|
|
24
26
|
const node_fs_1 = require("node:fs");
|
|
@@ -26,6 +28,7 @@ const node_path_1 = require("node:path");
|
|
|
26
28
|
const run_ts_1 = require("./run.js");
|
|
27
29
|
const read_ts_1 = require("./read.js");
|
|
28
30
|
const transcript_ts_1 = require("./transcript.js");
|
|
31
|
+
const layers_ts_1 = require("./layers.js");
|
|
29
32
|
/** How each agent takes a copy, and whether it can resume it as its own conversation. */
|
|
30
33
|
exports.TARGETS = Object.freeze({
|
|
31
34
|
'Claude Code': { fidelity: 'native', via: "a new session file in Claude Code's own layout" },
|
|
@@ -34,6 +37,9 @@ exports.TARGETS = Object.freeze({
|
|
|
34
37
|
'XENO agent': { fidelity: 'native', via: "a new session in the XENO agent's own layout" },
|
|
35
38
|
agy: { fidelity: 'handoff', via: 'a new conversation given the transcript as context (agy has no import)' },
|
|
36
39
|
});
|
|
40
|
+
/** Where a conversion keeps the layered record of the original, inside its own folder. */
|
|
41
|
+
const transcriptDir = (workDir) => (0, node_path_1.join)(workDir, 'transcript');
|
|
42
|
+
exports.transcriptDir = transcriptDir;
|
|
37
43
|
/** Claude Code's project folder name for a working folder. */
|
|
38
44
|
const slugForCwd = (cwd) => (0, node_path_1.resolve)(cwd).split(node_path_1.sep).join('-').replace(/[^A-Za-z0-9]/g, '-');
|
|
39
45
|
exports.slugForCwd = slugForCwd;
|
|
@@ -150,6 +156,14 @@ async function writeSession(target, msgs, source, ctx) {
|
|
|
150
156
|
(0, node_fs_1.mkdirSync)(ctx.workDir);
|
|
151
157
|
record({ kind: 'workdir', path: ctx.workDir });
|
|
152
158
|
const title = `Copy of ${source.title || source.id}`.slice(0, 160);
|
|
159
|
+
let index = null;
|
|
160
|
+
if (ctx.layers) {
|
|
161
|
+
const dir = (0, exports.transcriptDir)(ctx.workDir), l = (0, layers_ts_1.buildLayers)(ctx.layers.turns, ctx.layers.subagents, source, dir);
|
|
162
|
+
for (const f of l.files)
|
|
163
|
+
writeNew((0, node_path_1.join)(dir, f.name), f.text);
|
|
164
|
+
index = (0, node_path_1.join)(dir, l.readme.name);
|
|
165
|
+
writeNew(index, l.readme.text);
|
|
166
|
+
}
|
|
153
167
|
if (target === 'Claude Code') {
|
|
154
168
|
const sid = (0, node_crypto_1.randomUUID)(), file = (0, node_path_1.join)(ctx.stores.claude, 'projects', (0, exports.slugForCwd)(cwd), `${sid}.jsonl`);
|
|
155
169
|
writeNew(file, claudeLines(msgs, sid, cwd));
|
|
@@ -208,6 +222,10 @@ async function writeSession(target, msgs, source, ctx) {
|
|
|
208
222
|
return { id: sid, cwd, artifacts, resume: ['--resume', sid] };
|
|
209
223
|
}
|
|
210
224
|
// agy
|
|
225
|
+
if (index) {
|
|
226
|
+
record({ kind: 'file', path: index });
|
|
227
|
+
return { id: null, cwd, artifacts, handoff: { file: index, prompt: (0, layers_ts_1.layersPrompt)(index, source.vendor) } };
|
|
228
|
+
}
|
|
211
229
|
const doc = handoffDocument(msgs, source);
|
|
212
230
|
const file = (0, node_path_1.join)(ctx.workDir, 'handoff.md');
|
|
213
231
|
writeNew(file, doc.full);
|
package/dist/esm/sessions/cli.js
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// xeno-sessions
|
|
3
|
-
// xeno-sessions
|
|
4
|
-
// xeno-sessions
|
|
2
|
+
// xeno-sessions to <agent> [<id>] [--dry-run] copy a session into another agent: by its id, or this folder's newest session
|
|
3
|
+
// xeno-sessions list [--agent <name>] [--json] every agent session on this machine, newest first
|
|
4
|
+
// xeno-sessions plan [<agent>] <id> --to <agent> what a conversion would copy and lose; writes nothing
|
|
5
|
+
// xeno-sessions convert [<agent>] <id> --to <agent> the long form of `to` (the original is never written)
|
|
5
6
|
// xeno-sessions copies [--json] the copies this command made
|
|
6
7
|
// xeno-sessions remove <copy-id> remove exactly what one copy created
|
|
7
8
|
//
|
|
8
|
-
// Agents: "Claude Code" (or claude), Codex (codex), agy, opencode, "XENO agent" (xeno).
|
|
9
|
-
//
|
|
9
|
+
// Agents: "Claude Code" (or claude), Codex (codex), agy (or antigravity: the desktop app and the CLI), opencode, "XENO agent" (xeno).
|
|
10
|
+
// An id may be its first 8 or more characters, and its agent may be left out: it is found from the id (owner, 2026-11-28: "quick and
|
|
11
|
+
// fast commands"). A copy's record, its staging files and the full record of the original live in the XENO local home:
|
|
12
|
+
// state/agents/sessions/conversions/.
|
|
10
13
|
import { randomUUID } from 'node:crypto';
|
|
11
14
|
import { existsSync, readdirSync, readFileSync, unlinkSync } from 'node:fs';
|
|
12
15
|
import { createDirs } from "../dirs/dirs.js";
|
|
13
16
|
import { atomicWriteFile } from "../dirs/atomic.js";
|
|
14
17
|
import { convertSession, planConversion, removeArtifacts } from "./convert.js";
|
|
15
|
-
import { listSessions } from "./read.js";
|
|
18
|
+
import { listSessions, newestSessionIn } from "./read.js";
|
|
16
19
|
import { runAgent } from "./run.js";
|
|
17
20
|
import { defaultStores } from "./stores.js";
|
|
18
21
|
import { VENDORS } from "./types.js";
|
|
@@ -23,14 +26,23 @@ const vendorOf = (s) => {
|
|
|
23
26
|
throw new Error(`Unknown agent: ${s ?? '(none)'}. Known: ${VENDORS.join(', ')}.`);
|
|
24
27
|
return v;
|
|
25
28
|
};
|
|
29
|
+
const isVendor = (s) => VENDORS.some((x) => x.toLowerCase() === s.toLowerCase()) || s.toLowerCase() in ALIASES;
|
|
26
30
|
const argv = process.argv.slice(2);
|
|
27
31
|
const flag = (name) => { const i = argv.indexOf(name); if (i < 0)
|
|
28
32
|
return undefined; const v = argv[i + 1]; argv.splice(i, 2); return v; };
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
const bool = (name) => { const i = argv.indexOf(name); if (i < 0)
|
|
34
|
+
return false; argv.splice(i, 1); return true; };
|
|
35
|
+
const json = bool('--json');
|
|
32
36
|
const out = (v) => console.log(JSON.stringify(v, null, 2));
|
|
33
37
|
const ago = (ms) => { const s = (Date.now() - ms) / 1000; return s < 3600 ? `${Math.max(1, Math.round(s / 60))}m` : s < 86400 ? `${Math.round(s / 3600)}h` : `${Math.round(s / 86400)}d`; };
|
|
38
|
+
const command = (v) => v === 'Claude Code' ? 'claude' : v === 'XENO agent' ? 'xeno' : v.toLowerCase();
|
|
39
|
+
function printPlan(plan) {
|
|
40
|
+
console.log(`${plan.source.vendor} ${plan.source.id}${plan.source.title ? ` "${plan.source.title}"` : ''} ā ${plan.target} (${plan.fidelity}: ${plan.via})`);
|
|
41
|
+
// A turn is everything one side said before the other answered, so many replies and tool steps in a row are one turn of the copy.
|
|
42
|
+
console.log(` ${plan.report.userTurns} messages from the person, ${plan.report.assistantTurns} replies and ${plan.report.toolCalls} tool calls, carried as ${plan.report.total} turns`);
|
|
43
|
+
for (const l of plan.losses)
|
|
44
|
+
console.log(` - ${l}`);
|
|
45
|
+
}
|
|
34
46
|
async function main() {
|
|
35
47
|
const ctx = { stores: defaultStores(), run: runAgent };
|
|
36
48
|
const dirs = createDirs();
|
|
@@ -47,30 +59,60 @@ async function main() {
|
|
|
47
59
|
for (const r of results) {
|
|
48
60
|
console.log(`${r.vendor}: ${r.error ? `cannot be read (${r.error})` : `${r.sessions.length} session${r.sessions.length === 1 ? '' : 's'}`}`);
|
|
49
61
|
for (const s of r.sessions.slice(0, only ? 200 : 10))
|
|
50
|
-
console.log(` ${s.id.slice(0, 12).padEnd(12)} ${ago(s.updated).padStart(4)} ${s.title.slice(0, 70)}${s.cwd ? ` (${s.cwd})` : ''}`);
|
|
62
|
+
console.log(` ${s.id.slice(0, 12).padEnd(12)} ${ago(s.updated).padStart(4)} ${s.title.slice(0, 70)}${s.app && s.app !== r.vendor ? ` [${s.app}]` : ''}${s.cwd ? ` (${s.cwd})` : ''}`);
|
|
51
63
|
}
|
|
52
64
|
return 0;
|
|
53
65
|
}
|
|
54
|
-
|
|
66
|
+
let source = null, target = null, dryRun = false;
|
|
67
|
+
if (cmd === 'to') {
|
|
68
|
+
dryRun = bool('--dry-run');
|
|
69
|
+
const [to, id] = rest.filter((x) => !x.startsWith('--'));
|
|
70
|
+
if (!to) {
|
|
71
|
+
console.error('usage: xeno-sessions to <agent> [<id>] [--dry-run]');
|
|
72
|
+
return 2;
|
|
73
|
+
}
|
|
74
|
+
target = vendorOf(to);
|
|
75
|
+
if (id)
|
|
76
|
+
source = { id };
|
|
77
|
+
else {
|
|
78
|
+
const here = await newestSessionIn(process.cwd(), ctx, { except: target });
|
|
79
|
+
if (!here) {
|
|
80
|
+
console.error(`No session of another agent was used in ${process.cwd()}. Give its id (xeno-sessions list shows them).`);
|
|
81
|
+
return 1;
|
|
82
|
+
}
|
|
83
|
+
if (!json)
|
|
84
|
+
console.error(`This folder's newest session: ${here.vendor} ${here.id} "${here.title}" (${ago(here.updated)} ago)`);
|
|
85
|
+
source = { vendor: here.vendor, id: here.id };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else if (cmd === 'plan' || cmd === 'convert') {
|
|
55
89
|
const to = flag('--to');
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
90
|
+
const words = rest.filter((x) => !x.startsWith('--'));
|
|
91
|
+
const [agent, id] = words.length >= 2 ? words : [undefined, words[0]];
|
|
92
|
+
if (!id || !to) {
|
|
93
|
+
console.error(`usage: xeno-sessions ${cmd} [<agent>] <id> --to <agent>`);
|
|
59
94
|
return 2;
|
|
60
95
|
}
|
|
61
|
-
|
|
96
|
+
if (agent && !isVendor(agent)) {
|
|
97
|
+
console.error(`Unknown agent: ${agent}. Known: ${VENDORS.join(', ')}.`);
|
|
98
|
+
return 2;
|
|
99
|
+
}
|
|
100
|
+
source = agent ? { vendor: vendorOf(agent), id } : { id };
|
|
101
|
+
target = vendorOf(to);
|
|
102
|
+
dryRun = cmd === 'plan';
|
|
103
|
+
}
|
|
104
|
+
if (source && target) {
|
|
62
105
|
const plan = await planConversion(source, target, ctx);
|
|
63
|
-
if (
|
|
64
|
-
if (json)
|
|
106
|
+
if (dryRun) {
|
|
107
|
+
if (json)
|
|
65
108
|
out(plan);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
console.log(`${plan.source.vendor} ${plan.source.id} ā ${plan.target} (${plan.fidelity}: ${plan.via})`);
|
|
69
|
-
console.log(` ${plan.report.total} messages: ${plan.report.userTurns} from the user, ${plan.report.assistantTurns} replies, ${plan.report.toolCalls} tool calls`);
|
|
70
|
-
for (const l of plan.losses)
|
|
71
|
-
console.log(` - ${l}`);
|
|
109
|
+
else
|
|
110
|
+
printPlan(plan);
|
|
72
111
|
return 0;
|
|
73
112
|
}
|
|
113
|
+
if (!json)
|
|
114
|
+
printPlan(plan);
|
|
115
|
+
const exact = { vendor: plan.source.vendor, id: plan.source.id };
|
|
74
116
|
const cid = randomUUID(), base = copiesDir(), record = `${base}/${cid}.json`;
|
|
75
117
|
const artifacts = [];
|
|
76
118
|
const save = (extra) => atomicWriteFile(record, JSON.stringify({ schema: 1, id: cid, created: new Date().toISOString(), source: plan.source, target: plan.target, fidelity: plan.fidelity, losses: plan.losses, artifacts, ...extra }, null, 2) + '\n');
|
|
@@ -78,17 +120,19 @@ async function main() {
|
|
|
78
120
|
const queue = (extra) => { saving = saving.then(() => save(extra)); return saving; };
|
|
79
121
|
await saving;
|
|
80
122
|
try {
|
|
81
|
-
const done = await convertSession(
|
|
123
|
+
const done = await convertSession(exact, target, { ...ctx, workDir: `${base}/${cid}`, record: (a) => { artifacts.push(a); void queue({ failed: true }); }, onStep: (s) => { if (!json)
|
|
82
124
|
console.error(s); } });
|
|
83
|
-
await queue({ targetId: done.written.id, open: done.written.resume ? { resume: done.written.resume } : { handoff: done.written.handoff }, sourceSha256: done.sourceSha256 });
|
|
125
|
+
await queue({ targetId: done.written.id, open: done.written.resume ? { resume: done.written.resume } : { handoff: done.written.handoff }, sourceSha256: done.sourceSha256, record: `${base}/${cid}/transcript` });
|
|
84
126
|
if (json) {
|
|
85
127
|
out({ copy: cid, ...done });
|
|
86
128
|
return 0;
|
|
87
129
|
}
|
|
130
|
+
console.log(`The original is unchanged (sha256 ${done.sourceSha256.slice(0, 16)}ā¦, the same before and after).`);
|
|
88
131
|
if (done.written.resume)
|
|
89
|
-
console.log(`Copied. Continue it with: ${target
|
|
132
|
+
console.log(`Copied. Continue it with: ${command(target)} ${done.written.resume.join(' ')} (in ${done.written.cwd})`);
|
|
90
133
|
else if (done.written.handoff)
|
|
91
|
-
console.log(`
|
|
134
|
+
console.log(`Antigravity has no import, so it gets the full record and an index: ${done.written.handoff.file}\nOpen ${done.written.cwd} in Antigravity (or start agy there) and give it this prompt:\n ${done.written.handoff.prompt}`);
|
|
135
|
+
console.log(`The full record of the original: ${base}/${cid}/transcript`);
|
|
92
136
|
console.log(`Copy id ${cid} (remove it with: xeno-sessions remove ${cid})`);
|
|
93
137
|
return 0;
|
|
94
138
|
}
|
|
@@ -144,7 +188,7 @@ async function main() {
|
|
|
144
188
|
console.log(`Removed copy ${cid}.`);
|
|
145
189
|
return 0;
|
|
146
190
|
}
|
|
147
|
-
console.error('usage: xeno-sessions list | plan <agent> <id> --to <agent> | convert <agent> <id> --to <agent> | copies | remove <copy-id>');
|
|
191
|
+
console.error('usage: xeno-sessions to <agent> [<id>] [--dry-run] | list | plan [<agent>] <id> --to <agent> | convert [<agent>] <id> --to <agent> | copies | remove <copy-id>');
|
|
148
192
|
return cmd ? 2 : 0;
|
|
149
193
|
}
|
|
150
194
|
main().then((code) => { process.exitCode = code; }, (e) => { console.error(e instanceof Error ? e.message : String(e)); process.exitCode = 1; });
|