aia 2.0.0 → 2.1.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.
data/lib/aia/config.rb CHANGED
@@ -227,7 +227,7 @@ module AIA
227
227
  apply_models_env_var unless overrides[:models]
228
228
  apply_plugins_dir_env_var unless overrides[:plugins_dir]
229
229
  apply_overrides(overrides) if overrides && !overrides.empty?
230
- apply_default_provider
230
+ apply_cli_provider(overrides.key?(:models) ? :fill : :replace)
231
231
  expand_paths
232
232
  process_mcp_files(overrides[:mcp_files]) if overrides[:mcp_files]
233
233
  end
@@ -382,13 +382,22 @@ module AIA
382
382
  end
383
383
  end
384
384
 
385
- # `--provider SLUG` gives prefixless models a default provider. A model
386
- # named with an explicit "<provider>/" prefix keeps its own.
387
- def apply_default_provider
385
+ # `--provider SLUG` on the command line. Given together with --model
386
+ # (+mode+ :fill), it is the provider for the models named there without
387
+ # a "<provider>/" prefix; an explicit prefix keeps its own provider,
388
+ # since both values come from the command line. Given without --model
389
+ # (+mode+ :replace), the models from AIA_MODEL or the config file keep
390
+ # their names but take this provider, prefix or not, because a
391
+ # command-line flag outranks both.
392
+ #
393
+ # @param mode [Symbol] :fill or :replace
394
+ def apply_cli_provider(mode)
388
395
  return if provider.nil? || provider.to_s.empty?
389
396
 
390
397
  Array(models).each do |spec|
391
- spec.provider ||= provider if spec.respond_to?(:provider)
398
+ next unless spec.respond_to?(:provider)
399
+
400
+ spec.provider = provider if mode == :replace || spec.provider.nil?
392
401
  end
393
402
  end
394
403
 
@@ -9,6 +9,9 @@
9
9
  # Decomposition is delegated to TaskDecomposer.
10
10
  # Step execution is delegated to TaskExecutor.
11
11
 
12
+ require_relative 'task_decomposer'
13
+ require_relative 'task_executor'
14
+
12
15
  module AIA
13
16
  class DelegateHandler
14
17
  include ContentExtractor
data/lib/aia/errors.rb CHANGED
@@ -36,4 +36,8 @@ module AIA
36
36
 
37
37
  # Raised when all sub-tasks fail in SpecialModeHandler decompose mode
38
38
  class DecomposeError < Error; end
39
+
40
+ # Raised when a robot's LLM call fails during a batch (non-chat) pipeline
41
+ # step; robot_lab shields the exception into reply text, this surfaces it
42
+ class LLMError < Error; end
39
43
  end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ # lib/aia/llm_error_collector.rb
4
+ #
5
+ # A robot_lab hook that remembers the exceptions robots raise while a
6
+ # pipeline step runs. robot_lab's Network shields a robot's exception into
7
+ # an "Error: ..." reply so one failing robot cannot crash the network, which
8
+ # also hides the failure from aia: a batch run would print the error as the
9
+ # answer and exit 0. The on_error hook fires before the shield, so the
10
+ # PipelineOrchestrator can ask afterwards whether the step really failed.
11
+
12
+ module AIA
13
+ class LLMErrorCollector < RobotLab::Hook
14
+ Entry = Data.define(:robot_name, :error) do
15
+ def to_s
16
+ prefix = robot_name.empty? ? '' : "#{robot_name}: "
17
+ "#{prefix}#{error.class}: #{error.message}"
18
+ end
19
+ end
20
+
21
+ @errors = []
22
+ @mutex = Mutex.new
23
+
24
+ class << self
25
+ # Register the collector on +registry+ once. robot_lab's global
26
+ # registry (the default) is consulted by every Robot#run, including
27
+ # the robots a Network runs in parallel threads.
28
+ #
29
+ # @param registry [RobotLab::HookRegistry]
30
+ def install!(registry = RobotLab.hooks)
31
+ return if registry.registrations.any? { |reg| reg.handler_class == self }
32
+
33
+ registry.on(self)
34
+ end
35
+
36
+ # robot_lab hook: a robot run raised +ctx.error+.
37
+ #
38
+ # @param ctx [RobotLab::RunHookContext]
39
+ def on_error(ctx)
40
+ robot_name = ctx.respond_to?(:robot) ? ctx.robot&.name.to_s : ''
41
+ @mutex.synchronize { @errors << Entry.new(robot_name: robot_name, error: ctx.error) }
42
+ end
43
+
44
+ # Forget the errors of the previous step.
45
+ def reset!
46
+ @mutex.synchronize { @errors.clear }
47
+ end
48
+
49
+ # @return [Array<Entry>] the errors recorded since the last reset!
50
+ def errors
51
+ @mutex.synchronize { @errors.dup }
52
+ end
53
+
54
+ def errors?
55
+ !errors.empty?
56
+ end
57
+
58
+ # One line naming the prompt and every distinct error it hit.
59
+ #
60
+ # @param prompt_id [String]
61
+ # @return [String]
62
+ def message(prompt_id)
63
+ "LLM error in prompt '#{prompt_id}': #{errors.map(&:to_s).uniq.join('; ')}"
64
+ end
65
+ end
66
+ end
67
+ end
data/lib/aia/logger.rb CHANGED
@@ -18,8 +18,9 @@
18
18
  # file: STDOUT
19
19
  # level: warn
20
20
  # mcp:
21
- # file: STDOUT
21
+ # file: ~/.config/aia/logs/mcp.log
22
22
  # level: warn
23
+ # server_stderr: ~/.config/aia/logs/mcp_servers.log # stdio server stderr
23
24
  #
24
25
  # Lumberjack provides structured logging, context isolation,
25
26
  # automatic log file rolling, and multi-process safe file writes.
@@ -30,6 +31,7 @@
30
31
  # AIA::LoggerManager.clear_test_logs! # between tests
31
32
  # entries = AIA::LoggerManager.aia_logger.device.entries # inspect logs
32
33
 
34
+ require 'fileutils'
33
35
  require 'lumberjack'
34
36
 
35
37
  module AIA
@@ -287,6 +289,7 @@ module AIA
287
289
  Lumberjack::Device::Writer.new($stderr, autoflush: flush)
288
290
  else
289
291
  path = File.expand_path(file)
292
+ FileUtils.mkdir_p(File.dirname(path))
290
293
  # Daily date rolling via Logger::LogDevice, which also makes the
291
294
  # file safe for multiple loggers to write to
292
295
  Lumberjack::Device::LogFile.new(
@@ -0,0 +1,102 @@
1
+ # lib/aia/patches/mcp_stdio_stderr.rb
2
+ #
3
+ # Redirect the stderr of stdio MCP server processes away from the terminal.
4
+ #
5
+ # ruby_llm 2.1's RubyLLM::MCP::Stdio#start launches each server with
6
+ # Open3.popen2, so the child inherits aia's stderr ("Its stderr is the
7
+ # parent's"). Every server banner, npm notice, stack trace and Python
8
+ # validation dump then lands on the terminal, interleaved with the
9
+ # TTY::Spinner::Multi "Connecting MCP servers" display, which corrupts it.
10
+ # (ruby_llm-mcp 1.x used popen3 and drained stderr, so aia 1.x was quiet.)
11
+ #
12
+ # The destination comes from AIA.config.logger.mcp.server_stderr:
13
+ # a file path - appended to (default: ~/.config/aia/logs/mcp_servers.log)
14
+ # STDERR - the old passthrough behavior
15
+ # null - discard (also: none, /dev/null)
16
+ #
17
+ # Stdio#start has no hook for spawn options, so this re-implements its
18
+ # three-line body. It is guarded against drift: if a future ruby_llm drops
19
+ # Stdio#start, the patch is skipped with a warning instead of breaking MCP.
20
+
21
+ require 'fileutils'
22
+ require 'open3'
23
+
24
+ module AIA
25
+ module MCPStdioStderr
26
+ DEFAULT_PATH = '~/.config/aia/logs/mcp_servers.log'.freeze
27
+ DISCARD = %w[NULL NONE /DEV/NULL].freeze
28
+
29
+ class << self
30
+ # The spawn option value for a server's stderr.
31
+ #
32
+ # @param setting [String, nil] logger.mcp.server_stderr
33
+ # @return [Array(String, String), nil] [path, mode] for Process.spawn's
34
+ # err: option, or nil to inherit the parent's stderr
35
+ def spawn_target(setting = configured_setting)
36
+ value = setting.to_s.strip
37
+ value = DEFAULT_PATH if value.empty?
38
+
39
+ case value.upcase
40
+ when 'STDERR' then nil
41
+ when *DISCARD then [File::NULL, 'w']
42
+ else log_file_target(value)
43
+ end
44
+ end
45
+
46
+ # Spawn options for Open3 with the stderr redirect added.
47
+ #
48
+ # @param options [Hash] options ruby_llm would pass (e.g. chdir:)
49
+ # @param target [Array, nil] from .spawn_target
50
+ # @return [Hash]
51
+ def spawn_options(options, target = spawn_target)
52
+ target ? options.merge(err: target) : options
53
+ end
54
+
55
+ # Install the patch onto RubyLLM::MCP::Stdio (idempotent).
56
+ #
57
+ # @return [Class, nil] the patched class, or nil when it can't be patched
58
+ def install!(stdio = stdio_class)
59
+ return unless stdio&.private_method_defined?(:start)
60
+
61
+ stdio.prepend(StdioPatch) unless stdio.ancestors.include?(StdioPatch)
62
+ stdio
63
+ end
64
+
65
+ private
66
+
67
+ def configured_setting
68
+ AIA.config&.logger&.mcp&.server_stderr
69
+ rescue StandardError
70
+ nil # config not loaded yet (or malformed): fall back to the default file
71
+ end
72
+
73
+ def log_file_target(value)
74
+ path = File.expand_path(value)
75
+ FileUtils.mkdir_p(File.dirname(path))
76
+ [path, 'a']
77
+ rescue SystemCallError
78
+ [File::NULL, 'w'] # unwritable location: still keep the terminal clean
79
+ end
80
+
81
+ def stdio_class
82
+ RubyLLM::MCP::Stdio if defined?(RubyLLM::MCP::Stdio)
83
+ end
84
+ end
85
+
86
+ # Prepended onto RubyLLM::MCP::Stdio.
87
+ module StdioPatch
88
+ private
89
+
90
+ def start
91
+ options = @directory ? { chdir: @directory } : {}
92
+ options = MCPStdioStderr.spawn_options(options)
93
+ @stdin, @stdout, @process = Open3.popen2(@env, *@command, **options)
94
+ @buffer = +''
95
+ end
96
+ end
97
+ end
98
+ end
99
+
100
+ unless AIA::MCPStdioStderr.install!
101
+ warn 'AIA: RubyLLM::MCP::Stdio#start not found; MCP server stderr will reach the terminal'
102
+ end
@@ -38,6 +38,8 @@ module AIA
38
38
  bridge = config.flags.track_pipeline ? TrakFlowBridge.new : nil
39
39
  bridge&.create_plan_from_pipeline(config.pipeline)
40
40
 
41
+ LLMErrorCollector.install!
42
+
41
43
  until config.pipeline.empty?
42
44
  prompt_id = config.pipeline.shift
43
45
  next if prompt_id.nil? || prompt_id.empty?
@@ -69,7 +71,15 @@ module AIA
69
71
  # Front matter may have changed the model or its settings
70
72
  @robot = @robot_sync.call(@robot) if @robot_sync
71
73
 
74
+ LLMErrorCollector.reset!
75
+ if special_mode_handled?(prompt_text)
76
+ bridge&.update_step_status(prompt_id, :completed) unless llm_errors_handled?(prompt_id, bridge)
77
+ return
78
+ end
79
+
72
80
  result, content = compute_result(prompt_text, config)
81
+ return if llm_errors_handled?(prompt_id, bridge)
82
+
73
83
  bridge&.update_step_status(prompt_id, :completed)
74
84
 
75
85
  @tracker.record_turn(model: config.models.first.name, input: prompt_text, result: result)
@@ -79,6 +89,46 @@ module AIA
79
89
  raise
80
90
  end
81
91
 
92
+ # robot_lab shields a robot's exception into an "Error: ..." reply, so a
93
+ # failed LLM call comes back looking like an answer. The collector hook
94
+ # saw the real exception. Outside chat the step fails and aia exits 1
95
+ # (see AIA.run); in a chat session the error is shown and the session
96
+ # carries on. True when the step failed.
97
+ def llm_errors_handled?(prompt_id, bridge)
98
+ return false unless LLMErrorCollector.errors?
99
+
100
+ message = LLMErrorCollector.message(prompt_id)
101
+ raise AIA::LLMError, message unless AIA.chat?
102
+
103
+ @ui.display_info(message)
104
+ @ui.display_separator
105
+ bridge&.update_step_status(prompt_id, :failed, reason: message)
106
+ true
107
+ end
108
+
109
+ # A directive in the prompt (/debate, /verify, /decompose, /delegate,
110
+ # /spawn, /orchestrate) asked for a special mode: hand the turn to the
111
+ # SpecialModeHandler, as ChatLoop does. True when it ran the turn, which
112
+ # includes displaying, saving and recording it. Concurrent MCP is left
113
+ # to execute_prompt, which honors it alongside config.concurrency.auto.
114
+ # A --paint step has no robot turn to hand over.
115
+ def special_mode_handled?(prompt_text)
116
+ return false if AIA.paint? || !special_mode_requested?
117
+
118
+ special_mode_handler.robot = @robot
119
+ special_mode_handler.handle(prompt_text)
120
+ end
121
+
122
+ # True when the turn state holds a mode for SpecialModeHandler to run.
123
+ def special_mode_requested?
124
+ mode = AIA.turn_state.active_mode
125
+ !mode.nil? && mode != :concurrent_mcp
126
+ end
127
+
128
+ def special_mode_handler
129
+ @special_mode_handler ||= SpecialModeHandler.new(robot: @robot, ui_presenter: @ui, tracker: @tracker)
130
+ end
131
+
82
132
  # Show a step's response, then save and speak it. A --paint step saved
83
133
  # an image next to the output file, so there is no text to keep or speak.
84
134
  def present_result(content, result, config)
@@ -108,16 +158,16 @@ module AIA
108
158
  img_cfg = config.image
109
159
  quality = img_cfg.quality
110
160
  style = img_cfg.style
111
- params = {}
112
- params[:quality] = quality if quality && !quality.to_s.strip.empty?
113
- params[:style] = style if style && !style.to_s.strip.empty?
161
+ provider_options = {}
162
+ provider_options[:quality] = quality if quality && !quality.to_s.strip.empty?
163
+ provider_options[:style] = style if style && !style.to_s.strip.empty?
114
164
 
115
165
  image = @ui.with_spinner("Generating image") do
116
166
  RubyLLM.paint(
117
167
  prompt_text,
118
- model: img_cfg.model || 'gpt-image-1',
119
- size: img_cfg.size || '1024x1024',
120
- params: params
168
+ model: img_cfg.model || 'gpt-image-1',
169
+ size: img_cfg.size || '1024x1024',
170
+ provider_options:
121
171
  )
122
172
  end
123
173
 
@@ -22,6 +22,9 @@ module AIA
22
22
  'erb' => [%w[config erb], %w[config flags erb]]
23
23
  }.freeze
24
24
 
25
+ # Front matter `mode:` names that differ from their TurnState mode.
26
+ MODE_SHORTHANDS = { 'concurrent' => :concurrent_mcp }.freeze
27
+
25
28
  def initialize
26
29
  @prompts_dir = AIA.config.prompts.dir
27
30
 
@@ -36,6 +39,22 @@ module AIA
36
39
  register_pm_directives
37
40
  end
38
41
 
42
+ # The TurnState mode a front matter `mode:` +value+ names: a chat
43
+ # directive's name without the slash (debate, verify, decompose,
44
+ # delegate, spawn, orchestrate, concurrent).
45
+ #
46
+ # @param value [String, Symbol]
47
+ # @return [Symbol] one of TurnState::EXCLUSIVE_MODES
48
+ # @raise [ConfigurationError] for a name that is not a mode
49
+ def self.mode_for(value)
50
+ name = value.to_s.strip.downcase
51
+ mode = MODE_SHORTHANDS.fetch(name, name.to_sym)
52
+ return mode if TurnState::EXCLUSIVE_MODES.include?(mode)
53
+
54
+ names = (TurnState::EXCLUSIVE_MODES - MODE_SHORTHANDS.values).map(&:to_s) + MODE_SHORTHANDS.keys
55
+ raise ConfigurationError, "Unknown mode: #{value.inspect} (one of #{names.sort.join(', ')})"
56
+ end
57
+
39
58
  # A shell/erb flag is on unless it is explicitly false.
40
59
  #
41
60
  # @param flags [#shell, #erb, nil]
@@ -212,6 +231,11 @@ module AIA
212
231
 
213
232
  erb_val = shorthand(meta_hash, :erb)
214
233
  cfg.flags.erb = erb_val unless erb_val.nil?
234
+
235
+ # mode → the special mode for this prompt's turn, as the chat
236
+ # directive of that name (/debate, /verify, ...) would request it
237
+ mode_val = shorthand(meta_hash, :mode)
238
+ AIA.turn_state.request(self.class.mode_for(mode_val)) if mode_val
215
239
  end
216
240
 
217
241
  # Fetch a front-matter shorthand value by string or symbol key.
@@ -37,7 +37,9 @@ module AIA
37
37
  # Attempt to require the conventional gem path for a provider slug.
38
38
  # Returns true when the provider ends up registered. Failed lookups are
39
39
  # cached so repeated non-provider prefixes (model ids also use "/")
40
- # don't pay the require cost every time.
40
+ # don't pay the require cost every time. When the plain require fails
41
+ # because aia runs under Bundler and the gem is installed but not in the
42
+ # Gemfile, the gem is sideloaded from the RubyGems search path.
41
43
  def load(slug)
42
44
  slug = slug.to_s
43
45
  return false unless slug.match?(/\A[a-z0-9_]+\z/)
@@ -50,22 +52,71 @@ module AIA
50
52
  require "ruby_llm/providers/#{slug}"
51
53
  registered?(slug)
52
54
  rescue LoadError
53
- false
55
+ sideload(slug)
54
56
  end
55
57
  end
56
58
 
59
+ # Load an installed `ruby_llm-providers-<slug>` gem that the active
60
+ # bundle hides. Under Bundler only the Gemfile's gems can be required,
61
+ # so a provider gem added with `gem install` is invisible to a plain
62
+ # require even though it sits on disk. This finds its gemspec on the
63
+ # RubyGems search path and, when every runtime dependency it declares is
64
+ # already satisfied by the bundle, adds its lib directory to the load
65
+ # path and requires it. The bundle itself is not changed. Returns true
66
+ # when the provider ends up registered.
67
+ def sideload(slug)
68
+ spec = installed_spec(slug)
69
+ return false unless spec
70
+
71
+ unmet = spec.runtime_dependencies.reject { |dep| dependency_met?(dep) }
72
+ unless unmet.empty?
73
+ AIA.debug_warn("#{spec.full_name} is installed but needs #{unmet.join(', ')}, which this bundle does not provide")
74
+ return false
75
+ end
76
+
77
+ spec.full_require_paths.each { |dir| $LOAD_PATH.unshift(dir) unless $LOAD_PATH.include?(dir) }
78
+ require "ruby_llm/providers/#{slug}"
79
+ registered?(slug)
80
+ rescue LoadError
81
+ false
82
+ end
83
+
84
+ # The newest installed gemspec for `ruby_llm-providers-<slug>`, read from
85
+ # the specifications directories on the RubyGems search path, or nil.
86
+ # Reads the files directly, so it sees gems the bundle does not.
87
+ def installed_spec(slug)
88
+ name = "ruby_llm-providers-#{slug}"
89
+ Gem.path
90
+ .flat_map { |dir| Dir[File.join(dir, 'specifications', "#{name}-*.gemspec")] }
91
+ .filter_map { |file| Gem::Specification.load(file) }
92
+ .select { |spec| spec.name == name }
93
+ .max_by(&:version)
94
+ end
95
+
96
+ # Whether a gem dependency is satisfied by a gem already active in this
97
+ # process (under Bundler, that is the bundle).
98
+ def dependency_met?(dep)
99
+ active = Gem.loaded_specs[dep.name]
100
+ !active.nil? && dep.requirement.satisfied_by?(active.version)
101
+ end
102
+
57
103
  # A provider instance ready for API calls (model listing etc.).
58
104
  # Raises RubyLLM's own errors for unknown or unconfigured providers.
59
105
  def instantiate(slug)
60
106
  RubyLLM::Provider.resolve!(slug.to_sym).new(RubyLLM.config)
61
107
  end
62
108
 
63
- # Slugs of conventionally named provider gems visible to the bundle
64
- # (ruby_llm-providers-<slug>), whether or not they are loaded yet.
109
+ # Slugs of conventionally named provider gems (ruby_llm-providers-<slug>)
110
+ # that are installed, whether in the bundle or only on the RubyGems
111
+ # search path, and whether or not they are loaded yet.
65
112
  def installed_gem_slugs
66
- Gem::Specification.filter_map do |spec|
67
- spec.name.delete_prefix('ruby_llm-providers-') if spec.name.start_with?('ruby_llm-providers-')
68
- end.uniq
113
+ prefix = 'ruby_llm-providers-'
114
+ bundled = Gem::Specification.map(&:name)
115
+ on_disk = Gem.path.flat_map { |dir| Dir[File.join(dir, 'specifications', "#{prefix}*.gemspec")] }
116
+ .map { |file| File.basename(file, '.gemspec').sub(/-[^-]+\z/, '') }
117
+ (bundled + on_disk).select { |name| name.start_with?(prefix) }
118
+ .map { |name| name.delete_prefix(prefix) }
119
+ .uniq
69
120
  end
70
121
 
71
122
  # Register every installed conventional provider gem, so a full listing
@@ -243,9 +243,49 @@ module AIA
243
243
  # @return [RobotLab::Robot]
244
244
  def build_robot(spec, **opts)
245
245
  opts[:provider] = resolve_provider(spec) if spec.provider
246
+ opts = without_tools(spec, opts) unless provider_accepts_tools?(spec.provider)
246
247
  RobotLab.build(model: spec.name, **opts)
247
248
  end
248
249
 
250
+ # Whether a provider can take RubyLLM tools. Agent-CLI providers
251
+ # (claude_code, codex, copilot) run their own tools and say so with a
252
+ # class-level `accepts_tools?` returning false; every other provider
253
+ # accepts tools. Nothing is hardcoded here — the provider class decides.
254
+ #
255
+ # @param provider [String, nil] a RubyLLM provider slug
256
+ # @return [Boolean]
257
+ def provider_accepts_tools?(provider)
258
+ klass = provider && ProviderRegistry.providers[provider.to_s]
259
+ return true unless klass.respond_to?(:accepts_tools?)
260
+
261
+ klass.accepts_tools?
262
+ end
263
+
264
+ # Strip the tools and MCP servers from a robot's build options for a
265
+ # provider that brings its own, telling the user once per provider what
266
+ # was left out so a `--tools` or `--mcp-use` that silently did nothing
267
+ # is not a mystery.
268
+ #
269
+ # @param spec [AIA::ModelSpec]
270
+ # @param opts [Hash] RobotLab.build options
271
+ # @return [Hash] opts with empty local_tools: and mcp:
272
+ def without_tools(spec, opts)
273
+ dropped = []
274
+ dropped << 'tools' if opts[:local_tools]&.any?
275
+ dropped << 'MCP servers' if opts[:mcp]&.any?
276
+ notice_tools_dropped(spec.provider, dropped) unless dropped.empty?
277
+ opts.merge(local_tools: [], mcp: [])
278
+ end
279
+
280
+ # One notice per provider per process.
281
+ def notice_tools_dropped(provider, dropped)
282
+ @tools_dropped_notices ||= {}
283
+ return if @tools_dropped_notices[provider]
284
+
285
+ @tools_dropped_notices[provider] = true
286
+ AIA.debug_warn("#{provider} runs its own tools; aia #{dropped.join(' and ')} are not attached to it")
287
+ end
288
+
249
289
  # Resolve a spec's provider to a RubyLLM provider slug. Slugs pass
250
290
  # through unchanged — RubyLLM's registry is the single source of truth —
251
291
  # but the method stays as the seam where optional provider gems get
@@ -265,10 +305,23 @@ module AIA
265
305
 
266
306
  AIA.debug_warn(
267
307
  "provider '#{provider}' is not registered with RubyLLM and no " \
268
- "ruby_llm/providers/#{provider} library could be loaded"
308
+ "ruby_llm/providers/#{provider} library could be loaded#{bundler_hint(provider)}"
269
309
  )
270
310
  end
271
311
 
312
+ # Under Bundler only the gems in the Gemfile can be required, so a
313
+ # provider gem installed with `gem install` stays invisible. Name the
314
+ # Gemfile to add it to; outside Bundler there is nothing to add.
315
+ #
316
+ # @param provider [String] a provider slug
317
+ # @param gemfile [String, nil] the active Gemfile; nil when not under Bundler
318
+ # @return [String] text to append to the warning, "" outside Bundler
319
+ def bundler_hint(provider, gemfile = ENV.fetch('BUNDLE_GEMFILE', nil))
320
+ return '' if gemfile.nil? || gemfile.empty?
321
+
322
+ "; aia is running under Bundler, so add gem 'ruby_llm-providers-#{provider}' to #{gemfile}"
323
+ end
324
+
272
325
  private
273
326
 
274
327
  # Configure RobotLab providers from AIA config
@@ -253,8 +253,6 @@ module AIA
253
253
  def delegate_handler
254
254
  @delegate_handler ||= begin
255
255
  require_relative 'delegate_handler'
256
- require_relative 'task_decomposer'
257
- require_relative 'task_executor'
258
256
  DelegateHandler.new(
259
257
  robot: @robot, ui_presenter: @ui_presenter,
260
258
  tracker: @tracker, task_coordinator: AIA.task_coordinator
@@ -7,6 +7,8 @@
7
7
  # with full TaskBoardTool access. Foreman is built on first use
8
8
  # and cached for the session.
9
9
 
10
+ require_relative 'task_board_tool'
11
+
10
12
  module AIA
11
13
  class DelegateToForemanTool < RubyLLM::Tool
12
14
  description "Delegate a task management request to Foreman, the task board manager. " \
data/lib/aia/version.rb CHANGED
@@ -1,13 +1,5 @@
1
1
  # lib/aia/version.rb
2
- #
3
- # This file defines the version of the AIA application.
4
- # The VERSION constant defines the current version of the AIA application,
5
- # which is read from the .version file in the project root.
6
2
 
7
- # The AIA module serves as the namespace for the AIA application, which
8
- # provides an interface for interacting with AI models and managing prompts.
9
3
  module AIA
10
- # The VERSION constant defines the current version of the AIA application,
11
- # which is read from the .version file in the project root.
12
- VERSION = File.read(File.join(File.dirname(__FILE__), '..', '..', '.version')).strip
4
+ VERSION = '2.1.0'.freeze
13
5
  end
data/lib/aia.rb CHANGED
@@ -53,6 +53,7 @@ require_relative 'aia/robot_sync'
53
53
  require_relative 'aia/robot_builder'
54
54
  require_relative 'aia/directive_processor'
55
55
  require_relative 'aia/variable_input_collector'
56
+ require_relative 'aia/patches/mcp_stdio_stderr'
56
57
  require_relative 'aia/ui_presenter'
57
58
  require_relative 'aia/input_collector'
58
59
  require_relative 'aia/handler_context'
@@ -72,6 +73,7 @@ require_relative 'aia/mention_router'
72
73
  require_relative 'aia/special_mode_handler'
73
74
  require_relative 'aia/mcp_connection_manager'
74
75
  require_relative 'aia/startup_coordinator'
76
+ require_relative 'aia/llm_error_collector'
75
77
  require_relative 'aia/pipeline_orchestrator'
76
78
  require_relative 'aia/chat_loop'
77
79
  require_relative 'aia/session'
@@ -184,16 +186,23 @@ module AIA
184
186
  RobotFactory.setup(@config)
185
187
  load_fzf_integration
186
188
  start_session
187
- rescue AIA::ConfigurationError => e
188
- $stderr.puts e.message
189
- exit 1
190
189
  rescue AIA::Error => e
191
- $stderr.puts e.message
192
- exit 1
190
+ fail_run(e.message)
191
+ rescue RubyLLM::Error, RubyLLM::ConfigurationError => e
192
+ # An LLM failure that nothing shielded (image generation, provider setup)
193
+ fail_run("LLM error: #{e.class}: #{e.message}")
193
194
  end
194
195
 
195
196
  private
196
197
 
198
+ # Print a one-line fatal error to stderr and exit 1.
199
+ #
200
+ # @param message [String]
201
+ def fail_run(message)
202
+ $stderr.puts message
203
+ exit 1
204
+ end
205
+
197
206
  # Record startup in all three log files. Only aia.log gets the full
198
207
  # configuration dump; llm.log and mcp.log just note that AIA started,
199
208
  # since their configuration is already covered by the aia.log entry.