mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 12:21:13 -05:00
Validation fixes
This commit is contained in:
@@ -1142,17 +1142,25 @@ export class Cline {
|
||||
await this.browserSession.closeBrowser()
|
||||
}
|
||||
|
||||
// Validate tool use before execution
|
||||
const { mode } = (await this.providerRef.deref()?.getState()) ?? {}
|
||||
const { customModes } = (await this.providerRef.deref()?.getState()) ?? {}
|
||||
try {
|
||||
validateToolUse(block.name as ToolName, mode ?? defaultModeSlug, customModes ?? [], {
|
||||
apply_diff: this.diffEnabled,
|
||||
})
|
||||
} catch (error) {
|
||||
this.consecutiveMistakeCount++
|
||||
pushToolResult(formatResponse.toolError(error.message))
|
||||
break
|
||||
// Only validate complete tool uses
|
||||
if (!block.partial) {
|
||||
const { mode } = (await this.providerRef.deref()?.getState()) ?? {}
|
||||
const { customModes } = (await this.providerRef.deref()?.getState()) ?? {}
|
||||
try {
|
||||
validateToolUse(
|
||||
block.name as ToolName,
|
||||
mode ?? defaultModeSlug,
|
||||
customModes ?? [],
|
||||
{
|
||||
apply_diff: this.diffEnabled,
|
||||
},
|
||||
block.params,
|
||||
)
|
||||
} catch (error) {
|
||||
this.consecutiveMistakeCount++
|
||||
pushToolResult(formatResponse.toolError(error.message))
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
switch (block.name) {
|
||||
|
||||
@@ -22,7 +22,7 @@ const GroupOptionsSchema = z.object({
|
||||
},
|
||||
{ message: "Invalid regular expression pattern" },
|
||||
),
|
||||
fileRegexDescription: z.string().optional(),
|
||||
description: z.string().optional(),
|
||||
})
|
||||
|
||||
// Schema for a group entry - either a tool group string or a tuple of [group, options]
|
||||
|
||||
@@ -135,7 +135,7 @@ describe("CustomModeSchema", () => {
|
||||
roleDefinition: "Documentation editing mode",
|
||||
groups: [
|
||||
"read",
|
||||
["edit", { fileRegex: "\\.(md|txt)$", fileRegexDescription: "Documentation files only" }],
|
||||
["edit", { fileRegex: "\\.(md|txt)$", description: "Documentation files only" }],
|
||||
"browser",
|
||||
],
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Mode, isToolAllowedForMode, getModeConfig, ModeConfig } from "../shared/modes"
|
||||
import { Mode, isToolAllowedForMode, getModeConfig, ModeConfig, FileRestrictionError } from "../shared/modes"
|
||||
import { ToolName } from "../shared/tool-groups"
|
||||
|
||||
export { isToolAllowedForMode }
|
||||
@@ -9,8 +9,9 @@ export function validateToolUse(
|
||||
mode: Mode,
|
||||
customModes?: ModeConfig[],
|
||||
toolRequirements?: Record<string, boolean>,
|
||||
toolParams?: Record<string, unknown>,
|
||||
): void {
|
||||
if (!isToolAllowedForMode(toolName, mode, customModes ?? [], toolRequirements)) {
|
||||
if (!isToolAllowedForMode(toolName, mode, customModes ?? [], toolRequirements, toolParams)) {
|
||||
throw new Error(`Tool "${toolName}" is not allowed in ${mode} mode.`)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user