@runeditrun/rer 0.2.50 → 0.2.52

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.
@@ -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 retained=await lstat(worktree).then(()=>true,error=>{if(error.code==='ENOENT')return false;throw error;});
29
- if(retained) {
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);
@@ -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
 
@@ -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
- if(['install','setup','build','verify','deploy','release','export','import'].includes(options.verb)) {
17
- try{await store.run('Running declared project command',program,[...argv,...options.forwarded],{cwd:project.root,signal});return {childExitCode:0,signal:null};}
18
- catch(error){const code=error.signal?({SIGINT:130,SIGTERM:143}[error.signal]??1):error.childExitCode??1;throw new RerError('child_failed','The declared command failed.',code,{childExitCode:error.childExitCode,signal:error.signal});}
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 => { process.env.PATH = [directory, dirname(process.execPath), process.env.PATH].filter(Boolean).join(delimiter); };
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
- if (temporary) await rm(temporary, { recursive: true, force: true });
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
  }
@@ -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, PATH: dirname(binary) + delimiter + (process.env.PATH ?? '') },
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);
@@ -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
- // `node` is rer's own: the command puts its Node first on PATH beside this.
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)); }
@@ -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) ? [declaredCredentials.join(' or ') || credentialKeys.join(' or ')] : []),
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
  ];
@@ -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
- // Select the verified pnpm before any tool beside Node. Its shim still finds
62
- // this process's Node before the caller's PATH, but cannot be shadowed by a
63
- // different pnpm installed in that Node's bin directory.
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;
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.52
4
+
5
+ - **Shared job queues use one slot limit.** Every client sharing a queue directory admits against the same limit, so an older shell requesting three slots no longer holds up a five-slot queue. A live `config.json` slot limit is authoritative; otherwise the largest live client request sets the limit. Clients requesting a different limit see the queue's effective limit and configuration path. FIFO ordering, load admission and available-memory admission stay in place (#244).
6
+
7
+ ## 0.2.51
8
+
9
+ - **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).
10
+ - **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).
11
+ - **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).
12
+ - **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).
13
+
14
+ - **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).
15
+
3
16
  ## 0.2.50
4
17
 
5
18
  - **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).
@@ -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
- PATH="$root/node/bin:$PATH"
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 ! command -v node >/dev/null 2>&1; then
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.PATH = [dirname(binary), env.PATH].filter(Boolean).join(delimiter);
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 child = spawn('pnpm', ['run', '--silent', ...args], { cwd: target.root, env: process.env, stdio: 'inherit' });
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
- if ! command -v node >/dev/null 2>&1 || ! node -e 'process.exit(Number(process.versions.node.split(".")[0]) >= 22 ? 0 : 1)' >/dev/null 2>&1; then
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
- node - "$work/metadata.json" "${RER_VERSION:-}" >"$work/release" <<'NODE' || exit 1
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
- node - "$work/rer.tgz" "$integrity" "$files" "$size" <<'NODE' || fail "the download of rer $version was refused; nothing was installed."
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 node "$work/stage/package/global/rer.mjs" cli install </dev/null \
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:$PATH"
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
- PATH="$node_home/bin:$PATH"
200
+ node_binary="$node_home/bin/node"
201
+ PATH="$PATH:$node_home/bin"
200
202
  export PATH
201
203
  }
202
204
 
@@ -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. Applied entries must be an unchanged prefix of the desired set. 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.
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
- const validPrefix = (rows, migrations) => rows.every((row, index) => recorded(row, migrations[index]) && row.state === 'applied');
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 a
48
- * valid prefix, the error names that claim (`unconfirmedClaim`) so the refusal can
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 ?? '') && validPrefix(rows.slice(0, -1), migrations)) {
54
- const next = migrations[rows.length - 1];
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(validPrefix(old, migrations), 'changed-or-uncertain-migration-history');
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 whose import did not
79
- // complete: its exact bytes, or (`rewritten`) bytes a reviewed rewrite replaced.
80
- // migrate re-runs it only on proof (migration-retry.mjs).
81
- const last = applied.at(-1), next = migrations[applied.length - 1];
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 (!validPrefix(applied, migrations)) throw unmatched(applied, migrations);
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
- const final = (await query(api,id,`SELECT name, sha256, state FROM ${ledger} ORDER BY id`))[0].results;
87
- assert(final.length === migrations.length && final.every((x,i) => x.state === 'applied' && recorded(x, migrations[i])), 'migration-readback-mismatch');
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
  }
@@ -36,7 +36,7 @@ threshold when one is set, and available memory is strictly above the floor. Def
36
36
 
37
37
  | Setting in config.json | Default | Environment override |
38
38
  | --- | --- | --- |
39
- | slots | max(1, min(3, floor(CPUs / 4), floor(RAM / 8 GiB))) | RER_JOBS_SLOTS |
39
+ | slots | max(1, min(3, floor(CPUs / 4), floor(RAM / 8 GiB))) | RER_JOBS_SLOTS (request; shared policy below) |
40
40
  | loadThreshold | none: a fleet sets one in its own environment | RER_JOBS_LOAD_THRESHOLD |
41
41
  | minFreeMemoryBytes | 2 GiB | RER_JOBS_MIN_FREE_MEMORY_BYTES |
42
42
  | pollMs | 3000 | RER_JOBS_POLL_MS |
@@ -44,9 +44,20 @@ threshold when one is set, and available memory is strictly above the floor. Def
44
44
  | killGraceMs | 1000 | RER_JOBS_KILL_GRACE_MS |
45
45
 
46
46
  Put numeric settings in `$RER_JOBS_DIR/config.json` (or `~/.rer/jobs/config.json`).
47
- Environment overrides take precedence. All clients should use the same policy;
48
- central config avoids differing limits between sessions. Resource settings are
49
- read when a client is created. `status` prints its effective policy, current load,
47
+ For slots, `config.json` is authoritative and is read under the queue lock on
48
+ every operation, including admission: its `slots` overrides environment and
49
+ library requests from every client. Without a configured `slots`, the shared
50
+ limit is the largest slot request among live queue clients (environment, library
51
+ override, or hardware default). The limit and live membership are recorded in
52
+ `state.json` under the same lock as admission. Closing or reclaiming a dead client
53
+ removes its request; lowering the limit never interrupts running jobs. A client
54
+ whose request differs prints one line per differing effective limit, naming
55
+ the queue's limit and `config.json` as the way to change it. Thus an older shell
56
+ requesting 3 cannot block a head waiter when another live client requests 5.
57
+ Restart clients using older queue code before sharing this policy.
58
+
59
+ Environment overrides still take precedence for the other settings. Resource settings are
60
+ read when a client is created. `status` prints the shared slot limit, current load,
50
61
  available and raw free memory, running labels/repositories/elapsed times, ordered
51
62
  waiting jobs, and the head's admission reason. Available memory is what the OS
52
63
  can reclaim: on macOS the free, inactive, speculative and purgeable pages from
@@ -35,7 +35,7 @@ export function ordered(jobs) {
35
35
 
36
36
  // Each reason says what is running, what the limit is and how to change it.
37
37
  export function admissionDetails(running, config, sample) {
38
- if (running >= config.slots) return { code: 'slots', reason: `all job slots are in use (${running} of ${config.slots}; change with RER_JOBS_SLOTS)` };
38
+ if (running >= config.slots) return { code: 'slots', reason: `all job slots are in use (${running} of ${config.slots}; change slots in ${config.directory}/config.json)` };
39
39
  if (!Number.isFinite(sample.load) || !Number.isFinite(sample.availableMemoryBytes))
40
40
  return { code: 'resources_unavailable', reason: 'this computer\'s load or available memory could not be read' };
41
41
  if (sample.load > config.loadThreshold) return { code: 'load',
@@ -8,17 +8,29 @@ import { transaction } from './storage.mjs';
8
8
  import { sampleResources } from './resources.mjs';
9
9
  import { execute, signalExit } from './command.mjs';
10
10
  import { stopGroup } from './processes.mjs';
11
+ import { sharedSlots } from './slots.mjs';
11
12
 
12
13
  const WAIT_REPORT_INTERVAL_MS = 15_000;
13
14
 
14
15
  export async function createQueue(options = {}) {
15
16
  const config = await configuration(options), lifetime = await identity();
16
17
  const sampler = options.sampler ?? sampleResources;
17
- let active = 0, closed = false;
18
- const mutate = action => {
18
+ const member = { owner: lifetime.info, slots: config.slots, directory: config.directory };
19
+ let active = 0, closed = false, lastSlotNotice;
20
+ const mutate = async action => {
19
21
  if (closed) throw Error('Job queue is closed');
20
- return transaction(config.directory, lifetime.info, action);
22
+ const result = await transaction(config.directory, lifetime.info, async state => {
23
+ config.slots = await sharedSlots(state, member);
24
+ return action(state);
25
+ });
26
+ if (config.slots !== member.slots && config.slots !== lastSlotNotice) {
27
+ console.error(`Job queue uses ${config.slots} slots (this client requested ${member.slots}); set "slots" in ${config.directory}/config.json to change the shared limit.`);
28
+ lastSlotNotice = config.slots;
29
+ }
30
+ return result;
21
31
  };
32
+ try { await mutate(() => {}); }
33
+ catch (error) { await lifetime.close(); throw error; }
22
34
  async function reclaim(state) {
23
35
  for (const key of ['queued', 'running']) {
24
36
  const kept = [];
@@ -38,7 +50,7 @@ export async function createQueue(options = {}) {
38
50
  const resources = await sampler();
39
51
  const describe = ({ command, membership, owner: { token, socket, ...owner }, ...job }) => ({ ...job, owner,
40
52
  elapsedSeconds: Math.floor((Date.now() - (job.startedAt ?? job.enqueuedAt)) / 1000) });
41
- return { running: state.running.map(describe), queued: ordered(state.queued).map(describe), resources, config,
53
+ return { running: state.running.map(describe), queued: ordered(state.queued).map(describe), resources, config: { ...config },
42
54
  admissionReason: state.queued.length ? admissionDetails(state.running.length, config, resources)?.reason ?? 'ready' : 'queue empty' };
43
55
  });
44
56
  }
@@ -128,6 +140,9 @@ export async function createQueue(options = {}) {
128
140
  }
129
141
  return { config, run, status, drain, async close() {
130
142
  if (active) throw Error('Cannot close a queue with active jobs');
131
- closed = true; await lifetime.close();
143
+ if (closed) return;
144
+ closed = true;
145
+ try { await transaction(config.directory, lifetime.info, state => sharedSlots(state, member, false)); }
146
+ finally { await lifetime.close(); }
132
147
  } };
133
148
  }
@@ -0,0 +1,19 @@
1
+ import { join } from 'node:path';
2
+ import { alive } from './identity.mjs';
3
+ import { readJson } from './storage.mjs';
4
+
5
+ // Called only under the queue's transaction lock. Config is authoritative;
6
+ // without it every client uses the largest request from the same live members.
7
+ export async function sharedSlots(state, member, register = true) {
8
+ const members = [];
9
+ for (const item of state.slotMembers ?? []) {
10
+ if (item.owner.token !== member.owner.token && await alive(item.owner)) members.push(item);
11
+ }
12
+ if (register) members.push(member);
13
+ const disk = await readJson(join(member.directory, 'config.json'), {});
14
+ if (disk.slots !== undefined && (!Number.isInteger(disk.slots) || disk.slots < 1))
15
+ throw Error('Invalid job queue slots in config.json');
16
+ state.slotMembers = members;
17
+ state.slots = disk.slots ?? Math.max(1, ...members.map(item => item.slots));
18
+ return state.slots;
19
+ }
@@ -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
- const PAGE_STYLE = 'body{margin:0;font:16px/1.5 system-ui,sans-serif;color:#17212e;background:#f5f7fa}main{max-width:36rem;margin:0 auto;padding:32px 16px}';
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
- 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><style>${PAGE_STYLE}</style></head><body><main><h1>Opening the local app</h1><p>Open the RER_OPEN link that rer prints on this computer.</p></main><script>${EXCHANGE_SCRIPT}</script></body></html>`;
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;
@@ -10,6 +10,7 @@ import { checkoutPath, stepDiagnostic } from './step-failure.mjs';
10
10
  import { waitForReadiness } from './readiness.mjs';
11
11
  import { commandCustody } from './command-custody.mjs';
12
12
  import { createProcessBaseline, createProcessScope, inheritedScopeTokens, processScopeEnvironment } from './process-scope.mjs';
13
+ import { toolCommand } from './tool-command.mjs';
13
14
 
14
15
  export async function createCommands(directory,state,{terminal=text=>writeSync(1,text),spawn=spawnChild,queue:queuePolicy,custodyToken,onWaiting}={}) {
15
16
  let policy=queuePolicy?await commandPolicy():{environment:{},close:async()=>{}};
@@ -52,7 +53,7 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
52
53
  const lines=(capture?.snapshot()||'').split('\n');if(lines.at(-1)==='')lines.pop();
53
54
  // The step, its command, exit code, last output and log, for callers that name a failed step.
54
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))});
55
- 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});
56
57
  };
57
58
  const track=(label,child,ownershipScope)=>{
58
59
  if(captures.has(child))return child;
@@ -120,16 +121,18 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
120
121
  // label must not show that label twice.
121
122
  const announced=redaction.redact(String(label)),repeated=state.step===announced;
122
123
  state.step=announced;if(!repeated)report(label);
123
- // display: the command line a caller names in its failure; argv itself is never shown.
124
+ // Name the executable by default; only a caller's explicit safe display may
125
+ // include arguments. Raw argv can contain private positional values.
124
126
  const {signal:providedSignal,afterCommand,onChild,heavy,phase,display,...native}=options;
125
127
  const commandSignal=signal&&providedSignal?AbortSignal.any([signal,providedSignal]):providedSignal||signal;
126
128
  if(commandSignal?.aborted)throw failure(label,{reason:'cancel'});
127
129
  const ownershipScope=createProcessScope(custodyBaseline);redaction.addSecrets([ownershipScope.token,...inheritedScopeTokens(process.env),...inheritedScopeTokens(native.env)]);
128
- const child=spawn(command,args,{...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']:[])]});
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']:[])]});
129
132
  onChild?.(child);
130
133
  ownershipRecords.set(child,{pid:child.pid,token:ownershipScope.token});
131
134
  track(label,child,ownershipScope);
132
- Object.assign(captures.get(child),{cwd:native.cwd??process.cwd(),display:display===undefined?undefined:redaction.redact(String(display))});
135
+ Object.assign(captures.get(child),{cwd:native.cwd??process.cwd(),display:redaction.redact(String(display??command))});
133
136
  const cancel=()=>{void stopCommand(child);};
134
137
  commandSignal?.addEventListener('abort',cancel,{once:true});if(commandSignal?.aborted)cancel();
135
138
  const capture=captures.get(child);capture.removeCancellation=()=>commandSignal?.removeEventListener('abort',cancel);
@@ -154,7 +157,7 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
154
157
  if(result?.timedOut)throw busyRefusal({...result,reason:redaction.redact(String(result.reason))},{verb:queuePolicy.verb,maxWait:queuePolicy.maxWait??maxWaitSeconds});
155
158
  if(result){if(result.code!==0)throw failure(label,result,captures.get(queuedChild));return result;}
156
159
  }
157
- 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:()=>''});}
158
161
  const capture=captures.get(child);
159
162
  // Start cleanup at exit: inherited pipes can hold close open indefinitely.
160
163
  // Only run's bounded command ends here; spawn's app stays owned until stop.
@@ -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') + delimiter + (process.env.PATH ?? ''), 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) } }];
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 } : {}) } }];
@@ -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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runeditrun/rer",
3
- "version": "0.2.50",
3
+ "version": "0.2.52",
4
4
  "description": "The rer command: install, set up, run and launch Run Edit Run checkouts.",
5
5
  "license": "MIT",
6
6
  "type": "module",