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
|
@@ -34,6 +34,12 @@ module AIA
|
|
|
34
34
|
MAX_LAYERS = 5
|
|
35
35
|
MAX_TASKS_PER_LAYER = 4
|
|
36
36
|
|
|
37
|
+
BUILD_BANNER = <<~BANNER
|
|
38
|
+
╔══════════════════════════════════════════════════════════╗
|
|
39
|
+
║ LAYERED ORCHESTRATION — 3-TIER BUILD ║
|
|
40
|
+
╚══════════════════════════════════════════════════════════╝
|
|
41
|
+
BANNER
|
|
42
|
+
|
|
37
43
|
# Tier 1 prompt: decompose requirements into layers
|
|
38
44
|
# Deliberately short and directive to minimise qwen3 think-block noise.
|
|
39
45
|
LAYER_DECOMPOSE_PROMPT = <<~PROMPT
|
|
@@ -124,19 +130,14 @@ module AIA
|
|
|
124
130
|
#
|
|
125
131
|
# @param context [HandlerContext] — reads context.prompt as requirements text
|
|
126
132
|
# @return [String, nil] final synthesis or nil on failure
|
|
127
|
-
#
|
|
133
|
+
# :reek:TooManyStatements -- single orchestration script (banner, tier 1-3 waves, synthesis, report); the narrative order is the value
|
|
134
|
+
# :reek:DuplicateMethodCall -- say("") prints deliberate blank separator lines between build phases; not a hoistable value
|
|
128
135
|
def handle(context)
|
|
129
136
|
requirements = context.prompt
|
|
130
137
|
primary = @robot.chief
|
|
131
138
|
|
|
132
139
|
FileUtils.mkdir_p(@build_dir)
|
|
133
|
-
|
|
134
|
-
say("╔══════════════════════════════════════════════════════════╗")
|
|
135
|
-
say("║ LAYERED ORCHESTRATION — 3-TIER BUILD ║")
|
|
136
|
-
say("╚══════════════════════════════════════════════════════════╝")
|
|
137
|
-
say("Requirements: #{requirements.lines.first.strip}")
|
|
138
|
-
say("Build output: #{@build_dir}")
|
|
139
|
-
say("")
|
|
140
|
+
print_build_banner(requirements)
|
|
140
141
|
|
|
141
142
|
# Tier 1: Tobor decomposes requirements into layers
|
|
142
143
|
layers = decompose_to_layers(primary, requirements)
|
|
@@ -173,23 +174,38 @@ module AIA
|
|
|
173
174
|
save_final_report(final_text)
|
|
174
175
|
say("Build complete: #{@build_dir}")
|
|
175
176
|
|
|
177
|
+
record_final_turn(requirements, final_text)
|
|
178
|
+
final_text
|
|
179
|
+
rescue StandardError => e
|
|
180
|
+
report_orchestration_error(e)
|
|
181
|
+
nil
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
private
|
|
185
|
+
|
|
186
|
+
def print_build_banner(requirements)
|
|
187
|
+
say("")
|
|
188
|
+
BUILD_BANNER.each_line { |line| say(line.chomp) }
|
|
189
|
+
say("Requirements: #{requirements.lines.first.strip}")
|
|
190
|
+
say("Build output: #{@build_dir}")
|
|
191
|
+
say("")
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def record_final_turn(requirements, final_text)
|
|
176
195
|
@tracker.record_turn(
|
|
177
196
|
model: AIA.config.models.first.name,
|
|
178
197
|
input: requirements,
|
|
179
198
|
result: final_text
|
|
180
199
|
)
|
|
181
|
-
|
|
182
|
-
final_text
|
|
183
|
-
rescue StandardError => e
|
|
184
|
-
say("✗ Orchestration error: #{e.class}: #{e.message}")
|
|
185
|
-
e.backtrace&.first(5)&.each { |line| say(" #{line}") }
|
|
186
|
-
nil
|
|
187
200
|
end
|
|
188
|
-
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
|
189
201
|
|
|
190
|
-
|
|
202
|
+
def report_orchestration_error(error)
|
|
203
|
+
say("✗ Orchestration error: #{error.class}: #{error.message}")
|
|
204
|
+
error.backtrace&.first(5)&.each { |line| say(" #{line}") }
|
|
205
|
+
end
|
|
191
206
|
|
|
192
207
|
# Tier 1: use a probe robot to decompose requirements into layer specs
|
|
208
|
+
# :reek:TooManyStatements -- probe run plus parse-failure diagnostics and rescue reporting
|
|
193
209
|
def decompose_to_layers(robot, requirements)
|
|
194
210
|
say("Tier 1 ▶ #{robot.name} decomposing requirements into layers...")
|
|
195
211
|
probe = build_probe(robot.name + "-layer-probe")
|
|
@@ -227,6 +243,7 @@ module AIA
|
|
|
227
243
|
#
|
|
228
244
|
# @param layers [Array<Hash>] layer specs from Tier 1
|
|
229
245
|
# @return [Hash{ String => Array<Hash> }] layer_name => task list ([] on failure)
|
|
246
|
+
# :reek:TooManyStatements -- per-layer async fan-out with per-layer error capture; the barrier plumbing is inherent
|
|
230
247
|
def run_leads_wave(layers)
|
|
231
248
|
results = {}
|
|
232
249
|
|
|
@@ -234,19 +251,21 @@ module AIA
|
|
|
234
251
|
barrier = Async::Barrier.new
|
|
235
252
|
layers.each do |layer|
|
|
236
253
|
barrier.async do
|
|
237
|
-
|
|
254
|
+
name = layer['name']
|
|
255
|
+
title = layer['title']
|
|
256
|
+
probe = build_probe("#{name}-lead")
|
|
238
257
|
prompt = TASK_DECOMPOSE_PROMPT % {
|
|
239
|
-
layer_title:
|
|
258
|
+
layer_title: title,
|
|
240
259
|
requirements: layer['requirements'].to_s,
|
|
241
260
|
max_tasks: MAX_TASKS_PER_LAYER
|
|
242
261
|
}
|
|
243
262
|
result = probe.run(prompt, mcp: :none, tools: :none)
|
|
244
263
|
tasks = parse_json_array(extract_content(result)).first(MAX_TASKS_PER_LAYER)
|
|
245
|
-
say(" ✓ #{
|
|
246
|
-
results[
|
|
264
|
+
say(" ✓ #{title} lead: #{tasks.size} task(s)")
|
|
265
|
+
results[name] = tasks
|
|
247
266
|
rescue => e
|
|
248
|
-
say(" ✗ #{
|
|
249
|
-
results[
|
|
267
|
+
say(" ✗ #{title} lead failed: #{e.message}")
|
|
268
|
+
results[name] = []
|
|
250
269
|
end
|
|
251
270
|
end
|
|
252
271
|
barrier.wait
|
|
@@ -261,6 +280,7 @@ module AIA
|
|
|
261
280
|
#
|
|
262
281
|
# @param layer_task_map [Hash{ String => Array<Hash> }] output of run_leads_wave
|
|
263
282
|
# @return [Hash{ String => Hash }] "layer_name|artifact_path" => result hash
|
|
283
|
+
# :reek:TooManyStatements -- per-task async fan-out with success/failure result recording; the barrier plumbing is inherent
|
|
264
284
|
def run_specialists_wave(layer_task_map)
|
|
265
285
|
jobs = layer_task_map.flat_map do |layer_name, tasks|
|
|
266
286
|
tasks.map { |task| { layer_name: layer_name, task: task } }
|
|
@@ -273,31 +293,32 @@ module AIA
|
|
|
273
293
|
barrier = Async::Barrier.new
|
|
274
294
|
jobs.each do |job|
|
|
275
295
|
barrier.async do
|
|
276
|
-
task
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
296
|
+
task = job[:task]
|
|
297
|
+
artifact = task['artifact']
|
|
298
|
+
title = task['title']
|
|
299
|
+
specialist = task['specialist']
|
|
300
|
+
key = "#{job[:layer_name]}|#{artifact}"
|
|
301
|
+
probe = build_probe("#{specialist}-specialist")
|
|
302
|
+
|
|
303
|
+
full_prompt = "Artifact to produce: #{artifact}\n\n#{task['prompt']}"
|
|
281
304
|
result = probe.run(full_prompt, mcp: :none, tools: :none)
|
|
282
305
|
output = extract_content(result)
|
|
283
306
|
|
|
284
|
-
save_artifact(
|
|
285
|
-
say(" ✓ #{
|
|
307
|
+
save_artifact(artifact, output)
|
|
308
|
+
say(" ✓ #{artifact}")
|
|
286
309
|
|
|
287
310
|
results[key] = {
|
|
288
|
-
task:
|
|
289
|
-
specialist:
|
|
290
|
-
artifact:
|
|
311
|
+
task: title,
|
|
312
|
+
specialist: specialist,
|
|
313
|
+
artifact: artifact,
|
|
291
314
|
output: output
|
|
292
315
|
}
|
|
293
316
|
rescue => e
|
|
294
|
-
|
|
295
|
-
key = "#{job[:layer_name]}|#{task['artifact']}"
|
|
296
|
-
say(" ✗ #{task['artifact']} failed: #{e.message}")
|
|
317
|
+
say(" ✗ #{artifact} failed: #{e.message}")
|
|
297
318
|
results[key] = {
|
|
298
|
-
task:
|
|
299
|
-
specialist:
|
|
300
|
-
artifact:
|
|
319
|
+
task: title,
|
|
320
|
+
specialist: specialist,
|
|
321
|
+
artifact: artifact,
|
|
301
322
|
output: "[FAILED: #{e.message}]"
|
|
302
323
|
}
|
|
303
324
|
end
|
|
@@ -317,9 +338,11 @@ module AIA
|
|
|
317
338
|
# @return [Array<Hash>]
|
|
318
339
|
def build_layer_results(layers, layer_task_map, specialist_results)
|
|
319
340
|
layers.map do |layer|
|
|
320
|
-
|
|
341
|
+
name = layer['name']
|
|
342
|
+
title = layer['title']
|
|
343
|
+
tasks_for_layer = layer_task_map[name] || []
|
|
321
344
|
task_results = tasks_for_layer.map do |task|
|
|
322
|
-
key = "#{
|
|
345
|
+
key = "#{name}|#{task['artifact']}"
|
|
323
346
|
specialist_results[key] || {
|
|
324
347
|
task: task['title'],
|
|
325
348
|
specialist: task['specialist'],
|
|
@@ -328,9 +351,9 @@ module AIA
|
|
|
328
351
|
}
|
|
329
352
|
end
|
|
330
353
|
|
|
331
|
-
summary = synthesize_layer_from_results(
|
|
332
|
-
say(" ✓ #{
|
|
333
|
-
{ layer:
|
|
354
|
+
summary = synthesize_layer_from_results(title, task_results)
|
|
355
|
+
say(" ✓ #{title} synthesis complete")
|
|
356
|
+
{ layer: title, tasks: task_results, summary: summary }
|
|
334
357
|
end
|
|
335
358
|
end
|
|
336
359
|
|
data/lib/aia/logger.rb
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
# Provides loggers for three systems:
|
|
7
7
|
# - aia: Used within the AIA codebase for application-level logging
|
|
8
8
|
# - llm: Passed to RubyLLM gem's configuration (RubyLLM.logger)
|
|
9
|
-
# - mcp:
|
|
9
|
+
# - mcp: MCP connection logging (MCPConnectionManager) and RobotLab.config.logger;
|
|
10
|
+
# ruby_llm's own MCP client logs through RubyLLM.logger (llm)
|
|
10
11
|
#
|
|
11
12
|
# Configuration is read from AIA.config.logger section:
|
|
12
13
|
# logger:
|
|
@@ -76,22 +77,23 @@ module AIA
|
|
|
76
77
|
def configure_llm_logger
|
|
77
78
|
return unless defined?(RubyLLM)
|
|
78
79
|
|
|
79
|
-
logger
|
|
80
|
+
logger = llm_logger
|
|
81
|
+
llm_config = RubyLLM.config
|
|
80
82
|
|
|
81
83
|
# Set our logger on the RubyLLM config object
|
|
82
|
-
if
|
|
83
|
-
|
|
84
|
+
if llm_config.respond_to?(:logger=)
|
|
85
|
+
llm_config.logger = logger
|
|
84
86
|
end
|
|
85
87
|
|
|
86
88
|
# Also set log_file and log_level in case the logger gets recreated
|
|
87
|
-
if
|
|
89
|
+
if llm_config.respond_to?(:log_file=)
|
|
88
90
|
file = effective_log_file(logger_config_for(:llm))
|
|
89
|
-
|
|
91
|
+
llm_config.log_file = resolve_log_file_io(file)
|
|
90
92
|
end
|
|
91
93
|
|
|
92
|
-
if
|
|
94
|
+
if llm_config.respond_to?(:log_level=)
|
|
93
95
|
level = effective_log_level(logger_config_for(:llm))
|
|
94
|
-
|
|
96
|
+
llm_config.log_level = LOG_LEVELS.fetch(level) { Lumberjack::Severity::WARN }
|
|
95
97
|
end
|
|
96
98
|
|
|
97
99
|
# Reset the memoized @logger on RubyLLM module so next call uses our config
|
|
@@ -99,38 +101,8 @@ module AIA
|
|
|
99
101
|
RubyLLM.instance_variable_set(:@logger, nil) if RubyLLM.instance_variable_defined?(:@logger)
|
|
100
102
|
end
|
|
101
103
|
|
|
102
|
-
# Configure RubyLLM::MCP's logger
|
|
103
|
-
# RubyLLM::MCP.config has attr_writer :logger and a memoized getter.
|
|
104
|
-
# We need to set both the config.logger and reset any memoization.
|
|
105
|
-
def configure_mcp_logger
|
|
106
|
-
return unless defined?(RubyLLM::MCP)
|
|
107
|
-
|
|
108
|
-
logger = mcp_logger
|
|
109
|
-
|
|
110
|
-
# First reset the memoized @logger so our settings take effect
|
|
111
|
-
# RubyLLM::MCP.config.logger does: @logger ||= Logger.new(...)
|
|
112
|
-
config = RubyLLM::MCP.config
|
|
113
|
-
config.instance_variable_set(:@logger, nil) if config.instance_variable_defined?(:@logger)
|
|
114
|
-
|
|
115
|
-
# Set our logger on the MCP config object
|
|
116
|
-
# RubyLLM::MCP.config has attr_writer :logger (which sets @logger directly)
|
|
117
|
-
if config.respond_to?(:logger=)
|
|
118
|
-
config.logger = logger
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
# Also set log_file and log_level in case the logger gets recreated
|
|
122
|
-
if config.respond_to?(:log_file=)
|
|
123
|
-
file = effective_log_file(logger_config_for(:mcp))
|
|
124
|
-
config.log_file = resolve_log_file_io(file)
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
return unless config.respond_to?(:log_level=)
|
|
128
|
-
level = effective_log_level(logger_config_for(:mcp))
|
|
129
|
-
config.log_level = LOG_LEVELS.fetch(level, Lumberjack::Severity::WARN)
|
|
130
|
-
end
|
|
131
|
-
|
|
132
104
|
# Convert log file specification to IO object or file path
|
|
133
|
-
# RubyLLM
|
|
105
|
+
# RubyLLM expects an IO object or file path for log_file config
|
|
134
106
|
def resolve_log_file_io(file)
|
|
135
107
|
case file.to_s.upcase
|
|
136
108
|
when 'STDOUT'
|
|
@@ -171,13 +143,12 @@ module AIA
|
|
|
171
143
|
|
|
172
144
|
config = logger_config_for(system)
|
|
173
145
|
level = effective_log_level(config, system)
|
|
174
|
-
numeric = LOG_LEVELS.fetch(level
|
|
146
|
+
numeric = LOG_LEVELS.fetch(level) { Lumberjack::Severity::WARN }
|
|
175
147
|
logger.level = numeric
|
|
176
148
|
end
|
|
177
149
|
|
|
178
|
-
# Keep RubyLLM
|
|
150
|
+
# Keep the RubyLLM config in sync so it doesn't override us
|
|
179
151
|
configure_llm_logger
|
|
180
|
-
configure_mcp_logger
|
|
181
152
|
end
|
|
182
153
|
|
|
183
154
|
# =======================================================================
|
|
@@ -193,7 +164,7 @@ module AIA
|
|
|
193
164
|
def test_mode!(level: :debug)
|
|
194
165
|
reset!
|
|
195
166
|
@test_mode = true
|
|
196
|
-
@test_level = LOG_LEVELS.fetch(level.to_s
|
|
167
|
+
@test_level = LOG_LEVELS.fetch(level.to_s) { Lumberjack::Severity::DEBUG }
|
|
197
168
|
|
|
198
169
|
# Pre-create loggers with test devices
|
|
199
170
|
@aia_logger = create_test_logger(:aia)
|
|
@@ -273,7 +244,7 @@ module AIA
|
|
|
273
244
|
device = create_device(file, flush: flush)
|
|
274
245
|
Lumberjack::Logger.new(
|
|
275
246
|
device,
|
|
276
|
-
level: LOG_LEVELS.fetch(level
|
|
247
|
+
level: LOG_LEVELS.fetch(level) { Lumberjack::Severity::WARN },
|
|
277
248
|
progname: system.to_s.upcase
|
|
278
249
|
)
|
|
279
250
|
end
|
|
@@ -307,23 +278,21 @@ module AIA
|
|
|
307
278
|
# @param file [String] The file config value
|
|
308
279
|
# @param flush [Boolean] If true, flush immediately (no buffering)
|
|
309
280
|
# @return [Lumberjack::Device] The device instance
|
|
281
|
+
# :reek:BooleanParameter -- flush: maps directly onto Lumberjack's autoflush; two constructors would obscure that single toggle
|
|
310
282
|
def create_device(file, flush: true)
|
|
311
|
-
# buffer_size: 0 means immediate flush (no buffering)
|
|
312
|
-
buffer_size = flush ? 0 : 8192
|
|
313
|
-
|
|
314
283
|
case file.to_s.upcase
|
|
315
284
|
when 'STDOUT'
|
|
316
|
-
Lumberjack::Device::Writer.new($stdout,
|
|
285
|
+
Lumberjack::Device::Writer.new($stdout, autoflush: flush)
|
|
317
286
|
when 'STDERR'
|
|
318
|
-
Lumberjack::Device::Writer.new($stderr,
|
|
287
|
+
Lumberjack::Device::Writer.new($stderr, autoflush: flush)
|
|
319
288
|
else
|
|
320
289
|
path = File.expand_path(file)
|
|
321
|
-
#
|
|
322
|
-
#
|
|
323
|
-
Lumberjack::Device::
|
|
290
|
+
# Daily date rolling via Logger::LogDevice, which also makes the
|
|
291
|
+
# file safe for multiple loggers to write to
|
|
292
|
+
Lumberjack::Device::LogFile.new(
|
|
324
293
|
path,
|
|
325
|
-
|
|
326
|
-
|
|
294
|
+
shift_age: 'daily',
|
|
295
|
+
autoflush: flush
|
|
327
296
|
)
|
|
328
297
|
end
|
|
329
298
|
end
|
|
@@ -333,15 +302,11 @@ module AIA
|
|
|
333
302
|
# @param system [Symbol] The system (:aia, :llm, :mcp)
|
|
334
303
|
# @return [ConfigSection, nil] The configuration section
|
|
335
304
|
def logger_config_for(system)
|
|
336
|
-
|
|
305
|
+
logger_cfg = AIA.config&.logger
|
|
306
|
+
return nil unless logger_cfg
|
|
307
|
+
return nil unless %i[aia llm mcp].include?(system)
|
|
337
308
|
|
|
338
|
-
|
|
339
|
-
when :aia then AIA.config.logger.aia
|
|
340
|
-
when :llm then AIA.config.logger.llm
|
|
341
|
-
when :mcp then AIA.config.logger.mcp
|
|
342
|
-
end
|
|
343
|
-
rescue NoMethodError
|
|
344
|
-
nil
|
|
309
|
+
logger_cfg.public_send(system) if logger_cfg.respond_to?(system)
|
|
345
310
|
end
|
|
346
311
|
end
|
|
347
312
|
end
|
|
@@ -3,32 +3,45 @@
|
|
|
3
3
|
# lib/aia/mcp_config_normalizer.rb
|
|
4
4
|
#
|
|
5
5
|
# Normalizes a single MCP server config from AIA flat format to the nested
|
|
6
|
-
# transport format expected by robot_lab. Server
|
|
7
|
-
# the responsibility of MCPDiscovery — this class
|
|
6
|
+
# transport format expected by robot_lab (RobotLab::MCP.build). Server
|
|
7
|
+
# selection/filtering is the responsibility of MCPDiscovery — this class
|
|
8
|
+
# only transforms shape.
|
|
8
9
|
|
|
9
10
|
module AIA
|
|
10
11
|
class MCPConfigNormalizer
|
|
12
|
+
# Flat keys that describe how to reach the server; folded into :transport.
|
|
13
|
+
TRANSPORT_KEYS = %i[type command args env url headers bearer_token oauth cwd directory].freeze
|
|
14
|
+
|
|
11
15
|
class << self
|
|
12
16
|
# Normalize a single MCP server config to robot_lab's nested transport format.
|
|
17
|
+
# Settings robot_lab understands (timeout, prefix, only, except,
|
|
18
|
+
# requires_approval, description, ...) are carried through unchanged.
|
|
19
|
+
#
|
|
20
|
+
# A RubyLLM::MCP subclass or instance, or the constant name of one,
|
|
21
|
+
# already describes its own transport and is returned unchanged
|
|
22
|
+
# (RobotLab::MCP.build resolves the name).
|
|
13
23
|
#
|
|
14
|
-
# @param server [Hash]
|
|
15
|
-
# @return [Hash]
|
|
24
|
+
# @param server [Hash, Class<RubyLLM::MCP>, RubyLLM::MCP, String]
|
|
25
|
+
# @return [Hash, Class<RubyLLM::MCP>, RubyLLM::MCP, String]
|
|
16
26
|
def normalize(server)
|
|
17
|
-
server
|
|
27
|
+
return server if mcp_object?(server) || AIA::Utility.mcp_class_name?(server)
|
|
28
|
+
|
|
29
|
+
server = server.to_h.transform_keys(&:to_sym)
|
|
18
30
|
|
|
19
31
|
# Already in robot_lab format — pass through
|
|
20
32
|
return server if server[:transport]
|
|
21
33
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
transport
|
|
25
|
-
|
|
26
|
-
transport
|
|
27
|
-
|
|
34
|
+
transport = server.slice(*TRANSPORT_KEYS).compact
|
|
35
|
+
transport[:type] ||= server[:url] ? 'streamable-http' : 'stdio'
|
|
36
|
+
transport[:args] = Array(transport[:args]) if transport.key?(:args)
|
|
37
|
+
|
|
38
|
+
server.except(*TRANSPORT_KEYS).merge(transport: transport)
|
|
39
|
+
end
|
|
28
40
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
41
|
+
# @param server [Object]
|
|
42
|
+
# @return [Boolean] true for a RubyLLM::MCP instance or subclass
|
|
43
|
+
def mcp_object?(server)
|
|
44
|
+
server.is_a?(RubyLLM::MCP) || (server.is_a?(Class) && server <= RubyLLM::MCP)
|
|
32
45
|
end
|
|
33
46
|
end
|
|
34
47
|
end
|