@runeditrun/rer 0.2.85 → 0.2.86
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.
- package/README.md +138 -29
- package/cli/README.md +61 -1
- package/cli/agent-door.mjs +149 -0
- package/cli/agent-fixtures.mjs +16 -0
- package/cli/agent-mail.mjs +54 -0
- package/cli/agent-network.mjs +64 -0
- package/cli/agent-reviewers.mjs +110 -0
- package/cli/agent-secrets.mjs +23 -0
- package/cli/agent-sponsors.mjs +43 -0
- package/cli/agent-surface.mjs +34 -0
- package/cli/agent-webhooks.mjs +19 -0
- package/cli/authoring.mjs +2 -1
- package/cli/business/archive-task.mjs +32 -0
- package/cli/business/carry.mjs +3 -1
- package/cli/business/catchup-task.mjs +42 -0
- package/cli/business/choices.mjs +97 -0
- package/cli/business/command.mjs +23 -5
- package/cli/business/connect.mjs +19 -7
- package/cli/business/detector.mjs +4 -1
- package/cli/business/device.mjs +13 -0
- package/cli/business/export-inputs.mjs +69 -0
- package/cli/business/export-task.mjs +17 -0
- package/cli/business/invocation.mjs +8 -1
- package/cli/business/keychain.mjs +8 -1
- package/cli/business/lease.mjs +11 -1
- package/cli/business/local-commands.mjs +79 -31
- package/cli/business/outbound.mjs +9 -4
- package/cli/business/parsers-config.mjs +8 -7
- package/cli/business/parsers-syntax.mjs +7 -3
- package/cli/business/permissions.mjs +2 -0
- package/cli/business/questions.mjs +89 -9
- package/cli/business/setup-command.mjs +49 -0
- package/cli/business/setup-company.json +15 -0
- package/cli/business/setup-demo.mjs +95 -0
- package/cli/business/state.mjs +44 -10
- package/cli/business/supervisor.mjs +94 -35
- package/cli/business/vendor-door.mjs +230 -0
- package/cli/business/vendors/README.md +29 -3
- package/cli/business/vendors/common.mjs +8 -6
- package/cli/business/vendors/index.mjs +22 -11
- package/cli/business/vendors/sorry.mjs +106 -0
- package/cli/contract.mjs +2 -2
- package/cli/demo-deploy-error.mjs +14 -0
- package/cli/demo-native.mjs +4 -1
- package/cli/deploy-config.mjs +1 -1
- package/cli/deploy-owner-input.mjs +3 -1
- package/cli/deploy-variables.mjs +58 -0
- package/cli/door-clauses.mjs +157 -0
- package/cli/export.mjs +16 -4
- package/cli/hosted-output.mjs +17 -7
- package/cli/inspect.mjs +4 -0
- package/cli/jsonc.mjs +8 -4
- package/cli/lifecycle.mjs +3 -1
- package/cli/main.mjs +1 -0
- package/cli/managed-data-schema.mjs +14 -1
- package/cli/portability-empty.mjs +6 -0
- package/cli/portability-migrations.mjs +26 -4
- package/cli/production-auth.mjs +1 -1
- package/cli/production-mail.mjs +8 -2
- package/edition-authoring/archive-source.mjs +59 -0
- package/edition-authoring/base-copies.mjs +92 -18
- package/edition-authoring/cli.mjs +1 -1
- package/edition-authoring/edition-migrations.mjs +7 -3
- package/edition-authoring/module-closure.mjs +2 -16
- package/edition-authoring/workflow-copies.mjs +1 -1
- package/edition-authoring/workflow-scripts.mjs +12 -3
- package/foundation/runtime/contract-docs.mjs +215 -32
- package/foundation/runtime/contract-prose-patterns.mjs +14 -0
- package/foundation/runtime/contract-prose.mjs +88 -0
- package/global/CHANGELOG.md +93 -0
- package/global/README.md +138 -29
- package/global/door/command.mjs +3 -1
- package/global/main.mjs +1 -1
- package/modules/agent-door/CLAUSES.md +215 -0
- package/modules/agent-door/conformance/audit.mjs +66 -0
- package/modules/agent-door/conformance/authority.d.mts +2 -0
- package/modules/agent-door/conformance/authority.mjs +17 -0
- package/modules/agent-door/conformance/crypto.mjs +36 -0
- package/modules/agent-door/conformance/discovery.mjs +61 -0
- package/modules/agent-door/conformance/index.mjs +41 -0
- package/modules/agent-door/conformance/invocation.mjs +32 -0
- package/modules/agent-door/conformance/journey.mjs +112 -0
- package/modules/agent-door/conformance/narrowing.d.mts +1 -0
- package/modules/agent-door/conformance/narrowing.mjs +21 -0
- package/modules/agent-door/conformance/negative.mjs +47 -0
- package/modules/agent-door/conformance/network-modules.mjs +86 -0
- package/modules/agent-door/conformance/network-runtime.mjs +46 -0
- package/modules/agent-door/conformance/policy-phases.mjs +75 -0
- package/modules/agent-door/conformance/protocol.mjs +145 -0
- package/modules/agent-door/conformance/replay.mjs +38 -0
- package/modules/agent-door/conformance/schema.mjs +71 -0
- package/modules/agent-door/conformance/security.mjs +33 -0
- package/modules/agent-door/conformance/sponsors.mjs +68 -0
- package/modules/agent-door/conformance/surface.mjs +89 -0
- package/modules/agent-door/conformance/target.mjs +18 -0
- package/modules/agent-door/conformance/tool-name.d.mts +1 -0
- package/modules/agent-door/conformance/tool-name.mjs +7 -0
- package/modules/agent-door/conformance/webhooks.mjs +30 -0
- package/modules/container/image-variables.mjs +8 -2
- package/modules/demo-host/README.md +6 -0
- package/modules/demo-host/ownership.mjs +39 -0
- package/modules/demo-host/plan.mjs +2 -1
- package/modules/demo-host/remove.mjs +6 -1
- package/modules/import-kit/schema/importer-verification-receipt.schema.json +171 -0
- package/modules/import-kit/schema/importers.schema.json +107 -0
- package/modules/import-kit/src/door/ADOPTING.md +20 -0
- package/modules/import-kit/src/door/README.md +2 -1
- package/modules/import-kit/src/door/admission.ts +5 -3
- package/modules/import-kit/src/door/archive.ts +5 -2
- package/modules/import-kit/src/door/authority.ts +1 -0
- package/modules/import-kit/src/door/grants.ts +1 -1
- package/modules/import-kit/src/door/handler.ts +14 -8
- package/modules/import-kit/src/door/index.ts +1 -1
- package/modules/import-kit/src/door/jobs.ts +40 -0
- package/modules/import-kit/src/door/operator.ts +3 -3
- package/modules/import-kit/src/door/planning.ts +10 -6
- package/modules/import-kit/src/door/protocol.ts +2 -2
- package/modules/import-kit/src/door/raw.ts +25 -0
- package/modules/import-kit/src/door/refusals.ts +1 -0
- package/modules/import-kit/src/door/types.ts +26 -6
- package/modules/import-kit/src/receipt/encoding.ts +37 -0
- package/modules/import-kit/src/receipt/index.ts +69 -0
- package/modules/import-kit/src/receipt/policy.ts +24 -0
- package/modules/import-kit/src/receipt/types.ts +64 -0
- package/modules/import-kit/src/receipt/uri.ts +45 -0
- package/modules/import-kit/src/receipt/validation.ts +87 -0
- package/modules/import-kit/src/status/encoding.ts +13 -0
- package/modules/import-kit/src/status/evidence.ts +218 -0
- package/modules/import-kit/src/status/index.ts +56 -0
- package/modules/import-kit/src/status/schema.ts +208 -0
- package/modules/import-kit/src/status/types.ts +86 -0
- package/modules/operator-auth/accounts/delegated.mjs +48 -0
- package/modules/operator-auth/index.d.mts +7 -0
- package/modules/operator-auth/service.mjs +2 -0
- package/modules/portability/README.md +32 -11
- package/modules/portability/bridge.mjs +22 -2
- package/modules/portability/copies.mjs +8 -1
- package/modules/portability/derived.mjs +33 -0
- package/modules/portability/http-errors.mjs +1 -1
- package/modules/portability/import.mjs +14 -7
- package/package.json +4 -2
- package/scripts/publish-check/copy_identities.py +3 -1
- package/scripts/publish-check/github_refs.py +32 -13
- package/cli/business/opt-ins.mjs +0 -37
|
@@ -237,11 +237,12 @@ provider operation.
|
|
|
237
237
|
| Compatible `d1_migrations`, every recorded name exactly equal to its checkout filename | `{nativeApply:true}`; Wrangler may apply its pending files. Plain Wrangler names remain supported; tracked history must also match hashes and applied states. |
|
|
238
238
|
| Native alias-only or hash-only relocation, or an unmapped native data-only row | `migration_ledger:incompatible`; restore the matching checkout or reconcile through the owning runner before native apply. |
|
|
239
239
|
| Sole, fully applied matching `rer_migrations` | `{nativeApply:false}`; preserve Platform's ledger and skip Wrangler. |
|
|
240
|
-
|
|
|
241
|
-
|
|
|
240
|
+
| Fully applied matching `_rer_deploy_migrations` plus plain Wrangler `d1_migrations` bookkeeping | `{nativeApply:false}`; preserve the deploy history and skip Wrangler. Bookkeeping names must belong to that history. A tracked D1 ledger must match the deploy history's names, hashes and order. |
|
|
241
|
+
| Any pending checkout file with Platform history or the legacy pair | `migration_ledger:unapplied`, naming the file (`error.migration`); apply it through the owning runner first. |
|
|
242
|
+
| Other multiple ledgers, or disagreeing tracked native histories | `migration_ledger:multiple`; reconcile history through its owning runner. |
|
|
242
243
|
| Legacy `_rer_deploy_migrations` alone | `migration_ledger:runner`; use its owning runner, which can adopt the history. |
|
|
243
244
|
| Invalid ledger shape, row or binding | `migration_ledger:incompatible` or `migration_ledger:binding`. |
|
|
244
|
-
| Partial Platform batch or non-applied tracked row | `migration_ledger:uncertain`; resolve the incomplete operation first. |
|
|
245
|
+
| Partial Platform batch or non-applied tracked or legacy row | `migration_ledger:uncertain`; resolve the incomplete operation first. |
|
|
245
246
|
| Unknown hash/name, ambiguous hash/alias or conflicting name/hash | `migration_ledger:unknown`, `:ambiguous` or `:conflict`; use the matching checkout and declaration. |
|
|
246
247
|
|
|
247
248
|
Refusals throw `PortabilityError` with status 409 and a constant `code`;
|
|
@@ -275,8 +276,10 @@ owner claim. Such a destination keeps that claim and recovers access through
|
|
|
275
276
|
ordinary native sign-in; setup does not grant another owner. Other tables are
|
|
276
277
|
discovered automatically. Exclusion rules follow SQLite's ASCII identifier case matching.
|
|
277
278
|
Unlisted virtual tables, hidden virtual-table columns and foreign keys into
|
|
278
|
-
excluded tables fail by name.
|
|
279
|
-
|
|
279
|
+
excluded tables fail by name. Restore rebuilds policy-declared external-content
|
|
280
|
+
FTS5 indexes from their content tables in the same transaction as the restored
|
|
281
|
+
rows. The product must explicitly regenerate other derived data. A schema
|
|
282
|
+
upgrade may change columns but cannot silently omit tables.
|
|
280
283
|
|
|
281
284
|
Provider link keys and transient provider sessions never travel. Export marks
|
|
282
285
|
retained dependency links as needing re-link and turns provider sign-in and
|
|
@@ -433,7 +436,7 @@ Re-export from the original installation to carry the complete definitions.
|
|
|
433
436
|
A new archive explicitly records even an empty object inventory, so later
|
|
434
437
|
additive migrations can still be placed normally. The separate acknowledged
|
|
435
438
|
v1 recovery path remains an explicitly unverified recovery, as documented below.
|
|
436
|
-
Version 2 backups without that inventory
|
|
439
|
+
Version 2 backups without that inventory use recorded migration replay when it proves the complete destination schema, or the acknowledged recovery below.
|
|
437
440
|
|
|
438
441
|
New exports use archive version 2. The closing `archiveHash` is SHA-256 of
|
|
439
442
|
canonical JSON `{manifest,parts}`, where `manifest` is the complete manifest
|
|
@@ -468,20 +471,30 @@ authenticate it. If the original installation is unavailable, use the explicit
|
|
|
468
471
|
[backup-only v1 recovery](#backup-only-v1-recovery) below. Normal import still
|
|
469
472
|
requires version 2 integrity.
|
|
470
473
|
|
|
471
|
-
##
|
|
474
|
+
## Older version 2 backups and acknowledged recovery
|
|
472
475
|
|
|
473
476
|
A fresh export from a current rer is preferred whenever the original installation
|
|
474
477
|
is available. Current archives carry the complete schema inventory and restore
|
|
475
478
|
without any acknowledgment. Version 2 backups written by rer 0.2.79 or earlier
|
|
476
|
-
can lack `schemaObjects`.
|
|
477
|
-
|
|
479
|
+
can lack `schemaObjects`. Ordinary import verifies such a backup without an
|
|
480
|
+
acknowledgment when its nonempty recorded migration history, resolved against the
|
|
481
|
+
destination's own applied files in order, replays to the complete live destination
|
|
482
|
+
schema identity, including indexes, views and triggers. The same replay's tables
|
|
483
|
+
must match the archive's table definitions. The archive's ledger, when present,
|
|
484
|
+
must agree with its recorded names, and available hashes must match. Missing
|
|
485
|
+
history, failed replay, table drift or a different complete destination identity
|
|
486
|
+
still refuses `schema_mismatch:legacy_schema` before staging. Source SQL is never
|
|
487
|
+
installed. This verified path records no `schemaUnverified` receipt.
|
|
488
|
+
|
|
489
|
+
When that proof is unavailable, the owner can explicitly accept that its schema
|
|
490
|
+
objects are unverified:
|
|
478
491
|
|
|
479
492
|
```sh
|
|
480
493
|
rer import --input exports/retained.rer --yes --acknowledge-unverified-schema-objects
|
|
481
494
|
```
|
|
482
495
|
|
|
483
|
-
This accepts only the missing inventory
|
|
484
|
-
|
|
496
|
+
This accepts only the missing inventory and preserves the existing recovery path,
|
|
497
|
+
even when ordinary import could verify the backup. The acknowledgment never accepts
|
|
485
498
|
version 1 metadata; that separate recovery still needs both v1 flags below.
|
|
486
499
|
The destination must be empty under the existing product emptiness rule:
|
|
487
500
|
non-migration rows in product tables refuse `target_not_empty:<table>` before
|
|
@@ -994,6 +1007,7 @@ modules/portability/sqlite-tokens.mjs
|
|
|
994
1007
|
modules/portability/bookkeeping.mjs
|
|
995
1008
|
modules/portability/storage.mjs
|
|
996
1009
|
modules/portability/copies.mjs
|
|
1010
|
+
modules/portability/derived.mjs
|
|
997
1011
|
modules/portability/dev-data.mjs
|
|
998
1012
|
modules/portability/provider-data.mjs
|
|
999
1013
|
modules/portability/policy-data.mjs
|
|
@@ -1109,6 +1123,13 @@ in destination migrations, including objects attached to excluded tables. Intern
|
|
|
1109
1123
|
prefixes are compared literally. A scratch native import preflight checks the
|
|
1110
1124
|
projected archive before native restore can open the destination.
|
|
1111
1125
|
|
|
1126
|
+
Policy-declared derived virtual tables omitted from a Managed dump are created
|
|
1127
|
+
in the sandbox from the destination's migrated definitions. Their triggers must
|
|
1128
|
+
still be present and compatible; omitting those triggers remains a schema
|
|
1129
|
+
refusal. The dump statement allowlist still refuses all `CREATE VIRTUAL TABLE`
|
|
1130
|
+
statements, including declared names. A native copy-normalization SQLite failure
|
|
1131
|
+
is reported as `copy_normalization_failed`, without SQL diagnostics or row values.
|
|
1132
|
+
|
|
1112
1133
|
The current intake supports one database and declared buckets, local Workers
|
|
1113
1134
|
transport, stored ZIP members, at most 10,000 entries and statements, a 128 MiB
|
|
1114
1135
|
archive, 64 MiB members, 4 MiB metadata members and 16 MiB of SQL, with each SQL
|
|
@@ -34,8 +34,8 @@ async function placement(db,manifest,cat,replay,ledger,history,legacyRecovery,un
|
|
|
34
34
|
const recorded=historyEntries && matchMigrationLedger(historyEntries,files,replay);
|
|
35
35
|
// Only explicitly acknowledged v1 recovery may use the old projection for
|
|
36
36
|
// archive placement. The live destination check above remains complete, and
|
|
37
|
-
//
|
|
38
|
-
//
|
|
37
|
+
// current v2 imports use their authenticated object inventory. Verified legacy
|
|
38
|
+
// v2 uses the replayed complete identity; acknowledged recovery places by tables only.
|
|
39
39
|
const schemaAfter=names=>replay.schemaAfter(names,legacyRecovery && manifest.schemaObjects===undefined?{legacyExcludedObjects:true}:unverified?{tablesOnly:true}:undefined);
|
|
40
40
|
if(unverified && archived && manifest.migrations)insist(canonicalJson(matchMigrationLedger(archived,files,replay))===canonicalJson(recorded),'schema_mismatch:migration_history',409);
|
|
41
41
|
let earlier,unapplied;
|
|
@@ -69,6 +69,26 @@ async function placement(db,manifest,cat,replay,ledger,history,legacyRecovery,un
|
|
|
69
69
|
const {replays,rebuilt}=laterData({applied,unapplied,replay,catalogue,archived:archivedTables,empty,tables,secrets:manifest.excludedColumns??{},manifest:manifest.tables});
|
|
70
70
|
return {applied,earlier,replays,rebuilt};
|
|
71
71
|
}
|
|
72
|
+
// Old v2 writers recorded tables and applied migration names, but no behavioral
|
|
73
|
+
// object inventory. Verify both projections: the recorded files must reproduce
|
|
74
|
+
// the complete live schema, and their tables must reproduce the archive. Never
|
|
75
|
+
// guess an unrecorded prefix or install source SQL to fill missing evidence.
|
|
76
|
+
export async function verifiedLegacySchema(db,manifest,cat,migrations,history) {
|
|
77
|
+
if(!migrations)return false;
|
|
78
|
+
const replay=await migrations(),ledger=await destinationLedger(db)??[];
|
|
79
|
+
try {
|
|
80
|
+
const files=replay.names.map(name=>({name,sha256:replay.sha256?.(name),aliases:replay.aliases?.(name)}));
|
|
81
|
+
const archived=history(),entries=manifest.migrations?.map(name=>archived?.find(entry=>entry.name===name)??{name})??archived;
|
|
82
|
+
if(!entries?.length)return false;
|
|
83
|
+
const applied=matchMigrationLedger(ledger,files,replay),recorded=matchMigrationLedger(entries,files,replay);
|
|
84
|
+
if(!recorded.length || canonicalJson(applied)!==canonicalJson(replay.names)
|
|
85
|
+
|| !recorded.every((name,i)=>applied.indexOf(name)>(i?applied.indexOf(recorded[i-1]):-1)))return false;
|
|
86
|
+
if(archived && manifest.migrations && canonicalJson(matchMigrationLedger(archived,files,replay))!==canonicalJson(recorded))return false;
|
|
87
|
+
return await replay.schemaAfter(applied)===cat.identity
|
|
88
|
+
&& await replay.schemaAfter(recorded)===cat.identity
|
|
89
|
+
&& await replay.schemaAfter(recorded,{tablesOnly:true})===manifest.schema;
|
|
90
|
+
}catch{return false;} // Unknown history or a failed replay is not verification.
|
|
91
|
+
}
|
|
72
92
|
// An archive with the destination's schema identity can still predate later
|
|
73
93
|
// migrations that changed only data (a purge or a backfill).
|
|
74
94
|
// Those that change restorable data are refused like any other. Without a
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { all,statement,quote,insist } from './storage.mjs';
|
|
1
|
+
import { all,statement,quote,insist,PortabilityError } from './storage.mjs';
|
|
2
2
|
import { projectedColumns,encodedRow,mapRow,bindCell,writableColumns } from './catalogue.mjs';
|
|
3
3
|
import { canonicalJson, utf8 } from './hash.mjs';
|
|
4
4
|
import { generatedCopySQL } from './generated.mjs';
|
|
@@ -43,6 +43,13 @@ export async function readCopy(db,table,copy,offset,limit,encoded=false) {
|
|
|
43
43
|
return raw.map((row,i)=>({row,meta:meta[i]}));
|
|
44
44
|
}
|
|
45
45
|
export async function normalizeCopy(context,table,copy) {
|
|
46
|
+
try { return await normalize(context,table,copy); }
|
|
47
|
+
catch(error) {
|
|
48
|
+
if(error instanceof PortabilityError)throw error;
|
|
49
|
+
throw new PortabilityError('copy_normalization_failed',409);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function normalize(context,table,copy) {
|
|
46
53
|
const {db,config}=context,secrets=config.secretColumns[table.name]??[];
|
|
47
54
|
// Generated reads must reflect exactly the base cells a restore will receive.
|
|
48
55
|
if(table.columns.some(c=>c.generated)&&secrets.length)await db.prepare(`UPDATE ${quote(copy)} SET ${secrets.map(name=>quote(name)+'=NULL').join(',')}`).run();
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { all, quote } from './storage.mjs';
|
|
2
|
+
import { sqliteTokens, asciiFold } from './sqlite-tokens.mjs';
|
|
3
|
+
|
|
4
|
+
const value = token => {
|
|
5
|
+
const text = token?.text ?? '', delimiter = text[0];
|
|
6
|
+
return ['"', "'", '`', '['].includes(delimiter)
|
|
7
|
+
? text.slice(1, -1).replaceAll(delimiter + delimiter, delimiter) : text;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// Only external-content FTS5 has SQLite's native rebuild contract: its rows
|
|
11
|
+
// come from the migrated content table. Other derived data remains seed-owned.
|
|
12
|
+
function externalFts5(sql) {
|
|
13
|
+
const tokens = sqliteTokens(sql), words = tokens.map(token => asciiFold(token.text));
|
|
14
|
+
if (words.slice(0, 3).join(' ') !== 'create virtual table') return false;
|
|
15
|
+
const using = words.indexOf('using');
|
|
16
|
+
if (using < 0 || asciiFold(value(tokens[using + 1])) !== 'fts5') return false;
|
|
17
|
+
let depth = 0;
|
|
18
|
+
for (let i = using + 2; i < tokens.length; i++) {
|
|
19
|
+
if (tokens[i].text === '(') depth++;
|
|
20
|
+
else if (tokens[i].text === ')') depth--;
|
|
21
|
+
else if (depth === 1 && ['(', ','].includes(tokens[i - 1]?.text)
|
|
22
|
+
&& asciiFold(value(tokens[i])) === 'content' && tokens[i + 1]?.text === '=')
|
|
23
|
+
return value(tokens[i + 2]).length > 0;
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function rebuildDerivedStatements(db, config) {
|
|
29
|
+
if (!config.derivedTables.length) return [];
|
|
30
|
+
const objects = await all(db, "SELECT name,sql FROM sqlite_master WHERE type='table' AND sql IS NOT NULL ORDER BY name");
|
|
31
|
+
return objects.filter(object => config.derivedTables.includes(object.name) && !config.includeTables.includes(object.name) && externalFts5(object.sql))
|
|
32
|
+
.map(object => db.prepare(`INSERT INTO ${quote(object.name)}(${quote(object.name)}) VALUES('rebuild')`));
|
|
33
|
+
}
|
|
@@ -5,7 +5,7 @@ import { importRunningMetadata } from './import-lease.mjs';
|
|
|
5
5
|
const publicCodes = new Set(`
|
|
6
6
|
D1_RPC_TRANSPORT_LIMIT advance_limit archive_checksum archive_format archive_incomplete archive_json
|
|
7
7
|
binary_checksum binary_inventory binary_order binary_size body_too_large bucket_inventory bucket_not_empty
|
|
8
|
-
closing_missing column_inventory configuration_inventory confirmation_required content_checksum copy_inventory copy_rowid
|
|
8
|
+
closing_missing column_inventory configuration_inventory confirmation_required content_checksum copy_inventory copy_normalization_failed copy_rowid
|
|
9
9
|
data_after_closing dev_data erased_row erasure_epoch excluded_destination_dependents excluded_foreign_key
|
|
10
10
|
export_incomplete export_phase export_row_must_be_pure export_row_not_idempotent extra_part generated_sql
|
|
11
11
|
import_applying import_complete import_lease_expired import_phase import_row_columns import_row_key import_row_must_be_pure
|
|
@@ -13,11 +13,12 @@ import { fence, mergeJournal, tombstone } from './journal.mjs';
|
|
|
13
13
|
import { writeObject } from './payloads.mjs';
|
|
14
14
|
import { createCopy,sidecar,readCopy,restoreCopy } from './copies.mjs';
|
|
15
15
|
import { excludedDependentGuards, migrationSeeded, seededCondition } from './restore-safety.mjs';
|
|
16
|
-
import { additiveBridge, sameSchemaMigrations, appliedMigrations } from './bridge.mjs';
|
|
16
|
+
import { additiveBridge, sameSchemaMigrations, appliedMigrations, verifiedLegacySchema } from './bridge.mjs';
|
|
17
17
|
import { replayStatements } from './backfills.mjs';
|
|
18
18
|
import { checkArchivedLedgers, archivedHistory } from './ledgers.mjs';
|
|
19
19
|
import { legacyEmptyGuards, legacyAuditStatements, requireLegacyEmpty } from './legacy-safety.mjs';
|
|
20
20
|
import { checkReferences } from './references.mjs';
|
|
21
|
+
import { rebuildDerivedStatements } from './derived.mjs';
|
|
21
22
|
// ledgers: the rows of each migration ledger table the archive carries, as the
|
|
22
23
|
// caller read them from it ({table:rows}); uploadPart binds them to its parts.
|
|
23
24
|
export async function createImport(context,manifest,actor='direct',legacyRecovery,ledgers,acknowledgeUnverifiedSchemaObjects=false) {
|
|
@@ -28,17 +29,22 @@ export async function createImport(context,manifest,actor='direct',legacyRecover
|
|
|
28
29
|
const original=manifest;manifest=await restorableManifest(original);
|
|
29
30
|
const skippedTables=original.tables.filter(table=>platformTable(table.name)).map(table=>table.name);
|
|
30
31
|
const cat=await catalogue(db,config),upgrade=config.acceptedSchemas[original.schema];
|
|
31
|
-
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
const legacy=original.version===2 && manifest.schemaObjects===undefined;
|
|
33
|
+
// An explicit acknowledgment keeps its existing recovery semantics. Without
|
|
34
|
+
// it, legacy v2 needs positive replay evidence for the complete destination.
|
|
35
|
+
const unverified=legacy && acknowledgeUnverifiedSchemaObjects===true;
|
|
36
|
+
const verifyingLegacy=legacy && !unverified && !legacyRecovery;
|
|
37
|
+
const history=()=>archivedHistory(original,ledgers,{allowOlderShape:unverified || verifyingLegacy});
|
|
38
|
+
const verified=verifyingLegacy && await verifiedLegacySchema(db,manifest,cat,context.migrations,history);
|
|
39
|
+
insist(!legacy || legacyRecovery || unverified || verified,'schema_mismatch:legacy_schema',409);
|
|
40
|
+
if(verified)manifest={...manifest,schema:cat.identity,schemaObjects:cat.schemaObjects};
|
|
35
41
|
if(unverified)for(const table of manifest.tables) {
|
|
36
42
|
const target=cat.tables.find(t=>t.name===table.name);
|
|
37
43
|
insist(target,'schema_mismatch:table:'+table.name,409);
|
|
38
44
|
for(const column of table.columns)insist(target.columns.some(c=>canonicalJson(c)===canonicalJson(column)),'schema_mismatch:column:'+table.name+':'+column.name,409);
|
|
39
45
|
insist(table.dependencies.every(d=>target.dependencies.includes(d)),'schema_mismatch:dependencies:'+table.name,409);
|
|
40
46
|
}
|
|
41
|
-
const same=manifest.schema===cat.identity
|
|
47
|
+
const same=manifest.schema===cat.identity;
|
|
42
48
|
const {replays,...bridge}=unverified?await additiveBridge(db,manifest,cat,context.migrations,history,legacyRecovery,true):upgrade?{}:same?(await sameSchemaMigrations(db,manifest,cat,context.migrations,history)??{}):await additiveBridge(db,manifest,cat,context.migrations,history,legacyRecovery);
|
|
43
49
|
// Finalize checks object references on the staged rows; a later migration
|
|
44
50
|
// replayed into a reference table would publish rows that check never saw.
|
|
@@ -216,6 +222,7 @@ async function finalizeLeasedImport(context,id,{contentHash,archiveHash,laterJou
|
|
|
216
222
|
insist(hash.digest()===object.sha256,'object_write_checksum');
|
|
217
223
|
}
|
|
218
224
|
for(const payload of manifest.payloads)await config.extraPayloads[payload.name].consume(binaryStream(context,id,payload,binaryIndexes),payload);
|
|
225
|
+
const derived=await rebuildDerivedStatements(db,config);
|
|
219
226
|
row.phase='complete';row.metadata.contentHash=digest;
|
|
220
227
|
if(row.metadata.schemaUnverified)row.metadata.schemaUnverified.archiveHash=archiveHash;
|
|
221
228
|
await db.batch([db.prepare('PRAGMA defer_foreign_keys=ON'),...emptyGuards(context,row,seeded),...seeded.map(t=>guard(db,...seededCondition(t))),...dependentGuards,...legacyEmptyGuards(db,row),
|
|
@@ -224,7 +231,7 @@ async function finalizeLeasedImport(context,id,{contentHash,archiveHash,laterJou
|
|
|
224
231
|
...row.metadata.triggers.map(t=>db.prepare(`DROP TRIGGER ${quote(t.name)}`)),
|
|
225
232
|
...replaced.map(t=>db.prepare(`DELETE FROM ${quote(t)}`)),
|
|
226
233
|
...row.metadata.targets.flatMap(t=>restoreCopy(db,t,row.metadata.copies[t.name])),save(db,row),...replayStatements(db,row),
|
|
227
|
-
...row.metadata.triggers.map(t=>db.prepare(t.sql)),...mergeJournal(db,manifest,checked),...legacyAuditStatements(db,row),
|
|
234
|
+
...row.metadata.triggers.map(t=>db.prepare(t.sql)),...derived,...mergeJournal(db,manifest,checked),...legacyAuditStatements(db,row),
|
|
228
235
|
// Publication and removal of this import's scratch commit together. A lost
|
|
229
236
|
// acknowledgement still finds a complete job with no staging left behind.
|
|
230
237
|
...dropCopyStatements(db,row),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runeditrun/rer",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.86",
|
|
4
4
|
"description": "The rer command: install, set up, run and launch Run Edit Run checkouts.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -94,7 +94,9 @@
|
|
|
94
94
|
"./modules/dependencies": "./modules/dependencies/index.mjs",
|
|
95
95
|
"./internal/*": "./*",
|
|
96
96
|
"./package.json": "./package.json",
|
|
97
|
-
"./modules/import-kit/door": "./modules/import-kit/src/door/index.ts"
|
|
97
|
+
"./modules/import-kit/door": "./modules/import-kit/src/door/index.ts",
|
|
98
|
+
"./modules/import-kit/receipt": "./modules/import-kit/src/receipt/index.ts",
|
|
99
|
+
"./modules/import-kit/status": "./modules/import-kit/src/status/index.ts"
|
|
98
100
|
},
|
|
99
101
|
"engines": {
|
|
100
102
|
"node": ">=22"
|
|
@@ -34,7 +34,9 @@ def copy_pointers(document, read_regular):
|
|
|
34
34
|
value = read_regular(name)
|
|
35
35
|
if (value is None or value[1] != modes[name]
|
|
36
36
|
or hashlib.sha256(value[0]).hexdigest() != digest):
|
|
37
|
-
|
|
37
|
+
# An adapted or mismatched file does not invalidate its siblings'
|
|
38
|
+
# proofs. Its own digest and content remain ordinary scan inputs.
|
|
39
|
+
continue
|
|
38
40
|
pending.add(('copies', index, 'files', name))
|
|
39
41
|
else:
|
|
40
42
|
allowed.update(pending)
|
|
@@ -51,10 +51,35 @@ CONTEXT_URL = re.compile(r'(?i)(?<![A-Za-z])(?:' + REPOSITORY_CONTEXT + r')'
|
|
|
51
51
|
+ r'''[`*_~\[\]\s"']*(?:''' + URL.pattern.replace('(?i)', '') + ')')
|
|
52
52
|
LINK_URL = re.compile(r'(?i)\[(?P<label>[^]\n]+)\]\(\s*(?P<url>' + URL.pattern.replace('(?i)', '') + ')')
|
|
53
53
|
REPOSITORY_LABEL = re.compile(r'(?i)\b(?:' + REPOSITORY_CONTEXT + r')\b')
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
CODE_PREFIX = re.compile(r'(?i)(?<![A-Za-z])(?:origin|submodules?|repositories|repos|forks|clones)' + MARKUP + r'[ \t]*(?:[:=][ \t]*)?$')
|
|
55
|
+
CODE_SUFFIX = re.compile(r'(?i)[ \t]+(?:repositor(?:y|ies)|repos?)\b')
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def markdown_repository_context(match, text):
|
|
59
|
+
"""A declaration or command must attach to the token, not nearby prose."""
|
|
60
|
+
if match['reference'] is None:
|
|
61
|
+
prefix = text[text.rfind('\n', 0, match.start()) + 1:match.start()]
|
|
62
|
+
return bool(CODE_PREFIX.search(prefix) or CODE_SUFFIX.match(text, match.end()))
|
|
63
|
+
separator = match['separator']
|
|
64
|
+
if '\n' in text[match.start():match.start('reference')] and not re.search(r'[:=]', separator):
|
|
65
|
+
return False
|
|
66
|
+
prefix = text[text.rfind('\n', 0, match.start()) + 1:match.start()]
|
|
67
|
+
if '|' in separator:
|
|
68
|
+
# A table label occupies a whole cell. The last word of an outcome
|
|
69
|
+
# such as "registered against a repository" cannot label the next cell.
|
|
70
|
+
return not prefix.rsplit('|', 1)[-1].strip(' \t`*_~[]')
|
|
71
|
+
if re.search(r'[:=]', separator):
|
|
72
|
+
return True
|
|
73
|
+
# A bare "source" is not a declaration: "source commit/tree" is prose.
|
|
74
|
+
if re.fullmatch(r'(?i)source', match['label']) and not re.search(
|
|
75
|
+
r'(?i)repository|repo', text[match.start():match.start('reference')]):
|
|
76
|
+
return False
|
|
77
|
+
command = re.match(r'(?i)github|gh\s|clone|fork', match['label'])
|
|
78
|
+
end = text.find('\n', match.end())
|
|
79
|
+
tail = text[match.end():end if end != -1 else len(text)]
|
|
80
|
+
declaration = (re.fullmatch(r'[ \t#>*_~`\[\]-]*(?:[0-9]+\.[ \t]+)?', prefix) and
|
|
81
|
+
re.fullmatch(r'[ \t\r`*_~\[\].,;:!)]*', tail))
|
|
82
|
+
return bool(match['markup'] or command or declaration)
|
|
58
83
|
|
|
59
84
|
|
|
60
85
|
def explicit_references(text, path):
|
|
@@ -109,7 +134,7 @@ def reference_sets(text, path, local_paths=frozenset(), project_identity=None):
|
|
|
109
134
|
markdown = URL.sub('', text)
|
|
110
135
|
markdown = re.sub(r'\]\((?![A-Za-z][A-Za-z0-9+.-]*://)[^)]*\)', ']()', markdown)
|
|
111
136
|
for match in MARKDOWN_REFERENCE.finditer(markdown):
|
|
112
|
-
explicit = match
|
|
137
|
+
explicit = markdown_repository_context(match, markdown)
|
|
113
138
|
value = re.split(r'[?#]', match['reference'] or match['code'], maxsplit=1)[0]
|
|
114
139
|
# Underscores are also legal slug characters; remove a closing
|
|
115
140
|
# emphasis marker only when the reference has its matching opener.
|
|
@@ -123,17 +148,11 @@ def reference_sets(text, path, local_paths=frozenset(), project_identity=None):
|
|
|
123
148
|
continue
|
|
124
149
|
# A plain multi-segment path is ambiguous; GitHub's repository
|
|
125
150
|
# routes, a labeled field or a GitHub command disambiguate it.
|
|
126
|
-
labeled = explicit and (re.search(r'[:=|]', match['separator']) or re.match(r'(?i)github|gh\s', match['label']))
|
|
151
|
+
labeled = explicit and match['reference'] is not None and (re.search(r'[:=|]', match['separator']) or re.match(r'(?i)github|gh\s', match['label']))
|
|
127
152
|
if REPOSITORY_ROUTE.match(suffix) or labeled:
|
|
128
153
|
found.add(normalize(repository))
|
|
129
154
|
elif not suffix:
|
|
130
|
-
if explicit
|
|
131
|
-
weak = re.fullmatch(r'(?i)source', match['label']) and not re.search(r'(?i)repository|repo', markdown[match.start():match.start('reference')])
|
|
132
|
-
else:
|
|
133
|
-
line_start = markdown.rfind('\n', 0, match.start()) + 1
|
|
134
|
-
around = markdown[max(line_start, match.start() - CONTEXT_WINDOW):match.end() + CONTEXT_WINDOW].split('\n', 1)[0]
|
|
135
|
-
weak = not NEARBY_CONTEXT.search(around)
|
|
136
|
-
(ambiguous if weak else found).add(normalize(repository))
|
|
155
|
+
(found if explicit else ambiguous).add(normalize(repository))
|
|
137
156
|
elif METADATA.search(path) or SOURCE.search(path):
|
|
138
157
|
if path.lower().endswith('.json'):
|
|
139
158
|
try:
|
package/cli/business/opt-ins.mjs
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { installService } from './service.mjs';
|
|
2
|
-
import { installPermissions } from './permissions.mjs';
|
|
3
|
-
import { saveState } from './state.mjs';
|
|
4
|
-
import { carryLive } from './carry.mjs';
|
|
5
|
-
import { rerCommand } from './invocation.mjs';
|
|
6
|
-
|
|
7
|
-
// The server's field names stay internal; people see the browser's sentences.
|
|
8
|
-
export const optIns = {
|
|
9
|
-
installPermissions: 'Add rules so Claude Code never reads your secret files',
|
|
10
|
-
awakeConsent: 'Keep this computer awake while it works',
|
|
11
|
-
installService: 'Install the background service',
|
|
12
|
-
};
|
|
13
|
-
const optInNames = Object.keys(optIns);
|
|
14
|
-
|
|
15
|
-
export async function applyOptIns(api, state, { report = true } = {}) {
|
|
16
|
-
let self;
|
|
17
|
-
// A server without this route answers a device credential with 403 (or 404):
|
|
18
|
-
// nothing is decided yet. This first authenticated request activates the computer.
|
|
19
|
-
try { self = await api.get('/api/business/executors/self'); }
|
|
20
|
-
catch (error) { if (![403, 404].includes(error.status)) throw error; }
|
|
21
|
-
await carryLive(state, self);
|
|
22
|
-
const decisions = Object.fromEntries(optInNames.map(name => [name, self?.optIns?.[name] === true ? true : self?.optIns?.[name] === false ? false : null]));
|
|
23
|
-
if (decisions.installPermissions === true) await installPermissions({ consent: true });
|
|
24
|
-
state.awakeConsent = decisions.awakeConsent === true;
|
|
25
|
-
await saveState(state);
|
|
26
|
-
if (decisions.installService === true) await installService({ consent: true });
|
|
27
|
-
if (!report) return;
|
|
28
|
-
process.stdout.write(`This computer is connected to Business at ${state.origin}.\n`);
|
|
29
|
-
if (decisions.installService === true) {
|
|
30
|
-
process.stdout.write('The background service is installed and works tasks after this chat ends.\n');
|
|
31
|
-
}
|
|
32
|
-
const undecided = optInNames.filter(name => decisions[name] === null);
|
|
33
|
-
if (undecided.length) {
|
|
34
|
-
process.stdout.write(`The owner has not chosen yet:\n${undecided.map(name => ` - ${optIns[name]}\n`).join('')}Ask them to choose on this computer's row in ${state.origin}/business/${encodeURIComponent(state.businessId)}/settings.\n`);
|
|
35
|
-
}
|
|
36
|
-
process.stdout.write(`Run ${rerCommand()} business next to apply the owner's latest choices and see the next task.\n`);
|
|
37
|
-
}
|