fix(grid-agent): move setup into YAML preferences (#135)
This commit is contained in:
@@ -37,7 +37,8 @@ enum Operation {
|
||||
TuiClient,
|
||||
PrintPaths,
|
||||
Acceptance,
|
||||
CheckLiveOptIns,
|
||||
Preferences,
|
||||
ImportEnv,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -45,6 +46,7 @@ struct Options {
|
||||
config: Option<PathBuf>,
|
||||
operation: Operation,
|
||||
evidence: Option<PathBuf>,
|
||||
import_env: Option<PathBuf>,
|
||||
}
|
||||
|
||||
fn options() -> Result<Option<Options>, CliError> {
|
||||
@@ -60,7 +62,7 @@ fn options() -> Result<Option<Options>, CliError> {
|
||||
}
|
||||
if argument == "--help" || argument == "-h" {
|
||||
println!(
|
||||
"metacrate-grid-agent [--config PATH] [--check-config | --run-once | --tui | --tui-client | --print-paths | --acceptance-evidence PATH | --check-live-opt-ins]\n\
|
||||
"metacrate-grid-agent [--config PATH] [--check-config | --run-once | --tui | --tui-client | --preferences | --import-env PATH | --print-paths | --acceptance-evidence PATH]\n\
|
||||
Configuration precedence: defaults < JSON < secret files < environment.\n\
|
||||
With no --config, the platform default is used when it exists."
|
||||
);
|
||||
@@ -86,8 +88,15 @@ fn options() -> Result<Option<Options>, CliError> {
|
||||
.ok_or_else(|| CliError("--acceptance-evidence requires a new path".into()))?;
|
||||
count += 1;
|
||||
result.evidence = Some(PathBuf::from(path));
|
||||
} else if argument == "--check-live-opt-ins" {
|
||||
set_operation(&mut result, Operation::CheckLiveOptIns)?;
|
||||
} else if argument == "--preferences" {
|
||||
set_operation(&mut result, Operation::Preferences)?;
|
||||
} else if argument == "--import-env" {
|
||||
set_operation(&mut result, Operation::ImportEnv)?;
|
||||
let path = arguments
|
||||
.next()
|
||||
.ok_or_else(|| CliError("--import-env requires a .env path".into()))?;
|
||||
count += 1;
|
||||
result.import_env = Some(PathBuf::from(path));
|
||||
} else if argument == "--config" {
|
||||
let path = arguments
|
||||
.next()
|
||||
@@ -140,28 +149,31 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
if options.operation == Operation::CheckLiveOptIns {
|
||||
let opt_ins =
|
||||
metacrate_grid_agent::LiveGridOptIns::from_environment(|name| std::env::var(name).ok())
|
||||
.validate()?;
|
||||
let mut loader = ConfigLoader::new();
|
||||
let default_config_path = platform_paths.config_file;
|
||||
let config_path = options.config.or_else(|| {
|
||||
default_config_path
|
||||
.is_file()
|
||||
.then_some(default_config_path.clone())
|
||||
});
|
||||
let preferences_path = config_path.clone().unwrap_or(default_config_path);
|
||||
if options.operation == Operation::Preferences {
|
||||
metacrate_grid_agent::tui::run_preferences_terminal(preferences_path, !color_disabled())?;
|
||||
return Ok(());
|
||||
}
|
||||
if options.operation == Operation::ImportEnv {
|
||||
let source = options
|
||||
.import_env
|
||||
.ok_or_else(|| CliError("legacy .env path is required".into()))?;
|
||||
let mut preferences = metacrate_grid_agent::AgentPreferences::load(&preferences_path)?;
|
||||
preferences.import_dotenv(source)?;
|
||||
preferences.save(&preferences_path)?;
|
||||
println!(
|
||||
"live opt-ins: login={} chat_im={} script={} landmarks={} build={} visual={}",
|
||||
opt_ins.login,
|
||||
opt_ins.chat_and_im,
|
||||
opt_ins.script_delivery,
|
||||
opt_ins.landmarks_and_roaming,
|
||||
opt_ins.reversible_build,
|
||||
opt_ins.visual_capture
|
||||
"imported grid and AI settings into {}",
|
||||
preferences_path.display()
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
let mut loader = ConfigLoader::new();
|
||||
let config_path = options.config.or_else(|| {
|
||||
platform_paths
|
||||
.config_file
|
||||
.is_file()
|
||||
.then_some(platform_paths.config_file)
|
||||
});
|
||||
if let Some(path) = config_path {
|
||||
loader = loader.with_file(path);
|
||||
}
|
||||
@@ -181,8 +193,12 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
token.clone(),
|
||||
config.control.limits,
|
||||
);
|
||||
metacrate_grid_agent::tui::run_terminal(std::sync::Arc::new(client), !color_disabled())
|
||||
.await?;
|
||||
metacrate_grid_agent::tui::run_terminal_with_preferences(
|
||||
std::sync::Arc::new(client),
|
||||
!color_disabled(),
|
||||
Some(preferences_path),
|
||||
)
|
||||
.await?;
|
||||
return Ok(());
|
||||
}
|
||||
if config.mode != OperatingMode::OfflineFake {
|
||||
@@ -191,6 +207,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
config,
|
||||
options.operation == Operation::RunOnce,
|
||||
options.operation == Operation::Tui,
|
||||
preferences_path,
|
||||
)
|
||||
.await;
|
||||
#[cfg(not(feature = "live-grid"))]
|
||||
@@ -252,6 +269,7 @@ async fn run_live(
|
||||
config: metacrate_grid_agent::AgentConfig,
|
||||
run_once: bool,
|
||||
tui: bool,
|
||||
preferences_path: PathBuf,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
use metacrate_grid_agent::{
|
||||
AgentControlTarget, BehaviorObservation, ControlEventKind, ControlPlane, ControlTarget,
|
||||
@@ -402,10 +420,13 @@ async fn run_live(
|
||||
let client = integrated_client.ok_or_else(|| {
|
||||
CliError("--tui requires integrated mode; use --tui-client for split mode".into())
|
||||
})?;
|
||||
Some(tokio::spawn(metacrate_grid_agent::tui::run_terminal(
|
||||
Arc::new(client),
|
||||
!color_disabled(),
|
||||
)))
|
||||
Some(tokio::spawn(
|
||||
metacrate_grid_agent::tui::run_terminal_with_preferences(
|
||||
Arc::new(client),
|
||||
!color_disabled(),
|
||||
Some(preferences_path),
|
||||
),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user