@runeditrun/rer 0.2.49 → 0.2.51
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/cli/companion/recovery.mjs +3 -2
- package/cli/deploy-needs.mjs +1 -1
- package/cli/errors.mjs +1 -1
- package/cli/independent.mjs +12 -13
- package/cli/inspect.mjs +4 -1
- package/cli/lifecycle.mjs +4 -1
- package/cli/node-runtime.mjs +1 -1
- package/cli/pnpm-runtime.mjs +1 -2
- package/cli/production-mail.mjs +6 -1
- package/cli/project-pnpm.mjs +3 -4
- package/global/CHANGELOG.md +14 -0
- package/global/cli/layout.mjs +6 -3
- package/global/run.mjs +13 -4
- package/install.sh +8 -6
- package/modules/delivery-producer/declarations.mjs +5 -3
- package/modules/deploy-kit/README.md +1 -1
- package/modules/deploy-kit/migration-ledger.mjs +25 -12
- package/modules/deploy-kit/migrations.mjs +4 -4
- package/modules/job-queue/index.mjs +3 -5
- package/modules/operator-auth/README.md +5 -2
- package/modules/operator-auth/dev/index.mjs +1 -1
- package/modules/operator-auth/dev-gate.mjs +21 -8
- package/modules/operator-auth/index.d.mts +1 -1
- package/onboarding/adapter.mjs +3 -3
- package/onboarding/busy.mjs +21 -0
- package/onboarding/commands.mjs +12 -7
- package/onboarding/failures.mjs +7 -0
- package/onboarding/operator-installer.mjs +1 -1
- package/onboarding/queue.mjs +3 -2
- package/onboarding/tool-command.mjs +7 -0
- package/package.json +1 -1
|
@@ -25,8 +25,9 @@ export async function confirmUnstarted(root,state,jobId,confirmed) {
|
|
|
25
25
|
throw new Error('Only an exact legacy preparation failure without executor or pending-control state can be attested.');
|
|
26
26
|
let workspace;
|
|
27
27
|
const worktree=join(root,'worktrees',jobId);
|
|
28
|
-
const
|
|
29
|
-
if(
|
|
28
|
+
const info=await lstat(worktree).catch(error=>{if(error.code==='ENOENT')return null;throw error;});
|
|
29
|
+
if(info) {
|
|
30
|
+
if(!info.isDirectory() || info.isSymbolicLink())throw new Error('Retained worktree must be an ordinary directory.');
|
|
30
31
|
const mapping=state.mappings[active.job.project_id];
|
|
31
32
|
if(!mapping || mapping.repository!==active.job.repository || !/^[a-f0-9]{40}$/.test(active.job.base_commit||''))throw new Error('Retained worktree cannot be verified against approved mapping.');
|
|
32
33
|
const inside=retainedGit(root,worktree);
|
package/cli/deploy-needs.mjs
CHANGED
|
@@ -48,7 +48,7 @@ export function neededForRealDeploy({ declaration, env, signIn }) {
|
|
|
48
48
|
return [
|
|
49
49
|
...(credentials.length ? [`${credentials.join(' and ')} (${credentialHelp(declaration).join(' ')})`] : []),
|
|
50
50
|
...secrets,
|
|
51
|
-
...(mail ? [`production sign-in mail: ${mail}`] : []),
|
|
51
|
+
...(mail ? [`production sign-in mail: ${mail}${deployGuide(declaration) ? ` (see ${deployGuide(declaration)})` : ''}`] : []),
|
|
52
52
|
];
|
|
53
53
|
}
|
|
54
54
|
|
package/cli/errors.mjs
CHANGED
|
@@ -14,5 +14,5 @@ export async function lifecycleError(error, store) {
|
|
|
14
14
|
const {shared}=await import('./shared.mjs');
|
|
15
15
|
const {approvedFailure}=await shared('failures.mjs');
|
|
16
16
|
const approved=approvedFailure(error);
|
|
17
|
-
return new RerError(approved?.code
|
|
17
|
+
return new RerError(['owner_conflict','machine_busy'].includes(approved?.code)?'safety_refusal':'command_failed', approved?.message ?? `${store?.state?.step ?? 'Local lifecycle'} failed. Inspect the private redacted capture log.`, approved?.exitCode ?? 1, {childExitCode:approved?.childExitCode,signal:approved?.signal});
|
|
18
18
|
}
|
package/cli/independent.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { isAbsolute } from 'node:path';
|
|
2
|
+
import { constants } from 'node:os';
|
|
2
3
|
import { inspectRequiredLoops } from '../operations/project-operations.mjs';
|
|
3
4
|
import { contained } from './project.mjs';
|
|
4
|
-
import { missing, refuse, RerError } from './errors.mjs';
|
|
5
|
+
import { missing, refuse, RerError, lifecycleError } from './errors.mjs';
|
|
6
|
+
import { shared } from './shared.mjs';
|
|
5
7
|
|
|
6
8
|
export async function executeDeclared(project, options, store, signal) {
|
|
7
9
|
if (project.descriptor.version !== 2) throw refuse('Execution requires explicit OPERATIONS v2 argv; version 1 remains inspection-only.');
|
|
@@ -13,17 +15,14 @@ export async function executeDeclared(project, options, store, signal) {
|
|
|
13
15
|
if (absent.length || loops.some(loop => !['ready', 'optional-disabled'].includes(loop.status))) throw missing(`Required declared inputs or loops are missing. See ${project.descriptor.documentation?.document ?? 'the project operating documentation'}.`);
|
|
14
16
|
const [program, ...argv] = command.argv;
|
|
15
17
|
if (!isAbsolute(program) && (program.includes('/') || program.includes('\\'))) await contained(project.root, program);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
try {
|
|
19
|
+
await store.run('Running declared project command', program, [...argv, ...options.forwarded], { cwd: project.root, signal });
|
|
20
|
+
return { childExitCode: 0, signal: null };
|
|
21
|
+
} catch (error) {
|
|
22
|
+
const { isBusyFailure } = await shared('failures.mjs');
|
|
23
|
+
if (isBusyFailure(error)) throw error;
|
|
24
|
+
const diagnostic = await lifecycleError(error, store);
|
|
25
|
+
const code = error.signal ? 128 + (constants.signals[error.signal] ?? 0) : Number.isInteger(error.childExitCode) && error.childExitCode >= 0 ? error.childExitCode : 3;
|
|
26
|
+
throw new RerError('child_failed', diagnostic.message, code, { childExitCode: error.childExitCode, signal: error.signal });
|
|
19
27
|
}
|
|
20
|
-
const child = store.spawn('Running declared project command', program, [...argv, ...options.forwarded], { cwd: project.root, signal });
|
|
21
|
-
const completion = new Promise(resolve => { child.once('error', () => resolve({ error: true })); child.once('close', (code, terminationSignal) => resolve({ code, signal: terminationSignal })); });
|
|
22
|
-
await new Promise(resolve => { child.once('error', resolve); child.once('exit', resolve); });
|
|
23
|
-
await store.stop(child);
|
|
24
|
-
const result = await completion;
|
|
25
|
-
if (result.error) throw missing('The declared command executable is unavailable. See the project runtime requirements.');
|
|
26
|
-
const exitCode = result.signal ? ({ SIGINT: 130, SIGTERM: 143 }[result.signal] ?? 1) : result.code;
|
|
27
|
-
if (exitCode !== 0) throw new RerError('child_failed', 'The declared command failed.', exitCode, { childExitCode: result.code, signal: result.signal });
|
|
28
|
-
return { childExitCode: result.code, signal: result.signal };
|
|
29
28
|
}
|
package/cli/inspect.mjs
CHANGED
|
@@ -161,7 +161,10 @@ export async function tools(root, store, signal) {
|
|
|
161
161
|
const { ensureProjectPnpm } = await import('./project-pnpm.mjs');
|
|
162
162
|
await ensureProjectPnpm(root, { signal, store, report: text => store.report?.(text) });
|
|
163
163
|
}
|
|
164
|
-
const usePnpm = directory => {
|
|
164
|
+
const usePnpm = directory => {
|
|
165
|
+
process.env.RER_PNPM_ENTRY = resolve(directory, '..', 'bin', 'pnpm.cjs');
|
|
166
|
+
process.env.PATH = [process.env.PATH, directory, dirname(process.execPath)].filter(value => value !== undefined).join(delimiter);
|
|
167
|
+
};
|
|
165
168
|
|
|
166
169
|
export async function doctor(project, store, signal) {
|
|
167
170
|
const { inspectOperations } = await import('../operations/operations.mjs');
|
package/cli/lifecycle.mjs
CHANGED
|
@@ -167,7 +167,8 @@ async function runLifecycle(project, options, out, deployRedaction) {
|
|
|
167
167
|
try { await close(); } catch (error) { unclosed.push(store?.redact?.(String(error?.message)) ?? 'unknown cause'); }
|
|
168
168
|
}
|
|
169
169
|
if (unclosed.length && !failed) out.progress(`Local cleanup could not confirm that every helper process stopped (${unclosed.join('; ')}). The ${options.verb} itself finished.\n`);
|
|
170
|
-
|
|
170
|
+
// A failed independent command's diagnostic points here for its full output.
|
|
171
|
+
if (temporary && !failed) await rm(temporary, { recursive: true, force: true });
|
|
171
172
|
for (const [name, handler] of handlers) process.removeListener(name, handler);
|
|
172
173
|
if (termination) throw new RerError('cancelled', `Stopped by ${termination} after owned children were stopped.`, termination === 'SIGINT' ? 130 : 143);
|
|
173
174
|
}
|
|
@@ -184,6 +185,8 @@ async function hostedNeeds(project) {
|
|
|
184
185
|
// full log. A step that stopped outside a command still names the step and log.
|
|
185
186
|
async function installStepError(error, store, root) {
|
|
186
187
|
const { approvedFailure } = await shared('failures.mjs');
|
|
188
|
+
// A step the job queue never admitted is a busy machine; its message already says what to do.
|
|
189
|
+
if (approvedFailure(error)?.code === 'machine_busy') return error;
|
|
187
190
|
const { checkoutPath, stepDiagnostic, stepFailureText } = await shared('step-failure.mjs');
|
|
188
191
|
const step = approvedFailure(error)?.step ?? stepDiagnostic({ name: store.state.step, output: store.state.logs, log: store.redact(checkoutPath(root, store.logPath)) });
|
|
189
192
|
// Only a RerError's message or a symbolic error code is safe to show; a native message can hold private data.
|
package/cli/node-runtime.mjs
CHANGED
|
@@ -39,7 +39,7 @@ export async function selectNodeRuntime(options, argv, out) {
|
|
|
39
39
|
if (options.json) out.event('node-selection', { versionSelected: version, previousVersion: process.versions.node, message });
|
|
40
40
|
else out.human(message);
|
|
41
41
|
child = spawn(binary, [...process.execArgv, process.argv[1], ...argv], {
|
|
42
|
-
cwd: process.cwd(), stdio: 'inherit', env: { ...process.env,
|
|
42
|
+
cwd: process.cwd(), stdio: 'inherit', env: { ...process.env, RER_NODE_BINARY: binary, PATH: [process.env.PATH, dirname(binary)].filter(value => value !== undefined).join(delimiter) },
|
|
43
43
|
});
|
|
44
44
|
const result = await new Promise((resolve, reject) => {
|
|
45
45
|
child.once('error', reject);
|
package/cli/pnpm-runtime.mjs
CHANGED
|
@@ -85,8 +85,7 @@ export async function downloadPnpm(version, cancellation, { registry = 'https://
|
|
|
85
85
|
const extracted = join(temporary, 'package');
|
|
86
86
|
if (JSON.parse(await readFile(join(extracted, 'package.json'), 'utf8')).version !== version) throw Error('Verified pnpm release did not name the project pin.');
|
|
87
87
|
await mkdir(join(extracted, 'shim'), { mode: 0o700 });
|
|
88
|
-
|
|
89
|
-
await writeFile(join(extracted, 'shim', 'pnpm'), `#!/bin/sh\nexec node ${shellQuote(entry(version, env))} "$@"\n`, { mode: 0o700 });
|
|
88
|
+
await writeFile(join(extracted, 'shim', 'pnpm'), `#!/bin/sh\nexec ${shellQuote(process.execPath)} ${shellQuote(entry(version, env))} "$@"\n`, { mode: 0o700 });
|
|
90
89
|
await writeFile(join(extracted, '.rer-verified.json'), JSON.stringify({ version, integrity, entrySha256: await digest(join(extracted, 'bin', 'pnpm.cjs'), 'sha256', 'hex') }) + '\n', { flag: 'wx', mode: 0o600 });
|
|
91
90
|
await chmod(extracted, 0o700);
|
|
92
91
|
try { await rename(extracted, directoryOf(version, env)); }
|
package/cli/production-mail.mjs
CHANGED
|
@@ -50,13 +50,18 @@ export async function productionMail(root, declaration, env) {
|
|
|
50
50
|
const credentialKeys = deferred && nativeCredential[provider] && !declaredProviders.has(provider) ? [nativeCredential[provider]]
|
|
51
51
|
: ['MAIL_API_KEY', ...(nativeCredential[provider] ? [nativeCredential[provider]] : [])];
|
|
52
52
|
const declaredCredentials = credentialKeys.filter(key => secrets.has(key));
|
|
53
|
+
// Only resend and sendgrid have a provider key of their own; cloudflare and rer send with MAIL_API_KEY alone.
|
|
54
|
+
const providerKeys = (nativeCredential[provider] ? [nativeCredential[provider]] : []).filter(key => !declaredCredentials.includes(key));
|
|
55
|
+
const credentialText = declaredCredentials.includes('MAIL_API_KEY') && providerKeys.length
|
|
56
|
+
? `MAIL_API_KEY (or ${providerKeys.join(' / ')})`
|
|
57
|
+
: declaredCredentials.join(' or ') || credentialKeys.join(' or ');
|
|
53
58
|
return live => {
|
|
54
59
|
let relaySelected = true;
|
|
55
60
|
if (provider === 'rer') try { validateRerConfig({ relayUrl: bindings.MAIL_RELAY_URL }); } catch { relaySelected = false; }
|
|
56
61
|
const has = key => present(bindings[key]) || secrets.has(key) && live.includes(key);
|
|
57
62
|
return [
|
|
58
63
|
...(!sender(bindings.MAIL_FROM) ? [SENDER] : []),
|
|
59
|
-
...(!credentialKeys.some(has) ? [
|
|
64
|
+
...(!credentialKeys.some(has) ? [credentialText] : []),
|
|
60
65
|
...(provider === 'cloudflare' && !has('MAIL_ACCOUNT_ID') ? ['MAIL_ACCOUNT_ID'] : []),
|
|
61
66
|
...(!relaySelected ? ['MAIL_RELAY_URL (assigned HTTPS relay URL)'] : []),
|
|
62
67
|
];
|
package/cli/project-pnpm.mjs
CHANGED
|
@@ -58,10 +58,9 @@ async function ensure(root, { env = process.env, signal, report = () => {}, stor
|
|
|
58
58
|
throw missing(`pnpm ${pin} could not be fetched (${error.message}). Retry with a working connection, or run in this shell: npm install --prefix ${shellQuote(prefix)} --no-save pnpm@${pin} && export PATH=${shellQuote(join(prefix, 'node_modules/.bin'))}:"$PATH"`);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
const supplied = { ...env, PATH: [directory, dirname(process.execPath), env.PATH].filter(Boolean).join(delimiter) };
|
|
61
|
+
// The runner invokes this verified entry with its exact Node. Added tool
|
|
62
|
+
// directories remain after the caller's tools, including their Git.
|
|
63
|
+
const supplied = { ...env, RER_PNPM_ENTRY: join(directory, '..', 'bin', 'pnpm.cjs'), PATH: [env.PATH, directory, dirname(process.execPath)].filter(value => value !== undefined).join(delimiter) };
|
|
65
64
|
// A fresh pnpm's first run can stall or fail once (a cold start on a busy
|
|
66
65
|
// machine): the check settles with a bounded retry, then names what failed.
|
|
67
66
|
let result;
|
package/global/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.51
|
|
4
|
+
|
|
5
|
+
- **The Run page keeps commands clear of Copy.** Command blocks wrap beside the button while there is room and below it at narrower widths. The dev sign-in hand-off page now shows the seed’s own logo, or its product name when it declares no logo (#236).
|
|
6
|
+
- **Missing scripts and mail credentials are named.** `rer run X` checks the checkout’s scripts before fetching or spawning pnpm, names a missing script and the available scripts, and exits 2. Setup and deploy dry runs list the declared mail provider’s own API key alongside `MAIL_API_KEY` and link the project’s deploy guide (#237).
|
|
7
|
+
- **Commands keep the caller’s tool order and explain failures.** Rer preserves PATH order while selecting its pinned Node and pnpm explicitly. A failed command names the executable, exit code or signal, a redacted output tail, and the retained full log (#240).
|
|
8
|
+
- **Deploy accepts migration history with gaps in name order.** Applied rows must each name a build migration once and match its recorded bytes, including reviewed rewrites. Rer applies the missing migrations in name order and verifies the final ledger by name and digest. Unknown names, changed bytes and unconfirmed claims remain refused. This supports HappyToHelp’s production upgrade when newer migrations sort below already applied rows (#241).
|
|
9
|
+
|
|
10
|
+
- **Companion recovery checks retained paths.** A legacy recovery confirmation refuses a symlinked retained checkout before reading it. Verify now exercises the companion OS boundary on macOS while retaining portable Linux coverage (#239).
|
|
11
|
+
|
|
12
|
+
## 0.2.50
|
|
13
|
+
|
|
14
|
+
- **Seeds can declare an owner sign-in route.** The delivery producer, in Base and in each seed's vendored copy, now accepts an optional `surfaces.app.signIn.ownerSignIn` path, such as `"/auth/owner-signin"`. This is the route that accepts the platform's owner sign-in grant. The platform binds `RER_PREVIEW_OWNER_SIGNIN` to the declared path, and only when a seed declares it. The path follows the same rules as `signIn.path`, and the producer still refuses unknown keys and values such as `//evil` or `https://x` (#234).
|
|
15
|
+
- **`rer dev` says when the computer is busy.** When the job queue or the machine's load holds a setup step until its wait runs out, `rer dev` (and setup, build, preview, deploy and verify) now prints "Not started: this computer is busy" with the measured 1-minute load, the threshold and what to do next: run the same command again, or raise `RER_JOBS_LOAD_THRESHOLD`. It exits 4, like the server load guard. Before, the hold was reported as "Local migrations failed". A real migration failure keeps its own message and captured output. The job queue's `maxWait` now bounds only a blocked wait, so a job the machine can run is admitted even when the queue's first lock, reclaim and sample pass takes longer than `maxWait` (#221).
|
|
16
|
+
|
|
3
17
|
## 0.2.49
|
|
4
18
|
|
|
5
19
|
- **Large imports no longer fail with D1's request limit.** The import kit sized each D1 batch from the data statements alone and left out the authority, progress, scope and return checks that `atomic()` adds to the same request. A large import could therefore build one request just over D1's limit and stop with 409 `IMPORT_D1_REQUEST_LIMIT`: Nook's 3,547-entry Slack import stopped at checkpoint 51, where the estimate said 524 statements and the request held 573 against 572 remaining. Each batch is now sized with `atomicCount()`, the same count `atomic()` sends. The apply, reverse and fenced-reversal planners share it, because undo had the same gap. Nook's import now applies all 3,547 entries in 78 saved batches (#230).
|
package/global/cli/layout.mjs
CHANGED
|
@@ -22,14 +22,17 @@ ${marker}
|
|
|
22
22
|
# It uses the installer's private Node when present, otherwise Node on PATH.
|
|
23
23
|
root=${quote(data)}
|
|
24
24
|
if [ -x "$root/node/bin/node" ]; then
|
|
25
|
-
|
|
25
|
+
node="$root/node/bin/node"
|
|
26
|
+
PATH="$PATH:$root/node/bin"
|
|
26
27
|
export PATH
|
|
28
|
+
else
|
|
29
|
+
node=$(command -v node) || node=
|
|
27
30
|
fi
|
|
28
|
-
if
|
|
31
|
+
if [ -z "$node" ]; then
|
|
29
32
|
echo "rer: Node is missing. Run: curl -fsSL https://runeditrun.com/install.sh | sh" >&2
|
|
30
33
|
exit 127
|
|
31
34
|
fi
|
|
32
|
-
exec node "$root/current/global/rer.mjs" "$@"
|
|
35
|
+
exec "$node" "$root/current/global/rer.mjs" "$@"
|
|
33
36
|
`;
|
|
34
37
|
}
|
|
35
38
|
|
package/global/run.mjs
CHANGED
|
@@ -8,6 +8,7 @@ import { readFile } from 'node:fs/promises';
|
|
|
8
8
|
import { constants } from 'node:os';
|
|
9
9
|
import { delimiter, dirname, join } from 'node:path';
|
|
10
10
|
import { locate } from './checkout.mjs';
|
|
11
|
+
import { shared } from '../cli/shared.mjs';
|
|
11
12
|
|
|
12
13
|
export const runUsage = `Usage: rer run [--cwd DIR] [SCRIPT [ARGS...]]
|
|
13
14
|
Runs a package.json script of this checkout as pnpm run SCRIPT ARGS would, with the
|
|
@@ -25,7 +26,8 @@ async function projectNode(root, env) {
|
|
|
25
26
|
let binary = await installedRuntime(version);
|
|
26
27
|
try { binary ??= await downloadRuntime(version); }
|
|
27
28
|
catch (error) { if (error instanceof RerError) throw error; throw missing(`This project pins Node ${version}, which could not be fetched (${error.message}). Retry with a working connection, or set RER_NODE_AUTO=0 to use Node ${process.versions.node}.`); }
|
|
28
|
-
env.
|
|
29
|
+
env.RER_NODE_BINARY = binary;
|
|
30
|
+
env.PATH = [env.PATH, dirname(binary)].filter(value => value !== undefined).join(delimiter);
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
export async function runScript(args) {
|
|
@@ -41,19 +43,26 @@ export async function runScript(args) {
|
|
|
41
43
|
process.stderr.write(`rer run runs inside a checkout: a folder with OPERATIONS.json at or above this one, or --cwd DIR.\n`);
|
|
42
44
|
return 2;
|
|
43
45
|
}
|
|
46
|
+
let scripts = {};
|
|
47
|
+
try { scripts = JSON.parse(await readFile(join(target.root, 'package.json'), 'utf8')).scripts ?? {}; } catch {}
|
|
48
|
+
// pnpm run --silent hides pnpm's own missing-script error, so say it here, before any pnpm is fetched or spawned.
|
|
49
|
+
if (args[0] && !args[0].startsWith('-') && !Object.hasOwn(scripts, args[0])) {
|
|
50
|
+
process.stderr.write(`No script named ${args[0]} in this checkout. Scripts: ${Object.keys(scripts).join(', ') || '(none)'}\n`);
|
|
51
|
+
return 2;
|
|
52
|
+
}
|
|
44
53
|
const { ensureProjectPnpm } = await import('../cli/project-pnpm.mjs');
|
|
45
54
|
const { RerError } = await import('../cli/errors.mjs');
|
|
46
55
|
try {
|
|
47
56
|
await ensureProjectPnpm(target.root, { report: text => process.stderr.write(text + '\n') });
|
|
48
57
|
await projectNode(target.root, process.env);
|
|
49
58
|
} catch (error) { if (!(error instanceof RerError)) throw error; process.stderr.write(error.message + '\n'); return error.exitCode; }
|
|
50
|
-
let scripts = {};
|
|
51
|
-
try { scripts = JSON.parse(await readFile(join(target.root, 'package.json'), 'utf8')).scripts ?? {}; } catch {}
|
|
52
59
|
if (args[0] && /\bplaywright\b/.test(scripts[args[0]] ?? '')) {
|
|
53
60
|
const code = await (await import('./browser-runtime.mjs')).browserPreflight(target.root, ['run']);
|
|
54
61
|
if (code !== undefined) return code;
|
|
55
62
|
}
|
|
56
|
-
const
|
|
63
|
+
const { toolCommand } = await shared('tool-command.mjs');
|
|
64
|
+
const [program, parameters] = toolCommand('pnpm', ['run', '--silent', ...args], process.env);
|
|
65
|
+
const child = spawn(program, parameters, { cwd: target.root, env: process.env, stdio: 'inherit' });
|
|
57
66
|
const forward = new Map(['SIGINT', 'SIGTERM', 'SIGHUP'].map(signal => [signal, () => child.kill(signal)]));
|
|
58
67
|
for (const [signal, handler] of forward) process.on(signal, handler);
|
|
59
68
|
try {
|
package/install.sh
CHANGED
|
@@ -43,14 +43,15 @@ main() {
|
|
|
43
43
|
trap 'exit 130' INT TERM
|
|
44
44
|
|
|
45
45
|
# Bootstrap before reading npm metadata; no npm global install or PATH links.
|
|
46
|
-
|
|
46
|
+
node_binary=$(command -v node) || node_binary=
|
|
47
|
+
if [ -z "$node_binary" ] || ! "$node_binary" -e 'process.exit(Number(process.versions.node.split(".")[0]) >= 22 ? 0 : 1)' >/dev/null 2>&1; then
|
|
47
48
|
install_node
|
|
48
49
|
fi
|
|
49
50
|
|
|
50
51
|
curl -fsSL --proto '=http,https' -H 'Accept: application/json' "$registry/@runeditrun%2frer" -o "$work/metadata.json" \
|
|
51
52
|
|| fail "could not read $package from $registry."
|
|
52
53
|
# Writes version, tarball URL, integrity, file count and unpacked size, one per line.
|
|
53
|
-
|
|
54
|
+
"$node_binary" - "$work/metadata.json" "${RER_VERSION:-}" >"$work/release" <<'NODE' || exit 1
|
|
54
55
|
var fs = require('fs');
|
|
55
56
|
var wanted = process.argv[3];
|
|
56
57
|
function stop(message) { process.stderr.write('rer install: ' + message + '\n'); process.exit(1); }
|
|
@@ -75,7 +76,7 @@ NODE
|
|
|
75
76
|
printf 'Downloading rer %s from %s\n' "$version" "$registry"
|
|
76
77
|
curl -fsSL --proto '=http,https' "$tarball" -o "$work/rer.tgz" || fail "could not download $tarball."
|
|
77
78
|
# The exact bytes the registry names, and nothing tar could write outside its folder.
|
|
78
|
-
|
|
79
|
+
"$node_binary" - "$work/rer.tgz" "$integrity" "$files" "$size" <<'NODE' || fail "the download of rer $version was refused; nothing was installed."
|
|
79
80
|
var fs = require('fs'), hashes = require('crypto'), zlib = require('zlib');
|
|
80
81
|
function stop(message) { process.stderr.write('rer install: ' + message + '\n'); process.exit(1); }
|
|
81
82
|
var bytes = fs.readFileSync(process.argv[2]);
|
|
@@ -144,10 +145,10 @@ NODE
|
|
|
144
145
|
# the exact line that puts it there (no npx: Node may be rer's own).
|
|
145
146
|
no_next=
|
|
146
147
|
if [ "$#" -gt 0 ]; then no_next=1; fi
|
|
147
|
-
RER_INSTALL_CHANNEL=script RER_INSTALL_NO_NEXT=$no_next
|
|
148
|
+
RER_INSTALL_CHANNEL=script RER_INSTALL_NO_NEXT=$no_next "$node_binary" "$work/stage/package/global/rer.mjs" cli install </dev/null \
|
|
148
149
|
|| fail "rer cli install failed; any previous install is still selected."
|
|
149
150
|
if [ "$#" -eq 0 ]; then return; fi
|
|
150
|
-
PATH="$HOME/.local/bin
|
|
151
|
+
PATH="$PATH:$HOME/.local/bin"
|
|
151
152
|
export PATH
|
|
152
153
|
"$HOME/.local/bin/rer" "$@"
|
|
153
154
|
}
|
|
@@ -196,7 +197,8 @@ try {
|
|
|
196
197
|
fs.renameSync(temporary, path.join(root, 'node'));
|
|
197
198
|
} finally { try { fs.unlinkSync(temporary); } catch (error) { if (error.code !== 'ENOENT') throw error; } }
|
|
198
199
|
NODE
|
|
199
|
-
|
|
200
|
+
node_binary="$node_home/bin/node"
|
|
201
|
+
PATH="$PATH:$node_home/bin"
|
|
200
202
|
export PATH
|
|
201
203
|
}
|
|
202
204
|
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {array, bindingPattern, keys, string, strings} from './bindings.mjs';
|
|
2
2
|
|
|
3
3
|
const pathPattern = /^\/[A-Za-z0-9/_.~-]*$/;
|
|
4
|
+
const signInPath = value => typeof value === 'string' && /^\/(?!\/)[a-zA-Z0-9/_-]*$/.test(value);
|
|
4
5
|
const validSignIn = value => value && typeof value === 'object' && !Array.isArray(value)
|
|
5
|
-
&& Object.keys(value).every(key => ['path','loginHint'].includes(key))
|
|
6
|
-
&&
|
|
7
|
-
&& typeof value.loginHint === 'boolean'
|
|
6
|
+
&& Object.keys(value).every(key => ['path','loginHint','ownerSignIn'].includes(key))
|
|
7
|
+
&& signInPath(value.path)
|
|
8
|
+
&& typeof value.loginHint === 'boolean'
|
|
9
|
+
&& (value.ownerSignIn === undefined || signInPath(value.ownerSignIn));
|
|
8
10
|
const status = (value, label) => {
|
|
9
11
|
if (!Number.isInteger(value) || value < 100 || value > 599) throw Error(`Invalid ${label}`);
|
|
10
12
|
};
|
|
@@ -201,7 +201,7 @@ No Single Redirect (dynamic redirect ruleset) permission is needed. Base's refer
|
|
|
201
201
|
|
|
202
202
|
## Migration safety
|
|
203
203
|
|
|
204
|
-
SQL files have ordered unique names and SHA-256 identities. `d1_migrations` holds controller history with ordered IDs, names, timestamps, SHA-256 hashes and states. Native archives already exclude this installation table. Standard Wrangler name-only inserts remain possible, but their missing hashes/states block subsequent Base deployment pending reviewed adoption.
|
|
204
|
+
SQL files have ordered unique names and SHA-256 identities. `d1_migrations` holds controller history with ordered IDs, names, timestamps, SHA-256 hashes and states. Native archives already exclude this installation table. Standard Wrangler name-only inserts remain possible, but their missing hashes/states block subsequent Base deployment pending reviewed adoption. Every applied entry must name a migration in the desired set, once, with its unchanged bytes (or bytes a reviewed rewrite replaced); entries may skip migrations, because a release can add migrations that sort below ones an install already applied. The desired set's unapplied migrations then run in name order, as Wrangler applies them, and a ledger that holds an entry the build lacks, changed bytes or an unconfirmed claim is refused. A new migration gets an `applying` claim before its SQL and completion marker are submitted together through the [Cloudflare D1 SQL import API](https://developers.cloudflare.com/api/resources/d1/subresources/database/methods/import/), using the same whole-file protocol as Wrangler to preserve compound trigger bodies and atomic SQL/completion. Uploads use bounded HTTPS R2 destinations, without account credentials; polling is bounded and signed URLs are never diagnostic output. A failed import keeps Cloudflare's own codes and messages on the error (`providerRefusal`, which `rer deploy` prints, with credentials and URLs removed and each message cut to 300 characters) and names the migration it was running.
|
|
205
205
|
|
|
206
206
|
An import that did not complete leaves its `applying` claim. The next deploy of the same migration bytes runs it again only when it proves none of it applied (`migration-retry.mjs`): the import is atomic, so the migration's effects that would make a second run fail (a CREATE without IF NOT EXISTS, ADD COLUMN, RENAME) and that last to the end of the file must all be absent. Then no attempt committed, and one that commits late makes the re-run fail whole instead of applying twice. A name the file drops or renames away existed before it ran, so a table it rebuilds under the same name, and that table's indexes, are not checked. A migration with no such effect, or with any of them present, stays refused as `uncertain-migration-claim`; the message names the migration, what is present, and the exact step: undo what is present and deploy again, or confirm by hand and delete or complete its claim with `wrangler d1 execute`. The kit never re-runs a migration whose effects may be present, rolls back user data, or marks an unknown outcome successful. Any other unconfirmed or changed history is still `changed-or-uncertain-migration-history`. Readback checks every final identity.
|
|
207
207
|
|
|
@@ -41,17 +41,29 @@ export function migrationLedgerShape(rows) {
|
|
|
41
41
|
/** An applied row records this migration: its current bytes, or bytes a seed's
|
|
42
42
|
* reviewed rewrite record says this migration replaced. */
|
|
43
43
|
export const recorded = (row, migration) => row.name === migration?.name && (row.sha256 === migration.sha256 || (migration.rewrites ?? []).some(rewrite => rewrite.from === row.sha256));
|
|
44
|
-
|
|
44
|
+
/** Applied history this build records, by name: every row is applied, names a
|
|
45
|
+
* build migration once, and holds that migration's recorded bytes. Rows may skip
|
|
46
|
+
* build migrations: a seed release can add migrations that sort below ones an
|
|
47
|
+
* install already applied, and Wrangler applies those by name set too. */
|
|
48
|
+
const validHistory = (rows, migrations) => {
|
|
49
|
+
const byName = new Map(migrations.map(migration => [migration.name, migration])), seen = new Set();
|
|
50
|
+
return rows.every(row => row.state === 'applied' && !seen.has(row.name) && seen.add(row.name) && recorded(row, byName.get(row.name)));
|
|
51
|
+
};
|
|
52
|
+
/** The build migrations these rows do not apply, in name order. */
|
|
53
|
+
export const unapplied = (rows, migrations) => {
|
|
54
|
+
const names = new Set(rows.map(row => row.name));
|
|
55
|
+
return migrations.filter(migration => !names.has(migration.name));
|
|
56
|
+
};
|
|
45
57
|
const same = (a, b) => a.length === b.length && a.every((row, index) => row.name === b[index].name && row.sha256 === b[index].sha256 && row.state === b[index].state);
|
|
46
58
|
|
|
47
|
-
/** History this build does not match. When it ends in an unconfirmed claim after
|
|
48
|
-
* valid
|
|
59
|
+
/** History this build does not match. When it ends in an unconfirmed claim after
|
|
60
|
+
* valid history, the error names that claim (`unconfirmedClaim`) so the refusal can
|
|
49
61
|
* give the exact command that clears it; `rewritten` says a reviewed rewrite
|
|
50
62
|
* replaced the claimed bytes and only a deploy holding the install's lock retries it. */
|
|
51
63
|
function unmatched(rows, migrations) {
|
|
52
64
|
const error = new Error('changed-or-uncertain-migration-history'), last = rows.at(-1);
|
|
53
|
-
if (last?.state === 'applying' && /^[a-f0-9]{64}$/.test(last.sha256 ?? '') &&
|
|
54
|
-
const next =
|
|
65
|
+
if (last?.state === 'applying' && /^[a-f0-9]{64}$/.test(last.sha256 ?? '') && validHistory(rows.slice(0, -1), migrations)) {
|
|
66
|
+
const next = unapplied(rows.slice(0, -1), migrations)[0];
|
|
55
67
|
error.unconfirmedClaim = { name:last.name, sha256:last.sha256, rewritten:last.name === next?.name && (next.rewrites ?? []).some(rewrite => rewrite.from === last.sha256) };
|
|
56
68
|
}
|
|
57
69
|
return error;
|
|
@@ -68,22 +80,23 @@ export async function readLedger(api, id, migrations, query, { rewritten = false
|
|
|
68
80
|
const columns = await read(`SELECT name FROM pragma_table_info('${legacy}')`);
|
|
69
81
|
assert(columns.length === 3 && columns.every(row => ['name','sha256','state'].includes(row.name)), 'invalid-migration-ledger');
|
|
70
82
|
old = await read(`SELECT name, sha256, state FROM ${legacy} ORDER BY name`);
|
|
71
|
-
assert(
|
|
83
|
+
assert(validHistory(old, migrations), 'changed-or-uncertain-migration-history');
|
|
72
84
|
}
|
|
73
85
|
if (tables.includes(ledger)) {
|
|
74
86
|
const columns = (await read(`SELECT name FROM pragma_table_info('${ledger}')`)).map(row => row.name);
|
|
75
87
|
assert(['id','name','applied_at'].every(name => columns.includes(name)), 'invalid-migration-ledger');
|
|
76
88
|
if (columns.includes('sha256') && columns.includes('state')) {
|
|
77
89
|
applied = await read(`SELECT name, sha256, state FROM ${ledger} ORDER BY id`);
|
|
78
|
-
// The last row may claim this build's next migration
|
|
79
|
-
// complete: its exact bytes, or
|
|
80
|
-
// migrate re-runs it only on
|
|
81
|
-
|
|
90
|
+
// The last row may claim this build's next migration (its first unapplied one,
|
|
91
|
+
// as migrate claims them) whose import did not complete: its exact bytes, or
|
|
92
|
+
// (`rewritten`) bytes a reviewed rewrite replaced. migrate re-runs it only on
|
|
93
|
+
// proof (migration-retry.mjs).
|
|
94
|
+
const last = applied.at(-1), next = unapplied(applied.slice(0, -1), migrations)[0];
|
|
82
95
|
if (!tables.includes(legacy) && last?.state === 'applying' && last.name === next?.name) {
|
|
83
96
|
if (last.sha256 === next.sha256) claimed = Boolean(applied.pop());
|
|
84
97
|
else if (rewritten && (next.rewrites ?? []).some(rewrite => rewrite.from === last.sha256)) { claimedFrom = last.sha256; claimed = Boolean(applied.pop()); }
|
|
85
98
|
}
|
|
86
|
-
if (!
|
|
99
|
+
if (!validHistory(applied, migrations)) throw unmatched(applied, migrations);
|
|
87
100
|
if (tables.includes(legacy)) assert(same(applied, old), 'changed-or-uncertain-migration-history');
|
|
88
101
|
} else {
|
|
89
102
|
assert(!columns.includes('sha256') && !columns.includes('state'), 'invalid-migration-ledger');
|
|
@@ -102,7 +115,7 @@ export async function readLedger(api, id, migrations, query, { rewritten = false
|
|
|
102
115
|
applied = old;
|
|
103
116
|
}
|
|
104
117
|
if (tables.includes(legacy)) transition += `DROP TABLE ${legacy};`;
|
|
105
|
-
return { applied, transition, claimed, claimedFrom, exists:tables.includes(ledger) || tables.includes(legacy) };
|
|
118
|
+
return { applied, pending:unapplied(applied, migrations), transition, claimed, claimedFrom, exists:tables.includes(ledger) || tables.includes(legacy) };
|
|
106
119
|
}
|
|
107
120
|
function insert(row) {
|
|
108
121
|
return `INSERT INTO ${ledger}(name,sha256,state) VALUES (${literal(row.name)},${literal(row.sha256)},'applied');\n`;
|
|
@@ -56,8 +56,7 @@ export async function query(api, id, sql) {
|
|
|
56
56
|
/** `locked`: the caller holds the install's deploy lock (owner.mjs withStateLock). */
|
|
57
57
|
export async function migrate(api, id, migrations, { apply = true, upgrade = apply, locked = false } = {}) {
|
|
58
58
|
validateMigrations(migrations);
|
|
59
|
-
const { applied, transition, exists, claimed, claimedFrom } = await readLedger(api, id, migrations, query, { rewritten:locked });
|
|
60
|
-
const pending = migrations.slice(applied.length);
|
|
59
|
+
const { applied, pending, transition, exists, claimed, claimedFrom } = await readLedger(api, id, migrations, query, { rewritten:locked });
|
|
61
60
|
assert(apply || pending.length === 0,'pending-migrations');
|
|
62
61
|
if (transition && upgrade) {
|
|
63
62
|
await api.importSql(id, transition);
|
|
@@ -83,8 +82,9 @@ export async function migrate(api, id, migrations, { apply = true, upgrade = app
|
|
|
83
82
|
.catch(error => { error.migration ??= migration.name; throw error; });
|
|
84
83
|
}
|
|
85
84
|
if (pending.length) {
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
// By name and bytes: rows applied after ones that sort above them keep their ids.
|
|
86
|
+
const rows = (await query(api,id,`SELECT name, sha256, state FROM ${ledger}`))[0].results, final = new Map(rows.map(x => [x.name, x]));
|
|
87
|
+
assert(rows.length === migrations.length && final.size === rows.length && migrations.every(x => final.get(x.name)?.state === 'applied' && recorded(final.get(x.name), x)), 'migration-readback-mismatch');
|
|
88
88
|
}
|
|
89
89
|
return { applied:pending.map(x => x.name), retried:claimed ? [pending[0].name] : [], history:migrations.map(({name,sha256}) => ({name,sha256})) };
|
|
90
90
|
}
|
|
@@ -79,10 +79,8 @@ export async function createQueue(options = {}) {
|
|
|
79
79
|
if (blockers.length) return { reason: blockers.join('; '), blockers, reasonCodes, position, ahead,
|
|
80
80
|
queued: waiting.length, running: state.running.length, resources,
|
|
81
81
|
limits: { slots: config.slots, loadThreshold: config.loadThreshold, minFreeMemoryBytes: config.minFreeMemoryBytes } };
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
reasonCodes: ['max_wait'], position, queued: waiting.length, running: state.running.length, resources,
|
|
85
|
-
limits: { slots: config.slots, loadThreshold: config.loadThreshold, minFreeMemoryBytes: config.minFreeMemoryBytes } };
|
|
82
|
+
// maxWait bounds how long a blocked job waits. A job this pass finds admissible is admitted
|
|
83
|
+
// however long the pass itself took (lock, reclaim, sample), so a slow pass never refuses a free machine.
|
|
86
84
|
state.queued = state.queued.filter(item => item.id !== job.id);
|
|
87
85
|
job.startedAt = Date.now(); state.running.push(job);
|
|
88
86
|
return null;
|
|
@@ -90,7 +88,7 @@ export async function createQueue(options = {}) {
|
|
|
90
88
|
if (!result) break;
|
|
91
89
|
const elapsed = performance.now() - start;
|
|
92
90
|
if (opts.maxWait !== undefined && elapsed >= opts.maxWait * 1000)
|
|
93
|
-
return { code: TIMEOUT_EXIT, timedOut: true, reason: result.reason };
|
|
91
|
+
return { code: TIMEOUT_EXIT, timedOut: true, reason: result.reason, reasonCodes: result.reasonCodes, resources: result.resources, limits: result.limits };
|
|
94
92
|
const signature = `${result.position}:${result.reasonCodes.join(',')}`;
|
|
95
93
|
const now = performance.now();
|
|
96
94
|
if (!lastWaitReportAt || signature !== lastWaitSignature || now - lastWaitReportAt >= WAIT_REPORT_INTERVAL_MS) {
|
|
@@ -493,9 +493,12 @@ the gate is the key, not the network. `devGate({key, origin, local})` returns
|
|
|
493
493
|
null unless the key is present and the origin is an explicit loopback origin in
|
|
494
494
|
local mode. `admits(request)` accepts the `rer_dev_gate_<port>` cookie (an HMAC of the
|
|
495
495
|
key, so a reset key refuses old cookies) or the key in `x-rer-dev-key` (the rer
|
|
496
|
-
CLI and test harnesses). `exchange(request)` serves `GET /__dev/key` and trades
|
|
496
|
+
CLI and test harnesses). `exchange(request, branding)` serves `GET /__dev/key` and trades
|
|
497
497
|
the key from the URL fragment, through a same-origin POST, for a host-only
|
|
498
|
-
`HttpOnly; SameSite=Strict; Path=/` cookie.
|
|
498
|
+
`HttpOnly; SameSite=Strict; Path=/` cookie. Given the seed's `branding`
|
|
499
|
+
(`productName`, `theme`), the page between `rer dev` and the app shows the seed's own
|
|
500
|
+
mark, the `--rer-logo` its theme declares, as an `<img>` with the product name as its
|
|
501
|
+
alt text; a seed whose theme declares no logo shows the product name as text.
|
|
499
502
|
|
|
500
503
|
`dev/` is the dev layer: **server-only and local-only**. Import it only from a
|
|
501
504
|
local-only Worker entry (a Vite-serve or local `wrangler dev` entry), never
|
|
@@ -49,7 +49,7 @@ export function withDevIdentity(worker, { bindings = env => env, config: authCon
|
|
|
49
49
|
const gate = devGate({ key: env.RER_DEV_KEY, origin: env.AUTH_ORIGIN, local: env.AUTH_LOCAL === 'true' });
|
|
50
50
|
registerDevAdmission(gate && env.RER_DEV_IDENTITY !== 'off' ? r => gate.admits(r) : null);
|
|
51
51
|
const path = new URL(request.url).pathname;
|
|
52
|
-
if (path === '/__dev/key') return gate ? gate.exchange(request) : devNotFound();
|
|
52
|
+
if (path === '/__dev/key') return gate ? gate.exchange(request, authConfig(env).branding) : devNotFound();
|
|
53
53
|
if (path === '/signin' && gate && env.RER_DEV_IDENTITY !== 'off' && ['GET', 'HEAD'].includes(request.method)) {
|
|
54
54
|
if (!await gate.admits(request)) return new Response(null, { status: 303, headers: { ...headers, location: '/__dev/key' } });
|
|
55
55
|
const context = identity(env, authConfig, declared);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { rejectedResponse } from './rejected-response.mjs';
|
|
2
2
|
import { constantEqual } from './crypto.mjs';
|
|
3
|
-
import { isLoopbackHost, localCookieName } from './http.mjs';
|
|
3
|
+
import { escapeHtml, isLoopbackHost, localCookieName } from './http.mjs';
|
|
4
|
+
import { configureBranding } from './branding.mjs';
|
|
4
5
|
|
|
5
6
|
// The local key gate. `rer setup` writes a random RER_DEV_KEY per checkout and
|
|
6
7
|
// the local runtimes receive it as a binding; a deployed Worker never has one
|
|
@@ -31,10 +32,19 @@ async function cookieValue(key) {
|
|
|
31
32
|
// fragment navigation too: an open gate page stays loaded when RER_OPEN points
|
|
32
33
|
// to the same path with a fresh key fragment.
|
|
33
34
|
export const EXCHANGE_SCRIPT = "(()=>{const exchange=()=>{const h=new URLSearchParams(location.hash.slice(1)),k=h.get('rer-dev');if(!k)return;history.replaceState(null,'',location.pathname+location.search);const a=h.get('as'),n=h.get('next')||(a?'/auth/dev/enter?as='+encodeURIComponent(a):location.pathname+location.search),to=n.startsWith('/')&&!n.startsWith('//')&&!n.includes('\\\\')?n:'/';fetch('" + DEV_KEY_PATH + "',{method:'POST',credentials:'same-origin',headers:{'content-type':'application/json'},body:JSON.stringify({key:k})}).then(r=>{if(r.ok)location.replace(to);else document.body.insertAdjacentHTML('beforeend','<p role=\"alert\">This link no longer opens the app. Run rer dev again for a fresh one.</p>')})};addEventListener('hashchange',exchange);exchange()})()";
|
|
34
|
-
|
|
35
|
+
// The hand-off page wears the seed's own theme: the same rer-theme.css tokens and the
|
|
36
|
+
// same --rer-logo mark the sign-in pages draw. The mark becomes a real <img> named by
|
|
37
|
+
// the product and shown beside the wordmark text; a seed that declares no logo shows
|
|
38
|
+
// its product name as text alone.
|
|
39
|
+
const PAGE_STYLE = 'body{margin:0;font:16px/1.5 var(--rer-font-body,system-ui,sans-serif);color:var(--rer-text,#17212e);background:var(--rer-page,#f5f7fa)}main{max-width:36rem;margin:0 auto;padding:32px 16px}'
|
|
40
|
+
+ '.brand{display:flex;align-items:center;gap:12px;margin:0 0 28px;font:600 24px/1.2 var(--rer-font-heading,var(--rer-font-body,inherit));color:var(--rer-text,#17212e)}.brand img{display:block;flex:none;width:40px;height:40px;object-fit:contain}h1{font:600 20px/1.3 var(--rer-font-heading,var(--rer-font-body,inherit));margin:0 0 12px}p{color:var(--rer-muted,#475569);margin:0}';
|
|
41
|
+
// Reads --rer-logo from the linked theme (a script after a stylesheet waits for it) and
|
|
42
|
+
// shows that same-origin file as an <img> named by the product; the text beside it is
|
|
43
|
+
// then hidden from screen readers so the name is announced once.
|
|
44
|
+
export const LOGO_SCRIPT = "(()=>{const b=document.querySelector('.brand'),n=b&&b.querySelector('span'),m=/url\\(\\s*(['\"]?)(\\/(?!\\/)[^'\")\\s\\\\]+)\\1\\s*\\)/.exec(getComputedStyle(document.documentElement).getPropertyValue('--rer-logo'));if(!n||!m)return;const i=new Image();i.alt=n.textContent;i.src=m[2];i.width=i.height=40;b.prepend(i);n.setAttribute('aria-hidden','true')})()";
|
|
35
45
|
let hashes;
|
|
36
46
|
export async function exchangeHashes() {
|
|
37
|
-
return hashes ??= { script: `'sha256-${await digest(EXCHANGE_SCRIPT)}'`, style: `'sha256-${await digest(PAGE_STYLE)}'` };
|
|
47
|
+
return hashes ??= { script: `'sha256-${await digest(EXCHANGE_SCRIPT)}'`, logo: `'sha256-${await digest(LOGO_SCRIPT)}'`, style: `'sha256-${await digest(PAGE_STYLE)}'` };
|
|
38
48
|
}
|
|
39
49
|
|
|
40
50
|
const privateHeaders = { 'cache-control': 'no-store', 'referrer-policy': 'no-referrer', 'x-content-type-options': 'nosniff', 'x-robots-tag': 'noindex, nofollow' };
|
|
@@ -70,14 +80,17 @@ export function devGate({ key, origin, local }) {
|
|
|
70
80
|
return value !== null && constantEqual(value, await cookie());
|
|
71
81
|
},
|
|
72
82
|
setCookie,
|
|
73
|
-
// GET serves the exchange page; POST trades the key for the cookie.
|
|
74
|
-
async exchange(request) {
|
|
83
|
+
// GET serves the exchange page, branded by the seed's `branding` ({ productName, theme }) when given; POST trades the key for the cookie.
|
|
84
|
+
async exchange(request, branding) {
|
|
75
85
|
if (new URL(request.url).pathname !== DEV_KEY_PATH) return null;
|
|
76
86
|
if (request.method === 'GET' || request.method === 'HEAD') {
|
|
77
|
-
const { script, style } = await exchangeHashes();
|
|
78
|
-
|
|
87
|
+
const { script, logo, style } = await exchangeHashes();
|
|
88
|
+
// The seed's declared branding (its product name and theme) brands the page; without it the page is unnamed.
|
|
89
|
+
const brand = branding === undefined ? undefined : configureBranding(branding);
|
|
90
|
+
const theme = brand?.theme;
|
|
91
|
+
const body = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex, nofollow"><title>Opening the local app</title>${theme ? `<link rel="stylesheet" href="${escapeHtml(theme)}">` : ''}<style>${PAGE_STYLE}</style></head><body><main>${brand ? `<p class="brand"><span>${escapeHtml(brand.productName)}</span></p>` : ''}<h1>Opening the local app</h1><p>Open the RER_OPEN link that rer prints on this computer.</p></main>${theme ? `<script>${LOGO_SCRIPT}</script>` : ''}<script>${EXCHANGE_SCRIPT}</script></body></html>`;
|
|
79
92
|
return new Response(request.method === 'HEAD' ? null : body, { headers: { ...privateHeaders, 'content-type': 'text/html; charset=utf-8',
|
|
80
|
-
'content-security-policy': `default-src 'none'; script-src ${script}; style-src ${style}; connect-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'` } });
|
|
93
|
+
'content-security-policy': `default-src 'none'; script-src ${script}${theme ? ` ${logo}` : ''}; style-src ${theme ? "'self' " : ''}${style}${theme ? "; font-src 'self'; img-src 'self'" : ''}; connect-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'` } });
|
|
81
94
|
}
|
|
82
95
|
if (request.method !== 'POST' || request.headers.get('sec-fetch-site') === 'cross-site' || !request.headers.get('content-type')?.startsWith('application/json')) return rejectedResponse(request, devNotFound());
|
|
83
96
|
const text = await request.text();
|
|
@@ -228,7 +228,7 @@ export interface DevGate {
|
|
|
228
228
|
admits(request: Request): Promise<boolean>;
|
|
229
229
|
setCookie(): Promise<string>;
|
|
230
230
|
/** Handles GET/POST /__dev/key; null for every other path. */
|
|
231
|
-
exchange(request: Request): Promise<Response | null>;
|
|
231
|
+
exchange(request: Request, branding?: AuthBranding): Promise<Response | null>;
|
|
232
232
|
}
|
|
233
233
|
export const DEV_KEY_HEADER: 'x-rer-dev-key';
|
|
234
234
|
export function devGate(input: DevGateInput): DevGate | null;
|
package/onboarding/adapter.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { constants } from 'node:fs';
|
|
2
2
|
import { access } from 'node:fs/promises';
|
|
3
3
|
import { delimiter, join } from 'node:path';
|
|
4
|
-
import { commandFailure, approvedFailure, installationFailure, installationFailureMessage } from './failures.mjs';
|
|
4
|
+
import { commandFailure, approvedFailure, installationFailure, installationFailureMessage, isBusyFailure } from './failures.mjs';
|
|
5
5
|
import { withoutLocalVariables } from './local/build.mjs';
|
|
6
6
|
import { buildEnvironment } from './local/environment.mjs';
|
|
7
7
|
import { localOperation } from './local/operation.mjs';
|
|
@@ -72,7 +72,7 @@ export function localInstaller(hooks = {}) {
|
|
|
72
72
|
if (['installer', 'setup', 'dev'].includes(verb) && hooks.migrate) {
|
|
73
73
|
try { await phase(context, hooks, 'migrate', hooks.migrate); }
|
|
74
74
|
catch (error) {
|
|
75
|
-
if (verb !== 'dev' || signal?.aborted) throw error;
|
|
75
|
+
if (verb !== 'dev' || signal?.aborted || isBusyFailure(error)) throw error;
|
|
76
76
|
const failure = approvedFailure(error);
|
|
77
77
|
throw commandFailure(`${store.redact(failure?.message ?? error.message)}\nLocal migrations failed. Fix the error and run rer setup before trying again.`, failure ?? {});
|
|
78
78
|
}
|
|
@@ -124,7 +124,7 @@ function createContext(root, input, store, onApp, signal, guard) {
|
|
|
124
124
|
async run(label, command, args = [], { step = 'setup', ...options } = {}) {
|
|
125
125
|
if (guard) await guard(context);
|
|
126
126
|
try { return await store.run(label, command, args, { cwd: root, signal, ...options }); } catch (error) {
|
|
127
|
-
if (signal?.aborted || options.signal?.aborted) throw error;
|
|
127
|
+
if (signal?.aborted || options.signal?.aborted || isBusyFailure(error)) throw error;
|
|
128
128
|
throw installationFailure('command_failed', { step, diagnostic: error });
|
|
129
129
|
}
|
|
130
130
|
},
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { busyFailure } from './failures.mjs';
|
|
2
|
+
|
|
3
|
+
// A queued step the job queue never admitted is a busy machine, not a failed
|
|
4
|
+
// command: say what held it, the limit and the next step, in the same plain form
|
|
5
|
+
// as the server load guard (cli/server-resources.mjs).
|
|
6
|
+
const commandNames = new Set(['dev', 'setup', 'preview', 'build', 'deploy', 'verify']);
|
|
7
|
+
|
|
8
|
+
function waited(seconds) {
|
|
9
|
+
return seconds >= 60 ? `${Math.round(seconds / 60)} minutes` : `${Math.round(seconds)} seconds`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function busyMessage(result, { verb, maxWait }) {
|
|
13
|
+
const command = commandNames.has(verb) ? `rer ${verb}` : 'the same command';
|
|
14
|
+
const load = result.resources?.load, threshold = result.limits?.loadThreshold;
|
|
15
|
+
if (result.reasonCodes?.includes('load') && Number.isFinite(load) && threshold !== undefined) {
|
|
16
|
+
return `Not started: this computer is busy. Its 1-minute load is ${load.toFixed(1)} and jobs start only at ${threshold} or below; this step waited ${waited(maxWait)} for it to drop.\nTry again in a few minutes by running ${command} again, or start it anyway with a higher threshold, for example RER_JOBS_LOAD_THRESHOLD=${Math.ceil(Math.max(threshold, load) * 2)} ${command}.`;
|
|
17
|
+
}
|
|
18
|
+
return `Not started: the job queue did not admit this step within ${waited(maxWait)}: ${result.reason}.\nTry again in a few minutes by running ${command} again.`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const busyRefusal = (result, options) => busyFailure(busyMessage(result, options));
|
package/onboarding/commands.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { queuedCommand, queueLabel, commandPolicy } from './queue.mjs';
|
|
1
|
+
import { queuedCommand, queueLabel, commandPolicy, maxWaitSeconds } from './queue.mjs';
|
|
2
|
+
import { busyRefusal } from './busy.mjs';
|
|
2
3
|
import { spawn as spawnChild } from 'node:child_process';
|
|
3
4
|
import { writeSync } from 'node:fs';
|
|
4
5
|
import { join } from 'node:path';
|
|
@@ -9,6 +10,7 @@ import { checkoutPath, stepDiagnostic } from './step-failure.mjs';
|
|
|
9
10
|
import { waitForReadiness } from './readiness.mjs';
|
|
10
11
|
import { commandCustody } from './command-custody.mjs';
|
|
11
12
|
import { createProcessBaseline, createProcessScope, inheritedScopeTokens, processScopeEnvironment } from './process-scope.mjs';
|
|
13
|
+
import { toolCommand } from './tool-command.mjs';
|
|
12
14
|
|
|
13
15
|
export async function createCommands(directory,state,{terminal=text=>writeSync(1,text),spawn=spawnChild,queue:queuePolicy,custodyToken,onWaiting}={}) {
|
|
14
16
|
let policy=queuePolicy?await commandPolicy():{environment:{},close:async()=>{}};
|
|
@@ -51,7 +53,7 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
|
|
|
51
53
|
const lines=(capture?.snapshot()||'').split('\n');if(lines.at(-1)==='')lines.pop();
|
|
52
54
|
// The step, its command, exit code, last output and log, for callers that name a failed step.
|
|
53
55
|
const step=stepDiagnostic({name:redaction.redact(String(label)),command:capture?.display,exitCode:detail.code,signal:detail.signal,output:lines,log:redaction.redact(checkoutPath(capture?.cwd,logPath))});
|
|
54
|
-
return Object.assign(commandFailure(`${redaction.redact(String(label))}: ${status}.${detail.lastHealth?` Last health: ${redaction.redact(String(detail.lastHealth))}.`:''}\nLast output (up to 40 lines):\n${lines.length?lines.slice(-40).join('\n'):'(no output)'}\nLog: ${redaction.redact(logPath)}`,{childExitCode:detail.code,signal:detail.signal,step}),{childExitCode:detail.code,signal:detail.signal});
|
|
56
|
+
return Object.assign(commandFailure(`${redaction.redact(String(label))}: ${status}.${detail.lastHealth?` Last health: ${redaction.redact(String(detail.lastHealth))}.`:''}\nCommand: ${capture?.display ?? '(none: the step failed inside rer)'}\nLast output (up to 40 lines):\n${lines.length?lines.slice(-40).join('\n'):'(no output)'}\nLog: ${redaction.redact(logPath)}`,{childExitCode:detail.code,signal:detail.signal,step}),{childExitCode:detail.code,signal:detail.signal});
|
|
55
57
|
};
|
|
56
58
|
const track=(label,child,ownershipScope)=>{
|
|
57
59
|
if(captures.has(child))return child;
|
|
@@ -119,16 +121,18 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
|
|
|
119
121
|
// label must not show that label twice.
|
|
120
122
|
const announced=redaction.redact(String(label)),repeated=state.step===announced;
|
|
121
123
|
state.step=announced;if(!repeated)report(label);
|
|
122
|
-
//
|
|
124
|
+
// Name the executable by default; only a caller's explicit safe display may
|
|
125
|
+
// include arguments. Raw argv can contain private positional values.
|
|
123
126
|
const {signal:providedSignal,afterCommand,onChild,heavy,phase,display,...native}=options;
|
|
124
127
|
const commandSignal=signal&&providedSignal?AbortSignal.any([signal,providedSignal]):providedSignal||signal;
|
|
125
128
|
if(commandSignal?.aborted)throw failure(label,{reason:'cancel'});
|
|
126
129
|
const ownershipScope=createProcessScope(custodyBaseline);redaction.addSecrets([ownershipScope.token,...inheritedScopeTokens(process.env),...inheritedScopeTokens(native.env)]);
|
|
127
|
-
const
|
|
130
|
+
const [program,argv]=toolCommand(command,args,native.env??process.env);
|
|
131
|
+
const child=spawn(program,argv,{...native,env:processScopeEnvironment(ownershipScope,{...(native.env??process.env),...policy.environment,...(custodyToken?{RER_ONBOARDING_PROCESS_OWNER:[...inheritedScopeTokens(native.env??process.env),custodyToken].join(',')}:{})}),shell:false,detached:process.platform!=='win32',stdio:[Array.isArray(native.stdio)?native.stdio[0]:'ignore','pipe','pipe',...(native.stdio?.includes('ipc')?['ipc']:[])]});
|
|
128
132
|
onChild?.(child);
|
|
129
133
|
ownershipRecords.set(child,{pid:child.pid,token:ownershipScope.token});
|
|
130
134
|
track(label,child,ownershipScope);
|
|
131
|
-
Object.assign(captures.get(child),{cwd:native.cwd??process.cwd(),display:
|
|
135
|
+
Object.assign(captures.get(child),{cwd:native.cwd??process.cwd(),display:redaction.redact(String(display??command))});
|
|
132
136
|
const cancel=()=>{void stopCommand(child);};
|
|
133
137
|
commandSignal?.addEventListener('abort',cancel,{once:true});if(commandSignal?.aborted)cancel();
|
|
134
138
|
const capture=captures.get(child);capture.removeCancellation=()=>commandSignal?.removeEventListener('abort',cancel);
|
|
@@ -148,11 +152,12 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
|
|
|
148
152
|
let queuedChild;
|
|
149
153
|
const commandSignal=signal&&options.signal?AbortSignal.any([signal,options.signal]):options.signal||signal;
|
|
150
154
|
const result = await queuedCommand(command,args,{...options,verb:queuePolicy.verb,signal:commandSignal,originalCI:policy.ci,
|
|
151
|
-
label:await queueLabel(options.cwd??process.cwd(),queuePolicy.verb,options.phase??'command'),report,onWaiting,
|
|
155
|
+
label:await queueLabel(options.cwd??process.cwd(),queuePolicy.verb,options.phase??'command'),report,onWaiting,maxWait:queuePolicy.maxWait,queueOptions:queuePolicy.sampler?{sampler:queuePolicy.sampler}:undefined,
|
|
152
156
|
spawn:(program,argv,native)=>(queuedChild=spawnCommand(label,program,argv,{...native,onChild:options.onChild,display:options.display})),cleanup:async(child,result)=>{await stopCommand(child);await options.afterCommand?.(result);}});
|
|
157
|
+
if(result?.timedOut)throw busyRefusal({...result,reason:redaction.redact(String(result.reason))},{verb:queuePolicy.verb,maxWait:queuePolicy.maxWait??maxWaitSeconds});
|
|
153
158
|
if(result){if(result.code!==0)throw failure(label,result,captures.get(queuedChild));return result;}
|
|
154
159
|
}
|
|
155
|
-
let child;try{child=spawnCommand(label,command,args,options);}catch{throw failure(label,options.signal?.aborted||signal?.aborted?{reason:'cancel'}:{error:true});}
|
|
160
|
+
let child;try{child=spawnCommand(label,command,args,options);}catch{throw failure(label,options.signal?.aborted||signal?.aborted?{reason:'cancel'}:{error:true},{display:redaction.redact(String(options.display??command)),cwd:options.cwd,snapshot:()=>''});}
|
|
156
161
|
const capture=captures.get(child);
|
|
157
162
|
// Start cleanup at exit: inherited pipes can hold close open indefinitely.
|
|
158
163
|
// Only run's bounded command ends here; spawn's app stays owned until stop.
|
package/onboarding/failures.mjs
CHANGED
|
@@ -37,6 +37,13 @@ export function commandFailure(message, details = {}) {
|
|
|
37
37
|
const error=new Error(message);approved.set(error,{code:'captured_command_failed',message,details:{...details}});return error;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
// The job queue held a step until its wait ran out. The message names the load, the
|
|
41
|
+
// limit and the next step; callers show it as a refusal, never as a failed command.
|
|
42
|
+
export function busyFailure(message) {
|
|
43
|
+
const error=new Error(message);approved.set(error,{code:'machine_busy',message,details:{exitCode:4}});return error;
|
|
44
|
+
}
|
|
45
|
+
export const isBusyFailure = error => approved.get(error)?.code==='machine_busy';
|
|
46
|
+
|
|
40
47
|
// Terminal callers may expose only diagnostics approved at the capture boundary.
|
|
41
48
|
// A prior diagnostic's metadata must not replace the current composed message.
|
|
42
49
|
export const approvedFailure = error => { const value=approved.get(error); return value ? {...value.details,...value} : undefined; };
|
|
@@ -40,6 +40,6 @@ const developmentEnvironment = () => { const { RER_MODELS_SERVICE, RER_MODELS_KE
|
|
|
40
40
|
// A demo's Vite persists to its own folder (the seed's vite.config reads RER_STATE_DIR)
|
|
41
41
|
// and its Worker sees RER_DEMO=1 and the demo's end (modules/demo).
|
|
42
42
|
const demoBindings = demo => demo ? { RER_DEMO: '1', RER_DEMO_EXPIRES: demo.ends, RER_STATE_DIR: demo.state } : {};
|
|
43
|
-
export const developmentTarget = ({ root, origin, runtimePort, devKey, modelsLive, demo }) => [process.execPath, [projectViteBinary(root), 'dev', '--host', '127.0.0.1', '--port', internalPort(runtimePort), '--strictPort'], { env: { ...developmentEnvironment(), PATH: join(root, 'node_modules', '.bin')
|
|
43
|
+
export const developmentTarget = ({ root, origin, runtimePort, devKey, modelsLive, demo }) => [process.execPath, [projectViteBinary(root), 'dev', '--host', '127.0.0.1', '--port', internalPort(runtimePort), '--strictPort'], { env: { ...developmentEnvironment(), PATH: [process.env.PATH, join(root, 'node_modules', '.bin')].filter(value => value !== undefined).join(delimiter), RER_DEV_ORIGIN: origin, WRANGLER_SEND_METRICS: 'false', X_LOCAL_EXPLORER: 'false', ...devBindings(devKey), ...(modelsLive ? { RER_MODELS_SERVICE: modelsLive.baseUrl, RER_MODELS_KEY: modelsLive.apiKey } : {}), ...demoBindings(demo) } }];
|
|
44
44
|
|
|
45
45
|
export const previewTarget = ({ origin, runtimePort, devKey, scheduled }) => [process.execPath, [fileURLToPath(new URL('./production-runtime.mjs', import.meta.url))], { env: { ...process.env, RER_DEV_ORIGIN: origin, RER_RUNTIME_HOST: '127.0.0.1', RER_RUNTIME_PORT: internalPort(runtimePort), WRANGLER_SEND_METRICS: 'false', CLOUDFLARE_INCLUDE_PROCESS_ENV: 'false', X_LOCAL_EXPLORER: 'false', RER_RUNTIME_TRIGGERS: scheduled ? '1' : '0', ...(devKey ? { RER_DEV_KEY: devKey } : {}) } }];
|
package/onboarding/queue.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { createHash } from 'node:crypto';
|
|
|
4
4
|
import { readFile, realpath } from 'node:fs/promises';
|
|
5
5
|
const portable = basename(dirname(fileURLToPath(import.meta.url))) === 'base-onboarding';
|
|
6
6
|
const queueURL = new URL(portable ? '../base-cli/modules/job-queue/' : '../modules/job-queue/', import.meta.url);
|
|
7
|
+
export const maxWaitSeconds = 1200;
|
|
7
8
|
export const heavyVerbs = new Set(['install', 'setup', 'build', 'verify', 'dev', 'preview', 'deploy', 'release', 'export', 'import', 'installer']);
|
|
8
9
|
export const verificationBoundary = verb => verb === 'release' || verb === 'verify' || verb?.startsWith('verify:');
|
|
9
10
|
// The seed's display name (seed.json `name`, else its folder name) for terminal lines,
|
|
@@ -43,9 +44,9 @@ export async function queuedCommand(command, args, options) {
|
|
|
43
44
|
}
|
|
44
45
|
return null;
|
|
45
46
|
}
|
|
46
|
-
const queue = await createQueue();
|
|
47
|
+
const queue = await createQueue(options.queueOptions);
|
|
47
48
|
try {
|
|
48
|
-
const result = await queue.run([command, ...args], { ...options, kind: 'heavy', maxWait:
|
|
49
|
+
const result = await queue.run([command, ...args], { ...options, kind: 'heavy', maxWait: options.maxWait ?? maxWaitSeconds,
|
|
49
50
|
onWaiting: (reason, detail) => {
|
|
50
51
|
const wait = { ...(detail ?? { reason }), statusCommand, statusCommandText };
|
|
51
52
|
if (typeof options.onWaiting === 'function') return options.onWaiting(wait);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Select rer's own pinned tools without promoting their neighbouring programs
|
|
2
|
+
// ahead of the caller's PATH. Arbitrary project tools keep normal PATH lookup.
|
|
3
|
+
export function toolCommand(command, args = [], env = process.env) {
|
|
4
|
+
if (command === 'pnpm' && env.RER_PNPM_ENTRY) return [env.RER_NODE_BINARY ?? process.execPath, [env.RER_PNPM_ENTRY, ...args]];
|
|
5
|
+
if (command === 'node' && env.RER_NODE_BINARY) return [env.RER_NODE_BINARY, args];
|
|
6
|
+
return [command, args];
|
|
7
|
+
}
|