@runeditrun/rer 0.2.122 → 0.2.124
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/cli/README.md +8 -0
- package/cli/bounded.mjs +3 -3
- package/cli/business/agent-output.mjs +4 -2
- package/cli/business/agent-verbs.mjs +10 -4
- package/cli/business/api.mjs +12 -9
- package/cli/business/carry.mjs +3 -2
- package/cli/business/choices.mjs +4 -1
- package/cli/business/connect.mjs +2 -1
- package/cli/business/local-commands.mjs +4 -1
- package/cli/business/mcp-bridge.mjs +7 -2
- package/cli/business/questions.mjs +5 -4
- package/cli/business/refusal.mjs +47 -0
- package/cli/business/run-grant.mjs +15 -16
- package/cli/business/setup-command.mjs +7 -2
- package/cli/business/supervisor.mjs +4 -1
- package/cli/deploy.mjs +2 -1
- package/cli/dev-identity.mjs +7 -0
- package/cli/errors.mjs +45 -9
- package/cli/export.mjs +1 -0
- package/cli/inspect.mjs +2 -0
- package/cli/main.mjs +17 -3
- package/cli/managed-server.mjs +8 -4
- package/cli/portability-empty.mjs +4 -2
- package/cli/portability-evidence.mjs +9 -1
- package/cli/portability-migrations.mjs +30 -8
- package/cli/portability-owners.mjs +54 -0
- package/cli/portability-worker.mjs +13 -5
- package/cli/portability.mjs +6 -4
- package/cli/render-warmup.mjs +31 -0
- package/cli/setup-input.mjs +14 -2
- package/cli/site-private.mjs +9 -1
- package/cli/site.mjs +5 -5
- package/edition-authoring/cli.mjs +3 -0
- package/edition-authoring/project-hashes.mjs +58 -0
- package/global/CHANGELOG.md +45 -0
- package/global/launch/dev.mjs +2 -2
- package/global/launch/render.mjs +12 -1
- package/global/launch/state.mjs +11 -4
- package/global/launch/worker.mjs +22 -5
- package/modules/deploy-kit/owner-cli.mjs +5 -2
- package/modules/deploy-kit/owner-remove.mjs +23 -5
- package/modules/job-queue/identity.mjs +11 -6
- package/modules/job-queue/policy.mjs +16 -2
- package/modules/operator-auth/README.md +6 -0
- package/modules/operator-auth/accounts/oa.mjs +1 -1
- package/modules/operator-auth/dev/index.mjs +32 -14
- package/modules/operator-auth/dev/persona-entry.mjs +38 -0
- package/modules/operator-auth/dev/persona-grant.mjs +16 -0
- package/modules/operator-auth/dev-admission.d.mts +2 -2
- package/modules/operator-auth/dev-admission.mjs +2 -2
- package/modules/operator-auth/dev-gate-script.mjs +28 -0
- package/modules/operator-auth/dev-gate.mjs +7 -10
- package/modules/portability/README.md +7 -2
- package/modules/portability/bridge.mjs +25 -23
- package/modules/portability/checkout-history.mjs +7 -6
- package/modules/portability/export.mjs +6 -3
- package/modules/portability/format.mjs +2 -2
- package/modules/portability/http-errors.mjs +1 -1
- package/modules/portability/http.mjs +2 -2
- package/modules/portability/import.mjs +13 -11
- package/modules/portability/index.d.mts +4 -2
- package/modules/portability/index.mjs +2 -2
- package/modules/portability/ledgers.mjs +16 -3
- package/modules/portability/legacy-files.mjs +3 -3
- package/modules/portability/migration-history.mjs +4 -3
- package/modules/portability/owner-history.mjs +62 -0
- package/modules/portability/worker-history.d.mts +1 -0
- package/modules/portability/worker-history.mjs +4 -4
- package/modules/release/README.md +7 -0
- package/modules/release/produce.mjs +3 -0
- package/onboarding/adapter.mjs +9 -9
- package/onboarding/commands.mjs +15 -5
- package/onboarding/operator-installer.mjs +2 -2
- package/onboarding/operator-settings.mjs +10 -8
- package/onboarding/redaction.mjs +1 -1
- package/package.json +1 -1
package/cli/main.mjs
CHANGED
|
@@ -8,7 +8,11 @@ import { check, describe, doctorSummary } from './inspect.mjs';
|
|
|
8
8
|
import { selectNodeRuntime } from './node-runtime.mjs';
|
|
9
9
|
import { resolve } from 'node:path';
|
|
10
10
|
|
|
11
|
-
export async function main(argv
|
|
11
|
+
export async function main(argv) {
|
|
12
|
+
// The executable entry points call main() without arguments. Callers supplying
|
|
13
|
+
// their own argv get a status without changing the lifetime of their process.
|
|
14
|
+
const executable = argv === undefined;
|
|
15
|
+
argv ??= process.argv.slice(2);
|
|
12
16
|
if (argv[0] === 'rehearse') return (await import('./rehearse.mjs')).rehearseCommand(argv.slice(1));
|
|
13
17
|
if (argv[0] === 'door' && argv[1] === 'clauses') return (await import('./door-clauses.mjs')).doorClausesCommand(argv.slice(2));
|
|
14
18
|
if (argv[0] === 'business') return (await import('./business/command.mjs')).businessCommand(argv.slice(1));
|
|
@@ -51,6 +55,11 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
51
55
|
}
|
|
52
56
|
}
|
|
53
57
|
if(options.noQueue){const {shared}=await import('./shared.mjs');const {commandPolicy}=await shared('queue.mjs');const policy=await commandPolicy();try{if(!policy.ci)throw invalid('--no-queue requires the original caller CI=true.');}finally{await policy.close();}}
|
|
58
|
+
if (options.verb === 'verify') {
|
|
59
|
+
const { checkoutProjectHashProblems } = await import('../edition-authoring/project-hashes.mjs');
|
|
60
|
+
const problems = checkoutProjectHashProblems(options.cwd);
|
|
61
|
+
if (problems.length) throw new RerError('invalid_project_hash', problems.join('\n'), 1);
|
|
62
|
+
}
|
|
54
63
|
const runtime = await selectNodeRuntime(options, argv, out);
|
|
55
64
|
if (runtime) return runtime.exitCode;
|
|
56
65
|
if (!independent && Object.hasOwn(authoringVerbs, options.verb)) {
|
|
@@ -98,8 +107,13 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
98
107
|
else result = await (await import('./lifecycle.mjs')).runCommand(project, options, out);
|
|
99
108
|
out.result(true, 0, result); return 0;
|
|
100
109
|
} catch (error) {
|
|
101
|
-
const
|
|
102
|
-
|
|
110
|
+
const expected = error instanceof RerError;
|
|
111
|
+
const failure = expected ? error : unexpectedFailure(error);
|
|
112
|
+
out.error(failure); out.result(false, failure.exitCode, { ...failure.exportDetails, ...(failure.siteDeploy ? {siteDeploy:failure.siteDeploy} : {}), ...(failure.d1Import ? {d1Import:failure.d1Import} : {}), ...(failure.childExitCode === undefined ? {} : { childExitCode: failure.childExitCode, signal: failure.signal }) });
|
|
113
|
+
// The command's finally blocks have run. Allow pending output and cleanup to
|
|
114
|
+
// drain, but give a lingering handle at most three seconds to keep rer alive.
|
|
115
|
+
if (executable && !expected) setTimeout(() => process.exit(failure.exitCode), 3000).unref();
|
|
116
|
+
return failure.exitCode;
|
|
103
117
|
}
|
|
104
118
|
}
|
|
105
119
|
|
package/cli/managed-server.mjs
CHANGED
|
@@ -19,8 +19,9 @@ import { invalid,missing,refuse,RerError,lifecycleError } from './errors.mjs';
|
|
|
19
19
|
import { processInfo } from '../modules/job-queue/processes.mjs';
|
|
20
20
|
import { declaredCrons,runScheduled } from './scheduled.mjs';
|
|
21
21
|
import { demoGuarded,demoPreflight } from './demo.mjs';
|
|
22
|
-
import { readDevKey,requireDevKey,refuseManagedInstallation,resolvePersona,openUrl } from './dev-identity.mjs';
|
|
22
|
+
import { readDevKey,requireDevKey,refuseManagedInstallation,resolvePersona,openUrl,personaOpenUrl } from './dev-identity.mjs';
|
|
23
23
|
import { announceDoorRoute,claimSavedName,moveCheckout,routeRunning,verifyDoorFor } from './door-mode.mjs';
|
|
24
|
+
import { warmDocumentRender } from './render-warmup.mjs';
|
|
24
25
|
|
|
25
26
|
// Dev opens through the local identity exchange. Preview serves production output.
|
|
26
27
|
export async function ready(out,url,dev,json=false,siteUrl,demo,root,ownerOpenUrl){
|
|
@@ -150,6 +151,8 @@ export async function managedServer(project,options,out,{clock={}}={}){
|
|
|
150
151
|
// The runtime can receive public requests now. Keep announcement/registry
|
|
151
152
|
// readiness false until the browser has verified that same public door.
|
|
152
153
|
forwarding=true;
|
|
154
|
+
// Dev loads modules on demand: render one document now, so the owner's first signed-in page after setup does not pay for the whole graph.
|
|
155
|
+
if(options.verb==='dev')await warmDocumentRender(selected.url,proxy.probe,controller.signal,store);
|
|
153
156
|
// A key is sent (or printed) for a door origin only once the door proves it is ours.
|
|
154
157
|
if(devKey)await verifyDoorFor(selected.url);
|
|
155
158
|
if(demo)await demoGuarded(selected.url,demo.state,controller.signal);
|
|
@@ -189,7 +192,7 @@ function reportScheduled(out,options,run){
|
|
|
189
192
|
// which reset removes with the rest of .rer/local, for a person or agent that
|
|
190
193
|
// did not keep the terminal output.
|
|
191
194
|
async function emitReady(out,options,root,url,dev,siteUrl,demo,ownerOpenUrl){
|
|
192
|
-
if(options.verb==='dev'&&dev?.openUrl){
|
|
195
|
+
if(options.verb==='dev'&&options.as===undefined&&dev?.openUrl){
|
|
193
196
|
const {privateDirectory,writePrivateFile}=await shared('private-files.mjs');
|
|
194
197
|
await writePrivateFile(join(await privateDirectory(root,['.rer','local']),'open-url'),dev.openUrl+'\n');
|
|
195
198
|
}
|
|
@@ -199,9 +202,10 @@ async function devReady(root,url,key,options,signal,store){
|
|
|
199
202
|
const as=options.as??'owner',persona=await resolvePersona(url,key,as,signal);
|
|
200
203
|
// The owner persona names the owner the session will actually have (the
|
|
201
204
|
// remaining owner once the setup owner has left), or none when none is left.
|
|
202
|
-
const
|
|
205
|
+
const scoped=options.as!==undefined;
|
|
206
|
+
const link=scoped?await personaOpenUrl(url,key,persona):openUrl(url,key,{path:'/__dev/key',as:persona.as});
|
|
203
207
|
await ownerEntryReady(root,link,signal,store);
|
|
204
|
-
return {identity:true,signedInAs:persona.email??null,ownerLeft:as==='owner'&&!persona.email,openUrl:link};
|
|
208
|
+
return {identity:true,signedInAs:persona.email??null,ownerLeft:as==='owner'&&!persona.email,openUrl:scoped?await personaOpenUrl(url,key,persona):link};
|
|
205
209
|
}
|
|
206
210
|
async function checkedNativeEntry(root,issue,signal,store){
|
|
207
211
|
const link=await issue();
|
|
@@ -11,6 +11,7 @@ import { splitStatements } from '../modules/portability/sql-text.mjs';
|
|
|
11
11
|
import { requireEmptyTables } from '../modules/portability/restore-empty.mjs';
|
|
12
12
|
import { insist } from '../modules/portability/storage.mjs';
|
|
13
13
|
import { shared } from './shared.mjs';
|
|
14
|
+
import { ownerMigrationPolicy, ownerMigrationSources } from './portability-owners.mjs';
|
|
14
15
|
|
|
15
16
|
const status = path => lstat(path).catch(error => { if (error.code === 'ENOENT') return null; throw error; });
|
|
16
17
|
// Miniflare's named D1 identity: the declared binding determines its file.
|
|
@@ -58,8 +59,9 @@ export async function emptyNativePreflight({ root, binding, policy, policyModule
|
|
|
58
59
|
async all() { return { results: query.all(...values) }; },
|
|
59
60
|
async first() { return query.get(...values) ?? null; },
|
|
60
61
|
}; } };
|
|
61
|
-
const
|
|
62
|
-
const
|
|
62
|
+
const owners = await ownerMigrationSources(root, binding);
|
|
63
|
+
const rules = ownerMigrationPolicy(await loadPolicy(root, policy, policyModule), owners), declaration = platformMigrationDeclaration(platformMigrations);
|
|
64
|
+
const migrations = async () => migrationReplay(await appliedMigrations(root, db, binding, declaration, splitStatements, owners), rules, declaration);
|
|
63
65
|
await requireEmptyTables({ db, policy: rules, migrations });
|
|
64
66
|
} finally { try { snapshot?.close(); } finally { await rm(directory, { recursive: true, force: true }); } }
|
|
65
67
|
}
|
|
@@ -2,6 +2,8 @@ import { DatabaseSync } from 'node:sqlite';
|
|
|
2
2
|
import { realpath, readFile, readdir } from 'node:fs/promises';
|
|
3
3
|
import { resolve, relative, isAbsolute, sep } from 'node:path';
|
|
4
4
|
import { migrationDirectory } from './portability-migrations.mjs';
|
|
5
|
+
import { ownerMigrationSources } from './portability-owners.mjs';
|
|
6
|
+
import { collectMigrations } from '../modules/delivery-producer/migrations.mjs';
|
|
5
7
|
import { splitStatements } from '../modules/portability/sql-text.mjs';
|
|
6
8
|
import { canonicalJson, sha256 } from '../modules/portability/hash.mjs';
|
|
7
9
|
import { quote, insist } from '../modules/portability/storage.mjs';
|
|
@@ -25,6 +27,12 @@ export async function generateMigrationEvidence(root,{binding='DB'}={}) {
|
|
|
25
27
|
const bytes=await readFile(file);
|
|
26
28
|
return {name,sha256:await sha256(bytes),statements:splitStatements(bytes.toString('utf8'))};
|
|
27
29
|
}));
|
|
30
|
+
const sources=await ownerMigrationSources(root,binding);
|
|
31
|
+
const owners=await collectMigrations(root,sources.filter(source=>source.directory).map(({directory,prefix})=>({binding,path:directory,prefix})),[{kind:'d1',binding}]);
|
|
32
|
+
for(const {name,sha256,sql} of owners) {
|
|
33
|
+
insist(!files.some(file=>file.name===name),'migration_ledger:ambiguous',409);
|
|
34
|
+
files.push({name,sha256,statements:splitStatements(sql)});
|
|
35
|
+
}
|
|
28
36
|
const objects=[],indices=new Map(),prefixes=[];
|
|
29
37
|
const scratch=new DatabaseSync(':memory:');
|
|
30
38
|
try {
|
|
@@ -64,7 +72,7 @@ export async function generateMigrationEvidence(root,{binding='DB'}={}) {
|
|
|
64
72
|
await capture();
|
|
65
73
|
}
|
|
66
74
|
}finally{scratch.close();}
|
|
67
|
-
return {version:1,files,objects,prefixes};
|
|
75
|
+
return {version:1,files,objects,prefixes,...(sources.length?{ownerSources:sources.map(({prefix,table})=>({prefix,table}))}:{})};
|
|
68
76
|
}
|
|
69
77
|
|
|
70
78
|
// Explicit seed opt-in. The module is consumed only by the server/Worker graph;
|
|
@@ -5,6 +5,8 @@ import { migrationStatements } from '../modules/portability/migration-sql.mjs';
|
|
|
5
5
|
import { destinationLedger, ledgerNames, matchMigrationLedger } from '../modules/portability/ledgers.mjs';
|
|
6
6
|
import { all, insist, PortabilityError } from '../modules/portability/storage.mjs';
|
|
7
7
|
import {migrationDirectory} from '../modules/deploy-kit/migration-directory.mjs';
|
|
8
|
+
import { collectMigrations } from '../modules/delivery-producer/migrations.mjs';
|
|
9
|
+
import { nativeMigrationHistory } from './portability-owners.mjs';
|
|
8
10
|
export {migrationDirectory};
|
|
9
11
|
|
|
10
12
|
// Seed-owned declarations, never archive metadata: the deploymentSpec prefix
|
|
@@ -19,18 +21,26 @@ export function platformMigrationDeclaration(input={}) {
|
|
|
19
21
|
|
|
20
22
|
// Reproduce the runner's stored SQL text, then recover SQLite's statement
|
|
21
23
|
// boundaries (migration-sql.mjs).
|
|
22
|
-
export async function migrationInventory(root,binding,{prefix},split) {
|
|
24
|
+
export async function migrationInventory(root,binding,{prefix},split,sources=[]) {
|
|
23
25
|
const directory=await migrationDirectory(root,binding);
|
|
24
|
-
|
|
26
|
+
const files=await Promise.all((await readdir(directory)).filter(name=>name.endsWith('.sql')).sort().map(async name=>{
|
|
25
27
|
const bytes=await readFile(join(directory,name));
|
|
26
28
|
return {name,...(split?{statements:migrationStatements(bytes.toString('utf8'),split)}:{}),sha256:createHash('sha256').update(bytes).digest('hex'),...(prefix===undefined?{}:{aliases:[prefix+name]})};
|
|
27
29
|
}));
|
|
30
|
+
if(sources.length) {
|
|
31
|
+
const owners=await collectMigrations(root,sources.filter(source=>source.directory).map(({directory,prefix})=>({binding,path:directory,prefix})),[{kind:'d1',binding}]);
|
|
32
|
+
for(const {name,sha256,sql} of owners) {
|
|
33
|
+
insist(!files.some(file=>file.name===name || file.aliases?.includes(name)),'migration_ledger:ambiguous',409);
|
|
34
|
+
files.push({name,sha256,...(split?{statements:migrationStatements(sql,split)}:{})});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return files;
|
|
28
38
|
}
|
|
29
39
|
|
|
30
40
|
// Preserve the runner's applied order, resolving file identities by hash.
|
|
31
|
-
export async function appliedMigrations(root,db,binding,declaration,split) {
|
|
32
|
-
const
|
|
33
|
-
return matchMigrationLedger(
|
|
41
|
+
export async function appliedMigrations(root,db,binding,declaration,split,sources=[]) {
|
|
42
|
+
const history=await nativeMigrationHistory(db,sources),files=await migrationInventory(root,binding,declaration,split,sources);
|
|
43
|
+
return matchMigrationLedger(history?.entries ?? [],files,declaration).map(name=>files.find(file=>file.name===name));
|
|
34
44
|
}
|
|
35
45
|
|
|
36
46
|
// Ledger contents can contain private values. Report constant categories,
|
|
@@ -87,17 +97,23 @@ async function legacyPairPreflight(db) {
|
|
|
87
97
|
// Adapter entry point, before *any* native Wrangler apply. The caller supplies
|
|
88
98
|
// the real target binding and keeps its writers stopped through apply/transfer.
|
|
89
99
|
// This only reads: it never repairs history or creates a second ledger.
|
|
90
|
-
export async function nativeMigrationPreflight({root,db,binding='DB',platformMigrations}) {
|
|
100
|
+
export async function nativeMigrationPreflight({root,db,binding='DB',platformMigrations,ownerSources=[]}) {
|
|
91
101
|
const declaration=platformMigrationDeclaration(platformMigrations);
|
|
92
102
|
const tables=await all(db,`SELECT type,name FROM sqlite_master WHERE lower(name) IN (${ledgerNames.map(name=>`'${name}'`).join(',')})`);
|
|
93
103
|
const legacyPair=tables.length===2 && ['_rer_deploy_migrations','d1_migrations'].every(name=>tables.some(row=>row.name===name));
|
|
94
104
|
if(tables.length>1 && !legacyPair)throw Object.assign(new PortabilityError('migration_ledger:multiple',409),tables.some(row=>row.name==='rer_migrations')?{identity:'rer_migrations'}:{});
|
|
95
105
|
insist(tables.every(row=>row.type==='table' && ledgerNames.includes(row.name)),'migration_ledger:incompatible',409);
|
|
96
106
|
const table=legacyPair?'_rer_deploy_migrations':tables[0]?.name;
|
|
97
|
-
if(!table)
|
|
107
|
+
if(!table) {
|
|
108
|
+
if(ownerSources.length) {
|
|
109
|
+
await nativeMigrationHistory(db,ownerSources);
|
|
110
|
+
await migrationInventory(root,binding,declaration,undefined,ownerSources);
|
|
111
|
+
}
|
|
112
|
+
return {nativeApply:true};
|
|
113
|
+
}
|
|
98
114
|
// This runner's history cannot authorize Wrangler to apply the same files.
|
|
99
115
|
insist(table!=='_rer_deploy_migrations' || legacyPair,'migration_ledger:runner',409);
|
|
100
|
-
const files=await migrationInventory(root,binding,declaration);
|
|
116
|
+
const files=await migrationInventory(root,binding,declaration,undefined,table==='rer_migrations'?ownerSources:[]);
|
|
101
117
|
let nativeApply=false;
|
|
102
118
|
try {
|
|
103
119
|
if(legacyPair)await legacyPairPreflight(db);
|
|
@@ -108,5 +124,11 @@ export async function nativeMigrationPreflight({root,db,binding='DB',platformMig
|
|
|
108
124
|
// The checkout file is named: it is the seed's own, never a ledger value.
|
|
109
125
|
if(table!=='d1_migrations')for(const file of files)if(!applied.includes(file.name))throw Object.assign(new PortabilityError('migration_ledger:unapplied',409),{migration:file.name});
|
|
110
126
|
} catch(error) { throw constantRefusal(error,files); }
|
|
127
|
+
if(ownerSources.length && table!=='rer_migrations') {
|
|
128
|
+
const history=await nativeMigrationHistory(db,ownerSources);
|
|
129
|
+
const allFiles=await migrationInventory(root,binding,declaration,undefined,ownerSources);
|
|
130
|
+
try { matchMigrationLedger(history.entries,allFiles,declaration); }
|
|
131
|
+
catch(error) { throw constantRefusal(error,allFiles); }
|
|
132
|
+
}
|
|
111
133
|
return {nativeApply};
|
|
112
134
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { readFile, readdir, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { sourcePath } from '../modules/delivery-producer/migrations.mjs';
|
|
5
|
+
import { ledgerNames } from '../modules/portability/ledgers.mjs';
|
|
6
|
+
import { insist } from '../modules/portability/storage.mjs';
|
|
7
|
+
import { deliveryDeclarationSources } from './delivery-declarations.mjs';
|
|
8
|
+
import { parseJsonc } from './jsonc.mjs';
|
|
9
|
+
export { nativeMigrationHistory, ownerMigrationPolicy } from '../modules/portability/owner-history.mjs';
|
|
10
|
+
|
|
11
|
+
// Delivery declares the extra directories and their prefixes. Native Wrangler
|
|
12
|
+
// uses the edition's permanent <project>_<prefix>_migrations ledger for each.
|
|
13
|
+
export async function ownerMigrationSources(root, binding) {
|
|
14
|
+
let directories;
|
|
15
|
+
for (const [path, select] of deliveryDeclarationSources) {
|
|
16
|
+
const file = await sourcePath(root, path, { optional: true });
|
|
17
|
+
if (!file) continue;
|
|
18
|
+
directories = select(JSON.parse(await readFile(file, 'utf8')))?.extraMigrationDirectories;
|
|
19
|
+
if (directories !== undefined) break;
|
|
20
|
+
}
|
|
21
|
+
directories ??= [];
|
|
22
|
+
insist(Array.isArray(directories), 'migration_ledger:incompatible', 409);
|
|
23
|
+
const sources = directories.filter(source => source.binding === binding);
|
|
24
|
+
if (!sources.length) return [];
|
|
25
|
+
const { name } = JSON.parse(await readFile(join(root, 'package.json'), 'utf8'));
|
|
26
|
+
const project = name?.split('/').at(-1).replaceAll('-', '_');
|
|
27
|
+
insist(typeof project === 'string' && /^[a-z][a-z0-9_]*$/.test(project), 'migration_ledger:incompatible', 409);
|
|
28
|
+
const selected = await Promise.all(sources.map(async ({ path, prefix, optional }) => {
|
|
29
|
+
insist(typeof prefix === 'string' && /^[a-z][a-z0-9_-]*-$/.test(prefix), 'migration_ledger:incompatible', 409);
|
|
30
|
+
const table = project + '_' + prefix.slice(0, -1).replaceAll('-', '_') + '_migrations';
|
|
31
|
+
insist(!ledgerNames.includes(table), 'migration_ledger:ambiguous', 409);
|
|
32
|
+
const directory = await sourcePath(root, path, { kind: 'directory', optional: optional === true });
|
|
33
|
+
return { directory, prefix, table };
|
|
34
|
+
}));
|
|
35
|
+
insist(new Set(selected.map(source => source.table)).size === selected.length, 'migration_ledger:ambiguous', 409);
|
|
36
|
+
return selected;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function applyNativeOwnerMigrations({ root, binding, sources, store, signal, env }) {
|
|
40
|
+
if (!sources.some(source => source.directory)) return;
|
|
41
|
+
const config = parseJsonc(await readFile(join(root, 'wrangler.jsonc'), 'utf8'));
|
|
42
|
+
const target = config.d1_databases.find(entry => entry.binding === binding);
|
|
43
|
+
for (const { table, directory } of sources) {
|
|
44
|
+
if (!directory || !(await readdir(directory)).some(name => name.endsWith('.sql'))) continue;
|
|
45
|
+
const path = join(root, '.wrangler', `rer-owner-migrations-${randomUUID()}.json`);
|
|
46
|
+
try {
|
|
47
|
+
await writeFile(path, JSON.stringify({
|
|
48
|
+
name: config.name, compatibility_date: config.compatibility_date,
|
|
49
|
+
d1_databases: [{ ...target, migrations_dir: directory, migrations_table: table }],
|
|
50
|
+
}), { mode: 0o600, flag: 'wx' });
|
|
51
|
+
await store.run('Applying local owner migrations', 'pnpm', ['exec', 'wrangler', 'd1', 'migrations', 'apply', binding, '--local', '--persist-to', '.wrangler/state', '--config', path], { cwd: root, signal, env });
|
|
52
|
+
} finally { await rm(path, { force: true }); }
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -16,6 +16,7 @@ import { nativeFailure, stateBytes } from './portability-progress.mjs';
|
|
|
16
16
|
import { parseJsonc } from './jsonc.mjs';
|
|
17
17
|
import { loadPolicy } from './portability-policy.mjs';
|
|
18
18
|
import { appliedMigrations, platformMigrationDeclaration, nativeMigrationPreflight } from './portability-migrations.mjs';
|
|
19
|
+
import { nativeMigrationHistory, ownerMigrationPolicy, ownerMigrationSources } from './portability-owners.mjs';
|
|
19
20
|
|
|
20
21
|
// Transfers read only the D1 database and R2 buckets. A configuration with just
|
|
21
22
|
// those keeps the app's other bindings out of the proxy: a Durable Object class
|
|
@@ -51,11 +52,18 @@ async function run(direction, { root, path, journal, binding, buckets, policy, p
|
|
|
51
52
|
let proxy;
|
|
52
53
|
try {
|
|
53
54
|
proxy = await getPlatformProxy({ configPath, persist: { path: join(root, '.wrangler/state/v3') }, remoteBindings: false });
|
|
54
|
-
|
|
55
|
-
const
|
|
55
|
+
const db = proxy.env[binding], owners = await ownerMigrationSources(root, binding);
|
|
56
|
+
const migrationHistory = () => nativeMigrationHistory(db, owners);
|
|
57
|
+
if(direction==='migration-preflight') {
|
|
58
|
+
const result=await nativeMigrationPreflight({root,db,binding,platformMigrations,ownerSources:owners});
|
|
59
|
+
if(!owners.length)return result;
|
|
60
|
+
const history=await migrationHistory();
|
|
61
|
+
return {...result, nativeOwners: !history || history.table==='d1_migrations'};
|
|
62
|
+
}
|
|
63
|
+
const migrations=async()=>migrationReplay(await appliedMigrations(root,db,binding,declaration,unstable_splitSqlQuery,owners),policy,declaration);
|
|
56
64
|
const boundBuckets = Object.fromEntries(Object.entries(buckets).map(([name, binding]) => [name, proxy.env[binding]]));
|
|
57
|
-
policy = await loadPolicy(root, inputPolicy, policyModule, { db
|
|
58
|
-
const options={ db
|
|
65
|
+
policy = ownerMigrationPolicy(await loadPolicy(root, inputPolicy, policyModule, { db, buckets: boundBuckets }), owners);
|
|
66
|
+
const options={ db, buckets: boundBuckets, policy, migrations, migrationHistory };
|
|
59
67
|
if(direction==='schema-recovery-preflight') { await requireProductEmpty(options);return {checkedEmpty:true}; }
|
|
60
68
|
if(direction==='legacy-preflight') {
|
|
61
69
|
await requireLegacyEmpty(options,await legacyTargetState(options.db,options.migrations));
|
|
@@ -83,7 +91,7 @@ catch (error) {
|
|
|
83
91
|
// Report symbolic codes and identities verified against the checkout or the
|
|
84
92
|
// known Platform ledger name; native database errors can contain private data.
|
|
85
93
|
const ledgerIdentity = error instanceof PortabilityError && error.code.startsWith('migration_ledger:') ? error.migration ?? error.identity : undefined;
|
|
86
|
-
const reason = error instanceof PortabilityError ? (error.code.startsWith('migration_ledger:') ? error.code + (ledgerIdentity ? ':' + ledgerIdentity : '') : error.code.split(':')[0]) : /^[A-Z_]+$/.test(error.code ?? '') ? error.code : error.message === 'archive_json' ? 'archive_json' : 'native_error';
|
|
94
|
+
const reason = error instanceof PortabilityError ? (error.code.startsWith('migration_ledger:') ? error.code + (ledgerIdentity ? ':' + ledgerIdentity : '') : error.code === 'schema_mismatch:owner_migration_history' ? error.code : error.code.split(':')[0]) : /^[A-Z_]+$/.test(error.code ?? '') ? error.code : error.message === 'archive_json' ? 'archive_json' : 'native_error';
|
|
87
95
|
// A later migration that changes restorable data is named: it is a file of this installation.
|
|
88
96
|
const migration = error instanceof PortabilityError && error.code.startsWith('schema_mismatch:migration_data:') ? error.code.slice('schema_mismatch:migration_data:'.length) : undefined;
|
|
89
97
|
// An unapplied migration is a file of this checkout: it is named so it can be applied.
|
package/cli/portability.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import { shared } from './shared.mjs';
|
|
|
10
10
|
import { emptyNativePreflight } from './portability-empty.mjs';
|
|
11
11
|
import { withManagedDataImport } from './managed-data.mjs';
|
|
12
12
|
import { ledgerRefusal } from './ledger-refusal.mjs';
|
|
13
|
+
import { applyNativeOwnerMigrations, ownerMigrationSources } from './portability-owners.mjs';
|
|
13
14
|
|
|
14
15
|
export { withManagedDataImport };
|
|
15
16
|
|
|
@@ -71,14 +72,14 @@ export function localPortability({ database, binding = 'DB', buckets = {}, polic
|
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
if(unverifiedSchemaRecovery)await nativeWorker(store,'schema-recovery-preflight',input,signal);
|
|
74
|
-
const {nativeApply}=await nativeWorker(store,'migration-preflight',input,signal);
|
|
75
|
+
const {nativeApply,nativeOwners}=await nativeWorker(store,'migration-preflight',input,signal);
|
|
75
76
|
// Local migrations need no provider account: wrangler runs without credentials.
|
|
76
77
|
// The shared runner shows its progress (a count every ten migrations) and leaves out its
|
|
77
78
|
// own info lines, which only confuse a local backup; warnings and errors print.
|
|
78
79
|
const { dependencyEnvironment } = await shared('dependency-environment.mjs');
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
});
|
|
80
|
+
const env = { ...dependencyEnvironment(), RER_LOCAL_OPERATION: operationToken, WRANGLER_SEND_METRICS: 'false' };
|
|
81
|
+
if(nativeApply)await store.run('Applying local data migrations', 'pnpm', ['exec', 'wrangler', 'd1', 'migrations', 'apply', database, '--local', '--persist-to', '.wrangler/state', '--config', 'wrangler.jsonc'], { cwd: root, signal, env });
|
|
82
|
+
if(direction==='import' && nativeOwners)await applyNativeOwnerMigrations({root,binding,sources:await ownerMigrationSources(root,binding),store,signal,env});
|
|
82
83
|
const receipt=await nativeWorker(store,direction,input,signal);
|
|
83
84
|
if(legacyRecovery)receipt.output=relative(root,legacyRecovery.output);
|
|
84
85
|
return { target: 'local', [direction === 'export' ? 'output' : 'input']: relative(root, path), ...receipt };
|
|
@@ -107,6 +108,7 @@ async function nativeWorker(store,direction,input,signal) {
|
|
|
107
108
|
: receipt.reExport ? `Restore refused (schema_mismatch): the schema definitions cannot be safely verified by this version. ${reExport}`
|
|
108
109
|
: receipt.identityTable ? `Transfer refused (identity_table_undeclared:${receipt.identityTable}): declare this table in includeTables to transfer its rows or excludeTables to omit them.`
|
|
109
110
|
: receipt.safety ? `Restore refused (${receipt.reason}): safety normalization for ${receipt.safety} violates the declared import policy.`
|
|
111
|
+
: receipt.reason === 'schema_mismatch:owner_migration_history' ? 'Restore refused (schema_mismatch:owner_migration_history): the recorded migration order or file contents differ from this checkout.'
|
|
110
112
|
: receipt.reason?.startsWith('migration_ledger:') ? ledgerRefusal(receipt)
|
|
111
113
|
: receipt.migration ? `Restore refused (schema_mismatch:migration_data): migration ${receipt.migration} changed data after this archive was made, so its rows would skip that change. Restore an archive made after it.`
|
|
112
114
|
: receipt.occupied ? occupiedRefusal(input,receipt.reason)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { shared } from './shared.mjs';
|
|
2
|
+
import { RerError } from './errors.mjs';
|
|
3
|
+
|
|
4
|
+
// `rer dev` serves modules on demand: the app's first document render loads its
|
|
5
|
+
// whole server module graph (router, route tree, server functions) one round trip
|
|
6
|
+
// at a time, which takes seconds on an idle computer and minutes on a busy one.
|
|
7
|
+
// The owner-entry check lands on first-run setup, a Worker response that renders
|
|
8
|
+
// no route, so on a fresh install that cost fell on the first signed-in page after
|
|
9
|
+
// the owner's first form post, and every signed-in request waited behind it until a
|
|
10
|
+
// restart (whose entry check lands on the signed-in app) had loaded the graph.
|
|
11
|
+
// Render one document through the app's own router here, before the server is
|
|
12
|
+
// announced ready. Any path no route claims reaches the router's not-found page.
|
|
13
|
+
export const WARMUP_PATH = '/rer-warmup';
|
|
14
|
+
const BUDGET_MS = 300000;
|
|
15
|
+
|
|
16
|
+
// Resolves once the app has answered the document, whatever its status: the page
|
|
17
|
+
// being rendered is the point, not the page. A request that never answers, or a
|
|
18
|
+
// server that dies meanwhile, refuses the launch instead of announcing a ready
|
|
19
|
+
// server whose pages hang.
|
|
20
|
+
export async function warmDocumentRender(url, probe, signal, store, budgetMs = BUDGET_MS) {
|
|
21
|
+
const { appFetch } = await shared('app-fetch.mjs');
|
|
22
|
+
store.report?.('Preparing the first page render; a first launch can take a few minutes on a busy computer.');
|
|
23
|
+
const timeout = AbortSignal.timeout(budgetMs);
|
|
24
|
+
try {
|
|
25
|
+
const response = await appFetch(new URL(WARMUP_PATH, url), { headers: { 'x-rer-probe': probe, accept: 'text/html' }, redirect: 'manual', signal: AbortSignal.any([signal, timeout].filter(Boolean)) });
|
|
26
|
+
await response.arrayBuffer();
|
|
27
|
+
} catch (error) {
|
|
28
|
+
signal?.throwIfAborted();
|
|
29
|
+
throw new RerError('first_render_failed', `The application did not render its first page ${timeout.aborted ? `within ${Math.round(budgetMs / 1000)} s` : 'before the server was announced ready'}. Check the application startup log, then run ~/.local/bin/rer dev again.`, 1, { cause: error });
|
|
30
|
+
}
|
|
31
|
+
}
|
package/cli/setup-input.mjs
CHANGED
|
@@ -72,16 +72,28 @@ export async function setupInput(project, options, vars, signal, { origin } = {}
|
|
|
72
72
|
const missingKeys=seed.model.setupModel(answers,known).missing;
|
|
73
73
|
const keys=[...new Set([...missingKeys,...invalidKeys])];
|
|
74
74
|
if(keys.length){
|
|
75
|
+
const mail=seed.model.fields.MAIL_PROVIDER;
|
|
76
|
+
let mailHelp='', omitMail=false;
|
|
77
|
+
if(invalidKeys.includes('MAIL_PROVIDER')&&mail?.options){
|
|
78
|
+
const {localOperatorMailProvider}=await shared('operator-settings.mjs');
|
|
79
|
+
if(answers.MAIL_PROVIDER===localOperatorMailProvider){
|
|
80
|
+
mailHelp=` The shared operator adapter requires MAIL_PROVIDER=${localOperatorMailProvider} for local startup. This checkout's setup manifest does not offer that value.`;
|
|
81
|
+
const implicitProvider=(installerAnswers??savedAnswers).MAIL_PROVIDER??adapterDefaults.MAIL_PROVIDER??defaults.MAIL_PROVIDER;
|
|
82
|
+
omitMail=!project.adapter.localPrerequisites&&mail.valid(implicitProvider);
|
|
83
|
+
if(omitMail)mailHelp+=" Omit MAIL_PROVIDER from the answers file to use this checkout's local setup settings.";
|
|
84
|
+
}
|
|
85
|
+
}
|
|
75
86
|
// Only declared metadata and example choices are public, never supplied values.
|
|
76
87
|
const shape={},details=keys.map(key=>{
|
|
77
88
|
const field=Object.hasOwn(seed.model.fields,key)?seed.model.fields[key]:undefined;
|
|
78
89
|
if(!field)return '(undeclared field)';
|
|
79
90
|
const privateValue=field.type==='password',choices=privateValue?undefined:field.options?.map(([value])=>value);
|
|
80
91
|
const type=privateValue?'secret':field.kind??(choices?'select':field.type??'text');
|
|
81
|
-
shape[key]=privateValue?'<private value>':choices?.[0]??'<value>';
|
|
92
|
+
if(key!=='MAIL_PROVIDER'||!omitMail)shape[key]=privateValue?'<private value>':choices?.[0]??'<value>';
|
|
82
93
|
return `${key} (${type}${choices?`; choices: ${choices.map(value=>JSON.stringify(value)).join(' | ')}`:''})`;
|
|
83
94
|
});
|
|
84
|
-
|
|
95
|
+
const fileHelp=omitMail&&!Object.keys(shape).length?'Keep the other answers in the owner-only JSON file (chmod 600 answers.json)':`Create an owner-only JSON file (chmod 600 answers.json) shaped ${JSON.stringify(shape)}`;
|
|
96
|
+
throw missing(`Missing or invalid active setup fields: ${details.join(', ')}.${mailHelp} ${fileHelp}, then run ~/.local/bin/rer setup --answers answers.json --non-interactive. --owner-email EMAIL and --owner-name NAME are also accepted when declared; use manifest field names inside the JSON, never an environment-file wrapper.`);
|
|
85
97
|
}
|
|
86
98
|
if(!mailbox(answers[names.email]))throw invalid('Provide a valid plain owner mailbox.');
|
|
87
99
|
answers[names.email]=answers[names.email].toLowerCase();
|
package/cli/site-private.mjs
CHANGED
|
@@ -10,7 +10,15 @@ const run = promisify(execFile);
|
|
|
10
10
|
export async function unpublishedIdentities(root, identities, privateFiles = []) {
|
|
11
11
|
identities = [...new Set(identities)].filter(value => typeof value === 'string' && value.length);
|
|
12
12
|
if (!identities.length) return [];
|
|
13
|
-
const git = args =>
|
|
13
|
+
const git = async args => {
|
|
14
|
+
try { return await run('git', args, {cwd:root, maxBuffer:32 * 1024 * 1024, encoding:'buffer'}); }
|
|
15
|
+
catch (error) {
|
|
16
|
+
// Synchronous native spawn errors (including Darwin's bad CPU type) omit
|
|
17
|
+
// path. Keep the actual error and name only the executable at this boundary.
|
|
18
|
+
if (/^spawn(?: |$)/.test(error.syscall ?? '') && !error.path) error.path = 'git';
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
14
22
|
let paths, prefix;
|
|
15
23
|
try {
|
|
16
24
|
prefix = (await git(['rev-parse', '--show-prefix'])).stdout.toString().trim();
|
package/cli/site.mjs
CHANGED
|
@@ -69,12 +69,12 @@ export async function buildSite(project, store, signal, { prepare = false, deplo
|
|
|
69
69
|
try { await store.run('Building the run site', process.execPath, [fileURLToPath(new URL('./site-render.mjs', import.meta.url)), project.root, site.entry, staging, site.config ?? '', JSON.stringify({entries:site.clients ?? {}, config:site.clientConfig, privatePaths:privateSitePaths(project.adapter), hosting, ...(site.runtime ? {runtime:site.runtime, corpus:`${staging}.corpus.json`} : {})})], { cwd: project.root, signal, heavy: false }); }
|
|
70
70
|
catch (error) {
|
|
71
71
|
const code = await readFile(`${staging}.refusal`, 'utf8').catch(() => '');
|
|
72
|
-
if (code === 'site_private_input') throw new RerError(code, 'Run site client imports a private installation file or a file outside the seed and its declared dependencies.', 4);
|
|
73
|
-
if (code === 'site_client_server_import') throw new RerError(code, 'Run site client imports a server-only module. Use browser dependencies in every reachable island module.', 4);
|
|
72
|
+
if (code === 'site_private_input') throw new RerError(code, 'Run site client imports a private installation file or a file outside the seed and its declared dependencies.', 4, {cause:error});
|
|
73
|
+
if (code === 'site_client_server_import') throw new RerError(code, 'Run site client imports a server-only module. Use browser dependencies in every reachable island module.', 4, {cause:error});
|
|
74
74
|
// Command capture appends its absolute log path after the child output.
|
|
75
75
|
const { approvedFailure, commandFailure } = await shared('failures.mjs');
|
|
76
76
|
const diagnostic = approvedFailure(error);
|
|
77
|
-
if (diagnostic) throw commandFailure(redactSiteText(diagnostic.message), diagnostic);
|
|
77
|
+
if (diagnostic) throw Object.assign(commandFailure(redactSiteText(diagnostic.message), diagnostic), {cause:error});
|
|
78
78
|
throw error;
|
|
79
79
|
}
|
|
80
80
|
const privacy = await privateValues(project);
|
|
@@ -83,7 +83,7 @@ export async function buildSite(project, store, signal, { prepare = false, deplo
|
|
|
83
83
|
let runtime;
|
|
84
84
|
if (site.runtime) {
|
|
85
85
|
try { runtime = await buildSiteRuntime(project, site.runtime, `${staging}.corpus.json`, staging, { prepare, domain:deployment?.domain, compatibilityDate:deployment?.compatibilityDate, store, signal }); }
|
|
86
|
-
catch (error) { if (error instanceof RerError) throw error; throw new RerError('site_search_failed', 'Docs search preparation failed; publication stopped. Check the previous artifact and Workers AI availability.', 1); }
|
|
86
|
+
catch (error) { if (error instanceof RerError) throw error; throw new RerError('site_search_failed', 'Docs search preparation failed; publication stopped. Check the previous artifact and Workers AI availability.', 1, {cause:error}); }
|
|
87
87
|
if (prepare) checked = await checkSite(staging, checkOptions);
|
|
88
88
|
const corpus = await contained(project.root, site.runtime.corpus, {optional:true});
|
|
89
89
|
await mkdir(dirname(corpus), {recursive:true});
|
|
@@ -159,7 +159,7 @@ export async function siteCommand(project, options, store, signal, out) {
|
|
|
159
159
|
const redaction = createRedaction();
|
|
160
160
|
redaction.addSecrets(names.map(name => process.env[name]));
|
|
161
161
|
const diagnostic = deployDiagnostic(error,redaction.redact), provider = providerFailure(error,redaction.redact);
|
|
162
|
-
throw new RerError('deploy_refused', redaction.redact(`Run site deploy stopped: ${/^[a-z0-9-]{1,80}$/.test(error.message) ? error.message : 'site-deploy-failed'}${error.resource ? ` (${error.resource})` : ''}.${provider ? ` ${provider}.` : ''}${siteReadbackSummary(error)}`), 1, {step:diagnostic?.step, ...(diagnostic ? {siteDeploy:diagnostic} : {})});
|
|
162
|
+
throw new RerError('deploy_refused', redaction.redact(`Run site deploy stopped: ${/^[a-z0-9-]{1,80}$/.test(error.message) ? error.message : 'site-deploy-failed'}${error.resource ? ` (${error.resource})` : ''}.${provider ? ` ${provider}.` : ''}${siteReadbackSummary(error)}`), 1, {cause:error, step:diagnostic?.step, ...(diagnostic ? {siteDeploy:diagnostic} : {})});
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
|
|
@@ -10,10 +10,13 @@ import {json, tracked, writeTree, fresh} from './files.mjs';
|
|
|
10
10
|
|
|
11
11
|
import {resolveSources} from './lock.mjs';
|
|
12
12
|
import {adoptEdition} from './adopt.mjs';
|
|
13
|
+
import {checkoutProjectHashProblems} from './project-hashes.mjs';
|
|
13
14
|
|
|
14
15
|
const root = process.cwd();
|
|
15
16
|
const resolve = (retain = false, diagnostics = false) => resolveSources(root, retain, diagnostics);
|
|
16
17
|
function check() {
|
|
18
|
+
const hashProblems = checkoutProjectHashProblems(root);
|
|
19
|
+
if (hashProblems.length) throw Error(hashProblems.join('\n'));
|
|
17
20
|
const expected = JSON.parse(fs.readFileSync(path.join(root, 'sources.lock.json'), 'utf8'));
|
|
18
21
|
const actual = resolve();
|
|
19
22
|
if (json(expected) !== json(actual)) throw Error('Stale lock or source/tool integrity mismatch; run changes to inspect intentional edits before lock');
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { hash, physicalEntry, safe } from './files.mjs';
|
|
3
|
+
|
|
4
|
+
export const projectManifest = 'rer-project.json';
|
|
5
|
+
|
|
6
|
+
export function projectHashProblems(bytes, readBytes) {
|
|
7
|
+
if (bytes === undefined) return [];
|
|
8
|
+
let project;
|
|
9
|
+
try { project = JSON.parse(bytes); }
|
|
10
|
+
catch { return [`Correct the invalid JSON in ${projectManifest}.`]; }
|
|
11
|
+
if (!project || typeof project !== 'object' || Array.isArray(project)) return [`Declare a JSON object in ${projectManifest}.`];
|
|
12
|
+
|
|
13
|
+
const problems = [], hashes = new Map();
|
|
14
|
+
const pending = [{ key: '', value: project }];
|
|
15
|
+
for (const { key, value } of pending) {
|
|
16
|
+
for (const [name, child] of Object.entries(value)) {
|
|
17
|
+
if (!child || typeof child !== 'object') continue;
|
|
18
|
+
const childKey = Array.isArray(value) ? `[${name}]`
|
|
19
|
+
: /^[a-zA-Z_$][\w$]*$/.test(name) ? `${key ? '.' : ''}${name}` : `[${JSON.stringify(name)}]`;
|
|
20
|
+
pending.push({ key: key + childKey, value: child });
|
|
21
|
+
}
|
|
22
|
+
if (!Object.hasOwn(value, 'path')) continue;
|
|
23
|
+
for (const field of ['sha256', 'digest']) {
|
|
24
|
+
if (!Object.hasOwn(value, field)) continue;
|
|
25
|
+
const declaringKey = `${projectManifest} ${key ? key + '.' : ''}${field}`;
|
|
26
|
+
const path = value.path, declared = value[field];
|
|
27
|
+
let actual;
|
|
28
|
+
try {
|
|
29
|
+
safe(path);
|
|
30
|
+
if (!hashes.has(path)) hashes.set(path, hash(readBytes(path)));
|
|
31
|
+
actual = hashes.get(path);
|
|
32
|
+
} catch {
|
|
33
|
+
problems.push(`${declaringKey} names ${JSON.stringify(path)}. Correct the path or restore the named file as a readable regular file in the project tree.`);
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const digest = typeof declared === 'string' && (field === 'digest' ? declared.replace(/^sha256:/i, '') : declared);
|
|
37
|
+
if (!digest || !/^[a-f0-9]{64}$/i.test(digest)) {
|
|
38
|
+
problems.push(`${declaringKey} for ${JSON.stringify(path)} must declare its SHA-256. File SHA-256 is ${actual}.`);
|
|
39
|
+
} else if (digest.toLowerCase() !== actual) {
|
|
40
|
+
problems.push(`${declaringKey} for ${JSON.stringify(path)} declares ${declared}. File SHA-256 is ${actual}. Update the declaration to match the file, or restore the file if you meant to roll it back.`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return problems;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function checkoutProjectHashProblems(root) {
|
|
48
|
+
const readBytes = (path, optional = false) => {
|
|
49
|
+
const entry = physicalEntry(root, path);
|
|
50
|
+
if (entry.absent && optional) return undefined;
|
|
51
|
+
if (!entry.target) throw Error('Expected a regular file in the checkout');
|
|
52
|
+
return readFileSync(entry.target);
|
|
53
|
+
};
|
|
54
|
+
let bytes;
|
|
55
|
+
try { bytes = readBytes(projectManifest, true); }
|
|
56
|
+
catch { return [`Restore ${projectManifest} as a readable regular file in the project tree.`]; }
|
|
57
|
+
return projectHashProblems(bytes, readBytes);
|
|
58
|
+
}
|
package/global/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,50 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.124
|
|
4
|
+
|
|
5
|
+
Signed: Run Edit Run fleet, 2026-11-19.
|
|
6
|
+
|
|
7
|
+
### Archive restore with owner migrations
|
|
8
|
+
|
|
9
|
+
- Local `rer import` predicts the archived schema by replaying the recorded core and owner migrations, including an owner migration that alters a core table. Native exports record the combined applied history with file hashes and omit owner migration bookkeeping tables from product data. Worker migration evidence and the shared restore path also include declared owner migrations, covering the Spool restore adapter when core migrations precede owner migrations.
|
|
10
|
+
- Changed, missing, reordered or archive-extra owner migrations refuse with `schema_mismatch:owner_migration_history` before importing product rows. Later additive migrations in the destination remain supported by the additive-restore contract.
|
|
11
|
+
- The portability adoption list now includes `owner-history.mjs`. Maintained CLI copies and inventory are regenerated.
|
|
12
|
+
|
|
13
|
+
Archives written by this version for a seed WITH owner migrations carry a combined migration ledger and are not readable by rer 0.2.123 or older: those readers refuse `manifest_inventory`. Core-only and legacy archives are unchanged both ways. The archive format remains `runeditrun-portability` version 2; the existing optional migration ledger now accepts the native `d1_migrations` origin.
|
|
14
|
+
|
|
15
|
+
KNOWN LIMIT: a Worker restore replays core files before owner files. An owner who applied an ALTER and later installed a core upgrade can have a matching archive refused (HTTP 409, zero rows, nothing published). A follow-up fixes the applied-order replay.
|
|
16
|
+
|
|
17
|
+
ChargeDesk checkouts pin rer 0.2.118 and other seeds have older pins, and need a re-pin to receive this fix.
|
|
18
|
+
|
|
19
|
+
These changes require adoption through the seed's pinned package or refreshed source. This preparation establishes no seed adoption, live Spool deployment, provider delivery or production result. The source range changes portability and its maintained copies, with no import-kit or product migration change.
|
|
20
|
+
|
|
21
|
+
## 0.2.123
|
|
22
|
+
|
|
23
|
+
Signed: Run Edit Run fleet, 2026-11-18.
|
|
24
|
+
|
|
25
|
+
### Declared project file hashes
|
|
26
|
+
|
|
27
|
+
- `rer release` checks every object in `rer-project.json` that declares a `path` and a `sha256` or `digest` against the raw file bytes at the selected commit, before staging output or tags. Missing, unreadable or unsafe paths and malformed or mismatched hashes are refused with correction guidance. `rer verify`, `rer check` and the edition source check apply the same check to checkout files.
|
|
28
|
+
- Release producers must update a declared setup hash to match the file, or restore the intended file. Lamp v1.11.22 and Oncall v0.5.18 are cases this check refuses because their declared setup hashes differ from the files.
|
|
29
|
+
|
|
30
|
+
### Local startup and persona links
|
|
31
|
+
|
|
32
|
+
- Before announcing ready, `rer dev` requests an unmatched document through the app's router and waits for the response body, loading the server module graph before the owner's first signed-in page. Any HTTP status completes this warmup; five minutes without an answer refuses startup with `first_render_failed`. The owner-entry readiness check still follows it.
|
|
33
|
+
- Explicit `rer dev --as PERSONA` links carry a 15-minute grant signed with the checkout's key and bound to the origin and selected account. Exchange admits only the resulting dev session; persona switching and dev-minted credentials still require the checkout-wide gate. Reset invalidates local entry.
|
|
34
|
+
- Native lifecycle and synchronous spawn causes survive command capture and adapter wrappers. Diagnostics name the executable basename and classified OS failure, retaining a written capture-log path without exposing native arguments or private application data. Captured dev-key checks compare the used key with the saved private key.
|
|
35
|
+
- Failed command admission releases its policy sockets, process identity and log resources. After cleanup, an unexpected failure in the executable CLI allows pending output to drain but bounds lingering handles to three seconds; callers passing their own arguments receive a status without that process-lifetime change.
|
|
36
|
+
- Local setup explains when the shared operator requires `MAIL_PROVIDER=development` but the checkout's manifest does not offer it. Where the checkout's own valid local settings permit it, guidance says to omit that field from the answers file; other required fields retain their declared choices.
|
|
37
|
+
|
|
38
|
+
### Business refusals, removal and CI isolation
|
|
39
|
+
|
|
40
|
+
- Business API, pairing, grant, agent and MCP refusals retain bounded, redacted server prose, including failed change/update reasons, while withholding secret-bearing envelope fields and reflected credential values.
|
|
41
|
+
- Deployment removal reports resources as removed only after independent absence read-back. A surviving or unverified Worker retains its data; incomplete removal keeps the deployment record and names remaining or unverified resources for recovery.
|
|
42
|
+
- Verify planner fixtures isolate their GitHub job environment, and site-search fixtures prepare real pnpm before intercepting provider traffic. Maintained CLI and onboarding copies and inventories are regenerated.
|
|
43
|
+
|
|
44
|
+
ChargeDesk checkouts pin rer 0.2.118 and other seeds have older pins, and need a re-pin to receive these fixes.
|
|
45
|
+
|
|
46
|
+
These changes require adoption through the seed's pinned package or refreshed source. This preparation establishes no seed adoption, provider delivery, deployment or production result. The source range changes no portability or import-kit module, product migration or archive format identity.
|
|
47
|
+
|
|
3
48
|
## 0.2.122
|
|
4
49
|
|
|
5
50
|
Signed: Run Edit Run fleet, 2026-11-17.
|
package/global/launch/dev.mjs
CHANGED
|
@@ -16,7 +16,7 @@ import { delegate } from '../delegate.mjs';
|
|
|
16
16
|
import { ownRoot } from '../package-info.mjs';
|
|
17
17
|
import { LaunchFailure } from './failure.mjs';
|
|
18
18
|
import { describeCheckout } from './facts.mjs';
|
|
19
|
-
import { prepare } from './prepare.mjs';
|
|
19
|
+
import { flagValue, prepare } from './prepare.mjs';
|
|
20
20
|
import { printer } from './render.mjs';
|
|
21
21
|
import { access } from 'node:fs/promises';
|
|
22
22
|
import { layout } from '../cli/layout.mjs';
|
|
@@ -98,7 +98,7 @@ async function foreground(target, devArgs, directory, out, doorStart) {
|
|
|
98
98
|
async function detached(target, devArgs, directory, out, doorStart) {
|
|
99
99
|
let token, worker;
|
|
100
100
|
const holder = await liveWorker(directory);
|
|
101
|
-
if (holder) { token = holder.token; out.attaching(holder.startedAt); }
|
|
101
|
+
if (holder && holder.persona === flagValue(devArgs, '--as')) { token = holder.token; out.attaching(holder.startedAt); }
|
|
102
102
|
else {
|
|
103
103
|
token = randomUUID();
|
|
104
104
|
// The worker ends itself for a stop that ran after this command started.
|