@runeditrun/rer 0.2.111 → 0.2.113

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/README.md CHANGED
@@ -5,7 +5,7 @@ Allow roughly 500 MB–1 GB of downloads and 1–3 GB of disk space for a first
5
5
  <!-- END COLD RUN BUDGET -->
6
6
 
7
7
  `rer` is the Run Edit Run command. Install it once, then run `rer <verb>` in any
8
- Run Edit Run checkout: every verb runs that checkout's own pinned copy, so a
8
+ Run Edit Run checkout: project verbs run that checkout's own pinned copy, so a
9
9
  checkout always gets the behaviour it was built and tested with.
10
10
 
11
11
  For source authors, `rer adopt-edition` adds a recipe and lock to existing tracked
@@ -47,7 +47,20 @@ changing PATH: a child installer cannot change its parent shell’s PATH, and ba
47
47
  `~/.local/bin`, its closing lines give one required step: the
48
48
  `export PATH="$HOME/.local/bin:$PATH"` line to run now and add to your shell
49
49
  startup file, or `rer cli path` (by its absolute launcher) for other shells.
50
- The same start also fits on one line:
50
+ To run a downloaded JavaScript tool, open its folder in the terminal and use
51
+ `"$HOME/.local/bin/rer" run --script ./tool.mjs` followed by its arguments.
52
+ For example, from Downloads the Oncall PagerDuty exporter runs with:
53
+
54
+ ```sh
55
+ "$HOME/.local/bin/rer" run --script ./oncall-export.mjs pagerduty
56
+ ```
57
+
58
+ `--script` uses the Node running `rer`, including the installer's private Node;
59
+ it needs no checkout, pnpm or separate Node installation. The file path is
60
+ relative to the current folder, or to `--cwd DIR` when supplied before
61
+ `--script`. Remaining arguments go directly to the file. A package script
62
+ (`rer run NAME`) continues to use the checkout's pinned Node and pnpm.
63
+ The app start also fits on one line:
51
64
 
52
65
  ```sh
53
66
  curl -fsSL https://runeditrun.com/install.sh | sh -s -- dev just-every/run-inkwell
package/cli/README.md CHANGED
@@ -468,6 +468,62 @@ retirement and preserve the environment, checkout and env-file in recovery
468
468
  commands. Retirement can be finished with `rer deploy --unset-secret SETUP_TOKEN`
469
469
  plus the same `--environment`, `--env-file` and `--cwd` arguments.
470
470
 
471
+ A seed may declare an optional `commandAdapter.deployPolicy` function:
472
+
473
+ ```js
474
+ import { missing } from '@runeditrun/rer/errors';
475
+
476
+ const deployPolicy = async ({ root, options, environment, env, bindings,
477
+ declaration, declarationPath }) => {
478
+ // Normalize any seed-specific choices in a local copy, then validate the
479
+ // applicable operation. Binding values already resolve declared env aliases.
480
+ if (options.setSecret && env.MAIL_MODE === 'off'
481
+ && options.setSecret.split(',').some(name => name === 'OUTBOUND_TOKEN' && bindings[name]?.trim())) {
482
+ throw missing('Credentials are not bound while email is off.');
483
+ }
484
+ };
485
+ ```
486
+
487
+ The public application `rer deploy` door awaits this hook once, before dispatching
488
+ any build, custom deploy hook or owner-account provider operation, including
489
+ account/subdomain lookup and receipt recovery. It runs for ordinary deploy,
490
+ `--dry-run`, `--set-secret`, `--unset-secret`, `--rotate-secret`,
491
+ `--reopen-installation-key` and `--remove`; the seed chooses which policy applies
492
+ to each operation, allowing cleanup where appropriate. Run-site, hosted-demo and
493
+ independent-command doors retain their own contracts. A policy must stay local:
494
+ no provider calls, build, settings writes or secret output.
495
+
496
+ `options` is a copy of the parsed CLI options: repeated/comma-separated secret
497
+ flags have their usual deduplicated binding-name list. `environment` defaults to
498
+ `production`. `env` is the effective deploy environment (process environment,
499
+ then the owned `--env-file` override, then existing declared owner/generated
500
+ input supply). `bindings` starts with declaration `vars` and overlays nonblank
501
+ secret values under their declared Worker binding names, using each secret's
502
+ `environment` mapping. For example, `{binding:'OUTBOUND_TOKEN',
503
+ environment:'EMAIL_API_KEY'}` exposes `env.EMAIL_API_KEY` as
504
+ `bindings.OUTBOUND_TOKEN`; ambient `env.OUTBOUND_TOKEN` cannot override that
505
+ mapping. These are proposed local inputs, not a read of existing hosted secrets.
506
+ `root`, `declaration` and checkout-relative `declarationPath` name the selected
507
+ checkout and deploy declaration. Values are private; do not log them.
508
+
509
+ This is a validation hook: treat inputs as read-only; its return value is ignored.
510
+ Seed-specific provider enums and additional aliases remain the seed's job:
511
+ normalize them into a local copy before checking policy. Keep any deploy hook's
512
+ existing runtime normalization. A successful policy returns normally; throw a
513
+ `RerError` from the same rer copy/package to refuse. `missing(message)` gives exit
514
+ 3 and JSON `error` with `code:"missing_input"`, `message`, `exitCode:3`, followed
515
+ by `result` with `ok:false`, `exitCode:3`; `refuse(message)` retains the existing
516
+ exit-4 `safety_refusal`. Other errors retain the existing command-failure path.
517
+ A refusal stops before any provider contact. A declared non-function policy is
518
+ an invalid invocation (exit 2).
519
+
520
+ Seeds without this optional hook keep the existing contract: secret mutations
521
+ use the owner-account controller's declaration, value and ownership checks,
522
+ without invoking the application's build/deploy hook or the full-deploy
523
+ production-auth preflight. Full deployments still run that shared preflight.
524
+ No seed-specific mail policy is inferred. Low-level kit/controller callers remain
525
+ responsible for their own policy; this hook belongs to the public CLI adapter.
526
+
471
527
  ## Local business signals
472
528
 
473
529
  `rer business scan [DIR...] [--json]` reads local source and configuration names;
@@ -1,4 +1,5 @@
1
1
  import { requireProductionAuth, mailOffNotice } from './production-auth.mjs';
2
+ import { enforceDeployPolicy } from './deploy-policy.mjs';
2
3
  import { observedReadiness } from '../modules/deploy-kit/readiness-window.mjs';
3
4
  import { readFile, readdir } from 'node:fs/promises';
4
5
  import { contained } from './project.mjs';
@@ -80,6 +81,7 @@ export async function deployCommand(context) {
80
81
  if (local) throw refuse(`${path} names the local-only key ${local} as a deploy binding or secret. Remove it; local dev keys never reach a deployment.`);
81
82
  deployGuide(declaration);
82
83
  const settings = adapter.hooks?.secrets ?? adapter.settings;
84
+ await enforceDeployPolicy({ ...context, declaration, declarationPath: path, settings });
83
85
  // Required secrets have been checked; retain the production sign-in guidance.
84
86
  const dryRun = async (result, { planned = true, extraNeeded } = {}) => {
85
87
  const production = await deployEnvironment({ root, options, declaration, setupManifest, settings, localOnlyKeys });
@@ -0,0 +1,18 @@
1
+ import { deployPermissions } from './deploy-needs.mjs';
2
+
3
+ // An offline plan knows the declared migrations, never which ones the hosted
4
+ // databases have applied. Keep that distinction in the human summary.
5
+ export function deployPlanLines(plan, declaration) {
6
+ const lines = ['Would deploy:', ` Worker: ${plan.worker}`];
7
+ for (const database of plan.d1) lines.push(` D1 database: ${database.name} (${database.migrations.length} declared migration${database.migrations.length === 1 ? '' : 's'})`);
8
+ if (!plan.d1.length) lines.push(' D1 databases: none');
9
+ for (const [kind, label] of [['r2', 'R2 storage'], ['kv', 'KV storage'], ['queues', 'Queue'], ['services', 'Worker service']]) {
10
+ for (const item of plan[kind]) lines.push(` ${label}: ${item.name ?? item.service}`);
11
+ }
12
+ if (plan.durableObjects.length) lines.push(` Durable Objects: ${plan.durableObjects.length}`);
13
+ lines.push(` Secret inputs: ${plan.secrets.filter(item => !item.optional).length} required, ${plan.secrets.filter(item => item.optional).length} optional`);
14
+ lines.push(` Public settings: ${plan.vars.length}; scheduled triggers: ${plan.crons.length}`);
15
+ lines.push(` Cloudflare token permissions: ${deployPermissions(declaration).join(', ')}`);
16
+ lines.push(' Pending migrations: unknown until the hosted databases are checked.');
17
+ return lines;
18
+ }
@@ -0,0 +1,18 @@
1
+ import { deployEnvironment } from './deploy-inputs.mjs';
2
+ import { invalid } from './errors.mjs';
3
+
4
+ // Seed policy is separate from uploading: secret-only commands bypass the
5
+ // deploy hook, but must not bypass a seed's applicable local input policy.
6
+ export async function enforceDeployPolicy({ adapter, root, options, store, setupManifest, localOnlyKeys, declaration, declarationPath, settings }) {
7
+ if (adapter.deployPolicy === undefined) return;
8
+ await store.step('Checking deploy policy');
9
+ if (typeof adapter.deployPolicy !== 'function') throw invalid('The adapter deployPolicy must be a function.');
10
+ const { env } = await deployEnvironment({ root, options, declaration, setupManifest, settings, localOnlyKeys });
11
+ // Resolve declared environment aliases before policy sees Worker bindings.
12
+ // Arbitrary ambient binding-name values never override an explicit mapping.
13
+ const bindings = { ...declaration.vars };
14
+ for (const secret of declaration.secrets ?? []) {
15
+ if (env[secret.environment]?.trim()) bindings[secret.binding] = env[secret.environment];
16
+ }
17
+ await adapter.deployPolicy({ root, options: { ...options }, environment: options.environment ?? 'production', env, bindings, declaration, declarationPath });
18
+ }
package/cli/deploy.mjs CHANGED
@@ -22,6 +22,8 @@ import { keptSecrets, keepSecrets, forgetSecrets } from './deploy-secrets.mjs';
22
22
  import { withoutLocalSettings, refuseLocalEnvOutput } from './local-env.mjs';
23
23
  import { deployProductDirectory, deployProductArguments } from './deploy-product.mjs';
24
24
  import { rotateInstallationKey, reopenInstallationKey, keepInstallationKey } from './deploy-installation-key.mjs';
25
+ import { deployPlanLines } from './deploy-plan.mjs';
26
+ import { relative } from 'node:path';
25
27
 
26
28
  export function ownerDeploy(declarationPath, lifecycle) {
27
29
  // rer verify serves the build with this declaration's vars and secrets.
@@ -69,7 +71,9 @@ export function ownerDeploy(declarationPath, lifecycle) {
69
71
  try {
70
72
  if (options.dryRun) {
71
73
  const {plan} = await owner('local-plan');
72
- store.report(`Would deploy: ${JSON.stringify(plan)}`);
74
+ store.report(`Deploy plan: ${JSON.stringify(plan)}`, { logOnly: true });
75
+ for (const line of deployPlanLines(plan, declaration)) store.report(line);
76
+ store.report(`Full plan: repeat this command with --json.${store.logPath ? ` Redacted capture log: ${relative(root, store.logPath)}` : ''}`);
73
77
  return { dryRun: true, deployed: false, providerChecked: false, plan };
74
78
  }
75
79
  // A custom hook's own state file, when its deploy named one.
@@ -1,12 +1,18 @@
1
+ import { shellQuote } from './node-runtime-cache.mjs';
1
2
  // The one line a finished export ends with: which copy it exported, the
2
3
  // archive, its size and what it holds.
3
- export function exportSummary({ target = 'local', origin, output, bytes, tables, hostedExport, childExitCode, exitCode = childExitCode } = {}) {
4
+ export function exportSummary({ target = 'local', origin, output, bytes, tables, captureLog, hostedExport, childExitCode, exitCode = childExitCode } = {}) {
4
5
  if (typeof output !== 'string') return undefined;
5
6
  const copy = target === 'remote' ? `the hosted install${origin ? ` at ${origin}` : ''}` : 'the local copy';
6
7
  if (hostedExport && Number.isInteger(exitCode)) return exitCode === 0 ? `Exported ${copy} to ${output} (exit 0)` : `Export of ${copy} to ${output} failed (exit ${exitCode})`;
7
8
  if (!Number.isSafeInteger(bytes) || !Array.isArray(tables)) return undefined;
8
9
  const rows = tables.reduce((sum, table) => sum + (Number.isSafeInteger(table?.count) ? table.count : 0), 0);
9
- return `Exported ${copy} to ${output} (${size(bytes)}): ${counted(tables.length, 'table')}, ${counted(rows, 'row')}`;
10
+ const file = /^[A-Za-z0-9_./-]+$/.test(output) ? output : shellQuote(output);
11
+ return [
12
+ `Exported ${copy} to ${output} (${size(bytes)}): ${counted(tables.length, 'table')}, ${counted(rows, 'row')}`,
13
+ captureLog && `Full output: ${captureLog}`,
14
+ `To restore into an empty installation: rer import --input ${file} --yes`,
15
+ ].filter(Boolean).join('\n');
10
16
  }
11
17
 
12
18
  const counted = (value, noun) => `${value.toLocaleString('en-US')} ${noun}${value === 1 ? '' : 's'}`;
@@ -1,4 +1,17 @@
1
1
  // Only declared safe replacement values and aggregate counts reach the terminal.
2
+ export function importSummary(details = {}) {
3
+ const { input, tables, target = 'local', objects, captureLog, nextCommand = 'rer setup' } = details;
4
+ if (typeof input !== 'string' || !Array.isArray(tables)) return undefined;
5
+ const rows = tables.reduce((sum, table) => sum + (Number.isSafeInteger(table?.count) ? table.count : 0), 0);
6
+ return [
7
+ `Restored ${target === 'local' ? 'the local copy' : 'the hosted install'} from ${input}: ${count(tables.length, 'table')}, ${count(rows, 'row')}${Number.isSafeInteger(objects) ? `, ${count(objects, 'file')}` : ''}.`,
8
+ importSafetySummary(details),
9
+ captureLog && `Full output: ${captureLog}`,
10
+ `Next: ${nextCommand}${target === 'local' ? ', then rer dev to open the restored app' : ''}.`,
11
+ ].filter(Boolean).join('\n');
12
+ }
13
+ const count = (value, noun) => `${value.toLocaleString('en-US')} ${noun}${value === 1 ? '' : 's'}`;
14
+
2
15
  export function importSafetySummary({safetyChanges}={}) {
3
16
  if(!safetyChanges?.length)return undefined;
4
17
  return safetyChanges.map(({table,column,value,rows})=>
package/cli/lifecycle.mjs CHANGED
@@ -82,7 +82,7 @@ async function runLifecycle(project, options, out, deployRedaction) {
82
82
  const directory = project.profile === 'first-party' && options.verb !== 'doctor' ? await privateDirectory(project.root, capture) : (temporary = await mkdtemp(join(tmpdir(), 'rer-command-')));
83
83
  const state = { logs: [] };
84
84
  const progress = text => { if (!installingFrozen || options.json) out.progress(text); };
85
- store = await createCommands(directory, state, { terminal: options.verb === 'deploy' && options.dryRun ? withoutPnpmChatter(progress) : progress, onWaiting: options.json ? details => out.event('waiting', details) : undefined, queue: ['install','setup','build','verify','deploy','export','import'].includes(options.verb)?{verb:options.verb,originalCI:process.env.CI==='true'}:undefined });
85
+ store = await createCommands(directory, state, { filterViteWarnings: options.verb === 'setup', filterArchiveReceipts: options.verb === 'export', terminal: options.verb === 'deploy' && options.dryRun ? withoutPnpmChatter(progress) : progress, onWaiting: options.json ? details => out.event('waiting', details) : undefined, queue: ['install','setup','build','verify','deploy','export','import'].includes(options.verb)?{verb:options.verb,originalCI:process.env.CI==='true'}:undefined });
86
86
  store.state = state;
87
87
  if (deployRedaction) store.addSecrets?.(Object.values(process.env).filter(value => value && deployRedaction.redact(value) !== value));
88
88
  store.setupManifest = project.setupManifest;
@@ -163,6 +163,8 @@ async function runLifecycle(project, options, out, deployRedaction) {
163
163
  const deployNeeds = await hostedNeeds(project);
164
164
  if (options.json) out.event('setup-ready', { url, setupUrl: url+'/setup', ...(deployNeeds.length ? { neededForDeploy: deployNeeds } : {}) });
165
165
  else {
166
+ const { checkoutPath } = await shared('step-failure.mjs');
167
+ out.human(`Setup complete: ${state.migrationsApplied ? `${state.migrationsApplied} migration${state.migrationsApplied === 1 ? '' : 's'} applied` : 'database already up to date'}, owner set up. Full output: ${store.redact(checkoutPath(project.root, store.logPath))}`);
166
168
  out.human(`RER_SETUP_READY ${url}`); out.human(`Next: rer dev opens ${url} signed in as the owner; first-run setup finishes at ${url}/setup. rer preview prints a one-time native owner link on loopback; rer demo also prints a separate native owner entry.`);
167
169
  if (deployNeeds.length) out.human(['To host it on your own Cloudflare account later, rer deploy needs:', ...deployNeeds.map(item => ` - ${item}`), 'Set them in your environment or a private (mode 0600) file passed with --env-file, then check with rer deploy --dry-run.'].join('\n'));
168
170
  }
package/cli/output.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { humanError } from './human-error.mjs';
2
2
  import { handleBrokenPipes } from './stdio.mjs';
3
3
  import { exportSummary } from './export-summary.mjs';
4
- import { importSafetySummary } from './import-summary.mjs';
4
+ import { importSummary, importSafetySummary } from './import-summary.mjs';
5
5
  export function output(options) {
6
6
  handleBrokenPipes();
7
7
  let finished = false;
@@ -21,7 +21,7 @@ export function output(options) {
21
21
  if (structuredResult) this.event('result', { ok, exitCode, ...details });
22
22
  // A finished export ends with one line naming its archive; the receipt is --json data.
23
23
  else if (options.verb === 'export' && (ok || details.hostedExport) && exportSummary({ ...details, exitCode })) this.human(exportSummary({ ...details, exitCode }));
24
- else if (ok && options.verb === 'import' && importSafetySummary(details)) this.human('import: complete (exit 0)\n' + importSafetySummary(details));
24
+ else if (ok && options.verb === 'import' && (importSummary(details) || importSafetySummary(details))) this.human(importSummary(details) || ('import: complete (exit 0)\n' + importSafetySummary(details)));
25
25
  else if (!['describe', 'check', 'dev', 'preview', 'setup'].includes(options.verb) || !ok) this.human(`${options.verb}: ${ok ? 'complete' : 'failed'} (exit ${exitCode})`);
26
26
  },
27
27
  error(error) {
@@ -65,7 +65,7 @@ export function localPortability({ database, binding = 'DB', buckets = {}, polic
65
65
  if(direction==='import' && !legacyRecovery) {
66
66
  try { await emptyNativePreflight(input); }
67
67
  catch(error) {
68
- if(error instanceof PortabilityError && error.code.startsWith('target_not_empty:'))throw new RerError('restore_refused',occupiedRefusal(input,'target_not_empty',error.code.slice(error.code.indexOf(':')+1)),4);
68
+ if(error instanceof PortabilityError && error.code.startsWith('target_not_empty:'))throw new RerError('restore_refused',occupiedRefusal(input,'target_not_empty'),4);
69
69
  if(error instanceof PortabilityError)throw refuse(`Local restore refused (${error.code}).`);
70
70
  throw error;
71
71
  }
@@ -73,11 +73,11 @@ export function localPortability({ database, binding = 'DB', buckets = {}, polic
73
73
  if(unverifiedSchemaRecovery)await nativeWorker(store,'schema-recovery-preflight',input,signal);
74
74
  const {nativeApply}=await nativeWorker(store,'migration-preflight',input,signal);
75
75
  // Local migrations need no provider account: wrangler runs without credentials.
76
- // Its info lines (the local location and "Use --remote if you want to access
77
- // the remote instance") only confuse a local backup; warnings and errors print.
76
+ // The shared runner shows its progress (a count every ten migrations) and leaves out its
77
+ // own info lines, which only confuse a local backup; warnings and errors print.
78
78
  const { dependencyEnvironment } = await shared('dependency-environment.mjs');
79
79
  if(nativeApply)await store.run('Applying local data migrations', 'pnpm', ['exec', 'wrangler', 'd1', 'migrations', 'apply', database, '--local', '--persist-to', '.wrangler/state', '--config', 'wrangler.jsonc'], {
80
- cwd: root, signal, env: { ...dependencyEnvironment(), RER_LOCAL_OPERATION: operationToken, WRANGLER_SEND_METRICS: 'false', WRANGLER_LOG: 'warn' },
80
+ cwd: root, signal, env: { ...dependencyEnvironment(), RER_LOCAL_OPERATION: operationToken, WRANGLER_SEND_METRICS: 'false' },
81
81
  });
82
82
  const receipt=await nativeWorker(store,direction,input,signal);
83
83
  if(legacyRecovery)receipt.output=relative(root,legacyRecovery.output);
@@ -109,12 +109,12 @@ async function nativeWorker(store,direction,input,signal) {
109
109
  : receipt.safety ? `Restore refused (${receipt.reason}): safety normalization for ${receipt.safety} violates the declared import policy.`
110
110
  : receipt.reason?.startsWith('migration_ledger:') ? ledgerRefusal(receipt)
111
111
  : receipt.migration ? `Restore refused (schema_mismatch:migration_data): migration ${receipt.migration} changed data after this archive was made, so its rows would skip that change. Restore an archive made after it.`
112
- : receipt.occupied ? occupiedRefusal(input,receipt.reason,receipt.occupied)
112
+ : receipt.occupied ? occupiedRefusal(input,receipt.reason)
113
113
  : `The portability module refused or failed the archive operation (${receipt.reason ?? 'incomplete'}${receipt.native ? `: ${receipt.native.class}${receipt.native.code && receipt.native.code !== receipt.reason ? `, code ${receipt.native.code}` : ''}` : ''}).${receipt.native && receipt.exitCode === 1 ? ' Run the same command again; it starts over.' : ''}`, receipt.exitCode ?? 1);
114
114
  delete receipt.ok;
115
115
  return receipt;
116
116
  }
117
117
 
118
- function occupiedRefusal(input,reason,occupied) {
119
- return `Restore refused (${reason}): ${reason === 'bucket_not_empty' ? `storage bucket ${occupied} in this installation already holds files` : `table ${occupied} in this installation already holds rows its migrations did not insert`}, and a restore only goes into an empty installation. To replace this installation's data with the archive, keep a copy with rer export --output exports/before-restore.rer, then run rer reset --yes and rer import --input ${relative(input.root, input.path)} --yes again.`;
118
+ function occupiedRefusal(input,reason) {
119
+ return `Restore refused (${reason}): this installation already contains ${reason === 'bucket_not_empty' ? 'files' : 'people or data'}. Import restores into an empty installation. Use a fresh installation, or to replace this installation's data, keep a copy with rer export --output exports/before-restore.rer, then run rer reset --yes and rer import --input ${relative(input.root, input.path)} --yes again.`;
120
120
  }
package/cli/transfers.mjs CHANGED
@@ -45,10 +45,10 @@ export async function transfer(project, options, signal, custody) {
45
45
  const operation = direction === 'import' && typeof api.managedDataImport === 'function' && await isManagedDataZip(path) ? api.managedDataImport : api[direction];
46
46
  const result=await operation.call(api, { root: project.root, target, path, journal, origin: options.origin, sessionFile, signal, platform:options.platform, legacyRecovery, acknowledgeUnverifiedSchemaObjects:options.acknowledgeUnverifiedSchemaObjects, ...custody });
47
47
  // The archive's size, for the line a finished export ends with.
48
- if(direction==='export')return {...result,target,...(target==='remote'&&options.origin?{origin:new URL(options.origin).origin}:{}),output:result.output??relative(project.root,path),bytes:(await stat(path)).size};
48
+ if(direction==='export')return {...result,target,...(target==='remote'&&options.origin?{origin:new URL(options.origin).origin}:{}),output:result.output??relative(project.root,path),bytes:(await stat(path)).size,captureLog:relative(project.root,custody.store.logPath)};
49
49
  if(direction==='import' && target==='local' && (await localDependencyLinks(project.root)).some(link=>link.needs_relink)) {
50
50
  custody.store.report('Imported provider links need fresh approval. Run rer setup with RER_LINK_TOKEN_FILE to re-link this installation.');
51
51
  return {...result,needsRelink:true,nextCommand:'rer setup'};
52
52
  }
53
- return result;
53
+ return direction === 'import' ? { ...result, captureLog: relative(project.root, custody.store.logPath), nextCommand: 'rer setup' } : result;
54
54
  }
@@ -1,5 +1,43 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.113
4
+
5
+ ### Recovery output and archive restore
6
+
7
+ - Installation restore refusals explain that the destination already contains people, data or files, without exposing internal table or bucket names. Restore still requires an empty installation: use a fresh installation, or keep a backup before the explicit reset and restore commands printed in the refusal.
8
+ - Successful local restore reports the archive, table/row counts, file counts when available, safety changes and the setup/dev next step. Wrangler SQL results stay in the redacted capture log; failed queries keep their diagnostics. Setup keeps Vite source-import advisories and suppression instructions in that log while retaining unrelated warnings and errors.
9
+ - Local installation export keeps seed-owned worker success JSON in the redacted capture log and prints a readable archive receipt, its log path and a directly runnable `rer import --input FILE --yes` command for an empty installation. Paths needing shell quoting are quoted. The full structured receipt remains available with `--json`. Archive format is unchanged; this does not repair seed-owned restore validators.
10
+
11
+ ### Deploy plans and first-run startup
12
+
13
+ - `rer deploy --dry-run` prints the Worker, declared product resources, required token permissions, settings/secret counts and declared migration counts. Pending migrations remain unknown offline; the full structured plan stays in the redacted capture log and `--json`. Dry-run recovery retains `--dry-run`; real-deploy recovery retains its existing command. Ordinary seed deploy-policy failures now name `Checking deploy policy` and stop before provider contact; missing-input refusals retain exit 3. Setup token-permission coverage follows the seed's resource declaration, including R2 and Queues.
14
+ - Managed development targets that use the listener handshake without an explicit timeout now get the shared target's first-run readiness window and explain dependency optimization while waiting. Readiness still awaits the real application listener and health check.
15
+
16
+ ### Erasure archive preflight
17
+
18
+ - Shared portability import creation refuses an already-stale erasure archive before schema inventory and durable restore staging. The early epoch check is read-only and the final erasure fence remains in place. The reference emitted-Worker person-erasure journey advances more export parts per call without relaxing its assertions or timeout.
19
+
20
+ Seeds receive these CLI and shared-module changes only after adopting this rer through their pinned package or refreshed source. No seed adoption, deployed behavior or production result is established here. The actual diff adds no migrations; previously released export allocation/ETA and duplicate mail-key wording fixes are not new in 0.2.113.
21
+
22
+ ## 0.2.112
23
+
24
+ ### Downloaded tools and export progress
25
+
26
+ - `rer run --script FILE [ARGS...]` runs a downloaded JavaScript file with the Node running rer, including the installer's private Node, outside a project checkout and without `node` or pnpm on PATH. It preserves the working folder, arguments and exit status; `--cwd DIR` before `--script` selects the folder. Package scripts (`rer run NAME`) continue to use the checkout's pinned runtime. The installer and local instructions show this door; it becomes available when the installed rer is upgraded.
27
+ - Local installation export labels allocated disk space separately from archive size and leaves building time indeterminate until the total work is known. It no longer forecasts archive size or building time from unused database pages and temporary state; known-total writing and staging phases retain their progress estimates. CLI progress only; the archive format is unchanged.
28
+
29
+ ### Setup, import and export migration output
30
+
31
+ - `wrangler d1 migrations apply` run through rer's command runner, including a seed's setup, import or export adapter, shows `Applying migrations N/M` every ten migrations, warnings and errors, and one `Applied N migrations. Full output: <log>` summary. Repeated tables and boilerplate stay in the full log. A failed migration names itself and keeps wrangler's error and log path; an error without a failed row is associated with the first listed migration that did not finish. Shared local import and export now show this progress instead of silencing the whole apply.
32
+ - A finished `rer setup` adds a result line before `RER_SETUP_READY`: the number of migrations applied (or that the database is already up to date), owner setup and the full-output log path. Seeds get these command-runner and setup changes after adopting this rer through their pinned CLI.
33
+
34
+ ### Optional seed deploy policy
35
+
36
+ - Application `rer deploy` awaits optional `commandAdapter.deployPolicy({ root, options, environment, env, bindings, declaration, declarationPath })` once after basic CLI-option and declaration checks, before downstream deploy validation, builds, custom deploy hooks or owner-account provider contact, including secret-only updates and receipt recovery. `env` carries effective proposed local inputs; `bindings` overlays declaration vars with nonblank secrets mapped from their declared environment names, so an ambient binding-name value cannot override an explicit mapping. These are proposed inputs, not hosted secret readback.
37
+ - The hook is local validation: inputs are read-only, its return value is ignored, and it must make no provider calls, builds, settings writes or secret output. A seed can reject applicable operations with `missing(message)` from the same rer copy/package (exit 3, `missing_input`); `refuse(message)` retains exit 4. Seeds without the hook keep their existing deployment checks. This releases CLI support only: each seed must adopt the CLI and implement its own policy, including normalization of its provider choices and aliases. No seed-specific mail policy is inferred, and this release establishes no installed mail-OFF or deployed behavior.
38
+
39
+ Code and documentation only: the actual diff adds no migration. Nothing here establishes seed adoption or changes a deployed seed; each seed must adopt and deploy its own changes.
40
+
3
41
  ## 0.2.111
4
42
 
5
43
  ### `rer size`: statement size and growth with data
package/global/README.md CHANGED
@@ -5,7 +5,7 @@ Allow roughly 500 MB–1 GB of downloads and 1–3 GB of disk space for a first
5
5
  <!-- END COLD RUN BUDGET -->
6
6
 
7
7
  `rer` is the Run Edit Run command. Install it once, then run `rer <verb>` in any
8
- Run Edit Run checkout: every verb runs that checkout's own pinned copy, so a
8
+ Run Edit Run checkout: project verbs run that checkout's own pinned copy, so a
9
9
  checkout always gets the behaviour it was built and tested with.
10
10
 
11
11
  For source authors, `rer adopt-edition` adds a recipe and lock to existing tracked
@@ -47,7 +47,20 @@ changing PATH: a child installer cannot change its parent shell’s PATH, and ba
47
47
  `~/.local/bin`, its closing lines give one required step: the
48
48
  `export PATH="$HOME/.local/bin:$PATH"` line to run now and add to your shell
49
49
  startup file, or `rer cli path` (by its absolute launcher) for other shells.
50
- The same start also fits on one line:
50
+ To run a downloaded JavaScript tool, open its folder in the terminal and use
51
+ `"$HOME/.local/bin/rer" run --script ./tool.mjs` followed by its arguments.
52
+ For example, from Downloads the Oncall PagerDuty exporter runs with:
53
+
54
+ ```sh
55
+ "$HOME/.local/bin/rer" run --script ./oncall-export.mjs pagerduty
56
+ ```
57
+
58
+ `--script` uses the Node running `rer`, including the installer's private Node;
59
+ it needs no checkout, pnpm or separate Node installation. The file path is
60
+ relative to the current folder, or to `--cwd DIR` when supplied before
61
+ `--script`. Remaining arguments go directly to the file. A package script
62
+ (`rer run NAME`) continues to use the checkout's pinned Node and pnpm.
63
+ The app start also fits on one line:
51
64
 
52
65
  ```sh
53
66
  curl -fsSL https://runeditrun.com/install.sh | sh -s -- dev just-every/run-inkwell
@@ -44,7 +44,7 @@ async function writeLauncher(paths) {
44
44
  const shellQuote = value => "'" + value.replaceAll("'", "'\"'\"'") + "'";
45
45
  async function closing(paths) {
46
46
  const notices = await pathAdvice(paths, process.env, { includeShellStep: false });
47
- return (notices ? notices + '\n' : '') + (process.env.RER_INSTALL_NO_NEXT ? '' : `Next, start an app: ${shellQuote(paths.launcher)} dev <owner>/<repo>\n`);
47
+ return (notices ? notices + '\n' : '') + (process.env.RER_INSTALL_NO_NEXT ? '' : `Run a downloaded JavaScript tool with the installed runtime: ${shellQuote(paths.launcher)} run --script ./tool.mjs [ARGS...]\nNext, start an app: ${shellQuote(paths.launcher)} dev <owner>/<repo>\n`);
48
48
  }
49
49
 
50
50
  export async function install({ quiet = false } = {}) {
package/global/main.mjs CHANGED
@@ -28,6 +28,9 @@ else its vendored scripts/rer.mjs.
28
28
  rer run SCRIPT [ARGS]
29
29
  Run a package.json script with the pnpm and Node the checkout pins (rer keeps
30
30
  them off PATH): where a project's docs say pnpm run X, run rer run X.
31
+ rer run --script FILE [ARGS]
32
+ Run a downloaded JavaScript file with rer's Node, including its private runtime.
33
+ Works outside a checkout; FILE is relative to here (or --cwd DIR).
31
34
  rer list [DIR] The checkouts in DIR (default: here), newest first, with whether rer dev can
32
35
  launch them, whether they are set up, and their running URL. --json for data.
33
36
  rer business ... Set up your business once and share its name, logo and brand colour
package/global/run.mjs CHANGED
@@ -6,14 +6,18 @@
6
6
  import { spawn } from 'node:child_process';
7
7
  import { readFile } from 'node:fs/promises';
8
8
  import { constants } from 'node:os';
9
- import { delimiter, dirname, join } from 'node:path';
9
+ import { delimiter, dirname, join, resolve } from 'node:path';
10
10
  import { locate } from './checkout.mjs';
11
11
  import { shared } from '../cli/shared.mjs';
12
12
 
13
13
  export const runUsage = `Usage: rer run [--cwd DIR] [SCRIPT [ARGS...]]
14
+ rer run [--cwd DIR] --script FILE [ARGS...]
14
15
  Runs a package.json script of this checkout as pnpm run SCRIPT ARGS would, with the
15
16
  pnpm and Node the checkout pins (rer keeps them off PATH). Without SCRIPT it lists
16
17
  the scripts. Where a project's docs say pnpm run X -- ARGS, run rer run X -- ARGS.
18
+ With --script, runs a JavaScript file with the Node running rer, including the
19
+ installer's private runtime. No checkout or package manager is needed. FILE is
20
+ relative to the current folder (or --cwd DIR); remaining arguments go to the file.
17
21
  `;
18
22
 
19
23
  // The checkout's pinned Node, when it differs from this one (RER_NODE_AUTO=0 keeps this one).
@@ -38,6 +42,11 @@ export async function runScript(args) {
38
42
  if (!cwd?.trim() || cwd.startsWith('-')) { process.stderr.write(`A folder is required for --cwd.\n${runUsage}`); return 2; }
39
43
  args = args.slice(2);
40
44
  }
45
+ if (args[0] === '--script') {
46
+ const file = args[1];
47
+ if (!file?.trim() || file.startsWith('-')) { process.stderr.write(`A file is required for --script.\n${runUsage}`); return 2; }
48
+ return runChild(process.execPath, [resolve(cwd ?? '.', file), ...args.slice(2)], cwd ?? process.cwd());
49
+ }
41
50
  const target = locate(cwd ? ['run', '--cwd', cwd] : ['run']);
42
51
  if (!target.root || !['first-party', 'independent'].includes(target.profile)) {
43
52
  process.stderr.write(`rer run runs inside a checkout: a folder with OPERATIONS.json at or above this one, or --cwd DIR.\n`);
@@ -62,7 +71,11 @@ export async function runScript(args) {
62
71
  }
63
72
  const { toolCommand } = await shared('tool-command.mjs');
64
73
  const [program, parameters] = toolCommand('pnpm', ['run', '--silent', ...args], process.env);
65
- const child = spawn(program, parameters, { cwd: target.root, env: process.env, stdio: 'inherit' });
74
+ return runChild(program, parameters, target.root);
75
+ }
76
+
77
+ async function runChild(program, parameters, cwd) {
78
+ const child = spawn(program, parameters, { cwd, env: process.env, stdio: 'inherit' });
66
79
  const forward = new Map(['SIGINT', 'SIGTERM', 'SIGHUP'].map(signal => [signal, () => child.kill(signal)]));
67
80
  for (const [signal, handler] of forward) process.on(signal, handler);
68
81
  try {
package/install.sh CHANGED
@@ -178,6 +178,9 @@ NODE
178
178
  if [ -n "$path_step" ]; then RER_INSTALLER_PATH_STEP=1; export RER_INSTALLER_PATH_STEP; fi
179
179
  status=0
180
180
  "$HOME/.local/bin/rer" "$@" || status=$?
181
+ if [ "$1" != business ]; then
182
+ printf 'Run a downloaded JavaScript tool with the installed runtime: "%s/.local/bin/rer" run --script ./tool.mjs [ARGS...]\n' "$HOME"
183
+ fi
181
184
  if [ -n "$path_step" ]; then
182
185
  printf '\nRequired next step: %s/.local/bin is not on your PATH, so a bare `rer` in a new terminal says "rer: command not found". Run this in the terminal you will use, and add the same line to your shell startup file (~/.zshrc for zsh, ~/.bashrc for bash):\n export PATH="$HOME/.local/bin:$PATH"\nOther shells, such as fish: run %s/.local/bin/rer cli path to see the line for yours. Until then, start rer with %s/.local/bin/rer. This installer changes no shell file.\n' "$HOME" "$HOME" "$HOME"
183
186
  fi
@@ -11,7 +11,7 @@ import { platformTable, restorableManifest } from './bookkeeping.mjs';
11
11
  import { withoutAbsentExcludedObjects } from './snapshot-objects.mjs';
12
12
  import { canonicalJson, unbase64 } from './hash.mjs';
13
13
  import { checkManifest, checkPart, ContentVerifier, ArchiveVerifier } from './format.mjs';
14
- import { fence, mergeJournal, tombstone } from './journal.mjs';
14
+ import { checkEpoch, fence, mergeJournal, tombstone } from './journal.mjs';
15
15
  import { writeObject } from './payloads.mjs';
16
16
  import { createCopy,sidecar,readCopy,restoreCopy } from './copies.mjs';
17
17
  import { excludedDependentGuards, migrationSeeded, seededCondition } from './restore-safety.mjs';
@@ -26,6 +26,9 @@ import { rebuildDerivedStatements } from './derived.mjs';
26
26
  export async function createImport(context,manifest,actor='direct',legacyRecovery,ledgers,acknowledgeUnverifiedSchemaObjects=false,id=crypto.randomUUID()) {
27
27
  const {db,config,buckets}=context;await checkManifest(manifest);checkArchivedLedgers(manifest,ledgers);
28
28
  insist(manifest.product===config.product,'wrong_product');
29
+ // An already-stale backup cannot become restorable. Refuse before schema
30
+ // inventory, staging copies and part uploads; fence checks again at finalize.
31
+ await checkEpoch(db,manifest);
29
32
  // Explicit schema upgrades can reconcile rows, but cannot attest an interrupted deployment.
30
33
  await appliedMigrations(db);
31
34
  const original=manifest;manifest=await restorableManifest(original,{canonical:true});
@@ -21,10 +21,13 @@ export async function invalidateTransfersStatements(db) {
21
21
  export async function journal(db,source) {
22
22
  return (await all(db,'SELECT tombstone FROM rer_portability_journal WHERE source=? ORDER BY tombstone',source)).map(x=>x.tombstone);
23
23
  }
24
- export async function fence(db,manifest,copies,later) {
24
+ export async function checkEpoch(db,manifest) {
25
25
  const recorded=await statement(db,'SELECT epoch FROM rer_portability_epochs WHERE source=?',manifest.sourceIdentity).first();
26
- const s=await state(db);
27
- insist(manifest.epoch>=Math.max(recorded?.epoch??0,s.source_identity===manifest.sourceIdentity?s.epoch:0),'erasure_epoch');
26
+ const s=await statement(db,'SELECT source_identity,epoch FROM rer_portability_state WHERE id=1').first();
27
+ insist(manifest.epoch>=Math.max(recorded?.epoch??0,s?.source_identity===manifest.sourceIdentity?s.epoch:0),'erasure_epoch');
28
+ }
29
+ export async function fence(db,manifest,copies,later) {
30
+ await checkEpoch(db,manifest);
28
31
  if(later) insist(later.sourceIdentity===manifest.sourceIdentity && Number.isSafeInteger(later.epoch) && later.epoch>=manifest.epoch && Array.isArray(later.journal),'later_journal');
29
32
  const hashes=new Set([...manifest.journal,...await journal(db,manifest.sourceIdentity),...(later?.journal??[])]);
30
33
  insist([...hashes].every(x=>/^[a-f0-9]{64}$/.test(x)),'invalid_journal');
@@ -1,10 +1,11 @@
1
1
  import { skippedTablesLine } from './bookkeeping.mjs';
2
2
  // Human progress for a long export or import. The caller sends events; this turns
3
3
  // them into at most one line every few seconds, with an estimate of the time left
4
- // once a phase has two samples. The first and last line of every phase always show.
5
- // Rates are bytes per second measured on a 1.2 GB local install on a loaded machine
6
- // (export 1725 s, import 2234 s); a quiet machine is faster.
7
- const RATES = { export: 700_000, import: 550_000 };
4
+ // once a phase has two samples and a known total. The first and last line of every
5
+ // phase always show. Local disk allocation includes free pages and transient state;
6
+ // it cannot predict archive bytes or building time.
7
+ // Import rate measured on a 1.2 GB archive on a loaded machine (2234 s).
8
+ const IMPORT_RATE = 550_000;
8
9
  const UNITS = ['B', 'KB', 'MB', 'GB', 'TB'];
9
10
  export function formatBytes(bytes) {
10
11
  let value = bytes, unit = 0;
@@ -18,16 +19,15 @@ export function formatDuration(seconds) {
18
19
  }
19
20
  const left = seconds => `, ${formatDuration(seconds)} left`;
20
21
  export function transferProgress(report, { interval = 3000, now = () => performance.now() } = {}) {
21
- let phase, first, printed = -Infinity, expected;
22
+ let phase, first, printed = -Infinity;
22
23
  const line = event => {
23
- const bytes = event.bytes === undefined ? '' : ` (${formatBytes(event.bytes)}${event.phase === 'building' && expected ? ` of about ${formatBytes(expected)}` : ''})`;
24
+ const bytes = event.bytes === undefined ? '' : ` (${formatBytes(event.bytes)})`;
24
25
  const parts = event.total === undefined ? `${event.parts} part${event.parts === 1 ? '' : 's'} so far` : `${event.parts} of ${event.total} parts`;
25
26
  // Seconds left, from the rate since the phase's first sample.
26
27
  const eta = () => {
27
28
  const seconds = (now() - first.time) / 1000;
28
29
  if (event === first.event || seconds <= 0 || event.parts === event.total) return '';
29
30
  if (event.total !== undefined && event.parts > first.event.parts) return left((event.total - event.parts) * seconds / (event.parts - first.event.parts));
30
- if (event.phase === 'building' && expected && event.bytes > first.event.bytes && event.bytes < expected) return left((expected - event.bytes) * seconds / (event.bytes - first.event.bytes));
31
31
  return '';
32
32
  };
33
33
  switch (event.phase) {
@@ -42,9 +42,11 @@ export function transferProgress(report, { interval = 3000, now = () => performa
42
42
  if(event.phase==='schema-unverified') { report('Schema unverified: '+JSON.stringify(event.receipt)); return; }
43
43
  if (event.phase === 'skipped') { report(skippedTablesLine(event.tables)); return; }
44
44
  if (event.phase === 'start') {
45
- const noun = event.direction === 'export' ? `Exporting about ${formatBytes(event.bytes)} of local data` : `Restoring a ${formatBytes(event.bytes)} archive`;
46
- if (event.direction === 'export') expected = event.bytes;
47
- report(`${noun}. ${event.bytes / RATES[event.direction] < 45 ? 'This takes under a minute.' : `An archive this size usually takes ${formatDuration(event.bytes / RATES[event.direction])}; a busy machine takes longer. Progress follows every few seconds.`}`);
45
+ if (event.direction === 'export') {
46
+ report(`Exporting local data (${formatBytes(event.bytes)} on disk). Archive size and time remaining are not known yet. Progress follows every few seconds.`);
47
+ } else {
48
+ report(`Restoring a ${formatBytes(event.bytes)} archive. ${event.bytes / IMPORT_RATE < 45 ? 'This takes under a minute.' : `An archive this size usually takes ${formatDuration(event.bytes / IMPORT_RATE)}; a busy machine takes longer. Progress follows every few seconds.`}`);
49
+ }
48
50
  printed = now();
49
51
  return;
50
52
  }
@@ -233,7 +233,11 @@ async function start(context, hooks) {
233
233
  try{return await listenerPorts(child.pid);}
234
234
  catch(error){throw installationFailure('command_failed',{step:'start',diagnostic:error});}
235
235
  };
236
- const readinessTimeoutMs=timeoutMs??60000,readinessStarted=performance.now();
236
+ // A seed can use the managed IPC handshake without developmentTarget's
237
+ // options (Uptime does). Give that real listener/health journey the same
238
+ // first-run budget, including Vite dependency optimization.
239
+ const readinessTimeoutMs=timeoutMs??(runtimePortHandshake?900000:60000),readinessStarted=performance.now();
240
+ if(runtimePortHandshake)store.report('Waiting for the application server to finish starting; first launch may optimize dependencies.');
237
241
  try {
238
242
  await store.waitForReady(readinessLabel, child, async probeSignal => {
239
243
  if(runtimePortHandshake){
@@ -0,0 +1,76 @@
1
+ // Views run after redaction. The command store still writes every original
2
+ // redacted byte to install.log; only the person's progress is shortened here.
3
+ export function isWranglerQuery(command, args = []) {
4
+ const words = [command, ...args].map(String);
5
+ const tool = words.findIndex(word => /(^|[\\/])wrangler(\.js)?$/.test(word));
6
+ return tool >= 0 && words.slice(tool + 1).some((word, index, rest) => word === 'd1' && rest[index + 1] === 'execute');
7
+ }
8
+
9
+ export function wranglerQueryView({ log }) {
10
+ let tail = '';
11
+ return {
12
+ write(text) { tail = (tail + text).slice(-32768); return ''; },
13
+ end({ code, signal, error } = {}) {
14
+ // A failed SQL command must keep its actual diagnostic, including its exit
15
+ // status in the command store. Successful query JSON is never user output.
16
+ return code !== 0 || signal || error ? tail : `Database update complete. Full output: ${log}\n`;
17
+ },
18
+ };
19
+ }
20
+
21
+ // Vite emits multiline source-import advisories during setup. Keep both their
22
+ // source frames and suppression instructions in the capture, without hiding
23
+ // unrelated warnings or errors. A partial/unrecognized block stays visible.
24
+ export function viteDiagnosticsView(inner) {
25
+ let pending = '', block = '', kind;
26
+ const emit = text => inner ? inner.write(text) : text;
27
+ const line = text => {
28
+ if (!kind && /\[vite\].*warning:/.test(text)) kind = 'import';
29
+ if (!kind && /Your Vite config uses features that are unsupported by/.test(text)) kind = 'config';
30
+ if (!kind) return emit(text);
31
+ block += text;
32
+ const complete = kind === 'import' ? /^\s*File:/.test(text) : /VITE_CONFIG_NATIVE_IGNORE_WARNING.*suppress this warning/.test(text);
33
+ if (!complete && block.length < 32768) return '';
34
+ const advisory = kind === 'config' || /The above dynamic import cannot be analyzed by Vite/.test(block);
35
+ const result = advisory && complete ? '' : emit(block);
36
+ block = ''; kind = undefined;
37
+ return result;
38
+ };
39
+ return {
40
+ write(text) {
41
+ const lines = (pending + text).split('\n'); pending = lines.pop();
42
+ return lines.map(item => line(item + '\n')).join('');
43
+ },
44
+ end(result) {
45
+ const rest = (pending ? line(pending) : '') + (block ? emit(block) : '');
46
+ pending = ''; block = ''; kind = undefined;
47
+ return rest + (inner?.end(result) ?? '');
48
+ },
49
+ facts: () => inner?.facts?.() ?? {},
50
+ };
51
+ }
52
+
53
+ // Seed-owned archive workers may send their success receipt on stdout. It is
54
+ // protocol data, retained by the command store's redacted log; progress and
55
+ // failed receipts still belong in the terminal.
56
+ export function archiveReceiptView(inner) {
57
+ let pending = '';
58
+ const emit = text => inner ? inner.write(text) : text;
59
+ const line = text => {
60
+ let receipt;
61
+ try { receipt = JSON.parse(text); } catch { return emit(text); }
62
+ return receipt?.ok === true && typeof receipt.contentHash === 'string' && Array.isArray(receipt.tables)
63
+ ? '' : emit(text);
64
+ };
65
+ return {
66
+ write(text) {
67
+ const lines = (pending + text).split('\n'); pending = lines.pop();
68
+ return lines.map(item => line(item + '\n')).join('');
69
+ },
70
+ end(result) {
71
+ const rest = pending ? line(pending) : ''; pending = '';
72
+ return rest + (inner?.end(result) ?? '');
73
+ },
74
+ facts: () => inner?.facts?.() ?? {},
75
+ };
76
+ }
@@ -11,8 +11,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
13
  import { toolCommand } from './tool-command.mjs';
14
+ import { isWranglerMigrationApply, wranglerMigrationView } from './migration-progress.mjs';
15
+ import { isWranglerQuery, wranglerQueryView, viteDiagnosticsView, archiveReceiptView } from './command-diagnostics-view.mjs';
14
16
 
15
- export async function createCommands(directory,state,{terminal=text=>writeSync(1,text),spawn=spawnChild,queue:queuePolicy,custodyToken,onWaiting}={}) {
17
+ export async function createCommands(directory,state,{terminal=text=>writeSync(1,text),spawn=spawnChild,queue:queuePolicy,custodyToken,onWaiting,filterViteWarnings=false,filterArchiveReceipts=false}={}) {
16
18
  let policy=queuePolicy?await commandPolicy():{environment:{},close:async()=>{}};
17
19
  const custodyBaseline=['darwin','linux'].includes(process.platform)?await createProcessBaseline():undefined;
18
20
  const logPath=join(directory,'install.log'), log=await openPrivateLog(logPath);
@@ -38,12 +40,13 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
38
40
  else if(error.code!=='EAGAIN'&&error.code!=='EWOULDBLOCK')throw error;
39
41
  }
40
42
  };
41
- const emit=text=>{
43
+ // `logText` is what the setup log keeps when a command's view shows less than it printed.
44
+ const emit=(text,logText=text)=>{
45
+ if(logText&&!closed)log.write(logText);
42
46
  if(!text)return;
43
47
  // Store a bounded text tail as lines; fragment writes do not multiply entries.
44
48
  const textTail=((state.logs||[]).join('\n')+text).slice(-65536);
45
49
  state.logs=textTail.split('\n').slice(-400);
46
- if(!closed)log.write(text);
47
50
  writeTerminal(text);
48
51
  };
49
52
  // A line that lists secret NAMES keeps each name whole: a name is not a secret, even when a value
@@ -56,7 +59,10 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
56
59
  for(const match of text.matchAll(pattern)){result+=redaction.redact(text.slice(from,match.index))+match[0];from=match.index+match[0].length;}
57
60
  return result+redaction.redact(text.slice(from));
58
61
  };
59
- const report=(text,{names}={})=>emit(redactBesideNames(String(text),names)+'\n');
62
+ const report=(text,{names,logOnly=false}={})=>{
63
+ const line=redactBesideNames(String(text),names)+'\n';
64
+ emit(logOnly?'':line,line);
65
+ };
60
66
  const failure=(label,detail={},capture)=>{
61
67
  const outcome=`exit ${detail.code??'none'}, signal ${detail.signal??'none'}`;
62
68
  const status=detail.reason==='cancel'?`cancelled (${outcome})`:detail.reason==='deadline'?`readiness deadline exceeded (${outcome})`:detail.error?`could not start${detail.errorCode?` (${detail.errorCode})`:''} (${outcome})`:outcome;
@@ -65,14 +71,18 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
65
71
  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))});
66
72
  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});
67
73
  };
68
- const track=(label,child,ownershipScope)=>{
74
+ const track=(label,child,ownershipScope,view)=>{
69
75
  if(captures.has(child))return child;
76
+ if(filterViteWarnings)view=viteDiagnosticsView(view);
77
+ if(filterArchiveReceipts)view=archiveReceiptView(view);
70
78
  let resolveClose,resolveError,resolveExit;
71
79
  const capture={tail:'',scope:signal,closed:new Promise(resolve=>{resolveClose=resolve;}),failed:new Promise(resolve=>{resolveError=resolve;}),exited:new Promise(resolve=>{resolveExit=resolve;})};
72
80
  capture.custody=commandCustody(child,ownershipScope);
73
81
  // Redact in arrival order across both descriptors: their concatenation is what
74
82
  // reaches the shared page, disk and terminal sinks.
75
- const filter=redaction.stream(text=>{capture.tail=(capture.tail+text).slice(-32768);emit(text);});
83
+ // A command's view (see migration-progress.mjs) shortens what the terminal, page and
84
+ // failure tail show; the log keeps every byte.
85
+ const filter=redaction.stream(text=>{const shown=view?view.write(text):text;capture.tail=(capture.tail+shown).slice(-32768);emit(shown,text);});
76
86
  capture.snapshot=()=> (capture.tail+filter.snapshot()).slice(-32768);
77
87
  const sources=[child.stdout,child.stderr].filter(Boolean),data=chunk=>filter.write(chunk);
78
88
  for(const source of sources)source.on('data',data);
@@ -85,7 +95,9 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
85
95
  clearTimeout(capture.stopTimer);
86
96
  child.removeListener('exit',exited);if(!capture.exitResult)exited(code,terminationSignal);
87
97
  for(const source of sources)source.removeListener('data',data);
88
- filter.end();active.delete(child);if(!capture.custody)managed.delete(child);resolveClose({code,signal:terminationSignal,error,errorCode:capture.errorCode});
98
+ filter.end();
99
+ if(view){const rest=view.end({code,signal:terminationSignal,error});capture.tail=(capture.tail+rest).slice(-32768);emit(rest,'');Object.assign(state,view.facts?.());}
100
+ active.delete(child);if(!capture.custody)managed.delete(child);resolveClose({code,signal:terminationSignal,error,errorCode:capture.errorCode});
89
101
  };
90
102
  child.once('close',finish);
91
103
  captures.set(child,capture);
@@ -133,7 +145,7 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
133
145
  state.step=announced;if(!repeated)report(label);
134
146
  // Name the executable by default; only a caller's explicit safe display may
135
147
  // include arguments. Raw argv can contain private positional values.
136
- const {signal:providedSignal,afterCommand,onChild,heavy,phase,display,...native}=options;
148
+ const {signal:providedSignal,afterCommand,onChild,heavy,phase,display,view,...native}=options;
137
149
  const commandSignal=signal&&providedSignal?AbortSignal.any([signal,providedSignal]):providedSignal||signal;
138
150
  if(commandSignal?.aborted)throw failure(label,{reason:'cancel'});
139
151
  const ownershipScope=createProcessScope(custodyBaseline);redaction.addSecrets([ownershipScope.token,...inheritedScopeTokens(process.env),...inheritedScopeTokens(native.env)]);
@@ -141,7 +153,7 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
141
153
  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']:[])]});
142
154
  onChild?.(child);
143
155
  ownershipRecords.set(child,{pid:child.pid,token:ownershipScope.token});
144
- track(label,child,ownershipScope);
156
+ track(label,child,ownershipScope,view?.());
145
157
  Object.assign(captures.get(child),{cwd:native.cwd??process.cwd(),display:redaction.redact(String(display??command))});
146
158
  const cancel=()=>{void stopCommand(child);};
147
159
  commandSignal?.addEventListener('abort',cancel,{once:true});if(commandSignal?.aborted)cancel();
@@ -158,12 +170,16 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
158
170
  spawn:spawnCommand,
159
171
  async stop(child){await stopCommand(child);await captures.get(child)?.closed;const scope=captures.get(child)?.scope;if(![...managed].some(other=>captures.get(other).scope===scope)){const actions=cleanups.get(scope)??[];cleanups.delete(scope);for(const action of actions)await action();}},
160
172
  async run(label,command,args=[],options={}) {
173
+ // Any caller's `wrangler d1 migrations apply` (the setup hooks, a seed's own export and import) shows
174
+ // a count instead of wrangler's table redrawn per migration; the log keeps every byte and is named in the summary.
175
+ if(!options.view&&isWranglerMigrationApply(command,args))options={...options,view:()=>wranglerMigrationView({log:redaction.redact(checkoutPath(options.cwd??process.cwd(),logPath))})};
176
+ if(!options.view&&isWranglerQuery(command,args))options={...options,view:()=>wranglerQueryView({log:redaction.redact(checkoutPath(options.cwd??process.cwd(),logPath))})};
161
177
  if(queuePolicy && options.heavy !== false) {
162
178
  let queuedChild;
163
179
  const commandSignal=signal&&options.signal?AbortSignal.any([signal,options.signal]):options.signal||signal;
164
180
  const result = await queuedCommand(command,args,{...options,verb:queuePolicy.verb,signal:commandSignal,originalCI:policy.ci,
165
181
  label:await queueLabel(options.cwd??process.cwd(),queuePolicy.verb,options.phase??'command'),report,onWaiting,maxWait:queuePolicy.maxWait,queueOptions:queuePolicy.sampler?{sampler:queuePolicy.sampler}:undefined,
166
- 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);}});
182
+ spawn:(program,argv,native)=>(queuedChild=spawnCommand(label,program,argv,{...native,onChild:options.onChild,display:options.display,view:options.view})),cleanup:async(child,result)=>{await stopCommand(child);await options.afterCommand?.(result);}});
167
183
  if(result?.timedOut)throw busyRefusal({...result,reason:redaction.redact(String(result.reason))},{verb:queuePolicy.verb,maxWait:queuePolicy.maxWait??maxWaitSeconds});
168
184
  if(result){if(result.code!==0)throw failure(label,result,captures.get(queuedChild));return result;}
169
185
  }
@@ -0,0 +1,69 @@
1
+ // What a person sees while `wrangler d1 migrations apply` runs. Wrangler redraws
2
+ // its whole migration table after every migration it applies, so 75 migrations
3
+ // print the first one's name 76 times and about 1.2 MB in all. The command's
4
+ // full output stays in the setup log and in failure diagnostics' source; the
5
+ // terminal and shared page get a count every ten migrations, anything that is
6
+ // not a table row, wrangler's own boilerplate or an earlier-seen line (warnings,
7
+ // errors), and one summary. Wrangler names the migration that failed only for
8
+ // some errors (a SQL syntax error is just its message), so the view names the
9
+ // first migration of the list that never showed a check mark when an error came.
10
+
11
+ const TABLE_LINE = /^[┌├└│─]/;
12
+ const STEP = 10;
13
+ // Wrangler's per-migration "🚣 37 commands executed successfully." differs every time, so repeats are not caught.
14
+ const PER_MIGRATION = /^🚣 \d+ commands? executed successfully\.?$/;
15
+ // What wrangler says around every apply, whatever it applies: its banner, where the database is, how to reach
16
+ // a remote one, the confirmation it answers itself in CI.
17
+ const BOILERPLATE = /^(\u26C5\uFE0F?\s*wrangler\b|Resource location:|Use --remote if you want|Migrations to be applied:|\? About to apply \d+ migration|Your database may not be available|🤖 Using fallback value|🌀 (Executing on|To execute on)|✅ No migrations to apply)/u;
18
+
19
+ export function isWranglerMigrationApply(command, args = []) {
20
+ const words = [command, ...args].map(String);
21
+ const tool = words.findIndex(word => /(^|[\\/])wrangler(\.js)?$/.test(word));
22
+ if (tool < 0) return false;
23
+ const rest = words.slice(tool + 1);
24
+ return rest.some((word, index) => word === 'd1' && rest[index + 1] === 'migrations' && rest[index + 2] === 'apply');
25
+ }
26
+
27
+ // One view per command: write(text) returns the text to show, end() the rest.
28
+ // The summary names the log that keeps wrangler's full output: { log }.
29
+ export function wranglerMigrationView({ log } = {}) {
30
+ let pending = '', total = 0, announced = 0, failed = false, errored = false;
31
+ const applied = new Set(), seen = new Set(), names = [];
32
+ const shown = [];
33
+ const progress = () => `Applying migrations ${applied.size}/${Math.max(total, applied.size)}`;
34
+ const line = text => {
35
+ if (TABLE_LINE.test(text)) {
36
+ if (!text.startsWith('│')) return;
37
+ const cells = text.split('│').slice(1, -1).map(cell => cell.trim());
38
+ if (cells[0] === 'name') return;
39
+ if (cells.length === 1) { total += 1; if (!names.includes(cells[0])) names.push(cells[0]); return; }
40
+ if (cells[1].includes('❌')) { failed = true; shown.push(`Migration ${cells[0]} failed.`); return; }
41
+ if (cells[1].includes('✅') && !applied.has(cells[0])) {
42
+ applied.add(cells[0]);
43
+ if (applied.size % STEP === 0 && applied.size > announced) { announced = applied.size; shown.push(progress()); }
44
+ }
45
+ return;
46
+ }
47
+ const trimmed = text.trim();
48
+ if (/\[ERROR\]/.test(trimmed)) errored = true;
49
+ if (!trimmed || PER_MIGRATION.test(trimmed) || BOILERPLATE.test(trimmed) || seen.has(trimmed)) return;
50
+ seen.add(trimmed);
51
+ shown.push(text);
52
+ };
53
+ const drain = () => { const text = shown.length ? shown.join('\n') + '\n' : ''; shown.length = 0; return text; };
54
+ return {
55
+ write(text) {
56
+ const lines = (pending + text).split('\n');
57
+ pending = lines.pop();
58
+ for (const item of lines) line(item);
59
+ return drain();
60
+ },
61
+ end() {
62
+ if (pending) { line(pending); pending = ''; }
63
+ if (errored && !failed && names[applied.size]) shown.push(`Migration ${names[applied.size]} failed.`);
64
+ if (applied.size) shown.push(`Applied ${applied.size} migration${applied.size === 1 ? '' : 's'}.${log ? ` Full output: ${log}` : ''}`);
65
+ return drain();
66
+ },
67
+ facts: () => ({ migrationsApplied: applied.size }),
68
+ };
69
+ }
@@ -48,5 +48,6 @@ export async function migrateOperator(context, database) {
48
48
  const after = await appliedNames(state, table);
49
49
  const applied = names.filter(name => !before.has(name) && after.has(name));
50
50
  if (applied.length) store.report(`Applied local migrations: ${applied.join(', ')}`);
51
+ if (store.state) store.state.migrationsApplied = applied.length;
51
52
  } finally { await unlink(path); }
52
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runeditrun/rer",
3
- "version": "0.2.111",
3
+ "version": "0.2.113",
4
4
  "description": "The rer command: install, set up, run and launch Run Edit Run checkouts.",
5
5
  "license": "MIT",
6
6
  "type": "module",