pub struct DataContext {
pub status: StatusContext,
/* private fields */
}Expand description
Bundle of every source a segment may read during a single render
invocation. status is populated eagerly from the stdin payload;
all other sources lazy-init on first access and cache their
Result (including errors) for the lifetime of this context.
Accessors return Arc<Result<T, E>> so segments can hold the data
across calls without tying lifetimes to &self. The Result shape
preserves failure info for the plugin runtime’s tagged-map mirror
(#{ kind: "ok"|"error", ... }) per plugin-api.md §ctx shape.
Fields§
§status: StatusContextEagerly-parsed stdin payload.
Implementations§
Source§impl DataContext
impl DataContext
Sourcepub fn new(status: StatusContext) -> Self
pub fn new(status: StatusContext) -> Self
Wrap a parsed StatusContext with lazy accessors for every
other data source. cwd is None, so Self::git returns
Ok(None) unless the caller switches to Self::with_cwd.
Sourcepub fn with_cwd(status: StatusContext, cwd: Option<PathBuf>) -> Self
pub fn with_cwd(status: StatusContext, cwd: Option<PathBuf>) -> Self
Construct with an explicit cwd that seeds gix discovery. The
CLI passes std::env::current_dir().ok(); a fixture path
pins discovery to a known repo.
Sourcepub fn settings(&self) -> Arc<Result<Settings, SettingsError>>
pub fn settings(&self) -> Arc<Result<Settings, SettingsError>>
~/.claude/settings.json + overlays.
Sourcepub fn claude_json(&self) -> Arc<Result<ClaudeJson, ClaudeJsonError>>
pub fn claude_json(&self) -> Arc<Result<ClaudeJson, ClaudeJsonError>>
~/.claude.json per-user state.
Sourcepub fn jsonl(&self) -> Arc<Result<JsonlAggregate, JsonlError>>
pub fn jsonl(&self) -> Arc<Result<JsonlAggregate, JsonlError>>
Aggregated JSONL transcript state.
Invokes jsonl::aggregate_jsonl on first call and memoizes
the Arc<Result<...>> for the process lifetime. Scans the
project-root cascade once per process.
Sourcepub fn usage(&self) -> Arc<Result<UsageData, UsageError>>
pub fn usage(&self) -> Arc<Result<UsageData, UsageError>>
OAuth usage endpoint data (shared across rate-limit segments).
Runs the full fallback cascade on first call and memoizes the
result for the process lifetime. See
cascade::resolve_usage for the step order and
docs/specs/data-fetching.md §OAuth fallback cascade for
rationale. A fresh disk-cache hit short-circuits before any
Keychain subprocess or HTTP call.
Sourcepub fn credentials(&self) -> Arc<Result<Credentials, CredentialError>>
pub fn credentials(&self) -> Arc<Result<Credentials, CredentialError>>
macOS Keychain / .credentials.json OAuth credentials.
Invokes credentials::resolve_credentials on first call and
memoizes the Arc<Result<...>> for the process lifetime per
docs/specs/credentials.md §Non-functional. On macOS this may
trigger a security subprocess and a one-time Keychain access
prompt; on Linux/Windows it’s a file-cascade read.
Sourcepub fn preseed_usage(
&self,
result: Result<UsageData, UsageError>,
) -> Result<(), Arc<Result<UsageData, UsageError>>>
pub fn preseed_usage( &self, result: Result<UsageData, UsageError>, ) -> Result<(), Arc<Result<UsageData, UsageError>>>
Pre-populate the usage result so Self::usage returns it
without running the fallback cascade (which would otherwise
touch the real Keychain, network, and JSONL transcripts).
Mirrors OnceCell::set’s semantics: returns Err with the
already-stored value if the cell was already populated by a
prior ctx.usage() read.
Sourcepub fn sessions(&self) -> Arc<Result<LiveSessions, SessionError>>
pub fn sessions(&self) -> Arc<Result<LiveSessions, SessionError>>
~/.claude/sessions/{pid}.json live process snapshot.
Sourcepub fn git(&self) -> Arc<Result<Option<GitContext>, GitError>>
pub fn git(&self) -> Arc<Result<Option<GitContext>, GitError>>
Git repo inspection via gix. Ok(None) means cwd is not
inside a git repo; Ok(Some(_)) covers main checkouts, linked
worktrees, and bare repos; Err is a gix failure.
Runs git::resolve_repo against Self::cwd on first call
and memoizes the result. An unset cwd resolves to Ok(None).
On the first Err, writes the cause to stderr with the
linesmith: prefix so every consumer inherits the log without
having to re-emit — the docs/specs/git-segments.md §Data
dependency contract that each segment’s render path relies on.
Sourcepub fn preseed_git(
&self,
result: Result<Option<GitContext>, GitError>,
) -> Result<(), Arc<Result<Option<GitContext>, GitError>>>
pub fn preseed_git( &self, result: Result<Option<GitContext>, GitError>, ) -> Result<(), Arc<Result<Option<GitContext>, GitError>>>
Pre-populate the git result so Self::git returns it
without running gix::discover (which would otherwise touch
the real filesystem). Mirrors OnceCell::set’s semantics:
returns Err with the already-stored value if the cell was
already populated by a prior ctx.git() read.