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