Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix(startup): self-heal extensions dir, overwrite jan-cli on upgrade, reconcile vector-db ACL
Akarshan Biswas369232238b69
diff --git a/src-tauri/plugins/tauri-plugin-vector-db/permissions/autogenerated/reference.md b/src-tauri/plugins/tauri-plugin-vector-db/permissions/autogenerated/reference.mdindex 43ecee0c9..b859ecb87 100644--- a/src-tauri/plugins/tauri-plugin-vector-db/permissions/autogenerated/reference.md+++ b/src-tauri/plugins/tauri-plugin-vector-db/permissions/autogenerated/reference.md@@ -288,110 +288,6 @@ Denies the list_attachments command without any pre-configured scope.<tr><td>-`vector-db:allow-memory-clear`--</td>-<td>--Enables the memory_clear command without any pre-configured scope.--</td>-</tr>--<tr>-<td>--`vector-db:deny-memory-clear`--</td>-<td>--Denies the memory_clear command without any pre-configured scope.--</td>-</tr>--<tr>-<td>--`vector-db:allow-memory-delete-message`--</td>-<td>--Enables the memory_delete_message command without any pre-configured scope.--</td>-</tr>--<tr>-<td>--`vector-db:deny-memory-delete-message`--</td>-<td>--Denies the memory_delete_message command without any pre-configured scope.--</td>-</tr>--<tr>-<td>--`vector-db:allow-memory-index`--</td>-<td>--Enables the memory_index command without any pre-configured scope.--</td>-</tr>--<tr>-<td>--`vector-db:deny-memory-index`--</td>-<td>--Denies the memory_index command without any pre-configured scope.--</td>-</tr>--<tr>-<td>--`vector-db:allow-memory-search`--</td>-<td>--Enables the memory_search command without any pre-configured scope.--</td>-</tr>--<tr>-<td>--`vector-db:deny-memory-search`--</td>-<td>--Denies the memory_search command without any pre-configured scope.--</td>-</tr>--<tr>-<td>-`vector-db:allow-search-collection`</td>diff --git a/src-tauri/plugins/tauri-plugin-vector-db/permissions/schemas/schema.json b/src-tauri/plugins/tauri-plugin-vector-db/permissions/schemas/schema.jsonindex e9e8d582b..6410337c5 100644--- a/src-tauri/plugins/tauri-plugin-vector-db/permissions/schemas/schema.json+++ b/src-tauri/plugins/tauri-plugin-vector-db/permissions/schemas/schema.json@@ -414,54 +414,6 @@"const": "deny-list-attachments","markdownDescription": "Denies the list_attachments command without any pre-configured scope."},- {- "description": "Enables the memory_clear command without any pre-configured scope.",- "type": "string",- "const": "allow-memory-clear",- "markdownDescription": "Enables the memory_clear command without any pre-configured scope."- },- {- "description": "Denies the memory_clear command without any pre-configured scope.",- "type": "string",- "const": "deny-memory-clear",- "markdownDescription": "Denies the memory_clear command without any pre-configured scope."- },- {- "description": "Enables the memory_delete_message command without any pre-configured scope.",- "type": "string",- "const": "allow-memory-delete-message",- "markdownDescription": "Enables the memory_delete_message command without any pre-configured scope."- },- {- "description": "Denies the memory_delete_message command without any pre-configured scope.",- "type": "string",- "const": "deny-memory-delete-message",- "markdownDescription": "Denies the memory_delete_message command without any pre-configured scope."- },- {- "description": "Enables the memory_index command without any pre-configured scope.",- "type": "string",- "const": "allow-memory-index",- "markdownDescription": "Enables the memory_index command without any pre-configured scope."- },- {- "description": "Denies the memory_index command without any pre-configured scope.",- "type": "string",- "const": "deny-memory-index",- "markdownDescription": "Denies the memory_index command without any pre-configured scope."- },- {- "description": "Enables the memory_search command without any pre-configured scope.",- "type": "string",- "const": "allow-memory-search",- "markdownDescription": "Enables the memory_search command without any pre-configured scope."- },- {- "description": "Denies the memory_search command without any pre-configured scope.",- "type": "string",- "const": "deny-memory-search",- "markdownDescription": "Denies the memory_search command without any pre-configured scope."- },{"description": "Enables the search_collection command without any pre-configured scope.","type": "string",diff --git a/src-tauri/src/core/setup.rs b/src-tauri/src/core/setup.rsindex 98c7720d0..edce5de50 100644--- a/src-tauri/src/core/setup.rs+++ b/src-tauri/src/core/setup.rs@@ -2,7 +2,7 @@ use flate2::read::GzDecoder;use std::{fs::{self, File},io::Read,- path::PathBuf,+ path::{Path, PathBuf},sync::Arc,time::Duration,};@@ -24,6 +24,21 @@ use super::{extensions::commands::get_jan_extensions_path, mcp::helpers::run_mcp_commands, state::AppState,};+fn extensions_manifest_intact(manifest_path: &Path) -> bool {+ let Ok(data) = fs::read_to_string(manifest_path) else {+ return false;+ };+ let Ok(entries) = serde_json::from_str::<Vec<serde_json::Value>>(&data) else {+ return false;+ };+ !entries.is_empty()+ && entries.iter().all(|ext| {+ ext.get("url")+ .and_then(|u| u.as_str())+ .is_some_and(|u| Path::new(u).exists())+ })+}+pub fn install_extensions<R: Runtime>(app: tauri::AppHandle<R>, force: bool) -> Result<(), String> {// Skip extension installation on mobile platforms// Mobile uses pre-bundled extensions loaded via MobileCoreService in the frontend@@ -48,9 +63,10 @@ pub fn install_extensions<R: Runtime>(app: tauri::AppHandle<R>, force: bool) ->clean_up = true;}log::info!("Installing extensions. Clean up: {clean_up}");- // A bare directory is not proof of a completed install; gate on the manifest- // so a previously-aborted run self-heals on the next launch.- if !clean_up && extensions_json_path.exists() {+ // A bare directory (or a surviving manifest) is not proof of a completed+ // install; gate on the manifest AND on the files it points at so a partial+ // or externally-deleted install self-heals on the next launch.+ if !clean_up && extensions_manifest_intact(&extensions_json_path) {return Ok(());}@@ -712,3 +728,51 @@ fn setup_window_theme_listener<R: Runtime>(}});}++#[cfg(test)]+mod tests {+ use super::*;+ use std::fs;++ fn write_manifest(dir: &Path, urls: &[&str]) -> PathBuf {+ let entries: Vec<serde_json::Value> = urls+ .iter()+ .map(|u| serde_json::json!({ "name": "@janhq/x", "url": u }))+ .collect();+ let manifest = dir.join("extensions.json");+ fs::write(&manifest, serde_json::to_string(&entries).unwrap()).unwrap();+ manifest+ }++ #[test]+ fn intact_when_all_referenced_files_exist() {+ let tmp = tempfile::tempdir().unwrap();+ let ext = tmp.path().join("dist/index.js");+ fs::create_dir_all(ext.parent().unwrap()).unwrap();+ fs::write(&ext, "").unwrap();+ let manifest = write_manifest(tmp.path(), &[ext.to_str().unwrap()]);+ assert!(extensions_manifest_intact(&manifest));+ }++ #[test]+ fn not_intact_when_a_referenced_file_is_missing() {+ let tmp = tempfile::tempdir().unwrap();+ let manifest = write_manifest(tmp.path(), &[tmp.path().join("gone.js").to_str().unwrap()]);+ assert!(!extensions_manifest_intact(&manifest));+ }++ #[test]+ fn not_intact_when_manifest_missing_or_empty() {+ let tmp = tempfile::tempdir().unwrap();+ assert!(!extensions_manifest_intact(&tmp.path().join("extensions.json")));+ let empty = write_manifest(tmp.path(), &[]);+ assert!(!extensions_manifest_intact(&empty));+ }++ #[test]+ fn not_intact_when_extensions_dir_absent() {+ let tmp = tempfile::tempdir().unwrap();+ let manifest = tmp.path().join("extensions").join("extensions.json");+ assert!(!extensions_manifest_intact(&manifest));+ }+}diff --git a/src-tauri/src/core/system/commands.rs b/src-tauri/src/core/system/commands.rsindex 0f631a523..ae4594005 100644--- a/src-tauri/src/core/system/commands.rs+++ b/src-tauri/src/core/system/commands.rs@@ -684,6 +684,14 @@ pub fn install_jan_cli_sync<R: Runtime>(#[cfg(windows)]{if bundled.exists() {+ // rename won't reliably clobber a stale jan.exe from a previous+ // version (replace semantics / AV locks), so drop it first to+ // guarantee a version upgrade actually overwrites the binary.+ if dest.exists() {+ if let Err(e) = std::fs::remove_file(&dest) {+ log::warn!("Could not remove stale {}: {}", dest.display(), e);+ }+ }if let Err(e) = std::fs::rename(&bundled, &dest) {log::warn!("Could not rename jan-cli.exe to jan.exe: {}", e);}