@runeditrun/rer 0.2.85 → 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.
- package/README.md +138 -29
- package/cli/README.md +61 -1
- package/cli/agent-door.mjs +149 -0
- package/cli/agent-fixtures.mjs +16 -0
- package/cli/agent-mail.mjs +54 -0
- package/cli/agent-network.mjs +64 -0
- package/cli/agent-reviewers.mjs +110 -0
- package/cli/agent-secrets.mjs +23 -0
- package/cli/agent-sponsors.mjs +43 -0
- package/cli/agent-surface.mjs +34 -0
- package/cli/agent-webhooks.mjs +19 -0
- package/cli/authoring.mjs +2 -1
- package/cli/business/archive-task.mjs +32 -0
- package/cli/business/carry.mjs +3 -1
- package/cli/business/catchup-task.mjs +42 -0
- package/cli/business/choices.mjs +97 -0
- package/cli/business/command.mjs +23 -5
- package/cli/business/connect.mjs +19 -7
- package/cli/business/detector.mjs +4 -1
- package/cli/business/device.mjs +13 -0
- package/cli/business/export-inputs.mjs +69 -0
- package/cli/business/export-task.mjs +17 -0
- package/cli/business/invocation.mjs +8 -1
- package/cli/business/keychain.mjs +8 -1
- package/cli/business/lease.mjs +11 -1
- package/cli/business/local-commands.mjs +79 -31
- package/cli/business/outbound.mjs +9 -4
- package/cli/business/parsers-config.mjs +8 -7
- package/cli/business/parsers-syntax.mjs +7 -3
- package/cli/business/permissions.mjs +2 -0
- package/cli/business/questions.mjs +89 -9
- package/cli/business/setup-command.mjs +49 -0
- package/cli/business/setup-company.json +15 -0
- package/cli/business/setup-demo.mjs +95 -0
- package/cli/business/state.mjs +44 -10
- package/cli/business/supervisor.mjs +94 -35
- package/cli/business/vendor-door.mjs +230 -0
- package/cli/business/vendors/README.md +29 -3
- package/cli/business/vendors/common.mjs +8 -6
- package/cli/business/vendors/index.mjs +22 -11
- package/cli/business/vendors/sorry.mjs +106 -0
- package/cli/contract.mjs +2 -2
- package/cli/demo-deploy-error.mjs +14 -0
- package/cli/demo-native.mjs +4 -1
- package/cli/deploy-config.mjs +1 -1
- package/cli/deploy-owner-input.mjs +3 -1
- package/cli/deploy-variables.mjs +58 -0
- package/cli/door-clauses.mjs +157 -0
- package/cli/export.mjs +16 -4
- package/cli/hosted-output.mjs +17 -7
- package/cli/inspect.mjs +4 -0
- package/cli/jsonc.mjs +8 -4
- package/cli/lifecycle.mjs +3 -1
- package/cli/main.mjs +1 -0
- package/cli/managed-data-schema.mjs +14 -1
- package/cli/portability-empty.mjs +6 -0
- package/cli/portability-migrations.mjs +26 -4
- package/cli/production-auth.mjs +1 -1
- package/cli/production-mail.mjs +8 -2
- package/edition-authoring/archive-source.mjs +59 -0
- package/edition-authoring/base-copies.mjs +92 -18
- package/edition-authoring/cli.mjs +1 -1
- package/edition-authoring/edition-migrations.mjs +7 -3
- package/edition-authoring/module-closure.mjs +2 -16
- package/edition-authoring/workflow-copies.mjs +1 -1
- package/edition-authoring/workflow-scripts.mjs +12 -3
- package/foundation/runtime/contract-docs.mjs +215 -32
- package/foundation/runtime/contract-prose-patterns.mjs +14 -0
- package/foundation/runtime/contract-prose.mjs +88 -0
- package/global/CHANGELOG.md +93 -0
- package/global/README.md +138 -29
- package/global/door/command.mjs +3 -1
- package/global/main.mjs +1 -1
- package/modules/agent-door/CLAUSES.md +215 -0
- package/modules/agent-door/conformance/audit.mjs +66 -0
- package/modules/agent-door/conformance/authority.d.mts +2 -0
- package/modules/agent-door/conformance/authority.mjs +17 -0
- package/modules/agent-door/conformance/crypto.mjs +36 -0
- package/modules/agent-door/conformance/discovery.mjs +61 -0
- package/modules/agent-door/conformance/index.mjs +41 -0
- package/modules/agent-door/conformance/invocation.mjs +32 -0
- package/modules/agent-door/conformance/journey.mjs +112 -0
- package/modules/agent-door/conformance/narrowing.d.mts +1 -0
- package/modules/agent-door/conformance/narrowing.mjs +21 -0
- package/modules/agent-door/conformance/negative.mjs +47 -0
- package/modules/agent-door/conformance/network-modules.mjs +86 -0
- package/modules/agent-door/conformance/network-runtime.mjs +46 -0
- package/modules/agent-door/conformance/policy-phases.mjs +75 -0
- package/modules/agent-door/conformance/protocol.mjs +145 -0
- package/modules/agent-door/conformance/replay.mjs +38 -0
- package/modules/agent-door/conformance/schema.mjs +71 -0
- package/modules/agent-door/conformance/security.mjs +33 -0
- package/modules/agent-door/conformance/sponsors.mjs +68 -0
- package/modules/agent-door/conformance/surface.mjs +89 -0
- package/modules/agent-door/conformance/target.mjs +18 -0
- package/modules/agent-door/conformance/tool-name.d.mts +1 -0
- package/modules/agent-door/conformance/tool-name.mjs +7 -0
- package/modules/agent-door/conformance/webhooks.mjs +30 -0
- package/modules/container/image-variables.mjs +8 -2
- package/modules/demo-host/README.md +6 -0
- package/modules/demo-host/ownership.mjs +39 -0
- package/modules/demo-host/plan.mjs +2 -1
- package/modules/demo-host/remove.mjs +6 -1
- package/modules/import-kit/schema/importer-verification-receipt.schema.json +171 -0
- package/modules/import-kit/schema/importers.schema.json +107 -0
- package/modules/import-kit/src/door/ADOPTING.md +20 -0
- package/modules/import-kit/src/door/README.md +2 -1
- package/modules/import-kit/src/door/admission.ts +5 -3
- package/modules/import-kit/src/door/archive.ts +5 -2
- package/modules/import-kit/src/door/authority.ts +1 -0
- package/modules/import-kit/src/door/grants.ts +1 -1
- package/modules/import-kit/src/door/handler.ts +14 -8
- package/modules/import-kit/src/door/index.ts +1 -1
- package/modules/import-kit/src/door/jobs.ts +40 -0
- package/modules/import-kit/src/door/operator.ts +3 -3
- package/modules/import-kit/src/door/planning.ts +10 -6
- package/modules/import-kit/src/door/protocol.ts +2 -2
- package/modules/import-kit/src/door/raw.ts +25 -0
- package/modules/import-kit/src/door/refusals.ts +1 -0
- package/modules/import-kit/src/door/types.ts +26 -6
- package/modules/import-kit/src/receipt/encoding.ts +37 -0
- package/modules/import-kit/src/receipt/index.ts +69 -0
- package/modules/import-kit/src/receipt/policy.ts +24 -0
- package/modules/import-kit/src/receipt/types.ts +64 -0
- package/modules/import-kit/src/receipt/uri.ts +45 -0
- package/modules/import-kit/src/receipt/validation.ts +87 -0
- package/modules/import-kit/src/status/encoding.ts +13 -0
- package/modules/import-kit/src/status/evidence.ts +218 -0
- package/modules/import-kit/src/status/index.ts +56 -0
- package/modules/import-kit/src/status/schema.ts +208 -0
- package/modules/import-kit/src/status/types.ts +86 -0
- package/modules/operator-auth/accounts/delegated.mjs +48 -0
- package/modules/operator-auth/index.d.mts +7 -0
- package/modules/operator-auth/service.mjs +2 -0
- package/modules/portability/README.md +32 -11
- package/modules/portability/bridge.mjs +22 -2
- package/modules/portability/copies.mjs +8 -1
- package/modules/portability/derived.mjs +33 -0
- package/modules/portability/http-errors.mjs +1 -1
- package/modules/portability/import.mjs +14 -7
- package/package.json +4 -2
- package/scripts/publish-check/copy_identities.py +3 -1
- package/scripts/publish-check/github_refs.py +32 -13
- package/cli/business/opt-ins.mjs +0 -37
package/README.md
CHANGED
|
@@ -19,6 +19,13 @@ Review source changes and run edition tests before committing. See the
|
|
|
19
19
|
[edition authoring guide](https://github.com/runeditrun/base/blob/main/export/EDITION-AUTHORING.md)
|
|
20
20
|
for adoption, refusal behavior, JSON fields and the original Base-checkout form.
|
|
21
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
|
+
|
|
22
29
|
## Install
|
|
23
30
|
|
|
24
31
|
Start a seed from an empty folder, with or without Node:
|
|
@@ -415,6 +422,38 @@ Sensitive-looking outbound names are dropped and counted in `withheld`.
|
|
|
415
422
|
Symlinks, generated outputs and dependency trees are skipped; unsupported
|
|
416
423
|
formats and syntax may yield no signals.
|
|
417
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
|
+
|
|
418
457
|
## Business device commands
|
|
419
458
|
|
|
420
459
|
`rer business connect --code ABCD-1234 [--origin https://app.runeditrun.com]`
|
|
@@ -454,9 +493,12 @@ service). Connect, run and next read them as `optIns` from device-authenticated
|
|
|
454
493
|
`awakeConsent` and `installService`; the CLI prints only the sentences. Only
|
|
455
494
|
`true` enables an option. Undecided (`null`) options are listed with a browser
|
|
456
495
|
link; an older server without this route (it answers 403 or 404) leaves all
|
|
457
|
-
options undecided.
|
|
458
|
-
|
|
459
|
-
|
|
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
|
|
460
502
|
device-authenticated request happens after both the credential and local
|
|
461
503
|
pairing state are stored, so a storage failure cannot activate the computer.
|
|
462
504
|
A service installed with `RER_BUSINESS_STATE_DIR` set keeps that folder. Background
|
|
@@ -472,16 +514,35 @@ run outside the sandbox (in Codex, approve running that command outside the
|
|
|
472
514
|
sandbox when it asks); later commands
|
|
473
515
|
only read the credential and run inside the sandbox. Do not install a
|
|
474
516
|
background service or change user settings unless the owner enables those
|
|
475
|
-
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.
|
|
476
522
|
|
|
477
523
|
`rer business vendor-key add sentry` requires hidden credential entry in a
|
|
478
524
|
terminal, stores it in the OS keychain and prints only `sentry:read`.
|
|
479
525
|
`remove` deletes it. The same commands support `uptimerobot`, `pagerduty` and
|
|
480
|
-
`calendly`.
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
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.
|
|
485
546
|
`rer business answer ID VENDOR uses|sells|both|product-dependency [CONFIDENCE]`
|
|
486
547
|
submits a task-scoped classification through MCP. Choose a vendor ID from the
|
|
487
548
|
question's displayed answer schema, or `none`; the suggested vendor can be
|
|
@@ -498,7 +559,12 @@ device through device-authenticated `DELETE /api/business/executors/self` before
|
|
|
498
559
|
removing its service, device and vendor credentials, state and introduced Claude
|
|
499
560
|
rules, preserving preexisting settings and unrelated edits. It says "Device
|
|
500
561
|
revoked" only after the server confirms (`{"revoked":true}`, or 401 for a device
|
|
501
|
-
already revoked).
|
|
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
|
|
502
568
|
connected: disconnect says so, names the browser page to revoke it in and keeps
|
|
503
569
|
everything for a later disconnect. Any other failure exits 1 and also keeps the
|
|
504
570
|
credential for a retry. With no stored device credential, nothing is sent and
|
|
@@ -510,25 +576,68 @@ completion checks. Only the browser consent's paths are scanned. Names-only
|
|
|
510
576
|
snapshots and page boundaries are saved privately so a killed supervisor can
|
|
511
577
|
resume from its server checkpoint without rescanning a changed tree. Snapshots
|
|
512
578
|
are removed after completion. A missing snapshot for an acknowledged page is
|
|
513
|
-
an explicit error. Revocation stops the supervisor on its next 401
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
The
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
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).
|
|
532
641
|
|
|
533
642
|
## Local engineering companion
|
|
534
643
|
|
package/cli/README.md
CHANGED
|
@@ -283,6 +283,14 @@ resolves the deferred choice for preflight. An explicitly selected provider
|
|
|
283
283
|
still requires its own credentials. Undeclared environment values do not count;
|
|
284
284
|
the product's deploy adapter remains responsible for applying these settings.
|
|
285
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
|
+
|
|
286
294
|
Idle timeout is `--idle-timeout SECONDS`, then `RER_SERVER_IDLE_SECONDS`, then
|
|
287
295
|
43200 seconds (12 hours). Only positive integer seconds are accepted. HTTP requests,
|
|
288
296
|
including assets, reset inactivity; a live request/stream prevents idle
|
|
@@ -417,7 +425,16 @@ interactive deploy asks once and saves it there. For unattended deployment,
|
|
|
417
425
|
without a saved or supplied name, it refuses before upload. Names use the same
|
|
418
426
|
validation as `setup --owner-name`: nonblank, at most 200 characters and no
|
|
419
427
|
Unicode Cc or Cf control characters. Nameless installers retain their existing
|
|
420
|
-
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.
|
|
421
438
|
|
|
422
439
|
`--env-file` values are available in the command's preflight, custom hook and
|
|
423
440
|
child build environment and are redacted; the caller environment is restored
|
|
@@ -538,3 +555,46 @@ On loopback, `rer preview` prints `RER_OPEN` for native owner entry.
|
|
|
538
555
|
`rer demo` keeps its persona link and also prints `RER_OWNER_OPEN` for a native
|
|
539
556
|
owner session in its isolated demo data. These native entry links work once,
|
|
540
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
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { validateNetworkAdapter, NetworkAdapterError } from '../modules/agent-door/conformance/network-modules.mjs';
|
|
3
|
+
import { isolatedNetworkAdapter } from '../modules/agent-door/conformance/network-runtime.mjs';
|
|
4
|
+
import { verificationSecrets } from './agent-secrets.mjs';
|
|
5
|
+
import { RerError } from './errors.mjs';
|
|
6
|
+
import { createCapturedMail } from './agent-mail.mjs';
|
|
7
|
+
import { createFixtureControl } from './agent-fixtures.mjs';
|
|
8
|
+
|
|
9
|
+
const denied = () => new Response('Conformance has no network adapter for this external effect.', { status: 502 });
|
|
10
|
+
|
|
11
|
+
// Conformance is a disposable installation. Replace only the paid mail network
|
|
12
|
+
// edge; native invitation preparation, authorization and D1 commits still run.
|
|
13
|
+
// No request leaves this verifier and no stand-in credential reaches a provider.
|
|
14
|
+
export async function agentConformanceNetwork(request) {
|
|
15
|
+
const url = new URL(request.url);
|
|
16
|
+
if (request.method === 'POST' && url.origin === 'https://api.resend.com' && url.pathname === '/emails') {
|
|
17
|
+
await request.arrayBuffer();
|
|
18
|
+
return Response.json({ id: randomUUID() });
|
|
19
|
+
}
|
|
20
|
+
if (request.method === 'POST' && url.origin === 'https://api.sendgrid.com' && url.pathname === '/v3/mail/send') {
|
|
21
|
+
await request.arrayBuffer();
|
|
22
|
+
return new Response(null, { status: 202, headers: { 'x-message-id': randomUUID() } });
|
|
23
|
+
}
|
|
24
|
+
if (request.method === 'POST' && url.origin === 'https://api.cloudflare.com' && /^\/client\/v4\/accounts\/[^/]+\/email\/sending\/send$/.test(url.pathname)) {
|
|
25
|
+
const body = await request.json();
|
|
26
|
+
return Response.json({ success: true, errors: [], result: { message_id: randomUUID(), accepted: body.to, rejected: [] } });
|
|
27
|
+
}
|
|
28
|
+
return denied();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Extend the paid network edge for declared origins, without running seed
|
|
32
|
+
* modules in this process or giving them any route to the real network. */
|
|
33
|
+
export async function createAgentConformanceNetwork(root, config, { email } = {}) {
|
|
34
|
+
const mail = createCapturedMail(email);
|
|
35
|
+
let declaration, adapter, fixtures;
|
|
36
|
+
try {
|
|
37
|
+
if (config !== undefined) {
|
|
38
|
+
declaration = validateNetworkAdapter(Object.fromEntries(Object.entries(config).filter(([key]) => key !== 'secretSource')));
|
|
39
|
+
adapter = await isolatedNetworkAdapter(root, declaration.module, denied);
|
|
40
|
+
}
|
|
41
|
+
fixtures = createFixtureControl(declaration?.origins ?? new Set());
|
|
42
|
+
} catch (error) {
|
|
43
|
+
mail.close();
|
|
44
|
+
if (error instanceof NetworkAdapterError) throw new RerError('agent_network_invalid', error.message, 1);
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
return { mail: { read: options => mail.read(options) }, fixtures: { set: (origin, value) => fixtures.set(origin, value) },
|
|
48
|
+
provision: async hosted => {
|
|
49
|
+
if (config?.secretSource === undefined) return {};
|
|
50
|
+
const secrets = await verificationSecrets(root, config.secretSource, hosted.database);
|
|
51
|
+
await adapter.provision(secrets);
|
|
52
|
+
return secrets;
|
|
53
|
+
},
|
|
54
|
+
close: async () => { mail.close(); fixtures.close(); await adapter?.close(); }, fetch: async request => {
|
|
55
|
+
const capture = request.clone(), origin = new URL(request.url).origin;
|
|
56
|
+
try {
|
|
57
|
+
const response = declaration?.origins.has(origin) ? await adapter.fetch(request, fixtures.get(origin)) : await agentConformanceNetwork(request);
|
|
58
|
+
if (response.ok) await mail.capture(capture);
|
|
59
|
+
else void capture.body?.cancel();
|
|
60
|
+
return response;
|
|
61
|
+
}
|
|
62
|
+
catch { void capture.body?.cancel(); throw new RerError('agent_network_failed', 'The isolated conformance network adapter failed to handle a provider request. Its default fetch export must return a Response.', 1); }
|
|
63
|
+
} };
|
|
64
|
+
}
|