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
@@ -5,16 +5,18 @@ module AIA
5
5
  state_setting! :model
6
6
 
7
7
  desc "View or set configuration values"
8
+ # :reek:TooManyStatements -- view/set dispatch on arg count, coercing booleans and dot-notation keys before writing
8
9
  def config(args = [], context_manager = nil)
9
10
  args = Array(args)
11
+ cfg = AIA.config
10
12
 
11
13
  if args.empty?
12
- ap AIA.config.to_h
14
+ ap cfg.to_h
13
15
  elsif args.length == 1
14
16
  config_item = args.first
15
17
  local_cfg = {}
16
- local_cfg[config_item] = if AIA.config.respond_to?(config_item)
17
- AIA.config.send(config_item)
18
+ local_cfg[config_item] = if cfg.respond_to?(config_item)
19
+ cfg.send(config_item)
18
20
  end
19
21
  ap local_cfg
20
22
  else
@@ -25,9 +27,11 @@ module AIA
25
27
  leaf_key = config_item.to_s.split('.').last
26
28
 
27
29
  boolean = AIA.respond_to?("#{leaf_key}?")
28
- if boolean
29
- new_value = %w[true t yes y on 1 yea yeah yep yup].include?(new_value.downcase)
30
- 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
31
35
 
32
36
  if write_config_value(config_item, new_value)
33
37
  AIA::LoggerManager.reconfigure_levels!
@@ -41,66 +45,12 @@ module AIA
41
45
  alias cfg config
42
46
 
43
47
  desc "View or change the AI model"
44
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
45
48
  def model(args, context_manager = nil)
46
- if args.empty?
47
- puts
48
- models = AIA.config.models
49
-
50
- if models.size == 1
51
- puts "Current Model:"
52
- puts "=============="
53
- model_name = models.first.respond_to?(:name) ? models.first.name : models.first.to_s
54
- begin
55
- model_info = RubyLLM::Models.find(model_name)
56
- puts model_info.to_h.pretty_inspect if model_info
57
- rescue StandardError
58
- puts " #{model_name}"
59
- end
60
- else
61
- puts "Multi-Model Configuration:"
62
- puts "=========================="
63
- puts "Model count: #{models.size}"
64
- first_model = models.first.respond_to?(:name) ? models.first.name : models.first.to_s
65
- puts "Primary model: #{first_model} (used for consensus when --consensus flag is enabled)"
66
- consensus = AIA.config.flags.consensus
67
- puts "Consensus mode: #{consensus.nil? ? 'auto-detect (disabled by default)' : consensus}"
68
- puts
69
- puts "Model Details:"
70
- puts "-" * 50
71
-
72
- models.each_with_index do |model_spec, index|
73
- model_name = model_spec.respond_to?(:name) ? model_spec.name : model_spec.to_s
74
- puts "#{index + 1}. #{model_name}#{' (primary)' if index.zero?}"
75
-
76
- begin
77
- model_info = RubyLLM::Models.find(model_name)
78
- if model_info
79
- puts " Provider: #{model_info.provider || 'Unknown'}"
80
- puts " Context window: #{model_info.context_window || 'Unknown'}"
81
- puts " Input cost: $#{model_info.input_cost || 'Unknown'}"
82
- puts " Output cost: $#{model_info.output_cost || 'Unknown'}"
83
- puts " Mode: #{model_info.modalities || 'Unknown'}"
84
- puts " Capabilities: #{(model_info.capabilities || []).join(', ')}" if model_info.capabilities&.any?
85
- else
86
- puts " Details: Model not found in registry"
87
- end
88
- rescue StandardError => e
89
- puts " Details: Unable to fetch (#{e.class.name}: #{e.message})"
90
- end
91
- puts
92
- end
93
- end
94
- puts
95
- else
96
- model_names = args.join(' ').split(',').map(&:strip).reject(&:empty?)
97
- AIA.config.models = AIA::Config::TO_MODEL_SPECS.call(model_names)
98
- AIA.client = RobotFactory.rebuild(AIA.config)
99
- end
49
+ cfg = AIA.config
100
50
 
51
+ args.empty? ? show_models(cfg.models) : switch_models(cfg, args)
101
52
  ''
102
53
  end
103
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
104
54
 
105
55
  desc "Set the temperature parameter for AI responses"
106
56
  def temperature(args, context_manager = nil)
@@ -115,7 +65,7 @@ module AIA
115
65
  alias topp top_p
116
66
 
117
67
  desc "Dump session cost/token metrics as CSV"
118
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
68
+ # :reek:TooManyStatements -- CSV assembly: guards, header, rows, totals, print, optional file append
119
69
  def cost(args = [], context_manager = nil)
120
70
  tracker = AIA.session_tracker
121
71
  unless tracker
@@ -133,63 +83,164 @@ module AIA
133
83
 
134
84
  header = %w[model input_tokens output_tokens total_tokens cost elapsed]
135
85
  header << 'similarity' if has_similarity
136
- lines = [header.join(',')]
137
-
138
- turns.each do |turn|
139
- input_t = turn[:input_tokens] || 0
140
- output_t = turn[:output_tokens] || 0
141
- total_t = input_t + output_t
142
- cost_val = turn[:cost] || 0.0
143
- elapsed = turn[:elapsed] || 0
144
-
145
- row = [
146
- turn[:model],
147
- input_t,
148
- output_t,
149
- total_t,
150
- "$#{'%.5f' % cost_val}",
151
- "%.1fs" % elapsed
152
- ]
153
-
154
- if has_similarity
155
- sim = turn[:similarity]
156
- row << (sim.nil? ? 'ref' : "%.1f%%" % (sim * 100))
157
- end
86
+ lines = [header.join(',')]
87
+ turns.each { |turn| lines << cost_row(turn, has_similarity).join(',') }
88
+ lines << cost_totals_row(turns, has_similarity).join(',')
158
89
 
159
- lines << row.join(',')
90
+ csv = lines.join("\n")
91
+ puts
92
+ puts csv
93
+ puts
94
+
95
+ out_file = AIA.config.output&.file
96
+ File.open(out_file, 'a') { |f| f.puts csv } if out_file
97
+
98
+ ''
99
+ end
100
+
101
+ private
102
+
103
+ # One CSV row for a single recorded turn.
104
+ def cost_row(turn, has_similarity)
105
+ input_t = turn[:input_tokens] || 0
106
+ output_t = turn[:output_tokens] || 0
107
+
108
+ row = [
109
+ turn[:model],
110
+ input_t,
111
+ output_t,
112
+ input_t + output_t,
113
+ "$#{'%.5f' % (turn[:cost] || 0.0)}",
114
+ "%.1fs" % (turn[:elapsed] || 0)
115
+ ]
116
+
117
+ if has_similarity
118
+ sim = turn[:similarity]
119
+ row << (sim.nil? ? 'ref' : "%.1f%%" % (sim * 100))
160
120
  end
121
+ row
122
+ end
161
123
 
162
- # Totals
163
- total_input = turns.sum { |t| t[:input_tokens] || 0 }
164
- total_output = turns.sum { |t| t[:output_tokens] || 0 }
165
- total_tokens = total_input + total_output
166
- total_cost = turns.sum { |t| t[:cost] || 0.0 }
167
- max_elapsed = turns.map { |t| t[:elapsed] || 0 }.max
124
+ # The TOTAL summary row across all turns.
125
+ # :reek:DuplicateMethodCall -- each turns.sum aggregates a different field; there is no shared value to hoist
126
+ def cost_totals_row(turns, has_similarity)
127
+ total_input = turns.sum { |t| t[:input_tokens] || 0 }
128
+ total_output = turns.sum { |t| t[:output_tokens] || 0 }
129
+ total_cost = turns.sum { |t| t[:cost] || 0.0 }
130
+ max_elapsed = turns.map { |t| t[:elapsed] || 0 }.max
168
131
 
169
132
  totals = [
170
133
  'TOTAL',
171
134
  total_input,
172
135
  total_output,
173
- total_tokens,
136
+ total_input + total_output,
174
137
  "$#{'%.5f' % total_cost}",
175
138
  "%.1fs" % max_elapsed
176
139
  ]
177
140
  totals << '' if has_similarity
178
- lines << totals.join(',')
141
+ totals
142
+ end
179
143
 
180
- csv = lines.join("\n")
181
- puts
182
- puts csv
144
+ # Format a model spec's display name whether it is a ModelSpec or a bare string.
145
+ def model_display_name(spec)
146
+ spec.respond_to?(:name) ? spec.name : spec.to_s
147
+ end
148
+
149
+ def show_single_model(models)
150
+ puts "Current Model:"
151
+ puts "=============="
152
+ model_name = model_display_name(models.first)
153
+ begin
154
+ model_info = RubyLLM::Models.find(model_name)
155
+ puts model_info.to_h.pretty_inspect if model_info
156
+ rescue StandardError
157
+ puts " #{model_name}"
158
+ end
159
+ end
160
+
161
+ # :reek:TooManyStatements -- sequential terminal report: summary lines then a details block per model
162
+ def show_multi_model(models)
163
+ puts "Multi-Model Configuration:"
164
+ puts "=========================="
165
+ puts "Model count: #{models.size}"
166
+ puts "Primary model: #{model_display_name(models.first)} (used for consensus when --consensus flag is enabled)"
167
+ consensus = AIA.config.flags.consensus
168
+ puts "Consensus mode: #{consensus.nil? ? 'auto-detect (disabled by default)' : consensus}"
183
169
  puts
170
+ puts "Model Details:"
171
+ puts "-" * 50
184
172
 
185
- out_file = AIA.config.output&.file
186
- File.open(out_file, 'a') { |f| f.puts csv } if out_file
173
+ models.each_with_index do |model_spec, index|
174
+ puts "#{index + 1}. #{model_display_name(model_spec)}#{' (primary)' if index.zero?}"
175
+ show_model_details(model_display_name(model_spec))
176
+ puts
177
+ end
178
+ end
187
179
 
188
- ''
180
+ def show_model_details(model_name)
181
+ model_info = RubyLLM::Models.find(model_name)
182
+ if model_info
183
+ puts " Provider: #{model_info.provider || 'Unknown'}"
184
+ puts " Context window: #{model_info.context_window || 'Unknown'}"
185
+ puts " Input cost: $#{model_info.input_cost || 'Unknown'}"
186
+ puts " Output cost: $#{model_info.output_cost || 'Unknown'}"
187
+ puts " Mode: #{model_info.modalities || 'Unknown'}"
188
+ puts " Capabilities: #{(model_info.capabilities || []).join(', ')}" if model_info.capabilities&.any?
189
+ else
190
+ puts " Details: Model not found in registry"
191
+ end
192
+ rescue StandardError => e
193
+ puts " Details: Unable to fetch (#{e.class.name}: #{e.message})"
189
194
  end
190
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
191
195
 
192
- private
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
193
244
 
194
245
  # Apply a config value by key, supporting three forms:
195
246
  # flat CLI key — "debug" → CLI_TO_NESTED_MAP routing
@@ -197,13 +248,15 @@ module AIA
197
248
  # direct setter — "log_level_override" → AIA.config.<key>=
198
249
  #
199
250
  # Returns true if the value was set, false if the key was unknown.
251
+ # :reek:TooManyStatements -- three key-addressing forms (dot-notation walk, CLI map, direct setter) tried in order
200
252
  def write_config_value(config_item, new_value) # rubocop:disable Naming/PredicateMethod
201
253
  key_str = config_item.to_s
254
+ cfg = AIA.config
202
255
 
203
256
  # Dot-notation: walk the config object by path segments
204
257
  if key_str.include?('.')
205
258
  parts = key_str.split('.')
206
- obj = AIA.config
259
+ obj = cfg
207
260
  parents = parts[0..-2]
208
261
  leaf = parts.last
209
262
 
@@ -222,15 +275,15 @@ module AIA
222
275
 
223
276
  # Flat CLI key via CLI_TO_NESTED_MAP (e.g. "debug" → flags.debug)
224
277
  if AIA::Config::CLI_TO_NESTED_MAP.key?(key_str.to_sym) &&
225
- AIA.config.respond_to?(:apply_overrides)
226
- AIA.config.apply_overrides({ key_str.to_sym => new_value })
278
+ cfg.respond_to?(:apply_overrides)
279
+ cfg.apply_overrides({ key_str.to_sym => new_value })
227
280
  maybe_clear_log_override(key_str, new_value)
228
281
  return true
229
282
  end
230
283
 
231
284
  # Direct setter on the config object (e.g. "log_level_override")
232
- if AIA.config.respond_to?("#{key_str}=")
233
- AIA.config.send("#{key_str}=", new_value)
285
+ if cfg.respond_to?("#{key_str}=")
286
+ cfg.send("#{key_str}=", new_value)
234
287
  return true
235
288
  end
236
289
 
@@ -241,9 +294,11 @@ module AIA
241
294
  # drops back to its configured level rather than staying at DEBUG.
242
295
  def maybe_clear_log_override(key, value)
243
296
  return unless key.to_s == 'debug' && value == false
244
- return unless AIA.config.respond_to?(:log_level_override=)
245
297
 
246
- AIA.config.log_level_override = nil if AIA.config.log_level_override.to_s == 'debug'
298
+ cfg = AIA.config
299
+ return unless cfg.respond_to?(:log_level_override=)
300
+
301
+ cfg.log_level_override = nil if cfg.log_level_override.to_s == 'debug'
247
302
  end
248
303
  end
249
304
  end
@@ -21,6 +21,7 @@ module AIA
21
21
  end
22
22
 
23
23
  desc "Create a named checkpoint of the current context"
24
+ # :reek:TooManyStatements -- one snapshot build: name resolution, deep copy of every chat message list, store entry, feedback
24
25
  def checkpoint(args, _unused = nil)
25
26
  name = args.empty? ? nil : args.join(' ').strip
26
27
 
@@ -50,6 +51,7 @@ module AIA
50
51
  alias cp checkpoint
51
52
 
52
53
  desc "Restore context to a previous checkpoint"
54
+ # :reek:TooManyStatements -- restore flow: name resolution, validation, per-chat message replacement, user feedback
53
55
  def restore(args, _unused = nil)
54
56
  name = args.empty? ? nil : args.join(' ').strip
55
57
 
@@ -107,44 +109,23 @@ module AIA
107
109
  end
108
110
 
109
111
  desc "Display the current conversation context with checkpoint markers"
110
- # rubocop:disable Metrics/AbcSize
111
112
  def review(args, _unused = nil)
112
113
  chats = get_chats
113
114
  return "Error: No active chat sessions found." if chats.nil? || chats.empty?
114
115
 
115
- first_chat = chats.values.first
116
- messages = first_chat&.messages || []
117
-
118
- puts "\n=== Chat Context (RubyLLM) ==="
119
- puts "Total messages: #{messages.size}"
120
- puts "Models: #{chats.keys.join(', ')}"
121
- puts "Checkpoints: #{checkpoint_names.join(', ')}" if checkpoint_names.any?
122
- puts
116
+ messages = chats.values.first&.messages || []
117
+ print_review_header(chats, messages.size)
123
118
 
124
119
  positions = checkpoint_positions
125
-
126
120
  messages.each_with_index do |msg, index|
127
- if positions[index]
128
- puts "📍 [Checkpoint: #{positions[index].join(', ')}]"
129
- puts "-" * 40
130
- end
131
-
132
- role = msg.role.to_s.capitalize
133
- content = format_message_content(msg)
134
-
135
- puts "#{index + 1}. [#{role}]: #{content}"
136
- puts
137
- end
138
-
139
- if positions[messages.size]
140
- puts "📍 [Checkpoint: #{positions[messages.size].join(', ')}]"
141
- puts "-" * 40
121
+ print_checkpoint_marker(positions[index])
122
+ print_review_message(msg, index)
142
123
  end
124
+ print_checkpoint_marker(positions[messages.size])
143
125
 
144
126
  puts "=== End of Context ==="
145
127
  ""
146
128
  end
147
- # rubocop:enable Metrics/AbcSize
148
129
  alias context review
149
130
 
150
131
  desc "List all available checkpoints"
@@ -157,9 +138,10 @@ module AIA
157
138
  puts "\n=== Available Checkpoints ==="
158
139
  @checkpoint_store.each do |name, data|
159
140
  created = data[:created_at]&.strftime('%H:%M:%S') || 'unknown'
141
+ preview = data[:topic_preview]
160
142
  puts " #{name}: position #{data[:position]}, created #{created}"
161
- if data[:topic_preview] && !data[:topic_preview].empty?
162
- puts " → \"#{data[:topic_preview]}\""
143
+ if preview && !preview.empty?
144
+ puts " → \"#{preview}\""
163
145
  end
164
146
  end
165
147
  puts "=== End of Checkpoints ==="
@@ -173,6 +155,27 @@ module AIA
173
155
  @checkpoint_store.keys
174
156
  end
175
157
 
158
+ def print_review_header(chats, total)
159
+ puts "\n=== Chat Context (RubyLLM) ==="
160
+ puts "Total messages: #{total}"
161
+ puts "Models: #{chats.keys.join(', ')}"
162
+ puts "Checkpoints: #{checkpoint_names.join(', ')}" if checkpoint_names.any?
163
+ puts
164
+ end
165
+
166
+ # Print the marker block when checkpoint names exist at this position.
167
+ def print_checkpoint_marker(names)
168
+ return unless names
169
+
170
+ puts "📍 [Checkpoint: #{names.join(', ')}]"
171
+ puts "-" * 40
172
+ end
173
+
174
+ def print_review_message(msg, index)
175
+ puts "#{index + 1}. [#{msg.role.to_s.capitalize}]: #{format_message_content(msg)}"
176
+ puts
177
+ end
178
+
176
179
  def checkpoint_positions
177
180
  positions = {}
178
181
  @checkpoint_store.each do |name, data|
@@ -198,14 +201,18 @@ module AIA
198
201
 
199
202
  private
200
203
 
201
- # In v2, AIA.client is a RobotLab::Robot which wraps a RubyLLM::Chat.
202
- # 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.
203
208
  def get_robots
204
- robot = AIA.client
205
- return nil unless robot
209
+ client = AIA.client
210
+ return nil unless client
206
211
 
207
- name = robot.respond_to?(:name) ? robot.name : "default"
208
- { 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 }
209
216
  end
210
217
 
211
218
  # Return { name => RubyLLM::Chat } for operations that need direct chat access.
@@ -218,15 +225,23 @@ module AIA
218
225
  end
219
226
 
220
227
  def deep_copy_message(msg)
221
- RubyLLM::Message.new(
228
+ attrs = {
222
229
  role: msg.role,
223
230
  content: msg.content,
224
231
  tool_calls: msg.tool_calls&.transform_values { |tc| tc.dup rescue tc },
225
- tool_call_id: msg.tool_call_id,
226
- input_tokens: msg.input_tokens,
227
- output_tokens: msg.output_tokens,
228
- model_id: msg.model_id
229
- )
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)
230
245
  end
231
246
 
232
247
  def format_message_content(msg)
@@ -13,9 +13,10 @@ module AIA
13
13
  desc "Execute Ruby code (requires allow_ruby_eval: true in config)"
14
14
  def ruby(args, context_manager = nil)
15
15
  unless AIA.config.flags.allow_ruby_eval
16
- return "ERROR: /ruby is disabled. Set `allow_ruby_eval: true` in " \
17
- "~/.aia/config.yml or pass --allow-ruby-eval to enable it. " \
18
- "Note: this executes arbitrary Ruby with full process privileges."
16
+ puts "ERROR: /ruby is disabled. Set `flags: { allow_ruby_eval: true }` in " \
17
+ "~/.config/aia/aia.yml or pass --allow-ruby-eval to enable it. " \
18
+ "Note: this executes arbitrary Ruby with full process privileges."
19
+ return ""
19
20
  end
20
21
 
21
22
  ruby_code = args.join(' ')
@@ -34,45 +35,46 @@ module AIA
34
35
 
35
36
  desc "Use text-to-speech to speak the text"
36
37
  def say(args, context_manager = nil)
37
- audio = AIA.config.audio
38
- env = {}
39
- env['SPEECH_MODEL'] = audio.speech_model if audio.speech_model
40
- if audio.voice && !audio.voice.strip.empty?
41
- system(env, 'say', '-v', audio.voice, *args)
42
- else
43
- system(env, 'say', *args)
38
+ # Without text, `say` reads stdin and speaks every line the user types
39
+ # next — hijacking the chat session — so never invoke it bare.
40
+ text = Array(args).join(' ').strip
41
+ if text.empty?
42
+ puts "Usage: /say TEXT"
43
+ return nil
44
44
  end
45
+
46
+ Speech.speak_text(text)
45
47
  ""
46
48
  end
47
49
 
48
50
  desc "Execute next prompt with concurrent MCP server access"
49
51
  def concurrent(args, context_manager = nil)
50
- AIA.turn_state.force_concurrent_mcp = true
52
+ AIA.turn_state.request(:concurrent_mcp)
51
53
  "Concurrent MCP mode enabled for next prompt."
52
54
  end
53
55
  alias conc concurrent
54
56
 
55
57
  desc "Run next prompt through verification (two independent answers + reconciliation)"
56
58
  def verify(args, context_manager = nil)
57
- AIA.turn_state.force_verify = true
59
+ AIA.turn_state.request(:verify)
58
60
  "Verification mode enabled for next prompt."
59
61
  end
60
62
 
61
63
  desc "Decompose next prompt into parallel sub-tasks"
62
64
  def decompose(args, context_manager = nil)
63
- AIA.turn_state.force_decompose = true
65
+ AIA.turn_state.request(:decompose)
64
66
  "Decomposition mode enabled for next prompt."
65
67
  end
66
68
 
67
69
  desc "Multi-round debate between robots in the network"
68
70
  def debate(args, context_manager = nil)
69
- AIA.turn_state.force_debate = true
71
+ AIA.turn_state.request(:debate)
70
72
  "Debate mode enabled for next prompt."
71
73
  end
72
74
 
73
75
  desc "Delegate subtasks to specific robots via TrakFlow plan"
74
76
  def delegate(args, context_manager = nil)
75
- AIA.turn_state.force_delegate = true
77
+ AIA.turn_state.request(:delegate)
76
78
  "Delegation mode enabled for next prompt."
77
79
  end
78
80
  alias del delegate
@@ -80,17 +82,14 @@ module AIA
80
82
  desc "Spawn a specialist robot for the next prompt. " \
81
83
  "Usage: /spawn | /spawn <type> | /spawn <name> <provider/model> <system prompt>"
82
84
  def spawn(args, context_manager = nil)
83
- AIA.turn_state.force_spawn = true
84
-
85
85
  if args.size >= 2
86
86
  spec = AIA::SpawnSpecParser.parse(args)
87
- AIA.turn_state.spawn_spec = spec
88
- AIA.turn_state.spawn_type = nil
87
+ AIA.turn_state.request(:spawn, spec: spec)
89
88
  "Spawn mode enabled: '#{spec[:name]}' (#{spawn_model_summary(spec)}) for next prompt."
90
89
  else
91
- AIA.turn_state.spawn_spec = nil
92
- AIA.turn_state.spawn_type = args.first
93
- type_msg = args.first ? " (#{args.first})" : " (auto-detect)"
90
+ type = args.first
91
+ AIA.turn_state.request(:spawn, type: type)
92
+ type_msg = type ? " (#{type})" : " (auto-detect)"
94
93
  "Spawn mode enabled#{type_msg} for next prompt."
95
94
  end
96
95
  end
@@ -135,7 +134,7 @@ module AIA
135
134
 
136
135
  desc "3-tier layered orchestration: orchestrator → lead agents → specialists"
137
136
  def orchestrate(args, context_manager = nil)
138
- AIA.turn_state.force_orchestrate = true
137
+ AIA.turn_state.request(:orchestrate)
139
138
  "Orchestration mode enabled. Your next prompt is the application requirements."
140
139
  end
141
140
  alias orch orchestrate
@@ -144,9 +143,10 @@ module AIA
144
143
 
145
144
  # Human-readable model description for the /spawn confirmation message.
146
145
  def spawn_model_summary(spec)
147
- return 'inherited model' unless spec[:model]
146
+ model = spec[:model]
147
+ return 'inherited model' unless model
148
148
 
149
- spec[:provider] ? "#{spec[:provider]}/#{spec[:model]}" : spec[:model]
149
+ spec[:provider] ? "#{spec[:provider]}/#{model}" : model
150
150
  end
151
151
 
152
152
  # Model plus any assigned skills, for the /add_recruit confirmation message.