Skip to main content

Handler

Struct Handler 

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

Core reactive messaging handler.

Manages agent registrations, rate limiting, message injection, and audit logging.

Implementations§

Source§

impl Handler

Source

pub fn get_delivery_target(&self, name: &str) -> Option<&AgentRegistration>

Handler::get_agent, plus a former slug’s agent: for a delivery target only, never a name that authenticates or acts.

Source

pub fn lookup_delivery_target(&self, name: &str) -> LookupOutcome

Handler::lookup_by_name, plus a former slug’s agent: for a delivery target (a transcript, files, the resolve endpoint).

Source

pub fn set_former_slug_resolver(&mut self, resolver: FormerSlugResolver)

Source

pub fn set_display_route_resolver(&mut self, resolver: FormerSlugResolver)

The UID of the agent whose current display name routes to a name (Store::display_route_owner): the same delivery-only rules as a former slug, tried first, since a current name wins over a former one. Never consulted for a sender (#1459).

Source§

impl Handler

Source

pub fn new() -> Self

Create a new handler without an input sender. Call set_input_sender before injecting messages.

Source

pub fn set_input_sender(&mut self, sender: InputSender)

Set the input sender function for message injection.

Source

pub fn set_message_sender(&mut self, sender: MessageSender)

Set the controller-aware message sender. When present, inject_message tries it first: persistent stream-json and ACP agents receive a structured message on their live channel (mid-turn steering); PTY-based agents report back so injection falls through to the keystroke path.

Source

pub fn set_agent_identity_confirmer( &mut self, confirmer: AgentIdentityConfirmer, )

Set the agent-identity confirmer used by inject_message_inner to double-check a resolved delivery target against its own live, spawn-time-captured identity before delivering. Optional — if never set, delivery proceeds exactly as before this check existed (fail-open).

Source

pub fn set_stable_agent_identity_confirmer( &mut self, confirmer: AgentIdentityConfirmer, )

See stable_agent_identity_confirmer’s field doc comment.

Source

pub fn set_uid_identity_confirmer(&mut self, confirmer: AgentIdentityConfirmer)

See uid_identity_confirmer’s field doc comment (identity M2).

Source

pub fn set_block_liveness(&mut self, probe: BlockLivenessProbe)

See block_liveness’s field doc comment (identity M2).

Source

pub fn set_include_source(&mut self, include: bool)

Set whether to include source agent prefix in injected messages.

Source

pub fn register_agent( &mut self, agent_id: &str, block_id: &str, tab_id: Option<&str>, ) -> Result<(), String>

Register an agent with a block. Name-only registration. Every production site now goes through [register_agent_full] with its UID and counter site; this is the test-facing form (and the shape the pre-M2 API had).

Source

pub fn register_agent_with_nonce( &mut self, agent_id: &str, block_id: &str, tab_id: Option<&str>, registration_nonce: u64, alias: Option<&str>, ) -> Result<(), String>

[register_agent], recording the registering persistent-controller spawn’s process-wide registration nonce (AgentRegistration::registration_nonce) so its own exit-handler can later compare-and-remove ([unregister_block_if_nonce]) instead of blindly wiping a fallback respawn’s fresh registration (issue #2363).

alias, if given, becomes the block’s stable name binding (NameBindings::stable): kept when a later call replaces the display binding, so a jekt addressed to AGENTMUX_AGENT_ID still resolves after the display name has moved on post-rename.

Source

pub fn register_agent_full( &mut self, display: &str, block_id: &str, tab_id: Option<&str>, registration_nonce: u64, stable: Option<&str>, uid: Option<&str>, no_uid_counter: &'static str, ) -> Result<(), String>

The full registration (identity M2, spec §4.4.2): display is the block’s display binding, stable its stable binding (set or kept), uid its identity when the caller knows it, and no_uid_counter the §9.2 counter to bump when it does not.

Eviction is by identity, never by name:

  • uid already registered on another block → that block is evicted entirely (a respawn).
  • a name already held by another block is left alone unless neither block has a UID — that case keeps today’s name eviction exactly, and is counted.
  • a block that has a UID keeps it when re-registered without one (sticky — a transient row miss on the presence path must not drop a live block out of uid_to_block); a block without one is upgraded in place when a later registration supplies one.
Source

pub fn has_live_name(&self, name: &str) -> bool

Does any live block hold name (case-insensitive, like the cloud subscription’s keys)? An exit’s own nonce check can’t answer this: it reports false both when a newer spawn owns the registration and when nobody holds it any more.

Source

pub fn lookup_by_name(&self, name: &str) -> LookupOutcome

Name lookup that tells an ambiguous name apart from an unknown one (identity M2) — for callers that must refuse with candidates rather than fall through to cross-instance forwarding (GetAgentTranscript). No former slugs (lookup_delivery_target adds them).

Source

pub fn unregister_agent(&mut self, agent_id: &str) -> UnregisterOutcome

Unregister by name (identity M2, spec §4.4.4 Q7). One live block → removed. Several → nothing is removed and the candidates are returned; the caller must not report success. None → NotFound.

Source

pub fn unregister_block(&mut self, block_id: &str) -> Vec<String>

Unregister by block ID. Returns every name the block was bound under (empty if it was not registered) so name-keyed side state can be torn down for each.

Source

pub fn unregister_block_if_nonce( &mut self, block_id: &str, expected_nonce: u64, ) -> bool

Unregister by block ID only if the current registration was written by the spawn with expected_nonce — a compare-and-remove for persistent-controller exit-handlers (issue #2363: the handler’s is_current_generation gate is read once, while a fallback respawn re-registers on a parallel task; an unconditional [unregister_block] here could wipe the NEW spawn’s registration, leaving the live agent invisible to Tier-1 delivery with nothing left to re-register it). The nonce is process-wide unique, so the guard also holds across controller replacement (resync_controller — codex P1 on PR #2500), where a controller-local generation would restart at 1 and collide. Runs atomically under the handler’s own lock (via the outer wrapper). A registration with no recorded nonce (0 — HTTP/PTY paths) is never removed by this variant: leaving a stale entry to the TTL sweep is strictly safer than deleting a live one.

Returns true if the registration was ours and was removed.

Source

pub fn update_last_seen(&mut self, agent_id: &str)

Update the last_seen timestamp for an agent.

Source

pub fn get_agent(&self, agent_id: &str) -> Option<&AgentRegistration>

Get agent registration by agent ID — a UID, or a name held by exactly one live block. A name held by several is None, counted (lookup.ambiguous_name): callers that authorize on it fail closed, and callers that display on it show nothing rather than the wrong one. Never a former slug’s agent: callers authenticate and act on this.

Source

pub fn has_uid_registration(&self, uid: &str) -> bool

Whether uid has a live registration — a lookup with no side effect (no counter, no rate-limit token, no audit entry), for the held-jekt replay’s presence check.

Source

pub fn block_for_uid(&self, uid: &str) -> Option<String>

The block uid is registered on, with no side effect — for the held-jekt replay’s quiet sign-in check.

Source

pub fn inject_held(&mut self, req: InjectionRequest) -> InjectionResponse

Deliver a held jekt (durable jekt spec §2.3): the ordinary delivery path, audited as held_delivered (or held_retry on failure).

Source

pub fn get_agent_by_block(&self, block_id: &str) -> Option<&AgentRegistration>

Get agent registration by block ID.

Source

pub fn names_for_block(&self, block_id: &str) -> Vec<String>

Every name block_id is bound under (display first, then stable). Production teardown gets the same list back from [unregister_block]; this read-only form is what registration subscribes for cloud delivery.

Source

pub fn list_agents(&self) -> Vec<AgentRegistration>

List all registered agents.

Source

pub fn inject_message(&mut self, req: InjectionRequest) -> InjectionResponse

Inject a message into an agent’s terminal.

Sends message\r as a single payload (required for text display), then spawns 3 delayed \r sends at 200ms intervals as separate PTY writes to ensure submission. See docs/specs/jekt-inject-timing.md.

Source

pub fn deliver_system_note( &mut self, target_agent: &str, text: &str, ) -> Result<(), String>

Deliver one of srv’s own [AgentMux] system notes to target_agent now, which starts a turn if none is running; an informational note waits for the next one instead (held_notes). Not a jekt: no marker block, tier or trust label, because nothing but srv wrote the text, and no jekt or forwarded text can carry the marker (sanitize::neutralize_markers). Routed like a jekt: the controller’s structured channel, else keystrokes. Audited as system_note from agentmux.

Source

pub fn get_audit_log(&self, limit: usize) -> Vec<AuditLogEntry>

Get audit log entries, most recent first.

Trait Implementations§

Source§

impl Default for Handler

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

impl<T> Instrument for T

§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> NoneValue for T
where T: Default,

§

type NoneType = T

§

fn null_value() -> T

The none-equivalent value.
§

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

§

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
§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

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

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