viewable-one 0.12.4 → 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 +76 -0
- package/glytch.mjs +18 -11
- package/lib/auth.mjs +8 -3
- package/lib/codexApps.mjs +16 -4
- package/lib/doctor.mjs +6 -6
- package/lib/goodbye.mjs +120 -0
- package/lib/init-connect.mjs +2 -2
- package/lib/multiwatch.mjs +25 -2
- package/lib/npm-command.mjs +68 -0
- package/lib/registry.mjs +36 -0
- package/lib/runner.mjs +1 -1
- package/lib/runnerBeat.mjs +8 -3
- package/lib/runnerGates.mjs +7 -6
- package/lib/runnerPace.mjs +134 -5
- package/lib/runnerRegister.mjs +17 -3
- package/lib/selfUninstall.mjs +6 -10
- package/lib/signIn.mjs +43 -18
- package/lib/sync.mjs +4 -4
- package/lib/uninstall-project.mjs +6 -6
- package/lib/uninstall.mjs +12 -12
- package/lib/update.mjs +45 -22
- package/lib/viewableFolder.mjs +6 -3
- package/package.json +1 -1
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
|
-
?
|
|
123
|
-
:
|
|
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",
|
|
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",
|
|
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",
|
|
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
|
-
|
|
441
|
+
`Delete ${viewableDisplayPath(env)}`,
|
|
442
442
|
"left in place",
|
|
443
|
-
|
|
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
|
-
|
|
448
|
+
`Delete ${viewableDisplayPath(env)}`,
|
|
449
449
|
"kept",
|
|
450
|
-
|
|
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
|
@@ -21,8 +21,10 @@ 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";
|
|
23
23
|
import { noDaemonInstall } from "./logindaemon.mjs";
|
|
24
|
+
import { markQuietStop } from "./goodbye.mjs";
|
|
24
25
|
import { fileURLToPath } from "node:url";
|
|
25
26
|
|
|
27
|
+
import { npmCommand } from "./npm-command.mjs";
|
|
26
28
|
import { runnableCommand } from "./windows-command.mjs";
|
|
27
29
|
|
|
28
30
|
export const DAY_MS = 86_400_000;
|
|
@@ -60,27 +62,42 @@ export function compareVersions(a, b) {
|
|
|
60
62
|
return 0;
|
|
61
63
|
}
|
|
62
64
|
|
|
63
|
-
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
* otherwise the version row lies and says "offline" on a machine with a
|
|
69
|
-
* perfectly good connection. */
|
|
70
|
-
export const execNpm = (args, { timeoutMs = NPM_TIMEOUT_MS, platform = process.platform, env = process.env, exists, readFile, execImpl = execFile } = {}) =>
|
|
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 } = {}) =>
|
|
71
70
|
new Promise((resolve) => {
|
|
72
|
-
let
|
|
73
|
-
try {
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
resolve({ ok:
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
execImpl(resolved.file, resolved.args, { timeout: timeoutMs, windowsHide: true, env, shell: resolved.shell }, (error, stdout) =>
|
|
80
|
-
resolve({ ok: !error, stdout: String(stdout ?? "") }),
|
|
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) =>
|
|
75
|
+
resolve({ ok: !error, stdout: String(stdout ?? ""), stderr: String(stderr ?? ""), ...(error?.killed ? { timedOut: true } : {}) }),
|
|
81
76
|
);
|
|
82
77
|
});
|
|
83
78
|
|
|
79
|
+
/** Say what an install failure was, in plain words, from npm's own error
|
|
80
|
+
* text. `where` is the folder npm was installing into, used when npm does not
|
|
81
|
+
* name the path. Never says "Check your connection" unless the network is
|
|
82
|
+
* what failed. */
|
|
83
|
+
export function installFailureReason(result, where = "") {
|
|
84
|
+
const text = String(result?.stderr ?? "");
|
|
85
|
+
if (result?.timedOut) return "npm took too long to install it.";
|
|
86
|
+
if (/\b(?:EACCES|EPERM)\b|rejected by your operating system|permission denied/i.test(text)) {
|
|
87
|
+
// npm prints the path quoted after a colon, or bare ("npm error path /x/.npm/_cacache").
|
|
88
|
+
const named = /^(?:npm (?:error|ERR!)\s+)?path:?\s+'?([^'\r\n]+?)'?\s*$/im.exec(text)?.[1] ?? /'((?:\/|[A-Za-z]:\\)[^']+)'/.exec(text)?.[1] ?? where;
|
|
89
|
+
if (/[\\/]_cacache\b/.test(named)) return `No permission to write npm's cache folder ${named}. Fix the folder's owner; never run sudo.`;
|
|
90
|
+
return `No permission to write ${named || "the npm folder"}. Never run sudo; fix the folder's owner.`;
|
|
91
|
+
}
|
|
92
|
+
if (/\bENOSPC\b|no space left/i.test(text)) return "The disk is full.";
|
|
93
|
+
if (/\b(?:ENOTFOUND|EAI_AGAIN|ECONNRESET|ECONNREFUSED|ETIMEDOUT|ENETUNREACH|EPROTO)\b|network/i.test(text)) return "Could not reach npm. Check your connection.";
|
|
94
|
+
// npm ends a failed run with a pointer to its log; that is not the cause.
|
|
95
|
+
const line = text.split(/\r?\n/).filter((l) => !/^npm notice\b/i.test(l.trim()))
|
|
96
|
+
.map((l) => l.replace(/^npm (?:error|ERR!)\s*/i, "").trim())
|
|
97
|
+
.filter((l) => l && !/^a complete log of this run can be found/i.test(l)).at(-1);
|
|
98
|
+
return line ? `npm said: ${line.slice(0, 200)}` : "npm did not say why.";
|
|
99
|
+
}
|
|
100
|
+
|
|
84
101
|
export async function latestFromNpm({ exec = execNpm, name = PACKAGE_NAME, timeoutMs = NPM_TIMEOUT_MS } = {}) {
|
|
85
102
|
const result = await exec(["view", name, "version"], { timeoutMs });
|
|
86
103
|
if (!result?.ok) return null;
|
|
@@ -270,12 +287,13 @@ export async function initServiceScript({ env = process.env, verify = verifyInst
|
|
|
270
287
|
* No init/login/config rewrite, agent execution, or automatic updater. */
|
|
271
288
|
export async function runUpdate({
|
|
272
289
|
env = process.env, platform = process.platform, exec = execNpm,
|
|
290
|
+
cliPath = fileURLToPath(new URL("../glytch.mjs", import.meta.url)),
|
|
273
291
|
verify = verifyInstalledCli, sync, wait = waitForRunnerHealth,
|
|
274
292
|
readHealth = () => readRunnerHealth(env), now = Date.now, log = () => {},
|
|
275
293
|
} = {}) {
|
|
276
294
|
const failure = (error) => ({ ok: false, error });
|
|
277
295
|
if (noDaemonInstall(env)) return failure("Service changes are disabled. Nothing was installed or restarted.");
|
|
278
|
-
const npm = (args, options) => exec(args, { env, platform, ...options });
|
|
296
|
+
const npm = (args, options) => exec(args, { env, platform, cliPath, ...options });
|
|
279
297
|
const latest = await latestFromNpm({ exec: npm });
|
|
280
298
|
if (!latest) return failure("Could not check the latest published version. Check your connection and try viewable update again. Nothing was restarted.");
|
|
281
299
|
const root = await npm(["root", "-g"]);
|
|
@@ -283,12 +301,17 @@ export async function runUpdate({
|
|
|
283
301
|
const scriptPath = (platform === "win32" ? win32 : { join }).join(root.stdout.trim(), PACKAGE_NAME, "glytch.mjs");
|
|
284
302
|
log(`Installing Viewable ${latest}…`);
|
|
285
303
|
const installed = await npm(["install", "-g", `${PACKAGE_NAME}@${latest}`, "--force"], { timeoutMs: 180_000 });
|
|
286
|
-
if (!installed?.ok) return failure(
|
|
304
|
+
if (!installed?.ok) return failure(`Installation failed. ${installFailureReason(installed, root.stdout.trim())} The service was left alone. Retry viewable update after fixing the install.`);
|
|
287
305
|
const checked = await verify({ env, platform, expectedVersion: latest, scriptPath, allowVoltaPackage: true, log });
|
|
288
306
|
if (!checked.ok) return failure(`The package was installed, but ${checked.error}`);
|
|
289
307
|
const before = readHealth();
|
|
290
308
|
const after = now();
|
|
291
|
-
|
|
309
|
+
// An update's restart is not a goodbye (ruling #4979): the app it stops
|
|
310
|
+
// reads this note (lib/goodbye.mjs).
|
|
311
|
+
const restart = sync ?? (async (options) => {
|
|
312
|
+
await markQuietStop({ env, why: "update" });
|
|
313
|
+
return (await import("./sync.mjs")).syncLaunchAgent(options);
|
|
314
|
+
});
|
|
292
315
|
let result;
|
|
293
316
|
try { result = await restart({ env, platform, scriptPath: checked.scriptPath, version: latest, restart: true }); }
|
|
294
317
|
catch { return failure("The package was installed, but restarting failed. Folders and sign-in were kept. Run viewable doctor, then retry viewable update."); }
|
|
@@ -334,7 +357,7 @@ export async function installUpdate({
|
|
|
334
357
|
} = {}) {
|
|
335
358
|
const failure = (error) => ({ ok: false, error });
|
|
336
359
|
if (noDaemonInstall(env)) return failure("Updates are turned off on this computer.");
|
|
337
|
-
const npm = (args, options) => exec(args, { env, platform, ...options });
|
|
360
|
+
const npm = (args, options) => exec(args, { env, platform, cliPath: scriptPath, ...options });
|
|
338
361
|
const latest = await latestFromNpm({ exec: npm });
|
|
339
362
|
if (!latest) return failure("Could not reach npm to find the new version.");
|
|
340
363
|
if (compareVersions(latest, version) <= 0) return { ok: true, version, restart: false };
|
|
@@ -347,7 +370,7 @@ export async function installUpdate({
|
|
|
347
370
|
if (!same) return failure("This computer runs Viewable from another folder, so it cannot update itself.");
|
|
348
371
|
log(`update: installing Viewable ${latest}…`);
|
|
349
372
|
const installed = await npm(["install", "-g", `${PACKAGE_NAME}@${latest}`, "--force"], { timeoutMs: 180_000 });
|
|
350
|
-
if (!installed?.ok) return failure(
|
|
373
|
+
if (!installed?.ok) return failure(`Installation failed. ${installFailureReason(installed, root.stdout.trim())} Nothing was restarted.`);
|
|
351
374
|
const found = await readVersion(path.join(root.stdout.trim(), PACKAGE_NAME, "package.json")).catch(() => null);
|
|
352
375
|
if (found !== latest) return failure(`Installed, but the version reads ${found ?? "nothing"}, not ${latest}. Nothing was restarted.`);
|
|
353
376
|
return { ok: true, version: latest, restart: true };
|
package/lib/viewableFolder.mjs
CHANGED
|
@@ -7,12 +7,13 @@
|
|
|
7
7
|
// No existing folder is moved or rewritten by the rename (#2329).
|
|
8
8
|
//
|
|
9
9
|
// Made when the daemon starts watching, and kept: nothing here removes it.
|
|
10
|
+
// Unless the person removed it from the board: then it is left alone (#5290).
|
|
10
11
|
|
|
11
12
|
import { existsSync } from "node:fs";
|
|
12
13
|
import { lstat, mkdir, realpath, writeFile } from "node:fs/promises";
|
|
13
14
|
import { homedir } from "node:os";
|
|
14
15
|
import { basename, dirname, join, resolve } from "node:path";
|
|
15
|
-
import {
|
|
16
|
+
import { addFolderUnlessRemoved, folderWasRemoved } from "./registry.mjs";
|
|
16
17
|
import { git, isChatWorktreePath, resolveChatCwd } from "./worktree.mjs";
|
|
17
18
|
|
|
18
19
|
/** Where the default working folder lives, or null when there is none to make.
|
|
@@ -52,6 +53,9 @@ const COMMITTER = ["-c", "user.name=Viewable", "-c", "user.email=viewable@localh
|
|
|
52
53
|
export async function ensureViewableFolder(env = process.env, log = () => {}) {
|
|
53
54
|
const path = viewableFolderPath(env);
|
|
54
55
|
if (path === null) return null;
|
|
56
|
+
// A folder the person removed from the board is not made or watched again
|
|
57
|
+
// on the next start (#5290). Adding it by hand (init) clears the record.
|
|
58
|
+
if (await folderWasRemoved(path, env)) return null;
|
|
55
59
|
try {
|
|
56
60
|
await mkdir(path, { recursive: true });
|
|
57
61
|
// Its own repository, not one it happens to sit inside: a home folder
|
|
@@ -77,8 +81,7 @@ export async function ensureViewableFolder(env = process.env, log = () => {}) {
|
|
|
77
81
|
if (!commit.ok) throw new Error(`first commit failed: ${commit.stderr?.trim() || "no detail"}`);
|
|
78
82
|
log(`made the Viewable folder at ${path}`);
|
|
79
83
|
}
|
|
80
|
-
await
|
|
81
|
-
return path;
|
|
84
|
+
return await addFolderUnlessRemoved(path, env) === null ? null : path;
|
|
82
85
|
} catch (error) {
|
|
83
86
|
log(`could not make the Viewable folder at ${path}: ${error instanceof Error ? error.message : String(error)}`);
|
|
84
87
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "viewable-one",
|
|
3
|
-
"version": "0.12.
|
|
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",
|