@ai-launchpad-v1/expert-code 0.2.0 → 0.2.1

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 (3) hide show
  1. package/README.md +11 -1
  2. package/dist/index.js +141 -6
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -108,9 +108,19 @@ gauging context size and cost, not exact billing.
108
108
  | `expert setup` | Configure BYOK (your own provider key) |
109
109
  | `expert login` / `expert logout` | Managed sign-in / sign-out |
110
110
  | `expert whoami` | Show sign-in and active inference lane |
111
- | `expert config [set <k> <v>]` | Show or edit config (`apiBase`, `provider`) |
111
+ | `expert config [set <k> <v>]` | Show or edit config (`apiBase`, `provider`, `autoUpdate`) |
112
+ | `expert update` | Update to the latest version now |
112
113
  | `expert --version` / `--help` | Version / help |
113
114
 
115
+ ## Staying up to date
116
+
117
+ Expert Code updates itself. On startup it checks the npm registry (at most once a
118
+ day) and, when a newer version is published, installs it in the background so the
119
+ **next** time you run `expert` you're on the latest — no manual `npm i -g`. Force an
120
+ update any time with `expert update`, or turn the automatic check off with
121
+ `expert config set autoUpdate false` (also honoured: `EXPERT_NO_UPDATE`,
122
+ `NO_UPDATE_NOTIFIER`, and `CI`).
123
+
114
124
  ## Safety
115
125
 
116
126
  Every file operation is confined to the workspace root — checked lexically and after
package/dist/index.js CHANGED
@@ -1735,7 +1735,7 @@ async function login(ask) {
1735
1735
  options: { shouldCreateUser: true }
1736
1736
  });
1737
1737
  if (otpErr) throw new Error(otpErr.message);
1738
- const code = (await ask(" Enter the 6-digit code we emailed you: ")).trim();
1738
+ const code = (await ask(" Enter the code we emailed you: ")).trim();
1739
1739
  if (!code) throw new Error("No code entered.");
1740
1740
  const { data, error } = await sb.auth.verifyOtp({ email, token: code, type: "email" });
1741
1741
  if (error) throw new Error(error.message);
@@ -2969,8 +2969,92 @@ ${summary.trim()}`
2969
2969
  }
2970
2970
  }
2971
2971
 
2972
+ // update.ts
2973
+ init_esm_shims();
2974
+ import { spawn as spawn2 } from "child_process";
2975
+ var PKG = "@ai-launchpad-v1/expert-code";
2976
+ var REGISTRY = "https://registry.npmjs.org";
2977
+ var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
2978
+ function compareSemver(a, b) {
2979
+ const pa = a.split("-")[0].split(".").map((n) => parseInt(n, 10) || 0);
2980
+ const pb = b.split("-")[0].split(".").map((n) => parseInt(n, 10) || 0);
2981
+ for (let i = 0; i < 3; i++) {
2982
+ const d = (pa[i] || 0) - (pb[i] || 0);
2983
+ if (d !== 0) return d;
2984
+ }
2985
+ return 0;
2986
+ }
2987
+ async function fetchLatestVersion(timeoutMs) {
2988
+ try {
2989
+ const ctrl = new AbortController();
2990
+ const timer = setTimeout(() => ctrl.abort(), timeoutMs);
2991
+ const res = await fetch(`${REGISTRY}/${PKG}/latest`, {
2992
+ signal: ctrl.signal,
2993
+ headers: { accept: "application/json" }
2994
+ });
2995
+ clearTimeout(timer);
2996
+ if (!res.ok) return null;
2997
+ const data = await res.json();
2998
+ return typeof data.version === "string" ? data.version : null;
2999
+ } catch {
3000
+ return null;
3001
+ }
3002
+ }
3003
+ function npmInstall(spec, foreground) {
3004
+ return spawn2("npm", ["install", "-g", spec], {
3005
+ detached: !foreground,
3006
+ stdio: foreground ? "inherit" : "ignore",
3007
+ shell: process.platform === "win32"
3008
+ });
3009
+ }
3010
+ function autoUpdateDisabled(cfg) {
3011
+ return cfg.autoUpdate === false || Boolean(process.env.EXPERT_NO_UPDATE) || Boolean(process.env.NO_UPDATE_NOTIFIER) || Boolean(process.env.CI);
3012
+ }
3013
+ async function maybeAutoUpdate(current, cfg) {
3014
+ if (current === "dev" || autoUpdateDisabled(cfg)) return;
3015
+ const now = Date.now();
3016
+ if (now - (cfg.lastUpdateCheck ?? 0) < CHECK_INTERVAL_MS) return;
3017
+ cfg.lastUpdateCheck = now;
3018
+ saveConfig(cfg);
3019
+ const latest = await fetchLatestVersion(2e3);
3020
+ if (!latest || compareSemver(latest, current) <= 0) return;
3021
+ line(
3022
+ c.dim(
3023
+ ` Updating Expert Code ${current} \u2192 ${latest} in the background \u2014 restart to use it.`
3024
+ )
3025
+ );
3026
+ try {
3027
+ npmInstall(`${PKG}@latest`, false).unref();
3028
+ } catch {
3029
+ }
3030
+ }
3031
+ async function forceUpdate(current) {
3032
+ line(c.dim(`
3033
+ Current version: ${current}`));
3034
+ const latest = await fetchLatestVersion(5e3);
3035
+ if (latest && compareSemver(latest, current) <= 0) {
3036
+ line(c.green(` You're on the latest version.
3037
+ `));
3038
+ return;
3039
+ }
3040
+ line(` Installing ${c.orange(`${PKG}@latest`)}\u2026
3041
+ `);
3042
+ const code = await new Promise((resolve3) => {
3043
+ const child = npmInstall(`${PKG}@latest`, true);
3044
+ child.on("close", (c2) => resolve3(c2 ?? 1));
3045
+ child.on("error", () => resolve3(1));
3046
+ });
3047
+ const fresh = loadConfig();
3048
+ fresh.lastUpdateCheck = Date.now();
3049
+ saveConfig(fresh);
3050
+ if (code === 0) line(c.green("\n Updated. Restart `expert` to use the new version.\n"));
3051
+ else line(c.red(`
3052
+ Update failed (npm exited ${code}). Try: npm i -g ${PKG}
3053
+ `));
3054
+ }
3055
+
2972
3056
  // index.ts
2973
- var VERSION = true ? "0.2.0" : "dev";
3057
+ var VERSION = true ? "0.2.1" : "dev";
2974
3058
  function withReadline(fn) {
2975
3059
  const rl = readline2.createInterface({ input: process.stdin, output: process.stdout });
2976
3060
  const ask = (q) => new Promise((res) => rl.question(q, (a) => res(a)));
@@ -3169,9 +3253,14 @@ async function cmdConfig(args, cfg) {
3169
3253
  const v = args[2] ?? "";
3170
3254
  if (k === "apiBase") cfg.apiBase = v;
3171
3255
  else if (k === "provider" && PROVIDERS.includes(v)) cfg.provider = v;
3256
+ else if (k === "autoUpdate") cfg.autoUpdate = !/^(false|0|off|no)$/i.test(v);
3172
3257
  else {
3173
3258
  line(c.red(` Unknown or invalid config key: ${k}`));
3174
- line(c.dim(" Settable: apiBase <url>, provider <anthropic|openai|gemini|groq|openrouter>\n"));
3259
+ line(
3260
+ c.dim(
3261
+ " Settable: apiBase <url>, provider <anthropic|openai|gemini|groq|openrouter>, autoUpdate <true|false>\n"
3262
+ )
3263
+ );
3175
3264
  return;
3176
3265
  }
3177
3266
  saveConfig(cfg);
@@ -3186,7 +3275,39 @@ async function cmdConfig(args, cfg) {
3186
3275
  line(` signed in: ${isLoggedIn(cfg) ? cfg.session?.email ?? "yes" : "no"}`);
3187
3276
  const keyed = PROVIDERS.filter((p) => cfg.keys?.[p]);
3188
3277
  line(` keys : ${keyed.length ? keyed.join(", ") + " (stored)" : "none stored"}`);
3189
- line(c.dim("\n Edit: expert config set apiBase <url> | expert config set provider <name>\n"));
3278
+ line(` autoUpdate: ${cfg.autoUpdate === false ? "off" : "on"}`);
3279
+ line(
3280
+ c.dim(
3281
+ "\n Edit: expert config set apiBase <url> | provider <name> | autoUpdate <true|false>\n"
3282
+ )
3283
+ );
3284
+ }
3285
+ function hasCredential(cfg) {
3286
+ if (chosenLane(cfg) === "managed") return managedConfigured() && isLoggedIn(cfg);
3287
+ return Boolean(resolveKey(resolveProvider(cfg), cfg));
3288
+ }
3289
+ async function onboard() {
3290
+ const options = [];
3291
+ if (managedConfigured()) {
3292
+ options.push({
3293
+ label: "Sign in to the hosted backend \u2014 no API key needed (Premium)",
3294
+ run: () => cmdLogin()
3295
+ });
3296
+ }
3297
+ options.push({ label: "Use your own provider API key (BYOK)", run: () => cmdSetup([]) });
3298
+ line();
3299
+ line(" " + c.bold("Expert") + " " + c.bold(c.orange("Code")) + c.dim(" \u2014 get started"));
3300
+ line(c.dim(" Choose how to run the AI:") + "\n");
3301
+ options.forEach((o, i) => line(` ${c.orange(String(i + 1))}. ${o.label}`));
3302
+ line();
3303
+ const pick = (await withReadline((ask) => ask(` Select [1-${options.length}, default 1]: `))).trim();
3304
+ const chosen = options[pick ? parseInt(pick, 10) - 1 : 0];
3305
+ if (!chosen) {
3306
+ line(c.red("\n Invalid choice. Run `expert` again to retry.\n"));
3307
+ return false;
3308
+ }
3309
+ await chosen.run();
3310
+ return hasCredential(loadConfig());
3190
3311
  }
3191
3312
  async function cmdRun(args) {
3192
3313
  let manual = false;
@@ -3195,6 +3316,7 @@ async function cmdRun(args) {
3195
3316
  if (a === "--manual") manual = true;
3196
3317
  else if (!a.startsWith("-")) dirArg = a;
3197
3318
  }
3319
+ await maybeAutoUpdate(VERSION, loadConfig());
3198
3320
  let workspace;
3199
3321
  try {
3200
3322
  workspace = setWorkspace(dirArg ?? process.cwd());
@@ -3203,7 +3325,16 @@ async function cmdRun(args) {
3203
3325
  process.exitCode = 1;
3204
3326
  return;
3205
3327
  }
3206
- const cfg = loadConfig();
3328
+ let cfg = loadConfig();
3329
+ if (!hasCredential(cfg)) {
3330
+ const ready = await onboard();
3331
+ if (!ready) {
3332
+ process.exitCode = 1;
3333
+ return;
3334
+ }
3335
+ cfg = loadConfig();
3336
+ applyConfigToEnv(cfg);
3337
+ }
3207
3338
  const model = resolveModelClient(cfg);
3208
3339
  if (!model) {
3209
3340
  process.exitCode = 1;
@@ -3221,8 +3352,10 @@ function printUsage() {
3221
3352
  line(" expert login | logout managed sign-in (no API key needed)");
3222
3353
  line(" expert whoami show sign-in + active inference lane");
3223
3354
  line(" expert config [set <k> <v>] show or edit config");
3355
+ line(" expert update update to the latest version now");
3224
3356
  line(" expert --version | --help");
3225
3357
  line();
3358
+ line(c.dim(" Expert Code keeps itself up to date automatically (disable: config set autoUpdate false)."));
3226
3359
  line(c.dim(" Inference: signed in \u2192 hosted backend; otherwise your own key (BYOK)."));
3227
3360
  line(c.dim(" Get started: `expert setup` (BYOK) or `expert login` (managed), then `expert`."));
3228
3361
  line();
@@ -3238,7 +3371,7 @@ function printMissingKey(provider) {
3238
3371
  line(c.dim(` \u2026or set ${provider.toUpperCase()}_API_KEY in your environment for this session.`));
3239
3372
  line();
3240
3373
  }
3241
- var SUBCOMMANDS = /* @__PURE__ */ new Set(["setup", "login", "logout", "whoami", "config"]);
3374
+ var SUBCOMMANDS = /* @__PURE__ */ new Set(["setup", "login", "logout", "whoami", "config", "update"]);
3242
3375
  async function main() {
3243
3376
  const argv = process.argv.slice(2);
3244
3377
  if (argv.includes("--version") || argv.includes("-v")) {
@@ -3265,6 +3398,8 @@ async function main() {
3265
3398
  return cmdWhoami(cfg);
3266
3399
  case "config":
3267
3400
  return cmdConfig(rest, cfg);
3401
+ case "update":
3402
+ return forceUpdate(VERSION);
3268
3403
  }
3269
3404
  }
3270
3405
  return cmdRun(argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-launchpad-v1/expert-code",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Expert Code — an autonomous coding agent in your terminal. BYOK (your own AI provider key) or managed hosted sign-in.",
5
5
  "type": "module",
6
6
  "bin": {