aia 2.0.0.0.pre.alpha → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. checksums.yaml +4 -4
  2. data/.version +1 -1
  3. data/CHANGELOG.md +151 -228
  4. data/README.md +42 -19
  5. data/bin/aia +8 -3
  6. data/lib/aia/aia_completion.bash +2 -3
  7. data/lib/aia/aia_completion.fish +6 -5
  8. data/lib/aia/aia_completion.zsh +2 -3
  9. data/lib/aia/chat_loop.rb +24 -66
  10. data/lib/aia/config/cli_parser.rb +164 -123
  11. data/lib/aia/config/defaults.yml +12 -39
  12. data/lib/aia/config/mcp_parser.rb +42 -40
  13. data/lib/aia/config/model_spec.rb +8 -14
  14. data/lib/aia/config/validator.rb +144 -156
  15. data/lib/aia/config/value_caster.rb +76 -0
  16. data/lib/aia/config.rb +72 -54
  17. data/lib/aia/content_extractor.rb +2 -0
  18. data/lib/aia/cost_calculator.rb +1 -0
  19. data/lib/aia/crew.rb +29 -19
  20. data/lib/aia/debate_handler.rb +45 -20
  21. data/lib/aia/delegate_handler.rb +7 -3
  22. data/lib/aia/directive.rb +10 -8
  23. data/lib/aia/directives/configuration_directives.rb +164 -109
  24. data/lib/aia/directives/context_directives.rb +55 -40
  25. data/lib/aia/directives/execution_directives.rb +25 -25
  26. data/lib/aia/directives/model_directives.rb +112 -195
  27. data/lib/aia/directives/trakflow_directives.rb +27 -9
  28. data/lib/aia/directives/utility_directives.rb +86 -87
  29. data/lib/aia/directives/web_and_file_directives.rb +83 -63
  30. data/lib/aia/fact_asserter.rb +3 -3
  31. data/lib/aia/history_transfer.rb +64 -24
  32. data/lib/aia/layered_orchestrator.rb +66 -43
  33. data/lib/aia/logger.rb +27 -62
  34. data/lib/aia/mcp_config_normalizer.rb +27 -14
  35. data/lib/aia/mcp_connection_manager.rb +193 -186
  36. data/lib/aia/mcp_discovery.rb +43 -15
  37. data/lib/aia/mcp_grouper.rb +2 -1
  38. data/lib/aia/mcp_server_config.rb +48 -0
  39. data/lib/aia/mcp_utility.rb +28 -20
  40. data/lib/aia/mention_router.rb +22 -52
  41. data/lib/aia/modality_query.rb +36 -0
  42. data/lib/aia/model_alias_registry.rb +11 -11
  43. data/lib/aia/model_registry.rb +75 -0
  44. data/lib/aia/network_builder.rb +17 -11
  45. data/lib/aia/network_memory_manager.rb +6 -6
  46. data/lib/aia/patches/ruby_llm_streaming_error.rb +21 -4
  47. data/lib/aia/patches/ruby_llm_tool_param_compat.rb +18 -0
  48. data/lib/aia/pipeline_orchestrator.rb +88 -45
  49. data/lib/aia/plugin_monitor.rb +9 -6
  50. data/lib/aia/prompt_decomposer.rb +6 -4
  51. data/lib/aia/prompt_handler.rb +90 -69
  52. data/lib/aia/provider_registry.rb +105 -0
  53. data/lib/aia/robot_builder.rb +1 -1
  54. data/lib/aia/robot_factory.rb +77 -69
  55. data/lib/aia/robot_namer.rb +2 -8
  56. data/lib/aia/robot_sync.rb +79 -0
  57. data/lib/aia/role_catalog.rb +89 -0
  58. data/lib/aia/session.rb +32 -14
  59. data/lib/aia/session_tracker.rb +39 -41
  60. data/lib/aia/similarity_scorer.rb +5 -3
  61. data/lib/aia/skill_utils.rb +60 -19
  62. data/lib/aia/spawn_handler.rb +16 -4
  63. data/lib/aia/spawn_spec_parser.rb +6 -7
  64. data/lib/aia/special_mode_handler.rb +80 -57
  65. data/lib/aia/speech.rb +103 -0
  66. data/lib/aia/startup_coordinator.rb +17 -91
  67. data/lib/aia/streaming_runner.rb +16 -5
  68. data/lib/aia/system_prompt_assembler.rb +20 -15
  69. data/lib/aia/task_board.rb +60 -0
  70. data/lib/aia/task_coordinator.rb +10 -5
  71. data/lib/aia/timing.rb +15 -0
  72. data/lib/aia/tool_approver.rb +205 -0
  73. data/lib/aia/tool_filter.rb +1 -9
  74. data/lib/aia/tool_filter_strategy.rb +39 -25
  75. data/lib/aia/tool_introspection.rb +25 -0
  76. data/lib/aia/tool_loader.rb +71 -31
  77. data/lib/aia/tool_utility.rb +6 -5
  78. data/lib/aia/tools/delegate_to_foreman_tool.rb +6 -4
  79. data/lib/aia/tools/recruit_robot_tool.rb +12 -12
  80. data/lib/aia/tools/reskill_robot_tool.rb +7 -7
  81. data/lib/aia/tools/task_board_tool.rb +17 -16
  82. data/lib/aia/trakflow_bridge.rb +19 -11
  83. data/lib/aia/turn_state.rb +32 -8
  84. data/lib/aia/ui_presenter.rb +83 -59
  85. data/lib/aia/utility.rb +8 -24
  86. data/lib/aia/variable_input_collector.rb +1 -3
  87. data/lib/aia/verification_network.rb +10 -12
  88. data/lib/aia.rb +49 -8
  89. metadata +27 -162
  90. data/.better-commits.json +0 -150
  91. data/.config/tocer/configuration.yml +0 -6
  92. data/.envrc +0 -15
  93. data/.loki +0 -231
  94. data/.quality/flay_baseline.txt +0 -1
  95. data/.quality/flog_baseline.txt +0 -29
  96. data/.quality/reek_baseline.txt +0 -80
  97. data/.rubocop.yml +0 -116
  98. data/COMMITS.md +0 -196
  99. data/IMPLEMENTATION_PLAN.md +0 -506
  100. data/Rakefile +0 -160
  101. data/architecture_review.md +0 -314
  102. data/docs/AGENTS.md +0 -40
  103. data/docs/advanced-prompting.md +0 -814
  104. data/docs/assets/images/aia.png +0 -0
  105. data/docs/cli-reference.md +0 -1241
  106. data/docs/configuration.md +0 -747
  107. data/docs/contributing.md +0 -386
  108. data/docs/directives-reference.md +0 -1145
  109. data/docs/examples/index.md +0 -277
  110. data/docs/examples/mcp/index.md +0 -475
  111. data/docs/examples/prompts/analysis/index.md +0 -78
  112. data/docs/examples/prompts/automation/index.md +0 -109
  113. data/docs/examples/prompts/development/index.md +0 -125
  114. data/docs/examples/prompts/index.md +0 -333
  115. data/docs/examples/prompts/learning/index.md +0 -127
  116. data/docs/examples/prompts/writing/index.md +0 -62
  117. data/docs/examples/tools/index.md +0 -282
  118. data/docs/faq.md +0 -578
  119. data/docs/guides/available-models.md +0 -366
  120. data/docs/guides/basic-usage.md +0 -478
  121. data/docs/guides/chat.md +0 -680
  122. data/docs/guides/crew.md +0 -239
  123. data/docs/guides/executable-prompts.md +0 -331
  124. data/docs/guides/first-prompt.md +0 -454
  125. data/docs/guides/getting-started.md +0 -455
  126. data/docs/guides/image-generation.md +0 -507
  127. data/docs/guides/index.md +0 -48
  128. data/docs/guides/local-models.md +0 -306
  129. data/docs/guides/migrate-prompts.md +0 -335
  130. data/docs/guides/models.md +0 -1017
  131. data/docs/guides/shared-tools.md +0 -254
  132. data/docs/guides/tools.md +0 -831
  133. data/docs/index.md +0 -259
  134. data/docs/installation.md +0 -274
  135. data/docs/mcp-integration.md +0 -603
  136. data/docs/prompt_management.md +0 -665
  137. data/docs/security.md +0 -674
  138. data/docs/special_projects_guide.md +0 -386
  139. data/docs/tools-and-mcp-examples.md +0 -1211
  140. data/docs/workflows-and-pipelines.md +0 -636
  141. data/examples/.gitignore +0 -2
  142. data/examples/00_setup_aia.sh +0 -111
  143. data/examples/01_basic_usage.sh +0 -23
  144. data/examples/02_frontmatter.sh +0 -33
  145. data/examples/03_shell_integration.sh +0 -55
  146. data/examples/04_erb_templating.sh +0 -56
  147. data/examples/05_shell_then_erb.sh +0 -38
  148. data/examples/06_prompt_chaining.sh +0 -59
  149. data/examples/07_pipeline.sh +0 -46
  150. data/examples/08_context_files.sh +0 -43
  151. data/examples/09_roles.sh +0 -67
  152. data/examples/10_stdin_piping.sh +0 -49
  153. data/examples/11_multi_model.sh +0 -65
  154. data/examples/12_token_usage.sh +0 -52
  155. data/examples/13_cost_tracking.sh +0 -68
  156. data/examples/14_output_file.sh +0 -91
  157. data/examples/15_parameters.sh +0 -68
  158. data/examples/16_directives.sh +0 -113
  159. data/examples/17_require_and_conditionals.sh +0 -68
  160. data/examples/18_tools.sh +0 -61
  161. data/examples/19_local_tools.sh +0 -34
  162. data/examples/20_mcp_servers.sh +0 -102
  163. data/examples/21_executable_prompts.sh +0 -78
  164. data/examples/22_chat_mode.sh +0 -217
  165. data/examples/23_verify.sh +0 -139
  166. data/examples/24_decompose.sh +0 -139
  167. data/examples/25_spawn.sh +0 -139
  168. data/examples/26_debate.sh +0 -97
  169. data/examples/27_mention_routing.sh +0 -157
  170. data/examples/28_model_switching.sh +0 -106
  171. data/examples/29_agent_harness.sh +0 -177
  172. data/examples/README.md +0 -321
  173. data/examples/advanced_multi_robot_capabilities_without_examples.md +0 -106
  174. data/examples/aia_config.yml +0 -22
  175. data/examples/aia_config_orchestrator.yml +0 -45
  176. data/examples/aia_config_with_mcp.yml +0 -21
  177. data/examples/common.sh +0 -39
  178. data/examples/context/project_goals.md +0 -6
  179. data/examples/context/tech_stack.md +0 -7
  180. data/examples/directives/timestamp_directive.rb +0 -22
  181. data/examples/mcp/filesystem.json +0 -9
  182. data/examples/prompts_dir/analyze.md +0 -2
  183. data/examples/prompts_dir/brainstorm.md +0 -2
  184. data/examples/prompts_dir/conditional.md +0 -17
  185. data/examples/prompts_dir/creative.md +0 -4
  186. data/examples/prompts_dir/erbinfo.md +0 -5
  187. data/examples/prompts_dir/erbinfo_raw.md +0 -8
  188. data/examples/prompts_dir/evaluate.md +0 -2
  189. data/examples/prompts_dir/explain_joke.md +0 -1
  190. data/examples/prompts_dir/explain_recursion.md +0 -1
  191. data/examples/prompts_dir/fun_fact +0 -3
  192. data/examples/prompts_dir/greeting.md +0 -8
  193. data/examples/prompts_dir/greeting_required.md +0 -7
  194. data/examples/prompts_dir/hello.md +0 -1
  195. data/examples/prompts_dir/includes/ruby_facts.md +0 -4
  196. data/examples/prompts_dir/limerick.md +0 -1
  197. data/examples/prompts_dir/list_with_mcp.md +0 -3
  198. data/examples/prompts_dir/pick_best.md +0 -2
  199. data/examples/prompts_dir/project_summary +0 -12
  200. data/examples/prompts_dir/quiz_with_include.md +0 -6
  201. data/examples/prompts_dir/require_demo.md +0 -5
  202. data/examples/prompts_dir/roles/formal.md +0 -3
  203. data/examples/prompts_dir/roles/orchestrator.md +0 -21
  204. data/examples/prompts_dir/roles/pirate.md +0 -3
  205. data/examples/prompts_dir/shell_then_erb.md +0 -6
  206. data/examples/prompts_dir/sort_compare.md +0 -2
  207. data/examples/prompts_dir/summarize_context.md +0 -2
  208. data/examples/prompts_dir/sysinfo.md +0 -5
  209. data/examples/prompts_dir/sysinfo_raw.md +0 -8
  210. data/examples/prompts_dir/tagline.md +0 -1
  211. data/examples/prompts_dir/tell_joke.md +0 -1
  212. data/examples/prompts_dir/tell_joke_with_next.md +0 -4
  213. data/examples/prompts_dir/use_local_tool.md +0 -8
  214. data/examples/prompts_dir/use_tools.md +0 -8
  215. data/examples/prompts_dir/weather.md +0 -2
  216. data/examples/prompts_dir/whats_new.md +0 -2
  217. data/examples/prompts_dir/with_timestamp.md +0 -5
  218. data/examples/requirements/sinatra_taskflow_app.md +0 -139
  219. data/examples/rules/01_classify_ruby.rb +0 -16
  220. data/examples/rules/02_prefer_claude_for_code.rb +0 -19
  221. data/examples/rules/03_gate_prompt_length.rb +0 -19
  222. data/examples/rules/04_tool_selection.rb +0 -41
  223. data/examples/rules/README.md +0 -30
  224. data/examples/run_all.sh +0 -294
  225. data/examples/tools/word_count_tool.rb +0 -30
  226. data/lib/AGENTS.md +0 -57
  227. data/lib/aia/model_switch_handler.rb +0 -100
  228. data/mcp_servers/README.md +0 -110
  229. data/mcp_servers/apple-mcp.json +0 -8
  230. data/mcp_servers/filesystem.json +0 -9
  231. data/mcp_servers/mcp_server_chart.json +0 -11
  232. data/mcp_servers/playwright_one.json +0 -8
  233. data/mcp_servers/playwright_server_definition.json +0 -9
  234. data/mcp_servers/playwright_two.json +0 -8
  235. data/mcp_servers/tavily_mcp_server.json +0 -8
  236. data/mkdocs.yml +0 -169
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ # lib/aia/config/value_caster.rb
4
+ #
5
+ # Environment variables (AIA_*) and `/config KEY VALUE` arrive as strings.
6
+ # ValueCaster converts such a string to the type of the key's default in
7
+ # defaults.yml: booleans, integers, floats and comma-separated lists. Keys
8
+ # whose default is nil carry no type, so UNTYPED_DEFAULTS supplies one.
9
+ # Values that are not strings, or that don't parse, are returned unchanged.
10
+
11
+ module AIA
12
+ module ValueCaster
13
+ TRUE_WORDS = %w[true yes on 1].freeze
14
+ FALSE_WORDS = %w[false no off 0].freeze
15
+
16
+ # Type samples for keys whose default is nil (dotted path => sample value)
17
+ UNTYPED_DEFAULTS = {
18
+ 'llm.top_p' => 0.0,
19
+ 'tools.allowed' => [],
20
+ 'tools.rejected' => []
21
+ }.freeze
22
+
23
+ module_function
24
+
25
+ # @param value [Object] the incoming value
26
+ # @param default [Object] the key's default (its type is the target type)
27
+ # @return [Object] the converted value, or +value+ when it can't be converted
28
+ def cast(value, default)
29
+ return value unless value.is_a?(String)
30
+
31
+ case default
32
+ when true, false then to_boolean(value)
33
+ when Integer then Integer(value.strip, 10, exception: false) || value
34
+ when Float then Float(value.strip, exception: false) || value
35
+ when Array then value.split(',').map(&:strip).reject(&:empty?)
36
+ else value
37
+ end
38
+ end
39
+
40
+ # @return [Boolean, String] true/false for a recognized word, else +value+
41
+ def to_boolean(value)
42
+ word = value.strip.downcase
43
+ return true if TRUE_WORDS.include?(word)
44
+ return false if FALSE_WORDS.include?(word)
45
+
46
+ value
47
+ end
48
+
49
+ # The default used to type +path+ ("section.key"): the schema value, or the
50
+ # UNTYPED_DEFAULTS sample when the schema default is nil.
51
+ def default_for(path, schema_default)
52
+ schema_default.nil? ? UNTYPED_DEFAULTS[path] : schema_default
53
+ end
54
+
55
+ # Convert every string value in +section+ (a ConfigSection) in place,
56
+ # recursing into nested sections.
57
+ #
58
+ # @param section [#[], #[]=] the section to convert
59
+ # @param defaults [Hash] the section's defaults (symbol keys)
60
+ # @param prefix [String] dotted path of the section, e.g. "llm"
61
+ # @return [void]
62
+ def cast_section!(section, defaults, prefix)
63
+ return unless section && defaults.is_a?(Hash)
64
+
65
+ defaults.each do |key, schema_default|
66
+ path = "#{prefix}.#{key}"
67
+ value = section[key]
68
+ if schema_default.is_a?(Hash) && !schema_default.empty?
69
+ cast_section!(value, schema_default, path)
70
+ else
71
+ section[key] = cast(value, default_for(path, schema_default))
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
data/lib/aia/config.rb CHANGED
@@ -26,11 +26,9 @@ require 'date'
26
26
 
27
27
  require_relative 'config/model_spec'
28
28
  require_relative 'config/mcp_parser'
29
+ require_relative 'config/value_caster'
29
30
 
30
31
  module AIA
31
- # Backward compatibility alias
32
- ConfigSection = MywayConfig::ConfigSection
33
-
34
32
  class Config < MywayConfig::Base
35
33
  config_name :aia
36
34
  env_prefix :aia
@@ -48,16 +46,21 @@ module AIA
48
46
  # ==========================================================================
49
47
 
50
48
  # Nested section attributes (defined as hashes, converted to ConfigSection)
51
- attr_config :service, :llm, :prompts, :roles, :skills, :output, :audio, :image, :embedding,
52
- :tools, :flags, :registry, :paths, :logger, :rules, :concurrency,
53
- :tool_filter
49
+ SECTIONS = %i[service llm prompts skills output audio image
50
+ tools flags registry paths logger concurrency tool_filter].freeze
51
+
52
+ attr_config(*SECTIONS)
54
53
 
55
54
  # Array/collection attributes
56
55
  attr_config :models, :pipeline, :require_libs, :mcp_servers, :mcp_use, :mcp_skip, :context_files
57
56
 
57
+ # Model switching: /model history transfer mode and model-name aliases
58
+ attr_config :model_switch_history, :model_aliases
59
+
58
60
  # Runtime attributes (not loaded from config files)
61
+ attr_accessor :provider # --provider: default provider for prefixless models; also scopes --list-models
59
62
  attr_accessor :prompt_id, :stdin_content, :remaining_args, :dump_file,
60
- :completion, :mcp_list, :list_tools, :list_skills,
63
+ :completion, :mcp_list, :list_tools, :list_skills, :list_roles,
61
64
  :executable_prompt_content,
62
65
  :tool_names, :loaded_tools, :loaded_plugins,
63
66
  :log_level_override, :log_file_override,
@@ -107,18 +110,15 @@ module AIA
107
110
  service: config_section_coercion(:service),
108
111
  llm: config_section_coercion(:llm),
109
112
  prompts: config_section_coercion(:prompts),
110
- roles: config_section_coercion(:roles),
111
113
  skills: config_section_coercion(:skills),
112
114
  output: config_section_coercion(:output),
113
115
  audio: config_section_coercion(:audio),
114
116
  image: config_section_coercion(:image),
115
- embedding: config_section_coercion(:embedding),
116
117
  tools: config_section_coercion(:tools),
117
118
  flags: config_section_coercion(:flags),
118
119
  logger: config_section_coercion(:logger),
119
120
  registry: config_section_coercion(:registry),
120
121
  paths: config_section_coercion(:paths),
121
- rules: config_section_coercion(:rules),
122
122
  concurrency: config_section_coercion(:concurrency),
123
123
  tool_filter: config_section_coercion(:tool_filter),
124
124
 
@@ -167,10 +167,7 @@ module AIA
167
167
  verbose: %i[flags verbose],
168
168
  consensus: %i[flags consensus],
169
169
  track_pipeline: %i[flags track_pipeline],
170
- expert_routing: %i[flags expert_routing],
171
170
  auto_tool_filter: %i[flags auto_tool_filter],
172
- tool_filter_load: %i[flags tool_filter_load],
173
- tool_filter_save: %i[flags tool_filter_save],
174
171
  allow_ruby_eval: %i[flags allow_ruby_eval],
175
172
  thinking: %i[flags thinking],
176
173
  tool_filter_timeout_s: %i[tool_filter timeout_s],
@@ -187,14 +184,11 @@ module AIA
187
184
  role: %i[prompts role],
188
185
  skills_dir: %i[skills dir],
189
186
  skills: %i[prompts skills],
190
- tools_prefix: %i[prompts tools_prefix],
191
- tool: %i[prompts tool],
192
187
  system_prompt: %i[prompts system_prompt],
193
188
  # output section
194
189
  output: %i[output file],
195
190
  history_file: %i[output history_file],
196
191
  append: %i[output append],
197
- markdown: %i[output markdown],
198
192
  # audio section (speak is a flag, not audio config)
199
193
  speak: %i[flags speak],
200
194
  voice: %i[audio voice],
@@ -211,12 +205,11 @@ module AIA
211
205
  tool_paths: %i[tools paths],
212
206
  allowed_tools: %i[tools allowed],
213
207
  rejected_tools: %i[tools rejected],
208
+ tool_approval: %i[tools approval],
214
209
  # registry section
215
210
  refresh: %i[registry refresh],
216
211
  # paths section
217
- plugins_dir: %i[paths plugins_dir],
218
- # rules section
219
- rules_enabled: %i[rules enabled]
212
+ plugins_dir: %i[paths plugins_dir]
220
213
  }.freeze
221
214
 
222
215
  def initialize(overrides: {})
@@ -227,9 +220,14 @@ module AIA
227
220
  extra_config_path = overrides.delete(:extra_config_file)
228
221
  load_extra_config(extra_config_path) if extra_config_path
229
222
 
223
+ drop_unknown_keys
224
+ # Not a schema key, so it is set after unknown keys are dropped
225
+ paths[:extra_config_file] = File.expand_path(extra_config_path) if extra_config_path && File.exist?(extra_config_path)
226
+ cast_string_values
230
227
  apply_models_env_var unless overrides[:models]
231
228
  apply_plugins_dir_env_var unless overrides[:plugins_dir]
232
229
  apply_overrides(overrides) if overrides && !overrides.empty?
230
+ apply_default_provider
233
231
  expand_paths
234
232
  process_mcp_files(overrides[:mcp_files]) if overrides[:mcp_files]
235
233
  end
@@ -258,40 +256,56 @@ module AIA
258
256
  end
259
257
  end
260
258
 
259
+ # +hash+ without the keys +schema+ doesn't define, at every level. A
260
+ # schema value that is an empty Hash accepts any keys.
261
+ #
262
+ # @param hash [Hash] section values (from defaults, config files and env)
263
+ # @param schema [Hash] the section's defaults from defaults.yml
264
+ # @return [Hash]
265
+ def self.schema_keys_only(hash, schema)
266
+ return hash if schema.empty?
267
+
268
+ hash.each_with_object({}) do |(key, value), kept|
269
+ next unless schema.key?(key)
270
+
271
+ sub = schema[key]
272
+ kept[key] = sub.is_a?(Hash) && value.is_a?(Hash) ? schema_keys_only(value, sub) : value
273
+ end
274
+ end
275
+
261
276
  # Convert config to hash (for dump, etc.)
262
- # rubocop:disable Metrics/AbcSize
263
277
  def to_h
264
- {
265
- service: service.to_h,
266
- llm: llm.to_h,
278
+ SECTIONS.to_h { [it, send(it).to_h] }.merge(
267
279
  models: models.map(&:to_h),
268
- prompts: prompts.to_h,
269
- roles: roles.to_h,
270
- skills: skills.to_h,
271
- output: output.to_h,
272
- audio: audio.to_h,
273
- image: image.to_h,
274
- embedding: embedding.to_h,
275
- tools: tools.to_h,
276
- flags: flags.to_h,
277
- logger: logger.to_h,
278
- registry: registry.to_h,
279
- paths: paths.to_h,
280
- rules: rules.to_h,
281
- concurrency: concurrency.to_h,
282
- pipeline: pipeline,
283
- require_libs: require_libs,
284
- mcp_servers: mcp_servers,
285
- mcp_use: mcp_use,
286
- mcp_skip: mcp_skip,
287
- context_files: context_files
288
- }
280
+ model_switch_history:, model_aliases:,
281
+ pipeline:, require_libs:, mcp_servers:, mcp_use:, mcp_skip:, context_files:
282
+ )
289
283
  end
290
- # rubocop:enable Metrics/AbcSize
291
284
 
292
285
  private
293
286
 
287
+ # Keys that defaults.yml doesn't define — removed settings in an old
288
+ # config file, or AIA_* variables for them — are ignored, so they
289
+ # don't linger in the config or in --dump.
290
+ def drop_unknown_keys
291
+ SECTIONS.each do |name|
292
+ section = send(name)
293
+ kept = self.class.schema_keys_only(section.to_h, self.class.schema[name] || {})
294
+ send(:"#{name}=", MywayConfig::ConfigSection.new(kept)) unless kept == section.to_h
295
+ end
296
+ end
297
+
298
+ # Environment variables arrive as strings; give each section value the
299
+ # type of its default (booleans, numbers, comma-separated lists).
300
+ def cast_string_values
301
+ SECTIONS.each do |name|
302
+ ValueCaster.cast_section!(send(name), self.class.schema[name] || {}, name.to_s)
303
+ end
304
+ end
305
+
294
306
  # Load a config file that REPLACES the user's personal config.
307
+ # :reek:TooManyStatements -- single case dispatch mapping YAML keys to typed config setters; one branch per key family
308
+ # :reek:DuplicateMethodCall -- Array(value) sits in mutually exclusive case branches; hoisting it would coerce hash-section values too
295
309
  def load_extra_config(path)
296
310
  path = File.expand_path(path)
297
311
 
@@ -309,8 +323,6 @@ module AIA
309
323
 
310
324
  config_hash = raw.key?(:defaults) ? (raw[:defaults] || {}) : raw
311
325
 
312
- paths[:extra_config_file] = path
313
-
314
326
  config_hash.each do |key, value|
315
327
  case key
316
328
  when :models
@@ -319,8 +331,9 @@ module AIA
319
331
  send("#{key}=", Array(value)) if respond_to?("#{key}=")
320
332
  when :mcp_servers
321
333
  self.mcp_servers = Array(value)
322
- when :service, :llm, :prompts, :roles, :skills, :output, :audio, :image, :embedding,
323
- :tools, :flags, :registry, :paths, :logger, :rules, :concurrency
334
+ when :model_switch_history, :model_aliases
335
+ send("#{key}=", value)
336
+ when *SECTIONS
324
337
  section = send(key)
325
338
  if section.is_a?(MywayConfig::ConfigSection) && value.is_a?(Hash)
326
339
  merge_into_section(section, value)
@@ -369,6 +382,16 @@ module AIA
369
382
  end
370
383
  end
371
384
 
385
+ # `--provider SLUG` gives prefixless models a default provider. A model
386
+ # named with an explicit "<provider>/" prefix keeps its own.
387
+ def apply_default_provider
388
+ return if provider.nil? || provider.to_s.empty?
389
+
390
+ Array(models).each do |spec|
391
+ spec.provider ||= provider if spec.respond_to?(:provider)
392
+ end
393
+ end
394
+
372
395
  def apply_models_env_var
373
396
  models_env = ENV.fetch('AIA_MODEL', nil)
374
397
  return if models_env.nil? || models_env.empty?
@@ -387,15 +410,10 @@ module AIA
387
410
 
388
411
  def expand_paths
389
412
  expand_path_on(paths, :aia_dir)
390
- expand_path_on(paths, :config_file)
391
413
  expand_path_on(paths, :plugins_dir)
392
414
  expand_path_on(prompts, :dir)
393
- expand_path_on(prompts, :roles_dir)
394
- expand_path_on(roles, :dir)
395
415
  expand_path_on(skills, :dir)
396
- expand_path_on(tools, :dir)
397
416
  expand_path_on(output, :history_file)
398
- expand_path_on(rules, :dir)
399
417
  end
400
418
 
401
419
  def expand_path_on(obj, method_name)
@@ -34,6 +34,7 @@ module AIA
34
34
  #
35
35
  # @param flow_result [SimpleFlow::Result]
36
36
  # @return [String]
37
+ # :reek:TooManyStatements -- one pass duck-types reply/content/duration into labeled sections
37
38
  def extract_network_content(flow_result)
38
39
  parts = []
39
40
  flow_result.context.each do |task_name, robot_result|
@@ -97,6 +98,7 @@ module AIA
97
98
  # @param tracker [SessionTracker, nil] to record the turn
98
99
  # @param decisions [Hash, nil] routing decisions for tracker
99
100
  # @return [String] the extracted content
101
+ # :reek:LongParameterList { max_params: 7 } -- presentation seam: each keyword is an independent optional aspect
100
102
  def present_result(result, ui_presenter:, streamed_content: nil, prompt: nil, elapsed: nil, tracker: nil, decisions: nil)
101
103
  content = streamed_content || extract_content(result)
102
104
 
@@ -13,6 +13,7 @@ module AIA
13
13
  # @param output_tokens [Integer]
14
14
  # @return [Hash] { available: true, total_cost:, input_cost:, output_cost: }
15
15
  # or { available: false } when pricing is unavailable
16
+ # :reek:TooManyStatements -- linear price lookup: guard, registry fetch, per-direction cost math, result hash
16
17
  def self.calculate(model_id:, input_tokens:, output_tokens:)
17
18
  return { available: false } unless model_id && defined?(RubyLLM::Models)
18
19
 
data/lib/aia/crew.rb CHANGED
@@ -31,9 +31,10 @@ module AIA
31
31
  name: name,
32
32
  system_prompt: compose_system_prompt(spec),
33
33
  local_tools: chief_local_tools(chief),
34
+ **chief_mcp(chief),
35
+ **ToolApprover.options(AIA.config),
34
36
  **model_opts(spec)
35
37
  )
36
- inherit_mcp(robot, chief)
37
38
  crew.add_robot(robot)
38
39
  robot
39
40
  end
@@ -53,11 +54,13 @@ module AIA
53
54
  name = name.to_s
54
55
  old = find_member(crew, name)
55
56
  raise CrewError, "No crewmate named '#{name}'." unless old
56
- raise CrewError, "Cannot reskill the chief '#{name}'." if crew.chief&.name == name
57
57
 
58
- crew.remove_robot(name)
58
+ old_name = old.name
59
+ raise CrewError, "Cannot reskill the chief '#{old_name}'." if chief?(crew, old_name)
60
+
61
+ crew.remove_robot(old_name)
59
62
  recruit(
60
- name: name, model: old.model, provider: old.provider,
63
+ name: old_name, model: old.model, provider: old.provider,
61
64
  skills: skills, system_prompt: system_prompt
62
65
  )
63
66
  end
@@ -71,10 +74,13 @@ module AIA
71
74
  def drop(name)
72
75
  crew = require_crew
73
76
  name = name.to_s
74
- raise CrewError, "No crewmate named '#{name}'." unless member?(crew, name)
75
- raise CrewError, "Cannot drop the chief '#{name}'." if crew.chief&.name == name
77
+ member = find_member(crew, name)
78
+ raise CrewError, "No crewmate named '#{name}'." unless member
79
+
80
+ member_name = member.name
81
+ raise CrewError, "Cannot drop the chief '#{member_name}'." if chief?(crew, member_name)
76
82
 
77
- crew.remove_robot(name)
83
+ crew.remove_robot(member_name)
78
84
  end
79
85
 
80
86
  # The crew (Network) backing the current session.
@@ -88,14 +94,21 @@ module AIA
88
94
  crew
89
95
  end
90
96
 
97
+ # Crew names are matched without regard to case, as @mentions are.
98
+ #
91
99
  # @return [Boolean]
92
100
  def member?(crew, name)
93
- crew.crew.any? { |robot| robot.name == name }
101
+ !find_member(crew, name).nil?
94
102
  end
95
103
 
96
104
  # @return [RobotLab::Robot, nil]
97
105
  def find_member(crew, name)
98
- crew.crew.find { |robot| robot.name == name }
106
+ crew.crew.find { |robot| robot.name.to_s.casecmp?(name.to_s) }
107
+ end
108
+
109
+ # @return [Boolean]
110
+ def chief?(crew, name)
111
+ crew.chief&.name.to_s.casecmp?(name.to_s)
99
112
  end
100
113
 
101
114
  # Build the recruit's system prompt (its role) from any assigned skills
@@ -148,17 +161,14 @@ module AIA
148
161
  chief.respond_to?(:local_tools) ? Array(chief.local_tools) : []
149
162
  end
150
163
 
151
- # Hand the recruit the chief's already-connected MCP clients and tools rather
152
- # than opening fresh connections.
164
+ # Hand the recruit the chief's MCP servers. When they are the live
165
+ # RubyLLM::MCP instances aia connected at startup, the recruit shares the
166
+ # chief's connections rather than opening fresh ones.
153
167
  #
154
- # @return [void]
155
- def inherit_mcp(robot, chief)
156
- return unless robot.respond_to?(:inject_mcp!) && chief.respond_to?(:mcp_clients)
157
-
158
- clients = chief.mcp_clients
159
- return if clients.nil? || clients.empty?
160
-
161
- robot.inject_mcp!(clients: clients, tools: Array(chief.mcp_tools))
168
+ # @return [Hash] {mcp: [...]} or {}
169
+ def chief_mcp(chief)
170
+ servers = chief.respond_to?(:mcp_config) ? chief.mcp_config : nil
171
+ servers.is_a?(Array) && servers.any? ? { mcp: servers } : {}
162
172
  end
163
173
  end
164
174
  end
@@ -36,7 +36,7 @@ module AIA
36
36
  #
37
37
  # @param context [HandlerContext] — reads context.prompt
38
38
  # @return [String, nil] formatted debate results, or nil if not applicable
39
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
39
+ # :reek:TooManyStatements -- debate orchestration: per-round async fan-out, convergence check, tracking; stages share round state
40
40
  def handle(context)
41
41
  prompt = context.prompt
42
42
  return nil unless @robot.network?
@@ -55,33 +55,19 @@ module AIA
55
55
  rounds = []
56
56
 
57
57
  MAX_ROUNDS.times do |round|
58
+ round_no = round + 1
58
59
  round_context = build_round_context(prompt, rounds)
59
60
 
60
- round_results = Sync do
61
- barrier = Async::Barrier.new
62
- tasks = robots.map do |robot|
63
- barrier.async do
64
- @ui_presenter.display_info(" Round #{round + 1}: #{robot.name}...")
65
- result = robot.run(round_context, mcp: :inherit, tools: :inherit)
66
- content = extract_content(result)
67
- write_to_memory(round, robot.name, content)
68
- { robot: robot.name, content: content }
69
- rescue => e
70
- FailedResponse.new(robot_name: robot.name, error_message: e.message)
71
- end
72
- end
73
- barrier.wait
74
- tasks.map(&:wait)
75
- end
61
+ round_results = run_debate_round(robots, round_context, round, round_no)
76
62
 
77
- raise DebateError, "All robots failed in round #{round + 1}" if
63
+ raise DebateError, "All robots failed in round #{round_no}" if
78
64
  round_results.all?(FailedResponse)
79
65
 
80
66
  previous = rounds.last
81
67
  rounds << round_results
82
68
 
83
69
  if converged?(round, round_results, previous)
84
- @ui_presenter.display_info(" Converged in round #{round + 1}.")
70
+ @ui_presenter.display_info(" Converged in round #{round_no}.")
85
71
  break
86
72
  end
87
73
  end
@@ -94,10 +80,49 @@ module AIA
94
80
 
95
81
  format_rounds(rounds)
96
82
  end
97
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
98
83
 
99
84
  private
100
85
 
86
+ # Run every robot once against the round context, concurrently, showing
87
+ # each robot's response as soon as it arrives.
88
+ # Returns one entry per robot: a result hash, or FailedResponse on error.
89
+ def run_debate_round(robots, round_context, round, round_no)
90
+ @ui_presenter.display_info(" Round #{round_no}: #{robots.map(&:name).join(' and ')} responding...")
91
+
92
+ Sync do
93
+ barrier = Async::Barrier.new
94
+ tasks = robots.map do |robot|
95
+ barrier.async do
96
+ run_debater(robot, round_context, round).tap { |entry| show_turn(round_no, entry) }
97
+ end
98
+ end
99
+ barrier.wait
100
+ tasks.map(&:wait)
101
+ end
102
+ end
103
+
104
+ # One robot's turn in one round.
105
+ #
106
+ # @return [Hash, FailedResponse] {robot:, content:} or the captured failure
107
+ def run_debater(robot, round_context, round)
108
+ name = robot.name
109
+ result = robot.run(round_context, mcp: :inherit, tools: :inherit)
110
+ content = extract_content(result)
111
+ write_to_memory(round, name, content)
112
+ { robot: name, content: content }
113
+ rescue => e
114
+ FailedResponse.new(robot_name: name, error_message: e.message)
115
+ end
116
+
117
+ # Display one debate turn under a "Round N · Name" heading.
118
+ def show_turn(round_no, entry)
119
+ if entry.is_a?(FailedResponse)
120
+ @ui_presenter.display_robot_turn("Round #{round_no} · #{entry.robot_name}", "[FAILED] #{entry.error_message}")
121
+ else
122
+ @ui_presenter.display_robot_turn("Round #{round_no} · #{entry[:robot]}", entry[:content])
123
+ end
124
+ end
125
+
101
126
  def build_round_context(prompt, rounds)
102
127
  return prompt if rounds.empty?
103
128
 
@@ -27,6 +27,7 @@ module AIA
27
27
  #
28
28
  # @param context [HandlerContext] — reads context.prompt
29
29
  # @return [String, nil] combined results, or nil if not applicable
30
+ # :reek:TooManyStatements -- three-step delegation pipeline (decompose, plan, execute) sharing intermediate results
30
31
  def handle(context)
31
32
  prompt = context.prompt
32
33
  return nil unless @robot.network?
@@ -71,6 +72,7 @@ module AIA
71
72
 
72
73
  private
73
74
 
75
+ # :reek:TooManyStatements -- per-step loop: resolve assignee, announce, execute, record to memory and results
74
76
  def execute_steps(executor, prompt, plan, steps, robots)
75
77
  results = []
76
78
 
@@ -78,13 +80,15 @@ module AIA
78
80
  step_def = steps[i]
79
81
  assignee = robots.values.find { |r| r.name == step_def[:assignee] }
80
82
  assignee ||= robots.values.first
83
+ name = assignee.name
84
+ title = step_def[:title]
81
85
 
82
- @ui_presenter.display_info(" #{assignee.name}: #{step_def[:title]}...")
86
+ @ui_presenter.display_info(" #{name}: #{title}...")
83
87
 
84
88
  content = executor.execute(task, assignee, step_def, prompt, results)
85
89
 
86
- write_to_memory(i, assignee.name, step_def[:title], content)
87
- results << { robot: assignee.name, task: step_def[:title], content: content }
90
+ write_to_memory(i, name, title, content)
91
+ results << { robot: name, task: title, content: content }
88
92
  end
89
93
 
90
94
  results
data/lib/aia/directive.rb CHANGED
@@ -68,6 +68,7 @@ module AIA
68
68
  # Application-level concern: formats help text using DIRECTIVE_PREFIX
69
69
  # and all registered directive subclasses.
70
70
 
71
+ # :reek:TooManyStatements -- sequential terminal report: header, one section per directive category, footer
71
72
  def help
72
73
  puts
73
74
  puts "Available Directives"
@@ -84,14 +85,7 @@ module AIA
84
85
  puts "-" * cat.length
85
86
 
86
87
  klass.directive_descriptions.each do |method_name, description|
87
- aliases = klass.directive_aliases[method_name] || []
88
- alias_text = if aliases.any?
89
- " (aliases: #{aliases.map { |a| "#{DIRECTIVE_PREFIX}#{a}" }.join(', ')})"
90
- else
91
- ""
92
- end
93
-
94
- puts " #{DIRECTIVE_PREFIX}#{method_name}#{alias_text}"
88
+ puts " #{DIRECTIVE_PREFIX}#{method_name}#{alias_text_for(klass, method_name)}"
95
89
  puts " #{description}"
96
90
  puts
97
91
 
@@ -102,6 +96,14 @@ module AIA
102
96
  puts "\nTotal: #{total} directives available"
103
97
  ""
104
98
  end
99
+
100
+ # Format the "(aliases: ...)" suffix for a directive, or "" when it has none.
101
+ def alias_text_for(klass, method_name)
102
+ aliases = klass.directive_aliases[method_name] || []
103
+ return "" if aliases.empty?
104
+
105
+ " (aliases: #{aliases.map { |a| "#{DIRECTIVE_PREFIX}#{a}" }.join(', ')})"
106
+ end
105
107
  end
106
108
 
107
109
  private