@vatio-ai/cli 0.70.0 → 0.72.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/README.md +8 -4
- package/bin/vatio.mjs +2 -4
- package/lib/api-client.mjs +7 -22
- package/lib/commands/chat.mjs +1 -1
- package/lib/commands/deploy.mjs +40 -17
- package/lib/commands/env.mjs +14 -18
- package/lib/commands/improve.mjs +13 -8
- package/lib/commands/knowledge.mjs +8 -9
- package/lib/commands/misc.mjs +4 -3
- package/lib/commands/webhooks.mjs +2 -2
- package/lib/commands/workspace-admin.mjs +18 -25
- package/lib/help.mjs +27 -31
- package/lib/skills-hint.mjs +84 -0
- package/lib/support.mjs +20 -26
- package/package.json +1 -1
- package/lib/branch.mjs +0 -51
- package/lib/commands/propose.mjs +0 -51
package/README.md
CHANGED
|
@@ -53,8 +53,8 @@ init [SLUG] Create vatio.yml here, and the remote to match
|
|
|
53
53
|
login | logout Authorize this machine in a browser, or revoke and forget it
|
|
54
54
|
doctor Node, config, workspace and token status
|
|
55
55
|
|
|
56
|
-
push
|
|
57
|
-
publish
|
|
56
|
+
push Validate the workspace, then update preview
|
|
57
|
+
publish Take preview live, once `vatio eval` has tested it
|
|
58
58
|
diff [--env NAME] What this directory would change
|
|
59
59
|
status Preview and live deployment state
|
|
60
60
|
rollback Restore the previous live deployment
|
|
@@ -64,6 +64,10 @@ chat "message" [--env NAME] [--new]
|
|
|
64
64
|
chat show [CHAT_ID] [--json]
|
|
65
65
|
The chat you are in, or any chat in the workspace, with its tool calls
|
|
66
66
|
|
|
67
|
+
flags Every open report from the inbox, for your coding agent to fix
|
|
68
|
+
eval Test every report against preview; exits 1 if one fails
|
|
69
|
+
tools [--env NAME] How each tool's backend has been answering
|
|
70
|
+
|
|
67
71
|
kb list|show|create|rm Knowledge bases
|
|
68
72
|
kb write|cat|rm-entry Entries, from a file or stdin
|
|
69
73
|
|
|
@@ -78,8 +82,8 @@ docs [--save [PATH]] The whole developer contract
|
|
|
78
82
|
config show|set|unset base_url and token, per developer
|
|
79
83
|
```
|
|
80
84
|
|
|
81
|
-
`--env NAME` targets
|
|
82
|
-
|
|
85
|
+
`--env NAME` targets an environment: `preview`, the next version, or `live`,
|
|
86
|
+
what visitors talk to.
|
|
83
87
|
|
|
84
88
|
Run `npx @vatio-ai/cli help` for the whole surface, and see
|
|
85
89
|
[vatio.ai/docs](https://vatio.ai/docs) for the platform.
|
package/bin/vatio.mjs
CHANGED
|
@@ -21,7 +21,6 @@ import { business } from "../lib/commands/business.mjs";
|
|
|
21
21
|
import { instagram, whatsapp } from "../lib/commands/channels.mjs";
|
|
22
22
|
import { docs, feedback, shareSession } from "../lib/commands/support-commands.mjs";
|
|
23
23
|
import { evalCommand, flags, tools } from "../lib/commands/improve.mjs";
|
|
24
|
-
import { propose } from "../lib/commands/propose.mjs";
|
|
25
24
|
import { printUpdateNotice, startUpdateCheck } from "../lib/update-notice.mjs";
|
|
26
25
|
import { beginRun, isCodingAgent, reportRun, telemetryEnabled } from "../lib/telemetry.mjs";
|
|
27
26
|
|
|
@@ -37,7 +36,8 @@ const RETIRED = {
|
|
|
37
36
|
"the console's Widget page.",
|
|
38
37
|
mcp: "was removed. Point your coding agent at `vatio docs --save` and let it run the CLI.",
|
|
39
38
|
update: "is npm's job now: `npx @vatio-ai/cli@latest` always runs the current release, and\n" +
|
|
40
|
-
"`npm install -g @vatio-ai/cli@latest` updates a global install."
|
|
39
|
+
"`npm install -g @vatio-ai/cli@latest` updates a global install.",
|
|
40
|
+
propose: "was removed in 0.71.0. Test with `vatio eval` and publish with `vatio publish`."
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
const config = new Config({ startDir: process.cwd() });
|
|
@@ -109,8 +109,6 @@ async function run(command, args) {
|
|
|
109
109
|
return await evalCommand(config, args);
|
|
110
110
|
case "tools":
|
|
111
111
|
return await tools(config, args);
|
|
112
|
-
case "propose":
|
|
113
|
-
return await propose(config, args);
|
|
114
112
|
case "docs":
|
|
115
113
|
return await docs(config, args);
|
|
116
114
|
case "feedback":
|
package/lib/api-client.mjs
CHANGED
|
@@ -29,19 +29,21 @@ export class ApiClient extends HttpClient {
|
|
|
29
29
|
return this.post("/check", body);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
pushPreview({ manifest, gitSha = null, gitBranch = null, createdBy = null, environment = null }) {
|
|
32
|
+
pushPreview({ manifest, gitSha = null, gitBranch = null, createdBy = null, environment = null, force = false }) {
|
|
33
33
|
const body = { manifest };
|
|
34
34
|
if (gitSha) body.git_sha = gitSha;
|
|
35
35
|
if (gitBranch) body.git_branch = gitBranch;
|
|
36
36
|
if (createdBy) body.created_by = createdBy;
|
|
37
37
|
if (environment) body.environment = environment;
|
|
38
|
+
if (force) body.force = true;
|
|
38
39
|
return this.put("/push", body);
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
publish({ createdBy = null, environment = null } = {}) {
|
|
42
|
+
publish({ createdBy = null, environment = null, force = false } = {}) {
|
|
42
43
|
const body = {};
|
|
43
44
|
if (createdBy) body.created_by = createdBy;
|
|
44
45
|
if (environment) body.environment = environment;
|
|
46
|
+
if (force) body.force = true;
|
|
45
47
|
return this.post("/publish", body);
|
|
46
48
|
}
|
|
47
49
|
|
|
@@ -61,23 +63,6 @@ export class ApiClient extends HttpClient {
|
|
|
61
63
|
return this.get(`/env/${encode(name)}`);
|
|
62
64
|
}
|
|
63
65
|
|
|
64
|
-
deleteEnvironment(name) {
|
|
65
|
-
return this.delete(`/env/${encode(name)}`);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// --- proposals ------------------------------------------------------
|
|
69
|
-
|
|
70
|
-
proposals() {
|
|
71
|
-
return this.get("/proposals");
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
propose({ environment, title, summary }) {
|
|
75
|
-
const body = { environment };
|
|
76
|
-
if (title) body.title = title;
|
|
77
|
-
if (summary != null) body.summary = summary;
|
|
78
|
-
return this.post("/proposals", body);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
66
|
// The project "Connect Supabase" picked in the console, if any.
|
|
82
67
|
supabase() {
|
|
83
68
|
return this.get("/supabase");
|
|
@@ -106,9 +91,9 @@ export class ApiClient extends HttpClient {
|
|
|
106
91
|
|
|
107
92
|
// --- knowledge bases ------------------------------------------------
|
|
108
93
|
//
|
|
109
|
-
// Every read and write below is as one environment sees the base:
|
|
110
|
-
//
|
|
111
|
-
//
|
|
94
|
+
// Every read and write below is as one environment sees the base: preview,
|
|
95
|
+
// which keeps its changes on top of live, or `live` itself. Without one the
|
|
96
|
+
// platform means `preview`.
|
|
112
97
|
|
|
113
98
|
knowledgeBases({ environment = null } = {}) {
|
|
114
99
|
return this.get("/knowledge_bases", { environment });
|
package/lib/commands/chat.mjs
CHANGED
|
@@ -36,7 +36,7 @@ export async function chat(config, args) {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
const environment = takeEnv(args, { fallback: "preview"
|
|
39
|
+
const environment = takeEnv(args, { fallback: "preview" });
|
|
40
40
|
const timeout = Number(takeValue(args, "--timeout") ?? 120);
|
|
41
41
|
const lastValue = takeValue(args, "--last");
|
|
42
42
|
const last = Number(lastValue ?? 10);
|
package/lib/commands/deploy.mjs
CHANGED
|
@@ -16,10 +16,9 @@ import { stringify as stringifyYaml } from "yaml";
|
|
|
16
16
|
|
|
17
17
|
import { buildBundle, BundleError } from "../bundle.mjs";
|
|
18
18
|
import { ApiClient, CliClient } from "../api-client.mjs";
|
|
19
|
-
import { NotFoundError } from "../http.mjs";
|
|
19
|
+
import { NotFoundError, UnprocessableError } from "../http.mjs";
|
|
20
20
|
import { deviceLogin } from "./auth.mjs";
|
|
21
|
-
import {
|
|
22
|
-
import { detectGitSha, fail, paint, takeEnv, takeFlag, takeValue } from "../support.mjs";
|
|
21
|
+
import { detectGitBranch, detectGitSha, fail, paint, takeEnv, takeFlag, takeValue } from "../support.mjs";
|
|
23
22
|
|
|
24
23
|
// The first command that makes something exist on a server, so the first one
|
|
25
24
|
// that needs to know whose it is.
|
|
@@ -85,9 +84,11 @@ function diagnosticLine(row) {
|
|
|
85
84
|
export async function push(config, args) {
|
|
86
85
|
// Null, not "preview": the platform owns that default, and sending it
|
|
87
86
|
// explicitly would make a bare `vatio push` and `vatio push --env preview`
|
|
88
|
-
// two different requests that only happen to agree today.
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
// two different requests that only happen to agree today.
|
|
88
|
+
const environment = takeEnv(args, { fallback: null });
|
|
89
|
+
// Replaces an unpublished push from another branch, which the platform
|
|
90
|
+
// otherwise refuses (preview_has_unpublished_push).
|
|
91
|
+
const force = takeFlag(args, "--force");
|
|
91
92
|
const workspace = config.resolveWorkspaceRequired();
|
|
92
93
|
|
|
93
94
|
await ensureAuthorized(config, { workspace });
|
|
@@ -110,9 +111,10 @@ export async function push(config, args) {
|
|
|
110
111
|
const payload = await client.pushPreview({
|
|
111
112
|
manifest: check.manifest,
|
|
112
113
|
gitSha: detectGitSha(config.workspaceRootRequired()),
|
|
113
|
-
gitBranch:
|
|
114
|
+
gitBranch: detectGitBranch(config.workspaceRootRequired()),
|
|
114
115
|
createdBy: process.env.USER ?? null,
|
|
115
|
-
environment
|
|
116
|
+
environment,
|
|
117
|
+
force
|
|
116
118
|
});
|
|
117
119
|
|
|
118
120
|
const landedOn = payload.environment ?? "preview";
|
|
@@ -142,15 +144,25 @@ function printNotices(payload) {
|
|
|
142
144
|
|
|
143
145
|
export async function publish(config, args) {
|
|
144
146
|
// Here `--env` names the environment being promoted, not a destination: the
|
|
145
|
-
// destination of a publish is always live
|
|
146
|
-
//
|
|
147
|
-
|
|
148
|
-
|
|
147
|
+
// destination of a publish is always live, and what goes there is preview,
|
|
148
|
+
// with its knowledge changes.
|
|
149
|
+
const environment = takeEnv(args, { fallback: null });
|
|
150
|
+
// Publishes even when preview fails a report that live passes.
|
|
151
|
+
const force = takeFlag(args, "--force");
|
|
149
152
|
const workspace = config.resolveWorkspaceRequired();
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
153
|
+
let payload;
|
|
154
|
+
try {
|
|
155
|
+
payload = await deployClient(config, workspace).publish({
|
|
156
|
+
createdBy: process.env.USER ?? null,
|
|
157
|
+
environment,
|
|
158
|
+
force
|
|
159
|
+
});
|
|
160
|
+
} catch (error) {
|
|
161
|
+
// evals_missing and evals_running already say what to run next; a
|
|
162
|
+
// regression also needs to say which reports.
|
|
163
|
+
if (error instanceof UnprocessableError && error.errorKey === "evals_regressed") fail(regressionsMessage(error));
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
154
166
|
const from = asArray(payload.published_from);
|
|
155
167
|
const source = from.length > 0 ? ` from ${from.join(", ")}` : "";
|
|
156
168
|
console.log(`Published live deployment #${payload.deployment_id}${source} (git_sha=${JSON.stringify(payload.git_sha ?? null)})`);
|
|
@@ -159,6 +171,17 @@ export async function publish(config, args) {
|
|
|
159
171
|
printNotices(payload);
|
|
160
172
|
}
|
|
161
173
|
|
|
174
|
+
function regressionsMessage(error) {
|
|
175
|
+
const lines = [error.message];
|
|
176
|
+
for (const row of asArray(error.body.regressions)) lines.push(` ${row.id} — ${row.title}`);
|
|
177
|
+
lines.push(
|
|
178
|
+
"",
|
|
179
|
+
"Fix them, then `vatio push` and `vatio eval` again before publishing.",
|
|
180
|
+
"`vatio publish --force` publishes anyway: only if you know what you're doing."
|
|
181
|
+
);
|
|
182
|
+
return lines.join("\n");
|
|
183
|
+
}
|
|
184
|
+
|
|
162
185
|
export async function rollback(config) {
|
|
163
186
|
const workspace = config.resolveWorkspaceRequired();
|
|
164
187
|
const payload = await deployClient(config, workspace).rollback({ createdBy: process.env.USER ?? null });
|
|
@@ -183,7 +206,7 @@ export async function status(config) {
|
|
|
183
206
|
}
|
|
184
207
|
|
|
185
208
|
export async function diff(config, args) {
|
|
186
|
-
const environment = takeEnv(args, { fallback: "preview"
|
|
209
|
+
const environment = takeEnv(args, { fallback: "preview" });
|
|
187
210
|
const full = takeFlag(args, "--full");
|
|
188
211
|
const stat = takeFlag(args, "--stat");
|
|
189
212
|
const nameOnly = takeFlag(args, "--name-only");
|
package/lib/commands/env.mjs
CHANGED
|
@@ -1,26 +1,29 @@
|
|
|
1
|
-
// `vatio env` —
|
|
1
|
+
// `vatio env` — an environment, and how to point things at it.
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
3
|
+
// There are two: preview, the next version, which `vatio push` updates and
|
|
4
|
+
// where its knowledge changes and secret values sit on top of live; and live,
|
|
5
|
+
// what visitors talk to. This hands over what an app needs to talk to one --
|
|
6
|
+
// the publishable token and the widget snippet -- and the link to try it in
|
|
7
|
+
// the console.
|
|
8
8
|
|
|
9
9
|
import { deployClient } from "./deploy.mjs";
|
|
10
10
|
import { fail, takeEnv } from "../support.mjs";
|
|
11
11
|
|
|
12
12
|
export async function env(config, args) {
|
|
13
|
+
if (args[0] === "rm") {
|
|
14
|
+
fail("`vatio env rm` was removed in 0.71.0, with named environments: there are only preview and live.");
|
|
15
|
+
}
|
|
16
|
+
|
|
13
17
|
const workspace = config.resolveWorkspaceRequired();
|
|
14
18
|
const client = deployClient(config, workspace);
|
|
15
|
-
const sub = ["list", "show"
|
|
19
|
+
const sub = ["list", "show"].includes(args[0]) ? args.shift() : "show";
|
|
16
20
|
|
|
17
21
|
if (sub === "list") return await list(client, workspace);
|
|
18
22
|
|
|
19
23
|
const named = args.find((arg) => !arg.startsWith("-"));
|
|
20
24
|
if (named) args.splice(args.indexOf(named), 1);
|
|
21
|
-
const name = named ?? takeEnv(args, { fallback: "preview"
|
|
25
|
+
const name = named ?? takeEnv(args, { fallback: "preview" });
|
|
22
26
|
|
|
23
|
-
if (sub === "rm") return await remove(client, workspace, name);
|
|
24
27
|
return await show(client, workspace, name);
|
|
25
28
|
}
|
|
26
29
|
|
|
@@ -42,7 +45,8 @@ async function show(client, workspace, name) {
|
|
|
42
45
|
row = await client.environment(name);
|
|
43
46
|
} catch (error) {
|
|
44
47
|
if (error?.status !== 404) throw error;
|
|
45
|
-
|
|
48
|
+
const creates = name === "live" ? "vatio publish" : "vatio push";
|
|
49
|
+
console.log(`${name} on workspace ${workspace} does not exist yet — \`${creates}\` creates it.`);
|
|
46
50
|
return;
|
|
47
51
|
}
|
|
48
52
|
|
|
@@ -76,14 +80,6 @@ async function show(client, workspace, name) {
|
|
|
76
80
|
if (secrets.length > 0) console.log(`\n secrets with their own value here: ${secrets.join(", ")}`);
|
|
77
81
|
}
|
|
78
82
|
|
|
79
|
-
async function remove(client, workspace, name) {
|
|
80
|
-
if (!name || name === "live") fail("usage: vatio env rm NAME (live cannot be removed)");
|
|
81
|
-
|
|
82
|
-
const result = await client.deleteEnvironment(name);
|
|
83
|
-
console.log(`Removed ${name} from workspace ${workspace} (${result.agents ?? 0} agents, ${result.chats ?? 0} chats)`);
|
|
84
|
-
console.log("Its unpublished knowledge changes and secret values went with it.");
|
|
85
|
-
}
|
|
86
|
-
|
|
87
83
|
function asArray(value) {
|
|
88
84
|
return Array.isArray(value) ? value : [];
|
|
89
85
|
}
|
package/lib/commands/improve.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
// flags / eval / tools -- what supervisors
|
|
1
|
+
// flags / eval / tools -- what supervisors reported, proving a fix for it, and
|
|
2
2
|
// how the tools' backend has been answering.
|
|
3
3
|
//
|
|
4
4
|
// All print markdown, because the reader is usually a coding agent: `vatio
|
|
5
5
|
// flags` is the document it fixes the agent from, `vatio eval` is the
|
|
6
|
-
// evidence that the fix worked on
|
|
7
|
-
// `vatio tools` is the console's Tools page for the failures nobody
|
|
6
|
+
// evidence that the fix worked on preview before `vatio publish` takes it
|
|
7
|
+
// live, and `vatio tools` is the console's Tools page for the failures nobody
|
|
8
|
+
// reported.
|
|
8
9
|
|
|
9
10
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
10
11
|
import { dirname, resolve } from "node:path";
|
|
@@ -12,6 +13,7 @@ import { dirname, resolve } from "node:path";
|
|
|
12
13
|
import { HttpClient } from "../http.mjs";
|
|
13
14
|
import { clientHeaders } from "../telemetry.mjs";
|
|
14
15
|
import { fail, sleep, takeEnv, takeFlag, takeValue } from "../support.mjs";
|
|
16
|
+
import { printSkillsHint } from "../skills-hint.mjs";
|
|
15
17
|
|
|
16
18
|
const POLL_MS = 3_000;
|
|
17
19
|
const DEFAULT_TIMEOUT_S = 900;
|
|
@@ -55,6 +57,7 @@ export async function flags(config, args) {
|
|
|
55
57
|
const markdown = await fetchMarkdown(config, "/flags.md", "the flags");
|
|
56
58
|
if (!save) {
|
|
57
59
|
process.stdout.write(markdown);
|
|
60
|
+
printSkillsHint();
|
|
58
61
|
return;
|
|
59
62
|
}
|
|
60
63
|
|
|
@@ -62,13 +65,14 @@ export async function flags(config, args) {
|
|
|
62
65
|
mkdirSync(dirname(target), { recursive: true });
|
|
63
66
|
writeFileSync(target, markdown);
|
|
64
67
|
console.log(`Wrote ${target}. Hand it to your coding agent; re-run \`vatio flags --save\` to refresh.`);
|
|
68
|
+
printSkillsHint();
|
|
65
69
|
}
|
|
66
70
|
|
|
67
71
|
// Each tool's calls, error rate, timeouts and p50/p95 latency over a period,
|
|
68
72
|
// then the calls that failed with what your backend answered: the console's
|
|
69
73
|
// Tools page.
|
|
70
74
|
export async function tools(config, args) {
|
|
71
|
-
const environment = takeEnv(args, { fallback: "live"
|
|
75
|
+
const environment = takeEnv(args, { fallback: "live" });
|
|
72
76
|
const period = takeValue(args, "--period");
|
|
73
77
|
const json = takeFlag(args, "--json");
|
|
74
78
|
if (args.length > 0) fail("Usage: vatio tools [--env NAME] [--period 1h|1d|7d|30d] [--json]");
|
|
@@ -84,13 +88,13 @@ export async function tools(config, args) {
|
|
|
84
88
|
process.stdout.write(await fetchMarkdown(config, `/tools.md?${query}`, "the tools"));
|
|
85
89
|
}
|
|
86
90
|
|
|
87
|
-
// Replays every
|
|
88
|
-
//
|
|
91
|
+
// Replays every report with a note against an environment and waits for the
|
|
92
|
+
// judge. Exits 1 when a case fails, so it can gate CI.
|
|
89
93
|
export async function evalCommand(config, args) {
|
|
90
94
|
const show = takeValue(args, "--show");
|
|
91
95
|
if (show) return await evalShow(config, show);
|
|
92
96
|
|
|
93
|
-
const environment = takeEnv(args, { fallback: "preview"
|
|
97
|
+
const environment = takeEnv(args, { fallback: "preview" });
|
|
94
98
|
const agent = takeValue(args, "--agent");
|
|
95
99
|
const noWait = takeFlag(args, "--no-wait");
|
|
96
100
|
const timeoutS = Number(takeValue(args, "--timeout") ?? DEFAULT_TIMEOUT_S);
|
|
@@ -104,12 +108,13 @@ export async function evalCommand(config, args) {
|
|
|
104
108
|
}
|
|
105
109
|
const runs = started.runs ?? [];
|
|
106
110
|
if (runs.length === 0) {
|
|
107
|
-
console.log("No
|
|
111
|
+
console.log("No reports to test yet. Report a reply in the inbox and write what it should have said.");
|
|
108
112
|
return;
|
|
109
113
|
}
|
|
110
114
|
|
|
111
115
|
const total = runs.reduce((sum, run) => sum + run.cases, 0);
|
|
112
116
|
console.error(`vatio: replaying ${total} case${total === 1 ? "" : "s"} on ${environment}…`);
|
|
117
|
+
printSkillsHint();
|
|
113
118
|
if (noWait) {
|
|
114
119
|
for (const run of runs) console.log(`Run ${run.id} (${run.agent}): vatio eval --show ${run.id}`);
|
|
115
120
|
return;
|
|
@@ -5,12 +5,11 @@
|
|
|
5
5
|
// That is why this is a command and not part of the manifest.
|
|
6
6
|
//
|
|
7
7
|
// The entries are live. Reads and writes here are as one environment sees
|
|
8
|
-
// them:
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
// So: write, try it on the branch's preview, publish.
|
|
8
|
+
// them: `preview` by default, which keeps the entries it changed on top of
|
|
9
|
+
// live and answers from them; `--env live` writes live directly, the way a
|
|
10
|
+
// supervisor in the inbox does. `vatio publish` takes the changes live with
|
|
11
|
+
// the agent -- `vatio kb publish` takes them alone. So: write, try it on
|
|
12
|
+
// preview, publish.
|
|
14
13
|
//
|
|
15
14
|
// A base holds entries, and an entry is markdown you wrote.
|
|
16
15
|
|
|
@@ -27,7 +26,7 @@ export async function kb(config, args) {
|
|
|
27
26
|
const workspace = config.resolveWorkspaceRequired();
|
|
28
27
|
const client = deployClient(config, workspace);
|
|
29
28
|
const sub = args.shift() ?? "list";
|
|
30
|
-
const env = ENVIRONMENT_SCOPED.has(sub) ? takeEnv(args, { fallback: null
|
|
29
|
+
const env = ENVIRONMENT_SCOPED.has(sub) ? takeEnv(args, { fallback: null }) : null;
|
|
31
30
|
const ctx = { client, workspace, env };
|
|
32
31
|
|
|
33
32
|
switch (sub) {
|
|
@@ -73,8 +72,8 @@ function usage() {
|
|
|
73
72
|
vatio kb publish BASE Take this environment's changes live, without the agent
|
|
74
73
|
vatio kb history BASE What reached live, newest first
|
|
75
74
|
|
|
76
|
-
Entry commands, status and publish take --env
|
|
77
|
-
|
|
75
|
+
Entry commands, status and publish take --env preview|live; the default is
|
|
76
|
+
preview. --env live writes live.`;
|
|
78
77
|
}
|
|
79
78
|
|
|
80
79
|
async function list({ client, workspace, env }) {
|
package/lib/commands/misc.mjs
CHANGED
|
@@ -137,9 +137,10 @@ const AGENTS_NOTE = [
|
|
|
137
137
|
"contract for the manifest, tools, knowledge and the CLI; read it before",
|
|
138
138
|
"changing anything here.",
|
|
139
139
|
"",
|
|
140
|
-
"To
|
|
141
|
-
"`vatio flags`
|
|
142
|
-
"
|
|
140
|
+
"To fix what supervisors reported in the inbox, take every open report in",
|
|
141
|
+
"one session: `vatio flags` (follow the instructions at the top of its",
|
|
142
|
+
"output), fix, `vatio push`, `vatio eval` until the reports pass, then",
|
|
143
|
+
"`vatio publish`. The `vatio-improve` skill walks through it.",
|
|
143
144
|
"`vatio tools --env live` shows how each tool's backend has been answering:",
|
|
144
145
|
"error rate, timeouts, latency and the calls that failed.",
|
|
145
146
|
""
|
|
@@ -26,7 +26,7 @@ export async function templates(config, args) {
|
|
|
26
26
|
args.shift();
|
|
27
27
|
return createTemplate(config, args, json);
|
|
28
28
|
}
|
|
29
|
-
const environment = takeEnv(args, { fallback: "live"
|
|
29
|
+
const environment = takeEnv(args, { fallback: "live" });
|
|
30
30
|
const workspace = config.resolveWorkspaceRequired();
|
|
31
31
|
const client = deployClient(config, workspace);
|
|
32
32
|
const sub = args.shift() ?? "list";
|
|
@@ -102,7 +102,7 @@ async function createTemplate(config, args, json) {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
export async function webhooks(config, args) {
|
|
105
|
-
const environment = takeEnv(args, { fallback: "live"
|
|
105
|
+
const environment = takeEnv(args, { fallback: "live" });
|
|
106
106
|
const label = takeValue(args, "--label");
|
|
107
107
|
const events = takeAll(args, "--event");
|
|
108
108
|
const workspace = config.resolveWorkspaceRequired();
|
|
@@ -4,16 +4,15 @@
|
|
|
4
4
|
// them is in vatio.yml.
|
|
5
5
|
|
|
6
6
|
import { deployClient } from "./deploy.mjs";
|
|
7
|
-
import {
|
|
8
|
-
import { askSecret, branchDefault, fail, paint, takeFlag, takeValue } from "../support.mjs";
|
|
7
|
+
import { askSecret, fail, paint, takeFlag, takeValue } from "../support.mjs";
|
|
9
8
|
|
|
10
|
-
//
|
|
9
|
+
// The platform says which names exist (preview and live); this only keeps
|
|
10
|
+
// something that cannot be a name out of a URL.
|
|
11
11
|
const ENVIRONMENT_NAME = /^[a-z0-9]+(?:[-_][a-z0-9]+)*$/;
|
|
12
12
|
const ENVIRONMENT_MAX = 40;
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return checkEnvironment(givenEnvironment(args) ?? branchDefault(cwd, fallback));
|
|
14
|
+
function environmentOption(args, fallback) {
|
|
15
|
+
return checkEnvironment(givenEnvironment(args) ?? fallback);
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
function givenEnvironment(args) {
|
|
@@ -23,20 +22,18 @@ function givenEnvironment(args) {
|
|
|
23
22
|
function checkEnvironment(value) {
|
|
24
23
|
if (value === null) return null;
|
|
25
24
|
if (String(value).length > ENVIRONMENT_MAX || !ENVIRONMENT_NAME.test(String(value))) {
|
|
26
|
-
fail(`Unknown environment "${value}" (use
|
|
25
|
+
fail(`Unknown environment "${value}" (use preview or live)`);
|
|
27
26
|
}
|
|
28
27
|
return String(value);
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
// Without an environment a secret is the value everywhere.
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
// every
|
|
35
|
-
// so it never takes the branch's environment.
|
|
30
|
+
// Without an environment a secret is the value everywhere. With --env, it is
|
|
31
|
+
// the value only that environment uses -- preview pointing its tools at
|
|
32
|
+
// staging while live keeps production. With --tests, the value preview and
|
|
33
|
+
// every eval replay use.
|
|
36
34
|
//
|
|
37
35
|
// `list` shows every row, every environment's included, unless --env asks for
|
|
38
|
-
// one
|
|
39
|
-
// Every line names the row's scope, and `set` and `rm` say which one they
|
|
36
|
+
// one. Every line names the row's scope, and `set` and `rm` say which one they
|
|
40
37
|
// touched.
|
|
41
38
|
export async function secrets(config, args) {
|
|
42
39
|
const workspace = config.resolveWorkspaceRequired();
|
|
@@ -46,9 +43,9 @@ export async function secrets(config, args) {
|
|
|
46
43
|
if (tests && given) fail("--tests is the value for every environment but live; drop --env");
|
|
47
44
|
const sub = args.shift() ?? "list";
|
|
48
45
|
|
|
49
|
-
if (sub === "list") return listSecrets(client, workspace, checkEnvironment(given)
|
|
46
|
+
if (sub === "list") return listSecrets(client, workspace, checkEnvironment(given));
|
|
50
47
|
|
|
51
|
-
const environment = tests ? null : checkEnvironment(given
|
|
48
|
+
const environment = tests ? null : checkEnvironment(given);
|
|
52
49
|
const scope = secretScope({ environment, tests });
|
|
53
50
|
|
|
54
51
|
if (sub === "set") {
|
|
@@ -73,7 +70,7 @@ export async function secrets(config, args) {
|
|
|
73
70
|
fail("Usage: vatio secrets list|set KEY [VALUE]|rm KEY [--env NAME | --tests]");
|
|
74
71
|
}
|
|
75
72
|
|
|
76
|
-
async function listSecrets(client, workspace, environment
|
|
73
|
+
async function listSecrets(client, workspace, environment) {
|
|
77
74
|
const payload = await client.listSecrets({ environment });
|
|
78
75
|
const keys = asArray(payload.secrets);
|
|
79
76
|
const title = environment ? `secrets ${environment} reads on workspace ${workspace}` : `secrets on workspace ${workspace}`;
|
|
@@ -90,10 +87,6 @@ async function listSecrets(client, workspace, environment, cwd) {
|
|
|
90
87
|
for (const secret of keys) {
|
|
91
88
|
console.log(` ${String(secret.key ?? secret).padEnd(width)} ${secretScope(secret)}`);
|
|
92
89
|
}
|
|
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
90
|
}
|
|
98
91
|
|
|
99
92
|
function secretScope({ environment, tests }) {
|
|
@@ -111,7 +104,7 @@ function takeOrigins(args) {
|
|
|
111
104
|
}
|
|
112
105
|
|
|
113
106
|
export async function tokens(config, args) {
|
|
114
|
-
const environment = environmentOption(args, "live"
|
|
107
|
+
const environment = environmentOption(args, "live");
|
|
115
108
|
const label = takeValue(args, "--label") ?? takeValue(args, "-l");
|
|
116
109
|
const origins = takeOrigins(args);
|
|
117
110
|
const workspace = config.resolveWorkspaceRequired();
|
|
@@ -163,7 +156,7 @@ export async function tokens(config, args) {
|
|
|
163
156
|
}
|
|
164
157
|
|
|
165
158
|
fail(
|
|
166
|
-
"Usage: vatio tokens list|create [--env live|preview
|
|
159
|
+
"Usage: vatio tokens list|create [--env live|preview] [--label NAME] [--origin URL]...|" +
|
|
167
160
|
"origins PREFIX URL...|revoke PREFIX"
|
|
168
161
|
);
|
|
169
162
|
}
|
|
@@ -173,7 +166,7 @@ export async function tokens(config, args) {
|
|
|
173
166
|
// token it is a secret, and unlike the CLI's own token it belongs to the
|
|
174
167
|
// workspace, so it outlives whoever created it.
|
|
175
168
|
export async function keys(config, args) {
|
|
176
|
-
const environment = environmentOption(args, "live"
|
|
169
|
+
const environment = environmentOption(args, "live");
|
|
177
170
|
const label = takeValue(args, "--label") ?? takeValue(args, "-l");
|
|
178
171
|
const workspace = config.resolveWorkspaceRequired();
|
|
179
172
|
const client = deployClient(config, workspace);
|
|
@@ -221,7 +214,7 @@ export async function keys(config, args) {
|
|
|
221
214
|
return;
|
|
222
215
|
}
|
|
223
216
|
|
|
224
|
-
fail("Usage: vatio keys list|create [--env live|preview
|
|
217
|
+
fail("Usage: vatio keys list|create [--env live|preview] [--label NAME]|revoke PREFIX");
|
|
225
218
|
}
|
|
226
219
|
|
|
227
220
|
// An empty list is not "anywhere": only Vatio's own pages can use the token.
|
package/lib/help.mjs
CHANGED
|
@@ -4,7 +4,7 @@ export function helpText() {
|
|
|
4
4
|
return `Vatio CLI ${VERSION}
|
|
5
5
|
|
|
6
6
|
npx @vatio-ai/cli init my-agent Start a workspace here
|
|
7
|
-
npx @vatio-ai/cli push Deploy it to
|
|
7
|
+
npx @vatio-ai/cli push Deploy it to preview
|
|
8
8
|
|
|
9
9
|
(installed globally with \`npm i -g @vatio-ai/cli\`, the command is just \`vatio\`)
|
|
10
10
|
|
|
@@ -12,10 +12,9 @@ A workspace is any directory with a vatio.yml. Every command except init reads
|
|
|
12
12
|
\`workspace:\` from the vatio.yml at or above the cwd — there is no --workspace
|
|
13
13
|
flag, the directory decides.
|
|
14
14
|
|
|
15
|
-
--env NAME targets an environment
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
and the one its pull request deploys to. Elsewhere commands default as listed.
|
|
15
|
+
--env NAME targets an environment, and there are two: preview (the next
|
|
16
|
+
version, what \`vatio push\` updates) and live (what visitors talk to).
|
|
17
|
+
Commands default as listed.
|
|
19
18
|
|
|
20
19
|
Getting started:
|
|
21
20
|
init [SLUG] [--name NAME] Create vatio.yml here, and the remote to match
|
|
@@ -35,17 +34,19 @@ and the one its pull request deploys to. Elsewhere commands default as listed.
|
|
|
35
34
|
share-session --never Stop coding agents from offering
|
|
36
35
|
|
|
37
36
|
Deploy:
|
|
38
|
-
push [--
|
|
39
|
-
(the first
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
push [--force] Validate the workspace, then update preview; runs
|
|
38
|
+
no tests (the first push signs in like \`login\`).
|
|
39
|
+
--force replaces an unpublished push from
|
|
40
|
+
another git branch
|
|
41
|
+
publish [--force] Take preview live, with its knowledge changes.
|
|
42
|
+
Once published, refused until \`vatio eval\` has
|
|
43
|
+
tested preview's version, and while it fails a
|
|
44
|
+
report live passes; --force publishes anyway
|
|
44
45
|
rollback Put live back to the previous snapshot: config and knowledge
|
|
45
46
|
status Preview and live deployment state
|
|
46
|
-
env [
|
|
47
|
-
knowledge changes and conflicts
|
|
48
|
-
env list
|
|
47
|
+
env [preview|live] An environment: token, widget snippet, link,
|
|
48
|
+
knowledge changes and conflicts (default: preview)
|
|
49
|
+
env list Both environments and what each runs
|
|
49
50
|
diff [--env NAME] What this directory would change (default: preview)
|
|
50
51
|
--env live answers "what would publishing change?"
|
|
51
52
|
diff --stat|--name-only|--format json|--full
|
|
@@ -58,26 +59,22 @@ and the one its pull request deploys to. Elsewhere commands default as listed.
|
|
|
58
59
|
The chat you are in, or any chat in the workspace
|
|
59
60
|
(web, WhatsApp, ...): messages, tool calls, channel
|
|
60
61
|
|
|
61
|
-
Improve it from what supervisors
|
|
62
|
+
Improve it from what supervisors reported and how its tools answered
|
|
63
|
+
(flags, fix, push, eval, publish):
|
|
62
64
|
flags [--save [PATH]|--json]
|
|
63
|
-
Every open
|
|
65
|
+
Every open report: the conversation, what each tool
|
|
64
66
|
answered, and what should have happened
|
|
65
67
|
tools [--env NAME] [--period 1h|1d|7d|30d] [--json]
|
|
66
68
|
The console's Tools page: each tool's calls, error
|
|
67
69
|
rate, timeouts and p50/p95, then the calls that
|
|
68
70
|
failed with what your backend answered. Default:
|
|
69
|
-
|
|
70
|
-
eval [--env NAME] [--agent SLUG] [--no-wait]
|
|
71
|
-
|
|
72
|
-
judge it; exits 1 if one fails.
|
|
73
|
-
|
|
71
|
+
live, 7d
|
|
72
|
+
eval [--env NAME] [--agent SLUG] [--no-wait] [--timeout N]
|
|
73
|
+
Test every report with a note against preview
|
|
74
|
+
(default) and judge it; exits 1 if one fails.
|
|
75
|
+
Can take minutes: in Claude Code, run it in the
|
|
76
|
+
background
|
|
74
77
|
eval --show RUN_ID One run's report
|
|
75
|
-
propose [--env NAME] --title TEXT [--summary TEXT|--summary-file PATH]
|
|
76
|
-
Without a GitHub repo: put the branch's
|
|
77
|
-
environment in front of the owner, who accepts
|
|
78
|
-
(publishes) or discards it in the inbox. Replays
|
|
79
|
-
every eval case there first
|
|
80
|
-
propose --list Every proposal and where it stands
|
|
81
78
|
|
|
82
79
|
Knowledge:
|
|
83
80
|
kb [list] Bases, and whether a deployed agent reads each
|
|
@@ -105,10 +102,9 @@ and the one its pull request deploys to. Elsewhere commands default as listed.
|
|
|
105
102
|
Credentials:
|
|
106
103
|
secrets list|set KEY [VALUE]|rm KEY [--env NAME | --tests]
|
|
107
104
|
Without VALUE, set asks for it with the input hidden.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
and every eval uses, like a staging URL
|
|
105
|
+
With --env, the value only that environment uses;
|
|
106
|
+
otherwise the value everywhere. With --tests, the
|
|
107
|
+
value preview and every eval use, like a staging URL
|
|
112
108
|
tokens list|create [--env NAME] [--label NAME] [--origin URL]...|revoke PREFIX
|
|
113
109
|
tokens origins PREFIX URL...
|
|
114
110
|
The origins a token is accepted from (replaces the list)
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// "The Vatio skills are not installed here", after the commands of the
|
|
2
|
+
// improve loop. Without them Claude Code has no /vatio:vatio-improve, and the
|
|
3
|
+
// developer pastes the daily mail's prompt into a session that cannot run it.
|
|
4
|
+
//
|
|
5
|
+
// Installed means either copy: the Claude Code plugin (installed_plugins.json
|
|
6
|
+
// names vatio@<marketplace>), or the files `npx @vatio-ai/skills` puts in a
|
|
7
|
+
// project's .claude/skills or .agents/skills -- in this directory or one above
|
|
8
|
+
// it, or in ~/.claude/skills.
|
|
9
|
+
//
|
|
10
|
+
// Unlike the update notice it prints when stderr is not a terminal too: the
|
|
11
|
+
// reader is as often the coding agent running the command as a person. At
|
|
12
|
+
// most once a day per directory, and never in CI.
|
|
13
|
+
|
|
14
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
15
|
+
import { homedir } from "node:os";
|
|
16
|
+
import { dirname, join, resolve } from "node:path";
|
|
17
|
+
|
|
18
|
+
import { configHome } from "./config.mjs";
|
|
19
|
+
import { paint } from "./support.mjs";
|
|
20
|
+
|
|
21
|
+
const SKILL = "vatio-improve";
|
|
22
|
+
const SHOW_EVERY_MS = 24 * 60 * 60 * 1000;
|
|
23
|
+
|
|
24
|
+
export function printSkillsHint(startDir = process.cwd()) {
|
|
25
|
+
if (process.env.CI || process.env.VATIO_NO_SKILLS_HINT) return;
|
|
26
|
+
if (skillsInstalled(startDir)) return;
|
|
27
|
+
|
|
28
|
+
const path = join(configHome(), "skills-hint.json");
|
|
29
|
+
const key = resolve(startDir);
|
|
30
|
+
const state = readState(path);
|
|
31
|
+
const last = Date.parse(state[key] ?? "");
|
|
32
|
+
if (!Number.isNaN(last) && Date.now() - last < SHOW_EVERY_MS) return;
|
|
33
|
+
|
|
34
|
+
process.stderr.write(
|
|
35
|
+
`\n${paint("yellow", "The Vatio skills are not installed here, so Claude Code has no /vatio:vatio-improve.")}\n` +
|
|
36
|
+
"To install them, run in this project: npx @vatio-ai/skills\n"
|
|
37
|
+
);
|
|
38
|
+
writeState(path, { ...state, [key]: new Date().toISOString() });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function skillsInstalled(startDir) {
|
|
42
|
+
const claudeHome = String(process.env.CLAUDE_CONFIG_DIR ?? "").trim() || join(homedir(), ".claude");
|
|
43
|
+
if (pluginInstalled(join(claudeHome, "plugins", "installed_plugins.json"))) return true;
|
|
44
|
+
if (hasSkill(claudeHome)) return true;
|
|
45
|
+
|
|
46
|
+
let dir = resolve(startDir);
|
|
47
|
+
for (;;) {
|
|
48
|
+
if (hasSkill(join(dir, ".claude")) || hasSkill(join(dir, ".agents"))) return true;
|
|
49
|
+
const parent = dirname(dir);
|
|
50
|
+
if (parent === dir) return false;
|
|
51
|
+
dir = parent;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function hasSkill(base) {
|
|
56
|
+
return existsSync(join(base, "skills", SKILL, "SKILL.md"));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function pluginInstalled(path) {
|
|
60
|
+
try {
|
|
61
|
+
const plugins = JSON.parse(readFileSync(path, "utf8"))?.plugins ?? {};
|
|
62
|
+
return Object.keys(plugins).some((name) => name.startsWith("vatio@"));
|
|
63
|
+
} catch {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function readState(path) {
|
|
69
|
+
try {
|
|
70
|
+
const state = JSON.parse(readFileSync(path, "utf8"));
|
|
71
|
+
return state && typeof state === "object" ? state : {};
|
|
72
|
+
} catch {
|
|
73
|
+
return {};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function writeState(path, state) {
|
|
78
|
+
try {
|
|
79
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
80
|
+
writeFileSync(path, JSON.stringify(state, null, 2) + "\n");
|
|
81
|
+
} catch {
|
|
82
|
+
// A hint that cannot remember it was shown shows again tomorrow.
|
|
83
|
+
}
|
|
84
|
+
}
|
package/lib/support.mjs
CHANGED
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
import { execFileSync } from "node:child_process";
|
|
5
5
|
|
|
6
|
-
import { branchEnvironment } from "./branch.mjs";
|
|
7
|
-
|
|
8
6
|
export class UserError extends Error {
|
|
9
7
|
constructor(message) {
|
|
10
8
|
super(message);
|
|
@@ -19,15 +17,13 @@ export function fail(message) {
|
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
// `--env NAME` is the one way to say which environment a command is about:
|
|
22
|
-
//
|
|
20
|
+
// preview or live. The platform validates the name.
|
|
23
21
|
//
|
|
24
|
-
// Without it,
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
// in
|
|
28
|
-
|
|
29
|
-
// -- it is sitting in CI jobs, and there is nothing wrong with what it does.
|
|
30
|
-
export function takeEnv(args, { fallback = null, cwd = null } = {}) {
|
|
22
|
+
// Without it, the default is the command's own and is passed in, because the
|
|
23
|
+
// sensible answer differs: push writes preview, tokens are for live. `--as`
|
|
24
|
+
// was the spelling on push and publish and stays as an alias -- it is sitting
|
|
25
|
+
// in CI jobs, and there is nothing wrong with what it does.
|
|
26
|
+
export function takeEnv(args, { fallback = null } = {}) {
|
|
31
27
|
let environment;
|
|
32
28
|
const rest = [];
|
|
33
29
|
|
|
@@ -43,22 +39,13 @@ export function takeEnv(args, { fallback = null, cwd = null } = {}) {
|
|
|
43
39
|
continue;
|
|
44
40
|
}
|
|
45
41
|
i += 1;
|
|
46
|
-
if (i >= args.length) fail(`${match[0]} needs an environment name (
|
|
42
|
+
if (i >= args.length) fail(`${match[0]} needs an environment name (preview or live)`);
|
|
47
43
|
environment = args[i];
|
|
48
44
|
}
|
|
49
45
|
|
|
50
46
|
args.length = 0;
|
|
51
47
|
args.push(...rest);
|
|
52
|
-
return environment !== undefined ? environment :
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// The branch's environment when the workspace is on one, else `fallback`.
|
|
56
|
-
export function branchDefault(cwd, fallback) {
|
|
57
|
-
const fromBranch = cwd ? branchEnvironment(cwd) : null;
|
|
58
|
-
if (!fromBranch) return fallback;
|
|
59
|
-
|
|
60
|
-
process.stderr.write(paint("cyan", `vatio: environment ${fromBranch.environment} (branch ${fromBranch.branch})`) + "\n");
|
|
61
|
-
return fromBranch.environment;
|
|
48
|
+
return environment !== undefined ? environment : fallback;
|
|
62
49
|
}
|
|
63
50
|
|
|
64
51
|
export function takeFlag(args, name) {
|
|
@@ -89,12 +76,19 @@ export function takeValue(args, name) {
|
|
|
89
76
|
// Stamped on a deployment so a revision can be traced back to a commit. Absent
|
|
90
77
|
// outside a repository, which is fine -- a workspace does not have to be in one.
|
|
91
78
|
export function detectGitSha(cwd) {
|
|
79
|
+
return git(cwd, ["rev-parse", "HEAD"]);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Sent with a push so the platform can refuse one that would replace an
|
|
83
|
+
// unpublished push from another branch. Null outside a repository or with
|
|
84
|
+
// HEAD detached.
|
|
85
|
+
export function detectGitBranch(cwd) {
|
|
86
|
+
return git(cwd, ["symbolic-ref", "--short", "-q", "HEAD"]);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function git(cwd, args) {
|
|
92
90
|
try {
|
|
93
|
-
return execFileSync("git", ["
|
|
94
|
-
cwd,
|
|
95
|
-
encoding: "utf8",
|
|
96
|
-
stdio: ["ignore", "pipe", "ignore"]
|
|
97
|
-
}).trim() || null;
|
|
91
|
+
return execFileSync("git", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim() || null;
|
|
98
92
|
} catch {
|
|
99
93
|
return null;
|
|
100
94
|
}
|
package/package.json
CHANGED
package/lib/branch.mjs
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
// The environment a git branch gets, so that working on a branch is working in
|
|
2
|
-
// its own environment without saying so: `vatio push` from `fix/pagos` lands on
|
|
3
|
-
// `fix-pagos`, and so do `vatio kb write`, `vatio secrets set` and `vatio chat`.
|
|
4
|
-
// The pull request opened from that branch deploys to the same one.
|
|
5
|
-
//
|
|
6
|
-
// The default branch is not a branch environment: there, and outside a
|
|
7
|
-
// repository, every command keeps the default it always had.
|
|
8
|
-
//
|
|
9
|
-
// The name is derived exactly as the platform derives it for a pull request
|
|
10
|
-
// (Vatio::Environment.for_branch, backend/app/vatio/environment.rb). Kept in
|
|
11
|
-
// step by hand; both are short.
|
|
12
|
-
|
|
13
|
-
import { execFileSync } from "node:child_process";
|
|
14
|
-
import { createHash } from "node:crypto";
|
|
15
|
-
|
|
16
|
-
const RESERVED = new Set(["live", "preview", "staging", "sandbox", "main"]);
|
|
17
|
-
const MAX_LENGTH = 40;
|
|
18
|
-
|
|
19
|
-
export function environmentForBranch(ref) {
|
|
20
|
-
const raw = String(ref ?? "").replace(/^refs\/heads\//, "");
|
|
21
|
-
let slug = raw.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
22
|
-
if (slug === "") return null;
|
|
23
|
-
|
|
24
|
-
if (RESERVED.has(slug)) slug = `branch-${slug}`;
|
|
25
|
-
if (slug.length <= MAX_LENGTH) return slug;
|
|
26
|
-
|
|
27
|
-
const hash = createHash("sha1").update(String(ref)).digest("hex").slice(0, 6);
|
|
28
|
-
return `${slug.slice(0, 33).replace(/-+$/, "")}-${hash}`;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// { branch, environment } on a branch other than the default one; null on the
|
|
32
|
-
// default branch, outside a repository, or with HEAD detached.
|
|
33
|
-
export function branchEnvironment(cwd) {
|
|
34
|
-
const branch = git(cwd, ["symbolic-ref", "--short", "-q", "HEAD"]);
|
|
35
|
-
if (!branch) return null;
|
|
36
|
-
|
|
37
|
-
const remoteHead = git(cwd, ["symbolic-ref", "--short", "-q", "refs/remotes/origin/HEAD"]);
|
|
38
|
-
const defaultBranch = remoteHead ? remoteHead.replace(/^[^/]+\//, "") : null;
|
|
39
|
-
if (branch === defaultBranch || (!defaultBranch && (branch === "main" || branch === "master"))) return null;
|
|
40
|
-
|
|
41
|
-
const environment = environmentForBranch(branch);
|
|
42
|
-
return environment ? { branch, environment } : null;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function git(cwd, args) {
|
|
46
|
-
try {
|
|
47
|
-
return execFileSync("git", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim() || null;
|
|
48
|
-
} catch {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
}
|
package/lib/commands/propose.mjs
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import { deployClient } from "./deploy.mjs";
|
|
3
|
-
import { fail, takeEnv, takeFlag, takeValue } from "../support.mjs";
|
|
4
|
-
|
|
5
|
-
// `vatio propose`: put a branch's environment in front of the workspace's
|
|
6
|
-
// owner as a change to accept from the inbox, for a workspace with no
|
|
7
|
-
// repository connected -- there, the pull request is the proposal. Vatio
|
|
8
|
-
// replays every eval case on it and mails the owner once they finish; the
|
|
9
|
-
// owner accepts (which publishes it) or discards it. Proposing the same
|
|
10
|
-
// environment again, after another push, updates it and replays the evals.
|
|
11
|
-
export async function propose(config, args) {
|
|
12
|
-
const workspace = config.resolveWorkspaceRequired();
|
|
13
|
-
const client = deployClient(config, workspace);
|
|
14
|
-
if (takeFlag(args, "--list")) return await list(client, workspace);
|
|
15
|
-
|
|
16
|
-
const title = takeValue(args, "--title");
|
|
17
|
-
const summaryFile = takeValue(args, "--summary-file");
|
|
18
|
-
let summary = takeValue(args, "--summary");
|
|
19
|
-
if (summaryFile) {
|
|
20
|
-
try {
|
|
21
|
-
summary = readFileSync(summaryFile, "utf8");
|
|
22
|
-
} catch (error) {
|
|
23
|
-
fail(`Could not read ${summaryFile}: ${error.message}`);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
const environment = takeEnv(args, { fallback: null, cwd: config.workspaceRoot });
|
|
27
|
-
if (!environment) {
|
|
28
|
-
fail('usage: vatio propose --env NAME --title "What it fixes" [--summary TEXT | --summary-file PATH]');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const payload = await client.propose({ environment, title, summary });
|
|
32
|
-
console.log(`${payload.created ? "Proposed" : "Updated"} ${payload.environment} as ${payload.id}: ${payload.title}`);
|
|
33
|
-
const runs = Array.isArray(payload.runs) ? payload.runs : [];
|
|
34
|
-
const cases = runs.reduce((sum, run) => sum + (run.cases ?? 0), 0);
|
|
35
|
-
if (cases > 0) {
|
|
36
|
-
console.log(`Replaying ${cases} eval case${cases === 1 ? "" : "s"} there; the owner gets a mail when they finish.`);
|
|
37
|
-
} else {
|
|
38
|
-
console.log("No eval cases to replay: the owner decides on the change alone.");
|
|
39
|
-
}
|
|
40
|
-
console.log(`Accept or discard it in the inbox: ${payload.url}`);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async function list(client, workspace) {
|
|
44
|
-
const payload = await client.proposals();
|
|
45
|
-
const rows = Array.isArray(payload.data) ? payload.data : [];
|
|
46
|
-
console.log(`Proposals on workspace ${workspace} (${rows.length}):`);
|
|
47
|
-
for (const row of rows) {
|
|
48
|
-
console.log(` ${row.id} ${row.status.padEnd(9)} ${row.environment} ${row.title}`);
|
|
49
|
-
console.log(` ${row.url}`);
|
|
50
|
-
}
|
|
51
|
-
}
|