Class: Kward::Tools::ReadFile
Overview
Tool wrapper for bounded workspace file reads.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#call(args, conversation, cancellation: nil) ⇒ Object
Executes the tool and returns model-facing output text.
-
#initialize(workspace:) ⇒ ReadFile
constructor
Builds the tool schema and stores the execution dependency.
Methods inherited from Base
Constructor Details
#initialize(workspace:) ⇒ ReadFile
Builds the tool schema and stores the execution dependency.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/kward/tools/read_file.rb', line 10 def initialize(workspace:) @workspace = workspace super( "read_file", "Read a workspace text file. Output is capped; use offset/limit to continue.", properties: { path: { type: "string", description: "Workspace-relative path." }, offset: { type: "integer", description: "1-indexed start line." }, limit: { type: "integer", description: "Maximum lines to return." } }, required: ["path"] ) end |
Instance Method Details
#call(args, conversation, cancellation: nil) ⇒ Object
Executes the tool and returns model-facing output text.
25 26 27 28 29 30 31 32 |
# File 'lib/kward/tools/read_file.rb', line 25 def call(args, conversation, cancellation: nil) path = argument(args, :path, "") offset = argument(args, :offset) limit = argument(args, :limit) content = @workspace.read_file(path, offset: offset, limit: limit) conversation.mark_read(@workspace.resolved_path(path)) unless content.start_with?("Error:") content end |