viewable-one 0.12.5 → 0.12.6

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
@@ -13,6 +13,28 @@ package.
13
13
 
14
14
  ## [Unreleased]
15
15
 
16
+ ## [0.12.6] - 2026-11-10
17
+
18
+ ### Fixed
19
+
20
+ - `viewable update`, the Update button in More and Remove act on the copy of
21
+ Viewable that is really installed (#5305). When a login shell starts an
22
+ nvm-installed Viewable with a system Node, the install went to the wrong
23
+ folder. The shared npm resolver in `lib/npm-command.mjs` now pins `--prefix`
24
+ to the installed package's prefix and uses that prefix's own Node and npm
25
+ when present; self-uninstall uses the same resolver. A custom prefix keeps
26
+ its destination, Volta keeps its manager path, and local and npx copies
27
+ update as before. Windows runs `npm-cli.js` without a command shell. A
28
+ permission error keeps its real cause and drops the old running-Node advice.
29
+ - A project folder named `lib` is no longer taken for a global install (#5403).
30
+ `globalPackageDir` called any `<x>/lib/node_modules/viewable-one` global, so
31
+ Update could install into that project and Remove could `npm uninstall -g`
32
+ its copy. On posix a copy is now global only when `<prefix>/bin/viewable`
33
+ exists and resolves to this very file, the shim npm writes on a global
34
+ install. Windows rules are unchanged.
35
+ - Login, logout, doctor, init and uninstall messages show the actual credential
36
+ and registry paths when the computer home is overridden (#5398).
37
+
16
38
  ## [0.12.5] - 2026-11-10
17
39
 
18
40
  ### Fixed
package/glytch.mjs CHANGED
@@ -40,7 +40,7 @@ import { resolve } from "node:path";
40
40
  import { homedir } from "node:os";
41
41
  import { heading, checkSections, summary, homeNotice, wrap, bold, colorEnabled, dim, fail, hint, ok, step, warn, warnRow } from "./lib/cli-output.mjs";
42
42
 
43
- import { login as hostedLogin, logout as hostedLogout } from "./lib/auth.mjs";
43
+ import { authDisplayPath, login as hostedLogin, logout as hostedLogout } from "./lib/auth.mjs";
44
44
  import { detectAgents, detectionLines, execProbe } from "./lib/detect.mjs";
45
45
  import { allGreen, doctorRows } from "./lib/doctor.mjs";
46
46
  import { loginDaemon, noDaemonInstall } from "./lib/logindaemon.mjs";
@@ -384,7 +384,7 @@ async function login() {
384
384
  say("");
385
385
  say(ok(`Signed in to ${stored.appUrl}.`, { color }));
386
386
  say(`Board tools on your computer now reach ${stored.mcpUrl}: no app tab, no token to paste.`);
387
- say(`Saved to ~/.glytch/auth.json (mode 0600), or GLYTCH_HOME when that is set.`);
387
+ say(`Saved to ${authDisplayPath()} (mode 0600).`);
388
388
  return 0;
389
389
  }
390
390
 
@@ -392,7 +392,7 @@ async function logout() {
392
392
  const color = colorEnabled();
393
393
  say(heading("Viewable · Sign out", { color }));
394
394
  const removed = await hostedLogout();
395
- say(removed ? ok("Signed out. ~/.glytch/auth.json removed.", { color }) : warn("Not signed in, nothing to remove.", { color }));
395
+ say(removed ? ok(`Signed out. ${authDisplayPath()} removed.`, { color }) : warn("Not signed in, nothing to remove.", { color }));
396
396
  return 0;
397
397
  }
398
398
 
package/lib/auth.mjs CHANGED
@@ -49,7 +49,7 @@ import { createServer } from "node:http";
49
49
  import { spawn } from "node:child_process";
50
50
  import { join } from "node:path";
51
51
 
52
- import { viewableHome } from "./registry.mjs";
52
+ import { viewableHome, viewableDisplayPath } from "./registry.mjs";
53
53
  import { writeFileAtomic } from "./atomic.mjs";
54
54
  import { movedAuth } from "./retired-address.mjs";
55
55
 
@@ -94,6 +94,11 @@ const EXCHANGE_TIMEOUT_MS = 60_000;
94
94
 
95
95
  const authFilePath = (env = process.env) => join(viewableHome(env), "auth.json");
96
96
 
97
+ /** Match the storage resolver, preserving the familiar default-home spelling. */
98
+ export function authDisplayPath(env = process.env) {
99
+ return viewableDisplayPath(env, "auth.json");
100
+ }
101
+
97
102
  const trimTrailingSlash = (s) => String(s).replace(/\/+$/, "");
98
103
 
99
104
  /** The app origin this run should use: the explicit argument, then
@@ -1329,9 +1334,9 @@ export async function login({
1329
1334
  await writeAuthFile(result, env);
1330
1335
  log(
1331
1336
  keepsOAuth
1332
- ? "VIEWABLE_BOARD_TOKEN is set - saved it to ~/.glytch/auth.json as a personal access token, keeping the " +
1337
+ ? `VIEWABLE_BOARD_TOKEN is set - saved it to ${authDisplayPath(env)} as a personal access token, keeping the ` +
1333
1338
  "OAuth sign-in already there beside it. No browser needed."
1334
- : "VIEWABLE_BOARD_TOKEN is set - saved it to ~/.glytch/auth.json as a personal access token. No browser needed.",
1339
+ : `VIEWABLE_BOARD_TOKEN is set - saved it to ${authDisplayPath(env)} as a personal access token. No browser needed.`,
1335
1340
  );
1336
1341
  return result;
1337
1342
  }
package/lib/doctor.mjs CHANGED
@@ -46,7 +46,7 @@ import { projectMcpServerKey } from "./project-mcp.mjs";
46
46
  import { syncFolder } from "./sync.mjs";
47
47
  import { readAgentSelection } from "./agent-selection.mjs";
48
48
  import { compareVersions, latestFromNpm, packageVersion, verifyInstalledCli } from "./update.mjs";
49
- import { PERSONAL_TOKEN_REJECTED_HINT, REAUTH_REQUIRED_HINT, hostedStatus } from "./auth.mjs";
49
+ import { authDisplayPath, PERSONAL_TOKEN_REJECTED_HINT, REAUTH_REQUIRED_HINT, hostedStatus } from "./auth.mjs";
50
50
  import { presence as hostedPresence } from "./runnerApi.mjs";
51
51
 
52
52
  // `row` is imported from cli-output.mjs (brief 31 review, 2026-09-12 - it
@@ -377,7 +377,7 @@ export async function doctorRows(
377
377
  "board sign-in",
378
378
  false,
379
379
  "rejected",
380
- `the personal token in ~/.glytch/auth.json was rejected by the board${boardAuth.deadSince ? ` (since ${boardAuth.deadSince})` : ""}`,
380
+ `the personal token in ${authDisplayPath(env)} was rejected by the board${boardAuth.deadSince ? ` (since ${boardAuth.deadSince})` : ""}`,
381
381
  PERSONAL_TOKEN_REJECTED_HINT,
382
382
  )
383
383
  : row(
@@ -385,7 +385,7 @@ export async function doctorRows(
385
385
  "board sign-in",
386
386
  false,
387
387
  "expired",
388
- `the credential in ~/.glytch/auth.json was refused by the board${boardAuth.deadSince ? ` (since ${boardAuth.deadSince})` : ""} and cannot be renewed`,
388
+ `the credential in ${authDisplayPath(env)} was refused by the board${boardAuth.deadSince ? ` (since ${boardAuth.deadSince})` : ""} and cannot be renewed`,
389
389
  REAUTH_REQUIRED_HINT,
390
390
  )
391
391
  : boardAuth.signedIn
@@ -410,8 +410,8 @@ export async function doctorRows(
410
410
  (boardAuth.via === "VIEWABLE_BOARD_TOKEN"
411
411
  ? "VIEWABLE_BOARD_TOKEN is set"
412
412
  : boardAuth.via === "personal token"
413
- ? "a personal access token is stored in ~/.glytch/auth.json"
414
- : "~/.glytch/auth.json is there"),
413
+ ? `a personal access token is stored in ${authDisplayPath(env)}`
414
+ : `${authDisplayPath(env)} is there`),
415
415
  )
416
416
  : row(
417
417
  "boardAuth",
@@ -419,7 +419,7 @@ export async function doctorRows(
419
419
  false,
420
420
  "not signed in",
421
421
  "run `viewable login`, or set VIEWABLE_BOARD_TOKEN to a personal access token for a script",
422
- "Run `viewable login`. It opens a browser to sign in and approve, and the credential lands in ~/.glytch/auth.json. Re-running `viewable init` does not do this step.",
422
+ `Run \`viewable login\`. It opens a browser to sign in and approve, and the credential lands in ${authDisplayPath(env)}. Re-running \`viewable init\` does not do this step.`,
423
423
  ),
424
424
  );
425
425
 
@@ -34,7 +34,7 @@
34
34
  // are seams, every test asserts the argv sequence, and NOTHING in the suite
35
35
  // runs claude, codex, opencode or a browser on the machine running it.
36
36
 
37
- import { hostedStatus, login as hostedLogin, readAuthFile } from "./auth.mjs";
37
+ import { authDisplayPath, hostedStatus, login as hostedLogin, readAuthFile } from "./auth.mjs";
38
38
  import { projectMcpServerKey } from "./project-mcp.mjs";
39
39
  import { execProbe, runInteractive } from "./detect.mjs";
40
40
  import { compareVersions } from "./update.mjs";
@@ -209,7 +209,7 @@ export async function signInStep({
209
209
  }
210
210
  try {
211
211
  const stored = await login({ env, log: (line) => log(hint(line, options)) });
212
- return settle("ok", `VIEWABLE_BOARD_TOKEN saved to ~/.glytch/auth.json (${stored.appUrl})`);
212
+ return settle("ok", `VIEWABLE_BOARD_TOKEN saved to ${authDisplayPath(env)} (${stored.appUrl})`);
213
213
  } catch (error) {
214
214
  return settle("fail", error instanceof Error ? error.message : String(error));
215
215
  }
@@ -0,0 +1,68 @@
1
+ // Shared npm targeting for updates and removal. The installed package owns
2
+ // the prefix; env node may have started it with an unrelated Node (#5305).
3
+ import { existsSync, realpathSync } from "node:fs";
4
+ import { posix, win32 } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { runnableCommand } from "./windows-command.mjs";
7
+
8
+ const CLI_PATH = fileURLToPath(new URL("../glytch.mjs", import.meta.url));
9
+
10
+ /** A POSIX prefix owns this copy only when its own bin/viewable shim resolves
11
+ * to this very file. A folder shaped like `<prefix>/lib/node_modules` proves
12
+ * nothing: a project directory named `lib` has the same shape (#5403). */
13
+ function ownsShim(path, prefix, cliPath, { exists, resolvePath }) {
14
+ const shim = path.join(prefix, "bin", "viewable");
15
+ try { return exists(shim) && resolvePath(shim) === cliPath; } catch { return false; }
16
+ }
17
+
18
+ /** Extract the global package directory (formerly in selfUninstall). Never
19
+ * treat a checkout, local dependency or npx cache as a global installation. */
20
+ export function globalPackageDir(cliPath, { platform = process.platform, env = process.env, nodePath = process.execPath, exists = existsSync, resolvePath = realpathSync } = {}) {
21
+ const path = platform === "win32" ? win32 : posix;
22
+ try { cliPath = resolvePath(cliPath); } catch { return null; }
23
+ const dir = path.dirname(cliPath);
24
+ if (path.basename(dir) !== "viewable-one" || path.basename(path.dirname(dir)) !== "node_modules") return null;
25
+ if (/[\\/]_npx[\\/]/.test(dir)) return null;
26
+ const parent = path.dirname(path.dirname(dir));
27
+ if (platform !== "win32") return path.basename(parent) === "lib" && ownsShim(path, path.dirname(parent), cliPath, { exists, resolvePath }) ? dir : null;
28
+ // Windows global packages have command shims in their prefix. Local
29
+ // dependencies put those shims in node_modules/.bin instead.
30
+ const appData = env.APPDATA ? path.join(env.APPDATA, "npm") : "";
31
+ return parent.toLowerCase() === appData.toLowerCase() || parent.toLowerCase() === path.dirname(nodePath).toLowerCase()
32
+ || exists(path.join(parent, "viewable.cmd")) ? dir : null;
33
+ }
34
+
35
+ export function npmPathFor({ platform = process.platform, env = process.env, nodePath = process.execPath, exists = existsSync } = {}) {
36
+ const path = platform === "win32" ? win32 : posix;
37
+ const nodeDir = path.dirname(nodePath);
38
+ const voltaHome = String(env?.VOLTA_HOME ?? "");
39
+ if (/[\\/]tools[\\/]image[\\/]node[\\/]/.test(nodePath) || (voltaHome && nodePath.startsWith(voltaHome))) return env;
40
+ if (!exists(path.join(nodeDir, platform === "win32" ? "npm.cmd" : "npm"))) return env;
41
+ const key = Object.keys(env ?? {}).find((k) => (platform === "win32" ? k.toUpperCase() === "PATH" : k === "PATH")) ?? "PATH";
42
+ const rest = String(env?.[key] ?? "").split(path.delimiter).filter((dir) => dir && dir !== nodeDir);
43
+ return { ...env, [key]: [nodeDir, ...rest].join(path.delimiter) };
44
+ }
45
+
46
+ /** Resolve once before spawning, including before self-uninstall deletes us.
47
+ * Volta owns its package image, so its shim must retain control of the prefix.
48
+ * Custom global prefixes may have no Node; pin the destination regardless. */
49
+ export function npmCommand(args, { platform = process.platform, env = process.env, nodePath = process.execPath, cliPath = CLI_PATH, exists = existsSync, resolvePath = realpathSync, readFile } = {}) {
50
+ const path = platform === "win32" ? win32 : posix;
51
+ const packageDir = globalPackageDir(cliPath, { platform, env, nodePath, exists, resolvePath });
52
+ const volta = packageDir && /[\\/]tools[\\/]image[\\/]packages[\\/]/.test(packageDir);
53
+ const prefix = packageDir && !volta ? path.resolve(packageDir, platform === "win32" ? "../.." : "../../..") : null;
54
+ if (prefix) {
55
+ const bin = platform === "win32" ? prefix : path.join(prefix, "bin");
56
+ const owningNode = path.join(bin, platform === "win32" ? "node.exe" : "node");
57
+ const npm = platform === "win32" ? path.join(bin, "node_modules/npm/bin/npm-cli.js") : path.join(bin, "npm");
58
+ if (exists(owningNode) && exists(npm)) nodePath = owningNode;
59
+ args = [...args, "--prefix", prefix];
60
+ }
61
+ const npmEnv = volta ? env : npmPathFor({ platform, env, nodePath, exists });
62
+ const cli = path.join(path.dirname(nodePath), "node_modules/npm/bin/npm-cli.js");
63
+ // Node's npm.cmd uses variables that the generic shim parser refuses.
64
+ const command = !volta && platform === "win32" && exists(cli)
65
+ ? { file: nodePath, args: [cli, ...args], shell: false }
66
+ : runnableCommand("npm", args, { platform, env: npmEnv, nodePath, exists, ...(readFile ? { readFile } : {}) });
67
+ return { ...command, env: npmEnv, packageDir };
68
+ }
package/lib/registry.mjs CHANGED
@@ -25,6 +25,14 @@ import { acquireAdmission } from "./admission.mjs";
25
25
  export const viewableHome = (env = process.env) =>
26
26
  (env.VIEWABLE_HOME ?? env.GLYTCH_HOME)?.trim() || join(homedir(), ".glytch");
27
27
 
28
+ /** Display only: resolve through the storage helper, abbreviating the default home. */
29
+ export function viewableDisplayPath(env = process.env, ...parts) {
30
+ const home = viewableHome(env);
31
+ return home === viewableHome({})
32
+ ? ["~", ".glytch", ...parts].join("/")
33
+ : join(home, ...parts);
34
+ }
35
+
28
36
  export const registryPath = (env = process.env) => join(viewableHome(env), "folders.json");
29
37
 
30
38
  // Restore and Remove run in different processes. Reuse admission's exclusive
@@ -47,9 +47,10 @@ import { spawn } from "node:child_process";
47
47
  import { createHash } from "node:crypto";
48
48
  import { writeFileSync } from "node:fs";
49
49
  import { tmpdir } from "node:os";
50
- import { dirname, join, sep } from "node:path";
50
+ import { dirname, join } from "node:path";
51
51
  import { fileURLToPath } from "node:url";
52
52
 
53
+ import { globalPackageDir, npmCommand } from "./npm-command.mjs";
53
54
  import { appUrlFrom, readAuthFile } from "./auth.mjs";
54
55
 
55
56
  const CLI_PATH = join(dirname(fileURLToPath(import.meta.url)), "..", "glytch.mjs");
@@ -107,12 +108,6 @@ export async function credentialRemoved({ env = process.env, fetchImpl = fetch,
107
108
  return { removed: true, tokens };
108
109
  }
109
110
 
110
- /** Where the global npm package lives when this copy came from one. */
111
- function globalPackageDir(cliPath) {
112
- const marker = `${sep}node_modules${sep}viewable-one${sep}`;
113
- return cliPath.includes(marker) ? cliPath.slice(0, cliPath.indexOf(marker) + marker.length - 1) : null;
114
- }
115
-
116
111
  /** What the uninstall needs from this daemon's environment. A launcher
117
112
  * outside this process (a systemd unit, WMI) starts it with the user's
118
113
  * default environment instead, so the script carries these itself. Keys and
@@ -125,13 +120,14 @@ export function carriedEnv(env = process.env) {
125
120
 
126
121
  /** The detached command: `viewable uninstall --yes`, then, only when it
127
122
  * finished and this copy is the global npm package, `npm uninstall -g`. */
128
- export function selfUninstallCommand({ execPath = process.execPath, cliPath = CLI_PATH, env = process.env } = {}) {
129
- const npm = globalPackageDir(cliPath) ? join(dirname(execPath), process.platform === "win32" ? "npm.cmd" : "npm") : null;
123
+ export function selfUninstallCommand({ execPath = process.execPath, cliPath = CLI_PATH, env = process.env, ...options } = {}) {
124
+ const target = { ...options, nodePath: execPath, cliPath, env };
125
+ const npm = globalPackageDir(cliPath, target) ? npmCommand(["uninstall", "-g", "viewable-one"], target) : null;
130
126
  const script = [
131
127
  'const { spawnSync } = require("node:child_process");',
132
128
  `const env = { ...process.env, ...${JSON.stringify(carriedEnv(env))} };`,
133
129
  `const done = spawnSync(process.execPath, [${JSON.stringify(cliPath)}, "uninstall", "--yes"], { stdio: "ignore", env });`,
134
- npm ? `if (done.status === 0) spawnSync(${JSON.stringify(npm)}, ["uninstall", "-g", "viewable-one"], { stdio: "ignore", env, shell: process.platform === "win32" });` : "",
130
+ npm ? `if (done.status === 0) spawnSync(${JSON.stringify(npm.file)}, ${JSON.stringify(npm.args)}, { stdio: "ignore", env: { ...env, ...${JSON.stringify(carriedEnv(npm.env))} }, shell: false });` : "",
135
131
  ].join("\n");
136
132
  return { command: execPath, args: ["-e", script], script };
137
133
  }
package/lib/sync.mjs CHANGED
@@ -43,7 +43,7 @@ import {
43
43
  noDaemonInstall,
44
44
  } from "./logindaemon.mjs";
45
45
  import { BOARD_MCP_URL, mergeBoardServer } from "./mcpjson.mjs";
46
- import { addFolder, readRegistry } from "./registry.mjs";
46
+ import { viewableDisplayPath, addFolder, readRegistry } from "./registry.mjs";
47
47
  import { readAgentSelection, parseAgentSelection } from "./agent-selection.mjs";
48
48
  import { syncProjectMcp } from "./project-mcp.mjs";
49
49
  import { packageVersion } from "./update.mjs";
@@ -142,7 +142,7 @@ export async function syncOpencode(root, { exec = execProbe, found, write = true
142
142
  export async function syncRegistry(root, { env = process.env, write = true } = {}) {
143
143
  const folders = await readRegistry(env);
144
144
  if (folders.includes(root)) return row("registry", "folder registered", true, "present", "your computer watches this folder");
145
- if (!write) return row("registry", "folder registered", false, "missing", "this folder is not in ~/.glytch/folders.json");
145
+ if (!write) return row("registry", "folder registered", false, "missing", `this folder is not in ${viewableDisplayPath(env, "folders.json")}`);
146
146
  try {
147
147
  await addFolder(root, env);
148
148
  } catch (error) {
@@ -152,11 +152,11 @@ export async function syncRegistry(root, { env = process.env, write = true } = {
152
152
  "folder registered",
153
153
  false,
154
154
  "could not write",
155
- `~/.glytch/folders.json could not be written: ${why}`,
155
+ `${viewableDisplayPath(env, "folders.json")} could not be written: ${why}`,
156
156
  COMPUTER_REPAIR,
157
157
  );
158
158
  }
159
- return row("registry", "folder registered", true, "added", "added to ~/.glytch/folders.json");
159
+ return row("registry", "folder registered", true, "added", `added to ${viewableDisplayPath(env, "folders.json")}`);
160
160
  }
161
161
 
162
162
  /** The entries of a PATH, in order, without the empties.
@@ -34,7 +34,7 @@ import { boardEntryIsOurs as codexBoardEntryIsOurs, opencodeBoardEntryIsOurs, pr
34
34
  import { detectAgents, execProbe } from "./detect.mjs";
35
35
  import { SERVER_KEY, lastStderrLine } from "./init-connect.mjs";
36
36
  import { writeFileAtomic } from "./atomic.mjs";
37
- import { readRegistry, removeFolder } from "./registry.mjs";
37
+ import { viewableDisplayPath, readRegistry, removeFolder } from "./registry.mjs";
38
38
  import { row, warnRow } from "./cli-output.mjs";
39
39
 
40
40
  /** `code: message`, or just the message when there is no `.code` (a plain
@@ -527,17 +527,17 @@ async function registryRow(root, { env, dryRun, log, allOk = true }) {
527
527
  "left registered",
528
528
  "an earlier step in this project failed - left registered so `viewable uninstall` can retry",
529
529
  )
530
- : row("registry", "folder registered", true, "not present", "this folder is not in ~/.glytch/folders.json");
530
+ : row("registry", "folder registered", true, "not present", `this folder is not in ${viewableDisplayPath(env, "folders.json")}`);
531
531
  } else if (dryRun) {
532
532
  const folders = await readRegistry(env);
533
533
  r = folders.includes(target)
534
- ? row("registry", "folder registered", true, "would unregister", "would remove this folder from ~/.glytch/folders.json")
535
- : row("registry", "folder registered", true, "not present", "this folder is not in ~/.glytch/folders.json");
534
+ ? row("registry", "folder registered", true, "would unregister", `would remove this folder from ${viewableDisplayPath(env, "folders.json")}`)
535
+ : row("registry", "folder registered", true, "not present", `this folder is not in ${viewableDisplayPath(env, "folders.json")}`);
536
536
  } else {
537
537
  const result = await removeFolder(root, env);
538
538
  r = result.removed
539
- ? row("registry", "folder registered", true, "unregistered", "removed from ~/.glytch/folders.json")
540
- : row("registry", "folder registered", true, "not present", "this folder was not in ~/.glytch/folders.json");
539
+ ? row("registry", "folder registered", true, "unregistered", `removed from ${viewableDisplayPath(env, "folders.json")}`)
540
+ : row("registry", "folder registered", true, "not present", `this folder was not in ${viewableDisplayPath(env, "folders.json")}`);
541
541
  }
542
542
  } catch (error) {
543
543
  // U4: this should be rare (the registry file is JSON we control), but a
package/lib/uninstall.mjs CHANGED
@@ -36,7 +36,7 @@ import { join } from "node:path";
36
36
  import { bold, bullets, colorEnabled, heading, hint, renderRow, row, step, summary, warn, warnRow } from "./cli-output.mjs";
37
37
  import { appUrlFrom, logout as hostedLogout, readAuthFile } from "./auth.mjs";
38
38
  import { detectAgents, execProbe } from "./detect.mjs";
39
- import { viewableHome, readRegistry } from "./registry.mjs";
39
+ import { viewableDisplayPath, viewableHome, readRegistry } from "./registry.mjs";
40
40
  import { loginDaemon } from "./logindaemon.mjs";
41
41
  import { uninstallProject } from "./uninstall-project.mjs";
42
42
 
@@ -99,7 +99,7 @@ export function readlineAsk(input = process.stdin, output = process.stdout) {
99
99
 
100
100
  /** The bulleted plan printed before the question is ever asked - "print what
101
101
  * will happen" first, so "Type yes to continue" means something. */
102
- export function uninstallPlan(options, { folderCount = 0 } = {}) {
102
+ export function uninstallPlan(options, { folderCount = 0, env = process.env } = {}) {
103
103
  const lines = [];
104
104
  if (options.project) {
105
105
  lines.push(
@@ -119,8 +119,8 @@ export function uninstallPlan(options, { folderCount = 0 } = {}) {
119
119
  );
120
120
  lines.push(
121
121
  options.keepLogin
122
- ? "Leave ~/.glytch in place: the sign-in credential lives there (--keep-login)."
123
- : "Delete ~/.glytch entirely.",
122
+ ? `Leave ${viewableDisplayPath(env)} in place: the sign-in credential lives there (--keep-login).`
123
+ : `Delete ${viewableDisplayPath(env)} entirely.`,
124
124
  );
125
125
  }
126
126
  lines.push("Print the two steps left to finish by hand: uninstalling the npm package, and unlinking the folder in the app.");
@@ -313,13 +313,13 @@ export async function revokeRow({ stored, env, fetchImpl, dryRun, keepLogin, log
313
313
  export async function deleteHomeRow({ env, dryRun, keepLogin }) {
314
314
  const home = viewableHome(env);
315
315
  if (keepLogin) {
316
- return warnRow("home", "Delete ~/.glytch", "kept", `kept - the sign-in credential lives at ${join(home, "auth.json")} (--keep-login)`);
316
+ return warnRow("home", `Delete ${viewableDisplayPath(env)}`, "kept", `kept - the sign-in credential lives at ${join(home, "auth.json")} (--keep-login)`);
317
317
  }
318
318
  if (dryRun) {
319
- return row("home", "Delete ~/.glytch", true, "would delete", home);
319
+ return row("home", `Delete ${viewableDisplayPath(env)}`, true, "would delete", home);
320
320
  }
321
321
  await rm(home, { recursive: true, force: true });
322
- return row("home", "Delete ~/.glytch", true, "deleted", home);
322
+ return row("home", `Delete ${viewableDisplayPath(env)}`, true, "deleted", home);
323
323
  }
324
324
 
325
325
  /** The two steps this command cannot do for you, as hints under step 3.
@@ -356,7 +356,7 @@ export async function runUninstall({
356
356
  } = {}) {
357
357
  const paint = { color };
358
358
  const roots = options.project ? [root] : await readRegistry(env);
359
- const plan = uninstallPlan(options, { folderCount: roots.length });
359
+ const plan = uninstallPlan(options, { folderCount: roots.length, env });
360
360
  const proceed = await confirmUninstall({ options, plan, isTTY, ask, log, color });
361
361
  if (!proceed) return 1;
362
362
 
@@ -438,16 +438,16 @@ export async function runUninstall({
438
438
  const home = !projectsOk
439
439
  ? warnRow(
440
440
  "home",
441
- "Delete ~/.glytch",
441
+ `Delete ${viewableDisplayPath(env)}`,
442
442
  "left in place",
443
- "a project step failed - ~/.glytch was left in place so `viewable uninstall` can retry",
443
+ `a project step failed - ${viewableDisplayPath(env)} was left in place so \`viewable uninstall\` can retry`,
444
444
  )
445
445
  : revoke.keptCredential
446
446
  ? warnRow(
447
447
  "home",
448
- "Delete ~/.glytch",
448
+ `Delete ${viewableDisplayPath(env)}`,
449
449
  "kept",
450
- "the board sign-in could not be revoked and its credential was kept so a retry can revoke it; ~/.glytch was not deleted",
450
+ `the board sign-in could not be revoked and its credential was kept so a retry can revoke it; ${viewableDisplayPath(env)} was not deleted`,
451
451
  )
452
452
  : await deleteHomeRow({ env, dryRun: options.dryRun, keepLogin: options.keepLogin });
453
453
  for (const line of printedRows([home], paint)) log(line);
package/lib/update.mjs CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
  import { createRequire } from "node:module";
18
18
  import { execFile } from "node:child_process";
19
- import { existsSync, readFileSync } from "node:fs";
19
+ import { readFileSync } from "node:fs";
20
20
  import { realpath } from "node:fs/promises";
21
21
  import { basename, join, posix, win32 } from "node:path";
22
22
  import { readRunnerHealth, waitForRunnerHealth } from "./runner-health.mjs";
@@ -24,6 +24,7 @@ import { noDaemonInstall } from "./logindaemon.mjs";
24
24
  import { markQuietStop } from "./goodbye.mjs";
25
25
  import { fileURLToPath } from "node:url";
26
26
 
27
+ import { npmCommand } from "./npm-command.mjs";
27
28
  import { runnableCommand } from "./windows-command.mjs";
28
29
 
29
30
  export const DAY_MS = 86_400_000;
@@ -61,61 +62,16 @@ export function compareVersions(a, b) {
61
62
  return 0;
62
63
  }
63
64
 
64
- /** Run npm. `exec` is injected so the tests never touch the network.
65
- *
66
- * npm installs as `npm.cmd` on Windows, so this goes through the same
67
- * `runnableCommand` resolution as every other binary this package looks for -
68
- * otherwise the version row lies and says "offline" on a machine with a
69
- * perfectly good connection.
70
- *
71
- * WHICH npm (#5305). The first `npm` on the PATH is not necessarily the one
72
- * whose prefix holds this Viewable: a Mac with a system Node and nvm has
73
- * `/usr/local/bin/npm` first while Viewable lives under nvm, and installing
74
- * with the wrong one writes to a folder the person cannot write to. So the
75
- * npm that sits next to the Node running this process goes first on the
76
- * child's PATH (npm's own `#!/usr/bin/env node` then finds that Node too).
77
- * When no npm sits beside this Node (npx), or the Node is one of Volta's
78
- * images, the PATH decides as before: Volta's own npm shim installs into the
79
- * package image that #707's verification expects, and the image's bundled npm
80
- * would not.
81
- * Every npm call in this file goes through `execNpm`, so `viewable update`,
82
- * the no-paste Update, and the version checks all agree. This returns the env
83
- * to run npm with. */
84
- export function npmPathFor({ platform = process.platform, env = process.env, nodePath = process.execPath, exists = existsSync } = {}) {
85
- const path = platform === "win32" ? win32 : posix;
86
- const nodeDir = path.dirname(nodePath);
87
- const voltaHome = String(env?.VOLTA_HOME ?? "");
88
- if (/[\\/]tools[\\/]image[\\/]node[\\/]/.test(nodePath) || (voltaHome && nodePath.startsWith(voltaHome))) return env;
89
- if (!exists(path.join(nodeDir, platform === "win32" ? "npm.cmd" : "npm"))) return env;
90
- const key = Object.keys(env ?? {}).find((k) => (platform === "win32" ? k.toUpperCase() === "PATH" : k === "PATH")) ?? "PATH";
91
- const rest = String(env?.[key] ?? "").split(path.delimiter).filter((dir) => dir && dir !== nodeDir);
92
- return { ...env, [key]: [nodeDir, ...rest].join(path.delimiter) };
93
- }
94
-
95
- /** Resolves `{ ok, stdout, stderr, timedOut }`; `stderr` is what
96
- * `installFailureReason` reads. */
97
- /** Node's own Windows install ships `npm.cmd` as a launcher that starts
98
- * through variables ("%NODE_EXE%" "%NPM_CLI_JS%" %*), which `runnableCommand`
99
- * rightly refuses. Beside that Node the entry script is always at the same
100
- * place, so run it with that Node instead of the shim. */
101
- function nodeBesideNpm({ platform, nodePath, exists = existsSync }) {
102
- if (platform !== "win32") return null;
103
- const cli = win32.join(win32.dirname(nodePath), "node_modules", "npm", "bin", "npm-cli.js");
104
- return exists(cli) ? { file: nodePath, args: [cli], shell: false } : null;
105
- }
106
-
107
- export const execNpm = (args, { timeoutMs = NPM_TIMEOUT_MS, platform = process.platform, env = process.env, exists, readFile, execImpl = execFile, nodePath = process.execPath } = {}) =>
65
+ /** All npm calls target the running package's global prefix, even when
66
+ * env node started it with another Node. See npm-command.mjs for manager
67
+ * fallbacks; CLI, board Update and daily checks share this resolution. */
68
+ export { npmPathFor } from "./npm-command.mjs";
69
+ export const execNpm = (args, { timeoutMs = NPM_TIMEOUT_MS, execImpl = execFile, ...options } = {}) =>
108
70
  new Promise((resolve) => {
109
- let resolved;
110
- const npmEnv = npmPathFor({ platform, env, nodePath, ...(exists ? { exists } : {}) });
111
- const beside = nodeBesideNpm({ platform, nodePath, ...(exists ? { exists } : {}) });
112
- try {
113
- resolved = beside ? { ...beside, args: [...beside.args, ...args] } : runnableCommand("npm", args, { platform, env: npmEnv, nodePath, ...(exists ? { exists } : {}), ...(readFile ? { readFile } : {}) });
114
- } catch {
115
- resolve({ ok: false, stdout: "", stderr: "" });
116
- return;
117
- }
118
- execImpl(resolved.file, resolved.args, { timeout: timeoutMs, windowsHide: true, env: npmEnv, shell: resolved.shell }, (error, stdout, stderr) =>
71
+ let command;
72
+ try { command = npmCommand(args, options); }
73
+ catch { resolve({ ok: false, stdout: "", stderr: "" }); return; }
74
+ execImpl(command.file, command.args, { timeout: timeoutMs, windowsHide: true, env: command.env, shell: command.shell }, (error, stdout, stderr) =>
119
75
  resolve({ ok: !error, stdout: String(stdout ?? ""), stderr: String(stderr ?? ""), ...(error?.killed ? { timedOut: true } : {}) }),
120
76
  );
121
77
  });
@@ -131,7 +87,7 @@ export function installFailureReason(result, where = "") {
131
87
  // npm prints the path quoted after a colon, or bare ("npm error path /x/.npm/_cacache").
132
88
  const named = /^(?:npm (?:error|ERR!)\s+)?path:?\s+'?([^'\r\n]+?)'?\s*$/im.exec(text)?.[1] ?? /'((?:\/|[A-Za-z]:\\)[^']+)'/.exec(text)?.[1] ?? where;
133
89
  if (/[\\/]_cacache\b/.test(named)) return `No permission to write npm's cache folder ${named}. Fix the folder's owner; never run sudo.`;
134
- return `No permission to write ${named || "the npm folder"}. Never run sudo; use the npm that came with the Node running Viewable, or fix the folder's owner.`;
90
+ return `No permission to write ${named || "the npm folder"}. Never run sudo; fix the folder's owner.`;
135
91
  }
136
92
  if (/\bENOSPC\b|no space left/i.test(text)) return "The disk is full.";
137
93
  if (/\b(?:ENOTFOUND|EAI_AGAIN|ECONNRESET|ECONNREFUSED|ETIMEDOUT|ENETUNREACH|EPROTO)\b|network/i.test(text)) return "Could not reach npm. Check your connection.";
@@ -331,12 +287,13 @@ export async function initServiceScript({ env = process.env, verify = verifyInst
331
287
  * No init/login/config rewrite, agent execution, or automatic updater. */
332
288
  export async function runUpdate({
333
289
  env = process.env, platform = process.platform, exec = execNpm,
290
+ cliPath = fileURLToPath(new URL("../glytch.mjs", import.meta.url)),
334
291
  verify = verifyInstalledCli, sync, wait = waitForRunnerHealth,
335
292
  readHealth = () => readRunnerHealth(env), now = Date.now, log = () => {},
336
293
  } = {}) {
337
294
  const failure = (error) => ({ ok: false, error });
338
295
  if (noDaemonInstall(env)) return failure("Service changes are disabled. Nothing was installed or restarted.");
339
- const npm = (args, options) => exec(args, { env, platform, ...options });
296
+ const npm = (args, options) => exec(args, { env, platform, cliPath, ...options });
340
297
  const latest = await latestFromNpm({ exec: npm });
341
298
  if (!latest) return failure("Could not check the latest published version. Check your connection and try viewable update again. Nothing was restarted.");
342
299
  const root = await npm(["root", "-g"]);
@@ -400,7 +357,7 @@ export async function installUpdate({
400
357
  } = {}) {
401
358
  const failure = (error) => ({ ok: false, error });
402
359
  if (noDaemonInstall(env)) return failure("Updates are turned off on this computer.");
403
- const npm = (args, options) => exec(args, { env, platform, ...options });
360
+ const npm = (args, options) => exec(args, { env, platform, cliPath: scriptPath, ...options });
404
361
  const latest = await latestFromNpm({ exec: npm });
405
362
  if (!latest) return failure("Could not reach npm to find the new version.");
406
363
  if (compareVersions(latest, version) <= 0) return { ok: true, version, restart: false };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "viewable-one",
3
- "version": "0.12.5",
3
+ "version": "0.12.6",
4
4
  "description": "Run coding agents from the Viewable board. Connects your machine to app.viewable.one, launches a session in its own worktree when you press Run, and streams what it does back to the canvas.",
5
5
  "keywords": [
6
6
  "mcp",