@runeditrun/rer 0.2.84 → 0.2.86

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 (236) hide show
  1. package/README.md +156 -50
  2. package/cli/README.md +78 -2
  3. package/cli/agent-door.mjs +149 -0
  4. package/cli/agent-fixtures.mjs +16 -0
  5. package/cli/agent-mail.mjs +54 -0
  6. package/cli/agent-network.mjs +64 -0
  7. package/cli/agent-reviewers.mjs +110 -0
  8. package/cli/agent-secrets.mjs +23 -0
  9. package/cli/agent-sponsors.mjs +43 -0
  10. package/cli/agent-surface.mjs +34 -0
  11. package/cli/agent-webhooks.mjs +19 -0
  12. package/cli/authoring.mjs +2 -1
  13. package/cli/bounded.mjs +1 -1
  14. package/cli/business/archive-task.mjs +32 -0
  15. package/cli/business/carry.mjs +151 -0
  16. package/cli/business/catchup-task.mjs +42 -0
  17. package/cli/business/choices.mjs +97 -0
  18. package/cli/business/command.mjs +29 -6
  19. package/cli/business/connect.mjs +20 -8
  20. package/cli/business/detector.mjs +4 -1
  21. package/cli/business/device.mjs +13 -0
  22. package/cli/business/export-inputs.mjs +69 -0
  23. package/cli/business/export-task.mjs +17 -0
  24. package/cli/business/invocation.mjs +8 -1
  25. package/cli/business/keychain.mjs +8 -1
  26. package/cli/business/lease.mjs +11 -1
  27. package/cli/business/local-commands.mjs +80 -30
  28. package/cli/business/outbound.mjs +9 -4
  29. package/cli/business/parsers-config.mjs +8 -7
  30. package/cli/business/parsers-syntax.mjs +7 -3
  31. package/cli/business/permissions.mjs +2 -0
  32. package/cli/business/questions.mjs +89 -6
  33. package/cli/business/setup-command.mjs +49 -0
  34. package/cli/business/setup-company.json +15 -0
  35. package/cli/business/setup-demo.mjs +95 -0
  36. package/cli/business/state.mjs +44 -10
  37. package/cli/business/supervisor.mjs +97 -32
  38. package/cli/business/vendor-door.mjs +230 -0
  39. package/cli/business/vendors/README.md +29 -3
  40. package/cli/business/vendors/common.mjs +8 -6
  41. package/cli/business/vendors/index.mjs +22 -11
  42. package/cli/business/vendors/sorry.mjs +106 -0
  43. package/cli/container-transfer.mjs +2 -2
  44. package/cli/contract.mjs +7 -7
  45. package/cli/demo-deploy-error.mjs +14 -0
  46. package/cli/demo-native.mjs +6 -2
  47. package/cli/deploy-command.mjs +6 -4
  48. package/cli/deploy-config.mjs +1 -1
  49. package/cli/deploy-owner-input.mjs +3 -1
  50. package/cli/deploy-variables.mjs +58 -0
  51. package/cli/deploy.mjs +9 -7
  52. package/cli/door-clauses.mjs +157 -0
  53. package/cli/errors.mjs +1 -1
  54. package/cli/export.mjs +16 -4
  55. package/cli/hosted-output.mjs +17 -7
  56. package/cli/human-error.mjs +20 -0
  57. package/cli/inspect.mjs +4 -0
  58. package/cli/jsonc.mjs +8 -4
  59. package/cli/lifecycle.mjs +26 -6
  60. package/cli/main.mjs +2 -1
  61. package/cli/managed-data-schema.mjs +127 -0
  62. package/cli/managed-data-zip.mjs +116 -0
  63. package/cli/managed-data.mjs +110 -0
  64. package/cli/managed-server.mjs +25 -14
  65. package/cli/native-owner-entry.mjs +86 -0
  66. package/cli/output.mjs +3 -2
  67. package/cli/parse.mjs +2 -2
  68. package/cli/portability-empty.mjs +65 -0
  69. package/cli/portability-migrations.mjs +33 -9
  70. package/cli/portability-policy.mjs +5 -2
  71. package/cli/portability-worker.mjs +15 -6
  72. package/cli/portability.mjs +30 -8
  73. package/cli/production-auth.mjs +1 -1
  74. package/cli/production-mail.mjs +8 -2
  75. package/cli/ready-summary.mjs +9 -0
  76. package/cli/run-transfers.mjs +37 -0
  77. package/cli/runtime-front-door.mjs +4 -4
  78. package/cli/server-proxy.mjs +4 -3
  79. package/cli/server-registry.mjs +13 -8
  80. package/cli/site.mjs +6 -1
  81. package/cli/transfers.mjs +17 -4
  82. package/edition-authoring/archive-source.mjs +59 -0
  83. package/edition-authoring/base-copies.mjs +147 -25
  84. package/edition-authoring/cli.mjs +1 -1
  85. package/edition-authoring/edition-migrations.mjs +7 -3
  86. package/edition-authoring/module-closure.mjs +2 -16
  87. package/edition-authoring/workflow-copies.mjs +1 -1
  88. package/edition-authoring/workflow-scripts.mjs +12 -3
  89. package/foundation/runtime/contract-docs.mjs +218 -34
  90. package/foundation/runtime/contract-prose-patterns.mjs +14 -0
  91. package/foundation/runtime/contract-prose.mjs +88 -0
  92. package/foundation/runtime/run-data.d.mts +1 -0
  93. package/foundation/runtime/run-data.mjs +2 -0
  94. package/global/CHANGELOG.md +126 -0
  95. package/global/README.md +156 -50
  96. package/global/cli/command.mjs +8 -2
  97. package/global/cli/install.mjs +4 -5
  98. package/global/cli/path-link.mjs +3 -2
  99. package/global/cli/repo-command.mjs +3 -7
  100. package/global/door/command.mjs +3 -1
  101. package/global/launch/dev.mjs +12 -2
  102. package/global/launch/facts.mjs +2 -2
  103. package/global/launch/render.mjs +16 -9
  104. package/global/launch/state.mjs +4 -4
  105. package/global/main.mjs +13 -8
  106. package/install.sh +17 -6
  107. package/modules/agent-door/CLAUSES.md +215 -0
  108. package/modules/agent-door/conformance/audit.mjs +66 -0
  109. package/modules/agent-door/conformance/authority.d.mts +2 -0
  110. package/modules/agent-door/conformance/authority.mjs +17 -0
  111. package/modules/agent-door/conformance/crypto.mjs +36 -0
  112. package/modules/agent-door/conformance/discovery.mjs +61 -0
  113. package/modules/agent-door/conformance/index.mjs +41 -0
  114. package/modules/agent-door/conformance/invocation.mjs +32 -0
  115. package/modules/agent-door/conformance/journey.mjs +112 -0
  116. package/modules/agent-door/conformance/narrowing.d.mts +1 -0
  117. package/modules/agent-door/conformance/narrowing.mjs +21 -0
  118. package/modules/agent-door/conformance/negative.mjs +47 -0
  119. package/modules/agent-door/conformance/network-modules.mjs +86 -0
  120. package/modules/agent-door/conformance/network-runtime.mjs +46 -0
  121. package/modules/agent-door/conformance/policy-phases.mjs +75 -0
  122. package/modules/agent-door/conformance/protocol.mjs +145 -0
  123. package/modules/agent-door/conformance/replay.mjs +38 -0
  124. package/modules/agent-door/conformance/schema.mjs +71 -0
  125. package/modules/agent-door/conformance/security.mjs +33 -0
  126. package/modules/agent-door/conformance/sponsors.mjs +68 -0
  127. package/modules/agent-door/conformance/surface.mjs +89 -0
  128. package/modules/agent-door/conformance/target.mjs +18 -0
  129. package/modules/agent-door/conformance/tool-name.d.mts +1 -0
  130. package/modules/agent-door/conformance/tool-name.mjs +7 -0
  131. package/modules/agent-door/conformance/webhooks.mjs +30 -0
  132. package/modules/container/README.md +6 -1
  133. package/modules/container/adapters/d1-limits.mjs +286 -0
  134. package/modules/container/adapters/d1-sqlite.mjs +95 -0
  135. package/modules/container/adapters/d1-workerd-preload.mjs +19 -0
  136. package/modules/container/adapters/d1-workerd-setup.mjs +26 -0
  137. package/modules/container/adapters/d1-workerd.mjs +5 -0
  138. package/modules/container/adapters/sqlite-worker.mjs +5 -3
  139. package/modules/container/build.mjs +1 -0
  140. package/modules/container/image-variables.mjs +14 -3
  141. package/modules/container/transfer.mjs +14 -4
  142. package/modules/container/worker-engine.mjs +3 -3
  143. package/modules/demo-host/README.md +6 -0
  144. package/modules/demo-host/build.mjs +1 -0
  145. package/modules/demo-host/native/prepare.mjs +2 -1
  146. package/modules/demo-host/native/sql.mjs +7 -2
  147. package/modules/demo-host/ownership.mjs +39 -0
  148. package/modules/demo-host/plan.mjs +2 -1
  149. package/modules/demo-host/remove.mjs +6 -1
  150. package/modules/deploy-kit/README.md +22 -2
  151. package/modules/deploy-kit/d1-import-diagnostics.mjs +56 -0
  152. package/modules/deploy-kit/d1-import.mjs +17 -5
  153. package/modules/deploy-kit/diagnostics.mjs +29 -3
  154. package/modules/deploy-kit/owner-cli.mjs +20 -7
  155. package/modules/deploy-kit/provider-transport.mjs +19 -4
  156. package/modules/deploy-kit/provider.mjs +57 -22
  157. package/modules/deploy-kit/readiness-window.mjs +1 -1
  158. package/modules/deploy-kit/site.mjs +8 -3
  159. package/modules/deploy-kit/worker.mjs +4 -4
  160. package/modules/import-kit/schema/importer-verification-receipt.schema.json +171 -0
  161. package/modules/import-kit/schema/importers.schema.json +107 -0
  162. package/modules/import-kit/src/d1/README.md +23 -4
  163. package/modules/import-kit/src/d1/atomic-prefix.ts +2 -2
  164. package/modules/import-kit/src/d1/budget.ts +15 -7
  165. package/modules/import-kit/src/d1/column-layout.ts +5 -0
  166. package/modules/import-kit/src/d1/creation.ts +15 -8
  167. package/modules/import-kit/src/d1/database.ts +3 -3
  168. package/modules/import-kit/src/d1/erasure-pages.ts +2 -1
  169. package/modules/import-kit/src/d1/erasure.ts +2 -2
  170. package/modules/import-kit/src/d1/jobs.ts +10 -6
  171. package/modules/import-kit/src/d1/plans.ts +14 -8
  172. package/modules/import-kit/src/d1/retirement.ts +2 -2
  173. package/modules/import-kit/src/d1/sets.ts +1 -3
  174. package/modules/import-kit/src/d1/staged-creation.ts +3 -3
  175. package/modules/import-kit/src/door/ADOPTING.md +20 -0
  176. package/modules/import-kit/src/door/README.md +2 -1
  177. package/modules/import-kit/src/door/admission.ts +5 -3
  178. package/modules/import-kit/src/door/archive.ts +5 -2
  179. package/modules/import-kit/src/door/authority.ts +1 -0
  180. package/modules/import-kit/src/door/grants.ts +1 -1
  181. package/modules/import-kit/src/door/handler.ts +14 -8
  182. package/modules/import-kit/src/door/index.ts +1 -1
  183. package/modules/import-kit/src/door/jobs.ts +40 -0
  184. package/modules/import-kit/src/door/limits.ts +1 -1
  185. package/modules/import-kit/src/door/operator.ts +3 -3
  186. package/modules/import-kit/src/door/planning.ts +10 -6
  187. package/modules/import-kit/src/door/protocol.ts +2 -2
  188. package/modules/import-kit/src/door/raw.ts +25 -0
  189. package/modules/import-kit/src/door/refusals.ts +2 -1
  190. package/modules/import-kit/src/door/types.ts +26 -6
  191. package/modules/import-kit/src/receipt/encoding.ts +37 -0
  192. package/modules/import-kit/src/receipt/index.ts +69 -0
  193. package/modules/import-kit/src/receipt/policy.ts +24 -0
  194. package/modules/import-kit/src/receipt/types.ts +64 -0
  195. package/modules/import-kit/src/receipt/uri.ts +45 -0
  196. package/modules/import-kit/src/receipt/validation.ts +87 -0
  197. package/modules/import-kit/src/status/encoding.ts +13 -0
  198. package/modules/import-kit/src/status/evidence.ts +218 -0
  199. package/modules/import-kit/src/status/index.ts +56 -0
  200. package/modules/import-kit/src/status/schema.ts +208 -0
  201. package/modules/import-kit/src/status/types.ts +86 -0
  202. package/modules/operator-auth/accounts/delegated.mjs +48 -0
  203. package/modules/operator-auth/index.d.mts +7 -0
  204. package/modules/operator-auth/service.mjs +2 -0
  205. package/modules/portability/README.md +138 -9
  206. package/modules/portability/backfills.mjs +9 -8
  207. package/modules/portability/bridge.mjs +32 -5
  208. package/modules/portability/catalogue.mjs +12 -5
  209. package/modules/portability/copies.mjs +8 -1
  210. package/modules/portability/derived.mjs +33 -0
  211. package/modules/portability/files.mjs +4 -3
  212. package/modules/portability/http-errors.mjs +1 -1
  213. package/modules/portability/http.mjs +3 -3
  214. package/modules/portability/import.mjs +29 -13
  215. package/modules/portability/index.d.mts +4 -3
  216. package/modules/portability/index.mjs +1 -1
  217. package/modules/portability/ledgers.mjs +3 -2
  218. package/modules/portability/legacy-safety.mjs +11 -2
  219. package/modules/portability/migration-history.mjs +2 -2
  220. package/modules/portability/progress.mjs +1 -0
  221. package/modules/portability/restore-empty.mjs +12 -0
  222. package/modules/release/github-verify.mjs +11 -2
  223. package/onboarding/adapter.mjs +35 -6
  224. package/onboarding/app-fetch.mjs +6 -4
  225. package/onboarding/development-runtime.mjs +19 -0
  226. package/onboarding/local/operation.mjs +45 -27
  227. package/onboarding/loopback-fetch.mjs +16 -0
  228. package/onboarding/operator-installer.mjs +2 -4
  229. package/onboarding/process-diagnostics.mjs +6 -2
  230. package/onboarding/production-runtime.mjs +4 -2
  231. package/onboarding/readiness.mjs +1 -0
  232. package/package.json +4 -2
  233. package/scripts/publish-check/copy_identities.py +3 -1
  234. package/scripts/publish-check/github_refs.py +32 -13
  235. package/scripts/publish-check/public_hygiene.py +1 -1
  236. package/cli/business/opt-ins.mjs +0 -33
@@ -7,23 +7,30 @@ import { fileRecords } from '../modules/portability/files.mjs';
7
7
  import { RerError, refuse } from './errors.mjs';
8
8
  import { policyModuleURL, serializablePolicy } from './portability-policy.mjs';
9
9
  import { shared } from './shared.mjs';
10
+ import { emptyNativePreflight } from './portability-empty.mjs';
11
+ import { withManagedDataImport } from './managed-data.mjs';
10
12
  import { ledgerRefusal } from './ledger-refusal.mjs';
11
13
 
14
+ export { withManagedDataImport };
15
+
12
16
  const reExport = 'Re-export from the original installation with rer export --output exports/recovered.rer (add --target remote for a hosted installation), then retry rer import --input exports/recovered.rer --yes. Keep the original archive until recovery succeeds.';
13
17
 
14
18
  // Seeds declare their real bindings and data policy. The shared module owns the
15
19
  // archive format and atomic restore; the shared runner owns its native children.
16
- export function localPortability({ database, binding = 'DB', buckets = {}, policy, policyModule, transient = [], platformMigrations }) {
17
- async function run({ root, path, journal, store, signal, operationToken, platform, legacyRecovery }, direction) {
20
+ export function localPortability({ database, binding = 'DB', buckets = {}, policy, policyModule, transient = [], platformMigrations, managedData = false }) {
21
+ async function run({ root, path, journal, store, signal, operationToken, platform, legacyRecovery, acknowledgeUnverifiedSchemaObjects }, direction) {
18
22
  if (direction === 'export') {
19
23
  if (await lstat(path).catch(error => { if (error.code === 'ENOENT') return null; throw error; })) throw refuse('Export requires a new archive path.');
20
24
  }
21
25
  if(legacyRecovery && (!legacyRecovery.acknowledged || await lstat(legacyRecovery.output).catch(error=>{if(error.code==='ENOENT')return null;throw error;})))throw refuse('Legacy recovery requires acknowledgement and a new output archive path.');
26
+ let unverifiedSchemaRecovery=false;
22
27
  if (direction === 'import') {
23
28
  // Refuse damaged or unverifiable archives before migrations open the
24
29
  // destination database. Worker and finalization verify again before publish.
25
30
  try {
26
- for await (const record of fileRecords(path,legacyRecovery?readLegacyArchive:readArchive)) {}
31
+ for await (const record of fileRecords(path,legacyRecovery?readLegacyArchive:readArchive)) {
32
+ if(record.kind==='manifest')unverifiedSchemaRecovery=!legacyRecovery && acknowledgeUnverifiedSchemaObjects===true && record.schemaObjects===undefined;
33
+ }
27
34
  if(journal)for await(const record of fileRecords(journal)) {}
28
35
  }
29
36
  catch (error) {
@@ -48,14 +55,23 @@ export function localPortability({ database, binding = 'DB', buckets = {}, polic
48
55
  if (!(error instanceof PortabilityError)) throw error;
49
56
  throw refuse(`Local portability policy refused (${error.code}). Executable policies require a seed-owned policyModule with a valid default policy export; policyModule requires native local transport.`);
50
57
  }
51
- if(platform==='container') return (await import('./container-transfer.mjs')).containerTransfer({root,path,journal,store,signal,direction,binding,buckets,policy:declaration.policy,transient});
52
- const input={ root, path, journal, binding, buckets, ...declaration, transient, legacyRecovery, platformMigrations };
58
+ if(platform==='container') return (await import('./container-transfer.mjs')).containerTransfer({root,path,journal,store,signal,direction,binding,buckets,policy:declaration.policy,transient,acknowledgeUnverifiedSchemaObjects});
59
+ const input={ root, path, journal, binding, buckets, ...declaration, transient, legacyRecovery, acknowledgeUnverifiedSchemaObjects, platformMigrations };
53
60
  // Check the executable policy before migrations; the transfer worker imports
54
61
  // it again in its own process so module closures are retained during restore.
55
62
  if (policyModule !== undefined) await nativeWorker(store,'policy-preflight',input,signal);
56
63
  // Do not apply pending product migrations to a populated recovery target.
57
64
  // Check real existing bindings first; finalize repeats this under the lock.
58
65
  if(legacyRecovery)await nativeWorker(store,'legacy-preflight',input,signal);
66
+ if(direction==='import' && !legacyRecovery) {
67
+ try { await emptyNativePreflight(input); }
68
+ catch(error) {
69
+ 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);
70
+ if(error instanceof PortabilityError)throw refuse(`Local restore refused (${error.code}).`);
71
+ throw error;
72
+ }
73
+ }
74
+ if(unverifiedSchemaRecovery)await nativeWorker(store,'schema-recovery-preflight',input,signal);
59
75
  const {nativeApply}=await nativeWorker(store,'migration-preflight',input,signal);
60
76
  // Local migrations need no provider account: wrangler runs without credentials.
61
77
  // Its info lines (the local location and "Use --remote if you want to access
@@ -68,13 +84,15 @@ export function localPortability({ database, binding = 'DB', buckets = {}, polic
68
84
  if(legacyRecovery)receipt.output=relative(root,legacyRecovery.output);
69
85
  return { target: 'local', [direction === 'export' ? 'output' : 'input']: relative(root, path), ...receipt };
70
86
  }
71
- return { legacyRecovery:true, export: context => run(context, 'export'), import: context => run(context, 'import') };
87
+ const restore = context => run(context, 'import');
88
+ const intake = context => withManagedDataImport(context, { binding, buckets, policy, policyModule, platformMigrations, transient }, restore);
89
+ return { legacyRecovery:true, export: context => run(context, 'export'), import: managedData ? intake : restore, ...(managedData ? { managedDataImport: intake } : {}) };
72
90
  }
73
91
 
74
92
  async function nativeWorker(store,direction,input,signal) {
75
93
  // The notice filter loads before the worker links its static node:sqlite import.
76
94
  const worker = fileURLToPath(new URL('./portability-worker.mjs', import.meta.url)), notice = new URL('./sqlite-notice.mjs', import.meta.url).href;
77
- const child = store.spawn(`${direction === 'migration-preflight' ? 'Checking migration history for' : direction === 'policy-preflight' ? 'Checking archive policy' : direction === 'legacy-preflight' ? 'Checking empty recovery destination' : direction === 'export' ? 'Exporting' : 'Restoring'} local installation data`, process.execPath,
95
+ const child = store.spawn(`${direction === 'migration-preflight' ? 'Checking migration history for' : direction === 'policy-preflight' ? 'Checking archive policy' : ['legacy-preflight','schema-recovery-preflight'].includes(direction) ? 'Checking empty recovery destination' : direction === 'export' ? 'Exporting' : 'Restoring'} local installation data`, process.execPath,
78
96
  ['--import', notice, worker, direction, JSON.stringify(input)], { cwd: input.root, signal, env: { ...process.env, WRANGLER_SEND_METRICS: 'false' }, stdio: ['ignore', 'pipe', 'pipe', 'ipc'] });
79
97
  let receipt;
80
98
  // Progress lines come first, as {progress}; the last message is the receipt.
@@ -91,8 +109,12 @@ async function nativeWorker(store,direction,input,signal) {
91
109
  : receipt.safety ? `Restore refused (${receipt.reason}): safety normalization for ${receipt.safety} violates the declared import policy.`
92
110
  : receipt.reason?.startsWith('migration_ledger:') ? ledgerRefusal(receipt)
93
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.`
94
- : receipt.occupied ? `Restore refused (${receipt.reason}): ${receipt.reason === 'bucket_not_empty' ? `storage bucket ${receipt.occupied} in this installation already holds files` : `table ${receipt.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.`
112
+ : receipt.occupied ? occupiedRefusal(input,receipt.reason,receipt.occupied)
95
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);
96
114
  delete receipt.ok;
97
115
  return receipt;
98
116
  }
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.`;
120
+ }
@@ -12,7 +12,7 @@ export async function requireProductionAuth({ root, declaration, env, setupManif
12
12
  for (const secret of declaration.secrets ?? []) if (env[secret.environment]?.trim()) bindings[secret.binding] = env[secret.environment];
13
13
  const mail = await productionMail(root, declaration, env, declarationPath);
14
14
  if (!setupManifest?.steps?.some(step => step.type === 'owner-claim') && !dependencies.length && !mail.declared) return;
15
- if (mail.senderIssue && options.verb === 'deploy') throw refuse(`${mail.senderIssue} Nothing was built or uploaded.`);
15
+ if (mail.senderIssue && options.verb === 'deploy' && !(options.dryRun && mail.fixtureSender)) throw refuse(`${mail.senderIssue} Nothing was built or uploaded.`);
16
16
  if (mail.configured()) return;
17
17
  if (mail.canInspect && !options.dryRun && declarationPath) {
18
18
  try {
@@ -11,11 +11,16 @@ const present = value => typeof value === 'string' && Boolean(value.trim());
11
11
  // The sender forms the mail runtime sends from: a bare address or "Display Name <address>".
12
12
  const sender = value => { try { parseAddress(value); return true; } catch { return false; } };
13
13
  const SENDER = "MAIL_FROM (a real sender on your provider's verified domain; bare address or Display Name <address>)";
14
+ const fixtureSender = value => {
15
+ if (!sender(value)) return false;
16
+ const domain = parseAddress(value).email.toLowerCase().split('@')[1];
17
+ return /(?:^|\.)(?:invalid|example|test|localhost)$/.test(domain)
18
+ || /(?:^|\.)example\.(?:com|net|org)$/.test(domain);
19
+ };
14
20
  const placeholderSender = value => {
15
21
  if (!sender(value)) return false;
16
22
  const { email } = parseAddress(value), [local, domain] = email.toLowerCase().split('@');
17
- return /(?:^|\.)(?:invalid|example|test|localhost)$/.test(domain)
18
- || /(?:^|\.)example\.(?:com|net|org)$/.test(domain)
23
+ return fixtureSender(value)
19
24
  || /^(?:your-?domain|your-?business|fake|placeholder|changeme)\./.test(domain)
20
25
  || /^(?:fake|placeholder|change-?me|replace-?me|your-?email|your-?name|you)(?:[+._-]|$)/.test(local);
21
26
  };
@@ -99,6 +104,7 @@ export async function productionMail(root, declaration, env, declarationPath = '
99
104
  return {
100
105
  declared: 'MAIL_PROVIDER' in bindings || publicInputs.has('MAIL_PROVIDER') || secrets.has('MAIL_API_KEY') || selected.length > 0,
101
106
  senderIssue,
107
+ fixtureSender: fixtureSender(bindings.MAIL_FROM),
102
108
  configured: (live = []) => routes.some(missing => missing(live).length === 0),
103
109
  canInspect: sender(bindings.MAIL_FROM) && !senderIssue && routes.length > 0,
104
110
  missing: routes.length ? routes.map(missing => missing([]).join(', ')).join(' or ') : [
@@ -0,0 +1,9 @@
1
+ // Keep the credential link only where the caller already permits openUrl.
2
+ export function readySummary({ url, openUrl, signedInAs, siteUrl }) {
3
+ const lines = [openUrl
4
+ ? `Open your app${signedInAs ? ', already signed in' : ''} on this computer: ${openUrl}`
5
+ : `Open your app on this computer: ${url}`];
6
+ if (siteUrl) lines.push(`Help and public site preview (secondary): ${siteUrl}`);
7
+ if (openUrl) lines.push(`App address (without sign-in): ${url}`, 'Keep the sign-in link private.');
8
+ return lines;
9
+ }
@@ -0,0 +1,37 @@
1
+ // Archive payloads measured by install.sh; Git and package managers do not
2
+ // expose wire-byte totals here. Disk blocks are measured separately, never
3
+ // substituted for download sizes. No checkout content or credentials are read.
4
+ import { execFile } from 'node:child_process';
5
+ import { join } from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+ import { promisify } from 'node:util';
8
+ import { coldRunBudget } from '../foundation/runtime/run-data.mjs';
9
+ const ownRoot = fileURLToPath(new URL('../', import.meta.url));
10
+
11
+ const execute = promisify(execFile);
12
+ export function showBudget(args) {
13
+ if (!args.includes('--json') && !process.env.RER_BUDGET_SHOWN) process.stderr.write(coldRunBudget + '\n');
14
+ process.env.RER_BUDGET_SHOWN = '1';
15
+ }
16
+ const payload = value => /^\d+$/.test(value ?? '') ? `${value} bytes` : 'not measured';
17
+ async function disk(path) {
18
+ try {
19
+ const { stdout } = await execute('du', ['-sk', path], { timeout: 10000 });
20
+ const blocks = Number(stdout.match(/^\d+/)?.[0]);
21
+ if (Number.isSafeInteger(blocks)) return `${blocks * 1024} bytes`;
22
+ } catch { /* An unavailable measurement is stated, never estimated. */ }
23
+ return 'not measured';
24
+ }
25
+ export async function launchSummary(root) {
26
+ const components = [['rer', ownRoot], ['clone (Git objects)', root && join(root, '.git')], ['dependencies', root && join(root, 'node_modules')]];
27
+ const sizes = await Promise.all(components.map(async ([name, path]) => `${name}: ${path ? await disk(path) : 'not measured'}`));
28
+ const lines = [
29
+ `Downloads this run (archive payloads): Node installer: ${payload(process.env.RER_TRANSFER_NODE_BYTES)}; rer installer: ${payload(process.env.RER_TRANSFER_RER_BYTES)}.`,
30
+ 'Other downloads: project Node, clone and dependencies: not measured. Package-manager caches and metadata are not included in archive counts.',
31
+ `Disk use now (allocated space, not download sizes): ${sizes.join('; ')}.`,
32
+ ];
33
+ if (process.env.RER_TRANSFER_NODE_DISK) lines.push(`Installer Node disk use: ${payload(process.env.RER_TRANSFER_NODE_DISK)}.`);
34
+ if (process.env.RER_LAUNCH_PATH_STEP) lines.push(process.env.RER_LAUNCH_PATH_STEP);
35
+
36
+ return lines;
37
+ }
@@ -9,11 +9,11 @@ import { trafficProxy } from './server-proxy.mjs';
9
9
  // for application URLs, cookies and sign-in links.
10
10
  // In door mode (`door`) the listener is 127.0.0.1 on a port the OS assigns,
11
11
  // and only the machine's front door reaches it.
12
- export async function runtimeFrontDoor({ host, port, activity, door, devKey, origin }) {
13
- const runtimePort = await runtimeLoopbackPort(port);
12
+ export async function runtimeFrontDoor({ host, port, activity, door, devKey, origin, ownerEntry }) {
13
+ let runtimePort = await runtimeLoopbackPort(port);
14
14
  const observer = activity ?? { begin: () => () => {}, touch: () => {} };
15
- const proxy = await trafficProxy({ host, port, target: runtimePort, activity: observer, door, devKey, origin });
16
- return { ...proxy, runtimePort };
15
+ const proxy = await trafficProxy({ host, port, target: runtimePort, activity: observer, door, devKey, origin, ownerEntry });
16
+ return { ...proxy, get runtimePort(){return runtimePort;}, setRuntimePort(port){runtimePort=port;proxy.setTarget(port);} };
17
17
  }
18
18
 
19
19
  // The runtime binds this port strictly, seconds after it is chosen. A port the
@@ -23,12 +23,13 @@ import { UpstreamAgent } from './upstream-agent.mjs';
23
23
  // A Host that is neither loopback, a `*.localhost` name nor the configured
24
24
  // origin's (origin) gets a plain 421 here: the application would refuse it
25
25
  // anyway, and an auth check that throws on it must not answer with a crash page.
26
- export async function trafficProxy({host,port,target,activity,door,devKey,origin}) {
26
+ export async function trafficProxy({host,port,target,activity,door,devKey,origin,ownerEntry}) {
27
27
  const probe=randomUUID(),sockets=new Set(),keyed=keyHolder(devKey),configured=origin?new URL(origin).host:null;
28
28
  const agent=new UpstreamAgent();let closing=false;
29
- const server=http.createServer((req,res)=>{
29
+ const server=http.createServer(async (req,res)=>{
30
30
  if(door&&!doorAdmits(req,door)){req.resume();res.writeHead(403,{'content-type':'text/plain; charset=utf-8'});res.end('This checkout answers only through its front door.');return;}
31
31
  if(!hostAdmits(req,configured)){req.resume();res.writeHead(421,{'content-type':'text/plain; charset=utf-8'});res.end('This local server answers only its own host.');return;}
32
+ try { if(await ownerEntry?.(req,res))return; } catch {req.resume();notFound(res);return;}
32
33
  if(!publicPath(req.url)||fsPath(req.url)&&!keyed(req)){req.resume();notFound(res);return;}
33
34
  const internal=req.headers['x-rer-probe']===probe;delete req.headers['x-rer-probe'];
34
35
  const endActivity=internal?()=>{}:activity.begin();let finished=false;
@@ -102,7 +103,7 @@ export async function trafficProxy({host,port,target,activity,door,devKey,origin
102
103
  upstream.on('error',()=>socket.destroy());socket.on('error',()=>upstream.destroy());socket.on('close',()=>upstream.destroy());upstream.on('close',()=>socket.destroy());
103
104
  });
104
105
  try{await listen(server,host,port);}catch(error){agent.destroy();throw error;}
105
- return {probe,port:server.address().port,async close(){closing=true;agent.destroy();for(const socket of sockets)socket.destroy();await new Promise(resolve=>server.close(resolve));}};
106
+ return {probe,port:server.address().port,setTarget(port){target=port;},async close(){closing=true;agent.destroy();for(const socket of sockets)socket.destroy();await new Promise(resolve=>server.close(resolve));}};
106
107
  }
107
108
  function doorAdmits(req,door){
108
109
  const host=String(req.headers.host??'').toLowerCase(),given=Buffer.from(String(req.headers[door.header]??'')),secret=Buffer.from(door.secret);
@@ -28,10 +28,11 @@ export const declaresJourney = env => {
28
28
  if(env.RER_SERVER_JOURNEY==='1')return true;
29
29
  throw invalid('RER_SERVER_JOURNEY must be 1 to declare a test or CI journey.');
30
30
  };
31
- async function request(record, action) {
31
+ async function request(record, action, {timeoutMs=35000,signal}={}) {
32
32
  return new Promise((resolveRequest,reject)=>{
33
- const socket=createConnection(record.control);let text='';
34
- socket.setTimeout(35000,()=>socket.destroy(Error('Managed server did not complete cleanup.')));
33
+ const socket=createConnection({path:record.control,signal});let text='';
34
+ const timer=setTimeout(()=>socket.destroy(Error('Managed server did not complete cleanup.')),timeoutMs);
35
+ socket.once('close',()=>clearTimeout(timer));
35
36
  socket.on('connect',()=>socket.end(JSON.stringify({token:record.token,checkout:record.checkout,generation:record.generation,action})));
36
37
  socket.on('data',chunk=>{text+=chunk;if(text.length>16384)socket.destroy(Error('Invalid managed server reply.'));});
37
38
  socket.on('end',()=>{try{const value=JSON.parse(text);if(value.token!==record.token||value.checkout!==record.checkout||value.generation!==record.generation)throw Error('Unverified checkout server');resolveRequest(value);}catch(error){reject(error);}});
@@ -198,15 +199,19 @@ export async function serverRegistry(root,{env=process.env,memory=availableMemor
198
199
  }
199
200
  async function update(fields){Object.assign(owned,fields);await change(state=>{const item=state.running.find(item=>item.generation===owned.generation);if(!item)throw Error('Server reservation disappeared');Object.assign(item,fields);});}
200
201
  async function updateActivity(fields){await change(state=>{const item=state.running.find(item=>item.generation===owned.generation);if(item)Object.assign(item,fields);});}
201
- async function waitReady(record,signal){
202
- for(let attempt=0;attempt<1200;attempt++){
202
+ async function waitReady(record,signal,{timeoutMs=300000,now=()=>performance.now()}={}){
203
+ const deadline=now()+timeoutMs;
204
+ while(now()<deadline){
203
205
  signal?.throwIfAborted();if(!await alive(record.owner))throw refuse('Concurrent server startup failed. Retry after recovery.');
204
- try{const status=await request(record,'status');if(status.ready)return {...record,...status};}catch(error){if(attempt===1199)throw error;}
205
- await delay(250,undefined,{signal});
206
+ const remaining=deadline-now();if(remaining<=0)break;
207
+ try{const status=await request(record,'status',{timeoutMs:Math.min(35000,remaining),signal});if(now()<deadline&&status.ready)return {...record,...status};}
208
+ catch(error){if(signal?.aborted)throw error;}
209
+ if(now()<deadline)await delay(Math.min(250,deadline-now()),undefined,{signal});
206
210
  }
207
211
  throw refuse('The existing server is still starting. Wait for its ready output.');
208
212
  }
209
- return {checkout,existing,stop,reserve,serve,update,updateActivity,waitReady,custodyToken:()=>owned?.token,
213
+
214
+ return {checkout,existing,stop,reserve,serve,update,updateActivity,waitReady,ownerEntry:record=>request(record,'owner-entry'),custodyToken:()=>owned?.token,
210
215
  // The sockets close even when the record cannot be removed (its registry
211
216
  // deleted under it, say): an open listener would keep this process alive.
212
217
  close(){return closing??=(async()=>{
package/cli/site.mjs CHANGED
@@ -10,6 +10,7 @@ import { unpublishedIdentities } from './site-private.mjs';
10
10
  import { privateSitePaths } from './site-inputs.mjs';
11
11
  import { redactSiteText } from './site-diagnostics.mjs';
12
12
  import { siteRuntime, buildSiteRuntime, runtimeSummary } from './site-runtime.mjs';
13
+ import { deployDiagnostic, providerFailure } from '../modules/deploy-kit/diagnostics.mjs';
13
14
  import { siteHosting } from './site-hosting.mjs';
14
15
 
15
16
  // The run site: a seed's static marketing pages, /run and docs, built from
@@ -154,7 +155,11 @@ export async function siteCommand(project, options, store, signal, out) {
154
155
  return { dryRun: false, deployed: true, origin: result.origin, site: summary };
155
156
  } catch (error) {
156
157
  if (error instanceof RerError) throw error;
157
- 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})` : ''}.${siteReadbackSummary(error)}`, 1);
158
+ const { createRedaction } = await shared('redaction.mjs');
159
+ const redaction = createRedaction();
160
+ redaction.addSecrets(names.map(name => process.env[name]));
161
+ const diagnostic = deployDiagnostic(error,redaction.redact), provider = providerFailure(error,redaction.redact);
162
+ throw new RerError('deploy_refused', redaction.redact(`Run site deploy stopped: ${/^[a-z0-9-]{1,80}$/.test(error.message) ? error.message : 'site-deploy-failed'}${error.resource ? ` (${error.resource})` : ''}.${provider ? ` ${provider}.` : ''}${siteReadbackSummary(error)}`), 1, {step:diagnostic?.step, ...(diagnostic ? {siteDeploy:diagnostic} : {})});
158
163
  }
159
164
  }
160
165
 
package/cli/transfers.mjs CHANGED
@@ -1,5 +1,6 @@
1
+ import { isManagedDataZip } from './managed-data-zip.mjs';
1
2
  import { stat } from 'node:fs/promises';
2
- import { relative } from 'node:path';
3
+ import { basename, relative } from 'node:path';
3
4
  import {localDependencyLinks} from './dependency-doctor.mjs';
4
5
  import { contained } from './project.mjs';
5
6
  import { missing, refuse } from './errors.mjs';
@@ -18,19 +19,31 @@ export async function transfer(project, options, signal, custody) {
18
19
  if(target!=='local'||options.platform==='container'||api?.legacyRecovery!==true)throw refuse('Legacy v1 recovery is supported only by the local Workers portability adapter in an empty isolated installation.');
19
20
  }else if(direction==='import' && (options.acknowledgeUnverifiedMetadata||options.output))throw refuse('--acknowledge-unverified-metadata and import --output require --legacy-v1.');
20
21
  if (!api || typeof api[direction] !== 'function' || (target === 'remote' && api.remote !== true)) throw refuse(`Complete ${target} ${direction} is unsupported: the reviewed portability API and binding policy must be adopted first.`);
21
- const located = direction === 'export' ? await locateExport(project.root, file) : await locateImport(project.root, file), path = located.path;
22
+ const pathArgument = async (flag, action) => {
23
+ try { return await action(); } catch (error) {
24
+ if (error.code === 'safety_refusal' && error.message === 'Path must be a contained checkout path without traversal.') {
25
+ const quote = value => "'" + value.replaceAll("'", "'\\''") + "'";
26
+ const staged = value => `.rer/recovery/${basename(value.replaceAll('\\', '/'))}`;
27
+ const args = ['rer import', '--input', quote(flag === '--input' ? staged(options.input) : options.input), ...(options.journal ? ['--journal', quote(staged(options.journal))] : []), '--yes', '--cwd', quote(project.root)];
28
+ error.humanMessage = `${flag} ${JSON.stringify(options[flag.slice(2)])} must stay inside this checkout, without .. or an absolute path, for example .rer/recovery/<name>.rer. Stage the archives there as owned private files (0600), then run: ${args.join(' ')}`;
29
+ }
30
+ throw error;
31
+ }
32
+ };
33
+ const located = direction === 'export' ? await locateExport(project.root, file) : await pathArgument('--input', () => locateImport(project.root, file)), path = located.path;
22
34
  const legacyOutput = options.legacyV1 ? await locateExport(project.root, options.output) : undefined;
23
35
  const legacyRecovery=legacyOutput?{output:legacyOutput.path,acknowledged:options.acknowledgeUnverifiedMetadata}:undefined;
24
36
  const sessionFile = options.sessionFile ? await contained(project.root, options.sessionFile, { privateFile: true }) : undefined;
25
37
  if(options.journal && legacyRecovery)throw refuse('--journal requires normal v2 import; legacy v1 metadata cannot authenticate a later-journal recovery.');
26
38
  if (options.journal && (direction !== 'import' || target !== 'local')) throw refuse('--journal applies to a local import only.');
27
39
  // A later archive of the same installation carries its latest erasure journal.
28
- const journal = options.journal ? await contained(project.root, options.journal, { privateFile: true }) : undefined;
40
+ const journal = options.journal ? await pathArgument('--journal', () => contained(project.root, options.journal, { privateFile: true })) : undefined;
29
41
  await project.adapter.prepareData?.(project.root, custody.store, signal);
30
42
  await custody.store.step(`${target === 'remote' ? 'Hosted' : 'Local'} ${direction}`);
31
43
  // Only now can the seed's Vite configuration load in a checkout that never built.
32
44
  await located.unserved(); await legacyOutput?.unserved();
33
- const result=await api[direction]({ root: project.root, target, path, journal, origin: options.origin, sessionFile, signal, platform:options.platform, legacyRecovery, ...custody });
45
+ const operation = direction === 'import' && typeof api.managedDataImport === 'function' && await isManagedDataZip(path) ? api.managedDataImport : api[direction];
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 });
34
47
  // The archive's size, for the line a finished export ends with.
35
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};
36
49
  if(direction==='import' && target==='local' && (await localDependencyLinks(project.root)).some(link=>link.needs_relink)) {
@@ -0,0 +1,59 @@
1
+ // A source archive supplies one caller-identified revision, never Git history.
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import crypto from 'node:crypto';
5
+ import {hash, safe} from './files.mjs';
6
+
7
+ const limit = 64 * 1024 * 1024;
8
+ const objectId = bytes => crypto.createHash('sha1').update(`blob ${bytes.length}\0`).update(bytes).digest('hex');
9
+
10
+ export function archiveReader(directory, revision) {
11
+ if (!/^[a-f0-9]{40}$/.test(revision)) throw Error('A Base archive requires its immutable full 40-character Base commit in --ref');
12
+ if (!fs.lstatSync(directory).isDirectory()) throw Error('Base archive must be a plain directory without .git');
13
+ const root = fs.realpathSync(directory), tree = new Map(), objects = new Map();
14
+ function bytes(name) {
15
+ const filename = path.join(root, name), stat = fs.lstatSync(filename);
16
+ if (!stat.isFile()) throw Error(`Base archive source is not a regular file: ${name}`);
17
+ if (stat.size > limit) throw Error('Base archive source output exceeds the 64 MiB acquisition limit');
18
+ return fs.readFileSync(filename);
19
+ }
20
+ function walk(prefix = '') {
21
+ for (const name of fs.readdirSync(path.join(root, prefix)).sort((a, b) => Buffer.compare(Buffer.from(a), Buffer.from(b)))) {
22
+ if (name.toLowerCase() === '.git') throw Error('Base archive must be a plain directory without .git');
23
+ const relative = safe(prefix ? `${prefix}/${name}` : name), stat = fs.lstatSync(path.join(root, relative));
24
+ if (stat.isDirectory()) walk(relative);
25
+ else if (stat.isFile()) {
26
+ const object = objectId(bytes(relative)), mode = stat.mode & 0o100 ? '100755' : '100644';
27
+ tree.set(relative, {object, mode});
28
+ if (!objects.has(object)) objects.set(object, relative);
29
+ } else throw Error(`Unsupported Base archive entry: ${relative}; supply regular files and directories only`);
30
+ }
31
+ }
32
+ walk();
33
+ const orderedTree = new Map([...tree].sort(([a], [b]) => Buffer.compare(Buffer.from(a), Buffer.from(b))));
34
+ const history = () => { throw Error('Base archive has no Git history. Repeat with --base <checkout> containing the recorded and target commits; no files were refreshed.'); };
35
+ return {
36
+ historyAvailable: false,
37
+ objectId,
38
+ tree(pin) { return pin === revision ? orderedTree : history(); },
39
+ blobs(ids) {
40
+ const result = new Map(), unique = [...new Set(ids)];
41
+ for (let offset = 0; offset < unique.length; offset += 100) {
42
+ let size = 0;
43
+ for (const object of unique.slice(offset, offset + 100)) {
44
+ const name = objects.get(object);
45
+ if (!name) throw Error(`Base archive object ${object} is not available`);
46
+ const data = bytes(name);
47
+ size += data.length;
48
+ if (size > limit) throw Error('Base archive source output exceeds the 64 MiB acquisition limit');
49
+ if (objectId(data) !== object) throw Error(`Base archive changed while reading ${name}; retry with an unchanged archive`);
50
+ result.set(object, data);
51
+ }
52
+ }
53
+ return result;
54
+ },
55
+ digests(ids) { return new Map([...this.blobs(ids)].map(([object, data]) => [object, hash(data)])); },
56
+ contains: history,
57
+ history,
58
+ };
59
+ }