@runeditrun/rer 0.2.110 → 0.2.112

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 (68) hide show
  1. package/README.md +39 -2
  2. package/cli/README.md +56 -0
  3. package/cli/agent-door.mjs +12 -45
  4. package/cli/agent-history-database.mjs +13 -6
  5. package/cli/bounded.mjs +3 -3
  6. package/cli/contract.mjs +5 -1
  7. package/cli/deploy-command.mjs +4 -2
  8. package/cli/deploy-policy.mjs +17 -0
  9. package/cli/hosted-output.mjs +30 -10
  10. package/cli/hosted-owner.mjs +85 -0
  11. package/cli/inspect.mjs +6 -2
  12. package/cli/lifecycle.mjs +5 -1
  13. package/cli/main.mjs +13 -0
  14. package/cli/parse.mjs +4 -4
  15. package/cli/portability.mjs +3 -3
  16. package/cli/size/build-facts.mjs +58 -0
  17. package/cli/size/build-paths.mjs +3 -0
  18. package/cli/size/check.mjs +16 -0
  19. package/cli/size/clauses.mjs +21 -0
  20. package/cli/size/clock.mjs +21 -0
  21. package/cli/size/command.mjs +64 -0
  22. package/cli/size/declaration.mjs +87 -0
  23. package/cli/size/dml-parts.mjs +108 -0
  24. package/cli/size/examples/happytohelp.json +68 -0
  25. package/cli/size/expression-depth.mjs +45 -0
  26. package/cli/size/expression.mjs +33 -0
  27. package/cli/size/fixture.mjs +139 -0
  28. package/cli/size/flows.mjs +81 -0
  29. package/cli/size/from-items.mjs +124 -0
  30. package/cli/size/grow.mjs +83 -0
  31. package/cli/size/install.mjs +136 -0
  32. package/cli/size/json-duplicates.mjs +45 -0
  33. package/cli/size/limits.mjs +9 -0
  34. package/cli/size/measure.mjs +9 -0
  35. package/cli/size/meter.mjs +167 -0
  36. package/cli/size/personas.mjs +138 -0
  37. package/cli/size/report.mjs +23 -0
  38. package/cli/size/schema-objects.mjs +80 -0
  39. package/cli/size/schema.mjs +56 -0
  40. package/cli/size/statements.mjs +53 -0
  41. package/cli/size/validate-flows.mjs +109 -0
  42. package/cli/size/validate-kit.mjs +44 -0
  43. package/cli/size/validate-shape.mjs +75 -0
  44. package/cli/size/verdict.mjs +131 -0
  45. package/cli/size/verify-step.mjs +35 -0
  46. package/global/CHANGELOG.md +50 -0
  47. package/global/README.md +39 -2
  48. package/global/cli/install.mjs +1 -1
  49. package/global/main.mjs +3 -0
  50. package/global/run.mjs +15 -2
  51. package/install.sh +3 -0
  52. package/modules/agent-door/conformance/audit.mjs +3 -0
  53. package/modules/d1-transport/limits.mjs +5 -1
  54. package/modules/deploy-kit/sql-tokens.mjs +5 -4
  55. package/modules/operator-auth/accounts/one-click.mjs +2 -0
  56. package/modules/operator-auth/dev/index.mjs +7 -1
  57. package/modules/operator-auth/dev/invited.mjs +11 -0
  58. package/modules/operator-auth/dev-gate.mjs +3 -2
  59. package/modules/operator-auth/routes.mjs +4 -0
  60. package/modules/portability/progress.mjs +12 -10
  61. package/modules/release/README.md +8 -0
  62. package/modules/release/archive-guard.mjs +22 -0
  63. package/modules/release/archive-members.mjs +49 -0
  64. package/modules/release/export.mjs +7 -1
  65. package/onboarding/commands.mjs +17 -8
  66. package/onboarding/migration-progress.mjs +69 -0
  67. package/onboarding/operator-migrations.mjs +1 -0
  68. package/package.json +2 -1
package/README.md CHANGED
@@ -5,7 +5,7 @@ Allow roughly 500 MB–1 GB of downloads and 1–3 GB of disk space for a first
5
5
  <!-- END COLD RUN BUDGET -->
6
6
 
7
7
  `rer` is the Run Edit Run command. Install it once, then run `rer <verb>` in any
8
- Run Edit Run checkout: every verb runs that checkout's own pinned copy, so a
8
+ Run Edit Run checkout: project verbs run that checkout's own pinned copy, so a
9
9
  checkout always gets the behaviour it was built and tested with.
10
10
 
11
11
  For source authors, `rer adopt-edition` adds a recipe and lock to existing tracked
@@ -47,7 +47,20 @@ changing PATH: a child installer cannot change its parent shell’s PATH, and ba
47
47
  `~/.local/bin`, its closing lines give one required step: the
48
48
  `export PATH="$HOME/.local/bin:$PATH"` line to run now and add to your shell
49
49
  startup file, or `rer cli path` (by its absolute launcher) for other shells.
50
- The same start also fits on one line:
50
+ To run a downloaded JavaScript tool, open its folder in the terminal and use
51
+ `"$HOME/.local/bin/rer" run --script ./tool.mjs` followed by its arguments.
52
+ For example, from Downloads the Oncall PagerDuty exporter runs with:
53
+
54
+ ```sh
55
+ "$HOME/.local/bin/rer" run --script ./oncall-export.mjs pagerduty
56
+ ```
57
+
58
+ `--script` uses the Node running `rer`, including the installer's private Node;
59
+ it needs no checkout, pnpm or separate Node installation. The file path is
60
+ relative to the current folder, or to `--cwd DIR` when supplied before
61
+ `--script`. Remaining arguments go directly to the file. A package script
62
+ (`rer run NAME`) continues to use the checkout's pinned Node and pnpm.
63
+ The app start also fits on one line:
51
64
 
52
65
  ```sh
53
66
  curl -fsSL https://runeditrun.com/install.sh | sh -s -- dev just-every/run-inkwell
@@ -319,6 +332,7 @@ line that still names it. A later refresh is a version bump:
319
332
  | `@runeditrun/rer/jsonc` | JSONC reading | `scripts/base-cli/cli/jsonc.mjs` |
320
333
  | `@runeditrun/rer/parse`, `/scheduled` | CLI argument parsing, scheduled-job helpers | `scripts/base-cli/cli/parse.mjs`, `scheduled.mjs` |
321
334
  | `@runeditrun/rer/dev-identity` | dev identity helpers | `scripts/base-cli/cli/dev-identity.mjs` |
335
+ | `@runeditrun/rer/size-fixture` | `compileFixture(declaration, 'small' or 'large', { now, ownerEmail })`: a `size-check.json` shape as the ordered `[{name, sql, params}]` statements `rer size` runs on local D1 (the fleet runner's statements format), for seeding real D1 with the same rows | `scripts/base-cli/cli/size/fixture.mjs` |
322
336
  | `@runeditrun/rer/operator-installer` | `operatorInstaller`, `developmentTarget`, `previewTarget` | `scripts/base-onboarding/operator-installer.mjs` |
323
337
  | `@runeditrun/rer/local-installer` | `localInstaller` | `scripts/base-onboarding/adapter.mjs` |
324
338
  | `@runeditrun/rer/operator-install` | `installOperator` | `scripts/base-onboarding/operator-install.mjs` |
@@ -390,6 +404,29 @@ there lists its flags:
390
404
  `export`, `import`, `doctor`, `describe`, `check`, `release`,
391
405
  `release sign`, `release receipt` and `release keygen`.
392
406
 
407
+ `rer size` checks statement size against D1's limits: it fails a statement at 90
408
+ FROM items (counted with every CTE and view reference expanded) or expression
409
+ depth 90, where D1 refuses at 100 and local SQLite and Miniflare accept both.
410
+ With no flags it checks every view and trigger statement of the build's D1
411
+ migrations; `--migrations DIR` names a migrations directory instead, and
412
+ `--statements FILE` checks a statements file (`{"statements":[{"name","sql"}]}`)
413
+ against that schema. It runs in any checkout, needs no account, and exits 1 on
414
+ any failure, 0 otherwise and 3 with no build and no `--migrations`. `rer verify`
415
+ ends with the same check, inside its own job-queue slot, and fails exactly when
416
+ `rer size` would. With a `size-check.json` (or `--declaration FILE`, a
417
+ declaration kept outside the checkout) it also builds the declared shape at a
418
+ small and a large size on local D1, runs every declared flow on each through a
419
+ rows-read meter and fails a flow that passes its ceiling, reads more at large
420
+ than at small by over 10 percent plus 200 rows, answers the wrong status, has a
421
+ statement refused by local D1 or runs a statement at 90 FROM items or depth;
422
+ `--write-statements DIR` writes the statements each size ran in the fleet
423
+ runner's format. Without a `size-check.json`, verify's step checks the schema
424
+ objects and prints `Size check: undeclared (no size-check.json).` A checkout
425
+ without a seedContract runs it from the declaration's `build.wrangler` and
426
+ `build.deployDeclaration` and never forwards to a declared argv; its owner
427
+ persona needs an owner claim in `rer-setup.json` or `verification.owner` in
428
+ `agent-surface.json`.
429
+
393
430
  Anywhere: `rer list [DIR]`, `rer cli status|install|uninstall`, `rer update`,
394
431
  `rer queue NAME -- COMMAND`, `rer --version` and `rer --help`.
395
432
 
package/cli/README.md CHANGED
@@ -468,6 +468,62 @@ retirement and preserve the environment, checkout and env-file in recovery
468
468
  commands. Retirement can be finished with `rer deploy --unset-secret SETUP_TOKEN`
469
469
  plus the same `--environment`, `--env-file` and `--cwd` arguments.
470
470
 
471
+ A seed may declare an optional `commandAdapter.deployPolicy` function:
472
+
473
+ ```js
474
+ import { missing } from '@runeditrun/rer/errors';
475
+
476
+ const deployPolicy = async ({ root, options, environment, env, bindings,
477
+ declaration, declarationPath }) => {
478
+ // Normalize any seed-specific choices in a local copy, then validate the
479
+ // applicable operation. Binding values already resolve declared env aliases.
480
+ if (options.setSecret && env.MAIL_MODE === 'off'
481
+ && options.setSecret.split(',').some(name => name === 'OUTBOUND_TOKEN' && bindings[name]?.trim())) {
482
+ throw missing('Credentials are not bound while email is off.');
483
+ }
484
+ };
485
+ ```
486
+
487
+ The public application `rer deploy` door awaits this hook once, before dispatching
488
+ any build, custom deploy hook or owner-account provider operation, including
489
+ account/subdomain lookup and receipt recovery. It runs for ordinary deploy,
490
+ `--dry-run`, `--set-secret`, `--unset-secret`, `--rotate-secret`,
491
+ `--reopen-installation-key` and `--remove`; the seed chooses which policy applies
492
+ to each operation, allowing cleanup where appropriate. Run-site, hosted-demo and
493
+ independent-command doors retain their own contracts. A policy must stay local:
494
+ no provider calls, build, settings writes or secret output.
495
+
496
+ `options` is a copy of the parsed CLI options: repeated/comma-separated secret
497
+ flags have their usual deduplicated binding-name list. `environment` defaults to
498
+ `production`. `env` is the effective deploy environment (process environment,
499
+ then the owned `--env-file` override, then existing declared owner/generated
500
+ input supply). `bindings` starts with declaration `vars` and overlays nonblank
501
+ secret values under their declared Worker binding names, using each secret's
502
+ `environment` mapping. For example, `{binding:'OUTBOUND_TOKEN',
503
+ environment:'EMAIL_API_KEY'}` exposes `env.EMAIL_API_KEY` as
504
+ `bindings.OUTBOUND_TOKEN`; ambient `env.OUTBOUND_TOKEN` cannot override that
505
+ mapping. These are proposed local inputs, not a read of existing hosted secrets.
506
+ `root`, `declaration` and checkout-relative `declarationPath` name the selected
507
+ checkout and deploy declaration. Values are private; do not log them.
508
+
509
+ This is a validation hook: treat inputs as read-only; its return value is ignored.
510
+ Seed-specific provider enums and additional aliases remain the seed's job:
511
+ normalize them into a local copy before checking policy. Keep any deploy hook's
512
+ existing runtime normalization. A successful policy returns normally; throw a
513
+ `RerError` from the same rer copy/package to refuse. `missing(message)` gives exit
514
+ 3 and JSON `error` with `code:"missing_input"`, `message`, `exitCode:3`, followed
515
+ by `result` with `ok:false`, `exitCode:3`; `refuse(message)` retains the existing
516
+ exit-4 `safety_refusal`. Other errors retain the existing command-failure path.
517
+ A refusal stops before any provider contact. A declared non-function policy is
518
+ an invalid invocation (exit 2).
519
+
520
+ Seeds without this optional hook keep the existing contract: secret mutations
521
+ use the owner-account controller's declaration, value and ownership checks,
522
+ without invoking the application's build/deploy hook or the full-deploy
523
+ production-auth preflight. Full deployments still run that shared preflight.
524
+ No seed-specific mail policy is inferred. Low-level kit/controller callers remain
525
+ responsible for their own policy; this hook belongs to the public CLI adapter.
526
+
471
527
  ## Local business signals
472
528
 
473
529
  `rer business scan [DIR...] [--json]` reads local source and configuration names;
@@ -1,4 +1,4 @@
1
- import { randomBytes, randomUUID, webcrypto } from 'node:crypto';
1
+ import { randomUUID } from 'node:crypto';
2
2
  import { readFile, realpath } from 'node:fs/promises';
3
3
  import { join, resolve } from 'node:path';
4
4
  import { pathToFileURL } from 'node:url';
@@ -6,7 +6,8 @@ import { runAgentDoorConformance } from '../modules/agent-door/conformance/index
6
6
  import { validateAgentSurface } from '../modules/agent-door/conformance/surface.mjs';
7
7
  import { seconds, signJws } from '../modules/agent-door/conformance/crypto.mjs';
8
8
  import { readAgentSurface } from './agent-surface.mjs';
9
- import { HOSTED_ORIGIN, serveHosted } from './hosted-output.mjs';
9
+ import { serveHosted } from './hosted-output.mjs';
10
+ import { bootstrapOwner, hostedRequest, ownerBindings, ownerClaim, ownerKeys, ownerSession, pairedBindings, reviewerDoor } from './hosted-owner.mjs';
10
11
  import { createAgentConformanceNetwork } from './agent-network.mjs';
11
12
  import { contained } from './project.mjs';
12
13
  import { RerError } from './errors.mjs';
@@ -14,15 +15,11 @@ import { verificationReviewers } from './agent-reviewers.mjs';
14
15
  import { verificationSponsors } from './agent-sponsors.mjs';
15
16
  import { verificationWebhooks } from './agent-webhooks.mjs';
16
17
  import { verificationInvoke, verificationJourney } from './agent-verifier.mjs';
17
- import { verificationBindings } from './agent-bindings.mjs';
18
18
  import { writeVerificationHistory } from './agent-history-database.mjs';
19
19
  import { verificationHistory } from './agent-history.mjs';
20
20
  import { journeyFixtures } from './agent-journey-fixtures.mjs';
21
21
  import { verificationAgentInitializer } from './agent-initializer.mjs';
22
22
 
23
- // Unpairing re-serves the installation without the Business trust it was paired with.
24
- const pairedBindings = ['RER_OWNER_CLAIM_ISSUER', 'RER_OWNER_CLAIM_INSTALLATION_ID', 'RER_OWNER_CLAIM_APP_ORIGIN', 'RER_OWNER_CLAIM_PUBLIC_KEYS', 'RER_BUSINESS_TRUST'];
25
-
26
23
  function finish(result, report) {
27
24
  if (result.capabilities) report(`Agent capabilities (${result.capabilities.mode}): declared=${result.capabilities.declared.join(',')}; refused=${result.capabilities.refused.join(',')}; unscoped=${result.capabilities.unscoped.join(',')}.`);
28
25
  for (const point of result.points) report(`${point.ok ? 'PASS' : 'FAIL'} ${point.id}${point.ok || !point.detail ? '' : `: ${point.detail}`}`);
@@ -62,14 +59,8 @@ export async function checkAgentDoor(root, { declaration, setupManifest, owner,
62
59
  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);
63
60
  const reviewers = await verificationReviewers(root, verification.reviewers, email);
64
61
  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);
65
- const token = randomBytes(32).toString('hex'), kid = randomUUID(), installationId = randomUUID();
66
- const business = 'rer-agent-conformance';
67
- const issuer = `https://synthetic-base-1-${randomUUID()}.invalid`;
68
- const pair = await webcrypto.subtle.generateKey({ name: 'ECDSA', namedCurve: 'P-256' }, true, ['sign', 'verify']);
69
- const { kty, crv, x, y } = await webcrypto.subtle.exportKey('jwk', pair.publicKey);
70
- const publicKeys = { [kid]: { kty, crv, x, y, kid, alg: 'ES256', use: 'sig' } };
71
- const values = { issuer, installationId, appOrigin: HOSTED_ORIGIN, publicKeys: JSON.stringify(publicKeys), email, sub, token, sessionSecret: randomBytes(32).toString('hex') };
72
- const nativeBindings = await verificationBindings(root, native.bindings, values);
62
+ const keys = await ownerKeys(root, native, { email, sub });
63
+ const { token, kid, installationId, business, issuer, pair } = keys;
73
64
  const network = await createAgentConformanceNetwork(root, verification.network, { email, sponsorEmails: principals.slice(1).map(person => person.email) });
74
65
  let hosted, history;
75
66
  try {
@@ -78,43 +69,19 @@ export async function checkAgentDoor(root, { declaration, setupManifest, owner,
78
69
  if (copy) await reviewers.capture(copy, response.clone());
79
70
  return response;
80
71
  }, bindings: {
81
- RER_OWNER_CLAIM_ISSUER: issuer, RER_OWNER_CLAIM_INSTALLATION_ID: installationId,
82
- RER_OWNER_CLAIM_APP_ORIGIN: HOSTED_ORIGIN,
83
- RER_OWNER_CLAIM_PUBLIC_KEYS: JSON.stringify(publicKeys),
84
- RER_BUSINESS_TRUST: JSON.stringify({ v: 1, issuer, audience: HOSTED_ORIGIN, subject: installationId, email, keys: publicKeys }),
85
- OWNER_EMAIL: email, SETUP_TOKEN: token,
86
- ...(claim?.emailField ? { [claim.emailField]: email } : {}),
87
- ...(claim?.tokenField ? { [claim.tokenField]: token } : {}),
88
- ...(native.emailField ? { [native.emailField]: email } : {}),
89
- ...(native.tokenField ? { [native.tokenField]: token } : {}),
90
- ...nativeBindings,
72
+ ...ownerBindings(keys, { claim, native, email }),
91
73
  } });
92
- const request = (absolute, init = {}) => {
93
- const url = new URL(absolute);
94
- if (url.username || url.password || !hosted.origins.includes(url.origin)) throw new RerError('agent_door_origin', 'Agent conformance request must use a declared hosted installation origin.', 1);
95
- const timeout = AbortSignal.timeout(30_000);
96
- return hosted.fetch(url.href.slice(url.origin.length + 1), { ...init, origin: url.origin, signal: init.signal ? AbortSignal.any([init.signal, timeout]) : timeout, headers: Object.fromEntries(new Headers(init.headers)) });
97
- };
98
- const path = claim?.mode === 'signed' ? claim.path ?? '/auth/owner-claim' : owner?.path ?? claim?.path ?? '/auth/bootstrap';
99
- const issued = seconds();
100
- const claimToken = claim?.mode === 'signed' ? await signJws(pair.privateKey, kid, 'rer-owner-claim+jwt', {
101
- v: 1, iss: issuer, aud: hosted.origin, installationId, email, jti: randomUUID(), iat: issued, exp: issued + 300,
102
- }) : token;
74
+ const request = hostedRequest(hosted);
75
+ const { path, claimToken } = await ownerClaim({ claim, owner, hosted, keys, email });
103
76
  let bootstrap;
104
77
  try {
105
- bootstrap = native.initialize ? await native.initialize({ request, origin: hosted.origin, email, sub,
106
- reviewers: Object.freeze({ initialize: (label, session) => reviewers.initialize(label, session, { request, origin: hosted.origin, returnTo: owner?.returnTo ?? '/' }) }),
107
- 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,
108
- }) : await request(new URL(path, hosted.origin).href, { method: 'POST', redirect: 'manual',
109
- headers: { Origin: hosted.origin, 'Content-Type': 'application/json' },
110
- body: JSON.stringify({ token: claimToken, displayName: 'Synthetic Base 1', returnTo: owner?.returnTo ?? '/' }),
111
- });
78
+ bootstrap = await bootstrapOwner({ hosted, request, native, claim, owner, keys, email, sub, path, claimToken,
79
+ extra: { reviewers: reviewerDoor(reviewers, { request, hosted, owner }), mail: network.mail, fixtures: network.fixtures } });
112
80
  } catch {
113
81
  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);
114
82
  }
115
- const cookie = bootstrap.headers.getSetCookie().map(value => value.split(';', 1)[0]).join('; ');
116
- await bootstrap.body?.cancel();
117
- 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);
83
+ const { cookie, failure } = await ownerSession(bootstrap);
84
+ if (failure) return finish({ ok: false, points: [...validation.points, { id: 'BASE-AGENT-001.owner-bootstrap', ok: false, detail: failure }] }, report);
118
85
  const iat = seconds();
119
86
  const settings = await signJws(pair.privateKey, kid, 'rer-business-settings+jwt', {
120
87
  v: 1, iss: issuer, aud: hosted.origin, sub: installationId, business, email, owner_id: sub,
@@ -40,13 +40,20 @@ export async function writeVerificationHistory(hosted, declaration, rows) {
40
40
  // Both preparation APIs use this one disposable D1 writer. The public phase
41
41
  // handle exposes individual statements; declared history retains atomic batches
42
42
  // and its stricter insert-only, trigger-free table checks above.
43
- export function preparationDatabase(db) {
44
- const refuse = () => { throw new RerError('hosted_database_invalid', new FixtureDatabaseError().message, 1); };
43
+ // `diagnose` is for installs whose statements rer itself generates (rer size): the refusal then carries why
44
+ // (SQLite's own message, or the door's rule) as `diagnosis`. Agent-door fixtures never set it.
45
+ export function preparationDatabase(db, { diagnose = false } = {}) {
46
+ const refuse = reason => {
47
+ const error = new RerError('hosted_database_invalid', new FixtureDatabaseError().message, 1);
48
+ if (diagnose && reason !== undefined) error.diagnosis = String(reason);
49
+ throw error;
50
+ };
45
51
  const check = sql => {
46
- if (typeof sql !== 'string' || sql.includes(';')) return refuse();
52
+ const rule = 'the disposable database takes one SELECT, INSERT INTO table, UPDATE table or DELETE FROM table statement, with no ";" anywhere in it (write char(59) for a semicolon in a string) and not on an agent_door_ or sqlite_ table';
53
+ if (typeof sql !== 'string' || sql.includes(';')) return refuse(rule);
47
54
  const readOnly = /^\s*SELECT\b/i.test(sql);
48
55
  const target = /^\s*(?:UPDATE\s+|INSERT\s+INTO\s+|DELETE\s+FROM\s+)([a-z_][a-z0-9_]*)\b/i.exec(sql)?.[1];
49
- if (!readOnly && (!target || /^(?:agent_door_|sqlite_)/i.test(target))) return refuse();
56
+ if (!readOnly && (!target || /^(?:agent_door_|sqlite_)/i.test(target))) return refuse(rule);
50
57
  return { readOnly, target };
51
58
  };
52
59
  const batch = async rows => {
@@ -54,7 +61,7 @@ export function preparationDatabase(db) {
54
61
  const checked = rows.map(row => ({ ...row, ...check(row.sql) }));
55
62
  for (const { target } of checked.filter(row => !row.readOnly)) {
56
63
  const table = await db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name=? COLLATE NOCASE").bind(target).first();
57
- if (!table) return refuse();
64
+ if (!table) return refuse(`there is no table ${target}`);
58
65
  }
59
66
  const protectedTables = checked.some(row => !row.readOnly)
60
67
  ? (await db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND lower(substr(name,1,11))='agent_door_'").all()).results : [];
@@ -67,7 +74,7 @@ export function preparationDatabase(db) {
67
74
  ...guards.map(guard => db.prepare(`DROP TRIGGER "${guard.name}"`)),
68
75
  ]);
69
76
  return results.slice(guards.length, guards.length + checked.length);
70
- } catch { return refuse(); }
77
+ } catch (error) { return refuse(error?.diagnosis ?? error?.cause?.message ?? error?.message); }
71
78
  };
72
79
  const statement = (sql, values = []) => {
73
80
  check(sql);
package/cli/bounded.mjs CHANGED
@@ -5,13 +5,13 @@ import {fileURLToPath} from 'node:url';
5
5
  import {shared} from './shared.mjs';
6
6
  import {RerError} from './errors.mjs';
7
7
 
8
- // Admit the complete bounded workflow before it can acquire checkout custody.
8
+ // Admit the complete bounded workflow before it can acquire checkout custody. rer size's installs queue as verify does.
9
9
  // The child re-enters the same dispatcher with validated live queue membership.
10
10
  // Hold the child's semantic outcome until queue and process custody are released.
11
11
  // Child diagnostics remain captured/redacted on stderr. Long-lived servers never
12
12
  // enter this boundary.
13
13
  export async function boundedCommand(project,options,argv,out){
14
- if(!['install','setup','build','verify','deploy','export','import'].includes(options.verb))return null;
14
+ if(!['install','setup','build','verify','deploy','export','import','size'].includes(options.verb))return null;
15
15
  const {commandPolicy,queuedCommand,queueLabel,maxWaitSeconds}=await shared('queue.mjs');
16
16
  const policy=await commandPolicy();
17
17
  const childArgs=[...argv];const cwdIndex=childArgs.indexOf('--cwd');if(cwdIndex>=0&&(childArgs.indexOf('--')<0||cwdIndex<childArgs.indexOf('--')))childArgs[cwdIndex+1]=project.root;
@@ -24,7 +24,7 @@ export async function boundedCommand(project,options,argv,out){
24
24
  const {createCommands}=await shared('commands.mjs');
25
25
  store=await createCommands(directory,{logs:[]},{terminal:()=>{}});
26
26
  result=await queuedCommand(process.execPath,[fileURLToPath(new URL('../bin/rer.mjs',import.meta.url)),...childArgs],{
27
- cwd:project.root,verb:options.verb,signal:cancellation.signal,stdio:[!options.json&&!options.nonInteractive?'inherit':'ignore','pipe','pipe'],originalCI:policy.ci,env:{...process.env,...policy.environment,RER_BOUNDED_OUTPUT:'1'},
27
+ cwd:project.root,verb:options.verb==='size'?'verify':options.verb,signal:cancellation.signal,stdio:[!options.json&&!options.nonInteractive?'inherit':'ignore','pipe','pipe'],originalCI:policy.ci,env:{...process.env,...policy.environment,RER_BOUNDED_OUTPUT:'1'},
28
28
  label:await queueLabel(project.root,options.verb,'workflow'),report:text=>out.progress(store.redact(text)+'\n'),onWaiting:options.json?details=>out.event('waiting',details):undefined,
29
29
  spawn:(command,args,native)=>{
30
30
  const child=store.spawn('Running bounded workflow',command,args,native);
package/cli/contract.mjs CHANGED
@@ -25,6 +25,10 @@ export const demoVerb = Object.freeze({ bootstrap: 'before', flags: [...commonFl
25
25
  // `rer signin` is rer's own, not a seed operation: any seed rer deploys, it can
26
26
  // sign the owner in to, so no seed declares it and check does not ask for it.
27
27
  export const signinVerb = Object.freeze({ bootstrap: 'before', flags: [...commonFlags, '--environment', '--env-file'], effects: 'A one-time sign-in link for the hosted owner, without mail. Uses the Cloudflare credentials that deployed --environment (default production; from the environment or --env-file) to write a single-use grant for the recorded owner into that deployment\'s auth database, then prints the link once to this terminal; it is never saved. The link works once, only for that owner, expires within 15 minutes, and its use is recorded in the owner\'s audit log. Signed in this way, the owner can correct a wrong email in settings.' });
28
+ // `rer size` is rer's own too, never in `definitions`: check would otherwise ask
29
+ // every seed to declare it. It reads a checkout's D1 migrations, or a
30
+ // statements file, and runs in first-party and independent checkouts alike.
31
+ export const sizeVerb = Object.freeze({ bootstrap: 'before', flags: [...commonFlags, '--statements', '--migrations', '--declaration', '--write-statements', '--no-queue'], effects: 'Statement size against D1\'s limits, measured in SQLite on this computer with no account or network. D1 refuses a statement at 100 FROM items, counted with every CTE and view reference expanded in place, or at expression depth 100, and local SQLite and Miniflare accept both; rer fails at 90 of either, a margin of 10 because D1 changed how it enforces them without notice on 10 Nov 2026. With no flags it checks every view and trigger statement of the build\'s D1 migrations (dist/server/wrangler.json). --migrations DIR checks the objects of that migrations directory instead of the build\'s. --statements FILE checks the statements of FILE ({"statements":[{"name","sql"}]}, the fleet runner\'s format) against that schema. Each failure is named with both numbers and the start of its SQL. Exit 1 if any statement fails, 0 if none, 3 with no build and no --migrations. --json lists every statement as {name, fromItems, depth, ok}. With a size-check.json at the checkout root (or --declaration FILE, a declaration kept outside it), rer then builds the declared shape at a small and a large size, each in its own disposable local D1 install served as the hosted check serves the build: the owner is signed in with the bootstrap agent-door conformance uses (the setup manifest\'s owner-claim step, else verification.owner), each table is generated inside D1 by chunked INSERT … SELECT so the schema\'s own triggers fire, and each declared table is read back. It prints, for each size and table, the declared count, the count read back and the time per phase; a generation error names the size, the table, the row range, SQLite\'s message and its column, exits 1 and prints no built line for that size. budget.timeoutSeconds bounds both sizes and a timeout names the phase. While it serves installs it takes verify\'s job-queue slot (--no-queue only in the original CI environment). Then the personas sign in and every declared flow runs on each size, small first, through a rows-read meter wrapped around the Worker\'s D1 bindings (fetch, scheduled, queue, Durable Objects and waitUntil work; queues are held and queue consumer work is not measured). A flow fails when it reads more rows at large than its ceiling, more at large than at small by over growthPercent of small plus growthRows (unless growth.allowed), answers the wrong status, has a statement refused or failed by local D1, or runs a statement at 90 FROM items or depth; each failure names its rule and the three statements that read the most rows at large. --json carries every flow at both sizes; --write-statements DIR writes small.json and large.json in the fleet runner\'s statements format. --statements runs the statement check alone. rer verify runs the schema-object check as its last step.' });
28
32
  // Source-authoring commands belong to rer, not the seed adapter/OPERATIONS.
29
33
  // Their project-package bootstrap uses the same contract as every checkout verb.
30
34
  export const authoringVerbs = Object.freeze({
@@ -41,7 +45,7 @@ export const releaseVerb = Object.freeze({
41
45
  // All checkout commands, including those supplied by rer rather than declared
42
46
  // as seed operations. Bootstrap belongs to the selected command: before
43
47
  // dispatch, during launch, or never. A subcommand inherits its verb's policy.
44
- export const checkoutVerbs = Object.freeze({ ...verbs, ...authoringVerbs, demo: demoVerb, signin: signinVerb, release: releaseVerb });
48
+ export const checkoutVerbs = Object.freeze({ ...verbs, ...authoringVerbs, demo: demoVerb, signin: signinVerb, size: sizeVerb, release: releaseVerb });
45
49
  export function checkoutBootstrap([verb, ...args]) {
46
50
  if (args.includes('--help')) return 'never';
47
51
  const command = checkoutVerbs[verb];
@@ -1,4 +1,5 @@
1
1
  import { requireProductionAuth, mailOffNotice } from './production-auth.mjs';
2
+ import { enforceDeployPolicy } from './deploy-policy.mjs';
2
3
  import { observedReadiness } from '../modules/deploy-kit/readiness-window.mjs';
3
4
  import { readFile, readdir } from 'node:fs/promises';
4
5
  import { contained } from './project.mjs';
@@ -80,6 +81,7 @@ export async function deployCommand(context) {
80
81
  if (local) throw refuse(`${path} names the local-only key ${local} as a deploy binding or secret. Remove it; local dev keys never reach a deployment.`);
81
82
  deployGuide(declaration);
82
83
  const settings = adapter.hooks?.secrets ?? adapter.settings;
84
+ await enforceDeployPolicy({ ...context, declaration, declarationPath: path, settings });
83
85
  // Required secrets have been checked; retain the production sign-in guidance.
84
86
  const dryRun = async (result, { planned = true, extraNeeded } = {}) => {
85
87
  const production = await deployEnvironment({ root, options, declaration, setupManifest, settings, localOnlyKeys });
@@ -131,8 +133,6 @@ export async function deployCommand(context) {
131
133
  const command = async (verb, extra = [], values = env, more = {}) => owner([verb, '--declaration', path, '--environment', environment, ...(hookRecord ? ['--state', hookRecord] : []), ...(['dry-run', 'local-plan', 'deploy', 'health'].includes(verb) ? await deployProductArguments(root, productDirectory) : []), ...extra], values, { cwd: root, localOnlyKeys, ...more });
132
134
  // A hook that deployed through the kit's standard record lets rer issue and
133
135
  // retire the setup token; a hook keeping an unnamed record of its own keeps its token.
134
- // The hook reads that record: settle a secret change an earlier run left pending first, and stop if it cannot be.
135
- if (!options.dryRun && hookRecord) await command('settle');
136
136
  let recorded, hookReturned = false;
137
137
  const inspect = async (origin = deployed?.origin) => {
138
138
  try { return recorded = await command('inspect', [], env, hookReturned ? {} : {propagation:observedReadiness(origin)?.propagation}); }
@@ -142,6 +142,8 @@ export async function deployCommand(context) {
142
142
  let deployed, claimed, linked = false, linkResult, step = 'custom deploy';
143
143
  const link = async (token, origin) => { if (!linked) { const state = await inspect(origin); linkResult = await linkDependencies?.(state?.origin ?? origin, token); linked = true; } return linkResult; };
144
144
  try {
145
+ // The hook reads that record: settle a secret change an earlier run left pending first, and stop here, before the hook, if it cannot be.
146
+ if (!options.dryRun && hookRecord) { step = 'settle the recorded secret change'; await command('settle'); step = 'custom deploy'; }
145
147
  const result = await observeOwner({ paths: ['/auth/bootstrap', adapter.hooks?.owner?.path, setupManifest?.steps?.find(item => item.type === 'owner-claim')?.path].filter(Boolean), inspect, beforeClaim: link, addSecret, deployed: () => deployed, tokenKey: setupManifest?.steps?.find(item => item.type === 'owner-claim')?.tokenField }, async claims => {
146
148
  observedClaims = claims;
147
149
  const saved = { ...process.env };
@@ -0,0 +1,17 @@
1
+ import { deployEnvironment } from './deploy-inputs.mjs';
2
+ import { invalid } from './errors.mjs';
3
+
4
+ // Seed policy is separate from uploading: secret-only commands bypass the
5
+ // deploy hook, but must not bypass a seed's applicable local input policy.
6
+ export async function enforceDeployPolicy({ adapter, root, options, setupManifest, localOnlyKeys, declaration, declarationPath, settings }) {
7
+ if (adapter.deployPolicy === undefined) return;
8
+ if (typeof adapter.deployPolicy !== 'function') throw invalid('The adapter deployPolicy must be a function.');
9
+ const { env } = await deployEnvironment({ root, options, declaration, setupManifest, settings, localOnlyKeys });
10
+ // Resolve declared environment aliases before policy sees Worker bindings.
11
+ // Arbitrary ambient binding-name values never override an explicit mapping.
12
+ const bindings = { ...declaration.vars };
13
+ for (const secret of declaration.secrets ?? []) {
14
+ if (env[secret.environment]?.trim()) bindings[secret.binding] = env[secret.environment];
15
+ }
16
+ await adapter.deployPolicy({ root, options: { ...options }, environment: options.environment ?? 'production', env, bindings, declaration, declarationPath });
17
+ }
@@ -1,7 +1,7 @@
1
1
  import { readFile, readdir, realpath } from 'node:fs/promises';
2
2
  import { createRequire } from 'node:module';
3
3
  import { createHash, randomBytes } from 'node:crypto';
4
- import { join, resolve, extname } from 'node:path';
4
+ import { dirname, join, resolve, extname } from 'node:path';
5
5
  import { pathToFileURL } from 'node:url';
6
6
  import { RUN_WORKER_FIRST } from '../modules/deploy-kit/render.mjs';
7
7
  import { publicAssetPaths } from '../modules/deploy-kit/artifact.mjs';
@@ -17,6 +17,7 @@ import { verificationRpc } from './agent-rpc.mjs';
17
17
  import { hostedOrigins } from './hosted-hosts.mjs';
18
18
  import { preparationProducers } from './hosted-queue-producers.mjs';
19
19
  import { FixtureDatabaseError } from '../modules/agent-door/conformance/fixtures.mjs';
20
+ import { meterModule } from './size/meter.mjs';
20
21
 
21
22
  // Serve the production build the way rer deploy hosts it (assets behind the
22
23
  // Worker, deploy identity bound, a public https origin) on loopback, with no
@@ -84,12 +85,14 @@ async function hostedPublicVariables(root, config, declaration, manifest) {
84
85
 
85
86
  /** The build served as rer deploy hosts it, with declared vars, origin and
86
87
  * required public inputs and deploy/Managed mail secret stand-ins. `fetch(path, init)` uses the deployed origin. */
87
- export async function serveHosted(root, { declaration: declarationPath = 'deploy.json', bindings = {}, outboundService, rpc, workerEntrypoints = [], publicHosts, fixturePreparation = false } = {}) {
88
+ export async function serveHosted(root, { declaration: declarationPath = 'deploy.json', wrangler = 'dist/server/wrangler.json', bindings = {}, outboundService, rpc, workerEntrypoints = [], publicHosts, fixturePreparation = false, fixtureDiagnostics = false, meter } = {}) {
88
89
  const { loopbackFetch } = await shared('loopback-fetch.mjs');
89
- const build = join(root, 'dist/server'), client = join(root, 'dist/client');
90
+ const build = dirname(join(root, wrangler));
90
91
  let config;
91
- try { config = await read(join(build, 'wrangler.json')); }
92
- catch { throw new RerError('hosted_output_missing', 'No production build at dist/server/wrangler.json. Run rer build, then rer verify.', 1); }
92
+ try { config = await read(join(root, wrangler)); }
93
+ catch { throw new RerError('hosted_output_missing', `No production build at ${wrangler}. Run rer build, then rer verify.`, 1); }
94
+ // The build's own wrangler file says where its assets are: ../client from dist/server.
95
+ const client = resolve(build, config.assets?.directory ?? '../client');
93
96
  let declaration;
94
97
  try { declaration = await read(join(root, declarationPath)); }
95
98
  catch { throw new RerError('hosted_output_missing', `No readable deploy declaration at ${declarationPath}. A seed whose deploy reads another file names it with the commandAdapter option deployDeclaration.`, 1); }
@@ -144,6 +147,17 @@ export async function serveHosted(root, { declaration: declarationPath = 'deploy
144
147
  } };
145
148
  producers = preparationProducers(options, config);
146
149
  }
150
+ // `rer size` only: the rows-read meter wraps the app's D1 bindings, composed over the preparation wrapper when
151
+ // there is one. Every other caller leaves `meter` unset and serves the unwrapped build.
152
+ if (meter) {
153
+ const app = options.workers.find(worker => worker.name === 'app');
154
+ app.modules = [{ type: 'ESModule', path: join(build, '__rer_meter.mjs'), contents: meterModule({
155
+ inner: fixturePreparation ? './__rer_preparation.mjs' : './' + config.main,
156
+ d1: (config.d1_databases ?? []).map(item => item.binding),
157
+ durableObjects: (config.durable_objects?.bindings ?? []).filter(item => !item.script_name).map(item => item.class_name),
158
+ }) }, ...app.modules];
159
+ app.serviceBindings = { ...app.serviceBindings, RER_SIZE_METER: meter.service };
160
+ }
147
161
  const mf = new Miniflare(convertV4MiniflareOptions(options));
148
162
  let loopback;
149
163
  try {
@@ -160,7 +174,7 @@ export async function serveHosted(root, { declaration: declarationPath = 'deploy
160
174
  } catch (error) { await mf.dispose(); throw error; }
161
175
  const preparedDatabase = async binding => {
162
176
  if (!(config.d1_databases ?? []).some(item => item.binding === binding)) throw new RerError('hosted_database_invalid', new FixtureDatabaseError().message, 1);
163
- return preparationDatabase(await mf.getD1Database(binding, 'app'));
177
+ return preparationDatabase(await mf.getD1Database(binding, 'app'), { diagnose: fixtureDiagnostics });
164
178
  };
165
179
  const hosted = { client, identity, origin: HOSTED_ORIGIN, origins,
166
180
  worker: async entrypoint => {
@@ -173,13 +187,14 @@ export async function serveHosted(root, { declaration: declarationPath = 'deploy
173
187
  if (!fixturePreparation) throw new RerError('hosted_database_invalid', 'Native preparation requires a disposable conformance host.', 1);
174
188
  return Object.freeze({
175
189
  database: async binding => (await preparedDatabase(binding)).database,
176
- scheduled: async ({ scheduledTime = Date.now() } = {}) => {
190
+ scheduled: async ({ scheduledTime = Date.now(), cron } = {}) => {
177
191
  if (!Number.isFinite(scheduledTime)) throw new Error('Native scheduled preparation requires a finite Unix millisecond time.');
192
+ if (cron !== undefined && (typeof cron !== 'string' || !cron.trim())) throw new Error('Native scheduled preparation takes a cron expression as text.');
178
193
  try {
179
- const result = await (await mf.getWorker('app')).scheduled({ scheduledTime });
180
- if (result.outcome !== 'ok') throw new Error();
194
+ const result = await (await mf.getWorker('app')).scheduled({ scheduledTime, ...(cron === undefined ? {} : { cron }) });
195
+ if (result.outcome !== 'ok') throw new Error(result.outcome);
181
196
  }
182
- catch { throw new Error('Native scheduled preparation failed; fixture values are not logged.'); }
197
+ catch (error) { throw new Error(`Native scheduled preparation failed${fixtureDiagnostics && error.message ? ` (${error.message})` : ''}; fixture values are not logged.`); }
183
198
  },
184
199
  queues: Object.freeze({ hold: () => { held = true; }, release, ...producers(mf) }),
185
200
  });
@@ -207,6 +222,11 @@ export async function serveHosted(root, { declaration: declarationPath = 'deploy
207
222
  loopback = await mf.ready;
208
223
  };
209
224
  },
225
+ // A WebSocket upgrade through the ingress, which the loopback fetch cannot carry: the response holds `webSocket`.
226
+ upgrade: (path, { headers, origin = HOSTED_ORIGIN } = {}) => {
227
+ if (!origins.includes(origin)) throw new RerError('agent_door_origin', 'Agent conformance request must use a declared hosted installation origin.', 1);
228
+ return mf.dispatchFetch(`http://127.0.0.1/${path}`, { headers: { ...headers, upgrade: 'websocket', 'x-rer-original-url': `${origin}/${path}` } });
229
+ },
210
230
  close: () => { release(); return mf.dispose(); },
211
231
  fetch: (path, { headers, origin = HOSTED_ORIGIN, ...init } = {}) => {
212
232
  if (!origins.includes(origin)) throw new RerError('agent_door_origin', 'Agent conformance request must use a declared hosted installation origin.', 1);
@@ -0,0 +1,85 @@
1
+ import { randomBytes, randomUUID, webcrypto } from 'node:crypto';
2
+ import { seconds, signJws } from '../modules/agent-door/conformance/crypto.mjs';
3
+ import { RerError } from './errors.mjs';
4
+ import { HOSTED_ORIGIN } from './hosted-output.mjs';
5
+ import { verificationBindings } from './agent-bindings.mjs';
6
+
7
+ // The verification owner of a disposable hosted installation: the keys and token its claim is signed or
8
+ // presented with, the bindings that make the installation accept them, the bootstrap request (or the seed's own
9
+ // verification.owner initializer) and the check that it ended in a 303 with a session cookie. Agent-door
10
+ // conformance and `rer size` both sign the owner in this way.
11
+
12
+ // Unpairing re-serves the installation without the Business trust it was paired with.
13
+ export const pairedBindings = ['RER_OWNER_CLAIM_ISSUER', 'RER_OWNER_CLAIM_INSTALLATION_ID', 'RER_OWNER_CLAIM_APP_ORIGIN', 'RER_OWNER_CLAIM_PUBLIC_KEYS', 'RER_BUSINESS_TRUST'];
14
+
15
+ /** A fresh token and claim key ring for one installation, and the seed's native owner bindings generated from them. */
16
+ export async function ownerKeys(root, native, { email, sub }) {
17
+ const token = randomBytes(32).toString('hex'), kid = randomUUID(), installationId = randomUUID();
18
+ const business = 'rer-agent-conformance';
19
+ const issuer = `https://synthetic-base-1-${randomUUID()}.invalid`;
20
+ const pair = await webcrypto.subtle.generateKey({ name: 'ECDSA', namedCurve: 'P-256' }, true, ['sign', 'verify']);
21
+ const { kty, crv, x, y } = await webcrypto.subtle.exportKey('jwk', pair.publicKey);
22
+ const publicKeys = { [kid]: { kty, crv, x, y, kid, alg: 'ES256', use: 'sig' } };
23
+ const values = { issuer, installationId, appOrigin: HOSTED_ORIGIN, publicKeys: JSON.stringify(publicKeys), email, sub, token, sessionSecret: randomBytes(32).toString('hex') };
24
+ const nativeBindings = await verificationBindings(root, native.bindings, values);
25
+ return { token, kid, installationId, business, issuer, pair, publicKeys, nativeBindings };
26
+ }
27
+
28
+ /** The bindings serveHosted gets so the installation accepts the owner claim. */
29
+ export const ownerBindings = ({ issuer, installationId, publicKeys, token, nativeBindings }, { claim, native, email }) => ({
30
+ RER_OWNER_CLAIM_ISSUER: issuer, RER_OWNER_CLAIM_INSTALLATION_ID: installationId,
31
+ RER_OWNER_CLAIM_APP_ORIGIN: HOSTED_ORIGIN,
32
+ RER_OWNER_CLAIM_PUBLIC_KEYS: JSON.stringify(publicKeys),
33
+ RER_BUSINESS_TRUST: JSON.stringify({ v: 1, issuer, audience: HOSTED_ORIGIN, subject: installationId, email, keys: publicKeys }),
34
+ OWNER_EMAIL: email, SETUP_TOKEN: token,
35
+ ...(claim?.emailField ? { [claim.emailField]: email } : {}),
36
+ ...(claim?.tokenField ? { [claim.tokenField]: token } : {}),
37
+ ...(native.emailField ? { [native.emailField]: email } : {}),
38
+ ...(native.tokenField ? { [native.tokenField]: token } : {}),
39
+ ...nativeBindings,
40
+ });
41
+
42
+ /** A request to a declared hosted origin: refuses another origin or credentials in the URL, times out at 30 s. */
43
+ export const hostedRequest = hosted => (absolute, init = {}) => {
44
+ const url = new URL(absolute);
45
+ if (url.username || url.password || !hosted.origins.includes(url.origin)) throw new RerError('agent_door_origin', 'Agent conformance request must use a declared hosted installation origin.', 1);
46
+ const timeout = AbortSignal.timeout(30_000);
47
+ return hosted.fetch(url.href.slice(url.origin.length + 1), { ...init, origin: url.origin, signal: init.signal ? AbortSignal.any([init.signal, timeout]) : timeout, headers: Object.fromEntries(new Headers(init.headers)) });
48
+ };
49
+
50
+ /** Where the owner claim is presented, and what is presented: a signed claim for the signed mode, else the setup token. */
51
+ export async function ownerClaim({ claim, owner, hosted, keys, email }) {
52
+ const { token, kid, installationId, issuer, pair } = keys;
53
+ const path = claim?.mode === 'signed' ? claim.path ?? '/auth/owner-claim' : owner?.path ?? claim?.path ?? '/auth/bootstrap';
54
+ const issued = seconds();
55
+ const claimToken = claim?.mode === 'signed' ? await signJws(pair.privateKey, kid, 'rer-owner-claim+jwt', {
56
+ v: 1, iss: issuer, aud: hosted.origin, installationId, email, jti: randomUUID(), iat: issued, exp: issued + 300,
57
+ }) : token;
58
+ return { path, claimToken };
59
+ }
60
+
61
+ /** The bootstrap: the seed's native owner initializer, else the claim POSTed to the claim path. `extra` carries the
62
+ * caller's own initializer arguments (agent-door adds its reviewers, mail and fixtures). */
63
+ export function bootstrapOwner({ hosted, request, native, claim, owner, keys, email, sub, path, claimToken, extra = {} }) {
64
+ return native.initialize ? native.initialize({ request, origin: hosted.origin, email, sub,
65
+ ...extra,
66
+ displayName: 'Synthetic Base 1', label: native.label, database: hosted.database, token: keys.token, claim: { mode: claim?.mode ?? 'setup-token', path, token: claimToken }, returnTo: owner?.returnTo ?? '/',
67
+ }) : request(new URL(path, hosted.origin).href, { method: 'POST', redirect: 'manual',
68
+ headers: { Origin: hosted.origin, 'Content-Type': 'application/json' },
69
+ body: JSON.stringify({ token: claimToken, displayName: 'Synthetic Base 1', returnTo: owner?.returnTo ?? '/' }),
70
+ });
71
+ }
72
+
73
+ /** What the owner initializer gets as `reviewers`: it signs the declared native reviewers in with the owner's session. */
74
+ export const reviewerDoor = (reviewers, { request, hosted, owner }) => Object.freeze({
75
+ initialize: (label, session) => reviewers.initialize(label, session, { request, origin: hosted.origin, returnTo: owner?.returnTo ?? '/' }),
76
+ });
77
+
78
+ /** The owner's session cookie from the bootstrap response, or why it is not a session: the bootstrap must end in a
79
+ * 303 that was not followed and sets a cookie. */
80
+ export async function ownerSession(bootstrap) {
81
+ const cookie = bootstrap.headers.getSetCookie().map(value => value.split(';', 1)[0]).join('; ');
82
+ await bootstrap.body?.cancel();
83
+ if (bootstrap.status !== 303 || bootstrap.redirected || !cookie) return { cookie, failure: `Native owner bootstrap returned HTTP ${bootstrap.status}${!cookie ? ' without a session cookie' : ''}.` };
84
+ return { cookie };
85
+ }
package/cli/inspect.mjs CHANGED
@@ -5,7 +5,7 @@ import { inventory } from './export.mjs';
5
5
  import { lstat, readFile } from 'node:fs/promises';
6
6
  import { createHash } from 'node:crypto';
7
7
  import { delimiter, dirname, resolve } from 'node:path';
8
- import { authoringVerbs, aliases, demoVerb, pins, requiredHooks, serverDefaults, signinVerb, verbs, releaseFlags } from './contract.mjs';
8
+ import { authoringVerbs, aliases, demoVerb, pins, requiredHooks, serverDefaults, signinVerb, sizeVerb, verbs, releaseFlags } from './contract.mjs';
9
9
  import { runningVersion } from './version.mjs';
10
10
  import { contained, readPackage } from './project.mjs';
11
11
  import { shared } from './shared.mjs';
@@ -26,6 +26,7 @@ import { checkoutPlaceholderMarks } from './placeholder-mark.mjs';
26
26
  import { contractStatusClauses } from './contract-status.mjs';
27
27
  import { hostedExportCommand } from './hosted-export-command.mjs';
28
28
  import { agentSurfaceClauses } from './agent-surface.mjs';
29
+ import { sizeCheckClauses } from './size/clauses.mjs';
29
30
 
30
31
  // cliVersion: the rer version of the code answering (absent for a vendored copy
31
32
  // too old to record one). defaults: what a server start applies when the person
@@ -51,7 +52,9 @@ export async function describe(project) {
51
52
  }).concat(capabilities.dev?.flags?.includes('--demo') ? [['demo', { flags: demoVerb.flags.filter(flag => capabilities.dev.flags.includes(flag)), effects: demoVerb.effects }]] : [])
52
53
  // rer signin is rer's own: any seed it can deploy, it can sign the owner in to.
53
54
  .concat(Object.entries(authoringVerbs))
54
- .concat(capabilities.deploy ? [['signin', { flags: signinVerb.flags, effects: signinVerb.effects }]] : [])),
55
+ .concat(capabilities.deploy ? [['signin', { flags: signinVerb.flags, effects: signinVerb.effects }]] : [])
56
+ // So is rer size: it reads migrations, whatever the seed declares.
57
+ .concat([['size', { flags: sizeVerb.flags, effects: sizeVerb.effects }]])),
55
58
  aliases: Object.fromEntries(Object.entries(aliases).filter(([alias, verb]) => pkg.scripts?.[alias] === commandLine(verb, declaredPackage(pkg) !== undefined))),
56
59
  local: { state: project.adapter?.state, settings: project.adapter?.settings ?? [], installerState: '.seed/installer', ...await localState(project), origin: await savedOrigin(project), ...(project.adapter?.devIdentity ? { devIdentity: true, devKey: '.rer/local/dev-key.env' } : {}) },
57
60
  // This pin serves a checkout through the machine's front door (rer door).
@@ -84,6 +87,7 @@ export async function check(project, explicitProfile) {
84
87
  clauses.push(...await deliveryDeclarationClauses(project.root));
85
88
  clauses.push(await deployVariableClause(project.root, project.adapter));
86
89
  clauses.push(...await agentSurfaceClauses(project.root));
90
+ clauses.push(...await sizeCheckClauses(project.root, project.adapter));
87
91
  for (const command of project.commands) add('SC-10.inputs.' + command.name, command.available, `Restore the declared inputs for ${command.name}.`);
88
92
  for (const loop of project.descriptor.loops ?? []) add('SC-10.loop.' + loop.id, !loop.required || loop.enabled, `Enable the required ${loop.id} loop or correct its declaration.`);
89
93
  if (project.profile === 'first-party' || explicitProfile === 'first-party') {