Skip to content

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: Extension now shows project picker for multi-project support

nash_su1d8215a6d199
diff --git a/extension/popup.html b/extension/popup.html
index 4545c675..e1de9283 100644
--- a/extension/popup.html
+++ b/extension/popup.html
@@ -5,7 +5,7 @@
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
- width: 320px;
+ width: 340px;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
font-size: 13px;
color: #1a1a2e;
@@ -42,7 +42,7 @@
text-transform: uppercase;
margin-bottom: 4px;
}
- .field input, .field textarea {
+ .field input, .field textarea, .field select {
width: 100%;
padding: 8px;
border: 1px solid #e5e7eb;
@@ -50,12 +50,14 @@
font-size: 13px;
font-family: inherit;
outline: none;
+ background: white;
}
- .field input:focus, .field textarea:focus {
+ .field input:focus, .field textarea:focus, .field select:focus {
border-color: #6366f1;
box-shadow: 0 0 0 2px rgba(99,102,241,0.1);
}
.field textarea { resize: vertical; min-height: 60px; }
+ .field select { cursor: pointer; }
.preview {
padding: 8px;
background: #f3f4f6;
@@ -93,6 +95,14 @@
color: #9ca3af;
text-align: center;
}
+ .project-badge {
+ display: inline-block;
+ font-size: 10px;
+ background: rgba(255,255,255,0.2);
+ padding: 2px 6px;
+ border-radius: 4px;
+ margin-left: auto;
+ }
</style>
</head>
<body>
@@ -104,6 +114,13 @@
<div class="content">
<div id="statusBar" class="status disconnected">Checking connection...</div>
+ <div class="field">
+ <label>Save to Project</label>
+ <select id="projectSelect">
+ <option value="">Loading projects...</option>
+ </select>
+ </div>
+
<div class="field">
<label>Title</label>
<input type="text" id="titleInput" placeholder="Page title">
@@ -125,7 +142,7 @@
</div>
<div class="footer">
- Content will be saved to your LLM Wiki project
+ Content will be saved and auto-ingested into your wiki
</div>
<script src="popup.js"></script>
diff --git a/extension/popup.js b/extension/popup.js
index a0c453e3..a1abdc40 100644
--- a/extension/popup.js
+++ b/extension/popup.js
@@ -5,11 +5,12 @@ const titleInput = document.getElementById("titleInput");
const urlPreview = document.getElementById("urlPreview");
const contentPreview = document.getElementById("contentPreview");
const clipBtn = document.getElementById("clipBtn");
+const projectSelect = document.getElementById("projectSelect");
let extractedContent = "";
let pageUrl = "";
-// Check if LLM Wiki app is running
+// Check connection and load projects
async function checkConnection() {
try {
const res = await fetch(`${API_URL}/status`, { method: "GET" });
@@ -17,6 +18,7 @@ async function checkConnection() {
if (data.ok) {
statusBar.className = "status connected";
statusBar.textContent = "✓ Connected to LLM Wiki";
+ await loadProjects();
return true;
}
} catch {
@@ -25,9 +27,46 @@ async function checkConnection() {
statusBar.className = "status disconnected";
statusBar.textContent = "✗ LLM Wiki app is not running";
clipBtn.disabled = true;
+ projectSelect.innerHTML = '<option value="">App not running</option>';
return false;
}
+// Load project list from server
+async function loadProjects() {
+ try {
+ const res = await fetch(`${API_URL}/projects`, { method: "GET" });
+ const data = await res.json();
+ if (data.ok && data.projects) {
+ projectSelect.innerHTML = "";
+
+ if (data.projects.length === 0) {
+ projectSelect.innerHTML = '<option value="">No projects found</option>';
+ return;
+ }
+
+ for (const proj of data.projects) {
+ const opt = document.createElement("option");
+ opt.value = proj.path;
+ opt.textContent = proj.name + (proj.current ? " (current)" : "");
+ if (proj.current) opt.selected = true;
+ projectSelect.appendChild(opt);
+ }
+ }
+ } catch {
+ // Fallback: try getting just current project
+ try {
+ const res = await fetch(`${API_URL}/project`, { method: "GET" });
+ const data = await res.json();
+ if (data.ok && data.path) {
+ const name = data.path.split("/").pop() || data.path;
+ projectSelect.innerHTML = `<option value="${data.path}">${name}</option>`;
+ }
+ } catch {
+ projectSelect.innerHTML = '<option value="">No projects</option>';
+ }
+ }
+}
+
// Extract content from current tab
async function extractContent() {
try {
@@ -38,11 +77,9 @@ async function extractContent() {
titleInput.value = tab.title || "Untitled";
urlPreview.textContent = pageUrl;
- // Inject content extraction script
const results = await chrome.scripting.executeScript({
target: { tabId: tab.id },
func: () => {
- // Try to get article content using common selectors
const selectors = [
"article",
'[role="main"]',
@@ -59,16 +96,9 @@ async function extractContent() {
article = document.querySelector(sel);
if (article) break;
}
+ if (!article) article = document.body;
- // Fallback to body
- if (!article) {
- article = document.body;
- }
-
- // Clone to avoid modifying the page
const clone = article.cloneNode(true);
-
- // Remove unwanted elements
const removeSelectors = [
"script", "style", "nav", "header", "footer",
".sidebar", ".nav", ".menu", ".ad", ".advertisement",
@@ -79,19 +109,12 @@ async function extractContent() {
clone.querySelectorAll(sel).forEach((el) => el.remove());
}
- // Convert to simplified markdown-like text
- function nodeToText(node, depth = 0) {
- if (node.nodeType === Node.TEXT_NODE) {
- return node.textContent.trim();
- }
+ function nodeToText(node) {
+ if (node.nodeType === Node.TEXT_NODE) return node.textContent.trim();
if (node.nodeType !== Node.ELEMENT_NODE) return "";
const tag = node.tagName.toLowerCase();
- const children = Array.from(node.childNodes)
- .map((c) => nodeToText(c, depth))
- .filter((t) => t)
- .join(" ");
-
+ const children = Array.from(node.childNodes).map((c) => nodeToText(c)).filter((t) => t).join(" ");
if (!children.trim()) return "";
switch (tag) {
@@ -106,18 +129,10 @@ async function extractContent() {
case "pre": case "code": return `\n\n\`\`\`\n${children}\n\`\`\`\n\n`;
case "strong": case "b": return `**${children}**`;
case "em": case "i": return `*${children}*`;
- case "a": {
- const href = node.getAttribute("href") || "";
- return `[${children}](${href})`;
- }
- case "img": {
- const alt = node.getAttribute("alt") || "image";
- const src = node.getAttribute("src") || "";
- return `\n\n![${alt}](${src})\n\n`;
- }
+ case "a": return `[${children}](${node.getAttribute("href") || ""})`;
+ case "img": return `\n\n![${node.getAttribute("alt") || "image"}](${node.getAttribute("src") || ""})\n\n`;
case "br": return "\n";
case "hr": return "\n\n---\n\n";
- case "table": return `\n\n${children}\n\n`;
case "tr": return `| ${children} |\n`;
case "th": case "td": return ` ${children} |`;
default: return children;
@@ -125,13 +140,12 @@ async function extractContent() {
}
let text = nodeToText(clone);
- // Clean up excessive whitespace
text = text.replace(/\n{3,}/g, "\n\n").trim();
return text;
},
});
- if (results && results[0] && results[0].result) {
+ if (results?.[0]?.result) {
extractedContent = results[0].result;
const preview = extractedContent.slice(0, 200);
contentPreview.textContent = preview + (extractedContent.length > 200 ? "..." : "");
@@ -144,8 +158,15 @@ async function extractContent() {
}
}
-// Send clip to LLM Wiki
+// Send clip to selected project
async function sendClip() {
+ const selectedProject = projectSelect.value;
+ if (!selectedProject) {
+ statusBar.className = "status error";
+ statusBar.textContent = "✗ Please select a project";
+ return;
+ }
+
clipBtn.disabled = true;
statusBar.className = "status sending";
statusBar.textContent = "⏳ Sending to LLM Wiki...";
@@ -158,14 +179,16 @@ async function sendClip() {
title: titleInput.value,
url: pageUrl,
content: extractedContent,
+ projectPath: selectedProject,
}),
});
const data = await res.json();
if (data.ok) {
+ const projectName = projectSelect.options[projectSelect.selectedIndex]?.textContent || "project";
statusBar.className = "status success";
- statusBar.textContent = `✓ Saved: ${data.path}`;
+ statusBar.textContent = `✓ Saved to ${projectName}`;
clipBtn.textContent = "✓ Clipped!";
clipBtn.disabled = true;
} else {
diff --git a/src-tauri/src/clip_server.rs b/src-tauri/src/clip_server.rs
index be0d49cf..9c3705cc 100644
--- a/src-tauri/src/clip_server.rs
+++ b/src-tauri/src/clip_server.rs
@@ -3,6 +3,7 @@ use std::thread;
use tiny_http::{Header, Method, Response, Server};
static CURRENT_PROJECT: Mutex<String> = Mutex::new(String::new());
+static ALL_PROJECTS: Mutex<Vec<(String, String)>> = Mutex::new(Vec::new()); // (name, path)
pub fn start_clip_server() {
thread::spawn(|| {
@@ -79,6 +80,41 @@ pub fn start_clip_server() {
}
let _ = request.respond(response);
}
+ (&Method::Get, "/projects") => {
+ let projects = ALL_PROJECTS.lock().unwrap().clone();
+ let current = CURRENT_PROJECT.lock().unwrap().clone();
+ let items: Vec<String> = projects.iter()
+ .map(|(name, path)| format!(r#"{{"name":"{}","path":"{}","current":{}}}"#,
+ name.replace('"', r#"\""#),
+ path.replace('"', r#"\""#),
+ path == &current))
+ .collect();
+ let body = format!(r#"{{"ok":true,"projects":[{}]}}"#, items.join(","));
+ let mut response = Response::from_string(body);
+ for h in &cors_headers { response.add_header(h.clone()); }
+ let _ = request.respond(response);
+ }
+ (&Method::Post, "/projects") => {
+ let mut body = String::new();
+ if request.as_reader().read_to_string(&mut body).is_ok() {
+ if let Ok(parsed) = serde_json::from_str::<serde_json::Value>(&body) {
+ if let Some(arr) = parsed["projects"].as_array() {
+ let mut projects = ALL_PROJECTS.lock().unwrap();
+ projects.clear();
+ for item in arr {
+ let name = item["name"].as_str().unwrap_or("").to_string();
+ let path = item["path"].as_str().unwrap_or("").to_string();
+ if !path.is_empty() {
+ projects.push((name, path));
+ }
+ }
+ }
+ }
+ }
+ let mut response = Response::from_string(r#"{"ok":true}"#);
+ for h in &cors_headers { response.add_header(h.clone()); }
+ let _ = request.respond(response);
+ }
(&Method::Post, "/clip") => {
let mut body = String::new();
if let Err(e) = request.as_reader().read_to_string(&mut body) {
diff --git a/src/App.tsx b/src/App.tsx
index afdf9c20..b2eecdcb 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -5,7 +5,7 @@ import { useWikiStore } from "@/stores/wiki-store"
import { useReviewStore } from "@/stores/review-store"
import { useChatStore } from "@/stores/chat-store"
import { listDirectory, openProject } from "@/commands/fs"
-import { getLastProject, saveLastProject, loadLlmConfig, loadLanguage, loadSearchApiConfig } from "@/lib/project-store"
+import { getLastProject, getRecentProjects, saveLastProject, loadLlmConfig, loadLanguage, loadSearchApiConfig } from "@/lib/project-store"
import { loadReviewItems, loadChatHistory } from "@/lib/persist"
import { setupAutoSave } from "@/lib/auto-save"
import { AppLayout } from "@/components/layout/app-layout"
@@ -66,12 +66,22 @@ function App() {
setSelectedFile(null)
setActiveView("wiki")
await saveLastProject(proj)
- // Notify local clip server of the current project path (fire-and-forget)
+ // Notify local clip server of the current project + all recent projects
fetch("http://127.0.0.1:19827/project", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ path: proj.path }),
}).catch(() => {})
+
+ // Send all recent projects to clip server for extension project picker
+ getRecentProjects().then((recents) => {
+ const projects = recents.map((p) => ({ name: p.name, path: p.path }))
+ fetch("http://127.0.0.1:19827/projects", {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ projects }),
+ }).catch(() => {})
+ }).catch(() => {})
try {
const tree = await listDirectory(proj.path)
setFileTree(tree)