@poe-platform/safe-bash 0.1.821 → 0.1.822

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.
@@ -172,6 +172,158 @@ var PythonMultibyteDecoder = class {
172
172
  }
173
173
  };
174
174
 
175
+ // packages/safe-bash-csv-engine/src/python-iso2022.ts
176
+ var pythonIso2022Charsets = {
177
+ iso2022_jp: [194, 74, 192],
178
+ iso2022_jp_1: [194, 196, 74, 192],
179
+ iso2022_jp_2: [194, 196, 195, 193, 74, 192, 65, 70],
180
+ iso2022_jp_2004: [209, 194, 208],
181
+ iso2022_jp_3: [207, 194, 208],
182
+ iso2022_jp_ext: [194, 196, 74, 73, 192],
183
+ iso2022_kr: [195]
184
+ };
185
+ var escapeEnd = (byte) => byte === 64 || byte >= 65 && byte <= 90;
186
+ var PythonIso2022PendingError = class extends Error {
187
+ constructor() {
188
+ super("pending buffer overflow");
189
+ }
190
+ };
191
+ var PythonIso2022Decoder = class {
192
+ constructor(encoding) {
193
+ this.encoding = encoding;
194
+ }
195
+ encoding;
196
+ groups = [66, 66, 66];
197
+ shifted = false;
198
+ through = false;
199
+ pending = [];
200
+ maps = /* @__PURE__ */ new Map();
201
+ invalid() {
202
+ throw new PythonTextDecodeError("Invalid ISO-2022 input");
203
+ }
204
+ character(charset, bytes) {
205
+ const a = bytes[0];
206
+ if (charset === 74) return String.fromCodePoint(a === 92 ? 165 : a === 126 ? 8254 : a);
207
+ if (charset === 73) {
208
+ if (a < 33 || a > 95) return this.invalid();
209
+ return String.fromCodePoint(a + 65344);
210
+ }
211
+ if (charset === 65 || charset === 70) return this.invalid();
212
+ const b = bytes[1];
213
+ if (a < 33 || a > 126 || b < 33 || b > 126) return this.invalid();
214
+ if (charset === 208 && a < 110 && ![33, 35, 36, 37, 40, 44, 45, 46, 47].includes(a)) return this.invalid();
215
+ if ((charset === 207 || charset === 209) && a === 34 && b === 50) return "~";
216
+ const mapping = charset === 193 ? "gb2312" : charset === 195 ? "cp949" : charset === 207 ? "euc_jisx0213" : charset === 209 ? "euc_jis_2004" : charset === 208 ? "euc_jis_2004" : "euc_jp";
217
+ let decoder = this.maps.get(mapping);
218
+ if (!decoder) {
219
+ decoder = new PythonMultibyteDecoder(pythonMultibyteTables[mapping]);
220
+ this.maps.set(mapping, decoder);
221
+ }
222
+ return decoder.decode(Uint8Array.from(charset === 196 || charset === 208 ? [143, a + 128, b + 128] : [a + 128, b + 128]));
223
+ }
224
+ secondary(byte) {
225
+ const group = this.groups[2];
226
+ if (group === 66) {
227
+ if (byte >= 128) return this.invalid();
228
+ return String.fromCharCode(byte);
229
+ }
230
+ if (group === 65) {
231
+ if (byte >= 128) return this.invalid();
232
+ return String.fromCharCode(byte + 128);
233
+ }
234
+ if (group !== 70) throw new Error("Invalid ISO-2022 secondary designation");
235
+ const value = byte ^ 128;
236
+ if (value === 164 || value === 165 || value === 170) return this.invalid();
237
+ const point = pythonFileCodepages["iso8859-7"]?.[value];
238
+ if (point === void 0 || point < 0) return this.invalid();
239
+ return String.fromCodePoint(point);
240
+ }
241
+ escape(bytes) {
242
+ let length = 0;
243
+ for (let i = 1; i < 16; i++) {
244
+ if (i >= bytes.length) return void 0;
245
+ if (escapeEnd(bytes[i])) {
246
+ length = i + 1;
247
+ break;
248
+ }
249
+ if (this.encoding !== "iso2022_kr" && bytes[i] === 38 && bytes[i + 1] === 64) i += 2;
250
+ }
251
+ if (!length) return this.invalid();
252
+ let group, charset;
253
+ if (length === 3) {
254
+ charset = bytes[2];
255
+ if (bytes[1] === 36) {
256
+ charset |= 128;
257
+ group = 0;
258
+ } else if (bytes[1] === 40) group = 0;
259
+ else if (bytes[1] === 41) group = 1;
260
+ else if (bytes[1] === 46 && this.encoding === "iso2022_jp_2") group = 2;
261
+ else return this.invalid();
262
+ } else if (length === 4 && bytes[1] === 36 && (bytes[2] === 40 || bytes[2] === 41)) {
263
+ group = bytes[2] === 40 ? 0 : 1;
264
+ charset = bytes[3] | 128;
265
+ } else if (length === 6 && this.encoding !== "iso2022_kr" && bytes[3] === 27 && bytes[4] === 36 && bytes[5] === 66) {
266
+ group = 0;
267
+ charset = 194;
268
+ } else return this.invalid();
269
+ if (charset !== 66 && !pythonIso2022Charsets[this.encoding].includes(charset)) return this.invalid();
270
+ this.groups[group] = charset;
271
+ return length;
272
+ }
273
+ decode(bytes = new Uint8Array(), options = {}) {
274
+ const previous = this.pending, pending = [...previous];
275
+ let output = "";
276
+ if (bytes.length) this.pending = [];
277
+ for (const byte of bytes) {
278
+ pending.push(byte);
279
+ while (pending.length) {
280
+ const first = pending[0];
281
+ let consumed = 1;
282
+ if (this.through) {
283
+ output += String.fromCharCode(first);
284
+ if (escapeEnd(first)) this.through = false;
285
+ } else if (first === 27) {
286
+ if (pending.length < 2) break;
287
+ if ([40, 41, 36, 46, 38].includes(pending[1])) {
288
+ const length = this.escape(pending);
289
+ if (length === void 0) break;
290
+ consumed = length;
291
+ } else if (this.encoding === "iso2022_jp_2" && pending[1] === 78) {
292
+ if (pending.length < 3) break;
293
+ output += this.secondary(pending[2]);
294
+ consumed = 3;
295
+ } else {
296
+ output += "\x1B";
297
+ this.through = true;
298
+ }
299
+ } else if (this.encoding === "iso2022_kr" && (first === 14 || first === 15)) this.shifted = first === 14;
300
+ else if (first === 10) {
301
+ this.shifted = false;
302
+ output += "\n";
303
+ } else if (first < 32) output += String.fromCharCode(first);
304
+ else if (first >= 128) return this.invalid();
305
+ else {
306
+ const charset = this.groups[this.shifted ? 1 : 0];
307
+ if (charset === 66) output += String.fromCharCode(first);
308
+ else {
309
+ consumed = charset & 128 ? 2 : 1;
310
+ if (pending.length < consumed) break;
311
+ output += this.character(charset, pending);
312
+ }
313
+ }
314
+ pending.splice(0, consumed);
315
+ }
316
+ }
317
+ if (!options.stream && pending.length) {
318
+ this.pending = previous;
319
+ throw new PythonTextDecodeError("Incomplete ISO-2022 input");
320
+ }
321
+ if (pending.length > 8) throw new PythonIso2022PendingError();
322
+ this.pending = pending;
323
+ return output;
324
+ }
325
+ };
326
+
175
327
  // packages/safe-bash-csv-engine/src/python-hz.ts
176
328
  var PythonHzDecoder = class {
177
329
  shifted = false;
@@ -255,15 +407,15 @@ var PythonTextDecoder = class {
255
407
  constructor(encoding) {
256
408
  const name = normalizeEncoding(encoding);
257
409
  const canonical = Object.hasOwn(pythonCodecAliases, name) ? pythonCodecAliases[name] : void 0;
258
- if (canonical === void 0 || !["hz", "utf-8-sig", "utf-8", "utf-16", "utf-16-le", "utf-16-be", "utf-32", "utf-32-le", "utf-32-be"].includes(canonical) && !Object.hasOwn(fileCodepages, canonical) && !Object.hasOwn(pythonMultibyteTables, canonical)) throw new RangeError(`unknown encoding: ${encoding}`);
410
+ if (canonical === void 0 || !["hz", "utf-8-sig", "utf-8", "utf-16", "utf-16-le", "utf-16-be", "utf-32", "utf-32-le", "utf-32-be"].includes(canonical) && !Object.hasOwn(pythonIso2022Charsets, canonical) && !Object.hasOwn(fileCodepages, canonical) && !Object.hasOwn(pythonMultibyteTables, canonical)) throw new RangeError(`unknown encoding: ${encoding}`);
259
411
  this.encoding = canonical;
260
412
  this.codepoints = fileCodepages[canonical];
261
413
  this.signatureComplete = canonical !== "utf-8-sig";
262
- this.decoder = canonical === "hz" ? new PythonHzDecoder() : pythonMultibyteTables[canonical] ? new PythonMultibyteDecoder(pythonMultibyteTables[canonical]) : canonical === "utf-16" || canonical === "utf-16-le" || canonical === "utf-16-be" ? new PythonUtf16Decoder(canonical) : canonical === "utf-32" || canonical === "utf-32-le" || canonical === "utf-32-be" ? new PythonUtf32Decoder(canonical) : new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
414
+ this.decoder = Object.hasOwn(pythonIso2022Charsets, canonical) ? new PythonIso2022Decoder(canonical) : canonical === "hz" ? new PythonHzDecoder() : pythonMultibyteTables[canonical] ? new PythonMultibyteDecoder(pythonMultibyteTables[canonical]) : canonical === "utf-16" || canonical === "utf-16-le" || canonical === "utf-16-be" ? new PythonUtf16Decoder(canonical) : canonical === "utf-32" || canonical === "utf-32-le" || canonical === "utf-32-be" ? new PythonUtf32Decoder(canonical) : new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
263
415
  }
264
416
  decode(bytes, options) {
265
417
  if (this.codepoints) return decodePythonSingleByte(bytes ?? new Uint8Array(), this.codepoints, this.encoding);
266
- if (this.decoder instanceof PythonHzDecoder || this.decoder instanceof PythonUtf16Decoder || this.decoder instanceof PythonUtf32Decoder || this.decoder instanceof PythonMultibyteDecoder) return this.decoder.decode(bytes, options);
418
+ if (this.decoder instanceof PythonIso2022Decoder || this.decoder instanceof PythonHzDecoder || this.decoder instanceof PythonUtf16Decoder || this.decoder instanceof PythonUtf32Decoder || this.decoder instanceof PythonMultibyteDecoder) return this.decoder.decode(bytes, options);
267
419
  try {
268
420
  let offset = 0;
269
421
  if (!this.signatureComplete) {
@@ -290,5 +442,6 @@ var PythonTextDecoder = class {
290
442
  };
291
443
 
292
444
  export {
445
+ PythonIso2022PendingError,
293
446
  PythonTextDecoder
294
447
  };
@@ -110,7 +110,7 @@ var PatchPublication = class {
110
110
  data: new Uint8Array()
111
111
  }, {
112
112
  parent,
113
- retainCleanup: retained,
113
+ ...retained ? { retainCleanup: true } : {},
114
114
  signal: context.signal,
115
115
  ...mode === void 0 ? {} : { mode },
116
116
  ...mtimeMs === void 0 ? {} : { atimeMs: mtimeMs, mtimeMs }
@@ -30,7 +30,7 @@ import {
30
30
  } from "./chunk-AJEQUVDN.js";
31
31
  import {
32
32
  PatchPublication
33
- } from "./chunk-RTUDDAAY.js";
33
+ } from "./chunk-O3KFOFJM.js";
34
34
  import {
35
35
  TargetDocuments,
36
36
  TargetOutput,
@@ -1303,7 +1303,7 @@ async function withEmbeddingFileGlob(options, source, operation) {
1303
1303
 
1304
1304
  // packages/safe-bash-command-llm/src/import-files.ts
1305
1305
  import { FsError as FsError9 } from "../safe-bash-contracts/index.js";
1306
- import { PythonTextDecoder, PythonTextDecodeError } from "../safe-bash-csv-engine/text-decoder.js";
1306
+ import { PythonTextDecoder, PythonTextDecodeError, PythonIso2022PendingError } from "../safe-bash-csv-engine/text-decoder.js";
1307
1307
  async function withFileEmbeddingEntries(options, files, operation) {
1308
1308
  const { fs, directory, signal } = options, maxBytes = options.maxInputBytes ?? Infinity;
1309
1309
  if (maxBytes !== Infinity && (!Number.isSafeInteger(maxBytes) || maxBytes < 0)) throw new RangeError("Invalid embedding input byte limit");
@@ -1347,7 +1347,7 @@ async function withFileEmbeddingEntries(options, files, operation) {
1347
1347
  } catch (error) {
1348
1348
  failedAttempt = true;
1349
1349
  signal.throwIfAborted();
1350
- if (!(error instanceof PythonTextDecodeError)) throw error;
1350
+ if (!(error instanceof PythonTextDecodeError) && !(error instanceof PythonIso2022PendingError)) throw error;
1351
1351
  failedAttempt = false;
1352
1352
  } finally {
1353
1353
  if (!accepted) try {
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  patchCommand
3
- } from "../safe-bash/command-chunks/chunk-SLD5A7IL.js";
3
+ } from "../safe-bash/command-chunks/chunk-OU5UEUZN.js";
4
4
  import "../safe-bash/command-chunks/chunk-6GCK2KSL.js";
5
5
  import "../safe-bash/command-chunks/chunk-2C4QMQQD.js";
6
6
  import "../safe-bash/command-chunks/chunk-OQNX2OOS.js";
7
7
  import "../safe-bash/command-chunks/chunk-5XUWGUGN.js";
8
8
  import "../safe-bash/command-chunks/chunk-AJEQUVDN.js";
9
- import "../safe-bash/command-chunks/chunk-RTUDDAAY.js";
9
+ import "../safe-bash/command-chunks/chunk-O3KFOFJM.js";
10
10
  import "../safe-bash/command-chunks/chunk-KASXIRKD.js";
11
11
  import "../safe-bash/command-chunks/chunk-KHUT7BB5.js";
12
12
  import {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  PatchPublication
3
- } from "../safe-bash/command-chunks/chunk-RTUDDAAY.js";
3
+ } from "../safe-bash/command-chunks/chunk-O3KFOFJM.js";
4
4
  import "../safe-bash/command-chunks/chunk-KASXIRKD.js";
5
5
  import "../safe-bash/command-chunks/chunk-KHUT7BB5.js";
6
6
  import "../safe-bash/command-chunks/chunk-65DS4IOB.js";
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  patchCommand
3
- } from "../safe-bash/command-chunks/chunk-SLD5A7IL.js";
3
+ } from "../safe-bash/command-chunks/chunk-OU5UEUZN.js";
4
4
  import "../safe-bash/command-chunks/chunk-6GCK2KSL.js";
5
5
  import "../safe-bash/command-chunks/chunk-2C4QMQQD.js";
6
6
  import "../safe-bash/command-chunks/chunk-OQNX2OOS.js";
7
7
  import "../safe-bash/command-chunks/chunk-5XUWGUGN.js";
8
8
  import "../safe-bash/command-chunks/chunk-AJEQUVDN.js";
9
- import "../safe-bash/command-chunks/chunk-RTUDDAAY.js";
9
+ import "../safe-bash/command-chunks/chunk-O3KFOFJM.js";
10
10
  import "../safe-bash/command-chunks/chunk-KASXIRKD.js";
11
11
  import "../safe-bash/command-chunks/chunk-KHUT7BB5.js";
12
12
  import "../safe-bash/command-chunks/chunk-65DS4IOB.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  PythonTextDecoder
3
- } from "../safe-bash/command-chunks/chunk-GRFJKJFN.js";
3
+ } from "../safe-bash/command-chunks/chunk-4VHCA4KK.js";
4
4
  import "../safe-bash/command-chunks/chunk-OLXMWQJ5.js";
5
5
  import "../safe-bash/command-chunks/chunk-OOYVZAWL.js";
6
6
  import "../safe-bash/command-chunks/chunk-ZERCTWUI.js";
@@ -0,0 +1,21 @@
1
+ export declare const pythonIso2022Charsets: Readonly<Record<string, readonly number[]>>;
2
+ export declare class PythonIso2022PendingError extends Error {
3
+ constructor();
4
+ }
5
+ /** Bounded ISO-2022 designation and shift state, with existing Python mappings. */
6
+ export declare class PythonIso2022Decoder {
7
+ private readonly encoding;
8
+ private readonly groups;
9
+ private shifted;
10
+ private through;
11
+ private pending;
12
+ private readonly maps;
13
+ constructor(encoding: string);
14
+ private invalid;
15
+ private character;
16
+ private secondary;
17
+ private escape;
18
+ decode(bytes?: Uint8Array, options?: {
19
+ stream?: boolean;
20
+ }): string;
21
+ }
@@ -1,3 +1,4 @@
1
+ export { PythonIso2022PendingError } from "./python-iso2022.js";
1
2
  export { PythonTextDecodeError } from "./python-codepages.js";
2
3
  export declare class PythonTextDecoder {
3
4
  readonly encoding: string;
@@ -1,6 +1,7 @@
1
1
  import {
2
+ PythonIso2022PendingError,
2
3
  PythonTextDecoder
3
- } from "../safe-bash/command-chunks/chunk-GRFJKJFN.js";
4
+ } from "../safe-bash/command-chunks/chunk-4VHCA4KK.js";
4
5
  import "../safe-bash/command-chunks/chunk-OLXMWQJ5.js";
5
6
  import {
6
7
  PythonTextDecodeError
@@ -10,6 +11,7 @@ import "../safe-bash/command-chunks/chunk-WIUEM7HP.js";
10
11
  import "../safe-bash/command-chunks/chunk-HNEWGADJ.js";
11
12
  import "../safe-bash/command-chunks/chunk-65DS4IOB.js";
12
13
  export {
14
+ PythonIso2022PendingError,
13
15
  PythonTextDecodeError,
14
16
  PythonTextDecoder
15
17
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poe-platform/safe-bash",
3
- "version": "0.1.821",
3
+ "version": "0.1.822",
4
4
  "description": "Extensible virtual shell with pluggable filesystems and streaming commands",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1407,7 +1407,7 @@
1407
1407
  "access": "public"
1408
1408
  },
1409
1409
  "dependencies": {
1410
- "@poe-platform/safe-fs": "0.1.821",
1410
+ "@poe-platform/safe-fs": "0.1.822",
1411
1411
  "pdf-lib": "1.17.1",
1412
1412
  "@types/node": "^25.2.2",
1413
1413
  "@formatjs/intl-numberformat": "9.4.0",