( ctx context.Context, conn workspacesdk.AgentConn, args EditFilesArgs, resolvePlanPath func(context.Context) (chatPath string, home string, err error), )
| 123 | } |
| 124 | |
| 125 | func executeEditFilesTool( |
| 126 | ctx context.Context, |
| 127 | conn workspacesdk.AgentConn, |
| 128 | args EditFilesArgs, |
| 129 | resolvePlanPath func(context.Context) (chatPath string, home string, err error), |
| 130 | ) (fantasy.ToolResponse, error) { |
| 131 | if len(args.Files) == 0 { |
| 132 | return fantasy.NewTextErrorResponse("files is required"), nil |
| 133 | } |
| 134 | |
| 135 | var ( |
| 136 | chatPath string |
| 137 | home string |
| 138 | planPathErr error |
| 139 | planPathLoaded bool |
| 140 | ) |
| 141 | for i := range args.Files { |
| 142 | args.Files[i].Path = strings.TrimSpace(args.Files[i].Path) |
| 143 | file := args.Files[i] |
| 144 | |
| 145 | hasPlanFileName := looksLikePlanFileName(file.Path) |
| 146 | if hasPlanFileName && !isAbsolutePath(file.Path) { |
| 147 | return fantasy.NewTextErrorResponse( |
| 148 | "plan files must use absolute paths; use the chat-specific absolute plan path; no files in this batch were applied", |
| 149 | ), nil |
| 150 | } |
| 151 | if resolvePlanPath == nil || !hasPlanFileName { |
| 152 | continue |
| 153 | } |
| 154 | if !planPathLoaded { |
| 155 | chatPath, home, planPathErr = resolvePlanPath(ctx) |
| 156 | planPathLoaded = true |
| 157 | } |
| 158 | if resp, rejected := rejectSharedPlanPath(file.Path, home, chatPath, planPathErr); rejected { |
| 159 | return fantasy.NewTextErrorResponse( |
| 160 | resp.Content + "; no files in this batch were applied", |
| 161 | ), nil |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | resp, err := conn.EditFiles(ctx, workspacesdk.FileEditRequest{ |
| 166 | Files: args.toSDKFiles(), |
| 167 | IncludeDiff: true, |
| 168 | }) |
| 169 | if err != nil { |
| 170 | return fantasy.NewTextErrorResponse(err.Error()), nil |
| 171 | } |
| 172 | return toolResponse(map[string]any{ |
| 173 | "ok": true, |
| 174 | "files": resp.Files, |
| 175 | }), nil |
| 176 | } |
no test coverage detected