@vatio-ai/cli 0.82.1 → 0.84.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 +3 -1
- package/bin/vatio.mjs +45 -5
- package/lib/api-client.mjs +3 -3
- package/lib/commands/business.mjs +8 -71
- package/lib/commands/chat.mjs +12 -6
- package/lib/commands/deploy.mjs +76 -20
- package/lib/commands/misc.mjs +17 -2
- package/lib/config.mjs +42 -3
- package/lib/help.mjs +4 -5
- package/lib/http.mjs +15 -0
- package/lib/telemetry.mjs +1 -1
- package/lib/trial.mjs +134 -0
- package/lib/workspace.mjs +17 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,7 +27,9 @@ npx @vatio-ai/cli init my-agent
|
|
|
27
27
|
npx @vatio-ai/cli push
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
No runtime to install first: if you have Node 20 or newer, you have this.
|
|
30
|
+
No runtime to install first: if you have Node 20 or newer, you have this. No
|
|
31
|
+
account either: with none on the machine, `push` deploys a 7-day trial and
|
|
32
|
+
prints a link to try it and one to keep it, which is where you sign in.
|
|
31
33
|
|
|
32
34
|
The package is `@vatio-ai/cli`; the command it installs is `vatio`. So
|
|
33
35
|
`npm install -g @vatio-ai/cli` gives you `vatio push`, and `npx @vatio-ai/cli push`
|
package/bin/vatio.mjs
CHANGED
|
@@ -5,7 +5,16 @@
|
|
|
5
5
|
// terminal; the credential lives in ~/.vatio/config.json.
|
|
6
6
|
|
|
7
7
|
import { Config, ConfigError } from "../lib/config.mjs";
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
CliOutdatedError,
|
|
10
|
+
HttpError,
|
|
11
|
+
UnauthorizedError,
|
|
12
|
+
ForbiddenError,
|
|
13
|
+
NotFoundError,
|
|
14
|
+
TrialClaimedError,
|
|
15
|
+
TrialGoneError
|
|
16
|
+
} from "../lib/http.mjs";
|
|
17
|
+
import { keepClaimedTrial } from "../lib/trial.mjs";
|
|
9
18
|
import { UserError, fail } from "../lib/support.mjs";
|
|
10
19
|
import { helpText } from "../lib/help.mjs";
|
|
11
20
|
import { login, logout } from "../lib/commands/auth.mjs";
|
|
@@ -49,11 +58,25 @@ async function main(argv) {
|
|
|
49
58
|
const command = args.shift();
|
|
50
59
|
beginRun(command, args);
|
|
51
60
|
const updateCheck = startUpdateCheck(command);
|
|
52
|
-
await
|
|
61
|
+
await runKeepingTrial(command, args);
|
|
53
62
|
await reportRun(config, { exitCode: process.exitCode ?? 0 });
|
|
54
63
|
await printUpdateNotice(updateCheck);
|
|
55
64
|
}
|
|
56
65
|
|
|
66
|
+
// The trial this directory pushed to was kept in the browser since the last
|
|
67
|
+
// command (lib/trial.mjs): the refused call did nothing, so this terminal signs
|
|
68
|
+
// in to the account that kept it and the command runs again, as that account.
|
|
69
|
+
async function runKeepingTrial(command, args) {
|
|
70
|
+
const again = [...args];
|
|
71
|
+
try {
|
|
72
|
+
await run(command, args);
|
|
73
|
+
} catch (error) {
|
|
74
|
+
if (!(error instanceof TrialClaimedError) || !error.workspace) throw error;
|
|
75
|
+
await keepClaimedTrial(config, error);
|
|
76
|
+
await run(command, again);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
57
80
|
async function run(command, args) {
|
|
58
81
|
// `--help` after a command asks about it. Left to the command, it reads as a
|
|
59
82
|
// message to send, an argument, or nothing at all: `vatio chat --help` said
|
|
@@ -155,10 +178,23 @@ function printError(error) {
|
|
|
155
178
|
console.error(error.message);
|
|
156
179
|
return suggestFeedback();
|
|
157
180
|
}
|
|
181
|
+
if (error instanceof TrialGoneError) {
|
|
182
|
+
config.clearTrial();
|
|
183
|
+
// The platform's hint says what to run next.
|
|
184
|
+
console.error("This trial no longer exists: nobody kept it in time, so it was deleted.");
|
|
185
|
+
return printTrailer(error);
|
|
186
|
+
}
|
|
158
187
|
if (error instanceof UnauthorizedError) {
|
|
159
188
|
console.error("Authentication failed (401). Run `vatio login`.");
|
|
160
189
|
return printTrailer(error);
|
|
161
190
|
}
|
|
191
|
+
if (error instanceof ForbiddenError && errorCode(error) === "trial_unclaimed") {
|
|
192
|
+
// The platform says what needs an account; the link to keep it is only here.
|
|
193
|
+
const trial = config.trial();
|
|
194
|
+
const link = trial?.claim_url ?? 'the link `vatio push` printed after "Keep it"';
|
|
195
|
+
console.error(`${error.message} Keep it first: ${link}, then run vatio ${process.argv[2]} again (it signs this terminal in).`);
|
|
196
|
+
return printTrailer(error, { hint: false });
|
|
197
|
+
}
|
|
162
198
|
if (error instanceof ForbiddenError) {
|
|
163
199
|
console.error("Access denied (403). Your token cannot access this workspace.");
|
|
164
200
|
return printTrailer(error);
|
|
@@ -181,16 +217,20 @@ function printError(error) {
|
|
|
181
217
|
|
|
182
218
|
// What the platform said to do next, and the ids that find this request in
|
|
183
219
|
// its logs.
|
|
184
|
-
function printTrailer(error) {
|
|
220
|
+
function printTrailer(error, { hint: withHint = true } = {}) {
|
|
185
221
|
const hint = error.body?.hint;
|
|
186
|
-
if (hint && !(error instanceof UnauthorizedError)) console.error(`Next: ${hint}`);
|
|
222
|
+
if (withHint && hint && !(error instanceof UnauthorizedError)) console.error(`Next: ${hint}`);
|
|
187
223
|
|
|
188
|
-
const code =
|
|
224
|
+
const code = errorCode(error);
|
|
189
225
|
const ids = [code && `error=${code}`, error.requestId && `request_id=${error.requestId}`].filter(Boolean);
|
|
190
226
|
if (ids.length > 0) console.error(ids.join(" "));
|
|
191
227
|
suggestFeedback();
|
|
192
228
|
}
|
|
193
229
|
|
|
230
|
+
function errorCode(error) {
|
|
231
|
+
return error.body?.error_key ?? (typeof error.body?.error === "string" ? error.body.error : error.body?.error?.code);
|
|
232
|
+
}
|
|
233
|
+
|
|
194
234
|
// Said to coding agents only: a person at a terminal has better ways to
|
|
195
235
|
// complain, and does not need the line on every typo.
|
|
196
236
|
function suggestFeedback() {
|
package/lib/api-client.mjs
CHANGED
|
@@ -176,13 +176,13 @@ export class ApiClient extends HttpClient {
|
|
|
176
176
|
|
|
177
177
|
// --- business -------------------------------------------------------
|
|
178
178
|
|
|
179
|
-
// Name, description and
|
|
180
|
-
//
|
|
179
|
+
// Name, description and brand: one row for every environment, the same
|
|
180
|
+
// one the inbox's Business page edits.
|
|
181
181
|
business() {
|
|
182
182
|
return this.get("/business");
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
// Only the keys given change.
|
|
185
|
+
// Only the keys given change.
|
|
186
186
|
updateBusiness(fields) {
|
|
187
187
|
return this.patch("/business", fields);
|
|
188
188
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// business — the business the agent works for: name, description
|
|
2
|
-
//
|
|
1
|
+
// business — the business the agent works for: name, description and brand
|
|
2
|
+
// (logo, color, about). Not part of vatio.yml: it belongs to
|
|
3
3
|
// whoever runs the business and is usually edited on the inbox's Business
|
|
4
4
|
// page. This is the same row, for a developer setting a workspace up from a
|
|
5
5
|
// terminal. One value for every environment, live on save.
|
|
@@ -7,11 +7,8 @@
|
|
|
7
7
|
import { readFileSync, statSync } from "node:fs";
|
|
8
8
|
import { basename, extname } from "node:path";
|
|
9
9
|
import { deployClient } from "./deploy.mjs";
|
|
10
|
-
import { fail,
|
|
10
|
+
import { fail, takeFlag, takeValue } from "../support.mjs";
|
|
11
11
|
|
|
12
|
-
const DAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
|
|
13
|
-
const DAY_LABELS = { mon: "Mon", tue: "Tue", wed: "Wed", thu: "Thu", fri: "Fri", sat: "Sat", sun: "Sun" };
|
|
14
|
-
const RANGE = /^\d{2}:\d{2}-\d{2}:\d{2}$/;
|
|
15
12
|
const HEX = /^#[0-9a-fA-F]{6}$/;
|
|
16
13
|
// The platform checks the type and the size again; these only fail early.
|
|
17
14
|
const LOGO_TYPES = { ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".webp": "image/webp", ".gif": "image/gif" };
|
|
@@ -21,9 +18,7 @@ const USAGE =
|
|
|
21
18
|
"Usage: vatio business [show]\n" +
|
|
22
19
|
" vatio business set [--name NAME] [--description TEXT | --description-file FILE]\n" +
|
|
23
20
|
" [--about TEXT] [--color #RRGGBB | --color default]\n" +
|
|
24
|
-
" [--logo FILE | --remove-logo]
|
|
25
|
-
" vatio business hours [--timezone ZONE] [--mon 09:00-18:00] [--tue 09:00-13:00,14:00-18:00] ...\n" +
|
|
26
|
-
" vatio business hours --clear";
|
|
21
|
+
" [--logo FILE | --remove-logo]";
|
|
27
22
|
|
|
28
23
|
export async function business(config, args) {
|
|
29
24
|
const workspace = config.resolveWorkspaceRequired();
|
|
@@ -65,38 +60,10 @@ export async function business(config, args) {
|
|
|
65
60
|
return;
|
|
66
61
|
}
|
|
67
62
|
if (sub === "hours") {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const timezone = takeValue(args, "--timezone") ?? takeValue(args, "--tz");
|
|
75
|
-
const days = {};
|
|
76
|
-
for (const day of DAYS) {
|
|
77
|
-
const value = takeValue(args, `--${day}`);
|
|
78
|
-
if (value === null) continue;
|
|
79
|
-
const ranges = value.split(",").map((range) => range.trim()).filter(Boolean);
|
|
80
|
-
const bad = ranges.find((range) => !RANGE.test(range));
|
|
81
|
-
if (bad) fail(`--${day}: "${bad}" is not a range like 09:00-18:00`);
|
|
82
|
-
if (ranges.length > 0) days[day] = ranges;
|
|
83
|
-
}
|
|
84
|
-
rejectLeftovers(args);
|
|
85
|
-
|
|
86
|
-
// Nothing to change: show them.
|
|
87
|
-
if (timezone === null && Object.keys(days).length === 0) {
|
|
88
|
-
print(await client.business(), workspace);
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
if (Object.keys(days).length === 0) {
|
|
92
|
-
fail("Give at least one day (--mon 09:00-18:00 ...), or --clear for someone always available");
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// The week is replaced as a whole -- a day not given is a day nobody is
|
|
96
|
-
// on -- so the timezone is the only thing worth keeping from before.
|
|
97
|
-
const zone = timezone ?? (await client.business()).hours?.timezone ?? localTimezone();
|
|
98
|
-
print(await client.updateBusiness({ hours: { timezone: zone, days } }), workspace);
|
|
99
|
-
return;
|
|
63
|
+
fail(
|
|
64
|
+
"Business hours were removed. To have a person take a conversation over, give the agent a tool " +
|
|
65
|
+
"that alerts your team: https://vatio.ai/docs/handoff",
|
|
66
|
+
);
|
|
100
67
|
}
|
|
101
68
|
|
|
102
69
|
fail(USAGE);
|
|
@@ -120,12 +87,6 @@ function rejectLeftovers(args) {
|
|
|
120
87
|
if (args.length > 0) fail(`Unexpected: ${args.join(" ")}\n\n${USAGE}`);
|
|
121
88
|
}
|
|
122
89
|
|
|
123
|
-
function localTimezone() {
|
|
124
|
-
const zone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
125
|
-
if (zone && zone.includes("/")) return zone;
|
|
126
|
-
fail("Give --timezone, like --timezone America/Santiago");
|
|
127
|
-
}
|
|
128
|
-
|
|
129
90
|
function print(payload, workspace) {
|
|
130
91
|
console.log(`${payload.name} (workspace ${workspace})`);
|
|
131
92
|
console.log("");
|
|
@@ -136,30 +97,6 @@ function print(payload, workspace) {
|
|
|
136
97
|
console.log(` logo ${payload.logo_url ?? "none (vatio business set --logo FILE)"}`);
|
|
137
98
|
console.log(` color ${payload.accent_color ?? `${payload.default_accent_color} (Vatio's default)`}`);
|
|
138
99
|
console.log(` about ${payload.about ? payload.about.replace(/\s*\n\s*/g, " ") : "none"}`);
|
|
139
|
-
console.log("");
|
|
140
|
-
|
|
141
|
-
if (!payload.hours) {
|
|
142
|
-
console.log("Hours: none set — someone is always available");
|
|
143
|
-
} else {
|
|
144
|
-
const state = payload.open_now ? paint("green", "open now") : "closed now";
|
|
145
|
-
console.log(`Hours (${payload.hours.timezone}) — ${state}`);
|
|
146
|
-
for (const day of DAYS) {
|
|
147
|
-
const ranges = payload.hours.days?.[day] ?? [];
|
|
148
|
-
console.log(` ${DAY_LABELS[day]} ${ranges.length > 0 ? ranges.join(", ") : "closed"}`);
|
|
149
|
-
}
|
|
150
|
-
if (payload.next_opening) console.log(` Opens next ${payload.next_opening}`);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
console.log("");
|
|
154
|
-
if (!payload.handoff) {
|
|
155
|
-
console.log("Handoff: not declared in vatio.yml — the agent never hands a conversation over");
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
console.log("Hands over to a person when (from vatio.yml):");
|
|
159
|
-
const rules = [...(payload.handoff.when ?? [])];
|
|
160
|
-
if (payload.handoff.after_turns != null) rules.push(`always after ${payload.handoff.after_turns} visitor messages`);
|
|
161
|
-
if (rules.length === 0) rules.push("the agent judges it");
|
|
162
|
-
for (const rule of rules) console.log(` - ${rule}`);
|
|
163
100
|
}
|
|
164
101
|
|
|
165
102
|
function indent(text) {
|
package/lib/commands/chat.mjs
CHANGED
|
@@ -81,18 +81,24 @@ The open chat per deployment is remembered in ${STATE_FILE}, so a second
|
|
|
81
81
|
workspace has never met.`;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
// With no account on this machine, the trial this directory pushed to, with
|
|
85
|
+
// its key (lib/trial.mjs): a chat there is the trial's developer, like any.
|
|
84
86
|
function client(config, options) {
|
|
85
|
-
const apiUrl = config
|
|
86
|
-
const token = options.token ?? config.resolveToken();
|
|
87
|
+
const apiUrl = apiUrlFor(config, options);
|
|
88
|
+
const token = options.token ?? config.resolveToken() ?? config.activeTrial()?.key;
|
|
87
89
|
if (!apiUrl) {
|
|
88
90
|
// Says which: no vatio.yml here (and where one is), or one without `workspace:`.
|
|
89
91
|
config.resolveWorkspaceRequired();
|
|
90
92
|
fail("A workspace API url is required (--api-url, or base_url + a vatio.yml with `workspace:`)");
|
|
91
93
|
}
|
|
92
|
-
if (!token) fail("VATIO_TOKEN is required (env or `vatio login`)");
|
|
94
|
+
if (!token) fail("VATIO_TOKEN is required (env or `vatio login`). `vatio push` deploys a trial with no account.");
|
|
93
95
|
return new ApiClient({ baseUrl: apiUrl, token });
|
|
94
96
|
}
|
|
95
97
|
|
|
98
|
+
function apiUrlFor(config, options) {
|
|
99
|
+
return config.resolveApiUrl({ explicit: options.apiUrl, token: options.token });
|
|
100
|
+
}
|
|
101
|
+
|
|
96
102
|
function statePath(config) {
|
|
97
103
|
return join(config.workspaceRootRequired(), STATE_FILE);
|
|
98
104
|
}
|
|
@@ -124,7 +130,7 @@ function rememberChat(config, { apiUrl, environment, chatId }) {
|
|
|
124
130
|
}
|
|
125
131
|
|
|
126
132
|
async function ensureChat(config, options) {
|
|
127
|
-
const apiUrl = config
|
|
133
|
+
const apiUrl = apiUrlFor(config, options);
|
|
128
134
|
const existing = chatsFor(config, apiUrl)[options.environment];
|
|
129
135
|
if (existing) return Number(existing);
|
|
130
136
|
|
|
@@ -210,7 +216,7 @@ async function showChat(config, options, args) {
|
|
|
210
216
|
let chatId = args.shift();
|
|
211
217
|
if (chatId !== undefined && !/^\d+$/.test(chatId)) fail("Usage: vatio chat show [CHAT_ID] [--last N] [--json]");
|
|
212
218
|
if (chatId === undefined) {
|
|
213
|
-
const apiUrl = config
|
|
219
|
+
const apiUrl = apiUrlFor(config, options);
|
|
214
220
|
chatId = chatsFor(config, apiUrl)[options.environment];
|
|
215
221
|
if (!chatId) fail(`No ${options.environment} chat yet: run \`vatio chat "hello"\` first, or pass a CHAT_ID.`);
|
|
216
222
|
chatId = String(chatId);
|
|
@@ -325,7 +331,7 @@ function truncate(text, max) {
|
|
|
325
331
|
}
|
|
326
332
|
|
|
327
333
|
async function startOver(config, options) {
|
|
328
|
-
const apiUrl = config
|
|
334
|
+
const apiUrl = apiUrlFor(config, options);
|
|
329
335
|
const payload = await openChat(config, options, {
|
|
330
336
|
apiUrl,
|
|
331
337
|
chatId: chatsFor(config, apiUrl)[options.environment] ?? null
|
package/lib/commands/deploy.mjs
CHANGED
|
@@ -16,13 +16,14 @@ 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, UnprocessableError } from "../http.mjs";
|
|
19
|
+
import { NotFoundError, TrialGoneError, UnprocessableError } from "../http.mjs";
|
|
20
|
+
import { printTrialPush, startTrial } from "../trial.mjs";
|
|
20
21
|
import { deviceLogin } from "./auth.mjs";
|
|
21
22
|
import { detectGitBranch, detectGitSha, fail, paint, takeEnv, takeFlag, takeValue } from "../support.mjs";
|
|
22
23
|
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
export async function ensureAuthorized(config, { workspace = null, message = "Before I can
|
|
24
|
+
// For a command that needs to know whose it is. `push` does not: with no
|
|
25
|
+
// account it deploys a trial, and the account comes when someone keeps it.
|
|
26
|
+
export async function ensureAuthorized(config, { workspace = null, message = "Before I can do this, I need to know who you are." } = {}) {
|
|
26
27
|
if (config.resolveToken()) return;
|
|
27
28
|
|
|
28
29
|
const auth = await deviceLogin({ config, workspace, message });
|
|
@@ -31,13 +32,18 @@ export async function ensureAuthorized(config, { workspace = null, message = "Be
|
|
|
31
32
|
console.log("");
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
// With no account on this machine, the trial `vatio push` made from this
|
|
36
|
+
// directory (lib/trial.mjs), on its own slug and key: the platform answers
|
|
37
|
+
// what a trial may do and refuses the rest with `trial_unclaimed`.
|
|
34
38
|
export function deployClient(config, workspace) {
|
|
35
39
|
const base = config.resolveBaseUrl();
|
|
36
40
|
if (!base) fail("VATIO_BASE_URL is required (env or `vatio config set base_url …`)");
|
|
37
41
|
const token = config.resolveToken();
|
|
38
|
-
if (
|
|
42
|
+
if (token) return new ApiClient({ baseUrl: `${base}/api/developer/v1/${workspace}`, token });
|
|
39
43
|
|
|
40
|
-
|
|
44
|
+
const trial = config.trial();
|
|
45
|
+
if (trial) return new ApiClient({ baseUrl: `${base}/api/developer/v1/${trial.workspace}`, token: trial.key });
|
|
46
|
+
fail("VATIO_TOKEN is required (env or `vatio login`). `vatio push` deploys a trial with no account.");
|
|
41
47
|
}
|
|
42
48
|
|
|
43
49
|
export function workspacesClient(config) {
|
|
@@ -91,7 +97,9 @@ export async function push(config, args) {
|
|
|
91
97
|
const force = takeFlag(args, "--force");
|
|
92
98
|
const workspace = config.resolveWorkspaceRequired();
|
|
93
99
|
|
|
94
|
-
|
|
100
|
+
// No account here: a trial, which asks for one only when someone keeps it.
|
|
101
|
+
if (!config.resolveToken()) return await pushTrial(config, { workspace, environment, force });
|
|
102
|
+
noticeLeftoverTrial(config);
|
|
95
103
|
|
|
96
104
|
// The remote has to exist before the workspace can be checked: the slug is in
|
|
97
105
|
// the URL of the call that checks it. It is created unnamed; the display name
|
|
@@ -104,19 +112,7 @@ export async function push(config, args) {
|
|
|
104
112
|
console.log(`Created remote workspace ${workspace}`);
|
|
105
113
|
}
|
|
106
114
|
|
|
107
|
-
const
|
|
108
|
-
printDiagnostics(check);
|
|
109
|
-
if (!check.ok) fail(`push aborted: check failed (${asArray(check.errors).length} error(s))`);
|
|
110
|
-
|
|
111
|
-
const client = deployClient(config, workspace);
|
|
112
|
-
const payload = await client.pushPreview({
|
|
113
|
-
manifest: check.manifest,
|
|
114
|
-
gitSha: detectGitSha(config.workspaceRootRequired()),
|
|
115
|
-
gitBranch: detectGitBranch(config.workspaceRootRequired()),
|
|
116
|
-
createdBy: process.env.USER ?? null,
|
|
117
|
-
environment,
|
|
118
|
-
force
|
|
119
|
-
});
|
|
115
|
+
const payload = await checkAndPush(config, workspace, { environment, force });
|
|
120
116
|
|
|
121
117
|
const landedOn = payload.environment ?? "preview";
|
|
122
118
|
console.log(`Pushed deployment #${payload.deployment_id} to ${landedOn} (git_sha=${JSON.stringify(payload.git_sha ?? null)})`);
|
|
@@ -134,6 +130,66 @@ export async function push(config, args) {
|
|
|
134
130
|
printNotices(payload);
|
|
135
131
|
}
|
|
136
132
|
|
|
133
|
+
async function checkAndPush(config, workspace, { environment, force }) {
|
|
134
|
+
const check = await checkWorkspace(config, workspace, { environment });
|
|
135
|
+
printDiagnostics(check);
|
|
136
|
+
if (!check.ok) fail(`push aborted: check failed (${asArray(check.errors).length} error(s))`);
|
|
137
|
+
|
|
138
|
+
return await deployClient(config, workspace).pushPreview({
|
|
139
|
+
manifest: check.manifest,
|
|
140
|
+
gitSha: detectGitSha(config.workspaceRootRequired()),
|
|
141
|
+
gitBranch: detectGitBranch(config.workspaceRootRequired()),
|
|
142
|
+
createdBy: process.env.USER ?? null,
|
|
143
|
+
environment,
|
|
144
|
+
force
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// The first push makes the trial; the next ones reuse it, each one moving its
|
|
149
|
+
// deletion a week on. One deleted meanwhile is replaced by a new one, once.
|
|
150
|
+
async function pushTrial(config, { workspace, environment, force }) {
|
|
151
|
+
let trial = config.trial();
|
|
152
|
+
let started = false;
|
|
153
|
+
if (!trial) {
|
|
154
|
+
trial = await startTrial(config, workspace);
|
|
155
|
+
started = true;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
let payload;
|
|
159
|
+
try {
|
|
160
|
+
payload = await checkAndPush(config, workspace, { environment, force });
|
|
161
|
+
} catch (error) {
|
|
162
|
+
if (!(error instanceof TrialGoneError) || started) throw error;
|
|
163
|
+
config.clearTrial();
|
|
164
|
+
console.log(`The trial this directory had (${trial.workspace}) is gone: nobody kept it in time. Starting a new one.`);
|
|
165
|
+
trial = await startTrial(config, workspace);
|
|
166
|
+
started = true;
|
|
167
|
+
payload = await checkAndPush(config, workspace, { environment, force });
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
config.writeTrial({
|
|
171
|
+
...trial,
|
|
172
|
+
try_url: payload.trial?.try_url ?? payload.share_url ?? trial.try_url ?? null,
|
|
173
|
+
expires_at: payload.trial?.expires_at ?? trial.expires_at
|
|
174
|
+
});
|
|
175
|
+
printTrialPush(config.trial(), payload, { started });
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Signed in, in a directory that pushed to a trial before: the push goes to
|
|
179
|
+
// the account as usual, and the trial stays as it is until it is kept or
|
|
180
|
+
// deleted. Said on every push until it is due to be deleted.
|
|
181
|
+
function noticeLeftoverTrial(config) {
|
|
182
|
+
const trial = config.trial();
|
|
183
|
+
if (!trial) return;
|
|
184
|
+
if (Date.parse(trial.expires_at) < Date.now()) {
|
|
185
|
+
config.clearTrial();
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
process.stderr.write(
|
|
189
|
+
`${paint("yellow", `This directory had a trial (${trial.workspace}): keep it with ${trial.claim_url} or this push goes to your account`)}\n\n`
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
137
193
|
// Something the platform wants the developer to know about the command they
|
|
138
194
|
// just ran -- a deprecation, usually. On stderr so scripts reading stdout keep
|
|
139
195
|
// working.
|
package/lib/commands/misc.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import { KEYS, SLUG_FORMAT } from "../config.mjs";
|
|
|
7
7
|
import { MANIFEST_FILE, manifestPath } from "../workspace.mjs";
|
|
8
8
|
import { VERSION } from "../version.mjs";
|
|
9
9
|
import { fail, takeValue } from "../support.mjs";
|
|
10
|
+
import { formatUtc } from "../trial.mjs";
|
|
10
11
|
import { workspacesClient } from "./deploy.mjs";
|
|
11
12
|
|
|
12
13
|
export const DOCS_URL = "https://vatio.ai/docs";
|
|
@@ -36,7 +37,16 @@ export function doctor(config) {
|
|
|
36
37
|
console.log(`Workspace: unreadable — ${error.message}`);
|
|
37
38
|
}
|
|
38
39
|
if (slug) console.log(`Workspace: ${slug}`);
|
|
39
|
-
|
|
40
|
+
const token = config.resolveToken();
|
|
41
|
+
console.log(`Token: ${token ? "configured" : "missing — run `vatio login`"}`);
|
|
42
|
+
// Where this directory pushes with no account. The link to keep it is not
|
|
43
|
+
// printed: whoever holds it can take the trial, and this output is the one
|
|
44
|
+
// that gets pasted into issues.
|
|
45
|
+
const trial = config.trial();
|
|
46
|
+
if (trial) {
|
|
47
|
+
const used = token ? " (not used: this machine has an account)" : "";
|
|
48
|
+
console.log(`Trial: ${trial.workspace}${used}, deleted ${formatUtc(trial.expires_at)} unless kept`);
|
|
49
|
+
}
|
|
40
50
|
console.log(`Docs: ${DOCS_URL}`);
|
|
41
51
|
}
|
|
42
52
|
|
|
@@ -114,7 +124,12 @@ export async function init(config, args) {
|
|
|
114
124
|
console.log(`Wrote ${manifest}`);
|
|
115
125
|
const agentsNote = writeAgentsNote(target);
|
|
116
126
|
if (agentsNote) console.log(agentsNote);
|
|
117
|
-
if (!authorized)
|
|
127
|
+
if (!authorized) {
|
|
128
|
+
console.log(
|
|
129
|
+
"Local only for now — `vatio push` deploys it with no account, as a trial, and prints a link to try it " +
|
|
130
|
+
`and one to keep it as ${slug}.`
|
|
131
|
+
);
|
|
132
|
+
}
|
|
118
133
|
if (!authorized && String(name ?? "").trim() !== "") {
|
|
119
134
|
console.log("Set the display name once it exists: `vatio business set --name NAME`, or the inbox's Business page.");
|
|
120
135
|
}
|
package/lib/config.mjs
CHANGED
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
// identity is per directory and lives in that workspace's own vatio.yml. There
|
|
11
11
|
// is no --workspace flag, because the slug is a property of the directory, and
|
|
12
12
|
// reading it anywhere else is how a push lands in the wrong workspace.
|
|
13
|
+
//
|
|
14
|
+
// The one thing kept here per directory is a trial (lib/trial.mjs): what
|
|
15
|
+
// `vatio push` made with no account on this machine, under `trials`, keyed by
|
|
16
|
+
// the workspace's absolute path. Its deploy key is a credential, so it lives
|
|
17
|
+
// in this 0600 file and never in the directory, where it could be committed.
|
|
13
18
|
|
|
14
19
|
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
15
20
|
import { homedir } from "node:os";
|
|
@@ -135,17 +140,51 @@ export class Config {
|
|
|
135
140
|
return this.workspaceRoot ? manifestPath(this.workspaceRoot) : null;
|
|
136
141
|
}
|
|
137
142
|
|
|
138
|
-
// The workspace's slice of the API, which is what chat talks to
|
|
139
|
-
|
|
143
|
+
// The workspace's slice of the API, which is what chat talks to: the trial
|
|
144
|
+
// this directory pushed to while this machine has no account, unless a
|
|
145
|
+
// token was given for the call itself.
|
|
146
|
+
resolveApiUrl({ explicit = null, token = null } = {}) {
|
|
140
147
|
const url = presence(explicit);
|
|
141
148
|
if (url) return stripSlash(url);
|
|
142
149
|
|
|
143
150
|
const base = this.resolveBaseUrl();
|
|
144
|
-
const
|
|
151
|
+
const trial = presence(token) ? null : this.activeTrial();
|
|
152
|
+
const workspace = trial?.workspace ?? this.resolveWorkspace();
|
|
145
153
|
if (!base || !workspace) return null;
|
|
146
154
|
return `${base}/api/developer/v1/${workspace}`;
|
|
147
155
|
}
|
|
148
156
|
|
|
157
|
+
// The trial `vatio push` made from this directory against this base URL:
|
|
158
|
+
// { base_url, workspace, requested, key, claim_url, try_url, expires_at }.
|
|
159
|
+
trial() {
|
|
160
|
+
if (!this.workspaceRoot) return null;
|
|
161
|
+
const trials = this.load().trials;
|
|
162
|
+
const entry = trials && typeof trials === "object" ? trials[this.workspaceRoot] : null;
|
|
163
|
+
if (!entry || typeof entry !== "object" || !presence(entry.key) || !presence(entry.workspace)) return null;
|
|
164
|
+
return stripSlash(presence(entry.base_url)) === this.resolveBaseUrl() ? entry : null;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// The trial commands go to: only while this machine has no account.
|
|
168
|
+
activeTrial() {
|
|
169
|
+
return this.resolveToken() ? null : this.trial();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
writeTrial(entry) {
|
|
173
|
+
const root = this.workspaceRootRequired();
|
|
174
|
+
const data = this.load();
|
|
175
|
+
const trials = data.trials && typeof data.trials === "object" ? data.trials : {};
|
|
176
|
+
data.trials = { ...trials, [root]: { ...entry, base_url: this.resolveBaseUrl() } };
|
|
177
|
+
return this.save(data);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
clearTrial() {
|
|
181
|
+
const data = this.load();
|
|
182
|
+
if (!this.workspaceRoot || !data.trials?.[this.workspaceRoot]) return data;
|
|
183
|
+
delete data.trials[this.workspaceRoot];
|
|
184
|
+
if (Object.keys(data.trials).length === 0) delete data.trials;
|
|
185
|
+
return this.save(data);
|
|
186
|
+
}
|
|
187
|
+
|
|
149
188
|
writeAuth({ baseUrl, token }) {
|
|
150
189
|
const data = this.load();
|
|
151
190
|
data.base_url = stripSlash(String(baseUrl ?? "")) ?? "";
|
package/lib/help.mjs
CHANGED
|
@@ -35,7 +35,9 @@ Commands default as listed.
|
|
|
35
35
|
|
|
36
36
|
Deploy:
|
|
37
37
|
push [--force] Validate the workspace, then update preview; runs
|
|
38
|
-
no tests
|
|
38
|
+
no tests. With no account on this machine it
|
|
39
|
+
deploys a 7-day trial and prints a link to try
|
|
40
|
+
it and one to keep it (keeping it signs in).
|
|
39
41
|
--force replaces an unpublished push from
|
|
40
42
|
another git branch
|
|
41
43
|
publish [--force] Take preview live, with its knowledge changes.
|
|
@@ -99,12 +101,9 @@ Commands default as listed.
|
|
|
99
101
|
|
|
100
102
|
Business (one value for every environment, live on save; also on the inbox's
|
|
101
103
|
Business page):
|
|
102
|
-
business [show] Name, description, brand
|
|
104
|
+
business [show] Name, description, brand
|
|
103
105
|
business set [--name NAME] [--description TEXT | --description-file FILE]
|
|
104
106
|
[--about TEXT] [--color #RRGGBB|default] [--logo FILE | --remove-logo]
|
|
105
|
-
business hours --timezone ZONE --mon 09:00-18:00 --tue 09:00-13:00,14:00-18:00 ...
|
|
106
|
-
Replaces the week: a day not given is closed
|
|
107
|
-
business hours --clear No hours: someone is always available
|
|
108
107
|
|
|
109
108
|
Credentials:
|
|
110
109
|
secrets list|set KEY [VALUE]|rm KEY [--env NAME | --tests]
|
package/lib/http.mjs
CHANGED
|
@@ -21,6 +21,19 @@ export class UnauthorizedError extends HttpError {}
|
|
|
21
21
|
export class ForbiddenError extends HttpError {}
|
|
22
22
|
export class NotFoundError extends HttpError {}
|
|
23
23
|
|
|
24
|
+
// A trial's deploy key (lib/trial.mjs) after someone kept the trial: the call
|
|
25
|
+
// did nothing, and `workspace` is the workspace it became. bin/vatio.mjs signs
|
|
26
|
+
// this terminal in and runs the command again.
|
|
27
|
+
export class TrialClaimedError extends HttpError {
|
|
28
|
+
constructor(message, options) {
|
|
29
|
+
super(message, options);
|
|
30
|
+
this.workspace = typeof options.body?.workspace === "string" ? options.body.workspace : null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// A trial's deploy key whose trial was deleted: nobody kept it in time.
|
|
35
|
+
export class TrialGoneError extends HttpError {}
|
|
36
|
+
|
|
24
37
|
// The platform takes calls only from the CLI's current release
|
|
25
38
|
// (RequiresLatestCli on the backend): `latest` is the version to run instead.
|
|
26
39
|
// The refused call did nothing, so bin/vatio.mjs runs the whole command again
|
|
@@ -147,6 +160,8 @@ export class HttpClient {
|
|
|
147
160
|
|
|
148
161
|
const options = { status, requestId, body: body ?? {} };
|
|
149
162
|
if (status === 426 && body?.error_key === "cli_outdated") throw new CliOutdatedError(message, options);
|
|
163
|
+
if (status === 409 && body?.error === "trial_claimed") throw new TrialClaimedError(message, options);
|
|
164
|
+
if (status === 401 && body?.error === "trial_not_found") throw new TrialGoneError(message, options);
|
|
150
165
|
if (status === 401) throw new UnauthorizedError(message, options);
|
|
151
166
|
if (status === 403) throw new ForbiddenError(message, options);
|
|
152
167
|
if (status === 404) throw new NotFoundError(message, options);
|
package/lib/telemetry.mjs
CHANGED
|
@@ -28,7 +28,7 @@ const SUBCOMMANDS = {
|
|
|
28
28
|
chat: ["show"],
|
|
29
29
|
env: ["list", "rm"],
|
|
30
30
|
kb: ["list", "show", "create", "rm", "write", "cat", "rm-entry", "status", "publish", "history"],
|
|
31
|
-
business: ["show", "set"
|
|
31
|
+
business: ["show", "set"],
|
|
32
32
|
secrets: ["list", "set", "rm"],
|
|
33
33
|
tokens: ["list", "create", "revoke", "origins"],
|
|
34
34
|
keys: ["list", "create", "revoke"],
|
package/lib/trial.mjs
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// `vatio push` on a machine with no account: a trial workspace.
|
|
2
|
+
//
|
|
3
|
+
// The platform makes one (POST /api/developer/v1/trials) and answers with two
|
|
4
|
+
// secrets. The deploy key (`vtk_`) stays on this machine, in the config file,
|
|
5
|
+
// next to this directory's path: it pushes, checks, chats and writes knowledge
|
|
6
|
+
// on the trial's preview, and nothing else. The link to keep it (`claim_url`)
|
|
7
|
+
// is for the person: opened signed in, it makes the trial theirs.
|
|
8
|
+
//
|
|
9
|
+
// Keeping it hands this machine nothing. The key answers `409 trial_claimed`
|
|
10
|
+
// from then on, naming the workspace the trial became, and the next command
|
|
11
|
+
// signs this terminal in with a device code like `vatio login` does
|
|
12
|
+
// (keepClaimedTrial). A link that sent a token back here would send one to
|
|
13
|
+
// whoever made the trial and got someone else to open its link.
|
|
14
|
+
|
|
15
|
+
import { MANIFEST_FILE, rewriteWorkspaceSlug, workspaceSlug } from "./workspace.mjs";
|
|
16
|
+
import { HttpError, throwIfOutdated } from "./http.mjs";
|
|
17
|
+
import { clientHeaders } from "./telemetry.mjs";
|
|
18
|
+
import { deviceLogin } from "./commands/auth.mjs";
|
|
19
|
+
|
|
20
|
+
// Asks for a trial, and remembers it for this directory. `requested` is the
|
|
21
|
+
// slug vatio.yml names, which the trial takes when it is kept if it is free.
|
|
22
|
+
export async function startTrial(config, requested) {
|
|
23
|
+
const baseUrl = config.resolveBaseUrl();
|
|
24
|
+
const url = `${baseUrl}/api/developer/v1/trials`;
|
|
25
|
+
let response;
|
|
26
|
+
try {
|
|
27
|
+
response = await fetch(url, {
|
|
28
|
+
method: "POST",
|
|
29
|
+
headers: { ...clientHeaders(), "Content-Type": "application/json", Accept: "application/json" },
|
|
30
|
+
body: JSON.stringify({ workspace: requested }),
|
|
31
|
+
signal: AbortSignal.timeout(30_000)
|
|
32
|
+
});
|
|
33
|
+
} catch (error) {
|
|
34
|
+
const reason = error?.cause?.code ?? error?.name ?? "request failed";
|
|
35
|
+
throw new HttpError(`${reason}: ${url}`);
|
|
36
|
+
}
|
|
37
|
+
await throwIfOutdated(response);
|
|
38
|
+
|
|
39
|
+
const raw = await response.text();
|
|
40
|
+
let body;
|
|
41
|
+
try {
|
|
42
|
+
body = JSON.parse(raw);
|
|
43
|
+
} catch {
|
|
44
|
+
body = {};
|
|
45
|
+
}
|
|
46
|
+
if (response.status !== 201 || !body.trial_key || !body.workspace) {
|
|
47
|
+
const message = body.error_description ?? body.error ?? (raw.trim().slice(0, 200) || `HTTP ${response.status}`);
|
|
48
|
+
throw new HttpError(`Could not start a trial: ${message}`, {
|
|
49
|
+
status: response.status,
|
|
50
|
+
requestId: body.request_id ?? null,
|
|
51
|
+
body
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
console.log(
|
|
56
|
+
"No Vatio account on this machine, so this goes to a trial workspace. Nothing to sign up for until you keep it."
|
|
57
|
+
);
|
|
58
|
+
const trial = {
|
|
59
|
+
workspace: body.workspace,
|
|
60
|
+
requested,
|
|
61
|
+
key: body.trial_key,
|
|
62
|
+
claim_url: body.claim_url,
|
|
63
|
+
expires_at: body.expires_at
|
|
64
|
+
};
|
|
65
|
+
config.writeTrial(trial);
|
|
66
|
+
return config.trial();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// What a push to a trial prints: the two links, what a trial cannot do, and
|
|
70
|
+
// how long it lasts.
|
|
71
|
+
export function printTrialPush(trial, payload, { started }) {
|
|
72
|
+
const where = started ? "preview" : `preview of trial ${trial.workspace}`;
|
|
73
|
+
console.log(`Pushed deployment #${payload.deployment_id} to ${where} (git_sha=${JSON.stringify(payload.git_sha ?? null)})`);
|
|
74
|
+
for (const warning of Array.isArray(payload.warnings) ? payload.warnings : []) console.log(` warning: ${warning}`);
|
|
75
|
+
console.log("");
|
|
76
|
+
printTrialLinks(trial);
|
|
77
|
+
console.log("");
|
|
78
|
+
console.log(
|
|
79
|
+
`Deleted ${formatUtc(trial.expires_at)} unless you keep it. Until then: preview only, tools make no writes, no secrets.`
|
|
80
|
+
);
|
|
81
|
+
console.log('Talk to it: vatio chat "hello" Already have an account? vatio login, then vatio push.');
|
|
82
|
+
console.log("(A coding agent running this: give the person you work for both links.)");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function printTrialLinks(trial) {
|
|
86
|
+
if (trial.try_url) {
|
|
87
|
+
console.log("Try it (anyone with this link can chat with it):");
|
|
88
|
+
console.log(` ${trial.try_url}`);
|
|
89
|
+
}
|
|
90
|
+
console.log("Keep it (sign in or create an account; this link makes it yours, so don't share it):");
|
|
91
|
+
console.log(` ${trial.claim_url}`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Someone opened the link and kept the trial since the last command: the key
|
|
95
|
+
// stopped working, and this terminal signs in to the account that kept it --
|
|
96
|
+
// with a device code its owner approves in the browser, never with anything
|
|
97
|
+
// the platform sent here. vatio.yml then names the workspace the trial became,
|
|
98
|
+
// if that is not the slug it asked for.
|
|
99
|
+
export async function keepClaimedTrial(config, error) {
|
|
100
|
+
const trial = config.trial();
|
|
101
|
+
const workspace = error.workspace;
|
|
102
|
+
const auth = await deviceLogin({
|
|
103
|
+
config,
|
|
104
|
+
baseUrl: config.resolveBaseUrl(),
|
|
105
|
+
workspace,
|
|
106
|
+
message: `You kept this agent: it is workspace ${workspace} now. Sign this terminal in to keep working on it.`
|
|
107
|
+
});
|
|
108
|
+
config.writeAuth({ baseUrl: auth.baseUrl, token: auth.token });
|
|
109
|
+
console.log(`Token saved to ${config.configPath}`);
|
|
110
|
+
|
|
111
|
+
const root = config.workspaceRoot;
|
|
112
|
+
let current = null;
|
|
113
|
+
try {
|
|
114
|
+
current = root ? workspaceSlug(root) : null;
|
|
115
|
+
} catch {
|
|
116
|
+
current = null;
|
|
117
|
+
}
|
|
118
|
+
if (root && workspace && current !== workspace && rewriteWorkspaceSlug(root, workspace)) {
|
|
119
|
+
const why = current && current === trial?.requested ? `${current} was taken` : "the workspace you kept";
|
|
120
|
+
console.log(`${MANIFEST_FILE}: workspace ${current ?? "(none)"} → ${workspace} (${why})`);
|
|
121
|
+
}
|
|
122
|
+
config.clearTrial();
|
|
123
|
+
console.log("");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// "Fri Oct 16 03:40 UTC": when, to the minute, in the zone every terminal shows
|
|
127
|
+
// the same.
|
|
128
|
+
export function formatUtc(iso) {
|
|
129
|
+
const date = new Date(iso);
|
|
130
|
+
if (Number.isNaN(date.getTime())) return "soon";
|
|
131
|
+
const day = date.toLocaleDateString("en-US", { weekday: "short", month: "short", day: "numeric", timeZone: "UTC" });
|
|
132
|
+
const time = date.toLocaleTimeString("en-GB", { hour: "2-digit", minute: "2-digit", timeZone: "UTC" });
|
|
133
|
+
return `${day.replace(",", "")} ${time} UTC`;
|
|
134
|
+
}
|
package/lib/workspace.mjs
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
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
|
|
|
10
|
-
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
10
|
+
import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
11
11
|
import { dirname, join, parse as parsePath, relative, resolve } from "node:path";
|
|
12
12
|
import { parse as parseYaml } from "yaml";
|
|
13
13
|
|
|
@@ -90,6 +90,22 @@ export function workspaceSlug(dir) {
|
|
|
90
90
|
return slug;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
// Points the directory at another workspace: the one a trial became when it
|
|
94
|
+
// was kept under a slug other than the one vatio.yml asked for. Only the
|
|
95
|
+
// top-level `workspace:` line changes, comment and all kept, so the rest of
|
|
96
|
+
// the file is exactly what the developer wrote. False when there is no such
|
|
97
|
+
// line to change.
|
|
98
|
+
export function rewriteWorkspaceSlug(dir, slug) {
|
|
99
|
+
const file = manifestPath(dir);
|
|
100
|
+
if (!file || !SLUG_FORMAT.test(slug)) return false;
|
|
101
|
+
|
|
102
|
+
const text = readFileSync(file, "utf8");
|
|
103
|
+
const line = /^workspace:[ \t]*(["']?)[a-z0-9-]*\1([ \t]*#.*)?$/m;
|
|
104
|
+
if (!line.test(text)) return false;
|
|
105
|
+
writeFileSync(file, text.replace(line, (_match, _quote, comment = "") => `workspace: ${slug}${comment}`));
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
|
|
93
109
|
function readManifest(file) {
|
|
94
110
|
if (!existsSync(file)) return null;
|
|
95
111
|
try {
|