LLM Wiki is a cross-platform desktop application that turns your documents into an organized, interlinked knowledge base — automatically. Instead of traditional RAG (retrieve-and-answer from scratch every time), the LLM incrementally builds and maintains a persistent wiki from your sources。
TypeScript
feat: clip server daemon health monitoring with auto-restart
nash_su7d66fe6f07a0
diff --git a/src-tauri/src/clip_server.rs b/src-tauri/src/clip_server.rsindex d2bab0c3..1a214c84 100644--- a/src-tauri/src/clip_server.rs+++ b/src-tauri/src/clip_server.rs@@ -1,4 +1,5 @@use std::sync::Mutex;+use std::sync::atomic::{AtomicU8, Ordering};use std::thread;use tiny_http::{Header, Method, Response, Server};@@ -6,17 +7,68 @@ static CURRENT_PROJECT: Mutex<String> = Mutex::new(String::new());static ALL_PROJECTS: Mutex<Vec<(String, String)>> = Mutex::new(Vec::new()); // (name, path)static PENDING_CLIPS: Mutex<Vec<(String, String)>> = Mutex::new(Vec::new()); // (projectPath, filePath)+/// Daemon status: 0=starting, 1=running, 2=port_conflict, 3=error+static DAEMON_STATUS: AtomicU8 = AtomicU8::new(0);++const PORT: u16 = 19827;+const MAX_BIND_RETRIES: u32 = 3;+const MAX_RESTART_RETRIES: u32 = 10;+const BIND_RETRY_DELAY_SECS: u64 = 2;+const RESTART_DELAY_SECS: u64 = 5;++/// Get current daemon status as a string+pub fn get_daemon_status() -> &'static str {+ match DAEMON_STATUS.load(Ordering::Relaxed) {+ 0 => "starting",+ 1 => "running",+ 2 => "port_conflict",+ _ => "error",+ }+}+pub fn start_clip_server() {thread::spawn(|| {- let server = match Server::http("127.0.0.1:19827") {- Ok(s) => s,- Err(e) => {- eprintln!("Failed to start clip server: {}", e);- return;- }- };+ let mut restart_count: u32 = 0;- println!("Clip server listening on http://127.0.0.1:19827");+ loop {+ // Try to bind the port with retries+ let server = {+ let mut last_err = String::new();+ let mut bound = None;+ for attempt in 1..=MAX_BIND_RETRIES {+ match Server::http(format!("127.0.0.1:{}", PORT)) {+ Ok(s) => {+ bound = Some(s);+ break;+ }+ Err(e) => {+ last_err = format!("{}", e);+ eprintln!(+ "[Clip Server] Bind attempt {}/{} failed: {}",+ attempt, MAX_BIND_RETRIES, e+ );+ if attempt < MAX_BIND_RETRIES {+ thread::sleep(std::time::Duration::from_secs(BIND_RETRY_DELAY_SECS));+ }+ }+ }+ }+ match bound {+ Some(s) => s,+ None => {+ eprintln!(+ "[Clip Server] Port {} unavailable after {} attempts: {}",+ PORT, MAX_BIND_RETRIES, last_err+ );+ DAEMON_STATUS.store(2, Ordering::Relaxed); // port_conflict+ return; // Don't retry on port conflict — needs user action+ }+ }+ };++ DAEMON_STATUS.store(1, Ordering::Relaxed); // running+ restart_count = 0; // Reset on successful bind+ println!("[Clip Server] Listening on http://127.0.0.1:{}", PORT);for mut request in server.incoming_requests() {let cors_headers = vec![@@ -163,6 +215,25 @@ pub fn start_clip_server() {}}}++ // Server loop exited (shouldn't happen normally)+ DAEMON_STATUS.store(3, Ordering::Relaxed); // error+ restart_count += 1;++ if restart_count >= MAX_RESTART_RETRIES {+ eprintln!(+ "[Clip Server] Exceeded max restarts ({}). Giving up.",+ MAX_RESTART_RETRIES+ );+ return;+ }++ eprintln!(+ "[Clip Server] Crashed. Restarting in {}s (attempt {}/{})",+ RESTART_DELAY_SECS, restart_count, MAX_RESTART_RETRIES+ );+ thread::sleep(std::time::Duration::from_secs(RESTART_DELAY_SECS));+ }});}diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rsindex 245a160d..b678aec5 100644--- a/src-tauri/src/lib.rs+++ b/src-tauri/src/lib.rs@@ -2,6 +2,11 @@ mod clip_server;mod commands;mod types;+#[tauri::command]+fn clip_server_status() -> String {+ clip_server::get_daemon_status().to_string()+}+#[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {clip_server::start_clip_server();@@ -22,6 +27,7 @@ pub fn run() {commands::fs::create_directory,commands::project::create_project,commands::project::open_project,+ clip_server_status,commands::vectorstore::vector_upsert,commands::vectorstore::vector_search,commands::vectorstore::vector_delete,diff --git a/src/commands/fs.ts b/src/commands/fs.tsindex 311b0f58..a8d31027 100644--- a/src/commands/fs.ts+++ b/src/commands/fs.ts@@ -49,3 +49,7 @@ export async function createProject(export async function openProject(path: string): Promise<WikiProject> {return invoke<WikiProject>("open_project", { path })}++export async function clipServerStatus(): Promise<string> {+ return invoke<string>("clip_server_status")+}diff --git a/src/components/layout/icon-sidebar.tsx b/src/components/layout/icon-sidebar.tsxindex c0ccdab7..240e85a4 100644--- a/src/components/layout/icon-sidebar.tsx+++ b/src/components/layout/icon-sidebar.tsx@@ -1,3 +1,4 @@+import { useState, useEffect } from "react"import {FileText, FolderOpen, Search, Network, ClipboardCheck, Settings, ArrowLeftRight, ClipboardList, Globe,} from "lucide-react"@@ -33,6 +34,23 @@ export function IconSidebar({ onSwitchProject }: IconSidebarProps) {const researchActiveCount = useResearchStore((s) => s.tasks.filter((t) => t.status !== "done" && t.status !== "error").length)const toggleResearchPanel = useResearchStore((s) => s.setPanelOpen)+ // Daemon health check+ const [daemonStatus, setDaemonStatus] = useState<string>("starting")+ useEffect(() => {+ const check = async () => {+ try {+ const { clipServerStatus } = await import("@/commands/fs")+ const status = await clipServerStatus()+ setDaemonStatus(status)+ } catch {+ setDaemonStatus("error")+ }+ }+ check()+ const interval = setInterval(check, 30000)+ return () => clearInterval(interval)+ }, [])+return (<TooltipProvider delayDuration={300}><div className="flex h-full w-12 flex-col items-center border-r bg-muted/50 py-2">@@ -89,8 +107,27 @@ export function IconSidebar({ onSwitchProject }: IconSidebarProps) {<TooltipContent side="right">Deep Research</TooltipContent></Tooltip></div>- {/* Bottom: settings + switch project */}+ {/* Bottom: daemon status + settings + switch project */}<div className="flex flex-col items-center gap-1 pb-1">+ {/* Daemon status indicator */}+ {daemonStatus !== "running" && (+ <Tooltip>+ <TooltipTrigger className="flex h-6 w-6 items-center justify-center">+ <span+ className={`h-2.5 w-2.5 rounded-full ${+ daemonStatus === "starting" ? "bg-amber-400 animate-pulse" :+ daemonStatus === "port_conflict" ? "bg-red-500" :+ "bg-red-500 animate-pulse"+ }`}+ />+ </TooltipTrigger>+ <TooltipContent side="right">+ {daemonStatus === "starting" && "Clip server starting..."}+ {daemonStatus === "port_conflict" && "Port 19827 is occupied. Web Clipper unavailable."}+ {daemonStatus === "error" && "Clip server error. Restarting..."}+ </TooltipContent>+ </Tooltip>+ )}<Tooltip><TooltipTriggeronClick={() => setActiveView("settings")}