@evomap/evolver-proxy 2.0.48 → 2.0.50
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/dist/bin/evolver-proxy.js +86 -50
- package/dist/daemon/backgroundCuration.d.ts +54 -0
- package/dist/daemon/backgroundCuration.js +159 -0
- package/dist/daemon/curationGit.d.ts +5 -0
- package/dist/daemon/curationGit.js +140 -0
- package/dist/daemon/distillMeasures.d.ts +59 -0
- package/dist/daemon/distillMeasures.js +139 -0
- package/dist/daemon/localRecall.d.ts +6 -1
- package/dist/daemon/localRecall.js +59 -6
- package/dist/daemon/observedEvidence.d.ts +43 -0
- package/dist/daemon/observedEvidence.js +116 -0
- package/dist/daemon/proxyDaemon.d.ts +19 -0
- package/dist/daemon/proxyDaemon.js +179 -30
- package/dist/daemon/recallContext.js +2 -1
- package/dist/lifecycle/claimNudge.js +1 -1
- package/dist/lifecycle/deployGuard.js +1 -1
- package/dist/lifecycle/legacyNodeId.js +1 -1
- package/dist/lifecycle/manager.js +1 -1
- package/dist/llm/index.js +1 -1
- package/dist/llm/server.js +1 -1
- package/dist/llm/traceBackfill.js +1 -1
- package/dist/llm/traceConfig.js +1 -1
- package/dist/llm/traceControl.js +1 -1
- package/dist/llm/traceEnvelope.js +1 -1
- package/dist/llm/traceSink.js +1 -1
- package/dist/llm/traceUploadPayload.js +1 -1
- package/dist/llm/upstream.js +1 -1
- package/dist/router/cachePassthrough.js +1 -1
- package/dist/router/features.js +1 -1
- package/dist/router/index.js +1 -1
- package/dist/router/messagesRoute.js +1 -1
- package/dist/router/modelRouter.js +1 -1
- package/dist/router/providerRoutes.js +1 -1
- package/dist/router/sseScan.js +1 -1
- package/dist/selfUpdate/bootstrap.js +40 -46
- package/dist/selfUpdate/bootstrapReadiness.js +15 -3
- package/dist/selfUpdate/migration.js +37 -22
- package/dist/selfUpdate/transaction.js +158 -59
- package/dist/selfUpdate/windowsUpdater.js +70 -10
- package/dist/sync/engine.js +1 -1
- package/package.json +3 -3
|
@@ -19,7 +19,7 @@ import { closeSync, constants, existsSync, fstatSync, fsyncSync, linkSync, lstat
|
|
|
19
19
|
import { homedir } from 'node:os';
|
|
20
20
|
import { basename, dirname, join, parse as parsePath, posix, resolve as resolvePath, win32, } from 'node:path';
|
|
21
21
|
import { fileURLToPath } from 'node:url';
|
|
22
|
-
import { bootstrap as coreBootstrap, util } from '@evomap/evolver-core';
|
|
22
|
+
import { assetstore, bootstrap as coreBootstrap, util } from '@evomap/evolver-core';
|
|
23
23
|
import { isSelfUpdateExplicit, resolveSelfUpdatePolicy, selfUpdateSupervisorAttested, } from './policy.js';
|
|
24
24
|
import { isStandaloneReleaseBinaryName, resolveSelfUpdateTarget, } from './releaseBinary.js';
|
|
25
25
|
import { expandHomePath, parseEnvFile } from '../bin/envFile.js';
|
|
@@ -146,12 +146,6 @@ function boundedBootstrapDetail(value) {
|
|
|
146
146
|
}
|
|
147
147
|
return normalized.slice(0, MAX_BOOTSTRAP_DETAIL_LENGTH);
|
|
148
148
|
}
|
|
149
|
-
function bootstrapPathMetadata(path) {
|
|
150
|
-
const stat = lstatSync(path, { bigint: true });
|
|
151
|
-
// Reuse the native file witness; a missing Windows volume is not an identity.
|
|
152
|
-
return process.platform === 'win32' && stat.dev === 0n && stat.isFile() && !stat.isSymbolicLink()
|
|
153
|
-
? util.statRegularFileIdentity(path) : stat;
|
|
154
|
-
}
|
|
155
149
|
function readBoundedBootstrapStateFile(path, options, maxBytes = MAX_BOOTSTRAP_STATE_BYTES) {
|
|
156
150
|
const injected = options.exists !== undefined || options.readFile !== undefined;
|
|
157
151
|
try {
|
|
@@ -164,7 +158,7 @@ function readBoundedBootstrapStateFile(path, options, maxBytes = MAX_BOOTSTRAP_S
|
|
|
164
158
|
}
|
|
165
159
|
return { status: 'present', raw };
|
|
166
160
|
}
|
|
167
|
-
const before =
|
|
161
|
+
const before = assetstore.lstatWithAssetFileIdentity(path);
|
|
168
162
|
if (!before.isFile() || before.isSymbolicLink() || before.nlink !== 1n
|
|
169
163
|
|| before.size > BigInt(maxBytes)
|
|
170
164
|
|| before.dev <= 0n || before.ino <= 0n) {
|
|
@@ -174,7 +168,7 @@ function readBoundedBootstrapStateFile(path, options, maxBytes = MAX_BOOTSTRAP_S
|
|
|
174
168
|
const descriptor = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
175
169
|
try {
|
|
176
170
|
const opened = fstatSync(descriptor, { bigint: true });
|
|
177
|
-
if (!opened.isFile() || opened.dev !== before.dev || opened.ino !== before.ino
|
|
171
|
+
if (!opened.isFile() || opened.dev !== before.dev || opened.ino !== before.ino || opened.birthtimeNs !== before.birthtimeNs
|
|
178
172
|
|| opened.size !== before.size) {
|
|
179
173
|
return { status: 'invalid', detail: `changed durable state: ${basename(path)}` };
|
|
180
174
|
}
|
|
@@ -191,14 +185,14 @@ function readBoundedBootstrapStateFile(path, options, maxBytes = MAX_BOOTSTRAP_S
|
|
|
191
185
|
}
|
|
192
186
|
const raw = bytes.subarray(0, offset).toString('utf8');
|
|
193
187
|
const after = fstatSync(descriptor, { bigint: true });
|
|
194
|
-
if (after.dev !== opened.dev || after.ino !== opened.ino || after.size !== opened.size
|
|
188
|
+
if (after.dev !== opened.dev || after.ino !== opened.ino || after.birthtimeNs !== opened.birthtimeNs || after.size !== opened.size
|
|
195
189
|
|| after.mtimeNs !== opened.mtimeNs || after.ctimeNs !== opened.ctimeNs) {
|
|
196
190
|
return { status: 'invalid', detail: `changed durable state: ${basename(path)}` };
|
|
197
191
|
}
|
|
198
192
|
(options.assertIntentFileTrust ?? assertNativeBootstrapIntentFileTrust)(path);
|
|
199
|
-
const settled =
|
|
193
|
+
const settled = assetstore.lstatWithAssetFileIdentity(path);
|
|
200
194
|
if (!settled.isFile() || settled.isSymbolicLink() || settled.nlink !== 1n
|
|
201
|
-
|| settled.dev !== opened.dev || settled.ino !== opened.ino || settled.size !== opened.size
|
|
195
|
+
|| settled.dev !== opened.dev || settled.ino !== opened.ino || settled.birthtimeNs !== opened.birthtimeNs || settled.size !== opened.size
|
|
202
196
|
|| settled.mtimeNs !== opened.mtimeNs || settled.ctimeNs !== opened.ctimeNs) {
|
|
203
197
|
return { status: 'invalid', detail: `changed durable state: ${basename(path)}` };
|
|
204
198
|
}
|
|
@@ -274,7 +268,7 @@ function readLegacyBootstrapProofFile(receipt, options) {
|
|
|
274
268
|
const directory = dirname(receipt.path);
|
|
275
269
|
assertDirectoryTrust(directory);
|
|
276
270
|
assertFileTrust(receipt.path);
|
|
277
|
-
const before =
|
|
271
|
+
const before = assetstore.lstatWithAssetFileIdentity(receipt.path);
|
|
278
272
|
if (!before.isFile() || before.isSymbolicLink()
|
|
279
273
|
|| before.dev <= 0n || before.ino <= 0n
|
|
280
274
|
|| before.size !== BigInt(receipt.size)
|
|
@@ -286,7 +280,7 @@ function readLegacyBootstrapProofFile(receipt, options) {
|
|
|
286
280
|
try {
|
|
287
281
|
const opened = fstatSync(descriptor, { bigint: true });
|
|
288
282
|
if (!opened.isFile()
|
|
289
|
-
|| opened.dev !== before.dev || opened.ino !== before.ino
|
|
283
|
+
|| opened.dev !== before.dev || opened.ino !== before.ino || opened.birthtimeNs !== before.birthtimeNs
|
|
290
284
|
|| opened.size !== before.size
|
|
291
285
|
|| opened.mtimeNs !== before.mtimeNs || opened.ctimeNs !== before.ctimeNs) {
|
|
292
286
|
throw new Error('legacy bootstrap proof changed while opening');
|
|
@@ -309,16 +303,16 @@ function readLegacyBootstrapProofFile(receipt, options) {
|
|
|
309
303
|
if (!first.equals(second)
|
|
310
304
|
|| first.length !== receipt.size
|
|
311
305
|
|| createHash('sha256').update(first).digest('hex') !== receipt.sha256
|
|
312
|
-
|| after.dev !== opened.dev || after.ino !== opened.ino
|
|
306
|
+
|| after.dev !== opened.dev || after.ino !== opened.ino || after.birthtimeNs !== opened.birthtimeNs
|
|
313
307
|
|| after.size !== opened.size
|
|
314
308
|
|| after.mtimeNs !== opened.mtimeNs || after.ctimeNs !== opened.ctimeNs) {
|
|
315
309
|
throw new Error('legacy bootstrap proof changed while reading');
|
|
316
310
|
}
|
|
317
311
|
assertDirectoryTrust(directory);
|
|
318
312
|
assertFileTrust(receipt.path);
|
|
319
|
-
const settled =
|
|
313
|
+
const settled = assetstore.lstatWithAssetFileIdentity(receipt.path);
|
|
320
314
|
if (!settled.isFile() || settled.isSymbolicLink()
|
|
321
|
-
|| settled.dev !== opened.dev || settled.ino !== opened.ino
|
|
315
|
+
|| settled.dev !== opened.dev || settled.ino !== opened.ino || settled.birthtimeNs !== opened.birthtimeNs
|
|
322
316
|
|| settled.size !== opened.size
|
|
323
317
|
|| settled.mtimeNs !== opened.mtimeNs || settled.ctimeNs !== opened.ctimeNs) {
|
|
324
318
|
throw new Error('legacy bootstrap proof path changed while reading');
|
|
@@ -2043,7 +2037,7 @@ function syncBootstrapDirectory(path) {
|
|
|
2043
2037
|
function readBootstrapRegistrationIntentFile(options, path, registrationPath, terminalPath, clearingPath, expectedLinkCount = 1n) {
|
|
2044
2038
|
try {
|
|
2045
2039
|
assertBootstrapIntentFileTrust(options, path, Number(expectedLinkCount));
|
|
2046
|
-
const before =
|
|
2040
|
+
const before = assetstore.lstatWithAssetFileIdentity(path);
|
|
2047
2041
|
if (!before.isFile() || before.isSymbolicLink() || before.nlink !== expectedLinkCount
|
|
2048
2042
|
|| before.dev <= 0n || before.ino <= 0n
|
|
2049
2043
|
|| before.size > BigInt(MAX_BOOTSTRAP_REGISTRATION_INTENT_BYTES)
|
|
@@ -2064,7 +2058,7 @@ function readBootstrapRegistrationIntentFile(options, path, registrationPath, te
|
|
|
2064
2058
|
try {
|
|
2065
2059
|
const opened = fstatSync(descriptor, { bigint: true });
|
|
2066
2060
|
if (!opened.isFile() || opened.nlink !== expectedLinkCount
|
|
2067
|
-
|| opened.dev !== before.dev || opened.ino !== before.ino || opened.size !== before.size) {
|
|
2061
|
+
|| opened.dev !== before.dev || opened.ino !== before.ino || opened.birthtimeNs !== before.birthtimeNs || opened.size !== before.size) {
|
|
2068
2062
|
return { status: 'invalid', detail: 'registration intent changed before read' };
|
|
2069
2063
|
}
|
|
2070
2064
|
const bytes = Buffer.alloc(MAX_BOOTSTRAP_REGISTRATION_INTENT_BYTES + 1);
|
|
@@ -2080,7 +2074,7 @@ function readBootstrapRegistrationIntentFile(options, path, registrationPath, te
|
|
|
2080
2074
|
}
|
|
2081
2075
|
raw = bytes.subarray(0, offset).toString('utf8');
|
|
2082
2076
|
const settled = fstatSync(descriptor, { bigint: true });
|
|
2083
|
-
if (settled.dev !== opened.dev || settled.ino !== opened.ino
|
|
2077
|
+
if (settled.dev !== opened.dev || settled.ino !== opened.ino || settled.birthtimeNs !== opened.birthtimeNs
|
|
2084
2078
|
|| settled.size !== opened.size || settled.mtimeNs !== opened.mtimeNs
|
|
2085
2079
|
|| settled.ctimeNs !== opened.ctimeNs) {
|
|
2086
2080
|
return { status: 'invalid', detail: 'registration intent changed during read' };
|
|
@@ -2089,9 +2083,9 @@ function readBootstrapRegistrationIntentFile(options, path, registrationPath, te
|
|
|
2089
2083
|
finally {
|
|
2090
2084
|
closeSync(descriptor);
|
|
2091
2085
|
}
|
|
2092
|
-
const after =
|
|
2086
|
+
const after = assetstore.lstatWithAssetFileIdentity(path);
|
|
2093
2087
|
if (!after.isFile() || after.isSymbolicLink() || after.nlink !== expectedLinkCount
|
|
2094
|
-
|| after.dev !== before.dev || after.ino !== before.ino || after.size !== before.size
|
|
2088
|
+
|| after.dev !== before.dev || after.ino !== before.ino || after.birthtimeNs !== before.birthtimeNs || after.size !== before.size
|
|
2095
2089
|
|| after.mtimeNs !== before.mtimeNs || after.ctimeNs !== before.ctimeNs) {
|
|
2096
2090
|
return { status: 'invalid', detail: 'registration intent changed after read' };
|
|
2097
2091
|
}
|
|
@@ -2179,7 +2173,7 @@ function readBootstrapRegistrationPublisherClaim(options, stateDir) {
|
|
|
2179
2173
|
const path = join(stateDir, name);
|
|
2180
2174
|
try {
|
|
2181
2175
|
assertBootstrapIntentFileTrust(options, path);
|
|
2182
|
-
const before =
|
|
2176
|
+
const before = assetstore.lstatWithAssetFileIdentity(path);
|
|
2183
2177
|
if (!before.isFile() || before.isSymbolicLink() || before.nlink !== 1n
|
|
2184
2178
|
|| before.size !== 0n || before.dev <= 0n || before.ino <= 0n) {
|
|
2185
2179
|
return { status: 'invalid', detail: 'registration publisher claim is unsafe' };
|
|
@@ -2189,7 +2183,7 @@ function readBootstrapRegistrationPublisherClaim(options, stateDir) {
|
|
|
2189
2183
|
descriptor = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
2190
2184
|
const opened = fstatSync(descriptor, { bigint: true });
|
|
2191
2185
|
if (!opened.isFile() || opened.nlink !== 1n || opened.size !== 0n
|
|
2192
|
-
|| opened.dev !== before.dev || opened.ino !== before.ino
|
|
2186
|
+
|| opened.dev !== before.dev || opened.ino !== before.ino || opened.birthtimeNs !== before.birthtimeNs
|
|
2193
2187
|
|| opened.mtimeNs !== before.mtimeNs || opened.ctimeNs !== before.ctimeNs) {
|
|
2194
2188
|
return { status: 'invalid', detail: 'registration publisher claim changed before read' };
|
|
2195
2189
|
}
|
|
@@ -2198,9 +2192,9 @@ function readBootstrapRegistrationPublisherClaim(options, stateDir) {
|
|
|
2198
2192
|
if (descriptor !== undefined)
|
|
2199
2193
|
closeSync(descriptor);
|
|
2200
2194
|
}
|
|
2201
|
-
const after =
|
|
2195
|
+
const after = assetstore.lstatWithAssetFileIdentity(path);
|
|
2202
2196
|
if (!after.isFile() || after.isSymbolicLink() || after.nlink !== 1n || after.size !== 0n
|
|
2203
|
-
|| after.dev !== before.dev || after.ino !== before.ino
|
|
2197
|
+
|| after.dev !== before.dev || after.ino !== before.ino || after.birthtimeNs !== before.birthtimeNs
|
|
2204
2198
|
|| after.mtimeNs !== before.mtimeNs || after.ctimeNs !== before.ctimeNs) {
|
|
2205
2199
|
return { status: 'invalid', detail: 'registration publisher claim changed after read' };
|
|
2206
2200
|
}
|
|
@@ -2472,9 +2466,9 @@ function createBootstrapRegistrationPublisherClaim(options, stateDir, owner) {
|
|
|
2472
2466
|
throw new Error('bootstrap registration publisher claim failed');
|
|
2473
2467
|
syncBootstrapDirectory(stateDir);
|
|
2474
2468
|
assertBootstrapIntentFileTrust(options, path);
|
|
2475
|
-
const settled =
|
|
2469
|
+
const settled = assetstore.lstatWithAssetFileIdentity(path, 'write');
|
|
2476
2470
|
if (!settled.isFile() || settled.isSymbolicLink() || settled.nlink !== 1n
|
|
2477
|
-
|| settled.size !== 0n || settled.dev !== opened.dev || settled.ino !== opened.ino
|
|
2471
|
+
|| settled.size !== 0n || settled.dev !== opened.dev || settled.ino !== opened.ino || settled.birthtimeNs !== opened.birthtimeNs
|
|
2478
2472
|
|| settled.mtimeNs !== opened.mtimeNs || settled.ctimeNs !== opened.ctimeNs) {
|
|
2479
2473
|
throw new Error('bootstrap registration publisher claim is unconfirmed');
|
|
2480
2474
|
}
|
|
@@ -2574,9 +2568,9 @@ function publishBootstrapRegistrationIntent(options) {
|
|
|
2574
2568
|
if (!opened)
|
|
2575
2569
|
throw new Error('bootstrap registration intent publication failed');
|
|
2576
2570
|
assertBootstrapIntentFileTrust(options, publishingPath);
|
|
2577
|
-
const prepared =
|
|
2571
|
+
const prepared = assetstore.lstatWithAssetFileIdentity(publishingPath, 'write');
|
|
2578
2572
|
if (!prepared.isFile() || prepared.isSymbolicLink() || prepared.nlink !== 1n
|
|
2579
|
-
|| prepared.dev !== opened.dev || prepared.ino !== opened.ino
|
|
2573
|
+
|| prepared.dev !== opened.dev || prepared.ino !== opened.ino || prepared.birthtimeNs !== opened.birthtimeNs
|
|
2580
2574
|
|| prepared.size !== opened.size || prepared.mtimeNs !== opened.mtimeNs
|
|
2581
2575
|
|| prepared.ctimeNs !== opened.ctimeNs) {
|
|
2582
2576
|
throw new Error('bootstrap registration intent temp changed before publication');
|
|
@@ -2587,13 +2581,13 @@ function publishBootstrapRegistrationIntent(options) {
|
|
|
2587
2581
|
options.afterIntentPublicationStep?.('directory_fsync', stateDir);
|
|
2588
2582
|
assertBootstrapIntentFileTrust(options, publishingPath, 2);
|
|
2589
2583
|
assertBootstrapIntentFileTrust(options, path, 2);
|
|
2590
|
-
const linkedTemp =
|
|
2591
|
-
const linkedCanonical =
|
|
2584
|
+
const linkedTemp = assetstore.lstatWithAssetFileIdentity(publishingPath, 'write');
|
|
2585
|
+
const linkedCanonical = assetstore.lstatWithAssetFileIdentity(path, 'write');
|
|
2592
2586
|
if (!linkedTemp.isFile() || linkedTemp.isSymbolicLink() || linkedTemp.nlink !== 2n
|
|
2593
2587
|
|| !linkedCanonical.isFile() || linkedCanonical.isSymbolicLink()
|
|
2594
2588
|
|| linkedCanonical.nlink !== 2n
|
|
2595
|
-
|| linkedTemp.dev !== opened.dev || linkedTemp.ino !== opened.ino
|
|
2596
|
-
|| linkedCanonical.dev !== opened.dev || linkedCanonical.ino !== opened.ino
|
|
2589
|
+
|| linkedTemp.dev !== opened.dev || linkedTemp.ino !== opened.ino || linkedTemp.birthtimeNs !== opened.birthtimeNs
|
|
2590
|
+
|| linkedCanonical.dev !== opened.dev || linkedCanonical.ino !== opened.ino || linkedCanonical.birthtimeNs !== opened.birthtimeNs
|
|
2597
2591
|
|| linkedTemp.size !== opened.size || linkedCanonical.size !== opened.size
|
|
2598
2592
|
|| linkedTemp.mtimeNs !== opened.mtimeNs || linkedCanonical.mtimeNs !== opened.mtimeNs) {
|
|
2599
2593
|
throw new Error('bootstrap registration intent canonical claim is unconfirmed');
|
|
@@ -2604,9 +2598,9 @@ function publishBootstrapRegistrationIntent(options) {
|
|
|
2604
2598
|
throw new Error('bootstrap registration intent temp retirement is unconfirmed');
|
|
2605
2599
|
}
|
|
2606
2600
|
assertBootstrapIntentFileTrust(options, path);
|
|
2607
|
-
const published =
|
|
2601
|
+
const published = assetstore.lstatWithAssetFileIdentity(path, 'write');
|
|
2608
2602
|
if (!published.isFile() || published.isSymbolicLink() || published.nlink !== 1n
|
|
2609
|
-
|| published.dev !== opened.dev || published.ino !== opened.ino
|
|
2603
|
+
|| published.dev !== opened.dev || published.ino !== opened.ino || published.birthtimeNs !== opened.birthtimeNs
|
|
2610
2604
|
|| published.size !== opened.size || published.mtimeNs !== opened.mtimeNs) {
|
|
2611
2605
|
throw new Error('bootstrap registration intent changed during publication');
|
|
2612
2606
|
}
|
|
@@ -2640,7 +2634,7 @@ function terminalizeBootstrapRegistrationIntent(options, lease, outcome, transac
|
|
|
2640
2634
|
}
|
|
2641
2635
|
assertBootstrapIntentDirectoryTrust(options, dirname(lease.currentPath), true);
|
|
2642
2636
|
assertBootstrapIntentFileTrust(options, lease.currentPath);
|
|
2643
|
-
const current =
|
|
2637
|
+
const current = assetstore.lstatWithAssetFileIdentity(lease.currentPath);
|
|
2644
2638
|
if (!current.isFile() || current.isSymbolicLink() || current.nlink !== 1n
|
|
2645
2639
|
|| current.dev !== lease.device || current.ino !== lease.inode || current.size !== lease.size
|
|
2646
2640
|
|| current.mtimeNs !== lease.mtimeNs || current.ctimeNs !== lease.ctimeNs) {
|
|
@@ -2694,7 +2688,7 @@ function terminalizeBootstrapRegistrationIntent(options, lease, outcome, transac
|
|
|
2694
2688
|
if (!settled)
|
|
2695
2689
|
throw new Error('bootstrap registration intent terminal publication failed');
|
|
2696
2690
|
assertBootstrapIntentFileTrust(options, lease.terminalPath);
|
|
2697
|
-
const after =
|
|
2691
|
+
const after = assetstore.lstatWithAssetFileIdentity(lease.terminalPath, 'write');
|
|
2698
2692
|
if (!after.isFile() || after.isSymbolicLink() || after.nlink !== 1n
|
|
2699
2693
|
|| after.dev !== settled.dev || after.ino !== settled.ino
|
|
2700
2694
|
|| after.size !== settled.size || after.mtimeNs !== settled.mtimeNs
|
|
@@ -2704,7 +2698,7 @@ function terminalizeBootstrapRegistrationIntent(options, lease, outcome, transac
|
|
|
2704
2698
|
const stateDir = dirname(lease.currentPath);
|
|
2705
2699
|
syncBootstrapDirectory(stateDir);
|
|
2706
2700
|
options.afterIntentTerminalPublish?.();
|
|
2707
|
-
const active =
|
|
2701
|
+
const active = assetstore.lstatWithAssetFileIdentity(lease.path);
|
|
2708
2702
|
if (!active.isFile() || active.isSymbolicLink() || active.nlink !== 1n
|
|
2709
2703
|
|| active.dev !== lease.device || active.ino !== lease.inode || active.size !== lease.size
|
|
2710
2704
|
|| active.mtimeNs !== lease.mtimeNs || active.ctimeNs !== lease.ctimeNs) {
|
|
@@ -2734,7 +2728,7 @@ function clearBootstrapRegistrationIntent(options, lease) {
|
|
|
2734
2728
|
assertBootstrapIntentDirectoryTrust(options, stateDir, true);
|
|
2735
2729
|
if (lease.staleRegistering) {
|
|
2736
2730
|
assertBootstrapIntentFileTrust(options, lease.staleRegistering.path);
|
|
2737
|
-
const stale =
|
|
2731
|
+
const stale = assetstore.lstatWithAssetFileIdentity(lease.staleRegistering.path);
|
|
2738
2732
|
if (!stale.isFile() || stale.isSymbolicLink() || stale.nlink !== 1n
|
|
2739
2733
|
|| stale.dev !== lease.staleRegistering.device || stale.ino !== lease.staleRegistering.inode
|
|
2740
2734
|
|| stale.size !== lease.staleRegistering.size
|
|
@@ -2749,7 +2743,7 @@ function clearBootstrapRegistrationIntent(options, lease) {
|
|
|
2749
2743
|
}
|
|
2750
2744
|
}
|
|
2751
2745
|
assertBootstrapIntentFileTrust(options, lease.currentPath);
|
|
2752
|
-
const current =
|
|
2746
|
+
const current = assetstore.lstatWithAssetFileIdentity(lease.currentPath);
|
|
2753
2747
|
if (!current.isFile() || current.isSymbolicLink() || current.nlink !== 1n
|
|
2754
2748
|
|| current.dev !== lease.device || current.ino !== lease.inode || current.size !== lease.size
|
|
2755
2749
|
|| current.mtimeNs !== lease.mtimeNs || current.ctimeNs !== lease.ctimeNs) {
|
|
@@ -2767,7 +2761,7 @@ function clearBootstrapRegistrationIntent(options, lease) {
|
|
|
2767
2761
|
}
|
|
2768
2762
|
renameSync(lease.terminalPath, lease.clearingPath);
|
|
2769
2763
|
syncBootstrapDirectory(stateDir);
|
|
2770
|
-
const renamed =
|
|
2764
|
+
const renamed = assetstore.lstatWithAssetFileIdentity(lease.clearingPath);
|
|
2771
2765
|
if (!renamed.isFile() || renamed.isSymbolicLink() || renamed.nlink !== 1n
|
|
2772
2766
|
|| renamed.dev !== lease.device || renamed.ino !== lease.inode
|
|
2773
2767
|
|| renamed.size !== lease.size) {
|
|
@@ -2786,7 +2780,7 @@ function clearBootstrapRegistrationIntent(options, lease) {
|
|
|
2786
2780
|
throw new Error('bootstrap registration intent path is unexpected');
|
|
2787
2781
|
}
|
|
2788
2782
|
assertBootstrapIntentFileTrust(options, clearingLease.currentPath);
|
|
2789
|
-
const moved =
|
|
2783
|
+
const moved = assetstore.lstatWithAssetFileIdentity(clearingLease.currentPath);
|
|
2790
2784
|
if (!moved.isFile() || moved.isSymbolicLink() || moved.nlink !== 1n
|
|
2791
2785
|
|| moved.dev !== clearingLease.device || moved.ino !== clearingLease.inode
|
|
2792
2786
|
|| moved.size !== clearingLease.size || moved.mtimeNs !== clearingLease.mtimeNs
|
|
@@ -2822,7 +2816,7 @@ function sameBootstrapIncompletePublication(left, right) {
|
|
|
2822
2816
|
}
|
|
2823
2817
|
function assertBootstrapRegistrationIntentFileIdentity(options, expected) {
|
|
2824
2818
|
assertBootstrapIntentFileTrust(options, expected.path, Number(expected.linkCount));
|
|
2825
|
-
const current =
|
|
2819
|
+
const current = assetstore.lstatWithAssetFileIdentity(expected.path);
|
|
2826
2820
|
if (!current.isFile() || current.isSymbolicLink() || current.nlink !== expected.linkCount
|
|
2827
2821
|
|| current.dev !== expected.device || current.ino !== expected.inode
|
|
2828
2822
|
|| current.size !== expected.size || current.mtimeNs !== expected.mtimeNs
|
|
@@ -2848,7 +2842,7 @@ function clearBootstrapIncompletePublication(options, publication) {
|
|
|
2848
2842
|
&& publication.registration.identity.device === publication.publishing.device
|
|
2849
2843
|
&& publication.registration.identity.inode === publication.publishing.inode) {
|
|
2850
2844
|
assertBootstrapIntentFileTrust(options, publication.publishing.path);
|
|
2851
|
-
const remaining =
|
|
2845
|
+
const remaining = assetstore.lstatWithAssetFileIdentity(publication.publishing.path);
|
|
2852
2846
|
if (!remaining.isFile() || remaining.isSymbolicLink() || remaining.nlink !== 1n
|
|
2853
2847
|
|| remaining.dev !== publication.publishing.device
|
|
2854
2848
|
|| remaining.ino !== publication.publishing.inode
|
|
@@ -3033,7 +3027,7 @@ function recoverBootstrapRegistrationIntent(options) {
|
|
|
3033
3027
|
};
|
|
3034
3028
|
}
|
|
3035
3029
|
assertBootstrapIntentFileTrust(options, intent.terminalFile.path);
|
|
3036
|
-
const partial =
|
|
3030
|
+
const partial = assetstore.lstatWithAssetFileIdentity(intent.terminalFile.path);
|
|
3037
3031
|
if (!partial.isFile() || partial.isSymbolicLink() || partial.nlink !== 1n
|
|
3038
3032
|
|| partial.dev !== intent.terminalFile.device || partial.ino !== intent.terminalFile.inode) {
|
|
3039
3033
|
throw new Error('incomplete terminal receipt ownership changed');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { closeSync, constants, fchmodSync, fstatSync, fsyncSync, lstatSync, openSync, readSync, renameSync, rmSync, writeFileSync, } from 'node:fs';
|
|
3
3
|
import { basename, dirname, join } from 'node:path';
|
|
4
|
-
import { bootstrap as coreBootstrap, util } from '@evomap/evolver-core';
|
|
4
|
+
import { assetstore, bootstrap as coreBootstrap, util } from '@evomap/evolver-core';
|
|
5
5
|
import { resolveBootstrapStateDir } from './bootstrap.js';
|
|
6
6
|
const MAX_READINESS_BYTES = 16 * 1024;
|
|
7
7
|
function isErrno(error, code) {
|
|
@@ -32,13 +32,18 @@ function readExistingReadiness(path) {
|
|
|
32
32
|
before = util.statRegularFileIdentity(path);
|
|
33
33
|
}
|
|
34
34
|
if (!before.isFile() || before.isSymbolicLink() || before.size > BigInt(MAX_READINESS_BYTES)
|
|
35
|
-
|| before.
|
|
35
|
+
|| before.ino <= 0n) {
|
|
36
|
+
throw new Error('bootstrap readiness path is not a bounded regular file');
|
|
37
|
+
}
|
|
38
|
+
const identity = assetstore.captureRegularAssetFileIdentity(path);
|
|
39
|
+
if (identity.dev <= 0n || identity.ino <= 0n) {
|
|
36
40
|
throw new Error('bootstrap readiness path is not a bounded regular file');
|
|
37
41
|
}
|
|
38
42
|
const descriptor = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
39
43
|
try {
|
|
44
|
+
assetstore.assertOpenedRegularAssetFile(descriptor, path, identity);
|
|
40
45
|
const opened = fstatSync(descriptor, { bigint: true });
|
|
41
|
-
if (!opened.isFile() || opened.dev !==
|
|
46
|
+
if (!opened.isFile() || opened.dev !== identity.dev || opened.ino !== before.ino) {
|
|
42
47
|
throw new Error('bootstrap readiness path changed while opening');
|
|
43
48
|
}
|
|
44
49
|
const bytes = Buffer.alloc(MAX_READINESS_BYTES + 1);
|
|
@@ -58,6 +63,13 @@ function readExistingReadiness(path) {
|
|
|
58
63
|
|| after.mtimeNs !== opened.mtimeNs || after.ctimeNs !== opened.ctimeNs) {
|
|
59
64
|
throw new Error('bootstrap readiness path changed while reading');
|
|
60
65
|
}
|
|
66
|
+
assetstore.assertOpenedRegularAssetFile(descriptor, path, identity);
|
|
67
|
+
const settled = assetstore.lstatWithAssetFileIdentity(path);
|
|
68
|
+
if (!settled.isFile() || settled.isSymbolicLink() || settled.dev !== after.dev || settled.ino !== after.ino
|
|
69
|
+
|| settled.birthtimeNs !== after.birthtimeNs || settled.size !== after.size
|
|
70
|
+
|| settled.mtimeNs !== after.mtimeNs || settled.ctimeNs !== after.ctimeNs) {
|
|
71
|
+
throw new Error('bootstrap readiness path changed after reading');
|
|
72
|
+
}
|
|
61
73
|
const parsed = coreBootstrap.parseLifecycleBootstrapReadinessJson(raw);
|
|
62
74
|
if (!parsed)
|
|
63
75
|
throw new Error('bootstrap readiness receipt is corrupt');
|
|
@@ -21,13 +21,12 @@
|
|
|
21
21
|
// proves a committed or cleanly rolled-back terminal outcome.
|
|
22
22
|
import { execFileSync } from 'node:child_process';
|
|
23
23
|
import { createHash, randomUUID } from 'node:crypto';
|
|
24
|
-
import { closeSync, existsSync, fstatSync, fsyncSync, lstatSync, mkdirSync, openSync, readSync, readFileSync, realpathSync, renameSync, unlinkSync, writeFileSync, } from 'node:fs';
|
|
24
|
+
import { closeSync, constants, existsSync, fstatSync, fsyncSync, lstatSync, mkdirSync, openSync, readSync, readFileSync, realpathSync, renameSync, unlinkSync, writeFileSync, } from 'node:fs';
|
|
25
25
|
import { chmod as fsChmod, link as fsLink, lstat, mkdir as fsMkdir, open as fsOpen, readFile as fsReadFile, realpath as fsRealpath, rename as fsRename, rm as fsRm, rmdir as fsRmdir, unlink as fsUnlink, writeFile as fsWriteFile, } from 'node:fs/promises';
|
|
26
26
|
import { homedir } from 'node:os';
|
|
27
27
|
import { dirname, isAbsolute, join, parse as parsePath, relative, resolve as resolvePath, win32 } from 'node:path';
|
|
28
|
-
import { ops, util } from '@evomap/evolver-core';
|
|
28
|
+
import { assetstore, ops, util } from '@evomap/evolver-core';
|
|
29
29
|
import { SELF_UPDATE_FAILURE_CODES } from './failureCodes.js';
|
|
30
|
-
import { selfUpdateFileMetadata } from './fileMetadata.js';
|
|
31
30
|
import { resolveSelfUpdatePublicKey } from './builtinKey.js';
|
|
32
31
|
import { downloadGithubReleaseArtifact, releaseAssetName, resolveGithubReleaseManifest, } from './releaseBinary.js';
|
|
33
32
|
import { preflightManagedStagedBinary } from './transaction.js';
|
|
@@ -84,13 +83,8 @@ function assertTrustedMigrationStateLeafSync(path, options = {}) {
|
|
|
84
83
|
}
|
|
85
84
|
return existing;
|
|
86
85
|
}
|
|
87
|
-
function migrationPathMetadata(path) {
|
|
88
|
-
const stat = lstatSync(path, { bigint: true });
|
|
89
|
-
return process.platform === 'win32' && stat.dev === 0n && stat.isFile() && !stat.isSymbolicLink()
|
|
90
|
-
? util.statRegularFileIdentity(path) : stat;
|
|
91
|
-
}
|
|
92
86
|
function statMigrationStateLeafSync(path) {
|
|
93
|
-
const existing =
|
|
87
|
+
const existing = assetstore.lstatWithAssetFileIdentity(path);
|
|
94
88
|
if (existing.isSymbolicLink() || !existing.isFile() || existing.nlink !== 1n) {
|
|
95
89
|
throw new Error('unsafe_migration_state_leaf');
|
|
96
90
|
}
|
|
@@ -204,7 +198,7 @@ const defaultWriteTextFile = (path, content) => {
|
|
|
204
198
|
closeSync(fd);
|
|
205
199
|
fd = undefined;
|
|
206
200
|
renameSync(temporaryPath, path);
|
|
207
|
-
const published =
|
|
201
|
+
const published = assetstore.lstatWithAssetFileIdentity(path, 'write');
|
|
208
202
|
if (published.isSymbolicLink() || !published.isFile() || published.nlink !== 1n) {
|
|
209
203
|
throw new Error('unsafe_migration_state_publication');
|
|
210
204
|
}
|
|
@@ -900,10 +894,22 @@ async function ensureSafeMigrationDirectory(directory, mkdir, assertDirectoryTru
|
|
|
900
894
|
function sha256(bytes) {
|
|
901
895
|
return createHash('sha256').update(bytes).digest('hex');
|
|
902
896
|
}
|
|
897
|
+
async function nativeMigrationFileStat(path, witnessAccess = 'read') {
|
|
898
|
+
const named = await lstat(path, { bigint: true });
|
|
899
|
+
// Re-observe even when lstat reports a volume: the named link count can predate a concurrent hardlink, and the
|
|
900
|
+
// second witness must be read before the binary is published.
|
|
901
|
+
if (process.platform !== 'win32' || named.isSymbolicLink() || !named.isFile())
|
|
902
|
+
return named;
|
|
903
|
+
const snapshot = assetstore.captureRegularAssetFileSnapshot(path, witnessAccess === 'write' ? constants.O_WRONLY : constants.O_RDONLY);
|
|
904
|
+
if (named.ino !== snapshot.ino || named.birthtimeNs !== snapshot.birthtimeNs) {
|
|
905
|
+
throw new Error('migration_file_identity_changed');
|
|
906
|
+
}
|
|
907
|
+
return snapshot;
|
|
908
|
+
}
|
|
903
909
|
async function inspectExistingMigrationTarget(destPath, version, preflight, readBinary, expected, assertDirectoryTrust, assertFileTrust) {
|
|
904
910
|
let before;
|
|
905
911
|
try {
|
|
906
|
-
before = await
|
|
912
|
+
before = await nativeMigrationFileStat(destPath);
|
|
907
913
|
}
|
|
908
914
|
catch (error) {
|
|
909
915
|
if (isErrno(error, 'ENOENT'))
|
|
@@ -930,7 +936,7 @@ async function inspectExistingMigrationTarget(destPath, version, preflight, read
|
|
|
930
936
|
throw new Error(`destination_exists_unowned_or_invalid:${errorDetail(error)}`, { cause: error });
|
|
931
937
|
}
|
|
932
938
|
await assertFileTrust(destPath);
|
|
933
|
-
const after = await
|
|
939
|
+
const after = await nativeMigrationFileStat(destPath);
|
|
934
940
|
if (!after.isFile() || after.isSymbolicLink() || after.nlink !== 1n
|
|
935
941
|
|| after.dev !== before.dev || after.ino !== before.ino || after.size !== before.size
|
|
936
942
|
|| after.mtimeNs !== before.mtimeNs || after.ctimeNs !== before.ctimeNs) {
|
|
@@ -999,6 +1005,7 @@ function assertMigrationLockSnapshotShape(snapshot) {
|
|
|
999
1005
|
function sameMigrationLockSnapshot(left, right) {
|
|
1000
1006
|
return left.dev === right.dev
|
|
1001
1007
|
&& left.ino === right.ino
|
|
1008
|
+
&& left.birthtimeNs === right.birthtimeNs
|
|
1002
1009
|
&& left.nlink === 1n
|
|
1003
1010
|
&& right.nlink === 1n
|
|
1004
1011
|
&& left.size === right.size
|
|
@@ -1019,10 +1026,18 @@ function readBoundedMigrationLockFd(fd) {
|
|
|
1019
1026
|
return bytes.subarray(0, offset);
|
|
1020
1027
|
}
|
|
1021
1028
|
function readMigrationLockAuthority(lockPath) {
|
|
1022
|
-
const beforeOpen =
|
|
1029
|
+
const beforeOpen = assetstore.lstatWithAssetFileIdentity(lockPath);
|
|
1023
1030
|
assertMigrationLockSnapshotShape(beforeOpen);
|
|
1024
|
-
const fd = openSync(lockPath,
|
|
1031
|
+
const fd = openSync(lockPath, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
1025
1032
|
try {
|
|
1033
|
+
try {
|
|
1034
|
+
assetstore.assertOpenedRegularAssetFile(fd, lockPath, {
|
|
1035
|
+
dev: beforeOpen.dev, ino: beforeOpen.ino, birthtimeNs: beforeOpen.birthtimeNs,
|
|
1036
|
+
});
|
|
1037
|
+
}
|
|
1038
|
+
catch (error) {
|
|
1039
|
+
throw new Error('migration_lock_ownership_changed', { cause: error });
|
|
1040
|
+
}
|
|
1026
1041
|
const opened = fstatSync(fd, { bigint: true });
|
|
1027
1042
|
assertMigrationLockSnapshotShape(opened);
|
|
1028
1043
|
if (!sameMigrationLockSnapshot(beforeOpen, opened)) {
|
|
@@ -1030,10 +1045,10 @@ function readMigrationLockAuthority(lockPath) {
|
|
|
1030
1045
|
}
|
|
1031
1046
|
const firstBytes = readBoundedMigrationLockFd(fd);
|
|
1032
1047
|
const afterFirstFd = fstatSync(fd, { bigint: true });
|
|
1033
|
-
const afterFirstPath =
|
|
1048
|
+
const afterFirstPath = assetstore.lstatWithAssetFileIdentity(lockPath);
|
|
1034
1049
|
const secondBytes = readBoundedMigrationLockFd(fd);
|
|
1035
1050
|
const finalFd = fstatSync(fd, { bigint: true });
|
|
1036
|
-
const finalPath =
|
|
1051
|
+
const finalPath = assetstore.lstatWithAssetFileIdentity(lockPath);
|
|
1037
1052
|
for (const snapshot of [afterFirstFd, afterFirstPath, finalFd, finalPath]) {
|
|
1038
1053
|
assertMigrationLockSnapshotShape(snapshot);
|
|
1039
1054
|
if (!sameMigrationLockSnapshot(opened, snapshot)) {
|
|
@@ -1158,7 +1173,7 @@ async function installVerifiedMigrationBinary(input) {
|
|
|
1158
1173
|
await input.chmod(temporaryPath, 0o755);
|
|
1159
1174
|
await input.syncFile(temporaryPath);
|
|
1160
1175
|
const temporaryInfo = await input.stat(temporaryPath);
|
|
1161
|
-
const temporaryIdentity = await
|
|
1176
|
+
const temporaryIdentity = await nativeMigrationFileStat(temporaryPath, 'write');
|
|
1162
1177
|
if (temporaryInfo.isSymbolicLink() || !temporaryInfo.isFile()
|
|
1163
1178
|
|| temporaryIdentity.isSymbolicLink() || !temporaryIdentity.isFile()
|
|
1164
1179
|
|| temporaryIdentity.nlink !== 1n || temporaryIdentity.dev <= 0n || temporaryIdentity.ino <= 0n) {
|
|
@@ -1273,7 +1288,7 @@ function migrationRegistrationTargetQuarantinePath(destPath, intentId) {
|
|
|
1273
1288
|
}
|
|
1274
1289
|
async function migrationPathIdentity(path) {
|
|
1275
1290
|
try {
|
|
1276
|
-
return await
|
|
1291
|
+
return await nativeMigrationFileStat(path);
|
|
1277
1292
|
}
|
|
1278
1293
|
catch (error) {
|
|
1279
1294
|
if (isErrno(error, 'ENOENT'))
|
|
@@ -1285,7 +1300,7 @@ function sameMigrationFileId(left, right) {
|
|
|
1285
1300
|
return left.dev === right.dev && left.ino === right.ino;
|
|
1286
1301
|
}
|
|
1287
1302
|
async function inspectExactMigrationCleanupFile(input) {
|
|
1288
|
-
const before = await
|
|
1303
|
+
const before = await nativeMigrationFileStat(input.path);
|
|
1289
1304
|
await input.assertFileTrust(input.path);
|
|
1290
1305
|
if (before.isSymbolicLink()
|
|
1291
1306
|
|| !before.isFile()
|
|
@@ -1299,7 +1314,7 @@ async function inspectExactMigrationCleanupFile(input) {
|
|
|
1299
1314
|
if (bytes.byteLength !== input.expected.size || sha256(bytes) !== input.expected.sha256) {
|
|
1300
1315
|
throw new Error(input.hashError);
|
|
1301
1316
|
}
|
|
1302
|
-
const after = await
|
|
1317
|
+
const after = await nativeMigrationFileStat(input.path);
|
|
1303
1318
|
if (after.isSymbolicLink()
|
|
1304
1319
|
|| !after.isFile()
|
|
1305
1320
|
|| after.dev !== before.dev
|
|
@@ -1512,7 +1527,7 @@ async function recoverPendingMigrationInstall(input) {
|
|
|
1512
1527
|
if (pending.anchor.phase === 'planned') {
|
|
1513
1528
|
let before;
|
|
1514
1529
|
try {
|
|
1515
|
-
before = await
|
|
1530
|
+
before = await nativeMigrationFileStat(pending.anchor.temporaryPath);
|
|
1516
1531
|
}
|
|
1517
1532
|
catch (error) {
|
|
1518
1533
|
if (!isErrno(error, 'ENOENT'))
|
|
@@ -1531,7 +1546,7 @@ async function recoverPendingMigrationInstall(input) {
|
|
|
1531
1546
|
throw new Error('migration_planned_temporary_unowned');
|
|
1532
1547
|
}
|
|
1533
1548
|
const bytes = await input.readBinary(pending.anchor.temporaryPath);
|
|
1534
|
-
const after = await
|
|
1549
|
+
const after = await nativeMigrationFileStat(pending.anchor.temporaryPath);
|
|
1535
1550
|
if (after.isSymbolicLink()
|
|
1536
1551
|
|| !after.isFile()
|
|
1537
1552
|
|| after.dev !== before.dev
|