@vatio-ai/cli 0.66.0 → 0.68.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 +7 -5
- package/lib/claude-session.mjs +210 -0
- package/lib/commands/deploy.mjs +2 -2
- package/lib/commands/improve.mjs +31 -5
- package/lib/commands/misc.mjs +2 -0
- package/lib/commands/support-commands.mjs +223 -6
- package/lib/help.mjs +13 -1
- package/lib/telemetry.mjs +9 -6
- package/package.json +1 -1
package/bin/vatio.mjs
CHANGED
|
@@ -19,8 +19,8 @@ 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";
|
|
23
|
-
import { evalCommand, flags } from "../lib/commands/improve.mjs";
|
|
22
|
+
import { docs, feedback, shareSession } from "../lib/commands/support-commands.mjs";
|
|
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";
|
|
26
26
|
import { beginRun, isCodingAgent, reportRun, telemetryEnabled } from "../lib/telemetry.mjs";
|
|
@@ -33,8 +33,6 @@ const RETIRED = {
|
|
|
33
33
|
"or read the manifest at GET /api/developer/v1/:slug/manifest.",
|
|
34
34
|
issue: "was removed: report a problem on the public repository it belongs to --\n" +
|
|
35
35
|
"https://github.com/vatio-ai/cli/issues (or sdk, ios, ruby under github.com/vatio-ai).",
|
|
36
|
-
tools: "was removed: `vatio push` validates before it deploys, and `vatio diff` validates\n" +
|
|
37
|
-
"without deploying.",
|
|
38
36
|
widget: "was removed: `vatio env` prints the snippet and its token, and the look is edited on\n" +
|
|
39
37
|
"the console's Widget page.",
|
|
40
38
|
mcp: "was removed. Point your coding agent at `vatio docs --save` and let it run the CLI.",
|
|
@@ -109,12 +107,16 @@ async function run(command, args) {
|
|
|
109
107
|
return await flags(config, args);
|
|
110
108
|
case "eval":
|
|
111
109
|
return await evalCommand(config, args);
|
|
110
|
+
case "tools":
|
|
111
|
+
return await tools(config, args);
|
|
112
112
|
case "propose":
|
|
113
113
|
return await propose(config, args);
|
|
114
114
|
case "docs":
|
|
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/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("");
|
package/lib/commands/improve.mjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
// flags / eval -- what supervisors flagged,
|
|
1
|
+
// flags / eval / tools -- what supervisors flagged, proving a fix for it, and
|
|
2
|
+
// how the tools' backend has been answering.
|
|
2
3
|
//
|
|
3
|
-
//
|
|
4
|
-
// flags` is the document it fixes the agent from,
|
|
5
|
-
// evidence that the fix worked on a branch before anyone merges it
|
|
4
|
+
// All print markdown, because the reader is usually a coding agent: `vatio
|
|
5
|
+
// flags` is the document it fixes the agent from, `vatio eval` is the
|
|
6
|
+
// evidence that the fix worked on a branch before anyone merges it, and
|
|
7
|
+
// `vatio tools` is the console's Tools page for the failures nobody flagged.
|
|
6
8
|
|
|
7
9
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
8
10
|
import { dirname, resolve } from "node:path";
|
|
@@ -27,7 +29,11 @@ async function fetchMarkdown(config, path, what) {
|
|
|
27
29
|
headers: { ...clientHeaders(), Accept: "text/markdown, text/plain", Authorization: `Bearer ${token}` },
|
|
28
30
|
signal: AbortSignal.timeout(30_000)
|
|
29
31
|
});
|
|
30
|
-
if (!response.ok)
|
|
32
|
+
if (!response.ok) {
|
|
33
|
+
const body = await response.json().catch(() => null);
|
|
34
|
+
const reason = body?.error?.message ?? `HTTP ${response.status}`;
|
|
35
|
+
fail(`Could not read ${what} (${reason})`);
|
|
36
|
+
}
|
|
31
37
|
return await response.text();
|
|
32
38
|
}
|
|
33
39
|
|
|
@@ -58,6 +64,26 @@ export async function flags(config, args) {
|
|
|
58
64
|
console.log(`Wrote ${target}. Hand it to your coding agent; re-run \`vatio flags --save\` to refresh.`);
|
|
59
65
|
}
|
|
60
66
|
|
|
67
|
+
// Each tool's calls, error rate, timeouts and p50/p95 latency over a period,
|
|
68
|
+
// then the calls that failed with what your backend answered: the console's
|
|
69
|
+
// Tools page.
|
|
70
|
+
export async function tools(config, args) {
|
|
71
|
+
const environment = takeEnv(args, { fallback: "live", cwd: config.workspaceRoot });
|
|
72
|
+
const period = takeValue(args, "--period");
|
|
73
|
+
const json = takeFlag(args, "--json");
|
|
74
|
+
if (args.length > 0) fail("Usage: vatio tools [--env NAME] [--period 1h|1d|7d|30d] [--json]");
|
|
75
|
+
|
|
76
|
+
if (json) {
|
|
77
|
+
const { url, token } = workspaceBase(config);
|
|
78
|
+
const body = await new HttpClient({ baseUrl: url, token }).get("/tools", { environment, period });
|
|
79
|
+
process.stdout.write(`${JSON.stringify(body, null, 2)}\n`);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const query = new URLSearchParams({ environment, ...(period ? { period } : {}) });
|
|
84
|
+
process.stdout.write(await fetchMarkdown(config, `/tools.md?${query}`, "the tools"));
|
|
85
|
+
}
|
|
86
|
+
|
|
61
87
|
// Replays every eval case -- each flag is one -- against an environment and
|
|
62
88
|
// waits for the judge. Exits 1 when a case fails, so it can gate CI.
|
|
63
89
|
export async function evalCommand(config, args) {
|
package/lib/commands/misc.mjs
CHANGED
|
@@ -140,6 +140,8 @@ const AGENTS_NOTE = [
|
|
|
140
140
|
"To improve the agent from what supervisors flagged in the inbox, run",
|
|
141
141
|
"`vatio flags` and follow the instructions at the top of its output. Prove",
|
|
142
142
|
"each fix with `vatio eval` on a branch before opening a pull request.",
|
|
143
|
+
"`vatio tools --env live` shows how each tool's backend has been answering:",
|
|
144
|
+
"error rate, timeouts, latency and the calls that failed.",
|
|
143
145
|
""
|
|
144
146
|
].join("\n");
|
|
145
147
|
|
|
@@ -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);
|
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
|
|
@@ -51,10 +58,15 @@ and the one its pull request deploys to. Elsewhere commands default as listed.
|
|
|
51
58
|
The chat you are in, or any chat in the workspace
|
|
52
59
|
(web, WhatsApp, ...): messages, tool calls, channel
|
|
53
60
|
|
|
54
|
-
Improve it from what supervisors flagged:
|
|
61
|
+
Improve it from what supervisors flagged and how its tools answered:
|
|
55
62
|
flags [--save [PATH]|--json]
|
|
56
63
|
Every open flag: the conversation, what each tool
|
|
57
64
|
answered, and what should have happened
|
|
65
|
+
tools [--env NAME] [--period 1h|1d|7d|30d] [--json]
|
|
66
|
+
The console's Tools page: each tool's calls, error
|
|
67
|
+
rate, timeouts and p50/p95, then the calls that
|
|
68
|
+
failed with what your backend answered. Default:
|
|
69
|
+
the branch's environment, else live; 7d
|
|
58
70
|
eval [--env NAME] [--agent SLUG] [--no-wait]
|
|
59
71
|
Replay every eval case (each flag is one) and
|
|
60
72
|
judge it; exits 1 if one fails. Default: the
|
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`, {
|