@@ -85,6 +85,23 @@ func NewDefaultToolsetRegistry() *ToolsetRegistry {
8585 return r
8686}
8787
88+ // resolveToolsetPath expands shell patterns (~, env vars) in the given path,
89+ // then validates it relative to the working directory or parent directory.
90+ func resolveToolsetPath (toolsetPath , parentDir string , runConfig * config.RuntimeConfig ) (string , error ) {
91+ toolsetPath = path .ExpandPath (toolsetPath )
92+
93+ var basePath string
94+ if filepath .IsAbs (toolsetPath ) {
95+ basePath = ""
96+ } else if wd := runConfig .WorkingDir ; wd != "" {
97+ basePath = wd
98+ } else {
99+ basePath = parentDir
100+ }
101+
102+ return path .ValidatePathInDirectory (toolsetPath , basePath )
103+ }
104+
88105func createTodoTool (_ context.Context , toolset latest.Toolset , _ string , _ * config.RuntimeConfig , _ string ) (tools.ToolSet , error ) {
89106 if toolset .Shared {
90107 return builtin .NewSharedTodoTool (), nil
@@ -98,16 +115,7 @@ func createTasksTool(_ context.Context, toolset latest.Toolset, parentDir string
98115 toolsetPath = "tasks.json"
99116 }
100117
101- var basePath string
102- if filepath .IsAbs (toolsetPath ) {
103- basePath = ""
104- } else if wd := runConfig .WorkingDir ; wd != "" {
105- basePath = wd
106- } else {
107- basePath = parentDir
108- }
109-
110- validatedPath , err := path .ValidatePathInDirectory (toolsetPath , basePath )
118+ validatedPath , err := resolveToolsetPath (toolsetPath , parentDir , runConfig )
111119 if err != nil {
112120 return nil , fmt .Errorf ("invalid tasks storage path: %w" , err )
113121 }
@@ -122,18 +130,8 @@ func createMemoryTool(_ context.Context, toolset latest.Toolset, parentDir strin
122130 var validatedMemoryPath string
123131
124132 if toolset .Path != "" {
125- // Explicit path provided - resolve relative to working dir or parent dir
126- var basePath string
127- if filepath .IsAbs (toolset .Path ) {
128- basePath = ""
129- } else if wd := runConfig .WorkingDir ; wd != "" {
130- basePath = wd
131- } else {
132- basePath = parentDir
133- }
134-
135133 var err error
136- validatedMemoryPath , err = path . ValidatePathInDirectory (toolset .Path , basePath )
134+ validatedMemoryPath , err = resolveToolsetPath (toolset .Path , parentDir , runConfig )
137135 if err != nil {
138136 return nil , fmt .Errorf ("invalid memory database path: %w" , err )
139137 }
0 commit comments