linesmith_core/data_context/deps.rs
1//! [`DataDep`] enumerates the data sources a segment may declare via
2//! [`Segment::data_deps`](crate::segments::Segment::data_deps).
3//!
4//! Canonical definition: `docs/specs/data-fetching.md` §Segment
5//! dependency declaration.
6
7/// Which data source on [`DataContext`](super::DataContext) a segment reads.
8///
9/// Segments return `&'static [DataDep]` from `data_deps()`. The runtime
10/// unions the declared deps across all enabled segments and only
11/// lazy-fetches sources that some segment needs.
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
13#[non_exhaustive]
14pub enum DataDep {
15 /// Parsed stdin payload. Always populated eagerly; listing is optional.
16 Status,
17 /// `~/.claude/settings.json` + overlays.
18 Settings,
19 /// `~/.claude.json` per-user state.
20 ClaudeJson,
21 /// JSONL transcripts under `~/.claude/projects/**`.
22 Jsonl,
23 /// OAuth `/api/oauth/usage` endpoint + cache.
24 Usage,
25 /// macOS Keychain / `.credentials.json` — not plugin-accessible
26 /// (reserved in `plugin-api.md` §@data_deps header syntax).
27 Credentials,
28 /// `~/.claude/sessions/{pid}.json` live process directory.
29 Sessions,
30 /// Git repo state via `gix`.
31 Git,
32}
33
34impl DataDep {
35 /// The lowercase-token name used in the plugin-api `@data_deps`
36 /// header (`plugin-api.md` §@data_deps header syntax) and in log /
37 /// doctor output. Single source of truth for the wire name.
38 #[must_use]
39 pub fn as_str(&self) -> &'static str {
40 match self {
41 Self::Status => "status",
42 Self::Settings => "settings",
43 Self::ClaudeJson => "claude_json",
44 Self::Jsonl => "jsonl",
45 Self::Usage => "usage",
46 Self::Credentials => "credentials",
47 Self::Sessions => "sessions",
48 Self::Git => "git",
49 }
50 }
51}
52
53impl std::fmt::Display for DataDep {
54 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55 f.write_str(self.as_str())
56 }
57}