Handle one submitted line for either headless or TUI rendering.
(
bundle: RuntimeBundle,
line: str,
*,
print_system: SystemPrinter,
render_event: StreamRenderer,
clear_output: ClearHandler,
)
| 526 | |
| 527 | |
| 528 | async def handle_line( |
| 529 | bundle: RuntimeBundle, |
| 530 | line: str, |
| 531 | *, |
| 532 | print_system: SystemPrinter, |
| 533 | render_event: StreamRenderer, |
| 534 | clear_output: ClearHandler, |
| 535 | ) -> bool: |
| 536 | """Handle one submitted line for either headless or TUI rendering.""" |
| 537 | if not bundle.external_api_client: |
| 538 | bundle.hook_executor.update_registry( |
| 539 | load_hook_registry(bundle.current_settings(), bundle.current_plugins()) |
| 540 | ) |
| 541 | |
| 542 | command_context = CommandContext( |
| 543 | engine=bundle.engine, |
| 544 | hooks_summary=bundle.hook_summary(), |
| 545 | mcp_summary=bundle.mcp_summary(), |
| 546 | plugin_summary=bundle.plugin_summary(), |
| 547 | cwd=bundle.cwd, |
| 548 | tool_registry=bundle.tool_registry, |
| 549 | app_state=bundle.app_state, |
| 550 | session_backend=bundle.session_backend, |
| 551 | session_id=bundle.session_id, |
| 552 | extra_skill_dirs=bundle.extra_skill_dirs, |
| 553 | extra_plugin_roots=bundle.extra_plugin_roots, |
| 554 | memory_backend=bundle.memory_backend, |
| 555 | include_project_memory=bundle.include_project_memory, |
| 556 | ) |
| 557 | parsed = bundle.commands.lookup(line) or lookup_skill_slash_command(line, command_context) |
| 558 | if parsed is not None: |
| 559 | command, args = parsed |
| 560 | result = await command.handler( |
| 561 | args, |
| 562 | command_context, |
| 563 | ) |
| 564 | if result.refresh_runtime: |
| 565 | refresh_runtime_client(bundle) |
| 566 | await _render_command_result(result, print_system, clear_output, render_event) |
| 567 | if result.submit_prompt is not None: |
| 568 | original_model = bundle.engine.model |
| 569 | if result.submit_model: |
| 570 | bundle.engine.set_model(result.submit_model) |
| 571 | settings = bundle.current_settings() |
| 572 | submit_prompt = result.submit_prompt |
| 573 | system_prompt = build_runtime_system_prompt( |
| 574 | settings, |
| 575 | cwd=bundle.cwd, |
| 576 | latest_user_prompt=submit_prompt, |
| 577 | extra_skill_dirs=bundle.extra_skill_dirs, |
| 578 | extra_plugin_roots=bundle.extra_plugin_roots, |
| 579 | include_project_memory=bundle.include_project_memory, |
| 580 | ) |
| 581 | bundle.engine.set_system_prompt(system_prompt) |
| 582 | try: |
| 583 | async for event in bundle.engine.submit_message(submit_prompt): |
| 584 | await render_event(event) |
| 585 | except MaxTurnsExceeded as exc: |
no test coverage detected