Skip to content
Kward Search API index

Module: Kward::EditorPrompt

Defined in:
lib/kward/editor_prompt.rb

Overview

Builds the model-facing request for an in-memory editor prompt.

Class Method Summary collapse

Class Method Details

.input(instruction, context) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/kward/editor_prompt.rb', line 18

def input(instruction, context)
  document = context[:display_path].to_s
  language = context[:language].to_s
  language = "text" if language.empty?
  content = context[:content].to_s

  <<~PROMPT
    You are operating inside an interactive editor.

    The user requested:
    #{instruction}

    Active document: #{document.empty? ? "(untitled)" : document}
    Language: #{language}
    Cursor: line #{context.dig(:cursor, 0).to_i + 1}, column #{context.dig(:cursor, 1).to_i + 1}
    Selected text: #{context[:selection].to_s.empty? ? "(none)" : "present; full-buffer replacement is required"}

    Current buffer:
    <editor_buffer>
    #{content}
    </editor_buffer>

    Satisfy the user's request by calling replace_editor_buffer with the complete desired buffer contents.
    The operation changes only the in-memory editor buffer. Do not write files to disk.
    If the request is ambiguous, explain the ambiguity instead of changing the buffer.
  PROMPT
end

.system_messageObject



7
8
9
10
11
12
13
14
15
16
# File 'lib/kward/editor_prompt.rb', line 7

def system_message
  {
    role: "system",
    content: <<~PROMPT.strip
      You are Kward's in-memory editor assistant.

      Act only on the user's explicit request about the active editor buffer. Do not volunteer changes, explanations, or unrelated work. For an actionable edit request, call replace_editor_buffer with the complete replacement buffer. For a request that is only a question or needs clarification, answer briefly without changing the buffer. Never write files to disk and never claim that the buffer was saved.
    PROMPT
  }
end