aia 2.0.0.0.pre.beta2 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +152 -223
  3. data/README.md +41 -18
  4. data/bin/aia +8 -3
  5. data/lib/aia/aia_completion.bash +2 -3
  6. data/lib/aia/aia_completion.fish +6 -5
  7. data/lib/aia/aia_completion.zsh +2 -3
  8. data/lib/aia/chat_loop.rb +16 -14
  9. data/lib/aia/config/cli_parser.rb +123 -91
  10. data/lib/aia/config/defaults.yml +18 -40
  11. data/lib/aia/config/mcp_parser.rb +30 -36
  12. data/lib/aia/config/model_spec.rb +8 -14
  13. data/lib/aia/config/validator.rb +102 -103
  14. data/lib/aia/config/value_caster.rb +76 -0
  15. data/lib/aia/config.rb +70 -53
  16. data/lib/aia/crew.rb +29 -19
  17. data/lib/aia/debate_handler.rb +27 -10
  18. data/lib/aia/directives/configuration_directives.rb +55 -14
  19. data/lib/aia/directives/context_directives.rb +24 -12
  20. data/lib/aia/directives/execution_directives.rb +18 -23
  21. data/lib/aia/directives/model_directives.rb +41 -104
  22. data/lib/aia/directives/utility_directives.rb +16 -17
  23. data/lib/aia/directives/web_and_file_directives.rb +21 -14
  24. data/lib/aia/fact_asserter.rb +3 -3
  25. data/lib/aia/history_transfer.rb +64 -24
  26. data/lib/aia/logger.rb +14 -46
  27. data/lib/aia/mcp_config_normalizer.rb +27 -14
  28. data/lib/aia/mcp_connection_manager.rb +181 -184
  29. data/lib/aia/mcp_discovery.rb +43 -15
  30. data/lib/aia/mcp_grouper.rb +2 -1
  31. data/lib/aia/mcp_server_config.rb +20 -2
  32. data/lib/aia/mcp_utility.rb +24 -19
  33. data/lib/aia/mention_router.rb +15 -2
  34. data/lib/aia/modality_query.rb +36 -0
  35. data/lib/aia/model_alias_registry.rb +11 -11
  36. data/lib/aia/model_registry.rb +75 -0
  37. data/lib/aia/network_builder.rb +8 -7
  38. data/lib/aia/patches/mcp_stdio_stderr.rb +102 -0
  39. data/lib/aia/patches/ruby_llm_streaming_error.rb +21 -4
  40. data/lib/aia/patches/ruby_llm_tool_param_compat.rb +18 -0
  41. data/lib/aia/pipeline_orchestrator.rb +71 -38
  42. data/lib/aia/prompt_decomposer.rb +1 -1
  43. data/lib/aia/prompt_handler.rb +56 -29
  44. data/lib/aia/provider_registry.rb +105 -0
  45. data/lib/aia/robot_builder.rb +1 -1
  46. data/lib/aia/robot_factory.rb +67 -63
  47. data/lib/aia/robot_sync.rb +79 -0
  48. data/lib/aia/role_catalog.rb +89 -0
  49. data/lib/aia/session.rb +25 -11
  50. data/lib/aia/skill_utils.rb +60 -19
  51. data/lib/aia/spawn_handler.rb +16 -4
  52. data/lib/aia/spawn_spec_parser.rb +6 -7
  53. data/lib/aia/special_mode_handler.rb +28 -25
  54. data/lib/aia/speech.rb +70 -34
  55. data/lib/aia/startup_coordinator.rb +17 -92
  56. data/lib/aia/streaming_runner.rb +10 -2
  57. data/lib/aia/system_prompt_assembler.rb +12 -11
  58. data/lib/aia/task_board.rb +60 -0
  59. data/lib/aia/tool_approver.rb +205 -0
  60. data/lib/aia/tool_filter.rb +1 -10
  61. data/lib/aia/tool_filter_strategy.rb +12 -1
  62. data/lib/aia/tool_introspection.rb +9 -1
  63. data/lib/aia/tool_loader.rb +67 -33
  64. data/lib/aia/tool_utility.rb +6 -5
  65. data/lib/aia/tools/delegate_to_foreman_tool.rb +6 -4
  66. data/lib/aia/tools/recruit_robot_tool.rb +12 -12
  67. data/lib/aia/tools/reskill_robot_tool.rb +7 -7
  68. data/lib/aia/tools/task_board_tool.rb +16 -16
  69. data/lib/aia/trakflow_bridge.rb +14 -8
  70. data/lib/aia/turn_state.rb +31 -8
  71. data/lib/aia/ui_presenter.rb +16 -0
  72. data/lib/aia/utility.rb +6 -24
  73. data/lib/aia/variable_input_collector.rb +0 -3
  74. data/lib/aia/verification_network.rb +9 -10
  75. data/lib/aia/version.rb +1 -9
  76. data/lib/aia.rb +34 -8
  77. metadata +20 -161
  78. data/.better-commits.json +0 -150
  79. data/.config/tocer/configuration.yml +0 -6
  80. data/.envrc +0 -19
  81. data/.loki +0 -11
  82. data/.reek.yml +0 -160
  83. data/.rubocop.yml +0 -116
  84. data/.rubocop_strict.yml +0 -15
  85. data/.version +0 -1
  86. data/COMMITS.md +0 -196
  87. data/IMPLEMENTATION_PLAN.md +0 -506
  88. data/Rakefile +0 -47
  89. data/_typos.toml +0 -10
  90. data/aia.gemspec +0 -92
  91. data/architecture_review.md +0 -314
  92. data/config/aia.yml +0 -13
  93. data/docs/AGENTS.md +0 -40
  94. data/docs/advanced-prompting.md +0 -814
  95. data/docs/assets/images/aia.png +0 -0
  96. data/docs/cli-reference.md +0 -1241
  97. data/docs/configuration.md +0 -747
  98. data/docs/contributing.md +0 -386
  99. data/docs/directives-reference.md +0 -1145
  100. data/docs/examples/index.md +0 -277
  101. data/docs/examples/mcp/index.md +0 -475
  102. data/docs/examples/prompts/analysis/index.md +0 -78
  103. data/docs/examples/prompts/automation/index.md +0 -109
  104. data/docs/examples/prompts/development/index.md +0 -125
  105. data/docs/examples/prompts/index.md +0 -333
  106. data/docs/examples/prompts/learning/index.md +0 -127
  107. data/docs/examples/prompts/writing/index.md +0 -62
  108. data/docs/examples/tools/index.md +0 -282
  109. data/docs/faq.md +0 -578
  110. data/docs/guides/available-models.md +0 -366
  111. data/docs/guides/basic-usage.md +0 -478
  112. data/docs/guides/chat.md +0 -680
  113. data/docs/guides/crew.md +0 -239
  114. data/docs/guides/executable-prompts.md +0 -331
  115. data/docs/guides/first-prompt.md +0 -454
  116. data/docs/guides/getting-started.md +0 -455
  117. data/docs/guides/image-generation.md +0 -507
  118. data/docs/guides/index.md +0 -48
  119. data/docs/guides/local-models.md +0 -306
  120. data/docs/guides/migrate-prompts.md +0 -335
  121. data/docs/guides/models.md +0 -1017
  122. data/docs/guides/shared-tools.md +0 -254
  123. data/docs/guides/tools.md +0 -831
  124. data/docs/index.md +0 -259
  125. data/docs/installation.md +0 -274
  126. data/docs/mcp-integration.md +0 -603
  127. data/docs/prompt_management.md +0 -665
  128. data/docs/security.md +0 -674
  129. data/docs/special_projects_guide.md +0 -386
  130. data/docs/tools-and-mcp-examples.md +0 -1211
  131. data/docs/workflows-and-pipelines.md +0 -636
  132. data/examples/.gitignore +0 -2
  133. data/examples/00_setup_aia.sh +0 -111
  134. data/examples/01_basic_usage.sh +0 -23
  135. data/examples/02_frontmatter.sh +0 -33
  136. data/examples/03_shell_integration.sh +0 -55
  137. data/examples/04_erb_templating.sh +0 -56
  138. data/examples/05_shell_then_erb.sh +0 -38
  139. data/examples/06_prompt_chaining.sh +0 -59
  140. data/examples/07_pipeline.sh +0 -46
  141. data/examples/08_context_files.sh +0 -43
  142. data/examples/09_roles.sh +0 -67
  143. data/examples/10_stdin_piping.sh +0 -49
  144. data/examples/11_multi_model.sh +0 -65
  145. data/examples/12_token_usage.sh +0 -52
  146. data/examples/13_cost_tracking.sh +0 -68
  147. data/examples/14_output_file.sh +0 -91
  148. data/examples/15_parameters.sh +0 -68
  149. data/examples/16_directives.sh +0 -113
  150. data/examples/17_require_and_conditionals.sh +0 -68
  151. data/examples/18_tools.sh +0 -61
  152. data/examples/19_local_tools.sh +0 -34
  153. data/examples/20_mcp_servers.sh +0 -102
  154. data/examples/21_executable_prompts.sh +0 -78
  155. data/examples/22_chat_mode.sh +0 -217
  156. data/examples/23_verify.sh +0 -139
  157. data/examples/24_decompose.sh +0 -139
  158. data/examples/25_spawn.sh +0 -139
  159. data/examples/26_debate.sh +0 -97
  160. data/examples/27_mention_routing.sh +0 -157
  161. data/examples/28_model_switching.sh +0 -106
  162. data/examples/29_agent_harness.sh +0 -177
  163. data/examples/README.md +0 -321
  164. data/examples/advanced_multi_robot_capabilities_without_examples.md +0 -106
  165. data/examples/aia_config.yml +0 -22
  166. data/examples/aia_config_orchestrator.yml +0 -45
  167. data/examples/aia_config_with_mcp.yml +0 -21
  168. data/examples/common.sh +0 -39
  169. data/examples/context/project_goals.md +0 -6
  170. data/examples/context/tech_stack.md +0 -7
  171. data/examples/directives/timestamp_directive.rb +0 -22
  172. data/examples/mcp/filesystem.json +0 -9
  173. data/examples/prompts_dir/analyze.md +0 -2
  174. data/examples/prompts_dir/brainstorm.md +0 -2
  175. data/examples/prompts_dir/conditional.md +0 -17
  176. data/examples/prompts_dir/creative.md +0 -4
  177. data/examples/prompts_dir/erbinfo.md +0 -5
  178. data/examples/prompts_dir/erbinfo_raw.md +0 -8
  179. data/examples/prompts_dir/evaluate.md +0 -2
  180. data/examples/prompts_dir/explain_joke.md +0 -1
  181. data/examples/prompts_dir/explain_recursion.md +0 -1
  182. data/examples/prompts_dir/fun_fact +0 -3
  183. data/examples/prompts_dir/greeting.md +0 -8
  184. data/examples/prompts_dir/greeting_required.md +0 -7
  185. data/examples/prompts_dir/hello.md +0 -1
  186. data/examples/prompts_dir/includes/ruby_facts.md +0 -4
  187. data/examples/prompts_dir/limerick.md +0 -1
  188. data/examples/prompts_dir/list_with_mcp.md +0 -3
  189. data/examples/prompts_dir/pick_best.md +0 -2
  190. data/examples/prompts_dir/project_summary +0 -12
  191. data/examples/prompts_dir/quiz_with_include.md +0 -6
  192. data/examples/prompts_dir/require_demo.md +0 -5
  193. data/examples/prompts_dir/roles/formal.md +0 -3
  194. data/examples/prompts_dir/roles/orchestrator.md +0 -21
  195. data/examples/prompts_dir/roles/pirate.md +0 -3
  196. data/examples/prompts_dir/shell_then_erb.md +0 -6
  197. data/examples/prompts_dir/sort_compare.md +0 -2
  198. data/examples/prompts_dir/summarize_context.md +0 -2
  199. data/examples/prompts_dir/sysinfo.md +0 -5
  200. data/examples/prompts_dir/sysinfo_raw.md +0 -8
  201. data/examples/prompts_dir/tagline.md +0 -1
  202. data/examples/prompts_dir/tell_joke.md +0 -1
  203. data/examples/prompts_dir/tell_joke_with_next.md +0 -4
  204. data/examples/prompts_dir/use_local_tool.md +0 -8
  205. data/examples/prompts_dir/use_tools.md +0 -8
  206. data/examples/prompts_dir/weather.md +0 -2
  207. data/examples/prompts_dir/whats_new.md +0 -2
  208. data/examples/prompts_dir/with_timestamp.md +0 -5
  209. data/examples/requirements/sinatra_taskflow_app.md +0 -139
  210. data/examples/rules/01_classify_ruby.rb +0 -16
  211. data/examples/rules/02_prefer_claude_for_code.rb +0 -19
  212. data/examples/rules/03_gate_prompt_length.rb +0 -19
  213. data/examples/rules/04_tool_selection.rb +0 -41
  214. data/examples/rules/README.md +0 -30
  215. data/examples/run_all.sh +0 -294
  216. data/examples/tools/word_count_tool.rb +0 -30
  217. data/lib/AGENTS.md +0 -57
  218. data/lib/aia/model_switch_handler.rb +0 -100
  219. data/mcp_servers/README.md +0 -110
  220. data/mcp_servers/apple-mcp.json +0 -8
  221. data/mcp_servers/filesystem.json +0 -9
  222. data/mcp_servers/mcp_server_chart.json +0 -11
  223. data/mcp_servers/playwright_one.json +0 -8
  224. data/mcp_servers/playwright_server_definition.json +0 -9
  225. data/mcp_servers/playwright_two.json +0 -8
  226. data/mcp_servers/tavily_mcp_server.json +0 -8
  227. data/mkdocs.yml +0 -169
@@ -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,38 +256,53 @@ 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-next 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
284
 
291
285
  private
292
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
+
293
306
  # Load a config file that REPLACES the user's personal config.
294
307
  # :reek:TooManyStatements -- single case dispatch mapping YAML keys to typed config setters; one branch per key family
295
308
  # :reek:DuplicateMethodCall -- Array(value) sits in mutually exclusive case branches; hoisting it would coerce hash-section values too
@@ -310,8 +323,6 @@ module AIA
310
323
 
311
324
  config_hash = raw.key?(:defaults) ? (raw[:defaults] || {}) : raw
312
325
 
313
- paths[:extra_config_file] = path
314
-
315
326
  config_hash.each do |key, value|
316
327
  case key
317
328
  when :models
@@ -320,8 +331,9 @@ module AIA
320
331
  send("#{key}=", Array(value)) if respond_to?("#{key}=")
321
332
  when :mcp_servers
322
333
  self.mcp_servers = Array(value)
323
- when :service, :llm, :prompts, :roles, :skills, :output, :audio, :image, :embedding,
324
- :tools, :flags, :registry, :paths, :logger, :rules, :concurrency
334
+ when :model_switch_history, :model_aliases
335
+ send("#{key}=", value)
336
+ when *SECTIONS
325
337
  section = send(key)
326
338
  if section.is_a?(MywayConfig::ConfigSection) && value.is_a?(Hash)
327
339
  merge_into_section(section, value)
@@ -370,6 +382,16 @@ module AIA
370
382
  end
371
383
  end
372
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
+
373
395
  def apply_models_env_var
374
396
  models_env = ENV.fetch('AIA_MODEL', nil)
375
397
  return if models_env.nil? || models_env.empty?
@@ -388,15 +410,10 @@ module AIA
388
410
 
389
411
  def expand_paths
390
412
  expand_path_on(paths, :aia_dir)
391
- expand_path_on(paths, :config_file)
392
413
  expand_path_on(paths, :plugins_dir)
393
414
  expand_path_on(prompts, :dir)
394
- expand_path_on(prompts, :roles_dir)
395
- expand_path_on(roles, :dir)
396
415
  expand_path_on(skills, :dir)
397
- expand_path_on(tools, :dir)
398
416
  expand_path_on(output, :history_file)
399
- expand_path_on(rules, :dir)
400
417
  end
401
418
 
402
419
  def expand_path_on(obj, method_name)
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
@@ -83,22 +83,17 @@ module AIA
83
83
 
84
84
  private
85
85
 
86
- # Run every robot once against the round context, concurrently.
86
+ # Run every robot once against the round context, concurrently, showing
87
+ # each robot's response as soon as it arrives.
87
88
  # Returns one entry per robot: a result hash, or FailedResponse on error.
88
- # :reek:TooManyStatements -- async fan-out with per-robot progress, memory write, and failure capture
89
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
+
90
92
  Sync do
91
93
  barrier = Async::Barrier.new
92
94
  tasks = robots.map do |robot|
93
95
  barrier.async do
94
- name = robot.name
95
- @ui_presenter.display_info(" Round #{round_no}: #{name}...")
96
- result = robot.run(round_context, mcp: :inherit, tools: :inherit)
97
- content = extract_content(result)
98
- write_to_memory(round, name, content)
99
- { robot: name, content: content }
100
- rescue => e
101
- FailedResponse.new(robot_name: name, error_message: e.message)
96
+ run_debater(robot, round_context, round).tap { |entry| show_turn(round_no, entry) }
102
97
  end
103
98
  end
104
99
  barrier.wait
@@ -106,6 +101,28 @@ module AIA
106
101
  end
107
102
  end
108
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
+
109
126
  def build_round_context(prompt, rounds)
110
127
  return prompt if rounds.empty?
111
128
 
@@ -27,9 +27,11 @@ module AIA
27
27
  leaf_key = config_item.to_s.split('.').last
28
28
 
29
29
  boolean = AIA.respond_to?("#{leaf_key}?")
30
- if boolean
31
- new_value = %w[true t yes y on 1 yea yeah yep yup].include?(new_value.downcase)
32
- end
30
+ new_value = if boolean
31
+ %w[true t yes y on 1 yea yeah yep yup].include?(new_value.downcase)
32
+ else
33
+ typed_config_value(config_item, new_value)
34
+ end
33
35
 
34
36
  if write_config_value(config_item, new_value)
35
37
  AIA::LoggerManager.reconfigure_levels!
@@ -46,17 +48,7 @@ module AIA
46
48
  def model(args, context_manager = nil)
47
49
  cfg = AIA.config
48
50
 
49
- if args.empty?
50
- puts
51
- models = cfg.models
52
- models.size == 1 ? show_single_model(models) : show_multi_model(models)
53
- puts
54
- else
55
- model_names = args.join(' ').split(',').map(&:strip).reject(&:empty?)
56
- cfg.models = AIA::Config::TO_MODEL_SPECS.call(model_names)
57
- AIA.client = RobotFactory.rebuild(cfg)
58
- end
59
-
51
+ args.empty? ? show_models(cfg.models) : switch_models(cfg, args)
60
52
  ''
61
53
  end
62
54
 
@@ -201,6 +193,55 @@ module AIA
201
193
  puts " Details: Unable to fetch (#{e.class.name}: #{e.message})"
202
194
  end
203
195
 
196
+ # Convert a typed /config value to the type of the key's default
197
+ # (numbers, booleans, lists). Unknown keys keep the string.
198
+ def typed_config_value(config_item, raw)
199
+ path = config_key_path(config_item)
200
+ return raw unless path
201
+
202
+ schema_default = AIA::Config.schema.dig(*path)
203
+ AIA::ValueCaster.cast(raw, AIA::ValueCaster.default_for(path.join('.'), schema_default))
204
+ end
205
+
206
+ # The defaults.yml path for a /config key: "llm.temperature", a flat CLI
207
+ # key such as "temperature", or a top-level key. nil when unknown.
208
+ def config_key_path(config_item)
209
+ key = config_item.to_s
210
+ return key.split('.').map(&:to_sym) if key.include?('.')
211
+
212
+ sym = key.to_sym
213
+ AIA::Config::CLI_TO_NESTED_MAP[sym] || (AIA::Config.schema.key?(sym) ? [sym] : nil)
214
+ end
215
+
216
+ # Print the current model, or every model of a multi-model session.
217
+ def show_models(models)
218
+ puts
219
+ models.size == 1 ? show_single_model(models) : show_multi_model(models)
220
+ puts
221
+ end
222
+
223
+ # Switch to the comma-separated models in +args+ (aliases allowed),
224
+ # carrying the conversation over per model_switch_history.
225
+ def switch_models(cfg, args)
226
+ model_names = args.join(' ').split(',').map(&:strip).reject(&:empty?)
227
+ model_names = resolve_model_aliases(model_names, cfg.model_aliases)
228
+ cfg.models = AIA::Config::TO_MODEL_SPECS.call(model_names)
229
+ mode = HistoryTransfer.mode_for(cfg)
230
+ puts "Switching to #{model_names.join(', ')} (conversation: #{mode})..." unless mode == :clean
231
+ AIA.client = RobotFactory.rebuild(cfg, history_mode: mode)
232
+ end
233
+
234
+ # Replace names that exactly match a model alias (built in, or from the
235
+ # model_aliases config key), keeping any =ROLE suffix.
236
+ def resolve_model_aliases(model_names, custom_aliases)
237
+ registry = AIA::ModelAliasRegistry.new(custom_aliases || {})
238
+ model_names.map do |spec|
239
+ name, role = spec.split('=', 2)
240
+ name = registry.resolve(name) if registry.known?(name)
241
+ role ? "#{name}=#{role}" : name
242
+ end
243
+ end
244
+
204
245
  # Apply a config value by key, supporting three forms:
205
246
  # flat CLI key — "debug" → CLI_TO_NESTED_MAP routing
206
247
  # dot-notation — "flags.debug" → navigate section.subkey
@@ -201,14 +201,18 @@ module AIA
201
201
 
202
202
  private
203
203
 
204
- # In v2, AIA.client is a RobotLab::Robot which wraps a RubyLLM::Chat.
205
- # Returns a hash of { name => Robot } for checkpoint operations.
204
+ # In v2, AIA.client is a RobotLab::Robot (single-model chat) or a
205
+ # RobotLab::Network (crew / multi-model session). Returns a hash of
206
+ # { name => Robot } either way, so clear/checkpoint/restore/review act
207
+ # on every member robot's chat.
206
208
  def get_robots
207
- robot = AIA.client
208
- return nil unless robot
209
+ client = AIA.client
210
+ return nil unless client
209
211
 
210
- name = robot.respond_to?(:name) ? robot.name : "default"
211
- { name => robot }
212
+ return client.robots if client.respond_to?(:network?) && client.network?
213
+
214
+ name = client.respond_to?(:name) ? client.name : "default"
215
+ { name => client }
212
216
  end
213
217
 
214
218
  # Return { name => RubyLLM::Chat } for operations that need direct chat access.
@@ -221,15 +225,23 @@ module AIA
221
225
  end
222
226
 
223
227
  def deep_copy_message(msg)
224
- RubyLLM::Message.new(
228
+ attrs = {
225
229
  role: msg.role,
226
230
  content: msg.content,
227
231
  tool_calls: msg.tool_calls&.transform_values { |tc| tc.dup rescue tc },
228
- tool_call_id: msg.tool_call_id,
229
- input_tokens: msg.input_tokens,
230
- output_tokens: msg.output_tokens,
231
- model_id: msg.model_id
232
- )
232
+ tool_call_id: msg.tool_call_id
233
+ }
234
+
235
+ if msg.respond_to?(:tokens) # ruby_llm >= 2.0 moved token counts into #tokens
236
+ attrs[:tokens] = msg.tokens
237
+ attrs[:model] = msg.model
238
+ else # ruby_llm 1.x exposes them directly on the message
239
+ attrs[:input_tokens] = msg.input_tokens
240
+ attrs[:output_tokens] = msg.output_tokens
241
+ attrs[:model_id] = msg.model_id
242
+ end
243
+
244
+ RubyLLM::Message.new(**attrs)
233
245
  end
234
246
 
235
247
  def format_message_content(msg)