@poe-platform/safe-bash 0.1.749 → 0.1.750

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.
@@ -1383,7 +1383,7 @@ function basicCommands() {
1383
1383
  return { exitCode: 0 };
1384
1384
  }),
1385
1385
  define("basename", async (context2) => {
1386
- const parsed = options(context2.args, "as:z", { multiple: "a", suffix: "s", zero: "z" });
1386
+ const parsed = options(context2.args, "as:z", { multiple: "a", suffix: "s", zero: "z" }, true);
1387
1387
  const multiple = parsed.flags.has("a") || parsed.flags.has("s");
1388
1388
  requireOperands(parsed.operands, 1, multiple ? Infinity : 2);
1389
1389
  const suffix2 = value(parsed, "s") ?? (multiple ? void 0 : parsed.operands[1]);
@@ -1395,7 +1395,7 @@ function basicCommands() {
1395
1395
  return { exitCode: 0 };
1396
1396
  }, 1, 1),
1397
1397
  define("dirname", async (context2) => {
1398
- const parsed = options(context2.args, "z", { zero: "z" });
1398
+ const parsed = options(context2.args, "z", { zero: "z" }, true);
1399
1399
  requireOperands(parsed.operands);
1400
1400
  for (const operand of parsed.operands) {
1401
1401
  const parent = dirname(operand);
@@ -56372,7 +56372,6 @@ async function patternAdmission(pattern, context2) {
56372
56372
  }
56373
56373
  } else if (character === "]" && bracket && index > bracketStart + 1) bracket = false;
56374
56374
  }
56375
- if (bracket) unsupported("unclosed bracket pattern");
56376
56375
  }
56377
56376
  async function unary2(operator, value2, context2) {
56378
56377
  if (operator === "-n") return value2.length > 0;
@@ -75631,7 +75630,7 @@ var Runtime = class _Runtime {
75631
75630
  }
75632
75631
  return !rem.associative && rem.references === 1;
75633
75632
  }
75634
- return this.isPureSyncValueWord(e.left, rawState) && (e.operator === "==" || e.operator === "=" || e.operator === "!=" ? this.canSyncPatternWordParts(e.right, rawState) : this.isPureSyncValueWord(e.right, rawState));
75633
+ return this.isPureSyncValueWord(e.left, rawState) && this.isPureSyncValueWord(e.right, rawState) && (!(e.operator === "==" || e.operator === "=" || e.operator === "!=") || e.right.parts.length > 0 && e.right.parts.every((p) => p.quoted));
75635
75634
  }
75636
75635
  if (e.kind === "not") return checkCondNoFile(e.operand);
75637
75636
  if (e.kind === "and" || e.kind === "or") return checkCondNoFile(e.left) && checkCondNoFile(e.right);
@@ -78552,6 +78551,7 @@ var Runtime = class _Runtime {
78552
78551
  positionalSetVersion,
78553
78552
  savedPositionals: resumeSavedPos,
78554
78553
  callerLoopDepth,
78554
+ lastArgument: fnArgs.at(-1) ?? w0Plain,
78555
78555
  listIndex: bodyRes.listIndex,
78556
78556
  pipelineIndex: bodyRes.pipelineIndex
78557
78557
  });
@@ -78606,6 +78606,7 @@ var Runtime = class _Runtime {
78606
78606
  this.setSyncPipeStatusCell(activeExisting, statusStr);
78607
78607
  activeStore.changed(monitor.chargeInternal(syncPipeStatusCharge, syncPipeStatusTickets), "PIPESTATUS");
78608
78608
  }
78609
+ rawState.lastArgument = fnArgs.at(-1) ?? w0Plain;
78609
78610
  rawState.status = exitStatus;
78610
78611
  if (exitStatus !== 0 && !ignored && rawState.errexit) throw new Flow2("exit", exitStatus);
78611
78612
  return exitStatus;
@@ -79070,22 +79071,22 @@ var Runtime = class _Runtime {
79070
79071
  const list = part.script.lists[0];
79071
79072
  if (list.terminator || list.pipelines.length !== 1) return false;
79072
79073
  const p = list.pipelines[0];
79073
- if (p.negate || p.commands.length < 1 || p.commands.length > 5) return false;
79074
+ if (p.negate || p.commands.length !== 1) return false;
79074
79075
  let cmd = p.commands[0];
79075
- const hasSingleStdinRedir = cmd.kind === "simple" && cmd.redirects.length === 1 && cmd.redirects[0].operator === "<" && (cmd.redirects[0].descriptor === void 0 || cmd.redirects[0].descriptor === 0) && !cmd.redirects[0].move && !cmd.redirects[0].document && cmd.redirects[0].target.plain !== void 0 && !cmd.redirects[0].target.plain.startsWith("-") && cmd.redirects[0].target.plain !== "/dev/stdin";
79076
- const hasSingleHereStringRedir = cmd.kind === "simple" && cmd.redirects.length === 1 && cmd.redirects[0].operator === "<<<" && (cmd.redirects[0].descriptor === void 0 || cmd.redirects[0].descriptor === 0) && !cmd.redirects[0].move && !cmd.redirects[0].document && this.isPureSyncValueWord(cmd.redirects[0].target, rawState);
79077
79076
  if (cmd.kind === "for" || cmd.kind === "arithmetic-for" || cmd.kind === "while") return false;
79078
79077
  if (p.commands.length === 1 && (cmd.kind === "if" || cmd.kind === "case") && this.isPureSyncSubIfOrCase(cmd, rawState)) {
79079
79078
  continue;
79080
79079
  }
79081
- if (cmd.kind !== "simple" || cmd.redirects.length > 0 && !hasSingleStdinRedir && !hasSingleHereStringRedir || cmd.words.length === 0) return false;
79080
+ if (cmd.kind !== "simple" || cmd.redirects.length > 0 || cmd.words.length === 0) return false;
79082
79081
  let w0Plain = cmd.words[0].plain;
79083
79082
  if (p.commands.length === 1 && w0Plain !== void 0 && rawState.functions.has(w0Plain) && this.firstInternalDiscovery(w0Plain, rawState, false) === "function" && !rawState.extensions?.builtins.has(w0Plain)) {
79084
79083
  const fnBody = rawState.functions.get(w0Plain);
79085
- if (fnBody.kind === "group" && fnBody.redirects.length === 0 && fnBody.body.lists.length === 1 && !fnBody.body.lists[0].terminator && fnBody.body.lists[0].pipelines.length === 1 && !fnBody.body.lists[0].pipelines[0].negate && fnBody.body.lists[0].pipelines[0].commands.length === 1 && fnBody.body.lists[0].pipelines[0].commands[0].kind === "simple" && fnBody.body.lists[0].pipelines[0].commands[0].redirects.length === 0 && cmd.words.slice(1).every((w) => this.isPureSyncValueWord(w, rawState))) {
79084
+ if (fnBody.kind === "group" && fnBody.redirects.length === 0 && fnBody.body.lists.length === 1 && !fnBody.body.lists[0].terminator && fnBody.body.lists[0].pipelines.length === 1 && !fnBody.body.lists[0].pipelines[0].negate && fnBody.body.lists[0].pipelines[0].commands.length === 1 && fnBody.body.lists[0].pipelines[0].commands[0].kind === "simple" && fnBody.body.lists[0].pipelines[0].commands[0].redirects.length === 0 && cmd.words.slice(1).every((w) => this.isPureSyncValueWord(w, rawState) && w.parts.length > 0 && w.parts.every(
79085
+ (part2) => part2.quoted || part2.kind === "text" && part2.value.length > 0 && !part2.value.includes(" ") && !part2.value.includes(" ") && !part2.value.includes("\n") && !part2.value.includes("{") && !hasGlobOrEscape(part2.value, true)
79086
+ ))) {
79086
79087
  const innerCmd = fnBody.body.lists[0].pipelines[0].commands[0];
79087
79088
  const innerW0 = innerCmd.words[0]?.plain;
79088
- if (innerW0 && !rawState.functions.has(innerW0) && !rawState.extensions?.builtins.has(innerW0)) {
79089
+ if (innerW0 && (innerW0 === "echo" || innerW0 === "printf" || innerW0 === "dirname" || innerW0 === "basename" || innerW0 === "pwd" || innerW0 === "command" || innerW0 === "type" || innerW0 === "seq") && !rawState.functions.has(innerW0) && !rawState.extensions?.builtins.has(innerW0)) {
79089
79090
  cmd = innerCmd;
79090
79091
  w0Plain = innerW0;
79091
79092
  }
@@ -79097,81 +79098,15 @@ var Runtime = class _Runtime {
79097
79098
  return false;
79098
79099
  }
79099
79100
  if (w0Plain === "command" && cmd.words[1]?.plain === "-v" || w0Plain === "type" && cmd.words[1]?.plain === "-t") {
79100
- if (p.commands.length === 1 && cmd.words.length === 3 && !rawState.functions.has(w0Plain) && !rawState.extensions?.builtins.has(w0Plain) && this.isPureSyncValueWord(cmd.words[2], rawState) && (cmd.words[2].plain !== void 0 && this.tryResolveSyncDiscovery(w0Plain === "command" ? "name" : "kind", cmd.words[2].plain, rawState) !== void 0 || this._isMemoryBackingFs && this.backingFs?.capabilities?.permissions !== true)) {
79101
- continue;
79102
- }
79103
79101
  return false;
79104
79102
  }
79105
- const isFileCommand = w0Plain === "cat" || w0Plain === "head" || w0Plain === "tail" || w0Plain === "jq" || w0Plain === "awk" || w0Plain === "grep" || w0Plain === "sed" || w0Plain === "cut" || w0Plain === "wc" || w0Plain === "sort" || w0Plain === "uniq" || w0Plain === "tr" || hasSingleHereStringRedir && (w0Plain === "base64" || w0Plain === "rev" || w0Plain === "tac" || w0Plain === "nl" || w0Plain === "paste" || w0Plain === "numfmt");
79106
- const def = w0Plain ? this.commands.get(w0Plain) ?? (w0Plain === "rev" || w0Plain === "tac" || w0Plain === "nl" || w0Plain === "paste" || w0Plain === "jq" ? this.getExternalCommand(w0Plain) : void 0) : void 0;
79107
- if (!w0Plain || w0Plain !== "printf" && w0Plain !== "echo" && w0Plain !== "dirname" && w0Plain !== "basename" && w0Plain !== "seq" && !isFileCommand || !def || rawState.functions.has(w0Plain) || rawState.extensions?.builtins.has(w0Plain)) return false;
79108
- if ((hasSingleStdinRedir || hasSingleHereStringRedir) && !isFileCommand) return false;
79109
- if (w0Plain === "printf" ? def.execute !== printfCommand.execute : w0Plain === "echo" ? !defaultEchoExecutors.has(def.execute) : w0Plain === "seq" || w0Plain === "rev" || w0Plain === "tac" || w0Plain === "nl" || w0Plain === "paste" || w0Plain === "jq" ? !builtInDirectContextExecutors.has(def.execute) && customRegisteredCommands.has(def.execute) : !builtInDirectContextExecutors.has(def.execute)) return false;
79103
+ const def = w0Plain ? this.commands.get(w0Plain) : void 0;
79104
+ if (!w0Plain || w0Plain !== "printf" && w0Plain !== "echo" && w0Plain !== "dirname" && w0Plain !== "basename" && w0Plain !== "seq" || !def || rawState.functions.has(w0Plain) || rawState.extensions?.builtins.has(w0Plain)) return false;
79105
+ if (w0Plain === "printf" ? def.execute !== printfCommand.execute : w0Plain === "echo" ? !defaultEchoExecutors.has(def.execute) : w0Plain === "seq" ? !builtInDirectContextExecutors.has(def.execute) && customRegisteredCommands.has(def.execute) : !builtInDirectContextExecutors.has(def.execute)) return false;
79110
79106
  if (!cmd.words.slice(1).every((w) => this.isPureSyncValueWord(w, rawState))) return false;
79111
- if (isFileCommand) {
79112
- if (w0Plain === "tr" && !hasSingleStdinRedir && !hasSingleHereStringRedir) return false;
79113
- if (w0Plain === "grep" && rawState.errexit) return false;
79114
- if (!hasSingleHereStringRedir) {
79115
- const fPlain = hasSingleStdinRedir ? cmd.redirects[0].target.plain : cmd.words[cmd.words.length - 1]?.plain;
79116
- if (!fPlain || fPlain.startsWith("-") || fPlain === "/dev/stdin") return false;
79117
- const vCheck = this.tryReadMemoryFileViewSync(resolvePath(rawState.cwd, fPlain), false);
79118
- if (!vCheck || vCheck.byteLength > 16384 || vCheck.includes(0)) return false;
79119
- }
79120
- const opWords = hasSingleStdinRedir || hasSingleHereStringRedir ? cmd.words.slice(1) : cmd.words.slice(1, -1);
79121
- const opCount = opWords.length;
79122
- const op0 = opWords[0]?.plain;
79123
- const op1 = opWords[1]?.plain;
79124
- if (w0Plain === "cat" || w0Plain === "rev" || w0Plain === "tac") {
79125
- if (opCount !== 0) return false;
79126
- } else {
79127
- if (p.commands.length !== 1 && !hasSingleHereStringRedir) return false;
79128
- if (w0Plain === "head" || w0Plain === "tail") {
79129
- const validHT = opCount === 0 || opCount === 1 && op0 !== void 0 && (/^-(?:n|c|--lines=|--bytes=)?[0-9]{1,5}$/.test(op0) || /^--(?:lines|bytes)=[0-9]{1,5}$/.test(op0) || w0Plain === "tail" && /^(?:-n|--lines=)\+[0-9]{1,5}$/.test(op0) || w0Plain === "head" && /^(?:-n|--lines=)-[0-9]{1,5}$/.test(op0)) || opCount === 2 && (op0 === "-n" && op1 !== void 0 && (/^[0-9]{1,5}$/.test(op1) || w0Plain === "tail" && /^\+[0-9]{1,5}$/.test(op1) || w0Plain === "head" && /^-[0-9]{1,5}$/.test(op1)) || op0 === "-c" && op1 !== void 0 && /^[0-9]{1,5}$/.test(op1));
79130
- if (!validHT) return false;
79131
- }
79132
- const plainOps = [];
79133
- for (let oi = 0; oi < opCount; oi++) {
79134
- const ow = opWords[oi];
79135
- const pw = ow.plain ?? (ow.parts.length > 0 && ow.parts.every((pt) => pt.kind === "text") ? ow.parts.map((pt) => pt.value).join("") : void 0);
79136
- if (pw === void 0) break;
79137
- plainOps.push(pw);
79138
- }
79139
- if (w0Plain === "cut") {
79140
- if (plainOps.length !== opCount || this.evalSyncCut(["\xE9"], plainOps, byteLocale(rawState.variables)) === void 0) return false;
79141
- } else if (w0Plain === "sed") {
79142
- if (plainOps.length !== opCount || this.evalSyncSed([], plainOps) === void 0) return false;
79143
- } else if (w0Plain === "grep") {
79144
- if (plainOps.length !== opCount || this.evalSyncGrep([], plainOps, Boolean(rawState.errexit)) === void 0) return false;
79145
- } else if (w0Plain === "awk") {
79146
- const input3 = this.extractLoopInvariantInput(cmd, hasSingleStdinRedir, hasSingleHereStringRedir, rawState);
79147
- if (plainOps.length !== opCount || input3 === void 0) return false;
79148
- const lines3 = input3.length === 0 ? [] : input3.split("\n");
79149
- if (input3.endsWith("\n")) lines3.pop();
79150
- if (this.evalSyncAwk(lines3, plainOps) === void 0) return false;
79151
- } else if (w0Plain === "jq") {
79152
- if (plainOps.length !== opCount) return false;
79153
- const jqIn = this.extractLoopInvariantInput(cmd, hasSingleStdinRedir, hasSingleHereStringRedir, rawState)?.trim();
79154
- if (jqIn === void 0 || this.evalSyncJq(jqIn, plainOps) === void 0) return false;
79155
- } else if (w0Plain === "wc") {
79156
- if (opCount !== 1 || this.normalizeSyncWcFlag(op0) === void 0) return false;
79157
- } else if (w0Plain === "sort") {
79158
- if (plainOps.length !== opCount || this.evalSyncSort([], plainOps, byteLocale(rawState.variables)) === void 0) return false;
79159
- } else if (w0Plain === "uniq") {
79160
- if (plainOps.length !== opCount || this.evalSyncUniq([], plainOps) === void 0) return false;
79161
- } else if (w0Plain === "base64") {
79162
- if (opCount > 1 || opCount === 1 && op0 !== "-d" && op0 !== "--decode") return false;
79163
- } else if (w0Plain === "tr") {
79164
- if (plainOps.length !== opCount || this.evalSyncTr("", plainOps) === void 0) return false;
79165
- } else if (w0Plain === "nl") {
79166
- if (plainOps.length !== opCount || this.evalSyncNl([], plainOps) === void 0) return false;
79167
- } else if (w0Plain === "paste") {
79168
- if (plainOps.length !== opCount || this.evalSyncPaste([], plainOps) === void 0) return false;
79169
- } else if (w0Plain === "numfmt") {
79170
- const nmCheck = this.extractLoopInvariantInput(cmd, hasSingleStdinRedir, hasSingleHereStringRedir, rawState)?.trim();
79171
- if (nmCheck === void 0 || plainOps.length !== opCount || this.evalSyncNumfmt(nmCheck.split("\n"), plainOps) === void 0) return false;
79172
- }
79173
- }
79174
- }
79107
+ if ((w0Plain === "echo" || w0Plain === "basename" || w0Plain === "dirname") && !cmd.words.slice(1).every((w) => w.parts.length > 0 && w.parts.every(
79108
+ (part2) => part2.quoted || part2.kind === "text" && part2.value.length > 0 && !part2.value.includes(" ") && !part2.value.includes(" ") && !part2.value.includes("\n") && !part2.value.includes("{") && !hasGlobOrEscape(part2.value, true)
79109
+ ))) return false;
79175
79110
  if (w0Plain === "printf") {
79176
79111
  if (!this.isSyncPrintfCallOk(cmd, 1, rawState, this._activePrintfInductionName)) return false;
79177
79112
  } else if (w0Plain === "echo") {
@@ -79197,90 +79132,13 @@ var Runtime = class _Runtime {
79197
79132
  }
79198
79133
  if ((w0Plain === "dirname" ? this.evalSyncDirname(simArgs) : this.evalSyncBasename(simArgs)) === void 0) return false;
79199
79134
  } else if (w0Plain === "seq") {
79200
- const isSeqIntWord = (w) => {
79201
- if (w.plain !== void 0) return /^-?[0-9]{1,7}$/.test(w.plain);
79202
- if (w.parts.length === 1) {
79203
- const p02 = w.parts[0];
79204
- if (p02.kind === "arithmetic") return true;
79205
- if (p02.kind === "variable" && !p02.indirect && !p02.prefixNames && !p02.substring && !p02.transform && p02.operator === void 0 && getArraySelector(p02) === void 0) {
79206
- const cur = rawState.variables[p02.name];
79207
- return cur !== void 0 && /^-?[0-9]{1,7}$/.test(cur);
79208
- }
79209
- }
79210
- return false;
79211
- };
79212
- if (cmd.words.length < 2 || cmd.words.length > 4 || !cmd.words.slice(1).every(isSeqIntWord)) return false;
79213
- }
79214
- if (p.commands.length >= 2) {
79215
- if (w0Plain !== "printf" && w0Plain !== "echo" && w0Plain !== "seq" && w0Plain !== "cat" && !hasSingleHereStringRedir || syncPurePipelineSlotInUse || !this.budget.canSyncPurePipe || rawState.errexit || rawState.nounset) return false;
79216
- if (w0Plain === "printf") {
79217
- if (!this.isSyncPrintfCallOk(cmd, 1, rawState, this._activePrintfInductionName)) return false;
79218
- }
79219
- for (let sIdx = 1; sIdx < p.commands.length; sIdx++) {
79220
- const sCmd = p.commands[sIdx];
79221
- if (sCmd.kind !== "simple" || sCmd.redirects.length !== 0 || sCmd.words.length === 0) return false;
79222
- const sName = sCmd.words[0].plain;
79223
- if (!sName || sName !== "cut" && sName !== "tr" && sName !== "sort" && sName !== "head" && sName !== "tail" && sName !== "wc" && sName !== "sed" && sName !== "uniq" && sName !== "rev" && sName !== "awk" && sName !== "grep" && sName !== "jq" && sName !== "base64" && sName !== "tac" && sName !== "nl" && sName !== "paste" && sName !== "numfmt") return false;
79224
- const sDef = this.commands.get(sName) ?? (sName === "rev" || sName === "tac" || sName === "nl" || sName === "paste" || sName === "jq" ? this.getExternalCommand(sName) : void 0);
79225
- if (!sDef || customRegisteredCommands.has(sDef.execute) || sName !== "rev" && sName !== "tac" && sName !== "nl" && sName !== "paste" && sName !== "jq" && !builtInDirectContextExecutors.has(sDef.execute)) return false;
79226
- if (rawState.functions.has(sName) || rawState.extensions?.builtins.has(sName)) return false;
79227
- const sArgWords = sCmd.words.slice(1);
79228
- const sPlainArgs = [];
79229
- let allPlainStageArgs = true;
79230
- for (let k = 0; k < sArgWords.length; k++) {
79231
- const sw = sArgWords[k];
79232
- const sp = sw.plain ?? (sw.parts.length > 0 && sw.parts.every((pt) => pt.kind === "text") ? sw.parts.map((pt) => pt.value).join("") : void 0);
79233
- if (sp === void 0) {
79234
- allPlainStageArgs = false;
79235
- break;
79236
- }
79237
- sPlainArgs.push(sp);
79238
- }
79239
- if (!allPlainStageArgs) return false;
79240
- if (sName === "sort") {
79241
- if (this.evalSyncSort([], sPlainArgs, byteLocale(rawState.variables)) === void 0) return false;
79242
- } else if (sName === "uniq") {
79243
- if (this.evalSyncUniq([], sPlainArgs) === void 0) return false;
79244
- } else if (sName === "wc") {
79245
- if (sPlainArgs.length !== 1 || this.normalizeSyncWcFlag(sPlainArgs[0]) === void 0) return false;
79246
- } else if (sName === "head" || sName === "tail") {
79247
- const okHT = sPlainArgs.length === 0 || sPlainArgs.length === 1 && (/^-(?:n|c)?[0-9]{1,5}$/.test(sPlainArgs[0]) || /^--(?:lines|bytes)=[0-9]{1,5}$/.test(sPlainArgs[0]) || sName === "tail" && /^(?:-n|--lines=)\+[0-9]{1,5}$/.test(sPlainArgs[0]) || sName === "head" && /^(?:-n|--lines=)-[0-9]{1,5}$/.test(sPlainArgs[0])) || sPlainArgs.length === 2 && (sPlainArgs[0] === "-n" && (/^[0-9]{1,5}$/.test(sPlainArgs[1]) || sName === "tail" && /^\+[0-9]{1,5}$/.test(sPlainArgs[1]) || sName === "head" && /^-[0-9]{1,5}$/.test(sPlainArgs[1])) || sPlainArgs[0] === "-c" && /^[0-9]{1,5}$/.test(sPlainArgs[1]));
79248
- if (!okHT) return false;
79249
- } else if (sName === "cut") {
79250
- if (this.evalSyncCut(["\xE9"], sPlainArgs, byteLocale(rawState.variables)) === void 0) return false;
79251
- } else if (sName === "sed") {
79252
- if (this.evalSyncSed([], sPlainArgs) === void 0) return false;
79253
- } else if (sName === "awk") {
79254
- if (sIdx !== 1) return false;
79255
- const input3 = this.extractLoopInvariantInput(cmd, hasSingleStdinRedir, hasSingleHereStringRedir, rawState);
79256
- if (input3 === void 0) return false;
79257
- const lines3 = input3.length === 0 ? [] : input3.split("\n");
79258
- if (input3.endsWith("\n")) lines3.pop();
79259
- if (this.evalSyncAwk(lines3, sPlainArgs) === void 0) return false;
79260
- } else if (sName === "grep") {
79261
- if (this.evalSyncGrep([], sPlainArgs, Boolean(rawState.errexit)) === void 0) return false;
79262
- } else if (sName === "tr") {
79263
- if (this.evalSyncTr("", sPlainArgs) === void 0) return false;
79264
- } else if (sName === "jq") {
79265
- if (sIdx !== 1) return false;
79266
- const jqIn = this.extractLoopInvariantInput(cmd, hasSingleStdinRedir, hasSingleHereStringRedir, rawState)?.trim();
79267
- if (jqIn === void 0 || this.evalSyncJq(jqIn, sPlainArgs) === void 0) return false;
79268
- } else if (sName === "base64") {
79269
- if (sPlainArgs.length !== 0) return false;
79270
- } else if (sName === "tac") {
79271
- if (sPlainArgs.length !== 0 || w0Plain !== "echo" && !hasSingleHereStringRedir) return false;
79272
- } else if (sName === "nl") {
79273
- if (w0Plain !== "echo" && !hasSingleHereStringRedir || this.evalSyncNl([], sPlainArgs) === void 0) return false;
79274
- } else if (sName === "paste") {
79275
- if (this.evalSyncPaste([], sPlainArgs) === void 0) return false;
79276
- } else if (sName === "numfmt") {
79277
- if (sIdx !== 1) return false;
79278
- const nmCheck = this.extractLoopInvariantInput(cmd, hasSingleStdinRedir, hasSingleHereStringRedir, rawState)?.trim();
79279
- if (nmCheck === void 0 || this.evalSyncNumfmt(nmCheck.split("\n"), sPlainArgs) === void 0) return false;
79280
- } else if (sName === "rev") {
79281
- if (sPlainArgs.length !== 0) return false;
79282
- }
79283
- }
79135
+ if (cmd.words.length < 2 || cmd.words.length > 4) return false;
79136
+ const operands = cmd.words.slice(1).map((w) => w.plain);
79137
+ if (!operands.every((value2) => value2 !== void 0 && Number.isInteger(Number(value2)) && String(Number(value2)) === value2 && Math.abs(Number(value2)) <= 9999999)) return false;
79138
+ const first = operands.length === 1 ? 1 : Number(operands[0]);
79139
+ const increment = operands.length === 3 ? Number(operands[1]) : 1;
79140
+ const last = Number(operands[operands.length - 1]);
79141
+ if (increment === 0 || Math.abs((last - first) / increment) > 1024) return false;
79284
79142
  }
79285
79143
  continue;
79286
79144
  }
@@ -79684,7 +79542,7 @@ var Runtime = class _Runtime {
79684
79542
  if (patInfo?.isVar) return false;
79685
79543
  return this.isPureSyncValueWord(e.left, rawState) && this.getFastAnchoredEreRegex(e.right, rawState) !== void 0 && !rawState.readonlyVariables?.has("BASH_REMATCH") && !rawState.exported.has("BASH_REMATCH") && !stateMonitor(rawState)?.hasOverlay("BASH_REMATCH") && !(store ?? requireArrays(rawState))?.watches.has("BASH_REMATCH");
79686
79544
  }
79687
- return this.isPureSyncValueWord(e.left, rawState) && (e.operator === "==" || e.operator === "=" || e.operator === "!=" ? this.canSyncPatternWordParts(e.right, rawState) : this.isPureSyncValueWord(e.right, rawState));
79545
+ return this.isPureSyncValueWord(e.left, rawState) && this.isPureSyncValueWord(e.right, rawState) && (!(e.operator === "==" || e.operator === "=" || e.operator === "!=") || e.right.parts.length > 0 && e.right.parts.every((p2) => p2.quoted));
79688
79546
  }
79689
79547
  if (e.kind === "not") return checkLeaf(e.operand);
79690
79548
  if (e.kind === "and" || e.kind === "or") return checkLeaf(e.left) && checkLeaf(e.right);
@@ -79804,6 +79662,7 @@ var Runtime = class _Runtime {
79804
79662
  if (this.extractPosixBracketCondExpr(cmd, rawState, true, script2) !== void 0) continue;
79805
79663
  if (cmd.kind !== "simple") return false;
79806
79664
  if (nested && cmd.redirects.length !== 0) return false;
79665
+ if (cmd.words.length === 0) return false;
79807
79666
  if (cmd.redirects.length === 1) {
79808
79667
  const r0Check = cmd.redirects[0];
79809
79668
  const w0DevPlain = cmd.words[0].plain;
@@ -80389,21 +80248,12 @@ var Runtime = class _Runtime {
80389
80248
  const forPrintfInd = command7.kind === "for" && command7.words?.length === 1 && /^\{[0-9]{1,4}\.\.[0-9]{1,4}(?:\.\.[1-9][0-9]{0,2})?\}$/.test(command7.words[0].plain ?? "") ? command7.name : void 0;
80390
80249
  const printfInductionName = initializer?.kind === "binary" && initializer.operator === "=" && initializer.left.kind === "name" && initializer.right.kind === "literal" && initializer.right.value >= 0n && initializer.right.value <= 2000n && condition?.kind === "binary" && (condition.operator === "<" || condition.operator === "<=") && condition.left.kind === "name" && condition.left.name === initializer.left.name && condition.right.kind === "literal" && condition.right.value >= 0n && condition.right.value <= 2000n && increment?.kind === "unary" && increment.operator === "++" && increment.operand.kind === "name" && increment.operand.name === initializer.left.name && this.canSyncPrintfInductionBody(command7.body, rawState, initializer.left.name) ? initializer.left.name : whilePrintfInd && this.canSyncPrintfInductionBody(command7.body, rawState, whilePrintfInd) ? whilePrintfInd : forPrintfInd && this.canSyncPrintfInductionBody(command7.body, rawState, forPrintfInd) ? forPrintfInd : void 0;
80391
80250
  const prevActivePrintfInd = this._activePrintfInductionName;
80392
- const prevActiveLoopScript = this._activeLoopBodyScript;
80393
- const prevActiveLoopCond = this._activeLoopCondScript;
80394
- const prevActiveLoopVar = this._activeLoopVarName;
80395
80251
  this._activePrintfInductionName = printfInductionName;
80396
- this._activeLoopBodyScript = command7.body;
80397
- this._activeLoopCondScript = command7.kind === "while" ? command7.condition : void 0;
80398
- this._activeLoopVarName = command7.kind === "for" ? command7.name : printfInductionName ?? (whilePrintfInd || void 0);
80399
80252
  let bodySyncOk = false;
80400
80253
  try {
80401
80254
  bodySyncOk = !(guestArrays(rawState) && (guestArrays(rawState).watches.size > 0 || this.budget.limits.maxExpansionBytes < 65536)) && this.canSyncLoopBody(command7.body, rawState, io, false, printfInductionName);
80402
80255
  } finally {
80403
80256
  this._activePrintfInductionName = prevActivePrintfInd;
80404
- this._activeLoopBodyScript = prevActiveLoopScript;
80405
- this._activeLoopCondScript = prevActiveLoopCond;
80406
- this._activeLoopVarName = prevActiveLoopVar;
80407
80257
  }
80408
80258
  if (!bodySyncOk) {
80409
80259
  command7._skipTrySyncLoop = true;
@@ -80929,7 +80779,7 @@ var Runtime = class _Runtime {
80929
80779
  if (patInfo?.isVar) return false;
80930
80780
  return depth === 0 && this.isPureSyncValueWord(e.left, rawState) && this.getFastAnchoredEreRegex(e.right, rawState) !== void 0 && !rawState.readonlyVariables?.has("BASH_REMATCH") && !rawState.exported.has("BASH_REMATCH") && !monitor.hasOverlay("BASH_REMATCH") && !(store ?? requireArrays(rawState))?.watches.has("BASH_REMATCH");
80931
80781
  }
80932
- return this.isPureSyncValueWord(e.left, rawState) && (e.operator === "==" || e.operator === "=" || e.operator === "!=" ? this.canSyncPatternWordParts(e.right, rawState) : this.isPureSyncValueWord(e.right, rawState));
80782
+ return this.isPureSyncValueWord(e.left, rawState) && this.isPureSyncValueWord(e.right, rawState) && (!(e.operator === "==" || e.operator === "=" || e.operator === "!=") || e.right.parts.length > 0 && e.right.parts.every((p) => p.quoted));
80933
80783
  }
80934
80784
  if (e.kind === "not") return checkWhileCond(e.operand, depth + 1);
80935
80785
  if (e.kind === "and" || e.kind === "or") return checkWhileCond(e.left, depth + 1) && checkWhileCond(e.right, depth + 1);
@@ -81188,7 +81038,7 @@ var Runtime = class _Runtime {
81188
81038
  if (store) store.epoch = restEpoch2;
81189
81039
  return loopStatus2;
81190
81040
  }
81191
- if (!isShellIdentifier(command7.name) || command7.name === "OPTIND" || command7.name.includes("[") || store?.get(command7.name) || command7.words && (command7.words.length === 0 || command7.words.length > 64) || rawState.braceexpand === false) {
81041
+ if (!isShellIdentifier(command7.name) || command7.name === "OPTIND" || controlNames.has(command7.name) || command7.name === "LC_COLLATE" || command7.name.includes("[") || store?.get(command7.name) || command7.words && (command7.words.length === 0 || command7.words.length > 64) || rawState.braceexpand === false) {
81192
81042
  return void 0;
81193
81043
  }
81194
81044
  const activeValScope = io[valueScope];
@@ -81643,149 +81493,6 @@ ${s1}
81643
81493
  return pos <= 128 ? fastRedirectScratchViews[pos] : fastRedirectScratchBytes.subarray(0, pos);
81644
81494
  }
81645
81495
  _activePrintfInductionName = void 0;
81646
- _activeLoopBodyScript = void 0;
81647
- _activeLoopCondScript = void 0;
81648
- _activeLoopVarName = void 0;
81649
- isVarUnmutatedInScript(varName, script2) {
81650
- for (const list of script2.lists) {
81651
- for (const pipeline of list.pipelines) {
81652
- for (const cmd of pipeline.commands) {
81653
- if (cmd.kind === "arithmetic") {
81654
- if (cmd.expression.hasMutation && cmd.expression.source.includes(varName)) return false;
81655
- continue;
81656
- }
81657
- if (cmd.kind === "if") {
81658
- for (const br of cmd.branches) {
81659
- if (!this.isVarUnmutatedInScript(varName, br.condition) || !this.isVarUnmutatedInScript(varName, br.body)) return false;
81660
- }
81661
- if (cmd.otherwise && !this.isVarUnmutatedInScript(varName, cmd.otherwise)) return false;
81662
- continue;
81663
- }
81664
- if (cmd.kind === "case") {
81665
- for (const cl of cmd.clauses) {
81666
- if (!this.isVarUnmutatedInScript(varName, cl.body)) return false;
81667
- }
81668
- continue;
81669
- }
81670
- if (cmd.kind === "for") {
81671
- if (cmd.name === varName || !this.isVarUnmutatedInScript(varName, cmd.body)) return false;
81672
- continue;
81673
- }
81674
- if (cmd.kind === "arithmetic-for") {
81675
- if (cmd.expressions.some((e) => e && e.hasMutation && e.source.includes(varName)) || !this.isVarUnmutatedInScript(varName, cmd.body)) return false;
81676
- continue;
81677
- }
81678
- if (cmd.kind === "while") {
81679
- if (!this.isVarUnmutatedInScript(varName, cmd.condition) || !this.isVarUnmutatedInScript(varName, cmd.body)) return false;
81680
- continue;
81681
- }
81682
- if (cmd.kind === "group" || cmd.kind === "subshell") {
81683
- if (!this.isVarUnmutatedInScript(varName, cmd.body)) return false;
81684
- continue;
81685
- }
81686
- if (cmd.kind !== "simple") return false;
81687
- for (const w of cmd.words) {
81688
- const arrAss = getArrayAssignment(w);
81689
- if (arrAss && arrAss.name === varName) return false;
81690
- const p02 = w.parts[0];
81691
- if (p02?.kind === "text" && !p02.quoted && (p02.value.startsWith(varName + "=") || p02.value.startsWith(varName + "+=") || p02.value.startsWith(varName + "["))) return false;
81692
- }
81693
- const w0 = cmd.words[0]?.plain;
81694
- if (w0 === "read" || w0 === "unset" || w0 === "declare" || w0 === "typeset" || w0 === "local" || w0 === "export" || w0 === "mapfile" || w0 === "readarray") {
81695
- if (w0 === "read" && varName === "REPLY") return false;
81696
- if (cmd.words.slice(1).some((w) => (w.plain ?? "").includes(varName))) return false;
81697
- }
81698
- if (w0 === "printf" && cmd.words[1]?.plain === "-v" && (cmd.words[2]?.plain ?? "").startsWith(varName)) return false;
81699
- for (const w of [...cmd.words, ...cmd.redirects.map((r) => r.target)]) {
81700
- for (const pt of w.parts) {
81701
- if (pt.kind === "arithmetic" && pt.expression.hasMutation && pt.expression.source.includes(varName)) return false;
81702
- if (pt.kind === "substitution" && !this.isVarUnmutatedInScript(varName, pt.script)) return false;
81703
- }
81704
- }
81705
- }
81706
- }
81707
- }
81708
- return true;
81709
- }
81710
- isVarUnmutatedInActiveLoop(varName) {
81711
- if (varName === this._activeLoopVarName || varName === this._activePrintfInductionName) return false;
81712
- if (this._activeLoopCondScript && !this.isVarUnmutatedInScript(varName, this._activeLoopCondScript)) return false;
81713
- if (this._activeLoopBodyScript && !this.isVarUnmutatedInScript(varName, this._activeLoopBodyScript)) return false;
81714
- return true;
81715
- }
81716
- isFileReadOnlyScript(script2, rawState) {
81717
- const visit = (value2) => {
81718
- if (value2 === null || typeof value2 !== "object") return true;
81719
- if (Array.isArray(value2)) return value2.every(visit);
81720
- const node = value2;
81721
- if (typeof node.operator === "string" && "target" in node && !["<", "<<<", "<<", "<<-"].includes(node.operator)) return false;
81722
- if (node.kind === "simple") {
81723
- const cmd = value2;
81724
- const name2 = cmd.words[0]?.plain;
81725
- if (name2 === void 0 && !cmd.words.every((word) => this.assignment(word) || getArrayAssignment(word))) return false;
81726
- if (name2 !== void 0 && (hasShellFunction(rawState, name2) || !["jq", "cat", "echo", "printf", "test", "[", ":", "true", "false"].includes(name2))) return false;
81727
- }
81728
- return Object.values(node).every(visit);
81729
- };
81730
- return visit(script2);
81731
- }
81732
- extractLoopInvariantInput(cmd, hasSingleStdinRedir, hasSingleHereStringRedir, rawState) {
81733
- const w0 = cmd.words[0]?.plain;
81734
- const resolveInvariantWord = (w) => {
81735
- if (w.plain !== void 0) return w.plain;
81736
- if (w.parts.length > 0 && w.parts.every((pt) => pt.kind === "text")) return w.parts.map((pt) => pt.value).join("");
81737
- if (w.parts.length === 1 && w.parts[0].kind === "variable") {
81738
- const vp = w.parts[0];
81739
- if (!vp.indirect && !vp.operator && !vp.substring && !vp.transform && !vp.length && !vp.prefixNames && getArraySelector(vp) === void 0 && this.isVarUnmutatedInActiveLoop(vp.name)) {
81740
- const val = rawState.variables[vp.name];
81741
- if (typeof val === "string") return val;
81742
- }
81743
- }
81744
- return void 0;
81745
- };
81746
- if (w0 === "jq" || w0 === "numfmt" || w0 === "awk") {
81747
- if (hasSingleHereStringRedir) {
81748
- const resolved = resolveInvariantWord(cmd.redirects[0].target);
81749
- return resolved !== void 0 ? resolved + "\n" : void 0;
81750
- }
81751
- if (this._fileWrites?.size || this._outputFiles?.size) return void 0;
81752
- if ([this._activeLoopBodyScript, this._activeLoopCondScript].some((script2) => script2 && !this.isFileReadOnlyScript(script2, rawState))) return void 0;
81753
- const fPlain = hasSingleStdinRedir ? cmd.redirects[0].target.plain : cmd.words[cmd.words.length - 1]?.plain;
81754
- if (!fPlain || fPlain.startsWith("-") || fPlain === "/dev/stdin") return void 0;
81755
- const vCheck = this.tryReadMemoryFileViewSync(resolvePath(rawState.cwd, fPlain), false);
81756
- if (!vCheck || vCheck.byteLength > 16384 || vCheck.includes(0)) return void 0;
81757
- return sharedSyncPipeDecoder.decode(vCheck);
81758
- }
81759
- if (w0 === "cat") {
81760
- if (hasSingleHereStringRedir) {
81761
- const resolved = resolveInvariantWord(cmd.redirects[0].target);
81762
- return resolved !== void 0 ? resolved + "\n" : void 0;
81763
- }
81764
- if (this._fileWrites?.size || this._outputFiles?.size) return void 0;
81765
- if ([this._activeLoopBodyScript, this._activeLoopCondScript].some((script2) => script2 && !this.isFileReadOnlyScript(script2, rawState))) return void 0;
81766
- const fPlain = hasSingleStdinRedir ? cmd.redirects[0].target.plain : cmd.words[1]?.plain;
81767
- if (!fPlain || fPlain.startsWith("-") || fPlain === "/dev/stdin") return void 0;
81768
- const vCheck = this.tryReadMemoryFileViewSync(resolvePath(rawState.cwd, fPlain), false);
81769
- if (!vCheck || vCheck.byteLength > 16384 || vCheck.includes(0)) return void 0;
81770
- return sharedSyncPipeDecoder.decode(vCheck);
81771
- }
81772
- if (w0 === "echo" && cmd.words.length === 2) {
81773
- const resolved = resolveInvariantWord(cmd.words[1]);
81774
- if (resolved !== void 0 && !resolved.startsWith("-")) return resolved + "\n";
81775
- return void 0;
81776
- }
81777
- if (w0 === "printf" && cmd.words.length >= 2) {
81778
- const args = [];
81779
- for (let i = 1; i < cmd.words.length; i++) {
81780
- const r = resolveInvariantWord(cmd.words[i]);
81781
- if (r === void 0) return void 0;
81782
- args.push(r);
81783
- }
81784
- const formatted3 = tryFastPrintf(args);
81785
- return formatted3;
81786
- }
81787
- return void 0;
81788
- }
81789
81496
  canSyncPrintfInductionBody(script2, rawState, inductionName) {
81790
81497
  for (const list of script2.lists) for (const pipeline of list.pipelines) for (const command7 of pipeline.commands) {
81791
81498
  if (command7.kind === "arithmetic") {
@@ -82363,6 +82070,7 @@ ${s1}
82363
82070
  return check(tree);
82364
82071
  }
82365
82072
  canSyncErrorArithmeticStmt(expr, rawState) {
82073
+ if (expr.source.includes("$")) return false;
82366
82074
  if (expr.source.includes("/") || expr.source.includes("%") || expr.source.includes("<<") || expr.source.includes(">>") || expr.source.includes("**") || expr.source.includes("[")) return false;
82367
82075
  try {
82368
82076
  const cachedExpr = expr;
@@ -82504,27 +82212,40 @@ ${s1}
82504
82212
  const prevFastSubPos = this._fastSubPositional;
82505
82213
  rawState.positional = fnArgs;
82506
82214
  this._fastSubPositional = fnArgs;
82507
- const savedLocals = new Array(fnCall.locals.length);
82215
+ const savedLocals = [];
82216
+ const seenLocals = /* @__PURE__ */ new Set();
82508
82217
  try {
82509
- for (let i = 0; i < fnCall.locals.length; i++) {
82510
- const loc = fnCall.locals[i];
82511
- if (loc.isFirstInCmd) this.budget.tick();
82512
- savedLocals[i] = { name: loc.name, val: rawState.variables[loc.name], wasTouched: touched.has(loc.name) };
82513
- if (loc.valueWord !== void 0) {
82514
- rawState.variables[loc.name] = this.fastValueWord(loc.valueWord, rawState, io, false, false, false, false, 0, step.line);
82515
- touched.add(loc.name);
82516
- } else {
82517
- delete rawState.variables[loc.name];
82218
+ for (let i = 0; i < fnCall.locals.length; ) {
82219
+ this.budget.tick();
82220
+ let end = i + 1;
82221
+ while (end < fnCall.locals.length && !fnCall.locals[end].isFirstInCmd) end++;
82222
+ const values = fnCall.locals.slice(i, end).map((loc) => loc.valueWord === void 0 ? void 0 : this.fastValueWord(loc.valueWord, rawState, io, false, false, false, false, 0, step.line));
82223
+ const start = i;
82224
+ for (; i < end; i++) {
82225
+ const loc = fnCall.locals[i];
82226
+ const alreadyLocal = seenLocals.has(loc.name);
82227
+ if (!alreadyLocal) {
82228
+ savedLocals.push({ name: loc.name, val: rawState.variables[loc.name], wasTouched: touched.has(loc.name) });
82229
+ seenLocals.add(loc.name);
82230
+ }
82231
+ const value2 = values[i - start];
82232
+ if (value2 !== void 0) {
82233
+ rawState.variables[loc.name] = value2;
82234
+ touched.add(loc.name);
82235
+ } else if (!alreadyLocal) {
82236
+ delete rawState.variables[loc.name];
82237
+ }
82518
82238
  }
82519
82239
  }
82520
82240
  if (fnCall.steps.length > 0) {
82521
82241
  this.execSyncLoopSteps(fnCall.steps, rawState, io, monitor, touched, mode, onUpdate);
82522
82242
  } else {
82523
82243
  rawState.status = 0;
82524
- onUpdate({ lastCmd: step.cmd, lastArg: fnArgs.length > 0 ? fnArgs[fnArgs.length - 1] : fnCall.name });
82525
82244
  }
82245
+ rawState.lastArgument = fnArgs.at(-1) ?? fnCall.name;
82246
+ onUpdate({ lastCmd: step.cmd, lastArg: rawState.lastArgument });
82526
82247
  } finally {
82527
- for (let i = fnCall.locals.length - 1; i >= 0; i--) {
82248
+ for (let i = savedLocals.length - 1; i >= 0; i--) {
82528
82249
  const saved = savedLocals[i];
82529
82250
  if (saved.val !== void 0) {
82530
82251
  rawState.variables[saved.name] = saved.val;
@@ -85399,6 +85120,7 @@ ${s1}
85399
85120
  throw checkpointFailure;
85400
85121
  }
85401
85122
  if (hasThrown) throw thrownError;
85123
+ state.lastArgument = pendingResume?.lastArgument ?? args.at(-1) ?? name2;
85402
85124
  return exitStatus;
85403
85125
  } finally {
85404
85126
  await scope.close();
@@ -85897,6 +85619,7 @@ ${s1}
85897
85619
  throw checkpointFailure;
85898
85620
  }
85899
85621
  if (outcome.kind === "throw") throw outcome.reason;
85622
+ state.lastArgument = context3.args.at(-1) ?? context3.command;
85900
85623
  return outcome.value;
85901
85624
  }
85902
85625
  if (selectedKind === "builtin" && !(state.externalInvocation && this.commands.has(context3.command))) {
@@ -90459,6 +90182,7 @@ ${prefix3} line ${offset + line}: \`${source2.split("\n")[line - 1] ?? ""}'
90459
90182
  }
90460
90183
  expandSyncTrCharArray(spec) {
90461
90184
  if (spec.length === 0) return void 0;
90185
+ for (let i = 0; i < spec.length; i++) if (spec.charCodeAt(i) >= 128) return void 0;
90462
90186
  if (spec.includes("\\") && spec.includes("-")) return void 0;
90463
90187
  const posixClasses = {
90464
90188
  "[:lower:]": "abcdefghijklmnopqrstuvwxyz",
@@ -90884,9 +90608,9 @@ ${prefix3} line ${offset + line}: \`${source2.split("\n")[line - 1] ?? ""}'
90884
90608
  for (const el of item) {
90885
90609
  if (!el || typeof el !== "object" || Array.isArray(el)) return void 0;
90886
90610
  const rec = el;
90887
- const k = rec.key ?? rec.name ?? rec.k;
90611
+ const k = [rec.key, rec.Key, rec.name, rec.Name].find((value2) => value2 !== void 0 && value2 !== null && value2 !== false);
90888
90612
  if (typeof k !== "string") return void 0;
90889
- obj[k] = Object.hasOwn(rec, "value") ? rec.value : Object.hasOwn(rec, "v") ? rec.v : null;
90613
+ obj[k] = Object.hasOwn(rec, "value") ? rec.value : Object.hasOwn(rec, "Value") ? rec.Value : null;
90890
90614
  }
90891
90615
  return [obj];
90892
90616
  }
@@ -90915,7 +90639,7 @@ ${prefix3} line ${offset + line}: \`${source2.split("\n")[line - 1] ?? ""}'
90915
90639
  if (!Array.isArray(item) || !item.every((x) => typeof x === "string" || typeof x === "number" || typeof x === "boolean" || x === null)) return void 0;
90916
90640
  return [item.map((x) => x === null ? "" : String(x)).join(arg)];
90917
90641
  }
90918
- if (fn === "split") return typeof item === "string" ? [item.split(arg)] : void 0;
90642
+ if (fn === "split") return typeof item === "string" ? [arg === "" ? Array.from(item) : item.split(arg)] : void 0;
90919
90643
  if (fn === "ltrimstr") return typeof item === "string" ? [item.startsWith(arg) ? item.slice(arg.length) : item] : void 0;
90920
90644
  if (fn === "rtrimstr") return typeof item === "string" ? [arg.length > 0 && item.endsWith(arg) ? item.slice(0, -arg.length) : item] : void 0;
90921
90645
  if (fn === "startswith") return typeof item === "string" ? [item.startsWith(arg)] : void 0;
@@ -91120,9 +90844,8 @@ ${prefix3} line ${offset + line}: \`${source2.split("\n")[line - 1] ?? ""}'
91120
90844
  break;
91121
90845
  }
91122
90846
  if (!a.startsWith("-") || a === "-") {
91123
- operands.push(a);
91124
- idx++;
91125
- continue;
90847
+ operands.push(...args.slice(idx));
90848
+ break;
91126
90849
  }
91127
90850
  if (a === "-a" || a === "--multiple") {
91128
90851
  multiple = true;
@@ -91443,7 +91166,7 @@ ${prefix3} line ${offset + line}: \`${source2.split("\n")[line - 1] ?? ""}'
91443
91166
  }
91444
91167
  if (st.kind === "=") {
91445
91168
  out.push(String(idx1));
91446
- lastInputIndex = i;
91169
+ lastInputIndex = -1;
91447
91170
  continue;
91448
91171
  }
91449
91172
  if (st.kind === "q") {
@@ -91480,7 +91203,10 @@ ${prefix3} line ${offset + line}: \`${source2.split("\n")[line - 1] ?? ""}'
91480
91203
  }
91481
91204
  return replacement;
91482
91205
  });
91483
- if (matchedOnce && st.printOnMatch) out.push(l);
91206
+ if (matchedOnce && st.printOnMatch) {
91207
+ out.push(l);
91208
+ lastInputIndex = i;
91209
+ }
91484
91210
  }
91485
91211
  if (quitNow) {
91486
91212
  break;
@@ -92413,14 +92139,16 @@ ${prefix3} line ${offset + line}: \`${source2.split("\n")[line - 1] ?? ""}'
92413
92139
  endField = km[2] !== void 0 ? Number(km[2]) : void 0;
92414
92140
  if (endField !== void 0 && endField < startField) return void 0;
92415
92141
  const kf = km[3] ?? "";
92416
- if (kf.includes("n")) keyNum = true;
92417
- if (kf.includes("h")) keyHuman = true;
92418
- if (kf.includes("M")) keyMonth = true;
92419
- if (kf.includes("d")) keyDict = true;
92420
- if (kf.includes("r")) keyRev = true;
92421
- if (kf.includes("f")) keyFold = true;
92422
- if (kf.includes("b")) keyBlanks = true;
92423
- if (kf.includes("V")) keyVer = true;
92142
+ if (kf.length > 0) {
92143
+ keyNum = kf.includes("n");
92144
+ keyHuman = kf.includes("h");
92145
+ keyMonth = kf.includes("M");
92146
+ keyDict = kf.includes("d");
92147
+ keyRev = kf.includes("r");
92148
+ keyFold = kf.includes("f");
92149
+ keyBlanks = kf.includes("b");
92150
+ keyVer = kf.includes("V");
92151
+ }
92424
92152
  }
92425
92153
  const extractKey = (l) => {
92426
92154
  let raw = keySpec === void 0 ? l : (() => {
@@ -92444,7 +92172,13 @@ ${prefix3} line ${offset + line}: \`${source2.split("\n")[line - 1] ?? ""}'
92444
92172
  })();
92445
92173
  if (keyBlanks) raw = raw.replace(/^[ \t]+/, "");
92446
92174
  if (keyDict) raw = raw.replace(/[^a-zA-Z0-9 \t]+/g, "");
92447
- return keyFold ? raw.toUpperCase() : raw;
92175
+ if (!keyFold) return raw;
92176
+ let folded = "";
92177
+ for (let i = 0; i < raw.length; i++) {
92178
+ const code = raw.charCodeAt(i);
92179
+ folded += code >= 97 && code <= 122 ? String.fromCharCode(code - 32) : raw[i];
92180
+ }
92181
+ return folded;
92448
92182
  };
92449
92183
  const parseNum = (s) => {
92450
92184
  const m = /^[ \t]*(-?(?:\d+(?:\.\d*)?|\.\d+))/.exec(s);
@@ -92472,6 +92206,23 @@ ${prefix3} line ${offset + line}: \`${source2.split("\n")[line - 1] ?? ""}'
92472
92206
  const idx = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"].indexOf(m[1].toUpperCase());
92473
92207
  return idx === -1 ? 0 : idx + 1;
92474
92208
  };
92209
+ const encoded2 = /* @__PURE__ */ new Map();
92210
+ const bytesOf = (line) => {
92211
+ let bytes2 = encoded2.get(line);
92212
+ if (bytes2 === void 0) {
92213
+ bytes2 = fastSharedTextEncoder.encode(line);
92214
+ encoded2.set(line, bytes2);
92215
+ }
92216
+ return bytes2;
92217
+ };
92218
+ const compareBytes2 = (left, right) => {
92219
+ const a = bytesOf(left);
92220
+ const b = bytesOf(right);
92221
+ for (let i = 0; i < Math.min(a.length, b.length); i++) {
92222
+ if (a[i] !== b[i]) return a[i] - b[i];
92223
+ }
92224
+ return a.length - b.length;
92225
+ };
92475
92226
  const sorted = [...rawLines].sort((a, b) => {
92476
92227
  const ka = extractKey(a);
92477
92228
  const kb = extractKey(b);
@@ -92490,13 +92241,12 @@ ${prefix3} line ${offset + line}: \`${source2.split("\n")[line - 1] ?? ""}'
92490
92241
  const vc = this.compareSyncVersion(ka, kb);
92491
92242
  if (vc !== 0) return keyRev ? -vc : vc;
92492
92243
  } else if (ka !== kb) {
92493
- return ka < kb ? keyRev ? 1 : -1 : keyRev ? -1 : 1;
92244
+ const comparison2 = compareBytes2(ka, kb);
92245
+ return keyRev ? -comparison2 : comparison2;
92494
92246
  }
92495
92247
  if (uniq || stable) return 0;
92496
- const fa = fold2 ? a.toUpperCase() : a;
92497
- const fb = fold2 ? b.toUpperCase() : b;
92498
- if (fa !== fb) return fa < fb ? rev ? 1 : -1 : rev ? -1 : 1;
92499
- return a < b ? rev ? 1 : -1 : a > b ? rev ? -1 : 1 : 0;
92248
+ const comparison = compareBytes2(a, b);
92249
+ return rev ? -comparison : comparison;
92500
92250
  });
92501
92251
  if (!uniq) return sorted;
92502
92252
  const dedup = [];