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
@@ -10,6 +10,7 @@
10
10
  # resettable default instance (reset via ToolLoader.reset_instance! or AIA.reset!).
11
11
 
12
12
  module AIA
13
+ # :reek:TooManyMethods -- class-level delegators mirror the instance API; each loading step is its own small, testable method
13
14
  class ToolLoader
14
15
  class << self
15
16
  # Returns the shared default instance, creating it on first call.
@@ -27,6 +28,7 @@ module AIA
27
28
  def cached_tools = instance.cached_tools
28
29
  def clear_cache! = instance.clear_cache!
29
30
  def load_tools(config) = instance.load_tools(config)
31
+ def require_libs(config) = instance.require_libs(config)
30
32
  def filtered_tools(config) = instance.filtered_tools(config)
31
33
  def discover_tools = instance.discover_tools
32
34
  def eager_load_gem_tools = instance.eager_load_gem_tools
@@ -53,18 +55,9 @@ module AIA
53
55
 
54
56
  # Load tools from require_libs and tool paths, then cache the result.
55
57
  # Subsequent calls to RobotFactory.build skip this entirely if cache exists.
56
- # :reek:TooManyStatements -- sequential phases: require_libs with activation retry, tool files, eager loads, discovery cache
58
+ # :reek:TooManyStatements -- sequential phases: require_libs, tool files, eager loads, discovery cache
57
59
  def load_tools(config)
58
- Array(config.require_libs).each do |lib|
59
- require lib
60
- rescue LoadError
61
- # Not yet active — activate it (and its deps) via RubyGems, then retry
62
- if activate_unbundled_gem(lib)
63
- require lib rescue warn("Warning: Failed to require '#{lib}' after activation")
64
- else
65
- $stderr.puts "Warning: Failed to require '#{lib}': gem not found"
66
- end
67
- end
60
+ require_libs(config)
68
61
 
69
62
  # Load tool files from paths
70
63
  Array(config.tools&.paths).each do |path|
@@ -90,12 +83,24 @@ module AIA
90
83
  tools = discover_tools
91
84
  @tool_cache = tools
92
85
  config.loaded_tools = tools
93
- config.tool_names = tools.map { |t| tool_name(t) }.join(', ')
86
+ config.tool_names = tools.map { |t| ToolIntrospection.tool_name(t) }.join(', ')
94
87
  end
95
88
 
96
- # A tool's display name: instances expose #name; bare classes fall back to the class name.
97
- def tool_name(tool)
98
- tool.respond_to?(:name) ? tool.name : tool.class.name
89
+ # Require each --require library, activating an unbundled gem first when
90
+ # needed. Safe to call more than once: Kernel#require skips loaded files.
91
+ # Session calls it before connecting MCP servers, so mcp_servers: entries
92
+ # can name RubyLLM::MCP subclasses those libraries define.
93
+ def require_libs(config)
94
+ Array(config.require_libs).each do |lib|
95
+ require lib
96
+ rescue LoadError
97
+ # Not yet active — activate it (and its deps) via RubyGems, then retry
98
+ if activate_unbundled_gem(lib)
99
+ require lib rescue warn("Warning: Failed to require '#{lib}' after activation")
100
+ else
101
+ $stderr.puts "Warning: Failed to require '#{lib}': gem not found"
102
+ end
103
+ end
99
104
  end
100
105
 
101
106
  # Filter tools based on allowed/rejected lists and KBS decisions.
@@ -109,7 +114,7 @@ module AIA
109
114
  if allowed && !allowed.empty?
110
115
  allowed_list = Array(allowed).map(&:strip).map(&:downcase)
111
116
  tools = tools.select do |t|
112
- name = tool_name(t).downcase
117
+ name = ToolIntrospection.tool_name(t).downcase
113
118
  # name is a String; Array#intersect? would raise TypeError
114
119
  allowed_list.any? { |a| name.include?(a) }
115
120
  end
@@ -118,7 +123,7 @@ module AIA
118
123
  if rejected && !rejected.empty?
119
124
  rejected_list = Array(rejected).map(&:strip).map(&:downcase)
120
125
  tools = tools.reject do |t|
121
- name = tool_name(t).downcase
126
+ name = ToolIntrospection.tool_name(t).downcase
122
127
  # name is a String; Array#intersect? would raise TypeError
123
128
  rejected_list.any? { |r| name.include?(r) }
124
129
  end
@@ -126,7 +131,7 @@ module AIA
126
131
 
127
132
  seen = {}
128
133
  tools.select do |t|
129
- name = tool_name(t)
134
+ name = ToolIntrospection.tool_name(t)
130
135
  if seen[name]
131
136
  false
132
137
  else
@@ -137,22 +142,51 @@ module AIA
137
142
  end
138
143
 
139
144
  # Discover RubyLLM::Tool subclasses from ObjectSpace.
140
- # Skips tools that report themselves as unavailable via #available?.
145
+ # Skips tools that report themselves as unavailable via #available?
146
+ # (reported only under --debug, since that is a deliberate opt-out) and
147
+ # tools whose class body never finished loading (always reported).
141
148
  def discover_tools
142
- ObjectSpace.each_object(Class).select do |klass|
143
- next false unless defined?(RubyLLM::Tool) && klass < RubyLLM::Tool
144
- begin
145
- instance = klass.new
146
- if instance.respond_to?(:available?) && !instance.available?
147
- tool_name = instance.respond_to?(:name) ? instance.name : klass.name
148
- $stderr.puts "Info: Tool '#{tool_name}' is not available, skipping"
149
- next false
150
- end
151
- true
152
- rescue LoadError, StandardError
153
- false
154
- end
155
- end
149
+ return [] unless defined?(RubyLLM::Tool)
150
+
151
+ candidates = ObjectSpace.each_object(Class).select { |klass| klass < RubyLLM::Tool && !mcp_tool_class?(klass) }
152
+ incomplete, complete = candidates.partition { |klass| !implements_execute?(klass) }
153
+ warn_incomplete_tools(incomplete.map { |klass| klass.name || klass.inspect })
154
+ complete.select { |klass| available_tool?(klass) }
155
+ end
156
+
157
+ # True when the tool class can be instantiated and does not report
158
+ # itself unavailable through #available? (reported only under --debug).
159
+ def available_tool?(klass)
160
+ instance = klass.new
161
+ return true unless instance.respond_to?(:available?) && !instance.available?
162
+
163
+ $stderr.puts "Info: Tool '#{ToolIntrospection.tool_name(instance)}' is not available, skipping" if AIA.debug?
164
+ false
165
+ rescue LoadError, StandardError
166
+ false
167
+ end
168
+
169
+ # True for ruby_llm's RubyLLM::MCP::Tool (and subclasses): the wrapper an
170
+ # MCP server's tools arrive in. They come from MCPConnectionManager, never
171
+ # from ObjectSpace, and have no #execute of their own.
172
+ def mcp_tool_class?(klass)
173
+ defined?(RubyLLM::MCP::Tool) ? klass <= RubyLLM::MCP::Tool : false
174
+ end
175
+
176
+ # True when the tool class defines its own #execute. A class whose body
177
+ # raised partway through (e.g. a gem written against an older RubyLLM
178
+ # tool DSL) still inherits RubyLLM::Tool's abstract #execute and would
179
+ # fail with NotImplementedError on the first tool call.
180
+ def implements_execute?(klass)
181
+ klass.instance_method(:execute).owner != RubyLLM::Tool
182
+ end
183
+
184
+ # One summary line for tool classes rejected by #implements_execute?.
185
+ def warn_incomplete_tools(names)
186
+ return if names.empty?
187
+
188
+ $stderr.puts "Warning: #{names.size} tool(s) did not finish loading and were skipped " \
189
+ "(the gem providing them may need updating): #{names.sort.join(', ')}"
156
190
  end
157
191
 
158
192
  # Activate a gem that isn't yet active by asking RubyGems to activate it.
@@ -8,15 +8,16 @@
8
8
  module AIA
9
9
  module ToolUtility
10
10
  def tools?
11
- return true if AIA.config&.tool_names && !AIA.config.tool_names.empty?
11
+ names = AIA.config&.tool_names
12
+ return true if names && !names.empty?
12
13
  total_tool_count.positive?
13
14
  end
14
15
 
15
16
  def total_tool_count
16
- local = Array(AIA.config&.loaded_tools).size
17
- return local if AIA.config&.flags&.no_mcp
18
- mcp = defined?(RubyLLM::MCP) ? RubyLLM::MCP.clients.sum { |_, c| c.tools.count } : 0
19
- local + mcp
17
+ config = AIA.config
18
+ local = Array(config&.loaded_tools).size
19
+ return local if config&.flags&.no_mcp
20
+ local + (config&.mcp_server_tool_counts || {}).values.sum
20
21
  end
21
22
 
22
23
  def user_tools?
@@ -13,12 +13,14 @@ module AIA
13
13
  "Use this when you need to create, assign, track, or manage tasks. " \
14
14
  "Pass a natural language description of what you need done on the task board."
15
15
 
16
- param :request, type: :string, required: true,
17
- desc: "Natural language description of the task board operation " \
18
- "(e.g., 'create a research task about recessions assigned to Tobor with labels research, economics')"
16
+ parameter :request, type: :string, required: true,
17
+ description: "Natural language description of the task board operation " \
18
+ "(e.g., 'create a research task about recessions assigned to Tobor with labels research, economics')"
19
19
 
20
+ # Offered whenever TrakFlow is installed; the task board starts when
21
+ # Foreman first needs it.
20
22
  def available?
21
- AIA.task_coordinator&.available? || false
23
+ AIA::TaskBoard.gem_available?
22
24
  end
23
25
 
24
26
  def execute(request:, **_params)
@@ -14,18 +14,18 @@ module AIA
14
14
  "skills that define its role, and/or a system prompt. The " \
15
15
  "newcomer joins the crew right away and can be addressed with @name."
16
16
 
17
- param :name, type: :string, required: true,
18
- desc: "Unique name for the new robot, e.g. 'researcher'. Reserved: 'crew'."
19
- param :model, type: :string,
20
- desc: "Optional provider/model, e.g. 'ollama/qwen3.6:latest' or 'gpt-4o'. " \
21
- "Omit (or pass '-') to inherit the chief's model and provider."
22
- param :skills, type: :string,
23
- desc: "Optional comma-separated skill ids to assign as the robot's role " \
24
- "(e.g. 'security-review,ruby-style'). Each skill's content becomes " \
25
- "part of its system prompt. Use this to give crew members distinct jobs."
26
- param :system_prompt, type: :string,
27
- desc: "Optional extra system prompt, appended after any skills — its role, " \
28
- "persona, and instructions."
17
+ parameter :name, type: :string, required: true,
18
+ description: "Unique name for the new robot, e.g. 'researcher'. Reserved: 'crew'."
19
+ parameter :model, type: :string,
20
+ description: "Optional provider/model, e.g. 'ollama/qwen3.6:latest' or 'gpt-4o'. " \
21
+ "Omit (or pass '-') to inherit the chief's model and provider."
22
+ parameter :skills, type: :string,
23
+ description: "Optional comma-separated skill ids to assign as the robot's role " \
24
+ "(e.g. 'security-review,ruby-style'). Each skill's content becomes " \
25
+ "part of its system prompt. Use this to give crew members distinct jobs."
26
+ parameter :system_prompt, type: :string,
27
+ description: "Optional extra system prompt, appended after any skills — its role, " \
28
+ "persona, and instructions."
29
29
 
30
30
  def execute(name:, model: nil, skills: nil, system_prompt: nil)
31
31
  robot = AIA::Crew.recruit(build_spec(name, model, skills, system_prompt))
@@ -14,13 +14,13 @@ module AIA
14
14
  "role from the given skills and/or system prompt. Use this to " \
15
15
  "repurpose a member or recover one that went off task."
16
16
 
17
- param :name, type: :string, required: true,
18
- desc: "Name of the existing crew member to reset (cannot be the chief)."
19
- param :skills, type: :string,
20
- desc: "Optional comma-separated skill ids to assign as the new role " \
21
- "(e.g. 'testing,performance')."
22
- param :system_prompt, type: :string,
23
- desc: "Optional extra system prompt, appended after any skills."
17
+ parameter :name, type: :string, required: true,
18
+ description: "Name of the existing crew member to reset (cannot be the chief)."
19
+ parameter :skills, type: :string,
20
+ description: "Optional comma-separated skill ids to assign as the new role " \
21
+ "(e.g. 'testing,performance')."
22
+ parameter :system_prompt, type: :string,
23
+ description: "Optional extra system prompt, appended after any skills."
24
24
 
25
25
  def execute(name:, skills: nil, system_prompt: nil)
26
26
  prompt = system_prompt.to_s.strip
@@ -14,22 +14,22 @@ module AIA
14
14
  description "Manage a shared task board. Create tasks for other robots, " \
15
15
  "check what's ready, claim tasks, and report completion."
16
16
 
17
- param :action, type: :string, required: true,
18
- desc: "One of: create, plan, ready, claim, complete, block, status"
19
- param :title, type: :string,
20
- desc: "Task title (for create/plan actions)"
21
- param :assignee, type: :string,
22
- desc: "Robot name to assign to (for create/claim/ready)"
23
- param :labels, type: :string,
24
- desc: "Comma-separated labels (for create)"
25
- param :blocked_by, type: :string,
26
- desc: "Comma-separated blocker task IDs (for create)"
27
- param :steps, type: :string,
28
- desc: "JSON array of step objects [{title:, assignee:}] (for plan)"
29
- param :task_id, type: :string,
30
- desc: "Task ID (for claim/complete/block)"
31
- param :result, type: :string,
32
- desc: "Result summary (for complete) or reason (for block)"
17
+ parameter :action, type: :string, required: true,
18
+ description: "One of: create, plan, ready, claim, complete, block, status"
19
+ parameter :title, type: :string,
20
+ description: "Task title (for create/plan actions)"
21
+ parameter :assignee, type: :string,
22
+ description: "Robot name to assign to (for create/claim/ready)"
23
+ parameter :labels, type: :string,
24
+ description: "Comma-separated labels (for create)"
25
+ parameter :blocked_by, type: :string,
26
+ description: "Comma-separated blocker task IDs (for create)"
27
+ parameter :steps, type: :string,
28
+ description: "JSON array of step objects [{title:, assignee:}] (for plan)"
29
+ parameter :task_id, type: :string,
30
+ description: "Task ID (for claim/complete/block)"
31
+ parameter :result, type: :string,
32
+ description: "Result summary (for complete) or reason (for block)"
33
33
 
34
34
  # Never auto-discovered onto primary robots. Only Foreman
35
35
  # (built by DelegateToForemanTool) receives this tool explicitly.
@@ -11,7 +11,9 @@ require "trak_flow"
11
11
  module AIA
12
12
  class TrakFlowBridge
13
13
  def initialize
14
- @db = connect_database
14
+ @db = connect_database
15
+ @steps = Hash.new { |hash, key| hash[key] = [] } # prompt ID => this plan's unstarted steps
16
+ @current = {} # prompt ID => the step now running
15
17
  end
16
18
 
17
19
  # Whether a TrakFlow project is initialized and the database is accessible.
@@ -40,6 +42,7 @@ module AIA
40
42
  title: "Step #{i + 1}: #{prompt_id}",
41
43
  type: "task"
42
44
  })
45
+ @steps[prompt_id] << step
43
46
 
44
47
  if prev_step
45
48
  @db.add_dependency(TrakFlow::Models::Dependency.new(
@@ -60,13 +63,13 @@ module AIA
60
63
 
61
64
  # Update a task's status in TrakFlow.
62
65
  #
63
- # @param step_name [String] task title to find
66
+ # @param step_name [String] the prompt ID of a step in the plan this bridge created
64
67
  # @param status [Symbol] :started, :completed, or :failed
65
68
  # @param reason [String, nil] reason for failure
66
69
  def update_step_status(step_name, status, reason: nil)
67
70
  return unless available?
68
71
 
69
- task = find_task_by_title(step_name)
72
+ task = step_for(step_name, status)
70
73
  return unless task
71
74
 
72
75
  case status
@@ -157,7 +160,7 @@ module AIA
157
160
 
158
161
  # Connect to the TrakFlow database if a project is initialized.
159
162
  def connect_database
160
- return nil unless TrakFlow.initialized?
163
+ return nil unless TaskBoard.ensure_project!
161
164
 
162
165
  db = TrakFlow::Storage::Database.new(TrakFlow.database_path)
163
166
  db.connect
@@ -166,10 +169,13 @@ module AIA
166
169
  nil
167
170
  end
168
171
 
169
- # Find a task by its title (partial match).
170
- def find_task_by_title(title)
171
- tasks = @db.list_tasks(title: title)
172
- tasks.first
172
+ # The step this bridge created for +prompt_id+. :started takes the next
173
+ # unstarted one (a prompt can appear twice); later updates reuse it.
174
+ # Steps are never looked up by title, so older plans can't collide.
175
+ def step_for(prompt_id, status)
176
+ return @current[prompt_id] unless status == :started
177
+
178
+ @current[prompt_id] = @steps[prompt_id].shift
173
179
  end
174
180
  end
175
181
  end
@@ -6,10 +6,9 @@
6
6
  # Replaces ad-hoc instance variable flags on AIA.config.
7
7
  #
8
8
  # Only one special mode may be requested per turn (mutual exclusion).
9
- # Use TurnState#request(mode, **opts) to enqueue a mode — this clears
10
- # all other force_* flags before setting the new one. Assigning the
11
- # attr_accessors directly bypasses mutual exclusion (for backward compat
12
- # and direct test assertions).
9
+ # TurnState#request(mode, **opts) enqueues a mode and clears all other
10
+ # force_* flags. #consume! hands the active mode to its handler and
11
+ # clears it. The force_* flags are read-only from outside.
13
12
 
14
13
  module AIA
15
14
  # :reek:TooManyInstanceVariables -- one boolean flag per exclusive mode plus spawn/mcp details; a Hash would lose the attr_accessor API
@@ -19,9 +18,12 @@ module AIA
19
18
  verify decompose concurrent_mcp debate delegate spawn orchestrate
20
19
  ].freeze
21
20
 
22
- attr_accessor :force_verify, :force_decompose, :force_concurrent_mcp,
23
- :force_debate, :force_delegate, :force_spawn, :spawn_type,
24
- :spawn_spec, :force_orchestrate, :active_mcp_servers
21
+ attr_reader :force_verify, :force_decompose, :force_concurrent_mcp,
22
+ :force_debate, :force_delegate, :force_spawn, :spawn_type,
23
+ :spawn_spec, :force_orchestrate
24
+
25
+ # Per-turn MCP server filter; not an exclusive mode.
26
+ attr_accessor :active_mcp_servers
25
27
 
26
28
  def initialize
27
29
  clear!
@@ -33,8 +35,9 @@ module AIA
33
35
  #
34
36
  # @param mode [Symbol] one of EXCLUSIVE_MODES
35
37
  # @param type [String, nil] specialist type (only relevant for :spawn)
38
+ # @param spec [Hash, nil] explicit specialist spec (only relevant for :spawn)
36
39
  # @raise [ArgumentError] if mode is not one of EXCLUSIVE_MODES
37
- def request(mode, type: nil)
40
+ def request(mode, type: nil, spec: nil)
38
41
  unless EXCLUSIVE_MODES.include?(mode)
39
42
  raise ArgumentError, "Unknown TurnState mode: #{mode.inspect}. Valid: #{EXCLUSIVE_MODES.join(', ')}"
40
43
  end
@@ -49,10 +52,30 @@ module AIA
49
52
  when :delegate then @force_delegate = true
50
53
  when :spawn then @force_spawn = true
51
54
  @spawn_type = type
55
+ @spawn_spec = spec
52
56
  when :orchestrate then @force_orchestrate = true
53
57
  end
54
58
  end
55
59
 
60
+ # Take the active mode for handling and clear it.
61
+ #
62
+ # @return [Hash, nil] { mode:, spawn_type:, spawn_spec: }, or nil when no mode is active
63
+ def consume!
64
+ mode = active_mode
65
+ return nil unless mode
66
+
67
+ taken = { mode: mode, spawn_type: @spawn_type, spawn_spec: @spawn_spec }
68
+ clear_exclusive_flags!
69
+ taken
70
+ end
71
+
72
+ # Clear +mode+ if it is the active mode; leave any other mode alone.
73
+ #
74
+ # @param mode [Symbol] one of EXCLUSIVE_MODES
75
+ def clear_mode(mode)
76
+ clear_exclusive_flags! if active_mode == mode
77
+ end
78
+
56
79
  def clear!
57
80
  @force_verify = false
58
81
  @force_decompose = false
@@ -5,6 +5,7 @@ require 'tty-spinner'
5
5
  require 'tty-table'
6
6
  require 'reline'
7
7
  require 'fileutils'
8
+ require 'stringio'
8
9
 
9
10
  module AIA
10
11
  # :reek:TooManyMethods -- one small builder per table/report section keeps each display testable in isolation
@@ -26,6 +27,21 @@ module AIA
26
27
  format_chat_response(response)
27
28
  end
28
29
 
30
+ # Show one robot's turn (a debate round, say) under a heading. The block is
31
+ # rendered into a buffer and written in one call, so robots finishing
32
+ # concurrently cannot interleave their lines.
33
+ #
34
+ # @param heading [String] e.g. "Round 1 · Tobor"
35
+ # @param response [String, RubyLLM::Message, #reply]
36
+ # @param output [IO]
37
+ def display_robot_turn(heading, response, output = $stdout)
38
+ buffer = StringIO.new
39
+ buffer.puts "\n#{heading}:"
40
+ format_chat_response(response, buffer)
41
+ output.write(buffer.string)
42
+ output.flush
43
+ end
44
+
29
45
  # :reek:TooManyStatements -- line-by-line rendering with a code-fence state machine; the states share locals
30
46
  def format_chat_response(response, output = $stdout)
31
47
  indent = ' '
data/lib/aia/utility.rb CHANGED
@@ -4,12 +4,6 @@ require 'word_wrapper'
4
4
  require 'simple_flow'
5
5
  require 'trak_flow'
6
6
  require 'tty-table'
7
- begin
8
- require 'ruby_llm/mcp'
9
- rescue LoadError, StandardError
10
- # ruby_llm-mcp may not be installed
11
- end
12
-
13
7
  require_relative 'mcp_utility'
14
8
  require_relative 'tool_utility'
15
9
 
@@ -102,7 +96,6 @@ module AIA
102
96
 
103
97
  def banner_libs
104
98
  parts = ["ruby_llm v#{RubyLLM::VERSION}"]
105
- parts << "ruby_llm-mcp v#{RubyLLM::MCP::VERSION}" if defined?(RubyLLM::MCP::VERSION)
106
99
  parts << "robot_lab v#{RobotLab::VERSION}" if defined?(RobotLab::VERSION)
107
100
  parts << "simple_flow v#{SimpleFlow::VERSION}" if defined?(SimpleFlow::VERSION)
108
101
  parts << "trak_flow v#{TrakFlow::VERSION}" if defined?(TrakFlow::VERSION)
@@ -129,27 +122,16 @@ module AIA
129
122
  parts.join(' | ')
130
123
  end
131
124
 
132
- # Post-connection: connected_mcp_servers is the authoritative name list;
133
- # mcp_server_tool_counts provides per-server tool counts.
134
- # Pre-connection fallback: read live from RubyLLM::MCP.clients (--require clients).
135
- # :reek:TooManyStatements -- authoritative post-connection labels with a live RubyLLM::MCP fallback before connection
125
+ # connected_mcp_servers (set by MCPConnectionManager) is the authoritative
126
+ # name list; mcp_server_tool_counts provides per-server tool counts.
136
127
  def mcp_client_labels
137
128
  cfg = AIA.config
138
129
  return [] if cfg&.flags&.no_mcp
139
130
 
140
- connected = cfg&.connected_mcp_servers
141
- unless connected.nil?
142
- counts = cfg&.mcp_server_tool_counts || {}
143
- return connected.map do |name|
144
- count = counts[name]
145
- count ? "#{name}(#{count})" : name
146
- end
147
- end
148
-
149
- return [] unless defined?(RubyLLM::MCP)
150
- RubyLLM::MCP.clients.filter_map do |name, client|
151
- count = client.tools.count rescue nil
152
- "#{name}(#{count})" if count
131
+ counts = cfg&.mcp_server_tool_counts || {}
132
+ Array(cfg&.connected_mcp_servers).map do |name|
133
+ count = counts[name]
134
+ count ? "#{name}(#{count})" : name
153
135
  end
154
136
  end
155
137
 
@@ -45,7 +45,4 @@ module AIA
45
45
  end
46
46
  end
47
47
  end
48
-
49
- # Backward-compatibility alias — prefer VariableInputCollector in new code.
50
- HistoryManager = VariableInputCollector
51
48
  end
@@ -15,35 +15,34 @@ module AIA
15
15
  model = config.models.first
16
16
  run_config = RobotFactory.build_run_config(config)
17
17
  tools = ToolLoader.filtered_tools(config)
18
- mcp = RobotFactory.mcp_server_configs(config)
19
- model_id = model.internal_id
18
+ mcp = RobotFactory.mcp_servers(config)
20
19
 
21
20
  # rubocop:disable-next Metrics/BlockLength
22
21
  RobotLab.create_network(name: "aia-verification") do
23
- worker_a = RobotLab.build(
22
+ worker_a = RobotFactory.build_robot(
23
+ model,
24
24
  name: "verifier-a",
25
- model: model_id,
26
25
  system_prompt: "Answer the following question. Be thorough and precise.",
27
26
  local_tools: tools,
28
- mcp_servers: mcp,
27
+ mcp: mcp,
29
28
  config: run_config
30
29
  )
31
30
  task :verify_a, worker_a, depends_on: :none
32
31
 
33
- worker_b = RobotLab.build(
32
+ worker_b = RobotFactory.build_robot(
33
+ model,
34
34
  name: "verifier-b",
35
- model: model_id,
36
35
  system_prompt: "Answer the following question independently. " \
37
36
  "Focus on correctness and completeness.",
38
37
  local_tools: tools,
39
- mcp_servers: mcp,
38
+ mcp: mcp,
40
39
  config: run_config
41
40
  )
42
41
  task :verify_b, worker_b, depends_on: :none
43
42
 
44
- reconciler = RobotLab.build(
43
+ reconciler = RobotFactory.build_robot(
44
+ model,
45
45
  name: "reconciler",
46
- model: model_id,
47
46
  system_prompt: "Compare two independent answers to the same question. " \
48
47
  "Identify agreements and disagreements. " \
49
48
  "Produce a final, reconciled answer that is most accurate. " \
data/lib/aia.rb CHANGED
@@ -8,8 +8,12 @@ require 'bigdecimal'
8
8
  require 'robot_lab'
9
9
  require 'pm'
10
10
 
11
- require_relative 'aia/patches/ruby_llm_tool_error'
12
- require_relative 'aia/patches/ruby_llm_streaming_error'
11
+ # Patches disabled 2026-09-16 (per DVH) — re-enable by uncommenting.
12
+ # NOTE: with ruby_llm_tool_param_compat disabled, the 2.0-style tool DSL
13
+ # (`parameter`/`description:`) in lib/aia/tools/ requires ruby_llm >= 2.0.
14
+ # require_relative 'aia/patches/ruby_llm_tool_error'
15
+ # require_relative 'aia/patches/ruby_llm_streaming_error'
16
+ # require_relative 'aia/patches/ruby_llm_tool_param_compat'
13
17
 
14
18
  require_relative 'aia/errors'
15
19
  require_relative 'aia/timing'
@@ -20,7 +24,13 @@ require_relative 'aia/speech'
20
24
  require_relative 'aia/utility'
21
25
  require_relative 'aia/mcp_server_config'
22
26
  require_relative 'aia/skill_utils'
27
+ require_relative 'aia/role_catalog'
28
+ require_relative 'aia/model_registry'
29
+ require_relative 'aia/task_board'
30
+ require_relative 'aia/trakflow_bridge'
31
+ require_relative 'aia/task_coordinator'
23
32
  require_relative 'aia/version'
33
+ require_relative 'aia/provider_registry'
24
34
  require_relative 'aia/config'
25
35
  require_relative 'aia/logger'
26
36
 
@@ -37,7 +47,9 @@ require_relative 'aia/tools/reskill_robot_tool'
37
47
  require_relative 'aia/system_prompt_assembler'
38
48
  require_relative 'aia/mcp_config_normalizer'
39
49
  require_relative 'aia/network_memory_manager'
50
+ require_relative 'aia/tool_approver'
40
51
  require_relative 'aia/robot_factory'
52
+ require_relative 'aia/robot_sync'
41
53
  require_relative 'aia/robot_builder'
42
54
  require_relative 'aia/directive_processor'
43
55
  require_relative 'aia/variable_input_collector'
@@ -46,7 +58,6 @@ require_relative 'aia/input_collector'
46
58
  require_relative 'aia/handler_context'
47
59
  require_relative 'aia/handler_protocol'
48
60
  require_relative 'aia/model_alias_registry'
49
- require_relative 'aia/model_switch_handler'
50
61
  require_relative 'aia/mcp_discovery'
51
62
  require_relative 'aia/mcp_grouper'
52
63
  require_relative 'aia/cost_calculator'
@@ -74,9 +85,7 @@ module AIA
74
85
  $DEBUG_ME = false
75
86
  DebugMeDefaultOptions[:skip1] = true
76
87
 
77
- at_exit do
78
- $stderr.puts 'Exiting AIA application...'
79
- end
88
+ at_exit { AIA.announce_exit }
80
89
 
81
90
  @config = nil
82
91
  @client = nil
@@ -84,7 +93,23 @@ module AIA
84
93
  @turn_state = TurnState.new
85
94
 
86
95
  class << self
87
- attr_accessor :config, :client, :session_tracker, :turn_state, :task_coordinator
96
+ attr_accessor :config, :client, :session_tracker, :turn_state, :mcp_manager
97
+ attr_writer :task_coordinator
98
+
99
+ # The TrakFlow task coordinator, started the first time it is asked for.
100
+ #
101
+ # @return [AIA::TaskCoordinator, nil]
102
+ def task_coordinator
103
+ @task_coordinator ||= TaskBoard.coordinator
104
+ end
105
+
106
+ # Say goodbye when an interactive chat session ends. One-shot commands
107
+ # (--version, --help, --mcp-list, piped prompts) exit silently.
108
+ #
109
+ # @param io [IO]
110
+ def announce_exit(io = $stderr)
111
+ io.puts 'Exiting AIA application...' if chat?
112
+ end
88
113
 
89
114
  def logger
90
115
  AIA::LoggerManager.aia_logger
@@ -92,7 +117,7 @@ module AIA
92
117
 
93
118
  def reset!
94
119
  @config = @client = @session_tracker = @turn_state =
95
- @task_coordinator = nil
120
+ @task_coordinator = @mcp_manager = nil
96
121
  ToolLoader.reset_instance!
97
122
  end
98
123