pub struct Session { /* private fields */ }Expand description
One caller’s view of a database: the engine, the branch they are on, the project they are working in, and who they are.
The current branch is per-session state, not database state, so two clients can sit on different branches of the same database. The same goes for the namespace and the writer: two clients in two projects share one store.
Implementations§
Source§impl Session
impl Session
Sourcepub fn new(db: Db) -> Self
pub fn new(db: Db) -> Self
Start a session on the database’s default branch, in the fallback namespace, with no writer recorded.
Sourcepub fn autopilot(&self) -> MutexGuard<'_, SessionState>
pub fn autopilot(&self) -> MutexGuard<'_, SessionState>
Autopilot’s state for this session.
Sourcepub fn switch_to(&self, name: String)
pub fn switch_to(&self, name: String)
Move this session to name, which the caller has checked exists.
Autopilot’s way of following git and settling a fork.
Sourcepub fn sharing(self, shared: Arc<Shared>) -> Self
pub fn sharing(self, shared: Arc<Shared>) -> Self
Share leases, statistics and fact hashes with every other session in this process.
Sourcepub fn in_project(self, root: PathBuf) -> Self
pub fn in_project(self, root: PathBuf) -> Self
Check facts against the files under root, in this process.
What this session shares with the rest of the process.
Sourcepub fn set_session_id(&self, id: &str)
pub fn set_session_id(&self, id: &str)
Take the session id a proxy chose, so claims survive its reconnects.
Sourcepub fn facts_checked(&self, checked: &Checked)
pub fn facts_checked(&self, checked: &Checked)
Record what checking facts found: statistics, and one event per fact.
Sourcepub fn reporting_to(self, events: Arc<Events>) -> Self
pub fn reporting_to(self, events: Arc<Events>) -> Self
Report this session’s activity to events, for memfork watch.
Sourcepub fn in_namespace(db: Db, namespace: impl Into<String>) -> Self
pub fn in_namespace(db: Db, namespace: impl Into<String>) -> Self
Start a session in a given namespace.
Sourcepub fn set_namespace(&self, name: String)
pub fn set_namespace(&self, name: String)
Move the session to another namespace. The caller has validated it.
Sourcepub fn set_writer(&self, name: &str)
pub fn set_writer(&self, name: &str)
Record this session’s writes as coming from name — for the MCP
server, the name the client gave when it connected. Blank names are
ignored, and long ones cut, since this is whatever a client sent.
Sourcepub fn call(&self, name: &str, args: &JsonObject) -> Result<Json, ToolError>
pub fn call(&self, name: &str, args: &JsonObject) -> Result<Json, ToolError>
Run one tool call and return its result as JSON.
Every result carries current_branch, added here rather than by each
tool so it cannot be forgotten. Without it a caller that is unsure
which branch it is on has to spend a call finding out, and one that has
just forked has to confirm the switch — two of the redundant calls seen
in practice.