@poe-platform/safe-bash 0.1.802 → 0.1.803
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.
- package/README.md +4 -2
- package/dist/image-ast/index.browser.js +13 -4
- package/dist/image-ast/index.js +13 -4
- package/dist/safe-bash/chunks/{chunk-KDNSPLII.js → chunk-2LSAMQER.js} +1 -0
- package/dist/safe-bash/chunks/{chunk-NZQXYWA3.js → chunk-5OHX7C2V.js} +0 -1
- package/dist/safe-bash/chunks/{chunk-SHEMU2Z7.js → chunk-B7PIL77G.js} +82 -63
- package/dist/safe-bash/chunks/{chunk-WDLGKIHD.js → chunk-EEEWOYEG.js} +4 -4
- package/dist/safe-bash/chunks/{chunk-GETUOD5D.js → chunk-GDYNCWRV.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-RSTHLAF3.js → chunk-JMMEIDPF.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-44ALJ4QG.js → chunk-PNBBUWSM.js} +71 -55
- package/dist/safe-bash/chunks/{chunk-NQCM3TYR.js → chunk-RYFQ3LZG.js} +73 -44
- package/dist/safe-bash/chunks/chunk-VBTDHOWC.js +55 -0
- package/dist/safe-bash/command-chunks/{chunk-ORYGZYKW.js → chunk-4FEVBOL5.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-VXSLJH7G.js → chunk-6JSIFWYT.js} +26 -6
- package/dist/safe-bash/command-chunks/chunk-A7MU7762.js +200 -0
- package/dist/safe-bash/command-chunks/{chunk-KJIMDLBB.js → chunk-BXCXRYVU.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-F4TEEZTL.js → chunk-CQHP3I66.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-PEF7K3UQ.js → chunk-EARHPPPJ.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-QKFSRZGQ.js → chunk-GFC2NTDG.js} +2 -2
- package/dist/safe-bash/command-chunks/chunk-GIRNFXP3.js +466 -0
- package/dist/safe-bash/command-chunks/{chunk-FPVUD6TH.js → chunk-HDCNKOIX.js} +9 -7
- package/dist/safe-bash/command-chunks/{chunk-MQFIPHIQ.js → chunk-ILX2NOLF.js} +18 -15
- package/dist/safe-bash/command-chunks/{chunk-5E4WAO4O.js → chunk-JD5QNRNO.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-I237SNW5.js → chunk-LFJJQQND.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-W5DNF4JH.js → chunk-LOICUCHG.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-7U7EXOXX.js → chunk-NASVPT6F.js} +2 -1
- package/dist/safe-bash/command-chunks/{chunk-OQKC5ZU2.js → chunk-NKIELG7Y.js} +22 -1
- package/dist/safe-bash/command-chunks/{chunk-WPYIOKE3.js → chunk-PICVQ6B5.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-YOFC45RK.js → chunk-QVOS4YXL.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-VGG2DL5Q.js → chunk-TRR4MYWF.js} +4 -0
- package/dist/safe-bash/command-chunks/{chunk-2JRBIDAD.js → chunk-V4K2JDYU.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-6GWJUQAV.js → chunk-WWIBP2ET.js} +38 -111
- package/dist/safe-bash/command-chunks/chunk-ZDN7MJE6.js +168 -0
- package/dist/safe-bash/commands/bytes/compression/index.js +54 -51
- package/dist/safe-bash/commands/chmod/index.browser.js +14 -0
- package/dist/safe-bash/commands/chmod/index.d.ts +2 -0
- package/dist/safe-bash/commands/chmod/index.js +2 -0
- package/dist/safe-bash/commands/metadata/chmod.d.ts +1 -7
- package/dist/safe-bash/commands/metadata/chmod.js +1 -204
- package/dist/safe-bash/commands/metadata/index.browser.js +1 -5
- package/dist/safe-bash/commands/metadata/internal.d.ts +1 -30
- package/dist/safe-bash/commands/metadata/internal.js +1 -76
- package/dist/safe-bash/commands/metadata/mktemp.d.ts +1 -3
- package/dist/safe-bash/commands/metadata/mktemp.js +1 -202
- package/dist/safe-bash/commands/metadata/stat.d.ts +1 -7
- package/dist/safe-bash/commands/metadata/stat.js +1 -530
- package/dist/safe-bash/commands/mktemp/index.browser.js +13 -0
- package/dist/safe-bash/commands/mktemp/index.d.ts +2 -0
- package/dist/safe-bash/commands/mktemp/index.js +2 -0
- package/dist/safe-bash/commands/node/index.browser.js +2 -2
- package/dist/safe-bash/commands/portable-random.d.ts +1 -1
- package/dist/safe-bash/commands/portable-random.js +1 -12
- package/dist/safe-bash/commands/python/index.browser.js +3 -3
- package/dist/safe-bash/commands/stat/index.browser.js +13 -0
- package/dist/safe-bash/commands/stat/index.d.ts +2 -0
- package/dist/safe-bash/commands/stat/index.js +2 -0
- package/dist/safe-bash/commands/text.js +46 -10
- package/dist/safe-bash/full-core.browser.js +86 -86
- package/dist/safe-bash/jobs.browser.js +2 -2
- package/dist/safe-bash/opt-in/commands/yq/native-work.js +1 -0
- package/dist/safe-bash/optional-host.browser.js +10 -10
- package/dist/safe-bash/plugins/index.browser.js +13 -13
- package/dist/safe-bash/registry-entry.browser.js +16 -16
- package/dist/safe-bash/search.browser.js +14 -14
- package/dist/safe-bash/shell/runtime.d.ts +3 -0
- package/dist/safe-bash/shell/runtime.js +20 -3
- package/dist/safe-bash/shell/types.d.ts +2 -0
- package/dist/safe-bash/shell/worker-limits.js +1 -0
- package/dist/safe-bash/shell-entry.browser.js +12 -12
- package/dist/safe-bash/worker/host.js +1 -1
- package/dist/safe-bash-command-bc/index.js +12 -5
- package/dist/safe-bash-command-bzip2/index.js +4 -3
- package/dist/safe-bash-command-chmod/LICENSE +21 -0
- package/dist/safe-bash-command-chmod/command.d.ts +7 -0
- package/dist/safe-bash-command-chmod/command.js +11 -0
- package/dist/safe-bash-command-chmod/index.d.ts +6 -0
- package/dist/safe-bash-command-chmod/index.js +27 -0
- package/dist/safe-bash-command-exiftool/index.js +5 -5
- package/dist/safe-bash-command-find/find.js +1 -1
- package/dist/safe-bash-command-find/index.js +1 -1
- package/dist/safe-bash-command-fmt/index.js +9 -2
- package/dist/safe-bash-command-gzip/index.js +45 -42
- package/dist/safe-bash-command-imagemagick/index.js +3 -1
- package/dist/safe-bash-command-jq/index.js +1 -1
- package/dist/safe-bash-command-jq/jq.js +1 -1
- package/dist/safe-bash-command-less/index.js +12 -3
- package/dist/safe-bash-command-mktemp/LICENSE +21 -0
- package/dist/safe-bash-command-mktemp/command.d.ts +3 -0
- package/dist/safe-bash-command-mktemp/command.js +9 -0
- package/dist/safe-bash-command-mktemp/index.d.ts +6 -0
- package/dist/safe-bash-command-mktemp/index.js +25 -0
- package/dist/safe-bash-command-od/index.js +6 -2
- package/dist/safe-bash-command-op/index.js +25 -6
- package/dist/safe-bash-command-rg/index.js +1 -1
- package/dist/safe-bash-command-rg/rg-command.js +1 -1
- package/dist/safe-bash-command-sed/index.js +1 -1
- package/dist/safe-bash-command-sed/sed.js +1 -1
- package/dist/safe-bash-command-sips/index.js +13 -5
- package/dist/safe-bash-command-sponge/index.js +10 -3
- package/dist/safe-bash-command-stat/LICENSE +21 -0
- package/dist/safe-bash-command-stat/command.d.ts +7 -0
- package/dist/safe-bash-command-stat/command.js +9 -0
- package/dist/safe-bash-command-stat/index.d.ts +6 -0
- package/dist/safe-bash-command-stat/index.js +25 -0
- package/dist/safe-bash-command-unrtf/index.js +11 -1
- package/dist/safe-bash-command-xxd/index.js +6 -2
- package/dist/safe-bash-command-xz/command.d.ts +1 -1
- package/dist/safe-bash-command-xz/index.js +3 -2
- package/dist/safe-bash-command-yq/index.js +1 -0
- package/dist/safe-bash-command-yq/native-work.js +1 -0
- package/dist/safe-bash-command-yq/query.js +3 -0
- package/dist/safe-bash-compression-engine/bounded-codec.js +3 -3
- package/dist/safe-bash-compression-engine/codec-loader.js +2 -2
- package/dist/safe-bash-compression-engine/files.js +6 -6
- package/dist/safe-bash-compression-engine/index.js +5 -5
- package/dist/safe-bash-compression-engine/operand.js +6 -6
- package/dist/safe-bash-compression-engine/options.js +1 -1
- package/dist/safe-bash-compression-engine/stream.js +5 -5
- package/dist/safe-bash-compression-engine/zstd-decode.js +4 -4
- package/dist/safe-bash-contracts/escaping.js +2 -2
- package/dist/safe-bash-contracts/filesystem-output.js +2 -2
- package/dist/safe-bash-contracts/index.js +2 -2
- package/dist/safe-bash-contracts/io.d.ts +2 -0
- package/dist/safe-bash-contracts/io.js +1 -1
- package/dist/safe-bash-contracts/output.js +2 -2
- package/dist/safe-bash-io-engine/commands/search/requirements.js +1 -1
- package/dist/safe-bash-io-engine/commands/text-programs/shared.js +1 -1
- package/dist/safe-bash-mcp/index.browser.js +11 -1
- package/dist/safe-bash-mcp/index.js +35 -16
- package/dist/safe-bash-metadata-engine/LICENSE +21 -0
- package/dist/safe-bash-metadata-engine/index.d.ts +30 -0
- package/dist/safe-bash-metadata-engine/index.js +82 -0
- package/dist/safe-bash-metadata-engine/random.d.ts +1 -0
- package/dist/safe-bash-metadata-engine/random.js +21 -0
- package/dist/safe-bash-regex-engine/index.js +1 -1
- package/dist/safe-bash-regex-engine/text/regex.js +1 -1
- package/dist/safe-bash-search-engine/ergonomic-regex.js +2 -2
- package/dist/safe-bash-search-engine/glob.js +2 -2
- package/dist/safe-bash-search-engine/grep.js +2 -2
- package/dist/safe-bash-search-engine/matcher.js +2 -2
- package/dist/safe-bash-search-engine/options.d.ts +2 -0
- package/dist/safe-bash-search-engine/options.js +1 -1
- package/dist/safe-bash-search-engine/output.js +1 -1
- package/dist/safe-bash-search-engine/shared.js +2 -2
- package/dist/safe-bash-search-engine/walk.js +3 -3
- package/dist/safe-playwright-cloudflare/browser-snapshot-json.js +2 -2
- package/dist/safe-playwright-cloudflare/browser-snapshot-references.js +1 -1
- package/package.json +31 -5
- package/dist/safe-bash/chunks/chunk-VSAJ4OTM.js +0 -962
- package/dist/safe-bash/chunks/{chunk-BJA5XNP6.js → chunk-A7XEHALN.js} +3 -3
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
init_buffer();
|
|
7
7
|
import { utf8ByteLength, bytesFrom } from "../../safe-bash-byte-engine/index.js";
|
|
8
8
|
import { tryReadMemoryFileViewSync } from "@poe-platform/safe-fs/core";
|
|
9
|
-
import { assertCommandRequirements, collectBytes } from "../../safe-bash-contracts/index.js";
|
|
9
|
+
import { assertCommandRequirements, collectBytes, createCommandArguments, getCommandArguments } from "../../safe-bash-contracts/index.js";
|
|
10
10
|
import { hasYieldCheckpoint } from "../../safe-bash-contracts/yield.js";
|
|
11
11
|
import { chargeRuntimeFileSystemOperation, getRuntimeBackingFileSystem } from "../../safe-bash-contracts/runtime-control.js";
|
|
12
12
|
import { Matcher } from "../../safe-bash-search-engine/matcher.js";
|
|
@@ -1024,12 +1024,33 @@ ${totals.bytes_searched} bytes searched
|
|
|
1024
1024
|
})();
|
|
1025
1025
|
});
|
|
1026
1026
|
}
|
|
1027
|
+
async function executeRgWithConfig(context, executor, options, path) {
|
|
1028
|
+
try {
|
|
1029
|
+
if (parse(context.args).noConfig) return await executeRgSlow(context, executor, options);
|
|
1030
|
+
const maximum = options.maxFileBytes ?? Infinity;
|
|
1031
|
+
const bytes = await collectBytes(requiredFileInput(context, searchRequirements, "file", pathFor(context, path), maximum), { maxBytes: maximum, signal: context.signal });
|
|
1032
|
+
const configArgs = new TextDecoder("utf-8", { fatal: true }).decode(bytes).split("\n").map((line) => line.trim()).filter((line) => line.length > 0 && !line.startsWith("#"));
|
|
1033
|
+
const original = getCommandArguments(context);
|
|
1034
|
+
const argumentsWithConfig = original.slice(0, 0).concat(createCommandArguments(configArgs), original);
|
|
1035
|
+
const configured = Object.create(context, {
|
|
1036
|
+
args: { value: argumentsWithConfig.args },
|
|
1037
|
+
argumentValues: { value: argumentsWithConfig }
|
|
1038
|
+
});
|
|
1039
|
+
return await executeRgSlow(configured, executor, options);
|
|
1040
|
+
} catch (error) {
|
|
1041
|
+
context.signal.throwIfAborted();
|
|
1042
|
+
await diagnostic(context, error);
|
|
1043
|
+
return { exitCode: 2 };
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1027
1046
|
function createRgCommand(executor, options = {}) {
|
|
1028
1047
|
return {
|
|
1029
1048
|
name: "rg",
|
|
1030
1049
|
filesystemRequirements: searchRequirements,
|
|
1031
1050
|
description: "Search virtual files or stdin with recursive filtering and structured results",
|
|
1032
1051
|
execute(context) {
|
|
1052
|
+
const config = context.env.RIPGREP_CONFIG_PATH;
|
|
1053
|
+
if (config) return executeRgWithConfig(context, executor, options, config);
|
|
1033
1054
|
const fastSync = tryExecuteRgFastSync(context, executor, options);
|
|
1034
1055
|
if (fastSync !== void 0) return fastSync;
|
|
1035
1056
|
return executeRgSlow(context, executor, options);
|
|
@@ -28,6 +28,7 @@ var ParsedArguments = class _ParsedArguments {
|
|
|
28
28
|
patterns = [];
|
|
29
29
|
paths = [];
|
|
30
30
|
reset() {
|
|
31
|
+
this.noConfig = false;
|
|
31
32
|
this.help = void 0;
|
|
32
33
|
this.version = void 0;
|
|
33
34
|
this.patternFiles = EMPTY_STRINGS;
|
|
@@ -86,6 +87,7 @@ var ParsedArguments = class _ParsedArguments {
|
|
|
86
87
|
}
|
|
87
88
|
static {
|
|
88
89
|
Object.assign(_ParsedArguments.prototype, {
|
|
90
|
+
noConfig: false,
|
|
89
91
|
patternFiles: EMPTY_STRINGS,
|
|
90
92
|
explicitPatterns: false,
|
|
91
93
|
mode: "lines",
|
|
@@ -434,7 +436,9 @@ function parse(args, target) {
|
|
|
434
436
|
result.requireGit = false;
|
|
435
437
|
break;
|
|
436
438
|
case "no-ignore-global":
|
|
439
|
+
break;
|
|
437
440
|
case "no-config":
|
|
441
|
+
result.noConfig = true;
|
|
438
442
|
break;
|
|
439
443
|
case "a":
|
|
440
444
|
case "text":
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
zstdDecode
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-CQHP3I66.js";
|
|
4
4
|
import {
|
|
5
5
|
gunzipMembers
|
|
6
6
|
} from "./chunk-Z6UEDK5T.js";
|
|
7
7
|
import {
|
|
8
8
|
boundedCodec
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-LOICUCHG.js";
|
|
10
10
|
import {
|
|
11
11
|
CodecReader,
|
|
12
12
|
codec
|
|
@@ -973,74 +973,44 @@ var Pattern = class {
|
|
|
973
973
|
let matchEnd = -1;
|
|
974
974
|
let groupStart = -1;
|
|
975
975
|
let groupEnd = -1;
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
}
|
|
994
|
-
} else if (prefix.length === 0) {
|
|
995
|
-
let searchFrom = from;
|
|
996
|
-
const maxStart = textEnd - minimum;
|
|
997
|
-
while (searchFrom <= maxStart) {
|
|
998
|
-
const c0 = text.codePointAt(searchFrom);
|
|
999
|
-
if (c0 < 128 ? ascii[c0] === 0 : !accepts(String.fromCodePoint(c0))) {
|
|
1000
|
-
searchFrom += c0 > 65535 ? 2 : 1;
|
|
1001
|
-
continue;
|
|
1002
|
-
}
|
|
1003
|
-
const idx = searchFrom;
|
|
1004
|
-
let cursor = idx + (c0 > 65535 ? 2 : 1);
|
|
1005
|
-
let count = 1;
|
|
1006
|
-
while (cursor < textEnd) {
|
|
1007
|
-
const code = text.codePointAt(cursor);
|
|
976
|
+
let searchFrom = from;
|
|
977
|
+
let runStart = -1;
|
|
978
|
+
let runEnd = -1;
|
|
979
|
+
let count = 0;
|
|
980
|
+
while (searchFrom <= textEnd - prefix.length) {
|
|
981
|
+
budget.step();
|
|
982
|
+
const idx = anchoredStart2 ? textStart + prefix.length <= textEnd && text.startsWith(prefix, textStart) ? textStart : -1 : text.indexOf(prefix, searchFrom);
|
|
983
|
+
if (idx < 0 || idx > textEnd - prefix.length) break;
|
|
984
|
+
budget.step(idx - searchFrom);
|
|
985
|
+
const pos = idx + prefix.length;
|
|
986
|
+
if (pos > runEnd) {
|
|
987
|
+
runStart = pos;
|
|
988
|
+
runEnd = pos;
|
|
989
|
+
count = 0;
|
|
990
|
+
while (runEnd < textEnd) {
|
|
991
|
+
budget.step();
|
|
992
|
+
const code = text.codePointAt(runEnd);
|
|
1008
993
|
if (code < 128 ? ascii[code] === 0 : !accepts(String.fromCodePoint(code))) break;
|
|
1009
|
-
|
|
994
|
+
runEnd += code > 65535 ? 2 : 1;
|
|
1010
995
|
count++;
|
|
1011
996
|
}
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
break;
|
|
997
|
+
} else {
|
|
998
|
+
while (runStart < pos) {
|
|
999
|
+
budget.step();
|
|
1000
|
+
runStart += text.codePointAt(runStart) > 65535 ? 2 : 1;
|
|
1001
|
+
count--;
|
|
1018
1002
|
}
|
|
1019
|
-
searchFrom = cursor + ((text.codePointAt(cursor) ?? 0) > 65535 ? 2 : 1);
|
|
1020
1003
|
}
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
let cursor = pos;
|
|
1028
|
-
let count = 0;
|
|
1029
|
-
while (cursor < textEnd) {
|
|
1030
|
-
const code = text.codePointAt(cursor);
|
|
1031
|
-
if (code < 128 ? ascii[code] === 0 : !accepts(String.fromCodePoint(code))) break;
|
|
1032
|
-
cursor += code > 65535 ? 2 : 1;
|
|
1033
|
-
count++;
|
|
1034
|
-
}
|
|
1035
|
-
if (count >= minimum && (!anchoredEnd2 || cursor === textEnd)) {
|
|
1036
|
-
found2 = idx;
|
|
1037
|
-
matchEnd = cursor;
|
|
1038
|
-
groupStart = pos;
|
|
1039
|
-
groupEnd = cursor;
|
|
1040
|
-
break;
|
|
1041
|
-
}
|
|
1042
|
-
searchFrom = idx + 1;
|
|
1004
|
+
if (count >= minimum && (!anchoredEnd2 || runEnd === textEnd)) {
|
|
1005
|
+
found2 = idx;
|
|
1006
|
+
matchEnd = runEnd;
|
|
1007
|
+
groupStart = pos;
|
|
1008
|
+
groupEnd = runEnd;
|
|
1009
|
+
break;
|
|
1043
1010
|
}
|
|
1011
|
+
if (anchoredStart2) break;
|
|
1012
|
+
const next = prefix.length === 0 ? runEnd : idx;
|
|
1013
|
+
searchFrom = next + ((text.codePointAt(next) ?? 0) > 65535 ? 2 : 1);
|
|
1044
1014
|
}
|
|
1045
1015
|
const positionsTried2 = anchoredStart2 ? 1 : found2 >= 0 ? found2 - from + 1 : textEnd - from + 1;
|
|
1046
1016
|
const len2 = found2 >= 0 ? matchEnd - found2 : 0;
|
|
@@ -1168,58 +1138,15 @@ var Pattern = class {
|
|
|
1168
1138
|
return found !== void 0;
|
|
1169
1139
|
}
|
|
1170
1140
|
execSimpleRepeat(text, budget, from) {
|
|
1171
|
-
const
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
if (anchoredStart) {
|
|
1178
|
-
if (text.startsWith(prefix)) {
|
|
1179
|
-
const pos = prefix.length;
|
|
1180
|
-
let cursor = pos;
|
|
1181
|
-
let count = 0;
|
|
1182
|
-
while (cursor < text.length) {
|
|
1183
|
-
const code = text.codePointAt(cursor);
|
|
1184
|
-
if (code < 128 ? ascii[code] === 0 : !accepts(String.fromCodePoint(code))) break;
|
|
1185
|
-
cursor += code > 65535 ? 2 : 1;
|
|
1186
|
-
count++;
|
|
1187
|
-
}
|
|
1188
|
-
if (count >= minimum && (!anchoredEnd || cursor === text.length)) {
|
|
1189
|
-
found = 0;
|
|
1190
|
-
matchEnd = cursor;
|
|
1191
|
-
groupStart = pos;
|
|
1192
|
-
groupEnd = cursor;
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
} else {
|
|
1196
|
-
let searchFrom = from;
|
|
1197
|
-
while (searchFrom <= text.length - prefix.length) {
|
|
1198
|
-
const idx = text.indexOf(prefix, searchFrom);
|
|
1199
|
-
if (idx < 0) break;
|
|
1200
|
-
const pos = idx + prefix.length;
|
|
1201
|
-
let cursor = pos;
|
|
1202
|
-
let count = 0;
|
|
1203
|
-
while (cursor < text.length) {
|
|
1204
|
-
const code = text.codePointAt(cursor);
|
|
1205
|
-
if (code < 128 ? ascii[code] === 0 : !accepts(String.fromCodePoint(code))) break;
|
|
1206
|
-
cursor += code > 65535 ? 2 : 1;
|
|
1207
|
-
count++;
|
|
1208
|
-
}
|
|
1209
|
-
if (count >= minimum && (!anchoredEnd || cursor === text.length)) {
|
|
1210
|
-
found = idx;
|
|
1211
|
-
matchEnd = cursor;
|
|
1212
|
-
groupStart = pos;
|
|
1213
|
-
groupEnd = cursor;
|
|
1214
|
-
break;
|
|
1215
|
-
}
|
|
1216
|
-
searchFrom = idx + ((text.codePointAt(idx) ?? 0) > 65535 ? 2 : 1);
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1141
|
+
const matched = this.findSyncFastInto(text, budget, from, FAST_MATCH_OFFSETS);
|
|
1142
|
+
const found = matched ? FAST_MATCH_OFFSETS[0] : -1;
|
|
1143
|
+
const matchEnd = matched ? FAST_MATCH_OFFSETS[1] : -1;
|
|
1144
|
+
const groupStart = matched ? FAST_MATCH_OFFSETS[2] : -1;
|
|
1145
|
+
const groupEnd = matched ? FAST_MATCH_OFFSETS[3] : -1;
|
|
1146
|
+
const { anchoredStart, captured } = this.simpleRepeatMatch;
|
|
1219
1147
|
const positionsTried = anchoredStart ? 1 : found >= 0 ? found - from + 1 : text.length - from + 1;
|
|
1220
1148
|
const len = found >= 0 ? matchEnd - found : 0;
|
|
1221
1149
|
const stepCount = positionsTried * 2 + (found >= 0 ? this.code.length * 2 + len : 0);
|
|
1222
|
-
budget.step(stepCount);
|
|
1223
1150
|
if (stepCount >= 64) {
|
|
1224
1151
|
const midCheck = budget.checkpointSync ? budget.checkpointSync() : budget.checkpoint();
|
|
1225
1152
|
if (midCheck) {
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import {
|
|
2
|
+
init_buffer
|
|
3
|
+
} from "./chunk-HX3SHTCE.js";
|
|
4
|
+
|
|
5
|
+
// packages/safe-bash-command-mktemp/src/command.ts
|
|
6
|
+
init_buffer();
|
|
7
|
+
import { creationUmask } from "../../safe-bash-contracts/runtime-control.js";
|
|
8
|
+
import { randomInteger } from "../../safe-bash-metadata-engine/random.js";
|
|
9
|
+
import { FsError, validatePath } from "../../safe-bash-contracts/index.js";
|
|
10
|
+
import { codeOf, diagnostic, pathOf, syncCommandEvaluators, UsageError } from "../../safe-bash-io-engine/internal.js";
|
|
11
|
+
import { gnuInformationSync } from "../../safe-bash-io-engine/gnu-information.js";
|
|
12
|
+
import { MetadataBudget, metadataCommand, settings } from "../../safe-bash-metadata-engine/index.js";
|
|
13
|
+
var mktempEncoder = new TextEncoder();
|
|
14
|
+
function parse(args) {
|
|
15
|
+
let directory = false;
|
|
16
|
+
let dryRun = false;
|
|
17
|
+
let quiet = false;
|
|
18
|
+
let useTmpdir = false;
|
|
19
|
+
let deprecatedTmpdir = false;
|
|
20
|
+
let tmpdir;
|
|
21
|
+
let suffix;
|
|
22
|
+
let literal = false;
|
|
23
|
+
const operands = [];
|
|
24
|
+
for (let index = 0; index < args.length; index++) {
|
|
25
|
+
const argument = args[index];
|
|
26
|
+
if (literal || argument === "-" || !argument.startsWith("-")) operands.push(argument);
|
|
27
|
+
else if (argument === "--") literal = true;
|
|
28
|
+
else if (argument === "--directory") directory = true;
|
|
29
|
+
else if (argument === "--dry-run") dryRun = true;
|
|
30
|
+
else if (argument === "--quiet") quiet = true;
|
|
31
|
+
else if (argument === "--tmpdir" || argument.startsWith("--tmpdir=")) {
|
|
32
|
+
useTmpdir = true;
|
|
33
|
+
tmpdir = argument.includes("=") ? argument.slice(argument.indexOf("=") + 1) : "";
|
|
34
|
+
} else if (argument === "--suffix" || argument.startsWith("--suffix=")) {
|
|
35
|
+
suffix = argument.includes("=") ? argument.slice(argument.indexOf("=") + 1) : args[++index];
|
|
36
|
+
if (suffix === void 0) throw new UsageError("--suffix requires an argument");
|
|
37
|
+
} else if (!argument.startsWith("--")) {
|
|
38
|
+
for (let offset = 1; offset < argument.length; offset++) {
|
|
39
|
+
const option = argument[offset];
|
|
40
|
+
if (option === "d") directory = true;
|
|
41
|
+
else if (option === "u") dryRun = true;
|
|
42
|
+
else if (option === "q") quiet = true;
|
|
43
|
+
else if (option === "t") {
|
|
44
|
+
useTmpdir = true;
|
|
45
|
+
deprecatedTmpdir = true;
|
|
46
|
+
} else if (option === "p") {
|
|
47
|
+
tmpdir = argument.slice(offset + 1) || args[++index];
|
|
48
|
+
if (tmpdir === void 0) throw new UsageError("-p requires an argument");
|
|
49
|
+
useTmpdir = true;
|
|
50
|
+
break;
|
|
51
|
+
} else throw new UsageError(`unrecognized option '${argument}'`);
|
|
52
|
+
}
|
|
53
|
+
} else throw new UsageError(`unrecognized option '${argument}'`);
|
|
54
|
+
}
|
|
55
|
+
if (operands.length > 1) throw new UsageError("too many templates");
|
|
56
|
+
const template = operands[0] ?? "tmp.XXXXXXXXXX";
|
|
57
|
+
if (operands.length === 0) useTmpdir = true;
|
|
58
|
+
validatePath(template);
|
|
59
|
+
if (deprecatedTmpdir && template.includes("/")) throw new UsageError("template contains directory separator");
|
|
60
|
+
validatePath(suffix ?? "");
|
|
61
|
+
if (suffix?.includes("/") || suffix !== void 0 && !template.endsWith("X")) throw new UsageError("suffix requires a template ending in X and cannot contain '/'");
|
|
62
|
+
const name = template.slice(template.lastIndexOf("/") + 1);
|
|
63
|
+
if (name.length + (suffix?.length ?? 0) > 255 || mktempEncoder.encode(name).byteLength + mktempEncoder.encode(suffix ?? "").byteLength > 255) throw new FsError("ENAMETOOLONG", { path: template });
|
|
64
|
+
const end = name.lastIndexOf("X") + 1;
|
|
65
|
+
let start = end;
|
|
66
|
+
while (start > 0 && name[start - 1] === "X") start--;
|
|
67
|
+
if (end - start < 3) throw new UsageError("template must contain at least three consecutive X characters in its last component");
|
|
68
|
+
if (useTmpdir && template.startsWith("/")) throw new UsageError("template must be relative with --tmpdir/-p");
|
|
69
|
+
const tail = suffix ?? name.slice(end);
|
|
70
|
+
return { directory, dryRun, quiet, useTmpdir, deprecatedTmpdir, tmpdir, template, prefix: template.slice(0, template.length - name.length + start), count: end - start, tail };
|
|
71
|
+
}
|
|
72
|
+
var alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
73
|
+
function sampleTemplateChars(count) {
|
|
74
|
+
let out = "";
|
|
75
|
+
for (let index = 0; index < count; index++) out += alphabet[randomInteger(alphabet.length)];
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
function evalSyncMktemp(opArgs, env, statTypeSync, writeFileSync, mkdirSync) {
|
|
79
|
+
const gnuInfo = gnuInformationSync("mktemp", opArgs);
|
|
80
|
+
if (gnuInfo !== void 0) return gnuInfo;
|
|
81
|
+
try {
|
|
82
|
+
const parsed = parse(opArgs);
|
|
83
|
+
const parent = parsed.deprecatedTmpdir && env.TMPDIR || parsed.tmpdir || env.TMPDIR || "/tmp";
|
|
84
|
+
validatePath(parent);
|
|
85
|
+
if (!statTypeSync) return void 0;
|
|
86
|
+
if (parsed.useTmpdir && !parsed.dryRun && statTypeSync(parent || ".") !== "directory") return void 0;
|
|
87
|
+
for (let attempt = 0; attempt < 32; attempt++) {
|
|
88
|
+
const random = sampleTemplateChars(parsed.count);
|
|
89
|
+
const generated = `${parsed.prefix}${random}${parsed.tail}`;
|
|
90
|
+
const display = parsed.useTmpdir ? `${parent.replace(/\/+$/u, "")}/${generated}` : generated;
|
|
91
|
+
const st = statTypeSync(display);
|
|
92
|
+
if (st !== "missing") continue;
|
|
93
|
+
if (!parsed.dryRun) {
|
|
94
|
+
if (parsed.directory) {
|
|
95
|
+
if (!mkdirSync || !mkdirSync(display)) return void 0;
|
|
96
|
+
} else {
|
|
97
|
+
if (!writeFileSync || !writeFileSync(display, new Uint8Array(0))) return void 0;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return `${display}
|
|
101
|
+
`;
|
|
102
|
+
}
|
|
103
|
+
return void 0;
|
|
104
|
+
} catch {
|
|
105
|
+
return void 0;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
syncCommandEvaluators.evalSyncMktemp = evalSyncMktemp;
|
|
109
|
+
function createMktempCommand(configuration = {}) {
|
|
110
|
+
const configured = settings(configuration);
|
|
111
|
+
const configuredUmask = configuration.umask === void 0 ? void 0 : configured.umask;
|
|
112
|
+
return metadataCommand("mktemp", async (context) => {
|
|
113
|
+
const budget = new MetadataBudget(context, configured.limits);
|
|
114
|
+
const parsed = parse(context.args);
|
|
115
|
+
const parent = parsed.deprecatedTmpdir && context.env.TMPDIR || parsed.tmpdir || context.env.TMPDIR || "/tmp";
|
|
116
|
+
validatePath(parent);
|
|
117
|
+
try {
|
|
118
|
+
if (!parsed.dryRun) {
|
|
119
|
+
if (context.fs.capabilities.readOnly) throw new FsError("EROFS", { syscall: "mktemp" });
|
|
120
|
+
}
|
|
121
|
+
for (let attempt = 0; attempt < configured.limits.maxAttempts; attempt++) {
|
|
122
|
+
await budget.step();
|
|
123
|
+
const random = sampleTemplateChars(parsed.count);
|
|
124
|
+
const generated = `${parsed.prefix}${random}${parsed.tail}`;
|
|
125
|
+
const display = parsed.useTmpdir ? `${parent.replace(/\/+$/u, "")}/${generated}` : generated;
|
|
126
|
+
const path = pathOf(context, display);
|
|
127
|
+
if (mktempEncoder.encode(display).byteLength + 1 > configured.limits.maxOutputBytes) throw new FsError("EFBIG", { message: "temporary pathname output exceeds limit" });
|
|
128
|
+
if (parsed.dryRun) {
|
|
129
|
+
try {
|
|
130
|
+
await context.fs.lstat(path, { signal: context.signal });
|
|
131
|
+
continue;
|
|
132
|
+
} catch (error) {
|
|
133
|
+
context.signal.throwIfAborted();
|
|
134
|
+
if (codeOf(error) !== "ENOENT") throw error;
|
|
135
|
+
}
|
|
136
|
+
} else {
|
|
137
|
+
const capabilities = await context.fs.capabilitiesFor?.(path, { signal: context.signal }) ?? context.fs.capabilities;
|
|
138
|
+
if (capabilities.readOnly === true) throw new FsError("EROFS", { syscall: "mktemp" });
|
|
139
|
+
if (capabilities.permissions !== true) throw new FsError("ENOTSUP", { syscall: "mktemp", message: "private temporary creation requires declared permission support" });
|
|
140
|
+
try {
|
|
141
|
+
const mask = configuredUmask ?? Reflect.get(context.fs, creationUmask);
|
|
142
|
+
const activeUmask = typeof mask === "number" ? mask : configured.umask;
|
|
143
|
+
const mode = (parsed.directory ? 448 : 384) & ~activeUmask;
|
|
144
|
+
if (parsed.directory) await context.fs.mkdir(path, { mode, recursive: false, signal: context.signal });
|
|
145
|
+
else await context.fs.writeFile(path, new Uint8Array(), { mode, flag: "wx", signal: context.signal });
|
|
146
|
+
} catch (error) {
|
|
147
|
+
context.signal.throwIfAborted();
|
|
148
|
+
if (codeOf(error) !== "EEXIST") throw error;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
await budget.output(`${display}
|
|
153
|
+
`);
|
|
154
|
+
return { exitCode: 0 };
|
|
155
|
+
}
|
|
156
|
+
throw new FsError("EEXIST", { syscall: "mktemp", message: "temporary name collision limit exceeded" });
|
|
157
|
+
} catch (error) {
|
|
158
|
+
context.signal.throwIfAborted();
|
|
159
|
+
if (!parsed.quiet) await diagnostic(context, error);
|
|
160
|
+
return { exitCode: 1 };
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export {
|
|
166
|
+
evalSyncMktemp,
|
|
167
|
+
createMktempCommand
|
|
168
|
+
};
|
|
@@ -23,65 +23,68 @@ export function createCompressionCommands(config = {}) {
|
|
|
23
23
|
if (maxDecodedBytes !== undefined && maxDecodedBytes !== Infinity && (!Number.isSafeInteger(maxDecodedBytes) || maxDecodedBytes < 0)) {
|
|
24
24
|
throw new RangeError("maxDecodedBytes must be a nonnegative safe integer or Infinity");
|
|
25
25
|
}
|
|
26
|
-
const commands = profiles.flatMap(profile => profile.format === "gzip" ? createGzipCommands(config) : profile.format === "bzip2" ? createBzip2Commands(config) : profile.names.map((name) =>
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
let plans;
|
|
33
|
-
let planningFailed = false;
|
|
34
|
-
try {
|
|
35
|
-
if (options.operands.length > 1) {
|
|
36
|
-
plans = [];
|
|
37
|
-
for (const name of options.operands) {
|
|
38
|
-
try {
|
|
39
|
-
plans.push(...await planOperands(context, { ...options, operands: [name] }));
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
context.signal.throwIfAborted();
|
|
43
|
-
if (codeOf(error) === "EROFS")
|
|
44
|
-
throw error;
|
|
45
|
-
planningFailed = true;
|
|
46
|
-
if (options.quiet < 2)
|
|
47
|
-
await diagnostic(context, error);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (plans.length > 1)
|
|
51
|
-
await verifyOperandDestinations(context, plans);
|
|
26
|
+
const commands = profiles.flatMap(profile => profile.format === "gzip" ? createGzipCommands(config) : profile.format === "bzip2" ? createBzip2Commands(config) : profile.names.map((name) => {
|
|
27
|
+
const command = define(name, async (context) => {
|
|
28
|
+
const options = parseOptions(name, context.args);
|
|
29
|
+
if (options.help) {
|
|
30
|
+
await output(context, `Usage: ${name} [OPTION]... [FILE]...\n-c, --stdout, --to-stdout\n-d, --decompress, --uncompress\n-k, --keep\n-f, --force\n-t, --test\n${options.format === "zstd" ? "-1..-9, --best\nHigher levels and --fast[=NUM] are unsupported by the bounded codec.\n" : "-1..-9, --fast, --best\n"}${options.format === "zstd" ? "-q, --quiet (repeat to suppress errors)\n" : ""}${options.format === "gzip" ? "-q, --quiet (suppress warnings)\n-r, --recursive (traverse directories without following symlinks)\n-n, --no-name (always enabled)\n" : `Default compression level: ${options.level}.\n`}-h, --help\nNo FILE or FILE '-' uses stdin; file output uses private VFS staging.\n`);
|
|
31
|
+
return { exitCode: 0 };
|
|
52
32
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
context.signal.throwIfAborted();
|
|
58
|
-
if (options.quiet < 2)
|
|
59
|
-
throw error;
|
|
60
|
-
return { exitCode: 1 };
|
|
61
|
-
}
|
|
62
|
-
const decodedBudget = new DecodedBudget(maxDecodedBytes);
|
|
63
|
-
let exitCode = planningFailed ? 1 : 0;
|
|
64
|
-
for (const plan of plans) {
|
|
33
|
+
let plans;
|
|
34
|
+
let planningFailed = false;
|
|
65
35
|
try {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
36
|
+
if (options.operands.length > 1) {
|
|
37
|
+
plans = [];
|
|
38
|
+
for (const name of options.operands) {
|
|
39
|
+
try {
|
|
40
|
+
plans.push(...await planOperands(context, { ...options, operands: [name] }));
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
context.signal.throwIfAborted();
|
|
44
|
+
if (codeOf(error) === "EROFS")
|
|
45
|
+
throw error;
|
|
46
|
+
planningFailed = true;
|
|
47
|
+
if (options.quiet < 2)
|
|
48
|
+
await diagnostic(context, error);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (plans.length > 1)
|
|
52
|
+
await verifyOperandDestinations(context, plans);
|
|
72
53
|
}
|
|
54
|
+
else
|
|
55
|
+
plans = await planOperands(context, options);
|
|
73
56
|
}
|
|
74
57
|
catch (error) {
|
|
75
58
|
context.signal.throwIfAborted();
|
|
76
59
|
if (options.quiet < 2)
|
|
77
|
-
|
|
78
|
-
exitCode
|
|
79
|
-
if (decodedBudget.exceeded)
|
|
80
|
-
break;
|
|
60
|
+
throw error;
|
|
61
|
+
return { exitCode: 1 };
|
|
81
62
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
63
|
+
const decodedBudget = new DecodedBudget(maxDecodedBytes);
|
|
64
|
+
let exitCode = planningFailed ? 1 : 0;
|
|
65
|
+
for (const plan of plans) {
|
|
66
|
+
try {
|
|
67
|
+
const warned = await runOperand(context, plan, options, decodedBudget);
|
|
68
|
+
if (warned) {
|
|
69
|
+
if (!options.quiet)
|
|
70
|
+
await diagnostic(context, new PublicDiagnostic(`${plan.source}: decompression OK, trailing garbage ignored`));
|
|
71
|
+
if (exitCode === 0)
|
|
72
|
+
exitCode = 2;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
context.signal.throwIfAborted();
|
|
77
|
+
if (options.quiet < 2)
|
|
78
|
+
await diagnostic(context, error);
|
|
79
|
+
exitCode = 1;
|
|
80
|
+
if (decodedBudget.exceeded)
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return { exitCode };
|
|
85
|
+
});
|
|
86
|
+
return { ...command, execute: withInputByteBudget(async (context) => command.execute(context)) };
|
|
87
|
+
}));
|
|
85
88
|
const xzCmds = createXzCommands(config);
|
|
86
89
|
if (maxDecodedBytes === undefined || maxDecodedBytes === Infinity) {
|
|
87
90
|
for (const c of [...commands, ...xzCmds])
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
init_platform
|
|
3
|
+
} from "../../chunks/chunk-B7TAL7S5.js";
|
|
4
|
+
|
|
5
|
+
// packages/safe-bash/src/commands/chmod/index.ts
|
|
6
|
+
init_platform();
|
|
7
|
+
import { chmodCommands, createChmodCommand, createChmodCommands, evalSyncChmod, modeChange } from "../../../safe-bash-command-chmod/index.js";
|
|
8
|
+
export {
|
|
9
|
+
chmodCommands,
|
|
10
|
+
createChmodCommand,
|
|
11
|
+
createChmodCommands,
|
|
12
|
+
evalSyncChmod,
|
|
13
|
+
modeChange
|
|
14
|
+
};
|
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
import { type MetadataCommandsOptions } from "./internal.js";
|
|
3
|
-
export declare function createChmodCommand(configuration?: MetadataCommandsOptions): import("../../../safe-bash-contracts/command.js").CommandDefinition;
|
|
4
|
-
export declare function evalSyncChmod(opArgs: readonly string[], umask: number, chmodNodeSync?: (filePath: string, change: (stat: {
|
|
5
|
-
type: "file" | "directory" | "symlink";
|
|
6
|
-
mode: number;
|
|
7
|
-
}) => number) => boolean): string | undefined;
|
|
1
|
+
export * from "../../../safe-bash-command-chmod/command.js";
|
|
8
2
|
//# sourceMappingURL=chmod.d.ts.map
|