@runeditrun/rer 0.2.109 → 0.2.111

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 (67) hide show
  1. package/README.md +24 -0
  2. package/cli/agent-door.mjs +12 -45
  3. package/cli/agent-history-database.mjs +13 -6
  4. package/cli/bounded.mjs +3 -3
  5. package/cli/contract.mjs +5 -1
  6. package/cli/deploy-command.mjs +5 -2
  7. package/cli/deploy-inputs.mjs +1 -1
  8. package/cli/deploy-needs.mjs +12 -1
  9. package/cli/hosted-output.mjs +30 -10
  10. package/cli/hosted-owner.mjs +85 -0
  11. package/cli/inspect.mjs +23 -12
  12. package/cli/lifecycle.mjs +6 -2
  13. package/cli/main.mjs +13 -0
  14. package/cli/parse.mjs +4 -4
  15. package/cli/pnpm-chatter.mjs +25 -0
  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 +51 -0
  47. package/global/README.md +24 -0
  48. package/global/cli/path-link.mjs +1 -1
  49. package/global/launch/dev.mjs +2 -2
  50. package/global/main.mjs +1 -1
  51. package/modules/agent-door/conformance/audit.mjs +3 -0
  52. package/modules/d1-transport/limits.mjs +5 -1
  53. package/modules/deploy-kit/sql-tokens.mjs +5 -4
  54. package/modules/operator-auth/README.md +1 -1
  55. package/modules/operator-auth/accounts/admin.mjs +9 -3
  56. package/modules/operator-auth/accounts/one-click.mjs +8 -1
  57. package/modules/operator-auth/dev/index.mjs +7 -1
  58. package/modules/operator-auth/dev/invited.mjs +11 -0
  59. package/modules/operator-auth/dev-gate.mjs +4 -3
  60. package/modules/operator-auth/identity/email-link/index.mjs +2 -0
  61. package/modules/operator-auth/index.d.mts +2 -1
  62. package/modules/operator-auth/routes.mjs +4 -0
  63. package/modules/release/README.md +8 -0
  64. package/modules/release/archive-guard.mjs +22 -0
  65. package/modules/release/archive-members.mjs +49 -0
  66. package/modules/release/export.mjs +7 -1
  67. package/package.json +2 -1
package/README.md CHANGED
@@ -319,6 +319,7 @@ line that still names it. A later refresh is a version bump:
319
319
  | `@runeditrun/rer/jsonc` | JSONC reading | `scripts/base-cli/cli/jsonc.mjs` |
320
320
  | `@runeditrun/rer/parse`, `/scheduled` | CLI argument parsing, scheduled-job helpers | `scripts/base-cli/cli/parse.mjs`, `scheduled.mjs` |
321
321
  | `@runeditrun/rer/dev-identity` | dev identity helpers | `scripts/base-cli/cli/dev-identity.mjs` |
322
+ | `@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
323
  | `@runeditrun/rer/operator-installer` | `operatorInstaller`, `developmentTarget`, `previewTarget` | `scripts/base-onboarding/operator-installer.mjs` |
323
324
  | `@runeditrun/rer/local-installer` | `localInstaller` | `scripts/base-onboarding/adapter.mjs` |
324
325
  | `@runeditrun/rer/operator-install` | `installOperator` | `scripts/base-onboarding/operator-install.mjs` |
@@ -390,6 +391,29 @@ there lists its flags:
390
391
  `export`, `import`, `doctor`, `describe`, `check`, `release`,
391
392
  `release sign`, `release receipt` and `release keygen`.
392
393
 
394
+ `rer size` checks statement size against D1's limits: it fails a statement at 90
395
+ FROM items (counted with every CTE and view reference expanded) or expression
396
+ depth 90, where D1 refuses at 100 and local SQLite and Miniflare accept both.
397
+ With no flags it checks every view and trigger statement of the build's D1
398
+ migrations; `--migrations DIR` names a migrations directory instead, and
399
+ `--statements FILE` checks a statements file (`{"statements":[{"name","sql"}]}`)
400
+ against that schema. It runs in any checkout, needs no account, and exits 1 on
401
+ any failure, 0 otherwise and 3 with no build and no `--migrations`. `rer verify`
402
+ ends with the same check, inside its own job-queue slot, and fails exactly when
403
+ `rer size` would. With a `size-check.json` (or `--declaration FILE`, a
404
+ declaration kept outside the checkout) it also builds the declared shape at a
405
+ small and a large size on local D1, runs every declared flow on each through a
406
+ rows-read meter and fails a flow that passes its ceiling, reads more at large
407
+ than at small by over 10 percent plus 200 rows, answers the wrong status, has a
408
+ statement refused by local D1 or runs a statement at 90 FROM items or depth;
409
+ `--write-statements DIR` writes the statements each size ran in the fleet
410
+ runner's format. Without a `size-check.json`, verify's step checks the schema
411
+ objects and prints `Size check: undeclared (no size-check.json).` A checkout
412
+ without a seedContract runs it from the declaration's `build.wrangler` and
413
+ `build.deployDeclaration` and never forwards to a declared argv; its owner
414
+ persona needs an owner claim in `rer-setup.json` or `verification.owner` in
415
+ `agent-surface.json`.
416
+
393
417
  Anywhere: `rer list [DIR]`, `rer cli status|install|uninstall`, `rer update`,
394
418
  `rer queue NAME -- COMMAND`, `rer --version` and `rer --help`.
395
419
 
@@ -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];
@@ -131,8 +131,6 @@ export async function deployCommand(context) {
131
131
  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
132
  // A hook that deployed through the kit's standard record lets rer issue and
133
133
  // 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
134
  let recorded, hookReturned = false;
137
135
  const inspect = async (origin = deployed?.origin) => {
138
136
  try { return recorded = await command('inspect', [], env, hookReturned ? {} : {propagation:observedReadiness(origin)?.propagation}); }
@@ -142,6 +140,8 @@ export async function deployCommand(context) {
142
140
  let deployed, claimed, linked = false, linkResult, step = 'custom deploy';
143
141
  const link = async (token, origin) => { if (!linked) { const state = await inspect(origin); linkResult = await linkDependencies?.(state?.origin ?? origin, token); linked = true; } return linkResult; };
144
142
  try {
143
+ // 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.
144
+ if (!options.dryRun && hookRecord) { step = 'settle the recorded secret change'; await command('settle'); step = 'custom deploy'; }
145
145
  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
146
  observedClaims = claims;
147
147
  const saved = { ...process.env };
@@ -201,6 +201,9 @@ export async function deployCommand(context) {
201
201
  const outcome = error.owner ?? claimed ?? observedClaims.at(-1)?.outcome;
202
202
  const state = deployed?.deployed || recorded ? `The application is deployed at ${deployed?.origin ?? recorded.origin}; ${outcome ? `owner ${outcome}` : 'owner claim is not confirmed'}${recorded ? '; setup token retirement is not confirmed' : ''}.` : options.dryRun ? 'The dry run did not finish; nothing was deployed.' : 'The custom deploy did not finish; inspect its deployment record before recovery.';
203
203
  const redact = value => store.redact?.(redaction.redact(value)) ?? redaction.redact(value);
204
+ // A dry run whose own step stopped (a build, a seed's input check) has already printed why.
205
+ // Say it once: which step, its exit code and the same dry run to repeat. Nothing is deployed.
206
+ if (options.dryRun && Number.isInteger(error.childExitCode)) throw commandFailure(redact(`The dry run did not finish; nothing was deployed. ${error.message.split('\n', 1)[0].replace(', signal none.', '.')}\nWhat it printed above names the cause. Fix it and run ${again} again.`));
204
207
  const setup = hostedSetupFailure(error, { origin: deployed?.origin ?? recorded?.origin, again });
205
208
  if (setup) throw commandFailure(redact(setup));
206
209
  const readiness = mutationReadinessFailure(error, { again, redact });
@@ -98,5 +98,5 @@ export async function withDeployEnvironment(project, options, out, run) {
98
98
 
99
99
  export function deployAgain(options) {
100
100
  const quote = value => /^[a-zA-Z0-9_./-]+$/.test(value) ? value : `'${String(value).replaceAll("'", "'\"'\"'")}'`;
101
- return `rer deploy --environment ${quote(options.environment ?? 'production')}${options.envFile ? ` --env-file ${quote(options.envFile)}` : ''}${options.cwd ? ` --cwd ${quote(relative(process.cwd(), options.cwd) || '.')}` : ''}`;
101
+ return `rer deploy --environment ${quote(options.environment ?? 'production')}${options.envFile ? ` --env-file ${quote(options.envFile)}` : ''}${options.cwd ? ` --cwd ${quote(relative(process.cwd(), options.cwd) || '.')}` : ''}${options.dryRun ? ' --dry-run' : ''}`;
102
102
  }
@@ -40,12 +40,23 @@ export function missingCredentialsMessage(declaration, env, { dryRun = false, si
40
40
  ...(dryRun ? ['Needed for a real deploy (the dry run could not check the target):', ...neededForRealDeploy({declaration,env,signIn}).map(item => ` - ${item}`)] : [])].join('\n');
41
41
  }
42
42
 
43
+ // Naming a binding by the environment name a person sets can turn "MAIL_API_KEY (or
44
+ // SENDGRID_API_KEY)" into the same name twice: say each name once.
45
+ function onceEach(text) {
46
+ return text
47
+ .replace(/\b([A-Z][A-Z0-9_]*) or \1\b/g, '$1')
48
+ .replace(/\b([A-Z][A-Z0-9_]*) \(or ([^)]*)\)/g, (all, first, rest) => {
49
+ const others = [...new Set(rest.split(' / ').map(name => name.trim()))].filter(name => name !== first);
50
+ return others.length ? `${first} (or ${others.join(' / ')})` : first;
51
+ });
52
+ }
53
+
43
54
  // Setup guidance and failed dry-run inputs. After target resolution, held
44
55
  // secrets no longer count as missing local inputs.
45
56
  export function neededForRealDeploy({ declaration, env, signIn, secretsChecked = false }) {
46
57
  const declared = (Array.isArray(declaration.secrets) ? declaration.secrets : []).filter(item => item?.environment);
47
58
  // Sign-in names its inputs by binding; a person sets the environment name the declaration maps to it.
48
- const mail = signIn && declared.reduce((text, item) => item.binding === item.environment ? text : text.replace(new RegExp(`\\b${item.binding}\\b`, 'g'), item.environment), signIn);
59
+ const mail = signIn && onceEach(declared.reduce((text, item) => item.binding === item.environment ? text : text.replace(new RegExp(`\\b${item.binding}\\b`, 'g'), item.environment), signIn));
49
60
  const listed = name => cloudflareCredentials.includes(name) || mail && new RegExp(`\\b${name}\\b`).test(mail);
50
61
  const secrets = secretsChecked ? [] : [...new Set(declared.filter(item => !item.optional && !env[item.environment]?.trim()).map(item => item.environment))].filter(name => !listed(name));
51
62
  const credentials = secretsChecked ? [] : cloudflareCredentials.filter(name => !env[name]?.trim());
@@ -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';
@@ -25,8 +25,8 @@ import { deliveryDeclarationClauses } from './delivery-declarations.mjs';
25
25
  import { checkoutPlaceholderMarks } from './placeholder-mark.mjs';
26
26
  import { contractStatusClauses } from './contract-status.mjs';
27
27
  import { hostedExportCommand } from './hosted-export-command.mjs';
28
- import { cloudflareCredentials } from './deploy-needs.mjs';
29
28
  import { agentSurfaceClauses } from './agent-surface.mjs';
29
+ import { sizeCheckClauses } from './size/clauses.mjs';
30
30
 
31
31
  // cliVersion: the rer version of the code answering (absent for a vendored copy
32
32
  // too old to record one). defaults: what a server start applies when the person
@@ -52,7 +52,9 @@ export async function describe(project) {
52
52
  }).concat(capabilities.dev?.flags?.includes('--demo') ? [['demo', { flags: demoVerb.flags.filter(flag => capabilities.dev.flags.includes(flag)), effects: demoVerb.effects }]] : [])
53
53
  // rer signin is rer's own: any seed it can deploy, it can sign the owner in to.
54
54
  .concat(Object.entries(authoringVerbs))
55
- .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 }]])),
56
58
  aliases: Object.fromEntries(Object.entries(aliases).filter(([alias, verb]) => pkg.scripts?.[alias] === commandLine(verb, declaredPackage(pkg) !== undefined))),
57
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' } : {}) },
58
60
  // This pin serves a checkout through the machine's front door (rer door).
@@ -85,6 +87,7 @@ export async function check(project, explicitProfile) {
85
87
  clauses.push(...await deliveryDeclarationClauses(project.root));
86
88
  clauses.push(await deployVariableClause(project.root, project.adapter));
87
89
  clauses.push(...await agentSurfaceClauses(project.root));
90
+ clauses.push(...await sizeCheckClauses(project.root, project.adapter));
88
91
  for (const command of project.commands) add('SC-10.inputs.' + command.name, command.available, `Restore the declared inputs for ${command.name}.`);
89
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.`);
90
93
  if (project.profile === 'first-party' || explicitProfile === 'first-party') {
@@ -206,16 +209,12 @@ const usePnpm = directory => {
206
209
  process.env.PATH = [process.env.PATH, directory, dirname(process.execPath)].filter(value => value !== undefined).join(delimiter);
207
210
  };
208
211
 
212
+ // The deploy kit's trusted build workflow supplies these (modules/deploy-kit/README.md); a person's computer never does.
213
+ const buildWorkflowInput = /^RER_(?:PREPARE|DEPLOY)_[A-Z0-9_]+$/;
214
+
209
215
  export async function doctor(project, store, signal) {
210
216
  const { inspectOperations } = await import('../operations/operations.mjs');
211
217
  const diagnostic = await inspectOperations(project.root);
212
- // The operations declaration includes deployment prerequisites. Local health
213
- // does not require an account, and doctor never checks provider access.
214
- const deploymentInputs = project.profile === 'first-party' ? diagnostic.missingEnvironment.filter(name => cloudflareCredentials.includes(name)) : [];
215
- if (deploymentInputs.length) {
216
- diagnostic.missingEnvironment = diagnostic.missingEnvironment.filter(name => !deploymentInputs.includes(name));
217
- diagnostic.ok = diagnostic.commands.every(command => command.available) && !diagnostic.missingEnvironment.length && diagnostic.configuration === 'valid' && (diagnostic.loops ?? []).every(loop => ['ready', 'optional-disabled'].includes(loop.status));
218
- }
219
218
  const { localVariables } = await shared('local/environment.mjs');
220
219
  let values = {}, pnpm, expectedPnpm, stateIssue, stateValid = true;
221
220
  const pnpmIssues = [];
@@ -247,12 +246,24 @@ export async function doctor(project, store, signal) {
247
246
  const dependencies=project.profile==='first-party'?await dependencyDoctor(project.root):[];
248
247
  const expectedNode = await projectNodePin(project.root);
249
248
  const inputs = project.profile === 'first-party' ? requiredLocalSettings(project, values) : [];
249
+ // The operations declaration also lists what a deployment needs, and the inputs a hosted build
250
+ // workflow supplies. Local health needs neither an account nor that workflow: a first-party
251
+ // checkout is ready when its local setup is done (the check `rer dev` makes), and doctor never
252
+ // checks provider access. Deploy inputs are named as optional; workflow inputs not at all.
253
+ const firstParty = project.profile === 'first-party';
254
+ const workflowInputs = firstParty ? diagnostic.missingEnvironment.filter(name => buildWorkflowInput.test(name)) : [];
255
+ const deploymentInputs = firstParty ? diagnostic.missingEnvironment.filter(name => !buildWorkflowInput.test(name) && !inputs.includes(name) && !(typeof values[name] === 'string' && values[name].trim())) : [];
256
+ if (firstParty) {
257
+ diagnostic.missingEnvironment = diagnostic.missingEnvironment.filter(name => inputs.includes(name));
258
+ diagnostic.ok = diagnostic.commands.every(command => command.available) && !diagnostic.missingEnvironment.length && diagnostic.configuration === 'valid' && (diagnostic.loops ?? []).every(loop => ['ready', 'optional-disabled'].includes(loop.status));
259
+ }
260
+ const setupNeeded = firstParty ? !(await localState(project)).prepared : false;
250
261
  const warnings = project.profile === 'first-party' ? await cacheWarnings(project.root) : [];
251
262
  return { dependencies, warnings, browser, operations: diagnostic, ok: browser?.ok !== false && !aiIssues.length && dependencies.every(d=>d.ok) && diagnostic.ok && stateValid && !inputs.length && (project.profile !== 'first-party' || (Boolean(expectedPnpm) && process.versions.node === expectedNode && pnpm === expectedPnpm)),
252
263
  node: { actual: process.versions.node, expected: expectedNode },
253
264
  pnpm: project.profile === 'first-party' ? { actual: pnpm, expected: expectedPnpm ?? null, ...(pnpmIssues.length ? { issue: [...new Set(pnpmIssues)].join('\n') } : {}) } : undefined,
254
265
  ai: { issues: aiIssues },
255
- missingInputs: [...new Set([...diagnostic.missingEnvironment, ...inputs])], deploymentInputs,
266
+ missingInputs: [...new Set([...diagnostic.missingEnvironment, ...inputs])], deploymentInputs, workflowInputs, setupNeeded: setupNeeded || (!firstParty && diagnostic.missingEnvironment.length > 0),
256
267
  sources: project.descriptor.environmentSources ?? {}, state: { path: project.adapter?.state, safe: stateValid, ...(stateIssue ? { issue: stateIssue } : {}) }, scope: 'local-inputs-only' };
257
268
  }
258
269
 
@@ -266,7 +277,7 @@ export function doctorSummary(result) {
266
277
  if (result.missingInputs.length) {
267
278
  lines.push('Missing local inputs:');
268
279
  for (const name of result.missingInputs) lines.push(` ${name}${result.sources[name] ? `: ${result.sources[name]}` : ''}`);
269
- lines.push('Run rer setup to configure this checkout.');
280
+ if (result.setupNeeded) lines.push('Run rer setup to configure this checkout.');
270
281
  }
271
282
  const unavailable = result.operations.commands.filter(command => !command.available);
272
283
  if (unavailable.length) lines.push('Unavailable command inputs:', ...unavailable.map(command => ` ${command.name}: restore its declared input files.`));
package/cli/lifecycle.mjs CHANGED
@@ -18,6 +18,7 @@ import { rememberSetupAnswers } from './setup-answers.mjs';
18
18
  import { ensureDevKey, refuseDevLayerOutput } from './dev-identity.mjs';
19
19
  import { withoutLocalSettings, refuseLocalEnvOutput } from './local-env.mjs';
20
20
  import { announceDoorRoute } from './door-mode.mjs';
21
+ import { withoutPnpmChatter } from './pnpm-chatter.mjs';
21
22
 
22
23
  export async function runCommand(project, options, out) {
23
24
  if (project.profile === 'first-party' && ['build', 'dev', 'preview', 'deploy'].includes(options.verb)) {
@@ -80,7 +81,8 @@ async function runLifecycle(project, options, out, deployRedaction) {
80
81
  const capture = ['.seed', 'installer', ...(process.env.RER_LOCAL_OPERATION || process.env.RER_ONBOARDING_PROCESS_OWNER ? [`commands-${process.pid}`] : [])];
81
82
  const directory = project.profile === 'first-party' && options.verb !== 'doctor' ? await privateDirectory(project.root, capture) : (temporary = await mkdtemp(join(tmpdir(), 'rer-command-')));
82
83
  const state = { logs: [] };
83
- store = await createCommands(directory, state, { terminal: text => { if (!installingFrozen || options.json) out.progress(text); }, onWaiting: options.json ? details => out.event('waiting', details) : undefined, queue: ['install','setup','build','verify','deploy','export','import'].includes(options.verb)?{verb:options.verb,originalCI:process.env.CI==='true'}:undefined });
84
+ const progress = text => { if (!installingFrozen || options.json) out.progress(text); };
85
+ store = await createCommands(directory, state, { terminal: options.verb === 'deploy' && options.dryRun ? withoutPnpmChatter(progress) : progress, onWaiting: options.json ? details => out.event('waiting', details) : undefined, queue: ['install','setup','build','verify','deploy','export','import'].includes(options.verb)?{verb:options.verb,originalCI:process.env.CI==='true'}:undefined });
84
86
  store.state = state;
85
87
  if (deployRedaction) store.addSecrets?.(Object.values(process.env).filter(value => value && deployRedaction.redact(value) !== value));
86
88
  store.setupManifest = project.setupManifest;
@@ -119,7 +121,9 @@ async function runLifecycle(project, options, out, deployRedaction) {
119
121
  await store.step('Checking that page sections hydrate as separate units');
120
122
  const hydration = await (await import('./hydration/check.mjs')).checkHydration(project.root, { pages: adapter.publicPages, declaration, report: lines => lines.forEach(line => store.report(line)) });
121
123
  const agentDoor = await (await import('./agent-door.mjs')).checkAgentDoor(project.root, { declaration, setupManifest: project.setupManifest, owner: adapter.hooks?.owner, report: line => store.report(line) });
122
- return { hosted, hydration, agentDoor };
124
+ await store.step('Checking statement size and growth with data');
125
+ const size = await (await import('./size/verify-step.mjs')).checkSizeStep(project.root, { report: line => store.report(line) });
126
+ return { hosted, hydration, agentDoor, size };
123
127
  }
124
128
  if (['export', 'import'].includes(options.verb)) return await transfer(project, options, signal, { store, operationToken: operation.token });
125
129
  if (options.verb === 'deploy') {