aether-code 0.43.1 → 0.43.3

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,12 +1,10 @@
1
- // Startup update check + auto-update. On every REPL launch, checks the npm
2
- // registry and silently installs the latest version in the background if one
3
- // exists. Never throws, bounded by a short timeout so it can't slow startup.
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
4
 
5
- import { readFileSync, writeFileSync, existsSync } from "node:fs";
5
+ import { readFileSync } from "node:fs";
6
6
  import { fileURLToPath } from "node:url";
7
7
  import { dirname, join } from "node:path";
8
- import { tmpdir } from "node:os";
9
- import { spawn } from "node:child_process";
10
8
  import { c } from "./render.js";
11
9
 
12
10
  export function currentVersion() {
@@ -29,65 +27,10 @@ export function cmpVersion(a, b) {
29
27
  return 0;
30
28
  }
31
29
 
32
- const COOLDOWN_FILE = join(tmpdir(), "aether-update-ts");
33
- const COOLDOWN_MS = 3600_000; // 1 hour
34
-
35
- /**
36
- * Check for updates. If a newer version exists on npm, spawn a background
37
- * `npm install -g` to auto-install it. Returns a one-line status message
38
- * or null. Cooldown: only checks once per hour.
39
- */
40
- export async function autoUpdate({ fetchImpl = fetch, timeoutMs = 2000 } = {}) {
41
- const current = currentVersion();
42
- if (!current) return null;
43
-
44
- // Skip if we checked less than 1 hour ago
45
- try {
46
- const ts = parseInt(readFileSync(COOLDOWN_FILE, "utf8"), 10);
47
- if (Date.now() - ts < COOLDOWN_MS) return null;
48
- } catch { /* no file or parse error — check now */ }
49
-
50
- try {
51
- const ac = new AbortController();
52
- const t = setTimeout(() => ac.abort(), timeoutMs);
53
- let res;
54
- try {
55
- res = await fetchImpl("https://registry.npmjs.org/aether-code/latest", { signal: ac.signal });
56
- } finally {
57
- clearTimeout(t);
58
- }
59
- if (!res || !res.ok) return null;
60
- const latest = (await res.json())?.version;
61
-
62
- // Write cooldown regardless of whether an update is available
63
- try { writeFileSync(COOLDOWN_FILE, String(Date.now())); } catch { /* ignore */ }
64
-
65
- if (!latest || cmpVersion(latest, current) <= 0) return null;
66
-
67
- // Spawn background npm install — detached so it doesn't block the CLI.
68
- // On Windows, `npm` is a cmd script, so shell:true is required.
69
- const child = spawn("npm", ["install", "-g", `aether-code@${latest}`], {
70
- detached: true,
71
- stdio: "ignore",
72
- shell: true,
73
- windowsHide: true,
74
- });
75
- child.unref();
76
-
77
- return (
78
- c.cyan("↑ auto-updating ") +
79
- c.gray(current) + c.gray(" → ") + c.bold(c.green(latest)) +
80
- c.gray(" (background — applies next launch)")
81
- );
82
- } catch {
83
- /* offline / aborted / parse error — stay silent */
84
- }
85
- return null;
86
- }
87
-
88
30
  /**
89
- * Legacy nudge-only check (kept for the test suite). Same as before: returns
90
- * a one-line "update available" string or null.
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.
91
34
  */
92
35
  export async function checkForUpdate({ fetchImpl = fetch, timeoutMs = 2000 } = {}) {
93
36
  const current = currentVersion();
package/src/version.js ADDED
@@ -0,0 +1,15 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ let cached;
6
+ export function getVersion() {
7
+ if (cached) return cached;
8
+ try {
9
+ const pkgPath = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "package.json");
10
+ cached = JSON.parse(fs.readFileSync(pkgPath, "utf8")).version || "0";
11
+ } catch {
12
+ cached = "0";
13
+ }
14
+ return cached;
15
+ }
@@ -1,182 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * postinstall — auto-fix PATH on Windows so `aether` works immediately
4
- * after `npm install -g aether-code`.
5
- *
6
- * On non-Windows or when PATH already contains the npm bin dir, this is a no-op.
7
- */
8
-
9
- import { execFileSync } from "node:child_process";
10
- import process from "node:process";
11
- import path from "node:path";
12
- import fs from "node:fs";
13
-
14
- const IS_WIN = process.platform === "win32";
15
- const IS_GLOBAL = isGlobalInstall();
16
-
17
- function run(cmd, args) {
18
- return execFileSync(cmd, args, {
19
- encoding: "utf8",
20
- timeout: 15_000,
21
- windowsHide: true,
22
- }).trim();
23
- }
24
-
25
- function isGlobalInstall() {
26
- if (process.env.npm_config_global === "true") return true;
27
-
28
- try {
29
- const prefix = run("npm", ["config", "get", "prefix"]);
30
- const selfDir = path.resolve(process.cwd());
31
- return selfDir.toLowerCase().startsWith(prefix.toLowerCase());
32
- } catch {
33
- return false;
34
- }
35
- }
36
-
37
- function getNpmBinDir() {
38
- try {
39
- const prefix = run("npm", ["config", "get", "prefix"]);
40
- // On Windows binaries live directly in the prefix dir
41
- return IS_WIN ? prefix : path.join(prefix, "bin");
42
- } catch {
43
- return null;
44
- }
45
- }
46
-
47
- function isInPath(dir) {
48
- if (!dir) return false;
49
- const sep = IS_WIN ? ";" : ":";
50
- const pathDirs = (process.env.PATH || "").split(sep).map((d) => {
51
- try {
52
- return path.resolve(d).toLowerCase();
53
- } catch {
54
- return d.toLowerCase();
55
- }
56
- });
57
- return pathDirs.includes(path.resolve(dir).toLowerCase());
58
- }
59
-
60
- function readWindowsUserPath() {
61
- try {
62
- return run("powershell.exe", [
63
- "-NoProfile",
64
- "-Command",
65
- "[Environment]::GetEnvironmentVariable('Path', 'User')",
66
- ]);
67
- } catch {
68
- return "";
69
- }
70
- }
71
-
72
- function writeWindowsUserPath(newPath) {
73
- run("powershell.exe", [
74
- "-NoProfile",
75
- "-Command",
76
- `[Environment]::SetEnvironmentVariable('Path', '${newPath.replace(/'/g, "''")}', 'User')`,
77
- ]);
78
- }
79
-
80
- function addToWindowsUserPath(dir) {
81
- try {
82
- const currentUserPath = readWindowsUserPath();
83
-
84
- const pathEntries = currentUserPath
85
- .split(";")
86
- .filter(Boolean)
87
- .map((p) => {
88
- try {
89
- return path.resolve(p).toLowerCase();
90
- } catch {
91
- return p.toLowerCase();
92
- }
93
- });
94
-
95
- if (pathEntries.includes(path.resolve(dir).toLowerCase())) {
96
- return "already_set";
97
- }
98
-
99
- const newPath = currentUserPath ? `${currentUserPath};${dir}` : dir;
100
- writeWindowsUserPath(newPath);
101
- return "added";
102
- } catch {
103
- return "failed";
104
- }
105
- }
106
-
107
- function verifyBinaryExists(binDir) {
108
- if (!binDir) return false;
109
- const shimName = IS_WIN ? "aether.cmd" : "aether";
110
- return fs.existsSync(path.join(binDir, shimName));
111
- }
112
-
113
- // ── ANSI helpers ────────────────────────────────────────────────────────────────
114
-
115
- const RESET = "\x1b[0m";
116
- const GREEN = "\x1b[32m";
117
- const YELLOW = "\x1b[33m";
118
- const CYAN = "\x1b[36m";
119
- const BOLD = "\x1b[1m";
120
- const DIM = "\x1b[2m";
121
-
122
- function banner(lines) {
123
- console.log("");
124
- for (const l of lines) console.log(l);
125
- console.log("");
126
- }
127
-
128
- // ── main ────────────────────────────────────────────────────────────────────────
129
-
130
- function main() {
131
- if (!IS_GLOBAL) return;
132
-
133
- const binDir = getNpmBinDir();
134
- if (!binDir) return;
135
-
136
- // Already good — nothing to do
137
- if (isInPath(binDir) && verifyBinaryExists(binDir)) return;
138
-
139
- if (IS_WIN && !isInPath(binDir)) {
140
- const result = addToWindowsUserPath(binDir);
141
-
142
- if (result === "added") {
143
- banner([
144
- `${GREEN}${BOLD} ✔ aether${RESET}${GREEN} has been added to your PATH automatically.${RESET}`,
145
- `${YELLOW} ⚡ Restart your terminal${RESET}${DIM}, then run:${RESET}`,
146
- `${CYAN} aether${RESET}`,
147
- ]);
148
- } else if (result === "already_set") {
149
- banner([
150
- `${GREEN}${BOLD} ✔ aether${RESET}${GREEN} is installed.${RESET}`,
151
- `${YELLOW} ⚡ Restart your terminal${RESET}${DIM}, then run:${RESET}`,
152
- `${CYAN} aether${RESET}`,
153
- ]);
154
- } else {
155
- banner([
156
- `${GREEN}${BOLD} ✔ aether${RESET}${GREEN} is installed but your PATH needs updating.${RESET}`,
157
- `${YELLOW} Run this once to fix it:${RESET}`,
158
- ``,
159
- `${CYAN} powershell -Command "[Environment]::SetEnvironmentVariable('Path', $env:Path + ';${binDir}', 'User')"${RESET}`,
160
- ``,
161
- `${DIM} Then restart your terminal and run: ${RESET}${CYAN}aether${RESET}`,
162
- ]);
163
- }
164
- return;
165
- }
166
-
167
- if (!IS_WIN && !isInPath(binDir)) {
168
- const shell = process.env.SHELL || "/bin/bash";
169
- const rcFile = shell.includes("zsh") ? "~/.zshrc" : "~/.bashrc";
170
-
171
- banner([
172
- `${GREEN}${BOLD} ✔ aether${RESET}${GREEN} is installed but not in your PATH.${RESET}`,
173
- `${YELLOW} Add this to ${rcFile}:${RESET}`,
174
- ``,
175
- `${CYAN} export PATH="${binDir}:$PATH"${RESET}`,
176
- ``,
177
- `${DIM} Then restart your terminal and run: ${RESET}${CYAN}aether${RESET}`,
178
- ]);
179
- }
180
- }
181
-
182
- main();