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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
use anyhow::Result;
use clap::{Parser, Subcommand};
mod cli;
mod config;
mod daemon;
mod embeddings;
mod indexer;
mod reranker;
mod search;
mod storage;
/// Load environment variables from .env file in the current directory or parent directories
fn load_dotenv() {
// Try to find and load .env from current dir or parent directories
if let Ok(cwd) = std::env::current_dir() {
let mut dir = cwd.as_path();
loop {
let env_file = dir.join(".env");
if env_file.exists() {
let _ = dotenvy::from_path(&env_file);
break;
}
// Also try .env.local
let env_local = dir.join(".env.local");
if env_local.exists() {
let _ = dotenvy::from_path(&env_local);
}
match dir.parent() {
Some(parent) => dir = parent,
None => break,
}
}
}
}
#[derive(Parser)]
#[command(name = "vyctor")]
#[command(
author,
version,
about = "Fast semantic file search using vector embeddings"
)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
/// Initialize vyctor in the current directory
Init {
/// Force re-initialization even if .vyctor already exists
#[arg(short, long)]
force: bool,
},
/// Search for files matching a natural language query
Lookup {
/// The search query
query: String,
/// Folder to search in (relative to indexed root)
#[arg(short, long)]
folder: Option<String>,
/// Number of results to return
#[arg(short = 'n', long, default_value = "5")]
count: usize,
/// Show full file content instead of just the matching chunk
#[arg(long)]
full: bool,
/// Show verbose output (model loading, detailed timing)
#[arg(short, long)]
verbose: bool,
},
/// Synchronize the index with current files
Sync {
/// Force re-index all files
#[arg(short, long)]
force: bool,
},
/// Watch for file changes and auto-sync
Watch {
/// Debounce interval in milliseconds
#[arg(short, long, default_value = "300")]
debounce: u64,
/// Run as background daemon
#[arg(long)]
daemon: bool,
/// Stop running daemon
#[arg(long)]
stop: bool,
/// Show daemon status
#[arg(long)]
status: bool,
/// Show daemon logs
#[arg(long)]
logs: bool,
/// Follow log output (with --logs)
#[arg(short, long)]
follow: bool,
/// Internal flag: this process is the daemon child
#[arg(long, hide = true)]
daemon_child: bool,
},
/// Show index status and statistics
Status,
/// Show or edit configuration
Config {
/// Open config in editor
#[arg(short, long)]
edit: bool,
},
/// Browse and analyze indexed files and chunks
Browse {
#[command(subcommand)]
action: BrowseAction,
},
}
#[derive(Subcommand)]
enum BrowseAction {
/// List all indexed files
Files {
/// Filter files by path pattern
#[arg(short, long)]
filter: Option<String>,
/// Show content hash for each file
#[arg(long)]
hash: bool,
},
/// Browse chunks
Chunks {
/// Show chunks for a specific file
#[arg(short, long)]
file: Option<String>,
/// Show a specific chunk by ID
#[arg(long)]
id: Option<i64>,
/// Page number (1-indexed)
#[arg(short, long, default_value = "1")]
page: usize,
/// Number of chunks per page
#[arg(short = 'n', long, default_value = "10")]
size: usize,
/// Show full chunk content
#[arg(long)]
full: bool,
},
/// Show index statistics by file type
Stats,
}
#[tokio::main]
async fn main() -> Result<()> {
// Load .env file before anything else
load_dotenv();
let cli = Cli::parse();
match cli.command {
Commands::Init { force } => {
cli::init::run(force).await?;
}
Commands::Lookup {
query,
folder,
count,
full,
verbose,
} => {
cli::lookup::run(&query, folder.as_deref(), count, full, verbose).await?;
}
Commands::Sync { force } => {
cli::sync::run(force).await?;
}
Commands::Watch {
debounce,
daemon,
stop,
status,
logs,
follow,
daemon_child,
} => {
cli::watch::run(debounce, daemon, stop, status, logs, follow, daemon_child).await?;
}
Commands::Status => {
cli::status::run().await?;
}
Commands::Config { edit } => {
cli::config_cmd::run(edit).await?;
}
Commands::Browse { action } => match action {
BrowseAction::Files { filter, hash } => {
cli::browse::list_files(filter.as_deref(), hash).await?;
}
BrowseAction::Chunks {
file,
id,
page,
size,
full,
} => {
cli::browse::show_chunks(file.as_deref(), id, page, size, full).await?;
}
BrowseAction::Stats => {
cli::browse::show_stats().await?;
}
},
}
Ok(())
}