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