Repository navigation
feat(markdown): add a note graph for linked Markdown notes - #29868
nebourocket wants to merge 3 commits into
Conversation
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.
There was a problem hiding this comment.
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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to
|
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
78d82958-3e20-4d36-a812-603ae3482174
📒 Files selected for processing: 16
src/renderer/src/components/editor/EditorContent.tsxsrc/renderer/src/components/editor/EditorMarkdownFileSurface.tsxsrc/renderer/src/components/editor/MarkdownBacklinksPanel.tsxsrc/renderer/src/components/editor/MarkdownNoteGraphDialog.tsxsrc/renderer/src/components/editor/markdown-backlinks.test.tssrc/renderer/src/components/editor/markdown-backlinks.tssrc/renderer/src/components/editor/markdown-link-resolver.tssrc/renderer/src/components/editor/markdown-note-graph-layout.tssrc/renderer/src/components/editor/markdown-note-graph-viewport.test.tssrc/renderer/src/components/editor/markdown-note-graph-viewport.tssrc/renderer/src/components/editor/markdown-note-graph.test.tssrc/renderer/src/components/editor/markdown-note-graph.tssrc/renderer/src/components/editor/use-markdown-workspace-search.tssrc/renderer/src/i18n/locales/en.jsontests/e2e/markdown-backlinks.spec.tstests/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.
| 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 | ||
| } | ||
| } |
There was a problem hiding this comment.
🎯 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.tsxRepository: 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/srcRepository: 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 -120Repository: 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.
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:
N notes, M links, plus a notice when the graph was trimmedMechanism:
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.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.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.Dialogprimitive. Pan and zoom only change theviewBox; the math is inmarkdown-note-graph-viewport.tsand 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.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:
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 unlinkedisland.mdis left out.Testing
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, andmeetscaling and client-to-view mapping are correct.New e2e test,
tests/e2e/markdown-note-graph.spec.ts:The backlinks e2e test still passes.
Other checks:
pnpm tcpnpm run check:code-quality:changedcheck:max-lines-ratchetTested 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
Notes
fill-primary,fill-muted-foreground,stroke-border), so light and dark mode both work.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (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.