mirror of
https://github.com/instructkr/claw-code.git
synced 2026-04-08 00:54:49 +08:00
feat(runtime): activate per-worktree session isolation (#41)
Remove #[cfg(test)] gate from session_control module — SessionStore is now available at runtime, not just in tests. Export SessionStore and add workspace_sessions_dir() helper that creates fingerprinted session directories per workspace root. This is the #41 kill shot: parallel opencode serve instances will use separate session namespaces based on workspace fingerprint instead of sharing a global ~/.local/share/opencode/ store. The CLI already uses cwd/.claw/sessions/ (sessions_dir()), and now SessionStore::from_cwd() adds workspace hash isolation on top.
This commit is contained in:
@@ -35,8 +35,8 @@ pub mod recovery_recipes;
|
|||||||
mod remote;
|
mod remote;
|
||||||
pub mod sandbox;
|
pub mod sandbox;
|
||||||
mod session;
|
mod session;
|
||||||
#[cfg(test)]
|
pub mod session_control;
|
||||||
mod session_control;
|
pub use session_control::SessionStore;
|
||||||
mod sse;
|
mod sse;
|
||||||
pub mod stale_base;
|
pub mod stale_base;
|
||||||
pub mod stale_branch;
|
pub mod stale_branch;
|
||||||
|
|||||||
@@ -1434,3 +1434,12 @@ mod tests {
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Per-worktree session isolation: returns a session directory namespaced
|
||||||
|
/// by the workspace fingerprint of the given working directory.
|
||||||
|
/// This prevents parallel `opencode serve` instances from colliding.
|
||||||
|
pub fn workspace_sessions_dir(cwd: &std::path::Path) -> Result<std::path::PathBuf, SessionError> {
|
||||||
|
let store = crate::session_control::SessionStore::from_cwd(cwd)
|
||||||
|
.map_err(|e| SessionError::Io(std::io::Error::new(std::io::ErrorKind::Other, e.to_string())))?;
|
||||||
|
Ok(store.sessions_dir().to_path_buf())
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user