@google/gemini-cli-core 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 (56) hide show
  1. package/dist/docs/changelogs/index.md +46 -0
  2. package/dist/docs/changelogs/latest.md +82 -100
  3. package/dist/docs/changelogs/preview.md +82 -115
  4. package/dist/google-gemini-cli-core-0.71.0-nightly.20261118.g615d6bc8c.tgz +0 -0
  5. package/dist/src/confirmation-bus/types.d.ts +1 -0
  6. package/dist/src/confirmation-bus/types.js.map +1 -1
  7. package/dist/src/generated/git-commit.d.ts +2 -2
  8. package/dist/src/generated/git-commit.js +2 -2
  9. package/dist/src/generated/git-commit.js.map +1 -1
  10. package/dist/src/policy/policy-engine.d.ts +1 -0
  11. package/dist/src/policy/policy-engine.js +15 -6
  12. package/dist/src/policy/policy-engine.js.map +1 -1
  13. package/dist/src/sandbox/utils/commandUtils.js +35 -25
  14. package/dist/src/sandbox/utils/commandUtils.js.map +1 -1
  15. package/dist/src/sandbox/windows/WindowsSandboxManager.d.ts +1 -0
  16. package/dist/src/sandbox/windows/WindowsSandboxManager.js +9 -2
  17. package/dist/src/sandbox/windows/WindowsSandboxManager.js.map +1 -1
  18. package/dist/src/sandbox/windows/commandSafety.js +4 -2
  19. package/dist/src/sandbox/windows/commandSafety.js.map +1 -1
  20. package/dist/src/scheduler/policy.js +6 -0
  21. package/dist/src/scheduler/policy.js.map +1 -1
  22. package/dist/src/scheduler/scheduler.js +79 -59
  23. package/dist/src/scheduler/scheduler.js.map +1 -1
  24. package/dist/src/services/fileDiscoveryService.test.js +15 -0
  25. package/dist/src/services/fileDiscoveryService.test.js.map +1 -1
  26. package/dist/src/tools/shell-powershell-parsing.integration.test.d.ts +6 -0
  27. package/dist/src/tools/shell-powershell-parsing.integration.test.js +576 -0
  28. package/dist/src/tools/shell-powershell-parsing.integration.test.js.map +1 -0
  29. package/dist/src/tools/shell.d.ts +6 -1
  30. package/dist/src/tools/shell.js +281 -189
  31. package/dist/src/tools/shell.js.map +1 -1
  32. package/dist/src/tools/tools.d.ts +1 -0
  33. package/dist/src/tools/tools.js.map +1 -1
  34. package/dist/src/utils/gitIgnoreParser.js +33 -1
  35. package/dist/src/utils/gitIgnoreParser.js.map +1 -1
  36. package/dist/src/utils/gitIgnoreParser.test.js +32 -0
  37. package/dist/src/utils/gitIgnoreParser.test.js.map +1 -1
  38. package/dist/src/utils/ignorePathUtils.d.ts +1 -1
  39. package/dist/src/utils/ignorePathUtils.js +3 -2
  40. package/dist/src/utils/ignorePathUtils.js.map +1 -1
  41. package/dist/src/utils/ignorePathUtils.test.js +8 -0
  42. package/dist/src/utils/ignorePathUtils.test.js.map +1 -1
  43. package/dist/src/utils/shell-parse-cache.d.ts +37 -0
  44. package/dist/src/utils/shell-parse-cache.js +55 -0
  45. package/dist/src/utils/shell-parse-cache.js.map +1 -0
  46. package/dist/src/utils/shell-parse-cache.test.d.ts +6 -0
  47. package/dist/src/utils/shell-parse-cache.test.js +478 -0
  48. package/dist/src/utils/shell-parse-cache.test.js.map +1 -0
  49. package/dist/src/utils/shell-utils.d.ts +27 -29
  50. package/dist/src/utils/shell-utils.js +385 -89
  51. package/dist/src/utils/shell-utils.js.map +1 -1
  52. package/dist/src/utils/untrustedContextTracker.d.ts +2 -6
  53. package/dist/src/utils/untrustedContextTracker.js +65 -27
  54. package/dist/src/utils/untrustedContextTracker.js.map +1 -1
  55. package/dist/tsconfig.tsbuildinfo +1 -1
  56. package/package.json +1 -1
@@ -15,12 +15,13 @@ import { getErrorMessage } from '../utils/errors.js';
15
15
  import { summarizeToolOutput } from '../utils/summarizer.js';
16
16
  import { ShellExecutionService, } from '../services/shellExecutionService.js';
17
17
  import { formatBytes } from '../utils/formatters.js';
18
- import { getCommandRoots, initializeShellParsers, stripShellWrapper, parseCommandDetails, hasRedirection, detectCommandSubstitution, normalizeCommand, escapeShellArg, isInteractiveGeminiCommand, INTERACTIVE_GEMINI_SHELL_ERROR, } from '../utils/shell-utils.js';
18
+ import { getCommandRoots, getCommandRootsAsync, isDefaultGetCommandRoots, getShellConfiguration, initializeShellParsers, stripShellWrapper, parseCommandDetails, parseCommandDetailsAsync, isDefaultParseCommandDetails, hasRedirection, hasRedirectionAsync, isDefaultHasRedirection, detectCommandSubstitution, normalizeCommand, escapeShellArg, isInteractiveGeminiCommand, isInteractiveGeminiCommandAsync, isKnownInteractiveGeminiCommandSync, isDefaultIsInteractiveGeminiCommand, INTERACTIVE_GEMINI_SHELL_ERROR, } from '../utils/shell-utils.js';
19
+ import { CommandParseCache, runWithCommandParseCache, } from '../utils/shell-parse-cache.js';
19
20
  import { SHELL_TOOL_NAME } from './tool-names.js';
20
21
  import { PARAM_ADDITIONAL_PERMISSIONS } from './definitions/base-declarations.js';
21
22
  import { ApprovalMode, PolicyDecision } from '../policy/types.js';
22
23
  import { getToolCallContext } from '../utils/toolCallContext.js';
23
- import { acknowledgeUntrustedFlags, extractUntrustedContext, findUntrustedFlags, getUnacknowledgedUntrustedFlags, isBuildOrTestCommand, isRemoteContentCommand, getModifiedBuildFiles, resetModifiedBuildFiles, REMOTE_SHELL_OUTPUT_SOURCE, } from '../utils/untrustedContextTracker.js';
24
+ import { acknowledgeUntrustedFlags, extractUntrustedContext, findUntrustedFlags, getUnacknowledgedUntrustedFlags, isBuildOrTestCommand, isRemoteContentCommandAsync, getModifiedBuildFiles, resetModifiedBuildFiles, REMOTE_SHELL_OUTPUT_SOURCE, } from '../utils/untrustedContextTracker.js';
24
25
  import { getShellDefinition } from './definitions/coreTools.js';
25
26
  import { resolveToolDeclaration } from './definitions/resolver.js';
26
27
  import { toPathKey, isSubpath, resolveToRealPath } from '../utils/paths.js';
@@ -49,10 +50,54 @@ export class ShellToolInvocation extends BaseToolInvocation {
49
50
  context;
50
51
  proactivePermissionsConfirmed;
51
52
  confirmedCommand;
53
+ parseCache = new CommandParseCache();
52
54
  constructor(context, params, messageBus, _toolName, _toolDisplayName) {
53
55
  super(params, messageBus, _toolName, _toolDisplayName);
54
56
  this.context = context;
55
57
  }
58
+ runInCommandParseCache(fn) {
59
+ return runWithCommandParseCache(fn, this.parseCache);
60
+ }
61
+ async prepareCommandParseCache(signal) {
62
+ if (signal?.aborted ||
63
+ typeof stripShellWrapper !== 'function' ||
64
+ !isDefaultParseCommandDetails(parseCommandDetails)) {
65
+ return;
66
+ }
67
+ const rawCommand = this.params.command;
68
+ const stripped = stripShellWrapper(rawCommand);
69
+ let unwrapped = stripped;
70
+ for (let depth = 0; depth < 3; depth++) {
71
+ const next = stripShellWrapper(unwrapped);
72
+ if (next === unwrapped) {
73
+ break;
74
+ }
75
+ unwrapped = next;
76
+ }
77
+ await parseCommandDetailsAsync(stripped, this.parseCache, signal);
78
+ if (unwrapped !== stripped && !signal?.aborted) {
79
+ await parseCommandDetailsAsync(unwrapped, this.parseCache, signal);
80
+ }
81
+ }
82
+ hasCachedCommandParse(command) {
83
+ if (typeof getShellConfiguration !== 'function') {
84
+ return false;
85
+ }
86
+ const configuration = getShellConfiguration();
87
+ if (configuration.shell !== 'powershell') {
88
+ return true;
89
+ }
90
+ let unwrapped = command.trim();
91
+ for (let depth = 0; depth < 3; depth++) {
92
+ const next = stripShellWrapper(unwrapped);
93
+ if (next === unwrapped) {
94
+ break;
95
+ }
96
+ unwrapped = next;
97
+ }
98
+ return (this.parseCache.hasCompleted(configuration.executable, command) &&
99
+ this.parseCache.hasCompleted(configuration.executable, unwrapped));
100
+ }
56
101
  /**
57
102
  * Wraps a command in a subshell to capture background process IDs (PIDs)
58
103
  * using an EXIT trap. Uses newlines to prevent breaking heredocs or trailing
@@ -220,217 +265,244 @@ export class ShellToolInvocation extends BaseToolInvocation {
220
265
  return getUnacknowledgedUntrustedFlags(untrustedFlags, roots, config);
221
266
  }
222
267
  hasTaintedOrBuildFileRisk() {
223
- const command = stripShellWrapper(this.params.command);
224
- const untrustedFlags = this.getUntrustedFlags(command);
225
- const modifiedBuildFiles = getModifiedBuildFiles(this.context.config);
226
- const isBuildCmd = isBuildOrTestCommand(command);
227
- return (untrustedFlags.length > 0 || (isBuildCmd && modifiedBuildFiles.length > 0));
268
+ return this.runInCommandParseCache(() => {
269
+ const command = stripShellWrapper(this.params.command);
270
+ const untrustedFlags = this.getUntrustedFlags(command);
271
+ const modifiedBuildFiles = getModifiedBuildFiles(this.context.config);
272
+ const isBuildCmd = isBuildOrTestCommand(command);
273
+ return (untrustedFlags.length > 0 ||
274
+ (isBuildCmd && modifiedBuildFiles.length > 0));
275
+ });
228
276
  }
229
277
  getPolicyUpdateOptions(outcome) {
230
- if (outcome === ToolConfirmationOutcome.ProceedAlwaysAndSave ||
231
- outcome === ToolConfirmationOutcome.ProceedAlways) {
232
- const command = stripShellWrapper(this.params.command);
233
- if (this.hasTaintedOrBuildFileRisk()) {
234
- return undefined;
235
- }
236
- const rootCommands = [...new Set(getCommandRoots(command))];
237
- const allowRedirection = hasRedirection(command) ? true : undefined;
238
- const allowCommandSubstitution = detectCommandSubstitution(command)
239
- ? true
240
- : undefined;
241
- if (rootCommands.length > 0) {
278
+ return this.runInCommandParseCache(() => {
279
+ if (outcome === ToolConfirmationOutcome.ProceedAlwaysAndSave ||
280
+ outcome === ToolConfirmationOutcome.ProceedAlways) {
281
+ const command = stripShellWrapper(this.params.command);
282
+ if (this.hasTaintedOrBuildFileRisk()) {
283
+ return undefined;
284
+ }
285
+ const rootCommands = [...new Set(getCommandRoots(command))];
286
+ const allowRedirection = hasRedirection(command) ? true : undefined;
287
+ const allowCommandSubstitution = detectCommandSubstitution(command)
288
+ ? true
289
+ : undefined;
290
+ if (rootCommands.length > 0) {
291
+ return {
292
+ commandPrefix: rootCommands,
293
+ allowRedirection,
294
+ ...(allowCommandSubstitution !== undefined
295
+ ? { allowCommandSubstitution }
296
+ : {}),
297
+ };
298
+ }
242
299
  return {
243
- commandPrefix: rootCommands,
300
+ commandPrefix: this.params.command,
244
301
  allowRedirection,
245
302
  ...(allowCommandSubstitution !== undefined
246
303
  ? { allowCommandSubstitution }
247
304
  : {}),
248
305
  };
249
306
  }
250
- return {
251
- commandPrefix: this.params.command,
252
- allowRedirection,
253
- ...(allowCommandSubstitution !== undefined
254
- ? { allowCommandSubstitution }
255
- : {}),
256
- };
257
- }
258
- return undefined;
307
+ return undefined;
308
+ });
259
309
  }
260
310
  async shouldConfirmExecute(abortSignal, forcedDecision) {
261
- if (isInteractiveGeminiCommand(stripShellWrapper(this.params.command))) {
262
- return false;
263
- }
264
- if (forcedDecision === 'deny') {
265
- return super.shouldConfirmExecute(abortSignal, forcedDecision);
266
- }
267
- if (this.hasTaintedOrBuildFileRisk()) {
268
- return this.getConfirmationDetails(abortSignal);
269
- }
270
- if (this.context.config.getApprovalMode() === ApprovalMode.YOLO &&
271
- forcedDecision !== 'ask_user') {
272
- return super.shouldConfirmExecute(abortSignal, forcedDecision);
273
- }
274
- if (this.params[PARAM_ADDITIONAL_PERMISSIONS]) {
275
- return this.getConfirmationDetails(abortSignal);
276
- }
277
- if (this.context.config.getSandboxEnabled()) {
278
- const command = stripShellWrapper(this.params.command);
279
- const rootCommands = getCommandRoots(command);
280
- const rawRootCommand = rootCommands[0];
281
- if (rawRootCommand) {
282
- const rootCommand = normalizeCommand(rawRootCommand);
283
- const proactive = await getProactiveToolSuggestions(rootCommand);
284
- if (proactive) {
285
- const mode = this.context.config.getApprovalMode();
286
- const modeConfig = this.context.config.sandboxPolicyManager.getModeConfig(mode);
287
- const approved = this.context.config.sandboxPolicyManager.getCommandPermissions(rootCommand);
288
- const hasNetwork = modeConfig.network || approved.network;
289
- const missingNetwork = !!proactive.network && !hasNetwork;
290
- // Detect commands or sub-commands that definitely need network
291
- const parsed = parseCommandDetails(command);
292
- const subCommand = parsed?.details[0]?.args?.[0];
293
- const needsNetwork = isNetworkReliantCommand(rootCommand, subCommand);
294
- if (needsNetwork) {
295
- // Add write permission to the current directory if we are in readonly mode
296
- const isReadonlyMode = modeConfig.readonly ?? false;
297
- if (isReadonlyMode) {
298
- const cwd = this.params.dir_path || this.context.config.getTargetDir();
299
- proactive.fileSystem = proactive.fileSystem || {
300
- read: [],
301
- write: [],
302
- };
303
- proactive.fileSystem.write = proactive.fileSystem.write || [];
304
- if (!proactive.fileSystem.write.includes(cwd)) {
305
- proactive.fileSystem.write.push(cwd);
306
- proactive.fileSystem.read = proactive.fileSystem.read || [];
307
- if (!proactive.fileSystem.read.includes(cwd)) {
308
- proactive.fileSystem.read.push(cwd);
311
+ return this.runInCommandParseCache(async () => {
312
+ await this.prepareCommandParseCache(abortSignal);
313
+ const strippedForInteractiveCheck = stripShellWrapper(this.params.command);
314
+ const isInteractive = isDefaultIsInteractiveGeminiCommand(isInteractiveGeminiCommand)
315
+ ? await isInteractiveGeminiCommandAsync(strippedForInteractiveCheck, this.parseCache, abortSignal)
316
+ : isInteractiveGeminiCommand(strippedForInteractiveCheck);
317
+ if (isInteractive) {
318
+ return false;
319
+ }
320
+ if (forcedDecision === 'deny') {
321
+ return super.shouldConfirmExecute(abortSignal, forcedDecision);
322
+ }
323
+ if (this.hasTaintedOrBuildFileRisk()) {
324
+ return this.getConfirmationDetails(abortSignal);
325
+ }
326
+ if (this.context.config.getApprovalMode() === ApprovalMode.YOLO &&
327
+ forcedDecision !== 'ask_user') {
328
+ return super.shouldConfirmExecute(abortSignal, forcedDecision);
329
+ }
330
+ if (this.params[PARAM_ADDITIONAL_PERMISSIONS]) {
331
+ return this.getConfirmationDetails(abortSignal);
332
+ }
333
+ if (this.context.config.getSandboxEnabled()) {
334
+ const command = stripShellWrapper(this.params.command);
335
+ const rootCommands = isDefaultGetCommandRoots(getCommandRoots)
336
+ ? await getCommandRootsAsync(command, this.parseCache, abortSignal)
337
+ : getCommandRoots(command);
338
+ const rawRootCommand = rootCommands[0];
339
+ if (rawRootCommand) {
340
+ const rootCommand = normalizeCommand(rawRootCommand);
341
+ const proactive = await getProactiveToolSuggestions(rootCommand);
342
+ if (proactive) {
343
+ const mode = this.context.config.getApprovalMode();
344
+ const modeConfig = this.context.config.sandboxPolicyManager.getModeConfig(mode);
345
+ const approved = this.context.config.sandboxPolicyManager.getCommandPermissions(rootCommand);
346
+ const hasNetwork = modeConfig.network || approved.network;
347
+ const missingNetwork = !!proactive.network && !hasNetwork;
348
+ // Detect commands or sub-commands that definitely need network
349
+ const parsed = isDefaultParseCommandDetails(parseCommandDetails)
350
+ ? await parseCommandDetailsAsync(command, this.parseCache, abortSignal)
351
+ : parseCommandDetails(command);
352
+ const subCommand = parsed?.details[0]?.args?.[0];
353
+ const needsNetwork = isNetworkReliantCommand(rootCommand, subCommand);
354
+ if (needsNetwork) {
355
+ // Add write permission to the current directory if we are in readonly mode
356
+ const isReadonlyMode = modeConfig.readonly ?? false;
357
+ if (isReadonlyMode) {
358
+ const cwd = this.params.dir_path || this.context.config.getTargetDir();
359
+ proactive.fileSystem = proactive.fileSystem || {
360
+ read: [],
361
+ write: [],
362
+ };
363
+ proactive.fileSystem.write = proactive.fileSystem.write || [];
364
+ if (!proactive.fileSystem.write.includes(cwd)) {
365
+ proactive.fileSystem.write.push(cwd);
366
+ proactive.fileSystem.read = proactive.fileSystem.read || [];
367
+ if (!proactive.fileSystem.read.includes(cwd)) {
368
+ proactive.fileSystem.read.push(cwd);
369
+ }
309
370
  }
310
371
  }
311
- }
312
- const isApproved = (requestedPath, approvedPaths) => {
313
- if (!approvedPaths || approvedPaths.length === 0)
314
- return false;
315
- const requestedRealIdentity = toPathKey(resolveToRealPath(requestedPath));
316
- // Identity check is fast, subpath check is slower
317
- return approvedPaths.some((p) => {
318
- const approvedRealIdentity = toPathKey(resolveToRealPath(p));
319
- return (requestedRealIdentity === approvedRealIdentity ||
320
- isSubpath(approvedRealIdentity, requestedRealIdentity));
321
- });
322
- };
323
- const missingRead = (proactive.fileSystem?.read || []).filter((p) => !isApproved(p, approved.fileSystem?.read));
324
- const missingWrite = (proactive.fileSystem?.write || []).filter((p) => !isApproved(p, approved.fileSystem?.write));
325
- const needsExpansion = missingRead.length > 0 ||
326
- missingWrite.length > 0 ||
327
- missingNetwork;
328
- if (needsExpansion) {
329
- const details = await this.getConfirmationDetails(abortSignal, proactive);
330
- if (details && details.type === 'sandbox_expansion') {
331
- const originalOnConfirm = details.onConfirm;
332
- details.onConfirm = async (outcome) => {
333
- await originalOnConfirm(outcome);
334
- if (outcome !== ToolConfirmationOutcome.Cancel) {
335
- this.proactivePermissionsConfirmed = proactive;
336
- }
337
- };
372
+ const isApproved = (requestedPath, approvedPaths) => {
373
+ if (!approvedPaths || approvedPaths.length === 0)
374
+ return false;
375
+ const requestedRealIdentity = toPathKey(resolveToRealPath(requestedPath));
376
+ // Identity check is fast, subpath check is slower
377
+ return approvedPaths.some((p) => {
378
+ const approvedRealIdentity = toPathKey(resolveToRealPath(p));
379
+ return (requestedRealIdentity === approvedRealIdentity ||
380
+ isSubpath(approvedRealIdentity, requestedRealIdentity));
381
+ });
382
+ };
383
+ const missingRead = (proactive.fileSystem?.read || []).filter((p) => !isApproved(p, approved.fileSystem?.read));
384
+ const missingWrite = (proactive.fileSystem?.write || []).filter((p) => !isApproved(p, approved.fileSystem?.write));
385
+ const needsExpansion = missingRead.length > 0 ||
386
+ missingWrite.length > 0 ||
387
+ missingNetwork;
388
+ if (needsExpansion) {
389
+ const details = await this.getConfirmationDetails(abortSignal, proactive);
390
+ if (details && details.type === 'sandbox_expansion') {
391
+ const originalOnConfirm = details.onConfirm;
392
+ details.onConfirm = async (outcome) => {
393
+ await originalOnConfirm(outcome);
394
+ if (outcome !== ToolConfirmationOutcome.Cancel) {
395
+ this.proactivePermissionsConfirmed = proactive;
396
+ }
397
+ };
398
+ }
399
+ return details;
338
400
  }
339
- return details;
340
401
  }
341
402
  }
342
403
  }
343
404
  }
344
- }
345
- return super.shouldConfirmExecute(abortSignal, forcedDecision);
405
+ return super.shouldConfirmExecute(abortSignal, forcedDecision);
406
+ });
346
407
  }
347
- async getConfirmationDetails(_abortSignal, proactivePermissions) {
348
- const command = stripShellWrapper(this.params.command);
349
- const parsed = parseCommandDetails(command);
350
- let rootCommandDisplay = '';
351
- if (!parsed || parsed.hasError || parsed.details.length === 0) {
352
- // Fallback if parser fails
353
- const fallback = command.trim().split(/\s+/)[0];
354
- rootCommandDisplay = fallback || 'shell command';
355
- if (hasRedirection(command)) {
356
- rootCommandDisplay += ', redirection';
408
+ async getConfirmationDetails(abortSignal, proactivePermissions) {
409
+ return this.runInCommandParseCache(async () => {
410
+ const command = stripShellWrapper(this.params.command);
411
+ const parsed = isDefaultParseCommandDetails(parseCommandDetails)
412
+ ? await parseCommandDetailsAsync(command, this.parseCache, abortSignal)
413
+ : parseCommandDetails(command);
414
+ const commandHasRedirection = isDefaultHasRedirection(hasRedirection)
415
+ ? await hasRedirectionAsync(command, this.parseCache, abortSignal)
416
+ : hasRedirection(command);
417
+ let rootCommandDisplay = '';
418
+ if (!parsed || parsed.hasError || parsed.details.length === 0) {
419
+ // Fallback if parser fails
420
+ const fallback = command.trim().split(/\s+/)[0];
421
+ rootCommandDisplay = fallback || 'shell command';
422
+ if (commandHasRedirection) {
423
+ rootCommandDisplay += ', redirection';
424
+ }
357
425
  }
358
- }
359
- else {
360
- rootCommandDisplay = parsed.details
361
- .map((detail) => detail.name)
362
- .join(', ');
363
- }
364
- let rootCommands = [];
365
- try {
366
- rootCommands = [...new Set(getCommandRoots(command))];
367
- }
368
- catch {
369
- rootCommands = [command.trim().split(/\s+/)[0] || 'shell'];
370
- }
371
- const rootCommand = rootCommands[0] || 'shell';
372
- const untrustedFlags = this.getUntrustedFlags(command);
373
- const modifiedBuildFiles = getModifiedBuildFiles(this.context.config);
374
- const isBuildCmd = isBuildOrTestCommand(command);
375
- const hasSecurityWarning = untrustedFlags.length > 0 ||
376
- (isBuildCmd && modifiedBuildFiles.length > 0);
377
- // Proactively suggest expansion for known network-heavy tools (npm install, etc.)
378
- // to avoid hangs when network is restricted by default.
379
- const effectiveAdditionalPermissions = this.params[PARAM_ADDITIONAL_PERMISSIONS] || proactivePermissions;
380
- // Rely entirely on PolicyEngine for interactive confirmation.
381
- // If we are here, it means PolicyEngine returned ASK_USER (or no message bus),
382
- // so we must provide confirmation details.
383
- // If additional_permissions are provided, and no security warnings are present,
384
- // it's an expansion request
385
- if (effectiveAdditionalPermissions && !hasSecurityWarning) {
386
- return {
387
- type: 'sandbox_expansion',
388
- title: proactivePermissions
389
- ? 'Sandbox Expansion Request (Recommended)'
390
- : 'Sandbox Expansion Request',
426
+ else {
427
+ rootCommandDisplay = parsed.details
428
+ .map((detail) => detail.name)
429
+ .join(', ');
430
+ }
431
+ let rootCommands = [];
432
+ try {
433
+ const computedRoots = isDefaultGetCommandRoots(getCommandRoots)
434
+ ? await getCommandRootsAsync(command, this.parseCache, abortSignal)
435
+ : getCommandRoots(command);
436
+ rootCommands = [...new Set(computedRoots)];
437
+ }
438
+ catch {
439
+ rootCommands = [command.trim().split(/\s+/)[0] || 'shell'];
440
+ }
441
+ const rootCommand = rootCommands[0] || 'shell';
442
+ const untrustedFlags = this.getUntrustedFlags(command);
443
+ const modifiedBuildFiles = getModifiedBuildFiles(this.context.config);
444
+ const isBuildCmd = isBuildOrTestCommand(command);
445
+ const hasSecurityWarning = untrustedFlags.length > 0 ||
446
+ (isBuildCmd && modifiedBuildFiles.length > 0);
447
+ // Proactively suggest expansion for known network-heavy tools (npm install, etc.)
448
+ // to avoid hangs when network is restricted by default.
449
+ const effectiveAdditionalPermissions = this.params[PARAM_ADDITIONAL_PERMISSIONS] || proactivePermissions;
450
+ // Rely entirely on PolicyEngine for interactive confirmation.
451
+ // If we are here, it means PolicyEngine returned ASK_USER (or no message bus),
452
+ // so we must provide confirmation details.
453
+ // If additional_permissions are provided, and no security warnings are present,
454
+ // it's an expansion request
455
+ if (effectiveAdditionalPermissions && !hasSecurityWarning) {
456
+ return {
457
+ type: 'sandbox_expansion',
458
+ title: proactivePermissions
459
+ ? 'Sandbox Expansion Request (Recommended)'
460
+ : 'Sandbox Expansion Request',
461
+ command: this.params.command,
462
+ rootCommand: rootCommandDisplay,
463
+ additionalPermissions: effectiveAdditionalPermissions,
464
+ onConfirm: async (outcome) => {
465
+ if (outcome !== ToolConfirmationOutcome.Cancel &&
466
+ outcome !== ToolConfirmationOutcome.ModifyWithEditor) {
467
+ this.confirmedCommand = this.params.command;
468
+ }
469
+ if (outcome === ToolConfirmationOutcome.ProceedAlwaysAndSave) {
470
+ this.context.config.sandboxPolicyManager.addPersistentApproval(rootCommand, effectiveAdditionalPermissions);
471
+ }
472
+ else if (outcome === ToolConfirmationOutcome.ProceedAlways) {
473
+ this.context.config.sandboxPolicyManager.addSessionApproval(rootCommand, effectiveAdditionalPermissions);
474
+ }
475
+ },
476
+ };
477
+ }
478
+ const confirmationDetails = {
479
+ type: 'exec',
480
+ title: 'Confirm Shell Command',
391
481
  command: this.params.command,
392
482
  rootCommand: rootCommandDisplay,
393
- additionalPermissions: effectiveAdditionalPermissions,
483
+ rootCommands,
484
+ hasRedirection: commandHasRedirection,
485
+ untrustedFlags: untrustedFlags.length > 0 ? untrustedFlags : undefined,
486
+ modifiedBuildFiles: isBuildCmd && modifiedBuildFiles.length > 0
487
+ ? modifiedBuildFiles
488
+ : undefined,
394
489
  onConfirm: async (outcome) => {
395
- if (outcome !== ToolConfirmationOutcome.Cancel &&
396
- outcome !== ToolConfirmationOutcome.ModifyWithEditor) {
397
- this.confirmedCommand = this.params.command;
490
+ // Policy updates are now handled centrally by the scheduler
491
+ if (outcome === ToolConfirmationOutcome.Cancel ||
492
+ outcome === ToolConfirmationOutcome.ModifyWithEditor) {
493
+ return;
398
494
  }
399
- if (outcome === ToolConfirmationOutcome.ProceedAlwaysAndSave) {
400
- this.context.config.sandboxPolicyManager.addPersistentApproval(rootCommand, effectiveAdditionalPermissions);
401
- }
402
- else if (outcome === ToolConfirmationOutcome.ProceedAlways) {
403
- this.context.config.sandboxPolicyManager.addSessionApproval(rootCommand, effectiveAdditionalPermissions);
495
+ this.confirmedCommand = this.params.command;
496
+ // Remember approved flags and the reviewed build file state for the
497
+ // rest of the session so identical follow-up commands do not prompt.
498
+ acknowledgeUntrustedFlags(untrustedFlags, rootCommands, this.context.config);
499
+ if (isBuildCmd && modifiedBuildFiles.length > 0) {
500
+ resetModifiedBuildFiles(this.context.config);
404
501
  }
405
502
  },
406
503
  };
407
- }
408
- const confirmationDetails = {
409
- type: 'exec',
410
- title: 'Confirm Shell Command',
411
- command: this.params.command,
412
- rootCommand: rootCommandDisplay,
413
- rootCommands,
414
- untrustedFlags: untrustedFlags.length > 0 ? untrustedFlags : undefined,
415
- modifiedBuildFiles: isBuildCmd && modifiedBuildFiles.length > 0
416
- ? modifiedBuildFiles
417
- : undefined,
418
- onConfirm: async (outcome) => {
419
- // Policy updates are now handled centrally by the scheduler
420
- if (outcome === ToolConfirmationOutcome.Cancel ||
421
- outcome === ToolConfirmationOutcome.ModifyWithEditor) {
422
- return;
423
- }
424
- this.confirmedCommand = this.params.command;
425
- // Remember approved flags and the reviewed build file state for the
426
- // rest of the session so identical follow-up commands do not prompt.
427
- acknowledgeUntrustedFlags(untrustedFlags, rootCommands, this.context.config);
428
- if (isBuildCmd && modifiedBuildFiles.length > 0) {
429
- resetModifiedBuildFiles(this.context.config);
430
- }
431
- },
432
- };
433
- return confirmationDetails;
504
+ return confirmationDetails;
505
+ });
434
506
  }
435
507
  async isCommandSubstitutionAllowed(options) {
436
508
  if ((options.isClientInitiated ?? false) ||
@@ -438,6 +510,7 @@ export class ShellToolInvocation extends BaseToolInvocation {
438
510
  this.confirmedCommand === this.params.command) {
439
511
  return true;
440
512
  }
513
+ await this.prepareCommandParseCache(options.abortSignal);
441
514
  if (this.hasTaintedOrBuildFileRisk()) {
442
515
  return false;
443
516
  }
@@ -453,9 +526,25 @@ export class ShellToolInvocation extends BaseToolInvocation {
453
526
  return this.context.config?.getApprovalMode?.() === ApprovalMode.YOLO;
454
527
  }
455
528
  async execute(options) {
529
+ return this.runInCommandParseCache(() => this.executeInternal(options));
530
+ }
531
+ async executeInternal(options) {
456
532
  const { abortSignal: signal, updateOutput, shellExecutionConfig, setExecutionIdCallback, } = options;
457
533
  const strippedCommand = stripShellWrapper(this.params.command);
458
- if (isInteractiveGeminiCommand(strippedCommand)) {
534
+ let isInteractiveGemini;
535
+ if (!isDefaultIsInteractiveGeminiCommand(isInteractiveGeminiCommand)) {
536
+ isInteractiveGemini = isInteractiveGeminiCommand(strippedCommand);
537
+ }
538
+ else if (this.hasCachedCommandParse(strippedCommand)) {
539
+ isInteractiveGemini = isInteractiveGeminiCommand(strippedCommand, this.parseCache);
540
+ }
541
+ else {
542
+ const knownInteractive = isKnownInteractiveGeminiCommandSync(strippedCommand);
543
+ isInteractiveGemini =
544
+ knownInteractive ??
545
+ (await isInteractiveGeminiCommandAsync(strippedCommand, this.parseCache, signal));
546
+ }
547
+ if (isInteractiveGemini) {
459
548
  return {
460
549
  llmContent: INTERACTIVE_GEMINI_SHELL_ERROR,
461
550
  returnDisplay: INTERACTIVE_GEMINI_SHELL_ERROR,
@@ -842,7 +931,10 @@ export class ShellToolInvocation extends BaseToolInvocation {
842
931
  const sandboxDenial = this.context.config.sandboxManager.parseDenials(result);
843
932
  if (sandboxDenial) {
844
933
  const strippedCommand = stripShellWrapper(this.params.command);
845
- const rootCommands = getCommandRoots(strippedCommand).filter((r) => r !== 'shopt');
934
+ const computedRootCommands = isDefaultGetCommandRoots(getCommandRoots)
935
+ ? await getCommandRootsAsync(strippedCommand, this.parseCache)
936
+ : getCommandRoots(strippedCommand);
937
+ const rootCommands = computedRootCommands.filter((r) => r !== 'shopt');
846
938
  const rootCommandDisplay = rootCommands.length > 0 ? rootCommands[0] : 'shell';
847
939
  const readPaths = new Set(this.params[PARAM_ADDITIONAL_PERMISSIONS]?.fileSystem?.read || []);
848
940
  const writePaths = new Set(this.params[PARAM_ADDITIONAL_PERMISSIONS]?.fileSystem?.write || []);
@@ -947,7 +1039,7 @@ export class ShellToolInvocation extends BaseToolInvocation {
947
1039
  }
948
1040
  }
949
1041
  const summarizeConfig = this.context.config.getSummarizeToolOutputConfig();
950
- const outputSource = isRemoteContentCommand(strippedCommand)
1042
+ const outputSource = (await isRemoteContentCommandAsync(strippedCommand))
951
1043
  ? REMOTE_SHELL_OUTPUT_SOURCE
952
1044
  : undefined;
953
1045
  const executionError = result.error