@vatio-ai/cli 0.54.1 → 0.56.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/lib/workspace.mjs CHANGED
@@ -3,7 +3,7 @@
3
3
  // small.
4
4
  //
5
5
  // What a `tools/*.yml` declares, which blocks `vatio.yml` accepts and whether
6
- // any of it is valid are answered by POST /api/v1/:slug/deploy/check. The one
6
+ // any of it is valid are answered by POST /api/developer/v1/:slug/check. The one
7
7
  // thing a client cannot ask the platform for is the address of that call: the
8
8
  // slug is in its URL. So this reads `workspace:` and stops.
9
9
 
@@ -16,10 +16,6 @@ export const MANIFEST_FILE = "vatio.yml";
16
16
  // past this is still the platform's to reject; matching here only turns a typo
17
17
  // into a sentence instead of a 404.
18
18
  export const SLUG_FORMAT = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
19
- // The key `agent:` stores its single agent under, and the default an `entry:`
20
- // table falls back to. A workspace may declare several under `agents:`.
21
- export const ENTRY_AGENT = "main";
22
-
23
19
  // The manifest in a directory, or null when the directory is not a workspace
24
20
  // root. This file is the only thing that makes one.
25
21
  export function manifestPath(dir) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vatio-ai/cli",
3
- "version": "0.54.1",
3
+ "version": "0.56.0",
4
4
  "description": "Vatio CLI — deploy and manage Vatio agent workspaces",
5
5
  "keywords": [
6
6
  "vatio",
@@ -1,333 +0,0 @@
1
- // `vatio mcp` — the same CLI, spoken as Model Context Protocol over stdio, so a
2
- // coding agent drives the commands a developer would instead of writing its own
3
- // client for the API.
4
- //
5
- // It wraps the CLI rather than the API on purpose: what the agent reads is
6
- // exactly what the developer would have seen, including the advice at the end
7
- // of a failure. Every command gets a decision recorded in one of two tables --
8
- // COMMANDS (offered) or WITHHELD (deliberately not) -- and the default for a
9
- // command nobody thought about is "not offered".
10
-
11
- import { spawn } from "node:child_process";
12
- import { fileURLToPath } from "node:url";
13
- import { createInterface } from "node:readline";
14
- import { dirname, join } from "node:path";
15
-
16
- import { VERSION } from "../version.mjs";
17
-
18
- const PROTOCOL_VERSIONS = ["2025-06-18", "2025-03-26", "2024-11-05"];
19
- const MAX_OUTPUT = 20_000;
20
- const TIMEOUT_MS = 180_000;
21
-
22
- const COMMANDS = {
23
- docs: {
24
- usage: "[--save [PATH]]",
25
- summary:
26
- "The Vatio developer contract as markdown, live from the platform: vatio.yml, tools, auth, " +
27
- "visitor identity, knowledge, channels, the tool result shape, the whole CLI and API. Read " +
28
- "this before writing or changing anything in a workspace.",
29
- auth: false,
30
- annotations: { readOnlyHint: true, openWorldHint: true }
31
- },
32
- doctor: {
33
- usage: "",
34
- summary:
35
- "Node, config, workspace and token status. Run this when a command fails for a reason that " +
36
- "does not look like the workspace itself.",
37
- auth: false,
38
- annotations: { readOnlyHint: true }
39
- },
40
- tools: {
41
- usage: "check",
42
- summary:
43
- "`tools check` sends the workspace to Vatio and validates it against the contracts there — " +
44
- "manifest shape, tool specs, handler signatures — without deploying anything. The fastest " +
45
- "way to find out whether an edit is deployable; push runs the same check anyway.",
46
- annotations: { readOnlyHint: true }
47
- },
48
- status: {
49
- usage: "",
50
- summary: "Preview and live deployment state for this workspace.",
51
- annotations: { readOnlyHint: true }
52
- },
53
- diff: {
54
- usage: "[--env NAME] [--stat|--name-only|--format json|--full]",
55
- summary:
56
- "What this directory would change against a deployment — preview by default. `--env live` " +
57
- "answers \"what would publishing change?\" without publishing.",
58
- annotations: { readOnlyHint: true }
59
- },
60
- push: {
61
- usage: "[--env NAME]",
62
- summary:
63
- "Validate the workspace and update a preview deployment. Never touches live. On a git branch " +
64
- "other than the default one it lands on that branch's own environment (fix/pagos -> fix-pagos), " +
65
- "the same one the branch's pull request deploys to; elsewhere on `preview`.",
66
- annotations: { readOnlyHint: false }
67
- },
68
- publish: {
69
- usage: "[--env NAME]",
70
- summary:
71
- "Promote an environment to live, with the knowledge changes made in it — what customers see. " +
72
- "Ask the developer first: this is the one step that changes what real visitors get. Refused " +
73
- "when the workspace is connected to GitHub: there, live changes only by merging the branch's " +
74
- "pull request. Refused too when live changed an entry this environment also changed.",
75
- annotations: { readOnlyHint: false, destructiveHint: true }
76
- },
77
- env: {
78
- usage: "[NAME] | list | rm NAME",
79
- summary:
80
- "The environment this workspace is working in — the branch's own on a branch — with its " +
81
- "publishable token, widget snippet, share link, the knowledge entries it changed and any that " +
82
- "live changed underneath. Use its token to point an app being developed at this environment.",
83
- annotations: { readOnlyHint: true }
84
- },
85
- rollback: {
86
- usage: "",
87
- summary: "Put live back to the previous snapshot — its configuration and its knowledge together. Same weight as publish — ask first.",
88
- annotations: { readOnlyHint: false, destructiveHint: true }
89
- },
90
- chat: {
91
- usage: '"message" | transcript | debug | reset [--env NAME] | show CHAT_ID [--json]',
92
- summary:
93
- "Talk to the deployed agent as the developer holding the token, and read the transcript. " +
94
- "`debug` shows the developer view, including tool calls. `--env live` is a real conversation " +
95
- "that appears in the inbox. `show CHAT_ID` reads any chat in the workspace — a visitor's on " +
96
- "the web or WhatsApp too — with the environment and deployment that answered it.",
97
- annotations: { readOnlyHint: false }
98
- },
99
- secrets: {
100
- usage: "list | set KEY VALUE | rm KEY [--env NAME]",
101
- summary:
102
- "Credentials the workspace's tools read as $env.KEY. Values are write-only — listing shows " +
103
- "keys, never values. On a branch (or with --env) a value applies to that environment only, " +
104
- "replacing the one everywhere else: point a branch's tools at staging without touching live.",
105
- annotations: { readOnlyHint: false }
106
- },
107
- kb: {
108
- usage:
109
- "[list] | show NAME | create NAME | write BASE ENTRY [FILE] | cat BASE ENTRY [--version N] | " +
110
- "rm-entry BASE ENTRY | follow BASE URL | unfollow BASE URL | refresh BASE [URL] | status BASE | " +
111
- "publish BASE | history BASE (entry commands take --env NAME)",
112
- summary:
113
- "Knowledge bases, which belong to the workspace rather than to a deployment: `knowledge:` in " +
114
- "vatio.yml is a list of names, and a push neither fills nor empties one. The entries are live; " +
115
- "writes on a branch are changes only that branch's preview answers from, and they go live with " +
116
- "vatio_publish or the merge of its pull request. `status` names entries live changed underneath: " +
117
- "read those from live (`cat --env live`), write your change on top, and the conflict clears.",
118
- annotations: { readOnlyHint: false, openWorldHint: true }
119
- },
120
- tokens: {
121
- usage: "list | create [--env NAME] [--label NAME] [--origin URL]... | origins PREFIX URL... | revoke PREFIX",
122
- summary:
123
- "Publishable tokens for the widget and anything built on the SDK. A created token is shown in " +
124
- "full exactly once. Each token works only from its own allowed origins (--origin, repeatable, or " +
125
- "`origins PREFIX URL...` to replace the list); the install snippet's token is edited in the console.",
126
- annotations: { readOnlyHint: false }
127
- },
128
- widget: {
129
- usage: "[--env NAME]",
130
- summary:
131
- "What the platform will actually enforce for the widget, the origins its tokens accept, and the " +
132
- "tokens that exist. Read-only: the look is edited on the console's Brand page, whose URL it prints.",
133
- annotations: { readOnlyHint: true }
134
- },
135
- whatsapp: {
136
- usage: "[status] | check | activate | deactivate | numbers [list | add PHONE | verify PHONE CODE]",
137
- summary:
138
- "The workspace's own WhatsApp number, which serves live: whether it is connected, whether Meta " +
139
- "delivers to it, and whether it is answering — three things that fail separately. `numbers` is " +
140
- "the other thing: the shared WhatsApp preview, test phones that reach the environment they point at (`point PHONE --env NAME`) and need no Meta " +
141
- "account. A code goes to the handset, so a human has to read it back to you.",
142
- annotations: { readOnlyHint: false, openWorldHint: true }
143
- },
144
- instagram: {
145
- usage: "[status] | check | accounts [list | add @HANDLE | verify CODE]",
146
- summary:
147
- "The workspace's own Instagram account, which serves live, and the shared Instagram preview " +
148
- "under `accounts`. Registering a test account goes handle first, then the developer DMs the " +
149
- "preview account from it and Vatio replies with a code. `instagram connect` is not here — it " +
150
- "needs Meta's consent screen in a browser.",
151
- annotations: { readOnlyHint: false, openWorldHint: true }
152
- }
153
- };
154
-
155
- // Named rather than merely absent, so the reason travels with the refusal.
156
- const WITHHELD = {
157
- login: "needs a browser and a person approving a code",
158
- logout: "would take the developer's credential away from them",
159
- init: "creates a remote workspace; the developer decides that one",
160
- issue: "writes to a human's inbox in the developer's name",
161
- config: "edits the developer's own credentials file",
162
- version: "nothing an agent needs; `doctor` says more",
163
- help: "the tool list is this",
164
- mcp: "this"
165
- };
166
-
167
- const BLOCKED_SUBCOMMANDS = {
168
- chat: { destroy: "destroys a conversation; ask the developer" },
169
- kb: { rm: "deletes an indexed base; ask the developer" },
170
- env: { rm: "removes an environment with its unpublished knowledge changes; ask the developer" },
171
- whatsapp: { connect: "takes Meta credentials the developer holds", disconnect: "ask the developer" },
172
- instagram: { connect: "needs Meta's consent screen in a browser", disconnect: "ask the developer" }
173
- };
174
-
175
- const toolName = (command) => `vatio_${command}`;
176
-
177
- export async function mcp(config) {
178
- const cliPath = join(dirname(fileURLToPath(import.meta.url)), "..", "..", "bin", "vatio.mjs");
179
- const reader = createInterface({ input: process.stdin, crlfDelay: Infinity });
180
-
181
- for await (const line of reader) {
182
- if (line.trim() === "") continue;
183
-
184
- let message;
185
- try {
186
- message = JSON.parse(line);
187
- } catch {
188
- continue;
189
- }
190
-
191
- const response = await handle(message, { config, cliPath });
192
- // A notification has no id and gets no reply, which is the whole of the
193
- // difference between the two in JSON-RPC.
194
- if (response) process.stdout.write(`${JSON.stringify(response)}\n`);
195
- }
196
- }
197
-
198
- async function handle(message, context) {
199
- const id = message.id;
200
- if (id === undefined || id === null) return null;
201
-
202
- const reply = (result) => ({ jsonrpc: "2.0", id, result });
203
-
204
- switch (message.method) {
205
- case "initialize":
206
- return reply(initializeResult(message.params));
207
- case "ping":
208
- return reply({});
209
- case "tools/list":
210
- return reply({ tools: toolDefinitions() });
211
- case "tools/call":
212
- return reply(await callTool(message.params ?? {}, context));
213
- default:
214
- return { jsonrpc: "2.0", id, error: { code: -32601, message: `Unknown method: ${message.method}` } };
215
- }
216
- }
217
-
218
- function initializeResult(params) {
219
- const requested = params?.protocolVersion;
220
- const version = PROTOCOL_VERSIONS.includes(requested) ? requested : PROTOCOL_VERSIONS[0];
221
-
222
- return {
223
- protocolVersion: version,
224
- capabilities: { tools: { listChanged: false } },
225
- serverInfo: { name: "vatio", version: VERSION },
226
- instructions: [
227
- "These tools run the Vatio CLI. A workspace is any directory holding a vatio.yml, and that",
228
- "directory decides which remote it deploys to — there is no workspace flag. Pass workspace_dir",
229
- "when the workspace is not the directory this server started in.",
230
- "",
231
- "Start with vatio_docs: it is the contract for vatio.yml, tools, auth, visitor identity and",
232
- "knowledge, fetched live from the platform, so it is what the platform actually accepts.",
233
- "",
234
- "Work on a git branch (a worktree is ideal): every command then uses that branch's own",
235
- "environment — its agent, its knowledge changes, its secret values — and nothing you do there",
236
- "reaches live or another branch. vatio_env shows which one and the token to point an app at it.",
237
- "",
238
- "The loop is: edit files and knowledge (vatio_kb write), vatio_push, vatio_chat to read the",
239
- "agent's answer, then publish when the developer says so — by merging the branch's pull request",
240
- "when GitHub is connected, vatio_publish otherwise. The prompt and the knowledge go live together.",
241
- "",
242
- "Anything that needs a browser or a person — login, issue, instagram connect — is not here;",
243
- "ask the developer to run it in their terminal."
244
- ].join("\n")
245
- };
246
- }
247
-
248
- function toolDefinitions() {
249
- return Object.entries(COMMANDS).map(([command, spec]) => ({
250
- name: toolName(command),
251
- description: `${spec.summary}\n\nUsage: ${usageLine(command, spec)}`,
252
- inputSchema: {
253
- type: "object",
254
- properties: {
255
- args: { type: "array", items: { type: "string" }, description: `Arguments after \`vatio ${command}\`` },
256
- workspace_dir: { type: "string", description: "Directory holding vatio.yml; defaults to the cwd" }
257
- },
258
- required: []
259
- },
260
- annotations: spec.annotations ?? {}
261
- }));
262
- }
263
-
264
- function usageLine(command, spec) {
265
- return spec.usage ? `vatio ${command} ${spec.usage}` : `vatio ${command}`;
266
- }
267
-
268
- async function callTool(params, { config, cliPath }) {
269
- const name = params.name;
270
- const command = Object.keys(COMMANDS).find((key) => toolName(key) === name);
271
- if (!command) {
272
- const withheld = Object.keys(WITHHELD).find((key) => toolName(key) === name);
273
- if (withheld) return errorResult(`\`vatio ${withheld}\` is not offered here: ${WITHHELD[withheld]}.`);
274
- return errorResult(`Unknown tool ${name}. Offered: ${Object.keys(COMMANDS).map(toolName).join(", ")}`);
275
- }
276
-
277
- const args = Array.isArray(params.arguments?.args) ? params.arguments.args.map(String) : [];
278
- const blocked = BLOCKED_SUBCOMMANDS[command]?.[args[0]];
279
- if (blocked) return errorResult(`\`vatio ${command} ${args[0]}\` is not offered here: ${blocked}.`);
280
-
281
- if (COMMANDS[command].auth !== false && !config.resolveToken()) {
282
- return errorResult(
283
- "Not logged in: no token in VATIO_TOKEN or ~/.vatio/config.json. Ask the developer to run " +
284
- "`vatio login` in their terminal — the device authorization needs a browser — and this " +
285
- "server picks the token up from there."
286
- );
287
- }
288
-
289
- const dir = params.arguments?.workspace_dir ?? process.cwd();
290
- const { stdout, stderr, code, timedOut } = await run(cliPath, [command, ...args], dir);
291
-
292
- if (timedOut) return errorResult(`\`vatio ${command}\` did not finish within ${TIMEOUT_MS / 1000}s.`);
293
-
294
- const body = [stdout, stderr].map((part) => part.trim()).filter(Boolean).join("\n");
295
- if (code !== 0) return errorResult(`${body}\n\n\`vatio ${command}\` exited ${code}.`.trim());
296
- return { content: [{ type: "text", text: truncate(body) }], isError: false };
297
- }
298
-
299
- function run(cliPath, args, cwd) {
300
- return new Promise((resolvePromise) => {
301
- const child = spawn(process.execPath, [cliPath, ...args], { cwd, stdio: ["ignore", "pipe", "pipe"] });
302
- let stdout = "";
303
- let stderr = "";
304
- let timedOut = false;
305
-
306
- const timer = setTimeout(() => {
307
- timedOut = true;
308
- child.kill("SIGKILL");
309
- }, TIMEOUT_MS);
310
-
311
- child.stdout.on("data", (chunk) => { stdout += chunk; });
312
- child.stderr.on("data", (chunk) => { stderr += chunk; });
313
- child.on("error", (error) => {
314
- clearTimeout(timer);
315
- resolvePromise({ stdout, stderr: String(error.message), code: 1, timedOut });
316
- });
317
- child.on("close", (code) => {
318
- clearTimeout(timer);
319
- resolvePromise({ stdout, stderr, code: code ?? 1, timedOut });
320
- });
321
- });
322
- }
323
-
324
- // A failure is a tool result, not a protocol error: exiting or raising would
325
- // take the whole session down over one bad push.
326
- function errorResult(message) {
327
- return { content: [{ type: "text", text: truncate(message) }], isError: true };
328
- }
329
-
330
- function truncate(text) {
331
- const value = String(text ?? "");
332
- return value.length <= MAX_OUTPUT ? value : `${value.slice(0, MAX_OUTPUT - 3)}...`;
333
- }