Skip to content

Commit 28e6cc0

Browse files
committed
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.
1 parent f03b8dc commit 28e6cc0

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

rust/crates/runtime/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ pub mod recovery_recipes;
3535
mod remote;
3636
pub mod sandbox;
3737
mod session;
38-
#[cfg(test)]
39-
mod session_control;
38+
pub mod session_control;
39+
pub use session_control::SessionStore;
4040
mod sse;
4141
pub mod stale_base;
4242
pub mod stale_branch;

rust/crates/runtime/src/session.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,3 +1434,12 @@ mod tests {
14341434
.collect()
14351435
}
14361436
}
1437+
1438+
/// Per-worktree session isolation: returns a session directory namespaced
1439+
/// by the workspace fingerprint of the given working directory.
1440+
/// This prevents parallel `opencode serve` instances from colliding.
1441+
pub fn workspace_sessions_dir(cwd: &std::path::Path) -> Result<std::path::PathBuf, SessionError> {
1442+
let store = crate::session_control::SessionStore::from_cwd(cwd)
1443+
.map_err(|e| SessionError::Io(std::io::Error::new(std::io::ErrorKind::Other, e.to_string())))?;
1444+
Ok(store.sessions_dir().to_path_buf())
1445+
}

0 commit comments

Comments
 (0)