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
@@ -1,3 +1,43 @@
1
+ <!-- Tocer[start]: Auto-generated, don't remove. -->
2
+
3
+ ## Table of Contents
4
+
5
+ - [MCP Integration](#mcp-integration)
6
+ - [Understanding MCP](#understanding-mcp)
7
+ - [What is MCP?](#what-is-mcp)
8
+ - [MCP vs RubyLLM Tools](#mcp-vs-rubyllm-tools)
9
+ - [Enabling MCP Support](#enabling-mcp-support)
10
+ - [Configuration](#configuration)
11
+ - [Command Line Usage](#command-line-usage)
12
+ - [Available MCP Clients](#available-mcp-clients)
13
+ - [GitHub Integration](#github-integration)
14
+ - [File System Access](#file-system-access)
15
+ - [Database Integration](#database-integration)
16
+ - [Using MCP Clients in Prompts](#using-mcp-clients-in-prompts)
17
+ - [GitHub Analysis](#github-analysis)
18
+ - [File System Operations](#file-system-operations)
19
+ - [Database Schema Analysis](#database-schema-analysis)
20
+ - [Advanced MCP Integration](#advanced-mcp-integration)
21
+ - [Multi-Client Workflows](#multi-client-workflows)
22
+ - [Conditional MCP Usage](#conditional-mcp-usage)
23
+ - [Custom MCP Client Development](#custom-mcp-client-development)
24
+ - [Basic MCP Server Structure](#basic-mcp-server-structure)
25
+ - [Node.js MCP Server](#nodejs-mcp-server)
26
+ - [MCP Security and Best Practices](#mcp-security-and-best-practices)
27
+ - [Access Control](#access-control)
28
+ - [Server Configuration Security](#server-configuration-security)
29
+ - [Parallel Connections](#parallel-connections)
30
+ - [Troubleshooting MCP](#troubleshooting-mcp)
31
+ - [Common Issues](#common-issues)
32
+ - [Client Connection Failures](#client-connection-failures)
33
+ - [Protocol Errors](#protocol-errors)
34
+ - [MCP Examples Repository](#mcp-examples-repository)
35
+ - [GitHub Repository Analysis](#github-repository-analysis)
36
+ - [File System Audit](#file-system-audit)
37
+ - [Related Documentation](#related-documentation)
38
+
39
+ <!-- Tocer[finish]: Auto-generated, don't remove. -->
40
+
1
41
  # MCP Integration
2
42
 
3
43
  AIA supports Model Context Protocol (MCP) clients, enabling AI models to interact with external services, databases, and applications through standardized interfaces.
@@ -1,3 +1,70 @@
1
+ <!-- Tocer[start]: Auto-generated, don't remove. -->
2
+
3
+ ## Table of Contents
4
+
5
+ - [Prompt Management](#prompt-management)
6
+ - [Directory Structure](#directory-structure)
7
+ - [Default Structure](#default-structure)
8
+ - [Custom Structure](#custom-structure)
9
+ - [Prompt File Formats](#prompt-file-formats)
10
+ - [Basic Text Prompts](#basic-text-prompts)
11
+ - [Available Directives](#available-directives)
12
+ - [Prompts with Directives](#prompts-with-directives)
13
+ - [ERB Template Prompts](#erb-template-prompts)
14
+ - [Executable Prompts](#executable-prompts)
15
+ - [Prompt Discovery and Search](#prompt-discovery-and-search)
16
+ - [Basic Search](#basic-search)
17
+ - [Fuzzy Search (with fzf)](#fuzzy-search-with-fzf)
18
+ - [Advanced Search](#advanced-search)
19
+ - [Prompt Organization Strategies](#prompt-organization-strategies)
20
+ - [By Domain/Category](#by-domaincategory)
21
+ - [By Complexity](#by-complexity)
22
+ - [By Model Type](#by-model-type)
23
+ - [By Workflow Stage](#by-workflow-stage)
24
+ - [Parameterized Prompts](#parameterized-prompts)
25
+ - [ERB Variables](#erb-variables)
26
+ - [Usage with Parameters](#usage-with-parameters)
27
+ - [Parameter Extraction](#parameter-extraction)
28
+ - [Roles and Context](#roles-and-context)
29
+ - [Role Definitions](#role-definitions)
30
+ - [Using Roles](#using-roles)
31
+ - [Context Layering](#context-layering)
32
+ - [Chat Session Checkpoints](#chat-session-checkpoints)
33
+ - [Prompt Workflows and Pipelines](#prompt-workflows-and-pipelines)
34
+ - [Simple Workflows](#simple-workflows)
35
+ - [Complex Pipelines](#complex-pipelines)
36
+ - [Conditional Workflows](#conditional-workflows)
37
+ - [Version Control for Prompts](#version-control-for-prompts)
38
+ - [Git Integration](#git-integration)
39
+ - [Backup and Sync](#backup-and-sync)
40
+ - [Versioned Prompts](#versioned-prompts)
41
+ - [Prompt Sharing and Collaboration](#prompt-sharing-and-collaboration)
42
+ - [Team Prompt Libraries](#team-prompt-libraries)
43
+ - [Prompt Documentation](#prompt-documentation)
44
+ - [Prompt Standards](#prompt-standards)
45
+ - [Performance and Optimization](#performance-and-optimization)
46
+ - [Prompt Efficiency](#prompt-efficiency)
47
+ - [Caching Strategies](#caching-strategies)
48
+ - [Batch Processing](#batch-processing)
49
+ - [Troubleshooting Prompts](#troubleshooting-prompts)
50
+ - [Debugging Tools](#debugging-tools)
51
+ - [Common Issues](#common-issues)
52
+ - [Missing Parameters](#missing-parameters)
53
+ - [File Not Found](#file-not-found)
54
+ - [Permission Errors](#permission-errors)
55
+ - [Advanced Prompt Techniques](#advanced-prompt-techniques)
56
+ - [Dynamic Prompt Generation](#dynamic-prompt-generation)
57
+ - [Prompt Composition](#prompt-composition)
58
+ - [Adaptive Prompts](#adaptive-prompts)
59
+ - [Best Practices](#best-practices)
60
+ - [Prompt Design](#prompt-design)
61
+ - [Organization](#organization)
62
+ - [Recommended Directory Structure](#recommended-directory-structure)
63
+ - [Performance](#performance)
64
+ - [Related Documentation](#related-documentation)
65
+
66
+ <!-- Tocer[finish]: Auto-generated, don't remove. -->
67
+
1
68
  # Prompt Management
2
69
 
3
70
  AIA provides sophisticated prompt management capabilities through the PM gem, enabling you to organize, version, and efficiently use large collections of prompts.
@@ -8,15 +75,10 @@ AIA provides sophisticated prompt management capabilities through the PM gem, en
8
75
  ```
9
76
  ~/.prompts/
10
77
  ├── README.md # Documentation for your prompt collection
11
- ├── roles/ # Role definitions (LLM personality/persona)
78
+ ├── roles/ # Role-based prompts for context setting
12
79
  │ ├── assistant.md
13
80
  │ ├── code_expert.md
14
81
  │ └── teacher.md
15
- ├── skills/ # Skill definitions (task instructions)
16
- │ ├── code-review/
17
- │ │ └── SKILL.md # YAML front matter + instruction body
18
- │ └── summarizer/
19
- │ └── SKILL.md
20
82
  ├── development/ # Development-related prompts
21
83
  │ ├── code_review.md
22
84
  │ ├── debug_help.md
@@ -57,6 +119,21 @@ Please answer this question clearly and concisely:
57
119
  Provide examples where helpful.
58
120
  ```
59
121
 
122
+ ### Available Directives
123
+
124
+ Key directives available in prompt files:
125
+
126
+ - `/config key value` — Set a configuration value for this prompt run
127
+ - `/include path` — Insert the contents of a file at this point
128
+ - `/shell command` — Execute a shell command and insert its output (prompt_manager feature, processed at load time)
129
+ - `/ruby code` — Execute a Ruby one-liner and insert its output
130
+ - `/next prompt_id` — Set the next prompt to run in sequence
131
+ - `/pipeline id1,id2,...` — Define a multi-step prompt pipeline
132
+ - `/paste` — Insert the current system clipboard contents at this point in the conversation
133
+ - `/skill name` — Include a Claude Code skill file by name prefix match
134
+
135
+ See the [Directives Reference](directives-reference.md) for the full list.
136
+
60
137
  ### Prompts with Directives
61
138
  ```markdown
62
139
  # ~/.prompts/code_analysis.md
@@ -297,87 +374,9 @@ Current Task:
297
374
  Please provide guidance consistent with the project architecture and your role as <%= role %>.
298
375
  ```
299
376
 
300
- ## Skills
301
-
302
- ### Roles vs Skills
303
-
304
- These two concepts work together but serve distinct purposes:
305
-
306
- | Concept | Defines | Loaded from | Injected as |
307
- |---------|---------|-------------|-------------|
308
- | **Role** | LLM *personality* — who the model is | `~/.prompts/roles/<id>.md` | First, before skills and prompt |
309
- | **Skill** | Task *instructions* — how to approach the work | `~/.prompts/skills/<name>/SKILL.md` | After role, before user prompt |
310
-
311
- A **role** sets the persona: "You are a senior Ruby developer with deep expertise in performance optimization."
312
-
313
- A **skill** provides procedural guidance for that persona to follow when executing the user's request: "When reviewing code, always check for: N+1 queries, missing indexes, memory leaks, and security vulnerabilities. Present findings as a prioritized list."
314
-
315
- The assembled prompt order is:
316
-
317
- ```
318
- 1. Role content ← WHO the LLM is (personality)
319
- 2. Skill content(s) ← HOW to approach the task (instructions)
320
- 3. User prompt ← WHAT to do (request)
321
- 4. Context files ← supporting material
322
- ```
323
-
324
- ### Skill File Format
325
-
326
- Each skill lives in its own subdirectory under `~/.prompts/skills/`. The subdirectory must contain a `SKILL.md` file with YAML front matter followed by the skill instruction body:
327
-
328
- ```markdown
329
- ---
330
- name: code-review
331
- description: Thorough code review focusing on correctness, security, and maintainability.
332
- user-invocable: true
333
- argument-hint: ["file or topic to review"]
334
- ---
335
-
336
- When reviewing code, systematically check:
337
-
338
- 1. **Correctness** — Does the logic match the stated intent? Are edge cases handled?
339
- 2. **Security** — Are there injection risks, unsafe deserialization, or exposed secrets?
340
- 3. **Performance** — Are there N+1 queries, unbounded loops, or unnecessary allocations?
341
- 4. **Maintainability** — Is the code readable? Are names clear? Is complexity justified?
342
-
343
- Present findings as a prioritized list with file:line references where applicable.
344
- Always suggest a concrete fix, not just identification of the problem.
345
- ```
346
-
347
- The YAML front matter is metadata only. Only the body (everything after the closing `---`) is injected into the prompt.
348
-
349
- ### Using Skills
350
-
351
- ```bash
352
- # Prepend a skill before the user prompt
353
- aia --skill code-review review_prompt my_code.rb
354
-
355
- # Combine role + skill for maximum context
356
- aia --role ruby_expert --skill code-review review_prompt my_code.rb
357
-
358
- # Multiple skills (applied in order)
359
- aia --skill code-review --skill security-audit review_prompt my_code.rb
360
- aia -s code-review,security-audit review_prompt my_code.rb
361
-
362
- # List available skills
363
- aia --list-skills
364
-
365
- # Use a skill from within a chat session
366
- /skill code-review
367
- ```
368
-
369
- ### Skills in Chat Mode
370
-
371
- In chat mode, use the `/skill` directive to inject a skill at any point in the conversation:
372
-
373
- ```
374
- > /skill summarizer
375
- [Skill "summarizer" instructions are injected into the next message context]
376
-
377
- > Please summarize the discussion so far.
378
- ```
377
+ ## Chat Session Checkpoints
379
378
 
380
- The `/skill` directive injects only the body content of `SKILL.md` — the YAML front matter is never sent to the LLM.
379
+ In interactive chat sessions, use `/checkpoint [name]` to save the current conversation state, `/restore [name]` to return to it, and `/checkpoints` to list all saved checkpoints. `/clear` resets the conversation entirely.
381
380
 
382
381
  ## Prompt Workflows and Pipelines
383
382
 
data/docs/security.md CHANGED
@@ -1,3 +1,46 @@
1
+ <!-- Tocer[start]: Auto-generated, don't remove. -->
2
+
3
+ ## Table of Contents
4
+
5
+ - [Security Best Practices](#security-best-practices)
6
+ - [API Key Security](#api-key-security)
7
+ - [Storage and Management](#storage-and-management)
8
+ - [Key Permissions and Scope](#key-permissions-and-scope)
9
+ - [Key Validation and Testing](#key-validation-and-testing)
10
+ - [Code Execution Directives](#code-execution-directives)
11
+ - [/ruby Directive](#ruby-directive)
12
+ - [/shell Directive](#shell-directive)
13
+ - [ERB Processing](#erb-processing)
14
+ - [Prompt Security](#prompt-security)
15
+ - [Input Sanitization](#input-sanitization)
16
+ - [Prompt Injection Prevention](#prompt-injection-prevention)
17
+ - [Content Filtering](#content-filtering)
18
+ - [File System Security](#file-system-security)
19
+ - [Safe File Operations](#safe-file-operations)
20
+ - [Directory Traversal Prevention](#directory-traversal-prevention)
21
+ - [Network Security](#network-security)
22
+ - [HTTP Request Validation](#http-request-validation)
23
+ - [Request Rate Limiting](#request-rate-limiting)
24
+ - [Shell Command Security](#shell-command-security)
25
+ - [Command Sanitization](#command-sanitization)
26
+ - [Environment Variable Sanitization](#environment-variable-sanitization)
27
+ - [Tool and MCP Security](#tool-and-mcp-security)
28
+ - [Tool Access Control](#tool-access-control)
29
+ - [MCP Server Configuration Security](#mcp-server-configuration-security)
30
+ - [Environment-Specific Tips](#environment-specific-tips)
31
+ - [Monitoring and Auditing](#monitoring-and-auditing)
32
+ - [Security Logging](#security-logging)
33
+ - [Usage Monitoring](#usage-monitoring)
34
+ - [Incident Response](#incident-response)
35
+ - [Security Incident Detection](#security-incident-detection)
36
+ - [Automated Response](#automated-response)
37
+ - [Security Checklist](#security-checklist)
38
+ - [Pre-deployment Security Review](#pre-deployment-security-review)
39
+ - [Regular Security Maintenance](#regular-security-maintenance)
40
+ - [Related Documentation](#related-documentation)
41
+
42
+ <!-- Tocer[finish]: Auto-generated, don't remove. -->
43
+
1
44
  # Security Best Practices
2
45
 
3
46
  Security considerations and best practices for using AIA safely in various environments.
@@ -72,6 +115,8 @@ The `/shell` directive executes system commands with your user permissions:
72
115
  /shell cat /path/to/file
73
116
  ```
74
117
 
118
+ **Note**: `/shell` is a `prompt_manager` feature processed during prompt file loading, not a chat-time directive. In prompt files it executes shell commands via `//shell`. In interactive chat, use `/ruby` with backtick syntax for shell execution.
119
+
75
120
  **Mitigations**:
76
121
  - Same precautions as `/ruby` — only use with trusted prompts
77
122
  - Consider the implications of any shell command before running it
@@ -85,6 +130,8 @@ The current user is: <%= `whoami`.strip %>
85
130
  Today's date is: <%= Date.today %>
86
131
  ```
87
132
 
133
+ **Note**: ERB templates are always evaluated for `.md` prompt files and cannot be disabled per-prompt. The ERB evaluation context has full access to `ENV`, Ruby's standard library, and backtick shell execution — review prompts from untrusted sources carefully.
134
+
88
135
  **Mitigations**:
89
136
  - Review prompt files before running them, especially from untrusted sources
90
137
  - ERB processing is always enabled and cannot be disabled per-prompt
@@ -0,0 +1,386 @@
1
+ <!-- Tocer[start]: Auto-generated, don't remove. -->
2
+
3
+ ## Table of Contents
4
+
5
+ - [Special Projects Guide](#special-projects-guide)
6
+ - [Table of Contents](#table-of-contents)
7
+ - [Dynamic Model Switching](#dynamic-model-switching)
8
+ - [@mention Routing](#mention-routing)
9
+ - [Supported Phrases](#supported-phrases)
10
+ - [How It Works](#how-it-works)
11
+ - [Model Aliases](#model-aliases)
12
+ - [Custom Aliases](#custom-aliases)
13
+ - [Conversation History on Switch](#conversation-history-on-switch)
14
+ - [MCP Server Concurrency](#mcp-server-concurrency)
15
+ - [Configuration](#configuration)
16
+ - [Three Ways to Trigger](#three-ways-to-trigger)
17
+ - [Server Grouping](#server-grouping)
18
+ - [TrakFlow Integration](#trakflow-integration)
19
+ - [Setup](#setup)
20
+ - [Chat Directives](#chat-directives)
21
+ - [Pipeline Tracking](#pipeline-tracking)
22
+ - [Session Continuity](#session-continuity)
23
+ - [Expert Routing](#expert-routing)
24
+ - [Enable](#enable)
25
+ - [How It Works](#how-it-works-1)
26
+ - [Example Flow](#example-flow)
27
+ - [Verification Networks](#verification-networks)
28
+ - [Usage](#usage)
29
+ - [How It Works](#how-it-works-2)
30
+ - [Prompt Decomposition](#prompt-decomposition)
31
+ - [Usage](#usage-1)
32
+ - [How It Works](#how-it-works-3)
33
+ - [Session Tracking and Learning](#session-tracking-and-learning)
34
+ - [What's Tracked](#whats-tracked)
35
+ - [Learning Rules](#learning-rules)
36
+ - [Configuration Reference](#configuration-reference)
37
+ - [New Config Sections](#new-config-sections)
38
+ - [MCP Server Metadata Fields](#mcp-server-metadata-fields)
39
+
40
+ <!-- Tocer[finish]: Auto-generated, don't remove. -->
41
+
42
+ # Special Projects Guide
43
+
44
+ This guide documents the advanced features implemented from the Special Projects roadmap. Each feature builds on AIA v2's architecture of RobotFactory, ChatLoop, and the directive system.
45
+
46
+ ## Table of Contents
47
+
48
+ 1. [Dynamic Model Switching](#dynamic-model-switching)
49
+ 2. [MCP Server Concurrency](#mcp-server-concurrency)
50
+ 3. [TrakFlow Integration](#trakflow-integration)
51
+ 4. [Expert Routing](#expert-routing)
52
+ 5. [Verification Networks](#verification-networks)
53
+ 6. [Prompt Decomposition](#prompt-decomposition)
54
+ 7. [Session Tracking and Learning](#session-tracking-and-learning)
55
+ 8. [Configuration Reference](#configuration-reference)
56
+
57
+ ---
58
+
59
+ ## Dynamic Model Switching
60
+
61
+ Switch models mid-chat using natural language instead of the formal `/model` directive.
62
+
63
+ ### @mention Routing
64
+ In a multi-model network, route a message to a specific robot by prefixing its registered name with `@`:
65
+ ```
66
+ @tobor Explain your reasoning step by step.
67
+ ```
68
+ Use `/robots` to see the active crew and their `@mention` handles. The mention router scans the input for `@name` tokens, matches them against robot names, and routes the prompt only to the mentioned robots.
69
+
70
+ ### Supported Phrases
71
+
72
+ - **Switch**: "switch to claude", "use GPT-4o", "try gemini"
73
+ - **Compare**: "compare claude and gemini", "hear from both models"
74
+ - **Capability**: "use something cheaper", "switch to the best model"
75
+
76
+ ### How It Works
77
+
78
+ 1. The classification KB detects model-change intent
79
+ 2. `ModelSwitchHandler` extracts model names from the text
80
+ 3. Names are resolved through `ModelAliasRegistry`
81
+ 4. User is asked to confirm before switching
82
+ 5. Robot is rebuilt with the new model(s)
83
+
84
+ ### Model Aliases
85
+
86
+ Short names, provider names, and capability descriptors all resolve to model IDs:
87
+
88
+ | Alias | Resolves To |
89
+ |-------|------------|
90
+ | claude, sonnet | claude-sonnet-4-20250514 |
91
+ | opus | claude-opus-4-20250514 |
92
+ | haiku, fast | claude-haiku-4-5-20251001 |
93
+ | gpt4, gpt4o | gpt-4o |
94
+ | cheap, gpt4mini | gpt-4o-mini |
95
+ | best | claude-opus-4-20250514 |
96
+ | gemini, flash | gemini-2.0-flash |
97
+ | llama | llama-3.1-70b |
98
+ | anthropic | claude-sonnet-4-20250514 |
99
+ | openai | gpt-4o |
100
+ | google | gemini-2.0-flash |
101
+ | meta | llama-3.1-70b |
102
+ | coding | claude-sonnet-4-20250514 |
103
+ | vision | gpt-4o |
104
+
105
+ ### Custom Aliases
106
+
107
+ Add custom aliases in your config:
108
+
109
+ ```yaml
110
+ # ~/.config/aia/aia.yml
111
+ model_aliases:
112
+ mymodel: my-custom-model-id
113
+ team: our-fine-tuned-model
114
+ ```
115
+
116
+ ### Conversation History on Switch
117
+
118
+ Control what happens to conversation history when switching models:
119
+
120
+ ```yaml
121
+ model_switch_history: clean # fresh start (default)
122
+ model_switch_history: replay # replay all messages to new model
123
+ model_switch_history: summarize # summarize and inject context
124
+ ```
125
+
126
+ ---
127
+
128
+ ## MCP Server Concurrency
129
+
130
+ When a prompt needs multiple independent MCP servers, AIA can fan out to a robot-per-server and merge results.
131
+
132
+ ### Configuration
133
+
134
+ Add `topics` to your MCP server configs for domain-driven routing:
135
+
136
+ ```json
137
+ {
138
+ "mcpServers": {
139
+ "filesystem": {
140
+ "command": "npx",
141
+ "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path"],
142
+ "topics": ["files", "code", "directory"]
143
+ },
144
+ "database": {
145
+ "command": "python",
146
+ "args": ["-m", "mcp_server_sqlite"],
147
+ "topics": ["data", "sql", "records"]
148
+ }
149
+ }
150
+ }
151
+ ```
152
+
153
+ ### Three Ways to Trigger
154
+
155
+ 1. **Directive**: `/concurrent` before your prompt
156
+ 2. **Auto-detection**: Set `concurrency.auto: true` in config
157
+ 3. **Config-driven**: List independent servers in config
158
+
159
+ ```yaml
160
+ # ~/.config/aia/aia.yml
161
+ concurrency:
162
+ auto: true
163
+ independent_servers: [filesystem, database, web_search]
164
+ threshold: 2 # minimum independent servers to trigger
165
+ ```
166
+
167
+ ### Server Grouping
168
+
169
+ Servers can be grouped for sequential access:
170
+
171
+ ```json
172
+ {
173
+ "mcpServers": {
174
+ "db_reader": {
175
+ "command": "...",
176
+ "group": "database"
177
+ },
178
+ "db_writer": {
179
+ "command": "...",
180
+ "group": "database"
181
+ }
182
+ }
183
+ }
184
+ ```
185
+
186
+ Grouped servers run sequentially within their group; different groups run concurrently.
187
+
188
+ ---
189
+
190
+ ## TrakFlow Integration
191
+
192
+ TrakFlow is a distributed task tracking system for AI agents. AIA connects to it as an MCP server.
193
+
194
+ ### Setup
195
+
196
+ ```bash
197
+ # Add TrakFlow MCP to your AIA config
198
+ aia --mcp mcp_servers/trak_flow.json --chat
199
+ ```
200
+
201
+ ### Chat Directives
202
+
203
+ | Directive | Description |
204
+ |-----------|-------------|
205
+ | `/tasks` | Show ready tasks |
206
+ | `/tasks summary` | Show project summary |
207
+ | `/tf` | Alias for `/tasks` |
208
+ | `/plan <description>` | Create a TrakFlow plan |
209
+ | `/task <title>` | Create a single task |
210
+
211
+ ### Pipeline Tracking
212
+
213
+ Enable automatic pipeline tracking in TrakFlow:
214
+
215
+ ```yaml
216
+ flags:
217
+ track_pipeline: true
218
+ ```
219
+
220
+ When enabled, AIA creates a TrakFlow Plan for each pipeline and updates task status as steps complete:
221
+
222
+ ```
223
+ Pipeline: summarize → analyze → recommend
224
+
225
+ TrakFlow Plan:
226
+ Step 1: summarize → started → completed ✓
227
+ Step 2: analyze → started → completed ✓
228
+ Step 3: recommend → started → in_progress...
229
+ ```
230
+
231
+ ### Session Continuity
232
+
233
+ When TrakFlow is connected and you start a chat session, AIA checks for open tasks from previous sessions:
234
+
235
+ ```
236
+ Open tasks from previous sessions found:
237
+ - Step 4: Review auth module (blocked - needs user input)
238
+ - Task: Update documentation (ready)
239
+ ```
240
+
241
+ ---
242
+
243
+ ## Expert Routing
244
+
245
+ Route different prompt types to specialist robots with different models and MCP servers.
246
+
247
+ ### Enable
248
+
249
+ ```yaml
250
+ flags:
251
+ expert_routing: true
252
+ ```
253
+
254
+ ### How It Works
255
+
256
+ 1. The prompt is categorized by domain (code, data, image, planning)
257
+ 2. The best model for that domain is selected
258
+ 3. Relevant MCP servers are activated
259
+ 4. `ExpertRouter` builds a specialist robot with those specifics
260
+ 5. The specialist handles the prompt instead of the default robot
261
+
262
+ ### Example Flow
263
+
264
+ ```
265
+ User: "Refactor the auth module"
266
+ → Classification: domain=code
267
+ → Model Selection: claude-sonnet (code task)
268
+ → MCP Routing: filesystem server activated
269
+ → Expert robot built with claude-sonnet + filesystem MCP
270
+ → Specialist handles the prompt
271
+ ```
272
+
273
+ ---
274
+
275
+ ## Verification Networks
276
+
277
+ Use consensus for quality — two robots independently answer, then a third reconciles.
278
+
279
+ ### Usage
280
+
281
+ ```
282
+ /verify
283
+ How does quantum entanglement work?
284
+ ```
285
+
286
+ ### How It Works
287
+
288
+ 1. Two verifier robots independently answer the question
289
+ 2. A reconciler compares both answers
290
+ 3. The reconciler produces a final, verified answer noting agreements and uncertainties
291
+
292
+ ---
293
+
294
+ ## Prompt Decomposition
295
+
296
+ For complex prompts, a coordinator breaks them into independent sub-tasks, executes them in parallel, then synthesizes.
297
+
298
+ ### Usage
299
+
300
+ ```
301
+ /decompose
302
+ Research current AI safety approaches, compare them with historical precedents,
303
+ and recommend a framework for our team.
304
+ ```
305
+
306
+ ### How It Works
307
+
308
+ 1. The robot analyzes the prompt and identifies 2-5 independent sub-tasks
309
+ 2. Each sub-task runs separately
310
+ 3. Results are synthesized into a coherent response
311
+
312
+ If the prompt cannot be meaningfully decomposed, it falls back to normal execution.
313
+
314
+ ---
315
+
316
+ ## Session Tracking and Learning
317
+
318
+ AIA tracks session metrics for the post-response learning loop.
319
+
320
+ ### What's Tracked
321
+
322
+ Per turn:
323
+ - Model used
324
+ - Input length
325
+ - Token counts
326
+ - Cost estimate
327
+ - Routing decisions
328
+ - Timestamp
329
+
330
+ Session-wide:
331
+ - Total turns
332
+ - Total cost
333
+ - Total tokens
334
+ - Model switch events
335
+ - User feedback signals
336
+
337
+ ### Learning Rules
338
+
339
+ The post-response learning step fires after each response:
340
+
341
+ | Rule | Signal | Meaning |
342
+ |------|--------|---------|
343
+ | `track_model_switch` | model_dissatisfaction | User switched models after a response |
344
+ | `track_success` | model_success | User accepted the response |
345
+ | `cost_tracking` | cost_update | Running cost total |
346
+
347
+ These signals are currently informational. Future versions can use them to automatically adjust routing rules.
348
+
349
+ ---
350
+
351
+ ## Configuration Reference
352
+
353
+ ### New Config Sections
354
+
355
+ ```yaml
356
+ # ~/.config/aia/aia.yml
357
+
358
+ # Model aliases (custom overrides)
359
+ model_aliases:
360
+ mymodel: my-custom-model-id
361
+
362
+ # History mode on model switch
363
+ model_switch_history: clean # clean | replay | summarize
364
+
365
+ # MCP concurrency
366
+ concurrency:
367
+ auto: false
368
+ independent_servers: []
369
+ threshold: 2
370
+
371
+ # New flags
372
+ flags:
373
+ track_pipeline: false # Track pipelines in TrakFlow
374
+ expert_routing: false # Per-turn expert routing
375
+ ```
376
+
377
+ ### MCP Server Metadata Fields
378
+
379
+ ```json
380
+ {
381
+ "topics": ["code", "files"],
382
+ "independent": true,
383
+ "group": "database"
384
+ }
385
+ ```
386
+