Class: Envoy::Prompt

Inherits:
Object
  • Object
show all
Defined in:
lib/envoy/prompt.rb

Overview

A named block of system-prompt text, composable like a Toolset.

Prompts are code, not data: git is the version store. Bodies may be a String or a block; a block stays lazy so a host reading from disk picks up edits on to_prepare reload without a boot.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ Prompt

Returns a new instance of Prompt.



10
11
12
13
14
# File 'lib/envoy/prompt.rb', line 10

def initialize(key)
  @key = key.to_s
  @body = nil
  @composed_keys = []
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



8
9
10
# File 'lib/envoy/prompt.rb', line 8

def key
  @key
end

Instance Method Details

#body(text = nil, &block) ⇒ Object

Setter with text or a block; reader (no args) returns this prompt's own resolved body only. Use #full_body for the composed result.



18
19
20
21
# File 'lib/envoy/prompt.rb', line 18

def body(text = nil, &block)
  return own_body if text.nil? && block.nil?
  @body = block || text
end

#full_bodyObject

Composed bodies first, then this prompt's own — so shared framing (safety rules, draft status) precedes the specialisation that builds on it.



31
32
33
# File 'lib/envoy/prompt.rb', line 31

def full_body
  collect_bodies.compact_blank.join("\n\n").presence
end

#use(*keys) ⇒ Object

Compose other prompts into this one. Keys resolve lazily (at full_body time), so definition load order does not matter.



25
26
27
# File 'lib/envoy/prompt.rb', line 25

def use(*keys)
  @composed_keys.concat(keys.map(&:to_s))
end