feat(plan): handle inconsistency in schedulers (#17813)

This commit is contained in:
Adib234
2026-02-02 22:10:04 -05:00
committed by GitHub
parent 18cce6a9ab
commit 01e33465bd
6 changed files with 188 additions and 25 deletions
+26
View File
@@ -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.