Skip to content
Kward Search API index

Class: Kward::Tools::ReplaceEditorBuffer

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

Overview

Replaces the active editor's in-memory draft without saving to disk.

Instance Attribute Summary

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods inherited from Base

#schema

Constructor Details

#initialize(editor_prompt_session:) ⇒ ReplaceEditorBuffer

Returns a new instance of ReplaceEditorBuffer.



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

def initialize(editor_prompt_session:)
  @editor_prompt_session = editor_prompt_session
  super(
    "replace_editor_buffer",
    "Replace the complete contents of the active in-memory editor buffer. This does not save the file.",
    properties: {
      content: { type: "string", description: "Complete replacement contents for the editor buffer." }
    },
    required: ["content"]
  )
end

Instance Method Details

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



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

def call(args, _conversation, cancellation: nil)
  cancellation&.raise_if_cancelled!
  content = argument(args, :content, "")
  @editor_prompt_session.replace(content)
  lines = content.to_s.lines.length
  "Editor buffer replaced: #{lines} lines, #{content.to_s.bytesize} bytes. The file has not been saved."
end