joycraft 0.7.13 → 0.7.14
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 +25 -11
- package/dist/chunk-7BPB2IKY.js +255 -0
- package/dist/chunk-7BPB2IKY.js.map +1 -0
- package/dist/chunk-B73DPYYC.js +377 -0
- package/dist/chunk-B73DPYYC.js.map +1 -0
- package/dist/{chunk-EFHJI5KD.js → chunk-JYPBXPGD.js} +114 -112
- package/dist/chunk-JYPBXPGD.js.map +1 -0
- package/dist/{chunk-LKWD25KJ.js → chunk-KKDKC4FM.js} +8 -71
- package/dist/chunk-KKDKC4FM.js.map +1 -0
- package/dist/chunk-OMFGDJW4.js +97 -0
- package/dist/chunk-OMFGDJW4.js.map +1 -0
- package/dist/chunk-PR4QDKPL.js +3755 -0
- package/dist/chunk-PR4QDKPL.js.map +1 -0
- package/dist/chunk-Z5JFEGWG.js +563 -0
- package/dist/chunk-Z5JFEGWG.js.map +1 -0
- package/dist/cli.js +387 -54
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +235 -1
- package/dist/index.js +691 -1
- package/dist/index.js.map +1 -1
- package/dist/init-S5JU5BHL.js +60 -0
- package/dist/init-S5JU5BHL.js.map +1 -0
- package/dist/{init-autofix-E7DSPUSC.js → init-autofix-WSKUT2HN.js} +4 -3
- package/dist/{init-autofix-E7DSPUSC.js.map → init-autofix-WSKUT2HN.js.map} +1 -1
- package/dist/install-manifest-EQHT4474.js +37 -0
- package/dist/joycraft-release.json +8 -0
- package/dist/release-artifact-4TL5L2ZY.js +14 -0
- package/dist/release-artifact-4TL5L2ZY.js.map +1 -0
- package/dist/release-resolver-P2H46QTU.js +293 -0
- package/dist/release-resolver-P2H46QTU.js.map +1 -0
- package/dist/update-HNTXCEKB.js +19 -0
- package/dist/update-HNTXCEKB.js.map +1 -0
- package/dist/update-check-YT765NE7.js +36 -0
- package/dist/update-check-YT765NE7.js.map +1 -0
- package/dist/upgrade-LZOND7OZ.js +28 -0
- package/dist/upgrade-LZOND7OZ.js.map +1 -0
- package/package.json +5 -2
- package/dist/chunk-EFHJI5KD.js.map +0 -1
- package/dist/chunk-J6GDQ55S.js +0 -91
- package/dist/chunk-J6GDQ55S.js.map +0 -1
- package/dist/chunk-LKWD25KJ.js.map +0 -1
- package/dist/chunk-Q2ZQ6RGD.js +0 -243
- package/dist/chunk-Q2ZQ6RGD.js.map +0 -1
- package/dist/init-YSFURLGT.js +0 -1330
- package/dist/init-YSFURLGT.js.map +0 -1
- package/dist/upgrade-PELFI26D.js +0 -650
- package/dist/upgrade-PELFI26D.js.map +0 -1
- package/dist/version-J7MOKNJR.js +0 -28
- /package/dist/{version-J7MOKNJR.js.map → install-manifest-EQHT4474.js.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -275,7 +275,697 @@ async function detectStack(dir) {
|
|
|
275
275
|
}
|
|
276
276
|
return { language: "unknown", packageManager: "", commands: {} };
|
|
277
277
|
}
|
|
278
|
+
|
|
279
|
+
// src/update-check.ts
|
|
280
|
+
import {
|
|
281
|
+
existsSync as existsSync2,
|
|
282
|
+
lstatSync,
|
|
283
|
+
mkdirSync,
|
|
284
|
+
openSync,
|
|
285
|
+
closeSync,
|
|
286
|
+
readFileSync as readFileSync2,
|
|
287
|
+
realpathSync,
|
|
288
|
+
renameSync,
|
|
289
|
+
unlinkSync,
|
|
290
|
+
writeFileSync
|
|
291
|
+
} from "fs";
|
|
292
|
+
import { dirname, join as join2 } from "path";
|
|
293
|
+
import { randomUUID } from "crypto";
|
|
294
|
+
var CHECK_CACHE_PATH = "docs/.joycraft/local/check-cache.json";
|
|
295
|
+
var CHECK_SETTINGS_PATH = "docs/.joycraft/local/settings.json";
|
|
296
|
+
var CHECK_LOCK_PATH = "docs/.joycraft/local/check.lock";
|
|
297
|
+
var CHECK_CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
298
|
+
var CHECK_DEFAULT_DEADLINE_MS = 3e3;
|
|
299
|
+
var CHECK_MAX_BACKOFF_MS = 60 * 60 * 1e3;
|
|
300
|
+
var CHECK_LOCK_TTL_MS = 1e4;
|
|
301
|
+
function resolveCheckSessionId(explicit) {
|
|
302
|
+
return explicit ?? process.env.JOYCRAFT_SESSION_ID ?? `parent-${process.ppid}`;
|
|
303
|
+
}
|
|
304
|
+
var STABLE_VERSION = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
|
|
305
|
+
var REGISTRY_URL = "https://registry.npmjs.org/joycraft/latest";
|
|
306
|
+
function object(value) {
|
|
307
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
308
|
+
}
|
|
309
|
+
function validVersion(value) {
|
|
310
|
+
return typeof value === "string" && STABLE_VERSION.test(value);
|
|
311
|
+
}
|
|
312
|
+
function timestamp(options) {
|
|
313
|
+
return typeof options.now === "function" ? options.now() : options.now ?? Date.now();
|
|
314
|
+
}
|
|
315
|
+
function compareStableVersions(left, right) {
|
|
316
|
+
const a = left.match(STABLE_VERSION);
|
|
317
|
+
const b = right.match(STABLE_VERSION);
|
|
318
|
+
if (!a || !b) return null;
|
|
319
|
+
for (let i = 1; i <= 3; i += 1) {
|
|
320
|
+
const ai = BigInt(a[i]);
|
|
321
|
+
const bi = BigInt(b[i]);
|
|
322
|
+
if (ai !== bi) return ai > bi ? 1 : -1;
|
|
323
|
+
}
|
|
324
|
+
return 0;
|
|
325
|
+
}
|
|
326
|
+
function policy(value) {
|
|
327
|
+
return value === "off" || value === "auto-safe" || value === "notify" ? value : "notify";
|
|
328
|
+
}
|
|
329
|
+
function safeLocalPath(root, relative) {
|
|
330
|
+
let current;
|
|
331
|
+
try {
|
|
332
|
+
current = realpathSync(root);
|
|
333
|
+
if (!lstatSync(current).isDirectory()) return void 0;
|
|
334
|
+
} catch {
|
|
335
|
+
return void 0;
|
|
336
|
+
}
|
|
337
|
+
const destination = join2(current, relative);
|
|
338
|
+
const parts = relative.split("/");
|
|
339
|
+
for (const [index, segment] of parts.entries()) {
|
|
340
|
+
current = join2(current, segment);
|
|
341
|
+
try {
|
|
342
|
+
const stat = lstatSync(current);
|
|
343
|
+
if (stat.isSymbolicLink() || index < parts.length - 1 && !stat.isDirectory()) return void 0;
|
|
344
|
+
} catch (error) {
|
|
345
|
+
if (error.code === "ENOENT") break;
|
|
346
|
+
return void 0;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return destination;
|
|
350
|
+
}
|
|
351
|
+
function readJson(path) {
|
|
352
|
+
if (!path) return { present: true, valid: false };
|
|
353
|
+
if (!existsSync2(path)) return { present: false, valid: true };
|
|
354
|
+
try {
|
|
355
|
+
const value = object(JSON.parse(readFileSync2(path, "utf8")));
|
|
356
|
+
return value ? { value, present: true, valid: true } : { present: true, valid: false };
|
|
357
|
+
} catch {
|
|
358
|
+
return { present: true, valid: false };
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
function writeLocalJson(root, relative, value, existing) {
|
|
362
|
+
const path = safeLocalPath(root, relative);
|
|
363
|
+
if (!path) return false;
|
|
364
|
+
if (existing === void 0 && existsSync2(path)) return false;
|
|
365
|
+
const temp = `${path}.tmp-${process.pid}-${Date.now()}`;
|
|
366
|
+
try {
|
|
367
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
368
|
+
writeFileSync(temp, JSON.stringify({ ...existing ?? {}, ...value }, null, 2) + "\n", { encoding: "utf8", flag: "wx" });
|
|
369
|
+
renameSync(temp, path);
|
|
370
|
+
return true;
|
|
371
|
+
} catch {
|
|
372
|
+
try {
|
|
373
|
+
unlinkSync(temp);
|
|
374
|
+
} catch {
|
|
375
|
+
}
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
function readSettings(root) {
|
|
380
|
+
const result = readJson(safeLocalPath(root, CHECK_SETTINGS_PATH));
|
|
381
|
+
const settings = result.value;
|
|
382
|
+
const validPolicy = (value) => value === void 0 || value === "notify" || value === "off" || value === "auto-safe";
|
|
383
|
+
const validSettings = !settings || validPolicy(settings.updatePolicy) && validPolicy(settings.policy) && (settings.acknowledgedRelease === void 0 || typeof settings.acknowledgedRelease === "string") && (settings.acknowledgedSession === void 0 || typeof settings.acknowledgedSession === "string") && (settings.postponedRelease === void 0 || typeof settings.postponedRelease === "string");
|
|
384
|
+
return { settings, valid: result.valid && validSettings };
|
|
385
|
+
}
|
|
386
|
+
function readUpdatePolicy(root) {
|
|
387
|
+
const { settings, valid } = readSettings(root);
|
|
388
|
+
return valid ? policy(settings?.updatePolicy ?? settings?.policy) : "notify";
|
|
389
|
+
}
|
|
390
|
+
function setUpdatePolicy(root, value) {
|
|
391
|
+
if (!["notify", "auto-safe", "off"].includes(value)) return false;
|
|
392
|
+
const { settings, valid } = readSettings(root);
|
|
393
|
+
return valid && writeLocalJson(root, CHECK_SETTINGS_PATH, { updatePolicy: value }, settings);
|
|
394
|
+
}
|
|
395
|
+
function readManifest(root) {
|
|
396
|
+
const paths = ["docs/.joycraft/manifest.json", "docs/.joycraft/local/manifest.json"];
|
|
397
|
+
const found = [];
|
|
398
|
+
for (const relative of paths) {
|
|
399
|
+
const result = readJson(safeLocalPath(root, relative));
|
|
400
|
+
if (result.present) found.push({ path: relative, data: result.value, valid: result.valid });
|
|
401
|
+
}
|
|
402
|
+
if (found.some((entry) => !entry.valid)) {
|
|
403
|
+
return { pending: false, conflicts: [], valid: false, diagnostics: ["Joycraft installation manifest is invalid or unreadable."] };
|
|
404
|
+
}
|
|
405
|
+
if (!found.length) return { pending: false, conflicts: [], valid: true, diagnostics: ["No Joycraft installation manifest was found."] };
|
|
406
|
+
const valid = found.filter((entry) => Boolean(entry.data));
|
|
407
|
+
if (valid.some(({ data: data2 }) => data2.schemaVersion !== 1 || typeof data2.targetVersion !== "string" || !STABLE_VERSION.test(data2.targetVersion) || typeof data2.bundleIntegrity !== "string" || data2.profile !== "shared" && data2.profile !== "private" || !Array.isArray(data2.harnesses) || !object(data2.files))) {
|
|
408
|
+
return { pending: false, conflicts: [], valid: false, diagnostics: ["Joycraft installation manifest uses an unsupported or invalid schema."] };
|
|
409
|
+
}
|
|
410
|
+
for (const { data: data2 } of valid) {
|
|
411
|
+
for (const entry of Object.values(data2.files)) {
|
|
412
|
+
const file = object(entry);
|
|
413
|
+
if (!file || typeof file.vendorVersion !== "string" || !file.vendorVersion || typeof file.vendorHash !== "string" || !["vendor", "create-once", "config-patch"].includes(String(file.kind)) || file.ownership !== "verified" && file.ownership !== "unknown") {
|
|
414
|
+
return { pending: false, conflicts: [], valid: false, diagnostics: ["Joycraft installation manifest contains an invalid file entry."] };
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
if (valid.length === 2) {
|
|
419
|
+
return { pending: false, conflicts: [], valid: false, diagnostics: ["Both shared and private installation manifests are present; choose one authority."] };
|
|
420
|
+
}
|
|
421
|
+
const data = valid[0].data;
|
|
422
|
+
const files = object(data.files);
|
|
423
|
+
const conflicts = [];
|
|
424
|
+
if (data.pendingConflicts !== void 0) {
|
|
425
|
+
if (!Array.isArray(data.pendingConflicts) || data.pendingConflicts.some((path) => typeof path !== "string" || !path)) {
|
|
426
|
+
return { pending: false, conflicts: [], valid: false, diagnostics: ["Joycraft installation pending-conflict state is invalid."] };
|
|
427
|
+
}
|
|
428
|
+
conflicts.push(...new Set(data.pendingConflicts));
|
|
429
|
+
} else if (files) {
|
|
430
|
+
for (const [path, raw] of Object.entries(files)) {
|
|
431
|
+
const entry = object(raw);
|
|
432
|
+
if (!entry || entry.kind !== "create-once" && (entry.ownership === "unknown" || entry.kind === "vendor" && entry.vendorVersion !== data.targetVersion)) conflicts.push(path);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
return { version: data.targetVersion, pending: conflicts.length > 0, conflicts, valid: true, diagnostics: [] };
|
|
436
|
+
}
|
|
437
|
+
function validCache(value) {
|
|
438
|
+
return Boolean(value && value.schemaVersion === 1 && typeof value.fetchedAt === "number" && validVersion(value.version));
|
|
439
|
+
}
|
|
440
|
+
function cacheResult(root) {
|
|
441
|
+
const result = readJson(safeLocalPath(root, CHECK_CACHE_PATH));
|
|
442
|
+
return { cache: validCache(result.value) ? result.value : void 0, writable: !result.present || validCache(result.value) };
|
|
443
|
+
}
|
|
444
|
+
function acquireLock(root, now) {
|
|
445
|
+
const path = safeLocalPath(root, CHECK_LOCK_PATH);
|
|
446
|
+
if (!path) return void 0;
|
|
447
|
+
try {
|
|
448
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
449
|
+
} catch {
|
|
450
|
+
return void 0;
|
|
451
|
+
}
|
|
452
|
+
const receipt = JSON.stringify({ pid: process.pid, startedAt: now, token: randomUUID() }) + "\n";
|
|
453
|
+
const attempt = () => {
|
|
454
|
+
let fd;
|
|
455
|
+
try {
|
|
456
|
+
fd = openSync(path, "wx");
|
|
457
|
+
writeFileSync(fd, receipt, "utf8");
|
|
458
|
+
return receipt;
|
|
459
|
+
} catch {
|
|
460
|
+
if (fd !== void 0) {
|
|
461
|
+
try {
|
|
462
|
+
unlinkSync(path);
|
|
463
|
+
} catch {
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
return void 0;
|
|
467
|
+
} finally {
|
|
468
|
+
if (fd !== void 0) {
|
|
469
|
+
try {
|
|
470
|
+
closeSync(fd);
|
|
471
|
+
} catch {
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
const acquired = attempt();
|
|
477
|
+
if (acquired) return acquired;
|
|
478
|
+
try {
|
|
479
|
+
const raw = readFileSync2(path, "utf8");
|
|
480
|
+
const lock = object(JSON.parse(raw));
|
|
481
|
+
let dead = false;
|
|
482
|
+
if (Number.isInteger(lock?.pid) && Number(lock?.pid) > 0) {
|
|
483
|
+
try {
|
|
484
|
+
process.kill(Number(lock?.pid), 0);
|
|
485
|
+
} catch (error) {
|
|
486
|
+
dead = error.code === "ESRCH";
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
if (dead && typeof lock?.startedAt === "number" && now - lock.startedAt > CHECK_LOCK_TTL_MS && readFileSync2(path, "utf8") === raw) {
|
|
490
|
+
unlinkSync(path);
|
|
491
|
+
return attempt();
|
|
492
|
+
}
|
|
493
|
+
} catch {
|
|
494
|
+
}
|
|
495
|
+
return void 0;
|
|
496
|
+
}
|
|
497
|
+
function releaseLock(root, receipt) {
|
|
498
|
+
const path = safeLocalPath(root, CHECK_LOCK_PATH);
|
|
499
|
+
if (!path) return;
|
|
500
|
+
try {
|
|
501
|
+
if (readFileSync2(path, "utf8") === receipt) unlinkSync(path);
|
|
502
|
+
} catch {
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
async function withDeadline(task, deadlineMs) {
|
|
506
|
+
const controller = new AbortController();
|
|
507
|
+
let timeout;
|
|
508
|
+
const deadline = new Promise((_, reject) => {
|
|
509
|
+
timeout = setTimeout(() => {
|
|
510
|
+
controller.abort();
|
|
511
|
+
reject(new Error("Update check timed out."));
|
|
512
|
+
}, Math.max(1, Math.min(CHECK_DEFAULT_DEADLINE_MS, deadlineMs)));
|
|
513
|
+
});
|
|
514
|
+
try {
|
|
515
|
+
return await Promise.race([task(controller.signal), deadline]);
|
|
516
|
+
} finally {
|
|
517
|
+
if (timeout) clearTimeout(timeout);
|
|
518
|
+
controller.abort();
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
async function defaultFetch(signal) {
|
|
522
|
+
const response = await fetch(REGISTRY_URL, { signal });
|
|
523
|
+
if (!response.ok) throw new Error(`Registry returned HTTP ${response.status}.`);
|
|
524
|
+
return response.json();
|
|
525
|
+
}
|
|
526
|
+
function failureCache(previous, now, error) {
|
|
527
|
+
const count = Math.min((previous?.failureCount ?? 0) + 1, 8);
|
|
528
|
+
const delay = Math.min(1e3 * 2 ** (count - 1), CHECK_MAX_BACKOFF_MS);
|
|
529
|
+
return {
|
|
530
|
+
...previous ?? { schemaVersion: 1, fetchedAt: 0, version: "0.0.0" },
|
|
531
|
+
failureCount: count,
|
|
532
|
+
lastFailureAt: now,
|
|
533
|
+
nextRetryAt: now + delay,
|
|
534
|
+
lastError: error instanceof Error ? error.message : String(error)
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
function successfulCache(previous, metadata, now) {
|
|
538
|
+
return { ...previous ?? { schemaVersion: 1 }, schemaVersion: 1, fetchedAt: now, version: metadata.version, failureCount: 0, nextRetryAt: 0, lastError: void 0 };
|
|
539
|
+
}
|
|
540
|
+
function resolveUpdateStatus(input) {
|
|
541
|
+
const diagnostics = [...input.diagnostics ?? []];
|
|
542
|
+
const policyValue = policy(input.policy);
|
|
543
|
+
if (!input.installedVersion || !input.availableVersion || !validVersion(input.installedVersion) || !validVersion(input.availableVersion)) {
|
|
544
|
+
return { status: "unknown", display: false, diagnostics: [...diagnostics, "A stable installed and available version is required."] };
|
|
545
|
+
}
|
|
546
|
+
const comparison = compareStableVersions(input.availableVersion, input.installedVersion);
|
|
547
|
+
if (comparison === null) return { status: "current", display: false, diagnostics: [...diagnostics, "Prerelease or malformed release ignored for automatic selection."] };
|
|
548
|
+
if (input.pendingConflicts) return { status: "pending-conflicts", display: false, diagnostics };
|
|
549
|
+
if (comparison <= 0) return { status: "current", display: false, diagnostics };
|
|
550
|
+
const dismissed = !input.explicit && (input.postponedRelease === input.availableVersion || input.acknowledgedRelease === input.availableVersion && input.acknowledgedSession === input.sessionId);
|
|
551
|
+
if (dismissed && input.postponedRelease === input.availableVersion) return { status: "postponed", display: false, diagnostics };
|
|
552
|
+
return { status: "available", display: (policyValue === "notify" || input.explicit === true) && !dismissed, diagnostics, ...policyValue === "auto-safe" && !dismissed ? { autoSafeCandidate: true } : {} };
|
|
553
|
+
}
|
|
554
|
+
async function checkForUpdate(root, options = {}) {
|
|
555
|
+
const now = timestamp(options);
|
|
556
|
+
const explicit = options.explicit === true;
|
|
557
|
+
const sessionId = resolveCheckSessionId(options.sessionId);
|
|
558
|
+
const settingsResult = readSettings(root);
|
|
559
|
+
const settings = settingsResult.settings;
|
|
560
|
+
const localPolicy = policy(settings?.updatePolicy ?? settings?.policy);
|
|
561
|
+
if (!settingsResult.valid) return { status: "unknown", policy: localPolicy, display: false, explicit, fromCache: false, diagnostics: ["Joycraft local checker settings are invalid or unreadable."], conflicts: [] };
|
|
562
|
+
const manifest = readManifest(root);
|
|
563
|
+
if (!manifest.valid) return { status: "unknown", installedVersion: options.installedVersion, policy: localPolicy, display: false, explicit, fromCache: false, diagnostics: manifest.diagnostics, conflicts: manifest.conflicts };
|
|
564
|
+
const installedVersion = options.installedVersion ?? manifest.version;
|
|
565
|
+
if (localPolicy === "off" && !explicit) return { status: "unknown", installedVersion, policy: localPolicy, display: false, explicit, fromCache: false, diagnostics: [], conflicts: manifest.conflicts };
|
|
566
|
+
const { cache, writable } = cacheResult(root);
|
|
567
|
+
const useCache = cache && cache.version !== "0.0.0" && now >= cache.fetchedAt && now - cache.fetchedAt < CHECK_CACHE_TTL_MS;
|
|
568
|
+
let currentCache = cache;
|
|
569
|
+
let fromCache = Boolean(useCache);
|
|
570
|
+
let diagnostics = [...manifest.diagnostics];
|
|
571
|
+
if (!useCache) {
|
|
572
|
+
if (cache?.nextRetryAt && now < cache.nextRetryAt) {
|
|
573
|
+
return { status: "unknown", installedVersion, policy: localPolicy, display: false, explicit, fromCache: true, diagnostics: [...diagnostics, "Registry refresh is in bounded backoff."], conflicts: manifest.conflicts };
|
|
574
|
+
}
|
|
575
|
+
const lockReceipt = acquireLock(root, now);
|
|
576
|
+
if (!lockReceipt) {
|
|
577
|
+
return { status: "unknown", installedVersion, policy: localPolicy, display: false, explicit, fromCache: false, diagnostics: [...diagnostics, "Another checker is refreshing registry metadata."], conflicts: manifest.conflicts };
|
|
578
|
+
}
|
|
579
|
+
try {
|
|
580
|
+
const fetched = await withDeadline(options.fetchLatest ?? defaultFetch, options.deadlineMs ?? CHECK_DEFAULT_DEADLINE_MS);
|
|
581
|
+
const metadata = object(fetched);
|
|
582
|
+
if (!metadata || !validVersion(metadata.version)) throw new Error("Registry metadata did not contain a stable version.");
|
|
583
|
+
currentCache = successfulCache(cache, metadata, now);
|
|
584
|
+
if (writable) writeLocalJson(root, CHECK_CACHE_PATH, currentCache, cache);
|
|
585
|
+
fromCache = false;
|
|
586
|
+
} catch (error) {
|
|
587
|
+
if (writable) writeLocalJson(root, CHECK_CACHE_PATH, failureCache(cache, now, error), cache);
|
|
588
|
+
return { status: "unknown", installedVersion, policy: localPolicy, display: false, explicit, fromCache: false, diagnostics: [...diagnostics, error instanceof Error ? error.message : String(error)], conflicts: manifest.conflicts };
|
|
589
|
+
} finally {
|
|
590
|
+
releaseLock(root, lockReceipt);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
const resolved = resolveUpdateStatus({
|
|
594
|
+
installedVersion,
|
|
595
|
+
availableVersion: currentCache?.version,
|
|
596
|
+
policy: localPolicy,
|
|
597
|
+
explicit,
|
|
598
|
+
pendingConflicts: manifest.pending,
|
|
599
|
+
postponedRelease: typeof settings?.postponedRelease === "string" ? settings.postponedRelease : void 0,
|
|
600
|
+
acknowledgedRelease: typeof settings?.acknowledgedRelease === "string" ? settings.acknowledgedRelease : void 0,
|
|
601
|
+
acknowledgedSession: typeof settings?.acknowledgedSession === "string" ? settings.acknowledgedSession : void 0,
|
|
602
|
+
sessionId,
|
|
603
|
+
diagnostics
|
|
604
|
+
});
|
|
605
|
+
return {
|
|
606
|
+
status: resolved.status,
|
|
607
|
+
installedVersion,
|
|
608
|
+
availableVersion: currentCache?.version,
|
|
609
|
+
policy: localPolicy,
|
|
610
|
+
display: resolved.display,
|
|
611
|
+
explicit,
|
|
612
|
+
fromCache,
|
|
613
|
+
diagnostics: resolved.diagnostics,
|
|
614
|
+
conflicts: manifest.conflicts,
|
|
615
|
+
...resolved.autoSafeCandidate && currentCache ? {
|
|
616
|
+
automaticUpdate: {
|
|
617
|
+
verificationRequired: true,
|
|
618
|
+
command: ["npm", "exec", "--yes", "--", `joycraft@${currentCache.version}`, "update", "--auto-safe", "--non-interactive", "--json"]
|
|
619
|
+
}
|
|
620
|
+
} : {}
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
function acknowledgeUpdate(root, input) {
|
|
624
|
+
if (!validVersion(input.release) || !input.session) return false;
|
|
625
|
+
const { settings, valid } = readSettings(root);
|
|
626
|
+
if (!valid) return false;
|
|
627
|
+
return writeLocalJson(root, CHECK_SETTINGS_PATH, { acknowledgedRelease: input.release, acknowledgedSession: input.session }, settings);
|
|
628
|
+
}
|
|
629
|
+
function postponeUpdate(root, release) {
|
|
630
|
+
if (!validVersion(release)) return false;
|
|
631
|
+
const { settings, valid } = readSettings(root);
|
|
632
|
+
if (!valid) return false;
|
|
633
|
+
return writeLocalJson(root, CHECK_SETTINGS_PATH, { postponedRelease: release }, settings);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// src/release-artifact.ts
|
|
637
|
+
import { createHash } from "crypto";
|
|
638
|
+
import { gunzipSync } from "zlib";
|
|
639
|
+
var MAX_COMPRESSED_BYTES = 32 * 1024 * 1024;
|
|
640
|
+
var MAX_ARCHIVE_BYTES = 64 * 1024 * 1024;
|
|
641
|
+
var MAX_ENTRY_BYTES = 8 * 1024 * 1024;
|
|
642
|
+
var MAX_ENTRIES = 1e4;
|
|
643
|
+
var EXACT_VERSION = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-(?:0|[1-9]\d*|[0-9A-Za-z-]*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|[0-9A-Za-z-]*[A-Za-z-][0-9A-Za-z-]*))*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
|
|
644
|
+
var PACKAGE_NAME = /^(?:@[a-z0-9._~-]+\/)?[a-z0-9._~-]+$/i;
|
|
645
|
+
var SHA512_INTEGRITY = /^sha512-([A-Za-z0-9+/]+={0,2})$/;
|
|
646
|
+
var verifiedArtifacts = /* @__PURE__ */ new WeakSet();
|
|
647
|
+
function objectRecord(value, label) {
|
|
648
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error(`${label} must be an object.`);
|
|
649
|
+
return value;
|
|
650
|
+
}
|
|
651
|
+
function parseJson(data, label) {
|
|
652
|
+
if (typeof data === "string") {
|
|
653
|
+
try {
|
|
654
|
+
return JSON.parse(data);
|
|
655
|
+
} catch {
|
|
656
|
+
throw new Error(`${label} is not valid JSON.`);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
if (data instanceof Uint8Array) {
|
|
660
|
+
try {
|
|
661
|
+
return JSON.parse(Buffer.from(data).toString("utf8"));
|
|
662
|
+
} catch {
|
|
663
|
+
throw new Error(`${label} is not valid JSON.`);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
return data;
|
|
667
|
+
}
|
|
668
|
+
function assertExactVersion(version, label = "Release version") {
|
|
669
|
+
if (typeof version !== "string" || !EXACT_VERSION.test(version)) throw new Error(`${label} must be an exact semver.`);
|
|
670
|
+
}
|
|
671
|
+
function assertIntegrity(integrity) {
|
|
672
|
+
if (typeof integrity !== "string") throw new Error("Release integrity must be a canonical sha512 SRI value.");
|
|
673
|
+
const match = SHA512_INTEGRITY.exec(integrity);
|
|
674
|
+
if (!match || Buffer.from(match[1], "base64").length !== 64 || Buffer.from(match[1], "base64").toString("base64") !== match[1]) {
|
|
675
|
+
throw new Error("Release integrity must be a canonical sha512 SRI value.");
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
function cloneRelease(release) {
|
|
679
|
+
objectRecord(release, "Release");
|
|
680
|
+
if (typeof release.packageName !== "string" || !PACKAGE_NAME.test(release.packageName)) throw new Error("Release package name is invalid.");
|
|
681
|
+
assertExactVersion(release.version);
|
|
682
|
+
assertIntegrity(release.integrity);
|
|
683
|
+
if (typeof release.tarballUrl !== "string") throw new Error("Release tarball URL is invalid.");
|
|
684
|
+
let parsed;
|
|
685
|
+
try {
|
|
686
|
+
parsed = new URL(release.tarballUrl);
|
|
687
|
+
} catch {
|
|
688
|
+
throw new Error("Release tarball URL is invalid.");
|
|
689
|
+
}
|
|
690
|
+
if (parsed.protocol !== "https:" && parsed.protocol !== "http:" || parsed.username || parsed.password) throw new Error("Release tarball URL is invalid.");
|
|
691
|
+
return Object.freeze({
|
|
692
|
+
packageName: release.packageName,
|
|
693
|
+
version: release.version,
|
|
694
|
+
integrity: release.integrity,
|
|
695
|
+
tarballUrl: release.tarballUrl
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
function parseReleaseDescriptor(data, exactVersion) {
|
|
699
|
+
assertExactVersion(exactVersion, "Exact version");
|
|
700
|
+
const value = objectRecord(parseJson(data, "Release descriptor"), "Release descriptor");
|
|
701
|
+
if (value.schemaVersion !== 1) throw new Error("Release descriptor schema is unsupported.");
|
|
702
|
+
if (value.releaseVersion !== exactVersion) throw new Error("Release descriptor version does not match the exact release.");
|
|
703
|
+
const manifestSchemas = value.manifestSchemas;
|
|
704
|
+
if (!Array.isArray(manifestSchemas) || manifestSchemas.length < 1 || !manifestSchemas.every((schema) => Number.isSafeInteger(schema) && schema >= 1) || new Set(manifestSchemas).size !== manifestSchemas.length || !manifestSchemas.includes(1)) {
|
|
705
|
+
throw new Error("Release descriptor manifestSchemas must include supported schema 1.");
|
|
706
|
+
}
|
|
707
|
+
if (typeof value.autoSafeEligible !== "boolean") throw new Error("Release descriptor autoSafeEligible must be boolean.");
|
|
708
|
+
const schemas = Object.freeze([...manifestSchemas]);
|
|
709
|
+
return Object.freeze({ schemaVersion: 1, releaseVersion: exactVersion, manifestSchemas: schemas, autoSafeEligible: value.autoSafeEligible });
|
|
710
|
+
}
|
|
711
|
+
function textField(header, start, length) {
|
|
712
|
+
const raw = header.subarray(start, start + length);
|
|
713
|
+
const nul = raw.indexOf(0);
|
|
714
|
+
const end = nul < 0 ? raw.length : nul;
|
|
715
|
+
return raw.subarray(0, end).toString("utf8");
|
|
716
|
+
}
|
|
717
|
+
function octalField(header, start, length, label) {
|
|
718
|
+
const value = textField(header, start, length).trim();
|
|
719
|
+
if (value === "" || !/^[0-7]+$/.test(value)) throw new Error(`Archive ${label} is invalid.`);
|
|
720
|
+
const parsed = Number.parseInt(value, 8);
|
|
721
|
+
if (!Number.isSafeInteger(parsed)) throw new Error(`Archive ${label} is too large.`);
|
|
722
|
+
return parsed;
|
|
723
|
+
}
|
|
724
|
+
function validateArchivePath(name, directory) {
|
|
725
|
+
if (!name || name.includes("\\") || name.startsWith("/") || name.includes("\0")) throw new Error(`Archive path '${name}' is unsafe.`);
|
|
726
|
+
const normalized = directory && name.endsWith("/") ? name.slice(0, -1) : name;
|
|
727
|
+
const parts = normalized.split("/");
|
|
728
|
+
if (parts.some((part) => part === "" || part === "." || part === "..")) throw new Error(`Archive path '${name}' is unsafe.`);
|
|
729
|
+
return normalized;
|
|
730
|
+
}
|
|
731
|
+
function parseTarEntries(gzipBytes) {
|
|
732
|
+
if (gzipBytes.byteLength > MAX_COMPRESSED_BYTES) throw new Error("Release artifact is too large.");
|
|
733
|
+
let archive;
|
|
734
|
+
try {
|
|
735
|
+
archive = gunzipSync(Buffer.from(gzipBytes), { maxOutputLength: MAX_ARCHIVE_BYTES });
|
|
736
|
+
} catch (error) {
|
|
737
|
+
throw new Error(`Release artifact gzip is invalid or too large: ${error instanceof Error ? error.message : String(error)}`);
|
|
738
|
+
}
|
|
739
|
+
if (archive.length > MAX_ARCHIVE_BYTES) throw new Error("Release artifact archive is too large.");
|
|
740
|
+
const entries = /* @__PURE__ */ new Map();
|
|
741
|
+
let offset = 0;
|
|
742
|
+
let sawEnd = false;
|
|
743
|
+
let count = 0;
|
|
744
|
+
while (offset + 512 <= archive.length) {
|
|
745
|
+
const header = archive.subarray(offset, offset + 512);
|
|
746
|
+
if (header.every((byte) => byte === 0)) {
|
|
747
|
+
if (offset + 1024 > archive.length || !archive.subarray(offset).every((byte) => byte === 0)) throw new Error("Archive has an incomplete end marker or trailing data.");
|
|
748
|
+
sawEnd = true;
|
|
749
|
+
break;
|
|
750
|
+
}
|
|
751
|
+
count += 1;
|
|
752
|
+
if (count > MAX_ENTRIES) throw new Error("Release artifact has too many archive entries.");
|
|
753
|
+
const providedChecksum = octalField(header, 148, 8, "checksum");
|
|
754
|
+
let calculatedChecksum = 0;
|
|
755
|
+
for (let index = 0; index < 512; index += 1) calculatedChecksum += index >= 148 && index < 156 ? 32 : header[index];
|
|
756
|
+
if (providedChecksum !== calculatedChecksum) throw new Error("Archive header checksum is invalid.");
|
|
757
|
+
const name = textField(header, 0, 100);
|
|
758
|
+
const prefix = textField(header, 345, 155);
|
|
759
|
+
const fullName = prefix ? `${prefix}/${name}` : name;
|
|
760
|
+
const type = header[156] === 0 ? "0" : String.fromCharCode(header[156]);
|
|
761
|
+
const mode = octalField(header, 100, 8, "mode");
|
|
762
|
+
if ((mode & 61440) === 40960) throw new Error(`Archive contains symlink metadata for '${fullName}'.`);
|
|
763
|
+
if (type !== "0" && type !== "5") throw new Error(`Archive contains unsupported or unsafe entry '${fullName}'.`);
|
|
764
|
+
const normalizedName = validateArchivePath(fullName, type === "5");
|
|
765
|
+
if (entries.has(normalizedName)) throw new Error(`Archive contains duplicate entry '${normalizedName}'.`);
|
|
766
|
+
const size = octalField(header, 124, 12, "entry size");
|
|
767
|
+
if (type === "5" && size !== 0) throw new Error(`Archive directory '${fullName}' has invalid content.`);
|
|
768
|
+
if (size > MAX_ENTRY_BYTES) throw new Error(`Archive entry '${fullName}' is too large.`);
|
|
769
|
+
const dataStart = offset + 512;
|
|
770
|
+
const dataEnd = dataStart + size;
|
|
771
|
+
const next = dataStart + Math.ceil(size / 512) * 512;
|
|
772
|
+
if (dataEnd > archive.length || next > archive.length) throw new Error(`Archive entry '${fullName}' is truncated.`);
|
|
773
|
+
entries.set(normalizedName, Buffer.from(archive.subarray(dataStart, dataEnd)));
|
|
774
|
+
offset = next;
|
|
775
|
+
}
|
|
776
|
+
if (!sawEnd) throw new Error("Archive is missing its end marker.");
|
|
777
|
+
return entries;
|
|
778
|
+
}
|
|
779
|
+
function extractPackageMetadata(bytes, release) {
|
|
780
|
+
const entries = parseTarEntries(bytes);
|
|
781
|
+
const packageBytes = entries.get("package/package.json");
|
|
782
|
+
if (!packageBytes) throw new Error("Release artifact is missing package/package.json.");
|
|
783
|
+
const descriptorBytes = entries.get("package/dist/joycraft-release.json");
|
|
784
|
+
if (!descriptorBytes) throw new Error("Release artifact is missing package/dist/joycraft-release.json.");
|
|
785
|
+
const packageJson = objectRecord(parseJson(packageBytes, "Package metadata"), "Package metadata");
|
|
786
|
+
if (packageJson.name !== release.packageName || packageJson.version !== release.version) throw new Error("Package metadata name/version does not match the exact release.");
|
|
787
|
+
const descriptor = parseReleaseDescriptor(descriptorBytes, release.version);
|
|
788
|
+
if (descriptor.releaseVersion !== packageJson.version) throw new Error("Release descriptor version does not match package metadata.");
|
|
789
|
+
return { packageJson: Object.freeze({ ...packageJson }), descriptor };
|
|
790
|
+
}
|
|
791
|
+
var VerifiedReleaseArtifactImpl = class {
|
|
792
|
+
release;
|
|
793
|
+
descriptor;
|
|
794
|
+
#bytes;
|
|
795
|
+
constructor(release, descriptor, bytes) {
|
|
796
|
+
this.release = release;
|
|
797
|
+
this.descriptor = descriptor;
|
|
798
|
+
this.#bytes = Buffer.from(bytes);
|
|
799
|
+
verifiedArtifacts.add(this);
|
|
800
|
+
Object.freeze(this);
|
|
801
|
+
}
|
|
802
|
+
get tarball() {
|
|
803
|
+
return new Uint8Array(this.#bytes);
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
function verifyReleaseArtifact(release, tarball) {
|
|
807
|
+
const exactRelease = cloneRelease(release);
|
|
808
|
+
if (!(tarball instanceof Uint8Array) || tarball.byteLength === 0) throw new Error("Release artifact bytes are required.");
|
|
809
|
+
const actual = createHash("sha512").update(Buffer.from(tarball)).digest("base64");
|
|
810
|
+
if (`sha512-${actual}` !== exactRelease.integrity) throw new Error("Release artifact integrity does not match exact registry metadata.");
|
|
811
|
+
const { descriptor } = extractPackageMetadata(tarball, exactRelease);
|
|
812
|
+
return new VerifiedReleaseArtifactImpl(exactRelease, descriptor, tarball);
|
|
813
|
+
}
|
|
814
|
+
function isVerifiedReleaseArtifact(value) {
|
|
815
|
+
return typeof value === "object" && value !== null && verifiedArtifacts.has(value);
|
|
816
|
+
}
|
|
817
|
+
async function responseBytes(value, maxBytes) {
|
|
818
|
+
if (value instanceof Uint8Array) {
|
|
819
|
+
if (value.byteLength > maxBytes) throw new Error("Release tarball exceeds the download limit.");
|
|
820
|
+
return Buffer.from(value);
|
|
821
|
+
}
|
|
822
|
+
if (value instanceof ArrayBuffer) {
|
|
823
|
+
if (value.byteLength > maxBytes) throw new Error("Release tarball exceeds the download limit.");
|
|
824
|
+
return new Uint8Array(value);
|
|
825
|
+
}
|
|
826
|
+
const response = value;
|
|
827
|
+
if (response?.ok === false) throw new Error(`Release tarball request failed with HTTP ${String(response.status ?? "unknown")}.`);
|
|
828
|
+
if (response?.body?.getReader) {
|
|
829
|
+
const reader = response.body.getReader();
|
|
830
|
+
const chunks = [];
|
|
831
|
+
let total = 0;
|
|
832
|
+
try {
|
|
833
|
+
while (true) {
|
|
834
|
+
const result = await reader.read();
|
|
835
|
+
if (result.done) break;
|
|
836
|
+
const chunk = result.value;
|
|
837
|
+
total += chunk.byteLength;
|
|
838
|
+
if (total > maxBytes) throw new Error("Release tarball exceeds the download limit.");
|
|
839
|
+
chunks.push(chunk);
|
|
840
|
+
}
|
|
841
|
+
} finally {
|
|
842
|
+
reader.releaseLock();
|
|
843
|
+
}
|
|
844
|
+
return Buffer.concat(chunks.map((chunk) => Buffer.from(chunk)));
|
|
845
|
+
}
|
|
846
|
+
if (typeof response?.arrayBuffer === "function") {
|
|
847
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
848
|
+
if (bytes.byteLength > maxBytes) throw new Error("Release tarball exceeds the download limit.");
|
|
849
|
+
return bytes;
|
|
850
|
+
}
|
|
851
|
+
throw new Error("Release tarball response did not contain bytes.");
|
|
852
|
+
}
|
|
853
|
+
async function fetchVerifiedReleaseArtifact(release, options = {}) {
|
|
854
|
+
const maxBytes = options.maxBytes ?? MAX_COMPRESSED_BYTES;
|
|
855
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes <= 0 || maxBytes > MAX_COMPRESSED_BYTES) throw new Error("Artifact download limit is invalid.");
|
|
856
|
+
const timeoutMs = options.timeoutMs ?? 3e3;
|
|
857
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0) throw new Error("Artifact download timeout is invalid.");
|
|
858
|
+
const exactRelease = cloneRelease(release);
|
|
859
|
+
const fetchTarball = options.fetchTarball ?? (async (url, init) => fetch(url, init));
|
|
860
|
+
const controller = new AbortController();
|
|
861
|
+
let timer;
|
|
862
|
+
const deadline = new Promise((_, reject) => {
|
|
863
|
+
timer = setTimeout(() => {
|
|
864
|
+
controller.abort();
|
|
865
|
+
reject(new Error("Release tarball download timed out."));
|
|
866
|
+
}, timeoutMs);
|
|
867
|
+
});
|
|
868
|
+
const operation = (async () => {
|
|
869
|
+
const response = await fetchTarball(exactRelease.tarballUrl, { signal: controller.signal });
|
|
870
|
+
return responseBytes(response, maxBytes);
|
|
871
|
+
})();
|
|
872
|
+
void operation.catch(() => void 0);
|
|
873
|
+
try {
|
|
874
|
+
const bytes = await Promise.race([operation, deadline]);
|
|
875
|
+
return verifyReleaseArtifact(exactRelease, bytes);
|
|
876
|
+
} finally {
|
|
877
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
878
|
+
controller.abort();
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
// src/auto-safe-update.ts
|
|
883
|
+
function object2(value) {
|
|
884
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
885
|
+
}
|
|
886
|
+
function descriptorEqual(left, right) {
|
|
887
|
+
const a = object2(left);
|
|
888
|
+
const b = object2(right);
|
|
889
|
+
if (!a || !b) return false;
|
|
890
|
+
return a.schemaVersion === b.schemaVersion && a.releaseVersion === b.releaseVersion && a.autoSafeEligible === b.autoSafeEligible && Array.isArray(a.manifestSchemas) && Array.isArray(b.manifestSchemas) && JSON.stringify(a.manifestSchemas) === JSON.stringify(b.manifestSchemas);
|
|
891
|
+
}
|
|
892
|
+
function evaluateAutoSafeEligibility(input) {
|
|
893
|
+
const diagnostics = [];
|
|
894
|
+
const reject = (message) => {
|
|
895
|
+
diagnostics.push(message);
|
|
896
|
+
};
|
|
897
|
+
if (input.policy !== "auto-safe") reject("Automatic updates require the local auto-safe policy.");
|
|
898
|
+
const candidate = input.candidate;
|
|
899
|
+
if (!candidate || !isVerifiedReleaseArtifact(candidate)) {
|
|
900
|
+
reject("Automatic updates require a verifier-issued exact release artifact.");
|
|
901
|
+
}
|
|
902
|
+
const release = candidate?.release;
|
|
903
|
+
const descriptor = candidate?.descriptor;
|
|
904
|
+
const descriptorObject = object2(descriptor);
|
|
905
|
+
if (candidate && release && release.packageName !== "joycraft") reject("The verified artifact package is not Joycraft.");
|
|
906
|
+
if (candidate && release && release.version !== input.executingVersion) {
|
|
907
|
+
reject("The verified artifact version does not match the executing bundle.");
|
|
908
|
+
}
|
|
909
|
+
if (candidate && input.executingIntegrity !== void 0 && release && release.integrity !== input.executingIntegrity) {
|
|
910
|
+
reject("The verified artifact integrity does not match the executing bundle.");
|
|
911
|
+
}
|
|
912
|
+
if (input.executingDescriptor === void 0) reject("The executing bundle has no verified compatibility descriptor.");
|
|
913
|
+
else if (candidate && !descriptorEqual(descriptor, input.executingDescriptor)) {
|
|
914
|
+
reject("The verified compatibility descriptor does not match the executing bundle.");
|
|
915
|
+
}
|
|
916
|
+
if (!descriptorObject || descriptorObject.schemaVersion !== 1 || descriptorObject.releaseVersion !== release?.version) {
|
|
917
|
+
reject("The verified artifact has no supported compatibility descriptor.");
|
|
918
|
+
}
|
|
919
|
+
if (descriptorObject?.autoSafeEligible !== true) reject("The release is not declared eligible for auto-safe updates.");
|
|
920
|
+
const supportedSchemas = descriptorObject?.manifestSchemas;
|
|
921
|
+
const schema = input.manifestSchema ?? input.plan.nextManifest.schemaVersion;
|
|
922
|
+
if (!Array.isArray(supportedSchemas) || !supportedSchemas.includes(schema)) reject("The release does not support this manifest protocol.");
|
|
923
|
+
if (!/^(\d+)\.(\d+)\.(\d+)$/.test(input.executingVersion) || !release?.version || !/^(\d+)\.(\d+)\.(\d+)$/.test(release.version)) {
|
|
924
|
+
reject("Prerelease and malformed releases require an explicit update.");
|
|
925
|
+
} else if (compareStableVersions(release.version, input.executingVersion) !== 0) {
|
|
926
|
+
reject("Downgrades and version changes require an explicit update.");
|
|
927
|
+
}
|
|
928
|
+
if (!input.existingManifest) reject("Automatic updates require an existing installation manifest.");
|
|
929
|
+
else if (compareStableVersions(release?.version ?? "", input.existingManifest.targetVersion) !== 1) {
|
|
930
|
+
reject("The candidate is not newer than the installed release; use an explicit update.");
|
|
931
|
+
}
|
|
932
|
+
if (input.plan.conflicts.length > 0) reject("The update plan contains unresolved conflicts.");
|
|
933
|
+
if (input.plan.actions.some((action) => action.kind === "conflict" || action.kind === "repair")) {
|
|
934
|
+
reject("The update plan contains a conflict or repair action.");
|
|
935
|
+
}
|
|
936
|
+
if (input.plan.actions.some((action) => action.selected && (action.patch !== void 0 || action.path === ".claude/settings.json") && !(action.currentPresent && action.targetPresent && typeof action.rawPrecondition === "string" && action.rawPrecondition === action.rawTargetHash))) {
|
|
937
|
+
reject("The update plan changes user configuration.");
|
|
938
|
+
}
|
|
939
|
+
if ((input.replaceCustomized?.length ?? 0) > 0) reject("Customized replacements require an explicit update.");
|
|
940
|
+
if ((input.repair?.length ?? 0) > 0) reject("Repairs require an explicit update.");
|
|
941
|
+
if (input.migration) reject("Migrations require an explicit update.");
|
|
942
|
+
if (input.legacyBridge) reject("Legacy bridge adoption requires an explicit update.");
|
|
943
|
+
if (input.setupChanges) reject("Setup and user-configuration changes require an explicit update.");
|
|
944
|
+
if (input.profileChanges) reject("Profile changes require an explicit update.");
|
|
945
|
+
if (input.localOperations) reject("Local state migrations require an explicit update.");
|
|
946
|
+
if (input.authorityTransition) reject("Manifest authority transitions require an explicit update.");
|
|
947
|
+
return { eligible: diagnostics.length === 0, diagnostics };
|
|
948
|
+
}
|
|
278
949
|
export {
|
|
279
|
-
|
|
950
|
+
CHECK_CACHE_PATH,
|
|
951
|
+
CHECK_CACHE_TTL_MS,
|
|
952
|
+
CHECK_DEFAULT_DEADLINE_MS,
|
|
953
|
+
CHECK_LOCK_PATH,
|
|
954
|
+
CHECK_LOCK_TTL_MS,
|
|
955
|
+
CHECK_SETTINGS_PATH,
|
|
956
|
+
acknowledgeUpdate,
|
|
957
|
+
checkForUpdate,
|
|
958
|
+
compareStableVersions,
|
|
959
|
+
detectStack,
|
|
960
|
+
evaluateAutoSafeEligibility,
|
|
961
|
+
fetchVerifiedReleaseArtifact,
|
|
962
|
+
isVerifiedReleaseArtifact,
|
|
963
|
+
parseReleaseDescriptor,
|
|
964
|
+
postponeUpdate,
|
|
965
|
+
readUpdatePolicy,
|
|
966
|
+
resolveCheckSessionId,
|
|
967
|
+
resolveUpdateStatus,
|
|
968
|
+
setUpdatePolicy,
|
|
969
|
+
verifyReleaseArtifact
|
|
280
970
|
};
|
|
281
971
|
//# sourceMappingURL=index.js.map
|