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: configure structural lint rules
nash_sue33e8aca8b5c
diff --git a/src/components/lint/lint-view.tsx b/src/components/lint/lint-view.tsxindex a573cdbb..ce2060a7 100644--- a/src/components/lint/lint-view.tsx+++ b/src/components/lint/lint-view.tsx@@ -11,6 +11,7 @@ import {Wrench,Trash2,Link,+ Settings2,} from "lucide-react"import { Button } from "@/components/ui/button"import { useWikiStore } from "@/stores/wiki-store"@@ -28,6 +29,12 @@ import {} from "@/lib/lint-fixes"import { useTranslation } from "react-i18next"import { useAppDialog } from "@/stores/app-dialog-store"+import {+ DEFAULT_LINT_CONFIG,+ loadLintConfig,+ saveLintConfig,+ type LintConfig,+} from "@/lib/lint-config"export function groupLintResultsForDisplay(results: readonly LintItem[]): {warnings: LintItem[]@@ -75,6 +82,11 @@ export function LintView() {const [lintProgress, setLintProgress] = useState<{ completed: number; total: number } | null>(null)const [hasRun, setHasRun] = useState(false)const [runSemantic, setRunSemantic] = useState(false)+ const [showRuleSettings, setShowRuleSettings] = useState(false)+ const [lintConfig, setLintConfig] = useState<LintConfig>(DEFAULT_LINT_CONFIG)+ const [ignoredPagesDraft, setIgnoredPagesDraft] = useState("")+ const [savingConfig, setSavingConfig] = useState(false)+ const [configError, setConfigError] = useState<string | null>(null)const [fixingId, setFixingId] = useState<string | null>(null)const [batchFixing, setBatchFixing] = useState(false)const [fixError, setFixError] = useState<string | null>(null)@@ -83,6 +95,46 @@ export function LintView() {useEffect(() => () => lintAbortRef.current?.abort(), [])+ useEffect(() => {+ let active = true+ if (!project) {+ setLintConfig(DEFAULT_LINT_CONFIG)+ setIgnoredPagesDraft("")+ return () => { active = false }+ }+ const projectPath = project.path+ void loadLintConfig(projectPath).then((config) => {+ if (!active || useWikiStore.getState().project?.path !== projectPath) return+ setLintConfig(config)+ setIgnoredPagesDraft(config.ignorePages.join("\n"))+ setConfigError(null)+ })+ return () => { active = false }+ }, [project])++ const handleSaveLintConfig = useCallback(async () => {+ if (!project || savingConfig) return+ const projectPath = project.path+ setSavingConfig(true)+ setConfigError(null)+ try {+ const saved = await saveLintConfig(projectPath, {+ ...lintConfig,+ ignorePages: ignoredPagesDraft.split(/[,,\n]/),+ })+ if (useWikiStore.getState().project?.path !== projectPath) return+ setLintConfig(saved)+ setIgnoredPagesDraft(saved.ignorePages.join("\n"))+ setShowRuleSettings(false)+ } catch (error) {+ if (useWikiStore.getState().project?.path === projectPath) {+ setConfigError(String(error))+ }+ } finally {+ if (useWikiStore.getState().project?.path === projectPath) setSavingConfig(false)+ }+ }, [ignoredPagesDraft, lintConfig, project, savingConfig])+const handleRunLint = useCallback(async () => {if (!project || running) returnconst pp = normalizePath(project.path)@@ -96,6 +148,10 @@ export function LintView() {try {const structural = await runStructuralLint(pp, {signal: controller.signal,+ config: {+ ...lintConfig,+ ignorePages: ignoredPagesDraft.split(/[,,\n]/),+ },onProgress: (completed, total) => setLintProgress({ completed, total }),})let all = structural@@ -116,7 +172,16 @@ export function LintView() {setRunning(false)setLintProgress(null)}- }, [project, llmConfig, running, runSemantic, addLintItems, clearLintItems])+ }, [+ project,+ llmConfig,+ lintConfig,+ ignoredPagesDraft,+ running,+ runSemantic,+ addLintItems,+ clearLintItems,+ ])async function handleOpenPage(page: string) {if (!project) return@@ -395,6 +460,15 @@ export function LintView() {<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">+ <Button+ size="icon-sm"+ variant={showRuleSettings ? "secondary" : "ghost"}+ onClick={() => setShowRuleSettings((value) => !value)}+ title={t("lint.ruleSettings")}+ aria-label={t("lint.ruleSettings")}+ >+ <Settings2 className="h-3.5 w-3.5" />+ </Button><h2 className="text-sm font-semibold">{t("lint.title")}</h2>{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">@@ -428,6 +502,49 @@ export function LintView() {</div></div>+ {showRuleSettings && (+ <div className="shrink-0 space-y-3 border-b bg-muted/20 px-4 py-3 text-xs">+ <div className="font-medium">{t("lint.ruleSettings")}</div>+ <label className="flex cursor-pointer items-center gap-2 text-muted-foreground">+ <input+ type="checkbox"+ checked={lintConfig.ignoreOrphan}+ onChange={(event) => setLintConfig((config) => ({+ ...config,+ ignoreOrphan: event.target.checked,+ }))}+ />+ {t("lint.ignoreOrphan")}+ </label>+ <label className="flex cursor-pointer items-center gap-2 text-muted-foreground">+ <input+ type="checkbox"+ checked={lintConfig.ignoreNoOutlinks}+ onChange={(event) => setLintConfig((config) => ({+ ...config,+ ignoreNoOutlinks: event.target.checked,+ }))}+ />+ {t("lint.ignoreNoOutlinks")}+ </label>+ <label className="block space-y-1.5">+ <span className="text-muted-foreground">{t("lint.ignorePages")}</span>+ <textarea+ value={ignoredPagesDraft}+ onChange={(event) => setIgnoredPagesDraft(event.target.value)}+ placeholder={t("lint.ignorePagesPlaceholder")}+ className="min-h-20 w-full resize-y rounded border bg-background px-2 py-1.5 font-mono text-xs outline-none focus:ring-1 focus:ring-ring"+ />+ </label>+ {configError && <p className="text-destructive">{configError}</p>}+ <div className="flex justify-end">+ <Button size="sm" onClick={handleSaveLintConfig} disabled={savingConfig}>+ {savingConfig ? t("lint.savingRules") : t("lint.saveRules")}+ </Button>+ </div>+ </div>+ )}+{items.length > 0 && (<div className="flex flex-wrap items-center gap-2 border-b bg-muted/20 px-4 py-2 text-xs"><label className="flex cursor-pointer items-center gap-2 text-muted-foreground">diff --git a/src/i18n/en.json b/src/i18n/en.jsonindex 57fe1448..21219732 100644--- a/src/i18n/en.json+++ b/src/i18n/en.json@@ -361,6 +361,13 @@"lint": {"title": "Wiki Lint","semantic": "Semantic (LLM)",+ "ruleSettings": "Lint rules",+ "ignoreOrphan": "Do not report orphan pages",+ "ignoreNoOutlinks": "Do not report pages without outbound links",+ "ignorePages": "Ignored pages (one slug or path per line)",+ "ignorePagesPlaceholder": "archive/legacy-page\nintentional-leaf",+ "saveRules": "Save rules",+ "savingRules": "Saving...","running": "Running...","cancel": "Cancel check","cancelProgress": "Cancel {{completed}}/{{total}}",diff --git a/src/i18n/it.json b/src/i18n/it.jsonindex f9da4cef..1a93f5bf 100644--- a/src/i18n/it.json+++ b/src/i18n/it.json@@ -361,6 +361,13 @@"lint": {"title": "Lint del wiki","semantic": "Semantico (LLM)",+ "ruleSettings": "Regole di lint",+ "ignoreOrphan": "Non segnalare pagine orfane",+ "ignoreNoOutlinks": "Non segnalare pagine senza link in uscita",+ "ignorePages": "Pagine ignorate (uno slug o percorso per riga)",+ "ignorePagesPlaceholder": "archive/legacy-page\nintentional-leaf",+ "saveRules": "Salva regole",+ "savingRules": "Salvataggio...","running": "In esecuzione...","cancel": "Annulla il controllo","cancelProgress": "Annulla {{completed}}/{{total}}",diff --git a/src/i18n/ru.json b/src/i18n/ru.jsonindex 915f41ce..64d72786 100644--- a/src/i18n/ru.json+++ b/src/i18n/ru.json@@ -361,6 +361,13 @@"lint": {"title": "Проверка вики","semantic": "Семантическая (LLM)",+ "ruleSettings": "Правила проверки",+ "ignoreOrphan": "Не сообщать об изолированных страницах",+ "ignoreNoOutlinks": "Не сообщать о страницах без исходящих ссылок",+ "ignorePages": "Игнорируемые страницы (один slug или путь на строку)",+ "ignorePagesPlaceholder": "archive/legacy-page\nintentional-leaf",+ "saveRules": "Сохранить правила",+ "savingRules": "Сохранение...","running": "Выполняется...","cancel": "Отменить проверку","cancelProgress": "Отменить {{completed}}/{{total}}",diff --git a/src/i18n/zh.json b/src/i18n/zh.jsonindex 5cf2c0fd..408e0d9c 100644--- a/src/i18n/zh.json+++ b/src/i18n/zh.json@@ -361,6 +361,13 @@"lint": {"title": "Wiki 检查","semantic": "语义检查 (LLM)",+ "ruleSettings": "检查规则",+ "ignoreOrphan": "不报告孤立页面",+ "ignoreNoOutlinks": "不报告无出链页面",+ "ignorePages": "忽略的页面(每行一个 slug 或路径)",+ "ignorePagesPlaceholder": "archive/legacy-page\nintentional-leaf",+ "saveRules": "保存规则",+ "savingRules": "保存中……","running": "检查中...","cancel": "取消检查","cancelProgress": "取消 {{completed}}/{{total}}",diff --git a/src/lib/lint-config.test.ts b/src/lib/lint-config.test.tsnew file mode 100644index 00000000..ecc583ab--- /dev/null+++ b/src/lib/lint-config.test.ts@@ -0,0 +1,19 @@+import { describe, expect, it } from "vitest"+import { DEFAULT_LINT_CONFIG, normalizeLintConfig } from "./lint-config"++describe("lint config", () => {+ it("preserves existing lint behavior by default", () => {+ expect(normalizeLintConfig()).toEqual(DEFAULT_LINT_CONFIG)+ })++ it("normalizes comma and newline separated ignored pages", () => {+ expect(normalizeLintConfig({+ ignoreOrphan: true,+ ignorePages: ["alpha, beta", "beta\nfolder/gamma.md", ""],+ })).toEqual({+ ignoreOrphan: true,+ ignoreNoOutlinks: false,+ ignorePages: ["alpha", "beta", "folder/gamma.md"],+ })+ })+})diff --git a/src/lib/lint-config.ts b/src/lib/lint-config.tsnew file mode 100644index 00000000..abde3e36--- /dev/null+++ b/src/lib/lint-config.ts@@ -0,0 +1,50 @@+import { fileExists, readFile, writeFileAtomic } from "@/commands/fs"+import { normalizePath } from "@/lib/path-utils"++export interface LintConfig {+ ignoreOrphan: boolean+ ignoreNoOutlinks: boolean+ ignorePages: string[]+}++export const DEFAULT_LINT_CONFIG: LintConfig = {+ ignoreOrphan: false,+ ignoreNoOutlinks: false,+ ignorePages: [],+}++export function normalizeLintConfig(config?: Partial<LintConfig> | null): LintConfig {+ return {+ ignoreOrphan: config?.ignoreOrphan === true,+ ignoreNoOutlinks: config?.ignoreNoOutlinks === true,+ ignorePages: [...new Set((config?.ignorePages ?? [])+ .flatMap((value) => value.split(/[,,\n]/))+ .map((value) => value.trim())+ .filter(Boolean))],+ }+}++function lintConfigPath(projectPath: string): string {+ return `${normalizePath(projectPath)}/.llm-wiki/lint-config.json`+}++export async function loadLintConfig(projectPath: string): Promise<LintConfig> {+ const path = lintConfigPath(projectPath)+ try {+ if (!(await fileExists(path))) return DEFAULT_LINT_CONFIG+ return normalizeLintConfig(JSON.parse(await readFile(path)) as Partial<LintConfig>)+ } catch (error) {+ console.warn("[lint] failed to load lint config:", error)+ return DEFAULT_LINT_CONFIG+ }+}++export async function saveLintConfig(+ projectPath: string,+ config: LintConfig,+): Promise<LintConfig> {+ const normalized = normalizeLintConfig(config)+ await writeFileAtomic(lintConfigPath(projectPath), JSON.stringify(normalized, null, 2))+ return normalized+}+diff --git a/src/lib/lint-structural-core.test.ts b/src/lib/lint-structural-core.test.tsindex 8a9bd05a..b9cbc83b 100644--- a/src/lib/lint-structural-core.test.ts+++ b/src/lib/lint-structural-core.test.ts@@ -32,4 +32,28 @@ describe("computeStructuralLint", () => {// scan while remaining stable on slower CI runners.expect(elapsed).toBeLessThan(5_000)})++ it("can disable orphan and no-outlinks findings independently", () => {+ const pages = [+ { ...page(0, 1), shortName: "leaf.md", slug: "leaf", outlinks: [] },+ ]++ expect(computeStructuralLint(pages, undefined, { ignoreOrphan: true }))+ .toEqual([expect.objectContaining({ type: "no-outlinks" })])+ expect(computeStructuralLint(pages, undefined, { ignoreNoOutlinks: true }))+ .toEqual([expect.objectContaining({ type: "orphan" })])+ })++ it("suppresses all findings for ignored pages while retaining them as link targets", () => {+ const pages = [+ { ...page(0, 2), shortName: "folder/ignored.md", slug: "folder/ignored", outlinks: ["missing"] },+ { ...page(1, 2), shortName: "source.md", slug: "source", outlinks: ["folder/ignored"] },+ ]+ const findings = computeStructuralLint(pages, undefined, {+ ignorePages: ["wiki/folder/ignored.md"],+ })++ expect(findings.some((finding) => finding.page === "folder/ignored.md")).toBe(false)+ expect(findings.some((finding) => finding.type === "broken-link" && finding.brokenTarget === "folder/ignored")).toBe(false)+ })})diff --git a/src/lib/lint-structural-core.ts b/src/lib/lint-structural-core.tsindex 2a662b24..7ec86c88 100644--- a/src/lib/lint-structural-core.ts+++ b/src/lib/lint-structural-core.ts@@ -16,6 +16,12 @@ export interface StructuralLintFinding {suggestedSource?: string}+export interface StructuralLintConfig {+ ignoreOrphan?: boolean+ ignoreNoOutlinks?: boolean+ ignorePages?: string[]+}+interface IndexedPage extends StructuralLintPage {tokenSet: Set<string>}@@ -96,6 +102,7 @@ function topCandidates(scores: Map<number, number>, excluded: number): number[]export function computeStructuralLint(rawPages: StructuralLintPage[],onProgress?: (completed: number, total: number) => void,+ config: StructuralLintConfig = {},): StructuralLintFinding[] {const pages: IndexedPage[] = rawPages.map((page) => ({ ...page, tokenSet: new Set(page.tokens) }))const slugMap = new Map<string, number>()@@ -172,8 +179,12 @@ export function computeStructuralLint(}const results: StructuralLintFinding[] = []+ const ignoredPages = new Set((config.ignorePages ?? []).map(normalizeTarget).filter(Boolean))pages.forEach((page, pageIndex) => {- if (!inboundCounts.has(pageIndex)) {+ const pageKeys = [page.slug, page.shortName, fileName(page.shortName).replace(/\.md$/i, "")]+ .map(normalizeTarget)+ const ignored = pageKeys.some((key) => ignoredPages.has(key))+ if (!ignored && !config.ignoreOrphan && !inboundCounts.has(pageIndex)) {results.push({type: "orphan",severity: "info",@@ -182,7 +193,7 @@ export function computeStructuralLint(suggestedSource: relatedCandidate(pageIndex, "source")?.shortName,})}- if (page.outlinks.length === 0) {+ if (!ignored && !config.ignoreNoOutlinks && page.outlinks.length === 0) {results.push({type: "no-outlinks",severity: "info",@@ -191,7 +202,7 @@ export function computeStructuralLint(suggestedTarget: relatedCandidate(pageIndex, "target")?.shortName,})}- for (const link of page.outlinks) {+ for (const link of ignored ? [] : page.outlinks) {const basename = fileName(link).replace(/\.md$/i, "")if (slugMap.has(normalizeTarget(link)) || slugMap.has(normalizeTarget(basename))) continueresults.push({diff --git a/src/lib/lint-structural.worker.ts b/src/lib/lint-structural.worker.tsindex fcb59e29..15b6aa4f 100644--- a/src/lib/lint-structural.worker.ts+++ b/src/lib/lint-structural.worker.ts@@ -1,12 +1,17 @@-import { computeStructuralLint, type StructuralLintPage } from "./lint-structural-core"+import {+ computeStructuralLint,+ type StructuralLintConfig,+ type StructuralLintPage,+} from "./lint-structural-core"interface WorkerRequest {pages: StructuralLintPage[]+ config: StructuralLintConfig}self.onmessage = (event: MessageEvent<WorkerRequest>) => {const findings = computeStructuralLint(event.data.pages, (completed, total) => {self.postMessage({ type: "progress", completed, total })- })+ }, event.data.config)self.postMessage({ type: "done", findings })}diff --git a/src/lib/lint.ts b/src/lib/lint.tsindex d353cf17..3f5c8ace 100644--- a/src/lib/lint.ts+++ b/src/lib/lint.ts@@ -11,6 +11,7 @@ import {type StructuralLintFinding,type StructuralLintPage,} from "@/lib/lint-structural-core"+import type { LintConfig } from "@/lib/lint-config"export interface LintResult {type: "orphan" | "broken-link" | "no-outlinks" | "semantic"@@ -109,6 +110,7 @@ function tokenizeForSuggestion(text: string): Set<string> {export interface StructuralLintOptions {signal?: AbortSignalonProgress?: (completed: number, total: number) => void+ config?: LintConfig}function runStructuralWorker(@@ -116,7 +118,7 @@ function runStructuralWorker(options: StructuralLintOptions,): Promise<StructuralLintFinding[]> {if (typeof Worker === "undefined") {- return Promise.resolve(computeStructuralLint(pages, options.onProgress))+ return Promise.resolve(computeStructuralLint(pages, options.onProgress, options.config))}return new Promise((resolve, reject) => {const worker = new Worker(new URL("./lint-structural.worker.ts", import.meta.url), { type: "module" })@@ -148,7 +150,7 @@ function runStructuralWorker(worker.terminate()resolve(event.data.findings ?? [])}- worker.postMessage({ pages })+ worker.postMessage({ pages, config: options.config ?? {} })})}