@poe-platform/safe-bash 0.1.792 → 0.1.794

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 (43) hide show
  1. package/dist/safe-bash/chunks/{chunk-BENDQWMV.js → chunk-6IBTC4YL.js} +16 -2
  2. package/dist/safe-bash/chunks/{chunk-6AKPBNRF.js → chunk-6P25QN5M.js} +20 -25
  3. package/dist/safe-bash/chunks/{chunk-DVSLGXQU.js → chunk-C2NYCU7O.js} +2 -1
  4. package/dist/safe-bash/command-chunks/{chunk-JCORWQ2I.js → chunk-7FKUC34S.js} +1 -1
  5. package/dist/safe-bash/command-chunks/{chunk-ZJB7XJXD.js → chunk-XAFSZDY2.js} +1 -1
  6. package/dist/safe-bash/command-chunks/{chunk-UVHLUL62.js → chunk-YFSDDFGV.js} +42 -12
  7. package/dist/safe-bash/commands/llm/index.browser.js +3 -1
  8. package/dist/safe-bash/commands/python/index.browser.js +1 -1
  9. package/dist/safe-bash/commands/python/llm-capability.js +11 -2
  10. package/dist/safe-bash/commands/python/llm-module.js +6 -0
  11. package/dist/safe-bash/contracts/escaping.d.ts +2 -0
  12. package/dist/safe-bash/contracts/escaping.js +2 -0
  13. package/dist/safe-bash/core.browser.js +1 -1
  14. package/dist/safe-bash/full-core.browser.js +5 -3
  15. package/dist/safe-bash/opt-in/optional/commands/shuf/args.js +270 -168
  16. package/dist/safe-bash/opt-in/optional/commands/shuf/filesystem-output.js +19 -1
  17. package/dist/safe-bash/opt-in/optional/commands/shuf/input.js +121 -5
  18. package/dist/safe-bash/opt-in/optional/commands/shuf/random.d.ts +3 -0
  19. package/dist/safe-bash/opt-in/optional/commands/shuf/random.js +31 -23
  20. package/dist/safe-bash/opt-in/optional/commands/shuf/shuf.js +39 -37
  21. package/dist/safe-bash/shell/runtime.d.ts +1 -1
  22. package/dist/safe-bash/shell/runtime.js +14 -20
  23. package/dist/safe-bash/shell-entry.browser.js +1 -1
  24. package/dist/safe-bash-command-llm/command.js +1 -1
  25. package/dist/safe-bash-command-llm/index.d.ts +1 -1
  26. package/dist/safe-bash-command-llm/index.js +3 -1
  27. package/dist/safe-bash-command-llm/model-selection.d.ts +5 -0
  28. package/dist/safe-bash-command-shuf/args.d.ts +6 -4
  29. package/dist/safe-bash-command-shuf/args.js +270 -168
  30. package/dist/safe-bash-command-shuf/filesystem-output.js +19 -1
  31. package/dist/safe-bash-command-shuf/input.d.ts +19 -1
  32. package/dist/safe-bash-command-shuf/input.js +121 -5
  33. package/dist/safe-bash-command-shuf/random.d.ts +3 -0
  34. package/dist/safe-bash-command-shuf/random.js +31 -23
  35. package/dist/safe-bash-command-shuf/shuf.js +39 -37
  36. package/dist/safe-bash-command-sqlite3/btree.d.ts +1 -1
  37. package/dist/safe-bash-command-sqlite3/engine.d.ts +1 -1
  38. package/dist/safe-bash-command-sqlite3/index.js +61 -63
  39. package/dist/safe-bash-io-engine/commands/search/requirements.js +2 -2
  40. package/dist/safe-bash-io-engine/commands/text-programs/shared.js +2 -2
  41. package/dist/safe-bash-io-engine/internal.js +1 -1
  42. package/package.json +3 -3
  43. package/dist/safe-bash-command-llm/models-list.d.ts +0 -10
@@ -1,24 +1,7 @@
1
- const sharedEncoder = new TextEncoder();
2
- const Buffer = {
3
- from(input) {
4
- return typeof input === "string" ? sharedEncoder.encode(input) : new Uint8Array(input);
5
- },
6
- concat(chunks) {
7
- let total = 0;
8
- for (const c of chunks)
9
- total += c.byteLength;
10
- const out = new Uint8Array(total);
11
- let offset = 0;
12
- for (const c of chunks) {
13
- out.set(c, offset);
14
- offset += c.byteLength;
15
- }
16
- return out;
17
- }
18
- };
19
1
  import { getCommandArguments } from "../safe-bash-contracts/index.js";
20
2
  export const wordMax = (1n << 64n) - 1n;
21
- export const countMax = (1n << 63n) - 1n;
3
+ export const countMax = wordMax;
4
+ const unsignedMaximum = wordMax;
22
5
  export class Diagnostic extends Error {
23
6
  bytes;
24
7
  constructor(message, bytes) {
@@ -26,172 +9,291 @@ export class Diagnostic extends Error {
26
9
  this.bytes = bytes;
27
10
  }
28
11
  }
29
- export function quote(value) {
30
- let result = "'";
31
- const escapes = { "\n": "\\n", "\r": "\\r", "\t": "\\t", "\b": "\\b", "\f": "\\f", "\v": "\\v", "\u0007": "\\a", "\\": "\\\\", "'": "\\'" };
32
- for (const code of typeof value === "string" ? Buffer.from(value) : value) {
33
- const character = String.fromCharCode(code);
34
- result += escapes[character] ?? (code < 32 || code >= 127 ? `\\${code.toString(8).padStart(3, "0")}` : character);
12
+ class ShufDiagnostic extends Diagnostic {
13
+ constructor(detail, usage = false) {
14
+ const bytes = Uint8Array.from(`shuf: ${detail}\n${usage ? "Try 'shuf --help' for more information.\n" : ""}`, character => character.charCodeAt(0));
15
+ super(new TextDecoder().decode(bytes), bytes);
35
16
  }
36
- return `${result}'`;
37
17
  }
38
- export function fileQuote(value) {
39
- if (value && value !== "{" && value !== "}" && !"#~".includes(value[0]) && Array.from(value).every(character => "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_+-./,%#@]{}~".includes(character)))
40
- return value;
41
- if (!value.includes("'") && !Array.from(value).some(character => character.charCodeAt(0) < 32 || character.charCodeAt(0) >= 127))
42
- return `'${value}'`;
43
- if (value.includes("'") && !Array.from(value).some(character => "!\"$&()*;<=>?[\\^`|".includes(character) || character.charCodeAt(0) < 32 || character.charCodeAt(0) >= 127))
44
- return `"${value}"`;
45
- let result = "'";
46
- let escaped = false;
47
- for (const code of Buffer.from(value)) {
48
- const character = String.fromCharCode(code);
49
- const control = code < 32 || code >= 127;
50
- if (control !== escaped) {
51
- result += control ? "'$'" : "''";
52
- escaped = control;
18
+ const glibc231PrintableRanges = [
19
+ 0x20, 0x7e, 0xa0, 0x377, 0x37a, 0x37f, 0x384, 0x38a, 0x38c, 0x38c, 0x38e, 0x3a1, 0x3a3, 0x52f, 0x531, 0x556,
20
+ 0x559, 0x55f, 0x561, 0x587, 0x589, 0x58a, 0x58d, 0x58f, 0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0xecd, 0xed0, 0xed9, 0xedc, 0xedf, 0xf00, 0xf47,
40
+ 0xf49, 0xf6c, 0xf71, 0xf97, 0xf99, 0xfbc, 0xfbe, 0xfcc, 0xfce, 0xfda, 0x1000, 0x10c5, 0x10c7, 0x10c7, 0x10cd, 0x10cd,
41
+ 0x10d0, 0x1248, 0x124a, 0x124d, 0x1250, 0x1256, 0x1258, 0x1258, 0x125a, 0x125d, 0x1260, 0x1288, 0x128a, 0x128d, 0x1290, 0x12b0,
42
+ 0x12b2, 0x12b5, 0x12b8, 0x12be, 0x12c0, 0x12c0, 0x12c2, 0x12c5, 0x12c8, 0x12d6, 0x12d8, 0x1310, 0x1312, 0x1315, 0x1318, 0x135a,
43
+ 0x135d, 0x137c, 0x1380, 0x1399, 0x13a0, 0x13f5, 0x13f8, 0x13fd, 0x1400, 0x169c, 0x16a0, 0x16f8, 0x1700, 0x170c, 0x170e, 0x1714,
44
+ 0x1720, 0x1736, 0x1740, 0x1753, 0x1760, 0x176c, 0x176e, 0x1770, 0x1772, 0x1773, 0x1780, 0x17dd, 0x17e0, 0x17e9, 0x17f0, 0x17f9,
45
+ 0x1800, 0x180e, 0x1810, 0x1819, 0x1820, 0x1877, 0x1880, 0x18aa, 0x18b0, 0x18f5, 0x1900, 0x191e, 0x1920, 0x192b, 0x1930, 0x193b,
46
+ 0x1940, 0x1940, 0x1944, 0x196d, 0x1970, 0x1974, 0x1980, 0x19ab, 0x19b0, 0x19c9, 0x19d0, 0x19da, 0x19de, 0x1a1b, 0x1a1e, 0x1a5e,
47
+ 0x1a60, 0x1a7c, 0x1a7f, 0x1a89, 0x1a90, 0x1a99, 0x1aa0, 0x1aad, 0x1ab0, 0x1abe, 0x1b00, 0x1b4b, 0x1b50, 0x1b7c, 0x1b80, 0x1bf3,
48
+ 0x1bfc, 0x1c37, 0x1c3b, 0x1c49, 0x1c4d, 0x1c88, 0x1cc0, 0x1cc7, 0x1cd0, 0x1cf6, 0x1cf8, 0x1cf9, 0x1d00, 0x1df5, 0x1dfb, 0x1f15,
49
+ 0x1f18, 0x1f1d, 0x1f20, 0x1f45, 0x1f48, 0x1f4d, 0x1f50, 0x1f57, 0x1f59, 0x1f59, 0x1f5b, 0x1f5b, 0x1f5d, 0x1f5d, 0x1f5f, 0x1f7d,
50
+ 0x1f80, 0x1fb4, 0x1fb6, 0x1fc4, 0x1fc6, 0x1fd3, 0x1fd6, 0x1fdb, 0x1fdd, 0x1fef, 0x1ff2, 0x1ff4, 0x1ff6, 0x1ffe, 0x2000, 0x2027,
51
+ 0x202a, 0x2064, 0x2066, 0x2071, 0x2074, 0x208e, 0x2090, 0x209c, 0x20a0, 0x20be, 0x20d0, 0x20f0, 0x2100, 0x218b, 0x2190, 0x23fe,
52
+ 0x2400, 0x2426, 0x2440, 0x244a, 0x2460, 0x2b73, 0x2b76, 0x2b95, 0x2b98, 0x2bb9, 0x2bbd, 0x2bc8, 0x2bca, 0x2bd1, 0x2bec, 0x2bef,
53
+ 0x2c00, 0x2c2e, 0x2c30, 0x2c5e, 0x2c60, 0x2cf3, 0x2cf9, 0x2d25, 0x2d27, 0x2d27, 0x2d2d, 0x2d2d, 0x2d30, 0x2d67, 0x2d6f, 0x2d70,
54
+ 0x2d7f, 0x2d96, 0x2da0, 0x2da6, 0x2da8, 0x2dae, 0x2db0, 0x2db6, 0x2db8, 0x2dbe, 0x2dc0, 0x2dc6, 0x2dc8, 0x2dce, 0x2dd0, 0x2dd6,
55
+ 0x2dd8, 0x2dde, 0x2de0, 0x2e44, 0x2e80, 0x2e99, 0x2e9b, 0x2ef3, 0x2f00, 0x2fd5, 0x2ff0, 0x2ffb, 0x3000, 0x303f, 0x3041, 0x3096,
56
+ 0x3099, 0x30ff, 0x3105, 0x312d, 0x3131, 0x318e, 0x3190, 0x31ba, 0x31c0, 0x31e3, 0x31f0, 0x321e, 0x3220, 0x32fe, 0x3300, 0x4db5,
57
+ 0x4dc0, 0x9fd5, 0xa000, 0xa48c, 0xa490, 0xa4c6, 0xa4d0, 0xa62b, 0xa640, 0xa6f7, 0xa700, 0xa7ae, 0xa7b0, 0xa7b7, 0xa7f7, 0xa82b,
58
+ 0xa830, 0xa839, 0xa840, 0xa877, 0xa880, 0xa8c5, 0xa8ce, 0xa8d9, 0xa8e0, 0xa8fd, 0xa900, 0xa953, 0xa95f, 0xa97c, 0xa980, 0xa9cd,
59
+ 0xa9cf, 0xa9d9, 0xa9de, 0xa9fe, 0xaa00, 0xaa36, 0xaa40, 0xaa4d, 0xaa50, 0xaa59, 0xaa5c, 0xaac2, 0xaadb, 0xaaf6, 0xab01, 0xab06,
60
+ 0xab09, 0xab0e, 0xab11, 0xab16, 0xab20, 0xab26, 0xab28, 0xab2e, 0xab30, 0xab65, 0xab70, 0xabed, 0xabf0, 0xabf9, 0xac00, 0xd7a3,
61
+ 0xd7b0, 0xd7c6, 0xd7cb, 0xd7fb, 0xe000, 0xfa6d, 0xfa70, 0xfad9, 0xfb00, 0xfb06, 0xfb13, 0xfb17, 0xfb1d, 0xfb36, 0xfb38, 0xfb3c,
62
+ 0xfb3e, 0xfb3e, 0xfb40, 0xfb41, 0xfb43, 0xfb44, 0xfb46, 0xfbc1, 0xfbd3, 0xfd3f, 0xfd50, 0xfd8f, 0xfd92, 0xfdc7, 0xfdf0, 0xfdfd,
63
+ 0xfe00, 0xfe19, 0xfe20, 0xfe52, 0xfe54, 0xfe66, 0xfe68, 0xfe6b, 0xfe70, 0xfe74, 0xfe76, 0xfefc, 0xfeff, 0xfeff, 0xff01, 0xffbe,
64
+ 0xffc2, 0xffc7, 0xffca, 0xffcf, 0xffd2, 0xffd7, 0xffda, 0xffdc, 0xffe0, 0xffe6, 0xffe8, 0xffee, 0xfff9, 0xfffd, 0x10000, 0x1000b,
65
+ 0x1000d, 0x10026, 0x10028, 0x1003a, 0x1003c, 0x1003d, 0x1003f, 0x1004d, 0x10050, 0x1005d, 0x10080, 0x100fa, 0x10100, 0x10102, 0x10107, 0x10133,
66
+ 0x10137, 0x1018e, 0x10190, 0x1019b, 0x101a0, 0x101a0, 0x101d0, 0x101fd, 0x10280, 0x1029c, 0x102a0, 0x102d0, 0x102e0, 0x102fb, 0x10300, 0x10323,
67
+ 0x10330, 0x1034a, 0x10350, 0x1037a, 0x10380, 0x1039d, 0x1039f, 0x103c3, 0x103c8, 0x103d5, 0x10400, 0x1049d, 0x104a0, 0x104a9, 0x104b0, 0x104d3,
68
+ 0x104d8, 0x104fb, 0x10500, 0x10527, 0x10530, 0x10563, 0x1056f, 0x1056f, 0x10600, 0x10736, 0x10740, 0x10755, 0x10760, 0x10767, 0x10800, 0x10805,
69
+ 0x10808, 0x10808, 0x1080a, 0x10835, 0x10837, 0x10838, 0x1083c, 0x1083c, 0x1083f, 0x10855, 0x10857, 0x1089e, 0x108a7, 0x108af, 0x108e0, 0x108f2,
70
+ 0x108f4, 0x108f5, 0x108fb, 0x1091b, 0x1091f, 0x10939, 0x1093f, 0x1093f, 0x10980, 0x109b7, 0x109bc, 0x109cf, 0x109d2, 0x10a03, 0x10a05, 0x10a06,
71
+ 0x10a0c, 0x10a13, 0x10a15, 0x10a17, 0x10a19, 0x10a33, 0x10a38, 0x10a3a, 0x10a3f, 0x10a47, 0x10a50, 0x10a58, 0x10a60, 0x10a9f, 0x10ac0, 0x10ae6,
72
+ 0x10aeb, 0x10af6, 0x10b00, 0x10b35, 0x10b39, 0x10b55, 0x10b58, 0x10b72, 0x10b78, 0x10b91, 0x10b99, 0x10b9c, 0x10ba9, 0x10baf, 0x10c00, 0x10c48,
73
+ 0x10c80, 0x10cb2, 0x10cc0, 0x10cf2, 0x10cfa, 0x10cff, 0x10e60, 0x10e7e, 0x11000, 0x1104d, 0x11052, 0x1106f, 0x1107f, 0x110c1, 0x110d0, 0x110e8,
74
+ 0x110f0, 0x110f9, 0x11100, 0x11134, 0x11136, 0x11143, 0x11150, 0x11176, 0x11180, 0x111cd, 0x111d0, 0x111df, 0x111e1, 0x111f4, 0x11200, 0x11211,
75
+ 0x11213, 0x1123e, 0x11280, 0x11286, 0x11288, 0x11288, 0x1128a, 0x1128d, 0x1128f, 0x1129d, 0x1129f, 0x112a9, 0x112b0, 0x112ea, 0x112f0, 0x112f9,
76
+ 0x11300, 0x11303, 0x11305, 0x1130c, 0x1130f, 0x11310, 0x11313, 0x11328, 0x1132a, 0x11330, 0x11332, 0x11333, 0x11335, 0x11339, 0x1133c, 0x11344,
77
+ 0x11347, 0x11348, 0x1134b, 0x1134d, 0x11350, 0x11350, 0x11357, 0x11357, 0x1135d, 0x11363, 0x11366, 0x1136c, 0x11370, 0x11374, 0x11400, 0x11459,
78
+ 0x1145b, 0x1145b, 0x1145d, 0x1145d, 0x11480, 0x114c7, 0x114d0, 0x114d9, 0x11580, 0x115b5, 0x115b8, 0x115dd, 0x11600, 0x11644, 0x11650, 0x11659,
79
+ 0x11660, 0x1166c, 0x11680, 0x116b7, 0x116c0, 0x116c9, 0x11700, 0x11719, 0x1171d, 0x1172b, 0x11730, 0x1173f, 0x118a0, 0x118f2, 0x118ff, 0x118ff,
80
+ 0x11ac0, 0x11af8, 0x11c00, 0x11c08, 0x11c0a, 0x11c36, 0x11c38, 0x11c45, 0x11c50, 0x11c6c, 0x11c70, 0x11c8f, 0x11c92, 0x11ca7, 0x11ca9, 0x11cb6,
81
+ 0x12000, 0x12399, 0x12400, 0x1246e, 0x12470, 0x12474, 0x12480, 0x12543, 0x13000, 0x1342e, 0x14400, 0x14646, 0x16800, 0x16a38, 0x16a40, 0x16a5e,
82
+ 0x16a60, 0x16a69, 0x16a6e, 0x16a6f, 0x16ad0, 0x16aed, 0x16af0, 0x16af5, 0x16b00, 0x16b45, 0x16b50, 0x16b59, 0x16b5b, 0x16b61, 0x16b63, 0x16b77,
83
+ 0x16b7d, 0x16b8f, 0x16f00, 0x16f44, 0x16f50, 0x16f7e, 0x16f8f, 0x16f9f, 0x16fe0, 0x16fe0, 0x17000, 0x187ec, 0x18800, 0x18af2, 0x1b000, 0x1b001,
84
+ 0x1bc00, 0x1bc6a, 0x1bc70, 0x1bc7c, 0x1bc80, 0x1bc88, 0x1bc90, 0x1bc99, 0x1bc9c, 0x1bca3, 0x1d000, 0x1d0f5, 0x1d100, 0x1d126, 0x1d129, 0x1d1e8,
85
+ 0x1d200, 0x1d245, 0x1d300, 0x1d356, 0x1d360, 0x1d371, 0x1d400, 0x1d454, 0x1d456, 0x1d49c, 0x1d49e, 0x1d49f, 0x1d4a2, 0x1d4a2, 0x1d4a5, 0x1d4a6,
86
+ 0x1d4a9, 0x1d4ac, 0x1d4ae, 0x1d4b9, 0x1d4bb, 0x1d4bb, 0x1d4bd, 0x1d4c3, 0x1d4c5, 0x1d505, 0x1d507, 0x1d50a, 0x1d50d, 0x1d514, 0x1d516, 0x1d51c,
87
+ 0x1d51e, 0x1d539, 0x1d53b, 0x1d53e, 0x1d540, 0x1d544, 0x1d546, 0x1d546, 0x1d54a, 0x1d550, 0x1d552, 0x1d6a5, 0x1d6a8, 0x1d7cb, 0x1d7ce, 0x1da8b,
88
+ 0x1da9b, 0x1da9f, 0x1daa1, 0x1daaf, 0x1e000, 0x1e006, 0x1e008, 0x1e018, 0x1e01b, 0x1e021, 0x1e023, 0x1e024, 0x1e026, 0x1e02a, 0x1e800, 0x1e8c4,
89
+ 0x1e8c7, 0x1e8d6, 0x1e900, 0x1e94a, 0x1e950, 0x1e959, 0x1e95e, 0x1e95f, 0x1ee00, 0x1ee03, 0x1ee05, 0x1ee1f, 0x1ee21, 0x1ee22, 0x1ee24, 0x1ee24,
90
+ 0x1ee27, 0x1ee27, 0x1ee29, 0x1ee32, 0x1ee34, 0x1ee37, 0x1ee39, 0x1ee39, 0x1ee3b, 0x1ee3b, 0x1ee42, 0x1ee42, 0x1ee47, 0x1ee47, 0x1ee49, 0x1ee49,
91
+ 0x1ee4b, 0x1ee4b, 0x1ee4d, 0x1ee4f, 0x1ee51, 0x1ee52, 0x1ee54, 0x1ee54, 0x1ee57, 0x1ee57, 0x1ee59, 0x1ee59, 0x1ee5b, 0x1ee5b, 0x1ee5d, 0x1ee5d,
92
+ 0x1ee5f, 0x1ee5f, 0x1ee61, 0x1ee62, 0x1ee64, 0x1ee64, 0x1ee67, 0x1ee6a, 0x1ee6c, 0x1ee72, 0x1ee74, 0x1ee77, 0x1ee79, 0x1ee7c, 0x1ee7e, 0x1ee7e,
93
+ 0x1ee80, 0x1ee89, 0x1ee8b, 0x1ee9b, 0x1eea1, 0x1eea3, 0x1eea5, 0x1eea9, 0x1eeab, 0x1eebb, 0x1eef0, 0x1eef1, 0x1f000, 0x1f02b, 0x1f030, 0x1f093,
94
+ 0x1f0a0, 0x1f0ae, 0x1f0b1, 0x1f0bf, 0x1f0c1, 0x1f0cf, 0x1f0d1, 0x1f0f5, 0x1f100, 0x1f10c, 0x1f110, 0x1f12e, 0x1f130, 0x1f16b, 0x1f170, 0x1f1ac,
95
+ 0x1f1e6, 0x1f202, 0x1f210, 0x1f23b, 0x1f240, 0x1f248, 0x1f250, 0x1f251, 0x1f300, 0x1f6d2, 0x1f6e0, 0x1f6ec, 0x1f6f0, 0x1f6f6, 0x1f700, 0x1f773,
96
+ 0x1f780, 0x1f7d4, 0x1f800, 0x1f80b, 0x1f810, 0x1f847, 0x1f850, 0x1f859, 0x1f860, 0x1f887, 0x1f890, 0x1f8ad, 0x1f910, 0x1f91e, 0x1f920, 0x1f927,
97
+ 0x1f930, 0x1f930, 0x1f933, 0x1f93e, 0x1f940, 0x1f94b, 0x1f950, 0x1f95e, 0x1f980, 0x1f991, 0x1f9c0, 0x1f9c0, 0x20000, 0x2a6d6, 0x2a700, 0x2b734,
98
+ 0x2b740, 0x2b81d, 0x2b820, 0x2cea1, 0x2f800, 0x2fa1d, 0xe0001, 0xe0001, 0xe0020, 0xe007f, 0xe0100, 0xe01ef, 0xf0000, 0xffffd, 0x100000, 0x10fffd,
99
+ ];
100
+ export function unicodeLocale(context) {
101
+ const locale = (context.env.LC_ALL || context.env.LC_CTYPE || context.env.LANG || "C").toLowerCase();
102
+ return locale.endsWith("utf-8") || locale.endsWith("utf8");
103
+ }
104
+ function rawQuote(text, filename = false, unicode = false) {
105
+ const controls = { "\u0007": "\\a", "\b": "\\b", "\t": "\\t", "\n": "\\n", "\v": "\\v", "\f": "\\f", "\r": "\\r" };
106
+ const decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
107
+ const units = [];
108
+ for (let offset = 0; offset < text.length;) {
109
+ const first = text.charCodeAt(offset);
110
+ let length = 1;
111
+ let point = first;
112
+ let valid = first < 128;
113
+ if (unicode && first >= 0xc2 && first <= 0xf4) {
114
+ const size = first < 0xe0 ? 2 : first < 0xf0 ? 3 : 4;
115
+ try {
116
+ point = decoder.decode(Uint8Array.from(text.slice(offset, offset + size), character => character.charCodeAt(0))).codePointAt(0);
117
+ length = size;
118
+ valid = true;
119
+ }
120
+ catch {
121
+ valid = false;
122
+ }
123
+ }
124
+ let printable = valid && point >= 32 && point < 127;
125
+ if (valid && point >= 128) {
126
+ let low = 0, high = glibc231PrintableRanges.length / 2;
127
+ while (low < high) {
128
+ const middle = Math.floor((low + high) / 2);
129
+ if (point < glibc231PrintableRanges[middle * 2])
130
+ high = middle;
131
+ else if (point > glibc231PrintableRanges[middle * 2 + 1])
132
+ low = middle + 1;
133
+ else {
134
+ printable = true;
135
+ break;
136
+ }
137
+ }
53
138
  }
54
- result += control ? code >= 127 ? `\\${code.toString(8).padStart(3, "0")}` : quote(character).slice(1, -1) : character === "'" ? "'\\''" : character;
139
+ const unit = text.slice(offset, offset + length);
140
+ const shellSpecial = '!"$&()*;<=>?[\\^`|'.includes(unit);
141
+ const positional = "#~".includes(unit) ? offset === 0 : "{}".includes(unit) && text.length === 1;
142
+ units.push({ text: unit, printable, shellSpecial: shellSpecial || positional,
143
+ cAndShellCompatible: printable && !shellSpecial && (!"#~{}".includes(unit) || positional) });
144
+ offset += length;
55
145
  }
56
- return `${result}'`;
57
- }
58
- function usage(message) {
59
- throw new Diagnostic(`shuf: ${message}\nTry 'shuf --help' for more information.\n`);
146
+ if (filename && text && units.every(unit => unit.printable && !unit.shellSpecial && !" ':".includes(unit.text)))
147
+ return text;
148
+ if (filename && text.includes("'") && units.every(unit => unit.cAndShellCompatible))
149
+ return `"${text}"`;
150
+ const left = !filename && unicode ? "\xe2\x80\x98" : "'";
151
+ const right = !filename && unicode ? "\xe2\x80\x99" : "'";
152
+ let result = left;
153
+ let escaping = filename && text.includes("'") && units.length > 0 && !units[units.length - 1].printable;
154
+ for (const unit of units) {
155
+ if (filename && unit.text === "'") {
156
+ result += "'\\''";
157
+ escaping = false;
158
+ }
159
+ else if (!unit.printable) {
160
+ if (filename && !escaping)
161
+ result += "'$'";
162
+ escaping = true;
163
+ result += controls[unit.text] ?? Array.from(unit.text, character => `\\${character.charCodeAt(0).toString(8).padStart(3, "0")}`).join("");
164
+ }
165
+ else {
166
+ if (filename && escaping)
167
+ result += "''";
168
+ escaping = false;
169
+ if (!filename && (unit.text === right || unit.text === "\\"))
170
+ result += "\\";
171
+ result += unit.text;
172
+ }
173
+ }
174
+ return result + right;
60
175
  }
61
- function unsigned(value, start = 0) {
62
- let cursor = start;
63
- while (cursor < value.length && " \t\n\r\v\f".includes(value[cursor]))
64
- cursor++;
65
- if (value[cursor] === "+")
66
- cursor++;
67
- const first = cursor;
68
- let number = 0n;
69
- while (cursor < value.length && value[cursor] >= "0" && value[cursor] <= "9") {
70
- if (number <= wordMax)
71
- number = number * 10n + BigInt(value[cursor]);
72
- cursor++;
176
+ function decimal(text, count, unicode) {
177
+ let offset = 0;
178
+ while (text.charCodeAt(offset) === 32 || text.charCodeAt(offset) >= 9 && text.charCodeAt(offset) <= 13)
179
+ offset++;
180
+ if (text[offset] === "+")
181
+ offset++;
182
+ const start = offset;
183
+ let value = 0n;
184
+ while (text.charCodeAt(offset) >= 48 && text.charCodeAt(offset) <= 57) {
185
+ value = value > unsignedMaximum ? unsignedMaximum + 1n : value * 10n + BigInt(text.charCodeAt(offset) - 48);
186
+ offset++;
73
187
  }
74
- return { number, cursor, valid: cursor > first, overflow: number > wordMax };
188
+ if (offset === start || offset !== text.length || !count && value > unsignedMaximum) {
189
+ throw new ShufDiagnostic(`invalid ${count ? "line count" : "input range"}: ${rawQuote(text, false, unicode)}${!count && offset === text.length && value > unsignedMaximum ? ": Value too large for defined data type" : ""}`);
190
+ }
191
+ return value;
75
192
  }
76
- const longOptions = ["echo", "input-range", "head-count", "output", "random-source", "repeat", "zero-terminated", "help", "version"];
77
- export function parse(context) {
78
- const result = {
79
- echo: false, repeat: false, delimiter: 10, count: countMax,
80
- range: undefined,
81
- output: undefined, random: undefined,
82
- action: undefined, operands: [],
83
- };
84
- const apply = (option, value, valueIndex, valueOffset) => {
85
- switch (option) {
86
- case "e":
87
- result.echo = true;
88
- break;
89
- case "r":
90
- result.repeat = true;
91
- break;
92
- case "z":
93
- result.delimiter = 0;
94
- break;
95
- case "i": {
96
- if (result.range)
97
- throw new Diagnostic("shuf: multiple -i options specified\n");
98
- const low = unsigned(value);
99
- const high = unsigned(value, low.cursor + 1);
100
- const overflow = low.overflow || low.valid && value[low.cursor] === "-" && high.overflow && high.cursor === value.length;
101
- const size = high.number - low.number + 1n;
102
- if (!low.valid || !high.valid || value[low.cursor] !== "-" || high.cursor !== value.length || overflow || size < 0n || size > wordMax) {
103
- throw new Diagnostic(`shuf: invalid input range: ${quote(value)}${overflow ? ": Value too large to be stored in data type" : ""}\n`);
104
- }
105
- result.range = { low: low.number, size };
106
- break;
107
- }
108
- case "n": {
109
- const parsed = unsigned(value);
110
- if (!parsed.valid || parsed.cursor !== value.length) {
111
- throw new Diagnostic(`shuf: invalid line count: ${quote(getCommandArguments(context).bytes(valueIndex).subarray(valueOffset))}\n`);
112
- }
113
- if (!parsed.overflow && parsed.number < result.count)
114
- result.count = parsed.number;
115
- break;
116
- }
117
- case "o":
118
- if (result.output !== undefined && result.output !== value)
119
- throw new Diagnostic("shuf: multiple output files specified\n");
120
- result.output = value;
121
- break;
122
- case "random-source":
123
- if (result.random !== undefined && result.random !== value)
124
- throw new Diagnostic("shuf: multiple random sources specified\n");
125
- result.random = value;
126
- break;
127
- case "help":
128
- case "version":
129
- result.action = option;
130
- break;
193
+ function parseSettings(context) {
194
+ const unicode = unicodeLocale(context);
195
+ const carrier = getCommandArguments(context);
196
+ const args = context.args.map((_argument, index) => Array.from(carrier.bytes(index), byte => String.fromCharCode(byte)).join(""));
197
+ const settings = { echo: false, repeat: false, separator: 10, count: unsignedMaximum, hasCount: false, operands: [] };
198
+ const long = { echo: "e", "input-range": "i", "head-count": "n", output: "o", "random-source": "random", repeat: "r", "zero-terminated": "z", help: "help", version: "version" };
199
+ const apply = (key, value = "") => {
200
+ if (key === "e")
201
+ settings.echo = true;
202
+ else if (key === "r")
203
+ settings.repeat = true;
204
+ else if (key === "z")
205
+ settings.separator = 0;
206
+ else if (key === "help" || key === "version")
207
+ settings.information = key;
208
+ else if (key === "n") {
209
+ const number = decimal(value, true, unicode);
210
+ settings.hasCount = true;
211
+ if (number < settings.count)
212
+ settings.count = number;
213
+ }
214
+ else if (key === "i") {
215
+ if (settings.range)
216
+ throw new ShufDiagnostic("multiple -i options specified");
217
+ const dash = value.indexOf("-");
218
+ const low = dash < 0 ? unsignedMaximum : decimal(value.slice(0, dash), false, unicode);
219
+ const high = decimal(value.slice(dash + 1), false, unicode);
220
+ const length = high - low + 1n;
221
+ if (dash < 0 || length < 0n || length > unsignedMaximum)
222
+ throw new ShufDiagnostic(`invalid input range: ${rawQuote(value, false, unicode)}`);
223
+ settings.range = { low, length };
224
+ }
225
+ else {
226
+ const property = key === "o" ? "output" : "random";
227
+ if (settings[property] !== undefined && settings[property] !== value)
228
+ throw new ShufDiagnostic(`multiple ${property === "output" ? "output files" : "random sources"} specified`);
229
+ settings[property] = value;
131
230
  }
132
231
  };
133
- let ended = false;
134
- for (let index = 0; index < context.args.length; index++) {
135
- context.signal.throwIfAborted();
136
- const argument = context.args[index];
137
- if (ended || argument === "-" || !argument.startsWith("-")) {
138
- result.operands.push(index);
139
- if (Object.hasOwn(context.env, "POSIXLY_CORRECT"))
140
- ended = true;
232
+ let stopped = false;
233
+ for (let index = 0; index < args.length; index++) {
234
+ const argument = args[index];
235
+ if (stopped || argument === "-" || !argument.startsWith("-")) {
236
+ settings.operands.push(index);
237
+ if (context.env.POSIXLY_CORRECT !== undefined)
238
+ stopped = true;
141
239
  }
142
240
  else if (argument === "--")
143
- ended = true;
241
+ stopped = true;
144
242
  else if (argument.startsWith("--")) {
145
- const equal = argument.indexOf("=");
146
- const name = argument.slice(2, equal < 0 ? undefined : equal);
147
- const matches = longOptions.includes(name) ? [name] : longOptions.filter(option => option.startsWith(name));
148
- if (!matches.length)
149
- usage(`unrecognized option '${argument}'`);
150
- if (matches.length > 1)
151
- usage(`option '${argument}' is ambiguous; possibilities:${matches.map(option => ` '--${option}'`).join("")}`);
152
- const option = matches[0];
153
- const required = ["input-range", "head-count", "output", "random-source"].includes(option);
154
- if (!required && equal >= 0)
155
- usage(`option '--${option}' doesn't allow an argument`);
156
- let value = equal < 0 ? "" : argument.slice(equal + 1);
157
- if (required && equal < 0) {
158
- if (++index >= context.args.length)
159
- usage(`option '--${option}' requires an argument`);
160
- value = context.args[index];
161
- }
162
- const short = { echo: "e", "input-range": "i", "head-count": "n", output: "o", repeat: "r", "zero-terminated": "z" };
163
- apply(short[option] ?? option, value, index, equal < 0 ? 0 : equal + 1);
243
+ const equals = argument.indexOf("=");
244
+ const name = argument.slice(2, equals < 0 ? undefined : equals);
245
+ const matches = Object.keys(long).filter(candidate => candidate.startsWith(name));
246
+ const selected = Object.hasOwn(long, name) ? name : matches.length === 1 ? matches[0] : undefined;
247
+ if (!selected)
248
+ throw new ShufDiagnostic(matches.length > 1 ? `option '${argument}' is ambiguous; possibilities: ${matches.map(candidate => `'--${candidate}'`).join(" ")}` : `unrecognized option '${argument}'`, true);
249
+ const key = long[selected];
250
+ const required = ["i", "n", "o", "random"].includes(key);
251
+ if (!required && equals >= 0)
252
+ throw new ShufDiagnostic(`option '--${selected}' doesn't allow an argument`, true);
253
+ const value = required ? equals < 0 ? args[++index] : argument.slice(equals + 1) : "";
254
+ if (value === undefined)
255
+ throw new ShufDiagnostic(`option '--${selected}' requires an argument`, true);
256
+ apply(key, value);
164
257
  }
165
258
  else {
166
- for (let cursor = 1; cursor < argument.length; cursor++) {
167
- const option = argument[cursor];
168
- if (!"einorz".includes(option)) {
169
- const byte = getCommandArguments(context).bytes(index)[cursor];
170
- const bytes = Buffer.concat([Buffer.from("shuf: invalid option -- '"), Buffer.from([byte]), Buffer.from("'\nTry 'shuf --help' for more information.\n")]);
171
- throw new Diagnostic(bytes.toString(), bytes);
172
- }
259
+ for (let position = 1; position < argument.length; position++) {
260
+ const key = argument[position];
261
+ if (!"einorz".includes(key))
262
+ throw new ShufDiagnostic(`invalid option -- '${key}'`, true);
173
263
  let value = "";
174
- let valueOffset = cursor + 1;
175
- if ("ino".includes(option)) {
176
- value = argument.slice(cursor + 1);
177
- if (!value) {
178
- if (++index >= context.args.length)
179
- usage(`option requires an argument -- '${option}'`);
180
- value = context.args[index];
181
- valueOffset = 0;
182
- }
183
- cursor = argument.length;
264
+ if ("ino".includes(key)) {
265
+ const supplied = argument.slice(position + 1) || args[++index];
266
+ if (supplied === undefined)
267
+ throw new ShufDiagnostic(`option requires an argument -- '${key}'`, true);
268
+ value = supplied;
269
+ position = argument.length;
184
270
  }
185
- apply(option, value, index, valueOffset);
271
+ apply(key, value);
186
272
  }
187
273
  }
188
- if (result.action)
189
- return result;
274
+ if (settings.information)
275
+ return settings;
190
276
  }
191
- if (result.echo && result.range)
192
- usage("cannot combine -e and -i options");
193
- if (result.range ? result.operands.length > 0 : !result.echo && result.operands.length > 1) {
194
- usage(`extra operand ${quote(context.args[result.operands[result.range ? 0 : 1]])}`);
195
- }
196
- return result;
277
+ if (settings.echo && settings.range)
278
+ throw new ShufDiagnostic("cannot combine -e and -i options", true);
279
+ const maximum = settings.range ? 0 : settings.echo ? Infinity : 1;
280
+ if (settings.operands.length > maximum)
281
+ throw new ShufDiagnostic(`extra operand ${rawQuote(args[settings.operands[maximum]], false, unicode)}`, true);
282
+ return settings;
283
+ }
284
+ export function quote(value, unicode = false) {
285
+ const text = typeof value === "string" ? value : Array.from(value, byte => String.fromCharCode(byte)).join("");
286
+ return new TextDecoder().decode(Uint8Array.from(rawQuote(text, false, unicode), character => character.charCodeAt(0)));
287
+ }
288
+ export function fileQuote(value, unicode = false) {
289
+ return new TextDecoder().decode(Uint8Array.from(rawQuote(value, true, unicode), character => character.charCodeAt(0)));
290
+ }
291
+ export function parse(context) {
292
+ const settings = parseSettings(context);
293
+ return {
294
+ echo: settings.echo, repeat: settings.repeat, delimiter: settings.separator, count: settings.count,
295
+ hasCount: settings.hasCount, operands: settings.operands,
296
+ range: settings.range ? { low: settings.range.low, size: settings.range.length } : undefined,
297
+ output: settings.output, random: settings.random, action: settings.information,
298
+ };
197
299
  }
@@ -343,8 +343,26 @@ export async function openFileOutput(context, path, options, incremental) {
343
343
  throw new FsError("ENOTSUP", { path, syscall: "writeStream", message: "exclusive output requires streaming support" });
344
344
  if (flag === "w" && capabilities.write === false)
345
345
  throw new FsError("ENOTSUP", { path, syscall: "writeFile" });
346
- if ((!incremental || flag === "a") && capabilities.append === false)
346
+ if (flag === "a" && capabilities.append === false)
347
347
  throw new FsError("ENOTSUP", { path, syscall: "appendFile" });
348
+ if (!incremental && flag === "w" && capabilities.append === false) {
349
+ await fs.writeFile(path, new Uint8Array(), { ...fsOptions, flag });
350
+ const chunks = [];
351
+ let size = 0;
352
+ for await (const chunk of source) {
353
+ signal.throwIfAborted();
354
+ chunks.push(new Uint8Array(chunk));
355
+ size += chunk.byteLength;
356
+ }
357
+ const bytes = new Uint8Array(size);
358
+ let offset = 0;
359
+ for (const chunk of chunks) {
360
+ bytes.set(chunk, offset);
361
+ offset += chunk.length;
362
+ }
363
+ await fs.writeFile(path, bytes, fsOptions);
364
+ return;
365
+ }
348
366
  const sink = incremental ? await incremental() : await (async () => {
349
367
  if (flag === "a")
350
368
  await fs.appendFile(path, new Uint8Array(), fsOptions);
@@ -1,5 +1,23 @@
1
- import { type ByteSource } from "../safe-bash-contracts/index.js";
1
+ import { type ByteSource, type CommandContext, type FileStat } from "../safe-bash-contracts/index.js";
2
2
  export declare function virtualPath(cwd: string, name: string): string;
3
+ /** Own only acquisition and reads; a capability or pathname query owns no reader. */
4
+ export declare class FileInput {
5
+ private readonly context;
6
+ private readonly maxBytes;
7
+ stat: FileStat | undefined;
8
+ private handle;
9
+ private source;
10
+ private opening;
11
+ private closing;
12
+ private closed;
13
+ private readonly controller;
14
+ private readonly signal;
15
+ constructor(context: CommandContext, maxBytes: number);
16
+ open(name: string): Promise<void>;
17
+ next(): Promise<IteratorResult<Uint8Array>>;
18
+ close(): Promise<void>;
19
+ [Symbol.asyncIterator](): AsyncIterator<Uint8Array>;
20
+ }
3
21
  export declare function ownedBytes(source: ByteSource, signal: AbortSignal): AsyncGenerator<Uint8Array> & AsyncDisposable;
4
22
  export declare function records(source: ByteSource, delimiter: number, limit: number, signal: AbortSignal): AsyncGenerator<Uint8Array>;
5
23
  export declare function readAllRecords(source: ByteSource, delimiter: number, maxBytes: number, maxRecords: number, signal: AbortSignal, lines: Uint8Array[]): Promise<number>;