@vatio-ai/cli 0.89.0 → 0.90.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.
@@ -105,7 +105,7 @@ function jsonlIn(dir) {
105
105
  .map((name) => {
106
106
  const path = join(dir, name);
107
107
  const stat = statSync(path);
108
- return { id: name.slice(0, -".jsonl".length), path, bytes: stat.size, modifiedAt: stat.mtimeMs };
108
+ return { agent: "claude-code", id: name.slice(0, -".jsonl".length), path, bytes: stat.size, modifiedAt: stat.mtimeMs };
109
109
  })
110
110
  .sort((a, b) => b.modifiedAt - a.modifiedAt);
111
111
  }
@@ -207,7 +207,8 @@ function scrub(value, counts) {
207
207
 
208
208
  const HOME = homedir();
209
209
 
210
- function redact(text, counts) {
210
+ // Also what codex-session.mjs cleans a Codex session's text with.
211
+ export function redact(text, counts) {
211
212
  let result = text;
212
213
  for (const [pattern, replacement] of SECRET_PATTERNS) {
213
214
  result = result.replace(pattern, (...match) => {
@@ -0,0 +1,223 @@
1
+ // The coding agent's own session, as Codex keeps it on this machine: one JSONL
2
+ // file per thread under $CODEX_HOME/sessions/YYYY/MM/DD/, named
3
+ // rollout-<time>-<thread id>.jsonl, with $CODEX_HOME at ~/.codex unless it is
4
+ // set. Codex gives every command it runs the thread's id in CODEX_THREAD_ID.
5
+ // Each line is {timestamp, type, payload}; the first is the session_meta, with
6
+ // the directory the session was started in.
7
+ //
8
+ // The format is Codex's and changes between its releases, so nothing here
9
+ // depends on more of it than it has to: a line is kept or dropped by its
10
+ // `type`, and everything a kept line carries is passed through as it is.
11
+
12
+ import { closeSync, openSync, readdirSync, readFileSync, readSync, statSync } from "node:fs";
13
+ import { homedir } from "node:os";
14
+ import { dirname, join, resolve } from "node:path";
15
+
16
+ import { redact } from "./claude-session.mjs";
17
+
18
+ // What the agent and the developer said and did, and where. Everything else is
19
+ // Codex's bookkeeping: events that repeat the items, token counts, turn
20
+ // settings, compaction summaries of items the file still holds.
21
+ const KEPT_TYPES = new Set(["session_meta", "response_item"]);
22
+
23
+ // Codex's own system prompt and tool list, as long as a conversation, and the
24
+ // opaque encrypted copies of reasoning and arguments.
25
+ const DROPPED_META_KEYS = ["base_instructions", "dynamic_tools"];
26
+ const DROPPED_KEYS = new Set(["encrypted_content", "encrypted_function_args"]);
27
+
28
+ // Reading every session's first line to find the ones for a directory is the
29
+ // slow part; the newest are the ones anyone sends.
30
+ const SCANNED = 200;
31
+
32
+ const THREAD_ID = /^rollout-.+-([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?:_[0-9a-f-]+)?\.jsonl$/i;
33
+
34
+ export function codexHome() {
35
+ return process.env.CODEX_HOME || join(homedir(), ".codex");
36
+ }
37
+
38
+ // The sessions Codex kept for this directory, or for the nearest parent it was
39
+ // started in, newest first.
40
+ export function sessionsFor(startDir) {
41
+ const byDir = new Map();
42
+ for (const session of rollouts().slice(0, SCANNED)) {
43
+ const cwd = metaOf(session.path)?.cwd;
44
+ if (typeof cwd !== "string") continue;
45
+ const key = dirKey(cwd);
46
+ byDir.set(key, [...(byDir.get(key) ?? []), session]);
47
+ }
48
+
49
+ let dir = resolve(startDir);
50
+ for (;;) {
51
+ const sessions = byDir.get(dirKey(dir));
52
+ if (sessions) return sessions;
53
+ const parent = dirname(dir);
54
+ if (parent === dir) return [];
55
+ dir = parent;
56
+ }
57
+ }
58
+
59
+ export function sessionById(id) {
60
+ return rollouts().find((session) => session.id.startsWith(id)) ?? null;
61
+ }
62
+
63
+ // What a session is about, without cleaning it: for --list, and for picking
64
+ // the newest session that has a conversation in it.
65
+ export function describe(session) {
66
+ let firstPrompt = null;
67
+ let messages = 0;
68
+ let cwd = null;
69
+ for (const line of lines(session.path)) {
70
+ if (line.type === "session_meta") cwd ??= line.payload?.cwd ?? null;
71
+ const item = line.type === "response_item" ? line.payload : null;
72
+ if (item?.type !== "message" || !["user", "assistant"].includes(item.role)) continue;
73
+ messages += 1;
74
+ if (item.role === "user") firstPrompt ??= promptText(item.content);
75
+ }
76
+ return { ...session, title: firstPrompt, messages, cwd };
77
+ }
78
+
79
+ // The session as it is sent: only what was said and done, without images,
80
+ // with anything that looks like a secret, an email or a phone replaced and the
81
+ // home directory as ~.
82
+ export function clean(session) {
83
+ const kept = [];
84
+ const counts = { messages: 0, images: 0, redactions: 0, personal: 0 };
85
+ let startedAt = null;
86
+ let endedAt = null;
87
+ let gitBranch = null;
88
+ let cwd = null;
89
+
90
+ for (const line of lines(session.path)) {
91
+ if (!KEPT_TYPES.has(line.type)) continue;
92
+ if (line.type === "session_meta" && line.payload && typeof line.payload === "object") {
93
+ for (const key of DROPPED_META_KEYS) delete line.payload[key];
94
+ gitBranch = line.payload.git?.branch ?? gitBranch;
95
+ }
96
+
97
+ const scrubbed = scrub(line, counts);
98
+ const item = line.payload;
99
+ if (line.type === "response_item" && item?.type === "message" && ["user", "assistant"].includes(item.role)) {
100
+ counts.messages += 1;
101
+ }
102
+ if (line.timestamp) {
103
+ startedAt ??= line.timestamp;
104
+ endedAt = line.timestamp;
105
+ }
106
+ if (line.type === "session_meta") cwd ??= scrubbed.payload?.cwd ?? null;
107
+ kept.push(JSON.stringify(scrubbed));
108
+ }
109
+
110
+ return {
111
+ jsonl: kept.length > 0 ? `${kept.join("\n")}\n` : "",
112
+ ...counts,
113
+ startedAt,
114
+ endedAt,
115
+ gitBranch,
116
+ cwd
117
+ };
118
+ }
119
+
120
+ // Every session file, newest first. Compressed ones (.jsonl.zst) are old ones
121
+ // Codex packed away, and are left out.
122
+ function rollouts() {
123
+ const root = join(codexHome(), "sessions");
124
+ const files = [];
125
+ for (const year of listDir(root)) {
126
+ for (const month of listDir(join(root, year))) {
127
+ for (const day of listDir(join(root, year, month))) {
128
+ const dir = join(root, year, month, day);
129
+ for (const name of listDir(dir)) {
130
+ const match = THREAD_ID.exec(name);
131
+ if (!match) continue;
132
+ const path = join(dir, name);
133
+ const stat = statSync(path);
134
+ files.push({ agent: "codex", id: match[1].toLowerCase(), path, bytes: stat.size, modifiedAt: stat.mtimeMs });
135
+ }
136
+ }
137
+ }
138
+ }
139
+ return files.sort((a, b) => b.modifiedAt - a.modifiedAt);
140
+ }
141
+
142
+ // The first line alone, which carries the system prompt and can be long, but
143
+ // never the whole file, which can be many megabytes.
144
+ function metaOf(path) {
145
+ let fd;
146
+ try {
147
+ fd = openSync(path, "r");
148
+ const chunk = Buffer.alloc(64 * 1024);
149
+ const parts = [];
150
+ for (let total = 0; total < 4 * 1024 * 1024; ) {
151
+ const read = readSync(fd, chunk, 0, chunk.length, total);
152
+ if (read === 0) break;
153
+ const newline = chunk.subarray(0, read).indexOf(10);
154
+ parts.push(Buffer.from(chunk.subarray(0, newline === -1 ? read : newline)));
155
+ if (newline !== -1) break;
156
+ total += read;
157
+ }
158
+ const line = JSON.parse(Buffer.concat(parts).toString("utf8"));
159
+ return line?.type === "session_meta" ? line.payload : null;
160
+ } catch {
161
+ return null;
162
+ } finally {
163
+ if (fd !== undefined) closeSync(fd);
164
+ }
165
+ }
166
+
167
+ function* lines(path) {
168
+ for (const text of readFileSync(path, "utf8").split("\n")) {
169
+ if (text.trim() === "") continue;
170
+ try {
171
+ const line = JSON.parse(text);
172
+ if (line && typeof line === "object") yield line;
173
+ } catch {
174
+ // A line cut off while Codex was writing it: the session this command
175
+ // runs in is still being written.
176
+ }
177
+ }
178
+ }
179
+
180
+ function scrub(value, counts) {
181
+ if (typeof value === "string") return redact(value, counts);
182
+ if (Array.isArray(value)) return value.map((item) => scrub(item, counts));
183
+ if (!value || typeof value !== "object") return value;
184
+
185
+ // Pictures, base64 inline in a data: URL: screenshots of whatever was on
186
+ // screen.
187
+ if (value.type === "input_image") {
188
+ counts.images += 1;
189
+ return { type: value.type, omitted: true };
190
+ }
191
+
192
+ return Object.fromEntries(
193
+ Object.entries(value)
194
+ .filter(([key]) => !DROPPED_KEYS.has(key))
195
+ .map(([key, item]) => [key, scrub(item, counts)])
196
+ );
197
+ }
198
+
199
+ // Codex puts its own context in user messages too: the environment as a tag,
200
+ // and AGENTS.md under a heading of its own.
201
+ function promptText(content) {
202
+ const text = Array.isArray(content)
203
+ ? content.find((block) => block?.type === "input_text")?.text
204
+ : typeof content === "string" ? content : null;
205
+ if (!text) return null;
206
+ const trimmed = text.trimStart();
207
+ if (trimmed.startsWith("<") || trimmed.startsWith("# AGENTS.md")) return null;
208
+ return text.replace(/\s+/g, " ").trim();
209
+ }
210
+
211
+ // Windows paths compare without case, as Windows does.
212
+ function dirKey(path) {
213
+ const resolved = resolve(path);
214
+ return process.platform === "win32" ? resolved.toLowerCase() : resolved;
215
+ }
216
+
217
+ function listDir(dir) {
218
+ try {
219
+ return readdirSync(dir).sort().reverse();
220
+ } catch {
221
+ return [];
222
+ }
223
+ }
@@ -6,7 +6,8 @@ import { homedir } from "node:os";
6
6
  import { dirname, join, resolve } from "node:path";
7
7
  import { gzipSync } from "node:zlib";
8
8
 
9
- import { clean, describe, sessionById, sessionsFor } from "../claude-session.mjs";
9
+ import * as claudeSessions from "../claude-session.mjs";
10
+ import * as codexSessions from "../codex-session.mjs";
10
11
  import { configHome } from "../config.mjs";
11
12
  import { ask, fail, takeFlag, takeValue } from "../support.mjs";
12
13
  import { chosenHeaders, clientHeaders, sendFeedback, telemetryEnabled } from "../telemetry.mjs";
@@ -86,17 +87,18 @@ export async function shareSession(config, args) {
86
87
  if (never) return stopOffering();
87
88
 
88
89
  const session = findSession(id);
89
- const transcript = clean(session);
90
+ const { label, reader } = AGENTS[session.agent];
91
+ const transcript = reader.clean(session);
90
92
  if (transcript.messages === 0) fail(`Session ${short(session.id)} has no messages yet.`);
91
93
  const gzipped = gzipSync(transcript.jsonl);
92
94
 
93
- const { title } = describe(session);
94
- console.log(`Claude Code session ${short(session.id)}${title ? ` — ${truncate(title, 70)}` : ""}`);
95
+ const { title } = reader.describe(session);
96
+ console.log(`${label} session ${short(session.id)}${title ? ` — ${truncate(title, 70)}` : ""}`);
95
97
  console.log(` ${tilde(transcript.cwd ?? process.cwd())}${transcript.gitBranch ? ` (${transcript.gitBranch})` : ""}`);
96
98
  console.log(` ${transcript.messages} messages, ${when(transcript.startedAt)} → ${when(transcript.endedAt)}`);
97
99
  console.log(` ${size(Buffer.byteLength(transcript.jsonl))}, ${size(gzipped.length)} compressed`);
98
100
  console.log(
99
- ` Left out: ${transcript.images > 0 ? `${transcript.images} image(s) and ` : ""}Claude Code's own bookkeeping.` +
101
+ ` Left out: ${transcript.images > 0 ? `${transcript.images} image(s) and ` : ""}${label}'s own bookkeeping.` +
100
102
  (transcript.redactions > 0 ? ` ${transcript.redactions} thing(s) that looked like a key, token or password are [REDACTED].` : "") +
101
103
  (transcript.personal > 0 ? ` ${transcript.personal} email address(es) and phone number(s) are [EMAIL] and [PHONE].` : "")
102
104
  );
@@ -133,7 +135,7 @@ export async function shareSession(config, args) {
133
135
 
134
136
  const form = new FormData();
135
137
  form.set("transcript", new Blob([gzipped], { type: "application/gzip" }), `${session.id}.jsonl.gz`);
136
- form.set("source", "claude-code");
138
+ form.set("source", session.agent);
137
139
  form.set("source_session_id", session.id);
138
140
  form.set("messages", String(transcript.messages));
139
141
  if (transcript.startedAt) form.set("started_at", transcript.startedAt);
@@ -173,7 +175,7 @@ function answerShouldAsk() {
173
175
  console.log(`no — ${reason}`);
174
176
  return;
175
177
  }
176
- rememberOffer(process.env.CLAUDE_CODE_SESSION_ID);
178
+ rememberOffer(currentSession()?.id);
177
179
  console.log(
178
180
  "yes — ask the person you work for whether to send this session to the Vatio team: send it, " +
179
181
  "not now, or don't ask again (`vatio share-session --never`)."
@@ -185,9 +187,9 @@ function reasonNotToOffer() {
185
187
  if (!telemetryEnabled()) return "telemetry is off, so they would rather send nothing";
186
188
  const state = readOfferState();
187
189
  if (state.never) return "they said not to ask again";
188
- const current = process.env.CLAUDE_CODE_SESSION_ID;
189
- if (!current || !sessionById(current)) return "only a Claude Code session can be sent, from inside it";
190
- if (state.session === current) return "already offered in this session";
190
+ const current = currentSession();
191
+ if (!current) return "only a Claude Code or Codex session can be sent, from inside it";
192
+ if (state.session === current.id) return "already offered in this session";
191
193
  if (Date.now() - Date.parse(state.offered_at ?? "") < OFFER_EVERY_MS) return "already offered this week";
192
194
  return null;
193
195
  }
@@ -245,36 +247,68 @@ function writeOfferState(state) {
245
247
  writeFileSync(path, `${JSON.stringify(state)}\n`);
246
248
  }
247
249
 
248
- // The one this coding agent is running in, when it is Claude Code; otherwise
249
- // the newest one with a conversation in it, started here or above.
250
+ // The coding agents whose sessions can be sent, by the source the upload is
251
+ // tagged with, and how each says which session a command runs in.
252
+ const AGENTS = {
253
+ "claude-code": { label: "Claude Code", reader: claudeSessions, currentId: () => process.env.CLAUDE_CODE_SESSION_ID },
254
+ codex: { label: "Codex", reader: codexSessions, currentId: () => process.env.CODEX_THREAD_ID }
255
+ };
256
+
257
+ // The session this command runs in, when a coding agent we read runs it.
258
+ function currentSession() {
259
+ for (const { reader, currentId } of Object.values(AGENTS)) {
260
+ const id = currentId();
261
+ const session = id ? reader.sessionById(id) : null;
262
+ if (session) return session;
263
+ }
264
+ return null;
265
+ }
266
+
267
+ function sessionById(id) {
268
+ const matches = Object.values(AGENTS).map(({ reader }) => reader.sessionById(id)).filter(Boolean);
269
+ return matches.sort((a, b) => b.modifiedAt - a.modifiedAt)[0] ?? null;
270
+ }
271
+
272
+ // Every agent's sessions for this directory or the nearest parent, newest
273
+ // first, with what each is about.
274
+ function sessionsHere(limit = Infinity) {
275
+ return Object.values(AGENTS)
276
+ .flatMap(({ reader }) => reader.sessionsFor(process.cwd()).slice(0, limit).map(reader.describe))
277
+ .sort((a, b) => b.modifiedAt - a.modifiedAt);
278
+ }
279
+
280
+ // The one this coding agent is running in, when it is Claude Code or Codex;
281
+ // otherwise the newest one with a conversation in it, started here or above.
250
282
  function findSession(id) {
251
- const current = process.env.CLAUDE_CODE_SESSION_ID;
252
- if (id || current) {
253
- const session = sessionById(id ?? current);
283
+ if (id) {
284
+ const session = sessionById(id);
254
285
  if (session) return session;
255
- if (id) fail(`No Claude Code session ${id} on this machine. \`vatio share-session --list\` shows them.`);
286
+ fail(`No Claude Code or Codex session ${id} on this machine. \`vatio share-session --list\` shows them.`);
256
287
  }
288
+ const current = currentSession();
289
+ if (current) return current;
257
290
 
258
- const session = sessionsFor(process.cwd()).map(describe).find((candidate) => candidate.messages > 0);
291
+ const session = sessionsHere().find((candidate) => candidate.messages > 0);
259
292
  if (session) return session;
260
293
  fail(
261
- "No Claude Code session found for this directory. Run this from the project Claude Code was working in.\n" +
262
- 'Only Claude Code sessions for now: from another coding agent, tell us with `vatio feedback "…"`.'
294
+ "No Claude Code or Codex session found for this directory. Run this from the project your coding agent was\n" +
295
+ 'working in. From another coding agent, tell us with `vatio feedback "…"`.'
263
296
  );
264
297
  }
265
298
 
266
299
  function listSessions() {
267
- const sessions = sessionsFor(process.cwd()).slice(0, 20).map(describe).filter((session) => session.messages > 0).slice(0, 10);
268
- if (sessions.length === 0) fail("No Claude Code sessions for this directory.");
300
+ const sessions = sessionsHere(20).filter((session) => session.messages > 0).slice(0, 10);
301
+ if (sessions.length === 0) fail("No Claude Code or Codex sessions for this directory.");
269
302
 
270
- const current = process.env.CLAUDE_CODE_SESSION_ID;
303
+ const current = currentSession()?.id;
271
304
  const sent = sentSessions();
272
305
  for (const session of sessions) {
273
306
  const mark = session.id === current ? "*" : " ";
274
307
  const title = session.title ? truncate(session.title, 60) : "";
275
308
  const modified = when(new Date(session.modifiedAt).toISOString());
276
309
  const shared = sent[session.id] ? ` (sent #${sent[session.id].id}, ${when(sent[session.id].at)})` : "";
277
- console.log(`${mark} ${short(session.id)} ${modified} ${String(session.messages).padStart(5)} msgs ${title}${shared}`);
310
+ const agent = AGENTS[session.agent].label.padEnd(11);
311
+ console.log(`${mark} ${short(session.id)} ${modified} ${agent} ${String(session.messages).padStart(5)} msgs ${title}${shared}`);
278
312
  }
279
313
  console.log("\nSend one with `vatio share-session --id ID`.");
280
314
  }
package/lib/help.mjs CHANGED
@@ -27,8 +27,8 @@ Commands default as listed.
27
27
  version What this CLI is
28
28
  docs [--save [PATH]] The whole developer contract, live from Vatio
29
29
  feedback "TEXT" Tell the Vatio team what got in the way
30
- share-session ["FEEDBACK"] Send this Claude Code session to the Vatio team,
31
- after showing what goes; feedback optional
30
+ share-session ["FEEDBACK"] Send this Claude Code or Codex session to the
31
+ Vatio team, after showing what goes; feedback optional
32
32
  (--save FILE, --list, --id ID; --yes from a
33
33
  coding agent)
34
34
  share-session --should-ask Whether a coding agent should offer to send it
package/lib/telemetry.mjs CHANGED
@@ -57,7 +57,10 @@ export function codingAgent() {
57
57
  if (env.VATIO_AGENT) return String(env.VATIO_AGENT).slice(0, 64);
58
58
  if (env.CLAUDECODE) return "claude-code";
59
59
  if (env.CURSOR_AGENT || env.CURSOR_TRACE_ID) return "cursor";
60
- if (env.CODEX_SANDBOX || env.CODEX_MANAGED_BY_NPM) return "codex";
60
+ // CODEX_THREAD_ID and CODEX_SESSION_ID are on every command Codex runs, on
61
+ // every platform; the other two are not on Windows, where a whole session
62
+ // of Codex's once reported as "unknown".
63
+ if (env.CODEX_THREAD_ID || env.CODEX_SESSION_ID || env.CODEX_SANDBOX || env.CODEX_MANAGED_BY_NPM) return "codex";
61
64
  if (env.GEMINI_CLI) return "gemini-cli";
62
65
  if (env.CI) return "ci";
63
66
  return process.stdout.isTTY ? "human" : "unknown";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vatio-ai/cli",
3
- "version": "0.89.0",
3
+ "version": "0.90.0",
4
4
  "description": "Vatio CLI — deploy and manage Vatio agent workspaces",
5
5
  "keywords": [
6
6
  "vatio",