Module: Kward::Prompts
- Defined in:
- lib/kward/prompts.rb,
lib/kward/prompts/templates.rb
Overview
Prompt template discovery from configured markdown files.
Defined Under Namespace
Classes: Templates
Class Method Summary collapse
- .base_prompt ⇒ Object
- .config_agents_prompt ⇒ Object
- .config_agents_prompt_label ⇒ Object
- .config_agents_prompt_source ⇒ Object
- .persona_prompt(workspace_root = Dir.pwd, model: nil, reasoning_effort: nil, now: Time.now) ⇒ Object
- .prompt_parts(workspace_root: Dir.pwd, include_workspace_personality: true, model: nil, reasoning_effort: nil, now: Time.now, memory_context: nil, plugin_context: nil) ⇒ Object
- .prompt_section(label, content, source: nil) ⇒ Object
- .prompt_sections(workspace_root: Dir.pwd, include_workspace_personality: true, model: nil, reasoning_effort: nil, now: Time.now, memory_context: nil, plugin_context: nil) ⇒ Object
- .skills_prompt ⇒ Object
- .system_message(workspace_root: Dir.pwd, include_workspace_personality: true, model: nil, reasoning_effort: nil, now: Time.now, memory_context: nil, plugin_context: nil) ⇒ Object
- .workspace_agents_context(workspace_root = Dir.pwd) ⇒ Object
- .workspace_agents_context_label(workspace_root = Dir.pwd) ⇒ Object
- .workspace_agents_hint(workspace_root = Dir.pwd) ⇒ Object
- .workspace_agents_prompt(workspace_root = Dir.pwd) ⇒ Object
Class Method Details
.base_prompt ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/kward/prompts.rb', line 33 def base_prompt <<~PROMPT.strip You are Kward, a concise practical CLI coding agent. You are allowed to use the tools. Help users understand and modify software projects. Inspect files before changing them, make the smallest correct change, preserve existing style, and summarize what changed. Be honest about limitations. For web research, use web_search to discover sources, then fetch_content for important human-readable pages before relying on them. Use fetch_raw for machine-readable resources such as JSON, YAML, XML, RSS, OpenAPI specs, and plain text. Prefer official or primary sources when practical, and cite or mention the URLs you relied on. PROMPT end |
.config_agents_prompt ⇒ Object
41 42 43 |
# File 'lib/kward/prompts.rb', line 41 def config_agents_prompt ConfigFiles.agents_prompt end |
.config_agents_prompt_label ⇒ Object
45 46 47 48 49 50 |
# File 'lib/kward/prompts.rb', line 45 def config_agents_prompt_label return "Config principles" if File.exist?(ConfigFiles.config_principles_path) return "Config AGENTS.md alias" if File.exist?(ConfigFiles.config_agents_path) "Config principles" end |
.config_agents_prompt_source ⇒ Object
52 53 54 55 56 57 |
# File 'lib/kward/prompts.rb', line 52 def config_agents_prompt_source return ConfigFiles.config_principles_path if File.exist?(ConfigFiles.config_principles_path) return ConfigFiles.config_agents_path if File.exist?(ConfigFiles.config_agents_path) nil end |
.persona_prompt(workspace_root = Dir.pwd, model: nil, reasoning_effort: nil, now: Time.now) ⇒ Object
59 60 61 |
# File 'lib/kward/prompts.rb', line 59 def persona_prompt(workspace_root = Dir.pwd, model: nil, reasoning_effort: nil, now: Time.now) ConfigFiles.persona_prompt(workspace_root, model: model, reasoning_effort: reasoning_effort, now: now) end |
.prompt_parts(workspace_root: Dir.pwd, include_workspace_personality: true, model: nil, reasoning_effort: nil, now: Time.now, memory_context: nil, plugin_context: nil) ⇒ Object
16 17 18 |
# File 'lib/kward/prompts.rb', line 16 def prompt_parts(workspace_root: Dir.pwd, include_workspace_personality: true, model: nil, reasoning_effort: nil, now: Time.now, memory_context: nil, plugin_context: nil) prompt_sections(workspace_root: workspace_root, include_workspace_personality: include_workspace_personality, model: model, reasoning_effort: reasoning_effort, now: now, memory_context: memory_context, plugin_context: plugin_context).map { |section| section[:content] } end |
.prompt_section(label, content, source: nil) ⇒ Object
92 93 94 95 96 |
# File 'lib/kward/prompts.rb', line 92 def prompt_section(label, content, source: nil) return nil if content.to_s.empty? { label: label, content: content, source: source } end |
.prompt_sections(workspace_root: Dir.pwd, include_workspace_personality: true, model: nil, reasoning_effort: nil, now: Time.now, memory_context: nil, plugin_context: nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/kward/prompts.rb', line 20 def prompt_sections(workspace_root: Dir.pwd, include_workspace_personality: true, model: nil, reasoning_effort: nil, now: Time.now, memory_context: nil, plugin_context: nil) sections = [prompt_section("Built-in system prompt", base_prompt)] sections << prompt_section(config_agents_prompt_label, config_agents_prompt, source: config_agents_prompt_source) sections << prompt_section("Memory context", memory_context) unless memory_context.to_s.empty? if include_workspace_personality sections << prompt_section("Persona", persona_prompt(workspace_root, model: model, reasoning_effort: reasoning_effort, now: now)) sections << prompt_section("Plugin context", plugin_context) unless plugin_context.to_s.empty? end sections << prompt_section("Configured skills", skills_prompt, source: ConfigFiles.skills.empty? ? nil : File.join(ConfigFiles.config_dir, "skills")) sections << prompt_section(workspace_agents_context_label(workspace_root), workspace_agents_context(workspace_root), source: ConfigFiles.workspace_agents_file?(workspace_root) ? ConfigFiles.workspace_agents_path(workspace_root) : nil) sections.compact end |
.skills_prompt ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/kward/prompts.rb', line 98 def skills_prompt skills = ConfigFiles.skills return nil if skills.empty? lines = [ "Configured skills are available in the Kward config directory.", "When a task matches a skill, use read_skill to load its instructions before proceeding.", "Available skills:" ] skills.each do |skill| description = skill.description.empty? ? "No description provided." : skill.description lines << "- #{skill.name}: #{description}" end lines.join("\n") end |
.system_message(workspace_root: Dir.pwd, include_workspace_personality: true, model: nil, reasoning_effort: nil, now: Time.now, memory_context: nil, plugin_context: nil) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/kward/prompts.rb', line 9 def (workspace_root: Dir.pwd, include_workspace_personality: true, model: nil, reasoning_effort: nil, now: Time.now, memory_context: nil, plugin_context: nil) { role: "system", content: prompt_parts(workspace_root: workspace_root, include_workspace_personality: include_workspace_personality, model: model, reasoning_effort: reasoning_effort, now: now, memory_context: memory_context, plugin_context: plugin_context).compact.join("\n\n") } end |
.workspace_agents_context(workspace_root = Dir.pwd) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/kward/prompts.rb', line 63 def workspace_agents_context(workspace_root = Dir.pwd) if ConfigFiles.enforce_workspace_agents_file? ConfigFiles.workspace_agents_prompt(workspace_root) else workspace_agents_hint(workspace_root) end end |
.workspace_agents_context_label(workspace_root = Dir.pwd) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/kward/prompts.rb', line 85 def workspace_agents_context_label(workspace_root = Dir.pwd) return "Workspace AGENTS.md" unless ConfigFiles.workspace_agents_file?(workspace_root) return "Workspace AGENTS.md" if ConfigFiles.enforce_workspace_agents_file? "Workspace AGENTS.md hint" end |
.workspace_agents_hint(workspace_root = Dir.pwd) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/kward/prompts.rb', line 75 def workspace_agents_hint(workspace_root = Dir.pwd) return nil unless ConfigFiles.workspace_agents_file?(workspace_root) path = ConfigFiles.workspace_agents_path(workspace_root) <<~PROMPT.strip Workspace guidance is available in AGENTS.md at the workspace root: #{path} For tasks involving this repository, read it before analyzing or modifying project files, and follow it when it does not conflict with higher-priority instructions or the user's request. PROMPT end |
.workspace_agents_prompt(workspace_root = Dir.pwd) ⇒ Object
71 72 73 |
# File 'lib/kward/prompts.rb', line 71 def workspace_agents_prompt(workspace_root = Dir.pwd) ConfigFiles.workspace_agents_prompt(workspace_root) end |