Skip to main content

Module data_context

Module data_context 

Source
Expand description

Shared data-access context threaded through every segment’s render call.

DataContext owns the eagerly-parsed stdin payload (StatusContext at ctx.status) plus lazy OnceCell accessors for every other source (settings, ~/.claude.json, JSONL transcripts, OAuth usage, credentials, live sessions, git).

This module ships the v0.1 skeleton: the struct shape, the accessor surface, and stub NotImplemented errors. Real source implementations arrive with their owning epics (lsm-y6m for usage, lsm-8jl for git, etc.). Plugin scripts see a uniform { kind: "error", error: "NotImplemented" } shape until those land.

Canonical definition: docs/specs/data-fetching.md §DataContext.

Re-exports§

pub use credentials::CredentialSource;
pub use credentials::Credentials;
pub use deps::DataDep;
pub use error::ClaudeJsonError;
pub use error::CredentialError;
pub use error::GitError;
pub use error::JsonlError;
pub use error::SessionError;
pub use error::SettingsError;
pub use error::UsageError;
pub use git::DirtyCounts;
pub use git::DirtyState;
pub use git::GitContext;
pub use git::Head;
pub use git::RepoKind;
pub use git::UpstreamState;
pub use jsonl::FiveHourBlock;
pub use jsonl::JsonlAggregate;
pub use jsonl::TokenCounts;
pub use usage::EndpointUsage;
pub use usage::ExtraUsage;
pub use usage::FiveHourWindow;
pub use usage::JsonlUsage;
pub use usage::SevenDayWindow;
pub use usage::UsageApiResponse;
pub use usage::UsageBucket;
pub use usage::UsageData;

Modules§

cache
Disk-backed OAuth usage cache + lock file.
cascade
OAuth usage fallback cascade.
credentials
OAuth credential resolution for the OAuth /api/oauth/usage endpoint. Reads the access token from macOS Keychain (primary + multi-account fallback) or from a file cascade ($CLAUDE_CONFIG_DIR, XDG, ~/.claude/).
deps
DataDep enumerates the data sources a segment may declare via Segment::data_deps.
error
Error types for lazy DataContext sources.
fetcher
OAuth /api/oauth/usage HTTP client.
git
Git repository inspection state via gix.
jsonl
JSONL transcript aggregator — terminal fallback for the rate-limit data pipeline.
usage
OAuth /api/oauth/usage response + internal usage-data types.
xdg
Single source of truth for the linesmith XDG cascade.

Structs§

ClaudeJson
Parsed ~/.claude.json per-user state. Stub.
DataContext
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.
LiveSessions
Snapshot of ~/.claude/sessions/{pid}.json entries. Stub.
Settings
Parsed ~/.claude/settings.json + overlays. Stub.