aia 2.0.0.0.pre.beta2 → 2.0.1

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 (227) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +152 -223
  3. data/README.md +41 -18
  4. data/bin/aia +8 -3
  5. data/lib/aia/aia_completion.bash +2 -3
  6. data/lib/aia/aia_completion.fish +6 -5
  7. data/lib/aia/aia_completion.zsh +2 -3
  8. data/lib/aia/chat_loop.rb +16 -14
  9. data/lib/aia/config/cli_parser.rb +123 -91
  10. data/lib/aia/config/defaults.yml +18 -40
  11. data/lib/aia/config/mcp_parser.rb +30 -36
  12. data/lib/aia/config/model_spec.rb +8 -14
  13. data/lib/aia/config/validator.rb +102 -103
  14. data/lib/aia/config/value_caster.rb +76 -0
  15. data/lib/aia/config.rb +70 -53
  16. data/lib/aia/crew.rb +29 -19
  17. data/lib/aia/debate_handler.rb +27 -10
  18. data/lib/aia/directives/configuration_directives.rb +55 -14
  19. data/lib/aia/directives/context_directives.rb +24 -12
  20. data/lib/aia/directives/execution_directives.rb +18 -23
  21. data/lib/aia/directives/model_directives.rb +41 -104
  22. data/lib/aia/directives/utility_directives.rb +16 -17
  23. data/lib/aia/directives/web_and_file_directives.rb +21 -14
  24. data/lib/aia/fact_asserter.rb +3 -3
  25. data/lib/aia/history_transfer.rb +64 -24
  26. data/lib/aia/logger.rb +14 -46
  27. data/lib/aia/mcp_config_normalizer.rb +27 -14
  28. data/lib/aia/mcp_connection_manager.rb +181 -184
  29. data/lib/aia/mcp_discovery.rb +43 -15
  30. data/lib/aia/mcp_grouper.rb +2 -1
  31. data/lib/aia/mcp_server_config.rb +20 -2
  32. data/lib/aia/mcp_utility.rb +24 -19
  33. data/lib/aia/mention_router.rb +15 -2
  34. data/lib/aia/modality_query.rb +36 -0
  35. data/lib/aia/model_alias_registry.rb +11 -11
  36. data/lib/aia/model_registry.rb +75 -0
  37. data/lib/aia/network_builder.rb +8 -7
  38. data/lib/aia/patches/mcp_stdio_stderr.rb +102 -0
  39. data/lib/aia/patches/ruby_llm_streaming_error.rb +21 -4
  40. data/lib/aia/patches/ruby_llm_tool_param_compat.rb +18 -0
  41. data/lib/aia/pipeline_orchestrator.rb +71 -38
  42. data/lib/aia/prompt_decomposer.rb +1 -1
  43. data/lib/aia/prompt_handler.rb +56 -29
  44. data/lib/aia/provider_registry.rb +105 -0
  45. data/lib/aia/robot_builder.rb +1 -1
  46. data/lib/aia/robot_factory.rb +67 -63
  47. data/lib/aia/robot_sync.rb +79 -0
  48. data/lib/aia/role_catalog.rb +89 -0
  49. data/lib/aia/session.rb +25 -11
  50. data/lib/aia/skill_utils.rb +60 -19
  51. data/lib/aia/spawn_handler.rb +16 -4
  52. data/lib/aia/spawn_spec_parser.rb +6 -7
  53. data/lib/aia/special_mode_handler.rb +28 -25
  54. data/lib/aia/speech.rb +70 -34
  55. data/lib/aia/startup_coordinator.rb +17 -92
  56. data/lib/aia/streaming_runner.rb +10 -2
  57. data/lib/aia/system_prompt_assembler.rb +12 -11
  58. data/lib/aia/task_board.rb +60 -0
  59. data/lib/aia/tool_approver.rb +205 -0
  60. data/lib/aia/tool_filter.rb +1 -10
  61. data/lib/aia/tool_filter_strategy.rb +12 -1
  62. data/lib/aia/tool_introspection.rb +9 -1
  63. data/lib/aia/tool_loader.rb +67 -33
  64. data/lib/aia/tool_utility.rb +6 -5
  65. data/lib/aia/tools/delegate_to_foreman_tool.rb +6 -4
  66. data/lib/aia/tools/recruit_robot_tool.rb +12 -12
  67. data/lib/aia/tools/reskill_robot_tool.rb +7 -7
  68. data/lib/aia/tools/task_board_tool.rb +16 -16
  69. data/lib/aia/trakflow_bridge.rb +14 -8
  70. data/lib/aia/turn_state.rb +31 -8
  71. data/lib/aia/ui_presenter.rb +16 -0
  72. data/lib/aia/utility.rb +6 -24
  73. data/lib/aia/variable_input_collector.rb +0 -3
  74. data/lib/aia/verification_network.rb +9 -10
  75. data/lib/aia/version.rb +1 -9
  76. data/lib/aia.rb +34 -8
  77. metadata +20 -161
  78. data/.better-commits.json +0 -150
  79. data/.config/tocer/configuration.yml +0 -6
  80. data/.envrc +0 -19
  81. data/.loki +0 -11
  82. data/.reek.yml +0 -160
  83. data/.rubocop.yml +0 -116
  84. data/.rubocop_strict.yml +0 -15
  85. data/.version +0 -1
  86. data/COMMITS.md +0 -196
  87. data/IMPLEMENTATION_PLAN.md +0 -506
  88. data/Rakefile +0 -47
  89. data/_typos.toml +0 -10
  90. data/aia.gemspec +0 -92
  91. data/architecture_review.md +0 -314
  92. data/config/aia.yml +0 -13
  93. data/docs/AGENTS.md +0 -40
  94. data/docs/advanced-prompting.md +0 -814
  95. data/docs/assets/images/aia.png +0 -0
  96. data/docs/cli-reference.md +0 -1241
  97. data/docs/configuration.md +0 -747
  98. data/docs/contributing.md +0 -386
  99. data/docs/directives-reference.md +0 -1145
  100. data/docs/examples/index.md +0 -277
  101. data/docs/examples/mcp/index.md +0 -475
  102. data/docs/examples/prompts/analysis/index.md +0 -78
  103. data/docs/examples/prompts/automation/index.md +0 -109
  104. data/docs/examples/prompts/development/index.md +0 -125
  105. data/docs/examples/prompts/index.md +0 -333
  106. data/docs/examples/prompts/learning/index.md +0 -127
  107. data/docs/examples/prompts/writing/index.md +0 -62
  108. data/docs/examples/tools/index.md +0 -282
  109. data/docs/faq.md +0 -578
  110. data/docs/guides/available-models.md +0 -366
  111. data/docs/guides/basic-usage.md +0 -478
  112. data/docs/guides/chat.md +0 -680
  113. data/docs/guides/crew.md +0 -239
  114. data/docs/guides/executable-prompts.md +0 -331
  115. data/docs/guides/first-prompt.md +0 -454
  116. data/docs/guides/getting-started.md +0 -455
  117. data/docs/guides/image-generation.md +0 -507
  118. data/docs/guides/index.md +0 -48
  119. data/docs/guides/local-models.md +0 -306
  120. data/docs/guides/migrate-prompts.md +0 -335
  121. data/docs/guides/models.md +0 -1017
  122. data/docs/guides/shared-tools.md +0 -254
  123. data/docs/guides/tools.md +0 -831
  124. data/docs/index.md +0 -259
  125. data/docs/installation.md +0 -274
  126. data/docs/mcp-integration.md +0 -603
  127. data/docs/prompt_management.md +0 -665
  128. data/docs/security.md +0 -674
  129. data/docs/special_projects_guide.md +0 -386
  130. data/docs/tools-and-mcp-examples.md +0 -1211
  131. data/docs/workflows-and-pipelines.md +0 -636
  132. data/examples/.gitignore +0 -2
  133. data/examples/00_setup_aia.sh +0 -111
  134. data/examples/01_basic_usage.sh +0 -23
  135. data/examples/02_frontmatter.sh +0 -33
  136. data/examples/03_shell_integration.sh +0 -55
  137. data/examples/04_erb_templating.sh +0 -56
  138. data/examples/05_shell_then_erb.sh +0 -38
  139. data/examples/06_prompt_chaining.sh +0 -59
  140. data/examples/07_pipeline.sh +0 -46
  141. data/examples/08_context_files.sh +0 -43
  142. data/examples/09_roles.sh +0 -67
  143. data/examples/10_stdin_piping.sh +0 -49
  144. data/examples/11_multi_model.sh +0 -65
  145. data/examples/12_token_usage.sh +0 -52
  146. data/examples/13_cost_tracking.sh +0 -68
  147. data/examples/14_output_file.sh +0 -91
  148. data/examples/15_parameters.sh +0 -68
  149. data/examples/16_directives.sh +0 -113
  150. data/examples/17_require_and_conditionals.sh +0 -68
  151. data/examples/18_tools.sh +0 -61
  152. data/examples/19_local_tools.sh +0 -34
  153. data/examples/20_mcp_servers.sh +0 -102
  154. data/examples/21_executable_prompts.sh +0 -78
  155. data/examples/22_chat_mode.sh +0 -217
  156. data/examples/23_verify.sh +0 -139
  157. data/examples/24_decompose.sh +0 -139
  158. data/examples/25_spawn.sh +0 -139
  159. data/examples/26_debate.sh +0 -97
  160. data/examples/27_mention_routing.sh +0 -157
  161. data/examples/28_model_switching.sh +0 -106
  162. data/examples/29_agent_harness.sh +0 -177
  163. data/examples/README.md +0 -321
  164. data/examples/advanced_multi_robot_capabilities_without_examples.md +0 -106
  165. data/examples/aia_config.yml +0 -22
  166. data/examples/aia_config_orchestrator.yml +0 -45
  167. data/examples/aia_config_with_mcp.yml +0 -21
  168. data/examples/common.sh +0 -39
  169. data/examples/context/project_goals.md +0 -6
  170. data/examples/context/tech_stack.md +0 -7
  171. data/examples/directives/timestamp_directive.rb +0 -22
  172. data/examples/mcp/filesystem.json +0 -9
  173. data/examples/prompts_dir/analyze.md +0 -2
  174. data/examples/prompts_dir/brainstorm.md +0 -2
  175. data/examples/prompts_dir/conditional.md +0 -17
  176. data/examples/prompts_dir/creative.md +0 -4
  177. data/examples/prompts_dir/erbinfo.md +0 -5
  178. data/examples/prompts_dir/erbinfo_raw.md +0 -8
  179. data/examples/prompts_dir/evaluate.md +0 -2
  180. data/examples/prompts_dir/explain_joke.md +0 -1
  181. data/examples/prompts_dir/explain_recursion.md +0 -1
  182. data/examples/prompts_dir/fun_fact +0 -3
  183. data/examples/prompts_dir/greeting.md +0 -8
  184. data/examples/prompts_dir/greeting_required.md +0 -7
  185. data/examples/prompts_dir/hello.md +0 -1
  186. data/examples/prompts_dir/includes/ruby_facts.md +0 -4
  187. data/examples/prompts_dir/limerick.md +0 -1
  188. data/examples/prompts_dir/list_with_mcp.md +0 -3
  189. data/examples/prompts_dir/pick_best.md +0 -2
  190. data/examples/prompts_dir/project_summary +0 -12
  191. data/examples/prompts_dir/quiz_with_include.md +0 -6
  192. data/examples/prompts_dir/require_demo.md +0 -5
  193. data/examples/prompts_dir/roles/formal.md +0 -3
  194. data/examples/prompts_dir/roles/orchestrator.md +0 -21
  195. data/examples/prompts_dir/roles/pirate.md +0 -3
  196. data/examples/prompts_dir/shell_then_erb.md +0 -6
  197. data/examples/prompts_dir/sort_compare.md +0 -2
  198. data/examples/prompts_dir/summarize_context.md +0 -2
  199. data/examples/prompts_dir/sysinfo.md +0 -5
  200. data/examples/prompts_dir/sysinfo_raw.md +0 -8
  201. data/examples/prompts_dir/tagline.md +0 -1
  202. data/examples/prompts_dir/tell_joke.md +0 -1
  203. data/examples/prompts_dir/tell_joke_with_next.md +0 -4
  204. data/examples/prompts_dir/use_local_tool.md +0 -8
  205. data/examples/prompts_dir/use_tools.md +0 -8
  206. data/examples/prompts_dir/weather.md +0 -2
  207. data/examples/prompts_dir/whats_new.md +0 -2
  208. data/examples/prompts_dir/with_timestamp.md +0 -5
  209. data/examples/requirements/sinatra_taskflow_app.md +0 -139
  210. data/examples/rules/01_classify_ruby.rb +0 -16
  211. data/examples/rules/02_prefer_claude_for_code.rb +0 -19
  212. data/examples/rules/03_gate_prompt_length.rb +0 -19
  213. data/examples/rules/04_tool_selection.rb +0 -41
  214. data/examples/rules/README.md +0 -30
  215. data/examples/run_all.sh +0 -294
  216. data/examples/tools/word_count_tool.rb +0 -30
  217. data/lib/AGENTS.md +0 -57
  218. data/lib/aia/model_switch_handler.rb +0 -100
  219. data/mcp_servers/README.md +0 -110
  220. data/mcp_servers/apple-mcp.json +0 -8
  221. data/mcp_servers/filesystem.json +0 -9
  222. data/mcp_servers/mcp_server_chart.json +0 -11
  223. data/mcp_servers/playwright_one.json +0 -8
  224. data/mcp_servers/playwright_server_definition.json +0 -9
  225. data/mcp_servers/playwright_two.json +0 -8
  226. data/mcp_servers/tavily_mcp_server.json +0 -8
  227. 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
 
@@ -26,7 +25,6 @@ module AIA
26
25
  AIA.config&.failed_mcp_servers || []
27
26
  end
28
27
 
29
- # :reek:TooManyStatements -- server-name resolution applying no_mcp, use-list, and skip-list filters in precedence order
30
28
  def effective_mcp_server_names
31
29
  cfg = AIA.config
32
30
  return [] if cfg&.flags&.no_mcp
@@ -34,27 +32,34 @@ module AIA
34
32
  servers = cfg&.mcp_servers || []
35
33
  return [] if servers.empty?
36
34
 
37
- names = servers.map { |s| server_name(s) }.compact
38
- use_list = Array(cfg.mcp_use)
39
- skip_list = Array(cfg.mcp_skip)
40
-
41
- if use_list.any?
42
- names.select { |n| use_list.include?(n) }
43
- elsif skip_list.any?
44
- names.reject { |n| skip_list.include?(n) }
45
- else
46
- names
47
- end
35
+ MCPDiscovery.select(servers, use: cfg.mcp_use, skip: cfg.mcp_skip).map { server_name(it) }.compact
48
36
  end
49
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.
50
42
  def server_name(s)
51
- if s.is_a?(Hash)
52
- s[:name] || s['name']
53
- elsif s.respond_to?(:name)
54
- s.name
55
- else
56
- 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
57
48
  end
58
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
59
64
  end
60
65
  end
@@ -15,6 +15,10 @@ module AIA
15
15
  # Reserved @mention that broadcasts the message to every crew member.
16
16
  BROADCAST_TOKEN = 'crew'
17
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
+
18
22
  def initialize(ui_presenter:, tracker:, streaming_runner:)
19
23
  @ui_presenter = ui_presenter
20
24
  @tracker = tracker
@@ -32,13 +36,17 @@ module AIA
32
36
  prompt = context.prompt
33
37
  return false unless robot.network?
34
38
 
35
- mention_tokens = prompt.scan(/@(\w+)/i).flatten
39
+ mention_tokens = prompt.scan(MENTION).flatten
36
40
  return false if mention_tokens.empty?
37
41
 
38
42
  all_robots = robot.crew
39
43
  matched = resolve_mentions(mention_tokens, all_robots)
40
44
 
45
+ # No crew member named: ordinary text for the model, unless the message
46
+ # opens with an @address -- most likely a mistyped name.
41
47
  if matched.empty?
48
+ return false unless addressed?(prompt)
49
+
42
50
  report_unknown_mentions(mention_tokens, all_robots)
43
51
  return true
44
52
  end
@@ -60,11 +68,16 @@ module AIA
60
68
  prompt.sub(/\A(?:\s*@\w+)+\s*/i, '').strip
61
69
  end
62
70
 
71
+ # True when the message opens with an @address.
72
+ def addressed?(prompt)
73
+ prompt.match?(/\A\s*@\w/)
74
+ end
75
+
63
76
  # True when every @mention is part of the leading address — i.e. nothing but
64
77
  # @mentions before the message — so it's a broadcast to its addressees and
65
78
  # runs concurrently. A @mention woven into the body makes it sequential.
66
79
  def leading_address_only?(prompt)
67
- !strip_addressing_prefix(prompt).match?(/@\w+/)
80
+ !strip_addressing_prefix(prompt).match?(MENTION)
68
81
  end
69
82
 
70
83
  # Resolve @mention tokens to robots. The reserved @crew token broadcasts to
@@ -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
@@ -20,7 +20,7 @@ module AIA
20
20
  prompts = config.pipeline
21
21
  run_config = RobotFactory.build_run_config(config)
22
22
  tools = ToolLoader.filtered_tools(config)
23
- mcp = RobotFactory.mcp_server_configs(config)
23
+ mcp = RobotFactory.mcp_servers(config)
24
24
  model_spec = config.models.first
25
25
 
26
26
  RobotLab.create_network(name: "aia-pipeline") do
@@ -32,7 +32,7 @@ module AIA
32
32
  name: "#{namer.name_for(model_spec.name)}-s#{i}",
33
33
  system_prompt: nil,
34
34
  local_tools: tools,
35
- mcp_servers: mcp,
35
+ mcp: mcp,
36
36
  config: run_config
37
37
  )
38
38
  task task_name, robot, depends_on: prev ? [prev] : :none
@@ -49,7 +49,7 @@ module AIA
49
49
  def build_parallel_network(config, namer)
50
50
  run_config = RobotFactory.build_run_config(config)
51
51
  tools = ToolLoader.filtered_tools(config)
52
- mcp = RobotFactory.mcp_server_configs(config)
52
+ mcp = RobotFactory.mcp_servers(config)
53
53
  aia_config = config
54
54
  roster = config.models.map { |spec| { name: namer.name_for(spec.name), spec: spec } }
55
55
  build_robot = ->(entry) { build_roster_robot(entry, roster, tools, mcp, run_config, aia_config) }
@@ -71,7 +71,7 @@ module AIA
71
71
  def build_consensus_network(config, namer)
72
72
  run_config = RobotFactory.build_run_config(config)
73
73
  tools = ToolLoader.filtered_tools(config)
74
- mcp = RobotFactory.mcp_server_configs(config)
74
+ mcp = RobotFactory.mcp_servers(config)
75
75
  models = config.models
76
76
  primary = models.first
77
77
  aia_config = config
@@ -108,7 +108,7 @@ module AIA
108
108
  name: entry[:name],
109
109
  system_prompt: system_prompt,
110
110
  local_tools: tools,
111
- mcp_servers: mcp,
111
+ mcp: mcp,
112
112
  config: run_config
113
113
  )
114
114
  end
@@ -126,15 +126,16 @@ module AIA
126
126
  tools = ToolLoader.filtered_tools(config)
127
127
  model_spec = config.models.first
128
128
  system_prompt = SystemPromptAssembler.resolve_system_prompt(config, model_spec)
129
+ group_servers = server_groups.map { RobotFactory.mcp_servers(config, it) }
129
130
 
130
131
  network = RobotLab.create_network(name: "aia-concurrent-mcp") do
131
- server_groups.each_with_index do |group, i|
132
+ group_servers.each_with_index do |servers, i|
132
133
  robot = RobotFactory.build_robot(
133
134
  model_spec,
134
135
  name: "#{namer.name_for(model_spec.name)}-w#{i}",
135
136
  system_prompt: system_prompt,
136
137
  local_tools: tools,
137
- mcp_servers: group.map { |s| RobotFactory.normalize_mcp_config(s) },
138
+ mcp: servers,
138
139
  config: run_config
139
140
  )
140
141
  task :"mcp_worker_#{i}", robot, depends_on: :none
@@ -0,0 +1,102 @@
1
+ # lib/aia/patches/mcp_stdio_stderr.rb
2
+ #
3
+ # Redirect the stderr of stdio MCP server processes away from the terminal.
4
+ #
5
+ # ruby_llm 2.1's RubyLLM::MCP::Stdio#start launches each server with
6
+ # Open3.popen2, so the child inherits aia's stderr ("Its stderr is the
7
+ # parent's"). Every server banner, npm notice, stack trace and Python
8
+ # validation dump then lands on the terminal, interleaved with the
9
+ # TTY::Spinner::Multi "Connecting MCP servers" display, which corrupts it.
10
+ # (ruby_llm-mcp 1.x used popen3 and drained stderr, so aia 1.x was quiet.)
11
+ #
12
+ # The destination comes from AIA.config.logger.mcp.server_stderr:
13
+ # a file path - appended to (default: ~/.config/aia/logs/mcp_servers.log)
14
+ # STDERR - the old passthrough behavior
15
+ # null - discard (also: none, /dev/null)
16
+ #
17
+ # Stdio#start has no hook for spawn options, so this re-implements its
18
+ # three-line body. It is guarded against drift: if a future ruby_llm drops
19
+ # Stdio#start, the patch is skipped with a warning instead of breaking MCP.
20
+
21
+ require 'fileutils'
22
+ require 'open3'
23
+
24
+ module AIA
25
+ module MCPStdioStderr
26
+ DEFAULT_PATH = '~/.config/aia/logs/mcp_servers.log'.freeze
27
+ DISCARD = %w[NULL NONE /DEV/NULL].freeze
28
+
29
+ class << self
30
+ # The spawn option value for a server's stderr.
31
+ #
32
+ # @param setting [String, nil] logger.mcp.server_stderr
33
+ # @return [Array(String, String), nil] [path, mode] for Process.spawn's
34
+ # err: option, or nil to inherit the parent's stderr
35
+ def spawn_target(setting = configured_setting)
36
+ value = setting.to_s.strip
37
+ value = DEFAULT_PATH if value.empty?
38
+
39
+ case value.upcase
40
+ when 'STDERR' then nil
41
+ when *DISCARD then [File::NULL, 'w']
42
+ else log_file_target(value)
43
+ end
44
+ end
45
+
46
+ # Spawn options for Open3 with the stderr redirect added.
47
+ #
48
+ # @param options [Hash] options ruby_llm would pass (e.g. chdir:)
49
+ # @param target [Array, nil] from .spawn_target
50
+ # @return [Hash]
51
+ def spawn_options(options, target = spawn_target)
52
+ target ? options.merge(err: target) : options
53
+ end
54
+
55
+ # Install the patch onto RubyLLM::MCP::Stdio (idempotent).
56
+ #
57
+ # @return [Class, nil] the patched class, or nil when it can't be patched
58
+ def install!(stdio = stdio_class)
59
+ return unless stdio&.private_method_defined?(:start)
60
+
61
+ stdio.prepend(StdioPatch) unless stdio.ancestors.include?(StdioPatch)
62
+ stdio
63
+ end
64
+
65
+ private
66
+
67
+ def configured_setting
68
+ AIA.config&.logger&.mcp&.server_stderr
69
+ rescue StandardError
70
+ nil # config not loaded yet (or malformed): fall back to the default file
71
+ end
72
+
73
+ def log_file_target(value)
74
+ path = File.expand_path(value)
75
+ FileUtils.mkdir_p(File.dirname(path))
76
+ [path, 'a']
77
+ rescue SystemCallError
78
+ [File::NULL, 'w'] # unwritable location: still keep the terminal clean
79
+ end
80
+
81
+ def stdio_class
82
+ RubyLLM::MCP::Stdio if defined?(RubyLLM::MCP::Stdio)
83
+ end
84
+ end
85
+
86
+ # Prepended onto RubyLLM::MCP::Stdio.
87
+ module StdioPatch
88
+ private
89
+
90
+ def start
91
+ options = @directory ? { chdir: @directory } : {}
92
+ options = MCPStdioStderr.spawn_options(options)
93
+ @stdin, @stdout, @process = Open3.popen2(@env, *@command, **options)
94
+ @buffer = +''
95
+ end
96
+ end
97
+ end
98
+ end
99
+
100
+ unless AIA::MCPStdioStderr.install!
101
+ warn 'AIA: RubyLLM::MCP::Stdio#start not found; MCP server stderr will reach the terminal'
102
+ 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)
@@ -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,54 +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]
28
- # :reek:TooManyStatements -- shift-based loop so front-matter pipeline edits take effect; tracking interleaved
29
34
  # :reek:DuplicateMethodCall -- config.pipeline is deliberately re-read each iteration because prompt front matter mutates it mid-loop
30
35
  def process(config)
31
- bridge = TrakFlowBridge.new
32
- tracking = bridge.available? && config.flags.track_pipeline
33
-
34
- 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)
35
40
 
36
- # Use shift-based loop so that prompt front matter which sets
37
- # config.pipeline (via `next:` or `pipeline:`) is picked up on
38
- # the next iteration rather than being silently ignored.
39
41
  until config.pipeline.empty?
40
42
  prompt_id = config.pipeline.shift
41
43
  next if prompt_id.nil? || prompt_id.empty?
42
44
 
43
- begin
44
- bridge.update_step_status(prompt_id, :started) if tracking
45
-
46
- prompt_text = build_prompt_text(prompt_id, config)
47
- next if prompt_text.nil? || prompt_text.strip.empty?
48
-
49
- result, content = compute_result(prompt_text, config)
50
-
51
- bridge.update_step_status(prompt_id, :completed) if tracking
52
-
53
- @tracker.record_turn(
54
- model: config.models.first.name,
55
- input: prompt_text,
56
- result: result
57
- )
58
-
59
- @ui.display_ai_response(content)
60
- output_to_file(content, config)
61
- display_metrics(result, config)
62
- @ui.display_separator
63
- rescue StandardError => e
64
- bridge.update_step_status(prompt_id, :failed, reason: e.message) if tracking
65
- raise
66
- end
45
+ run_step(prompt_id, config, bridge)
67
46
  end
68
47
  end
69
48
 
70
49
  # Allow robot to be updated (after model switch)
71
50
  attr_writer :robot
72
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
+
73
57
  private
74
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
+
75
94
  # Returns [result, displayable_content] for one prompt — image when in paint
76
95
  # mode, otherwise the LLM text response.
77
96
  def compute_result(prompt_text, config)
@@ -96,7 +115,7 @@ module AIA
96
115
  image = @ui.with_spinner("Generating image") do
97
116
  RubyLLM.paint(
98
117
  prompt_text,
99
- model: img_cfg.model || 'dall-e-3',
118
+ model: img_cfg.model || 'gpt-image-1',
100
119
  size: img_cfg.size || '1024x1024',
101
120
  params: params
102
121
  )
@@ -137,9 +156,7 @@ module AIA
137
156
  concurrency = config.respond_to?(:concurrency) ? config.concurrency : nil
138
157
  return nil unless concurrency&.auto || turn_state.force_concurrent_mcp
139
158
 
140
- if turn_state.force_concurrent_mcp
141
- turn_state.force_concurrent_mcp = false
142
- end
159
+ turn_state.clear_mode(:concurrent_mcp)
143
160
 
144
161
  discovery = MCPDiscovery.new
145
162
  relevant_servers = discovery.discover(config)
@@ -169,7 +186,7 @@ module AIA
169
186
  values.each { |k, v| parameters[k] = v }
170
187
  end
171
188
 
172
- prompt_text = parsed.to_s
189
+ prompt_text = render_prompt(parsed)
173
190
 
174
191
  role = config.prompts.role
175
192
  if role && !role.empty?
@@ -198,6 +215,22 @@ module AIA
198
215
  add_context_files(prompt_text, config)
199
216
  end
200
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
+
201
234
  # Append context file contents to prompt
202
235
  def add_context_files(prompt_text, config)
203
236
  context_files = config.context_files
@@ -118,7 +118,7 @@ module AIA
118
118
  private
119
119
 
120
120
  def structured_output?
121
- RubyLLM.models.find(AIA.config.models.first.internal_id).structured_output?
121
+ RubyLLM.models.find(AIA.config.models.first.internal_id).supports?(:structured_output)
122
122
  rescue StandardError
123
123
  false
124
124
  end