Skip to main content

lean_ctx/core/providers/
provider_trait.rs

1use super::{ProviderItem, ProviderResult};
2
3/// Plugin-ready trait for external context providers.
4///
5/// A ContextProvider connects LeanCTX to external data sources (issue trackers,
6/// CI systems, documentation, etc.) and returns structured context that flows
7/// through the standard compression and IR pipeline.
8///
9/// The existing GitLab provider implements this interface pattern.
10/// Future plugins will register implementations dynamically via the provider
11/// framework contract.
12pub trait ContextProvider: Send + Sync {
13    /// Unique identifier for this provider (e.g. "gitlab", "github", "jira").
14    fn id(&self) -> &str;
15
16    /// Human-readable display name.
17    fn display_name(&self) -> &str;
18
19    /// Returns the actions this provider supports (e.g. "issues", "mrs", "pipelines").
20    fn supported_actions(&self) -> &[&str];
21
22    /// Execute a provider action and return structured results.
23    fn execute(&self, action: &str, params: &ProviderParams) -> Result<ProviderResult, String>;
24
25    /// TTL for caching results from this provider (in seconds).
26    fn cache_ttl_secs(&self) -> u64 {
27        120
28    }
29
30    /// Whether this provider requires authentication.
31    fn requires_auth(&self) -> bool {
32        true
33    }
34
35    /// Check if the provider is configured and ready to serve requests.
36    fn is_available(&self) -> bool;
37}
38
39/// Parameters passed to a provider action.
40#[derive(Debug, Clone, Default)]
41pub struct ProviderParams {
42    pub project: Option<String>,
43    pub state: Option<String>,
44    pub limit: Option<usize>,
45    pub query: Option<String>,
46    pub id: Option<String>,
47}
48
49/// A context packet produced by a provider, ready for the IR pipeline.
50#[derive(Debug, Clone)]
51pub struct ContextPacket {
52    pub provider_id: String,
53    pub action: String,
54    pub items: Vec<ProviderItem>,
55    pub token_count_raw: usize,
56    pub token_count_compressed: usize,
57    pub cache_hit: bool,
58}