Skip to content
Kward Search API index

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:, workspace_targets: nil) ⇒ 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_targets: nil)
  configure_workspace_targets(workspace, workspace_targets)
  super(
    "write_file",
    "Write a workspace file. Existing files must be read first.",
    properties: targeted_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
32
33
34
# File 'lib/kward/tools/write_file.rb', line 24

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

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