MCPcopy Index your code
hub / github.com/coder/coder / executeWriteFileTool

Function executeWriteFileTool

coderd/x/chatd/chattool/writefile.go:57–86  ·  view source on GitHub ↗
(
	ctx context.Context,
	conn workspacesdk.AgentConn,
	args WriteFileArgs,
	resolvePlanPath func(context.Context) (chatPath string, home string, err error),
)

Source from the content-addressed store, hash-verified

55}
56
57func 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}

Callers 1

WriteFileFunction · 0.85

Calls 6

looksLikePlanFileNameFunction · 0.85
isAbsolutePathFunction · 0.85
rejectSharedPlanPathFunction · 0.85
toolResponseFunction · 0.85
WriteFileMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected