Skip to main content

SessionsRegistry

Struct SessionsRegistry 

Source
pub struct SessionsRegistry { /* private fields */ }
Expand description

The cross-window session registry.

The in-memory, TTL-reaped set of running Claude sessions plus the companion window-embedding reports used to tag a session’s Source. Hosted by SessionsService.

Implementations§

Source§

impl SessionsRegistry

Source

pub fn new() -> Self

Creates the registry with the default liveness TTLs. Cheap — no I/O.

Source

pub fn subscribe_changes(&self) -> Receiver<u64>

A change-notification receiver for the push subscription: it observes a new value each time the rendered session state changes (see bump). Created with the current version already marked seen, so the first watch::Receiver::changed resolves on the next change — the subscriber sends its own initial snapshot up front and then waits for deltas (#1414).

Source

pub fn observe(&self, req: ObserveRequest)

Records (upserts) a session sighting, running the SessionState inference and refreshing liveness. Reaps stale entries first, then — only when a genuinely new session would grow the map past [MAX_SESSIONS] — evicts the longest-silent entry. Infallible: an upsert never evicts.

Best-effort fields (cwd/transcript_path/repo/model) fill in on an existing entry and never overwrite known data with None, so a later hook enriches a watcher-discovered session without a race losing data.

bumps only when the sighting changed something a consumer renders — a brand-new session, a SessionState transition, a best-effort field taking a new value, or a reap that dropped a sibling. A repeat sighting that merely refreshes liveness does not, since hooks fire on every tool call (the heartbeat precedent in WorktreesRegistry).

Source

pub fn end(&self, session_id: &str, _reason: Option<&str>) -> bool

Marks a session ended (SessionEnd), so list shows it as ended for a short window ([ENDED_SESSION_TTL]) before it is reaped. Returns whether the session was known. A no-op for an already-unknown session (a duplicate/late SessionEnd).

Source

pub fn report_window(&self, report: WindowReport)

Records (upserts) a companion window-embedding report and refreshes its liveness. Reaps stale windows first, then caps like observe.

bumps only when the report changes the Source join a consumer renders — a new window, different folders, or an embedding that appeared or vanished — never on the unchanged ~10 s refresh every open window sends, which would otherwise put a permanent push floor under the daemon proportional to the window count.

Source

pub fn unregister_window(&self, key: &str) -> bool

Drops a companion window-embedding report (the window closed). Returns whether an entry was present.

Source

pub fn list(&self) -> Vec<SessionEntry>

Reaps stale sessions and windows, then returns the live sessions with each Source resolved and sorted for deterministic output.

Two independent locks, each held only for pure-CPU work and never nested: the sessions snapshot is taken and the lock dropped, then the windows snapshot, then the join runs lock-free. Path matching is a pure prefix compare (no canonicalization / disk I/O), honouring the Mutex-never-across-.await and no-I/O-under-lock invariants.

Deliberately does not bump, even when its inline reap drops an entry: this is the body of every subscription’s snapshot(), so bumping here would feed the stream loop back into itself. A read-path reap reaches other subscribers on the server’s next periodic re-sample, whose diff sees the shrunken list — the WorktreesRegistry::list arrangement.

Source

pub fn focus_folder(&self, session_id: &str) -> Option<PathBuf>

The first workspace folder of the still-live window a session is embedded in, if any — used by the tray “focus” action to resolve a session to a folder to open in VS Code. None when the session has no cwd, or is not matched to a reporting window with a folder.

Trait Implementations§

Source§

impl Default for SessionsRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. 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<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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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