@forgezero/agent 0.1.114 → 0.1.116

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/fz-agent.js CHANGED
@@ -5568,6 +5568,7 @@ function validateCapacityCalibrationOptions(options) {
5568
5568
  const endpoint = localCalibrationEndpoint(options.endpoint);
5569
5569
  const maxConcurrency = options.maxConcurrency ?? 256;
5570
5570
  const requestsPerWorker = options.requestsPerWorker ?? 8;
5571
+ const maximumRequestsPerWorker = options.maximumRequestsPerWorker ?? 100;
5571
5572
  const maxP95Ms = options.maxP95Ms ?? 250;
5572
5573
  const maxErrorRate = options.maxErrorRate ?? 0.01;
5573
5574
  const safetyRatio = options.safetyRatio ?? 0.8;
@@ -5575,13 +5576,14 @@ function validateCapacityCalibrationOptions(options) {
5575
5576
  const minimumStageDurationMs = options.minimumStageDurationMs ?? 5000;
5576
5577
  const maxCpuUtilizationPercent = options.maxCpuUtilizationPercent ?? 90;
5577
5578
  const maxMemoryUtilizationPercent = options.maxMemoryUtilizationPercent ?? 90;
5578
- if (!Number.isSafeInteger(maxConcurrency) || maxConcurrency < 1 || maxConcurrency > 4096 || !Number.isSafeInteger(requestsPerWorker) || requestsPerWorker < 2 || requestsPerWorker > 100 || !Number.isFinite(maxP95Ms) || maxP95Ms < 1 || !Number.isFinite(maxErrorRate) || maxErrorRate < 0 || maxErrorRate > 0.2 || !Number.isFinite(safetyRatio) || safetyRatio < 0.25 || safetyRatio > 0.95 || !Number.isSafeInteger(requestTimeoutMs) || requestTimeoutMs < 100 || requestTimeoutMs > 30000 || !Number.isSafeInteger(minimumStageDurationMs) || minimumStageDurationMs < 100 || minimumStageDurationMs > 60000 || !Number.isFinite(maxCpuUtilizationPercent) || maxCpuUtilizationPercent < 25 || maxCpuUtilizationPercent > 100 || !Number.isFinite(maxMemoryUtilizationPercent) || maxMemoryUtilizationPercent < 25 || maxMemoryUtilizationPercent > 100) {
5579
+ if (!Number.isSafeInteger(maxConcurrency) || maxConcurrency < 1 || maxConcurrency > 4096 || !Number.isSafeInteger(requestsPerWorker) || requestsPerWorker < 2 || requestsPerWorker > 100 || !Number.isSafeInteger(maximumRequestsPerWorker) || maximumRequestsPerWorker < requestsPerWorker || maximumRequestsPerWorker > 100 || !Number.isFinite(maxP95Ms) || maxP95Ms < 1 || !Number.isFinite(maxErrorRate) || maxErrorRate < 0 || maxErrorRate > 0.2 || !Number.isFinite(safetyRatio) || safetyRatio < 0.25 || safetyRatio > 0.95 || !Number.isSafeInteger(requestTimeoutMs) || requestTimeoutMs < 100 || requestTimeoutMs > 30000 || !Number.isSafeInteger(minimumStageDurationMs) || minimumStageDurationMs < 100 || minimumStageDurationMs > 60000 || !Number.isFinite(maxCpuUtilizationPercent) || maxCpuUtilizationPercent < 25 || maxCpuUtilizationPercent > 100 || !Number.isFinite(maxMemoryUtilizationPercent) || maxMemoryUtilizationPercent < 25 || maxMemoryUtilizationPercent > 100) {
5579
5580
  throw new Error("Capacity calibration bounds are invalid.");
5580
5581
  }
5581
5582
  return {
5582
5583
  endpoint,
5583
5584
  maxConcurrency,
5584
5585
  requestsPerWorker,
5586
+ maximumRequestsPerWorker,
5585
5587
  maxP95Ms,
5586
5588
  maxErrorRate,
5587
5589
  safetyRatio,
@@ -5591,7 +5593,7 @@ function validateCapacityCalibrationOptions(options) {
5591
5593
  maxMemoryUtilizationPercent
5592
5594
  };
5593
5595
  }
5594
- async function stage(endpoint, concurrency, requestsPerWorker, timeoutMs, minimumDurationMs, fetcher, sampler) {
5596
+ async function stage(endpoint, concurrency, requestsPerWorker, maximumRequestsPerWorker, timeoutMs, minimumDurationMs, fetcher, sampler) {
5595
5597
  const latencies = [];
5596
5598
  let succeeded = 0;
5597
5599
  let failed = 0;
@@ -5600,7 +5602,7 @@ async function stage(endpoint, concurrency, requestsPerWorker, timeoutMs, minimu
5600
5602
  const started = performance.now();
5601
5603
  await Promise.all(Array.from({ length: concurrency }, async () => {
5602
5604
  let request = 0;
5603
- while (request < requestsPerWorker || performance.now() - started < minimumDurationMs) {
5605
+ while (request < maximumRequestsPerWorker && (request < requestsPerWorker || performance.now() - started < minimumDurationMs)) {
5604
5606
  request += 1;
5605
5607
  const requestStarted = performance.now();
5606
5608
  try {
@@ -5659,6 +5661,7 @@ async function calibrateHttpConcurrency(options, fetcher = fetch, sampler = host
5659
5661
  safetyRatio,
5660
5662
  requestTimeoutMs: timeoutMs,
5661
5663
  minimumStageDurationMs,
5664
+ maximumRequestsPerWorker,
5662
5665
  maxCpuUtilizationPercent,
5663
5666
  maxMemoryUtilizationPercent
5664
5667
  } = validateCapacityCalibrationOptions(options);
@@ -5666,7 +5669,7 @@ async function calibrateHttpConcurrency(options, fetcher = fetch, sampler = host
5666
5669
  let lastSafe;
5667
5670
  let stopReason = "maximum-tested";
5668
5671
  for (let concurrency = 1;; concurrency = Math.min(maxConcurrency, concurrency * 2)) {
5669
- const measured = await stage(endpoint, concurrency, requestsPerWorker, timeoutMs, minimumStageDurationMs, fetcher, sampler);
5672
+ const measured = await stage(endpoint, concurrency, requestsPerWorker, maximumRequestsPerWorker, timeoutMs, minimumStageDurationMs, fetcher, sampler);
5670
5673
  stages.push(measured);
5671
5674
  const previous = stages.at(-2);
5672
5675
  const throughputRegressed = Boolean(previous && concurrency > 1 && measured.successfulRequestsPerSecond < previous.successfulRequestsPerSecond * 0.9);
@@ -5767,6 +5770,7 @@ function capacityCalibration(value, where) {
5767
5770
  "endpoint",
5768
5771
  "maxConcurrency",
5769
5772
  "requestsPerWorker",
5773
+ "maximumRequestsPerWorker",
5770
5774
  "maxP95Ms",
5771
5775
  "maxErrorRate",
5772
5776
  "safetyRatio",
@@ -5795,6 +5799,7 @@ function capacityCalibration(value, where) {
5795
5799
  ...Object.fromEntries([
5796
5800
  "maxConcurrency",
5797
5801
  "requestsPerWorker",
5802
+ "maximumRequestsPerWorker",
5798
5803
  "maxP95Ms",
5799
5804
  "maxErrorRate",
5800
5805
  "safetyRatio",
@@ -6730,7 +6735,7 @@ function validateComponent(value, where, targets, requirements) {
6730
6735
  const row2 = object(value, where);
6731
6736
  const selectedTarget = targets.get(String(row2.target)) ?? fail(`${where}.target`, "must name an existing target.");
6732
6737
  if (row2.kind === "application") {
6733
- exact3(row2, ["kind", "target", "runtime", "service", "resources", "storage", "network", "rollout"], where);
6738
+ exact3(row2, ["kind", "target", "runtime", "service", "capacityCalibration", "resources", "storage", "network", "rollout"], where);
6734
6739
  const runtime = object(row2.runtime, `${where}.runtime`);
6735
6740
  const runtimeRequirement = requirements.get(String(runtime.requirement));
6736
6741
  if (!runtimeRequirement)
@@ -6812,6 +6817,33 @@ function validateComponent(value, where, targets, requirements) {
6812
6817
  fail(`${where}.service.websocket`, "must be a boolean.");
6813
6818
  if (service.maximumConnections !== undefined)
6814
6819
  integer(service.maximumConnections, `${where}.service.maximumConnections`, 1, 1e7);
6820
+ if (row2.capacityCalibration !== undefined) {
6821
+ const calibration = object(row2.capacityCalibration, `${where}.capacityCalibration`);
6822
+ exact3(calibration, [
6823
+ "path",
6824
+ "maxConcurrency",
6825
+ "requestsPerWorker",
6826
+ "maximumRequestsPerWorker",
6827
+ "maxP95Ms",
6828
+ "maxErrorRate",
6829
+ "safetyRatio",
6830
+ "requestTimeoutMs",
6831
+ "minimumStageDurationMs",
6832
+ "maxCpuUtilizationPercent",
6833
+ "maxMemoryUtilizationPercent"
6834
+ ], `${where}.capacityCalibration`);
6835
+ if (typeof calibration.path !== "string" || !HEALTH_PATH.test(calibration.path) || calibration.path.includes("..") || calibration.path.includes("//")) {
6836
+ fail(`${where}.capacityCalibration.path`, "must be one bounded absolute loopback path.");
6837
+ }
6838
+ try {
6839
+ validateCapacityCalibrationOptions({
6840
+ ...calibration,
6841
+ endpoint: `http://127.0.0.1:${String(service.port)}${calibration.path}`
6842
+ });
6843
+ } catch {
6844
+ fail(`${where}.capacityCalibration`, "contains invalid bounds.");
6845
+ }
6846
+ }
6815
6847
  validateResources(row2.resources, `${where}.resources`);
6816
6848
  if (runtime.kind === "container") {
6817
6849
  const resources = object(row2.resources, `${where}.resources`);
@@ -7274,6 +7306,15 @@ function compileDeployment(sourceValue) {
7274
7306
  named(componentName, "deployment.spec.components key");
7275
7307
  validateComponent(value, `deployment.spec.components.${componentName}`, targetDefinitions, requirementDefinitions);
7276
7308
  }
7309
+ for (const targetName of targetNames) {
7310
+ const calibrated = componentEntries.filter(([, component2]) => {
7311
+ const candidate = component2;
7312
+ return candidate.kind === "application" && candidate.target === targetName && candidate.capacityCalibration !== undefined;
7313
+ });
7314
+ if (calibrated.length > 1) {
7315
+ fail(`deployment.spec.components`, `may calibrate at most one application on target ${targetName}.`);
7316
+ }
7317
+ }
7277
7318
  for (const [targetName, target] of targetDefinitions) {
7278
7319
  if (target.connectivity?.public?.mode !== "cloudflare-tunnel")
7279
7320
  continue;
@@ -8340,14 +8381,14 @@ function createDeploymentManager(options) {
8340
8381
  } : {}
8341
8382
  });
8342
8383
  for (const targetName of targetNames) {
8343
- const capacity2 = resolvedTargets.find(({ name }) => name === targetName)?.allocation.resources;
8344
- if (!capacity2)
8384
+ const capacity3 = resolvedTargets.find(({ name }) => name === targetName)?.allocation.resources;
8385
+ if (!capacity3)
8345
8386
  throw new DeploymentError("PIPELINE_FAILED", `target ${targetName} has no resolved capacity`);
8346
8387
  const components = Object.values(plan.spec.components).filter(({ target }) => target === targetName);
8347
8388
  const cpu = components.reduce((sum, component2) => sum + (component2.resources?.cpu?.limit ?? 0), 0);
8348
8389
  const memoryMiB = components.reduce((sum, component2) => sum + (component2.resources?.memory?.limitMiB ?? 0), 0);
8349
8390
  const ephemeralMiB = components.reduce((sum, component2) => sum + (component2.kind === "application" ? (component2.storage ?? []).reduce((storage, mount) => storage + (mount.class === "ephemeral" ? mount.sizeMiB : 0), 0) : 0), 0);
8350
- if (cpu > capacity2.cpuCores || memoryMiB > capacity2.memoryMiB || ephemeralMiB > capacity2.storageGiB * 1024) {
8391
+ if (cpu > capacity3.cpuCores || memoryMiB > capacity3.memoryMiB || ephemeralMiB > capacity3.storageGiB * 1024) {
8351
8392
  throw new DeploymentError("PIPELINE_FAILED", `component limits exceed the reserved capacity of target ${targetName}`);
8352
8393
  }
8353
8394
  }
@@ -8592,6 +8633,37 @@ function createDeploymentManager(options) {
8592
8633
  const failed = run2.steps.find((step2) => step2.status === "failed" || step2.status === "manual-intervention");
8593
8634
  throw new DeploymentError("PIPELINE_FAILED", `deployment plan failed at ${failed?.id ?? "unknown step"}: ${failed?.error?.message ?? run2.status}`, deploymentExecution([phase]));
8594
8635
  }
8636
+ const executionTarget = assigned?.targetName ?? matchingTargetNames[0];
8637
+ const calibratedApplication = Object.values(plan.spec.components).find((component2) => component2.kind === "application" && component2.target === executionTarget && component2.capacityCalibration !== undefined);
8638
+ let capacity2;
8639
+ if (calibratedApplication?.kind === "application" && calibratedApplication.capacityCalibration) {
8640
+ if (!options.capacityEvidenceDirectory) {
8641
+ throw new DeploymentError("PIPELINE_FAILED", "capacity calibration was requested but the Agent has no evidence directory");
8642
+ }
8643
+ const { path: path2, ...bounds } = calibratedApplication.capacityCalibration;
8644
+ const calibration = await (options.calibrateCapacity ?? calibrateHttpConcurrency)({
8645
+ ...bounds,
8646
+ endpoint: `http://127.0.0.1:${calibratedApplication.service.port}${path2}`
8647
+ });
8648
+ const measuredAtTs = now();
8649
+ const evidencePath = persistCapacityCalibration({
8650
+ directory: options.capacityEvidenceDirectory,
8651
+ deploymentKey: options.key,
8652
+ revision: head,
8653
+ definitionDigest: plan.sourceDigest,
8654
+ profile: options.profile,
8655
+ measuredAtTs,
8656
+ calibration
8657
+ });
8658
+ capacity2 = {
8659
+ ...calibration,
8660
+ evidencePath,
8661
+ recommendedCoordinate: {
8662
+ FZ_REQUESTS_PER_SECOND_LIMIT: String(calibration.allowedRequestsPerSecond),
8663
+ FZ_CONCURRENCY_LIMIT: String(calibration.recommendedConcurrency)
8664
+ }
8665
+ };
8666
+ }
8595
8667
  return {
8596
8668
  key: options.key,
8597
8669
  repository: options.repository,
@@ -8604,7 +8676,8 @@ function createDeploymentManager(options) {
8604
8676
  ok: true,
8605
8677
  phases: [phase],
8606
8678
  execution: deploymentExecution([phase]),
8607
- resolvedTargets
8679
+ resolvedTargets,
8680
+ ...capacity2 ? { capacity: capacity2 } : {}
8608
8681
  };
8609
8682
  }
8610
8683
  const definition = parseDeployDefinition(readDefinition(join2(release, ".fz", "deploy.json")));
@@ -9528,7 +9601,7 @@ async function writeAndCloseProcessInput(input, value) {
9528
9601
  }
9529
9602
 
9530
9603
  // src/version.ts
9531
- var VERSION2 = "0.1.114";
9604
+ var VERSION2 = "0.1.116";
9532
9605
 
9533
9606
  // src/ssh-bootstrap.ts
9534
9607
  class SshBootstrapError extends Error {
package/dist/fz.js CHANGED
@@ -4841,7 +4841,7 @@ var UPDATE_RETRY_BASE_MS = 5 * 60000;
4841
4841
  var UPDATE_RETRY_MAX_MS = 24 * 60 * 60000;
4842
4842
 
4843
4843
  // src/version.ts
4844
- var VERSION2 = "0.1.114";
4844
+ var VERSION2 = "0.1.116";
4845
4845
 
4846
4846
  // src/software.ts
4847
4847
  var PINNED_BUN_VERSION = "1.3.14";
@@ -4941,6 +4941,7 @@ function validateCapacityCalibrationOptions(options) {
4941
4941
  const endpoint = localCalibrationEndpoint(options.endpoint);
4942
4942
  const maxConcurrency = options.maxConcurrency ?? 256;
4943
4943
  const requestsPerWorker = options.requestsPerWorker ?? 8;
4944
+ const maximumRequestsPerWorker = options.maximumRequestsPerWorker ?? 100;
4944
4945
  const maxP95Ms = options.maxP95Ms ?? 250;
4945
4946
  const maxErrorRate = options.maxErrorRate ?? 0.01;
4946
4947
  const safetyRatio = options.safetyRatio ?? 0.8;
@@ -4948,13 +4949,14 @@ function validateCapacityCalibrationOptions(options) {
4948
4949
  const minimumStageDurationMs = options.minimumStageDurationMs ?? 5000;
4949
4950
  const maxCpuUtilizationPercent = options.maxCpuUtilizationPercent ?? 90;
4950
4951
  const maxMemoryUtilizationPercent = options.maxMemoryUtilizationPercent ?? 90;
4951
- if (!Number.isSafeInteger(maxConcurrency) || maxConcurrency < 1 || maxConcurrency > 4096 || !Number.isSafeInteger(requestsPerWorker) || requestsPerWorker < 2 || requestsPerWorker > 100 || !Number.isFinite(maxP95Ms) || maxP95Ms < 1 || !Number.isFinite(maxErrorRate) || maxErrorRate < 0 || maxErrorRate > 0.2 || !Number.isFinite(safetyRatio) || safetyRatio < 0.25 || safetyRatio > 0.95 || !Number.isSafeInteger(requestTimeoutMs) || requestTimeoutMs < 100 || requestTimeoutMs > 30000 || !Number.isSafeInteger(minimumStageDurationMs) || minimumStageDurationMs < 100 || minimumStageDurationMs > 60000 || !Number.isFinite(maxCpuUtilizationPercent) || maxCpuUtilizationPercent < 25 || maxCpuUtilizationPercent > 100 || !Number.isFinite(maxMemoryUtilizationPercent) || maxMemoryUtilizationPercent < 25 || maxMemoryUtilizationPercent > 100) {
4952
+ if (!Number.isSafeInteger(maxConcurrency) || maxConcurrency < 1 || maxConcurrency > 4096 || !Number.isSafeInteger(requestsPerWorker) || requestsPerWorker < 2 || requestsPerWorker > 100 || !Number.isSafeInteger(maximumRequestsPerWorker) || maximumRequestsPerWorker < requestsPerWorker || maximumRequestsPerWorker > 100 || !Number.isFinite(maxP95Ms) || maxP95Ms < 1 || !Number.isFinite(maxErrorRate) || maxErrorRate < 0 || maxErrorRate > 0.2 || !Number.isFinite(safetyRatio) || safetyRatio < 0.25 || safetyRatio > 0.95 || !Number.isSafeInteger(requestTimeoutMs) || requestTimeoutMs < 100 || requestTimeoutMs > 30000 || !Number.isSafeInteger(minimumStageDurationMs) || minimumStageDurationMs < 100 || minimumStageDurationMs > 60000 || !Number.isFinite(maxCpuUtilizationPercent) || maxCpuUtilizationPercent < 25 || maxCpuUtilizationPercent > 100 || !Number.isFinite(maxMemoryUtilizationPercent) || maxMemoryUtilizationPercent < 25 || maxMemoryUtilizationPercent > 100) {
4952
4953
  throw new Error("Capacity calibration bounds are invalid.");
4953
4954
  }
4954
4955
  return {
4955
4956
  endpoint,
4956
4957
  maxConcurrency,
4957
4958
  requestsPerWorker,
4959
+ maximumRequestsPerWorker,
4958
4960
  maxP95Ms,
4959
4961
  maxErrorRate,
4960
4962
  safetyRatio,
@@ -5034,6 +5036,7 @@ function capacityCalibration(value, where) {
5034
5036
  "endpoint",
5035
5037
  "maxConcurrency",
5036
5038
  "requestsPerWorker",
5039
+ "maximumRequestsPerWorker",
5037
5040
  "maxP95Ms",
5038
5041
  "maxErrorRate",
5039
5042
  "safetyRatio",
@@ -5062,6 +5065,7 @@ function capacityCalibration(value, where) {
5062
5065
  ...Object.fromEntries([
5063
5066
  "maxConcurrency",
5064
5067
  "requestsPerWorker",
5068
+ "maximumRequestsPerWorker",
5065
5069
  "maxP95Ms",
5066
5070
  "maxErrorRate",
5067
5071
  "safetyRatio",
@@ -10920,7 +10924,7 @@ function validateComponent(value, where, targets, requirements) {
10920
10924
  const row2 = object(value, where);
10921
10925
  const selectedTarget = targets.get(String(row2.target)) ?? fail2(`${where}.target`, "must name an existing target.");
10922
10926
  if (row2.kind === "application") {
10923
- exact3(row2, ["kind", "target", "runtime", "service", "resources", "storage", "network", "rollout"], where);
10927
+ exact3(row2, ["kind", "target", "runtime", "service", "capacityCalibration", "resources", "storage", "network", "rollout"], where);
10924
10928
  const runtime = object(row2.runtime, `${where}.runtime`);
10925
10929
  const runtimeRequirement = requirements.get(String(runtime.requirement));
10926
10930
  if (!runtimeRequirement)
@@ -11002,6 +11006,33 @@ function validateComponent(value, where, targets, requirements) {
11002
11006
  fail2(`${where}.service.websocket`, "must be a boolean.");
11003
11007
  if (service.maximumConnections !== undefined)
11004
11008
  integer(service.maximumConnections, `${where}.service.maximumConnections`, 1, 1e7);
11009
+ if (row2.capacityCalibration !== undefined) {
11010
+ const calibration = object(row2.capacityCalibration, `${where}.capacityCalibration`);
11011
+ exact3(calibration, [
11012
+ "path",
11013
+ "maxConcurrency",
11014
+ "requestsPerWorker",
11015
+ "maximumRequestsPerWorker",
11016
+ "maxP95Ms",
11017
+ "maxErrorRate",
11018
+ "safetyRatio",
11019
+ "requestTimeoutMs",
11020
+ "minimumStageDurationMs",
11021
+ "maxCpuUtilizationPercent",
11022
+ "maxMemoryUtilizationPercent"
11023
+ ], `${where}.capacityCalibration`);
11024
+ if (typeof calibration.path !== "string" || !HEALTH_PATH.test(calibration.path) || calibration.path.includes("..") || calibration.path.includes("//")) {
11025
+ fail2(`${where}.capacityCalibration.path`, "must be one bounded absolute loopback path.");
11026
+ }
11027
+ try {
11028
+ validateCapacityCalibrationOptions({
11029
+ ...calibration,
11030
+ endpoint: `http://127.0.0.1:${String(service.port)}${calibration.path}`
11031
+ });
11032
+ } catch {
11033
+ fail2(`${where}.capacityCalibration`, "contains invalid bounds.");
11034
+ }
11035
+ }
11005
11036
  validateResources(row2.resources, `${where}.resources`);
11006
11037
  if (runtime.kind === "container") {
11007
11038
  const resources = object(row2.resources, `${where}.resources`);
@@ -11464,6 +11495,15 @@ function compileDeployment(sourceValue) {
11464
11495
  named(componentName, "deployment.spec.components key");
11465
11496
  validateComponent(value, `deployment.spec.components.${componentName}`, targetDefinitions, requirementDefinitions);
11466
11497
  }
11498
+ for (const targetName of targetNames) {
11499
+ const calibrated = componentEntries.filter(([, component2]) => {
11500
+ const candidate = component2;
11501
+ return candidate.kind === "application" && candidate.target === targetName && candidate.capacityCalibration !== undefined;
11502
+ });
11503
+ if (calibrated.length > 1) {
11504
+ fail2(`deployment.spec.components`, `may calibrate at most one application on target ${targetName}.`);
11505
+ }
11506
+ }
11467
11507
  for (const [targetName, target] of targetDefinitions) {
11468
11508
  if (target.connectivity?.public?.mode !== "cloudflare-tunnel")
11469
11509
  continue;
@@ -12198,6 +12238,9 @@ function platformGenesisClaims(guests, sshPublicKeys) {
12198
12238
  throw new Error("platform genesis requires at least one operator SSH public key");
12199
12239
  return reviewed.map((guest) => claimFor(guest, keys, "create"));
12200
12240
  }
12241
+ function platformGenesisDeletionClaims(guests) {
12242
+ return validatePlatformGenesisGuests(guests).map((guest) => claimFor(guest, [], "delete"));
12243
+ }
12201
12244
  function platformCommunityRehearsalClaims(seedGuests, rehearsalGuest, sshPublicKeys) {
12202
12245
  const reviewed = validatePlatformGenesisGuests([...seedGuests, rehearsalGuest], 4);
12203
12246
  const keys = [...new Set(sshPublicKeys.map(publicKey))];
@@ -17323,14 +17366,14 @@ function planOperatorMetalBootstrap(request, mode) {
17323
17366
  if ((mode === "rehearsal" || mode === "rehearsal-cleanup") && !request.genesis.rehearsalNode) {
17324
17367
  throw new Error("the reviewed metal request has no rehearsal node");
17325
17368
  }
17326
- const claims = mode === "rehearsal" || mode === "rehearsal-cleanup" ? mode === "rehearsal-cleanup" ? platformCommunityRehearsalDeletionClaims(request.genesis.nodes, request.genesis.rehearsalNode) : platformCommunityRehearsalClaims(request.genesis.nodes, request.genesis.rehearsalNode, keys) : platformGenesisClaims(request.genesis.nodes, keys);
17369
+ const claims = mode === "genesis-cleanup" ? platformGenesisDeletionClaims(request.genesis.nodes) : mode === "rehearsal" || mode === "rehearsal-cleanup" ? mode === "rehearsal-cleanup" ? platformCommunityRehearsalDeletionClaims(request.genesis.nodes, request.genesis.rehearsalNode) : platformCommunityRehearsalClaims(request.genesis.nodes, request.genesis.rehearsalNode, keys) : platformGenesisClaims(request.genesis.nodes, keys);
17327
17370
  const genesisNodes = mode === "host-keys" ? request.genesis.nodes.map(({ name }) => name) : mode === "rehearsal-host-keys" ? guestRows(request).map(({ name }) => name) : claims.map((claim) => claim.spec.guestName).filter((name) => Boolean(name));
17328
17371
  return {
17329
17372
  kind: "metal-remote",
17330
17373
  mode,
17331
17374
  mutation: !["status", "host-keys", "rehearsal-host-keys"].includes(mode),
17332
17375
  target: { address: request.target.address, port: request.target.port, user: request.target.user },
17333
- steps: mode === "status" ? ["verify pinned SSH transport", "run typed fz bootstrap status"] : mode === "host-keys" || mode === "rehearsal-host-keys" ? ["verify pinned SSH transport", "collect exact Ed25519 host keys for the reviewed guest addresses"] : mode === "genesis" || mode === "rehearsal" || mode === "rehearsal-cleanup" ? ["verify pinned SSH transport", mode === "rehearsal" ? "send the three reviewed seed claims plus the reviewed fourth Community rehearsal claim to the constrained Metal helper" : mode === "rehearsal-cleanup" ? "delete the exact four reviewed disposable guests and their owned disks, units, seed data and inventory" : "send the three reviewed platform-genesis claims to the constrained Metal helper"] : [
17376
+ steps: mode === "status" ? ["verify pinned SSH transport", "run typed fz bootstrap status"] : mode === "host-keys" || mode === "rehearsal-host-keys" ? ["verify pinned SSH transport", "collect exact Ed25519 host keys for the reviewed guest addresses"] : mode === "genesis" || mode === "genesis-cleanup" || mode === "rehearsal" || mode === "rehearsal-cleanup" ? ["verify pinned SSH transport", mode === "rehearsal" ? "send the three reviewed seed claims plus the reviewed fourth Community rehearsal claim to the constrained Metal helper" : mode === "genesis-cleanup" ? "delete the exact three reviewed platform guests and their owned disks, units, seed data and inventory" : mode === "rehearsal-cleanup" ? "delete the exact four reviewed disposable guests and their owned disks, units, seed data and inventory" : "send the three reviewed platform-genesis claims to the constrained Metal helper"] : [
17334
17377
  "verify pinned SSH transport and caller-approved SSH agent",
17335
17378
  "copy pinned Bun and packaged fz artifacts to private staging",
17336
17379
  "stage the strict owner-only metal config and optional seed handoff",
@@ -17928,13 +17971,13 @@ async function applyOperatorMetalBootstrap(request, mode, options = {}) {
17928
17971
  output: JSON.stringify(await collectOperatorGuestHostKeys(request, { ...options, exec }, mode === "rehearsal-host-keys"))
17929
17972
  };
17930
17973
  }
17931
- if (mode === "genesis" || mode === "rehearsal" || mode === "rehearsal-cleanup") {
17974
+ if (mode === "genesis" || mode === "genesis-cleanup" || mode === "rehearsal" || mode === "rehearsal-cleanup") {
17932
17975
  const keys = request.genesis.sshPublicKeyFiles.map((path) => publicIdentity(path));
17933
17976
  if ((mode === "rehearsal" || mode === "rehearsal-cleanup") && !request.genesis.rehearsalNode) {
17934
17977
  throw new Error("the reviewed metal request has no rehearsal node");
17935
17978
  }
17936
17979
  const outputs = [];
17937
- const claims = mode === "rehearsal" || mode === "rehearsal-cleanup" ? mode === "rehearsal-cleanup" ? platformCommunityRehearsalDeletionClaims(request.genesis.nodes, request.genesis.rehearsalNode) : platformCommunityRehearsalClaims(request.genesis.nodes, request.genesis.rehearsalNode, keys) : platformGenesisClaims(request.genesis.nodes, keys);
17980
+ const claims = mode === "genesis-cleanup" ? platformGenesisDeletionClaims(request.genesis.nodes) : mode === "rehearsal" || mode === "rehearsal-cleanup" ? mode === "rehearsal-cleanup" ? platformCommunityRehearsalDeletionClaims(request.genesis.nodes, request.genesis.rehearsalNode) : platformCommunityRehearsalClaims(request.genesis.nodes, request.genesis.rehearsalNode, keys) : platformGenesisClaims(request.genesis.nodes, keys);
17938
17981
  for (const claim of claims) {
17939
17982
  outputs.push(await remote(exec, request, knownHosts, ["/usr/bin/sudo", "-n", "/usr/local/bin/fz-agent", "metal-apply", "--claim=-"], `provision ${claim.spec.guestName}`, false, `${JSON.stringify(claim)}
17940
17983
  `));
@@ -18838,7 +18881,9 @@ function parseOptions(argv2) {
18838
18881
  options.bootstrapConfigPath = argv2[++index];
18839
18882
  else if (token === "--secrets-env-file")
18840
18883
  options.bootstrapSecretsEnvFile = argv2[++index];
18841
- else if (token === "--output")
18884
+ else if (token.startsWith("--confirm-disposable-fleet=")) {
18885
+ options.disposableFleetConfirmation = token.slice("--confirm-disposable-fleet=".length);
18886
+ } else if (token === "--output")
18842
18887
  options.outputPath = argv2[++index];
18843
18888
  else if (token === "--query")
18844
18889
  options.queries.push(argv2[++index] ?? "");
@@ -20035,8 +20080,8 @@ async function cmdBootstrap(options, args) {
20035
20080
  }
20036
20081
  if (operation === "metal" && args[1] === "remote") {
20037
20082
  const mode = args[2];
20038
- if (!mode || !["apply", "genesis", "rehearsal", "rehearsal-cleanup", "host-keys", "rehearsal-host-keys", "status"].includes(mode) || args[3] !== undefined) {
20039
- throw new Error("Usage: fz bootstrap metal remote <apply|genesis|rehearsal|rehearsal-cleanup|host-keys|rehearsal-host-keys|status> --bootstrap-config <owner-only-request.json> [--output <owner-only-evidence.json>] [--apply]");
20083
+ if (!mode || !["apply", "genesis", "genesis-cleanup", "rehearsal", "rehearsal-cleanup", "host-keys", "rehearsal-host-keys", "status"].includes(mode) || args[3] !== undefined) {
20084
+ throw new Error("Usage: fz bootstrap metal remote <apply|genesis|genesis-cleanup|rehearsal|rehearsal-cleanup|host-keys|rehearsal-host-keys|status> --bootstrap-config <owner-only-request.json> [--output <owner-only-evidence.json>] [--confirm-disposable-fleet=<exact-names>] [--apply]");
20040
20085
  }
20041
20086
  if (!options.bootstrapConfigPath)
20042
20087
  throw new Error("remote metal bootstrap requires --bootstrap-config");
@@ -20047,6 +20092,17 @@ async function cmdBootstrap(options, args) {
20047
20092
  validateMetalConfig: mode === "apply"
20048
20093
  });
20049
20094
  const plan2 = planOperatorMetalBootstrap(request, mode);
20095
+ if (mode === "genesis-cleanup") {
20096
+ const expected = plan2.genesisNodes.join(",");
20097
+ if (!options.apply) {
20098
+ out.line(JSON.stringify({ ...plan2, requiredConfirmation: expected }, null, 2));
20099
+ out.step(`Repeat with --confirm-disposable-fleet=${expected} --apply to delete only this reviewed fleet.`);
20100
+ return 0;
20101
+ }
20102
+ if (options.disposableFleetConfirmation !== expected) {
20103
+ throw new Error(`genesis cleanup requires --confirm-disposable-fleet=${expected}`);
20104
+ }
20105
+ }
20050
20106
  if (!options.apply) {
20051
20107
  out.line(JSON.stringify(plan2, null, 2));
20052
20108
  out.step("Review the pinned metal target and exact genesis nodes, then repeat with --apply to contact the host.");
@@ -20148,7 +20204,7 @@ async function cmdBootstrap(options, args) {
20148
20204
  return 0;
20149
20205
  }
20150
20206
  if (!["platform", "repair"].includes(operation)) {
20151
- throw new Error("Usage: fz bootstrap config <metal|platform|cloudflare>|platform [launch|bundle|fleet <apply|status>|remote <apply|status>|cloudflare [verify|finalize]]|metal [remote <apply|genesis|rehearsal|rehearsal-cleanup|host-keys|rehearsal-host-keys|status>]|status|repair [--bootstrap-config <path>] [--apply]");
20207
+ throw new Error("Usage: fz bootstrap config <metal|platform|cloudflare>|platform [launch|bundle|fleet <apply|status>|remote <apply|status>|cloudflare [verify|finalize]]|metal [remote <apply|genesis|genesis-cleanup|rehearsal|rehearsal-cleanup|host-keys|rehearsal-host-keys|status>]|status|repair [--bootstrap-config <path>] [--apply]");
20152
20208
  }
20153
20209
  const config = options.bootstrapConfigPath ? readBootstrapConfig(options.bootstrapConfigPath) : operation === "repair" ? (() => {
20154
20210
  throw new Error("repair requires --bootstrap-config so immutable coordinates are revalidated");
@@ -20818,7 +20874,7 @@ function usage() {
20818
20874
  Persist secret-free public-node acceptance, then remove
20819
20875
  the completed non-secret checkpoint and node handoffs
20820
20876
  fz bootstrap metal Plan/install an identity-only physical provisioner
20821
- fz bootstrap metal remote <apply|genesis|rehearsal|rehearsal-cleanup|host-keys|rehearsal-host-keys|status>
20877
+ fz bootstrap metal remote <apply|genesis|genesis-cleanup|rehearsal|rehearsal-cleanup|host-keys|rehearsal-host-keys|status>
20822
20878
  Install/bootstrap one pinned blank metal target, then
20823
20879
  provision the exact selected three-node genesis seed
20824
20880
  fz bootstrap status Verify persisted profile and supervised units
@@ -366,7 +366,7 @@ function systemdAgentEgressDirectives(loopbackTcpPorts = []) {
366
366
  }
367
367
 
368
368
  // src/version.ts
369
- var VERSION = "0.1.114";
369
+ var VERSION = "0.1.116";
370
370
 
371
371
  // src/otel-collector.ts
372
372
  var FORGEZERO_OTEL_COLLECTOR_UNIT = "forgezero-otel-collector.service";
@@ -90,7 +90,7 @@ export interface OperatorPlatformFleetCoordinates {
90
90
  }[];
91
91
  }
92
92
  export type OperatorPlatformBootstrapMode = 'apply' | 'status';
93
- export type OperatorMetalBootstrapMode = 'apply' | 'genesis' | 'rehearsal' | 'rehearsal-cleanup' | 'host-keys' | 'rehearsal-host-keys' | 'status';
93
+ export type OperatorMetalBootstrapMode = 'apply' | 'genesis' | 'genesis-cleanup' | 'rehearsal' | 'rehearsal-cleanup' | 'host-keys' | 'rehearsal-host-keys' | 'status';
94
94
  export interface OperatorPlatformBootstrapPlan {
95
95
  kind: 'platform-remote';
96
96
  mode: OperatorPlatformBootstrapMode;
@@ -1460,7 +1460,7 @@ var UPDATE_RETRY_BASE_MS = 5 * 60000;
1460
1460
  var UPDATE_RETRY_MAX_MS = 24 * 60 * 60000;
1461
1461
 
1462
1462
  // src/version.ts
1463
- var VERSION = "0.1.114";
1463
+ var VERSION = "0.1.116";
1464
1464
 
1465
1465
  // src/software.ts
1466
1466
  var PINNED_BUN_VERSION = "1.3.14";
@@ -1504,6 +1504,44 @@ var DOCKER_DAEMON_CONFIG = `${JSON.stringify({
1504
1504
  import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, readdirSync, realpathSync, renameSync as renameSync2, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "fs";
1505
1505
  import { dirname as dirname3, join as join2, resolve as resolve3, sep } from "path";
1506
1506
 
1507
+ // src/capacity-calibration.ts
1508
+ function localCalibrationEndpoint(value) {
1509
+ const endpoint2 = new URL(value);
1510
+ if (endpoint2.protocol !== "http:" || !["localhost", "127.0.0.1", "[::1]"].includes(endpoint2.hostname) || !endpoint2.port || endpoint2.username || endpoint2.password || endpoint2.hash) {
1511
+ throw new Error("Capacity calibration requires an explicit loopback HTTP endpoint and port.");
1512
+ }
1513
+ return endpoint2;
1514
+ }
1515
+ function validateCapacityCalibrationOptions(options) {
1516
+ const endpoint2 = localCalibrationEndpoint(options.endpoint);
1517
+ const maxConcurrency = options.maxConcurrency ?? 256;
1518
+ const requestsPerWorker = options.requestsPerWorker ?? 8;
1519
+ const maximumRequestsPerWorker = options.maximumRequestsPerWorker ?? 100;
1520
+ const maxP95Ms = options.maxP95Ms ?? 250;
1521
+ const maxErrorRate = options.maxErrorRate ?? 0.01;
1522
+ const safetyRatio = options.safetyRatio ?? 0.8;
1523
+ const requestTimeoutMs = options.requestTimeoutMs ?? 5000;
1524
+ const minimumStageDurationMs = options.minimumStageDurationMs ?? 5000;
1525
+ const maxCpuUtilizationPercent = options.maxCpuUtilizationPercent ?? 90;
1526
+ const maxMemoryUtilizationPercent = options.maxMemoryUtilizationPercent ?? 90;
1527
+ if (!Number.isSafeInteger(maxConcurrency) || maxConcurrency < 1 || maxConcurrency > 4096 || !Number.isSafeInteger(requestsPerWorker) || requestsPerWorker < 2 || requestsPerWorker > 100 || !Number.isSafeInteger(maximumRequestsPerWorker) || maximumRequestsPerWorker < requestsPerWorker || maximumRequestsPerWorker > 100 || !Number.isFinite(maxP95Ms) || maxP95Ms < 1 || !Number.isFinite(maxErrorRate) || maxErrorRate < 0 || maxErrorRate > 0.2 || !Number.isFinite(safetyRatio) || safetyRatio < 0.25 || safetyRatio > 0.95 || !Number.isSafeInteger(requestTimeoutMs) || requestTimeoutMs < 100 || requestTimeoutMs > 30000 || !Number.isSafeInteger(minimumStageDurationMs) || minimumStageDurationMs < 100 || minimumStageDurationMs > 60000 || !Number.isFinite(maxCpuUtilizationPercent) || maxCpuUtilizationPercent < 25 || maxCpuUtilizationPercent > 100 || !Number.isFinite(maxMemoryUtilizationPercent) || maxMemoryUtilizationPercent < 25 || maxMemoryUtilizationPercent > 100) {
1528
+ throw new Error("Capacity calibration bounds are invalid.");
1529
+ }
1530
+ return {
1531
+ endpoint: endpoint2,
1532
+ maxConcurrency,
1533
+ requestsPerWorker,
1534
+ maximumRequestsPerWorker,
1535
+ maxP95Ms,
1536
+ maxErrorRate,
1537
+ safetyRatio,
1538
+ requestTimeoutMs,
1539
+ minimumStageDurationMs,
1540
+ maxCpuUtilizationPercent,
1541
+ maxMemoryUtilizationPercent
1542
+ };
1543
+ }
1544
+
1507
1545
  // src/definition.ts
1508
1546
  var RESERVED_STEP_ENV = new Set([
1509
1547
  "PATH",
@@ -3089,6 +3127,9 @@ function platformGenesisClaims(guests, sshPublicKeys) {
3089
3127
  throw new Error("platform genesis requires at least one operator SSH public key");
3090
3128
  return reviewed.map((guest) => claimFor(guest, keys, "create"));
3091
3129
  }
3130
+ function platformGenesisDeletionClaims(guests) {
3131
+ return validatePlatformGenesisGuests(guests).map((guest) => claimFor(guest, [], "delete"));
3132
+ }
3092
3133
  function platformCommunityRehearsalClaims(seedGuests, rehearsalGuest, sshPublicKeys) {
3093
3134
  const reviewed = validatePlatformGenesisGuests([...seedGuests, rehearsalGuest], 4);
3094
3135
  const keys = [...new Set(sshPublicKeys.map(publicKey))];
@@ -6674,14 +6715,14 @@ function planOperatorMetalBootstrap(request, mode) {
6674
6715
  if ((mode === "rehearsal" || mode === "rehearsal-cleanup") && !request.genesis.rehearsalNode) {
6675
6716
  throw new Error("the reviewed metal request has no rehearsal node");
6676
6717
  }
6677
- const claims = mode === "rehearsal" || mode === "rehearsal-cleanup" ? mode === "rehearsal-cleanup" ? platformCommunityRehearsalDeletionClaims(request.genesis.nodes, request.genesis.rehearsalNode) : platformCommunityRehearsalClaims(request.genesis.nodes, request.genesis.rehearsalNode, keys) : platformGenesisClaims(request.genesis.nodes, keys);
6718
+ const claims = mode === "genesis-cleanup" ? platformGenesisDeletionClaims(request.genesis.nodes) : mode === "rehearsal" || mode === "rehearsal-cleanup" ? mode === "rehearsal-cleanup" ? platformCommunityRehearsalDeletionClaims(request.genesis.nodes, request.genesis.rehearsalNode) : platformCommunityRehearsalClaims(request.genesis.nodes, request.genesis.rehearsalNode, keys) : platformGenesisClaims(request.genesis.nodes, keys);
6678
6719
  const genesisNodes = mode === "host-keys" ? request.genesis.nodes.map(({ name }) => name) : mode === "rehearsal-host-keys" ? guestRows(request).map(({ name }) => name) : claims.map((claim) => claim.spec.guestName).filter((name) => Boolean(name));
6679
6720
  return {
6680
6721
  kind: "metal-remote",
6681
6722
  mode,
6682
6723
  mutation: !["status", "host-keys", "rehearsal-host-keys"].includes(mode),
6683
6724
  target: { address: request.target.address, port: request.target.port, user: request.target.user },
6684
- steps: mode === "status" ? ["verify pinned SSH transport", "run typed fz bootstrap status"] : mode === "host-keys" || mode === "rehearsal-host-keys" ? ["verify pinned SSH transport", "collect exact Ed25519 host keys for the reviewed guest addresses"] : mode === "genesis" || mode === "rehearsal" || mode === "rehearsal-cleanup" ? ["verify pinned SSH transport", mode === "rehearsal" ? "send the three reviewed seed claims plus the reviewed fourth Community rehearsal claim to the constrained Metal helper" : mode === "rehearsal-cleanup" ? "delete the exact four reviewed disposable guests and their owned disks, units, seed data and inventory" : "send the three reviewed platform-genesis claims to the constrained Metal helper"] : [
6725
+ steps: mode === "status" ? ["verify pinned SSH transport", "run typed fz bootstrap status"] : mode === "host-keys" || mode === "rehearsal-host-keys" ? ["verify pinned SSH transport", "collect exact Ed25519 host keys for the reviewed guest addresses"] : mode === "genesis" || mode === "genesis-cleanup" || mode === "rehearsal" || mode === "rehearsal-cleanup" ? ["verify pinned SSH transport", mode === "rehearsal" ? "send the three reviewed seed claims plus the reviewed fourth Community rehearsal claim to the constrained Metal helper" : mode === "genesis-cleanup" ? "delete the exact three reviewed platform guests and their owned disks, units, seed data and inventory" : mode === "rehearsal-cleanup" ? "delete the exact four reviewed disposable guests and their owned disks, units, seed data and inventory" : "send the three reviewed platform-genesis claims to the constrained Metal helper"] : [
6685
6726
  "verify pinned SSH transport and caller-approved SSH agent",
6686
6727
  "copy pinned Bun and packaged fz artifacts to private staging",
6687
6728
  "stage the strict owner-only metal config and optional seed handoff",
@@ -7374,13 +7415,13 @@ async function applyOperatorMetalBootstrap(request, mode, options = {}) {
7374
7415
  output: JSON.stringify(await collectOperatorGuestHostKeys(request, { ...options, exec }, mode === "rehearsal-host-keys"))
7375
7416
  };
7376
7417
  }
7377
- if (mode === "genesis" || mode === "rehearsal" || mode === "rehearsal-cleanup") {
7418
+ if (mode === "genesis" || mode === "genesis-cleanup" || mode === "rehearsal" || mode === "rehearsal-cleanup") {
7378
7419
  const keys = request.genesis.sshPublicKeyFiles.map((path) => publicIdentity(path));
7379
7420
  if ((mode === "rehearsal" || mode === "rehearsal-cleanup") && !request.genesis.rehearsalNode) {
7380
7421
  throw new Error("the reviewed metal request has no rehearsal node");
7381
7422
  }
7382
7423
  const outputs = [];
7383
- const claims = mode === "rehearsal" || mode === "rehearsal-cleanup" ? mode === "rehearsal-cleanup" ? platformCommunityRehearsalDeletionClaims(request.genesis.nodes, request.genesis.rehearsalNode) : platformCommunityRehearsalClaims(request.genesis.nodes, request.genesis.rehearsalNode, keys) : platformGenesisClaims(request.genesis.nodes, keys);
7424
+ const claims = mode === "genesis-cleanup" ? platformGenesisDeletionClaims(request.genesis.nodes) : mode === "rehearsal" || mode === "rehearsal-cleanup" ? mode === "rehearsal-cleanup" ? platformCommunityRehearsalDeletionClaims(request.genesis.nodes, request.genesis.rehearsalNode) : platformCommunityRehearsalClaims(request.genesis.nodes, request.genesis.rehearsalNode, keys) : platformGenesisClaims(request.genesis.nodes, keys);
7384
7425
  for (const claim of claims) {
7385
7426
  outputs.push(await remote(exec, request, knownHosts, ["/usr/bin/sudo", "-n", "/usr/local/bin/fz-agent", "metal-apply", "--claim=-"], `provision ${claim.spec.guestName}`, false, `${JSON.stringify(claim)}
7386
7427
  `));
@@ -669,6 +669,9 @@ function platformGenesisClaims(guests, sshPublicKeys) {
669
669
  throw new Error("platform genesis requires at least one operator SSH public key");
670
670
  return reviewed.map((guest) => claimFor(guest, keys, "create"));
671
671
  }
672
+ function platformGenesisDeletionClaims(guests) {
673
+ return validatePlatformGenesisGuests(guests).map((guest) => claimFor(guest, [], "delete"));
674
+ }
672
675
  function platformCommunityRehearsalClaims(seedGuests, rehearsalGuest, sshPublicKeys) {
673
676
  const reviewed = validatePlatformGenesisGuests([...seedGuests, rehearsalGuest], 4);
674
677
  const keys = [...new Set(sshPublicKeys.map(publicKey))];