@poe-platform/safe-bash 0.1.539 → 0.1.541

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 (138) hide show
  1. package/dist/safe-bash/chunks/bz2-B2RXT4EX.js +4836 -0
  2. package/dist/safe-bash/chunks/bz2-B2RXT4EX.js.map +7 -0
  3. package/dist/safe-bash/chunks/{chunk-4NMFAR4Z.js → chunk-2KL6W6NB.js} +3 -629
  4. package/dist/safe-bash/chunks/{chunk-4NMFAR4Z.js.map → chunk-2KL6W6NB.js.map} +4 -4
  5. package/dist/safe-bash/chunks/chunk-5VBLSPNM.js +641 -0
  6. package/dist/safe-bash/chunks/chunk-5VBLSPNM.js.map +7 -0
  7. package/dist/safe-bash/chunks/{chunk-LUIEXTN5.js → chunk-66VSWIUC.js} +6 -4
  8. package/dist/safe-bash/chunks/{chunk-LUIEXTN5.js.map → chunk-66VSWIUC.js.map} +1 -1
  9. package/dist/safe-bash/chunks/{chunk-5X2TAR25.js → chunk-6PSMEBVP.js} +6 -4
  10. package/dist/safe-bash/chunks/{chunk-5X2TAR25.js.map → chunk-6PSMEBVP.js.map} +1 -1
  11. package/dist/safe-bash/chunks/{chunk-RDIJ6M2D.js → chunk-AZNI263O.js} +6 -4
  12. package/dist/safe-bash/chunks/{chunk-RDIJ6M2D.js.map → chunk-AZNI263O.js.map} +1 -1
  13. package/dist/safe-bash/chunks/{chunk-CI42NIWL.js → chunk-DPJWEGIX.js} +2 -2
  14. package/dist/safe-bash/chunks/{chunk-GV76QENF.js → chunk-EZLQA6ON.js} +6 -4
  15. package/dist/safe-bash/chunks/{chunk-GV76QENF.js.map → chunk-EZLQA6ON.js.map} +1 -1
  16. package/dist/safe-bash/chunks/{chunk-F4UILGOA.js → chunk-HFEU5SBQ.js} +8 -6
  17. package/dist/safe-bash/chunks/{chunk-F4UILGOA.js.map → chunk-HFEU5SBQ.js.map} +1 -1
  18. package/dist/safe-bash/chunks/{chunk-UL4TNDNV.js → chunk-PZMJ4EC3.js} +5 -3
  19. package/dist/safe-bash/chunks/{chunk-UL4TNDNV.js.map → chunk-PZMJ4EC3.js.map} +1 -1
  20. package/dist/safe-bash/chunks/chunk-R3QJL5HH.js +698 -0
  21. package/dist/safe-bash/chunks/chunk-R3QJL5HH.js.map +7 -0
  22. package/dist/safe-bash/chunks/{chunk-R5ZK7V4W.js → chunk-T5BV7HPD.js} +7 -5
  23. package/dist/safe-bash/chunks/{chunk-R5ZK7V4W.js.map → chunk-T5BV7HPD.js.map} +1 -1
  24. package/dist/safe-bash/chunks/{chunk-RVGX5DQT.js → chunk-TPD45VUZ.js} +15 -11
  25. package/dist/safe-bash/chunks/chunk-TPD45VUZ.js.map +7 -0
  26. package/dist/safe-bash/chunks/{chunk-GZH6ILJC.js → chunk-VNDFKT6F.js} +7 -5
  27. package/dist/safe-bash/chunks/{chunk-GZH6ILJC.js.map → chunk-VNDFKT6F.js.map} +1 -1
  28. package/dist/safe-bash/chunks/{chunk-ELK3CQTQ.js → chunk-WF4P7XKI.js} +7 -5
  29. package/dist/safe-bash/chunks/{chunk-ELK3CQTQ.js.map → chunk-WF4P7XKI.js.map} +1 -1
  30. package/dist/safe-bash/chunks/{chunk-67TENRTW.js → chunk-WODV2DVM.js} +7 -5
  31. package/dist/safe-bash/chunks/{chunk-67TENRTW.js.map → chunk-WODV2DVM.js.map} +1 -1
  32. package/dist/safe-bash/chunks/{chunk-QWCD4HKE.js → chunk-YEJBZLE5.js} +9 -7
  33. package/dist/safe-bash/chunks/{chunk-QWCD4HKE.js.map → chunk-YEJBZLE5.js.map} +1 -1
  34. package/dist/safe-bash/chunks/xz-AVXFDXW4.js +6042 -0
  35. package/dist/safe-bash/chunks/xz-AVXFDXW4.js.map +7 -0
  36. package/dist/safe-bash/chunks/zstd-R6RPHJYO.js +27110 -0
  37. package/dist/safe-bash/chunks/zstd-R6RPHJYO.js.map +7 -0
  38. package/dist/safe-bash/commands/bytes/compression/bounded-codec.d.ts +20 -0
  39. package/dist/safe-bash/commands/bytes/compression/bounded-codec.d.ts.map +1 -0
  40. package/dist/safe-bash/commands/bytes/compression/bounded-codec.js +111 -0
  41. package/dist/safe-bash/commands/bytes/compression/bounded-codec.js.map +1 -0
  42. package/dist/safe-bash/commands/bytes/compression/codec-loader.d.ts +5 -0
  43. package/dist/safe-bash/commands/bytes/compression/codec-loader.d.ts.map +1 -0
  44. package/dist/safe-bash/commands/bytes/compression/codec-loader.js +89 -0
  45. package/dist/safe-bash/commands/bytes/compression/codec-loader.js.map +1 -0
  46. package/dist/safe-bash/commands/bytes/compression/file-operation.d.ts +16 -0
  47. package/dist/safe-bash/commands/bytes/compression/file-operation.d.ts.map +1 -0
  48. package/dist/safe-bash/commands/bytes/compression/file-operation.js +134 -0
  49. package/dist/safe-bash/commands/bytes/compression/file-operation.js.map +1 -0
  50. package/dist/safe-bash/commands/bytes/compression/files.d.ts +1 -1
  51. package/dist/safe-bash/commands/bytes/compression/files.d.ts.map +1 -1
  52. package/dist/safe-bash/commands/bytes/compression/files.js +141 -67
  53. package/dist/safe-bash/commands/bytes/compression/files.js.map +1 -1
  54. package/dist/safe-bash/commands/bytes/compression/index.js +3 -3
  55. package/dist/safe-bash/commands/bytes/compression/index.js.map +1 -1
  56. package/dist/safe-bash/commands/bytes/compression/native/LICENSES.txt +777 -0
  57. package/dist/safe-bash/commands/bytes/compression/native/generated/bz2.d.mts +3 -0
  58. package/dist/safe-bash/commands/bytes/compression/native/generated/bz2.mjs +2 -0
  59. package/dist/safe-bash/commands/bytes/compression/native/generated/xz.d.mts +3 -0
  60. package/dist/safe-bash/commands/bytes/compression/native/generated/xz.mjs +2 -0
  61. package/dist/safe-bash/commands/bytes/compression/native/generated/zstd.d.mts +3 -0
  62. package/dist/safe-bash/commands/bytes/compression/native/generated/zstd.mjs +2 -0
  63. package/dist/safe-bash/commands/bytes/compression/native/sources.json +246 -0
  64. package/dist/safe-bash/commands/bytes/compression/native/types.d.ts +17 -0
  65. package/dist/safe-bash/commands/bytes/compression/native/types.d.ts.map +1 -0
  66. package/dist/safe-bash/commands/bytes/compression/native/types.js +2 -0
  67. package/dist/safe-bash/commands/bytes/compression/native/types.js.map +1 -0
  68. package/dist/safe-bash/commands/bytes/compression/options.d.ts +27 -0
  69. package/dist/safe-bash/commands/bytes/compression/options.d.ts.map +1 -1
  70. package/dist/safe-bash/commands/bytes/compression/options.js +16 -3
  71. package/dist/safe-bash/commands/bytes/compression/options.js.map +1 -1
  72. package/dist/safe-bash/commands/bytes/compression/stream.d.ts.map +1 -1
  73. package/dist/safe-bash/commands/bytes/compression/stream.js +9 -5
  74. package/dist/safe-bash/commands/bytes/compression/stream.js.map +1 -1
  75. package/dist/safe-bash/commands/csplit/index.browser.js +6 -5
  76. package/dist/safe-bash/commands/factor/index.browser.js +4 -3
  77. package/dist/safe-bash/commands/getopt/index.browser.js +4 -3
  78. package/dist/safe-bash/commands/hexdump/command.d.ts +5 -0
  79. package/dist/safe-bash/commands/hexdump/command.d.ts.map +1 -0
  80. package/dist/safe-bash/commands/hexdump/command.js +174 -0
  81. package/dist/safe-bash/commands/hexdump/command.js.map +1 -0
  82. package/dist/safe-bash/commands/hexdump/format.d.ts +2 -0
  83. package/dist/safe-bash/commands/hexdump/format.d.ts.map +1 -0
  84. package/dist/safe-bash/commands/hexdump/format.js +25 -0
  85. package/dist/safe-bash/commands/hexdump/format.js.map +1 -0
  86. package/dist/safe-bash/commands/hexdump/index.browser.js +17 -0
  87. package/dist/safe-bash/commands/hexdump/index.browser.js.map +7 -0
  88. package/dist/safe-bash/commands/hexdump/index.d.ts +7 -0
  89. package/dist/safe-bash/commands/hexdump/index.d.ts.map +1 -0
  90. package/dist/safe-bash/commands/hexdump/index.js +17 -0
  91. package/dist/safe-bash/commands/hexdump/index.js.map +1 -0
  92. package/dist/safe-bash/commands/hexdump/internal.d.ts +52 -0
  93. package/dist/safe-bash/commands/hexdump/internal.d.ts.map +1 -0
  94. package/dist/safe-bash/commands/hexdump/internal.js +150 -0
  95. package/dist/safe-bash/commands/hexdump/internal.js.map +1 -0
  96. package/dist/safe-bash/commands/hexdump/io.d.ts +41 -0
  97. package/dist/safe-bash/commands/hexdump/io.d.ts.map +1 -0
  98. package/dist/safe-bash/commands/hexdump/io.js +288 -0
  99. package/dist/safe-bash/commands/hexdump/io.js.map +1 -0
  100. package/dist/safe-bash/commands/hexdump/options.d.ts +10 -0
  101. package/dist/safe-bash/commands/hexdump/options.d.ts.map +1 -0
  102. package/dist/safe-bash/commands/hexdump/options.js +80 -0
  103. package/dist/safe-bash/commands/hexdump/options.js.map +1 -0
  104. package/dist/safe-bash/commands/network/curl.js +1 -1
  105. package/dist/safe-bash/commands/network/curl.js.map +1 -1
  106. package/dist/safe-bash/commands/network/index.browser.js +7 -6
  107. package/dist/safe-bash/commands/network/output.d.ts.map +1 -1
  108. package/dist/safe-bash/commands/network/output.js +2 -2
  109. package/dist/safe-bash/commands/network/output.js.map +1 -1
  110. package/dist/safe-bash/commands/network/types.d.ts +4 -0
  111. package/dist/safe-bash/commands/network/types.d.ts.map +1 -1
  112. package/dist/safe-bash/commands/network/types.js.map +1 -1
  113. package/dist/safe-bash/commands/pr/index.browser.js +5 -4
  114. package/dist/safe-bash/commands/truncate.d.ts.map +1 -1
  115. package/dist/safe-bash/commands/truncate.js +14 -1
  116. package/dist/safe-bash/commands/truncate.js.map +1 -1
  117. package/dist/safe-bash/commands/tsort/index.browser.js +5 -4
  118. package/dist/safe-bash/commands/xml/index.browser.js +6 -5
  119. package/dist/safe-bash/commands/yq/index.browser.js +7 -6
  120. package/dist/safe-bash/contracts/filesystem.d.ts +1 -1
  121. package/dist/safe-bash/contracts/filesystem.d.ts.map +1 -1
  122. package/dist/safe-bash/contracts/yield.d.ts +1 -0
  123. package/dist/safe-bash/contracts/yield.d.ts.map +1 -1
  124. package/dist/safe-bash/contracts/yield.js +5 -0
  125. package/dist/safe-bash/contracts/yield.js.map +1 -1
  126. package/dist/safe-bash/core.browser.js +597 -163
  127. package/dist/safe-bash/core.browser.js.map +4 -4
  128. package/dist/safe-bash/core.d.ts +1 -0
  129. package/dist/safe-bash/core.d.ts.map +1 -1
  130. package/dist/safe-bash/core.js +1 -0
  131. package/dist/safe-bash/core.js.map +1 -1
  132. package/dist/safe-bash/plugins/composition.d.ts +2 -0
  133. package/dist/safe-bash/plugins/composition.d.ts.map +1 -1
  134. package/dist/safe-bash/plugins/composition.js +3 -1
  135. package/dist/safe-bash/plugins/composition.js.map +1 -1
  136. package/package.json +8 -2
  137. package/dist/safe-bash/chunks/chunk-RVGX5DQT.js.map +0 -7
  138. /package/dist/safe-bash/chunks/{chunk-CI42NIWL.js.map → chunk-DPJWEGIX.js.map} +0 -0
@@ -2,12 +2,18 @@ import {
2
2
  createGetoptCommand,
3
3
  createGetoptCommands,
4
4
  getoptCommands
5
- } from "./chunks/chunk-GV76QENF.js";
5
+ } from "./chunks/chunk-EZLQA6ON.js";
6
+ import {
7
+ createHdCommand,
8
+ createHexdumpCommand,
9
+ createHexdumpCommands,
10
+ hexdumpCommands
11
+ } from "./chunks/chunk-R3QJL5HH.js";
6
12
  import {
7
13
  createXmlCommands,
8
14
  defaultXmlQueryLimits,
9
15
  xmlCommands
10
- } from "./chunks/chunk-F4UILGOA.js";
16
+ } from "./chunks/chunk-HFEU5SBQ.js";
11
17
  import {
12
18
  Interpreter,
13
19
  createYqCommand,
@@ -18,7 +24,7 @@ import {
18
24
  rawValues,
19
25
  stringify,
20
26
  yqCommands
21
- } from "./chunks/chunk-QWCD4HKE.js";
27
+ } from "./chunks/chunk-YEJBZLE5.js";
22
28
  import {
23
29
  Budget,
24
30
  JqError,
@@ -31,7 +37,7 @@ import {
31
37
  resolveJqLimits,
32
38
  truth,
33
39
  wellFormed
34
- } from "./chunks/chunk-5X2TAR25.js";
40
+ } from "./chunks/chunk-6PSMEBVP.js";
35
41
  import {
36
42
  CurlError,
37
43
  cloudflareWorkerNetworkLimits,
@@ -44,7 +50,7 @@ import {
44
50
  curlCommands,
45
51
  defaultNetworkLimits,
46
52
  networkCommands
47
- } from "./chunks/chunk-RVGX5DQT.js";
53
+ } from "./chunks/chunk-TPD45VUZ.js";
48
54
  import {
49
55
  RecordBuffer,
50
56
  UsageError,
@@ -76,7 +82,7 @@ import {
76
82
  textOutputRequirements,
77
83
  value,
78
84
  writeDiagnostic
79
- } from "./chunks/chunk-R5ZK7V4W.js";
85
+ } from "./chunks/chunk-T5BV7HPD.js";
80
86
  import {
81
87
  AvailableRecords,
82
88
  EreLedger,
@@ -96,22 +102,22 @@ import {
96
102
  exprMatchCeilings,
97
103
  matchEre,
98
104
  withRegexSession
99
- } from "./chunks/chunk-67TENRTW.js";
105
+ } from "./chunks/chunk-WODV2DVM.js";
100
106
  import {
101
107
  bindFileOutputBudget,
102
108
  openFileOutput,
103
109
  writeFileOutput
104
- } from "./chunks/chunk-RDIJ6M2D.js";
110
+ } from "./chunks/chunk-AZNI263O.js";
105
111
  import {
106
112
  createPrCommand,
107
113
  createPrCommands,
108
114
  prCommands
109
- } from "./chunks/chunk-GZH6ILJC.js";
115
+ } from "./chunks/chunk-VNDFKT6F.js";
110
116
  import {
111
117
  createTsortCommand,
112
118
  createTsortCommands,
113
119
  tsortCommands
114
- } from "./chunks/chunk-ELK3CQTQ.js";
120
+ } from "./chunks/chunk-WF4P7XKI.js";
115
121
  import {
116
122
  basename,
117
123
  dirname,
@@ -121,15 +127,15 @@ import {
121
127
  relativePath,
122
128
  resolvePath,
123
129
  validatePath
124
- } from "./chunks/chunk-CI42NIWL.js";
130
+ } from "./chunks/chunk-DPJWEGIX.js";
125
131
  import {
126
132
  createFactorCommand,
127
133
  createFactorCommands,
128
134
  factorCommands
129
- } from "./chunks/chunk-LUIEXTN5.js";
135
+ } from "./chunks/chunk-66VSWIUC.js";
130
136
  import {
131
137
  createOutputOperation
132
- } from "./chunks/chunk-UL4TNDNV.js";
138
+ } from "./chunks/chunk-PZMJ4EC3.js";
133
139
  import {
134
140
  CommandArgumentIdentityError,
135
141
  CommandRegistry,
@@ -142,8 +148,7 @@ import {
142
148
  createBytePipe,
143
149
  createCommandArguments,
144
150
  getCommandArguments,
145
- import_buffer,
146
- init_platform,
151
+ inheritYieldCheckpoint,
147
152
  isErrnoCode,
148
153
  isFsError,
149
154
  monotonicNow,
@@ -164,7 +169,11 @@ import {
164
169
  writeBytes,
165
170
  writeText,
166
171
  yieldTurn
167
- } from "./chunks/chunk-4NMFAR4Z.js";
172
+ } from "./chunks/chunk-5VBLSPNM.js";
173
+ import {
174
+ import_buffer,
175
+ init_platform
176
+ } from "./chunks/chunk-2KL6W6NB.js";
168
177
 
169
178
  // packages/safe-bash/src/core.browser.ts
170
179
  init_platform();
@@ -17252,6 +17261,88 @@ init_platform();
17252
17261
 
17253
17262
  // packages/safe-bash/src/commands/bytes/compression/files.ts
17254
17263
  init_platform();
17264
+ import { retainFileSystemCleanup } from "@poe-platform/safe-fs/core";
17265
+
17266
+ // packages/safe-bash/src/commands/bytes/compression/options.ts
17267
+ init_platform();
17268
+ var profiles = [
17269
+ { format: "gzip", names: ["gzip", "gunzip", "zcat"], suffix: ".gz", level: 6, keep: false },
17270
+ { format: "bzip2", names: ["bzip2", "bunzip2", "bzcat"], suffix: ".bz2", level: 9, keep: false },
17271
+ { format: "xz", names: ["xz", "unxz", "xzcat"], suffix: ".xz", level: 3, keep: false },
17272
+ { format: "zstd", names: ["zstd", "unzstd", "zstdcat"], suffix: ".zst", level: 3, keep: true }
17273
+ ];
17274
+ var aliases = {
17275
+ stdout: "c",
17276
+ "to-stdout": "c",
17277
+ decompress: "d",
17278
+ uncompress: "d",
17279
+ keep: "k",
17280
+ force: "f",
17281
+ test: "t",
17282
+ fast: "1",
17283
+ best: "9",
17284
+ "no-name": "n",
17285
+ help: "h"
17286
+ };
17287
+ function parseOptions(command7, args) {
17288
+ const profile2 = profiles.find((value2) => value2.names.some((name2) => name2 === command7));
17289
+ if (!profile2) throw new UsageError(`unknown compression command '${command7}'`);
17290
+ const result2 = {
17291
+ format: profile2.format,
17292
+ decompress: command7 !== profile2.names[0],
17293
+ stdout: command7 === profile2.names[2],
17294
+ keep: profile2.keep,
17295
+ force: false,
17296
+ test: false,
17297
+ help: false,
17298
+ level: profile2.level,
17299
+ operands: []
17300
+ };
17301
+ let ended = false;
17302
+ for (const argument2 of args) {
17303
+ if (ended || argument2 === "-" || !argument2.startsWith("-")) {
17304
+ result2.operands.push(argument2);
17305
+ continue;
17306
+ }
17307
+ if (argument2 === "--") {
17308
+ ended = true;
17309
+ continue;
17310
+ }
17311
+ const flags3 = argument2.startsWith("--") ? aliases[argument2.slice(2)] : argument2.slice(1);
17312
+ if (!flags3) throw new UsageError(`unrecognized option '${argument2}'`);
17313
+ for (const flag of flags3) {
17314
+ switch (flag) {
17315
+ case "c":
17316
+ result2.stdout = true;
17317
+ break;
17318
+ case "d":
17319
+ result2.decompress = true;
17320
+ break;
17321
+ case "k":
17322
+ result2.keep = true;
17323
+ break;
17324
+ case "f":
17325
+ result2.force = true;
17326
+ break;
17327
+ case "t":
17328
+ result2.test = true;
17329
+ result2.decompress = true;
17330
+ break;
17331
+ case "h":
17332
+ result2.help = true;
17333
+ break;
17334
+ case "n":
17335
+ if (profile2.format !== "gzip") throw new UsageError(`invalid option -- '${flag}'`);
17336
+ break;
17337
+ default:
17338
+ if (/^[1-9]$/u.test(flag)) result2.level = Number(flag);
17339
+ else throw new UsageError(`invalid option -- '${flag}'`);
17340
+ }
17341
+ }
17342
+ }
17343
+ if (!result2.operands.length) result2.operands.push("-");
17344
+ return result2;
17345
+ }
17255
17346
 
17256
17347
  // packages/safe-bash/src/commands/bytes/compression/stream.ts
17257
17348
  init_platform();
@@ -20545,6 +20636,187 @@ async function* gunzipMembers(source2, parentSignal, force, warn) {
20545
20636
  }
20546
20637
  }
20547
20638
 
20639
+ // packages/safe-bash/src/commands/bytes/compression/bounded-codec.ts
20640
+ init_platform();
20641
+
20642
+ // packages/safe-bash/src/commands/bytes/compression/codec-loader.ts
20643
+ init_platform();
20644
+ function unavailable() {
20645
+ throw new Error("codec attempted an unavailable host operation");
20646
+ }
20647
+ var wasi = Object.freeze({
20648
+ fd_prestat_get: () => 8,
20649
+ fd_prestat_dir_name: unavailable,
20650
+ fd_write: unavailable,
20651
+ fd_read: unavailable,
20652
+ fd_close: unavailable,
20653
+ fd_seek: unavailable,
20654
+ fd_fdstat_get: unavailable,
20655
+ fd_fdstat_set_flags: unavailable,
20656
+ fd_filestat_get: unavailable,
20657
+ environ_get: unavailable,
20658
+ environ_sizes_get: unavailable,
20659
+ random_get: unavailable,
20660
+ clock_time_get: unavailable,
20661
+ proc_exit: unavailable
20662
+ });
20663
+ async function createCodec(options2, signal, factory) {
20664
+ signal.throwIfAborted();
20665
+ if (!Number.isInteger(options2.level) || options2.level < 1 || options2.level > 9) throw new RangeError("invalid codec level");
20666
+ if (!factory) {
20667
+ switch (options2.format) {
20668
+ case "bzip2":
20669
+ factory = (await import("./chunks/bz2-B2RXT4EX.js")).default;
20670
+ break;
20671
+ case "xz":
20672
+ factory = (await import("./chunks/xz-AVXFDXW4.js")).default;
20673
+ break;
20674
+ case "zstd":
20675
+ factory = (await import("./chunks/zstd-R6RPHJYO.js")).default;
20676
+ break;
20677
+ }
20678
+ }
20679
+ signal.throwIfAborted();
20680
+ const module = factory(wasi);
20681
+ let closed = false;
20682
+ const close = () => {
20683
+ if (!closed) {
20684
+ closed = true;
20685
+ module.bridge_destroy();
20686
+ }
20687
+ };
20688
+ try {
20689
+ module._initialize?.();
20690
+ const initialized = module.bridge_create(Number(options2.decompress), options2.level, 64 * 1024 * 1024, 23);
20691
+ signal.throwIfAborted();
20692
+ if (initialized !== 0) throw new PublicDiagnostic("codec initialization failed or memory limit exceeded");
20693
+ const inputPointer = module.bridge_input();
20694
+ const outputPointer = module.bridge_output();
20695
+ return {
20696
+ step(input3, output2, finish) {
20697
+ signal.throwIfAborted();
20698
+ if (closed) throw new Error("codec is closed");
20699
+ if (input3.length > 65536 || output2.length < 1 || output2.length > 65536) throw new RangeError("invalid codec buffer size");
20700
+ new Uint8Array(module.memory.buffer, inputPointer, input3.length).set(input3);
20701
+ const status2 = module.bridge_step(inputPointer, input3.length, outputPointer, output2.length, Number(finish));
20702
+ signal.throwIfAborted();
20703
+ if (status2 === -4) throw new PublicDiagnostic("unexpected end of file");
20704
+ if (status2 === -2 || status2 === -3) throw new PublicDiagnostic("invalid compressed data or codec memory limit exceeded");
20705
+ if (status2 !== 1 && status2 !== 2 && status2 !== 3) throw new Error(`invalid codec status ${status2}`);
20706
+ const consumed = module.bridge_consumed();
20707
+ const produced = module.bridge_produced();
20708
+ if (!Number.isSafeInteger(consumed) || consumed < 0 || consumed > input3.length || !Number.isSafeInteger(produced) || produced < 0 || produced > output2.length) throw new Error("invalid codec progress");
20709
+ output2.set(new Uint8Array(module.memory.buffer, outputPointer, produced));
20710
+ return { consumed, produced, status: status2 === 1 ? "end" : status2 === 3 ? "output" : "input" };
20711
+ },
20712
+ close
20713
+ };
20714
+ } catch (error) {
20715
+ try {
20716
+ close();
20717
+ } catch {
20718
+ }
20719
+ throw error;
20720
+ }
20721
+ }
20722
+
20723
+ // packages/safe-bash/src/commands/bytes/compression/bounded-codec.ts
20724
+ async function* boundedCodec(input3, options2, signal, create = createCodec) {
20725
+ signal.throwIfAborted();
20726
+ let stream;
20727
+ let current = new Uint8Array();
20728
+ let offset = 0;
20729
+ let eof = false;
20730
+ let needsInput = true;
20731
+ let ended = false;
20732
+ let calls = 0;
20733
+ let work = 0;
20734
+ let failed = false;
20735
+ let output2 = new Uint8Array(64 * 1024);
20736
+ try {
20737
+ stream = await create(options2, signal);
20738
+ for (; ; ) {
20739
+ signal.throwIfAborted();
20740
+ if ((needsInput || ended) && offset === current.length && !eof) {
20741
+ current = await input3.chunk() ?? new Uint8Array();
20742
+ offset = 0;
20743
+ eof = current.length === 0;
20744
+ signal.throwIfAborted();
20745
+ }
20746
+ if (ended) {
20747
+ if (options2.format === "xz") {
20748
+ let padding = 0;
20749
+ while (!eof) {
20750
+ while (offset < current.length && current[offset] === 0) {
20751
+ offset++;
20752
+ padding = (padding + 1) % 4;
20753
+ if (++work >= 64 * 1024) {
20754
+ await yieldTurn(signal);
20755
+ work = 0;
20756
+ calls = 0;
20757
+ }
20758
+ }
20759
+ if (offset < current.length) break;
20760
+ current = await input3.chunk() ?? new Uint8Array();
20761
+ offset = 0;
20762
+ eof = current.length === 0;
20763
+ signal.throwIfAborted();
20764
+ }
20765
+ if (padding) throw new PublicDiagnostic("invalid XZ stream padding");
20766
+ }
20767
+ if (eof) return;
20768
+ const previous = stream;
20769
+ stream = void 0;
20770
+ previous.close();
20771
+ stream = await create(options2, signal);
20772
+ signal.throwIfAborted();
20773
+ ended = false;
20774
+ }
20775
+ const bytes3 = current.subarray(offset, Math.min(current.length, offset + 64 * 1024));
20776
+ const result2 = stream.step(bytes3, output2, eof);
20777
+ signal.throwIfAborted();
20778
+ if (!Number.isSafeInteger(result2.consumed) || result2.consumed < 0 || result2.consumed > bytes3.length || !Number.isSafeInteger(result2.produced) || result2.produced < 0 || result2.produced > output2.length || !["input", "output", "end"].includes(result2.status)) {
20779
+ throw new Error("invalid codec progress");
20780
+ }
20781
+ offset += result2.consumed;
20782
+ if (!result2.consumed && !result2.produced && result2.status !== "end") {
20783
+ if (eof) throw new PublicDiagnostic("unexpected end of file");
20784
+ if (bytes3.length || result2.status !== "input") throw new Error("codec made no progress");
20785
+ }
20786
+ if (result2.produced) {
20787
+ yield output2.subarray(0, result2.produced);
20788
+ signal.throwIfAborted();
20789
+ output2 = new Uint8Array(64 * 1024);
20790
+ }
20791
+ signal.throwIfAborted();
20792
+ work += result2.consumed + result2.produced;
20793
+ if (++calls >= 64 || work >= 64 * 1024) {
20794
+ await yieldTurn(signal);
20795
+ calls = 0;
20796
+ work = 0;
20797
+ }
20798
+ if (result2.status === "end") {
20799
+ if (!options2.decompress) return;
20800
+ ended = true;
20801
+ }
20802
+ needsInput = result2.status !== "output";
20803
+ }
20804
+ } catch (error) {
20805
+ failed = true;
20806
+ options2.onFailure?.(error);
20807
+ throw error;
20808
+ } finally {
20809
+ if (failed) {
20810
+ try {
20811
+ stream?.close();
20812
+ } catch {
20813
+ }
20814
+ } else {
20815
+ stream?.close();
20816
+ }
20817
+ }
20818
+ }
20819
+
20548
20820
  // packages/safe-bash/src/commands/bytes/compression/stream.ts
20549
20821
  var chunkBytes = 64 * 1024;
20550
20822
  var stagingLimit = 256 * 1024 * 1024;
@@ -20607,6 +20879,7 @@ async function* split2(source2, signal, fail4) {
20607
20879
  async function transform(source2, consume, options2, parentSignal, maxOutput = Infinity) {
20608
20880
  const controller = new AbortController();
20609
20881
  const signal = AbortSignal.any([parentSignal, controller.signal]);
20882
+ inheritYieldCheckpoint(parentSignal, signal);
20610
20883
  let failure;
20611
20884
  let hasFailure = false;
20612
20885
  const fail4 = (error) => {
@@ -20618,11 +20891,11 @@ async function transform(source2, consume, options2, parentSignal, maxOutput = I
20618
20891
  };
20619
20892
  let prepared = split2(typeof source2 === "function" ? source2(signal) : source2, signal, fail4);
20620
20893
  let warned2 = false;
20621
- if (options2.decompress) prepared = gunzipMembers(prepared, signal, options2.force, () => {
20894
+ if (options2.format === "gzip" && options2.decompress) prepared = gunzipMembers(prepared, signal, options2.force, () => {
20622
20895
  warned2 = true;
20623
20896
  });
20624
- const reader = options2.decompress ? void 0 : new CodecReader(prepared, signal);
20625
- const transformed = reader ? codec(reader, { mode: "gzip", level: options2.level, onFailure: fail4 }, signal) : prepared;
20897
+ const reader = options2.format === "gzip" && options2.decompress ? void 0 : new CodecReader(prepared, signal);
20898
+ const transformed = options2.format !== "gzip" ? boundedCodec(reader, { format: options2.format, decompress: options2.decompress, level: options2.level, onFailure: fail4 }, signal) : reader ? codec(reader, { mode: "gzip", level: options2.level, onFailure: fail4 }, signal) : prepared;
20626
20899
  let consumed = false;
20627
20900
  const output2 = (async function* () {
20628
20901
  let size = 0;
@@ -20630,7 +20903,7 @@ async function transform(source2, consume, options2, parentSignal, maxOutput = I
20630
20903
  for await (const chunk of readBytes(transformed, signal)) {
20631
20904
  if (chunk.length > maxOutput - size) throw new FsError("EFBIG", { message: `staged output exceeds ${maxOutput} bytes` });
20632
20905
  let bytes3 = chunk;
20633
- if (!options2.decompress && size <= 9 && size + chunk.length > 9) {
20906
+ if (options2.format === "gzip" && !options2.decompress && size <= 9 && size + chunk.length > 9) {
20634
20907
  bytes3 = chunk.slice();
20635
20908
  bytes3[9 - size] = 255;
20636
20909
  }
@@ -20662,15 +20935,153 @@ async function transform(source2, consume, options2, parentSignal, maxOutput = I
20662
20935
  return warned2;
20663
20936
  }
20664
20937
 
20938
+ // packages/safe-bash/src/commands/bytes/compression/file-operation.ts
20939
+ init_platform();
20940
+ var FileOperation = class {
20941
+ signal;
20942
+ fs;
20943
+ controller = new AbortController();
20944
+ pending = /* @__PURE__ */ new Set();
20945
+ sources = [];
20946
+ closing;
20947
+ caller;
20948
+ constructor(context2, cleanup) {
20949
+ this.caller = context2.signal;
20950
+ this.signal = this.controller.signal;
20951
+ this.caller.throwIfAborted();
20952
+ inheritYieldCheckpoint(this.caller, this.signal);
20953
+ const filesystem = context2.fs;
20954
+ this.caller.throwIfAborted();
20955
+ this.fs = new Proxy(filesystem, {
20956
+ get: (target, key) => {
20957
+ this.check();
20958
+ const value2 = Reflect.get(target, key, target);
20959
+ this.check();
20960
+ return typeof value2 === "function" ? (...args) => {
20961
+ this.check();
20962
+ const result2 = Reflect.apply(value2, target, args);
20963
+ return key === "readStream" ? this.ownSource(result2) : result2;
20964
+ } : value2;
20965
+ }
20966
+ });
20967
+ let outcomeClaimed = false;
20968
+ let registeredClosing;
20969
+ const abort = () => {
20970
+ void retire().catch(() => {
20971
+ });
20972
+ };
20973
+ const retire = () => {
20974
+ if (!this.closing) {
20975
+ this.closing = Promise.resolve().then(async () => {
20976
+ try {
20977
+ const sources2 = Promise.allSettled(this.sources.map((close) => close()));
20978
+ await Promise.allSettled([...this.pending]);
20979
+ const outcomes = await sources2;
20980
+ await cleanup?.();
20981
+ const failures = outcomes.filter((outcome) => outcome.status === "rejected").map((outcome) => outcome.reason);
20982
+ if (failures.length === 1) throw failures[0];
20983
+ if (failures.length) throw new AggregateError(failures, "Compression source cleanup failed");
20984
+ } finally {
20985
+ this.caller.removeEventListener("abort", abort);
20986
+ }
20987
+ });
20988
+ void this.closing.catch(() => {
20989
+ });
20990
+ this.controller.abort(this.caller.aborted ? this.caller.reason : new Error("Compression file operation is closed"));
20991
+ }
20992
+ return this.closing;
20993
+ };
20994
+ this.close = () => {
20995
+ outcomeClaimed = true;
20996
+ return retire();
20997
+ };
20998
+ const register = context2.registerCleanup;
20999
+ this.check();
21000
+ if (register) Reflect.apply(register, context2, [() => {
21001
+ registeredClosing ??= retire().catch((error) => {
21002
+ if (!outcomeClaimed) throw error;
21003
+ });
21004
+ void registeredClosing.catch(() => {
21005
+ });
21006
+ return registeredClosing;
21007
+ }]);
21008
+ this.check();
21009
+ this.caller.addEventListener("abort", abort, { once: true });
21010
+ if (this.caller.aborted) abort();
21011
+ }
21012
+ close;
21013
+ check() {
21014
+ this.caller.throwIfAborted();
21015
+ this.signal.throwIfAborted();
21016
+ }
21017
+ async run(start) {
21018
+ this.check();
21019
+ const pending = Promise.resolve().then(() => {
21020
+ this.check();
21021
+ return start();
21022
+ });
21023
+ this.pending.add(pending);
21024
+ try {
21025
+ return await pending;
21026
+ } finally {
21027
+ this.pending.delete(pending);
21028
+ }
21029
+ }
21030
+ ownSource(source2) {
21031
+ let iterator = void 0;
21032
+ let closing;
21033
+ const close = () => {
21034
+ closing ??= Promise.resolve().then(async () => {
21035
+ const method = iterator?.return;
21036
+ return method ? await Reflect.apply(method, iterator, []) : { done: true, value: void 0 };
21037
+ });
21038
+ void closing.catch(() => {
21039
+ });
21040
+ return closing;
21041
+ };
21042
+ this.sources.push(close);
21043
+ const factory = source2[Symbol.asyncIterator];
21044
+ iterator = Reflect.apply(factory, source2, []);
21045
+ this.check();
21046
+ let claimed = false;
21047
+ return {
21048
+ [Symbol.asyncIterator]: () => {
21049
+ this.check();
21050
+ if (claimed) throw new Error("Compression input was already acquired");
21051
+ claimed = true;
21052
+ return {
21053
+ next: async () => {
21054
+ this.check();
21055
+ if (closing) throw new Error("Compression input is closed");
21056
+ const method = iterator.next;
21057
+ this.check();
21058
+ const result2 = await Reflect.apply(method, iterator, []);
21059
+ this.check();
21060
+ const done = result2.done;
21061
+ this.check();
21062
+ const value2 = result2.value;
21063
+ this.check();
21064
+ return done ? { done: true, value: value2 } : { done: false, value: value2 };
21065
+ },
21066
+ return: close
21067
+ };
21068
+ }
21069
+ };
21070
+ }
21071
+ };
21072
+
20665
21073
  // packages/safe-bash/src/commands/bytes/compression/files.ts
21074
+ function identified(stat) {
21075
+ return stat.identityScope !== void 0 && Number.isSafeInteger(stat.ino) && Number.isSafeInteger(stat.dev);
21076
+ }
20666
21077
  function sameIdentity(first, second) {
20667
- return first.ino !== void 0 && second.ino !== void 0 && first.ino === second.ino && first.dev === second.dev;
21078
+ return identified(first) && identified(second) && first.identityScope === second.identityScope && first.ino === second.ino && first.dev === second.dev;
20668
21079
  }
20669
21080
  function sameSnapshot(first, second) {
20670
- return first.type === second.type && first.size === second.size && first.mode === second.mode && first.mtimeMs === second.mtimeMs && first.ctimeMs === second.ctimeMs && first.ino === second.ino && first.dev === second.dev && first.nlink === second.nlink && first.birthtimeMs === second.birthtimeMs && first.uid === second.uid && first.gid === second.gid;
21081
+ return first.type === second.type && first.size === second.size && first.mode === second.mode && first.mtimeMs === second.mtimeMs && first.ctimeMs === second.ctimeMs && first.ino === second.ino && first.dev === second.dev && first.nlink === second.nlink && first.birthtimeMs === second.birthtimeMs && first.uid === second.uid && first.gid === second.gid && first.identityScope === second.identityScope;
20671
21082
  }
20672
21083
  function sameEntry(first, second) {
20673
- return first.type === second.type && first.ino === second.ino && first.dev === second.dev && first.birthtimeMs === second.birthtimeMs;
21084
+ return sameIdentity(first, second) && first.type === second.type && first.birthtimeMs === second.birthtimeMs;
20674
21085
  }
20675
21086
  async function existing(context2, path) {
20676
21087
  try {
@@ -20681,6 +21092,17 @@ async function existing(context2, path) {
20681
21092
  }
20682
21093
  }
20683
21094
  function outputPath(source2, options2) {
21095
+ if (options2.format !== "gzip") {
21096
+ const suffix2 = profiles.find((profile2) => profile2.format === options2.format).suffix;
21097
+ if (options2.decompress) {
21098
+ if (!source2.endsWith(suffix2)) throw new FsError("EINVAL", { path: source2, message: `unknown ${options2.format} suffix (use -c for stdout)` });
21099
+ const destination2 = source2.slice(0, -suffix2.length);
21100
+ if (destination2.endsWith("/")) throw new FsError("EINVAL", { path: source2, message: "empty output filename" });
21101
+ return destination2;
21102
+ }
21103
+ if (!options2.force && source2.endsWith(suffix2)) throw new FsError("EINVAL", { path: source2, message: `already has a ${options2.format} suffix (use -f to compress again)` });
21104
+ return source2 + suffix2;
21105
+ }
20684
21106
  if (options2.decompress) {
20685
21107
  if (/\.(?:tgz|taz)$/iu.test(source2)) return source2.slice(0, -4) + ".tar";
20686
21108
  const suffix2 = /(?:\.gz|\.z|-gz|-z|_z)$/iu.exec(source2);
@@ -20695,6 +21117,15 @@ function outputPath(source2, options2) {
20695
21117
  return source2 + ".gz";
20696
21118
  }
20697
21119
  async function planOperands(context2, options2) {
21120
+ const operation2 = new FileOperation(context2);
21121
+ try {
21122
+ return await operation2.run(() => collectOperands({ ...context2, fs: operation2.fs, signal: operation2.signal }, options2));
21123
+ } finally {
21124
+ await operation2.close();
21125
+ context2.signal.throwIfAborted();
21126
+ }
21127
+ }
21128
+ async function collectOperands(context2, options2) {
20698
21129
  const plans = [];
20699
21130
  for (const name2 of options2.operands) {
20700
21131
  context2.signal.throwIfAborted();
@@ -20728,6 +21159,13 @@ async function planOperands(context2, options2) {
20728
21159
  throw new FsError("ENOTSUP", { message: "file output requires VFS streaming writes (use -c for stdout)" });
20729
21160
  }
20730
21161
  const destinationStat = await existing(context2, destination2);
21162
+ if (!identified(sourceStat) || destinationStat && !identified(destinationStat)) {
21163
+ throw new FsError("ENOTSUP", { path: source2, message: "file output requires stable scoped entry identities" });
21164
+ }
21165
+ if (!context2.fs.rmdir || capabilities.exclusiveCreate !== true || (destinationStat ? capabilities.atomicRename : capabilities.atomicRenameNoReplace) !== true) {
21166
+ throw new FsError("ENOTSUP", { path: destination2, message: "file output requires exclusive staging, safe rmdir and atomic publication (use -c for stdout)" });
21167
+ }
21168
+ context2.signal.throwIfAborted();
20731
21169
  if (destinationStat) {
20732
21170
  if (destinationStat.type !== "file" || sameIdentity(sourceStat, destinationStat) || realSource === await context2.fs.realpath(destination2, { signal: context2.signal })) {
20733
21171
  throw new FsError("EINVAL", { path: destination2, message: "destination is not a distinct regular file" });
@@ -20758,23 +21196,10 @@ async function unchangedSource(context2, plan) {
20758
21196
  throw new FsError("EBUSY", { path: plan.source, message: "input identity or metadata changed; input retained" });
20759
21197
  }
20760
21198
  }
20761
- async function temporaryDirectory(context2, destination2) {
20762
- for (let attempt = 0; attempt < 16; attempt++) {
20763
- const path = joinPath(dirname(destination2), `.virtual-bash-gzip-${globalThis.crypto.randomUUID()}`);
20764
- try {
20765
- await context2.fs.mkdir(path, { mode: 448, signal: context2.signal });
20766
- return path;
20767
- } catch (error) {
20768
- if (codeOf(error) !== "EEXIST") throw error;
20769
- }
20770
- }
20771
- throw new FsError("EEXIST", { message: "unable to allocate a private gzip staging directory" });
20772
- }
20773
21199
  async function writeFileOperand(context2, plan, options2) {
20774
21200
  const destination2 = plan.destination;
20775
- await unchangedSource(context2, plan);
20776
- const directory2 = await temporaryDirectory(context2, destination2);
20777
- const staged = joinPath(directory2, "data");
21201
+ let directory2;
21202
+ let staged;
20778
21203
  let directoryStat;
20779
21204
  let stageStat;
20780
21205
  let stageOwned = false;
@@ -20782,146 +21207,127 @@ async function writeFileOperand(context2, plan, options2) {
20782
21207
  let failure;
20783
21208
  let failed = false;
20784
21209
  let warned2 = false;
21210
+ let cleanupFailed = false;
21211
+ let retainedCleanup;
21212
+ const operation2 = new FileOperation(context2, async () => {
21213
+ await retainedCleanup?.();
21214
+ });
21215
+ const active = { ...context2, fs: operation2.fs, signal: operation2.signal };
21216
+ const { fs, signal } = active;
21217
+ const snapshot = (stat) => {
21218
+ const result2 = {};
21219
+ for (const key of ["type", "size", "mode", "mtimeMs", "atimeMs", "ctimeMs", "birthtimeMs", "identityScope", "ino", "dev", "nlink", "uid", "gid"]) {
21220
+ result2[key] = stat[key];
21221
+ operation2.check();
21222
+ }
21223
+ return Object.freeze(result2);
21224
+ };
20785
21225
  try {
20786
- directoryStat = await context2.fs.lstat(directory2, { signal: context2.signal });
20787
- if (directoryStat.type !== "directory") throw new FsError("EBUSY", { path: directory2 });
20788
- await context2.fs.writeFile(staged, new Uint8Array(), { flag: "wx", mode: 384, signal: context2.signal });
20789
- stageOwned = true;
20790
- stageStat = await context2.fs.lstat(staged, { signal: context2.signal });
20791
- if (stageStat.type !== "file" || stageStat.size !== 0) throw new FsError("EBUSY", { path: staged });
20792
- warned2 = await transform((signal) => context2.fs.readStream(plan.source, { signal, chunkSize: chunkBytes }), async (output2, signal) => {
20793
- await context2.fs.writeStream(staged, output2, { flag: "w", mode: 384, signal });
20794
- }, { ...options2, force: false }, context2.signal, stagingLimit);
20795
- await unchangedSource(context2, plan);
20796
- const target = await existing(context2, destination2);
21226
+ retainedCleanup = retainFileSystemCleanup(context2.fs, async (cleanup) => {
21227
+ if (directory2 === void 0) return;
21228
+ const cleanupSignal = AbortSignal.timeout(5e3);
21229
+ const currentDirectory = await cleanup.lstat(directory2, { signal: cleanupSignal });
21230
+ if (!directoryStat || !sameEntry(directoryStat, currentDirectory)) {
21231
+ throw new FsError("EBUSY", { path: directory2, message: "staging directory identity is unknown or changed; refusing cleanup" });
21232
+ }
21233
+ if (stageOwned && !moved && staged !== void 0) {
21234
+ let currentStage;
21235
+ try {
21236
+ currentStage = await cleanup.lstat(staged, { signal: cleanupSignal });
21237
+ } catch (error) {
21238
+ if (codeOf(error) !== "ENOENT") throw error;
21239
+ }
21240
+ if (currentStage) {
21241
+ if (!stageStat || !sameEntry(stageStat, currentStage)) throw new FsError("EBUSY", { path: staged, message: "staging file identity changed; refusing cleanup" });
21242
+ await cleanup.rm(staged, { signal: cleanupSignal });
21243
+ }
21244
+ }
21245
+ if (!cleanup.rmdir) throw new FsError("ENOTSUP", { path: directory2, message: "safe directory removal unavailable" });
21246
+ try {
21247
+ await cleanup.rmdir(directory2, { signal: cleanupSignal });
21248
+ } catch (error) {
21249
+ if (codeOf(error) === "ENOTEMPTY") throw new FsError("ENOTEMPTY", { path: directory2, message: "unexpected staging entries; refusing cleanup" });
21250
+ throw error;
21251
+ }
21252
+ }, { maxOperations: 8 });
21253
+ operation2.check();
21254
+ await operation2.run(() => unchangedSource(active, plan));
21255
+ for (let attempt = 0; directory2 === void 0 && attempt < 16; attempt++) {
21256
+ const path = joinPath(dirname(destination2), `.virtual-bash-gzip-${globalThis.crypto.randomUUID()}`);
21257
+ const capabilities = await operation2.run(async () => await fs.capabilitiesFor?.(path, { signal, create: true, allowDirectory: true }) ?? fs.capabilities);
21258
+ operation2.check();
21259
+ const snapshotRmdir = capabilities.snapshotRmdir;
21260
+ operation2.check();
21261
+ if (snapshotRmdir === true) throw new FsError("ENOTSUP", { path, message: "strong staging directory cleanup unavailable; snapshot-only rmdir is unsupported" });
21262
+ try {
21263
+ await operation2.run(async () => {
21264
+ await fs.mkdir(path, { mode: 448, signal });
21265
+ directory2 = path;
21266
+ });
21267
+ } catch (error) {
21268
+ operation2.check();
21269
+ if (codeOf(error) !== "EEXIST") throw error;
21270
+ }
21271
+ }
21272
+ if (directory2 === void 0) throw new FsError("EEXIST", { message: "unable to allocate a private gzip staging directory" });
21273
+ staged = joinPath(directory2, "data");
21274
+ directoryStat = snapshot(await operation2.run(() => fs.lstat(directory2, { signal })));
21275
+ if (directoryStat.type !== "directory" || !identified(directoryStat)) throw new FsError("EBUSY", { path: directory2 });
21276
+ await operation2.run(async () => {
21277
+ await fs.writeFile(staged, new Uint8Array(), { flag: "wx", mode: 384, signal });
21278
+ stageOwned = true;
21279
+ });
21280
+ stageStat = snapshot(await operation2.run(() => fs.lstat(staged, { signal })));
21281
+ if (stageStat.type !== "file" || stageStat.size !== 0 || !identified(stageStat)) throw new FsError("EBUSY", { path: staged });
21282
+ warned2 = await operation2.run(() => transform((signal2) => fs.readStream(plan.source, { signal: signal2, chunkSize: chunkBytes }), async (output2, signal2) => {
21283
+ await fs.writeStream(staged, output2, { flag: "w", mode: 384, signal: signal2 });
21284
+ }, { ...options2, force: false }, signal, stagingLimit));
21285
+ await operation2.run(() => unchangedSource(active, plan));
21286
+ const target = await operation2.run(() => existing(active, destination2));
20797
21287
  if (plan.destinationStat ? !target || !sameSnapshot(plan.destinationStat, target) : target !== void 0) {
20798
21288
  throw new FsError("EBUSY", { path: destination2, message: "destination changed during compression" });
20799
21289
  }
20800
- if (!sameEntry(stageStat, await context2.fs.lstat(staged, { signal: context2.signal }))) {
21290
+ if (!sameEntry(stageStat, snapshot(await operation2.run(() => fs.lstat(staged, { signal }))))) {
20801
21291
  throw new FsError("EBUSY", { path: staged, message: "staging identity changed" });
20802
21292
  }
20803
- if (plan.destinationStat) {
20804
- await context2.fs.rename(staged, destination2, { signal: context2.signal });
21293
+ await operation2.run(async () => {
21294
+ await fs.rename(staged, destination2, { signal, noReplace: !plan.destinationStat });
20805
21295
  moved = true;
20806
- } else await context2.fs.copyFile(staged, destination2, { exclusive: true, signal: context2.signal });
20807
- context2.signal.throwIfAborted();
21296
+ });
21297
+ operation2.check();
21298
+ try {
21299
+ await retainedCleanup();
21300
+ } catch (error) {
21301
+ cleanupFailed = true;
21302
+ throw error;
21303
+ }
21304
+ operation2.check();
21305
+ if (!options2.keep) {
21306
+ await operation2.run(() => unchangedSource(active, plan));
21307
+ await operation2.run(() => fs.rm(plan.source, { signal }));
21308
+ }
20808
21309
  } catch (error) {
20809
21310
  failed = true;
20810
21311
  failure = error;
20811
21312
  }
20812
21313
  try {
20813
- const signal = AbortSignal.timeout(5e3);
20814
- const currentDirectory = await context2.fs.lstat(directory2, { signal });
20815
- if (directoryStat && !sameEntry(directoryStat, currentDirectory)) {
20816
- throw new FsError("EBUSY", { path: directory2, message: "staging directory identity changed; refusing cleanup" });
20817
- }
20818
- if (stageOwned && !moved) {
20819
- let currentStage;
20820
- try {
20821
- currentStage = await context2.fs.lstat(staged, { signal });
20822
- } catch (error) {
20823
- if (codeOf(error) !== "ENOENT") throw error;
20824
- }
20825
- if (currentStage) {
20826
- if (!stageStat || !sameEntry(stageStat, currentStage)) {
20827
- throw new FsError("EBUSY", { path: staged, message: "staging file identity changed; refusing cleanup" });
20828
- }
20829
- await context2.fs.rm(staged, { signal });
20830
- }
20831
- }
20832
- if ((await context2.fs.readdir(directory2, { signal })).length) {
20833
- throw new FsError("ENOTEMPTY", { path: directory2, message: "unexpected staging entries; refusing recursive cleanup" });
20834
- }
20835
- await context2.fs.rm(directory2, { recursive: true, signal });
21314
+ await operation2.close();
20836
21315
  } catch (error) {
21316
+ if (cleanupFailed && error === failure) throw error;
20837
21317
  if (failed) {
20838
21318
  const aggregate = new AggregateError([failure, error], "compression failed and staging cleanup failed; input retained");
20839
21319
  throw new PublicDiagnostic(aggregate.message, { cause: aggregate });
20840
21320
  }
20841
21321
  throw error;
20842
21322
  }
21323
+ context2.signal.throwIfAborted();
20843
21324
  if (failed) throw failure;
20844
- if (!options2.keep) {
20845
- await unchangedSource(context2, plan);
20846
- await context2.fs.rm(plan.source, { signal: context2.signal });
20847
- }
20848
21325
  return warned2;
20849
21326
  }
20850
21327
 
20851
- // packages/safe-bash/src/commands/bytes/compression/options.ts
20852
- init_platform();
20853
- var aliases = {
20854
- stdout: "c",
20855
- "to-stdout": "c",
20856
- decompress: "d",
20857
- uncompress: "d",
20858
- keep: "k",
20859
- force: "f",
20860
- test: "t",
20861
- fast: "1",
20862
- best: "9",
20863
- "no-name": "n",
20864
- help: "h"
20865
- };
20866
- function parseOptions(command7, args) {
20867
- const result2 = {
20868
- decompress: command7 !== "gzip",
20869
- stdout: command7 === "zcat",
20870
- keep: false,
20871
- force: false,
20872
- test: false,
20873
- help: false,
20874
- level: 6,
20875
- operands: []
20876
- };
20877
- let ended = false;
20878
- for (const argument2 of args) {
20879
- if (ended || argument2 === "-" || !argument2.startsWith("-")) {
20880
- result2.operands.push(argument2);
20881
- continue;
20882
- }
20883
- if (argument2 === "--") {
20884
- ended = true;
20885
- continue;
20886
- }
20887
- const flags3 = argument2.startsWith("--") ? aliases[argument2.slice(2)] : argument2.slice(1);
20888
- if (!flags3) throw new UsageError(`unrecognized option '${argument2}'`);
20889
- for (const flag of flags3) {
20890
- switch (flag) {
20891
- case "c":
20892
- result2.stdout = true;
20893
- break;
20894
- case "d":
20895
- result2.decompress = true;
20896
- break;
20897
- case "k":
20898
- result2.keep = true;
20899
- break;
20900
- case "f":
20901
- result2.force = true;
20902
- break;
20903
- case "t":
20904
- result2.test = true;
20905
- result2.decompress = true;
20906
- break;
20907
- case "h":
20908
- result2.help = true;
20909
- break;
20910
- case "n":
20911
- break;
20912
- default:
20913
- if (/^[1-9]$/u.test(flag)) result2.level = Number(flag);
20914
- else throw new UsageError(`invalid option -- '${flag}'`);
20915
- }
20916
- }
20917
- }
20918
- if (!result2.operands.length) result2.operands.push("-");
20919
- return result2;
20920
- }
20921
-
20922
21328
  // packages/safe-bash/src/commands/bytes/compression/index.ts
20923
21329
  function createCompressionCommands() {
20924
- return ["gzip", "gunzip", "zcat"].map((name2) => define(name2, async (context2) => {
21330
+ return profiles.flatMap((profile2) => profile2.names).map((name2) => define(name2, async (context2) => {
20925
21331
  const options2 = parseOptions(name2, context2.args);
20926
21332
  if (options2.help) {
20927
21333
  await output(context2, `Usage: ${name2} [OPTION]... [FILE]...
@@ -20931,8 +21337,9 @@ function createCompressionCommands() {
20931
21337
  -f, --force
20932
21338
  -t, --test
20933
21339
  -1..-9, --fast, --best
20934
- -n, --no-name (always enabled)
20935
- -h, --help
21340
+ ${options2.format === "gzip" ? "-n, --no-name (always enabled)\n" : `Default compression level: ${options2.level}; 64 MiB codec allocation cap.
21341
+ High presets may exceed the cap and fail explicitly.
21342
+ `}-h, --help
20936
21343
  No FILE or FILE '-' uses stdin; file output uses private VFS staging.
20937
21344
  `);
20938
21345
  return { exitCode: 0 };
@@ -24802,7 +25209,7 @@ function truncateCommand(options2 = {}) {
24802
25209
  const configured = settings(options2);
24803
25210
  const argumentLimit = Math.min(65536, configured.limits.maxArgumentBytes);
24804
25211
  const outputMaximum = Math.min(bufferLimit, configured.limits.maxOutputBytes);
24805
- return { name: "truncate", filesystemRequirements: [{ id: "resize", description: "Resize retained writable VFS entries", capabilities: ["retainedResize"], mutates: true }], async execute(context2) {
25212
+ return { name: "truncate", filesystemRequirements: [{ id: "resize", description: "Resize writable VFS entries through retained handles or atomic operations", capabilities: [], anyOf: [["retainedResize"], ["atomicResize"]], mutates: true }], async execute(context2) {
24806
25213
  context2.signal.throwIfAborted();
24807
25214
  const root = createOutputOperation({ signal: context2.signal, registerCleanup(cleanup) {
24808
25215
  let retirement;
@@ -24962,6 +25369,26 @@ ${error.usage ? "Try 'truncate --help' for more information.\n" : ""}`);
24962
25369
  if (readOnly === true) throw new FsError("EROFS");
24963
25370
  const retainedResize = capabilities.retainedResize;
24964
25371
  signal.throwIfAborted();
25372
+ if (retainedResize !== true && capabilities.atomicResize === true) {
25373
+ signal.throwIfAborted();
25374
+ const resize = filesystem.resizeFile;
25375
+ signal.throwIfAborted();
25376
+ if (typeof resize !== "function") throw new FsError("ENOTSUP");
25377
+ const operation2 = {
25378
+ size: settings17.size ?? reference,
25379
+ modifier: settings17.modifier,
25380
+ ...reference === void 0 ? {} : { referenceSize: reference },
25381
+ ioBlocks: settings17.blocks
25382
+ };
25383
+ await root.acquire((signal2) => Reflect.apply(resize, filesystem, [
25384
+ path,
25385
+ operation2,
25386
+ { create: !settings17.noCreate, mode: 438 & ~configured.umask, signal: signal2 }
25387
+ ]), () => {
25388
+ });
25389
+ signal.throwIfAborted();
25390
+ continue;
25391
+ }
24965
25392
  if (retainedResize !== true) throw new FsError("ENOTSUP");
24966
25393
  const openResizeFile = filesystem.openResizeFile;
24967
25394
  signal.throwIfAborted();
@@ -26597,7 +27024,7 @@ async function writeZipArchive(archive, limits, signal) {
26597
27024
 
26598
27025
  // packages/safe-bash/src/commands/archive/zip/safety.ts
26599
27026
  init_platform();
26600
- import { retainFileSystemCleanup } from "@poe-platform/safe-fs/core";
27027
+ import { retainFileSystemCleanup as retainFileSystemCleanup2 } from "@poe-platform/safe-fs/core";
26601
27028
  var ZipScope = class {
26602
27029
  constructor(original, limits) {
26603
27030
  this.original = original;
@@ -26705,7 +27132,7 @@ async function publishZip(scope, prepared) {
26705
27132
  const owner = directory2 && await scope.stat(directory2.path);
26706
27133
  if (parent !== prepared.parent || !owner || owner.type !== "directory" || !sameIdentity2(owner, directory2.stat)) fail("ZIP temporary ownership changed before mutation");
26707
27134
  };
26708
- const close = retainFileSystemCleanup(fs, async (cleanup) => {
27135
+ const close = retainFileSystemCleanup2(fs, async (cleanup) => {
26709
27136
  if (!directory2 || !hasIdentity(directory2.stat)) return;
26710
27137
  const parent = await cleanup.realpath(prepared.parentName);
26711
27138
  const owner = await cleanup.lstat(directory2.path);
@@ -27210,7 +27637,7 @@ var Answers = class {
27210
27637
 
27211
27638
  // packages/safe-bash/src/commands/archive/unzip/safety.ts
27212
27639
  init_platform();
27213
- import { retainFileSystemCleanup as retainFileSystemCleanup2 } from "@poe-platform/safe-fs/core";
27640
+ import { retainFileSystemCleanup as retainFileSystemCleanup3 } from "@poe-platform/safe-fs/core";
27214
27641
  var Extraction = class {
27215
27642
  constructor(context2, limits) {
27216
27643
  this.context = context2;
@@ -27397,7 +27824,7 @@ var Extraction = class {
27397
27824
  let identity2;
27398
27825
  let created = false;
27399
27826
  let failure;
27400
- const cleanup = retainFileSystemCleanup2(fs, async (view) => {
27827
+ const cleanup = retainFileSystemCleanup3(fs, async (view) => {
27401
27828
  if (!created || !identity2) return;
27402
27829
  try {
27403
27830
  let parent = "/";
@@ -36374,6 +36801,7 @@ function composeAgentCommands(options2, executors) {
36374
36801
  const tsortLimits = options2.tsort?.limits;
36375
36802
  const factorLimits = options2.factor?.limits;
36376
36803
  const getoptLimits = options2.getopt?.limits;
36804
+ const hexdumpLimits = options2.hexdump?.limits;
36377
36805
  const whichLimits = options2.which?.limits;
36378
36806
  const timeoutOptions = options2.timeout;
36379
36807
  const applyPatchLimits = options2.applyPatch?.limits;
@@ -36411,7 +36839,8 @@ function composeAgentCommands(options2, executors) {
36411
36839
  ...createPrCommands({ ...prLimits === void 0 ? {} : { limits: prLimits }, ...prClock === void 0 ? {} : { clock: prClock } }),
36412
36840
  ...createTsortCommands(tsortLimits === void 0 ? {} : { limits: tsortLimits }),
36413
36841
  ...createFactorCommands(factorLimits === void 0 ? {} : { limits: factorLimits }),
36414
- ...createGetoptCommands(getoptLimits === void 0 ? {} : { limits: getoptLimits })
36842
+ ...createGetoptCommands(getoptLimits === void 0 ? {} : { limits: getoptLimits }),
36843
+ ...createHexdumpCommands(hexdumpLimits === void 0 ? {} : { limits: hexdumpLimits })
36415
36844
  );
36416
36845
  return new CommandRegistry(commands).list();
36417
36846
  }
@@ -48969,7 +49398,7 @@ init_platform();
48969
49398
  // packages/safe-js/dist/browser/safe-fs.js
48970
49399
  init_platform();
48971
49400
 
48972
- // packages/safe-js/dist/browser/chunks/chunk-HG5OAL4N.js
49401
+ // packages/safe-js/dist/browser/chunks/chunk-BAO3TSWI.js
48973
49402
  init_platform();
48974
49403
  var platform = Object.freeze({
48975
49404
  errno(_code) {
@@ -50461,7 +50890,8 @@ var deviceCapabilities = Object.freeze({
50461
50890
  atomicRename: false,
50462
50891
  atomicRenameNoReplace: false,
50463
50892
  descriptorWriteStream: true,
50464
- retainedResize: true
50893
+ retainedResize: true,
50894
+ atomicResize: false
50465
50895
  });
50466
50896
  var syntheticStat = Object.freeze({
50467
50897
  type: "directory",
@@ -52794,6 +53224,9 @@ export {
52794
53224
  createGetoptCommand,
52795
53225
  createGetoptCommands,
52796
53226
  createGrepAliasCommands,
53227
+ createHdCommand,
53228
+ createHexdumpCommand,
53229
+ createHexdumpCommands,
52797
53230
  createHtmlToMarkdownCommand,
52798
53231
  createHtmlToMarkdownCommands,
52799
53232
  createMemoryFileSystem2 as createMemoryFileSystem,
@@ -52851,6 +53284,7 @@ export {
52851
53284
  getCommandArguments,
52852
53285
  getoptCommands,
52853
53286
  grepAliasCommands,
53287
+ hexdumpCommands,
52854
53288
  htmlToMarkdownCommands,
52855
53289
  isAbsolutePath3 as isAbsolutePath,
52856
53290
  isErrnoCode,