Seed auth from existing pi install on first run
Avoids re-authentication when pi is already configured on the host.
Assisted-by: Claude Opus 4.6 via pi
diff --git a/src/main.rs b/src/main.rs
index b620d45..c487184 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -61,12 +61,19 @@ fn run() -> Result<()> {
fs_err::write(&agents_md, "")?;
}
- // User-scoped: auth shared across all sessions
+ // User-scoped: auth shared across all sessions.
+ // Seed from pi's own auth if available so the user doesn't re-authenticate.
let auth_file = xdg
.place_data_file("auth.json")
.wrap_err("failed to create auth file path")?;
if !auth_file.exists() {
- fs_err::write(&auth_file, "{}")?;
+ let pi_auth = home_dir().map(|h| h.join(".pi/agent/auth.json"));
+ if let Some(src) = pi_auth.filter(|p| p.is_file()) {
+ info!(src = %src.display(), "seeding auth from pi");
+ fs_err::copy(&src, &auth_file)?;
+ } else {
+ fs_err::write(&auth_file, "{}")?;
+ }
}
// Repo-scoped: per-workspace pi data dir for sessions
@@ -174,6 +181,10 @@ fn run() -> Result<()> {
Ok(())
}
+fn home_dir() -> Option<PathBuf> {
+ std::env::var("HOME").ok().map(PathBuf::from)
+}
+
/// Generate a short random session ID.
fn session_id() -> String {
format!("{:x}", std::process::id())