codelens-engine 1.13.34

Harness-native Rust MCP server for code intelligence — hybrid retrieval, mutation-gated workflows, and a token-lean response contract tuned for frontier agent models (Claude Fable-class)
Documentation
//! # codelens-engine
//!
//! Read/mutate/index primitives for CodeLens. **Internal API.**
//!
//! Mutation primitives — every function that writes to the project
//! tree (`file_ops::writer::*`, `auto_import::add_import`,
//! `edit_transaction::apply_full_write_with_evidence`,
//! `lsp::LspWorkspaceEditTransaction::apply`, `rename::apply_rename`) —
//! **do NOT enforce ADR-0009 role gates, audit sinks, or cache
//! invalidation contracts**. Those guarantees live exclusively in
//! `codelens-mcp`'s dispatch pipeline (`dispatch::role_gate`,
//! `dispatch::session::apply_post_mutation`).
//!
//! Consumers — including third-party crates that depend on
//! `codelens-engine` — **MUST** route mutations through
//! `codelens-mcp` (HTTP / stdio MCP protocol, or in-process
//! `dispatch_tool`) so the trust substrate can audit, gate, and
//! invalidate consistently. Calling mutation primitives directly is
//! supported only inside the workspace (mcp + engine tests + benches);
//! anything else is at the caller's own risk and will silently bypass
//! the project's principals.toml configuration.
//!
//! Read primitives (`find_*`, `get_*`, `search_*`, `LspSessionPool`)
//! are safe to call directly — they have no side effects on disk or
//! audit state.
//!
//! See ADR-0009 (`docs/adr/ADR-0009-mutation-trust-substrate.md`)
//! for the full contract this crate participates in.

pub mod auto_import;
pub mod call_graph;
pub mod circular;
pub mod coupling;
pub mod db;
pub mod dead_code;
pub mod edit_transaction;
#[cfg(feature = "semantic")]
pub mod embedding;
pub mod embedding_store;
pub mod file_ops;
pub mod git;
pub mod import_graph;
pub(crate) mod lang_config;
pub mod lang_registry;
pub mod lsp;
pub mod memory;
pub mod phantom_modules;
pub mod project;
pub mod redundant_definitions;
pub mod rename;
pub mod scope_analysis;
pub mod search;
pub mod symbols;
pub mod type_hierarchy;
pub mod unicode;
pub mod vfs;
pub mod watcher;

pub use auto_import::{
    ImportSuggestion, MissingImportAnalysis, add_import, analyze_missing_imports,
};
pub use call_graph::{CallEdge, CalleeEntry, CallerEntry, extract_calls, get_callees, get_callers};
pub use circular::{CircularDependency, find_circular_dependencies};
pub use coupling::{CouplingEntry, get_change_coupling};
pub use db::{
    DirStats, IndexDb, NewCall, NewImport, NewSymbol, SymbolWithFile, content_hash, index_db_path,
};
pub use dead_code::{DeadCodeEntryV2, find_dead_code, find_dead_code_v2};
pub use edit_transaction::{
    ApplyError, ApplyEvidence, ApplyStatus, FileHash, RollbackEntry, WorkspaceEditTransaction,
    apply_full_write_with_evidence, apply_full_writes_with_evidence,
};
pub use file_ops::{
    DirectoryEntry, EnclosingSymbol, FileMatch, FileReadResult, PatternMatch, SmartPatternMatch,
    TextReference, create_text_file, delete_lines, extract_word_at_position, find_files,
    find_referencing_symbols_via_text, insert_after_symbol, insert_at_line, insert_before_symbol,
    list_dir, read_file, replace_content, replace_lines, replace_symbol_body, search_for_pattern,
    search_for_pattern_smart,
};
pub use git::{ChangedFile, DiffSymbol, DiffSymbolEntry, get_changed_files, get_diff_symbols};
pub use import_graph::{
    BlastRadiusEntry, DeadCodeEntry, GraphCache, ImportanceEntry, ImporterEntry,
    extract_imports_for_file, get_blast_radius, get_importance, get_importers,
    resolve_module_for_file, supports_import_graph,
};
pub use lsp::{
    LSP_RECIPES, LspDiagnostic, LspDiagnosticRequest, LspRecipe, LspReference, LspRenamePlan,
    LspRenamePlanRequest, LspRequest, LspResolveTargetRequest, LspResolvedTarget, LspResourceOp,
    LspSessionPool, LspStatus, LspTypeHierarchyRequest, LspWorkspaceEditTransaction,
    LspWorkspaceSymbol, LspWorkspaceSymbolRequest, check_lsp_status, default_lsp_args_for_command,
    default_lsp_command_for_extension, default_lsp_command_for_path,
    find_referencing_symbols_via_lsp, get_diagnostics_via_lsp, get_lsp_recipe,
    get_rename_plan_via_lsp, get_type_hierarchy_via_lsp, lsp_binary_exists,
    lsp_binary_exists_with_hint, resolve_lsp_binary_with_hint, resolve_symbol_target_via_lsp,
    search_workspace_symbols_via_lsp,
};
pub use project::{
    ProjectRoot, WorkspacePackage, compute_dominant_language, detect_frameworks,
    detect_workspace_packages,
};
pub use rename::{
    RenameEdit, RenameResult, RenameScope, apply_edits, find_all_word_matches, rename_symbol,
};
pub mod change_signature;
pub mod embedding_types;
pub mod inline;
pub mod ir;
pub mod move_symbol;
pub mod oxc_analysis;
#[cfg(feature = "scip-backend")]
pub mod scip_backend;
#[cfg(test)]
pub(crate) mod test_helpers;
#[cfg(feature = "semantic")]
pub use embedding::{
    EmbeddingEngine, configured_embedding_model_name, configured_embedding_runtime_info,
    configured_embedding_runtime_preference, configured_embedding_threads,
    embedding_model_assets_available,
};
pub use embedding_types::{EmbeddingIndexInfo, EmbeddingRuntimeInfo, SemanticMatch};
pub use memory::{
    AuditRecorder, MemoryAuditEvent, MemoryFrontmatter, MemoryLocation, MemoryMetadata,
    MemoryPolicy, MemoryTier, NullRecorder, archive_memory, archive_memory_rec, delete_memory,
    delete_memory_tiered, delete_memory_tiered_rec, global_memory_dir, list_all_memory_names,
    list_archived, list_memory_names, parse_frontmatter, read_memory, read_memory_from_tier,
    read_memory_with_metadata, read_policy, rename_memory, resolve_memory_path,
    resolve_memory_tier, restore_archived, restore_archived_rec, strip_frontmatter, write_memory,
    write_memory_tiered, write_memory_tiered_rec,
};
#[cfg(feature = "scip-backend")]
pub use scip_backend::ScipBackend;
pub use scope_analysis::{
    ReferenceKind, ScopedReference, find_scoped_references, find_scoped_references_in_file,
};
pub use search::{SearchResult, search_symbols_hybrid, search_symbols_hybrid_with_semantic};
pub use symbols::{
    IndexStats, RankedContextEntry, RankedContextResult, SymbolIndex, SymbolInfo, SymbolKind,
    SymbolProvenance, find_symbol, find_symbol_range, get_symbols_overview, make_symbol_id,
    parse_symbol_id, sparse_coverage_bonus_from_fields, sparse_max_bonus, sparse_threshold,
    sparse_weighting_enabled,
};
pub use type_hierarchy::{TypeHierarchyResult, TypeNode, get_type_hierarchy_native};
pub use watcher::{FileWatcher, WatcherStats};
// Semantic IR — new types only; existing types are already re-exported above.
pub use ir::{
    CodeDiagnostic, DiagnosticSeverity, EditAction, EditActionKind, EditPlan, ImpactKind,
    ImpactNode, IntelligenceSource, IrCallEdge, PreciseBackend, Relation, RelationKind,
    RetrievalConfig, RetrievalStage, RetrievalWeights, SearchCandidate,
};