@runeditrun/rer 0.2.94 → 0.2.96

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 (71) hide show
  1. package/README.md +16 -2
  2. package/cli/README.md +5 -1
  3. package/cli/agent-door.mjs +4 -0
  4. package/cli/agent-journey-fixtures.mjs +1 -1
  5. package/cli/authoring.mjs +1 -1
  6. package/cli/business/carry-files.mjs +142 -0
  7. package/cli/business/carry.mjs +37 -83
  8. package/cli/business/choices.mjs +17 -8
  9. package/cli/business/connect.mjs +6 -5
  10. package/cli/business/invocation.mjs +3 -2
  11. package/cli/business/local-commands.mjs +6 -6
  12. package/cli/business/questions.mjs +4 -1
  13. package/cli/business/state.mjs +4 -1
  14. package/cli/checkout-folders.mjs +14 -0
  15. package/cli/checkout-preparation.mjs +83 -0
  16. package/cli/contract.mjs +1 -1
  17. package/cli/door-clauses.mjs +29 -2
  18. package/cli/hosted-output.mjs +14 -3
  19. package/cli/hosted-queue-producers.mjs +43 -0
  20. package/cli/jsonc.mjs +1 -115
  21. package/cli/parse.mjs +1 -1
  22. package/cli/portability-migrations.mjs +2 -12
  23. package/edition-authoring/archive-source.mjs +86 -1
  24. package/edition-authoring/base-copies.mjs +15 -45
  25. package/edition-authoring/cli.mjs +1 -1
  26. package/edition-authoring/edition-migrations.mjs +2 -2
  27. package/edition-authoring/module-closure.mjs +119 -50
  28. package/edition-authoring/module-packages.mjs +12 -5
  29. package/edition-authoring/module-syntax.mjs +13 -50
  30. package/edition-authoring/runtime-dependencies.mjs +4 -4
  31. package/foundation/runtime/contract-docs.mjs +1 -1
  32. package/global/CHANGELOG.md +70 -0
  33. package/global/README.md +16 -2
  34. package/global/cli/layout.mjs +3 -0
  35. package/global/launch/facts.mjs +1 -29
  36. package/global/launch/state.mjs +3 -6
  37. package/global/list.mjs +9 -15
  38. package/modules/agent-door/CLAUSES.md +12 -0
  39. package/modules/agent-door/conformance/audit.mjs +22 -4
  40. package/modules/agent-door/conformance/discovery.mjs +32 -1
  41. package/modules/agent-door/conformance/erasure.mjs +103 -0
  42. package/modules/agent-door/conformance/index.mjs +13 -4
  43. package/modules/agent-door/conformance/journey.mjs +19 -1
  44. package/modules/agent-door/conformance/policy-phases.mjs +34 -1
  45. package/modules/agent-door/conformance/protocol.mjs +13 -3
  46. package/modules/agent-door/conformance/relay.mjs +63 -0
  47. package/modules/agent-door/conformance/unpair.mjs +47 -0
  48. package/modules/deploy-kit/jsonc.mjs +115 -0
  49. package/modules/deploy-kit/migration-directory.mjs +16 -0
  50. package/modules/deploy-kit/prepare.mjs +1 -1
  51. package/modules/deploy-kit/templates.mjs +9 -4
  52. package/modules/erasure/cascade.mjs +4 -4
  53. package/modules/erasure/index.d.mts +1 -1
  54. package/modules/erasure/index.mjs +1 -1
  55. package/modules/import-kit/src/d1/README.md +16 -1
  56. package/modules/import-kit/src/d1/preserved-reverse.ts +5 -2
  57. package/modules/import-kit/src/d1/read-fence.ts +14 -2
  58. package/modules/import-kit/src/d1/reverse.ts +4 -1
  59. package/modules/import-kit/src/d1/sets.ts +8 -0
  60. package/modules/import-kit/src/d1/snapshot-text.ts +68 -0
  61. package/modules/import-kit/src/d1/undo-report.ts +4 -1
  62. package/modules/import-kit/src/door/ADOPTING.md +9 -4
  63. package/modules/portability/README.md +28 -2
  64. package/modules/portability/bookkeeping.mjs +8 -4
  65. package/modules/portability/checkout-history.mjs +12 -6
  66. package/modules/portability/import.mjs +1 -1
  67. package/modules/portability/storage.mjs +7 -1
  68. package/modules/portability/worker-history.d.mts +1 -1
  69. package/modules/portability/worker-history.mjs +1 -1
  70. package/onboarding/operator-migrations.mjs +5 -1
  71. package/package.json +1 -1
@@ -608,7 +608,30 @@ of bounded deterministic seeded rows. Volatile seeded rows cannot be vouched for
608
608
  their values are never bundled. Runtime policy projects each inventory through
609
609
  the same schema identity code as live SQLite. The Worker adapter binds evidence
610
610
  to the live hashed ledger and complete schema, then supplies the existing legacy
611
- collector, archived-ledger validation, bridge and restore guards. Archive SQL is
611
+ collector, archived-ledger validation, bridge and restore guards.
612
+
613
+ The same explicit build-evidence adoption supports native Wrangler's plain
614
+ `d1_migrations` ledger. Keep the reviewed, unchanged applied migration files in
615
+ the binding's declared directory when building. Every live name must select the
616
+ exact ordered prefix of those files, and replay of that prefix must reproduce
617
+ the complete live schema, including indexes and triggers on excluded tables.
618
+ Unknown names, gaps, reordered names, tracked but missing hashes, and schema
619
+ drift refuse before restore writes. Existing hashes must still match; the
620
+ Node automatic checkout path still requires hashed history. This binds the
621
+ reviewed build to the verified current installation; it does not attest bytes
622
+ Wrangler never recorded. Do not adopt an installation whose applied source
623
+ cannot be established from its retained checkout/build provenance. No ledger
624
+ row, ID, timestamp or schema is changed, no historical hash is backfilled, and
625
+ no archive ancestry is inferred. The archive still needs its own authenticated
626
+ recorded history and schema proof through the existing collector. Native
627
+ seed adapters that normalize an older product format remain responsible for
628
+ that format's existing validation. `restorableManifest` preserves a recognized
629
+ raw table-hash representation carrying an object inventory when projecting out
630
+ bookkeeping so those native
631
+ adapters can recognize their retained formats. Base's importer requests the
632
+ complete canonical identity independently; it never uses that raw projection as
633
+ schema compatibility evidence. Older inventory-free archives retain their
634
+ existing projection and verified legacy-history path. Archive SQL is
612
635
  never executed as evidence. Unsupported migration selections and missing evidence
613
636
  fail closed with `schema_mismatch:legacy_evidence` (the public HTTP vocabulary
614
637
  reports `schema_mismatch`). The ordinary automatic Node library path is unchanged.
@@ -616,7 +639,10 @@ reports `schema_mismatch`). The ordinary automatic Node library path is unchange
616
639
  The plugin runs for direct Vite builds and managed builds, rejects client imports,
617
640
  and puts its module in the existing Worker bundle/package path. Seeds that do not
618
641
  declare it generate no evidence module and need no migration or configuration
619
- change. Keep the same service instance throughout the initial legacy upload.
642
+ change. Refresh installed helpers and any copied portability runtime together;
643
+ constructor-issued refusals retain their identity across those module copies,
644
+ while arbitrary errors are not promoted to `PortabilityError`. Keep the same
645
+ service instance throughout the initial legacy upload.
620
646
 
621
647
  Later data statements also qualify when a surviving trigger from that same
622
648
  migration repeats the complete statement block, in order, on Base's restore
@@ -1,4 +1,4 @@
1
- import { schemaIdentityOf } from './schema-identity.mjs';
1
+ import { schemaIdentityOf, rawSchemaIdentityOf } from './schema-identity.mjs';
2
2
  import { insist } from './storage.mjs';
3
3
 
4
4
  // Installation authority and transient working state, never product data.
@@ -10,21 +10,25 @@ export const platformTables=Object.freeze([
10
10
  'rer_mail_development_outbox','rer_ai_development_outbox',
11
11
  'rer_dependency_keys','rer_dependency_pending','rer_dependency_codes',
12
12
  'rer_command_receipts','rer_erasure_blobs','rer_erasure_guard',
13
- 'rer_erasure_scope','rer_erasure_rates','rer_demo',
13
+ 'rer_erasure_scope','rer_erasure_rates','rer_demo','agent_door_replay_aliases',
14
14
  ]);
15
15
  export const identifier=value=>value.replace(/[A-Z]/g,letter=>letter.toLowerCase());
16
16
  export const matches=(table,pattern)=>pattern.endsWith('%') ? identifier(table).startsWith(identifier(pattern.slice(0,-1))) : identifier(table)===identifier(pattern);
17
17
  export const platformTable=table=>platformTables.some(pattern=>matches(table,pattern));
18
18
  // Compatibility uses the product schema, while the original manifest and parts
19
19
  // remain intact for end-to-end archive verification, including skipped rows.
20
- export async function restorableManifest(manifest) {
20
+ // Native adapters can recognize a table-hash format carrying objects after bookkeeping is
21
+ // removed. Retain that wire representation here; Base's validator explicitly
22
+ // requests the complete canonical identity before deciding compatibility.
23
+ export async function restorableManifest(manifest,{canonical=false}={}) {
21
24
  // Successful import-kit units always clear their CHECK guard rows before
22
25
  // committing. An old archive may carry the empty table, never its rows.
23
26
  for(const table of manifest.tables)if(identifier(table.name)==='ik_d1_assertions')
24
27
  insist(table.count===0,'invalid_bookkeeping_rows:'+table.name,409);
25
28
  const tables=manifest.tables.filter(table=>!platformTable(table.name));
26
29
  const schemaObjects=manifest.schemaObjects?.filter(object=>!manifest.tables.some(table=>platformTable(table.name) && table.name===object.table));
27
- return {...manifest,tables,...(schemaObjects?{schemaObjects}:{}),schema:await schemaIdentityOf(tables,schemaObjects),
30
+ const raw=!canonical && manifest.schemaObjects!==undefined && manifest.schema===await rawSchemaIdentityOf(manifest.tables);
31
+ return {...manifest,tables,...(schemaObjects?{schemaObjects}:{}),schema:await (raw?rawSchemaIdentityOf(tables):schemaIdentityOf(tables,schemaObjects)),
28
32
  excludedColumns:Object.fromEntries(Object.entries(manifest.excludedColumns).filter(([name])=>!platformTable(name)))};
29
33
  }
30
34
  export const skippedTablesLine=tables=>'Skipped platform bookkeeping tables: '+tables.join(', ')+'.';
@@ -1,12 +1,18 @@
1
1
  import { catalogue, policy } from './catalogue.mjs';
2
- import { destinationLedger, matchMigrationLedger } from './ledgers.mjs';
2
+ import { readLedger, matchMigrationLedger } from './ledgers.mjs';
3
3
  import { insist } from './storage.mjs';
4
4
 
5
- // Both evidence adapters bind the seed's files to the live hashed history and
6
- // complete schema before the shared legacy collector can accept an upload.
7
- export async function checkoutHistory(db,input,files,replayFor) {
8
- const ledger=await destinationLedger(db)??[];
9
- insist(ledger.length && ledger.every(row=>row.sha256),'schema_mismatch:legacy_evidence',409);
5
+ // Both evidence adapters bind the seed's files to live history and the complete
6
+ // schema. Only an explicitly bundled Worker may bind plain Wrangler history:
7
+ // literal names must select an ordered checkout prefix, never aliases or gaps.
8
+ export async function checkoutHistory(db,input,files,replayFor,{nativeWrangler=false}={}) {
9
+ const history=await readLedger(db),ledger=history?.entries??[];
10
+ insist(ledger.length,'schema_mismatch:legacy_evidence',409);
11
+ if(!ledger.every(row=>row.sha256)) {
12
+ insist(nativeWrangler && history.table==='d1_migrations'
13
+ && ledger.every((row,i)=>row.sha256===undefined && row.name===files[i]?.name),
14
+ 'schema_mismatch:legacy_evidence',409);
15
+ }
10
16
  const applied=matchMigrationLedger(ledger,files);
11
17
  const replay=await replayFor(applied);
12
18
  insist(await replay.schemaAfter(replay.names)===(await catalogue(db,policy(input))).identity,'schema_mismatch');
@@ -28,7 +28,7 @@ export async function createImport(context,manifest,actor='direct',legacyRecover
28
28
  insist(manifest.product===config.product,'wrong_product');
29
29
  // Explicit schema upgrades can reconcile rows, but cannot attest an interrupted deployment.
30
30
  await appliedMigrations(db);
31
- const original=manifest;manifest=await restorableManifest(original);
31
+ const original=manifest;manifest=await restorableManifest(original,{canonical:true});
32
32
  const skippedTables=original.tables.filter(table=>platformTable(table.name)).map(table=>table.name);
33
33
  const cat=await catalogue(db,config),upgrade=config.acceptedSchemas[original.schema];
34
34
  manifest=await withoutAbsentExcludedObjects(manifest,cat,config);
@@ -1,8 +1,14 @@
1
1
  import { canonicalJson } from './hash.mjs';
2
- const errorCodes = new WeakMap();
2
+ // Installed helpers and copied runtimes can coexist in one Worker. Share only
3
+ // constructor-issued identities, so arbitrary objects with code/status fields
4
+ // never become PortabilityError instances across that boundary.
5
+ const registry = Symbol.for('runeditrun.portability.errors.v1');
6
+ if (!Object.hasOwn(globalThis,registry)) Object.defineProperty(globalThis,registry,{value:new WeakMap()});
7
+ const errorCodes = globalThis[registry];
3
8
  // A verifier's original machine code remains independent of mutable properties.
4
9
  export const portabilityErrorCode = error => errorCodes.get(error);
5
10
  export class PortabilityError extends Error {
11
+ static [Symbol.hasInstance](error) { return errorCodes.has(error); }
6
12
  constructor(code, status=400) { super(code); this.code=code; this.status=status; errorCodes.set(this,code); }
7
13
  }
8
14
  export function insist(condition, code, status=400) { if (!condition) throw new PortabilityError(code,status); }
@@ -5,5 +5,5 @@ export interface MigrationEvidence {
5
5
  objects:{name:string;sql:string;type:string;tbl_name:string}[];
6
6
  prefixes:{objects:number[];shadows:string[];seeds:{name:string;columns:string[];hashes:string[]}[]}[];
7
7
  }
8
- /** Return a replay bound to the destination's hashed ledger and complete schema. */
8
+ /** Return a replay bound to the destination's hashed history or exact native Wrangler prefix, and complete schema. */
9
9
  export function workerMigrations(db:D1Database,policy:ArchivePolicy,evidence:MigrationEvidence):Promise<MigrationReplay>;
@@ -24,6 +24,6 @@ export async function workerMigrations(db,input,evidence) {
24
24
  async rowImages(requests){return new Map(requests.filter(r=>final.seeds.some(s=>s.name===r.name && !s.hashes.length)).map(r=>[r.name,[]]));},
25
25
  async rowHashes(requests,limit){return new Map(requests.flatMap(r=>{const found=final.seeds.find(s=>s.name===r.name && s.hashes.length<=limit && canonicalJson(s.columns)===canonicalJson(r.columns));return found?[[r.name,found.hashes]]:[];}));},
26
26
  };
27
- });
27
+ },{nativeWrangler:true});
28
28
  }catch(error){if(error instanceof PortabilityError)throw error;throw new PortabilityError('schema_mismatch:legacy_evidence',409);}
29
29
  }
@@ -39,8 +39,12 @@ export async function migrateOperator(context, database) {
39
39
  await writePrivateFile(path, JSON.stringify({ name: config.name, compatibility_date: config.compatibility_date,
40
40
  d1_databases: [{ ...binding, migrations_dir: inventory, migrations_pattern: `${inventory}/*.sql` }] }));
41
41
  try {
42
+ // Wrangler redraws the full history after every migration. Keep warnings and
43
+ // errors, then name the migrations actually applied from the durable ledger.
44
+ const pending = names.filter(name => !before.has(name));
45
+ if (pending.length) store.report(`Applying ${pending.length} local migrations.`);
42
46
  await context.run(labels.migrate, 'pnpm', ['exec', 'wrangler', 'd1', 'migrations', 'apply', database,
43
- '--local', '--persist-to', state, '--config', path], { step: 'setup' });
47
+ '--local', '--persist-to', state, '--config', path], { step: 'setup', env: { ...process.env, WRANGLER_LOG: 'warn' } });
44
48
  const after = await appliedNames(state, table);
45
49
  const applied = names.filter(name => !before.has(name) && after.has(name));
46
50
  if (applied.length) store.report(`Applied local migrations: ${applied.join(', ')}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runeditrun/rer",
3
- "version": "0.2.94",
3
+ "version": "0.2.96",
4
4
  "description": "The rer command: install, set up, run and launch Run Edit Run checkouts.",
5
5
  "license": "MIT",
6
6
  "type": "module",