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