viewable-one 0.12.1 → 0.12.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.
- package/CHANGELOG.md +71 -1
- package/README.md +31 -48
- package/SPAWN.md +136 -79
- package/glytch.mjs +41 -10
- package/lib/acp.mjs +152 -150
- package/lib/admission.mjs +25 -5
- package/lib/agent-selection.mjs +5 -4
- package/lib/agents.mjs +68 -24
- package/lib/answerTag.mjs +47 -0
- package/lib/atomic.mjs +1 -16
- package/lib/auth.mjs +172 -52
- package/lib/authenticatedHttp.mjs +10 -3
- package/lib/boardside.mjs +28 -12
- package/lib/child.mjs +129 -116
- package/lib/claudeModels.mjs +168 -0
- package/lib/codex-rpc.mjs +2 -2
- package/lib/codex.mjs +50 -50
- package/lib/codexApps.mjs +17 -3
- package/lib/codexToolInputs.mjs +98 -22
- package/lib/codingChecks.mjs +8 -4
- package/lib/conversationRules.mjs +47 -7
- package/lib/detect.mjs +39 -24
- package/lib/devserver.mjs +30 -19
- package/lib/doctor.mjs +10 -8
- package/lib/folderReads.mjs +96 -0
- package/lib/followUps.mjs +170 -0
- package/lib/hosted.mjs +13 -4
- package/lib/init-connect.mjs +29 -10
- package/lib/lateResume.mjs +135 -0
- package/lib/logindaemon.mjs +129 -49
- package/lib/logs.mjs +2 -2
- package/lib/mcpjson.mjs +35 -2
- package/lib/memberPreview.mjs +22 -14
- package/lib/multiwatch.mjs +28 -41
- package/lib/pagePictures.mjs +15 -12
- package/lib/pageRoutes.mjs +5 -2
- package/lib/paths.mjs +3 -3
- package/lib/permissionAsk.mjs +344 -61
- package/lib/previewGateway.mjs +4 -3
- package/lib/procs.mjs +73 -2
- package/lib/refusal.mjs +0 -2
- package/lib/registry.mjs +7 -7
- package/lib/repomap.mjs +4 -3
- package/lib/restartPass.mjs +39 -11
- package/lib/rowsAnswers.mjs +52 -69
- package/lib/rowsEvents.mjs +20 -2
- package/lib/runner-health.mjs +29 -5
- package/lib/runner.mjs +161 -1347
- package/lib/runnerAdmission.mjs +6 -12
- package/lib/runnerApi.mjs +20 -11
- package/lib/runnerBeat.mjs +384 -0
- package/lib/runnerCompletion.mjs +5 -2
- package/lib/runnerExecute.mjs +227 -0
- package/lib/runnerGates.mjs +338 -0
- package/lib/runnerLaunch.mjs +351 -0
- package/lib/runnerLease.mjs +31 -9
- package/lib/runnerOps.mjs +217 -0
- package/lib/runnerPace.mjs +10 -6
- package/lib/runnerRecovery.mjs +457 -0
- package/lib/runnerRegister.mjs +29 -8
- package/lib/runnerSettlement.mjs +43 -16
- package/lib/runnerWorkspace.mjs +19 -4
- package/lib/spawn.mjs +0 -5
- package/lib/sync.mjs +28 -16
- package/lib/uninstall-project.mjs +12 -11
- package/lib/uninstall.mjs +32 -25
- package/lib/update.mjs +4 -4
- package/lib/{glytchFolder.mjs → viewableFolder.mjs} +22 -16
- package/lib/worktree.mjs +83 -26
- package/lib/writePolicy.mjs +90 -10
- package/package.json +2 -2
package/lib/mcpjson.mjs
CHANGED
|
@@ -71,14 +71,47 @@ export const DEFAULT_BOARD_MCP_URL = "https://app.viewable.one/mcp";
|
|
|
71
71
|
* other bridge file imports it from here. */
|
|
72
72
|
export const RETIRED_BOARD_MCP_URL = `${RETIRED_APP_URL}/mcp`;
|
|
73
73
|
export const RETIRED_BOARD_MCP_URLS = RETIRED_APP_URLS.map(origin => `${origin}/mcp`);
|
|
74
|
+
/** Is this address the board endpoint on a retired host? Compared by parsed
|
|
75
|
+
* origin, not by string (#3736): scheme is ignored (http or https), the host
|
|
76
|
+
* is case-insensitive and may end in a dot, a default port is dropped, and the path must be /mcp in
|
|
77
|
+
* any case (repeated and trailing slashes allowed) with any query or fragment. */
|
|
78
|
+
export function isRetiredBoardUrl(value) {
|
|
79
|
+
if (typeof value !== "string") return false;
|
|
80
|
+
let url;
|
|
81
|
+
try { url = new URL(value.trim()); } catch { return false; }
|
|
82
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") return false;
|
|
83
|
+
// The path is /mcp in any case, with repeated or trailing slashes ("//mcp",
|
|
84
|
+
// "/MCP/"); the host may end in a dot ("app.glytch.ai.").
|
|
85
|
+
if (url.pathname.toLowerCase().replace(/\/{2,}/g, "/").replace(/\/+$/, "") !== "/mcp") return false;
|
|
86
|
+
// `new URL` lowercases the host and drops the scheme's default port; the
|
|
87
|
+
// other scheme's default (http on 443, https on 80) is dropped here.
|
|
88
|
+
const port = url.port === "" || url.port === "80" || url.port === "443" ? "" : `:${url.port}`;
|
|
89
|
+
const hostname = url.hostname.replace(/\.+$/, "");
|
|
90
|
+
return RETIRED_APP_URLS.some(origin => new URL(origin).host === `${hostname}${port}`);
|
|
91
|
+
}
|
|
74
92
|
export const BOARD_MCP_URL = (env = process.env) => {
|
|
75
93
|
const value = (env?.VIEWABLE_BOARD_URL ?? env?.GLYTCH_BOARD_URL);
|
|
76
94
|
return typeof value === "string" && value.trim() !== "" ? value.trim() : DEFAULT_BOARD_MCP_URL;
|
|
77
95
|
};
|
|
78
96
|
/** Run children already have a bearer, so use the runner's direct function
|
|
79
97
|
* host for the production MCP endpoint. Keep discovered/custom endpoints.
|
|
80
|
-
* The hosted project address stays owned by runnerApiUrlFrom (#813).
|
|
81
|
-
|
|
98
|
+
* The hosted project address stays owned by runnerApiUrlFrom (#813).
|
|
99
|
+
*
|
|
100
|
+
* A developer's `GLYTCH_BOARD_URL` / `VIEWABLE_BOARD_URL` wins over the
|
|
101
|
+
* app-derived address (#3705). Without it a runner on the local stack posted
|
|
102
|
+
* its collect and report calls to `<stack>/mcp`, which is not the board
|
|
103
|
+
* function (the stack answers 406 "Client must accept both application/json
|
|
104
|
+
* and text/event-stream"), so a finished run never wrote its summary.
|
|
105
|
+
*
|
|
106
|
+
* An override at a RETIRED host is not followed (#3717). Those hosts answer
|
|
107
|
+
* with a redirect, and a cross-origin redirect drops the Authorization
|
|
108
|
+
* header, so the runner would lose its sign-in. It is treated as unset (the
|
|
109
|
+
* derived function host is used) and `warn`, when given, is told why. */
|
|
110
|
+
export function runnerMcpUrlFrom({ appUrl, mcpUrl }, env = process.env, warn) {
|
|
111
|
+
const override = BOARD_MCP_URL(env);
|
|
112
|
+
if (isRetiredBoardUrl(override)) {
|
|
113
|
+
warn?.(`The board address ${override} is retired and redirects without the sign-in header; using the board function instead. Unset VIEWABLE_BOARD_URL or set it to ${DEFAULT_BOARD_MCP_URL}.`);
|
|
114
|
+
} else if (override !== DEFAULT_BOARD_MCP_URL) return override;
|
|
82
115
|
if (appUrl !== DEFAULT_APP_URL || mcpUrl !== DEFAULT_BOARD_MCP_URL) return mcpUrl;
|
|
83
116
|
const runnerUrl = new URL(runnerApiUrlFrom(appUrl, env));
|
|
84
117
|
// A trailing slash still names the runner endpoint, not a directory.
|
package/lib/memberPreview.mjs
CHANGED
|
@@ -4,9 +4,10 @@ import { createPublicKey, randomBytes, randomUUID, verify } from "node:crypto";
|
|
|
4
4
|
import { createPreviewGateway } from "./previewGateway.mjs";
|
|
5
5
|
import { startQuickPreviewTunnel } from "./previewTunnel.mjs";
|
|
6
6
|
|
|
7
|
-
export const PREVIEW_COOKIE = "
|
|
8
|
-
const
|
|
9
|
-
const
|
|
7
|
+
export const PREVIEW_COOKIE = "__viewable_preview";
|
|
8
|
+
const LEGACY_PREVIEW_COOKIE = "__glytch_preview";
|
|
9
|
+
const AUTH_PATH = "/__viewable_preview/auth";
|
|
10
|
+
const SESSION_PATH = "/__viewable_preview/session";
|
|
10
11
|
|
|
11
12
|
export function previewAuthConfig(env = process.env) {
|
|
12
13
|
if (!env.PREVIEW_VERIFY_JWK || !env.PM_PREVIEW_APP_ORIGINS) {
|
|
@@ -37,7 +38,7 @@ export function verifyPreviewGrant(token, key, expected, now = Date.now()) {
|
|
|
37
38
|
const [header, claims] = parts.slice(0, 2).map((p) => JSON.parse(Buffer.from(p, "base64url").toString("utf8")));
|
|
38
39
|
if (header.alg !== "RS256" || header.typ !== "JWT" || header.crit) return null;
|
|
39
40
|
if (!verify("RSA-SHA256", Buffer.from(`${parts[0]}.${parts[1]}`), key, Buffer.from(parts[2], "base64url"))) return null;
|
|
40
|
-
if (
|
|
41
|
+
if (!["viewable-preview", "glytch-preview"].includes(claims.iss) || typeof claims.sub !== "string" || !claims.sub) return null;
|
|
41
42
|
for (const field of ["aud", "boardId", "workspaceId", "nodeId", "runKey", "previewId"]) {
|
|
42
43
|
if (typeof expected[field] !== "string" || !expected[field] || claims[field] !== expected[field]) return null;
|
|
43
44
|
}
|
|
@@ -48,8 +49,13 @@ export function verifyPreviewGrant(token, key, expected, now = Date.now()) {
|
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
function cookie(req) {
|
|
51
|
-
const
|
|
52
|
-
|
|
52
|
+
const parts = String(req.headers.cookie ?? "").split(";").map((s) => s.trim());
|
|
53
|
+
for (const name of [PREVIEW_COOKIE, LEGACY_PREVIEW_COOKIE]) {
|
|
54
|
+
const matches = parts.filter((s) => s.startsWith(`${name}=`));
|
|
55
|
+
if (matches.length > 1) return "";
|
|
56
|
+
if (matches.length === 1) return matches[0].slice(name.length + 1);
|
|
57
|
+
}
|
|
58
|
+
return "";
|
|
53
59
|
}
|
|
54
60
|
|
|
55
61
|
const json = (res, status, body, extra = {}) => {
|
|
@@ -57,24 +63,25 @@ const json = (res, status, body, extra = {}) => {
|
|
|
57
63
|
res.end(JSON.stringify(body));
|
|
58
64
|
};
|
|
59
65
|
|
|
60
|
-
function authPage(appOrigins, nonce) {
|
|
66
|
+
function authPage(appOrigins, nonce, legacy = false) {
|
|
61
67
|
// Only the dedicated parent iframe can exchange a grant. Neither grant nor
|
|
62
68
|
// the application session token appears in a URL, referrer, or app response.
|
|
69
|
+
const prefix = legacy ? "glytch" : "viewable";
|
|
63
70
|
const origins = JSON.stringify(appOrigins).replaceAll("<", "\\u003c");
|
|
64
71
|
return `<!doctype html><meta charset="utf-8"><title>Preview access</title><script nonce="${nonce}">
|
|
65
72
|
const origins = ${origins};
|
|
66
73
|
addEventListener('message', async (event) => {
|
|
67
|
-
if (event.source !== parent || !origins.includes(event.origin) || event.data?.type !== '
|
|
74
|
+
if (event.source !== parent || !origins.includes(event.origin) || event.data?.type !== '${prefix}-preview-grant') return;
|
|
68
75
|
try {
|
|
69
76
|
const response = await fetch('${SESSION_PATH}', {method:'POST', credentials:'include', headers:{'content-type':'application/json'}, body:JSON.stringify({grant:event.data.grant})});
|
|
70
77
|
const result = await response.json();
|
|
71
78
|
if (!response.ok) throw Error();
|
|
72
79
|
const confirmed = await fetch('${SESSION_PATH}', {credentials:'include',cache:'no-store'});
|
|
73
80
|
if (!confirmed.ok) throw Error();
|
|
74
|
-
parent.postMessage({type:'
|
|
75
|
-
} catch { parent.postMessage({type:'
|
|
81
|
+
parent.postMessage({type:'${prefix}-preview-authorized',expiresAt:result.expiresAt}, event.origin);
|
|
82
|
+
} catch { parent.postMessage({type:'${prefix}-preview-error'}, event.origin); }
|
|
76
83
|
});
|
|
77
|
-
for (const origin of origins) parent.postMessage({type:'
|
|
84
|
+
for (const origin of origins) parent.postMessage({type:'${prefix}-preview-ready'}, origin);
|
|
78
85
|
</script>`;
|
|
79
86
|
}
|
|
80
87
|
|
|
@@ -107,15 +114,16 @@ export async function createMemberPreviewTunnel(origin, context, {
|
|
|
107
114
|
return grant.exp * 1000 > now() ? { expiresAt: grant.exp * 1000 } : false;
|
|
108
115
|
},
|
|
109
116
|
handleAuth: async (req, res) => {
|
|
110
|
-
const
|
|
111
|
-
|
|
117
|
+
const requestedPath = new URL(req.url, "http://gateway.invalid").pathname;
|
|
118
|
+
const path = requestedPath.replace(/^\/__glytch_preview\//, "/__viewable_preview/");
|
|
119
|
+
if (!path.startsWith("/__viewable_preview/")) return false;
|
|
112
120
|
if (!publicOrigin) { json(res, 503, { error: "Preview is connecting." }); return true; }
|
|
113
121
|
if (path === AUTH_PATH && req.method === "GET") {
|
|
114
122
|
const nonce = randomBytes(16).toString("base64");
|
|
115
123
|
res.writeHead(200, { "content-type": "text/html; charset=utf-8", "cache-control": "no-store",
|
|
116
124
|
"referrer-policy": "no-referrer", "x-content-type-options": "nosniff",
|
|
117
125
|
"content-security-policy": `default-src 'none'; script-src 'nonce-${nonce}'; connect-src 'self'; frame-ancestors ${appOrigins.join(" ")}; base-uri 'none'; form-action 'none'` });
|
|
118
|
-
res.end(authPage(appOrigins, nonce)); return true;
|
|
126
|
+
res.end(authPage(appOrigins, nonce, requestedPath.startsWith("/__glytch_preview/") && new URL(req.url, "http://gateway.invalid").searchParams.get("protocol") !== "viewable")); return true;
|
|
119
127
|
}
|
|
120
128
|
if (path === SESSION_PATH && req.method === "GET") {
|
|
121
129
|
const claims = check(cookie(req));
|
package/lib/multiwatch.mjs
CHANGED
|
@@ -38,12 +38,11 @@
|
|
|
38
38
|
// gets its sync and its watcher without anything being restarted.
|
|
39
39
|
|
|
40
40
|
import { makeRunnerHealth } from "./runner-health.mjs";
|
|
41
|
-
import {
|
|
41
|
+
import { unwatchFile, watchFile } from "node:fs";
|
|
42
42
|
import { stat } from "node:fs/promises";
|
|
43
|
-
import { basename, dirname } from "node:path";
|
|
44
43
|
import { makeAgentProbe } from "./detect.mjs";
|
|
45
44
|
import { platformMark } from "./platform.mjs";
|
|
46
|
-
import {
|
|
45
|
+
import { ensureViewableFolder } from "./viewableFolder.mjs";
|
|
47
46
|
import { readRegistryChecked, registryPath } from "./registry.mjs";
|
|
48
47
|
import { watch, newRunnerId } from "./runner.mjs";
|
|
49
48
|
import { RUNNER_BEAT_MS } from "./spawn.mjs";
|
|
@@ -54,13 +53,15 @@ import { syncFolder } from "./sync.mjs";
|
|
|
54
53
|
import { makeUpdateChecker, packageVersion } from "./update.mjs";
|
|
55
54
|
|
|
56
55
|
export const SWEEP_INTERVAL_MS = 86_400_000;
|
|
57
|
-
/** How often the registry is re-read when
|
|
58
|
-
* floor, not the mechanism:
|
|
59
|
-
*
|
|
60
|
-
* directory,
|
|
61
|
-
*
|
|
62
|
-
*
|
|
56
|
+
/** How often the registry is re-read when the stat poll below tells us
|
|
57
|
+
* nothing. The floor, not the mechanism: the stat poll answers within
|
|
58
|
+
* REGISTRY_STAT_MS, and this is what catches the cases where it does not - a
|
|
59
|
+
* network home directory, a file system whose stat times do not move. A
|
|
60
|
+
* minute is invisible to a person typing `viewable init` and then switching
|
|
61
|
+
* to the app. */
|
|
63
62
|
export const REGISTRY_POLL_MS = 60_000;
|
|
63
|
+
/** How often the registry file is stat'ed for a change (fs.watchFile). */
|
|
64
|
+
export const REGISTRY_STAT_MS = 1_000;
|
|
64
65
|
|
|
65
66
|
const isDir = async (path) => {
|
|
66
67
|
try {
|
|
@@ -109,9 +110,9 @@ export async function watchRegistered({
|
|
|
109
110
|
// watch is not asking the registry anything, so the live re-read below
|
|
110
111
|
// stands down for it. Nothing in the package passes this; the tests do.
|
|
111
112
|
const pinned = folders !== undefined;
|
|
112
|
-
// The Glytch folder (
|
|
113
|
+
// The Glytch folder (viewableFolder.mjs) is made and registered first, so a
|
|
113
114
|
// computer with no folder linked yet still has one to work in.
|
|
114
|
-
if (!pinned) await
|
|
115
|
+
if (!pinned) await ensureViewableFolder(env, log);
|
|
115
116
|
// When the registry file was last written, read before the list is: a
|
|
116
117
|
// rewrite that keeps the same folders is `glytch init` asking for a beat.
|
|
117
118
|
const registryStamp = async () => (await stat(registryPath(env)).catch(() => null))?.mtimeMs ?? null;
|
|
@@ -366,33 +367,25 @@ export async function watchRegistered({
|
|
|
366
367
|
}
|
|
367
368
|
};
|
|
368
369
|
|
|
369
|
-
//
|
|
370
|
-
//
|
|
371
|
-
//
|
|
372
|
-
//
|
|
373
|
-
//
|
|
374
|
-
// platform where fs.watch does nothing at all still picks a new folder up
|
|
375
|
-
// within registryPollMs.
|
|
370
|
+
// A STAT POLL ON THE FILE, NOT fs.watch (#4726). fs.watchFile stats the
|
|
371
|
+
// path, so it sees writeFileAtomic's rename, an edit in place and a file
|
|
372
|
+
// that does not exist yet. A folder fs.watch on macOS starts FSEvents, and
|
|
373
|
+
// closing it waits on fseventsd: a stuck one froze Ctrl-C on `runner watch`
|
|
374
|
+
// forever. setInterval below is still the floor.
|
|
376
375
|
const regPath = registryPath(env);
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
|
|
376
|
+
const onRegistryStat = (now, before) => {
|
|
377
|
+
if (now.mtimeMs === before.mtimeMs && now.ino === before.ino && now.size === before.size) return;
|
|
378
|
+
void refresh();
|
|
379
|
+
};
|
|
380
|
+
let statWatching = false;
|
|
381
|
+
if (!pinned) {
|
|
380
382
|
try {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
});
|
|
385
|
-
w.on("error", () => {}); // a dead watch is not an exit; the poll covers it
|
|
386
|
-
w.unref?.();
|
|
387
|
-
fsWatchers.push(w);
|
|
383
|
+
// persistent: false - the keepAlive below owns the process lifetime.
|
|
384
|
+
watchFile(regPath, { persistent: false, interval: REGISTRY_STAT_MS }, onRegistryStat);
|
|
385
|
+
statWatching = true;
|
|
388
386
|
} catch {
|
|
389
|
-
//
|
|
390
|
-
// poll is the answer to both.
|
|
387
|
+
// A path that cannot be stat-watched is not an exit; the poll covers it.
|
|
391
388
|
}
|
|
392
|
-
};
|
|
393
|
-
if (!pinned) {
|
|
394
|
-
attach(regPath, false);
|
|
395
|
-
attach(dirname(regPath), true);
|
|
396
389
|
}
|
|
397
390
|
const polling = setInterval(() => void refresh(), registryPollMs);
|
|
398
391
|
polling.unref?.();
|
|
@@ -416,13 +409,7 @@ export async function watchRegistered({
|
|
|
416
409
|
signal?.removeEventListener("abort", bump);
|
|
417
410
|
clearInterval(sweeping);
|
|
418
411
|
clearInterval(polling);
|
|
419
|
-
|
|
420
|
-
try {
|
|
421
|
-
w.close();
|
|
422
|
-
} catch {
|
|
423
|
-
// closing twice, or after an error, is not a failure worth a line
|
|
424
|
-
}
|
|
425
|
-
}
|
|
412
|
+
if (statWatching) unwatchFile(regPath, onRegistryStat);
|
|
426
413
|
}
|
|
427
414
|
return { watched, missing };
|
|
428
415
|
}
|
package/lib/pagePictures.mjs
CHANGED
|
@@ -22,6 +22,7 @@ import { createServer } from "node:net";
|
|
|
22
22
|
import { tmpdir } from "node:os";
|
|
23
23
|
import { delimiter, join } from "node:path";
|
|
24
24
|
import { devServerEnv } from "./child.mjs";
|
|
25
|
+
import { OUT_OF_TIME } from "./codingChecks.mjs";
|
|
25
26
|
import { killTree } from "./kill.mjs";
|
|
26
27
|
import { pageOf, isScreenFile } from "./pageRoutes.mjs";
|
|
27
28
|
import { runnableCommand } from "./windows-command.mjs";
|
|
@@ -52,7 +53,7 @@ const LINUX_BINS = ["google-chrome", "google-chrome-stable", "microsoft-edge", "
|
|
|
52
53
|
/** A browser already on this computer, as `{bin, args}`, or null. Nothing is
|
|
53
54
|
* ever downloaded. `GLYTCH_BROWSER` names one, or `none` turns pictures off. */
|
|
54
55
|
export function findBrowser({ env = process.env, platform = process.platform, exists = existsSync } = {}) {
|
|
55
|
-
const named = env.GLYTCH_BROWSER?.trim();
|
|
56
|
+
const named = (env.VIEWABLE_BROWSER ?? env.GLYTCH_BROWSER)?.trim();
|
|
56
57
|
if (named) return named.toLowerCase() === "none" ? null : { bin: named, args: [] };
|
|
57
58
|
const candidates = [];
|
|
58
59
|
if (platform === "darwin") {
|
|
@@ -75,7 +76,7 @@ export function findBrowser({ env = process.env, platform = process.platform, ex
|
|
|
75
76
|
// ---------- the browser, over its DevTools pipe ----------
|
|
76
77
|
|
|
77
78
|
/** Start the browser headless with a fresh profile it forgets afterwards. */
|
|
78
|
-
export async function openBrowser(browser, { platform = process.platform, stopCheck, deadline = Infinity } = {}) {
|
|
79
|
+
export async function openBrowser(browser, { platform = process.platform, stopCheck, onProcess, deadline = Infinity } = {}) {
|
|
79
80
|
const profile = await mkdtemp(join(tmpdir(), "viewable-browser-"));
|
|
80
81
|
const args = [
|
|
81
82
|
...browser.args, "--headless=new", "--remote-debugging-pipe", `--user-data-dir=${profile}`,
|
|
@@ -84,7 +85,8 @@ export async function openBrowser(browser, { platform = process.platform, stopCh
|
|
|
84
85
|
`--window-size=${VIEWPORT.width},${VIEWPORT.height}`, "about:blank",
|
|
85
86
|
];
|
|
86
87
|
// The person's own browser, but not the runner's secrets.
|
|
87
|
-
const child = spawn(browser.bin, args, { stdio: ["ignore", "ignore", "ignore", "pipe", "pipe"], windowsHide: true, env: devServerEnv(process.env, platform) });
|
|
88
|
+
const child = spawn(browser.bin, args, { stdio: ["ignore", "ignore", "ignore", "pipe", "pipe"], windowsHide: true, detached: Boolean(onProcess) && platform !== "win32", env: devServerEnv(process.env, platform) });
|
|
89
|
+
onProcess?.(child.pid);
|
|
88
90
|
const waiting = new Map();
|
|
89
91
|
const listeners = new Set();
|
|
90
92
|
let nextId = 1;
|
|
@@ -254,7 +256,7 @@ async function appScript(dir) {
|
|
|
254
256
|
}
|
|
255
257
|
|
|
256
258
|
/** Start the folder's app on a free port and wait until it answers. */
|
|
257
|
-
export async function startApp(dir, { env, platform = process.platform, deadline, stopCheck, killGraceMs = 3_000, fetchImpl = fetch }) {
|
|
259
|
+
export async function startApp(dir, { env, platform = process.platform, deadline, stopCheck, killGraceMs = 3_000, onProcess, fetchImpl = fetch }) {
|
|
258
260
|
const found = await appScript(dir);
|
|
259
261
|
if (!found.script) return { ok: false, missing: found.missing };
|
|
260
262
|
const port = await freePort();
|
|
@@ -264,6 +266,7 @@ export async function startApp(dir, { env, platform = process.platform, deadline
|
|
|
264
266
|
stdio: ["ignore", "pipe", "pipe"],
|
|
265
267
|
env: { ...devServerEnv(env, platform), ...(port ? { PORT: String(port) } : {}), BROWSER: "none", NO_COLOR: "1", FORCE_COLOR: "0" },
|
|
266
268
|
});
|
|
269
|
+
onProcess?.(child.pid);
|
|
267
270
|
let log = "";
|
|
268
271
|
let exited = false;
|
|
269
272
|
const take = (chunk) => { log = (log + String(chunk)).slice(-8_000); };
|
|
@@ -330,7 +333,7 @@ async function pictureOf(dir, page, browser, options) {
|
|
|
330
333
|
* `files` are the paths the run changed. `folder` is where the app is tried
|
|
331
334
|
* when the copy's does not start: if it does not start there either, the
|
|
332
335
|
* check is skipped (not the run's doing), never failed. */
|
|
333
|
-
export async function checkPage({ cwd, folder, files, env, baseEnv = process.env, platform = process.platform, deadline, stopCheck, killGraceMs, browser: given, fetchImpl }) {
|
|
336
|
+
export async function checkPage({ cwd, folder, files, env, baseEnv = process.env, platform = process.platform, deadline, stopCheck, killGraceMs, onProcess, browser: given, fetchImpl }) {
|
|
334
337
|
// A page the run deleted has no address left to open.
|
|
335
338
|
const screens = files.filter((file) => isScreenFile(file) && existsSync(join(cwd, file)));
|
|
336
339
|
if (screens.length === 0) return null;
|
|
@@ -339,11 +342,11 @@ export async function checkPage({ cwd, folder, files, env, baseEnv = process.env
|
|
|
339
342
|
const browser = given === undefined ? findBrowser({ env: baseEnv, platform }) : given;
|
|
340
343
|
if (!browser) return { page, check: check("skipped", "No browser was found on this computer."), note: NO_BROWSER };
|
|
341
344
|
if (await stopCheck?.()) return { page, browser, stopped: true, check: check("skipped", "Stopped before this check finished.") };
|
|
342
|
-
if (Date.now() >= deadline) return { page, browser, check: check("
|
|
343
|
-
const options = { env, platform, deadline, stopCheck, killGraceMs, ...(fetchImpl ? { fetchImpl } : {}) };
|
|
345
|
+
if (Date.now() >= deadline) return { page, browser, check: check("skipped", OUT_OF_TIME) };
|
|
346
|
+
const options = { env, platform, deadline, stopCheck, killGraceMs, onProcess, ...(fetchImpl ? { fetchImpl } : {}) };
|
|
344
347
|
let opened;
|
|
345
348
|
let stoppedStarting = false;
|
|
346
|
-
try { opened = await openBrowser(browser, { platform, stopCheck, deadline }); } catch (error) { opened = null; stoppedStarting = error.stopped === true; }
|
|
349
|
+
try { opened = await openBrowser(browser, { platform, stopCheck, deadline, onProcess }); } catch (error) { opened = null; stoppedStarting = error.stopped === true; }
|
|
347
350
|
if (stoppedStarting) return { page, browser, stopped: true, check: check("skipped", "Stopped before this check finished.") };
|
|
348
351
|
if (!opened) return { page, check: check("skipped", "The browser on this computer did not start."), note: NO_BROWSER };
|
|
349
352
|
try {
|
|
@@ -352,7 +355,7 @@ export async function checkPage({ cwd, folder, files, env, baseEnv = process.env
|
|
|
352
355
|
if (after.browserGone) return { page, browser, check: check("skipped", "The browser on this computer closed."), note: BROWSER_CLOSED };
|
|
353
356
|
if (after.missing === "script") return { page, browser, check: check("skipped", "This folder has no app to start."), note: NO_APP_SCRIPT };
|
|
354
357
|
if (after.missing === "dependencies") return { page, browser, check: check("skipped", "The folder's dependencies are not installed."), note: NO_APP };
|
|
355
|
-
if (after.timedOut) return { page, browser, check: check("
|
|
358
|
+
if (after.timedOut) return { page, browser, check: check("skipped", OUT_OF_TIME) };
|
|
356
359
|
if (!after.started) {
|
|
357
360
|
const there = folder ? await startApp(folder, options) : { ok: false };
|
|
358
361
|
if (there.ok) await there.stop();
|
|
@@ -377,13 +380,13 @@ export async function checkPage({ cwd, folder, files, env, baseEnv = process.env
|
|
|
377
380
|
|
|
378
381
|
/** Before, from the folder, and the changed part of After. Pictures that do
|
|
379
382
|
* not differ mean the wrong page was opened: no pictures at all. */
|
|
380
|
-
export async function beforePicture({ folder, page, after, browser, env, platform = process.platform, deadline, stopCheck, killGraceMs, fetchImpl }) {
|
|
383
|
+
export async function beforePicture({ folder, page, after, browser, env, platform = process.platform, deadline, stopCheck, killGraceMs, onProcess, fetchImpl }) {
|
|
381
384
|
if (!after || !browser) return {};
|
|
382
385
|
if (!folder || await stopCheck?.() || Date.now() >= deadline) return { after };
|
|
383
386
|
let opened;
|
|
384
|
-
try { opened = await openBrowser(browser, { platform, stopCheck, deadline }); } catch { return { after }; }
|
|
387
|
+
try { opened = await openBrowser(browser, { platform, stopCheck, deadline, onProcess }); } catch { return { after }; }
|
|
385
388
|
try {
|
|
386
|
-
const before = await pictureOf(folder, page, opened, { env, platform, deadline, stopCheck, killGraceMs, ...(fetchImpl ? { fetchImpl } : {}) });
|
|
389
|
+
const before = await pictureOf(folder, page, opened, { env, platform, deadline, stopCheck, killGraceMs, onProcess, ...(fetchImpl ? { fetchImpl } : {}) });
|
|
387
390
|
if (!before.started || !before.ok || !before.image) return { after };
|
|
388
391
|
let changed = null;
|
|
389
392
|
try { changed = await opened.changedArea(before.image, after); } catch { return { before: before.image, after }; }
|
package/lib/pageRoutes.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { readFile } from "node:fs/promises";
|
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
|
|
7
7
|
/** The file a session writes in its copy's root to name the page it changed. */
|
|
8
|
-
export const PAGE_RECORD_FILE = ".
|
|
8
|
+
export const PAGE_RECORD_FILE = ".viewable-page.json";
|
|
9
9
|
|
|
10
10
|
const SCREEN_EXT = /\.(?:tsx|jsx|vue|svelte|astro|html|css|scss|sass|less)$/i;
|
|
11
11
|
const NOT_SCREEN = /(?:\.(?:test|spec|stories)\.[a-z]+$|(?:^|\/)(?:__tests__|tests?|e2e)\/)/i;
|
|
@@ -52,7 +52,10 @@ export function pageNameOf(path) {
|
|
|
52
52
|
* of a changed page file, else the home page. */
|
|
53
53
|
export async function pageOf(cwd, files) {
|
|
54
54
|
try {
|
|
55
|
-
const record = JSON.parse(await readFile(join(cwd, PAGE_RECORD_FILE), "utf8"))
|
|
55
|
+
const record = JSON.parse(await readFile(join(cwd, PAGE_RECORD_FILE), "utf8").catch((error) => {
|
|
56
|
+
if (error.code !== "ENOENT") throw error;
|
|
57
|
+
return readFile(join(cwd, ".glytch-page.json"), "utf8");
|
|
58
|
+
}));
|
|
56
59
|
const path = typeof record?.path === "string" ? record.path.trim() : "";
|
|
57
60
|
if (/^\/(?!\/)[^\s]{0,300}$/.test(path)) {
|
|
58
61
|
const name = typeof record.name === "string" ? record.name.replace(/\s+/g, " ").trim().slice(0, 60) : "";
|
package/lib/paths.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Local runner scratch and image staging. Board coordination uses hosted rows.
|
|
2
2
|
// Historical request files and the repo-map cache still live under SPAWN_DIR.
|
|
3
3
|
|
|
4
|
-
export const BOARD_DIR = ".
|
|
5
|
-
|
|
6
|
-
export const SPAWN_DIR =
|
|
4
|
+
export const BOARD_DIR = ".viewable";
|
|
5
|
+
// Kept on purpose: the sweep reads receipts written by old runners.
|
|
6
|
+
export const SPAWN_DIR = ".glytch/inbox/spawn";
|
|
7
7
|
|
|
8
8
|
/** Path segments, for join(root, ...segmentsOf(DIR)). */
|
|
9
9
|
export const segmentsOf = (dir) => dir.split("/");
|