fix: resolve wiki-root-relative wikilinks - #680
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates wikilink/path resolution so wiki-root-relative links like [[concepts/foo]] (and optional .md) correctly resolve to pages under wiki/ across the frontend resolver, structural lint, graph building/relevance, and the Tauri (Rust) link resolvers. This reduces false broken-link reports and restores missing graph edges for LLM-generated path-shaped links.
Changes:
- Extend
resolveRelatedSlugto accept wiki-root-relative path refs (with/without.md) while still restricting resolution towiki/. - Update graph-building and relevance logic to normalize link targets and add path-based aliases (via per-node
shortPath/ basename) soconcepts/fooresolves to the right node ID. - Update structural lint indexing and Rust resolvers to recognize wiki-root-relative path-shaped links, plus add regression tests.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/lib/wiki-page-resolver.ts | Adds support for wiki-root-relative path-shaped refs in resolveRelatedSlug. |
| src/lib/wiki-page-resolver.test.ts | Adds regression test for wiki-root-relative path refs with/without .md. |
| src/lib/wiki-graph.ts | Improves target indexing by adding shortPath and normalized aliases for path-shaped targets. |
| src/lib/lint-structural-core.ts | Expands normalization/indexing to resolve wiki-root-relative path-shaped links during structural lint. |
| src/lib/lint-structural-core.test.ts | Adds regression test ensuring structural lint doesn’t flag wiki-root-relative links as broken. |
| src/lib/graph-relevance.ts | Updates retrieval-graph link resolution to consider shortPath / basename normalization. |
| src/lib/tests/wiki-graph.test.ts | Adds regression test ensuring wiki-root-relative links produce graph edges. |
| src-tauri/src/commands/search.rs | Updates reader-links resolver to accept wiki-root-relative paths and optional .md. |
| src-tauri/src/api_server.rs | Updates API-server link resolver to accept wiki-root-relative/project-relative paths and optional .md. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| function normalizeLinkTarget(raw: string): string { | ||
| return raw.replace(/\\/g, "/") | ||
| .replace(/^\/+/, "") | ||
| .replace(/^wiki\//i, "") | ||
| .replace(/\.md$/i, "") |
| let normalized_raw = raw | ||
| .trim() | ||
| .replace('\\', "/") | ||
| .trim_start_matches('/') | ||
| .trim_start_matches("wiki/") | ||
| .trim_end_matches(".md") | ||
| .to_string(); |
|
Measured the impact of this on a vault built entirely by llm_wiki, in case it helps size the fix. Test vault: 50 pages, generated end-to-end by the app from source ingest, no hand-authored links, no imported index convention. Its The Control, same file and same role, on a second vault whose links had been converted to bare basenames:
So this is not only cosmetic reporting noise. Worth noting the writer side too: Happy to re-run either measurement against this branch if that's useful. |
|
@Thomas-Piva The .slice(0, 200) cap is a separate writer-side limit, but the resolver fix should address the disconnected graph behavior you measured and eliminate most of the missing-link noise across nodes. |
Summary
[[concepts/foo]]to existingwiki/concepts/foo.mdpages.wiki/...links.Why
LLM-generated wiki pages can emit links like
[[concepts/foo]]. These links point to valid pages underwiki/concepts/, but some resolvers treated path-shaped links as project-relative only, causing false broken-link / missing-link reports and missing graph edges.Tests
npm run test:mocks -- src/lib/wiki-page-resolver.test.ts src/lib/lint-structural-core.test.ts src/lib/__tests__/wiki-graph.test.tscargo test --manifest-path src-tauri/Cargo.toml commands::search::tests::page_links_require_markdown_input_and_exact_reader_pathscargo test --manifest-path src-tauri/Cargo.toml api_server::tests::resolve_link_accepts_wiki_root_relative_paths