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: preserve graph controls and add min links

nash_su2d1d94173ec0
diff --git a/src/components/graph/graph-view.tsx b/src/components/graph/graph-view.tsx
index 9cbed78b..b5ea09f5 100644
--- a/src/components/graph/graph-view.tsx
+++ b/src/components/graph/graph-view.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useCallback, useMemo, useState, useRef, type ChangeEvent } from "react"
+import { useEffect, useCallback, useMemo, useState, useRef, type ChangeEvent, type SetStateAction } from "react"
import Graph from "graphology"
import { SigmaContainer, useLoadGraph, useRegisterEvents, useSetSettings, useSigma } from "@react-sigma/core"
import "@react-sigma/core/lib/style.css"
@@ -9,7 +9,7 @@ import { Network, RefreshCw, ZoomIn, ZoomOut, Maximize, Layers, Tag, Lightbulb,
import { ErrorBoundary } from "@/components/error-boundary"
import { useResearchStore } from "@/stores/research-store"
import { Button } from "@/components/ui/button"
-import { useWikiStore } from "@/stores/wiki-store"
+import { useWikiStore, type GraphColorMode } from "@/stores/wiki-store"
import { readFile, writeFile } from "@/commands/fs"
import { WikiEditor } from "@/components/editor/wiki-editor"
import { FilePreview } from "@/components/editor/file-preview"
@@ -19,7 +19,7 @@ import { queueResearch } from "@/lib/deep-research"
import { optimizeResearchTopic } from "@/lib/optimize-research-topic"
import { getFileName, normalizePath } from "@/lib/path-utils"
import { getFileCategory } from "@/lib/file-types"
-import { applyGraphFilters, DEFAULT_GRAPH_FILTERS, hasActiveGraphFilters, type GraphFilterState } from "@/lib/graph-filters"
+import { applyGraphFilters, hasActiveGraphFilters, type GraphFilterState } from "@/lib/graph-filters"
import { applyGraphSearch } from "@/lib/graph-search"
import { wikiTypeLabel } from "@/lib/wiki-page-types"
import { useTranslation } from "react-i18next"
@@ -64,7 +64,6 @@ const COMMUNITY_COLORS = [
"#fbbf24", // amber-400
]
-type ColorMode = "type" | "community"
type GraphThemePalette = {
defaultEdge: string
label: string
@@ -79,7 +78,6 @@ type GraphThemePalette = {
const BASE_NODE_SIZE = 8
const MAX_NODE_SIZE = 28
-const DEFAULT_NODE_SCALE = 1
const DEFAULT_GRAPH_SPACING = 1
const GRAPH_SPACING_DEBOUNCE_MS = 180
const WORKER_LAYOUT_NODE_THRESHOLD = 220
@@ -313,7 +311,7 @@ function GraphLoader({
}: {
nodes: GraphNode[]
edges: GraphEdge[]
- colorMode: ColorMode
+ colorMode: GraphColorMode
nodeScale: number
graphSpacing: number
}) {
@@ -643,7 +641,13 @@ export function GraphView() {
const [loading, setLoading] = useState(false)
const [error, setError] = useState<string | null>(null)
const [hoveredType, setHoveredType] = useState<string | null>(null)
- const [colorMode, setColorMode] = useState<ColorMode>("type")
+ const graphUiState = useWikiStore((s) => s.graphUiState)
+ const setGraphUiState = useWikiStore((s) => s.setGraphUiState)
+ const resetGraphUiState = useWikiStore((s) => s.resetGraphUiState)
+ const colorMode = graphUiState.colorMode
+ const filters = graphUiState.filters
+ const nodeScale = graphUiState.nodeScale
+ const graphSpacingDraft = graphUiState.graphSpacingDraft
const [showInsights, setShowInsights] = useState(false)
const [highlightedNodes, setHighlightedNodes] = useState<Set<string>>(new Set())
const [hoverState, setHoverState] = useState<HoverState>(null)
@@ -654,15 +658,8 @@ export function GraphView() {
const [showFilters, setShowFilters] = useState(false)
const [graphSearchOpen, setGraphSearchOpen] = useState(false)
const [graphSearch, setGraphSearch] = useState("")
- const [nodeScale, setNodeScale] = useState(DEFAULT_NODE_SCALE)
- const [graphSpacingDraft, setGraphSpacingDraft] = useState(DEFAULT_GRAPH_SPACING)
- const [graphSpacing, setGraphSpacing] = useState(DEFAULT_GRAPH_SPACING)
+ const [graphSpacing, setGraphSpacing] = useState(graphSpacingDraft)
const [graphPreview, setGraphPreview] = useState<GraphPreview | null>(null)
- const [filters, setFilters] = useState<GraphFilterState>(() => ({
- ...DEFAULT_GRAPH_FILTERS,
- hiddenTypes: new Set(),
- hiddenNodeIds: new Set(),
- }))
const [nodeMenu, setNodeMenu] = useState<{ nodeId: string; x: number; y: number } | null>(null)
const graphContainerRef = useRef<HTMLDivElement>(null)
const researchDialogTokenRef = useRef(0)
@@ -670,6 +667,25 @@ export function GraphView() {
const [nodeTypeLabels, setNodeTypeLabels] = useState<Record<string, string>>({})
const graphSearchInputRef = useRef<HTMLInputElement>(null)
+ const setColorMode = useCallback((colorMode: GraphColorMode) => {
+ setGraphUiState((prev) => ({ ...prev, colorMode }))
+ }, [setGraphUiState])
+
+ const setFilters = useCallback((next: SetStateAction<GraphFilterState>) => {
+ setGraphUiState((prev) => ({
+ ...prev,
+ filters: typeof next === "function" ? next(prev.filters) : next,
+ }))
+ }, [setGraphUiState])
+
+ const setNodeScale = useCallback((nodeScale: number) => {
+ setGraphUiState((prev) => ({ ...prev, nodeScale }))
+ }, [setGraphUiState])
+
+ const setGraphSpacingDraft = useCallback((graphSpacingDraft: number) => {
+ setGraphUiState((prev) => ({ ...prev, graphSpacingDraft }))
+ }, [setGraphUiState])
+
// Research confirmation dialog
const [researchDialog, setResearchDialog] = useState<{
loading: boolean
@@ -767,16 +783,10 @@ export function GraphView() {
}, [])
const resetFilters = useCallback(() => {
- setFilters({
- ...DEFAULT_GRAPH_FILTERS,
- hiddenTypes: new Set(),
- hiddenNodeIds: new Set(),
- })
- setNodeScale(DEFAULT_NODE_SCALE)
- setGraphSpacingDraft(DEFAULT_GRAPH_SPACING)
+ resetGraphUiState()
setGraphSpacing(DEFAULT_GRAPH_SPACING)
setNodeMenu(null)
- }, [])
+ }, [resetGraphUiState])
const knowledgeGapKey = useCallback((gap: KnowledgeGap) => (
`gap:${gap.type}:${gap.title}:${gap.nodeIds.join(",")}`
@@ -1191,6 +1201,28 @@ export function GraphView() {
</label>
</div>
+ <div className="space-y-1.5">
+ <div className="font-medium text-muted-foreground">{t("graph.minLinks")}</div>
+ <div className="flex items-center gap-2">
+ <input
+ type="number"
+ min={0}
+ className="h-7 w-20 rounded border bg-background px-2 text-xs"
+ value={filters.minLinks ?? ""}
+ onChange={(e) => {
+ const raw = e.target.value.trim()
+ const value = Number(raw)
+ setFilters((prev) => ({
+ ...prev,
+ minLinks: raw === "" || !Number.isFinite(value) ? undefined : Math.max(0, value),
+ }))
+ }}
+ placeholder="Any"
+ />
+ <span className="text-muted-foreground">{t("graph.minLinksHint")}</span>
+ </div>
+ </div>
+
<div className="space-y-1.5">
<div className="font-medium text-muted-foreground">{t("graph.maxLinks")}</div>
<div className="flex items-center gap-2">
diff --git a/src/i18n/en.json b/src/i18n/en.json
index ee9ea8c3..a94867c0 100644
--- a/src/i18n/en.json
+++ b/src/i18n/en.json
@@ -712,6 +712,8 @@
"quickFilters": "Quick filters",
"hideIndexOverview": "Hide index / overview / log",
"hideIsolated": "Hide isolated nodes",
+ "minLinks": "Min links",
+ "minLinksHint": "Hide nodes below this link count",
"maxLinks": "Max links",
"maxLinksHint": "Hide nodes above this link count",
"displayTuning": "Display tuning",
diff --git a/src/i18n/zh.json b/src/i18n/zh.json
index b086878b..80779c22 100644
--- a/src/i18n/zh.json
+++ b/src/i18n/zh.json
@@ -712,6 +712,8 @@
"quickFilters": "快速过滤",
"hideIndexOverview": "隐藏索引/概述/日志",
"hideIsolated": "隐藏孤立节点",
+ "minLinks": "最小链接数",
+ "minLinksHint": "隐藏链接数低于此值的节点",
"maxLinks": "最大链接数",
"maxLinksHint": "隐藏链接数超过此值的节点",
"displayTuning": "显示调节",
diff --git a/src/lib/graph-filters.test.ts b/src/lib/graph-filters.test.ts
index cbd72c52..32dc3e83 100644
--- a/src/lib/graph-filters.test.ts
+++ b/src/lib/graph-filters.test.ts
@@ -75,6 +75,22 @@ describe("graph filters", () => {
expect(out.edges).toEqual([])
})
+ it("hides weakly connected nodes below the min link threshold", () => {
+ const out = applyGraphFilters(nodes, edges, makeFilters({
+ hideStructural: false,
+ minLinks: 2,
+ }))
+
+ expect(out.nodes.map((n) => n.id)).not.toContain("source-c")
+ expect(out.nodes.map((n) => n.id)).not.toContain("isolated")
+ expect(out.nodes.map((n) => n.id)).toEqual(["index", "concept-a", "entity-b"])
+ expect(out.edges).toEqual([
+ { source: "index", target: "concept-a", weight: 1 },
+ { source: "index", target: "entity-b", weight: 1 },
+ { source: "concept-a", target: "entity-b", weight: 2 },
+ ])
+ })
+
it("hides isolated nodes when requested", () => {
const out = applyGraphFilters(nodes, edges, makeFilters({
hideStructural: false,
@@ -88,5 +104,6 @@ describe("graph filters", () => {
expect(hasActiveGraphFilters(makeFilters({ hideStructural: false }))).toBe(false)
expect(hasActiveGraphFilters(makeFilters())).toBe(true)
expect(hasActiveGraphFilters(makeFilters({ hideStructural: false, hiddenNodeIds: new Set(["x"]) }))).toBe(true)
+ expect(hasActiveGraphFilters(makeFilters({ hideStructural: false, minLinks: 2 }))).toBe(true)
})
})
diff --git a/src/lib/graph-filters.ts b/src/lib/graph-filters.ts
index 900e4312..48f2a56b 100644
--- a/src/lib/graph-filters.ts
+++ b/src/lib/graph-filters.ts
@@ -6,6 +6,7 @@ export interface GraphFilterState {
hiddenNodeIds: ReadonlySet<string>
hideStructural: boolean
hideIsolated: boolean
+ minLinks?: number
maxLinks?: number
}
@@ -20,6 +21,7 @@ export const DEFAULT_GRAPH_FILTERS: GraphFilterState = {
hiddenNodeIds: new Set(),
hideStructural: true,
hideIsolated: false,
+ minLinks: undefined,
maxLinks: undefined,
}
@@ -64,6 +66,10 @@ export function applyGraphFilters(
hiddenNodeIds.add(node.id)
continue
}
+ if (filters.minLinks !== undefined && node.linkCount < filters.minLinks) {
+ hiddenNodeIds.add(node.id)
+ continue
+ }
if (filters.maxLinks !== undefined && node.linkCount > filters.maxLinks) {
hiddenNodeIds.add(node.id)
}
@@ -84,6 +90,7 @@ export function hasActiveGraphFilters(filters: GraphFilterState): boolean {
filters.hideIsolated ||
filters.hiddenTypes.size > 0 ||
filters.hiddenNodeIds.size > 0 ||
+ filters.minLinks !== undefined ||
filters.maxLinks !== undefined
)
}
diff --git a/src/stores/wiki-store.test.ts b/src/stores/wiki-store.test.ts
index 0ddff635..7a621d5a 100644
--- a/src/stores/wiki-store.test.ts
+++ b/src/stores/wiki-store.test.ts
@@ -150,4 +150,37 @@ describe("wiki preview store actions", () => {
expect(state.previewContentPath).toBe("/project/wiki/page.md")
expect(state.externalPreview).toBeNull()
})
+
+ it("keeps graph ui state until explicitly reset", () => {
+ useWikiStore.getState().resetGraphUiState()
+
+ useWikiStore.getState().setGraphUiState((current) => ({
+ ...current,
+ colorMode: "community",
+ filters: {
+ ...current.filters,
+ minLinks: 2,
+ hiddenTypes: new Set(["source"]),
+ },
+ nodeScale: 1.25,
+ graphSpacingDraft: 1.4,
+ }))
+ useWikiStore.getState().setActiveView("chat")
+ useWikiStore.getState().setActiveView("graph")
+
+ const preserved = useWikiStore.getState().graphUiState
+ expect(preserved.colorMode).toBe("community")
+ expect(preserved.filters.minLinks).toBe(2)
+ expect(preserved.filters.hiddenTypes.has("source")).toBe(true)
+ expect(preserved.nodeScale).toBe(1.25)
+ expect(preserved.graphSpacingDraft).toBe(1.4)
+
+ useWikiStore.getState().resetGraphUiState()
+ const reset = useWikiStore.getState().graphUiState
+ expect(reset.colorMode).toBe("type")
+ expect(reset.filters.minLinks).toBeUndefined()
+ expect(reset.filters.hiddenTypes.size).toBe(0)
+ expect(reset.nodeScale).toBe(1)
+ expect(reset.graphSpacingDraft).toBe(1)
+ })
})
diff --git a/src/stores/wiki-store.ts b/src/stores/wiki-store.ts
index b9b09a1b..b3cf788f 100644
--- a/src/stores/wiki-store.ts
+++ b/src/stores/wiki-store.ts
@@ -6,6 +6,7 @@ import {
createEmptyProjectPathIndex,
type ProjectPathIndex,
} from "@/lib/wiki-page-resolver"
+import { DEFAULT_GRAPH_FILTERS, type GraphFilterState } from "@/lib/graph-filters"
/**
* Wire protocol used when `provider === "custom"`. Other providers have a
@@ -212,6 +213,28 @@ interface ApiConfig {
export type CloseBehavior = "ask" | "minimize" | "exit"
+export type GraphColorMode = "type" | "community"
+
+export interface GraphUiState {
+ colorMode: GraphColorMode
+ filters: GraphFilterState
+ nodeScale: number
+ graphSpacingDraft: number
+}
+
+export function createDefaultGraphUiState(): GraphUiState {
+ return {
+ colorMode: "type",
+ filters: {
+ ...DEFAULT_GRAPH_FILTERS,
+ hiddenTypes: new Set(),
+ hiddenNodeIds: new Set(),
+ },
+ nodeScale: 1,
+ graphSpacingDraft: 1,
+ }
+}
+
export interface GeneralConfig {
autostart: boolean
closeBehavior: CloseBehavior
@@ -355,6 +378,7 @@ interface WikiState {
mineruConfig: MineruConfig
apiConfig: ApiConfig
generalConfig: GeneralConfig
+ graphUiState: GraphUiState
dataVersion: number
setProject: (project: WikiProject | null) => void
@@ -380,6 +404,8 @@ interface WikiState {
setMineruConfig: (config: MineruConfig) => void
setApiConfig: (config: ApiConfig) => void
setGeneralConfig: (config: GeneralConfig) => void
+ setGraphUiState: (state: GraphUiState | ((current: GraphUiState) => GraphUiState)) => void
+ resetGraphUiState: () => void
bumpDataVersion: () => void
}
@@ -512,6 +538,8 @@ export const useWikiStore = create<WikiState>((set) => ({
closeBehavior: "minimize",
},
+ graphUiState: createDefaultGraphUiState(),
+
setLlmConfig: (llmConfig) => set({ llmConfig }),
setProviderConfigs: (providerConfigs) => set({ providerConfigs }),
setActivePresetId: (activePresetId) => set({ activePresetId }),
@@ -525,6 +553,13 @@ export const useWikiStore = create<WikiState>((set) => ({
setMineruConfig: (mineruConfig) => set({ mineruConfig }),
setApiConfig: (apiConfig) => set({ apiConfig }),
setGeneralConfig: (generalConfig) => set({ generalConfig }),
+ setGraphUiState: (graphUiState) =>
+ set((state) => ({
+ graphUiState: typeof graphUiState === "function"
+ ? graphUiState(state.graphUiState)
+ : graphUiState,
+ })),
+ resetGraphUiState: () => set({ graphUiState: createDefaultGraphUiState() }),
bumpDataVersion: () => set((state) => ({ dataVersion: state.dataVersion + 1 })),
}))