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
@@ -61,19 +61,12 @@ defaults:
61
61
  extname: .md
62
62
  #
63
63
  role: ~
64
- roles_dir: ~/.prompts/roles
65
64
  roles_prefix: roles
66
65
  #
67
66
  skills: []
68
67
  #
69
- tool: ~
70
- tools_prefix: tools
71
- #
72
68
  system_prompt: ~
73
69
 
74
- roles:
75
- dir: ~/.prompts/roles
76
-
77
70
  skills:
78
71
  dir: ~/.prompts/skills
79
72
 
@@ -85,7 +78,6 @@ defaults:
85
78
  output:
86
79
  file: temp.md
87
80
  append: false
88
- markdown: true
89
81
  history_file: ~/.prompts/_prompts.log
90
82
 
91
83
  # ---------------------------------------------------------------------------
@@ -96,6 +88,7 @@ defaults:
96
88
  audio:
97
89
  voice: ~
98
90
  speak_command: say
91
+ player: ~
99
92
  speech_model: ~
100
93
  transcription_model: ~
101
94
 
@@ -105,29 +98,24 @@ defaults:
105
98
  # Env: AIA_IMAGE__MODEL, AIA_IMAGE__SIZE, etc.
106
99
  # ---------------------------------------------------------------------------
107
100
  image:
108
- model: dall-e-3
101
+ model: gpt-image-1
109
102
  size: 1024x1024
110
103
  quality: standard
111
104
  style: vivid
112
105
 
113
- # ---------------------------------------------------------------------------
114
- # Embedding Configuration
115
- # Access: AIA.config.embedding.model
116
- # Env: AIA_EMBEDDING__MODEL
117
- # ---------------------------------------------------------------------------
118
- embedding:
119
- model: text-embedding-ada-002
120
-
121
106
  # ---------------------------------------------------------------------------
122
107
  # Tools Configuration
123
108
  # Access: AIA.config.tools.paths, AIA.config.tools.allowed, etc.
124
109
  # Env: AIA_TOOLS__PATHS, AIA_TOOLS__ALLOWED, etc.
125
110
  # ---------------------------------------------------------------------------
126
111
  tools:
127
- dir: ~/.prompts/tools
128
112
  paths: []
129
113
  allowed: ~
130
114
  rejected: ~
115
+ # Tool calls that require approval (an MCP server's requires_approval:)
116
+ # and MCP input requests: ask (prompt on the terminal; refuse when there
117
+ # is none), approve (allow them all), or deny (refuse them all).
118
+ approval: ask
131
119
 
132
120
  # ---------------------------------------------------------------------------
133
121
  # Flags (Boolean Options)
@@ -145,13 +133,9 @@ defaults:
145
133
  speak: false
146
134
  shell: true
147
135
  erb: true
148
- clear: false
149
136
  consensus: false
150
137
  track_pipeline: false
151
- expert_routing: false
152
138
  auto_tool_filter: true
153
- tool_filter_load: false
154
- tool_filter_save: false
155
139
  allow_ruby_eval: false
156
140
  paint: false
157
141
  thinking: false
@@ -213,13 +197,12 @@ defaults:
213
197
 
214
198
  # ---------------------------------------------------------------------------
215
199
  # Paths Configuration
216
- # Access: AIA.config.paths.aia_dir, AIA.config.paths.config_file, AIA.config.paths.plugins_dir
217
- # Env: AIA_PATHS__AIA_DIR, AIA_PATHS__CONFIG_FILE
200
+ # Access: AIA.config.paths.aia_dir, AIA.config.paths.plugins_dir
201
+ # Env: AIA_PATHS__AIA_DIR
218
202
  # Special-case env: AIA_PLUGINS_DIR
219
203
  # ---------------------------------------------------------------------------
220
204
  paths:
221
205
  aia_dir: ~/.config/aia
222
- config_file: ~/.config/aia/aia.yml
223
206
  plugins_dir: ~
224
207
 
225
208
  # ---------------------------------------------------------------------------
@@ -231,10 +214,12 @@ defaults:
231
214
  # ---------------------------------------------------------------------------
232
215
  # Model Switch History Mode
233
216
  # Controls conversation history transfer when switching models mid-chat.
234
- # Values: clean (fresh start), replay (replay messages), summarize (summary)
217
+ # Values: clean (fresh start), replay (re-send every user message to the
218
+ # new model), summarize (old model summarizes; the new model gets the summary)
219
+ # Used by the /model directive.
235
220
  # Access: AIA.config.model_switch_history
236
221
  # ---------------------------------------------------------------------------
237
- model_switch_history: clean
222
+ model_switch_history: summarize
238
223
 
239
224
  # ---------------------------------------------------------------------------
240
225
  # Concurrency Configuration
@@ -243,21 +228,9 @@ defaults:
243
228
  # ---------------------------------------------------------------------------
244
229
  concurrency:
245
230
  auto: false
246
- independent_servers: []
247
231
  threshold: 2
248
232
  mcp_timeout: 120
249
233
 
250
- # ---------------------------------------------------------------------------
251
- # Rules Configuration (Enhanced Multi-KB in v2)
252
- # Access: AIA.config.rules.dir, AIA.config.rules.enabled, etc.
253
- # Env: AIA_RULES__DIR, AIA_RULES__ENABLED
254
- # ---------------------------------------------------------------------------
255
- rules:
256
- dir: ~/.config/aia/rules
257
- enabled: true
258
- store: memory
259
- db_path: ~/.config/aia/rules.db
260
-
261
234
  # ---------------------------------------------------------------------------
262
235
  # Context Files (set at runtime)
263
236
  # Access: AIA.config.context_files (array of file paths)
@@ -11,7 +11,6 @@
11
11
  # transport: { type: "stdio", command: "npx", args: [...], env: {...} },
12
12
  # timeout: 8000,
13
13
  # topics: ["routing"], # AIA routing metadata (optional)
14
- # independent: false, # AIA concurrency metadata (optional)
15
14
  # group: "services" # AIA grouping metadata (optional)
16
15
  # }
17
16
  #
@@ -39,6 +38,12 @@ require 'json'
39
38
 
40
39
  module AIA
41
40
  module McpParser
41
+ # Keys that describe how to reach the server; they go into :transport.
42
+ TRANSPORT_KEYS = %w[type command args env url headers bearer_token oauth cwd directory].freeze
43
+
44
+ # Server settings robot_lab understands, carried through as written.
45
+ SERVER_KEYS = %w[prefix only except requires_approval description].freeze
46
+
42
47
  class << self
43
48
  # Parse MCP server configuration files and return array of server configs
44
49
  # in robot_lab's nested transport format.
@@ -93,20 +98,29 @@ module AIA
93
98
  # @param mcp_servers [Hash] the mcpServers hash from JSON
94
99
  # @return [Array<Hash>] array of server configurations
95
100
  def convert_mcp_servers_format(mcp_servers)
96
- mcp_servers.map do |name, config|
97
- server = { name: name, transport: build_transport(config) }
98
- server[:timeout] = config['timeout'].to_i if config['timeout']
99
- server.merge!(routing_metadata(config))
100
- end
101
+ mcp_servers.map { |name, config| build_server(name, config) }
102
+ end
103
+
104
+ # One server in robot_lab's format. Both JSON forms accept the same keys.
105
+ def build_server(name, config)
106
+ server = { name: name, transport: build_transport(config) }
107
+ server[:timeout] = config['timeout'].to_i if config['timeout']
108
+ SERVER_KEYS.each { |key| server[key.to_sym] = config[key] if config.key?(key) }
109
+ server.merge!(routing_metadata(config))
101
110
  end
102
111
 
112
+ # The transport hash. With no "type", a url means Streamable HTTP and
113
+ # anything else stdio. A "command" given as an array holds the command
114
+ # followed by its arguments.
103
115
  def build_transport(config)
104
- transport = { type: config['type'] || 'stdio' }
105
- transport[:command] = config['command'] if config['command']
106
- transport[:args] = Array(config['args']) if config['args']
107
- transport[:env] = config['env'] if config['env']
108
- transport[:url] = config['url'] if config['url']
109
- transport[:headers] = config['headers'] if config['headers']
116
+ transport = config.slice(*TRANSPORT_KEYS).transform_keys(&:to_sym)
117
+ command = transport[:command]
118
+ if command.is_a?(Array)
119
+ transport[:command] = command.first
120
+ transport[:args] = Array(command[1..]) + Array(transport[:args])
121
+ end
122
+ transport[:args] = Array(transport[:args]) if transport.key?(:args)
123
+ transport[:type] ||= transport[:url] && !transport[:command] ? 'streamable-http' : 'stdio'
110
124
  transport
111
125
  end
112
126
 
@@ -114,38 +128,18 @@ module AIA
114
128
  def routing_metadata(config)
115
129
  meta = {}
116
130
  meta[:topics] = Array(config['topics']) if config['topics']
117
- meta[:independent] = config['independent'] unless config['independent'].nil?
118
131
  meta[:group] = config['group'] if config['group']
119
132
  meta
120
133
  end
121
134
 
122
- # Convert simple format to robot_lab nested transport format
135
+ # Convert simple format to robot_lab nested transport format. The
136
+ # server is named after the file ("filesystem.json" -> "filesystem").
123
137
  #
124
- # @param parsed [Hash] parsed JSON with type and command
138
+ # @param parsed [Hash] one server's settings
125
139
  # @param file_path [String] file path for deriving server name
126
140
  # @return [Array<Hash>] array with single server configuration
127
141
  def convert_simple_format(parsed, file_path)
128
- # Derive name from filename (e.g., "filesystem.json" -> "filesystem")
129
- name = File.basename(file_path, '.*')
130
-
131
- transport = { type: parsed['type'] || 'stdio' }
132
-
133
- command = parsed['command']
134
- if command.is_a?(Array)
135
- # Command is an array: first element is command, rest are args
136
- transport[:command] = command.first
137
- transport[:args] = command[1..] || []
138
- elsif command
139
- transport[:command] = command
140
- transport[:args] = parsed['args'] || []
141
- end
142
-
143
- transport[:env] = parsed['env'] if parsed['env']
144
-
145
- server = { name: name, transport: transport }
146
- server[:timeout] = parsed['timeout'].to_i if parsed['timeout']
147
-
148
- [server]
142
+ [build_server(File.basename(file_path, '.*'), parsed)]
149
143
  end
150
144
  end
151
145
  end
@@ -15,14 +15,6 @@ module AIA
15
15
  class ModelSpec
16
16
  attr_accessor :name, :role, :instance, :internal_id, :provider
17
17
 
18
- # Provider prefixes that map to RubyLLM provider slugs.
19
- # 'lms' is stored as-is; RobotFactory maps it to the openai provider
20
- # with a custom API base so it doesn't conflict with real OpenAI models.
21
- PROVIDER_ALIASES = {
22
- 'ollama' => 'ollama',
23
- 'lms' => 'lms'
24
- }.freeze
25
-
26
18
  def initialize(hash = {})
27
19
  hash = hash.transform_keys(&:to_sym) if hash.respond_to?(:transform_keys)
28
20
 
@@ -32,7 +24,7 @@ module AIA
32
24
  @internal_id = hash[:internal_id] || @name
33
25
  @provider = hash[:provider]
34
26
 
35
- # Extract provider from name if prefixed (e.g., "ollama/llama3" or "lms/my-model")
27
+ # Extract provider from name if prefixed (e.g., "<provider>/<model-id>")
36
28
  extract_provider_from_name! unless @provider
37
29
  end
38
30
 
@@ -84,15 +76,17 @@ module AIA
84
76
 
85
77
  private
86
78
 
87
- # Extract provider prefix from model name.
88
- # "ollama/llama3:latest" => provider: "ollama", name: "llama3:latest"
89
- # "lms/my-model" => provider: "openai", name: "my-model"
79
+ # Extract a provider prefix from the model name. The prefix is a provider
80
+ # exactly when RubyLLM knows it (registered already, or loadable as a
81
+ # conventional ruby_llm-providers-<prefix> gem) — no provider names are
82
+ # hardcoded here. Names whose first segment is not a provider (registry
83
+ # ids like "meta-llama/llama-4-maverick") pass through untouched.
90
84
  def extract_provider_from_name!
91
85
  return unless @name&.include?('/')
92
86
 
93
87
  prefix, rest = @name.split('/', 2)
94
- return unless PROVIDER_ALIASES.key?(prefix)
95
- @provider = PROVIDER_ALIASES[prefix]
88
+ return unless ProviderRegistry.available?(prefix)
89
+ @provider = prefix
96
90
  @name = rest
97
91
  end
98
92
  end
@@ -1,7 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'timeout'
4
+ require 'did_you_mean'
3
5
  require 'word_wrapper'
4
6
  require_relative '../skill_utils'
7
+ require_relative '../role_catalog'
5
8
 
6
9
  # lib/aia/config/validator.rb
7
10
  #
@@ -34,12 +37,13 @@ module AIA
34
37
  handle_executable_prompt(config)
35
38
  handle_stdin_as_prompt(config)
36
39
  return :early_exit if handle_early_exits(config) == :early_exit
37
- validate_required_prompt_id(config)
40
+ adopt_pipeline_head(config)
38
41
  process_role_configuration(config)
42
+ validate_model_roles(config)
43
+ validate_required_prompt_id(config)
39
44
  validate_plugins_dir(config)
40
45
  handle_fuzzy_search_prompt_id(config)
41
46
  normalize_boolean_flags(config)
42
- validate_final_prompt_requirements(config)
43
47
  prepare_pipeline(config)
44
48
  validate_pipeline_prompts(config)
45
49
 
@@ -51,6 +55,7 @@ module AIA
51
55
  return :early_exit if handle_mcp_list(config) == :early_exit
52
56
  return :early_exit if handle_list_tools(config) == :early_exit
53
57
  return :early_exit if handle_list_skills(config) == :early_exit
58
+ return :early_exit if handle_list_roles(config) == :early_exit
54
59
  :early_exit if handle_completion_script(config) == :early_exit
55
60
  end
56
61
 
@@ -93,6 +98,7 @@ module AIA
93
98
  "Did you mean: #{suggestions}?\n" \
94
99
  "Flags require a dash prefix (e.g., -B not _B)."
95
100
  end
101
+ raise AIA::ConfigurationError, missing_prompt_message(config, bad_files) if missing_prompt_id?(config, remaining_args, bad_files)
96
102
  raise AIA::ConfigurationError, "The following files do not exist: #{bad_files.join(', ')}"
97
103
  end
98
104
 
@@ -100,6 +106,31 @@ module AIA
100
106
  config.context_files += remaining_args
101
107
  end
102
108
 
109
+ # The first argument looks like a prompt ID (no extension) but names
110
+ # neither a prompt nor a file.
111
+ def missing_prompt_id?(config, remaining_args, bad_files)
112
+ word = remaining_args.first
113
+ config.prompt_id.nil? && bad_files.first == word && File.extname(word).empty?
114
+ end
115
+
116
+ def missing_prompt_message(config, bad_files)
117
+ word, *others = bad_files
118
+ dir = config.prompts.dir
119
+ message = "No prompt named '#{word}' in #{dir} (and no file by that name)."
120
+ suggestions = prompt_suggestions(word, dir, config.prompts.extname)
121
+ message += "\nDid you mean: #{suggestions.join(', ')}?" if suggestions.any?
122
+ message += "\nThe following files do not exist: #{others.join(', ')}" if others.any?
123
+ message
124
+ end
125
+
126
+ # Prompt IDs under +dir+ that are close spellings of +word+.
127
+ def prompt_suggestions(word, dir, extname)
128
+ return [] unless dir && Dir.exist?(dir)
129
+
130
+ ids = Dir.glob("**/*#{extname}", base: dir).map { it.delete_suffix(extname) }
131
+ DidYouMean::SpellChecker.new(dictionary: ids).correct(word).first(3)
132
+ end
133
+
103
134
  def handle_executable_prompt(config)
104
135
  return unless config.prompt_id.nil?
105
136
 
@@ -122,20 +153,34 @@ module AIA
122
153
  content = config.stdin_content
123
154
  return unless content && !content.strip.empty?
124
155
 
125
- if content.lines.first&.strip&.start_with?('#!')
126
- content = content.lines[1..].join
127
- end
128
-
129
- config.executable_prompt_content = content
156
+ config.executable_prompt_content = strip_shebang(content)
130
157
  config.stdin_content = nil
131
158
  config.prompt_id = '__EXECUTABLE_PROMPT__'
132
159
  end
133
160
 
161
+ # Piped text arrives with a leading newline (see process_stdin_content).
162
+ # Drop it, and a "#!" line if the text starts with one, so the front
163
+ # matter that follows is recognized.
164
+ def strip_shebang(content)
165
+ text = content.delete_prefix("\n")
166
+ text.start_with?('#!') ? text.lines[1..].join : text
167
+ end
168
+
169
+ # With no prompt ID, --pipeline's first prompt is the one to run.
170
+ def adopt_pipeline_head(config)
171
+ return unless config.prompt_id.nil? || config.prompt_id.empty?
172
+
173
+ head = Array(config.pipeline).first
174
+ config.prompt_id = head unless head.nil? || head.empty?
175
+ end
176
+
134
177
  def validate_required_prompt_id(config)
135
178
  return unless config.prompt_id.nil? && config.flags.chat != true && config.flags.fuzzy != true
136
179
 
137
180
  raise AIA::ConfigurationError,
138
- "A prompt ID is required unless using --chat, --fuzzy, or providing context files. Use -h or --help for help."
181
+ "A prompt ID is required unless you use --chat, --fuzzy, --pipeline or --role, " \
182
+ "pipe the prompt in, or run an executable prompt. Context files alone are not a prompt. " \
183
+ "Use -h or --help for help."
139
184
  end
140
185
 
141
186
  def process_role_configuration(config)
@@ -149,8 +194,6 @@ module AIA
149
194
  prompts.role = role
150
195
  end
151
196
 
152
- prompts.roles_dir ||= File.join(prompts.dir, roles_prefix.to_s)
153
-
154
197
  return if config.flags&.chat == true
155
198
 
156
199
  return unless config.prompt_id.nil? || config.prompt_id.empty?
@@ -223,7 +266,11 @@ module AIA
223
266
  def print_mcp_server(server_config)
224
267
  args_str = server_config.args.empty? ? '' : " #{server_config.args.join(' ')}"
225
268
  puts " #{server_config.name || '(unnamed)'}"
226
- puts " command: #{server_config.command || '(no command)'}#{args_str}"
269
+ if server_config.command.nil? && server_config.url
270
+ puts " url: #{server_config.url}"
271
+ else
272
+ puts " command: #{server_config.command || '(no command)'}#{args_str}"
273
+ end
227
274
  puts
228
275
  end
229
276
 
@@ -320,18 +367,13 @@ module AIA
320
367
  end
321
368
  end
322
369
 
370
+ # The servers --mcp-use/--mcp-skip keep. --require libraries are loaded
371
+ # first and entries naming a RubyLLM::MCP subclass are resolved to it,
372
+ # exactly as a session does before connecting.
323
373
  def filter_mcp_servers(config)
324
- servers = config.mcp_servers || []
325
- use_list = Array(config.mcp_use)
326
- skip_list = Array(config.mcp_skip)
327
-
328
- if !use_list.empty?
329
- servers.select { |s| use_list.include?(s[:name] || s['name']) }
330
- elsif !skip_list.empty?
331
- servers.reject { |s| skip_list.include?(s[:name] || s['name']) }
332
- else
333
- servers
334
- end
374
+ AIA::ToolLoader.require_libs(config)
375
+ selected = AIA::MCPDiscovery.select(config.mcp_servers || [], use: config.mcp_use, skip: config.mcp_skip)
376
+ AIA::MCPDiscovery.new.resolve_entries(selected)
335
377
  end
336
378
 
337
379
  def mcp_filter_active?(config)
@@ -361,38 +403,34 @@ module AIA
361
403
  :early_exit
362
404
  end
363
405
 
364
- def load_local_tools(config)
365
- require_configured_libs(config)
366
- require_tool_files(config)
367
- instantiable_tool_classes
368
- end
406
+ # --list-roles, from the configured prompts directory and roles prefix.
407
+ def handle_list_roles(config)
408
+ return unless config.respond_to?(:list_roles) && config.list_roles
369
409
 
370
- # :reek:DuplicateMethodCall -- each e.message belongs to a different rescue clause exception; nothing to hoist
371
- def require_configured_libs(config)
372
- Array(config.require_libs).each do |lib|
373
- require lib
374
- rescue LoadError => e
375
- $stderr.puts "Warning: Failed to require '#{lib}': #{e.message}"
376
- $stderr.puts "Hint: Make sure the gem is installed: gem install #{lib}"
377
- rescue StandardError => e
378
- $stderr.puts "Warning: Error in library '#{lib}': #{e.class} - #{e.message}"
379
- end
410
+ prompts = config.prompts
411
+ puts AIA::RoleCatalog.listing(prompts.dir, prompts.roles_prefix, extname: prompts.extname)
412
+ :early_exit
380
413
  end
381
414
 
382
- # Scan ObjectSpace for RubyLLM::Tool subclasses that can be instantiated.
383
- def instantiable_tool_classes
384
- ObjectSpace.each_object(Class).select do |klass|
385
- next false unless defined?(RubyLLM::Tool) && klass < RubyLLM::Tool
415
+ # Every -m MODEL=ROLE role must exist in the configured prompts directory.
416
+ def validate_model_roles(config)
417
+ prompts = config.prompts
418
+ Array(config.models).each do |spec|
419
+ role = spec.respond_to?(:role) ? spec.role : nil
420
+ next if role.nil? || role.to_s.empty?
386
421
 
387
- begin
388
- klass.new
389
- true
390
- rescue StandardError
391
- false
392
- end
422
+ AIA::RoleCatalog.validate!(role, dir: prompts.dir, prefix: prompts.roles_prefix, extname: prompts.extname)
393
423
  end
394
424
  end
395
425
 
426
+ # The local tools a session would offer: loaded the same way
427
+ # (--require gems, --tools files, lazily loaded tool gems) and narrowed
428
+ # by --allowed-tools / --rejected-tools.
429
+ def load_local_tools(config)
430
+ ToolLoader.load_tools(config)
431
+ ToolLoader.filtered_tools(config)
432
+ end
433
+
396
434
  def first_sentences(text, count)
397
435
  normalized = text.gsub(/\s*\n\s*/, ' ').gsub(/\s{2,}/, ' ').strip
398
436
  sentences = normalized.scan(/[^.!?]*[.!?]/)
@@ -405,61 +443,31 @@ module AIA
405
443
  servers = filter_mcp_servers(config)
406
444
  return {} if servers.empty?
407
445
 
408
- quiet_mcp_logger
409
-
410
446
  servers.each_with_object({}) do |server, groups|
411
447
  server_config = McpServerConfig.from_hash(server)
412
448
  $stderr.print "MCP: Connecting to #{server_config.name}..."
413
449
  $stderr.flush
414
450
 
415
- tools = collect_server_tools(server_config)
416
- if tools
417
- groups[server_config.name] = tools
418
- $stderr.puts " #{tools.size} tools"
419
- else
420
- $stderr.puts " failed"
421
- end
451
+ tools = collect_server_tools(server, server_config)
452
+ groups[server_config.name] = tools
453
+ $stderr.puts " #{tools.size} tools"
422
454
  rescue StandardError => e
423
455
  $stderr.puts " error: #{e.message}"
424
456
  end
425
457
  end
426
458
 
427
- # Connect to one server and return its tools, or nil when the client
428
- # never comes alive.
429
- def collect_server_tools(server_config)
430
- mcp_add_client(server_config)
431
- client = RubyLLM::MCP.clients[server_config.name]
432
- client.start
433
- return nil unless client.alive?
434
-
435
- client.tools rescue []
436
- end
437
-
438
- def mcp_add_client(server_config)
439
- mcp_config = { command: server_config.command, args: server_config.args }
440
- mcp_config[:env] = server_config.env unless server_config.env.empty?
441
-
442
- RubyLLM::MCP.add_client(
443
- name: server_config.name, transport_type: :stdio,
444
- config: mcp_config, request_timeout: server_config.timeout_ms, start: false
445
- )
446
- rescue ArgumentError
447
- # Older ruby_llm-mcp versions do not accept request_timeout
448
- RubyLLM::MCP.add_client(
449
- name: server_config.name, transport_type: :stdio,
450
- config: mcp_config, start: false
451
- )
459
+ # Build the server the way MCPConnectionManager does (RobotLab::MCP.build,
460
+ # so --list-tools shows exactly the RubyLLM::MCP::Tools a robot would be
461
+ # handed) and return its tools. Connection failures raise. The server is
462
+ # closed before returning.
463
+ def collect_server_tools(server, server_config)
464
+ mcp = RobotLab::MCP.build(MCPConfigNormalizer.normalize(server))
465
+ Timeout.timeout(server_config.timeout_ms / 1000.0) { mcp.tools }
466
+ ensure
467
+ mcp&.close
452
468
  end
453
469
  # rubocop:enable Metrics/ModuleLength
454
470
 
455
- def quiet_mcp_logger
456
- return unless defined?(RubyLLM::MCP) && RubyLLM::MCP.respond_to?(:config)
457
- mcp_config = RubyLLM::MCP.config
458
- return unless mcp_config.respond_to?(:logger=)
459
- quiet = Logger.new(File::NULL)
460
- mcp_config.logger = quiet
461
- end
462
-
463
471
  def handle_completion_script(config)
464
472
  return unless config.completion
465
473
 
@@ -470,21 +478,12 @@ module AIA
470
478
  def generate_completion_script(shell)
471
479
  script_path = File.join(File.dirname(__FILE__), "../aia_completion.#{shell}")
472
480
 
473
- if File.exist?(script_path)
474
- puts File.read(script_path)
475
- else
476
- $stderr.puts "ERROR: The shell '#{shell}' is not supported or the completion script is missing."
481
+ unless File.exist?(script_path)
482
+ raise AIA::ConfigurationError,
483
+ "ERROR: The shell '#{shell}' is not supported (use bash, zsh or fish)."
477
484
  end
478
- end
479
485
 
480
- def validate_final_prompt_requirements(config)
481
- chat_mode = config.flags.chat == true
482
- fuzzy_mode = config.flags.fuzzy == true
483
- no_prompt = config.prompt_id.nil? || config.prompt_id.empty?
484
- no_context = config.context_files.nil? || config.context_files.empty?
485
- return unless !chat_mode && !fuzzy_mode && no_prompt && no_context
486
- raise AIA::ConfigurationError,
487
- "A prompt ID is required unless using --chat, --fuzzy, or providing context files. Use -h or --help for help."
486
+ puts File.read(script_path)
488
487
  end
489
488
 
490
489
  def prepare_pipeline(config)
@@ -502,7 +501,7 @@ module AIA
502
501
  config.pipeline.each do |prompt_id|
503
502
  next if prompt_id.nil? || prompt_id.empty? || prompt_id == '__FUZZY_SEARCH__' || prompt_id == '__EXECUTABLE_PROMPT__'
504
503
 
505
- prompt_file_path = File.join(config.prompts.dir, "#{prompt_id}#{config.prompts.extname}")
504
+ prompt_file_path = AIA::SkillUtils.prompt_file_path(prompt_id, dir: config.prompts.dir, extname: config.prompts.extname)
506
505
  unless File.exist?(prompt_file_path)
507
506
  $stderr.puts "Error: Prompt ID '#{prompt_id}' does not exist at #{prompt_file_path}"
508
507
  and_exit = true