feat(core): add ollama lifecycle management for cron sync

Add src/core/ollama_mgmt.rs module that handles Ollama detection, startup,
and health checking. This enables cron-based sync to automatically start
Ollama when it's installed but not running, ensuring embeddings are always
available during unattended sync runs.

Integration points:
- sync handler (--lock mode): calls ensure_ollama() before embedding phase
- cron status: displays Ollama health (installed/running/not-installed)
- robot JSON: includes OllamaStatusBrief in cron status response

The module handles local vs remote Ollama URLs, IPv6, process detection
via lsof, and graceful startup with configurable wait timeouts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
teernisse
2026-03-12 17:06:57 -04:00
parent 75469af514
commit 16bd33e8c0
4 changed files with 569 additions and 1 deletions

View File

@@ -1664,6 +1664,24 @@ async fn handle_sync_cmd(
None
};
// In cron mode (--lock), ensure Ollama is running for embeddings
if args.lock {
let result = lore::core::ollama_mgmt::ensure_ollama(&config.embedding.base_url);
if !result.installed {
tracing::warn!(
"Ollama is not installed — embeddings will be skipped. {}",
result.install_hint.as_deref().unwrap_or("")
);
} else if result.started {
tracing::info!("Started ollama serve (was not running)");
} else if !result.running {
tracing::warn!(
"Failed to start Ollama: {}",
result.error.as_deref().unwrap_or("unknown error")
);
}
}
// Surgical mode: run_sync_surgical manages its own recorder, signal, and recording.
// Skip the normal recorder setup and let the dispatch handle everything.
if options.is_surgical() {