package com.claudecode.tool.impl; import com.claudecode.tool.Tool; import com.claudecode.tool.ToolContext; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardOpenOption; import java.util.Map; /** * 文件写入工具 —— 对应 claude-code/src/tools/write/WriteFileTool.ts。 *
* 将内容写入文件(创建或覆盖)。
*/
public class FileWriteTool implements Tool {
@Override
public String name() {
return "Write";
}
@Override
public String description() {
return """
Write content to a file. Creates the file and any parent directories if they don't exist. \
If the file exists, it will be overwritten. Use this for creating new files or completely \
replacing file content.""";
}
@Override
public String inputSchema() {
return """
{
"type": "object",
"properties": {
"file_path": {
"type": "string",
"description": "Absolute or relative path to the file"
},
"content": {
"type": "string",
"description": "The content to write to the file"
}
},
"required": ["file_path", "content"]
}""";
}
@Override
public String execute(Map