Skip to main content

Session

Struct Session 

Source
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

Source

pub fn new(db: Db) -> Self

Start a session on the database’s default branch, in the fallback namespace, with no writer recorded.

Source

pub fn autopilot(&self) -> MutexGuard<'_, SessionState>

Autopilot’s state for this session.

Source

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.

Source

pub fn sharing(self, shared: Arc<Shared>) -> Self

Share leases, statistics and fact hashes with every other session in this process.

Source

pub fn in_project(self, root: PathBuf) -> Self

Check facts against the files under root, in this process.

Source

pub fn shared(&self) -> &Arc<Shared> ⓘ

What this session shares with the rest of the process.

Source

pub fn set_session_id(&self, id: &str)

Take the session id a proxy chose, so claims survive its reconnects.

Source

pub fn who(&self) -> Who

Who this session is, for claims.

Source

pub fn facts_checked(&self, checked: &Checked)

Record what checking facts found: statistics, and one event per fact.

Source

pub fn reporting_to(self, events: Arc<Events>) -> Self

Report this session’s activity to events, for memfork watch.

Source

pub fn announce(&self)

The client has said who it is: list it as connected. Once only.

Source

pub fn in_namespace(db: Db, namespace: impl Into<String>) -> Self

Start a session in a given namespace.

Source

pub fn namespace(&self) -> String

The project namespace the handoff and resume tools work in.

Source

pub fn set_namespace(&self, name: String)

Move the session to another namespace. The caller has validated it.

Source

pub fn writer(&self) -> Option<String>

Who this session’s writes are recorded as, if anyone.

Source

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.

Source

pub fn db(&self) -> &Db

The database this session reads and writes.

Source

pub fn branch(&self) -> String

The branch this session is currently on.

Source

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.

Trait Implementations§

Source§

impl Debug for Session

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Session

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more