Skip to content

Commit aa79adf

Browse files
authored
refactor(agent_setup): consolidate suppress_stderr and tui_mode into RuntimeContext (#3026)
Replace the two decomposed bool parameters `suppress_stderr` and `tui_mode` in `build_tool_setup` with a single `RuntimeContext` argument. This removes a decomposition site at the call sites in runner.rs and lets the function access context fields directly via `runtime_ctx.suppress_stderr()` and `runtime_ctx.tui_mode`. Closes #3021
1 parent d8433b7 commit aa79adf

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

src/agent_setup.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::sync::Arc;
77

88
use parking_lot::RwLock;
99

10+
use zeph_core::RuntimeContext;
1011
use zeph_core::channel::Channel;
1112
use zeph_core::config::Config;
1213
use zeph_tools::{
@@ -342,12 +343,11 @@ pub(crate) async fn build_tool_setup(
342343
config: &Config,
343344
permission_policy: zeph_tools::PermissionPolicy,
344345
with_tool_events: bool,
345-
suppress_stderr: bool,
346+
runtime_ctx: RuntimeContext,
346347
age_vault: Option<&Arc<tokio::sync::RwLock<zeph_core::vault::AgeVaultProvider>>>,
347348
status_tx: Option<tokio::sync::mpsc::UnboundedSender<String>>,
348349
pool: Option<&zeph_db::DbPool>,
349350
provider: &zeph_llm::any::AnyProvider,
350-
tui_mode: bool,
351351
) -> ToolSetup {
352352
let filter_registry = if config.tools.filters.enabled {
353353
zeph_tools::OutputFilterRegistry::default_filters(&config.tools.filters)
@@ -361,7 +361,7 @@ pub(crate) async fn build_tool_setup(
361361
let mut audit_logger: Option<Arc<zeph_tools::AuditLogger>> = None;
362362
if config.tools.audit.enabled
363363
&& let Ok(logger) =
364-
zeph_tools::AuditLogger::from_config(&config.tools.audit, tui_mode).await
364+
zeph_tools::AuditLogger::from_config(&config.tools.audit, runtime_ctx.tui_mode).await
365365
{
366366
let logger = Arc::new(logger);
367367
shell_executor = shell_executor.with_audit(Arc::clone(&logger));
@@ -395,8 +395,11 @@ pub(crate) async fn build_tool_setup(
395395
.collect(),
396396
);
397397

398-
let mut mcp_manager_builder =
399-
crate::bootstrap::create_mcp_manager_with_vault(config, suppress_stderr, age_vault);
398+
let mut mcp_manager_builder = crate::bootstrap::create_mcp_manager_with_vault(
399+
config,
400+
runtime_ctx.suppress_stderr(),
401+
age_vault,
402+
);
400403
if let Some(tx) = status_tx {
401404
mcp_manager_builder = mcp_manager_builder.with_status_tx(tx);
402405
}

src/runner.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -652,8 +652,6 @@ pub(crate) async fn run(cli: Cli) -> anyhow::Result<()> {
652652
Some(tokio::spawn(async move { warmup_provider(&p).await }))
653653
};
654654

655-
let suppress_mcp_stderr = runtime_ctx.suppress_stderr();
656-
657655
// For TUI path: create the channel and start rendering immediately so the user
658656
// sees a spinner during the heavy init phases below. For non-TUI paths (or when
659657
// --tui is not passed), channel creation is deferred until after the tokio::join!
@@ -756,12 +754,11 @@ pub(crate) async fn run(cli: Cli) -> anyhow::Result<()> {
756754
config,
757755
permission_policy.clone(),
758756
with_tool_events,
759-
suppress_mcp_stderr,
757+
runtime_ctx,
760758
app.age_vault_arc(),
761759
Some(agent_status_tx.clone()),
762760
Some(memory.sqlite().pool()),
763761
&provider,
764-
runtime_ctx.tui_mode,
765762
)
766763
.await
767764
});
@@ -770,12 +767,11 @@ pub(crate) async fn run(cli: Cli) -> anyhow::Result<()> {
770767
config,
771768
permission_policy.clone(),
772769
with_tool_events,
773-
suppress_mcp_stderr,
770+
runtime_ctx,
774771
app.age_vault_arc(),
775772
Some(agent_status_tx.clone()),
776773
Some(memory.sqlite().pool()),
777774
&provider,
778-
runtime_ctx.tui_mode,
779775
)
780776
.await;
781777

0 commit comments

Comments
 (0)