commonswarm 0.1.50 → 0.1.51

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.
Files changed (2) hide show
  1. package/cswarm.cjs +1101 -1029
  2. package/package.json +1 -1
package/cswarm.cjs CHANGED
@@ -44,7 +44,7 @@ var __toESM = (mod, isNodeMode, target2) => (target2 = mod != null ? __create(__
44
44
  ));
45
45
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
46
46
 
47
- // node_modules/tslib/tslib.es6.mjs
47
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/tslib/tslib.es6.mjs
48
48
  var tslib_es6_exports = {};
49
49
  __export(tslib_es6_exports, {
50
50
  __addDisposableResource: () => __addDisposableResource,
@@ -483,7 +483,7 @@ function __rewriteRelativeImportExtension(path, preserveJsx) {
483
483
  }
484
484
  var extendStatics, __assign, __createBinding, __setModuleDefault, ownKeys, _SuppressedError, tslib_es6_default;
485
485
  var init_tslib_es6 = __esm({
486
- "node_modules/tslib/tslib.es6.mjs"() {
486
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/tslib/tslib.es6.mjs"() {
487
487
  extendStatics = function(d, b2) {
488
488
  extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b3) {
489
489
  d2.__proto__ = b3;
@@ -569,9 +569,9 @@ var init_tslib_es6 = __esm({
569
569
  }
570
570
  });
571
571
 
572
- // node_modules/@supabase/functions-js/dist/main/helper.js
572
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/functions-js/dist/main/helper.js
573
573
  var require_helper = __commonJS({
574
- "node_modules/@supabase/functions-js/dist/main/helper.js"(exports2) {
574
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/functions-js/dist/main/helper.js"(exports2) {
575
575
  "use strict";
576
576
  Object.defineProperty(exports2, "__esModule", { value: true });
577
577
  exports2.resolveFetch = void 0;
@@ -585,9 +585,9 @@ var require_helper = __commonJS({
585
585
  }
586
586
  });
587
587
 
588
- // node_modules/@supabase/functions-js/dist/main/types.js
588
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/functions-js/dist/main/types.js
589
589
  var require_types = __commonJS({
590
- "node_modules/@supabase/functions-js/dist/main/types.js"(exports2) {
590
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/functions-js/dist/main/types.js"(exports2) {
591
591
  "use strict";
592
592
  Object.defineProperty(exports2, "__esModule", { value: true });
593
593
  exports2.FunctionRegion = exports2.FunctionsHttpError = exports2.FunctionsRelayError = exports2.FunctionsFetchError = exports2.FunctionsError = void 0;
@@ -645,9 +645,9 @@ var require_types = __commonJS({
645
645
  }
646
646
  });
647
647
 
648
- // node_modules/@supabase/functions-js/dist/main/FunctionsClient.js
648
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/functions-js/dist/main/FunctionsClient.js
649
649
  var require_FunctionsClient = __commonJS({
650
- "node_modules/@supabase/functions-js/dist/main/FunctionsClient.js"(exports2) {
650
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/functions-js/dist/main/FunctionsClient.js"(exports2) {
651
651
  "use strict";
652
652
  Object.defineProperty(exports2, "__esModule", { value: true });
653
653
  exports2.FunctionsClient = void 0;
@@ -931,9 +931,9 @@ var require_FunctionsClient = __commonJS({
931
931
  }
932
932
  });
933
933
 
934
- // node_modules/@supabase/functions-js/dist/main/index.js
934
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/functions-js/dist/main/index.js
935
935
  var require_main = __commonJS({
936
- "node_modules/@supabase/functions-js/dist/main/index.js"(exports2) {
936
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/functions-js/dist/main/index.js"(exports2) {
937
937
  "use strict";
938
938
  Object.defineProperty(exports2, "__esModule", { value: true });
939
939
  exports2.FunctionRegion = exports2.FunctionsRelayError = exports2.FunctionsHttpError = exports2.FunctionsFetchError = exports2.FunctionsError = exports2.FunctionsClient = void 0;
@@ -960,9 +960,9 @@ var require_main = __commonJS({
960
960
  }
961
961
  });
962
962
 
963
- // node_modules/@supabase/realtime-js/dist/main/lib/websocket-factory.js
963
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/lib/websocket-factory.js
964
964
  var require_websocket_factory = __commonJS({
965
- "node_modules/@supabase/realtime-js/dist/main/lib/websocket-factory.js"(exports2) {
965
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/lib/websocket-factory.js"(exports2) {
966
966
  "use strict";
967
967
  Object.defineProperty(exports2, "__esModule", { value: true });
968
968
  exports2.WebSocketFactory = void 0;
@@ -1071,9 +1071,9 @@ Suggested solution: ${env.workaround}`;
1071
1071
  }
1072
1072
  });
1073
1073
 
1074
- // node_modules/@supabase/realtime-js/dist/main/lib/version.js
1074
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/lib/version.js
1075
1075
  var require_version = __commonJS({
1076
- "node_modules/@supabase/realtime-js/dist/main/lib/version.js"(exports2) {
1076
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/lib/version.js"(exports2) {
1077
1077
  "use strict";
1078
1078
  Object.defineProperty(exports2, "__esModule", { value: true });
1079
1079
  exports2.version = void 0;
@@ -1081,9 +1081,9 @@ var require_version = __commonJS({
1081
1081
  }
1082
1082
  });
1083
1083
 
1084
- // node_modules/@supabase/realtime-js/dist/main/lib/constants.js
1084
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/lib/constants.js
1085
1085
  var require_constants = __commonJS({
1086
- "node_modules/@supabase/realtime-js/dist/main/lib/constants.js"(exports2) {
1086
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/lib/constants.js"(exports2) {
1087
1087
  "use strict";
1088
1088
  Object.defineProperty(exports2, "__esModule", { value: true });
1089
1089
  exports2.CONNECTION_STATE = exports2.TRANSPORTS = exports2.CHANNEL_EVENTS = exports2.CHANNEL_STATES = exports2.SOCKET_STATES = exports2.MAX_PUSH_BUFFER_SIZE = exports2.WS_CLOSE_NORMAL = exports2.DEFAULT_TIMEOUT = exports2.VERSION = exports2.DEFAULT_VSN = exports2.VSN_2_0_0 = exports2.VSN_1_0_0 = exports2.DEFAULT_VERSION = void 0;
@@ -1129,9 +1129,9 @@ var require_constants = __commonJS({
1129
1129
  }
1130
1130
  });
1131
1131
 
1132
- // node_modules/@supabase/realtime-js/dist/main/lib/serializer.js
1132
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/lib/serializer.js
1133
1133
  var require_serializer = __commonJS({
1134
- "node_modules/@supabase/realtime-js/dist/main/lib/serializer.js"(exports2) {
1134
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/lib/serializer.js"(exports2) {
1135
1135
  "use strict";
1136
1136
  Object.defineProperty(exports2, "__esModule", { value: true });
1137
1137
  var Serializer = class {
@@ -1283,9 +1283,9 @@ var require_serializer = __commonJS({
1283
1283
  }
1284
1284
  });
1285
1285
 
1286
- // node_modules/@supabase/realtime-js/dist/main/lib/transformers.js
1286
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/lib/transformers.js
1287
1287
  var require_transformers = __commonJS({
1288
- "node_modules/@supabase/realtime-js/dist/main/lib/transformers.js"(exports2) {
1288
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/lib/transformers.js"(exports2) {
1289
1289
  "use strict";
1290
1290
  Object.defineProperty(exports2, "__esModule", { value: true });
1291
1291
  exports2.httpEndpointURL = exports2.toTimestampString = exports2.toArray = exports2.toJson = exports2.toNumber = exports2.toBoolean = exports2.convertCell = exports2.convertColumn = exports2.convertChangeData = exports2.PostgresTypes = void 0;
@@ -1462,9 +1462,9 @@ var require_transformers = __commonJS({
1462
1462
  }
1463
1463
  });
1464
1464
 
1465
- // node_modules/@supabase/phoenix/priv/static/phoenix.cjs.js
1465
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/phoenix/priv/static/phoenix.cjs.js
1466
1466
  var require_phoenix_cjs = __commonJS({
1467
- "node_modules/@supabase/phoenix/priv/static/phoenix.cjs.js"(exports2, module2) {
1467
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/phoenix/priv/static/phoenix.cjs.js"(exports2, module2) {
1468
1468
  "use strict";
1469
1469
  var __defProp2 = Object.defineProperty;
1470
1470
  var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
@@ -3314,9 +3314,9 @@ var require_phoenix_cjs = __commonJS({
3314
3314
  }
3315
3315
  });
3316
3316
 
3317
- // node_modules/@supabase/realtime-js/dist/main/phoenix/presenceAdapter.js
3317
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/phoenix/presenceAdapter.js
3318
3318
  var require_presenceAdapter = __commonJS({
3319
- "node_modules/@supabase/realtime-js/dist/main/phoenix/presenceAdapter.js"(exports2) {
3319
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/phoenix/presenceAdapter.js"(exports2) {
3320
3320
  "use strict";
3321
3321
  Object.defineProperty(exports2, "__esModule", { value: true });
3322
3322
  var phoenix_1 = require_phoenix_cjs();
@@ -3412,9 +3412,9 @@ var require_presenceAdapter = __commonJS({
3412
3412
  }
3413
3413
  });
3414
3414
 
3415
- // node_modules/@supabase/realtime-js/dist/main/RealtimePresence.js
3415
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/RealtimePresence.js
3416
3416
  var require_RealtimePresence = __commonJS({
3417
- "node_modules/@supabase/realtime-js/dist/main/RealtimePresence.js"(exports2) {
3417
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/RealtimePresence.js"(exports2) {
3418
3418
  "use strict";
3419
3419
  Object.defineProperty(exports2, "__esModule", { value: true });
3420
3420
  exports2.REALTIME_PRESENCE_LISTEN_EVENTS = void 0;
@@ -3456,9 +3456,9 @@ var require_RealtimePresence = __commonJS({
3456
3456
  }
3457
3457
  });
3458
3458
 
3459
- // node_modules/@supabase/realtime-js/dist/main/lib/normalizeChannelError.js
3459
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/lib/normalizeChannelError.js
3460
3460
  var require_normalizeChannelError = __commonJS({
3461
- "node_modules/@supabase/realtime-js/dist/main/lib/normalizeChannelError.js"(exports2) {
3461
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/lib/normalizeChannelError.js"(exports2) {
3462
3462
  "use strict";
3463
3463
  Object.defineProperty(exports2, "__esModule", { value: true });
3464
3464
  exports2.normalizeChannelError = normalizeChannelError;
@@ -3482,9 +3482,9 @@ var require_normalizeChannelError = __commonJS({
3482
3482
  }
3483
3483
  });
3484
3484
 
3485
- // node_modules/@supabase/realtime-js/dist/main/phoenix/channelAdapter.js
3485
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/phoenix/channelAdapter.js
3486
3486
  var require_channelAdapter = __commonJS({
3487
- "node_modules/@supabase/realtime-js/dist/main/phoenix/channelAdapter.js"(exports2) {
3487
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/phoenix/channelAdapter.js"(exports2) {
3488
3488
  "use strict";
3489
3489
  Object.defineProperty(exports2, "__esModule", { value: true });
3490
3490
  var constants_1 = require_constants();
@@ -3589,9 +3589,9 @@ var require_channelAdapter = __commonJS({
3589
3589
  }
3590
3590
  });
3591
3591
 
3592
- // node_modules/@supabase/realtime-js/dist/main/RealtimePostgresFilterBuilder.js
3592
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/RealtimePostgresFilterBuilder.js
3593
3593
  var require_RealtimePostgresFilterBuilder = __commonJS({
3594
- "node_modules/@supabase/realtime-js/dist/main/RealtimePostgresFilterBuilder.js"(exports2) {
3594
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/RealtimePostgresFilterBuilder.js"(exports2) {
3595
3595
  "use strict";
3596
3596
  Object.defineProperty(exports2, "__esModule", { value: true });
3597
3597
  exports2.postgresChangesFilter = exports2.RealtimePostgresFilterBuilder = void 0;
@@ -3713,9 +3713,9 @@ var require_RealtimePostgresFilterBuilder = __commonJS({
3713
3713
  }
3714
3714
  });
3715
3715
 
3716
- // node_modules/@supabase/realtime-js/dist/main/RealtimeChannel.js
3716
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/RealtimeChannel.js
3717
3717
  var require_RealtimeChannel = __commonJS({
3718
- "node_modules/@supabase/realtime-js/dist/main/RealtimeChannel.js"(exports2) {
3718
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/RealtimeChannel.js"(exports2) {
3719
3719
  "use strict";
3720
3720
  Object.defineProperty(exports2, "__esModule", { value: true });
3721
3721
  exports2.REALTIME_CHANNEL_STATES = exports2.REALTIME_SUBSCRIBE_STATES = exports2.REALTIME_LISTEN_TYPES = exports2.REALTIME_POSTGRES_CHANGES_LISTEN_EVENT = exports2.postgresChangesFilter = exports2.RealtimePostgresFilterBuilder = void 0;
@@ -4444,9 +4444,9 @@ var require_RealtimeChannel = __commonJS({
4444
4444
  }
4445
4445
  });
4446
4446
 
4447
- // node_modules/@supabase/realtime-js/dist/main/phoenix/socketAdapter.js
4447
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/phoenix/socketAdapter.js
4448
4448
  var require_socketAdapter = __commonJS({
4449
- "node_modules/@supabase/realtime-js/dist/main/phoenix/socketAdapter.js"(exports2) {
4449
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/phoenix/socketAdapter.js"(exports2) {
4450
4450
  "use strict";
4451
4451
  Object.defineProperty(exports2, "__esModule", { value: true });
4452
4452
  var phoenix_1 = require_phoenix_cjs();
@@ -4562,9 +4562,9 @@ var require_socketAdapter = __commonJS({
4562
4562
  }
4563
4563
  });
4564
4564
 
4565
- // node_modules/@supabase/realtime-js/dist/main/RealtimeClient.js
4565
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/RealtimeClient.js
4566
4566
  var require_RealtimeClient = __commonJS({
4567
- "node_modules/@supabase/realtime-js/dist/main/RealtimeClient.js"(exports2) {
4567
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/RealtimeClient.js"(exports2) {
4568
4568
  "use strict";
4569
4569
  Object.defineProperty(exports2, "__esModule", { value: true });
4570
4570
  var tslib_1 = (init_tslib_es6(), __toCommonJS(tslib_es6_exports));
@@ -5216,9 +5216,9 @@ var require_RealtimeClient = __commonJS({
5216
5216
  }
5217
5217
  });
5218
5218
 
5219
- // node_modules/@supabase/realtime-js/dist/main/index.js
5219
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/index.js
5220
5220
  var require_main2 = __commonJS({
5221
- "node_modules/@supabase/realtime-js/dist/main/index.js"(exports2) {
5221
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/realtime-js/dist/main/index.js"(exports2) {
5222
5222
  "use strict";
5223
5223
  Object.defineProperty(exports2, "__esModule", { value: true });
5224
5224
  exports2.WebSocketFactory = exports2.REALTIME_CHANNEL_STATES = exports2.REALTIME_SUBSCRIBE_STATES = exports2.REALTIME_PRESENCE_LISTEN_EVENTS = exports2.REALTIME_POSTGRES_CHANGES_LISTEN_EVENT = exports2.REALTIME_LISTEN_TYPES = exports2.postgresChangesFilter = exports2.RealtimePostgresFilterBuilder = exports2.RealtimeClient = exports2.RealtimeChannel = exports2.RealtimePresence = void 0;
@@ -5255,9 +5255,9 @@ var require_main2 = __commonJS({
5255
5255
  }
5256
5256
  });
5257
5257
 
5258
- // node_modules/@supabase/auth-js/dist/main/lib/version.js
5258
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/version.js
5259
5259
  var require_version2 = __commonJS({
5260
- "node_modules/@supabase/auth-js/dist/main/lib/version.js"(exports2) {
5260
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/version.js"(exports2) {
5261
5261
  "use strict";
5262
5262
  Object.defineProperty(exports2, "__esModule", { value: true });
5263
5263
  exports2.version = void 0;
@@ -5265,9 +5265,9 @@ var require_version2 = __commonJS({
5265
5265
  }
5266
5266
  });
5267
5267
 
5268
- // node_modules/@supabase/auth-js/dist/main/lib/constants.js
5268
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/constants.js
5269
5269
  var require_constants2 = __commonJS({
5270
- "node_modules/@supabase/auth-js/dist/main/lib/constants.js"(exports2) {
5270
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/constants.js"(exports2) {
5271
5271
  "use strict";
5272
5272
  Object.defineProperty(exports2, "__esModule", { value: true });
5273
5273
  exports2.JWKS_TTL = exports2.BASE64URL_REGEX = exports2.API_VERSIONS = exports2.API_VERSION_HEADER_NAME = exports2.NETWORK_FAILURE = exports2.DEFAULT_HEADERS = exports2.AUDIENCE = exports2.STORAGE_KEY = exports2.GOTRUE_URL = exports2.REFRESH_FAILURE_COOLDOWN_MS = exports2.EXPIRY_MARGIN_MS = exports2.AUTO_REFRESH_TICK_THRESHOLD = exports2.AUTO_REFRESH_TICK_DURATION_MS = void 0;
@@ -5297,9 +5297,9 @@ var require_constants2 = __commonJS({
5297
5297
  }
5298
5298
  });
5299
5299
 
5300
- // node_modules/@supabase/auth-js/dist/main/lib/errors.js
5300
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/errors.js
5301
5301
  var require_errors = __commonJS({
5302
- "node_modules/@supabase/auth-js/dist/main/lib/errors.js"(exports2) {
5302
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/errors.js"(exports2) {
5303
5303
  "use strict";
5304
5304
  Object.defineProperty(exports2, "__esModule", { value: true });
5305
5305
  exports2.AuthInvalidJwtError = exports2.AuthWeakPasswordError = exports2.AuthRefreshDiscardedError = exports2.AuthRetryableFetchError = exports2.AuthPKCECodeVerifierMissingError = exports2.AuthPKCEGrantCodeExchangeError = exports2.AuthImplicitGrantRedirectError = exports2.AuthInvalidCredentialsError = exports2.AuthInvalidTokenResponseError = exports2.AuthSessionMissingError = exports2.CustomAuthError = exports2.AuthUnknownError = exports2.AuthApiError = exports2.AuthError = void 0;
@@ -5455,9 +5455,9 @@ var require_errors = __commonJS({
5455
5455
  }
5456
5456
  });
5457
5457
 
5458
- // node_modules/@supabase/auth-js/dist/main/lib/base64url.js
5458
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/base64url.js
5459
5459
  var require_base64url = __commonJS({
5460
- "node_modules/@supabase/auth-js/dist/main/lib/base64url.js"(exports2) {
5460
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/base64url.js"(exports2) {
5461
5461
  "use strict";
5462
5462
  Object.defineProperty(exports2, "__esModule", { value: true });
5463
5463
  exports2.byteToBase64URL = byteToBase64URL;
@@ -5645,9 +5645,9 @@ var require_base64url = __commonJS({
5645
5645
  }
5646
5646
  });
5647
5647
 
5648
- // node_modules/@supabase/auth-js/dist/main/lib/helpers.js
5648
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/helpers.js
5649
5649
  var require_helpers = __commonJS({
5650
- "node_modules/@supabase/auth-js/dist/main/lib/helpers.js"(exports2) {
5650
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/helpers.js"(exports2) {
5651
5651
  "use strict";
5652
5652
  Object.defineProperty(exports2, "__esModule", { value: true });
5653
5653
  exports2.Deferred = exports2.removeItemAsync = exports2.getItemAsync = exports2.setItemAsync = exports2.looksLikeFetchResponse = exports2.resolveFetch = exports2.supportsLocalStorage = exports2.isBrowser = void 0;
@@ -5967,9 +5967,9 @@ var require_helpers = __commonJS({
5967
5967
  }
5968
5968
  });
5969
5969
 
5970
- // node_modules/@supabase/auth-js/dist/main/lib/fetch.js
5970
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/fetch.js
5971
5971
  var require_fetch = __commonJS({
5972
- "node_modules/@supabase/auth-js/dist/main/lib/fetch.js"(exports2) {
5972
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/fetch.js"(exports2) {
5973
5973
  "use strict";
5974
5974
  Object.defineProperty(exports2, "__esModule", { value: true });
5975
5975
  exports2.handleError = handleError2;
@@ -6151,9 +6151,9 @@ var require_fetch = __commonJS({
6151
6151
  }
6152
6152
  });
6153
6153
 
6154
- // node_modules/@supabase/auth-js/dist/main/lib/types.js
6154
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/types.js
6155
6155
  var require_types2 = __commonJS({
6156
- "node_modules/@supabase/auth-js/dist/main/lib/types.js"(exports2) {
6156
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/types.js"(exports2) {
6157
6157
  "use strict";
6158
6158
  Object.defineProperty(exports2, "__esModule", { value: true });
6159
6159
  exports2.SIGN_OUT_SCOPES = void 0;
@@ -6161,9 +6161,9 @@ var require_types2 = __commonJS({
6161
6161
  }
6162
6162
  });
6163
6163
 
6164
- // node_modules/@supabase/auth-js/dist/main/GoTrueAdminApi.js
6164
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/GoTrueAdminApi.js
6165
6165
  var require_GoTrueAdminApi = __commonJS({
6166
- "node_modules/@supabase/auth-js/dist/main/GoTrueAdminApi.js"(exports2) {
6166
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/GoTrueAdminApi.js"(exports2) {
6167
6167
  "use strict";
6168
6168
  Object.defineProperty(exports2, "__esModule", { value: true });
6169
6169
  var tslib_1 = (init_tslib_es6(), __toCommonJS(tslib_es6_exports));
@@ -7247,9 +7247,9 @@ var require_GoTrueAdminApi = __commonJS({
7247
7247
  }
7248
7248
  });
7249
7249
 
7250
- // node_modules/@supabase/auth-js/dist/main/lib/local-storage.js
7250
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/local-storage.js
7251
7251
  var require_local_storage = __commonJS({
7252
- "node_modules/@supabase/auth-js/dist/main/lib/local-storage.js"(exports2) {
7252
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/local-storage.js"(exports2) {
7253
7253
  "use strict";
7254
7254
  Object.defineProperty(exports2, "__esModule", { value: true });
7255
7255
  exports2.memoryLocalStorageAdapter = memoryLocalStorageAdapter;
@@ -7269,9 +7269,9 @@ var require_local_storage = __commonJS({
7269
7269
  }
7270
7270
  });
7271
7271
 
7272
- // node_modules/@supabase/auth-js/dist/main/lib/locks.js
7272
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/locks.js
7273
7273
  var require_locks = __commonJS({
7274
- "node_modules/@supabase/auth-js/dist/main/lib/locks.js"(exports2) {
7274
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/locks.js"(exports2) {
7275
7275
  "use strict";
7276
7276
  Object.defineProperty(exports2, "__esModule", { value: true });
7277
7277
  exports2.ProcessLockAcquireTimeoutError = exports2.NavigatorLockAcquireTimeoutError = exports2.LockAcquireTimeoutError = exports2.internals = void 0;
@@ -7447,9 +7447,9 @@ var require_locks = __commonJS({
7447
7447
  }
7448
7448
  });
7449
7449
 
7450
- // node_modules/@supabase/auth-js/dist/main/lib/polyfills.js
7450
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/polyfills.js
7451
7451
  var require_polyfills = __commonJS({
7452
- "node_modules/@supabase/auth-js/dist/main/lib/polyfills.js"(exports2) {
7452
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/polyfills.js"(exports2) {
7453
7453
  "use strict";
7454
7454
  Object.defineProperty(exports2, "__esModule", { value: true });
7455
7455
  exports2.polyfillGlobalThis = polyfillGlobalThis;
@@ -7474,9 +7474,9 @@ var require_polyfills = __commonJS({
7474
7474
  }
7475
7475
  });
7476
7476
 
7477
- // node_modules/@supabase/auth-js/dist/main/lib/web3/ethereum.js
7477
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/web3/ethereum.js
7478
7478
  var require_ethereum = __commonJS({
7479
- "node_modules/@supabase/auth-js/dist/main/lib/web3/ethereum.js"(exports2) {
7479
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/web3/ethereum.js"(exports2) {
7480
7480
  "use strict";
7481
7481
  Object.defineProperty(exports2, "__esModule", { value: true });
7482
7482
  exports2.getAddress = getAddress;
@@ -7552,9 +7552,9 @@ ${suffix}`;
7552
7552
  }
7553
7553
  });
7554
7554
 
7555
- // node_modules/@supabase/auth-js/dist/main/lib/webauthn.errors.js
7555
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/webauthn.errors.js
7556
7556
  var require_webauthn_errors = __commonJS({
7557
- "node_modules/@supabase/auth-js/dist/main/lib/webauthn.errors.js"(exports2) {
7557
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/webauthn.errors.js"(exports2) {
7558
7558
  "use strict";
7559
7559
  Object.defineProperty(exports2, "__esModule", { value: true });
7560
7560
  exports2.WebAuthnUnknownError = exports2.WebAuthnError = void 0;
@@ -7743,9 +7743,9 @@ var require_webauthn_errors = __commonJS({
7743
7743
  }
7744
7744
  });
7745
7745
 
7746
- // node_modules/@supabase/auth-js/dist/main/lib/webauthn.js
7746
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/webauthn.js
7747
7747
  var require_webauthn = __commonJS({
7748
- "node_modules/@supabase/auth-js/dist/main/lib/webauthn.js"(exports2) {
7748
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/lib/webauthn.js"(exports2) {
7749
7749
  "use strict";
7750
7750
  Object.defineProperty(exports2, "__esModule", { value: true });
7751
7751
  exports2.WebAuthnApi = exports2.DEFAULT_REQUEST_OPTIONS = exports2.DEFAULT_CREATION_OPTIONS = exports2.webAuthnAbortService = exports2.WebAuthnAbortService = exports2.identifyAuthenticationError = exports2.identifyRegistrationError = exports2.isWebAuthnError = exports2.WebAuthnError = void 0;
@@ -8302,9 +8302,9 @@ var require_webauthn = __commonJS({
8302
8302
  }
8303
8303
  });
8304
8304
 
8305
- // node_modules/@supabase/auth-js/dist/main/GoTrueClient.js
8305
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/GoTrueClient.js
8306
8306
  var require_GoTrueClient = __commonJS({
8307
- "node_modules/@supabase/auth-js/dist/main/GoTrueClient.js"(exports2) {
8307
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/GoTrueClient.js"(exports2) {
8308
8308
  "use strict";
8309
8309
  Object.defineProperty(exports2, "__esModule", { value: true });
8310
8310
  var tslib_1 = (init_tslib_es6(), __toCommonJS(tslib_es6_exports));
@@ -13442,9 +13442,9 @@ var require_GoTrueClient = __commonJS({
13442
13442
  }
13443
13443
  });
13444
13444
 
13445
- // node_modules/@supabase/auth-js/dist/main/AuthAdminApi.js
13445
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/AuthAdminApi.js
13446
13446
  var require_AuthAdminApi = __commonJS({
13447
- "node_modules/@supabase/auth-js/dist/main/AuthAdminApi.js"(exports2) {
13447
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/AuthAdminApi.js"(exports2) {
13448
13448
  "use strict";
13449
13449
  Object.defineProperty(exports2, "__esModule", { value: true });
13450
13450
  var tslib_1 = (init_tslib_es6(), __toCommonJS(tslib_es6_exports));
@@ -13454,9 +13454,9 @@ var require_AuthAdminApi = __commonJS({
13454
13454
  }
13455
13455
  });
13456
13456
 
13457
- // node_modules/@supabase/auth-js/dist/main/AuthClient.js
13457
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/AuthClient.js
13458
13458
  var require_AuthClient = __commonJS({
13459
- "node_modules/@supabase/auth-js/dist/main/AuthClient.js"(exports2) {
13459
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/AuthClient.js"(exports2) {
13460
13460
  "use strict";
13461
13461
  Object.defineProperty(exports2, "__esModule", { value: true });
13462
13462
  var tslib_1 = (init_tslib_es6(), __toCommonJS(tslib_es6_exports));
@@ -13466,9 +13466,9 @@ var require_AuthClient = __commonJS({
13466
13466
  }
13467
13467
  });
13468
13468
 
13469
- // node_modules/@supabase/auth-js/dist/main/index.js
13469
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/index.js
13470
13470
  var require_main3 = __commonJS({
13471
- "node_modules/@supabase/auth-js/dist/main/index.js"(exports2) {
13471
+ "../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/auth-js/dist/main/index.js"(exports2) {
13472
13472
  "use strict";
13473
13473
  Object.defineProperty(exports2, "__esModule", { value: true });
13474
13474
  exports2.processLock = exports2.lockInternals = exports2.NavigatorLockAcquireTimeoutError = exports2.navigatorLock = exports2.AuthClient = exports2.AuthAdminApi = exports2.GoTrueClient = exports2.GoTrueAdminApi = void 0;
@@ -13535,7 +13535,7 @@ var import_node_crypto2 = require("node:crypto");
13535
13535
  var import_node_http = require("node:http");
13536
13536
  var import_node_child_process = require("node:child_process");
13537
13537
 
13538
- // node_modules/@supabase/supabase-js/dist/index.mjs
13538
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/supabase-js/dist/index.mjs
13539
13539
  var dist_exports = {};
13540
13540
  __export(dist_exports, {
13541
13541
  FunctionRegion: () => import_functions_js.FunctionRegion,
@@ -13550,7 +13550,7 @@ __export(dist_exports, {
13550
13550
  });
13551
13551
  var import_functions_js = __toESM(require_main(), 1);
13552
13552
 
13553
- // node_modules/@supabase/postgrest-js/dist/index.mjs
13553
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/postgrest-js/dist/index.mjs
13554
13554
  var DEFAULT_MAX_RETRIES = 3;
13555
13555
  var getRetryDelay = (attemptIndex) => Math.min(1e3 * 2 ** attemptIndex, 3e4);
13556
13556
  var RETRYABLE_STATUS_CODES = [520, 503];
@@ -17328,10 +17328,10 @@ var PostgrestClient = class PostgrestClient2 {
17328
17328
  }
17329
17329
  };
17330
17330
 
17331
- // node_modules/@supabase/supabase-js/dist/index.mjs
17331
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/supabase-js/dist/index.mjs
17332
17332
  var import_realtime_js = __toESM(require_main2(), 1);
17333
17333
 
17334
- // node_modules/iceberg-js/dist/index.mjs
17334
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/iceberg-js/dist/index.mjs
17335
17335
  var IcebergError = class extends Error {
17336
17336
  constructor(message, opts) {
17337
17337
  super(message);
@@ -17864,7 +17864,7 @@ var IcebergRestCatalog = class {
17864
17864
  }
17865
17865
  };
17866
17866
 
17867
- // node_modules/@supabase/storage-js/dist/index.mjs
17867
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/storage-js/dist/index.mjs
17868
17868
  function _typeof2(o) {
17869
17869
  "@babel/helpers - typeof";
17870
17870
  return _typeof2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
@@ -20656,7 +20656,7 @@ var StorageClient = class extends StorageBucketApi {
20656
20656
  }
20657
20657
  };
20658
20658
 
20659
- // node_modules/@supabase/supabase-js/dist/index.mjs
20659
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/@supabase/supabase-js/dist/index.mjs
20660
20660
  var import_auth_js = __toESM(require_main3(), 1);
20661
20661
  __reExport(dist_exports, __toESM(require_main2(), 1));
20662
20662
  __reExport(dist_exports, __toESM(require_main3(), 1));
@@ -24061,11 +24061,11 @@ async function resolveCloudTarget(options) {
24061
24061
  // src/cloud/seed.ts
24062
24062
  var import_node_crypto7 = require("node:crypto");
24063
24063
 
24064
- // node_modules/postgres/src/index.js
24064
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/postgres/src/index.js
24065
24065
  var import_os = __toESM(require("os"), 1);
24066
24066
  var import_fs = __toESM(require("fs"), 1);
24067
24067
 
24068
- // node_modules/postgres/src/query.js
24068
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/postgres/src/query.js
24069
24069
  var originCache = /* @__PURE__ */ new Map();
24070
24070
  var originStackCache = /* @__PURE__ */ new Map();
24071
24071
  var originError = /* @__PURE__ */ Symbol("OriginError");
@@ -24202,7 +24202,7 @@ function cachedError(xs) {
24202
24202
  return originCache.get(xs);
24203
24203
  }
24204
24204
 
24205
- // node_modules/postgres/src/errors.js
24205
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/postgres/src/errors.js
24206
24206
  var PostgresError = class extends Error {
24207
24207
  constructor(x) {
24208
24208
  super(x.message);
@@ -24252,7 +24252,7 @@ function notSupported(x) {
24252
24252
  return error;
24253
24253
  }
24254
24254
 
24255
- // node_modules/postgres/src/types.js
24255
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/postgres/src/types.js
24256
24256
  var types = {
24257
24257
  string: {
24258
24258
  to: 25,
@@ -24538,14 +24538,14 @@ fromKebab.column = { to: fromKebab };
24538
24538
  var kebab = { ...toKebab };
24539
24539
  kebab.column.to = fromKebab;
24540
24540
 
24541
- // node_modules/postgres/src/connection.js
24541
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/postgres/src/connection.js
24542
24542
  var import_net = __toESM(require("net"), 1);
24543
24543
  var import_tls = __toESM(require("tls"), 1);
24544
24544
  var import_crypto = __toESM(require("crypto"), 1);
24545
24545
  var import_stream = __toESM(require("stream"), 1);
24546
24546
  var import_perf_hooks = require("perf_hooks");
24547
24547
 
24548
- // node_modules/postgres/src/result.js
24548
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/postgres/src/result.js
24549
24549
  var Result = class extends Array {
24550
24550
  constructor() {
24551
24551
  super();
@@ -24562,7 +24562,7 @@ var Result = class extends Array {
24562
24562
  }
24563
24563
  };
24564
24564
 
24565
- // node_modules/postgres/src/queue.js
24565
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/postgres/src/queue.js
24566
24566
  var queue_default = Queue;
24567
24567
  function Queue(initial = []) {
24568
24568
  let xs = initial.slice();
@@ -24589,7 +24589,7 @@ function Queue(initial = []) {
24589
24589
  };
24590
24590
  }
24591
24591
 
24592
- // node_modules/postgres/src/bytes.js
24592
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/postgres/src/bytes.js
24593
24593
  var size = 256;
24594
24594
  var buffer = Buffer.allocUnsafe(size);
24595
24595
  var messages = "BCcDdEFfHPpQSX".split("").reduce((acc, x) => {
@@ -24662,7 +24662,7 @@ function reset() {
24662
24662
  return b;
24663
24663
  }
24664
24664
 
24665
- // node_modules/postgres/src/connection.js
24665
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/postgres/src/connection.js
24666
24666
  var connection_default = Connection;
24667
24667
  var uid = 1;
24668
24668
  var Sync = bytes_default().S().end();
@@ -25502,7 +25502,7 @@ function timer(fn, seconds) {
25502
25502
  }
25503
25503
  }
25504
25504
 
25505
- // node_modules/postgres/src/subscribe.js
25505
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/postgres/src/subscribe.js
25506
25506
  var noop2 = () => {
25507
25507
  };
25508
25508
  function Subscribe(postgres2, options) {
@@ -25714,7 +25714,7 @@ function parseEvent(x) {
25714
25714
  return (command2 || "*") + (path ? ":" + (path.indexOf(".") === -1 ? "public." + path : path) : "") + (key2 ? "=" + key2 : "");
25715
25715
  }
25716
25716
 
25717
- // node_modules/postgres/src/large.js
25717
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/postgres/src/large.js
25718
25718
  var import_stream2 = __toESM(require("stream"), 1);
25719
25719
  function largeObject(sql, oid, mode3 = 131072 | 262144) {
25720
25720
  return new Promise(async (resolve3, reject) => {
@@ -25780,7 +25780,7 @@ function largeObject(sql, oid, mode3 = 131072 | 262144) {
25780
25780
  });
25781
25781
  }
25782
25782
 
25783
- // node_modules/postgres/src/index.js
25783
+ // ../../../../../../../Users/yulanbot/Developer/Ridge.io/cloud-swarm/node_modules/postgres/src/index.js
25784
25784
  Object.assign(Postgres, {
25785
25785
  PostgresError,
25786
25786
  toPascal,
@@ -31078,6 +31078,598 @@ function signalReceiptJsonPayload(report, nowMs = Date.now()) {
31078
31078
  };
31079
31079
  }
31080
31080
 
31081
+ // src/cloud/delivery.ts
31082
+ var UUID_RE13 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
31083
+ var RFC3339_TIMESTAMP_RE = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:Z|([+-]\d{2}):(\d{2}))$/i;
31084
+ var DELIVERY_KINDS = /* @__PURE__ */ new Set(["ask", "note"]);
31085
+ var SENDER_OWNER_RELATIONS2 = /* @__PURE__ */ new Set([
31086
+ "same_owner",
31087
+ "cross_owner",
31088
+ "unknown"
31089
+ ]);
31090
+ var DELIVERY_ACK_OUTCOMES = /* @__PURE__ */ new Set([
31091
+ "replied",
31092
+ "observed",
31093
+ "queued",
31094
+ "expired",
31095
+ "failed_terminal"
31096
+ ]);
31097
+ var DELIVERY_HANDLED_OUTCOMES = new Set(
31098
+ [...DELIVERY_ACK_OUTCOMES].filter(
31099
+ (outcome) => outcome === "replied" || outcome === "observed"
31100
+ )
31101
+ );
31102
+ var DELIVERY_PROVIDER_PROVEN_OUTCOMES = new Set(
31103
+ [...DELIVERY_ACK_OUTCOMES].filter((outcome) => outcome === "replied")
31104
+ );
31105
+ function orList(values2) {
31106
+ return values2.length <= 1 ? values2.join("") : `${values2.slice(0, -1).join(", ")}, or ${values2[values2.length - 1]}`;
31107
+ }
31108
+ var DELIVERY_REQUEST_TIMEOUT_MS = 3e4;
31109
+ var COMMAND_ID_VALIDATOR_RE = /^[A-Za-z0-9_-]{8,72}$/;
31110
+ var FAILED_TERMINAL_CODES_SET = /* @__PURE__ */ new Set([
31111
+ "provider_refused",
31112
+ "local_effect_failed",
31113
+ "host_session_failed",
31114
+ "credential_unavailable"
31115
+ ]);
31116
+ var SERVER_ERROR_CODES_SET = /* @__PURE__ */ new Set([
31117
+ "unauthenticated",
31118
+ "fresh_auth_required",
31119
+ "invalid_request",
31120
+ "payload_too_large",
31121
+ "forbidden",
31122
+ "delivery_unavailable",
31123
+ "delivery_ack_conflict",
31124
+ "command_id_conflict",
31125
+ "rate_limited",
31126
+ "upgrade_required",
31127
+ "temporarily_unavailable",
31128
+ "internal_error"
31129
+ ]);
31130
+ var DELIVERY_FAILED_TERMINAL_CODES = Object.freeze([
31131
+ "provider_refused",
31132
+ "local_effect_failed",
31133
+ "host_session_failed",
31134
+ "credential_unavailable"
31135
+ ]);
31136
+ var DELIVERY_SERVER_ERROR_CODES = Object.freeze([
31137
+ "unauthenticated",
31138
+ "fresh_auth_required",
31139
+ "invalid_request",
31140
+ "payload_too_large",
31141
+ "forbidden",
31142
+ "delivery_unavailable",
31143
+ "delivery_ack_conflict",
31144
+ "command_id_conflict",
31145
+ "rate_limited",
31146
+ "upgrade_required",
31147
+ "temporarily_unavailable",
31148
+ "internal_error"
31149
+ ]);
31150
+ var DELIVERY_UNKNOWN_ERROR_CODE = "unknown_error";
31151
+ function observationCommandId(signalId) {
31152
+ checkedUuidRequest(signalId, "signalId");
31153
+ return `observe_${signalId.toLowerCase().replaceAll("-", "")}`;
31154
+ }
31155
+ var DeliveryTransportError = class extends Error {
31156
+ constructor(message) {
31157
+ super(message);
31158
+ this.name = "DeliveryTransportError";
31159
+ }
31160
+ };
31161
+ var DeliveryHttpError = class extends Error {
31162
+ constructor(status, code, message, retryAfterMs = null) {
31163
+ super(message);
31164
+ this.status = status;
31165
+ this.code = code;
31166
+ this.retryAfterMs = retryAfterMs;
31167
+ this.name = "DeliveryHttpError";
31168
+ }
31169
+ status;
31170
+ code;
31171
+ retryAfterMs;
31172
+ };
31173
+ var DeliveryProtocolError = class extends Error {
31174
+ constructor(message) {
31175
+ super(message);
31176
+ this.name = "DeliveryProtocolError";
31177
+ }
31178
+ };
31179
+ function checkedUuid3(value, field) {
31180
+ if (typeof value !== "string" || !UUID_RE13.test(value)) {
31181
+ throw new DeliveryProtocolError(
31182
+ `delivery response returned a malformed ${field}`
31183
+ );
31184
+ }
31185
+ return value.toLowerCase();
31186
+ }
31187
+ function isLeapYear(year) {
31188
+ return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
31189
+ }
31190
+ function daysInMonth(year, month) {
31191
+ switch (month) {
31192
+ case 1:
31193
+ case 3:
31194
+ case 5:
31195
+ case 7:
31196
+ case 8:
31197
+ case 10:
31198
+ case 12:
31199
+ return 31;
31200
+ case 4:
31201
+ case 6:
31202
+ case 9:
31203
+ case 11:
31204
+ return 30;
31205
+ case 2:
31206
+ return isLeapYear(year) ? 29 : 28;
31207
+ default:
31208
+ return 0;
31209
+ }
31210
+ }
31211
+ function checkedRfc3339Timestamp(value, field) {
31212
+ if (typeof value !== "string") {
31213
+ throw new DeliveryProtocolError(
31214
+ `delivery response returned a malformed ${field}`
31215
+ );
31216
+ }
31217
+ const match = RFC3339_TIMESTAMP_RE.exec(value);
31218
+ if (!match) {
31219
+ throw new DeliveryProtocolError(
31220
+ `delivery response returned a malformed ${field}`
31221
+ );
31222
+ }
31223
+ const year = parseInt(match[1], 10);
31224
+ const month = parseInt(match[2], 10);
31225
+ const day = parseInt(match[3], 10);
31226
+ const hour = parseInt(match[4], 10);
31227
+ const minute = parseInt(match[5], 10);
31228
+ const second = parseInt(match[6], 10);
31229
+ if (month < 1 || month > 12 || day < 1 || day > daysInMonth(year, month) || hour < 0 || hour > 23 || minute < 0 || minute > 59 || second < 0 || second > 59) {
31230
+ throw new DeliveryProtocolError(
31231
+ `delivery response returned a malformed ${field}`
31232
+ );
31233
+ }
31234
+ if (match[7] !== void 0 && match[8] !== void 0) {
31235
+ const offsetHour = Math.abs(parseInt(match[7], 10));
31236
+ const offsetMin = parseInt(match[8], 10);
31237
+ if (offsetHour > 23 || offsetMin < 0 || offsetMin > 59) {
31238
+ throw new DeliveryProtocolError(
31239
+ `delivery response returned a malformed ${field}`
31240
+ );
31241
+ }
31242
+ }
31243
+ if (!Number.isFinite(Date.parse(value))) {
31244
+ throw new DeliveryProtocolError(
31245
+ `delivery response returned a malformed ${field}`
31246
+ );
31247
+ }
31248
+ return value;
31249
+ }
31250
+ function checkedLiveLease(leasedUntil, now) {
31251
+ if (Date.parse(leasedUntil) <= now()) {
31252
+ throw new DeliveryProtocolError(
31253
+ "delivery claim response returned an already expired lease"
31254
+ );
31255
+ }
31256
+ }
31257
+ function checkedRelation(value) {
31258
+ if (typeof value !== "string" || !SENDER_OWNER_RELATIONS2.has(value)) {
31259
+ throw new DeliveryProtocolError(
31260
+ "delivery response returned a malformed sender_owner_relation"
31261
+ );
31262
+ }
31263
+ return value;
31264
+ }
31265
+ function checkedNonNegativeCount(value, field) {
31266
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
31267
+ throw new DeliveryProtocolError(
31268
+ `delivery response returned a malformed ${field}`
31269
+ );
31270
+ }
31271
+ return value;
31272
+ }
31273
+ function checkedClaimCapabilities(value) {
31274
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
31275
+ throw new DeliveryProtocolError(
31276
+ "delivery claim response is missing delivery capabilities"
31277
+ );
31278
+ }
31279
+ const row = value;
31280
+ for (const marker of ["delivery_claim", "delivery_ack", "sender_owner_relation"]) {
31281
+ if (row[marker] !== 1) {
31282
+ throw new DeliveryProtocolError(
31283
+ `delivery claim response is missing the ${marker} capability`
31284
+ );
31285
+ }
31286
+ }
31287
+ return { deliveryClaim: true, deliveryAck: true, senderOwnerRelation: true };
31288
+ }
31289
+ function checkedOptionalUuidArray(value, field) {
31290
+ if (value === void 0) return;
31291
+ if (!Array.isArray(value) || value.some((item) => typeof item !== "string" || !UUID_RE13.test(item))) {
31292
+ throw new DeliveryProtocolError(
31293
+ `delivery response returned a malformed ${field}`
31294
+ );
31295
+ }
31296
+ }
31297
+ function checkedOptionalArray(value, field) {
31298
+ if (value === void 0) return;
31299
+ if (!Array.isArray(value)) {
31300
+ throw new DeliveryProtocolError(
31301
+ `delivery response returned a malformed ${field}`
31302
+ );
31303
+ }
31304
+ }
31305
+ function parseDeliveryRow(value, expected, index, now) {
31306
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
31307
+ throw new DeliveryProtocolError(
31308
+ "delivery claim response returned a malformed delivery row"
31309
+ );
31310
+ }
31311
+ const row = value;
31312
+ let signal;
31313
+ try {
31314
+ signal = parseSignalRecord(row.signal);
31315
+ } catch {
31316
+ throw new DeliveryProtocolError(
31317
+ `delivery claim response returned a malformed signal at ${index}`
31318
+ );
31319
+ }
31320
+ if (signal.workspace_id !== expected.workspaceId) {
31321
+ throw new DeliveryProtocolError(
31322
+ "delivery claim response returned a signal for another workspace"
31323
+ );
31324
+ }
31325
+ if (signal.to_agent !== expected.principalId) {
31326
+ throw new DeliveryProtocolError(
31327
+ "delivery claim response returned a signal addressed to another agent"
31328
+ );
31329
+ }
31330
+ if (!DELIVERY_KINDS.has(signal.kind)) {
31331
+ throw new DeliveryProtocolError(
31332
+ "delivery claim response returned a non-direct signal kind"
31333
+ );
31334
+ }
31335
+ const senderOwnerRelation = checkedRelation(row.sender_owner_relation);
31336
+ const leaseId = checkedUuid3(row.lease_id, "lease_id");
31337
+ const leasedUntil = checkedRfc3339Timestamp(row.leased_until, "leased_until");
31338
+ checkedLiveLease(leasedUntil, now);
31339
+ signal.sender_owner_relation = senderOwnerRelation;
31340
+ return { signal, leaseId, leasedUntil, senderOwnerRelation };
31341
+ }
31342
+ function parseClaimSuccess(body, expected, now) {
31343
+ if (!body || typeof body !== "object" || Array.isArray(body)) {
31344
+ throw new DeliveryProtocolError("delivery claim response was not an object");
31345
+ }
31346
+ const row = body;
31347
+ if (row.status !== "accepted" || row.ok !== true) {
31348
+ throw new DeliveryProtocolError(
31349
+ "delivery claim response did not report accepted ok"
31350
+ );
31351
+ }
31352
+ const capabilities = checkedClaimCapabilities(row.capabilities);
31353
+ checkedOptionalUuidArray(row.event_ids, "event_ids");
31354
+ checkedOptionalArray(row.events, "events");
31355
+ if (!Array.isArray(row.deliveries)) {
31356
+ throw new DeliveryProtocolError(
31357
+ "delivery claim response is missing its deliveries array"
31358
+ );
31359
+ }
31360
+ const deliveries = row.deliveries.map(
31361
+ (item, index) => parseDeliveryRow(item, expected, index, now)
31362
+ );
31363
+ const signalIds = /* @__PURE__ */ new Set();
31364
+ const leaseIds = /* @__PURE__ */ new Set();
31365
+ for (const delivery of deliveries) {
31366
+ if (signalIds.has(delivery.signal.id)) {
31367
+ throw new DeliveryProtocolError(
31368
+ "delivery claim response repeats a signal id"
31369
+ );
31370
+ }
31371
+ signalIds.add(delivery.signal.id);
31372
+ if (leaseIds.has(delivery.leaseId)) {
31373
+ throw new DeliveryProtocolError(
31374
+ "delivery claim response repeats a lease id"
31375
+ );
31376
+ }
31377
+ leaseIds.add(delivery.leaseId);
31378
+ }
31379
+ if (deliveries.length > 1) {
31380
+ throw new DeliveryProtocolError(
31381
+ "delivery claim response returned more than one delivery"
31382
+ );
31383
+ }
31384
+ const pendingDeliveryCount = checkedNonNegativeCount(
31385
+ row.pending_delivery_count,
31386
+ "pending_delivery_count"
31387
+ );
31388
+ const terminalDeliveryFailureCount = checkedNonNegativeCount(
31389
+ row.terminal_delivery_failure_count,
31390
+ "terminal_delivery_failure_count"
31391
+ );
31392
+ if (deliveries.length > pendingDeliveryCount) {
31393
+ throw new DeliveryProtocolError(
31394
+ "delivery claim response returned more deliveries than its pending count"
31395
+ );
31396
+ }
31397
+ return {
31398
+ capabilities,
31399
+ deliveries,
31400
+ pendingDeliveryCount,
31401
+ terminalDeliveryFailureCount
31402
+ };
31403
+ }
31404
+ function parseAckSuccess(body, expected) {
31405
+ if (!body || typeof body !== "object" || Array.isArray(body)) {
31406
+ throw new DeliveryProtocolError(
31407
+ "delivery acknowledgement response was not an object"
31408
+ );
31409
+ }
31410
+ const row = body;
31411
+ if (row.status !== "accepted" || row.ok !== true) {
31412
+ throw new DeliveryProtocolError(
31413
+ "delivery acknowledgement response did not report accepted ok"
31414
+ );
31415
+ }
31416
+ checkedOptionalUuidArray(row.event_ids, "event_ids");
31417
+ checkedOptionalArray(row.events, "events");
31418
+ if (row.signal_id !== expected.signalId) {
31419
+ throw new DeliveryProtocolError(
31420
+ "delivery acknowledgement response echoed a different signal id"
31421
+ );
31422
+ }
31423
+ if (row.outcome !== expected.outcome) {
31424
+ throw new DeliveryProtocolError(
31425
+ "delivery acknowledgement response echoed a different outcome"
31426
+ );
31427
+ }
31428
+ }
31429
+ function checkedCommandId(value) {
31430
+ if (typeof value !== "string" || !COMMAND_ID_VALIDATOR_RE.test(value)) {
31431
+ throw new Error(
31432
+ "a delivery command id must be 8..72 characters of [A-Za-z0-9_-]"
31433
+ );
31434
+ }
31435
+ return value;
31436
+ }
31437
+ function checkedUuidRequest(value, field) {
31438
+ if (!UUID_RE13.test(value)) {
31439
+ throw new Error(`${field} must be a UUID for an agent delivery command`);
31440
+ }
31441
+ }
31442
+ function assertAckRequest(request) {
31443
+ checkedCommandId(request.commandId);
31444
+ assertAgentToken(request.credential);
31445
+ checkedUuidRequest(request.workspaceId, "workspaceId");
31446
+ checkedUuidRequest(request.signalId, "signalId");
31447
+ checkedUuidRequest(request.leaseId, "leaseId");
31448
+ checkedUuidRequest(request.listenerInstanceId, "listenerInstanceId");
31449
+ if (!DELIVERY_ACK_OUTCOMES.has(request.outcome)) {
31450
+ throw new Error(
31451
+ `a delivery outcome must be ${orList([...DELIVERY_ACK_OUTCOMES])}`
31452
+ );
31453
+ }
31454
+ if (request.outcome === "failed_terminal") {
31455
+ if (typeof request.lastErrorCode !== "string" || !FAILED_TERMINAL_CODES_SET.has(request.lastErrorCode)) {
31456
+ throw new Error(
31457
+ `a failed_terminal acknowledgement requires one of ${orList([...FAILED_TERMINAL_CODES_SET])}`
31458
+ );
31459
+ }
31460
+ } else if (request.lastErrorCode !== null) {
31461
+ throw new Error(
31462
+ "a non-failed acknowledgement must send lastErrorCode null"
31463
+ );
31464
+ }
31465
+ }
31466
+ function boundedDeliveryErrorCode(body) {
31467
+ if (!body || typeof body !== "object" || Array.isArray(body)) {
31468
+ return DELIVERY_UNKNOWN_ERROR_CODE;
31469
+ }
31470
+ const error = body.error;
31471
+ if (typeof error === "string" && SERVER_ERROR_CODES_SET.has(error)) {
31472
+ return error;
31473
+ }
31474
+ return DELIVERY_UNKNOWN_ERROR_CODE;
31475
+ }
31476
+ function refusal(response, text) {
31477
+ let code = DELIVERY_UNKNOWN_ERROR_CODE;
31478
+ try {
31479
+ code = boundedDeliveryErrorCode(JSON.parse(text));
31480
+ } catch {
31481
+ }
31482
+ const retryAfterMs = parseRetryAfterMs(response.headers.get("retry-after"));
31483
+ return new DeliveryHttpError(
31484
+ response.status,
31485
+ code,
31486
+ `delivery command failed (HTTP ${response.status}): ${code}`,
31487
+ retryAfterMs
31488
+ );
31489
+ }
31490
+ function successBody(response, text, verb) {
31491
+ try {
31492
+ return JSON.parse(text);
31493
+ } catch {
31494
+ throw new DeliveryProtocolError(
31495
+ `${verb} response was not JSON (HTTP ${response.status})`
31496
+ );
31497
+ }
31498
+ }
31499
+ var DeliveryCommandClient = class {
31500
+ constructor(target2, fetcher = fetch, options = {}) {
31501
+ this.target = target2;
31502
+ this.fetcher = fetcher;
31503
+ this.deadlineMs = options.deadlineMs ?? DELIVERY_REQUEST_TIMEOUT_MS;
31504
+ this.now = options.now ?? Date.now;
31505
+ this.clearTimeoutFn = options.clearTimeout ?? ((timer2) => clearTimeout(timer2));
31506
+ this.createAbortControllerFn = options.createAbortController ?? (() => new AbortController());
31507
+ }
31508
+ target;
31509
+ fetcher;
31510
+ deadlineMs;
31511
+ now;
31512
+ clearTimeoutFn;
31513
+ createAbortControllerFn;
31514
+ async post(request, command2, verb) {
31515
+ if (this.deadlineMs <= 0) {
31516
+ throw new DeliveryTransportError(`${verb} request timed out`);
31517
+ }
31518
+ const deadlineController = this.createAbortControllerFn();
31519
+ let timedOut = false;
31520
+ const signal = deadlineController.signal;
31521
+ let onAbort = () => {
31522
+ };
31523
+ const aborted = new Promise((resolve3) => {
31524
+ onAbort = () => resolve3("timeout");
31525
+ if (signal.aborted) {
31526
+ onAbort();
31527
+ } else {
31528
+ signal.addEventListener("abort", onAbort, { once: true });
31529
+ }
31530
+ });
31531
+ const timer2 = setTimeout(() => {
31532
+ timedOut = true;
31533
+ deadlineController.abort();
31534
+ }, this.deadlineMs);
31535
+ try {
31536
+ if (signal.aborted) {
31537
+ throw new DeliveryTransportError(`${verb} request timed out`);
31538
+ }
31539
+ const read = (async () => {
31540
+ let response;
31541
+ try {
31542
+ response = await this.fetcher(commandEndpoint(this.target), {
31543
+ method: "POST",
31544
+ headers: {
31545
+ authorization: `Bearer ${request.credential}`,
31546
+ apikey: this.target.anonKey,
31547
+ "content-type": "application/json"
31548
+ },
31549
+ body: JSON.stringify({
31550
+ command_id: request.commandId,
31551
+ client_version: CLIENT_PROTOCOL_VERSION,
31552
+ workspace_id: request.workspaceId.toLowerCase(),
31553
+ stream: { kind: "workspace" },
31554
+ command: command2
31555
+ }),
31556
+ signal
31557
+ });
31558
+ } catch (error) {
31559
+ if (signal.aborted || timedOut || error?.name === "AbortError") {
31560
+ return "timeout";
31561
+ }
31562
+ throw new DeliveryTransportError(
31563
+ `${verb} request failed before a response`
31564
+ );
31565
+ }
31566
+ if (signal.aborted || timedOut) return "timeout";
31567
+ let text;
31568
+ try {
31569
+ text = await response.text();
31570
+ } catch {
31571
+ if (signal.aborted || timedOut) return "timeout";
31572
+ throw new DeliveryTransportError(
31573
+ `${verb} response body was interrupted`
31574
+ );
31575
+ }
31576
+ if (signal.aborted || timedOut) return "timeout";
31577
+ return { response, text };
31578
+ })();
31579
+ const raced = await Promise.race([read, aborted]);
31580
+ if (raced === "timeout") {
31581
+ throw new DeliveryTransportError(`${verb} request timed out`);
31582
+ }
31583
+ return raced;
31584
+ } finally {
31585
+ this.clearTimeoutFn(timer2);
31586
+ signal.removeEventListener("abort", onAbort);
31587
+ }
31588
+ }
31589
+ /** Claim the caller's own single unacked direct-signal delivery row. */
31590
+ async claimAgentInbox(request) {
31591
+ checkedCommandId(request.commandId);
31592
+ assertAgentToken(request.credential);
31593
+ checkedUuidRequest(request.workspaceId, "workspaceId");
31594
+ checkedUuidRequest(request.listenerInstanceId, "listenerInstanceId");
31595
+ checkedUuidRequest(request.expectedPrincipalId, "expectedPrincipalId");
31596
+ const { response, text } = await this.post(request, {
31597
+ kind: "claim_agent_inbox",
31598
+ listener_instance_id: request.listenerInstanceId.toLowerCase(),
31599
+ limit: 1
31600
+ }, "delivery claim");
31601
+ if (!response.ok) throw refusal(response, text);
31602
+ const parsed = parseClaimSuccess(
31603
+ successBody(response, text, "delivery claim"),
31604
+ {
31605
+ workspaceId: request.workspaceId.toLowerCase(),
31606
+ principalId: request.expectedPrincipalId.toLowerCase()
31607
+ },
31608
+ this.now
31609
+ );
31610
+ return {
31611
+ httpStatus: response.status,
31612
+ capabilities: parsed.capabilities,
31613
+ deliveries: parsed.deliveries,
31614
+ pendingDeliveryCount: parsed.pendingDeliveryCount,
31615
+ terminalDeliveryFailureCount: parsed.terminalDeliveryFailureCount
31616
+ };
31617
+ }
31618
+ /** Acknowledge one leased delivery with an exact terminal outcome. */
31619
+ async ackAgentDelivery(request) {
31620
+ assertAckRequest(request);
31621
+ const { response, text } = await this.post(request, {
31622
+ kind: "ack_agent_delivery",
31623
+ signal_id: request.signalId.toLowerCase(),
31624
+ lease_id: request.leaseId.toLowerCase(),
31625
+ listener_instance_id: request.listenerInstanceId.toLowerCase(),
31626
+ outcome: request.outcome,
31627
+ last_error_code: request.lastErrorCode
31628
+ }, "delivery acknowledgement");
31629
+ if (!response.ok) throw refusal(response, text);
31630
+ parseAckSuccess(
31631
+ successBody(response, text, "delivery acknowledgement"),
31632
+ {
31633
+ signalId: request.signalId.toLowerCase(),
31634
+ outcome: request.outcome
31635
+ }
31636
+ );
31637
+ return {
31638
+ httpStatus: response.status,
31639
+ signalId: request.signalId.toLowerCase(),
31640
+ outcome: request.outcome
31641
+ };
31642
+ }
31643
+ /** Mark a queued delivery observed only after the interactive hook surfaced it. */
31644
+ async observeQueuedAgentDelivery(request) {
31645
+ checkedCommandId(request.commandId);
31646
+ assertAgentToken(request.credential);
31647
+ checkedUuidRequest(request.workspaceId, "workspaceId");
31648
+ checkedUuidRequest(request.signalId, "signalId");
31649
+ const { response, text } = await this.post(request, {
31650
+ kind: "ack_agent_delivery",
31651
+ signal_id: request.signalId.toLowerCase(),
31652
+ lease_id: null,
31653
+ listener_instance_id: null,
31654
+ outcome: "observed",
31655
+ last_error_code: null
31656
+ }, "delivery observation");
31657
+ if (!response.ok) throw refusal(response, text);
31658
+ parseAckSuccess(
31659
+ successBody(response, text, "delivery observation"),
31660
+ {
31661
+ signalId: request.signalId.toLowerCase(),
31662
+ outcome: "observed"
31663
+ }
31664
+ );
31665
+ return {
31666
+ httpStatus: response.status,
31667
+ signalId: request.signalId.toLowerCase(),
31668
+ outcome: "observed"
31669
+ };
31670
+ }
31671
+ };
31672
+
31081
31673
  // src/cloud/agent-signal-receipts.ts
31082
31674
  var AGENT_SEEN_BATCH_MAX = 50;
31083
31675
  var AGENT_SEEN_TIMEOUT_MS = 5e3;
@@ -33898,7 +34490,7 @@ async function resolveBudgetAndPrompt(session, prompt, budget) {
33898
34490
  }
33899
34491
 
33900
34492
  // src/listener/engine.ts
33901
- var UUID_RE13 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
34493
+ var UUID_RE14 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
33902
34494
  var TERMINAL_STATES = /* @__PURE__ */ new Set(["done", "expired", "failed"]);
33903
34495
  var REPLY_MAX_CODE_UNITS = 2e3;
33904
34496
  var TRUNCATION_SUFFIX = "\n[Reply truncated by CommonSwarm]";
@@ -33906,7 +34498,7 @@ var UNSAFE_CONTROLS_RE = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u009f\u
33906
34498
  var LISTENER_MAX_PROMPT_ATTEMPTS = 3;
33907
34499
  var LISTENER_MAX_POST_ATTEMPTS = 5;
33908
34500
  function listenerReplyCommandId(signalId, effectOrdinal = 0) {
33909
- if (!UUID_RE13.test(signalId)) {
34501
+ if (!UUID_RE14.test(signalId)) {
33910
34502
  throw new Error("listener signal id must be a UUID");
33911
34503
  }
33912
34504
  if (!Number.isSafeInteger(effectOrdinal) || effectOrdinal < 0) {
@@ -34399,7 +34991,7 @@ var import_node_crypto13 = require("node:crypto");
34399
34991
  var import_node_os6 = require("node:os");
34400
34992
  var import_node_path9 = require("node:path");
34401
34993
  var import_node_util = require("node:util");
34402
- var UUID_RE14 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
34994
+ var UUID_RE15 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
34403
34995
  var COMMAND_ID_RE2 = /^[A-Za-z0-9_-]{8,72}$/;
34404
34996
  var MAX_EFFECT_BYTES = 1024 * 1024;
34405
34997
  var STATES = /* @__PURE__ */ new Set([
@@ -34449,7 +35041,7 @@ function defaultListenerStateDirectory() {
34449
35041
  return process.env.XDG_STATE_HOME ? (0, import_node_path9.join)(process.env.XDG_STATE_HOME, "cswarm", "listeners") : (0, import_node_path9.join)((0, import_node_os6.homedir)(), ".cswarm", "listeners");
34450
35042
  }
34451
35043
  function listenerInstanceKey(input) {
34452
- if (!UUID_RE14.test(input.workspaceId) || !UUID_RE14.test(input.principalId)) {
35044
+ if (!UUID_RE15.test(input.workspaceId) || !UUID_RE15.test(input.principalId)) {
34453
35045
  throw new Error("listener workspace and principal ids must be UUIDs");
34454
35046
  }
34455
35047
  if (!input.profileId || input.profileId.includes("\0")) {
@@ -34482,7 +35074,7 @@ function parseListenerEffectRecord(raw, expectedId) {
34482
35074
  }
34483
35075
  const row = value;
34484
35076
  rejectSensitiveKeys(row);
34485
- if (typeof row.version !== "number" || row.version !== 1 && row.version !== 2 || typeof row.signalId !== "string" || row.signalId.toLowerCase() !== expectedId || !UUID_RE14.test(row.signalId)) {
35077
+ if (typeof row.version !== "number" || row.version !== 1 && row.version !== 2 || typeof row.signalId !== "string" || row.signalId.toLowerCase() !== expectedId || !UUID_RE15.test(row.signalId)) {
34486
35078
  throw new Error("stored listener effect is malformed");
34487
35079
  }
34488
35080
  if (row.version === 1) {
@@ -34497,7 +35089,7 @@ function upcastV1Ask(row) {
34497
35089
  if (row.effectOrdinal !== 0 || typeof row.commandId !== "string" || !COMMAND_ID_RE2.test(row.commandId) || typeof row.askBody !== "string" || row.askBody.length < 1 || typeof row.askUntil !== "string" || !Number.isFinite(Date.parse(row.askUntil)) || typeof row.senderOwnerRelation !== "string" || !RELATIONS.has(row.senderOwnerRelation) || typeof row.state !== "string" || !STATES.has(row.state) || !integer(row.promptAttempts) || !integer(row.postAttempts) || !nullableString2(row.replyBody, 2e3) || typeof row.replyTruncated !== "boolean" || !nullableString2(row.replySignalId, 64) || !nullableString2(row.failureCode, 96) || typeof row.updatedAt !== "string" || !Number.isFinite(Date.parse(row.updatedAt))) {
34498
35090
  throw new Error("stored listener effect is malformed");
34499
35091
  }
34500
- if (row.replySignalId !== null && !UUID_RE14.test(row.replySignalId)) {
35092
+ if (row.replySignalId !== null && !UUID_RE15.test(row.replySignalId)) {
34501
35093
  throw new Error("stored listener effect is malformed");
34502
35094
  }
34503
35095
  return {
@@ -34536,7 +35128,7 @@ function parseV2Record(row) {
34536
35128
  if (typeof row.commandId !== "string" || !COMMAND_ID_RE2.test(row.commandId) || row.state === "observed") {
34537
35129
  throw new Error("stored listener effect is malformed");
34538
35130
  }
34539
- if (row.replySignalId !== null && !UUID_RE14.test(row.replySignalId)) {
35131
+ if (row.replySignalId !== null && !UUID_RE15.test(row.replySignalId)) {
34540
35132
  throw new Error("stored listener effect is malformed");
34541
35133
  }
34542
35134
  }
@@ -34560,7 +35152,7 @@ function parseV2Record(row) {
34560
35152
  };
34561
35153
  }
34562
35154
  function newObservedNoteRecord(input) {
34563
- if (!UUID_RE14.test(input.signalId)) {
35155
+ if (!UUID_RE15.test(input.signalId)) {
34564
35156
  throw new Error("listener note signal id must be a UUID");
34565
35157
  }
34566
35158
  if (input.body.length < 1) {
@@ -34694,7 +35286,7 @@ var FileListenerEffectStore = class {
34694
35286
  );
34695
35287
  }
34696
35288
  checkedId(signalId) {
34697
- if (!UUID_RE14.test(signalId)) {
35289
+ if (!UUID_RE15.test(signalId)) {
34698
35290
  throw new Error("listener signal id must be a UUID");
34699
35291
  }
34700
35292
  return signalId.toLowerCase();
@@ -35488,240 +36080,47 @@ var import_node_crypto16 = require("node:crypto");
35488
36080
  var import_promises7 = require("node:fs/promises");
35489
36081
  var import_node_os8 = require("node:os");
35490
36082
  var import_node_path13 = require("node:path");
35491
- var CLAUDE_CODE_VERSION_REQUIRED_RE = /\bClaude Code (\d+\.\d+\.\d+) does not support this model; version (\d+\.\d+\.\d+) or newer is required\b/;
35492
- var CLAUDE_AUTH_FAILURE_RE = /\b(?:authentication failed|failed to authenticate|authentication required|not authenticated|OAuth (?:sign-in|login|token)|OAuth session (?:expired|could not be refreshed)|keychain\/OAuth|please (?:log|sign) in)\b/i;
35493
- var CLAUDE_CANARY_TIMEOUT_RE = /^ACP request timed out: session\/prompt(?: \(failed \d+ attempts\))?$/;
35494
- function classifyClaudeCanaryFailure(detail, typedReasonCode, peerError) {
35495
- const recorded = detail?.trim() ?? "";
35496
- const peerData = peerError?.data;
35497
- const peerErrorKind = peerData && typeof peerData === "object" && !Array.isArray(peerData) ? peerData.errorKind : void 0;
35498
- if (typedReasonCode === "claude_canary_auth_failed" || (typedReasonCode === "rpc_error" || typedReasonCode === null || typedReasonCode === void 0) && (peerError?.code === -32e3 || peerErrorKind === "authentication_failed")) {
35499
- return { code: "claude_canary_auth_failed", minimumRequiredVersion: null };
35500
- }
35501
- const demanded = CLAUDE_CODE_VERSION_REQUIRED_RE.exec(recorded);
35502
- if (demanded?.[2]) {
35503
- return {
35504
- code: "claude_bridge_version_required",
35505
- minimumRequiredVersion: demanded[2]
35506
- };
35507
- }
35508
- if (typedReasonCode === "claude_canary_timeout" || typedReasonCode === "timeout" || (typedReasonCode === null || typedReasonCode === void 0) && CLAUDE_CANARY_TIMEOUT_RE.test(recorded)) {
35509
- return { code: "claude_canary_timeout", minimumRequiredVersion: null };
35510
- }
35511
- if (typedReasonCode === "claude_bridge_version_required") {
35512
- return {
35513
- code: "claude_bridge_version_required",
35514
- minimumRequiredVersion: demanded?.[2] ?? null
35515
- };
35516
- }
35517
- if ((typedReasonCode === "rpc_error" || typedReasonCode === null || typedReasonCode === void 0) && CLAUDE_AUTH_FAILURE_RE.test(recorded)) {
35518
- return { code: "claude_canary_auth_failed", minimumRequiredVersion: null };
35519
- }
35520
- return { code: "claude_canary_unknown", minimumRequiredVersion: null };
35521
- }
35522
- var ClaudeListenerClosedDuringOpen = class extends Error {
35523
- constructor() {
35524
- super("listener model closed while the Claude worker was opening");
35525
- this.name = "ClaudeListenerClosedDuringOpen";
35526
- }
35527
- };
35528
- var ClaudeListenerModel = class {
35529
- constructor(options) {
35530
- this.options = options;
35531
- this.openSession = options.open ?? openClaudeAcpSession;
35532
- this.permissionMode = options.permissionMode ?? "deny";
35533
- }
35534
- options;
35535
- openSession;
35536
- permissionMode;
35537
- worker = null;
35538
- opening = null;
35539
- openingController = null;
35540
- openingHandle = null;
35541
- workerCanary = true;
35542
- closed = false;
35543
- closePromise = null;
35544
- /** Initialize the worker and deny canary before reporting ready. */
35545
- async start() {
35546
- await this.ensureWorker();
35547
- }
35548
- async prompt(_signal, _mode, prompt) {
35549
- if (this.closed) throw new Error("listener model is closed");
35550
- const worker = await this.ensureWorker();
35551
- const budget = this.options.promptTimeoutMs ?? LISTENER_PROMPT_TIMEOUT_MS;
35552
- try {
35553
- return await resolveBudgetAndPrompt(worker.session, prompt, budget);
35554
- } catch (error) {
35555
- if (error instanceof AcpChildExitError) {
35556
- try {
35557
- await worker.close();
35558
- } finally {
35559
- if (this.worker === worker) this.worker = null;
35560
- }
35561
- }
35562
- throw error;
35563
- }
35564
- }
35565
- cancel() {
35566
- this.worker?.session.cancel();
35567
- }
35568
- async close() {
35569
- if (this.closePromise) return this.closePromise;
35570
- this.closed = true;
35571
- this.cancel();
35572
- this.closePromise = (async () => {
35573
- const closeFailures = [];
35574
- const opening = this.opening;
35575
- this.openingController?.abort();
35576
- const openingHandle = this.openingHandle;
35577
- if (openingHandle) {
35578
- try {
35579
- openingHandle.session.cancel();
35580
- } catch {
35581
- }
35582
- try {
35583
- await openingHandle.close();
35584
- } catch (error) {
35585
- closeFailures.push(error);
35586
- }
35587
- }
35588
- if (opening) {
35589
- try {
35590
- await opening;
35591
- } catch (error) {
35592
- const code = error.code;
35593
- if (!(error instanceof ClaudeListenerClosedDuringOpen) && code !== "cancelled" && !openingHandle) {
35594
- throw error;
35595
- }
35596
- }
35597
- }
35598
- const handle = this.worker;
35599
- this.worker = null;
35600
- if (handle && handle !== openingHandle) {
35601
- try {
35602
- await handle.close();
35603
- } catch (error) {
35604
- closeFailures.push(error);
35605
- }
35606
- }
35607
- if (closeFailures.length > 0) throw closeFailures[0];
35608
- })();
35609
- return this.closePromise;
35610
- }
35611
- async ensureWorker() {
35612
- if (this.closed) throw new Error("listener model is closed");
35613
- if (this.worker) return this.worker;
35614
- if (this.opening) return this.opening;
35615
- const opening = this.openWorker();
35616
- this.opening = opening;
35617
- try {
35618
- return await opening;
35619
- } finally {
35620
- if (this.opening === opening) this.opening = null;
35621
- }
35622
- }
35623
- async openWorker() {
35624
- const controller = new AbortController();
35625
- this.openingController = controller;
35626
- this.workerCanary = true;
35627
- const permissionCallback = (request) => this.workerCanary || this.permissionMode === "deny" ? defaultPermissionCallback(request) : allowOnceOrDeny(request);
35628
- try {
35629
- const handle = await this.openSession({
35630
- cwd: this.options.cwd,
35631
- permissionCallback,
35632
- ...this.options.executable ? { executable: this.options.executable } : {},
35633
- ...this.options.env ? { env: this.options.env } : {},
35634
- ...this.options.onVersionNotice ? { onVersionNotice: this.options.onVersionNotice } : {},
35635
- ...this.options.onRuntimeNotice ? { onRuntimeNotice: this.options.onRuntimeNotice } : {},
35636
- ...this.options.events ? { events: this.options.events } : {},
35637
- signal: controller.signal,
35638
- ...this.options.onWorkerStderrTail ? { onStderrTail: this.options.onWorkerStderrTail } : {},
35639
- clientName: "cswarm-listener"
35640
- });
35641
- this.openingHandle = handle;
35642
- try {
35643
- if (this.closed) throw new ClaudeListenerClosedDuringOpen();
35644
- await this.enablePromptsAfterClaudeCanary(handle);
35645
- if (this.closed) throw new ClaudeListenerClosedDuringOpen();
35646
- this.workerCanary = false;
35647
- this.worker = handle;
35648
- return handle;
35649
- } catch (error) {
35650
- await handle.close();
35651
- throw error;
35652
- } finally {
35653
- if (this.openingHandle === handle) this.openingHandle = null;
35654
- }
35655
- } finally {
35656
- if (this.openingController === controller) this.openingController = null;
35657
- }
35658
- }
35659
- /** Force Claude's measured Write permission path without changing worker cwd. */
35660
- async enablePromptsAfterClaudeCanary(handle) {
35661
- const sentinelPath = (0, import_node_path13.join)(
35662
- (0, import_node_os8.tmpdir)(),
35663
- `cswarm-claude-permission-canary-${process.pid}-${(0, import_node_crypto16.randomUUID)()}`
35664
- );
35665
- let canaryError;
35666
- let sentinelCreated = false;
35667
- try {
35668
- await handle.session.enablePromptsAfterCanary({
35669
- timeoutMs: ACP_CANARY_TIMEOUT_MS,
35670
- probeText: `Create the file ${sentinelPath} using the Write tool with content CSWARM_CANARY_NOOP. You must use the Write tool. Do nothing else.`,
35671
- ...this.options.onCanaryAttempt ? { onAttempt: this.options.onCanaryAttempt } : {}
35672
- });
35673
- } catch (error) {
35674
- canaryError = error;
35675
- } finally {
35676
- try {
35677
- await (0, import_promises7.lstat)(sentinelPath);
35678
- sentinelCreated = true;
35679
- await (0, import_promises7.unlink)(sentinelPath);
35680
- } catch (error) {
35681
- if (error.code !== "ENOENT") throw error;
35682
- }
35683
- }
35684
- if (sentinelCreated) {
35685
- throw new AcpPermissionCanaryError(
35686
- "Claude bridge wrote the permission canary sentinel before denial",
35687
- "claude_canary_write_not_blocked"
35688
- );
35689
- }
35690
- if (canaryError instanceof AcpPermissionCanaryError) {
35691
- const shape = classifyClaudeCanaryFailure(
35692
- canaryError.message,
35693
- canaryError.reasonCode,
35694
- canaryError.peerError
35695
- );
35696
- throw new AcpPermissionCanaryError(
35697
- canaryError.message,
35698
- shape.code,
35699
- shape.minimumRequiredVersion
35700
- );
35701
- }
35702
- if (canaryError !== void 0) throw canaryError;
36083
+ var CLAUDE_CODE_VERSION_REQUIRED_RE = /\bClaude Code (\d+\.\d+\.\d+) does not support this model; version (\d+\.\d+\.\d+) or newer is required\b/;
36084
+ var CLAUDE_AUTH_FAILURE_RE = /\b(?:authentication failed|failed to authenticate|authentication required|not authenticated|OAuth (?:sign-in|login|token)|OAuth session (?:expired|could not be refreshed)|keychain\/OAuth|please (?:log|sign) in)\b/i;
36085
+ var CLAUDE_CANARY_TIMEOUT_RE = /^ACP request timed out: session\/prompt(?: \(failed \d+ attempts\))?$/;
36086
+ function classifyClaudeCanaryFailure(detail, typedReasonCode, peerError) {
36087
+ const recorded = detail?.trim() ?? "";
36088
+ const peerData = peerError?.data;
36089
+ const peerErrorKind = peerData && typeof peerData === "object" && !Array.isArray(peerData) ? peerData.errorKind : void 0;
36090
+ if (typedReasonCode === "claude_canary_auth_failed" || (typedReasonCode === "rpc_error" || typedReasonCode === null || typedReasonCode === void 0) && (peerError?.code === -32e3 || peerErrorKind === "authentication_failed")) {
36091
+ return { code: "claude_canary_auth_failed", minimumRequiredVersion: null };
35703
36092
  }
35704
- };
35705
-
35706
- // src/listener/codex-model.ts
35707
- var import_node_crypto17 = require("node:crypto");
35708
- var import_promises8 = require("node:fs/promises");
35709
- var import_node_os9 = require("node:os");
35710
- var import_node_path14 = require("node:path");
35711
- var CodexListenerClosedDuringOpen = class extends Error {
36093
+ const demanded = CLAUDE_CODE_VERSION_REQUIRED_RE.exec(recorded);
36094
+ if (demanded?.[2]) {
36095
+ return {
36096
+ code: "claude_bridge_version_required",
36097
+ minimumRequiredVersion: demanded[2]
36098
+ };
36099
+ }
36100
+ if (typedReasonCode === "claude_canary_timeout" || typedReasonCode === "timeout" || (typedReasonCode === null || typedReasonCode === void 0) && CLAUDE_CANARY_TIMEOUT_RE.test(recorded)) {
36101
+ return { code: "claude_canary_timeout", minimumRequiredVersion: null };
36102
+ }
36103
+ if (typedReasonCode === "claude_bridge_version_required") {
36104
+ return {
36105
+ code: "claude_bridge_version_required",
36106
+ minimumRequiredVersion: demanded?.[2] ?? null
36107
+ };
36108
+ }
36109
+ if ((typedReasonCode === "rpc_error" || typedReasonCode === null || typedReasonCode === void 0) && CLAUDE_AUTH_FAILURE_RE.test(recorded)) {
36110
+ return { code: "claude_canary_auth_failed", minimumRequiredVersion: null };
36111
+ }
36112
+ return { code: "claude_canary_unknown", minimumRequiredVersion: null };
36113
+ }
36114
+ var ClaudeListenerClosedDuringOpen = class extends Error {
35712
36115
  constructor() {
35713
- super("listener model closed while the Codex worker was opening");
35714
- this.name = "CodexListenerClosedDuringOpen";
36116
+ super("listener model closed while the Claude worker was opening");
36117
+ this.name = "ClaudeListenerClosedDuringOpen";
35715
36118
  }
35716
36119
  };
35717
- function pathIsInsideOrEqual(ancestor, candidate) {
35718
- const fromAncestor = (0, import_node_path14.relative)(ancestor, candidate);
35719
- return fromAncestor === "" || fromAncestor !== ".." && !fromAncestor.startsWith(`..${import_node_path14.sep}`) && !(0, import_node_path14.isAbsolute)(fromAncestor);
35720
- }
35721
- var CodexListenerModel = class {
36120
+ var ClaudeListenerModel = class {
35722
36121
  constructor(options) {
35723
36122
  this.options = options;
35724
- this.openSession = options.open ?? openCodexAcpSession;
36123
+ this.openSession = options.open ?? openClaudeAcpSession;
35725
36124
  this.permissionMode = options.permissionMode ?? "deny";
35726
36125
  }
35727
36126
  options;
@@ -35783,7 +36182,7 @@ var CodexListenerModel = class {
35783
36182
  await opening;
35784
36183
  } catch (error) {
35785
36184
  const code = error.code;
35786
- if (!(error instanceof CodexListenerClosedDuringOpen) && code !== "cancelled" && !openingHandle) {
36185
+ if (!(error instanceof ClaudeListenerClosedDuringOpen) && code !== "cancelled" && !openingHandle) {
35787
36186
  throw error;
35788
36187
  }
35789
36188
  }
@@ -35801,712 +36200,324 @@ var CodexListenerModel = class {
35801
36200
  })();
35802
36201
  return this.closePromise;
35803
36202
  }
35804
- async ensureWorker() {
35805
- if (this.closed) throw new Error("listener model is closed");
35806
- if (this.worker) return this.worker;
35807
- if (this.opening) return this.opening;
35808
- const opening = this.openWorker();
35809
- this.opening = opening;
35810
- try {
35811
- return await opening;
35812
- } finally {
35813
- if (this.opening === opening) this.opening = null;
35814
- }
35815
- }
35816
- async openWorker() {
35817
- const controller = new AbortController();
35818
- this.openingController = controller;
35819
- this.workerCanary = true;
35820
- const permissionCallback = (request) => this.workerCanary || this.permissionMode === "deny" ? defaultPermissionCallback(request) : allowOnceOrDeny(request);
35821
- try {
35822
- const handle = await this.openSession({
35823
- cwd: this.options.cwd,
35824
- permissionCallback,
35825
- ...this.options.executable ? { executable: this.options.executable } : {},
35826
- ...this.options.env ? { env: this.options.env } : {},
35827
- ...this.options.onVersionNotice ? { onVersionNotice: this.options.onVersionNotice } : {},
35828
- ...this.options.events ? { events: this.options.events } : {},
35829
- signal: controller.signal,
35830
- ...this.options.onWorkerStderrTail ? { onStderrTail: this.options.onWorkerStderrTail } : {},
35831
- clientName: "cswarm-listener"
35832
- });
35833
- this.openingHandle = handle;
35834
- try {
35835
- if (this.closed) throw new CodexListenerClosedDuringOpen();
35836
- await this.enablePromptsAfterCodexCanary(handle);
35837
- if (this.closed) throw new CodexListenerClosedDuringOpen();
35838
- this.workerCanary = false;
35839
- this.worker = handle;
35840
- return handle;
35841
- } catch (error) {
35842
- await handle.close();
35843
- throw error;
35844
- } finally {
35845
- if (this.openingHandle === handle) this.openingHandle = null;
35846
- }
35847
- } finally {
35848
- if (this.openingController === controller) this.openingController = null;
35849
- }
35850
- }
35851
- /** Force Codex's measured shell permission path without changing worker cwd. */
35852
- async enablePromptsAfterCodexCanary(handle) {
35853
- const configuredHome = this.options.env?.HOME;
35854
- const home = configuredHome && (0, import_node_path14.isAbsolute)(configuredHome) ? configuredHome : (0, import_node_os9.homedir)();
35855
- const sentinelDirectory = (0, import_node_path14.join)(home, ".cswarm", "canary");
35856
- await (0, import_promises8.mkdir)(sentinelDirectory, { recursive: true, mode: 448 });
35857
- await (0, import_promises8.chmod)(sentinelDirectory, 448);
35858
- const [workerCwd, canaryDirectory] = await Promise.all([
35859
- (0, import_promises8.realpath)(this.options.cwd),
35860
- (0, import_promises8.realpath)(sentinelDirectory)
35861
- ]);
35862
- if (pathIsInsideOrEqual(workerCwd, canaryDirectory)) {
35863
- throw new AcpPermissionCanaryError(
35864
- `canary_path_inside_cwd: ${canaryDirectory} is inside listener cwd ${workerCwd}. Next: pass a --cwd that is not your home directory`
35865
- );
35866
- }
35867
- const sentinelPath = (0, import_node_path14.join)(
35868
- canaryDirectory,
35869
- `cswarm-codex-permission-canary-${process.pid}-${(0, import_node_crypto17.randomUUID)()}`
35870
- );
35871
- let canaryError;
35872
- let sentinelCreated = false;
35873
- try {
35874
- await handle.session.enablePromptsAfterCanary({
35875
- timeoutMs: ACP_CANARY_TIMEOUT_MS,
35876
- probeText: `Use a shell command to create ${sentinelPath} with content CSWARM_CANARY_NOOP. You must use the shell. Do nothing else.`,
35877
- ...this.options.onCanaryAttempt ? { onAttempt: this.options.onCanaryAttempt } : {}
35878
- });
35879
- } catch (error) {
35880
- canaryError = error;
35881
- } finally {
35882
- try {
35883
- await (0, import_promises8.lstat)(sentinelPath);
35884
- sentinelCreated = true;
35885
- await (0, import_promises8.unlink)(sentinelPath);
35886
- } catch (error) {
35887
- if (error.code !== "ENOENT") throw error;
35888
- }
35889
- }
35890
- const observation = handle.session.canaryObservation;
35891
- const sawPermissionRequest = observation?.sawPermissionRequest === true;
35892
- const bridgeVersion = handle.providerVersion ?? handle.session.info?.agentVersion ?? "unknown";
35893
- if (sentinelCreated && !sawPermissionRequest) {
35894
- throw new AcpPermissionCanaryError(
35895
- `canary_executed_without_permission: codex-acp ${bridgeVersion} ran the shell probe without a permission request and wrote ${sentinelPath}. Next: replace codex-acp ${bridgeVersion} with a bridge version that asks before writing ${sentinelPath}`
35896
- );
35897
- }
35898
- if (sentinelCreated) {
35899
- throw new AcpPermissionCanaryError(
35900
- `canary_write_not_blocked: codex-acp ${bridgeVersion} wrote ${sentinelPath} even though the host rejected the canary. Next: update or reinstall the codex-acp bridge`
35901
- );
35902
- }
35903
- if (canaryError instanceof AcpPermissionCanaryError) {
35904
- if (canaryError.reasonCode === "timeout") {
35905
- throw new AcpPermissionCanaryError(
35906
- `canary_timeout: ${canaryError.message}. Next: retry to run a fresh bounded permission canary`,
35907
- "timeout"
35908
- );
35909
- }
35910
- if (canaryError.reasonCode !== null) {
35911
- throw new AcpPermissionCanaryError(
35912
- `canary_bridge_error: codex-acp ${bridgeVersion} returned ${canaryError.message}. Next: resolve the quoted bridge error, then retry`,
35913
- canaryError.reasonCode
35914
- );
35915
- }
35916
- if (!sawPermissionRequest) {
35917
- throw new AcpPermissionCanaryError(
35918
- `canary_no_tool_call: codex-acp ${bridgeVersion} did not request permission or create ${sentinelPath}. Next: retry to re-sample the model's shell choice`
35919
- );
35920
- }
35921
- }
35922
- if (canaryError !== void 0) throw canaryError;
35923
- }
35924
- };
35925
-
35926
- // src/listener/runtime.ts
35927
- var import_node_crypto18 = require("node:crypto");
35928
-
35929
- // src/cloud/delivery.ts
35930
- var UUID_RE15 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
35931
- var RFC3339_TIMESTAMP_RE = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:Z|([+-]\d{2}):(\d{2}))$/i;
35932
- var DELIVERY_KINDS = /* @__PURE__ */ new Set(["ask", "note"]);
35933
- var SENDER_OWNER_RELATIONS2 = /* @__PURE__ */ new Set([
35934
- "same_owner",
35935
- "cross_owner",
35936
- "unknown"
35937
- ]);
35938
- var DELIVERY_ACK_OUTCOMES = /* @__PURE__ */ new Set([
35939
- "replied",
35940
- "observed",
35941
- "queued",
35942
- "expired",
35943
- "failed_terminal"
35944
- ]);
35945
- var DELIVERY_REQUEST_TIMEOUT_MS = 3e4;
35946
- var COMMAND_ID_VALIDATOR_RE = /^[A-Za-z0-9_-]{8,72}$/;
35947
- var FAILED_TERMINAL_CODES_SET = /* @__PURE__ */ new Set([
35948
- "provider_refused",
35949
- "local_effect_failed",
35950
- "host_session_failed",
35951
- "credential_unavailable"
35952
- ]);
35953
- var SERVER_ERROR_CODES_SET = /* @__PURE__ */ new Set([
35954
- "unauthenticated",
35955
- "fresh_auth_required",
35956
- "invalid_request",
35957
- "payload_too_large",
35958
- "forbidden",
35959
- "delivery_unavailable",
35960
- "delivery_ack_conflict",
35961
- "command_id_conflict",
35962
- "rate_limited",
35963
- "upgrade_required",
35964
- "temporarily_unavailable",
35965
- "internal_error"
35966
- ]);
35967
- var DELIVERY_FAILED_TERMINAL_CODES = Object.freeze([
35968
- "provider_refused",
35969
- "local_effect_failed",
35970
- "host_session_failed",
35971
- "credential_unavailable"
35972
- ]);
35973
- var DELIVERY_SERVER_ERROR_CODES = Object.freeze([
35974
- "unauthenticated",
35975
- "fresh_auth_required",
35976
- "invalid_request",
35977
- "payload_too_large",
35978
- "forbidden",
35979
- "delivery_unavailable",
35980
- "delivery_ack_conflict",
35981
- "command_id_conflict",
35982
- "rate_limited",
35983
- "upgrade_required",
35984
- "temporarily_unavailable",
35985
- "internal_error"
35986
- ]);
35987
- var DELIVERY_UNKNOWN_ERROR_CODE = "unknown_error";
35988
- function observationCommandId(signalId) {
35989
- checkedUuidRequest(signalId, "signalId");
35990
- return `observe_${signalId.toLowerCase().replaceAll("-", "")}`;
35991
- }
35992
- var DeliveryTransportError = class extends Error {
35993
- constructor(message) {
35994
- super(message);
35995
- this.name = "DeliveryTransportError";
35996
- }
35997
- };
35998
- var DeliveryHttpError = class extends Error {
35999
- constructor(status, code, message, retryAfterMs = null) {
36000
- super(message);
36001
- this.status = status;
36002
- this.code = code;
36003
- this.retryAfterMs = retryAfterMs;
36004
- this.name = "DeliveryHttpError";
36005
- }
36006
- status;
36007
- code;
36008
- retryAfterMs;
36009
- };
36010
- var DeliveryProtocolError = class extends Error {
36011
- constructor(message) {
36012
- super(message);
36013
- this.name = "DeliveryProtocolError";
36014
- }
36015
- };
36016
- function checkedUuid3(value, field) {
36017
- if (typeof value !== "string" || !UUID_RE15.test(value)) {
36018
- throw new DeliveryProtocolError(
36019
- `delivery response returned a malformed ${field}`
36020
- );
36021
- }
36022
- return value.toLowerCase();
36023
- }
36024
- function isLeapYear(year) {
36025
- return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
36026
- }
36027
- function daysInMonth(year, month) {
36028
- switch (month) {
36029
- case 1:
36030
- case 3:
36031
- case 5:
36032
- case 7:
36033
- case 8:
36034
- case 10:
36035
- case 12:
36036
- return 31;
36037
- case 4:
36038
- case 6:
36039
- case 9:
36040
- case 11:
36041
- return 30;
36042
- case 2:
36043
- return isLeapYear(year) ? 29 : 28;
36044
- default:
36045
- return 0;
36046
- }
36047
- }
36048
- function checkedRfc3339Timestamp(value, field) {
36049
- if (typeof value !== "string") {
36050
- throw new DeliveryProtocolError(
36051
- `delivery response returned a malformed ${field}`
36052
- );
36053
- }
36054
- const match = RFC3339_TIMESTAMP_RE.exec(value);
36055
- if (!match) {
36056
- throw new DeliveryProtocolError(
36057
- `delivery response returned a malformed ${field}`
36058
- );
36059
- }
36060
- const year = parseInt(match[1], 10);
36061
- const month = parseInt(match[2], 10);
36062
- const day = parseInt(match[3], 10);
36063
- const hour = parseInt(match[4], 10);
36064
- const minute = parseInt(match[5], 10);
36065
- const second = parseInt(match[6], 10);
36066
- if (month < 1 || month > 12 || day < 1 || day > daysInMonth(year, month) || hour < 0 || hour > 23 || minute < 0 || minute > 59 || second < 0 || second > 59) {
36067
- throw new DeliveryProtocolError(
36068
- `delivery response returned a malformed ${field}`
36069
- );
36070
- }
36071
- if (match[7] !== void 0 && match[8] !== void 0) {
36072
- const offsetHour = Math.abs(parseInt(match[7], 10));
36073
- const offsetMin = parseInt(match[8], 10);
36074
- if (offsetHour > 23 || offsetMin < 0 || offsetMin > 59) {
36075
- throw new DeliveryProtocolError(
36076
- `delivery response returned a malformed ${field}`
36077
- );
36078
- }
36079
- }
36080
- if (!Number.isFinite(Date.parse(value))) {
36081
- throw new DeliveryProtocolError(
36082
- `delivery response returned a malformed ${field}`
36083
- );
36084
- }
36085
- return value;
36086
- }
36087
- function checkedLiveLease(leasedUntil, now) {
36088
- if (Date.parse(leasedUntil) <= now()) {
36089
- throw new DeliveryProtocolError(
36090
- "delivery claim response returned an already expired lease"
36091
- );
36092
- }
36093
- }
36094
- function checkedRelation(value) {
36095
- if (typeof value !== "string" || !SENDER_OWNER_RELATIONS2.has(value)) {
36096
- throw new DeliveryProtocolError(
36097
- "delivery response returned a malformed sender_owner_relation"
36098
- );
36099
- }
36100
- return value;
36101
- }
36102
- function checkedNonNegativeCount(value, field) {
36103
- if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
36104
- throw new DeliveryProtocolError(
36105
- `delivery response returned a malformed ${field}`
36106
- );
36107
- }
36108
- return value;
36109
- }
36110
- function checkedClaimCapabilities(value) {
36111
- if (!value || typeof value !== "object" || Array.isArray(value)) {
36112
- throw new DeliveryProtocolError(
36113
- "delivery claim response is missing delivery capabilities"
36114
- );
36115
- }
36116
- const row = value;
36117
- for (const marker of ["delivery_claim", "delivery_ack", "sender_owner_relation"]) {
36118
- if (row[marker] !== 1) {
36119
- throw new DeliveryProtocolError(
36120
- `delivery claim response is missing the ${marker} capability`
36121
- );
36122
- }
36123
- }
36124
- return { deliveryClaim: true, deliveryAck: true, senderOwnerRelation: true };
36125
- }
36126
- function checkedOptionalUuidArray(value, field) {
36127
- if (value === void 0) return;
36128
- if (!Array.isArray(value) || value.some((item) => typeof item !== "string" || !UUID_RE15.test(item))) {
36129
- throw new DeliveryProtocolError(
36130
- `delivery response returned a malformed ${field}`
36131
- );
36132
- }
36133
- }
36134
- function checkedOptionalArray(value, field) {
36135
- if (value === void 0) return;
36136
- if (!Array.isArray(value)) {
36137
- throw new DeliveryProtocolError(
36138
- `delivery response returned a malformed ${field}`
36139
- );
36140
- }
36141
- }
36142
- function parseDeliveryRow(value, expected, index, now) {
36143
- if (!value || typeof value !== "object" || Array.isArray(value)) {
36144
- throw new DeliveryProtocolError(
36145
- "delivery claim response returned a malformed delivery row"
36146
- );
36147
- }
36148
- const row = value;
36149
- let signal;
36150
- try {
36151
- signal = parseSignalRecord(row.signal);
36152
- } catch {
36153
- throw new DeliveryProtocolError(
36154
- `delivery claim response returned a malformed signal at ${index}`
36155
- );
36156
- }
36157
- if (signal.workspace_id !== expected.workspaceId) {
36158
- throw new DeliveryProtocolError(
36159
- "delivery claim response returned a signal for another workspace"
36160
- );
36161
- }
36162
- if (signal.to_agent !== expected.principalId) {
36163
- throw new DeliveryProtocolError(
36164
- "delivery claim response returned a signal addressed to another agent"
36165
- );
36166
- }
36167
- if (!DELIVERY_KINDS.has(signal.kind)) {
36168
- throw new DeliveryProtocolError(
36169
- "delivery claim response returned a non-direct signal kind"
36170
- );
36171
- }
36172
- const senderOwnerRelation = checkedRelation(row.sender_owner_relation);
36173
- const leaseId = checkedUuid3(row.lease_id, "lease_id");
36174
- const leasedUntil = checkedRfc3339Timestamp(row.leased_until, "leased_until");
36175
- checkedLiveLease(leasedUntil, now);
36176
- signal.sender_owner_relation = senderOwnerRelation;
36177
- return { signal, leaseId, leasedUntil, senderOwnerRelation };
36178
- }
36179
- function parseClaimSuccess(body, expected, now) {
36180
- if (!body || typeof body !== "object" || Array.isArray(body)) {
36181
- throw new DeliveryProtocolError("delivery claim response was not an object");
36182
- }
36183
- const row = body;
36184
- if (row.status !== "accepted" || row.ok !== true) {
36185
- throw new DeliveryProtocolError(
36186
- "delivery claim response did not report accepted ok"
36187
- );
36188
- }
36189
- const capabilities = checkedClaimCapabilities(row.capabilities);
36190
- checkedOptionalUuidArray(row.event_ids, "event_ids");
36191
- checkedOptionalArray(row.events, "events");
36192
- if (!Array.isArray(row.deliveries)) {
36193
- throw new DeliveryProtocolError(
36194
- "delivery claim response is missing its deliveries array"
36195
- );
36196
- }
36197
- const deliveries = row.deliveries.map(
36198
- (item, index) => parseDeliveryRow(item, expected, index, now)
36199
- );
36200
- const signalIds = /* @__PURE__ */ new Set();
36201
- const leaseIds = /* @__PURE__ */ new Set();
36202
- for (const delivery of deliveries) {
36203
- if (signalIds.has(delivery.signal.id)) {
36204
- throw new DeliveryProtocolError(
36205
- "delivery claim response repeats a signal id"
36206
- );
36207
- }
36208
- signalIds.add(delivery.signal.id);
36209
- if (leaseIds.has(delivery.leaseId)) {
36210
- throw new DeliveryProtocolError(
36211
- "delivery claim response repeats a lease id"
36212
- );
36213
- }
36214
- leaseIds.add(delivery.leaseId);
36215
- }
36216
- if (deliveries.length > 1) {
36217
- throw new DeliveryProtocolError(
36218
- "delivery claim response returned more than one delivery"
36219
- );
36220
- }
36221
- const pendingDeliveryCount = checkedNonNegativeCount(
36222
- row.pending_delivery_count,
36223
- "pending_delivery_count"
36224
- );
36225
- const terminalDeliveryFailureCount = checkedNonNegativeCount(
36226
- row.terminal_delivery_failure_count,
36227
- "terminal_delivery_failure_count"
36228
- );
36229
- if (deliveries.length > pendingDeliveryCount) {
36230
- throw new DeliveryProtocolError(
36231
- "delivery claim response returned more deliveries than its pending count"
36232
- );
36233
- }
36234
- return {
36235
- capabilities,
36236
- deliveries,
36237
- pendingDeliveryCount,
36238
- terminalDeliveryFailureCount
36239
- };
36240
- }
36241
- function parseAckSuccess(body, expected) {
36242
- if (!body || typeof body !== "object" || Array.isArray(body)) {
36243
- throw new DeliveryProtocolError(
36244
- "delivery acknowledgement response was not an object"
36245
- );
36246
- }
36247
- const row = body;
36248
- if (row.status !== "accepted" || row.ok !== true) {
36249
- throw new DeliveryProtocolError(
36250
- "delivery acknowledgement response did not report accepted ok"
36251
- );
36252
- }
36253
- checkedOptionalUuidArray(row.event_ids, "event_ids");
36254
- checkedOptionalArray(row.events, "events");
36255
- if (row.signal_id !== expected.signalId) {
36256
- throw new DeliveryProtocolError(
36257
- "delivery acknowledgement response echoed a different signal id"
36258
- );
36259
- }
36260
- if (row.outcome !== expected.outcome) {
36261
- throw new DeliveryProtocolError(
36262
- "delivery acknowledgement response echoed a different outcome"
36263
- );
36264
- }
36265
- }
36266
- function checkedCommandId(value) {
36267
- if (typeof value !== "string" || !COMMAND_ID_VALIDATOR_RE.test(value)) {
36268
- throw new Error(
36269
- "a delivery command id must be 8..72 characters of [A-Za-z0-9_-]"
36270
- );
36203
+ async ensureWorker() {
36204
+ if (this.closed) throw new Error("listener model is closed");
36205
+ if (this.worker) return this.worker;
36206
+ if (this.opening) return this.opening;
36207
+ const opening = this.openWorker();
36208
+ this.opening = opening;
36209
+ try {
36210
+ return await opening;
36211
+ } finally {
36212
+ if (this.opening === opening) this.opening = null;
36213
+ }
36271
36214
  }
36272
- return value;
36273
- }
36274
- function checkedUuidRequest(value, field) {
36275
- if (!UUID_RE15.test(value)) {
36276
- throw new Error(`${field} must be a UUID for an agent delivery command`);
36215
+ async openWorker() {
36216
+ const controller = new AbortController();
36217
+ this.openingController = controller;
36218
+ this.workerCanary = true;
36219
+ const permissionCallback = (request) => this.workerCanary || this.permissionMode === "deny" ? defaultPermissionCallback(request) : allowOnceOrDeny(request);
36220
+ try {
36221
+ const handle = await this.openSession({
36222
+ cwd: this.options.cwd,
36223
+ permissionCallback,
36224
+ ...this.options.executable ? { executable: this.options.executable } : {},
36225
+ ...this.options.env ? { env: this.options.env } : {},
36226
+ ...this.options.onVersionNotice ? { onVersionNotice: this.options.onVersionNotice } : {},
36227
+ ...this.options.onRuntimeNotice ? { onRuntimeNotice: this.options.onRuntimeNotice } : {},
36228
+ ...this.options.events ? { events: this.options.events } : {},
36229
+ signal: controller.signal,
36230
+ ...this.options.onWorkerStderrTail ? { onStderrTail: this.options.onWorkerStderrTail } : {},
36231
+ clientName: "cswarm-listener"
36232
+ });
36233
+ this.openingHandle = handle;
36234
+ try {
36235
+ if (this.closed) throw new ClaudeListenerClosedDuringOpen();
36236
+ await this.enablePromptsAfterClaudeCanary(handle);
36237
+ if (this.closed) throw new ClaudeListenerClosedDuringOpen();
36238
+ this.workerCanary = false;
36239
+ this.worker = handle;
36240
+ return handle;
36241
+ } catch (error) {
36242
+ await handle.close();
36243
+ throw error;
36244
+ } finally {
36245
+ if (this.openingHandle === handle) this.openingHandle = null;
36246
+ }
36247
+ } finally {
36248
+ if (this.openingController === controller) this.openingController = null;
36249
+ }
36277
36250
  }
36278
- }
36279
- function assertAckRequest(request) {
36280
- checkedCommandId(request.commandId);
36281
- assertAgentToken(request.credential);
36282
- checkedUuidRequest(request.workspaceId, "workspaceId");
36283
- checkedUuidRequest(request.signalId, "signalId");
36284
- checkedUuidRequest(request.leaseId, "leaseId");
36285
- checkedUuidRequest(request.listenerInstanceId, "listenerInstanceId");
36286
- if (!DELIVERY_ACK_OUTCOMES.has(request.outcome)) {
36287
- throw new Error(
36288
- "a delivery outcome must be replied, observed, queued, expired, or failed_terminal"
36251
+ /** Force Claude's measured Write permission path without changing worker cwd. */
36252
+ async enablePromptsAfterClaudeCanary(handle) {
36253
+ const sentinelPath = (0, import_node_path13.join)(
36254
+ (0, import_node_os8.tmpdir)(),
36255
+ `cswarm-claude-permission-canary-${process.pid}-${(0, import_node_crypto16.randomUUID)()}`
36289
36256
  );
36290
- }
36291
- if (request.outcome === "failed_terminal") {
36292
- if (typeof request.lastErrorCode !== "string" || !FAILED_TERMINAL_CODES_SET.has(request.lastErrorCode)) {
36293
- throw new Error(
36294
- "a failed_terminal acknowledgement requires one of provider_refused, local_effect_failed, host_session_failed, credential_unavailable"
36257
+ let canaryError;
36258
+ let sentinelCreated = false;
36259
+ try {
36260
+ await handle.session.enablePromptsAfterCanary({
36261
+ timeoutMs: ACP_CANARY_TIMEOUT_MS,
36262
+ probeText: `Create the file ${sentinelPath} using the Write tool with content CSWARM_CANARY_NOOP. You must use the Write tool. Do nothing else.`,
36263
+ ...this.options.onCanaryAttempt ? { onAttempt: this.options.onCanaryAttempt } : {}
36264
+ });
36265
+ } catch (error) {
36266
+ canaryError = error;
36267
+ } finally {
36268
+ try {
36269
+ await (0, import_promises7.lstat)(sentinelPath);
36270
+ sentinelCreated = true;
36271
+ await (0, import_promises7.unlink)(sentinelPath);
36272
+ } catch (error) {
36273
+ if (error.code !== "ENOENT") throw error;
36274
+ }
36275
+ }
36276
+ if (sentinelCreated) {
36277
+ throw new AcpPermissionCanaryError(
36278
+ "Claude bridge wrote the permission canary sentinel before denial",
36279
+ "claude_canary_write_not_blocked"
36295
36280
  );
36296
36281
  }
36297
- } else if (request.lastErrorCode !== null) {
36298
- throw new Error(
36299
- "a non-failed acknowledgement must send lastErrorCode null"
36300
- );
36301
- }
36302
- }
36303
- function boundedDeliveryErrorCode(body) {
36304
- if (!body || typeof body !== "object" || Array.isArray(body)) {
36305
- return DELIVERY_UNKNOWN_ERROR_CODE;
36306
- }
36307
- const error = body.error;
36308
- if (typeof error === "string" && SERVER_ERROR_CODES_SET.has(error)) {
36309
- return error;
36282
+ if (canaryError instanceof AcpPermissionCanaryError) {
36283
+ const shape = classifyClaudeCanaryFailure(
36284
+ canaryError.message,
36285
+ canaryError.reasonCode,
36286
+ canaryError.peerError
36287
+ );
36288
+ throw new AcpPermissionCanaryError(
36289
+ canaryError.message,
36290
+ shape.code,
36291
+ shape.minimumRequiredVersion
36292
+ );
36293
+ }
36294
+ if (canaryError !== void 0) throw canaryError;
36310
36295
  }
36311
- return DELIVERY_UNKNOWN_ERROR_CODE;
36312
- }
36313
- function refusal(response, text) {
36314
- let code = DELIVERY_UNKNOWN_ERROR_CODE;
36315
- try {
36316
- code = boundedDeliveryErrorCode(JSON.parse(text));
36317
- } catch {
36296
+ };
36297
+
36298
+ // src/listener/codex-model.ts
36299
+ var import_node_crypto17 = require("node:crypto");
36300
+ var import_promises8 = require("node:fs/promises");
36301
+ var import_node_os9 = require("node:os");
36302
+ var import_node_path14 = require("node:path");
36303
+ var CodexListenerClosedDuringOpen = class extends Error {
36304
+ constructor() {
36305
+ super("listener model closed while the Codex worker was opening");
36306
+ this.name = "CodexListenerClosedDuringOpen";
36318
36307
  }
36319
- const retryAfterMs = parseRetryAfterMs(response.headers.get("retry-after"));
36320
- return new DeliveryHttpError(
36321
- response.status,
36322
- code,
36323
- `delivery command failed (HTTP ${response.status}): ${code}`,
36324
- retryAfterMs
36325
- );
36308
+ };
36309
+ function pathIsInsideOrEqual(ancestor, candidate) {
36310
+ const fromAncestor = (0, import_node_path14.relative)(ancestor, candidate);
36311
+ return fromAncestor === "" || fromAncestor !== ".." && !fromAncestor.startsWith(`..${import_node_path14.sep}`) && !(0, import_node_path14.isAbsolute)(fromAncestor);
36326
36312
  }
36327
- function successBody(response, text, verb) {
36328
- try {
36329
- return JSON.parse(text);
36330
- } catch {
36331
- throw new DeliveryProtocolError(
36332
- `${verb} response was not JSON (HTTP ${response.status})`
36333
- );
36313
+ var CodexListenerModel = class {
36314
+ constructor(options) {
36315
+ this.options = options;
36316
+ this.openSession = options.open ?? openCodexAcpSession;
36317
+ this.permissionMode = options.permissionMode ?? "deny";
36334
36318
  }
36335
- }
36336
- var DeliveryCommandClient = class {
36337
- constructor(target2, fetcher = fetch, options = {}) {
36338
- this.target = target2;
36339
- this.fetcher = fetcher;
36340
- this.deadlineMs = options.deadlineMs ?? DELIVERY_REQUEST_TIMEOUT_MS;
36341
- this.now = options.now ?? Date.now;
36342
- this.clearTimeoutFn = options.clearTimeout ?? ((timer2) => clearTimeout(timer2));
36343
- this.createAbortControllerFn = options.createAbortController ?? (() => new AbortController());
36319
+ options;
36320
+ openSession;
36321
+ permissionMode;
36322
+ worker = null;
36323
+ opening = null;
36324
+ openingController = null;
36325
+ openingHandle = null;
36326
+ workerCanary = true;
36327
+ closed = false;
36328
+ closePromise = null;
36329
+ /** Initialize the worker and deny canary before reporting ready. */
36330
+ async start() {
36331
+ await this.ensureWorker();
36344
36332
  }
36345
- target;
36346
- fetcher;
36347
- deadlineMs;
36348
- now;
36349
- clearTimeoutFn;
36350
- createAbortControllerFn;
36351
- async post(request, command2, verb) {
36352
- if (this.deadlineMs <= 0) {
36353
- throw new DeliveryTransportError(`${verb} request timed out`);
36354
- }
36355
- const deadlineController = this.createAbortControllerFn();
36356
- let timedOut = false;
36357
- const signal = deadlineController.signal;
36358
- let onAbort = () => {
36359
- };
36360
- const aborted = new Promise((resolve3) => {
36361
- onAbort = () => resolve3("timeout");
36362
- if (signal.aborted) {
36363
- onAbort();
36364
- } else {
36365
- signal.addEventListener("abort", onAbort, { once: true });
36366
- }
36367
- });
36368
- const timer2 = setTimeout(() => {
36369
- timedOut = true;
36370
- deadlineController.abort();
36371
- }, this.deadlineMs);
36333
+ async prompt(_signal, _mode, prompt) {
36334
+ if (this.closed) throw new Error("listener model is closed");
36335
+ const worker = await this.ensureWorker();
36336
+ const budget = this.options.promptTimeoutMs ?? LISTENER_PROMPT_TIMEOUT_MS;
36372
36337
  try {
36373
- if (signal.aborted) {
36374
- throw new DeliveryTransportError(`${verb} request timed out`);
36338
+ return await resolveBudgetAndPrompt(worker.session, prompt, budget);
36339
+ } catch (error) {
36340
+ if (error instanceof AcpChildExitError) {
36341
+ try {
36342
+ await worker.close();
36343
+ } finally {
36344
+ if (this.worker === worker) this.worker = null;
36345
+ }
36375
36346
  }
36376
- const read = (async () => {
36377
- let response;
36347
+ throw error;
36348
+ }
36349
+ }
36350
+ cancel() {
36351
+ this.worker?.session.cancel();
36352
+ }
36353
+ async close() {
36354
+ if (this.closePromise) return this.closePromise;
36355
+ this.closed = true;
36356
+ this.cancel();
36357
+ this.closePromise = (async () => {
36358
+ const closeFailures = [];
36359
+ const opening = this.opening;
36360
+ this.openingController?.abort();
36361
+ const openingHandle = this.openingHandle;
36362
+ if (openingHandle) {
36378
36363
  try {
36379
- response = await this.fetcher(commandEndpoint(this.target), {
36380
- method: "POST",
36381
- headers: {
36382
- authorization: `Bearer ${request.credential}`,
36383
- apikey: this.target.anonKey,
36384
- "content-type": "application/json"
36385
- },
36386
- body: JSON.stringify({
36387
- command_id: request.commandId,
36388
- client_version: CLIENT_PROTOCOL_VERSION,
36389
- workspace_id: request.workspaceId.toLowerCase(),
36390
- stream: { kind: "workspace" },
36391
- command: command2
36392
- }),
36393
- signal
36394
- });
36364
+ openingHandle.session.cancel();
36365
+ } catch {
36366
+ }
36367
+ try {
36368
+ await openingHandle.close();
36395
36369
  } catch (error) {
36396
- if (signal.aborted || timedOut || error?.name === "AbortError") {
36397
- return "timeout";
36370
+ closeFailures.push(error);
36371
+ }
36372
+ }
36373
+ if (opening) {
36374
+ try {
36375
+ await opening;
36376
+ } catch (error) {
36377
+ const code = error.code;
36378
+ if (!(error instanceof CodexListenerClosedDuringOpen) && code !== "cancelled" && !openingHandle) {
36379
+ throw error;
36398
36380
  }
36399
- throw new DeliveryTransportError(
36400
- `${verb} request failed before a response`
36401
- );
36402
36381
  }
36403
- if (signal.aborted || timedOut) return "timeout";
36404
- let text;
36382
+ }
36383
+ const handle = this.worker;
36384
+ this.worker = null;
36385
+ if (handle && handle !== openingHandle) {
36405
36386
  try {
36406
- text = await response.text();
36407
- } catch {
36408
- if (signal.aborted || timedOut) return "timeout";
36409
- throw new DeliveryTransportError(
36410
- `${verb} response body was interrupted`
36411
- );
36387
+ await handle.close();
36388
+ } catch (error) {
36389
+ closeFailures.push(error);
36412
36390
  }
36413
- if (signal.aborted || timedOut) return "timeout";
36414
- return { response, text };
36415
- })();
36416
- const raced = await Promise.race([read, aborted]);
36417
- if (raced === "timeout") {
36418
- throw new DeliveryTransportError(`${verb} request timed out`);
36419
36391
  }
36420
- return raced;
36392
+ if (closeFailures.length > 0) throw closeFailures[0];
36393
+ })();
36394
+ return this.closePromise;
36395
+ }
36396
+ async ensureWorker() {
36397
+ if (this.closed) throw new Error("listener model is closed");
36398
+ if (this.worker) return this.worker;
36399
+ if (this.opening) return this.opening;
36400
+ const opening = this.openWorker();
36401
+ this.opening = opening;
36402
+ try {
36403
+ return await opening;
36421
36404
  } finally {
36422
- this.clearTimeoutFn(timer2);
36423
- signal.removeEventListener("abort", onAbort);
36405
+ if (this.opening === opening) this.opening = null;
36424
36406
  }
36425
36407
  }
36426
- /** Claim the caller's own single unacked direct-signal delivery row. */
36427
- async claimAgentInbox(request) {
36428
- checkedCommandId(request.commandId);
36429
- assertAgentToken(request.credential);
36430
- checkedUuidRequest(request.workspaceId, "workspaceId");
36431
- checkedUuidRequest(request.listenerInstanceId, "listenerInstanceId");
36432
- checkedUuidRequest(request.expectedPrincipalId, "expectedPrincipalId");
36433
- const { response, text } = await this.post(request, {
36434
- kind: "claim_agent_inbox",
36435
- listener_instance_id: request.listenerInstanceId.toLowerCase(),
36436
- limit: 1
36437
- }, "delivery claim");
36438
- if (!response.ok) throw refusal(response, text);
36439
- const parsed = parseClaimSuccess(
36440
- successBody(response, text, "delivery claim"),
36441
- {
36442
- workspaceId: request.workspaceId.toLowerCase(),
36443
- principalId: request.expectedPrincipalId.toLowerCase()
36444
- },
36445
- this.now
36446
- );
36447
- return {
36448
- httpStatus: response.status,
36449
- capabilities: parsed.capabilities,
36450
- deliveries: parsed.deliveries,
36451
- pendingDeliveryCount: parsed.pendingDeliveryCount,
36452
- terminalDeliveryFailureCount: parsed.terminalDeliveryFailureCount
36453
- };
36454
- }
36455
- /** Acknowledge one leased delivery with an exact terminal outcome. */
36456
- async ackAgentDelivery(request) {
36457
- assertAckRequest(request);
36458
- const { response, text } = await this.post(request, {
36459
- kind: "ack_agent_delivery",
36460
- signal_id: request.signalId.toLowerCase(),
36461
- lease_id: request.leaseId.toLowerCase(),
36462
- listener_instance_id: request.listenerInstanceId.toLowerCase(),
36463
- outcome: request.outcome,
36464
- last_error_code: request.lastErrorCode
36465
- }, "delivery acknowledgement");
36466
- if (!response.ok) throw refusal(response, text);
36467
- parseAckSuccess(
36468
- successBody(response, text, "delivery acknowledgement"),
36469
- {
36470
- signalId: request.signalId.toLowerCase(),
36471
- outcome: request.outcome
36408
+ async openWorker() {
36409
+ const controller = new AbortController();
36410
+ this.openingController = controller;
36411
+ this.workerCanary = true;
36412
+ const permissionCallback = (request) => this.workerCanary || this.permissionMode === "deny" ? defaultPermissionCallback(request) : allowOnceOrDeny(request);
36413
+ try {
36414
+ const handle = await this.openSession({
36415
+ cwd: this.options.cwd,
36416
+ permissionCallback,
36417
+ ...this.options.executable ? { executable: this.options.executable } : {},
36418
+ ...this.options.env ? { env: this.options.env } : {},
36419
+ ...this.options.onVersionNotice ? { onVersionNotice: this.options.onVersionNotice } : {},
36420
+ ...this.options.events ? { events: this.options.events } : {},
36421
+ signal: controller.signal,
36422
+ ...this.options.onWorkerStderrTail ? { onStderrTail: this.options.onWorkerStderrTail } : {},
36423
+ clientName: "cswarm-listener"
36424
+ });
36425
+ this.openingHandle = handle;
36426
+ try {
36427
+ if (this.closed) throw new CodexListenerClosedDuringOpen();
36428
+ await this.enablePromptsAfterCodexCanary(handle);
36429
+ if (this.closed) throw new CodexListenerClosedDuringOpen();
36430
+ this.workerCanary = false;
36431
+ this.worker = handle;
36432
+ return handle;
36433
+ } catch (error) {
36434
+ await handle.close();
36435
+ throw error;
36436
+ } finally {
36437
+ if (this.openingHandle === handle) this.openingHandle = null;
36472
36438
  }
36473
- );
36474
- return {
36475
- httpStatus: response.status,
36476
- signalId: request.signalId.toLowerCase(),
36477
- outcome: request.outcome
36478
- };
36439
+ } finally {
36440
+ if (this.openingController === controller) this.openingController = null;
36441
+ }
36479
36442
  }
36480
- /** Mark a queued delivery observed only after the interactive hook surfaced it. */
36481
- async observeQueuedAgentDelivery(request) {
36482
- checkedCommandId(request.commandId);
36483
- assertAgentToken(request.credential);
36484
- checkedUuidRequest(request.workspaceId, "workspaceId");
36485
- checkedUuidRequest(request.signalId, "signalId");
36486
- const { response, text } = await this.post(request, {
36487
- kind: "ack_agent_delivery",
36488
- signal_id: request.signalId.toLowerCase(),
36489
- lease_id: null,
36490
- listener_instance_id: null,
36491
- outcome: "observed",
36492
- last_error_code: null
36493
- }, "delivery observation");
36494
- if (!response.ok) throw refusal(response, text);
36495
- parseAckSuccess(
36496
- successBody(response, text, "delivery observation"),
36497
- {
36498
- signalId: request.signalId.toLowerCase(),
36499
- outcome: "observed"
36500
- }
36443
+ /** Force Codex's measured shell permission path without changing worker cwd. */
36444
+ async enablePromptsAfterCodexCanary(handle) {
36445
+ const configuredHome = this.options.env?.HOME;
36446
+ const home = configuredHome && (0, import_node_path14.isAbsolute)(configuredHome) ? configuredHome : (0, import_node_os9.homedir)();
36447
+ const sentinelDirectory = (0, import_node_path14.join)(home, ".cswarm", "canary");
36448
+ await (0, import_promises8.mkdir)(sentinelDirectory, { recursive: true, mode: 448 });
36449
+ await (0, import_promises8.chmod)(sentinelDirectory, 448);
36450
+ const [workerCwd, canaryDirectory] = await Promise.all([
36451
+ (0, import_promises8.realpath)(this.options.cwd),
36452
+ (0, import_promises8.realpath)(sentinelDirectory)
36453
+ ]);
36454
+ if (pathIsInsideOrEqual(workerCwd, canaryDirectory)) {
36455
+ throw new AcpPermissionCanaryError(
36456
+ `canary_path_inside_cwd: ${canaryDirectory} is inside listener cwd ${workerCwd}. Next: pass a --cwd that is not your home directory`
36457
+ );
36458
+ }
36459
+ const sentinelPath = (0, import_node_path14.join)(
36460
+ canaryDirectory,
36461
+ `cswarm-codex-permission-canary-${process.pid}-${(0, import_node_crypto17.randomUUID)()}`
36501
36462
  );
36502
- return {
36503
- httpStatus: response.status,
36504
- signalId: request.signalId.toLowerCase(),
36505
- outcome: "observed"
36506
- };
36463
+ let canaryError;
36464
+ let sentinelCreated = false;
36465
+ try {
36466
+ await handle.session.enablePromptsAfterCanary({
36467
+ timeoutMs: ACP_CANARY_TIMEOUT_MS,
36468
+ probeText: `Use a shell command to create ${sentinelPath} with content CSWARM_CANARY_NOOP. You must use the shell. Do nothing else.`,
36469
+ ...this.options.onCanaryAttempt ? { onAttempt: this.options.onCanaryAttempt } : {}
36470
+ });
36471
+ } catch (error) {
36472
+ canaryError = error;
36473
+ } finally {
36474
+ try {
36475
+ await (0, import_promises8.lstat)(sentinelPath);
36476
+ sentinelCreated = true;
36477
+ await (0, import_promises8.unlink)(sentinelPath);
36478
+ } catch (error) {
36479
+ if (error.code !== "ENOENT") throw error;
36480
+ }
36481
+ }
36482
+ const observation = handle.session.canaryObservation;
36483
+ const sawPermissionRequest = observation?.sawPermissionRequest === true;
36484
+ const bridgeVersion = handle.providerVersion ?? handle.session.info?.agentVersion ?? "unknown";
36485
+ if (sentinelCreated && !sawPermissionRequest) {
36486
+ throw new AcpPermissionCanaryError(
36487
+ `canary_executed_without_permission: codex-acp ${bridgeVersion} ran the shell probe without a permission request and wrote ${sentinelPath}. Next: replace codex-acp ${bridgeVersion} with a bridge version that asks before writing ${sentinelPath}`
36488
+ );
36489
+ }
36490
+ if (sentinelCreated) {
36491
+ throw new AcpPermissionCanaryError(
36492
+ `canary_write_not_blocked: codex-acp ${bridgeVersion} wrote ${sentinelPath} even though the host rejected the canary. Next: update or reinstall the codex-acp bridge`
36493
+ );
36494
+ }
36495
+ if (canaryError instanceof AcpPermissionCanaryError) {
36496
+ if (canaryError.reasonCode === "timeout") {
36497
+ throw new AcpPermissionCanaryError(
36498
+ `canary_timeout: ${canaryError.message}. Next: retry to run a fresh bounded permission canary`,
36499
+ "timeout"
36500
+ );
36501
+ }
36502
+ if (canaryError.reasonCode !== null) {
36503
+ throw new AcpPermissionCanaryError(
36504
+ `canary_bridge_error: codex-acp ${bridgeVersion} returned ${canaryError.message}. Next: resolve the quoted bridge error, then retry`,
36505
+ canaryError.reasonCode
36506
+ );
36507
+ }
36508
+ if (!sawPermissionRequest) {
36509
+ throw new AcpPermissionCanaryError(
36510
+ `canary_no_tool_call: codex-acp ${bridgeVersion} did not request permission or create ${sentinelPath}. Next: retry to re-sample the model's shell choice`
36511
+ );
36512
+ }
36513
+ }
36514
+ if (canaryError !== void 0) throw canaryError;
36507
36515
  }
36508
36516
  };
36509
36517
 
36518
+ // src/listener/runtime.ts
36519
+ var import_node_crypto18 = require("node:crypto");
36520
+
36510
36521
  // src/listener/main-routing.ts
36511
36522
  var import_node_path15 = require("node:path");
36512
36523
  var UUID_RE16 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
@@ -38103,6 +38114,7 @@ var MAX_CONTROL_BYTES = 8 * 1024;
38103
38114
  var CONTROL_TIMEOUT_MS = 2e3;
38104
38115
  var START_LOCK_WAIT_MS = 2e3;
38105
38116
  var START_LOCK_STALE_MS = 1e4;
38117
+ var LISTENER_DELIVERY_FAILING_THRESHOLD = 3;
38106
38118
  var ListenerAlreadyRunningError = class extends Error {
38107
38119
  constructor() {
38108
38120
  super("a listener is already running for this agent principal");
@@ -38165,6 +38177,9 @@ var STATUS_ALLOWED_KEYS = /* @__PURE__ */ new Set([
38165
38177
  "lastTerminalDeliveryFailureAt",
38166
38178
  "lastClaimAt",
38167
38179
  "lastAckAt",
38180
+ "lastAckOutcome",
38181
+ "consecutiveAckFailureCount",
38182
+ "lastAckSignalId",
38168
38183
  "routeMode",
38169
38184
  "deferOverChars",
38170
38185
  "pendingForMainCount",
@@ -38204,8 +38219,11 @@ var STATUS_DELIVERY_KEYS = [
38204
38219
  "lastTerminalDeliveryFailureCount",
38205
38220
  "lastTerminalDeliveryFailureAt",
38206
38221
  "lastClaimAt",
38207
- "lastAckAt"
38222
+ "lastAckAt",
38223
+ "lastAckOutcome",
38224
+ "consecutiveAckFailureCount"
38208
38225
  ];
38226
+ var deliveryOutcomes = DELIVERY_ACK_OUTCOMES;
38209
38227
  function parseStatus(raw, rejectUnknownKeys = false) {
38210
38228
  let value;
38211
38229
  try {
@@ -38229,7 +38247,7 @@ function parseStatus(raw, rejectUnknownKeys = false) {
38229
38247
  const nullableCount = (candidate) => candidate === null || typeof candidate === "number" && Number.isSafeInteger(candidate) && candidate >= 0;
38230
38248
  const nullableTimestamp3 = (candidate) => candidate === null || typeof candidate === "string" && Number.isFinite(Date.parse(candidate));
38231
38249
  const readHealth = row.readHealth === void 0 ? void 0 : parseListenerReadHealth(row.readHealth, rejectUnknownKeys);
38232
- if (row.version !== 1 || typeof row.instanceId !== "string" || !UUID_RE18.test(row.instanceId) || row.provider !== "grok" && row.provider !== "opencode" && row.provider !== "claude" && row.provider !== "codex" || typeof row.profileId !== "string" || typeof row.workspaceId !== "string" || !UUID_RE18.test(row.workspaceId) || typeof row.principalId !== "string" || !UUID_RE18.test(row.principalId) || !Number.isSafeInteger(row.pid) || row.pid < 1 || typeof row.state !== "string" || !["starting", "ready", "stopping", "stopped", "failed"].includes(row.state) || typeof row.startedAt !== "string" || !Number.isFinite(Date.parse(row.startedAt)) || !(row.readyAt === null || typeof row.readyAt === "string" && Number.isFinite(Date.parse(row.readyAt))) || typeof row.updatedAt !== "string" || !Number.isFinite(Date.parse(row.updatedAt)) || !(row.stoppedAt === null || typeof row.stoppedAt === "string" && Number.isFinite(Date.parse(row.stoppedAt))) || !nullableUuid3(row.lastSignalId) || !(row.lastErrorCode === null || typeof row.lastErrorCode === "string" && /^[a-z0-9_-]{1,96}$/.test(row.lastErrorCode)) || !(row.lastErrorDetail === void 0 || row.lastErrorDetail === null || typeof row.lastErrorDetail === "string" && row.lastErrorDetail.length > 0 && row.lastErrorDetail.length <= 2048 && !/swm_(?:agt|inv|cap)_/i.test(row.lastErrorDetail)) || !(row.lastErrorReasonCode === void 0 || row.lastErrorReasonCode === null || typeof row.lastErrorReasonCode === "string" && /^[a-z0-9_-]{1,96}$/.test(row.lastErrorReasonCode)) || !(row.providerExecutable === void 0 || row.providerExecutable === null || typeof row.providerExecutable === "string" && (0, import_node_path16.isAbsolute)(row.providerExecutable)) || !(row.providerVersion === void 0 || row.providerVersion === null || typeof row.providerVersion === "string" && SEMVER_RE2.test(row.providerVersion)) || !(row.providerLastMeasuredVersion === void 0 || row.providerLastMeasuredVersion === null || typeof row.providerLastMeasuredVersion === "string" && SEMVER_RE2.test(row.providerLastMeasuredVersion)) || !(row.providerBundledAgentSdkVersion === void 0 || row.providerBundledAgentSdkVersion === null || typeof row.providerBundledAgentSdkVersion === "string" && SEMVER_RE2.test(row.providerBundledAgentSdkVersion)) || !(row.providerBundledClaudeCodeVersion === void 0 || row.providerBundledClaudeCodeVersion === null || typeof row.providerBundledClaudeCodeVersion === "string" && SEMVER_RE2.test(row.providerBundledClaudeCodeVersion)) || !(row.providerMinimumRequiredVersion === void 0 || row.providerMinimumRequiredVersion === null || typeof row.providerMinimumRequiredVersion === "string" && SEMVER_RE2.test(row.providerMinimumRequiredVersion)) || !(row.cswarmVersion === void 0 || row.cswarmVersion === null || typeof row.cswarmVersion === "string" && SEMVER_RE2.test(row.cswarmVersion)) || (row.providerVersion === null || row.providerVersion === void 0) !== (row.providerLastMeasuredVersion === null || row.providerLastMeasuredVersion === void 0) || !(row.lastWorkerStderrTail === void 0 || row.lastWorkerStderrTail === null || typeof row.lastWorkerStderrTail === "string" && row.lastWorkerStderrTail.length > 0 && row.lastWorkerStderrTail.length <= 2048 && !/swm_(?:agt|inv|cap)_/i.test(row.lastWorkerStderrTail)) || typeof row.logPath !== "string" || !(0, import_node_path16.isAbsolute)(row.logPath) || !(row.deliveryMode === void 0 || row.deliveryMode === null || typeof row.deliveryMode === "string" && STATUS_DELIVERY_MODES.has(row.deliveryMode)) || !(row.pendingDeliveryCount === void 0 || nullableCount(row.pendingDeliveryCount)) || !(row.lastTerminalDeliveryFailureCount === void 0 || nullableCount(row.lastTerminalDeliveryFailureCount)) || !(row.lastTerminalDeliveryFailureAt === void 0 || nullableTimestamp3(row.lastTerminalDeliveryFailureAt)) || !(row.lastClaimAt === void 0 || nullableTimestamp3(row.lastClaimAt)) || !(row.lastAckAt === void 0 || nullableTimestamp3(row.lastAckAt)) || !(row.routeMode === void 0 || row.routeMode === "worker" || row.routeMode === "main" || row.routeMode === "split") || !(row.deferOverChars === void 0 || row.deferOverChars === null || typeof row.deferOverChars === "number" && Number.isSafeInteger(row.deferOverChars) && row.deferOverChars >= 1 && row.deferOverChars <= 1e4) || !(row.pendingForMainCount === void 0 || typeof row.pendingForMainCount === "number" && Number.isSafeInteger(row.pendingForMainCount) && row.pendingForMainCount >= 0) || !(row.droppedForMainCount === void 0 || typeof row.droppedForMainCount === "number" && Number.isSafeInteger(row.droppedForMainCount) && row.droppedForMainCount >= 0) || readHealth === null || !(row.connectionsOpened === void 0 || typeof row.connectionsOpened === "number" && Number.isSafeInteger(row.connectionsOpened) && row.connectionsOpened >= 0) || !(row.connectionReuseRatio === void 0 || typeof row.connectionReuseRatio === "number" && Number.isFinite(row.connectionReuseRatio) && row.connectionReuseRatio >= 0) || !(row.activityPublishFailures === void 0 || typeof row.activityPublishFailures === "number" && Number.isSafeInteger(row.activityPublishFailures) && row.activityPublishFailures >= 0) || !(row.activityLastErrorCode === void 0 || row.activityLastErrorCode === null || typeof row.activityLastErrorCode === "string" && STATUS_ACTIVITY_ERROR_CODES.has(
38250
+ if (row.version !== 1 || typeof row.instanceId !== "string" || !UUID_RE18.test(row.instanceId) || row.provider !== "grok" && row.provider !== "opencode" && row.provider !== "claude" && row.provider !== "codex" || typeof row.profileId !== "string" || typeof row.workspaceId !== "string" || !UUID_RE18.test(row.workspaceId) || typeof row.principalId !== "string" || !UUID_RE18.test(row.principalId) || !Number.isSafeInteger(row.pid) || row.pid < 1 || typeof row.state !== "string" || !["starting", "ready", "stopping", "stopped", "failed"].includes(row.state) || typeof row.startedAt !== "string" || !Number.isFinite(Date.parse(row.startedAt)) || !(row.readyAt === null || typeof row.readyAt === "string" && Number.isFinite(Date.parse(row.readyAt))) || typeof row.updatedAt !== "string" || !Number.isFinite(Date.parse(row.updatedAt)) || !(row.stoppedAt === null || typeof row.stoppedAt === "string" && Number.isFinite(Date.parse(row.stoppedAt))) || !nullableUuid3(row.lastSignalId) || !(row.lastErrorCode === null || typeof row.lastErrorCode === "string" && /^[a-z0-9_-]{1,96}$/.test(row.lastErrorCode)) || !(row.lastErrorDetail === void 0 || row.lastErrorDetail === null || typeof row.lastErrorDetail === "string" && row.lastErrorDetail.length > 0 && row.lastErrorDetail.length <= 2048 && !/swm_(?:agt|inv|cap)_/i.test(row.lastErrorDetail)) || !(row.lastErrorReasonCode === void 0 || row.lastErrorReasonCode === null || typeof row.lastErrorReasonCode === "string" && /^[a-z0-9_-]{1,96}$/.test(row.lastErrorReasonCode)) || !(row.providerExecutable === void 0 || row.providerExecutable === null || typeof row.providerExecutable === "string" && (0, import_node_path16.isAbsolute)(row.providerExecutable)) || !(row.providerVersion === void 0 || row.providerVersion === null || typeof row.providerVersion === "string" && SEMVER_RE2.test(row.providerVersion)) || !(row.providerLastMeasuredVersion === void 0 || row.providerLastMeasuredVersion === null || typeof row.providerLastMeasuredVersion === "string" && SEMVER_RE2.test(row.providerLastMeasuredVersion)) || !(row.providerBundledAgentSdkVersion === void 0 || row.providerBundledAgentSdkVersion === null || typeof row.providerBundledAgentSdkVersion === "string" && SEMVER_RE2.test(row.providerBundledAgentSdkVersion)) || !(row.providerBundledClaudeCodeVersion === void 0 || row.providerBundledClaudeCodeVersion === null || typeof row.providerBundledClaudeCodeVersion === "string" && SEMVER_RE2.test(row.providerBundledClaudeCodeVersion)) || !(row.providerMinimumRequiredVersion === void 0 || row.providerMinimumRequiredVersion === null || typeof row.providerMinimumRequiredVersion === "string" && SEMVER_RE2.test(row.providerMinimumRequiredVersion)) || !(row.cswarmVersion === void 0 || row.cswarmVersion === null || typeof row.cswarmVersion === "string" && SEMVER_RE2.test(row.cswarmVersion)) || (row.providerVersion === null || row.providerVersion === void 0) !== (row.providerLastMeasuredVersion === null || row.providerLastMeasuredVersion === void 0) || !(row.lastWorkerStderrTail === void 0 || row.lastWorkerStderrTail === null || typeof row.lastWorkerStderrTail === "string" && row.lastWorkerStderrTail.length > 0 && row.lastWorkerStderrTail.length <= 2048 && !/swm_(?:agt|inv|cap)_/i.test(row.lastWorkerStderrTail)) || typeof row.logPath !== "string" || !(0, import_node_path16.isAbsolute)(row.logPath) || !(row.deliveryMode === void 0 || row.deliveryMode === null || typeof row.deliveryMode === "string" && STATUS_DELIVERY_MODES.has(row.deliveryMode)) || !(row.pendingDeliveryCount === void 0 || nullableCount(row.pendingDeliveryCount)) || !(row.lastTerminalDeliveryFailureCount === void 0 || nullableCount(row.lastTerminalDeliveryFailureCount)) || !(row.lastTerminalDeliveryFailureAt === void 0 || nullableTimestamp3(row.lastTerminalDeliveryFailureAt)) || !(row.lastClaimAt === void 0 || nullableTimestamp3(row.lastClaimAt)) || !(row.lastAckAt === void 0 || nullableTimestamp3(row.lastAckAt)) || !(row.lastAckOutcome === void 0 || row.lastAckOutcome === null || typeof row.lastAckOutcome === "string" && deliveryOutcomes.has(row.lastAckOutcome)) || !(row.consecutiveAckFailureCount === void 0 || nullableCount(row.consecutiveAckFailureCount)) || !(row.lastAckSignalId === void 0 || row.lastAckSignalId === null || typeof row.lastAckSignalId === "string" && UUID_RE18.test(row.lastAckSignalId)) || !(row.routeMode === void 0 || row.routeMode === "worker" || row.routeMode === "main" || row.routeMode === "split") || !(row.deferOverChars === void 0 || row.deferOverChars === null || typeof row.deferOverChars === "number" && Number.isSafeInteger(row.deferOverChars) && row.deferOverChars >= 1 && row.deferOverChars <= 1e4) || !(row.pendingForMainCount === void 0 || typeof row.pendingForMainCount === "number" && Number.isSafeInteger(row.pendingForMainCount) && row.pendingForMainCount >= 0) || !(row.droppedForMainCount === void 0 || typeof row.droppedForMainCount === "number" && Number.isSafeInteger(row.droppedForMainCount) && row.droppedForMainCount >= 0) || readHealth === null || !(row.connectionsOpened === void 0 || typeof row.connectionsOpened === "number" && Number.isSafeInteger(row.connectionsOpened) && row.connectionsOpened >= 0) || !(row.connectionReuseRatio === void 0 || typeof row.connectionReuseRatio === "number" && Number.isFinite(row.connectionReuseRatio) && row.connectionReuseRatio >= 0) || !(row.activityPublishFailures === void 0 || typeof row.activityPublishFailures === "number" && Number.isSafeInteger(row.activityPublishFailures) && row.activityPublishFailures >= 0) || !(row.activityLastErrorCode === void 0 || row.activityLastErrorCode === null || typeof row.activityLastErrorCode === "string" && STATUS_ACTIVITY_ERROR_CODES.has(
38233
38251
  row.activityLastErrorCode
38234
38252
  ))) {
38235
38253
  throw new Error("stored listener status is malformed");
@@ -38250,6 +38268,11 @@ function parseStatus(raw, rejectUnknownKeys = false) {
38250
38268
  lastTerminalDeliveryFailureAt: row.lastTerminalDeliveryFailureAt ?? null,
38251
38269
  lastClaimAt: row.lastClaimAt ?? null,
38252
38270
  lastAckAt: row.lastAckAt ?? null,
38271
+ lastAckOutcome: row.lastAckOutcome ?? null,
38272
+ consecutiveAckFailureCount: row.consecutiveAckFailureCount ?? null,
38273
+ // Optional key: present only when the file carried it, so a status written
38274
+ // without it round-trips byte-for-byte (the routeMode pattern).
38275
+ ...row.lastAckSignalId === void 0 ? {} : { lastAckSignalId: row.lastAckSignalId ?? null },
38253
38276
  lastErrorDetail: row.lastErrorDetail ?? null,
38254
38277
  lastWorkerStderrTail: row.lastWorkerStderrTail ?? null,
38255
38278
  providerVersion: row.providerVersion ?? null,
@@ -38329,13 +38352,6 @@ async function appendListenerEvent(paths, event) {
38329
38352
  "dropped_count"
38330
38353
  ]);
38331
38354
  const deliveryModes = /* @__PURE__ */ new Set(["durable_claim", "cursor_fallback"]);
38332
- const deliveryOutcomes = /* @__PURE__ */ new Set([
38333
- "replied",
38334
- "observed",
38335
- "queued",
38336
- "expired",
38337
- "failed_terminal"
38338
- ]);
38339
38355
  const routeModes = /* @__PURE__ */ new Set(["worker", "main", "split"]);
38340
38356
  const routeDecisions = /* @__PURE__ */ new Set(["worker", "main"]);
38341
38357
  for (const [key2, value] of Object.entries(event)) {
@@ -38745,6 +38761,7 @@ async function runListenerSupervisor(options) {
38745
38761
  const startedAt = iso2(now);
38746
38762
  const controller = new AbortController();
38747
38763
  const proposedInstanceId = (0, import_node_crypto20.randomUUID)();
38764
+ const carried = await readListenerStatus(options.paths).catch(() => null);
38748
38765
  let status = {
38749
38766
  version: 1,
38750
38767
  instanceId: proposedInstanceId,
@@ -38760,7 +38777,7 @@ async function runListenerSupervisor(options) {
38760
38777
  readyAt: null,
38761
38778
  updatedAt: startedAt,
38762
38779
  stoppedAt: null,
38763
- lastSignalId: null,
38780
+ lastSignalId: carried?.lastSignalId ?? null,
38764
38781
  lastErrorCode: null,
38765
38782
  lastErrorDetail: null,
38766
38783
  lastErrorReasonCode: null,
@@ -38776,7 +38793,14 @@ async function runListenerSupervisor(options) {
38776
38793
  lastTerminalDeliveryFailureCount: null,
38777
38794
  lastTerminalDeliveryFailureAt: null,
38778
38795
  lastClaimAt: null,
38779
- lastAckAt: null,
38796
+ /* The ack record is carried WHOLE. Carrying the outcome and the run without
38797
+ their timestamp and signal id rendered a screen whose own sentences
38798
+ disagreed -- "the newest delivery acknowledgement was replied" above
38799
+ "No signal has been handled yet." */
38800
+ lastAckAt: carried?.lastAckAt ?? null,
38801
+ lastAckOutcome: carried?.lastAckOutcome ?? null,
38802
+ consecutiveAckFailureCount: carried?.consecutiveAckFailureCount ?? null,
38803
+ lastAckSignalId: carried?.lastAckSignalId ?? null,
38780
38804
  routeMode: options.routeMode ?? "worker",
38781
38805
  deferOverChars: options.deferOverChars ?? null,
38782
38806
  pendingForMainCount: 0,
@@ -38857,6 +38881,17 @@ async function runListenerSupervisor(options) {
38857
38881
  const versionNotice = options.getProviderVersionNotice?.() ?? null;
38858
38882
  transition("ready", {
38859
38883
  readyAt: event.ts,
38884
+ // Deliberately does NOT clear consecutiveAckFailureCount. Reaching
38885
+ // `ready` is not provider proof: the permission canary is its own
38886
+ // prompt, and a provider can answer it and fail every real one --
38887
+ // tests/listener-cli-process.test.ts builds such a child, whose
38888
+ // `failPrompts` trips only non-canary prompts (that test does not
38889
+ // restart it, so it does not by itself exercise this path). Clearing
38890
+ // the run here while `lastAckOutcome` still held a stale `observed`
38891
+ // put `HANDLED: yes` back on the incident screen after any restartable
38892
+ // blip. Only a `replied` ack clears the run; the pin is in
38893
+ // tests/listener-runtime.test.ts, which fires `ready` after the
38894
+ // measured incident and asserts the run survives it.
38860
38895
  lastErrorCode: null,
38861
38896
  lastErrorDetail: null,
38862
38897
  lastErrorReasonCode: null,
@@ -39041,9 +39076,14 @@ async function runListenerSupervisor(options) {
39041
39076
  return;
39042
39077
  }
39043
39078
  if (event.type === "delivery_ack") {
39079
+ const failed = event.outcome === "failed_terminal";
39080
+ const providerProven = DELIVERY_PROVIDER_PROVEN_OUTCOMES.has(event.outcome);
39044
39081
  status = {
39045
39082
  ...status,
39046
39083
  lastAckAt: event.ts,
39084
+ lastAckOutcome: event.outcome,
39085
+ lastAckSignalId: event.signalId,
39086
+ consecutiveAckFailureCount: failed ? (status.consecutiveAckFailureCount ?? 0) + 1 : providerProven ? 0 : status.consecutiveAckFailureCount,
39047
39087
  pendingDeliveryCount: null,
39048
39088
  lastSignalId: event.signalId,
39049
39089
  updatedAt: event.ts
@@ -41989,8 +42029,8 @@ var BOOLEAN_FLAGS = /* @__PURE__ */ new Set([
41989
42029
  ]);
41990
42030
  var UUID_RE23 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
41991
42031
  function packageVersion() {
41992
- if ("0.1.50".length > 0) {
41993
- return "0.1.50";
42032
+ if ("0.1.51".length > 0) {
42033
+ return "0.1.51";
41994
42034
  }
41995
42035
  try {
41996
42036
  const value = JSON.parse(
@@ -45027,7 +45067,9 @@ function listenerAttendanceState(status, evidence) {
45027
45067
  const connected = status.state === "ready";
45028
45068
  const attendanceState = routeMode === "worker" ? "not_required" : pending > 0 ? "unattended" : evidence.hookSurfaceAdvanced ? "attended" : "unproven";
45029
45069
  const attended = attendanceState === "attended" ? true : attendanceState === "unattended" ? false : null;
45030
- const handled = pending > 0 ? false : routeMode === "worker" && status.lastAckAt !== null ? true : null;
45070
+ const lastAckOutcome = status.lastAckOutcome ?? null;
45071
+ const deliveryFailing = (status.consecutiveAckFailureCount ?? 0) >= LISTENER_DELIVERY_FAILING_THRESHOLD;
45072
+ const handled = pending > 0 ? false : routeMode !== "worker" || lastAckOutcome === null ? null : deliveryFailing ? false : DELIVERY_HANDLED_OUTCOMES.has(lastAckOutcome) ? true : lastAckOutcome === "failed_terminal" ? false : null;
45031
45073
  return {
45032
45074
  connected,
45033
45075
  attended,
@@ -45068,10 +45110,36 @@ function listenerLapseNotices(status, summary) {
45068
45110
  }
45069
45111
  if (summary.throughputLapseHours.length > 0) {
45070
45112
  const latest = summary.throughputLapseHours.at(-1);
45113
+ const pending = status.pendingDeliveryCount;
45114
+ const pendingClause = pending === null ? " No pending count was recorded." : ` Pending deliveries now: ${pending}.`;
45115
+ const lapseRetries = summary.retryHours.find((hour) => hour.hourStart === latest.hourStart)?.retries ?? 0;
45071
45116
  notices.push({
45072
45117
  code: "listener_claim_throughput_lapse",
45073
- message: `Claim throughput fell below 0.50 for the full hour at ${latest.hourStart}: ${latest.claims}/${Math.round(latest.expectedClaims)} expected (${latest.ratio.toFixed(3)}).`,
45074
- nextStep: "This host is starving the listener \u2014 check load/memory pressure (sysctl kern.memorystatus_vm_pressure_level), or move the listener."
45118
+ message: `Claim throughput fell below ${LISTENER_THROUGHPUT_LAPSE_RATIO.toFixed(2)} for the full hour at ${latest.hourStart}: ${latest.claims}/${Math.round(latest.expectedClaims)} expected (${latest.ratio.toFixed(3)}).${pendingClause}`,
45119
+ nextStep: lapseRetries > 0 ? `Reads also failed in that hour: ${lapseRetries} ${lapseRetries === 1 ? "retry" : "retries"} recorded. Read those failures first; any notice above names the code. A retry does not say where the fault was \u2014 host_ports_exhausted is a retry AND a host fault.` : "No read retries were recorded in that hour, so the reads were not FAILING. That does not settle whether they were SLOW: a read that succeeds slowly records nothing here, and a claim retry sleeps in the claim loop without recording either. This notice measured nothing else about that hour, and nothing about the host \u2014 read any other notice above before looking further. Cheapest checks first: load average (uptime), process count, memory pressure (sysctl kern.memorystatus_vm_pressure_level, 1 is normal), sockets (netstat -an | grep -c TIME_WAIT)."
45120
+ });
45121
+ }
45122
+ const consecutive = status.consecutiveAckFailureCount ?? 0;
45123
+ if (consecutive >= LISTENER_DELIVERY_FAILING_THRESHOLD) {
45124
+ notices.push({
45125
+ code: "listener_delivery_failing",
45126
+ message: (
45127
+ // Do not assert "messages are not being answered": a notes-only listener
45128
+ // acks `observed` and is fine. State only what the run records.
45129
+ `The listener recorded ${consecutive} terminal delivery ${consecutive === 1 ? "failure" : "failures"} with no reply since. The newest acknowledgement was ${status.lastAckOutcome ?? "not recorded"} at ${status.lastAckAt ?? "an unknown time"}. The most recent listener error code is ${status.lastErrorCode ?? "not recorded"}.`
45130
+ ),
45131
+ nextStep: (
45132
+ // `failed_terminal` covers a refusing-but-healthy provider, a dead host
45133
+ // session, and a local post failure, and the run alone cannot tell them
45134
+ // apart — so name the check, not a diagnosis. The command needs the
45135
+ // credential on stdin, and the listener is still running here.
45136
+ // `stop` takes --principal-id and needs no credential, so it must not
45137
+ // read stdin: one pipe cannot feed both halves of a chained command.
45138
+ // `listen stop` returns while the state is still `stopping` (D-074), and
45139
+ // `listen start` refuses a listener that is stopping, so the two verbs
45140
+ // race unless the confirm step sits between them.
45141
+ `Read the failure codes in ${status.logPath}, then stop the listener with: cswarm listen stop --workspace-id ${status.workspaceId} --principal-id ${status.principalId}. Wait until it is no longer running -- state stopped or failed, not stopping -- confirming with: cswarm listen status --workspace-id ${status.workspaceId} --principal-id ${status.principalId}. Then restart it by piping the same agent credential into: ${listenerRestartCommand(status)}`
45142
+ )
45075
45143
  });
45076
45144
  }
45077
45145
  return notices;
@@ -45169,6 +45237,9 @@ function listenerStatusJson(status, permissionMode, evidence = {
45169
45237
  lastTerminalDeliveryFailureAt: status.lastTerminalDeliveryFailureAt ?? null,
45170
45238
  lastClaimAt: status.lastClaimAt ?? null,
45171
45239
  lastAckAt: status.lastAckAt ?? null,
45240
+ lastAckOutcome: status.lastAckOutcome ?? null,
45241
+ consecutiveAckFailureCount: status.consecutiveAckFailureCount ?? null,
45242
+ lastAckSignalId: status.lastAckSignalId ?? null,
45172
45243
  routeMode: status.routeMode ?? "worker",
45173
45244
  deferOverChars: status.deferOverChars ?? null,
45174
45245
  pendingForMainCount: status.pendingForMainCount ?? 0,
@@ -45194,6 +45265,7 @@ function renderListenerStatus(status, evidence = {
45194
45265
  hookSurfaceAdvanced: false
45195
45266
  }, nowMs = Date.now(), installed = null) {
45196
45267
  const routeMode = status.routeMode ?? "worker";
45268
+ const deliveryFailureRun = status.consecutiveAckFailureCount ?? 0;
45197
45269
  const pendingForMainCount = status.pendingForMainCount ?? 0;
45198
45270
  const droppedForMainCount = status.droppedForMainCount ?? 0;
45199
45271
  const unattendedCount = `${pendingForMainCount} ${pendingForMainCount === 1 ? "message is" : "messages are"} unattended`;
@@ -45205,7 +45277,7 @@ function renderListenerStatus(status, evidence = {
45205
45277
  lapseNotices.length > 0 ? `Listener LAPSE for agent ${status.principalId}: ${lapseNotices.map((notice) => notice.code).join(", ")}.` : pendingForMainCount > 0 ? `Listener WARNING for agent ${status.principalId}: ${unattendedCount}.` : `Listener ${status.state} for agent ${status.principalId}.`,
45206
45278
  `CONNECTED: ${attendance.connected ? "yes" : "no"}. Transport state is ${status.state}.`,
45207
45279
  `ATTENDED: ${attendance.attendanceState === "attended" ? "yes. The session hook has surfaced messages on this host" : attendance.attendanceState === "unattended" ? "no. The main-session queue is not draining" : attendance.attendanceState === "not_required" ? "not required for the worker route" : "not yet proven on this host"}.`,
45208
- `HANDLED: ${attendance.handledState === "handled" ? "yes. A delivery acknowledgement is recorded" : attendance.handledState === "not_handled" ? "no. Queued messages have not reached the session hook" : "not yet measured"}.`,
45280
+ `HANDLED: ${attendance.handledState === "handled" ? `yes. The newest delivery acknowledgement was ${status.lastAckOutcome}` : attendance.handledState === "not_handled" ? routeMode === "worker" ? deliveryFailureRun >= LISTENER_DELIVERY_FAILING_THRESHOLD ? `no. ${deliveryFailureRun} ${deliveryFailureRun === 1 ? "delivery has" : "deliveries have"} failed since the last reply; the newest delivery acknowledgement was ${status.lastAckOutcome ?? "not recorded"}${status.lastErrorCode ? ` (${status.lastErrorCode})` : ""}` : `no. The newest delivery acknowledgement was ${status.lastAckOutcome ?? "not recorded"}${status.lastErrorCode ? ` (${status.lastErrorCode})` : ""}` : "no. Queued messages have not reached the session hook" : "not yet measured"}.`,
45209
45281
  `Provider: ${status.provider}; process: ${status.pid}; started: ${status.startedAt}.`,
45210
45282
  `Provider executable: ${status.providerExecutable ?? "not measured"}.`,
45211
45283
  `Connections opened: ${status.connectionsOpened ?? "not measured"}.`,
@@ -45213,7 +45285,7 @@ function renderListenerStatus(status, evidence = {
45213
45285
  ...status.activityPublishFailures !== void 0 && status.activityPublishFailures > 0 ? [`Activity publish failures: ${status.activityPublishFailures}.`] : [],
45214
45286
  ...status.activityLastErrorCode ? [`Last activity publish error code: ${status.activityLastErrorCode}.`] : [],
45215
45287
  status.readyAt ? `Ready since: ${status.readyAt}.` : "Not ready yet.",
45216
- status.lastSignalId ? pendingForMainCount > 0 ? `Last claimed and queued signal: ${status.lastSignalId}. It is not handled yet.` : routeMode === "worker" ? `Last handled signal: ${status.lastSignalId}.` : `Last listener signal: ${status.lastSignalId}. Local status does not prove its final observed receipt.` : "No signal has been handled yet.",
45288
+ status.lastSignalId ? pendingForMainCount > 0 ? `Last claimed and queued signal: ${status.lastSignalId}. It is not handled yet.` : routeMode === "worker" ? status.lastAckAt === null ? `Last listener signal: ${status.lastSignalId}. No delivery acknowledgement is recorded.` : status.lastAckOutcome === null ? `Last listener signal: ${status.lastSignalId}. An acknowledgement was recorded at ${status.lastAckAt}; its outcome was not recorded.` : !status.lastAckSignalId ? `Last listener signal: ${status.lastSignalId}. The newest acknowledgement was ${status.lastAckOutcome}; which signal it belonged to was not recorded.` : status.lastAckOutcome === "failed_terminal" ? `Last failed delivery signal: ${status.lastAckSignalId}.` : DELIVERY_HANDLED_OUTCOMES.has(status.lastAckOutcome) && deliveryFailureRun < LISTENER_DELIVERY_FAILING_THRESHOLD ? `Last handled signal: ${status.lastAckSignalId}.` : `Last acknowledged signal: ${status.lastAckSignalId}. Its outcome was ${status.lastAckOutcome}.` : `Last listener signal: ${status.lastSignalId}. Local status does not prove its final observed receipt.` : "No signal has been handled yet.",
45217
45289
  status.lastErrorCode ? `Last status code: ${status.lastErrorCode}.` : "No listener process error is recorded.",
45218
45290
  readHealth.currentEpisodeStartedAt === null ? "Current read retry episode: none." : `Current read retry episode: ${readHealth.currentEpisodeAttempts} attempt${readHealth.currentEpisodeAttempts === 1 ? "" : "s"} since ${readHealth.currentEpisodeStartedAt}; reason ${readHealth.currentReasonCode}${readHealth.currentHttpStatus === null ? "" : ` (HTTP ${readHealth.currentHttpStatus})`}${readHealth.currentErrorConstructor === null ? "" : ` (${readHealth.currentErrorConstructor})`}.`,
45219
45291
  `Read retry episodes in the last 24h: ${readSummary.episodesLast24h}; retries in the rolling hour: ${readSummary.retriesLastHour}.`,
@@ -45319,7 +45391,7 @@ function renderListenerStatus(status, evidence = {
45319
45391
  }
45320
45392
  if (status.lastTerminalDeliveryFailureCount !== null && status.lastTerminalDeliveryFailureCount > 0) {
45321
45393
  lines.push(
45322
- `The last claim reported ${status.lastTerminalDeliveryFailureCount} terminal delivery failures; they remain recorded, and the listener will keep receiving.`
45394
+ `The last claim reported ${status.lastTerminalDeliveryFailureCount} ${status.lastTerminalDeliveryFailureCount === 1 ? "delivery the service gave up on because this listener never acknowledged it. It remains" : "deliveries the service gave up on because this listener never acknowledged them. They remain"} recorded, and the listener will keep receiving.`
45323
45395
  );
45324
45396
  }
45325
45397
  if (status.state === "stopping" || status.state === "starting") {