@poe-platform/safe-bash 0.1.801 → 0.1.803

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 (198) hide show
  1. package/README.md +4 -2
  2. package/dist/image-ast/index.browser.js +16 -5
  3. package/dist/image-ast/index.js +16 -5
  4. package/dist/safe-bash/chunks/chunk-2LSAMQER.js +84 -0
  5. package/dist/safe-bash/chunks/chunk-3HQU4OJO.js +13 -0
  6. package/dist/safe-bash/chunks/chunk-4BSJLKNM.js +14 -0
  7. package/dist/safe-bash/chunks/chunk-4D4N7IU2.js +47 -0
  8. package/dist/safe-bash/chunks/chunk-55YJASTN.js +14 -0
  9. package/dist/safe-bash/chunks/{chunk-NZQXYWA3.js → chunk-5OHX7C2V.js} +0 -1
  10. package/dist/safe-bash/chunks/chunk-7ZBU7KYV.js +14 -0
  11. package/dist/safe-bash/chunks/{chunk-7VNF5BFF.js → chunk-B7PIL77G.js} +101 -415
  12. package/dist/safe-bash/chunks/chunk-DQP3VHSB.js +15 -0
  13. package/dist/safe-bash/chunks/{chunk-VQDD3G76.js → chunk-EEEWOYEG.js} +18 -18
  14. package/dist/safe-bash/chunks/chunk-FZE4HW6G.js +11 -0
  15. package/dist/safe-bash/chunks/{chunk-45PK3NWI.js → chunk-GDYNCWRV.js} +1 -1
  16. package/dist/safe-bash/chunks/chunk-GEG3BWGE.js +14 -0
  17. package/dist/safe-bash/chunks/chunk-HBCN24ZA.js +50 -0
  18. package/dist/safe-bash/chunks/chunk-HZ7BWKQ3.js +13 -0
  19. package/dist/safe-bash/chunks/{chunk-ICFDYV64.js → chunk-HZAMGT5I.js} +2 -2
  20. package/dist/safe-bash/chunks/{chunk-FNDNHAGE.js → chunk-JMMEIDPF.js} +2 -2
  21. package/dist/safe-bash/chunks/{chunk-IVRQ4BXL.js → chunk-PH63PLPZ.js} +7 -7
  22. package/dist/safe-bash/chunks/{chunk-SZH7EJLD.js → chunk-PNBBUWSM.js} +5529 -6547
  23. package/dist/safe-bash/chunks/chunk-QGUV42T5.js +44 -0
  24. package/dist/safe-bash/chunks/chunk-R3NAKOED.js +51 -0
  25. package/dist/safe-bash/chunks/chunk-RRR7AQ24.js +38 -0
  26. package/dist/safe-bash/chunks/{chunk-PQRAK7HU.js → chunk-RYFQ3LZG.js} +281 -476
  27. package/dist/safe-bash/chunks/chunk-VBTDHOWC.js +55 -0
  28. package/dist/safe-bash/chunks/{chunk-NR3EM4LS.js → chunk-VKNVHEX3.js} +1 -6
  29. package/dist/safe-bash/chunks/chunk-XAQMU6OY.js +14 -0
  30. package/dist/safe-bash/chunks/chunk-ZVD5IS4V.js +49 -0
  31. package/dist/safe-bash/command-chunks/{chunk-ORYGZYKW.js → chunk-4FEVBOL5.js} +1 -1
  32. package/dist/safe-bash/command-chunks/{chunk-VXSLJH7G.js → chunk-6JSIFWYT.js} +26 -6
  33. package/dist/safe-bash/command-chunks/chunk-A7MU7762.js +200 -0
  34. package/dist/safe-bash/command-chunks/{chunk-KJIMDLBB.js → chunk-BXCXRYVU.js} +1 -1
  35. package/dist/safe-bash/command-chunks/{chunk-F4TEEZTL.js → chunk-CQHP3I66.js} +1 -1
  36. package/dist/safe-bash/command-chunks/{chunk-PEF7K3UQ.js → chunk-EARHPPPJ.js} +1 -1
  37. package/dist/safe-bash/command-chunks/{chunk-QKFSRZGQ.js → chunk-GFC2NTDG.js} +2 -2
  38. package/dist/safe-bash/command-chunks/chunk-GIRNFXP3.js +466 -0
  39. package/dist/safe-bash/command-chunks/{chunk-EFANWIHL.js → chunk-GY3BWK7K.js} +1 -0
  40. package/dist/safe-bash/command-chunks/{chunk-FPVUD6TH.js → chunk-HDCNKOIX.js} +9 -7
  41. package/dist/safe-bash/command-chunks/{chunk-MQFIPHIQ.js → chunk-ILX2NOLF.js} +18 -15
  42. package/dist/safe-bash/command-chunks/{chunk-5E4WAO4O.js → chunk-JD5QNRNO.js} +3 -3
  43. package/dist/safe-bash/command-chunks/{chunk-I237SNW5.js → chunk-LFJJQQND.js} +1 -1
  44. package/dist/safe-bash/command-chunks/{chunk-W5DNF4JH.js → chunk-LOICUCHG.js} +1 -1
  45. package/dist/safe-bash/command-chunks/{chunk-7U7EXOXX.js → chunk-NASVPT6F.js} +2 -1
  46. package/dist/safe-bash/command-chunks/{chunk-WBNZ4PRE.js → chunk-NGG2XL56.js} +7 -4
  47. package/dist/safe-bash/command-chunks/{chunk-GLOZX57Y.js → chunk-NKIELG7Y.js} +45 -115
  48. package/dist/safe-bash/command-chunks/{chunk-WPYIOKE3.js → chunk-PICVQ6B5.js} +2 -2
  49. package/dist/safe-bash/command-chunks/{chunk-YOFC45RK.js → chunk-QVOS4YXL.js} +1 -1
  50. package/dist/safe-bash/command-chunks/{chunk-VGG2DL5Q.js → chunk-TRR4MYWF.js} +4 -0
  51. package/dist/safe-bash/command-chunks/{chunk-2JRBIDAD.js → chunk-V4K2JDYU.js} +2 -2
  52. package/dist/safe-bash/command-chunks/{chunk-CZ7EN3JG.js → chunk-VT6MJBEI.js} +1 -1
  53. package/dist/safe-bash/command-chunks/{chunk-PCEFOYA3.js → chunk-WWIBP2ET.js} +41 -114
  54. package/dist/safe-bash/command-chunks/{chunk-F6OYH562.js → chunk-X54L3DBL.js} +4 -9
  55. package/dist/safe-bash/command-chunks/{chunk-TNOA7FCQ.js → chunk-YVNGTIJO.js} +1 -1
  56. package/dist/safe-bash/command-chunks/chunk-ZDN7MJE6.js +168 -0
  57. package/dist/safe-bash/commands/apply-patch/index.browser.js +14 -0
  58. package/dist/safe-bash/commands/archive/index.browser.js +36 -0
  59. package/dist/safe-bash/commands/bytes/compression/index.js +54 -51
  60. package/dist/safe-bash/commands/chmod/index.browser.js +14 -0
  61. package/dist/safe-bash/commands/chmod/index.d.ts +2 -0
  62. package/dist/safe-bash/commands/chmod/index.js +2 -0
  63. package/dist/safe-bash/commands/column/index.browser.js +12 -0
  64. package/dist/safe-bash/commands/du/index.browser.js +14 -0
  65. package/dist/safe-bash/commands/expr/index.browser.js +12 -0
  66. package/dist/safe-bash/commands/file/index.browser.js +14 -0
  67. package/dist/safe-bash/commands/filesystem.js +9 -2
  68. package/dist/safe-bash/commands/grep-aliases/index.browser.js +14 -0
  69. package/dist/safe-bash/commands/html-to-markdown/index.browser.js +16 -0
  70. package/dist/safe-bash/commands/metadata/chmod.d.ts +1 -7
  71. package/dist/safe-bash/commands/metadata/chmod.js +1 -204
  72. package/dist/safe-bash/commands/metadata/index.browser.js +17 -0
  73. package/dist/safe-bash/commands/metadata/internal.d.ts +1 -30
  74. package/dist/safe-bash/commands/metadata/internal.js +1 -76
  75. package/dist/safe-bash/commands/metadata/mktemp.d.ts +1 -3
  76. package/dist/safe-bash/commands/metadata/mktemp.js +1 -202
  77. package/dist/safe-bash/commands/metadata/stat.d.ts +1 -7
  78. package/dist/safe-bash/commands/metadata/stat.js +1 -530
  79. package/dist/safe-bash/commands/mktemp/index.browser.js +13 -0
  80. package/dist/safe-bash/commands/mktemp/index.d.ts +2 -0
  81. package/dist/safe-bash/commands/mktemp/index.js +2 -0
  82. package/dist/safe-bash/commands/network/index.browser.js +1 -1
  83. package/dist/safe-bash/commands/node/index.browser.js +4 -4
  84. package/dist/safe-bash/commands/portable-random.d.ts +1 -1
  85. package/dist/safe-bash/commands/portable-random.js +1 -12
  86. package/dist/safe-bash/commands/python/index.browser.js +8 -8
  87. package/dist/safe-bash/commands/regex-execution/public.browser.js +5 -3
  88. package/dist/safe-bash/commands/split/index.browser.js +14 -0
  89. package/dist/safe-bash/commands/stat/index.browser.js +13 -0
  90. package/dist/safe-bash/commands/stat/index.d.ts +2 -0
  91. package/dist/safe-bash/commands/stat/index.js +2 -0
  92. package/dist/safe-bash/commands/stream-format/index.browser.js +11 -0
  93. package/dist/safe-bash/commands/stream-inspection/index.browser.js +11 -0
  94. package/dist/safe-bash/commands/streams.js +5 -5
  95. package/dist/safe-bash/commands/table-text/index.browser.js +11 -0
  96. package/dist/safe-bash/commands/text.js +48 -143
  97. package/dist/safe-bash/commands/time-env/index.browser.js +15 -0
  98. package/dist/safe-bash/commands/tree/index.browser.js +14 -0
  99. package/dist/safe-bash/full-core.browser.js +256 -247
  100. package/dist/safe-bash/opt-in/commands/yq/native-work.js +1 -0
  101. package/dist/safe-bash/optional-host.browser.js +12 -12
  102. package/dist/safe-bash/plugins/index.browser.js +25 -11
  103. package/dist/safe-bash/registry-entry.browser.js +28 -14
  104. package/dist/safe-bash/search.browser.js +48 -0
  105. package/dist/safe-bash/shell/runtime.d.ts +3 -9
  106. package/dist/safe-bash/shell/runtime.js +63 -311
  107. package/dist/safe-bash/shell/shell.js +0 -23
  108. package/dist/safe-bash/shell/types.d.ts +2 -0
  109. package/dist/safe-bash/shell/worker-limits.js +1 -0
  110. package/dist/safe-bash/shell-entry.browser.js +19 -10
  111. package/dist/safe-bash/worker/host.js +1 -1
  112. package/dist/safe-bash-command-bc/index.js +12 -5
  113. package/dist/safe-bash-command-bzip2/index.js +4 -3
  114. package/dist/safe-bash-command-chmod/LICENSE +21 -0
  115. package/dist/safe-bash-command-chmod/command.d.ts +7 -0
  116. package/dist/safe-bash-command-chmod/command.js +11 -0
  117. package/dist/safe-bash-command-chmod/index.d.ts +6 -0
  118. package/dist/safe-bash-command-chmod/index.js +27 -0
  119. package/dist/safe-bash-command-exiftool/index.js +5 -5
  120. package/dist/safe-bash-command-find/find.js +1 -1
  121. package/dist/safe-bash-command-find/index.js +1 -1
  122. package/dist/safe-bash-command-fmt/index.js +9 -2
  123. package/dist/safe-bash-command-gzip/index.js +45 -42
  124. package/dist/safe-bash-command-imagemagick/index.js +3 -1
  125. package/dist/safe-bash-command-jq/index.js +1 -1
  126. package/dist/safe-bash-command-jq/jq.js +1 -1
  127. package/dist/safe-bash-command-less/index.js +12 -3
  128. package/dist/safe-bash-command-mktemp/LICENSE +21 -0
  129. package/dist/safe-bash-command-mktemp/command.d.ts +3 -0
  130. package/dist/safe-bash-command-mktemp/command.js +9 -0
  131. package/dist/safe-bash-command-mktemp/index.d.ts +6 -0
  132. package/dist/safe-bash-command-mktemp/index.js +25 -0
  133. package/dist/safe-bash-command-nl/index.js +1 -1
  134. package/dist/safe-bash-command-nl/nl.js +1 -1
  135. package/dist/safe-bash-command-od/index.js +6 -2
  136. package/dist/safe-bash-command-op/index.js +25 -6
  137. package/dist/safe-bash-command-rg/index.js +1 -1
  138. package/dist/safe-bash-command-rg/rg-command.d.ts +0 -1
  139. package/dist/safe-bash-command-rg/rg-command.js +3 -5
  140. package/dist/safe-bash-command-sed/index.js +1 -1
  141. package/dist/safe-bash-command-sed/sed.js +1 -1
  142. package/dist/safe-bash-command-sips/index.js +13 -5
  143. package/dist/safe-bash-command-sponge/index.js +10 -3
  144. package/dist/safe-bash-command-stat/LICENSE +21 -0
  145. package/dist/safe-bash-command-stat/command.d.ts +7 -0
  146. package/dist/safe-bash-command-stat/command.js +9 -0
  147. package/dist/safe-bash-command-stat/index.d.ts +6 -0
  148. package/dist/safe-bash-command-stat/index.js +25 -0
  149. package/dist/safe-bash-command-unexpand/index.js +1 -1
  150. package/dist/safe-bash-command-unexpand/unexpand.js +1 -1
  151. package/dist/safe-bash-command-unrtf/index.js +11 -1
  152. package/dist/safe-bash-command-xxd/index.js +6 -2
  153. package/dist/safe-bash-command-xz/command.d.ts +1 -1
  154. package/dist/safe-bash-command-xz/index.js +3 -2
  155. package/dist/safe-bash-command-yq/index.js +1 -0
  156. package/dist/safe-bash-command-yq/native-work.js +1 -0
  157. package/dist/safe-bash-command-yq/query.js +3 -0
  158. package/dist/safe-bash-compression-engine/bounded-codec.js +3 -3
  159. package/dist/safe-bash-compression-engine/codec-loader.js +2 -2
  160. package/dist/safe-bash-compression-engine/files.js +6 -6
  161. package/dist/safe-bash-compression-engine/index.js +5 -5
  162. package/dist/safe-bash-compression-engine/operand.js +6 -6
  163. package/dist/safe-bash-compression-engine/options.js +1 -1
  164. package/dist/safe-bash-compression-engine/stream.js +5 -5
  165. package/dist/safe-bash-compression-engine/zstd-decode.js +4 -4
  166. package/dist/safe-bash-contracts/escaping.js +2 -2
  167. package/dist/safe-bash-contracts/filesystem-output.js +2 -2
  168. package/dist/safe-bash-contracts/index.js +2 -2
  169. package/dist/safe-bash-contracts/io.d.ts +2 -0
  170. package/dist/safe-bash-contracts/io.js +1 -1
  171. package/dist/safe-bash-contracts/output.js +2 -2
  172. package/dist/safe-bash-io-engine/commands/search/requirements.js +1 -1
  173. package/dist/safe-bash-io-engine/commands/text-programs/shared.js +1 -1
  174. package/dist/safe-bash-mcp/index.browser.js +11 -1
  175. package/dist/safe-bash-mcp/index.js +38 -17
  176. package/dist/safe-bash-metadata-engine/LICENSE +21 -0
  177. package/dist/safe-bash-metadata-engine/index.d.ts +30 -0
  178. package/dist/safe-bash-metadata-engine/index.js +82 -0
  179. package/dist/safe-bash-metadata-engine/random.d.ts +1 -0
  180. package/dist/safe-bash-metadata-engine/random.js +21 -0
  181. package/dist/safe-bash-regex-engine/index.js +4 -4
  182. package/dist/safe-bash-regex-engine/text/budget.d.ts +0 -1
  183. package/dist/safe-bash-regex-engine/text/budget.js +1 -1
  184. package/dist/safe-bash-regex-engine/text/regex.js +4 -4
  185. package/dist/safe-bash-regex-engine/text/replacement-buffer.js +2 -2
  186. package/dist/safe-bash-regex-engine/text/rust-syntax.js +2 -2
  187. package/dist/safe-bash-search-engine/ergonomic-regex.js +2 -2
  188. package/dist/safe-bash-search-engine/glob.js +2 -2
  189. package/dist/safe-bash-search-engine/grep.js +2 -2
  190. package/dist/safe-bash-search-engine/matcher.js +2 -2
  191. package/dist/safe-bash-search-engine/options.d.ts +2 -0
  192. package/dist/safe-bash-search-engine/options.js +1 -1
  193. package/dist/safe-bash-search-engine/output.js +1 -1
  194. package/dist/safe-bash-search-engine/shared.js +2 -2
  195. package/dist/safe-bash-search-engine/walk.js +3 -3
  196. package/dist/safe-playwright-cloudflare/browser-snapshot-json.js +2 -2
  197. package/dist/safe-playwright-cloudflare/browser-snapshot-references.js +1 -1
  198. package/package.json +91 -10
@@ -0,0 +1,14 @@
1
+ import {
2
+ createSplitCommand,
3
+ createSplitCommands,
4
+ evalSyncSplit,
5
+ splitCommands
6
+ } from "../../chunks/chunk-7ZBU7KYV.js";
7
+ import "../../chunks/chunk-IWDICZVK.js";
8
+ import "../../chunks/chunk-B7TAL7S5.js";
9
+ export {
10
+ createSplitCommand,
11
+ createSplitCommands,
12
+ evalSyncSplit,
13
+ splitCommands
14
+ };
@@ -0,0 +1,13 @@
1
+ import {
2
+ init_platform
3
+ } from "../../chunks/chunk-B7TAL7S5.js";
4
+
5
+ // packages/safe-bash/src/commands/stat/index.ts
6
+ init_platform();
7
+ import { createStatCommand, createStatCommands, evalSyncStat, statCommands } from "../../../safe-bash-command-stat/index.js";
8
+ export {
9
+ createStatCommand,
10
+ createStatCommands,
11
+ evalSyncStat,
12
+ statCommands
13
+ };
@@ -0,0 +1,2 @@
1
+ export * from "../../../safe-bash-command-stat/index.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,2 @@
1
+ export * from "../../../safe-bash-command-stat/index.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,11 @@
1
+ import {
2
+ createStreamFormatCommands,
3
+ streamFormatCommands
4
+ } from "../../chunks/chunk-R3NAKOED.js";
5
+ import "../../chunks/chunk-E7OYNDGL.js";
6
+ import "../../chunks/chunk-IWDICZVK.js";
7
+ import "../../chunks/chunk-B7TAL7S5.js";
8
+ export {
9
+ createStreamFormatCommands,
10
+ streamFormatCommands
11
+ };
@@ -0,0 +1,11 @@
1
+ import {
2
+ createStreamInspectionCommands,
3
+ streamInspectionCommands
4
+ } from "../../chunks/chunk-HBCN24ZA.js";
5
+ import "../../chunks/chunk-E7OYNDGL.js";
6
+ import "../../chunks/chunk-IWDICZVK.js";
7
+ import "../../chunks/chunk-B7TAL7S5.js";
8
+ export {
9
+ createStreamInspectionCommands,
10
+ streamInspectionCommands
11
+ };
@@ -450,14 +450,14 @@ async function suffix(context, source, count, bytes, omit, delimiter) {
450
450
  const needed = line.bytes.length + (line.terminated ? 1 : 0);
451
451
  if (needed > batch.length) {
452
452
  if (batchUsed > 0) {
453
- await output(context, batch.subarray(0, batchUsed));
453
+ await outputRange(context, batch, batchUsed);
454
454
  batchUsed = 0;
455
455
  }
456
456
  await output(context, line.terminated ? concatenate([line.bytes, delimiterByte]) : line.bytes);
457
457
  continue;
458
458
  }
459
459
  if (batchUsed + needed > batch.length) {
460
- await output(context, batch.subarray(0, batchUsed));
460
+ await outputRange(context, batch, batchUsed);
461
461
  batchUsed = 0;
462
462
  }
463
463
  batch.set(line.bytes, batchUsed);
@@ -466,7 +466,7 @@ async function suffix(context, source, count, bytes, omit, delimiter) {
466
466
  batch[batchUsed++] = delimiter;
467
467
  }
468
468
  if (batchUsed > 0) {
469
- await output(context, batch.subarray(0, batchUsed));
469
+ await outputRange(context, batch, batchUsed);
470
470
  }
471
471
  }
472
472
  return;
@@ -1100,7 +1100,7 @@ async function executeTrAsync(context, iter, deleting, squeezing, mapping, remov
1100
1100
  if (!deleting && !squeezing) {
1101
1101
  for (let index = 0; index < chunk.length; index++)
1102
1102
  buf[index] = mapping[chunk[index]];
1103
- const p = output(context, useShared ? buf.subarray(0, chunk.length) : buf);
1103
+ const p = useShared ? outputRange(context, buf, chunk.length) : output(context, buf);
1104
1104
  if (!isSyncResolved(p))
1105
1105
  await p;
1106
1106
  continue;
@@ -1117,7 +1117,7 @@ async function executeTrAsync(context, iter, deleting, squeezing, mapping, remov
1117
1117
  previous = translated;
1118
1118
  }
1119
1119
  if (count) {
1120
- const p = output(context, buf.subarray(0, count));
1120
+ const p = outputRange(context, buf, count);
1121
1121
  if (!isSyncResolved(p))
1122
1122
  await p;
1123
1123
  }
@@ -0,0 +1,11 @@
1
+ import {
2
+ createTableTextCommands,
3
+ tableTextCommands
4
+ } from "../../chunks/chunk-4D4N7IU2.js";
5
+ import "../../chunks/chunk-E7OYNDGL.js";
6
+ import "../../chunks/chunk-IWDICZVK.js";
7
+ import "../../chunks/chunk-B7TAL7S5.js";
8
+ export {
9
+ createTableTextCommands,
10
+ tableTextCommands
11
+ };
@@ -8,6 +8,20 @@ import { hasYieldCheckpoint, yieldTurn } from "../contracts/yield.js";
8
8
  import { RecordBuffer } from "./record-buffer.js";
9
9
  import { SortRecordBudget } from "./sort-admission.js";
10
10
  import { compareObservedEntries } from "./copy-identity.js";
11
+ function sortCollator(env) {
12
+ const locale = env.LC_ALL || env.LC_COLLATE || env.LANG || "C";
13
+ if (["C", "POSIX", "C.UTF-8", "C.utf8"].includes(locale))
14
+ return undefined;
15
+ const language = locale.split(".")[0].split("_").join("-");
16
+ try {
17
+ if (!Intl.Collator.supportedLocalesOf([language]).length || locale.includes("@"))
18
+ throw new RangeError();
19
+ return new Intl.Collator(language, { usage: "sort", sensitivity: "variant", caseFirst: "lower" });
20
+ }
21
+ catch {
22
+ throw new UsageError(`unsupported collation locale '${locale}'`);
23
+ }
24
+ }
11
25
  class SortWork {
12
26
  signal;
13
27
  #pending = 0;
@@ -1093,7 +1107,7 @@ async function collectSortRecords(source, delimiter, budget, signal, accept) {
1093
1107
  pending.clear();
1094
1108
  }
1095
1109
  }
1096
- async function executeSortGeneral(context, preReadChunks) {
1110
+ async function executeSortGeneral(context, preReadChunks, collator = sortCollator(context.env)) {
1097
1111
  let ended = false;
1098
1112
  let hasCheckLong = false;
1099
1113
  for (let i = 0; i < context.args.length; i++) {
@@ -1159,6 +1173,24 @@ async function executeSortGeneral(context, preReadChunks) {
1159
1173
  const simple = !keys.length && !["b", "f", "h", "n", "g", "M", "V", "d", "i"].some(flag => parsed.flags.has(flag));
1160
1174
  const direction = parsed.flags.has("r") ? -1 : 1;
1161
1175
  const work = new SortWork(context.signal);
1176
+ const decoder = collator ? new TextDecoder("utf-8", { fatal: true }) : undefined;
1177
+ const compareText = collator ? async (left, right, work) => {
1178
+ await work.charge(left.length + right.length);
1179
+ let first, second;
1180
+ try {
1181
+ first = decoder.decode(left);
1182
+ }
1183
+ catch { /* Invalid UTF-8 sorts after valid text. */ }
1184
+ try {
1185
+ second = decoder.decode(right);
1186
+ }
1187
+ catch { /* Keep invalid records byte-ordered. */ }
1188
+ if (first === undefined)
1189
+ return second === undefined ? compareSortBytes(left, right, work) : 1;
1190
+ if (second === undefined)
1191
+ return -1;
1192
+ return collator.compare(first, second);
1193
+ } : compareSortBytes;
1162
1194
  const numericKey = keys.length === 1 ? keys[0] : undefined;
1163
1195
  const numericKeyFlags = numericKey?.flags.size ? numericKey.flags : parsed.flags;
1164
1196
  const skipTieFallback = simple || parsed.flags.has("s") || parsed.flags.has("u");
@@ -1166,7 +1198,8 @@ async function executeSortGeneral(context, preReadChunks) {
1166
1198
  const exitCode = 0;
1167
1199
  const delimiter = parsed.flags.has("z") ? 0 : 10;
1168
1200
  const outPath = value(parsed, "o");
1169
- const canFastIndexSort = !preReadChunks &&
1201
+ const canFastIndexSort = collator === undefined &&
1202
+ !preReadChunks &&
1170
1203
  !checking &&
1171
1204
  !hasYieldCheckpoint(context.signal) &&
1172
1205
  !parsed.flags.has("m") &&
@@ -1395,7 +1428,7 @@ async function executeSortGeneral(context, preReadChunks) {
1395
1428
  else if (flags.has("V"))
1396
1429
  result = await compareVersions(first, second, work);
1397
1430
  else
1398
- result = flags.has("n") || flags.has("h") ? await compareNumeric(first, second, flags.has("h")) : await compareSortBytes(first, second, work);
1431
+ result = flags.has("n") || flags.has("h") ? await compareNumeric(first, second, flags.has("h")) : await compareText(first, second, work);
1399
1432
  if (flags.has("r"))
1400
1433
  result = -result;
1401
1434
  if (result)
@@ -1405,7 +1438,7 @@ async function executeSortGeneral(context, preReadChunks) {
1405
1438
  };
1406
1439
  const keyCompareSimpleAsync = async (left, right, checkpoint) => {
1407
1440
  await checkpoint;
1408
- return (await compareSortBytes(left, right, work)) * direction;
1441
+ return (await compareText(left, right, work)) * direction;
1409
1442
  };
1410
1443
  const compareUnkeyedNumericAsync = async (left, right, rightPending) => {
1411
1444
  const leftValue = await left;
@@ -1417,7 +1450,7 @@ async function executeSortGeneral(context, preReadChunks) {
1417
1450
  if (simple) {
1418
1451
  if (checkpoint)
1419
1452
  return keyCompareSimpleAsync(left, right, checkpoint);
1420
- const cmp = compareSortBytes(left, right, work);
1453
+ const cmp = compareText(left, right, work);
1421
1454
  return typeof cmp === "number" ? cmp * direction : resolveScaledAfterPromise(cmp, direction);
1422
1455
  }
1423
1456
  if (isUnkeyedNumericFast && checkpoint === undefined) {
@@ -1459,7 +1492,7 @@ async function executeSortGeneral(context, preReadChunks) {
1459
1492
  await checkpoint;
1460
1493
  const first = await (firstPending ?? getKeyedLexSlice(left));
1461
1494
  const second = await (secondPending ?? getKeyedLexSlice(right));
1462
- return (await compareSortBytes(first, second, work)) * lexRev;
1495
+ return (await compareText(first, second, work)) * lexRev;
1463
1496
  };
1464
1497
  keyCompare = (left, right) => {
1465
1498
  const checkpoint = work.charge();
@@ -1470,7 +1503,7 @@ async function executeSortGeneral(context, preReadChunks) {
1470
1503
  if (!(first instanceof Promise)) {
1471
1504
  second = getKeyedLexSlice(right);
1472
1505
  if (!(second instanceof Promise)) {
1473
- const cmp = compareSortBytes(first, second, work);
1506
+ const cmp = compareText(first, second, work);
1474
1507
  if (typeof cmp === "number")
1475
1508
  return cmp * lexRev;
1476
1509
  return resolveScaledAfterPromise(cmp, lexRev);
@@ -1643,7 +1676,7 @@ async function executeSortGeneral(context, preReadChunks) {
1643
1676
  const rs = ev.evalLexSync(right);
1644
1677
  if (rs === undefined)
1645
1678
  return keyCompareGeneralAsync(left, right, undefined);
1646
- const cmp = compareSortBytes(ls, rs, work);
1679
+ const cmp = compareText(ls, rs, work);
1647
1680
  if (typeof cmp !== "number")
1648
1681
  return keyCompareGeneralAsync(left, right, undefined);
1649
1682
  if (cmp !== 0)
@@ -1657,14 +1690,14 @@ async function executeSortGeneral(context, preReadChunks) {
1657
1690
  const resolved = await resultPromise;
1658
1691
  if (resolved !== 0 || skipTieFallback)
1659
1692
  return resolved;
1660
- return (await compareSortBytes(left, right, work)) * direction;
1693
+ return (await compareText(left, right, work)) * direction;
1661
1694
  };
1662
1695
  const compare = (left, right) => {
1663
1696
  const result = keyCompare(left, right);
1664
1697
  if (typeof result === "number") {
1665
1698
  if (result !== 0 || skipTieFallback)
1666
1699
  return result;
1667
- const fallback = compareSortBytes(left, right, work);
1700
+ const fallback = compareText(left, right, work);
1668
1701
  return typeof fallback === "number" ? fallback * direction : resolveScaledAfterPromise(fallback, direction);
1669
1702
  }
1670
1703
  return compareSlowAsync(result, left, right);
@@ -1704,138 +1737,7 @@ async function executeSortGeneral(context, preReadChunks) {
1704
1737
  }
1705
1738
  if (checking)
1706
1739
  return { exitCode };
1707
- let ordered;
1708
- if (!parsed.flags.has("m") &&
1709
- !parsed.flags.has("u") &&
1710
- records.length >= 2 &&
1711
- records.length <= 65536 &&
1712
- (canMultiKeyFast || isSingleLexKeyFast)) {
1713
- const count = records.length;
1714
- const keySpecs = keys.map(k => {
1715
- const f = k.flags.size ? k.flags : parsed.flags;
1716
- const numeric = f.has("n") || f.has("h");
1717
- const human = f.has("h");
1718
- const blanks = f.has("b");
1719
- const revScale = f.has("r") ? -1 : 1;
1720
- if (numeric) {
1721
- const fastNums = new Float64Array(count);
1722
- const numVals = new Array(count);
1723
- return { numeric: true, human, blanks, revScale, key: k, fastNums, numVals };
1724
- }
1725
- const slices = new Array(count);
1726
- return { numeric: false, blanks, revScale, key: k, slices };
1727
- });
1728
- for (let i = 0; i < count; i++) {
1729
- const rec = records[i];
1730
- for (let ki = 0; ki < keySpecs.length; ki++) {
1731
- const ks = keySpecs[ki];
1732
- const sliceOrPromise = keyBytesSync(rec, ks.key, separator, ks.blanks, work);
1733
- const slice = sliceOrPromise instanceof Promise ? await sliceOrPromise : sliceOrPromise;
1734
- if (ks.numeric) {
1735
- const parsedOrPromise = parseNumeric(slice, work, ks.human);
1736
- const nv = parsedOrPromise instanceof Promise ? await parsedOrPromise : parsedOrPromise;
1737
- ks.numVals[i] = nv;
1738
- if (!ks.human && nv.fraction.length === 0 && nv.whole.length <= 15) {
1739
- const mag = nv.whole.length === 0 ? 0 : Number(nv.whole);
1740
- ks.fastNums[i] = nv.negative ? (mag === 0 ? 0 : -mag) : mag;
1741
- }
1742
- else {
1743
- ks.fastNums[i] = Number.NaN;
1744
- }
1745
- }
1746
- else {
1747
- ks.slices[i] = slice;
1748
- }
1749
- }
1750
- }
1751
- let srcIdx = new Int32Array(count);
1752
- let dstIdx = new Int32Array(count);
1753
- for (let i = 0; i < count; i++)
1754
- srcIdx[i] = i;
1755
- for (let width = 1; width < count; width *= 2) {
1756
- for (let begin = 0; begin < count; begin += width * 2) {
1757
- const middle = Math.min(begin + width, count);
1758
- const end = Math.min(begin + width * 2, count);
1759
- let left = begin;
1760
- let right = middle;
1761
- for (let index = begin; index < end; index++) {
1762
- const cp = work.charge(2);
1763
- if (cp)
1764
- await cp;
1765
- if (left < middle) {
1766
- if (right === end) {
1767
- dstIdx[index] = srcIdx[left++];
1768
- continue;
1769
- }
1770
- const a = srcIdx[left];
1771
- const b = srcIdx[right];
1772
- let cmp = 0;
1773
- for (let ki = 0; ki < keySpecs.length; ki++) {
1774
- const ks = keySpecs[ki];
1775
- if (ks.numeric) {
1776
- const fa = ks.fastNums[a];
1777
- const fb = ks.fastNums[b];
1778
- if (fa === fa && fb === fb) {
1779
- cmp = fa === fb ? 0 : (fa < fb ? -ks.revScale : ks.revScale);
1780
- }
1781
- else {
1782
- const r = compareNumericValues(ks.numVals[a], ks.numVals[b], work);
1783
- const resolved = typeof r === "number" ? r : await r;
1784
- cmp = resolved * ks.revScale;
1785
- }
1786
- }
1787
- else {
1788
- const sa = ks.slices[a];
1789
- const sb = ks.slices[b];
1790
- const lenA = sa.length;
1791
- const lenB = sb.length;
1792
- const minL = lenA < lenB ? lenA : lenB;
1793
- let d = 0;
1794
- for (let p = 0; p < minL; p++) {
1795
- d = sa[p] - sb[p];
1796
- if (d !== 0)
1797
- break;
1798
- }
1799
- if (d === 0)
1800
- d = lenA - lenB;
1801
- cmp = d * ks.revScale;
1802
- }
1803
- if (cmp !== 0)
1804
- break;
1805
- }
1806
- if (cmp === 0 && !skipTieFallback) {
1807
- const ra = records[a];
1808
- const rb = records[b];
1809
- const minL = ra.length < rb.length ? ra.length : rb.length;
1810
- let d = 0;
1811
- for (let p = 0; p < minL; p++) {
1812
- d = ra[p] - rb[p];
1813
- if (d !== 0)
1814
- break;
1815
- }
1816
- if (d === 0)
1817
- d = ra.length - rb.length;
1818
- cmp = d * direction;
1819
- }
1820
- if (cmp <= 0) {
1821
- dstIdx[index] = srcIdx[left++];
1822
- continue;
1823
- }
1824
- }
1825
- dstIdx[index] = srcIdx[right++];
1826
- }
1827
- }
1828
- const tmp = srcIdx;
1829
- srcIdx = dstIdx;
1830
- dstIdx = tmp;
1831
- }
1832
- ordered = new Array(count);
1833
- for (let i = 0; i < count; i++)
1834
- ordered[i] = records[srcIdx[i]];
1835
- }
1836
- else {
1837
- ordered = parsed.flags.has("m") ? await mergeSortRuns(runs, compare, work) : await sortRecords(records, compare, work);
1838
- }
1740
+ const ordered = parsed.flags.has("m") ? await mergeSortRuns(runs, compare, work) : await sortRecords(records, compare, work);
1839
1741
  let estBytes = 0;
1840
1742
  let allCounted = true;
1841
1743
  for (let i = 0; i < ordered.length; i++) {
@@ -2040,7 +1942,7 @@ async function executeCutGeneral(context) {
2040
1942
  const canFastSliceCut = (byteSelection || mode === "c") && !complement && ranges.length <= 16;
2041
1943
  const processFastSliceRange = (buf, lineStart, lineEnd) => {
2042
1944
  const lineLen = lineEnd - lineStart;
2043
- if (writer.remaining <= lineLen * (outDelimLen > 1 ? outDelimLen : 1) + 1) {
1945
+ if (writer.remaining <= lineLen + (outputDelimiter !== undefined ? Math.max(0, ranges.length - 1) * outDelimLen : 0) + 1) {
2044
1946
  return null;
2045
1947
  }
2046
1948
  if (!byteSelection) {
@@ -2465,6 +2367,9 @@ async function executeUniqGeneral(context, preReadSource) {
2465
2367
  export function textCommands() {
2466
2368
  return [
2467
2369
  define("sort", context => {
2370
+ const collator = sortCollator(context.env);
2371
+ if (collator)
2372
+ return executeSortGeneral(context, undefined, collator);
2468
2373
  if ((context.args.length === 0 || (context.args.length === 1 && context.args[0] === "-r")) &&
2469
2374
  !hasYieldCheckpoint(context.signal) &&
2470
2375
  SortRecordBudget.prototype.admit === defaultSortAdmit &&
@@ -0,0 +1,15 @@
1
+ import {
2
+ createTimeEnvCommands,
3
+ evalSyncDate,
4
+ evalSyncPrintenv,
5
+ timeEnvCommands
6
+ } from "../../chunks/chunk-ZVD5IS4V.js";
7
+ import "../../chunks/chunk-E7OYNDGL.js";
8
+ import "../../chunks/chunk-IWDICZVK.js";
9
+ import "../../chunks/chunk-B7TAL7S5.js";
10
+ export {
11
+ createTimeEnvCommands,
12
+ evalSyncDate,
13
+ evalSyncPrintenv,
14
+ timeEnvCommands
15
+ };
@@ -0,0 +1,14 @@
1
+ import {
2
+ createTreeCommand,
3
+ createTreeCommands,
4
+ evalSyncTree,
5
+ treeCommands
6
+ } from "../../chunks/chunk-55YJASTN.js";
7
+ import "../../chunks/chunk-IWDICZVK.js";
8
+ import "../../chunks/chunk-B7TAL7S5.js";
9
+ export {
10
+ createTreeCommand,
11
+ createTreeCommands,
12
+ evalSyncTree,
13
+ treeCommands
14
+ };