@runeditrun/rer 0.2.110 → 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 (57) 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 +2 -2
  7. package/cli/hosted-output.mjs +30 -10
  8. package/cli/hosted-owner.mjs +85 -0
  9. package/cli/inspect.mjs +6 -2
  10. package/cli/lifecycle.mjs +3 -1
  11. package/cli/main.mjs +13 -0
  12. package/cli/parse.mjs +4 -4
  13. package/cli/size/build-facts.mjs +58 -0
  14. package/cli/size/build-paths.mjs +3 -0
  15. package/cli/size/check.mjs +16 -0
  16. package/cli/size/clauses.mjs +21 -0
  17. package/cli/size/clock.mjs +21 -0
  18. package/cli/size/command.mjs +64 -0
  19. package/cli/size/declaration.mjs +87 -0
  20. package/cli/size/dml-parts.mjs +108 -0
  21. package/cli/size/examples/happytohelp.json +68 -0
  22. package/cli/size/expression-depth.mjs +45 -0
  23. package/cli/size/expression.mjs +33 -0
  24. package/cli/size/fixture.mjs +139 -0
  25. package/cli/size/flows.mjs +81 -0
  26. package/cli/size/from-items.mjs +124 -0
  27. package/cli/size/grow.mjs +83 -0
  28. package/cli/size/install.mjs +136 -0
  29. package/cli/size/json-duplicates.mjs +45 -0
  30. package/cli/size/limits.mjs +9 -0
  31. package/cli/size/measure.mjs +9 -0
  32. package/cli/size/meter.mjs +167 -0
  33. package/cli/size/personas.mjs +138 -0
  34. package/cli/size/report.mjs +23 -0
  35. package/cli/size/schema-objects.mjs +80 -0
  36. package/cli/size/schema.mjs +56 -0
  37. package/cli/size/statements.mjs +53 -0
  38. package/cli/size/validate-flows.mjs +109 -0
  39. package/cli/size/validate-kit.mjs +44 -0
  40. package/cli/size/validate-shape.mjs +75 -0
  41. package/cli/size/verdict.mjs +131 -0
  42. package/cli/size/verify-step.mjs +35 -0
  43. package/global/CHANGELOG.md +31 -0
  44. package/global/README.md +24 -0
  45. package/modules/agent-door/conformance/audit.mjs +3 -0
  46. package/modules/d1-transport/limits.mjs +5 -1
  47. package/modules/deploy-kit/sql-tokens.mjs +5 -4
  48. package/modules/operator-auth/accounts/one-click.mjs +2 -0
  49. package/modules/operator-auth/dev/index.mjs +7 -1
  50. package/modules/operator-auth/dev/invited.mjs +11 -0
  51. package/modules/operator-auth/dev-gate.mjs +3 -2
  52. package/modules/operator-auth/routes.mjs +4 -0
  53. package/modules/release/README.md +8 -0
  54. package/modules/release/archive-guard.mjs +22 -0
  55. package/modules/release/archive-members.mjs +49 -0
  56. package/modules/release/export.mjs +7 -1
  57. 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 };
@@ -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') {
package/cli/lifecycle.mjs CHANGED
@@ -121,7 +121,9 @@ async function runLifecycle(project, options, out, deployRedaction) {
121
121
  await store.step('Checking that page sections hydrate as separate units');
122
122
  const hydration = await (await import('./hydration/check.mjs')).checkHydration(project.root, { pages: adapter.publicPages, declaration, report: lines => lines.forEach(line => store.report(line)) });
123
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) });
124
- 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 };
125
127
  }
126
128
  if (['export', 'import'].includes(options.verb)) return await transfer(project, options, signal, { store, operationToken: operation.token });
127
129
  if (options.verb === 'deploy') {
package/cli/main.mjs CHANGED
@@ -6,6 +6,7 @@ import { invalid, RerError } from './errors.mjs';
6
6
  import { resolveProject, parsingProfile } from './project.mjs';
7
7
  import { check, describe, doctorSummary } from './inspect.mjs';
8
8
  import { selectNodeRuntime } from './node-runtime.mjs';
9
+ import { resolve } from 'node:path';
9
10
 
10
11
  export async function main(argv = process.argv.slice(2)) {
11
12
  if (argv[0] === 'door' && argv[1] === 'clauses') return (await import('./door-clauses.mjs')).doorClausesCommand(argv.slice(2));
@@ -22,6 +23,18 @@ export async function main(argv = process.argv.slice(2)) {
22
23
  if (options.verb === 'archive') return (await import('./archive.mjs')).archiveCommand(options.archiveArgs,out);
23
24
  if (options.verb === 'listing') return (await import('./listing.mjs')).dispatchListing(options.listingArgs);
24
25
  if (options.verb === 'release') return (await import('./release.mjs')).dispatchRelease(options.releaseArgs);
26
+ // rer's own, like release: it reads migrations and statement files, whatever the checkout's profile.
27
+ if (options.verb === 'size') {
28
+ // Building fixtures serves installs: that is heavy work, so it takes verify's job-queue slot.
29
+ if ((await import('./size/grow.mjs')).growthRequested(options)) {
30
+ if (options.noQueue) {const {shared}=await import('./shared.mjs');const {commandPolicy}=await shared('queue.mjs');const policy=await commandPolicy();try{if(!policy.ci)throw invalid('--no-queue requires the original caller CI=true.');}finally{await policy.close();}}
31
+ // The queued child runs in the checkout: a relative --declaration means the caller's folder, so hand it over absolute.
32
+ const named = ['--declaration', '--write-statements'].map(flag => argv.indexOf(flag) + 1).filter(Boolean), queuedArgv = argv.map((argument, index) => named.includes(index) ? resolve(process.cwd(), argument) : argument);
33
+ const bounded = await (await import('./bounded.mjs')).boundedCommand({ root: options.cwd, profile: 'independent' }, options, queuedArgv, out);
34
+ if (bounded) return bounded.exitCode;
35
+ }
36
+ return await (await import('./size/command.mjs')).sizeCommand(options, out);
37
+ }
25
38
  const independent = await parsingProfile(options.cwd)==='independent'&&!['describe','check','doctor'].includes(options.verb);
26
39
  options=parse(argv,process.cwd(),{independent});out=output(options);
27
40
  if (options.help) return showHelp(options,out);
package/cli/parse.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { resolve } from 'node:path';
2
- import { authoringVerbs, commonFlags, serverDefaults, signinVerb, verbs } from './contract.mjs';
2
+ import { authoringVerbs, commonFlags, serverDefaults, signinVerb, sizeVerb, verbs } from './contract.mjs';
3
3
  import { invalid, refuse } from './errors.mjs';
4
4
  import { isLoopbackHost } from '../modules/operator-auth/loopback.mjs';
5
5
  import { normalizeEmail } from '../modules/operator-auth/policy.mjs';
@@ -27,7 +27,7 @@ export function parse(argv, cwd = process.cwd(), { independent = false, deferTai
27
27
  // Independent projects own verb names; only the common wrapper flags apply
28
28
  // to unknown names. Profile resolution rejects undeclared commands later.
29
29
  if (!/^[a-z][a-z0-9-]*$/.test(verb)) throw invalid('Unknown rer command. Run rer --help.');
30
- const allowed = new Set(independent ? [...commonFlags,...(['install','setup','build','verify','deploy','release','export','import','dev','preview'].includes(verb)?['--no-queue']:[])] : (verbs[verb] ?? authoringVerbs[verb] ?? (verb === 'signin' ? signinVerb : undefined))?.flags ?? commonFlags), options = { verb, cwd: resolve(cwd), forwarded: [], supplied: new Set() };
30
+ const allowed = new Set(independent ? [...commonFlags,...(['install','setup','build','verify','deploy','release','export','import','dev','preview'].includes(verb)?['--no-queue']:[])] : (verbs[verb] ?? authoringVerbs[verb] ?? (verb === 'signin' ? signinVerb : verb === 'size' ? sizeVerb : undefined))?.flags ?? commonFlags), options = { verb, cwd: resolve(cwd), forwarded: [], supplied: new Set() };
31
31
  let separator = false;
32
32
  for (let i = 0; i < args.length; i++) {
33
33
  const flag = args[i];
@@ -109,8 +109,8 @@ export function parse(argv, cwd = process.cwd(), { independent = false, deferTai
109
109
  }
110
110
 
111
111
  export function help(verb) {
112
- if (!verb) return `Usage: rer VERB [FLAGS]\nCommands: ${Object.keys({...verbs, ...authoringVerbs}).join(', ')}, signin, release, listing\nRun rer VERB --help for flags.\n${appSignInHelp}\n`;
113
- const known = verbs[verb] ?? authoringVerbs[verb] ?? (verb === 'signin' ? signinVerb : undefined);
112
+ if (!verb) return `Usage: rer VERB [FLAGS]\nCommands: ${Object.keys({...verbs, ...authoringVerbs}).join(', ')}, signin, size, release, listing\nRun rer VERB --help for flags.\n${appSignInHelp}\n`;
113
+ const known = verbs[verb] ?? authoringVerbs[verb] ?? (verb === 'signin' ? signinVerb : verb === 'size' ? sizeVerb : undefined);
114
114
  const door = ['export', 'import'].includes(verb) ? 'To move records, start the app and open its signed-in owner import door:\n\n rer dev\n\nOpen /app/import, then export or upload and review supported records there.\n\nTo back up or restore this installation:\n' : '';
115
115
  return `${door}Usage: rer ${verb}${verb === 'refresh-base' ? ' --ref FULL_COMMIT' : ''} [FLAGS]\nFlags: ${(known?.flags ?? commonFlags).join(', ')}\n${known?.effects ?? 'Execute the declared OPERATIONS v2 argv with explicit arguments after --.'}\n`;
116
116
  }
@@ -0,0 +1,58 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { contained } from '../project.mjs';
3
+ import { parseJsonc } from '../jsonc.mjs';
4
+ import { deployConfigPaths } from '../deploy-config.mjs';
5
+ import { declaredCrons } from '../scheduled.mjs';
6
+ import { defaultBuild } from './build-paths.mjs';
7
+
8
+
9
+ async function readOptional(root, path) {
10
+ try { return await readFile(await contained(root, path, { optional: true }), 'utf8'); }
11
+ catch (error) { if (error.code === 'ENOENT') return null; throw error; }
12
+ }
13
+
14
+ // `binding = "DB"` inside [[d1_databases]] tables or an inline d1_databases list.
15
+ function tomlD1Bindings(source) {
16
+ const names = [];
17
+ let inside = false;
18
+ for (const line of source.split('\n').map(text => text.replace(/^\s*#.*/, ''))) {
19
+ const header = /^\s*\[+\s*([^\]]+?)\s*\]+\s*$/.exec(line);
20
+ if (header) { inside = header[1] === 'd1_databases'; continue; }
21
+ const inline = /^\s*d1_databases\s*=\s*(.*)$/.exec(line);
22
+ if (inline) for (const match of inline[1].matchAll(/binding\s*=\s*"([^"]+)"/g)) names.push(match[1]);
23
+ else if (inside) { const match = /^\s*binding\s*=\s*"([^"]+)"/.exec(line); if (match) names.push(match[1]); }
24
+ }
25
+ return names;
26
+ }
27
+
28
+ function jsonD1Bindings(config) {
29
+ return (Array.isArray(config.d1_databases) ? config.d1_databases : []).map(entry => entry?.binding).filter(name => typeof name === 'string');
30
+ }
31
+
32
+ // What a checkout declares that a size-check.json is checked against: its Cron Triggers and D1 bindings, read from
33
+ // the files `rer check` and `rer dev` already read (deploy-config.mjs), the deploy declaration and the optional build
34
+ // wrangler file. Nothing is built or run. `problems` lists files that cannot be read, each as { path, message }.
35
+ export async function buildFacts(root, adapter, build = {}) {
36
+ const crons = new Set(), bindings = new Set(), problems = [];
37
+ try { for (const cron of await declaredCrons(root, adapter)) crons.add(cron); }
38
+ catch (error) { problems.push({ path: 'flows', message: `The checkout's declared crons cannot be read (${error.message}); fix its wrangler or deploy configuration.` }); }
39
+ const wrangler = [...deployConfigPaths(adapter), build.wrangler ?? defaultBuild.wrangler];
40
+ for (const path of new Set(wrangler)) {
41
+ let source;
42
+ try { source = await readOptional(root, path); }
43
+ catch { problems.push({ path: 'build', message: `${path} cannot be read inside the checkout; point build.wrangler at a file in it.` }); continue; }
44
+ if (source === null) continue;
45
+ try { for (const name of /\.toml$/.test(path) ? tomlD1Bindings(source) : jsonD1Bindings(parseJsonc(source))) bindings.add(name); }
46
+ catch (error) { problems.push({ path: 'build', message: `${path} is not valid configuration (${error.message}); fix it.` }); }
47
+ }
48
+ const deployPath = build.deployDeclaration ?? defaultBuild.deployDeclaration;
49
+ try {
50
+ const source = await readOptional(root, deployPath);
51
+ if (source !== null) {
52
+ const declaration = JSON.parse(source);
53
+ for (const entry of Array.isArray(declaration.d1) ? declaration.d1 : []) if (typeof entry?.binding === 'string') bindings.add(entry.binding);
54
+ for (const cron of Array.isArray(declaration.crons) ? declaration.crons : []) if (typeof cron === 'string') crons.add(cron);
55
+ }
56
+ } catch { problems.push({ path: 'build', message: `${deployPath} cannot be read as JSON inside the checkout; point build.deployDeclaration at the deploy declaration.` }); }
57
+ return { crons: [...crons], bindings: [...bindings], problems };
58
+ }
@@ -0,0 +1,3 @@
1
+ // Where a build lives when size-check.json does not say: the Vite Cloudflare build's wrangler file (its main,
2
+ // migrations and assets are read relative to that file's folder) and the deploy declaration.
3
+ export const defaultBuild = { wrangler: 'dist/server/wrangler.json', deployDeclaration: 'deploy.json' };