aia 2.0.0.0.pre.alpha → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. checksums.yaml +4 -4
  2. data/.version +1 -1
  3. data/CHANGELOG.md +151 -228
  4. data/README.md +42 -19
  5. data/bin/aia +8 -3
  6. data/lib/aia/aia_completion.bash +2 -3
  7. data/lib/aia/aia_completion.fish +6 -5
  8. data/lib/aia/aia_completion.zsh +2 -3
  9. data/lib/aia/chat_loop.rb +24 -66
  10. data/lib/aia/config/cli_parser.rb +164 -123
  11. data/lib/aia/config/defaults.yml +12 -39
  12. data/lib/aia/config/mcp_parser.rb +42 -40
  13. data/lib/aia/config/model_spec.rb +8 -14
  14. data/lib/aia/config/validator.rb +144 -156
  15. data/lib/aia/config/value_caster.rb +76 -0
  16. data/lib/aia/config.rb +72 -54
  17. data/lib/aia/content_extractor.rb +2 -0
  18. data/lib/aia/cost_calculator.rb +1 -0
  19. data/lib/aia/crew.rb +29 -19
  20. data/lib/aia/debate_handler.rb +45 -20
  21. data/lib/aia/delegate_handler.rb +7 -3
  22. data/lib/aia/directive.rb +10 -8
  23. data/lib/aia/directives/configuration_directives.rb +164 -109
  24. data/lib/aia/directives/context_directives.rb +55 -40
  25. data/lib/aia/directives/execution_directives.rb +25 -25
  26. data/lib/aia/directives/model_directives.rb +112 -195
  27. data/lib/aia/directives/trakflow_directives.rb +27 -9
  28. data/lib/aia/directives/utility_directives.rb +86 -87
  29. data/lib/aia/directives/web_and_file_directives.rb +83 -63
  30. data/lib/aia/fact_asserter.rb +3 -3
  31. data/lib/aia/history_transfer.rb +64 -24
  32. data/lib/aia/layered_orchestrator.rb +66 -43
  33. data/lib/aia/logger.rb +27 -62
  34. data/lib/aia/mcp_config_normalizer.rb +27 -14
  35. data/lib/aia/mcp_connection_manager.rb +193 -186
  36. data/lib/aia/mcp_discovery.rb +43 -15
  37. data/lib/aia/mcp_grouper.rb +2 -1
  38. data/lib/aia/mcp_server_config.rb +48 -0
  39. data/lib/aia/mcp_utility.rb +28 -20
  40. data/lib/aia/mention_router.rb +22 -52
  41. data/lib/aia/modality_query.rb +36 -0
  42. data/lib/aia/model_alias_registry.rb +11 -11
  43. data/lib/aia/model_registry.rb +75 -0
  44. data/lib/aia/network_builder.rb +17 -11
  45. data/lib/aia/network_memory_manager.rb +6 -6
  46. data/lib/aia/patches/ruby_llm_streaming_error.rb +21 -4
  47. data/lib/aia/patches/ruby_llm_tool_param_compat.rb +18 -0
  48. data/lib/aia/pipeline_orchestrator.rb +88 -45
  49. data/lib/aia/plugin_monitor.rb +9 -6
  50. data/lib/aia/prompt_decomposer.rb +6 -4
  51. data/lib/aia/prompt_handler.rb +90 -69
  52. data/lib/aia/provider_registry.rb +105 -0
  53. data/lib/aia/robot_builder.rb +1 -1
  54. data/lib/aia/robot_factory.rb +77 -69
  55. data/lib/aia/robot_namer.rb +2 -8
  56. data/lib/aia/robot_sync.rb +79 -0
  57. data/lib/aia/role_catalog.rb +89 -0
  58. data/lib/aia/session.rb +32 -14
  59. data/lib/aia/session_tracker.rb +39 -41
  60. data/lib/aia/similarity_scorer.rb +5 -3
  61. data/lib/aia/skill_utils.rb +60 -19
  62. data/lib/aia/spawn_handler.rb +16 -4
  63. data/lib/aia/spawn_spec_parser.rb +6 -7
  64. data/lib/aia/special_mode_handler.rb +80 -57
  65. data/lib/aia/speech.rb +103 -0
  66. data/lib/aia/startup_coordinator.rb +17 -91
  67. data/lib/aia/streaming_runner.rb +16 -5
  68. data/lib/aia/system_prompt_assembler.rb +20 -15
  69. data/lib/aia/task_board.rb +60 -0
  70. data/lib/aia/task_coordinator.rb +10 -5
  71. data/lib/aia/timing.rb +15 -0
  72. data/lib/aia/tool_approver.rb +205 -0
  73. data/lib/aia/tool_filter.rb +1 -9
  74. data/lib/aia/tool_filter_strategy.rb +39 -25
  75. data/lib/aia/tool_introspection.rb +25 -0
  76. data/lib/aia/tool_loader.rb +71 -31
  77. data/lib/aia/tool_utility.rb +6 -5
  78. data/lib/aia/tools/delegate_to_foreman_tool.rb +6 -4
  79. data/lib/aia/tools/recruit_robot_tool.rb +12 -12
  80. data/lib/aia/tools/reskill_robot_tool.rb +7 -7
  81. data/lib/aia/tools/task_board_tool.rb +17 -16
  82. data/lib/aia/trakflow_bridge.rb +19 -11
  83. data/lib/aia/turn_state.rb +32 -8
  84. data/lib/aia/ui_presenter.rb +83 -59
  85. data/lib/aia/utility.rb +8 -24
  86. data/lib/aia/variable_input_collector.rb +1 -3
  87. data/lib/aia/verification_network.rb +10 -12
  88. data/lib/aia.rb +49 -8
  89. metadata +27 -162
  90. data/.better-commits.json +0 -150
  91. data/.config/tocer/configuration.yml +0 -6
  92. data/.envrc +0 -15
  93. data/.loki +0 -231
  94. data/.quality/flay_baseline.txt +0 -1
  95. data/.quality/flog_baseline.txt +0 -29
  96. data/.quality/reek_baseline.txt +0 -80
  97. data/.rubocop.yml +0 -116
  98. data/COMMITS.md +0 -196
  99. data/IMPLEMENTATION_PLAN.md +0 -506
  100. data/Rakefile +0 -160
  101. data/architecture_review.md +0 -314
  102. data/docs/AGENTS.md +0 -40
  103. data/docs/advanced-prompting.md +0 -814
  104. data/docs/assets/images/aia.png +0 -0
  105. data/docs/cli-reference.md +0 -1241
  106. data/docs/configuration.md +0 -747
  107. data/docs/contributing.md +0 -386
  108. data/docs/directives-reference.md +0 -1145
  109. data/docs/examples/index.md +0 -277
  110. data/docs/examples/mcp/index.md +0 -475
  111. data/docs/examples/prompts/analysis/index.md +0 -78
  112. data/docs/examples/prompts/automation/index.md +0 -109
  113. data/docs/examples/prompts/development/index.md +0 -125
  114. data/docs/examples/prompts/index.md +0 -333
  115. data/docs/examples/prompts/learning/index.md +0 -127
  116. data/docs/examples/prompts/writing/index.md +0 -62
  117. data/docs/examples/tools/index.md +0 -282
  118. data/docs/faq.md +0 -578
  119. data/docs/guides/available-models.md +0 -366
  120. data/docs/guides/basic-usage.md +0 -478
  121. data/docs/guides/chat.md +0 -680
  122. data/docs/guides/crew.md +0 -239
  123. data/docs/guides/executable-prompts.md +0 -331
  124. data/docs/guides/first-prompt.md +0 -454
  125. data/docs/guides/getting-started.md +0 -455
  126. data/docs/guides/image-generation.md +0 -507
  127. data/docs/guides/index.md +0 -48
  128. data/docs/guides/local-models.md +0 -306
  129. data/docs/guides/migrate-prompts.md +0 -335
  130. data/docs/guides/models.md +0 -1017
  131. data/docs/guides/shared-tools.md +0 -254
  132. data/docs/guides/tools.md +0 -831
  133. data/docs/index.md +0 -259
  134. data/docs/installation.md +0 -274
  135. data/docs/mcp-integration.md +0 -603
  136. data/docs/prompt_management.md +0 -665
  137. data/docs/security.md +0 -674
  138. data/docs/special_projects_guide.md +0 -386
  139. data/docs/tools-and-mcp-examples.md +0 -1211
  140. data/docs/workflows-and-pipelines.md +0 -636
  141. data/examples/.gitignore +0 -2
  142. data/examples/00_setup_aia.sh +0 -111
  143. data/examples/01_basic_usage.sh +0 -23
  144. data/examples/02_frontmatter.sh +0 -33
  145. data/examples/03_shell_integration.sh +0 -55
  146. data/examples/04_erb_templating.sh +0 -56
  147. data/examples/05_shell_then_erb.sh +0 -38
  148. data/examples/06_prompt_chaining.sh +0 -59
  149. data/examples/07_pipeline.sh +0 -46
  150. data/examples/08_context_files.sh +0 -43
  151. data/examples/09_roles.sh +0 -67
  152. data/examples/10_stdin_piping.sh +0 -49
  153. data/examples/11_multi_model.sh +0 -65
  154. data/examples/12_token_usage.sh +0 -52
  155. data/examples/13_cost_tracking.sh +0 -68
  156. data/examples/14_output_file.sh +0 -91
  157. data/examples/15_parameters.sh +0 -68
  158. data/examples/16_directives.sh +0 -113
  159. data/examples/17_require_and_conditionals.sh +0 -68
  160. data/examples/18_tools.sh +0 -61
  161. data/examples/19_local_tools.sh +0 -34
  162. data/examples/20_mcp_servers.sh +0 -102
  163. data/examples/21_executable_prompts.sh +0 -78
  164. data/examples/22_chat_mode.sh +0 -217
  165. data/examples/23_verify.sh +0 -139
  166. data/examples/24_decompose.sh +0 -139
  167. data/examples/25_spawn.sh +0 -139
  168. data/examples/26_debate.sh +0 -97
  169. data/examples/27_mention_routing.sh +0 -157
  170. data/examples/28_model_switching.sh +0 -106
  171. data/examples/29_agent_harness.sh +0 -177
  172. data/examples/README.md +0 -321
  173. data/examples/advanced_multi_robot_capabilities_without_examples.md +0 -106
  174. data/examples/aia_config.yml +0 -22
  175. data/examples/aia_config_orchestrator.yml +0 -45
  176. data/examples/aia_config_with_mcp.yml +0 -21
  177. data/examples/common.sh +0 -39
  178. data/examples/context/project_goals.md +0 -6
  179. data/examples/context/tech_stack.md +0 -7
  180. data/examples/directives/timestamp_directive.rb +0 -22
  181. data/examples/mcp/filesystem.json +0 -9
  182. data/examples/prompts_dir/analyze.md +0 -2
  183. data/examples/prompts_dir/brainstorm.md +0 -2
  184. data/examples/prompts_dir/conditional.md +0 -17
  185. data/examples/prompts_dir/creative.md +0 -4
  186. data/examples/prompts_dir/erbinfo.md +0 -5
  187. data/examples/prompts_dir/erbinfo_raw.md +0 -8
  188. data/examples/prompts_dir/evaluate.md +0 -2
  189. data/examples/prompts_dir/explain_joke.md +0 -1
  190. data/examples/prompts_dir/explain_recursion.md +0 -1
  191. data/examples/prompts_dir/fun_fact +0 -3
  192. data/examples/prompts_dir/greeting.md +0 -8
  193. data/examples/prompts_dir/greeting_required.md +0 -7
  194. data/examples/prompts_dir/hello.md +0 -1
  195. data/examples/prompts_dir/includes/ruby_facts.md +0 -4
  196. data/examples/prompts_dir/limerick.md +0 -1
  197. data/examples/prompts_dir/list_with_mcp.md +0 -3
  198. data/examples/prompts_dir/pick_best.md +0 -2
  199. data/examples/prompts_dir/project_summary +0 -12
  200. data/examples/prompts_dir/quiz_with_include.md +0 -6
  201. data/examples/prompts_dir/require_demo.md +0 -5
  202. data/examples/prompts_dir/roles/formal.md +0 -3
  203. data/examples/prompts_dir/roles/orchestrator.md +0 -21
  204. data/examples/prompts_dir/roles/pirate.md +0 -3
  205. data/examples/prompts_dir/shell_then_erb.md +0 -6
  206. data/examples/prompts_dir/sort_compare.md +0 -2
  207. data/examples/prompts_dir/summarize_context.md +0 -2
  208. data/examples/prompts_dir/sysinfo.md +0 -5
  209. data/examples/prompts_dir/sysinfo_raw.md +0 -8
  210. data/examples/prompts_dir/tagline.md +0 -1
  211. data/examples/prompts_dir/tell_joke.md +0 -1
  212. data/examples/prompts_dir/tell_joke_with_next.md +0 -4
  213. data/examples/prompts_dir/use_local_tool.md +0 -8
  214. data/examples/prompts_dir/use_tools.md +0 -8
  215. data/examples/prompts_dir/weather.md +0 -2
  216. data/examples/prompts_dir/whats_new.md +0 -2
  217. data/examples/prompts_dir/with_timestamp.md +0 -5
  218. data/examples/requirements/sinatra_taskflow_app.md +0 -139
  219. data/examples/rules/01_classify_ruby.rb +0 -16
  220. data/examples/rules/02_prefer_claude_for_code.rb +0 -19
  221. data/examples/rules/03_gate_prompt_length.rb +0 -19
  222. data/examples/rules/04_tool_selection.rb +0 -41
  223. data/examples/rules/README.md +0 -30
  224. data/examples/run_all.sh +0 -294
  225. data/examples/tools/word_count_tool.rb +0 -30
  226. data/lib/AGENTS.md +0 -57
  227. data/lib/aia/model_switch_handler.rb +0 -100
  228. data/mcp_servers/README.md +0 -110
  229. data/mcp_servers/apple-mcp.json +0 -8
  230. data/mcp_servers/filesystem.json +0 -9
  231. data/mcp_servers/mcp_server_chart.json +0 -11
  232. data/mcp_servers/playwright_one.json +0 -8
  233. data/mcp_servers/playwright_server_definition.json +0 -9
  234. data/mcp_servers/playwright_two.json +0 -8
  235. data/mcp_servers/tavily_mcp_server.json +0 -8
  236. data/mkdocs.yml +0 -169
@@ -28,6 +28,8 @@ module AIA
28
28
  # @param spinner_message [String] spinner label
29
29
  # @param tools [Array<String>, nil] tool names to allow for this turn (nil = all)
30
30
  # @return [Array(Object, String, Float)] [result, streamed_content_or_nil, elapsed_seconds]
31
+ # :reek:TooManyStatements -- one streaming turn: spinner lifecycle, chunk-filter closure, robot run with cleanup, timing
32
+ # :reek:DuplicateMethodCall -- @spinner.stop guards three distinct control paths (first chunk, exception, completion)
31
33
  def run(robot, prompt, header: "\nAI:\n ", spinner_message: "Processing...", tools: nil)
32
34
  @spinner.reset
33
35
  @spinner.update(title: spinner_message)
@@ -63,7 +65,7 @@ module AIA
63
65
  tools_param = resolve_tools_param(tools, robot)
64
66
 
65
67
  begin
66
- result = robot.run(prompt, mcp: :inherit, tools: tools_param, &streaming_block)
68
+ result = with_approval_spinner { robot.run(prompt, mcp: :inherit, tools: tools_param, &streaming_block) }
67
69
  rescue Exception # rubocop:disable Lint/RescueException
68
70
  @spinner.stop unless header_printed
69
71
  raise
@@ -77,6 +79,14 @@ module AIA
77
79
 
78
80
  private
79
81
 
82
+ # Let ToolApprover pause this turn's spinner while an approval prompt is on screen.
83
+ def with_approval_spinner
84
+ ToolApprover.spinner = @spinner
85
+ yield
86
+ ensure
87
+ ToolApprover.spinner = nil
88
+ end
89
+
80
90
  # Translate the resolved tool list into robot_lab's ToolConfig vocabulary,
81
91
  # then clamp it to the provider's limit:
82
92
  # nil -> :inherit (no filter active / filter errored — use the full set)
@@ -107,11 +117,12 @@ module AIA
107
117
 
108
118
  max = max_tools
109
119
  names = tools_param == :inherit ? robot_tool_names(robot) : tools_param
110
- return tools_param if names.size <= max
120
+ size = names.size
121
+ return tools_param if size <= max
111
122
 
112
- dropped = names.size - max
123
+ dropped = size - max
113
124
  $stderr.puts(
114
- "⚠ Tool list (#{names.size}) exceeds the provider limit of #{max}; " \
125
+ "⚠ Tool list (#{size}) exceeds the provider limit of #{max}; " \
115
126
  "sending #{max}, dropping #{dropped}. Enable --auto-tool-filter or reduce " \
116
127
  "the available tools to control which ones are sent."
117
128
  )
@@ -129,7 +140,7 @@ module AIA
129
140
  def robot_tool_names(robot)
130
141
  local = robot.respond_to?(:local_tools) ? Array(robot.local_tools) : []
131
142
  mcp = robot.respond_to?(:mcp_tools) ? Array(robot.mcp_tools) : []
132
- (local + mcp).map { |t| t.respond_to?(:name) ? t.name : t.class.name }
143
+ (local + mcp).map { |t| ToolIntrospection.tool_name(t) }
133
144
  end
134
145
 
135
146
  def show_thinking?
@@ -6,7 +6,9 @@
6
6
  # Extracted from RobotFactory to isolate the prompt assembly concern.
7
7
  # Completely stateless — no module ivars.
8
8
 
9
+ require 'pm'
9
10
  require_relative 'skill_utils'
11
+ require_relative 'role_catalog'
10
12
 
11
13
  module AIA
12
14
  module SystemPromptAssembler
@@ -18,9 +20,10 @@ module AIA
18
20
  # @param model_spec [ModelSpec, nil] optional model spec with role override
19
21
  # @return [String, nil] the assembled system prompt
20
22
  def resolve_system_prompt(config, model_spec = nil)
21
- system_prompt = config.prompts.system_prompt
23
+ prompts_cfg = config.prompts
24
+ system_prompt = prompts_cfg.system_prompt
22
25
 
23
- role_id = model_spec&.role || config.prompts.role
26
+ role_id = model_spec&.role || prompts_cfg.role
24
27
  if role_id && !role_id.empty?
25
28
  role_content = load_role_content(config, role_id)
26
29
  if role_content
@@ -32,7 +35,7 @@ module AIA
32
35
  # Pipeline mode appends skills to each prompt text instead (pipeline_orchestrator).
33
36
  if config.flags&.chat == true
34
37
  skill_content = AIA::SkillUtils.load_skills_content(
35
- Array(config.prompts&.skills),
38
+ Array(prompts_cfg&.skills),
36
39
  AIA::SkillUtils.skills_base_dir(config)
37
40
  )
38
41
  system_prompt = [system_prompt, skill_content].compact.join("\n\n") if skill_content
@@ -48,6 +51,7 @@ module AIA
48
51
  # @param spec [ModelSpec] this robot's model spec
49
52
  # @param roster [Array<Hash>] all robots: [{ name:, spec: }, ...]
50
53
  # @return [String]
54
+ # :reek:TooManyStatements -- builds the identity line plus a roster entry per teammate; one cohesive prompt fragment
51
55
  def build_identity_prompt(robot_name, spec, roster)
52
56
  provider_label = spec.provider ? " (#{spec.provider})" : ""
53
57
  lines = ["You are #{robot_name}, powered by #{spec.name}#{provider_label}."]
@@ -55,9 +59,10 @@ module AIA
55
59
  if roster.size > 1
56
60
  lines << "You are part of a team of AI robots:"
57
61
  roster.each do |entry|
58
- p = entry[:spec].provider ? " (#{entry[:spec].provider})" : ""
62
+ entry_spec = entry[:spec]
63
+ p = entry_spec.provider ? " (#{entry_spec.provider})" : ""
59
64
  marker = entry[:name] == robot_name ? " ← you" : ""
60
- lines << " - #{entry[:name]}: #{entry[:spec].name}#{p}#{marker}"
65
+ lines << " - #{entry[:name]}: #{entry_spec.name}#{p}#{marker}"
61
66
  end
62
67
  lines << "Users can address a specific robot with @name mentions."
63
68
  end
@@ -65,21 +70,21 @@ module AIA
65
70
  lines.join("\n")
66
71
  end
67
72
 
68
- # Load role file content.
73
+ # Load a role for the system prompt. Named roles come from the roles
74
+ # folder of the prompts directory; path-based roles from anywhere. The
75
+ # file is processed like a prompt: front matter removed, shell and ERB
76
+ # expanded.
69
77
  #
70
78
  # @param config [AIA::Config] the AIA configuration
71
- # @param role_id [String] the role identifier
72
- # @return [String, nil] the role file content or nil
79
+ # @param role_id [String] the role identifier or path
80
+ # @return [String, nil] the rendered role, or nil if it is missing or fails
73
81
  def load_role_content(config, role_id)
74
- roles_prefix = config.prompts.roles_prefix
75
- unless role_id.start_with?(roles_prefix)
76
- role_id = "#{roles_prefix}/#{role_id}"
77
- end
78
-
79
- role_file = File.join(config.prompts.dir, "#{role_id}#{config.prompts.extname}")
82
+ prompts_cfg = config.prompts
83
+ role_file = AIA::RoleCatalog.role_file(role_id, dir: prompts_cfg.dir, prefix: prompts_cfg.roles_prefix,
84
+ extname: prompts_cfg.extname)
80
85
  return nil unless File.exist?(role_file)
81
86
 
82
- File.read(role_file)
87
+ PM.parse(Pathname.new(role_file)).to_s
83
88
  rescue => e
84
89
  $stderr.puts "Warning: Could not load role '#{role_id}': #{e.message}"
85
90
  nil
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ # lib/aia/task_board.rb
4
+ #
5
+ # The TrakFlow task board, started on first use. Nothing touches the disk
6
+ # until a feature that records tasks (/task, /delegate, /spawn tracking,
7
+ # --track-pipeline, the task-board tools) actually needs it, so a plain
8
+ # session leaves no .trak_flow directory behind.
9
+
10
+ require 'fileutils'
11
+
12
+ module AIA
13
+ module TaskBoard
14
+ module_function
15
+
16
+ # Whether the trak_flow gem can be loaded.
17
+ #
18
+ # @return [Boolean]
19
+ def gem_available?
20
+ return true if defined?(TrakFlow)
21
+
22
+ require 'trak_flow'
23
+ true
24
+ rescue LoadError
25
+ false
26
+ end
27
+
28
+ # Make sure a TrakFlow project exists, creating .trak_flow in the current
29
+ # directory when none is found here or in a parent. The tasks themselves
30
+ # live in TrakFlow's database (~/.config/trak_flow/tf.db by default).
31
+ #
32
+ # @return [Boolean] true when the project is ready
33
+ def ensure_project!
34
+ return false unless gem_available?
35
+ return true if TrakFlow.initialized?
36
+
37
+ FileUtils.mkdir_p(TrakFlow.trak_flow_dir)
38
+ TrakFlow::Storage::Database.new.connect
39
+ TrakFlow.reset_root!
40
+ TrakFlow.initialized?
41
+ rescue StandardError => e
42
+ AIA.debug_warn("TrakFlow initialization failed (non-fatal): #{e.message}", exc: e)
43
+ false
44
+ end
45
+
46
+ # A TaskCoordinator on a ready project, or nil when TrakFlow can't run.
47
+ #
48
+ # @return [AIA::TaskCoordinator, nil]
49
+ def coordinator
50
+ return nil unless ensure_project!
51
+
52
+ require_relative 'trakflow_bridge'
53
+ require_relative 'task_coordinator'
54
+ TaskCoordinator.new
55
+ rescue StandardError => e
56
+ AIA.debug_warn("TaskCoordinator initialization failed (non-fatal): #{e.message}", exc: e)
57
+ nil
58
+ end
59
+ end
60
+ end
@@ -33,6 +33,7 @@ module AIA
33
33
  # @param labels [Array<String>] labels like "robot:alice", "domain:code"
34
34
  # @param creator [String] name of the creating robot
35
35
  # @return [TrakFlow::Models::Task, nil]
36
+ # :reek:LongParameterList { max_params: 6 } -- one keyword per optional task attribute; callers set only what they need
36
37
  def create_task(title, assignee: nil, parent_id: nil,
37
38
  blocked_by: [], labels: [], creator: "aia")
38
39
  return nil unless available?
@@ -40,27 +41,28 @@ module AIA
40
41
  task = TrakFlow::Models::Task.new(
41
42
  title: title, assignee: assignee, type: "task"
42
43
  )
43
- task = @db.create_task(task)
44
+ task = @db.create_task(task)
45
+ task_id = task.id
44
46
 
45
47
  @db.add_label(TrakFlow::Models::Label.new(
46
- task_id: task.id, name: "creator:#{creator}"
48
+ task_id: task_id, name: "creator:#{creator}"
47
49
  ))
48
50
 
49
51
  labels.each do |label|
50
52
  @db.add_label(TrakFlow::Models::Label.new(
51
- task_id: task.id, name: label
53
+ task_id: task_id, name: label
52
54
  ))
53
55
  end
54
56
 
55
57
  blocked_by.each do |blocker_id|
56
58
  @db.add_dependency(TrakFlow::Models::Dependency.new(
57
- source_id: blocker_id, target_id: task.id, type: "blocks"
59
+ source_id: blocker_id, target_id: task_id, type: "blocks"
58
60
  ))
59
61
  end
60
62
 
61
63
  if parent_id
62
64
  @db.add_dependency(TrakFlow::Models::Dependency.new(
63
- source_id: parent_id, target_id: task.id, type: "parent-child"
65
+ source_id: parent_id, target_id: task_id, type: "parent-child"
64
66
  ))
65
67
  end
66
68
 
@@ -74,6 +76,8 @@ module AIA
74
76
  # @param creator [String] creating robot name
75
77
  # @param ephemeral [Boolean] true for single-session plans (auto-gc)
76
78
  # @return [Hash, nil] { plan:, steps: }
79
+ # :reek:BooleanParameter -- ephemeral: tags a plan for auto-gc at session end; a second method would duplicate the whole build
80
+ # :reek:TooManyStatements -- plan build: create the plan task, then per step a child task, labels, and ordering dependency
77
81
  def create_plan(title, steps:, creator: "aia", ephemeral: false)
78
82
  return nil unless available?
79
83
 
@@ -177,6 +181,7 @@ module AIA
177
181
  # Summary of the current task board state.
178
182
  #
179
183
  # @return [String, nil]
184
+ # :reek:TooManyStatements -- one board report: totals line, per-assignee open/done counts, unassigned tail
180
185
  def status_summary
181
186
  return nil unless available?
182
187
 
data/lib/aia/timing.rb ADDED
@@ -0,0 +1,15 @@
1
+ # lib/aia/timing.rb
2
+
3
+ module AIA
4
+ # Monotonic-clock instrumentation shared by benchmark-reporting code.
5
+ module Timing
6
+ module_function
7
+
8
+ # Run the block and return [result, elapsed_seconds].
9
+ def timed
10
+ t0 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
11
+ result = yield
12
+ [result, Process.clock_gettime(Process::CLOCK_MONOTONIC) - t0]
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,205 @@
1
+ # frozen_string_literal: true
2
+
3
+ # lib/aia/tool_approver.rb
4
+ #
5
+ # Settles what robot_lab pauses a run for: tool calls that require approval
6
+ # (an MCP server's `requires_approval:`, or a RubyLLM::Tool that declares
7
+ # it) and MCP input requests (elicitation: a server asking the user for
8
+ # values, or to visit a URL).
9
+ #
10
+ # The mode comes from `tools.approval` (CLI: --tool-approval, env:
11
+ # AIA_TOOLS__APPROVAL):
12
+ #
13
+ # ask -- prompt on the terminal; deny when there is no terminal (default)
14
+ # approve -- allow every tool call that requires approval
15
+ # deny -- refuse them all and decline every input request
16
+ #
17
+ # Prompts go to $stderr so they never mix with the AI's answer on $stdout,
18
+ # and the turn's spinner is paused while one is shown.
19
+
20
+ module AIA
21
+ class ToolApprover
22
+ MODES = %w[ask approve deny].freeze
23
+ DEFAULT_MODE = 'ask'
24
+ YES = %w[y yes].freeze
25
+
26
+ # One prompt at a time: robots in a parallel network run on their own threads.
27
+ PROMPT_LOCK = Mutex.new
28
+
29
+ class << self
30
+ # The spinner of the turn in progress (set by StreamingRunner), paused
31
+ # while a prompt is on screen.
32
+ attr_accessor :spinner
33
+
34
+ # The approval settings for RobotLab.build / RobotLab::RunConfig.
35
+ #
36
+ # @param config [AIA::Config]
37
+ # @return [Hash] tool_approval:, plus on_tool_approval: / on_input_request: when they apply
38
+ def options(config)
39
+ new(mode: mode_for(config)).options
40
+ end
41
+
42
+ # @param config [AIA::Config]
43
+ # @return [String] one of MODES
44
+ def mode_for(config)
45
+ tools = config.tools if config.respond_to?(:tools)
46
+ mode = (tools.approval if tools.respond_to?(:approval)).to_s.strip.downcase
47
+ mode = DEFAULT_MODE if mode.empty?
48
+ return mode if MODES.include?(mode)
49
+
50
+ AIA.debug_warn("Unknown tools.approval '#{mode}' (expected #{MODES.join(', ')}); using '#{DEFAULT_MODE}'")
51
+ DEFAULT_MODE
52
+ end
53
+ end
54
+
55
+ attr_reader :mode
56
+
57
+ # @param mode [String] one of MODES
58
+ # @param input [IO] where answers are read from
59
+ # @param output [IO] where prompts are written
60
+ # @param interactive [Boolean, nil] whether a person can answer; defaults to input.tty?
61
+ def initialize(mode: DEFAULT_MODE, input: $stdin, output: $stderr, interactive: nil)
62
+ @mode = mode.to_s
63
+ @input = input
64
+ @output = output
65
+ @interactive = interactive
66
+ end
67
+
68
+ # @return [Hash] the robot_lab settings for this mode
69
+ def options
70
+ case mode
71
+ when 'approve' then { tool_approval: :approve, on_input_request: method(:answer_input) }
72
+ when 'deny' then { tool_approval: :deny }
73
+ else { tool_approval: :deny, on_tool_approval: method(:approve?), on_input_request: method(:answer_input) }
74
+ end
75
+ end
76
+
77
+ # Ask whether a tool call that requires approval may run.
78
+ #
79
+ # @param tool_call [RubyLLM::ToolCall]
80
+ # @return [Boolean]
81
+ def approve?(tool_call)
82
+ return refuse("tool '#{tool_call.name}' requires approval and there is no terminal to ask") unless interactive?
83
+
84
+ prompting do
85
+ @output.puts "\nTool '#{tool_call.name}' requires approval."
86
+ @output.puts " arguments: #{format_arguments(tool_call.arguments)}"
87
+ YES.include?(ask(' Allow it? [y/N] ').downcase)
88
+ end
89
+ end
90
+
91
+ # Answer an MCP server's request for input.
92
+ #
93
+ # @param request [RubyLLM::MCP::InputRequest]
94
+ # @return [Hash, true, nil] field values, true to accept a URL request, nil to decline
95
+ def answer_input(request)
96
+ return refuse("an MCP server asked for input (#{request.message}) and there is no terminal to ask") unless interactive?
97
+
98
+ prompting do
99
+ @output.puts "\nAn MCP server needs your input: #{request.message}"
100
+ request.url? ? answer_url(request) : answer_form(request)
101
+ end
102
+ end
103
+
104
+ private
105
+
106
+ def interactive?
107
+ @interactive.nil? ? @input.respond_to?(:tty?) && @input.tty? : @interactive
108
+ end
109
+
110
+ def refuse(reason)
111
+ AIA.logger&.warn("Tool approval: #{reason}; refusing")
112
+ @output.puts "[AIA] Refused: #{reason}. Set tools.approval (--tool-approval) to approve or deny."
113
+ nil
114
+ end
115
+
116
+ # Pause the spinner and hold the prompt lock while a question is on screen.
117
+ def prompting
118
+ PROMPT_LOCK.synchronize do
119
+ spinner = self.class.spinner
120
+ was_spinning = spinner&.spinning?
121
+ spinner&.pause if was_spinning
122
+ begin
123
+ yield
124
+ ensure
125
+ spinner&.resume if was_spinning
126
+ end
127
+ end
128
+ end
129
+
130
+ def ask(question)
131
+ @output.print question
132
+ @output.flush if @output.respond_to?(:flush)
133
+ @input.gets.to_s.strip
134
+ end
135
+
136
+ def answer_url(request)
137
+ @output.puts " Open this page: #{request.url}"
138
+ true if YES.include?(ask(' Continue once you have visited it? [y/N] ').downcase)
139
+ end
140
+
141
+ # Each field is asked in turn. A blank answer keeps the server's default;
142
+ # a blank answer to a required field without one declines the request.
143
+ def answer_form(request)
144
+ request.fields.each_with_object({}) do |field, values|
145
+ value = ask_field(field)
146
+ return nil if value == :decline
147
+
148
+ values[field.name] = value unless value.nil?
149
+ end
150
+ end
151
+
152
+ # @return [Object, nil, :decline] the typed value, nil to keep the default, :decline to give up
153
+ def ask_field(field)
154
+ loop do
155
+ raw = ask(field_question(field))
156
+ return blank_answer(field) if raw.empty?
157
+
158
+ value = cast(raw, field)
159
+ return value unless value.nil?
160
+
161
+ @output.puts " '#{raw}' is not a valid #{field.choices ? "choice (#{field.choices.join(', ')})" : field.type}."
162
+ end
163
+ end
164
+
165
+ def blank_answer(field)
166
+ field.required? && field.default.nil? ? :decline : nil
167
+ end
168
+
169
+ def field_question(field)
170
+ label = field.title || field.name.to_s
171
+ parts = [" #{label}"]
172
+ parts << "(#{field.description})" if field.description
173
+ parts << "[#{field.choices.join('/')}]" if field.choices
174
+ parts << "default: #{field.default}" unless field.default.nil?
175
+ parts << '*' if field.required?
176
+ "#{parts.join(' ')}: "
177
+ end
178
+
179
+ # @return [Object, nil] nil when +raw+ does not fit the field
180
+ def cast(raw, field)
181
+ choices = field.choices
182
+ return choices.find { it.to_s == raw } if choices
183
+
184
+ case field.type
185
+ when 'integer' then Integer(raw, exception: false)
186
+ when 'number' then Float(raw, exception: false)
187
+ when 'boolean' then boolean(raw)
188
+ else raw
189
+ end
190
+ end
191
+
192
+ def boolean(raw)
193
+ return true if %w[y yes true 1].include?(raw.downcase)
194
+ return false if %w[n no false 0].include?(raw.downcase)
195
+
196
+ nil
197
+ end
198
+
199
+ def format_arguments(arguments)
200
+ text = arguments.to_h.map { |key, value| "#{key}=#{value.inspect}" }.join(', ')
201
+ text = '(none)' if text.empty?
202
+ text.length > 300 ? "#{text[0, 300]}..." : text
203
+ end
204
+ end
205
+ end
@@ -13,11 +13,8 @@ module AIA
13
13
  class ToolFilter
14
14
  attr_reader :tool_count, :prep_ms, :label
15
15
 
16
- def initialize(label:, db_dir: nil, load_db: false, save_db: false)
16
+ def initialize(label:)
17
17
  @label = label
18
- @db_dir = db_dir
19
- @load_db = load_db
20
- @save_db = save_db
21
18
  @tool_count = 0
22
19
  @prep_ms = 0.0
23
20
  end
@@ -48,11 +45,6 @@ module AIA
48
45
  @tool_count.positive?
49
46
  end
50
47
 
51
- # True when this filter supports database persistence (--load / --save).
52
- def persistable?
53
- false
54
- end
55
-
56
48
  protected
57
49
 
58
50
  def do_prep
@@ -8,6 +8,8 @@
8
8
  # After each resolve(), prints a timing table showing
9
9
  # prep and filter times for the active filter.
10
10
 
11
+ require 'tty-table'
12
+
11
13
  module AIA
12
14
  class ToolFilterStrategy
13
15
  # Maps filter keys to display info.
@@ -17,6 +19,17 @@ module AIA
17
19
 
18
20
  DEFAULT_TIMEOUT_S = 10
19
21
 
22
+ # The per-filter timeout from config (tool_filter.timeout_s), or the default
23
+ # when it is unset or not a positive number.
24
+ #
25
+ # @param config [#tool_filter]
26
+ # @return [Numeric]
27
+ def self.timeout_from(config)
28
+ section = config.respond_to?(:tool_filter) ? config.tool_filter : nil
29
+ value = section.respond_to?(:timeout_s) ? section.timeout_s : nil
30
+ value.is_a?(Numeric) && value.positive? ? value : DEFAULT_TIMEOUT_S
31
+ end
32
+
20
33
  # @param filters [Hash{Symbol => ToolFilter}] e.g. {tfidf: tfidf_filter}
21
34
  # @param ui_presenter [UIPresenter, nil] for display (unused currently, reserved)
22
35
  # @param timeout_s [Numeric] per-filter wall-clock timeout in seconds
@@ -88,26 +101,45 @@ module AIA
88
101
 
89
102
  # Display single-filter results via logger.
90
103
  def display_filter_results(key, scored)
91
- meta = meta_for(key)
104
+ meta = meta_for(key)
105
+ label = meta[:label]
106
+ logger = AIA.logger
92
107
 
93
108
  if scored.empty?
94
- AIA.logger.debug "[#{meta[:label]}] No tools matched (all tools available)"
109
+ logger.debug "[#{label}] No tools matched (no tools sent this turn)"
95
110
  return
96
111
  end
97
112
 
98
113
  names = scored.map { |e| e[:name] }.join(', ')
99
- AIA.logger.debug "[#{meta[:label]}] Tools for this turn (#{scored.size}): #{names}"
114
+ logger.debug "[#{label}] Tools for this turn (#{scored.size}): #{names}"
100
115
 
101
116
  scored.each do |entry|
102
- AIA.logger.debug "[#{meta[:label]}] #{entry[:name]} (#{meta[:score_label]}: #{format('%.4f', entry[:score])})"
117
+ logger.debug "[#{label}] #{entry[:name]} (#{meta[:score_label]}: #{format('%.4f', entry[:score])})"
103
118
  end
104
119
  end
105
120
 
106
121
  # Print the timing table via logger.
107
- # rubocop:disable Metrics/AbcSize
122
+ # :reek:DuplicateMethodCall -- header and each data row map the same columns into different cells
108
123
  def display_timing_table(filter_ms_by_key)
109
- columns = @filters.map do |key, filter|
110
- meta = meta_for(key)
124
+ columns = build_timing_columns(filter_ms_by_key)
125
+ return if columns.empty?
126
+
127
+ header = ["Process"] + columns.map { |col| "#{col[:header]}\n#{col[:sub]}" }
128
+ rows = [
129
+ ["prep"] + columns.map { |col| col[:prep] },
130
+ ["filter"] + columns.map { |col| col[:filter] }
131
+ ]
132
+
133
+ alignments = [:left] + Array.new(columns.size, :right)
134
+ rendered = TTY::Table.new(header, rows)
135
+ .render(:unicode, multiline: true, alignments: alignments, padding: [0, 1])
136
+ rendered.each_line { |line| AIA.logger.debug(line.chomp) }
137
+ end
138
+
139
+ # Column data (header, sub-label, prep/filter cells) for each configured filter.
140
+ def build_timing_columns(filter_ms_by_key)
141
+ @filters.map do |key, filter|
142
+ meta = meta_for(key)
111
143
  active = filter_ms_by_key.key?(key)
112
144
  {
113
145
  header: "Option #{meta[:letter]}",
@@ -116,25 +148,7 @@ module AIA
116
148
  filter: active ? fmt_ms(filter_ms_by_key[key]) : "--"
117
149
  }
118
150
  end
119
-
120
- return if columns.empty?
121
-
122
- pw = 7 # "Process" column width
123
- widths = columns.map do |col|
124
- [10, col[:header].length, col[:sub].length, col[:prep].length, col[:filter].length].max
125
- end
126
-
127
- lines = []
128
- lines << ("┌─#{'─' * pw}─" + columns.each_with_index.map { |_, i| "┬─#{'─' * widths[i]}─" }.join + "┐")
129
- lines << ("│ #{'Process'.ljust(pw)} " + columns.each_with_index.map { |col, i| "│ #{col[:header].ljust(widths[i])} " }.join + "│")
130
- lines << ("│ #{' ' * pw} " + columns.each_with_index.map { |col, i| "│ #{col[:sub].ljust(widths[i])} " }.join + "│")
131
- lines << ("├─#{'─' * pw}─" + columns.each_with_index.map { |_, i| "┼─#{'─' * widths[i]}─" }.join + "┤")
132
- lines << ("│ #{'prep'.ljust(pw)} " + columns.each_with_index.map { |col, i| "│ #{col[:prep].rjust(widths[i])} " }.join + "│")
133
- lines << ("│ #{'filter'.ljust(pw)} " + columns.each_with_index.map { |col, i| "│ #{col[:filter].rjust(widths[i])} " }.join + "│")
134
- lines << ("└─#{'─' * pw}─" + columns.each_with_index.map { |_, i| "┴─#{'─' * widths[i]}─" }.join + "┘")
135
- lines.each { |line| AIA.logger.debug line }
136
151
  end
137
- # rubocop:enable Metrics/AbcSize
138
152
 
139
153
  def fmt_ms(ms)
140
154
  "#{ms.round(1)}ms"
@@ -0,0 +1,25 @@
1
+ # lib/aia/tool_introspection.rb
2
+
3
+ module AIA
4
+ # Shared name/description extraction for tool objects, which may be
5
+ # RubyLLM tools, RobotLab tools, or bare tool classes.
6
+ module ToolIntrospection
7
+ module_function
8
+
9
+ # The name the model calls the tool by. A RubyLLM::Tool class answers
10
+ # with its +tool_name+ ("dns"), not its Ruby constant name
11
+ # ("SharedTools::Tools::DnsTool"): robot_lab instantiates tool classes,
12
+ # so allowlists and per-turn tool filters must use that name to match.
13
+ def tool_name(tool)
14
+ if tool.is_a?(Class)
15
+ tool.respond_to?(:tool_name) ? tool.tool_name : tool.name
16
+ else
17
+ tool.respond_to?(:name) ? tool.name : tool.class.name
18
+ end
19
+ end
20
+
21
+ def tool_description(tool)
22
+ tool.respond_to?(:description) ? tool.description.to_s : ''
23
+ end
24
+ end
25
+ end