nemu-cli 1.1.0 → 1.2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.0
4
+
5
+ The CLI tells you when a newer version is out: "There is a new version available (1.2.0 -> 1.3.0).
6
+ Do you want to upgrade?" Saying yes installs it with npm. It asks at most once a day, waits at most
7
+ 1.5 seconds for the registry, and stays silent in hooks, the MCP bridge, `--json` output, scripts
8
+ and CI. `nemu update` checks right away; `nemu update --yes` installs without asking. Set
9
+ `NEMU_NO_UPDATE_CHECK=1` to turn the check off.
10
+
3
11
  ## 1.1.0
4
12
 
5
13
  Nemu Context for coding agents. `nemu setup claude` (aliases `cc`, `claude-code`) and
package/README.md CHANGED
@@ -159,6 +159,7 @@ the question.
159
159
  | `nemu context projects` / `export --out file` | List projects, or export everything as JSON |
160
160
  | `nemu status` | Sign in, this device, global install, and each client's setup |
161
161
  | `nemu uninstall [claude\|codex\|all]` | Remove exactly what setup added |
162
+ | `nemu update [--yes]` | Check for a newer version and install it. The CLI also asks by itself, at most once a day; `NEMU_NO_UPDATE_CHECK=1` turns that off |
162
163
  | `nemu token [--header]` | Print a fresh access token |
163
164
 
164
165
  A project is recognised by its first git commit, so the same repository shares notes on every machine
package/dist/config.js CHANGED
@@ -20,6 +20,10 @@ const settings_schema = z.object({
20
20
  .optional(),
21
21
  device_api_url: z.string().url().optional(),
22
22
  reports: z.boolean().default(true),
23
+ update_checked_at: z.number().optional(),
24
+ update_latest: z.string().max(64).optional(),
25
+ update_declined_version: z.string().max(64).optional(),
26
+ update_declined_at: z.number().optional(),
23
27
  });
24
28
  export function api_url() {
25
29
  return (process.env.NEMU_API_URL ?? DEFAULT_API_URL).replace(/\/+$/, "");
package/dist/index.js CHANGED
@@ -17,6 +17,7 @@ import { context } from "./commands/context.js";
17
17
  import { config_command } from "./commands/settings.js";
18
18
  import { client_command } from "./commands/client.js";
19
19
  import { send_report } from "./report.js";
20
+ import { maybe_offer_update, update_command } from "./update.js";
20
21
  import { CliError } from "./errors.js";
21
22
  import { VERSION } from "./version.js";
22
23
  import { bold, dim, fail, out } from "./ui.js";
@@ -52,6 +53,7 @@ const COMMANDS = {
52
53
  hook,
53
54
  context,
54
55
  config: config_command,
56
+ update: update_command,
55
57
  };
56
58
  const HELP = `
57
59
  ${bold("nemu")} ${dim(VERSION)}
@@ -75,6 +77,7 @@ const HELP = `
75
77
  uninstall [claude|codex|all] Remove what setup added
76
78
  token [--header] Print a fresh access token
77
79
  config get | set reports on|off Error reports sent after a failure
80
+ update [--yes] Check for a new version and install it
78
81
 
79
82
  ${bold("Account")}
80
83
  login [--force] [--no-browser] Sign in with the device flow
@@ -179,6 +182,7 @@ async function main() {
179
182
  usage();
180
183
  return 0;
181
184
  }
185
+ await maybe_offer_update(command);
182
186
  return await handler(args);
183
187
  }
184
188
  async function report_failure(error) {
package/dist/update.js ADDED
@@ -0,0 +1,141 @@
1
+ import { z } from "zod";
2
+ import { read_settings, update_settings } from "./config.js";
3
+ import { run, which } from "./system.js";
4
+ import { confirm, dim, fail, is_interactive, out, spinner, success } from "./ui.js";
5
+ import { emit, is_json_mode } from "./output.js";
6
+ import { bool_flag } from "./args.js";
7
+ import { VERSION } from "./version.js";
8
+ const PACKAGE = "nemu-cli";
9
+ const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
10
+ const FETCH_TIMEOUT_MS = 1500;
11
+ const QUIET_COMMANDS = new Set(["hook", "mcp", "token", "update"]);
12
+ const SEMVER = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/;
13
+ const registry_schema = z.object({ version: z.string().regex(SEMVER) });
14
+ function registry_url() {
15
+ const base = (process.env.NEMU_REGISTRY_URL ?? "https://registry.npmjs.org").replace(/\/+$/, "");
16
+ return `${base}/${PACKAGE}/latest`;
17
+ }
18
+ export function is_newer(candidate, current) {
19
+ const next = SEMVER.exec(candidate);
20
+ const now = SEMVER.exec(current);
21
+ if (next === null || now === null)
22
+ return false;
23
+ for (let i = 1; i <= 3; i += 1) {
24
+ const difference = Number(next[i]) - Number(now[i]);
25
+ if (difference !== 0)
26
+ return difference > 0;
27
+ }
28
+ if (next[4] === undefined && now[4] !== undefined)
29
+ return true;
30
+ return false;
31
+ }
32
+ export async function fetch_latest() {
33
+ try {
34
+ const response = await fetch(registry_url(), {
35
+ headers: { accept: "application/json" },
36
+ signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
37
+ });
38
+ if (!response.ok)
39
+ return null;
40
+ const parsed = registry_schema.safeParse(await response.json());
41
+ return parsed.success ? parsed.data.version : null;
42
+ }
43
+ catch {
44
+ return null;
45
+ }
46
+ }
47
+ export async function latest_version(force, now = Date.now()) {
48
+ const settings = await read_settings();
49
+ const fresh = settings.update_checked_at !== undefined && now - settings.update_checked_at < CHECK_INTERVAL_MS;
50
+ if (!force && fresh && settings.update_latest !== undefined)
51
+ return settings.update_latest;
52
+ const latest = await fetch_latest();
53
+ await update_settings({
54
+ update_checked_at: now,
55
+ ...(latest !== null ? { update_latest: latest } : {}),
56
+ }).catch(() => undefined);
57
+ return latest ?? (fresh ? (settings.update_latest ?? null) : null);
58
+ }
59
+ function is_ephemeral_run() {
60
+ const script = (process.argv[1] ?? "").replaceAll("\\", "/");
61
+ return script.includes("/_npx/") || script.includes("/.bun/install/cache/");
62
+ }
63
+ function should_check(command) {
64
+ if (QUIET_COMMANDS.has(command))
65
+ return false;
66
+ if (is_json_mode() || !is_interactive())
67
+ return false;
68
+ if (process.env.CI !== undefined || process.env.NEMU_NO_UPDATE_CHECK === "1")
69
+ return false;
70
+ return !is_ephemeral_run();
71
+ }
72
+ async function install(version) {
73
+ const command = `npm i -g ${PACKAGE}@${version}`;
74
+ if ((await which("npm")) === null) {
75
+ fail(`npm was not found. Update by hand: ${command}`);
76
+ return false;
77
+ }
78
+ const progress = spinner(`Installing ${PACKAGE} ${version}`);
79
+ const result = await run("npm", ["install", "-g", `${PACKAGE}@${version}`], { timeout_ms: 180_000 });
80
+ progress.stop();
81
+ if (result.code !== 0) {
82
+ fail(`The update did not install. Run it yourself: ${command}`);
83
+ return false;
84
+ }
85
+ success(`Updated to ${version}.`);
86
+ return true;
87
+ }
88
+ async function offer(latest, now) {
89
+ out(` There is a new version available (${VERSION} -> ${latest}).`);
90
+ const accepted = await confirm("Do you want to upgrade?", true);
91
+ if (!accepted) {
92
+ await update_settings({ update_declined_version: latest, update_declined_at: now }).catch(() => undefined);
93
+ out(dim(` Later: nemu update`));
94
+ return false;
95
+ }
96
+ return install(latest);
97
+ }
98
+ export async function maybe_offer_update(command, now = Date.now()) {
99
+ try {
100
+ if (!should_check(command))
101
+ return;
102
+ const latest = await latest_version(false, now);
103
+ if (latest === null || !is_newer(latest, VERSION))
104
+ return;
105
+ const settings = await read_settings();
106
+ const declined_recently = settings.update_declined_version === latest &&
107
+ settings.update_declined_at !== undefined &&
108
+ now - settings.update_declined_at < CHECK_INTERVAL_MS;
109
+ if (declined_recently)
110
+ return;
111
+ if (await offer(latest, now))
112
+ out();
113
+ }
114
+ catch {
115
+ return;
116
+ }
117
+ }
118
+ export async function update_command(args) {
119
+ const latest = await latest_version(true);
120
+ if (latest === null) {
121
+ fail("Could not reach the npm registry. Try again, or run: npm i -g nemu-cli@latest");
122
+ return 1;
123
+ }
124
+ const available = is_newer(latest, VERSION);
125
+ if (is_json_mode()) {
126
+ emit({ current: VERSION, latest, update_available: available });
127
+ return 0;
128
+ }
129
+ if (!available) {
130
+ out(` nemu ${VERSION} is the latest version.`);
131
+ return 0;
132
+ }
133
+ if (bool_flag(args, "yes", "y"))
134
+ return (await install(latest)) ? 0 : 1;
135
+ if (!is_interactive()) {
136
+ out(` There is a new version available (${VERSION} -> ${latest}). Run: npm i -g ${PACKAGE}@${latest}`);
137
+ return 0;
138
+ }
139
+ await offer(latest, Date.now());
140
+ return 0;
141
+ }
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "1.1.0";
1
+ export const VERSION = "1.2.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nemu-cli",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Command line access to Nemu, and portable project memory for Claude Code, Codex and any MCP client.",
5
5
  "bin": {
6
6
  "nemu": "./dist/index.js"