Class: Kward::Tools::ReadFile

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

Instance Attribute Summary

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods inherited from Base

#schema

Constructor Details

#initialize(workspace:) ⇒ ReadFile

Returns a new instance of ReadFile.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/kward/tools/read_file.rb', line 6

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



20
21
22
23
24
25
26
27
# File 'lib/kward/tools/read_file.rb', line 20

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