aia 2.0.0.0.pre.alpha → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. checksums.yaml +4 -4
  2. data/.version +1 -1
  3. data/CHANGELOG.md +151 -228
  4. data/README.md +42 -19
  5. data/bin/aia +8 -3
  6. data/lib/aia/aia_completion.bash +2 -3
  7. data/lib/aia/aia_completion.fish +6 -5
  8. data/lib/aia/aia_completion.zsh +2 -3
  9. data/lib/aia/chat_loop.rb +24 -66
  10. data/lib/aia/config/cli_parser.rb +164 -123
  11. data/lib/aia/config/defaults.yml +12 -39
  12. data/lib/aia/config/mcp_parser.rb +42 -40
  13. data/lib/aia/config/model_spec.rb +8 -14
  14. data/lib/aia/config/validator.rb +144 -156
  15. data/lib/aia/config/value_caster.rb +76 -0
  16. data/lib/aia/config.rb +72 -54
  17. data/lib/aia/content_extractor.rb +2 -0
  18. data/lib/aia/cost_calculator.rb +1 -0
  19. data/lib/aia/crew.rb +29 -19
  20. data/lib/aia/debate_handler.rb +45 -20
  21. data/lib/aia/delegate_handler.rb +7 -3
  22. data/lib/aia/directive.rb +10 -8
  23. data/lib/aia/directives/configuration_directives.rb +164 -109
  24. data/lib/aia/directives/context_directives.rb +55 -40
  25. data/lib/aia/directives/execution_directives.rb +25 -25
  26. data/lib/aia/directives/model_directives.rb +112 -195
  27. data/lib/aia/directives/trakflow_directives.rb +27 -9
  28. data/lib/aia/directives/utility_directives.rb +86 -87
  29. data/lib/aia/directives/web_and_file_directives.rb +83 -63
  30. data/lib/aia/fact_asserter.rb +3 -3
  31. data/lib/aia/history_transfer.rb +64 -24
  32. data/lib/aia/layered_orchestrator.rb +66 -43
  33. data/lib/aia/logger.rb +27 -62
  34. data/lib/aia/mcp_config_normalizer.rb +27 -14
  35. data/lib/aia/mcp_connection_manager.rb +193 -186
  36. data/lib/aia/mcp_discovery.rb +43 -15
  37. data/lib/aia/mcp_grouper.rb +2 -1
  38. data/lib/aia/mcp_server_config.rb +48 -0
  39. data/lib/aia/mcp_utility.rb +28 -20
  40. data/lib/aia/mention_router.rb +22 -52
  41. data/lib/aia/modality_query.rb +36 -0
  42. data/lib/aia/model_alias_registry.rb +11 -11
  43. data/lib/aia/model_registry.rb +75 -0
  44. data/lib/aia/network_builder.rb +17 -11
  45. data/lib/aia/network_memory_manager.rb +6 -6
  46. data/lib/aia/patches/ruby_llm_streaming_error.rb +21 -4
  47. data/lib/aia/patches/ruby_llm_tool_param_compat.rb +18 -0
  48. data/lib/aia/pipeline_orchestrator.rb +88 -45
  49. data/lib/aia/plugin_monitor.rb +9 -6
  50. data/lib/aia/prompt_decomposer.rb +6 -4
  51. data/lib/aia/prompt_handler.rb +90 -69
  52. data/lib/aia/provider_registry.rb +105 -0
  53. data/lib/aia/robot_builder.rb +1 -1
  54. data/lib/aia/robot_factory.rb +77 -69
  55. data/lib/aia/robot_namer.rb +2 -8
  56. data/lib/aia/robot_sync.rb +79 -0
  57. data/lib/aia/role_catalog.rb +89 -0
  58. data/lib/aia/session.rb +32 -14
  59. data/lib/aia/session_tracker.rb +39 -41
  60. data/lib/aia/similarity_scorer.rb +5 -3
  61. data/lib/aia/skill_utils.rb +60 -19
  62. data/lib/aia/spawn_handler.rb +16 -4
  63. data/lib/aia/spawn_spec_parser.rb +6 -7
  64. data/lib/aia/special_mode_handler.rb +80 -57
  65. data/lib/aia/speech.rb +103 -0
  66. data/lib/aia/startup_coordinator.rb +17 -91
  67. data/lib/aia/streaming_runner.rb +16 -5
  68. data/lib/aia/system_prompt_assembler.rb +20 -15
  69. data/lib/aia/task_board.rb +60 -0
  70. data/lib/aia/task_coordinator.rb +10 -5
  71. data/lib/aia/timing.rb +15 -0
  72. data/lib/aia/tool_approver.rb +205 -0
  73. data/lib/aia/tool_filter.rb +1 -9
  74. data/lib/aia/tool_filter_strategy.rb +39 -25
  75. data/lib/aia/tool_introspection.rb +25 -0
  76. data/lib/aia/tool_loader.rb +71 -31
  77. data/lib/aia/tool_utility.rb +6 -5
  78. data/lib/aia/tools/delegate_to_foreman_tool.rb +6 -4
  79. data/lib/aia/tools/recruit_robot_tool.rb +12 -12
  80. data/lib/aia/tools/reskill_robot_tool.rb +7 -7
  81. data/lib/aia/tools/task_board_tool.rb +17 -16
  82. data/lib/aia/trakflow_bridge.rb +19 -11
  83. data/lib/aia/turn_state.rb +32 -8
  84. data/lib/aia/ui_presenter.rb +83 -59
  85. data/lib/aia/utility.rb +8 -24
  86. data/lib/aia/variable_input_collector.rb +1 -3
  87. data/lib/aia/verification_network.rb +10 -12
  88. data/lib/aia.rb +49 -8
  89. metadata +27 -162
  90. data/.better-commits.json +0 -150
  91. data/.config/tocer/configuration.yml +0 -6
  92. data/.envrc +0 -15
  93. data/.loki +0 -231
  94. data/.quality/flay_baseline.txt +0 -1
  95. data/.quality/flog_baseline.txt +0 -29
  96. data/.quality/reek_baseline.txt +0 -80
  97. data/.rubocop.yml +0 -116
  98. data/COMMITS.md +0 -196
  99. data/IMPLEMENTATION_PLAN.md +0 -506
  100. data/Rakefile +0 -160
  101. data/architecture_review.md +0 -314
  102. data/docs/AGENTS.md +0 -40
  103. data/docs/advanced-prompting.md +0 -814
  104. data/docs/assets/images/aia.png +0 -0
  105. data/docs/cli-reference.md +0 -1241
  106. data/docs/configuration.md +0 -747
  107. data/docs/contributing.md +0 -386
  108. data/docs/directives-reference.md +0 -1145
  109. data/docs/examples/index.md +0 -277
  110. data/docs/examples/mcp/index.md +0 -475
  111. data/docs/examples/prompts/analysis/index.md +0 -78
  112. data/docs/examples/prompts/automation/index.md +0 -109
  113. data/docs/examples/prompts/development/index.md +0 -125
  114. data/docs/examples/prompts/index.md +0 -333
  115. data/docs/examples/prompts/learning/index.md +0 -127
  116. data/docs/examples/prompts/writing/index.md +0 -62
  117. data/docs/examples/tools/index.md +0 -282
  118. data/docs/faq.md +0 -578
  119. data/docs/guides/available-models.md +0 -366
  120. data/docs/guides/basic-usage.md +0 -478
  121. data/docs/guides/chat.md +0 -680
  122. data/docs/guides/crew.md +0 -239
  123. data/docs/guides/executable-prompts.md +0 -331
  124. data/docs/guides/first-prompt.md +0 -454
  125. data/docs/guides/getting-started.md +0 -455
  126. data/docs/guides/image-generation.md +0 -507
  127. data/docs/guides/index.md +0 -48
  128. data/docs/guides/local-models.md +0 -306
  129. data/docs/guides/migrate-prompts.md +0 -335
  130. data/docs/guides/models.md +0 -1017
  131. data/docs/guides/shared-tools.md +0 -254
  132. data/docs/guides/tools.md +0 -831
  133. data/docs/index.md +0 -259
  134. data/docs/installation.md +0 -274
  135. data/docs/mcp-integration.md +0 -603
  136. data/docs/prompt_management.md +0 -665
  137. data/docs/security.md +0 -674
  138. data/docs/special_projects_guide.md +0 -386
  139. data/docs/tools-and-mcp-examples.md +0 -1211
  140. data/docs/workflows-and-pipelines.md +0 -636
  141. data/examples/.gitignore +0 -2
  142. data/examples/00_setup_aia.sh +0 -111
  143. data/examples/01_basic_usage.sh +0 -23
  144. data/examples/02_frontmatter.sh +0 -33
  145. data/examples/03_shell_integration.sh +0 -55
  146. data/examples/04_erb_templating.sh +0 -56
  147. data/examples/05_shell_then_erb.sh +0 -38
  148. data/examples/06_prompt_chaining.sh +0 -59
  149. data/examples/07_pipeline.sh +0 -46
  150. data/examples/08_context_files.sh +0 -43
  151. data/examples/09_roles.sh +0 -67
  152. data/examples/10_stdin_piping.sh +0 -49
  153. data/examples/11_multi_model.sh +0 -65
  154. data/examples/12_token_usage.sh +0 -52
  155. data/examples/13_cost_tracking.sh +0 -68
  156. data/examples/14_output_file.sh +0 -91
  157. data/examples/15_parameters.sh +0 -68
  158. data/examples/16_directives.sh +0 -113
  159. data/examples/17_require_and_conditionals.sh +0 -68
  160. data/examples/18_tools.sh +0 -61
  161. data/examples/19_local_tools.sh +0 -34
  162. data/examples/20_mcp_servers.sh +0 -102
  163. data/examples/21_executable_prompts.sh +0 -78
  164. data/examples/22_chat_mode.sh +0 -217
  165. data/examples/23_verify.sh +0 -139
  166. data/examples/24_decompose.sh +0 -139
  167. data/examples/25_spawn.sh +0 -139
  168. data/examples/26_debate.sh +0 -97
  169. data/examples/27_mention_routing.sh +0 -157
  170. data/examples/28_model_switching.sh +0 -106
  171. data/examples/29_agent_harness.sh +0 -177
  172. data/examples/README.md +0 -321
  173. data/examples/advanced_multi_robot_capabilities_without_examples.md +0 -106
  174. data/examples/aia_config.yml +0 -22
  175. data/examples/aia_config_orchestrator.yml +0 -45
  176. data/examples/aia_config_with_mcp.yml +0 -21
  177. data/examples/common.sh +0 -39
  178. data/examples/context/project_goals.md +0 -6
  179. data/examples/context/tech_stack.md +0 -7
  180. data/examples/directives/timestamp_directive.rb +0 -22
  181. data/examples/mcp/filesystem.json +0 -9
  182. data/examples/prompts_dir/analyze.md +0 -2
  183. data/examples/prompts_dir/brainstorm.md +0 -2
  184. data/examples/prompts_dir/conditional.md +0 -17
  185. data/examples/prompts_dir/creative.md +0 -4
  186. data/examples/prompts_dir/erbinfo.md +0 -5
  187. data/examples/prompts_dir/erbinfo_raw.md +0 -8
  188. data/examples/prompts_dir/evaluate.md +0 -2
  189. data/examples/prompts_dir/explain_joke.md +0 -1
  190. data/examples/prompts_dir/explain_recursion.md +0 -1
  191. data/examples/prompts_dir/fun_fact +0 -3
  192. data/examples/prompts_dir/greeting.md +0 -8
  193. data/examples/prompts_dir/greeting_required.md +0 -7
  194. data/examples/prompts_dir/hello.md +0 -1
  195. data/examples/prompts_dir/includes/ruby_facts.md +0 -4
  196. data/examples/prompts_dir/limerick.md +0 -1
  197. data/examples/prompts_dir/list_with_mcp.md +0 -3
  198. data/examples/prompts_dir/pick_best.md +0 -2
  199. data/examples/prompts_dir/project_summary +0 -12
  200. data/examples/prompts_dir/quiz_with_include.md +0 -6
  201. data/examples/prompts_dir/require_demo.md +0 -5
  202. data/examples/prompts_dir/roles/formal.md +0 -3
  203. data/examples/prompts_dir/roles/orchestrator.md +0 -21
  204. data/examples/prompts_dir/roles/pirate.md +0 -3
  205. data/examples/prompts_dir/shell_then_erb.md +0 -6
  206. data/examples/prompts_dir/sort_compare.md +0 -2
  207. data/examples/prompts_dir/summarize_context.md +0 -2
  208. data/examples/prompts_dir/sysinfo.md +0 -5
  209. data/examples/prompts_dir/sysinfo_raw.md +0 -8
  210. data/examples/prompts_dir/tagline.md +0 -1
  211. data/examples/prompts_dir/tell_joke.md +0 -1
  212. data/examples/prompts_dir/tell_joke_with_next.md +0 -4
  213. data/examples/prompts_dir/use_local_tool.md +0 -8
  214. data/examples/prompts_dir/use_tools.md +0 -8
  215. data/examples/prompts_dir/weather.md +0 -2
  216. data/examples/prompts_dir/whats_new.md +0 -2
  217. data/examples/prompts_dir/with_timestamp.md +0 -5
  218. data/examples/requirements/sinatra_taskflow_app.md +0 -139
  219. data/examples/rules/01_classify_ruby.rb +0 -16
  220. data/examples/rules/02_prefer_claude_for_code.rb +0 -19
  221. data/examples/rules/03_gate_prompt_length.rb +0 -19
  222. data/examples/rules/04_tool_selection.rb +0 -41
  223. data/examples/rules/README.md +0 -30
  224. data/examples/run_all.sh +0 -294
  225. data/examples/tools/word_count_tool.rb +0 -30
  226. data/lib/AGENTS.md +0 -57
  227. data/lib/aia/model_switch_handler.rb +0 -100
  228. data/mcp_servers/README.md +0 -110
  229. data/mcp_servers/apple-mcp.json +0 -8
  230. data/mcp_servers/filesystem.json +0 -9
  231. data/mcp_servers/mcp_server_chart.json +0 -11
  232. data/mcp_servers/playwright_one.json +0 -8
  233. data/mcp_servers/playwright_server_definition.json +0 -9
  234. data/mcp_servers/playwright_two.json +0 -8
  235. data/mcp_servers/tavily_mcp_server.json +0 -8
  236. data/mkdocs.yml +0 -169
@@ -12,10 +12,13 @@ require_relative 'skill_utils'
12
12
  module AIA
13
13
  class PipelineOrchestrator
14
14
  include ContentExtractor
15
+ include Speech
15
16
  include SkillUtils
16
17
 
17
- def initialize(robot:, prompt_handler:, input_collector:, ui_presenter:, session_tracker:)
18
+ # :reek:LongParameterList -- collaborators injected for isolated testing
19
+ def initialize(robot:, prompt_handler:, input_collector:, ui_presenter:, session_tracker:, robot_sync: nil)
18
20
  @robot = robot
21
+ @robot_sync = robot_sync
19
22
  @prompt_handler = prompt_handler
20
23
  @input_collector = input_collector
21
24
  @ui = ui_presenter
@@ -24,52 +27,70 @@ module AIA
24
27
 
25
28
  # Process all prompts in the pipeline.
26
29
  #
30
+ # Shift-based loop: prompt front matter that sets config.pipeline
31
+ # (`next:` or `pipeline:`) is picked up on the next iteration.
32
+ #
27
33
  # @param config [AIA::Config]
34
+ # :reek:DuplicateMethodCall -- config.pipeline is deliberately re-read each iteration because prompt front matter mutates it mid-loop
28
35
  def process(config)
29
- bridge = TrakFlowBridge.new
30
- tracking = bridge.available? && config.flags.track_pipeline
31
-
32
- bridge.create_plan_from_pipeline(config.pipeline) if tracking
36
+ # Only --track-pipeline starts TrakFlow for a pipeline run. The bridge
37
+ # does nothing when TrakFlow isn't available.
38
+ bridge = config.flags.track_pipeline ? TrakFlowBridge.new : nil
39
+ bridge&.create_plan_from_pipeline(config.pipeline)
33
40
 
34
- # Use shift-based loop so that prompt front matter which sets
35
- # config.pipeline (via `next:` or `pipeline:`) is picked up on
36
- # the next iteration rather than being silently ignored.
37
41
  until config.pipeline.empty?
38
42
  prompt_id = config.pipeline.shift
39
43
  next if prompt_id.nil? || prompt_id.empty?
40
44
 
41
- begin
42
- bridge.update_step_status(prompt_id, :started) if tracking
43
-
44
- prompt_text = build_prompt_text(prompt_id, config)
45
- next if prompt_text.nil? || prompt_text.strip.empty?
46
-
47
- result, content = compute_result(prompt_text, config)
48
-
49
- bridge.update_step_status(prompt_id, :completed) if tracking
50
-
51
- @tracker.record_turn(
52
- model: config.models.first.name,
53
- input: prompt_text,
54
- result: result
55
- )
56
-
57
- @ui.display_ai_response(content)
58
- output_to_file(content, config)
59
- display_metrics(result, config)
60
- @ui.display_separator
61
- rescue StandardError => e
62
- bridge.update_step_status(prompt_id, :failed, reason: e.message) if tracking
63
- raise
64
- end
45
+ run_step(prompt_id, config, bridge)
65
46
  end
66
47
  end
67
48
 
68
49
  # Allow robot to be updated (after model switch)
69
50
  attr_writer :robot
70
51
 
52
+ # The parameter names in a PM "Missing required parameters: a, b" message.
53
+ def self.missing_parameter_names(message)
54
+ message.to_s.sub(/\AMissing required parameters:/, '').split(',').map(&:strip).reject(&:empty?)
55
+ end
56
+
71
57
  private
72
58
 
59
+ # Run one pipeline prompt, recording its progress on +bridge+ (a
60
+ # TrakFlowBridge, or nil when the run isn't tracked).
61
+ #
62
+ # :reek:TooManyStatements -- build, sync, run, record and present one step, with its tracking interleaved
63
+ def run_step(prompt_id, config, bridge)
64
+ bridge&.update_step_status(prompt_id, :started)
65
+
66
+ prompt_text = build_prompt_text(prompt_id, config)
67
+ return if prompt_text.nil? || prompt_text.strip.empty?
68
+
69
+ # Front matter may have changed the model or its settings
70
+ @robot = @robot_sync.call(@robot) if @robot_sync
71
+
72
+ result, content = compute_result(prompt_text, config)
73
+ bridge&.update_step_status(prompt_id, :completed)
74
+
75
+ @tracker.record_turn(model: config.models.first.name, input: prompt_text, result: result)
76
+ present_result(content, result, config)
77
+ rescue StandardError => e
78
+ bridge&.update_step_status(prompt_id, :failed, reason: e.message)
79
+ raise
80
+ end
81
+
82
+ # Show a step's response, then save and speak it. A --paint step saved
83
+ # an image next to the output file, so there is no text to keep or speak.
84
+ def present_result(content, result, config)
85
+ @ui.display_ai_response(content)
86
+ unless AIA.paint?
87
+ output_to_file(content, config)
88
+ speak(content)
89
+ end
90
+ display_metrics(result, config)
91
+ @ui.display_separator
92
+ end
93
+
73
94
  # Returns [result, displayable_content] for one prompt — image when in paint
74
95
  # mode, otherwise the LLM text response.
75
96
  def compute_result(prompt_text, config)
@@ -82,16 +103,19 @@ module AIA
82
103
  end
83
104
  end
84
105
 
106
+ # :reek:TooManyStatements -- image request assembly, spinner-wrapped generation, then save/display of the result
85
107
  def generate_image(prompt_text, config)
86
108
  img_cfg = config.image
109
+ quality = img_cfg.quality
110
+ style = img_cfg.style
87
111
  params = {}
88
- params[:quality] = img_cfg.quality if img_cfg.quality && !img_cfg.quality.to_s.strip.empty?
89
- params[:style] = img_cfg.style if img_cfg.style && !img_cfg.style.to_s.strip.empty?
112
+ params[:quality] = quality if quality && !quality.to_s.strip.empty?
113
+ params[:style] = style if style && !style.to_s.strip.empty?
90
114
 
91
115
  image = @ui.with_spinner("Generating image") do
92
116
  RubyLLM.paint(
93
117
  prompt_text,
94
- model: img_cfg.model || 'dall-e-3',
118
+ model: img_cfg.model || 'gpt-image-1',
95
119
  size: img_cfg.size || '1024x1024',
96
120
  params: params
97
121
  )
@@ -124,15 +148,15 @@ module AIA
124
148
  end
125
149
 
126
150
  # Check if concurrent MCP mode should be used
151
+ # :reek:TooManyStatements -- ordered eligibility gates (server count, auto/forced, discovery, grouping threshold) before the build
127
152
  def maybe_use_concurrent_mcp(prompt_text, config)
128
153
  return nil unless (config.mcp_servers || []).size > 1
129
154
 
155
+ turn_state = AIA.turn_state
130
156
  concurrency = config.respond_to?(:concurrency) ? config.concurrency : nil
131
- return nil unless concurrency&.auto || AIA.turn_state.force_concurrent_mcp
157
+ return nil unless concurrency&.auto || turn_state.force_concurrent_mcp
132
158
 
133
- if AIA.turn_state.force_concurrent_mcp
134
- AIA.turn_state.force_concurrent_mcp = false
135
- end
159
+ turn_state.clear_mode(:concurrent_mcp)
136
160
 
137
161
  discovery = MCPDiscovery.new
138
162
  relevant_servers = discovery.discover(config)
@@ -151,16 +175,18 @@ module AIA
151
175
  end
152
176
 
153
177
  # Build prompt text from a prompt_id
178
+ # :reek:TooManyStatements -- layered prompt assembly: parameters, role prefix, skills, stdin, context files, in a fixed order
154
179
  def build_prompt_text(prompt_id, config)
155
180
  parsed = @prompt_handler.fetch_prompt(prompt_id)
156
181
  return nil unless parsed
157
182
 
158
- if parsed.respond_to?(:parameters) && parsed.parameters && !parsed.parameters.empty?
159
- values = @input_collector.collect(parsed.parameters)
160
- values.each { |k, v| parsed.parameters[k] = v }
183
+ parameters = parsed.respond_to?(:parameters) ? parsed.parameters : nil
184
+ if parameters && !parameters.empty?
185
+ values = @input_collector.collect(parameters)
186
+ values.each { |k, v| parameters[k] = v }
161
187
  end
162
188
 
163
- prompt_text = parsed.to_s
189
+ prompt_text = render_prompt(parsed)
164
190
 
165
191
  role = config.prompts.role
166
192
  if role && !role.empty?
@@ -180,14 +206,31 @@ module AIA
180
206
  prompt_text = "#{prompt_text}\n\n#{skill_content}" if skill_content
181
207
  end
182
208
 
183
- if config.stdin_content && !config.stdin_content.strip.empty?
184
- prompt_text = "#{prompt_text}\n\n#{config.stdin_content}"
209
+ stdin_content = config.stdin_content
210
+ if stdin_content && !stdin_content.strip.empty?
211
+ prompt_text = "#{prompt_text}\n\n#{stdin_content}"
185
212
  config.stdin_content = nil
186
213
  end
187
214
 
188
215
  add_context_files(prompt_text, config)
189
216
  end
190
217
 
218
+ # Render +parsed+, asking for any required parameter that only an
219
+ # included file declares. Such a parameter is not known until the
220
+ # include runs, so each MissingParameterError names more to ask for;
221
+ # rendering stops retrying once it names nothing new.
222
+ def render_prompt(parsed)
223
+ extra = {}
224
+ loop do
225
+ return parsed.to_s(extra)
226
+ rescue PM::MissingParameterError => e
227
+ names = self.class.missing_parameter_names(e.message) - extra.keys
228
+ raise if names.empty?
229
+
230
+ extra.merge!(@input_collector.collect(names.to_h { [it, nil] }))
231
+ end
232
+ end
233
+
191
234
  # Append context file contents to prompt
192
235
  def add_context_files(prompt_text, config)
193
236
  context_files = config.context_files
@@ -13,6 +13,7 @@ module AIA
13
13
  # CPU). If `listen` cannot be loaded, it falls back to a background thread that
14
14
  # polls file signatures ([mtime, size]). Either way the same #react logic drives
15
15
  # {PluginLoader}, so behavior is identical — only latency differs.
16
+ # :reek:TooManyInstanceVariables -- holds both backends' state (listener vs polling thread) plus watch config and callbacks
16
17
  class PluginMonitor
17
18
  DEFAULT_INTERVAL = 1.0 # seconds (polling fallback only)
18
19
 
@@ -83,9 +84,11 @@ module AIA
83
84
  #
84
85
  # @return [Array<Array(Symbol, String)>] e.g. [[:added, "/p/foo.rb"], ...]
85
86
  def detect_changes(old_snapshot, new_snapshot)
86
- added = (new_snapshot.keys - old_snapshot.keys).map { |path| [:added, path] }
87
- removed = (old_snapshot.keys - new_snapshot.keys).map { |path| [:removed, path] }
88
- modified = (old_snapshot.keys & new_snapshot.keys)
87
+ old_keys = old_snapshot.keys
88
+ new_keys = new_snapshot.keys
89
+ added = (new_keys - old_keys).map { |path| [:added, path] }
90
+ removed = (old_keys - new_keys).map { |path| [:removed, path] }
91
+ modified = (old_keys & new_keys)
89
92
  .reject { |path| new_snapshot[path] == old_snapshot[path] }
90
93
  .map { |path| [:modified, path] }
91
94
  added + removed + modified
@@ -115,9 +118,9 @@ module AIA
115
118
  # Map a listen callback into per-file reactions, ignoring anything that is
116
119
  # not a top-level file of the plugins directory (listen watches recursively).
117
120
  def handle_listen_events(modified, added, removed)
118
- Array(added).each { |path| react(:added, path) if top_level?(path) }
119
- Array(modified).each { |path| react(:modified, path) if top_level?(path) }
120
- Array(removed).each { |path| react(:removed, path) if top_level?(path) }
121
+ { added: added, modified: modified, removed: removed }.each do |event, paths|
122
+ Array(paths).each { |path| react(event, path) if top_level?(path) }
123
+ end
121
124
  end
122
125
 
123
126
  # listen reports resolved (symlink-free) paths, and on macOS the plugins
@@ -75,7 +75,9 @@ module AIA
75
75
  #
76
76
  # @param prompt [String] the user's prompt
77
77
  # @return [Array<String>] sub-task descriptions (empty if not decomposable)
78
+ # :reek:TooManyStatements -- schema vs JSON-fallback probe setup, run, extraction, and rescue reporting in one flow
78
79
  def decompose(prompt)
80
+ logger = AIA.logger
79
81
  probe = build_probe_robot
80
82
  use_schema = structured_output?
81
83
 
@@ -83,17 +85,17 @@ module AIA
83
85
  probe.with_schema(SUBTASKS_SCHEMA)
84
86
  full_prompt = DECOMPOSITION_PROMPT % { prompt: prompt }
85
87
  else
86
- AIA.logger.warn("PromptDecomposer: configured model does not support structured output — using JSON prompt fallback")
88
+ logger.warn("PromptDecomposer: configured model does not support structured output — using JSON prompt fallback")
87
89
  full_prompt = (DECOMPOSITION_PROMPT + FALLBACK_JSON_INSTRUCTION) % { prompt: prompt }
88
90
  end
89
91
 
90
92
  result = probe.run(full_prompt, mcp: :none, tools: :none)
91
93
  content = extract_content(result)
92
- AIA.logger.debug("PromptDecomposer#decompose content class=#{content.class}")
94
+ logger.debug("PromptDecomposer#decompose content class=#{content.class}")
93
95
  subtasks = extract_subtasks(content)
94
96
  subtasks.is_a?(Array) ? subtasks.select { |t| t.is_a?(String) && !t.empty? } : []
95
97
  rescue StandardError => e
96
- AIA.logger.warn("PromptDecomposer#decompose failed: #{e.class}: #{e.message}")
98
+ logger.warn("PromptDecomposer#decompose failed: #{e.class}: #{e.message}")
97
99
  []
98
100
  end
99
101
 
@@ -116,7 +118,7 @@ module AIA
116
118
  private
117
119
 
118
120
  def structured_output?
119
- RubyLLM.models.find(AIA.config.models.first.internal_id).structured_output?
121
+ RubyLLM.models.find(AIA.config.models.first.internal_id).supports?(:structured_output)
120
122
  rescue StandardError
121
123
  false
122
124
  end
@@ -4,15 +4,10 @@ require 'pm'
4
4
  require 'erb'
5
5
 
6
6
  module AIA
7
+ # :reek:TooManyMethods -- prompt/role fetching, front-matter merging, and fzf search form one lookup pipeline of small named steps
7
8
  class PromptHandler
8
9
  include AIA::SkillUtils
9
10
 
10
- # Struct for path-based role content (bypasses PM parsing)
11
- RoleContent = Struct.new(:content) do
12
- def to_s = content
13
- def metadata = nil
14
- end
15
-
16
11
  # Root-level YAML keys that are shorthands for deeper config paths
17
12
  SHORTHAND_KEYS = %w[model temperature top_p next pipeline shell erb].freeze
18
13
 
@@ -29,15 +24,35 @@ module AIA
29
24
 
30
25
  def initialize
31
26
  @prompts_dir = AIA.config.prompts.dir
32
- @roles_dir = AIA.config.prompts.roles_dir
33
27
 
28
+ flags = AIA.config.flags
34
29
  PM.configure do |c|
35
30
  c.prompts_dir = @prompts_dir
31
+ # flags.shell / flags.erb are the defaults; a file's front matter can still override them
32
+ c.shell = self.class.flag_enabled?(flags, :shell)
33
+ c.erb = self.class.flag_enabled?(flags, :erb)
36
34
  end
37
35
 
38
36
  register_pm_directives
39
37
  end
40
38
 
39
+ # A shell/erb flag is on unless it is explicitly false.
40
+ #
41
+ # @param flags [#shell, #erb, nil]
42
+ # @param name [Symbol] :shell or :erb
43
+ # @return [Boolean]
44
+ def self.flag_enabled?(flags, name)
45
+ return true unless flags.respond_to?(name)
46
+
47
+ flags.public_send(name) != false
48
+ end
49
+
50
+ # A pipeline from front matter: a list, or a comma-separated String
51
+ # ("a, b"), as a list of prompt IDs.
52
+ def self.pipeline_list(value)
53
+ Array(value).flat_map { it.to_s.split(',') }.map(&:strip).reject(&:empty?)
54
+ end
55
+
41
56
  def fetch_prompt(prompt_id)
42
57
  if prompt_id == '__FUZZY_SEARCH__'
43
58
  return fuzzy_search_prompt('')
@@ -47,10 +62,10 @@ module AIA
47
62
  return fetch_executable_prompt
48
63
  end
49
64
 
50
- prompt_file_path = File.join(@prompts_dir, "#{prompt_id}#{AIA.config.prompts.extname}")
65
+ prompt_file_path = prompt_path(prompt_id)
51
66
 
52
67
  parsed = if File.exist?(prompt_file_path)
53
- PM.parse(prompt_id)
68
+ parse_prompt_file(prompt_id)
54
69
  else
55
70
  $stderr.puts "Warning: Invalid prompt ID or file not found: #{prompt_id}"
56
71
  logger.warn("Invalid prompt ID or file not found: #{prompt_id}")
@@ -65,16 +80,15 @@ module AIA
65
80
  return handle_missing_role("roles/") if role_id.nil?
66
81
  return fetch_role_from_path(role_id) if path_based_id?(role_id)
67
82
 
68
- unless role_id.start_with?(AIA.config.prompts.roles_prefix)
69
- role_id = "#{AIA.config.prompts.roles_prefix}/#{role_id}"
83
+ prompts_cfg = AIA.config.prompts
84
+ unless role_id.start_with?(prompts_cfg.roles_prefix)
85
+ role_id = "#{prompts_cfg.roles_prefix}/#{role_id}"
70
86
  end
71
87
 
72
- role_file_path = File.join(@prompts_dir, "#{role_id}#{AIA.config.prompts.extname}")
88
+ role_file_path = File.join(@prompts_dir, "#{role_id}#{prompts_cfg.extname}")
73
89
 
74
90
  parsed = if File.exist?(role_file_path)
75
- # PM.parse(role_id) cannot resolve subdirectory IDs like "roles/jersey_mike"
76
- # and returns the ID string as content. Parse from raw file content instead.
77
- PM.parse_string(File.read(role_file_path))
91
+ parse_prompt_file(role_id)
78
92
  else
79
93
  $stderr.puts "Warning: Invalid role ID or file not found: #{role_id}"
80
94
  logger.warn("Invalid role ID or file not found: #{role_id}")
@@ -131,7 +145,7 @@ module AIA
131
145
 
132
146
  def fetch_executable_prompt
133
147
  content = AIA.config.executable_prompt_content
134
- parsed = PM.parse(content)
148
+ parsed = PM.parse_string(content)
135
149
  apply_metadata_config(parsed) if parsed
136
150
  parsed
137
151
  end
@@ -171,56 +185,47 @@ module AIA
171
185
  end
172
186
 
173
187
  # Apply root-level shorthand keys to AIA.config
174
- # rubocop:disable Metrics/AbcSize
188
+ # :reek:TooManyStatements -- one guarded assignment per supported front-matter shorthand key
175
189
  def apply_root_shorthands(meta_hash)
176
- # model → AIA.config.models (replace with single-model array)
177
- model_val = meta_hash['model'] || meta_hash[:model]
178
- if model_val
179
- AIA.config.models = [model_val]
180
- end
190
+ cfg = AIA.config
181
191
 
182
- # temperature → AIA.config.llm.temperature
183
- temp_val = meta_hash['temperature'] || meta_hash[:temperature]
184
- if temp_val
185
- AIA.config.llm.temperature = temp_val
186
- end
192
+ # model → cfg.models (replace; a String or list becomes ModelSpecs)
193
+ model_val = shorthand(meta_hash, :model)
194
+ cfg.models = Config::TO_MODEL_SPECS.call(Array(model_val)) if model_val
187
195
 
188
- # top_p → AIA.config.llm.top_p
189
- top_p_val = meta_hash['top_p'] || meta_hash[:top_p]
190
- if top_p_val
191
- AIA.config.llm.top_p = top_p_val
192
- end
196
+ temp_val = shorthand(meta_hash, :temperature)
197
+ cfg.llm.temperature = temp_val if temp_val
193
198
 
194
- # next → AIA.config.pipeline (replace)
195
- next_val = meta_hash['next'] || meta_hash[:next]
196
- if next_val
197
- if AIA.config.pipeline.any?
198
- logger.info "Prompt metadata 'next: #{next_val}' overrides remaining pipeline #{AIA.config.pipeline.inspect}"
199
- end
200
- AIA.config.pipeline = [next_val]
201
- end
199
+ top_p_val = shorthand(meta_hash, :top_p)
200
+ cfg.llm.top_p = top_p_val if top_p_val
202
201
 
203
- # pipeline → AIA.config.pipeline (replace)
204
- pipeline_val = meta_hash['pipeline'] || meta_hash[:pipeline]
205
- if pipeline_val
206
- if AIA.config.pipeline.any?
207
- logger.info "Prompt metadata 'pipeline' overrides remaining pipeline #{AIA.config.pipeline.inspect}"
208
- end
209
- AIA.config.pipeline = Array(pipeline_val)
210
- end
202
+ # next / pipeline → cfg.pipeline (replace)
203
+ next_val = shorthand(meta_hash, :next)
204
+ apply_pipeline_shorthand(cfg, next_val, "next: #{next_val}") if next_val
211
205
 
212
- # shell → AIA.config.flags.shell (and PM's shell via metadata)
213
- shell_val = meta_hash['shell'] || meta_hash[:shell]
214
- unless shell_val.nil?
215
- AIA.config.flags.shell = shell_val
216
- end
206
+ pipeline_val = shorthand(meta_hash, :pipeline)
207
+ apply_pipeline_shorthand(cfg, pipeline_val, "pipeline") if pipeline_val
208
+
209
+ # shell / erb → cfg.flags (and PM's shell/erb via metadata)
210
+ shell_val = shorthand(meta_hash, :shell)
211
+ cfg.flags.shell = shell_val unless shell_val.nil?
212
+
213
+ erb_val = shorthand(meta_hash, :erb)
214
+ cfg.flags.erb = erb_val unless erb_val.nil?
215
+ end
217
216
 
218
- # erb → AIA.config.flags.erb (and PM's erb via metadata)
219
- erb_val = meta_hash['erb'] || meta_hash[:erb]
220
- return if erb_val.nil?
221
- AIA.config.flags.erb = erb_val
217
+ # Fetch a front-matter shorthand value by string or symbol key.
218
+ def shorthand(meta_hash, key)
219
+ meta_hash[key.to_s] || meta_hash[key]
220
+ end
221
+
222
+ # Replace cfg.pipeline, logging when a remaining pipeline is overridden.
223
+ def apply_pipeline_shorthand(cfg, new_pipeline, label)
224
+ if cfg.pipeline.any?
225
+ logger.info "Prompt metadata '#{label}' overrides remaining pipeline #{cfg.pipeline.inspect}"
226
+ end
227
+ cfg.pipeline = self.class.pipeline_list(new_pipeline)
222
228
  end
223
- # rubocop:enable Metrics/AbcSize
224
229
 
225
230
  def logger
226
231
  @logger ||= LoggerManager.aia_logger
@@ -237,6 +242,10 @@ module AIA
237
242
  if sub_config
238
243
  deep_merge_into_config(sub_config, value)
239
244
  end
245
+ elsif key == :pipeline
246
+ target.pipeline = self.class.pipeline_list(value)
247
+ elsif key == :models
248
+ target.models = Config::TO_MODEL_SPECS.call(Array(value))
240
249
  elsif target.respond_to?(:"#{key}=")
241
250
  target.send(:"#{key}=", value)
242
251
  end
@@ -293,8 +302,7 @@ module AIA
293
302
  end
294
303
 
295
304
  def fetch_role_from_path(role_id)
296
- expanded = File.expand_path(role_id)
297
- expanded += '.md' if File.extname(expanded).empty?
305
+ expanded = prompt_path(role_id)
298
306
 
299
307
  unless File.exist?(expanded)
300
308
  $stderr.puts "Warning: Role file not found at path: #{expanded}"
@@ -302,7 +310,9 @@ module AIA
302
310
  return handle_missing_role(role_id)
303
311
  end
304
312
 
305
- RoleContent.new(File.read(expanded))
313
+ parsed = PM.parse(Pathname.new(expanded))
314
+ apply_metadata_config(parsed)
315
+ parsed
306
316
  end
307
317
 
308
318
  def fuzzy_search_prompt(prompt_id)
@@ -312,7 +322,7 @@ module AIA
312
322
  raise "Error: Could not find prompt with ID: #{prompt_id} even with fuzzy search"
313
323
  end
314
324
 
315
- PM.parse(new_prompt_id)
325
+ parse_prompt_file(new_prompt_id)
316
326
  end
317
327
 
318
328
  def handle_missing_role(role_id)
@@ -336,7 +346,19 @@ module AIA
336
346
  raise "Error: Could not find role with ID: #{role_id} even with fuzzy search"
337
347
  end
338
348
 
339
- PM.parse(new_role_id)
349
+ parse_prompt_file(new_role_id)
350
+ end
351
+
352
+ # Full path of the prompt file for +prompt_id+ (relative to the prompts dir).
353
+ def prompt_path(prompt_id)
354
+ SkillUtils.prompt_file_path(prompt_id, dir: @prompts_dir, extname: AIA.config.prompts.extname)
355
+ end
356
+
357
+ # Parse the prompt file for +prompt_id+. PM.parse only treats a single
358
+ # \w+ word as a file name, so IDs such as "code-review" or "dev/review"
359
+ # would be parsed as literal text; a Pathname is always read as a file.
360
+ def parse_prompt_file(prompt_id)
361
+ PM.parse(Pathname.new(prompt_path(prompt_id)))
340
362
  end
341
363
 
342
364
  def search_prompt_id_with_fzf(initial_query)
@@ -353,11 +375,12 @@ module AIA
353
375
  end
354
376
 
355
377
  def search_role_id_with_fzf(initial_query)
356
- role_files = Dir.glob(File.join(@roles_dir, "*#{AIA.config.prompts.extname}"))
357
- .map { |file| File.basename(file, AIA.config.prompts.extname) }
378
+ prompts_cfg = AIA.config.prompts
379
+ prefix = prompts_cfg.roles_prefix
380
+ role_files = RoleCatalog.names(@prompts_dir, prefix, extname: prompts_cfg.extname)
358
381
  fzf = AIA::Fzf.new(
359
382
  list: role_files,
360
- directory: @prompts_dir,
383
+ directory: File.join(@prompts_dir, prefix.to_s),
361
384
  query: initial_query,
362
385
  subject: 'Role IDs',
363
386
  prompt: 'Select a role ID:'
@@ -369,9 +392,7 @@ module AIA
369
392
  raise "No role ID selected"
370
393
  end
371
394
 
372
- unless role.start_with?(AIA.config.prompts.roles_prefix)
373
- role = AIA.config.prompts.roles_prefix + '/' + role
374
- end
395
+ role = "#{prefix}/#{role}" unless role.start_with?(prefix)
375
396
 
376
397
  role
377
398
  end
@@ -0,0 +1,105 @@
1
+ # lib/aia/provider_registry.rb
2
+ #
3
+ # Generic gateway to RubyLLM's provider registry (ruby_llm >= 2.0).
4
+ # AIA hardcodes no provider names: a model prefix counts as a provider
5
+ # exactly when RubyLLM has it registered — built-in providers, provider gems
6
+ # the user loaded (e.g. `aia --require ruby_llm-providers-xyzzy`), or a gem
7
+ # following the conventional `ruby_llm/providers/<slug>` require path that
8
+ # can be loaded on demand the first time its slug is seen.
9
+
10
+ module AIA
11
+ module ProviderRegistry
12
+ module_function
13
+
14
+ # All registered provider slugs, as strings.
15
+ def slugs
16
+ RubyLLM::Provider.providers.keys.map(&:to_s)
17
+ end
18
+
19
+ # Registered providers as {slug (String) => provider class}.
20
+ def providers
21
+ RubyLLM::Provider.providers.transform_keys(&:to_s)
22
+ end
23
+
24
+ # True when RubyLLM already has this slug registered.
25
+ def registered?(slug)
26
+ return false unless slug
27
+
28
+ RubyLLM::Provider.providers.key?(slug.to_sym)
29
+ end
30
+
31
+ # True when the slug names a registered provider, loading the
32
+ # conventional provider gem on demand the first time it is seen.
33
+ def available?(slug)
34
+ registered?(slug) || load(slug)
35
+ end
36
+
37
+ # Attempt to require the conventional gem path for a provider slug.
38
+ # Returns true when the provider ends up registered. Failed lookups are
39
+ # cached so repeated non-provider prefixes (model ids also use "/")
40
+ # don't pay the require cost every time.
41
+ def load(slug)
42
+ slug = slug.to_s
43
+ return false unless slug.match?(/\A[a-z0-9_]+\z/)
44
+
45
+ @load_attempts ||= {}
46
+ return @load_attempts[slug] if @load_attempts.key?(slug)
47
+
48
+ @load_attempts[slug] =
49
+ begin
50
+ require "ruby_llm/providers/#{slug}"
51
+ registered?(slug)
52
+ rescue LoadError
53
+ false
54
+ end
55
+ end
56
+
57
+ # A provider instance ready for API calls (model listing etc.).
58
+ # Raises RubyLLM's own errors for unknown or unconfigured providers.
59
+ def instantiate(slug)
60
+ RubyLLM::Provider.resolve!(slug.to_sym).new(RubyLLM.config)
61
+ end
62
+
63
+ # Slugs of conventionally named provider gems visible to the bundle
64
+ # (ruby_llm-providers-<slug>), whether or not they are loaded yet.
65
+ def installed_gem_slugs
66
+ Gem::Specification.filter_map do |spec|
67
+ spec.name.delete_prefix('ruby_llm-providers-') if spec.name.start_with?('ruby_llm-providers-')
68
+ end.uniq
69
+ end
70
+
71
+ # Register every installed conventional provider gem, so a full listing
72
+ # reflects what is available, not just what has been referenced so far.
73
+ def load_installed_gems
74
+ installed_gem_slugs.each { |slug| load(slug) }
75
+ end
76
+
77
+ # Endpoints for local servers that RubyLLM leaves unset, so they work
78
+ # without an environment variable when running on their usual port.
79
+ DEFAULT_ENDPOINTS = { 'ollama' => 'http://localhost:11434/v1' }.freeze
80
+
81
+ # Generic env-var endpoint overrides: for every registered provider,
82
+ # <SLUG>_API_BASE sets RubyLLM.config.<slug>_api_base when the provider
83
+ # defines that option (RubyLLM registers the accessor with the provider).
84
+ # A provider in DEFAULT_ENDPOINTS with no endpoint set gets its default.
85
+ def apply_env_endpoints
86
+ RubyLLM.configure do |c|
87
+ slugs.each do |slug|
88
+ setter = :"#{slug}_api_base="
89
+ next unless c.respond_to?(setter)
90
+
91
+ value = ENV.fetch("#{slug.upcase}_API_BASE", nil) || default_endpoint(c, slug)
92
+ c.public_send(setter, value) if value
93
+ end
94
+ end
95
+ end
96
+
97
+ # The default endpoint for +slug+ when RubyLLM has none configured.
98
+ def default_endpoint(ruby_llm_config, slug)
99
+ getter = :"#{slug}_api_base"
100
+ return nil if ruby_llm_config.respond_to?(getter) && ruby_llm_config.public_send(getter)
101
+
102
+ DEFAULT_ENDPOINTS[slug.to_s]
103
+ end
104
+ end
105
+ end
@@ -27,7 +27,7 @@ module AIA
27
27
  name: robot_name,
28
28
  system_prompt: system_prompt,
29
29
  local_tools: ToolLoader.filtered_tools(config),
30
- mcp_servers: RobotFactory.mcp_server_configs(config),
30
+ mcp: RobotFactory.mcp_servers(config),
31
31
  on_content: nil,
32
32
  config: RobotFactory.build_run_config(config)
33
33
  )