MCPcopy Create free account
hub / github.com/echoVic/blade-code / executeCommand

Method executeCommand

src/tools/builtin/file-system.ts:305–346  ·  view source on GitHub ↗

* 执行文件写入

(
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    _command: string,
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    _workingDirectory: string,
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    _options: ConfirmationOptions,
    params: Record<string, any>
  )

Source from the content-addressed store, hash-verified

303 * 执行文件写入
304 */
305 protected async executeCommand(
306 // eslint-disable-next-line @typescript-eslint/no-unused-vars
307 _command: string,
308 // eslint-disable-next-line @typescript-eslint/no-unused-vars
309 _workingDirectory: string,
310 // eslint-disable-next-line @typescript-eslint/no-unused-vars
311 _options: ConfirmationOptions,
312 params: Record<string, any>
313 ) {
314 const { path, content, encoding, createDirectories } = params;
315
316 try {
317 const resolvedPath = resolve(path);
318
319 // 创建目录结构
320 if (createDirectories) {
321 const dir = dirname(resolvedPath);
322 await fs.mkdir(dir, { recursive: true });
323 }
324
325 await fs.writeFile(resolvedPath, content, encoding as BufferEncoding);
326
327 // 获取文件信息
328 const stats = await fs.stat(resolvedPath);
329
330 return {
331 success: true,
332 data: {
333 path: resolvedPath,
334 size: stats.size,
335 encoding,
336 created: stats.birthtime,
337 modified: stats.mtime,
338 },
339 };
340 } catch (error: any) {
341 return {
342 success: false,
343 error: `文件写入失败: ${error.message}`,
344 };
345 }
346 }
347}
348
349// 创建 file_write 工具实例

Callers 2

executeFunction · 0.45
handlePreCheckFailureFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected