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
@@ -34,6 +34,12 @@ module AIA
34
34
  MAX_LAYERS = 5
35
35
  MAX_TASKS_PER_LAYER = 4
36
36
 
37
+ BUILD_BANNER = <<~BANNER
38
+ ╔══════════════════════════════════════════════════════════╗
39
+ ║ LAYERED ORCHESTRATION — 3-TIER BUILD ║
40
+ ╚══════════════════════════════════════════════════════════╝
41
+ BANNER
42
+
37
43
  # Tier 1 prompt: decompose requirements into layers
38
44
  # Deliberately short and directive to minimise qwen3 think-block noise.
39
45
  LAYER_DECOMPOSE_PROMPT = <<~PROMPT
@@ -124,19 +130,14 @@ module AIA
124
130
  #
125
131
  # @param context [HandlerContext] — reads context.prompt as requirements text
126
132
  # @return [String, nil] final synthesis or nil on failure
127
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
133
+ # :reek:TooManyStatements -- single orchestration script (banner, tier 1-3 waves, synthesis, report); the narrative order is the value
134
+ # :reek:DuplicateMethodCall -- say("") prints deliberate blank separator lines between build phases; not a hoistable value
128
135
  def handle(context)
129
136
  requirements = context.prompt
130
137
  primary = @robot.chief
131
138
 
132
139
  FileUtils.mkdir_p(@build_dir)
133
- say("")
134
- say("╔══════════════════════════════════════════════════════════╗")
135
- say("║ LAYERED ORCHESTRATION — 3-TIER BUILD ║")
136
- say("╚══════════════════════════════════════════════════════════╝")
137
- say("Requirements: #{requirements.lines.first.strip}")
138
- say("Build output: #{@build_dir}")
139
- say("")
140
+ print_build_banner(requirements)
140
141
 
141
142
  # Tier 1: Tobor decomposes requirements into layers
142
143
  layers = decompose_to_layers(primary, requirements)
@@ -173,23 +174,38 @@ module AIA
173
174
  save_final_report(final_text)
174
175
  say("Build complete: #{@build_dir}")
175
176
 
177
+ record_final_turn(requirements, final_text)
178
+ final_text
179
+ rescue StandardError => e
180
+ report_orchestration_error(e)
181
+ nil
182
+ end
183
+
184
+ private
185
+
186
+ def print_build_banner(requirements)
187
+ say("")
188
+ BUILD_BANNER.each_line { |line| say(line.chomp) }
189
+ say("Requirements: #{requirements.lines.first.strip}")
190
+ say("Build output: #{@build_dir}")
191
+ say("")
192
+ end
193
+
194
+ def record_final_turn(requirements, final_text)
176
195
  @tracker.record_turn(
177
196
  model: AIA.config.models.first.name,
178
197
  input: requirements,
179
198
  result: final_text
180
199
  )
181
-
182
- final_text
183
- rescue StandardError => e
184
- say("✗ Orchestration error: #{e.class}: #{e.message}")
185
- e.backtrace&.first(5)&.each { |line| say(" #{line}") }
186
- nil
187
200
  end
188
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
189
201
 
190
- private
202
+ def report_orchestration_error(error)
203
+ say("✗ Orchestration error: #{error.class}: #{error.message}")
204
+ error.backtrace&.first(5)&.each { |line| say(" #{line}") }
205
+ end
191
206
 
192
207
  # Tier 1: use a probe robot to decompose requirements into layer specs
208
+ # :reek:TooManyStatements -- probe run plus parse-failure diagnostics and rescue reporting
193
209
  def decompose_to_layers(robot, requirements)
194
210
  say("Tier 1 ▶ #{robot.name} decomposing requirements into layers...")
195
211
  probe = build_probe(robot.name + "-layer-probe")
@@ -227,6 +243,7 @@ module AIA
227
243
  #
228
244
  # @param layers [Array<Hash>] layer specs from Tier 1
229
245
  # @return [Hash{ String => Array<Hash> }] layer_name => task list ([] on failure)
246
+ # :reek:TooManyStatements -- per-layer async fan-out with per-layer error capture; the barrier plumbing is inherent
230
247
  def run_leads_wave(layers)
231
248
  results = {}
232
249
 
@@ -234,19 +251,21 @@ module AIA
234
251
  barrier = Async::Barrier.new
235
252
  layers.each do |layer|
236
253
  barrier.async do
237
- probe = build_probe("#{layer['name']}-lead")
254
+ name = layer['name']
255
+ title = layer['title']
256
+ probe = build_probe("#{name}-lead")
238
257
  prompt = TASK_DECOMPOSE_PROMPT % {
239
- layer_title: layer['title'],
258
+ layer_title: title,
240
259
  requirements: layer['requirements'].to_s,
241
260
  max_tasks: MAX_TASKS_PER_LAYER
242
261
  }
243
262
  result = probe.run(prompt, mcp: :none, tools: :none)
244
263
  tasks = parse_json_array(extract_content(result)).first(MAX_TASKS_PER_LAYER)
245
- say(" ✓ #{layer['title']} lead: #{tasks.size} task(s)")
246
- results[layer['name']] = tasks
264
+ say(" ✓ #{title} lead: #{tasks.size} task(s)")
265
+ results[name] = tasks
247
266
  rescue => e
248
- say(" ✗ #{layer['title']} lead failed: #{e.message}")
249
- results[layer['name']] = []
267
+ say(" ✗ #{title} lead failed: #{e.message}")
268
+ results[name] = []
250
269
  end
251
270
  end
252
271
  barrier.wait
@@ -261,6 +280,7 @@ module AIA
261
280
  #
262
281
  # @param layer_task_map [Hash{ String => Array<Hash> }] output of run_leads_wave
263
282
  # @return [Hash{ String => Hash }] "layer_name|artifact_path" => result hash
283
+ # :reek:TooManyStatements -- per-task async fan-out with success/failure result recording; the barrier plumbing is inherent
264
284
  def run_specialists_wave(layer_task_map)
265
285
  jobs = layer_task_map.flat_map do |layer_name, tasks|
266
286
  tasks.map { |task| { layer_name: layer_name, task: task } }
@@ -273,31 +293,32 @@ module AIA
273
293
  barrier = Async::Barrier.new
274
294
  jobs.each do |job|
275
295
  barrier.async do
276
- task = job[:task]
277
- key = "#{job[:layer_name]}|#{task['artifact']}"
278
- probe = build_probe("#{task['specialist']}-specialist")
279
-
280
- full_prompt = "Artifact to produce: #{task['artifact']}\n\n#{task['prompt']}"
296
+ task = job[:task]
297
+ artifact = task['artifact']
298
+ title = task['title']
299
+ specialist = task['specialist']
300
+ key = "#{job[:layer_name]}|#{artifact}"
301
+ probe = build_probe("#{specialist}-specialist")
302
+
303
+ full_prompt = "Artifact to produce: #{artifact}\n\n#{task['prompt']}"
281
304
  result = probe.run(full_prompt, mcp: :none, tools: :none)
282
305
  output = extract_content(result)
283
306
 
284
- save_artifact(task['artifact'], output)
285
- say(" ✓ #{task['artifact']}")
307
+ save_artifact(artifact, output)
308
+ say(" ✓ #{artifact}")
286
309
 
287
310
  results[key] = {
288
- task: task['title'],
289
- specialist: task['specialist'],
290
- artifact: task['artifact'],
311
+ task: title,
312
+ specialist: specialist,
313
+ artifact: artifact,
291
314
  output: output
292
315
  }
293
316
  rescue => e
294
- task = job[:task]
295
- key = "#{job[:layer_name]}|#{task['artifact']}"
296
- say(" ✗ #{task['artifact']} failed: #{e.message}")
317
+ say(" ✗ #{artifact} failed: #{e.message}")
297
318
  results[key] = {
298
- task: task['title'],
299
- specialist: task['specialist'],
300
- artifact: task['artifact'],
319
+ task: title,
320
+ specialist: specialist,
321
+ artifact: artifact,
301
322
  output: "[FAILED: #{e.message}]"
302
323
  }
303
324
  end
@@ -317,9 +338,11 @@ module AIA
317
338
  # @return [Array<Hash>]
318
339
  def build_layer_results(layers, layer_task_map, specialist_results)
319
340
  layers.map do |layer|
320
- tasks_for_layer = layer_task_map[layer['name']] || []
341
+ name = layer['name']
342
+ title = layer['title']
343
+ tasks_for_layer = layer_task_map[name] || []
321
344
  task_results = tasks_for_layer.map do |task|
322
- key = "#{layer['name']}|#{task['artifact']}"
345
+ key = "#{name}|#{task['artifact']}"
323
346
  specialist_results[key] || {
324
347
  task: task['title'],
325
348
  specialist: task['specialist'],
@@ -328,9 +351,9 @@ module AIA
328
351
  }
329
352
  end
330
353
 
331
- summary = synthesize_layer_from_results(layer['title'], task_results)
332
- say(" ✓ #{layer['title']} synthesis complete")
333
- { layer: layer['title'], tasks: task_results, summary: summary }
354
+ summary = synthesize_layer_from_results(title, task_results)
355
+ say(" ✓ #{title} synthesis complete")
356
+ { layer: title, tasks: task_results, summary: summary }
334
357
  end
335
358
  end
336
359
 
data/lib/aia/logger.rb CHANGED
@@ -6,7 +6,8 @@
6
6
  # Provides loggers for three systems:
7
7
  # - aia: Used within the AIA codebase for application-level logging
8
8
  # - llm: Passed to RubyLLM gem's configuration (RubyLLM.logger)
9
- # - mcp: Passed to RubyLLM::MCP process (RubyLLM::MCP.logger)
9
+ # - mcp: MCP connection logging (MCPConnectionManager) and RobotLab.config.logger;
10
+ # ruby_llm's own MCP client logs through RubyLLM.logger (llm)
10
11
  #
11
12
  # Configuration is read from AIA.config.logger section:
12
13
  # logger:
@@ -76,22 +77,23 @@ module AIA
76
77
  def configure_llm_logger
77
78
  return unless defined?(RubyLLM)
78
79
 
79
- logger = llm_logger
80
+ logger = llm_logger
81
+ llm_config = RubyLLM.config
80
82
 
81
83
  # Set our logger on the RubyLLM config object
82
- if RubyLLM.config.respond_to?(:logger=)
83
- RubyLLM.config.logger = logger
84
+ if llm_config.respond_to?(:logger=)
85
+ llm_config.logger = logger
84
86
  end
85
87
 
86
88
  # Also set log_file and log_level in case the logger gets recreated
87
- if RubyLLM.config.respond_to?(:log_file=)
89
+ if llm_config.respond_to?(:log_file=)
88
90
  file = effective_log_file(logger_config_for(:llm))
89
- RubyLLM.config.log_file = resolve_log_file_io(file)
91
+ llm_config.log_file = resolve_log_file_io(file)
90
92
  end
91
93
 
92
- if RubyLLM.config.respond_to?(:log_level=)
94
+ if llm_config.respond_to?(:log_level=)
93
95
  level = effective_log_level(logger_config_for(:llm))
94
- RubyLLM.config.log_level = LOG_LEVELS.fetch(level, Lumberjack::Severity::WARN)
96
+ llm_config.log_level = LOG_LEVELS.fetch(level) { Lumberjack::Severity::WARN }
95
97
  end
96
98
 
97
99
  # Reset the memoized @logger on RubyLLM module so next call uses our config
@@ -99,38 +101,8 @@ module AIA
99
101
  RubyLLM.instance_variable_set(:@logger, nil) if RubyLLM.instance_variable_defined?(:@logger)
100
102
  end
101
103
 
102
- # Configure RubyLLM::MCP's logger
103
- # RubyLLM::MCP.config has attr_writer :logger and a memoized getter.
104
- # We need to set both the config.logger and reset any memoization.
105
- def configure_mcp_logger
106
- return unless defined?(RubyLLM::MCP)
107
-
108
- logger = mcp_logger
109
-
110
- # First reset the memoized @logger so our settings take effect
111
- # RubyLLM::MCP.config.logger does: @logger ||= Logger.new(...)
112
- config = RubyLLM::MCP.config
113
- config.instance_variable_set(:@logger, nil) if config.instance_variable_defined?(:@logger)
114
-
115
- # Set our logger on the MCP config object
116
- # RubyLLM::MCP.config has attr_writer :logger (which sets @logger directly)
117
- if config.respond_to?(:logger=)
118
- config.logger = logger
119
- end
120
-
121
- # Also set log_file and log_level in case the logger gets recreated
122
- if config.respond_to?(:log_file=)
123
- file = effective_log_file(logger_config_for(:mcp))
124
- config.log_file = resolve_log_file_io(file)
125
- end
126
-
127
- return unless config.respond_to?(:log_level=)
128
- level = effective_log_level(logger_config_for(:mcp))
129
- config.log_level = LOG_LEVELS.fetch(level, Lumberjack::Severity::WARN)
130
- end
131
-
132
104
  # Convert log file specification to IO object or file path
133
- # RubyLLM::MCP expects an IO object or file path for log_file config
105
+ # RubyLLM expects an IO object or file path for log_file config
134
106
  def resolve_log_file_io(file)
135
107
  case file.to_s.upcase
136
108
  when 'STDOUT'
@@ -171,13 +143,12 @@ module AIA
171
143
 
172
144
  config = logger_config_for(system)
173
145
  level = effective_log_level(config, system)
174
- numeric = LOG_LEVELS.fetch(level, Lumberjack::Severity::WARN)
146
+ numeric = LOG_LEVELS.fetch(level) { Lumberjack::Severity::WARN }
175
147
  logger.level = numeric
176
148
  end
177
149
 
178
- # Keep RubyLLM / MCP configs in sync so they don't override us
150
+ # Keep the RubyLLM config in sync so it doesn't override us
179
151
  configure_llm_logger
180
- configure_mcp_logger
181
152
  end
182
153
 
183
154
  # =======================================================================
@@ -193,7 +164,7 @@ module AIA
193
164
  def test_mode!(level: :debug)
194
165
  reset!
195
166
  @test_mode = true
196
- @test_level = LOG_LEVELS.fetch(level.to_s, Lumberjack::Severity::DEBUG)
167
+ @test_level = LOG_LEVELS.fetch(level.to_s) { Lumberjack::Severity::DEBUG }
197
168
 
198
169
  # Pre-create loggers with test devices
199
170
  @aia_logger = create_test_logger(:aia)
@@ -273,7 +244,7 @@ module AIA
273
244
  device = create_device(file, flush: flush)
274
245
  Lumberjack::Logger.new(
275
246
  device,
276
- level: LOG_LEVELS.fetch(level, Lumberjack::Severity::WARN),
247
+ level: LOG_LEVELS.fetch(level) { Lumberjack::Severity::WARN },
277
248
  progname: system.to_s.upcase
278
249
  )
279
250
  end
@@ -307,23 +278,21 @@ module AIA
307
278
  # @param file [String] The file config value
308
279
  # @param flush [Boolean] If true, flush immediately (no buffering)
309
280
  # @return [Lumberjack::Device] The device instance
281
+ # :reek:BooleanParameter -- flush: maps directly onto Lumberjack's autoflush; two constructors would obscure that single toggle
310
282
  def create_device(file, flush: true)
311
- # buffer_size: 0 means immediate flush (no buffering)
312
- buffer_size = flush ? 0 : 8192
313
-
314
283
  case file.to_s.upcase
315
284
  when 'STDOUT'
316
- Lumberjack::Device::Writer.new($stdout, buffer_size: buffer_size)
285
+ Lumberjack::Device::Writer.new($stdout, autoflush: flush)
317
286
  when 'STDERR'
318
- Lumberjack::Device::Writer.new($stderr, buffer_size: buffer_size)
287
+ Lumberjack::Device::Writer.new($stderr, autoflush: flush)
319
288
  else
320
289
  path = File.expand_path(file)
321
- # Use date rolling for file-based logs
322
- # Multiple loggers can safely write to the same file
323
- Lumberjack::Device::DateRollingLogFile.new(
290
+ # Daily date rolling via Logger::LogDevice, which also makes the
291
+ # file safe for multiple loggers to write to
292
+ Lumberjack::Device::LogFile.new(
324
293
  path,
325
- roll: :daily,
326
- buffer_size: buffer_size
294
+ shift_age: 'daily',
295
+ autoflush: flush
327
296
  )
328
297
  end
329
298
  end
@@ -333,15 +302,11 @@ module AIA
333
302
  # @param system [Symbol] The system (:aia, :llm, :mcp)
334
303
  # @return [ConfigSection, nil] The configuration section
335
304
  def logger_config_for(system)
336
- return nil unless AIA.config&.logger
305
+ logger_cfg = AIA.config&.logger
306
+ return nil unless logger_cfg
307
+ return nil unless %i[aia llm mcp].include?(system)
337
308
 
338
- case system
339
- when :aia then AIA.config.logger.aia
340
- when :llm then AIA.config.logger.llm
341
- when :mcp then AIA.config.logger.mcp
342
- end
343
- rescue NoMethodError
344
- nil
309
+ logger_cfg.public_send(system) if logger_cfg.respond_to?(system)
345
310
  end
346
311
  end
347
312
  end
@@ -3,32 +3,45 @@
3
3
  # lib/aia/mcp_config_normalizer.rb
4
4
  #
5
5
  # Normalizes a single MCP server config from AIA flat format to the nested
6
- # transport format expected by robot_lab. Server selection/filtering is
7
- # the responsibility of MCPDiscovery — this class only transforms shape.
6
+ # transport format expected by robot_lab (RobotLab::MCP.build). Server
7
+ # selection/filtering is the responsibility of MCPDiscovery — this class
8
+ # only transforms shape.
8
9
 
9
10
  module AIA
10
11
  class MCPConfigNormalizer
12
+ # Flat keys that describe how to reach the server; folded into :transport.
13
+ TRANSPORT_KEYS = %i[type command args env url headers bearer_token oauth cwd directory].freeze
14
+
11
15
  class << self
12
16
  # Normalize a single MCP server config to robot_lab's nested transport format.
17
+ # Settings robot_lab understands (timeout, prefix, only, except,
18
+ # requires_approval, description, ...) are carried through unchanged.
19
+ #
20
+ # A RubyLLM::MCP subclass or instance, or the constant name of one,
21
+ # already describes its own transport and is returned unchanged
22
+ # (RobotLab::MCP.build resolves the name).
13
23
  #
14
- # @param server [Hash]
15
- # @return [Hash]
24
+ # @param server [Hash, Class<RubyLLM::MCP>, RubyLLM::MCP, String]
25
+ # @return [Hash, Class<RubyLLM::MCP>, RubyLLM::MCP, String]
16
26
  def normalize(server)
17
- server = server.is_a?(Hash) ? server.transform_keys(&:to_sym) : server.to_h.transform_keys(&:to_sym)
27
+ return server if mcp_object?(server) || AIA::Utility.mcp_class_name?(server)
28
+
29
+ server = server.to_h.transform_keys(&:to_sym)
18
30
 
19
31
  # Already in robot_lab format — pass through
20
32
  return server if server[:transport]
21
33
 
22
- # Legacy flat format: wrap command/args/env into transport
23
- name = server[:name]
24
- transport = { type: server[:type] || 'stdio' }
25
- transport[:command] = server[:command] if server[:command]
26
- transport[:args] = Array(server[:args]) if server[:args]
27
- transport[:env] = server[:env] if server[:env]
34
+ transport = server.slice(*TRANSPORT_KEYS).compact
35
+ transport[:type] ||= server[:url] ? 'streamable-http' : 'stdio'
36
+ transport[:args] = Array(transport[:args]) if transport.key?(:args)
37
+
38
+ server.except(*TRANSPORT_KEYS).merge(transport: transport)
39
+ end
28
40
 
29
- result = { name: name, transport: transport }
30
- result[:timeout] = server[:timeout] if server[:timeout]
31
- result
41
+ # @param server [Object]
42
+ # @return [Boolean] true for a RubyLLM::MCP instance or subclass
43
+ def mcp_object?(server)
44
+ server.is_a?(RubyLLM::MCP) || (server.is_a?(Class) && server <= RubyLLM::MCP)
32
45
  end
33
46
  end
34
47
  end