aia 2.0.0.0.pre.beta2 → 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 (225) hide show
  1. checksums.yaml +4 -4
  2. data/.version +1 -1
  3. data/CHANGELOG.md +146 -228
  4. data/README.md +41 -18
  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 +16 -14
  10. data/lib/aia/config/cli_parser.rb +123 -91
  11. data/lib/aia/config/defaults.yml +12 -39
  12. data/lib/aia/config/mcp_parser.rb +30 -36
  13. data/lib/aia/config/model_spec.rb +8 -14
  14. data/lib/aia/config/validator.rb +102 -103
  15. data/lib/aia/config/value_caster.rb +76 -0
  16. data/lib/aia/config.rb +70 -53
  17. data/lib/aia/crew.rb +29 -19
  18. data/lib/aia/debate_handler.rb +27 -10
  19. data/lib/aia/directives/configuration_directives.rb +55 -14
  20. data/lib/aia/directives/context_directives.rb +24 -12
  21. data/lib/aia/directives/execution_directives.rb +18 -23
  22. data/lib/aia/directives/model_directives.rb +41 -104
  23. data/lib/aia/directives/utility_directives.rb +16 -17
  24. data/lib/aia/directives/web_and_file_directives.rb +21 -14
  25. data/lib/aia/fact_asserter.rb +3 -3
  26. data/lib/aia/history_transfer.rb +64 -24
  27. data/lib/aia/logger.rb +10 -45
  28. data/lib/aia/mcp_config_normalizer.rb +27 -14
  29. data/lib/aia/mcp_connection_manager.rb +181 -184
  30. data/lib/aia/mcp_discovery.rb +43 -15
  31. data/lib/aia/mcp_grouper.rb +2 -1
  32. data/lib/aia/mcp_server_config.rb +20 -2
  33. data/lib/aia/mcp_utility.rb +24 -19
  34. data/lib/aia/mention_router.rb +15 -2
  35. data/lib/aia/modality_query.rb +36 -0
  36. data/lib/aia/model_alias_registry.rb +11 -11
  37. data/lib/aia/model_registry.rb +75 -0
  38. data/lib/aia/network_builder.rb +8 -7
  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.rb +33 -8
  76. metadata +19 -160
  77. data/.better-commits.json +0 -150
  78. data/.config/tocer/configuration.yml +0 -6
  79. data/.envrc +0 -19
  80. data/.loki +0 -11
  81. data/.reek.yml +0 -160
  82. data/.rubocop.yml +0 -116
  83. data/.rubocop_strict.yml +0 -15
  84. data/COMMITS.md +0 -196
  85. data/IMPLEMENTATION_PLAN.md +0 -506
  86. data/Rakefile +0 -47
  87. data/_typos.toml +0 -10
  88. data/aia.gemspec +0 -92
  89. data/architecture_review.md +0 -314
  90. data/config/aia.yml +0 -13
  91. data/docs/AGENTS.md +0 -40
  92. data/docs/advanced-prompting.md +0 -814
  93. data/docs/assets/images/aia.png +0 -0
  94. data/docs/cli-reference.md +0 -1241
  95. data/docs/configuration.md +0 -747
  96. data/docs/contributing.md +0 -386
  97. data/docs/directives-reference.md +0 -1145
  98. data/docs/examples/index.md +0 -277
  99. data/docs/examples/mcp/index.md +0 -475
  100. data/docs/examples/prompts/analysis/index.md +0 -78
  101. data/docs/examples/prompts/automation/index.md +0 -109
  102. data/docs/examples/prompts/development/index.md +0 -125
  103. data/docs/examples/prompts/index.md +0 -333
  104. data/docs/examples/prompts/learning/index.md +0 -127
  105. data/docs/examples/prompts/writing/index.md +0 -62
  106. data/docs/examples/tools/index.md +0 -282
  107. data/docs/faq.md +0 -578
  108. data/docs/guides/available-models.md +0 -366
  109. data/docs/guides/basic-usage.md +0 -478
  110. data/docs/guides/chat.md +0 -680
  111. data/docs/guides/crew.md +0 -239
  112. data/docs/guides/executable-prompts.md +0 -331
  113. data/docs/guides/first-prompt.md +0 -454
  114. data/docs/guides/getting-started.md +0 -455
  115. data/docs/guides/image-generation.md +0 -507
  116. data/docs/guides/index.md +0 -48
  117. data/docs/guides/local-models.md +0 -306
  118. data/docs/guides/migrate-prompts.md +0 -335
  119. data/docs/guides/models.md +0 -1017
  120. data/docs/guides/shared-tools.md +0 -254
  121. data/docs/guides/tools.md +0 -831
  122. data/docs/index.md +0 -259
  123. data/docs/installation.md +0 -274
  124. data/docs/mcp-integration.md +0 -603
  125. data/docs/prompt_management.md +0 -665
  126. data/docs/security.md +0 -674
  127. data/docs/special_projects_guide.md +0 -386
  128. data/docs/tools-and-mcp-examples.md +0 -1211
  129. data/docs/workflows-and-pipelines.md +0 -636
  130. data/examples/.gitignore +0 -2
  131. data/examples/00_setup_aia.sh +0 -111
  132. data/examples/01_basic_usage.sh +0 -23
  133. data/examples/02_frontmatter.sh +0 -33
  134. data/examples/03_shell_integration.sh +0 -55
  135. data/examples/04_erb_templating.sh +0 -56
  136. data/examples/05_shell_then_erb.sh +0 -38
  137. data/examples/06_prompt_chaining.sh +0 -59
  138. data/examples/07_pipeline.sh +0 -46
  139. data/examples/08_context_files.sh +0 -43
  140. data/examples/09_roles.sh +0 -67
  141. data/examples/10_stdin_piping.sh +0 -49
  142. data/examples/11_multi_model.sh +0 -65
  143. data/examples/12_token_usage.sh +0 -52
  144. data/examples/13_cost_tracking.sh +0 -68
  145. data/examples/14_output_file.sh +0 -91
  146. data/examples/15_parameters.sh +0 -68
  147. data/examples/16_directives.sh +0 -113
  148. data/examples/17_require_and_conditionals.sh +0 -68
  149. data/examples/18_tools.sh +0 -61
  150. data/examples/19_local_tools.sh +0 -34
  151. data/examples/20_mcp_servers.sh +0 -102
  152. data/examples/21_executable_prompts.sh +0 -78
  153. data/examples/22_chat_mode.sh +0 -217
  154. data/examples/23_verify.sh +0 -139
  155. data/examples/24_decompose.sh +0 -139
  156. data/examples/25_spawn.sh +0 -139
  157. data/examples/26_debate.sh +0 -97
  158. data/examples/27_mention_routing.sh +0 -157
  159. data/examples/28_model_switching.sh +0 -106
  160. data/examples/29_agent_harness.sh +0 -177
  161. data/examples/README.md +0 -321
  162. data/examples/advanced_multi_robot_capabilities_without_examples.md +0 -106
  163. data/examples/aia_config.yml +0 -22
  164. data/examples/aia_config_orchestrator.yml +0 -45
  165. data/examples/aia_config_with_mcp.yml +0 -21
  166. data/examples/common.sh +0 -39
  167. data/examples/context/project_goals.md +0 -6
  168. data/examples/context/tech_stack.md +0 -7
  169. data/examples/directives/timestamp_directive.rb +0 -22
  170. data/examples/mcp/filesystem.json +0 -9
  171. data/examples/prompts_dir/analyze.md +0 -2
  172. data/examples/prompts_dir/brainstorm.md +0 -2
  173. data/examples/prompts_dir/conditional.md +0 -17
  174. data/examples/prompts_dir/creative.md +0 -4
  175. data/examples/prompts_dir/erbinfo.md +0 -5
  176. data/examples/prompts_dir/erbinfo_raw.md +0 -8
  177. data/examples/prompts_dir/evaluate.md +0 -2
  178. data/examples/prompts_dir/explain_joke.md +0 -1
  179. data/examples/prompts_dir/explain_recursion.md +0 -1
  180. data/examples/prompts_dir/fun_fact +0 -3
  181. data/examples/prompts_dir/greeting.md +0 -8
  182. data/examples/prompts_dir/greeting_required.md +0 -7
  183. data/examples/prompts_dir/hello.md +0 -1
  184. data/examples/prompts_dir/includes/ruby_facts.md +0 -4
  185. data/examples/prompts_dir/limerick.md +0 -1
  186. data/examples/prompts_dir/list_with_mcp.md +0 -3
  187. data/examples/prompts_dir/pick_best.md +0 -2
  188. data/examples/prompts_dir/project_summary +0 -12
  189. data/examples/prompts_dir/quiz_with_include.md +0 -6
  190. data/examples/prompts_dir/require_demo.md +0 -5
  191. data/examples/prompts_dir/roles/formal.md +0 -3
  192. data/examples/prompts_dir/roles/orchestrator.md +0 -21
  193. data/examples/prompts_dir/roles/pirate.md +0 -3
  194. data/examples/prompts_dir/shell_then_erb.md +0 -6
  195. data/examples/prompts_dir/sort_compare.md +0 -2
  196. data/examples/prompts_dir/summarize_context.md +0 -2
  197. data/examples/prompts_dir/sysinfo.md +0 -5
  198. data/examples/prompts_dir/sysinfo_raw.md +0 -8
  199. data/examples/prompts_dir/tagline.md +0 -1
  200. data/examples/prompts_dir/tell_joke.md +0 -1
  201. data/examples/prompts_dir/tell_joke_with_next.md +0 -4
  202. data/examples/prompts_dir/use_local_tool.md +0 -8
  203. data/examples/prompts_dir/use_tools.md +0 -8
  204. data/examples/prompts_dir/weather.md +0 -2
  205. data/examples/prompts_dir/whats_new.md +0 -2
  206. data/examples/prompts_dir/with_timestamp.md +0 -5
  207. data/examples/requirements/sinatra_taskflow_app.md +0 -139
  208. data/examples/rules/01_classify_ruby.rb +0 -16
  209. data/examples/rules/02_prefer_claude_for_code.rb +0 -19
  210. data/examples/rules/03_gate_prompt_length.rb +0 -19
  211. data/examples/rules/04_tool_selection.rb +0 -41
  212. data/examples/rules/README.md +0 -30
  213. data/examples/run_all.sh +0 -294
  214. data/examples/tools/word_count_tool.rb +0 -30
  215. data/lib/AGENTS.md +0 -57
  216. data/lib/aia/model_switch_handler.rb +0 -100
  217. data/mcp_servers/README.md +0 -110
  218. data/mcp_servers/apple-mcp.json +0 -8
  219. data/mcp_servers/filesystem.json +0 -9
  220. data/mcp_servers/mcp_server_chart.json +0 -11
  221. data/mcp_servers/playwright_one.json +0 -8
  222. data/mcp_servers/playwright_server_definition.json +0 -9
  223. data/mcp_servers/playwright_two.json +0 -8
  224. data/mcp_servers/tavily_mcp_server.json +0 -8
  225. data/mkdocs.yml +0 -169
@@ -5,15 +5,33 @@ module AIA
5
5
  # symbol or string keys, and with connection fields either nested under
6
6
  # :transport or at the top level; this object owns all of that fallback
7
7
  # logic so callers never touch the raw hash shape.
8
- McpServerConfig = Data.define(:name, :command, :args, :env, :timeout_raw) do
8
+ McpServerConfig = Data.define(:name, :command, :args, :env, :timeout_raw, :url) do
9
9
  def self.from_hash(server)
10
+ return from_class(server) unless server.is_a?(Hash)
11
+
10
12
  transport = fetch_key(server, :transport) || {}
11
13
  new(
12
14
  name: AIA::Utility.server_name(server),
13
15
  command: fetch_key(transport, :command) || fetch_key(server, :command),
14
16
  args: Array(fetch_key(transport, :args) || fetch_key(server, :args)),
15
17
  env: fetch_key(transport, :env) || fetch_key(server, :env) || {},
16
- timeout_raw: fetch_key(server, :timeout)
18
+ timeout_raw: fetch_key(server, :timeout),
19
+ url: fetch_key(transport, :url) || fetch_key(server, :url)
20
+ )
21
+ end
22
+
23
+ # A RubyLLM::MCP subclass describes itself through its class DSL. A
24
+ # constant name whose class is not loaded yet yields just its name.
25
+ def self.from_class(server)
26
+ klass = server.is_a?(Class) ? server : nil
27
+ argv = klass.respond_to?(:command) ? Array(klass.command) : []
28
+ new(
29
+ name: AIA::Utility.server_name(server),
30
+ command: argv.first,
31
+ args: argv.drop(1),
32
+ env: {},
33
+ timeout_raw: (klass.timeout if klass.respond_to?(:timeout)),
34
+ url: (klass.url if klass.respond_to?(:url))
17
35
  )
18
36
  end
19
37
 
@@ -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
@@ -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