Skip to main content

pi/
lib.rs

1//! Pi - High-performance AI coding agent CLI
2//!
3//! This library provides the core functionality for the Pi CLI tool,
4//! a Rust port of pi-mono (TypeScript) with emphasis on:
5//! - Performance: Sub-100ms startup, smooth TUI at 60fps
6//! - Reliability: No panics in normal operation
7//! - Efficiency: Single binary, minimal dependencies
8//!
9//! ## Public API policy
10//!
11//! The `pi` crate is primarily the implementation crate for the `pi` CLI binary.
12//! External consumers should treat non-`sdk` modules/types as **unstable**
13//! and subject to change. Use [`sdk`] as the stable library-facing surface.
14//!
15//! Currently intended stable exports:
16//! - [`Error`]
17//! - [`PiResult`]
18//! - [`sdk`] module
19
20#![forbid(unsafe_code)]
21#![allow(dead_code, clippy::unused_async, unused_attributes)]
22#![cfg_attr(
23    test,
24    allow(
25        unused_variables,
26        clippy::assertions_on_constants,
27        clippy::match_same_arms,
28        clippy::uninlined_format_args,
29        clippy::missing_const_for_fn,
30        clippy::collapsible_if
31    )
32)]
33// Allow pedantic lints during early development - can tighten later
34#![allow(
35    clippy::must_use_candidate,
36    clippy::doc_markdown,
37    clippy::missing_errors_doc,
38    clippy::missing_panics_doc,
39    clippy::module_name_repetitions,
40    clippy::similar_names,
41    clippy::wildcard_imports
42)]
43
44// Allow in-crate tests that include integration test helpers to resolve `pi::...`
45// paths the same way integration tests do.
46extern crate self as pi;
47
48// Gap H: jemalloc allocator for allocation-heavy paths.
49// Declared in the library so all project binaries/tests share allocator behavior.
50#[cfg(all(feature = "jemalloc", not(target_env = "msvc")))]
51#[global_allocator]
52static GLOBAL_ALLOCATOR: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
53
54pub mod acp;
55pub mod agent;
56pub mod agent_cx;
57pub mod app;
58pub mod auth;
59pub mod autocomplete;
60pub mod buffer_shim;
61pub mod cli;
62pub mod compaction;
63pub mod compaction_worker;
64pub mod config;
65pub mod conformance;
66pub mod conformance_shapes;
67pub mod connectors;
68pub mod crypto_shim;
69pub mod doctor;
70pub mod error;
71pub mod error_hints;
72pub mod extension_conformance_matrix;
73pub mod extension_dispatcher;
74pub mod extension_events;
75pub mod extension_inclusion;
76pub mod extension_index;
77pub mod extension_license;
78pub mod extension_popularity;
79pub mod extension_preflight;
80pub mod extension_replay;
81pub mod extension_scoring;
82pub mod extension_tools;
83pub mod extension_validation;
84pub mod extensions;
85pub mod extensions_js;
86pub mod flake_classifier;
87pub mod hostcall_amac;
88pub mod hostcall_io_uring_lane;
89pub mod hostcall_queue;
90pub mod hostcall_rewrite;
91pub mod hostcall_s3_fifo;
92pub mod hostcall_superinstructions;
93pub mod hostcall_trace_jit;
94pub mod http;
95pub mod http_shim;
96pub mod interactive;
97pub mod keybindings;
98pub mod migrations;
99pub mod model;
100pub mod model_selector;
101pub mod models;
102pub mod package_manager;
103pub mod perf_build;
104pub mod permissions;
105#[cfg(feature = "wasm-host")]
106pub mod pi_wasm;
107pub mod platform;
108pub mod provider;
109pub mod provider_metadata;
110pub mod providers;
111pub mod resources;
112pub mod rpc;
113pub mod scheduler;
114pub mod sdk;
115pub mod session;
116pub mod session_index;
117pub mod session_metrics;
118pub mod session_picker;
119#[cfg(feature = "sqlite-sessions")]
120pub mod session_sqlite;
121pub mod session_store_v2;
122pub mod sse;
123pub mod terminal_images;
124pub mod theme;
125pub mod tools;
126pub mod tui;
127pub mod vcr;
128pub mod version_check;
129
130pub use error::{Error, Result as PiResult};
131pub use extension_dispatcher::ExtensionDispatcher;
132
133// Conditional re-exports for fuzz harnesses.
134// These expose internal parsing functions that are normally private,
135// gated behind the `fuzzing` feature so they do not appear in the
136// public API during normal builds.
137#[cfg(feature = "fuzzing")]
138pub mod fuzz_exports {
139    //! Re-exports of internal parsing/deserialization functions for
140    //! `cargo-fuzz` / `libFuzzer` harnesses.
141    //!
142    //! Enabled only when the `fuzzing` Cargo feature is active.
143    //! The `fuzz/Cargo.toml` depends on this crate with
144    //! `features = ["fuzzing"]`.
145
146    pub use crate::config::Config;
147    pub use crate::model::{
148        AssistantMessage, ContentBlock, Message, StreamEvent, TextContent, ThinkingContent,
149        ToolCall, ToolResultMessage, Usage, UserContent, UserMessage,
150    };
151    pub use crate::session::{Session, SessionEntry, SessionHeader, SessionMessage};
152    pub use crate::sse::{SseEvent, SseParser};
153    pub use crate::tools::{fuzz_normalize_dot_segments, fuzz_resolve_path};
154
155    // Provider stream processor wrappers for coverage-guided fuzzing.
156    pub use crate::providers::anthropic::fuzz::Processor as AnthropicProcessor;
157    pub use crate::providers::azure::fuzz::Processor as AzureProcessor;
158    pub use crate::providers::cohere::fuzz::Processor as CohereProcessor;
159    pub use crate::providers::gemini::fuzz::Processor as GeminiProcessor;
160    pub use crate::providers::openai::fuzz::Processor as OpenAIProcessor;
161    pub use crate::providers::openai_responses::fuzz::Processor as OpenAIResponsesProcessor;
162    pub use crate::providers::vertex::fuzz::Processor as VertexProcessor;
163}