aia 2.0.0.0.pre.beta2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. checksums.yaml +4 -4
  2. data/.version +1 -1
  3. data/CHANGELOG.md +146 -228
  4. data/README.md +41 -18
  5. data/bin/aia +8 -3
  6. data/lib/aia/aia_completion.bash +2 -3
  7. data/lib/aia/aia_completion.fish +6 -5
  8. data/lib/aia/aia_completion.zsh +2 -3
  9. data/lib/aia/chat_loop.rb +16 -14
  10. data/lib/aia/config/cli_parser.rb +123 -91
  11. data/lib/aia/config/defaults.yml +12 -39
  12. data/lib/aia/config/mcp_parser.rb +30 -36
  13. data/lib/aia/config/model_spec.rb +8 -14
  14. data/lib/aia/config/validator.rb +102 -103
  15. data/lib/aia/config/value_caster.rb +76 -0
  16. data/lib/aia/config.rb +70 -53
  17. data/lib/aia/crew.rb +29 -19
  18. data/lib/aia/debate_handler.rb +27 -10
  19. data/lib/aia/directives/configuration_directives.rb +55 -14
  20. data/lib/aia/directives/context_directives.rb +24 -12
  21. data/lib/aia/directives/execution_directives.rb +18 -23
  22. data/lib/aia/directives/model_directives.rb +41 -104
  23. data/lib/aia/directives/utility_directives.rb +16 -17
  24. data/lib/aia/directives/web_and_file_directives.rb +21 -14
  25. data/lib/aia/fact_asserter.rb +3 -3
  26. data/lib/aia/history_transfer.rb +64 -24
  27. data/lib/aia/logger.rb +10 -45
  28. data/lib/aia/mcp_config_normalizer.rb +27 -14
  29. data/lib/aia/mcp_connection_manager.rb +181 -184
  30. data/lib/aia/mcp_discovery.rb +43 -15
  31. data/lib/aia/mcp_grouper.rb +2 -1
  32. data/lib/aia/mcp_server_config.rb +20 -2
  33. data/lib/aia/mcp_utility.rb +24 -19
  34. data/lib/aia/mention_router.rb +15 -2
  35. data/lib/aia/modality_query.rb +36 -0
  36. data/lib/aia/model_alias_registry.rb +11 -11
  37. data/lib/aia/model_registry.rb +75 -0
  38. data/lib/aia/network_builder.rb +8 -7
  39. data/lib/aia/patches/ruby_llm_streaming_error.rb +21 -4
  40. data/lib/aia/patches/ruby_llm_tool_param_compat.rb +18 -0
  41. data/lib/aia/pipeline_orchestrator.rb +71 -38
  42. data/lib/aia/prompt_decomposer.rb +1 -1
  43. data/lib/aia/prompt_handler.rb +56 -29
  44. data/lib/aia/provider_registry.rb +105 -0
  45. data/lib/aia/robot_builder.rb +1 -1
  46. data/lib/aia/robot_factory.rb +67 -63
  47. data/lib/aia/robot_sync.rb +79 -0
  48. data/lib/aia/role_catalog.rb +89 -0
  49. data/lib/aia/session.rb +25 -11
  50. data/lib/aia/skill_utils.rb +60 -19
  51. data/lib/aia/spawn_handler.rb +16 -4
  52. data/lib/aia/spawn_spec_parser.rb +6 -7
  53. data/lib/aia/special_mode_handler.rb +28 -25
  54. data/lib/aia/speech.rb +70 -34
  55. data/lib/aia/startup_coordinator.rb +17 -92
  56. data/lib/aia/streaming_runner.rb +10 -2
  57. data/lib/aia/system_prompt_assembler.rb +12 -11
  58. data/lib/aia/task_board.rb +60 -0
  59. data/lib/aia/tool_approver.rb +205 -0
  60. data/lib/aia/tool_filter.rb +1 -10
  61. data/lib/aia/tool_filter_strategy.rb +12 -1
  62. data/lib/aia/tool_introspection.rb +9 -1
  63. data/lib/aia/tool_loader.rb +67 -33
  64. data/lib/aia/tool_utility.rb +6 -5
  65. data/lib/aia/tools/delegate_to_foreman_tool.rb +6 -4
  66. data/lib/aia/tools/recruit_robot_tool.rb +12 -12
  67. data/lib/aia/tools/reskill_robot_tool.rb +7 -7
  68. data/lib/aia/tools/task_board_tool.rb +16 -16
  69. data/lib/aia/trakflow_bridge.rb +14 -8
  70. data/lib/aia/turn_state.rb +31 -8
  71. data/lib/aia/ui_presenter.rb +16 -0
  72. data/lib/aia/utility.rb +6 -24
  73. data/lib/aia/variable_input_collector.rb +0 -3
  74. data/lib/aia/verification_network.rb +9 -10
  75. data/lib/aia.rb +33 -8
  76. metadata +19 -160
  77. data/.better-commits.json +0 -150
  78. data/.config/tocer/configuration.yml +0 -6
  79. data/.envrc +0 -19
  80. data/.loki +0 -11
  81. data/.reek.yml +0 -160
  82. data/.rubocop.yml +0 -116
  83. data/.rubocop_strict.yml +0 -15
  84. data/COMMITS.md +0 -196
  85. data/IMPLEMENTATION_PLAN.md +0 -506
  86. data/Rakefile +0 -47
  87. data/_typos.toml +0 -10
  88. data/aia.gemspec +0 -92
  89. data/architecture_review.md +0 -314
  90. data/config/aia.yml +0 -13
  91. data/docs/AGENTS.md +0 -40
  92. data/docs/advanced-prompting.md +0 -814
  93. data/docs/assets/images/aia.png +0 -0
  94. data/docs/cli-reference.md +0 -1241
  95. data/docs/configuration.md +0 -747
  96. data/docs/contributing.md +0 -386
  97. data/docs/directives-reference.md +0 -1145
  98. data/docs/examples/index.md +0 -277
  99. data/docs/examples/mcp/index.md +0 -475
  100. data/docs/examples/prompts/analysis/index.md +0 -78
  101. data/docs/examples/prompts/automation/index.md +0 -109
  102. data/docs/examples/prompts/development/index.md +0 -125
  103. data/docs/examples/prompts/index.md +0 -333
  104. data/docs/examples/prompts/learning/index.md +0 -127
  105. data/docs/examples/prompts/writing/index.md +0 -62
  106. data/docs/examples/tools/index.md +0 -282
  107. data/docs/faq.md +0 -578
  108. data/docs/guides/available-models.md +0 -366
  109. data/docs/guides/basic-usage.md +0 -478
  110. data/docs/guides/chat.md +0 -680
  111. data/docs/guides/crew.md +0 -239
  112. data/docs/guides/executable-prompts.md +0 -331
  113. data/docs/guides/first-prompt.md +0 -454
  114. data/docs/guides/getting-started.md +0 -455
  115. data/docs/guides/image-generation.md +0 -507
  116. data/docs/guides/index.md +0 -48
  117. data/docs/guides/local-models.md +0 -306
  118. data/docs/guides/migrate-prompts.md +0 -335
  119. data/docs/guides/models.md +0 -1017
  120. data/docs/guides/shared-tools.md +0 -254
  121. data/docs/guides/tools.md +0 -831
  122. data/docs/index.md +0 -259
  123. data/docs/installation.md +0 -274
  124. data/docs/mcp-integration.md +0 -603
  125. data/docs/prompt_management.md +0 -665
  126. data/docs/security.md +0 -674
  127. data/docs/special_projects_guide.md +0 -386
  128. data/docs/tools-and-mcp-examples.md +0 -1211
  129. data/docs/workflows-and-pipelines.md +0 -636
  130. data/examples/.gitignore +0 -2
  131. data/examples/00_setup_aia.sh +0 -111
  132. data/examples/01_basic_usage.sh +0 -23
  133. data/examples/02_frontmatter.sh +0 -33
  134. data/examples/03_shell_integration.sh +0 -55
  135. data/examples/04_erb_templating.sh +0 -56
  136. data/examples/05_shell_then_erb.sh +0 -38
  137. data/examples/06_prompt_chaining.sh +0 -59
  138. data/examples/07_pipeline.sh +0 -46
  139. data/examples/08_context_files.sh +0 -43
  140. data/examples/09_roles.sh +0 -67
  141. data/examples/10_stdin_piping.sh +0 -49
  142. data/examples/11_multi_model.sh +0 -65
  143. data/examples/12_token_usage.sh +0 -52
  144. data/examples/13_cost_tracking.sh +0 -68
  145. data/examples/14_output_file.sh +0 -91
  146. data/examples/15_parameters.sh +0 -68
  147. data/examples/16_directives.sh +0 -113
  148. data/examples/17_require_and_conditionals.sh +0 -68
  149. data/examples/18_tools.sh +0 -61
  150. data/examples/19_local_tools.sh +0 -34
  151. data/examples/20_mcp_servers.sh +0 -102
  152. data/examples/21_executable_prompts.sh +0 -78
  153. data/examples/22_chat_mode.sh +0 -217
  154. data/examples/23_verify.sh +0 -139
  155. data/examples/24_decompose.sh +0 -139
  156. data/examples/25_spawn.sh +0 -139
  157. data/examples/26_debate.sh +0 -97
  158. data/examples/27_mention_routing.sh +0 -157
  159. data/examples/28_model_switching.sh +0 -106
  160. data/examples/29_agent_harness.sh +0 -177
  161. data/examples/README.md +0 -321
  162. data/examples/advanced_multi_robot_capabilities_without_examples.md +0 -106
  163. data/examples/aia_config.yml +0 -22
  164. data/examples/aia_config_orchestrator.yml +0 -45
  165. data/examples/aia_config_with_mcp.yml +0 -21
  166. data/examples/common.sh +0 -39
  167. data/examples/context/project_goals.md +0 -6
  168. data/examples/context/tech_stack.md +0 -7
  169. data/examples/directives/timestamp_directive.rb +0 -22
  170. data/examples/mcp/filesystem.json +0 -9
  171. data/examples/prompts_dir/analyze.md +0 -2
  172. data/examples/prompts_dir/brainstorm.md +0 -2
  173. data/examples/prompts_dir/conditional.md +0 -17
  174. data/examples/prompts_dir/creative.md +0 -4
  175. data/examples/prompts_dir/erbinfo.md +0 -5
  176. data/examples/prompts_dir/erbinfo_raw.md +0 -8
  177. data/examples/prompts_dir/evaluate.md +0 -2
  178. data/examples/prompts_dir/explain_joke.md +0 -1
  179. data/examples/prompts_dir/explain_recursion.md +0 -1
  180. data/examples/prompts_dir/fun_fact +0 -3
  181. data/examples/prompts_dir/greeting.md +0 -8
  182. data/examples/prompts_dir/greeting_required.md +0 -7
  183. data/examples/prompts_dir/hello.md +0 -1
  184. data/examples/prompts_dir/includes/ruby_facts.md +0 -4
  185. data/examples/prompts_dir/limerick.md +0 -1
  186. data/examples/prompts_dir/list_with_mcp.md +0 -3
  187. data/examples/prompts_dir/pick_best.md +0 -2
  188. data/examples/prompts_dir/project_summary +0 -12
  189. data/examples/prompts_dir/quiz_with_include.md +0 -6
  190. data/examples/prompts_dir/require_demo.md +0 -5
  191. data/examples/prompts_dir/roles/formal.md +0 -3
  192. data/examples/prompts_dir/roles/orchestrator.md +0 -21
  193. data/examples/prompts_dir/roles/pirate.md +0 -3
  194. data/examples/prompts_dir/shell_then_erb.md +0 -6
  195. data/examples/prompts_dir/sort_compare.md +0 -2
  196. data/examples/prompts_dir/summarize_context.md +0 -2
  197. data/examples/prompts_dir/sysinfo.md +0 -5
  198. data/examples/prompts_dir/sysinfo_raw.md +0 -8
  199. data/examples/prompts_dir/tagline.md +0 -1
  200. data/examples/prompts_dir/tell_joke.md +0 -1
  201. data/examples/prompts_dir/tell_joke_with_next.md +0 -4
  202. data/examples/prompts_dir/use_local_tool.md +0 -8
  203. data/examples/prompts_dir/use_tools.md +0 -8
  204. data/examples/prompts_dir/weather.md +0 -2
  205. data/examples/prompts_dir/whats_new.md +0 -2
  206. data/examples/prompts_dir/with_timestamp.md +0 -5
  207. data/examples/requirements/sinatra_taskflow_app.md +0 -139
  208. data/examples/rules/01_classify_ruby.rb +0 -16
  209. data/examples/rules/02_prefer_claude_for_code.rb +0 -19
  210. data/examples/rules/03_gate_prompt_length.rb +0 -19
  211. data/examples/rules/04_tool_selection.rb +0 -41
  212. data/examples/rules/README.md +0 -30
  213. data/examples/run_all.sh +0 -294
  214. data/examples/tools/word_count_tool.rb +0 -30
  215. data/lib/AGENTS.md +0 -57
  216. data/lib/aia/model_switch_handler.rb +0 -100
  217. data/mcp_servers/README.md +0 -110
  218. data/mcp_servers/apple-mcp.json +0 -8
  219. data/mcp_servers/filesystem.json +0 -9
  220. data/mcp_servers/mcp_server_chart.json +0 -11
  221. data/mcp_servers/playwright_one.json +0 -8
  222. data/mcp_servers/playwright_server_definition.json +0 -9
  223. data/mcp_servers/playwright_two.json +0 -8
  224. data/mcp_servers/tavily_mcp_server.json +0 -8
  225. data/mkdocs.yml +0 -169
@@ -13,8 +13,8 @@ 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
- puts "ERROR: /ruby is disabled. Set `allow_ruby_eval: true` in " \
17
- "~/.aia/config.yml or pass --allow-ruby-eval to enable it. " \
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
18
  "Note: this executes arbitrary Ruby with full process privileges."
19
19
  return ""
20
20
  end
@@ -35,46 +35,46 @@ module AIA
35
35
 
36
36
  desc "Use text-to-speech to speak the text"
37
37
  def say(args, context_manager = nil)
38
- audio = AIA.config.audio
39
- voice = audio.voice
40
- env = {}
41
- env['SPEECH_MODEL'] = audio.speech_model if audio.speech_model
42
- if voice && !voice.strip.empty?
43
- system(env, 'say', '-v', voice, *args)
44
- else
45
- 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
46
44
  end
45
+
46
+ Speech.speak_text(text)
47
47
  ""
48
48
  end
49
49
 
50
50
  desc "Execute next prompt with concurrent MCP server access"
51
51
  def concurrent(args, context_manager = nil)
52
- AIA.turn_state.force_concurrent_mcp = true
52
+ AIA.turn_state.request(:concurrent_mcp)
53
53
  "Concurrent MCP mode enabled for next prompt."
54
54
  end
55
55
  alias conc concurrent
56
56
 
57
57
  desc "Run next prompt through verification (two independent answers + reconciliation)"
58
58
  def verify(args, context_manager = nil)
59
- AIA.turn_state.force_verify = true
59
+ AIA.turn_state.request(:verify)
60
60
  "Verification mode enabled for next prompt."
61
61
  end
62
62
 
63
63
  desc "Decompose next prompt into parallel sub-tasks"
64
64
  def decompose(args, context_manager = nil)
65
- AIA.turn_state.force_decompose = true
65
+ AIA.turn_state.request(:decompose)
66
66
  "Decomposition mode enabled for next prompt."
67
67
  end
68
68
 
69
69
  desc "Multi-round debate between robots in the network"
70
70
  def debate(args, context_manager = nil)
71
- AIA.turn_state.force_debate = true
71
+ AIA.turn_state.request(:debate)
72
72
  "Debate mode enabled for next prompt."
73
73
  end
74
74
 
75
75
  desc "Delegate subtasks to specific robots via TrakFlow plan"
76
76
  def delegate(args, context_manager = nil)
77
- AIA.turn_state.force_delegate = true
77
+ AIA.turn_state.request(:delegate)
78
78
  "Delegation mode enabled for next prompt."
79
79
  end
80
80
  alias del delegate
@@ -82,18 +82,13 @@ module AIA
82
82
  desc "Spawn a specialist robot for the next prompt. " \
83
83
  "Usage: /spawn | /spawn <type> | /spawn <name> <provider/model> <system prompt>"
84
84
  def spawn(args, context_manager = nil)
85
- state = AIA.turn_state
86
- state.force_spawn = true
87
-
88
85
  if args.size >= 2
89
86
  spec = AIA::SpawnSpecParser.parse(args)
90
- state.spawn_spec = spec
91
- state.spawn_type = nil
87
+ AIA.turn_state.request(:spawn, spec: spec)
92
88
  "Spawn mode enabled: '#{spec[:name]}' (#{spawn_model_summary(spec)}) for next prompt."
93
89
  else
94
90
  type = args.first
95
- state.spawn_spec = nil
96
- state.spawn_type = type
91
+ AIA.turn_state.request(:spawn, type: type)
97
92
  type_msg = type ? " (#{type})" : " (auto-detect)"
98
93
  "Spawn mode enabled#{type_msg} for next prompt."
99
94
  end
@@ -139,7 +134,7 @@ module AIA
139
134
 
140
135
  desc "3-tier layered orchestration: orchestrator → lead agents → specialists"
141
136
  def orchestrate(args, context_manager = nil)
142
- AIA.turn_state.force_orchestrate = true
137
+ AIA.turn_state.request(:orchestrate)
143
138
  "Orchestration mode enabled. Your next prompt is the application requirements."
144
139
  end
145
140
  alias orch orchestrate
@@ -1,21 +1,17 @@
1
1
  # lib/aia/directives/model_directives.rb
2
2
 
3
+ require_relative '../modality_query'
4
+
3
5
  module AIA
4
6
  class ModelDirectives < Directive
5
7
  desc "List all available AI models"
6
8
  def available_models(args = nil, context_manager = nil)
7
- current_models = AIA.config.models
8
-
9
- model_names = current_models.map do |m|
10
- m.respond_to?(:name) ? m.name : m.to_s
11
- end
12
-
13
9
  positive_terms, negative_terms = parse_search_terms(Array(args))
14
10
 
15
- using_local_provider = model_names.any? { |m| m.start_with?('ollama/', 'lms/') }
11
+ provider_slugs = configured_provider_slugs(AIA.config.models)
16
12
 
17
- if using_local_provider
18
- show_local_models(model_names, positive_terms, negative_terms)
13
+ if provider_slugs.any?
14
+ show_provider_models(provider_slugs, positive_terms, negative_terms)
19
15
  else
20
16
  show_rubyllm_models(positive_terms, negative_terms)
21
17
  end
@@ -49,10 +45,10 @@ module AIA
49
45
 
50
46
  # --- helpers (no desc → not registered) ---
51
47
 
52
- # Split a //compare arg list into [prompt, models]; the first non-flag
53
- # token is the prompt, `--models a,b,c` supplies the model list.
48
+ # Split a //compare arg list into [prompt, models]; every word that is
49
+ # not part of `--models a,b,c` belongs to the prompt.
54
50
  def parse_compare_args(args)
55
- prompt = nil
51
+ words = []
56
52
  models = []
57
53
 
58
54
  i = 0
@@ -61,12 +57,13 @@ module AIA
61
57
  models = args[i + 1].split(',')
62
58
  i += 2
63
59
  else
64
- prompt ||= args[i]
60
+ words << args[i]
65
61
  i += 1
66
62
  end
67
63
  end
68
64
 
69
- [prompt, models]
65
+ prompt = words.join(' ').strip
66
+ [prompt.empty? ? nil : prompt, models]
70
67
  end
71
68
 
72
69
  def compare_with_model(model_name, prompt)
@@ -87,68 +84,43 @@ module AIA
87
84
  nil
88
85
  end
89
86
 
90
- def show_local_models(current_models, positive_terms = nil, negative_terms = nil)
91
- require 'net/http'
92
- require 'json'
93
-
94
- positive_terms, negative_terms = normalized_model_search_terms(positive_terms, negative_terms)
95
-
96
- puts "\nLocal LLM Models:"
97
- puts
98
-
99
- current_models.each do |model_spec|
100
- if model_spec.start_with?('ollama/')
101
- api_base = ENV.fetch('OLLAMA_API_BASE', 'http://localhost:11434')
102
- api_base = api_base.gsub(%r{/v1/?$}, '')
103
- show_ollama_models(api_base, positive_terms, negative_terms)
104
- elsif model_spec.start_with?('lms/')
105
- api_base = ENV.fetch('LMS_API_BASE', 'http://localhost:1234')
106
- show_lms_models(api_base, positive_terms, negative_terms)
87
+ # Provider slugs referenced by the configured models — from ModelSpec#provider
88
+ # when present, else from a registered "<slug>/" name prefix (raw string
89
+ # model specs). Entirely registry-driven; no provider names are hardcoded.
90
+ def configured_provider_slugs(models)
91
+ Array(models).filter_map do |m|
92
+ if m.respond_to?(:provider) && m.provider
93
+ m.provider.to_s
94
+ else
95
+ name = (m.respond_to?(:name) ? m.name : m).to_s
96
+ prefix = name.split('/', 2).first if name.include?('/')
97
+ prefix if AIA::ProviderRegistry.registered?(prefix)
107
98
  end
108
- end
99
+ end.uniq
109
100
  end
110
101
 
111
- # :reek:TooManyStatements -- sequential terminal report: fetch, connection guards, filtered listing
112
- def show_ollama_models(api_base, positive_terms = nil, negative_terms = nil)
102
+ # List each provider's live models through RubyLLM's own provider API
103
+ # (Provider#list_models), the same path every registered provider —
104
+ # built-in or gem-supplied — implements.
105
+ # :reek:TooManyStatements -- sequential terminal report per provider: header, listing, connection guard
106
+ def show_provider_models(provider_slugs, positive_terms = nil, negative_terms = nil)
113
107
  positive_terms, negative_terms = normalized_model_search_terms(positive_terms, negative_terms)
114
108
 
115
- data = fetch_json("#{api_base}/api/tags")
116
- if data.nil?
117
- puts "❌ Cannot connect to Ollama at #{api_base}"
118
- return
119
- end
109
+ provider_slugs.each do |slug|
110
+ puts "\n#{slug} models:"
111
+ puts "-" * 60
120
112
 
121
- models = data['models'] || []
122
- if models.empty?
123
- puts "No Ollama models found"
124
- return
113
+ entries = provider_model_entries(slug)
114
+ print_filtered_entries(entries, positive_terms, negative_terms, "#{slug} model(s) available")
115
+ rescue StandardError => e
116
+ puts "❌ Cannot list models for provider '#{slug}': #{e.message}"
125
117
  end
126
-
127
- puts "Ollama Models (#{api_base}):"
128
- puts "-" * 60
129
-
130
- entries = models.map { |model| format_ollama_entry(model) }
131
- print_filtered_entries(entries, positive_terms, negative_terms, "Ollama model(s) available")
132
- rescue StandardError => e
133
- puts "❌ Error fetching Ollama models: #{e.message}"
134
- end
135
-
136
- def format_ollama_entry(model)
137
- size = model['size'] ? format_bytes(model['size']) : 'unknown'
138
- modified = model['modified_at'] ? Time.parse(model['modified_at']).strftime('%Y-%m-%d') : 'unknown'
139
- "- ollama/#{model['name']} (size: #{size}, modified: #{modified})"
140
118
  end
141
119
 
142
- # Fetch and parse JSON from a local model server; nil unless HTTP success.
143
- def fetch_json(uri_string)
144
- uri = URI(uri_string)
145
- http = Net::HTTP.new(uri.host, uri.port)
146
- http.open_timeout = 5
147
- http.read_timeout = 5
148
- response = http.request(Net::HTTP::Get.new(uri))
149
- return nil unless response.is_a?(Net::HTTPSuccess)
150
-
151
- JSON.parse(response.body)
120
+ # One "- <slug>/<model-id>" line per model the provider reports.
121
+ def provider_model_entries(slug)
122
+ provider = AIA::ProviderRegistry.instantiate(slug)
123
+ provider.list_models.map { |model| "- #{slug}/#{model.id}" }
152
124
  end
153
125
 
154
126
  # The entry is a String; Array#intersect? would raise TypeError
@@ -171,41 +143,6 @@ module AIA
171
143
  puts
172
144
  end
173
145
 
174
- # :reek:TooManyStatements -- sequential terminal report: fetch, connection guards, filtered listing
175
- def show_lms_models(api_base, positive_terms = nil, negative_terms = nil)
176
- positive_terms, negative_terms = normalized_model_search_terms(positive_terms, negative_terms)
177
-
178
- data = fetch_json("#{api_base.gsub(%r{/v1/?$}, '')}/v1/models")
179
- if data.nil?
180
- puts "❌ Cannot connect to LM Studio at #{api_base}"
181
- return
182
- end
183
-
184
- models = data['data'] || []
185
- if models.empty?
186
- puts "No LM Studio models found"
187
- return
188
- end
189
-
190
- puts "LM Studio Models (#{api_base}):"
191
- puts "-" * 60
192
-
193
- entries = models.map { |model| "- lms/#{model['id']}" }
194
- print_filtered_entries(entries, positive_terms, negative_terms, "LM Studio model(s) available")
195
- rescue StandardError => e
196
- puts "❌ Error fetching LM Studio models: #{e.message}"
197
- end
198
-
199
- def format_bytes(bytes)
200
- units = %w[B KB MB GB TB]
201
- return "0 B" if bytes.zero?
202
-
203
- exp = (Math.log(bytes) / Math.log(1024)).to_i
204
- exp = [exp, units.length - 1].min
205
-
206
- "%.1f %s" % [bytes.to_f / (1024**exp), units[exp]]
207
- end
208
-
209
146
  # :reek:TooManyStatements -- sequential terminal report: header, filtered model listing, summary
210
147
  def show_rubyllm_models(positive_terms = nil, negative_terms = nil)
211
148
  positive_terms, negative_terms = normalized_model_search_terms(positive_terms, negative_terms)
@@ -218,7 +155,7 @@ module AIA
218
155
 
219
156
  # modality terms (e.g. "text_to_text") trigger capability checks; the rest
220
157
  # are plain substring filters applied to the formatted entry string
221
- modality_terms, substring_terms = positive_terms.partition { |q| q.include?('_to_') }
158
+ modality_terms, substring_terms = positive_terms.partition { |q| ModalityQuery.modality_term?(q) }
222
159
 
223
160
  counter = 0
224
161
  RubyLLM.models.all.each do |llm|
@@ -249,7 +186,7 @@ module AIA
249
186
  end
250
187
 
251
188
  def rubyllm_entry_visible?(llm, entry, modality_terms, substring_terms, negative_terms)
252
- modality_terms.all? { |q| llm.modalities.send("#{q}?") } &&
189
+ modality_terms.all? { |q| ModalityQuery.matches?(llm.modalities, q) } &&
253
190
  substring_terms.all? { |q| entry.include?(q) } &&
254
191
  negative_terms.none? { |q| entry.downcase.include?(q) }
255
192
  end
@@ -135,7 +135,7 @@ module AIA
135
135
  def tools_by_server(connected, mcp_tools)
136
136
  grouped = connected.to_h { |name| [name, []] }
137
137
  mcp_tools.each do |tool|
138
- server_name = tool.respond_to?(:mcp) ? tool.mcp : nil
138
+ server_name = mcp_server_name_for(tool)
139
139
  grouped[server_name] << tool if server_name && grouped.key?(server_name)
140
140
  end
141
141
  grouped
@@ -237,26 +237,25 @@ module AIA
237
237
  end
238
238
  end
239
239
 
240
- # Retrieve MCP tools from robot or first robot in a Network.
241
- # Falls back to RubyLLM::MCP.clients for tools registered by shared_tools
242
- # or other gems that use RubyLLM::MCP.add_client directly.
240
+ # The MCP tools aia connected at startup (shared by every robot), or the
241
+ # robot's own when no connection manager ran.
243
242
  def all_mcp_tools
243
+ manager = AIA.mcp_manager
244
+ return manager.connected_tools if manager&.connected?
245
+
244
246
  robot = AIA.client
245
- if robot
246
- if robot.respond_to?(:mcp_tools) && robot.mcp_tools&.any?
247
- return Array(robot.mcp_tools)
248
- end
247
+ robot = robot.chief if robot && !robot.respond_to?(:mcp_tools) && robot.respond_to?(:chief)
248
+ robot.respond_to?(:mcp_tools) ? Array(robot.mcp_tools) : []
249
+ end
249
250
 
250
- first_robot = robot.chief
251
- if first_robot.respond_to?(:mcp_tools) && first_robot.mcp_tools&.any?
252
- return Array(first_robot.mcp_tools)
253
- end
254
- end
251
+ # Name of the MCP server that offers +tool+, or nil for a local tool.
252
+ def mcp_server_name_for(tool)
253
+ by_server = AIA.mcp_manager&.tools_by_server || {}
254
+ owner, = by_server.find { |_, tools| tools.any? { it.equal?(tool) } }
255
+ return owner if owner
255
256
 
256
- # Fall back to RubyLLM::MCP clients (shared_tools and other gems
257
- # that register MCP servers via RubyLLM::MCP.add_client)
258
- return [] unless defined?(RubyLLM::MCP)
259
- RubyLLM::MCP.clients.values.flat_map(&:tools)
257
+ robot = AIA.client
258
+ robot.respond_to?(:mcp_server_for) ? robot.mcp_server_for(tool)&.name : nil
260
259
  end
261
260
  end
262
261
  end
@@ -68,25 +68,17 @@ module AIA
68
68
  return report_skill_error("Error: /skill requires a skill name. Use /skills to list available skills.")
69
69
  end
70
70
 
71
+ if path_based_id?(skill_name) && non_markdown_skill_file?(File.expand_path(skill_name))
72
+ return report_skill_error("Error: #{non_markdown_skill_message(skill_name)}.")
73
+ end
74
+
71
75
  dir = aia_skills_dir
72
76
  skill_dir = find_skill_dir(skill_name, dir)
73
77
  unless skill_dir
74
78
  return report_skill_error("Error: No skill matching '#{skill_name}' found in #{dir}. Use /skills to list available skills.")
75
79
  end
76
80
 
77
- return File.read(skill_dir) if File.file?(skill_dir)
78
-
79
- skill_path = File.join(skill_dir, 'SKILL.md')
80
- unless File.exist?(skill_path)
81
- msg = if path_based_id?(skill_name)
82
- "Error: No skill matching '#{skill_name}' found in #{dir}. Use /skills to list available skills."
83
- else
84
- "Error: Skill '#{File.basename(skill_dir)}' has no SKILL.md in #{dir}."
85
- end
86
- return report_skill_error(msg)
87
- end
88
-
89
- File.read(skill_path)
81
+ read_skill_text(skill_name, skill_dir, dir)
90
82
  end
91
83
 
92
84
  desc "Paste content from the system clipboard"
@@ -131,6 +123,21 @@ module AIA
131
123
 
132
124
  # Log and print a /skill error message; returns nil so callers can
133
125
  # `return report_skill_error(msg)` from any guard.
126
+ # The text of a found skill: the file itself, or the folder's SKILL.md.
127
+ def read_skill_text(skill_name, skill_dir, dir)
128
+ return File.read(skill_dir) if File.file?(skill_dir)
129
+
130
+ skill_path = File.join(skill_dir, 'SKILL.md')
131
+ return File.read(skill_path) if File.exist?(skill_path)
132
+
133
+ msg = if path_based_id?(skill_name)
134
+ "Error: No skill matching '#{skill_name}' found in #{dir}. Use /skills to list available skills."
135
+ else
136
+ "Error: Skill '#{File.basename(skill_dir)}' has no SKILL.md in #{dir}."
137
+ end
138
+ report_skill_error(msg)
139
+ end
140
+
134
141
  def report_skill_error(msg)
135
142
  AIA::LoggerManager.aia_logger.error(msg)
136
143
  puts msg
@@ -142,7 +149,7 @@ module AIA
142
149
  skills = AIA.respond_to?(:config) ? AIA.config&.skills : nil
143
150
  return skills.dir if skills.respond_to?(:dir) && skills.dir
144
151
 
145
- ENV.fetch('AIA_SKILLS__DIR', File.expand_path('~/.prompts/skills'))
152
+ ENV.fetch('AIA_SKILLS__DIR') { File.expand_path('~/.prompts/skills') }
146
153
  end
147
154
 
148
155
  def terminal_width
@@ -10,10 +10,10 @@ module AIA
10
10
  class FactAsserter
11
11
  # Extract the tool's name as a non-nil String.
12
12
  #
13
- # @param tool [Object] any object that responds to .name
14
- # @return [String]
13
+ # @param tool [Object] a tool instance or RubyLLM::Tool class
14
+ # @return [String] the name the model calls it by (see ToolIntrospection.tool_name)
15
15
  def tool_name(tool)
16
- String(tool.respond_to?(:name) ? tool.name : "").strip
16
+ String(ToolIntrospection.tool_name(tool)).strip
17
17
  end
18
18
 
19
19
  # Extract the tool's description as a non-nil String.
@@ -4,24 +4,68 @@
4
4
  #
5
5
  # Stateless module for transferring conversation history between robots.
6
6
  # Extracted from RobotFactory to isolate the history transfer concern.
7
+ #
8
+ # Both arguments may be a single RobotLab::Robot or a RobotLab::Network (the
9
+ # interactive session always runs a crew). History is read from the old
10
+ # runnable's chief — the robot the user has been talking to — and carried to
11
+ # every member of the new crew.
7
12
 
8
13
  module AIA
9
14
  module HistoryTransfer
15
+ MODES = %i[clean replay summarize].freeze
16
+ DEFAULT_MODE = :summarize
17
+
10
18
  module_function
11
19
 
20
+ # The history mode configured for model switches (config.model_switch_history),
21
+ # falling back to DEFAULT_MODE when it is unset or not a known mode.
22
+ #
23
+ # @param config [AIA::Config, nil]
24
+ # @return [Symbol] one of MODES
25
+ def mode_for(config)
26
+ value = config.respond_to?(:model_switch_history) ? config.model_switch_history : nil
27
+ mode = value.to_s.strip.downcase.to_sym
28
+ MODES.include?(mode) ? mode : DEFAULT_MODE
29
+ end
30
+
31
+ # The user/assistant turns of +runnable+'s chief, oldest first. System
32
+ # prompts and tool traffic are left out: they belong to the old robot.
33
+ #
34
+ # @param runnable [RobotLab::Robot, RobotLab::Network, nil]
35
+ # @return [Array<RubyLLM::Message>]
36
+ def conversation(runnable)
37
+ chief = chief_of(runnable)
38
+ return [] unless chief.respond_to?(:messages)
39
+
40
+ Array(chief.messages).select do |msg|
41
+ msg.respond_to?(:role) && %i[user assistant].include?(msg.role) && !msg.content.to_s.strip.empty?
42
+ end
43
+ end
44
+
45
+ # The robot whose conversation the user sees: a network's chief, or the robot itself.
46
+ def chief_of(runnable)
47
+ runnable.respond_to?(:chief) ? runnable.chief : runnable
48
+ end
49
+
50
+ # The robots that should receive the transferred history.
51
+ #
52
+ # @param runnable [RobotLab::Robot, RobotLab::Network]
53
+ # @return [Array<RobotLab::Robot>]
54
+ def recipients(runnable)
55
+ runnable.respond_to?(:crew) ? Array(runnable.crew) : [runnable]
56
+ end
57
+
12
58
  # Replay conversation history from an old robot to a new one.
13
59
  #
14
- # Performance: O(N) API calls where N = number of user messages.
15
- # Each user message triggers a full LLM round-trip on the new model.
16
- # For a 10-turn conversation with a local model (~1s/turn), expect ~10s.
17
- # For a cloud model (~2-5s/turn), expect 20-50s. MCP/tools are disabled
18
- # during replay to avoid side effects.
60
+ # Performance: O(N) API calls per recipient, where N = number of user
61
+ # messages. Each user message triggers a full LLM round-trip on the new
62
+ # model. MCP/tools are disabled during replay to avoid side effects.
19
63
  def replay_history(old_robot, new_robot)
20
- return unless old_robot.respond_to?(:messages)
64
+ user_turns = conversation(old_robot).select { it.role == :user }
65
+ return if user_turns.empty?
21
66
 
22
- old_robot.messages.each do |msg|
23
- next unless msg.respond_to?(:role) && msg.role == :user
24
- new_robot.run(msg.content, mcp: :none, tools: :none)
67
+ recipients(new_robot).each do |robot|
68
+ user_turns.each { robot.run(it.content.to_s, mcp: :none, tools: :none) }
25
69
  end
26
70
  rescue StandardError => e
27
71
  $stderr.puts "Warning: History replay failed: #{e.message}"
@@ -29,25 +73,21 @@ module AIA
29
73
 
30
74
  # Summarize conversation history and inject into new robot.
31
75
  #
32
- # Performance: Exactly 2 API calls regardless of conversation length.
33
- # 1) Summarize on old model (input tokens proportional to conversation)
34
- # 2) Inject summary into new model (small fixed-size prompt)
35
- # Faster than :replay for conversations with >2 turns, but loses
36
- # per-turn context fidelity. Total latency ~4-10s for cloud models.
76
+ # Performance: one summary call on the old model, plus one injection call
77
+ # per recipient, regardless of conversation length. Faster than :replay
78
+ # for conversations with >2 turns, but loses per-turn context fidelity.
37
79
  def summarize_history(old_robot, new_robot)
38
- return unless old_robot.respond_to?(:messages) && old_robot.messages.any?
39
-
40
- summary_lines = old_robot.messages.map do |msg|
41
- "#{msg.role}: #{msg.content}" if msg.respond_to?(:role)
42
- end.compact
80
+ turns = conversation(old_robot)
81
+ return if turns.empty?
43
82
 
44
- return if summary_lines.empty?
45
-
46
- summary_prompt = "Summarize this conversation concisely for context transfer:\n#{summary_lines.join("\n")}"
47
- summary = old_robot.run(summary_prompt, mcp: :none, tools: :none)
83
+ transcript = turns.map { "#{it.role}: #{it.content}" }.join("\n")
84
+ summary = chief_of(old_robot).run("Summarize this conversation concisely for context transfer:\n#{transcript}",
85
+ mcp: :none, tools: :none)
48
86
  content = summary.respond_to?(:reply) ? summary.reply : summary.to_s
49
87
 
50
- new_robot.run("Context from previous conversation: #{content}", mcp: :none, tools: :none)
88
+ recipients(new_robot).each do |robot|
89
+ robot.run("Context from previous conversation: #{content}", mcp: :none, tools: :none)
90
+ end
51
91
  rescue StandardError => e
52
92
  $stderr.puts "Warning: History summarization failed: #{e.message}"
53
93
  end
data/lib/aia/logger.rb CHANGED
@@ -6,7 +6,8 @@
6
6
  # Provides loggers for three systems:
7
7
  # - aia: Used within the AIA codebase for application-level logging
8
8
  # - llm: Passed to RubyLLM gem's configuration (RubyLLM.logger)
9
- # - mcp: Passed to RubyLLM::MCP process (RubyLLM::MCP.logger)
9
+ # - mcp: MCP connection logging (MCPConnectionManager) and RobotLab.config.logger;
10
+ # ruby_llm's own MCP client logs through RubyLLM.logger (llm)
10
11
  #
11
12
  # Configuration is read from AIA.config.logger section:
12
13
  # logger:
@@ -92,7 +93,7 @@ module AIA
92
93
 
93
94
  if llm_config.respond_to?(:log_level=)
94
95
  level = effective_log_level(logger_config_for(:llm))
95
- llm_config.log_level = LOG_LEVELS.fetch(level, Lumberjack::Severity::WARN)
96
+ llm_config.log_level = LOG_LEVELS.fetch(level) { Lumberjack::Severity::WARN }
96
97
  end
97
98
 
98
99
  # Reset the memoized @logger on RubyLLM module so next call uses our config
@@ -100,38 +101,8 @@ module AIA
100
101
  RubyLLM.instance_variable_set(:@logger, nil) if RubyLLM.instance_variable_defined?(:@logger)
101
102
  end
102
103
 
103
- # Configure RubyLLM::MCP's logger
104
- # RubyLLM::MCP.config has attr_writer :logger and a memoized getter.
105
- # We need to set both the config.logger and reset any memoization.
106
- def configure_mcp_logger
107
- return unless defined?(RubyLLM::MCP)
108
-
109
- logger = mcp_logger
110
-
111
- # First reset the memoized @logger so our settings take effect
112
- # RubyLLM::MCP.config.logger does: @logger ||= Logger.new(...)
113
- config = RubyLLM::MCP.config
114
- config.instance_variable_set(:@logger, nil) if config.instance_variable_defined?(:@logger)
115
-
116
- # Set our logger on the MCP config object
117
- # RubyLLM::MCP.config has attr_writer :logger (which sets @logger directly)
118
- if config.respond_to?(:logger=)
119
- config.logger = logger
120
- end
121
-
122
- # Also set log_file and log_level in case the logger gets recreated
123
- if config.respond_to?(:log_file=)
124
- file = effective_log_file(logger_config_for(:mcp))
125
- config.log_file = resolve_log_file_io(file)
126
- end
127
-
128
- return unless config.respond_to?(:log_level=)
129
- level = effective_log_level(logger_config_for(:mcp))
130
- config.log_level = LOG_LEVELS.fetch(level, Lumberjack::Severity::WARN)
131
- end
132
-
133
104
  # Convert log file specification to IO object or file path
134
- # RubyLLM::MCP expects an IO object or file path for log_file config
105
+ # RubyLLM expects an IO object or file path for log_file config
135
106
  def resolve_log_file_io(file)
136
107
  case file.to_s.upcase
137
108
  when 'STDOUT'
@@ -172,13 +143,12 @@ module AIA
172
143
 
173
144
  config = logger_config_for(system)
174
145
  level = effective_log_level(config, system)
175
- numeric = LOG_LEVELS.fetch(level, Lumberjack::Severity::WARN)
146
+ numeric = LOG_LEVELS.fetch(level) { Lumberjack::Severity::WARN }
176
147
  logger.level = numeric
177
148
  end
178
149
 
179
- # Keep RubyLLM / MCP configs in sync so they don't override us
150
+ # Keep the RubyLLM config in sync so it doesn't override us
180
151
  configure_llm_logger
181
- configure_mcp_logger
182
152
  end
183
153
 
184
154
  # =======================================================================
@@ -194,7 +164,7 @@ module AIA
194
164
  def test_mode!(level: :debug)
195
165
  reset!
196
166
  @test_mode = true
197
- @test_level = LOG_LEVELS.fetch(level.to_s, Lumberjack::Severity::DEBUG)
167
+ @test_level = LOG_LEVELS.fetch(level.to_s) { Lumberjack::Severity::DEBUG }
198
168
 
199
169
  # Pre-create loggers with test devices
200
170
  @aia_logger = create_test_logger(:aia)
@@ -274,7 +244,7 @@ module AIA
274
244
  device = create_device(file, flush: flush)
275
245
  Lumberjack::Logger.new(
276
246
  device,
277
- level: LOG_LEVELS.fetch(level, Lumberjack::Severity::WARN),
247
+ level: LOG_LEVELS.fetch(level) { Lumberjack::Severity::WARN },
278
248
  progname: system.to_s.upcase
279
249
  )
280
250
  end
@@ -334,14 +304,9 @@ module AIA
334
304
  def logger_config_for(system)
335
305
  logger_cfg = AIA.config&.logger
336
306
  return nil unless logger_cfg
307
+ return nil unless %i[aia llm mcp].include?(system)
337
308
 
338
- case system
339
- when :aia then logger_cfg.aia
340
- when :llm then logger_cfg.llm
341
- when :mcp then logger_cfg.mcp
342
- end
343
- rescue NoMethodError
344
- nil
309
+ logger_cfg.public_send(system) if logger_cfg.respond_to?(system)
345
310
  end
346
311
  end
347
312
  end