aptu_core/lib.rs
1// SPDX-License-Identifier: Apache-2.0
2
3//! # Aptu Core
4//!
5//! Core library for the Aptu CLI - AI-powered OSS issue triage.
6//!
7//! This crate provides reusable components for:
8//! - GitHub API integration (authentication, issues, GraphQL)
9//! - AI-assisted issue triage via `OpenRouter`
10//! - Configuration management
11//! - Contribution history tracking
12//! - Curated repository discovery
13//!
14//! ## Quick Start
15//!
16//! ```rust,no_run
17//! use aptu_core::{load_config, OpenRouterClient, IssueDetails};
18//! use anyhow::Result;
19//!
20//! # async fn example() -> Result<()> {
21//! // Load configuration
22//! let config = load_config()?;
23//!
24//! // Create AI client (reuse for multiple requests)
25//! let client = OpenRouterClient::new(&config.ai)?;
26//!
27//! // Create issue details
28//! let issue = IssueDetails {
29//! owner: "block".to_string(),
30//! repo: "goose".to_string(),
31//! number: 123,
32//! title: "Example issue".to_string(),
33//! body: "Issue description...".to_string(),
34//! labels: vec![],
35//! comments: vec![],
36//! url: "https://github.com/block/goose/issues/123".to_string(),
37//! repo_context: vec![],
38//! repo_tree: vec![],
39//! };
40//!
41//! // Analyze with AI
42//! let ai_response = client.analyze_issue(&issue).await?;
43//! println!("Summary: {}", ai_response.triage.summary);
44//! # Ok(())
45//! # }
46//! ```
47//!
48//! ## Modules
49//!
50//! - [`ai`] - AI integration (`OpenRouter` API, triage analysis)
51//! - [`config`] - Configuration loading and paths
52//! - [`error`] - Error types
53//! - [`github`] - GitHub API (auth, issues, GraphQL)
54//! - [`history`] - Contribution history tracking
55//! - [`repos`] - Curated repository list
56
57// ============================================================================
58// Authentication
59// ============================================================================
60
61pub use auth::TokenProvider;
62
63// ============================================================================
64// Error Handling
65// ============================================================================
66
67pub use error::AptuError;
68
69/// Convenience Result type for Aptu operations.
70///
71/// This is equivalent to `std::result::Result<T, AptuError>`.
72pub type Result<T> = std::result::Result<T, AptuError>;
73
74// ============================================================================
75// Configuration
76// ============================================================================
77
78pub use config::{
79 AiConfig, AppConfig, CacheConfig, GitHubConfig, UiConfig, UserConfig, config_dir,
80 config_file_path, data_dir, load_config,
81};
82
83// ============================================================================
84// Caching
85// ============================================================================
86
87pub use cache::CacheEntry;
88
89// ============================================================================
90// AI Triage
91// ============================================================================
92
93pub use ai::types::{IssueComment, IssueDetails, TriageResponse};
94pub use ai::{AiModel, ModelProvider, OpenRouterClient};
95
96// ============================================================================
97// GitHub Integration
98// ============================================================================
99
100pub use github::auth::TokenSource;
101pub use github::graphql::IssueNode;
102
103// ============================================================================
104// History Tracking
105// ============================================================================
106
107pub use history::{Contribution, ContributionStatus, HistoryData};
108
109// ============================================================================
110// Repository Discovery
111// ============================================================================
112
113pub use repos::CuratedRepo;
114
115// ============================================================================
116// Triage Detection
117// ============================================================================
118
119pub use triage::{APTU_SIGNATURE, TriageStatus, check_already_triaged};
120
121// ============================================================================
122// Retry Logic
123// ============================================================================
124
125pub use retry::{is_retryable_anyhow, is_retryable_http, retry_backoff};
126
127// ============================================================================
128// Utilities
129// ============================================================================
130
131pub use utils::{
132 format_relative_time, parse_and_format_relative_time, truncate, truncate_with_suffix,
133};
134
135// ============================================================================
136// Platform-Agnostic Facade
137// ============================================================================
138
139pub use facade::{analyze_issue, fetch_issues};
140
141// ============================================================================
142// Modules
143// ============================================================================
144
145pub mod ai;
146pub mod auth;
147pub mod cache;
148pub mod config;
149pub mod error;
150pub mod facade;
151pub mod github;
152pub mod history;
153pub mod repos;
154pub mod retry;
155pub mod triage;
156pub mod utils;