MCPcopy Index your code
hub / github.com/coder/mux / createFileEditInsertTool

Function createFileEditInsertTool

src/node/services/tools/file_edit_insert.ts:47–136  ·  view source on GitHub ↗
(config: ToolConfiguration)

Source from the content-addressed store, hash-verified

45}
46
47export const createFileEditInsertTool: ToolFactory = (config: ToolConfiguration) => {
48 return tool({
49 description: TOOL_DEFINITIONS.file_edit_insert.description,
50 inputSchema: TOOL_DEFINITIONS.file_edit_insert.schema,
51 execute: async (
52 { path, content, insert_before, insert_after }: FileEditInsertToolArgs,
53 { abortSignal }
54 ): Promise<FileEditInsertToolResult> => {
55 try {
56 const {
57 correctedPath,
58 warning: pathWarning,
59 resolvedPath,
60 } = resolvePathWithinCwd(path, config.cwd, config.runtime);
61 path = correctedPath;
62
63 // Validate plan mode access restrictions
64 const planModeError = await validatePlanModeAccess(path, config);
65 if (planModeError) {
66 return planModeError;
67 }
68
69 const exists = await fileExists(config.runtime, resolvedPath, abortSignal);
70
71 if (!exists) {
72 try {
73 await writeFileString(config.runtime, resolvedPath, content, abortSignal);
74 } catch (err) {
75 if (err instanceof RuntimeError) {
76 return {
77 success: false,
78 error: err.message,
79 };
80 }
81 throw err;
82 }
83
84 // Record file state for post-compaction attachment tracking
85 if (config.recordFileState) {
86 try {
87 const newStat = await config.runtime.stat(resolvedPath, abortSignal);
88 await config.recordFileState(resolvedPath, {
89 content,
90 timestamp: newStat.modifiedTime.getTime(),
91 });
92 } catch {
93 // File stat failed, skip recording
94 }
95 }
96
97 const diff = generateDiff(resolvedPath, "", content);
98 return {
99 success: true,
100 diff: FILE_EDIT_DIFF_OMITTED_MESSAGE,
101 ui_only: {
102 file_edit: {
103 diff,
104 },

Callers 3

getToolsForModelFunction · 0.90
createTestToolFunction · 0.90

Calls 11

resolvePathWithinCwdFunction · 0.90
validatePlanModeAccessFunction · 0.90
fileExistsFunction · 0.90
writeFileStringFunction · 0.90
generateDiffFunction · 0.90
executeFileEditOperationFunction · 0.90
getErrorMessageFunction · 0.90
insertContentFunction · 0.85
recordFileStateMethod · 0.80
statMethod · 0.65
toolFunction · 0.50

Tested by 1

createTestToolFunction · 0.72