aether-code 0.31.0 → 0.32.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.
@@ -1,60 +1,60 @@
1
- // Startup update check — like Claude Code / npm itself nudging you when a newer
2
- // version is published. Never throws, bounded by a short timeout so it can't
3
- // slow or block startup; silent when offline or already current.
4
-
5
- import { readFileSync } from "node:fs";
6
- import { fileURLToPath } from "node:url";
7
- import { dirname, join } from "node:path";
8
- import { c } from "./render.js";
9
-
10
- export function currentVersion() {
11
- try {
12
- const p = join(dirname(fileURLToPath(import.meta.url)), "..", "package.json");
13
- return JSON.parse(readFileSync(p, "utf8")).version || null;
14
- } catch {
15
- return null;
16
- }
17
- }
18
-
19
- // Compare two "x.y.z" strings. Returns >0 if a is newer than b.
20
- export function cmpVersion(a, b) {
21
- const pa = String(a).split(".").map(Number);
22
- const pb = String(b).split(".").map(Number);
23
- for (let i = 0; i < 3; i++) {
24
- const d = (pa[i] || 0) - (pb[i] || 0);
25
- if (d !== 0) return d;
26
- }
27
- return 0;
28
- }
29
-
30
- /**
31
- * Resolve a one-line "update available" nudge if the npm registry has a newer
32
- * version than the installed one — otherwise null. Bounded to ~2s; any failure
33
- * (offline, timeout, registry hiccup) resolves to null silently.
34
- */
35
- export async function checkForUpdate({ fetchImpl = fetch, timeoutMs = 2000 } = {}) {
36
- const current = currentVersion();
37
- if (!current) return null;
38
- try {
39
- const ac = new AbortController();
40
- const t = setTimeout(() => ac.abort(), timeoutMs);
41
- let res;
42
- try {
43
- res = await fetchImpl("https://registry.npmjs.org/aether-code/latest", { signal: ac.signal });
44
- } finally {
45
- clearTimeout(t);
46
- }
47
- if (!res || !res.ok) return null;
48
- const latest = (await res.json())?.version;
49
- if (latest && cmpVersion(latest, current) > 0) {
50
- return (
51
- c.yellow("update available: ") +
52
- c.gray(current) + " -> " + c.bold(c.green(latest)) +
53
- c.gray(" · run ") + c.cyan("npm i -g aether-code@latest")
54
- );
55
- }
56
- } catch {
57
- /* offline / aborted / parse error — stay silent */
58
- }
59
- return null;
60
- }
1
+ // Startup update check — like Claude Code / npm itself nudging you when a newer
2
+ // version is published. Never throws, bounded by a short timeout so it can't
3
+ // slow or block startup; silent when offline or already current.
4
+
5
+ import { readFileSync } from "node:fs";
6
+ import { fileURLToPath } from "node:url";
7
+ import { dirname, join } from "node:path";
8
+ import { c } from "./render.js";
9
+
10
+ export function currentVersion() {
11
+ try {
12
+ const p = join(dirname(fileURLToPath(import.meta.url)), "..", "package.json");
13
+ return JSON.parse(readFileSync(p, "utf8")).version || null;
14
+ } catch {
15
+ return null;
16
+ }
17
+ }
18
+
19
+ // Compare two "x.y.z" strings. Returns >0 if a is newer than b.
20
+ export function cmpVersion(a, b) {
21
+ const pa = String(a).split(".").map(Number);
22
+ const pb = String(b).split(".").map(Number);
23
+ for (let i = 0; i < 3; i++) {
24
+ const d = (pa[i] || 0) - (pb[i] || 0);
25
+ if (d !== 0) return d;
26
+ }
27
+ return 0;
28
+ }
29
+
30
+ /**
31
+ * Resolve a one-line "update available" nudge if the npm registry has a newer
32
+ * version than the installed one — otherwise null. Bounded to ~2s; any failure
33
+ * (offline, timeout, registry hiccup) resolves to null silently.
34
+ */
35
+ export async function checkForUpdate({ fetchImpl = fetch, timeoutMs = 2000 } = {}) {
36
+ const current = currentVersion();
37
+ if (!current) return null;
38
+ try {
39
+ const ac = new AbortController();
40
+ const t = setTimeout(() => ac.abort(), timeoutMs);
41
+ let res;
42
+ try {
43
+ res = await fetchImpl("https://registry.npmjs.org/aether-code/latest", { signal: ac.signal });
44
+ } finally {
45
+ clearTimeout(t);
46
+ }
47
+ if (!res || !res.ok) return null;
48
+ const latest = (await res.json())?.version;
49
+ if (latest && cmpVersion(latest, current) > 0) {
50
+ return (
51
+ c.yellow("update available: ") +
52
+ c.gray(current) + " -> " + c.bold(c.green(latest)) +
53
+ c.gray(" · run ") + c.cyan("npm i -g aether-code@latest")
54
+ );
55
+ }
56
+ } catch {
57
+ /* offline / aborted / parse error — stay silent */
58
+ }
59
+ return null;
60
+ }