Skip to content

feat(markdown): add a note graph for linked Markdown notes - #29868

Open
nebourocket wants to merge 3 commits into
stablyai:mainfrom
nebourocket:feat/markdown-note-graph
Open

nebourocket wants to merge 3 commits into
stablyai:mainfrom
nebourocket:feat/markdown-note-graph

Conversation

@nebourocket

Copy link
Copy Markdown

Stacked on #29861 (backlinks). Until that merges, this diff also shows its commit. Only the last commit, feat(markdown): add a note graph…, belongs to this PR.

ELI5

A picture of how your notes connect. Each Markdown note that links to, or is linked from, another note is a dot, and each link is a line. Click a dot to open that note. Scroll to zoom and drag to move around. This is the "graph view" Obsidian users know.

What Changed

Before: Orca resolves [[links]] (and, with #29861, lists backlinks), but there was no overview of how a notes folder is connected.

After: the Markdown Backlinks bar has a Graph button. It opens a dialog with:

  • a force-directed graph of linked notes (notes without links are left out)
  • the open note highlighted
  • the note name under each dot, and the full path on hover
  • cursor-anchored zoom with clamped limits, and drag to pan
  • click or Enter on a node to open that note and close the dialog
  • a footer showing N notes, M links, plus a notice when the graph was trimmed

Mechanism:

  1. Search. One workspace text search through the existing searchRuntimeFiles (local, SSH and paired runtimes) for \[\[|\]( over *.md, *.mdx, *.markdown. Every link line contains one of these, so this returns the whole link set without reading every file in the renderer. It is bounded by the existing 2,000-match search cap.
  2. Resolve. Each hit is resolved with the same resolver backlinks use. That resolver is now shared as markdown-link-resolver.ts, so the two features cannot disagree. Hits become undirected, de-duplicated edges, and self-links are dropped (markdown-note-graph.ts). If there are more than 300 linked notes, the 300 best-connected are kept and the dialog says so.
  3. Layout. A small deterministic Fruchterman–Reingold layout (markdown-note-graph-layout.ts, with no new dependency). It starts from a circle and cools step by step, and its iteration count is budgeted so a 300-node graph stays fast. The same notes always draw the same way.
  4. View. An SVG in the existing Dialog primitive. Pan and zoom only change the viewBox; the math is in markdown-note-graph-viewport.ts and is unit-tested. The node and edge layer is memoized, so panning does not re-render hundreds of nodes. Drag starts only on the primary button and ends on pointer up, cancel or lost capture.
  5. Shared search hook. The search hook from feat(markdown): show backlinks under Markdown notes #29861 is generalized into useMarkdownWorkspaceSearch, which both features use.

Why

#3040 asks for an Obsidian-style reading experience. Links and backlinks show the neighbours of one note; the graph shows the shape of the whole vault (hubs, clusters, orphans).

Alternatives considered:

  • A graph library (d3-force, cytoscape, react-flow). It would add a dependency for roughly 60 lines of layout. The in-house layout is deterministic and testable, and costs nothing until the dialog opens.
  • A persistent link index in the main process. It would need invalidation and storage for every route (local, SSH, runtime). The search-then-resolve approach reuses existing, bounded infrastructure and always matches the resolver.
  • A new editor tab type. That would mean much wider changes (tab model, persistence, restore). A dialog keeps the change local, and it could move to a tab later.

Limits: notes past the search cap or the 300-node cap are left out, and the dialog says so. The graph is a snapshot taken when the dialog opens.

Linked Issue

Fixes #29867 (related: #3040)

Visual Proof

Before: there was no graph. After: three linked notes, with the open note (propulsion) highlighted. The unlinked island.md is left out.

note graph

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Unit tests:

  • markdown-note-graph.test.ts: edges are de-duplicated and undirected, self-links and missing targets are dropped, unlinked notes are left out, the node cap keeps the best-connected notes, and the layout is deterministic, finite, and places linked notes closer.
  • markdown-note-graph-viewport.test.ts: zoom keeps the anchor fixed, zoom stays clamped after 500 scroll events, horizontal-only scrolling is ignored, and meet scaling and client-to-view mapping are correct.

New e2e test, tests/e2e/markdown-note-graph.spec.ts:

  1. Open a note and the graph.
  2. Check that the three linked notes are drawn and the unlinked note is not.
  3. Click a node and check that the dialog closes and that note opens.

The backlinks e2e test still passes.

Other checks:

  • All editor Vitest suites: 2,657 tests pass.
  • pnpm tc
  • pnpm run check:code-quality:changed
  • oxlint
  • localization extraction and catalogs
  • check:max-lines-ratchet

Tested on Linux (WSL2). Not tested on macOS, Windows or a real SSH host.

AI Disclosure

Written with Claude Code (Claude Opus 5.5). I reviewed the code and verified it with the tests above.

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Performance: nothing runs until the dialog opens. After that it is one bounded search and one budgeted layout. Pan and zoom do not re-render the node layer.
  • Security: read-only, using existing search and open paths.
  • Cross-platform: path separators are normalised, and Windows and macOS case-insensitivity matches the wiki-link resolver.
  • Theme: colours come only from theme tokens (fill-primary, fill-muted-foreground, stroke-border), so light and dark mode both work.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred). Typecheck, the changed-code gate, oxlint, localization checks, the editor suites and the electron-vite build pass locally. CI will cover the full suites.

Add an Obsidian-style Backlinks bar under the rich editor, the inline
preview and Markdown preview tabs. Opening it runs one workspace text
search for the note's name (plain or URL-encoded) and keeps only lines
whose [[wiki link]] or [text](relative.md) link resolves to this note,
using the existing doc-link resolver. Each entry opens the linking note.
Add a Graph button to the Backlinks bar that opens a dialog drawing the
workspace's linked notes as a force-directed graph (no new dependency).
One workspace search finds every [[ or ]( line; links are resolved with
the same resolver as backlinks, now shared in markdown-link-resolver.
The view supports cursor-anchored zoom, drag to pan, highlights the
open note, and opens the note you click. Large workspaces keep the 300
best-connected notes.
Copilot AI balanced review requested due to automatic review settings October 16, 2026 23:00

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 317bb35c-c609-4b0b-8a9b-d1309a34535d
📥 Commits

Reviewing files that changed from the base of the PR and between 69af7f0 and 111df2d.

📒 Files selected for processing: 5
  • src/renderer/src/components/editor/MarkdownNoteGraphDialog.tsx
  • src/renderer/src/components/editor/markdown-backlinks.ts
  • src/renderer/src/components/editor/markdown-link-resolver.ts
  • src/renderer/src/components/editor/markdown-note-graph.test.ts
  • src/renderer/src/components/editor/markdown-note-graph.ts
🚧 Files skipped from review as they are similar to previous changes: 1
  • src/renderer/src/components/editor/markdown-backlinks.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

📝 Walkthrough

The change adds backlink search and resolved-link utilities for Markdown documents. Markdown editor views now include a backlinks panel, and a graph dialog displays connected notes with zoom, pan, and note-opening interactions. The graph supports a node limit and reports partial results. Unit and end-to-end tests cover link resolution, graph construction and interaction, and backlink navigation.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 111df

The note graph feature adds a dialog that is bounded and reads from a snapshot. The supplied evidence shows no remaining merge-blocking risk.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Out of Scope Changes check Warning The whole-PR changes include the standalone backlinks feature from #29861. They add WithMarkdownBacklinks, MarkdownBacklinksPanel, backlink collection, backlinks tests, backlink localization, and … Rebase this PR onto the reviewed head of #29861, or remove the standalone backlinks implementation from this PR. Keep the graph feature and only the shared changes required for graph integration.
Docstring Coverage Warning Docstring coverage is 46.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 28 functions across 15 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: adding a Markdown note graph for linked notes.
Description check Passed The description is complete and closely follows the repository template. It explains the user-facing behavior, implementation, rationale, linked issue, visual proof, testing, AI disclosure, performanc…
Linked Issues check Passed Issue #29867 requires a bounded graph of Markdown notes with resolved wiki and inline links, active-note highlighting, node navigation, zoom, and pan. The graph builder resolves and de-duplicates link…
Full details: Description check

Explanation

The description is complete and closely follows the repository template. It explains the user-facing behavior, implementation, rationale, linked issue, visual proof, testing, AI disclosure, performance, security, cross-platform considerations, and checklist status. It also clearly notes that full lint, typecheck, test, and build validation will be covered by CI.

Full details: Linked Issues check

Explanation

Issue #29867 requires a bounded graph of Markdown notes with resolved wiki and inline links, active-note highlighting, node navigation, zoom, and pan. The graph builder resolves and de-duplicates links, removes self-links, omits unlinked notes, caps nodes, and preserves the active note when capped. The dialog implements highlighting, click and keyboard navigation, zoom, pan, and partial-result reporting. Unit and end-to-end tests cover graph construction, layout, viewport behavior, bounds, and navigation.

Full details: Out of Scope Changes check

Explanation

The whole-PR changes include the standalone backlinks feature from #29861. They add WithMarkdownBacklinks, MarkdownBacklinksPanel, backlink collection, backlinks tests, backlink localization, and the backlinks end-to-end test. These changes are not required by directly linked issue #29867. The shared resolver and search hook changes support the graph feature and remain in scope.

Resolution

Rebase this PR onto the reviewed head of #29861, or remove the standalone backlinks implementation from this PR. Keep the graph feature and only the shared changes required for graph integration.

  • Fix all pre-merge checks with AI
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 78d82958-3e20-4d36-a812-603ae3482174
📥 Commits

Reviewing files that changed from the base of the PR and between 6dd7ab5 and 69af7f0.

📒 Files selected for processing: 16
  • src/renderer/src/components/editor/EditorContent.tsx
  • src/renderer/src/components/editor/EditorMarkdownFileSurface.tsx
  • src/renderer/src/components/editor/MarkdownBacklinksPanel.tsx
  • src/renderer/src/components/editor/MarkdownNoteGraphDialog.tsx
  • src/renderer/src/components/editor/markdown-backlinks.test.ts
  • src/renderer/src/components/editor/markdown-backlinks.ts
  • src/renderer/src/components/editor/markdown-link-resolver.ts
  • src/renderer/src/components/editor/markdown-note-graph-layout.ts
  • src/renderer/src/components/editor/markdown-note-graph-viewport.test.ts
  • src/renderer/src/components/editor/markdown-note-graph-viewport.ts
  • src/renderer/src/components/editor/markdown-note-graph.test.ts
  • src/renderer/src/components/editor/markdown-note-graph.ts
  • src/renderer/src/components/editor/use-markdown-workspace-search.ts
  • src/renderer/src/i18n/locales/en.json
  • tests/e2e/markdown-backlinks.spec.ts
  • tests/e2e/markdown-note-graph.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Comment on lines +58 to +78
if (from.key === to.key || edgeKeys.has(edgeKey)) {
continue
}
edgeKeys.add(edgeKey)
edges.push({ source: from.key, target: to.key })
from.degree += 1
to.degree += 1
}
}
}
const linkedNodes = [...nodes.values()].filter((entry) => entry.degree > 0)
const kept = linkedNodes
.sort((a, b) => b.degree - a.degree || a.key.localeCompare(b.key))
.slice(0, maxNodes)
const keptKeys = new Set(kept.map((entry) => entry.key))
return {
nodes: kept,
edges: edges.filter((edge) => keptKeys.has(edge.source) && keptKeys.has(edge.target)),
omittedNodes: linkedNodes.length - kept.length
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '28,85p' src/renderer/src/components/editor/markdown-note-graph.ts
sed -n '70,195p' src/renderer/src/components/editor/MarkdownNoteGraphDialog.tsx

Repository: stablyai/orca

Length of output: 6806


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- graph file references ---'
rg -n -F --glob 'src/renderer/src/components/editor/*' \
  -e 'MarkdownNoteGraphLayer' \
  -e 'MarkdownNoteGraphDialog' \
  -e 'buildMarkdownNoteGraph' \
  -e 'NOTE_GRAPH_SEARCH' \
  -e 'activeKey' \
  -e 'MARKDOWN_NOTE_GRAPH_MAX_NODES' \
  src/renderer/src/components/editor || test "$?" -eq 1
printf '%s\n' '--- graph source beginning ---'
sed -n '1,120p' src/renderer/src/components/editor/markdown-note-graph.ts
printf '%s\n' '--- layer and dialog definitions ---'
rg -n -F --glob '*.tsx' \
  -e 'function MarkdownNoteGraphLayer' \
  -e 'const MarkdownNoteGraphLayer' \
  -e 'export function MarkdownNoteGraphDialog' \
  -e 'function MarkdownNoteGraphDialog' \
  src/renderer/src/components/editor || test "$?" -eq 1
sed -n '1,90p' src/renderer/src/components/editor/MarkdownNoteGraphDialog.tsx
printf '%s\n' '--- graph tests and dialog tests ---'
rg -n --glob '*.{test,spec}.{ts,tsx}' \
  -e 'buildMarkdownNoteGraph' \
  -e 'MarkdownNoteGraph' \
  -e 'note graph' \
  -e 'activeKey' \
  -e 'omittedNodes' \
  src tests || test "$?" -eq 1
printf '%s\n' '--- search hook and graph callers ---'
rg -n -F --glob '*.ts*' \
  -e 'useMarkdownWorkspaceSearch' \
  -e 'markdownNoteGraphSearchOptions' \
  src/renderer/src

Repository: stablyai/orca

Length of output: 13829


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- graph layer ---'
sed -n '190,270p' src/renderer/src/components/editor/MarkdownNoteGraphDialog.tsx
printf '%s\n' '--- workspace search hook ---'
sed -n '1,180p' src/renderer/src/components/editor/use-markdown-workspace-search.ts
printf '%s\n' '--- backlinks graph entrypoint ---'
sed -n '120,175p' src/renderer/src/components/editor/MarkdownBacklinksPanel.tsx
printf '%s\n' '--- graph unit tests ---'
sed -n '1,115p' src/renderer/src/components/editor/markdown-note-graph.test.ts
printf '%s\n' '--- e2e graph fixture ---'
sed -n '1,180p' tests/e2e/markdown-note-graph.spec.ts
printf '%s\n' '--- markdown document/search types and fixtures ---'
rg -n -F --glob '*.{ts,tsx}' \
  -e 'type MarkdownDocument' \
  -e 'interface MarkdownDocument' \
  -e 'type SearchResult' \
  -e 'interface SearchResult' \
  -e 'markdownDocuments' \
  src/renderer/src/components/editor tests/e2e/markdown-note-graph.spec.ts | head -120

Repository: stablyai/orca

Length of output: 27526


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- numbered graph builder ---'
nl -ba src/renderer/src/components/editor/markdown-note-graph.ts | sed -n '10,90p'
printf '%s\n' '--- numbered dialog search and active handling ---'
nl -ba src/renderer/src/components/editor/MarkdownNoteGraphDialog.tsx | sed -n '20,110p'
nl -ba src/renderer/src/components/editor/MarkdownNoteGraphDialog.tsx | sed -n '196,255p'
printf '%s\n' '--- numbered search hook and graph entrypoint ---'
nl -ba src/renderer/src/components/editor/use-markdown-workspace-search.ts | sed -n '15,85p'
nl -ba src/renderer/src/components/editor/MarkdownBacklinksPanel.tsx | sed -n '35,65p'
printf '%s\n' '--- numbered tests ---'
nl -ba src/renderer/src/components/editor/markdown-note-graph.test.ts | sed -n '30,70p'

Repository: stablyai/orca

Length of output: 15871


Retain the active note when applying the node cap.

buildMarkdownNoteGraph can omit the open note when more than 300 linked notes exist. MarkdownNoteGraphLayer highlights only nodes present in graph.nodes, so the dialog cannot highlight the active note. Pass the active key into the builder and replace the lowest-ranked retained node when necessary.

Suggested fix
 export function buildMarkdownNoteGraph(
   documents: MarkdownDocument[],
   search: SearchResult,
-  maxNodes = MARKDOWN_NOTE_GRAPH_MAX_NODES
+  maxNodes = MARKDOWN_NOTE_GRAPH_MAX_NODES,
+  activeKey?: string
 ): MarkdownNoteGraph {
@@
   const kept = linkedNodes
     .sort((a, b) => b.degree - a.degree || a.key.localeCompare(b.key))
     .slice(0, maxNodes)
+  const active = activeKey ? linkedNodes.find((entry) => entry.key === activeKey) : undefined
+  if (active && kept.length > 0 && !kept.includes(active)) {
+    kept[kept.length - 1] = active
+  }

Make the dialog's search interpreter call buildMarkdownNoteGraph with its existing activeKey; otherwise the builder cannot apply the exception.

…ch roots

Search returns canonical file paths, which differ from the Markdown listing
when the workspace root is aliased; fall back to the relative path so those
hits still count. The node cap could drop the open note, which the dialog
highlights; keep it in place of the lowest-ranked note.

This branch has not been deployed

No deployments
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.

[Feature]: Graph view of linked Markdown notes

2 participants