Class: Kward::Tools::WriteFile

Inherits:
Base
  • Object
show all
Defined in:
lib/kward/tools/write_file.rb

Overview

Tool wrapper for guarded full-file writes.

Instance Attribute Summary

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods inherited from Base

#schema

Constructor Details

#initialize(workspace:) ⇒ WriteFile

Builds the tool schema and stores the execution dependency.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/kward/tools/write_file.rb', line 10

def initialize(workspace:)
  @workspace = workspace
  super(
    "write_file",
    "Write a workspace file. Existing files must be read first.",
    properties: {
      path: { type: "string", description: "Workspace-relative path." },
      content: { type: "string", description: "Complete file content." }
    },
    required: ["path", "content"]
  )
end

Instance Method Details

#call(args, conversation, cancellation: nil) ⇒ Object

Executes the tool and returns model-facing output text.



24
25
26
27
28
29
30
31
# File 'lib/kward/tools/write_file.rb', line 24

def call(args, conversation, cancellation: nil)
  path = argument(args, :path, "")
  content = argument(args, :content, "")

  result = @workspace.write_file(path, content, read_paths: conversation.read_paths)
  conversation.refresh_system_message! if agents_file_changed?(@workspace, path, result)
  result
end