Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/aft/src/bash_background/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub fn storage_dir(configured: Option<&std::path::Path>) -> PathBuf {
if let Some(dir) = std::env::var_os("AFT_CACHE_DIR") {
return PathBuf::from(dir).join("aft");
}
// Default to the CortexKit shared data root the SAME location the
// Default to the CortexKit shared data root - the SAME location the
// plugins inject as `storage_dir` on every configure. Before this, the
// fallback was the pre-migration `~/.cache/aft`, which only plugin-less
// invocations ever hit; once the daemon-supervised module became such an
Expand Down
58 changes: 57 additions & 1 deletion crates/aft/src/cli/warmup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ pub fn run(args: Vec<OsString>) -> Result<(), WarmupError> {
);
}

// Resolve ONNX Runtime from the plugin-managed cache so `aft warmup`
// can build the semantic index without the plugin setting ORT_DYLIB_PATH.
if args.areas.semantic {
try_set_ort_dylib_path(&storage_dir);
}

let ctx = AppContext::new(Box::new(TreeSitterProvider::new()), Config::default());
configure(&ctx, &root, &storage_dir, args.areas, args.force)?;

Expand Down Expand Up @@ -249,11 +255,32 @@ fn warmup_storage_dir() -> PathBuf {
if let Some(value) = std::env::var_os("AFT_STORAGE_DIR") {
return PathBuf::from(value);
}
// Same CortexKit shared data root the plugins inject warming here must
// Same CortexKit shared data root the plugins inject - warming here must
// land in the storage universe real sessions will read from.
aft::bash_background::storage_dir(None)
}

/// Set `ORT_DYLIB_PATH` from a cached ONNX Runtime library if not already set.
fn try_set_ort_dylib_path(storage_dir: &std::path::Path) {
if std::env::var_os("ORT_DYLIB_PATH").is_some() {
return;
}
let lib_name = if cfg!(target_os = "macos") {
"libonnxruntime.dylib"
} else if cfg!(target_os = "windows") {
"onnxruntime.dll"
} else {
"libonnxruntime.so"
};
let ort_dir = storage_dir.join("onnxruntime").join("1.24.4");
for candidate in [ort_dir.join(lib_name), ort_dir.join("lib").join(lib_name)] {
if candidate.is_file() {
std::env::set_var("ORT_DYLIB_PATH", &candidate);
break;
}
}
}

/// Build the `configure` params for a warmup run.
///
/// P1 config relocation: core config (search_index/semantic_search) is now
Expand Down Expand Up @@ -899,4 +926,33 @@ mod tests {
assert_eq!(err.exit_code(), 2);
assert!(err.to_string().contains("--only requires a value"));
}

#[test]
fn try_set_ort_dylib_path_finds_cached_library() {
use std::sync::Mutex;
static LOCK: Mutex<()> = Mutex::new(());
let _guard = LOCK.lock().unwrap();
std::env::remove_var("ORT_DYLIB_PATH");

let temp = tempfile::tempdir().unwrap();
let lib_name = if cfg!(target_os = "macos") {
"libonnxruntime.dylib"
} else if cfg!(target_os = "windows") {
"onnxruntime.dll"
} else {
"libonnxruntime.so"
};
let ort_dir = temp.path().join("onnxruntime").join("1.24.4");
std::fs::create_dir_all(&ort_dir).unwrap();
let lib_path = ort_dir.join(lib_name);
std::fs::write(&lib_path, b"fake").unwrap();

try_set_ort_dylib_path(temp.path());

assert_eq!(
std::env::var_os("ORT_DYLIB_PATH"),
Some(lib_path.as_os_str().to_owned())
);
std::env::remove_var("ORT_DYLIB_PATH");
}
}
Loading