Skip to main content

ctx/
lib.rs

1//! ctx - Code intelligence library for AI-assisted development.
2//!
3//! This library provides tools for understanding codebases and generating
4//! context for Large Language Models (LLMs). It includes:
5//!
6//! - **Code Indexing**: Parse and index source code with symbol extraction
7//! - **Semantic Search**: Find relevant code using embeddings
8//! - **Call Graph Analysis**: Understand code relationships and impact
9//! - **Smart Context Selection**: Intelligently select files for LLM context
10//! - **Diff-Aware Context**: Generate context focused on code changes
11//! - **Token Management**: Count and budget tokens for LLM context windows
12//!
13//! # Quick Start
14//!
15//! ```ignore
16//! use ctx::{index::Indexer, db::Database, smart::{smart_context, SmartConfig}};
17//! use ctx::embeddings::LocalProvider;
18//!
19//! // Index a codebase
20//! let mut indexer = Indexer::new("./my-project", false)?;
21//! indexer.index()?;
22//!
23//! // Open the database
24//! let db = index::open_database("./my-project")?;
25//!
26//! // Generate smart context for a task
27//! let provider = LocalProvider::new()?;
28//! let config = SmartConfig::default();
29//! let context = smart_context(&db, &analytics, &provider, "add caching", config)?;
30//! ```
31//!
32//! # Feature Flags
33//!
34//! - `mcp` - Enable Model Context Protocol server support
35
36// Core modules
37pub mod analytics;
38pub mod db;
39pub mod embeddings;
40pub mod error;
41pub mod index;
42pub mod parser;
43pub mod tokens;
44pub mod walker;
45
46// Context generation
47pub mod diff;
48pub mod smart;
49
50// Output formatting
51pub mod formatter;
52pub mod output;
53pub mod tree;
54
55// Utilities
56pub mod audit;
57pub mod utils;
58
59// Internal modules (not part of public API)
60pub(crate) mod default_ignores;
61
62// MCP server support (feature-gated)
63#[cfg(feature = "mcp")]
64pub mod mcp;
65
66// Re-export commonly used types at the crate root
67pub use error::{CtxError, Result};
68
69/// Prelude module for convenient imports.
70///
71/// ```ignore
72/// use ctx::prelude::*;
73/// ```
74pub mod prelude {
75    pub use crate::analytics::Analytics;
76    pub use crate::db::{Database, Edge, EdgeKind, FileRecord, ParseResult, Symbol, SymbolKind};
77    pub use crate::diff::{diff_context, DiffConfig, DiffContext};
78    pub use crate::embeddings::{Embedding, EmbeddingProvider, LocalProvider};
79    pub use crate::error::{CtxError, Result};
80    pub use crate::index::{open_database, IndexResult, Indexer};
81    pub use crate::parser::{CodeParser, Language};
82    pub use crate::smart::{smart_context, FileSelection, SmartConfig, SmartContext};
83    pub use crate::tokens::{count_tokens, Encoding, HasTokenCount, TokenCount};
84    pub use crate::walker::{discover_files, FileEntry, WalkerConfig};
85}