-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rs
More file actions
112 lines (104 loc) · 3.78 KB
/
Copy pathmain.rs
File metadata and controls
112 lines (104 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
use clap::{Parser, Subcommand};
use git_reticulator::lattice::affine;
use git_reticulator::store::LatticeStore;
#[derive(Parser)]
#[command(name = "reticulate")]
#[command(about = "Git-Reticulator: Build and query semantic lattices from git repos", long_about = None)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
/// Build a semantic lattice from a git repo
Build {
/// Path to the git repository
#[arg(short, long)]
repo: String,
/// PostgreSQL database URI
#[arg(short, long)]
db: String,
},
/// Query the lattice with a zoom level to minimize token cost
Query {
/// Semantic node or keyword to zoom into
#[arg(short, long)]
zoom: String,
/// PostgreSQL database URI
#[arg(short, long)]
db: String,
},
/// Start the REST API server for LLM integration
Api {
/// PostgreSQL database URI
#[arg(short, long)]
db: String,
},
}
/// Ingest a repository into a lattice. With `--features git-integration` this is
/// git-aware (HEAD tree + commit-history coupling), falling back to a filesystem
/// walk when `repo` is not a git repository; otherwise it is always a walk.
#[cfg(feature = "git-integration")]
fn reticulate_ingest(repo: &str) -> git_reticulator::lattice::Lattice {
match git_reticulator::ingest::from_git(repo) {
Ok(lattice) => lattice,
Err(_) => git_reticulator::ingest::from_path(repo),
}
}
#[cfg(not(feature = "git-integration"))]
fn reticulate_ingest(repo: &str) -> git_reticulator::lattice::Lattice {
git_reticulator::ingest::from_path(repo)
}
#[tokio::main]
async fn main() {
let cli = Cli::parse();
env_logger::init();
match &cli.command {
Commands::Build { repo, db } => {
println!("🚀 Reticulating {repo} ...");
let lattice = reticulate_ingest(repo);
let cond = lattice.condense();
println!(
" {} nodes · {} edges · {} components · acyclic={}",
lattice.len(),
lattice.edges().len(),
cond.num_components,
cond.is_acyclic()
);
#[cfg(feature = "verisim")]
let to_verisim = if db.starts_with("http://") || db.starts_with("https://") {
let store = git_reticulator::store::verisim::VerisimStore::new(db.clone());
match store.persist(&lattice).await {
Ok(n) => println!("📦 persisted {n} octads to VeriSimDB ({db})"),
Err(e) => eprintln!("⚠️ verisim persist failed: {e}"),
}
true
} else {
false
};
#[cfg(not(feature = "verisim"))]
let to_verisim = false;
if !to_verisim {
let mut store = git_reticulator::store::InMemoryStore::new();
let n = match store.persist(&lattice) {
Ok(n) => n,
// InMemoryStore is Infallible — this arm is unreachable.
Err(never) => match never {},
};
println!("📦 persisted {n} nodes to the in-memory store (target: {db})");
}
println!("✅ done.");
}
Commands::Query { zoom, db } => {
println!("🔍 Querying lattice for context: {}", zoom);
affine::query_lattice(zoom, db);
}
Commands::Api { db } => {
println!("🌐 Starting Git-Reticulator API on http://localhost:8080");
println!("Using database: {}", db);
git_reticulator::api::app::start_server(db.clone())
.await
.expect("Failed to start API server");
}
}
}