pub struct Context {
pub config: Config,
pub filesystem: Client,
pub plugin: Option<PluginPath>,
/* private fields */
}Fields§
§config: Config§filesystem: Client§plugin: Option<PluginPath>The plugin a command is running on behalf of, when it was
invoked through a plugin’s nested-command protocol. Assembled
from the OBJECTIVEAI_PLUGIN_* env vars (via Config).
Implementations§
Source§impl Context
impl Context
pub fn new(config: Config) -> Self
Sourcepub async fn python(&self) -> Result<&Python, Error>
pub async fn python(&self) -> Result<&Python, Error>
The WASI python runtime, initialized on first use and
memoized. First use machine-wide JIT-compiles the embedded
interpreter and publishes <bin>/cache/rustpython-<hash>.cwasm
under the bin lock; later uses deserialize that artifact in
milliseconds. Commands that never execute python never pay
either cost.
Sourcepub async fn api_client(&self) -> Result<&HttpClient, Error>
pub async fn api_client(&self) -> Result<&HttpClient, Error>
The API HttpClient, built on first use and memoized.
Address resolution: api.address from the merged (--final)
config view when set, else the api spawn flow — which
returns the lock-published URL of an already-running api
without spawning, or starts one and waits for its lock.
Sourcepub async fn github_http_client(&self) -> Result<HttpClient, Error>
pub async fn github_http_client(&self) -> Result<HttpClient, Error>
Builds an HttpClient for direct GitHub reads (agents / swarms /
functions / profiles) — without spawning or contacting the
ObjectiveAI API. The github_* methods talk to github.com directly
and never use the base address, so we hand it a deliberately
invalid one: any accidental API call through this client fails loudly
instead of silently hitting a real server. x_github_authorization
(from config) authenticates the GitHub requests. Built fresh per
call — these commands are short-lived and don’t memoize a client.
Sourcepub async fn resolve_mcp_timeout_ms(&self) -> Result<u64, Error>
pub async fn resolve_mcp_timeout_ms(&self) -> Result<u64, Error>
Effective MCP timeout (ms), used as BOTH the connect and per-call
timeout for every MCP client this CLI drives (its streaming
conduit). The merged (--final) api.mcp_timeout_ms config value,
or the canonical default (60000ms) when unset.
Sourcepub async fn resolve_backoff_max_elapsed_time_ms(&self) -> Result<u64, Error>
pub async fn resolve_backoff_max_elapsed_time_ms(&self) -> Result<u64, Error>
Effective backoff max-elapsed-time (ms) — the retry budget for the
CLI’s own MCP client. The merged api.backoff_max_elapsed_time_ms
config value, or the canonical default (60000ms) when unset. The
other exponential-backoff knobs keep their built-in defaults.
Sourcepub async fn resolve_backoff_max_elapsed_time_ms_opt(
&self,
) -> Result<Option<u64>, Error>
pub async fn resolve_backoff_max_elapsed_time_ms_opt( &self, ) -> Result<Option<u64>, Error>
The configured api.backoff_max_elapsed_time_ms, or None when
unset — the api spawn uses this to project the backoff env onto the
spawned server only when the user explicitly set it.
Sourcepub async fn resolve_mcp_timeout_ms_opt(&self) -> Result<Option<u64>, Error>
pub async fn resolve_mcp_timeout_ms_opt(&self) -> Result<Option<u64>, Error>
The configured api.mcp_timeout_ms, or None when unset.
The api spawn uses this to project the MCP_* timeout env onto
the spawned (machine-wide, shared) server ONLY when the user
explicitly set a timeout. Leaving it unset lets the api resolve it
itself — <OBJECTIVEAI_DIR>/.env, then its built-in default. That
fallback is behaviorally identical to passing the canonical
default in production, and it’s what the test .env (which sets
MCP_BACKOFF_*=0 to fast-fail real MCP errors instead of masking
them with retry storms) relies on: unconditionally setting the
default here would clobber that 0 on the shared api.
Sourcepub async fn viewer_client(&self) -> Result<&ViewerClient, Error>
pub async fn viewer_client(&self) -> Result<&ViewerClient, Error>
The synchronous-response viewer client, built on first use and memoized.
Address resolution mirrors Self::api_client:
viewer.address from the merged config view when set, else
the viewer spawn flow. Signature: env VIEWER_SIGNATURE,
else viewer.signature from the same view.
Sourcepub async fn db_client(&self) -> Result<&Pool, Error>
pub async fn db_client(&self) -> Result<&Pool, Error>
The db pool, connected on first use and memoized — the
pool-only view of Self::db_handle.
Sourcepub async fn db_handle(&self) -> Result<&DbHandle, Error>
pub async fn db_handle(&self) -> Result<&DbHandle, Error>
The db handle — pool plus the admin coordinates it was built
from (address, admin user/password, database name), which
crate::db::compartment needs to mint derived per-plugin
connection strings. Connected on first use (ensuring the
application database + schema exist) and memoized. Must NOT
connect eagerly: commands like db config ... and db spawn
have to work before any database exists — they’re how you
bring one up in the first place.
URL resolution: when db.address is set in the merged config
view, a remote-postgres URL is composed from the config db
parts; otherwise the db spawn flow returns the local
cluster’s lock-published postgresql:// URL (starting the
objectiveai-db supervisor if needed), whose admin coordinates
are parsed back out of that URL (our own
postgresql://postgres:{password}@{host}:{port} shape).
Sourcepub fn reset_api_client(&mut self)
pub fn reset_api_client(&mut self)
Detach this clone’s API-client cell. MUST be called after
mutating config.agent_instance_hierarchy or
config.mcp_session_id on a cloned Context: the memoized
HttpClient snapshots those into headers, so a shared cell
would either serve the base identity to this clone or poison
the base context with this clone’s identity. The viewer/db
cells stay shared — neither client carries identity.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Context
impl !UnwindSafe for Context
impl Freeze for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnsafeUnpin for Context
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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