aptu_core/
lib.rs

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