summaryrefslogtreecommitdiffhomepage
path: root/lib/dispatch/tool/files/create_file.rb
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-03-31 23:10:45 +0900
committerAdam Malczewski <[email protected]>2026-03-31 23:10:45 +0900
commit57c56daf5906442dacc15951c9b3405f89309839 (patch)
treee76890119c0e47acb48f8585222b7a2f5e22df56 /lib/dispatch/tool/files/create_file.rb
parent25488d32336e05b69a41391cc7b5153478d3cc8a (diff)
downloaddispatch-tool-files-dev.tar.gz
dispatch-tool-files-dev.zip
impdev
Diffstat (limited to 'lib/dispatch/tool/files/create_file.rb')
-rw-r--r--lib/dispatch/tool/files/create_file.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/dispatch/tool/files/create_file.rb b/lib/dispatch/tool/files/create_file.rb
new file mode 100644
index 0000000..5cc13e4
--- /dev/null
+++ b/lib/dispatch/tool/files/create_file.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+module Dispatch
+ module Tool
+ module Files
+ CREATE_FILE = Dispatch::Tools::Definition.new(
+ name: "create_file",
+ description: "Create a new file with the given content. Fails if the file already exists.",
+ parameters: {
+ type: "object",
+ properties: {
+ path: {
+ type: "string",
+ description: "Path to the file to create, relative to the worktree root."
+ },
+ content: {
+ type: "string",
+ description: "The content to write to the new 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
+
+ if File.exist?(resolved)
+ next Dispatch::Tools::Result.failure(error: "File already exists: #{path}. Use write_file to overwrite.")
+ end
+
+ FileUtils.mkdir_p(File.dirname(resolved))
+ File.write(resolved, content)
+
+ Dispatch::Tools::Result.success(output: "Created #{path}")
+ end
+ end
+ end
+end