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//!     milestone: None,
38//!     comments: vec![],
39//!     url: "https://github.com/block/goose/issues/123".to_string(),
40//!     repo_context: vec![],
41//!     repo_tree: vec![],
42//!     available_labels: vec![],
43//!     available_milestones: vec![],
44//!     viewer_permission: None,
45//! };
46//!
47//! // Analyze with AI
48//! let ai_response = client.analyze_issue(&issue).await?;
49//! println!("Summary: {}", ai_response.triage.summary);
50//! # Ok(())
51//! # }
52//! ```
53//!
54//! ## Modules
55//!
56//! - [`ai`] - AI integration (`OpenRouter` API, triage analysis)
57//! - [`config`] - Configuration loading and paths
58//! - [`error`] - Error types
59//! - [`github`] - GitHub API (auth, issues, GraphQL)
60//! - [`history`] - Contribution history tracking
61//! - [`repos`] - Curated repository list
62
63// ============================================================================
64// Authentication
65// ============================================================================
66
67pub use auth::TokenProvider;
68
69// ============================================================================
70// Error Handling
71// ============================================================================
72
73pub use error::AptuError;
74
75/// Convenience Result type for Aptu operations.
76///
77/// This is equivalent to `std::result::Result<T, AptuError>`.
78pub type Result<T> = std::result::Result<T, AptuError>;
79
80// ============================================================================
81// Configuration
82// ============================================================================
83
84pub use config::{
85    AiConfig, AppConfig, CacheConfig, GitHubConfig, UiConfig, UserConfig, config_dir,
86    config_file_path, data_dir, load_config,
87};
88
89// ============================================================================
90// Caching
91// ============================================================================
92
93pub use cache::CacheEntry;
94
95// ============================================================================
96// AI Triage
97// ============================================================================
98
99pub use ai::types::{
100    IssueComment, IssueDetails, PrDetails, PrFile, PrReviewResponse, ReviewEvent, TriageResponse,
101};
102pub use ai::{
103    AiClient, AiModel, ModelInfo, ModelProvider, ProviderConfig, all_providers, get_provider,
104};
105
106// ============================================================================
107// GitHub Integration
108// ============================================================================
109
110pub use github::auth::TokenSource;
111pub use github::graphql::IssueNode;
112pub use github::ratelimit::{RateLimitStatus, check_rate_limit};
113
114// ============================================================================
115// AI Integration
116// ============================================================================
117
118pub use ai::types::CreditsStatus;
119
120// ============================================================================
121// History Tracking
122// ============================================================================
123
124pub use history::{Contribution, ContributionStatus, HistoryData};
125
126// ============================================================================
127// Repository Discovery
128// ============================================================================
129
130pub use repos::{CuratedRepo, RepoFilter};
131
132// ============================================================================
133// Triage Detection
134// ============================================================================
135
136pub use triage::{APTU_SIGNATURE, TriageStatus, check_already_triaged};
137
138// ============================================================================
139// Retry Logic
140// ============================================================================
141
142pub use retry::{is_retryable_anyhow, is_retryable_http, retry_backoff};
143
144// ============================================================================
145// Utilities
146// ============================================================================
147
148pub use utils::{
149    format_relative_time, parse_and_format_relative_time, truncate, truncate_with_suffix,
150};
151
152// ============================================================================
153// Platform-Agnostic Facade
154// ============================================================================
155
156pub use facade::{
157    add_custom_repo, analyze_issue, fetch_issues, list_curated_repos, list_repos, post_pr_review,
158    remove_custom_repo, review_pr,
159};
160
161// ============================================================================
162// Modules
163// ============================================================================
164
165pub mod ai;
166pub mod auth;
167pub mod cache;
168pub mod config;
169pub mod error;
170pub mod facade;
171pub mod github;
172pub mod history;
173pub mod repos;
174pub mod retry;
175pub mod triage;
176pub mod utils;