agent-transport-system 0.7.57 → 0.7.58

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,12 +27,12 @@ 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.57";
30
+ var version = "0.7.58";
31
31
  var package_default = {
32
32
  $schema: "https://www.schemastore.org/package.json",
33
33
  name: "agent-transport-system",
34
34
  version,
35
- atsReleaseDate: "2026-06-11",
35
+ atsReleaseDate: "2026-06-12",
36
36
  description: "Agent Transport System CLI - https://ats.sh",
37
37
  license: "MIT",
38
38
  type: "module",
@@ -27954,9 +27954,12 @@ async function resolveDaemonStatusSnapshot(input = {}) {
27954
27954
  });
27955
27955
  const runtimeContractRepairReport = currentReplyReadiness.daemonStatus.installed ? await readDaemonRuntimeContractRepairReport().catch(() => null) : null;
27956
27956
  const latestLifecycleEvent = await readLatestDaemonLifecycleOriginEvent().catch(() => null);
27957
- const baseAttention = resolveDaemonStatusAttention({
27958
- inventory: currentReplyReadiness.inventory,
27959
- runtimeState: currentReplyReadiness.displayRuntimeStatus ?? currentReplyReadiness.runtimeStatus
27957
+ const baseAttention = demoteRepairAttentionForLiveRoute({
27958
+ attention: resolveDaemonStatusAttention({
27959
+ inventory: currentReplyReadiness.inventory,
27960
+ runtimeState: currentReplyReadiness.displayRuntimeStatus ?? currentReplyReadiness.runtimeStatus
27961
+ }),
27962
+ daemonRouteObservation: currentReplyReadiness.daemonRouteObservation
27960
27963
  });
27961
27964
  const liveDependencyDiagnostics = shouldCheckDaemonServiceDependenciesForStatus(currentReplyReadiness.displayRuntimeStatus ?? currentReplyReadiness.runtimeStatus) ? await resolveDaemonServiceDependencyDiagnostics({ scopePolicy: "loopback_only" }).catch(() => null) : null;
27962
27965
  const recordedStartFailure = shouldCheckDaemonServiceDependenciesForStatus(currentReplyReadiness.displayRuntimeStatus ?? currentReplyReadiness.runtimeStatus) ? await readDaemonStartFailureState().catch(() => null) : null;
@@ -27970,6 +27973,12 @@ async function resolveDaemonStatusSnapshot(input = {}) {
27970
27973
  runtimeContractRepairReport
27971
27974
  };
27972
27975
  }
27976
+ function demoteRepairAttentionForLiveRoute(input) {
27977
+ if (!input.attention) return null;
27978
+ if (input.attention.code !== "service_repair_recommended") return input.attention;
27979
+ if (input.daemonRouteObservation.status !== "online") return input.attention;
27980
+ return null;
27981
+ }
27973
27982
  function shouldCheckDaemonServiceDependenciesForStatus(runtimeState) {
27974
27983
  return runtimeState?.status !== "running";
27975
27984
  }
@@ -36120,6 +36129,12 @@ async function submitRuntimeAgentControllerReports(input) {
36120
36129
  reasonCode: "runtime.reporting.service_contract_unavailable"
36121
36130
  });
36122
36131
  const authCompatibility = await resolveRuntimeReportingAuthCompatibility(serviceContract.gatewayUrl);
36132
+ if (authCompatibility.status === "unavailable") return failedSubmissions({
36133
+ gatewayUrl: serviceContract.gatewayUrl,
36134
+ reports: input.reports,
36135
+ reason: "auth_unavailable",
36136
+ reasonCode: `runtime.reporting.auth_${authCompatibility.authState}`
36137
+ });
36123
36138
  if (authCompatibility.status === "mismatch") return failedSubmissions({
36124
36139
  authBaseUrl: authCompatibility.authBaseUrl,
36125
36140
  gatewayUrl: serviceContract.gatewayUrl,
@@ -36186,6 +36201,12 @@ async function submitRuntimeProviderConversationProofs(input) {
36186
36201
  reasonCode: "provider_conversation.runtime_reporting.service_contract_unavailable"
36187
36202
  });
36188
36203
  const authCompatibility = await resolveRuntimeReportingAuthCompatibility(serviceContract.gatewayUrl);
36204
+ if (authCompatibility.status === "unavailable") return failedProviderConversationProofSubmissions({
36205
+ gatewayUrl: serviceContract.gatewayUrl,
36206
+ proofs: input.proofs,
36207
+ reason: "auth_unavailable",
36208
+ reasonCode: `provider_conversation.runtime_reporting.auth_${authCompatibility.authState}`
36209
+ });
36189
36210
  if (authCompatibility.status === "mismatch") return failedProviderConversationProofSubmissions({
36190
36211
  authBaseUrl: authCompatibility.authBaseUrl,
36191
36212
  gatewayUrl: serviceContract.gatewayUrl,
@@ -36353,7 +36374,14 @@ function failedProviderConversationProofSubmissions(input) {
36353
36374
  }
36354
36375
  async function resolveRuntimeReportingAuthCompatibility(gatewayUrl) {
36355
36376
  const authState = await getAuthSessionState().catch(() => null);
36356
- if (!(authState?.state === "valid" && authState.session)) return { status: "compatible" };
36377
+ if (!authState) return {
36378
+ authState: "error",
36379
+ status: "unavailable"
36380
+ };
36381
+ if (!(authState.state === "valid" && authState.session)) return {
36382
+ authState: authState.state === "expired" || authState.state === "invalid" ? authState.state : "missing",
36383
+ status: "unavailable"
36384
+ };
36357
36385
  if (canAttachAuthTokenToRequest(authState.session, gatewayUrl)) return { status: "compatible" };
36358
36386
  return {
36359
36387
  authBaseUrl: authState.session.authBaseUrl,
@@ -40803,6 +40831,54 @@ function buildDaemonRuntimeLease(input) {
40803
40831
  };
40804
40832
  }
40805
40833
 
40834
+ //#endregion
40835
+ //#region src/local-service/state/service-connection-state.ts
40836
+ function createServiceConnectionStateTracker(input) {
40837
+ let current = {
40838
+ state: "starting",
40839
+ reason: null,
40840
+ detail: null,
40841
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
40842
+ };
40843
+ return {
40844
+ get: () => current,
40845
+ set: (state, options) => {
40846
+ const reason = options?.reason ?? null;
40847
+ if (current.state === state && current.reason === reason) return;
40848
+ current = {
40849
+ state,
40850
+ reason,
40851
+ detail: options?.detail ?? null,
40852
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
40853
+ };
40854
+ input?.onTransition?.(current);
40855
+ }
40856
+ };
40857
+ }
40858
+ function classifyConnectionFailureReason(message) {
40859
+ const lowered = message.toLowerCase();
40860
+ if (lowered.includes("authentication required") || lowered.includes("401") || lowered.includes("unauthorized")) return "auth_rejected";
40861
+ if (lowered.includes("fetch failed") || lowered.includes("timed out") || lowered.includes("timeout") || lowered.includes("econn") || lowered.includes("enotfound") || lowered.includes("socket") || lowered.includes("network")) return "network_unreachable";
40862
+ return "internal";
40863
+ }
40864
+ function toHealthProjection(state) {
40865
+ if (state.state === "online") return {
40866
+ state: "ok",
40867
+ runtimeState: "healthy",
40868
+ reasonCode: "ok"
40869
+ };
40870
+ if (state.state === "stopping") return {
40871
+ state: "degraded",
40872
+ runtimeState: "idle",
40873
+ reasonCode: "stopping"
40874
+ };
40875
+ return {
40876
+ state: "degraded",
40877
+ runtimeState: "suspect",
40878
+ reasonCode: state.reason ?? state.state
40879
+ };
40880
+ }
40881
+
40806
40882
  //#endregion
40807
40883
  //#region src/local-service/adapters/resolve-daemon-capabilities.ts
40808
40884
  function resolveDaemonCapabilities(input) {
@@ -46809,6 +46885,7 @@ const runDaemonServiceLoop = async (input) => {
46809
46885
  initialState: daemonRuntimeState,
46810
46886
  leaseDescriptor: await resolveDaemonRuntimeLeaseDescriptor({ command: daemonRuntimeState.command })
46811
46887
  });
46888
+ const connectionState = createRunLoopConnectionStateTracker(input.presenter);
46812
46889
  const localAdapterContainer = createLocalAdapterContainer(createLocalAdapterEntries({
46813
46890
  registerRuntimeProcess: (event) => {
46814
46891
  const nextProcessId = event.phase === "process_exit" ? null : event.processId;
@@ -46863,9 +46940,10 @@ const runDaemonServiceLoop = async (input) => {
46863
46940
  getContext: async () => ({
46864
46941
  healthPayload: {
46865
46942
  checkedAt: nowIsoString(),
46866
- reasonCode: stopRequested ? "stopping" : "ok",
46867
- runtimeState: stopRequested ? "idle" : "healthy",
46868
- state: stopRequested ? "degraded" : "ok"
46943
+ ...toHealthProjection(stopRequested ? {
46944
+ ...connectionState.get(),
46945
+ state: "stopping"
46946
+ } : connectionState.get())
46869
46947
  },
46870
46948
  historyEntries: [],
46871
46949
  interruptHandler: async (payload) => await handleLocalControlPlaneInterrupt({
@@ -46905,6 +46983,7 @@ const runDaemonServiceLoop = async (input) => {
46905
46983
  const requestStop = () => {
46906
46984
  if (stopRequested) return;
46907
46985
  stopRequested = true;
46986
+ connectionState.set("stopping");
46908
46987
  activeSocket?.close(1e3, "shutdown");
46909
46988
  };
46910
46989
  const onSigint = () => {
@@ -46954,6 +47033,7 @@ const runDaemonServiceLoop = async (input) => {
46954
47033
  });
46955
47034
  }
46956
47035
  while (!stopRequested) try {
47036
+ connectionState.set("connecting", { reason: resolveConnectingReason(reconnectAttempt) });
46957
47037
  const wsUrl = toDaemonStreamUrl(baseUrl);
46958
47038
  const ws = await connectWebSocket(wsUrl, {
46959
47039
  headers: selectedAtsProfile ? await buildAtsProfileRequestHeadersWithAuth({
@@ -46999,7 +47079,10 @@ const runDaemonServiceLoop = async (input) => {
46999
47079
  reconnectAttempt,
47000
47080
  routeCatalogState,
47001
47081
  socket: ws,
47002
- touchRuntimeState: runtimeStateTracker.touchRuntimeState
47082
+ touchRuntimeState: async (updates) => {
47083
+ if (typeof updates.heartbeatAt === "string") connectionState.set("online");
47084
+ await runtimeStateTracker.touchRuntimeState(updates);
47085
+ }
47003
47086
  });
47004
47087
  reconnectAttempt = 0;
47005
47088
  activeSocket = null;
@@ -47016,6 +47099,11 @@ const runDaemonServiceLoop = async (input) => {
47016
47099
  if (stopRequested) break;
47017
47100
  reconnectAttempt += 1;
47018
47101
  const backoffMs = resolveReconnectBackoffMs(reconnectAttempt);
47102
+ noteReconnectFailureState({
47103
+ connectionState,
47104
+ errorMessage: toErrorMessage$29(error),
47105
+ reconnectAttempt
47106
+ });
47019
47107
  const reconcileDecision = resolveRouteRegistrationReconcileDecision({
47020
47108
  driftDetected: true,
47021
47109
  foregroundActive: mode === "foreground"
@@ -47311,6 +47399,31 @@ function summarizeLocalControlSyncSkippedProfiles(payload) {
47311
47399
  if (!payload.skippedProfiles || payload.skippedProfiles.length === 0) return "";
47312
47400
  return `; skipped=${payload.skippedProfiles.length} (${summarizeSkippedDaemonProfiles(payload.skippedProfiles)})`;
47313
47401
  }
47402
+ function createRunLoopConnectionStateTracker(presenter) {
47403
+ return createServiceConnectionStateTracker({ onTransition: (next) => {
47404
+ emitRunLine({
47405
+ presenter,
47406
+ code: "daemon.run.connection_state",
47407
+ text: `connection state: ${next.state}${next.reason ? ` (${next.reason})` : ""}${next.detail ? ` - ${next.detail}` : ""}`,
47408
+ payload: {
47409
+ detail: next.detail,
47410
+ reason: next.reason,
47411
+ state: next.state,
47412
+ updatedAt: next.updatedAt
47413
+ }
47414
+ });
47415
+ } });
47416
+ }
47417
+ function noteReconnectFailureState(input) {
47418
+ if (input.reconnectAttempt < 2) return;
47419
+ input.connectionState.set("degraded", {
47420
+ detail: input.errorMessage,
47421
+ reason: classifyConnectionFailureReason(input.errorMessage)
47422
+ });
47423
+ }
47424
+ function resolveConnectingReason(reconnectAttempt) {
47425
+ return reconnectAttempt > 0 ? "reconnecting" : null;
47426
+ }
47314
47427
 
47315
47428
  //#endregion
47316
47429
  //#region src/local-service/lifecycle/daemon-service-hygiene.ts