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 community;
34pub mod coupling;
35pub mod db;
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 vfs;
56pub mod watcher;
57
58pub use auto_import::{
59    ImportSuggestion, MissingImportAnalysis, add_import, analyze_missing_imports,
60};
61pub use call_graph::{CallEdge, CalleeEntry, CallerEntry, extract_calls, get_callees, get_callers};
62pub use circular::{CircularDependency, find_circular_dependencies};
63pub use coupling::{CouplingEntry, get_change_coupling};
64pub use db::{
65    DirStats, IndexDb, NewCall, NewImport, NewSymbol, SymbolWithFile, content_hash, index_db_path,
66};
67pub use edit_transaction::{
68    ApplyError, ApplyEvidence, ApplyStatus, FileHash, RollbackEntry, WorkspaceEditTransaction,
69    apply_full_write_with_evidence, apply_full_writes_with_evidence,
70};
71pub use file_ops::{
72    DirectoryEntry, EnclosingSymbol, FileMatch, FileReadResult, PatternMatch, SmartPatternMatch,
73    TextReference, create_text_file, delete_lines, extract_word_at_position, find_files,
74    find_referencing_symbols_via_text, insert_after_symbol, insert_at_line, insert_before_symbol,
75    list_dir, read_file, replace_content, replace_lines, replace_symbol_body, search_for_pattern,
76    search_for_pattern_smart,
77};
78pub use git::{ChangedFile, DiffSymbol, DiffSymbolEntry, get_changed_files, get_diff_symbols};
79pub use import_graph::{
80    BlastRadiusEntry, DeadCodeEntry, DeadCodeEntryV2, GraphCache, ImportanceEntry, ImporterEntry,
81    extract_imports_for_file, find_dead_code, find_dead_code_v2, get_blast_radius, get_importance,
82    get_importers, resolve_module_for_file, supports_import_graph,
83};
84pub use lsp::{
85    LSP_RECIPES, LspDiagnostic, LspDiagnosticRequest, LspRecipe, LspReference, LspRenamePlan,
86    LspRenamePlanRequest, LspRequest, LspResolveTargetRequest, LspResolvedTarget, LspResourceOp,
87    LspSessionPool, LspStatus, LspTypeHierarchyRequest, LspWorkspaceEditTransaction,
88    LspWorkspaceSymbol, LspWorkspaceSymbolRequest, check_lsp_status, default_lsp_args_for_command,
89    default_lsp_command_for_extension, default_lsp_command_for_path,
90    find_referencing_symbols_via_lsp, get_diagnostics_via_lsp, get_lsp_recipe,
91    get_rename_plan_via_lsp, get_type_hierarchy_via_lsp, lsp_binary_exists,
92    resolve_symbol_target_via_lsp, search_workspace_symbols_via_lsp,
93};
94pub use project::{
95    ProjectRoot, WorkspacePackage, compute_dominant_language, detect_frameworks,
96    detect_workspace_packages,
97};
98pub use rename::{
99    RenameEdit, RenameResult, RenameScope, apply_edits, find_all_word_matches, rename_symbol,
100};
101pub mod change_signature;
102pub mod embedding_types;
103pub mod inline;
104pub mod ir;
105pub mod move_symbol;
106pub mod oxc_analysis;
107#[cfg(feature = "scip-backend")]
108pub mod scip_backend;
109#[cfg(feature = "semantic")]
110pub use embedding::{
111    EmbeddingEngine, configured_embedding_model_name, configured_embedding_runtime_info,
112    configured_embedding_runtime_preference, configured_embedding_threads,
113    embedding_model_assets_available,
114};
115pub use embedding_types::{EmbeddingIndexInfo, EmbeddingRuntimeInfo, SemanticMatch};
116#[cfg(feature = "scip-backend")]
117pub use scip_backend::ScipBackend;
118pub use scope_analysis::{
119    ReferenceKind, ScopedReference, find_scoped_references, find_scoped_references_in_file,
120};
121pub use search::{SearchResult, search_symbols_hybrid, search_symbols_hybrid_with_semantic};
122pub use symbols::{
123    IndexStats, RankedContextEntry, RankedContextResult, SymbolIndex, SymbolInfo, SymbolKind,
124    SymbolProvenance, find_symbol, find_symbol_range, get_symbols_overview, make_symbol_id,
125    parse_symbol_id, sparse_coverage_bonus_from_fields, sparse_max_bonus, sparse_threshold,
126    sparse_weighting_enabled,
127};
128pub use type_hierarchy::{TypeHierarchyResult, TypeNode, get_type_hierarchy_native};
129pub use watcher::{FileWatcher, WatcherStats};
130// Semantic IR — new types only; existing types are already re-exported above.
131pub use ir::{
132    CodeDiagnostic, DiagnosticSeverity, EditAction, EditActionKind, EditPlan, ImpactKind,
133    ImpactNode, IntelligenceSource, IrCallEdge, PreciseBackend, Relation, RelationKind,
134    RetrievalConfig, RetrievalStage, RetrievalWeights, SearchCandidate,
135};