@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
package/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # rer
2
2
 
3
+ <!-- BEGIN COLD RUN BUDGET -->
4
+ Allow roughly 500 MB–1 GB of downloads and 1–3 GB of disk space for a first run, including Node, rer, the app and its dependencies. The app and your computer can need more; later runs reuse downloads.
5
+ <!-- END COLD RUN BUDGET -->
6
+
3
7
  `rer` is the Run Edit Run command. Install it once, then run `rer <verb>` in any
4
8
  Run Edit Run checkout: every verb runs that checkout's own pinned copy, so a
5
9
  checkout always gets the behaviour it was built and tested with.
@@ -15,19 +19,28 @@ Review source changes and run edition tests before committing. See the
15
19
  [edition authoring guide](https://github.com/runeditrun/base/blob/main/export/EDITION-AUTHORING.md)
16
20
  for adoption, refusal behavior, JSON fields and the original Base-checkout form.
17
21
 
22
+ `rer door clauses --write` syncs the shared agent requirements into a seed's
23
+ contract, preserving its judgments and its own specialist clauses, then runs
24
+ contract document generation and checking. `rer door clauses --check` reports
25
+ missing or stale requirements without writing; use `--cwd DIR` to select a seed.
26
+ The CLI can sync a contract before runtime adoption; regenerate the seed's source lock last.
27
+ See [agent door adoption](https://github.com/runeditrun/base/blob/main/modules/agent-door/ADOPTING.md#contract-clauses).
28
+
18
29
  ## Install
19
30
 
20
31
  Start a seed from an empty folder, with or without Node:
21
32
 
22
33
  ```sh
23
34
  curl -fsSL https://runeditrun.com/install.sh | sh
24
- rer dev just-every/run-inkwell
35
+ "$HOME/.local/bin/rer" dev just-every/run-inkwell
25
36
  ```
26
37
 
27
38
  The installer needs no Node: without Node 22 or later on PATH it installs a
28
- private one for `rer` (see below). It edits no shell profile: it names the next
29
- command, `rer dev <owner>/<repo>`, and when `~/.local/bin` is not on PATH for new
30
- terminals its last line is the one to run first, which adds it for your shell.
39
+ private one for `rer` (see below). It edits no shell profile. The second step
40
+ uses the installed launcher directly, so it works in the same shell without
41
+ changing PATH: a child installer cannot change its parent shell’s PATH, and bare
42
+ `rer` needs `~/.local/bin` on PATH. After the app opens, an optional
43
+ `rer cli path` step explains how to make `rer` available in future terminals.
31
44
  The same start also fits on one line:
32
45
 
33
46
  ```sh
@@ -66,24 +79,13 @@ With no Node 22 or later on PATH, the script installs Node 22.20.0 from
66
79
  `nodejs.org` into `~/.local/share/rer/runtimes` (under `XDG_DATA_HOME` when set),
67
80
  verifies the tarball against that release's published `SHASUMS256.txt`, and
68
81
  prints its location. The launcher uses this private runtime on later runs.
69
- System Node and other PATH directories are left alone: the private runtime's
70
- `node`, `npm` and `npx` are not put on PATH, because `rer` is the one command
71
- the installer provides. With no arguments the script names the next command,
72
- `rer dev <owner>/<repo>`, and ends with the PATH line below when one is needed.
73
-
74
- No installer edits shell profiles. The canonical launcher is `~/.local/bin/rer`.
75
- Installation creates that directory if needed and never writes into another
76
- PATH directory. It names any existing `rer` elsewhere on PATH and leaves it
77
- unchanged. If `~/.local/bin` is absent from PATH, another command shadows it,
78
- or no startup file of your shell adds it for new terminals, its last line is
79
- one command to run: it appends `export PATH="$HOME/.local/bin:$PATH"` to that
80
- startup file (`~/.zshrc` for zsh; `~/.bash_profile` for bash on macOS and
81
- `~/.bashrc` elsewhere; `~/.profile` otherwise) and runs it in the current shell.
82
- For fish it is `fish_add_path ~/.local/bin`. Without a private runtime, the
83
- launcher uses `node` from PATH. A re-run with the same build changes
84
- nothing; a different build is installed beside the current one, the previous one
85
- is kept and older ones are removed. It refuses to replace a `~/.local/bin/rer`
86
- that it did not write.
82
+ System Node is left alone. With no arguments, the installer prints an app-start
83
+ command using its absolute launcher. After a first launch, `rer cli path` shows
84
+ an optional shell-specific line to make `rer` available in future terminals.
85
+ Only running that line changes a shell startup file; `rer` never edits one.
86
+ A re-run with the same build changes nothing; a different build keeps the
87
+ previous version and removes older ones. It refuses to replace a launcher it
88
+ did not write.
87
89
 
88
90
  `rer --version` prints this rer's version; inside a checkout a second line
89
91
  names the version the checkout pins, or says that its vendored copy is
@@ -420,6 +422,38 @@ Sensitive-looking outbound names are dropped and counted in `withheld`.
420
422
  Symlinks, generated outputs and dependency trees are skipped; unsupported
421
423
  formats and syntax may yield no signals.
422
424
 
425
+ ## Run your business demo
426
+
427
+ ```sh
428
+ rer business setup --origin https://app.runeditrun.com --session-file /private/path/owner.session --confirm-demo
429
+ ```
430
+
431
+ This provisions the synthetic Juniper Harbor Software demo through the platform's
432
+ Business routes using the signed-in person's session. The session file must be
433
+ an owned regular file with mode `0600`, containing only `rer_session=VALUE` or
434
+ `__Host-rer_session=VALUE`. Symbolic links are refused. The session is read in
435
+ process, sent only as the platform Cookie header, and never printed or placed
436
+ in argv, local Business state or a receipt. `--confirm-demo` is required.
437
+
438
+ Hosting defaults to `managed`; `--hosting assisted` and `--hosting self_host`
439
+ are also supported. There is no `hosted` alias. `--wait-seconds 0..240` bounds
440
+ provisioning polling (default: 240). Both normal output and `--json` print the
441
+ platform script's JSON receipt, including each seed's actual state and only
442
+ credential identifiers. Errors print a named `{code}` to stderr and exit 1.
443
+
444
+ Run the same command to resume. Completed seeds keep their token, consent and
445
+ policy identifiers and report equal receipts (`already provisioned`). The
446
+ receipt includes each seed's state and a top-level `complete` flag. Exit 0
447
+ requires `complete: true`: every required seed must be provisioned, token-issued,
448
+ policy-confirmed, settings-delivered and have its door proofs recorded.
449
+ Missing adoptions remain `not yet on the agent door` and exit nonzero.
450
+
451
+ The route order, policy, synthetic company profile and receipt are mirrored from
452
+ the RER platform at commit `0261033177e8e05284c037369ee9c3a85922a8aa`,
453
+ `scripts/business/demo.mjs` and `demo/company.json`. The platform owns the seed
454
+ catalogue, fixture data and door proofs. This command does not pair the computer
455
+ or use its stored device credential.
456
+
423
457
  ## Business device commands
424
458
 
425
459
  `rer business connect --code ABCD-1234 [--origin https://app.runeditrun.com]`
@@ -454,12 +488,17 @@ The owner chooses three things on the computer's row in the browser: "Add rules
454
488
  so Claude Code never reads your secret files" (Claude Code user Read deny
455
489
  rules), "Keep this computer awake while it works" (export-scoped macOS wake
456
490
  prevention) and "Install the background service" (a launchd or systemd user
457
- service). Connect reads them as `optIns` from device-authenticated
491
+ service). Connect, run and next read them as `optIns` from device-authenticated
458
492
  `GET /api/business/executors/self`, with keys `installPermissions`,
459
493
  `awakeConsent` and `installService`; the CLI prints only the sentences. Only
460
494
  `true` enables an option. Undecided (`null`) options are listed with a browser
461
495
  link; an older server without this route (it answers 403 or 404) leaves all
462
- options undecided. Run connect again after the owner decides. The first
496
+ options undecided. Connect never has to run again after the owner decides:
497
+ `rer business run` (at every check-in) and `rer business next` read the choices
498
+ again, apply each one that changed (a `false` removes what an earlier `true`
499
+ added) and print which choices they applied. A choice this session cannot apply,
500
+ such as Claude Code rules in `~/.claude` from inside an agent sandbox, is named
501
+ with its cause and tried again at the next check-in. The first
463
502
  device-authenticated request happens after both the credential and local
464
503
  pairing state are stored, so a storage failure cannot activate the computer.
465
504
  A service installed with `RER_BUSINESS_STATE_DIR` set keeps that folder. Background
@@ -475,16 +514,35 @@ run outside the sandbox (in Codex, approve running that command outside the
475
514
  sandbox when it asks); later commands
476
515
  only read the credential and run inside the sandbox. Do not install a
477
516
  background service or change user settings unless the owner enables those
478
- options and the sandbox permits their locations.
517
+ options and the sandbox permits their locations. Inside that sandbox macOS also
518
+ refuses to remove the Keychain item (`security` exits 161 and leaves it), so
519
+ `disconnect` revokes on the server, exits 0, says "revoked on the server; the
520
+ local credential is still stored" and names the one command that removes it when
521
+ run outside the sandbox; until then `status` says revoked, never paired.
479
522
 
480
523
  `rer business vendor-key add sentry` requires hidden credential entry in a
481
524
  terminal, stores it in the OS keychain and prints only `sentry:read`.
482
525
  `remove` deletes it. The same commands support `uptimerobot`, `pagerduty` and
483
- `calendly`. Never put a key in command arguments, chat or a URL.
484
-
485
- `rer business next` returns one locally templated classification or owner link,
486
- or `Nothing yet`, within 60 seconds. It never reflects server instructions or
487
- raw evidence. Owner items cannot be answered from this CLI.
526
+ `calendly`. Sorry's export reads its public status page and needs no key. Never
527
+ put a key in command arguments, chat or a URL.
528
+
529
+ `rer business next` returns, within 60 seconds, one locally templated
530
+ classification, owner link or agent step, or says what `run` would start, and
531
+ says `Nothing yet` only when no agent step waits. Once an app is claimed and its
532
+ import door is on, its `export.vendor` task is the agent's step, and so are a
533
+ move's `catchup.vendor` (bringing over what changed in the old tool) and
534
+ `switchoff.archive` (the final archive before switch-off): next names the step,
535
+ the owner-typed `rer business vendor-key add <vendor>` (or says the key is
536
+ already stored, or that the vendor needs none) and `rer business run`. Run reads
537
+ the adapter's non-secret inputs from the leased task's `export_inputs` (Sentry's
538
+ organization and window, PagerDuty's window and `schedules: 'all'` (every rota
539
+ moves), Sorry's page host); a task that does not carry them yet is handed
540
+ back as paused until Business has them. A move's owner steps (`freeze.vendor`,
541
+ a `rollback.*` card, `switchoff.cancel`) are named as the owner's, with the
542
+ move's page (`/business/:id/moves/:toolId` when the summary names its
543
+ `tool_id`, else the switch-over board `/business/:id`), never as agent work. It
544
+ never reflects server instructions or raw evidence. Owner items cannot be
545
+ answered from this CLI.
488
546
  `rer business answer ID VENDOR uses|sells|both|product-dependency [CONFIDENCE]`
489
547
  submits a task-scoped classification through MCP. Choose a vendor ID from the
490
548
  question's displayed answer schema, or `none`; the suggested vendor can be
@@ -501,7 +559,12 @@ device through device-authenticated `DELETE /api/business/executors/self` before
501
559
  removing its service, device and vendor credentials, state and introduced Claude
502
560
  rules, preserving preexisting settings and unrelated edits. It says "Device
503
561
  revoked" only after the server confirms (`{"revoked":true}`, or 401 for a device
504
- already revoked). A server without that route (403 or 404) leaves the computer
562
+ already revoked). If this session may not remove the credential, a key, the
563
+ service or the rules after the server revoked the computer, disconnect still
564
+ exits 0: it names what is left and the one command (with
565
+ `RER_BUSINESS_STATE_DIR` when set) that finishes outside the agent sandbox, and
566
+ keeps only that record, so `status` and every other command say revoked. A
567
+ server without that route (403 or 404) leaves the computer
505
568
  connected: disconnect says so, names the browser page to revoke it in and keeps
506
569
  everything for a later disconnect. Any other failure exits 1 and also keeps the
507
570
  credential for a retry. With no stored device credential, nothing is sent and
@@ -513,25 +576,68 @@ completion checks. Only the browser consent's paths are scanned. Names-only
513
576
  snapshots and page boundaries are saved privately so a killed supervisor can
514
577
  resume from its server checkpoint without rescanning a changed tree. Snapshots
515
578
  are removed after completion. A missing snapshot for an acknowledged page is
516
- an explicit error. Revocation stops the supervisor on its next 401.
517
-
518
- **Remaining export blockers:** grants for linked, configured targets now resolve
519
- to an HTTPS `/api/rer/import/uploads` destination with a 2 MiB quota. They declare
520
- `upload_authorization: seed_import_grant_required` but supply no signed seed
521
- import authority. Vendor task inputs, adapter resume checkpoints and the chunk
522
- assembly/upload contract are also absent. The CLI releases these tasks before
523
- reading a vendor key; background mode parks them, and `run --once` reports the
524
- dependency as a command failure. An unavailable destination reports its reason
525
- and releases with `paused` after a `connected_runner_required` event.
526
- Vendor export remains blocked.
527
-
528
- The current MCP `next_question` filters out owner items. When an owner summary
529
- is supplied, the CLI displays its browser link and refuses to answer it.
530
-
531
- The four deterministic adapter implementations and their native output formats
532
- are described in [the adapter guide](https://github.com/runeditrun/base/blob/main/cli/business/vendors/README.md). Their
533
- presence does not enable export until the seed import authority and remaining
534
- transport contracts are connected.
579
+ an explicit error. Revocation stops the supervisor on its next 401; it then
580
+ removes the device credential if it may and `status` says revoked. While it
581
+ waits, `run` says what for: the owner's permission to scan the folder connect
582
+ ran in (with the Your tools link) until this computer's scan is done, then the
583
+ owner's next step. It removes `run.lock` on every exit, including Ctrl-C,
584
+ SIGTERM and a closed terminal (SIGHUP); a lock whose process is gone, or that
585
+ has not been refreshed for two minutes, is cleared on the next start.
586
+
587
+ `rer business run` also performs claimed `export.vendor` tasks into the app's
588
+ import door. The claim's grant names the door (`/api/rer/import/uploads` on the
589
+ app's HTTPS origin) and `import_grants`; every door request asks
590
+ `POST /api/business/tasks/:taskId/import-grants` for its own short-lived
591
+ RER-signed grant (`uploads` or `plan`; apply is the server's alone after the
592
+ owner's wave approval), and the first grant's namespace names the vendor. The
593
+ read-only vendor key is read from OS credential storage, never from arguments,
594
+ the environment or a file. The shipped adapter runs into a private 0600
595
+ `export-<id>.bundle` file in the state folder, each item checked by the outbound
596
+ detector; the bundle is sent in 64 KiB chunks, then planned, which leaves a
597
+ zero-write preview in the door. Run then completes the task with outputs
598
+ `{upload_id, plan_id, bundle_sha256}` (identifiers only); Business reads that
599
+ plan from the door with its own grants and completes the task only if it is the
600
+ plan of exactly that bundle. Run prints only counts and removes the bundle on
601
+ every exit. Without the key, run
602
+ releases the task as `paused` after an `owner_required` event and names the
603
+ owner's command; a running supervisor picks the export up once the key is
604
+ stored. A door that is not ready releases it as `paused` after a
605
+ `connected_runner_required` event, naming the reason. UptimeRobot needs no
606
+ other input. Sentry, PagerDuty and Sorry use the leased task's `export_inputs`;
607
+ when those inputs are missing they release as `paused` after a
608
+ `configuration_required` event. Calendly's folder of files has no single-bundle
609
+ door format yet and releases with the same event. While an agent step waits (an export, or a
610
+ question for `next`, or the lease an earlier run on this computer still holds),
611
+ run says what it waits for instead of `Nothing yet`; otherwise it names a move's
612
+ owner step with its link before `Nothing yet`.
613
+
614
+ `rer business run` performs claimed `catchup.vendor` and `switchoff.archive`
615
+ tasks the same way: the claim's grant names the door, the key comes from OS
616
+ credential storage, and the shipped adapter's bundle goes up in 64 KiB chunks,
617
+ each with its own grant, from a private 0600 file removed on every exit.
618
+
619
+ - A catch-up then plans the upload with `{uploadId, catchup: true}`. Business
620
+ mints its plan grant under the owner's standing catch-up approval when one
621
+ covers the tool, and says so with `catchup: "bounded"` on the grant. If the
622
+ door refuses that with `catchup_requires_proposal:<reason>` (gone, conflicting
623
+ or rejected records, or a change of 5% or more), run asks
624
+ `import-grants` for `{action: "plan", review: true}` and plans the same upload
625
+ again for the owner's review. Run completes with
626
+ `{upload_id, plan_id, bundle_sha256}`; Business applies a bounded plan under
627
+ the standing approval and any other only after the owner approves it.
628
+ - An archive calls the door's `archive` action with `{uploadId, tool, takenAt}`
629
+ (the tool is the vendor's namespace), then `restore-check` with the
630
+ `archiveId`, and requires both answers to carry the bundle's SHA-256 and size,
631
+ the key `business-archive/<tool>/<takenAt>` and the same counts. Run completes
632
+ with `{archive_id, bundle_sha256}`; Business runs its own `restore-check`
633
+ before the task is done. Archive grants are `uploads`, `archive` and
634
+ `restore-check`; catch-up grants are `uploads`, `plan` and `status`.
635
+
636
+ Run prints only counts and the archive key. When an owner summary is supplied,
637
+ the CLI displays its browser link and refuses to answer it.
638
+
639
+ The five deterministic adapter implementations and their native output formats
640
+ are described in [the adapter guide](https://github.com/runeditrun/base/blob/main/cli/business/vendors/README.md).
535
641
 
536
642
  ## Local engineering companion
537
643
 
package/cli/README.md CHANGED
@@ -65,6 +65,17 @@ owner/sign-in hooks. The reference hook declaration is
65
65
  internal build/dev/verify targets and deployment policy. The CLI owns flags,
66
66
  pins, containment, cancellation, capture, output and sequencing.
67
67
 
68
+ Shared local dev and preview runtimes bind an OS-assigned socket before reporting
69
+ its port over their private parent channel. The CLI confirms that the runtime
70
+ owns that socket, then updates the traffic proxy and scheduled-trigger target.
71
+ Custom runtime targets retain the assigned internal port contract: bind it
72
+ strictly. A healthy application on a different owned port causes an immediate
73
+ port-mismatch refusal. Application health has a hard 60-second limit, including
74
+ setup; an individual probe gets at most five seconds by default. Concurrent
75
+ starts waiting on an existing server have one five-minute elapsed deadline,
76
+ including control requests and polling. Loopback HTTP requests use an elapsed
77
+ deadline, so a response that keeps sending bytes cannot extend readiness.
78
+
68
79
  `rer dev` runs the local migration hook before starting the app and checking its
69
80
  owner prerequisites. The shared operator hook reads every SQL file in the seed's
70
81
  canonical `migrations/core` inventory, including changes pulled since the last
@@ -272,6 +283,14 @@ resolves the deferred choice for preflight. An explicitly selected provider
272
283
  still requires its own credentials. Undeclared environment values do not count;
273
284
  the product's deploy adapter remains responsible for applying these settings.
274
285
 
286
+ `rer deploy --dry-run` accepts syntactically valid fixture senders on reserved
287
+ domains: `.test`, `.example`, `.invalid`, `.localhost`, and `example.com`,
288
+ `example.net` or `example.org` (including their subdomains). It prints the local
289
+ plan and the sender correction needed for a real deploy. A real deploy still
290
+ refuses these placeholder senders with `safety_refusal` before building or
291
+ uploading. Malformed senders and placeholders on ordinary domains refuse in
292
+ both modes. A dry run sends no mail and makes no Cloudflare request.
293
+
275
294
  Idle timeout is `--idle-timeout SECONDS`, then `RER_SERVER_IDLE_SECONDS`, then
276
295
  43200 seconds (12 hours). Only positive integer seconds are accepted. HTTP requests,
277
296
  including assets, reset inactivity; a live request/stream prevents idle
@@ -396,7 +415,7 @@ declaration refuses completion. A kit or custom-hook deploy, except `--dry-run`,
396
415
  first refuses uncommitted tracked source, naming the files, before any build or
397
416
  upload.
398
417
 
399
- The owner deployment declaration may set top-level `"productDirectory": ".rer/deploy/product"` for a product staged by the build or deploy hook. It must name a normalized checkout-relative subdirectory: no absolute path, backslash, empty, `.` or `..` segment. The directory must exist after the build or hook, with no symlink on its path. rer reads this field and passes `--product` only to the kit's packaging commands (`dry-run`, `deploy` and `health`), including its extra dry run after a custom hook. A hook that invokes the kit itself still supplies `--product` on its own invocation; the wrapper reads the declaration for its own steps. Omitting the field keeps packaging at the checkout root. State, root ownership, secret changes and removal keep their existing locations and behavior; dry run still requires credentials for target secret reads.
418
+ The owner deployment declaration may set top-level `"productDirectory": ".rer/deploy/product"` for a product staged by the build or deploy hook. It must name a normalized checkout-relative subdirectory: no absolute path, backslash, empty, `.` or `..` segment. The directory must exist after the build or hook, with no symlink on its path. rer reads this field and passes `--product` only to the kit's packaging commands (`local-plan`, `deploy` and `health`). A public dry run runs the build lifecycle instead of the custom upload hook. A hook that invokes the kit itself still supplies `--product` on its own invocation; the wrapper reads the declaration for its own steps. Omitting the field keeps packaging at the checkout root. State, root ownership, secret changes and removal keep their existing locations and behavior; dry run needs no credentials and never reads target secrets.
400
419
 
401
420
  For a hosted owner claim, deploy reuses the name saved by `rer setup` in the
402
421
  checkout's `.seed/installer/setup-answers.json`, under the adapter's
@@ -406,7 +425,16 @@ interactive deploy asks once and saves it there. For unattended deployment,
406
425
  without a saved or supplied name, it refuses before upload. Names use the same
407
426
  validation as `setup --owner-name`: nonblank, at most 200 characters and no
408
427
  Unicode Cc or Cf control characters. Nameless installers retain their existing
409
- deployment behavior.
428
+ deployment behavior. A dry run never prompts for or requires a missing owner
429
+ name, never saves a name, and never claims a hosted owner. An explicitly supplied
430
+ name still must be valid and supported by the installer.
431
+
432
+ For real deployments, an adapter that validates the hosted owner email in its
433
+ managed deploy preflight does so before rer asks for the owner name. A placeholder
434
+ email therefore receives the adapter's email refusal first; once the email is
435
+ accepted, a missing name prompts interactively or refuses unattended deployment.
436
+ Dry runs bypass custom deploy hooks and their owner-email preflight: they validate
437
+ the local plan, while a real deployment validates the hosted identity before upload.
410
438
 
411
439
  `--env-file` values are available in the command's preflight, custom hook and
412
440
  child build environment and are redacted; the caller environment is restored
@@ -522,3 +550,51 @@ sealing-capable Base version after restoring D1; rolling code back cannot decryp
522
550
  the rows. The CLI has no old-Base capability receipt or code rollback command,
523
551
  so it cannot preflight an out-of-band provider rollback. Current Base rejects a
524
552
  sealed key passed to its plaintext signing path with `installation_key_sealed_rollback`.
553
+
554
+ On loopback, `rer preview` prints `RER_OPEN` for native owner entry.
555
+ `rer demo` keeps its persona link and also prints `RER_OWNER_OPEN` for a native
556
+ owner session in its isolated demo data. These native entry links work once,
557
+ expire within 15 minutes and are never saved. Restarting retires them.
558
+
559
+ ## Run your business demo
560
+
561
+ ```sh
562
+ rer business setup --origin https://app.runeditrun.com --session-file /private/path/owner.session --confirm-demo
563
+ ```
564
+
565
+ This provisions the synthetic Juniper Harbor Software demo through the platform's
566
+ Business routes using the signed-in person's session. The session file must be
567
+ an owned regular file with mode `0600`, containing only `rer_session=VALUE` or
568
+ `__Host-rer_session=VALUE`. Symbolic links are refused. The session is read in
569
+ process, sent only as the platform Cookie header, and never printed or placed
570
+ in argv, local Business state or a receipt. `--confirm-demo` is required.
571
+
572
+ Hosting defaults to `managed`; `--hosting assisted` and `--hosting self_host`
573
+ are also supported. There is no `hosted` alias. `--wait-seconds 0..240` bounds
574
+ provisioning polling (default: 240). Both normal output and `--json` print the
575
+ platform script's JSON receipt, including each seed's actual state and only
576
+ credential identifiers. Errors print a named `{code}` to stderr and exit 1.
577
+
578
+ Run the same command to resume. Completed seeds keep their token, consent and
579
+ policy identifiers and report equal receipts (`already provisioned`). The
580
+ receipt includes each seed's state and a top-level `complete` flag. Exit 0
581
+ requires `complete: true`: every required seed must be provisioned, token-issued,
582
+ policy-confirmed, settings-delivered and have its door proofs recorded.
583
+ Missing adoptions remain `not yet on the agent door` and exit nonzero.
584
+
585
+ The route order, policy, synthetic company profile and receipt are mirrored from
586
+ the RER platform at commit `0261033177e8e05284c037369ee9c3a85922a8aa`,
587
+ `scripts/business/demo.mjs` and `demo/company.json`. The platform owns the seed
588
+ catalogue, fixture data and door proofs. This command does not pair the computer
589
+ or use its stored device credential.
590
+
591
+ ## Sync agent contract clauses
592
+
593
+ `rer door clauses --write` synchronizes Base's thirteen shared agent duties
594
+ into a seed's `CONTRACT.md` and runs its contract-docs generator and check.
595
+ `rer door clauses --check` names missing or stale clauses and exits nonzero;
596
+ `--cwd DIR` selects the seed root. Existing statuses, evidence and gaps survive,
597
+ new clauses start missing, and seed-owned AGENT and SURFACE clauses stay intact.
598
+ Run the edition's source-lock command last. See
599
+ [Contract clauses](../modules/agent-door/ADOPTING.md#contract-clauses) for source
600
+ delivery and generation details.
@@ -0,0 +1,149 @@
1
+ import { randomBytes, randomUUID, webcrypto } from 'node:crypto';
2
+ import { readFile, realpath } from 'node:fs/promises';
3
+ import { join, resolve } from 'node:path';
4
+ import { pathToFileURL } from 'node:url';
5
+ import { runAgentDoorConformance } from '../modules/agent-door/conformance/index.mjs';
6
+ import { validateAgentSurface } from '../modules/agent-door/conformance/surface.mjs';
7
+ import { seconds, signJws } from '../modules/agent-door/conformance/crypto.mjs';
8
+ import { readAgentSurface } from './agent-surface.mjs';
9
+ import { HOSTED_ORIGIN, serveHosted } from './hosted-output.mjs';
10
+ import { createAgentConformanceNetwork } from './agent-network.mjs';
11
+ import { contained } from './project.mjs';
12
+ import { RerError } from './errors.mjs';
13
+ import { verificationReviewers } from './agent-reviewers.mjs';
14
+ import { verificationSponsors } from './agent-sponsors.mjs';
15
+ import { verificationWebhooks } from './agent-webhooks.mjs';
16
+
17
+ function finish(result, report) {
18
+ for (const point of result.points) report(`${point.ok ? 'PASS' : 'FAIL'} ${point.id}${point.ok || !point.detail ? '' : `: ${point.detail}`}`);
19
+ const failed = result.points.filter(point => !point.ok).map(point => point.id);
20
+ report(`Agent door conformance: ${result.points.length - failed.length}/${result.points.length} points passed.`);
21
+ if (!result.ok) throw new RerError('agent_door_failed', `Agent door conformance failed: ${failed.join(', ')}.`, 1, { failures: failed, agentDoor: result });
22
+ return { declared: true, ...result };
23
+ }
24
+
25
+ /** A fresh production installation and key ring for every conformance run. */
26
+ export async function checkAgentDoor(root, { declaration, setupManifest, owner, report = console.log } = {}) {
27
+ const declared = await readAgentSurface(root);
28
+ if (!declared) { report('Agent door conformance: undeclared (no agent-surface.json).'); return { declared: false }; }
29
+ const validation = validateAgentSurface(declared.surface, { contract: declared.contract });
30
+ if (!validation.ok) return finish(validation, report);
31
+ const manifest = setupManifest ?? JSON.parse(await readFile(join(root, 'rer-setup.json'), 'utf8'));
32
+ const claim = manifest.steps?.find(step => step.type === 'owner-claim');
33
+ const verification = declared.surface.verification ?? {};
34
+ let prove;
35
+ if (verification.proof !== undefined) {
36
+ if (typeof verification.proof?.module !== 'string' || Object.keys(verification.proof).join(',') !== 'module') throw new RerError('agent_proof_invalid', 'verification.proof must name a contained test module.', 1);
37
+ await contained(root, verification.proof.module);
38
+ prove = (await import(pathToFileURL(resolve(root, verification.proof.module)))).default;
39
+ if (typeof prove !== 'function') throw new RerError('agent_proof_invalid', 'verification.proof module must default-export a native proof test function.', 1);
40
+ }
41
+ const principals = await verificationSponsors(root, verification), native = principals[0], { email, sub } = native;
42
+ if (verification.reviewers !== undefined && !native.initialize) throw new RerError('agent_reviewer_invalid', 'verification.reviewers requires a native owner initializer to drive invitation and independent review.', 1);
43
+ const reviewers = await verificationReviewers(root, verification.reviewers, email);
44
+ if (claim?.mode && !['signed', 'setup-token'].includes(claim.mode) && !native.initialize) throw new RerError('agent_owner_invalid', `Owner claim mode ${claim.mode} requires verification.owner.initializer using the seed's production lifecycle.`, 1);
45
+ const token = randomBytes(32).toString('hex'), kid = randomUUID(), installationId = randomUUID();
46
+ const business = 'rer-agent-conformance';
47
+ const issuer = `https://synthetic-base-1-${randomUUID()}.invalid`;
48
+ const pair = await webcrypto.subtle.generateKey({ name: 'ECDSA', namedCurve: 'P-256' }, true, ['sign', 'verify']);
49
+ const { kty, crv, x, y } = await webcrypto.subtle.exportKey('jwk', pair.publicKey);
50
+ const publicKeys = { [kid]: { kty, crv, x, y, kid, alg: 'ES256', use: 'sig' } };
51
+ const values = { issuer, installationId, appOrigin: HOSTED_ORIGIN, publicKeys: JSON.stringify(publicKeys), email, sub, token, sessionSecret: randomBytes(32).toString('hex') };
52
+ const nativeBindings = Object.fromEntries(Object.entries(native.bindings ?? {}).map(([name, source]) => [name, values[source]]));
53
+ const network = await createAgentConformanceNetwork(root, verification.network, { email });
54
+ let hosted;
55
+ try {
56
+ hosted = await serveHosted(root, { declaration, outboundService: async request => {
57
+ const copy = reviewers.observes(request) ? request.clone() : null, response = await network.fetch(request);
58
+ if (copy) await reviewers.capture(copy, response.clone());
59
+ return response;
60
+ }, bindings: {
61
+ RER_OWNER_CLAIM_ISSUER: issuer, RER_OWNER_CLAIM_INSTALLATION_ID: installationId,
62
+ RER_OWNER_CLAIM_APP_ORIGIN: HOSTED_ORIGIN,
63
+ RER_OWNER_CLAIM_PUBLIC_KEYS: JSON.stringify(publicKeys),
64
+ RER_BUSINESS_TRUST: JSON.stringify({ v: 1, issuer, audience: HOSTED_ORIGIN, subject: installationId, email, keys: publicKeys }),
65
+ OWNER_EMAIL: email, SETUP_TOKEN: token,
66
+ ...(claim?.emailField ? { [claim.emailField]: email } : {}),
67
+ ...(claim?.tokenField ? { [claim.tokenField]: token } : {}),
68
+ ...(native.emailField ? { [native.emailField]: email } : {}),
69
+ ...(native.tokenField ? { [native.tokenField]: token } : {}),
70
+ ...nativeBindings,
71
+ } });
72
+ const request = (absolute, init = {}) => {
73
+ const url = new URL(absolute);
74
+ if (url.origin !== hosted.origin) throw new RerError('agent_door_origin', 'Agent conformance request must use the fresh hosted installation origin.', 1);
75
+ const timeout = AbortSignal.timeout(30_000);
76
+ return hosted.fetch(url.href.slice(hosted.origin.length + 1), { ...init, signal: init.signal ? AbortSignal.any([init.signal, timeout]) : timeout, headers: Object.fromEntries(new Headers(init.headers)) });
77
+ };
78
+ const path = claim?.mode === 'signed' ? claim.path ?? '/auth/owner-claim' : owner?.path ?? claim?.path ?? '/auth/bootstrap';
79
+ const issued = seconds();
80
+ const claimToken = claim?.mode === 'signed' ? await signJws(pair.privateKey, kid, 'rer-owner-claim+jwt', {
81
+ v: 1, iss: issuer, aud: hosted.origin, installationId, email, jti: randomUUID(), iat: issued, exp: issued + 300,
82
+ }) : token;
83
+ let bootstrap;
84
+ try {
85
+ bootstrap = native.initialize ? await native.initialize({ request, origin: hosted.origin, email, sub,
86
+ reviewers: Object.freeze({ initialize: (label, session) => reviewers.initialize(label, session, { request, origin: hosted.origin, returnTo: owner?.returnTo ?? '/' }) }),
87
+ displayName: 'Synthetic Base 1', label: native.label, database: hosted.database, token, claim: { mode: claim?.mode ?? 'setup-token', path, token: claimToken }, returnTo: owner?.returnTo ?? '/', mail: network.mail, fixtures: network.fixtures,
88
+ }) : await request(new URL(path, hosted.origin).href, { method: 'POST', redirect: 'manual',
89
+ headers: { Origin: hosted.origin, 'Content-Type': 'application/json' },
90
+ body: JSON.stringify({ token: claimToken, displayName: 'Synthetic Base 1', returnTo: owner?.returnTo ?? '/' }),
91
+ });
92
+ } catch {
93
+ return finish({ ok: false, points: [...validation.points, ...reviewers.points(), { id: 'BASE-AGENT-001.owner-bootstrap', ok: false, detail: 'Native owner bootstrap did not complete through the hosted installation origin.' }] }, report);
94
+ }
95
+ const cookie = bootstrap.headers.getSetCookie().map(value => value.split(';', 1)[0]).join('; ');
96
+ await bootstrap.body?.cancel();
97
+ if (bootstrap.status !== 303 || bootstrap.redirected || !cookie) return finish({ ok: false, points: [...validation.points, { id: 'BASE-AGENT-001.owner-bootstrap', ok: false, detail: `Native owner bootstrap returned HTTP ${bootstrap.status}${!cookie ? ' without a session cookie' : ''}.` }] }, report);
98
+ const iat = seconds();
99
+ const settings = await signJws(pair.privateKey, kid, 'rer-business-settings+jwt', {
100
+ v: 1, iss: issuer, aud: hosted.origin, sub: installationId, business, email, owner_id: sub,
101
+ jti: randomUUID(), iat, exp: iat + 300, rev: 1, values: {}, logo: null, team: principals.length > 1 ? principals.slice(1).map(person => ({ id: person.sub, email: person.email, name: person.label, role: person.role, invite: 1 })) : null,
102
+ });
103
+ const paired = await request(new URL('/api/rer/business-settings', hosted.origin).href, {
104
+ method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ settings }),
105
+ });
106
+ let ack; try { ack = await paired.json(); } catch {}
107
+ if (!paired.ok || ack?.rev !== 1) return finish({ ok: false, points: [...validation.points, { id: 'BASE-AGENT-004.business-owner-binding', ok: false, detail: `Signed Business owner binding returned HTTP ${paired.status} without the expected acknowledgement.` }] }, report);
108
+ const sponsors = [{ email, cookie, sub, label: native.label }];
109
+ for (const principal of principals.slice(1)) {
110
+ const issued = seconds();
111
+ const signedClaim = await signJws(pair.privateKey, kid, 'rer-owner-claim+jwt', {
112
+ v: 1, iss: issuer, aud: hosted.origin, installationId, email: principal.email, jti: randomUUID(), iat: issued, exp: issued + 300,
113
+ });
114
+ let response;
115
+ try {
116
+ response = await principal.initialize({ request, origin: hosted.origin, email: principal.email, sub: principal.sub,
117
+ label: principal.label, displayName: principal.label, token, claim: { mode: 'signed', path, token: signedClaim },
118
+ owner: sponsors[0], database: hosted.database, mail: network.mail, fixtures: network.fixtures, returnTo: owner?.returnTo ?? '/',
119
+ });
120
+ } catch { throw new RerError('agent_sponsor_bootstrap', 'An additional sponsor could not complete its native lifecycle through the disposable installation.', 1); }
121
+ const session = response?.headers?.getSetCookie().map(value => value.split(';', 1)[0]).join('; ');
122
+ await response?.body?.cancel();
123
+ if (response?.status !== 303 || response.redirected || !session) throw new RerError('agent_sponsor_bootstrap', 'Each sponsor initializer must return its native final 303 session response.', 1);
124
+ sponsors.push({ email: principal.email, cookie: session, sub: principal.sub, label: principal.label });
125
+ }
126
+ const secrets = await network.provision(hosted);
127
+ const webhooks = await verificationWebhooks(root, verification.webhooks, secrets);
128
+ let nativeJourney;
129
+ if (verification.journey !== undefined) {
130
+ await contained(root, verification.journey);
131
+ const journey = (await import(pathToFileURL(resolve(root, verification.journey)))).default;
132
+ if (typeof journey !== 'function') throw new RerError('agent_journey_invalid', 'verification.journey must default-export an async native journey.', 1);
133
+ nativeJourney = async ({ tool }) => {
134
+ try { await journey({ request, origin: hosted.origin, email, cookie, mail: network.mail, fixtures: network.fixtures, tool }); }
135
+ catch { throw new Error('Native verification journey failed; no captured mail or fixture values are logged.'); }
136
+ };
137
+ }
138
+ const result = await runAgentDoorConformance({ fetch: request, origin: hosted.origin, surface: declared.surface,
139
+ signer: { issuer, installationId, kid, privateKey: pair.privateKey }, person: sponsors[0], sponsors, webhooks, business, prove, nativeJourney,
140
+ });
141
+ const points = [...result.points, ...reviewers.points()];
142
+ return finish({ ...result, points, ok: points.every(point => point.ok) }, report);
143
+ } finally { reviewers.close(); try { await hosted?.close(); } finally { await network.close(); } }
144
+ }
145
+
146
+ if (process.argv[1] && await realpath(new URL(import.meta.url)) === await realpath(process.argv[1])) {
147
+ try { await checkAgentDoor(resolve(process.argv[2] ?? '.'), { declaration: process.argv[3] }); }
148
+ catch (error) { console.error(error instanceof RerError ? error.message : 'Agent door conformance could not complete.'); process.exitCode = 1; }
149
+ }
@@ -0,0 +1,16 @@
1
+ // Host-only per-run fixture control. The app can neither call this function nor
2
+ // widen the declaration. Values cross only into the isolated provider adapter.
3
+ export function createFixtureControl(origins) {
4
+ const values = new Map(); let count = 0, closed = false;
5
+ return {
6
+ set(origin, value) {
7
+ if (closed || !origins.has(origin) || count >= 100) throw new TypeError('Fixture control requires an active run, a declared origin and at most 100 updates.');
8
+ let json;
9
+ try { json = JSON.stringify(value); } catch { /* Use a value-free diagnostic. */ }
10
+ if (json === undefined || Buffer.byteLength(json) > 16_384) throw new TypeError('Fixture control requires JSON data of at most 16384 bytes.');
11
+ values.set(origin, JSON.parse(json)); count++;
12
+ },
13
+ get(origin) { return structuredClone(values.get(origin)); },
14
+ close() { closed = true; values.clear(); },
15
+ };
16
+ }
@@ -0,0 +1,54 @@
1
+ import { randomUUID } from 'node:crypto';
2
+
3
+ // rer-conformance-captured-mail/1: disposable verifier memory, never a route,
4
+ // database binding or application module. Capture no provider headers/secrets.
5
+ const maxCount = 20, maxAge = 300_000, maxBytes = 65_536;
6
+ const address = value => typeof value === 'string' ? value.toLowerCase().match(/(?:<)?([^\s<>]+@[^\s<>]+)>?$/)?.[1] : value?.email?.toLowerCase();
7
+ const list = value => Array.isArray(value) ? value : value ? [value] : [];
8
+
9
+ export function createCapturedMail(email, now = Date.now) {
10
+ const messages = [];
11
+ let closed = false;
12
+ const prune = () => { while (messages.length && now() - messages[0].at > maxAge) messages.shift(); };
13
+ return {
14
+ read({ limit = 10, maxAgeMs = maxAge, after = 0 } = {}) {
15
+ if (closed || !Number.isSafeInteger(limit) || limit < 1 || limit > maxCount || !Number.isSafeInteger(maxAgeMs) || maxAgeMs < 0 || maxAgeMs > maxAge || !Number.isFinite(after)) throw new TypeError('Captured mail requires an active run, limit 1..20 and age 0..300000ms.');
16
+ prune();
17
+ return structuredClone(messages.filter(message => message.at >= after && now() - message.at <= maxAgeMs).slice(-limit));
18
+ },
19
+ async capture(request) {
20
+ if (closed || request.method !== 'POST') return;
21
+ const url = new URL(request.url);
22
+ const sendgrid = url.origin === 'https://api.sendgrid.com' && url.pathname === '/v3/mail/send';
23
+ const resend = url.origin === 'https://api.resend.com' && url.pathname === '/emails';
24
+ const cloudflare = url.origin === 'https://api.cloudflare.com' && /^\/client\/v4\/accounts\/[^/]+\/email\/sending\/send$/.test(url.pathname);
25
+ if (!sendgrid && !resend && !cloudflare) { void request.body?.cancel(); return; }
26
+ // Bound both intake and retained data. Oversized or malformed submissions
27
+ // remain the native provider adapter's responsibility and are not captured.
28
+ const reader = request.body?.getReader();
29
+ if (!reader) return;
30
+ const chunks = []; let length = 0;
31
+ try {
32
+ for (;;) {
33
+ const chunk = await reader.read();
34
+ if (chunk.done) break;
35
+ length += chunk.value.byteLength;
36
+ if (length > maxBytes) { void reader.cancel(); return; }
37
+ chunks.push(chunk.value);
38
+ }
39
+ const bytes = new Uint8Array(length); let offset = 0;
40
+ for (const chunk of chunks) { bytes.set(chunk, offset); offset += chunk.length; }
41
+ const body = JSON.parse(new TextDecoder().decode(bytes));
42
+ const recipients = sendgrid ? list(body.personalizations).flatMap(item => list(item.to)) : list(body.to);
43
+ if (!recipients.some(value => address(value) === email)) return;
44
+ const text = sendgrid ? list(body.content).filter(item => item.type === 'text/plain').map(item => item.value).join('\n') : body.text;
45
+ const html = sendgrid ? list(body.content).filter(item => item.type === 'text/html').map(item => item.value).join('\n') : body.html;
46
+ prune();
47
+ messages.push({ id: randomUUID(), at: now(), subject: typeof body.subject === 'string' ? body.subject : '', text: typeof text === 'string' ? text : '', html: typeof html === 'string' ? html : '' });
48
+ if (messages.length > maxCount) messages.shift();
49
+ } catch { /* A refused capture never prints a mail body or confirmation. */ }
50
+ finally { reader.releaseLock(); }
51
+ },
52
+ close() { closed = true; messages.length = 0; },
53
+ };
54
+ }