Skip to main content

codelens_engine/
lib.rs

1//! # codelens-engine
2//!
3//! Read/mutate/index primitives for CodeLens. **Internal API.**
4//!
5//! Mutation primitives — every function that writes to the project
6//! tree (`file_ops::writer::*`, `auto_import::add_import`,
7//! `edit_transaction::apply_full_write_with_evidence`,
8//! `lsp::LspWorkspaceEditTransaction::apply`, `rename::apply_rename`) —
9//! **do NOT enforce ADR-0009 role gates, audit sinks, or cache
10//! invalidation contracts**. Those guarantees live exclusively in
11//! `codelens-mcp`'s dispatch pipeline (`dispatch::role_gate`,
12//! `dispatch::session::apply_post_mutation`).
13//!
14//! Consumers — including third-party crates that depend on
15//! `codelens-engine` — **MUST** route mutations through
16//! `codelens-mcp` (HTTP / stdio MCP protocol, or in-process
17//! `dispatch_tool`) so the trust substrate can audit, gate, and
18//! invalidate consistently. Calling mutation primitives directly is
19//! supported only inside the workspace (mcp + engine tests + benches);
20//! anything else is at the caller's own risk and will silently bypass
21//! the project's principals.toml configuration.
22//!
23//! Read primitives (`find_*`, `get_*`, `search_*`, `LspSessionPool`)
24//! are safe to call directly — they have no side effects on disk or
25//! audit state.
26//!
27//! See ADR-0009 (`docs/adr/ADR-0009-mutation-trust-substrate.md`)
28//! for the full contract this crate participates in.
29
30pub mod auto_import;
31pub mod call_graph;
32pub mod circular;
33pub mod coupling;
34pub mod db;
35pub mod dead_code;
36pub mod edit_transaction;
37#[cfg(feature = "semantic")]
38pub mod embedding;
39pub mod embedding_store;
40pub mod file_ops;
41pub mod git;
42pub mod import_graph;
43pub(crate) mod lang_config;
44pub mod lang_registry;
45pub mod lsp;
46pub mod memory;
47pub mod phantom_modules;
48pub mod project;
49pub mod redundant_definitions;
50pub mod rename;
51pub mod scope_analysis;
52pub mod search;
53pub mod symbols;
54pub mod type_hierarchy;
55pub mod unicode;
56pub mod vfs;
57pub mod watcher;
58
59pub use auto_import::{
60    ImportSuggestion, MissingImportAnalysis, add_import, analyze_missing_imports,
61};
62pub use call_graph::{CallEdge, CalleeEntry, CallerEntry, extract_calls, get_callees, get_callers};
63pub use circular::{CircularDependency, find_circular_dependencies};
64pub use coupling::{CouplingEntry, get_change_coupling};
65pub use db::{
66    DirStats, IndexDb, NewCall, NewImport, NewSymbol, SymbolWithFile, content_hash, index_db_path,
67};
68pub use dead_code::{DeadCodeEntryV2, find_dead_code, find_dead_code_v2};
69pub use edit_transaction::{
70    ApplyError, ApplyEvidence, ApplyStatus, FileHash, RollbackEntry, WorkspaceEditTransaction,
71    apply_full_write_with_evidence, apply_full_writes_with_evidence,
72};
73pub use file_ops::{
74    DirectoryEntry, EnclosingSymbol, FileMatch, FileReadResult, PatternMatch, SmartPatternMatch,
75    TextReference, create_text_file, delete_lines, extract_word_at_position, find_files,
76    find_referencing_symbols_via_text, insert_after_symbol, insert_at_line, insert_before_symbol,
77    list_dir, read_file, replace_content, replace_lines, replace_symbol_body, search_for_pattern,
78    search_for_pattern_smart,
79};
80pub use git::{ChangedFile, DiffSymbol, DiffSymbolEntry, get_changed_files, get_diff_symbols};
81pub use import_graph::{
82    BlastRadiusEntry, DeadCodeEntry, GraphCache, ImportanceEntry, ImporterEntry,
83    extract_imports_for_file, get_blast_radius, get_importance, get_importers,
84    resolve_module_for_file, supports_import_graph,
85};
86pub use lsp::{
87    LSP_RECIPES, LspDiagnostic, LspDiagnosticRequest, LspRecipe, LspReference, LspRenamePlan,
88    LspRenamePlanRequest, LspRequest, LspResolveTargetRequest, LspResolvedTarget, LspResourceOp,
89    LspSessionPool, LspStatus, LspTypeHierarchyRequest, LspWorkspaceEditTransaction,
90    LspWorkspaceSymbol, LspWorkspaceSymbolRequest, check_lsp_status, default_lsp_args_for_command,
91    default_lsp_command_for_extension, default_lsp_command_for_path,
92    find_referencing_symbols_via_lsp, get_diagnostics_via_lsp, get_lsp_recipe,
93    get_rename_plan_via_lsp, get_type_hierarchy_via_lsp, lsp_binary_exists,
94    lsp_binary_exists_with_hint, resolve_lsp_binary_with_hint, resolve_symbol_target_via_lsp,
95    search_workspace_symbols_via_lsp,
96};
97pub use project::{
98    ProjectRoot, WorkspacePackage, compute_dominant_language, detect_frameworks,
99    detect_workspace_packages,
100};
101pub use rename::{
102    RenameEdit, RenameResult, RenameScope, apply_edits, find_all_word_matches, rename_symbol,
103};
104pub mod change_signature;
105pub mod embedding_types;
106pub mod inline;
107pub mod ir;
108pub mod move_symbol;
109pub mod oxc_analysis;
110#[cfg(feature = "scip-backend")]
111pub mod scip_backend;
112#[cfg(test)]
113pub(crate) mod test_helpers;
114#[cfg(feature = "semantic")]
115pub use embedding::{
116    EmbeddingEngine, configured_embedding_model_name, configured_embedding_runtime_info,
117    configured_embedding_runtime_preference, configured_embedding_threads,
118    embedding_model_assets_available,
119};
120pub use embedding_types::{EmbeddingIndexInfo, EmbeddingRuntimeInfo, SemanticMatch};
121pub use memory::{
122    AuditRecorder, MemoryAuditEvent, MemoryFrontmatter, MemoryLocation, MemoryMetadata,
123    MemoryPolicy, MemoryTier, NullRecorder, archive_memory, archive_memory_rec, delete_memory,
124    delete_memory_tiered, delete_memory_tiered_rec, global_memory_dir, list_all_memory_names,
125    list_archived, list_memory_names, parse_frontmatter, read_memory, read_memory_from_tier,
126    read_memory_with_metadata, read_policy, rename_memory, resolve_memory_path,
127    resolve_memory_tier, restore_archived, restore_archived_rec, strip_frontmatter, write_memory,
128    write_memory_tiered, write_memory_tiered_rec,
129};
130#[cfg(feature = "scip-backend")]
131pub use scip_backend::ScipBackend;
132pub use scope_analysis::{
133    ReferenceKind, ScopedReference, find_scoped_references, find_scoped_references_in_file,
134};
135pub use search::{SearchResult, search_symbols_hybrid, search_symbols_hybrid_with_semantic};
136pub use symbols::{
137    IndexStats, RankedContextEntry, RankedContextResult, SymbolIndex, SymbolInfo, SymbolKind,
138    SymbolProvenance, find_symbol, find_symbol_range, get_symbols_overview, make_symbol_id,
139    parse_symbol_id, sparse_coverage_bonus_from_fields, sparse_max_bonus, sparse_threshold,
140    sparse_weighting_enabled,
141};
142pub use type_hierarchy::{TypeHierarchyResult, TypeNode, get_type_hierarchy_native};
143pub use watcher::{FileWatcher, WatcherStats};
144// Semantic IR — new types only; existing types are already re-exported above.
145pub use ir::{
146    CodeDiagnostic, DiagnosticSeverity, EditAction, EditActionKind, EditPlan, ImpactKind,
147    ImpactNode, IntelligenceSource, IrCallEdge, PreciseBackend, Relation, RelationKind,
148    RetrievalConfig, RetrievalStage, RetrievalWeights, SearchCandidate,
149};