pub struct Kernel {Show 18 fields
pub session_id: SessionId,
pub event_bus: Arc<EventBus>,
pub capsules: Arc<RwLock<CapsuleRegistry>>,
pub mcp: SecureMcpClient,
pub capabilities: Arc<CapabilityStore>,
pub vfs: Arc<dyn Vfs>,
pub overlay_registry: Arc<OverlayVfsRegistry>,
pub vfs_root_handle: DirHandle,
pub workspace_root: PathBuf,
pub home_root: Option<PathBuf>,
pub cli_socket_listener: Option<Arc<Mutex<UnixListener>>>,
pub kv: Arc<SurrealKvStore>,
pub audit_log: Arc<AuditLog>,
pub ephemeral: AtomicBool,
pub boot_time: Instant,
pub shutdown_tx: Sender<bool>,
pub session_token: Arc<SessionToken>,
pub allowance_store: Arc<AllowanceStore>,
/* private fields */
}Expand description
The core Operating System Kernel.
Fields§
§session_id: SessionIdThe unique identifier for this kernel session.
event_bus: Arc<EventBus>The global IPC message bus.
capsules: Arc<RwLock<CapsuleRegistry>>The process manager (loaded WASM capsules).
mcp: SecureMcpClientThe secure MCP client with capability-based authorization and audit logging.
capabilities: Arc<CapabilityStore>The capability store for this session.
vfs: Arc<dyn Vfs>The global Virtual File System mount.
Points at the unmodified workspace (no overlay). Principal-scoped
overlays live in overlay_registry — this
field is kept for kernel-internal paths that do not know a principal
(discovery, capsule load scan).
overlay_registry: Arc<OverlayVfsRegistry>Per-principal overlay registry (Layer 4, issue #668).
Each invoking principal resolves their own
OverlayVfs from this registry on first
use — lower layer is the shared workspace, upper layer is a
principal-private tempdir. Agent A’s uncommitted writes are never
visible to Agent B.
vfs_root_handle: DirHandleThe global physical root handle (cap-std) for the VFS.
workspace_root: PathBufThe physical path the VFS is mounted to.
home_root: Option<PathBuf>The principal home resources directory (~/.astrid/home/{principal}/).
Capsules declaring fs_read = ["home://"] can read files under this
root. Scoped to the principal’s home so that keys, databases, and
system config in ~/.astrid/ are NOT accessible.
Always Some in production (boot requires AstridHome). Remains
Option for compatibility with CapsuleContext and test fixtures.
cli_socket_listener: Option<Arc<Mutex<UnixListener>>>The natively bound Unix Socket for the CLI proxy.
kv: Arc<SurrealKvStore>Shared KV store backing all capsule-scoped stores and kernel state.
audit_log: Arc<AuditLog>Chain-linked cryptographic audit log with persistent storage.
ephemeral: AtomicBoolEphemeral mode: shut down immediately when the last client disconnects.
boot_time: InstantInstant when the kernel was booted (for uptime calculation).
shutdown_tx: Sender<bool>Sender for the API-initiated shutdown signal. The daemon’s main loop
selects on the receiver to exit gracefully without process::exit.
session_token: Arc<SessionToken>Session token for socket authentication. Generated at boot, written to
~/.astrid/run/system.token. CLI sends this as its first message.
allowance_store: Arc<AllowanceStore>Shared allowance store for capsule-level approval decisions.
Capsules can check existing allowances and create new ones when users approve actions with session/always scope.
Implementations§
Source§impl Kernel
impl Kernel
Sourcepub async fn new(
session_id: SessionId,
workspace_root: PathBuf,
) -> Result<Arc<Self>, Error>
pub async fn new( session_id: SessionId, workspace_root: PathBuf, ) -> Result<Arc<Self>, Error>
Sourcepub async fn load_all_capsules(&self)
pub async fn load_all_capsules(&self)
Auto-discover and load all capsules from the standard directories (~/.astrid/capsules and .astrid/capsules).
Capsules are loaded in dependency order (topological sort) with uplink/daemon capsules loaded first. Each uplink must signal readiness before non-uplink capsules are loaded.
After all capsules are loaded, tool schemas are injected into every
capsule’s KV namespace and the astrid.v1.capsules_loaded event is published.
Sourcepub fn connection_opened(&self, principal: &PrincipalId)
pub fn connection_opened(&self, principal: &PrincipalId)
Record that a new client connection for principal has been established.
Sourcepub fn connection_closed(&self, principal: &PrincipalId)
pub fn connection_closed(&self, principal: &PrincipalId)
Record that a client connection for principal has been closed.
Uses fetch_update for atomic saturating decrement - avoids the
TOCTOU window where fetch_sub wraps to usize::MAX before a
corrective store.
When this principal’s counter reaches zero, clears only that
principal’s session-scoped allowances — other principals’ state is
untouched. The global ephemeral-shutdown path remains gated on the
sum across every principal (see
total_connection_count).
Sourcepub fn set_ephemeral(&self, val: bool)
pub fn set_ephemeral(&self, val: bool)
Enable or disable ephemeral mode (immediate shutdown on last disconnect).
Sourcepub fn total_connection_count(&self) -> usize
pub fn total_connection_count(&self) -> usize
Total number of active client connections across all principals.
Used by the ephemeral-shutdown gate: the kernel shuts down only when every principal’s counter has reached zero.
Sourcepub fn connections_by_principal(&self) -> Vec<(PrincipalId, usize)>
pub fn connections_by_principal(&self) -> Vec<(PrincipalId, usize)>
Snapshot of (principal, count) for every principal with a
non-zero active connection. The astrid who admin surface
reads this to attribute connections to specific agents
instead of fabricating a default-only row from the bare
total.
Not a hot-path call site — taken at status-RPC time. Iterating
the DashMap snapshots the shard guards individually, so the
total may not be perfectly consistent with a concurrent
connect/disconnect, but each entry is internally consistent
and the operator-facing accuracy bound (a flickering one-off
count) is acceptable.
Auto Trait Implementations§
impl !Freeze for Kernel
impl !RefUnwindSafe for Kernel
impl Send for Kernel
impl Sync for Kernel
impl Unpin for Kernel
impl UnsafeUnpin for Kernel
impl !UnwindSafe for Kernel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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