@vatio-ai/cli 0.67.0 → 0.69.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/bin/vatio.mjs +4 -2
- package/lib/claude-session.mjs +210 -0
- package/lib/commands/chat.mjs +17 -0
- package/lib/commands/deploy.mjs +2 -2
- package/lib/commands/support-commands.mjs +223 -6
- package/lib/commands/workspace-admin.mjs +51 -31
- package/lib/help.mjs +7 -0
- package/lib/telemetry.mjs +9 -6
- package/package.json +1 -1
package/bin/vatio.mjs
CHANGED
|
@@ -19,7 +19,7 @@ import { chat } from "../lib/commands/chat.mjs";
|
|
|
19
19
|
import { kb } from "../lib/commands/knowledge.mjs";
|
|
20
20
|
import { business } from "../lib/commands/business.mjs";
|
|
21
21
|
import { instagram, whatsapp } from "../lib/commands/channels.mjs";
|
|
22
|
-
import { docs, feedback } from "../lib/commands/support-commands.mjs";
|
|
22
|
+
import { docs, feedback, shareSession } from "../lib/commands/support-commands.mjs";
|
|
23
23
|
import { evalCommand, flags, tools } from "../lib/commands/improve.mjs";
|
|
24
24
|
import { propose } from "../lib/commands/propose.mjs";
|
|
25
25
|
import { printUpdateNotice, startUpdateCheck } from "../lib/update-notice.mjs";
|
|
@@ -115,6 +115,8 @@ async function run(command, args) {
|
|
|
115
115
|
return await docs(config, args);
|
|
116
116
|
case "feedback":
|
|
117
117
|
return await feedback(config, args);
|
|
118
|
+
case "share-session":
|
|
119
|
+
return await shareSession(config, args);
|
|
118
120
|
case "help":
|
|
119
121
|
case "-h":
|
|
120
122
|
case "--help":
|
|
@@ -177,7 +179,7 @@ function printTrailer(error) {
|
|
|
177
179
|
// Said to coding agents only: a person at a terminal has better ways to
|
|
178
180
|
// complain, and does not need the line on every typo.
|
|
179
181
|
function suggestFeedback() {
|
|
180
|
-
if (!telemetryEnabled() || !isCodingAgent() || process.argv[2]
|
|
182
|
+
if (!telemetryEnabled() || !isCodingAgent() || ["feedback", "share-session"].includes(process.argv[2])) return;
|
|
181
183
|
console.error(
|
|
182
184
|
'\nIf this has you stuck, tell the Vatio team: vatio feedback "what you were trying to do and what got in the way"'
|
|
183
185
|
);
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// The coding agent's own session, as Claude Code keeps it on this machine: one
|
|
2
|
+
// JSONL file per session under ~/.claude/projects/<dir>/<session id>.jsonl,
|
|
3
|
+
// where <dir> is the directory it was started in with every character that is
|
|
4
|
+
// not a letter or a digit turned into "-".
|
|
5
|
+
//
|
|
6
|
+
// The format is Claude Code's and changes between its releases, so nothing
|
|
7
|
+
// here depends on more of it than it has to: a line is kept or dropped by its
|
|
8
|
+
// `type`, and everything a kept line carries is passed through as it is.
|
|
9
|
+
|
|
10
|
+
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
11
|
+
import { homedir } from "node:os";
|
|
12
|
+
import { dirname, join, resolve } from "node:path";
|
|
13
|
+
|
|
14
|
+
// What the agent and the developer said and did. Everything else in the file
|
|
15
|
+
// is Claude Code's bookkeeping: costs, modes, titles, file-history snapshots.
|
|
16
|
+
const KEPT_TYPES = new Set(["user", "assistant", "system"]);
|
|
17
|
+
|
|
18
|
+
// A copy of what the tool_result block already says, and Claude Code's own
|
|
19
|
+
// wiring, each as large as the conversation itself.
|
|
20
|
+
const DROPPED_KEYS = ["toolUseResult", "wireToolInputs", "wireIngestContext"];
|
|
21
|
+
|
|
22
|
+
const REDACTED = "[REDACTED]";
|
|
23
|
+
|
|
24
|
+
// What a transcript most often carries that nobody meant to send: keys and
|
|
25
|
+
// tokens printed by a command or read from a file. A pattern can only catch
|
|
26
|
+
// what looks like a secret, which is why `--save` exists.
|
|
27
|
+
const SECRET_PATTERNS = [
|
|
28
|
+
[/-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z ]*PRIVATE KEY-----/g, REDACTED],
|
|
29
|
+
[/\b(?:vat|vsk|vatsup|vda|whsec)_[A-Za-z0-9_-]{16,}/g, REDACTED],
|
|
30
|
+
[/\bsk-(?:ant-|proj-|or-v1-)?[A-Za-z0-9_-]{20,}/g, REDACTED],
|
|
31
|
+
[/\b(?:sk|rk)_(?:live|test)_[A-Za-z0-9]{10,}/g, REDACTED],
|
|
32
|
+
[/\b(?:gh[pousr]_[A-Za-z0-9]{30,}|github_pat_[A-Za-z0-9_]{40,})/g, REDACTED],
|
|
33
|
+
[/\bxox[abprs]-[A-Za-z0-9-]{10,}/g, REDACTED],
|
|
34
|
+
[/\bAKIA[0-9A-Z]{16}\b/g, REDACTED],
|
|
35
|
+
[/\bAIza[0-9A-Za-z_-]{35}\b/g, REDACTED],
|
|
36
|
+
[/\beyJ[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g, REDACTED],
|
|
37
|
+
[/\b(Bearer|Basic)\s+[A-Za-z0-9._~+/=-]{16,}/g, `$1 ${REDACTED}`],
|
|
38
|
+
[/(\b[a-z][a-z0-9+.-]*:\/\/[^\s:@/]+:)[^\s@/]+@/gi, `$1${REDACTED}@`],
|
|
39
|
+
// KEY=value in an .env file or a shell, by the name's convention.
|
|
40
|
+
[
|
|
41
|
+
/\b([A-Z0-9_]*(?:SECRET|TOKEN|PASSWORD|PASSWD|API_KEY|APIKEY|PRIVATE_KEY|ACCESS_KEY)[A-Z0-9_]*)(\s*[=:]\s*)(["']?)([^\s"'$]{6,})\3/g,
|
|
42
|
+
`$1$2$3${REDACTED}$3`
|
|
43
|
+
],
|
|
44
|
+
// "password": "…" in a JSON or YAML file.
|
|
45
|
+
[
|
|
46
|
+
/(["']?\b(?:password|secret|client_secret|api_key|apiKey|access_token|refresh_token|private_key)["']?\s*:\s*)(["'])([^"'\s]{6,})\2/g,
|
|
47
|
+
`$1$2${REDACTED}$2`
|
|
48
|
+
]
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
export function claudeHome() {
|
|
52
|
+
return process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function projectsDir() {
|
|
56
|
+
return join(claudeHome(), "projects");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function projectKey(dir) {
|
|
60
|
+
return dir.replace(/[^A-Za-z0-9]/g, "-");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// The sessions Claude Code kept for this directory, or for the nearest parent
|
|
64
|
+
// it was started in, newest first.
|
|
65
|
+
export function sessionsFor(startDir) {
|
|
66
|
+
let dir = resolve(startDir);
|
|
67
|
+
for (;;) {
|
|
68
|
+
const sessions = jsonlIn(join(projectsDir(), projectKey(dir)));
|
|
69
|
+
if (sessions.length > 0) return sessions;
|
|
70
|
+
const parent = dirname(dir);
|
|
71
|
+
if (parent === dir) return [];
|
|
72
|
+
dir = parent;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// By id, in whichever directory's folder it is: a session that moved into a
|
|
77
|
+
// worktree is filed under the worktree, not where the command runs.
|
|
78
|
+
export function sessionById(id) {
|
|
79
|
+
const matches = listDir(projectsDir())
|
|
80
|
+
.flatMap((dir) => jsonlIn(join(projectsDir(), dir)))
|
|
81
|
+
.filter((session) => session.id.startsWith(id));
|
|
82
|
+
return matches.sort((a, b) => b.modifiedAt - a.modifiedAt)[0] ?? null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function jsonlIn(dir) {
|
|
86
|
+
return listDir(dir)
|
|
87
|
+
.filter((name) => name.endsWith(".jsonl"))
|
|
88
|
+
.map((name) => {
|
|
89
|
+
const path = join(dir, name);
|
|
90
|
+
const stat = statSync(path);
|
|
91
|
+
return { id: name.slice(0, -".jsonl".length), path, bytes: stat.size, modifiedAt: stat.mtimeMs };
|
|
92
|
+
})
|
|
93
|
+
.sort((a, b) => b.modifiedAt - a.modifiedAt);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function listDir(dir) {
|
|
97
|
+
try {
|
|
98
|
+
return readdirSync(dir);
|
|
99
|
+
} catch {
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// What a session is about, without cleaning it: for --list, and for picking
|
|
105
|
+
// the newest session that has a conversation in it.
|
|
106
|
+
export function describe(session) {
|
|
107
|
+
let title = null;
|
|
108
|
+
let firstPrompt = null;
|
|
109
|
+
let messages = 0;
|
|
110
|
+
let cwd = null;
|
|
111
|
+
for (const entry of entries(session.path)) {
|
|
112
|
+
if (entry.type === "ai-title" && entry.aiTitle) title = entry.aiTitle;
|
|
113
|
+
if (entry.type === "summary" && entry.summary) title ??= entry.summary;
|
|
114
|
+
if (entry.type !== "user" && entry.type !== "assistant") continue;
|
|
115
|
+
messages += 1;
|
|
116
|
+
cwd ??= entry.cwd ?? null;
|
|
117
|
+
if (entry.type === "user" && !entry.isMeta) firstPrompt ??= promptText(entry.message?.content);
|
|
118
|
+
}
|
|
119
|
+
return { ...session, title: title ?? firstPrompt, messages, cwd };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// The session as it is sent: only what was said and done, without images,
|
|
123
|
+
// with anything that looks like a secret replaced and the home directory as ~.
|
|
124
|
+
export function clean(session) {
|
|
125
|
+
const lines = [];
|
|
126
|
+
const counts = { messages: 0, images: 0, redactions: 0 };
|
|
127
|
+
let startedAt = null;
|
|
128
|
+
let endedAt = null;
|
|
129
|
+
let gitBranch = null;
|
|
130
|
+
let cwd = null;
|
|
131
|
+
|
|
132
|
+
for (const entry of entries(session.path)) {
|
|
133
|
+
if (!KEPT_TYPES.has(entry.type)) continue;
|
|
134
|
+
for (const key of DROPPED_KEYS) delete entry[key];
|
|
135
|
+
|
|
136
|
+
const kept = scrub(entry, counts);
|
|
137
|
+
if (entry.type !== "system") counts.messages += 1;
|
|
138
|
+
if (entry.timestamp) {
|
|
139
|
+
startedAt ??= entry.timestamp;
|
|
140
|
+
endedAt = entry.timestamp;
|
|
141
|
+
}
|
|
142
|
+
gitBranch = entry.gitBranch ?? gitBranch;
|
|
143
|
+
cwd ??= kept.cwd ?? null;
|
|
144
|
+
lines.push(JSON.stringify(kept));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
jsonl: lines.length > 0 ? `${lines.join("\n")}\n` : "",
|
|
149
|
+
...counts,
|
|
150
|
+
startedAt,
|
|
151
|
+
endedAt,
|
|
152
|
+
gitBranch,
|
|
153
|
+
cwd
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function* entries(path) {
|
|
158
|
+
for (const line of readFileSync(path, "utf8").split("\n")) {
|
|
159
|
+
if (line.trim() === "") continue;
|
|
160
|
+
try {
|
|
161
|
+
const entry = JSON.parse(line);
|
|
162
|
+
if (entry && typeof entry === "object") yield entry;
|
|
163
|
+
} catch {
|
|
164
|
+
// A line cut off while Claude Code was writing it: the session this
|
|
165
|
+
// command runs in is still being written.
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function scrub(value, counts) {
|
|
171
|
+
if (typeof value === "string") return redact(value, counts);
|
|
172
|
+
if (Array.isArray(value)) return value.map((item) => scrub(item, counts));
|
|
173
|
+
if (!value || typeof value !== "object") return value;
|
|
174
|
+
|
|
175
|
+
// Pictures and PDFs, base64 inline: screenshots of whatever was on screen.
|
|
176
|
+
if (value.source?.type === "base64" && typeof value.source.data === "string") {
|
|
177
|
+
counts.images += 1;
|
|
178
|
+
return { type: value.type, omitted: true };
|
|
179
|
+
}
|
|
180
|
+
// A thinking block's signature is opaque and as long as the thinking.
|
|
181
|
+
if (value.type === "thinking" && "signature" in value) {
|
|
182
|
+
const { signature, ...rest } = value;
|
|
183
|
+
value = rest;
|
|
184
|
+
}
|
|
185
|
+
if (value.type === "redacted_thinking") return { type: value.type, omitted: true };
|
|
186
|
+
|
|
187
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, scrub(item, counts)]));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const HOME = homedir();
|
|
191
|
+
|
|
192
|
+
function redact(text, counts) {
|
|
193
|
+
let result = text;
|
|
194
|
+
for (const [pattern, replacement] of SECRET_PATTERNS) {
|
|
195
|
+
result = result.replace(pattern, (...match) => {
|
|
196
|
+
counts.redactions += 1;
|
|
197
|
+
return replacement.replace(/\$(\d)/g, (_, index) => match[Number(index)] ?? "");
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
return HOME.length > 1 ? result.replaceAll(HOME, "~") : result;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function promptText(content) {
|
|
204
|
+
const text = typeof content === "string"
|
|
205
|
+
? content
|
|
206
|
+
: Array.isArray(content) ? content.find((block) => block?.type === "text")?.text : null;
|
|
207
|
+
// Slash commands and hook output arrive as tags, not as something typed.
|
|
208
|
+
if (!text || text.trimStart().startsWith("<")) return null;
|
|
209
|
+
return text.replace(/\s+/g, " ").trim();
|
|
210
|
+
}
|
package/lib/commands/chat.mjs
CHANGED
|
@@ -235,6 +235,8 @@ async function showChat(config, options, args) {
|
|
|
235
235
|
}
|
|
236
236
|
if (message.role === "tool") {
|
|
237
237
|
console.log(` [tool result] ${truncate(content, 400)}`);
|
|
238
|
+
const limit = toolLimit(content);
|
|
239
|
+
if (limit) console.log(` [tool limit] ${limit}`);
|
|
238
240
|
continue;
|
|
239
241
|
}
|
|
240
242
|
const flags = message.discarded ? " (discarded)" : "";
|
|
@@ -246,6 +248,21 @@ async function showChat(config, options, args) {
|
|
|
246
248
|
if (messages.length === 0) console.log("(no messages)");
|
|
247
249
|
}
|
|
248
250
|
|
|
251
|
+
// Vatio::Runtime::ToolBudget's marks on a tool result, said on a line of their
|
|
252
|
+
// own: the note rides at the end of the result and truncate() can cut it off,
|
|
253
|
+
// which left a turn that ran out of calls looking like one that just stopped.
|
|
254
|
+
function toolLimit(content) {
|
|
255
|
+
let result;
|
|
256
|
+
try {
|
|
257
|
+
result = JSON.parse(content);
|
|
258
|
+
} catch {
|
|
259
|
+
return null;
|
|
260
|
+
}
|
|
261
|
+
if (result?.error_key === "tool_budget_spent") return "call refused: this reply had spent its tool calls";
|
|
262
|
+
if (result?.tool_budget) return "this reply spent its tool calls; the agent was told to answer now";
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
|
|
249
266
|
function truncate(text, max) {
|
|
250
267
|
return text.length > max ? `${text.slice(0, max)}…` : text;
|
|
251
268
|
}
|
package/lib/commands/deploy.mjs
CHANGED
|
@@ -23,10 +23,10 @@ import { detectGitSha, fail, paint, takeEnv, takeFlag, takeValue } from "../supp
|
|
|
23
23
|
|
|
24
24
|
// The first command that makes something exist on a server, so the first one
|
|
25
25
|
// that needs to know whose it is.
|
|
26
|
-
export async function ensureAuthorized(config, { workspace = null } = {}) {
|
|
26
|
+
export async function ensureAuthorized(config, { workspace = null, message = "Before I can push this, I need to know whose it is." } = {}) {
|
|
27
27
|
if (config.resolveToken()) return;
|
|
28
28
|
|
|
29
|
-
const auth = await deviceLogin({ config, workspace, message
|
|
29
|
+
const auth = await deviceLogin({ config, workspace, message });
|
|
30
30
|
config.writeAuth({ baseUrl: auth.baseUrl, token: auth.token });
|
|
31
31
|
console.log(`Token saved to ${config.configPath}`);
|
|
32
32
|
console.log("");
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
// docs and
|
|
2
|
-
// deployment.
|
|
1
|
+
// docs, feedback and share-session — the commands that are about Vatio rather
|
|
2
|
+
// than about a deployment.
|
|
3
3
|
|
|
4
|
-
import { mkdirSync, writeFileSync } from "node:fs";
|
|
5
|
-
import {
|
|
4
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { homedir } from "node:os";
|
|
6
|
+
import { dirname, join, resolve } from "node:path";
|
|
7
|
+
import { gzipSync } from "node:zlib";
|
|
6
8
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
+
import { clean, describe, sessionById, sessionsFor } from "../claude-session.mjs";
|
|
10
|
+
import { configHome } from "../config.mjs";
|
|
11
|
+
import { ask, fail, takeFlag, takeValue } from "../support.mjs";
|
|
12
|
+
import { chosenHeaders, clientHeaders, sendFeedback, telemetryEnabled } from "../telemetry.mjs";
|
|
13
|
+
import { ensureAuthorized } from "./deploy.mjs";
|
|
9
14
|
import { DOCS_URL } from "./misc.mjs";
|
|
10
15
|
|
|
11
16
|
// The whole developer contract as markdown, live from the platform. Fetched
|
|
@@ -61,6 +66,218 @@ export async function feedback(config, args) {
|
|
|
61
66
|
console.log("Sent to the Vatio team, with the commands this session ran before it. Thank you.");
|
|
62
67
|
}
|
|
63
68
|
|
|
69
|
+
// The coding agent's whole session, for when a sentence is not enough: the
|
|
70
|
+
// team reads what the agent read, ran and was told, and where it went wrong.
|
|
71
|
+
// It is the developer's conversation, so nothing leaves without them seeing
|
|
72
|
+
// what it is and saying yes -- at a terminal by answering, and from a coding
|
|
73
|
+
// agent by it asking them and passing --yes. The session goes on its own;
|
|
74
|
+
// feedback in the developer's words rides along when they give some.
|
|
75
|
+
export async function shareSession(config, args) {
|
|
76
|
+
const list = takeFlag(args, "--list");
|
|
77
|
+
const yes = takeFlag(args, "--yes") || takeFlag(args, "-y");
|
|
78
|
+
const id = takeValue(args, "--id");
|
|
79
|
+
const savePath = takeValue(args, "--save");
|
|
80
|
+
const shouldAsk = takeFlag(args, "--should-ask");
|
|
81
|
+
const never = takeFlag(args, "--never");
|
|
82
|
+
let feedback = args.join(" ").trim();
|
|
83
|
+
|
|
84
|
+
if (list) return listSessions();
|
|
85
|
+
if (shouldAsk) return answerShouldAsk();
|
|
86
|
+
if (never) return stopOffering();
|
|
87
|
+
|
|
88
|
+
const session = findSession(id);
|
|
89
|
+
const transcript = clean(session);
|
|
90
|
+
if (transcript.messages === 0) fail(`Session ${short(session.id)} has no messages yet.`);
|
|
91
|
+
const gzipped = gzipSync(transcript.jsonl);
|
|
92
|
+
|
|
93
|
+
const { title } = describe(session);
|
|
94
|
+
console.log(`Claude Code session ${short(session.id)}${title ? ` — ${truncate(title, 70)}` : ""}`);
|
|
95
|
+
console.log(` ${tilde(transcript.cwd ?? process.cwd())}${transcript.gitBranch ? ` (${transcript.gitBranch})` : ""}`);
|
|
96
|
+
console.log(` ${transcript.messages} messages, ${when(transcript.startedAt)} → ${when(transcript.endedAt)}`);
|
|
97
|
+
console.log(` ${size(Buffer.byteLength(transcript.jsonl))}, ${size(gzipped.length)} compressed`);
|
|
98
|
+
console.log(
|
|
99
|
+
` Left out: ${transcript.images > 0 ? `${transcript.images} image(s) and ` : ""}Claude Code's own bookkeeping.` +
|
|
100
|
+
(transcript.redactions > 0 ? ` ${transcript.redactions} thing(s) that looked like a key, token or password are [REDACTED].` : "")
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
if (savePath) {
|
|
104
|
+
const target = resolve(savePath);
|
|
105
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
106
|
+
writeFileSync(target, transcript.jsonl);
|
|
107
|
+
console.log(`\nWrote ${target}: exactly what would be sent. Nothing was sent.`);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
console.log("\nOnly the Vatio team reads it, to see where you and your coding agent got stuck.");
|
|
112
|
+
if (!yes) {
|
|
113
|
+
if (!process.stdin.isTTY) {
|
|
114
|
+
fail(
|
|
115
|
+
"Not sent: this is the whole conversation. Ask the person you work for, and whether they want to\n" +
|
|
116
|
+
'add feedback in their own words, then run it again with --yes ["FEEDBACK"]\n' +
|
|
117
|
+
"(--save FILE writes what would be sent, if they want to read it first)."
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
const answer = (await ask("Send it? [y/N] ")).toLowerCase();
|
|
121
|
+
if (!["y", "yes", "s", "si", "sí"].includes(answer)) {
|
|
122
|
+
console.log("Not sent.");
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (!feedback) feedback = await ask("Feedback for the Vatio team, if you have any (Enter to skip): ");
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
await ensureAuthorized(config, { message: "Before I can send this, I need to know who it is from." });
|
|
129
|
+
|
|
130
|
+
const form = new FormData();
|
|
131
|
+
form.set("transcript", new Blob([gzipped], { type: "application/gzip" }), `${session.id}.jsonl.gz`);
|
|
132
|
+
form.set("source", "claude-code");
|
|
133
|
+
form.set("source_session_id", session.id);
|
|
134
|
+
form.set("messages", String(transcript.messages));
|
|
135
|
+
if (transcript.startedAt) form.set("started_at", transcript.startedAt);
|
|
136
|
+
if (transcript.endedAt) form.set("ended_at", transcript.endedAt);
|
|
137
|
+
if (feedback) form.set("feedback", feedback);
|
|
138
|
+
const workspace = config.resolveWorkspace();
|
|
139
|
+
if (workspace) form.set("workspace", workspace);
|
|
140
|
+
|
|
141
|
+
let response;
|
|
142
|
+
try {
|
|
143
|
+
response = await fetch(`${config.resolveBaseUrl()}/api/developer/v1/cli/transcripts`, {
|
|
144
|
+
method: "POST",
|
|
145
|
+
headers: { ...chosenHeaders(), Authorization: `Bearer ${config.resolveToken()}`, Accept: "application/json" },
|
|
146
|
+
body: form,
|
|
147
|
+
signal: AbortSignal.timeout(120_000)
|
|
148
|
+
});
|
|
149
|
+
} catch (error) {
|
|
150
|
+
fail(`Could not send it: ${error?.cause?.code ?? error.message}. Try again in a moment.`);
|
|
151
|
+
}
|
|
152
|
+
const body = await response.json().catch(() => ({}));
|
|
153
|
+
if (response.status === 401) fail("Your sign-in has expired. Run `vatio login`, then this again.");
|
|
154
|
+
if (!response.ok) fail(`Could not send it: ${body.error_description ?? `HTTP ${response.status}`}`);
|
|
155
|
+
|
|
156
|
+
console.log(`Sent to the Vatio team (#${body.id}). Thank you.`);
|
|
157
|
+
rememberOffer(session.id);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Coding agents offer to send the session when their work is done -- the
|
|
161
|
+
// skills say when -- and ask this first. A yes counts as the offer: never twice
|
|
162
|
+
// in one session, at most once a week, and never again after --never.
|
|
163
|
+
const OFFER_EVERY_MS = 7 * 24 * 60 * 60 * 1000;
|
|
164
|
+
|
|
165
|
+
function answerShouldAsk() {
|
|
166
|
+
const reason = reasonNotToOffer();
|
|
167
|
+
if (reason) {
|
|
168
|
+
console.log(`no — ${reason}`);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
rememberOffer(process.env.CLAUDE_CODE_SESSION_ID);
|
|
172
|
+
console.log(
|
|
173
|
+
"yes — ask the person you work for whether to send this session to the Vatio team: send it, " +
|
|
174
|
+
"not now, or don't ask again (`vatio share-session --never`)."
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function reasonNotToOffer() {
|
|
179
|
+
if (process.env.CI) return "this is CI";
|
|
180
|
+
if (!telemetryEnabled()) return "telemetry is off, so they would rather send nothing";
|
|
181
|
+
const state = readOfferState();
|
|
182
|
+
if (state.never) return "they said not to ask again";
|
|
183
|
+
const current = process.env.CLAUDE_CODE_SESSION_ID;
|
|
184
|
+
if (!current || !sessionById(current)) return "only a Claude Code session can be sent, from inside it";
|
|
185
|
+
if (state.session === current) return "already offered in this session";
|
|
186
|
+
if (Date.now() - Date.parse(state.offered_at ?? "") < OFFER_EVERY_MS) return "already offered this week";
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function stopOffering() {
|
|
191
|
+
writeOfferState({ ...readOfferState(), never: true });
|
|
192
|
+
console.log("Coding agents won't offer to send a session again. `vatio share-session` still sends one when you want.");
|
|
193
|
+
console.log(`To be asked again, delete ${tilde(offerStatePath())}.`);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function rememberOffer(sessionId) {
|
|
197
|
+
try {
|
|
198
|
+
writeOfferState({ ...readOfferState(), offered_at: new Date().toISOString(), session: sessionId });
|
|
199
|
+
} catch {
|
|
200
|
+
// Not remembering only means the next offer comes sooner.
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function offerStatePath() {
|
|
205
|
+
return join(configHome(), "share-session.json");
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function readOfferState() {
|
|
209
|
+
try {
|
|
210
|
+
const state = JSON.parse(readFileSync(offerStatePath(), "utf8"));
|
|
211
|
+
return state && typeof state === "object" && !Array.isArray(state) ? state : {};
|
|
212
|
+
} catch {
|
|
213
|
+
return {};
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function writeOfferState(state) {
|
|
218
|
+
const path = offerStatePath();
|
|
219
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
220
|
+
writeFileSync(path, `${JSON.stringify(state)}\n`);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// The one this coding agent is running in, when it is Claude Code; otherwise
|
|
224
|
+
// the newest one with a conversation in it, started here or above.
|
|
225
|
+
function findSession(id) {
|
|
226
|
+
const current = process.env.CLAUDE_CODE_SESSION_ID;
|
|
227
|
+
if (id || current) {
|
|
228
|
+
const session = sessionById(id ?? current);
|
|
229
|
+
if (session) return session;
|
|
230
|
+
if (id) fail(`No Claude Code session ${id} on this machine. \`vatio share-session --list\` shows them.`);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const session = sessionsFor(process.cwd()).map(describe).find((candidate) => candidate.messages > 0);
|
|
234
|
+
if (session) return session;
|
|
235
|
+
fail(
|
|
236
|
+
"No Claude Code session found for this directory. Run this from the project Claude Code was working in.\n" +
|
|
237
|
+
'Only Claude Code sessions for now: from another coding agent, tell us with `vatio feedback "…"`.'
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function listSessions() {
|
|
242
|
+
const sessions = sessionsFor(process.cwd()).slice(0, 20).map(describe).filter((session) => session.messages > 0).slice(0, 10);
|
|
243
|
+
if (sessions.length === 0) fail("No Claude Code sessions for this directory.");
|
|
244
|
+
|
|
245
|
+
const current = process.env.CLAUDE_CODE_SESSION_ID;
|
|
246
|
+
for (const session of sessions) {
|
|
247
|
+
const mark = session.id === current ? "*" : " ";
|
|
248
|
+
const title = session.title ? truncate(session.title, 60) : "";
|
|
249
|
+
const modified = when(new Date(session.modifiedAt).toISOString());
|
|
250
|
+
console.log(`${mark} ${short(session.id)} ${modified} ${String(session.messages).padStart(5)} msgs ${title}`);
|
|
251
|
+
}
|
|
252
|
+
console.log("\nSend one with `vatio share-session --id ID`.");
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function short(id) {
|
|
256
|
+
return id.slice(0, 8);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function truncate(text, length) {
|
|
260
|
+
return text.length > length ? `${text.slice(0, length - 1)}…` : text;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function when(iso) {
|
|
264
|
+
if (!iso) return "?";
|
|
265
|
+
const date = new Date(iso);
|
|
266
|
+
const pad = (value) => String(value).padStart(2, "0");
|
|
267
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function size(bytes) {
|
|
271
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
272
|
+
if (bytes < 1024 * 1024) return `${Math.round(bytes / 1024)} KB`;
|
|
273
|
+
return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function tilde(path) {
|
|
277
|
+
const home = homedir();
|
|
278
|
+
return path.startsWith(home) ? `~${path.slice(home.length)}` : path;
|
|
279
|
+
}
|
|
280
|
+
|
|
64
281
|
async function readStdin() {
|
|
65
282
|
const chunks = [];
|
|
66
283
|
for await (const chunk of process.stdin) chunks.push(chunk);
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// them is in vatio.yml.
|
|
5
5
|
|
|
6
6
|
import { deployClient } from "./deploy.mjs";
|
|
7
|
+
import { branchEnvironment } from "../branch.mjs";
|
|
7
8
|
import { askSecret, branchDefault, fail, paint, takeFlag, takeValue } from "../support.mjs";
|
|
8
9
|
|
|
9
10
|
// live, preview, or a branch's own like fix-pagos.
|
|
@@ -12,8 +13,14 @@ const ENVIRONMENT_MAX = 40;
|
|
|
12
13
|
|
|
13
14
|
// On a branch, its environment unless told otherwise (see branch.mjs).
|
|
14
15
|
function environmentOption(args, fallback, cwd) {
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
return checkEnvironment(givenEnvironment(args) ?? branchDefault(cwd, fallback));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function givenEnvironment(args) {
|
|
20
|
+
return takeValue(args, "--env") ?? takeValue(args, "--environment") ?? takeValue(args, "-e");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function checkEnvironment(value) {
|
|
17
24
|
if (value === null) return null;
|
|
18
25
|
if (String(value).length > ENVIRONMENT_MAX || !ENVIRONMENT_NAME.test(String(value))) {
|
|
19
26
|
fail(`Unknown environment "${value}" (use live, preview, or a branch's environment like fix-pagos)`);
|
|
@@ -26,39 +33,24 @@ function environmentOption(args, fallback, cwd) {
|
|
|
26
33
|
// its tools at staging while live keeps production. With --tests, the value
|
|
27
34
|
// every environment but live and every eval replay uses, branches included,
|
|
28
35
|
// so it never takes the branch's environment.
|
|
36
|
+
//
|
|
37
|
+
// `list` shows every row, every environment's included, unless --env asks for
|
|
38
|
+
// one: a value set from a branch was otherwise somewhere `list` did not look.
|
|
39
|
+
// Every line names the row's scope, and `set` and `rm` say which one they
|
|
40
|
+
// touched.
|
|
29
41
|
export async function secrets(config, args) {
|
|
30
42
|
const workspace = config.resolveWorkspaceRequired();
|
|
31
43
|
const client = deployClient(config, workspace);
|
|
32
44
|
const tests = takeFlag(args, "--tests");
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
const environment = tests ? null : environmentOption(args, null, config.workspaceRoot);
|
|
37
|
-
const where = tests
|
|
38
|
-
? `workspace ${workspace}, for tests`
|
|
39
|
-
: environment
|
|
40
|
-
? `${environment} on workspace ${workspace}`
|
|
41
|
-
: `workspace ${workspace}`;
|
|
45
|
+
const given = givenEnvironment(args);
|
|
46
|
+
if (tests && given) fail("--tests is the value for every environment but live; drop --env");
|
|
42
47
|
const sub = args.shift() ?? "list";
|
|
43
48
|
|
|
44
|
-
if (sub === "list")
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
console.log(" Set one: vatio secrets set STRIPE_KEY sk_live_…");
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
// Keys only, never values. The platform does not hand a value back once it
|
|
53
|
-
// is stored, and a CLI that printed them would be a CLI that leaks them
|
|
54
|
-
// into a terminal scrollback.
|
|
55
|
-
console.log(`Secrets on ${where} (${keys.length}):`);
|
|
56
|
-
for (const secret of keys) {
|
|
57
|
-
const scope = secret.tests ? " (tests)" : secret.environment ? ` (only ${secret.environment})` : "";
|
|
58
|
-
console.log(` ${secret.key ?? secret}${scope}`);
|
|
59
|
-
}
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
49
|
+
if (sub === "list") return listSecrets(client, workspace, checkEnvironment(given), config.workspaceRoot);
|
|
50
|
+
|
|
51
|
+
const environment = tests ? null : checkEnvironment(given ?? branchDefault(config.workspaceRoot, null));
|
|
52
|
+
const scope = secretScope({ environment, tests });
|
|
53
|
+
|
|
62
54
|
if (sub === "set") {
|
|
63
55
|
const key = args.shift();
|
|
64
56
|
if (!key) fail("Usage: vatio secrets set KEY [VALUE] [--env NAME | --tests]");
|
|
@@ -67,20 +59,48 @@ export async function secrets(config, args) {
|
|
|
67
59
|
const value = args.shift() ?? (await askSecret(`${paint("green", "?")} Paste your secret: `));
|
|
68
60
|
if (value === "") fail(`No value given for ${key}`);
|
|
69
61
|
await client.upsertSecret({ key, value, environment, tests });
|
|
70
|
-
console.log(`${paint("green", "✓")} Set secret ${key} on ${
|
|
62
|
+
console.log(`${paint("green", "✓")} Set secret ${key} on workspace ${workspace} (${scope})`);
|
|
71
63
|
return;
|
|
72
64
|
}
|
|
73
65
|
if (sub === "rm" || sub === "remove" || sub === "delete") {
|
|
74
66
|
const key = args.shift();
|
|
75
67
|
if (!key) fail("Usage: vatio secrets rm KEY [--env NAME | --tests]");
|
|
76
68
|
await client.deleteSecret({ key, environment, tests });
|
|
77
|
-
console.log(`Removed ${key} from ${
|
|
69
|
+
console.log(`Removed ${key} from workspace ${workspace} (${scope})`);
|
|
78
70
|
return;
|
|
79
71
|
}
|
|
80
72
|
|
|
81
73
|
fail("Usage: vatio secrets list|set KEY [VALUE]|rm KEY [--env NAME | --tests]");
|
|
82
74
|
}
|
|
83
75
|
|
|
76
|
+
async function listSecrets(client, workspace, environment, cwd) {
|
|
77
|
+
const payload = await client.listSecrets({ environment });
|
|
78
|
+
const keys = asArray(payload.secrets);
|
|
79
|
+
const title = environment ? `secrets ${environment} reads on workspace ${workspace}` : `secrets on workspace ${workspace}`;
|
|
80
|
+
if (keys.length === 0) {
|
|
81
|
+
console.log(`No ${title}`);
|
|
82
|
+
console.log(" Set one: vatio secrets set STRIPE_KEY sk_live_…");
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
// Keys only, never values. The platform does not hand a value back once it
|
|
86
|
+
// is stored, and a CLI that printed them would be a CLI that leaks them
|
|
87
|
+
// into a terminal scrollback.
|
|
88
|
+
console.log(`${title[0].toUpperCase()}${title.slice(1)} (${keys.length}):`);
|
|
89
|
+
const width = Math.max(...keys.map((secret) => String(secret.key ?? secret).length));
|
|
90
|
+
for (const secret of keys) {
|
|
91
|
+
console.log(` ${String(secret.key ?? secret).padEnd(width)} ${secretScope(secret)}`);
|
|
92
|
+
}
|
|
93
|
+
const branch = environment || !cwd ? null : branchEnvironment(cwd);
|
|
94
|
+
if (branch) {
|
|
95
|
+
console.log(`On branch ${branch.branch}, \`vatio secrets set\` sets the value only ${branch.environment} uses; --env NAME picks another.`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function secretScope({ environment, tests }) {
|
|
100
|
+
if (tests) return "tests";
|
|
101
|
+
return environment ? `only ${environment}` : "every environment";
|
|
102
|
+
}
|
|
103
|
+
|
|
84
104
|
// Repeatable: `--origin https://a.com --origin https://b.com`.
|
|
85
105
|
function takeOrigins(args) {
|
|
86
106
|
const origins = [];
|
package/lib/help.mjs
CHANGED
|
@@ -26,6 +26,13 @@ and the one its pull request deploys to. Elsewhere commands default as listed.
|
|
|
26
26
|
version What this CLI is
|
|
27
27
|
docs [--save [PATH]] The whole developer contract, live from Vatio
|
|
28
28
|
feedback "TEXT" Tell the Vatio team what got in the way
|
|
29
|
+
share-session ["FEEDBACK"] Send this Claude Code session to the Vatio team,
|
|
30
|
+
after showing what goes; feedback optional
|
|
31
|
+
(--save FILE, --list, --id ID; --yes from a
|
|
32
|
+
coding agent)
|
|
33
|
+
share-session --should-ask Whether a coding agent should offer to send it
|
|
34
|
+
now: yes or no, and why
|
|
35
|
+
share-session --never Stop coding agents from offering
|
|
29
36
|
|
|
30
37
|
Deploy:
|
|
31
38
|
push [--env NAME] Validate the workspace, then update a preview
|
package/lib/telemetry.mjs
CHANGED
|
@@ -34,7 +34,8 @@ const SUBCOMMANDS = {
|
|
|
34
34
|
keys: ["list", "create", "revoke"],
|
|
35
35
|
templates: ["list", "create"],
|
|
36
36
|
webhooks: ["list", "create", "test", "deliveries", "enable", "rm"],
|
|
37
|
-
config: ["show", "get", "set", "unset"]
|
|
37
|
+
config: ["show", "get", "set", "unset"],
|
|
38
|
+
"share-session": ["--should-ask", "--never"]
|
|
38
39
|
};
|
|
39
40
|
|
|
40
41
|
export const USER_AGENT = `vatio-cli/${VERSION} (node ${process.version}; ${platform()} ${arch()})`;
|
|
@@ -124,13 +125,15 @@ export async function sendFeedback(config, message) {
|
|
|
124
125
|
await post(config, { kind: "feedback", command: "feedback", message: message.slice(0, MAX_MESSAGE) }, { strict: true });
|
|
125
126
|
}
|
|
126
127
|
|
|
128
|
+
// What the developer chose to send -- `vatio feedback`, `vatio share-session` --
|
|
129
|
+
// says which session and coding agent it came from even with telemetry off.
|
|
130
|
+
export function chosenHeaders() {
|
|
131
|
+
return { ...clientHeaders(), "X-Vatio-Session": sessionId(), "X-Vatio-Agent": codingAgent() };
|
|
132
|
+
}
|
|
133
|
+
|
|
127
134
|
async function post(config, body, { strict = false } = {}) {
|
|
128
135
|
const token = safely(() => config.resolveToken());
|
|
129
|
-
const headers = { ...clientHeaders(), "Content-Type": "application/json", Accept: "application/json" };
|
|
130
|
-
if (strict) {
|
|
131
|
-
headers["X-Vatio-Session"] ??= sessionId();
|
|
132
|
-
headers["X-Vatio-Agent"] ??= codingAgent();
|
|
133
|
-
}
|
|
136
|
+
const headers = { ...(strict ? chosenHeaders() : clientHeaders()), "Content-Type": "application/json", Accept: "application/json" };
|
|
134
137
|
if (token) headers.Authorization = `Bearer ${token}`;
|
|
135
138
|
|
|
136
139
|
const response = await fetch(`${config.resolveBaseUrl()}/api/developer/v1/cli/events`, {
|