Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

chore: add Reset button to local api server

Louise838f8b0e883
diff --git a/Makefile b/Makefile
index 5d2d11990..147b8270e 100644
--- a/Makefile
+++ b/Makefile
@@ -153,7 +153,6 @@ else
@echo "Skipping MLX server build (macOS only)"
endif
-
# Build MLX server only if not already present (for dev)
build-mlx-server-if-exists:
ifeq ($(shell uname -s),Darwin)
@@ -168,38 +167,28 @@ endif
# Build jan CLI (release, platform-aware) → src-tauri/resources/bin/jan[.exe]
build-cli:
+ mkdir -p src-tauri/resources/bin
ifeq ($(shell uname -s),Darwin)
- @echo "Building jan CLI (universal macOS)..."
cd src-tauri && cargo build --release --features cli --bin jan --target aarch64-apple-darwin
cd src-tauri && cargo build --release --features cli --bin jan --target x86_64-apple-darwin
- mkdir -p src-tauri/resources/bin
lipo -create \
src-tauri/target/aarch64-apple-darwin/release/jan \
src-tauri/target/x86_64-apple-darwin/release/jan \
-output src-tauri/resources/bin/jan
chmod +x src-tauri/resources/bin/jan
- @echo "jan CLI (universal) → src-tauri/resources/bin/jan"
else ifeq ($(OS),Windows_NT)
- @echo "Building jan CLI (Windows)..."
cd src-tauri && cargo build --release --features cli --bin jan
- mkdir -p src-tauri/resources/bin
cp src-tauri/target/release/jan.exe src-tauri/resources/bin/jan.exe
- @echo "jan CLI → src-tauri/resources/bin/jan.exe"
else
- @echo "Building jan CLI (Linux)..."
cd src-tauri && cargo build --release --features cli --bin jan
- mkdir -p src-tauri/resources/bin
cp src-tauri/target/release/jan src-tauri/resources/bin/jan
- chmod +x src-tauri/resources/bin/jan
- @echo "jan CLI → src-tauri/resources/bin/jan"
endif
-# Debug build for local dev (faster, no lipo on macOS)
+# Debug build for local dev (faster, native arch only)
build-cli-dev:
- cd src-tauri && cargo build --features cli --bin jan
mkdir -p src-tauri/resources/bin
- cp src-tauri/target/debug/jan src-tauri/resources/bin/jan
- chmod +x src-tauri/resources/bin/jan
+ cd src-tauri && cargo build --features cli --bin jan
+ install -m755 src-tauri/target/debug/jan src-tauri/resources/bin/jan
# Build
build: install-and-build install-rust-targets
diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock
index 3fc130cf1..818b65738 100644
--- a/src-tauri/Cargo.lock
+++ b/src-tauri/Cargo.lock
@@ -11,9 +11,12 @@ dependencies = [
"bollard",
"chrono",
"clap",
+ "console",
+ "dialoguer",
"dirs",
"ed25519-dalek",
"env",
+ "env_logger",
"fix-path-env",
"flate2",
"futures",
@@ -23,6 +26,7 @@ dependencies = [
"hmac",
"hostname",
"hyper 0.14.32",
+ "indicatif",
"jan-utils",
"libc",
"libloading 0.8.9",
@@ -31,6 +35,7 @@ dependencies = [
"once_cell",
"rand 0.8.5",
"reqwest 0.11.27",
+ "reqwest 0.12.23",
"rfd",
"rmcp",
"serde",
@@ -154,7 +159,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbb4e440d04be07da1f1bf44fb4495ebd58669372fe0cffa6e48595ac5bd88a3"
dependencies = [
"android_log-sys",
- "env_filter",
+ "env_filter 0.1.3",
"log",
]
@@ -946,6 +951,19 @@ dependencies = [
"crossbeam-utils",
]
+[[package]]
+name = "console"
+version = "0.15.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "054ccb5b10f9f2cbf51eb355ca1d05c2d279ce1804688d0db74b4733a5aeafd8"
+dependencies = [
+ "encode_unicode",
+ "libc",
+ "once_cell",
+ "unicode-width 0.2.2",
+ "windows-sys 0.59.0",
+]
+
[[package]]
name = "const-oid"
version = "0.9.6"
@@ -1372,6 +1390,19 @@ dependencies = [
"syn 2.0.106",
]
+[[package]]
+name = "dialoguer"
+version = "0.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "658bce805d770f407bc62102fca7c2c64ceef2fbcb2b8bd19d2765ce093980de"
+dependencies = [
+ "console",
+ "shell-words",
+ "tempfile",
+ "thiserror 1.0.69",
+ "zeroize",
+]
+
[[package]]
name = "digest"
version = "0.10.7"
@@ -1586,6 +1617,12 @@ version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ef6b89e5b37196644d8796de5268852ff179b44e96276cf4290264843743bb7"
+[[package]]
+name = "encode_unicode"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0"
+
[[package]]
name = "encoding_rs"
version = "0.8.35"
@@ -1641,6 +1678,29 @@ dependencies = [
"regex",
]
+[[package]]
+name = "env_filter"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7a1c3cc8e57274ec99de65301228b537f1e4eedc1b8e0f9411c6caac8ae7308f"
+dependencies = [
+ "log",
+ "regex",
+]
+
+[[package]]
+name = "env_logger"
+version = "0.11.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b2daee4ea451f429a58296525ddf28b45a3b64f1acf6587e2067437bb11e218d"
+dependencies = [
+ "anstream",
+ "anstyle",
+ "env_filter 1.0.0",
+ "jiff",
+ "log",
+]
+
[[package]]
name = "equivalent"
version = "1.0.2"
@@ -2497,7 +2557,7 @@ dependencies = [
"markup5ever 0.11.0",
"tendril",
"thiserror 1.0.69",
- "unicode-width",
+ "unicode-width 0.1.14",
"xml5ever",
]
@@ -2707,6 +2767,22 @@ dependencies = [
"tokio-native-tls",
]
+[[package]]
+name = "hyper-tls"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0"
+dependencies = [
+ "bytes",
+ "http-body-util",
+ "hyper 1.7.0",
+ "hyper-util",
+ "native-tls",
+ "tokio",
+ "tokio-native-tls",
+ "tower-service",
+]
+
[[package]]
name = "hyper-util"
version = "0.1.17"
@@ -2918,6 +2994,19 @@ dependencies = [
"serde_core",
]
+[[package]]
+name = "indicatif"
+version = "0.17.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "183b3088984b400f4cfac3620d5e076c84da5364016b4f49473de574b2586235"
+dependencies = [
+ "console",
+ "number_prefix",
+ "portable-atomic",
+ "unicode-width 0.2.2",
+ "web-time",
+]
+
[[package]]
name = "infer"
version = "0.15.0"
@@ -3043,6 +3132,30 @@ dependencies = [
"system-deps",
]
+[[package]]
+name = "jiff"
+version = "0.2.22"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "819b44bc7c87d9117eb522f14d46e918add69ff12713c475946b0a29363ed1c2"
+dependencies = [
+ "jiff-static",
+ "log",
+ "portable-atomic",
+ "portable-atomic-util",
+ "serde_core",
+]
+
+[[package]]
+name = "jiff-static"
+version = "0.2.22"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "470252db18ecc35fd766c0891b1e3ec6cbbcd62507e85276c01bf75d8e94d4a1"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.106",
+]
+
[[package]]
name = "jni"
version = "0.21.1"
@@ -3597,6 +3710,12 @@ dependencies = [
"libc",
]
+[[package]]
+name = "number_prefix"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
+
[[package]]
name = "nvml-wrapper"
version = "0.10.0"
@@ -4419,6 +4538,21 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60f6ce597ecdcc9a098e7fddacb1065093a3d66446fa16c675e7e71d1b5c28e6"
+[[package]]
+name = "portable-atomic"
+version = "1.13.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49"
+
+[[package]]
+name = "portable-atomic-util"
+version = "0.2.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7a9db96d7fa8782dd8c15ce32ffe8680bbd1e978a43bf51a34d39483540495f5"
+dependencies = [
+ "portable-atomic",
+]
+
[[package]]
name = "postscript"
version = "0.14.1"
@@ -4900,7 +5034,7 @@ dependencies = [
"http-body 0.4.6",
"hyper 0.14.32",
"hyper-rustls 0.24.2",
- "hyper-tls",
+ "hyper-tls 0.5.0",
"ipnet",
"js-sys",
"log",
@@ -4949,10 +5083,12 @@ dependencies = [
"http-body-util",
"hyper 1.7.0",
"hyper-rustls 0.27.7",
+ "hyper-tls 0.6.0",
"hyper-util",
"js-sys",
"log",
"mime",
+ "native-tls",
"percent-encoding",
"pin-project-lite",
"quinn",
@@ -4963,6 +5099,7 @@ dependencies = [
"serde_urlencoded",
"sync_wrapper 1.0.2",
"tokio",
+ "tokio-native-tls",
"tokio-rustls 0.26.4",
"tokio-util",
"tower",
@@ -5636,6 +5773,12 @@ dependencies = [
"windows-sys 0.60.2",
]
+[[package]]
+name = "shell-words"
+version = "1.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dc6fe69c597f9c37bfeeeeeb33da3530379845f10be461a66d16d03eca2ded77"
+
[[package]]
name = "shlex"
version = "1.3.0"
@@ -7415,6 +7558,12 @@ version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
+[[package]]
+name = "unicode-width"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254"
+
[[package]]
name = "unsafe-libyaml"
version = "0.2.11"
diff --git a/src-tauri/src/core/system/commands.rs b/src-tauri/src/core/system/commands.rs
index a3cdaa164..f3b599506 100644
--- a/src-tauri/src/core/system/commands.rs
+++ b/src-tauri/src/core/system/commands.rs
@@ -408,6 +408,98 @@ pub fn uninstall_jan_cli() -> Result<(), String> {
Ok(())
}
+/// Build the cleaned shell-file content with all Jan CC env vars stripped out.
+fn build_cleaned_env_content(env_file_path: &str) -> String {
+ let existing_content = std::fs::read_to_string(env_file_path).unwrap_or_default();
+ let cleaned: Vec<&str> = existing_content
+ .split('\n')
+ .filter(|line| {
+ !line.starts_with("# Jan Local API Server - Claude Code Config")
+ && !line.starts_with("# Jan Local API Server")
+ && !line.starts_with("export ANTHROPIC_")
+ })
+ .collect();
+ // Trim trailing blank lines left behind by the removed block
+ cleaned.join("\n").trim_end().to_string() + "\n"
+}
+
+/// Clear all Jan-written Claude Code environment variables from the shell config.
+/// Uses the same write-probe + osascript-fallback logic as `launch_claude_code_with_config`.
+#[tauri::command]
+pub fn clear_claude_code_env() -> Result<(), String> {
+ if cfg!(target_os = "macos") {
+ let home_dir = std::env::var("HOME").map_err(|e| e.to_string())?;
+ let (shell_name, env_file_path) = detect_shell_env_file(&home_dir, true);
+ log::info!("Clearing CC env from shell: {}, file: {}", shell_name, env_file_path);
+
+ let cleaned = build_cleaned_env_content(&env_file_path);
+
+ match std::fs::OpenOptions::new()
+ .write(true)
+ .create(true)
+ .open(&env_file_path)
+ {
+ Ok(_) => {
+ std::fs::write(&env_file_path, &cleaned).map_err(|e| e.to_string())?;
+ return Ok(());
+ }
+ Err(_) => {
+ // Write cleaned content to a temp file, then use osascript to move it
+ let temp_path = format!("{}/.jan_env_clear.sh", home_dir);
+ std::fs::write(&temp_path, &cleaned).map_err(|e| e.to_string())?;
+
+ let script = format!(
+ r#"do shell script "cp '{}' '{}' && rm '{}'" with administrator privileges"#,
+ temp_path, env_file_path, temp_path
+ );
+
+ std::process::Command::new("osascript")
+ .arg("-e")
+ .arg(&script)
+ .output()
+ .map_err(|e| e.to_string())?;
+
+ log::info!("CC env cleared from {} with admin privileges", env_file_path);
+ return Ok(());
+ }
+ }
+ } else if cfg!(target_os = "linux") {
+ let home_dir = std::env::var("HOME").map_err(|e| e.to_string())?;
+ let (shell_name, env_file_path) = detect_shell_env_file(&home_dir, false);
+ log::info!("Clearing CC env from shell: {}, file: {}", shell_name, env_file_path);
+
+ let cleaned = build_cleaned_env_content(&env_file_path);
+
+ match std::fs::OpenOptions::new()
+ .write(true)
+ .create(true)
+ .open(&env_file_path)
+ {
+ Ok(_) => {
+ std::fs::write(&env_file_path, &cleaned).map_err(|e| e.to_string())?;
+ Ok(())
+ }
+ Err(_) => Err(format!("NEED_PERMISSION:{}", env_file_path)),
+ }
+ } else {
+ // Windows: delete the persistent user env vars from the registry
+ let keys = [
+ "ANTHROPIC_BASE_URL",
+ "ANTHROPIC_AUTH_TOKEN",
+ "ANTHROPIC_DEFAULT_OPUS_MODEL",
+ "ANTHROPIC_DEFAULT_SONNET_MODEL",
+ "ANTHROPIC_DEFAULT_HAIKU_MODEL",
+ ];
+ for key in &keys {
+ let _ = std::process::Command::new("reg")
+ .args(["delete", "HKCU\\Environment", "/v", key, "/f"])
+ .output();
+ }
+ log::info!("CC env vars removed from Windows registry.");
+ Ok(())
+ }
+}
+
/// Determine the best writable directory for the Jan CLI install.
fn jan_cli_install_dir() -> Result<PathBuf, String> {
#[cfg(unix)]
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index 8d5682d77..476429810 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -104,6 +104,7 @@ pub fn run() {
core::system::commands::check_jan_cli_installed,
core::system::commands::install_jan_cli,
core::system::commands::uninstall_jan_cli,
+ core::system::commands::clear_claude_code_env,
// Server commands
core::server::commands::start_server,
core::server::commands::stop_server,
@@ -265,6 +266,7 @@ pub fn run() {
core::system::commands::check_jan_cli_installed,
core::system::commands::install_jan_cli,
core::system::commands::uninstall_jan_cli,
+ core::system::commands::clear_claude_code_env,
// Server commands
core::server::commands::start_server,
core::server::commands::stop_server,