Class: Tools::Write
Overview
Creates or overwrites files with automatic intermediate directory creation. Writes content exactly as given — no line ending normalization, no BOM handling. Full replacement only; no append or merge.
Class Method Summary collapse
Instance Method Summary collapse
- #execute(input) ⇒ String, Hash
-
#initialize(shell_session: nil) ⇒ Write
constructor
A new instance of Write.
Methods inherited from Base
Constructor Details
#initialize(shell_session: nil) ⇒ Write
Returns a new instance of Write.
34 35 36 |
# File 'lib/tools/write.rb', line 34 def initialize(shell_session: nil, **) @working_directory = shell_session&.pwd end |
Class Method Details
.description ⇒ Object
20 |
# File 'lib/tools/write.rb', line 20 def self.description = "Write file." |
.input_schema ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/tools/write.rb', line 22 def self.input_schema { type: "object", properties: { path: {type: "string", description: "Relative paths resolve against working directory. Creates intermediate directories."}, content: {type: "string"} }, required: %w[path content] } end |
.tool_name ⇒ Object
18 |
# File 'lib/tools/write.rb', line 18 def self.tool_name = "write" |
Instance Method Details
#execute(input) ⇒ String, Hash
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/tools/write.rb', line 41 def execute(input) path, content = extract_params(input) return {error: "Path cannot be blank"} if path.empty? path = resolve_path(path) error = validate_target(path) return error if error write_file(path, content) end |