aia 2.0.0.0.pre.beta2 → 2.0.1

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 (227) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +152 -223
  3. data/README.md +41 -18
  4. data/bin/aia +8 -3
  5. data/lib/aia/aia_completion.bash +2 -3
  6. data/lib/aia/aia_completion.fish +6 -5
  7. data/lib/aia/aia_completion.zsh +2 -3
  8. data/lib/aia/chat_loop.rb +16 -14
  9. data/lib/aia/config/cli_parser.rb +123 -91
  10. data/lib/aia/config/defaults.yml +18 -40
  11. data/lib/aia/config/mcp_parser.rb +30 -36
  12. data/lib/aia/config/model_spec.rb +8 -14
  13. data/lib/aia/config/validator.rb +102 -103
  14. data/lib/aia/config/value_caster.rb +76 -0
  15. data/lib/aia/config.rb +70 -53
  16. data/lib/aia/crew.rb +29 -19
  17. data/lib/aia/debate_handler.rb +27 -10
  18. data/lib/aia/directives/configuration_directives.rb +55 -14
  19. data/lib/aia/directives/context_directives.rb +24 -12
  20. data/lib/aia/directives/execution_directives.rb +18 -23
  21. data/lib/aia/directives/model_directives.rb +41 -104
  22. data/lib/aia/directives/utility_directives.rb +16 -17
  23. data/lib/aia/directives/web_and_file_directives.rb +21 -14
  24. data/lib/aia/fact_asserter.rb +3 -3
  25. data/lib/aia/history_transfer.rb +64 -24
  26. data/lib/aia/logger.rb +14 -46
  27. data/lib/aia/mcp_config_normalizer.rb +27 -14
  28. data/lib/aia/mcp_connection_manager.rb +181 -184
  29. data/lib/aia/mcp_discovery.rb +43 -15
  30. data/lib/aia/mcp_grouper.rb +2 -1
  31. data/lib/aia/mcp_server_config.rb +20 -2
  32. data/lib/aia/mcp_utility.rb +24 -19
  33. data/lib/aia/mention_router.rb +15 -2
  34. data/lib/aia/modality_query.rb +36 -0
  35. data/lib/aia/model_alias_registry.rb +11 -11
  36. data/lib/aia/model_registry.rb +75 -0
  37. data/lib/aia/network_builder.rb +8 -7
  38. data/lib/aia/patches/mcp_stdio_stderr.rb +102 -0
  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/version.rb +1 -9
  76. data/lib/aia.rb +34 -8
  77. metadata +20 -161
  78. data/.better-commits.json +0 -150
  79. data/.config/tocer/configuration.yml +0 -6
  80. data/.envrc +0 -19
  81. data/.loki +0 -11
  82. data/.reek.yml +0 -160
  83. data/.rubocop.yml +0 -116
  84. data/.rubocop_strict.yml +0 -15
  85. data/.version +0 -1
  86. data/COMMITS.md +0 -196
  87. data/IMPLEMENTATION_PLAN.md +0 -506
  88. data/Rakefile +0 -47
  89. data/_typos.toml +0 -10
  90. data/aia.gemspec +0 -92
  91. data/architecture_review.md +0 -314
  92. data/config/aia.yml +0 -13
  93. data/docs/AGENTS.md +0 -40
  94. data/docs/advanced-prompting.md +0 -814
  95. data/docs/assets/images/aia.png +0 -0
  96. data/docs/cli-reference.md +0 -1241
  97. data/docs/configuration.md +0 -747
  98. data/docs/contributing.md +0 -386
  99. data/docs/directives-reference.md +0 -1145
  100. data/docs/examples/index.md +0 -277
  101. data/docs/examples/mcp/index.md +0 -475
  102. data/docs/examples/prompts/analysis/index.md +0 -78
  103. data/docs/examples/prompts/automation/index.md +0 -109
  104. data/docs/examples/prompts/development/index.md +0 -125
  105. data/docs/examples/prompts/index.md +0 -333
  106. data/docs/examples/prompts/learning/index.md +0 -127
  107. data/docs/examples/prompts/writing/index.md +0 -62
  108. data/docs/examples/tools/index.md +0 -282
  109. data/docs/faq.md +0 -578
  110. data/docs/guides/available-models.md +0 -366
  111. data/docs/guides/basic-usage.md +0 -478
  112. data/docs/guides/chat.md +0 -680
  113. data/docs/guides/crew.md +0 -239
  114. data/docs/guides/executable-prompts.md +0 -331
  115. data/docs/guides/first-prompt.md +0 -454
  116. data/docs/guides/getting-started.md +0 -455
  117. data/docs/guides/image-generation.md +0 -507
  118. data/docs/guides/index.md +0 -48
  119. data/docs/guides/local-models.md +0 -306
  120. data/docs/guides/migrate-prompts.md +0 -335
  121. data/docs/guides/models.md +0 -1017
  122. data/docs/guides/shared-tools.md +0 -254
  123. data/docs/guides/tools.md +0 -831
  124. data/docs/index.md +0 -259
  125. data/docs/installation.md +0 -274
  126. data/docs/mcp-integration.md +0 -603
  127. data/docs/prompt_management.md +0 -665
  128. data/docs/security.md +0 -674
  129. data/docs/special_projects_guide.md +0 -386
  130. data/docs/tools-and-mcp-examples.md +0 -1211
  131. data/docs/workflows-and-pipelines.md +0 -636
  132. data/examples/.gitignore +0 -2
  133. data/examples/00_setup_aia.sh +0 -111
  134. data/examples/01_basic_usage.sh +0 -23
  135. data/examples/02_frontmatter.sh +0 -33
  136. data/examples/03_shell_integration.sh +0 -55
  137. data/examples/04_erb_templating.sh +0 -56
  138. data/examples/05_shell_then_erb.sh +0 -38
  139. data/examples/06_prompt_chaining.sh +0 -59
  140. data/examples/07_pipeline.sh +0 -46
  141. data/examples/08_context_files.sh +0 -43
  142. data/examples/09_roles.sh +0 -67
  143. data/examples/10_stdin_piping.sh +0 -49
  144. data/examples/11_multi_model.sh +0 -65
  145. data/examples/12_token_usage.sh +0 -52
  146. data/examples/13_cost_tracking.sh +0 -68
  147. data/examples/14_output_file.sh +0 -91
  148. data/examples/15_parameters.sh +0 -68
  149. data/examples/16_directives.sh +0 -113
  150. data/examples/17_require_and_conditionals.sh +0 -68
  151. data/examples/18_tools.sh +0 -61
  152. data/examples/19_local_tools.sh +0 -34
  153. data/examples/20_mcp_servers.sh +0 -102
  154. data/examples/21_executable_prompts.sh +0 -78
  155. data/examples/22_chat_mode.sh +0 -217
  156. data/examples/23_verify.sh +0 -139
  157. data/examples/24_decompose.sh +0 -139
  158. data/examples/25_spawn.sh +0 -139
  159. data/examples/26_debate.sh +0 -97
  160. data/examples/27_mention_routing.sh +0 -157
  161. data/examples/28_model_switching.sh +0 -106
  162. data/examples/29_agent_harness.sh +0 -177
  163. data/examples/README.md +0 -321
  164. data/examples/advanced_multi_robot_capabilities_without_examples.md +0 -106
  165. data/examples/aia_config.yml +0 -22
  166. data/examples/aia_config_orchestrator.yml +0 -45
  167. data/examples/aia_config_with_mcp.yml +0 -21
  168. data/examples/common.sh +0 -39
  169. data/examples/context/project_goals.md +0 -6
  170. data/examples/context/tech_stack.md +0 -7
  171. data/examples/directives/timestamp_directive.rb +0 -22
  172. data/examples/mcp/filesystem.json +0 -9
  173. data/examples/prompts_dir/analyze.md +0 -2
  174. data/examples/prompts_dir/brainstorm.md +0 -2
  175. data/examples/prompts_dir/conditional.md +0 -17
  176. data/examples/prompts_dir/creative.md +0 -4
  177. data/examples/prompts_dir/erbinfo.md +0 -5
  178. data/examples/prompts_dir/erbinfo_raw.md +0 -8
  179. data/examples/prompts_dir/evaluate.md +0 -2
  180. data/examples/prompts_dir/explain_joke.md +0 -1
  181. data/examples/prompts_dir/explain_recursion.md +0 -1
  182. data/examples/prompts_dir/fun_fact +0 -3
  183. data/examples/prompts_dir/greeting.md +0 -8
  184. data/examples/prompts_dir/greeting_required.md +0 -7
  185. data/examples/prompts_dir/hello.md +0 -1
  186. data/examples/prompts_dir/includes/ruby_facts.md +0 -4
  187. data/examples/prompts_dir/limerick.md +0 -1
  188. data/examples/prompts_dir/list_with_mcp.md +0 -3
  189. data/examples/prompts_dir/pick_best.md +0 -2
  190. data/examples/prompts_dir/project_summary +0 -12
  191. data/examples/prompts_dir/quiz_with_include.md +0 -6
  192. data/examples/prompts_dir/require_demo.md +0 -5
  193. data/examples/prompts_dir/roles/formal.md +0 -3
  194. data/examples/prompts_dir/roles/orchestrator.md +0 -21
  195. data/examples/prompts_dir/roles/pirate.md +0 -3
  196. data/examples/prompts_dir/shell_then_erb.md +0 -6
  197. data/examples/prompts_dir/sort_compare.md +0 -2
  198. data/examples/prompts_dir/summarize_context.md +0 -2
  199. data/examples/prompts_dir/sysinfo.md +0 -5
  200. data/examples/prompts_dir/sysinfo_raw.md +0 -8
  201. data/examples/prompts_dir/tagline.md +0 -1
  202. data/examples/prompts_dir/tell_joke.md +0 -1
  203. data/examples/prompts_dir/tell_joke_with_next.md +0 -4
  204. data/examples/prompts_dir/use_local_tool.md +0 -8
  205. data/examples/prompts_dir/use_tools.md +0 -8
  206. data/examples/prompts_dir/weather.md +0 -2
  207. data/examples/prompts_dir/whats_new.md +0 -2
  208. data/examples/prompts_dir/with_timestamp.md +0 -5
  209. data/examples/requirements/sinatra_taskflow_app.md +0 -139
  210. data/examples/rules/01_classify_ruby.rb +0 -16
  211. data/examples/rules/02_prefer_claude_for_code.rb +0 -19
  212. data/examples/rules/03_gate_prompt_length.rb +0 -19
  213. data/examples/rules/04_tool_selection.rb +0 -41
  214. data/examples/rules/README.md +0 -30
  215. data/examples/run_all.sh +0 -294
  216. data/examples/tools/word_count_tool.rb +0 -30
  217. data/lib/AGENTS.md +0 -57
  218. data/lib/aia/model_switch_handler.rb +0 -100
  219. data/mcp_servers/README.md +0 -110
  220. data/mcp_servers/apple-mcp.json +0 -8
  221. data/mcp_servers/filesystem.json +0 -9
  222. data/mcp_servers/mcp_server_chart.json +0 -11
  223. data/mcp_servers/playwright_one.json +0 -8
  224. data/mcp_servers/playwright_server_definition.json +0 -9
  225. data/mcp_servers/playwright_two.json +0 -8
  226. data/mcp_servers/tavily_mcp_server.json +0 -8
  227. data/mkdocs.yml +0 -169
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  <img src="docs/assets/images/aia.png" alt="Robots waiter ready to take your order."><br />
8
8
  **The Prompt is the Code**<br />
9
- <p>Check out the new <a href="http://madbomber.github.io/aia/guides/models/?h=inline+role+syntax#inline-role-syntax">Inline Role Syntax</a> when working with multiple concurrent models.</p>
9
+ <p>Check out the new <a href="https://madbomber.github.io/aia/extending/multi-model/#giving-each-model-a-role">Inline Role Syntax</a> when working with multiple concurrent models.</p>
10
10
  </div>
11
11
 
12
12
  ---
@@ -74,13 +74,13 @@ For more information on AIA visit these locations:
74
74
 
75
75
  ```plain
76
76
 
77
- , , AIA v2.0.0.alpha is Online
77
+ , , AIA v2.0.0 is Online
78
78
  (\____/)
79
79
  (_oo_) Models: gpt-4o-mini
80
80
  (O) DB: refreshed 2026-03-19 at 10:56
81
- __|||__ \) Libs: ruby_llm v1.14.0, ruby_llm-mcp v1.0.0, robot_lab v0.0.9,
82
- [/ Tobor \] / simple_flow v0.3.0, trak_flow v0.1.3, typed_bus v0.0.1
83
- / \_______/ \/ Tools: 0 tools loaded
81
+ __|||__ \) Libs: ruby_llm v2.1.1, robot_lab v0.5.0, simple_flow v0.4.0,
82
+ [/ Tobor \] / trak_flow v0.2.0, typed_bus v0.0.1
83
+ / \_______/ \/ Tools: none loaded
84
84
  / /___\ MCP: (none configured)
85
85
  (\ /_____\ Crew: @tobor
86
86
  ::: :::
@@ -231,7 +231,7 @@ Implement a schema registry with event-driven synchronization...
231
231
 
232
232
  ### Requirements
233
233
 
234
- - **Ruby**: >= 4.0.0
234
+ - **Ruby**: >= 4.0.9
235
235
  - **External Tools**:
236
236
  - [fzf](https://github.com/junegunn/fzf) - Command-line fuzzy finder
237
237
 
@@ -579,9 +579,8 @@ Directives are special commands in prompt files and chat sessions that begin wit
579
579
  /config model = gpt-4
580
580
  /config temperature = 0.9
581
581
 
582
- # Enable chat mode and terse responses
582
+ # Enable chat mode
583
583
  /config chat = true
584
- /config terse = true
585
584
 
586
585
  Your prompt content here...
587
586
  ```
@@ -834,7 +833,7 @@ answer to `@name`, and inherit the chief's tools and MCP servers.
834
833
  ```
835
834
 
836
835
  Unlike `/spawn` — a one-shot specialist for the next prompt only — recruited
837
- members stay in the crew. See the [Crews guide](docs/guides/crew.md) for the
836
+ members stay in the crew. See the [Crews guide](docs/extending/crews.md) for the
838
837
  full picture.
839
838
 
840
839
  #### Dynamic Model Switching
@@ -910,7 +909,7 @@ aia --model ollama/llama3.2,gpt-4o-mini --consensus my_prompt
910
909
  **Environment Variables:**
911
910
  ```bash
912
911
  # Optional: Set custom Ollama API endpoint
913
- export OLLAMA_API_BASE=http://localhost:11434
912
+ export OLLAMA_API_BASE=http://localhost:11434/v1
914
913
  ```
915
914
 
916
915
  **Reasoning models:** models such as `qwen3` stream their chain-of-thought
@@ -1263,7 +1262,7 @@ Use `/delegate` to hand off a subtask to a specialist robot — AIA spawns the r
1263
1262
 
1264
1263
  ### MCP Server Configuration
1265
1264
 
1266
- AIA supports defining MCP (Model Context Protocol) servers directly in your configuration file. This allows MCP tools to be automatically loaded at startup without needing to specify them on the command line each time. When multiple MCP servers are configured, AIA connects to them **in parallel** using fiber-based concurrency (via the `simple_flow` gem) for faster startup.
1265
+ AIA supports defining MCP (Model Context Protocol) servers directly in your configuration file. This allows MCP tools to be automatically loaded at startup without needing to specify them on the command line each time. When multiple MCP servers are configured, AIA connects to them **in parallel** (one thread per server) before the first robot is built, and every robot in the session shares those connections.
1267
1266
 
1268
1267
  #### Configuration Format
1269
1268
 
@@ -1274,7 +1273,7 @@ mcp_servers:
1274
1273
  - name: "server-name"
1275
1274
  command: "server_command"
1276
1275
  args: ["arg1", "arg2"]
1277
- timeout: 30000 # milliseconds (default: 8000)
1276
+ timeout: 30000 # milliseconds (default: 30 seconds)
1278
1277
  env:
1279
1278
  ENV_VAR: "value"
1280
1279
  ```
@@ -1284,10 +1283,34 @@ mcp_servers:
1284
1283
  | Option | Required | Default | Description |
1285
1284
  |--------|----------|---------|-------------|
1286
1285
  | `name` | Yes | - | Unique identifier for the MCP server |
1287
- | `command` | Yes | - | Executable command (absolute path or found in PATH) |
1286
+ | `command` | Unless `url` | - | Executable command (absolute path or found in PATH) |
1288
1287
  | `args` | No | `[]` | Array of command-line arguments |
1289
- | `timeout` | No | `8000` | Connection timeout in milliseconds |
1288
+ | `timeout` | No | 30 seconds | Connection timeout; values of 1000 or more are milliseconds, smaller values are seconds |
1290
1289
  | `env` | No | `{}` | Environment variables for the server process |
1290
+ | `url` | No | - | Streamable HTTP endpoint, used instead of `command` (`headers:` and `bearer_token:` apply) |
1291
+ | `prefix` | No | - | Prefix for the server's tool names, e.g. `github` turns `search` into `github_search`; needed when two servers offer a tool with the same name |
1292
+ | `only` / `except` | No | - | Offer only these tools, or hide these tools |
1293
+ | `requires_approval` | No | - | Tool names (or `true` for all) that need your approval before they run; see below |
1294
+
1295
+ #### Tool Approval and Input Requests
1296
+
1297
+ Tools listed in `requires_approval` pause before they run. MCP servers can also ask for input mid-call, such as a value to fill in or a page to visit to connect an account. The `tools.approval` setting (`--tool-approval`, `AIA_TOOLS__APPROVAL`) decides what happens:
1298
+
1299
+ | Mode | Behavior |
1300
+ |------|----------|
1301
+ | `ask` (default) | AIA shows the tool name and its arguments and asks `Allow it? [y/N]`, and asks for each value a server requests. With no terminal (piped or scripted runs) the call is refused. |
1302
+ | `approve` | Every tool call that requires approval runs. Input requests are still asked on the terminal. |
1303
+ | `deny` | Every such tool call is refused and every input request is declined. |
1304
+
1305
+ ```yaml
1306
+ mcp_servers:
1307
+ - name: "github"
1308
+ command: "github-mcp-server"
1309
+ args: ["stdio"]
1310
+ requires_approval: ["create_issue", "merge_pull_request"]
1311
+ ```
1312
+
1313
+ A refused call is reported back to the model as denied, so it can explain or try something else.
1291
1314
 
1292
1315
  #### Example: GitHub MCP Server
1293
1316
 
@@ -1373,12 +1396,12 @@ mcp_servers:
1373
1396
  When MCP servers are configured, AIA displays them in the startup robot:
1374
1397
 
1375
1398
  ```
1376
- , , AIA v2.0.0.alpha is Online
1399
+ , , AIA v2.0.0 is Online
1377
1400
  (\____/)
1378
1401
  (_oo_) Models: gpt-4o-mini
1379
1402
  (O) DB: refreshed 2026-03-19 at 10:56
1380
- __|||__ \) Libs: ruby_llm v1.14.0, ruby_llm-mcp v1.0.0, robot_lab v0.0.9,
1381
- [/ Tobor \] / simple_flow v0.3.0, trak_flow v0.1.3, typed_bus v0.0.1
1403
+ __|||__ \) Libs: ruby_llm v2.1.1, robot_lab v0.5.0, simple_flow v0.4.0,
1404
+ [/ Tobor \] / trak_flow v0.2.0, typed_bus v0.0.1
1382
1405
  / \_______/ \/ Tools: 24 tools loaded
1383
1406
  / /___\ MCP: github, htm
1384
1407
  (\ /_____\ Crew: @tobor
@@ -1571,7 +1594,7 @@ export AIA_OUTPUT__FILE=./temp.md
1571
1594
  export AIA_MODEL=gpt-4o-mini
1572
1595
  export AIA_FLAGS__VERBOSE=true # Shows spinner while waiting for LLM response
1573
1596
 
1574
- alias chat='aia --chat --terse'
1597
+ alias chat='aia --chat'
1575
1598
  ask() { echo "$1" | aia --no-output; }
1576
1599
  ```
1577
1600
 
data/bin/aia CHANGED
@@ -5,9 +5,14 @@
5
5
  # Bundler so dependency version constraints are resolved before any require.
6
6
  # When installed as a standalone gem there is no adjacent Gemfile, so this
7
7
  # block is skipped and RubyGems handles activation as normal.
8
- gemfile = File.expand_path('../Gemfile', __dir__)
9
- if File.exist?(gemfile)
10
- ENV['BUNDLE_GEMFILE'] ||= gemfile
8
+ #
9
+ # A relative BUNDLE_GEMFILE (the workspace .envrc exports "Gemfile" or
10
+ # "Gemfile.local" to toggle prod/dev bundles) is resolved against the repo
11
+ # root, not the current directory, so bin/aia works when run from anywhere
12
+ # (e.g. examples/). An absolute path is left as-is.
13
+ repo_root = File.expand_path('..', __dir__)
14
+ if File.exist?(File.join(repo_root, 'Gemfile'))
15
+ ENV['BUNDLE_GEMFILE'] = File.expand_path(ENV['BUNDLE_GEMFILE'] || 'Gemfile', repo_root)
11
16
  require 'bundler/setup'
12
17
  end
13
18
 
@@ -2,8 +2,7 @@
2
2
  # Setup a prompt completion for use with
3
3
  # the bash shell
4
4
  #
5
- # This script assumes that the system environment
6
- # variable AIA_PROMPTS__DIR has been set correctly
5
+ # Prompt IDs come from $AIA_PROMPTS__DIR, or ~/.prompts when it is unset.
7
6
 
8
7
  _aia_completion() {
9
8
  # The current word being completed
@@ -18,7 +17,7 @@ _aia_completion() {
18
17
  # Check if we are currently completing the option that requires prompt IDs
19
18
  if [[ "$prev_word" == "aia" ]]; then
20
19
  # Change directory to the prompts directory
21
- cd "$AIA_PROMPTS__DIR" || return
20
+ cd "${AIA_PROMPTS__DIR:-$HOME/.prompts}" || return
22
21
 
23
22
  # Generate a list of relative paths from the ~/.prompts directory (without .md extension)
24
23
  local files=($(find . -name "*.md" -type f | sed 's|^\./||' | sed 's/\.md$//'))
@@ -1,8 +1,7 @@
1
1
  # lib/aia/aia_completion.fish
2
2
  # Setup a prompt completion for use with the fish shell
3
3
  #
4
- # This script assumes that the system environment
5
- # variable AIA_PROMPTS__DIR has been set correctly
4
+ # Prompt IDs come from $AIA_PROMPTS__DIR, or ~/.prompts when it is unset.
6
5
 
7
6
  function __fish_aia_complete
8
7
  # Get the command line and current token
@@ -12,9 +11,11 @@ function __fish_aia_complete
12
11
  # Check if we are currently completing the option that requires prompt IDs
13
12
  if set -q cmd_line[2]
14
13
  # Change directory to the prompts directory
15
- if test -d $AIA_PROMPTS__DIR
16
- pushd $AIA_PROMPTS__DIR
17
- # Generate completions based on .md files in the AIA_PROMPTS__DIR directory
14
+ set -l prompts_dir ~/.prompts
15
+ set -q AIA_PROMPTS__DIR; and set prompts_dir $AIA_PROMPTS__DIR
16
+ if test -d $prompts_dir
17
+ pushd $prompts_dir
18
+ # Generate completions based on .md files in the prompts directory
18
19
  for file in (find . -name "*.md" -type f)
19
20
  set file (string replace -r '\.md$' '' -- $file)
20
21
  set file (string replace -r '^\./' '' -- $file)
@@ -2,8 +2,7 @@
2
2
  # Setup a prompt completion for use with
3
3
  # the zsh shell
4
4
  #
5
- # This script assumes that the system environment
6
- # variable AIA_PROMPTS__DIR has been set correctly
5
+ # Prompt IDs come from $AIA_PROMPTS__DIR, or ~/.prompts when it is unset.
7
6
 
8
7
  _aia_completion() {
9
8
  # The current word being completed
@@ -18,7 +17,7 @@ _aia_completion() {
18
17
  # Check if we are currently completing the option that requires prompt IDs
19
18
  if [[ "$prev_word" == "aia" ]]; then
20
19
  # Change directory to the prompts directory
21
- cd "$AIA_PROMPTS__DIR" || return
20
+ cd "${AIA_PROMPTS__DIR:-$HOME/.prompts}" || return
22
21
 
23
22
  # Generate a list of relative paths from the ~/.prompts directory (without .md extension)
24
23
  local files=($(find . -name "*.md" -type f | sed 's|^\./||' | sed 's/\.md$//'))
data/lib/aia/chat_loop.rb CHANGED
@@ -18,13 +18,12 @@ module AIA
18
18
  include Speech
19
19
 
20
20
  def initialize(robot, ui_presenter, directive_processor,
21
- session_tracker: nil, alias_registry: nil, filters: {})
21
+ session_tracker: nil, filters: {}, robot_sync: nil)
22
22
  @robot = robot
23
+ @robot_sync = robot_sync
23
24
  @ui_presenter = ui_presenter
24
25
  @directive_processor = directive_processor
25
26
  @tracker = session_tracker || SessionTracker.new
26
- @alias_registry = alias_registry || ModelAliasRegistry.new
27
- @model_switch_handler = ModelSwitchHandler.new(@alias_registry, @ui_presenter)
28
27
  @filters = filters
29
28
 
30
29
  @streaming_runner = StreamingRunner.new
@@ -40,7 +39,8 @@ module AIA
40
39
  )
41
40
  @tool_filter_strategy = ToolFilterStrategy.new(
42
41
  filters: filters,
43
- ui_presenter: @ui_presenter
42
+ ui_presenter: @ui_presenter,
43
+ timeout_s: ToolFilterStrategy.timeout_from(AIA.config)
44
44
  )
45
45
  end
46
46
 
@@ -91,7 +91,7 @@ module AIA
91
91
  processed_prompt = resolve_input(follow_up_prompt)
92
92
  next if processed_prompt.nil?
93
93
 
94
- next if model_switch_handled?
94
+ sync_robot_settings
95
95
  next if special_routing_handled?(processed_prompt, @robot)
96
96
 
97
97
  execute_and_present(processed_prompt, @robot)
@@ -132,13 +132,6 @@ module AIA
132
132
  nil
133
133
  end
134
134
 
135
- def model_switch_handled?
136
- return false unless @model_switch_handler.handle(HandlerContext.new(config: AIA.config))
137
-
138
- update_robot
139
- true
140
- end
141
-
142
135
  def special_routing_handled?(processed_prompt, active_robot)
143
136
  if @special_mode_handler.handle(processed_prompt)
144
137
  clear_turn_mcp_filter
@@ -202,6 +195,15 @@ module AIA
202
195
  @special_mode_handler.robot = @robot
203
196
  end
204
197
 
198
+ # Bring the robot in line with settings changed since the last turn
199
+ # (/temperature, /top_p, /config llm.*). See RobotSync.
200
+ def sync_robot_settings
201
+ return unless @robot_sync
202
+
203
+ @robot_sync.call(@robot)
204
+ rebind_robot_if_rebuilt
205
+ end
206
+
205
207
  # Re-bind @robot when a directive rebuilt AIA.client into a different robot
206
208
  # (e.g. /model). No-op when the client is unchanged or unset.
207
209
  def rebind_robot_if_rebuilt
@@ -329,8 +331,8 @@ module AIA
329
331
  # active_robot is always a Network; resolve to the chief for tool inspection.
330
332
  target = robot.respond_to?(:chief) ? robot.chief : robot
331
333
 
332
- local = Array(target.local_tools).map { |t| t.respond_to?(:name) ? t.name : t.class.name }
333
- mcp = Array(target.mcp_tools).map { |t| t.respond_to?(:name) ? t.name : t.class.name }
334
+ local = Array(target.local_tools).map { |t| ToolIntrospection.tool_name(t) }
335
+ mcp = Array(target.mcp_tools).map { |t| ToolIntrospection.tool_name(t) }
334
336
 
335
337
  $stderr.puts "[DEBUG] Tool filter strategy: #{@tool_filter_strategy.active_strategy_label}"
336
338
  $stderr.puts "[DEBUG] Robot local_tools (#{local.size}): #{local.join(', ')}"
@@ -8,7 +8,9 @@
8
8
  require 'optparse'
9
9
  require 'yaml'
10
10
  require_relative 'model_spec'
11
+ require_relative '../errors'
11
12
  require_relative '../skill_utils'
13
+ require_relative '../modality_query'
12
14
 
13
15
  module AIA
14
16
  # rubocop:disable Metrics/ModuleLength
@@ -23,12 +25,15 @@ module AIA
23
25
  begin
24
26
  parser = create_option_parser(options)
25
27
  parser.parse!
26
- rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
27
- $stderr.puts "ERROR: #{e.message}"
28
- $stderr.puts " use --help for usage report"
29
- exit 1
28
+ rescue OptionParser::ParseError, AIA::ConfigurationError => e
29
+ report_parse_error(e)
30
30
  end
31
31
 
32
+ # Post-parse so these work regardless of flag order (and after any
33
+ # --require libs have been noted).
34
+ handle_list_providers(options)
35
+ handle_list_models(options)
36
+
32
37
  # Store remaining args for prompt_id and context files
33
38
  options[:remaining_args] = ARGV.dup
34
39
 
@@ -72,10 +77,6 @@ module AIA
72
77
  options[:fuzzy] = true
73
78
  end
74
79
 
75
- opts.on("--expert-routing", "Route each prompt to a specialist robot based on domain classification") do
76
- options[:expert_routing] = true
77
- end
78
-
79
80
  opts.on("--track-pipeline", "Track pipeline execution in TrakFlow") do
80
81
  options[:track_pipeline] = true
81
82
  end
@@ -87,14 +88,6 @@ module AIA
87
88
  opts.on("-A", "--[no-]auto-tool-filter", "Use TF-IDF similarity-based tool filtering (default: on)") do |v|
88
89
  options[:auto_tool_filter] = v
89
90
  end
90
-
91
- opts.on("--load", "Load persisted tool filter databases from ~/.config/aia/") do
92
- options[:tool_filter_load] = true
93
- end
94
-
95
- opts.on("--save", "Save tool filter databases to ~/.config/aia/") do
96
- options[:tool_filter_save] = true
97
- end
98
91
  end
99
92
 
100
93
  # :reek:TooManyStatements -- one opts.on registration per CLI flag; splitting the group would scatter related flags
@@ -105,6 +98,20 @@ module AIA
105
98
  list_available_models(query)
106
99
  end
107
100
 
101
+ opts.on('--provider SLUG',
102
+ 'Default provider for models given without a provider/ prefix; ' \
103
+ 'also scopes --list-models (any RubyLLM-registered provider)') do |slug|
104
+ options[:provider] = slug
105
+ end
106
+
107
+ opts.on('--list-models', 'List the live models served by the --provider and exit') do
108
+ options[:list_models] = true
109
+ end
110
+
111
+ opts.on('--list-providers', 'List the registered RubyLLM providers and exit') do
112
+ options[:list_providers] = true
113
+ end
114
+
108
115
  opts.on("-m MODEL", "--model MODEL",
109
116
  "Set LLM model(s). Format: MODEL[=ROLE][,MODEL[=ROLE]]... " \
110
117
  "Multiple models run in parallel; use --consensus to synthesize results") do |model_string|
@@ -116,8 +123,7 @@ module AIA
116
123
  end
117
124
 
118
125
  opts.on("--list-roles", "List available roles and exit") do
119
- list_available_roles
120
- exit 0
126
+ options[:list_roles] = true
121
127
  end
122
128
 
123
129
  opts.on("--sm", "--speech-model MODEL", "Set speech model") do |model|
@@ -154,10 +160,6 @@ module AIA
154
160
  opts.on("--[no-]history-file [FILE]", "Set conversation history file path") do |file|
155
161
  options[:history_file] = file
156
162
  end
157
-
158
- opts.on("--md", "--[no-]markdown", "Enable Markdown formatting") do |md|
159
- options[:markdown] = md
160
- end
161
163
  end
162
164
 
163
165
  # :reek:TooManyStatements -- one opts.on registration per CLI flag; splitting the group would scatter related flags
@@ -204,8 +206,8 @@ module AIA
204
206
  options[:pipeline] += pipeline.split(',').map(&:strip)
205
207
  end
206
208
 
207
- opts.on("--system-prompt PROMPT_ID", "Set system prompt for chat sessions") do |prompt_id|
208
- options[:system_prompt] = prompt_id
209
+ opts.on("--system-prompt TEXT", "Set the system prompt (literal text)") do |text|
210
+ options[:system_prompt] = text
209
211
  end
210
212
  end
211
213
 
@@ -253,7 +255,7 @@ module AIA
253
255
  options[:paint] = true
254
256
  end
255
257
 
256
- opts.on("--im", "--image-model MODEL", "Set image model for generation (default: dall-e-3)") do |model|
258
+ opts.on("--im", "--image-model MODEL", "Set image model for generation (default: gpt-image-1)") do |model|
257
259
  options[:image_model] = model
258
260
  end
259
261
 
@@ -297,6 +299,11 @@ module AIA
297
299
  options[:rejected_tools] += tools_list.split(',').map(&:strip)
298
300
  end
299
301
 
302
+ opts.on("--tool-approval MODE", %w[ask approve deny],
303
+ "Tool calls that require approval: ask (default), approve, or deny") do |mode|
304
+ options[:tool_approval] = mode
305
+ end
306
+
300
307
  opts.on("--list-tools", "List available tools and exit (combine with --mcp-list for MCP tools)") do
301
308
  options[:list_tools] = true
302
309
  end
@@ -441,7 +448,7 @@ module AIA
441
448
  - PromptManager Docs: https://madbomber.github.io/prompt_manager
442
449
  - ERB Documentation: https://docs.ruby-lang.org/en/master/ERB.html
443
450
  - MCP Specification: https://modelcontextprotocol.io
444
- - MCP Client Docs: https://github.com/patvice/ruby_llm-mcp/blob/main/README.md
451
+ - RobotLab Docs: https://github.com/MadBomber/robot_lab
445
452
 
446
453
  EXTRA
447
454
  end
@@ -460,7 +467,7 @@ module AIA
460
467
  spec.strip!
461
468
 
462
469
  if spec =~ /^=|=$/
463
- raise ArgumentError, "Invalid model syntax: '#{spec}'. Expected format: MODEL[=ROLE]"
470
+ raise AIA::ConfigurationError, "Invalid model syntax: '#{spec}'. Expected format: MODEL[=ROLE]"
464
471
  end
465
472
 
466
473
  if spec.include?('=')
@@ -468,8 +475,6 @@ module AIA
468
475
  model_name.strip!
469
476
  role_name.strip!
470
477
 
471
- validate_role_exists(role_name)
472
-
473
478
  model_counts[model_name] += 1
474
479
  instance = model_counts[model_name]
475
480
 
@@ -495,84 +500,111 @@ module AIA
495
500
  models
496
501
  end
497
502
 
498
- def validate_role_exists(role_id)
499
- return validate_role_path!(role_id) if AIA::SkillUtils.path_based_id?(role_id)
503
+ # Print a command-line error without a backtrace and exit 1. Covers every
504
+ # OptionParser failure (unknown option, missing or invalid argument) and
505
+ # configuration errors raised while options are parsed (e.g. a missing role).
506
+ def report_parse_error(error)
507
+ $stderr.puts "ERROR: #{error.message}"
508
+ $stderr.puts ' use --help for usage report' if error.is_a?(OptionParser::ParseError)
509
+ exit 1
510
+ end
511
+
512
+ # Post-parse handler for `--list-providers`. Lists every provider
513
+ # registered with RubyLLM (built-ins plus any --require'd gems) and exits.
514
+ def handle_list_providers(options)
515
+ return unless options[:list_providers]
500
516
 
501
- prompts_dir = ENV.fetch('AIA_PROMPTS__DIR', File.join(Dir.home, '.prompts'))
502
- roles_prefix = ENV.fetch('AIA_PROMPTS__ROLES_PREFIX', 'roles')
503
- role_id = "#{roles_prefix}/#{role_id}" unless role_id.start_with?(roles_prefix)
517
+ require_listed_libs(options)
518
+ list_available_providers
519
+ end
520
+
521
+ def list_available_providers
522
+ AIA::ProviderRegistry.load_installed_gems
523
+
524
+ entries = AIA::ProviderRegistry.providers.sort.map { |slug, klass| provider_entry(slug, klass) }
504
525
 
505
- role_file_path = File.join(prompts_dir, "#{role_id}.md")
506
- return if File.exist?(role_file_path)
526
+ puts <<~OUTPUT
507
527
 
508
- raise ArgumentError, role_not_found_message(role_file_path, prompts_dir, roles_prefix)
528
+ Registered RubyLLM providers:
529
+ #{'-' * 60}
530
+ #{entries.join("\n")}
531
+
532
+ #{entries.size} provider(s) registered
533
+ OUTPUT
534
+
535
+ exit
509
536
  end
510
537
 
511
- # A path-based role id must resolve to an existing file.
512
- def validate_role_path!(role_id)
513
- expanded = File.expand_path(role_id)
514
- expanded += '.md' if File.extname(expanded).empty?
515
- raise ArgumentError, "Role file not found: #{expanded}" unless File.exist?(expanded)
538
+ # One listing line per provider, annotated with what the provider
539
+ # declares about itself: " (local)" and/or " (has API key)".
540
+ def provider_entry(slug, klass)
541
+ entry = "- #{slug}"
542
+ entry += ' (local)' if klass.respond_to?(:local?) && klass.local?
543
+ entry += ' (has API key)' if provider_api_key?(slug)
544
+ entry
516
545
  end
517
546
 
518
- def role_not_found_message(role_file_path, prompts_dir, roles_prefix)
519
- available_roles = list_available_role_names(prompts_dir, roles_prefix)
520
- message = "Role file not found: #{role_file_path}\n\n"
547
+ # Generic API-key detection: RubyLLM.config's <slug>_api_key (set by
548
+ # robot_lab or the user), or the conventional <SLUG>_API_KEY env var
549
+ # that robot_lab maps into it at session start.
550
+ def provider_api_key?(slug)
551
+ key_attr = :"#{slug}_api_key"
552
+ config = RubyLLM.config
553
+ return true if config.respond_to?(key_attr) && !config.public_send(key_attr).to_s.empty?
521
554
 
522
- if available_roles.empty?
523
- message + "No roles directory found at #{File.join(prompts_dir, roles_prefix)}\n" \
524
- "Create the directory and add role files to use this feature."
525
- else
526
- message + "Available roles:\n" +
527
- available_roles.map { |r| " - #{r}" }.join("\n") +
528
- "\n\nCreate the role file or use an existing role."
529
- end
555
+ !ENV.fetch("#{slug.upcase}_API_KEY", '').empty?
530
556
  end
531
557
 
532
- # :reek:TooManyStatements -- sequential terminal report: guards, then a markdown table per role; exits after printing
533
- def list_available_roles
534
- prompts_dir = ENV.fetch('AIA_PROMPTS__DIR', File.join(Dir.home, '.prompts'))
535
- roles_prefix = ENV.fetch('AIA_PROMPTS__ROLES_PREFIX', 'roles')
536
- roles_dir = File.join(prompts_dir, roles_prefix)
558
+ # Post-parse handler for `--provider SLUG --list-models`. Lists the
559
+ # provider's live models (via RubyLLM's Provider#list_models) and exits.
560
+ def handle_list_models(options)
561
+ return unless options[:list_models]
537
562
 
538
- unless Dir.exist?(roles_dir)
539
- puts "No roles directory found at #{roles_dir}"
540
- puts "Create this directory and add role files to use roles."
541
- return
563
+ slug = options[:provider]
564
+ if slug
565
+ require_listed_libs(options)
566
+ AIA::ProviderRegistry.apply_env_endpoints
567
+ list_provider_models(slug)
568
+ else
569
+ $stderr.puts "ERROR: --list-models requires --provider SLUG " \
570
+ "(use --available-models to search the full model registry)"
571
+ exit 1
542
572
  end
573
+ end
543
574
 
544
- roles = list_available_role_names(prompts_dir, roles_prefix)
545
-
546
- if roles.empty?
547
- puts "No role files found in #{roles_dir}"
548
- puts "Create .md files in this directory to define roles."
549
- return
575
+ # `--require` libs may register additional RubyLLM providers, so load
576
+ # them before resolving the provider slug.
577
+ def require_listed_libs(options)
578
+ Array(options[:require_libs]).each do |lib|
579
+ require lib
580
+ rescue LoadError => e
581
+ $stderr.puts "Warning: Failed to require '#{lib}': #{e.message}"
550
582
  end
583
+ end
551
584
 
552
- roles.each do |role_id|
553
- role_file = File.join(roles_dir, "#{role_id}.md")
554
- front_matter = AIA::SkillUtils.parse_front_matter(role_file)
585
+ # :reek:TooManyStatements -- sequential --list-models report: resolve provider, list, summary, exit
586
+ def list_provider_models(slug)
587
+ if AIA::ProviderRegistry.available?(slug)
588
+ entries = AIA::ProviderRegistry.instantiate(slug).list_models.map { |model| "- #{slug}/#{model.id}" }
555
589
 
556
- puts "## #{role_id}"
557
- puts
558
- puts "| Key | Value |"
559
- puts "|-----|-------|"
560
- front_matter.each do |key, value|
561
- safe_value = value.to_s.gsub('|', '\\|')
562
- puts "| #{key} | #{safe_value} |"
563
- end
564
- puts
565
- end
566
- end
590
+ puts <<~OUTPUT
567
591
 
568
- def list_available_role_names(prompts_dir, roles_prefix)
569
- roles_dir = File.join(prompts_dir, roles_prefix)
570
- return [] unless Dir.exist?(roles_dir)
592
+ #{slug} models:
593
+ #{'-' * 60}
594
+ #{entries.join("\n")}
571
595
 
572
- Dir.glob("**/*.md", base: roles_dir)
573
- .map { |f| f.chomp('.md') }
574
- .reject { |f| f.split('/').any? { |part| part.start_with?('_') } }
575
- .sort
596
+ #{entries.size} #{slug} model(s) available
597
+ OUTPUT
598
+
599
+ exit
600
+ else
601
+ $stderr.puts "ERROR: unknown provider '#{slug}'. Registered providers: " \
602
+ "#{AIA::ProviderRegistry.slugs.sort.join(', ')}"
603
+ exit 1
604
+ end
605
+ rescue StandardError => e
606
+ $stderr.puts "ERROR: cannot list models for provider '#{slug}': #{e.message}"
607
+ exit 1
576
608
  end
577
609
 
578
610
  # :reek:TooManyStatements -- sequential --available-models report: parse query, print matches, summary, exit
@@ -609,7 +641,7 @@ module AIA
609
641
  # Split a query into modality terms (e.g. "text_to_text", leading ':'
610
642
  # stripped) and plain substring terms.
611
643
  def parse_model_query(query)
612
- modality, substrings = query.partition { |q| q.include?('_to_') }
644
+ modality, substrings = query.partition { |q| ModalityQuery.modality_term?(q) }
613
645
  [modality.map { |q| q.delete_prefix(':') }, substrings]
614
646
  end
615
647
 
@@ -619,7 +651,7 @@ module AIA
619
651
  end
620
652
 
621
653
  def model_entry_visible?(llm, entry, modality_terms, substring_terms)
622
- modality_terms.all? { |q| llm.modalities.send("#{q}?") } &&
654
+ modality_terms.all? { |q| ModalityQuery.matches?(llm.modalities, q) } &&
623
655
  substring_terms.all? { |q| entry.include?(q) }
624
656
  end
625
657
  # rubocop:enable Metrics/ModuleLength