1mod agent;
22mod fs_util;
23mod gate;
24mod hybrid;
25mod isolate;
26mod resolution;
27mod run_md;
28mod scope;
29mod sections;
30mod settings;
31mod split;
32mod support;
33mod types;
34
35pub use resolution::resolve_node_capabilities;
36pub use types::{
37 ContextInjection, ContextInjectionMode, ContextInjectionReport, HybridRealization,
38 RenderFlavor, DEFAULT_CONTEXT_INJECTION, DEFAULT_RENDER_FLAVOR,
39};
40
41use crate::error::DispatchError;
42use crate::interactive::{
43 native_analysis_prompt_fragment, native_analysis_terminal_presentation_instructions,
44 native_answer_persistence_instructions, native_context_enrichment_prompt_fragment,
45 native_context_enrichment_terminal_presentation_instructions,
46 native_dashboard_save_instructions, prepare_interactive_output,
47 setup_bootstrap_authority_instructions, setup_recovery_instructions, NativeMcpDescriptor,
48 NativePurpose, NativeSessionScope,
49};
50use crate::ir::{validate_ir_version, RealizationKind, WarbleIr};
51use crate::models::{ModelConfig, ANTHROPIC_PROVIDER};
52use crate::provider::{compose_target, ProviderFragment, ToolMap};
53use crate::resolve::ResolutionReport;
54use crate::targets::{CapabilityOutcome, TargetId};
55use std::path::Path;
56
57use agent::build_agent_markdown;
58use fs_util::{mkdir_all, write_file, write_json};
59use hybrid::{
60 any_local_provider, build_hybrid_disclosure, build_hybrid_run_md, emit_hybrid_file_target,
61 emit_hybrid_file_target_mcp,
62};
63use isolate::{
64 build_isolated_child_markdown, build_isolating_parent_markdown, isolated_agent_name,
65 should_isolate,
66};
67use resolution::{print_resolution_summary, resolve_node_with_shared_binding};
68use run_md::{build_interactive_run_md, build_profile_run_md};
69use scope::{build_scope_prompt, merge_scope_settings, scope_denies_destructive_bash};
70use settings::{build_settings, wren_config};
71use split::{
72 build_driver_markdown, build_split_settings, build_subagent_markdown,
73 should_split_per_step_tier, subagent_name,
74};
75use support::{outcome_supported, realization_supported, trigger_supported, unsupported};
76
77fn is_native_dashboard_component(node: &crate::ir::ComponentNode) -> bool {
78 node.required_capabilities
79 .iter()
80 .any(|capability| capability == "genbi_build")
81 && node
82 .required_capabilities
83 .iter()
84 .any(|capability| capability == "artifact_write")
85}
86
87fn is_native_persisted_answer_component(node: &crate::ir::ComponentNode) -> bool {
90 let blocks = &node.effect.render_blocks;
91 let table = blocks
92 .iter()
93 .filter(|block| block.block_type == "table")
94 .count();
95 let definition = blocks
96 .iter()
97 .filter(|block| block.block_type == "definition")
98 .count();
99 table == 1
100 && definition <= 1
101 && blocks.len() == table + definition
102 && blocks
103 .iter()
104 .find(|block| block.block_type == "table")
105 .is_some_and(|block| {
106 block
107 .fields
108 .get("columns")
109 .is_some_and(|field| field == "string[]")
110 && block
111 .fields
112 .get("rows")
113 .is_some_and(|field| field == "row[]")
114 })
115 && blocks
116 .iter()
117 .filter(|block| block.block_type == "definition")
118 .all(|block| {
119 block
120 .fields
121 .get("sql")
122 .is_some_and(|field| field == "string")
123 && block
124 .fields
125 .get("source_tables")
126 .is_some_and(|field| field == "string[]")
127 && block
128 .fields
129 .get("filters")
130 .is_some_and(|field| field == "string[]")
131 })
132}
133
134fn native_setup_settings(
135 mut settings: serde_json::Value,
136 purpose: Option<NativePurpose>,
137 native_scope: Option<&NativeSessionScope>,
138) -> Result<serde_json::Value, DispatchError> {
139 if purpose != Some(NativePurpose::Setup) {
140 return Ok(settings);
141 }
142 let scope = native_scope.ok_or_else(|| {
143 DispatchError("Setup permissions require a server-derived native scope".to_string())
144 })?;
145 let scoped_permissions = scope.claude_setup_write_permissions()?;
146 let allow = settings
147 .pointer_mut("/permissions/allow")
148 .and_then(serde_json::Value::as_array_mut)
149 .ok_or_else(|| DispatchError("native Setup permissions are incompatible".to_string()))?;
150 allow.retain(|entry| !matches!(entry.as_str(), Some("Edit" | "Write")));
151 for permission in scoped_permissions {
152 allow.push(serde_json::Value::String(permission));
153 }
154 let note = "Setup write authority is server-sealed: only Edit/Write paths below the host-provided WARBLE_SETUP_BOOTSTRAP_ROOT are allowed; the native cwd is private and read-only.";
155 match settings.get_mut("$comment") {
156 Some(comment) => {
157 let existing = comment.as_str().ok_or_else(|| {
158 DispatchError("native Setup permissions are incompatible".to_string())
159 })?;
160 *comment = serde_json::Value::String(format!("{existing} {note}"));
161 }
162 None => {
163 settings["$comment"] = serde_json::Value::String(note.to_string());
164 }
165 }
166 Ok(settings)
167}
168
169pub fn emit_claude_code(
170 ir: &WarbleIr,
171 out_dir: &Path,
172 target_id: &str,
173 render_flavor: RenderFlavor,
174) -> Result<(), DispatchError> {
175 emit_claude_code_with_models(
176 ir,
177 out_dir,
178 target_id,
179 render_flavor,
180 &ModelConfig::default(),
181 )
182}
183
184fn require_per_step_provider_support(
189 ir: &WarbleIr,
190 target_id: &str,
191 models: &ModelConfig,
192) -> Result<(), DispatchError> {
193 let supported = TargetId::parse(target_id)
194 .map(|t| t.profile())
195 .and_then(|p| p.get("llm:per_step_provider").map(|e| e.outcome))
196 .is_some_and(|outcome| outcome != CapabilityOutcome::Fail);
197 if supported {
198 return Ok(());
199 }
200 for node in &ir.components {
201 for call in &node.llm_calls {
202 let binding = models.binding(&call.tier)?;
203 if binding.provider != ANTHROPIC_PROVIDER {
204 return Err(DispatchError(format!(
205 "llm:per_step_provider: fail on {target_id} — the binding routes step '{}.{}' \
206(tier '{}') to provider '{}', but this target is whole-session single-provider and does not support \
207per-step provider routing (hybrid). Use an all-cloud binding for this target, or dispatch to a target \
208that realizes llm:per_step_provider.",
209 node.verb,
210 call.name,
211 call.tier,
212 binding.provider.as_str()
213 )));
214 }
215 }
216 }
217 Ok(())
218}
219
220pub fn emit_claude_code_with_models(
226 ir: &WarbleIr,
227 out_dir: &Path,
228 target_id: &str,
229 render_flavor: RenderFlavor,
230 models: &ModelConfig,
231) -> Result<(), DispatchError> {
232 emit_claude_code_with_realization(
233 ir,
234 out_dir,
235 target_id,
236 render_flavor,
237 models,
238 HybridRealization::default(),
239 )
240}
241
242pub fn emit_claude_code_with_realization(
245 ir: &WarbleIr,
246 out_dir: &Path,
247 target_id: &str,
248 render_flavor: RenderFlavor,
249 models: &ModelConfig,
250 hybrid: HybridRealization,
251) -> Result<(), DispatchError> {
252 let context = ContextInjection::from_ir(ir, DEFAULT_CONTEXT_INJECTION, None);
253 emit_claude_code_with_context(
254 ir,
255 out_dir,
256 target_id,
257 render_flavor,
258 models,
259 hybrid,
260 &context,
261 )
262}
263
264#[allow(clippy::too_many_arguments)]
267pub fn emit_claude_code_with_context(
268 ir: &WarbleIr,
269 out_dir: &Path,
270 target_id: &str,
271 render_flavor: RenderFlavor,
272 models: &ModelConfig,
273 hybrid: HybridRealization,
274 context: &ContextInjection,
275) -> Result<(), DispatchError> {
276 emit_claude_code_with_providers(
277 ir,
278 out_dir,
279 target_id,
280 render_flavor,
281 models,
282 hybrid,
283 context,
284 &[],
285 )
286}
287
288#[allow(clippy::too_many_arguments)]
292pub fn emit_claude_code_with_providers(
293 ir: &WarbleIr,
294 out_dir: &Path,
295 target_id: &str,
296 render_flavor: RenderFlavor,
297 models: &ModelConfig,
298 hybrid: HybridRealization,
299 context: &ContextInjection,
300 providers: &[ProviderFragment],
301) -> Result<(), DispatchError> {
302 emit_claude_code_with_native_purpose(
303 ir,
304 out_dir,
305 target_id,
306 render_flavor,
307 models,
308 hybrid,
309 context,
310 providers,
311 None,
312 None,
313 None,
314 )
315}
316
317#[allow(clippy::too_many_arguments)]
320pub fn emit_claude_code_with_native_purpose(
321 ir: &WarbleIr,
322 out_dir: &Path,
323 target_id: &str,
324 render_flavor: RenderFlavor,
325 models: &ModelConfig,
326 hybrid: HybridRealization,
327 context: &ContextInjection,
328 providers: &[ProviderFragment],
329 purpose: Option<NativePurpose>,
330 native_scope: Option<NativeSessionScope>,
331 native_mcp: Option<NativeMcpDescriptor>,
332) -> Result<(), DispatchError> {
333 validate_ir_version(ir)?;
334 if let Some(purpose) = purpose {
335 if target_id != "claude-code:interactive" {
336 return Err(DispatchError(
337 "--purpose is supported only by native interactive targets".to_string(),
338 ));
339 }
340 purpose.validate_profile(ir)?;
341 }
342 if native_mcp.is_some() && purpose.is_none() {
343 return Err(DispatchError(
344 "--native-mcp requires a native Sessions --purpose".to_string(),
345 ));
346 }
347 let include_setup_recovery_instructions =
348 purpose == Some(NativePurpose::Setup) && native_mcp.is_some();
349 if target_id == "codex:interactive" {
350 return Err(DispatchError("codex:interactive must use the native Codex materializer, never the Claude file emitter".to_string()));
351 }
352 let filtered_ir;
356 let ir = if target_id == "claude-code:interactive" {
357 filtered_ir = WarbleIr {
358 components: ir
359 .components
360 .iter()
361 .filter(|node| {
362 !node
363 .required_capabilities
364 .iter()
365 .any(|capability| capability == "enrichment_apply:deterministic")
366 })
367 .cloned()
368 .collect(),
369 ..ir.clone()
370 };
371 if filtered_ir.components.is_empty() {
372 return Err(DispatchError("apply_enrichment cannot be dispatched on claude-code:interactive: native materialization has no enforceable human-approval apply channel (wall-hit)".to_string()));
373 }
374 &filtered_ir
375 } else {
376 ir
377 };
378 models.validate(ir)?;
380 if ir
384 .components
385 .iter()
386 .any(|n| should_split_per_step_tier(n) || should_isolate(n))
387 {
388 models.orchestrator()?;
389 }
390 require_per_step_provider_support(ir, target_id, models)?;
396
397 for node in &ir.components {
399 if !realization_supported(node.realization_kind) {
400 return Err(unsupported(
401 "realization_kind",
402 node.realization_kind.as_str(),
403 ));
404 }
405 if !trigger_supported(node.trigger.kind) {
406 return Err(unsupported("trigger.kind", node.trigger.kind.as_str()));
407 }
408 if !outcome_supported(node.effect.outcome.kind) {
409 return Err(unsupported(
410 "outcome.kind",
411 node.effect.outcome.kind.as_str(),
412 ));
413 }
414 }
415
416 let target = TargetId::parse(target_id).ok_or_else(|| {
421 DispatchError(format!(
422 "target '{target_id}' has no capability profile (known targets: {})",
423 crate::targets::known_target_names().join(", ")
424 ))
425 })?;
426 let composed = compose_target(target.profile(), ToolMap::new(), providers, target)?;
427 let tool_map = &composed.tool_map;
428
429 let mut reports: Vec<(String, ResolutionReport)> = Vec::with_capacity(ir.components.len());
431 for node in &ir.components {
432 if node.realization_kind == RealizationKind::GatedTool && should_split_per_step_tier(node) {
449 return Err(DispatchError(format!(
450 "llm:per_step_tier: gated-tool component '{}' has divergent step tiers, but per-step splitting would grant every subagent the mutation guardrail's write/edit authority alongside the approval-gated driver, duplicating write access outside the two-phase approval lifecycle (dry-run diff -> blast-radius -> human approval -> apply) — refusing to dispatch rather than silently collapsing the tiers or unsafely splitting write authority. Realize this component as `tool` (no approval gate) or `skill` to enable per-step-tier splitting, or author it with a single tier to keep it a `gated-tool`.",
451 node.verb
452 )));
453 }
454 reports.push((
455 node.id.clone(),
456 resolve_node_with_shared_binding(
457 node,
458 &ir.context_binding,
459 target_id,
460 &composed.profile,
461 )?,
462 ));
463 }
464 let report_for = |id: &str| -> &ResolutionReport {
465 &reports
466 .iter()
467 .find(|(nid, _)| nid == id)
468 .expect("report exists")
469 .1
470 };
471
472 if any_local_provider(ir, models)? {
476 if native_mcp.is_some() {
477 return Err(DispatchError(
478 "native MCP discovery requires an all-cloud native interactive materialization; hybrid MCP configuration is a separate producer contract"
479 .to_string(),
480 ));
481 }
482 let scope_components = ir
483 .components
484 .iter()
485 .map(|node| (node, report_for(&node.id)))
486 .collect::<Vec<_>>();
487 let disclosure = build_hybrid_disclosure(ir, models, hybrid)?;
488 let scope_prompt = format!(
489 "{}{}",
490 build_scope_prompt(ir, &scope_components, render_flavor, true),
491 disclosure
492 );
493 let run = build_hybrid_run_md(ir, target_id, &disclosure);
494 match hybrid {
495 HybridRealization::BashScript => {
496 emit_hybrid_file_target(ir, out_dir, target_id, models, context)?
497 }
498 HybridRealization::McpServer => {
499 emit_hybrid_file_target_mcp(ir, out_dir, target_id, models, context)?
500 }
501 }
502 write_file(&out_dir.join(".claude/CLAUDE.md"), &scope_prompt)?;
503 write_file(&out_dir.join("RUN.md"), &run)?;
504 return Ok(());
505 }
506
507 let interactive = if target_id == "claude-code:interactive" {
510 let signature = ir
511 .components
512 .iter()
513 .map(|node| node.id.as_str())
514 .collect::<Vec<_>>()
515 .join(",");
516 let mut paths = vec![
517 std::path::PathBuf::from("RUN.md"),
518 std::path::PathBuf::from("context-report.json"),
519 std::path::PathBuf::from("capability-report.json"),
520 std::path::PathBuf::from(".claude/CLAUDE.md"),
521 std::path::PathBuf::from(".claude/settings.json"),
522 std::path::PathBuf::from(".wren/config.json"),
523 ];
524 if native_mcp.is_some() {
525 paths.push(std::path::PathBuf::from(".mcp.json"));
526 }
527 for node in &ir.components {
528 paths.push(std::path::PathBuf::from(format!(
529 ".claude/agents/{}.md",
530 node.verb
531 )));
532 if should_split_per_step_tier(node) {
533 for call in &node.llm_calls {
534 paths.push(std::path::PathBuf::from(format!(
535 ".claude/agents/{}.md",
536 subagent_name(&node.verb, call)
537 )));
538 }
539 }
540 }
541 Some(prepare_interactive_output(
542 out_dir,
543 target_id,
544 "claude",
545 &signature,
546 &paths,
547 purpose,
548 native_scope.clone(),
549 native_mcp.clone(),
550 )?)
551 } else {
552 None
553 };
554 let out_dir = interactive
555 .as_ref()
556 .map_or(out_dir, |output| output.root.as_path());
557
558 mkdir_all(out_dir)?;
561 write_json(
562 &out_dir.join("context-report.json"),
563 &serde_json::to_value(context.report()).expect("context report serializes"),
564 )?;
565 let include_session_dashboard_save_tool = purpose == Some(NativePurpose::Analysis)
569 && native_mcp.is_some()
570 && ir.components.iter().any(is_native_dashboard_component);
571 let include_session_persist_answer_tool = purpose == Some(NativePurpose::Analysis)
572 && native_mcp.is_some()
573 && ir
574 .components
575 .iter()
576 .any(is_native_persisted_answer_component);
577
578 let claude_dir = out_dir.join(".claude");
579 let agents_dir = claude_dir.join("agents");
580 let wren_dir = out_dir.join(".wren");
581 mkdir_all(&agents_dir)?;
582 mkdir_all(&wren_dir)?;
583 let mut component_settings: Vec<(String, serde_json::Value)> =
587 Vec::with_capacity(ir.components.len());
588
589 for node in &ir.components {
590 let include_dashboard_save_tool = purpose == Some(NativePurpose::Analysis)
591 && native_mcp.is_some()
592 && (is_native_dashboard_component(node) || is_native_persisted_answer_component(node));
593 let include_persist_answer_tool = purpose == Some(NativePurpose::Analysis)
594 && native_mcp.is_some()
595 && is_native_persisted_answer_component(node);
596 let include_native_terminal_presentation = matches!(
597 purpose,
598 Some(NativePurpose::Analysis | NativePurpose::ContextEnrichment)
599 );
600 let mut rendered_node;
605 let node = if include_native_terminal_presentation {
606 rendered_node = node.clone();
607 rendered_node.prompt_fragment = match purpose {
608 Some(NativePurpose::Analysis) => {
609 native_analysis_prompt_fragment(&node.prompt_fragment)
610 }
611 Some(NativePurpose::ContextEnrichment) => {
612 native_context_enrichment_prompt_fragment(&node.prompt_fragment)
613 }
614 _ => unreachable!("native terminal presentation requires a native purpose"),
615 };
616 &rendered_node
617 } else {
618 node
619 };
620 let report = report_for(&node.id);
621
622 if should_isolate(node) {
628 write_file(
629 &agents_dir.join(format!("{}.md", node.verb)),
630 &build_isolating_parent_markdown(node, report, render_flavor, models)?,
631 )?;
632 write_file(
633 &agents_dir.join(format!("{}.md", isolated_agent_name(&node.verb))),
634 &build_isolated_child_markdown(
635 node,
636 report,
637 render_flavor,
638 models,
639 context,
640 tool_map,
641 include_setup_recovery_instructions,
642 include_dashboard_save_tool,
643 )?,
644 )?;
645 component_settings.push((
648 node.verb.clone(),
649 build_split_settings(
650 node,
651 report,
652 render_flavor,
653 tool_map,
654 include_session_dashboard_save_tool,
655 include_session_persist_answer_tool,
656 ),
657 ));
658 } else if should_split_per_step_tier(node) {
659 let mut driver = build_driver_markdown(
660 node,
661 report,
662 render_flavor,
663 models,
664 context,
665 include_dashboard_save_tool,
666 include_persist_answer_tool,
667 include_native_terminal_presentation,
668 );
669 if include_persist_answer_tool {
670 driver.push('\n');
671 driver.push_str(native_answer_persistence_instructions());
672 }
673 if include_dashboard_save_tool {
674 driver.push('\n');
675 driver.push_str(native_dashboard_save_instructions());
676 }
677 if include_native_terminal_presentation {
678 driver.push('\n');
679 driver.push_str(match purpose {
680 Some(NativePurpose::Analysis) => {
681 native_analysis_terminal_presentation_instructions()
682 }
683 Some(NativePurpose::ContextEnrichment) => {
684 native_context_enrichment_terminal_presentation_instructions()
685 }
686 _ => unreachable!("native terminal presentation requires a native purpose"),
687 });
688 }
689 if purpose == Some(NativePurpose::Setup) {
690 driver.push('\n');
691 driver.push_str(&setup_bootstrap_authority_instructions());
692 }
693 write_file(&agents_dir.join(format!("{}.md", node.verb)), &driver)?;
694 for call in &node.llm_calls {
695 let mut subagent = build_subagent_markdown(node, call, models, context, tool_map);
696 if purpose == Some(NativePurpose::Setup) {
697 subagent.push('\n');
698 subagent.push_str(&setup_bootstrap_authority_instructions());
699 }
700 write_file(
701 &agents_dir.join(format!("{}.md", subagent_name(&node.verb, call))),
702 &subagent,
703 )?;
704 }
705 component_settings.push((
706 node.verb.clone(),
707 build_split_settings(
708 node,
709 report,
710 render_flavor,
711 tool_map,
712 include_session_dashboard_save_tool,
713 include_session_persist_answer_tool,
714 ),
715 ));
716 } else {
717 let mut agent_markdown = build_agent_markdown(
718 node,
719 report,
720 render_flavor,
721 models,
722 context,
723 tool_map,
724 include_setup_recovery_instructions,
725 include_dashboard_save_tool,
726 )?;
727 if include_dashboard_save_tool {
728 agent_markdown.push('\n');
729 agent_markdown.push_str(native_dashboard_save_instructions());
730 }
731 if include_native_terminal_presentation {
732 agent_markdown.push('\n');
733 agent_markdown.push_str(match purpose {
734 Some(NativePurpose::Analysis) => {
735 native_analysis_terminal_presentation_instructions()
736 }
737 Some(NativePurpose::ContextEnrichment) => {
738 native_context_enrichment_terminal_presentation_instructions()
739 }
740 _ => unreachable!("native terminal presentation requires a native purpose"),
741 });
742 }
743 if include_setup_recovery_instructions {
744 agent_markdown.push('\n');
745 agent_markdown.push_str(setup_recovery_instructions());
746 }
747 if purpose == Some(NativePurpose::Setup) {
748 agent_markdown.push('\n');
749 agent_markdown.push_str(&setup_bootstrap_authority_instructions());
750 }
751 write_file(
752 &agents_dir.join(format!("{}.md", node.verb)),
753 &agent_markdown,
754 )?;
755 component_settings.push((
756 node.verb.clone(),
757 build_settings(
758 node,
759 report,
760 render_flavor,
761 tool_map,
762 include_setup_recovery_instructions,
763 include_session_dashboard_save_tool,
764 include_session_persist_answer_tool,
765 ),
766 ));
767 }
768 }
769
770 let scope_components = ir
775 .components
776 .iter()
777 .map(|node| (node, report_for(&node.id)))
778 .collect::<Vec<_>>();
779 write_json(
780 &claude_dir.join("settings.json"),
781 &native_setup_settings(
782 merge_scope_settings(&component_settings),
783 purpose,
784 native_scope.as_ref(),
785 )?,
786 )?;
787 write_json(&wren_dir.join("config.json"), &wren_config())?;
788 let scope_prompt = build_scope_prompt(
789 ir,
790 &scope_components,
791 render_flavor,
792 scope_denies_destructive_bash(&component_settings),
793 );
794 write_file(
795 &claude_dir.join("CLAUDE.md"),
796 &match interactive.as_ref() {
797 Some(output) => format!("{}\n{scope_prompt}", output.marker()),
798 None => scope_prompt,
799 },
800 )?;
801
802 let run = match interactive.as_ref() {
806 Some(output) => format!(
807 "{}\n{}",
808 output.marker(),
809 build_interactive_run_md(ir, purpose)
810 ),
811 None => build_profile_run_md(&ir.profile, &scope_components, render_flavor, models)?,
812 };
813 write_file(&out_dir.join("RUN.md"), &run)?;
814
815 if let (Some(_), Some(descriptor)) = (&interactive, native_mcp.as_ref()) {
816 write_file(
817 &out_dir.join(".mcp.json"),
818 &descriptor.claude_discovery_config()?,
819 )?;
820 }
823
824 let capability_report = serde_json::json!({
825 "target": target_id,
826 "components": ir.components.iter().map(|node| {
827 let mut entry = serde_json::json!({
828 "id": node.id,
829 "capabilities": report_for(&node.id),
830 });
831 let granted: serde_json::Map<String, serde_json::Value> = node
835 .required_capabilities
836 .iter()
837 .filter_map(|c| tool_map.get(c.as_str()).map(|b| (c, b)))
838 .map(|(capability, binding)| {
839 (
840 capability.clone(),
841 serde_json::json!({ "names": binding.names, "source": binding.source }),
842 )
843 })
844 .collect();
845 if !granted.is_empty() {
846 entry["tool_bindings"] = serde_json::Value::Object(granted);
847 }
848 if should_isolate(node) {
852 let collapsed = models.collapsed_model(&node.llm_calls).ok();
853 entry["isolation"] = serde_json::json!({
854 "realized_via": "single-child-subagent",
855 "child_agent": isolated_agent_name(&node.verb),
856 "per_step_tier": if should_split_per_step_tier(node) {
857 serde_json::json!({
858 "outcome": "degrade",
859 "reason": "the whole component runs in one child, so its steps share one model",
860 "collapsed_to": collapsed,
861 })
862 } else {
863 serde_json::json!({ "outcome": "not-requested" })
864 },
865 });
866 }
867 entry
868 }).collect::<Vec<_>>(),
869 });
870 write_json(&out_dir.join("capability-report.json"), &capability_report)?;
871
872 for node in &ir.components {
873 print_resolution_summary(
874 &format!("{target_id} (component '{}')", node.id),
875 report_for(&node.id),
876 );
877 }
878
879 if let Some(output) = interactive {
880 output.write_ownership()?;
881 output.write_launch_spec()?;
882 }
883 Ok(())
884}