@camstack/agent 1.1.58 → 1.1.59

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/index.mjs CHANGED
@@ -5,8 +5,8 @@ import {
5
5
  loadAgentConfig,
6
6
  startAgent,
7
7
  startAgentHttpServer
8
- } from "./chunk-2P5A5KTL.mjs";
9
- import "./chunk-DIBZT6GT.mjs";
8
+ } from "./chunk-54PFYHKN.mjs";
9
+ import "./chunk-ADZNLSIO.mjs";
10
10
  export {
11
11
  createAgentHttpServer,
12
12
  createAgentService,
package/dist/starter.js CHANGED
@@ -313,6 +313,33 @@ var require_dist = __commonJS({
313
313
  }
314
314
  var fs3 = __toESM2(require("fs"));
315
315
  var path3 = __toESM2(require("path"));
316
+ function parse(version) {
317
+ const dashIdx = version.indexOf("-");
318
+ const base = dashIdx === -1 ? version : version.slice(0, dashIdx);
319
+ const prerelease = dashIdx === -1 ? null : version.slice(dashIdx + 1);
320
+ const nums = base.split(".").map((seg) => {
321
+ const n = Number.parseInt(seg, 10);
322
+ return Number.isNaN(n) ? 0 : n;
323
+ });
324
+ return { nums, prerelease };
325
+ }
326
+ function compareSemver(a, b) {
327
+ const pa = parse(a);
328
+ const pb = parse(b);
329
+ const len = Math.max(pa.nums.length, pb.nums.length);
330
+ for (let i = 0; i < len; i++) {
331
+ const na = pa.nums[i] ?? 0;
332
+ const nb = pb.nums[i] ?? 0;
333
+ if (na < nb) return -1;
334
+ if (na > nb) return 1;
335
+ }
336
+ if (pa.prerelease === null && pb.prerelease === null) return 0;
337
+ if (pa.prerelease === null) return 1;
338
+ if (pb.prerelease === null) return -1;
339
+ if (pa.prerelease < pb.prerelease) return -1;
340
+ if (pa.prerelease > pb.prerelease) return 1;
341
+ return 0;
342
+ }
316
343
  var CURRENT_DIRNAME = "current";
317
344
  var PENDING_ROOT_SWAP_FILE = ".pending-root-swap.json";
318
345
  var LEGACY_FRAMEWORK_MARKERS = [
@@ -454,13 +481,41 @@ var require_dist = __commonJS({
454
481
  log(`[single-copy] applied staged root swap \u2192 ${marker.version}`);
455
482
  return { applied: true, version: marker.version, reason: "applied" };
456
483
  }
484
+ function readClosureVersion(closureDir, spec) {
485
+ try {
486
+ const raw = JSON.parse(
487
+ fs3.readFileSync(path3.join(rootPackageDir(closureDir, spec), "package.json"), "utf-8")
488
+ );
489
+ if (typeof raw === "object" && raw !== null) {
490
+ const version = raw["version"];
491
+ if (typeof version === "string") return version;
492
+ }
493
+ } catch {
494
+ }
495
+ return null;
496
+ }
497
+ function isAdoptablePendingClosure(rootDir, version, nodeMajor, spec) {
498
+ const dir = versionDir(rootDir, version);
499
+ return validateClosureDir(dir, nodeMajor, spec, version) === null && findMissingNativePrebuilds(dir).length === 0;
500
+ }
457
501
  function migrateToSingleCopy(rootDir, spec, nodeMajor, now, log) {
458
502
  const dest = currentDir(rootDir);
459
- if (fs3.existsSync(dest) && validateClosureDir(dest, nodeMajor, spec) === null) {
460
- return { migrated: false, version: null, reason: "current already present" };
503
+ const legacyState = readServerRootState(rootDir);
504
+ const pendingVersion = legacyState?.pendingBoot?.version ?? null;
505
+ const pendingAdoptable = pendingVersion !== null && isAdoptablePendingClosure(rootDir, pendingVersion, nodeMajor, spec);
506
+ const currentValid = fs3.existsSync(dest) && validateClosureDir(dest, nodeMajor, spec) === null;
507
+ if (currentValid) {
508
+ const currentVersion = readClosureVersion(dest, spec);
509
+ const pendingSupersedes = pendingAdoptable && pendingVersion !== null && (currentVersion === null || compareSemver(pendingVersion, currentVersion) > 0);
510
+ if (!pendingSupersedes) {
511
+ return { migrated: false, version: null, reason: "current already present" };
512
+ }
513
+ log(
514
+ `[single-copy] in-flight pending ${pendingVersion} supersedes older current ${currentVersion ?? "?"}`
515
+ );
461
516
  }
462
517
  const candidates = [];
463
- const legacyState = readServerRootState(rootDir);
518
+ if (pendingAdoptable && pendingVersion !== null) candidates.push(pendingVersion);
464
519
  if (legacyState !== null) {
465
520
  for (const v of [
466
521
  legacyState.currentVersion,
@@ -527,33 +582,6 @@ var require_dist = __commonJS({
527
582
  }
528
583
  return { kind: "baked", reason: "no valid single-copy closure \u2014 booting the baked seed" };
529
584
  }
530
- function parse(version) {
531
- const dashIdx = version.indexOf("-");
532
- const base = dashIdx === -1 ? version : version.slice(0, dashIdx);
533
- const prerelease = dashIdx === -1 ? null : version.slice(dashIdx + 1);
534
- const nums = base.split(".").map((seg) => {
535
- const n = Number.parseInt(seg, 10);
536
- return Number.isNaN(n) ? 0 : n;
537
- });
538
- return { nums, prerelease };
539
- }
540
- function compareSemver(a, b) {
541
- const pa = parse(a);
542
- const pb = parse(b);
543
- const len = Math.max(pa.nums.length, pb.nums.length);
544
- for (let i = 0; i < len; i++) {
545
- const na = pa.nums[i] ?? 0;
546
- const nb = pb.nums[i] ?? 0;
547
- if (na < nb) return -1;
548
- if (na > nb) return 1;
549
- }
550
- if (pa.prerelease === null && pb.prerelease === null) return 0;
551
- if (pa.prerelease === null) return 1;
552
- if (pb.prerelease === null) return -1;
553
- if (pa.prerelease < pb.prerelease) return -1;
554
- if (pa.prerelease > pb.prerelease) return 1;
555
- return 0;
556
- }
557
585
  var fs4 = __toESM2(require("fs"));
558
586
  var path4 = __toESM2(require("path"));
559
587
  function detectWorkspaceRoot(fromDir) {
@@ -616,7 +644,7 @@ var require_dist = __commonJS({
616
644
  };
617
645
  registerHooks(hooks);
618
646
  }
619
- function readClosureVersion(closureDir, spec) {
647
+ function readClosureVersion2(closureDir, spec) {
620
648
  try {
621
649
  const raw = JSON.parse(
622
650
  fs5.readFileSync(path5.join(rootPackageDir(closureDir, spec), "package.json"), "utf-8")
@@ -671,7 +699,7 @@ var require_dist = __commonJS({
671
699
  }
672
700
  const plan = planBoot(invalid === null);
673
701
  if (plan.kind === "current") {
674
- const version = readClosureVersion(activeRootDir, options.spec);
702
+ const version = readClosureVersion2(activeRootDir, options.spec);
675
703
  const entry = currentEntryPath(rootDir, options.spec);
676
704
  console.log(
677
705
  `[starter] booting ${options.spec.packageName}@${version ?? "?"} from ${activeRootDir}`