aia 1.1.1 → 2.0.0.0.pre.alpha

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 (169) hide show
  1. checksums.yaml +4 -4
  2. data/.envrc +5 -1
  3. data/.loki +231 -0
  4. data/.quality/flay_baseline.txt +1 -0
  5. data/.quality/flog_baseline.txt +29 -0
  6. data/.quality/reek_baseline.txt +80 -0
  7. data/.rubocop.yml +116 -0
  8. data/.version +1 -1
  9. data/CHANGELOG.md +259 -50
  10. data/IMPLEMENTATION_PLAN.md +506 -0
  11. data/README.md +266 -238
  12. data/Rakefile +118 -5
  13. data/architecture_review.md +314 -0
  14. data/bin/aia +16 -0
  15. data/docs/AGENTS.md +40 -0
  16. data/docs/advanced-prompting.md +67 -3
  17. data/docs/cli-reference.md +312 -56
  18. data/docs/configuration.md +130 -19
  19. data/docs/contributing.md +56 -2
  20. data/docs/directives-reference.md +593 -78
  21. data/docs/faq.md +85 -3
  22. data/docs/guides/available-models.md +1 -1
  23. data/docs/guides/basic-usage.md +6 -6
  24. data/docs/guides/chat.md +40 -16
  25. data/docs/guides/crew.md +239 -0
  26. data/docs/guides/executable-prompts.md +1 -1
  27. data/docs/guides/index.md +1 -0
  28. data/docs/guides/models.md +15 -0
  29. data/docs/index.md +29 -2
  30. data/docs/installation.md +44 -17
  31. data/docs/mcp-integration.md +40 -0
  32. data/docs/prompt_management.md +85 -86
  33. data/docs/security.md +47 -0
  34. data/docs/special_projects_guide.md +386 -0
  35. data/docs/tools-and-mcp-examples.md +23 -0
  36. data/docs/workflows-and-pipelines.md +84 -7
  37. data/examples/.gitignore +1 -0
  38. data/examples/00_setup_aia.sh +27 -44
  39. data/examples/11_multi_model.sh +4 -14
  40. data/examples/12_token_usage.sh +3 -12
  41. data/examples/18_tools.sh +10 -2
  42. data/examples/22_chat_mode.sh +0 -10
  43. data/examples/23_verify.sh +139 -0
  44. data/examples/24_decompose.sh +139 -0
  45. data/examples/25_spawn.sh +139 -0
  46. data/examples/26_debate.sh +97 -0
  47. data/examples/27_mention_routing.sh +157 -0
  48. data/examples/28_model_switching.sh +106 -0
  49. data/examples/29_agent_harness.sh +177 -0
  50. data/examples/README.md +65 -0
  51. data/examples/advanced_multi_robot_capabilities_without_examples.md +106 -0
  52. data/examples/aia_config.yml +1 -1
  53. data/examples/aia_config_orchestrator.yml +45 -0
  54. data/examples/common.sh +18 -6
  55. data/examples/context/tech_stack.md +2 -2
  56. data/examples/prompts_dir/roles/orchestrator.md +21 -0
  57. data/examples/requirements/sinatra_taskflow_app.md +139 -0
  58. data/examples/rules/01_classify_ruby.rb +16 -0
  59. data/examples/rules/02_prefer_claude_for_code.rb +19 -0
  60. data/examples/rules/03_gate_prompt_length.rb +19 -0
  61. data/examples/rules/04_tool_selection.rb +41 -0
  62. data/examples/rules/README.md +30 -0
  63. data/examples/run_all.sh +48 -15
  64. data/examples/tools/word_count_tool.rb +1 -1
  65. data/lib/AGENTS.md +57 -0
  66. data/lib/aia/chat_loop.rb +304 -164
  67. data/lib/aia/config/cli_parser.rb +174 -111
  68. data/lib/aia/config/defaults.yml +62 -33
  69. data/lib/aia/config/mcp_parser.rb +39 -46
  70. data/lib/aia/config/model_spec.rb +34 -2
  71. data/lib/aia/config/validator.rb +108 -142
  72. data/lib/aia/config.rb +110 -145
  73. data/lib/aia/content_extractor.rb +153 -0
  74. data/lib/aia/cost_calculator.rb +38 -0
  75. data/lib/aia/crew.rb +164 -0
  76. data/lib/aia/debate_handler.rb +166 -0
  77. data/lib/aia/delegate_handler.rb +112 -0
  78. data/lib/aia/directive.rb +33 -18
  79. data/lib/aia/directive_processor.rb +16 -7
  80. data/lib/aia/directives/configuration_directives.rb +160 -20
  81. data/lib/aia/directives/context_directives.rb +38 -26
  82. data/lib/aia/directives/execution_directives.rb +136 -4
  83. data/lib/aia/directives/model_directives.rb +76 -34
  84. data/lib/aia/directives/trakflow_directives.rb +44 -0
  85. data/lib/aia/directives/utility_directives.rb +203 -6
  86. data/lib/aia/directives/web_and_file_directives.rb +96 -60
  87. data/lib/aia/errors.rb +15 -0
  88. data/lib/aia/fact_asserter.rb +27 -0
  89. data/lib/aia/fzf.rb +9 -31
  90. data/lib/aia/handler_context.rb +17 -0
  91. data/lib/aia/handler_protocol.rb +19 -0
  92. data/lib/aia/history_transfer.rb +55 -0
  93. data/lib/aia/input_collector.rb +3 -3
  94. data/lib/aia/layered_orchestrator.rb +448 -0
  95. data/lib/aia/logger.rb +24 -4
  96. data/lib/aia/mcp_config_normalizer.rb +35 -0
  97. data/lib/aia/mcp_connection_manager.rb +305 -0
  98. data/lib/aia/mcp_discovery.rb +44 -0
  99. data/lib/aia/mcp_grouper.rb +33 -0
  100. data/lib/aia/mcp_utility.rb +57 -0
  101. data/lib/aia/mention_router.rb +260 -0
  102. data/lib/aia/model_alias_registry.rb +97 -0
  103. data/lib/aia/model_switch_handler.rb +100 -0
  104. data/lib/aia/network_builder.rb +155 -0
  105. data/lib/aia/network_memory_manager.rb +55 -0
  106. data/lib/aia/patches/ruby_llm_streaming_error.rb +43 -0
  107. data/lib/aia/patches/ruby_llm_tool_error.rb +96 -0
  108. data/lib/aia/pipeline_orchestrator.rb +262 -0
  109. data/lib/aia/plugin_loader.rb +170 -0
  110. data/lib/aia/plugin_monitor.rb +208 -0
  111. data/lib/aia/prompt_decomposer.rb +157 -0
  112. data/lib/aia/prompt_handler.rb +19 -39
  113. data/lib/aia/robot_builder.rb +51 -0
  114. data/lib/aia/robot_factory.rb +334 -0
  115. data/lib/aia/robot_namer.rb +116 -0
  116. data/lib/aia/session.rb +83 -17
  117. data/lib/aia/session_tracker.rb +209 -0
  118. data/lib/aia/similarity_scorer.rb +39 -0
  119. data/lib/aia/skill_utils.rb +105 -1
  120. data/lib/aia/spawn_handler.rb +129 -0
  121. data/lib/aia/spawn_spec_parser.rb +65 -0
  122. data/lib/aia/special_mode_handler.rb +302 -0
  123. data/lib/aia/startup_coordinator.rb +150 -0
  124. data/lib/aia/streaming_runner.rb +169 -0
  125. data/lib/aia/system_prompt_assembler.rb +88 -0
  126. data/lib/aia/task_coordinator.rb +202 -0
  127. data/lib/aia/task_decomposer.rb +57 -0
  128. data/lib/aia/task_executor.rb +51 -0
  129. data/lib/aia/tfidf_math.rb +27 -0
  130. data/lib/aia/tool_filter/tfidf.rb +116 -0
  131. data/lib/aia/tool_filter/wordnet_expander.rb +127 -0
  132. data/lib/aia/tool_filter.rb +82 -0
  133. data/lib/aia/tool_filter_registry.rb +30 -0
  134. data/lib/aia/tool_filter_strategy.rb +143 -0
  135. data/lib/aia/tool_loader.rb +210 -0
  136. data/lib/aia/tool_utility.rb +30 -0
  137. data/lib/aia/tools/delegate_to_foreman_tool.rb +70 -0
  138. data/lib/aia/tools/recruit_robot_tool.rb +60 -0
  139. data/lib/aia/tools/reskill_robot_tool.rb +44 -0
  140. data/lib/aia/tools/task_board_tool.rb +114 -0
  141. data/lib/aia/trakflow_bridge.rb +173 -0
  142. data/lib/aia/turn_state.rb +94 -0
  143. data/lib/aia/ui_presenter.rb +166 -198
  144. data/lib/aia/utility.rb +134 -87
  145. data/lib/aia/{history_manager.rb → variable_input_collector.rb} +8 -9
  146. data/lib/aia/verification_network.rb +58 -0
  147. data/lib/aia.rb +108 -63
  148. data/mkdocs.yml +1 -0
  149. metadata +179 -56
  150. data/justfile +0 -215
  151. data/lib/aia/adapter/chat_execution.rb +0 -242
  152. data/lib/aia/adapter/error_handler.rb +0 -68
  153. data/lib/aia/adapter/gem_activator.rb +0 -57
  154. data/lib/aia/adapter/mcp_connector.rb +0 -274
  155. data/lib/aia/adapter/modality_handlers.rb +0 -167
  156. data/lib/aia/adapter/model_registry.rb +0 -81
  157. data/lib/aia/adapter/multi_model_chat.rb +0 -218
  158. data/lib/aia/adapter/provider_configurator.rb +0 -59
  159. data/lib/aia/adapter/tool_filter.rb +0 -85
  160. data/lib/aia/adapter/tool_loader.rb +0 -90
  161. data/lib/aia/chat_processor_service.rb +0 -178
  162. data/lib/aia/prompt_pipeline.rb +0 -183
  163. data/lib/aia/ruby_llm_adapter.rb +0 -95
  164. data/lib/extensions/openstruct_merge.rb +0 -48
  165. data/lib/extensions/ruby_llm/.irbrc +0 -56
  166. data/lib/extensions/ruby_llm/modalities.rb +0 -36
  167. data/lib/extensions/ruby_llm/provider_fix.rb +0 -79
  168. data/lib/refinements/string.rb +0 -16
  169. data/main.just +0 -76
data/examples/run_all.sh CHANGED
@@ -9,15 +9,18 @@
9
9
  # differences (missing sections, crashes, changed command output).
10
10
  #
11
11
  # What it skips:
12
- # - 00_setup_aia.sh — run manually first (pulls models, writes config)
13
- # - 15_parameters.sh — Part 2 prompts interactively for a required param
14
- # - 20_mcp_servers.sh — requires Node.js/npx + MCP filesystem server
15
- # - 22_chat_mode.sh — interactive chat (Parts 1-4 use expect; Part 5
16
- # opens a live session)
12
+ # - 00_setup_aia.sh — run manually first (pulls models, writes config)
13
+ # - 15_parameters.sh — Part 2 prompts interactively for a required param
14
+ # - 20_mcp_servers.sh — requires Node.js/npx + MCP filesystem server
15
+ # - 22_chat_mode.sh — interactive chat (Parts 1-4 use expect; Part 5
16
+ # opens a live session)
17
+ # - 29_agent_harness.sh — 3-tier orchestration (10-20 min runtime)
18
+ #
19
+ # Scripts 23-28 run with BATCH_MODE=true, which skips their interactive
20
+ # "your turn" sections but still executes the automated expect-based parts.
17
21
  #
18
22
  # Prerequisites:
19
- # - Run 00_setup_aia.sh first
20
- # - Ollama running with qwen3 model available
23
+ # - Run 00_setup_aia.sh first (OPENAI_API_KEY must be set)
21
24
  #
22
25
  # Usage:
23
26
  # cd examples
@@ -61,14 +64,17 @@ Comparing runs:
61
64
  diff output/run_PREV.log output/run_LATEST.log
62
65
 
63
66
  Skipped scripts (require manual or interactive setup):
64
- 00_setup_aia.sh — run manually first (pulls models, writes config)
65
- 15_parameters.sh — Part 2 prompts interactively for a required param
66
- 20_mcp_servers.sh — requires Node.js/npx + MCP filesystem server
67
- 22_chat_mode.sh — interactive chat session
67
+ 00_setup_aia.sh — run manually first (pulls models, writes config)
68
+ 15_parameters.sh — Part 2 prompts interactively for a required param
69
+ 20_mcp_servers.sh — requires Node.js/npx + MCP filesystem server
70
+ 22_chat_mode.sh — interactive chat session
71
+ 29_agent_harness.sh — 3-tier orchestration (10-20 min runtime)
72
+
73
+ Scripts 23-28 run with BATCH_MODE=true, which skips their interactive
74
+ "your turn" sections but still runs the automated expect-based parts.
68
75
 
69
76
  Prerequisites:
70
- 1. Run 00_setup_aia.sh first
71
- 2. Ollama running with the qwen3 model available
77
+ 1. Run 00_setup_aia.sh first (OPENAI_API_KEY must be set)
72
78
 
73
79
  Exit codes:
74
80
  0 All scripts completed (some may have non-fatal warnings)
@@ -129,12 +135,20 @@ SCRIPTS=(
129
135
  # 20_mcp_servers.sh — skipped: requires npx + MCP server
130
136
  21_executable_prompts.sh
131
137
  # 22_chat_mode.sh — skipped: interactive chat session
138
+ 23_verify.sh
139
+ 24_decompose.sh
140
+ 25_spawn.sh
141
+ 26_debate.sh
142
+ 27_mention_routing.sh
143
+ 28_model_switching.sh
144
+ # 29_agent_harness.sh — skipped: 3-tier orchestration, 10-20 min runtime
132
145
  )
133
146
 
134
147
  SKIPPED=(
135
- "15_parameters.sh (interactive parameter input)"
148
+ "15_parameters.sh (interactive parameter input)"
136
149
  "20_mcp_servers.sh (requires Node.js/npx + MCP server)"
137
- "22_chat_mode.sh (interactive chat session)"
150
+ "22_chat_mode.sh (interactive chat session)"
151
+ "29_agent_harness.sh (3-tier orchestration, 10-20 min runtime)"
138
152
  )
139
153
 
140
154
  # --- Set up output ---
@@ -200,6 +214,16 @@ run_script() {
200
214
  return ${status}
201
215
  }
202
216
 
217
+ # Scripts that require BATCH_MODE=true to skip their interactive sessions
218
+ BATCH_MODE_SCRIPTS=(
219
+ 23_verify.sh
220
+ 24_decompose.sh
221
+ 25_spawn.sh
222
+ 26_debate.sh
223
+ 27_mention_routing.sh
224
+ 28_model_switching.sh
225
+ )
226
+
203
227
  # --- Main ---
204
228
 
205
229
  main() {
@@ -214,6 +238,13 @@ main() {
214
238
  local script="${SCRIPTS[$i]}"
215
239
  local index=$((i + 1))
216
240
 
241
+ # Enable batch mode for scripts with interactive "your turn" sessions
242
+ if printf '%s\n' "${BATCH_MODE_SCRIPTS[@]}" | grep -qx "${script}"; then
243
+ export BATCH_MODE=true
244
+ else
245
+ unset BATCH_MODE
246
+ fi
247
+
217
248
  if run_script "${script}" "${index}" "${total}"; then
218
249
  ((passed++))
219
250
  else
@@ -222,6 +253,8 @@ main() {
222
253
  fi
223
254
  done
224
255
 
256
+ unset BATCH_MODE
257
+
225
258
  echo "================================================================================"
226
259
  echo " Summary"
227
260
  echo "================================================================================"
@@ -6,7 +6,7 @@ require 'ruby_llm/tool'
6
6
  class WordCountTool < RubyLLM::Tool
7
7
  def self.name = 'word_count'
8
8
 
9
- description <<~'DESC'
9
+ description <<~DESC
10
10
  Count words, characters, lines, and sentences in a given text.
11
11
  Useful for text analysis and content length checks.
12
12
  DESC
data/lib/AGENTS.md ADDED
@@ -0,0 +1,57 @@
1
+ ### Local Agent Context: lib
2
+
3
+ ## Setup & Commands
4
+
5
+ - To run the AIA application, use: `ruby lib/aia.rb`
6
+ - Set up configurations by editing `lib/aia/config/defaults.yml` or using environment variables prefixed with `AIA_`.
7
+
8
+ ## Code Style & Patterns
9
+
10
+ - Use single source of truth for configs: defined in `lib/aia/config/defaults.yml`
11
+ - CLI flags are mapped to nested config locations using the `CLI_TO_NESTED_MAP` hash within `aia/config.rb`.
12
+ - Initialize new components within the AIA module using `AIA` namespace, e.g., `AIA::ChatLoop`.
13
+
14
+ ## Implementation Details
15
+
16
+ ### Entry Point - `lib/aia.rb`
17
+ - Main application entry starts by loading essential modules and patches.
18
+ - Use `AIA.run` as the entrypoint method which initializes configuration, validates it, and starts the session.
19
+
20
+ ### Configuring AIA - `lib/aia/config.rb`
21
+ - Configurations are merged from sources in priority: defaults => user config => ENV => CLI.
22
+ - Use `Config.setup(cli_overrides)` to initialize configuration with CLI argument overrides.
23
+ - Ensure `lib/aia/config/model_spec.rb` is loaded for model specification handling.
24
+ - Top-level config sections include: `service`, `llm`, `prompts`, `roles`, `skills`, `output`, `audio`, `image`, `embedding`, `tools`, `flags`, `registry`, `paths`, `logger`, `rules`, `concurrency`, `tool_filter`.
25
+ - `roles` and `skills` are proper config sections; `AIA.config.skills.dir` returns the resolved skills directory.
26
+
27
+ ### Directive System - `lib/aia/directive.rb` and `lib/aia/directives/`
28
+ - `AIA::Directive` (base class) inherits from `PM::Directive` and adds AIA-specific concerns.
29
+ - `DIRECTIVE_PREFIX = '/'` — all chat directives use a single slash, not `//`.
30
+ - The base class provides `parse_search_terms(args)` as a private instance method available to all directive subclasses. It splits args into `[positive_terms, negative_terms]`: bare terms and `+prefix` are positive (AND); `-`, `~`, or `!` prefix marks AND NOT terms.
31
+ - Directive subclasses live in `lib/aia/directives/`:
32
+ - `web_and_file_directives.rb` — `/skill`, `/skills`, `/webpage`, `/paste`
33
+ - `model_directives.rb` — `/llms` (and aliases), `/compare`
34
+ - `context_directives.rb`, `execution_directives.rb`, `navigation_directives.rb`, `special_mode_directives.rb`, `config_directives.rb`
35
+
36
+ ### `/skill` and `/skills` Directives - `lib/aia/directives/web_and_file_directives.rb`
37
+ - Skills directory resolves via `aia_skills_dir`: `AIA.config.skills.dir` → `$AIA_SKILLS__DIR` → `~/.prompts/skills`.
38
+ - A skill is a subdirectory containing a `SKILL.md` file with YAML front matter (`name`, `description`).
39
+ - `/skill <id>` reads and returns the full `SKILL.md` content. On error, prints to stdout and returns `nil` (nothing injected into the AI prompt).
40
+ - `/skills [terms...]` prints `skill_id: name\n description\n\n` to stdout for each matching skill; returns `nil`. Supports AND logic for positive terms and AND NOT for `-`/`~`/`!`-prefixed terms.
41
+
42
+ ### `/llms` Directive - `lib/aia/directives/model_directives.rb`
43
+ - `available_models` (aliased as `/llms`, `/models`, etc.) parses args with `parse_search_terms` into `positive_terms` and `negative_terms`.
44
+ - Passes both to `show_rubyllm_models(positive_terms, negative_terms)`, `show_ollama_models(api_base, positive_terms, negative_terms)`, and `show_lms_models(api_base, positive_terms, negative_terms)`.
45
+ - Negative terms apply AND NOT filtering: models whose entry string contains any negative term are excluded.
46
+
47
+ ### Chat Loop Operation - `lib/aia/chat_loop.rb`
48
+ - `AIA::ChatLoop` handles the interactive chat REPL loop.
49
+ - Initialize the chat loop with components: `robot`, `ui_presenter`, `directive_processor`.
50
+ - Start the chat loop with `ChatLoop#start`, which sets up the session, processes context, and runs the interactive loop.
51
+
52
+ ### Error Handling
53
+ - Use `AIA.debug_warn(msg, exc: nil)` to log warnings with optional debug backtrace.
54
+ - Catch `AIA::ConfigurationError` and `AIA::Error` in the run method to handle config and general errors gracefully.
55
+
56
+ ### Resetting State
57
+ - `AIA.reset!` reinitializes key components, suitable for stateful parts (e.g., `config`, `client`).