Repository navigation
Connect stdiod to multiple backend profiles #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,9 @@ pub struct UninstallArgs { | |
| /// `--purge` to wipe everything stdiod-related. | ||
| #[arg(long)] | ||
| pub purge: bool, | ||
| /// Preserve named backend credentials and preferences during a default sign-in reset. | ||
| #[arg(long, requires = "purge")] | ||
| pub keep_profiles: bool, | ||
| } | ||
|
|
||
| pub fn install(_args: InstallArgs) -> Result<()> { | ||
|
|
@@ -55,27 +58,56 @@ pub fn uninstall(args: UninstallArgs) -> Result<()> { | |
| // uninstall, even without ``--purge``. config.toml stays because it | ||
| // carries the user's credentials. | ||
| if let Ok(state_path) = paths::state_file() { | ||
| match std::fs::remove_file(&state_path) { | ||
| Ok(()) => info!(path = %state_path.display(), "removed state.json"), | ||
| Err(e) if e.kind() == std::io::ErrorKind::NotFound => {} | ||
| Err(e) => { | ||
| tracing::warn!(error = %e, "failed to remove state.json; continuing"); | ||
| remove_state(&state_path); | ||
| } | ||
| match paths::profile_names() { | ||
| Ok(names) => { | ||
| for name in names { | ||
| remove_state(&paths::profile_dir(&name)?.join("state.json")); | ||
| } | ||
| } | ||
| Err(error) => tracing::warn!(%error, "could not discover backend profiles"), | ||
| } | ||
| if args.purge { | ||
| purge_user_data().context("purge")?; | ||
| purge_user_data(args.keep_profiles).context("purge")?; | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn purge_user_data() -> Result<()> { | ||
| let config_dir = paths::config_dir()?; | ||
| if config_dir.exists() { | ||
| std::fs::remove_dir_all(&config_dir) | ||
| fn remove_state(path: &std::path::Path) { | ||
| match std::fs::remove_file(path) { | ||
| Ok(()) => info!(path = %path.display(), "removed state.json"), | ||
| Err(error) if error.kind() == std::io::ErrorKind::NotFound => {} | ||
| Err(error) => tracing::warn!(%error, path = %path.display(), "failed to remove state.json"), | ||
| } | ||
| } | ||
|
|
||
| fn purge_config(config_dir: &std::path::Path, keep_profiles: bool) -> Result<()> { | ||
| if keep_profiles { | ||
| for entry in std::fs::read_dir(config_dir)? { | ||
| let entry = entry?; | ||
| if entry.file_name() == paths::PROFILES_DIRECTORY { | ||
| continue; | ||
| } | ||
| let path = entry.path(); | ||
| let remove = if entry.file_type()?.is_dir() { | ||
| std::fs::remove_dir_all(&path) | ||
| } else { | ||
| std::fs::remove_file(&path) | ||
| }; | ||
| remove.with_context(|| format!("removing {}", path.display()))?; | ||
| } | ||
| } else if config_dir.exists() { | ||
| std::fs::remove_dir_all(config_dir) | ||
| .with_context(|| format!("removing {}", config_dir.display()))?; | ||
| info!(path = %config_dir.display(), "purged config dir"); | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn purge_user_data(keep_profiles: bool) -> Result<()> { | ||
| let config_dir = paths::config_dir()?; | ||
| purge_config(&config_dir, keep_profiles)?; | ||
| let log_dir = paths::log_dir()?; | ||
| if log_dir.exists() { | ||
| std::fs::remove_dir_all(&log_dir) | ||
|
|
@@ -85,3 +117,27 @@ fn purge_user_data() -> Result<()> { | |
| println!("Purged config and logs."); | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn default_reset_preserves_named_profile_credentials() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: The new test covers only Prompt for AI agents |
||
| let root = | ||
| std::env::temp_dir().join(format!("stdiod-profile-purge-{}", std::process::id())); | ||
| let profile = root.join(paths::PROFILES_DIRECTORY).join("staging"); | ||
| std::fs::create_dir_all(&profile).unwrap(); | ||
| std::fs::write(root.join("config.toml"), "default-config").unwrap(); | ||
| std::fs::write(profile.join("config.toml"), "staging-config").unwrap(); | ||
|
|
||
| purge_config(&root, true).unwrap(); | ||
| assert!(!root.join("config.toml").exists()); | ||
| assert_eq!( | ||
| std::fs::read_to_string(profile.join("config.toml")).unwrap(), | ||
| "staging-config" | ||
| ); | ||
| purge_config(&root, false).unwrap(); | ||
| assert!(!root.exists()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -142,8 +142,11 @@ pub(crate) async fn submit( | |
|
|
||
| fn format_create_result(name: &str, response: ClientCreateRequestResponse) -> String { | ||
| if response.auto_approved { | ||
| let profile_option = crate::paths::profile_name() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: The new Prompt for AI agents |
||
| .map(|profile| format!(" --profile {profile}")) | ||
| .unwrap_or_default(); | ||
| format!( | ||
| "Request '{name}' was auto-approved (request ID {}). Run `sealgate-stdiod status` to confirm it has spawned.", | ||
| "Request '{name}' was auto-approved (request ID {}). Run `sealgate-stdiod status{profile_option}` to confirm it has spawned.", | ||
| response.request_id | ||
| ) | ||
| } else { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: This profile-state deletion races daemon shutdown on macOS.
platform::uninstall()returns beforebootouthas finished, so a profile session can rewritestate.jsonafter this call; wait for all sessions to stop before deleting state, or perform the cleanup after teardown has settled.Prompt for AI agents