mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-16 13:00:39 -07:00
Implement background process monitoring and inspection tools (#23799)
This commit is contained in:
@@ -65,6 +65,7 @@ export interface ShellToolParams {
|
||||
description?: string;
|
||||
dir_path?: string;
|
||||
is_background?: boolean;
|
||||
delay_ms?: number;
|
||||
[PARAM_ADDITIONAL_PERMISSIONS]?: SandboxPermissions;
|
||||
}
|
||||
|
||||
@@ -521,6 +522,7 @@ export class ShellToolInvocation extends BaseToolInvocation<
|
||||
this.context.config.getEnableInteractiveShell(),
|
||||
{
|
||||
...shellExecutionConfig,
|
||||
sessionId: this.context.config?.getSessionId?.() ?? 'default',
|
||||
pager: 'cat',
|
||||
sanitizationConfig:
|
||||
shellExecutionConfig?.sanitizationConfig ??
|
||||
@@ -547,6 +549,7 @@ export class ShellToolInvocation extends BaseToolInvocation<
|
||||
},
|
||||
backgroundCompletionBehavior:
|
||||
this.context.config.getShellBackgroundCompletionBehavior(),
|
||||
originalCommand: strippedCommand,
|
||||
},
|
||||
);
|
||||
|
||||
@@ -556,10 +559,32 @@ export class ShellToolInvocation extends BaseToolInvocation<
|
||||
}
|
||||
|
||||
// If the model requested to run in the background, do so after a short delay.
|
||||
let completed = false;
|
||||
if (this.params.is_background) {
|
||||
resultPromise
|
||||
.then(() => {
|
||||
completed = true;
|
||||
})
|
||||
.catch(() => {
|
||||
completed = true; // Also mark completed if it failed
|
||||
});
|
||||
|
||||
const sessionId = this.context.config?.getSessionId?.() ?? 'default';
|
||||
const delay = this.params.delay_ms ?? BACKGROUND_DELAY_MS;
|
||||
setTimeout(() => {
|
||||
ShellExecutionService.background(pid);
|
||||
}, BACKGROUND_DELAY_MS);
|
||||
ShellExecutionService.background(pid, sessionId, strippedCommand);
|
||||
}, delay);
|
||||
|
||||
// Wait for the delay amount to see if command returns quickly
|
||||
await new Promise((resolve) => setTimeout(resolve, delay));
|
||||
|
||||
if (!completed) {
|
||||
// Return early with initial output if still running
|
||||
return {
|
||||
llmContent: `Command is running in background. PID: ${pid}. Initial output:\n${cumulativeOutput}`,
|
||||
returnDisplay: `Background process started with PID ${pid}.`,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user