@poe-platform/safe-bash 0.1.756 → 0.1.757

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 (113) hide show
  1. package/dist/image-ast/index.browser.js +4 -4
  2. package/dist/image-ast/index.js +4 -4
  3. package/dist/safe-bash/chunks/{chunk-LESPJ3OG.js → chunk-WNWIBBJZ.js} +15 -2
  4. package/dist/safe-bash/command-chunks/{chunk-S4J6MSLY.js → chunk-444OTXM7.js} +3 -3
  5. package/dist/safe-bash/command-chunks/{chunk-6AIOGLZO.js → chunk-CE6Z2ULX.js} +2 -2
  6. package/dist/safe-bash/command-chunks/{chunk-5VSGEE6J.js → chunk-F4IQCXZG.js} +5 -5
  7. package/dist/safe-bash/command-chunks/{chunk-F5MORDSU.js → chunk-FDNCPZQS.js} +32 -1
  8. package/dist/safe-bash/command-chunks/{chunk-SG3ZDZCX.js → chunk-FLMLM7Y4.js} +2 -2
  9. package/dist/safe-bash/command-chunks/{chunk-CT3FB722.js → chunk-J7UMKBRK.js} +1 -1
  10. package/dist/safe-bash/command-chunks/{chunk-QQOAK7JQ.js → chunk-KKJCKPTA.js} +1 -1
  11. package/dist/safe-bash/command-chunks/{chunk-7KS6PX4U.js → chunk-KSIGF4AG.js} +3 -3
  12. package/dist/safe-bash/command-chunks/{chunk-4HQ7WYSI.js → chunk-MED2BOOW.js} +30 -5
  13. package/dist/safe-bash/command-chunks/{chunk-JRNLDPLI.js → chunk-OZSWW23M.js} +1 -1
  14. package/dist/safe-bash/command-chunks/{chunk-DKQ5REXF.js → chunk-QDPRSPHQ.js} +1 -1
  15. package/dist/safe-bash/command-chunks/{chunk-WOPU2VWF.js → chunk-RID3B5RE.js} +1 -1
  16. package/dist/safe-bash/command-chunks/{chunk-DVZCHNB5.js → chunk-S4MLIYSN.js} +7 -7
  17. package/dist/safe-bash/command-chunks/{chunk-REYTQLLB.js → chunk-TT2DMDBY.js} +1 -1
  18. package/dist/safe-bash/command-chunks/{chunk-UGX6MXDD.js → chunk-UIIT4ULR.js} +3 -3
  19. package/dist/safe-bash/command-chunks/{chunk-A6NFLWZI.js → chunk-WKPOGTZY.js} +22 -6
  20. package/dist/safe-bash/command-chunks/{chunk-3DOHQQJR.js → chunk-Y64PA6IA.js} +8 -8
  21. package/dist/safe-bash/command-chunks/{chunk-6Z7OS3TZ.js → chunk-ZP5KDHB4.js} +7 -7
  22. package/dist/safe-bash/commands/pandoc/index.d.ts +1 -1
  23. package/dist/safe-bash/commands/pandoc/index.js +5 -3
  24. package/dist/safe-bash/commands/python/index.browser.js +1 -1
  25. package/dist/safe-bash/commands/python/index.js +6 -0
  26. package/dist/safe-bash/commands/python/jspi.js +11 -2
  27. package/dist/safe-bash/core.browser.js +6 -4
  28. package/dist/safe-bash-command-csvkit/index.js +8 -8
  29. package/dist/safe-bash-command-soffice/index.js +16 -16
  30. package/dist/safe-bash-command-ssconvert/core.js +8 -8
  31. package/dist/safe-bash-command-ssconvert/formats/csv.js +9 -9
  32. package/dist/safe-bash-command-ssconvert/formats/ods.js +8 -8
  33. package/dist/safe-bash-command-ssconvert/formats/spreadsheetml.js +1 -1
  34. package/dist/safe-bash-command-ssconvert/formats/xls.js +9 -8
  35. package/dist/safe-bash-command-ssconvert/formats/xlsx.js +8 -8
  36. package/dist/safe-bash-command-ssconvert/index.js +107 -27
  37. package/dist/safe-bash-contracts/filesystem-descriptor.js +1 -1
  38. package/dist/safe-bash-contracts/filesystem-output.js +1 -1
  39. package/dist/safe-bash-mcp/index.js +4 -4
  40. package/dist/spreadsheet-engine/formulas/ast.d.ts +13 -0
  41. package/dist/spreadsheet-engine/formulas/conventions.js +1 -1
  42. package/dist/spreadsheet-engine/formulas/dependencies.js +2 -2
  43. package/dist/spreadsheet-engine/formulas/evaluator.js +2 -2
  44. package/dist/spreadsheet-engine/formulas/named-expressions.d.ts +2 -2
  45. package/dist/spreadsheet-engine/formulas/named-expressions.js +31 -5
  46. package/dist/spreadsheet-engine/formulas/parser.js +34 -0
  47. package/dist/spreadsheet-engine/formulas/rewriting.js +19 -1
  48. package/dist/spreadsheet-engine/formulas/serialization.js +6 -0
  49. package/dist/spreadsheet-format-xls/biff-write-formulas.js +2 -0
  50. package/dist/xlsx-ast/formula-semantics.js +2 -0
  51. package/package.json +2 -2
  52. package/dist/safe-bash/chunks/browser-ECQX6GMK.js +0 -6766
  53. package/dist/safe-bash/chunks/bz2-4OP3OWW3.js +0 -8
  54. package/dist/safe-bash/chunks/chunk-22XPAAOI.js +0 -173
  55. package/dist/safe-bash/chunks/chunk-44WUNUPV.js +0 -649
  56. package/dist/safe-bash/chunks/chunk-4E3SGG37.js +0 -876
  57. package/dist/safe-bash/chunks/chunk-4QTSSQKP.js +0 -898
  58. package/dist/safe-bash/chunks/chunk-5UVGPVXP.js +0 -410
  59. package/dist/safe-bash/chunks/chunk-64OE6Q6X.js +0 -3487
  60. package/dist/safe-bash/chunks/chunk-6IIFUPN2.js +0 -1526
  61. package/dist/safe-bash/chunks/chunk-BENDLTQD.js +0 -7065
  62. package/dist/safe-bash/chunks/chunk-BMO5LWEX.js +0 -534
  63. package/dist/safe-bash/chunks/chunk-BPMCPTNP.js +0 -1920
  64. package/dist/safe-bash/chunks/chunk-BRJTAWP5.js +0 -2955
  65. package/dist/safe-bash/chunks/chunk-C3GEIN7Q.js +0 -20054
  66. package/dist/safe-bash/chunks/chunk-CBVANNKK.js +0 -174814
  67. package/dist/safe-bash/chunks/chunk-CEWCRI6H.js +0 -2813
  68. package/dist/safe-bash/chunks/chunk-CGL53DQQ.js +0 -37
  69. package/dist/safe-bash/chunks/chunk-CTYJJD4O.js +0 -869
  70. package/dist/safe-bash/chunks/chunk-CWSS4MQA.js +0 -7
  71. package/dist/safe-bash/chunks/chunk-DLIGMTCP.js +0 -3266
  72. package/dist/safe-bash/chunks/chunk-EMAJ7WUW.js +0 -1031
  73. package/dist/safe-bash/chunks/chunk-FDKIZ2IJ.js +0 -1950
  74. package/dist/safe-bash/chunks/chunk-FZWJ2A7V.js +0 -3093
  75. package/dist/safe-bash/chunks/chunk-G2VCIF2J.js +0 -22
  76. package/dist/safe-bash/chunks/chunk-GVKBUQDX.js +0 -2649
  77. package/dist/safe-bash/chunks/chunk-IO2OGW3E.js +0 -28051
  78. package/dist/safe-bash/chunks/chunk-ISCZG7WA.js +0 -2648
  79. package/dist/safe-bash/chunks/chunk-JCN3FXLP.js +0 -38983
  80. package/dist/safe-bash/chunks/chunk-KJHDD4A2.js +0 -759
  81. package/dist/safe-bash/chunks/chunk-LB6HVRXS.js +0 -857
  82. package/dist/safe-bash/chunks/chunk-LLWAJOZH.js +0 -15
  83. package/dist/safe-bash/chunks/chunk-LMUKYZIJ.js +0 -708
  84. package/dist/safe-bash/chunks/chunk-M5SCNKIK.js +0 -2012
  85. package/dist/safe-bash/chunks/chunk-MJPFHANT.js +0 -3350
  86. package/dist/safe-bash/chunks/chunk-MZQW2DOL.js +0 -82
  87. package/dist/safe-bash/chunks/chunk-NB2V7EOY.js +0 -1348
  88. package/dist/safe-bash/chunks/chunk-NJVGOIYN.js +0 -17
  89. package/dist/safe-bash/chunks/chunk-OLNZHDIQ.js +0 -5141
  90. package/dist/safe-bash/chunks/chunk-OSUXMC43.js +0 -2317
  91. package/dist/safe-bash/chunks/chunk-OUUVROTM.js +0 -38
  92. package/dist/safe-bash/chunks/chunk-PA6GYKBQ.js +0 -151
  93. package/dist/safe-bash/chunks/chunk-PEFHZ226.js +0 -6957
  94. package/dist/safe-bash/chunks/chunk-QBB5P5KW.js +0 -4839
  95. package/dist/safe-bash/chunks/chunk-RSAWYAEH.js +0 -973
  96. package/dist/safe-bash/chunks/chunk-UWLYRWT4.js +0 -739
  97. package/dist/safe-bash/chunks/chunk-V463NBQH.js +0 -13
  98. package/dist/safe-bash/chunks/chunk-WPUALYUS.js +0 -843
  99. package/dist/safe-bash/chunks/chunk-XHKFSRGU.js +0 -5747
  100. package/dist/safe-bash/chunks/chunk-XHRCLZ3N.js +0 -13391
  101. package/dist/safe-bash/chunks/chunk-XPF5XHLY.js +0 -15
  102. package/dist/safe-bash/chunks/chunk-ZBFOWARG.js +0 -305
  103. package/dist/safe-bash/chunks/chunk-ZG7GWQ5P.js +0 -1859
  104. package/dist/safe-bash/chunks/model-store-EIY3ZQLZ.js +0 -10
  105. package/dist/safe-bash/chunks/pdf-renderer-CMF3CSVU.js +0 -22
  106. package/dist/safe-bash/chunks/pptx-ZL6L7KP2-O425BFIU.js +0 -30658
  107. package/dist/safe-bash/chunks/src-HHEPGR7U.js +0 -18969
  108. package/dist/safe-bash/chunks/src-MXIKQCIC.js +0 -187
  109. package/dist/safe-bash/chunks/usage-6TGVA2OM.js +0 -35
  110. package/dist/safe-bash/chunks/xz-EGQGQUEI.js +0 -8
  111. package/dist/safe-bash/chunks/xz-K2E2WLM6.js +0 -9
  112. package/dist/safe-bash/chunks/zstd-6JBLP5EF.js +0 -8
  113. package/dist/safe-bash/git_rust-C3QYOAZL.wasm +0 -0
@@ -1,739 +0,0 @@
1
- import {
2
- builtInDirectContextExecutors
3
- } from "./chunk-ISCZG7WA.js";
4
- import {
5
- init_platform
6
- } from "./chunk-ZG7GWQ5P.js";
7
-
8
- // packages/safe-bash/src/commands/tsort/index.ts
9
- init_platform();
10
-
11
- // packages/safe-bash-command-tsort/src/index.ts
12
- init_platform();
13
-
14
- // packages/safe-bash-command-tsort/src/command.ts
15
- init_platform();
16
- import { createOutputOperation } from "../../safe-bash-contracts/output.js";
17
-
18
- // packages/safe-bash-command-tsort/src/internal.ts
19
- init_platform();
20
- import { getCommandArguments } from "../../safe-bash-contracts/index.js";
21
- import { shellValueByteLength, shellValueBytes } from "../../safe-bash-contracts/value.js";
22
- import { hasYieldCheckpoint, monotonicNow, runYieldCheckpoint, yieldTurn } from "../../safe-bash-contracts/yield.js";
23
- import { PublicDiagnostic } from "../../safe-bash-contracts/diagnostics.js";
24
- function settings(options) {
25
- const limits = {
26
- maxArguments: Infinity,
27
- maxArgumentBytes: Infinity,
28
- maxInputBytes: Infinity,
29
- maxTokenBytes: Infinity,
30
- maxTokens: Infinity,
31
- maxNodes: Infinity,
32
- maxEdges: Infinity,
33
- maxBufferedBytes: Infinity,
34
- maxOutputBytes: Infinity,
35
- maxDiagnosticBytes: Infinity,
36
- maxWork: Infinity,
37
- maxEmptyChunks: Infinity,
38
- ...options.limits
39
- };
40
- for (const [name, value] of Object.entries(limits)) {
41
- if (value !== Infinity && (!Number.isSafeInteger(value) || value < 1)) throw new RangeError(`Invalid tsort limit: ${name}`);
42
- }
43
- return Object.freeze(limits);
44
- }
45
- var TsortError = class extends PublicDiagnostic {
46
- constructor(message, usage = false) {
47
- super(message);
48
- this.usage = usage;
49
- }
50
- usage;
51
- };
52
- function raw(value) {
53
- let result = "";
54
- for (let offset = 0; offset < value.length; offset += 4096) result += String.fromCharCode(...value.subarray(offset, offset + 4096));
55
- return result;
56
- }
57
- function bytes(value) {
58
- const len = value.length;
59
- const out = new Uint8Array(len);
60
- for (let i = 0; i < len; i++) out[i] = value.charCodeAt(i);
61
- return out;
62
- }
63
- function pathText(value) {
64
- try {
65
- return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes(value));
66
- } catch {
67
- throw new TsortError("filesystem paths must be valid UTF-8");
68
- }
69
- }
70
- function quote(value) {
71
- const escapes = { "\x07": "\\a", "\b": "\\b", "\f": "\\f", "\n": "\\n", "\r": "\\r", " ": "\\t", "\v": "\\v", "\\": "\\\\", "'": "\\'" };
72
- let result = "'";
73
- for (const character of value) {
74
- const code = character.charCodeAt(0);
75
- result += escapes[character] ?? (code >= 32 && code < 127 ? character : `\\${code.toString(8).padStart(3, "0")}`);
76
- }
77
- return `${result}'`;
78
- }
79
- function fileQuote(value) {
80
- let safe = value.length > 0;
81
- let escaped = false;
82
- for (const character of value) {
83
- const code = character.charCodeAt(0);
84
- if (!(character >= "a" && character <= "z" || character >= "A" && character <= "Z" || character >= "0" && character <= "9" || "_./-".includes(character))) safe = false;
85
- if (code < 32 || code >= 127) escaped = true;
86
- }
87
- if (safe) return value;
88
- if (!escaped) {
89
- if (value.includes("'") && !["$", "`", "\\", '"'].some((character) => value.includes(character))) return `"${value}"`;
90
- return `'${value.split("'").join("'\\''")}'`;
91
- }
92
- const escapes = { "\x07": "\\a", "\b": "\\b", "\f": "\\f", "\n": "\\n", "\r": "\\r", " ": "\\t", "\v": "\\v" };
93
- let result = "'", inEscape = false;
94
- for (const character of value) {
95
- const code = character.charCodeAt(0);
96
- if (code < 32 || code >= 127) {
97
- if (!inEscape) {
98
- result += "'$'";
99
- inEscape = true;
100
- }
101
- result += escapes[character] ?? `\\${code.toString(8).padStart(3, "0")}`;
102
- } else {
103
- if (inEscape) {
104
- result += "''";
105
- inEscape = false;
106
- }
107
- result += character === "'" ? "'\\''" : character;
108
- }
109
- }
110
- return `${result}'`;
111
- }
112
- var Budget = class {
113
- constructor(context, limits, signal) {
114
- this.context = context;
115
- this.limits = limits;
116
- this.signal = signal;
117
- this.signalAborted = signal.aborted;
118
- this.pollSignal = Object.prototype.hasOwnProperty.call(signal, "aborted");
119
- if (!this.signalAborted && !this.pollSignal) {
120
- signal.addEventListener("abort", () => {
121
- this.signalAborted = true;
122
- }, { once: true });
123
- }
124
- }
125
- context;
126
- limits;
127
- signal;
128
- work = 0;
129
- checkpoint = 0;
130
- checkpointCount = 0;
131
- lastYield = monotonicNow();
132
- retained = 0;
133
- input = 0;
134
- output = 0;
135
- diagnostics = 0;
136
- signalAborted;
137
- pollSignal;
138
- assertSignalOpen() {
139
- if (this.pollSignal ? this.signal.aborted : this.signalAborted) this.signal.throwIfAborted();
140
- }
141
- check(value, maximum, label) {
142
- if (value > maximum || value < 0 || (value | 0) !== value && !Number.isSafeInteger(value)) throw new TsortError(`${label} limit exceeded`);
143
- }
144
- charge(amount = 1) {
145
- this.assertSignalOpen();
146
- this.check(this.work + amount, this.limits.maxWork, "work");
147
- this.work += amount;
148
- }
149
- checkpointWork() {
150
- this.assertSignalOpen();
151
- if (this.work - this.checkpoint < 4096) return;
152
- this.checkpoint = this.work;
153
- const count = ++this.checkpointCount;
154
- const now = monotonicNow();
155
- if (count === 1 || now - this.lastYield >= 16 || hasYieldCheckpoint(this.signal)) {
156
- this.lastYield = now;
157
- return yieldTurn(this.signal).then(() => {
158
- this.lastYield = monotonicNow();
159
- });
160
- }
161
- return runYieldCheckpoint(this.signal);
162
- }
163
- retain(amount) {
164
- this.check(this.retained + amount, this.limits.maxBufferedBytes, "buffered bytes");
165
- this.retained += amount;
166
- }
167
- inputBytes(amount) {
168
- this.check(this.input + amount, this.limits.maxInputBytes, "input bytes");
169
- this.input += amount;
170
- }
171
- emitted(amount, diagnostic) {
172
- if (diagnostic) {
173
- this.check(this.diagnostics + amount, this.limits.maxDiagnosticBytes, "diagnostic bytes");
174
- this.diagnostics += amount;
175
- } else {
176
- this.check(this.output + amount, this.limits.maxOutputBytes, "output bytes");
177
- this.output += amount;
178
- this.charge(amount);
179
- }
180
- }
181
- arguments() {
182
- this.check(this.context.args.length, this.limits.maxArguments, "argument count");
183
- let total = 0;
184
- for (const argument of this.context.args) {
185
- total += argument.length;
186
- this.check(total, this.limits.maxArgumentBytes, "argument bytes");
187
- for (let offset = 0; offset < argument.length; offset++) {
188
- const unit = argument.charCodeAt(offset);
189
- if (unit >= 55296 && unit <= 56319) {
190
- const next = argument.charCodeAt(++offset);
191
- if (!(next >= 56320 && next <= 57343)) throw new TsortError("arguments must contain well-formed Unicode");
192
- } else if (unit >= 56320 && unit <= 57343) throw new TsortError("arguments must contain well-formed Unicode");
193
- }
194
- }
195
- total = 0;
196
- const values = this.context.argumentValues === void 0 ? this.context.args : getCommandArguments(this.context).values;
197
- for (const argument of values) {
198
- total += shellValueByteLength(argument);
199
- this.check(total, this.limits.maxArgumentBytes, "argument bytes");
200
- }
201
- this.charge(total);
202
- this.retain(total * 8 + this.context.args.length * 64 + 128);
203
- total = 0;
204
- return getCommandArguments(this.context).values.map((argument) => {
205
- total += shellValueByteLength(argument);
206
- this.check(total, this.limits.maxArgumentBytes, "argument bytes");
207
- this.charge(shellValueByteLength(argument));
208
- const value = shellValueBytes(argument);
209
- if (value.includes(0)) throw new TsortError("NUL is not supported in arguments");
210
- return raw(value);
211
- });
212
- }
213
- };
214
-
215
- // packages/safe-bash-command-tsort/src/io.ts
216
- init_platform();
217
- import { FsError, resolvePath } from "../../safe-bash-contracts/index.js";
218
- var Lifecycle = class {
219
- constructor(budget, output) {
220
- this.budget = budget;
221
- output.registerCleanup(() => this.close());
222
- }
223
- budget;
224
- pending = /* @__PURE__ */ new Set();
225
- cleanups = [];
226
- closing;
227
- pendingStdout = "";
228
- cleanup(action) {
229
- this.assertOpen();
230
- this.cleanups.push(action);
231
- }
232
- assertOpen() {
233
- this.budget.assertSignalOpen();
234
- if (this.closing) throw new TsortError("command is closed");
235
- }
236
- async flush() {
237
- if (!this.pendingStdout.length) return;
238
- const chunk = this.pendingStdout;
239
- this.pendingStdout = "";
240
- try {
241
- await this.operation(async () => {
242
- const sink = this.budget.context.stdout;
243
- this.assertOpen();
244
- const destination = sink.ownedOutput ?? sink;
245
- this.assertOpen();
246
- const write = destination.write;
247
- this.assertOpen();
248
- await Reflect.apply(write, destination, [bytes(chunk)]);
249
- }, true);
250
- } finally {
251
- this.budget.retain(-chunk.length * 3);
252
- }
253
- }
254
- async operation(action, diagnostic = false) {
255
- this.assertOpen();
256
- if (!diagnostic) this.budget.charge();
257
- const pending = Promise.resolve().then(() => {
258
- this.assertOpen();
259
- return action();
260
- });
261
- this.pending.add(pending);
262
- try {
263
- const value = await pending;
264
- this.assertOpen();
265
- return value;
266
- } finally {
267
- this.pending.delete(pending);
268
- }
269
- }
270
- close() {
271
- return this.closing ??= Promise.resolve().then(async () => {
272
- while (this.pending.size) await Promise.allSettled([...this.pending]);
273
- const failures = [];
274
- for (const cleanup of this.cleanups) {
275
- try {
276
- await cleanup();
277
- } catch (error) {
278
- failures.push(error);
279
- }
280
- }
281
- if (failures.length === 1) throw failures[0];
282
- if (failures.length > 1) throw new AggregateError(failures, "tsort cleanup failed");
283
- });
284
- }
285
- write(value, diagnostic = false) {
286
- if (!diagnostic) {
287
- this.budget.emitted(value.length, false);
288
- this.assertOpen();
289
- if (!value.length) return;
290
- this.budget.retain(value.length * 3);
291
- this.pendingStdout += value;
292
- if (Number.isFinite(this.budget.limits.maxBufferedBytes) || this.pendingStdout.length >= 16384) return this.flush();
293
- return;
294
- }
295
- return this.writeDiagnostic(value);
296
- }
297
- async writeDiagnostic(value) {
298
- const diagnostic = true;
299
- if (this.pendingStdout.length) await this.flush();
300
- this.budget.emitted(value.length, true);
301
- await this.operation(async () => {
302
- const sink = this.budget.context.stderr;
303
- this.assertOpen();
304
- const destination = sink.ownedOutput ?? sink;
305
- this.assertOpen();
306
- const write = destination.write;
307
- this.assertOpen();
308
- await Reflect.apply(write, destination, [bytes(value)]);
309
- }, diagnostic);
310
- }
311
- };
312
- var Reader = class {
313
- constructor(name, lifecycle) {
314
- this.name = name;
315
- this.lifecycle = lifecycle;
316
- lifecycle.cleanup(async () => {
317
- try {
318
- if (!this.ended) await this.iterator?.return?.();
319
- } finally {
320
- this.iterator = void 0;
321
- this.releaseSnapshot();
322
- lifecycle.budget.retain(-this.chunk.length);
323
- this.chunk = new Uint8Array();
324
- }
325
- });
326
- }
327
- name;
328
- lifecycle;
329
- iterator;
330
- chunk = new Uint8Array();
331
- offset = 0;
332
- ended = false;
333
- empties = 0;
334
- snapshotBytes = 0;
335
- releaseSnapshot = () => {
336
- this.lifecycle.budget.retain(-this.snapshotBytes);
337
- this.snapshotBytes = 0;
338
- };
339
- async open() {
340
- const { budget } = this.lifecycle;
341
- try {
342
- await this.lifecycle.operation(async () => {
343
- let source;
344
- let needsAcquisitionCleanup = false;
345
- if (this.name === "-") source = budget.context.stdin;
346
- else {
347
- const path = resolvePath(budget.context.cwd, pathText(this.name));
348
- const fs = budget.context.fs;
349
- this.lifecycle.assertOpen();
350
- const statMethod = fs.stat;
351
- this.lifecycle.assertOpen();
352
- const stat = await Reflect.apply(statMethod, fs, [path, { signal: budget.signal }]);
353
- this.lifecycle.assertOpen();
354
- if (stat.type === "directory") {
355
- this.ended = true;
356
- return;
357
- }
358
- if (stat.type !== "file" && stat.type !== "character") throw new FsError("ENOTSUP", { path });
359
- const capabilitiesFor = fs.capabilitiesFor;
360
- this.lifecycle.assertOpen();
361
- const selected = capabilitiesFor ? await Reflect.apply(capabilitiesFor, fs, [path, { signal: budget.signal }]) : void 0;
362
- this.lifecycle.assertOpen();
363
- const capabilities = selected ?? fs.capabilities;
364
- this.lifecycle.assertOpen();
365
- const readStream = fs.readStream;
366
- this.lifecycle.assertOpen();
367
- const streamingRead = readStream && capabilities.streamingRead !== false;
368
- this.lifecycle.assertOpen();
369
- if (readStream && streamingRead) {
370
- source = Reflect.apply(readStream, fs, [path, { signal: budget.signal, chunkSize: 16384 }]);
371
- needsAcquisitionCleanup = budget.signal.aborted;
372
- } else {
373
- const maximum = Math.min(budget.limits.maxInputBytes, Math.floor(budget.limits.maxBufferedBytes / 2));
374
- budget.check(stat.size, maximum, "buffered input bytes");
375
- const reserved = Number.isFinite(maximum) ? maximum : 0;
376
- budget.retain(reserved);
377
- this.snapshotBytes = reserved;
378
- const readFile = fs.readFile;
379
- this.lifecycle.assertOpen();
380
- const content = await Reflect.apply(readFile, fs, [path, { signal: budget.signal, ...Number.isFinite(maximum) ? { maxBytes: maximum } : {} }]);
381
- if (!(content instanceof Uint8Array)) throw new TypeError("tsort input requires bytes");
382
- budget.check(content.length, maximum, "buffered input bytes");
383
- budget.retain(content.length - reserved);
384
- this.snapshotBytes = content.length;
385
- const { releaseSnapshot } = this;
386
- source = { async *[Symbol.asyncIterator]() {
387
- try {
388
- yield content;
389
- } finally {
390
- releaseSnapshot();
391
- }
392
- } };
393
- }
394
- }
395
- if (!needsAcquisitionCleanup) this.lifecycle.assertOpen();
396
- const factory = source[Symbol.asyncIterator];
397
- if (!needsAcquisitionCleanup) this.lifecycle.assertOpen();
398
- this.iterator = Reflect.apply(factory, source, []);
399
- });
400
- } catch (error) {
401
- if (error instanceof FsError) throw new TsortError(`${fileQuote(this.name)}: ${fsDetail(error)}`);
402
- throw error;
403
- }
404
- }
405
- get() {
406
- const { budget } = this.lifecycle;
407
- budget.charge();
408
- const cp = budget.checkpointWork();
409
- if (!cp && this.offset < this.chunk.length) return this.chunk[this.offset++];
410
- return this.getSlow(cp);
411
- }
412
- async getSlow(cp) {
413
- const { budget } = this.lifecycle;
414
- if (cp) await cp;
415
- while (this.offset === this.chunk.length) {
416
- if (this.ended) return -1;
417
- let next;
418
- try {
419
- next = await this.lifecycle.operation(() => {
420
- const iterator = this.iterator;
421
- const advance = iterator.next;
422
- this.lifecycle.assertOpen();
423
- return Reflect.apply(advance, iterator, []);
424
- });
425
- } catch (error) {
426
- if (error instanceof FsError) throw new TsortError(`${fileQuote(this.name)}: ${fsDetail(error)}`);
427
- throw error;
428
- }
429
- budget.retain(-this.chunk.length);
430
- this.chunk = new Uint8Array();
431
- this.offset = 0;
432
- if (next.done) {
433
- this.ended = true;
434
- this.iterator = void 0;
435
- return -1;
436
- }
437
- if (!(next.value instanceof Uint8Array)) throw new TypeError("tsort input requires bytes");
438
- budget.inputBytes(next.value.length);
439
- budget.charge(next.value.length);
440
- budget.retain(next.value.length);
441
- this.chunk = Uint8Array.from(next.value);
442
- if (!this.chunk.length) budget.check(++this.empties, budget.limits.maxEmptyChunks, "empty input chunks");
443
- }
444
- return this.chunk[this.offset++];
445
- }
446
- };
447
- function fsDetail(error) {
448
- const details = {
449
- EACCES: "Permission denied",
450
- EPERM: "Operation not permitted",
451
- ENOENT: "No such file or directory",
452
- EISDIR: "Is a directory",
453
- ENOTDIR: "Not a directory",
454
- EIO: "Input/output error",
455
- ELOOP: "Too many levels of symbolic links",
456
- ENAMETOOLONG: "File name too long",
457
- ENOTSUP: "Operation not supported"
458
- };
459
- return details[error.code] ?? error.message;
460
- }
461
-
462
- // packages/safe-bash-command-tsort/src/graph.ts
463
- init_platform();
464
- import { yieldTurn as yieldTurn2 } from "../../safe-bash-contracts/yield.js";
465
- async function sort(reader, lifecycle) {
466
- const { budget } = lifecycle;
467
- const nodes = /* @__PURE__ */ new Map();
468
- let tokens = 0, edges = 0, length = 0, nameLength = 0;
469
- let nul = false;
470
- let token = new Uint8Array();
471
- let predecessor;
472
- const admitToken = () => {
473
- budget.check(++tokens, budget.limits.maxTokens, "tokens");
474
- budget.charge(nameLength + 1);
475
- budget.retain(nameLength * 4);
476
- const name = raw(token.subarray(0, nameLength));
477
- let node = nodes.get(name);
478
- if (!node) {
479
- budget.check(nodes.size + 1, budget.limits.maxNodes, "nodes");
480
- budget.retain(160);
481
- node = { name, count: 0, printed: false, top: void 0, link: void 0 };
482
- nodes.set(name, node);
483
- } else budget.retain(-nameLength * 4);
484
- if (!predecessor) predecessor = node;
485
- else {
486
- if (predecessor !== node) {
487
- budget.check(++edges, budget.limits.maxEdges, "edges");
488
- budget.retain(48);
489
- predecessor.top = { target: node, next: predecessor.top };
490
- node.count++;
491
- }
492
- predecessor = void 0;
493
- }
494
- length = 0;
495
- nameLength = 0;
496
- nul = false;
497
- };
498
- for (; ; ) {
499
- const r = reader.get();
500
- const value = typeof r === "number" ? r : await r;
501
- if (value < 0 || value === 32 || value === 9 || value === 10) {
502
- if (length) admitToken();
503
- if (value < 0) break;
504
- } else {
505
- budget.check(++length, budget.limits.maxTokenBytes, "token bytes");
506
- if (value === 0) nul = true;
507
- if (!nul) {
508
- if (nameLength === token.length) {
509
- const capacity = Math.min(budget.limits.maxTokenBytes, Math.max(64, token.length * 2));
510
- budget.retain(capacity);
511
- budget.charge(token.length);
512
- const grown = new Uint8Array(capacity);
513
- grown.set(token);
514
- budget.retain(-token.length);
515
- token = grown;
516
- }
517
- token[nameLength++] = value;
518
- }
519
- }
520
- }
521
- budget.retain(-token.length);
522
- token = new Uint8Array();
523
- if (predecessor) throw new TsortError(`${fileQuote(reader.name)}: input contains an odd number of tokens`);
524
- await yieldTurn2(budget.signal);
525
- budget.retain(nodes.size * 16);
526
- let ordered = [...nodes.values()];
527
- let scratch = new Array(ordered.length);
528
- for (let width = 1; width < ordered.length; width *= 2) {
529
- for (let start = 0; start < ordered.length; start += width * 2) {
530
- const middle = Math.min(start + width, ordered.length), end = Math.min(start + width * 2, ordered.length);
531
- let left = start, right = middle;
532
- for (let offset = start; offset < end; offset++) {
533
- budget.charge();
534
- let useLeft = right === end;
535
- if (left < middle && right < end) {
536
- budget.charge(Math.min(ordered[left].name.length, ordered[right].name.length) + 1);
537
- useLeft = ordered[left].name < ordered[right].name;
538
- }
539
- scratch[offset] = left < middle && useLeft ? ordered[left++] : ordered[right++];
540
- {
541
- const cp = budget.checkpointWork();
542
- if (cp) await cp;
543
- }
544
- }
545
- }
546
- [ordered, scratch] = [scratch, ordered];
547
- }
548
- let remaining = ordered.length, status = 0;
549
- while (remaining) {
550
- let head, tail;
551
- for (const node of ordered) {
552
- budget.charge();
553
- if (!node.printed && !node.count) {
554
- if (tail) tail.link = node;
555
- else head = node;
556
- tail = node;
557
- node.link = void 0;
558
- }
559
- {
560
- const cp = budget.checkpointWork();
561
- if (cp) await cp;
562
- }
563
- }
564
- while (head) {
565
- const node = head;
566
- budget.check(node.name.length + 1, budget.limits.maxOutputBytes, "output bytes");
567
- {
568
- const w = lifecycle.write(`${node.name}
569
- `);
570
- if (w) await w;
571
- }
572
- node.printed = true;
573
- remaining--;
574
- for (let edge = node.top; edge; edge = edge.next) {
575
- budget.charge();
576
- if (!--edge.target.count) {
577
- tail.link = edge.target;
578
- tail = edge.target;
579
- tail.link = void 0;
580
- }
581
- {
582
- const cp = budget.checkpointWork();
583
- if (cp) await cp;
584
- }
585
- }
586
- head = node.link;
587
- node.link = void 0;
588
- }
589
- if (!remaining) break;
590
- status = 1;
591
- await lifecycle.write(`tsort: ${fileQuote(reader.name)}: input contains a loop:
592
- `, true);
593
- let loop;
594
- do {
595
- let found = false;
596
- for (const node of ordered) {
597
- budget.charge();
598
- {
599
- const cp = budget.checkpointWork();
600
- if (cp) await cp;
601
- }
602
- if (!node.count) continue;
603
- if (!loop) {
604
- loop = node;
605
- continue;
606
- }
607
- let previous;
608
- for (let edge = node.top; edge; edge = edge.next) {
609
- budget.charge();
610
- {
611
- const cp = budget.checkpointWork();
612
- if (cp) await cp;
613
- }
614
- if (edge.target === loop) {
615
- if (node.link) {
616
- while (loop) {
617
- budget.charge();
618
- const next = loop.link;
619
- await lifecycle.write(`tsort: ${loop.name}
620
- `, true);
621
- if (loop === node) {
622
- edge.target.count--;
623
- if (previous) previous.next = edge.next;
624
- else node.top = edge.next;
625
- break;
626
- }
627
- loop.link = void 0;
628
- loop = next;
629
- }
630
- while (loop) {
631
- budget.charge();
632
- const next = loop.link;
633
- loop.link = void 0;
634
- loop = next;
635
- {
636
- const cp = budget.checkpointWork();
637
- if (cp) await cp;
638
- }
639
- }
640
- found = true;
641
- } else {
642
- node.link = loop;
643
- loop = node;
644
- }
645
- break;
646
- }
647
- previous = edge;
648
- }
649
- if (found) break;
650
- }
651
- } while (loop);
652
- }
653
- await lifecycle.flush();
654
- return status;
655
- }
656
-
657
- // packages/safe-bash-command-tsort/src/command.ts
658
- function createTsortCommand(options = {}) {
659
- const limits = settings(options);
660
- return { name: "tsort", description: "Topologically sort pairs of byte-valued node names", async execute(context) {
661
- const output = createOutputOperation(context, context.stdout);
662
- const budget = new Budget(context, limits, output.signal);
663
- let lifecycle;
664
- let failure;
665
- let primary;
666
- let exitCode = 0;
667
- try {
668
- lifecycle = new Lifecycle(budget, output);
669
- const args = budget.arguments();
670
- const lone = args.length === 1 ? args[0] : "";
671
- if (lone.length > 2 && ("--help".startsWith(lone) || "--version".startsWith(lone))) {
672
- await lifecycle.write("--help".startsWith(lone) ? "Usage: tsort [OPTION] [FILE]\nWrite a topological ordering of whitespace-separated node pairs.\nWith no FILE, or FILE -, read standard input.\nOptions: --help --version\n" : "tsort (virtual-bash)\n");
673
- await lifecycle.flush();
674
- } else {
675
- let optionsEnded = false;
676
- const files = [];
677
- for (const argument of args) {
678
- if (!optionsEnded && argument === "--") {
679
- optionsEnded = true;
680
- continue;
681
- }
682
- if (!optionsEnded && argument.startsWith("--")) throw new TsortError(`unrecognized option '${argument}'`, true);
683
- if (!optionsEnded && argument.length > 1 && argument.startsWith("-")) throw new TsortError(`invalid option -- '${argument[1]}'`, true);
684
- files.push(argument);
685
- if (context.env.POSIXLY_CORRECT !== void 0) optionsEnded = true;
686
- }
687
- if (files.length > 1) throw new TsortError(`extra operand ${quote(files[1])}`, true);
688
- const reader = new Reader(files[0] ?? "-", lifecycle);
689
- await reader.open();
690
- exitCode = await sort(reader, lifecycle);
691
- await lifecycle.flush();
692
- }
693
- } catch (error) {
694
- primary = { reason: error };
695
- if (error instanceof TsortError && !output.signal.aborted && lifecycle) {
696
- exitCode = 1;
697
- try {
698
- await lifecycle.write(`tsort: ${error.message}
699
- ${error.usage ? "Try 'tsort --help' for more information.\n" : ""}`, true);
700
- } catch (reporting) {
701
- failure = { reason: new AggregateError([error, reporting], "tsort failure reporting failed") };
702
- }
703
- } else failure = { reason: error };
704
- }
705
- try {
706
- await output.close();
707
- } catch (cleanup) {
708
- const previous = failure ?? primary;
709
- failure = { reason: previous ? new AggregateError([previous.reason, cleanup], "tsort execution and cleanup failed") : cleanup };
710
- }
711
- context.signal.throwIfAborted();
712
- output.signal.throwIfAborted();
713
- if (failure) throw failure.reason;
714
- return { exitCode };
715
- } };
716
- }
717
-
718
- // packages/safe-bash-command-tsort/src/index.ts
719
- function createTsortCommand2(options = {}) {
720
- const def = createTsortCommand(options);
721
- builtInDirectContextExecutors.add(def.execute);
722
- return def;
723
- }
724
- function createTsortCommands(options = {}) {
725
- return [createTsortCommand2(options)];
726
- }
727
- function tsortCommands(options = {}) {
728
- const commands = createTsortCommands(options);
729
- return { name: "tsort-commands", setup(host) {
730
- for (const command of commands) host.commands.register(command, { replace: options.replace ?? false });
731
- } };
732
- }
733
-
734
- export {
735
- createTsortCommand2 as createTsortCommand,
736
- createTsortCommands,
737
- tsortCommands
738
- };
739
- //# sourceMappingURL=chunk-UWLYRWT4.js.map