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
@@ -14,7 +14,6 @@ module AIA
14
14
  def mcp_server_names
15
15
  connected = AIA.config&.connected_mcp_servers
16
16
  return connected unless connected.nil?
17
- return RubyLLM::MCP.clients.keys if defined?(RubyLLM::MCP) && RubyLLM::MCP.clients.any?
18
17
  effective_mcp_server_names
19
18
  end
20
19
 
@@ -27,31 +26,40 @@ module AIA
27
26
  end
28
27
 
29
28
  def effective_mcp_server_names
30
- return [] if AIA.config&.flags&.no_mcp
31
- servers = AIA.config&.mcp_servers || []
32
- return [] if servers.empty?
29
+ cfg = AIA.config
30
+ return [] if cfg&.flags&.no_mcp
33
31
 
34
- names = servers.map { |s| server_name(s) }.compact
35
- use_list = Array(AIA.config.mcp_use)
36
- skip_list = Array(AIA.config.mcp_skip)
32
+ servers = cfg&.mcp_servers || []
33
+ return [] if servers.empty?
37
34
 
38
- if use_list.any?
39
- names.select { |n| use_list.include?(n) }
40
- elsif skip_list.any?
41
- names.reject { |n| skip_list.include?(n) }
42
- else
43
- names
44
- end
35
+ MCPDiscovery.select(servers, use: cfg.mcp_use, skip: cfg.mcp_skip).map { server_name(it) }.compact
45
36
  end
46
37
 
38
+ # The name a configured server is known by: a Hash's :name, a server
39
+ # instance's #name, or for a RubyLLM::MCP subclass (or its constant name,
40
+ # e.g. "SharedTools::MCP::GitHub") the server's default name ("github").
41
+ # A constant name whose class is not loaded yet is returned as given.
47
42
  def server_name(s)
48
- if s.is_a?(Hash)
49
- s[:name] || s['name']
50
- elsif s.respond_to?(:name)
51
- s.name
52
- else
53
- s.to_s
43
+ case s
44
+ when Hash then s[:name] || s['name']
45
+ when Class then s.respond_to?(:default_name) ? s.default_name : s.name
46
+ when String then mcp_class_name?(s) ? class_server_name(s) : s
47
+ else s.respond_to?(:name) ? s.name : s.to_s
54
48
  end
55
49
  end
50
+
51
+ # True when +value+ is shaped like a Ruby constant path ("Foo::Bar"),
52
+ # the form an mcp_servers: entry takes to name a RubyLLM::MCP subclass.
53
+ def mcp_class_name?(value)
54
+ value.is_a?(String) && value.match?(/\A(::)?[A-Z]\w*(::[A-Z]\w*)*\z/)
55
+ end
56
+
57
+ private
58
+
59
+ def class_server_name(constant_name)
60
+ RobotLab::MCP.name_of(constant_name)
61
+ rescue RobotLab::MCPError
62
+ constant_name
63
+ end
56
64
  end
57
65
  end
@@ -10,10 +10,15 @@ module AIA
10
10
  class MentionRouter
11
11
  include ContentExtractor
12
12
  include HandlerProtocol
13
+ include Speech
13
14
 
14
15
  # Reserved @mention that broadcasts the message to every crew member.
15
16
  BROADCAST_TOKEN = 'crew'
16
17
 
18
+ # An @name at the start of a word. The look-behind leaves e-mail
19
+ # addresses (bob@example.com) and dotted names alone.
20
+ MENTION = /(?<![\w.@])@(\w+)/
21
+
17
22
  def initialize(ui_presenter:, tracker:, streaming_runner:)
18
23
  @ui_presenter = ui_presenter
19
24
  @tracker = tracker
@@ -25,18 +30,23 @@ module AIA
25
30
  #
26
31
  # @param context [HandlerContext] — reads context.robot and context.prompt
27
32
  # @return [Boolean]
33
+ # :reek:TooManyStatements -- mention routing: scan, resolve, report unknowns, dispatch; one decision chain
28
34
  def handle(context) # rubocop:disable Naming/PredicateMethod
29
35
  robot = context.robot
30
36
  prompt = context.prompt
31
37
  return false unless robot.network?
32
38
 
33
- mention_tokens = prompt.scan(/@(\w+)/i).flatten
39
+ mention_tokens = prompt.scan(MENTION).flatten
34
40
  return false if mention_tokens.empty?
35
41
 
36
42
  all_robots = robot.crew
37
43
  matched = resolve_mentions(mention_tokens, all_robots)
38
44
 
45
+ # No crew member named: ordinary text for the model, unless the message
46
+ # opens with an @address -- most likely a mistyped name.
39
47
  if matched.empty?
48
+ return false unless addressed?(prompt)
49
+
40
50
  report_unknown_mentions(mention_tokens, all_robots)
41
51
  return true
42
52
  end
@@ -58,11 +68,16 @@ module AIA
58
68
  prompt.sub(/\A(?:\s*@\w+)+\s*/i, '').strip
59
69
  end
60
70
 
71
+ # True when the message opens with an @address.
72
+ def addressed?(prompt)
73
+ prompt.match?(/\A\s*@\w/)
74
+ end
75
+
61
76
  # True when every @mention is part of the leading address — i.e. nothing but
62
77
  # @mentions before the message — so it's a broadcast to its addressees and
63
78
  # runs concurrently. A @mention woven into the body makes it sequential.
64
79
  def leading_address_only?(prompt)
65
- !strip_addressing_prefix(prompt).match?(/@\w+/)
80
+ !strip_addressing_prefix(prompt).match?(MENTION)
66
81
  end
67
82
 
68
83
  # Resolve @mention tokens to robots. The reserved @crew token broadcasts to
@@ -120,10 +135,11 @@ module AIA
120
135
 
121
136
  # A single addressed robot streams its reply token-by-token.
122
137
  def run_streamed(bot, prompt)
138
+ name = bot.name
123
139
  result, streamed_content, elapsed = @streaming_runner.run(
124
140
  bot, prompt,
125
- header: "\nAI (#{bot.name}):\n ",
126
- spinner_message: "#{bot.name} processing..."
141
+ header: "\nAI (#{name}):\n ",
142
+ spinner_message: "#{name} processing..."
127
143
  )
128
144
  content = streamed_content || extract_content(result)
129
145
 
@@ -137,7 +153,7 @@ module AIA
137
153
  finalize_reply(bot, prompt, result, content, elapsed)
138
154
  content
139
155
  rescue StandardError => e
140
- @ui_presenter.display_info("Error from #{bot.name}: #{e.class}: #{e.message}")
156
+ @ui_presenter.display_info("Error from #{name}: #{e.class}: #{e.message}")
141
157
  nil
142
158
  end
143
159
 
@@ -156,6 +172,7 @@ module AIA
156
172
 
157
173
  # Run one crew member to completion (off the streaming path), in a worker
158
174
  # thread. Returns [bot, result, elapsed, error] — no shared state touched.
175
+ # :reek:DuplicateMethodCall -- each clock_gettime must read the clock at that moment (start, success end, failure end)
159
176
  def run_member(bot, prompt)
160
177
  started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
161
178
  result = bot.run(prompt, mcp: :inherit, tools: :inherit)
@@ -209,52 +226,5 @@ module AIA
209
226
  return message.model if message.respond_to?(:model) && message.model
210
227
  nil
211
228
  end
212
-
213
- def speak(content)
214
- return unless AIA.speak?
215
-
216
- audio = AIA.config.audio
217
- command = audio.speak_command || 'say'
218
- env = {}
219
- env['SPEECH_MODEL'] = audio.speech_model if audio.speech_model
220
-
221
- if command == 'say'
222
- run_with_spinner("Speaking...") do
223
- if audio.voice && !audio.voice.to_s.strip.empty?
224
- system(env, command, '-v', audio.voice, content.to_s)
225
- else
226
- system(env, command, content.to_s)
227
- end
228
- end
229
- else
230
- require 'tempfile'
231
- tmpfile = Tempfile.new(['aia-tts-', '.mp3'])
232
- tmpfile.close
233
- begin
234
- run_with_spinner("Converting to audio...") do
235
- system(env, command, content.to_s, tmpfile.path)
236
- end
237
- if File.size?(tmpfile.path)
238
- run_with_spinner("Speaking...") do
239
- system('afplay', tmpfile.path)
240
- end
241
- end
242
- ensure
243
- tmpfile.unlink
244
- end
245
- end
246
- rescue StandardError => e
247
- $stderr.puts "Warning: Speech failed: #{e.message}"
248
- end
249
-
250
- def run_with_spinner(message)
251
- spinner = TTY::Spinner.new("[:spinner] #{message}", format: :bouncing_ball, output: $stderr)
252
- spinner.auto_spin
253
- begin
254
- yield
255
- ensure
256
- spinner.stop
257
- end
258
- end
259
229
  end
260
230
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ # lib/aia/modality_query.rb
4
+ #
5
+ # Matches a model's input/output modalities against an "INPUT_to_OUTPUT"
6
+ # search term such as "text_to_image" (as used by --available-models and
7
+ # /available_models). RubyLLM 2.x exposes modalities as plain input/output
8
+ # lists, so the term is split and each side is looked up in its list.
9
+
10
+ module AIA
11
+ module ModalityQuery
12
+ SEPARATOR = '_to_'
13
+
14
+ module_function
15
+
16
+ # @param term [String]
17
+ # @return [Boolean] true when +term+ has the INPUT_to_OUTPUT form
18
+ def modality_term?(term)
19
+ term.to_s.include?(SEPARATOR)
20
+ end
21
+
22
+ # @param modalities [#input, #output] a model's modalities
23
+ # @param term [String] e.g. "text_to_image" or ":image_to_text"
24
+ # @return [Boolean]
25
+ def matches?(modalities, term)
26
+ input, output = term.to_s.delete_prefix(':').downcase.split(SEPARATOR, 2)
27
+ return false if input.to_s.empty? || output.to_s.empty?
28
+
29
+ names(modalities.input).include?(input) && names(modalities.output).include?(output)
30
+ end
31
+
32
+ def names(list)
33
+ Array(list).map { it.to_s.downcase }
34
+ end
35
+ end
36
+ end
@@ -9,28 +9,28 @@ module AIA
9
9
  class ModelAliasRegistry
10
10
  DEFAULT_ALIASES = {
11
11
  # Short names
12
- "claude" => "claude-sonnet-4-20250514",
13
- "sonnet" => "claude-sonnet-4-20250514",
14
- "opus" => "claude-opus-4-20250514",
12
+ "claude" => "claude-sonnet-4-5",
13
+ "sonnet" => "claude-sonnet-4-5",
14
+ "opus" => "claude-opus-5",
15
15
  "haiku" => "claude-haiku-4-5-20251001",
16
16
  "gpt4" => "gpt-4o",
17
17
  "gpt4o" => "gpt-4o",
18
18
  "gpt4mini" => "gpt-4o-mini",
19
- "gemini" => "gemini-2.0-flash",
20
- "flash" => "gemini-2.0-flash",
21
- "llama" => "llama-3.1-70b",
19
+ "gemini" => "gemini-3.8-flash",
20
+ "flash" => "gemini-3.8-flash",
21
+ "llama" => "meta-llama/llama-4-maverick",
22
22
 
23
23
  # Provider names (resolve to default model for provider)
24
- "anthropic" => "claude-sonnet-4-20250514",
24
+ "anthropic" => "claude-sonnet-4-5",
25
25
  "openai" => "gpt-4o",
26
- "google" => "gemini-2.0-flash",
27
- "meta" => "llama-3.1-70b",
26
+ "google" => "gemini-3.8-flash",
27
+ "meta" => "meta-llama/llama-4-maverick",
28
28
 
29
29
  # Capability descriptors
30
30
  "fast" => "claude-haiku-4-5-20251001",
31
31
  "cheap" => "gpt-4o-mini",
32
- "best" => "claude-opus-4-20250514",
33
- "coding" => "claude-sonnet-4-20250514",
32
+ "best" => "claude-opus-5",
33
+ "coding" => "claude-sonnet-4-5",
34
34
  "vision" => "gpt-4o"
35
35
  }.freeze
36
36
 
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ # lib/aia/model_registry.rb
4
+ #
5
+ # AIA's local copy of the RubyLLM model list, kept at
6
+ # <paths.aia_dir>/models.json and refreshed from the provider APIs every
7
+ # registry.refresh days (--refresh DAYS; 0 turns refreshing off).
8
+
9
+ require 'date'
10
+ require 'fileutils'
11
+
12
+ module AIA
13
+ module ModelRegistry
14
+ DEFAULT_REFRESH_DAYS = 7
15
+
16
+ module_function
17
+
18
+ # Point RubyLLM at AIA's models.json, refreshing it first when it is due.
19
+ #
20
+ # @param config [AIA::Config]
21
+ def prepare(config)
22
+ path = registry_path(config.paths&.aia_dir)
23
+ return unless path
24
+
25
+ days = refresh_days(config.registry&.refresh)
26
+ if refresh_due?(path, days)
27
+ refresh(path)
28
+ elsif File.exist?(path)
29
+ use(path)
30
+ end
31
+ end
32
+
33
+ # @return [String, nil] the models.json path, or nil without an aia_dir
34
+ def registry_path(aia_dir)
35
+ return nil if aia_dir.to_s.strip.empty?
36
+
37
+ File.join(File.expand_path(aia_dir), 'models.json')
38
+ end
39
+
40
+ # The refresh interval as a whole number of days; nil means the default.
41
+ def refresh_days(value)
42
+ return DEFAULT_REFRESH_DAYS if value.nil?
43
+
44
+ [Integer(value.to_s, exception: false) || DEFAULT_REFRESH_DAYS, 0].max
45
+ end
46
+
47
+ # Whether +path+ is missing or more than +days+ days old. Never due when
48
+ # +days+ is 0.
49
+ def refresh_due?(path, days, today: Date.today)
50
+ return false if days.zero?
51
+ return true unless File.exist?(path)
52
+
53
+ today > File.mtime(path).to_date + days
54
+ end
55
+
56
+ # Load the model list from +path+.
57
+ def use(path)
58
+ RubyLLM.config.model_registry_file = path
59
+ RubyLLM.models.load_from_json(path)
60
+ end
61
+
62
+ # Refresh the model list from the provider APIs and save it to +path+.
63
+ # On failure RubyLLM keeps the list it already had.
64
+ def refresh(path)
65
+ llm_config = RubyLLM.config
66
+ previous = llm_config.model_registry_file
67
+ FileUtils.mkdir_p(File.dirname(path))
68
+ llm_config.model_registry_file = path
69
+ Speech.run_with_spinner("Refreshing the model list...") { RubyLLM.models.refresh }
70
+ rescue StandardError => e
71
+ llm_config&.model_registry_file = previous
72
+ $stderr.puts "Warning: Could not refresh the model list (#{e.message}). Using the existing list."
73
+ end
74
+ end
75
+ end
@@ -15,11 +15,12 @@ module AIA
15
15
  # @param config [AIA::Config]
16
16
  # @param namer [RobotNamer]
17
17
  # @return [RobotLab::Network]
18
+ # :reek:TooManyStatements -- gathers shared robot inputs then declares one network task per pipeline step
18
19
  def build_pipeline_network(config, namer)
19
20
  prompts = config.pipeline
20
21
  run_config = RobotFactory.build_run_config(config)
21
22
  tools = ToolLoader.filtered_tools(config)
22
- mcp = RobotFactory.mcp_server_configs(config)
23
+ mcp = RobotFactory.mcp_servers(config)
23
24
  model_spec = config.models.first
24
25
 
25
26
  RobotLab.create_network(name: "aia-pipeline") do
@@ -31,7 +32,7 @@ module AIA
31
32
  name: "#{namer.name_for(model_spec.name)}-s#{i}",
32
33
  system_prompt: nil,
33
34
  local_tools: tools,
34
- mcp_servers: mcp,
35
+ mcp: mcp,
35
36
  config: run_config
36
37
  )
37
38
  task task_name, robot, depends_on: prev ? [prev] : :none
@@ -48,7 +49,7 @@ module AIA
48
49
  def build_parallel_network(config, namer)
49
50
  run_config = RobotFactory.build_run_config(config)
50
51
  tools = ToolLoader.filtered_tools(config)
51
- mcp = RobotFactory.mcp_server_configs(config)
52
+ mcp = RobotFactory.mcp_servers(config)
52
53
  aia_config = config
53
54
  roster = config.models.map { |spec| { name: namer.name_for(spec.name), spec: spec } }
54
55
  build_robot = ->(entry) { build_roster_robot(entry, roster, tools, mcp, run_config, aia_config) }
@@ -66,13 +67,15 @@ module AIA
66
67
  # @param config [AIA::Config]
67
68
  # @param namer [RobotNamer]
68
69
  # @return [RobotLab::Network]
70
+ # :reek:TooManyStatements -- gathers shared robot inputs, declares one task per roster member plus the synthesizer
69
71
  def build_consensus_network(config, namer)
70
72
  run_config = RobotFactory.build_run_config(config)
71
- tools = ToolLoader.filtered_tools(config)
72
- mcp = RobotFactory.mcp_server_configs(config)
73
- primary = config.models.first
73
+ tools = ToolLoader.filtered_tools(config)
74
+ mcp = RobotFactory.mcp_servers(config)
75
+ models = config.models
76
+ primary = models.first
74
77
  aia_config = config
75
- roster = config.models.map { |spec| { name: namer.name_for(spec.name), spec: spec } }
78
+ roster = models.map { |spec| { name: namer.name_for(spec.name), spec: spec } }
76
79
  build_robot = ->(entry) { build_roster_robot(entry, roster, tools, mcp, run_config, aia_config) }
77
80
 
78
81
  RobotLab.create_network(name: "aia-consensus") do
@@ -89,11 +92,12 @@ module AIA
89
92
  config: run_config
90
93
  )
91
94
  task :consensus, synthesizer,
92
- depends_on: config.models.map { |s| s.internal_id.to_sym }
95
+ depends_on: models.map { |s| s.internal_id.to_sym }
93
96
  end
94
97
  end
95
98
 
96
99
  # Shared helper: builds a single roster robot (used by parallel and consensus networks).
100
+ # :reek:LongParameterList { max_params: 6 } -- pass-through of the shared per-network build inputs
97
101
  def build_roster_robot(entry, roster, tools, mcp, run_config, aia_config)
98
102
  spec = entry[:spec]
99
103
  identity = SystemPromptAssembler.build_identity_prompt(entry[:name], spec, roster)
@@ -104,7 +108,7 @@ module AIA
104
108
  name: entry[:name],
105
109
  system_prompt: system_prompt,
106
110
  local_tools: tools,
107
- mcp_servers: mcp,
111
+ mcp: mcp,
108
112
  config: run_config
109
113
  )
110
114
  end
@@ -116,20 +120,22 @@ module AIA
116
120
  # @param namer [RobotNamer]
117
121
  # @param server_groups [Array<Array<Hash>>]
118
122
  # @return [RobotLab::Network]
123
+ # :reek:TooManyStatements -- gathers shared robot inputs, declares one task per server group plus the synthesizer
119
124
  def build_concurrent_mcp_network(config, namer, server_groups)
120
125
  run_config = RobotFactory.build_run_config(config)
121
126
  tools = ToolLoader.filtered_tools(config)
122
127
  model_spec = config.models.first
123
128
  system_prompt = SystemPromptAssembler.resolve_system_prompt(config, model_spec)
129
+ group_servers = server_groups.map { RobotFactory.mcp_servers(config, it) }
124
130
 
125
131
  network = RobotLab.create_network(name: "aia-concurrent-mcp") do
126
- server_groups.each_with_index do |group, i|
132
+ group_servers.each_with_index do |servers, i|
127
133
  robot = RobotFactory.build_robot(
128
134
  model_spec,
129
135
  name: "#{namer.name_for(model_spec.name)}-w#{i}",
130
136
  system_prompt: system_prompt,
131
137
  local_tools: tools,
132
- mcp_servers: group.map { |s| RobotFactory.normalize_mcp_config(s) },
138
+ mcp: servers,
133
139
  config: run_config
134
140
  )
135
141
  task :"mcp_worker_#{i}", robot, depends_on: :none
@@ -16,12 +16,12 @@ module AIA
16
16
  def initialize_memory(network, config)
17
17
  return network unless network.respond_to?(:memory)
18
18
 
19
- memory = network.memory
20
- memory.data.session_id = SecureRandom.hex(8)
21
- memory.data.model_count = config.models.size
22
- memory.data.model_names = config.models.map(&:name)
23
- memory.data.mode = config.flags.consensus ? :consensus : :parallel
24
- memory.data.turn_count = 0
19
+ data = network.memory.data
20
+ data.session_id = SecureRandom.hex(8)
21
+ data.model_count = config.models.size
22
+ data.model_names = config.models.map(&:name)
23
+ data.mode = config.flags.consensus ? :consensus : :parallel
24
+ data.turn_count = 0
25
25
 
26
26
  network
27
27
  end
@@ -20,8 +20,9 @@
20
20
  # ruby_llm's own private parse_error_from_json. Guarded against API drift: if
21
21
  # parse_error_from_json is renamed/removed the patch is skipped with a warning.
22
22
  #
23
- # NOTE: This fixes a genuine upstream bug — it should be contributed to
24
- # crmne/ruby_llm so this patch can eventually be retired.
23
+ # ruby_llm >= 2.0 moved the module to RubyLLM::Protocol::Streaming and fixed
24
+ # the bug upstream (nil-safe data-line access plus SSE event buffering), so on
25
+ # 2.0+ this patch deliberately does not apply. It stays for the 1.x line only.
25
26
 
26
27
  module AIA
27
28
  module RubyLLMStreamingError
@@ -35,8 +36,24 @@ module AIA
35
36
  end
36
37
  end
37
38
 
38
- if RubyLLM::Streaming.private_method_defined?(:parse_error_from_json)
39
- RubyLLM::Streaming.prepend(AIA::RubyLLMStreamingError)
39
+ # ruby_llm is Zeitwerk-managed, so the constants must be referenced (not
40
+ # defined?-probed) to trigger their autoload; NameError means "not this version".
41
+ streaming =
42
+ begin
43
+ RubyLLM::Streaming # ruby_llm 1.x
44
+ rescue NameError
45
+ nil
46
+ end
47
+
48
+ if streaming.nil?
49
+ begin
50
+ RubyLLM::Protocol::Streaming # ruby_llm >= 2.0: fixed upstream, no patch needed
51
+ rescue NameError
52
+ $stderr.puts "WARNING: [AIA] ruby_llm patch skipped: no streaming module found " \
53
+ "(ruby_llm #{RubyLLM::VERSION}). Streaming error messages may be cryptic."
54
+ end
55
+ elsif streaming.private_method_defined?(:parse_error_from_json)
56
+ streaming.prepend(AIA::RubyLLMStreamingError)
40
57
  else
41
58
  $stderr.puts "WARNING: [AIA] ruby_llm patch skipped: RubyLLM::Streaming#parse_error_from_json " \
42
59
  "not found (ruby_llm #{RubyLLM::VERSION}). Streaming error messages may be cryptic."
@@ -0,0 +1,18 @@
1
+ # lib/aia/patches/ruby_llm_tool_param_compat.rb
2
+ #
3
+ # ruby_llm 1.x tools declare arguments with `param ... desc:`; ruby_llm 2.0
4
+ # renamed the DSL to `parameter ... description:`. AIA's tool classes are
5
+ # written in the 2.0 style. On a 1.x runtime this shim translates the 2.0
6
+ # declaration back onto the 1.x `param` DSL so the same tool classes load on
7
+ # both lines. Retire together with ruby_llm 1.x support.
8
+
9
+ module AIA
10
+ module RubyLLMToolParamCompat
11
+ def parameter(name, **options)
12
+ options[:desc] = options.delete(:description) if options.key?(:description)
13
+ param(name, **options)
14
+ end
15
+ end
16
+ end
17
+
18
+ RubyLLM::Tool.extend(AIA::RubyLLMToolParamCompat) unless RubyLLM::Tool.respond_to?(:parameter)