From 93b6577cd392551d5a80bbdbfbe4d5eb6425f819 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Wed, 22 Apr 2026 21:02:37 -0400 Subject: [PATCH] simplify: drop duplicate settings plumbing from cli/server refactor - Remove CommandContext::cli_settings and cascade through 11 functions whose only use of `cli: &CliNamespace` was constructing it; dispatchers now forward only cli_layer. - Drop `ServerSettings as CurrentServerSettings` / `ServerNamespace as ResolvedServerSettings` rename aliases; use the canonical type names in fabro-server. - Inline `local_server::server_settings` and `user_config::{resolve_user_settings, resolve_cli_settings}` wrappers; callers use `ServerSettings::from_layer` / `UserSettings::from_layer` directly (anyhow converts via `?`). - Trim narrative module doc in fabro-config/src/lib.rs. Co-Authored-By: Claude Opus 4.7 (1M context) --- lib/crates/fabro-cli/src/command_context.rs | 29 ++++--------------- .../fabro-cli/src/commands/artifact/cp.rs | 1 - .../fabro-cli/src/commands/artifact/list.rs | 1 - .../fabro-cli/src/commands/artifact/mod.rs | 3 +- .../fabro-cli/src/commands/auth/login.rs | 6 ++-- .../fabro-cli/src/commands/auth/logout.rs | 4 +-- lib/crates/fabro-cli/src/commands/auth/mod.rs | 8 ++--- .../fabro-cli/src/commands/auth/status.rs | 4 +-- .../fabro-cli/src/commands/config/mod.rs | 5 ++-- lib/crates/fabro-cli/src/commands/doctor.rs | 2 +- lib/crates/fabro-cli/src/commands/graph.rs | 2 +- lib/crates/fabro-cli/src/commands/install.rs | 4 +-- lib/crates/fabro-cli/src/commands/model.rs | 2 +- lib/crates/fabro-cli/src/commands/pr/close.rs | 4 +-- .../fabro-cli/src/commands/pr/create.rs | 4 +-- lib/crates/fabro-cli/src/commands/pr/list.rs | 4 +-- lib/crates/fabro-cli/src/commands/pr/merge.rs | 4 +-- lib/crates/fabro-cli/src/commands/pr/mod.rs | 6 ++-- lib/crates/fabro-cli/src/commands/pr/view.rs | 4 +-- .../fabro-cli/src/commands/preflight.rs | 2 +- .../fabro-cli/src/commands/provider/login.rs | 4 +-- .../fabro-cli/src/commands/provider/mod.rs | 4 +-- .../fabro-cli/src/commands/repo/init.rs | 5 ++-- .../fabro-cli/src/commands/run/command.rs | 4 +-- lib/crates/fabro-cli/src/commands/run/cp.rs | 9 ++---- lib/crates/fabro-cli/src/commands/run/diff.rs | 2 +- lib/crates/fabro-cli/src/commands/run/fork.rs | 2 +- lib/crates/fabro-cli/src/commands/run/logs.rs | 2 +- lib/crates/fabro-cli/src/commands/run/mod.rs | 11 ++++--- .../fabro-cli/src/commands/run/preview.rs | 2 +- .../fabro-cli/src/commands/run/resume.rs | 2 +- .../fabro-cli/src/commands/run/rewind.rs | 2 +- lib/crates/fabro-cli/src/commands/run/ssh.rs | 2 +- lib/crates/fabro-cli/src/commands/run/wait.rs | 2 +- .../fabro-cli/src/commands/runs/archive.rs | 4 +-- .../fabro-cli/src/commands/runs/inspect.rs | 10 ++----- .../fabro-cli/src/commands/runs/list.rs | 2 +- lib/crates/fabro-cli/src/commands/runs/mod.rs | 2 +- lib/crates/fabro-cli/src/commands/runs/rm.rs | 2 +- .../fabro-cli/src/commands/secret/mod.rs | 2 +- .../fabro-cli/src/commands/store/dump.rs | 2 +- .../fabro-cli/src/commands/system/df.rs | 2 +- .../fabro-cli/src/commands/system/events.rs | 2 +- .../fabro-cli/src/commands/system/info.rs | 2 +- .../fabro-cli/src/commands/system/prune.rs | 2 +- lib/crates/fabro-cli/src/commands/validate.rs | 2 +- lib/crates/fabro-cli/src/commands/version.rs | 2 +- lib/crates/fabro-cli/src/local_server.rs | 6 +--- lib/crates/fabro-cli/src/main.rs | 24 ++++----------- lib/crates/fabro-cli/src/user_config.rs | 12 +------- lib/crates/fabro-config/src/lib.rs | 6 ++-- .../fabro-server/src/canonical_origin.rs | 4 +-- lib/crates/fabro-server/src/jwt_auth.rs | 13 ++++----- lib/crates/fabro-server/src/serve.rs | 22 +++++++------- lib/crates/fabro-server/src/server.rs | 14 ++++----- 55 files changed, 104 insertions(+), 185 deletions(-) diff --git a/lib/crates/fabro-cli/src/command_context.rs b/lib/crates/fabro-cli/src/command_context.rs index ac508f5ed..b5351d640 100644 --- a/lib/crates/fabro-cli/src/command_context.rs +++ b/lib/crates/fabro-cli/src/command_context.rs @@ -4,8 +4,8 @@ use std::sync::Arc; use anyhow::{Context as _, Result, bail}; use fabro_config::UserSettings; use fabro_config::merge::combine_files; +use fabro_types::settings::SettingsLayer; use fabro_types::settings::cli::CliLayer; -use fabro_types::settings::{CliNamespace, SettingsLayer}; use fabro_util::printer::Printer; use tokio::sync::OnceCell; @@ -35,24 +35,18 @@ pub(crate) struct CommandContext { base_config_path: PathBuf, machine_settings: SettingsLayer, user_settings: UserSettings, - cli_settings: CliNamespace, server_mode: ServerMode, server: OnceCell>, } impl CommandContext { - pub(crate) fn base( - printer: Printer, - cli_settings: CliNamespace, - cli_layer: &CliLayer, - ) -> Result { - Self::new(printer, ServerMode::None, cli_settings, cli_layer) + pub(crate) fn base(printer: Printer, cli_layer: &CliLayer) -> Result { + Self::new(printer, ServerMode::None, cli_layer) } pub(crate) fn for_target( args: &ServerTargetArgs, printer: Printer, - cli_settings: CliNamespace, cli_layer: &CliLayer, ) -> Result { Self::new( @@ -60,7 +54,6 @@ impl CommandContext { ServerMode::ByTarget { target_override: args.server.clone(), }, - cli_settings, cli_layer, ) } @@ -68,7 +61,6 @@ impl CommandContext { pub(crate) fn for_connection( args: &ServerConnectionArgs, printer: Printer, - cli_settings: CliNamespace, cli_layer: &CliLayer, ) -> Result { Self::new( @@ -77,17 +69,11 @@ impl CommandContext { target_override: args.target.server.clone(), storage_dir_override: args.storage_dir.clone_path(), }, - cli_settings, cli_layer, ) } - fn new( - printer: Printer, - server_mode: ServerMode, - cli_settings: CliNamespace, - cli_layer: &CliLayer, - ) -> Result { + fn new(printer: Printer, server_mode: ServerMode, cli_layer: &CliLayer) -> Result { let cwd = std::env::current_dir().context("Failed to get current directory")?; let base_config_path = user_config::active_settings_path(None); let disk_settings = match &server_mode { @@ -101,7 +87,7 @@ impl CommandContext { cli: Some(cli_layer.clone()), ..SettingsLayer::default() }); - let user_settings = user_config::resolve_user_settings(&machine_settings)?; + let user_settings = fabro_config::UserSettings::from_layer(&machine_settings)?; Ok(Self { printer, @@ -109,7 +95,6 @@ impl CommandContext { base_config_path, machine_settings, user_settings, - cli_settings, server_mode, server: OnceCell::new(), }) @@ -135,10 +120,6 @@ impl CommandContext { &self.user_settings } - pub(crate) fn cli_settings(&self) -> &CliNamespace { - &self.cli_settings - } - pub(crate) async fn server(&self) -> Result> { let server_mode = self.server_mode.clone(); let base_config_path = self.base_config_path.clone(); diff --git a/lib/crates/fabro-cli/src/commands/artifact/cp.rs b/lib/crates/fabro-cli/src/commands/artifact/cp.rs index 9b87dd6a1..2756912c1 100644 --- a/lib/crates/fabro-cli/src/commands/artifact/cp.rs +++ b/lib/crates/fabro-cli/src/commands/artifact/cp.rs @@ -26,7 +26,6 @@ pub(super) async fn cp_command( run_id_selector, args.node.as_deref(), args.retry, - cli, cli_layer, printer, ) diff --git a/lib/crates/fabro-cli/src/commands/artifact/list.rs b/lib/crates/fabro-cli/src/commands/artifact/list.rs index 0637f7a5b..e7de1d4a4 100644 --- a/lib/crates/fabro-cli/src/commands/artifact/list.rs +++ b/lib/crates/fabro-cli/src/commands/artifact/list.rs @@ -19,7 +19,6 @@ pub(super) async fn list_command( &args.run_id, args.node.as_deref(), args.retry, - cli, cli_layer, printer, ) diff --git a/lib/crates/fabro-cli/src/commands/artifact/mod.rs b/lib/crates/fabro-cli/src/commands/artifact/mod.rs index 571f3cdb0..605d1beec 100644 --- a/lib/crates/fabro-cli/src/commands/artifact/mod.rs +++ b/lib/crates/fabro-cli/src/commands/artifact/mod.rs @@ -26,11 +26,10 @@ pub(super) async fn resolve_artifacts( run_selector: &str, node: Option<&str>, retry: Option, - cli: &CliNamespace, cli_layer: &CliLayer, printer: Printer, ) -> Result<(RunId, Client, Vec)> { - let ctx = CommandContext::for_target(server, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(server, printer, cli_layer)?; let client = ctx.server().await?; let run_id = client.resolve_run(run_selector).await?.run_id; let mut entries = Vec::new(); diff --git a/lib/crates/fabro-cli/src/commands/auth/login.rs b/lib/crates/fabro-cli/src/commands/auth/login.rs index 5d3d69a30..7968fb78e 100644 --- a/lib/crates/fabro-cli/src/commands/auth/login.rs +++ b/lib/crates/fabro-cli/src/commands/auth/login.rs @@ -4,7 +4,6 @@ use anyhow::{Context as _, Result, bail}; use chrono::{DateTime, Utc}; use fabro_client::{AuthEntry, AuthStore, StoredSubject}; use fabro_http::header::CONTENT_TYPE; -use fabro_types::settings::CliNamespace; use fabro_types::settings::cli::CliLayer; use fabro_util::browser; use fabro_util::printer::Printer; @@ -36,7 +35,6 @@ struct CliTokenSubject { pub(super) async fn login_command( args: AuthLoginArgs, - cli: &CliNamespace, cli_layer: &CliLayer, process_local_json: bool, printer: Printer, @@ -45,7 +43,7 @@ pub(super) async fn login_command( #[cfg(not(unix))] { - let _ = (args, cli, cli_layer, printer); + let _ = (args, cli_layer, printer); bail!( "CLI OAuth login is not supported on Windows in this release. Use WSL, or use a dev-token server." ); @@ -53,7 +51,7 @@ pub(super) async fn login_command( #[cfg(unix)] { - let ctx = CommandContext::base(printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::base(printer, cli_layer)?; let target = user_config::resolve_server_target(&args.server, ctx.machine_settings())?; let web_url = browser_origin(&target)?; let pkce = fabro_oauth::generate_pkce(); diff --git a/lib/crates/fabro-cli/src/commands/auth/logout.rs b/lib/crates/fabro-cli/src/commands/auth/logout.rs index eda47e51b..6acf20275 100644 --- a/lib/crates/fabro-cli/src/commands/auth/logout.rs +++ b/lib/crates/fabro-cli/src/commands/auth/logout.rs @@ -1,7 +1,6 @@ use anyhow::{Result, bail}; use fabro_client::{AuthEntry, AuthStore}; use fabro_http::header::AUTHORIZATION; -use fabro_types::settings::CliNamespace; use fabro_types::settings::cli::CliLayer; use fabro_util::printer::Printer; @@ -12,14 +11,13 @@ use crate::user_config::ServerTarget; pub(super) async fn logout_command( args: AuthLogoutArgs, - cli: &CliNamespace, cli_layer: &CliLayer, process_local_json: bool, printer: Printer, ) -> Result<()> { require_no_json_override(process_local_json)?; - let ctx = CommandContext::base(printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::base(printer, cli_layer)?; let store = AuthStore::default(); if args.all { let entries = store.list()?; diff --git a/lib/crates/fabro-cli/src/commands/auth/mod.rs b/lib/crates/fabro-cli/src/commands/auth/mod.rs index 1d5a4546e..dd4ca8a83 100644 --- a/lib/crates/fabro-cli/src/commands/auth/mod.rs +++ b/lib/crates/fabro-cli/src/commands/auth/mod.rs @@ -3,7 +3,6 @@ mod logout; mod status; use anyhow::Result; -use fabro_types::settings::CliNamespace; use fabro_types::settings::cli::CliLayer; use fabro_util::printer::Printer; @@ -11,20 +10,19 @@ use crate::args::{AuthCommand, AuthNamespace}; pub(crate) async fn dispatch( ns: AuthNamespace, - cli: &CliNamespace, cli_layer: &CliLayer, process_local_json: bool, printer: Printer, ) -> Result<()> { match ns.command { AuthCommand::Login(args) => { - login::login_command(args, cli, cli_layer, process_local_json, printer).await + login::login_command(args, cli_layer, process_local_json, printer).await } AuthCommand::Logout(args) => { - logout::logout_command(args, cli, cli_layer, process_local_json, printer).await + logout::logout_command(args, cli_layer, process_local_json, printer).await } AuthCommand::Status(args) => { - status::status_command(&args, cli, cli_layer, process_local_json, printer) + status::status_command(&args, cli_layer, process_local_json, printer) } } } diff --git a/lib/crates/fabro-cli/src/commands/auth/status.rs b/lib/crates/fabro-cli/src/commands/auth/status.rs index 86962b52a..aa82b6f7e 100644 --- a/lib/crates/fabro-cli/src/commands/auth/status.rs +++ b/lib/crates/fabro-cli/src/commands/auth/status.rs @@ -1,7 +1,6 @@ use anyhow::Result; use chrono::{DateTime, Utc}; use fabro_client::{AuthEntry, AuthStore}; -use fabro_types::settings::CliNamespace; use fabro_types::settings::cli::CliLayer; use fabro_util::dev_token::{read_dev_token_file, validate_dev_token_format}; use fabro_util::printer::Printer; @@ -43,12 +42,11 @@ struct StatusOutput { pub(super) fn status_command( args: &AuthStatusArgs, - cli: &CliNamespace, cli_layer: &CliLayer, process_local_json: bool, printer: Printer, ) -> Result<()> { - let ctx = CommandContext::base(printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::base(printer, cli_layer)?; let store = AuthStore::default(); let now = Utc::now(); let rows = if args.server.as_deref().is_some() { diff --git a/lib/crates/fabro-cli/src/commands/config/mod.rs b/lib/crates/fabro-cli/src/commands/config/mod.rs index 1f329af84..670cca826 100644 --- a/lib/crates/fabro-cli/src/commands/config/mod.rs +++ b/lib/crates/fabro-cli/src/commands/config/mod.rs @@ -26,11 +26,10 @@ struct RenderedConfig { async fn rendered_config( args: &SettingsArgs, - cli: &CliNamespace, cli_layer: &CliLayer, printer: Printer, ) -> anyhow::Result { - let ctx = CommandContext::for_target(&args.target, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(&args.target, printer, cli_layer)?; let user = fabro_config::UserSettings::resolve()?; let server = ctx .server() @@ -46,7 +45,7 @@ pub(crate) async fn execute( cli_layer: &CliLayer, printer: Printer, ) -> anyhow::Result<()> { - let config = Box::pin(rendered_config(args, cli, cli_layer, printer)).await?; + let config = Box::pin(rendered_config(args, cli_layer, printer)).await?; if cli.output.format == OutputFormat::Json { print_json_pretty(&config)?; return Ok(()); diff --git a/lib/crates/fabro-cli/src/commands/doctor.rs b/lib/crates/fabro-cli/src/commands/doctor.rs index fb25bb147..85c8517c6 100644 --- a/lib/crates/fabro-cli/src/commands/doctor.rs +++ b/lib/crates/fabro-cli/src/commands/doctor.rs @@ -179,7 +179,7 @@ pub(crate) async fn run_doctor( }], }; - let ctx = match CommandContext::for_target(&args.target, printer, cli.clone(), cli_layer) { + let ctx = match CommandContext::for_target(&args.target, printer, cli_layer) { Ok(ctx) => ctx, Err(err) => { report.sections.push(CheckSection { diff --git a/lib/crates/fabro-cli/src/commands/graph.rs b/lib/crates/fabro-cli/src/commands/graph.rs index 0df39a2e1..71ffa9f68 100644 --- a/lib/crates/fabro-cli/src/commands/graph.rs +++ b/lib/crates/fabro-cli/src/commands/graph.rs @@ -37,7 +37,7 @@ pub(crate) async fn run( require_no_json_override(process_local_json)?; } - let ctx = CommandContext::for_target(&args.target, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(&args.target, printer, cli_layer)?; let built = build_run_manifest(ManifestBuildInput { workflow: args.workflow.clone(), cwd: ctx.cwd().to_path_buf(), diff --git a/lib/crates/fabro-cli/src/commands/install.rs b/lib/crates/fabro-cli/src/commands/install.rs index fa9d26f73..3e0753af4 100644 --- a/lib/crates/fabro-cli/src/commands/install.rs +++ b/lib/crates/fabro-cli/src/commands/install.rs @@ -1277,7 +1277,7 @@ async fn write_artifact_store_metadata( settings: &SettingsLayer, fabro_version: &str, ) -> Result<()> { - let resolved = local_server::server_settings(settings)?; + let resolved = fabro_config::ServerSettings::from_layer(settings)?; let (object_store, prefix) = serve::build_artifact_object_store(&resolved.server)?; let artifact_store = ArtifactStore::new(object_store, prefix); artifact_store.write_metadata(fabro_version).await?; @@ -1796,7 +1796,7 @@ async fn run_install_inner( .context("failed to parse generated settings.toml")?, args.storage_dir.as_deref(), ); - local_server::server_settings(&install_settings)?; + fabro_config::ServerSettings::from_layer(&install_settings)?; // Secrets and auth material { diff --git a/lib/crates/fabro-cli/src/commands/model.rs b/lib/crates/fabro-cli/src/commands/model.rs index c96b3c349..d7c26c2a5 100644 --- a/lib/crates/fabro-cli/src/commands/model.rs +++ b/lib/crates/fabro-cli/src/commands/model.rs @@ -51,7 +51,7 @@ pub(crate) async fn execute( ModelsCommand::List(args) => &args.target, ModelsCommand::Test(args) => &args.target, }; - let ctx = CommandContext::for_target(target_args, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(target_args, printer, cli_layer)?; let server = ctx.server().await?; run_models(command, &server, cli.output.format == OutputFormat::Json).await diff --git a/lib/crates/fabro-cli/src/commands/pr/close.rs b/lib/crates/fabro-cli/src/commands/pr/close.rs index 0cc9a4a39..c48132ba0 100644 --- a/lib/crates/fabro-cli/src/commands/pr/close.rs +++ b/lib/crates/fabro-cli/src/commands/pr/close.rs @@ -14,9 +14,9 @@ pub(super) async fn close_command( printer: Printer, ) -> Result<()> { let (record, _run_id) = - super::load_pr_record(&args.server, &args.run_id, cli, cli_layer, printer).await?; + super::load_pr_record(&args.server, &args.run_id, cli_layer, printer).await?; - let creds = super::load_github_credentials_required(cli, cli_layer, printer)?; + let creds = super::load_github_credentials_required(cli_layer, printer)?; fabro_github::close_pull_request( &creds, diff --git a/lib/crates/fabro-cli/src/commands/pr/create.rs b/lib/crates/fabro-cli/src/commands/pr/create.rs index d26b8080b..e42c633e2 100644 --- a/lib/crates/fabro-cli/src/commands/pr/create.rs +++ b/lib/crates/fabro-cli/src/commands/pr/create.rs @@ -31,7 +31,7 @@ pub(super) async fn create_command( cli_layer: &CliLayer, printer: Printer, ) -> Result<()> { - let ctx = CommandContext::for_target(&args.server, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(&args.server, printer, cli_layer)?; let client = ctx.server().await?; let run_id = client.resolve_run(&args.run_id).await?.run_id; let events = client.list_run_events(&run_id, None, None).await?; @@ -86,7 +86,7 @@ pub(super) async fn create_command( let (owner, repo) = fabro_github::parse_github_owner_repo(&https_url) .map_err(|err| anyhow::anyhow!("{err}"))?; - let creds = super::load_github_credentials_required(cli, cli_layer, printer)?; + let creds = super::load_github_credentials_required(cli_layer, printer)?; let branch_found = fabro_github::branch_exists( &creds, diff --git a/lib/crates/fabro-cli/src/commands/pr/list.rs b/lib/crates/fabro-cli/src/commands/pr/list.rs index 2e0f51f1b..bf86031eb 100644 --- a/lib/crates/fabro-cli/src/commands/pr/list.rs +++ b/lib/crates/fabro-cli/src/commands/pr/list.rs @@ -29,7 +29,7 @@ pub(super) async fn list_command( cli_layer: &CliLayer, printer: Printer, ) -> Result<()> { - let ctx = CommandContext::for_target(&args.server, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(&args.server, printer, cli_layer)?; let lookup = ServerSummaryLookup::from_client(ctx.server().await?).await?; let mut entries = Vec::new(); @@ -50,7 +50,7 @@ pub(super) async fn list_command( return Ok(()); } - let creds = super::load_github_credentials_required(cli, cli_layer, printer)?; + let creds = super::load_github_credentials_required(cli_layer, printer)?; let futures: Vec<_> = entries .iter() diff --git a/lib/crates/fabro-cli/src/commands/pr/merge.rs b/lib/crates/fabro-cli/src/commands/pr/merge.rs index be7ce9f61..3ee3f3338 100644 --- a/lib/crates/fabro-cli/src/commands/pr/merge.rs +++ b/lib/crates/fabro-cli/src/commands/pr/merge.rs @@ -14,9 +14,9 @@ pub(super) async fn merge_command( printer: Printer, ) -> Result<()> { let (record, _run_id) = - super::load_pr_record(&args.server, &args.run_id, cli, cli_layer, printer).await?; + super::load_pr_record(&args.server, &args.run_id, cli_layer, printer).await?; - let creds = super::load_github_credentials_required(cli, cli_layer, printer)?; + let creds = super::load_github_credentials_required(cli_layer, printer)?; fabro_github::merge_pull_request( &creds, diff --git a/lib/crates/fabro-cli/src/commands/pr/mod.rs b/lib/crates/fabro-cli/src/commands/pr/mod.rs index 8d1933f66..dd70c83f7 100644 --- a/lib/crates/fabro-cli/src/commands/pr/mod.rs +++ b/lib/crates/fabro-cli/src/commands/pr/mod.rs @@ -42,11 +42,10 @@ pub(crate) async fn dispatch( reason = "boundary-exempt(pr-api): remove with follow-up #1 when PR ops move server-side" )] fn load_github_credentials_required( - cli: &CliNamespace, cli_layer: &CliLayer, printer: Printer, ) -> Result { - let ctx = CommandContext::base(printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::base(printer, cli_layer)?; let server_settings = fabro_config::ServerSettings::from_layer(ctx.machine_settings()) .map_err(anyhow::Error::from)?; let vault = user_config::storage_dir(ctx.machine_settings()) @@ -71,11 +70,10 @@ fn load_github_credentials_required( pub(crate) async fn load_pr_record( server: &ServerTargetArgs, run_id: &str, - cli: &CliNamespace, cli_layer: &CliLayer, printer: Printer, ) -> Result<(PullRequestRecord, fabro_types::RunId)> { - let ctx = CommandContext::for_target(server, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(server, printer, cli_layer)?; let client = ctx.server().await?; let run_id = client.resolve_run(run_id).await?.run_id; let state = client.get_run_state(&run_id).await?; diff --git a/lib/crates/fabro-cli/src/commands/pr/view.rs b/lib/crates/fabro-cli/src/commands/pr/view.rs index 79eabadeb..d766e7dd4 100644 --- a/lib/crates/fabro-cli/src/commands/pr/view.rs +++ b/lib/crates/fabro-cli/src/commands/pr/view.rs @@ -14,9 +14,9 @@ pub(super) async fn view_command( printer: Printer, ) -> Result<()> { let (record, _run_id) = - super::load_pr_record(&args.server, &args.run_id, cli, cli_layer, printer).await?; + super::load_pr_record(&args.server, &args.run_id, cli_layer, printer).await?; - let creds = super::load_github_credentials_required(cli, cli_layer, printer)?; + let creds = super::load_github_credentials_required(cli_layer, printer)?; let detail = fabro_github::get_pull_request( &creds, diff --git a/lib/crates/fabro-cli/src/commands/preflight.rs b/lib/crates/fabro-cli/src/commands/preflight.rs index 03dd4304a..1a49e8cb5 100644 --- a/lib/crates/fabro-cli/src/commands/preflight.rs +++ b/lib/crates/fabro-cli/src/commands/preflight.rs @@ -22,7 +22,7 @@ pub(crate) async fn execute( printer: Printer, ) -> anyhow::Result<()> { let styles: &'static Styles = Box::leak(Box::new(Styles::detect_stderr())); - let ctx = CommandContext::for_target(&args.target, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(&args.target, printer, cli_layer)?; args.verbose = args.verbose || cli.output.verbosity == OutputVerbosity::Verbose; let manifest = build_run_manifest(ManifestBuildInput { diff --git a/lib/crates/fabro-cli/src/commands/provider/login.rs b/lib/crates/fabro-cli/src/commands/provider/login.rs index 1c613936d..86a393a09 100644 --- a/lib/crates/fabro-cli/src/commands/provider/login.rs +++ b/lib/crates/fabro-cli/src/commands/provider/login.rs @@ -1,7 +1,6 @@ use anyhow::Result; use fabro_api::types; use fabro_auth::credential_id_for; -use fabro_types::settings::CliNamespace; use fabro_types::settings::cli::CliLayer; use fabro_util::printer::Printer; use fabro_util::terminal::Styles; @@ -12,14 +11,13 @@ use crate::shared::provider_auth; pub(super) async fn login_command( args: ProviderLoginArgs, - cli: &CliNamespace, cli_layer: &CliLayer, process_local_json: bool, printer: Printer, ) -> Result<()> { require_no_json_override(process_local_json)?; let s = Styles::detect_stderr(); - let ctx = CommandContext::for_target(&args.target, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(&args.target, printer, cli_layer)?; let server = ctx.server().await?; let credential = if args.api_key_stdin { provider_auth::authenticate_provider_with_api_key_source( diff --git a/lib/crates/fabro-cli/src/commands/provider/mod.rs b/lib/crates/fabro-cli/src/commands/provider/mod.rs index 85dd085a8..07e3d9adf 100644 --- a/lib/crates/fabro-cli/src/commands/provider/mod.rs +++ b/lib/crates/fabro-cli/src/commands/provider/mod.rs @@ -1,7 +1,6 @@ mod login; use anyhow::Result; -use fabro_types::settings::CliNamespace; use fabro_types::settings::cli::CliLayer; use fabro_util::printer::Printer; @@ -9,14 +8,13 @@ use crate::args::{ProviderCommand, ProviderNamespace}; pub(crate) async fn dispatch( ns: ProviderNamespace, - cli: &CliNamespace, cli_layer: &CliLayer, process_local_json: bool, printer: Printer, ) -> Result<()> { match ns.command { ProviderCommand::Login(args) => { - login::login_command(args, cli, cli_layer, process_local_json, printer).await + login::login_command(args, cli_layer, process_local_json, printer).await } } } diff --git a/lib/crates/fabro-cli/src/commands/repo/init.rs b/lib/crates/fabro-cli/src/commands/repo/init.rs index 6b3d717f3..6a9ba0d28 100644 --- a/lib/crates/fabro-cli/src/commands/repo/init.rs +++ b/lib/crates/fabro-cli/src/commands/repo/init.rs @@ -151,7 +151,7 @@ draft = true } if cli.output.format != OutputFormat::Json { - check_github_app_installation(&args.target, cli, cli_layer, printer).await; + check_github_app_installation(&args.target, cli_layer, printer).await; } Ok(created) @@ -159,7 +159,6 @@ draft = true async fn check_github_app_installation( target: &ServerTargetArgs, - cli: &CliNamespace, cli_layer: &CliLayer, printer: Printer, ) { @@ -200,7 +199,7 @@ async fn check_github_app_installation( return; // Not a GitHub repo — skip silently }; - let ctx = match CommandContext::for_target(target, printer, cli.clone(), cli_layer) { + let ctx = match CommandContext::for_target(target, printer, cli_layer) { Ok(ctx) => ctx, Err(err) => { fabro_util::printerr!( diff --git a/lib/crates/fabro-cli/src/commands/run/command.rs b/lib/crates/fabro-cli/src/commands/run/command.rs index 1f63dbef5..20572cf2b 100644 --- a/lib/crates/fabro-cli/src/commands/run/command.rs +++ b/lib/crates/fabro-cli/src/commands/run/command.rs @@ -16,12 +16,12 @@ pub(crate) async fn execute( printer: Printer, ) -> Result<()> { let styles: &'static Styles = Box::leak(Box::new(Styles::detect_stderr())); - let ctx = CommandContext::for_target(&args.target, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(&args.target, printer, cli_layer)?; let cli_defaults = load_settings_with_storage_dir(None)?; args.verbose = args.verbose || cli.output.verbosity == OutputVerbosity::Verbose; let quiet = args.detach; - let prevent_idle_sleep = ctx.cli_settings().exec.prevent_idle_sleep; + let prevent_idle_sleep = ctx.user_settings().cli.exec.prevent_idle_sleep; let created_run = Box::pin(super::create::create_run( &ctx, &args, diff --git a/lib/crates/fabro-cli/src/commands/run/cp.rs b/lib/crates/fabro-cli/src/commands/run/cp.rs index a757ac81c..84c05258e 100644 --- a/lib/crates/fabro-cli/src/commands/run/cp.rs +++ b/lib/crates/fabro-cli/src/commands/run/cp.rs @@ -41,8 +41,7 @@ pub(crate) async fn cp_command( local_path, } => { let (client, run_id) = - resolve_client_and_run_id(&args.server, &run_prefix, cli, cli_layer, printer) - .await?; + resolve_client_and_run_id(&args.server, &run_prefix, cli_layer, printer).await?; let file_count = if args.recursive { Some(download_recursive(&client, &run_id, &remote_path, &local_path).await?) @@ -73,8 +72,7 @@ pub(crate) async fn cp_command( remote_path, } => { let (client, run_id) = - resolve_client_and_run_id(&args.server, &run_prefix, cli, cli_layer, printer) - .await?; + resolve_client_and_run_id(&args.server, &run_prefix, cli_layer, printer).await?; let file_count = if args.recursive { Some(upload_recursive(&client, &run_id, &local_path, &remote_path).await?) @@ -128,11 +126,10 @@ fn parse_direction(src: &str, dst: &str) -> Result { async fn resolve_client_and_run_id( server: &ServerTargetArgs, run_prefix: &str, - cli: &CliNamespace, cli_layer: &CliLayer, printer: Printer, ) -> Result<(Client, fabro_types::RunId)> { - let ctx = CommandContext::for_target(server, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(server, printer, cli_layer)?; let client = ctx.server().await?; let run_id = client.resolve_run(run_prefix).await?.run_id; Ok((client.clone_for_reuse(), run_id)) diff --git a/lib/crates/fabro-cli/src/commands/run/diff.rs b/lib/crates/fabro-cli/src/commands/run/diff.rs index 138c54162..51da824cc 100644 --- a/lib/crates/fabro-cli/src/commands/run/diff.rs +++ b/lib/crates/fabro-cli/src/commands/run/diff.rs @@ -27,7 +27,7 @@ pub(crate) async fn run( printer: Printer, ) -> Result<()> { info!(run_id = %args.run, "Showing diff"); - let ctx = CommandContext::for_target(&args.server, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(&args.server, printer, cli_layer)?; let client = ctx.server().await?; let run_id = client.resolve_run(&args.run).await?.run_id; let state = client.get_run_state(&run_id).await?; diff --git a/lib/crates/fabro-cli/src/commands/run/fork.rs b/lib/crates/fabro-cli/src/commands/run/fork.rs index e08b934b0..70d5ebba6 100644 --- a/lib/crates/fabro-cli/src/commands/run/fork.rs +++ b/lib/crates/fabro-cli/src/commands/run/fork.rs @@ -21,7 +21,7 @@ pub(crate) async fn run( printer: Printer, ) -> Result<()> { let repo = Repository::discover(".").context("not in a git repository")?; - let ctx = CommandContext::for_target(&args.server, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(&args.server, printer, cli_layer)?; let client = ctx.server().await?; let run_id = client.resolve_run(&args.run_id).await?.run_id; let state = client.get_run_state(&run_id).await?; diff --git a/lib/crates/fabro-cli/src/commands/run/logs.rs b/lib/crates/fabro-cli/src/commands/run/logs.rs index fbaca77cd..9098c2e85 100644 --- a/lib/crates/fabro-cli/src/commands/run/logs.rs +++ b/lib/crates/fabro-cli/src/commands/run/logs.rs @@ -36,7 +36,7 @@ pub(crate) async fn run( cli_layer: &CliLayer, printer: Printer, ) -> Result<()> { - let ctx = CommandContext::for_target(&args.server, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(&args.server, printer, cli_layer)?; let client = ctx.server().await?; let run_id = client.resolve_run(&args.run).await?.run_id; info!(run_id = %run_id, "Showing logs"); diff --git a/lib/crates/fabro-cli/src/commands/run/mod.rs b/lib/crates/fabro-cli/src/commands/run/mod.rs index ff0641f29..7acd35e3e 100644 --- a/lib/crates/fabro-cli/src/commands/run/mod.rs +++ b/lib/crates/fabro-cli/src/commands/run/mod.rs @@ -39,7 +39,7 @@ pub(crate) async fn dispatch( RunCommands::Create(args) => { let styles: &'static Styles = Box::leak(Box::new(Styles::detect_stderr())); let cli_defaults = load_settings_with_storage_dir(None)?; - let ctx = CommandContext::for_target(&args.target, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(&args.target, printer, cli_layer)?; let created_run = Box::pin(create::create_run( &ctx, &args, @@ -57,7 +57,7 @@ pub(crate) async fn dispatch( Ok(()) } RunCommands::Start(StartArgs { server, run }) => { - let ctx = CommandContext::for_target(&server, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(&server, printer, cli_layer)?; let client = ctx.server().await?; let run_id = client.resolve_run(&run).await?.run_id; start::start_run_with_client(client.as_ref(), &run_id, false).await?; @@ -68,7 +68,7 @@ pub(crate) async fn dispatch( } RunCommands::Attach(AttachArgs { server, run }) => { let styles: &'static Styles = Box::leak(Box::new(Styles::detect_stderr())); - let ctx = CommandContext::for_target(&server, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(&server, printer, cli_layer)?; let client = ctx.server().await?; let run_id = client.resolve_run(&run).await?.run_id; let exit_code = Box::pin(attach::attach_run_with_client( @@ -113,9 +113,8 @@ pub(crate) async fn dispatch( let styles: &'static Styles = Box::leak(Box::new(Styles::detect_stderr())); #[cfg(feature = "sleep_inhibitor")] let _sleep_guard = { - let ctx = - CommandContext::for_target(&args.server, printer, cli.clone(), cli_layer)?; - crate::sleep_inhibitor::guard(ctx.cli_settings().exec.prevent_idle_sleep) + let ctx = CommandContext::for_target(&args.server, printer, cli_layer)?; + crate::sleep_inhibitor::guard(ctx.user_settings().cli.exec.prevent_idle_sleep) }; Box::pin(resume::resume_command( args, styles, cli, cli_layer, printer, diff --git a/lib/crates/fabro-cli/src/commands/run/preview.rs b/lib/crates/fabro-cli/src/commands/run/preview.rs index 1bcb5f6b2..f344ffd76 100644 --- a/lib/crates/fabro-cli/src/commands/run/preview.rs +++ b/lib/crates/fabro-cli/src/commands/run/preview.rs @@ -15,7 +15,7 @@ pub(crate) async fn run( process_local_json: bool, printer: Printer, ) -> Result<()> { - let ctx = CommandContext::for_target(&args.server, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(&args.server, printer, cli_layer)?; let client = ctx.server().await?; let run_id = client.resolve_run(&args.run).await?.run_id; let expires_in_secs = diff --git a/lib/crates/fabro-cli/src/commands/run/resume.rs b/lib/crates/fabro-cli/src/commands/run/resume.rs index fb175cb51..9c892ea14 100644 --- a/lib/crates/fabro-cli/src/commands/run/resume.rs +++ b/lib/crates/fabro-cli/src/commands/run/resume.rs @@ -19,7 +19,7 @@ pub(crate) async fn resume_command( cli_layer: &CliLayer, printer: Printer, ) -> anyhow::Result<()> { - let ctx = CommandContext::for_target(&args.server, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(&args.server, printer, cli_layer)?; let client = ctx.server().await?; let run_id = client.resolve_run(&args.run).await?.run_id; diff --git a/lib/crates/fabro-cli/src/commands/run/rewind.rs b/lib/crates/fabro-cli/src/commands/run/rewind.rs index 6e65a5f98..1c541f2da 100644 --- a/lib/crates/fabro-cli/src/commands/run/rewind.rs +++ b/lib/crates/fabro-cli/src/commands/run/rewind.rs @@ -38,7 +38,7 @@ pub(crate) async fn run( printer: Printer, ) -> Result<()> { let repo = Repository::discover(".").context("not in a git repository")?; - let ctx = CommandContext::for_target(&args.server, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(&args.server, printer, cli_layer)?; let client = ctx.server().await?; let run_id = client.resolve_run(&args.run_id).await?.run_id; let state = client.get_run_state(&run_id).await?; diff --git a/lib/crates/fabro-cli/src/commands/run/ssh.rs b/lib/crates/fabro-cli/src/commands/run/ssh.rs index f4465d499..d3ce4f9f8 100644 --- a/lib/crates/fabro-cli/src/commands/run/ssh.rs +++ b/lib/crates/fabro-cli/src/commands/run/ssh.rs @@ -19,7 +19,7 @@ pub(crate) async fn run( require_no_json_override(process_local_json)?; } - let ctx = CommandContext::for_target(&args.server, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(&args.server, printer, cli_layer)?; let client = ctx.server().await?; let run_id = client.resolve_run(&args.run).await?.run_id; let ssh = client.create_run_ssh_access(&run_id, args.ttl).await?; diff --git a/lib/crates/fabro-cli/src/commands/run/wait.rs b/lib/crates/fabro-cli/src/commands/run/wait.rs index 639960771..4642cddf1 100644 --- a/lib/crates/fabro-cli/src/commands/run/wait.rs +++ b/lib/crates/fabro-cli/src/commands/run/wait.rs @@ -31,7 +31,7 @@ pub(crate) async fn run( cli_layer: &CliLayer, printer: Printer, ) -> Result<()> { - let ctx = CommandContext::for_target(&args.server, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(&args.server, printer, cli_layer)?; let client = ctx.server().await?; let run_id = client.resolve_run(&args.run).await?.run_id; info!(run_id = %run_id, "Waiting for run to complete"); diff --git a/lib/crates/fabro-cli/src/commands/runs/archive.rs b/lib/crates/fabro-cli/src/commands/runs/archive.rs index 6052d9457..dcc996fc9 100644 --- a/lib/crates/fabro-cli/src/commands/runs/archive.rs +++ b/lib/crates/fabro-cli/src/commands/runs/archive.rs @@ -15,7 +15,7 @@ pub(crate) async fn archive_command( cli_layer: &CliLayer, printer: Printer, ) -> Result<()> { - let ctx = CommandContext::for_target(&args.server, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(&args.server, printer, cli_layer)?; run_bulk( Action::Archive, &args.runs, @@ -32,7 +32,7 @@ pub(crate) async fn unarchive_command( cli_layer: &CliLayer, printer: Printer, ) -> Result<()> { - let ctx = CommandContext::for_target(&args.server, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(&args.server, printer, cli_layer)?; run_bulk( Action::Unarchive, &args.runs, diff --git a/lib/crates/fabro-cli/src/commands/runs/inspect.rs b/lib/crates/fabro-cli/src/commands/runs/inspect.rs index 7858260f1..0ac3f1c4e 100644 --- a/lib/crates/fabro-cli/src/commands/runs/inspect.rs +++ b/lib/crates/fabro-cli/src/commands/runs/inspect.rs @@ -1,5 +1,4 @@ use anyhow::Result; -use fabro_types::settings::CliNamespace; use fabro_types::settings::cli::CliLayer; use fabro_util::printer::Printer; use fabro_workflow::run_status::RunStatus; @@ -21,13 +20,8 @@ pub(crate) struct InspectOutput { pub sandbox: Option, } -pub(crate) async fn run( - args: &InspectArgs, - cli: &CliNamespace, - cli_layer: &CliLayer, - printer: Printer, -) -> Result<()> { - let ctx = CommandContext::for_target(&args.server, printer, cli.clone(), cli_layer)?; +pub(crate) async fn run(args: &InspectArgs, cli_layer: &CliLayer, printer: Printer) -> Result<()> { + let ctx = CommandContext::for_target(&args.server, printer, cli_layer)?; let client = ctx.server().await?; let run = ServerRunSummaryInfo::from_summary(client.resolve_run(&args.run).await?); let run_id = run.run_id(); diff --git a/lib/crates/fabro-cli/src/commands/runs/list.rs b/lib/crates/fabro-cli/src/commands/runs/list.rs index 8b81b5f7b..2e48a3843 100644 --- a/lib/crates/fabro-cli/src/commands/runs/list.rs +++ b/lib/crates/fabro-cli/src/commands/runs/list.rs @@ -24,7 +24,7 @@ pub(crate) async fn list_command( cli_layer: &CliLayer, printer: Printer, ) -> Result<()> { - let ctx = CommandContext::for_target(&args.server, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(&args.server, printer, cli_layer)?; let lookup = ServerSummaryLookup::from_client(ctx.server().await?).await?; let label_filters = parse_label_filters(&args.filter.label); let filtered = filter_server_runs( diff --git a/lib/crates/fabro-cli/src/commands/runs/mod.rs b/lib/crates/fabro-cli/src/commands/runs/mod.rs index fb62b7f2a..3804d4052 100644 --- a/lib/crates/fabro-cli/src/commands/runs/mod.rs +++ b/lib/crates/fabro-cli/src/commands/runs/mod.rs @@ -23,7 +23,7 @@ pub(crate) async fn dispatch( list::list_command(&args, &styles, cli, cli_layer, printer).await } RunsCommands::Rm(args) => rm::remove_command(&args, cli, cli_layer, printer).await, - RunsCommands::Inspect(args) => inspect::run(&args, cli, cli_layer, printer).await, + RunsCommands::Inspect(args) => inspect::run(&args, cli_layer, printer).await, RunsCommands::Archive(args) => { archive::archive_command(&args, cli, cli_layer, printer).await } diff --git a/lib/crates/fabro-cli/src/commands/runs/rm.rs b/lib/crates/fabro-cli/src/commands/runs/rm.rs index eb1047332..8990d4efc 100644 --- a/lib/crates/fabro-cli/src/commands/runs/rm.rs +++ b/lib/crates/fabro-cli/src/commands/runs/rm.rs @@ -15,7 +15,7 @@ pub(crate) async fn remove_command( cli_layer: &CliLayer, printer: Printer, ) -> Result<()> { - let ctx = CommandContext::for_target(&args.server, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(&args.server, printer, cli_layer)?; remove_from(args, ctx.server().await?.as_ref(), cli, printer).await } diff --git a/lib/crates/fabro-cli/src/commands/secret/mod.rs b/lib/crates/fabro-cli/src/commands/secret/mod.rs index 59146f0a8..19fdeef73 100644 --- a/lib/crates/fabro-cli/src/commands/secret/mod.rs +++ b/lib/crates/fabro-cli/src/commands/secret/mod.rs @@ -16,7 +16,7 @@ pub(crate) async fn dispatch( cli_layer: &CliLayer, printer: Printer, ) -> Result<()> { - let ctx = CommandContext::for_target(&ns.target, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(&ns.target, printer, cli_layer)?; let server = ctx.server().await?; match ns.command { SecretCommand::List(args) => list::list_command(&server, &args, cli, printer).await, diff --git a/lib/crates/fabro-cli/src/commands/store/dump.rs b/lib/crates/fabro-cli/src/commands/store/dump.rs index 1713ce6b2..935ec6c0e 100644 --- a/lib/crates/fabro-cli/src/commands/store/dump.rs +++ b/lib/crates/fabro-cli/src/commands/store/dump.rs @@ -32,7 +32,7 @@ pub(crate) async fn dump_command( cli_layer: &CliLayer, printer: Printer, ) -> Result<()> { - let ctx = CommandContext::for_target(&args.server, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(&args.server, printer, cli_layer)?; let client = ctx.server().await?; let run_id = client.resolve_run(&args.run).await?.run_id; let state = client.get_run_state(&run_id).await?; diff --git a/lib/crates/fabro-cli/src/commands/system/df.rs b/lib/crates/fabro-cli/src/commands/system/df.rs index f5cebe0b4..67a099a2e 100644 --- a/lib/crates/fabro-cli/src/commands/system/df.rs +++ b/lib/crates/fabro-cli/src/commands/system/df.rs @@ -17,7 +17,7 @@ pub(super) async fn df_command( cli_layer: &CliLayer, printer: Printer, ) -> Result<()> { - let ctx = CommandContext::for_connection(&args.connection, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_connection(&args.connection, printer, cli_layer)?; let server = ctx.server().await?; let json = cli.output.format == OutputFormat::Json; diff --git a/lib/crates/fabro-cli/src/commands/system/events.rs b/lib/crates/fabro-cli/src/commands/system/events.rs index 7e94cfa1d..1e8d69346 100644 --- a/lib/crates/fabro-cli/src/commands/system/events.rs +++ b/lib/crates/fabro-cli/src/commands/system/events.rs @@ -14,7 +14,7 @@ pub(super) async fn events_command( cli_layer: &CliLayer, printer: Printer, ) -> Result<()> { - let ctx = CommandContext::for_connection(&args.connection, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_connection(&args.connection, printer, cli_layer)?; let server = ctx.server().await?; let mut stream = server.attach_events(&args.run_ids).await?; let mut pending = Vec::new(); diff --git a/lib/crates/fabro-cli/src/commands/system/info.rs b/lib/crates/fabro-cli/src/commands/system/info.rs index a1c584453..314b3f347 100644 --- a/lib/crates/fabro-cli/src/commands/system/info.rs +++ b/lib/crates/fabro-cli/src/commands/system/info.rs @@ -13,7 +13,7 @@ pub(super) async fn info_command( cli_layer: &CliLayer, printer: Printer, ) -> Result<()> { - let ctx = CommandContext::for_connection(&args.connection, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_connection(&args.connection, printer, cli_layer)?; let server = ctx.server().await?; let response = server.get_system_info().await?; diff --git a/lib/crates/fabro-cli/src/commands/system/prune.rs b/lib/crates/fabro-cli/src/commands/system/prune.rs index f7242b023..376ae2003 100644 --- a/lib/crates/fabro-cli/src/commands/system/prune.rs +++ b/lib/crates/fabro-cli/src/commands/system/prune.rs @@ -17,7 +17,7 @@ pub(super) async fn prune_command( cli_layer: &CliLayer, printer: Printer, ) -> Result<()> { - let ctx = CommandContext::for_connection(&args.connection, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_connection(&args.connection, printer, cli_layer)?; let server = ctx.server().await?; let response = server .prune_runs(types::PruneRunsRequest { diff --git a/lib/crates/fabro-cli/src/commands/validate.rs b/lib/crates/fabro-cli/src/commands/validate.rs index 95691b74e..74bba2d11 100644 --- a/lib/crates/fabro-cli/src/commands/validate.rs +++ b/lib/crates/fabro-cli/src/commands/validate.rs @@ -19,7 +19,7 @@ pub(crate) async fn run( cli_layer: &CliLayer, printer: Printer, ) -> anyhow::Result<()> { - let ctx = CommandContext::for_target(&args.target, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(&args.target, printer, cli_layer)?; let built = build_run_manifest(ManifestBuildInput { workflow: args.workflow.clone(), cwd: ctx.cwd().to_path_buf(), diff --git a/lib/crates/fabro-cli/src/commands/version.rs b/lib/crates/fabro-cli/src/commands/version.rs index 826ec108b..993557834 100644 --- a/lib/crates/fabro-cli/src/commands/version.rs +++ b/lib/crates/fabro-cli/src/commands/version.rs @@ -23,7 +23,7 @@ pub(crate) async fn version_command( printer: Printer, ) -> Result<()> { let client = client_info(); - let ctx = CommandContext::for_target(&args.target, printer, cli.clone(), cli_layer)?; + let ctx = CommandContext::for_target(&args.target, printer, cli_layer)?; let server_target = user_config::resolve_server_target(&args.target, ctx.machine_settings())?; let server_address = format_server_target(&server_target); let server_info = match ctx.server().await { diff --git a/lib/crates/fabro-cli/src/local_server.rs b/lib/crates/fabro-cli/src/local_server.rs index 5128e70da..cdba3b556 100644 --- a/lib/crates/fabro-cli/src/local_server.rs +++ b/lib/crates/fabro-cli/src/local_server.rs @@ -26,12 +26,8 @@ pub(crate) fn bind_request( resolve_bind_request_from_settings(settings, cli_override) } -pub(crate) fn server_settings(settings: &SettingsLayer) -> Result { - fabro_config::ServerSettings::from_layer(settings).map_err(anyhow::Error::from) -} - pub(crate) fn auth_methods(settings: &SettingsLayer) -> Vec { - server_settings(settings) + fabro_config::ServerSettings::from_layer(settings) .map(|resolved| resolved.server.auth.methods) .unwrap_or_default() } diff --git a/lib/crates/fabro-cli/src/main.rs b/lib/crates/fabro-cli/src/main.rs index bd2cd9e06..6e54808ff 100644 --- a/lib/crates/fabro-cli/src/main.rs +++ b/lib/crates/fabro-cli/src/main.rs @@ -173,9 +173,9 @@ async fn main_inner() -> (String, Result<()>) { cli: Some(cli_layer.clone()), ..SettingsLayer::default() }); - let cli_settings = match user_config::resolve_cli_settings(&combined_settings) { - Ok(cli_settings) => cli_settings, - Err(err) => return (command_name, Err(err)), + let cli_settings = match fabro_config::UserSettings::from_layer(&combined_settings) { + Ok(settings) => settings.cli, + Err(err) => return (command_name, Err(err.into())), }; let printer = printer_from_verbosity(cli_settings.output.verbosity); @@ -318,14 +318,7 @@ async fn main_inner() -> (String, Result<()>) { commands::uninstall::run_uninstall(&args, &cli_settings, printer).await?; } Commands::Auth(ns) => { - commands::auth::dispatch( - ns, - &cli_settings, - &cli_layer, - process_local_json, - printer, - ) - .await?; + commands::auth::dispatch(ns, &cli_layer, process_local_json, printer).await?; } Commands::Pr(ns) => { Box::pin(commands::pr::dispatch( @@ -353,14 +346,7 @@ async fn main_inner() -> (String, Result<()>) { commands::upgrade::run_upgrade(args, &cli_settings, printer).await?; } Commands::Provider(ns) => { - commands::provider::dispatch( - ns, - &cli_settings, - &cli_layer, - process_local_json, - printer, - ) - .await?; + commands::provider::dispatch(ns, &cli_layer, process_local_json, printer).await?; } Commands::Sandbox { command } => { commands::sandbox::dispatch( diff --git a/lib/crates/fabro-cli/src/user_config.rs b/lib/crates/fabro-cli/src/user_config.rs index 687831cc4..03429dbb4 100644 --- a/lib/crates/fabro-cli/src/user_config.rs +++ b/lib/crates/fabro-cli/src/user_config.rs @@ -30,16 +30,6 @@ pub(crate) fn load_settings_with_config_and_storage_dir( Ok(apply_storage_dir_override(layer, storage_dir)) } -pub(crate) fn resolve_user_settings( - file: &SettingsLayer, -) -> anyhow::Result { - fabro_config::UserSettings::from_layer(file).map_err(anyhow::Error::from) -} - -pub(crate) fn resolve_cli_settings(file: &SettingsLayer) -> anyhow::Result { - resolve_user_settings(file).map(|settings| settings.cli) -} - pub(crate) fn apply_storage_dir_override( mut layer: SettingsLayer, storage_dir: Option<&Path>, @@ -68,7 +58,7 @@ fn cli_target_from_settings(settings: &CliNamespace) -> Option { } fn configured_server_target(settings: &SettingsLayer) -> Result> { - let user_settings = resolve_user_settings(settings)?; + let user_settings = fabro_config::UserSettings::from_layer(settings)?; let Some(value) = cli_target_from_settings(&user_settings.cli) else { return Ok(None); }; diff --git a/lib/crates/fabro-config/src/lib.rs b/lib/crates/fabro-config/src/lib.rs index dc654cbeb..24af07e32 100644 --- a/lib/crates/fabro-config/src/lib.rs +++ b/lib/crates/fabro-config/src/lib.rs @@ -2,10 +2,8 @@ clippy::disallowed_methods, reason = "sync config loading utilities used at startup; not on a Tokio path" )] -//! Settings resolution entrypoints are owner-first context types: -//! [`ServerSettings`] for current server/runtime config and [`UserSettings`] -//! for current CLI/user config. Stored `SettingsLayer` artifacts still use the -//! per-namespace `resolve_*_from_file` helpers. +//! Resolved settings entrypoints: [`ServerSettings`] for the running server and +//! [`UserSettings`] for the CLI/user perspective. extern crate self as fabro_config; diff --git a/lib/crates/fabro-server/src/canonical_origin.rs b/lib/crates/fabro-server/src/canonical_origin.rs index 05bd7793c..203a86abe 100644 --- a/lib/crates/fabro-server/src/canonical_origin.rs +++ b/lib/crates/fabro-server/src/canonical_origin.rs @@ -1,10 +1,10 @@ -use fabro_types::settings::ServerNamespace as ResolvedServerSettings; +use fabro_types::settings::ServerNamespace; use url::Url; use crate::server::EnvLookup; pub(crate) fn resolve_canonical_origin( - resolved: &ResolvedServerSettings, + resolved: &ServerNamespace, env_lookup: &EnvLookup, ) -> Result { let value = resolved diff --git a/lib/crates/fabro-server/src/jwt_auth.rs b/lib/crates/fabro-server/src/jwt_auth.rs index 4b2b53d54..b332cb797 100644 --- a/lib/crates/fabro-server/src/jwt_auth.rs +++ b/lib/crates/fabro-server/src/jwt_auth.rs @@ -2,7 +2,7 @@ use anyhow::{Result, anyhow}; use axum::extract::FromRequestParts; use axum::http::header; use axum::http::request::Parts; -use fabro_types::settings::{ServerAuthMethod, ServerNamespace as ResolvedServerSettings}; +use fabro_types::settings::{ServerAuthMethod, ServerNamespace}; use fabro_types::{IdpIdentity, RunAuthMethod}; use fabro_util::dev_token::validate_dev_token_format; use hmac::{Hmac, Mac}; @@ -51,14 +51,11 @@ pub enum AuthMode { Disabled, } -pub fn resolve_auth_mode(settings: &ResolvedServerSettings) -> Result { +pub fn resolve_auth_mode(settings: &ServerNamespace) -> Result { resolve_auth_mode_with_lookup(settings, |name| std::env::var(name).ok()) } -pub fn resolve_auth_mode_with_lookup( - settings: &ResolvedServerSettings, - lookup: F, -) -> Result +pub fn resolve_auth_mode_with_lookup(settings: &ServerNamespace, lookup: F) -> Result where F: Fn(&str) -> Option, { @@ -124,7 +121,7 @@ where })) } -fn resolve_jwt_issuer(settings: &ResolvedServerSettings, lookup: &F) -> String +fn resolve_jwt_issuer(settings: &ServerNamespace, lookup: &F) -> String where F: Fn(&str) -> Option, { @@ -389,7 +386,7 @@ mod tests { use tracing_subscriber::{Layer, Registry}; use super::*; - fn settings(source: &str) -> ResolvedServerSettings { + fn settings(source: &str) -> ServerNamespace { let file = parse_settings_layer(source).expect("fixture should parse"); resolve_server_from_file(&file).expect("fixture should resolve") } diff --git a/lib/crates/fabro-server/src/serve.rs b/lib/crates/fabro-server/src/serve.rs index 0055eb108..137928875 100644 --- a/lib/crates/fabro-server/src/serve.rs +++ b/lib/crates/fabro-server/src/serve.rs @@ -8,14 +8,14 @@ use clap::Args; use fabro_config::bind::{self, Bind, BindRequest}; use fabro_config::merge::combine_files; use fabro_config::user::load_settings_config; -use fabro_config::{ServerSettings as CurrentServerSettings, Storage}; +use fabro_config::{ServerSettings, Storage}; use fabro_sandbox::SandboxProvider; use fabro_types::settings::server::{ GithubIntegrationStrategy, ServerLayer, ServerListenLayer, WebhookStrategy, }; use fabro_types::settings::{ GithubIntegrationSettings, InterpString, ObjectStoreSettings, ServerListenSettings, - ServerNamespace as ResolvedServerSettings, SettingsLayer, + ServerNamespace, SettingsLayer, }; use fabro_util::terminal::Styles; use object_store::ObjectStore; @@ -142,12 +142,12 @@ fn apply_runtime_settings( settings } -fn router_web_enabled(settings: &ResolvedServerSettings) -> bool { +fn router_web_enabled(settings: &ServerNamespace) -> bool { settings.web.enabled } async fn resolve_github_webhook_ip_allowlist( - resolved_server_settings: &ResolvedServerSettings, + resolved_server_settings: &ServerNamespace, github_meta_resolver: &GitHubMetaResolver, ) -> anyhow::Result> { let config = resolve_ip_allowlist_config( @@ -167,7 +167,7 @@ async fn resolve_github_webhook_ip_allowlist( } async fn resolve_startup_github_webhook_ip_allowlist( - resolved_server_settings: &ResolvedServerSettings, + resolved_server_settings: &ServerNamespace, github_meta_resolver: &GitHubMetaResolver, webhook_secret_present: bool, ) -> anyhow::Result>> { @@ -228,7 +228,7 @@ fn resolve_webhook_preconditions( } async fn start_webhook_strategy( - resolved_server_settings: &ResolvedServerSettings, + resolved_server_settings: &ServerNamespace, state: &Arc, bind_addr: &Bind, webhook_secret_present: bool, @@ -349,8 +349,8 @@ fn build_object_store_from_settings( } } -fn resolve_server_settings(file: &SettingsLayer) -> anyhow::Result { - CurrentServerSettings::from_layer(file) +fn resolve_server_settings(file: &SettingsLayer) -> anyhow::Result { + ServerSettings::from_layer(file) .map(|settings| settings.server) .map_err(anyhow::Error::from) } @@ -391,7 +391,7 @@ fn bind_override_layer(bind: BindRequest) -> SettingsLayer { } fn resolved_bind_request( - resolved_server_settings: &ResolvedServerSettings, + resolved_server_settings: &ServerNamespace, ) -> anyhow::Result { match &resolved_server_settings.listen { ServerListenSettings::Unix { path } => Ok(BindRequest::Unix(resolve_interp_path(path)?)), @@ -411,7 +411,7 @@ fn resolve_interp_path(value: &InterpString) -> anyhow::Result { } pub fn build_artifact_object_store( - settings: &ResolvedServerSettings, + settings: &ServerNamespace, ) -> anyhow::Result<(Arc, String)> { let prefix = resolve_interp(&settings.artifacts.prefix)?; let object_store = build_object_store_from_settings(&settings.artifacts.store)?; @@ -419,7 +419,7 @@ pub fn build_artifact_object_store( } fn build_slatedb_store( - settings: &ResolvedServerSettings, + settings: &ServerNamespace, ) -> anyhow::Result<(Arc, String, Duration, bool)> { let prefix = resolve_interp(&settings.slatedb.prefix)?; let object_store = build_object_store_from_settings(&settings.slatedb.store)?; diff --git a/lib/crates/fabro-server/src/server.rs b/lib/crates/fabro-server/src/server.rs index 6d2526cb1..c0fe087b8 100644 --- a/lib/crates/fabro-server/src/server.rs +++ b/lib/crates/fabro-server/src/server.rs @@ -40,7 +40,7 @@ pub use fabro_api::types::{ }; use fabro_auth::parse_credential_secret; use fabro_config::daemon::ServerDaemon; -use fabro_config::{ServerSettings as CurrentServerSettings, Storage}; +use fabro_config::{ServerSettings, Storage}; use fabro_interview::{ Answer, ControlInterviewer, Interviewer, Question, QuestionType, WorkerControlEnvelope, }; @@ -573,7 +573,7 @@ pub struct AppState { pub(crate) server_secrets: ServerSecrets, pub(crate) provider_credentials: ProviderCredentials, pub(crate) settings: Arc>, - pub(crate) server_settings: RwLock>, + pub(crate) server_settings: RwLock>, pub(crate) env_lookup: EnvLookup, http_client: Option, shutting_down: AtomicBool, @@ -638,7 +638,7 @@ fn accumulate_model_billing(entry: &mut ModelBillingTotals, usage: &BilledModelU } impl AppState { - pub(crate) fn server_settings(&self) -> Arc { + pub(crate) fn server_settings(&self) -> Arc { Arc::clone( &self .server_settings @@ -780,7 +780,7 @@ impl AppState { } pub(crate) fn replace_settings(&self, settings: SettingsLayer) -> anyhow::Result<()> { - let resolved = Arc::new(CurrentServerSettings::from_layer(&settings)?); + let resolved = Arc::new(ServerSettings::from_layer(&settings)?); resolve_canonical_origin(&resolved.server, &self.env_lookup).map_err(anyhow::Error::msg)?; *self.settings.write().expect("settings lock poisoned") = settings; @@ -1656,7 +1656,7 @@ fn system_sandbox_provider(settings: &SettingsLayer) -> String { } fn resolved_storage_dir(settings: &SettingsLayer) -> Result { - let resolved = CurrentServerSettings::from_layer(settings).map_err(|err| err.to_string())?; + let resolved = ServerSettings::from_layer(settings).map_err(|err| err.to_string())?; resolved .server .storage @@ -1672,7 +1672,7 @@ fn resolved_storage_dir(settings: &SettingsLayer) -> Result { } fn resolved_github_settings(settings: &SettingsLayer) -> Result { - let resolved = CurrentServerSettings::from_layer(settings).map_err(|err| err.to_string())?; + let resolved = ServerSettings::from_layer(settings).map_err(|err| err.to_string())?; Ok(resolved.server.integrations.github) } @@ -2589,7 +2589,7 @@ pub(crate) fn build_app_state(config: AppStateConfig) -> anyhow::Result