@google/gemini-cli 0.70.0 → 0.71.0-preview.0

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 (59) hide show
  1. package/bundle/{chunk-V4HIE5G5.js → chunk-3XHFESDF.js} +1 -1
  2. package/bundle/{chunk-YOEWNBDC.js → chunk-532N7TZB.js} +2 -2
  3. package/bundle/{chunk-BOIBJEIO.js → chunk-5SC43MXU.js} +3 -3
  4. package/bundle/{chunk-AMHNNZY2.js → chunk-6E6XAAYL.js} +7 -7
  5. package/bundle/{chunk-6IKD2NB3.js → chunk-7UJSGYFD.js} +1 -1
  6. package/bundle/{chunk-GFBMTAPD.js → chunk-7YXHVH7Y.js} +2 -2
  7. package/bundle/{chunk-VHXUWMGE.js → chunk-AJZTZFAS.js} +2 -2
  8. package/bundle/{chunk-SPAMAY26.js → chunk-AQXZKJST.js} +1 -1
  9. package/bundle/{chunk-37D3S3FZ.js → chunk-BTH7KEMH.js} +842 -368
  10. package/bundle/{chunk-FXAACYC3.js → chunk-DCBU7GEJ.js} +1 -1
  11. package/bundle/{chunk-CB37EK5Y.js → chunk-DPAMHBTE.js} +3 -3
  12. package/bundle/{chunk-RFQXG324.js → chunk-EERY2AEY.js} +1 -1
  13. package/bundle/{chunk-QYKA4YD7.js → chunk-FUOK6VUJ.js} +3 -3
  14. package/bundle/{chunk-FHK4RNCX.js → chunk-IBD2PLWE.js} +7 -7
  15. package/bundle/{chunk-LMBUPWFC.js → chunk-JJNQ5PWH.js} +842 -368
  16. package/bundle/{chunk-4BWP3TDK.js → chunk-KSDBDSBI.js} +1 -1
  17. package/bundle/{chunk-CMKRWIX6.js → chunk-LGRO4U3O.js} +7 -7
  18. package/bundle/{chunk-KV6XIC2Z.js → chunk-NATMLC5X.js} +1 -1
  19. package/bundle/{chunk-3VGGGCOZ.js → chunk-NMOD2T37.js} +2 -2
  20. package/bundle/{chunk-WRWAVEME.js → chunk-NQGCTXGR.js} +1 -1
  21. package/bundle/{chunk-G6SC5BOV.js → chunk-QGOT25K4.js} +1 -1
  22. package/bundle/{chunk-JLKRLYZG.js → chunk-QQNZHLIF.js} +2 -2
  23. package/bundle/{chunk-5VFAWK3F.js → chunk-UTK4LRWO.js} +1 -1
  24. package/bundle/{chunk-7JS2T75Z.js → chunk-VIXTMKUM.js} +1 -1
  25. package/bundle/{chunk-EG2BSKPF.js → chunk-W7J7YSH2.js} +1 -1
  26. package/bundle/{chunk-LMNAB62M.js → chunk-Y6WF3A3Q.js} +2 -2
  27. package/bundle/{chunk-UF44X63P.js → chunk-YQO7IBVQ.js} +751 -320
  28. package/bundle/{cleanup-BMYAIPAL.js → cleanup-4WL7SSTL.js} +2 -2
  29. package/bundle/{cleanup-CWOSCK57.js → cleanup-62ECCOLP.js} +2 -2
  30. package/bundle/{cleanup-JTPRPYIQ.js → cleanup-JWSUGSQB.js} +2 -2
  31. package/bundle/{core-XZECNCR2.js → core-6V72TKM3.js} +31 -1
  32. package/bundle/{core-HYVGBZPP.js → core-NP64K3HR.js} +31 -1
  33. package/bundle/{devtoolsService-WNJOZ7ZT.js → devtoolsService-3G6P4EBB.js} +2 -2
  34. package/bundle/{devtoolsService-ER22TM2Y.js → devtoolsService-DWVXCWJ7.js} +2 -2
  35. package/bundle/{devtoolsService-O5VD5YWD.js → devtoolsService-XMEVE7R4.js} +2 -2
  36. package/bundle/{dist-75NDR3EX.js → dist-AAGC2327.js} +31 -1
  37. package/bundle/docs/changelogs/index.md +23 -0
  38. package/bundle/docs/changelogs/latest.md +112 -98
  39. package/bundle/docs/changelogs/preview.md +82 -115
  40. package/bundle/{formatError-M4GLDFGE.js → formatError-7YP6B7ZW.js} +2 -2
  41. package/bundle/{formatError-QOZLAZ32.js → formatError-P6NGVTF2.js} +2 -2
  42. package/bundle/{formatError-FYLLVZDF.js → formatError-QS36O76I.js} +2 -2
  43. package/bundle/{gemini-PG2FEK5D.js → gemini-3VVVLE4J.js} +15 -15
  44. package/bundle/{gemini-FRSP6LA3.js → gemini-AC4RONBV.js} +15 -15
  45. package/bundle/{gemini-AYDYW6NZ.js → gemini-TY6A5Q5C.js} +15 -15
  46. package/bundle/gemini.js +8 -8
  47. package/bundle/{interactiveCli-BYWR7IEK.js → interactiveCli-AO75ICTD.js} +157 -32
  48. package/bundle/{interactiveCli-6TVFB4R5.js → interactiveCli-BHEEEW2H.js} +157 -32
  49. package/bundle/{interactiveCli-76LAQB3B.js → interactiveCli-XULKUHW4.js} +157 -32
  50. package/bundle/{liteRtServerManager-GIRVSE6M.js → liteRtServerManager-7VEEHSC6.js} +4 -4
  51. package/bundle/{liteRtServerManager-KZ62KJW3.js → liteRtServerManager-DRZ6V4ZL.js} +4 -4
  52. package/bundle/{liteRtServerManager-BYJWS5BO.js → liteRtServerManager-GFU4D3JF.js} +4 -4
  53. package/bundle/{oauth2-provider-SFFQQ6OE.js → oauth2-provider-S7DQJKA5.js} +1 -1
  54. package/bundle/{oauth2-provider-ZBFFAIQE.js → oauth2-provider-XYK3N74K.js} +1 -1
  55. package/bundle/{oauth2-provider-SRH6I6G7.js → oauth2-provider-YZI5V6PH.js} +1 -1
  56. package/bundle/{start-PLK5XHJC.js → start-EMZSUYV6.js} +6 -6
  57. package/bundle/{start-Q66LTS3Y.js → start-JGS6ZUFX.js} +6 -6
  58. package/bundle/{start-OLEVDFQS.js → start-QQTZCWPJ.js} +6 -6
  59. package/package.json +1 -1
@@ -257243,6 +257243,51 @@ import {
257243
257243
  spawn,
257244
257244
  spawnSync
257245
257245
  } from "node:child_process";
257246
+
257247
+ // packages/core/src/utils/shell-parse-cache.ts
257248
+ import { AsyncLocalStorage } from "node:async_hooks";
257249
+ var CommandParseCache = class {
257250
+ completed = /* @__PURE__ */ new Map();
257251
+ inFlight = /* @__PURE__ */ new Map();
257252
+ makeKey(executable, command) {
257253
+ return `${executable}\0${command}`;
257254
+ }
257255
+ hasCompleted(executable, command) {
257256
+ return this.completed.has(this.makeKey(executable, command));
257257
+ }
257258
+ getCompleted(executable, command) {
257259
+ return this.completed.get(this.makeKey(executable, command));
257260
+ }
257261
+ setCompleted(executable, command, result) {
257262
+ this.completed.set(this.makeKey(executable, command), result);
257263
+ }
257264
+ getInFlight(executable, command) {
257265
+ return this.inFlight.get(this.makeKey(executable, command));
257266
+ }
257267
+ trackInFlight(executable, command, promise2) {
257268
+ const key = this.makeKey(executable, command);
257269
+ this.inFlight.set(key, promise2);
257270
+ void promise2.finally(() => {
257271
+ if (this.inFlight.get(key) === promise2) {
257272
+ this.inFlight.delete(key);
257273
+ }
257274
+ });
257275
+ return promise2;
257276
+ }
257277
+ };
257278
+ var commandParseCacheStorage = new AsyncLocalStorage();
257279
+ function getActiveCommandParseCache() {
257280
+ return commandParseCacheStorage.getStore();
257281
+ }
257282
+ function runWithCommandParseCache(fn3, cache2) {
257283
+ const targetCache = cache2 ?? commandParseCacheStorage.getStore() ?? new CommandParseCache();
257284
+ if (commandParseCacheStorage.getStore() === targetCache) {
257285
+ return fn3(targetCache);
257286
+ }
257287
+ return commandParseCacheStorage.run(targetCache, () => fn3(targetCache));
257288
+ }
257289
+
257290
+ // packages/core/src/utils/shell-utils.ts
257246
257291
  import * as readline from "node:readline";
257247
257292
 
257248
257293
  // node_modules/web-tree-sitter/tree-sitter.js
@@ -264349,7 +264394,7 @@ async function getCommandName(command, args2) {
264349
264394
  await initializeShellParsers();
264350
264395
  const fullCmd = [command, ...args2].join(" ");
264351
264396
  const stripped = stripShellWrapper(fullCmd);
264352
- const roots = getCommandRoots(stripped).filter(
264397
+ const roots = (await getCommandRootsAsync(stripped)).filter(
264353
264398
  (r9) => r9 !== "shopt" && r9 !== "set"
264354
264399
  );
264355
264400
  if (roots.length > 0) {
@@ -264755,7 +264800,51 @@ function parseBashCommandDetails(command) {
264755
264800
  hasError: hasError2
264756
264801
  };
264757
264802
  }
264758
- function parsePowerShellCommandDetails(command, executable) {
264803
+ function isRawPowerShellCommand(value) {
264804
+ return typeof value === "object" && value !== null && !Array.isArray(value);
264805
+ }
264806
+ function isRawPowerShellParsePayload(value) {
264807
+ return typeof value === "object" && value !== null && !Array.isArray(value);
264808
+ }
264809
+ function parsePowerShellParserOutput(rawStdout, originalCommand) {
264810
+ const output = rawStdout.trim();
264811
+ if (!output) {
264812
+ return { details: [], hasError: true };
264813
+ }
264814
+ let parsedUnknown;
264815
+ try {
264816
+ parsedUnknown = JSON.parse(output);
264817
+ } catch {
264818
+ return { details: [], hasError: true };
264819
+ }
264820
+ if (!isRawPowerShellParsePayload(parsedUnknown) || parsedUnknown.success !== true) {
264821
+ return { details: [], hasError: true };
264822
+ }
264823
+ const rawCommandsField = parsedUnknown.commands;
264824
+ const rawCommands = Array.isArray(rawCommandsField) ? rawCommandsField : isRawPowerShellCommand(rawCommandsField) ? [rawCommandsField] : [];
264825
+ const details = rawCommands.map((commandDetail) => {
264826
+ if (!isRawPowerShellCommand(commandDetail) || typeof commandDetail.name !== "string") {
264827
+ return null;
264828
+ }
264829
+ const name3 = normalizeCommandName(commandDetail.name);
264830
+ const text = typeof commandDetail.text === "string" ? commandDetail.text.trim() : originalCommand;
264831
+ const rawArgs = commandDetail.args;
264832
+ return {
264833
+ name: name3,
264834
+ text,
264835
+ startIndex: typeof commandDetail.startIndex === "number" ? commandDetail.startIndex : 0,
264836
+ args: Array.isArray(rawArgs) ? rawArgs.filter((arg) => typeof arg === "string") : void 0
264837
+ };
264838
+ }).filter((detail) => detail !== null).sort((a2, b3) => a2.startIndex - b3.startIndex);
264839
+ return {
264840
+ details,
264841
+ hasError: details.length === 0,
264842
+ hasRedirection: typeof parsedUnknown.hasRedirection === "boolean" ? parsedUnknown.hasRedirection : void 0,
264843
+ hasCommandSubstitution: typeof parsedUnknown.hasCommandSubstitution === "boolean" ? parsedUnknown.hasCommandSubstitution : false
264844
+ };
264845
+ }
264846
+ var globalInFlightPowerShellParses = /* @__PURE__ */ new Map();
264847
+ function parsePowerShellCommandDetails(command, executable, cache2) {
264759
264848
  const trimmed = command.trim();
264760
264849
  if (!trimmed) {
264761
264850
  return {
@@ -264763,6 +264852,10 @@ function parsePowerShellCommandDetails(command, executable) {
264763
264852
  hasError: true
264764
264853
  };
264765
264854
  }
264855
+ const activeCache = cache2 ?? getActiveCommandParseCache();
264856
+ if (activeCache?.hasCompleted(executable, command)) {
264857
+ return activeCache.getCompleted(executable, command) ?? null;
264858
+ }
264766
264859
  try {
264767
264860
  const result = spawnSync(
264768
264861
  executable,
@@ -264782,56 +264875,173 @@ function parsePowerShellCommandDetails(command, executable) {
264782
264875
  }
264783
264876
  );
264784
264877
  if (result.error || result.status !== 0) {
264878
+ activeCache?.setCompleted(executable, command, null);
264785
264879
  return null;
264786
264880
  }
264787
- const output = (result.stdout ?? "").toString().trim();
264788
- if (!output) {
264789
- return { details: [], hasError: true };
264881
+ const parsed = parsePowerShellParserOutput(
264882
+ (result.stdout ?? "").toString(),
264883
+ command
264884
+ );
264885
+ activeCache?.setCompleted(executable, command, parsed);
264886
+ return parsed;
264887
+ } catch {
264888
+ activeCache?.setCompleted(executable, command, null);
264889
+ return null;
264890
+ }
264891
+ }
264892
+ async function parsePowerShellCommandDetailsAsync(command, executable, cache2, signal) {
264893
+ const trimmed = command.trim();
264894
+ if (!trimmed) {
264895
+ return {
264896
+ details: [],
264897
+ hasError: true
264898
+ };
264899
+ }
264900
+ if (signal?.aborted) {
264901
+ return null;
264902
+ }
264903
+ const activeCache = cache2 ?? getActiveCommandParseCache();
264904
+ if (activeCache?.hasCompleted(executable, command)) {
264905
+ return activeCache.getCompleted(executable, command) ?? null;
264906
+ }
264907
+ const existingInFlight = activeCache?.getInFlight(executable, command);
264908
+ if (existingInFlight) {
264909
+ return existingInFlight;
264910
+ }
264911
+ const globalKey = `${executable}\0${command}`;
264912
+ if (!signal) {
264913
+ const existingGlobalInFlight = globalInFlightPowerShellParses.get(globalKey);
264914
+ if (existingGlobalInFlight) {
264915
+ const joinedPromise = existingGlobalInFlight.then((result) => {
264916
+ activeCache?.setCompleted(executable, command, result);
264917
+ return result;
264918
+ });
264919
+ if (activeCache) {
264920
+ return activeCache.trackInFlight(executable, command, joinedPromise);
264921
+ }
264922
+ return joinedPromise;
264790
264923
  }
264791
- let parsed = null;
264924
+ }
264925
+ const parsePromise = new Promise((resolve30) => {
264926
+ let settled = false;
264927
+ const finish = (value, cacheResult = true) => {
264928
+ if (!settled) {
264929
+ settled = true;
264930
+ if (cacheResult && !signal?.aborted) {
264931
+ activeCache?.setCompleted(executable, command, value);
264932
+ }
264933
+ resolve30(value);
264934
+ }
264935
+ };
264936
+ let child;
264792
264937
  try {
264793
- parsed = JSON.parse(output);
264938
+ child = spawn(
264939
+ executable,
264940
+ [
264941
+ "-NoLogo",
264942
+ "-NoProfile",
264943
+ "-NonInteractive",
264944
+ "-EncodedCommand",
264945
+ POWERSHELL_PARSER_SCRIPT
264946
+ ],
264947
+ {
264948
+ env: {
264949
+ ...process.env,
264950
+ [POWERSHELL_COMMAND_ENV]: command
264951
+ },
264952
+ stdio: ["ignore", "pipe", "pipe"],
264953
+ windowsHide: true,
264954
+ ...signal ? { signal } : {}
264955
+ }
264956
+ );
264794
264957
  } catch {
264795
- return { details: [], hasError: true };
264796
- }
264797
- if (!parsed?.success) {
264798
- return { details: [], hasError: true };
264958
+ finish(null, !signal?.aborted);
264959
+ return;
264799
264960
  }
264800
- const rawCommands = Array.isArray(parsed.commands) ? parsed.commands : parsed.commands ? [parsed.commands] : [];
264801
- const details = rawCommands.map((commandDetail) => {
264802
- if (!commandDetail || typeof commandDetail.name !== "string") {
264803
- return null;
264961
+ let stdout = "";
264962
+ child.stdout?.setEncoding("utf-8");
264963
+ child.stdout?.on("data", (chunk) => {
264964
+ stdout += chunk.toString();
264965
+ });
264966
+ child.stderr?.on("data", () => {
264967
+ });
264968
+ child.on("error", (err2) => {
264969
+ if (err2.name === "AbortError" || signal?.aborted) {
264970
+ finish(null, false);
264971
+ return;
264804
264972
  }
264805
- const name3 = normalizeCommandName(commandDetail.name);
264806
- const text = typeof commandDetail.text === "string" ? commandDetail.text.trim() : command;
264807
- return {
264808
- name: name3,
264809
- text,
264810
- startIndex: typeof commandDetail.startIndex === "number" ? commandDetail.startIndex : 0,
264811
- args: Array.isArray(commandDetail.args) ? commandDetail.args : void 0
264812
- };
264813
- }).filter((detail) => detail !== null).sort((a2, b3) => a2.startIndex - b3.startIndex);
264814
- return {
264815
- details,
264816
- hasError: details.length === 0,
264817
- hasRedirection: parsed.hasRedirection,
264818
- hasCommandSubstitution: parsed.hasCommandSubstitution ?? false
264819
- };
264820
- } catch {
264821
- return null;
264973
+ finish(null);
264974
+ });
264975
+ child.on("close", (code) => {
264976
+ if (signal?.aborted) {
264977
+ finish(null, false);
264978
+ return;
264979
+ }
264980
+ if (code !== 0) {
264981
+ finish(null);
264982
+ return;
264983
+ }
264984
+ const parsed = parsePowerShellParserOutput(stdout, command);
264985
+ finish(parsed);
264986
+ });
264987
+ });
264988
+ if (!signal) {
264989
+ globalInFlightPowerShellParses.set(globalKey, parsePromise);
264990
+ void parsePromise.finally(() => {
264991
+ if (globalInFlightPowerShellParses.get(globalKey) === parsePromise) {
264992
+ globalInFlightPowerShellParses.delete(globalKey);
264993
+ }
264994
+ });
264995
+ }
264996
+ if (activeCache) {
264997
+ return activeCache.trackInFlight(executable, command, parsePromise);
264822
264998
  }
264999
+ return parsePromise;
264823
265000
  }
264824
- function parseCommandDetails(command) {
265001
+ function parseCommandDetails(command, cache2) {
264825
265002
  const configuration = getShellConfiguration();
264826
265003
  if (configuration.shell === "powershell") {
264827
265004
  const result = parsePowerShellCommandDetails(
264828
265005
  command,
264829
- configuration.executable
265006
+ configuration.executable,
265007
+ cache2
265008
+ );
265009
+ if (!result || result.hasError) {
265010
+ if (detectPowerShellSubstitution(command)) {
265011
+ return result ?? { details: [], hasError: true };
265012
+ }
265013
+ const bashResult = parseBashCommandDetails(command);
265014
+ if (bashResult && !bashResult.hasError) {
265015
+ return bashResult;
265016
+ }
265017
+ }
265018
+ return result;
265019
+ }
265020
+ if (configuration.shell === "bash") {
265021
+ return parseBashCommandDetails(command);
265022
+ }
265023
+ return null;
265024
+ }
265025
+ async function parseCommandDetailsAsync(command, cache2, signal) {
265026
+ if (signal?.aborted) {
265027
+ return null;
265028
+ }
265029
+ const configuration = getShellConfiguration();
265030
+ if (configuration.shell === "powershell") {
265031
+ const result = await parsePowerShellCommandDetailsAsync(
265032
+ command,
265033
+ configuration.executable,
265034
+ cache2,
265035
+ signal
264830
265036
  );
265037
+ if (signal?.aborted) {
265038
+ return null;
265039
+ }
264831
265040
  if (!result || result.hasError) {
264832
265041
  if (detectPowerShellSubstitution(command)) {
264833
265042
  return result ?? { details: [], hasError: true };
264834
265043
  }
265044
+ await initializeShellParsers();
264835
265045
  const bashResult = parseBashCommandDetails(command);
264836
265046
  if (bashResult && !bashResult.hasError) {
264837
265047
  return bashResult;
@@ -264840,10 +265050,15 @@ function parseCommandDetails(command) {
264840
265050
  return result;
264841
265051
  }
264842
265052
  if (configuration.shell === "bash") {
265053
+ await initializeShellParsers();
264843
265054
  return parseBashCommandDetails(command);
264844
265055
  }
264845
265056
  return null;
264846
265057
  }
265058
+ var defaultParseCommandDetailsRef = parseCommandDetails;
265059
+ function isDefaultParseCommandDetails(fn3) {
265060
+ return fn3 === defaultParseCommandDetailsRef;
265061
+ }
264847
265062
  function getShellConfiguration() {
264848
265063
  if (isWindows()) {
264849
265064
  const powershellArgsPrefix = ["-NoProfile", "-NonInteractive", "-Command"];
@@ -264895,7 +265110,23 @@ function escapeShellArg(arg, shell) {
264895
265110
  return (0, import_shell_quote.quote)([arg]);
264896
265111
  }
264897
265112
  }
264898
- function hasRedirection(command) {
265113
+ function hasBashTreeRedirection(command, fallbackCheck) {
265114
+ const tree = parseCommandTree(command);
265115
+ if (!tree) return fallbackCheck();
265116
+ const stack = [tree.rootNode];
265117
+ while (stack.length > 0) {
265118
+ const current = stack.pop();
265119
+ if (current.type === "redirected_statement" || current.type === "file_redirect" || current.type === "heredoc_redirect" || current.type === "herestring_redirect") {
265120
+ return true;
265121
+ }
265122
+ for (let i3 = current.childCount - 1; i3 >= 0; i3 -= 1) {
265123
+ const child = current.child(i3);
265124
+ if (child) stack.push(child);
265125
+ }
265126
+ }
265127
+ return false;
265128
+ }
265129
+ function hasRedirection(command, cache2) {
264899
265130
  const fallbackCheck = () => /[><]/.test(command);
264900
265131
  if (!fallbackCheck()) {
264901
265132
  return false;
@@ -264904,26 +265135,43 @@ function hasRedirection(command) {
264904
265135
  if (configuration.shell === "powershell") {
264905
265136
  const parsed = parsePowerShellCommandDetails(
264906
265137
  command,
264907
- configuration.executable
265138
+ configuration.executable,
265139
+ cache2
264908
265140
  );
264909
265141
  return parsed && !parsed.hasError ? !!parsed.hasRedirection : fallbackCheck();
264910
265142
  }
264911
265143
  if (configuration.shell === "bash" && bashLanguage) {
264912
- const tree = parseCommandTree(command);
264913
- if (!tree) return fallbackCheck();
264914
- const stack = [tree.rootNode];
264915
- while (stack.length > 0) {
264916
- const current = stack.pop();
264917
- if (current.type === "redirected_statement" || current.type === "file_redirect" || current.type === "heredoc_redirect" || current.type === "herestring_redirect") {
264918
- return true;
264919
- }
264920
- for (let i3 = current.childCount - 1; i3 >= 0; i3 -= 1) {
264921
- const child = current.child(i3);
264922
- if (child) stack.push(child);
264923
- }
264924
- }
265144
+ return hasBashTreeRedirection(command, fallbackCheck);
265145
+ }
265146
+ return fallbackCheck();
265147
+ }
265148
+ async function hasRedirectionAsync(command, cache2, signal) {
265149
+ if (signal?.aborted) {
264925
265150
  return false;
264926
265151
  }
265152
+ const fallbackCheck = () => /[><]/.test(command);
265153
+ if (!fallbackCheck()) {
265154
+ return false;
265155
+ }
265156
+ const configuration = getShellConfiguration();
265157
+ if (configuration.shell === "powershell") {
265158
+ const parsed = await parsePowerShellCommandDetailsAsync(
265159
+ command,
265160
+ configuration.executable,
265161
+ cache2,
265162
+ signal
265163
+ );
265164
+ if (signal?.aborted) {
265165
+ return false;
265166
+ }
265167
+ return parsed && !parsed.hasError ? !!parsed.hasRedirection : fallbackCheck();
265168
+ }
265169
+ if (configuration.shell === "bash") {
265170
+ await initializeShellParsers();
265171
+ if (bashLanguage) {
265172
+ return hasBashTreeRedirection(command, fallbackCheck);
265173
+ }
265174
+ }
264927
265175
  return fallbackCheck();
264928
265176
  }
264929
265177
  var SHELL_EXPANSION_NODE_TYPES = /* @__PURE__ */ new Set([
@@ -265060,30 +265308,66 @@ function hasUnresolvedShellExpansion(command) {
265060
265308
  tree.delete();
265061
265309
  }
265062
265310
  }
265063
- function splitCommands(command) {
265064
- const parsed = parseCommandDetails(command);
265311
+ function splitCommands(command, cache2) {
265312
+ const parsed = parseCommandDetails(command, cache2);
265313
+ if (!parsed || parsed.hasError) {
265314
+ return [];
265315
+ }
265316
+ return parsed.details.filter((detail) => !REDIRECTION_NAMES.has(detail.name)).map((detail) => detail.text).filter(Boolean);
265317
+ }
265318
+ async function splitCommandsAsync(command, cache2, signal) {
265319
+ const parsed = await parseCommandDetailsAsync(command, cache2, signal);
265065
265320
  if (!parsed || parsed.hasError) {
265066
265321
  return [];
265067
265322
  }
265068
265323
  return parsed.details.filter((detail) => !REDIRECTION_NAMES.has(detail.name)).map((detail) => detail.text).filter(Boolean);
265069
265324
  }
265070
- function getCommandRoot(command) {
265071
- const parsed = parseCommandDetails(command);
265325
+ function getCommandRoot(command, cache2) {
265326
+ const parsed = parseCommandDetails(command, cache2);
265072
265327
  if (!parsed || parsed.hasError || parsed.details.length === 0) {
265073
265328
  return void 0;
265074
265329
  }
265075
265330
  return parsed.details[0]?.name;
265076
265331
  }
265077
- function getCommandRoots(command) {
265332
+ async function getCommandRootAsync(command, cache2, signal) {
265333
+ const parsed = await parseCommandDetailsAsync(command, cache2, signal);
265334
+ if (!parsed || parsed.hasError || parsed.details.length === 0) {
265335
+ return void 0;
265336
+ }
265337
+ return parsed.details[0]?.name;
265338
+ }
265339
+ function getCommandRoots(command, cache2) {
265078
265340
  if (!command) {
265079
265341
  return [];
265080
265342
  }
265081
- const parsed = parseCommandDetails(command);
265343
+ const parsed = parseCommandDetails(command, cache2);
265082
265344
  if (!parsed || parsed.hasError) {
265083
265345
  return [];
265084
265346
  }
265085
265347
  return parsed.details.map((detail) => detail.name).filter((name3) => !REDIRECTION_NAMES.has(name3)).filter(Boolean);
265086
265348
  }
265349
+ async function getCommandRootsAsync(command, cache2, signal) {
265350
+ if (!command) {
265351
+ return [];
265352
+ }
265353
+ const parsed = await parseCommandDetailsAsync(command, cache2, signal);
265354
+ if (!parsed || parsed.hasError) {
265355
+ return [];
265356
+ }
265357
+ return parsed.details.map((detail) => detail.name).filter((name3) => !REDIRECTION_NAMES.has(name3)).filter(Boolean);
265358
+ }
265359
+ var defaultHasRedirectionRef = hasRedirection;
265360
+ var defaultSplitCommandsRef = splitCommands;
265361
+ var defaultGetCommandRootsRef = getCommandRoots;
265362
+ function isDefaultHasRedirection(fn3) {
265363
+ return fn3 === defaultHasRedirectionRef;
265364
+ }
265365
+ function isDefaultSplitCommands(fn3) {
265366
+ return fn3 === defaultSplitCommandsRef;
265367
+ }
265368
+ function isDefaultGetCommandRoots(fn3) {
265369
+ return fn3 === defaultGetCommandRootsRef;
265370
+ }
265087
265371
  var PS_WRAPPER_FLAGS = /* @__PURE__ */ new Set([
265088
265372
  "-nologo",
265089
265373
  "-noprofile",
@@ -266342,10 +266626,7 @@ function isInteractiveGeminiSegment(segment) {
266342
266626
  }
266343
266627
  return true;
266344
266628
  }
266345
- function isInteractiveGeminiCommand(command) {
266346
- if (!command || !command.trim()) {
266347
- return false;
266348
- }
266629
+ function unwrapCommandForGeminiCheck(command) {
266349
266630
  let unwrapped = command.trim();
266350
266631
  for (let depth = 0; depth < 3; depth++) {
266351
266632
  const next = stripShellWrapper(unwrapped);
@@ -266354,10 +266635,59 @@ function isInteractiveGeminiCommand(command) {
266354
266635
  }
266355
266636
  unwrapped = next;
266356
266637
  }
266357
- const parsedSegments = splitCommands(unwrapped);
266638
+ return unwrapped;
266639
+ }
266640
+ var GEMINI_SUBSEQUENCE = "gemini";
266641
+ function containsGeminiSubsequence(input) {
266642
+ const lower = input.toLowerCase();
266643
+ let pos = 0;
266644
+ for (const ch of GEMINI_SUBSEQUENCE) {
266645
+ const found = lower.indexOf(ch, pos);
266646
+ if (found === -1) {
266647
+ return false;
266648
+ }
266649
+ pos = found + 1;
266650
+ }
266651
+ return true;
266652
+ }
266653
+ function isKnownInteractiveGeminiCommandSync(command) {
266654
+ if (!command || !command.trim()) {
266655
+ return false;
266656
+ }
266657
+ const unwrapped = unwrapCommandForGeminiCheck(command);
266658
+ if (!containsGeminiSubsequence(unwrapped)) {
266659
+ return false;
266660
+ }
266358
266661
  const fallbackSegments = splitShellCommandSegments(unwrapped);
266359
- const allSegments = parsedSegments.length > 0 ? [...parsedSegments, ...fallbackSegments] : fallbackSegments;
266360
- return allSegments.some((segment) => isInteractiveGeminiSegment(segment));
266662
+ if (fallbackSegments.some((segment) => isInteractiveGeminiSegment(segment))) {
266663
+ return true;
266664
+ }
266665
+ return void 0;
266666
+ }
266667
+ function isInteractiveGeminiCommand(command, cache2) {
266668
+ const fastResult = isKnownInteractiveGeminiCommandSync(command);
266669
+ if (fastResult !== void 0) {
266670
+ return fastResult;
266671
+ }
266672
+ const unwrapped = unwrapCommandForGeminiCheck(command);
266673
+ const parsedSegments = splitCommands(unwrapped, cache2);
266674
+ return parsedSegments.some((segment) => isInteractiveGeminiSegment(segment));
266675
+ }
266676
+ async function isInteractiveGeminiCommandAsync(command, cache2, signal) {
266677
+ if (signal?.aborted) {
266678
+ return false;
266679
+ }
266680
+ const fastResult = isKnownInteractiveGeminiCommandSync(command);
266681
+ if (fastResult !== void 0) {
266682
+ return fastResult;
266683
+ }
266684
+ const unwrapped = unwrapCommandForGeminiCheck(command);
266685
+ const parsedSegments = await splitCommandsAsync(unwrapped, cache2, signal);
266686
+ return parsedSegments.some((segment) => isInteractiveGeminiSegment(segment));
266687
+ }
266688
+ var defaultIsInteractiveGeminiCommandRef = isInteractiveGeminiCommand;
266689
+ function isDefaultIsInteractiveGeminiCommand(fn3) {
266690
+ return fn3 === defaultIsInteractiveGeminiCommandRef;
266361
266691
  }
266362
266692
 
266363
266693
  // packages/core/src/sandbox/utils/commandSafety.ts
@@ -266926,7 +267256,7 @@ async function isStrictlyApproved(command, args2, approvedTools, cwd, workspaceR
266926
267256
  await initializeShellParsers();
266927
267257
  const fullCmd = [command, ...args2].join(" ");
266928
267258
  const stripped = stripShellWrapper(fullCmd);
266929
- const pipelineCommands = splitCommands(stripped);
267259
+ const pipelineCommands = isDefaultSplitCommands(splitCommands) ? await splitCommandsAsync(stripped) : splitCommands(stripped);
266930
267260
  if (pipelineCommands.length === 0) {
266931
267261
  return tools.includes(command) || isKnownSafeCommand2([command, ...args2], cwd, workspaceRoot);
266932
267262
  }
@@ -267435,35 +267765,38 @@ async function isStrictlyApproved2(req, approvedTools) {
267435
267765
  if (!approvedTools || approvedTools.length === 0) {
267436
267766
  return false;
267437
267767
  }
267438
- await initializeShellParsers();
267439
- const fullCmd = [req.command, ...req.args].join(" ");
267440
- const stripped = stripShellWrapper(fullCmd);
267441
- const roots = getCommandRoots(stripped);
267442
- if (roots.length === 0) return false;
267443
- const allRootsApproved = roots.every((root) => approvedTools.includes(root));
267444
- if (allRootsApproved) {
267445
- return true;
267446
- }
267447
- if (hasUnresolvedShellExpansion(stripped)) {
267448
- return false;
267449
- }
267450
- const pipelineCommands = splitCommands(stripped);
267451
- if (pipelineCommands.length === 0) return false;
267452
- for (const cmdString of pipelineCommands) {
267453
- const parsedArgs = (0, import_shell_quote4.parse)(cmdString).map(String);
267454
- if (!isKnownSafeCommand(parsedArgs)) {
267768
+ return runWithCommandParseCache(async () => {
267769
+ await initializeShellParsers();
267770
+ const fullCmd = [req.command, ...req.args].join(" ");
267771
+ const stripped = stripShellWrapper(fullCmd);
267772
+ const roots = isDefaultGetCommandRoots(getCommandRoots) ? await getCommandRootsAsync(stripped) : getCommandRoots(stripped);
267773
+ if (roots.length === 0) return false;
267774
+ const allRootsApproved = roots.every(
267775
+ (root) => approvedTools.includes(root)
267776
+ );
267777
+ if (allRootsApproved) {
267778
+ return true;
267779
+ }
267780
+ if (hasUnresolvedShellExpansion(stripped)) {
267455
267781
  return false;
267456
267782
  }
267457
- }
267458
- return true;
267783
+ const pipelineCommands = isDefaultSplitCommands(splitCommands) ? await splitCommandsAsync(stripped) : splitCommands(stripped);
267784
+ if (pipelineCommands.length === 0) return false;
267785
+ for (const cmdString of pipelineCommands) {
267786
+ const parsedArgs = (0, import_shell_quote4.parse)(cmdString).map(String);
267787
+ if (!isKnownSafeCommand(parsedArgs)) {
267788
+ return false;
267789
+ }
267790
+ }
267791
+ return true;
267792
+ });
267459
267793
  }
267460
267794
  async function getCommandName2(req) {
267461
267795
  await initializeShellParsers();
267462
267796
  const fullCmd = [req.command, ...req.args].join(" ");
267463
267797
  const stripped = stripShellWrapper(fullCmd);
267464
- const roots = getCommandRoots(stripped).filter(
267465
- (r9) => r9 !== "shopt" && r9 !== "set"
267466
- );
267798
+ const computedRoots = isDefaultGetCommandRoots(getCommandRoots) ? await getCommandRootsAsync(stripped) : getCommandRoots(stripped);
267799
+ const roots = computedRoots.filter((r9) => r9 !== "shopt" && r9 !== "set");
267467
267800
  if (roots.length > 0) {
267468
267801
  return roots[0];
267469
267802
  }
@@ -268839,6 +269172,9 @@ var WindowsSandboxManager = class _WindowsSandboxManager {
268839
269172
  * Prepares a command for sandboxed execution on Windows.
268840
269173
  */
268841
269174
  async prepareCommand(req) {
269175
+ return runWithCommandParseCache(() => this.prepareCommandInternal(req));
269176
+ }
269177
+ async prepareCommandInternal(req) {
268842
269178
  await this.ensureHelperCompiled();
268843
269179
  const sanitizationConfig = getSecureSanitizationConfig(
268844
269180
  req.policy?.sanitizationConfig
@@ -268875,9 +269211,8 @@ var WindowsSandboxManager = class _WindowsSandboxManager {
268875
269211
  await initializeShellParsers();
268876
269212
  const fullCmd = [command, ...args2].join(" ");
268877
269213
  const stripped = stripShellWrapper(fullCmd);
268878
- const roots = getCommandRoots(stripped).filter(
268879
- (r9) => r9 !== "shopt" && r9 !== "set"
268880
- );
269214
+ const computedRoots = isDefaultGetCommandRoots(getCommandRoots) ? await getCommandRootsAsync(stripped) : getCommandRoots(stripped);
269215
+ const roots = computedRoots.filter((r9) => r9 !== "shopt" && r9 !== "set");
268881
269216
  const isGitCommand = roots.includes("git");
268882
269217
  const resolvedPaths = await resolveSandboxPaths(
268883
269218
  this.options,
@@ -295413,8 +295748,8 @@ function isValidToolName(name3, options = {}) {
295413
295748
  }
295414
295749
 
295415
295750
  // packages/core/src/generated/git-commit.ts
295416
- var GIT_COMMIT_INFO = "7f51a3899";
295417
- var CLI_VERSION = "0.70.0-preview.0";
295751
+ var GIT_COMMIT_INFO = "808199f5c";
295752
+ var CLI_VERSION = "0.71.0-preview.0";
295418
295753
 
295419
295754
  // packages/core/src/ide/detect-ide.ts
295420
295755
  var IDE_DEFINITIONS = {
@@ -328408,7 +328743,7 @@ function getVersion() {
328408
328743
  }
328409
328744
  versionPromise = (async () => {
328410
328745
  const pkgJson = await getPackageJson(__dirname4);
328411
- return "0.70.0-preview.0";
328746
+ return "0.71.0-preview.0";
328412
328747
  })();
328413
328748
  return versionPromise;
328414
328749
  }
@@ -330601,8 +330936,8 @@ var BaseLlmClient = class {
330601
330936
  };
330602
330937
 
330603
330938
  // packages/core/src/utils/promptIdContext.ts
330604
- import { AsyncLocalStorage } from "node:async_hooks";
330605
- var promptIdContext = new AsyncLocalStorage();
330939
+ import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
330940
+ var promptIdContext = new AsyncLocalStorage2();
330606
330941
  function getPromptIdWithFallback(componentName) {
330607
330942
  const promptId = promptIdContext.getStore();
330608
330943
  if (promptId) {
@@ -331314,24 +331649,17 @@ function findUntrustedFlags(command, untrustedContext, options) {
331314
331649
  }
331315
331650
  return Array.from(detected);
331316
331651
  }
331317
- function isBuildOrTestCommand(command) {
331318
- if (!command) {
331319
- return false;
331320
- }
331652
+ function evaluateBuildOrTestCommandFromRoots(command, roots) {
331321
331653
  const getBaseName = (cmd) => {
331322
331654
  const base2 = cmd.replace(/\\/g, "/").split("/").pop();
331323
331655
  if (!base2) return cmd.toLowerCase();
331324
331656
  return base2.toLowerCase().replace(/\.(exe|cmd|bat)$/, "");
331325
331657
  };
331326
- try {
331327
- const roots = getCommandRoots(command);
331328
- if (roots.length > 0) {
331329
- return roots.some((root2) => {
331330
- const base2 = getBaseName(root2);
331331
- return BUILD_TEST_COMMAND_ROOTS.has(base2) || BUILD_TEST_COMMAND_ROOTS.has(root2.toLowerCase());
331332
- });
331333
- }
331334
- } catch {
331658
+ if (roots.length > 0) {
331659
+ return roots.some((root2) => {
331660
+ const base2 = getBaseName(root2);
331661
+ return BUILD_TEST_COMMAND_ROOTS.has(base2) || BUILD_TEST_COMMAND_ROOTS.has(root2.toLowerCase());
331662
+ });
331335
331663
  }
331336
331664
  const parts2 = command.trim().split(/\s+/);
331337
331665
  let rootIndex = 0;
@@ -331343,18 +331671,33 @@ function isBuildOrTestCommand(command) {
331343
331671
  const base = getBaseName(root);
331344
331672
  return BUILD_TEST_COMMAND_ROOTS.has(base) || BUILD_TEST_COMMAND_ROOTS.has(root.toLowerCase());
331345
331673
  }
331346
- function isRemoteContentCommand(command) {
331674
+ function isBuildOrTestCommand(command) {
331347
331675
  if (!command) {
331348
331676
  return false;
331349
331677
  }
331350
331678
  let roots = [];
331351
331679
  try {
331352
- roots = getCommandRoots(command).map((root) => normalizeCommand(root));
331680
+ roots = getCommandRoots(command);
331353
331681
  } catch {
331354
331682
  }
331683
+ return evaluateBuildOrTestCommandFromRoots(command, roots);
331684
+ }
331685
+ function evaluateRemoteContentCommandFromRoots(command, rawRoots) {
331686
+ const roots = rawRoots.map((root) => normalizeCommand(root));
331355
331687
  const candidates = roots.length === 0 || roots.some((root) => COMMAND_WRAPPER_ROOTS.has(root)) ? command.trim().split(/[\s;&|()]+/).map((word) => normalizeCommand(word)) : roots;
331356
331688
  return candidates.some((name3) => REMOTE_CONTENT_COMMAND_ROOTS.has(name3));
331357
331689
  }
331690
+ async function isRemoteContentCommandAsync(command) {
331691
+ if (!command) {
331692
+ return false;
331693
+ }
331694
+ let rawRoots = [];
331695
+ try {
331696
+ rawRoots = isDefaultGetCommandRoots(getCommandRoots) ? await getCommandRootsAsync(command) : getCommandRoots(command);
331697
+ } catch {
331698
+ }
331699
+ return evaluateRemoteContentCommandFromRoots(command, rawRoots);
331700
+ }
331358
331701
  var MODIFIED_BUILD_FILES_SYMBOL = Symbol("sessionModifiedBuildFiles");
331359
331702
  var ACKNOWLEDGED_UNTRUSTED_FLAGS_SYMBOL = Symbol(
331360
331703
  "sessionAcknowledgedUntrustedFlags"
@@ -345179,8 +345522,8 @@ ${truncated}`;
345179
345522
  };
345180
345523
 
345181
345524
  // packages/core/src/utils/toolCallContext.ts
345182
- import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
345183
- var toolCallContext = new AsyncLocalStorage2();
345525
+ import { AsyncLocalStorage as AsyncLocalStorage3 } from "node:async_hooks";
345526
+ var toolCallContext = new AsyncLocalStorage3();
345184
345527
  function runWithToolCallContext(context2, fn3) {
345185
345528
  return toolCallContext.run(context2, fn3);
345186
345529
  }
@@ -345346,6 +345689,47 @@ var ShellToolInvocation = class extends BaseToolInvocation {
345346
345689
  }
345347
345690
  proactivePermissionsConfirmed;
345348
345691
  confirmedCommand;
345692
+ parseCache = new CommandParseCache();
345693
+ runInCommandParseCache(fn3) {
345694
+ return runWithCommandParseCache(fn3, this.parseCache);
345695
+ }
345696
+ async prepareCommandParseCache(signal) {
345697
+ if (signal?.aborted || typeof stripShellWrapper !== "function" || !isDefaultParseCommandDetails(parseCommandDetails)) {
345698
+ return;
345699
+ }
345700
+ const rawCommand = this.params.command;
345701
+ const stripped = stripShellWrapper(rawCommand);
345702
+ let unwrapped = stripped;
345703
+ for (let depth = 0; depth < 3; depth++) {
345704
+ const next = stripShellWrapper(unwrapped);
345705
+ if (next === unwrapped) {
345706
+ break;
345707
+ }
345708
+ unwrapped = next;
345709
+ }
345710
+ await parseCommandDetailsAsync(stripped, this.parseCache, signal);
345711
+ if (unwrapped !== stripped && !signal?.aborted) {
345712
+ await parseCommandDetailsAsync(unwrapped, this.parseCache, signal);
345713
+ }
345714
+ }
345715
+ hasCachedCommandParse(command) {
345716
+ if (typeof getShellConfiguration !== "function") {
345717
+ return false;
345718
+ }
345719
+ const configuration = getShellConfiguration();
345720
+ if (configuration.shell !== "powershell") {
345721
+ return true;
345722
+ }
345723
+ let unwrapped = command.trim();
345724
+ for (let depth = 0; depth < 3; depth++) {
345725
+ const next = stripShellWrapper(unwrapped);
345726
+ if (next === unwrapped) {
345727
+ break;
345728
+ }
345729
+ unwrapped = next;
345730
+ }
345731
+ return this.parseCache.hasCompleted(configuration.executable, command) && this.parseCache.hasCompleted(configuration.executable, unwrapped);
345732
+ }
345349
345733
  /**
345350
345734
  * Wraps a command in a subshell to capture background process IDs (PIDs)
345351
345735
  * using an EXIT trap. Uses newlines to prevent breaking heredocs or trailing
@@ -345504,205 +345888,235 @@ exit $__code`;
345504
345888
  return getUnacknowledgedUntrustedFlags(untrustedFlags, roots, config2);
345505
345889
  }
345506
345890
  hasTaintedOrBuildFileRisk() {
345507
- const command = stripShellWrapper(this.params.command);
345508
- const untrustedFlags = this.getUntrustedFlags(command);
345509
- const modifiedBuildFiles = getModifiedBuildFiles(this.context.config);
345510
- const isBuildCmd = isBuildOrTestCommand(command);
345511
- return untrustedFlags.length > 0 || isBuildCmd && modifiedBuildFiles.length > 0;
345891
+ return this.runInCommandParseCache(() => {
345892
+ const command = stripShellWrapper(this.params.command);
345893
+ const untrustedFlags = this.getUntrustedFlags(command);
345894
+ const modifiedBuildFiles = getModifiedBuildFiles(this.context.config);
345895
+ const isBuildCmd = isBuildOrTestCommand(command);
345896
+ return untrustedFlags.length > 0 || isBuildCmd && modifiedBuildFiles.length > 0;
345897
+ });
345512
345898
  }
345513
345899
  getPolicyUpdateOptions(outcome) {
345514
- if (outcome === "proceed_always_and_save" /* ProceedAlwaysAndSave */ || outcome === "proceed_always" /* ProceedAlways */) {
345515
- const command = stripShellWrapper(this.params.command);
345516
- if (this.hasTaintedOrBuildFileRisk()) {
345517
- return void 0;
345518
- }
345519
- const rootCommands = [...new Set(getCommandRoots(command))];
345520
- const allowRedirection = hasRedirection(command) ? true : void 0;
345521
- const allowCommandSubstitution = detectCommandSubstitution(command) ? true : void 0;
345522
- if (rootCommands.length > 0) {
345900
+ return this.runInCommandParseCache(() => {
345901
+ if (outcome === "proceed_always_and_save" /* ProceedAlwaysAndSave */ || outcome === "proceed_always" /* ProceedAlways */) {
345902
+ const command = stripShellWrapper(this.params.command);
345903
+ if (this.hasTaintedOrBuildFileRisk()) {
345904
+ return void 0;
345905
+ }
345906
+ const rootCommands = [...new Set(getCommandRoots(command))];
345907
+ const allowRedirection = hasRedirection(command) ? true : void 0;
345908
+ const allowCommandSubstitution = detectCommandSubstitution(command) ? true : void 0;
345909
+ if (rootCommands.length > 0) {
345910
+ return {
345911
+ commandPrefix: rootCommands,
345912
+ allowRedirection,
345913
+ ...allowCommandSubstitution !== void 0 ? { allowCommandSubstitution } : {}
345914
+ };
345915
+ }
345523
345916
  return {
345524
- commandPrefix: rootCommands,
345917
+ commandPrefix: this.params.command,
345525
345918
  allowRedirection,
345526
345919
  ...allowCommandSubstitution !== void 0 ? { allowCommandSubstitution } : {}
345527
345920
  };
345528
345921
  }
345529
- return {
345530
- commandPrefix: this.params.command,
345531
- allowRedirection,
345532
- ...allowCommandSubstitution !== void 0 ? { allowCommandSubstitution } : {}
345533
- };
345534
- }
345535
- return void 0;
345922
+ return void 0;
345923
+ });
345536
345924
  }
345537
345925
  async shouldConfirmExecute(abortSignal, forcedDecision) {
345538
- if (isInteractiveGeminiCommand(stripShellWrapper(this.params.command))) {
345539
- return false;
345540
- }
345541
- if (forcedDecision === "deny") {
345542
- return super.shouldConfirmExecute(abortSignal, forcedDecision);
345543
- }
345544
- if (this.hasTaintedOrBuildFileRisk()) {
345545
- return this.getConfirmationDetails(abortSignal);
345546
- }
345547
- if (this.context.config.getApprovalMode() === "yolo" /* YOLO */ && forcedDecision !== "ask_user") {
345548
- return super.shouldConfirmExecute(abortSignal, forcedDecision);
345549
- }
345550
- if (this.params[PARAM_ADDITIONAL_PERMISSIONS]) {
345551
- return this.getConfirmationDetails(abortSignal);
345552
- }
345553
- if (this.context.config.getSandboxEnabled()) {
345554
- const command = stripShellWrapper(this.params.command);
345555
- const rootCommands = getCommandRoots(command);
345556
- const rawRootCommand = rootCommands[0];
345557
- if (rawRootCommand) {
345558
- const rootCommand = normalizeCommand(rawRootCommand);
345559
- const proactive = await getProactiveToolSuggestions(rootCommand);
345560
- if (proactive) {
345561
- const mode = this.context.config.getApprovalMode();
345562
- const modeConfig = this.context.config.sandboxPolicyManager.getModeConfig(mode);
345563
- const approved = this.context.config.sandboxPolicyManager.getCommandPermissions(
345564
- rootCommand
345565
- );
345566
- const hasNetwork = modeConfig.network || approved.network;
345567
- const missingNetwork = !!proactive.network && !hasNetwork;
345568
- const parsed = parseCommandDetails(command);
345569
- const subCommand = parsed?.details[0]?.args?.[0];
345570
- const needsNetwork = isNetworkReliantCommand(rootCommand, subCommand);
345571
- if (needsNetwork) {
345572
- const isReadonlyMode = modeConfig.readonly ?? false;
345573
- if (isReadonlyMode) {
345574
- const cwd = this.params.dir_path || this.context.config.getTargetDir();
345575
- proactive.fileSystem = proactive.fileSystem || {
345576
- read: [],
345577
- write: []
345578
- };
345579
- proactive.fileSystem.write = proactive.fileSystem.write || [];
345580
- if (!proactive.fileSystem.write.includes(cwd)) {
345581
- proactive.fileSystem.write.push(cwd);
345582
- proactive.fileSystem.read = proactive.fileSystem.read || [];
345583
- if (!proactive.fileSystem.read.includes(cwd)) {
345584
- proactive.fileSystem.read.push(cwd);
345926
+ return this.runInCommandParseCache(async () => {
345927
+ await this.prepareCommandParseCache(abortSignal);
345928
+ const strippedForInteractiveCheck = stripShellWrapper(
345929
+ this.params.command
345930
+ );
345931
+ const isInteractive = isDefaultIsInteractiveGeminiCommand(
345932
+ isInteractiveGeminiCommand
345933
+ ) ? await isInteractiveGeminiCommandAsync(
345934
+ strippedForInteractiveCheck,
345935
+ this.parseCache,
345936
+ abortSignal
345937
+ ) : isInteractiveGeminiCommand(strippedForInteractiveCheck);
345938
+ if (isInteractive) {
345939
+ return false;
345940
+ }
345941
+ if (forcedDecision === "deny") {
345942
+ return super.shouldConfirmExecute(abortSignal, forcedDecision);
345943
+ }
345944
+ if (this.hasTaintedOrBuildFileRisk()) {
345945
+ return this.getConfirmationDetails(abortSignal);
345946
+ }
345947
+ if (this.context.config.getApprovalMode() === "yolo" /* YOLO */ && forcedDecision !== "ask_user") {
345948
+ return super.shouldConfirmExecute(abortSignal, forcedDecision);
345949
+ }
345950
+ if (this.params[PARAM_ADDITIONAL_PERMISSIONS]) {
345951
+ return this.getConfirmationDetails(abortSignal);
345952
+ }
345953
+ if (this.context.config.getSandboxEnabled()) {
345954
+ const command = stripShellWrapper(this.params.command);
345955
+ const rootCommands = isDefaultGetCommandRoots(getCommandRoots) ? await getCommandRootsAsync(command, this.parseCache, abortSignal) : getCommandRoots(command);
345956
+ const rawRootCommand = rootCommands[0];
345957
+ if (rawRootCommand) {
345958
+ const rootCommand = normalizeCommand(rawRootCommand);
345959
+ const proactive = await getProactiveToolSuggestions(rootCommand);
345960
+ if (proactive) {
345961
+ const mode = this.context.config.getApprovalMode();
345962
+ const modeConfig = this.context.config.sandboxPolicyManager.getModeConfig(mode);
345963
+ const approved = this.context.config.sandboxPolicyManager.getCommandPermissions(
345964
+ rootCommand
345965
+ );
345966
+ const hasNetwork = modeConfig.network || approved.network;
345967
+ const missingNetwork = !!proactive.network && !hasNetwork;
345968
+ const parsed = isDefaultParseCommandDetails(parseCommandDetails) ? await parseCommandDetailsAsync(
345969
+ command,
345970
+ this.parseCache,
345971
+ abortSignal
345972
+ ) : parseCommandDetails(command);
345973
+ const subCommand = parsed?.details[0]?.args?.[0];
345974
+ const needsNetwork = isNetworkReliantCommand(
345975
+ rootCommand,
345976
+ subCommand
345977
+ );
345978
+ if (needsNetwork) {
345979
+ const isReadonlyMode = modeConfig.readonly ?? false;
345980
+ if (isReadonlyMode) {
345981
+ const cwd = this.params.dir_path || this.context.config.getTargetDir();
345982
+ proactive.fileSystem = proactive.fileSystem || {
345983
+ read: [],
345984
+ write: []
345985
+ };
345986
+ proactive.fileSystem.write = proactive.fileSystem.write || [];
345987
+ if (!proactive.fileSystem.write.includes(cwd)) {
345988
+ proactive.fileSystem.write.push(cwd);
345989
+ proactive.fileSystem.read = proactive.fileSystem.read || [];
345990
+ if (!proactive.fileSystem.read.includes(cwd)) {
345991
+ proactive.fileSystem.read.push(cwd);
345992
+ }
345585
345993
  }
345586
345994
  }
345587
- }
345588
- const isApproved = (requestedPath, approvedPaths) => {
345589
- if (!approvedPaths || approvedPaths.length === 0) return false;
345590
- const requestedRealIdentity = toPathKey(
345591
- resolveToRealPath(requestedPath)
345995
+ const isApproved = (requestedPath, approvedPaths) => {
345996
+ if (!approvedPaths || approvedPaths.length === 0) return false;
345997
+ const requestedRealIdentity = toPathKey(
345998
+ resolveToRealPath(requestedPath)
345999
+ );
346000
+ return approvedPaths.some((p2) => {
346001
+ const approvedRealIdentity = toPathKey(resolveToRealPath(p2));
346002
+ return requestedRealIdentity === approvedRealIdentity || isSubpath(approvedRealIdentity, requestedRealIdentity);
346003
+ });
346004
+ };
346005
+ const missingRead = (proactive.fileSystem?.read || []).filter(
346006
+ (p2) => !isApproved(p2, approved.fileSystem?.read)
345592
346007
  );
345593
- return approvedPaths.some((p2) => {
345594
- const approvedRealIdentity = toPathKey(resolveToRealPath(p2));
345595
- return requestedRealIdentity === approvedRealIdentity || isSubpath(approvedRealIdentity, requestedRealIdentity);
345596
- });
345597
- };
345598
- const missingRead = (proactive.fileSystem?.read || []).filter(
345599
- (p2) => !isApproved(p2, approved.fileSystem?.read)
345600
- );
345601
- const missingWrite = (proactive.fileSystem?.write || []).filter(
345602
- (p2) => !isApproved(p2, approved.fileSystem?.write)
345603
- );
345604
- const needsExpansion = missingRead.length > 0 || missingWrite.length > 0 || missingNetwork;
345605
- if (needsExpansion) {
345606
- const details = await this.getConfirmationDetails(
345607
- abortSignal,
345608
- proactive
346008
+ const missingWrite = (proactive.fileSystem?.write || []).filter(
346009
+ (p2) => !isApproved(p2, approved.fileSystem?.write)
345609
346010
  );
345610
- if (details && details.type === "sandbox_expansion") {
345611
- const originalOnConfirm = details.onConfirm;
345612
- details.onConfirm = async (outcome) => {
345613
- await originalOnConfirm(outcome);
345614
- if (outcome !== "cancel" /* Cancel */) {
345615
- this.proactivePermissionsConfirmed = proactive;
345616
- }
345617
- };
346011
+ const needsExpansion = missingRead.length > 0 || missingWrite.length > 0 || missingNetwork;
346012
+ if (needsExpansion) {
346013
+ const details = await this.getConfirmationDetails(
346014
+ abortSignal,
346015
+ proactive
346016
+ );
346017
+ if (details && details.type === "sandbox_expansion") {
346018
+ const originalOnConfirm = details.onConfirm;
346019
+ details.onConfirm = async (outcome) => {
346020
+ await originalOnConfirm(outcome);
346021
+ if (outcome !== "cancel" /* Cancel */) {
346022
+ this.proactivePermissionsConfirmed = proactive;
346023
+ }
346024
+ };
346025
+ }
346026
+ return details;
345618
346027
  }
345619
- return details;
345620
346028
  }
345621
346029
  }
345622
346030
  }
345623
346031
  }
345624
- }
345625
- return super.shouldConfirmExecute(abortSignal, forcedDecision);
346032
+ return super.shouldConfirmExecute(abortSignal, forcedDecision);
346033
+ });
345626
346034
  }
345627
- async getConfirmationDetails(_abortSignal, proactivePermissions) {
345628
- const command = stripShellWrapper(this.params.command);
345629
- const parsed = parseCommandDetails(command);
345630
- let rootCommandDisplay = "";
345631
- if (!parsed || parsed.hasError || parsed.details.length === 0) {
345632
- const fallback = command.trim().split(/\s+/)[0];
345633
- rootCommandDisplay = fallback || "shell command";
345634
- if (hasRedirection(command)) {
345635
- rootCommandDisplay += ", redirection";
346035
+ async getConfirmationDetails(abortSignal, proactivePermissions) {
346036
+ return this.runInCommandParseCache(async () => {
346037
+ const command = stripShellWrapper(this.params.command);
346038
+ const parsed = isDefaultParseCommandDetails(parseCommandDetails) ? await parseCommandDetailsAsync(command, this.parseCache, abortSignal) : parseCommandDetails(command);
346039
+ const commandHasRedirection = isDefaultHasRedirection(hasRedirection) ? await hasRedirectionAsync(command, this.parseCache, abortSignal) : hasRedirection(command);
346040
+ let rootCommandDisplay = "";
346041
+ if (!parsed || parsed.hasError || parsed.details.length === 0) {
346042
+ const fallback = command.trim().split(/\s+/)[0];
346043
+ rootCommandDisplay = fallback || "shell command";
346044
+ if (commandHasRedirection) {
346045
+ rootCommandDisplay += ", redirection";
346046
+ }
346047
+ } else {
346048
+ rootCommandDisplay = parsed.details.map((detail) => detail.name).join(", ");
345636
346049
  }
345637
- } else {
345638
- rootCommandDisplay = parsed.details.map((detail) => detail.name).join(", ");
345639
- }
345640
- let rootCommands = [];
345641
- try {
345642
- rootCommands = [...new Set(getCommandRoots(command))];
345643
- } catch {
345644
- rootCommands = [command.trim().split(/\s+/)[0] || "shell"];
345645
- }
345646
- const rootCommand = rootCommands[0] || "shell";
345647
- const untrustedFlags = this.getUntrustedFlags(command);
345648
- const modifiedBuildFiles = getModifiedBuildFiles(this.context.config);
345649
- const isBuildCmd = isBuildOrTestCommand(command);
345650
- const hasSecurityWarning = untrustedFlags.length > 0 || isBuildCmd && modifiedBuildFiles.length > 0;
345651
- const effectiveAdditionalPermissions = this.params[PARAM_ADDITIONAL_PERMISSIONS] || proactivePermissions;
345652
- if (effectiveAdditionalPermissions && !hasSecurityWarning) {
345653
- return {
345654
- type: "sandbox_expansion",
345655
- title: proactivePermissions ? "Sandbox Expansion Request (Recommended)" : "Sandbox Expansion Request",
346050
+ let rootCommands = [];
346051
+ try {
346052
+ const computedRoots = isDefaultGetCommandRoots(getCommandRoots) ? await getCommandRootsAsync(command, this.parseCache, abortSignal) : getCommandRoots(command);
346053
+ rootCommands = [...new Set(computedRoots)];
346054
+ } catch {
346055
+ rootCommands = [command.trim().split(/\s+/)[0] || "shell"];
346056
+ }
346057
+ const rootCommand = rootCommands[0] || "shell";
346058
+ const untrustedFlags = this.getUntrustedFlags(command);
346059
+ const modifiedBuildFiles = getModifiedBuildFiles(this.context.config);
346060
+ const isBuildCmd = isBuildOrTestCommand(command);
346061
+ const hasSecurityWarning = untrustedFlags.length > 0 || isBuildCmd && modifiedBuildFiles.length > 0;
346062
+ const effectiveAdditionalPermissions = this.params[PARAM_ADDITIONAL_PERMISSIONS] || proactivePermissions;
346063
+ if (effectiveAdditionalPermissions && !hasSecurityWarning) {
346064
+ return {
346065
+ type: "sandbox_expansion",
346066
+ title: proactivePermissions ? "Sandbox Expansion Request (Recommended)" : "Sandbox Expansion Request",
346067
+ command: this.params.command,
346068
+ rootCommand: rootCommandDisplay,
346069
+ additionalPermissions: effectiveAdditionalPermissions,
346070
+ onConfirm: async (outcome) => {
346071
+ if (outcome !== "cancel" /* Cancel */ && outcome !== "modify_with_editor" /* ModifyWithEditor */) {
346072
+ this.confirmedCommand = this.params.command;
346073
+ }
346074
+ if (outcome === "proceed_always_and_save" /* ProceedAlwaysAndSave */) {
346075
+ this.context.config.sandboxPolicyManager.addPersistentApproval(
346076
+ rootCommand,
346077
+ effectiveAdditionalPermissions
346078
+ );
346079
+ } else if (outcome === "proceed_always" /* ProceedAlways */) {
346080
+ this.context.config.sandboxPolicyManager.addSessionApproval(
346081
+ rootCommand,
346082
+ effectiveAdditionalPermissions
346083
+ );
346084
+ }
346085
+ }
346086
+ };
346087
+ }
346088
+ const confirmationDetails = {
346089
+ type: "exec",
346090
+ title: "Confirm Shell Command",
345656
346091
  command: this.params.command,
345657
346092
  rootCommand: rootCommandDisplay,
345658
- additionalPermissions: effectiveAdditionalPermissions,
346093
+ rootCommands,
346094
+ hasRedirection: commandHasRedirection,
346095
+ untrustedFlags: untrustedFlags.length > 0 ? untrustedFlags : void 0,
346096
+ modifiedBuildFiles: isBuildCmd && modifiedBuildFiles.length > 0 ? modifiedBuildFiles : void 0,
345659
346097
  onConfirm: async (outcome) => {
345660
- if (outcome !== "cancel" /* Cancel */ && outcome !== "modify_with_editor" /* ModifyWithEditor */) {
345661
- this.confirmedCommand = this.params.command;
346098
+ if (outcome === "cancel" /* Cancel */ || outcome === "modify_with_editor" /* ModifyWithEditor */) {
346099
+ return;
345662
346100
  }
345663
- if (outcome === "proceed_always_and_save" /* ProceedAlwaysAndSave */) {
345664
- this.context.config.sandboxPolicyManager.addPersistentApproval(
345665
- rootCommand,
345666
- effectiveAdditionalPermissions
345667
- );
345668
- } else if (outcome === "proceed_always" /* ProceedAlways */) {
345669
- this.context.config.sandboxPolicyManager.addSessionApproval(
345670
- rootCommand,
345671
- effectiveAdditionalPermissions
345672
- );
346101
+ this.confirmedCommand = this.params.command;
346102
+ acknowledgeUntrustedFlags(
346103
+ untrustedFlags,
346104
+ rootCommands,
346105
+ this.context.config
346106
+ );
346107
+ if (isBuildCmd && modifiedBuildFiles.length > 0) {
346108
+ resetModifiedBuildFiles(this.context.config);
345673
346109
  }
345674
346110
  }
345675
346111
  };
345676
- }
345677
- const confirmationDetails = {
345678
- type: "exec",
345679
- title: "Confirm Shell Command",
345680
- command: this.params.command,
345681
- rootCommand: rootCommandDisplay,
345682
- rootCommands,
345683
- untrustedFlags: untrustedFlags.length > 0 ? untrustedFlags : void 0,
345684
- modifiedBuildFiles: isBuildCmd && modifiedBuildFiles.length > 0 ? modifiedBuildFiles : void 0,
345685
- onConfirm: async (outcome) => {
345686
- if (outcome === "cancel" /* Cancel */ || outcome === "modify_with_editor" /* ModifyWithEditor */) {
345687
- return;
345688
- }
345689
- this.confirmedCommand = this.params.command;
345690
- acknowledgeUntrustedFlags(
345691
- untrustedFlags,
345692
- rootCommands,
345693
- this.context.config
345694
- );
345695
- if (isBuildCmd && modifiedBuildFiles.length > 0) {
345696
- resetModifiedBuildFiles(this.context.config);
345697
- }
345698
- }
345699
- };
345700
- return confirmationDetails;
346112
+ return confirmationDetails;
346113
+ });
345701
346114
  }
345702
346115
  async isCommandSubstitutionAllowed(options) {
345703
346116
  if ((options.isClientInitiated ?? false) || (options.isUserConfirmed ?? false) || this.confirmedCommand === this.params.command) {
345704
346117
  return true;
345705
346118
  }
346119
+ await this.prepareCommandParseCache(options.abortSignal);
345706
346120
  if (this.hasTaintedOrBuildFileRisk()) {
345707
346121
  return false;
345708
346122
  }
@@ -345723,6 +346137,9 @@ exit $__code`;
345723
346137
  return this.context.config?.getApprovalMode?.() === "yolo" /* YOLO */;
345724
346138
  }
345725
346139
  async execute(options) {
346140
+ return this.runInCommandParseCache(() => this.executeInternal(options));
346141
+ }
346142
+ async executeInternal(options) {
345726
346143
  const {
345727
346144
  abortSignal: signal,
345728
346145
  updateOutput,
@@ -345730,7 +346147,23 @@ exit $__code`;
345730
346147
  setExecutionIdCallback
345731
346148
  } = options;
345732
346149
  const strippedCommand = stripShellWrapper(this.params.command);
345733
- if (isInteractiveGeminiCommand(strippedCommand)) {
346150
+ let isInteractiveGemini;
346151
+ if (!isDefaultIsInteractiveGeminiCommand(isInteractiveGeminiCommand)) {
346152
+ isInteractiveGemini = isInteractiveGeminiCommand(strippedCommand);
346153
+ } else if (this.hasCachedCommandParse(strippedCommand)) {
346154
+ isInteractiveGemini = isInteractiveGeminiCommand(
346155
+ strippedCommand,
346156
+ this.parseCache
346157
+ );
346158
+ } else {
346159
+ const knownInteractive = isKnownInteractiveGeminiCommandSync(strippedCommand);
346160
+ isInteractiveGemini = knownInteractive ?? await isInteractiveGeminiCommandAsync(
346161
+ strippedCommand,
346162
+ this.parseCache,
346163
+ signal
346164
+ );
346165
+ }
346166
+ if (isInteractiveGemini) {
345734
346167
  return {
345735
346168
  llmContent: INTERACTIVE_GEMINI_SHELL_ERROR,
345736
346169
  returnDisplay: INTERACTIVE_GEMINI_SHELL_ERROR,
@@ -346099,7 +346532,8 @@ ${result.output}`;
346099
346532
  const sandboxDenial = this.context.config.sandboxManager.parseDenials(result);
346100
346533
  if (sandboxDenial) {
346101
346534
  const strippedCommand2 = stripShellWrapper(this.params.command);
346102
- const rootCommands = getCommandRoots(strippedCommand2).filter(
346535
+ const computedRootCommands = isDefaultGetCommandRoots(getCommandRoots) ? await getCommandRootsAsync(strippedCommand2, this.parseCache) : getCommandRoots(strippedCommand2);
346536
+ const rootCommands = computedRootCommands.filter(
346103
346537
  (r9) => r9 !== "shopt"
346104
346538
  );
346105
346539
  const rootCommandDisplay = rootCommands.length > 0 ? rootCommands[0] : "shell";
@@ -346195,7 +346629,7 @@ ${result.output}`;
346195
346629
  }
346196
346630
  }
346197
346631
  const summarizeConfig = this.context.config.getSummarizeToolOutputConfig();
346198
- const outputSource = isRemoteContentCommand(strippedCommand) ? REMOTE_SHELL_OUTPUT_SOURCE : void 0;
346632
+ const outputSource = await isRemoteContentCommandAsync(strippedCommand) ? REMOTE_SHELL_OUTPUT_SOURCE : void 0;
346199
346633
  const executionError = result.error ? {
346200
346634
  error: {
346201
346635
  message: result.error.message,
@@ -363364,7 +363798,7 @@ var A2AAuthProviderFactory = class _A2AAuthProviderFactory {
363364
363798
  return provider;
363365
363799
  }
363366
363800
  case "oauth2": {
363367
- const { OAuth2AuthProvider } = await import("./oauth2-provider-ZBFFAIQE.js");
363801
+ const { OAuth2AuthProvider } = await import("./oauth2-provider-XYK3N74K.js");
363368
363802
  const provider = new OAuth2AuthProvider(
363369
363803
  authConfig,
363370
363804
  options.agentName ?? "unknown",
@@ -365263,6 +365697,9 @@ function isAutoEditTransition(tool, outcome) {
365263
365697
  }
365264
365698
  async function handleStandardPolicyUpdate(tool, outcome, confirmationDetails, messageBus, persistScope, toolInvocation, config2, modes) {
365265
365699
  if (outcome === "proceed_always" /* ProceedAlways */ || outcome === "proceed_always_and_save" /* ProceedAlwaysAndSave */) {
365700
+ if (typeof toolInvocation === "object" && toolInvocation !== null && "prepareCommandParseCache" in toolInvocation && typeof toolInvocation.prepareCommandParseCache === "function") {
365701
+ await toolInvocation.prepareCommandParseCache();
365702
+ }
365266
365703
  const options = toolInvocation?.getPolicyUpdateOptions?.(outcome) || {};
365267
365704
  if (!options.commandPrefix && confirmationDetails?.type === "exec") {
365268
365705
  options.commandPrefix = confirmationDetails.rootCommands;
@@ -371729,6 +372166,15 @@ var ToolModificationHandler = class {
371729
372166
  };
371730
372167
 
371731
372168
  // packages/core/src/scheduler/scheduler.ts
372169
+ function isCommandParseCacheAware(invocation) {
372170
+ return typeof invocation === "object" && invocation !== null && "runInCommandParseCache" in invocation && typeof invocation.runInCommandParseCache === "function" && "prepareCommandParseCache" in invocation && typeof invocation.prepareCommandParseCache === "function";
372171
+ }
372172
+ function runWithInvocationParseCache(invocation, fn3) {
372173
+ if (isCommandParseCacheAware(invocation)) {
372174
+ return invocation.runInCommandParseCache(fn3);
372175
+ }
372176
+ return runWithCommandParseCache(fn3);
372177
+ }
371732
372178
  function isTaintRiskDetectable(invocation) {
371733
372179
  return typeof invocation === "object" && invocation !== null && "hasTaintedOrBuildFileRisk" in invocation && typeof invocation.hasTaintedOrBuildFileRisk === "function";
371734
372180
  }
@@ -372171,83 +372617,88 @@ var Scheduler = class {
372171
372617
  toolCall.request.inputModifiedByHook = true;
372172
372618
  toolCall.invocation = newInvocation;
372173
372619
  }
372174
- const { decision: policyDecision, rule } = await checkPolicy(
372175
- toolCall,
372176
- this.config,
372177
- this.subagent
372178
- );
372179
- let decision = policyDecision;
372180
- if (hookDecision === "ask") {
372181
- decision = "ask_user" /* ASK_USER */;
372182
- }
372183
- const hasTaintRisk = isTaintRiskDetectable(toolCall.invocation) && toolCall.invocation.hasTaintedOrBuildFileRisk();
372184
- if (decision === "allow" /* ALLOW */ && hasTaintRisk) {
372185
- decision = this.config.isInteractive?.() ?? true ? "ask_user" /* ASK_USER */ : "deny" /* DENY */;
372186
- }
372187
- if (decision === "deny" /* DENY */) {
372188
- const { errorMessage, errorType } = getPolicyDenialError(
372620
+ await runWithInvocationParseCache(toolCall.invocation, async () => {
372621
+ const { decision: policyDecision, rule } = await checkPolicy(
372622
+ toolCall,
372189
372623
  this.config,
372190
- rule
372624
+ this.subagent
372191
372625
  );
372192
- this.state.updateStatus(
372193
- callId,
372194
- "error" /* Error */,
372195
- createErrorResponse(
372196
- toolCall.request,
372197
- new Error(errorMessage),
372198
- errorType
372199
- )
372200
- );
372201
- return;
372202
- }
372203
- let outcome = "proceed_once" /* ProceedOnce */;
372204
- let lastDetails;
372205
- if (decision === "ask_user" /* ASK_USER */) {
372206
- const forcedDecision = hookDecision === "ask" || policyDecision === "allow" /* ALLOW */ && hasTaintRisk ? "ask_user" : void 0;
372207
- const result = await resolveConfirmation(toolCall, signal, {
372208
- config: this.config,
372209
- messageBus: this.messageBus,
372210
- state: this.state,
372211
- modifier: this.modifier,
372212
- getPreferredEditor: this.getPreferredEditor,
372213
- schedulerId: this.schedulerId,
372214
- onWaitingForConfirmation: this.onWaitingForConfirmation,
372215
- systemMessage: hookSystemMessage,
372216
- forcedDecision
372217
- });
372218
- outcome = result.outcome;
372219
- lastDetails = result.lastDetails;
372220
- if ((result.confirmedByUser ?? false) && outcome !== "cancel" /* Cancel */) {
372221
- toolCall.request.isUserConfirmed = true;
372222
- const updatedCall = this.state.getToolCall(callId);
372223
- if (updatedCall) {
372224
- updatedCall.request.isUserConfirmed = true;
372225
- }
372226
- }
372227
- }
372228
- this.state.setOutcome(callId, outcome);
372229
- if (decision === "ask_user" /* ASK_USER */ && outcome) {
372230
- await updatePolicy(
372231
- toolCall.tool,
372232
- outcome,
372233
- lastDetails,
372234
- this.context,
372235
- this.messageBus,
372236
- toolCall.invocation
372237
- );
372238
- }
372239
- if (outcome === "cancel" /* Cancel */) {
372240
- this.state.updateStatus(
372241
- callId,
372242
- "cancelled" /* Cancelled */,
372243
- "User denied execution."
372244
- );
372245
- if (this.cancelAllQueuedOnCancel) {
372246
- this.state.cancelAllQueued("User cancelled operation");
372626
+ let decision = policyDecision;
372627
+ if (hookDecision === "ask") {
372628
+ decision = "ask_user" /* ASK_USER */;
372247
372629
  }
372248
- return;
372249
- }
372250
- this.state.updateStatus(callId, "scheduled" /* Scheduled */);
372630
+ if (isCommandParseCacheAware(toolCall.invocation)) {
372631
+ await toolCall.invocation.prepareCommandParseCache(signal);
372632
+ }
372633
+ const hasTaintRisk = isTaintRiskDetectable(toolCall.invocation) && toolCall.invocation.hasTaintedOrBuildFileRisk();
372634
+ if (decision === "allow" /* ALLOW */ && hasTaintRisk) {
372635
+ decision = this.config.isInteractive?.() ?? true ? "ask_user" /* ASK_USER */ : "deny" /* DENY */;
372636
+ }
372637
+ if (decision === "deny" /* DENY */) {
372638
+ const { errorMessage, errorType } = getPolicyDenialError(
372639
+ this.config,
372640
+ rule
372641
+ );
372642
+ this.state.updateStatus(
372643
+ callId,
372644
+ "error" /* Error */,
372645
+ createErrorResponse(
372646
+ toolCall.request,
372647
+ new Error(errorMessage),
372648
+ errorType
372649
+ )
372650
+ );
372651
+ return;
372652
+ }
372653
+ let outcome = "proceed_once" /* ProceedOnce */;
372654
+ let lastDetails;
372655
+ if (decision === "ask_user" /* ASK_USER */) {
372656
+ const forcedDecision = hookDecision === "ask" || policyDecision === "allow" /* ALLOW */ && hasTaintRisk ? "ask_user" : void 0;
372657
+ const result = await resolveConfirmation(toolCall, signal, {
372658
+ config: this.config,
372659
+ messageBus: this.messageBus,
372660
+ state: this.state,
372661
+ modifier: this.modifier,
372662
+ getPreferredEditor: this.getPreferredEditor,
372663
+ schedulerId: this.schedulerId,
372664
+ onWaitingForConfirmation: this.onWaitingForConfirmation,
372665
+ systemMessage: hookSystemMessage,
372666
+ forcedDecision
372667
+ });
372668
+ outcome = result.outcome;
372669
+ lastDetails = result.lastDetails;
372670
+ if ((result.confirmedByUser ?? false) && outcome !== "cancel" /* Cancel */) {
372671
+ toolCall.request.isUserConfirmed = true;
372672
+ const updatedCall = this.state.getToolCall(callId);
372673
+ if (updatedCall) {
372674
+ updatedCall.request.isUserConfirmed = true;
372675
+ }
372676
+ }
372677
+ }
372678
+ this.state.setOutcome(callId, outcome);
372679
+ if (decision === "ask_user" /* ASK_USER */ && outcome) {
372680
+ await updatePolicy(
372681
+ toolCall.tool,
372682
+ outcome,
372683
+ lastDetails,
372684
+ this.context,
372685
+ this.messageBus,
372686
+ toolCall.invocation
372687
+ );
372688
+ }
372689
+ if (outcome === "cancel" /* Cancel */) {
372690
+ this.state.updateStatus(
372691
+ callId,
372692
+ "cancelled" /* Cancelled */,
372693
+ "User denied execution."
372694
+ );
372695
+ if (this.cancelAllQueuedOnCancel) {
372696
+ this.state.cancelAllQueued("User cancelled operation");
372697
+ }
372698
+ return;
372699
+ }
372700
+ this.state.updateStatus(callId, "scheduled" /* Scheduled */);
372701
+ });
372251
372702
  }
372252
372703
  // --- Sub-phase Handlers ---
372253
372704
  /**
@@ -372687,7 +373138,7 @@ ${wrapInput(safeInput)}`;
372687
373138
  }
372688
373139
 
372689
373140
  // packages/core/src/config/scoped-config.ts
372690
- import { AsyncLocalStorage as AsyncLocalStorage3 } from "node:async_hooks";
373141
+ import { AsyncLocalStorage as AsyncLocalStorage4 } from "node:async_hooks";
372691
373142
  import * as path73 from "node:path";
372692
373143
 
372693
373144
  // packages/core/src/utils/workspaceContext.ts
@@ -372886,9 +373337,9 @@ var WorkspaceContext = class {
372886
373337
  };
372887
373338
 
372888
373339
  // packages/core/src/config/scoped-config.ts
372889
- var workspaceContextOverride = new AsyncLocalStorage3();
372890
- var memoryInboxAccessOverride = new AsyncLocalStorage3();
372891
- var autoMemoryExtractionWriteAccessOverride = new AsyncLocalStorage3();
373340
+ var workspaceContextOverride = new AsyncLocalStorage4();
373341
+ var memoryInboxAccessOverride = new AsyncLocalStorage4();
373342
+ var autoMemoryExtractionWriteAccessOverride = new AsyncLocalStorage4();
372892
373343
  function getWorkspaceContextOverride() {
372893
373344
  return workspaceContextOverride.getStore();
372894
373345
  }
@@ -387138,9 +387589,10 @@ var PolicyEngine = class {
387138
387589
  isAlwaysAllowRule(rule) {
387139
387590
  return rule.priority !== void 0 && Math.round(rule.priority % 1 * 1e3) === ALWAYS_ALLOW_PRIORITY_FRACTION;
387140
387591
  }
387141
- shouldDowngradeForRedirection(command, allowRedirection, rule) {
387592
+ async shouldDowngradeForRedirection(command, allowRedirection, rule) {
387142
387593
  if (allowRedirection) return false;
387143
- if (!hasRedirection(command)) return false;
387594
+ const redirected = isDefaultHasRedirection(hasRedirection) ? await hasRedirectionAsync(command) : hasRedirection(command);
387595
+ if (!redirected) return false;
387144
387596
  if (rule?.argsPattern && !allowRedirection) {
387145
387597
  return true;
387146
387598
  }
@@ -387237,7 +387689,7 @@ var PolicyEngine = class {
387237
387689
  };
387238
387690
  }
387239
387691
  await initializeShellParsers();
387240
- const parsed = parseCommandDetails(command);
387692
+ const parsed = isDefaultParseCommandDetails(parseCommandDetails) ? await parseCommandDetailsAsync(command) : parseCommandDetails(command);
387241
387693
  const subCommands = parsed?.details ?? [];
387242
387694
  if (subCommands.length === 0 || parsed?.hasError) {
387243
387695
  if (ruleDecision === "deny" /* DENY */) {
@@ -387271,11 +387723,7 @@ var PolicyEngine = class {
387271
387723
  }
387272
387724
  let aggregateDecision = ruleDecision;
387273
387725
  let responsibleRule = rule && ruleDecision === rule.decision ? rule : void 0;
387274
- const hasTopLevelRedirectionDowngrade = this.shouldDowngradeForRedirection(
387275
- command,
387276
- allowRedirection,
387277
- rule
387278
- );
387726
+ const hasTopLevelRedirectionDowngrade = await this.shouldDowngradeForRedirection(command, allowRedirection, rule);
387279
387727
  if (hasTopLevelRedirectionDowngrade) {
387280
387728
  if (aggregateDecision === "allow" /* ALLOW */) {
387281
387729
  debugLogger.debug(
@@ -387353,7 +387801,7 @@ var PolicyEngine = class {
387353
387801
  }
387354
387802
  aggregateDecision = "ask_user" /* ASK_USER */;
387355
387803
  }
387356
- if (subResult.decision === "allow" /* ALLOW */ && (this.shouldDowngradeForRedirection(
387804
+ if (subResult.decision === "allow" /* ALLOW */ && (await this.shouldDowngradeForRedirection(
387357
387805
  subCmd,
387358
387806
  subResult.rule?.allowRedirection ?? allowRedirection,
387359
387807
  subResult.rule
@@ -387397,6 +387845,17 @@ var PolicyEngine = class {
387397
387845
  * Returns the decision and the matching rule (if any).
387398
387846
  */
387399
387847
  async check(toolCall, serverName, toolAnnotations, subagent, skipHeuristics = false) {
387848
+ return runWithCommandParseCache(
387849
+ () => this.checkInternal(
387850
+ toolCall,
387851
+ serverName,
387852
+ toolAnnotations,
387853
+ subagent,
387854
+ skipHeuristics
387855
+ )
387856
+ );
387857
+ }
387858
+ async checkInternal(toolCall, serverName, toolAnnotations, subagent, skipHeuristics = false) {
387400
387859
  if (!serverName && isMcpToolAnnotation(toolAnnotations)) {
387401
387860
  serverName = toolAnnotations._serverName;
387402
387861
  }
@@ -425355,6 +425814,9 @@ export {
425355
425814
  external_exports,
425356
425815
  debugLogger,
425357
425816
  require_shell_quote,
425817
+ CommandParseCache,
425818
+ getActiveCommandParseCache,
425819
+ runWithCommandParseCache,
425358
425820
  ToolErrorType,
425359
425821
  isFatalToolError,
425360
425822
  GEMINI_DIR,
@@ -425473,19 +425935,31 @@ export {
425473
425935
  normalizeCommand,
425474
425936
  parseBashCommandDetails,
425475
425937
  parseCommandDetails,
425938
+ parseCommandDetailsAsync,
425939
+ isDefaultParseCommandDetails,
425476
425940
  getShellConfiguration,
425477
425941
  isWindows,
425478
425942
  escapeShellArg,
425479
425943
  hasRedirection,
425944
+ hasRedirectionAsync,
425480
425945
  hasUnresolvedShellExpansion,
425481
425946
  splitCommands,
425947
+ splitCommandsAsync,
425482
425948
  getCommandRoot,
425949
+ getCommandRootAsync,
425483
425950
  getCommandRoots,
425951
+ getCommandRootsAsync,
425952
+ isDefaultHasRedirection,
425953
+ isDefaultSplitCommands,
425954
+ isDefaultGetCommandRoots,
425484
425955
  stripShellWrapper,
425485
425956
  spawnAsync,
425486
425957
  execStreaming,
425487
425958
  detectCommandSubstitution,
425959
+ isKnownInteractiveGeminiCommandSync,
425488
425960
  isInteractiveGeminiCommand,
425961
+ isInteractiveGeminiCommandAsync,
425962
+ isDefaultIsInteractiveGeminiCommand,
425489
425963
  import_fixed_deque,
425490
425964
  import_lru_cache,
425491
425965
  import_lru_map_with_delete,