@vatio-ai/cli 0.59.0 → 0.60.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.
@@ -1,64 +1,83 @@
1
- // login / logout, and the device-code dance they share with `init`.
1
+ // login / logout, and the device-code dance they share with `push`.
2
2
 
3
- import { DeviceAuthClient, ExpiredError, PendingError } from "../device-auth.mjs";
3
+ import { DeniedError, DeviceAuthClient, ExpiredError, PendingError } from "../device-auth.mjs";
4
4
  import { DEFAULT_BASE_URL } from "../config.mjs";
5
- import { ask, fail, openBrowser, sleep, takeValue } from "../support.mjs";
5
+ import { fail, openBrowser, sleep, takeValue } from "../support.mjs";
6
6
 
7
- // A token is minted by a human approving it in a browser, never by the CLI
8
- // alone. The email turns that approval into a link we mail, which is what lets
9
- // somebody with no account finish it; typing nothing falls back to the URL.
10
- export async function deviceLogin({ baseUrl, message, email }) {
7
+ // A token is minted by a human signing in on the page this opens -- email,
8
+ // Google or GitHub -- never by the CLI alone, which is why it asks nothing
9
+ // itself: a coding agent running it has no one to ask. The code in flight is
10
+ // kept in the config file, so an agent whose shell gave up waiting picks the
11
+ // same page back up on its next run instead of starting over.
12
+ export async function deviceLogin({ config, baseUrl, message, workspace = null }) {
11
13
  const resolved = String(baseUrl || process.env.VATIO_BASE_URL || DEFAULT_BASE_URL).replace(/\/$/, "");
12
14
  const client = new DeviceAuthClient({ baseUrl: resolved });
13
15
 
14
16
  console.log(message);
15
- const address = String(email ?? (await ask("Your email (we send you a link): "))).trim();
16
-
17
- const auth = await client.start({ email: address });
18
- const deviceCode = auth.device_code;
19
- const userCode = auth.user_code;
20
- const verificationUri = auth.verification_uri_complete ?? auth.verification_uri;
21
- const interval = Number(auth.interval ?? 5);
22
- const expiresIn = Number(auth.expires_in ?? 900);
23
- if (!deviceCode || !verificationUri) fail("The platform did not return a device code");
17
+ let pending = config.pendingLogin();
18
+ const resumed = pending && pending.base_url === resolved && pending.expires_at > Date.now();
19
+ if (!resumed) pending = await startLogin({ config, client, resolved, workspace });
24
20
 
25
21
  console.log("");
26
- if (auth.email_sent) {
27
- console.log(`We emailed ${address} a link.`);
28
- console.log(`This terminal is ${userCode} — check it matches before you approve.`);
29
- } else {
30
- console.log(`Open: ${verificationUri}`);
31
- console.log(`Code: ${userCode}`);
32
- openBrowser(verificationUri);
33
- }
22
+ console.log(resumed ? "Still waiting for you to sign in here:" : "Sign in to Vatio here:");
23
+ console.log(` ${pending.url}`);
24
+ console.log(`This terminal is ${pending.user_code} — check the page shows the same code.`);
25
+ console.log("(A coding agent running this: if no browser opened, show this link to the person you work for.)");
26
+ if (!resumed) openBrowser(pending.url);
34
27
  console.log("");
35
- console.log("Waiting…");
28
+ console.log("Waiting… (if this gets cut off, run the same command again once you have signed in)");
36
29
 
37
- const deadline = Date.now() + expiresIn * 1000;
38
30
  for (;;) {
39
- if (Date.now() > deadline) fail("Timed out waiting for authorization");
31
+ if (Date.now() > pending.expires_at) {
32
+ config.clearPendingLogin();
33
+ fail("The link expired. Run the command again to get a new one.");
34
+ }
40
35
  try {
41
- const result = await client.poll({ deviceCode });
36
+ const result = await client.poll({ deviceCode: pending.device_code });
37
+ config.clearPendingLogin();
42
38
  return {
43
39
  token: result.token,
44
40
  baseUrl: String(result.base_url ?? "").trim() || resolved
45
41
  };
46
42
  } catch (error) {
47
43
  if (error instanceof PendingError) {
48
- await sleep(interval * 1000);
44
+ await sleep(pending.interval * 1000);
49
45
  continue;
50
46
  }
51
- if (error instanceof ExpiredError) fail("The code expired. Run `vatio login` again.");
47
+ if (error instanceof ExpiredError || error instanceof DeniedError) {
48
+ config.clearPendingLogin();
49
+ fail(error instanceof DeniedError
50
+ ? "The sign-in was turned down in the browser. Run the command again to get a new link."
51
+ : "The link expired. Run the command again to get a new one.");
52
+ }
52
53
  throw error;
53
54
  }
54
55
  }
55
56
  }
56
57
 
58
+ async function startLogin({ config, client, resolved, workspace }) {
59
+ const auth = await client.start({ workspace });
60
+ const url = auth.verification_uri_complete ?? auth.verification_uri;
61
+ if (!auth.device_code || !url) fail("The platform did not return a device code");
62
+
63
+ const pending = {
64
+ base_url: resolved,
65
+ url,
66
+ device_code: auth.device_code,
67
+ user_code: auth.user_code,
68
+ interval: Number(auth.interval ?? 5),
69
+ expires_at: Date.now() + Number(auth.expires_in ?? 900) * 1000
70
+ };
71
+ config.writePendingLogin(pending);
72
+ return pending;
73
+ }
74
+
57
75
  export async function login(config, args) {
58
76
  const baseUrl = takeValue(args, "--base-url");
59
77
  const { token, baseUrl: resolved } = await deviceLogin({
78
+ config,
60
79
  baseUrl,
61
- message: "Starting device authorization for Vatio CLI…"
80
+ message: "Signing this machine in to Vatio…"
62
81
  });
63
82
 
64
83
  config.writeAuth({ baseUrl: resolved, token });
@@ -23,10 +23,10 @@ import { detectGitSha, fail, paint, takeEnv, takeFlag, takeValue } from "../supp
23
23
 
24
24
  // The first command that makes something exist on a server, so the first one
25
25
  // that needs to know whose it is.
26
- export async function ensureAuthorized(config) {
26
+ export async function ensureAuthorized(config, { workspace = null } = {}) {
27
27
  if (config.resolveToken()) return;
28
28
 
29
- const auth = await deviceLogin({ message: "Before I can push this, I need to know whose it is." });
29
+ const auth = await deviceLogin({ config, workspace, message: "Before I can push this, I need to know whose it is." });
30
30
  config.writeAuth({ baseUrl: auth.baseUrl, token: auth.token });
31
31
  console.log(`Token saved to ${config.configPath}`);
32
32
  console.log("");
@@ -90,7 +90,7 @@ export async function push(config, args) {
90
90
  const environment = takeEnv(args, { fallback: null, cwd: config.workspaceRoot });
91
91
  const workspace = config.resolveWorkspaceRequired();
92
92
 
93
- await ensureAuthorized(config);
93
+ await ensureAuthorized(config, { workspace });
94
94
 
95
95
  // The remote has to exist before the workspace can be checked: the slug is in
96
96
  // the URL of the call that checks it. It is created unnamed; the display name
@@ -52,7 +52,6 @@ async function show(client, workspace, name) {
52
52
  ? ` deployment: #${row.deployment_id}${row.git_sha ? ` (${row.git_sha.slice(0, 7)})` : ""}`
53
53
  : " deployment: none yet — `vatio push`");
54
54
  if (row.share_url) console.log(` try it: ${row.share_url}`);
55
- if (row.page_url) console.log(` page with the bubble: ${row.page_url}`);
56
55
  if (row.knowledge_url) console.log(` knowledge diff: ${row.knowledge_url}`);
57
56
 
58
57
  if (row.token) {
package/lib/config.mjs CHANGED
@@ -156,6 +156,24 @@ export class Config {
156
156
  return this.save(data);
157
157
  }
158
158
 
159
+ pendingLogin() {
160
+ const pending = this.load().pending_login;
161
+ return pending && typeof pending === "object" && pending.device_code ? pending : null;
162
+ }
163
+
164
+ writePendingLogin(pending) {
165
+ const data = this.load();
166
+ data.pending_login = pending;
167
+ return this.save(data);
168
+ }
169
+
170
+ clearPendingLogin() {
171
+ const data = this.load();
172
+ if (!Object.hasOwn(data, "pending_login")) return data;
173
+ delete data.pending_login;
174
+ return this.save(data);
175
+ }
176
+
159
177
  displayHash() {
160
178
  const out = {};
161
179
  const base = this.resolveBaseUrl();
@@ -17,11 +17,11 @@ export class DeviceAuthClient {
17
17
  this.baseUrl = String(baseUrl ?? "").replace(/\/$/, "");
18
18
  }
19
19
 
20
- // With an `email` the platform mails the approval link; without one the
21
- // response is exactly what it always was.
22
- start({ email } = {}) {
20
+ // A `workspace` lets the page the developer signs in on wait for that push
21
+ // and land on its test screen.
22
+ start({ workspace } = {}) {
23
23
  const body = {};
24
- if (String(email ?? "").trim() !== "") body.email = String(email).trim();
24
+ if (workspace) body.workspace = workspace;
25
25
  return this.#post("/api/developer/v1/device_authorizations", body);
26
26
  }
27
27
 
package/lib/help.mjs CHANGED
@@ -19,7 +19,8 @@ and the one its pull request deploys to. Elsewhere commands default as listed.
19
19
 
20
20
  Getting started:
21
21
  init [SLUG] [--name NAME] Create vatio.yml here, and the remote to match
22
- login [--base-url URL] Authorize this machine in a browser
22
+ login [--base-url URL] Sign this machine in from the browser: email link,
23
+ Google or GitHub. Creates the account if needed
23
24
  logout Forget the token
24
25
  doctor Node, config, workspace and token status
25
26
  version What this CLI is
@@ -28,6 +29,7 @@ and the one its pull request deploys to. Elsewhere commands default as listed.
28
29
 
29
30
  Deploy:
30
31
  push [--env NAME] Validate the workspace, then update a preview
32
+ (the first one signs in like \`login\`)
31
33
  publish [--env NAME] Promote an environment to live, with its knowledge
32
34
  changes. Without --env or a branch, the latest
33
35
  push. Refused when GitHub is connected: merge
package/lib/support.mjs CHANGED
@@ -100,6 +100,12 @@ export function detectGitSha(cwd) {
100
100
  }
101
101
  }
102
102
 
103
+ export function sleep(ms) {
104
+ return new Promise((resolve) => setTimeout(resolve, ms));
105
+ }
106
+
107
+ // Works without a terminal too: a coding agent running on the developer's own
108
+ // machine still opens their browser.
103
109
  export function openBrowser(url) {
104
110
  if (!url) return;
105
111
  const command =
@@ -114,12 +120,8 @@ export function openBrowser(url) {
114
120
  }
115
121
  }
116
122
 
117
- export function sleep(ms) {
118
- return new Promise((resolve) => setTimeout(resolve, ms));
119
- }
120
-
121
123
  // Returns "" with nothing attached to stdin, so an agent running `vatio push`
122
- // in a pipeline falls back to the URL instead of hanging on a prompt.
124
+ // in a pipeline never hangs on a prompt.
123
125
  export async function ask(question) {
124
126
  if (!process.stdin.isTTY) return "";
125
127
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vatio-ai/cli",
3
- "version": "0.59.0",
3
+ "version": "0.60.0",
4
4
  "description": "Vatio CLI — deploy and manage Vatio agent workspaces",
5
5
  "keywords": [
6
6
  "vatio",