@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
@@ -24,7 +24,7 @@ import {
24
24
  createXmlCommands,
25
25
  defaultXmlQueryLimits,
26
26
  xmlCommands
27
- } from "./chunks/chunk-G5FT6GOL.js";
27
+ } from "./chunks/chunk-KR2R6MLR.js";
28
28
  import {
29
29
  Interpreter,
30
30
  createYqCommand,
@@ -35,7 +35,7 @@ import {
35
35
  rawValues,
36
36
  stringify,
37
37
  yqCommands
38
- } from "./chunks/chunk-FXCEA7NR.js";
38
+ } from "./chunks/chunk-2XJFAB3E.js";
39
39
  import {
40
40
  Budget,
41
41
  JqError,
@@ -61,7 +61,7 @@ import {
61
61
  curlCommands,
62
62
  defaultNetworkLimits,
63
63
  networkCommands
64
- } from "./chunks/chunk-B5Y7TH7K.js";
64
+ } from "./chunks/chunk-VZJ3RTVV.js";
65
65
  import {
66
66
  SafeJsCommandLimitError,
67
67
  createSafeJsNodeCommand,
@@ -72,7 +72,7 @@ import {
72
72
  safeJsNodeCommands,
73
73
  stringValue,
74
74
  withSignal
75
- } from "./chunks/chunk-4C5H4M64.js";
75
+ } from "./chunks/chunk-LEZHTGWK.js";
76
76
  import {
77
77
  AvailableRecords,
78
78
  EreLedger,
@@ -92,7 +92,7 @@ import {
92
92
  exprMatchCeilings,
93
93
  matchEre,
94
94
  withRegexSession
95
- } from "./chunks/chunk-YOUOJRAP.js";
95
+ } from "./chunks/chunk-ZHWEPWDW.js";
96
96
  import {
97
97
  openFileOutput,
98
98
  writeFileOutput
@@ -152,7 +152,7 @@ import {
152
152
  import {
153
153
  createLlmCommands,
154
154
  llmCommands
155
- } from "./chunks/chunk-SACGNKFN.js";
155
+ } from "./chunks/chunk-T7T3UICV.js";
156
156
  import {
157
157
  RecordBuffer,
158
158
  UsageError,
@@ -182,7 +182,7 @@ import {
182
182
  textOutputRequirements,
183
183
  value,
184
184
  writeDiagnostic
185
- } from "./chunks/chunk-N4PN6Z63.js";
185
+ } from "./chunks/chunk-FEJYNOYN.js";
186
186
  import {
187
187
  PublicDiagnostic,
188
188
  publicDiagnosticMessage
@@ -4194,7 +4194,7 @@ async function* combinedInput(context2, names, state) {
4194
4194
  }
4195
4195
  }
4196
4196
  }
4197
- async function prefix(context2, source2, count2, bytes3, skip) {
4197
+ async function prefix(context2, source2, count2, bytes3, skip, delimiter) {
4198
4198
  let remaining = count2;
4199
4199
  if (!remaining && !skip) return;
4200
4200
  for await (const chunk of source2) {
@@ -4205,7 +4205,7 @@ async function prefix(context2, source2, count2, bytes3, skip) {
4205
4205
  offset = Math.min(chunk.length, remaining);
4206
4206
  remaining -= offset;
4207
4207
  } else {
4208
- for (; offset < chunk.length && remaining; offset++) if (chunk[offset] === 10) remaining--;
4208
+ for (; offset < chunk.length && remaining; offset++) if (chunk[offset] === delimiter) remaining--;
4209
4209
  }
4210
4210
  }
4211
4211
  if (skip) {
@@ -4216,12 +4216,12 @@ async function prefix(context2, source2, count2, bytes3, skip) {
4216
4216
  }
4217
4217
  }
4218
4218
  }
4219
- async function suffix(context2, source2, count2, bytes3, omit) {
4219
+ async function suffix(context2, source2, count2, bytes3, omit, delimiter) {
4220
4220
  let pending = [];
4221
4221
  let start = 0;
4222
4222
  let size = 0;
4223
4223
  const records5 = bytes3 ? source2 : (async function* () {
4224
- for await (const line of lines(source2)) yield line.terminated ? concatenate([line.bytes, Uint8Array.of(10)]) : line.bytes;
4224
+ for await (const line of lines(source2, delimiter)) yield line.terminated ? concatenate([line.bytes, Uint8Array.of(delimiter)]) : line.bytes;
4225
4225
  })();
4226
4226
  for await (const chunk of records5) {
4227
4227
  context2.signal.throwIfAborted();
@@ -4296,9 +4296,10 @@ function headTail(name2, maxTailFollowHandles = 64) {
4296
4296
  return define(name2, async (context2) => {
4297
4297
  const args = context2.args[0] && /^-[0-9]+$/u.test(context2.args[0]) ? ["-n", context2.args[0].slice(1), ...context2.args.slice(1)] : context2.args;
4298
4298
  const follow = name2 === "tail" ? parseTailFollow(args) : void 0;
4299
- const parsed = options(follow?.args ?? args, "n:c:qv", { lines: "n", bytes: "c", quiet: "q", silent: "q", verbose: "v" });
4299
+ const parsed = options(follow?.args ?? args, "n:c:qvz", { lines: "n", bytes: "c", quiet: "q", silent: "q", verbose: "v", "zero-terminated": "z" });
4300
4300
  if (parsed.flags.has("n") && parsed.flags.has("c")) throw new UsageError("cannot combine line and byte counts");
4301
4301
  const bytes3 = parsed.flags.has("c");
4302
+ const delimiter = parsed.flags.has("z") ? 0 : 10;
4302
4303
  const amount = value(parsed, bytes3 ? "c" : "n") ?? "10";
4303
4304
  const positive = amount.startsWith("+");
4304
4305
  const negative = amount.startsWith("-");
@@ -4312,7 +4313,7 @@ function headTail(name2, maxTailFollowHandles = 64) {
4312
4313
  bytes: bytes3,
4313
4314
  positive,
4314
4315
  headers: parsed.flags.has("v") || names.length > 1 && !parsed.flags.has("q")
4315
- }, maxTailFollowHandles, (target, source2) => positive ? prefix(target, source2, Math.max(0, count2 - 1), bytes3, true) : suffix(target, source2, count2, bytes3, false));
4316
+ }, maxTailFollowHandles, (target, source2) => positive ? prefix(target, source2, Math.max(0, count2 - 1), bytes3, true, delimiter) : suffix(target, source2, count2, bytes3, false, delimiter));
4316
4317
  await assertInputRequirements(context2, names);
4317
4318
  (0, command_requirements_exports.assertCommandRequirements)(context2, inspectedInputRequirements, [names.some((name3) => name3 !== "-") ? "file" : "stdin"]);
4318
4319
  let exitCode = 0;
@@ -4330,9 +4331,9 @@ function headTail(name2, maxTailFollowHandles = 64) {
4330
4331
  `);
4331
4332
  headerWritten = true;
4332
4333
  }
4333
- if (name2 === "head" && !negative) await prefix(context2, input(context2, file), count2, bytes3, false);
4334
- else if (name2 === "tail" && positive) await prefix(context2, input(context2, file), Math.max(0, count2 - 1), bytes3, true);
4335
- else await suffix(context2, input(context2, file), count2, bytes3, name2 === "head");
4334
+ if (name2 === "head" && !negative) await prefix(context2, input(context2, file), count2, bytes3, false, delimiter);
4335
+ else if (name2 === "tail" && positive) await prefix(context2, input(context2, file), Math.max(0, count2 - 1), bytes3, true, delimiter);
4336
+ else await suffix(context2, input(context2, file), count2, bytes3, name2 === "head", delimiter);
4336
4337
  } catch (error) {
4337
4338
  await diagnostic(context2, error);
4338
4339
  exitCode = 1;
@@ -4401,7 +4402,26 @@ function streamCommands(maxTeeTargets = 64, maxTailFollowHandles = 64) {
4401
4402
  }
4402
4403
  return [
4403
4404
  define("cat", async (context2) => {
4404
- const parsed = options(context2.args, "nbsvETAute", { number: "n", "number-nonblank": "b", "squeeze-blank": "s", "show-ends": "E", "show-tabs": "T", "show-nonprinting": "v", "show-all": "A" });
4405
+ const parsed = options(context2.args, "nbsvETAute", { help: false, number: "n", "number-nonblank": "b", "squeeze-blank": "s", "show-ends": "E", "show-tabs": "T", "show-nonprinting": "v", "show-all": "A" });
4406
+ if (parsed.flags.has("help")) {
4407
+ await output(context2, `Usage: cat [OPTION]... [FILE]...
4408
+ Concatenate FILEs to standard output. With no FILE, or FILE -, read standard input.
4409
+
4410
+ -n, --number Number all output lines
4411
+ -b, --number-nonblank Number nonempty output lines (overrides -n)
4412
+ -s, --squeeze-blank Suppress repeated empty output lines
4413
+ -E, --show-ends Display $ at each line end
4414
+ -T, --show-tabs Display TAB characters as ^I
4415
+ -v, --show-nonprinting Display nonprinting characters
4416
+ -A, --show-all Equivalent to -vET
4417
+ -e Equivalent to -vE
4418
+ -t Equivalent to -vT
4419
+ -u Accepted for compatibility; ignored
4420
+ --help Display this help and exit
4421
+ -- End options; remaining arguments are filenames
4422
+ `);
4423
+ return { exitCode: 0 };
4424
+ }
4405
4425
  await assertInputRequirements(context2, parsed.operands);
4406
4426
  if (parsed.flags.has("A")) for (const flag of ["v", "E", "T"]) parsed.flags.add(flag);
4407
4427
  if (parsed.flags.has("e")) {
@@ -12556,7 +12576,7 @@ async function execute(program, context2, files, quiet, budget, separator, outpu
12556
12576
  const character = pattern[offset];
12557
12577
  const lineEnd = character === "\n" && separator === "\n";
12558
12578
  const token = character === void 0 || lineEnd ? "$" : escapes2[character] ?? (character.charCodeAt(0) < 32 || character.charCodeAt(0) >= 127 ? `\\${character.charCodeAt(0).toString(8).padStart(3, "0")}` : character);
12559
- if (line.length + token.length >= 60) {
12579
+ if (character !== void 0 && !lineEnd && line.length + token.length >= 70) {
12560
12580
  await emit2(line + "\\" + separator);
12561
12581
  line = "";
12562
12582
  }
@@ -12717,6 +12737,14 @@ function sedCommand(options2 = {}) {
12717
12737
  separator = "\0";
12718
12738
  continue;
12719
12739
  }
12740
+ if (argument2 === "--quiet") {
12741
+ quiet = true;
12742
+ continue;
12743
+ }
12744
+ if (argument2 === "--regexp-extended") {
12745
+ extended = true;
12746
+ continue;
12747
+ }
12720
12748
  if (argument2.startsWith("--")) throw new ProgramError(`unsupported option '${argument2}'`);
12721
12749
  for (let position = 1; position < argument2.length; position++) {
12722
12750
  const flag = argument2[position];
@@ -15053,6 +15081,9 @@ function parse6(args) {
15053
15081
  return output2;
15054
15082
  };
15055
15083
  switch (flag) {
15084
+ case "help":
15085
+ result.help = true;
15086
+ break;
15056
15087
  case "e":
15057
15088
  case "regexp":
15058
15089
  result.explicitPatterns = true;
@@ -15298,7 +15329,7 @@ function parse6(args) {
15298
15329
  }
15299
15330
  }
15300
15331
  if (result.before > 1e5 || result.after > 1e5) throw new SearchError("context limit exceeded");
15301
- if (result.mode !== "files" && !result.explicitPatterns) {
15332
+ if (!result.help && result.mode !== "files" && !result.explicitPatterns) {
15302
15333
  const pattern = operands.shift();
15303
15334
  if (pattern === void 0) throw new SearchError("a search pattern is required");
15304
15335
  result.patterns.push(pattern);
@@ -15900,6 +15931,65 @@ function createRgCommand(executor, options2 = {}) {
15900
15931
  try {
15901
15932
  const limits = new Limits(context2, options2);
15902
15933
  args = parse6(context2.args);
15934
+ if (args.help) {
15935
+ await limits.output(import_buffer.Buffer.from(`Usage: rg [OPTIONS] PATTERN [PATH ...]
15936
+ Search files for PATTERN. PATH - reads standard input.
15937
+ Default input depends on shell configuration.
15938
+
15939
+ -e, --regexp=PATTERN Add a pattern (repeatable)
15940
+ -f, --file=FILE Read patterns from FILE
15941
+ -F, --fixed-strings Use fixed strings
15942
+ -i, --ignore-case Ignore case distinctions
15943
+ -s, --case-sensitive Match case sensitively
15944
+ -S, --smart-case Infer case sensitivity from the pattern
15945
+ -v, --invert-match Select nonmatching lines
15946
+ -w, --word-regexp Match whole words
15947
+ -x, --line-regexp Match whole lines
15948
+ -n, --line-number Print line numbers
15949
+ -N, --no-line-number Suppress line numbers
15950
+ -H, --with-filename Print filenames
15951
+ -I, --no-filename Suppress filenames
15952
+ -o, --only-matching Print matching parts
15953
+ -l, --files-with-matches Print filenames with matches
15954
+ --files-without-match Print filenames without matches
15955
+ --files List files without searching
15956
+ -c, --count Print matching line counts
15957
+ --count-matches Print match counts
15958
+ --json Emit JSON events
15959
+ -q, --quiet Suppress normal output
15960
+ -g, --glob=GLOB Include or exclude paths (repeatable)
15961
+ --iglob=GLOB Case-insensitive glob
15962
+ -t, --type=TYPE Include a file type
15963
+ -T, --type-not=TYPE Exclude a file type
15964
+ -., --hidden Search hidden files
15965
+ -L, --follow Follow symbolic links
15966
+ --no-ignore Disable ignore-file filtering
15967
+ -u, --unrestricted Relax ignore, hidden and binary filtering (repeatable)
15968
+ -a, --text Search binary files as text
15969
+ -A, --after-context=NUM Print NUM lines after matches
15970
+ -B, --before-context=NUM Print NUM lines before matches
15971
+ -C, --context=NUM Print NUM lines before and after matches
15972
+ -m, --max-count=NUM Limit matching lines per file
15973
+ --max-depth=NUM Limit directory traversal depth (maximum 128)
15974
+ --column Print columns
15975
+ -b, --byte-offset Print byte offsets
15976
+ -0, --null NUL-terminate filenames
15977
+ --null-data Use NUL-delimited records
15978
+ --crlf Handle CRLF line endings
15979
+ --heading Group output by filename
15980
+ --sort=path Sort paths
15981
+ --color=never Disable color
15982
+ --help Display this help and exit
15983
+ -- End options
15984
+
15985
+ Exit status: 0 when a match is found, 1 when none is found, 2 on error.
15986
+ Regular expression support depends on the configured regex executor.
15987
+ The default supports UTF-8 literals and bounded ASCII regular expressions.
15988
+ Regex operators: . ^ $ [...] (...) | * + ? {n,m}; -F treats patterns literally.
15989
+ Word/case flags and extended regex syntax require a configured executor.
15990
+ `));
15991
+ return { exitCode: 0 };
15992
+ }
15903
15993
  if (args.mode !== "files" && args.patternFiles.includes("-") && args.paths.includes("-")) {
15904
15994
  throw new SearchError("cannot search stdin while also reading patterns from stdin");
15905
15995
  }
@@ -15958,7 +16048,51 @@ var maxPatternCount = 1024;
15958
16048
  function createGrepCommands(executor) {
15959
16049
  return [{ name: "grep", filesystemRequirements: grepRequirements, execute: (context2) => withRegexSession(context2, executor, async (session) => {
15960
16050
  try {
15961
- const parsed = options(context2.args, "EFivnclLqhHowxae:f:m:sz", { "extended-regexp": "E", "fixed-strings": "F", "ignore-case": "i", "invert-match": "v", "line-number": "n", count: "c", "files-with-matches": "l", "files-without-match": "L", quiet: "q", silent: "q", "no-filename": "h", "with-filename": "H", "only-matching": "o", "word-regexp": "w", "line-regexp": "x", regexp: "e", file: "f", "max-count": "m", "no-messages": "s", text: "a", "null-data": "z" });
16051
+ const contextLengths = /* @__PURE__ */ new Map();
16052
+ const parsed = options(context2.args, "EFivnclLqhHowxae:f:m:szA:B:C:", { help: false, "extended-regexp": "E", "fixed-strings": "F", "ignore-case": "i", "invert-match": "v", "line-number": "n", count: "c", "files-with-matches": "l", "files-without-match": "L", quiet: "q", silent: "q", "no-filename": "h", "with-filename": "H", "only-matching": "o", "word-regexp": "w", "line-regexp": "x", regexp: "e", file: "f", "max-count": "m", "no-messages": "s", text: "a", "null-data": "z", "after-context": "A", "before-context": "B", context: "C" }, false, void 0, (key, index, offset) => {
16053
+ if (!["A", "B", "C"].includes(key)) return;
16054
+ const text3 = context2.args[index].slice(offset);
16055
+ try {
16056
+ contextLengths.set(key, integer(text3));
16057
+ } catch {
16058
+ throw new UsageError(`${text3}: invalid context length argument`);
16059
+ }
16060
+ });
16061
+ if (parsed.flags.has("help")) {
16062
+ await output(context2, `Usage: grep [OPTION]... PATTERN [FILE]...
16063
+ Print lines matching PATTERN. With no FILE, or FILE -, read standard input.
16064
+
16065
+ -E, --extended-regexp Use extended regular expressions
16066
+ -F, --fixed-strings Use fixed strings
16067
+ -e, --regexp=PATTERN Add a pattern (repeatable)
16068
+ -f, --file=FILE Read patterns from FILE
16069
+ -i, --ignore-case Ignore case distinctions
16070
+ -v, --invert-match Select nonmatching lines
16071
+ -w, --word-regexp Match whole words
16072
+ -x, --line-regexp Match whole lines
16073
+ -n, --line-number Print line numbers
16074
+ -H, --with-filename Print filenames
16075
+ -h, --no-filename Suppress filenames
16076
+ -o, --only-matching Print only matching parts
16077
+ -c, --count Print matching line counts
16078
+ -l, --files-with-matches Print filenames with matches
16079
+ -L, --files-without-match Print filenames without matches
16080
+ -q, --quiet, --silent Suppress normal output
16081
+ -m, --max-count=NUM Stop after NUM selected lines per file
16082
+ -A, --after-context=NUM Print NUM lines after selected lines
16083
+ -B, --before-context=NUM Print NUM lines before selected lines
16084
+ -C, --context=NUM Print NUM lines before and after selected lines
16085
+ -s, --no-messages Suppress file error messages
16086
+ -a, --text Process input as text
16087
+ -z, --null-data Use NUL-delimited records
16088
+ --help Display this help and exit
16089
+ -- End options
16090
+
16091
+ Exit status: 0 when a line is selected, 1 when none is selected, 2 on error.
16092
+ Regular expression support depends on the configured regex executor.
16093
+ `);
16094
+ return { exitCode: 0 };
16095
+ }
15962
16096
  let positionalPattern;
15963
16097
  if (!parsed.flags.has("e") && !parsed.flags.has("f")) {
15964
16098
  if (!parsed.operands.length) throw new UsageError("missing pattern");
@@ -16020,13 +16154,30 @@ function createGrepCommands(executor) {
16020
16154
  const batchSize = Number.isFinite(maxCount) || parsed.flags.has("q") || parsed.flags.has("l") || parsed.flags.has("L") ? 1 : 128;
16021
16155
  const delimiter = parsed.flags.has("z") ? "\0" : "\n";
16022
16156
  const extractMatches = parsed.flags.has("o") && !["c", "q", "l", "L", "v"].some((flag) => parsed.flags.has(flag));
16157
+ const displayLines = !["c", "q", "l", "L"].some((flag) => parsed.flags.has(flag));
16158
+ const withContext = contextLengths.size > 0 && displayLines && !(parsed.flags.has("o") && parsed.flags.has("v"));
16159
+ const before = withContext ? contextLengths.get("B") ?? contextLengths.get("C") ?? 0 : 0;
16160
+ const after = withContext ? contextLengths.get("A") ?? contextLengths.get("C") ?? 0 : 0;
16161
+ let emittedGroup = false;
16023
16162
  let anySelected = false;
16024
16163
  let failed = false;
16025
16164
  for (const name2 of names) {
16026
16165
  let count2 = 0;
16027
16166
  let number6 = 0;
16167
+ let lastCovered = 0;
16168
+ let remainingAfter = 0;
16169
+ let pendingBytes = 0;
16170
+ const pending = /* @__PURE__ */ new Map();
16028
16171
  const named2 = name2 === "-" ? "(standard input)" : name2;
16029
- const prefix3 = (lineNumber = false) => `${!parsed.flags.has("h") && (parsed.flags.has("H") || names.length > 1) ? `${named2}:` : ""}${lineNumber && parsed.flags.has("n") ? `${number6}:` : ""}`;
16172
+ const prefix3 = (lineNumber = false, position = number6, separator = ":") => `${!parsed.flags.has("h") && (parsed.flags.has("H") || names.length > 1) ? `${named2}${separator}` : ""}${lineNumber && parsed.flags.has("n") ? `${position}${separator}` : ""}`;
16173
+ const emitContext = async (line, position) => {
16174
+ if (!parsed.flags.has("o")) {
16175
+ await output(context2, prefix3(true, position, "-"));
16176
+ await output(context2, line.bytes);
16177
+ await output(context2, delimiter);
16178
+ }
16179
+ lastCovered = position;
16180
+ };
16030
16181
  try {
16031
16182
  const available2 = new AvailableRecords(parsed.flags.has("z") ? 0 : 10, bufferLimit);
16032
16183
  const source2 = name2 === "-" ? input(context2) : requiredFileInput(context2, grepRequirements, "file", name2, bufferLimit);
@@ -16037,12 +16188,40 @@ function createGrepCommands(executor) {
16037
16188
  context2.signal.throwIfAborted();
16038
16189
  number6++;
16039
16190
  const found = results[index];
16040
- if (found.length > 0 === parsed.flags.has("v")) continue;
16191
+ const selected = count2 < maxCount && found.length > 0 !== parsed.flags.has("v");
16192
+ if (!selected) {
16193
+ if (remainingAfter > 0) {
16194
+ await emitContext(line, number6);
16195
+ remainingAfter--;
16196
+ if (count2 >= maxCount && remainingAfter === 0) break records;
16197
+ } else if (before > 0) {
16198
+ if (pending.size >= before) {
16199
+ const oldest = pending.keys().next().value;
16200
+ pendingBytes -= pending.get(oldest).bytes.length + 1;
16201
+ pending.delete(oldest);
16202
+ }
16203
+ const size = line.bytes.length + 1;
16204
+ if (size > bufferLimit - pendingBytes) throw new UsageError(`context byte limit exceeded (${bufferLimit} bytes)`);
16205
+ pending.set(number6, { bytes: Uint8Array.from(line.bytes), terminated: line.terminated });
16206
+ pendingBytes += size;
16207
+ }
16208
+ continue;
16209
+ }
16041
16210
  count2++;
16042
16211
  if (!parsed.flags.has("L")) anySelected = true;
16043
16212
  if (parsed.flags.has("q")) return { exitCode: 0 };
16044
16213
  if (parsed.flags.has("l") || parsed.flags.has("L")) break records;
16045
16214
  if (!parsed.flags.has("c")) {
16215
+ if (withContext) {
16216
+ const first = pending.keys().next().value ?? number6;
16217
+ if (emittedGroup && (lastCovered === 0 || first > lastCovered + 1)) await output(context2, "--\n");
16218
+ for (const [position, previous] of pending) await emitContext(previous, position);
16219
+ pending.clear();
16220
+ pendingBytes = 0;
16221
+ remainingAfter = after;
16222
+ lastCovered = number6;
16223
+ emittedGroup = true;
16224
+ }
16046
16225
  if (parsed.flags.has("o")) {
16047
16226
  if (!parsed.flags.has("v")) {
16048
16227
  let end = -1;
@@ -16060,7 +16239,7 @@ function createGrepCommands(executor) {
16060
16239
  await output(context2, delimiter);
16061
16240
  }
16062
16241
  }
16063
- if (count2 >= maxCount) break records;
16242
+ if (count2 >= maxCount && remainingAfter === 0) break records;
16064
16243
  }
16065
16244
  }
16066
16245
  if (parsed.flags.has("l") && count2 > 0 || parsed.flags.has("L") && count2 === 0) {
@@ -25820,6 +25999,7 @@ async function parseOptions2(context2, limits) {
25820
25999
  if (values.has(flag) && value2 === void 0) value2 = context2.args[++index];
25821
26000
  if (values.has(flag) && value2 === void 0) fail(`missing argument for --${name2}`);
25822
26001
  if (!values.has(flag) && value2 !== void 0) fail(`option --${name2} does not take an argument`);
26002
+ if (flag === "help") return "help";
25823
26003
  await apply(flag, value2);
25824
26004
  } else if (!end && (argument2.startsWith("-") && argument2 !== "-" || index === 0 && /^[ctxzvfCT]+$/u.test(argument2))) {
25825
26005
  const old = !argument2.startsWith("-");
@@ -31590,6 +31770,33 @@ function createTarCommand(options2 = {}) {
31590
31770
  const context2 = { ...original, signal };
31591
31771
  try {
31592
31772
  const parsed = await parseOptions2(context2, limits);
31773
+ if (parsed === "help") {
31774
+ await (0, contracts_exports.writeBytes)(context2.stdout, import_buffer.Buffer.from(`Usage: tar [OPTION]... [FILE]...
31775
+ Create, list or extract USTAR/PAX archives in the virtual filesystem.
31776
+
31777
+ -c, --create Create an archive
31778
+ -t, --list List archive members
31779
+ -x, --extract, --get Extract archive members
31780
+ -f, --file=ARCHIVE Use ARCHIVE (default - for standard input/output)
31781
+ -z, --gzip Use gzip compression
31782
+ -v, --verbose List processed members
31783
+ -C, --directory=DIR Change directory for subsequent operands
31784
+ -T, --files-from=FILE Read filenames from FILE (- for standard input)
31785
+ --null Read NUL-delimited filenames; implies verbatim names
31786
+ --no-null Read newline-delimited filenames
31787
+ --verbatim-files-from Treat file-list entries as literal filenames
31788
+ --no-verbatim-files-from Enable supported file-list directory options
31789
+ --exclude=PATTERN Exclude paths (place before source operands)
31790
+ --strip-components=NUM Remove leading components when reading archives
31791
+ --format=FORMAT Create pax (default), posix or ustar archives
31792
+ --help Display this help and exit
31793
+ -- End options; remaining arguments are filenames
31794
+
31795
+ Exactly one of -c, -t or -x is required for archive operations.
31796
+ Examples: tar cf archive.tar file; tar tf archive.tar; tar xf archive.tar -C directory
31797
+ `), signal);
31798
+ return { exitCode: 0 };
31799
+ }
31593
31800
  const budget = new Budget14(context2, limits);
31594
31801
  if (parsed.mode === "c") {
31595
31802
  const prepared = await manifest(context2, parsed, budget);