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
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ # lib/aia/role_catalog.rb
4
+ #
5
+ # Finding, checking and listing role files. Every function takes the prompts
6
+ # directory and roles prefix explicitly, so callers pass the configured
7
+ # values (--prompts-dir, the config file, AIA_PROMPTS__DIR) rather than
8
+ # guessing them.
9
+
10
+ require_relative 'skill_utils'
11
+ require_relative 'errors'
12
+
13
+ module AIA
14
+ # :reek:DataClump -- pure functions over (dir, prefix, extname) on purpose: callers pass the configured values explicitly (see above)
15
+ module RoleCatalog
16
+ module_function
17
+
18
+ # A role ID with the roles prefix added ("editor" -> "roles/editor").
19
+ # Path-based IDs and IDs that already carry the prefix are unchanged.
20
+ def qualified_id(role_id, prefix)
21
+ id = role_id.to_s
22
+ return id if SkillUtils.path_based_id?(id) || prefix.to_s.empty? || id.start_with?("#{prefix}/")
23
+
24
+ "#{prefix}/#{id}"
25
+ end
26
+
27
+ # The file a role ID names.
28
+ def role_file(role_id, dir:, prefix:, extname: '.md')
29
+ SkillUtils.prompt_file_path(qualified_id(role_id, prefix), dir: dir, extname: extname)
30
+ end
31
+
32
+ # Role IDs (without the prefix) under <dir>/<prefix>. Files and folders
33
+ # starting with "_" are private and not listed.
34
+ def names(dir, prefix, extname: '.md')
35
+ roles_dir = File.join(dir.to_s, prefix.to_s)
36
+ return [] unless Dir.exist?(roles_dir)
37
+
38
+ Dir.glob("**/*#{extname}", base: roles_dir)
39
+ .map { it.delete_suffix(extname) }
40
+ .reject { |f| f.split('/').any? { it.start_with?('_') } }
41
+ .sort
42
+ end
43
+
44
+ # Raise AIA::ConfigurationError unless the role's file exists.
45
+ def validate!(role_id, dir:, prefix:, extname: '.md')
46
+ file = role_file(role_id, dir: dir, prefix: prefix, extname: extname)
47
+ return if File.exist?(file)
48
+
49
+ message = if SkillUtils.path_based_id?(role_id)
50
+ "Role file not found: #{file}"
51
+ else
52
+ not_found_message(file, dir, prefix, extname)
53
+ end
54
+ raise AIA::ConfigurationError, message
55
+ end
56
+
57
+ def not_found_message(file, dir, prefix, extname = '.md')
58
+ available = names(dir, prefix, extname: extname)
59
+ message = "Role file not found: #{file}\n\n"
60
+
61
+ if available.empty?
62
+ message + "No roles directory found at #{File.join(dir.to_s, prefix.to_s)}\n" \
63
+ "Create the directory and add role files to use this feature."
64
+ else
65
+ message + "Available roles:\n" + available.map { " - #{it}" }.join("\n") +
66
+ "\n\nCreate the role file or use an existing role."
67
+ end
68
+ end
69
+
70
+ # The --list-roles report: a heading and front-matter table per role.
71
+ def listing(dir, prefix, extname: '.md')
72
+ roles_dir = File.join(dir.to_s, prefix.to_s)
73
+ unless Dir.exist?(roles_dir)
74
+ return "No roles directory found at #{roles_dir}\nCreate this directory and add role files to use roles."
75
+ end
76
+
77
+ roles = names(dir, prefix, extname: extname)
78
+ return "No role files found in #{roles_dir}\nCreate #{extname} files in this directory to define roles." if roles.empty?
79
+
80
+ roles.flat_map { listing_entry(roles_dir, it, extname) }.join("\n")
81
+ end
82
+
83
+ def listing_entry(roles_dir, role_id, extname)
84
+ front_matter = SkillUtils.parse_front_matter(File.join(roles_dir, "#{role_id}#{extname}"))
85
+ rows = front_matter.map { |key, value| "| #{key} | #{value.to_s.gsub('|', '\\|')} |" }
86
+ ["## #{role_id}", '', '| Key | Value |', '|-----|-------|', *rows, '']
87
+ end
88
+ end
89
+ end
data/lib/aia/session.rb CHANGED
@@ -11,6 +11,10 @@ require "reline"
11
11
  require "pm"
12
12
  require "json"
13
13
  require "fileutils"
14
+ # amazing_print 3.0's ActiveSupport extension assumes a fully loaded
15
+ # ActiveSupport (Object#try, LogSubscriber) and raises at require time otherwise
16
+ require "active_support"
17
+ require "active_support/core_ext/object/try"
14
18
  require "amazing_print"
15
19
  require_relative "directive_processor"
16
20
  require_relative "variable_input_collector"
@@ -40,15 +44,26 @@ module AIA
40
44
  def start
41
45
  cfg = AIA.config
42
46
 
47
+ # --require libraries first, so mcp_servers: entries can name the
48
+ # RubyLLM::MCP subclasses they define (e.g. SharedTools::MCP::Memory).
49
+ ToolLoader.require_libs(cfg)
50
+
51
+ # Connect MCP servers next: every robot built from here on is handed
52
+ # the same live server instances (see RobotFactory.mcp_servers).
53
+ @mcp_manager = MCPConnectionManager.start(cfg)
54
+
55
+ coordinator = StartupCoordinator.new(robot: nil, ui_presenter: @ui_presenter, mcp_manager: @mcp_manager)
56
+ coordinator.prepare_task_board
57
+
43
58
  # Build robot or network
44
59
  @robot = RobotFactory.build(cfg)
45
60
  AIA.client = @robot
61
+ @robot_sync = RobotSync.new(cfg, @robot)
46
62
 
47
- # Run all startup coordination: MCP, tools, filters, task board, bus
48
- coordinator = StartupCoordinator.new(robot: @robot, ui_presenter: @ui_presenter)
63
+ # Run the remaining startup coordination: tool filters, bus
64
+ coordinator.robot = @robot
49
65
  coordinator.run(cfg)
50
- @filters = coordinator.filters
51
- @mcp_manager = coordinator.mcp_manager
66
+ @filters = coordinator.filters
52
67
 
53
68
  # Store session tracker globally for KBS access
54
69
  AIA.session_tracker = @session_tracker
@@ -66,7 +81,8 @@ module AIA
66
81
  prompt_handler: @prompt_handler,
67
82
  input_collector: @input_collector,
68
83
  ui_presenter: @ui_presenter,
69
- session_tracker: @session_tracker
84
+ session_tracker: @session_tracker,
85
+ robot_sync: @robot_sync
70
86
  ).process(cfg)
71
87
 
72
88
  # Start chat mode after all prompts are processed
@@ -95,9 +111,6 @@ module AIA
95
111
  @input_collector = InputCollector.new
96
112
 
97
113
  @session_tracker = SessionTracker.new
98
- @alias_registry = ModelAliasRegistry.new(
99
- AIA.config.respond_to?(:model_aliases) ? (AIA.config.model_aliases || {}) : {}
100
- )
101
114
  @chat_loop = nil # created after robot is built
102
115
 
103
116
  rotate_history_log_if_needed
@@ -125,11 +138,12 @@ module AIA
125
138
  end
126
139
 
127
140
  def build_chat_loop
141
+ # A pipeline step may have rebuilt the client (front-matter model:)
128
142
  ChatLoop.new(
129
- @robot, @ui_presenter, @directive_processor,
143
+ AIA.client || @robot, @ui_presenter, @directive_processor,
130
144
  session_tracker: @session_tracker,
131
- alias_registry: @alias_registry,
132
- filters: @filters
145
+ filters: @filters,
146
+ robot_sync: @robot_sync
133
147
  )
134
148
  end
135
149
 
@@ -10,6 +10,17 @@ module AIA
10
10
  id.to_s.start_with?('/', './', '../', '~/')
11
11
  end
12
12
 
13
+ # The file a prompt ID names. A path-based ID ("./x", "~/p/x.md") is
14
+ # expanded, gaining +extname+ when it has none; any other ID is
15
+ # relative to +dir+.
16
+ def prompt_file_path(prompt_id, dir:, extname:)
17
+ id = prompt_id.to_s
18
+ return File.join(dir, "#{id}#{extname}") unless path_based_id?(id)
19
+
20
+ expanded = File.expand_path(id)
21
+ File.extname(expanded).empty? ? "#{expanded}#{extname}" : expanded
22
+ end
23
+
13
24
  def parse_front_matter(path)
14
25
  return {} unless File.exist?(path)
15
26
  content = File.read(path)
@@ -22,11 +33,26 @@ module AIA
22
33
  {}
23
34
  end
24
35
 
36
+ # File extensions a skill given as a file path may have.
37
+ SKILL_EXTENSIONS = %w[.md .markdown].freeze
38
+
39
+ # Whether +path+ names a file that can't be a skill (not markdown).
40
+ def non_markdown_skill_file?(path)
41
+ File.file?(path) && !SKILL_EXTENSIONS.include?(File.extname(path).downcase)
42
+ end
43
+
44
+ # The warning for a skill path that names a non-markdown file.
45
+ def non_markdown_skill_message(skill_id)
46
+ "Skill '#{skill_id}' is not a markdown file (#{SKILL_EXTENSIONS.join(' or ')})"
47
+ end
48
+
49
+ # A skill directory or markdown file. Path IDs may name either; a file
50
+ # must be markdown. Named skills are looked up in +base_dir+ only.
25
51
  def find_skill_dir(skill_name, base_dir)
26
52
  if path_based_id?(skill_name)
27
53
  expanded = File.expand_path(skill_name)
28
54
  return expanded if Dir.exist?(expanded)
29
- return expanded if File.file?(expanded)
55
+ return expanded if File.file?(expanded) && !non_markdown_skill_file?(expanded)
30
56
  return nil
31
57
  end
32
58
 
@@ -116,7 +142,6 @@ module AIA
116
142
  def load_skills_content(skill_ids, skills_base_dir)
117
143
  ids = Array(skill_ids).reject { |s| s.nil? || s.strip.empty? }
118
144
  return nil if ids.empty?
119
- return nil unless skills_base_dir && Dir.exist?(skills_base_dir)
120
145
 
121
146
  contents = ids.filter_map { |id| load_single_skill_content(id, skills_base_dir) }
122
147
  contents.empty? ? nil : contents.join("\n\n")
@@ -129,26 +154,42 @@ module AIA
129
154
  # @param skills_base_dir [String] base directory for named skills
130
155
  # @return [String, nil] skill body text, or nil on error
131
156
  def load_single_skill_content(skill_id, skills_base_dir)
157
+ problem = skill_load_problem(skill_id, skills_base_dir)
158
+ return skill_warning(problem) if problem
159
+
132
160
  skill_dir = find_skill_dir(skill_id, skills_base_dir)
133
- unless skill_dir
134
- $stderr.puts "Warning: Skill '#{skill_id}' not found in #{skills_base_dir}"
135
- return nil
136
- end
161
+ return skill_warning("Skill '#{skill_id}' not found in #{skills_base_dir}") unless skill_dir
137
162
 
138
- raw = if File.file?(skill_dir)
139
- File.read(skill_dir)
140
- else
141
- skill_path = File.join(skill_dir, 'SKILL.md')
142
- unless File.exist?(skill_path)
143
- $stderr.puts "Warning: SKILL.md not found in #{skill_dir}"
144
- return nil
145
- end
146
- File.read(skill_path)
147
- end
148
-
149
- skill_body(raw)
163
+ raw = read_skill_source(skill_dir)
164
+ raw && skill_body(raw)
150
165
  rescue StandardError => e
151
- $stderr.puts "Warning: Could not load skill '#{skill_id}': #{e.message}"
166
+ skill_warning("Could not load skill '#{skill_id}': #{e.message}")
167
+ end
168
+
169
+ # Why +skill_id+ can't be loaded before looking for it, or nil.
170
+ def skill_load_problem(skill_id, skills_base_dir)
171
+ path_id = path_based_id?(skill_id)
172
+ unless path_id || (skills_base_dir && Dir.exist?(skills_base_dir))
173
+ return "Skill '#{skill_id}' not loaded: skills directory #{skills_base_dir.inspect} does not exist"
174
+ end
175
+ return "#{non_markdown_skill_message(skill_id)}; not loaded" if path_id && non_markdown_skill_file?(File.expand_path(skill_id))
176
+
177
+ nil
178
+ end
179
+
180
+ # The raw text of a found skill: the file itself, or the folder's SKILL.md.
181
+ def read_skill_source(skill_dir)
182
+ return File.read(skill_dir) if File.file?(skill_dir)
183
+
184
+ skill_path = File.join(skill_dir, 'SKILL.md')
185
+ return File.read(skill_path) if File.exist?(skill_path)
186
+
187
+ skill_warning("SKILL.md not found in #{skill_dir}")
188
+ end
189
+
190
+ # Print a skill warning; returns nil so callers can `return skill_warning(...)`.
191
+ def skill_warning(message)
192
+ $stderr.puts "Warning: #{message}"
152
193
  nil
153
194
  end
154
195
 
@@ -43,7 +43,11 @@ module AIA
43
43
  # Spawn or reuse specialist (evict oldest when cache is full)
44
44
  specialist = @spawned[role] ||= begin
45
45
  evict_oldest! if @spawned.size >= MAX_CACHE_SIZE
46
- primary.spawn(name: role, system_prompt: instruction, **spawn_opts)
46
+ primary.spawn(
47
+ name: role, system_prompt: instruction,
48
+ **chief_tool_opts(primary),
49
+ **ToolApprover.options(AIA.config), **spawn_opts
50
+ )
47
51
  end
48
52
 
49
53
  @ui_presenter.display_info("Specialist '#{role}' responding...")
@@ -79,9 +83,7 @@ module AIA
79
83
  # @return [Array(String, String, Hash)] [role, instruction, spawn_opts]
80
84
  def resolve_specialist(context, primary, prompt)
81
85
  if (spec = context.spawn_spec)
82
- role = spec[:name]
83
- instruction = spec[:system_prompt] || "You are #{role}."
84
- [role, instruction, model_opts(spec)]
86
+ [spec[:name], Crew.compose_system_prompt(spec), model_opts(spec)]
85
87
  elsif (type = context.specialist_type)
86
88
  [type, "You are a #{type} specialist. Answer precisely within your domain of expertise.", {}]
87
89
  else
@@ -102,6 +104,16 @@ module AIA
102
104
  { model: spec[:model], provider: spec[:provider] }
103
105
  end
104
106
 
107
+ # The chief's local tools and MCP servers, so a specialist can do the
108
+ # same work. Empty sets are left out.
109
+ #
110
+ # @return [Hash]
111
+ def chief_tool_opts(primary)
112
+ tools = Crew.chief_local_tools(primary)
113
+ opts = tools.empty? ? {} : { local_tools: tools }
114
+ opts.merge(Crew.chief_mcp(primary))
115
+ end
116
+
105
117
  def evict_oldest!
106
118
  @spawned.delete(@spawned.keys.first)
107
119
  end
@@ -8,10 +8,10 @@ module AIA
8
8
  #
9
9
  # <name> <provider/model> <system prompt...>
10
10
  #
11
- # The second token is parsed as a model via {ModelSpec}, so
12
- # "ollama/qwen3.6:latest" yields model "qwen3.6:latest" + provider "ollama"
13
- # (and "lms/..." maps to the openai provider). Use "-" or "inherit" as the
14
- # model token to keep the parent robot's model and provider.
11
+ # The second token is parsed as a model via {ModelSpec}, so a
12
+ # "<provider>/<model>" spec yields the model plus its RubyLLM provider for
13
+ # any provider RubyLLM knows (see {ProviderRegistry}). Use "-" or "inherit"
14
+ # as the model token to keep the parent robot's model and provider.
15
15
  #
16
16
  # Any token of the form "skill:<id>" (anywhere after the name) is pulled out
17
17
  # as a skill assignment and returned in :skills; "skill:a,b" lists several.
@@ -57,9 +57,8 @@ module AIA
57
57
  def self.parse_model(token)
58
58
  return [nil, nil] if token.nil? || INHERIT_TOKENS.include?(token.downcase)
59
59
 
60
- spec = ModelSpec.new(name: token)
61
- provider = spec.provider == 'lms' ? 'openai' : spec.provider
62
- [spec.name, provider]
60
+ spec = ModelSpec.new(name: token)
61
+ [spec.name, RobotFactory.resolve_provider(spec)]
63
62
  end
64
63
  end
65
64
  end
@@ -14,26 +14,24 @@ module AIA
14
14
  class SpecialModeHandler
15
15
  include ContentExtractor
16
16
 
17
- # Special-mode dispatch table. Each row is triggered by a TurnState flag and
17
+ # Special-mode dispatch table. Each row is triggered by a TurnState mode and
18
18
  # runs either a bespoke method (`run:`) or, for the uniform "sub-handler
19
19
  # returns content" family, the shared #run_sub_handler (`sub:`). Adding a
20
20
  # mode means adding a row here plus (for a bespoke mode) its handle_* method
21
21
  # — never editing #handle.
22
22
  MODES = [
23
- { flag: :force_verify, run: :handle_verification },
24
- { flag: :force_decompose, run: :handle_decomposition },
25
- { flag: :force_concurrent_mcp, run: :handle_concurrent_mcp },
26
- { flag: :force_debate, sub: { handler: :debate_handler, label: 'Debate' } },
27
- { flag: :force_delegate, sub: { handler: :delegate_handler, label: 'Delegation' } },
28
- { flag: :force_spawn, sub: { handler: :spawn_handler, label: 'Spawn',
29
- context: lambda { |prompt, ts|
30
- type = ts.spawn_type
31
- spec = ts.spawn_spec
32
- ts.spawn_type = nil
33
- ts.spawn_spec = nil
34
- { prompt: prompt, specialist_type: type, spawn_spec: spec }
35
- } } },
36
- { flag: :force_orchestrate, run: :handle_orchestration }
23
+ { mode: :verify, run: :handle_verification },
24
+ { mode: :decompose, run: :handle_decomposition },
25
+ { mode: :concurrent_mcp, run: :handle_concurrent_mcp },
26
+ # live: the handler already displayed its output turn by turn, so the
27
+ # returned transcript is only saved (--output), not displayed again.
28
+ { mode: :debate, sub: { handler: :debate_handler, label: 'Debate', live: true } },
29
+ { mode: :delegate, sub: { handler: :delegate_handler, label: 'Delegation' } },
30
+ { mode: :spawn, sub: { handler: :spawn_handler, label: 'Spawn',
31
+ context: lambda { |prompt, taken|
32
+ { prompt: prompt, specialist_type: taken[:spawn_type], spawn_spec: taken[:spawn_spec] }
33
+ } } },
34
+ { mode: :orchestrate, run: :handle_orchestration }
37
35
  ].freeze
38
36
 
39
37
  # Memoized sub-handler accessors, used to propagate a robot swap.
@@ -66,15 +64,14 @@ module AIA
66
64
  # @param prompt [String] the user prompt
67
65
  # @return [Boolean]
68
66
  def handle(prompt)
69
- turn_state = AIA.turn_state
70
- mode = MODES.find { |m| turn_state.public_send(m[:flag]) }
71
- return false unless mode
67
+ taken = AIA.turn_state.consume!
68
+ return false unless taken
72
69
 
73
- turn_state.public_send(:"#{mode[:flag]}=", false)
74
- if mode[:sub]
75
- run_sub_handler(mode[:sub], prompt, turn_state)
70
+ row = MODES.find { |m| m[:mode] == taken[:mode] }
71
+ if row[:sub]
72
+ run_sub_handler(row[:sub], prompt, taken)
76
73
  else
77
- send(mode[:run], prompt)
74
+ send(row[:run], prompt)
78
75
  end
79
76
  end
80
77
 
@@ -83,12 +80,12 @@ module AIA
83
80
  # Run a "sub-handler returns content" mode: debate / delegate / spawn share
84
81
  # this exact shape, differing only by handler, label, and (spawn) an extra
85
82
  # context field built by spec[:context].
86
- def run_sub_handler(spec, prompt, turn_state)
87
- ctx_args = spec[:context] ? spec[:context].call(prompt, turn_state) : { prompt: prompt }
83
+ def run_sub_handler(spec, prompt, taken)
84
+ ctx_args = spec[:context] ? spec[:context].call(prompt, taken) : { prompt: prompt }
88
85
  content = send(spec[:handler]).handle(HandlerContext.new(**ctx_args))
89
86
  return false unless content
90
87
 
91
- display_and_save(content)
88
+ spec[:live] ? save_live_output(content) : display_and_save(content)
92
89
  true
93
90
  rescue StandardError => e
94
91
  @ui_presenter.display_info("#{spec[:label]} failed: #{e.message}. Falling back to normal mode.")
@@ -287,6 +284,12 @@ module AIA
287
284
  @ui_presenter.display_separator
288
285
  end
289
286
 
287
+ # For a handler that displayed its output as it went: save, don't repeat.
288
+ def save_live_output(content)
289
+ output_to_file(content)
290
+ @ui_presenter.display_separator
291
+ end
292
+
290
293
  # Aggregate token counts from all sub-task raw results plus the synthesis
291
294
  # result and display a combined metrics table. Only runs when --tokens is set.
292
295
  # :reek:TooManyStatements -- sums token usage across sub-task results plus synthesis, then prints the metrics block
data/lib/aia/speech.rb CHANGED
@@ -2,58 +2,87 @@
2
2
 
3
3
  # lib/aia/speech.rb
4
4
  #
5
- # Shared text-to-speech behavior for interactive handlers (ChatLoop,
6
- # MentionRouter). ContentExtractor duck-calls #speak on any includer
7
- # that responds to it, so both sides route through this one pipeline.
5
+ # Shared text-to-speech behavior. Interactive handlers (ChatLoop,
6
+ # MentionRouter) include it: ContentExtractor duck-calls #speak on any
7
+ # includer that responds to it, and #speak only talks when --speak is on.
8
+ # The /say directive calls Speech.speak_text directly.
9
+
10
+ require 'shellwords'
8
11
 
9
12
  module AIA
10
13
  module Speech
11
- private
14
+ # Players tried in order when audio.player is not set.
15
+ PLAYERS = [
16
+ %w[afplay],
17
+ %w[mpv --no-video --really-quiet],
18
+ %w[ffplay -nodisp -autoexit -loglevel quiet],
19
+ %w[mpg123 -q]
20
+ ].freeze
12
21
 
13
- # :reek:TooManyStatements -- two-stage TTS pipeline (convert, then play) with spinner and tempfile cleanup
14
- def speak(content)
15
- return unless AIA.speak?
22
+ module_function
16
23
 
24
+ # Speak +text+ with the configured speak command (audio.speak_command,
25
+ # default macOS `say`), whether or not --speak is on.
26
+ #
27
+ # @param text [String]
28
+ # :reek:TooManyStatements -- two-stage TTS pipeline (convert, then play) with spinner and tempfile cleanup
29
+ def speak_text(text)
17
30
  audio = AIA.config.audio
18
31
  command = audio.speak_command || 'say'
19
- voice = audio.voice
20
- text = content.to_s
21
32
  env = {}
22
33
  env['SPEECH_MODEL'] = audio.speech_model if audio.speech_model
23
34
 
24
35
  if command == 'say'
25
36
  # Local TTS: say converts and plays in one step
26
- run_with_spinner("Speaking...") do
27
- if voice && !voice.to_s.strip.empty?
28
- system(env, command, '-v', voice, text)
29
- else
30
- system(env, command, text)
31
- end
32
- end
37
+ run_with_spinner("Speaking...") { system(env, *say_command(audio.voice, text)) }
33
38
  else
34
- # Custom TTS script: stage 2 = convert text → audio file,
35
- # stage 3 = play the file. AIA passes the output path as $2.
36
- require 'tempfile'
37
- tmpfile = Tempfile.new(['aia-tts-', '.mp3'])
38
- tmpfile.close
39
- path = tmpfile.path
40
- begin
41
- run_with_spinner("Converting to audio...") do
42
- system(env, command, text, path)
43
- end
44
- if File.size?(path)
45
- run_with_spinner("Speaking...") do
46
- system('afplay', path)
47
- end
48
- end
49
- ensure
50
- tmpfile.unlink
51
- end
39
+ speak_with_script(env, command, text)
52
40
  end
53
41
  rescue StandardError => e
54
42
  $stderr.puts "Warning: Speech failed: #{e.message}"
55
43
  end
56
44
 
45
+ # The macOS `say` argument list, with -v VOICE when a voice is set.
46
+ def say_command(voice, text)
47
+ voice.nil? || voice.to_s.strip.empty? ? ['say', text] : ['say', '-v', voice, text]
48
+ end
49
+
50
+ # Custom TTS script: convert text to an audio file (AIA passes the
51
+ # output path as $2), then play the file.
52
+ def speak_with_script(env, command, text)
53
+ require 'tempfile'
54
+ tmpfile = Tempfile.new(['aia-tts-', '.mp3'])
55
+ tmpfile.close
56
+ path = tmpfile.path
57
+ run_with_spinner("Converting to audio...") { system(env, command, text, path) }
58
+ play(path) if File.size?(path)
59
+ ensure
60
+ tmpfile&.unlink
61
+ end
62
+
63
+ # Play an audio file with audio.player, or the first known player found.
64
+ def play(path)
65
+ player = player_command(AIA.config.audio.player)
66
+ unless player
67
+ $stderr.puts "Warning: No audio player found. Set audio.player (for example `mpv`)."
68
+ return
69
+ end
70
+
71
+ run_with_spinner("Speaking...") { system(*player, path) }
72
+ end
73
+
74
+ # The player command as an argument list: the configured one (split like
75
+ # a shell would), or the first of PLAYERS on the PATH.
76
+ def player_command(configured)
77
+ return Shellwords.split(configured.to_s) unless configured.to_s.strip.empty?
78
+
79
+ PLAYERS.find { on_path?(it.first) }
80
+ end
81
+
82
+ def on_path?(program)
83
+ ENV['PATH'].to_s.split(File::PATH_SEPARATOR).any? { File.executable?(File.join(it, program)) }
84
+ end
85
+
57
86
  def run_with_spinner(message)
58
87
  spinner = TTY::Spinner.new("[:spinner] #{message}", format: :bouncing_ball, output: $stderr)
59
88
  spinner.auto_spin
@@ -63,5 +92,12 @@ module AIA
63
92
  spinner.stop
64
93
  end
65
94
  end
95
+
96
+ # Speak a response when --speak is on.
97
+ def speak(content)
98
+ return unless AIA.speak?
99
+
100
+ Speech.speak_text(content.to_s)
101
+ end
66
102
  end
67
103
  end