nexo-code 0.1.0 → 0.1.2

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.
Files changed (2) hide show
  1. package/nexo.mjs +53 -4
  2. package/package.json +1 -1
package/nexo.mjs CHANGED
@@ -14681,6 +14681,8 @@ var require_content_type = __commonJS({
14681
14681
 
14682
14682
  // dist/main.js
14683
14683
  import { spawnSync as spawnSync2 } from "node:child_process";
14684
+ import { rmSync } from "node:fs";
14685
+ import { join as join19 } from "node:path";
14684
14686
  import { createInterface } from "node:readline";
14685
14687
 
14686
14688
  // dist/update.js
@@ -14688,7 +14690,7 @@ import { mkdir, readFile, writeFile } from "node:fs/promises";
14688
14690
  import { join } from "node:path";
14689
14691
 
14690
14692
  // dist/version.js
14691
- var VERSION = "0.1.0";
14693
+ var VERSION = "0.1.2";
14692
14694
 
14693
14695
  // dist/update.js
14694
14696
  var PACKAGE = "nexo-code";
@@ -44245,7 +44247,9 @@ async function login(io, opts) {
44245
44247
  io.err(`${s.error(s.sym.fail)} Use an https:// API URL (plain http is only allowed for localhost).`);
44246
44248
  return 2;
44247
44249
  }
44248
- const token = await io.readSecret(`Paste your Nexo token (input hidden): `);
44250
+ const token = !opts.token && io.interactive && io.readLine ? await emailSignIn(io, apiUrl) : await io.readSecret(`Paste your Nexo token (input hidden): `);
44251
+ if (token === null)
44252
+ return 1;
44249
44253
  if (!TOKEN2.test(token)) {
44250
44254
  io.err(`${s.error(s.sym.fail)} That doesn't look like a Nexo token (it starts with nexo_). Ask the account owner for one.`);
44251
44255
  return 2;
@@ -44257,6 +44261,37 @@ async function login(io, opts) {
44257
44261
  io.out(s.dim(` user ${me.userId}`));
44258
44262
  return 0;
44259
44263
  }
44264
+ async function emailSignIn(io, apiUrl) {
44265
+ const { style: s } = io;
44266
+ io.err(`${s.bold("Sign in to Nexo")} ${s.dim("(Ctrl+C to cancel)")}`);
44267
+ io.err("Type your email address and press Enter:");
44268
+ const email3 = (await io.readLine(`${s.primary("\u203A")} Your email: `))?.trim();
44269
+ if (!email3)
44270
+ return null;
44271
+ if (!await io.confirm("Nexo is for adults. Are you 18 or older?")) {
44272
+ io.err(s.dim(" Nexo is only for people 18 and older."));
44273
+ return null;
44274
+ }
44275
+ const post = (path2, body) => (io.fetch ?? fetch)(new URL(path2, apiUrl), { method: "POST", headers: { "content-type": "application/json", "x-nexo-client": "cli" }, body: JSON.stringify(body) });
44276
+ const started = await post("/v1/auth/email/start", { email: email3, adult: true });
44277
+ if (!started.ok)
44278
+ throw await errorFromResponse(started);
44279
+ io.err(s.dim(` If ${email3} has a Nexo account, a six-digit code is on its way. No account yet? Sign up at https://usenexoai.com`));
44280
+ for (let tries = 0; tries < 3; tries++) {
44281
+ io.err("Type the six-digit code from the email and press Enter:");
44282
+ const code = (await io.readLine(`${s.primary("\u203A")} Code from the email: `))?.replace(/\s+/g, "");
44283
+ if (!code)
44284
+ return null;
44285
+ const res = await post("/v1/auth/email/verify", { email: email3, code });
44286
+ if (res.ok)
44287
+ return String((await res.json()).token ?? "");
44288
+ const err = await errorFromResponse(res);
44289
+ io.err(`${s.error(s.sym.fail)} ${err.message}`);
44290
+ if (err.code !== "UNAUTHENTICATED" && err.code !== "INVALID_INPUT")
44291
+ return null;
44292
+ }
44293
+ return null;
44294
+ }
44260
44295
  async function authStatus(io) {
44261
44296
  const { style: s } = io;
44262
44297
  const creds = await loadCredentials(io.env);
@@ -46442,7 +46477,7 @@ Usage:
46442
46477
  nexo remote Take tasks from the Nexo app (Code) in this folder: they run here, and
46443
46478
  every file change and command is approved on your phone
46444
46479
  nexo models The models you can put in a team (nexo run --team)
46445
- nexo login [--api-url <url>] Save your Nexo token (from the account owner)
46480
+ nexo login Sign in with your email and the code it receives (--token to paste a token)
46446
46481
  nexo auth status Show login and this month's usage against your cap
46447
46482
  nexo logout Revoke the token and remove it from this machine
46448
46483
  nexo update Install the latest Nexo Code (npm install -g nexo-code@latest)
@@ -46544,6 +46579,7 @@ async function run2(argv, io) {
46544
46579
  print: { type: "string", short: "p" },
46545
46580
  output: { type: "string" },
46546
46581
  "api-url": { type: "string" },
46582
+ token: { type: "boolean" },
46547
46583
  "no-color": { type: "boolean" },
46548
46584
  debug: { type: "boolean" }
46549
46585
  }
@@ -46641,6 +46677,8 @@ async function run2(argv, io) {
46641
46677
  io.err(`${io.style.error(io.style.sym.fail)} Could not run npm. Install the update yourself: npm install -g ${PACKAGE}@latest`);
46642
46678
  return 1;
46643
46679
  }
46680
+ if (npm.status === 0 && process.platform === "win32")
46681
+ dropBlockedLauncher();
46644
46682
  return npm.status ?? 1;
46645
46683
  }
46646
46684
  if (cmd === "remote") {
@@ -46656,7 +46694,7 @@ async function run2(argv, io) {
46656
46694
  return remote(io, budget);
46657
46695
  }
46658
46696
  if (cmd === "login")
46659
- return login(io, values["api-url"] ? { apiUrl: values["api-url"] } : {});
46697
+ return login(io, { ...values["api-url"] ? { apiUrl: values["api-url"] } : {}, ...values.token ? { token: true } : {} });
46660
46698
  if (cmd === "models")
46661
46699
  return listModels(io);
46662
46700
  if (cmd === "logout")
@@ -46733,6 +46771,17 @@ async function headless(io, words, format, yes) {
46733
46771
  line2({ type: "result", exitCode: code, answer: text2.trim(), ...result ?? { outcome: code === 0 ? "done" : "failed", filesChanged: [], costMicros: 0 } });
46734
46772
  return code;
46735
46773
  }
46774
+ function dropBlockedLauncher() {
46775
+ try {
46776
+ const policy = spawnSync2("powershell.exe", ["-NoProfile", "-Command", "Get-ExecutionPolicy"], { encoding: "utf8", windowsHide: true }).stdout.trim();
46777
+ if (policy !== "Restricted" && policy !== "AllSigned")
46778
+ return;
46779
+ const prefix = spawnSync2("npm.cmd", ["prefix", "-g"], { encoding: "utf8", shell: true, windowsHide: true }).stdout.trim();
46780
+ if (prefix)
46781
+ rmSync(join19(prefix, "nexo.ps1"), { force: true });
46782
+ } catch {
46783
+ }
46784
+ }
46736
46785
  var isMain = true;
46737
46786
  if (isMain) {
46738
46787
  const settings = loadSettings(configDir(process.env));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexo-code",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Nexo Code: an AI coding agent for your terminal. Sign in with your Nexo account.",
5
5
  "homepage": "https://usenexoai.com",
6
6
  "license": "UNLICENSED",