agent-transport-system 0.7.10 → 0.7.11

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/ats.js CHANGED
@@ -27,7 +27,7 @@ import wrapAnsi from "wrap-ansi";
27
27
  import { Box, Container, Editor, Key, ProcessTerminal, TUI, Text, getEditorKeybindings, matchesKey } from "@mariozechner/pi-tui";
28
28
 
29
29
  //#region package.json
30
- var version = "0.7.10";
30
+ var version = "0.7.11";
31
31
  var package_default = {
32
32
  $schema: "https://www.schemastore.org/package.json",
33
33
  name: "agent-transport-system",
@@ -8246,10 +8246,30 @@ function safeParseJson$1(raw) {
8246
8246
  }
8247
8247
  }
8248
8248
 
8249
+ //#endregion
8250
+ //#region src/config/published-production-safety.ts
8251
+ const PUBLISHED_PRODUCTION_ATS_ROOT = normalizeComparablePath(join(homedir(), resolveDefaultAtsHomeDirname("prod")));
8252
+ function assertNoPublishedProductionMutationDuringTests(pathInput, targetName) {
8253
+ if (!isTestProcess(pathInput)) return;
8254
+ if (!isPublishedProductionAtsRoot(pathInput)) return;
8255
+ throw new Error([`Refusing to mutate ${targetName} in the published production lane during tests.`, "Set ATS_HOME to a fresh temporary directory, or run the validation through ats-dev or ats-canary."].join(" "));
8256
+ }
8257
+ function isPublishedProductionAtsRoot(pathInput) {
8258
+ return normalizeComparablePath(resolveAtsRootDir(pathInput)) === PUBLISHED_PRODUCTION_ATS_ROOT;
8259
+ }
8260
+ function isTestProcess(pathInput = {}) {
8261
+ const env = pathInput.env ?? process.env;
8262
+ const argv = pathInput.argv ?? process.argv;
8263
+ return env.NODE_ENV === "test" || env.VITEST === "true" || typeof env.VITEST_WORKER_ID === "string" || typeof env.JEST_WORKER_ID === "string" || argv.some((arg) => arg.includes("vitest"));
8264
+ }
8265
+ function normalizeComparablePath(path) {
8266
+ const normalized = resolve(path);
8267
+ return process.platform === "win32" ? normalized.toLowerCase() : normalized;
8268
+ }
8269
+
8249
8270
  //#endregion
8250
8271
  //#region src/config/daemon-service-contract.ts
8251
8272
  const DAEMON_SERVICE_CONTRACT_FILENAME = "service-contract.json";
8252
- const PUBLISHED_PRODUCTION_ATS_ROOT = normalizeComparablePath(join(homedir(), resolveDefaultAtsHomeDirname("prod")));
8253
8273
  function daemonServiceContractPath(pathInput = {}) {
8254
8274
  return join(daemonRuntimeStateRootPath(pathInput), DAEMON_SERVICE_CONTRACT_FILENAME);
8255
8275
  }
@@ -8283,13 +8303,11 @@ async function clearDaemonServiceContract(pathInput = {}) {
8283
8303
  await rm(daemonServiceContractPath(pathInput), { force: true });
8284
8304
  }
8285
8305
  function assertDaemonServiceContractMutationAllowed(pathInput) {
8286
- if (!isTestProcess()) return;
8287
- if (!isPublishedProductionAtsRoot(pathInput)) return;
8288
- throw new Error(["Refusing to mutate ATS Service contract in the published production lane during tests.", "Set ATS_HOME to a fresh temporary directory, or run the validation through ats-dev or ats-canary."].join(" "));
8306
+ assertNoPublishedProductionMutationDuringTests(pathInput, "ATS Service contract");
8289
8307
  }
8290
8308
  function assertDaemonServiceContractIdentityAllowed(candidate, pathInput) {
8291
- if (!isPublishedProductionAtsRoot(pathInput)) return;
8292
8309
  if (!isUnsafeProductionDaemonServiceContractIdentity(candidate)) return;
8310
+ if (isTestProcess(pathInput) && !isPublishedProductionAtsRoot(pathInput)) return;
8293
8311
  throw new Error(["Refusing to write ATS Service contract with a test fixture identity in the published production lane.", "Run `ats service repair --profile <profile-id>` from the signed-in production lane, or clear the polluted local service state before retrying."].join(" "));
8294
8312
  }
8295
8313
  function isDaemonServiceContractIdentityReusable(contract, pathInput = {}) {
@@ -8317,16 +8335,6 @@ const UNSAFE_PRODUCTION_PROFILE_IDS = new Set([
8317
8335
  function normalizeFixtureText(value) {
8318
8336
  return value.trim().toLowerCase();
8319
8337
  }
8320
- function isPublishedProductionAtsRoot(pathInput) {
8321
- return normalizeComparablePath(resolveAtsRootDir(pathInput)) === PUBLISHED_PRODUCTION_ATS_ROOT;
8322
- }
8323
- function isTestProcess(env = process.env) {
8324
- return env.NODE_ENV === "test" || env.VITEST === "true" || typeof env.VITEST_WORKER_ID === "string" || typeof env.JEST_WORKER_ID === "string" || process.argv.some((arg) => arg.includes("vitest"));
8325
- }
8326
- function normalizeComparablePath(path) {
8327
- const normalized = resolve(path);
8328
- return process.platform === "win32" ? normalized.toLowerCase() : normalized;
8329
- }
8330
8338
  function buildContractCandidate(input, pathInput, current) {
8331
8339
  const lane = input.lane ?? resolveAtsEnvPreset(pathInput);
8332
8340
  const connectedComputerId = input.connectedComputerId ?? (current && current.lane === lane && current.gatewayUrl === input.gatewayUrl && current.profileId === input.profileId && current.deviceId === input.deviceId ? current.connectedComputerId : void 0);
@@ -9793,6 +9801,7 @@ async function resolveDaemonLifecycleAttribution(input) {
9793
9801
  };
9794
9802
  }
9795
9803
  async function emitDaemonLifecycleEvent(input) {
9804
+ assertNoPublishedProductionMutationDuringTests(input.pathInput ?? {}, "ATS Service lifecycle journal");
9796
9805
  const journalPath = daemonLifecycleJournalPath(input.pathInput);
9797
9806
  const attribution = await resolveDaemonLifecycleAttribution(input);
9798
9807
  const event = {
@@ -50412,7 +50421,7 @@ async function resolveDaemonServiceParticipationStatusAfterInstall(input) {
50412
50421
  return { status: refreshedStatus };
50413
50422
  }
50414
50423
  async function runDaemonServiceSafeRefresh(input) {
50415
- const outcome = await runDaemonReinstall({
50424
+ return await runDaemonReinstall({
50416
50425
  agentOverviewHandled: true,
50417
50426
  ...input.gatewayUrl ? { gatewayUrl: input.gatewayUrl } : {},
50418
50427
  ...input.atsProfileId ? { profile: input.atsProfileId } : {},
@@ -50423,8 +50432,6 @@ async function runDaemonServiceSafeRefresh(input) {
50423
50432
  suppressAgentOverview: true,
50424
50433
  suppressInstallOutput: true
50425
50434
  });
50426
- if (outcome.ok && outcome.result === "completed" && outcome.serviceState === "running") return;
50427
- throw new Error(`ATS Service refresh did not complete: ${outcome.result}`);
50428
50435
  }
50429
50436
  async function runDaemonServiceParticipationActionStage(input) {
50430
50437
  if (input.status.kind === "needs_repair") return await runDaemonServiceParticipationRefresh({
@@ -50459,11 +50466,39 @@ async function runDaemonServiceParticipationRefresh(input) {
50459
50466
  data: { reasonCode: input.accountIssue.reasonCode }
50460
50467
  });
50461
50468
  try {
50462
- await runDaemonServiceSafeRefresh({
50469
+ const refreshOutcome = await runDaemonServiceSafeRefresh({
50463
50470
  atsProfileId: input.input.atsProfileId,
50464
50471
  gatewayUrl: input.input.gatewayUrl,
50465
50472
  view: input.input.view
50466
50473
  });
50474
+ if (refreshOutcome.ok && (refreshOutcome.result === "completed" || refreshOutcome.result === "stopped_safe") && refreshOutcome.serviceState === "stopped") {
50475
+ const startMapped = await mapDaemonBackgroundStartResult(await runDaemonBackgroundStartForDecision({
50476
+ gatewayUrl: input.input.gatewayUrl,
50477
+ ...input.input.atsProfileId ? { profile: input.input.atsProfileId } : {},
50478
+ view: input.input.view
50479
+ }), {
50480
+ expectedVersion: input.expectedVersion,
50481
+ presenter: input.input.presenter,
50482
+ codePrefix: input.codePrefix
50483
+ });
50484
+ if (startMapped.status !== "aligned") return startMapped;
50485
+ const accountIssueAfterStart = await resolveDaemonServiceAccountAlignmentIssue(input.input);
50486
+ if (accountIssueAfterStart) {
50487
+ renderDaemonStartNeedsAttention({
50488
+ presenter: input.input.presenter,
50489
+ codePrefix: input.codePrefix,
50490
+ summary: accountIssueAfterStart.summary
50491
+ });
50492
+ input.input.presenter.line({
50493
+ code: `${input.codePrefix}.account_alignment_failed`,
50494
+ text: accountIssueAfterStart.summary,
50495
+ data: { reasonCode: accountIssueAfterStart.reasonCode }
50496
+ });
50497
+ return { status: "needs_attention" };
50498
+ }
50499
+ return startMapped;
50500
+ }
50501
+ if (!(refreshOutcome.ok && refreshOutcome.result === "completed" && refreshOutcome.serviceState === "running")) throw new Error(`ATS Service refresh did not complete: ${refreshOutcome.result}`);
50467
50502
  } catch (error) {
50468
50503
  renderDaemonStartNeedsAttention({
50469
50504
  presenter: input.input.presenter,
@@ -64731,7 +64766,7 @@ function buildTerminalStep(input) {
64731
64766
  case "refresh_service": return {
64732
64767
  message: "Starting or repairing ATS Service.",
64733
64768
  run: async () => {
64734
- if ((await runDaemonServiceParticipationGate({
64769
+ const gate = await runDaemonServiceParticipationGate({
64735
64770
  intent: "start",
64736
64771
  presenter: input.input.presenter,
64737
64772
  resolvedView: input.input.runtime.resolvedView,
@@ -64741,7 +64776,8 @@ function buildTerminalStep(input) {
64741
64776
  ...input.humanProfileId ? { atsProfileId: input.humanProfileId } : {},
64742
64777
  forcePrompt: true,
64743
64778
  view: input.input.view
64744
- })).status !== "aligned") throw new Error("ATS Service is not connected yet.");
64779
+ });
64780
+ if (gate.status !== "aligned") throw new Error(gate.errorMessage ?? "ATS Service is not connected yet.");
64745
64781
  emitHumanStatus(input.input, "Current step", ["Connecting this computer to ATS.", "Saving this computer's ATS Service identity so ATS Web can use it."]);
64746
64782
  const runtimeIdentity = await syncLocalSetupCurrentDeviceTargetFromServiceContract({ gatewayUrl: input.input.gatewayUrl });
64747
64783
  emitHumanStatus(input.input, "Current step", ["Checking local setup state.", "Reading installed local agents and ATS Service compatibility."]);