Module: Brute::Prompts

Defined in:
lib/brute/prompts.rb,
lib/brute/prompts/base.rb,
lib/brute/prompts/skills.rb,
lib/brute/prompts/autonomy.rb,
lib/brute/prompts/identity.rb,
lib/brute/prompts/max_steps.rb,
lib/brute/prompts/code_style.rb,
lib/brute/prompts/git_safety.rb,
lib/brute/prompts/tool_usage.rb,
lib/brute/prompts/conventions.rb,
lib/brute/prompts/doing_tasks.rb,
lib/brute/prompts/environment.rb,
lib/brute/prompts/objectivity.rb,
lib/brute/prompts/build_switch.rb,
lib/brute/prompts/instructions.rb,
lib/brute/prompts/plan_reminder.rb,
lib/brute/prompts/proactiveness.rb,
lib/brute/prompts/frontend_tasks.rb,
lib/brute/prompts/tone_and_style.rb,
lib/brute/prompts/code_references.rb,
lib/brute/prompts/task_management.rb,
lib/brute/prompts/editing_approach.rb,
lib/brute/prompts/editing_constraints.rb,
lib/brute/prompts/security_and_safety.rb

Defined Under Namespace

Modules: Autonomy, BuildSwitch, CodeReferences, CodeStyle, Conventions, DoingTasks, EditingApproach, EditingConstraints, Environment, FrontendTasks, GitSafety, Identity, Instructions, MaxSteps, Objectivity, PlanReminder, Proactiveness, SecurityAndSafety, Skills, TaskManagement, ToneAndStyle, ToolUsage Classes: Context

Constant Summary collapse

TEXT_DIR =
File.expand_path("text", __dir__)
TEMPLATES =

Compiled templates, keyed by absolute path. Compilation is idempotent, so a racy double-assign under Async is harmless.

{}

Class Method Summary collapse

Class Method Details

.agent_prompt(name) ⇒ Object

Read a named agent prompt (e.g. "explore", "compaction").



28
29
30
31
# File 'lib/brute/prompts/base.rb', line 28

def self.agent_prompt(name)
  path = File.join(TEXT_DIR, "agents", "#{name}.txt")
  File.exist?(path) ? File.read(path) : nil
end

.read(section, provider_name) ⇒ Object

Resolve a provider-specific text file. Looks for section/provider_name.txt, falls back to section/default.txt.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/brute/prompts/base.rb', line 14

def self.read(section, provider_name)
  provider = provider_name.to_s
  path = File.join(TEXT_DIR, section, "#{provider}.txt")
  unless File.exist?(path)
    path = File.join(TEXT_DIR, section, "default.txt")
  end
  if File.exist?(path)
    File.read(path)
  else
    nil
  end
end

.render(section, ctx) ⇒ Object

Resolve and render text/

/.erb, falling back to default.erb, then to the legacy plain .txt files. Returns nil when the section has no template or text file at all.

Templates are ERB: arbitrary Ruby. Only ship templates with the gem or load them from paths you trust.



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/brute/prompts/base.rb', line 74

def self.render(section, ctx)
  provider = ctx[:provider_name].to_s
  path = [provider, "default"]
         .map { |variant| File.join(TEXT_DIR, section, "#{variant}.erb") }
         .find { |candidate| File.exist?(candidate) }
  if path
    erb = TEMPLATES[path] ||= ERB.new(File.read(path), trim_mode: "-")
    erb.result(Context.new(ctx).get_binding)
  else
    read(section, provider)
  end
end