@yaks/session 0.0.0-stage → 0.2.36
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/LICENSE +202 -0
- package/README.md +1392 -2
- package/_dist/admission.d.ts +15 -0
- package/_dist/admission.d.ts.map +1 -0
- package/_dist/announce.d.ts +17 -0
- package/_dist/announce.d.ts.map +1 -0
- package/_dist/answer.d.ts +200 -0
- package/_dist/answer.d.ts.map +1 -0
- package/_dist/append.d.ts +10 -0
- package/_dist/append.d.ts.map +1 -0
- package/_dist/archive.d.ts +6 -0
- package/_dist/archive.d.ts.map +1 -0
- package/_dist/asks.d.ts +11 -0
- package/_dist/asks.d.ts.map +1 -0
- package/_dist/audit.d.ts +15 -0
- package/_dist/audit.d.ts.map +1 -0
- package/_dist/bounce.d.ts +19 -0
- package/_dist/bounce.d.ts.map +1 -0
- package/_dist/bus.d.ts +8 -0
- package/_dist/bus.d.ts.map +1 -0
- package/_dist/cache.d.ts +45 -0
- package/_dist/cache.d.ts.map +1 -0
- package/_dist/child-notice.d.ts +6 -0
- package/_dist/child-notice.d.ts.map +1 -0
- package/_dist/children.d.ts +59 -0
- package/_dist/children.d.ts.map +1 -0
- package/_dist/cli.d.ts +8 -0
- package/_dist/cli.d.ts.map +1 -0
- package/_dist/comp.d.ts +9 -0
- package/_dist/comp.d.ts.map +1 -0
- package/_dist/compact.d.ts +19 -0
- package/_dist/compact.d.ts.map +1 -0
- package/_dist/conversation.d.ts +158 -0
- package/_dist/conversation.d.ts.map +1 -0
- package/_dist/cost.d.ts +13 -0
- package/_dist/cost.d.ts.map +1 -0
- package/_dist/deferred.d.ts +79 -0
- package/_dist/deferred.d.ts.map +1 -0
- package/_dist/ended.d.ts +27 -0
- package/_dist/ended.d.ts.map +1 -0
- package/_dist/files.d.ts +73 -0
- package/_dist/files.d.ts.map +1 -0
- package/_dist/fork.d.ts +23 -0
- package/_dist/fork.d.ts.map +1 -0
- package/_dist/graft.d.ts +33 -0
- package/_dist/graft.d.ts.map +1 -0
- package/_dist/graph.d.ts +14 -0
- package/_dist/graph.d.ts.map +1 -0
- package/_dist/handoff.d.ts +29 -0
- package/_dist/handoff.d.ts.map +1 -0
- package/_dist/imported.d.ts +63 -0
- package/_dist/imported.d.ts.map +1 -0
- package/_dist/intake.d.ts +43 -0
- package/_dist/intake.d.ts.map +1 -0
- package/_dist/joined.d.ts +35 -0
- package/_dist/joined.d.ts.map +1 -0
- package/_dist/lease.d.ts +21 -0
- package/_dist/lease.d.ts.map +1 -0
- package/_dist/lines.d.ts +13 -0
- package/_dist/lines.d.ts.map +1 -0
- package/_dist/mod.d.ts +107 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/naming.d.ts +10 -0
- package/_dist/naming.d.ts.map +1 -0
- package/_dist/native.d.ts +13 -0
- package/_dist/native.d.ts.map +1 -0
- package/_dist/parts.d.ts +145 -0
- package/_dist/parts.d.ts.map +1 -0
- package/_dist/plugin.d.ts +33 -0
- package/_dist/plugin.d.ts.map +1 -0
- package/_dist/project.d.ts +67 -0
- package/_dist/project.d.ts.map +1 -0
- package/_dist/prose.d.ts +7 -0
- package/_dist/prose.d.ts.map +1 -0
- package/_dist/providers.d.ts +36 -0
- package/_dist/providers.d.ts.map +1 -0
- package/_dist/reach.d.ts +39 -0
- package/_dist/reach.d.ts.map +1 -0
- package/_dist/react.d.ts +236 -0
- package/_dist/react.d.ts.map +1 -0
- package/_dist/readers.d.ts +221 -0
- package/_dist/readers.d.ts.map +1 -0
- package/_dist/reap.d.ts +21 -0
- package/_dist/reap.d.ts.map +1 -0
- package/_dist/recall.d.ts +32 -0
- package/_dist/recall.d.ts.map +1 -0
- package/_dist/routes.d.ts +15 -0
- package/_dist/routes.d.ts.map +1 -0
- package/_dist/run.d.ts +81 -0
- package/_dist/run.d.ts.map +1 -0
- package/_dist/service.d.ts +131 -0
- package/_dist/service.d.ts.map +1 -0
- package/_dist/source.d.ts +9 -0
- package/_dist/source.d.ts.map +1 -0
- package/_dist/start.d.ts +29 -0
- package/_dist/start.d.ts.map +1 -0
- package/_dist/state.d.ts +75 -0
- package/_dist/state.d.ts.map +1 -0
- package/_dist/status.d.ts +38 -0
- package/_dist/status.d.ts.map +1 -0
- package/_dist/tail.d.ts +121 -0
- package/_dist/tail.d.ts.map +1 -0
- package/_dist/timing.d.ts +9 -0
- package/_dist/timing.d.ts.map +1 -0
- package/_dist/told.d.ts +17 -0
- package/_dist/told.d.ts.map +1 -0
- package/_dist/tools.d.ts +41 -0
- package/_dist/tools.d.ts.map +1 -0
- package/_dist/transcript.d.ts +5 -0
- package/_dist/transcript.d.ts.map +1 -0
- package/_dist/turn.d.ts +49 -0
- package/_dist/turn.d.ts.map +1 -0
- package/_dist/unknown.d.ts +6 -0
- package/_dist/unknown.d.ts.map +1 -0
- package/_dist/views.d.ts +9 -0
- package/_dist/views.d.ts.map +1 -0
- package/_dist/vocab.d.ts +9 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/_dist/wait.d.ts +15 -0
- package/_dist/wait.d.ts.map +1 -0
- package/_dist/wake.d.ts +116 -0
- package/_dist/wake.d.ts.map +1 -0
- package/_dist/watch.d.ts +52 -0
- package/_dist/watch.d.ts.map +1 -0
- package/_dist/who.d.ts +84 -0
- package/_dist/who.d.ts.map +1 -0
- package/_dist/window.d.ts +43 -0
- package/_dist/window.d.ts.map +1 -0
- package/admission.js +137 -0
- package/admission.js.map +1 -0
- package/admission.ts +164 -0
- package/announce.js +123 -0
- package/announce.js.map +1 -0
- package/announce.ts +126 -0
- package/answer.js +372 -0
- package/answer.js.map +1 -0
- package/answer.ts +426 -0
- package/append.js +125 -0
- package/append.js.map +1 -0
- package/append.ts +205 -0
- package/archive.js +62 -0
- package/archive.js.map +1 -0
- package/archive.ts +62 -0
- package/asks.js +80 -0
- package/asks.js.map +1 -0
- package/asks.ts +106 -0
- package/attempt.js +46 -0
- package/attempt.js.map +1 -0
- package/attempt.ts +60 -0
- package/audit.js +57 -0
- package/audit.js.map +1 -0
- package/audit.ts +65 -0
- package/bounce.js +29 -0
- package/bounce.js.map +1 -0
- package/bounce.ts +34 -0
- package/bus.js +568 -0
- package/bus.js.map +1 -0
- package/bus.ts +683 -0
- package/cache.js +169 -0
- package/cache.js.map +1 -0
- package/cache.ts +230 -0
- package/child-notice.js +128 -0
- package/child-notice.js.map +1 -0
- package/child-notice.ts +136 -0
- package/children.js +937 -0
- package/children.js.map +1 -0
- package/children.ts +925 -0
- package/claude-control.js +8 -0
- package/claude-control.js.map +1 -0
- package/claude-control.ts +12 -0
- package/cli.js +23 -0
- package/cli.js.map +1 -0
- package/cli.ts +28 -0
- package/comp.js +76 -0
- package/comp.js.map +1 -0
- package/comp.ts +78 -0
- package/compact.js +157 -0
- package/compact.js.map +1 -0
- package/compact.ts +209 -0
- package/compact_ask.js +280 -0
- package/compact_ask.js.map +1 -0
- package/compact_ask.ts +199 -0
- package/continue.js +131 -0
- package/continue.js.map +1 -0
- package/continue.ts +143 -0
- package/conversation.js +337 -0
- package/conversation.js.map +1 -0
- package/conversation.ts +593 -0
- package/cost.js +111 -0
- package/cost.js.map +1 -0
- package/cost.ts +93 -0
- package/deferred.js +207 -0
- package/deferred.js.map +1 -0
- package/deferred.ts +219 -0
- package/deno.json +1 -0
- package/dependencies.js +114 -0
- package/dependencies.js.map +1 -0
- package/dependencies.ts +110 -0
- package/draining.js +20 -0
- package/draining.js.map +1 -0
- package/draining.ts +26 -0
- package/ended.js +210 -0
- package/ended.js.map +1 -0
- package/ended.ts +225 -0
- package/files.js +285 -0
- package/files.js.map +1 -0
- package/files.ts +318 -0
- package/fork.js +96 -0
- package/fork.js.map +1 -0
- package/fork.ts +124 -0
- package/graft.js +97 -0
- package/graft.js.map +1 -0
- package/graft.ts +88 -0
- package/graph.js +49 -0
- package/graph.js.map +1 -0
- package/graph.ts +61 -0
- package/handoff.js +111 -0
- package/handoff.js.map +1 -0
- package/handoff.ts +147 -0
- package/help.js +432 -0
- package/help.js.map +1 -0
- package/help.ts +431 -0
- package/hooks.js +253 -0
- package/hooks.js.map +1 -0
- package/hooks.ts +333 -0
- package/imported.js +259 -0
- package/imported.js.map +1 -0
- package/imported.ts +201 -0
- package/inspect.js +353 -0
- package/inspect.js.map +1 -0
- package/inspect.ts +378 -0
- package/intake.js +115 -0
- package/intake.js.map +1 -0
- package/intake.ts +124 -0
- package/joined.js +67 -0
- package/joined.js.map +1 -0
- package/joined.ts +69 -0
- package/lease.js +146 -0
- package/lease.js.map +1 -0
- package/lease.ts +151 -0
- package/lifecycle.js +49 -0
- package/lifecycle.js.map +1 -0
- package/lifecycle.ts +46 -0
- package/lines.js +171 -0
- package/lines.js.map +1 -0
- package/lines.ts +177 -0
- package/listen.js +604 -0
- package/listen.js.map +1 -0
- package/listen.ts +976 -0
- package/log.js +78 -0
- package/log.js.map +1 -0
- package/log.ts +88 -0
- package/mod.js +107 -0
- package/mod.js.map +1 -0
- package/mod.ts +113 -0
- package/name.js +51 -0
- package/name.js.map +1 -0
- package/name.ts +84 -0
- package/naming.js +96 -0
- package/naming.js.map +1 -0
- package/naming.ts +102 -0
- package/native.js +17 -0
- package/native.js.map +1 -0
- package/native.ts +17 -0
- package/package.json +133 -4
- package/parts.js +334 -0
- package/parts.js.map +1 -0
- package/parts.ts +383 -0
- package/plugin.js +77 -0
- package/plugin.js.map +1 -0
- package/plugin.ts +98 -0
- package/project.js +354 -0
- package/project.js.map +1 -0
- package/project.ts +407 -0
- package/prompt.js +57 -0
- package/prompt.js.map +1 -0
- package/prompt.ts +92 -0
- package/prose.js +43 -0
- package/prose.js.map +1 -0
- package/prose.ts +63 -0
- package/providers.js +279 -0
- package/providers.js.map +1 -0
- package/providers.ts +306 -0
- package/pruning.js +80 -0
- package/pruning.js.map +1 -0
- package/pruning.ts +147 -0
- package/reach.js +923 -0
- package/reach.js.map +1 -0
- package/reach.ts +1107 -0
- package/react.js +2259 -0
- package/react.js.map +1 -0
- package/react.ts +2864 -0
- package/readers.js +956 -0
- package/readers.js.map +1 -0
- package/readers.ts +1017 -0
- package/reap.js +60 -0
- package/reap.js.map +1 -0
- package/reap.ts +65 -0
- package/recall.js +67 -0
- package/recall.js.map +1 -0
- package/recall.ts +114 -0
- package/reopen.js +45 -0
- package/reopen.js.map +1 -0
- package/reopen.ts +44 -0
- package/result-entry.js +32 -0
- package/result-entry.js.map +1 -0
- package/result-entry.ts +34 -0
- package/resume.js +266 -0
- package/resume.js.map +1 -0
- package/resume.ts +283 -0
- package/routes.js +129 -0
- package/routes.js.map +1 -0
- package/routes.ts +147 -0
- package/routine.js +179 -0
- package/routine.js.map +1 -0
- package/routine.ts +191 -0
- package/run.js +932 -0
- package/run.js.map +1 -0
- package/run.ts +999 -0
- package/service.js +806 -0
- package/service.js.map +1 -0
- package/service.ts +911 -0
- package/source.js +26 -0
- package/source.js.map +1 -0
- package/source.ts +40 -0
- package/start.js +197 -0
- package/start.js.map +1 -0
- package/start.ts +214 -0
- package/state.js +247 -0
- package/state.js.map +1 -0
- package/state.ts +404 -0
- package/status.js +1222 -0
- package/status.js.map +1 -0
- package/status.ts +1555 -0
- package/status_bench.ts +50 -0
- package/statusline.js +187 -0
- package/statusline.js.map +1 -0
- package/statusline.ts +232 -0
- package/tail.js +748 -0
- package/tail.js.map +1 -0
- package/tail.ts +815 -0
- package/talk.js +58 -0
- package/talk.js.map +1 -0
- package/talk.ts +51 -0
- package/task-context.js +41 -0
- package/task-context.js.map +1 -0
- package/task-context.ts +53 -0
- package/texted.js +65 -0
- package/texted.js.map +1 -0
- package/texted.ts +65 -0
- package/timing.js +37 -0
- package/timing.js.map +1 -0
- package/timing.ts +52 -0
- package/told.js +56 -0
- package/told.js.map +1 -0
- package/told.ts +54 -0
- package/tools.js +595 -0
- package/tools.js.map +1 -0
- package/tools.ts +633 -0
- package/transcript.js +34 -0
- package/transcript.js.map +1 -0
- package/transcript.ts +41 -0
- package/turn.js +47 -0
- package/turn.js.map +1 -0
- package/turn.ts +68 -0
- package/unknown.js +8 -0
- package/unknown.js.map +1 -0
- package/unknown.ts +9 -0
- package/views.js +15 -0
- package/views.js.map +1 -0
- package/views.ts +21 -0
- package/vocab.js +24 -0
- package/vocab.js.map +1 -0
- package/vocab.json +1573 -0
- package/vocab.ts +30 -0
- package/wait.js +30 -0
- package/wait.js.map +1 -0
- package/wait.ts +45 -0
- package/wake.js +552 -0
- package/wake.js.map +1 -0
- package/wake.ts +597 -0
- package/watch.js +520 -0
- package/watch.js.map +1 -0
- package/watch.ts +596 -0
- package/who.js +309 -0
- package/who.js.map +1 -0
- package/who.ts +347 -0
- package/window.js +179 -0
- package/window.js.map +1 -0
- package/window.ts +268 -0
- package/woken.js +129 -0
- package/woken.js.map +1 -0
- package/woken.ts +127 -0
package/files.js
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
// The transcript files each CLI keeps: discovery and the first metadata line.
|
|
2
|
+
// Discovery describes sources; the bounded session duty decides when to read.
|
|
3
|
+
import * as fs from "@yaks/file/io";
|
|
4
|
+
import * as systemProcess from "@yaks/process/system";
|
|
5
|
+
import { identityEid } from "@yaks/graph/identity";
|
|
6
|
+
import { accountEid, accountHome, ACCOUNTS } from "@yaks/model";
|
|
7
|
+
// The directory under an account that holds its transcripts.
|
|
8
|
+
let KEEPS = {
|
|
9
|
+
claude: 'projects',
|
|
10
|
+
codex: 'sessions',
|
|
11
|
+
grok: 'sessions',
|
|
12
|
+
antigravity: 'brain'
|
|
13
|
+
};
|
|
14
|
+
/** The account a CLI signs in with in an environment, this process's by
|
|
15
|
+
* default: the directory its variable names, else its own under the home
|
|
16
|
+
* directory (`~/.claude`, `~/.codex`, `~/.grok`,
|
|
17
|
+
* `~/.gemini/antigravity-cli`). */ export let home = (runner, env = systemProcess.env)=>accountHome(runner, (name)=>env.get(name));
|
|
18
|
+
/** Where an account keeps its transcripts: Claude Code's `projects`, Codex's
|
|
19
|
+
* and Grok's `sessions`, Antigravity's `brain`. */ export let transcriptsOf = (h)=>`${h.dir}/${KEEPS[h.runner]}`;
|
|
20
|
+
/** Where a Claude Code account keeps one file per running process, naming
|
|
21
|
+
* its session. */ export let runningOf = (h)=>`${h.dir}/sessions`;
|
|
22
|
+
let isDir = async (path)=>{
|
|
23
|
+
try {
|
|
24
|
+
return (await fs.stat(path)).isDirectory;
|
|
25
|
+
} catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
// Which CLI's account a directory is by its name: `~/.claude-work` is
|
|
30
|
+
// Claude Code's, `~/.grok` Grok's.
|
|
31
|
+
let named = (dir)=>dir.match(/\/\.(claude|codex|grok)[^/]*$/)?.[1] ?? (dir.endsWith('/antigravity-cli') ? 'antigravity' : undefined);
|
|
32
|
+
// Which CLI's account a directory listed by hand is, by its name or else by
|
|
33
|
+
// what it holds: Claude Code keeps `projects`, Antigravity `brain`, Codex
|
|
34
|
+
// `sessions`.
|
|
35
|
+
let kindOf = async (dir)=>named(dir) ?? (await isDir(`${dir}/projects`) ? 'claude' : await isDir(`${dir}/brain`) ? 'antigravity' : await isDir(`${dir}/sessions`) ? 'codex' : undefined);
|
|
36
|
+
/**
|
|
37
|
+
* Every account on this machine that holds transcripts: the directories
|
|
38
|
+
* `listed` names and, unless `find` is false, the ones the environment (this
|
|
39
|
+
* process's by default) signs in with and each `~/.claude*`, `~/.codex*` and
|
|
40
|
+
* `~/.grok*` directory. Someone
|
|
41
|
+
* with several accounts keeps each in a directory of its own
|
|
42
|
+
* (`CLAUDE_CONFIG_DIR=~/.claude-work`), so each is found on its own.
|
|
43
|
+
*
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { homes } from './files.ts'
|
|
46
|
+
*
|
|
47
|
+
* // await homes(['/Volumes/work/claude']) — [{ runner: 'claude', dir }, …]
|
|
48
|
+
* ```
|
|
49
|
+
*/ export let homes = async (listed = [], find = true, env = systemProcess.env)=>{
|
|
50
|
+
let at = env.get('HOME');
|
|
51
|
+
let expand = (dir)=>dir.replace(/^~(?=\/|$)/, at ?? '~').replace(/(.)\/+$/, '$1');
|
|
52
|
+
let found = find && at ? (await list(at)).filter((f)=>f.isDirectory).map((f)=>`${at}/${f.name}`).filter(named).sort() : [];
|
|
53
|
+
let out = new Map();
|
|
54
|
+
let add = async (runner, dir)=>{
|
|
55
|
+
if (!runner || !dir || out.has(dir)) return;
|
|
56
|
+
if (await isDir(transcriptsOf({
|
|
57
|
+
runner,
|
|
58
|
+
dir
|
|
59
|
+
}))) {
|
|
60
|
+
out.set(dir, {
|
|
61
|
+
runner,
|
|
62
|
+
dir
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
if (find) {
|
|
67
|
+
for (let runner of Object.keys(ACCOUNTS)){
|
|
68
|
+
await add(runner, home(runner, env));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
for (let dir of listed.map(expand))await add(await kindOf(dir), dir);
|
|
72
|
+
for (let dir of found)await add(named(dir), dir);
|
|
73
|
+
return [
|
|
74
|
+
...out.values()
|
|
75
|
+
];
|
|
76
|
+
};
|
|
77
|
+
/** The rows that name accounts: each one's `account`, and its provider's. */ export let accountRows = (from)=>{
|
|
78
|
+
let providers = [
|
|
79
|
+
...new Set(from.map((h)=>h.runner))
|
|
80
|
+
];
|
|
81
|
+
return [
|
|
82
|
+
...providers.map((name)=>({
|
|
83
|
+
entity: {
|
|
84
|
+
eid: identityEid('provider', [
|
|
85
|
+
name
|
|
86
|
+
])
|
|
87
|
+
},
|
|
88
|
+
provider: {
|
|
89
|
+
name
|
|
90
|
+
}
|
|
91
|
+
})),
|
|
92
|
+
...from.map((h)=>({
|
|
93
|
+
entity: {
|
|
94
|
+
eid: accountEid(h.dir)
|
|
95
|
+
},
|
|
96
|
+
account: {
|
|
97
|
+
home: h.dir,
|
|
98
|
+
provider: identityEid('provider', [
|
|
99
|
+
h.runner
|
|
100
|
+
])
|
|
101
|
+
}
|
|
102
|
+
}))
|
|
103
|
+
];
|
|
104
|
+
};
|
|
105
|
+
/** Every transcript the accounts keep, each with its account: Claude Code's
|
|
106
|
+
* by {@link transcripts}, Codex's by {@link rollouts}, Grok's by
|
|
107
|
+
* {@link grokSessions} and Antigravity's by {@link conversations}. */ export let held = async (from)=>(await Promise.all(from.map(async (h)=>{
|
|
108
|
+
let found = await LISTS[h.runner](transcriptsOf(h));
|
|
109
|
+
let account = accountEid(h.dir);
|
|
110
|
+
return found.map((f)=>({
|
|
111
|
+
...f,
|
|
112
|
+
account
|
|
113
|
+
}));
|
|
114
|
+
}))).flat();
|
|
115
|
+
/**
|
|
116
|
+
* Move a thread's transcript from one account of a CLI to another, at the
|
|
117
|
+
* same place under the other's transcripts, so the CLI signed in there
|
|
118
|
+
* carries the thread on (`claude --resume`, `codex resume`). Its subagents'
|
|
119
|
+
* transcripts stay where they were read from. Whether it was found to move.
|
|
120
|
+
*
|
|
121
|
+
* ```ts
|
|
122
|
+
* import { moveThread } from './files.ts'
|
|
123
|
+
*
|
|
124
|
+
* // await moveThread({ runner: 'claude', dir: '~/.claude-a' }, '~/.claude-b', id)
|
|
125
|
+
* ```
|
|
126
|
+
*/ export let moveThread = async (from, to, thread)=>{
|
|
127
|
+
let [found] = (await held([
|
|
128
|
+
from
|
|
129
|
+
])).filter((f)=>f.id == thread && !f.parent);
|
|
130
|
+
if (!found) return false;
|
|
131
|
+
let path = to + found.path.slice(from.dir.length);
|
|
132
|
+
await fs.mkdir(path.slice(0, path.lastIndexOf('/')), {
|
|
133
|
+
recursive: true
|
|
134
|
+
});
|
|
135
|
+
await fs.rename(found.path, path);
|
|
136
|
+
return true;
|
|
137
|
+
};
|
|
138
|
+
/** What a compressed transcript is at a moment: its size and when it was
|
|
139
|
+
* written. A read that reached its end records this as `transcript.finished`. */ export let versionOf = (file)=>file ? `${file.size}:${file.mtime?.getTime() ?? 0}` : '';
|
|
140
|
+
/** Every transcript under a Claude projects directory: the sessions', then
|
|
141
|
+
* their subagents'. Listed a directory at a time, so the thread runs its
|
|
142
|
+
* timers between them: a box keeps thousands. */ export let transcripts = async (dir)=>{
|
|
143
|
+
let out = [];
|
|
144
|
+
let agents = [];
|
|
145
|
+
for (let project of (await list(dir))){
|
|
146
|
+
if (!project.isDirectory) continue;
|
|
147
|
+
let at = `${dir}/${project.name}`;
|
|
148
|
+
for (let f of (await list(at))){
|
|
149
|
+
if (f.isFile && f.name.endsWith('.jsonl')) {
|
|
150
|
+
out.push({
|
|
151
|
+
id: f.name.slice(0, -'.jsonl'.length),
|
|
152
|
+
path: `${at}/${f.name}`
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
if (!f.isDirectory) continue;
|
|
156
|
+
for (let a of (await list(`${at}/${f.name}/subagents`))){
|
|
157
|
+
let id = a.name.match(/^agent-(.+)\.jsonl$/)?.[1];
|
|
158
|
+
if (!a.isFile || !id) continue;
|
|
159
|
+
let path = `${at}/${f.name}/subagents/${a.name}`;
|
|
160
|
+
agents.push({
|
|
161
|
+
id,
|
|
162
|
+
path,
|
|
163
|
+
parent: f.name
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return [
|
|
169
|
+
...out,
|
|
170
|
+
...agents
|
|
171
|
+
];
|
|
172
|
+
};
|
|
173
|
+
// A directory's entries; none where it is missing or unreadable.
|
|
174
|
+
let list = async (dir)=>{
|
|
175
|
+
try {
|
|
176
|
+
return await Array.fromAsync(fs.readDir(dir));
|
|
177
|
+
} catch {
|
|
178
|
+
return [];
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
// Rollouts are dated YYYY/MM/DD, and the filename carries the thread UUID.
|
|
182
|
+
// The same bounded look follows both providers; no second duty scans them.
|
|
183
|
+
export let rollouts = async (dir, depth = 0)=>{
|
|
184
|
+
let files = await list(dir);
|
|
185
|
+
let names = new Set(files.map((f)=>f.name));
|
|
186
|
+
let found = [];
|
|
187
|
+
for (let f of files){
|
|
188
|
+
let path = `${dir}/${f.name}`;
|
|
189
|
+
if (f.isDirectory && depth < 3 && /^\d+$/.test(f.name)) {
|
|
190
|
+
found.push(...await rollouts(path, depth + 1));
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
let id = f.name.match(/^rollout-.+-([\da-f]{8}-(?:[\da-f]{4}-){3}[\da-f]{12})\.jsonl(?:\.zst)?$/i)?.[1];
|
|
194
|
+
if (!f.isFile || !id) continue;
|
|
195
|
+
if (f.name.endsWith('.zst') && names.has(f.name.slice(0, -4))) continue;
|
|
196
|
+
found.push({
|
|
197
|
+
id,
|
|
198
|
+
path,
|
|
199
|
+
runner: 'codex'
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
return found;
|
|
203
|
+
};
|
|
204
|
+
// Only the header is needed to identify a child. Never read its whole log
|
|
205
|
+
// merely to open a tail; the importer will read the remaining bytes once.
|
|
206
|
+
export let header = (path)=>{
|
|
207
|
+
let file = fs.openSync(path);
|
|
208
|
+
try {
|
|
209
|
+
let buf = new Uint8Array(4096), text = '', dec = new TextDecoder();
|
|
210
|
+
for(let n = file.readSync(buf); n; n = file.readSync(buf)){
|
|
211
|
+
text += dec.decode(buf.subarray(0, n), {
|
|
212
|
+
stream: true
|
|
213
|
+
});
|
|
214
|
+
if (text.includes('\n')) {
|
|
215
|
+
try {
|
|
216
|
+
return JSON.parse(text.split('\n')[0]).payload ?? {};
|
|
217
|
+
} catch {
|
|
218
|
+
return {};
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (text.length > 1024 * 1024) return {};
|
|
222
|
+
}
|
|
223
|
+
return {};
|
|
224
|
+
} finally{
|
|
225
|
+
file.close();
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
// A session's id as its directory names it: a UUID.
|
|
229
|
+
let UUID = /^[\da-f]{8}-(?:[\da-f]{4}-){3}[\da-f]{12}$/i;
|
|
230
|
+
/** Every Grok Build session under its `sessions` directory: one directory
|
|
231
|
+
* per working directory (percent-encoded), and in it one per session, named
|
|
232
|
+
* by its id, holding the model's history, `chat_history.jsonl`. */ export let grokSessions = async (dir)=>{
|
|
233
|
+
let found = [];
|
|
234
|
+
for (let cwd of (await list(dir))){
|
|
235
|
+
if (!cwd.isDirectory) continue;
|
|
236
|
+
for (let s of (await list(`${dir}/${cwd.name}`))){
|
|
237
|
+
if (!s.isDirectory || !UUID.test(s.name)) continue;
|
|
238
|
+
let path = `${dir}/${cwd.name}/${s.name}/chat_history.jsonl`;
|
|
239
|
+
if (await isFile(path)) found.push({
|
|
240
|
+
id: s.name,
|
|
241
|
+
path,
|
|
242
|
+
runner: 'grok'
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return found;
|
|
247
|
+
};
|
|
248
|
+
/** Every Antigravity CLI conversation under its `brain` directory: one
|
|
249
|
+
* directory per conversation, named by its id, whose steps are logged in
|
|
250
|
+
* `.system_generated/logs/transcript_full.jsonl`, or, where an older version
|
|
251
|
+
* kept only the shortened log, `transcript.jsonl`. */ export let conversations = async (dir)=>{
|
|
252
|
+
let found = [];
|
|
253
|
+
for (let c of (await list(dir))){
|
|
254
|
+
if (!c.isDirectory || !UUID.test(c.name)) continue;
|
|
255
|
+
let logs = `${dir}/${c.name}/.system_generated/logs`;
|
|
256
|
+
for (let name of [
|
|
257
|
+
'transcript_full.jsonl',
|
|
258
|
+
'transcript.jsonl'
|
|
259
|
+
]){
|
|
260
|
+
if (!await isFile(`${logs}/${name}`)) continue;
|
|
261
|
+
found.push({
|
|
262
|
+
id: c.name,
|
|
263
|
+
path: `${logs}/${name}`,
|
|
264
|
+
runner: 'antigravity'
|
|
265
|
+
});
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return found;
|
|
270
|
+
};
|
|
271
|
+
let isFile = async (path)=>{
|
|
272
|
+
try {
|
|
273
|
+
return (await fs.stat(path)).isFile;
|
|
274
|
+
} catch {
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
// How each CLI's transcripts are listed.
|
|
279
|
+
let LISTS = {
|
|
280
|
+
claude: (dir)=>transcripts(dir),
|
|
281
|
+
codex: (dir)=>rollouts(dir),
|
|
282
|
+
grok: grokSessions,
|
|
283
|
+
antigravity: conversations
|
|
284
|
+
};
|
|
285
|
+
//# sourceMappingURL=files.js.map
|
package/files.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.js","sources":["./files.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,8EAA8E;AAE9E,YAAY,6BAAkC;AAC9C,YAAY,+CAAoD;AAEhE,SAAS,WAAW,oCAAyC;AAC7D,SAAS,UAAU,EAAE,WAAW,EAAE,QAAQ,2BAA6C;AAOvF,6DAA6D;AAC7D,IAAI,QAAgC;EAClC,QAAQ;EACR,OAAO;EACP,MAAM;EACN,aAAa;AACf;AAIA;;;iCAGiC,GACjC,OAAO,IAAI,OAAO,CAChB,QACA,MAAW,cAAc,GAAG,GACL,YAAY,QAAQ,CAAC,OAAS,IAAI,GAAG,CAAC,OAAM;AAErE;iDACiD,GACjD,OAAO,IAAI,gBAAgB,CAAC,IAAoB,GAAG,EAAE,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,EAAE,CAAA;AAE7E;gBACgB,GAChB,OAAO,IAAI,YAAY,CAAC,IAAoB,GAAG,EAAE,GAAG,CAAC,SAAS,CAAC,CAAA;AAE/D,IAAI,QAAQ,OAAO;EACjB,IAAI;IACF,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,EAAE,WAAW;EAC1C,EAAE,OAAM;IACN,OAAO;EACT;AACF;AAEA,sEAAsE;AACtE,mCAAmC;AACnC,IAAI,QAAQ,CAAC,MACV,IAAI,KAAK,CAAC,kCAAkC,CAAC,EAAE,IAC9C,CAAC,IAAI,QAAQ,CAAC,sBAAsB,gBAAgB,SAAS;AAIjE,4EAA4E;AAC5E,0EAA0E;AAC1E,cAAc;AACd,IAAI,SAAS,OAAO,MAClB,MAAM,QACJ,CAAC,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,IAC1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;QAAE,QAAQ;MAAc;MACxE;IACF;EACF;EACA,OAAO;AACT,EAAC;AAED,IAAI,SAAS,OAAO;EAClB,IAAI;IACF,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,EAAE,MAAM;EACrC,EAAE,OAAM;IACN,OAAO;EACT;AACF;AAEA,yCAAyC;AACzC,IAAI,QAA2D;EAC7D,QAAQ,CAAC,MAAQ,YAAY;EAC7B,OAAO,CAAC,MAAQ,SAAS;EACzB,MAAM;EACN,aAAa;AACf"}
|
package/files.ts
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
// The transcript files each CLI keeps: discovery and the first metadata line.
|
|
2
|
+
// Discovery describes sources; the bounded session duty decides when to read.
|
|
3
|
+
|
|
4
|
+
import * as fs from '@yaks/file/io'
|
|
5
|
+
import * as systemProcess from '@yaks/process/system'
|
|
6
|
+
import type { Bundle } from 'jsr:@yaks/graph@0.2.36'
|
|
7
|
+
import { identityEid } from '@yaks/graph/identity'
|
|
8
|
+
import { accountEid, accountHome, ACCOUNTS, type Runner } from '@yaks/model'
|
|
9
|
+
|
|
10
|
+
/** An account a CLI keeps on this machine: its config directory, the one
|
|
11
|
+
* `CLAUDE_CONFIG_DIR`, `CODEX_HOME` or `GROK_HOME` names, which holds its
|
|
12
|
+
* transcripts (@yaks/model `ACCOUNTS`). */
|
|
13
|
+
export type Home = { runner: Runner; dir: string }
|
|
14
|
+
|
|
15
|
+
// The directory under an account that holds its transcripts.
|
|
16
|
+
let KEEPS: Record<Runner, string> = {
|
|
17
|
+
claude: 'projects',
|
|
18
|
+
codex: 'sessions',
|
|
19
|
+
grok: 'sessions',
|
|
20
|
+
antigravity: 'brain',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type Env = Pick<systemProcess.Env, 'get'>
|
|
24
|
+
|
|
25
|
+
/** The account a CLI signs in with in an environment, this process's by
|
|
26
|
+
* default: the directory its variable names, else its own under the home
|
|
27
|
+
* directory (`~/.claude`, `~/.codex`, `~/.grok`,
|
|
28
|
+
* `~/.gemini/antigravity-cli`). */
|
|
29
|
+
export let home = (
|
|
30
|
+
runner: Home['runner'],
|
|
31
|
+
env: Env = systemProcess.env,
|
|
32
|
+
): string | undefined => accountHome(runner, (name) => env.get(name))
|
|
33
|
+
|
|
34
|
+
/** Where an account keeps its transcripts: Claude Code's `projects`, Codex's
|
|
35
|
+
* and Grok's `sessions`, Antigravity's `brain`. */
|
|
36
|
+
export let transcriptsOf = (h: Home): string => `${h.dir}/${KEEPS[h.runner]}`
|
|
37
|
+
|
|
38
|
+
/** Where a Claude Code account keeps one file per running process, naming
|
|
39
|
+
* its session. */
|
|
40
|
+
export let runningOf = (h: Home): string => `${h.dir}/sessions`
|
|
41
|
+
|
|
42
|
+
let isDir = async (path: string) => {
|
|
43
|
+
try {
|
|
44
|
+
return (await fs.stat(path)).isDirectory
|
|
45
|
+
} catch {
|
|
46
|
+
return false
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Which CLI's account a directory is by its name: `~/.claude-work` is
|
|
51
|
+
// Claude Code's, `~/.grok` Grok's.
|
|
52
|
+
let named = (dir: string): Runner | undefined =>
|
|
53
|
+
(dir.match(/\/\.(claude|codex|grok)[^/]*$/)?.[1] ??
|
|
54
|
+
(dir.endsWith('/antigravity-cli') ? 'antigravity' : undefined)) as
|
|
55
|
+
| Runner
|
|
56
|
+
| undefined
|
|
57
|
+
|
|
58
|
+
// Which CLI's account a directory listed by hand is, by its name or else by
|
|
59
|
+
// what it holds: Claude Code keeps `projects`, Antigravity `brain`, Codex
|
|
60
|
+
// `sessions`.
|
|
61
|
+
let kindOf = async (dir: string): Promise<Runner | undefined> =>
|
|
62
|
+
named(dir) ??
|
|
63
|
+
(await isDir(`${dir}/projects`)
|
|
64
|
+
? 'claude'
|
|
65
|
+
: await isDir(`${dir}/brain`)
|
|
66
|
+
? 'antigravity'
|
|
67
|
+
: await isDir(`${dir}/sessions`)
|
|
68
|
+
? 'codex'
|
|
69
|
+
: undefined)
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Every account on this machine that holds transcripts: the directories
|
|
73
|
+
* `listed` names and, unless `find` is false, the ones the environment (this
|
|
74
|
+
* process's by default) signs in with and each `~/.claude*`, `~/.codex*` and
|
|
75
|
+
* `~/.grok*` directory. Someone
|
|
76
|
+
* with several accounts keeps each in a directory of its own
|
|
77
|
+
* (`CLAUDE_CONFIG_DIR=~/.claude-work`), so each is found on its own.
|
|
78
|
+
*
|
|
79
|
+
* ```ts
|
|
80
|
+
* import { homes } from './files.ts'
|
|
81
|
+
*
|
|
82
|
+
* // await homes(['/Volumes/work/claude']) — [{ runner: 'claude', dir }, …]
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export let homes = async (
|
|
86
|
+
listed: string[] = [],
|
|
87
|
+
find = true,
|
|
88
|
+
env: Env = systemProcess.env,
|
|
89
|
+
): Promise<Home[]> => {
|
|
90
|
+
let at = env.get('HOME')
|
|
91
|
+
let expand = (dir: string) =>
|
|
92
|
+
dir.replace(/^~(?=\/|$)/, at ?? '~').replace(/(.)\/+$/, '$1')
|
|
93
|
+
let found = find && at
|
|
94
|
+
? (await list(at)).filter((f) => f.isDirectory)
|
|
95
|
+
.map((f) => `${at}/${f.name}`).filter(named).sort()
|
|
96
|
+
: []
|
|
97
|
+
let out = new Map<string, Home>()
|
|
98
|
+
let add = async (runner: Runner | undefined, dir?: string) => {
|
|
99
|
+
if (!runner || !dir || out.has(dir)) return
|
|
100
|
+
if (await isDir(transcriptsOf({ runner, dir }))) {
|
|
101
|
+
out.set(dir, { runner, dir })
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (find) {
|
|
105
|
+
for (let runner of Object.keys(ACCOUNTS) as Runner[]) {
|
|
106
|
+
await add(runner, home(runner, env))
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
for (let dir of listed.map(expand)) await add(await kindOf(dir), dir)
|
|
110
|
+
for (let dir of found) await add(named(dir), dir)
|
|
111
|
+
return [...out.values()]
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** The rows that name accounts: each one's `account`, and its provider's. */
|
|
115
|
+
export let accountRows = (from: Home[]): Bundle[] => {
|
|
116
|
+
let providers = [...new Set(from.map((h) => h.runner))]
|
|
117
|
+
return [
|
|
118
|
+
...providers.map((name) => ({
|
|
119
|
+
entity: { eid: identityEid('provider', [name]) },
|
|
120
|
+
provider: { name },
|
|
121
|
+
})),
|
|
122
|
+
...from.map((h) => ({
|
|
123
|
+
entity: { eid: accountEid(h.dir) },
|
|
124
|
+
account: { home: h.dir, provider: identityEid('provider', [h.runner]) },
|
|
125
|
+
})),
|
|
126
|
+
]
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Every transcript the accounts keep, each with its account: Claude Code's
|
|
130
|
+
* by {@link transcripts}, Codex's by {@link rollouts}, Grok's by
|
|
131
|
+
* {@link grokSessions} and Antigravity's by {@link conversations}. */
|
|
132
|
+
export let held = async (from: Home[]): Promise<Found[]> =>
|
|
133
|
+
(await Promise.all(from.map(async (h) => {
|
|
134
|
+
let found = await LISTS[h.runner](transcriptsOf(h))
|
|
135
|
+
let account = accountEid(h.dir)
|
|
136
|
+
return found.map((f) => ({ ...f, account }))
|
|
137
|
+
}))).flat()
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Move a thread's transcript from one account of a CLI to another, at the
|
|
141
|
+
* same place under the other's transcripts, so the CLI signed in there
|
|
142
|
+
* carries the thread on (`claude --resume`, `codex resume`). Its subagents'
|
|
143
|
+
* transcripts stay where they were read from. Whether it was found to move.
|
|
144
|
+
*
|
|
145
|
+
* ```ts
|
|
146
|
+
* import { moveThread } from './files.ts'
|
|
147
|
+
*
|
|
148
|
+
* // await moveThread({ runner: 'claude', dir: '~/.claude-a' }, '~/.claude-b', id)
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export let moveThread = async (
|
|
152
|
+
from: Home,
|
|
153
|
+
to: string,
|
|
154
|
+
thread: string,
|
|
155
|
+
): Promise<boolean> => {
|
|
156
|
+
let [found] = (await held([from])).filter((f) => f.id == thread && !f.parent)
|
|
157
|
+
if (!found) return false
|
|
158
|
+
let path = to + found.path.slice(from.dir.length)
|
|
159
|
+
await fs.mkdir(path.slice(0, path.lastIndexOf('/')), { recursive: true })
|
|
160
|
+
await fs.rename(found.path, path)
|
|
161
|
+
return true
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** What a compressed transcript is at a moment: its size and when it was
|
|
165
|
+
* written. A read that reached its end records this as `transcript.finished`. */
|
|
166
|
+
export let versionOf = (
|
|
167
|
+
file: { size: number; mtime: Date | null } | undefined,
|
|
168
|
+
): string => file ? `${file.size}:${file.mtime?.getTime() ?? 0}` : ''
|
|
169
|
+
|
|
170
|
+
/** One transcript on disk: the harness's id for the session, and the file. */
|
|
171
|
+
export type Found = {
|
|
172
|
+
id: string
|
|
173
|
+
path: string
|
|
174
|
+
/** the CLI that keeps it, where it is not Claude Code */
|
|
175
|
+
runner?: Exclude<Runner, 'claude'>
|
|
176
|
+
/** a subagent's: the harness's id for the session that started it */
|
|
177
|
+
parent?: string
|
|
178
|
+
/** the account whose transcript it is (@yaks/model `account`) */
|
|
179
|
+
account?: string
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** Every transcript under a Claude projects directory: the sessions', then
|
|
183
|
+
* their subagents'. Listed a directory at a time, so the thread runs its
|
|
184
|
+
* timers between them: a box keeps thousands. */
|
|
185
|
+
export let transcripts = async (dir: string): Promise<Found[]> => {
|
|
186
|
+
let out: Found[] = []
|
|
187
|
+
let agents: Found[] = []
|
|
188
|
+
for (let project of await list(dir)) {
|
|
189
|
+
if (!project.isDirectory) continue
|
|
190
|
+
let at = `${dir}/${project.name}`
|
|
191
|
+
for (let f of await list(at)) {
|
|
192
|
+
if (f.isFile && f.name.endsWith('.jsonl')) {
|
|
193
|
+
out.push({
|
|
194
|
+
id: f.name.slice(0, -'.jsonl'.length),
|
|
195
|
+
path: `${at}/${f.name}`,
|
|
196
|
+
})
|
|
197
|
+
}
|
|
198
|
+
if (!f.isDirectory) continue
|
|
199
|
+
for (let a of await list(`${at}/${f.name}/subagents`)) {
|
|
200
|
+
let id = a.name.match(/^agent-(.+)\.jsonl$/)?.[1]
|
|
201
|
+
if (!a.isFile || !id) continue
|
|
202
|
+
let path = `${at}/${f.name}/subagents/${a.name}`
|
|
203
|
+
agents.push({ id, path, parent: f.name })
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return [...out, ...agents]
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// A directory's entries; none where it is missing or unreadable.
|
|
211
|
+
let list = async (dir: string): Promise<fs.DirEntry[]> => {
|
|
212
|
+
try {
|
|
213
|
+
return await Array.fromAsync(fs.readDir(dir))
|
|
214
|
+
} catch {
|
|
215
|
+
return []
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Rollouts are dated YYYY/MM/DD, and the filename carries the thread UUID.
|
|
220
|
+
// The same bounded look follows both providers; no second duty scans them.
|
|
221
|
+
export let rollouts = async (dir: string, depth = 0): Promise<Found[]> => {
|
|
222
|
+
let files = await list(dir)
|
|
223
|
+
let names = new Set(files.map((f) => f.name))
|
|
224
|
+
let found: Found[] = []
|
|
225
|
+
for (let f of files) {
|
|
226
|
+
let path = `${dir}/${f.name}`
|
|
227
|
+
if (f.isDirectory && depth < 3 && /^\d+$/.test(f.name)) {
|
|
228
|
+
found.push(...await rollouts(path, depth + 1))
|
|
229
|
+
continue
|
|
230
|
+
}
|
|
231
|
+
let id = f.name.match(
|
|
232
|
+
/^rollout-.+-([\da-f]{8}-(?:[\da-f]{4}-){3}[\da-f]{12})\.jsonl(?:\.zst)?$/i,
|
|
233
|
+
)?.[1]
|
|
234
|
+
if (!f.isFile || !id) continue
|
|
235
|
+
if (
|
|
236
|
+
f.name.endsWith('.zst') &&
|
|
237
|
+
names.has(f.name.slice(0, -4))
|
|
238
|
+
) continue
|
|
239
|
+
found.push({ id, path, runner: 'codex' })
|
|
240
|
+
}
|
|
241
|
+
return found
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// Only the header is needed to identify a child. Never read its whole log
|
|
245
|
+
// merely to open a tail; the importer will read the remaining bytes once.
|
|
246
|
+
export let header = (path: string): Record<string, unknown> => {
|
|
247
|
+
let file = fs.openSync(path)
|
|
248
|
+
try {
|
|
249
|
+
let buf = new Uint8Array(4096), text = '', dec = new TextDecoder()
|
|
250
|
+
for (let n = file.readSync(buf); n; n = file.readSync(buf)) {
|
|
251
|
+
text += dec.decode(buf.subarray(0, n), { stream: true })
|
|
252
|
+
if (text.includes('\n')) {
|
|
253
|
+
try {
|
|
254
|
+
return JSON.parse(text.split('\n')[0]).payload ?? {}
|
|
255
|
+
} catch {
|
|
256
|
+
return {}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (text.length > 1024 * 1024) return {}
|
|
260
|
+
}
|
|
261
|
+
return {}
|
|
262
|
+
} finally {
|
|
263
|
+
file.close()
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// A session's id as its directory names it: a UUID.
|
|
268
|
+
let UUID = /^[\da-f]{8}-(?:[\da-f]{4}-){3}[\da-f]{12}$/i
|
|
269
|
+
|
|
270
|
+
/** Every Grok Build session under its `sessions` directory: one directory
|
|
271
|
+
* per working directory (percent-encoded), and in it one per session, named
|
|
272
|
+
* by its id, holding the model's history, `chat_history.jsonl`. */
|
|
273
|
+
export let grokSessions = async (dir: string): Promise<Found[]> => {
|
|
274
|
+
let found: Found[] = []
|
|
275
|
+
for (let cwd of await list(dir)) {
|
|
276
|
+
if (!cwd.isDirectory) continue
|
|
277
|
+
for (let s of await list(`${dir}/${cwd.name}`)) {
|
|
278
|
+
if (!s.isDirectory || !UUID.test(s.name)) continue
|
|
279
|
+
let path = `${dir}/${cwd.name}/${s.name}/chat_history.jsonl`
|
|
280
|
+
if (await isFile(path)) found.push({ id: s.name, path, runner: 'grok' })
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return found
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/** Every Antigravity CLI conversation under its `brain` directory: one
|
|
287
|
+
* directory per conversation, named by its id, whose steps are logged in
|
|
288
|
+
* `.system_generated/logs/transcript_full.jsonl`, or, where an older version
|
|
289
|
+
* kept only the shortened log, `transcript.jsonl`. */
|
|
290
|
+
export let conversations = async (dir: string): Promise<Found[]> => {
|
|
291
|
+
let found: Found[] = []
|
|
292
|
+
for (let c of await list(dir)) {
|
|
293
|
+
if (!c.isDirectory || !UUID.test(c.name)) continue
|
|
294
|
+
let logs = `${dir}/${c.name}/.system_generated/logs`
|
|
295
|
+
for (let name of ['transcript_full.jsonl', 'transcript.jsonl']) {
|
|
296
|
+
if (!await isFile(`${logs}/${name}`)) continue
|
|
297
|
+
found.push({ id: c.name, path: `${logs}/${name}`, runner: 'antigravity' })
|
|
298
|
+
break
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return found
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
let isFile = async (path: string) => {
|
|
305
|
+
try {
|
|
306
|
+
return (await fs.stat(path)).isFile
|
|
307
|
+
} catch {
|
|
308
|
+
return false
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// How each CLI's transcripts are listed.
|
|
313
|
+
let LISTS: Record<Runner, (dir: string) => Promise<Found[]>> = {
|
|
314
|
+
claude: (dir) => transcripts(dir),
|
|
315
|
+
codex: (dir) => rollouts(dir),
|
|
316
|
+
grok: grokSessions,
|
|
317
|
+
antigravity: conversations,
|
|
318
|
+
}
|