@withone/cli 1.12.7 → 1.12.9

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/dist/index.js +66 -10
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4406,21 +4406,57 @@ validation rules, and platform-specific details.
4406
4406
  // src/commands/update.ts
4407
4407
  import { createRequire } from "module";
4408
4408
  import { spawn as spawn2 } from "child_process";
4409
+ import { readFileSync, writeFileSync, mkdirSync } from "fs";
4410
+ import { homedir } from "os";
4411
+ import { join } from "path";
4409
4412
  var require2 = createRequire(import.meta.url);
4410
4413
  var { version: currentVersion } = require2("../package.json");
4411
- async function updateCommand() {
4412
- const s = createSpinner();
4413
- s.start("Checking for updates...");
4414
- let latestVersion;
4414
+ var CACHE_PATH = join(homedir(), ".one", "update-check.json");
4415
+ var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
4416
+ async function fetchLatestVersion() {
4415
4417
  try {
4416
4418
  const res = await fetch("https://registry.npmjs.org/@withone/cli/latest");
4417
- if (!res.ok) {
4418
- s.stop("");
4419
- error(`Failed to check for updates (HTTP ${res.status})`);
4420
- }
4419
+ if (!res.ok) return null;
4421
4420
  const data = await res.json();
4422
- latestVersion = data.version;
4423
- } catch (err) {
4421
+ return data.version;
4422
+ } catch {
4423
+ return null;
4424
+ }
4425
+ }
4426
+ function readCache() {
4427
+ try {
4428
+ return JSON.parse(readFileSync(CACHE_PATH, "utf8"));
4429
+ } catch {
4430
+ return null;
4431
+ }
4432
+ }
4433
+ function writeCache(latestVersion) {
4434
+ try {
4435
+ mkdirSync(join(homedir(), ".one"), { recursive: true });
4436
+ writeFileSync(CACHE_PATH, JSON.stringify({ lastCheck: Date.now(), latestVersion }));
4437
+ } catch {
4438
+ }
4439
+ }
4440
+ async function checkLatestVersion() {
4441
+ const version2 = await fetchLatestVersion();
4442
+ if (version2) writeCache(version2);
4443
+ return version2;
4444
+ }
4445
+ async function checkLatestVersionCached() {
4446
+ const cache = readCache();
4447
+ if (cache && Date.now() - cache.lastCheck < CHECK_INTERVAL_MS) {
4448
+ return cache.latestVersion;
4449
+ }
4450
+ return checkLatestVersion();
4451
+ }
4452
+ function getCurrentVersion() {
4453
+ return currentVersion;
4454
+ }
4455
+ async function updateCommand() {
4456
+ const s = createSpinner();
4457
+ s.start("Checking for updates...");
4458
+ const latestVersion = await checkLatestVersion();
4459
+ if (!latestVersion) {
4424
4460
  s.stop("");
4425
4461
  error("Failed to check for updates \u2014 could not reach npm registry");
4426
4462
  }
@@ -4495,11 +4531,31 @@ program.name("one").option("--agent", "Machine-readable JSON output (no colors,
4495
4531
 
4496
4532
  Platform names are always kebab-case (e.g. hub-spot, ship-station, google-calendar).
4497
4533
  Run 'one platforms' to browse all 200+ available platforms.`).version(version);
4534
+ var updateCheckPromise;
4498
4535
  program.hook("preAction", (thisCommand) => {
4499
4536
  const opts = program.opts();
4500
4537
  if (opts.agent) {
4501
4538
  setAgentMode(true);
4502
4539
  }
4540
+ const commandName = thisCommand.args?.[0];
4541
+ if (commandName !== "update") {
4542
+ updateCheckPromise = checkLatestVersionCached();
4543
+ }
4544
+ });
4545
+ program.hook("postAction", async () => {
4546
+ if (!updateCheckPromise) return;
4547
+ const latestVersion = await updateCheckPromise;
4548
+ if (!latestVersion) return;
4549
+ const current = getCurrentVersion();
4550
+ if (current === latestVersion) return;
4551
+ if (isAgentMode()) {
4552
+ process.stderr.write(`
4553
+ Update available: v${current} \u2192 v${latestVersion}. Run "one update" to upgrade.
4554
+ `);
4555
+ } else {
4556
+ console.log(`
4557
+ \x1B[33mUpdate available: v${current} \u2192 v${latestVersion}. Run \x1B[1mone update\x1B[22m to upgrade.\x1B[0m`);
4558
+ }
4503
4559
  });
4504
4560
  program.command("init").description("Set up One and install MCP to your AI agents").option("-y, --yes", "Skip confirmations").option("-g, --global", "Install MCP globally (available in all projects)").option("-p, --project", "Install MCP for this project only (creates .mcp.json)").action(async (options) => {
4505
4561
  await initCommand(options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@withone/cli",
3
- "version": "1.12.7",
3
+ "version": "1.12.9",
4
4
  "description": "CLI for managing One",
5
5
  "type": "module",
6
6
  "files": [