MCPcopy Index your code
hub / github.com/anus-dev/ANUS / WriteFileToolInvocation

Class WriteFileToolInvocation

packages/core/src/tools/write-file.ts:132–380  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

130}
131
132class WriteFileToolInvocation extends BaseToolInvocation<
133 WriteFileToolParams,
134 ToolResult
135> {
136 constructor(
137 private readonly config: Config,
138 params: WriteFileToolParams,
139 ) {
140 super(params);
141 }
142
143 override toolLocations(): ToolLocation[] {
144 return [{ path: this.params.file_path }];
145 }
146
147 override getDescription(): string {
148 const relativePath = makeRelative(
149 this.params.file_path,
150 this.config.getTargetDir(),
151 );
152 return `Writing to ${shortenPath(relativePath)}`;
153 }
154
155 override async shouldConfirmExecute(
156 abortSignal: AbortSignal,
157 ): Promise<ToolCallConfirmationDetails | false> {
158 if (this.config.getApprovalMode() === ApprovalMode.AUTO_EDIT) {
159 return false;
160 }
161
162 const correctedContentResult = await getCorrectedFileContent(
163 this.config,
164 this.params.file_path,
165 this.params.content,
166 abortSignal,
167 );
168
169 if (correctedContentResult.error) {
170 // If file exists but couldn't be read, we can't show a diff for confirmation.
171 return false;
172 }
173
174 const { originalContent, correctedContent } = correctedContentResult;
175 const relativePath = makeRelative(
176 this.params.file_path,
177 this.config.getTargetDir(),
178 );
179 const fileName = path.basename(this.params.file_path);
180
181 const fileDiff = Diff.createPatch(
182 fileName,
183 originalContent, // Original content (empty if new file or unreadable)
184 correctedContent, // Content after potential correction
185 'Current',
186 'Proposed',
187 DEFAULT_DIFF_OPTIONS,
188 );
189

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected