@runeditrun/rer 0.1.1 → 0.2.0

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.
Files changed (106) hide show
  1. package/README.md +111 -1
  2. package/cli/README.md +28 -3
  3. package/cli/contract.mjs +4 -4
  4. package/cli/dev-identity.mjs +2 -1
  5. package/cli/door-mode.mjs +134 -0
  6. package/cli/door.mjs +263 -0
  7. package/cli/hosted-output.mjs +15 -5
  8. package/cli/hydration/browser.mjs +91 -0
  9. package/cli/hydration/cases.mjs +106 -0
  10. package/cli/hydration/check.mjs +105 -0
  11. package/cli/hydration/probe.mjs +164 -0
  12. package/cli/hydration/scripts.mjs +39 -0
  13. package/cli/hydration/verdict.mjs +85 -0
  14. package/cli/inspect.mjs +56 -9
  15. package/cli/lifecycle.mjs +36 -12
  16. package/cli/local.mjs +9 -3
  17. package/cli/main.mjs +2 -0
  18. package/cli/managed-server.mjs +52 -18
  19. package/cli/package-calls.mjs +81 -0
  20. package/cli/package-mode.mjs +46 -0
  21. package/cli/parse.mjs +14 -4
  22. package/cli/pnpm-runtime.mjs +96 -0
  23. package/cli/portability-worker.mjs +2 -2
  24. package/cli/runtime-front-door.mjs +4 -2
  25. package/cli/server-proxy.mjs +69 -5
  26. package/cli/server-registry.mjs +10 -7
  27. package/cli/settings.mjs +14 -0
  28. package/cli/site-check.mjs +96 -0
  29. package/cli/site-preview.mjs +53 -0
  30. package/cli/site-render.mjs +77 -0
  31. package/cli/site.mjs +109 -0
  32. package/global/CHANGELOG.md +63 -0
  33. package/global/README.md +111 -1
  34. package/global/checkout.mjs +24 -10
  35. package/global/cli/install.mjs +6 -2
  36. package/global/delegate.mjs +9 -7
  37. package/global/door/command.mjs +254 -0
  38. package/global/door/control.mjs +65 -0
  39. package/global/door/cookies.mjs +41 -0
  40. package/global/door/pages.mjs +49 -0
  41. package/global/door/policy.mjs +49 -0
  42. package/global/door/routes.mjs +45 -0
  43. package/global/door/server.mjs +255 -0
  44. package/global/door/sites.mjs +192 -0
  45. package/global/launch/dev.mjs +21 -7
  46. package/global/launch/door.mjs +36 -0
  47. package/global/launch/install-pinned.mjs +22 -0
  48. package/global/launch/prepare.mjs +38 -5
  49. package/global/launch/render.mjs +6 -1
  50. package/global/launch/steps.mjs +12 -7
  51. package/global/launch/worker.mjs +3 -3
  52. package/global/list.mjs +6 -3
  53. package/global/main.mjs +37 -3
  54. package/global/version.mjs +8 -8
  55. package/modules/dependencies/protocol.mjs +2 -1
  56. package/modules/deploy-kit/README.md +34 -1
  57. package/modules/deploy-kit/artifact.mjs +10 -0
  58. package/modules/deploy-kit/owner.mjs +5 -4
  59. package/modules/deploy-kit/prepare.mjs +3 -2
  60. package/modules/deploy-kit/provider.mjs +6 -3
  61. package/modules/deploy-kit/site.mjs +135 -0
  62. package/modules/erasure/CONTRACT.md +6 -3
  63. package/modules/erasure/README.md +8 -1
  64. package/modules/erasure/audit.mjs +2 -2
  65. package/modules/erasure/cascade.mjs +52 -11
  66. package/modules/erasure/order.mjs +29 -22
  67. package/modules/erasure/plan.mjs +4 -2
  68. package/modules/erasure/queue.mjs +41 -0
  69. package/modules/erasure/scope.mjs +3 -3
  70. package/modules/erasure/verification.mjs +4 -2
  71. package/modules/mail/README.md +1 -1
  72. package/modules/mail/index.mjs +1 -1
  73. package/modules/mail/src/core/errors.mjs +9 -0
  74. package/modules/mail/src/development/index.d.mts +6 -0
  75. package/modules/mail/src/development/index.mjs +6 -3
  76. package/modules/mail/src/development/viewer-html.mjs +3 -3
  77. package/modules/mail/src/development/viewer.mjs +8 -1
  78. package/modules/operator-auth/dev/index.mjs +15 -5
  79. package/modules/operator-auth/http.mjs +2 -3
  80. package/modules/operator-auth/loopback.mjs +17 -0
  81. package/modules/owner-claim/verify.mjs +2 -1
  82. package/modules/portability/README.md +8 -0
  83. package/modules/portability/hash.mjs +6 -2
  84. package/modules/portability/import.mjs +1 -1
  85. package/modules/portability/legacy-files.mjs +4 -4
  86. package/modules/portability/legacy-safety.mjs +51 -10
  87. package/modules/portability/migration-history.mjs +15 -0
  88. package/modules/release/README.md +5 -3
  89. package/modules/release/produce.mjs +5 -2
  90. package/modules/release/source.mjs +15 -4
  91. package/onboarding/adapter-auth.mjs +4 -3
  92. package/onboarding/adapter-settings.mjs +21 -5
  93. package/onboarding/adapter.mjs +2 -1
  94. package/onboarding/app-fetch.mjs +79 -0
  95. package/onboarding/archive-output.d.mts +4 -2
  96. package/onboarding/archive-output.mjs +22 -10
  97. package/onboarding/dependency-approval.mjs +4 -3
  98. package/onboarding/local/environment.mjs +7 -2
  99. package/onboarding/operator-install.mjs +8 -2
  100. package/onboarding/operator-prerequisites.mjs +5 -2
  101. package/onboarding/queued-entry.mjs +9 -5
  102. package/operations/operations.mjs +11 -2
  103. package/package.json +75 -1
  104. package/scripts/publish-check/github_refs.py +28 -2
  105. package/scripts/publish-check/public_hygiene.py +35 -4
  106. package/scripts/publish-check/publication-config.json +14 -1
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env node
2
+ // Child of `rer build --site` and `rer dev`: builds the seed's declared site
3
+ // entry with the checkout's own Vite for Node (an SSR build), loads it and
4
+ // calls its sitePages({ styles }), then writes the static run site: "/" to
5
+ // index.html, "/run" to run.html, "/docs/a" to docs/a.html, "/404" to
6
+ // 404.html, the declared public files, and the stylesheet and files the
7
+ // entry's CSS imports compile to. The optional site config is a Vite config
8
+ // naming the plugins the site pages need (a docs virtual module, a CSS
9
+ // toolchain); the app's own Vite config is never loaded, because its Worker
10
+ // plugins do not run in Node. It reads no installation data.
11
+ // Usage: node site-render.mjs ROOT ENTRY OUTPUT [CONFIG]
12
+ import { cp, lstat, mkdir, rm, writeFile } from 'node:fs/promises';
13
+ import { createRequire } from 'node:module';
14
+ import { dirname, join, resolve, sep } from 'node:path';
15
+ import { pathToFileURL } from 'node:url';
16
+
17
+ const [root, entry, output, config] = process.argv.slice(2);
18
+ const fail = message => { process.stderr.write(`${message}\n`); process.exit(2); };
19
+ if (!root || !entry || !output) fail('Usage: site-render.mjs ROOT ENTRY OUTPUT [CONFIG]');
20
+ const inside = (base, path) => { const target = resolve(base, path); return target === base || target.startsWith(base + sep) ? target : null; };
21
+ // Compiled CSS and the files it references land under this folder of the site.
22
+ const ASSETS = 'site-assets';
23
+
24
+ let vite;
25
+ try { vite = await import(pathToFileURL(createRequire(join(root, 'package.json')).resolve('vite')).href); }
26
+ catch { fail('The run site renders with the checkout\'s own Vite. Run rer install first.'); }
27
+ process.env.NODE_ENV ??= 'production';
28
+
29
+ // The Node bundle sits beside the output, inside the checkout, so its external
30
+ // imports resolve from the checkout's node_modules. It never enters the site.
31
+ const server = `${output}.render`;
32
+ let module, styles = [], files = [];
33
+ try {
34
+ const built = await vite.build({
35
+ root, configFile: config ? resolve(root, config) : false, envFile: false, logLevel: 'error', mode: 'production',
36
+ build: {
37
+ ssr: resolve(root, entry), outDir: server, emptyOutDir: true, copyPublicDir: false, ssrEmitAssets: true,
38
+ cssCodeSplit: false, assetsDir: ASSETS, sourcemap: false, minify: false, reportCompressedSize: false, watch: null,
39
+ },
40
+ }).catch(error => fail(`The run site entry ${entry} did not build: ${error.message.split('\n')[0]}${config ? '' : ' If its pages need Vite plugins (a docs virtual module, a CSS toolchain), name a site Vite config: site: { config } in the command adapter.'}`));
41
+ const outputs = (Array.isArray(built) ? built : [built]).flatMap(result => result.output ?? []);
42
+ const chunk = outputs.find(item => item.type === 'chunk' && item.isEntry);
43
+ if (!chunk) fail(`The run site entry ${entry} produced no module.`);
44
+ files = outputs.filter(item => item.type === 'asset' && item.fileName.startsWith(`${ASSETS}/`)).map(item => item.fileName);
45
+ styles = files.filter(name => name.endsWith('.css')).map(name => `/${name}`);
46
+ await writeFile(join(server, 'package.json'), '{"type":"module"}\n');
47
+ module = await import(pathToFileURL(join(server, chunk.fileName)).href);
48
+ if (typeof module.sitePages !== 'function') fail(`${entry} must export sitePages(), returning { pages: [{ path, html }], assets: [public paths] }.`);
49
+ const build = await module.sitePages({ styles });
50
+ if (!Array.isArray(build?.pages) || !Array.isArray(build.assets)) fail('sitePages() returns { pages, assets }.');
51
+
52
+ const written = new Set();
53
+ for (const page of build.pages) {
54
+ if (typeof page?.path !== 'string' || !/^\/(?:[a-z0-9][a-z0-9._-]*(?:\/[a-z0-9][a-z0-9._-]*)*)?$/i.test(page.path) || page.path.endsWith('.html') || typeof page.html !== 'string') fail(`Invalid site page ${JSON.stringify(page?.path)}: a path such as /run with its HTML.`);
55
+ const file = page.path === '/' ? 'index.html' : `${page.path.slice(1)}.html`;
56
+ if (written.has(file) || file.startsWith(`${ASSETS}/`)) fail(`Duplicate site page ${page.path}.`);
57
+ written.add(file);
58
+ await mkdir(dirname(join(output, file)), { recursive: true });
59
+ await writeFile(join(output, file), page.html);
60
+ }
61
+ const publicDirectory = resolve(root, 'public');
62
+ for (const asset of build.assets) {
63
+ const source = typeof asset === 'string' && !asset.split('/').some(part => !part || part.startsWith('.')) && inside(publicDirectory, asset);
64
+ if (!source || source === publicDirectory) fail(`Invalid site asset ${JSON.stringify(asset)}: a file or folder under public/.`);
65
+ if (asset === ASSETS || asset.startsWith(`${ASSETS}/`)) fail(`public/${ASSETS} is reserved for the run site's compiled styles; rename it.`);
66
+ await lstat(source).catch(() => fail(`Missing site asset public/${asset}.`));
67
+ await cp(source, join(output, asset), { recursive: true, errorOnExist: true, force: false, verbatimSymlinks: true });
68
+ }
69
+ // Only the emitted files: the Node chunks share the folder and never ship.
70
+ for (const file of files) {
71
+ await mkdir(dirname(join(output, file)), { recursive: true });
72
+ await cp(join(server, file), join(output, file), { errorOnExist: true, force: false });
73
+ }
74
+ process.stdout.write(`${JSON.stringify({ pages: build.pages.length, assets: build.assets.length, styles: styles.length })}\n`);
75
+ } finally { await rm(server, { recursive: true, force: true }); }
76
+ // Vite and the loaded pages can keep handles open; every file is written.
77
+ process.exit(0);
package/cli/site.mjs ADDED
@@ -0,0 +1,109 @@
1
+ import { readFile, rename, rm, mkdir } from 'node:fs/promises';
2
+ import { dirname, join, relative } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { contained } from './project.mjs';
5
+ import { invalid, missing, refuse, RerError } from './errors.mjs';
6
+ import { checkSite } from './site-check.mjs';
7
+ import { readDevKey } from './dev-identity.mjs';
8
+ import { shared } from './shared.mjs';
9
+
10
+ // The run site: a seed's static marketing pages, /run and docs, built from
11
+ // edition identity with no installation data. A seed opts in with
12
+ // commandAdapter's `site: { entry, output, declaration, config? }`: the module
13
+ // whose sitePages({ styles }) returns the pages, the ignored folder the build
14
+ // writes, the deploy declaration naming the run site's domain, and optionally
15
+ // the Vite config holding the plugins the site pages need.
16
+ const relativePath = value => typeof value === 'string' && /^[A-Za-z0-9._/-]+$/.test(value) && !value.split('/').some(part => !part || part === '.' || part === '..');
17
+
18
+ export function declaredSite(project) {
19
+ const site = project.adapter?.site;
20
+ if (!site) throw refuse('This checkout declares no run site. A seed opts in with site: { entry, output, declaration } in its command adapter; see SEED-COMMAND-CONTRACT.md.');
21
+ if (!relativePath(site.entry) || !relativePath(site.output) || !relativePath(site.declaration) || (site.config !== undefined && !relativePath(site.config)) || ['src', 'public', 'node_modules', 'migrations'].some(top => site.output === top || site.output.startsWith(top + '/'))) throw invalid('The declared run site needs a relative entry, an output folder outside src, public and node_modules, a deploy declaration and, when named, a relative site Vite config.');
22
+ return site;
23
+ }
24
+
25
+ // Owner identity, secrets and the dev key: none may appear in the run site.
26
+ async function privateValues(project) {
27
+ const values = [], names = project.adapter.input?.names ?? {};
28
+ const { localVariables } = await shared('local/environment.mjs');
29
+ const variables = await readFile(join(project.root, project.adapter.hooks?.secrets?.file ?? '.dev.vars'), 'utf8').then(localVariables, () => ({}));
30
+ for (const [key, value] of Object.entries(variables)) if ([names.email, names.name].includes(key) || /SECRET|TOKEN|PASSWORD|_KEY$/.test(key)) values.push(value);
31
+ const answers = await readFile(join(project.root, '.seed/installer/setup-answers.json'), 'utf8').then(JSON.parse, () => ({}));
32
+ for (const key of [names.email, names.name]) if (typeof answers?.[key] === 'string') values.push(answers[key]);
33
+ const key = await readDevKey(project.root).catch(() => null);
34
+ if (key) values.push(key);
35
+ return values;
36
+ }
37
+
38
+ /** Render the run site into its declared folder, check it and replace the previous build. */
39
+ export async function buildSite(project, store, signal) {
40
+ const site = declaredSite(project);
41
+ await contained(project.root, site.entry);
42
+ if (site.config) await contained(project.root, site.config);
43
+ const folder = await contained(project.root, site.output, { optional: true });
44
+ await mkdir(dirname(folder), { recursive: true });
45
+ const staging = `${folder}.building-${process.pid}`;
46
+ await rm(staging, { recursive: true, force: true });
47
+ try {
48
+ await mkdir(staging);
49
+ await store.run('Building the run site', process.execPath, [fileURLToPath(new URL('./site-render.mjs', import.meta.url)), project.root, site.entry, staging, ...(site.config ? [site.config] : [])], { cwd: project.root, signal, heavy: false });
50
+ const checked = await checkSite(staging, { privateValues: await privateValues(project) });
51
+ await rm(folder, { recursive: true, force: true });
52
+ await rename(staging, folder);
53
+ return { folder, ...checked };
54
+ } finally { await Promise.all([staging, `${staging}.render`].map(path => rm(path, { recursive: true, force: true }))); }
55
+ }
56
+
57
+ async function siteDeployment(project, options, folder) {
58
+ const site = declaredSite(project), environment = options.environment ?? 'production';
59
+ const read = async path => { try { return JSON.parse(await readFile(await contained(project.root, path), 'utf8')); } catch (error) { if (error instanceof RerError) throw error; throw invalid(`Malformed ${path}.`); } };
60
+ const app = await read(project.adapter.deploy?.declaration ?? 'deploy.json'), declaration = await read(site.declaration);
61
+ const { sitePlan } = await import('../modules/deploy-kit/site.mjs');
62
+ try { return sitePlan({ project: app.project, environment, compatibilityDate: app.compatibilityDate, declaration, assets: folder }); }
63
+ catch (error) { throw invalid(`The run site deploy declaration is invalid (${error.message}). ${site.declaration} holds {"version": 1, "domain": "<apex hostname>"}.`); }
64
+ }
65
+
66
+ /** `rer build --site` and `rer deploy --site [--dry-run]`. */
67
+ export async function siteCommand(project, options, store, signal, out) {
68
+ const built = await buildSite(project, store, signal);
69
+ if (options.verb === 'build') {
70
+ // Output redaction masks an inherited PWD (a credential-shaped name), so the
71
+ // checkout-relative folder is named too.
72
+ const path = relative(project.root, built.folder);
73
+ if (!options.json) out.human(`Run site written to ${path} (${built.pages} pages, ${built.files} files): ${built.folder}`);
74
+ return { site: { folder: built.folder, path, pages: built.pages, files: built.files } };
75
+ }
76
+ const plan = await siteDeployment(project, options, built.folder);
77
+ const human = [`Run site plan: site Worker ${plan.worker}, Base-generated, its only binding the assets (the app's Worker ${plan.appWorker} is not touched)`, ` assets: ${plan.assets} (${built.files} files; HTML ${plan.assetsConfig.html_handling}, not found ${plan.assetsConfig.not_found_handling}; the Worker runs first)`,
78
+ ` custom domains: ${plan.hostnames.join(', ')}; workers.dev off`, ...plan.redirects.map(rule => ` redirect in the Worker: ${rule.from} -> ${rule.to} (${rule.status}, keeps ${rule.keeps.join(' and ')})`)];
79
+ const summary = { worker: plan.worker, appWorker: plan.appWorker, module: plan.module, bindings: plan.bindings, assets: plan.assets, files: built.files, domain: plan.domain, hostnames: plan.hostnames, workersDev: false, runWorkerFirst: true, assetsConfig: plan.assetsConfig, redirects: plan.redirects.map(({ from, to, status }) => ({ from, to, status })) };
80
+ if (options.dryRun) {
81
+ if (options.json) out.event('site', summary); else for (const line of human) out.human(line);
82
+ store.report('deploy --site: dry run complete; no deployment occurred and no provider request was made.');
83
+ return { dryRun: true, deployed: false, site: summary };
84
+ }
85
+ const names = ['CLOUDFLARE_ACCOUNT_ID', 'CLOUDFLARE_API_TOKEN'];
86
+ if (names.some(name => !process.env[name]?.trim())) throw missing('CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN are required, with the run site token permissions in the deploy-kit README.');
87
+ if (!options.json) for (const line of human) out.human(line);
88
+ const { cloudflare } = await import('../modules/deploy-kit/provider.mjs');
89
+ const { collectFiles } = await import('../modules/deploy-kit/artifact.mjs');
90
+ const { siteDeploy } = await import('../modules/deploy-kit/site.mjs');
91
+ const environment = options.environment ?? 'production';
92
+ try {
93
+ const api = cloudflare({ accountId: process.env.CLOUDFLARE_ACCOUNT_ID, token: process.env.CLOUDFLARE_API_TOKEN });
94
+ // The receipt is for the person; ownership is read from the provider, so a fresh checkout deploys too.
95
+ const result = await siteDeploy({ api, plan, files: await collectFiles(built.folder), receiptPath: join(project.root, '.rer', 'deploy', `site-${environment}.json`) });
96
+ return { dryRun: false, deployed: true, origin: result.origin, site: summary };
97
+ } catch (error) {
98
+ if (error instanceof RerError) throw error;
99
+ throw new RerError('deploy_refused', `Run site deploy stopped: ${/^[a-z0-9-]{1,80}$/.test(error.message) ? error.message : 'site-deploy-failed'}${error.resource ? ` (${error.resource})` : ''}.`, 1);
100
+ }
101
+ }
102
+
103
+ /** For rer dev: build the run site and serve it on the first free port above the app's. */
104
+ export async function devSite(project, store, signal, { host, port }) {
105
+ const built = await buildSite(project, store, signal);
106
+ const { sitePreview } = await import('./site-preview.mjs');
107
+ return { ...await sitePreview(built.folder, { host, ports: Array.from({ length: 50 }, (_, index) => port + 1 + index).filter(value => value <= 65535) }), folder: relative(project.root, built.folder) };
108
+ }
109
+
@@ -0,0 +1,63 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0
4
+
5
+ What changes for a user since 0.1.1.
6
+
7
+ ### Package mode
8
+
9
+ - A first-party seed pins `@runeditrun/rer` as an exact devDependency instead of
10
+ carrying `scripts/rer.mjs`, `scripts/base-cli` and `scripts/base-onboarding`.
11
+ `node scripts/export-cli.mjs --to-package SEED_ROOT [--version X]` converts a
12
+ vendored seed (it refuses local edits and lists them).
13
+ - `rer check` and `rer describe` in a checkout whose `node_modules` lacks its
14
+ pin install it with the frozen lockfile first, then run the pinned verb, so a
15
+ fresh clone checks with the pinned bytes. `rer check --profile first-party`
16
+ accepts package mode (SC-13) and still accepts vendored mode.
17
+ - Named exports for every Base file a seed's adapter, Vite config, build or
18
+ package script imports; nothing needs `internal/`.
19
+
20
+ ### Lobby, homepage variants, setup state
21
+
22
+ - The Lobby (the pre-claim page) and `GET /setup/state`; a seed supplies its own
23
+ first-run read, and the fonts stylesheet its edition names.
24
+ - Homepage variants and a hydration check that follows a redirecting `/`, counts
25
+ cross-origin client scripts and fails an edit case React hydrated too early to test.
26
+
27
+ ### Run sites
28
+
29
+ - `rer build --site` builds the seed's run site (with its own Vite config and
30
+ CSS) and `rer deploy --site` deploys it. Ownership is proven from the provider
31
+ alone (the latest deployment serves the newest version, which carries the
32
+ kit's annotation), so a fresh CI checkout redeploys; a foreign Worker or
33
+ domain is refused.
34
+ - The site Worker is Base-generated: `www.<domain>` answers a 301 to the apex
35
+ (path and query kept) and everything else comes from assets. No zone ruleset
36
+ is read or written.
37
+ - The publication scan accepts the run-NAME repository names the owner
38
+ proposed (for example run-lamp under the just-every account) as intended
39
+ public destinations; the earlier names stay valid.
40
+
41
+ ### Local development hardening
42
+
43
+ - A request with a foreign `Host` gets a plain 421; keyless `/@fs` and any
44
+ path Vite would answer with its 403 "Restricted" page (which lists checkout
45
+ and home paths) get 404. The dev key opens them.
46
+ - `rer` fetches the pinned pnpm from the npm registry, checked against its
47
+ integrity hash, when PATH lacks it.
48
+ - An explicit `RER_SERVER_LIMIT` caps its own start, higher or lower.
49
+ - `rer door`: keys never go through the door, a moved checkout keeps its name,
50
+ a restart hands starts over, a missing folder is a plain page.
51
+
52
+ ### Hosted output
53
+
54
+ - Built `.html` files are served by the hosted Worker (`staticAssetResponse`),
55
+ including revalidation (`If-None-Match` answers 304). The hosted check
56
+ requests every built file and sends one conditional request per `.html`.
57
+ - A deploy secret may carry `verifyStandIn` for the hosted check.
58
+ - Packed deploy assets leave out `.assetsignore` and what it names.
59
+
60
+ ### Fixes
61
+
62
+ - Setup reads the seed's declared settings format and session-secret name.
63
+ - Large stores export, and a fresh install recovers a legacy backup.
package/global/README.md CHANGED
@@ -97,6 +97,10 @@ RER_OPEN http://127.0.0.1:8787/__dev/key#...
97
97
  ```
98
98
 
99
99
  or `RER_SIGN_IN <outbox>` for a seed that signs in through its development outbox.
100
+ A seed that declares a run site prints one more line after those,
101
+ `RER_SITE http://127.0.0.1:8788`: a local preview of its static run site (its
102
+ marketing homepage, `/run` and docs) on the first free port above the app's. It
103
+ stops with the app.
100
104
  It never prompts and never re-runs setup on a checkout that is already set up. A
101
105
  setup a launch started that was stopped or failed is run again by the next
102
106
  `rer dev`, keeping the owner and origin it saved, unless a setup has finished
@@ -130,6 +134,27 @@ checkout never records a limit you did not set.
130
134
  A start is never refused for machine load alone unless `RER_SERVERS_LOAD_THRESHOLD`
131
135
  or `RER_JOBS_LOAD_THRESHOLD` is set; memory and disk guards stay.
132
136
 
137
+ ## The front door
138
+
139
+ ```sh
140
+ rer door enable # opt this computer in: port 8700, 10 servers, 12 hours idle
141
+ rer door add ~/review/* # register checkouts; prints each http://NAME.localhost:8700
142
+ rer door status --links # every checkout, its state, and sign-in links
143
+ ```
144
+
145
+ One process on one port serves every registered checkout at
146
+ `http://NAME.localhost:PORT` (NAME is its folder name, unique and stable);
147
+ `http://localhost:PORT` lists them. A stopped checkout starts when you open it
148
+ in a browser and stops when idle; subresources, API calls and WebSockets never
149
+ start one. `rer door enable` stores the policy (`--port`, `--server-limit`,
150
+ `--idle-timeout`) and the `RER_*` variables in effect, so whoever later starts
151
+ the door cannot change what its checkouts run with. While it is enabled, `rer
152
+ dev` sets fresh checkouts up behind it; `rer dev --door` moves an existing one
153
+ (keeping its data), `rer dev --direct` moves it back, and `--port N` always
154
+ serves directly. `rer door start`, `stop`, `restart`, `disable` and `remove
155
+ NAME` do what they say; after a reboot or logout the door needs `rer door
156
+ start`. `rer door --help` has the details.
157
+
133
158
  ## Find what to launch
134
159
 
135
160
  ```sh
@@ -144,6 +169,91 @@ Independent projects (an `OPERATIONS.json` version 2 without a seed contract) ru
144
169
  their declared commands with `rer <verb> [-- args]`; zero-setup launching does not
145
170
  apply to them. `OPERATIONS.json` version 1 is not supported.
146
171
 
172
+ ## Package mode: a checkout that pins `@runeditrun/rer`
173
+
174
+ A checkout runs one of two copies of rer. In **vendored mode** it carries
175
+ `scripts/rer.mjs`, `scripts/base-cli` and `scripts/base-onboarding`, and `rer`
176
+ runs that copy. In **package mode** it carries none of them and pins this package
177
+ as an exact devDependency instead (`"@runeditrun/rer": "0.2.0"`, locked in
178
+ `pnpm-lock.yaml`): its `OPERATIONS.json` argv and package scripts are `rer VERB`,
179
+ which inside `pnpm run` is the pinned copy in `node_modules/.bin`, so
180
+ `pnpm install --frozen-lockfile && pnpm run build` needs no global `rer`. A global
181
+ `rer` hands every verb to the pinned package, launching included. Until
182
+ `node_modules` holds the pinned version, `rer install` and `rer dev` install it
183
+ first (the frozen `pnpm install`) and every other verb says to run `rer install`.
184
+
185
+ Heavy package scripts wait for this computer's job queue with
186
+ `rer queue NAME -- COMMAND [ARGS]` (in vendored mode,
187
+ `node scripts/base-onboarding/queued-entry.mjs NAME -- COMMAND`).
188
+
189
+ `rer check --profile first-party` accepts either mode. In package mode it asks for
190
+ the exact devDependency (`SC-13.package.pin`), its lockfile entry
191
+ (`SC-13.package.lockfile`), no vendored copy (`SC-13.package.vendored.*`) and `rer
192
+ VERB` targets and aliases (`SC-02.target.*`, `SC-02.alias.*`); in vendored mode for
193
+ the copy and its recorded inventory, as before.
194
+
195
+ Convert a vendored seed from a Base checkout with
196
+
197
+ ```sh
198
+ node scripts/export-cli.mjs --to-package SEED_ROOT [--version X]
199
+ ```
200
+
201
+ (the default version is the latest published one, read with the seed's own npm
202
+ configuration). It refuses, listing them, when the vendored copy differs from its
203
+ recorded inventory: carry those edits with `pnpm patch @runeditrun/rer` once
204
+ converted, or upstream them to Base. Otherwise it pins and locks the package
205
+ (`pnpm install --lockfile-only`), rewrites imports into the copy to the exports
206
+ below (anything else to `@runeditrun/rer/internal/PATH`, which promises nothing
207
+ beyond the pinned version), rewrites the package scripts and `OPERATIONS.json`
208
+ argv to `rer VERB` and the delivery operations (`rer-project.json` and the
209
+ `scripts/delivery/base/packaging.json` it is generated from), the shell scripts
210
+ they and CI workflows run, and workflow lines to `pnpm exec rer VERB` (a frozen
211
+ `pnpm install` first where nothing has installed yet), drops the copy's own records from `base-copies.json` (the
212
+ app-runtime copies it records stay as they are), removes the copy and lists every
213
+ line that still names it. A later refresh is a version bump:
214
+ `pnpm add -D -E @runeditrun/rer@X`.
215
+
216
+ ### Exports
217
+
218
+ | Import | What it gives | Vendored path it replaces |
219
+ | --- | --- | --- |
220
+ | `@runeditrun/rer/adapter` | `commandAdapter` | `scripts/base-cli/cli/adapter.mjs` |
221
+ | `@runeditrun/rer/deploy` | `ownerDeploy` | `scripts/base-cli/cli/deploy.mjs` |
222
+ | `@runeditrun/rer/portability` | `localPortability` | `scripts/base-cli/cli/portability.mjs` |
223
+ | `@runeditrun/rer/errors` | the CLI's error helpers | `scripts/base-cli/cli/errors.mjs` |
224
+ | `@runeditrun/rer/jsonc` | JSONC reading | `scripts/base-cli/cli/jsonc.mjs` |
225
+ | `@runeditrun/rer/parse`, `/scheduled` | CLI argument parsing, scheduled-job helpers | `scripts/base-cli/cli/parse.mjs`, `scheduled.mjs` |
226
+ | `@runeditrun/rer/dev-identity` | dev identity helpers | `scripts/base-cli/cli/dev-identity.mjs` |
227
+ | `@runeditrun/rer/operator-installer` | `operatorInstaller`, `developmentTarget`, `previewTarget` | `scripts/base-onboarding/operator-installer.mjs` |
228
+ | `@runeditrun/rer/local-installer` | `localInstaller` | `scripts/base-onboarding/adapter.mjs` |
229
+ | `@runeditrun/rer/operator-install` | `installOperator` | `scripts/base-onboarding/operator-install.mjs` |
230
+ | `@runeditrun/rer/operator-prerequisites` | `operatorPrerequisites` | `scripts/base-onboarding/operator-prerequisites.mjs` |
231
+ | `@runeditrun/rer/local/state` | `selectLocalState` | `scripts/base-onboarding/local/state.mjs` |
232
+ | `@runeditrun/rer/local/build` | local build step | `scripts/base-onboarding/local/build.mjs` |
233
+ | `@runeditrun/rer/state`, `/commands` | onboarding state and command runners | `scripts/base-onboarding/state.mjs`, `commands.mjs` |
234
+ | `@runeditrun/rer/local/environment`, `/local/files`, `/local/operation`, `/local/recovery` | local setup helpers | `scripts/base-onboarding/local/*.mjs` |
235
+ | `@runeditrun/rer/private-files` | private file helpers | `scripts/base-onboarding/private-files.mjs` |
236
+ | `@runeditrun/rer/adapter-settings` | adapter settings helpers | `scripts/base-onboarding/adapter-settings.mjs` |
237
+ | `@runeditrun/rer/adapter-auth`, `/adapter-hosting` | adapter auth and hosting helpers | `scripts/base-onboarding/adapter-auth.mjs`, `adapter-hosting.mjs` |
238
+ | `@runeditrun/rer/process-diagnostics` | process diagnostics | `scripts/base-onboarding/process-diagnostics.mjs` |
239
+ | `@runeditrun/rer/process-cleanup`, `/process-scope` | process cleanup and scope | `scripts/base-onboarding/process-cleanup.mjs`, `process-scope.mjs` |
240
+ | `@runeditrun/rer/failures`, `/redaction` | failure and redaction helpers | `scripts/base-onboarding/failures.mjs`, `redaction.mjs` |
241
+ | `@runeditrun/rer/setup-manifest`, `/setup-schema` | setup manifest loading and its JSON schema | `scripts/base-onboarding/setup-manifest.mjs`, `schema/SETUP.schema.json` |
242
+ | `@runeditrun/rer/production-runtime`, `/production-modules` | production runtime helpers | `scripts/base-onboarding/production-runtime.mjs`, `production-modules.mjs` |
243
+ | `@runeditrun/rer/queued-entry` | the job-queue entry | `scripts/base-onboarding/queued-entry.mjs` |
244
+ | `@runeditrun/rer/archive-output` | `archiveOutputGuard` (with types) | `scripts/base-onboarding/archive-output.mjs` |
245
+ | `@runeditrun/rer/launcher` | the browser installer launcher | `scripts/base-onboarding/launcher.mjs` |
246
+ | `@runeditrun/rer/installer-server` | the browser installer's server (installer journeys) | `scripts/base-onboarding/server.mjs` |
247
+ | `@runeditrun/rer/server-resources` | managed server resource readings (runtime journeys) | `scripts/base-cli/cli/server-resources.mjs` |
248
+ | `@runeditrun/rer/operations` | OPERATIONS describe and check | `scripts/base-cli/operations/operations.mjs` |
249
+ | `@runeditrun/rer/modules/portability`, `/catalogue`, `/cli`, `/cli-options`, `/files`, `/format`, `/http`, `/import`, `/journal`, `/legacy-safety`, `/migration-history`, `/storage` | portability module | `scripts/base-cli/modules/portability/*.mjs` |
250
+ | `@runeditrun/rer/modules/release/export`, `/publication-scan`, `/source` | release export and publication scan | `scripts/base-cli/modules/release/*.mjs` |
251
+ | `@runeditrun/rer/modules/deploy-kit/owner`, `/owner-cli`, `/prepare`, `/provider` | deploy kit | `scripts/base-cli/modules/deploy-kit/*.mjs` |
252
+ | `@runeditrun/rer/modules/operator-auth`, `/dev`, `/dev/badge`, `/dev-admission`, `/accounts/native`, `/identity/email-link` | operator auth | `scripts/base-cli/modules/operator-auth/index.mjs`, `dev/index.mjs`, `dev/badge.mjs`, `dev-admission.mjs`, `accounts/native.mjs`, `identity/email-link/index.mjs` |
253
+ | `@runeditrun/rer/modules/erasure/fence` | erasure fence statements | `scripts/base-cli/modules/erasure/fence.mjs` |
254
+ | `@runeditrun/rer/modules/owner-claim`, `/modules/dependencies` | owner claim, dependency links | `scripts/base-cli/modules/owner-claim/index.mjs`, `dependencies/index.mjs` |
255
+ | `@runeditrun/rer/internal/PATH` | any other package file, for tests | `scripts/base-cli/PATH`, and `scripts/base-onboarding/PATH` with PATH under `onboarding/` |
256
+
147
257
  ## Verbs
148
258
 
149
259
  In a checkout, every verb runs that checkout's own pinned `rer`; `rer VERB --help`
@@ -153,6 +263,6 @@ there lists its flags:
153
263
  `export`, `import`, `outbox`, `doctor`, `describe`, `check`, `release`.
154
264
 
155
265
  Anywhere: `rer list [DIR]`, `rer cli status|install|uninstall`, `rer update`,
156
- `rer --version` and `rer --help`.
266
+ `rer queue NAME -- COMMAND`, `rer --version` and `rer --help`.
157
267
 
158
268
  Licence: MIT.
@@ -2,6 +2,7 @@
2
2
  // above the working directory, or exactly --cwd DIR. Then pick whose code runs it.
3
3
  import { existsSync, readFileSync, realpathSync, statSync } from 'node:fs';
4
4
  import { dirname, join, resolve } from 'node:path';
5
+ import { exactVersion } from '../cli/package-mode.mjs';
5
6
  import { ownRoot, packageName } from './package-info.mjs';
6
7
 
7
8
  // The value of --cwd among the wrapper flags (never after a -- separator).
@@ -53,19 +54,32 @@ export function unsupportedMessage(root, version) {
53
54
  return `${join(root, 'OPERATIONS.json')} is an OPERATIONS version ${version ?? '(none)'} descriptor, which rer does not run. Use the commands that project documents, or move it to OPERATIONS version 2.`;
54
55
  }
55
56
 
56
- function declaresPackage(root) {
57
- try {
58
- const manifest = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'));
59
- return Boolean(manifest.dependencies?.[packageName] ?? manifest.devDependencies?.[packageName]);
60
- } catch { return false; }
57
+ // The rer package a checkout pins in package.json (package mode): the declared
58
+ // specifier, the version node_modules holds, and whether that installed copy is
59
+ // the one to run (`ready`: present, and equal to an exact pin). undefined for a
60
+ // checkout that does not declare it.
61
+ export function pinnedPackage(root) {
62
+ let manifest;
63
+ try { manifest = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')); } catch { return undefined; }
64
+ const declared = manifest.devDependencies?.[packageName] ?? manifest.dependencies?.[packageName];
65
+ if (!declared) return undefined;
66
+ let installed;
67
+ try { installed = JSON.parse(readFileSync(join(root, 'node_modules', packageName, 'package.json'), 'utf8')).version; } catch {}
68
+ return { declared, installed, ready: installed !== undefined && (installed === declared || !exactVersion.test(declared)) };
61
69
  }
62
70
 
63
- // 1. the checkout's own pinned package, 2. its vendored scripts/rer.mjs,
64
- // 3. this package's bundled dispatcher.
71
+ // What runs a checkout's verbs: `entry` is the dispatcher (the verbs
72
+ // themselves) and, for a pinned package, `launcher` is its own rer command.
73
+ // 1. the checkout's own pinned package, once node_modules holds the version
74
+ // package.json pins (see pinnedPackage), 2. its vendored scripts/rer.mjs, 3. this package's
75
+ // bundled dispatcher.
65
76
  export function dispatcher(root) {
66
- if (root && declaresPackage(root)) {
67
- const pinned = join(root, 'node_modules', packageName);
68
- if (existsSync(join(pinned, 'global/rer.mjs')) && realpathSync(pinned) !== ownRoot) return { mode: 'package', entry: join(realpathSync(pinned), 'global/rer.mjs') };
77
+ const pinned = root ? pinnedPackage(root) : undefined;
78
+ if (pinned?.ready) {
79
+ const location = realpathSync(join(root, 'node_modules', packageName));
80
+ // This package is that pin: it runs the checkout itself, whatever else the checkout holds.
81
+ if (location === ownRoot) return { mode: 'bundled', entry: join(ownRoot, 'bin/rer.mjs') };
82
+ if (existsSync(join(location, 'global/rer.mjs'))) return { mode: 'package', entry: join(location, 'bin/rer.mjs'), launcher: join(location, 'global/rer.mjs') };
69
83
  }
70
84
  if (root && existsSync(join(root, 'scripts/rer.mjs'))) return { mode: 'vendored', entry: join(root, 'scripts/rer.mjs') };
71
85
  return { mode: 'bundled', entry: join(ownRoot, 'bin/rer.mjs') };
@@ -2,10 +2,11 @@
2
2
  // version directory, switch `current` atomically, keep the previous version,
3
3
  // prune older ones and write the launcher. Never edits shell profiles.
4
4
  import { randomUUID } from 'node:crypto';
5
- import { chmod, cp, mkdir, readdir, readlink, rename, rm, symlink, writeFile } from 'node:fs/promises';
5
+ import { chmod, cp, mkdir, readdir, readlink, realpath, rename, rm, symlink, writeFile } from 'node:fs/promises';
6
6
  import { basename, join, resolve } from 'node:path';
7
7
  import { ownManifest, ownRoot, packageDigest, packageFileList } from '../package-info.mjs';
8
8
  import { installRecord, launcherOwner, launcherScript, layout } from './layout.mjs';
9
+ import { runningDoor } from '../../cli/door.mjs';
9
10
 
10
11
  async function readLink(path) { try { return await readlink(path); } catch (error) { if (['ENOENT', 'EINVAL'].includes(error.code)) return undefined; throw error; } }
11
12
 
@@ -66,7 +67,10 @@ export async function install() {
66
67
  if (!present) { await rm(join(paths.versions, name), { recursive: true, force: true }); await copyVersion(paths, name); }
67
68
  const previousName = current?.startsWith('versions/') && current !== join('versions', name) ? current.slice('versions/'.length) : record?.previous;
68
69
  if (current !== join('versions', name)) await switchCurrent(paths, name);
69
- const keep = new Set([name, previousName].filter(Boolean));
70
+ // A running front door keeps running from its own version: never prune it.
71
+ const door = await runningDoor().catch(() => undefined);
72
+ const doorVersion = door?.versionDir && resolve(door.versionDir, '..') === await realpath(paths.versions).catch(() => resolve(paths.versions)) ? basename(door.versionDir) : undefined;
73
+ const keep = new Set([name, previousName, doorVersion].filter(Boolean));
70
74
  for (const entry of await readdir(paths.versions)) if (!keep.has(entry) && !entry.startsWith('.staging-')) await rm(join(paths.versions, entry), { recursive: true, force: true });
71
75
  await writeFile(paths.record, JSON.stringify({ channel, previous: previousName && keep.has(previousName) ? previousName : null }, null, 2) + '\n', { mode: 0o644 });
72
76
  if (launcher.text !== script) await writeLauncher(paths);
@@ -1,13 +1,15 @@
1
- // Run an invocation with the checkout's own dispatcher, in this process, exactly
2
- // as `node scripts/rer.mjs ...` would from the project root: process.argv[1] is
3
- // that file, so its Node-pin re-exec and queued child spawns behave as they do
4
- // when it is run directly. The dispatcher sets process.exitCode itself.
1
+ // Run an invocation with the checkout's own rer, in this process. A pinned
2
+ // package runs it with its own rer command, so launching is its own too. A
3
+ // vendored or bundled dispatcher runs it exactly as `node scripts/rer.mjs ...`
4
+ // would from the project root: process.argv[1] is that file, so its Node-pin
5
+ // re-exec and queued child spawns behave as they do when it is run directly.
6
+ // The dispatcher sets process.exitCode itself.
5
7
  import { pathToFileURL } from 'node:url';
6
8
  import { dispatcher } from './checkout.mjs';
7
9
 
8
10
  export async function delegate(target, args) {
9
- const { entry } = dispatcher(target.root);
11
+ const { entry, launcher } = dispatcher(target.root);
10
12
  if (target.root) process.chdir(target.root);
11
- process.argv = [process.argv[0], entry, ...args];
12
- await import(pathToFileURL(entry).href);
13
+ process.argv = [process.argv[0], launcher ?? entry, ...args];
14
+ await import(pathToFileURL(launcher ?? entry).href);
13
15
  }