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
refactor: make chat a standalone view
nash_su9f386eebe74a
diff --git a/src/components/chat/chat-message.tsx b/src/components/chat/chat-message.tsxindex 904dc0ea..aa7f6bf7 100644--- a/src/components/chat/chat-message.tsx+++ b/src/components/chat/chat-message.tsx@@ -354,8 +354,7 @@ interface CitedImageInfo {function CitedReferencesPanel({ content, savedReferences }: { content: string; savedReferences?: CitedPage[] }) {const project = useWikiStore((s) => s.project)- const setSelectedFile = useWikiStore((s) => s.setSelectedFile)- const setFileContent = useWikiStore((s) => s.setFileContent)+ const openFileInPreview = useWikiStore((s) => s.openFileInPreview)const setExternalPreview = useWikiStore((s) => s.setExternalPreview)const setPendingScrollImageSrc = useWikiStore((s) => s.setPendingScrollImageSrc)const [expanded, setExpanded] = useState(false)@@ -449,8 +448,7 @@ function CitedReferencesPanel({ content, savedReferences }: { content: string; stry {const content = await readFile(rawPath)setPendingScrollImageSrc(imageUrlToAbsolute(firstUrl, pp))- setSelectedFile(rawPath)- setFileContent(content)+ openFileInPreview(rawPath, content)console.log(`[refs:image-jump] ${firstUrl} → raw source ${rawPath}`)return} catch (err) {@@ -463,13 +461,12 @@ function CitedReferencesPanel({ content, savedReferences }: { content: string; stry {const content = await readFile(`${pp}/${fallbackPath}`)setPendingScrollImageSrc(firstUrl)- setSelectedFile(`${pp}/${fallbackPath}`)- setFileContent(content)+ openFileInPreview(`${pp}/${fallbackPath}`, content)} catch (err) {console.warn(`[refs:image-jump] fallback also failed:`, err)}},- [project, setPendingScrollImageSrc, setSelectedFile, setFileContent],+ [project, setPendingScrollImageSrc, openFileInPreview],)if (citedPages.length === 0) return null@@ -516,8 +513,7 @@ function CitedReferencesPanel({ content, savedReferences }: { content: string; s"",page.snippet?.trim() || "(No fragment returned by AnyTXT.)",].join("\n")- setSelectedFile(previewPath)- setFileContent(previewContent)+ openFileInPreview(previewPath, previewContent)setExternalPreview({title: page.title,path: previewPath,@@ -549,14 +545,14 @@ function CitedReferencesPanel({ content, savedReferences }: { content: string; s]for (const candidate of candidates) {try {- await readFile(candidate)- setSelectedFile(candidate)+ const content = await readFile(candidate)+ openFileInPreview(candidate, content)return} catch {// try next}}- setSelectedFile(`${pp}/${page.path}`)+ openFileInPreview(`${pp}/${page.path}`, `Unable to load: ${page.path}`)}return (// Outer is a div, NOT a button — we have two click@@ -955,9 +951,7 @@ function processContent(text: string): string {function WikiLink({ pageName, children }: { pageName: string; children: React.ReactNode }) {const project = useWikiStore((s) => s.project)- const setSelectedFile = useWikiStore((s) => s.setSelectedFile)- const setFileContent = useWikiStore((s) => s.setFileContent)- const setActiveView = useWikiStore((s) => s.setActiveView)+ const openFileInPreview = useWikiStore((s) => s.openFileInPreview)const [exists, setExists] = useState<boolean | null>(null)const resolvedPath = useRef<string | null>(null)@@ -998,13 +992,11 @@ function WikiLink({ pageName, children }: { pageName: string; children: React.Reif (!resolvedPath.current) returntry {const content = await readFile(resolvedPath.current)- setSelectedFile(resolvedPath.current)- setFileContent(content)- setActiveView("wiki")+ openFileInPreview(resolvedPath.current, content)} catch {// ignore}- }, [setSelectedFile, setFileContent, setActiveView])+ }, [openFileInPreview])if (exists === false) {return (diff --git a/src/components/editor/frontmatter-panel.tsx b/src/components/editor/frontmatter-panel.tsxindex 52951177..0759fc7b 100644--- a/src/components/editor/frontmatter-panel.tsx+++ b/src/components/editor/frontmatter-panel.tsx@@ -42,7 +42,7 @@ const TOP_LEVEL_KEYS = new Set([export function FrontmatterPanel({ data }: FrontmatterPanelProps) {const project = useWikiStore((s) => s.project)const fileTree = useWikiStore((s) => s.fileTree)- const setSelectedFile = useWikiStore((s) => s.setSelectedFile)+ const openPathInPreview = useWikiStore((s) => s.openPathInPreview)const title = stringValue(data.title)const type = stringValue(data.type)@@ -79,7 +79,7 @@ export function FrontmatterPanel({ data }: FrontmatterPanelProps) {function handleNavigate(path: string | null) {if (!path) return- setSelectedFile(path)+ openPathInPreview(path)}return (diff --git a/src/components/editor/wiki-reader.tsx b/src/components/editor/wiki-reader.tsxindex 3bc04610..a1cf4e7b 100644--- a/src/components/editor/wiki-reader.tsx+++ b/src/components/editor/wiki-reader.tsx@@ -34,13 +34,13 @@ interface WikiReaderProps {* never serialize back to disk, transforming for display is safe.** Wikilink anchor clicks are intercepted: `#slug` is resolved- * against the project's wiki tree and routed to setSelectedFile,+ * against the project's wiki tree and routed to the wiki preview,* giving the user single-click navigation between pages.*/export function WikiReader({ body, filePath }: WikiReaderProps) {const project = useWikiStore((s) => s.project)const fileTree = useWikiStore((s) => s.fileTree)- const setSelectedFile = useWikiStore((s) => s.setSelectedFile)+ const openPathInPreview = useWikiStore((s) => s.openPathInPreview)// Image embeds (`![[…]]`) must be rewritten BEFORE the generic// wikilink pass, otherwise the embed target gets mangled into a@@ -75,7 +75,7 @@ export function WikiReader({ body, filePath }: WikiReaderProps) {}})()const path = resolveRelatedSlug(fileTree, slug, wikiRoot)- if (path) setSelectedFile(path)+ if (path) openPathInPreview(path)}return (diff --git a/src/components/graph/graph-view.tsx b/src/components/graph/graph-view.tsxindex dfdfeba3..e60408ac 100644--- a/src/components/graph/graph-view.tsx+++ b/src/components/graph/graph-view.tsx@@ -538,8 +538,7 @@ export function GraphView() {const { t } = useTranslation()const project = useWikiStore((s) => s.project)const dataVersion = useWikiStore((s) => s.dataVersion)- const setSelectedFile = useWikiStore((s) => s.setSelectedFile)- const setFileContent = useWikiStore((s) => s.setFileContent)+ const openFileInPreview = useWikiStore((s) => s.openFileInPreview)const isDarkMode = useResolvedDarkMode()const graphPalette = useMemo(() => graphThemePalette(isDarkMode), [isDarkMode])@@ -648,13 +647,12 @@ export function GraphView() {if (!node) returntry {const content = await readFile(node.path)- setSelectedFile(node.path)- setFileContent(content)+ openFileInPreview(node.path, content)} catch (err) {console.error("Failed to open wiki page:", err)}},- [nodes, setSelectedFile, setFileContent],+ [nodes, openFileInPreview],)const handleNodeContextMenu = useCallback((nodeId: string, x: number, y: number) => {diff --git a/src/components/layout/activity-panel.tsx b/src/components/layout/activity-panel.tsxindex 842501db..58b24021 100644--- a/src/components/layout/activity-panel.tsx+++ b/src/components/layout/activity-panel.tsx@@ -430,7 +430,7 @@ function FileSyncRow({ task, onRetry, onIgnore }: { task: FileChangeTask; onRetr}function ActivityRow({ item, onCancel }: { item: ActivityItem; onCancel?: () => void }) {- const setSelectedFile = useWikiStore((s) => s.setSelectedFile)+ const openPathInPreview = useWikiStore((s) => s.openPathInPreview)const project = useWikiStore((s) => s.project)function handleFileClick(filePath: string) {@@ -439,7 +439,7 @@ function ActivityRow({ item, onCancel }: { item: ActivityItem; onCancel?: () =>const fullPath = isAbsolutePath(filePath)? normalizePath(filePath): `${pp}/${filePath}`- setSelectedFile(fullPath)+ openPathInPreview(fullPath)}return (diff --git a/src/components/layout/app-layout-visibility.test.ts b/src/components/layout/app-layout-visibility.test.tsnew file mode 100644index 00000000..8e9a05ad--- /dev/null+++ b/src/components/layout/app-layout-visibility.test.ts@@ -0,0 +1,29 @@+import { describe, expect, it } from "vitest"+import { getAppLayoutVisibility } from "./app-layout-visibility"++describe("getAppLayoutVisibility", () => {+ it("keeps chat as a standalone view even when research panel is open", () => {+ expect(getAppLayoutVisibility("chat", true)).toEqual({+ showLeftPanel: false,+ hasRightPanel: false,+ })+ })++ it("keeps settings as a standalone view even when research panel is open", () => {+ expect(getAppLayoutVisibility("settings", true)).toEqual({+ showLeftPanel: false,+ hasRightPanel: false,+ })+ })++ it("shows the project side panel and optional research panel in workspace views", () => {+ expect(getAppLayoutVisibility("wiki", false)).toEqual({+ showLeftPanel: true,+ hasRightPanel: false,+ })+ expect(getAppLayoutVisibility("search", true)).toEqual({+ showLeftPanel: true,+ hasRightPanel: true,+ })+ })+})diff --git a/src/components/layout/app-layout-visibility.ts b/src/components/layout/app-layout-visibility.tsnew file mode 100644index 00000000..d3f3e39e--- /dev/null+++ b/src/components/layout/app-layout-visibility.ts@@ -0,0 +1,13 @@+import type { WikiState } from "@/stores/wiki-store"+import { isStandaloneView } from "./research-panel-nav"++export function getAppLayoutVisibility(+ activeView: WikiState["activeView"],+ researchPanelOpen: boolean,+): { showLeftPanel: boolean; hasRightPanel: boolean } {+ const isStandalone = isStandaloneView(activeView)+ return {+ showLeftPanel: !isStandalone,+ hasRightPanel: !isStandalone && researchPanelOpen,+ }+}diff --git a/src/components/layout/app-layout.tsx b/src/components/layout/app-layout.tsxindex 9a2870ba..b84168f7 100644--- a/src/components/layout/app-layout.tsx+++ b/src/components/layout/app-layout.tsx@@ -6,11 +6,11 @@ import { IconSidebar } from "./icon-sidebar"import { UpdateBanner } from "./update-banner"import { SidebarPanel } from "./sidebar-panel"import { ContentArea } from "./content-area"-import { PreviewPanel } from "./preview-panel"import { ResearchPanel } from "./research-panel"import { ActivityPanel } from "./activity-panel"import { useResearchStore } from "@/stores/research-store"import { ErrorBoundary } from "@/components/error-boundary"+import { getAppLayoutVisibility } from "./app-layout-visibility"interface AppLayoutProps {onSwitchProject: () => void@@ -18,7 +18,6 @@ interface AppLayoutProps {export function AppLayout({ onSwitchProject }: AppLayoutProps) {const project = useWikiStore((s) => s.project)- const selectedFile = useWikiStore((s) => s.selectedFile)const activeView = useWikiStore((s) => s.activeView)const researchPanelOpen = useResearchStore((s) => s.panelOpen)const setFileTree = useWikiStore((s) => s.setFileTree)@@ -83,12 +82,10 @@ export function AppLayout({ onSwitchProject }: AppLayoutProps) {[])- // Settings is a full-width admin view — the file tree / activity panel- // are irrelevant there and their narrow column makes the settings form- // cramped. Hide both the left sidebar (and the file preview on the- // right) so the settings screen uses the whole content area.- const isSettings = activeView === "settings"- const hasRightPanel = !isSettings && !!(selectedFile || researchPanelOpen)+ // Settings and Chat are standalone views. Hide the project file tree,+ // activity strip, and optional right research panel there so those+ // screens use the whole work area.+ const { showLeftPanel, hasRightPanel } = getAppLayoutVisibility(activeView, researchPanelOpen)return (// Outer column layout: full-width update banner on top (when an@@ -101,60 +98,49 @@ export function AppLayout({ onSwitchProject }: AppLayoutProps) {<div className="flex min-h-0 flex-1"><IconSidebar onSwitchProject={onSwitchProject} /><div ref={containerRef} className="relative flex min-w-0 flex-1 overflow-hidden">- {!isSettings && (- <>- {/* Left: File tree + Activity */}- <div- className="flex shrink-0 flex-col overflow-hidden border-r"- style={{ width: leftWidth }}- >- <div className="flex-1 overflow-hidden">- <SidebarPanel />+ {showLeftPanel && (+ <>+ {/* Left: File tree + Activity */}+ <div+ className="flex shrink-0 flex-col overflow-hidden border-r"+ style={{ width: leftWidth }}+ >+ <div className="flex-1 overflow-hidden">+ <SidebarPanel />+ </div>+ <ActivityPanel /></div>- <ActivityPanel />- </div>- <div- className="w-1.5 shrink-0 cursor-col-resize bg-border/40 transition-colors hover:bg-primary/30 active:bg-primary/40"- onMouseDown={startDrag("left")}- />- </>- )}+ <div+ className="w-1.5 shrink-0 cursor-col-resize bg-border/40 transition-colors hover:bg-primary/30 active:bg-primary/40"+ onMouseDown={startDrag("left")}+ />+ </>+ )}- {/* Center: Chat or view (sources/settings/review) */}- <div className="min-w-0 flex-1 overflow-hidden">- <ErrorBoundary>- <ContentArea />- </ErrorBoundary>- </div>+ {/* Center: Chat, wiki preview, or tool view */}+ <div className="min-w-0 flex-1 overflow-hidden">+ <ErrorBoundary>+ <ContentArea />+ </ErrorBoundary>+ </div>- {/* Right panels */}- {hasRightPanel && (- <>- <div- className="w-1.5 shrink-0 cursor-col-resize bg-border/40 transition-colors hover:bg-primary/30 active:bg-primary/40"- onMouseDown={startDrag("right")}- />- <div- className="flex shrink-0 flex-col overflow-hidden border-l"- style={{ width: rightWidth }}- >- <ErrorBoundary>- {/* File preview on top (if file selected) */}- {selectedFile && (- <div className={researchPanelOpen ? "flex-1 overflow-hidden border-b" : "flex-1 overflow-hidden"}>- <PreviewPanel />- </div>- )}- {/* Research panel on bottom (if open) */}- {researchPanelOpen && (- <div className={selectedFile ? "h-1/2 shrink-0 overflow-hidden" : "flex-1 overflow-hidden"}>- <ResearchPanel />- </div>- )}- </ErrorBoundary>- </div>- </>- )}+ {/* Right panels */}+ {hasRightPanel && (+ <>+ <div+ className="w-1.5 shrink-0 cursor-col-resize bg-border/40 transition-colors hover:bg-primary/30 active:bg-primary/40"+ onMouseDown={startDrag("right")}+ />+ <div+ className="flex shrink-0 flex-col overflow-hidden border-l"+ style={{ width: rightWidth }}+ >+ <ErrorBoundary>+ <ResearchPanel />+ </ErrorBoundary>+ </div>+ </>+ )}</div></div></div>diff --git a/src/components/layout/chat-bar.tsx b/src/components/layout/chat-bar.tsxdeleted file mode 100644index ea948af7..00000000--- a/src/components/layout/chat-bar.tsx+++ /dev/null@@ -1,41 +0,0 @@-import { MessageSquare, ChevronUp, ChevronDown } from "lucide-react"-import { useWikiStore } from "@/stores/wiki-store"-import { ChatPanel } from "@/components/chat/chat-panel"--export function ChatBar() {- const chatExpanded = useWikiStore((s) => s.chatExpanded)- const setChatExpanded = useWikiStore((s) => s.setChatExpanded)-- if (!chatExpanded) {- return (- <button- onClick={() => setChatExpanded(true)}- className="flex w-full items-center justify-between border-t px-4 py-2 text-sm text-muted-foreground hover:bg-accent/50"- >- <span className="flex items-center gap-2">- <MessageSquare className="h-4 w-4" />- CHAT- </span>- <ChevronUp className="h-4 w-4" />- </button>- )- }-- return (- <div className="flex h-full flex-col">- <button- onClick={() => setChatExpanded(false)}- className="flex w-full items-center justify-between border-b px-4 py-2 text-sm text-muted-foreground hover:bg-accent/50"- >- <span className="flex items-center gap-2">- <MessageSquare className="h-4 w-4" />- CHAT- </span>- <ChevronDown className="h-4 w-4" />- </button>- <div className="flex-1 overflow-hidden">- <ChatPanel />- </div>- </div>- )-}diff --git a/src/components/layout/content-area.tsx b/src/components/layout/content-area.tsxindex ac026369..234563e9 100644--- a/src/components/layout/content-area.tsx+++ b/src/components/layout/content-area.tsx@@ -6,11 +6,16 @@ import { ReviewView } from "@/components/review/review-view"import { LintView } from "@/components/lint/lint-view"import { SearchView } from "@/components/search/search-view"import { GraphView } from "@/components/graph/graph-view"+import { PreviewPanel } from "./preview-panel"export function ContentArea() {const activeView = useWikiStore((s) => s.activeView)switch (activeView) {+ case "chat":+ return <ChatPanel />+ case "wiki":+ return <PreviewPanel />case "settings":return <SettingsView />case "sources":@@ -24,6 +29,6 @@ export function ContentArea() {case "graph":return <GraphView />default:- return <ChatPanel />+ return <PreviewPanel />}}diff --git a/src/components/layout/file-tree.tsx b/src/components/layout/file-tree.tsxindex 185cae63..22887e1f 100644--- a/src/components/layout/file-tree.tsx+++ b/src/components/layout/file-tree.tsx@@ -10,7 +10,7 @@ import { openProjectFolder } from "@/commands/fs"function TreeNode({ node, depth }: { node: FileNode; depth: number }) {const [expanded, setExpanded] = useState(depth < 1)const selectedFile = useWikiStore((s) => s.selectedFile)- const setSelectedFile = useWikiStore((s) => s.setSelectedFile)+ const openPathInPreview = useWikiStore((s) => s.openPathInPreview)const isSelected = selectedFile === node.pathconst paddingLeft = 12 + depth * 16@@ -40,7 +40,7 @@ function TreeNode({ node, depth }: { node: FileNode; depth: number }) {return (<button- onClick={() => setSelectedFile(node.path)}+ onClick={() => openPathInPreview(node.path)}className={`flex w-full items-center gap-1 py-1 text-sm ${isSelected? "bg-accent text-accent-foreground"diff --git a/src/components/layout/icon-sidebar.tsx b/src/components/layout/icon-sidebar.tsxindex 576a64f3..c0575b51 100644--- a/src/components/layout/icon-sidebar.tsx+++ b/src/components/layout/icon-sidebar.tsx@@ -1,6 +1,6 @@import { useState, useEffect } from "react"import {- FileText, FolderOpen, Search, Network, ClipboardCheck, Settings, ArrowLeftRight, ClipboardList, Globe,+ FileText, FolderOpen, Search, Network, ClipboardCheck, Settings, ArrowLeftRight, ClipboardList, Globe, MessageSquare,} from "lucide-react"import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"import { useWikiStore } from "@/stores/wiki-store"@@ -10,10 +10,15 @@ import { useUpdateStore, hasAvailableUpdate } from "@/stores/update-store"import { useTranslation } from "react-i18next"import logoImg from "@/assets/logo.jpg"import type { WikiState } from "@/stores/wiki-store"+import {+ isResearchPanelVisible,+ nextResearchPanelNavState,+} from "./research-panel-nav"type NavView = WikiState["activeView"]const NAV_ITEMS: { view: NavView; icon: typeof FileText; labelKey: string }[] = [+ { view: "chat", icon: MessageSquare, labelKey: "nav.chat" },{ view: "wiki", icon: FileText, labelKey: "nav.wiki" },{ view: "sources", icon: FolderOpen, labelKey: "nav.sources" },{ view: "search", icon: Search, labelKey: "nav.search" },@@ -60,6 +65,12 @@ export function IconSidebar({ onSwitchProject }: IconSidebarProps) {return () => clearInterval(interval)}, [])+ function handleResearchPanelToggle() {+ const next = nextResearchPanelNavState(activeView, researchPanelOpen)+ if (next.activeView !== activeView) setActiveView(next.activeView)+ toggleResearchPanel(next.researchPanelOpen)+ }+return (<TooltipProvider delay={300}><div className="flex h-full w-12 flex-col items-center border-r bg-muted/50 py-2">@@ -99,9 +110,9 @@ export function IconSidebar({ onSwitchProject }: IconSidebarProps) {{/* Deep Research — same row as other nav items */}<Tooltip><TooltipTrigger- onClick={() => toggleResearchPanel(!researchPanelOpen)}+ onClick={handleResearchPanelToggle}className={`relative flex h-10 w-10 items-center justify-center rounded-md transition-colors ${- researchPanelOpen+ isResearchPanelVisible(activeView, researchPanelOpen)? "bg-accent text-accent-foreground": "text-muted-foreground hover:bg-accent/50 hover:text-accent-foreground"}`}diff --git a/src/components/layout/knowledge-tree.tsx b/src/components/layout/knowledge-tree.tsxindex dd172b15..16439e74 100644--- a/src/components/layout/knowledge-tree.tsx+++ b/src/components/layout/knowledge-tree.tsx@@ -40,6 +40,7 @@ export function KnowledgeTree() {const project = useWikiStore((s) => s.project)const selectedFile = useWikiStore((s) => s.selectedFile)const setSelectedFile = useWikiStore((s) => s.setSelectedFile)+ const openPathInPreview = useWikiStore((s) => s.openPathInPreview)const fileTree = useWikiStore((s) => s.fileTree)const setFileTree = useWikiStore((s) => s.setFileTree)const bumpDataVersion = useWikiStore((s) => s.bumpDataVersion)@@ -200,7 +201,7 @@ export function KnowledgeTree() {}`}><button- onClick={() => setSelectedFile(page.path)}+ onClick={() => openPathInPreview(page.path)}className={`flex flex-1 items-center gap-1.5 px-2 py-1 text-left text-sm min-w-0 ${isSelected? "text-accent-foreground"@@ -243,7 +244,7 @@ export function KnowledgeTree() {function RawSourcesSection() {const project = useWikiStore((s) => s.project)- const setSelectedFile = useWikiStore((s) => s.setSelectedFile)+ const openPathInPreview = useWikiStore((s) => s.openPathInPreview)const selectedFile = useWikiStore((s) => s.selectedFile)const [expanded, setExpanded] = useState(false)const [sources, setSources] = useState<FileNode[]>([])@@ -280,7 +281,7 @@ function RawSourcesSection() {return (<buttonkey={file.path}- onClick={() => setSelectedFile(file.path)}+ onClick={() => openPathInPreview(file.path)}className={`flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-sm ${isSelected? "bg-accent text-accent-foreground"diff --git a/src/components/layout/preview-panel.tsx b/src/components/layout/preview-panel.tsxindex 68f4e1df..fa9317eb 100644--- a/src/components/layout/preview-panel.tsx+++ b/src/components/layout/preview-panel.tsx@@ -10,6 +10,7 @@ import { getFileName } from "@/lib/path-utils"export function PreviewPanel() {const selectedFile = useWikiStore((s) => s.selectedFile)const fileContent = useWikiStore((s) => s.fileContent)+ const previewContentPath = useWikiStore((s) => s.previewContentPath)const externalPreview = useWikiStore((s) => s.externalPreview)const setFileContent = useWikiStore((s) => s.setFileContent)const setSelectedFile = useWikiStore((s) => s.setSelectedFile)@@ -27,6 +28,10 @@ export function PreviewPanel() {lastLoadedRef.current = ""return}+ if (previewContentPath === selectedFile) {+ lastLoadedRef.current = fileContent+ return+ }if (externalPreview?.path === selectedFile) {lastLoadedRef.current = fileContentreturn@@ -49,7 +54,7 @@ export function PreviewPanel() {lastLoadedRef.current = ""setFileContent(`Error loading file: ${err}`)})- }, [selectedFile, externalPreview, fileContent, setFileContent])+ }, [selectedFile, previewContentPath, externalPreview, setFileContent])const writeNow = useCallback((path: string, markdown: string, syncStore = false) => {writeFile(path, markdown)diff --git a/src/components/layout/research-panel-nav.test.ts b/src/components/layout/research-panel-nav.test.tsnew file mode 100644index 00000000..3d4a905b--- /dev/null+++ b/src/components/layout/research-panel-nav.test.ts@@ -0,0 +1,35 @@+import { describe, expect, it } from "vitest"+import {+ isResearchPanelVisible,+ nextResearchPanelNavState,+} from "./research-panel-nav"++describe("research panel nav state", () => {+ it("switches standalone views to wiki and opens the panel", () => {+ expect(nextResearchPanelNavState("chat", false)).toEqual({+ activeView: "wiki",+ researchPanelOpen: true,+ })+ expect(nextResearchPanelNavState("settings", true)).toEqual({+ activeView: "wiki",+ researchPanelOpen: true,+ })+ })++ it("toggles the panel inside workspace views", () => {+ expect(nextResearchPanelNavState("search", true)).toEqual({+ activeView: "search",+ researchPanelOpen: false,+ })+ expect(nextResearchPanelNavState("graph", false)).toEqual({+ activeView: "graph",+ researchPanelOpen: true,+ })+ })++ it("only marks the panel visible outside standalone views", () => {+ expect(isResearchPanelVisible("chat", true)).toBe(false)+ expect(isResearchPanelVisible("settings", true)).toBe(false)+ expect(isResearchPanelVisible("wiki", true)).toBe(true)+ })+})diff --git a/src/components/layout/research-panel-nav.ts b/src/components/layout/research-panel-nav.tsnew file mode 100644index 00000000..a4d8c1f8--- /dev/null+++ b/src/components/layout/research-panel-nav.ts@@ -0,0 +1,22 @@+import type { WikiState } from "@/stores/wiki-store"++export function isStandaloneView(view: WikiState["activeView"]): boolean {+ return view === "chat" || view === "settings"+}++export function isResearchPanelVisible(+ activeView: WikiState["activeView"],+ researchPanelOpen: boolean,+): boolean {+ return researchPanelOpen && !isStandaloneView(activeView)+}++export function nextResearchPanelNavState(+ activeView: WikiState["activeView"],+ researchPanelOpen: boolean,+): { activeView: WikiState["activeView"]; researchPanelOpen: boolean } {+ if (isStandaloneView(activeView)) {+ return { activeView: "wiki", researchPanelOpen: true }+ }+ return { activeView, researchPanelOpen: !researchPanelOpen }+}diff --git a/src/components/layout/research-panel.tsx b/src/components/layout/research-panel.tsxindex c453648f..5849b0ed 100644--- a/src/components/layout/research-panel.tsx+++ b/src/components/layout/research-panel.tsx@@ -222,8 +222,7 @@ function ResearchTaskCard({ task, onRemove }: { task: ResearchTask; onRemove: (iconst [expanded, setExpanded] = useState(task.status === "synthesizing" || task.status === "searching")- const setSelectedFile = useWikiStore((s) => s.setSelectedFile)- const setFileContent = useWikiStore((s) => s.setFileContent)+ const openFileInPreview = useWikiStore((s) => s.openFileInPreview)const project = useWikiStore((s) => s.project)const statusIcon = {@@ -249,8 +248,7 @@ function ResearchTaskCard({ task, onRemove }: { task: ResearchTask; onRemove: (iconst path = `${normalizePath(project.path)}/${task.savedPath}`try {const content = await readFile(path)- setSelectedFile(path)- setFileContent(content)+ openFileInPreview(path, content)} catch {// ignore}diff --git a/src/components/lint/lint-view.tsx b/src/components/lint/lint-view.tsxindex f2d04c33..c2966620 100644--- a/src/components/lint/lint-view.tsx+++ b/src/components/lint/lint-view.tsx@@ -53,9 +53,7 @@ export function LintView() {const { t } = useTranslation()const project = useWikiStore((s) => s.project)const llmConfig = useWikiStore((s) => s.llmConfig)- const setSelectedFile = useWikiStore((s) => s.setSelectedFile)- const setFileContent = useWikiStore((s) => s.setFileContent)- const setActiveView = useWikiStore((s) => s.setActiveView)+ const openFileInPreview = useWikiStore((s) => s.openFileInPreview)const setFileTree = useWikiStore((s) => s.setFileTree)const bumpDataVersion = useWikiStore((s) => s.bumpDataVersion)@@ -108,19 +106,16 @@ export function LintView() {`${pp}/wiki/${page}`,`${pp}/wiki/${page}.md`,]- setActiveView("wiki")for (const path of candidates) {try {const content = await readFile(path)- setSelectedFile(path)- setFileContent(content)+ openFileInPreview(path, content)return} catch {// try next}}- setSelectedFile(candidates[0])- setFileContent(`Unable to load: ${page}`)+ openFileInPreview(candidates[0], `Unable to load: ${page}`)}async function handleFix(item: LintItem) {diff --git a/src/components/review/review-view.tsx b/src/components/review/review-view.tsxindex fde5ec30..023cd7e9 100644--- a/src/components/review/review-view.tsx+++ b/src/components/review/review-view.tsx@@ -102,8 +102,7 @@ export function ReviewView() {// Refresh treeconst tree = await listDirectory(pp)setFileTree(tree)- useWikiStore.getState().setSelectedFile(filePath)- useWikiStore.getState().setFileContent(pageContent)+ useWikiStore.getState().openFileInPreview(filePath, pageContent)useWikiStore.getState().bumpDataVersion()resolveItem(id, "Saved to Wiki")@@ -127,8 +126,7 @@ export function ReviewView() {for (const path of candidates) {try {const content = await readFile(path)- useWikiStore.getState().setSelectedFile(path)- useWikiStore.getState().setFileContent(content)+ useWikiStore.getState().openFileInPreview(path, content)return} catch {// try next@@ -213,8 +211,7 @@ export function ReviewView() {// Refreshconst tree = await listDirectory(pp)setFileTree(tree)- useWikiStore.getState().setSelectedFile(filePath)- useWikiStore.getState().setFileContent(pageContent)+ useWikiStore.getState().openFileInPreview(filePath, pageContent)useWikiStore.getState().bumpDataVersion()resolveItem(id, `Created: wiki/${dir}/${fileName}`)diff --git a/src/components/search/search-view.tsx b/src/components/search/search-view.tsxindex 08c95011..9f3795c3 100644--- a/src/components/search/search-view.tsx+++ b/src/components/search/search-view.tsx@@ -28,8 +28,7 @@ interface ImageHit extends ImageRef {export function SearchView() {const { t } = useTranslation()const project = useWikiStore((s) => s.project)- const setSelectedFile = useWikiStore((s) => s.setSelectedFile)- const setFileContent = useWikiStore((s) => s.setFileContent)+ const openFileInPreview = useWikiStore((s) => s.openFileInPreview)const setPendingScrollImageSrc = useWikiStore((s) => s.setPendingScrollImageSrc)const [query, setQuery] = useState("")@@ -117,8 +116,7 @@ export function SearchView() {async function handleOpen(path: string) {try {const content = await readFile(path)- setSelectedFile(path)- setFileContent(content)+ openFileInPreview(path, content)} catch (err) {console.error("Failed to open search result:", err)}@@ -174,8 +172,7 @@ export function SearchView() {try {const content = await readFile(openPath)setPendingScrollImageSrc(scrollTarget)- setSelectedFile(openPath)- setFileContent(content)+ openFileInPreview(openPath, content)setLightbox(null)} catch (err) {console.error("Failed to jump to source:", err)diff --git a/src/components/sources/sources-view.tsx b/src/components/sources/sources-view.tsxindex a191ee0d..b613596a 100644--- a/src/components/sources/sources-view.tsx+++ b/src/components/sources/sources-view.tsx@@ -27,7 +27,7 @@ export function SourcesView() {const project = useWikiStore((s) => s.project)const selectedFile = useWikiStore((s) => s.selectedFile)const setSelectedFile = useWikiStore((s) => s.setSelectedFile)- const setFileContent = useWikiStore((s) => s.setFileContent)+ const openFileInPreview = useWikiStore((s) => s.openFileInPreview)const setFileTree = useWikiStore((s) => s.setFileTree)const llmConfig = useWikiStore((s) => s.llmConfig)const sourceWatchConfig = useWikiStore((s) => s.sourceWatchConfig)@@ -167,10 +167,9 @@ export function SourcesView() {}async function handleOpenSource(node: FileNode) {- setSelectedFile(node.path)try {const content = await readFile(node.path)- setFileContent(content)+ openFileInPreview(node.path, content)} catch (err) {console.error("Failed to read source:", err)}diff --git a/src/i18n/en.json b/src/i18n/en.jsonindex eacf6f51..316fa9b1 100644--- a/src/i18n/en.json+++ b/src/i18n/en.json@@ -4,6 +4,7 @@"subtitle": "Build and maintain your personal knowledge base with LLMs"},"nav": {+ "chat": "Chat","wiki": "Wiki","sources": "Sources","search": "Search",diff --git a/src/i18n/zh.json b/src/i18n/zh.jsonindex 192628b7..d4cd1724 100644--- a/src/i18n/zh.json+++ b/src/i18n/zh.json@@ -4,6 +4,7 @@"subtitle": "用 LLM 构建和维护你的个人知识库"},"nav": {+ "chat": "对话","wiki": "Wiki","sources": "原始资料","search": "搜索",diff --git a/src/stores/wiki-store.test.ts b/src/stores/wiki-store.test.tsnew file mode 100644index 00000000..b4384701--- /dev/null+++ b/src/stores/wiki-store.test.ts@@ -0,0 +1,54 @@+import { describe, expect, it } from "vitest"+import { useWikiStore } from "./wiki-store"++describe("wiki preview store actions", () => {+ it("opens a path in the wiki preview and clears external previews", () => {+ useWikiStore.setState({+ activeView: "chat",+ selectedFile: null,+ fileContent: "old",+ previewContentPath: "/old.md",+ externalPreview: {+ title: "External",+ path: "remote",+ source: "AnyTXT",+ url: "anytxt://remote",+ snippet: "snippet",+ },+ })++ useWikiStore.getState().openPathInPreview("/project/wiki/page.md")++ const state = useWikiStore.getState()+ expect(state.activeView).toBe("wiki")+ expect(state.selectedFile).toBe("/project/wiki/page.md")+ expect(state.fileContent).toBe("old")+ expect(state.previewContentPath).toBeNull()+ expect(state.externalPreview).toBeNull()+ })++ it("opens loaded file content in the wiki preview", () => {+ useWikiStore.setState({+ activeView: "search",+ selectedFile: null,+ fileContent: "",+ previewContentPath: null,+ externalPreview: {+ title: "External",+ path: "remote",+ source: "AnyTXT",+ url: "anytxt://remote",+ snippet: "snippet",+ },+ })++ useWikiStore.getState().openFileInPreview("/project/wiki/page.md", "# Page")++ const state = useWikiStore.getState()+ expect(state.activeView).toBe("wiki")+ expect(state.selectedFile).toBe("/project/wiki/page.md")+ expect(state.fileContent).toBe("# Page")+ expect(state.previewContentPath).toBe("/project/wiki/page.md")+ expect(state.externalPreview).toBeNull()+ })+})diff --git a/src/stores/wiki-store.ts b/src/stores/wiki-store.tsindex cc67a10b..56165e00 100644--- a/src/stores/wiki-store.ts+++ b/src/stores/wiki-store.ts@@ -303,6 +303,7 @@ interface WikiState {fileTree: FileNode[]selectedFile: string | nullfileContent: string+ previewContentPath: string | nullexternalPreview: ExternalPreview | null/*** One-shot scroll target for the markdown preview. When the user@@ -319,8 +320,7 @@ interface WikiState {* one wiki-relative) still works.*/pendingScrollImageSrc: string | null- chatExpanded: boolean- activeView: "wiki" | "sources" | "search" | "graph" | "lint" | "review" | "settings"+ activeView: "chat" | "wiki" | "sources" | "search" | "graph" | "lint" | "review" | "settings"llmConfig: LlmConfig/** Per-provider-preset stored overrides (API key, model, endpoint, …). */providerConfigs: ProviderConfigs@@ -342,9 +342,10 @@ interface WikiState {setFileTree: (tree: FileNode[]) => voidsetSelectedFile: (path: string | null) => voidsetFileContent: (content: string) => void+ openPathInPreview: (path: string) => void+ openFileInPreview: (path: string, content: string) => voidsetExternalPreview: (preview: ExternalPreview | null) => voidsetPendingScrollImageSrc: (src: string | null) => void- setChatExpanded: (expanded: boolean) => voidsetActiveView: (view: WikiState["activeView"]) => voidsetLlmConfig: (config: LlmConfig) => voidsetProviderConfigs: (configs: ProviderConfigs) => void@@ -367,9 +368,9 @@ export const useWikiStore = create<WikiState>((set) => ({fileTree: [],selectedFile: null,fileContent: "",+ previewContentPath: null,externalPreview: null,pendingScrollImageSrc: null,- chatExpanded: false,activeView: "wiki",llmConfig: {provider: "openai",@@ -389,11 +390,21 @@ export const useWikiStore = create<WikiState>((set) => ({setProject: (project) => set({ project }),setFileTree: (fileTree) => set({ fileTree }),- setSelectedFile: (selectedFile) => set({ selectedFile, externalPreview: null }),+ setSelectedFile: (selectedFile) =>+ set({ selectedFile, previewContentPath: null, externalPreview: null }),setFileContent: (fileContent) => set({ fileContent }),+ openPathInPreview: (selectedFile) =>+ set({ selectedFile, previewContentPath: null, externalPreview: null, activeView: "wiki" }),+ openFileInPreview: (selectedFile, fileContent) =>+ set({+ selectedFile,+ fileContent,+ previewContentPath: selectedFile,+ externalPreview: null,+ activeView: "wiki",+ }),setExternalPreview: (externalPreview) => set({ externalPreview }),setPendingScrollImageSrc: (pendingScrollImageSrc) => set({ pendingScrollImageSrc }),- setChatExpanded: (chatExpanded) => set({ chatExpanded }),setActiveView: (activeView) => set({ activeView }),searchApiConfig: {provider: "none",