@sjawhar/pi-envoy 9.7.1 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/envoy.js CHANGED
@@ -168,11 +168,11 @@ var require_nuid = __commonJS((exports) => {
168
168
  var require_core = __commonJS((exports) => {
169
169
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
170
170
  function adopt(value) {
171
- return value instanceof P ? value : new P(function(resolve) {
172
- resolve(value);
171
+ return value instanceof P ? value : new P(function(resolve2) {
172
+ resolve2(value);
173
173
  });
174
174
  }
175
- return new (P || (P = Promise))(function(resolve, reject) {
175
+ return new (P || (P = Promise))(function(resolve2, reject) {
176
176
  function fulfilled(value) {
177
177
  try {
178
178
  step(generator.next(value));
@@ -188,7 +188,7 @@ var require_core = __commonJS((exports) => {
188
188
  }
189
189
  }
190
190
  function step(result) {
191
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
191
+ result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
192
192
  }
193
193
  step((generator = generator.apply(thisArg, _arguments || [])).next());
194
194
  });
@@ -391,11 +391,11 @@ var require_core = __commonJS((exports) => {
391
391
  var require_util = __commonJS((exports) => {
392
392
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
393
393
  function adopt(value) {
394
- return value instanceof P ? value : new P(function(resolve) {
395
- resolve(value);
394
+ return value instanceof P ? value : new P(function(resolve2) {
395
+ resolve2(value);
396
396
  });
397
397
  }
398
- return new (P || (P = Promise))(function(resolve, reject) {
398
+ return new (P || (P = Promise))(function(resolve2, reject) {
399
399
  function fulfilled(value) {
400
400
  try {
401
401
  step(generator.next(value));
@@ -411,7 +411,7 @@ var require_util = __commonJS((exports) => {
411
411
  }
412
412
  }
413
413
  function step(result) {
414
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
414
+ result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
415
415
  }
416
416
  step((generator = generator.apply(thisArg, _arguments || [])).next());
417
417
  });
@@ -425,14 +425,14 @@ var require_util = __commonJS((exports) => {
425
425
  }, i);
426
426
  function verb(n) {
427
427
  i[n] = o[n] && function(v) {
428
- return new Promise(function(resolve, reject) {
429
- v = o[n](v), settle(resolve, reject, v.done, v.value);
428
+ return new Promise(function(resolve2, reject) {
429
+ v = o[n](v), settle(resolve2, reject, v.done, v.value);
430
430
  });
431
431
  };
432
432
  }
433
- function settle(resolve, reject, d, v) {
433
+ function settle(resolve2, reject, d, v) {
434
434
  Promise.resolve(v).then(function(v2) {
435
- resolve({ value: v2, done: d });
435
+ resolve2({ value: v2, done: d });
436
436
  }, reject);
437
437
  }
438
438
  };
@@ -491,9 +491,9 @@ var require_util = __commonJS((exports) => {
491
491
  }
492
492
  function delay(ms = 0) {
493
493
  let methods;
494
- const p = new Promise((resolve) => {
494
+ const p = new Promise((resolve2) => {
495
495
  const timer = setTimeout(() => {
496
- resolve();
496
+ resolve2();
497
497
  }, ms);
498
498
  const cancel = () => {
499
499
  if (timer) {
@@ -512,18 +512,18 @@ var require_util = __commonJS((exports) => {
512
512
  }
513
513
  function deferred() {
514
514
  let methods = {};
515
- const p = new Promise((resolve, reject) => {
516
- methods = { resolve, reject };
515
+ const p = new Promise((resolve2, reject) => {
516
+ methods = { resolve: resolve2, reject };
517
517
  });
518
518
  return Object.assign(p, methods);
519
519
  }
520
520
  function debugDeferred() {
521
521
  let methods = {};
522
- const p = new Promise((resolve, reject) => {
522
+ const p = new Promise((resolve2, reject) => {
523
523
  methods = {
524
524
  resolve: (v) => {
525
525
  console.trace("resolve", v);
526
- resolve(v);
526
+ resolve2(v);
527
527
  },
528
528
  reject: (err) => {
529
529
  console.trace("reject");
@@ -1005,11 +1005,11 @@ var require_ipparser = __commonJS((exports) => {
1005
1005
  var require_servers = __commonJS((exports) => {
1006
1006
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
1007
1007
  function adopt(value) {
1008
- return value instanceof P ? value : new P(function(resolve) {
1009
- resolve(value);
1008
+ return value instanceof P ? value : new P(function(resolve2) {
1009
+ resolve2(value);
1010
1010
  });
1011
1011
  }
1012
- return new (P || (P = Promise))(function(resolve, reject) {
1012
+ return new (P || (P = Promise))(function(resolve2, reject) {
1013
1013
  function fulfilled(value) {
1014
1014
  try {
1015
1015
  step(generator.next(value));
@@ -1025,7 +1025,7 @@ var require_servers = __commonJS((exports) => {
1025
1025
  }
1026
1026
  }
1027
1027
  function step(result) {
1028
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
1028
+ result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
1029
1029
  }
1030
1030
  step((generator = generator.apply(thisArg, _arguments || [])).next());
1031
1031
  });
@@ -6434,11 +6434,11 @@ var require_options = __commonJS((exports) => {
6434
6434
  var require_protocol = __commonJS((exports) => {
6435
6435
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
6436
6436
  function adopt(value) {
6437
- return value instanceof P ? value : new P(function(resolve) {
6438
- resolve(value);
6437
+ return value instanceof P ? value : new P(function(resolve2) {
6438
+ resolve2(value);
6439
6439
  });
6440
6440
  }
6441
- return new (P || (P = Promise))(function(resolve, reject) {
6441
+ return new (P || (P = Promise))(function(resolve2, reject) {
6442
6442
  function fulfilled(value) {
6443
6443
  try {
6444
6444
  step(generator.next(value));
@@ -6454,7 +6454,7 @@ var require_protocol = __commonJS((exports) => {
6454
6454
  }
6455
6455
  }
6456
6456
  function step(result) {
6457
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
6457
+ result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
6458
6458
  }
6459
6459
  step((generator = generator.apply(thisArg, _arguments || [])).next());
6460
6460
  });
@@ -6468,14 +6468,14 @@ var require_protocol = __commonJS((exports) => {
6468
6468
  }, i);
6469
6469
  function verb(n) {
6470
6470
  i[n] = o[n] && function(v) {
6471
- return new Promise(function(resolve, reject) {
6472
- v = o[n](v), settle(resolve, reject, v.done, v.value);
6471
+ return new Promise(function(resolve2, reject) {
6472
+ v = o[n](v), settle(resolve2, reject, v.done, v.value);
6473
6473
  });
6474
6474
  };
6475
6475
  }
6476
- function settle(resolve, reject, d, v) {
6476
+ function settle(resolve2, reject, d, v) {
6477
6477
  Promise.resolve(v).then(function(v2) {
6478
- resolve({ value: v2, done: d });
6478
+ resolve2({ value: v2, done: d });
6479
6479
  }, reject);
6480
6480
  }
6481
6481
  };
@@ -6886,12 +6886,12 @@ var require_protocol = __commonJS((exports) => {
6886
6886
  }
6887
6887
  _doDial(srv) {
6888
6888
  return __awaiter(this, undefined, undefined, function* () {
6889
- const { resolve } = this.options;
6889
+ const { resolve: resolve2 } = this.options;
6890
6890
  const alts = yield srv.resolve({
6891
6891
  fn: (0, transport_1.getResolveFn)(),
6892
6892
  debug: this.options.debug,
6893
6893
  randomize: !this.options.noRandomize,
6894
- resolve
6894
+ resolve: resolve2
6895
6895
  });
6896
6896
  let lastErr = null;
6897
6897
  for (const a of alts) {
@@ -7639,11 +7639,11 @@ var require_jsutil = __commonJS((exports) => {
7639
7639
  var require_jsbaseclient_api = __commonJS((exports) => {
7640
7640
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
7641
7641
  function adopt(value) {
7642
- return value instanceof P ? value : new P(function(resolve) {
7643
- resolve(value);
7642
+ return value instanceof P ? value : new P(function(resolve2) {
7643
+ resolve2(value);
7644
7644
  });
7645
7645
  }
7646
- return new (P || (P = Promise))(function(resolve, reject) {
7646
+ return new (P || (P = Promise))(function(resolve2, reject) {
7647
7647
  function fulfilled(value) {
7648
7648
  try {
7649
7649
  step(generator.next(value));
@@ -7659,7 +7659,7 @@ var require_jsbaseclient_api = __commonJS((exports) => {
7659
7659
  }
7660
7660
  }
7661
7661
  function step(result) {
7662
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
7662
+ result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
7663
7663
  }
7664
7664
  step((generator = generator.apply(thisArg, _arguments || [])).next());
7665
7665
  });
@@ -7767,11 +7767,11 @@ var require_jsbaseclient_api = __commonJS((exports) => {
7767
7767
  var require_jslister = __commonJS((exports) => {
7768
7768
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
7769
7769
  function adopt(value) {
7770
- return value instanceof P ? value : new P(function(resolve) {
7771
- resolve(value);
7770
+ return value instanceof P ? value : new P(function(resolve2) {
7771
+ resolve2(value);
7772
7772
  });
7773
7773
  }
7774
- return new (P || (P = Promise))(function(resolve, reject) {
7774
+ return new (P || (P = Promise))(function(resolve2, reject) {
7775
7775
  function fulfilled(value) {
7776
7776
  try {
7777
7777
  step(generator.next(value));
@@ -7787,7 +7787,7 @@ var require_jslister = __commonJS((exports) => {
7787
7787
  }
7788
7788
  }
7789
7789
  function step(result) {
7790
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
7790
+ result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
7791
7791
  }
7792
7792
  step((generator = generator.apply(thisArg, _arguments || [])).next());
7793
7793
  });
@@ -8264,11 +8264,11 @@ var require_types2 = __commonJS((exports) => {
8264
8264
  var require_jsmconsumer_api = __commonJS((exports) => {
8265
8265
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
8266
8266
  function adopt(value) {
8267
- return value instanceof P ? value : new P(function(resolve) {
8268
- resolve(value);
8267
+ return value instanceof P ? value : new P(function(resolve2) {
8268
+ resolve2(value);
8269
8269
  });
8270
8270
  }
8271
- return new (P || (P = Promise))(function(resolve, reject) {
8271
+ return new (P || (P = Promise))(function(resolve2, reject) {
8272
8272
  function fulfilled(value) {
8273
8273
  try {
8274
8274
  step(generator.next(value));
@@ -8284,7 +8284,7 @@ var require_jsmconsumer_api = __commonJS((exports) => {
8284
8284
  }
8285
8285
  }
8286
8286
  function step(result) {
8287
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
8287
+ result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
8288
8288
  }
8289
8289
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8290
8290
  });
@@ -8533,11 +8533,11 @@ var require_mod2 = __commonJS((exports) => {
8533
8533
  var require_jsmsg = __commonJS((exports) => {
8534
8534
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
8535
8535
  function adopt(value) {
8536
- return value instanceof P ? value : new P(function(resolve) {
8537
- resolve(value);
8536
+ return value instanceof P ? value : new P(function(resolve2) {
8537
+ resolve2(value);
8538
8538
  });
8539
8539
  }
8540
- return new (P || (P = Promise))(function(resolve, reject) {
8540
+ return new (P || (P = Promise))(function(resolve2, reject) {
8541
8541
  function fulfilled(value) {
8542
8542
  try {
8543
8543
  step(generator.next(value));
@@ -8553,7 +8553,7 @@ var require_jsmsg = __commonJS((exports) => {
8553
8553
  }
8554
8554
  }
8555
8555
  function step(result) {
8556
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
8556
+ result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
8557
8557
  }
8558
8558
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8559
8559
  });
@@ -8726,11 +8726,11 @@ var require_jsmsg = __commonJS((exports) => {
8726
8726
  var require_typedsub = __commonJS((exports) => {
8727
8727
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
8728
8728
  function adopt(value) {
8729
- return value instanceof P ? value : new P(function(resolve) {
8730
- resolve(value);
8729
+ return value instanceof P ? value : new P(function(resolve2) {
8730
+ resolve2(value);
8731
8731
  });
8732
8732
  }
8733
- return new (P || (P = Promise))(function(resolve, reject) {
8733
+ return new (P || (P = Promise))(function(resolve2, reject) {
8734
8734
  function fulfilled(value) {
8735
8735
  try {
8736
8736
  step(generator.next(value));
@@ -8746,7 +8746,7 @@ var require_typedsub = __commonJS((exports) => {
8746
8746
  }
8747
8747
  }
8748
8748
  function step(result) {
8749
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
8749
+ result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
8750
8750
  }
8751
8751
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8752
8752
  });
@@ -9469,11 +9469,11 @@ var require_sha_digest_parser = __commonJS((exports) => {
9469
9469
  var require_objectstore = __commonJS((exports) => {
9470
9470
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
9471
9471
  function adopt(value) {
9472
- return value instanceof P ? value : new P(function(resolve) {
9473
- resolve(value);
9472
+ return value instanceof P ? value : new P(function(resolve2) {
9473
+ resolve2(value);
9474
9474
  });
9475
9475
  }
9476
- return new (P || (P = Promise))(function(resolve, reject) {
9476
+ return new (P || (P = Promise))(function(resolve2, reject) {
9477
9477
  function fulfilled(value) {
9478
9478
  try {
9479
9479
  step(generator.next(value));
@@ -9489,7 +9489,7 @@ var require_objectstore = __commonJS((exports) => {
9489
9489
  }
9490
9490
  }
9491
9491
  function step(result) {
9492
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
9492
+ result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
9493
9493
  }
9494
9494
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9495
9495
  });
@@ -9503,14 +9503,14 @@ var require_objectstore = __commonJS((exports) => {
9503
9503
  }, i);
9504
9504
  function verb(n) {
9505
9505
  i[n] = o[n] && function(v) {
9506
- return new Promise(function(resolve, reject) {
9507
- v = o[n](v), settle(resolve, reject, v.done, v.value);
9506
+ return new Promise(function(resolve2, reject) {
9507
+ v = o[n](v), settle(resolve2, reject, v.done, v.value);
9508
9508
  });
9509
9509
  };
9510
9510
  }
9511
- function settle(resolve, reject, d, v) {
9511
+ function settle(resolve2, reject, d, v) {
9512
9512
  Promise.resolve(v).then(function(v2) {
9513
- resolve({ value: v2, done: d });
9513
+ resolve2({ value: v2, done: d });
9514
9514
  }, reject);
9515
9515
  }
9516
9516
  };
@@ -10277,11 +10277,11 @@ var require_idleheartbeat_monitor = __commonJS((exports) => {
10277
10277
  var require_jsclient = __commonJS((exports) => {
10278
10278
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
10279
10279
  function adopt(value) {
10280
- return value instanceof P ? value : new P(function(resolve) {
10281
- resolve(value);
10280
+ return value instanceof P ? value : new P(function(resolve2) {
10281
+ resolve2(value);
10282
10282
  });
10283
10283
  }
10284
- return new (P || (P = Promise))(function(resolve, reject) {
10284
+ return new (P || (P = Promise))(function(resolve2, reject) {
10285
10285
  function fulfilled(value) {
10286
10286
  try {
10287
10287
  step(generator.next(value));
@@ -10297,7 +10297,7 @@ var require_jsclient = __commonJS((exports) => {
10297
10297
  }
10298
10298
  }
10299
10299
  function step(result) {
10300
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
10300
+ result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
10301
10301
  }
10302
10302
  step((generator = generator.apply(thisArg, _arguments || [])).next());
10303
10303
  });
@@ -11021,11 +11021,11 @@ var require_jsclient = __commonJS((exports) => {
11021
11021
  var require_kv = __commonJS((exports) => {
11022
11022
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
11023
11023
  function adopt(value) {
11024
- return value instanceof P ? value : new P(function(resolve) {
11025
- resolve(value);
11024
+ return value instanceof P ? value : new P(function(resolve2) {
11025
+ resolve2(value);
11026
11026
  });
11027
11027
  }
11028
- return new (P || (P = Promise))(function(resolve, reject) {
11028
+ return new (P || (P = Promise))(function(resolve2, reject) {
11029
11029
  function fulfilled(value) {
11030
11030
  try {
11031
11031
  step(generator.next(value));
@@ -11041,7 +11041,7 @@ var require_kv = __commonJS((exports) => {
11041
11041
  }
11042
11042
  }
11043
11043
  function step(result) {
11044
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
11044
+ result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
11045
11045
  }
11046
11046
  step((generator = generator.apply(thisArg, _arguments || [])).next());
11047
11047
  });
@@ -11055,14 +11055,14 @@ var require_kv = __commonJS((exports) => {
11055
11055
  }, i);
11056
11056
  function verb(n) {
11057
11057
  i[n] = o[n] && function(v) {
11058
- return new Promise(function(resolve, reject) {
11059
- v = o[n](v), settle(resolve, reject, v.done, v.value);
11058
+ return new Promise(function(resolve2, reject) {
11059
+ v = o[n](v), settle(resolve2, reject, v.done, v.value);
11060
11060
  });
11061
11061
  };
11062
11062
  }
11063
- function settle(resolve, reject, d, v) {
11063
+ function settle(resolve2, reject, d, v) {
11064
11064
  Promise.resolve(v).then(function(v2) {
11065
- resolve({ value: v2, done: d });
11065
+ resolve2({ value: v2, done: d });
11066
11066
  }, reject);
11067
11067
  }
11068
11068
  };
@@ -12003,11 +12003,11 @@ var require_kv = __commonJS((exports) => {
12003
12003
  var require_consumer = __commonJS((exports) => {
12004
12004
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
12005
12005
  function adopt(value) {
12006
- return value instanceof P ? value : new P(function(resolve) {
12007
- resolve(value);
12006
+ return value instanceof P ? value : new P(function(resolve2) {
12007
+ resolve2(value);
12008
12008
  });
12009
12009
  }
12010
- return new (P || (P = Promise))(function(resolve, reject) {
12010
+ return new (P || (P = Promise))(function(resolve2, reject) {
12011
12011
  function fulfilled(value) {
12012
12012
  try {
12013
12013
  step(generator.next(value));
@@ -12023,7 +12023,7 @@ var require_consumer = __commonJS((exports) => {
12023
12023
  }
12024
12024
  }
12025
12025
  function step(result) {
12026
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
12026
+ result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
12027
12027
  }
12028
12028
  step((generator = generator.apply(thisArg, _arguments || [])).next());
12029
12029
  });
@@ -12037,14 +12037,14 @@ var require_consumer = __commonJS((exports) => {
12037
12037
  }, i);
12038
12038
  function verb(n) {
12039
12039
  i[n] = o[n] && function(v) {
12040
- return new Promise(function(resolve, reject) {
12041
- v = o[n](v), settle(resolve, reject, v.done, v.value);
12040
+ return new Promise(function(resolve2, reject) {
12041
+ v = o[n](v), settle(resolve2, reject, v.done, v.value);
12042
12042
  });
12043
12043
  };
12044
12044
  }
12045
- function settle(resolve, reject, d, v) {
12045
+ function settle(resolve2, reject, d, v) {
12046
12046
  Promise.resolve(v).then(function(v2) {
12047
- resolve({ value: v2, done: d });
12047
+ resolve2({ value: v2, done: d });
12048
12048
  }, reject);
12049
12049
  }
12050
12050
  };
@@ -12896,11 +12896,11 @@ var require_consumer = __commonJS((exports) => {
12896
12896
  var require_jsmstream_api = __commonJS((exports) => {
12897
12897
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
12898
12898
  function adopt(value) {
12899
- return value instanceof P ? value : new P(function(resolve) {
12900
- resolve(value);
12899
+ return value instanceof P ? value : new P(function(resolve2) {
12900
+ resolve2(value);
12901
12901
  });
12902
12902
  }
12903
- return new (P || (P = Promise))(function(resolve, reject) {
12903
+ return new (P || (P = Promise))(function(resolve2, reject) {
12904
12904
  function fulfilled(value) {
12905
12905
  try {
12906
12906
  step(generator.next(value));
@@ -12916,7 +12916,7 @@ var require_jsmstream_api = __commonJS((exports) => {
12916
12916
  }
12917
12917
  }
12918
12918
  function step(result) {
12919
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
12919
+ result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
12920
12920
  }
12921
12921
  step((generator = generator.apply(thisArg, _arguments || [])).next());
12922
12922
  });
@@ -13367,11 +13367,11 @@ var require_jsmstream_api = __commonJS((exports) => {
13367
13367
  var require_jsm = __commonJS((exports) => {
13368
13368
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
13369
13369
  function adopt(value) {
13370
- return value instanceof P ? value : new P(function(resolve) {
13371
- resolve(value);
13370
+ return value instanceof P ? value : new P(function(resolve2) {
13371
+ resolve2(value);
13372
13372
  });
13373
13373
  }
13374
- return new (P || (P = Promise))(function(resolve, reject) {
13374
+ return new (P || (P = Promise))(function(resolve2, reject) {
13375
13375
  function fulfilled(value) {
13376
13376
  try {
13377
13377
  step(generator.next(value));
@@ -13387,7 +13387,7 @@ var require_jsm = __commonJS((exports) => {
13387
13387
  }
13388
13388
  }
13389
13389
  function step(result) {
13390
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
13390
+ result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
13391
13391
  }
13392
13392
  step((generator = generator.apply(thisArg, _arguments || [])).next());
13393
13393
  });
@@ -13401,14 +13401,14 @@ var require_jsm = __commonJS((exports) => {
13401
13401
  }, i);
13402
13402
  function verb(n) {
13403
13403
  i[n] = o[n] && function(v) {
13404
- return new Promise(function(resolve, reject) {
13405
- v = o[n](v), settle(resolve, reject, v.done, v.value);
13404
+ return new Promise(function(resolve2, reject) {
13405
+ v = o[n](v), settle(resolve2, reject, v.done, v.value);
13406
13406
  });
13407
13407
  };
13408
13408
  }
13409
- function settle(resolve, reject, d, v) {
13409
+ function settle(resolve2, reject, d, v) {
13410
13410
  Promise.resolve(v).then(function(v2) {
13411
- resolve({ value: v2, done: d });
13411
+ resolve2({ value: v2, done: d });
13412
13412
  }, reject);
13413
13413
  }
13414
13414
  };
@@ -13598,11 +13598,11 @@ var require_jsm = __commonJS((exports) => {
13598
13598
  var require_service = __commonJS((exports) => {
13599
13599
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
13600
13600
  function adopt(value) {
13601
- return value instanceof P ? value : new P(function(resolve) {
13602
- resolve(value);
13601
+ return value instanceof P ? value : new P(function(resolve2) {
13602
+ resolve2(value);
13603
13603
  });
13604
13604
  }
13605
- return new (P || (P = Promise))(function(resolve, reject) {
13605
+ return new (P || (P = Promise))(function(resolve2, reject) {
13606
13606
  function fulfilled(value) {
13607
13607
  try {
13608
13608
  step(generator.next(value));
@@ -13618,7 +13618,7 @@ var require_service = __commonJS((exports) => {
13618
13618
  }
13619
13619
  }
13620
13620
  function step(result) {
13621
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
13621
+ result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
13622
13622
  }
13623
13623
  step((generator = generator.apply(thisArg, _arguments || [])).next());
13624
13624
  });
@@ -14086,11 +14086,11 @@ var require_service = __commonJS((exports) => {
14086
14086
  var require_serviceclient = __commonJS((exports) => {
14087
14087
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
14088
14088
  function adopt(value) {
14089
- return value instanceof P ? value : new P(function(resolve) {
14090
- resolve(value);
14089
+ return value instanceof P ? value : new P(function(resolve2) {
14090
+ resolve2(value);
14091
14091
  });
14092
14092
  }
14093
- return new (P || (P = Promise))(function(resolve, reject) {
14093
+ return new (P || (P = Promise))(function(resolve2, reject) {
14094
14094
  function fulfilled(value) {
14095
14095
  try {
14096
14096
  step(generator.next(value));
@@ -14106,7 +14106,7 @@ var require_serviceclient = __commonJS((exports) => {
14106
14106
  }
14107
14107
  }
14108
14108
  function step(result) {
14109
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
14109
+ result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
14110
14110
  }
14111
14111
  step((generator = generator.apply(thisArg, _arguments || [])).next());
14112
14112
  });
@@ -14120,14 +14120,14 @@ var require_serviceclient = __commonJS((exports) => {
14120
14120
  }, i);
14121
14121
  function verb(n) {
14122
14122
  i[n] = o[n] && function(v) {
14123
- return new Promise(function(resolve, reject) {
14124
- v = o[n](v), settle(resolve, reject, v.done, v.value);
14123
+ return new Promise(function(resolve2, reject) {
14124
+ v = o[n](v), settle(resolve2, reject, v.done, v.value);
14125
14125
  });
14126
14126
  };
14127
14127
  }
14128
- function settle(resolve, reject, d, v) {
14128
+ function settle(resolve2, reject, d, v) {
14129
14129
  Promise.resolve(v).then(function(v2) {
14130
- resolve({ value: v2, done: d });
14130
+ resolve2({ value: v2, done: d });
14131
14131
  }, reject);
14132
14132
  }
14133
14133
  };
@@ -14208,11 +14208,11 @@ var require_serviceclient = __commonJS((exports) => {
14208
14208
  var require_nats = __commonJS((exports) => {
14209
14209
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
14210
14210
  function adopt(value) {
14211
- return value instanceof P ? value : new P(function(resolve) {
14212
- resolve(value);
14211
+ return value instanceof P ? value : new P(function(resolve2) {
14212
+ resolve2(value);
14213
14213
  });
14214
14214
  }
14215
- return new (P || (P = Promise))(function(resolve, reject) {
14215
+ return new (P || (P = Promise))(function(resolve2, reject) {
14216
14216
  function fulfilled(value) {
14217
14217
  try {
14218
14218
  step(generator.next(value));
@@ -14228,7 +14228,7 @@ var require_nats = __commonJS((exports) => {
14228
14228
  }
14229
14229
  }
14230
14230
  function step(result) {
14231
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
14231
+ result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
14232
14232
  }
14233
14233
  step((generator = generator.apply(thisArg, _arguments || [])).next());
14234
14234
  });
@@ -14242,14 +14242,14 @@ var require_nats = __commonJS((exports) => {
14242
14242
  }, i);
14243
14243
  function verb(n) {
14244
14244
  i[n] = o[n] && function(v) {
14245
- return new Promise(function(resolve, reject) {
14246
- v = o[n](v), settle(resolve, reject, v.done, v.value);
14245
+ return new Promise(function(resolve2, reject) {
14246
+ v = o[n](v), settle(resolve2, reject, v.done, v.value);
14247
14247
  });
14248
14248
  };
14249
14249
  }
14250
- function settle(resolve, reject, d, v) {
14250
+ function settle(resolve2, reject, d, v) {
14251
14251
  Promise.resolve(v).then(function(v2) {
14252
- resolve({ value: v2, done: d });
14252
+ resolve2({ value: v2, done: d });
14253
14253
  }, reject);
14254
14254
  }
14255
14255
  };
@@ -14277,7 +14277,7 @@ var require_nats = __commonJS((exports) => {
14277
14277
  this.listeners = [];
14278
14278
  }
14279
14279
  static connect(opts = {}) {
14280
- return new Promise((resolve, reject) => {
14280
+ return new Promise((resolve2, reject) => {
14281
14281
  const nc = new NatsConnectionImpl(opts);
14282
14282
  protocol_1.ProtocolHandler.connect(nc.options, nc).then((ph) => {
14283
14283
  nc.protocol = ph;
@@ -14306,7 +14306,7 @@ var require_nats = __commonJS((exports) => {
14306
14306
  }
14307
14307
  });
14308
14308
  })();
14309
- resolve(nc);
14309
+ resolve2(nc);
14310
14310
  }).catch((err) => {
14311
14311
  reject(err);
14312
14312
  });
@@ -14697,11 +14697,11 @@ ${errCtx.stack}`;
14697
14697
  var require_bench = __commonJS((exports) => {
14698
14698
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
14699
14699
  function adopt(value) {
14700
- return value instanceof P ? value : new P(function(resolve) {
14701
- resolve(value);
14700
+ return value instanceof P ? value : new P(function(resolve2) {
14701
+ resolve2(value);
14702
14702
  });
14703
14703
  }
14704
- return new (P || (P = Promise))(function(resolve, reject) {
14704
+ return new (P || (P = Promise))(function(resolve2, reject) {
14705
14705
  function fulfilled(value) {
14706
14706
  try {
14707
14707
  step(generator.next(value));
@@ -14717,7 +14717,7 @@ var require_bench = __commonJS((exports) => {
14717
14717
  }
14718
14718
  }
14719
14719
  function step(result) {
14720
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
14720
+ result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
14721
14721
  }
14722
14722
  step((generator = generator.apply(thisArg, _arguments || [])).next());
14723
14723
  });
@@ -14731,14 +14731,14 @@ var require_bench = __commonJS((exports) => {
14731
14731
  }, i);
14732
14732
  function verb(n) {
14733
14733
  i[n] = o[n] && function(v) {
14734
- return new Promise(function(resolve, reject) {
14735
- v = o[n](v), settle(resolve, reject, v.done, v.value);
14734
+ return new Promise(function(resolve2, reject) {
14735
+ v = o[n](v), settle(resolve2, reject, v.done, v.value);
14736
14736
  });
14737
14737
  };
14738
14738
  }
14739
- function settle(resolve, reject, d, v) {
14739
+ function settle(resolve2, reject, d, v) {
14740
14740
  Promise.resolve(v).then(function(v2) {
14741
- resolve({ value: v2, done: d });
14741
+ resolve2({ value: v2, done: d });
14742
14742
  }, reject);
14743
14743
  }
14744
14744
  };
@@ -15489,11 +15489,11 @@ var require_nats_base_client = __commonJS((exports) => {
15489
15489
  var require_node_transport = __commonJS((exports) => {
15490
15490
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
15491
15491
  function adopt(value) {
15492
- return value instanceof P ? value : new P(function(resolve2) {
15493
- resolve2(value);
15492
+ return value instanceof P ? value : new P(function(resolve3) {
15493
+ resolve3(value);
15494
15494
  });
15495
15495
  }
15496
- return new (P || (P = Promise))(function(resolve2, reject) {
15496
+ return new (P || (P = Promise))(function(resolve3, reject) {
15497
15497
  function fulfilled(value) {
15498
15498
  try {
15499
15499
  step(generator.next(value));
@@ -15509,7 +15509,7 @@ var require_node_transport = __commonJS((exports) => {
15509
15509
  }
15510
15510
  }
15511
15511
  function step(result) {
15512
- result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
15512
+ result.done ? resolve3(result.value) : adopt(result.value).then(fulfilled, rejected);
15513
15513
  }
15514
15514
  step((generator = generator.apply(thisArg, _arguments || [])).next());
15515
15515
  });
@@ -15568,8 +15568,8 @@ var require_node_transport = __commonJS((exports) => {
15568
15568
  var net_1 = __require("net");
15569
15569
  var util_1 = require_util();
15570
15570
  var tls_1 = __require("tls");
15571
- var { resolve } = __require("path");
15572
- var { readFile, existsSync } = __require("fs");
15571
+ var { resolve: resolve2 } = __require("path");
15572
+ var { readFile, existsSync: existsSync2 } = __require("fs");
15573
15573
  var dns = __require("dns");
15574
15574
  var VERSION = "2.29.3";
15575
15575
  var LANG = "nats.js";
@@ -15684,8 +15684,8 @@ var require_node_transport = __commonJS((exports) => {
15684
15684
  }
15685
15685
  const d = (0, nats_base_client_1.deferred)();
15686
15686
  try {
15687
- fn = resolve(fn);
15688
- if (!existsSync(fn)) {
15687
+ fn = resolve2(fn);
15688
+ if (!existsSync2(fn)) {
15689
15689
  d.reject(new Error(`${fn} doesn't exist`));
15690
15690
  }
15691
15691
  readFile(fn, (err, data) => {
@@ -16110,8 +16110,8 @@ var require_mod4 = __commonJS((exports) => {
16110
16110
  });
16111
16111
 
16112
16112
  // extensions/envoy.ts
16113
- import { existsSync } from "fs";
16114
- import { delimiter, dirname, resolve } from "path";
16113
+ import { existsSync as existsSync2 } from "fs";
16114
+ import { delimiter, dirname as dirname2, resolve as resolve2 } from "path";
16115
16115
  import { fileURLToPath } from "url";
16116
16116
 
16117
16117
  // ../../node_modules/.bun/zod@4.3.6/node_modules/zod/v4/classic/external.js
@@ -30518,24 +30518,6 @@ function zodSchemaApi(zod) {
30518
30518
  }
30519
30519
  };
30520
30520
  }
30521
- // ../envoy-client/src/defaults.ts
30522
- var DEFAULT_ENVOY_URL = "http://127.0.0.1:9020";
30523
- var DEFAULT_HEARTBEAT_MS = 120000;
30524
- var MIN_HEARTBEAT_MS = 25;
30525
- function envoyDefaultsFromEnvironment(environment) {
30526
- const rawHeartbeatMs = Number(environment["ENVOY_HEARTBEAT_MS"]);
30527
- const heartbeatMs = Number.isFinite(rawHeartbeatMs) && rawHeartbeatMs > 0 ? Math.max(rawHeartbeatMs, MIN_HEARTBEAT_MS) : DEFAULT_HEARTBEAT_MS;
30528
- const natsUrls = environment["ENVOY_NATS_URL"]?.split(",").map((url2) => url2.trim()).filter((url2) => url2.length > 0) ?? [];
30529
- return {
30530
- envoyUrl: normalizeEnvoyUrl(environment["ENVOY_URL"] ?? DEFAULT_ENVOY_URL),
30531
- natsUrls,
30532
- heartbeatMs
30533
- };
30534
- }
30535
- function normalizeEnvoyUrl(value) {
30536
- return value.replace(/\/+$/, "");
30537
- }
30538
-
30539
30521
  // ../../node_modules/.bun/@toon-format+toon@4.1.1/node_modules/@toon-format/toon/dist/index.mjs
30540
30522
  var NULL_LITERAL = "null";
30541
30523
  var DELIMITERS = {
@@ -32064,13 +32046,113 @@ function renderInbound(raw, sessionID, subject2) {
32064
32046
  };
32065
32047
  }
32066
32048
 
32067
- // ../envoy-client/src/dispatch-config.ts
32068
- import { readFileSync as readFileSync2 } from "fs";
32069
- import { homedir } from "os";
32049
+ // ../envoy-client/src/envoy-config.ts
32050
+ import {
32051
+ chmodSync,
32052
+ closeSync,
32053
+ existsSync,
32054
+ lstatSync,
32055
+ mkdtempSync,
32056
+ openSync,
32057
+ readFileSync as readFileSync2,
32058
+ readlinkSync,
32059
+ rmSync,
32060
+ statSync
32061
+ } from "fs";
32062
+ import { homedir, tmpdir } from "os";
32070
32063
  import * as path from "path";
32071
32064
 
32065
+ // ../envoy-client/src/json-position.ts
32066
+ function jsonErrorPosition(text) {
32067
+ let at = 0;
32068
+ const fail = () => {
32069
+ throw new RangeError("not JSON");
32070
+ };
32071
+ const space = () => {
32072
+ while (at < text.length && `
32073
+ \r`.includes(text.charAt(at)))
32074
+ at += 1;
32075
+ };
32076
+ const expect = (char) => {
32077
+ if (text.charAt(at) !== char)
32078
+ fail();
32079
+ at += 1;
32080
+ };
32081
+ const string4 = () => {
32082
+ expect('"');
32083
+ while (at < text.length) {
32084
+ const char = text.charAt(at);
32085
+ if (char === '"') {
32086
+ at += 1;
32087
+ return;
32088
+ }
32089
+ if (char < " ")
32090
+ fail();
32091
+ at += char === "\\" ? 2 : 1;
32092
+ }
32093
+ fail();
32094
+ };
32095
+ const value = () => {
32096
+ space();
32097
+ const char = text.charAt(at);
32098
+ if (char === "{" || char === "[") {
32099
+ const close = char === "{" ? "}" : "]";
32100
+ at += 1;
32101
+ space();
32102
+ if (text.charAt(at) === close) {
32103
+ at += 1;
32104
+ return;
32105
+ }
32106
+ for (;; ) {
32107
+ if (close === "}") {
32108
+ space();
32109
+ string4();
32110
+ space();
32111
+ expect(":");
32112
+ }
32113
+ value();
32114
+ space();
32115
+ if (text.charAt(at) === ",") {
32116
+ at += 1;
32117
+ continue;
32118
+ }
32119
+ expect(close);
32120
+ return;
32121
+ }
32122
+ }
32123
+ if (char === '"') {
32124
+ string4();
32125
+ return;
32126
+ }
32127
+ for (const word of ["true", "false", "null"]) {
32128
+ if (text.startsWith(word, at)) {
32129
+ at += word.length;
32130
+ return;
32131
+ }
32132
+ }
32133
+ const number4 = /^-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?/.exec(text.slice(at));
32134
+ if (number4 === null)
32135
+ fail();
32136
+ at += number4?.[0].length ?? 0;
32137
+ };
32138
+ try {
32139
+ value();
32140
+ space();
32141
+ if (at < text.length)
32142
+ fail();
32143
+ return;
32144
+ } catch {
32145
+ const before = text.slice(0, at).split(`
32146
+ `);
32147
+ return `line ${before.length}, column ${(before.at(-1)?.length ?? 0) + 1}`;
32148
+ }
32149
+ }
32150
+
32072
32151
  // ../envoy-client/src/secret-file.ts
32073
32152
  import { readFileSync } from "fs";
32153
+ function sendable(value) {
32154
+ return !/[\s\p{Cc}]/u.test(value);
32155
+ }
32074
32156
  function readSecretFile(variable, filePath) {
32075
32157
  let contents;
32076
32158
  try {
@@ -32081,131 +32163,431 @@ function readSecretFile(variable, filePath) {
32081
32163
  const value = contents.trim();
32082
32164
  if (value.length === 0)
32083
32165
  throw new Error(`${variable} names ${filePath}, which is empty`);
32166
+ if (!sendable(value)) {
32167
+ throw new Error(`${variable} names ${filePath}, which holds whitespace or a control character`);
32168
+ }
32084
32169
  return value;
32085
32170
  }
32086
32171
 
32087
- // ../envoy-client/src/dispatch-config.ts
32088
- var DEFAULT_SERVER_URL = "http://localhost:8766";
32089
- function normalizeDispatchUrl(url2) {
32090
- return url2.replace(/\/+$/, "");
32172
+ // ../envoy-client/src/envoy-config.ts
32173
+ var COMMAND_TIMEOUT_MS = 1e4;
32174
+ function nonEmpty(value) {
32175
+ return value === undefined || value === "" ? undefined : value;
32091
32176
  }
32092
- function parsedDispatchUrl(value, source) {
32093
- const url2 = normalizeDispatchUrl(value);
32094
- try {
32095
- new URL(url2);
32096
- return { url: url2, error: null };
32097
- } catch {
32098
- return { url: null, error: `${source} must be a valid URL` };
32177
+ function absolute(name, value) {
32178
+ if (value !== undefined && !path.isAbsolute(value)) {
32179
+ throw new Error(`${name} is ${value}, which is not an absolute path`);
32180
+ }
32181
+ return value;
32182
+ }
32183
+ function neutralConfig(env) {
32184
+ const xdgConfigHome = nonEmpty(env.XDG_CONFIG_HOME);
32185
+ if (xdgConfigHome !== undefined && !path.isAbsolute(xdgConfigHome)) {
32186
+ return { error: `XDG_CONFIG_HOME is ${xdgConfigHome}, which is not an absolute path` };
32187
+ }
32188
+ const configHome = xdgConfigHome ?? path.join(nonEmpty(env.HOME) ?? homedir(), ".config");
32189
+ return { path: path.resolve(configHome, "legion", "envoy.json") };
32190
+ }
32191
+ var HARNESS_DIRECTORY_VARIABLE = {
32192
+ omp: "PI_CODING_AGENT_DIR",
32193
+ claude: "CLAUDE_CONFIG_DIR",
32194
+ opencode: "OPENCODE_CONFIG_DIR"
32195
+ };
32196
+ var PLUGIN_HARNESSES = Object.keys(HARNESS_DIRECTORY_VARIABLE);
32197
+ function namedDirectory(harness, env) {
32198
+ if (harness === "omp") {
32199
+ const profile = nonEmpty(env.OMP_PROFILE);
32200
+ if (profile === undefined || profile === "default")
32201
+ return;
32099
32202
  }
32203
+ return nonEmpty(env[HARNESS_DIRECTORY_VARIABLE[harness]]);
32100
32204
  }
32205
+ function harnessDirectory(harness, env) {
32206
+ for (const plugin of harness === "command" ? PLUGIN_HARNESSES : [harness]) {
32207
+ if (harness === "command" && plugin === "claude" && env.CLAUDE_CODE_CHILD_SESSION !== "1") {
32208
+ continue;
32209
+ }
32210
+ const directory = namedDirectory(plugin, env);
32211
+ if (directory !== undefined)
32212
+ return absolute(HARNESS_DIRECTORY_VARIABLE[plugin], directory);
32213
+ }
32214
+ return;
32215
+ }
32216
+ function handedConfigPath(env) {
32217
+ const handed = nonEmpty(env.ENVOY_CONFIG_FILE);
32218
+ return handed === undefined ? undefined : path.resolve(absolute("ENVOY_CONFIG_FILE", handed));
32219
+ }
32220
+ function envoyConfigPath(harness, env) {
32221
+ const handedFirst = harness === "command" ? handedConfigPath(env) : undefined;
32222
+ if (handedFirst !== undefined)
32223
+ return handedFirst;
32224
+ const directory = harnessDirectory(harness, env);
32225
+ if (directory !== undefined)
32226
+ return path.resolve(directory, "envoy.json");
32227
+ const handed = handedConfigPath(env);
32228
+ if (handed !== undefined)
32229
+ return handed;
32230
+ const neutral = neutralConfig(env);
32231
+ if ("error" in neutral)
32232
+ throw new Error(neutral.error);
32233
+ return neutral.path;
32234
+ }
32235
+ var httpUrlSchema = exports_external.url({ protocol: /^https?$/, error: "must be an http or https URL" });
32236
+ var DispatchSectionSchema = exports_external.strictObject({
32237
+ enabled: exports_external.boolean().optional(),
32238
+ serverUrl: httpUrlSchema.optional(),
32239
+ token: exports_external.string().optional()
32240
+ });
32241
+ var EnvoySectionSchema = exports_external.strictObject({
32242
+ enabled: exports_external.boolean().optional(),
32243
+ url: httpUrlSchema.optional(),
32244
+ natsUrls: exports_external.array(exports_external.string().trim().min(1, "must not be empty")).optional(),
32245
+ token: exports_external.string().optional(),
32246
+ natsSeed: exports_external.string().optional()
32247
+ });
32101
32248
  var EnvoyFileSchema = exports_external.looseObject({
32102
32249
  $schema: exports_external.string().optional(),
32103
- natsUrls: exports_external.array(exports_external.string()).optional(),
32104
- dispatch: exports_external.strictObject({
32105
- enabled: exports_external.boolean().optional(),
32106
- serverUrl: exports_external.url().optional(),
32107
- token: exports_external.string().optional()
32108
- }).optional()
32250
+ dispatch: DispatchSectionSchema.optional(),
32251
+ envoy: EnvoySectionSchema.optional()
32252
+ });
32253
+ var CheckoutFileSchema = exports_external.looseObject({
32254
+ $schema: exports_external.string().optional(),
32255
+ dispatch: DispatchSectionSchema.optional()
32109
32256
  });
32257
+ function offWithNotice(notice) {
32258
+ return { enabled: false, notice, error: null };
32259
+ }
32260
+ function offWithError(error48) {
32261
+ return { enabled: false, notice: null, error: error48 };
32262
+ }
32263
+ function httpUrl2(value) {
32264
+ let url2;
32265
+ try {
32266
+ url2 = new URL(value);
32267
+ } catch {
32268
+ return;
32269
+ }
32270
+ return url2.protocol === "http:" || url2.protocol === "https:" ? url2 : undefined;
32271
+ }
32110
32272
  function describeSchemaIssue(filePath, error48) {
32111
32273
  const issue2 = error48.issues[0];
32112
32274
  if (!issue2)
32113
- return `${filePath}: invalid dispatch config`;
32275
+ return `${filePath}: invalid envoy.json`;
32114
32276
  if (issue2.code === "unrecognized_keys") {
32115
- const keys = issue2.keys.map((key) => `dispatch.${key}`).join(", ");
32116
- return `${filePath}: unrecognized dispatch key(s): ${keys}`;
32277
+ const section = issue2.path.join(".");
32278
+ const keys = issue2.keys.map((key) => `${section}.${key}`).join(", ");
32279
+ return `${filePath}: unrecognized ${section} key(s): ${keys}`;
32117
32280
  }
32118
32281
  return `${filePath}: ${issue2.path.join(".")}: ${issue2.message}`;
32119
32282
  }
32120
- function readEnvoyFile(filePath) {
32283
+ function danglingLink(filePath) {
32284
+ try {
32285
+ return lstatSync(filePath).isSymbolicLink() ? readlinkSync(filePath) : null;
32286
+ } catch {
32287
+ return null;
32288
+ }
32289
+ }
32290
+ function parseFile(filePath, schema, checkout) {
32121
32291
  let raw;
32122
32292
  try {
32123
32293
  raw = readFileSync2(filePath, "utf-8");
32124
- } catch {
32125
- return { kind: "absent" };
32294
+ } catch (error48) {
32295
+ if (hasErrnoCode(error48, "ENOENT") || hasErrnoCode(error48, "ENOTDIR")) {
32296
+ return { kind: "absent", link: danglingLink(filePath) };
32297
+ }
32298
+ return { kind: "invalid", reason: `${filePath}: could not be read (${messageFor(error48)})` };
32126
32299
  }
32127
32300
  let parsedJson;
32128
32301
  try {
32129
32302
  parsedJson = JSON.parse(raw);
32130
- } catch (err) {
32131
- return { kind: "invalid", reason: `${filePath}: invalid JSON (${messageFor(err)})` };
32303
+ } catch {
32304
+ const position = jsonErrorPosition(raw);
32305
+ return {
32306
+ kind: "invalid",
32307
+ reason: `${filePath}: invalid JSON${position === undefined ? "" : ` at ${position}`}`
32308
+ };
32132
32309
  }
32133
- const parsed = EnvoyFileSchema.safeParse(parsedJson);
32310
+ if (typeof parsedJson === "object" && parsedJson !== null && "natsUrls" in parsedJson) {
32311
+ return {
32312
+ kind: "invalid",
32313
+ reason: checkout ? `${filePath}: the top-level natsUrls is not read, and a checkout's envoy.json holds only a dispatch section` : `${filePath}: the top-level natsUrls is not read; move it to envoy.natsUrls`
32314
+ };
32315
+ }
32316
+ const parsed = schema.safeParse(parsedJson);
32134
32317
  if (!parsed.success) {
32135
32318
  return { kind: "invalid", reason: describeSchemaIssue(filePath, parsed.error) };
32136
32319
  }
32137
- return { kind: "valid", settings: parsed.data.dispatch ?? null };
32138
- }
32139
- function resolveDispatchConfig(env, options = {}) {
32140
- const explicitUrl = env.DISPATCH_URL;
32141
- const home = options.home ?? env.HOME ?? homedir();
32142
- const cwd = options.cwd ?? process.cwd();
32143
- const userFile = readEnvoyFile(path.join(home, ".config", "opencode", "envoy.json"));
32144
- const repoFile = readEnvoyFile(path.join(cwd, ".opencode", "envoy.json"));
32145
- for (const file2 of [userFile, repoFile]) {
32146
- if (file2.kind === "invalid") {
32147
- return { enabled: false, url: null, token: null, error: file2.reason };
32148
- }
32149
- }
32150
- const userSettings = userFile.kind === "valid" ? userFile.settings : null;
32151
- const repoSettings = repoFile.kind === "valid" ? repoFile.settings : null;
32152
- const merged = { ...userSettings, ...repoSettings };
32153
- const repoURL = repoSettings?.serverUrl;
32154
- if (explicitUrl === undefined && merged.enabled === true && repoURL !== undefined) {
32155
- const token2 = repoSettings?.token ?? null;
32156
- if (!token2) {
32320
+ return { kind: "valid", settings: parsed.data };
32321
+ }
32322
+ var FAILURE_KEPT_MS = 60000;
32323
+ var COMMAND_OUTCOMES = Symbol.for("legion.envoy-config.commands.v1");
32324
+ var processGlobal = globalThis;
32325
+ var commandOutcomes = processGlobal[COMMAND_OUTCOMES] ?? new Map;
32326
+ processGlobal[COMMAND_OUTCOMES] = commandOutcomes;
32327
+ function runCommand(command, env, cwd) {
32328
+ const childEnv = {};
32329
+ for (const [name, variable] of Object.entries(env)) {
32330
+ if (variable !== undefined)
32331
+ childEnv[name] = variable;
32332
+ }
32333
+ const directory = mkdtempSync(path.join(tmpdir(), "envoy-command-"));
32334
+ try {
32335
+ chmodSync(directory, 448);
32336
+ const output = path.join(directory, "stdout");
32337
+ const fd = openSync(output, "wx", 384);
32338
+ let result;
32339
+ try {
32340
+ result = Bun.spawnSync(["/bin/sh", "-c", command], {
32341
+ cwd,
32342
+ env: childEnv,
32343
+ stdin: "ignore",
32344
+ stdout: fd,
32345
+ stderr: "ignore",
32346
+ timeout: COMMAND_TIMEOUT_MS,
32347
+ detached: true
32348
+ });
32349
+ } catch (error48) {
32350
+ return { failure: `could not start: ${messageFor(error48)}`, timedOut: false };
32351
+ } finally {
32352
+ closeSync(fd);
32353
+ }
32354
+ try {
32355
+ process.kill(-result.pid, "SIGKILL");
32356
+ } catch {}
32357
+ if (result.exitedDueToTimeout) {
32358
+ return {
32359
+ failure: `did not finish within ${COMMAND_TIMEOUT_MS / 1000} s, and does not run again in this process`,
32360
+ timedOut: true
32361
+ };
32362
+ }
32363
+ if (!result.success) {
32364
+ return {
32365
+ failure: `exited with ${result.signalCode ?? `status ${result.exitCode}`}`,
32366
+ timedOut: false
32367
+ };
32368
+ }
32369
+ const value = readFileSync2(output, "utf-8").trim();
32370
+ if (value.length === 0)
32371
+ return { failure: "printed nothing", timedOut: false };
32372
+ if (!sendable(value)) {
32157
32373
  return {
32158
- enabled: false,
32159
- url: null,
32160
- token: null,
32161
- error: "repository dispatch.serverUrl requires dispatch.token from the same .opencode/envoy.json or DISPATCH_URL with DISPATCH_TOKEN"
32374
+ failure: "printed more than one line, or whitespace inside its value",
32375
+ timedOut: false
32162
32376
  };
32163
32377
  }
32164
- const url3 = parsedDispatchUrl(repoURL, "repository dispatch.serverUrl");
32165
- if (url3.error !== null)
32166
- return { enabled: false, url: null, token: null, error: url3.error };
32167
- return { enabled: true, url: url3.url, token: token2, error: null };
32378
+ return { value };
32379
+ } finally {
32380
+ rmSync(directory, { recursive: true, force: true });
32168
32381
  }
32169
- const rawUrl = explicitUrl !== undefined ? { value: explicitUrl, source: "DISPATCH_URL" } : merged.enabled === true ? { value: merged.serverUrl ?? DEFAULT_SERVER_URL, source: "dispatch.serverUrl" } : null;
32170
- const url2 = rawUrl ? parsedDispatchUrl(rawUrl.value, rawUrl.source) : { url: null, error: null };
32171
- let token;
32172
- let tokenSource;
32173
- if (env.DISPATCH_TOKEN_FILE !== undefined) {
32174
- tokenSource = "DISPATCH_TOKEN_FILE";
32175
- try {
32176
- token = readSecretFile(tokenSource, env.DISPATCH_TOKEN_FILE);
32177
- } catch (error48) {
32178
- return { enabled: false, url: url2.url, token: null, error: messageFor(error48) };
32382
+ }
32383
+ function fileValue(value, field, filePath, env) {
32384
+ if (!value.startsWith("!")) {
32385
+ if (!sendable(value)) {
32386
+ throw new Error(`${filePath}: ${field} holds whitespace or a control character`);
32179
32387
  }
32180
- } else if (env.DISPATCH_TOKEN !== undefined) {
32181
- tokenSource = "DISPATCH_TOKEN";
32182
- token = env.DISPATCH_TOKEN;
32183
- } else {
32184
- tokenSource = "dispatch.token";
32185
- token = merged.token ?? null;
32186
- }
32187
- if (url2.error !== null)
32188
- return { enabled: false, url: null, token, error: url2.error };
32189
- if (url2.url === null)
32190
- return { enabled: false, url: null, token, error: null };
32191
- if (!token) {
32192
- return {
32193
- enabled: false,
32194
- url: url2.url,
32195
- token,
32196
- error: `${tokenSource} must be a non-empty bearer token`
32388
+ return value;
32389
+ }
32390
+ const command = value.slice(1);
32391
+ const cwd = path.dirname(path.resolve(filePath));
32392
+ const key = JSON.stringify([command, filePath, cwd]);
32393
+ let outcome = commandOutcomes.get(key);
32394
+ if (outcome === undefined || "failure" in outcome && !outcome.timedOut && Date.now() - outcome.at >= FAILURE_KEPT_MS) {
32395
+ outcome = { ...runCommand(command, env, cwd), at: Date.now() };
32396
+ commandOutcomes.set(key, outcome);
32397
+ }
32398
+ if ("failure" in outcome)
32399
+ throw new Error(`${filePath}: ${field}'s command ${outcome.failure}`);
32400
+ return outcome.value;
32401
+ }
32402
+ function statDevice(directory) {
32403
+ try {
32404
+ return statSync(directory).dev;
32405
+ } catch {
32406
+ return;
32407
+ }
32408
+ }
32409
+ function moveNotice(oldFile, newFile, move, deviceOf) {
32410
+ const oldDevice = deviceOf(path.dirname(oldFile));
32411
+ let ancestor = path.dirname(newFile);
32412
+ let newDevice = deviceOf(ancestor);
32413
+ while (newDevice === undefined && path.dirname(ancestor) !== ancestor) {
32414
+ ancestor = path.dirname(ancestor);
32415
+ newDevice = deviceOf(ancestor);
32416
+ }
32417
+ if (oldDevice !== undefined && newDevice !== undefined && oldDevice !== newDevice) {
32418
+ return `${oldFile} is not read, and is on another filesystem than ${newFile} (a mount): create ${newFile}, and move ${oldFile} on the machine that owns it`;
32419
+ }
32420
+ return `${oldFile} is not read: ${move}`;
32421
+ }
32422
+ function oldUserFileNotice(filePath, env, deviceOf) {
32423
+ const home = nonEmpty(env.HOME) ?? homedir();
32424
+ const old = path.join(home, ".config", "opencode", "envoy.json");
32425
+ if (!existsSync(old))
32426
+ return;
32427
+ const selected = path.resolve(filePath);
32428
+ const userFile = path.resolve(home, ".config", "legion", "envoy.json");
32429
+ if (selected === userFile) {
32430
+ return moveNotice(old, userFile, "mkdir -p ~/.config/legion && mv ~/.config/opencode/envoy.json ~/.config/legion/", deviceOf);
32431
+ }
32432
+ const profileFile = PLUGIN_HARNESSES.map((harness) => namedDirectory(harness, env)).some((directory) => directory !== undefined && path.isAbsolute(directory) && selected === path.resolve(directory, "envoy.json"));
32433
+ if (profileFile) {
32434
+ return `${old} is not read for this profile; copy or link it to ${filePath}, or write that file`;
32435
+ }
32436
+ const configHome = nonEmpty(env.XDG_CONFIG_HOME);
32437
+ const neutral = neutralConfig(env);
32438
+ if (configHome !== undefined && path.isAbsolute(configHome) && "path" in neutral && selected === neutral.path) {
32439
+ return `${old} is not read under XDG_CONFIG_HOME=${configHome}`;
32440
+ }
32441
+ return;
32442
+ }
32443
+ function missingConfigNotice(filePath, missing, off) {
32444
+ const link = missing.link === null ? "" : ` (a link to ${missing.link}, which does not exist)`;
32445
+ const old = missing.oldUserFileNotice === undefined ? "" : `; ${missing.oldUserFileNotice}`;
32446
+ return `no envoy.json at ${filePath}${link}: ${off}${old}`;
32447
+ }
32448
+ function readEnvoyConfig(filePath, env, options) {
32449
+ const deviceOf = options.deviceOf ?? statDevice;
32450
+ const chosen = parseFile(filePath, EnvoyFileSchema, false);
32451
+ if (chosen.kind === "invalid")
32452
+ return { kind: "failed", path: filePath, error: chosen.reason };
32453
+ const resolvedChosen = path.resolve(filePath);
32454
+ const checkoutPath = path.resolve(options.cwd, ".envoy", "envoy.json");
32455
+ const checkoutFile = checkoutPath === resolvedChosen ? { kind: "absent", link: null } : parseFile(checkoutPath, CheckoutFileSchema, true);
32456
+ const own = chosen.kind === "valid" ? chosen.settings : {};
32457
+ let checkout = null;
32458
+ if (checkoutFile.kind === "invalid") {
32459
+ checkout = { kind: "invalid", path: checkoutPath, error: checkoutFile.reason };
32460
+ } else if (checkoutFile.kind === "valid") {
32461
+ checkout = {
32462
+ kind: "valid",
32463
+ path: checkoutPath,
32464
+ dispatch: checkoutFile.settings.dispatch ?? {},
32465
+ envoyError: Object.hasOwn(checkoutFile.settings, "envoy") ? `${checkoutPath}: envoy is not read from a checkout's envoy.json; put it in ${filePath}` : null
32197
32466
  };
32198
32467
  }
32199
- return { enabled: true, url: url2.url, token, error: null };
32468
+ const oldCheckout = path.resolve(options.cwd, ".opencode", "envoy.json");
32469
+ const warnings = oldCheckout !== resolvedChosen && !existsSync(checkoutPath) && existsSync(oldCheckout) ? [
32470
+ moveNotice(oldCheckout, checkoutPath, `mkdir -p ${path.dirname(checkoutPath)} && mv ${oldCheckout} ${checkoutPath}`, deviceOf)
32471
+ ] : [];
32472
+ const unreadOldUserFile = chosen.kind === "absent" ? oldUserFileNotice(filePath, env, deviceOf) : undefined;
32473
+ return {
32474
+ kind: "read",
32475
+ path: filePath,
32476
+ dispatch: own.dispatch ?? {},
32477
+ envoy: own.envoy ?? {},
32478
+ checkout,
32479
+ missing: chosen.kind === "absent" ? {
32480
+ link: chosen.link,
32481
+ ...unreadOldUserFile === undefined ? {} : { oldUserFileNotice: unreadOldUserFile }
32482
+ } : null,
32483
+ warnings
32484
+ };
32200
32485
  }
32201
- function activeDispatchConfig(env, options = {}) {
32202
- const config2 = resolveDispatchConfig(env, options);
32203
- if (config2.error !== null)
32204
- throw new Error(`dispatch config: ${config2.error}`);
32205
- const { url: url2, token } = config2;
32206
- if (!config2.enabled || url2 === null || token === null)
32207
- return null;
32208
- return { ...config2, url: url2, token };
32486
+
32487
+ // ../envoy-client/src/bearer.ts
32488
+ function bearerSource(env, section, written) {
32489
+ const pointer = nonEmpty(env[`${section}_TOKEN_FILE`]);
32490
+ if (pointer !== undefined) {
32491
+ return { kind: "variable", token: readSecretFile(`${section}_TOKEN_FILE`, pointer) };
32492
+ }
32493
+ const plain = nonEmpty(env[`${section}_TOKEN`]);
32494
+ if (plain !== undefined) {
32495
+ if (!sendable(plain)) {
32496
+ throw new Error(`${section}_TOKEN holds whitespace or a control character`);
32497
+ }
32498
+ return { kind: "variable", token: plain };
32499
+ }
32500
+ const bearer = written();
32501
+ return bearer === undefined ? { kind: "none" } : { kind: "file", ...bearer };
32502
+ }
32503
+ function fileBearer(bearer, url2, section, env) {
32504
+ const named = httpUrl2(url2)?.origin;
32505
+ const paired = httpUrl2(bearer.server)?.origin;
32506
+ if (named !== paired) {
32507
+ throw new Error(`${section}_URL names ${named}, but ${bearer.path}'s ${bearer.field} is for ${paired}; set ${section}_TOKEN or ${section}_TOKEN_FILE for it`);
32508
+ }
32509
+ if (bearer.checkout && bearer.token.startsWith("!")) {
32510
+ throw new Error(`${bearer.path}: ${bearer.field} is a command, which a checkout's envoy.json cannot run`);
32511
+ }
32512
+ if (bearer.token === "") {
32513
+ throw new Error(`${bearer.field} in ${bearer.path} must be a non-empty bearer token`);
32514
+ }
32515
+ return fileValue(bearer.token, bearer.field, bearer.path, env);
32516
+ }
32517
+
32518
+ // ../envoy-client/src/dispatch-config.ts
32519
+ var DEFAULT_SERVER_URL = "http://localhost:8766";
32520
+ function checkoutPair(checkout, serverUrl) {
32521
+ const { token } = checkout.dispatch;
32522
+ if (token === undefined) {
32523
+ throw new Error(`${checkout.path}: dispatch.serverUrl requires dispatch.token in the same file`);
32524
+ }
32525
+ return {
32526
+ kind: "file",
32527
+ token,
32528
+ field: "dispatch.token",
32529
+ path: checkout.path,
32530
+ server: serverUrl,
32531
+ checkout: true
32532
+ };
32533
+ }
32534
+ function writtenToken(config2, checkout) {
32535
+ if (checkout?.dispatch.token !== undefined) {
32536
+ throw new Error(`${checkout.path}: dispatch.token requires dispatch.serverUrl in the same file`);
32537
+ }
32538
+ const own = config2.dispatch;
32539
+ if (own.token === undefined)
32540
+ return;
32541
+ const server = own.serverUrl ?? DEFAULT_SERVER_URL;
32542
+ return {
32543
+ token: own.token,
32544
+ field: "dispatch.token",
32545
+ path: config2.path,
32546
+ server,
32547
+ checkout: false
32548
+ };
32549
+ }
32550
+ function dispatchSettings(env, config2) {
32551
+ if (config2.kind === "failed")
32552
+ return offWithError(config2.error);
32553
+ const explicitUrl = nonEmpty(env.DISPATCH_URL);
32554
+ const checkoutFile = explicitUrl === undefined ? config2.checkout : null;
32555
+ if (checkoutFile?.kind === "invalid")
32556
+ return offWithError(checkoutFile.error);
32557
+ const checkout = checkoutFile?.kind === "valid" ? checkoutFile : null;
32558
+ const own = config2.dispatch;
32559
+ if (own.enabled === false) {
32560
+ return offWithNotice(`${config2.path} sets dispatch.enabled to false: Dispatch is off`);
32561
+ }
32562
+ if (checkout?.dispatch.enabled === false) {
32563
+ return offWithNotice(`${checkout.path} sets dispatch.enabled to false: Dispatch is off`);
32564
+ }
32565
+ const checkoutServer = checkout?.dispatch.serverUrl;
32566
+ const addressed = explicitUrl !== undefined || checkoutServer !== undefined || own.serverUrl !== undefined || own.enabled === true;
32567
+ if (!addressed) {
32568
+ return offWithNotice(config2.missing === null ? `${config2.path} names no Dispatch server, and DISPATCH_URL is not set: Dispatch is off` : missingConfigNotice(config2.path, config2.missing, "Dispatch is off"));
32569
+ }
32570
+ if (explicitUrl !== undefined && httpUrl2(explicitUrl) === undefined) {
32571
+ return offWithError("DISPATCH_URL must be an http or https URL");
32572
+ }
32573
+ try {
32574
+ const source = checkout !== null && checkoutServer !== undefined ? checkoutPair(checkout, checkoutServer) : bearerSource(env, "DISPATCH", () => writtenToken(config2, checkout));
32575
+ if (source.kind === "none") {
32576
+ return offWithError(explicitUrl === undefined ? `${config2.path}: dispatch is enabled and no token is: set dispatch.token, or DISPATCH_TOKEN or DISPATCH_TOKEN_FILE` : `DISPATCH_URL is set and no token is: set DISPATCH_TOKEN or DISPATCH_TOKEN_FILE, or dispatch.token in ${config2.path}`);
32577
+ }
32578
+ const url2 = (explicitUrl ?? (source.kind === "file" ? source.server : own.serverUrl ?? DEFAULT_SERVER_URL)).replace(/\/+$/, "");
32579
+ const token = source.kind === "variable" ? source.token : fileBearer(source, url2, "DISPATCH", env);
32580
+ return { enabled: true, url: url2, token };
32581
+ } catch (error48) {
32582
+ return offWithError(messageFor(error48));
32583
+ }
32584
+ }
32585
+ function activeDispatchSettings(resolution) {
32586
+ if (resolution.enabled)
32587
+ return resolution;
32588
+ if (resolution.error !== null)
32589
+ throw new Error(`dispatch config: ${resolution.error}`);
32590
+ return null;
32209
32591
  }
32210
32592
 
32211
32593
  // ../envoy-client/src/dispatch-first.ts
@@ -32985,16 +33367,16 @@ async function readPictures(client, addresses, shown) {
32985
33367
  // ../envoy-client/src/dispatch-session-state.ts
32986
33368
  import {
32987
33369
  appendFileSync,
32988
- closeSync,
33370
+ closeSync as closeSync2,
32989
33371
  fstatSync,
32990
33372
  mkdirSync,
32991
- openSync,
33373
+ openSync as openSync2,
32992
33374
  readdirSync,
32993
33375
  readFileSync as readFileSync4,
32994
33376
  readSync,
32995
33377
  renameSync,
32996
- rmSync,
32997
- statSync,
33378
+ rmSync as rmSync2,
33379
+ statSync as statSync2,
32998
33380
  writeFileSync
32999
33381
  } from "fs";
33000
33382
  import { homedir as homedir2 } from "os";
@@ -33049,7 +33431,7 @@ function readResultsSince(dir, offset, onMalformed) {
33049
33431
  const path2 = join3(dir, "results.jsonl");
33050
33432
  let fd;
33051
33433
  try {
33052
- fd = openSync(path2, "r");
33434
+ fd = openSync2(path2, "r");
33053
33435
  } catch (error48) {
33054
33436
  if (hasErrnoCode(error48, "ENOENT"))
33055
33437
  return { entries: [], offset };
@@ -33078,7 +33460,7 @@ function readResultsSince(dir, offset, onMalformed) {
33078
33460
  }
33079
33461
  });
33080
33462
  } finally {
33081
- closeSync(fd);
33463
+ closeSync2(fd);
33082
33464
  }
33083
33465
  return { entries, offset: offset + complete };
33084
33466
  }
@@ -33093,7 +33475,7 @@ function linesBefore(fd, offset) {
33093
33475
  }
33094
33476
  function resultsEnd(dir) {
33095
33477
  try {
33096
- return statSync(join3(dir, "results.jsonl")).size;
33478
+ return statSync2(join3(dir, "results.jsonl")).size;
33097
33479
  } catch (error48) {
33098
33480
  if (hasErrnoCode(error48, "ENOENT"))
33099
33481
  return 0;
@@ -33136,36 +33518,186 @@ function subscriptionRemovedTopics(raw, sessionID) {
33136
33518
  // ../envoy-client/src/nats-auth.ts
33137
33519
  var import_nats = __toESM(require_mod4(), 1);
33138
33520
  var seedKeys = import_nats.nkeys;
33139
- function natsAuthOptions(env) {
33140
- const { NATS_NKEY_SEED_FILE: file2, NATS_NKEY_SEED: plain } = env;
33141
- let seed;
33142
- let source;
33143
- if (file2 !== undefined) {
33144
- if (file2 === "")
33145
- throw new Error("NATS_NKEY_SEED_FILE is set but empty");
33146
- seed = readSecretFile("NATS_NKEY_SEED_FILE", file2);
33147
- source = `NATS_NKEY_SEED_FILE (${file2})`;
33148
- } else if (plain !== undefined) {
33149
- seed = plain.trim();
33150
- if (seed.length === 0)
33151
- throw new Error("NATS_NKEY_SEED is set but empty");
33152
- source = "NATS_NKEY_SEED";
33153
- } else {
33521
+ function natsAuthOptions(seed) {
33522
+ if (seed === undefined)
33154
33523
  return {};
33155
- }
33156
- const bytes = new TextEncoder().encode(seed);
33524
+ const bytes = new TextEncoder().encode(seed.value);
33157
33525
  let publicKey;
33158
33526
  try {
33159
33527
  publicKey = seedKeys.fromSeed(bytes).getPublicKey();
33160
33528
  } catch (error48) {
33161
- throw new Error(`${source} does not hold a valid nkey seed: ${messageFor(error48)}`);
33529
+ throw new Error(`${seed.source} does not hold a valid nkey seed: ${messageFor(error48)}`);
33162
33530
  }
33163
33531
  if (!publicKey.startsWith("U")) {
33164
- throw new Error(`${source} holds an nkey seed that is not a user's (public key ${publicKey})`);
33532
+ throw new Error(`${seed.source} holds an nkey seed that is not a user's (public key ${publicKey})`);
33165
33533
  }
33166
33534
  return { authenticator: import_nats.nkeyAuthenticator(bytes) };
33167
33535
  }
33168
33536
 
33537
+ // ../envoy-client/src/envoy-settings.ts
33538
+ var DEFAULT_ENVOY_URL = "http://127.0.0.1:9020";
33539
+ var DEFAULT_HEARTBEAT_MS = 120000;
33540
+ var MIN_HEARTBEAT_MS = 25;
33541
+ function natsSeedFromEnvironment(env) {
33542
+ const { NATS_NKEY_SEED_FILE: file2, NATS_NKEY_SEED: plain } = env;
33543
+ if (file2 !== undefined) {
33544
+ if (file2 === "")
33545
+ throw new Error("NATS_NKEY_SEED_FILE is set but empty");
33546
+ return {
33547
+ value: readSecretFile("NATS_NKEY_SEED_FILE", file2),
33548
+ source: `NATS_NKEY_SEED_FILE (${file2})`
33549
+ };
33550
+ }
33551
+ if (plain === undefined)
33552
+ return;
33553
+ const value = plain.trim();
33554
+ if (value.length === 0)
33555
+ throw new Error("NATS_NKEY_SEED is set but empty");
33556
+ return { value, source: "NATS_NKEY_SEED" };
33557
+ }
33558
+ var NO_NATS_SERVER = "Envoy has no NATS server (envoy.natsUrls, ENVOY_NATS_URL)";
33559
+ var NO_NATS_CONNECTION = "this session opens no NATS connection";
33560
+ function natsServerKey(url2) {
33561
+ const match = /^([a-z][a-z0-9+.-]*):\/\/([^@/]*@)?(\[[^\]]*\]|[^:/]*)(?::(\d+))?(\/.*)?$/i.exec(url2);
33562
+ if (match === null)
33563
+ return url2;
33564
+ const [, scheme = "", userinfo = "", host = "", port = "4222", rest = ""] = match;
33565
+ return `${scheme.toLowerCase()}://${userinfo}${host.toLowerCase()}:${port}${rest.replace(/\/+$/, "")}`;
33566
+ }
33567
+ function natsCredential(env, section, namedNatsUrls, filePath) {
33568
+ const fromEnvironment = natsSeedFromEnvironment(env);
33569
+ if (fromEnvironment !== undefined || section.natsSeed === undefined)
33570
+ return fromEnvironment;
33571
+ if (namedNatsUrls.length > 0) {
33572
+ const servers = new Set((section.natsUrls ?? []).map(natsServerKey));
33573
+ const named = new Set(namedNatsUrls.map(natsServerKey));
33574
+ if (named.size !== servers.size || ![...named].every((server) => servers.has(server))) {
33575
+ throw new Error(`ENVOY_NATS_URL names other servers than ${filePath}'s envoy.natsUrls; set NATS_NKEY_SEED_FILE for them`);
33576
+ }
33577
+ }
33578
+ return {
33579
+ value: fileValue(section.natsSeed, "envoy.natsSeed", filePath, env),
33580
+ source: `envoy.natsSeed in ${filePath}`
33581
+ };
33582
+ }
33583
+ function envoySettings(env, config2, options = {}) {
33584
+ if (config2.kind === "failed")
33585
+ return offWithError(config2.error);
33586
+ const section = config2.envoy;
33587
+ if (section.enabled === false) {
33588
+ return offWithNotice(`${config2.path} sets envoy.enabled to false: Envoy is off`);
33589
+ }
33590
+ const namedUrl = nonEmpty(env.ENVOY_URL);
33591
+ const namedNatsUrls = (env.ENVOY_NATS_URL ?? "").split(",").map((url3) => url3.trim()).filter((url3) => url3.length > 0);
33592
+ const addressed = namedUrl !== undefined || namedNatsUrls.length > 0 || section.url !== undefined || (section.natsUrls ?? []).length > 0 || section.enabled === true;
33593
+ if (!addressed) {
33594
+ return offWithNotice(config2.missing === null ? `${config2.path} names no Envoy listener or NATS server, and neither ENVOY_URL nor ENVOY_NATS_URL is set: Envoy is off` : missingConfigNotice(config2.path, config2.missing, "Envoy is off"));
33595
+ }
33596
+ if (namedUrl !== undefined && httpUrl2(namedUrl) === undefined) {
33597
+ return offWithError("ENVOY_URL must be an http or https URL");
33598
+ }
33599
+ const listener = section.url ?? DEFAULT_ENVOY_URL;
33600
+ const url2 = namedUrl ?? listener;
33601
+ let token;
33602
+ try {
33603
+ const source = bearerSource(env, "ENVOY", () => section.token === undefined ? undefined : {
33604
+ token: section.token,
33605
+ field: "envoy.token",
33606
+ path: config2.path,
33607
+ server: listener,
33608
+ checkout: false
33609
+ });
33610
+ token = source.kind === "none" ? undefined : source.kind === "variable" ? source.token : fileBearer(source, url2, "ENVOY", env);
33611
+ } catch (error48) {
33612
+ return offWithError(messageFor(error48));
33613
+ }
33614
+ const natsUrls = namedNatsUrls.length > 0 ? namedNatsUrls : section.natsUrls ?? [];
33615
+ let inbound;
33616
+ if (options.nats === false)
33617
+ inbound = { off: NO_NATS_CONNECTION };
33618
+ else if (natsUrls.length === 0)
33619
+ inbound = { off: NO_NATS_SERVER };
33620
+ else {
33621
+ try {
33622
+ inbound = { natsUrls, natsSeed: natsCredential(env, section, namedNatsUrls, config2.path) };
33623
+ } catch (error48) {
33624
+ inbound = { off: messageFor(error48) };
33625
+ }
33626
+ }
33627
+ const rawHeartbeatMs = Number(env.ENVOY_HEARTBEAT_MS);
33628
+ return {
33629
+ enabled: true,
33630
+ url: normalizeEnvoyUrl(url2),
33631
+ token,
33632
+ inbound,
33633
+ heartbeatMs: Number.isFinite(rawHeartbeatMs) && rawHeartbeatMs > 0 ? Math.max(rawHeartbeatMs, MIN_HEARTBEAT_MS) : DEFAULT_HEARTBEAT_MS
33634
+ };
33635
+ }
33636
+ function normalizeEnvoyUrl(value) {
33637
+ return value.replace(/\/+$/, "");
33638
+ }
33639
+
33640
+ // ../envoy-client/src/session-settings.ts
33641
+ function sessionConfigFile(harness, env) {
33642
+ try {
33643
+ return { path: envoyConfigPath(harness, env), error: null };
33644
+ } catch (error48) {
33645
+ return { path: null, error: messageFor(error48) };
33646
+ }
33647
+ }
33648
+ function startNotice(config2, dispatch, envoy, nats) {
33649
+ if (config2.kind === "failed")
33650
+ return `${config2.error}: Dispatch and Envoy are off`;
33651
+ const { missing, checkout } = config2;
33652
+ const dispatchQuiet = !dispatch.enabled && dispatch.error === null;
33653
+ const envoyQuiet = !envoy.enabled && envoy.error === null;
33654
+ const parts = [];
33655
+ if (missing !== null && dispatchQuiet && envoyQuiet) {
33656
+ parts.push(missingConfigNotice(config2.path, missing, "Dispatch and Envoy are off"));
33657
+ } else {
33658
+ if (!dispatch.enabled && dispatch.error !== null)
33659
+ parts.push(`Dispatch is off: ${dispatch.error}`);
33660
+ else if (dispatchQuiet && missing !== null) {
33661
+ parts.push(missingConfigNotice(config2.path, missing, "Dispatch is off"));
33662
+ }
33663
+ if (!envoy.enabled && envoy.error !== null)
33664
+ parts.push(`Envoy is off: ${envoy.error}`);
33665
+ else if (envoyQuiet && missing !== null) {
33666
+ parts.push(missingConfigNotice(config2.path, missing, "Envoy is off"));
33667
+ }
33668
+ }
33669
+ if (checkout?.kind === "valid" && checkout.envoyError !== null)
33670
+ parts.push(checkout.envoyError);
33671
+ if (checkout?.kind === "invalid" && (dispatch.enabled || dispatch.error !== checkout.error)) {
33672
+ parts.push(`${checkout.error}; not read while DISPATCH_URL is set`);
33673
+ }
33674
+ parts.push(...config2.warnings);
33675
+ if (envoy.enabled && nats && "off" in envoy.inbound) {
33676
+ parts.push(`Envoy's inbound messages are off: ${envoy.inbound.off}; the Envoy tools still work`);
33677
+ }
33678
+ return parts.length === 0 ? null : parts.join("; ");
33679
+ }
33680
+ function sessionSettings(file2, env, options) {
33681
+ if (file2.path === null) {
33682
+ const off = offWithError(file2.error);
33683
+ return { dispatch: off, envoy: off, notice: `${file2.error}: Dispatch and Envoy are off` };
33684
+ }
33685
+ const config2 = readEnvoyConfig(file2.path, env, options);
33686
+ const dispatch = dispatchSettings(env, config2);
33687
+ const envoy = envoySettings(env, config2, { nats: options.nats });
33688
+ return { dispatch, envoy, notice: startNotice(config2, dispatch, envoy, options.nats !== false) };
33689
+ }
33690
+ function sessionDispatchSettings(file2, env, options) {
33691
+ if (file2.path === null)
33692
+ return { dispatch: offWithError(file2.error), warnings: [], missing: null };
33693
+ const config2 = readEnvoyConfig(file2.path, env, options);
33694
+ return {
33695
+ dispatch: dispatchSettings(env, config2),
33696
+ warnings: config2.kind === "read" ? config2.warnings : [],
33697
+ missing: config2.kind === "read" ? config2.missing : null
33698
+ };
33699
+ }
33700
+
33169
33701
  // ../envoy-client/src/tool-contract.ts
33170
33702
  var DELIVERY_CONTRACT = "Delivery is at-least-once, possibly out of order across topics; use id for dedupe and at for freshness.";
33171
33703
  var TOPIC_GUIDE = "Topic guide (all are under notifications.): agent.<session_id> (subscribe: own inbox); role.<role> " + "(publish-to; holders claim via envoy_role_set). > matches one or more trailing tokens and does not " + "match the base subject. Envoy registers the concrete base when you subscribe to <subject>.>, so " + "the recommended default remains github.<owner>.<repo>.pr.<n>.>. <owner> and <repo> are one token " + "each, with every dot in the name written _ (sjawhar/.github is github.sjawhar._github; " + "acme/site.io is github.acme.site_io), and a topic spelled with the dot receives nothing. " + "Default PR subscription: " + "github.<owner>.<repo>.pr.<n>.> (it receives the quiet PR family): pr.<n> (lifecycle: " + "opened/synchronize/closed; closed carries merged, merge_commit_sha, merged_by, head_sha), " + "pr.<n>.comment, pr.<n>.review, pr.<n>.mention, pr.<n>.checks (one settlement event per commit whose checks settle, the head or not, naming its sha: " + 'passed/failed/cancelled/skipped with failing names and URLs; re-fires with superseded_settlement: "true" ' + "when new runs appear for the same commit). Other GitHub: issue.<n>, issue.<n>.comment, " + "issue.<n>.mention, mention, push.branch.<name>, push.tag.<name>, workflow.<file>.<action> (only " + "runs without an associated PR); slack.<team>.<channel>.message|mention and " + "slack.<team>.<channel>.thread.<ts>.message|mention; ghostwispr.<session>.<kind>; " + "whatsapp.<phone>.<jid>.<kind>; envoy.exceptions.<original-topic>.";
@@ -33382,16 +33914,10 @@ class EnvoyApiError extends Error {
33382
33914
  this.expected = parsed?.expected;
33383
33915
  }
33384
33916
  }
33385
- function resolveEnvoyToken(env) {
33386
- const { ENVOY_TOKEN_FILE: file2, ENVOY_TOKEN: plain } = env;
33387
- if (file2 !== undefined && file2 !== "")
33388
- return readSecretFile("ENVOY_TOKEN_FILE", file2);
33389
- return plain || undefined;
33390
- }
33391
33917
  function createEnvoyClient(config2) {
33392
33918
  const baseUrl = normalizeEnvoyUrl(config2.baseUrl);
33393
33919
  const timeoutMs = config2.timeoutMs ?? DEFAULT_TIMEOUT_MS;
33394
- const apiToken = resolveEnvoyToken(process.env);
33920
+ const apiToken = config2.token;
33395
33921
  const request = async (path2, init) => {
33396
33922
  const url2 = `${baseUrl}${path2}`;
33397
33923
  for (let attempt = 0;attempt < 2; attempt += 1) {
@@ -33522,8 +34048,8 @@ function createEnvoyClient(config2) {
33522
34048
  };
33523
34049
  }
33524
34050
  function waitForRetry() {
33525
- const { promise: promise2, resolve } = Promise.withResolvers();
33526
- setTimeout(resolve, RETRY_DELAY_MS);
34051
+ const { promise: promise2, resolve: resolve2 } = Promise.withResolvers();
34052
+ setTimeout(resolve2, RETRY_DELAY_MS);
33527
34053
  return promise2;
33528
34054
  }
33529
34055
  function messageMetadata(input) {
@@ -34417,7 +34943,7 @@ var codec2 = import_nats2.StringCodec();
34417
34943
  var NATS_RETRY_INTERVAL_MS = 15000;
34418
34944
  var DELIVERY_PICTURES_TIMEOUT_MS = 20000;
34419
34945
  function timedDispatchClient(timeoutMs) {
34420
- const config2 = activeDispatchConfig(process.env, { cwd: process.cwd() });
34946
+ const config2 = activeDispatchSettings(sessionDispatchSettings(CONFIG_FILE, process.env, { cwd: process.cwd() }).dispatch);
34421
34947
  return config2 === null ? undefined : new DispatchClient(config2.url, config2.token, fetch, AbortSignal.timeout(timeoutMs));
34422
34948
  }
34423
34949
  var CAPABILITIES_WITHOUT_BTW = DELIVERY_CAPABILITIES.filter((capability) => capability !== "btw");
@@ -34496,12 +35022,12 @@ function isRoleClaimEntry(entry) {
34496
35022
  return entry.data.role === null || typeof entry.data.role === "string";
34497
35023
  }
34498
35024
  function resolveSkillsDirectory() {
34499
- const moduleDirectory = dirname(fileURLToPath(import.meta.url));
35025
+ const moduleDirectory = dirname2(fileURLToPath(import.meta.url));
34500
35026
  const candidates = [
34501
- resolve(moduleDirectory, "skills"),
34502
- resolve(moduleDirectory, "../../../skills")
35027
+ resolve2(moduleDirectory, "skills"),
35028
+ resolve2(moduleDirectory, "../../../skills")
34503
35029
  ];
34504
- const found = candidates.find((directory) => existsSync(directory));
35030
+ const found = candidates.find((directory) => existsSync2(directory));
34505
35031
  if (!found) {
34506
35032
  throw new Error(`legion skills directory not found; tried: ${candidates.join(", ")}`);
34507
35033
  }
@@ -34509,24 +35035,41 @@ function resolveSkillsDirectory() {
34509
35035
  }
34510
35036
  var SKILLS_DIRECTORY = resolveSkillsDirectory();
34511
35037
  var DISPATCH_FIRST_CONTEXT = readDispatchFirstContext(dispatchFirstSkillFile(SKILLS_DIRECTORY));
34512
- var PLUGIN_BIN = resolve(dirname(fileURLToPath(import.meta.url)), "..", "bin");
35038
+ var PLUGIN_BIN = resolve2(dirname2(fileURLToPath(import.meta.url)), "..", "bin");
34513
35039
  if (!(process.env.PATH ?? "").split(delimiter).includes(PLUGIN_BIN)) {
34514
35040
  process.env.PATH = `${PLUGIN_BIN}${delimiter}${process.env.PATH ?? ""}`;
34515
35041
  }
34516
35042
  process.env.DISPATCH_HOST = "omp";
35043
+ var CONFIG_FILE = sessionConfigFile("omp", process.env);
35044
+ if (CONFIG_FILE.path !== null)
35045
+ process.env.ENVOY_CONFIG_FILE = CONFIG_FILE.path;
34517
35046
  function envoyExtension(pi) {
34518
35047
  logger3.debug("extension instance loaded", { extension: import.meta.url });
34519
35048
  const publishedInterface = publishEnvoyPluginInterface(import.meta.url);
34520
- const defaults = envoyDefaultsFromEnvironment(process.env);
34521
- const dispatchConfig = resolveDispatchConfig(process.env, { cwd: process.cwd() });
35049
+ const atStart = sessionSettings(CONFIG_FILE, process.env, { cwd: process.cwd() });
35050
+ const { envoy } = atStart;
34522
35051
  const currentDispatchConfig = () => {
34523
- const config2 = activeDispatchConfig(process.env, { cwd: process.cwd() });
35052
+ const resolution = sessionDispatchSettings(CONFIG_FILE, process.env, {
35053
+ cwd: process.cwd()
35054
+ }).dispatch;
35055
+ const config2 = activeDispatchSettings(resolution);
34524
35056
  if (config2 === null) {
34525
- throw new Error("Dispatch is no longer configured (dispatch.serverUrl/token missing)");
35057
+ throw new Error(`Dispatch is no longer configured: ${resolution.enabled ? "" : resolution.notice}`);
34526
35058
  }
34527
35059
  return config2;
34528
35060
  };
34529
- const client = createEnvoyClient({ baseUrl: defaults.envoyUrl, fetch });
35061
+ const inbound = envoy.enabled && !("off" in envoy.inbound);
35062
+ const startNotice2 = atStart.notice ?? "";
35063
+ const active = envoy.enabled ? {
35064
+ settings: envoy,
35065
+ client: createEnvoyClient({ baseUrl: envoy.url, fetch, token: envoy.token })
35066
+ } : undefined;
35067
+ const requireEnvoy = () => {
35068
+ if (active === undefined) {
35069
+ throw new Error(`Envoy is off for this session: ${envoy.enabled ? "" : envoy.error ?? envoy.notice}`);
35070
+ }
35071
+ return active;
35072
+ };
34530
35073
  const subscriptions = new Map;
34531
35074
  const delivered = createDeliveryDedupe();
34532
35075
  let connection;
@@ -34664,13 +35207,21 @@ function envoyExtension(pi) {
34664
35207
  };
34665
35208
  pi.on("resources_discover", async () => ({ skillPaths: [SKILLS_DIRECTORY] }));
34666
35209
  registerEnvoyMessageRenderer(pi);
35210
+ const requireInbound = () => {
35211
+ const { inbound: inbound2 } = requireEnvoy().settings;
35212
+ if ("off" in inbound2) {
35213
+ throw new Error(`inbound messages are off for this session: ${inbound2.off}`);
35214
+ }
35215
+ return inbound2;
35216
+ };
34667
35217
  const ensureConnection = async () => {
34668
35218
  if (connection?.isClosed() === false)
34669
35219
  return connection;
35220
+ const { natsUrls, natsSeed } = requireInbound();
34670
35221
  connection = await import_nats2.connect({
34671
- servers: [...defaults.natsUrls],
35222
+ servers: [...natsUrls],
34672
35223
  name: `omp-${sessionID || "unknown"}`,
34673
- ...natsAuthOptions(process.env),
35224
+ ...natsAuthOptions(natsSeed),
34674
35225
  reconnect: true,
34675
35226
  maxReconnectAttempts: -1,
34676
35227
  reconnectTimeWait: 2000
@@ -35008,8 +35559,8 @@ function envoyExtension(pi) {
35008
35559
  agentStreamCommandsRefreshedOnWatchAt = -Infinity;
35009
35560
  }
35010
35561
  agentStreamControlSession = session;
35011
- const active = await ensureConnection();
35012
- const subscription = active.subscribe(agentStreamControlSubject(session));
35562
+ const active2 = await ensureConnection();
35563
+ const subscription = active2.subscribe(agentStreamControlSubject(session));
35013
35564
  agentStreamControl = subscription;
35014
35565
  pumpAgentStreamControl(subscription, session);
35015
35566
  };
@@ -35057,7 +35608,7 @@ function envoyExtension(pi) {
35057
35608
  closeIntentionally(subject2);
35058
35609
  return false;
35059
35610
  };
35060
- const registerSession = () => client.subscribe({
35611
+ const registerSession = () => requireEnvoy().client.subscribe({
35061
35612
  sessionID,
35062
35613
  directory: sessionDirectory2,
35063
35614
  topics: [
@@ -35078,6 +35629,7 @@ function envoyExtension(pi) {
35078
35629
  return;
35079
35630
  const id = sessionID;
35080
35631
  const role = topic.slice(ROLE_TOPIC_PREFIX.length);
35632
+ const { client } = requireEnvoy();
35081
35633
  const holder = await client.getRole(role).then((info) => info.holder, (error48) => {
35082
35634
  if (error48 instanceof EnvoyApiError && error48.details.status === 404)
35083
35635
  return;
@@ -35152,10 +35704,11 @@ function envoyExtension(pi) {
35152
35704
  }).finally(() => {
35153
35705
  healing = false;
35154
35706
  });
35155
- }, defaults.heartbeatMs);
35707
+ }, requireEnvoy().settings.heartbeatMs);
35156
35708
  heartbeatRegistered = true;
35157
35709
  };
35158
35710
  const recoverRegisteredInterests = async () => {
35711
+ const { client } = requireEnvoy();
35159
35712
  const registry2 = await client.getInterest(sessionID).catch(() => {
35160
35713
  return;
35161
35714
  });
@@ -35170,6 +35723,7 @@ function envoyExtension(pi) {
35170
35723
  const setEnvoyRole = async (role, options = {}) => {
35171
35724
  const topic = ROLE_TOPIC_PREFIX + role;
35172
35725
  const previousTopic = claimedRoleTopic;
35726
+ const { client } = requireEnvoy();
35173
35727
  const result = await client.setRole({
35174
35728
  sessionID,
35175
35729
  role,
@@ -35217,6 +35771,7 @@ function envoyExtension(pi) {
35217
35771
  }
35218
35772
  let role = remembered ?? claimedRoleTopic?.slice(ROLE_TOPIC_PREFIX.length);
35219
35773
  if (role === undefined) {
35774
+ const { client } = requireEnvoy();
35220
35775
  for (const source of roleSources(previousSessionID, carryPreviousSessionRole)) {
35221
35776
  const registry2 = await client.getInterest(source).catch(() => {
35222
35777
  return;
@@ -35278,6 +35833,7 @@ function envoyExtension(pi) {
35278
35833
  throw new Error(`Envoy has no active session for Legion role claim: ${targetSessionID}`);
35279
35834
  }
35280
35835
  markLegionManagedSession(targetSessionID);
35836
+ requireInbound();
35281
35837
  if (sessionID !== targetSessionID)
35282
35838
  await establishSession(context);
35283
35839
  await registerSession();
@@ -35322,16 +35878,10 @@ function envoyExtension(pi) {
35322
35878
  bindDispatchSession(context.sessionManager.getSessionId());
35323
35879
  const previousSessionID = sessionID;
35324
35880
  restoreLocalSessionState(context);
35325
- if (dispatchConfig.error !== null) {
35326
- context.ui.notify(`envoy: Dispatch disabled \u2014 ${dispatchConfig.error}`, "warning");
35327
- }
35328
- if (defaults.natsUrls.length === 0) {
35329
- context.ui.notify([
35330
- "envoy: ENVOY_NATS_URL is not set; inbound envoy messages are disabled",
35331
- "(outbound tools still work)"
35332
- ].join(" "), "warning");
35881
+ if (startNotice2 !== "")
35882
+ context.ui.notify(`envoy: ${startNotice2}`, "warning");
35883
+ if (!inbound)
35333
35884
  return;
35334
- }
35335
35885
  let established = false;
35336
35886
  const establish = async () => {
35337
35887
  await establishSession(context, {}, previousSessionID);
@@ -35359,7 +35909,7 @@ function envoyExtension(pi) {
35359
35909
  return;
35360
35910
  const previousID = sessionID;
35361
35911
  restoreLocalSessionState(context);
35362
- if (defaults.natsUrls.length === 0)
35912
+ if (!inbound)
35363
35913
  return;
35364
35914
  try {
35365
35915
  const carryPreviousSessionRole = reason !== "new" && reason !== "resume";
@@ -35408,7 +35958,7 @@ function envoyExtension(pi) {
35408
35958
  const deadline = Promise.withResolvers();
35409
35959
  const timer = setTimeout(deadline.resolve, 1000);
35410
35960
  try {
35411
- const deregistration = sessionID === "" ? Promise.resolve() : client.unregisterSession(sessionID).catch(() => {
35961
+ const deregistration = sessionID === "" || active === undefined ? Promise.resolve() : active.client.unregisterSession(sessionID).catch(() => {
35412
35962
  return;
35413
35963
  });
35414
35964
  const draining = connection?.drain().catch(() => {
@@ -35435,23 +35985,25 @@ function envoyExtension(pi) {
35435
35985
  forgetShownPictures(liveSessionID);
35436
35986
  }
35437
35987
  });
35438
- for (const spec of envoyToolSpecs) {
35439
- pi.registerTool({
35440
- name: spec.name,
35441
- label: spec.name,
35442
- description: spec.description,
35443
- parameters: schemaFor(pi, spec.operation),
35444
- lenientArgValidation: true,
35445
- execute: async (_id, parameters, _signal, _onUpdate, context) => execute(spec.operation, parameters, context)
35446
- });
35988
+ if (envoy.enabled) {
35989
+ for (const spec of envoyToolSpecs) {
35990
+ pi.registerTool({
35991
+ name: spec.name,
35992
+ label: spec.name,
35993
+ description: spec.description,
35994
+ parameters: schemaFor(pi, spec.operation),
35995
+ lenientArgValidation: true,
35996
+ execute: async (_id, parameters, _signal, _onUpdate, context) => execute(spec.operation, parameters, context)
35997
+ });
35998
+ }
35999
+ registerEnvoyWhoamiCommand(pi, replyAddress);
35447
36000
  }
35448
- if (dispatchConfig.enabled) {
36001
+ if (atStart.dispatch.enabled) {
35449
36002
  pi.on("context", async (event) => {
35450
36003
  const messages = withDispatchFirst(event.messages, DISPATCH_FIRST_CONTEXT);
35451
36004
  return messages === undefined ? undefined : { messages };
35452
36005
  });
35453
36006
  }
35454
- registerEnvoyWhoamiCommand(pi, replyAddress);
35455
36007
  pi.on("before_agent_start", async (event, context) => {
35456
36008
  const id = context.sessionManager.getSessionId();
35457
36009
  if (id === "" || event.prompt.trim() === "" || !context.hasUI || sideTurn(context) === undefined || legionManaged(id)) {
@@ -35610,6 +36162,7 @@ function envoyExtension(pi) {
35610
36162
  async function execute(operation, rawParameters, context) {
35611
36163
  try {
35612
36164
  const parameters = parseEnvoyToolArguments(operation, rawParameters);
36165
+ const { client } = requireEnvoy();
35613
36166
  switch (operation) {
35614
36167
  case EnvoyToolOperation.subscribe: {
35615
36168
  const added = [];