From 57c56daf5906442dacc15951c9b3405f89309839 Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Tue, 31 Mar 2026 23:10:45 +0900 Subject: imp --- lib/dispatch/tool/files/write_file.rb | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 lib/dispatch/tool/files/write_file.rb (limited to 'lib/dispatch/tool/files/write_file.rb') diff --git a/lib/dispatch/tool/files/write_file.rb b/lib/dispatch/tool/files/write_file.rb new file mode 100644 index 0000000..218c310 --- /dev/null +++ b/lib/dispatch/tool/files/write_file.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +module Dispatch + module Tool + module Files + WRITE_FILE = Dispatch::Tools::Definition.new( + name: "write_file", + description: "Write or overwrite a file with the given content. Creates parent directories if needed.", + parameters: { + type: "object", + properties: { + path: { + type: "string", + description: "Path to the file to write, relative to the worktree root." + }, + content: { + type: "string", + description: "The content to write to the file." + } + }, + required: %w[path content], + additionalProperties: false + } + ) do |params, context| + worktree_path = context[:worktree_path] + path = params[:path] + content = params[:content] + + resolved = begin + Sandbox.resolve_path(path, worktree_path:) + rescue SandboxError => e + next Dispatch::Tools::Result.failure(error: e.message) + end + + FileUtils.mkdir_p(File.dirname(resolved)) + File.write(resolved, content) + + byte_count = content.bytesize + Dispatch::Tools::Result.success(output: "Wrote #{byte_count} bytes to #{path}") + end + end + end +end -- cgit v1.2.3