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

Fix lint persistence state handling

nash_sud52fb070758a
diff --git a/src/App.tsx b/src/App.tsx
index 1ade5c93..615c283d 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -374,13 +374,12 @@ function App() {
// ignore, start fresh
}
// Load persisted lint items
+ useLintStore.getState().setItems([])
try {
const savedLint = await loadLintItems(proj.path)
- if (savedLint.length > 0) {
- useLintStore.getState().setItems(savedLint)
- }
+ useLintStore.getState().setItems(savedLint)
} catch {
- // ignore, start fresh
+ useLintStore.getState().setItems([])
}
// Load persisted chat history
try {
diff --git a/src/components/lint/lint-view.test.ts b/src/components/lint/lint-view.test.ts
index 40e5742c..07b14644 100644
--- a/src/components/lint/lint-view.test.ts
+++ b/src/components/lint/lint-view.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest"
-import { groupLintResultsForDisplay } from "./lint-view"
+import { groupLintResultsForDisplay, shouldShowLintResults } from "./lint-view"
import type { LintItem } from "@/stores/lint-store"
function makeLintItem(
@@ -38,3 +38,17 @@ describe("groupLintResultsForDisplay", () => {
])
})
})
+
+describe("shouldShowLintResults", () => {
+ it("shows restored persisted lint items before a new run in the current view", () => {
+ expect(shouldShowLintResults(false, 2)).toBe(true)
+ })
+
+ it("keeps the first-run empty prompt when no run has happened and nothing was restored", () => {
+ expect(shouldShowLintResults(false, 0)).toBe(false)
+ })
+
+ it("shows the all-clear state after a run with no items", () => {
+ expect(shouldShowLintResults(true, 0)).toBe(true)
+ })
+})
diff --git a/src/components/lint/lint-view.tsx b/src/components/lint/lint-view.tsx
index e0e8f711..5956e525 100644
--- a/src/components/lint/lint-view.tsx
+++ b/src/components/lint/lint-view.tsx
@@ -39,6 +39,10 @@ export function groupLintResultsForDisplay(results: readonly LintItem[]): {
return { warnings, infos }
}
+export function shouldShowLintResults(hasRun: boolean, itemCount: number): boolean {
+ return hasRun || itemCount > 0
+}
+
export function LintView() {
const { t } = useTranslation()
const project = useWikiStore((s) => s.project)
@@ -228,13 +232,14 @@ export function LintView() {
() => groupLintResultsForDisplay(items),
[items],
)
+ const showResults = shouldShowLintResults(hasRun, items.length)
return (
<div className="flex h-full flex-col">
<div className="shrink-0 flex items-center justify-between border-b px-4 py-3">
<div className="flex items-center gap-2">
<h2 className="text-sm font-semibold">{t("lint.title")}</h2>
- {hasRun && items.length > 0 && (
+ {showResults && items.length > 0 && (
<span className="rounded-full bg-amber-500/20 px-2 py-0.5 text-xs font-medium text-amber-600 dark:text-amber-400">
{items.length === 1 ? t("lint.issues", { count: items.length }) : t("lint.issues_plural", { count: items.length })}
</span>
@@ -262,7 +267,7 @@ export function LintView() {
</div>
<div className="flex-1 overflow-y-auto">
- {!hasRun ? (
+ {!showResults ? (
<div className="flex flex-col items-center justify-center gap-2 p-8 text-center text-sm text-muted-foreground">
<CheckCircle2 className="h-8 w-8 text-muted-foreground/30" />
<p>{t("lint.runLintHint")}</p>
diff --git a/src/lib/auto-save.ts b/src/lib/auto-save.ts
index 9b110ea3..fb6bd6c6 100644
--- a/src/lib/auto-save.ts
+++ b/src/lib/auto-save.ts
@@ -22,11 +22,11 @@ export function setupAutoSave(): void {
// Auto-save lint items (debounced 1s)
useLintStore.subscribe((state) => {
+ const projectPath = useWikiStore.getState().project?.path
if (lintTimer) clearTimeout(lintTimer)
lintTimer = setTimeout(() => {
- const project = useWikiStore.getState().project
- if (project) {
- saveLintItems(project.path, state.items).catch(() => {})
+ if (projectPath) {
+ saveLintItems(projectPath, state.items).catch(() => {})
}
}, 1000)
})
diff --git a/src/stores/lint-store.test.ts b/src/stores/lint-store.test.ts
index 74524d78..11290071 100644
--- a/src/stores/lint-store.test.ts
+++ b/src/stores/lint-store.test.ts
@@ -73,6 +73,18 @@ describe("lint-store setItems", () => {
useLintStore.getState().setItems([])
expect(useLintStore.getState().items).toHaveLength(0)
})
+
+ it("keeps generated ids unique after restoring persisted items", () => {
+ useLintStore.getState().setItems([
+ { id: "lint-100", type: "orphan", severity: "info", page: "old.md", detail: "d", createdAt: 999 },
+ ])
+ useLintStore.getState().addItems([makeLintResult({ page: "new.md" })])
+
+ const ids = useLintStore.getState().items.map((item) => item.id)
+ expect(ids[0]).toBe("lint-100")
+ expect(ids[1]).toMatch(/^lint-\d+$/)
+ expect(new Set(ids).size).toBe(ids.length)
+ })
})
describe("lint-store removeItem", () => {
@@ -109,4 +121,4 @@ describe("lint-store clearItems", () => {
it("clearItems on already-empty store is safe", () => {
expect(() => useLintStore.getState().clearItems()).not.toThrow()
})
-})
\ No newline at end of file
+})
diff --git a/src/stores/lint-store.ts b/src/stores/lint-store.ts
index 2cd3785f..e1f4ed5c 100644
--- a/src/stores/lint-store.ts
+++ b/src/stores/lint-store.ts
@@ -23,6 +23,17 @@ function lintResultToItem(result: LintResult): LintItem {
}
}
+function syncCounterFromItems(items: readonly LintItem[]): void {
+ for (const item of items) {
+ const match = /^lint-(\d+)$/.exec(item.id)
+ if (!match) continue
+ const idNumber = Number(match[1])
+ if (Number.isFinite(idNumber) && idNumber > counter) {
+ counter = idNumber
+ }
+ }
+}
+
interface LintState {
items: LintItem[]
setItems: (items: LintItem[]) => void
@@ -36,7 +47,10 @@ let counter = 0
export const useLintStore = create<LintState>((set) => ({
items: [],
- setItems: (items) => set({ items }),
+ setItems: (items) => {
+ syncCounterFromItems(items)
+ set({ items })
+ },
addItems: (results) =>
set((state) => ({
@@ -49,4 +63,4 @@ export const useLintStore = create<LintState>((set) => ({
})),
clearItems: () => set({ items: [] }),
-}))
\ No newline at end of file
+}))