@google/gemini-cli-core 0.70.0-preview.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.
- package/dist/docs/changelogs/index.md +23 -0
- package/dist/docs/changelogs/latest.md +112 -98
- package/dist/docs/changelogs/preview.md +82 -115
- package/dist/src/confirmation-bus/types.d.ts +1 -0
- package/dist/src/confirmation-bus/types.js.map +1 -1
- package/dist/src/generated/git-commit.d.ts +2 -2
- package/dist/src/generated/git-commit.js +2 -2
- package/dist/src/policy/policy-engine.d.ts +1 -0
- package/dist/src/policy/policy-engine.js +15 -6
- package/dist/src/policy/policy-engine.js.map +1 -1
- package/dist/src/sandbox/utils/commandUtils.js +35 -25
- package/dist/src/sandbox/utils/commandUtils.js.map +1 -1
- package/dist/src/sandbox/windows/WindowsSandboxManager.d.ts +1 -0
- package/dist/src/sandbox/windows/WindowsSandboxManager.js +9 -2
- package/dist/src/sandbox/windows/WindowsSandboxManager.js.map +1 -1
- package/dist/src/sandbox/windows/commandSafety.js +4 -2
- package/dist/src/sandbox/windows/commandSafety.js.map +1 -1
- package/dist/src/scheduler/policy.js +6 -0
- package/dist/src/scheduler/policy.js.map +1 -1
- package/dist/src/scheduler/scheduler.js +79 -59
- package/dist/src/scheduler/scheduler.js.map +1 -1
- package/dist/src/tools/shell-powershell-parsing.integration.test.d.ts +6 -0
- package/dist/src/tools/shell-powershell-parsing.integration.test.js +576 -0
- package/dist/src/tools/shell-powershell-parsing.integration.test.js.map +1 -0
- package/dist/src/tools/shell.d.ts +6 -1
- package/dist/src/tools/shell.js +281 -189
- package/dist/src/tools/shell.js.map +1 -1
- package/dist/src/tools/tools.d.ts +1 -0
- package/dist/src/tools/tools.js.map +1 -1
- package/dist/src/utils/shell-parse-cache.d.ts +37 -0
- package/dist/src/utils/shell-parse-cache.js +55 -0
- package/dist/src/utils/shell-parse-cache.js.map +1 -0
- package/dist/src/utils/shell-parse-cache.test.d.ts +6 -0
- package/dist/src/utils/shell-parse-cache.test.js +478 -0
- package/dist/src/utils/shell-parse-cache.test.js.map +1 -0
- package/dist/src/utils/shell-utils.d.ts +27 -29
- package/dist/src/utils/shell-utils.js +385 -89
- package/dist/src/utils/shell-utils.js.map +1 -1
- package/dist/src/utils/untrustedContextTracker.d.ts +2 -6
- package/dist/src/utils/untrustedContextTracker.js +65 -27
- package/dist/src/utils/untrustedContextTracker.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/src/tools/shell.js
CHANGED
|
@@ -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,
|
|
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
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
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
|
-
|
|
231
|
-
outcome === ToolConfirmationOutcome.
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
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:
|
|
300
|
+
commandPrefix: this.params.command,
|
|
244
301
|
allowRedirection,
|
|
245
302
|
...(allowCommandSubstitution !== undefined
|
|
246
303
|
? { allowCommandSubstitution }
|
|
247
304
|
: {}),
|
|
248
305
|
};
|
|
249
306
|
}
|
|
250
|
-
return
|
|
251
|
-
|
|
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
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
const
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
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
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
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
|
-
|
|
405
|
+
return super.shouldConfirmExecute(abortSignal, forcedDecision);
|
|
406
|
+
});
|
|
346
407
|
}
|
|
347
|
-
async getConfirmationDetails(
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
const
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
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
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
:
|
|
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
|
-
|
|
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
|
-
|
|
396
|
-
|
|
397
|
-
|
|
490
|
+
// Policy updates are now handled centrally by the scheduler
|
|
491
|
+
if (outcome === ToolConfirmationOutcome.Cancel ||
|
|
492
|
+
outcome === ToolConfirmationOutcome.ModifyWithEditor) {
|
|
493
|
+
return;
|
|
398
494
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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 =
|
|
1042
|
+
const outputSource = (await isRemoteContentCommandAsync(strippedCommand))
|
|
951
1043
|
? REMOTE_SHELL_OUTPUT_SOURCE
|
|
952
1044
|
: undefined;
|
|
953
1045
|
const executionError = result.error
|