mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-12 21:03:05 -07:00
feat(plan): handle inconsistency in schedulers (#17813)
This commit is contained in:
@@ -4,10 +4,12 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { ToolErrorType } from '../tools/tool-error.js';
|
||||
import {
|
||||
ApprovalMode,
|
||||
PolicyDecision,
|
||||
type CheckResult,
|
||||
type PolicyRule,
|
||||
} from '../policy/types.js';
|
||||
import type { Config } from '../config/config.js';
|
||||
import type { MessageBus } from '../confirmation-bus/message-bus.js';
|
||||
@@ -24,6 +26,30 @@ import { DiscoveredMCPTool } from '../tools/mcp-tool.js';
|
||||
import { EDIT_TOOL_NAMES } from '../tools/tool-names.js';
|
||||
import type { ValidatingToolCall } from './types.js';
|
||||
|
||||
export const PLAN_MODE_DENIAL_MESSAGE =
|
||||
'You are in Plan Mode - adjust your prompt to only use read and search tools.';
|
||||
|
||||
/**
|
||||
* Helper to determine the error message and type for a policy denial.
|
||||
*/
|
||||
export function getPolicyDenialError(
|
||||
config: Config,
|
||||
rule?: PolicyRule,
|
||||
): { errorMessage: string; errorType: ToolErrorType } {
|
||||
if (config.getApprovalMode() === ApprovalMode.PLAN) {
|
||||
return {
|
||||
errorMessage: PLAN_MODE_DENIAL_MESSAGE,
|
||||
errorType: ToolErrorType.STOP_EXECUTION,
|
||||
};
|
||||
}
|
||||
|
||||
const denyMessage = rule?.denyMessage ? ` ${rule.denyMessage}` : '';
|
||||
return {
|
||||
errorMessage: `Tool execution denied by policy.${denyMessage}`,
|
||||
errorType: ToolErrorType.POLICY_VIOLATION,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries the system PolicyEngine to determine tool allowance.
|
||||
* @returns The PolicyDecision.
|
||||
|
||||
Reference in New Issue
Block a user