refactor: eliminate all CARGO_MANIFEST_DIR compile-time dependencies (A-4)
- Add src/core/path_utils.rs with runtime path resolution helpers
- Replace all env!("CARGO_MANIFEST_DIR") with runtime resolution
- Priority: env var -> current_exe sibling -> dev fallback
Changes:
- executor.rs: scripts_dir(), cli_dir() (4 locations)
- face.rs: swift_processor_path()
- tool_selector.rs: swift_binary_path()
- thumbnail/mod.rs: script_path()
Issue: CARGO_MANIFEST_DIR expands to build machine path at compile time,
breaking on binary-only release hosts.
Solution: Resolve paths at runtime in this order:
1. Explicit environment variable (MOMENTRY_SCRIPTS_DIR, MOMENTRY_CLI_DIR)
2. Sibling of current_exe (same directory as running binary)
3. Relative path fallback (dev machine)
Verified: cargo check --lib passes
This commit is contained in:
@@ -0,0 +1,351 @@
|
||||
//! Momentry Core - Digital asset management system with video analysis and RAG
|
||||
//!
|
||||
//! This is the main entry point for the CLI application.
|
||||
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
|
||||
// Local modules
|
||||
mod cli;
|
||||
mod processing;
|
||||
|
||||
fn init_tracing() {
|
||||
tracing_subscriber::fmt()
|
||||
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
|
||||
.with_target(true)
|
||||
.with_writer(|| std::io::LineWriter::new(std::io::stdout()))
|
||||
.init();
|
||||
}
|
||||
|
||||
fn load_env() {
|
||||
let _ = dotenv::from_filename("/Users/accusys/momentry_core/.env");
|
||||
}
|
||||
|
||||
use cli::*;
|
||||
use processing::handlers::*;
|
||||
|
||||
/// Main entry point
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
load_env();
|
||||
init_tracing();
|
||||
let cli = Cli::parse();
|
||||
|
||||
match cli.command {
|
||||
Commands::Register { path } => {
|
||||
handle_register(&path).await?;
|
||||
}
|
||||
Commands::Process {
|
||||
target,
|
||||
modules,
|
||||
cloud,
|
||||
force,
|
||||
resume,
|
||||
} => {
|
||||
handle_process(&target, modules, cloud, force, resume).await?;
|
||||
}
|
||||
Commands::Chunk { uuid } => {
|
||||
handle_chunk(&uuid).await?;
|
||||
}
|
||||
Commands::StoreAsrx { uuid } => {
|
||||
handle_store_asrx(&uuid).await?;
|
||||
}
|
||||
Commands::TkgBackfill { file_uuid } => {
|
||||
handle_tkg_backfill(&file_uuid).await?;
|
||||
}
|
||||
Commands::Vectorize { uuid } => {
|
||||
handle_vectorize(&uuid).await?;
|
||||
}
|
||||
Commands::Phase1 { uuid } => {
|
||||
handle_phase1(&uuid).await?;
|
||||
}
|
||||
Commands::Complete { uuid } => {
|
||||
handle_complete(&uuid).await?;
|
||||
}
|
||||
Commands::Play { target } => {
|
||||
handle_play(&target).await?;
|
||||
}
|
||||
Commands::Watch { directories } => {
|
||||
handle_watch(directories).await?;
|
||||
}
|
||||
Commands::System { gpu } => {
|
||||
handle_system(gpu).await?;
|
||||
}
|
||||
Commands::Server { host, port } => {
|
||||
handle_server(&host, port).await?;
|
||||
}
|
||||
Commands::Worker {
|
||||
max_concurrent,
|
||||
poll_interval,
|
||||
batch_size,
|
||||
} => {
|
||||
handle_worker(max_concurrent, poll_interval, batch_size).await?;
|
||||
}
|
||||
Commands::Query { query } => {
|
||||
handle_query(&query).await?;
|
||||
}
|
||||
Commands::Lookup { path } => {
|
||||
handle_lookup(&path).await?;
|
||||
}
|
||||
Commands::Resolve { uuid } => {
|
||||
handle_resolve(&uuid).await?;
|
||||
}
|
||||
Commands::Thumbnails { uuid, count } => {
|
||||
handle_thumbnails(uuid, count).await?;
|
||||
}
|
||||
Commands::Status { uuid } => {
|
||||
handle_status(uuid).await?;
|
||||
}
|
||||
Commands::Backup { action, days } => {
|
||||
handle_backup(&action, days).await?;
|
||||
}
|
||||
Commands::ApiKey {
|
||||
action,
|
||||
name,
|
||||
key_type,
|
||||
ttl,
|
||||
key,
|
||||
} => {
|
||||
handle_api_key(action, name, key_type, ttl, key).await?;
|
||||
}
|
||||
Commands::Gitea {
|
||||
action,
|
||||
username,
|
||||
password,
|
||||
token_name,
|
||||
scopes,
|
||||
} => {
|
||||
handle_gitea(action, username, password, token_name, scopes).await?;
|
||||
}
|
||||
Commands::Agent { tool, args } => {
|
||||
cli::agent::handle_agent(&tool, &args).await?;
|
||||
}
|
||||
Commands::Detect {
|
||||
image,
|
||||
objects,
|
||||
cascade,
|
||||
threshold,
|
||||
} => {
|
||||
cli::vision::handle_detect_command(image, objects, cascade, threshold).await?;
|
||||
}
|
||||
Commands::Vision(cmd) => {
|
||||
cli::vision::handle_vision_command(cmd).await?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Handle register command
|
||||
async fn handle_register(path: &str) -> Result<()> {
|
||||
println!("Registering video: {}", path);
|
||||
|
||||
// TODO: Implement registration logic
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Handle process command
|
||||
async fn handle_process(
|
||||
target: &str,
|
||||
modules: Option<Vec<String>>,
|
||||
cloud: Option<Vec<String>>,
|
||||
force: bool,
|
||||
resume: bool,
|
||||
) -> Result<()> {
|
||||
println!("Processing video: {}", target);
|
||||
println!("Modules: {:?}", modules);
|
||||
println!("Cloud modules: {:?}", cloud);
|
||||
println!("Force: {}, Resume: {}", force, resume);
|
||||
|
||||
// TODO: Implement processing logic
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Handle chunk command
|
||||
async fn handle_chunk(uuid: &str) -> Result<()> {
|
||||
println!("Generating chunks for: {}", uuid);
|
||||
|
||||
// TODO: Implement chunk logic
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Handle story command
|
||||
/// Handle vectorize command
|
||||
async fn handle_vectorize(uuid: &str) -> Result<()> {
|
||||
println!("Vectorizing chunks for: {}", uuid);
|
||||
|
||||
// TODO: Implement vectorize logic
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Handle play command
|
||||
async fn handle_play(target: &str) -> Result<()> {
|
||||
println!("Playing video: {}", target);
|
||||
|
||||
// TODO: Implement play logic
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Handle watch command
|
||||
async fn handle_watch(directories: Option<String>) -> Result<()> {
|
||||
println!("Watching directories: {:?}", directories);
|
||||
|
||||
// TODO: Implement watch logic
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Handle system command
|
||||
async fn handle_system(gpu: bool) -> Result<()> {
|
||||
println!("Checking system resources...");
|
||||
|
||||
// TODO: Implement proper system resource checking
|
||||
println!("System Information:");
|
||||
println!(" CPU: (would show CPU info)");
|
||||
println!(" Memory: (would show memory info)");
|
||||
|
||||
if gpu {
|
||||
println!("GPU details: (would show GPU info if available)");
|
||||
}
|
||||
|
||||
println!("(System resource checking would be implemented here)");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Handle server command
|
||||
async fn handle_server(host: &str, port: Option<u16>) -> Result<()> {
|
||||
let port = port.unwrap_or(3002);
|
||||
println!("Starting API server on {}:{}", host, port);
|
||||
|
||||
// Start the actual API server
|
||||
momentry_core::api::start_server(host, port).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Handle worker command
|
||||
async fn handle_worker(
|
||||
max_concurrent: Option<usize>,
|
||||
poll_interval: Option<u64>,
|
||||
batch_size: Option<i32>,
|
||||
) -> Result<()> {
|
||||
use momentry_core::core::db::{Database, PostgresDb, RedisClient};
|
||||
use momentry_core::worker::{JobWorker, WorkerConfig};
|
||||
|
||||
println!("Starting job worker");
|
||||
println!("Max concurrent: {:?}", max_concurrent);
|
||||
println!("Poll interval: {:?}", poll_interval);
|
||||
println!("Batch size: {:?}", batch_size);
|
||||
|
||||
let config = WorkerConfig {
|
||||
max_concurrent: max_concurrent.unwrap_or(2),
|
||||
poll_interval_secs: poll_interval.unwrap_or(5),
|
||||
enabled: true,
|
||||
batch_size: batch_size.unwrap_or(10),
|
||||
processor_timeout_secs: 3600,
|
||||
};
|
||||
|
||||
let db = PostgresDb::init().await?;
|
||||
let redis = RedisClient::new()?;
|
||||
|
||||
let worker = JobWorker::new(
|
||||
std::sync::Arc::new(db),
|
||||
std::sync::Arc::new(redis),
|
||||
config.clone(),
|
||||
);
|
||||
|
||||
println!(
|
||||
"Starting worker with max_concurrent={}, poll_interval={}s",
|
||||
config.max_concurrent, config.poll_interval_secs
|
||||
);
|
||||
|
||||
worker.run().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Handle query command
|
||||
async fn handle_query(query: &str) -> Result<()> {
|
||||
println!("Querying: {}", query);
|
||||
|
||||
// TODO: Implement query logic
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Handle lookup command
|
||||
async fn handle_lookup(path: &str) -> Result<()> {
|
||||
println!("Looking up UUID for path: {}", path);
|
||||
|
||||
// TODO: Implement lookup logic
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Handle resolve command
|
||||
async fn handle_resolve(uuid: &str) -> Result<()> {
|
||||
println!("Resolving path for UUID: {}", uuid);
|
||||
|
||||
// TODO: Implement resolve logic
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Handle thumbnails command
|
||||
async fn handle_thumbnails(uuid: Option<String>, count: u32) -> Result<()> {
|
||||
println!("Generating thumbnails");
|
||||
println!("UUID: {:?}", uuid);
|
||||
println!("Count: {}", count);
|
||||
|
||||
// TODO: Implement thumbnails logic
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Handle status command
|
||||
async fn handle_status(uuid: Option<String>) -> Result<()> {
|
||||
println!("Checking storage status");
|
||||
println!("UUID: {:?}", uuid);
|
||||
|
||||
// TODO: Implement status logic
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Handle backup command
|
||||
async fn handle_backup(action: &str, days: Option<u32>) -> Result<()> {
|
||||
println!("Backup action: {}", action);
|
||||
println!("Days to keep: {:?}", days);
|
||||
|
||||
// TODO: Implement backup logic
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Handle API key command
|
||||
async fn handle_api_key(
|
||||
action: ApiKeyAction,
|
||||
name: Option<String>,
|
||||
key_type: Option<String>,
|
||||
ttl: Option<i64>,
|
||||
key: Option<String>,
|
||||
) -> Result<()> {
|
||||
println!("API Key action: {:?}", action);
|
||||
println!("Name: {:?}", name);
|
||||
println!("Key type: {:?}", key_type);
|
||||
println!("TTL: {:?}", ttl);
|
||||
println!("Key: {:?}", key);
|
||||
|
||||
// TODO: Implement API key logic
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Handle Gitea command
|
||||
async fn handle_gitea(
|
||||
action: GiteaAction,
|
||||
username: Option<String>,
|
||||
password: Option<String>,
|
||||
token_name: Option<String>,
|
||||
scopes: Option<String>,
|
||||
) -> Result<()> {
|
||||
println!("Gitea action: {:?}", action);
|
||||
println!("Username: {:?}", username);
|
||||
println!("Token name: {:?}", token_name);
|
||||
println!("Scopes: {:?}", scopes);
|
||||
|
||||
// TODO: Implement Gitea logic
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user