@poe-platform/safe-bash 0.1.59 → 0.1.61

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.
@@ -41,7 +41,7 @@ var require_base64_js = __commonJS({
41
41
  "node_modules/base64-js/index.js"(exports) {
42
42
  "use strict";
43
43
  init_platform();
44
- exports.byteLength = byteLength;
44
+ exports.byteLength = byteLength2;
45
45
  exports.toByteArray = toByteArray;
46
46
  exports.fromByteArray = fromByteArray;
47
47
  var lookup = [];
@@ -66,7 +66,7 @@ var require_base64_js = __commonJS({
66
66
  var placeHoldersLen = validLen === len2 ? 0 : 4 - validLen % 4;
67
67
  return [validLen, placeHoldersLen];
68
68
  }
69
- function byteLength(b64) {
69
+ function byteLength2(b64) {
70
70
  var lens = getLens(b64);
71
71
  var validLen = lens[0];
72
72
  var placeHoldersLen = lens[1];
@@ -366,7 +366,7 @@ var require_buffer = __commonJS({
366
366
  if (!Buffer3.isEncoding(encoding)) {
367
367
  throw new TypeError("Unknown encoding: " + encoding);
368
368
  }
369
- const length = byteLength(string, encoding) | 0;
369
+ const length = byteLength2(string, encoding) | 0;
370
370
  let buf = createBuffer(length);
371
371
  const actual = buf.write(string, encoding);
372
372
  if (actual !== length) {
@@ -374,11 +374,11 @@ var require_buffer = __commonJS({
374
374
  }
375
375
  return buf;
376
376
  }
377
- function fromArrayLike(array) {
378
- const length = array.length < 0 ? 0 : checked(array.length) | 0;
377
+ function fromArrayLike(array2) {
378
+ const length = array2.length < 0 ? 0 : checked(array2.length) | 0;
379
379
  const buf = createBuffer(length);
380
380
  for (let i = 0; i < length; i += 1) {
381
- buf[i] = array[i] & 255;
381
+ buf[i] = array2[i] & 255;
382
382
  }
383
383
  return buf;
384
384
  }
@@ -389,20 +389,20 @@ var require_buffer = __commonJS({
389
389
  }
390
390
  return fromArrayLike(arrayView);
391
391
  }
392
- function fromArrayBuffer(array, byteOffset, length) {
393
- if (byteOffset < 0 || array.byteLength < byteOffset) {
392
+ function fromArrayBuffer(array2, byteOffset2, length) {
393
+ if (byteOffset2 < 0 || array2.byteLength < byteOffset2) {
394
394
  throw new RangeError('"offset" is outside of buffer bounds');
395
395
  }
396
- if (array.byteLength < byteOffset + (length || 0)) {
396
+ if (array2.byteLength < byteOffset2 + (length || 0)) {
397
397
  throw new RangeError('"length" is outside of buffer bounds');
398
398
  }
399
399
  let buf;
400
- if (byteOffset === void 0 && length === void 0) {
401
- buf = new Uint8Array(array);
400
+ if (byteOffset2 === void 0 && length === void 0) {
401
+ buf = new Uint8Array(array2);
402
402
  } else if (length === void 0) {
403
- buf = new Uint8Array(array, byteOffset);
403
+ buf = new Uint8Array(array2, byteOffset2);
404
404
  } else {
405
- buf = new Uint8Array(array, byteOffset, length);
405
+ buf = new Uint8Array(array2, byteOffset2, length);
406
406
  }
407
407
  Object.setPrototypeOf(buf, Buffer3.prototype);
408
408
  return buf;
@@ -520,7 +520,7 @@ var require_buffer = __commonJS({
520
520
  }
521
521
  return buffer;
522
522
  };
523
- function byteLength(string, encoding) {
523
+ function byteLength2(string, encoding) {
524
524
  if (Buffer3.isBuffer(string)) {
525
525
  return string.length;
526
526
  }
@@ -563,7 +563,7 @@ var require_buffer = __commonJS({
563
563
  }
564
564
  }
565
565
  }
566
- Buffer3.byteLength = byteLength;
566
+ Buffer3.byteLength = byteLength2;
567
567
  function slowToString(encoding, start, end) {
568
568
  let loweredCase = false;
569
569
  if (start === void 0 || start < 0) {
@@ -726,26 +726,26 @@ var require_buffer = __commonJS({
726
726
  if (y < x) return 1;
727
727
  return 0;
728
728
  };
729
- function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
729
+ function bidirectionalIndexOf(buffer, val, byteOffset2, encoding, dir) {
730
730
  if (buffer.length === 0) return -1;
731
- if (typeof byteOffset === "string") {
732
- encoding = byteOffset;
733
- byteOffset = 0;
734
- } else if (byteOffset > 2147483647) {
735
- byteOffset = 2147483647;
736
- } else if (byteOffset < -2147483648) {
737
- byteOffset = -2147483648;
738
- }
739
- byteOffset = +byteOffset;
740
- if (numberIsNaN(byteOffset)) {
741
- byteOffset = dir ? 0 : buffer.length - 1;
742
- }
743
- if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
744
- if (byteOffset >= buffer.length) {
731
+ if (typeof byteOffset2 === "string") {
732
+ encoding = byteOffset2;
733
+ byteOffset2 = 0;
734
+ } else if (byteOffset2 > 2147483647) {
735
+ byteOffset2 = 2147483647;
736
+ } else if (byteOffset2 < -2147483648) {
737
+ byteOffset2 = -2147483648;
738
+ }
739
+ byteOffset2 = +byteOffset2;
740
+ if (numberIsNaN(byteOffset2)) {
741
+ byteOffset2 = dir ? 0 : buffer.length - 1;
742
+ }
743
+ if (byteOffset2 < 0) byteOffset2 = buffer.length + byteOffset2;
744
+ if (byteOffset2 >= buffer.length) {
745
745
  if (dir) return -1;
746
- else byteOffset = buffer.length - 1;
747
- } else if (byteOffset < 0) {
748
- if (dir) byteOffset = 0;
746
+ else byteOffset2 = buffer.length - 1;
747
+ } else if (byteOffset2 < 0) {
748
+ if (dir) byteOffset2 = 0;
749
749
  else return -1;
750
750
  }
751
751
  if (typeof val === "string") {
@@ -755,21 +755,21 @@ var require_buffer = __commonJS({
755
755
  if (val.length === 0) {
756
756
  return -1;
757
757
  }
758
- return arrayIndexOf(buffer, val, byteOffset, encoding, dir);
758
+ return arrayIndexOf(buffer, val, byteOffset2, encoding, dir);
759
759
  } else if (typeof val === "number") {
760
760
  val = val & 255;
761
761
  if (typeof Uint8Array.prototype.indexOf === "function") {
762
762
  if (dir) {
763
- return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);
763
+ return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset2);
764
764
  } else {
765
- return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);
765
+ return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset2);
766
766
  }
767
767
  }
768
- return arrayIndexOf(buffer, [val], byteOffset, encoding, dir);
768
+ return arrayIndexOf(buffer, [val], byteOffset2, encoding, dir);
769
769
  }
770
770
  throw new TypeError("val must be string, number or Buffer");
771
771
  }
772
- function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
772
+ function arrayIndexOf(arr, val, byteOffset2, encoding, dir) {
773
773
  let indexSize = 1;
774
774
  let arrLength = arr.length;
775
775
  let valLength = val.length;
@@ -782,7 +782,7 @@ var require_buffer = __commonJS({
782
782
  indexSize = 2;
783
783
  arrLength /= 2;
784
784
  valLength /= 2;
785
- byteOffset /= 2;
785
+ byteOffset2 /= 2;
786
786
  }
787
787
  }
788
788
  function read(buf, i2) {
@@ -795,7 +795,7 @@ var require_buffer = __commonJS({
795
795
  let i;
796
796
  if (dir) {
797
797
  let foundIndex = -1;
798
- for (i = byteOffset; i < arrLength; i++) {
798
+ for (i = byteOffset2; i < arrLength; i++) {
799
799
  if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
800
800
  if (foundIndex === -1) foundIndex = i;
801
801
  if (i - foundIndex + 1 === valLength) return foundIndex * indexSize;
@@ -805,8 +805,8 @@ var require_buffer = __commonJS({
805
805
  }
806
806
  }
807
807
  } else {
808
- if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
809
- for (i = byteOffset; i >= 0; i--) {
808
+ if (byteOffset2 + valLength > arrLength) byteOffset2 = arrLength - valLength;
809
+ for (i = byteOffset2; i >= 0; i--) {
810
810
  let found = true;
811
811
  for (let j = 0; j < valLength; j++) {
812
812
  if (read(arr, i + j) !== read(val, j)) {
@@ -819,14 +819,14 @@ var require_buffer = __commonJS({
819
819
  }
820
820
  return -1;
821
821
  }
822
- Buffer3.prototype.includes = function includes(val, byteOffset, encoding) {
823
- return this.indexOf(val, byteOffset, encoding) !== -1;
822
+ Buffer3.prototype.includes = function includes(val, byteOffset2, encoding) {
823
+ return this.indexOf(val, byteOffset2, encoding) !== -1;
824
824
  };
825
- Buffer3.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
826
- return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
825
+ Buffer3.prototype.indexOf = function indexOf(val, byteOffset2, encoding) {
826
+ return bidirectionalIndexOf(this, val, byteOffset2, encoding, true);
827
827
  };
828
- Buffer3.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
829
- return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
828
+ Buffer3.prototype.lastIndexOf = function lastIndexOf(val, byteOffset2, encoding) {
829
+ return bidirectionalIndexOf(this, val, byteOffset2, encoding, false);
830
830
  };
831
831
  function hexWrite(buf, string, offset, length) {
832
832
  offset = Number(offset) || 0;
@@ -1066,28 +1066,28 @@ var require_buffer = __commonJS({
1066
1066
  if (offset % 1 !== 0 || offset < 0) throw new RangeError("offset is not uint");
1067
1067
  if (offset + ext > length) throw new RangeError("Trying to access beyond buffer length");
1068
1068
  }
1069
- Buffer3.prototype.readUintLE = Buffer3.prototype.readUIntLE = function readUIntLE(offset, byteLength2, noAssert) {
1069
+ Buffer3.prototype.readUintLE = Buffer3.prototype.readUIntLE = function readUIntLE(offset, byteLength3, noAssert) {
1070
1070
  offset = offset >>> 0;
1071
- byteLength2 = byteLength2 >>> 0;
1072
- if (!noAssert) checkOffset(offset, byteLength2, this.length);
1071
+ byteLength3 = byteLength3 >>> 0;
1072
+ if (!noAssert) checkOffset(offset, byteLength3, this.length);
1073
1073
  let val = this[offset];
1074
1074
  let mul = 1;
1075
1075
  let i = 0;
1076
- while (++i < byteLength2 && (mul *= 256)) {
1076
+ while (++i < byteLength3 && (mul *= 256)) {
1077
1077
  val += this[offset + i] * mul;
1078
1078
  }
1079
1079
  return val;
1080
1080
  };
1081
- Buffer3.prototype.readUintBE = Buffer3.prototype.readUIntBE = function readUIntBE(offset, byteLength2, noAssert) {
1081
+ Buffer3.prototype.readUintBE = Buffer3.prototype.readUIntBE = function readUIntBE(offset, byteLength3, noAssert) {
1082
1082
  offset = offset >>> 0;
1083
- byteLength2 = byteLength2 >>> 0;
1083
+ byteLength3 = byteLength3 >>> 0;
1084
1084
  if (!noAssert) {
1085
- checkOffset(offset, byteLength2, this.length);
1085
+ checkOffset(offset, byteLength3, this.length);
1086
1086
  }
1087
- let val = this[offset + --byteLength2];
1087
+ let val = this[offset + --byteLength3];
1088
1088
  let mul = 1;
1089
- while (byteLength2 > 0 && (mul *= 256)) {
1090
- val += this[offset + --byteLength2] * mul;
1089
+ while (byteLength3 > 0 && (mul *= 256)) {
1090
+ val += this[offset + --byteLength3] * mul;
1091
1091
  }
1092
1092
  return val;
1093
1093
  };
@@ -1140,32 +1140,32 @@ var require_buffer = __commonJS({
1140
1140
  const lo = this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last;
1141
1141
  return (BigInt(hi) << BigInt(32)) + BigInt(lo);
1142
1142
  });
1143
- Buffer3.prototype.readIntLE = function readIntLE(offset, byteLength2, noAssert) {
1143
+ Buffer3.prototype.readIntLE = function readIntLE(offset, byteLength3, noAssert) {
1144
1144
  offset = offset >>> 0;
1145
- byteLength2 = byteLength2 >>> 0;
1146
- if (!noAssert) checkOffset(offset, byteLength2, this.length);
1145
+ byteLength3 = byteLength3 >>> 0;
1146
+ if (!noAssert) checkOffset(offset, byteLength3, this.length);
1147
1147
  let val = this[offset];
1148
1148
  let mul = 1;
1149
1149
  let i = 0;
1150
- while (++i < byteLength2 && (mul *= 256)) {
1150
+ while (++i < byteLength3 && (mul *= 256)) {
1151
1151
  val += this[offset + i] * mul;
1152
1152
  }
1153
1153
  mul *= 128;
1154
- if (val >= mul) val -= Math.pow(2, 8 * byteLength2);
1154
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength3);
1155
1155
  return val;
1156
1156
  };
1157
- Buffer3.prototype.readIntBE = function readIntBE(offset, byteLength2, noAssert) {
1157
+ Buffer3.prototype.readIntBE = function readIntBE(offset, byteLength3, noAssert) {
1158
1158
  offset = offset >>> 0;
1159
- byteLength2 = byteLength2 >>> 0;
1160
- if (!noAssert) checkOffset(offset, byteLength2, this.length);
1161
- let i = byteLength2;
1159
+ byteLength3 = byteLength3 >>> 0;
1160
+ if (!noAssert) checkOffset(offset, byteLength3, this.length);
1161
+ let i = byteLength3;
1162
1162
  let mul = 1;
1163
1163
  let val = this[offset + --i];
1164
1164
  while (i > 0 && (mul *= 256)) {
1165
1165
  val += this[offset + --i] * mul;
1166
1166
  }
1167
1167
  mul *= 128;
1168
- if (val >= mul) val -= Math.pow(2, 8 * byteLength2);
1168
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength3);
1169
1169
  return val;
1170
1170
  };
1171
1171
  Buffer3.prototype.readInt8 = function readInt8(offset, noAssert) {
@@ -1244,37 +1244,37 @@ var require_buffer = __commonJS({
1244
1244
  if (value2 > max || value2 < min) throw new RangeError('"value" argument is out of bounds');
1245
1245
  if (offset + ext > buf.length) throw new RangeError("Index out of range");
1246
1246
  }
1247
- Buffer3.prototype.writeUintLE = Buffer3.prototype.writeUIntLE = function writeUIntLE(value2, offset, byteLength2, noAssert) {
1247
+ Buffer3.prototype.writeUintLE = Buffer3.prototype.writeUIntLE = function writeUIntLE(value2, offset, byteLength3, noAssert) {
1248
1248
  value2 = +value2;
1249
1249
  offset = offset >>> 0;
1250
- byteLength2 = byteLength2 >>> 0;
1250
+ byteLength3 = byteLength3 >>> 0;
1251
1251
  if (!noAssert) {
1252
- const maxBytes = Math.pow(2, 8 * byteLength2) - 1;
1253
- checkInt(this, value2, offset, byteLength2, maxBytes, 0);
1252
+ const maxBytes = Math.pow(2, 8 * byteLength3) - 1;
1253
+ checkInt(this, value2, offset, byteLength3, maxBytes, 0);
1254
1254
  }
1255
1255
  let mul = 1;
1256
1256
  let i = 0;
1257
1257
  this[offset] = value2 & 255;
1258
- while (++i < byteLength2 && (mul *= 256)) {
1258
+ while (++i < byteLength3 && (mul *= 256)) {
1259
1259
  this[offset + i] = value2 / mul & 255;
1260
1260
  }
1261
- return offset + byteLength2;
1261
+ return offset + byteLength3;
1262
1262
  };
1263
- Buffer3.prototype.writeUintBE = Buffer3.prototype.writeUIntBE = function writeUIntBE(value2, offset, byteLength2, noAssert) {
1263
+ Buffer3.prototype.writeUintBE = Buffer3.prototype.writeUIntBE = function writeUIntBE(value2, offset, byteLength3, noAssert) {
1264
1264
  value2 = +value2;
1265
1265
  offset = offset >>> 0;
1266
- byteLength2 = byteLength2 >>> 0;
1266
+ byteLength3 = byteLength3 >>> 0;
1267
1267
  if (!noAssert) {
1268
- const maxBytes = Math.pow(2, 8 * byteLength2) - 1;
1269
- checkInt(this, value2, offset, byteLength2, maxBytes, 0);
1268
+ const maxBytes = Math.pow(2, 8 * byteLength3) - 1;
1269
+ checkInt(this, value2, offset, byteLength3, maxBytes, 0);
1270
1270
  }
1271
- let i = byteLength2 - 1;
1271
+ let i = byteLength3 - 1;
1272
1272
  let mul = 1;
1273
1273
  this[offset + i] = value2 & 255;
1274
1274
  while (--i >= 0 && (mul *= 256)) {
1275
1275
  this[offset + i] = value2 / mul & 255;
1276
1276
  }
1277
- return offset + byteLength2;
1277
+ return offset + byteLength3;
1278
1278
  };
1279
1279
  Buffer3.prototype.writeUint8 = Buffer3.prototype.writeUInt8 = function writeUInt8(value2, offset, noAssert) {
1280
1280
  value2 = +value2;
@@ -1365,33 +1365,33 @@ var require_buffer = __commonJS({
1365
1365
  Buffer3.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE(value2, offset = 0) {
1366
1366
  return wrtBigUInt64BE(this, value2, offset, BigInt(0), BigInt("0xffffffffffffffff"));
1367
1367
  });
1368
- Buffer3.prototype.writeIntLE = function writeIntLE(value2, offset, byteLength2, noAssert) {
1368
+ Buffer3.prototype.writeIntLE = function writeIntLE(value2, offset, byteLength3, noAssert) {
1369
1369
  value2 = +value2;
1370
1370
  offset = offset >>> 0;
1371
1371
  if (!noAssert) {
1372
- const limit = Math.pow(2, 8 * byteLength2 - 1);
1373
- checkInt(this, value2, offset, byteLength2, limit - 1, -limit);
1372
+ const limit = Math.pow(2, 8 * byteLength3 - 1);
1373
+ checkInt(this, value2, offset, byteLength3, limit - 1, -limit);
1374
1374
  }
1375
1375
  let i = 0;
1376
1376
  let mul = 1;
1377
1377
  let sub = 0;
1378
1378
  this[offset] = value2 & 255;
1379
- while (++i < byteLength2 && (mul *= 256)) {
1379
+ while (++i < byteLength3 && (mul *= 256)) {
1380
1380
  if (value2 < 0 && sub === 0 && this[offset + i - 1] !== 0) {
1381
1381
  sub = 1;
1382
1382
  }
1383
1383
  this[offset + i] = (value2 / mul >> 0) - sub & 255;
1384
1384
  }
1385
- return offset + byteLength2;
1385
+ return offset + byteLength3;
1386
1386
  };
1387
- Buffer3.prototype.writeIntBE = function writeIntBE(value2, offset, byteLength2, noAssert) {
1387
+ Buffer3.prototype.writeIntBE = function writeIntBE(value2, offset, byteLength3, noAssert) {
1388
1388
  value2 = +value2;
1389
1389
  offset = offset >>> 0;
1390
1390
  if (!noAssert) {
1391
- const limit = Math.pow(2, 8 * byteLength2 - 1);
1392
- checkInt(this, value2, offset, byteLength2, limit - 1, -limit);
1391
+ const limit = Math.pow(2, 8 * byteLength3 - 1);
1392
+ checkInt(this, value2, offset, byteLength3, limit - 1, -limit);
1393
1393
  }
1394
- let i = byteLength2 - 1;
1394
+ let i = byteLength3 - 1;
1395
1395
  let mul = 1;
1396
1396
  let sub = 0;
1397
1397
  this[offset + i] = value2 & 255;
@@ -1401,7 +1401,7 @@ var require_buffer = __commonJS({
1401
1401
  }
1402
1402
  this[offset + i] = (value2 / mul >> 0) - sub & 255;
1403
1403
  }
1404
- return offset + byteLength2;
1404
+ return offset + byteLength3;
1405
1405
  };
1406
1406
  Buffer3.prototype.writeInt8 = function writeInt8(value2, offset, noAssert) {
1407
1407
  value2 = +value2;
@@ -1646,28 +1646,28 @@ var require_buffer = __commonJS({
1646
1646
  }
1647
1647
  return `${val.slice(0, i)}${res}`;
1648
1648
  }
1649
- function checkBounds(buf, offset, byteLength2) {
1649
+ function checkBounds(buf, offset, byteLength3) {
1650
1650
  validateNumber(offset, "offset");
1651
- if (buf[offset] === void 0 || buf[offset + byteLength2] === void 0) {
1652
- boundsError(offset, buf.length - (byteLength2 + 1));
1651
+ if (buf[offset] === void 0 || buf[offset + byteLength3] === void 0) {
1652
+ boundsError(offset, buf.length - (byteLength3 + 1));
1653
1653
  }
1654
1654
  }
1655
- function checkIntBI(value2, min, max, buf, offset, byteLength2) {
1655
+ function checkIntBI(value2, min, max, buf, offset, byteLength3) {
1656
1656
  if (value2 > max || value2 < min) {
1657
1657
  const n = typeof min === "bigint" ? "n" : "";
1658
1658
  let range;
1659
- if (byteLength2 > 3) {
1659
+ if (byteLength3 > 3) {
1660
1660
  if (min === 0 || min === BigInt(0)) {
1661
- range = `>= 0${n} and < 2${n} ** ${(byteLength2 + 1) * 8}${n}`;
1661
+ range = `>= 0${n} and < 2${n} ** ${(byteLength3 + 1) * 8}${n}`;
1662
1662
  } else {
1663
- range = `>= -(2${n} ** ${(byteLength2 + 1) * 8 - 1}${n}) and < 2 ** ${(byteLength2 + 1) * 8 - 1}${n}`;
1663
+ range = `>= -(2${n} ** ${(byteLength3 + 1) * 8 - 1}${n}) and < 2 ** ${(byteLength3 + 1) * 8 - 1}${n}`;
1664
1664
  }
1665
1665
  } else {
1666
1666
  range = `>= ${min}${n} and <= ${max}${n}`;
1667
1667
  }
1668
1668
  throw new errors.ERR_OUT_OF_RANGE("value", range, value2);
1669
1669
  }
1670
- checkBounds(buf, offset, byteLength2);
1670
+ checkBounds(buf, offset, byteLength3);
1671
1671
  }
1672
1672
  function validateNumber(value2, name2) {
1673
1673
  if (typeof value2 !== "number") {
@@ -2179,18 +2179,18 @@ var CommandRegistry = class {
2179
2179
  constructor(commands = []) {
2180
2180
  for (const command2 of commands) this.register(command2);
2181
2181
  }
2182
- register(command2, options2 = {}) {
2183
- const { name: name2, execute: execute2 } = command2;
2182
+ register(command2, options3 = {}) {
2183
+ const { name: name2, execute: execute3 } = command2;
2184
2184
  if (typeof name2 !== "string" || !name2 || /[\s/\0]/u.test(name2)) {
2185
2185
  throw new TypeError("Command names must be nonempty and contain no whitespace, slash, or NUL");
2186
2186
  }
2187
- if (typeof execute2 !== "function") {
2187
+ if (typeof execute3 !== "function") {
2188
2188
  throw new TypeError("Command execute must be a function");
2189
2189
  }
2190
- if (this.#commands.has(name2) && !options2.replace) {
2190
+ if (this.#commands.has(name2) && !options3.replace) {
2191
2191
  throw new Error(`Command already registered: ${name2}`);
2192
2192
  }
2193
- this.#commands.set(name2, Object.freeze({ ...command2, name: name2, execute: execute2 }));
2193
+ this.#commands.set(name2, Object.freeze({ ...command2, name: name2, execute: execute3 }));
2194
2194
  return this;
2195
2195
  }
2196
2196
  get(name2) {
@@ -2273,9 +2273,9 @@ init_platform();
2273
2273
  import { collectBytes, readBytes } from "@poe-platform/safe-fs/core";
2274
2274
  import { collectBytes as collectBytes2, readBytes as readBytes2, toByteSource } from "@poe-platform/safe-fs/core";
2275
2275
  var outputFailure = /* @__PURE__ */ Symbol("output failure");
2276
- function createBytePipe(options2 = {}) {
2277
- const highWaterMark = options2.highWaterMark ?? 64 * 1024;
2278
- const signal = options2.signal;
2276
+ function createBytePipe(options3 = {}) {
2277
+ const highWaterMark = options3.highWaterMark ?? 64 * 1024;
2278
+ const signal = options3.signal;
2279
2279
  if (!Number.isSafeInteger(highWaterMark) || highWaterMark < 1) {
2280
2280
  throw new RangeError("highWaterMark must be a positive safe integer");
2281
2281
  }
@@ -2390,8 +2390,8 @@ async function pipeBytes(source, sink, signal) {
2390
2390
  }
2391
2391
  signal?.throwIfAborted();
2392
2392
  }
2393
- async function collectText(source, options2) {
2394
- return new TextDecoder().decode(await collectBytes(source, options2));
2393
+ async function collectText(source, options3) {
2394
+ return new TextDecoder().decode(await collectBytes(source, options3));
2395
2395
  }
2396
2396
  async function abortable(operation, signal) {
2397
2397
  signal?.throwIfAborted();
@@ -2796,17 +2796,6 @@ function concatenate(chunks, size = chunks.reduce((sum, chunk) => sum + chunk.le
2796
2796
  }
2797
2797
  return result;
2798
2798
  }
2799
- async function collect(source, signal, limit = bufferLimit) {
2800
- const chunks = [];
2801
- let size = 0;
2802
- for await (const chunk of source) {
2803
- signal.throwIfAborted();
2804
- size += chunk.length;
2805
- if (size > limit) throw new FsError("EFBIG", { message: `buffer limit exceeded (${limit} bytes)` });
2806
- chunks.push(new Uint8Array(chunk));
2807
- }
2808
- return concatenate(chunks, size);
2809
- }
2810
2799
  async function* lines(source, separator = 10) {
2811
2800
  let pending = [];
2812
2801
  let size = 0;
@@ -3128,23 +3117,23 @@ function compareCopyIdentity(left, right) {
3128
3117
  if (!left || !right || !complete(left) || !complete(right)) return "unknown";
3129
3118
  return left.identityScope === right.identityScope && left.dev === right.dev && left.ino === right.ino ? "same" : "distinct";
3130
3119
  }
3131
- async function compareObservedEntries(fs, path, stat, peer, peerPath, peerStat, options2 = {}) {
3132
- options2.signal?.throwIfAborted();
3120
+ async function compareObservedEntries(fs, path, stat, peer, peerPath, peerStat, options3 = {}) {
3121
+ options3.signal?.throwIfAborted();
3133
3122
  const identity = compareCopyIdentity(stat, peerStat);
3134
3123
  if (identity !== "unknown") return identity;
3135
3124
  let result = "unknown";
3136
3125
  const operands = fs === peer ? [[fs, path, peer, peerPath]] : [[fs, path, peer, peerPath], [peer, peerPath, fs, path]];
3137
3126
  for (const [owner, ownPath, other, otherPath] of operands) {
3138
- options2.signal?.throwIfAborted();
3127
+ options3.signal?.throwIfAborted();
3139
3128
  if (!owner.compareEntry) continue;
3140
3129
  let answer;
3141
3130
  try {
3142
- answer = await owner.compareEntry(ownPath, other, otherPath, options2);
3131
+ answer = await owner.compareEntry(ownPath, other, otherPath, options3);
3143
3132
  } catch (error) {
3144
- options2.signal?.throwIfAborted();
3133
+ options3.signal?.throwIfAborted();
3145
3134
  throw error;
3146
3135
  }
3147
- options2.signal?.throwIfAborted();
3136
+ options3.signal?.throwIfAborted();
3148
3137
  if (answer !== "same" && answer !== "distinct" && answer !== "unknown") {
3149
3138
  throw new FsError("EIO", { path, dest: peerPath, message: "invalid entry comparison answer" });
3150
3139
  }
@@ -4772,15 +4761,15 @@ function textCommands() {
4772
4761
  if (numericKey && numericKeyFlags.has("n") && !["b", "f"].some((flag) => numericKeyFlags.has(flag)) && !parsed.flags.has("c")) {
4773
4762
  const keyedNumericValues = /* @__PURE__ */ new Map();
4774
4763
  let retainedKeyBytes = 0;
4775
- const keyedNumericValue = (record3) => {
4776
- const cached = keyedNumericValues.get(record3);
4764
+ const keyedNumericValue = (record4) => {
4765
+ const cached = keyedNumericValues.get(record4);
4777
4766
  if (cached !== void 0) return cached;
4778
4767
  context.signal.throwIfAborted();
4779
- const bytes2 = keyBytes(record3, numericKey, separator, false);
4768
+ const bytes2 = keyBytes(record4, numericKey, separator, false);
4780
4769
  const charge2 = 6 * bytes2.length + 2;
4781
4770
  if (keyedNumericValues.size >= 16384 || charge2 > 1048576 - retainedKeyBytes) return parseNumeric(bytes2);
4782
4771
  const parsedValue = parseNumeric(bytes2);
4783
- keyedNumericValues.set(record3, parsedValue);
4772
+ keyedNumericValues.set(record4, parsedValue);
4784
4773
  retainedKeyBytes += charge2;
4785
4774
  return parsedValue;
4786
4775
  };
@@ -4826,13 +4815,13 @@ function textCommands() {
4826
4815
  let previous;
4827
4816
  let buffer = new Uint8Array(64 * 1024);
4828
4817
  let used = 0;
4829
- for (const record3 of records) {
4818
+ for (const record4 of records) {
4830
4819
  context.signal.throwIfAborted();
4831
- if (parsed.flags.has("u") && previous !== void 0 && keyCompare(previous, record3) === 0) continue;
4820
+ if (parsed.flags.has("u") && previous !== void 0 && keyCompare(previous, record4) === 0) continue;
4832
4821
  let offset = 0;
4833
- while (offset < record3.length) {
4834
- const length = Math.min(record3.length - offset, buffer.length - used);
4835
- buffer.set(record3.subarray(offset, offset + length), used);
4822
+ while (offset < record4.length) {
4823
+ const length = Math.min(record4.length - offset, buffer.length - used);
4824
+ buffer.set(record4.subarray(offset, offset + length), used);
4836
4825
  offset += length;
4837
4826
  used += length;
4838
4827
  if (used === buffer.length) {
@@ -4847,7 +4836,7 @@ function textCommands() {
4847
4836
  buffer = new Uint8Array(64 * 1024);
4848
4837
  used = 0;
4849
4838
  }
4850
- previous = record3;
4839
+ previous = record4;
4851
4840
  }
4852
4841
  if (used) yield buffer.subarray(0, used);
4853
4842
  })();
@@ -4878,19 +4867,19 @@ function textCommands() {
4878
4867
  let previousKey;
4879
4868
  let count2 = 0;
4880
4869
  const selected = () => (!parsed.flags.has("d") || count2 > 1) && (!parsed.flags.has("u") || count2 === 1);
4881
- const record3 = () => concatenate([...parsed.flags.has("c") ? [encoder2.encode(`${String(count2).padStart(7)} `)] : [], previous, Uint8Array.of(delimiter)]);
4870
+ const record4 = () => concatenate([...parsed.flags.has("c") ? [encoder2.encode(`${String(count2).padStart(7)} `)] : [], previous, Uint8Array.of(delimiter)]);
4882
4871
  for await (const line of lines(input(context, parsed.operands[0]), delimiter)) {
4883
4872
  context.signal.throwIfAborted();
4884
4873
  const currentKey = key(line.bytes);
4885
4874
  if (previousKey && compareBytes(previousKey, currentKey) === 0) count2++;
4886
4875
  else {
4887
- if (previous !== void 0 && selected()) yield record3();
4876
+ if (previous !== void 0 && selected()) yield record4();
4888
4877
  previous = line.bytes;
4889
4878
  previousKey = currentKey;
4890
4879
  count2 = 1;
4891
4880
  }
4892
4881
  }
4893
- if (previous !== void 0 && selected()) yield record3();
4882
+ if (previous !== void 0 && selected()) yield record4();
4894
4883
  })();
4895
4884
  if (parsed.operands[1] !== void 0 && parsed.operands[0] !== "-" && pathOf(context, parsed.operands[0]) === pathOf(context, parsed.operands[1])) throw new UsageError("input and output must be different files");
4896
4885
  await emitRecords(context, records, parsed.operands[1]);
@@ -4923,9 +4912,9 @@ function textCommands() {
4923
4912
  context.signal.throwIfAborted();
4924
4913
  let bytes2;
4925
4914
  if (mode === "f") {
4926
- const record3 = import_buffer.Buffer.from(line.bytes.buffer, line.bytes.byteOffset, line.bytes.byteLength);
4915
+ const record4 = import_buffer.Buffer.from(line.bytes.buffer, line.bytes.byteOffset, line.bytes.byteLength);
4927
4916
  const separator = import_buffer.Buffer.from(delimiter);
4928
- let boundary = record3.indexOf(separator);
4917
+ let boundary = record4.indexOf(separator);
4929
4918
  if (boundary < 0) {
4930
4919
  if (parsed.flags.has("s")) continue;
4931
4920
  bytes2 = line.bytes;
@@ -4938,12 +4927,12 @@ function textCommands() {
4938
4927
  while (true) {
4939
4928
  if (selected(field++)) {
4940
4929
  if (emitted) pieces.push(joiner);
4941
- pieces.push(record3.subarray(start, boundary < 0 ? record3.length : boundary));
4930
+ pieces.push(record4.subarray(start, boundary < 0 ? record4.length : boundary));
4942
4931
  emitted = true;
4943
4932
  }
4944
4933
  if (boundary < 0) break;
4945
4934
  start = boundary + separator.length;
4946
- boundary = record3.indexOf(separator, start);
4935
+ boundary = record4.indexOf(separator, start);
4947
4936
  }
4948
4937
  bytes2 = concatenate(pieces);
4949
4938
  }
@@ -6327,7 +6316,7 @@ var Parser = class {
6327
6316
  this.advance();
6328
6317
  let nodes = 0;
6329
6318
  const grouped = /* @__PURE__ */ new WeakSet();
6330
- const admit = () => {
6319
+ const admit2 = () => {
6331
6320
  if (nodes >= 4096) this.error("Conditional syntax exceeds 4096 nodes");
6332
6321
  nodes++;
6333
6322
  };
@@ -6338,7 +6327,7 @@ var Parser = class {
6338
6327
  const primary = (depth) => {
6339
6328
  if (depth > 64) this.error("Conditional syntax nesting exceeds 64");
6340
6329
  if (this.is("!")) {
6341
- admit();
6330
+ admit2();
6342
6331
  this.advance();
6343
6332
  const expression2 = primary(depth + 1);
6344
6333
  return expression2.kind === "not" && !grouped.has(expression2) ? expression2.operand : { kind: "not", operand: expression2 };
@@ -6350,7 +6339,7 @@ var Parser = class {
6350
6339
  grouped.add(expression2);
6351
6340
  return expression2;
6352
6341
  }
6353
- admit();
6342
+ admit2();
6354
6343
  const first = operand();
6355
6344
  if (conditionalBinary.has(this.current.value)) {
6356
6345
  const operator = this.current.value;
@@ -6365,7 +6354,7 @@ var Parser = class {
6365
6354
  const conjunction = (depth) => {
6366
6355
  let expression2 = primary(depth);
6367
6356
  while (this.is("&&")) {
6368
- admit();
6357
+ admit2();
6369
6358
  this.advance();
6370
6359
  expression2 = { kind: "and", left: expression2, right: primary(depth) };
6371
6360
  }
@@ -6374,7 +6363,7 @@ var Parser = class {
6374
6363
  const disjunction = (depth) => {
6375
6364
  let expression2 = conjunction(depth);
6376
6365
  while (this.is("||")) {
6377
- admit();
6366
+ admit2();
6378
6367
  this.advance();
6379
6368
  expression2 = { kind: "or", left: expression2, right: conjunction(depth) };
6380
6369
  }
@@ -6539,18 +6528,18 @@ var Parser = class {
6539
6528
  return script;
6540
6529
  }
6541
6530
  redirect() {
6542
- let descriptor;
6531
+ let descriptor2;
6543
6532
  if (this.current.kind === "word" && /^\d+$/u.test(this.current.value)) {
6544
6533
  const next = this.peek();
6545
- if (/^(?:>|>>|<|<<|<<-|<<<|>&|<&|>\|)$/u.test(next.value) && this.current.end === next.offset) descriptor = Number(this.advance().value);
6534
+ if (/^(?:>|>>|<|<<|<<-|<<<|>&|<&|>\|)$/u.test(next.value) && this.current.end === next.offset) descriptor2 = Number(this.advance().value);
6546
6535
  }
6547
6536
  if (!/^(?:>|>>|<|<<|<<-|<<<|>&|<&|>\||&>)$/u.test(this.current.value) || this.current.kind !== "operator") return void 0;
6548
6537
  const operator = this.advance().value;
6549
- descriptor ??= operator.startsWith("<") ? 0 : 1;
6550
- if (!Number.isSafeInteger(descriptor) || descriptor > 255) this.error("File descriptor must be between 0 and 255");
6538
+ descriptor2 ??= operator.startsWith("<") ? 0 : 1;
6539
+ if (!Number.isSafeInteger(descriptor2) || descriptor2 > 255) this.error("File descriptor must be between 0 and 255");
6551
6540
  if (!this.current.word) this.error("Expected redirect target");
6552
6541
  const target = this.advance();
6553
- return { descriptor, operator, target: target.word, line: this.lexer.lineAt(Math.max(target.offset, target.end - 1)), ...(operator === "<&" || operator === ">&") && this.lexer.source[target.end - 1] === "-" ? { move: true } : {}, ...target.document ? { document: target.document } : {} };
6542
+ return { descriptor: descriptor2, operator, target: target.word, line: this.lexer.lineAt(Math.max(target.offset, target.end - 1)), ...(operator === "<&" || operator === ">&") && this.lexer.source[target.end - 1] === "-" ? { move: true } : {}, ...target.document ? { document: target.document } : {} };
6554
6543
  }
6555
6544
  };
6556
6545
  function parseShell(source, depth = 0) {
@@ -6599,13 +6588,13 @@ init_platform();
6599
6588
  // packages/safe-bash/src/shell/value-state.ts
6600
6589
  init_platform();
6601
6590
  var ValueArena = class {
6602
- constructor(maximumBytes, maximumSlots, checkpoint, fail = (limit) => {
6591
+ constructor(maximumBytes, maximumSlots, checkpoint, fail2 = (limit) => {
6603
6592
  throw new ShellLimitError(limit);
6604
6593
  }) {
6605
6594
  this.maximumBytes = maximumBytes;
6606
6595
  this.maximumSlots = maximumSlots;
6607
6596
  this.checkpoint = checkpoint;
6608
- this.fail = fail;
6597
+ this.fail = fail2;
6609
6598
  }
6610
6599
  maximumBytes;
6611
6600
  maximumSlots;
@@ -6635,25 +6624,25 @@ var ValueArena = class {
6635
6624
  if (!Number.isSafeInteger(bytes2) || bytes2 < 0 || !Number.isSafeInteger(slots) || slots < 0) throw new RangeError("Invalid shell value allocation");
6636
6625
  if (bytes2 > this.maximumBytes - this.#bytes) this.fail("maxExpansionBytes");
6637
6626
  if (slots > this.maximumSlots - this.#slots) this.fail("maxExpansionFields");
6638
- const record3 = { bytes: bytes2, slots, references: 1 };
6627
+ const record4 = { bytes: bytes2, slots, references: 1 };
6639
6628
  this.#bytes += bytes2;
6640
6629
  this.#slots += slots;
6641
- this.#records.add(record3);
6642
- return record3;
6630
+ this.#records.add(record4);
6631
+ return record4;
6643
6632
  }
6644
- commit(record3, object) {
6633
+ commit(record4, object) {
6645
6634
  this.assertOpen();
6646
- if (!this.#records.has(record3) || record3.object || this.#objects.has(object)) throw new Error("Shell value reservation is not fresh");
6647
- record3.object = object;
6648
- this.#objects.set(object, record3);
6649
- }
6650
- release(record3) {
6651
- if (!this.#records.has(record3)) return;
6652
- if (--record3.references) return;
6653
- this.#records.delete(record3);
6654
- if (record3.object) this.#objects.delete(record3.object);
6655
- this.#bytes -= record3.bytes;
6656
- this.#slots -= record3.slots;
6635
+ if (!this.#records.has(record4) || record4.object || this.#objects.has(object)) throw new Error("Shell value reservation is not fresh");
6636
+ record4.object = object;
6637
+ this.#objects.set(object, record4);
6638
+ }
6639
+ release(record4) {
6640
+ if (!this.#records.has(record4)) return;
6641
+ if (--record4.references) return;
6642
+ this.#records.delete(record4);
6643
+ if (record4.object) this.#objects.delete(record4.object);
6644
+ this.#bytes -= record4.bytes;
6645
+ this.#slots -= record4.slots;
6657
6646
  }
6658
6647
  hold(value2) {
6659
6648
  this.assertOpen();
@@ -6696,7 +6685,7 @@ var ValueArena = class {
6696
6685
  }
6697
6686
  close() {
6698
6687
  this.#closed = true;
6699
- for (const record3 of this.#records) if (record3.object) this.#objects.delete(record3.object);
6688
+ for (const record4 of this.#records) if (record4.object) this.#objects.delete(record4.object);
6700
6689
  this.#records.clear();
6701
6690
  this.#bytes = 0;
6702
6691
  this.#slots = 0;
@@ -6718,19 +6707,19 @@ var ValueScope = class {
6718
6707
  reserve(bytes2, slots) {
6719
6708
  this.assertOpen();
6720
6709
  this.#enrollment ??= this.arena.allocate(64, 1);
6721
- const record3 = this.arena.allocate(bytes2, slots);
6710
+ const record4 = this.arena.allocate(bytes2, slots);
6722
6711
  let released = false;
6723
6712
  const release = () => {
6724
6713
  if (released) return;
6725
6714
  released = true;
6726
6715
  this.#releases.delete(release);
6727
- this.arena.release(record3);
6716
+ this.arena.release(record4);
6728
6717
  };
6729
6718
  this.#releases.add(release);
6730
6719
  return { commit: (value2) => {
6731
6720
  this.assertOpen();
6732
6721
  if (released) throw new Error("Shell value reservation is released");
6733
- this.arena.commit(record3, value2);
6722
+ this.arena.commit(record4, value2);
6734
6723
  }, release };
6735
6724
  }
6736
6725
  hold(value2) {
@@ -6898,28 +6887,28 @@ function positionalTemplate(source, checkpoint) {
6898
6887
  }
6899
6888
  return found;
6900
6889
  }
6901
- function positionalValue(name2, options2) {
6890
+ function positionalValue(name2, options3) {
6902
6891
  let index = 0;
6903
6892
  let outside = false;
6904
6893
  for (let position = 0; position < name2.length; position++) {
6905
- if (position % 128 === 0) options2.checkpoint();
6894
+ if (position % 128 === 0) options3.checkpoint();
6906
6895
  const next = name2.charCodeAt(position) - 48;
6907
- if (index > Math.floor((options2.positional.length - next) / 10)) outside = true;
6896
+ if (index > Math.floor((options3.positional.length - next) / 10)) outside = true;
6908
6897
  if (!outside) index = index * 10 + next;
6909
6898
  }
6910
- return outside ? void 0 : index === 0 ? options2.arg0 : options2.positional[index - 1];
6899
+ return outside ? void 0 : index === 0 ? options3.arg0 : options3.positional[index - 1];
6911
6900
  }
6912
- function evaluatePositionalArithmetic(program, options2, evaluate) {
6901
+ function evaluatePositionalArithmetic(program, options3, evaluate) {
6913
6902
  const source = program.source;
6914
6903
  if (!source.includes("$")) return evaluate(program);
6915
- options2.checkpoint();
6916
- if (!positionalTemplate(source, options2.checkpoint)) return evaluate(program);
6917
- const header = options2.owner?.reserve({ metadata: 128, allocatedSlots: 2, work: source.length * 2 + 8 });
6904
+ options3.checkpoint();
6905
+ if (!positionalTemplate(source, options3.checkpoint)) return evaluate(program);
6906
+ const header = options3.owner?.reserve({ metadata: 128, allocatedSlots: 2, work: source.length * 2 + 8 });
6918
6907
  const admissions = [];
6919
6908
  const chunks = [];
6920
6909
  let bytes2 = 0;
6921
6910
  const reserve = (payload) => {
6922
- const admission = options2.owner?.reserve({ payload, metadata: 64, allocatedSlots: 2, work: 4 });
6911
+ const admission = options3.owner?.reserve({ payload, metadata: 64, allocatedSlots: 2, work: 4 });
6923
6912
  if (admission) admissions.push(admission);
6924
6913
  };
6925
6914
  const length = (text, start, end, maximum) => {
@@ -6927,7 +6916,7 @@ function evaluatePositionalArithmetic(program, options2, evaluate) {
6927
6916
  let nextCheckpoint = start;
6928
6917
  for (let position = start; position < end; ) {
6929
6918
  if (position >= nextCheckpoint) {
6930
- options2.checkpoint();
6919
+ options3.checkpoint();
6931
6920
  nextCheckpoint = position + 128;
6932
6921
  }
6933
6922
  const code = text.charCodeAt(position++);
@@ -6937,14 +6926,14 @@ function evaluatePositionalArithmetic(program, options2, evaluate) {
6937
6926
  size += 4;
6938
6927
  position++;
6939
6928
  } else size += 3;
6940
- if (size > maximum) options2.limit();
6929
+ if (size > maximum) options3.limit();
6941
6930
  }
6942
- options2.owner?.reserve({ work: end - start }).release();
6931
+ options3.owner?.reserve({ work: end - start }).release();
6943
6932
  return size;
6944
6933
  };
6945
6934
  const literal = (start, end) => {
6946
6935
  if (start === end) return;
6947
- const size = length(source, start, end, options2.maximumBytes - bytes2);
6936
+ const size = length(source, start, end, options3.maximumBytes - bytes2);
6948
6937
  reserve(size);
6949
6938
  chunks.push(source.slice(start, end));
6950
6939
  bytes2 += size;
@@ -6954,7 +6943,7 @@ function evaluatePositionalArithmetic(program, options2, evaluate) {
6954
6943
  let nextCheckpoint = 0;
6955
6944
  for (let position = 0; position < source.length; ) {
6956
6945
  if (position >= nextCheckpoint) {
6957
- options2.checkpoint();
6946
+ options3.checkpoint();
6958
6947
  nextCheckpoint = position + 128;
6959
6948
  }
6960
6949
  if (source[position] !== "$") {
@@ -6967,17 +6956,17 @@ function evaluatePositionalArithmetic(program, options2, evaluate) {
6967
6956
  let nameEnd = nameStart + 1;
6968
6957
  if (braced) while (digit(source, nameEnd)) {
6969
6958
  if (nameEnd >= nextCheckpoint) {
6970
- options2.checkpoint();
6959
+ options3.checkpoint();
6971
6960
  nextCheckpoint = nameEnd + 128;
6972
6961
  }
6973
6962
  nameEnd++;
6974
6963
  }
6975
6964
  reserve(nameEnd - nameStart);
6976
6965
  const name2 = source.slice(nameStart, nameEnd);
6977
- const value2 = positionalValue(name2, options2);
6978
- options2.requireParameter(name2, value2);
6966
+ const value2 = positionalValue(name2, options3);
6967
+ options3.requireParameter(name2, value2);
6979
6968
  const text = value2 ?? "";
6980
- const size = length(text, 0, text.length, options2.maximumBytes - bytes2);
6969
+ const size = length(text, 0, text.length, options3.maximumBytes - bytes2);
6981
6970
  reserve(size);
6982
6971
  chunks.push(text);
6983
6972
  bytes2 += size;
@@ -6985,10 +6974,10 @@ function evaluatePositionalArithmetic(program, options2, evaluate) {
6985
6974
  start = position;
6986
6975
  }
6987
6976
  literal(start, source.length);
6988
- options2.checkpoint();
6977
+ options3.checkpoint();
6989
6978
  reserve(bytes2);
6990
6979
  const expanded = chunks.join("");
6991
- options2.checkpoint();
6980
+ options3.checkpoint();
6992
6981
  return evaluate(prepareArithmetic(expanded));
6993
6982
  } finally {
6994
6983
  for (let position = admissions.length - 1; position >= 0; position--) admissions[position].release();
@@ -7522,7 +7511,7 @@ async function* argumentsFrom(source, signal, delimiter, replacement = false) {
7522
7511
  if (quote || escaped) throw new UsageError(quote ? "unmatched quote in input" : "trailing backslash in input");
7523
7512
  if (active) yield current;
7524
7513
  }
7525
- function executionCommands(execute2) {
7514
+ function executionCommands(execute3) {
7526
7515
  return [
7527
7516
  define("env", async (context) => {
7528
7517
  const argumentValues = getCommandArguments(context);
@@ -7573,7 +7562,7 @@ function executionCommands(execute2) {
7573
7562
  stderr: context.stderr,
7574
7563
  ...context.stdinIsDefault === void 0 ? {} : { stdinIsDefault: context.stdinIsDefault }
7575
7564
  });
7576
- return execute2({ ...context, command: parsed.operands[offset], args: childArguments.args, argumentValues: childArguments, env: childEnv, cwd });
7565
+ return execute3({ ...context, command: parsed.operands[offset], args: childArguments.args, argumentValues: childArguments, env: childEnv, cwd });
7577
7566
  }
7578
7567
  for (const name2 of names) await output(context, `${name2}=${env[name2]}${parsed.flags.has("0") ? "\0" : "\n"}`);
7579
7568
  return { exitCode: 0 };
@@ -7613,7 +7602,7 @@ function executionCommands(execute2) {
7613
7602
  const size = encoder2.encode(command2).length + 1 + childArguments.values.reduce((sum, argument) => sum + shellValueByteLength(argument) + 1, 0);
7614
7603
  if (size > maxBytes) throw new UsageError("expanded arguments exceed command size limit");
7615
7604
  if (parsed.flags.has("t")) await writeBytes(context.stderr, encoder2.encode([command2, ...args].map((argument) => /^[A-Za-z0-9_./-]+$/u.test(argument) ? argument : `'${argument.replaceAll("'", "'\\''")}'`).join(" ") + "\n"), context.signal);
7616
- const result = await execute2({ ...context, command: command2, args, argumentValues: childArguments, stdin: emptyInput(), stdinIsDefault: true, env: { ...context.env } });
7605
+ const result = await execute3({ ...context, command: command2, args, argumentValues: childArguments, stdin: emptyInput(), stdinIsDefault: true, env: { ...context.env } });
7617
7606
  executed = true;
7618
7607
  if (result.exitCode === 255) {
7619
7608
  status = 124;
@@ -7770,9 +7759,9 @@ async function validateString(value2, work, optstring = false) {
7770
7759
  else work.addBytes(3);
7771
7760
  }
7772
7761
  }
7773
- async function scanGetopts(state, optstring, args, options2) {
7774
- if (!record2(options2) || typeof options2.reportErrors !== "boolean") throw new GetoptsError("INVALID_INPUT", "Getopts requires explicit diagnostic policy and work controls");
7775
- const work = new ScanWork(options2.work);
7762
+ async function scanGetopts(state, optstring, args, options3) {
7763
+ if (!record2(options3) || typeof options3.reportErrors !== "boolean") throw new GetoptsError("INVALID_INPUT", "Getopts requires explicit diagnostic policy and work controls");
7764
+ const work = new ScanWork(options3.work);
7776
7765
  const original = cloneGetoptsState(state);
7777
7766
  if (!Array.isArray(args)) throw new GetoptsError("INVALID_INPUT", "Getopts requires an argument array");
7778
7767
  if (args.length > work.maxArguments) throw new GetoptsError("ARGUMENT_LIMIT", "Getopts argument limit exceeded");
@@ -7827,7 +7816,7 @@ async function scanGetopts(state, optstring, args, options2) {
7827
7816
  active = attached ? { argument: active.argument, offset } : void 0;
7828
7817
  if (!attached) index++;
7829
7818
  if (specification[code] === -1) {
7830
- return finish("unknown-option", "?", silent ? { kind: "set", value: option } : { kind: "unset" }, !silent && options2.reportErrors ? { kind: "unknown-option", option } : null);
7819
+ return finish("unknown-option", "?", silent ? { kind: "set", value: option } : { kind: "unset" }, !silent && options3.reportErrors ? { kind: "unknown-option", option } : null);
7831
7820
  }
7832
7821
  if (specification[code] === 1) {
7833
7822
  if (attached) {
@@ -7840,7 +7829,7 @@ async function scanGetopts(state, optstring, args, options2) {
7840
7829
  index++;
7841
7830
  return finish("option", option, { kind: "set", value: value2 }, null);
7842
7831
  }
7843
- return finish("missing-argument", silent ? ":" : "?", silent ? { kind: "set", value: option } : { kind: "unset" }, !silent && options2.reportErrors ? { kind: "missing-argument", option } : null);
7832
+ return finish("missing-argument", silent ? ":" : "?", silent ? { kind: "set", value: option } : { kind: "unset" }, !silent && options3.reportErrors ? { kind: "missing-argument", option } : null);
7844
7833
  }
7845
7834
  return finish("option", option, { kind: "unset" }, null);
7846
7835
  }
@@ -8179,17 +8168,17 @@ function throwLocalActivationFailure(state) {
8179
8168
  const failure = localActivationFailure(state);
8180
8169
  if (failure.failed) throw failure.reason;
8181
8170
  }
8182
- function prepareChildCancellation(parent, options2, snapshot, controls) {
8171
+ function prepareChildCancellation(parent, options3, snapshot, controls) {
8183
8172
  const parentState = requireLink(parent);
8184
8173
  throwAdmissionFailure(parentState);
8185
8174
  let localSignal;
8186
- if (options2 !== void 0) {
8187
- if (options2 === null || typeof options2 !== "object" && typeof options2 !== "function") {
8175
+ if (options3 !== void 0) {
8176
+ if (options3 === null || typeof options3 !== "object" && typeof options3 !== "function") {
8188
8177
  return stagedFailure(parentState, new TypeError("Cancellation options must be an object or function"));
8189
8178
  }
8190
8179
  let candidate;
8191
8180
  try {
8192
- candidate = options2.signal;
8181
+ candidate = options3.signal;
8193
8182
  } catch (error) {
8194
8183
  return stagedFailure(parentState, error);
8195
8184
  }
@@ -9154,10 +9143,10 @@ var StateMonitor = class {
9154
9143
  monitor.finish(tickets, name2);
9155
9144
  return result;
9156
9145
  },
9157
- defineProperty(target, key, descriptor) {
9146
+ defineProperty(target, key, descriptor2) {
9158
9147
  const name2 = named ? String(key) : void 0;
9159
9148
  const tickets = monitor.mutation(name2);
9160
- const result = Reflect.defineProperty(target, key, descriptor);
9149
+ const result = Reflect.defineProperty(target, key, descriptor2);
9161
9150
  if (result) monitor.changedValue(target, field, key);
9162
9151
  monitor.finish(tickets, name2);
9163
9152
  return result;
@@ -10183,7 +10172,7 @@ var typedSavedVariables = /* @__PURE__ */ new WeakMap();
10183
10172
  var valueScope = /* @__PURE__ */ Symbol("shell value allocation scope");
10184
10173
  var invokedValues = /* @__PURE__ */ new WeakMap();
10185
10174
  function isolateIO(io) {
10186
- return { ...io, ...io.descriptors ? { descriptors: new Map([...io.descriptors].map(([number, descriptor]) => [number, { ...descriptor }])) } : {} };
10175
+ return { ...io, ...io.descriptors ? { descriptors: new Map([...io.descriptors].map(([number, descriptor2]) => [number, { ...descriptor2 }])) } : {} };
10187
10176
  }
10188
10177
  function activeIO(io) {
10189
10178
  const input3 = io.descriptors?.get(0);
@@ -10661,11 +10650,11 @@ var DirectoryStackWork = class {
10661
10650
  await writeText(this.stdout, text);
10662
10651
  this.signal.throwIfAborted();
10663
10652
  }
10664
- async display(cwd, entries, options2, home) {
10653
+ async display(cwd, entries, options3, home) {
10665
10654
  await this.scan(cwd, "path");
10666
- const homeBytes = !options2.long && home !== void 0 ? await this.scan(home, "HOME") : 0;
10667
- const start = options2.index ?? 0;
10668
- const end = options2.index ?? entries.length;
10655
+ const homeBytes = !options3.long && home !== void 0 ? await this.scan(home, "HOME") : 0;
10656
+ const start = options3.index ?? 0;
10657
+ const end = options3.index ?? entries.length;
10669
10658
  for (let index = start; index <= end; index++) {
10670
10659
  await this.charge(1);
10671
10660
  let entry = index === 0 ? cwd : entries[index - 1];
@@ -10683,12 +10672,12 @@ var DirectoryStackWork = class {
10683
10672
  if (entry.length === home.length || entry[home.length] === "/") entry = `~${entry.slice(home.length)}`;
10684
10673
  }
10685
10674
  }
10686
- if (index !== start && !options2.lines && !options2.verbose) await this.emit(" ");
10687
- if (options2.verbose) await this.emit(`${String(index).padStart(2, " ")} `);
10675
+ if (index !== start && !options3.lines && !options3.verbose) await this.emit(" ");
10676
+ if (options3.verbose) await this.emit(`${String(index).padStart(2, " ")} `);
10688
10677
  await this.emit(entry);
10689
- if (options2.lines || options2.verbose) await this.emit("\n");
10678
+ if (options3.lines || options3.verbose) await this.emit("\n");
10690
10679
  }
10691
- if (!options2.lines && !options2.verbose) await this.emit("\n");
10680
+ if (!options3.lines && !options3.verbose) await this.emit("\n");
10692
10681
  await this.flushOutput();
10693
10682
  }
10694
10683
  };
@@ -10746,34 +10735,34 @@ var RuntimeCancellationState = class {
10746
10735
  }
10747
10736
  bind(promise, boundary) {
10748
10737
  if (this.#closed) throw new Error("Cancellation outcome admission is closed");
10749
- const record3 = { promise, boundary, finalized: false, consumed: false };
10750
- this.#records.add(record3);
10751
- return record3;
10738
+ const record4 = { promise, boundary, finalized: false, consumed: false };
10739
+ this.#records.add(record4);
10740
+ return record4;
10752
10741
  }
10753
- finalize(record3, selection) {
10754
- if (record3.consumed || !this.#records.has(record3)) return;
10755
- record3.selection = selection;
10756
- record3.finalized = true;
10742
+ finalize(record4, selection) {
10743
+ if (record4.consumed || !this.#records.has(record4)) return;
10744
+ record4.selection = selection;
10745
+ record4.finalized = true;
10757
10746
  }
10758
10747
  consume(rawReturn, capturedReason) {
10759
- for (const record3 of this.#records) {
10760
- if (record3.promise !== rawReturn) continue;
10761
- record3.consumed = true;
10762
- this.#records.delete(record3);
10763
- const selection = record3.selection;
10764
- if (!record3.finalized || selection?.outcome.kind !== "throw" || !Object.is(selection.outcome.reason, capturedReason)) return void 0;
10748
+ for (const record4 of this.#records) {
10749
+ if (record4.promise !== rawReturn) continue;
10750
+ record4.consumed = true;
10751
+ this.#records.delete(record4);
10752
+ const selection = record4.selection;
10753
+ if (!record4.finalized || selection?.outcome.kind !== "throw" || !Object.is(selection.outcome.reason, capturedReason)) return void 0;
10765
10754
  return selection.report;
10766
10755
  }
10767
10756
  return void 0;
10768
10757
  }
10769
- discard(record3) {
10770
- if (!record3) return;
10771
- record3.consumed = true;
10772
- this.#records.delete(record3);
10758
+ discard(record4) {
10759
+ if (!record4) return;
10760
+ record4.consumed = true;
10761
+ this.#records.delete(record4);
10773
10762
  }
10774
10763
  close() {
10775
10764
  this.#closed = true;
10776
- for (const record3 of this.#records) record3.consumed = true;
10765
+ for (const record4 of this.#records) record4.consumed = true;
10777
10766
  this.#records.clear();
10778
10767
  this.#diagnostics = /* @__PURE__ */ new WeakMap();
10779
10768
  }
@@ -10827,7 +10816,7 @@ var InvocationCancellationOwner = class {
10827
10816
  throw error;
10828
10817
  }
10829
10818
  }
10830
- capture(execute2, frame) {
10819
+ capture(execute3, frame) {
10831
10820
  return new Promise((resolve) => {
10832
10821
  let settled = false;
10833
10822
  let raw;
@@ -10849,7 +10838,7 @@ var InvocationCancellationOwner = class {
10849
10838
  });
10850
10839
  };
10851
10840
  try {
10852
- raw = Promise.resolve(execute2());
10841
+ raw = Promise.resolve(execute3());
10853
10842
  } catch (reason) {
10854
10843
  settle({ kind: "throw", reason });
10855
10844
  return;
@@ -11087,13 +11076,13 @@ var Runtime = class _Runtime {
11087
11076
  }
11088
11077
  );
11089
11078
  }
11090
- invokeChild(options2, state, parent, validate, execute2) {
11079
+ invokeChild(options3, state, parent, validate, execute3) {
11091
11080
  const publicPromise = Promise.resolve().then(async () => {
11092
11081
  if (!this.cancellation.deliverySignal.aborted) parent.assertOpen();
11093
11082
  const childDepth = this.cancellationDepth + 1;
11094
11083
  const prepared = prepareChildCancellation(
11095
11084
  this.cancellation,
11096
- options2,
11085
+ options3,
11097
11086
  this.cancellationAdmission(childDepth)
11098
11087
  );
11099
11088
  this.cancellationOwner?.assertAdmissionOpen();
@@ -11133,7 +11122,7 @@ var Runtime = class _Runtime {
11133
11122
  frame
11134
11123
  );
11135
11124
  let captured;
11136
- const executeChild = () => execute2(runtime, scope);
11125
+ const executeChild = () => execute3(runtime, scope);
11137
11126
  if (owner) captured = await owner.capture(executeChild, frame);
11138
11127
  else {
11139
11128
  try {
@@ -11282,8 +11271,8 @@ var Runtime = class _Runtime {
11282
11271
  if (!typedSavedVariables.has(saved)) await this.prepareVariable(state, name2, saved);
11283
11272
  await owner.ledger.checkpoint(this.signal);
11284
11273
  }
11285
- for (const frame of stateMonitor(state).overlayFrames()) for (const [name2, record3] of frame) {
11286
- const saved = record3;
11274
+ for (const frame of stateMonitor(state).overlayFrames()) for (const [name2, record4] of frame) {
11275
+ const saved = record4;
11287
11276
  if (!saved.superseded && !typedSavedVariables.has(saved)) await this.prepareVariable(state, name2, saved, true);
11288
11277
  await owner.ledger.checkpoint(this.signal);
11289
11278
  }
@@ -11812,7 +11801,7 @@ var Runtime = class _Runtime {
11812
11801
  let io = originalIO;
11813
11802
  let diagnosticFailure;
11814
11803
  try {
11815
- const execute2 = async () => {
11804
+ const execute3 = async () => {
11816
11805
  if (command2.kind === "function") {
11817
11806
  if (state.profile === "sh" && specialBuiltinNames.has(command2.name)) {
11818
11807
  await this.diagnostic(io, `\`${command2.name}': is a special builtin`);
@@ -11965,7 +11954,7 @@ var Runtime = class _Runtime {
11965
11954
  }
11966
11955
  return status2;
11967
11956
  };
11968
- const status = await execute2();
11957
+ const status = await execute3();
11969
11958
  await finishOutputs(status);
11970
11959
  return status;
11971
11960
  } catch (caught) {
@@ -12079,8 +12068,8 @@ var Runtime = class _Runtime {
12079
12068
  if (io.stdout === closedSink) descriptors.delete(1);
12080
12069
  if (io.stderr === closedSink) descriptors.delete(2);
12081
12070
  const currentIO = () => {
12082
- const descriptor = descriptors.get(0)?.closed ? void 0 : descriptors.get(0);
12083
- const stdinIsDefault = descriptor?.input ? descriptor.stdinIsDefault : false;
12071
+ const descriptor2 = descriptors.get(0)?.closed ? void 0 : descriptors.get(0);
12072
+ const stdinIsDefault = descriptor2?.input ? descriptor2.stdinIsDefault : false;
12084
12073
  return {
12085
12074
  [invocationScope]: io[invocationScope],
12086
12075
  ...io.execution === void 0 ? {} : { execution: io.execution },
@@ -12089,7 +12078,7 @@ var Runtime = class _Runtime {
12089
12078
  ...io.scriptName === void 0 ? {} : { scriptName: io.scriptName },
12090
12079
  ...io.substitutionDiagnosticLine === void 0 ? {} : { substitutionDiagnosticLine: io.substitutionDiagnosticLine },
12091
12080
  ...io.substitutionDiagnosticLines === void 0 ? {} : { substitutionDiagnosticLines: io.substitutionDiagnosticLines },
12092
- stdin: descriptor?.input ?? closedSource,
12081
+ stdin: descriptor2?.input ?? closedSource,
12093
12082
  ...stdinIsDefault === void 0 ? {} : { stdinIsDefault },
12094
12083
  stdout: descriptors.get(1)?.closed ? closedSink : descriptors.get(1)?.output ?? closedSink,
12095
12084
  stderr: descriptors.get(2)?.closed ? closedSink : descriptors.get(2)?.output ?? closedSink,
@@ -12131,20 +12120,20 @@ var Runtime = class _Runtime {
12131
12120
  const move = target.endsWith("-");
12132
12121
  if (move && !redirect.move) throw new Error(`${target}: ambiguous redirect`);
12133
12122
  const sourceDescriptor = Number(move ? target.slice(0, -1) : target);
12134
- const descriptor = descriptors.get(sourceDescriptor);
12135
- if (!descriptor || descriptor.closed || !move && (redirect.operator === "<&" ? !descriptor.input : !descriptor.output)) throw new Error(`${move ? sourceDescriptor : target}: Bad file descriptor`);
12136
- descriptors.set(redirect.descriptor, { ...descriptor });
12123
+ const descriptor2 = descriptors.get(sourceDescriptor);
12124
+ if (!descriptor2 || descriptor2.closed || !move && (redirect.operator === "<&" ? !descriptor2.input : !descriptor2.output)) throw new Error(`${move ? sourceDescriptor : target}: Bad file descriptor`);
12125
+ descriptors.set(redirect.descriptor, { ...descriptor2 });
12137
12126
  if (move && sourceDescriptor !== redirect.descriptor) {
12138
12127
  descriptors.delete(sourceDescriptor);
12139
- if (persistMoves && !replaced.has(sourceDescriptor)) descriptor.closed = true;
12128
+ if (persistMoves && !replaced.has(sourceDescriptor)) descriptor2.closed = true;
12140
12129
  }
12141
12130
  }
12142
12131
  } else {
12143
12132
  const path = resolvePath(state.cwd, target);
12144
- const options2 = { signal: this.signal };
12133
+ const options3 = { signal: this.signal };
12145
12134
  if (redirect.operator === "<") {
12146
- await interruptible(this.fs.access(path, 4, options2), this.signal);
12147
- const stat = await interruptible(this.fs.stat(path, options2), this.signal);
12135
+ await interruptible(this.fs.access(path, 4, options3), this.signal);
12136
+ const stat = await interruptible(this.fs.stat(path, options3), this.signal);
12148
12137
  if (stat.type === "directory" && !fileShortcut) throw new Error(`${target}: Is a directory`);
12149
12138
  const source = stat.type === "directory" ? toByteSource("") : await fileInput(this.fs, path, this.budget.limits.maxInputBytes, this.signal);
12150
12139
  const input3 = new ShellInput(source, this.budget, this.signal);
@@ -12152,7 +12141,7 @@ var Runtime = class _Runtime {
12152
12141
  descriptors.set(redirect.descriptor, { input: input3, stdinIsDefault: false });
12153
12142
  } else {
12154
12143
  const append = redirect.operator === ">>";
12155
- const capabilities = await this.fs.capabilitiesFor?.(path, options2) ?? this.fs.capabilities;
12144
+ const capabilities = await this.fs.capabilitiesFor?.(path, options3) ?? this.fs.capabilities;
12156
12145
  const random = capabilities.randomAccessWrite === true;
12157
12146
  let file;
12158
12147
  await this.fileOperation(path, async () => {
@@ -12165,8 +12154,8 @@ var Runtime = class _Runtime {
12165
12154
  let offset = 0;
12166
12155
  const incremental = async () => {
12167
12156
  await this.fileOperation(path, async () => {
12168
- if (append) await this.fs.appendFile(path, new Uint8Array(), options2);
12169
- else await this.fs.writeFile(path, new Uint8Array(), { ...options2, flag: "w" });
12157
+ if (append) await this.fs.appendFile(path, new Uint8Array(), options3);
12158
+ else await this.fs.writeFile(path, new Uint8Array(), { ...options3, flag: "w" });
12170
12159
  if (!append) file.data = new Uint8Array();
12171
12160
  });
12172
12161
  return { write: (chunk) => {
@@ -12177,7 +12166,7 @@ var Runtime = class _Runtime {
12177
12166
  let atEOF = false;
12178
12167
  if (!append && current && offset === current.length && capabilities.append === true && capabilities.stat !== false) {
12179
12168
  try {
12180
- atEOF = (await interruptible(this.fs.stat(path, options2), this.signal)).size === offset;
12169
+ atEOF = (await interruptible(this.fs.stat(path, options3), this.signal)).size === offset;
12181
12170
  } catch {
12182
12171
  this.signal.throwIfAborted();
12183
12172
  }
@@ -12185,13 +12174,13 @@ var Runtime = class _Runtime {
12185
12174
  }
12186
12175
  if (append || atEOF) {
12187
12176
  const bytes2 = current ? appendOutputBytes(current, copy2) : void 0;
12188
- await this.fs.appendFile(path, copy2, options2);
12177
+ await this.fs.appendFile(path, copy2, options3);
12189
12178
  file.data = bytes2;
12190
12179
  } else {
12191
12180
  const bytes2 = new Uint8Array(Math.max(current?.length ?? 0, offset + copy2.length));
12192
12181
  if (current) bytes2.set(current);
12193
12182
  bytes2.set(copy2, offset);
12194
- await this.fs.writeFile(path, bytes2, options2);
12183
+ await this.fs.writeFile(path, bytes2, options3);
12195
12184
  file.data = bytes2;
12196
12185
  }
12197
12186
  if (!append) offset += copy2.length;
@@ -12460,8 +12449,8 @@ var Runtime = class _Runtime {
12460
12449
  fs: this.fs,
12461
12450
  signal: this.commandSignal,
12462
12451
  registerCleanup: (cleanup) => scope.register(cleanup),
12463
- invoke: (name3, args, options2) => {
12464
- const invocation = this.invoke(name3, args, options2, context, state, scope);
12452
+ invoke: (name3, args, options3) => {
12453
+ const invocation = this.invoke(name3, args, options3, context, state, scope);
12465
12454
  void invocation.catch(() => void 0);
12466
12455
  return invocation;
12467
12456
  }
@@ -12477,7 +12466,7 @@ var Runtime = class _Runtime {
12477
12466
  });
12478
12467
  return this.observeRuntimeReturn(raw, runtimeFrame, () => downstream);
12479
12468
  });
12480
- const execute2 = composeMiddleware(middleware, (forwarded) => scope.run(async () => {
12469
+ const execute3 = composeMiddleware(middleware, (forwarded) => scope.run(async () => {
12481
12470
  scope.assertOpen();
12482
12471
  const forwardedValues = getCommandArguments(forwarded);
12483
12472
  const admitted = forwardedValues === argumentValues ? argumentValues : this.admitArguments(forwardedValues.values, allocation);
@@ -12690,7 +12679,7 @@ var Runtime = class _Runtime {
12690
12679
  }
12691
12680
  }));
12692
12681
  try {
12693
- return validateExitCode((await interruptible(execute2(context), this.signal)).exitCode);
12682
+ return validateExitCode((await interruptible(execute3(context), this.signal)).exitCode);
12694
12683
  } catch (error) {
12695
12684
  if (builtinFailure && error === builtinFailure.error) throw new ExecutionFailure(error, io, builtinFailure.diagnostic);
12696
12685
  if (runtimeFrame.report && Object.is(runtimeFrame.report.origin.signal.reason, error) && this.outcomeFrame) {
@@ -12824,10 +12813,10 @@ ${functionDisplay(name2, state.functions.get(name2))}`;
12824
12813
  const target = component === void 0 ? name2 : `${component || "."}${component?.endsWith("/") ? "" : "/"}${name2}`;
12825
12814
  const resolved = resolvePath(state.cwd, target);
12826
12815
  try {
12827
- const options2 = { signal: this.signal };
12828
- if ((await interruptible(this.fs.stat(resolved, options2), this.signal)).type !== "file") continue;
12816
+ const options3 = { signal: this.signal };
12817
+ if ((await interruptible(this.fs.stat(resolved, options3), this.signal)).type !== "file") continue;
12829
12818
  if (this.fs.capabilities.permissions !== true) throw new CommandFailure(`${target}: execution permissions are not supported by this filesystem`, 126);
12830
- await interruptible(this.fs.access(resolved, ACCESS_MODES.X_OK, options2), this.signal);
12819
+ await interruptible(this.fs.access(resolved, ACCESS_MODES.X_OK, options3), this.signal);
12831
12820
  matches.push(target);
12832
12821
  if (!all) return matches;
12833
12822
  } catch (error) {
@@ -13051,8 +13040,8 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
13051
13040
  stderr: this.budget.sink(incoming.stderr, runtime.signal),
13052
13041
  signal: this.commandSignal,
13053
13042
  registerCleanup: (cleanup) => scope.register(cleanup),
13054
- invoke: (name2, args, options2) => {
13055
- const invocation = invocationOverride.current ? invocationOverride.current(name2, args, options2) : runtime.invoke(name2, args, options2, context, child, scope);
13043
+ invoke: (name2, args, options3) => {
13044
+ const invocation = invocationOverride.current ? invocationOverride.current(name2, args, options3) : runtime.invoke(name2, args, options3, context, child, scope);
13056
13045
  void invocation.catch(() => void 0);
13057
13046
  return invocation;
13058
13047
  }
@@ -13072,7 +13061,7 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
13072
13061
  });
13073
13062
  return runtime.observeRuntimeReturn(raw, runtimeFrame, () => downstream);
13074
13063
  });
13075
- const execute2 = composeMiddleware(middleware, async () => {
13064
+ const execute3 = composeMiddleware(middleware, async () => {
13076
13065
  scope.assertOpen();
13077
13066
  const forwardedValues = getCommandArguments(context);
13078
13067
  const admitted = forwardedValues === argumentValues ? argumentValues : runtime.admitArguments(forwardedValues.values, allocation);
@@ -13083,7 +13072,7 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
13083
13072
  return await runtime.observeRuntimeReturn(raw, runtimeFrame);
13084
13073
  });
13085
13074
  try {
13086
- const result = await interruptible(execute2(context), runtime.signal);
13075
+ const result = await interruptible(execute3(context), runtime.signal);
13087
13076
  runtime.signal.throwIfAborted();
13088
13077
  return validateExitCode(result.exitCode);
13089
13078
  } catch (error) {
@@ -13096,8 +13085,8 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
13096
13085
  if (ownsScope) await scope.close();
13097
13086
  }
13098
13087
  }
13099
- shebangTarget(context, state, io, command2, args, options2, target, loadedSource) {
13100
- return this.invokeChild(options2, state, io[invocationScope], () => {
13088
+ shebangTarget(context, state, io, command2, args, options3, target, loadedSource) {
13089
+ return this.invokeChild(options3, state, io[invocationScope], () => {
13101
13090
  this.signal.throwIfAborted();
13102
13091
  io[invocationScope].assertOpen();
13103
13092
  if (typeof command2 !== "string" || command2.includes("\0") || !Array.isArray(args) || args.some((argument) => typeof argument !== "string" || argument.includes("\0"))) {
@@ -13108,14 +13097,14 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
13108
13097
  for (const argument of [command2, ...args]) {
13109
13098
  if (import_buffer.Buffer.byteLength(argument) > this.budget.limits.maxExpansionBytes) this.budget.fail("maxExpansionBytes");
13110
13099
  }
13111
- }, (runtime, scope) => runtime.shebangTargetScoped(context, state, io, command2, args, options2, target, loadedSource, scope));
13100
+ }, (runtime, scope) => runtime.shebangTargetScoped(context, state, io, command2, args, options3, target, loadedSource, scope));
13112
13101
  }
13113
- async shebangTargetScoped(context, state, io, command2, args, options2, target, loadedSource, scope) {
13102
+ async shebangTargetScoped(context, state, io, command2, args, options3, target, loadedSource, scope) {
13114
13103
  const reserved = command2 === "bash" || command2 === "sh";
13115
13104
  const direct = command2.includes("/");
13116
13105
  const definition = this.commands.get(command2);
13117
13106
  const child = await this.shebangState(context, state);
13118
- child.cwd = resolvePath(context.cwd, options2.cwd ?? ".");
13107
+ child.cwd = resolvePath(context.cwd, options3.cwd ?? ".");
13119
13108
  if (!reserved) {
13120
13109
  if (child.depth >= this.budget.limits.maxSubstitutionDepth) this.budget.fail("maxSubstitutionDepth");
13121
13110
  child.depth++;
@@ -13124,18 +13113,18 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
13124
13113
  child.sourceDepth = 0;
13125
13114
  child.locals = [];
13126
13115
  }
13127
- const stdinIsDefault = options2.stdin === void 0 ? context.stdinIsDefault : options2.stdinIsDefault ?? false;
13128
- const argumentValues = getCommandArguments({ args, ...options2.argumentValues ? { argumentValues: options2.argumentValues } : {} });
13116
+ const stdinIsDefault = options3.stdin === void 0 ? context.stdinIsDefault : options3.stdinIsDefault ?? false;
13117
+ const argumentValues = getCommandArguments({ args, ...options3.argumentValues ? { argumentValues: options3.argumentValues } : {} });
13129
13118
  const selected = {
13130
13119
  ...context,
13131
13120
  command: command2,
13132
13121
  args: argumentValues.args,
13133
13122
  argumentValues,
13134
13123
  cwd: child.cwd,
13135
- env: options2.replaceEnv ? { ...options2.env } : { ...context.env, ...options2.env, PWD: child.cwd },
13136
- stdin: options2.stdin ?? context.stdin,
13137
- stdout: options2.stdout ?? context.stdout,
13138
- stderr: options2.stderr ?? context.stderr,
13124
+ env: options3.replaceEnv ? { ...options3.env } : { ...context.env, ...options3.env, PWD: child.cwd },
13125
+ stdin: options3.stdin ?? context.stdin,
13126
+ stdout: options3.stdout ?? context.stdout,
13127
+ stderr: options3.stderr ?? context.stderr,
13139
13128
  ...stdinIsDefault === void 0 ? {} : { stdinIsDefault }
13140
13129
  };
13141
13130
  const exitCode = await this.shebangStage(selected, child, io, async (runtime, forwarded, state2, childIO) => {
@@ -13151,7 +13140,7 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
13151
13140
  await writeText(forwarded.stderr, `env: ${command2}: command not found
13152
13141
  `);
13153
13142
  return { exitCode: 127 };
13154
- }, void 0, options2.stdin !== context.stdin ? options2.stdin : void 0, scope);
13143
+ }, void 0, options3.stdin !== context.stdin ? options3.stdin : void 0, scope);
13155
13144
  return { exitCode };
13156
13145
  }
13157
13146
  async envShebang(context, state, io, optionalArgument, target, args, loadedSource) {
@@ -13172,8 +13161,8 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
13172
13161
  let failureReport;
13173
13162
  const result = await interruptible(Promise.resolve(definition.execute({
13174
13163
  ...forwarded,
13175
- invoke: (command2, arguments_, options2) => {
13176
- const raw = forwarded.invoke(command2, arguments_, options2);
13164
+ invoke: (command2, arguments_, options3) => {
13165
+ const raw = forwarded.invoke(command2, arguments_, options3);
13177
13166
  return raw.catch((error) => {
13178
13167
  failed = true;
13179
13168
  failure = error;
@@ -13188,7 +13177,7 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
13188
13177
  throw failure;
13189
13178
  }
13190
13179
  return { exitCode: validateExitCode(result.exitCode) };
13191
- }, (runtime, forwarded, child, childIO) => (command2, arguments_, options2 = {}) => runtime.shebangTarget(forwarded, child, childIO, command2, arguments_, options2, target, loadedSource));
13180
+ }, (runtime, forwarded, child, childIO) => (command2, arguments_, options3 = {}) => runtime.shebangTarget(forwarded, child, childIO, command2, arguments_, options3, target, loadedSource));
13192
13181
  }
13193
13182
  async scriptFile(context, state, io, target, args, direct, errexit = false, loadedSource) {
13194
13183
  if (target === "") throw new CommandFailure(`${context.command}: : No such file or directory`, 127);
@@ -13200,14 +13189,14 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
13200
13189
  try {
13201
13190
  if (loadedSource?.path === path) source = loadedSource.source;
13202
13191
  else {
13203
- const options2 = { signal: this.signal };
13204
- const stat = await interruptible(this.fs.stat(path, options2), this.signal);
13192
+ const options3 = { signal: this.signal };
13193
+ const stat = await interruptible(this.fs.stat(path, options3), this.signal);
13205
13194
  if (stat.type !== "file") throw new CommandFailure(`${target}: ${stat.type === "directory" ? "Is a directory" : "not a regular file"}`, 126);
13206
13195
  if (direct && this.fs.capabilities.permissions !== true) throw new CommandFailure(`${target}: execution permissions are not supported by this filesystem`, 126);
13207
- await interruptible(this.fs.access(path, ACCESS_MODES.R_OK | (direct ? ACCESS_MODES.X_OK : 0), options2), this.signal);
13196
+ await interruptible(this.fs.access(path, ACCESS_MODES.R_OK | (direct ? ACCESS_MODES.X_OK : 0), options3), this.signal);
13208
13197
  const maxBytes = this.budget.limits.maxSourceBytes - this.budget.sourceBytes;
13209
13198
  if (stat.size > maxBytes) this.budget.fail("maxSourceBytes");
13210
- const bytes2 = await interruptible(this.fs.readFile(path, { ...options2, maxBytes }), this.signal);
13199
+ const bytes2 = await interruptible(this.fs.readFile(path, { ...options3, maxBytes }), this.signal);
13211
13200
  this.budget.source(bytes2.byteLength);
13212
13201
  source = this.sourceText(bytes2, target);
13213
13202
  }
@@ -13334,7 +13323,7 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
13334
13323
  let target = filename;
13335
13324
  let source;
13336
13325
  try {
13337
- const options2 = { signal: this.signal };
13326
+ const options3 = { signal: this.signal };
13338
13327
  if (filename && !filename.includes("/") && state.variables.PATH) {
13339
13328
  if (import_buffer.Buffer.byteLength(state.variables.PATH) > this.budget.limits.maxExpansionBytes) this.budget.fail("maxExpansionBytes");
13340
13329
  const components = state.variables.PATH.split(":");
@@ -13345,8 +13334,8 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
13345
13334
  const candidate = `${component || "."}${component.endsWith("/") ? "" : "/"}${filename}`;
13346
13335
  const path2 = resolvePath(state.cwd, candidate);
13347
13336
  try {
13348
- if ((await interruptible(this.fs.stat(path2, options2), this.signal)).type !== "file") continue;
13349
- await interruptible(this.fs.access(path2, ACCESS_MODES.R_OK, options2), this.signal);
13337
+ if ((await interruptible(this.fs.stat(path2, options3), this.signal)).type !== "file") continue;
13338
+ await interruptible(this.fs.access(path2, ACCESS_MODES.R_OK, options3), this.signal);
13350
13339
  target = candidate;
13351
13340
  found = true;
13352
13341
  break;
@@ -13359,13 +13348,13 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
13359
13348
  }
13360
13349
  if (!filename) throw new CommandFailure(": No such file or directory", 1);
13361
13350
  const path = resolvePath(state.cwd, target);
13362
- const stat = await interruptible(this.fs.stat(path, options2), this.signal);
13351
+ const stat = await interruptible(this.fs.stat(path, options3), this.signal);
13363
13352
  if (stat.type === "directory") throw new CommandFailure(`${context.command}: ${target}: is a directory`, 1);
13364
13353
  if (stat.type !== "file") throw new CommandFailure(`${target}: not a regular file`, 1);
13365
- await interruptible(this.fs.access(path, ACCESS_MODES.R_OK, options2), this.signal);
13354
+ await interruptible(this.fs.access(path, ACCESS_MODES.R_OK, options3), this.signal);
13366
13355
  const maxBytes = this.budget.limits.maxSourceBytes - this.budget.sourceBytes;
13367
13356
  if (stat.size > maxBytes) this.budget.fail("maxSourceBytes");
13368
- const bytes2 = await interruptible(this.fs.readFile(path, { ...options2, maxBytes }), this.signal);
13357
+ const bytes2 = await interruptible(this.fs.readFile(path, { ...options3, maxBytes }), this.signal);
13369
13358
  this.budget.source(bytes2.byteLength);
13370
13359
  source = this.sourceText(bytes2, target);
13371
13360
  } catch (error) {
@@ -13430,22 +13419,22 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
13430
13419
  }
13431
13420
  }
13432
13421
  }
13433
- invoke(name2, args, options2 = {}, context, state, parent) {
13434
- return this.invokeChild(options2, state, parent, () => {
13422
+ invoke(name2, args, options3 = {}, context, state, parent) {
13423
+ return this.invokeChild(options3, state, parent, () => {
13435
13424
  if (typeof name2 !== "string" || name2.includes("\0") || !Array.isArray(args) || args.some((arg) => typeof arg !== "string" || arg.includes("\0"))) {
13436
13425
  throw new TypeError("invoke requires a command and literal string arguments without NUL");
13437
13426
  }
13438
13427
  if (state.depth >= this.budget.limits.maxSubstitutionDepth) this.budget.fail("maxSubstitutionDepth");
13439
- }, (runtime, scope) => runtime.invokeScoped(name2, args, options2, context, state, scope));
13428
+ }, (runtime, scope) => runtime.invokeScoped(name2, args, options3, context, state, scope));
13440
13429
  }
13441
- async invokeScoped(name2, args, options2, context, state, scope) {
13430
+ async invokeScoped(name2, args, options3, context, state, scope) {
13442
13431
  this.signal.throwIfAborted();
13443
13432
  const allocation = this.budget.values.scope();
13444
13433
  scope.register(() => allocation.close());
13445
- const carrier = this.admitArguments(getCommandArguments({ args, ...options2.argumentValues ? { argumentValues: options2.argumentValues } : {} }).values, allocation);
13434
+ const carrier = this.admitArguments(getCommandArguments({ args, ...options3.argumentValues ? { argumentValues: options3.argumentValues } : {} }).values, allocation);
13446
13435
  const child = await cloneState(state, this.signal);
13447
- child.cwd = resolvePath(context.cwd, options2.cwd ?? ".");
13448
- const env = options2.replaceEnv ? { ...options2.env } : { ...context.env, ...options2.env, PWD: child.cwd };
13436
+ child.cwd = resolvePath(context.cwd, options3.cwd ?? ".");
13437
+ const env = options3.replaceEnv ? { ...options3.env } : { ...context.env, ...options3.env, PWD: child.cwd };
13449
13438
  if (guestArrays(child) || Object.keys(env).some((key) => arrayStore(child)?.get(key))) await this.indexedEnvironment(child, env);
13450
13439
  else {
13451
13440
  for (const key of child.exported) delete child.variables[key];
@@ -13461,15 +13450,15 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
13461
13450
  child.functionDepth = 0;
13462
13451
  child.sourceDepth = 0;
13463
13452
  child.locals = [];
13464
- const input3 = options2.stdin === void 0 ? void 0 : new ShellInput(options2.stdin, this.budget, this.signal);
13465
- const stdinIsDefault = options2.stdin === void 0 ? context.stdinIsDefault : options2.stdinIsDefault ?? false;
13453
+ const input3 = options3.stdin === void 0 ? void 0 : new ShellInput(options3.stdin, this.budget, this.signal);
13454
+ const stdinIsDefault = options3.stdin === void 0 ? context.stdinIsDefault : options3.stdinIsDefault ?? false;
13466
13455
  const io = {
13467
13456
  ...context,
13468
13457
  [invocationScope]: scope,
13469
13458
  stdin: input3 ?? context.stdin,
13470
13459
  ...stdinIsDefault === void 0 ? {} : { stdinIsDefault },
13471
- stdout: options2.stdout ? this.budget.sink(options2.stdout, this.signal) : context.stdout,
13472
- stderr: options2.stderr ? this.budget.sink(options2.stderr, this.signal) : context.stderr
13460
+ stdout: options3.stdout ? this.budget.sink(options3.stdout, this.signal) : context.stdout,
13461
+ stderr: options3.stderr ? this.budget.sink(options3.stderr, this.signal) : context.stderr
13473
13462
  };
13474
13463
  const command2 = {
13475
13464
  kind: "simple",
@@ -13517,8 +13506,8 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
13517
13506
  else if (flag === "o" && position === option.length - 1) {
13518
13507
  const name2 = args[index + 1];
13519
13508
  if (name2 === void 0) {
13520
- const options2 = [["errexit", !!state.errexit], ["nounset", !!state.nounset], ["pipefail", state.pipefail]];
13521
- for (const [name3, active] of options2) await writeText(stdout, enabled ? `${name3} ${active ? "on" : "off"}
13509
+ const options3 = [["errexit", !!state.errexit], ["nounset", !!state.nounset], ["pipefail", state.pipefail]];
13510
+ for (const [name3, active] of options3) await writeText(stdout, enabled ? `${name3} ${active ? "on" : "off"}
13522
13511
  ` : `set ${active ? "-" : "+"}o ${name3}
13523
13512
  `);
13524
13513
  } else {
@@ -13549,7 +13538,7 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
13549
13538
  async letBuiltin(context, state) {
13550
13539
  this.signal.throwIfAborted();
13551
13540
  const { maxExpansionBytes: bytes2, maxExpansionFields: fields } = this.budget.limits;
13552
- const admit = (value3) => {
13541
+ const admit2 = (value3) => {
13553
13542
  if (typeof value3 !== "string" || value3.includes("\0")) throw new CommandFailure("let: arguments must be strings without NUL", 2);
13554
13543
  if (value3.length > bytes2 || import_buffer.Buffer.byteLength(value3) > bytes2) this.budget.fail("maxExpansionBytes");
13555
13544
  };
@@ -13561,10 +13550,10 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
13561
13550
  const { args } = context;
13562
13551
  if (!Array.isArray(args)) throw new CommandFailure("let: argument array required", 2);
13563
13552
  if (args.length + 1 > fields) this.budget.fail("maxExpansionFields");
13564
- admit(context.command);
13553
+ admit2(context.command);
13565
13554
  for (let index = 0; index < args.length; index++) {
13566
13555
  this.signal.throwIfAborted();
13567
- admit(args[index]);
13556
+ admit2(args[index]);
13568
13557
  if ((index + 1) % 128 === 0) await checkpoint();
13569
13558
  }
13570
13559
  if (args[0] === "--help") throw new CommandFailure("let: --help: unsupported option", 2);
@@ -13593,7 +13582,7 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
13593
13582
  async getoptsBuiltin(context, state) {
13594
13583
  this.signal.throwIfAborted();
13595
13584
  const { maxExpansionBytes: bytes2, maxExpansionFields: fields } = this.budget.limits;
13596
- const admit = (value2) => {
13585
+ const admit2 = (value2) => {
13597
13586
  if (typeof value2 !== "string") throw new CommandFailure("getopts: arguments must be strings without NUL", 2);
13598
13587
  if (value2.length > bytes2 || import_buffer.Buffer.byteLength(value2) > bytes2) this.budget.fail("maxExpansionBytes");
13599
13588
  if (value2.includes("\0")) throw new CommandFailure("getopts: arguments must be strings without NUL", 2);
@@ -13605,10 +13594,10 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
13605
13594
  };
13606
13595
  if (!Array.isArray(context.args)) throw new CommandFailure("getopts: argument array required", 2);
13607
13596
  if (context.args.length + 1 > fields) this.budget.fail("maxExpansionFields");
13608
- admit(context.command);
13597
+ admit2(context.command);
13609
13598
  for (let index = 0; index < context.args.length; index++) {
13610
13599
  this.signal.throwIfAborted();
13611
- admit(context.args[index]);
13600
+ admit2(context.args[index]);
13612
13601
  if ((index + 1) % 128 === 0) await checkpoint();
13613
13602
  }
13614
13603
  const offset = context.args[0] === "--" ? 1 : 0;
@@ -13627,7 +13616,7 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
13627
13616
  if (args.length > fields) this.budget.fail("maxExpansionFields");
13628
13617
  for (let index = 0; index < args.length; index++) {
13629
13618
  this.signal.throwIfAborted();
13630
- admit(args[index]);
13619
+ admit2(args[index]);
13631
13620
  if ((index + 1) % 128 === 0) await checkpoint();
13632
13621
  }
13633
13622
  const maxBytes = saturatedProduct(bytes2, saturatedSum(args.length, 1));
@@ -13988,14 +13977,14 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
13988
13977
  const declarationArgs = [...args];
13989
13978
  let indexedLocal = false;
13990
13979
  if (command2 === "local") {
13991
- const options2 = localDeclarationOptions(declarationArgs, this.signal);
13992
- if (options2.error !== void 0) {
13993
- await writeText(stderr, `local: ${options2.error}: unsupported option
13980
+ const options3 = localDeclarationOptions(declarationArgs, this.signal);
13981
+ if (options3.error !== void 0) {
13982
+ await writeText(stderr, `local: ${options3.error}: unsupported option
13994
13983
  `);
13995
13984
  return 2;
13996
13985
  }
13997
- indexedLocal = options2.indexed;
13998
- declarationArgs.splice(0, options2.offset);
13986
+ indexedLocal = options3.indexed;
13987
+ declarationArgs.splice(0, options3.offset);
13999
13988
  if (indexedLocal && declarationArgs.length === 0) {
14000
13989
  await writeText(stderr, "local: -a requires a variable name\n");
14001
13990
  return 2;
@@ -15190,15 +15179,15 @@ var ShellInput = class _ShellInput {
15190
15179
  return bytes2;
15191
15180
  });
15192
15181
  }
15193
- line(raw, options2) {
15194
- return this.#cursor.consume(this.signal, () => options2 ? this.readBounded(raw, options2) : this.readLine(raw));
15182
+ line(raw, options3) {
15183
+ return this.#cursor.consume(this.signal, () => options3 ? this.readBounded(raw, options3) : this.readLine(raw));
15195
15184
  }
15196
- async readBounded(raw, options2) {
15185
+ async readBounded(raw, options3) {
15197
15186
  const text = new ReadText();
15198
15187
  let characters = 0;
15199
15188
  const escaped = /* @__PURE__ */ new Set();
15200
15189
  const decoder3 = new TextDecoder("utf-8", { fatal: true });
15201
- const delimiter = options2.delimiter ?? 10;
15190
+ const delimiter = options3.delimiter ?? 10;
15202
15191
  let chunk = new Uint8Array();
15203
15192
  let offset = 0;
15204
15193
  let length = 0;
@@ -15206,7 +15195,7 @@ var ShellInput = class _ShellInput {
15206
15195
  let escapedCharacter = false;
15207
15196
  let units = 0;
15208
15197
  let pulls = 0;
15209
- let terminated = options2.count === 0;
15198
+ let terminated = options3.count === 0;
15210
15199
  try {
15211
15200
  while (!terminated) {
15212
15201
  if (offset === chunk.length) {
@@ -15220,7 +15209,7 @@ var ShellInput = class _ShellInput {
15220
15209
  if (!chunk.length) continue;
15221
15210
  }
15222
15211
  const byte = chunk[offset++];
15223
- if (!options2.exact && !escaping && byte === delimiter) {
15212
+ if (!options3.exact && !escaping && byte === delimiter) {
15224
15213
  terminated = true;
15225
15214
  break;
15226
15215
  }
@@ -15250,8 +15239,8 @@ var ShellInput = class _ShellInput {
15250
15239
  characters++;
15251
15240
  decodedCharacters++;
15252
15241
  }
15253
- units += options2.byteCount ? 1 : decodedCharacters;
15254
- if (units === options2.count) terminated = true;
15242
+ units += options3.byteCount ? 1 : decodedCharacters;
15243
+ if (units === options3.count) terminated = true;
15255
15244
  }
15256
15245
  decoder3.decode();
15257
15246
  return { value: text.finish(), escaped, terminated };
@@ -15361,7 +15350,7 @@ var RootInvocationCancellationOwner = class {
15361
15350
  assertAdmissionOpen() {
15362
15351
  if (!this.#admissionOpen) throw new Error("Root cancellation admission is closed");
15363
15352
  }
15364
- capture(execute2) {
15353
+ capture(execute3) {
15365
15354
  return new Promise((resolve) => {
15366
15355
  let settled = false;
15367
15356
  let raw;
@@ -15383,7 +15372,7 @@ var RootInvocationCancellationOwner = class {
15383
15372
  });
15384
15373
  };
15385
15374
  try {
15386
- raw = Promise.resolve(execute2());
15375
+ raw = Promise.resolve(execute3());
15387
15376
  } catch (reason) {
15388
15377
  settle({ kind: "throw", reason });
15389
15378
  return;
@@ -15424,12 +15413,12 @@ var Shell = class {
15424
15413
  #disposed = false;
15425
15414
  #disposal;
15426
15415
  #active = /* @__PURE__ */ new Set();
15427
- constructor(options2) {
15428
- if (!options2?.fs) throw new TypeError("Shell requires an explicit filesystem");
15429
- warnIfHostProcessEnv(options2.env);
15430
- resolveLimits(options2.limits);
15431
- this.#options = { ...options2, cwd: resolvePath("/", options2.cwd ?? "/"), env: { ...options2.env }, limits: { ...options2.limits } };
15432
- this.commands = options2.commands ?? new CommandRegistry();
15416
+ constructor(options3) {
15417
+ if (!options3?.fs) throw new TypeError("Shell requires an explicit filesystem");
15418
+ warnIfHostProcessEnv(options3.env);
15419
+ resolveLimits(options3.limits);
15420
+ this.#options = { ...options3, cwd: resolvePath("/", options3.cwd ?? "/"), env: { ...options3.env }, limits: { ...options3.limits } };
15421
+ this.commands = options3.commands ?? new CommandRegistry();
15433
15422
  }
15434
15423
  use(middleware) {
15435
15424
  if (this.#disposed) throw new Error("Shell is disposed");
@@ -15442,17 +15431,17 @@ var Shell = class {
15442
15431
  if (!middleware || typeof middleware.setup !== "function") throw new TypeError("Expected middleware or shell plugin");
15443
15432
  this.#ready = this.#ready.then(async () => {
15444
15433
  let active = true;
15445
- const admit = () => {
15434
+ const admit2 = () => {
15446
15435
  if (this.#disposed && !active) throw new Error("Shell is disposed");
15447
15436
  };
15448
15437
  const host = {
15449
15438
  commands: this.commands,
15450
15439
  use: (middleware2) => {
15451
- admit();
15440
+ admit2();
15452
15441
  this.#install(middleware2);
15453
15442
  },
15454
15443
  registerFileSystem: (scheme, factory) => {
15455
- admit();
15444
+ admit2();
15456
15445
  this.#registerFileSystem(scheme, factory);
15457
15446
  }
15458
15447
  };
@@ -15466,9 +15455,9 @@ var Shell = class {
15466
15455
  void this.#ready.catch(() => void 0);
15467
15456
  }
15468
15457
  }
15469
- register(command2, options2) {
15458
+ register(command2, options3) {
15470
15459
  if (this.#disposed) throw new Error("Shell is disposed");
15471
- this.commands.register(command2, options2);
15460
+ this.commands.register(command2, options3);
15472
15461
  return this;
15473
15462
  }
15474
15463
  registerFileSystem(scheme, factory) {
@@ -15480,23 +15469,23 @@ var Shell = class {
15480
15469
  if (this.#filesystems.has(scheme)) throw new Error(`Filesystem already registered: ${scheme}`);
15481
15470
  this.#filesystems.set(scheme, factory);
15482
15471
  }
15483
- async createFileSystem(scheme, options2 = {}) {
15472
+ async createFileSystem(scheme, options3 = {}) {
15484
15473
  if (this.#disposed) throw new Error("Shell is disposed");
15485
15474
  await this.#ready;
15486
15475
  const factory = this.#filesystems.get(scheme);
15487
15476
  if (!factory) throw new Error(`Unknown filesystem scheme: ${scheme}`);
15488
- return factory(options2);
15477
+ return factory(options3);
15489
15478
  }
15490
- async exec(source, options2 = {}) {
15479
+ async exec(source, options3 = {}) {
15491
15480
  if (this.#disposed) throw new Error("Shell is disposed");
15492
- warnIfHostProcessEnv(options2.env);
15493
- const budget = new Budget(resolveLimits(this.#options.limits, options2.limits), options2.signal);
15494
- const scope = new InvocationScope(options2.signal);
15481
+ warnIfHostProcessEnv(options3.env);
15482
+ const budget = new Budget(resolveLimits(this.#options.limits, options3.limits), options3.signal);
15483
+ const scope = new InvocationScope(options3.signal);
15495
15484
  const cancellationState = new RuntimeCancellationState();
15496
15485
  const owner = new RootInvocationCancellationOwner(scope);
15497
15486
  const boundary = createRootCancellationLink({
15498
15487
  admission: Runtime.rootCancellationAdmission(budget),
15499
- callerSignal: options2.signal,
15488
+ callerSignal: options3.signal,
15500
15489
  controls: [{ role: "budget-control", signal: budget.controller.signal }]
15501
15490
  });
15502
15491
  try {
@@ -15511,7 +15500,7 @@ var Shell = class {
15511
15500
  this.#active.add(active);
15512
15501
  let captured;
15513
15502
  try {
15514
- captured = await owner.capture(() => this.#execute(source, options2, scope, budget, boundary, cancellationState, owner));
15503
+ captured = await owner.capture(() => this.#execute(source, options3, scope, budget, boundary, cancellationState, owner));
15515
15504
  } finally {
15516
15505
  budget.close();
15517
15506
  await scope.close();
@@ -15523,7 +15512,7 @@ var Shell = class {
15523
15512
  throwCleanupFailures(scope.failures);
15524
15513
  return selection.outcome.value;
15525
15514
  }
15526
- async #execute(source, options2, scope, budget, cancellation, cancellationState, owner) {
15515
+ async #execute(source, options3, scope, budget, cancellation, cancellationState, owner) {
15527
15516
  if (typeof source !== "string") throw new TypeError("Shell source must be a string");
15528
15517
  if (import_buffer.Buffer.byteLength(source) > budget.limits.maxSourceBytes) throw new ShellLimitError("maxSourceBytes");
15529
15518
  budget.source(import_buffer.Buffer.byteLength(source));
@@ -15547,20 +15536,20 @@ var Shell = class {
15547
15536
  const io = {
15548
15537
  [invocationScope]: scope,
15549
15538
  stdin: toByteSource(""),
15550
- stdinIsDefault: options2.stdin === void 0,
15551
- stdout: sink(stdout, options2.stdout),
15552
- stderr: sink(stderr, options2.stderr)
15539
+ stdinIsDefault: options3.stdin === void 0,
15540
+ stdout: sink(stdout, options3.stdout),
15541
+ stderr: sink(stderr, options3.stderr)
15553
15542
  };
15554
15543
  let exitCode;
15555
15544
  let failed = false;
15556
15545
  try {
15557
15546
  try {
15558
- let unit = parseShellUnit(source, 0, byteLocale({ ...this.#options.env, ...options2.env }));
15559
- stdin = new ShellInput(typeof options2.stdin === "string" || options2.stdin instanceof Uint8Array ? toByteSource(options2.stdin) : options2.stdin ?? toByteSource(""), budget);
15547
+ let unit = parseShellUnit(source, 0, byteLocale({ ...this.#options.env, ...options3.env }));
15548
+ stdin = new ShellInput(typeof options3.stdin === "string" || options3.stdin instanceof Uint8Array ? toByteSource(options3.stdin) : options3.stdin ?? toByteSource(""), budget);
15560
15549
  io.stdin = stdin;
15561
15550
  await interruptible(this.#ready, budget.signal);
15562
- const cwd = resolvePath("/", options2.cwd ?? this.#options.cwd ?? "/");
15563
- const variables = Object.assign(/* @__PURE__ */ Object.create(null), this.#options.env, options2.env, { PWD: cwd });
15551
+ const cwd = resolvePath("/", options3.cwd ?? this.#options.cwd ?? "/");
15552
+ const variables = Object.assign(/* @__PURE__ */ Object.create(null), this.#options.env, options3.env, { PWD: cwd });
15564
15553
  for (const [name2, value2] of Object.entries(variables)) {
15565
15554
  if (name2.includes("\0") || name2.includes("=") || typeof value2 !== "string" || value2.includes("\0")) throw new TypeError("Invalid environment entry");
15566
15555
  }
@@ -15587,7 +15576,7 @@ var Shell = class {
15587
15576
  };
15588
15577
  const admission = Runtime.rootCancellationAdmission(budget);
15589
15578
  const runtime = new Runtime(
15590
- options2.fs ?? this.#options.fs,
15579
+ options3.fs ?? this.#options.fs,
15591
15580
  this.commands,
15592
15581
  [...this.#middleware],
15593
15582
  budget,
@@ -15773,8 +15762,8 @@ function requestBody(source, signal) {
15773
15762
  }
15774
15763
  });
15775
15764
  }
15776
- function createFetchTransport(options2 = {}) {
15777
- const fetchRequest = options2.fetch ?? globalThis.fetch;
15765
+ function createFetchTransport(options3 = {}) {
15766
+ const fetchRequest = options3.fetch ?? globalThis.fetch;
15778
15767
  if (typeof fetchRequest !== "function") throw new TypeError("Fetch is unavailable");
15779
15768
  return async (input3) => {
15780
15769
  input3.signal.throwIfAborted();
@@ -15841,7 +15830,7 @@ function privateHostname(input3) {
15841
15830
  const [first, second] = octets;
15842
15831
  return first === 10 || first === 127 || first === 0 || first === 169 && second === 254 || first === 192 && second === 168 || first === 172 && second >= 16 && second <= 31;
15843
15832
  }
15844
- function createOriginAuthorizer(allowlist = "*", options2 = {}) {
15833
+ function createOriginAuthorizer(allowlist = "*", options3 = {}) {
15845
15834
  const origins = /* @__PURE__ */ new Set();
15846
15835
  const hosts = /* @__PURE__ */ new Set();
15847
15836
  for (const entry of allowlist === "*" ? [] : allowlist) {
@@ -15861,7 +15850,7 @@ function createOriginAuthorizer(allowlist = "*", options2 = {}) {
15861
15850
  return (request) => {
15862
15851
  const url = new URL(request.url);
15863
15852
  const hostname = url.hostname.toLowerCase().replace(/\.$/u, "");
15864
- if (options2.denyPrivateNetworks && privateHostname(hostname)) return false;
15853
+ if (options3.denyPrivateNetworks && privateHostname(hostname)) return false;
15865
15854
  return allowlist === "*" || origins.has(url.origin) || hosts.has(hostname);
15866
15855
  };
15867
15856
  }
@@ -15911,25 +15900,25 @@ var ExprMatchError = class extends Error {
15911
15900
  function exactObject(value2, keys) {
15912
15901
  return value2 !== null && typeof value2 === "object" && !Array.isArray(value2) && Object.keys(value2).length === keys.length && keys.every((key) => Object.hasOwn(value2, key));
15913
15902
  }
15914
- function validateExprInput(descriptor, rows, signal) {
15903
+ function validateExprInput(descriptor2, rows, signal) {
15915
15904
  signal.throwIfAborted();
15916
15905
  const invalid = () => {
15917
15906
  throw new RegexExecutionError("PROTOCOL", "invalid expr request");
15918
15907
  };
15919
- if (!exactObject(descriptor, ["kind", "pattern", "profile", "limits"]) || descriptor.kind !== "expr-match" || !(descriptor.pattern instanceof Uint8Array) || !["byte", "utf8-scalar"].includes(descriptor.profile)) invalid();
15908
+ if (!exactObject(descriptor2, ["kind", "pattern", "profile", "limits"]) || descriptor2.kind !== "expr-match" || !(descriptor2.pattern instanceof Uint8Array) || !["byte", "utf8-scalar"].includes(descriptor2.profile)) invalid();
15920
15909
  const keys = Object.keys(exprMatchCeilings);
15921
- if (!exactObject(descriptor.limits, keys)) invalid();
15910
+ if (!exactObject(descriptor2.limits, keys)) invalid();
15922
15911
  for (const key of keys) {
15923
- if (!Number.isSafeInteger(descriptor.limits[key]) || descriptor.limits[key] < 1 || descriptor.limits[key] > exprMatchCeilings[key]) invalid();
15912
+ if (!Number.isSafeInteger(descriptor2.limits[key]) || descriptor2.limits[key] < 1 || descriptor2.limits[key] > exprMatchCeilings[key]) invalid();
15924
15913
  }
15925
15914
  if (!Array.isArray(rows) || rows.length !== 1) invalid();
15926
15915
  const row = rows[0];
15927
15916
  if (!exactObject(row, ["bytes", "all", "terminated"]) || !(row.bytes instanceof Uint8Array) || row.all !== false || row.terminated !== false) invalid();
15928
- if (descriptor.pattern.length > descriptor.limits.maxPatternBytes || row.bytes.length > descriptor.limits.maxSubjectBytes) {
15917
+ if (descriptor2.pattern.length > descriptor2.limits.maxPatternBytes || row.bytes.length > descriptor2.limits.maxSubjectBytes) {
15929
15918
  throw new ExprMatchError("limit", "regex input bytes limit exceeded");
15930
15919
  }
15931
15920
  }
15932
- function validateExprReply(value2, id, descriptor, subject, signal) {
15921
+ function validateExprReply(value2, id, descriptor2, subject, signal) {
15933
15922
  signal.throwIfAborted();
15934
15923
  const invalid = () => {
15935
15924
  throw new RegexExecutionError("PROTOCOL", "invalid expr reply");
@@ -15943,13 +15932,13 @@ function validateExprReply(value2, id, descriptor, subject, signal) {
15943
15932
  }
15944
15933
  if (!exactObject(reply, ["id", "operation", "result"])) return invalid();
15945
15934
  const result = reply.result;
15946
- if (!exactObject(result, ["offsetUnit", "matched", "hasCapture", "overall", "capture", "steps"]) || result.offsetUnit !== "byte" || typeof result.matched !== "boolean" || typeof result.hasCapture !== "boolean" || !Number.isSafeInteger(result.steps) || result.steps < 1 || result.steps > descriptor.limits.maxSteps) return invalid();
15935
+ if (!exactObject(result, ["offsetUnit", "matched", "hasCapture", "overall", "capture", "steps"]) || result.offsetUnit !== "byte" || typeof result.matched !== "boolean" || typeof result.hasCapture !== "boolean" || !Number.isSafeInteger(result.steps) || result.steps < 1 || result.steps > descriptor2.limits.maxSteps) return invalid();
15947
15936
  const span = (value3) => {
15948
15937
  if (value3 === null) return null;
15949
15938
  if (!exactObject(value3, ["start", "end"]) || !Number.isSafeInteger(value3.start) || !Number.isSafeInteger(value3.end)) return invalid();
15950
15939
  const start = value3.start, end = value3.end;
15951
15940
  if (start < 0 || end < start || end > subject.length) return invalid();
15952
- if (descriptor.profile === "utf8-scalar") {
15941
+ if (descriptor2.profile === "utf8-scalar") {
15953
15942
  for (const offset of [start, end]) if (offset < subject.length && subject[offset] >= 128 && subject[offset] <= 191) return invalid();
15954
15943
  }
15955
15944
  return { start, end };
@@ -15958,8 +15947,8 @@ function validateExprReply(value2, id, descriptor, subject, signal) {
15958
15947
  if (result.matched !== (overall !== null) || overall && overall.start !== 0 || capture && (!result.hasCapture || !overall || capture.start < overall.start || capture.end > overall.end)) return invalid();
15959
15948
  return { offsetUnit: "byte", matched: result.matched, hasCapture: result.hasCapture, overall, capture, steps: result.steps };
15960
15949
  }
15961
- function policy(options2) {
15962
- const result = { ...defaults, ...options2 };
15950
+ function policy(options3) {
15951
+ const result = { ...defaults, ...options3 };
15963
15952
  for (const key of Object.keys(defaults)) {
15964
15953
  const minimum = key === "maxQueuedRequests" || key === "maxQueuedBytes" ? 0 : 1;
15965
15954
  if (!Number.isSafeInteger(result[key]) || result[key] < minimum) throw new RangeError(`regex ${key} must be a safe integer >= ${minimum}`);
@@ -15969,9 +15958,9 @@ function policy(options2) {
15969
15958
  }
15970
15959
  return Object.freeze(result);
15971
15960
  }
15972
- function inputBytes(descriptor, rows, signal) {
15973
- let total = 128 + (descriptor.kind === "glob" ? descriptor.globOptions.length * 32 : 0);
15974
- for (const pattern of descriptor.patterns) {
15961
+ function inputBytes(descriptor2, rows, signal) {
15962
+ let total = 128 + (descriptor2.kind === "glob" ? descriptor2.globOptions.length * 32 : 0);
15963
+ for (const pattern of descriptor2.patterns) {
15975
15964
  signal.throwIfAborted();
15976
15965
  total += 16 + pattern.length * 2;
15977
15966
  if (!Number.isSafeInteger(total)) throw new RegexExecutionError("QUEUE_EXHAUSTED", "input accounting overflow");
@@ -16016,7 +16005,7 @@ async function awaitRetirements(retirements) {
16016
16005
  if (failures.length === 1) throw failures[0];
16017
16006
  if (failures.length > 1) throw new AggregateError(failures, "regex retirement failed");
16018
16007
  }
16019
- async function withRegexSession(context, executor, execute2) {
16008
+ async function withRegexSession(context, executor, execute3) {
16020
16009
  context.signal.throwIfAborted();
16021
16010
  let session;
16022
16011
  let closing;
@@ -16034,7 +16023,7 @@ async function withRegexSession(context, executor, execute2) {
16034
16023
  context.signal.throwIfAborted();
16035
16024
  if (closing) throw new RegexExecutionError("CLOSED", "invocation is closed");
16036
16025
  session = executor.open(context.signal);
16037
- outcome = { result: await execute2(session) };
16026
+ outcome = { result: await execute3(session) };
16038
16027
  } catch (error) {
16039
16028
  outcome = { error };
16040
16029
  }
@@ -16126,10 +16115,10 @@ var Slot = class {
16126
16115
  }
16127
16116
  };
16128
16117
  var RegexExecutor = class {
16129
- constructor(provider, options2 = defaults) {
16118
+ constructor(provider, options3 = defaults) {
16130
16119
  this.provider = provider;
16131
16120
  if (!provider || typeof provider.createWorker !== "function") throw new TypeError("a bounded regex provider is required");
16132
- this.options = policy(options2);
16121
+ this.options = policy(options3);
16133
16122
  }
16134
16123
  provider;
16135
16124
  options;
@@ -16164,21 +16153,21 @@ var RegexExecutor = class {
16164
16153
  this.slots.delete(slot);
16165
16154
  this.pump();
16166
16155
  }
16167
- request(descriptor, rows, signal, retirements = /* @__PURE__ */ new Set()) {
16156
+ request(descriptor2, rows, signal, retirements = /* @__PURE__ */ new Set()) {
16168
16157
  signal.throwIfAborted();
16169
16158
  if (this.disposed) return Promise.reject(new RegexExecutionError("CLOSED", "executor is disposed"));
16170
- if (descriptor.kind === "expr-match") validateExprInput(descriptor, rows, signal);
16171
- const bytes2 = descriptor.kind === "expr-match" ? 256 + descriptor.pattern.length + rows[0].bytes.length : inputBytes(descriptor, rows, signal);
16159
+ if (descriptor2.kind === "expr-match") validateExprInput(descriptor2, rows, signal);
16160
+ const bytes2 = descriptor2.kind === "expr-match" ? 256 + descriptor2.pattern.length + rows[0].bytes.length : inputBytes(descriptor2, rows, signal);
16172
16161
  const available = this.queue.length === 0 && ([...this.slots].some((slot) => !slot.busy && !slot.retired) || this.slots.size < this.options.maxWorkers);
16173
16162
  if (!available && (this.queue.length >= this.options.maxQueuedRequests || bytes2 > this.options.maxQueuedBytes - this.queuedBytes)) return Promise.reject(new RegexExecutionError("QUEUE_EXHAUSTED", "queued request count or input byte limit exceeded"));
16174
- const ownedDescriptor = descriptor.kind === "expr-match" ? { ...descriptor, pattern: Uint8Array.from(descriptor.pattern), limits: { ...descriptor.limits } } : { ...descriptor, patterns: descriptor.patterns.map((pattern) => {
16163
+ const ownedDescriptor = descriptor2.kind === "expr-match" ? { ...descriptor2, pattern: Uint8Array.from(descriptor2.pattern), limits: { ...descriptor2.limits } } : { ...descriptor2, patterns: descriptor2.patterns.map((pattern) => {
16175
16164
  signal.throwIfAborted();
16176
16165
  return pattern;
16177
16166
  }) };
16178
16167
  if (ownedDescriptor.kind === "glob") {
16179
- const globOptions = ownedDescriptor.globOptions.map((options2) => {
16168
+ const globOptions = ownedDescriptor.globOptions.map((options3) => {
16180
16169
  signal.throwIfAborted();
16181
- return { ...options2 };
16170
+ return { ...options3 };
16182
16171
  });
16183
16172
  Object.assign(ownedDescriptor, { globOptions });
16184
16173
  }
@@ -16296,18 +16285,18 @@ var RegexSession = class {
16296
16285
  retirements = /* @__PURE__ */ new Set();
16297
16286
  controller = new AbortController();
16298
16287
  requestSignal;
16299
- run(descriptor, rows) {
16288
+ run(descriptor2, rows) {
16300
16289
  this.signal.throwIfAborted();
16301
16290
  if (this.closed) throw new RegexExecutionError("CLOSED", "invocation is closed");
16302
- const result = this.executor.request(descriptor, rows, this.requestSignal, this.retirements);
16291
+ const result = this.executor.request(descriptor2, rows, this.requestSignal, this.retirements);
16303
16292
  this.pending.add(result);
16304
16293
  void result.then(() => this.pending.delete(result), () => this.pending.delete(result));
16305
16294
  return result;
16306
16295
  }
16307
- matchExpr(descriptor, subject) {
16296
+ matchExpr(descriptor2, subject) {
16308
16297
  this.signal.throwIfAborted();
16309
16298
  if (this.closed) throw new RegexExecutionError("CLOSED", "invocation is closed");
16310
- const result = this.executor.request(descriptor, [{ bytes: subject, all: false, terminated: false }], this.requestSignal, this.retirements);
16299
+ const result = this.executor.request(descriptor2, [{ bytes: subject, all: false, terminated: false }], this.requestSignal, this.retirements);
16311
16300
  this.pending.add(result);
16312
16301
  void result.then(() => this.pending.delete(result), () => this.pending.delete(result));
16313
16302
  return result;
@@ -16440,10 +16429,10 @@ async function* requiredFileInput(context, requirements, mode, file, maxBytes) {
16440
16429
  var ProgramError = class extends Error {
16441
16430
  };
16442
16431
  var Budget3 = class {
16443
- constructor(context, options2) {
16432
+ constructor(context, options3) {
16444
16433
  this.context = context;
16445
- this.remaining = options2.maxSteps ?? 5e6;
16446
- this.maxBufferBytes = options2.maxBufferBytes ?? 32 * 1024 * 1024;
16434
+ this.remaining = options3.maxSteps ?? 5e6;
16435
+ this.maxBufferBytes = options3.maxBufferBytes ?? 32 * 1024 * 1024;
16447
16436
  for (const value2 of [this.remaining, this.maxBufferBytes]) {
16448
16437
  if (!Number.isSafeInteger(value2) || value2 < 1) throw new ProgramError("limits must be positive safe integers");
16449
16438
  }
@@ -17060,10 +17049,10 @@ async function execute(program, context, files, quiet, budget) {
17060
17049
  following = void 0;
17061
17050
  return next;
17062
17051
  };
17063
- const prepareRecord = async (record3) => {
17064
- if (record3.terminated || files.length < 2) return record3;
17052
+ const prepareRecord = async (record4) => {
17053
+ if (record4.terminated || files.length < 2) return record4;
17065
17054
  const next = await peekNext();
17066
- return !next.done && next.value.fileIndex !== record3.fileIndex ? { ...record3, terminated: true } : record3;
17055
+ return !next.done && next.value.fileIndex !== record4.fileIndex ? { ...record4, terminated: true } : record4;
17067
17056
  };
17068
17057
  let number = 0;
17069
17058
  let hold = "";
@@ -17078,8 +17067,8 @@ async function execute(program, context, files, quiet, budget) {
17078
17067
  while (!current.done) {
17079
17068
  budget.step();
17080
17069
  number++;
17081
- let record3 = await prepareRecord(current.value);
17082
- let pattern = record3.text;
17070
+ let record4 = await prepareRecord(current.value);
17071
+ let pattern = record4.text;
17083
17072
  const appended = [];
17084
17073
  let appendedSize = 0;
17085
17074
  const append = (item) => {
@@ -17091,7 +17080,7 @@ async function execute(program, context, files, quiet, budget) {
17091
17080
  let deleted = false;
17092
17081
  let quit = false;
17093
17082
  let status = 0;
17094
- const print = () => write(context, pattern + (record3.terminated ? "\n" : ""));
17083
+ const print = () => write(context, pattern + (record4.terminated ? "\n" : ""));
17095
17084
  const flush = async () => {
17096
17085
  await assertPathRequirements(context, sedRequirements, ["script-read"], appended.flatMap((item) => item.file === void 0 ? [] : [item.file]));
17097
17086
  if (!quiet && !deleted) await print();
@@ -17152,7 +17141,7 @@ async function execute(program, context, files, quiet, budget) {
17152
17141
  break;
17153
17142
  case "P": {
17154
17143
  const end = pattern.indexOf("\n");
17155
- await write(context, end < 0 ? pattern + (record3.terminated ? "\n" : "") : pattern.slice(0, end + 1));
17144
+ await write(context, end < 0 ? pattern + (record4.terminated ? "\n" : "") : pattern.slice(0, end + 1));
17156
17145
  break;
17157
17146
  }
17158
17147
  case "=":
@@ -17266,9 +17255,9 @@ async function execute(program, context, files, quiet, budget) {
17266
17255
  if (instruction.kind === "N") await flush();
17267
17256
  return { status: 0, quit: false };
17268
17257
  }
17269
- record3 = await prepareRecord(next.value);
17258
+ record4 = await prepareRecord(next.value);
17270
17259
  number++;
17271
- pattern = instruction.kind === "N" ? budget.check(pattern + "\n" + record3.text) : record3.text;
17260
+ pattern = instruction.kind === "N" ? budget.check(pattern + "\n" + record4.text) : record4.text;
17272
17261
  substituted = false;
17273
17262
  break;
17274
17263
  }
@@ -17284,9 +17273,9 @@ async function execute(program, context, files, quiet, budget) {
17284
17273
  await source.return(void 0);
17285
17274
  }
17286
17275
  }
17287
- function sedCommand(options2 = {}) {
17276
+ function sedCommand(options3 = {}) {
17288
17277
  const definition = command("sed", async (context) => {
17289
- const budget = new Budget3(context, options2);
17278
+ const budget = new Budget3(context, options3);
17290
17279
  const sources = [];
17291
17280
  const files = [];
17292
17281
  let quiet = false;
@@ -17382,6 +17371,7 @@ function sedCommand(options2 = {}) {
17382
17371
 
17383
17372
  // packages/safe-bash/src/commands/search/grep.ts
17384
17373
  init_platform();
17374
+ var maxPatternCount = 1024;
17385
17375
  function createGrepCommands(executor) {
17386
17376
  return [{ name: "grep", filesystemRequirements: grepRequirements, execute: (context) => withRegexSession(context, executor, async (session) => {
17387
17377
  try {
@@ -17394,20 +17384,46 @@ function createGrepCommands(executor) {
17394
17384
  const names = parsed.operands.length ? parsed.operands : ["-"];
17395
17385
  const patternFiles = parsed.values.get("f") ?? [];
17396
17386
  const patterns2 = [];
17397
- const addPatterns = (text, file) => {
17398
- if (file && text === "") return;
17399
- const parts = text.split("\n");
17400
- if (parts.length > 1 && parts.at(-1) === "") parts.pop();
17401
- patterns2.push(...parts);
17387
+ let patternCount = 0;
17388
+ let patternBytes = 0;
17389
+ const admit2 = (chunk, atStart) => {
17390
+ context.signal.throwIfAborted();
17391
+ const size = typeof chunk === "string" ? import_buffer.Buffer.byteLength(chunk) : chunk.length;
17392
+ if (size > bufferLimit - patternBytes) throw new UsageError(`pattern byte limit exceeded (${bufferLimit} bytes)`);
17393
+ patternBytes += size;
17394
+ for (let offset = 0; offset < chunk.length; ) {
17395
+ if (atStart && ++patternCount > maxPatternCount) throw new UsageError(`pattern count limit exceeded (${maxPatternCount})`);
17396
+ const newline = typeof chunk === "string" ? chunk.indexOf("\n", offset) : chunk.indexOf(10, offset);
17397
+ if (newline < 0) return false;
17398
+ offset = newline + 1;
17399
+ atStart = true;
17400
+ }
17401
+ return atStart;
17402
17402
  };
17403
- for (const pattern of parsed.values.get("e") ?? []) addPatterns(import_buffer.Buffer.from(pattern).toString("latin1"), false);
17403
+ const addArgument = async (pattern) => {
17404
+ admit2(pattern, true);
17405
+ if (pattern === "") {
17406
+ if (++patternCount > maxPatternCount) throw new UsageError(`pattern count limit exceeded (${maxPatternCount})`);
17407
+ patterns2.push("");
17408
+ } else {
17409
+ for await (const line of lines(toByteSource(pattern))) patterns2.push(import_buffer.Buffer.from(line.bytes).toString("latin1"));
17410
+ }
17411
+ };
17412
+ async function* admitted(source) {
17413
+ let atStart = true;
17414
+ for await (const chunk of source) {
17415
+ atStart = admit2(chunk, atStart);
17416
+ yield chunk;
17417
+ }
17418
+ }
17419
+ for (const pattern of parsed.values.get("e") ?? []) await addArgument(pattern);
17404
17420
  for (const name2 of patternFiles) {
17405
- const source = name2 === "-" ? input(context) : requiredFileInput(context, grepRequirements, "pattern-file", name2, bufferLimit);
17406
- addPatterns(import_buffer.Buffer.from(await collect(source, context.signal)).toString("latin1"), true);
17421
+ const source = name2 === "-" ? input(context) : requiredFileInput(context, grepRequirements, "pattern-file", name2, bufferLimit - patternBytes);
17422
+ for await (const line of lines(admitted(source))) patterns2.push(import_buffer.Buffer.from(line.bytes).toString("latin1"));
17407
17423
  }
17408
- if (positionalPattern !== void 0) addPatterns(import_buffer.Buffer.from(positionalPattern).toString("latin1"), false);
17424
+ if (positionalPattern !== void 0) await addArgument(positionalPattern);
17409
17425
  if (parsed.flags.has("E") && parsed.flags.has("F")) throw new UsageError("conflicting matchers specified");
17410
- const descriptor = {
17426
+ const descriptor2 = {
17411
17427
  kind: "grep",
17412
17428
  patterns: patterns2,
17413
17429
  fixed: parsed.flags.has("F"),
@@ -17416,7 +17432,7 @@ function createGrepCommands(executor) {
17416
17432
  whole: parsed.flags.has("x"),
17417
17433
  word: parsed.flags.has("w")
17418
17434
  };
17419
- await session.run(descriptor, []);
17435
+ await session.run(descriptor2, []);
17420
17436
  const maxCount = value(parsed, "m") === void 0 ? Infinity : integer(value(parsed, "m"));
17421
17437
  const batchSize = Number.isFinite(maxCount) || parsed.flags.has("q") || parsed.flags.has("l") || parsed.flags.has("L") ? 1 : 128;
17422
17438
  const delimiter = parsed.flags.has("z") ? "\0" : "\n";
@@ -17431,7 +17447,7 @@ function createGrepCommands(executor) {
17431
17447
  const available = new AvailableRecords(parsed.flags.has("z") ? 0 : 10, bufferLimit);
17432
17448
  const source = name2 === "-" ? input(context) : requiredFileInput(context, grepRequirements, "file", name2, bufferLimit);
17433
17449
  records: if (maxCount > 0) for await (const batch of available.batches(lines(available.source(source), parsed.flags.has("z") ? 0 : 10), (line) => line.bytes.length, () => batchSize)) {
17434
- const results = await session.run(descriptor, batch.map((line) => ({ bytes: line.bytes, all: parsed.flags.has("o"), terminated: line.terminated })));
17450
+ const results = await session.run(descriptor2, batch.map((line) => ({ bytes: line.bytes, all: parsed.flags.has("o"), terminated: line.terminated })));
17435
17451
  for (let index = 0; index < batch.length; index++) {
17436
17452
  const line = batch[index];
17437
17453
  context.signal.throwIfAborted();
@@ -17851,13 +17867,13 @@ function pathFor(context, path) {
17851
17867
  var OutputClosed = class extends SearchError {
17852
17868
  };
17853
17869
  var Limits = class {
17854
- constructor(context, options2) {
17870
+ constructor(context, options3) {
17855
17871
  this.context = context;
17856
17872
  this.signal = AbortSignal.any([context.signal, this.stopped.signal]);
17857
- this.maxOutputBytes = options2.maxOutputBytes ?? 16 * 1024 * 1024;
17858
- this.maxLineBytes = options2.maxLineBytes ?? 1024 * 1024;
17859
- this.maxFileBytes = options2.maxFileBytes ?? 64 * 1024 * 1024;
17860
- this.maxFiles = options2.maxFiles ?? 1e5;
17873
+ this.maxOutputBytes = options3.maxOutputBytes ?? 16 * 1024 * 1024;
17874
+ this.maxLineBytes = options3.maxLineBytes ?? 1024 * 1024;
17875
+ this.maxFileBytes = options3.maxFileBytes ?? 64 * 1024 * 1024;
17876
+ this.maxFiles = options3.maxFiles ?? 1e5;
17861
17877
  for (const limit of [this.maxOutputBytes, this.maxLineBytes, this.maxFileBytes, this.maxFiles]) {
17862
17878
  if (!Number.isSafeInteger(limit) || limit < 1) throw new SearchError("search limits must be positive safe integers");
17863
17879
  }
@@ -18042,13 +18058,13 @@ async function matchGlobs(globs, candidates, session) {
18042
18058
  bytes2 += size;
18043
18059
  offset++;
18044
18060
  }
18045
- const descriptor = {
18061
+ const descriptor2 = {
18046
18062
  kind: "glob",
18047
18063
  patterns: batch.map((glob) => glob.source),
18048
18064
  globOptions: batch.map((glob) => ({ insensitive: glob.insensitive, literalUnclosedClass: glob.literalUnclosedClass }))
18049
18065
  };
18050
18066
  try {
18051
- results.push(...(await session.run(descriptor, rows)).map((result) => result.length > 0));
18067
+ results.push(...(await session.run(descriptor2, rows)).map((result) => result.length > 0));
18052
18068
  } catch (error) {
18053
18069
  if (error instanceof RegexExecutionError && error.code === "MATCH") throw new SearchError(error.message);
18054
18070
  throw error;
@@ -18247,10 +18263,10 @@ var Walker = class {
18247
18263
  };
18248
18264
 
18249
18265
  // packages/safe-bash/src/commands/search/rg-command.ts
18250
- function selectInput(context, args, options2) {
18266
+ function selectInput(context, args, options3) {
18251
18267
  if (args.paths.length) return { paths: args.paths, implicit: false };
18252
- if (args.mode === "files" || options2.defaultInput === "cwd" || args.patternFiles.includes("-")) return { paths: ["."], implicit: true };
18253
- const stdin = options2.defaultInput === "stdin" || context.stdinIsDefault === false;
18268
+ if (args.mode === "files" || options3.defaultInput === "cwd" || args.patternFiles.includes("-")) return { paths: ["."], implicit: true };
18269
+ const stdin = options3.defaultInput === "stdin" || context.stdinIsDefault === false;
18254
18270
  return { paths: stdin ? ["-"] : ["."], implicit: !stdin };
18255
18271
  }
18256
18272
  async function patterns(context, args) {
@@ -18372,7 +18388,7 @@ async function searchFile(context, args, limits, matcher, printer, target, stdin
18372
18388
  }
18373
18389
  return { found, stats: totals };
18374
18390
  }
18375
- function createRgCommand(executor, options2 = {}) {
18391
+ function createRgCommand(executor, options3 = {}) {
18376
18392
  return {
18377
18393
  name: "rg",
18378
18394
  filesystemRequirements: searchRequirements,
@@ -18383,12 +18399,12 @@ function createRgCommand(executor, options2 = {}) {
18383
18399
  let failed = false;
18384
18400
  let found = false;
18385
18401
  try {
18386
- const limits = new Limits(context, options2);
18402
+ const limits = new Limits(context, options3);
18387
18403
  args = parse2(context.args);
18388
18404
  if (args.mode !== "files" && args.patternFiles.includes("-") && args.paths.includes("-")) {
18389
18405
  throw new SearchError("cannot search stdin while also reading patterns from stdin");
18390
18406
  }
18391
- const selection = selectInput(context, args, options2);
18407
+ const selection = selectInput(context, args, options3);
18392
18408
  const report = async (error) => {
18393
18409
  context.signal.throwIfAborted();
18394
18410
  failed = true;
@@ -18438,16 +18454,16 @@ function createRgCommand(executor, options2 = {}) {
18438
18454
  }
18439
18455
 
18440
18456
  // packages/safe-bash/src/commands/search/portable.ts
18441
- function portableSearchCommands(options2) {
18442
- const executor = new RegexExecutor(options2.provider, options2.regex);
18443
- const commands = [...createGrepCommands(executor), createRgCommand(executor, options2.search), sedCommand(options2.sed)];
18457
+ function portableSearchCommands(options3) {
18458
+ const executor = new RegexExecutor(options3.provider, options3.regex);
18459
+ const commands = [...createGrepCommands(executor), createRgCommand(executor, options3.search), sedCommand(options3.sed)];
18444
18460
  return {
18445
18461
  name: "portable-search-commands",
18446
18462
  setup(host) {
18447
- if (!options2.replace) for (const command2 of commands) {
18463
+ if (!options3.replace) for (const command2 of commands) {
18448
18464
  if (host.commands.has(command2.name)) throw new Error(`Command already registered: ${command2.name}`);
18449
18465
  }
18450
- for (const command2 of commands) host.commands.register(command2, { replace: options2.replace ?? false });
18466
+ for (const command2 of commands) host.commands.register(command2, { replace: options3.replace ?? false });
18451
18467
  },
18452
18468
  dispose: () => executor.dispose()
18453
18469
  };
@@ -18456,6 +18472,281 @@ function portableSearchCommands(options2) {
18456
18472
  // packages/safe-bash/src/commands/regex-execution/public.ts
18457
18473
  init_platform();
18458
18474
 
18475
+ // packages/safe-bash/src/commands/regex-execution/bounded-provider.ts
18476
+ init_platform();
18477
+ var defaults2 = Object.freeze({
18478
+ maxWorkers: 2,
18479
+ maxPatterns: 32,
18480
+ maxPatternBytes: 8192,
18481
+ maxRows: 128,
18482
+ maxInputBytes: 65536,
18483
+ maxResultBytes: 2048,
18484
+ maxWork: 2e6,
18485
+ maxAllocationUnits: 1e6,
18486
+ maxStates: 65536
18487
+ });
18488
+ var ceilings = Object.freeze({
18489
+ maxWorkers: 32,
18490
+ maxPatterns: 128,
18491
+ maxPatternBytes: 65532,
18492
+ maxRows: 4096,
18493
+ maxInputBytes: 1048576,
18494
+ maxResultBytes: 65536,
18495
+ maxWork: 33554432,
18496
+ maxAllocationUnits: 4e6,
18497
+ maxStates: 65536
18498
+ });
18499
+ var typedArrayPrototype2 = Object.getPrototypeOf(Uint8Array.prototype);
18500
+ var byteLength = Object.getOwnPropertyDescriptor(typedArrayPrototype2, "byteLength").get;
18501
+ var byteOffset = Object.getOwnPropertyDescriptor(typedArrayPrototype2, "byteOffset").get;
18502
+ var byteBuffer = Object.getOwnPropertyDescriptor(typedArrayPrototype2, "buffer").get;
18503
+ function fail(kind, message2) {
18504
+ throw new Error(`bounded regex ${kind}: ${message2}`);
18505
+ }
18506
+ function record3(value2, keys, optional = []) {
18507
+ if (value2 === null || typeof value2 !== "object" || Array.isArray(value2)) fail("protocol", "expected a data record");
18508
+ const ownKeys = Reflect.ownKeys(value2);
18509
+ if (ownKeys.length < keys.length || ownKeys.length > keys.length + optional.length || ownKeys.some((key) => typeof key !== "string" || !keys.includes(key) && !optional.includes(key))) fail("protocol", "unexpected data-record fields");
18510
+ for (const key of [...keys, ...optional]) {
18511
+ const property = Object.getOwnPropertyDescriptor(value2, key);
18512
+ if (property === void 0 ? keys.includes(key) : !("value" in property)) fail("protocol", "missing field or accessor");
18513
+ }
18514
+ }
18515
+ function array(value2, limit, label) {
18516
+ if (!Array.isArray(value2)) fail("protocol", `${label} must be an array`);
18517
+ if (value2.length > limit) fail("limit", `${label} count limit exceeded`);
18518
+ const keys = Reflect.ownKeys(value2);
18519
+ if (keys.length !== value2.length + 1) fail("protocol", `${label} must be a dense data array`);
18520
+ for (let index = 0; index < value2.length; index++) {
18521
+ const property = Object.getOwnPropertyDescriptor(value2, index);
18522
+ if (!property || !("value" in property)) fail("protocol", `${label} must be a dense data array`);
18523
+ }
18524
+ }
18525
+ function options2(input3) {
18526
+ const keys = Object.keys(defaults2);
18527
+ try {
18528
+ record3(input3, [], keys);
18529
+ } catch {
18530
+ throw new TypeError("bounded regex options require supported own data fields");
18531
+ }
18532
+ const result = { ...defaults2 };
18533
+ for (const key of keys) {
18534
+ if (!Object.hasOwn(input3, key)) continue;
18535
+ const value2 = input3[key];
18536
+ if (typeof value2 !== "number" || !Number.isSafeInteger(value2) || value2 < 1 || value2 > ceilings[key]) throw new RangeError(`bounded regex option ${key} is outside its limit`);
18537
+ result[key] = value2;
18538
+ }
18539
+ return Object.freeze(result);
18540
+ }
18541
+ function descriptor(value2, limits) {
18542
+ if (value2 === null || typeof value2 !== "object") fail("protocol", "invalid descriptor");
18543
+ const kind = Object.getOwnPropertyDescriptor(value2, "kind");
18544
+ if (!kind || !("value" in kind)) fail("protocol", "invalid descriptor kind");
18545
+ if (kind.value !== "grep" && kind.value !== "rg") fail("unsupported", "only grep and fixed rg selection descriptors are supported");
18546
+ const flags = kind.value === "grep" ? ["fixed", "extended", "insensitive", "whole", "word"] : ["fixed", "whole", "word", "nullData"];
18547
+ record3(value2, ["kind", "patterns", ...flags, ...kind.value === "rg" ? ["case"] : []]);
18548
+ for (const flag of flags) if (typeof value2[flag] !== "boolean") fail("protocol", `invalid ${flag} flag`);
18549
+ if (kind.value === "rg" && !["sensitive", "insensitive", "smart"].includes(value2.case)) fail("protocol", "invalid case flag");
18550
+ if (value2.word || kind.value === "grep" && value2.insensitive || kind.value === "rg" && value2.case !== "sensitive") fail("unsupported", "only case-sensitive, non-word selection is supported");
18551
+ if (kind.value === "rg" && !value2.fixed) fail("unsupported", "rg regex and Unicode modes are unsupported; use fixed ASCII patterns");
18552
+ array(value2.patterns, limits.maxPatterns, "pattern");
18553
+ let bytes2 = 0;
18554
+ for (let index = 0; index < value2.patterns.length; index++) {
18555
+ const pattern = value2.patterns[index];
18556
+ if (typeof pattern !== "string") fail("protocol", "patterns must be strings");
18557
+ if (pattern.length > limits.maxPatternBytes - bytes2) fail("limit", "aggregate pattern byte limit exceeded");
18558
+ bytes2 += pattern.length;
18559
+ }
18560
+ return value2;
18561
+ }
18562
+ function admit(input3, limits, signal) {
18563
+ record3(input3, ["id", "descriptor", "rows"]);
18564
+ const selected = descriptor(input3.descriptor, limits);
18565
+ array(input3.rows, limits.maxRows, "row");
18566
+ if (input3.rows.length > Math.floor(limits.maxResultBytes / 16)) fail("limit", "result byte limit exceeded");
18567
+ let bytes2 = 0;
18568
+ for (let index = 0; index < input3.rows.length; index++) {
18569
+ const row = input3.rows[index];
18570
+ record3(row, ["bytes", "all", "terminated"], ["directory", "ancestors"]);
18571
+ if (!(row.bytes instanceof Uint8Array) || typeof row.all !== "boolean" || typeof row.terminated !== "boolean" || Object.hasOwn(row, "directory") && typeof row.directory !== "boolean" || Object.hasOwn(row, "ancestors") && typeof row.ancestors !== "boolean") fail("protocol", "invalid row");
18572
+ if (Object.hasOwn(row, "directory") || Object.hasOwn(row, "ancestors")) fail("unsupported", "glob row flags are unsupported");
18573
+ if (row.all) fail("unsupported", "all-match enumeration is unsupported");
18574
+ const length = byteLength.call(row.bytes);
18575
+ if (length > limits.maxInputBytes - bytes2) fail("limit", "aggregate input byte limit exceeded");
18576
+ bytes2 += length;
18577
+ }
18578
+ const ledger = new EreLedger({ maxExpansionBytes: 1048576, maxExpansionFields: 8192 }, {
18579
+ patternBytes: limits.maxPatternBytes + 4,
18580
+ subjectBytes: limits.maxInputBytes,
18581
+ work: limits.maxWork,
18582
+ allocationUnits: limits.maxAllocationUnits,
18583
+ states: limits.maxStates
18584
+ });
18585
+ ledger.charge("allocationUnits", bytes2 + input3.rows.length * 12 + selected.patterns.length * 2 + 16, signal);
18586
+ const patterns2 = [];
18587
+ for (let index = 0; index < selected.patterns.length; index++) patterns2.push(selected.patterns[index]);
18588
+ const ownedDescriptor = selected.kind === "grep" ? { kind: "grep", patterns: patterns2, fixed: selected.fixed, extended: selected.extended, insensitive: selected.insensitive, whole: selected.whole, word: selected.word } : { kind: "rg", patterns: patterns2, fixed: selected.fixed, case: selected.case, whole: selected.whole, word: selected.word, nullData: selected.nullData };
18589
+ const rows = [];
18590
+ for (let index = 0; index < input3.rows.length; index++) {
18591
+ const row = input3.rows[index];
18592
+ const source = new Uint8Array(byteBuffer.call(row.bytes), byteOffset.call(row.bytes), byteLength.call(row.bytes));
18593
+ const copy2 = new Uint8Array(source.length);
18594
+ copy2.set(source);
18595
+ rows.push({ bytes: copy2, all: false, terminated: row.terminated });
18596
+ }
18597
+ return { id: input3.id, descriptor: ownedDescriptor, rows, ledger };
18598
+ }
18599
+ async function admitBre(pattern, ledger, signal) {
18600
+ let bracket = -1;
18601
+ let member = false;
18602
+ let namedClass = false;
18603
+ for (let index = 0; index < pattern.length; index++) {
18604
+ ledger.charge("work", 1, signal);
18605
+ await ledger.checkpoint(signal);
18606
+ const character = pattern[index];
18607
+ if ("\\()+?{}|".includes(character)) fail("unsupported", "BRE escapes, groups and interval/operator extensions are unsupported; use grep -E");
18608
+ if (bracket >= 0) {
18609
+ if (index === bracket + 1 && character === "^") continue;
18610
+ if (namedClass) {
18611
+ if (character === "]" && pattern[index - 1] === ":") namedClass = false;
18612
+ } else if (character === "]" && member) bracket = -1;
18613
+ else if (character === "[" && pattern[index + 1] === ":") namedClass = true;
18614
+ member = true;
18615
+ } else if (character === "[") {
18616
+ bracket = index;
18617
+ member = false;
18618
+ } else if (character === "^" && index !== 0 || character === "$" && index !== pattern.length - 1) {
18619
+ fail("unsupported", "BRE anchors are supported only at record boundaries");
18620
+ } else if (character === "*" && (index === 0 || index === 1 && pattern[0] === "^")) {
18621
+ fail("unsupported", "BRE leading literal star is unsupported; use fixed matching");
18622
+ }
18623
+ }
18624
+ }
18625
+ async function execute2(input3, signal) {
18626
+ const { descriptor: selected, rows, ledger } = input3;
18627
+ const programs2 = [];
18628
+ for (const pattern of selected.patterns) {
18629
+ if (selected.kind === "grep" && !selected.fixed && !selected.extended) await admitBre(pattern, ledger, signal);
18630
+ if (selected.kind === "rg" && !selected.nullData && pattern.includes("\n")) fail("unsupported", "rg multiline matching is unsupported");
18631
+ ledger.charge("allocationUnits", (selected.whole ? 3 : 1) * 3 + 2, signal);
18632
+ const fragments = selected.whole ? [{ text: "^(", literal: false }, { text: pattern, literal: selected.fixed }, { text: ")$", literal: false }] : [{ text: pattern, literal: selected.fixed }];
18633
+ programs2.push(await compileEre(fragments, ledger, signal));
18634
+ }
18635
+ const results = [];
18636
+ for (const row of rows) {
18637
+ ledger.charge("allocationUnits", row.bytes.length * 2 + 2, signal);
18638
+ const characters = [];
18639
+ for (const byte of row.bytes) {
18640
+ ledger.charge("work", 1, signal);
18641
+ if (byte === 0 || byte > 127) fail("unsupported", "subjects require non-NUL ASCII; Unicode and invalid UTF-8 are unsupported");
18642
+ characters.push(String.fromCharCode(byte));
18643
+ await ledger.checkpoint(signal);
18644
+ }
18645
+ const subject = characters.join("");
18646
+ let span;
18647
+ for (const program of programs2) {
18648
+ const match = await matchEre(program, subject, ledger, signal);
18649
+ if (!match.matched) continue;
18650
+ const candidate = match.captures[0];
18651
+ if (selected.kind === "grep") {
18652
+ span = candidate;
18653
+ break;
18654
+ }
18655
+ if (!span || candidate.start < span.start) span = candidate;
18656
+ }
18657
+ signal.throwIfAborted();
18658
+ results.push(span ? new Float64Array([span.start, span.end]) : new Float64Array());
18659
+ }
18660
+ return { id: input3.id, results };
18661
+ }
18662
+ var CooperativeWorker = class {
18663
+ constructor(limits, release) {
18664
+ this.limits = limits;
18665
+ this.release = release;
18666
+ queueMicrotask(() => {
18667
+ if (!this.#closing) this.emit({ ready: true });
18668
+ });
18669
+ }
18670
+ limits;
18671
+ release;
18672
+ #controller = new AbortController();
18673
+ #listeners = /* @__PURE__ */ new Map();
18674
+ #tasks = /* @__PURE__ */ new Set();
18675
+ #busy = false;
18676
+ #closing;
18677
+ on(event, listener) {
18678
+ if (this.#closing) return;
18679
+ let listeners = this.#listeners.get(event);
18680
+ if (!listeners) {
18681
+ listeners = /* @__PURE__ */ new Set();
18682
+ this.#listeners.set(event, listeners);
18683
+ }
18684
+ listeners.add(listener);
18685
+ }
18686
+ off(event, listener) {
18687
+ this.#listeners.get(event)?.delete(listener);
18688
+ }
18689
+ emit(value2) {
18690
+ for (const listener of this.#listeners.get("message") ?? []) listener(value2);
18691
+ }
18692
+ postMessage(input3) {
18693
+ if (this.#closing) throw new Error("bounded regex worker is closed");
18694
+ if (this.#busy) throw new Error("bounded regex worker is busy");
18695
+ const identity = input3 !== null && typeof input3 === "object" ? Object.getOwnPropertyDescriptor(input3, "id") : void 0;
18696
+ if (!identity || !("value" in identity) || !Number.isSafeInteger(identity.value) || identity.value < 1) fail("protocol", "invalid request identity");
18697
+ const id = identity.value;
18698
+ const submitted = Object.getOwnPropertyDescriptor(input3, "descriptor")?.value;
18699
+ const expression = submitted !== null && typeof submitted === "object" && Object.getOwnPropertyDescriptor(submitted, "kind")?.value === "expr-match";
18700
+ let owned;
18701
+ let failure;
18702
+ try {
18703
+ owned = admit(input3, this.limits, this.#controller.signal);
18704
+ } catch (error) {
18705
+ failure = error instanceof Error ? error.message.slice(0, 512) : "bounded regex protocol: request admission failed";
18706
+ }
18707
+ this.#busy = true;
18708
+ const task = Promise.resolve().then(async () => {
18709
+ let reply;
18710
+ try {
18711
+ this.#controller.signal.throwIfAborted();
18712
+ reply = owned ? await execute2(owned, this.#controller.signal) : { id, error: failure };
18713
+ } catch (error) {
18714
+ reply = { id, error: error instanceof Error ? error.message.slice(0, 512) : "bounded regex request failed" };
18715
+ }
18716
+ if (expression && "error" in reply) reply = { id, operation: "expr-match", category: "unsupported", error: reply.error };
18717
+ owned = void 0;
18718
+ this.#busy = false;
18719
+ if (!this.#closing) this.emit(reply);
18720
+ });
18721
+ this.#tasks.add(task);
18722
+ void task.then(() => this.#tasks.delete(task), () => this.#tasks.delete(task));
18723
+ }
18724
+ terminate() {
18725
+ if (!this.#closing) {
18726
+ this.#closing = Promise.allSettled([...this.#tasks]).then(() => {
18727
+ this.#listeners.clear();
18728
+ this.#tasks.clear();
18729
+ this.release();
18730
+ });
18731
+ this.#controller.abort(new Error("bounded regex worker terminated"));
18732
+ }
18733
+ return this.#closing;
18734
+ }
18735
+ };
18736
+ function createBoundedRegexProvider(input3 = {}) {
18737
+ const limits = options2(input3);
18738
+ let active = 0;
18739
+ return Object.freeze({
18740
+ createWorker() {
18741
+ if (active >= limits.maxWorkers) fail("limit", "worker count limit exceeded");
18742
+ active++;
18743
+ return new CooperativeWorker(limits, () => {
18744
+ active--;
18745
+ });
18746
+ }
18747
+ });
18748
+ }
18749
+
18459
18750
  // packages/safe-bash/src/browser.ts
18460
18751
  function createBrowserCommands() {
18461
18752
  return [
@@ -18466,17 +18757,17 @@ function createBrowserCommands() {
18466
18757
  ...textCommands()
18467
18758
  ];
18468
18759
  }
18469
- function browserCommands(options2 = {}) {
18760
+ function browserCommands(options3 = {}) {
18470
18761
  return {
18471
18762
  name: "browser-commands",
18472
18763
  setup(host) {
18473
18764
  const commands = createBrowserCommands();
18474
- if (!options2.replace) {
18765
+ if (!options3.replace) {
18475
18766
  for (const command2 of commands) {
18476
18767
  if (host.commands.has(command2.name)) throw new Error(`Command already registered: ${command2.name}`);
18477
18768
  }
18478
18769
  }
18479
- for (const command2 of commands) host.commands.register(command2, { replace: options2.replace ?? false });
18770
+ for (const command2 of commands) host.commands.register(command2, { replace: options3.replace ?? false });
18480
18771
  }
18481
18772
  };
18482
18773
  }
@@ -18507,6 +18798,7 @@ export {
18507
18798
  collectText,
18508
18799
  compileEre,
18509
18800
  composeMiddleware,
18801
+ createBoundedRegexProvider,
18510
18802
  createBrowserCommands,
18511
18803
  createBytePipe,
18512
18804
  createCommandArguments,