@runeditrun/rer 0.2.110 → 0.2.112

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +39 -2
  2. package/cli/README.md +56 -0
  3. package/cli/agent-door.mjs +12 -45
  4. package/cli/agent-history-database.mjs +13 -6
  5. package/cli/bounded.mjs +3 -3
  6. package/cli/contract.mjs +5 -1
  7. package/cli/deploy-command.mjs +4 -2
  8. package/cli/deploy-policy.mjs +17 -0
  9. package/cli/hosted-output.mjs +30 -10
  10. package/cli/hosted-owner.mjs +85 -0
  11. package/cli/inspect.mjs +6 -2
  12. package/cli/lifecycle.mjs +5 -1
  13. package/cli/main.mjs +13 -0
  14. package/cli/parse.mjs +4 -4
  15. package/cli/portability.mjs +3 -3
  16. package/cli/size/build-facts.mjs +58 -0
  17. package/cli/size/build-paths.mjs +3 -0
  18. package/cli/size/check.mjs +16 -0
  19. package/cli/size/clauses.mjs +21 -0
  20. package/cli/size/clock.mjs +21 -0
  21. package/cli/size/command.mjs +64 -0
  22. package/cli/size/declaration.mjs +87 -0
  23. package/cli/size/dml-parts.mjs +108 -0
  24. package/cli/size/examples/happytohelp.json +68 -0
  25. package/cli/size/expression-depth.mjs +45 -0
  26. package/cli/size/expression.mjs +33 -0
  27. package/cli/size/fixture.mjs +139 -0
  28. package/cli/size/flows.mjs +81 -0
  29. package/cli/size/from-items.mjs +124 -0
  30. package/cli/size/grow.mjs +83 -0
  31. package/cli/size/install.mjs +136 -0
  32. package/cli/size/json-duplicates.mjs +45 -0
  33. package/cli/size/limits.mjs +9 -0
  34. package/cli/size/measure.mjs +9 -0
  35. package/cli/size/meter.mjs +167 -0
  36. package/cli/size/personas.mjs +138 -0
  37. package/cli/size/report.mjs +23 -0
  38. package/cli/size/schema-objects.mjs +80 -0
  39. package/cli/size/schema.mjs +56 -0
  40. package/cli/size/statements.mjs +53 -0
  41. package/cli/size/validate-flows.mjs +109 -0
  42. package/cli/size/validate-kit.mjs +44 -0
  43. package/cli/size/validate-shape.mjs +75 -0
  44. package/cli/size/verdict.mjs +131 -0
  45. package/cli/size/verify-step.mjs +35 -0
  46. package/global/CHANGELOG.md +50 -0
  47. package/global/README.md +39 -2
  48. package/global/cli/install.mjs +1 -1
  49. package/global/main.mjs +3 -0
  50. package/global/run.mjs +15 -2
  51. package/install.sh +3 -0
  52. package/modules/agent-door/conformance/audit.mjs +3 -0
  53. package/modules/d1-transport/limits.mjs +5 -1
  54. package/modules/deploy-kit/sql-tokens.mjs +5 -4
  55. package/modules/operator-auth/accounts/one-click.mjs +2 -0
  56. package/modules/operator-auth/dev/index.mjs +7 -1
  57. package/modules/operator-auth/dev/invited.mjs +11 -0
  58. package/modules/operator-auth/dev-gate.mjs +3 -2
  59. package/modules/operator-auth/routes.mjs +4 -0
  60. package/modules/portability/progress.mjs +12 -10
  61. package/modules/release/README.md +8 -0
  62. package/modules/release/archive-guard.mjs +22 -0
  63. package/modules/release/archive-members.mjs +49 -0
  64. package/modules/release/export.mjs +7 -1
  65. package/onboarding/commands.mjs +17 -8
  66. package/onboarding/migration-progress.mjs +69 -0
  67. package/onboarding/operator-migrations.mjs +1 -0
  68. package/package.json +2 -1
@@ -159,6 +159,9 @@ export async function auditPhase(c) {
159
159
  const applicable = type === 'policy.adopted' || rows.some(row => row.approval);
160
160
  if (applicable) c.add(`BASE-AGENT-010.6.${type}`, [...events, ...c.effectEvents ?? []].some(event => event.type === type), `Missing ${type} event while readable, including before native erasure.`);
161
161
  }
162
+ // The newest adoption carries the classes it covers and a decision reference to its revision, and nothing but policy metadata.
163
+ const adopted = [...events, ...c.effectEvents ?? []].filter(event => event.type === 'policy.adopted').at(-1);
164
+ if (adopted) c.add('BASE-AGENT-010.6.policy.adopted.shape', Array.isArray(adopted.classes) && adopted.classes.every(item => item?.class && Object.keys(item).join() === 'class') && adopted.decision?.revision === adopted.revision && Object.keys(adopted).every(key => ['id', 'type', 'uri', 'actor', 'at', 'seq', 'revision', 'classes', 'decision'].includes(key)), 'policy.adopted must carry the adopted classes as {class} entries and a decision reference to its revision, and nothing else.');
162
165
  const writeTools = new Set(rows.filter(row => row.tool !== 'resources/read' && ['done', 'replayed'].includes(row.outcome) && c.surface.tools.find(tool => tool.name === row.tool)?.readOnly === false).map(row => row.tool));
163
166
  c.add('BASE-AGENT-010.1.effects', !writeTools.size || [...events, ...c.effectEvents ?? []].some(event => event.actor?.kind === 'agent' && !['policy.decision', 'approval.pending', 'approval.decided'].includes(event.type)), 'Completed writes must produce record-change events attributed to the agent while their native resources are readable.');
164
167
  if (events.length > 1) {
@@ -1,10 +1,14 @@
1
1
  /** Cloudflare D1 per-query limits, supplied from the platform limits page
2
2
  * (updated 24 Oct 2026). Expression depth 100 is OBSERVED-NOT-DOCUMENTED:
3
3
  * native D1 rejected a concatenation tree of depth 101 on 27 Oct 2026.
4
+ * FROM items 100 is OBSERVED-NOT-DOCUMENTED (K21, 10 Nov 2026): native D1
5
+ * refuses a statement with "VIEWs and/or subqueries nested too deep" once its
6
+ * FROM-clause items, counted with every CTE and view reference expanded in
7
+ * place, reach 100. Local SQLite and Miniflare accept such a statement.
4
8
  * Node 22.20.0 ignores DatabaseSync limits options: preflight is mandatory.
5
9
  * Queries per Worker invocation (Paid 1000, Free 50, batch counts once) and
6
10
  * the 30 second query deadline are NOT-ENFORCEABLE-LOCALLY here: a database
7
11
  * connection has neither the invocation boundary nor the provider scheduler.
8
12
  */
9
13
  export const d1NativeLimits = Object.freeze({ length: 2_000_000, sqlLength: 100_000,
10
- column: 100, variableNumber: 100, functionArg: 32, likePatternLength: 50, exprDepth: 100 });
14
+ column: 100, variableNumber: 100, functionArg: 32, likePatternLength: 50, exprDepth: 100, fromItems: 100 });
@@ -2,6 +2,7 @@ import { assert } from './validation.mjs';
2
2
 
3
3
  // SQLite quotes escape themselves by doubling, except brackets, which end at ].
4
4
  // Keep quoted tokens intact: their punctuation and keywords are never syntax.
5
+ // Each token also carries its source span: sql.slice(start, end) is its text.
5
6
  export function sqlTokens(sql) {
6
7
  assert(!sql.includes('\0'), 'unsafe-migration-control');
7
8
  const tokens = [];
@@ -33,16 +34,16 @@ export function sqlTokens(sql) {
33
34
  break;
34
35
  }
35
36
  assert(closed, 'unsafe-migration-control');
36
- tokens.push({ kind: char === "'" ? 'string' : 'identifier', value });
37
+ tokens.push({ kind: char === "'" ? 'string' : 'identifier', value, start, end: offset });
37
38
  } else if (/[0-9]/.test(char) || (char === '.' && /[0-9]/.test(sql[offset] ?? ''))) {
38
39
  const number = /^(?:0[xX][0-9a-fA-F_]+|(?:[0-9][0-9_]*(?:\.[0-9_]*)?|\.[0-9][0-9_]*)(?:[eE][+-]?[0-9][0-9_]*)?)/.exec(sql.slice(start))[0];
39
40
  offset = start + number.length;
40
- tokens.push({ kind: 'number', value: number });
41
+ tokens.push({ kind: 'number', value: number, start, end: offset });
41
42
  } else if (/[A-Za-z_\u0080-\uFFFF]/.test(char)) {
42
43
  while (offset < sql.length && /[A-Za-z0-9_$\u0080-\uFFFF]/.test(sql[offset])) offset++;
43
- tokens.push({ kind: 'word', value: sql.slice(start, offset) });
44
+ tokens.push({ kind: 'word', value: sql.slice(start, offset), start, end: offset });
44
45
  } else {
45
- tokens.push({ kind: 'symbol', value: char });
46
+ tokens.push({ kind: 'symbol', value: char, start, end: offset });
46
47
  }
47
48
  }
48
49
  return tokens;
@@ -34,6 +34,8 @@ export function oneClickAccounts({ config, store, clock, sessions, authorizedLin
34
34
  return operator.status === 'active';
35
35
  }
36
36
  return {
37
+ // Only a local run's refusal can point at `rer dev`.
38
+ local: config.local === true,
37
39
  async people(request) {
38
40
  if (!await mode(request)) return null;
39
41
  requireOrigin(request, config);
@@ -18,6 +18,7 @@ import { signInRefusal } from './refusal.mjs';
18
18
  import { representation } from '../representation.mjs';
19
19
  import { decorateLabel } from '../../demo/label.mjs';
20
20
  import { oneClickPage } from '../signin/one-click.mjs';
21
+ import { hasInvitedPeople } from './invited.mjs';
21
22
 
22
23
  export const DEV_LAYER_MARKER = 'rer-dev-layer:local-only-never-deploy';
23
24
  const headers = { 'cache-control': 'no-store', 'referrer-policy': 'no-referrer', 'x-content-type-options': 'nosniff', 'x-robots-tag': 'noindex, nofollow', 'x-rer-dev-layer': DEV_LAYER_MARKER };
@@ -51,7 +52,12 @@ export function withDevIdentity(worker, { bindings = env => env, config: authCon
51
52
  const gate = devGate({ key: env.RER_DEV_KEY, origin: env.AUTH_ORIGIN, local: env.AUTH_LOCAL === 'true' });
52
53
  registerDevAdmission(gate && env.RER_DEV_IDENTITY !== 'off' ? r => gate.admitsSession(r) : null);
53
54
  const path = new URL(request.url).pathname;
54
- if (path === '/__dev/key') return gate ? gate.exchange(request, authConfig(env).branding) : devNotFound();
55
+ if (path === '/__dev/key') {
56
+ if (!gate) return devNotFound();
57
+ // The guidance names `rer dev --as <email>` only when the app has someone to take.
58
+ const context = request.method === 'GET' || request.method === 'HEAD' ? identity(env, authConfig, declared) : null;
59
+ return gate.exchange(request, authConfig(env).branding, { invited: context ? await hasInvitedPeople({ store: context.store, config: context.config, declared }) : false });
60
+ }
55
61
  if (path === '/signin' && gate && env.RER_DEV_IDENTITY !== 'off' && ['GET', 'HEAD'].includes(request.method)) {
56
62
  if (!await gate.admits(request)) return new Response(null, { status: 303, headers: { ...headers, location: '/__dev/key' } });
57
63
  const context = identity(env, authConfig, declared);
@@ -0,0 +1,11 @@
1
+ // Whether /__dev/personas would list someone beyond the owner and the seed's own
2
+ // personas: an active person or one with a live invitation. The keyless guidance page
3
+ // uses this one fact to say whether `rer dev --as <email>` has anyone to take; it
4
+ // reads no name or address.
5
+ export async function hasInvitedPeople({ store, config, declared, now = Date.now() }) {
6
+ const own = [config.OWNER_EMAIL, ...declared.map(persona => persona.email)];
7
+ const row = await store.first(`SELECT 1 AS found FROM oa_operators o WHERE o.email NOT IN (${own.map(() => '?').join(',')})
8
+ AND (o.status='active' OR (o.status='invited' AND EXISTS (SELECT 1 FROM oa_tokens t WHERE t.operator_id=o.id AND t.kind='invite'
9
+ AND t.consumed_at IS NULL AND t.revoked_at IS NULL AND t.expires_at>? AND t.operator_version=o.version))) LIMIT 1`, [...own, now]);
10
+ return row !== null && row !== undefined;
11
+ }
@@ -94,7 +94,8 @@ export function devGate({ key, origin, local }) {
94
94
  admitsSession: admitted,
95
95
  setCookie,
96
96
  // GET serves the exchange page with the seed's productName, mark and theme; POST trades the key for the cookie.
97
- async exchange(request, branding) {
97
+ // `invited` says whether the app has a person beyond the owner and its personas for `rer dev --as <email>` to take.
98
+ async exchange(request, branding, { invited = false } = {}) {
98
99
  if (new URL(request.url).pathname !== DEV_KEY_PATH) return null;
99
100
  if (request.method === 'GET' || request.method === 'HEAD') {
100
101
  const { script, logo, style } = await exchangeHashes();
@@ -103,7 +104,7 @@ export function devGate({ key, origin, local }) {
103
104
  const theme = brand?.theme;
104
105
  const mark = brand?.mark ? `<img src="${escapeHtml(brand.mark)}" alt="${escapeHtml(brand.productName)}" width="40" height="40" decoding="async">` : '';
105
106
  const themeLogo = theme && !brand.mark;
106
- const body = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex, nofollow"><title>Open the local app</title>${iconHead}${theme ? `<link rel="stylesheet" href="${escapeHtml(theme)}">` : ''}<style>${PAGE_STYLE}</style></head><body><main>${brand ? `<p class="brand">${mark}<span>${escapeHtml(brand.productName)}</span></p>` : ''}<h1>This app runs on your own computer</h1><p>It opens only from that computer. Use the link printed in the terminal where <code>rer dev</code> is running, or run <code>rer dev --as owner</code> from the project folder.</p><p>To sign in as someone who was invited, run <code>rer dev --as</code> followed by their email address.</p></main>${themeLogo ? `<script>${LOGO_SCRIPT}</script>` : ''}<script>${EXCHANGE_SCRIPT}</script></body></html>`;
107
+ const body = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex, nofollow"><title>Open the local app</title>${iconHead}${theme ? `<link rel="stylesheet" href="${escapeHtml(theme)}">` : ''}<style>${PAGE_STYLE}</style></head><body><main>${brand ? `<p class="brand">${mark}<span>${escapeHtml(brand.productName)}</span></p>` : ''}<h1>This app runs on your own computer</h1><p>It opens only from that computer. Use the link printed in the terminal where <code>rer dev</code> is running, or run <code>rer dev --as owner</code> from the project folder.</p>${invited ? '<p>To sign in as someone who was invited, run <code>rer dev --as</code> followed by their email address.</p>' : ''}</main>${themeLogo ? `<script>${LOGO_SCRIPT}</script>` : ''}<script>${EXCHANGE_SCRIPT}</script></body></html>`;
107
108
  return new Response(request.method === 'HEAD' ? null : body, { headers: { ...privateHeaders, 'content-type': 'text/html; charset=utf-8',
108
109
  'content-security-policy': `default-src 'none'; img-src 'self'; script-src ${script}${themeLogo ? ` ${logo}` : ''}; style-src ${theme ? "'self' " : ''}${style}${theme ? "; font-src 'self'" : ''}; connect-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'` } });
109
110
  }
@@ -9,6 +9,7 @@ import { securityHeaders, requireLoopback } from './http.mjs';
9
9
  import { safeReturnTo } from './policy.mjs';
10
10
  import { readInput, readParameters } from './input.mjs';
11
11
  import { OWNER_SIGNIN_PATH } from './owner-signin-grant.mjs';
12
+ const ONE_CLICK_REFUSED = 'This sign-in link did not open here. Open the link from the app itself, or run rer dev --as followed by the email address from the project folder.';
12
13
  function json(value, status = 200) { return Response.json(value, { status, headers: securityHeaders() }); }
13
14
  function seeOther(location, cookie) { return new Response(null, { status: 303, headers: { ...securityHeaders(), ...(cookie ? { 'Set-Cookie': cookie } : {}), Location: location } }); }
14
15
  // A native HTML form (the sign-in page before any script) gets a page back; an
@@ -143,6 +144,9 @@ export function createAuthHandler(auth) {
143
144
  return settingsRefusalPage(request, auth.presentation, code, status);
144
145
  }
145
146
  if (form) return seeOther(notice(auth, error instanceof AuthError ? error.code : 'auth_unavailable'));
147
+ // A browser that follows a refused local one-click link gets words, with the same status and headers as the JSON.
148
+ if (path === '/auth/one-click' && auth.oneClick?.local && error instanceof AuthError && error.code === 'not_found' && representation(request) === 'html')
149
+ return new Response(ONE_CLICK_REFUSED, { status: error.status, headers: { ...securityHeaders(), 'Content-Type': 'text/plain; charset=utf-8' } });
146
150
  if (error instanceof AuthError) return json({ error: error.code }, error.status);
147
151
  // Do not put SQL, email addresses, setup tokens or provider exceptions on the wire.
148
152
  return json({ error: 'auth_unavailable' }, 503);
@@ -1,10 +1,11 @@
1
1
  import { skippedTablesLine } from './bookkeeping.mjs';
2
2
  // Human progress for a long export or import. The caller sends events; this turns
3
3
  // them into at most one line every few seconds, with an estimate of the time left
4
- // once a phase has two samples. The first and last line of every phase always show.
5
- // Rates are bytes per second measured on a 1.2 GB local install on a loaded machine
6
- // (export 1725 s, import 2234 s); a quiet machine is faster.
7
- const RATES = { export: 700_000, import: 550_000 };
4
+ // once a phase has two samples and a known total. The first and last line of every
5
+ // phase always show. Local disk allocation includes free pages and transient state;
6
+ // it cannot predict archive bytes or building time.
7
+ // Import rate measured on a 1.2 GB archive on a loaded machine (2234 s).
8
+ const IMPORT_RATE = 550_000;
8
9
  const UNITS = ['B', 'KB', 'MB', 'GB', 'TB'];
9
10
  export function formatBytes(bytes) {
10
11
  let value = bytes, unit = 0;
@@ -18,16 +19,15 @@ export function formatDuration(seconds) {
18
19
  }
19
20
  const left = seconds => `, ${formatDuration(seconds)} left`;
20
21
  export function transferProgress(report, { interval = 3000, now = () => performance.now() } = {}) {
21
- let phase, first, printed = -Infinity, expected;
22
+ let phase, first, printed = -Infinity;
22
23
  const line = event => {
23
- const bytes = event.bytes === undefined ? '' : ` (${formatBytes(event.bytes)}${event.phase === 'building' && expected ? ` of about ${formatBytes(expected)}` : ''})`;
24
+ const bytes = event.bytes === undefined ? '' : ` (${formatBytes(event.bytes)})`;
24
25
  const parts = event.total === undefined ? `${event.parts} part${event.parts === 1 ? '' : 's'} so far` : `${event.parts} of ${event.total} parts`;
25
26
  // Seconds left, from the rate since the phase's first sample.
26
27
  const eta = () => {
27
28
  const seconds = (now() - first.time) / 1000;
28
29
  if (event === first.event || seconds <= 0 || event.parts === event.total) return '';
29
30
  if (event.total !== undefined && event.parts > first.event.parts) return left((event.total - event.parts) * seconds / (event.parts - first.event.parts));
30
- if (event.phase === 'building' && expected && event.bytes > first.event.bytes && event.bytes < expected) return left((expected - event.bytes) * seconds / (event.bytes - first.event.bytes));
31
31
  return '';
32
32
  };
33
33
  switch (event.phase) {
@@ -42,9 +42,11 @@ export function transferProgress(report, { interval = 3000, now = () => performa
42
42
  if(event.phase==='schema-unverified') { report('Schema unverified: '+JSON.stringify(event.receipt)); return; }
43
43
  if (event.phase === 'skipped') { report(skippedTablesLine(event.tables)); return; }
44
44
  if (event.phase === 'start') {
45
- const noun = event.direction === 'export' ? `Exporting about ${formatBytes(event.bytes)} of local data` : `Restoring a ${formatBytes(event.bytes)} archive`;
46
- if (event.direction === 'export') expected = event.bytes;
47
- report(`${noun}. ${event.bytes / RATES[event.direction] < 45 ? 'This takes under a minute.' : `An archive this size usually takes ${formatDuration(event.bytes / RATES[event.direction])}; a busy machine takes longer. Progress follows every few seconds.`}`);
45
+ if (event.direction === 'export') {
46
+ report(`Exporting local data (${formatBytes(event.bytes)} on disk). Archive size and time remaining are not known yet. Progress follows every few seconds.`);
47
+ } else {
48
+ report(`Restoring a ${formatBytes(event.bytes)} archive. ${event.bytes / IMPORT_RATE < 45 ? 'This takes under a minute.' : `An archive this size usually takes ${formatDuration(event.bytes / IMPORT_RATE)}; a busy machine takes longer. Progress follows every few seconds.`}`);
49
+ }
48
50
  printed = now();
49
51
  return;
50
52
  }
@@ -136,6 +136,14 @@ With `--tag`, passing gates produce `public-source.tar`, containing the checked
136
136
  exact ordinary files without Git history, and a hash-pinned site bundle:
137
137
  `site/<id>/<version>/release.json`, published documents, listing assets and
138
138
  `site/registry.json`.
139
+ The archive is built with the host `tar` from the files written out of the checked blobs, so
140
+ its bytes are not reproducible from the source alone (modes and times come from the producing
141
+ host); `publicExport.sha256` in the receipt, not a rebuild, is what the signed statement
142
+ checks the archive against. macOS `tar` would add a `._<name>` AppleDouble member for every file and
143
+ directory carrying an extended attribute: the producer runs it with `COPYFILE_DISABLE=1` and,
144
+ on macOS only, `--no-xattrs`, then reads the member names from the archive bytes and stops the
145
+ release before a digest is recorded if any `._*` member is not a tracked path (a tracked file
146
+ named `._x` is archived like any other).
139
147
  Export attributes cannot silently omit or substitute bytes. The site metadata
140
148
  comes from committed seed and contract data; no screenshots, install guarantees
141
149
  or verified maturity claims are invented. Copy the reviewed bundle into the site
@@ -0,0 +1,22 @@
1
+ import { archiveMembers } from './archive-members.mjs';
2
+
3
+ const normal = path => path.replace(/^(\.\/)+/, '').replace(/\/+$/, '');
4
+
5
+ // macOS tar writes a `._<name>` AppleDouble member beside every file and
6
+ // directory that has extended attributes. The export is the tracked tree and
7
+ // nothing else: such a member is refused unless a tracked path is that name.
8
+ export function assertTrackedMembers(members, trackedPaths) {
9
+ const tracked = new Set();
10
+ for (const path of trackedPaths) {
11
+ const parts = path.split('/');
12
+ for (let length = 1; length <= parts.length; length++) tracked.add(parts.slice(0, length).join('/'));
13
+ }
14
+ const stray = members.map(member => normal(member.path)).filter(path => path && path.split('/').pop().startsWith('._') && !tracked.has(path));
15
+ if (stray.length)
16
+ throw Error(`Public export archive holds ${stray.length} AppleDouble entr${stray.length === 1 ? 'y' : 'ies'} that are not tracked paths (first: ${stray[0]}). `
17
+ + 'macOS tar adds them from extended attributes; the release was stopped before any digest was recorded.');
18
+ }
19
+
20
+ export function assertArchiveTracked(archive, trackedPaths) {
21
+ assertTrackedMembers(archiveMembers(archive), trackedPaths);
22
+ }
@@ -0,0 +1,49 @@
1
+ import { readFileSync } from 'node:fs';
2
+
3
+ // Reads member paths straight from the tar bytes. A system `tar -t` on macOS
4
+ // merges AppleDouble members while listing, so it cannot be trusted to show
5
+ // what a Linux reader will extract.
6
+ const text = bytes => bytes.toString('utf8');
7
+ const field = (block, from, to) => text(block.subarray(from, to)).replace(/\0.*$/s, '');
8
+
9
+ function octal(bytes) {
10
+ if (bytes[0] & 0x80) {
11
+ let value = 0n;
12
+ for (const byte of bytes.subarray(1)) value = (value << 8n) | BigInt(byte);
13
+ return Number(value);
14
+ }
15
+ return parseInt(text(bytes).replace(/\0.*$/s, '').trim() || '0', 8);
16
+ }
17
+
18
+ function paxPath(data) {
19
+ let at = 0;
20
+ while (at < data.length) {
21
+ const space = data.indexOf(0x20, at);
22
+ const length = Number.parseInt(text(data.subarray(at, space)), 10);
23
+ if (!(length > 0)) break;
24
+ const record = text(data.subarray(space + 1, at + length - 1));
25
+ if (record.startsWith('path=')) return record.slice(5);
26
+ at += length;
27
+ }
28
+ return null;
29
+ }
30
+
31
+ export function archiveMembers(file) {
32
+ const bytes = readFileSync(file), members = [];
33
+ let at = 0, next = null;
34
+ while (at + 512 <= bytes.length) {
35
+ const block = bytes.subarray(at, at + 512);
36
+ if (block.every(byte => byte === 0)) break;
37
+ const type = String.fromCharCode(block[156] || 0x30);
38
+ const size = octal(block.subarray(124, 136));
39
+ const data = bytes.subarray(at + 512, at + 512 + size);
40
+ at += 512 + Math.ceil(size / 512) * 512;
41
+ if (type === 'x') { next = paxPath(data) ?? next; continue; }
42
+ if (type === 'L') { next = text(data).replace(/\0.*$/s, ''); continue; }
43
+ if (type === 'g') continue;
44
+ const prefix = field(block, 345, 500);
45
+ members.push({ path: next ?? (prefix ? `${prefix}/` : '') + field(block, 0, 100), type });
46
+ next = null;
47
+ }
48
+ return members;
49
+ }
@@ -3,6 +3,7 @@ import { resolve, dirname } from 'node:path';
3
3
  import { execFileSync } from 'node:child_process';
4
4
  import { git } from './source.mjs';
5
5
  import { sha256 } from './catalogue.mjs';
6
+ import { assertArchiveTracked } from './archive-guard.mjs';
6
7
 
7
8
  // Read the checked Git blobs directly. export-ignore/export-subst attributes
8
9
  // cannot silently remove or change bytes after publication inspection.
@@ -46,6 +47,11 @@ export function cleanHistory(source, temporary, tagged = false) {
46
47
  export function publicExport(source, temporary, output) {
47
48
  const tree = sourceTree(source, resolve(temporary, 'public-source'));
48
49
  const archive = resolve(output, 'public-source.tar');
49
- execFileSync('tar', ['-cf', archive, '-C', tree, '.'], { stdio: ['ignore', 'pipe', 'pipe'] });
50
+ // macOS tar turns extended attributes into `._*` members and pax headers.
51
+ // COPYFILE_DISABLE is ignored elsewhere; the flag is added only on macOS so
52
+ // other hosts run the exact command they always did.
53
+ const flags = process.platform === 'darwin' ? ['--no-xattrs'] : [];
54
+ execFileSync('tar', ['-cf', archive, ...flags, '-C', tree, '.'], { stdio: ['ignore', 'pipe', 'pipe'], env: { ...process.env, COPYFILE_DISABLE: '1' } });
55
+ assertArchiveTracked(archive, source.entries.keys());
50
56
  return { path: 'public-source.tar', sha256: sha256(readFileSync(archive)), format: 'tar', revision: source.commit };
51
57
  }
@@ -11,6 +11,7 @@ import { waitForReadiness } from './readiness.mjs';
11
11
  import { commandCustody } from './command-custody.mjs';
12
12
  import { createProcessBaseline, createProcessScope, inheritedScopeTokens, processScopeEnvironment } from './process-scope.mjs';
13
13
  import { toolCommand } from './tool-command.mjs';
14
+ import { isWranglerMigrationApply, wranglerMigrationView } from './migration-progress.mjs';
14
15
 
15
16
  export async function createCommands(directory,state,{terminal=text=>writeSync(1,text),spawn=spawnChild,queue:queuePolicy,custodyToken,onWaiting}={}) {
16
17
  let policy=queuePolicy?await commandPolicy():{environment:{},close:async()=>{}};
@@ -38,12 +39,13 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
38
39
  else if(error.code!=='EAGAIN'&&error.code!=='EWOULDBLOCK')throw error;
39
40
  }
40
41
  };
41
- const emit=text=>{
42
+ // `logText` is what the setup log keeps when a command's view shows less than it printed.
43
+ const emit=(text,logText=text)=>{
44
+ if(logText&&!closed)log.write(logText);
42
45
  if(!text)return;
43
46
  // Store a bounded text tail as lines; fragment writes do not multiply entries.
44
47
  const textTail=((state.logs||[]).join('\n')+text).slice(-65536);
45
48
  state.logs=textTail.split('\n').slice(-400);
46
- if(!closed)log.write(text);
47
49
  writeTerminal(text);
48
50
  };
49
51
  // A line that lists secret NAMES keeps each name whole: a name is not a secret, even when a value
@@ -65,14 +67,16 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
65
67
  const step=stepDiagnostic({name:redaction.redact(String(label)),command:capture?.display,exitCode:detail.code,signal:detail.signal,output:lines,log:redaction.redact(checkoutPath(capture?.cwd,logPath))});
66
68
  return Object.assign(commandFailure(`${redaction.redact(String(label))}: ${status}.${detail.lastHealth?` Last health: ${redaction.redact(String(detail.lastHealth))}.`:''}\nCommand: ${capture?.display ?? '(none: the step failed inside rer)'}\nLast output (up to 40 lines):\n${lines.length?lines.slice(-40).join('\n'):'(no output)'}\nLog: ${redaction.redact(logPath)}`,{childExitCode:detail.code,signal:detail.signal,step}),{childExitCode:detail.code,signal:detail.signal});
67
69
  };
68
- const track=(label,child,ownershipScope)=>{
70
+ const track=(label,child,ownershipScope,view)=>{
69
71
  if(captures.has(child))return child;
70
72
  let resolveClose,resolveError,resolveExit;
71
73
  const capture={tail:'',scope:signal,closed:new Promise(resolve=>{resolveClose=resolve;}),failed:new Promise(resolve=>{resolveError=resolve;}),exited:new Promise(resolve=>{resolveExit=resolve;})};
72
74
  capture.custody=commandCustody(child,ownershipScope);
73
75
  // Redact in arrival order across both descriptors: their concatenation is what
74
76
  // reaches the shared page, disk and terminal sinks.
75
- const filter=redaction.stream(text=>{capture.tail=(capture.tail+text).slice(-32768);emit(text);});
77
+ // A command's view (see migration-progress.mjs) shortens what the terminal, page and
78
+ // failure tail show; the log keeps every byte.
79
+ const filter=redaction.stream(text=>{const shown=view?view.write(text):text;capture.tail=(capture.tail+shown).slice(-32768);emit(shown,text);});
76
80
  capture.snapshot=()=> (capture.tail+filter.snapshot()).slice(-32768);
77
81
  const sources=[child.stdout,child.stderr].filter(Boolean),data=chunk=>filter.write(chunk);
78
82
  for(const source of sources)source.on('data',data);
@@ -85,7 +89,9 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
85
89
  clearTimeout(capture.stopTimer);
86
90
  child.removeListener('exit',exited);if(!capture.exitResult)exited(code,terminationSignal);
87
91
  for(const source of sources)source.removeListener('data',data);
88
- filter.end();active.delete(child);if(!capture.custody)managed.delete(child);resolveClose({code,signal:terminationSignal,error,errorCode:capture.errorCode});
92
+ filter.end();
93
+ if(view){const rest=view.end();capture.tail=(capture.tail+rest).slice(-32768);emit(rest,'');Object.assign(state,view.facts?.());}
94
+ active.delete(child);if(!capture.custody)managed.delete(child);resolveClose({code,signal:terminationSignal,error,errorCode:capture.errorCode});
89
95
  };
90
96
  child.once('close',finish);
91
97
  captures.set(child,capture);
@@ -133,7 +139,7 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
133
139
  state.step=announced;if(!repeated)report(label);
134
140
  // Name the executable by default; only a caller's explicit safe display may
135
141
  // include arguments. Raw argv can contain private positional values.
136
- const {signal:providedSignal,afterCommand,onChild,heavy,phase,display,...native}=options;
142
+ const {signal:providedSignal,afterCommand,onChild,heavy,phase,display,view,...native}=options;
137
143
  const commandSignal=signal&&providedSignal?AbortSignal.any([signal,providedSignal]):providedSignal||signal;
138
144
  if(commandSignal?.aborted)throw failure(label,{reason:'cancel'});
139
145
  const ownershipScope=createProcessScope(custodyBaseline);redaction.addSecrets([ownershipScope.token,...inheritedScopeTokens(process.env),...inheritedScopeTokens(native.env)]);
@@ -141,7 +147,7 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
141
147
  const child=spawn(program,argv,{...native,env:processScopeEnvironment(ownershipScope,{...(native.env??process.env),...policy.environment,...(custodyToken?{RER_ONBOARDING_PROCESS_OWNER:[...inheritedScopeTokens(native.env??process.env),custodyToken].join(',')}:{})}),shell:false,detached:process.platform!=='win32',stdio:[Array.isArray(native.stdio)?native.stdio[0]:'ignore','pipe','pipe',...(native.stdio?.includes('ipc')?['ipc']:[])]});
142
148
  onChild?.(child);
143
149
  ownershipRecords.set(child,{pid:child.pid,token:ownershipScope.token});
144
- track(label,child,ownershipScope);
150
+ track(label,child,ownershipScope,view?.());
145
151
  Object.assign(captures.get(child),{cwd:native.cwd??process.cwd(),display:redaction.redact(String(display??command))});
146
152
  const cancel=()=>{void stopCommand(child);};
147
153
  commandSignal?.addEventListener('abort',cancel,{once:true});if(commandSignal?.aborted)cancel();
@@ -158,12 +164,15 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
158
164
  spawn:spawnCommand,
159
165
  async stop(child){await stopCommand(child);await captures.get(child)?.closed;const scope=captures.get(child)?.scope;if(![...managed].some(other=>captures.get(other).scope===scope)){const actions=cleanups.get(scope)??[];cleanups.delete(scope);for(const action of actions)await action();}},
160
166
  async run(label,command,args=[],options={}) {
167
+ // Any caller's `wrangler d1 migrations apply` (the setup hooks, a seed's own export and import) shows
168
+ // a count instead of wrangler's table redrawn per migration; the log keeps every byte and is named in the summary.
169
+ if(!options.view&&isWranglerMigrationApply(command,args))options={...options,view:()=>wranglerMigrationView({log:redaction.redact(checkoutPath(options.cwd??process.cwd(),logPath))})};
161
170
  if(queuePolicy && options.heavy !== false) {
162
171
  let queuedChild;
163
172
  const commandSignal=signal&&options.signal?AbortSignal.any([signal,options.signal]):options.signal||signal;
164
173
  const result = await queuedCommand(command,args,{...options,verb:queuePolicy.verb,signal:commandSignal,originalCI:policy.ci,
165
174
  label:await queueLabel(options.cwd??process.cwd(),queuePolicy.verb,options.phase??'command'),report,onWaiting,maxWait:queuePolicy.maxWait,queueOptions:queuePolicy.sampler?{sampler:queuePolicy.sampler}:undefined,
166
- spawn:(program,argv,native)=>(queuedChild=spawnCommand(label,program,argv,{...native,onChild:options.onChild,display:options.display})),cleanup:async(child,result)=>{await stopCommand(child);await options.afterCommand?.(result);}});
175
+ spawn:(program,argv,native)=>(queuedChild=spawnCommand(label,program,argv,{...native,onChild:options.onChild,display:options.display,view:options.view})),cleanup:async(child,result)=>{await stopCommand(child);await options.afterCommand?.(result);}});
167
176
  if(result?.timedOut)throw busyRefusal({...result,reason:redaction.redact(String(result.reason))},{verb:queuePolicy.verb,maxWait:queuePolicy.maxWait??maxWaitSeconds});
168
177
  if(result){if(result.code!==0)throw failure(label,result,captures.get(queuedChild));return result;}
169
178
  }
@@ -0,0 +1,69 @@
1
+ // What a person sees while `wrangler d1 migrations apply` runs. Wrangler redraws
2
+ // its whole migration table after every migration it applies, so 75 migrations
3
+ // print the first one's name 76 times and about 1.2 MB in all. The command's
4
+ // full output stays in the setup log and in failure diagnostics' source; the
5
+ // terminal and shared page get a count every ten migrations, anything that is
6
+ // not a table row, wrangler's own boilerplate or an earlier-seen line (warnings,
7
+ // errors), and one summary. Wrangler names the migration that failed only for
8
+ // some errors (a SQL syntax error is just its message), so the view names the
9
+ // first migration of the list that never showed a check mark when an error came.
10
+
11
+ const TABLE_LINE = /^[┌├└│─]/;
12
+ const STEP = 10;
13
+ // Wrangler's per-migration "🚣 37 commands executed successfully." differs every time, so repeats are not caught.
14
+ const PER_MIGRATION = /^🚣 \d+ commands? executed successfully\.?$/;
15
+ // What wrangler says around every apply, whatever it applies: its banner, where the database is, how to reach
16
+ // a remote one, the confirmation it answers itself in CI.
17
+ const BOILERPLATE = /^(\u26C5\uFE0F?\s*wrangler\b|Resource location:|Use --remote if you want|Migrations to be applied:|\? About to apply \d+ migration|Your database may not be available|🤖 Using fallback value|🌀 (Executing on|To execute on)|✅ No migrations to apply)/u;
18
+
19
+ export function isWranglerMigrationApply(command, args = []) {
20
+ const words = [command, ...args].map(String);
21
+ const tool = words.findIndex(word => /(^|[\\/])wrangler(\.js)?$/.test(word));
22
+ if (tool < 0) return false;
23
+ const rest = words.slice(tool + 1);
24
+ return rest.some((word, index) => word === 'd1' && rest[index + 1] === 'migrations' && rest[index + 2] === 'apply');
25
+ }
26
+
27
+ // One view per command: write(text) returns the text to show, end() the rest.
28
+ // The summary names the log that keeps wrangler's full output: { log }.
29
+ export function wranglerMigrationView({ log } = {}) {
30
+ let pending = '', total = 0, announced = 0, failed = false, errored = false;
31
+ const applied = new Set(), seen = new Set(), names = [];
32
+ const shown = [];
33
+ const progress = () => `Applying migrations ${applied.size}/${Math.max(total, applied.size)}`;
34
+ const line = text => {
35
+ if (TABLE_LINE.test(text)) {
36
+ if (!text.startsWith('│')) return;
37
+ const cells = text.split('│').slice(1, -1).map(cell => cell.trim());
38
+ if (cells[0] === 'name') return;
39
+ if (cells.length === 1) { total += 1; if (!names.includes(cells[0])) names.push(cells[0]); return; }
40
+ if (cells[1].includes('❌')) { failed = true; shown.push(`Migration ${cells[0]} failed.`); return; }
41
+ if (cells[1].includes('✅') && !applied.has(cells[0])) {
42
+ applied.add(cells[0]);
43
+ if (applied.size % STEP === 0 && applied.size > announced) { announced = applied.size; shown.push(progress()); }
44
+ }
45
+ return;
46
+ }
47
+ const trimmed = text.trim();
48
+ if (/\[ERROR\]/.test(trimmed)) errored = true;
49
+ if (!trimmed || PER_MIGRATION.test(trimmed) || BOILERPLATE.test(trimmed) || seen.has(trimmed)) return;
50
+ seen.add(trimmed);
51
+ shown.push(text);
52
+ };
53
+ const drain = () => { const text = shown.length ? shown.join('\n') + '\n' : ''; shown.length = 0; return text; };
54
+ return {
55
+ write(text) {
56
+ const lines = (pending + text).split('\n');
57
+ pending = lines.pop();
58
+ for (const item of lines) line(item);
59
+ return drain();
60
+ },
61
+ end() {
62
+ if (pending) { line(pending); pending = ''; }
63
+ if (errored && !failed && names[applied.size]) shown.push(`Migration ${names[applied.size]} failed.`);
64
+ if (applied.size) shown.push(`Applied ${applied.size} migration${applied.size === 1 ? '' : 's'}.${log ? ` Full output: ${log}` : ''}`);
65
+ return drain();
66
+ },
67
+ facts: () => ({ migrationsApplied: applied.size }),
68
+ };
69
+ }
@@ -48,5 +48,6 @@ export async function migrateOperator(context, database) {
48
48
  const after = await appliedNames(state, table);
49
49
  const applied = names.filter(name => !before.has(name) && after.has(name));
50
50
  if (applied.length) store.report(`Applied local migrations: ${applied.join(', ')}`);
51
+ if (store.state) store.state.migrationsApplied = applied.length;
51
52
  } finally { await unlink(path); }
52
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runeditrun/rer",
3
- "version": "0.2.110",
3
+ "version": "0.2.112",
4
4
  "description": "The rer command: install, set up, run and launch Run Edit Run checkouts.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -24,6 +24,7 @@
24
24
  "./jsonc": "./cli/jsonc.mjs",
25
25
  "./parse": "./cli/parse.mjs",
26
26
  "./scheduled": "./cli/scheduled.mjs",
27
+ "./size-fixture": "./cli/size/fixture.mjs",
27
28
  "./dev-identity": "./cli/dev-identity.mjs",
28
29
  "./local-installer": "./onboarding/adapter.mjs",
29
30
  "./state": "./onboarding/state.mjs",