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
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
@@ -1533,7 +1556,7 @@ Create executable prompts:
1533
1556
  #!/usr/bin/env aia --no-output
1534
1557
  # Get current storm activity for the east and south coast of the US
1535
1558
 
1536
- Summarize the tropical storm outlook fpr the Atlantic, Caribbean Sea and Gulf of America.
1559
+ Summarize the tropical storm outlook for the Atlantic, Caribbean Sea and Gulf of America.
1537
1560
 
1538
1561
  /webpage https://www.nhc.noaa.gov/text/refresh/MIATWOAT+shtml/201724_MIATWOAT.shtml
1539
1562
  ```
@@ -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
@@ -11,17 +11,19 @@ require "reline"
11
11
  require "pm"
12
12
 
13
13
  module AIA
14
+ # :reek:TooManyInstanceVariables -- interactive-loop hub wires robot, presenter, tracker, routers, and handlers together by design
15
+ # :reek:TooManyMethods -- one private helper per loop concern (context, metrics, speech, history)
14
16
  class ChatLoop
15
17
  include ContentExtractor
18
+ include Speech
16
19
 
17
20
  def initialize(robot, ui_presenter, directive_processor,
18
- session_tracker: nil, alias_registry: nil, filters: {})
21
+ session_tracker: nil, filters: {}, robot_sync: nil)
19
22
  @robot = robot
23
+ @robot_sync = robot_sync
20
24
  @ui_presenter = ui_presenter
21
25
  @directive_processor = directive_processor
22
26
  @tracker = session_tracker || SessionTracker.new
23
- @alias_registry = alias_registry || ModelAliasRegistry.new
24
- @model_switch_handler = ModelSwitchHandler.new(@alias_registry, @ui_presenter)
25
27
  @filters = filters
26
28
 
27
29
  @streaming_runner = StreamingRunner.new
@@ -37,11 +39,13 @@ module AIA
37
39
  )
38
40
  @tool_filter_strategy = ToolFilterStrategy.new(
39
41
  filters: filters,
40
- ui_presenter: @ui_presenter
42
+ ui_presenter: @ui_presenter,
43
+ timeout_s: ToolFilterStrategy.timeout_from(AIA.config)
41
44
  )
42
45
  end
43
46
 
44
47
  # Start the interactive chat session
48
+ # :reek:BooleanParameter -- lets Session skip re-sending context files after a pipeline; two entry methods would duplicate rescue/ensure
45
49
  def start(skip_context_files: false)
46
50
  setup_session
47
51
  process_initial_context(skip_context_files)
@@ -62,9 +66,10 @@ module AIA
62
66
  end
63
67
 
64
68
  def process_initial_context(skip_context_files)
65
- return if skip_context_files || !AIA.config.context_files || AIA.config.context_files.empty?
69
+ files = AIA.config.context_files
70
+ return if skip_context_files || !files || files.empty?
66
71
 
67
- context = AIA.config.context_files.map do |file|
72
+ context = files.map do |file|
68
73
  File.read(file) rescue "Error reading file: #{file}"
69
74
  end.join("\n\n")
70
75
 
@@ -86,7 +91,7 @@ module AIA
86
91
  processed_prompt = resolve_input(follow_up_prompt)
87
92
  next if processed_prompt.nil?
88
93
 
89
- next if model_switch_handled?
94
+ sync_robot_settings
90
95
  next if special_routing_handled?(processed_prompt, @robot)
91
96
 
92
97
  execute_and_present(processed_prompt, @robot)
@@ -127,13 +132,6 @@ module AIA
127
132
  nil
128
133
  end
129
134
 
130
- def model_switch_handled?
131
- return false unless @model_switch_handler.handle(HandlerContext.new(config: AIA.config))
132
-
133
- update_robot
134
- true
135
- end
136
-
137
135
  def special_routing_handled?(processed_prompt, active_robot)
138
136
  if @special_mode_handler.handle(processed_prompt)
139
137
  clear_turn_mcp_filter
@@ -197,6 +195,15 @@ module AIA
197
195
  @special_mode_handler.robot = @robot
198
196
  end
199
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
+
200
207
  # Re-bind @robot when a directive rebuilt AIA.client into a different robot
201
208
  # (e.g. /model). No-op when the client is unchanged or unset.
202
209
  def rebind_robot_if_rebuilt
@@ -262,6 +269,7 @@ module AIA
262
269
  # Each robot_result.duration holds the elapsed seconds.
263
270
  # Similarity scores compare each model's response text against the
264
271
  # first model using TF-IDF cosine similarity.
272
+ # :reek:TooManyStatements -- one pass builds paired metric and similarity arrays; splitting hides the pairing
265
273
  def display_network_metrics(flow_result)
266
274
  metrics_list = []
267
275
  response_texts = []
@@ -323,8 +331,8 @@ module AIA
323
331
  # active_robot is always a Network; resolve to the chief for tool inspection.
324
332
  target = robot.respond_to?(:chief) ? robot.chief : robot
325
333
 
326
- local = Array(target.local_tools).map { |t| t.respond_to?(:name) ? t.name : t.class.name }
327
- 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) }
328
336
 
329
337
  $stderr.puts "[DEBUG] Tool filter strategy: #{@tool_filter_strategy.active_strategy_label}"
330
338
  $stderr.puts "[DEBUG] Robot local_tools (#{local.size}): #{local.join(', ')}"
@@ -337,55 +345,5 @@ module AIA
337
345
 
338
346
  File.open(out_file, "a") { |f| f.puts "\nYou: #{input}" }
339
347
  end
340
-
341
- def speak(content)
342
- return unless AIA.speak?
343
-
344
- audio = AIA.config.audio
345
- command = audio.speak_command || 'say'
346
- env = {}
347
- env['SPEECH_MODEL'] = audio.speech_model if audio.speech_model
348
-
349
- if command == 'say'
350
- # Local TTS: say converts and plays in one step
351
- run_with_spinner("Speaking...") do
352
- if audio.voice && !audio.voice.to_s.strip.empty?
353
- system(env, command, '-v', audio.voice, content.to_s)
354
- else
355
- system(env, command, content.to_s)
356
- end
357
- end
358
- else
359
- # Custom TTS script: stage 2 = convert text → audio file,
360
- # stage 3 = play the file. AIA passes the output path as $2.
361
- require 'tempfile'
362
- tmpfile = Tempfile.new(['aia-tts-', '.mp3'])
363
- tmpfile.close
364
- begin
365
- run_with_spinner("Converting to audio...") do
366
- system(env, command, content.to_s, tmpfile.path)
367
- end
368
- if File.size?(tmpfile.path)
369
- run_with_spinner("Speaking...") do
370
- system('afplay', tmpfile.path)
371
- end
372
- end
373
- ensure
374
- tmpfile.unlink
375
- end
376
- end
377
- rescue StandardError => e
378
- $stderr.puts "Warning: Speech failed: #{e.message}"
379
- end
380
-
381
- def run_with_spinner(message)
382
- spinner = TTY::Spinner.new("[:spinner] #{message}", format: :bouncing_ball, output: $stderr)
383
- spinner.auto_spin
384
- begin
385
- yield
386
- ensure
387
- spinner.stop
388
- end
389
- end
390
348
  end
391
349
  end