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

Function WriteFile

coderd/x/chatd/chattool/writefile.go:23–55  ·  view source on GitHub ↗
(options WriteFileOptions)

Source from the content-addressed store, hash-verified

21}
22
23func WriteFile(options WriteFileOptions) fantasy.AgentTool {
24 return fantasy.NewAgentTool(
25 "write_file",
26 "Write a file to the workspace.",
27 func(ctx context.Context, args WriteFileArgs, _ fantasy.ToolCall) (fantasy.ToolResponse, error) {
28 var planPath string
29 if options.IsPlanTurn {
30 args.Path = strings.TrimSpace(args.Path)
31 resolvedPlanPath, err := resolvePlanTurnPath(ctx, options.ResolvePlanPath)
32 if err != nil {
33 return fantasy.NewTextErrorResponse(err.Error()), nil
34 }
35 if args.Path != resolvedPlanPath {
36 return fantasy.NewTextErrorResponse("during plan turns, write_file is restricted to " + resolvedPlanPath), nil
37 }
38 planPath = resolvedPlanPath
39 }
40 if options.GetWorkspaceConn == nil {
41 return fantasy.NewTextErrorResponse("workspace connection resolver is not configured"), nil
42 }
43 conn, err := options.GetWorkspaceConn(ctx)
44 if err != nil {
45 return fantasy.NewTextErrorResponse(err.Error()), nil
46 }
47 if planPath != "" {
48 if err := ensurePlanPathResolvesToItself(ctx, conn, planPath); err != nil {
49 return fantasy.NewTextErrorResponse(err.Error()), nil
50 }
51 }
52 return executeWriteFileTool(ctx, conn, args, options.ResolvePlanPath)
53 },
54 )
55}
56
57func executeWriteFileTool(
58 ctx context.Context,

Callers 2

runChatMethod · 0.92
TestWriteFileFunction · 0.92

Calls 4

resolvePlanTurnPathFunction · 0.85
executeWriteFileToolFunction · 0.85
ErrorMethod · 0.45

Tested by 1

TestWriteFileFunction · 0.74