@poe-platform/safe-bash 0.1.718 → 0.1.719

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/README.md +10 -1
  2. package/dist/safe-bash/chunks/{chunk-FXCEA7NR.js → chunk-2XJFAB3E.js} +2 -2
  3. package/dist/safe-bash/chunks/{chunk-RVYQDJCC.js → chunk-4CEZRUSZ.js} +2 -2
  4. package/dist/safe-bash/chunks/{chunk-N4PN6Z63.js → chunk-FEJYNOYN.js} +4 -3
  5. package/dist/safe-bash/chunks/chunk-FEJYNOYN.js.map +7 -0
  6. package/dist/safe-bash/chunks/{chunk-G5FT6GOL.js → chunk-KR2R6MLR.js} +2 -2
  7. package/dist/safe-bash/chunks/{chunk-4C5H4M64.js → chunk-LEZHTGWK.js} +2 -2
  8. package/dist/safe-bash/chunks/{chunk-MCBWPJRQ.js → chunk-MX6K5URO.js} +2 -2
  9. package/dist/safe-bash/chunks/{chunk-WSCXISXW.js → chunk-RGSI3B5P.js} +2 -2
  10. package/dist/safe-bash/chunks/{chunk-SACGNKFN.js → chunk-T7T3UICV.js} +2 -2
  11. package/dist/safe-bash/chunks/{chunk-HC4S4QZD.js → chunk-TZ53QA73.js} +2 -2
  12. package/dist/safe-bash/chunks/{chunk-LUQYNLH7.js → chunk-UKO4AP3K.js} +2 -2
  13. package/dist/safe-bash/chunks/{chunk-JESM4RK2.js → chunk-UMCWCITQ.js} +4 -3
  14. package/dist/safe-bash/chunks/chunk-UMCWCITQ.js.map +7 -0
  15. package/dist/safe-bash/chunks/{chunk-B5Y7TH7K.js → chunk-VZJ3RTVV.js} +2 -2
  16. package/dist/safe-bash/chunks/{chunk-BM3BGSH7.js → chunk-YJPA2BVP.js} +63 -20
  17. package/dist/safe-bash/chunks/chunk-YJPA2BVP.js.map +7 -0
  18. package/dist/safe-bash/chunks/{chunk-YOUOJRAP.js → chunk-ZHWEPWDW.js} +63 -20
  19. package/dist/safe-bash/chunks/chunk-ZHWEPWDW.js.map +7 -0
  20. package/dist/safe-bash/commands/archive/index.d.ts.map +1 -1
  21. package/dist/safe-bash/commands/archive/index.js +27 -0
  22. package/dist/safe-bash/commands/archive/index.js.map +1 -1
  23. package/dist/safe-bash/commands/archive/options.d.ts +1 -1
  24. package/dist/safe-bash/commands/archive/options.d.ts.map +1 -1
  25. package/dist/safe-bash/commands/archive/options.js +2 -0
  26. package/dist/safe-bash/commands/archive/options.js.map +1 -1
  27. package/dist/safe-bash/commands/csplit/index.browser.js +1 -1
  28. package/dist/safe-bash/commands/internal.d.ts +1 -1
  29. package/dist/safe-bash/commands/internal.d.ts.map +1 -1
  30. package/dist/safe-bash/commands/internal.js +3 -2
  31. package/dist/safe-bash/commands/internal.js.map +1 -1
  32. package/dist/safe-bash/commands/llm/index.browser.js +2 -2
  33. package/dist/safe-bash/commands/network/index.browser.js +2 -2
  34. package/dist/safe-bash/commands/node/index.browser.js +2 -2
  35. package/dist/safe-bash/commands/pandoc/index.js.map +2 -2
  36. package/dist/safe-bash/commands/regex-execution/ascii.d.ts +2 -0
  37. package/dist/safe-bash/commands/regex-execution/ascii.d.ts.map +1 -1
  38. package/dist/safe-bash/commands/regex-execution/ascii.js +4 -0
  39. package/dist/safe-bash/commands/regex-execution/ascii.js.map +1 -1
  40. package/dist/safe-bash/commands/regex-execution/bounded-provider.d.ts.map +1 -1
  41. package/dist/safe-bash/commands/regex-execution/bounded-provider.js +51 -21
  42. package/dist/safe-bash/commands/regex-execution/bounded-provider.js.map +1 -1
  43. package/dist/safe-bash/commands/regex-execution/ere/matcher.d.ts +2 -2
  44. package/dist/safe-bash/commands/regex-execution/ere/matcher.d.ts.map +1 -1
  45. package/dist/safe-bash/commands/regex-execution/ere/matcher.js +23 -9
  46. package/dist/safe-bash/commands/regex-execution/ere/matcher.js.map +1 -1
  47. package/dist/safe-bash/commands/search/grep.d.ts.map +1 -1
  48. package/dist/safe-bash/commands/search/grep.js +99 -4
  49. package/dist/safe-bash/commands/search/grep.js.map +1 -1
  50. package/dist/safe-bash/commands/search/options.d.ts +1 -0
  51. package/dist/safe-bash/commands/search/options.d.ts.map +1 -1
  52. package/dist/safe-bash/commands/search/options.js +4 -1
  53. package/dist/safe-bash/commands/search/options.js.map +1 -1
  54. package/dist/safe-bash/commands/search/rg-command.d.ts.map +1 -1
  55. package/dist/safe-bash/commands/search/rg-command.js +59 -0
  56. package/dist/safe-bash/commands/search/rg-command.js.map +1 -1
  57. package/dist/safe-bash/commands/streams.d.ts.map +1 -1
  58. package/dist/safe-bash/commands/streams.js +32 -12
  59. package/dist/safe-bash/commands/streams.js.map +1 -1
  60. package/dist/safe-bash/commands/text-programs/sed.d.ts.map +1 -1
  61. package/dist/safe-bash/commands/text-programs/sed.js +10 -1
  62. package/dist/safe-bash/commands/text-programs/sed.js.map +1 -1
  63. package/dist/safe-bash/commands/xml/index.browser.js +2 -2
  64. package/dist/safe-bash/commands/yq/index.browser.js +2 -2
  65. package/dist/safe-bash/core.browser.js +230 -23
  66. package/dist/safe-bash/core.browser.js.map +3 -3
  67. package/package.json +2 -2
  68. package/dist/safe-bash/chunks/chunk-BM3BGSH7.js.map +0 -7
  69. package/dist/safe-bash/chunks/chunk-JESM4RK2.js.map +0 -7
  70. package/dist/safe-bash/chunks/chunk-N4PN6Z63.js.map +0 -7
  71. package/dist/safe-bash/chunks/chunk-YOUOJRAP.js.map +0 -7
  72. /package/dist/safe-bash/chunks/{chunk-FXCEA7NR.js.map → chunk-2XJFAB3E.js.map} +0 -0
  73. /package/dist/safe-bash/chunks/{chunk-RVYQDJCC.js.map → chunk-4CEZRUSZ.js.map} +0 -0
  74. /package/dist/safe-bash/chunks/{chunk-G5FT6GOL.js.map → chunk-KR2R6MLR.js.map} +0 -0
  75. /package/dist/safe-bash/chunks/{chunk-4C5H4M64.js.map → chunk-LEZHTGWK.js.map} +0 -0
  76. /package/dist/safe-bash/chunks/{chunk-MCBWPJRQ.js.map → chunk-MX6K5URO.js.map} +0 -0
  77. /package/dist/safe-bash/chunks/{chunk-WSCXISXW.js.map → chunk-RGSI3B5P.js.map} +0 -0
  78. /package/dist/safe-bash/chunks/{chunk-SACGNKFN.js.map → chunk-T7T3UICV.js.map} +0 -0
  79. /package/dist/safe-bash/chunks/{chunk-HC4S4QZD.js.map → chunk-TZ53QA73.js.map} +0 -0
  80. /package/dist/safe-bash/chunks/{chunk-LUQYNLH7.js.map → chunk-UKO4AP3K.js.map} +0 -0
  81. /package/dist/safe-bash/chunks/{chunk-B5Y7TH7K.js.map → chunk-VZJ3RTVV.js.map} +0 -0
@@ -33,6 +33,9 @@ init_platform();
33
33
  function foldAscii(code) {
34
34
  return code >= 65 && code <= 90 ? code + 32 : code;
35
35
  }
36
+ function isAsciiWord(code) {
37
+ return code >= 65 && code <= 90 || code >= 97 && code <= 122 || code >= 48 && code <= 57 || code === 95;
38
+ }
36
39
 
37
40
  // packages/safe-bash/src/commands/expr/bre-engine.ts
38
41
  init_platform();
@@ -8804,7 +8807,7 @@ async function matchEre(program, subject, ledger, signal) {
8804
8807
  await admitAscii(subject, ledger, signal);
8805
8808
  return runMatcher(program, subject, ledger, signal, 0, true);
8806
8809
  }
8807
- async function prepareUtf8EreSubject(bytes2, ledger, signal) {
8810
+ async function prepareUtf8EreSubject(bytes2, ledger, signal, leftmostFirst = false, word = false) {
8808
8811
  ledger.check(signal);
8809
8812
  ledger.admitInput("subjectBytes", bytes2.length, signal);
8810
8813
  ledger.charge("allocationUnits", bytes2.length * 11 + 16, signal);
@@ -8815,7 +8818,7 @@ async function prepareUtf8EreSubject(bytes2, ledger, signal) {
8815
8818
  const offsets = [];
8816
8819
  for (let offset = 0; offset < owned.length; ) {
8817
8820
  const first = owned[offset];
8818
- const width = first < 128 ? 1 : first < 224 ? 2 : first < 240 ? 3 : 4;
8821
+ const width = word || first < 128 ? 1 : first < 224 ? 2 : first < 240 ? 3 : 4;
8819
8822
  ledger.charge("work", width, signal);
8820
8823
  await ledger.checkpoint(signal);
8821
8824
  offsets.push(offset);
@@ -8840,14 +8843,14 @@ async function prepareUtf8EreSubject(bytes2, ledger, signal) {
8840
8843
  else upper = middle;
8841
8844
  }
8842
8845
  if (offsets[lower] !== start) throw new RangeError("UTF-8 ERE cursor must be a scalar boundary");
8843
- const span = await runMatcher(program, subject, ledger, signal, lower, false);
8846
+ const span = await runMatcher(program, subject, ledger, signal, lower, false, leftmostFirst, word);
8844
8847
  if (!span) return void 0;
8845
8848
  ledger.charge("allocationUnits", 2, signal);
8846
8849
  return Object.freeze({ start: offsets[span.start], end: offsets[span.end] });
8847
8850
  };
8848
8851
  };
8849
8852
  }
8850
- async function runMatcher(program, subject, ledger, signal, from, materialize) {
8853
+ async function runMatcher(program, subject, ledger, signal, from, materialize, leftmostFirst = false, word = false) {
8851
8854
  const root = resolveEreProgram(program, ledger);
8852
8855
  const width = program.groups + 1;
8853
8856
  ledger.charge("work", width * 2, signal);
@@ -8866,6 +8869,11 @@ async function runMatcher(program, subject, ledger, signal, from, materialize) {
8866
8869
  pending.push({ position, task: next, captures, histories });
8867
8870
  };
8868
8871
  for (let start = from; start <= subject.length; start++) {
8872
+ if (word) {
8873
+ ledger.charge("work", 1, signal);
8874
+ await ledger.checkpoint(signal);
8875
+ if (isAsciiWord(subject.charCodeAt(start - 1))) continue;
8876
+ }
8869
8877
  push(start, task(() => ({ kind: "node", node: root, next: null })), emptyCaptures, emptyHistories);
8870
8878
  let best;
8871
8879
  while (pending.length > 0) {
@@ -8874,6 +8882,11 @@ async function runMatcher(program, subject, ledger, signal, from, materialize) {
8874
8882
  const state = pending.pop();
8875
8883
  const current = state.task;
8876
8884
  if (current === null) {
8885
+ if (word && isAsciiWord(subject.charCodeAt(state.position))) continue;
8886
+ if (leftmostFirst) {
8887
+ best = state;
8888
+ break;
8889
+ }
8877
8890
  if (!best || await preferred(state, best, ledger, signal)) best = state;
8878
8891
  continue;
8879
8892
  }
@@ -8915,7 +8928,7 @@ async function runMatcher(program, subject, ledger, signal, from, materialize) {
8915
8928
  case "literal":
8916
8929
  case "set": {
8917
8930
  const code = subject.charCodeAt(state.position);
8918
- if (state.position < subject.length && (node.kind === "dot" || node.kind === "literal" && (node.insensitive ? foldAscii(node.code) === foldAscii(code) : node.code === code) || node.kind === "set" && (code < 128 ? node.members[code] : node.nonAscii))) {
8931
+ if (state.position < subject.length && (node.kind === "dot" && (!leftmostFirst || code !== 10) || node.kind === "literal" && (node.insensitive ? foldAscii(node.code) === foldAscii(code) : node.code === code) || node.kind === "set" && (code < 128 ? node.members[code] : node.nonAscii))) {
8919
8932
  push(state.position + 1, current.next, state.captures, state.histories);
8920
8933
  }
8921
8934
  break;
@@ -9059,13 +9072,12 @@ function descriptor(value, limits) {
9059
9072
  if (value === null || typeof value !== "object") fail("protocol", "invalid descriptor");
9060
9073
  const kind = Object.getOwnPropertyDescriptor(value, "kind");
9061
9074
  if (!kind || !("value" in kind)) fail("protocol", "invalid descriptor kind");
9062
- if (kind.value !== "grep" && kind.value !== "rg") fail("unsupported", "only grep and fixed rg selection descriptors are supported");
9075
+ if (kind.value !== "grep" && kind.value !== "rg") fail("unsupported", "only grep and rg selection descriptors are supported");
9063
9076
  const flags = kind.value === "grep" ? ["fixed", "extended", "insensitive", "whole", "word"] : ["fixed", "whole", "word", "nullData"];
9064
9077
  record(value, ["kind", "patterns", ...flags, ...kind.value === "rg" ? ["case"] : []]);
9065
9078
  for (const flag of flags) if (typeof value[flag] !== "boolean") fail("protocol", `invalid ${flag} flag`);
9066
9079
  if (kind.value === "rg" && !["sensitive", "insensitive", "smart"].includes(value.case)) fail("protocol", "invalid case flag");
9067
- if (value.word || kind.value === "rg" && value.case !== "sensitive") fail("unsupported", "word matching and rg case-insensitive selection are unsupported");
9068
- if (kind.value === "rg" && !value.fixed) fail("unsupported", "rg regex modes are unsupported; use fixed UTF-8 patterns");
9080
+ if (kind.value === "rg" && (value.word || value.case !== "sensitive")) fail("unsupported", "rg word matching and case-insensitive selection are unsupported");
9069
9081
  array(value.patterns, limits.maxPatterns, "pattern");
9070
9082
  let bytes2 = 0;
9071
9083
  for (let index = 0; index < value.patterns.length; index++) {
@@ -9087,7 +9099,6 @@ function admit(input, limits, signal) {
9087
9099
  record(row, ["bytes", "all", "terminated"], ["directory", "ancestors"]);
9088
9100
  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");
9089
9101
  if (Object.hasOwn(row, "directory") || Object.hasOwn(row, "ancestors")) fail("unsupported", "glob row flags are unsupported");
9090
- if (row.all && selected.kind !== "grep") fail("unsupported", "rg all-match enumeration is unsupported");
9091
9102
  const length = byteLength.call(row.bytes);
9092
9103
  if (length > limits.maxInputBytes - bytes2) fail("limit", "aggregate input byte limit exceeded");
9093
9104
  bytes2 += length;
@@ -9271,17 +9282,28 @@ async function compileLiteral(bytes2, ledger, signal, insensitive = false) {
9271
9282
  }
9272
9283
  return { bytes: bytes2, fallback, insensitive };
9273
9284
  }
9274
- async function literalStart(program, subject, whole, ledger, signal, from = 0) {
9285
+ async function literalStart(program, subject, whole, word, ledger, signal, from = 0) {
9275
9286
  const { bytes: bytes2, fallback } = program;
9276
9287
  ledger.charge("work", 1, signal);
9277
9288
  await ledger.checkpoint(signal);
9278
9289
  if (whole && (from !== 0 || bytes2.length !== subject.length) || bytes2.length > subject.length - from) return -1;
9279
- if (bytes2.length === 0) return from;
9290
+ if (bytes2.length === 0) {
9291
+ for (let start = from; start <= subject.length; start++) {
9292
+ ledger.charge("work", 1, signal);
9293
+ await ledger.checkpoint(signal);
9294
+ if (!word || !isAsciiWord(subject[start - 1] ?? -1) && !isAsciiWord(subject[start] ?? -1)) return start;
9295
+ }
9296
+ return -1;
9297
+ }
9280
9298
  for (let index = from, prefix = 0; index < subject.length; ) {
9281
9299
  ledger.charge("work", 1, signal);
9282
9300
  if ((program.insensitive ? foldAscii(subject[index]) : subject[index]) === bytes2[prefix]) {
9283
9301
  index++;
9284
- if (++prefix === bytes2.length) return index - prefix;
9302
+ if (++prefix === bytes2.length) {
9303
+ const start = index - prefix;
9304
+ if (!word || !isAsciiWord(subject[start - 1] ?? -1) && !isAsciiWord(subject[index] ?? -1)) return start;
9305
+ prefix = fallback[prefix - 1];
9306
+ }
9285
9307
  } else if (prefix > 0) prefix = fallback[prefix - 1];
9286
9308
  else index++;
9287
9309
  await ledger.checkpoint(signal);
@@ -9293,6 +9315,9 @@ async function enumerate(input, row, finders, usage, signal) {
9293
9315
  ledger.charge("allocationUnits", finders.length + 2, signal);
9294
9316
  const cached = new Array(finders.length);
9295
9317
  const ranges = [];
9318
+ const byteEmpty = input.descriptor.kind === "rg" && !input.descriptor.whole && input.descriptor.patterns.length === 1 && input.descriptor.patterns[0] === "";
9319
+ const byteCursor = input.descriptor.kind === "grep" && input.descriptor.word;
9320
+ let previousEnd = -1;
9296
9321
  for (let from = 0; from <= row.bytes.length; ) {
9297
9322
  let best;
9298
9323
  for (let index = 0; index < finders.length; index++) {
@@ -9303,9 +9328,14 @@ async function enumerate(input, row, finders, usage, signal) {
9303
9328
  candidate = await finders[index](from) ?? null;
9304
9329
  cached[index] = candidate;
9305
9330
  }
9306
- if (candidate && (!best || candidate.start < best.start || candidate.start === best.start && candidate.end > best.end)) best = candidate;
9331
+ if (candidate && (!best || candidate.start < best.start || input.descriptor.kind === "grep" && candidate.start === best.start && candidate.end > best.end)) best = candidate;
9332
+ }
9333
+ if (!best || byteEmpty && !row.terminated && best.start === row.bytes.length) break;
9334
+ if (input.descriptor.kind === "rg" && !byteEmpty && best.start === best.end && best.start === previousEnd) {
9335
+ const byte = row.bytes[best.end];
9336
+ from = best.end + (byte === void 0 || byte < 128 ? 1 : byte < 224 ? 2 : byte < 240 ? 3 : 4);
9337
+ continue;
9307
9338
  }
9308
- if (!best) break;
9309
9339
  if (ranges.length / 2 >= limits.maxMatchesPerLine) fail("limit", "matches per line limit exceeded");
9310
9340
  if (usage.count >= limits.maxTotalMatches) fail("limit", "total match limit exceeded");
9311
9341
  if (usage.count >= Math.floor(limits.maxResultBytes / 16)) fail("limit", "result byte limit exceeded");
@@ -9313,10 +9343,11 @@ async function enumerate(input, row, finders, usage, signal) {
9313
9343
  ledger.charge("allocationUnits", 24, signal);
9314
9344
  usage.count++;
9315
9345
  ranges.push(best.start, best.end);
9346
+ previousEnd = best.end;
9316
9347
  if (best.end > best.start) from = best.end;
9317
9348
  else {
9318
9349
  const byte = row.bytes[best.end];
9319
- from = best.end + (byte === void 0 || byte < 128 ? 1 : byte < 224 ? 2 : byte < 240 ? 3 : 4);
9350
+ from = best.end + (byteEmpty || byteCursor || byte === void 0 || byte < 128 ? 1 : byte < 224 ? 2 : byte < 240 ? 3 : 4);
9320
9351
  }
9321
9352
  }
9322
9353
  ledger.charge("work", ranges.length, signal);
@@ -9337,7 +9368,7 @@ async function executeLiteral(input, signal) {
9337
9368
  if (row.all) {
9338
9369
  ledger.charge("allocationUnits", programs2.length * 2, signal);
9339
9370
  const finders = programs2.map((program) => async (from) => {
9340
- const start2 = await literalStart(program, row.bytes, selected.whole, ledger, signal, from);
9371
+ const start2 = await literalStart(program, row.bytes, selected.whole, selected.word, ledger, signal, from);
9341
9372
  if (start2 < 0) return void 0;
9342
9373
  ledger.charge("allocationUnits", 2, signal);
9343
9374
  return { start: start2, end: start2 + program.bytes.length };
@@ -9348,7 +9379,7 @@ async function executeLiteral(input, signal) {
9348
9379
  let start = -1;
9349
9380
  let end = -1;
9350
9381
  for (const program of programs2) {
9351
- const candidate = await literalStart(program, row.bytes, selected.whole, ledger, signal);
9382
+ const candidate = await literalStart(program, row.bytes, selected.whole, selected.word, ledger, signal);
9352
9383
  if (candidate < 0) continue;
9353
9384
  if (start < 0 || candidate < start) {
9354
9385
  start = candidate;
@@ -9367,7 +9398,19 @@ async function executeLiteral(input, signal) {
9367
9398
  }
9368
9399
  async function execute(input, signal) {
9369
9400
  const { descriptor: selected, rows, ledger } = input;
9370
- if (selected.fixed) return executeLiteral(input, signal);
9401
+ let literal = selected.fixed;
9402
+ if (!literal && selected.kind === "rg") {
9403
+ literal = true;
9404
+ patterns: for (const pattern of selected.patterns) {
9405
+ ledger.charge("work", pattern.length, signal);
9406
+ await ledger.checkpoint(signal);
9407
+ for (const character of pattern) if ("\\.^$[]()|*+?{}".includes(character)) {
9408
+ literal = false;
9409
+ break patterns;
9410
+ }
9411
+ }
9412
+ }
9413
+ if (literal) return executeLiteral(input, signal);
9371
9414
  const programs2 = [];
9372
9415
  for (const pattern of selected.patterns) {
9373
9416
  if (selected.kind === "rg" && !selected.nullData && pattern.includes("\n")) fail("unsupported", "rg multiline matching is unsupported");
@@ -9385,7 +9428,7 @@ async function execute(input, signal) {
9385
9428
  const results = [];
9386
9429
  const usage = { count: 0 };
9387
9430
  for (const row of rows) {
9388
- const subject = await prepareUtf8EreSubject(row.bytes, ledger, signal);
9431
+ const subject = await prepareUtf8EreSubject(row.bytes, ledger, signal, selected.kind === "rg", selected.word);
9389
9432
  if (row.all) {
9390
9433
  ledger.charge("allocationUnits", programs2.length + 1, signal);
9391
9434
  const finders = [];
@@ -12157,4 +12200,4 @@ export {
12157
12200
  createCsplitCommands,
12158
12201
  csplitCommands
12159
12202
  };
12160
- //# sourceMappingURL=chunk-YOUOJRAP.js.map
12203
+ //# sourceMappingURL=chunk-ZHWEPWDW.js.map