Skip to content

fix: resolve wiki-root-relative wikilinks - #680

Open
Mybigwang wants to merge 1 commit into
nashsu:mainfrom
Mybigwang:fix/wiki-root-relative-wikilinks
Open

fix: resolve wiki-root-relative wikilinks#680
Mybigwang wants to merge 1 commit into
nashsu:mainfrom
Mybigwang:fix/wiki-root-relative-wikilinks

Conversation

@Mybigwang

Copy link
Copy Markdown

Summary

  • Resolve wiki-root-relative wikilinks such as [[concepts/foo]] to existing wiki/concepts/foo.md pages.
  • Keep support for existing bare links and project-relative wiki/... links.
  • Apply the same resolution behavior across reader links, page links, structural lint, graph building, graph relevance, and the local API graph.

Why

LLM-generated wiki pages can emit links like [[concepts/foo]]. These links point to valid pages under wiki/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.ts
  • cargo test --manifest-path src-tauri/Cargo.toml commands::search::tests::page_links_require_markdown_input_and_exact_reader_paths
  • cargo test --manifest-path src-tauri/Cargo.toml api_server::tests::resolve_link_accepts_wiki_root_relative_paths

Copilot AI lite review requested due to automatic review settings August 18, 2026 05:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 resolveRelatedSlug to accept wiki-root-relative path refs (with/without .md) while still restricting resolution to wiki/.
  • Update graph-building and relevance logic to normalize link targets and add path-based aliases (via per-node shortPath / basename) so concepts/foo resolves 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.

Comment thread src/lib/wiki-graph.ts
Comment on lines +338 to +342
function normalizeLinkTarget(raw: string): string {
return raw.replace(/\\/g, "/")
.replace(/^\/+/, "")
.replace(/^wiki\//i, "")
.replace(/\.md$/i, "")
Comment on lines +2514 to +2520
let normalized_raw = raw
.trim()
.replace('\\', "/")
.trim_start_matches('/')
.trim_start_matches("wiki/")
.trim_end_matches(".md")
.to_string();
@Thomas-Piva

Copy link
Copy Markdown
Contributor

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 wiki/index.md contains 45 wikilinks, all in the [[entities/foo]] form the app itself writes in updateBoundedRecentIndexSection (path.replace(/^wiki\//, "")). Querying the local API graph for that project:

edges out of `index`:      0   (out of 45 links)
nodes with 0 links:        5
connected components:      6
orphans:                   14 / 50  (28%)

The index node is itself isolated in its own graph.

Control, same file and same role, on a second vault whose links had been converted to bare basenames:

vault link form in index.md edges from index
app-generated [[entities/foo]] 0 / 45
basename-converted [[foo]] 130

So this is not only cosmetic reporting noise. wiki/index.md is the one mechanism the app has for giving a freshly written page an inbound link, and because the writer and the resolvers disagree on the target form, none of those links become edges — which is where the 28% orphan rate on an otherwise healthy vault comes from (the generator itself averages 4.2 outgoing links per page, so the pages are not under-linked; nothing links back to them).

Worth noting the writer side too: updateBoundedRecentIndexSection caps that section at .slice(0, 200), so on a large vault the oldest entries fall out of the list regardless of how the links resolve.

Happy to re-run either measurement against this branch if that's useful.

@Mybigwang

Copy link
Copy Markdown
Author

@Thomas-Piva
Thanks — this is really helpful context.
It makes the impact much clearer: this wasn’t just a reporting mismatch, it was preventing app-generated [[entities/foo]] links from turning into real graph edges.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants