1+ import { ToolPolicy } from "@continuedev/terminal-security" ;
12import { Tool } from "../.." ;
3+ import { ResolvedPath , resolveInputPath } from "../../util/pathResolver" ;
24import { BUILT_IN_GROUP_NAME , BuiltInToolNames } from "../builtIn" ;
5+ import { evaluateFileAccessPolicy } from "../policies/fileAccess" ;
36
47export const readFileTool : Tool = {
58 type : "function" ,
@@ -21,7 +24,7 @@ export const readFileTool: Tool = {
2124 filepath : {
2225 type : "string" ,
2326 description :
24- "The path of the file to read, relative to the root of the workspace (NOT uri or absolute path) " ,
27+ "The path of the file to read. Can be a relative path (from workspace root), absolute path, tilde path (~/...), or file:// URI " ,
2528 } ,
2629 } ,
2730 } ,
@@ -32,4 +35,26 @@ export const readFileTool: Tool = {
3235 } ,
3336 defaultToolPolicy : "allowedWithoutPermission" ,
3437 toolCallIcon : "DocumentIcon" ,
38+ preprocessArgs : async ( args , { ide } ) => {
39+ const filepath = args . filepath as string ;
40+ const resolvedPath = await resolveInputPath ( ide , filepath ) ;
41+
42+ // Store the resolved path info in args for policy evaluation
43+ return {
44+ resolvedPath,
45+ } ;
46+ } ,
47+ evaluateToolCallPolicy : (
48+ basePolicy : ToolPolicy ,
49+ _ : Record < string , unknown > ,
50+ processedArgs ?: Record < string , unknown > ,
51+ ) : ToolPolicy => {
52+ const resolvedPath = processedArgs ?. resolvedPath as
53+ | ResolvedPath
54+ | null
55+ | undefined ;
56+ if ( ! resolvedPath ) return basePolicy ;
57+
58+ return evaluateFileAccessPolicy ( basePolicy , resolvedPath . isWithinWorkspace ) ;
59+ } ,
3560} ;
0 commit comments