@runeditrun/rer 0.2.112 → 0.2.114

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
@@ -727,3 +727,54 @@ runtime and type dependencies. The existing
727
727
  `@runeditrun/rer/modules/import-kit/d1` entry remains available. See the
728
728
  [adoption guide](https://github.com/runeditrun/base/blob/main/modules/import-kit/src/door/ADOPTING.md)
729
729
  for native adapters, consent, declared intake projection and reviewed apply/Undo.
730
+
731
+ ## Rehearse before signing a seed release
732
+
733
+ Run `rer rehearse --cwd /path/to/seed --ref HEAD` before announcing a release.
734
+ It exports the selected commit into a fresh repository outside the checkout,
735
+ with an empty `Initial commit` and one installation commit. The installation
736
+ projection removes publisher automation, preserves a dispatch-only managed
737
+ workflow, updates its recipe/copy metadata, adds schema-1 `rer-upstream.json`
738
+ (repository, tag/ref, exact source SHA), and regenerates changed lock identities
739
+ through Base's source-lock generator while retaining the publisher's source pins.
740
+ Uncommitted files and publisher history are absent. The source checkout is unchanged.
741
+
742
+ This installs dependencies and builds. Signers and seed lanes must use the heavy slot:
743
+
744
+ ```sh
745
+ python3 -I /path/to/.tools/heavy-slot.py --remote auto -- rer rehearse --cwd /path/to/seed --ref HEAD
746
+ ```
747
+
748
+ Use a committed clean worktree for remote routing and make the source available
749
+ on that runner. The command itself uses local Git objects and creates no remote;
750
+ only the declared operations may acquire dependencies over the network. Supply the
751
+ same Node and package-manager tools as the seed's trusted build. A fresh private
752
+ HOME/config/cache and a restricted environment keep caller provider credentials out.
753
+ The operations are trusted source code, not a sandbox for an untrusted seed.
754
+
755
+ Every declared `setup`, `build`, `verify`, `artifact` command runs in that order
756
+ from the scratch root, in its own `bash -e -o pipefail` process. Rehearsal continues
757
+ after failures, so one run reports every failing operation. A later command that
758
+ cannot start because a prior operation left a required input unavailable is
759
+ reported `NOT REACHED` with the missing-input diagnostic. Recovery prose is not
760
+ an executable operation. Shell variables and working-directory changes do not
761
+ carry between operations; filesystem changes do.
762
+
763
+ The summary prints PASS/FAIL/NOT REACHED, the first cause line and the full redacted
764
+ capture-log path. Logs survive scratch cleanup; `--keep` retains the repository and
765
+ its private HOME for diagnosis. `--operation-timeout-seconds N` defaults to 900;
766
+ `--timeout-seconds N` bounds preparation and all operations together (default 3600).
767
+ Both accept integer seconds from 1 to 86400. If no dispatch-only managed workflow
768
+ exists, provide the platform's immutable `--workflow-ref OWNER/REPO/.github/workflows/FILE.yml@SHA`.
769
+ `--repository OWNER/REPO` overrides the descriptor's source repository identity.
770
+ A branch/ref in the rehearsal upstream record identifies unreleased source; it is
771
+ not a signed stable-release record.
772
+
773
+ Exit codes: 0 all pass; 1 an operation failed or was not reached; 2 invalid flags;
774
+ 3 preparation/source/declaration failure; 124 overall timeout; 130/143 interruption.
775
+ A per-operation timeout is FAIL and exit 1. With `--json`, stdout contains one
776
+ version-1 `result` event with `ok`, `exitCode`, source/install identities, elapsed
777
+ `seconds`, `captureLog` and every operation's command, status, cause and child
778
+ exit/signal. `rer rehearse --help` lists the flags. This proves local declared
779
+ build operations under the recorded host conditions; GitHub attestation, artifact
780
+ upload and provider deployment remain separate.
@@ -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
+ }
@@ -3,8 +3,9 @@ import { invalid } from './errors.mjs';
3
3
 
4
4
  // Seed policy is separate from uploading: secret-only commands bypass the
5
5
  // deploy hook, but must not bypass a seed's applicable local input policy.
6
- export async function enforceDeployPolicy({ adapter, root, options, setupManifest, localOnlyKeys, declaration, declarationPath, settings }) {
6
+ export async function enforceDeployPolicy({ adapter, root, options, store, setupManifest, localOnlyKeys, declaration, declarationPath, settings }) {
7
7
  if (adapter.deployPolicy === undefined) return;
8
+ await store.step('Checking deploy policy');
8
9
  if (typeof adapter.deployPolicy !== 'function') throw invalid('The adapter deployPolicy must be a function.');
9
10
  const { env } = await deployEnvironment({ root, options, declaration, setupManifest, settings, localOnlyKeys });
10
11
  // Resolve declared environment aliases before policy sees Worker bindings.
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;
package/cli/main.mjs CHANGED
@@ -9,6 +9,7 @@ import { selectNodeRuntime } from './node-runtime.mjs';
9
9
  import { resolve } from 'node:path';
10
10
 
11
11
  export async function main(argv = process.argv.slice(2)) {
12
+ if (argv[0] === 'rehearse') return (await import('./rehearse.mjs')).rehearseCommand(argv.slice(1));
12
13
  if (argv[0] === 'door' && argv[1] === 'clauses') return (await import('./door-clauses.mjs')).doorClausesCommand(argv.slice(2));
13
14
  if (argv[0] === 'business') return (await import('./business/command.mjs')).businessCommand(argv.slice(1));
14
15
  if (argv[0] === 'companion') return (await import('./companion/command.mjs')).companionCommand(argv.slice(1));
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) {
package/cli/parse.mjs CHANGED
@@ -109,7 +109,7 @@ export function parse(argv, cwd = process.cwd(), { independent = false, deferTai
109
109
  }
110
110
 
111
111
  export function help(verb) {
112
- if (!verb) return `Usage: rer VERB [FLAGS]\nCommands: ${Object.keys({...verbs, ...authoringVerbs}).join(', ')}, signin, size, release, listing\nRun rer VERB --help for flags.\n${appSignInHelp}\n`;
112
+ if (!verb) return `Usage: rer VERB [FLAGS]\nCommands: ${Object.keys({...verbs, ...authoringVerbs}).join(', ')}, signin, size, release, listing, rehearse\nRun rer VERB --help for flags.\n${appSignInHelp}\n`;
113
113
  const known = verbs[verb] ?? authoringVerbs[verb] ?? (verb === 'signin' ? signinVerb : verb === 'size' ? sizeVerb : undefined);
114
114
  const door = ['export', 'import'].includes(verb) ? 'To move records, start the app and open its signed-in owner import door:\n\n rer dev\n\nOpen /app/import, then export or upload and review supported records there.\n\nTo back up or restore this installation:\n' : '';
115
115
  return `${door}Usage: rer ${verb}${verb === 'refresh-base' ? ' --ref FULL_COMMIT' : ''} [FLAGS]\nFlags: ${(known?.flags ?? commonFlags).join(', ')}\n${known?.effects ?? 'Execute the declared OPERATIONS v2 argv with explicit arguments after --.'}\n`;
@@ -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
  }
@@ -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
  }
@@ -0,0 +1,29 @@
1
+ // Mirrors platform repository-automation.ts (bbf6ca98); keep installation projection behavior aligned.
2
+ export const MANAGED_WORKFLOW = '.github/workflows/rer-managed.yml'
3
+
4
+ /** Repository automation belongs to the publisher, not to each installed app. Application runtime
5
+ * schedules (Wrangler, deployment specs and scheduled handlers) are application source and stay intact. */
6
+ export function repositoryAutomation(path ) {
7
+ return path === '.github' || path === '.github/workflows' || path.startsWith('.github/workflows/')
8
+ || /^(?:\.github\/)?(?:dependabot\.ya?ml|\.?renovate(?:rc)?(?:\.json5?)?)$/.test(path)
9
+ || /^(?:\.circleci|\.buildkite|\.teamcity|\.gitlab)(?:\/|$)/.test(path)
10
+ || /^(?:\.gitlab-ci\.ya?ml|azure-pipelines\.ya?ml|bitbucket-pipelines\.ya?ml|\.travis\.yml|\.drone\.ya?ml|\.woodpecker\.ya?ml|Jenkinsfile)$/.test(path)
11
+ }
12
+
13
+ /** A publisher's own delivery entry is kept verbatim, as installs did before automation was stripped, when GitHub
14
+ * can start it only by an explicit dispatch: its sole `on` event is workflow_dispatch. Anything else (push,
15
+ * pull_request, schedule, a flow mapping RER does not read) is replaced by RER's generated entry. */
16
+ export function dispatchOnlyWorkflow(bytes ) {
17
+ const lines = new TextDecoder().decode(bytes).split(/\r?\n/)
18
+ const top = lines.flatMap((line, index) => /^[^\s#]/.test(line) ? [{line, index}] : [])
19
+ const on = top.filter(({line}) => /^(?:on|'on'|"on")\s*:/.test(line))
20
+ if (on.length !== 1) return false
21
+ const inline = on[0].line.replace(/^[^:]+:/, '').replace(/\s#.*$/, '').trim()
22
+ if (inline) return /^(?:workflow_dispatch|\[\s*workflow_dispatch\s*\])$/.test(inline)
23
+ const end = top.find(({index}) => index > on[0].index)?.index ?? lines.length
24
+ const body = lines.slice(on[0].index + 1, end).filter(line => line.trim() && !/^\s*#/.test(line))
25
+ const depth = (line ) => line.length - line.trimStart().length
26
+ const indent = Math.min(...body.map(depth))
27
+ const events = body.filter(line => depth(line) === indent).map(line => line.trim().replace(/\s*:.*$/, ''))
28
+ return events.length === 1 && events[0] === 'workflow_dispatch'
29
+ }
@@ -0,0 +1,14 @@
1
+ import {join} from 'node:path';
2
+
3
+ // An allowlist keeps provider credentials, Git config and caller startup hooks out.
4
+ // HOME/config/cache are private and fresh; PATH supplies the caller's build tools.
5
+ export function rehearsalEnvironment(home, artifactFile) {
6
+ return {PATH: process.env.PATH ?? '', HOME: home, TMPDIR: home, TMP: home, TEMP: home,
7
+ XDG_CONFIG_HOME: join(home, 'config'), XDG_CACHE_HOME: join(home, 'cache'),
8
+ CI: 'true', ARTIFACT_FILE: artifactFile, VERIFICATION_PROFILE: 'full',
9
+ LANG: 'C.UTF-8', TZ: 'UTC', GIT_CONFIG_NOSYSTEM: '1', GIT_CONFIG_GLOBAL: join(home, 'gitconfig'),
10
+ GIT_TERMINAL_PROMPT: '0', GIT_NO_LAZY_FETCH: '1', GIT_NO_REPLACE_OBJECTS: '1',
11
+ GIT_AUTHOR_NAME: 'Rehearsal', GIT_AUTHOR_EMAIL: 'rehearsal@example.invalid',
12
+ GIT_COMMITTER_NAME: 'Rehearsal', GIT_COMMITTER_EMAIL: 'rehearsal@example.invalid',
13
+ WRANGLER_SEND_METRICS: 'false', RER_UPDATE_CHECK: '0'};
14
+ }
@@ -0,0 +1,84 @@
1
+ // Mirrors platform install-metadata.ts (bbf6ca98); keep installation projection behavior aligned.
2
+ import {MANAGED_WORKFLOW, repositoryAutomation} from './automation.mjs'
3
+
4
+ /** The edition-authoring recipe; its local component paths must all be tracked for the seed's source check. */
5
+ export const RECIPE = 'edition.json'
6
+ /** Generated metadata is JSON: the recipe, and Base copy records and object proofs wherever a seed keeps them
7
+ * (edition-authoring's default `base-copies.json`, or any `--record` file), recognised by shape rather than name. */
8
+ export const metadataCandidate = (path ) => path.endsWith('.json')
9
+
10
+ const within = (name , prefix ) => name === prefix || name.startsWith(prefix + '/')
11
+ const encode = (value ) => new TextEncoder().encode(JSON.stringify(value, null, 2) + '\n')
12
+ // Unreadable metadata (a merge conflict, a publisher defect) passes through unchanged for the seed's own check to report.
13
+ const parse = (bytes ) => { try { return JSON.parse(new TextDecoder().decode(bytes)) } catch { return null } }
14
+
15
+ /** A Base copy record names each verbatim copy, and the seed's own verify checks every recorded file is on disk with
16
+ * its recorded bytes. The installation's record drops removed automation (and rer-managed.yml when RER replaced it,
17
+ * since its bytes are no longer Base's). Returns null when nothing changes, keeping the publisher's bytes. */
18
+ const copyRecord = (record ) => record?.schemaVersion === 1 && Array.isArray(record.copies)
19
+ && record.copies.every((copy ) => typeof copy?.path === 'string' && copy.files && typeof copy.files === 'object')
20
+ const removedCopy = (name , keptWorkflow ) => repositoryAutomation(name) && !(keptWorkflow && name === MANAGED_WORKFLOW)
21
+
22
+ function installationCopyRecord(record , keptWorkflow ) {
23
+ if (!copyRecord(record)) return null
24
+ let changed = false
25
+ const copies = record.copies.flatMap((copy ) => {
26
+ const names = Object.keys(copy?.files ?? {}), kept = names.filter(name => !removedCopy(name, keptWorkflow))
27
+ if (kept.length === names.length) return [copy]
28
+ changed = true
29
+ if (!kept.length) return []
30
+ const pick = (map ) => Object.fromEntries(Object.entries(map).filter(([name]) => kept.includes(name)))
31
+ return [{...copy, files: pick(copy.files), ...(copy.modes ? {modes: pick(copy.modes)} : {})}]
32
+ })
33
+ return changed ? encode({...record, copies}) : null
34
+ }
35
+
36
+ /** The recipe's local component paths (and their mappings) drop the automation RER removed; RER's entry stays. */
37
+ function installationRecipe(recipe ) {
38
+ if (!Array.isArray(recipe?.components)) return null
39
+ const removed = (path ) => typeof path === 'string' && repositoryAutomation(path) && !within(MANAGED_WORKFLOW, path)
40
+ let changed = false
41
+ const components = recipe.components.map((component ) => {
42
+ const source = component?.source
43
+ if (source?.kind !== 'local' || !Array.isArray(source.paths) || !source.paths.some(removed)) return component
44
+ changed = true
45
+ const paths = source.paths.filter((path ) => !removed(path))
46
+ const mappings = source.mappings?.filter((mapping ) => typeof mapping?.path === 'string' && paths.some((path ) => within(mapping.path, path)))
47
+ return {...component, source: {...source, paths, ...(source.mappings ? {mappings} : {})}}
48
+ })
49
+ return changed ? encode({...recipe, components}) : null
50
+ }
51
+
52
+ /** Blob ids that only the dropped copy records name, from every metadata file given (non-records are ignored);
53
+ * `blob` maps a publisher path to its blob id. A recorded copy's bytes equal its Base origin's (the seed's check
54
+ * compares both), so these are the origin blobs a retained Base object proof holds only for dropped records. */
55
+ export function droppedCopyBlobs(files , blob , keptWorkflow ) {
56
+ const dropped = new Set (), named = new Set ()
57
+ for (const bytes of files) {
58
+ const record = parse(bytes)
59
+ if (copyRecord(record)) for (const copy of record.copies) for (const name of Object.keys(copy.files)) {
60
+ const id = blob(name)
61
+ if (id) (removedCopy(name, keptWorkflow) ? dropped : named).add(id)
62
+ }
63
+ }
64
+ for (const id of named) dropped.delete(id)
65
+ return dropped
66
+ }
67
+
68
+ /** A retained Base object proof (native Git objects by id, standing in for the Base repository) admits exactly the
69
+ * objects its copy records require, so it drops the origin blobs of the dropped records. */
70
+ function installationObjectProof(proof , dropped ) {
71
+ const objects = proof?.objects
72
+ if (!dropped.size || !Array.isArray(proof?.revisions) || !objects || typeof objects !== 'object' || Array.isArray(objects)
73
+ || !Object.keys(objects).every(id => /^[a-f0-9]{40}$/.test(id))) return null
74
+ const kept = Object.entries(objects).filter(([id]) => !dropped.has(id))
75
+ return kept.length === Object.keys(objects).length ? null : encode({...proof, objects: Object.fromEntries(kept)})
76
+ }
77
+
78
+ /** The installation's bytes for one publisher metadata file, or null when it stays as published. `keptWorkflow`:
79
+ * the installation carries the publisher's own rer-managed.yml; `dropped`: droppedCopyBlobs of the same tree. */
80
+ export function installationMetadata(path , bytes , keptWorkflow , dropped = new Set()) {
81
+ if (!metadataCandidate(path)) return null
82
+ const value = parse(bytes)
83
+ return path === RECIPE ? installationRecipe(value) : installationCopyRecord(value, keptWorkflow) ?? installationObjectProof(value, dropped)
84
+ }
@@ -0,0 +1,54 @@
1
+ import {resolve} from 'node:path';
2
+ import {invalid} from '../errors.mjs';
3
+
4
+ export const rehearseHelp = `Usage: rer rehearse [--cwd DIR] [--ref REF] [--json] [FLAGS]
5
+
6
+ Rehearse the first managed build in a fresh two-commit copy, outside this checkout.
7
+ Runs every declared setup, build, verify and artifact operation, in that order,
8
+ continuing after failures. No provider credentials are passed to the operations.
9
+
10
+ --ref REF Committed source to rehearse (default HEAD).
11
+ --repository OWNER/REPO Upstream identity (default rer-project.json sourceRepository).
12
+ --workflow-ref WORKFLOW@SHA Platform trusted workflow pin, required only when the seed
13
+ has no dispatch-only .github/workflows/rer-managed.yml.
14
+ --operation-timeout-seconds N Deadline for each operation (default 900).
15
+ --timeout-seconds N Overall deadline, including preparation (default 3600).
16
+ --keep Keep the scratch repository and its private HOME for diagnosis.
17
+ --json One version-1 result event with every operation, cause,
18
+ child exit/signal, elapsed seconds and captureLog path.
19
+ --help Show help without running anything.
20
+
21
+ Exit 0: all operations pass; 1: any FAIL or NOT REACHED; 2: invalid arguments;
22
+ 3: source/declaration/scratch preparation failed; 124: overall timeout;
23
+ 130/143: interrupted by SIGINT/SIGTERM. Per-operation timeouts are FAIL (exit 1).
24
+ The redacted capture log survives cleanup. NOT REACHED names a missing prerequisite
25
+ following a failed operation, or the overall deadline/interruption that prevented a start.
26
+ Operations are trusted seed code and can install packages and contact the network.
27
+ This is a local build rehearsal; it does not attest, upload or deploy an artifact.
28
+
29
+ Heavy work: signers and seed lanes must run through .tools/heavy-slot.py:
30
+ python3 -I /path/to/.tools/heavy-slot.py --remote auto -- rer rehearse --cwd SEED
31
+ Use a clean committed worktree when routing remotely; the selected source must be local
32
+ on that runner. Only declared operations may acquire dependencies over the network.
33
+ `;
34
+
35
+ export function rehearseOptions(args) {
36
+ const options = {cwd:process.cwd(), ref:'HEAD', operationTimeoutSeconds:900, timeoutSeconds:3600};
37
+ const seen = new Set();
38
+ for (let index=0; index<args.length; index++) {
39
+ const flag=args[index];
40
+ if (seen.has(flag)) throw invalid(`Repeated flag ${flag}.`); seen.add(flag);
41
+ if (['--json','--keep','--help','--non-interactive'].includes(flag)) options[flag.slice(2)] = true;
42
+ else if (['--cwd','--ref','--repository','--workflow-ref','--operation-timeout-seconds','--timeout-seconds'].includes(flag)) {
43
+ const value=args[++index];if (!value || value.startsWith('--')) throw invalid(`Provide a value for ${flag}.`);
44
+ const key=flag.slice(2).replace(/-([a-z])/g,(_,letter)=>letter.toUpperCase());
45
+ if (flag.endsWith('seconds')) {
46
+ if (!/^[1-9][0-9]*$/.test(value) || !Number.isSafeInteger(Number(value)) || Number(value)>86400) throw invalid(`${flag} takes integer seconds from 1 to 86400.`);
47
+ options[key]=Number(value);
48
+ } else options[key]=value;
49
+ } else throw invalid(`Unsupported rehearsal flag ${flag}. Run rer rehearse --help.`);
50
+ }
51
+ options.cwd=resolve(options.cwd);
52
+ if (options.ref.startsWith('-')) throw invalid('--ref must name a Git commit or reference.');
53
+ return options;
54
+ }
@@ -0,0 +1,94 @@
1
+ import {mkdtemp, mkdir, readFile, rm} from 'node:fs/promises';
2
+ import {join, relative, isAbsolute} from 'node:path';
3
+ import {tmpdir} from 'node:os';
4
+ import {execFile} from 'node:child_process';
5
+ import {promisify} from 'node:util';
6
+ import {shared} from '../shared.mjs';
7
+ import {projectInstallation, restoreArchive} from './snapshot.mjs';
8
+ import {rehearsalEnvironment} from './environment.mjs';
9
+
10
+ const execute=promisify(execFile), order=['setup','build','verify','artifact'];
11
+ const firstLine=value=>String(value).split(/\r?\n/).map(line=>line.trim()).find(Boolean);
12
+ const missingInput=/(?:ENOENT|Cannot find (?:module|package)|command not found|No such file or directory|cannot (?:open|access)|missing (?:build|artifact|output))/i;
13
+ const causeLine=text=>text.split(/\r?\n/).map(line=>line.trim()).find(line=>/error|failed|missing|cannot|not found|ERR_|contract_anchor/i.test(line)) ?? firstLine(text);
14
+
15
+ export async function rehearse(options, progress) {
16
+ const started=performance.now(), controller=new AbortController();
17
+ const timer=setTimeout(()=>controller.abort('Overall rehearsal deadline reached.'),options.timeoutSeconds*1000);
18
+ const handlers=new Map(['SIGINT','SIGTERM'].map(signal=>[signal,()=>controller.abort(signal)]));
19
+ for (const [signal,handler] of handlers) process.on(signal,handler);
20
+ let scratch,store,captureDirectory,currentOutput='',phase='Preparing managed copy';
21
+ const operations=[], result={sourceRef:options.ref, runtime:{node:process.version,platform:process.platform,arch:process.arch}, operations};
22
+ const elapsed=()=>Number(((performance.now()-started)/1000).toFixed(3));
23
+ try {
24
+ scratch=await mkdtemp(join(tmpdir(),'rer-rehearse-'));
25
+ // Logs live separately so cleanup does not discard the reason a signer needs.
26
+ captureDirectory=await mkdtemp(join(tmpdir(),'rer-rehearse-log-'));
27
+ const home=join(scratch,'home'), root=join(scratch,'repository');await mkdir(home);await mkdir(root);
28
+ const env=rehearsalEnvironment(home,'rer-worker-artifact.json');
29
+ const {createCommands}=await shared('commands.mjs');
30
+ store=await createCommands(captureDirectory,{logs:[]},{terminal:text=>{currentOutput=(currentOutput+text).slice(-65536);}});
31
+ result.captureLog=store.logPath;
32
+ const git=async (cwd,...args)=>(await execute('git',['-C',cwd,...args],{env,signal:controller.signal,maxBuffer:64*1024*1024})).stdout;
33
+ const sourceRoot=(await git(options.cwd,'rev-parse','--show-toplevel')).trim();
34
+ const inside=relative(sourceRoot,scratch);
35
+ if (!inside || (!inside.startsWith('..') && !isAbsolute(inside))) throw Error('The temporary directory must be outside the source checkout. Set TMPDIR to an external directory.');
36
+ result.sourceCommit=(await git(sourceRoot,'rev-parse','--verify',`${options.ref}^{commit}`)).trim();
37
+ const sourceCommit=result.sourceCommit;
38
+ const entries=(await git(sourceRoot,'ls-tree','-rz','--full-tree',sourceCommit)).split('\0').filter(Boolean).map(row=>{
39
+ const tab=row.indexOf('\t'), [mode,type,id]=row.slice(0,tab).split(' ');if(type!=='blob')throw Error('Unsupported external Git objects in source tree.');
40
+ return {mode,id,path:row.slice(tab+1)};
41
+ });
42
+ const run=(name,command,args,cwd=root,signal=controller.signal)=>store.run(name,command,args,{cwd,env,signal,display:[command,...args].join(' ')});
43
+ await run(phase,'git',['-C',sourceRoot,'archive','--format=tar',`--output=${join(scratch,'source.tar')}`,sourceCommit]);
44
+ await run(phase,'tar',['-xf',join(scratch,'source.tar'),'-C',root]);
45
+ await restoreArchive(root,entries,async id=>(await execute('git',['-C',sourceRoot,'cat-file','blob',id],{env,signal:controller.signal,encoding:'buffer',maxBuffer:64*1024*1024})).stdout);
46
+ const descriptor=JSON.parse(await readFile(join(root,'rer-project.json'),'utf8'));
47
+ if (descriptor.schema!==1 || descriptor.deployment?.target!=='cloudflare-workers' || !descriptor.operations ||
48
+ !['build','verify'].every(name=>typeof descriptor.operations[name]==='string' && descriptor.operations[name].trim())) throw Error('rer-project.json must declare schema 1, cloudflare-workers, build and verify operations.');
49
+ for (const name of order) if (descriptor.operations[name]!==undefined && (typeof descriptor.operations[name]!=='string' || !descriptor.operations[name].trim())) throw Error(`rer-project.json operations.${name} must be a nonempty shell command.`);
50
+ const artifactFile=descriptor.deployment.artifactFile??'rer-worker-artifact.json';
51
+ if (!/^[\w.-]+\.json$/.test(artifactFile)) throw Error('Invalid deployment artifact filename.');
52
+ env.ARTIFACT_FILE=artifactFile;
53
+ const repository=(options.repository??descriptor.sourceRepository??'').replace(/^https:\/\/github\.com\//,'').replace(/\.git$/,'').replace(/\/$/,'');
54
+ if (!/^[A-Za-z0-9][A-Za-z0-9-]{0,38}\/[A-Za-z0-9._-]{1,100}$/.test(repository)) throw Error('Provide --repository OWNER/REPO or declare sourceRepository in rer-project.json.');
55
+ result.repository=repository;
56
+ await run(phase,'git',['init','-q','--initial-branch=main']);
57
+ await run(phase,'git',['-c','core.hooksPath=/dev/null','commit','-q','--allow-empty','-m','Initial commit']);
58
+ await projectInstallation(root,entries,{repository,ref:options.ref,sourceCommit,workflowRef:options.workflowRef,artifactFile});
59
+ await run(phase,'git',['add','--all','--force']);
60
+ await run(phase,'git',['-c','core.hooksPath=/dev/null','commit','-q','-m',`Install ${descriptor.projectId??repository} from ${repository}@${sourceCommit}\n\n[skip ci]\n`]);
61
+ result.installCommit=(await git(root,'rev-parse','HEAD')).trim();
62
+ result.installTree=(await git(root,'rev-parse','HEAD^{tree}')).trim();
63
+ if (options.keep) result.scratch=root;
64
+ for (const name of order.filter(name=>descriptor.operations[name]!==undefined)) {
65
+ const command=descriptor.operations[name], operationStarted=performance.now();
66
+ if (controller.signal.aborted) {operations.push({name,command,status:'NOT REACHED',cause:String(controller.signal.reason),seconds:0});continue;}
67
+ progress?.(`Rehearsing ${name}…`); phase=name;currentOutput='';
68
+ const deadline=AbortSignal.timeout(options.operationTimeoutSeconds*1000), signal=AbortSignal.any([controller.signal,deadline]);
69
+ try {
70
+ await run(name,'/bin/bash',['-e','-o','pipefail','-c',command],root,signal);
71
+ operations.push({name,command,status:'PASS',exitCode:0,seconds:Number(((performance.now()-operationStarted)/1000).toFixed(3))});
72
+ } catch (error) {
73
+ const output=store.redact(currentOutput), earlier=operations.filter(row=>row.status!=='PASS').map(row=>row.name);
74
+ const unavailable=earlier.length>0 && missingInput.test(output);
75
+ const cause=controller.signal.aborted?String(controller.signal.reason):deadline.aborted?`Operation exceeded ${options.operationTimeoutSeconds} seconds.`:causeLine(output.replace(new RegExp(`^${name}\\s*\\n`),''))??firstLine(error.message);
76
+ operations.push({name,command,status:unavailable?'NOT REACHED':'FAIL',cause:unavailable?`Missing prerequisite after ${earlier.join(', ')} failed: ${cause}`:cause,exitCode:error.childExitCode??null,signal:error.signal??null,seconds:Number(((performance.now()-operationStarted)/1000).toFixed(3))});
77
+ }
78
+ }
79
+ result.exitCode=operations.every(row=>row.status==='PASS')?0:1;
80
+ } catch (error) {
81
+ result.exitCode=3;
82
+ const cause=error.step ? causeLine(error.step.output.join('\n'))??firstLine(error.message) : firstLine(error.message);
83
+ result.cause=store?.redact(cause)??cause;
84
+ store?.report(`${phase}: ${error.message}`,{logOnly:true});
85
+ } finally {
86
+ clearTimeout(timer);
87
+ for (const [signal,handler] of handlers) process.off(signal,handler);
88
+ try {await store?.closeCommands();} catch(error) {result.exitCode=3;result.cause=store?.redact(firstLine(error.message));}
89
+ if (controller.signal.aborted) result.exitCode=controller.signal.reason==='SIGINT'?130:controller.signal.reason==='SIGTERM'?143:124;
90
+ if (scratch && !options.keep) await rm(scratch,{recursive:true,force:true});
91
+ result.seconds=elapsed();result.ok=result.exitCode===0;
92
+ }
93
+ return result;
94
+ }
@@ -0,0 +1,60 @@
1
+ import {readFile, writeFile, readdir, rm, chmod, mkdir, lstat} from 'node:fs/promises';
2
+ import {createHash} from 'node:crypto';
3
+ import {join, dirname} from 'node:path';
4
+ import {installationLock} from '../../edition-authoring/lock.mjs';
5
+ import {MANAGED_WORKFLOW, repositoryAutomation, dispatchOnlyWorkflow} from './automation.mjs';
6
+ import {droppedCopyBlobs, installationMetadata} from './metadata.mjs';
7
+ import {managedWorkflow} from './workflow.mjs';
8
+
9
+ const json = value => JSON.stringify(value, null, 2) + '\n';
10
+ export async function projectInstallation(root, entries, {repository, ref, sourceCommit, workflowRef, artifactFile}) {
11
+ const sources = new Map(), ids = new Map(entries.map(entry => [entry.path, entry.id]));
12
+ for (const {path} of entries) if (path.endsWith('.json') || path === MANAGED_WORKFLOW) sources.set(path, await readFile(join(root,path)));
13
+ const kept = sources.has(MANAGED_WORKFLOW) && dispatchOnlyWorkflow(sources.get(MANAGED_WORKFLOW));
14
+ if (!kept && !workflowRef) throw Error('Provide --workflow-ref OWNER/REPO/.github/workflows/FILE.yml@SHA: the seed has no dispatch-only managed workflow.');
15
+ const workflow = kept ? sources.get(MANAGED_WORKFLOW) : managedWorkflow(workflowRef, artifactFile);
16
+ const dropped = droppedCopyBlobs(sources.values(), path => ids.get(path), kept), changed = {};
17
+ const replace = async (path, bytes, executable = false) => {
18
+ await mkdir(dirname(join(root,path)), {recursive:true});
19
+ await writeFile(join(root,path), bytes); await chmod(join(root,path), executable ? 0o755 : 0o644);
20
+ changed[path] = {data: Buffer.from(bytes).toString('base64'), executable};
21
+ };
22
+ for (const {path} of entries) if (repositoryAutomation(path)) await rm(join(root,path), {force:true});
23
+ let recipe;
24
+ for (const [path,bytes] of sources) {
25
+ if (repositoryAutomation(path) || path === 'sources.lock.json') continue;
26
+ const body = installationMetadata(path, bytes, kept, dropped);
27
+ if (body) {
28
+ await replace(path, body, entries.find(entry => entry.path === path).mode === '100755');
29
+ if (path === 'edition.json') recipe = JSON.parse(Buffer.from(body).toString('utf8'));
30
+ }
31
+ }
32
+ await replace(MANAGED_WORKFLOW, workflow, kept && entries.find(entry => entry.path === MANAGED_WORKFLOW).mode === '100755');
33
+ await replace('rer-upstream.json', json({schema:1, repository, tag:ref, commit:sourceCommit}));
34
+ if (sources.has('sources.lock.json')) await writeFile(join(root,'sources.lock.json'),json(installationLock(JSON.parse(sources.get('sources.lock.json')), {removed:repositoryAutomation, changed, recipe})));
35
+ }
36
+
37
+ // Archive attributes may omit/substitute bytes. Restore those from local Git objects,
38
+ // just as the platform verifies its downloaded archive against the exact source tree.
39
+ export async function restoreArchive(root, entries, readBlob) {
40
+ const names = new Set(entries.map(entry => entry.path));
41
+ async function prune(directory, prefix = '') {
42
+ for (const item of await readdir(directory, {withFileTypes:true})) {
43
+ const name = prefix + item.name, path = join(directory,item.name);
44
+ if (item.isDirectory()) { await prune(path,name+'/'); continue; }
45
+ if (!names.has(name)) await rm(path,{force:true});
46
+ }
47
+ }
48
+ await prune(root);
49
+ for (const entry of entries) {
50
+ if (!['100644','100755'].includes(entry.mode)) throw Error(`Unsupported source mode: ${entry.path}`);
51
+ const path = join(root,entry.path), stat = await lstat(path).catch(() => null);
52
+ const bytes = stat?.isFile() ? await readFile(path) : null;
53
+ const id = bytes && createHash('sha1').update(`blob ${bytes.length}\0`).update(bytes).digest('hex');
54
+ if (id !== entry.id) {
55
+ if (stat) await rm(path,{force:true,recursive:true});
56
+ await mkdir(dirname(path),{recursive:true});await writeFile(path,await readBlob(entry.id));
57
+ }
58
+ await chmod(path,entry.mode === '100755' ? 0o755 : 0o644);
59
+ }
60
+ }
@@ -0,0 +1,42 @@
1
+ // Mirrors platform managed-workflow.ts (bbf6ca98); keep installation projection behavior aligned.
2
+ /** RER's delivery entry for a publisher without its own dispatch-only rer-managed.yml: the Base producer shape, one
3
+ * dispatch-only job calling the trusted build, which runs the project's declared setup, build, verify and artifact. */
4
+ export function managedWorkflow(trusted , artifactFile ) {
5
+ if (!/^[\w.-]+\/[\w.-]+\/\.github\/workflows\/[\w.-]+\.ya?ml@[a-f0-9]{40}$/.test(trusted)
6
+ || !/^[\w.-]+\.json$/.test(artifactFile)) throw Error('Invalid managed workflow configuration')
7
+ return new TextEncoder().encode(`name: Managed release
8
+ on:
9
+ workflow_dispatch:
10
+ inputs:
11
+ installation_id:
12
+ required: true
13
+ type: string
14
+ broker_url:
15
+ required: true
16
+ type: string
17
+ environment:
18
+ required: true
19
+ default: preview
20
+ type: choice
21
+ options: [preview, production]
22
+ verification_profile:
23
+ required: true
24
+ default: full
25
+ type: choice
26
+ options: [full]
27
+ permissions:
28
+ contents: read
29
+ actions: read
30
+ id-token: write
31
+ jobs:
32
+ release:
33
+ uses: ${trusted}
34
+ with:
35
+ installation_id: \${{ inputs.installation_id }}
36
+ broker_url: \${{ inputs.broker_url }}
37
+ environment: \${{ inputs.environment }}
38
+ verification_profile: \${{ inputs.verification_profile }}
39
+ artifact_file: ${artifactFile}
40
+ build_profile: project
41
+ `)
42
+ }
@@ -0,0 +1,20 @@
1
+ import {rehearseOptions, rehearseHelp} from './rehearse/options.mjs';
2
+ import {rehearse} from './rehearse/run.mjs';
3
+ import {output} from './output.mjs';
4
+
5
+ export async function rehearseCommand(args) {
6
+ let options={verb:'rehearse',json:args.includes('--json')}, out=output(options);
7
+ try {
8
+ options={...rehearseOptions(args),verb:'rehearse'};out=output(options);
9
+ if(options.help){if(options.json)out.event('help',{usage:rehearseHelp});else out.human(rehearseHelp);return 0;}
10
+ const result=await rehearse(options,options.json?undefined:text=>out.progress(text+'\n'));
11
+ if(!options.json){
12
+ for(const row of result.operations)out.human(`${row.status} ${row.name}${row.cause?`: ${row.cause}`:''}`);
13
+ if(result.cause)out.human(`Could not prepare rehearsal: ${result.cause}`);
14
+ if(result.captureLog)out.human(`Capture log: ${result.captureLog}`);
15
+ if(result.scratch)out.human(`Kept scratch copy: ${result.scratch}`);
16
+ out.human(`Elapsed: ${result.seconds}s`);
17
+ }
18
+ const {ok,exitCode,...details}=result;out.result(ok,exitCode,details);return exitCode;
19
+ } catch(error){const code=error.exitCode??2;out.error({code:error.code??'invalid_invocation',message:error.message,exitCode:code});out.result(false,code);return code;}
20
+ }
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
  }
@@ -14,6 +14,30 @@ function toolsIdentity() {
14
14
  function includes(files, selected) {
15
15
  return Object.keys(files).some(p => p === selected || p.startsWith(selected + '/'));
16
16
  }
17
+ // Regenerate projected identities with the same hashing/serialization as normal source locks.
18
+ export function fileIdentities(files) {
19
+ return Object.fromEntries(Object.entries(files).sort(([a], [b]) => a.localeCompare(b)).map(([name, value]) => [name, {
20
+ sha256: hash(Buffer.from(value.data, 'base64')), executable: value.executable,
21
+ }]));
22
+ }
23
+
24
+ // Managed copies retain the publisher's toolchain and source pins. Only the installation's
25
+ // changed metadata/automation is regenerated; unchanged application identities stay bound.
26
+ export function installationLock(lock, {removed, changed, recipe}) {
27
+ if (lock.schemaVersion !== 1 || !lock.files || Array.isArray(lock.files) ||
28
+ Object.values(lock.files).some(value => !value || !/^[a-f0-9]{64}$/.test(value.sha256) || typeof value.executable !== 'boolean'))
29
+ throw Error('Unsupported source lock; provide an edition-authoring file lock.');
30
+ const files = Object.fromEntries(Object.entries(lock.files).filter(([name]) => !removed(name)));
31
+ Object.assign(files, fileIdentities(changed));
32
+ lock = {...lock, files: Object.fromEntries(Object.entries(files).sort(([a], [b]) => a.localeCompare(b)))};
33
+ if (recipe && 'manifest' in lock) lock.manifest = hash(json(recipe));
34
+ if (recipe && Array.isArray(lock.components)) lock.components = lock.components.map(component => {
35
+ const selected = recipe.components.find(entry => entry.id === component?.id);
36
+ return selected && 'source' in component ? {...component, source: selected.source} : component;
37
+ });
38
+ return lock;
39
+ }
40
+
17
41
  export function resolveSources(root, retain = false, diagnostics = false, additionalFiles = {}) {
18
42
  const recipe = manifest(root);
19
43
  const files = Object.assign(tracked(root, diagnostics), additionalFiles);
@@ -37,12 +61,10 @@ export function resolveSources(root, retain = false, diagnostics = false, additi
37
61
  components.push({id: component.id, source: selected, baseline: baseline ? {key: baseline.key, digest: baseline.digest, sha256: hash(json(baseline))} : null});
38
62
  }
39
63
  const parent = recipe.parent ? snapshot(root, {...recipe.parent, excludeSnapshots: true}, retain) : null;
40
- const identities = Object.entries(files).sort(([a], [b]) => a.localeCompare(b)).map(([name, value]) => [name, {
41
- sha256: hash(Buffer.from(value.data, 'base64')), executable: value.executable,
42
- }]);
64
+ const identities = fileIdentities(files);
43
65
  return {
44
66
  schemaVersion: 1, parent: parent ? {key: parent.key, digest: parent.digest, sha256: hash(json(parent))} : null,
45
67
  edition: recipe.id, manifest: hash(json(recipe)), toolchain: toolsIdentity(),
46
- components, files: Object.fromEntries(identities),
68
+ components, files: identities,
47
69
  };
48
70
  }
@@ -1,5 +1,34 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.114
4
+
5
+ ### Pre-install rehearsal
6
+
7
+ - New `rer rehearse --cwd DIR --ref REF` runs the selected committed seed's declared setup, build, verify and artifact operations, in order, in a fresh two-commit installation copy outside the source checkout. It removes publisher automation, retains or generates a dispatch-only managed workflow, updates installation metadata and source-lock identities while preserving publisher source pins, and leaves the source checkout unchanged.
8
+ - Rehearsal continues after operation failures and reports PASS, FAIL or NOT REACHED with the first cause, elapsed time and a redacted capture-log path. Per-operation and overall deadlines bound execution; `--json` provides the structured result and `--keep` retains the scratch copy for diagnosis. A fresh private HOME/config/cache and restricted environment keep caller provider credentials out. Declared operations are trusted seed code and may acquire dependencies over the network; signers and seed lanes must run this heavy work through their supported heavy slot.
9
+ - The global launcher and refreshed default-seed CLI expose the command and its help. This releases CLI support: each signer or seed lane must adopt this rer and run rehearsal against its own committed seed. A local rehearsal does not establish GitHub attestation, artifact upload, provider deployment, seed adoption or production behavior.
10
+
11
+ Code and documentation only: the actual diff adds no migrations and touches neither modules/import-kit nor modules/portability. No deployed seed behavior is changed by preparing this release.
12
+
13
+ ## 0.2.113
14
+
15
+ ### Recovery output and archive restore
16
+
17
+ - 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.
18
+ - 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.
19
+ - 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.
20
+
21
+ ### Deploy plans and first-run startup
22
+
23
+ - `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.
24
+ - 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.
25
+
26
+ ### Erasure archive preflight
27
+
28
+ - 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.
29
+
30
+ 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.
31
+
3
32
  ## 0.2.112
4
33
 
5
34
  ### Downloaded tools and export progress
package/global/README.md CHANGED
@@ -727,3 +727,54 @@ runtime and type dependencies. The existing
727
727
  `@runeditrun/rer/modules/import-kit/d1` entry remains available. See the
728
728
  [adoption guide](https://github.com/runeditrun/base/blob/main/modules/import-kit/src/door/ADOPTING.md)
729
729
  for native adapters, consent, declared intake projection and reviewed apply/Undo.
730
+
731
+ ## Rehearse before signing a seed release
732
+
733
+ Run `rer rehearse --cwd /path/to/seed --ref HEAD` before announcing a release.
734
+ It exports the selected commit into a fresh repository outside the checkout,
735
+ with an empty `Initial commit` and one installation commit. The installation
736
+ projection removes publisher automation, preserves a dispatch-only managed
737
+ workflow, updates its recipe/copy metadata, adds schema-1 `rer-upstream.json`
738
+ (repository, tag/ref, exact source SHA), and regenerates changed lock identities
739
+ through Base's source-lock generator while retaining the publisher's source pins.
740
+ Uncommitted files and publisher history are absent. The source checkout is unchanged.
741
+
742
+ This installs dependencies and builds. Signers and seed lanes must use the heavy slot:
743
+
744
+ ```sh
745
+ python3 -I /path/to/.tools/heavy-slot.py --remote auto -- rer rehearse --cwd /path/to/seed --ref HEAD
746
+ ```
747
+
748
+ Use a committed clean worktree for remote routing and make the source available
749
+ on that runner. The command itself uses local Git objects and creates no remote;
750
+ only the declared operations may acquire dependencies over the network. Supply the
751
+ same Node and package-manager tools as the seed's trusted build. A fresh private
752
+ HOME/config/cache and a restricted environment keep caller provider credentials out.
753
+ The operations are trusted source code, not a sandbox for an untrusted seed.
754
+
755
+ Every declared `setup`, `build`, `verify`, `artifact` command runs in that order
756
+ from the scratch root, in its own `bash -e -o pipefail` process. Rehearsal continues
757
+ after failures, so one run reports every failing operation. A later command that
758
+ cannot start because a prior operation left a required input unavailable is
759
+ reported `NOT REACHED` with the missing-input diagnostic. Recovery prose is not
760
+ an executable operation. Shell variables and working-directory changes do not
761
+ carry between operations; filesystem changes do.
762
+
763
+ The summary prints PASS/FAIL/NOT REACHED, the first cause line and the full redacted
764
+ capture-log path. Logs survive scratch cleanup; `--keep` retains the repository and
765
+ its private HOME for diagnosis. `--operation-timeout-seconds N` defaults to 900;
766
+ `--timeout-seconds N` bounds preparation and all operations together (default 3600).
767
+ Both accept integer seconds from 1 to 86400. If no dispatch-only managed workflow
768
+ exists, provide the platform's immutable `--workflow-ref OWNER/REPO/.github/workflows/FILE.yml@SHA`.
769
+ `--repository OWNER/REPO` overrides the descriptor's source repository identity.
770
+ A branch/ref in the rehearsal upstream record identifies unreleased source; it is
771
+ not a signed stable-release record.
772
+
773
+ Exit codes: 0 all pass; 1 an operation failed or was not reached; 2 invalid flags;
774
+ 3 preparation/source/declaration failure; 124 overall timeout; 130/143 interruption.
775
+ A per-operation timeout is FAIL and exit 1. With `--json`, stdout contains one
776
+ version-1 `result` event with `ok`, `exitCode`, source/install identities, elapsed
777
+ `seconds`, `captureLog` and every operation's command, status, cause and child
778
+ exit/signal. `rer rehearse --help` lists the flags. This proves local declared
779
+ build operations under the recorded host conditions; GitHub attestation, artifact
780
+ upload and provider deployment remain separate.
package/global/main.mjs CHANGED
@@ -25,6 +25,8 @@ else its vendored scripts/rer.mjs.
25
25
  RER_READY and a sign-in link. Without a terminal it returns once the app is
26
26
  ready and leaves it running (--detach and --foreground override); allow up
27
27
  to 10 minutes on a first launch, or rerun it to reattach. rer dev --stop stops it.
28
+ rer rehearse [--cwd DIR] [--ref REF]
29
+ Rehearse every managed build operation in a two-commit scratch copy.
28
30
  rer run SCRIPT [ARGS]
29
31
  Run a package.json script with the pnpm and Node the checkout pins (rer keeps
30
32
  them off PATH): where a project's docs say pnpm run X, run rer run X.
@@ -59,6 +61,7 @@ export async function main(argv) {
59
61
  handleBrokenPipes();
60
62
  const [verb] = argv;
61
63
  const installsFirst = checkoutBootstrap(argv) === 'before';
64
+ if (verb === 'rehearse') return (await import('../cli/rehearse.mjs')).rehearseCommand(argv.slice(1));
62
65
  if (verb === '--version' || verb === '-v') return (await import('./version.mjs')).versionCommand(argv);
63
66
  if (verb === 'queue' && argv.length === 2 && argv[1] === '--help') {
64
67
  process.stdout.write('Usage: rer queue NAME -- COMMAND [ARGS]\nRun COMMAND once this computer\'s job queue admits it.\n');
@@ -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');
@@ -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
+ }
@@ -12,8 +12,9 @@ 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
14
  import { isWranglerMigrationApply, wranglerMigrationView } from './migration-progress.mjs';
15
+ import { isWranglerQuery, wranglerQueryView, viteDiagnosticsView, archiveReceiptView } from './command-diagnostics-view.mjs';
15
16
 
16
- 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}={}) {
17
18
  let policy=queuePolicy?await commandPolicy():{environment:{},close:async()=>{}};
18
19
  const custodyBaseline=['darwin','linux'].includes(process.platform)?await createProcessBaseline():undefined;
19
20
  const logPath=join(directory,'install.log'), log=await openPrivateLog(logPath);
@@ -58,7 +59,10 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
58
59
  for(const match of text.matchAll(pattern)){result+=redaction.redact(text.slice(from,match.index))+match[0];from=match.index+match[0].length;}
59
60
  return result+redaction.redact(text.slice(from));
60
61
  };
61
- 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
+ };
62
66
  const failure=(label,detail={},capture)=>{
63
67
  const outcome=`exit ${detail.code??'none'}, signal ${detail.signal??'none'}`;
64
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;
@@ -69,6 +73,8 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
69
73
  };
70
74
  const track=(label,child,ownershipScope,view)=>{
71
75
  if(captures.has(child))return child;
76
+ if(filterViteWarnings)view=viteDiagnosticsView(view);
77
+ if(filterArchiveReceipts)view=archiveReceiptView(view);
72
78
  let resolveClose,resolveError,resolveExit;
73
79
  const capture={tail:'',scope:signal,closed:new Promise(resolve=>{resolveClose=resolve;}),failed:new Promise(resolve=>{resolveError=resolve;}),exited:new Promise(resolve=>{resolveExit=resolve;})};
74
80
  capture.custody=commandCustody(child,ownershipScope);
@@ -90,7 +96,7 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
90
96
  child.removeListener('exit',exited);if(!capture.exitResult)exited(code,terminationSignal);
91
97
  for(const source of sources)source.removeListener('data',data);
92
98
  filter.end();
93
- if(view){const rest=view.end();capture.tail=(capture.tail+rest).slice(-32768);emit(rest,'');Object.assign(state,view.facts?.());}
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?.());}
94
100
  active.delete(child);if(!capture.custody)managed.delete(child);resolveClose({code,signal:terminationSignal,error,errorCode:capture.errorCode});
95
101
  };
96
102
  child.once('close',finish);
@@ -167,6 +173,7 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
167
173
  // Any caller's `wrangler d1 migrations apply` (the setup hooks, a seed's own export and import) shows
168
174
  // a count instead of wrangler's table redrawn per migration; the log keeps every byte and is named in the summary.
169
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))})};
170
177
  if(queuePolicy && options.heavy !== false) {
171
178
  let queuedChild;
172
179
  const commandSignal=signal&&options.signal?AbortSignal.any([signal,options.signal]):options.signal||signal;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runeditrun/rer",
3
- "version": "0.2.112",
3
+ "version": "0.2.114",
4
4
  "description": "The rer command: install, set up, run and launch Run Edit Run checkouts.",
5
5
  "license": "MIT",
6
6
  "type": "module",