( ctx context.Context, conn workspacesdk.AgentConn, args WriteFileArgs, resolvePlanPath func(context.Context) (chatPath string, home string, err error), )
| 55 | } |
| 56 | |
| 57 | func executeWriteFileTool( |
| 58 | ctx context.Context, |
| 59 | conn workspacesdk.AgentConn, |
| 60 | args WriteFileArgs, |
| 61 | resolvePlanPath func(context.Context) (chatPath string, home string, err error), |
| 62 | ) (fantasy.ToolResponse, error) { |
| 63 | requestedPath := strings.TrimSpace(args.Path) |
| 64 | if requestedPath == "" { |
| 65 | return fantasy.NewTextErrorResponse("path is required"), nil |
| 66 | } |
| 67 | |
| 68 | hasPlanFileName := looksLikePlanFileName(requestedPath) |
| 69 | if hasPlanFileName && !isAbsolutePath(requestedPath) { |
| 70 | return fantasy.NewTextErrorResponse( |
| 71 | "plan files must use absolute paths; use the chat-specific absolute plan path", |
| 72 | ), nil |
| 73 | } |
| 74 | |
| 75 | if resolvePlanPath != nil && hasPlanFileName { |
| 76 | chatPath, home, err := resolvePlanPath(ctx) |
| 77 | if resp, rejected := rejectSharedPlanPath(requestedPath, home, chatPath, err); rejected { |
| 78 | return resp, nil |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | if err := conn.WriteFile(ctx, requestedPath, strings.NewReader(args.Content)); err != nil { |
| 83 | return fantasy.NewTextErrorResponse(err.Error()), nil |
| 84 | } |
| 85 | return toolResponse(map[string]any{"ok": true}), nil |
| 86 | } |
no test coverage detected