@google/gemini-cli 0.70.0 → 0.71.0-nightly.20261120.gd4cb1713f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/bundle/{chunk-VHXUWMGE.js → chunk-22NLCXU3.js} +2 -2
  2. package/bundle/{chunk-SPAMAY26.js → chunk-3DBVNRC7.js} +1 -1
  3. package/bundle/{chunk-FXAACYC3.js → chunk-3VKSDKQA.js} +1 -1
  4. package/bundle/{chunk-YOEWNBDC.js → chunk-43QQPZRQ.js} +2 -2
  5. package/bundle/{chunk-5VFAWK3F.js → chunk-4FKCNBUM.js} +1 -1
  6. package/bundle/{chunk-BOIBJEIO.js → chunk-4SEHQOPY.js} +3 -3
  7. package/bundle/{chunk-6IKD2NB3.js → chunk-4V6FXIV7.js} +1 -1
  8. package/bundle/{chunk-FHK4RNCX.js → chunk-4YWPS6WG.js} +7 -7
  9. package/bundle/{chunk-4BWP3TDK.js → chunk-6VJSIYX5.js} +9 -8
  10. package/bundle/{chunk-LMNAB62M.js → chunk-7CGFKAQQ.js} +2 -2
  11. package/bundle/{chunk-3VGGGCOZ.js → chunk-7WRW57EW.js} +2 -2
  12. package/bundle/{chunk-37D3S3FZ.js → chunk-AQR7HAVC.js} +878 -371
  13. package/bundle/{chunk-V4HIE5G5.js → chunk-AWAS7A4U.js} +1 -1
  14. package/bundle/{chunk-GFBMTAPD.js → chunk-BFYOZTEC.js} +8 -6
  15. package/bundle/{chunk-WRWAVEME.js → chunk-CVDUPOPD.js} +1 -1
  16. package/bundle/{chunk-JLKRLYZG.js → chunk-EV4MLSRK.js} +2 -2
  17. package/bundle/{chunk-KV6XIC2Z.js → chunk-H35O2XC7.js} +1 -1
  18. package/bundle/{chunk-7JS2T75Z.js → chunk-HBX5SUG6.js} +1 -1
  19. package/bundle/chunk-ID6HT5PN.js +512 -0
  20. package/bundle/chunk-JUDLPWWJ.js +1962 -0
  21. package/bundle/{chunk-CB37EK5Y.js → chunk-JVBEESQE.js} +3 -3
  22. package/bundle/{chunk-EG2BSKPF.js → chunk-L7GW5P2N.js} +1 -1
  23. package/bundle/{chunk-UF44X63P.js → chunk-MFOWRKY4.js} +782 -323
  24. package/bundle/chunk-MPPDWK6R.js +40024 -0
  25. package/bundle/{chunk-G6SC5BOV.js → chunk-NF46UAZ5.js} +1 -1
  26. package/bundle/chunk-P3QKD7NI.js +190 -0
  27. package/bundle/chunk-P5SMSWOI.js +65 -0
  28. package/bundle/{chunk-QYKA4YD7.js → chunk-Q3MSDTUZ.js} +3 -3
  29. package/bundle/{chunk-AMHNNZY2.js → chunk-QYILFI2Q.js} +7 -7
  30. package/bundle/{chunk-RFQXG324.js → chunk-R5O4JOJ7.js} +1 -1
  31. package/bundle/chunk-T5ERFODG.js +118 -0
  32. package/bundle/{chunk-LMBUPWFC.js → chunk-TKCJYF6S.js} +8765 -15613
  33. package/bundle/{chunk-CMKRWIX6.js → chunk-WEQEDCCJ.js} +71 -58
  34. package/bundle/chunk-YGBB6EOP.js +1571 -0
  35. package/bundle/chunk-ZL2NEMMB.js +420386 -0
  36. package/bundle/chunk-ZM7BCSH5.js +60338 -0
  37. package/bundle/{cleanup-BMYAIPAL.js → cleanup-2V4YG4JU.js} +2 -2
  38. package/bundle/{cleanup-CWOSCK57.js → cleanup-577T3DEI.js} +2 -2
  39. package/bundle/{cleanup-JTPRPYIQ.js → cleanup-A7BQ5O2C.js} +2 -2
  40. package/bundle/cleanup-BER5KF3M.js +34 -0
  41. package/bundle/{core-XZECNCR2.js → core-J5GAQUTA.js} +31 -1
  42. package/bundle/{devtoolsService-ER22TM2Y.js → devtoolsService-5ICQIIYF.js} +2 -2
  43. package/bundle/{devtoolsService-WNJOZ7ZT.js → devtoolsService-7E2XLRN6.js} +2 -2
  44. package/bundle/{devtoolsService-O5VD5YWD.js → devtoolsService-B2G4MIWC.js} +4 -3
  45. package/bundle/devtoolsService-HFMB7OZU.js +919 -0
  46. package/bundle/{core-HYVGBZPP.js → dist-63TFONDS.js} +31 -1
  47. package/bundle/{dist-75NDR3EX.js → dist-J4SRUOE6.js} +31 -1
  48. package/bundle/dist-J54GSUG2.js +2372 -0
  49. package/bundle/docs/changelogs/index.md +46 -0
  50. package/bundle/docs/changelogs/latest.md +82 -100
  51. package/bundle/docs/changelogs/preview.md +82 -115
  52. package/bundle/{formatError-M4GLDFGE.js → formatError-ISWUYAZB.js} +2 -2
  53. package/bundle/{formatError-QOZLAZ32.js → formatError-IX7HHO6M.js} +2 -2
  54. package/bundle/{formatError-FYLLVZDF.js → formatError-MZRXOV55.js} +2 -2
  55. package/bundle/formatError-U2ZQLJHB.js +14 -0
  56. package/bundle/{gemini-AYDYW6NZ.js → gemini-FRGLIXP7.js} +15 -15
  57. package/bundle/{gemini-PG2FEK5D.js → gemini-GSQARDB2.js} +224 -208
  58. package/bundle/gemini-KZFVMGY3.js +20020 -0
  59. package/bundle/{gemini-FRSP6LA3.js → gemini-ZZBTL6TA.js} +15 -15
  60. package/bundle/gemini.js +8 -8
  61. package/bundle/{interactiveCli-76LAQB3B.js → interactiveCli-AHDFCTRR.js} +157 -32
  62. package/bundle/{interactiveCli-BYWR7IEK.js → interactiveCli-MVGIIVAP.js} +157 -32
  63. package/bundle/{interactiveCli-6TVFB4R5.js → interactiveCli-UN4BNLK2.js} +468 -324
  64. package/bundle/interactiveCli-XW2S7MKZ.js +36447 -0
  65. package/bundle/{liteRtServerManager-GIRVSE6M.js → liteRtServerManager-3MOGK3XY.js} +4 -4
  66. package/bundle/{liteRtServerManager-KZ62KJW3.js → liteRtServerManager-O727KCKA.js} +4 -4
  67. package/bundle/{liteRtServerManager-BYJWS5BO.js → liteRtServerManager-TSG2V5XN.js} +4 -4
  68. package/bundle/liteRtServerManager-YLE7JTV7.js +65 -0
  69. package/bundle/{oauth2-provider-ZBFFAIQE.js → oauth2-provider-3EEFSHG4.js} +1 -1
  70. package/bundle/{oauth2-provider-SFFQQ6OE.js → oauth2-provider-DWO2KVCY.js} +1 -1
  71. package/bundle/{oauth2-provider-SRH6I6G7.js → oauth2-provider-G25ZRGDY.js} +41 -79
  72. package/bundle/oauth2-provider-RHT5OSMO.js +273 -0
  73. package/bundle/{start-PLK5XHJC.js → start-4XOSRN5A.js} +6 -6
  74. package/bundle/{start-Q66LTS3Y.js → start-7JXWL6XR.js} +6 -6
  75. package/bundle/{start-OLEVDFQS.js → start-CAA6RQBK.js} +6 -6
  76. package/bundle/start-I3RUABAZ.js +18 -0
  77. package/package.json +1 -1
@@ -257240,6 +257240,51 @@ import os4 from "node:os";
257240
257240
  import fs8 from "node:fs";
257241
257241
  import path8 from "node:path";
257242
257242
  import { spawn, spawnSync } from "node:child_process";
257243
+
257244
+ // packages/core/dist/src/utils/shell-parse-cache.js
257245
+ import { AsyncLocalStorage } from "node:async_hooks";
257246
+ var CommandParseCache = class {
257247
+ completed = /* @__PURE__ */ new Map();
257248
+ inFlight = /* @__PURE__ */ new Map();
257249
+ makeKey(executable, command) {
257250
+ return `${executable}\0${command}`;
257251
+ }
257252
+ hasCompleted(executable, command) {
257253
+ return this.completed.has(this.makeKey(executable, command));
257254
+ }
257255
+ getCompleted(executable, command) {
257256
+ return this.completed.get(this.makeKey(executable, command));
257257
+ }
257258
+ setCompleted(executable, command, result) {
257259
+ this.completed.set(this.makeKey(executable, command), result);
257260
+ }
257261
+ getInFlight(executable, command) {
257262
+ return this.inFlight.get(this.makeKey(executable, command));
257263
+ }
257264
+ trackInFlight(executable, command, promise2) {
257265
+ const key = this.makeKey(executable, command);
257266
+ this.inFlight.set(key, promise2);
257267
+ void promise2.finally(() => {
257268
+ if (this.inFlight.get(key) === promise2) {
257269
+ this.inFlight.delete(key);
257270
+ }
257271
+ });
257272
+ return promise2;
257273
+ }
257274
+ };
257275
+ var commandParseCacheStorage = new AsyncLocalStorage();
257276
+ function getActiveCommandParseCache() {
257277
+ return commandParseCacheStorage.getStore();
257278
+ }
257279
+ function runWithCommandParseCache(fn3, cache2) {
257280
+ const targetCache = cache2 ?? commandParseCacheStorage.getStore() ?? new CommandParseCache();
257281
+ if (commandParseCacheStorage.getStore() === targetCache) {
257282
+ return fn3(targetCache);
257283
+ }
257284
+ return commandParseCacheStorage.run(targetCache, () => fn3(targetCache));
257285
+ }
257286
+
257287
+ // packages/core/dist/src/utils/shell-utils.js
257243
257288
  import * as readline from "node:readline";
257244
257289
 
257245
257290
  // node_modules/web-tree-sitter/tree-sitter.js
@@ -264265,7 +264310,7 @@ async function getCommandName(command, args2) {
264265
264310
  await initializeShellParsers();
264266
264311
  const fullCmd = [command, ...args2].join(" ");
264267
264312
  const stripped = stripShellWrapper(fullCmd);
264268
- const roots = getCommandRoots(stripped).filter((r9) => r9 !== "shopt" && r9 !== "set");
264313
+ const roots = (await getCommandRootsAsync(stripped)).filter((r9) => r9 !== "shopt" && r9 !== "set");
264269
264314
  if (roots.length > 0) {
264270
264315
  return roots[0];
264271
264316
  }
@@ -264656,7 +264701,51 @@ function parseBashCommandDetails(command) {
264656
264701
  hasError: hasError2
264657
264702
  };
264658
264703
  }
264659
- function parsePowerShellCommandDetails(command, executable) {
264704
+ function isRawPowerShellCommand(value) {
264705
+ return typeof value === "object" && value !== null && !Array.isArray(value);
264706
+ }
264707
+ function isRawPowerShellParsePayload(value) {
264708
+ return typeof value === "object" && value !== null && !Array.isArray(value);
264709
+ }
264710
+ function parsePowerShellParserOutput(rawStdout, originalCommand) {
264711
+ const output = rawStdout.trim();
264712
+ if (!output) {
264713
+ return { details: [], hasError: true };
264714
+ }
264715
+ let parsedUnknown;
264716
+ try {
264717
+ parsedUnknown = JSON.parse(output);
264718
+ } catch {
264719
+ return { details: [], hasError: true };
264720
+ }
264721
+ if (!isRawPowerShellParsePayload(parsedUnknown) || parsedUnknown.success !== true) {
264722
+ return { details: [], hasError: true };
264723
+ }
264724
+ const rawCommandsField = parsedUnknown.commands;
264725
+ const rawCommands = Array.isArray(rawCommandsField) ? rawCommandsField : isRawPowerShellCommand(rawCommandsField) ? [rawCommandsField] : [];
264726
+ const details = rawCommands.map((commandDetail) => {
264727
+ if (!isRawPowerShellCommand(commandDetail) || typeof commandDetail.name !== "string") {
264728
+ return null;
264729
+ }
264730
+ const name3 = normalizeCommandName(commandDetail.name);
264731
+ const text = typeof commandDetail.text === "string" ? commandDetail.text.trim() : originalCommand;
264732
+ const rawArgs = commandDetail.args;
264733
+ return {
264734
+ name: name3,
264735
+ text,
264736
+ startIndex: typeof commandDetail.startIndex === "number" ? commandDetail.startIndex : 0,
264737
+ args: Array.isArray(rawArgs) ? rawArgs.filter((arg) => typeof arg === "string") : void 0
264738
+ };
264739
+ }).filter((detail) => detail !== null).sort((a2, b3) => a2.startIndex - b3.startIndex);
264740
+ return {
264741
+ details,
264742
+ hasError: details.length === 0,
264743
+ hasRedirection: typeof parsedUnknown.hasRedirection === "boolean" ? parsedUnknown.hasRedirection : void 0,
264744
+ hasCommandSubstitution: typeof parsedUnknown.hasCommandSubstitution === "boolean" ? parsedUnknown.hasCommandSubstitution : false
264745
+ };
264746
+ }
264747
+ var globalInFlightPowerShellParses = /* @__PURE__ */ new Map();
264748
+ function parsePowerShellCommandDetails(command, executable, cache2) {
264660
264749
  const trimmed = command.trim();
264661
264750
  if (!trimmed) {
264662
264751
  return {
@@ -264664,6 +264753,10 @@ function parsePowerShellCommandDetails(command, executable) {
264664
264753
  hasError: true
264665
264754
  };
264666
264755
  }
264756
+ const activeCache = cache2 ?? getActiveCommandParseCache();
264757
+ if (activeCache?.hasCompleted(executable, command)) {
264758
+ return activeCache.getCompleted(executable, command) ?? null;
264759
+ }
264667
264760
  try {
264668
264761
  const result = spawnSync(executable, [
264669
264762
  "-NoLogo",
@@ -264679,53 +264772,157 @@ function parsePowerShellCommandDetails(command, executable) {
264679
264772
  encoding: "utf-8"
264680
264773
  });
264681
264774
  if (result.error || result.status !== 0) {
264775
+ activeCache?.setCompleted(executable, command, null);
264682
264776
  return null;
264683
264777
  }
264684
- const output = (result.stdout ?? "").toString().trim();
264685
- if (!output) {
264686
- return { details: [], hasError: true };
264778
+ const parsed = parsePowerShellParserOutput((result.stdout ?? "").toString(), command);
264779
+ activeCache?.setCompleted(executable, command, parsed);
264780
+ return parsed;
264781
+ } catch {
264782
+ activeCache?.setCompleted(executable, command, null);
264783
+ return null;
264784
+ }
264785
+ }
264786
+ async function parsePowerShellCommandDetailsAsync(command, executable, cache2, signal) {
264787
+ const trimmed = command.trim();
264788
+ if (!trimmed) {
264789
+ return {
264790
+ details: [],
264791
+ hasError: true
264792
+ };
264793
+ }
264794
+ if (signal?.aborted) {
264795
+ return null;
264796
+ }
264797
+ const activeCache = cache2 ?? getActiveCommandParseCache();
264798
+ if (activeCache?.hasCompleted(executable, command)) {
264799
+ return activeCache.getCompleted(executable, command) ?? null;
264800
+ }
264801
+ const existingInFlight = activeCache?.getInFlight(executable, command);
264802
+ if (existingInFlight) {
264803
+ return existingInFlight;
264804
+ }
264805
+ const globalKey = `${executable}\0${command}`;
264806
+ if (!signal) {
264807
+ const existingGlobalInFlight = globalInFlightPowerShellParses.get(globalKey);
264808
+ if (existingGlobalInFlight) {
264809
+ const joinedPromise = existingGlobalInFlight.then((result) => {
264810
+ activeCache?.setCompleted(executable, command, result);
264811
+ return result;
264812
+ });
264813
+ if (activeCache) {
264814
+ return activeCache.trackInFlight(executable, command, joinedPromise);
264815
+ }
264816
+ return joinedPromise;
264687
264817
  }
264688
- let parsed = null;
264818
+ }
264819
+ const parsePromise = new Promise((resolve30) => {
264820
+ let settled = false;
264821
+ const finish = (value, cacheResult = true) => {
264822
+ if (!settled) {
264823
+ settled = true;
264824
+ if (cacheResult && !signal?.aborted) {
264825
+ activeCache?.setCompleted(executable, command, value);
264826
+ }
264827
+ resolve30(value);
264828
+ }
264829
+ };
264830
+ let child;
264689
264831
  try {
264690
- parsed = JSON.parse(output);
264832
+ child = spawn(executable, [
264833
+ "-NoLogo",
264834
+ "-NoProfile",
264835
+ "-NonInteractive",
264836
+ "-EncodedCommand",
264837
+ POWERSHELL_PARSER_SCRIPT
264838
+ ], {
264839
+ env: {
264840
+ ...process.env,
264841
+ [POWERSHELL_COMMAND_ENV]: command
264842
+ },
264843
+ stdio: ["ignore", "pipe", "pipe"],
264844
+ windowsHide: true,
264845
+ ...signal ? { signal } : {}
264846
+ });
264691
264847
  } catch {
264692
- return { details: [], hasError: true };
264693
- }
264694
- if (!parsed?.success) {
264695
- return { details: [], hasError: true };
264848
+ finish(null, !signal?.aborted);
264849
+ return;
264696
264850
  }
264697
- const rawCommands = Array.isArray(parsed.commands) ? parsed.commands : parsed.commands ? [parsed.commands] : [];
264698
- const details = rawCommands.map((commandDetail) => {
264699
- if (!commandDetail || typeof commandDetail.name !== "string") {
264700
- return null;
264851
+ let stdout = "";
264852
+ child.stdout?.setEncoding("utf-8");
264853
+ child.stdout?.on("data", (chunk) => {
264854
+ stdout += chunk.toString();
264855
+ });
264856
+ child.stderr?.on("data", () => {
264857
+ });
264858
+ child.on("error", (err2) => {
264859
+ if (err2.name === "AbortError" || signal?.aborted) {
264860
+ finish(null, false);
264861
+ return;
264701
264862
  }
264702
- const name3 = normalizeCommandName(commandDetail.name);
264703
- const text = typeof commandDetail.text === "string" ? commandDetail.text.trim() : command;
264704
- return {
264705
- name: name3,
264706
- text,
264707
- startIndex: typeof commandDetail.startIndex === "number" ? commandDetail.startIndex : 0,
264708
- args: Array.isArray(commandDetail.args) ? commandDetail.args : void 0
264709
- };
264710
- }).filter((detail) => detail !== null).sort((a2, b3) => a2.startIndex - b3.startIndex);
264711
- return {
264712
- details,
264713
- hasError: details.length === 0,
264714
- hasRedirection: parsed.hasRedirection,
264715
- hasCommandSubstitution: parsed.hasCommandSubstitution ?? false
264716
- };
264717
- } catch {
264718
- return null;
264863
+ finish(null);
264864
+ });
264865
+ child.on("close", (code) => {
264866
+ if (signal?.aborted) {
264867
+ finish(null, false);
264868
+ return;
264869
+ }
264870
+ if (code !== 0) {
264871
+ finish(null);
264872
+ return;
264873
+ }
264874
+ const parsed = parsePowerShellParserOutput(stdout, command);
264875
+ finish(parsed);
264876
+ });
264877
+ });
264878
+ if (!signal) {
264879
+ globalInFlightPowerShellParses.set(globalKey, parsePromise);
264880
+ void parsePromise.finally(() => {
264881
+ if (globalInFlightPowerShellParses.get(globalKey) === parsePromise) {
264882
+ globalInFlightPowerShellParses.delete(globalKey);
264883
+ }
264884
+ });
264885
+ }
264886
+ if (activeCache) {
264887
+ return activeCache.trackInFlight(executable, command, parsePromise);
264888
+ }
264889
+ return parsePromise;
264890
+ }
264891
+ function parseCommandDetails(command, cache2) {
264892
+ const configuration = getShellConfiguration();
264893
+ if (configuration.shell === "powershell") {
264894
+ const result = parsePowerShellCommandDetails(command, configuration.executable, cache2);
264895
+ if (!result || result.hasError) {
264896
+ if (detectPowerShellSubstitution(command)) {
264897
+ return result ?? { details: [], hasError: true };
264898
+ }
264899
+ const bashResult = parseBashCommandDetails(command);
264900
+ if (bashResult && !bashResult.hasError) {
264901
+ return bashResult;
264902
+ }
264903
+ }
264904
+ return result;
264905
+ }
264906
+ if (configuration.shell === "bash") {
264907
+ return parseBashCommandDetails(command);
264719
264908
  }
264909
+ return null;
264720
264910
  }
264721
- function parseCommandDetails(command) {
264911
+ async function parseCommandDetailsAsync(command, cache2, signal) {
264912
+ if (signal?.aborted) {
264913
+ return null;
264914
+ }
264722
264915
  const configuration = getShellConfiguration();
264723
264916
  if (configuration.shell === "powershell") {
264724
- const result = parsePowerShellCommandDetails(command, configuration.executable);
264917
+ const result = await parsePowerShellCommandDetailsAsync(command, configuration.executable, cache2, signal);
264918
+ if (signal?.aborted) {
264919
+ return null;
264920
+ }
264725
264921
  if (!result || result.hasError) {
264726
264922
  if (detectPowerShellSubstitution(command)) {
264727
264923
  return result ?? { details: [], hasError: true };
264728
264924
  }
264925
+ await initializeShellParsers();
264729
264926
  const bashResult = parseBashCommandDetails(command);
264730
264927
  if (bashResult && !bashResult.hasError) {
264731
264928
  return bashResult;
@@ -264734,10 +264931,15 @@ function parseCommandDetails(command) {
264734
264931
  return result;
264735
264932
  }
264736
264933
  if (configuration.shell === "bash") {
264934
+ await initializeShellParsers();
264737
264935
  return parseBashCommandDetails(command);
264738
264936
  }
264739
264937
  return null;
264740
264938
  }
264939
+ var defaultParseCommandDetailsRef = parseCommandDetails;
264940
+ function isDefaultParseCommandDetails(fn3) {
264941
+ return fn3 === defaultParseCommandDetailsRef;
264942
+ }
264741
264943
  function getShellConfiguration() {
264742
264944
  if (isWindows()) {
264743
264945
  const powershellArgsPrefix = ["-NoProfile", "-NonInteractive", "-Command"];
@@ -264789,34 +264991,61 @@ function escapeShellArg(arg, shell) {
264789
264991
  return (0, import_shell_quote.quote)([arg]);
264790
264992
  }
264791
264993
  }
264792
- function hasRedirection(command) {
264994
+ function hasBashTreeRedirection(command, fallbackCheck) {
264995
+ const tree = parseCommandTree(command);
264996
+ if (!tree)
264997
+ return fallbackCheck();
264998
+ const stack = [tree.rootNode];
264999
+ while (stack.length > 0) {
265000
+ const current = stack.pop();
265001
+ if (current.type === "redirected_statement" || current.type === "file_redirect" || current.type === "heredoc_redirect" || current.type === "herestring_redirect") {
265002
+ return true;
265003
+ }
265004
+ for (let i3 = current.childCount - 1; i3 >= 0; i3 -= 1) {
265005
+ const child = current.child(i3);
265006
+ if (child)
265007
+ stack.push(child);
265008
+ }
265009
+ }
265010
+ return false;
265011
+ }
265012
+ function hasRedirection(command, cache2) {
264793
265013
  const fallbackCheck = () => /[><]/.test(command);
264794
265014
  if (!fallbackCheck()) {
264795
265015
  return false;
264796
265016
  }
264797
265017
  const configuration = getShellConfiguration();
264798
265018
  if (configuration.shell === "powershell") {
264799
- const parsed = parsePowerShellCommandDetails(command, configuration.executable);
265019
+ const parsed = parsePowerShellCommandDetails(command, configuration.executable, cache2);
264800
265020
  return parsed && !parsed.hasError ? !!parsed.hasRedirection : fallbackCheck();
264801
265021
  }
264802
265022
  if (configuration.shell === "bash" && bashLanguage) {
264803
- const tree = parseCommandTree(command);
264804
- if (!tree)
264805
- return fallbackCheck();
264806
- const stack = [tree.rootNode];
264807
- while (stack.length > 0) {
264808
- const current = stack.pop();
264809
- if (current.type === "redirected_statement" || current.type === "file_redirect" || current.type === "heredoc_redirect" || current.type === "herestring_redirect") {
264810
- return true;
264811
- }
264812
- for (let i3 = current.childCount - 1; i3 >= 0; i3 -= 1) {
264813
- const child = current.child(i3);
264814
- if (child)
264815
- stack.push(child);
264816
- }
264817
- }
265023
+ return hasBashTreeRedirection(command, fallbackCheck);
265024
+ }
265025
+ return fallbackCheck();
265026
+ }
265027
+ async function hasRedirectionAsync(command, cache2, signal) {
265028
+ if (signal?.aborted) {
264818
265029
  return false;
264819
265030
  }
265031
+ const fallbackCheck = () => /[><]/.test(command);
265032
+ if (!fallbackCheck()) {
265033
+ return false;
265034
+ }
265035
+ const configuration = getShellConfiguration();
265036
+ if (configuration.shell === "powershell") {
265037
+ const parsed = await parsePowerShellCommandDetailsAsync(command, configuration.executable, cache2, signal);
265038
+ if (signal?.aborted) {
265039
+ return false;
265040
+ }
265041
+ return parsed && !parsed.hasError ? !!parsed.hasRedirection : fallbackCheck();
265042
+ }
265043
+ if (configuration.shell === "bash") {
265044
+ await initializeShellParsers();
265045
+ if (bashLanguage) {
265046
+ return hasBashTreeRedirection(command, fallbackCheck);
265047
+ }
265048
+ }
264820
265049
  return fallbackCheck();
264821
265050
  }
264822
265051
  var SHELL_EXPANSION_NODE_TYPES = /* @__PURE__ */ new Set([
@@ -264953,30 +265182,66 @@ function hasUnresolvedShellExpansion(command) {
264953
265182
  tree.delete();
264954
265183
  }
264955
265184
  }
264956
- function splitCommands(command) {
264957
- const parsed = parseCommandDetails(command);
265185
+ function splitCommands(command, cache2) {
265186
+ const parsed = parseCommandDetails(command, cache2);
264958
265187
  if (!parsed || parsed.hasError) {
264959
265188
  return [];
264960
265189
  }
264961
265190
  return parsed.details.filter((detail) => !REDIRECTION_NAMES.has(detail.name)).map((detail) => detail.text).filter(Boolean);
264962
265191
  }
264963
- function getCommandRoot(command) {
264964
- const parsed = parseCommandDetails(command);
265192
+ async function splitCommandsAsync(command, cache2, signal) {
265193
+ const parsed = await parseCommandDetailsAsync(command, cache2, signal);
265194
+ if (!parsed || parsed.hasError) {
265195
+ return [];
265196
+ }
265197
+ return parsed.details.filter((detail) => !REDIRECTION_NAMES.has(detail.name)).map((detail) => detail.text).filter(Boolean);
265198
+ }
265199
+ function getCommandRoot(command, cache2) {
265200
+ const parsed = parseCommandDetails(command, cache2);
265201
+ if (!parsed || parsed.hasError || parsed.details.length === 0) {
265202
+ return void 0;
265203
+ }
265204
+ return parsed.details[0]?.name;
265205
+ }
265206
+ async function getCommandRootAsync(command, cache2, signal) {
265207
+ const parsed = await parseCommandDetailsAsync(command, cache2, signal);
264965
265208
  if (!parsed || parsed.hasError || parsed.details.length === 0) {
264966
265209
  return void 0;
264967
265210
  }
264968
265211
  return parsed.details[0]?.name;
264969
265212
  }
264970
- function getCommandRoots(command) {
265213
+ function getCommandRoots(command, cache2) {
265214
+ if (!command) {
265215
+ return [];
265216
+ }
265217
+ const parsed = parseCommandDetails(command, cache2);
265218
+ if (!parsed || parsed.hasError) {
265219
+ return [];
265220
+ }
265221
+ return parsed.details.map((detail) => detail.name).filter((name3) => !REDIRECTION_NAMES.has(name3)).filter(Boolean);
265222
+ }
265223
+ async function getCommandRootsAsync(command, cache2, signal) {
264971
265224
  if (!command) {
264972
265225
  return [];
264973
265226
  }
264974
- const parsed = parseCommandDetails(command);
265227
+ const parsed = await parseCommandDetailsAsync(command, cache2, signal);
264975
265228
  if (!parsed || parsed.hasError) {
264976
265229
  return [];
264977
265230
  }
264978
265231
  return parsed.details.map((detail) => detail.name).filter((name3) => !REDIRECTION_NAMES.has(name3)).filter(Boolean);
264979
265232
  }
265233
+ var defaultHasRedirectionRef = hasRedirection;
265234
+ var defaultSplitCommandsRef = splitCommands;
265235
+ var defaultGetCommandRootsRef = getCommandRoots;
265236
+ function isDefaultHasRedirection(fn3) {
265237
+ return fn3 === defaultHasRedirectionRef;
265238
+ }
265239
+ function isDefaultSplitCommands(fn3) {
265240
+ return fn3 === defaultSplitCommandsRef;
265241
+ }
265242
+ function isDefaultGetCommandRoots(fn3) {
265243
+ return fn3 === defaultGetCommandRootsRef;
265244
+ }
264980
265245
  var PS_WRAPPER_FLAGS = /* @__PURE__ */ new Set([
264981
265246
  "-nologo",
264982
265247
  "-noprofile",
@@ -266218,10 +266483,7 @@ function isInteractiveGeminiSegment(segment) {
266218
266483
  }
266219
266484
  return true;
266220
266485
  }
266221
- function isInteractiveGeminiCommand(command) {
266222
- if (!command || !command.trim()) {
266223
- return false;
266224
- }
266486
+ function unwrapCommandForGeminiCheck(command) {
266225
266487
  let unwrapped = command.trim();
266226
266488
  for (let depth = 0; depth < 3; depth++) {
266227
266489
  const next = stripShellWrapper(unwrapped);
@@ -266230,10 +266492,59 @@ function isInteractiveGeminiCommand(command) {
266230
266492
  }
266231
266493
  unwrapped = next;
266232
266494
  }
266233
- const parsedSegments = splitCommands(unwrapped);
266495
+ return unwrapped;
266496
+ }
266497
+ var GEMINI_SUBSEQUENCE = "gemini";
266498
+ function containsGeminiSubsequence(input) {
266499
+ const lower = input.toLowerCase();
266500
+ let pos = 0;
266501
+ for (const ch of GEMINI_SUBSEQUENCE) {
266502
+ const found = lower.indexOf(ch, pos);
266503
+ if (found === -1) {
266504
+ return false;
266505
+ }
266506
+ pos = found + 1;
266507
+ }
266508
+ return true;
266509
+ }
266510
+ function isKnownInteractiveGeminiCommandSync(command) {
266511
+ if (!command || !command.trim()) {
266512
+ return false;
266513
+ }
266514
+ const unwrapped = unwrapCommandForGeminiCheck(command);
266515
+ if (!containsGeminiSubsequence(unwrapped)) {
266516
+ return false;
266517
+ }
266234
266518
  const fallbackSegments = splitShellCommandSegments(unwrapped);
266235
- const allSegments = parsedSegments.length > 0 ? [...parsedSegments, ...fallbackSegments] : fallbackSegments;
266236
- return allSegments.some((segment) => isInteractiveGeminiSegment(segment));
266519
+ if (fallbackSegments.some((segment) => isInteractiveGeminiSegment(segment))) {
266520
+ return true;
266521
+ }
266522
+ return void 0;
266523
+ }
266524
+ function isInteractiveGeminiCommand(command, cache2) {
266525
+ const fastResult = isKnownInteractiveGeminiCommandSync(command);
266526
+ if (fastResult !== void 0) {
266527
+ return fastResult;
266528
+ }
266529
+ const unwrapped = unwrapCommandForGeminiCheck(command);
266530
+ const parsedSegments = splitCommands(unwrapped, cache2);
266531
+ return parsedSegments.some((segment) => isInteractiveGeminiSegment(segment));
266532
+ }
266533
+ async function isInteractiveGeminiCommandAsync(command, cache2, signal) {
266534
+ if (signal?.aborted) {
266535
+ return false;
266536
+ }
266537
+ const fastResult = isKnownInteractiveGeminiCommandSync(command);
266538
+ if (fastResult !== void 0) {
266539
+ return fastResult;
266540
+ }
266541
+ const unwrapped = unwrapCommandForGeminiCheck(command);
266542
+ const parsedSegments = await splitCommandsAsync(unwrapped, cache2, signal);
266543
+ return parsedSegments.some((segment) => isInteractiveGeminiSegment(segment));
266544
+ }
266545
+ var defaultIsInteractiveGeminiCommandRef = isInteractiveGeminiCommand;
266546
+ function isDefaultIsInteractiveGeminiCommand(fn3) {
266547
+ return fn3 === defaultIsInteractiveGeminiCommandRef;
266237
266548
  }
266238
266549
 
266239
266550
  // packages/core/dist/src/sandbox/utils/commandSafety.js
@@ -266807,7 +267118,7 @@ async function isStrictlyApproved(command, args2, approvedTools, cwd, workspaceR
266807
267118
  await initializeShellParsers();
266808
267119
  const fullCmd = [command, ...args2].join(" ");
266809
267120
  const stripped = stripShellWrapper(fullCmd);
266810
- const pipelineCommands = splitCommands(stripped);
267121
+ const pipelineCommands = isDefaultSplitCommands(splitCommands) ? await splitCommandsAsync(stripped) : splitCommands(stripped);
266811
267122
  if (pipelineCommands.length === 0) {
266812
267123
  return tools.includes(command) || isKnownSafeCommand2([command, ...args2], cwd, workspaceRoot);
266813
267124
  }
@@ -267301,35 +267612,38 @@ async function isStrictlyApproved2(req, approvedTools) {
267301
267612
  if (!approvedTools || approvedTools.length === 0) {
267302
267613
  return false;
267303
267614
  }
267304
- await initializeShellParsers();
267305
- const fullCmd = [req.command, ...req.args].join(" ");
267306
- const stripped = stripShellWrapper(fullCmd);
267307
- const roots = getCommandRoots(stripped);
267308
- if (roots.length === 0)
267309
- return false;
267310
- const allRootsApproved = roots.every((root) => approvedTools.includes(root));
267311
- if (allRootsApproved) {
267312
- return true;
267313
- }
267314
- if (hasUnresolvedShellExpansion(stripped)) {
267315
- return false;
267316
- }
267317
- const pipelineCommands = splitCommands(stripped);
267318
- if (pipelineCommands.length === 0)
267319
- return false;
267320
- for (const cmdString of pipelineCommands) {
267321
- const parsedArgs = (0, import_shell_quote4.parse)(cmdString).map(String);
267322
- if (!isKnownSafeCommand(parsedArgs)) {
267615
+ return runWithCommandParseCache(async () => {
267616
+ await initializeShellParsers();
267617
+ const fullCmd = [req.command, ...req.args].join(" ");
267618
+ const stripped = stripShellWrapper(fullCmd);
267619
+ const roots = isDefaultGetCommandRoots(getCommandRoots) ? await getCommandRootsAsync(stripped) : getCommandRoots(stripped);
267620
+ if (roots.length === 0)
267323
267621
  return false;
267622
+ const allRootsApproved = roots.every((root) => approvedTools.includes(root));
267623
+ if (allRootsApproved) {
267624
+ return true;
267324
267625
  }
267325
- }
267326
- return true;
267626
+ if (hasUnresolvedShellExpansion(stripped)) {
267627
+ return false;
267628
+ }
267629
+ const pipelineCommands = isDefaultSplitCommands(splitCommands) ? await splitCommandsAsync(stripped) : splitCommands(stripped);
267630
+ if (pipelineCommands.length === 0)
267631
+ return false;
267632
+ for (const cmdString of pipelineCommands) {
267633
+ const parsedArgs = (0, import_shell_quote4.parse)(cmdString).map(String);
267634
+ if (!isKnownSafeCommand(parsedArgs)) {
267635
+ return false;
267636
+ }
267637
+ }
267638
+ return true;
267639
+ });
267327
267640
  }
267328
267641
  async function getCommandName2(req) {
267329
267642
  await initializeShellParsers();
267330
267643
  const fullCmd = [req.command, ...req.args].join(" ");
267331
267644
  const stripped = stripShellWrapper(fullCmd);
267332
- const roots = getCommandRoots(stripped).filter((r9) => r9 !== "shopt" && r9 !== "set");
267645
+ const computedRoots = isDefaultGetCommandRoots(getCommandRoots) ? await getCommandRootsAsync(stripped) : getCommandRoots(stripped);
267646
+ const roots = computedRoots.filter((r9) => r9 !== "shopt" && r9 !== "set");
267333
267647
  if (roots.length > 0) {
267334
267648
  return roots[0];
267335
267649
  }
@@ -268597,6 +268911,9 @@ var WindowsSandboxManager = class _WindowsSandboxManager {
268597
268911
  * Prepares a command for sandboxed execution on Windows.
268598
268912
  */
268599
268913
  async prepareCommand(req) {
268914
+ return runWithCommandParseCache(() => this.prepareCommandInternal(req));
268915
+ }
268916
+ async prepareCommandInternal(req) {
268600
268917
  await this.ensureHelperCompiled();
268601
268918
  const sanitizationConfig = getSecureSanitizationConfig(req.policy?.sanitizationConfig);
268602
268919
  const sanitizedEnv = sanitizeEnvironment(req.env, sanitizationConfig);
@@ -268631,7 +268948,8 @@ var WindowsSandboxManager = class _WindowsSandboxManager {
268631
268948
  await initializeShellParsers();
268632
268949
  const fullCmd = [command, ...args2].join(" ");
268633
268950
  const stripped = stripShellWrapper(fullCmd);
268634
- const roots = getCommandRoots(stripped).filter((r9) => r9 !== "shopt" && r9 !== "set");
268951
+ const computedRoots = isDefaultGetCommandRoots(getCommandRoots) ? await getCommandRootsAsync(stripped) : getCommandRoots(stripped);
268952
+ const roots = computedRoots.filter((r9) => r9 !== "shopt" && r9 !== "set");
268635
268953
  const isGitCommand = roots.includes("git");
268636
268954
  const resolvedPaths = await resolveSandboxPaths(this.options, req, mergedAdditional);
268637
268955
  this.ensureGovernanceFilesExist(resolvedPaths.workspace.resolved);
@@ -295062,8 +295380,8 @@ function isValidToolName(name3, options = {}) {
295062
295380
  }
295063
295381
 
295064
295382
  // packages/core/dist/src/generated/git-commit.js
295065
- var GIT_COMMIT_INFO = "7f51a3899";
295066
- var CLI_VERSION = "0.70.0";
295383
+ var GIT_COMMIT_INFO = "d4cb1713f";
295384
+ var CLI_VERSION = "0.71.0-nightly.20261120.gd4cb1713f";
295067
295385
 
295068
295386
  // packages/core/dist/src/ide/detect-ide.js
295069
295387
  var IDE_DEFINITIONS = {
@@ -327681,7 +327999,7 @@ function getVersion() {
327681
327999
  }
327682
328000
  versionPromise = (async () => {
327683
328001
  const pkgJson = await getPackageJson(__dirname4);
327684
- return "0.70.0";
328002
+ return "0.71.0-nightly.20261120.gd4cb1713f";
327685
328003
  })();
327686
328004
  return versionPromise;
327687
328005
  }
@@ -329537,8 +329855,8 @@ var BaseLlmClient = class {
329537
329855
  };
329538
329856
 
329539
329857
  // packages/core/dist/src/utils/promptIdContext.js
329540
- import { AsyncLocalStorage } from "node:async_hooks";
329541
- var promptIdContext = new AsyncLocalStorage();
329858
+ import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
329859
+ var promptIdContext = new AsyncLocalStorage2();
329542
329860
  function getPromptIdWithFallback(componentName) {
329543
329861
  const promptId = promptIdContext.getStore();
329544
329862
  if (promptId) {
@@ -330220,25 +330538,18 @@ function findUntrustedFlags(command, untrustedContext, options) {
330220
330538
  }
330221
330539
  return Array.from(detected);
330222
330540
  }
330223
- function isBuildOrTestCommand(command) {
330224
- if (!command) {
330225
- return false;
330226
- }
330541
+ function evaluateBuildOrTestCommandFromRoots(command, roots) {
330227
330542
  const getBaseName = (cmd) => {
330228
330543
  const base2 = cmd.replace(/\\/g, "/").split("/").pop();
330229
330544
  if (!base2)
330230
330545
  return cmd.toLowerCase();
330231
330546
  return base2.toLowerCase().replace(/\.(exe|cmd|bat)$/, "");
330232
330547
  };
330233
- try {
330234
- const roots = getCommandRoots(command);
330235
- if (roots.length > 0) {
330236
- return roots.some((root2) => {
330237
- const base2 = getBaseName(root2);
330238
- return BUILD_TEST_COMMAND_ROOTS.has(base2) || BUILD_TEST_COMMAND_ROOTS.has(root2.toLowerCase());
330239
- });
330240
- }
330241
- } catch {
330548
+ if (roots.length > 0) {
330549
+ return roots.some((root2) => {
330550
+ const base2 = getBaseName(root2);
330551
+ return BUILD_TEST_COMMAND_ROOTS.has(base2) || BUILD_TEST_COMMAND_ROOTS.has(root2.toLowerCase());
330552
+ });
330242
330553
  }
330243
330554
  const parts2 = command.trim().split(/\s+/);
330244
330555
  let rootIndex = 0;
@@ -330251,18 +330562,33 @@ function isBuildOrTestCommand(command) {
330251
330562
  const base = getBaseName(root);
330252
330563
  return BUILD_TEST_COMMAND_ROOTS.has(base) || BUILD_TEST_COMMAND_ROOTS.has(root.toLowerCase());
330253
330564
  }
330254
- function isRemoteContentCommand(command) {
330565
+ function isBuildOrTestCommand(command) {
330255
330566
  if (!command) {
330256
330567
  return false;
330257
330568
  }
330258
330569
  let roots = [];
330259
330570
  try {
330260
- roots = getCommandRoots(command).map((root) => normalizeCommand(root));
330571
+ roots = getCommandRoots(command);
330261
330572
  } catch {
330262
330573
  }
330574
+ return evaluateBuildOrTestCommandFromRoots(command, roots);
330575
+ }
330576
+ function evaluateRemoteContentCommandFromRoots(command, rawRoots) {
330577
+ const roots = rawRoots.map((root) => normalizeCommand(root));
330263
330578
  const candidates = roots.length === 0 || roots.some((root) => COMMAND_WRAPPER_ROOTS.has(root)) ? command.trim().split(/[\s;&|()]+/).map((word) => normalizeCommand(word)) : roots;
330264
330579
  return candidates.some((name3) => REMOTE_CONTENT_COMMAND_ROOTS.has(name3));
330265
330580
  }
330581
+ async function isRemoteContentCommandAsync(command) {
330582
+ if (!command) {
330583
+ return false;
330584
+ }
330585
+ let rawRoots = [];
330586
+ try {
330587
+ rawRoots = isDefaultGetCommandRoots(getCommandRoots) ? await getCommandRootsAsync(command) : getCommandRoots(command);
330588
+ } catch {
330589
+ }
330590
+ return evaluateRemoteContentCommandFromRoots(command, rawRoots);
330591
+ }
330266
330592
  var MODIFIED_BUILD_FILES_SYMBOL = Symbol("sessionModifiedBuildFiles");
330267
330593
  var ACKNOWLEDGED_UNTRUSTED_FLAGS_SYMBOL = Symbol("sessionAcknowledgedUntrustedFlags");
330268
330594
  function hasSessionRecord(sessionKey) {
@@ -334506,7 +334832,7 @@ function canNegationMatchInsideDir(dir, negations) {
334506
334832
  }
334507
334833
  return false;
334508
334834
  }
334509
- function expandWildcardDirectoryPatterns(rawPatterns, extraRawPatterns) {
334835
+ function expandWildcardDirectoryPatterns(rawPatterns, extraRawPatterns, hasNestedNegation) {
334510
334836
  const negations = /* @__PURE__ */ new Set();
334511
334837
  const allPatternSources = extraRawPatterns ? [...rawPatterns, ...extraRawPatterns] : rawPatterns;
334512
334838
  for (const p2 of allPatternSources) {
@@ -334532,7 +334858,7 @@ function expandWildcardDirectoryPatterns(rawPatterns, extraRawPatterns) {
334532
334858
  if (withoutGlob === "" || withoutGlob.includes("*") || withoutGlob.includes("?") || withoutGlob.includes("[")) {
334533
334859
  continue;
334534
334860
  }
334535
- if (!canNegationMatchInsideDir(withoutGlob, negations)) {
334861
+ if (!canNegationMatchInsideDir(withoutGlob, negations) && !hasNestedNegation?.(withoutGlob)) {
334536
334862
  expanded.push(`/${withoutGlob}/`);
334537
334863
  }
334538
334864
  }
@@ -334576,7 +334902,35 @@ var GitIgnoreParser = class {
334576
334902
  return this.processPatterns(rawPatterns, relativeBaseDir);
334577
334903
  }
334578
334904
  processPatterns(rawPatterns, relativeBaseDir) {
334579
- const expandedPatterns = expandWildcardDirectoryPatterns(rawPatterns, this.extraPatterns);
334905
+ const checkedDirs = /* @__PURE__ */ new Map();
334906
+ const hasNestedNegation = (dir) => {
334907
+ let result = checkedDirs.get(dir);
334908
+ if (result !== void 0) {
334909
+ return result;
334910
+ }
334911
+ const targetRelDir = relativeBaseDir && relativeBaseDir !== "." ? path49.posix.join(relativeBaseDir, dir) : dir;
334912
+ const gitignorePath = path49.resolve(this.projectRoot, targetRelDir, ".gitignore");
334913
+ if (!isWithinRoot(gitignorePath, this.projectRoot)) {
334914
+ checkedDirs.set(dir, false);
334915
+ return false;
334916
+ }
334917
+ try {
334918
+ const content = fs41.readFileSync(gitignorePath, "utf-8");
334919
+ result = false;
334920
+ for (const line of content.split(/\r\n|\n|\r/)) {
334921
+ const trimmed = line.trim();
334922
+ if (trimmed.startsWith("!") && trimmed.slice(1).trim() !== "") {
334923
+ result = true;
334924
+ break;
334925
+ }
334926
+ }
334927
+ } catch {
334928
+ result = false;
334929
+ }
334930
+ checkedDirs.set(dir, result);
334931
+ return result;
334932
+ };
334933
+ const expandedPatterns = expandWildcardDirectoryPatterns(rawPatterns, this.extraPatterns, hasNestedNegation);
334580
334934
  return expandedPatterns.map((p2) => p2.trimStart()).filter((p2) => p2 !== "" && !p2.startsWith("#")).map((p2) => {
334581
334935
  const isNegative = p2.startsWith("!");
334582
334936
  if (isNegative) {
@@ -342955,8 +343309,8 @@ ${truncated}`;
342955
343309
  };
342956
343310
 
342957
343311
  // packages/core/dist/src/utils/toolCallContext.js
342958
- import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
342959
- var toolCallContext = new AsyncLocalStorage2();
343312
+ import { AsyncLocalStorage as AsyncLocalStorage3 } from "node:async_hooks";
343313
+ var toolCallContext = new AsyncLocalStorage3();
342960
343314
  function runWithToolCallContext(context2, fn3) {
342961
343315
  return toolCallContext.run(context2, fn3);
342962
343316
  }
@@ -343115,10 +343469,51 @@ var ShellToolInvocation = class extends BaseToolInvocation {
343115
343469
  context;
343116
343470
  proactivePermissionsConfirmed;
343117
343471
  confirmedCommand;
343472
+ parseCache = new CommandParseCache();
343118
343473
  constructor(context2, params, messageBus, _toolName, _toolDisplayName) {
343119
343474
  super(params, messageBus, _toolName, _toolDisplayName);
343120
343475
  this.context = context2;
343121
343476
  }
343477
+ runInCommandParseCache(fn3) {
343478
+ return runWithCommandParseCache(fn3, this.parseCache);
343479
+ }
343480
+ async prepareCommandParseCache(signal) {
343481
+ if (signal?.aborted || typeof stripShellWrapper !== "function" || !isDefaultParseCommandDetails(parseCommandDetails)) {
343482
+ return;
343483
+ }
343484
+ const rawCommand = this.params.command;
343485
+ const stripped = stripShellWrapper(rawCommand);
343486
+ let unwrapped = stripped;
343487
+ for (let depth = 0; depth < 3; depth++) {
343488
+ const next = stripShellWrapper(unwrapped);
343489
+ if (next === unwrapped) {
343490
+ break;
343491
+ }
343492
+ unwrapped = next;
343493
+ }
343494
+ await parseCommandDetailsAsync(stripped, this.parseCache, signal);
343495
+ if (unwrapped !== stripped && !signal?.aborted) {
343496
+ await parseCommandDetailsAsync(unwrapped, this.parseCache, signal);
343497
+ }
343498
+ }
343499
+ hasCachedCommandParse(command) {
343500
+ if (typeof getShellConfiguration !== "function") {
343501
+ return false;
343502
+ }
343503
+ const configuration = getShellConfiguration();
343504
+ if (configuration.shell !== "powershell") {
343505
+ return true;
343506
+ }
343507
+ let unwrapped = command.trim();
343508
+ for (let depth = 0; depth < 3; depth++) {
343509
+ const next = stripShellWrapper(unwrapped);
343510
+ if (next === unwrapped) {
343511
+ break;
343512
+ }
343513
+ unwrapped = next;
343514
+ }
343515
+ return this.parseCache.hasCompleted(configuration.executable, command) && this.parseCache.hasCompleted(configuration.executable, unwrapped);
343516
+ }
343122
343517
  /**
343123
343518
  * Wraps a command in a subshell to capture background process IDs (PIDs)
343124
343519
  * using an EXIT trap. Uses newlines to prevent breaking heredocs or trailing
@@ -343278,185 +343673,200 @@ exit $__code`;
343278
343673
  return getUnacknowledgedUntrustedFlags(untrustedFlags, roots, config2);
343279
343674
  }
343280
343675
  hasTaintedOrBuildFileRisk() {
343281
- const command = stripShellWrapper(this.params.command);
343282
- const untrustedFlags = this.getUntrustedFlags(command);
343283
- const modifiedBuildFiles = getModifiedBuildFiles(this.context.config);
343284
- const isBuildCmd = isBuildOrTestCommand(command);
343285
- return untrustedFlags.length > 0 || isBuildCmd && modifiedBuildFiles.length > 0;
343676
+ return this.runInCommandParseCache(() => {
343677
+ const command = stripShellWrapper(this.params.command);
343678
+ const untrustedFlags = this.getUntrustedFlags(command);
343679
+ const modifiedBuildFiles = getModifiedBuildFiles(this.context.config);
343680
+ const isBuildCmd = isBuildOrTestCommand(command);
343681
+ return untrustedFlags.length > 0 || isBuildCmd && modifiedBuildFiles.length > 0;
343682
+ });
343286
343683
  }
343287
343684
  getPolicyUpdateOptions(outcome) {
343288
- if (outcome === ToolConfirmationOutcome.ProceedAlwaysAndSave || outcome === ToolConfirmationOutcome.ProceedAlways) {
343289
- const command = stripShellWrapper(this.params.command);
343290
- if (this.hasTaintedOrBuildFileRisk()) {
343291
- return void 0;
343292
- }
343293
- const rootCommands = [...new Set(getCommandRoots(command))];
343294
- const allowRedirection = hasRedirection(command) ? true : void 0;
343295
- const allowCommandSubstitution = detectCommandSubstitution(command) ? true : void 0;
343296
- if (rootCommands.length > 0) {
343685
+ return this.runInCommandParseCache(() => {
343686
+ if (outcome === ToolConfirmationOutcome.ProceedAlwaysAndSave || outcome === ToolConfirmationOutcome.ProceedAlways) {
343687
+ const command = stripShellWrapper(this.params.command);
343688
+ if (this.hasTaintedOrBuildFileRisk()) {
343689
+ return void 0;
343690
+ }
343691
+ const rootCommands = [...new Set(getCommandRoots(command))];
343692
+ const allowRedirection = hasRedirection(command) ? true : void 0;
343693
+ const allowCommandSubstitution = detectCommandSubstitution(command) ? true : void 0;
343694
+ if (rootCommands.length > 0) {
343695
+ return {
343696
+ commandPrefix: rootCommands,
343697
+ allowRedirection,
343698
+ ...allowCommandSubstitution !== void 0 ? { allowCommandSubstitution } : {}
343699
+ };
343700
+ }
343297
343701
  return {
343298
- commandPrefix: rootCommands,
343702
+ commandPrefix: this.params.command,
343299
343703
  allowRedirection,
343300
343704
  ...allowCommandSubstitution !== void 0 ? { allowCommandSubstitution } : {}
343301
343705
  };
343302
343706
  }
343303
- return {
343304
- commandPrefix: this.params.command,
343305
- allowRedirection,
343306
- ...allowCommandSubstitution !== void 0 ? { allowCommandSubstitution } : {}
343307
- };
343308
- }
343309
- return void 0;
343707
+ return void 0;
343708
+ });
343310
343709
  }
343311
343710
  async shouldConfirmExecute(abortSignal, forcedDecision) {
343312
- if (isInteractiveGeminiCommand(stripShellWrapper(this.params.command))) {
343313
- return false;
343314
- }
343315
- if (forcedDecision === "deny") {
343316
- return super.shouldConfirmExecute(abortSignal, forcedDecision);
343317
- }
343318
- if (this.hasTaintedOrBuildFileRisk()) {
343319
- return this.getConfirmationDetails(abortSignal);
343320
- }
343321
- if (this.context.config.getApprovalMode() === ApprovalMode.YOLO && forcedDecision !== "ask_user") {
343322
- return super.shouldConfirmExecute(abortSignal, forcedDecision);
343323
- }
343324
- if (this.params[PARAM_ADDITIONAL_PERMISSIONS]) {
343325
- return this.getConfirmationDetails(abortSignal);
343326
- }
343327
- if (this.context.config.getSandboxEnabled()) {
343328
- const command = stripShellWrapper(this.params.command);
343329
- const rootCommands = getCommandRoots(command);
343330
- const rawRootCommand = rootCommands[0];
343331
- if (rawRootCommand) {
343332
- const rootCommand = normalizeCommand(rawRootCommand);
343333
- const proactive = await getProactiveToolSuggestions(rootCommand);
343334
- if (proactive) {
343335
- const mode = this.context.config.getApprovalMode();
343336
- const modeConfig = this.context.config.sandboxPolicyManager.getModeConfig(mode);
343337
- const approved = this.context.config.sandboxPolicyManager.getCommandPermissions(rootCommand);
343338
- const hasNetwork = modeConfig.network || approved.network;
343339
- const missingNetwork = !!proactive.network && !hasNetwork;
343340
- const parsed = parseCommandDetails(command);
343341
- const subCommand = parsed?.details[0]?.args?.[0];
343342
- const needsNetwork = isNetworkReliantCommand(rootCommand, subCommand);
343343
- if (needsNetwork) {
343344
- const isReadonlyMode = modeConfig.readonly ?? false;
343345
- if (isReadonlyMode) {
343346
- const cwd = this.params.dir_path || this.context.config.getTargetDir();
343347
- proactive.fileSystem = proactive.fileSystem || {
343348
- read: [],
343349
- write: []
343350
- };
343351
- proactive.fileSystem.write = proactive.fileSystem.write || [];
343352
- if (!proactive.fileSystem.write.includes(cwd)) {
343353
- proactive.fileSystem.write.push(cwd);
343354
- proactive.fileSystem.read = proactive.fileSystem.read || [];
343355
- if (!proactive.fileSystem.read.includes(cwd)) {
343356
- proactive.fileSystem.read.push(cwd);
343711
+ return this.runInCommandParseCache(async () => {
343712
+ await this.prepareCommandParseCache(abortSignal);
343713
+ const strippedForInteractiveCheck = stripShellWrapper(this.params.command);
343714
+ const isInteractive = isDefaultIsInteractiveGeminiCommand(isInteractiveGeminiCommand) ? await isInteractiveGeminiCommandAsync(strippedForInteractiveCheck, this.parseCache, abortSignal) : isInteractiveGeminiCommand(strippedForInteractiveCheck);
343715
+ if (isInteractive) {
343716
+ return false;
343717
+ }
343718
+ if (forcedDecision === "deny") {
343719
+ return super.shouldConfirmExecute(abortSignal, forcedDecision);
343720
+ }
343721
+ if (this.hasTaintedOrBuildFileRisk()) {
343722
+ return this.getConfirmationDetails(abortSignal);
343723
+ }
343724
+ if (this.context.config.getApprovalMode() === ApprovalMode.YOLO && forcedDecision !== "ask_user") {
343725
+ return super.shouldConfirmExecute(abortSignal, forcedDecision);
343726
+ }
343727
+ if (this.params[PARAM_ADDITIONAL_PERMISSIONS]) {
343728
+ return this.getConfirmationDetails(abortSignal);
343729
+ }
343730
+ if (this.context.config.getSandboxEnabled()) {
343731
+ const command = stripShellWrapper(this.params.command);
343732
+ const rootCommands = isDefaultGetCommandRoots(getCommandRoots) ? await getCommandRootsAsync(command, this.parseCache, abortSignal) : getCommandRoots(command);
343733
+ const rawRootCommand = rootCommands[0];
343734
+ if (rawRootCommand) {
343735
+ const rootCommand = normalizeCommand(rawRootCommand);
343736
+ const proactive = await getProactiveToolSuggestions(rootCommand);
343737
+ if (proactive) {
343738
+ const mode = this.context.config.getApprovalMode();
343739
+ const modeConfig = this.context.config.sandboxPolicyManager.getModeConfig(mode);
343740
+ const approved = this.context.config.sandboxPolicyManager.getCommandPermissions(rootCommand);
343741
+ const hasNetwork = modeConfig.network || approved.network;
343742
+ const missingNetwork = !!proactive.network && !hasNetwork;
343743
+ const parsed = isDefaultParseCommandDetails(parseCommandDetails) ? await parseCommandDetailsAsync(command, this.parseCache, abortSignal) : parseCommandDetails(command);
343744
+ const subCommand = parsed?.details[0]?.args?.[0];
343745
+ const needsNetwork = isNetworkReliantCommand(rootCommand, subCommand);
343746
+ if (needsNetwork) {
343747
+ const isReadonlyMode = modeConfig.readonly ?? false;
343748
+ if (isReadonlyMode) {
343749
+ const cwd = this.params.dir_path || this.context.config.getTargetDir();
343750
+ proactive.fileSystem = proactive.fileSystem || {
343751
+ read: [],
343752
+ write: []
343753
+ };
343754
+ proactive.fileSystem.write = proactive.fileSystem.write || [];
343755
+ if (!proactive.fileSystem.write.includes(cwd)) {
343756
+ proactive.fileSystem.write.push(cwd);
343757
+ proactive.fileSystem.read = proactive.fileSystem.read || [];
343758
+ if (!proactive.fileSystem.read.includes(cwd)) {
343759
+ proactive.fileSystem.read.push(cwd);
343760
+ }
343357
343761
  }
343358
343762
  }
343359
- }
343360
- const isApproved = (requestedPath, approvedPaths) => {
343361
- if (!approvedPaths || approvedPaths.length === 0)
343362
- return false;
343363
- const requestedRealIdentity = toPathKey(resolveToRealPath(requestedPath));
343364
- return approvedPaths.some((p2) => {
343365
- const approvedRealIdentity = toPathKey(resolveToRealPath(p2));
343366
- return requestedRealIdentity === approvedRealIdentity || isSubpath(approvedRealIdentity, requestedRealIdentity);
343367
- });
343368
- };
343369
- const missingRead = (proactive.fileSystem?.read || []).filter((p2) => !isApproved(p2, approved.fileSystem?.read));
343370
- const missingWrite = (proactive.fileSystem?.write || []).filter((p2) => !isApproved(p2, approved.fileSystem?.write));
343371
- const needsExpansion = missingRead.length > 0 || missingWrite.length > 0 || missingNetwork;
343372
- if (needsExpansion) {
343373
- const details = await this.getConfirmationDetails(abortSignal, proactive);
343374
- if (details && details.type === "sandbox_expansion") {
343375
- const originalOnConfirm = details.onConfirm;
343376
- details.onConfirm = async (outcome) => {
343377
- await originalOnConfirm(outcome);
343378
- if (outcome !== ToolConfirmationOutcome.Cancel) {
343379
- this.proactivePermissionsConfirmed = proactive;
343380
- }
343381
- };
343763
+ const isApproved = (requestedPath, approvedPaths) => {
343764
+ if (!approvedPaths || approvedPaths.length === 0)
343765
+ return false;
343766
+ const requestedRealIdentity = toPathKey(resolveToRealPath(requestedPath));
343767
+ return approvedPaths.some((p2) => {
343768
+ const approvedRealIdentity = toPathKey(resolveToRealPath(p2));
343769
+ return requestedRealIdentity === approvedRealIdentity || isSubpath(approvedRealIdentity, requestedRealIdentity);
343770
+ });
343771
+ };
343772
+ const missingRead = (proactive.fileSystem?.read || []).filter((p2) => !isApproved(p2, approved.fileSystem?.read));
343773
+ const missingWrite = (proactive.fileSystem?.write || []).filter((p2) => !isApproved(p2, approved.fileSystem?.write));
343774
+ const needsExpansion = missingRead.length > 0 || missingWrite.length > 0 || missingNetwork;
343775
+ if (needsExpansion) {
343776
+ const details = await this.getConfirmationDetails(abortSignal, proactive);
343777
+ if (details && details.type === "sandbox_expansion") {
343778
+ const originalOnConfirm = details.onConfirm;
343779
+ details.onConfirm = async (outcome) => {
343780
+ await originalOnConfirm(outcome);
343781
+ if (outcome !== ToolConfirmationOutcome.Cancel) {
343782
+ this.proactivePermissionsConfirmed = proactive;
343783
+ }
343784
+ };
343785
+ }
343786
+ return details;
343382
343787
  }
343383
- return details;
343384
343788
  }
343385
343789
  }
343386
343790
  }
343387
343791
  }
343388
- }
343389
- return super.shouldConfirmExecute(abortSignal, forcedDecision);
343792
+ return super.shouldConfirmExecute(abortSignal, forcedDecision);
343793
+ });
343390
343794
  }
343391
- async getConfirmationDetails(_abortSignal, proactivePermissions) {
343392
- const command = stripShellWrapper(this.params.command);
343393
- const parsed = parseCommandDetails(command);
343394
- let rootCommandDisplay = "";
343395
- if (!parsed || parsed.hasError || parsed.details.length === 0) {
343396
- const fallback = command.trim().split(/\s+/)[0];
343397
- rootCommandDisplay = fallback || "shell command";
343398
- if (hasRedirection(command)) {
343399
- rootCommandDisplay += ", redirection";
343795
+ async getConfirmationDetails(abortSignal, proactivePermissions) {
343796
+ return this.runInCommandParseCache(async () => {
343797
+ const command = stripShellWrapper(this.params.command);
343798
+ const parsed = isDefaultParseCommandDetails(parseCommandDetails) ? await parseCommandDetailsAsync(command, this.parseCache, abortSignal) : parseCommandDetails(command);
343799
+ const commandHasRedirection = isDefaultHasRedirection(hasRedirection) ? await hasRedirectionAsync(command, this.parseCache, abortSignal) : hasRedirection(command);
343800
+ let rootCommandDisplay = "";
343801
+ if (!parsed || parsed.hasError || parsed.details.length === 0) {
343802
+ const fallback = command.trim().split(/\s+/)[0];
343803
+ rootCommandDisplay = fallback || "shell command";
343804
+ if (commandHasRedirection) {
343805
+ rootCommandDisplay += ", redirection";
343806
+ }
343807
+ } else {
343808
+ rootCommandDisplay = parsed.details.map((detail) => detail.name).join(", ");
343400
343809
  }
343401
- } else {
343402
- rootCommandDisplay = parsed.details.map((detail) => detail.name).join(", ");
343403
- }
343404
- let rootCommands = [];
343405
- try {
343406
- rootCommands = [...new Set(getCommandRoots(command))];
343407
- } catch {
343408
- rootCommands = [command.trim().split(/\s+/)[0] || "shell"];
343409
- }
343410
- const rootCommand = rootCommands[0] || "shell";
343411
- const untrustedFlags = this.getUntrustedFlags(command);
343412
- const modifiedBuildFiles = getModifiedBuildFiles(this.context.config);
343413
- const isBuildCmd = isBuildOrTestCommand(command);
343414
- const hasSecurityWarning = untrustedFlags.length > 0 || isBuildCmd && modifiedBuildFiles.length > 0;
343415
- const effectiveAdditionalPermissions = this.params[PARAM_ADDITIONAL_PERMISSIONS] || proactivePermissions;
343416
- if (effectiveAdditionalPermissions && !hasSecurityWarning) {
343417
- return {
343418
- type: "sandbox_expansion",
343419
- title: proactivePermissions ? "Sandbox Expansion Request (Recommended)" : "Sandbox Expansion Request",
343810
+ let rootCommands = [];
343811
+ try {
343812
+ const computedRoots = isDefaultGetCommandRoots(getCommandRoots) ? await getCommandRootsAsync(command, this.parseCache, abortSignal) : getCommandRoots(command);
343813
+ rootCommands = [...new Set(computedRoots)];
343814
+ } catch {
343815
+ rootCommands = [command.trim().split(/\s+/)[0] || "shell"];
343816
+ }
343817
+ const rootCommand = rootCommands[0] || "shell";
343818
+ const untrustedFlags = this.getUntrustedFlags(command);
343819
+ const modifiedBuildFiles = getModifiedBuildFiles(this.context.config);
343820
+ const isBuildCmd = isBuildOrTestCommand(command);
343821
+ const hasSecurityWarning = untrustedFlags.length > 0 || isBuildCmd && modifiedBuildFiles.length > 0;
343822
+ const effectiveAdditionalPermissions = this.params[PARAM_ADDITIONAL_PERMISSIONS] || proactivePermissions;
343823
+ if (effectiveAdditionalPermissions && !hasSecurityWarning) {
343824
+ return {
343825
+ type: "sandbox_expansion",
343826
+ title: proactivePermissions ? "Sandbox Expansion Request (Recommended)" : "Sandbox Expansion Request",
343827
+ command: this.params.command,
343828
+ rootCommand: rootCommandDisplay,
343829
+ additionalPermissions: effectiveAdditionalPermissions,
343830
+ onConfirm: async (outcome) => {
343831
+ if (outcome !== ToolConfirmationOutcome.Cancel && outcome !== ToolConfirmationOutcome.ModifyWithEditor) {
343832
+ this.confirmedCommand = this.params.command;
343833
+ }
343834
+ if (outcome === ToolConfirmationOutcome.ProceedAlwaysAndSave) {
343835
+ this.context.config.sandboxPolicyManager.addPersistentApproval(rootCommand, effectiveAdditionalPermissions);
343836
+ } else if (outcome === ToolConfirmationOutcome.ProceedAlways) {
343837
+ this.context.config.sandboxPolicyManager.addSessionApproval(rootCommand, effectiveAdditionalPermissions);
343838
+ }
343839
+ }
343840
+ };
343841
+ }
343842
+ const confirmationDetails = {
343843
+ type: "exec",
343844
+ title: "Confirm Shell Command",
343420
343845
  command: this.params.command,
343421
343846
  rootCommand: rootCommandDisplay,
343422
- additionalPermissions: effectiveAdditionalPermissions,
343847
+ rootCommands,
343848
+ hasRedirection: commandHasRedirection,
343849
+ untrustedFlags: untrustedFlags.length > 0 ? untrustedFlags : void 0,
343850
+ modifiedBuildFiles: isBuildCmd && modifiedBuildFiles.length > 0 ? modifiedBuildFiles : void 0,
343423
343851
  onConfirm: async (outcome) => {
343424
- if (outcome !== ToolConfirmationOutcome.Cancel && outcome !== ToolConfirmationOutcome.ModifyWithEditor) {
343425
- this.confirmedCommand = this.params.command;
343852
+ if (outcome === ToolConfirmationOutcome.Cancel || outcome === ToolConfirmationOutcome.ModifyWithEditor) {
343853
+ return;
343426
343854
  }
343427
- if (outcome === ToolConfirmationOutcome.ProceedAlwaysAndSave) {
343428
- this.context.config.sandboxPolicyManager.addPersistentApproval(rootCommand, effectiveAdditionalPermissions);
343429
- } else if (outcome === ToolConfirmationOutcome.ProceedAlways) {
343430
- this.context.config.sandboxPolicyManager.addSessionApproval(rootCommand, effectiveAdditionalPermissions);
343855
+ this.confirmedCommand = this.params.command;
343856
+ acknowledgeUntrustedFlags(untrustedFlags, rootCommands, this.context.config);
343857
+ if (isBuildCmd && modifiedBuildFiles.length > 0) {
343858
+ resetModifiedBuildFiles(this.context.config);
343431
343859
  }
343432
343860
  }
343433
343861
  };
343434
- }
343435
- const confirmationDetails = {
343436
- type: "exec",
343437
- title: "Confirm Shell Command",
343438
- command: this.params.command,
343439
- rootCommand: rootCommandDisplay,
343440
- rootCommands,
343441
- untrustedFlags: untrustedFlags.length > 0 ? untrustedFlags : void 0,
343442
- modifiedBuildFiles: isBuildCmd && modifiedBuildFiles.length > 0 ? modifiedBuildFiles : void 0,
343443
- onConfirm: async (outcome) => {
343444
- if (outcome === ToolConfirmationOutcome.Cancel || outcome === ToolConfirmationOutcome.ModifyWithEditor) {
343445
- return;
343446
- }
343447
- this.confirmedCommand = this.params.command;
343448
- acknowledgeUntrustedFlags(untrustedFlags, rootCommands, this.context.config);
343449
- if (isBuildCmd && modifiedBuildFiles.length > 0) {
343450
- resetModifiedBuildFiles(this.context.config);
343451
- }
343452
- }
343453
- };
343454
- return confirmationDetails;
343862
+ return confirmationDetails;
343863
+ });
343455
343864
  }
343456
343865
  async isCommandSubstitutionAllowed(options) {
343457
343866
  if ((options.isClientInitiated ?? false) || (options.isUserConfirmed ?? false) || this.confirmedCommand === this.params.command) {
343458
343867
  return true;
343459
343868
  }
343869
+ await this.prepareCommandParseCache(options.abortSignal);
343460
343870
  if (this.hasTaintedOrBuildFileRisk()) {
343461
343871
  return false;
343462
343872
  }
@@ -343472,9 +343882,21 @@ exit $__code`;
343472
343882
  return this.context.config?.getApprovalMode?.() === ApprovalMode.YOLO;
343473
343883
  }
343474
343884
  async execute(options) {
343885
+ return this.runInCommandParseCache(() => this.executeInternal(options));
343886
+ }
343887
+ async executeInternal(options) {
343475
343888
  const { abortSignal: signal, updateOutput, shellExecutionConfig, setExecutionIdCallback } = options;
343476
343889
  const strippedCommand = stripShellWrapper(this.params.command);
343477
- if (isInteractiveGeminiCommand(strippedCommand)) {
343890
+ let isInteractiveGemini;
343891
+ if (!isDefaultIsInteractiveGeminiCommand(isInteractiveGeminiCommand)) {
343892
+ isInteractiveGemini = isInteractiveGeminiCommand(strippedCommand);
343893
+ } else if (this.hasCachedCommandParse(strippedCommand)) {
343894
+ isInteractiveGemini = isInteractiveGeminiCommand(strippedCommand, this.parseCache);
343895
+ } else {
343896
+ const knownInteractive = isKnownInteractiveGeminiCommandSync(strippedCommand);
343897
+ isInteractiveGemini = knownInteractive ?? await isInteractiveGeminiCommandAsync(strippedCommand, this.parseCache, signal);
343898
+ }
343899
+ if (isInteractiveGemini) {
343478
343900
  return {
343479
343901
  llmContent: INTERACTIVE_GEMINI_SHELL_ERROR,
343480
343902
  returnDisplay: INTERACTIVE_GEMINI_SHELL_ERROR,
@@ -343812,7 +344234,8 @@ ${result.output}`;
343812
344234
  const sandboxDenial = this.context.config.sandboxManager.parseDenials(result);
343813
344235
  if (sandboxDenial) {
343814
344236
  const strippedCommand2 = stripShellWrapper(this.params.command);
343815
- const rootCommands = getCommandRoots(strippedCommand2).filter((r9) => r9 !== "shopt");
344237
+ const computedRootCommands = isDefaultGetCommandRoots(getCommandRoots) ? await getCommandRootsAsync(strippedCommand2, this.parseCache) : getCommandRoots(strippedCommand2);
344238
+ const rootCommands = computedRootCommands.filter((r9) => r9 !== "shopt");
343816
344239
  const rootCommandDisplay = rootCommands.length > 0 ? rootCommands[0] : "shell";
343817
344240
  const readPaths = new Set(this.params[PARAM_ADDITIONAL_PERMISSIONS]?.fileSystem?.read || []);
343818
344241
  const writePaths = new Set(this.params[PARAM_ADDITIONAL_PERMISSIONS]?.fileSystem?.write || []);
@@ -343900,7 +344323,7 @@ ${result.output}`;
343900
344323
  }
343901
344324
  }
343902
344325
  const summarizeConfig = this.context.config.getSummarizeToolOutputConfig();
343903
- const outputSource = isRemoteContentCommand(strippedCommand) ? REMOTE_SHELL_OUTPUT_SOURCE : void 0;
344326
+ const outputSource = await isRemoteContentCommandAsync(strippedCommand) ? REMOTE_SHELL_OUTPUT_SOURCE : void 0;
343904
344327
  const executionError = result.error ? {
343905
344328
  error: {
343906
344329
  message: result.error.message,
@@ -360317,7 +360740,7 @@ var A2AAuthProviderFactory = class _A2AAuthProviderFactory {
360317
360740
  return provider;
360318
360741
  }
360319
360742
  case "oauth2": {
360320
- const { OAuth2AuthProvider } = await import("./oauth2-provider-SFFQQ6OE.js");
360743
+ const { OAuth2AuthProvider } = await import("./oauth2-provider-DWO2KVCY.js");
360321
360744
  const provider = new OAuth2AuthProvider(authConfig, options.agentName ?? "unknown", agentCard, options.agentCardUrl);
360322
360745
  await provider.initialize();
360323
360746
  return provider;
@@ -362026,6 +362449,9 @@ function isAutoEditTransition(tool, outcome) {
362026
362449
  }
362027
362450
  async function handleStandardPolicyUpdate(tool, outcome, confirmationDetails, messageBus, persistScope, toolInvocation, config2, modes) {
362028
362451
  if (outcome === ToolConfirmationOutcome.ProceedAlways || outcome === ToolConfirmationOutcome.ProceedAlwaysAndSave) {
362452
+ if (typeof toolInvocation === "object" && toolInvocation !== null && "prepareCommandParseCache" in toolInvocation && typeof toolInvocation.prepareCommandParseCache === "function") {
362453
+ await toolInvocation.prepareCommandParseCache();
362454
+ }
362029
362455
  const options = toolInvocation?.getPolicyUpdateOptions?.(outcome) || {};
362030
362456
  if (!options.commandPrefix && confirmationDetails?.type === "exec") {
362031
362457
  options.commandPrefix = confirmationDetails.rootCommands;
@@ -367722,6 +368148,15 @@ var ToolModificationHandler = class {
367722
368148
  };
367723
368149
 
367724
368150
  // packages/core/dist/src/scheduler/scheduler.js
368151
+ function isCommandParseCacheAware(invocation) {
368152
+ return typeof invocation === "object" && invocation !== null && "runInCommandParseCache" in invocation && typeof invocation.runInCommandParseCache === "function" && "prepareCommandParseCache" in invocation && typeof invocation.prepareCommandParseCache === "function";
368153
+ }
368154
+ function runWithInvocationParseCache(invocation, fn3) {
368155
+ if (isCommandParseCacheAware(invocation)) {
368156
+ return invocation.runInCommandParseCache(fn3);
368157
+ }
368158
+ return runWithCommandParseCache(fn3);
368159
+ }
367725
368160
  function isTaintRiskDetectable(invocation) {
367726
368161
  return typeof invocation === "object" && invocation !== null && "hasTaintedOrBuildFileRisk" in invocation && typeof invocation.hasTaintedOrBuildFileRisk === "function";
367727
368162
  }
@@ -368085,57 +368520,62 @@ var Scheduler = class {
368085
368520
  toolCall.request.inputModifiedByHook = true;
368086
368521
  toolCall.invocation = newInvocation;
368087
368522
  }
368088
- const { decision: policyDecision, rule } = await checkPolicy(toolCall, this.config, this.subagent);
368089
- let decision = policyDecision;
368090
- if (hookDecision === "ask") {
368091
- decision = PolicyDecision.ASK_USER;
368092
- }
368093
- const hasTaintRisk = isTaintRiskDetectable(toolCall.invocation) && toolCall.invocation.hasTaintedOrBuildFileRisk();
368094
- if (decision === PolicyDecision.ALLOW && hasTaintRisk) {
368095
- decision = this.config.isInteractive?.() ?? true ? PolicyDecision.ASK_USER : PolicyDecision.DENY;
368096
- }
368097
- if (decision === PolicyDecision.DENY) {
368098
- const { errorMessage, errorType } = getPolicyDenialError(this.config, rule);
368099
- this.state.updateStatus(callId, CoreToolCallStatus.Error, createErrorResponse(toolCall.request, new Error(errorMessage), errorType));
368100
- return;
368101
- }
368102
- let outcome = ToolConfirmationOutcome.ProceedOnce;
368103
- let lastDetails;
368104
- if (decision === PolicyDecision.ASK_USER) {
368105
- const forcedDecision = hookDecision === "ask" || policyDecision === PolicyDecision.ALLOW && hasTaintRisk ? "ask_user" : void 0;
368106
- const result = await resolveConfirmation(toolCall, signal, {
368107
- config: this.config,
368108
- messageBus: this.messageBus,
368109
- state: this.state,
368110
- modifier: this.modifier,
368111
- getPreferredEditor: this.getPreferredEditor,
368112
- schedulerId: this.schedulerId,
368113
- onWaitingForConfirmation: this.onWaitingForConfirmation,
368114
- systemMessage: hookSystemMessage,
368115
- forcedDecision
368116
- });
368117
- outcome = result.outcome;
368118
- lastDetails = result.lastDetails;
368119
- if ((result.confirmedByUser ?? false) && outcome !== ToolConfirmationOutcome.Cancel) {
368120
- toolCall.request.isUserConfirmed = true;
368121
- const updatedCall = this.state.getToolCall(callId);
368122
- if (updatedCall) {
368123
- updatedCall.request.isUserConfirmed = true;
368523
+ await runWithInvocationParseCache(toolCall.invocation, async () => {
368524
+ const { decision: policyDecision, rule } = await checkPolicy(toolCall, this.config, this.subagent);
368525
+ let decision = policyDecision;
368526
+ if (hookDecision === "ask") {
368527
+ decision = PolicyDecision.ASK_USER;
368528
+ }
368529
+ if (isCommandParseCacheAware(toolCall.invocation)) {
368530
+ await toolCall.invocation.prepareCommandParseCache(signal);
368531
+ }
368532
+ const hasTaintRisk = isTaintRiskDetectable(toolCall.invocation) && toolCall.invocation.hasTaintedOrBuildFileRisk();
368533
+ if (decision === PolicyDecision.ALLOW && hasTaintRisk) {
368534
+ decision = this.config.isInteractive?.() ?? true ? PolicyDecision.ASK_USER : PolicyDecision.DENY;
368535
+ }
368536
+ if (decision === PolicyDecision.DENY) {
368537
+ const { errorMessage, errorType } = getPolicyDenialError(this.config, rule);
368538
+ this.state.updateStatus(callId, CoreToolCallStatus.Error, createErrorResponse(toolCall.request, new Error(errorMessage), errorType));
368539
+ return;
368540
+ }
368541
+ let outcome = ToolConfirmationOutcome.ProceedOnce;
368542
+ let lastDetails;
368543
+ if (decision === PolicyDecision.ASK_USER) {
368544
+ const forcedDecision = hookDecision === "ask" || policyDecision === PolicyDecision.ALLOW && hasTaintRisk ? "ask_user" : void 0;
368545
+ const result = await resolveConfirmation(toolCall, signal, {
368546
+ config: this.config,
368547
+ messageBus: this.messageBus,
368548
+ state: this.state,
368549
+ modifier: this.modifier,
368550
+ getPreferredEditor: this.getPreferredEditor,
368551
+ schedulerId: this.schedulerId,
368552
+ onWaitingForConfirmation: this.onWaitingForConfirmation,
368553
+ systemMessage: hookSystemMessage,
368554
+ forcedDecision
368555
+ });
368556
+ outcome = result.outcome;
368557
+ lastDetails = result.lastDetails;
368558
+ if ((result.confirmedByUser ?? false) && outcome !== ToolConfirmationOutcome.Cancel) {
368559
+ toolCall.request.isUserConfirmed = true;
368560
+ const updatedCall = this.state.getToolCall(callId);
368561
+ if (updatedCall) {
368562
+ updatedCall.request.isUserConfirmed = true;
368563
+ }
368124
368564
  }
368125
368565
  }
368126
- }
368127
- this.state.setOutcome(callId, outcome);
368128
- if (decision === PolicyDecision.ASK_USER && outcome) {
368129
- await updatePolicy(toolCall.tool, outcome, lastDetails, this.context, this.messageBus, toolCall.invocation);
368130
- }
368131
- if (outcome === ToolConfirmationOutcome.Cancel) {
368132
- this.state.updateStatus(callId, CoreToolCallStatus.Cancelled, "User denied execution.");
368133
- if (this.cancelAllQueuedOnCancel) {
368134
- this.state.cancelAllQueued("User cancelled operation");
368566
+ this.state.setOutcome(callId, outcome);
368567
+ if (decision === PolicyDecision.ASK_USER && outcome) {
368568
+ await updatePolicy(toolCall.tool, outcome, lastDetails, this.context, this.messageBus, toolCall.invocation);
368135
368569
  }
368136
- return;
368137
- }
368138
- this.state.updateStatus(callId, CoreToolCallStatus.Scheduled);
368570
+ if (outcome === ToolConfirmationOutcome.Cancel) {
368571
+ this.state.updateStatus(callId, CoreToolCallStatus.Cancelled, "User denied execution.");
368572
+ if (this.cancelAllQueuedOnCancel) {
368573
+ this.state.cancelAllQueued("User cancelled operation");
368574
+ }
368575
+ return;
368576
+ }
368577
+ this.state.updateStatus(callId, CoreToolCallStatus.Scheduled);
368578
+ });
368139
368579
  }
368140
368580
  // --- Sub-phase Handlers ---
368141
368581
  /**
@@ -368515,7 +368955,7 @@ ${wrapInput(safeInput)}`;
368515
368955
  }
368516
368956
 
368517
368957
  // packages/core/dist/src/config/scoped-config.js
368518
- import { AsyncLocalStorage as AsyncLocalStorage3 } from "node:async_hooks";
368958
+ import { AsyncLocalStorage as AsyncLocalStorage4 } from "node:async_hooks";
368519
368959
  import * as path73 from "node:path";
368520
368960
 
368521
368961
  // packages/core/dist/src/utils/workspaceContext.js
@@ -368709,9 +369149,9 @@ var WorkspaceContext = class {
368709
369149
  };
368710
369150
 
368711
369151
  // packages/core/dist/src/config/scoped-config.js
368712
- var workspaceContextOverride = new AsyncLocalStorage3();
368713
- var memoryInboxAccessOverride = new AsyncLocalStorage3();
368714
- var autoMemoryExtractionWriteAccessOverride = new AsyncLocalStorage3();
369152
+ var workspaceContextOverride = new AsyncLocalStorage4();
369153
+ var memoryInboxAccessOverride = new AsyncLocalStorage4();
369154
+ var autoMemoryExtractionWriteAccessOverride = new AsyncLocalStorage4();
368715
369155
  function getWorkspaceContextOverride() {
368716
369156
  return workspaceContextOverride.getStore();
368717
369157
  }
@@ -381920,10 +382360,11 @@ var PolicyEngine = class {
381920
382360
  isAlwaysAllowRule(rule) {
381921
382361
  return rule.priority !== void 0 && Math.round(rule.priority % 1 * 1e3) === ALWAYS_ALLOW_PRIORITY_FRACTION;
381922
382362
  }
381923
- shouldDowngradeForRedirection(command, allowRedirection, rule) {
382363
+ async shouldDowngradeForRedirection(command, allowRedirection, rule) {
381924
382364
  if (allowRedirection)
381925
382365
  return false;
381926
- if (!hasRedirection(command))
382366
+ const redirected = isDefaultHasRedirection(hasRedirection) ? await hasRedirectionAsync(command) : hasRedirection(command);
382367
+ if (!redirected)
381927
382368
  return false;
381928
382369
  if (rule?.argsPattern && !allowRedirection) {
381929
382370
  return true;
@@ -382005,7 +382446,7 @@ var PolicyEngine = class {
382005
382446
  };
382006
382447
  }
382007
382448
  await initializeShellParsers();
382008
- const parsed = parseCommandDetails(command);
382449
+ const parsed = isDefaultParseCommandDetails(parseCommandDetails) ? await parseCommandDetailsAsync(command) : parseCommandDetails(command);
382009
382450
  const subCommands = parsed?.details ?? [];
382010
382451
  if (subCommands.length === 0 || parsed?.hasError) {
382011
382452
  if (ruleDecision === PolicyDecision.DENY) {
@@ -382033,7 +382474,7 @@ var PolicyEngine = class {
382033
382474
  }
382034
382475
  let aggregateDecision = ruleDecision;
382035
382476
  let responsibleRule = rule && ruleDecision === rule.decision ? rule : void 0;
382036
- const hasTopLevelRedirectionDowngrade = this.shouldDowngradeForRedirection(command, allowRedirection, rule);
382477
+ const hasTopLevelRedirectionDowngrade = await this.shouldDowngradeForRedirection(command, allowRedirection, rule);
382037
382478
  if (hasTopLevelRedirectionDowngrade) {
382038
382479
  if (aggregateDecision === PolicyDecision.ALLOW) {
382039
382480
  debugLogger.debug(`[PolicyEngine.check] Downgrading ALLOW to ASK_USER for redirected command: ${command}`);
@@ -382092,7 +382533,7 @@ var PolicyEngine = class {
382092
382533
  }
382093
382534
  aggregateDecision = PolicyDecision.ASK_USER;
382094
382535
  }
382095
- if (subResult.decision === PolicyDecision.ALLOW && (this.shouldDowngradeForRedirection(subCmd, subResult.rule?.allowRedirection ?? allowRedirection, subResult.rule) || this.shouldDowngradeForCommandSubstitution(subCmd, subResult.rule?.allowCommandSubstitution ?? rule?.allowCommandSubstitution, subResult.rule))) {
382536
+ if (subResult.decision === PolicyDecision.ALLOW && (await this.shouldDowngradeForRedirection(subCmd, subResult.rule?.allowRedirection ?? allowRedirection, subResult.rule) || this.shouldDowngradeForCommandSubstitution(subCmd, subResult.rule?.allowCommandSubstitution ?? rule?.allowCommandSubstitution, subResult.rule))) {
382096
382537
  allSubCommandsExplicitlyAllowed = false;
382097
382538
  if (aggregateDecision === PolicyDecision.ALLOW) {
382098
382539
  aggregateDecision = PolicyDecision.ASK_USER;
@@ -382128,6 +382569,9 @@ var PolicyEngine = class {
382128
382569
  * Returns the decision and the matching rule (if any).
382129
382570
  */
382130
382571
  async check(toolCall, serverName, toolAnnotations, subagent, skipHeuristics = false) {
382572
+ return runWithCommandParseCache(() => this.checkInternal(toolCall, serverName, toolAnnotations, subagent, skipHeuristics));
382573
+ }
382574
+ async checkInternal(toolCall, serverName, toolAnnotations, subagent, skipHeuristics = false) {
382131
382575
  if (!serverName && isMcpToolAnnotation(toolAnnotations)) {
382132
382576
  serverName = toolAnnotations._serverName;
382133
382577
  }
@@ -418048,6 +418492,9 @@ export {
418048
418492
  external_exports,
418049
418493
  debugLogger,
418050
418494
  require_shell_quote,
418495
+ CommandParseCache,
418496
+ getActiveCommandParseCache,
418497
+ runWithCommandParseCache,
418051
418498
  ToolErrorType,
418052
418499
  isFatalToolError,
418053
418500
  GEMINI_DIR,
@@ -418166,19 +418613,31 @@ export {
418166
418613
  normalizeCommand,
418167
418614
  parseBashCommandDetails,
418168
418615
  parseCommandDetails,
418616
+ parseCommandDetailsAsync,
418617
+ isDefaultParseCommandDetails,
418169
418618
  getShellConfiguration,
418170
418619
  isWindows,
418171
418620
  escapeShellArg,
418172
418621
  hasRedirection,
418622
+ hasRedirectionAsync,
418173
418623
  hasUnresolvedShellExpansion,
418174
418624
  splitCommands,
418625
+ splitCommandsAsync,
418175
418626
  getCommandRoot,
418627
+ getCommandRootAsync,
418176
418628
  getCommandRoots,
418629
+ getCommandRootsAsync,
418630
+ isDefaultHasRedirection,
418631
+ isDefaultSplitCommands,
418632
+ isDefaultGetCommandRoots,
418177
418633
  stripShellWrapper,
418178
418634
  spawnAsync,
418179
418635
  execStreaming,
418180
418636
  detectCommandSubstitution,
418637
+ isKnownInteractiveGeminiCommandSync,
418181
418638
  isInteractiveGeminiCommand,
418639
+ isInteractiveGeminiCommandAsync,
418640
+ isDefaultIsInteractiveGeminiCommand,
418182
418641
  import_fixed_deque,
418183
418642
  import_lru_cache,
418184
418643
  import_lru_map_with_delete,