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.
- checksums.yaml +4 -4
- data/.version +1 -1
- data/CHANGELOG.md +151 -228
- data/README.md +42 -19
- data/bin/aia +8 -3
- data/lib/aia/aia_completion.bash +2 -3
- data/lib/aia/aia_completion.fish +6 -5
- data/lib/aia/aia_completion.zsh +2 -3
- data/lib/aia/chat_loop.rb +24 -66
- data/lib/aia/config/cli_parser.rb +164 -123
- data/lib/aia/config/defaults.yml +12 -39
- data/lib/aia/config/mcp_parser.rb +42 -40
- data/lib/aia/config/model_spec.rb +8 -14
- data/lib/aia/config/validator.rb +144 -156
- data/lib/aia/config/value_caster.rb +76 -0
- data/lib/aia/config.rb +72 -54
- data/lib/aia/content_extractor.rb +2 -0
- data/lib/aia/cost_calculator.rb +1 -0
- data/lib/aia/crew.rb +29 -19
- data/lib/aia/debate_handler.rb +45 -20
- data/lib/aia/delegate_handler.rb +7 -3
- data/lib/aia/directive.rb +10 -8
- data/lib/aia/directives/configuration_directives.rb +164 -109
- data/lib/aia/directives/context_directives.rb +55 -40
- data/lib/aia/directives/execution_directives.rb +25 -25
- data/lib/aia/directives/model_directives.rb +112 -195
- data/lib/aia/directives/trakflow_directives.rb +27 -9
- data/lib/aia/directives/utility_directives.rb +86 -87
- data/lib/aia/directives/web_and_file_directives.rb +83 -63
- data/lib/aia/fact_asserter.rb +3 -3
- data/lib/aia/history_transfer.rb +64 -24
- data/lib/aia/layered_orchestrator.rb +66 -43
- data/lib/aia/logger.rb +27 -62
- data/lib/aia/mcp_config_normalizer.rb +27 -14
- data/lib/aia/mcp_connection_manager.rb +193 -186
- data/lib/aia/mcp_discovery.rb +43 -15
- data/lib/aia/mcp_grouper.rb +2 -1
- data/lib/aia/mcp_server_config.rb +48 -0
- data/lib/aia/mcp_utility.rb +28 -20
- data/lib/aia/mention_router.rb +22 -52
- data/lib/aia/modality_query.rb +36 -0
- data/lib/aia/model_alias_registry.rb +11 -11
- data/lib/aia/model_registry.rb +75 -0
- data/lib/aia/network_builder.rb +17 -11
- data/lib/aia/network_memory_manager.rb +6 -6
- data/lib/aia/patches/ruby_llm_streaming_error.rb +21 -4
- data/lib/aia/patches/ruby_llm_tool_param_compat.rb +18 -0
- data/lib/aia/pipeline_orchestrator.rb +88 -45
- data/lib/aia/plugin_monitor.rb +9 -6
- data/lib/aia/prompt_decomposer.rb +6 -4
- data/lib/aia/prompt_handler.rb +90 -69
- data/lib/aia/provider_registry.rb +105 -0
- data/lib/aia/robot_builder.rb +1 -1
- data/lib/aia/robot_factory.rb +77 -69
- data/lib/aia/robot_namer.rb +2 -8
- data/lib/aia/robot_sync.rb +79 -0
- data/lib/aia/role_catalog.rb +89 -0
- data/lib/aia/session.rb +32 -14
- data/lib/aia/session_tracker.rb +39 -41
- data/lib/aia/similarity_scorer.rb +5 -3
- data/lib/aia/skill_utils.rb +60 -19
- data/lib/aia/spawn_handler.rb +16 -4
- data/lib/aia/spawn_spec_parser.rb +6 -7
- data/lib/aia/special_mode_handler.rb +80 -57
- data/lib/aia/speech.rb +103 -0
- data/lib/aia/startup_coordinator.rb +17 -91
- data/lib/aia/streaming_runner.rb +16 -5
- data/lib/aia/system_prompt_assembler.rb +20 -15
- data/lib/aia/task_board.rb +60 -0
- data/lib/aia/task_coordinator.rb +10 -5
- data/lib/aia/timing.rb +15 -0
- data/lib/aia/tool_approver.rb +205 -0
- data/lib/aia/tool_filter.rb +1 -9
- data/lib/aia/tool_filter_strategy.rb +39 -25
- data/lib/aia/tool_introspection.rb +25 -0
- data/lib/aia/tool_loader.rb +71 -31
- data/lib/aia/tool_utility.rb +6 -5
- data/lib/aia/tools/delegate_to_foreman_tool.rb +6 -4
- data/lib/aia/tools/recruit_robot_tool.rb +12 -12
- data/lib/aia/tools/reskill_robot_tool.rb +7 -7
- data/lib/aia/tools/task_board_tool.rb +17 -16
- data/lib/aia/trakflow_bridge.rb +19 -11
- data/lib/aia/turn_state.rb +32 -8
- data/lib/aia/ui_presenter.rb +83 -59
- data/lib/aia/utility.rb +8 -24
- data/lib/aia/variable_input_collector.rb +1 -3
- data/lib/aia/verification_network.rb +10 -12
- data/lib/aia.rb +49 -8
- metadata +27 -162
- data/.better-commits.json +0 -150
- data/.config/tocer/configuration.yml +0 -6
- data/.envrc +0 -15
- data/.loki +0 -231
- data/.quality/flay_baseline.txt +0 -1
- data/.quality/flog_baseline.txt +0 -29
- data/.quality/reek_baseline.txt +0 -80
- data/.rubocop.yml +0 -116
- data/COMMITS.md +0 -196
- data/IMPLEMENTATION_PLAN.md +0 -506
- data/Rakefile +0 -160
- data/architecture_review.md +0 -314
- data/docs/AGENTS.md +0 -40
- data/docs/advanced-prompting.md +0 -814
- data/docs/assets/images/aia.png +0 -0
- data/docs/cli-reference.md +0 -1241
- data/docs/configuration.md +0 -747
- data/docs/contributing.md +0 -386
- data/docs/directives-reference.md +0 -1145
- data/docs/examples/index.md +0 -277
- data/docs/examples/mcp/index.md +0 -475
- data/docs/examples/prompts/analysis/index.md +0 -78
- data/docs/examples/prompts/automation/index.md +0 -109
- data/docs/examples/prompts/development/index.md +0 -125
- data/docs/examples/prompts/index.md +0 -333
- data/docs/examples/prompts/learning/index.md +0 -127
- data/docs/examples/prompts/writing/index.md +0 -62
- data/docs/examples/tools/index.md +0 -282
- data/docs/faq.md +0 -578
- data/docs/guides/available-models.md +0 -366
- data/docs/guides/basic-usage.md +0 -478
- data/docs/guides/chat.md +0 -680
- data/docs/guides/crew.md +0 -239
- data/docs/guides/executable-prompts.md +0 -331
- data/docs/guides/first-prompt.md +0 -454
- data/docs/guides/getting-started.md +0 -455
- data/docs/guides/image-generation.md +0 -507
- data/docs/guides/index.md +0 -48
- data/docs/guides/local-models.md +0 -306
- data/docs/guides/migrate-prompts.md +0 -335
- data/docs/guides/models.md +0 -1017
- data/docs/guides/shared-tools.md +0 -254
- data/docs/guides/tools.md +0 -831
- data/docs/index.md +0 -259
- data/docs/installation.md +0 -274
- data/docs/mcp-integration.md +0 -603
- data/docs/prompt_management.md +0 -665
- data/docs/security.md +0 -674
- data/docs/special_projects_guide.md +0 -386
- data/docs/tools-and-mcp-examples.md +0 -1211
- data/docs/workflows-and-pipelines.md +0 -636
- data/examples/.gitignore +0 -2
- data/examples/00_setup_aia.sh +0 -111
- data/examples/01_basic_usage.sh +0 -23
- data/examples/02_frontmatter.sh +0 -33
- data/examples/03_shell_integration.sh +0 -55
- data/examples/04_erb_templating.sh +0 -56
- data/examples/05_shell_then_erb.sh +0 -38
- data/examples/06_prompt_chaining.sh +0 -59
- data/examples/07_pipeline.sh +0 -46
- data/examples/08_context_files.sh +0 -43
- data/examples/09_roles.sh +0 -67
- data/examples/10_stdin_piping.sh +0 -49
- data/examples/11_multi_model.sh +0 -65
- data/examples/12_token_usage.sh +0 -52
- data/examples/13_cost_tracking.sh +0 -68
- data/examples/14_output_file.sh +0 -91
- data/examples/15_parameters.sh +0 -68
- data/examples/16_directives.sh +0 -113
- data/examples/17_require_and_conditionals.sh +0 -68
- data/examples/18_tools.sh +0 -61
- data/examples/19_local_tools.sh +0 -34
- data/examples/20_mcp_servers.sh +0 -102
- data/examples/21_executable_prompts.sh +0 -78
- data/examples/22_chat_mode.sh +0 -217
- data/examples/23_verify.sh +0 -139
- data/examples/24_decompose.sh +0 -139
- data/examples/25_spawn.sh +0 -139
- data/examples/26_debate.sh +0 -97
- data/examples/27_mention_routing.sh +0 -157
- data/examples/28_model_switching.sh +0 -106
- data/examples/29_agent_harness.sh +0 -177
- data/examples/README.md +0 -321
- data/examples/advanced_multi_robot_capabilities_without_examples.md +0 -106
- data/examples/aia_config.yml +0 -22
- data/examples/aia_config_orchestrator.yml +0 -45
- data/examples/aia_config_with_mcp.yml +0 -21
- data/examples/common.sh +0 -39
- data/examples/context/project_goals.md +0 -6
- data/examples/context/tech_stack.md +0 -7
- data/examples/directives/timestamp_directive.rb +0 -22
- data/examples/mcp/filesystem.json +0 -9
- data/examples/prompts_dir/analyze.md +0 -2
- data/examples/prompts_dir/brainstorm.md +0 -2
- data/examples/prompts_dir/conditional.md +0 -17
- data/examples/prompts_dir/creative.md +0 -4
- data/examples/prompts_dir/erbinfo.md +0 -5
- data/examples/prompts_dir/erbinfo_raw.md +0 -8
- data/examples/prompts_dir/evaluate.md +0 -2
- data/examples/prompts_dir/explain_joke.md +0 -1
- data/examples/prompts_dir/explain_recursion.md +0 -1
- data/examples/prompts_dir/fun_fact +0 -3
- data/examples/prompts_dir/greeting.md +0 -8
- data/examples/prompts_dir/greeting_required.md +0 -7
- data/examples/prompts_dir/hello.md +0 -1
- data/examples/prompts_dir/includes/ruby_facts.md +0 -4
- data/examples/prompts_dir/limerick.md +0 -1
- data/examples/prompts_dir/list_with_mcp.md +0 -3
- data/examples/prompts_dir/pick_best.md +0 -2
- data/examples/prompts_dir/project_summary +0 -12
- data/examples/prompts_dir/quiz_with_include.md +0 -6
- data/examples/prompts_dir/require_demo.md +0 -5
- data/examples/prompts_dir/roles/formal.md +0 -3
- data/examples/prompts_dir/roles/orchestrator.md +0 -21
- data/examples/prompts_dir/roles/pirate.md +0 -3
- data/examples/prompts_dir/shell_then_erb.md +0 -6
- data/examples/prompts_dir/sort_compare.md +0 -2
- data/examples/prompts_dir/summarize_context.md +0 -2
- data/examples/prompts_dir/sysinfo.md +0 -5
- data/examples/prompts_dir/sysinfo_raw.md +0 -8
- data/examples/prompts_dir/tagline.md +0 -1
- data/examples/prompts_dir/tell_joke.md +0 -1
- data/examples/prompts_dir/tell_joke_with_next.md +0 -4
- data/examples/prompts_dir/use_local_tool.md +0 -8
- data/examples/prompts_dir/use_tools.md +0 -8
- data/examples/prompts_dir/weather.md +0 -2
- data/examples/prompts_dir/whats_new.md +0 -2
- data/examples/prompts_dir/with_timestamp.md +0 -5
- data/examples/requirements/sinatra_taskflow_app.md +0 -139
- data/examples/rules/01_classify_ruby.rb +0 -16
- data/examples/rules/02_prefer_claude_for_code.rb +0 -19
- data/examples/rules/03_gate_prompt_length.rb +0 -19
- data/examples/rules/04_tool_selection.rb +0 -41
- data/examples/rules/README.md +0 -30
- data/examples/run_all.sh +0 -294
- data/examples/tools/word_count_tool.rb +0 -30
- data/lib/AGENTS.md +0 -57
- data/lib/aia/model_switch_handler.rb +0 -100
- data/mcp_servers/README.md +0 -110
- data/mcp_servers/apple-mcp.json +0 -8
- data/mcp_servers/filesystem.json +0 -9
- data/mcp_servers/mcp_server_chart.json +0 -11
- data/mcp_servers/playwright_one.json +0 -8
- data/mcp_servers/playwright_server_definition.json +0 -9
- data/mcp_servers/playwright_two.json +0 -8
- data/mcp_servers/tavily_mcp_server.json +0 -8
- data/mkdocs.yml +0 -169
|
@@ -6,49 +6,24 @@ require 'word_wrapper'
|
|
|
6
6
|
module AIA
|
|
7
7
|
class UtilityDirectives < Directive
|
|
8
8
|
desc "List available tools (optional filter by name or description substring)"
|
|
9
|
-
# rubocop:disable Metrics/AbcSize
|
|
10
9
|
def tools(args = [], context_manager = nil)
|
|
11
|
-
|
|
12
|
-
spaces = " " * indent
|
|
13
|
-
width = TTY::Screen.width - indent - 2
|
|
14
|
-
filter = args.first&.downcase
|
|
15
|
-
|
|
10
|
+
raw_filter = args.first
|
|
16
11
|
loaded_tools = Array(AIA.config.loaded_tools) + all_mcp_tools
|
|
17
12
|
|
|
18
13
|
if loaded_tools.empty?
|
|
19
14
|
puts "No tools are available"
|
|
20
15
|
else
|
|
21
|
-
tools_to_display = loaded_tools
|
|
22
|
-
|
|
23
|
-
if filter
|
|
24
|
-
tools_to_display = tools_to_display.select do |tool|
|
|
25
|
-
name = tool.respond_to?(:name) ? tool.name : tool.class.name
|
|
26
|
-
desc = tool.respond_to?(:description) ? tool.description.to_s : ""
|
|
27
|
-
"#{name} #{desc}".downcase.include?(filter)
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
16
|
+
tools_to_display = filter_tools(loaded_tools, raw_filter&.downcase)
|
|
31
17
|
if tools_to_display.empty?
|
|
32
|
-
puts "No tools match the filter: #{
|
|
18
|
+
puts "No tools match the filter: #{raw_filter}"
|
|
33
19
|
else
|
|
34
|
-
|
|
35
|
-
header = filter ? "Available Tools (filtered by '#{args.first}')" : "Available Tools"
|
|
36
|
-
puts header
|
|
37
|
-
puts "=" * header.length
|
|
38
|
-
|
|
39
|
-
tools_to_display.each do |tool|
|
|
40
|
-
name = tool.respond_to?(:name) ? tool.name : tool.class.name
|
|
41
|
-
puts "\n#{name}"
|
|
42
|
-
puts "-" * name.size
|
|
43
|
-
puts WordWrapper::MinimumRaggedness.new(width, tool.description).wrap.split("\n").map { |s| spaces + s + "\n" }.join
|
|
44
|
-
end
|
|
20
|
+
print_tools_report(tools_to_display, raw_filter)
|
|
45
21
|
end
|
|
46
22
|
end
|
|
47
23
|
puts
|
|
48
24
|
|
|
49
25
|
''
|
|
50
26
|
end
|
|
51
|
-
# rubocop:enable Metrics/AbcSize
|
|
52
27
|
|
|
53
28
|
desc "List loaded plugin basenames"
|
|
54
29
|
def plugins(args = [], context_manager = nil)
|
|
@@ -68,57 +43,22 @@ module AIA
|
|
|
68
43
|
end
|
|
69
44
|
|
|
70
45
|
desc "Show MCP server connection status and available tools"
|
|
71
|
-
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
72
46
|
def mcp(args = [], context_manager = nil)
|
|
73
47
|
connected = AIA.config&.connected_mcp_servers || []
|
|
74
48
|
failed = AIA.config&.failed_mcp_servers || []
|
|
75
|
-
defined_count = AIA::Utility.effective_mcp_server_names.size
|
|
76
49
|
|
|
77
50
|
puts
|
|
78
51
|
puts "MCP Server Status"
|
|
79
52
|
puts "================="
|
|
80
|
-
puts "Defined: #{
|
|
53
|
+
puts "Defined: #{AIA::Utility.effective_mcp_server_names.size} " \
|
|
54
|
+
"Connected: #{connected.size} Failed: #{failed.size}"
|
|
81
55
|
puts
|
|
82
56
|
|
|
83
|
-
if connected.any?
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
# Group tools by their MCP server name
|
|
87
|
-
tools_by_server = {}
|
|
88
|
-
connected.each { |name| tools_by_server[name] = [] }
|
|
89
|
-
|
|
90
|
-
mcp_tools.each do |tool|
|
|
91
|
-
server_name = tool.respond_to?(:mcp) ? tool.mcp : nil
|
|
92
|
-
if server_name && tools_by_server.key?(server_name)
|
|
93
|
-
tools_by_server[server_name] << tool
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
puts "Connected Servers:"
|
|
98
|
-
connected.each do |name|
|
|
99
|
-
tools = tools_by_server[name] || []
|
|
100
|
-
puts " #{name} (#{tools.size} tools)"
|
|
101
|
-
tools.each do |tool|
|
|
102
|
-
tool_name = tool.respond_to?(:name) ? tool.name : tool.class.name
|
|
103
|
-
puts " - #{tool_name}"
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
puts
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
if failed.any?
|
|
110
|
-
puts "Failed Servers:"
|
|
111
|
-
failed.each do |f|
|
|
112
|
-
name = f[:name] || f['name']
|
|
113
|
-
error = f[:error] || f['error']
|
|
114
|
-
puts " #{name}: #{error}"
|
|
115
|
-
end
|
|
116
|
-
puts
|
|
117
|
-
end
|
|
57
|
+
print_connected_servers(connected) if connected.any?
|
|
58
|
+
print_failed_servers(failed) if failed.any?
|
|
118
59
|
|
|
119
60
|
''
|
|
120
61
|
end
|
|
121
|
-
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
|
122
62
|
|
|
123
63
|
desc "Show active robot configuration"
|
|
124
64
|
def robots(args = [], context_manager = nil)
|
|
@@ -152,13 +92,72 @@ module AIA
|
|
|
152
92
|
|
|
153
93
|
private
|
|
154
94
|
|
|
95
|
+
def filter_tools(tools, filter)
|
|
96
|
+
return tools unless filter
|
|
97
|
+
|
|
98
|
+
tools.select do |tool|
|
|
99
|
+
"#{ToolIntrospection.tool_name(tool)} #{ToolIntrospection.tool_description(tool)}"
|
|
100
|
+
.downcase.include?(filter)
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def print_tools_report(tools_to_display, raw_filter)
|
|
105
|
+
puts
|
|
106
|
+
header = raw_filter ? "Available Tools (filtered by '#{raw_filter}')" : "Available Tools"
|
|
107
|
+
puts header
|
|
108
|
+
puts "=" * header.length
|
|
109
|
+
|
|
110
|
+
indent = 4
|
|
111
|
+
width = TTY::Screen.width - indent - 2
|
|
112
|
+
tools_to_display.each { |tool| print_tool_entry(tool, width, " " * indent) }
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def print_tool_entry(tool, width, spaces)
|
|
116
|
+
name = ToolIntrospection.tool_name(tool)
|
|
117
|
+
puts "\n#{name}"
|
|
118
|
+
puts "-" * name.size
|
|
119
|
+
puts WordWrapper::MinimumRaggedness.new(width, tool.description).wrap.split("\n").map { |s| spaces + s + "\n" }.join
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def print_connected_servers(connected)
|
|
123
|
+
grouped = tools_by_server(connected, all_mcp_tools)
|
|
124
|
+
|
|
125
|
+
puts "Connected Servers:"
|
|
126
|
+
connected.each do |name|
|
|
127
|
+
tools = grouped[name] || []
|
|
128
|
+
puts " #{name} (#{tools.size} tools)"
|
|
129
|
+
tools.each { |tool| puts " - #{ToolIntrospection.tool_name(tool)}" }
|
|
130
|
+
end
|
|
131
|
+
puts
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Group MCP tools under the connected server each one came from.
|
|
135
|
+
def tools_by_server(connected, mcp_tools)
|
|
136
|
+
grouped = connected.to_h { |name| [name, []] }
|
|
137
|
+
mcp_tools.each do |tool|
|
|
138
|
+
server_name = mcp_server_name_for(tool)
|
|
139
|
+
grouped[server_name] << tool if server_name && grouped.key?(server_name)
|
|
140
|
+
end
|
|
141
|
+
grouped
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def print_failed_servers(failed)
|
|
145
|
+
puts "Failed Servers:"
|
|
146
|
+
failed.each do |f|
|
|
147
|
+
puts " #{f[:name] || f['name']}: #{f[:error] || f['error']}"
|
|
148
|
+
end
|
|
149
|
+
puts
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# :reek:TooManyStatements -- mode classification plus sequential report of every crew member
|
|
155
153
|
def show_network(network)
|
|
154
|
+
cfg = AIA.config
|
|
156
155
|
robot_count = network.robot_count
|
|
157
|
-
mode = if
|
|
156
|
+
mode = if cfg.flags.consensus
|
|
158
157
|
"Consensus"
|
|
159
|
-
elsif
|
|
158
|
+
elsif cfg.pipeline.length > 1
|
|
160
159
|
"Pipeline"
|
|
161
|
-
elsif
|
|
160
|
+
elsif cfg.models.length > 1
|
|
162
161
|
"Parallel"
|
|
163
162
|
else
|
|
164
163
|
"Crew" # single-model session wrapped as a one-member crew
|
|
@@ -185,6 +184,7 @@ module AIA
|
|
|
185
184
|
show_robot_detail(bot)
|
|
186
185
|
end
|
|
187
186
|
|
|
187
|
+
# :reek:TooManyStatements -- one labeled line per robot attribute (model, wage, tool counts, role)
|
|
188
188
|
def show_robot_detail(bot)
|
|
189
189
|
puts " #{bot.name}"
|
|
190
190
|
|
|
@@ -237,26 +237,25 @@ module AIA
|
|
|
237
237
|
end
|
|
238
238
|
end
|
|
239
239
|
|
|
240
|
-
#
|
|
241
|
-
#
|
|
242
|
-
# or other gems that use RubyLLM::MCP.add_client directly.
|
|
240
|
+
# The MCP tools aia connected at startup (shared by every robot), or the
|
|
241
|
+
# robot's own when no connection manager ran.
|
|
243
242
|
def all_mcp_tools
|
|
243
|
+
manager = AIA.mcp_manager
|
|
244
|
+
return manager.connected_tools if manager&.connected?
|
|
245
|
+
|
|
244
246
|
robot = AIA.client
|
|
245
|
-
if robot
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
end
|
|
247
|
+
robot = robot.chief if robot && !robot.respond_to?(:mcp_tools) && robot.respond_to?(:chief)
|
|
248
|
+
robot.respond_to?(:mcp_tools) ? Array(robot.mcp_tools) : []
|
|
249
|
+
end
|
|
249
250
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
251
|
+
# Name of the MCP server that offers +tool+, or nil for a local tool.
|
|
252
|
+
def mcp_server_name_for(tool)
|
|
253
|
+
by_server = AIA.mcp_manager&.tools_by_server || {}
|
|
254
|
+
owner, = by_server.find { |_, tools| tools.any? { it.equal?(tool) } }
|
|
255
|
+
return owner if owner
|
|
255
256
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
return [] unless defined?(RubyLLM::MCP)
|
|
259
|
-
RubyLLM::MCP.clients.values.flat_map(&:tools)
|
|
257
|
+
robot = AIA.client
|
|
258
|
+
robot.respond_to?(:mcp_server_for) ? robot.mcp_server_for(tool)&.name : nil
|
|
260
259
|
end
|
|
261
260
|
end
|
|
262
261
|
end
|
|
@@ -10,29 +10,34 @@ module AIA
|
|
|
10
10
|
PUREMD_API_KEY = ENV.fetch('PUREMD_API_KEY', nil)
|
|
11
11
|
|
|
12
12
|
desc "Fetch and include content from a webpage"
|
|
13
|
+
# :reek:TooManyStatements -- guard, fetch via pure.md, then success/error reporting in one flow
|
|
13
14
|
def webpage(args, _context_manager = nil)
|
|
14
15
|
if PUREMD_API_KEY.nil?
|
|
15
|
-
'ERROR: PUREMD_API_KEY is required in order to include a webpage'
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
msg = 'ERROR: PUREMD_API_KEY is required in order to include a webpage'
|
|
17
|
+
AIA::LoggerManager.aia_logger.error(msg)
|
|
18
|
+
puts msg
|
|
19
|
+
return nil
|
|
20
|
+
end
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
end
|
|
22
|
+
url = args.shift.to_s.strip
|
|
23
|
+
puremd_url = "https://pure.md/#{url}"
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
else
|
|
27
|
-
"Error: Status was #{response.status}\n#{ap response}"
|
|
28
|
-
end
|
|
25
|
+
response = Faraday.get(puremd_url) do |req|
|
|
26
|
+
req.headers['x-puremd-api-token'] = PUREMD_API_KEY
|
|
29
27
|
end
|
|
28
|
+
|
|
29
|
+
return response.body if response.status == 200
|
|
30
|
+
|
|
31
|
+
msg = "Error: Fetching #{url} returned status #{response.status}"
|
|
32
|
+
AIA::LoggerManager.aia_logger.error(msg)
|
|
33
|
+
puts msg
|
|
34
|
+
nil
|
|
30
35
|
end
|
|
31
36
|
alias website webpage
|
|
32
37
|
alias web webpage
|
|
33
38
|
|
|
34
39
|
desc "List available AIA skills"
|
|
35
|
-
#
|
|
40
|
+
# :reek:TooManyStatements -- sequential listing: directory guard, term filtering, per-skill output
|
|
36
41
|
def skills(args = [], _context_manager = nil)
|
|
37
42
|
dir = aia_skills_dir
|
|
38
43
|
unless Dir.exist?(dir)
|
|
@@ -41,18 +46,7 @@ module AIA
|
|
|
41
46
|
end
|
|
42
47
|
|
|
43
48
|
positive_terms, negative_terms = parse_search_terms(Array(args))
|
|
44
|
-
|
|
45
|
-
skill_dirs = Dir.children(dir).select do |e|
|
|
46
|
-
File.directory?(File.join(dir, e)) &&
|
|
47
|
-
File.exist?(File.join(dir, e, 'SKILL.md'))
|
|
48
|
-
end
|
|
49
|
-
entries = skill_dirs.select do |e|
|
|
50
|
-
next true if positive_terms.empty? && negative_terms.empty?
|
|
51
|
-
text = read_front_matter_text(File.join(dir, e, 'SKILL.md'))
|
|
52
|
-
# text is a String; Array#intersect? would raise TypeError
|
|
53
|
-
positive_terms.all? { |t| text.include?(t) } &&
|
|
54
|
-
negative_terms.none? { |t| text.include?(t) }
|
|
55
|
-
end.sort
|
|
49
|
+
entries = matching_skill_ids(dir, positive_terms, negative_terms)
|
|
56
50
|
|
|
57
51
|
if entries.empty?
|
|
58
52
|
all_terms = positive_terms + negative_terms
|
|
@@ -61,55 +55,30 @@ module AIA
|
|
|
61
55
|
end
|
|
62
56
|
|
|
63
57
|
wrap_width = terminal_width - 2
|
|
64
|
-
|
|
65
|
-
entries.each do |skill_id|
|
|
66
|
-
fm = parse_skill_front_matter(File.join(dir, skill_id, 'SKILL.md'))
|
|
67
|
-
name = fm['name'] || ''
|
|
68
|
-
description = fm['description'] || '(no description)'
|
|
69
|
-
puts "#{skill_id}: #{name}"
|
|
70
|
-
puts word_wrap(description, width: wrap_width, indent: ' ')
|
|
71
|
-
puts
|
|
72
|
-
end
|
|
58
|
+
entries.each { |skill_id| print_skill_entry(dir, skill_id, wrap_width) }
|
|
73
59
|
|
|
74
60
|
nil
|
|
75
61
|
end
|
|
76
|
-
# rubocop:enable Metrics/AbcSize
|
|
77
62
|
|
|
78
63
|
desc "Include an AIA skill from the configured skills directory"
|
|
79
64
|
def skill(args = [], _context_manager = nil)
|
|
80
65
|
args = Array(args)
|
|
81
66
|
skill_name = args.first&.strip
|
|
82
67
|
if skill_name.nil? || skill_name.empty?
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
68
|
+
return report_skill_error("Error: /skill requires a skill name. Use /skills to list available skills.")
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
if path_based_id?(skill_name) && non_markdown_skill_file?(File.expand_path(skill_name))
|
|
72
|
+
return report_skill_error("Error: #{non_markdown_skill_message(skill_name)}.")
|
|
87
73
|
end
|
|
88
74
|
|
|
89
75
|
dir = aia_skills_dir
|
|
90
76
|
skill_dir = find_skill_dir(skill_name, dir)
|
|
91
77
|
unless skill_dir
|
|
92
|
-
|
|
93
|
-
AIA::LoggerManager.aia_logger.error(msg)
|
|
94
|
-
puts msg
|
|
95
|
-
return nil
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
return File.read(skill_dir) if File.file?(skill_dir)
|
|
99
|
-
|
|
100
|
-
skill_path = File.join(skill_dir, 'SKILL.md')
|
|
101
|
-
unless File.exist?(skill_path)
|
|
102
|
-
msg = if path_based_id?(skill_name)
|
|
103
|
-
"Error: No skill matching '#{skill_name}' found in #{dir}. Use /skills to list available skills."
|
|
104
|
-
else
|
|
105
|
-
"Error: Skill '#{File.basename(skill_dir)}' has no SKILL.md in #{dir}."
|
|
106
|
-
end
|
|
107
|
-
AIA::LoggerManager.aia_logger.error(msg)
|
|
108
|
-
puts msg
|
|
109
|
-
return nil
|
|
78
|
+
return report_skill_error("Error: No skill matching '#{skill_name}' found in #{dir}. Use /skills to list available skills.")
|
|
110
79
|
end
|
|
111
80
|
|
|
112
|
-
|
|
81
|
+
read_skill_text(skill_name, skill_dir, dir)
|
|
113
82
|
end
|
|
114
83
|
|
|
115
84
|
desc "Paste content from the system clipboard"
|
|
@@ -117,19 +86,70 @@ module AIA
|
|
|
117
86
|
content = Clipboard.paste
|
|
118
87
|
content.to_s
|
|
119
88
|
rescue StandardError => e
|
|
120
|
-
"Error: Unable to paste from clipboard - #{e.message}"
|
|
89
|
+
msg = "Error: Unable to paste from clipboard - #{e.message}"
|
|
90
|
+
AIA::LoggerManager.aia_logger.error(msg)
|
|
91
|
+
puts msg
|
|
92
|
+
nil
|
|
121
93
|
end
|
|
122
94
|
alias clipboard paste
|
|
123
95
|
|
|
124
96
|
private
|
|
125
97
|
|
|
98
|
+
# Skill directories under dir with a SKILL.md whose front matter passes
|
|
99
|
+
# the positive/negative term filters, sorted.
|
|
100
|
+
def matching_skill_ids(dir, positive_terms, negative_terms)
|
|
101
|
+
skill_dirs = Dir.children(dir).select do |e|
|
|
102
|
+
File.directory?(File.join(dir, e)) &&
|
|
103
|
+
File.exist?(File.join(dir, e, 'SKILL.md'))
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
skill_dirs.select do |e|
|
|
107
|
+
next true if positive_terms.empty? && negative_terms.empty?
|
|
108
|
+
text = read_front_matter_text(File.join(dir, e, 'SKILL.md'))
|
|
109
|
+
# text is a String; Array#intersect? would raise TypeError
|
|
110
|
+
positive_terms.all? { |t| text.include?(t) } &&
|
|
111
|
+
negative_terms.none? { |t| text.include?(t) }
|
|
112
|
+
end.sort
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def print_skill_entry(dir, skill_id, wrap_width)
|
|
116
|
+
fm = parse_skill_front_matter(File.join(dir, skill_id, 'SKILL.md'))
|
|
117
|
+
name = fm['name'] || ''
|
|
118
|
+
description = fm['description'] || '(no description)'
|
|
119
|
+
puts "#{skill_id}: #{name}"
|
|
120
|
+
puts word_wrap(description, width: wrap_width, indent: ' ')
|
|
121
|
+
puts
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# Log and print a /skill error message; returns nil so callers can
|
|
125
|
+
# `return report_skill_error(msg)` from any guard.
|
|
126
|
+
# The text of a found skill: the file itself, or the folder's SKILL.md.
|
|
127
|
+
def read_skill_text(skill_name, skill_dir, dir)
|
|
128
|
+
return File.read(skill_dir) if File.file?(skill_dir)
|
|
129
|
+
|
|
130
|
+
skill_path = File.join(skill_dir, 'SKILL.md')
|
|
131
|
+
return File.read(skill_path) if File.exist?(skill_path)
|
|
132
|
+
|
|
133
|
+
msg = if path_based_id?(skill_name)
|
|
134
|
+
"Error: No skill matching '#{skill_name}' found in #{dir}. Use /skills to list available skills."
|
|
135
|
+
else
|
|
136
|
+
"Error: Skill '#{File.basename(skill_dir)}' has no SKILL.md in #{dir}."
|
|
137
|
+
end
|
|
138
|
+
report_skill_error(msg)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def report_skill_error(msg)
|
|
142
|
+
AIA::LoggerManager.aia_logger.error(msg)
|
|
143
|
+
puts msg
|
|
144
|
+
nil
|
|
145
|
+
end
|
|
146
|
+
|
|
126
147
|
# Resolve the AIA skills directory from config, env vars, or defaults.
|
|
127
148
|
def aia_skills_dir
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
end
|
|
149
|
+
skills = AIA.respond_to?(:config) ? AIA.config&.skills : nil
|
|
150
|
+
return skills.dir if skills.respond_to?(:dir) && skills.dir
|
|
131
151
|
|
|
132
|
-
ENV.fetch('AIA_SKILLS__DIR'
|
|
152
|
+
ENV.fetch('AIA_SKILLS__DIR') { File.expand_path('~/.prompts/skills') }
|
|
133
153
|
end
|
|
134
154
|
|
|
135
155
|
def terminal_width
|
data/lib/aia/fact_asserter.rb
CHANGED
|
@@ -10,10 +10,10 @@ module AIA
|
|
|
10
10
|
class FactAsserter
|
|
11
11
|
# Extract the tool's name as a non-nil String.
|
|
12
12
|
#
|
|
13
|
-
# @param tool [Object]
|
|
14
|
-
# @return [String]
|
|
13
|
+
# @param tool [Object] a tool instance or RubyLLM::Tool class
|
|
14
|
+
# @return [String] the name the model calls it by (see ToolIntrospection.tool_name)
|
|
15
15
|
def tool_name(tool)
|
|
16
|
-
String(
|
|
16
|
+
String(ToolIntrospection.tool_name(tool)).strip
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
# Extract the tool's description as a non-nil String.
|
data/lib/aia/history_transfer.rb
CHANGED
|
@@ -4,24 +4,68 @@
|
|
|
4
4
|
#
|
|
5
5
|
# Stateless module for transferring conversation history between robots.
|
|
6
6
|
# Extracted from RobotFactory to isolate the history transfer concern.
|
|
7
|
+
#
|
|
8
|
+
# Both arguments may be a single RobotLab::Robot or a RobotLab::Network (the
|
|
9
|
+
# interactive session always runs a crew). History is read from the old
|
|
10
|
+
# runnable's chief — the robot the user has been talking to — and carried to
|
|
11
|
+
# every member of the new crew.
|
|
7
12
|
|
|
8
13
|
module AIA
|
|
9
14
|
module HistoryTransfer
|
|
15
|
+
MODES = %i[clean replay summarize].freeze
|
|
16
|
+
DEFAULT_MODE = :summarize
|
|
17
|
+
|
|
10
18
|
module_function
|
|
11
19
|
|
|
20
|
+
# The history mode configured for model switches (config.model_switch_history),
|
|
21
|
+
# falling back to DEFAULT_MODE when it is unset or not a known mode.
|
|
22
|
+
#
|
|
23
|
+
# @param config [AIA::Config, nil]
|
|
24
|
+
# @return [Symbol] one of MODES
|
|
25
|
+
def mode_for(config)
|
|
26
|
+
value = config.respond_to?(:model_switch_history) ? config.model_switch_history : nil
|
|
27
|
+
mode = value.to_s.strip.downcase.to_sym
|
|
28
|
+
MODES.include?(mode) ? mode : DEFAULT_MODE
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# The user/assistant turns of +runnable+'s chief, oldest first. System
|
|
32
|
+
# prompts and tool traffic are left out: they belong to the old robot.
|
|
33
|
+
#
|
|
34
|
+
# @param runnable [RobotLab::Robot, RobotLab::Network, nil]
|
|
35
|
+
# @return [Array<RubyLLM::Message>]
|
|
36
|
+
def conversation(runnable)
|
|
37
|
+
chief = chief_of(runnable)
|
|
38
|
+
return [] unless chief.respond_to?(:messages)
|
|
39
|
+
|
|
40
|
+
Array(chief.messages).select do |msg|
|
|
41
|
+
msg.respond_to?(:role) && %i[user assistant].include?(msg.role) && !msg.content.to_s.strip.empty?
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# The robot whose conversation the user sees: a network's chief, or the robot itself.
|
|
46
|
+
def chief_of(runnable)
|
|
47
|
+
runnable.respond_to?(:chief) ? runnable.chief : runnable
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# The robots that should receive the transferred history.
|
|
51
|
+
#
|
|
52
|
+
# @param runnable [RobotLab::Robot, RobotLab::Network]
|
|
53
|
+
# @return [Array<RobotLab::Robot>]
|
|
54
|
+
def recipients(runnable)
|
|
55
|
+
runnable.respond_to?(:crew) ? Array(runnable.crew) : [runnable]
|
|
56
|
+
end
|
|
57
|
+
|
|
12
58
|
# Replay conversation history from an old robot to a new one.
|
|
13
59
|
#
|
|
14
|
-
# Performance: O(N) API calls where N = number of user
|
|
15
|
-
# Each user message triggers a full LLM round-trip on the new
|
|
16
|
-
#
|
|
17
|
-
# For a cloud model (~2-5s/turn), expect 20-50s. MCP/tools are disabled
|
|
18
|
-
# during replay to avoid side effects.
|
|
60
|
+
# Performance: O(N) API calls per recipient, where N = number of user
|
|
61
|
+
# messages. Each user message triggers a full LLM round-trip on the new
|
|
62
|
+
# model. MCP/tools are disabled during replay to avoid side effects.
|
|
19
63
|
def replay_history(old_robot, new_robot)
|
|
20
|
-
|
|
64
|
+
user_turns = conversation(old_robot).select { it.role == :user }
|
|
65
|
+
return if user_turns.empty?
|
|
21
66
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
new_robot.run(msg.content, mcp: :none, tools: :none)
|
|
67
|
+
recipients(new_robot).each do |robot|
|
|
68
|
+
user_turns.each { robot.run(it.content.to_s, mcp: :none, tools: :none) }
|
|
25
69
|
end
|
|
26
70
|
rescue StandardError => e
|
|
27
71
|
$stderr.puts "Warning: History replay failed: #{e.message}"
|
|
@@ -29,25 +73,21 @@ module AIA
|
|
|
29
73
|
|
|
30
74
|
# Summarize conversation history and inject into new robot.
|
|
31
75
|
#
|
|
32
|
-
# Performance:
|
|
33
|
-
#
|
|
34
|
-
#
|
|
35
|
-
# Faster than :replay for conversations with >2 turns, but loses
|
|
36
|
-
# per-turn context fidelity. Total latency ~4-10s for cloud models.
|
|
76
|
+
# Performance: one summary call on the old model, plus one injection call
|
|
77
|
+
# per recipient, regardless of conversation length. Faster than :replay
|
|
78
|
+
# for conversations with >2 turns, but loses per-turn context fidelity.
|
|
37
79
|
def summarize_history(old_robot, new_robot)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
summary_lines = old_robot.messages.map do |msg|
|
|
41
|
-
"#{msg.role}: #{msg.content}" if msg.respond_to?(:role)
|
|
42
|
-
end.compact
|
|
80
|
+
turns = conversation(old_robot)
|
|
81
|
+
return if turns.empty?
|
|
43
82
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
summary = old_robot.run(summary_prompt, mcp: :none, tools: :none)
|
|
83
|
+
transcript = turns.map { "#{it.role}: #{it.content}" }.join("\n")
|
|
84
|
+
summary = chief_of(old_robot).run("Summarize this conversation concisely for context transfer:\n#{transcript}",
|
|
85
|
+
mcp: :none, tools: :none)
|
|
48
86
|
content = summary.respond_to?(:reply) ? summary.reply : summary.to_s
|
|
49
87
|
|
|
50
|
-
new_robot.
|
|
88
|
+
recipients(new_robot).each do |robot|
|
|
89
|
+
robot.run("Context from previous conversation: #{content}", mcp: :none, tools: :none)
|
|
90
|
+
end
|
|
51
91
|
rescue StandardError => e
|
|
52
92
|
$stderr.puts "Warning: History summarization failed: #{e.message}"
|
|
53
93
|
end
|