Configurable session storage path (sessions_dir, HX_SESSIONS_DIR, optional sessions_host)
This commit is contained in:
1 parent
b84b6ab23a
commit
05165d7b8f
4 files changed
+54
-11
No files matched your search
@@ -169,6 +169,10 @@ struct Config {
|
||||
codemode: Option<bool>,
|
||||
/// Capture the mouse for wheel scrolling (default true; false = terminal selection works without shift).
|
||||
mouse: Option<bool>,
|
||||
/// Where sessions live (default `~/.hx/sessions`); `~` expands. Point at a synced/mounted cloud folder. `HX_SESSIONS_DIR` wins.
|
||||
sessions_dir: Option<String>,
|
||||
/// Prefix session folders with the host name, so machines sharing `sessions_dir` stay apart (default false).
|
||||
sessions_host: Option<bool>,
|
||||
/// Reuse the last model chosen with /model or /provider (default true).
|
||||
remember_model: Option<bool>,
|
||||
/// `/model auto`: tier pins (`fast`, `balanced`, `deep` = model ids) and `down_after`.
|
||||
@@ -244,6 +248,8 @@ impl Config {
|
||||
subagents: o.subagents.or(c.subagents),
|
||||
codemode: o.codemode.or(c.codemode),
|
||||
mouse: o.mouse.or(c.mouse),
|
||||
sessions_dir: o.sessions_dir.or(c.sessions_dir),
|
||||
sessions_host: o.sessions_host.or(c.sessions_host),
|
||||
remember_model: o.remember_model.or(c.remember_model),
|
||||
auto: o.auto.or(c.auto),
|
||||
permissions: o.permissions.or(c.permissions),
|
||||
@@ -591,8 +597,33 @@ impl<H: Hook> Hook for ArcHook<H> {
|
||||
}
|
||||
}
|
||||
|
||||
fn session_dir(cwd: &std::path::Path) -> std::path::PathBuf {
|
||||
hx_core::session::dir(&context::hx_home(), cwd)
|
||||
fn session_dir(cwd: &std::path::Path, cfg: &Config) -> Result<std::path::PathBuf> {
|
||||
let home = context::hx_home();
|
||||
let root = match std::env::var("HX_SESSIONS_DIR")
|
||||
.ok()
|
||||
.or(cfg.sessions_dir.clone())
|
||||
{
|
||||
Some(s) if !s.is_empty() => match s.strip_prefix('~') {
|
||||
Some(r) => std::env::var_os("HOME")
|
||||
.map(std::path::PathBuf::from)
|
||||
.unwrap_or_default()
|
||||
.join(r.trim_start_matches('/')),
|
||||
None => s.into(),
|
||||
},
|
||||
_ => home.join("sessions"),
|
||||
};
|
||||
let host = cfg.sessions_host.unwrap_or(false).then(|| {
|
||||
["HOSTNAME", "HOST", "COMPUTERNAME"]
|
||||
.iter()
|
||||
.find_map(|k| std::env::var(k).ok())
|
||||
.or_else(|| std::fs::read_to_string("/etc/hostname").ok())
|
||||
.map_or("host".into(), |h| h.trim().to_string())
|
||||
});
|
||||
let dir = hx_core::session::dir(&root, cwd, host.as_deref());
|
||||
// fail loud: a silent fallback would leave sessions off the cloud folder
|
||||
std::fs::create_dir_all(&dir)
|
||||
.map_err(|e| anyhow::anyhow!("sessions dir {}: {e}", dir.display()))?;
|
||||
Ok(dir)
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
@@ -912,7 +943,7 @@ async fn main() -> Result<()> {
|
||||
}
|
||||
.unwrap_or_else(|| hx_ai::models::default_for(kind, &models))
|
||||
});
|
||||
let dir = session_dir(&cwd);
|
||||
let dir = session_dir(&cwd, &cfg)?;
|
||||
let query = cli.resume.as_deref().filter(|q| !q.is_empty());
|
||||
let path = match (cli.session, cli.r#continue, query) {
|
||||
_ if acp_id.is_some() => dir.join(format!(
|
||||
|
||||
Reference in new issue
Block a user