Skip to main content

cpd_semantic/
lib.rs

1//! Semantic clones for jscpd (`--semantic`, experimental): functions that
2//! do the same job written differently — renamed, restructured, or in
3//! another language, like a rule a Rust backend enforces and a Svelte
4//! frontend repeats.
5//!
6//! - [`extract`] and [`units`] find the functions of a source and the text a
7//!   model sees for each;
8//! - [`embed`] turns those texts into vectors: a model run in-process
9//!   ([`Provider::Local`]) or an OpenAI-compatible API ([`Provider::Http`]),
10//!   behind an on-disk cache; [`embed::catalog`] holds the thresholds of
11//!   the models jscpd has calibrated;
12//! - [`search`] pairs the functions whose vectors point the same way;
13//! - [`SemanticPass`] runs all of it as a clone pass of the finder
14//!   ([`cpd_finder::pass`]);
15//! - [`compare`] pairs the functions of two codebases instead (`--compare`):
16//!   a project and its port, or the iOS and the Android version of an app.
17//!
18//! Everything `--semantic` needs lives here, with every dependency it
19//! brings — the model runtime, the model's tokenizer, the tree-sitter
20//! grammars, the HTTP client — so the core, the tokenizer and the finder
21//! compile without them.
22
23pub mod compare;
24pub mod embed;
25pub mod extract;
26mod pass;
27pub mod search;
28pub mod test_code;
29pub mod units;
30
31pub use embed::{
32    API_KEY_ENV, DEFAULT_HTTP_MODEL, DEFAULT_LOCAL_MODEL, DEFAULT_URL, Provider, SemanticOptions,
33    download, embedder, missing_model, model_list,
34};
35pub use pass::{SemanticPass, UnitReader};
36pub use search::{Embedder, SemanticScope, Thresholds};