markshelf 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/.next/standalone/.next/BUILD_ID +1 -1
  2. package/.next/standalone/.next/app-path-routes-manifest.json +1 -0
  3. package/.next/standalone/.next/build-manifest.json +3 -3
  4. package/.next/standalone/.next/prerender-manifest.json +3 -3
  5. package/.next/standalone/.next/routes-manifest.json +6 -0
  6. package/.next/standalone/.next/server/app/_global-error.html +1 -1
  7. package/.next/standalone/.next/server/app/_global-error.rsc +1 -1
  8. package/.next/standalone/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  9. package/.next/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  10. package/.next/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  11. package/.next/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  12. package/.next/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  13. package/.next/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  14. package/.next/standalone/.next/server/app/_not-found.html +1 -1
  15. package/.next/standalone/.next/server/app/_not-found.rsc +2 -2
  16. package/.next/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +2 -2
  17. package/.next/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  18. package/.next/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +2 -2
  19. package/.next/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  20. package/.next/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  21. package/.next/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  22. package/.next/standalone/.next/server/app/api/diff/route.js +3 -2
  23. package/.next/standalone/.next/server/app/api/diff/route.js.nft.json +1 -1
  24. package/.next/standalone/.next/server/app/api/file/route.js +3 -2
  25. package/.next/standalone/.next/server/app/api/file/route.js.nft.json +1 -1
  26. package/.next/standalone/.next/server/app/api/graph/route.js +3 -2
  27. package/.next/standalone/.next/server/app/api/graph/route.js.nft.json +1 -1
  28. package/.next/standalone/.next/server/app/api/history/route.js +3 -2
  29. package/.next/standalone/.next/server/app/api/history/route.js.nft.json +1 -1
  30. package/.next/standalone/.next/server/app/api/search/route.js +3 -2
  31. package/.next/standalone/.next/server/app/api/search/route.js.nft.json +1 -1
  32. package/.next/standalone/.next/server/app/api/timeline/route.js +3 -2
  33. package/.next/standalone/.next/server/app/api/timeline/route.js.nft.json +1 -1
  34. package/.next/standalone/.next/server/app/api/tree/route.js +3 -2
  35. package/.next/standalone/.next/server/app/api/tree/route.js.nft.json +1 -1
  36. package/.next/standalone/.next/server/app/api/watch/route/app-paths-manifest.json +3 -0
  37. package/.next/standalone/.next/server/app/api/watch/route/build-manifest.json +9 -0
  38. package/.next/standalone/.next/server/app/api/watch/route/server-reference-manifest.json +4 -0
  39. package/.next/standalone/.next/server/app/api/watch/route.js +6 -0
  40. package/.next/standalone/.next/server/app/api/watch/route.js.map +5 -0
  41. package/.next/standalone/.next/server/app/api/watch/route.js.nft.json +1 -0
  42. package/.next/standalone/.next/server/app/api/watch/route_client-reference-manifest.js +3 -0
  43. package/.next/standalone/.next/server/app/favicon.ico/route.js +2 -1
  44. package/.next/standalone/.next/server/app/favicon.ico/route.js.nft.json +1 -1
  45. package/.next/standalone/.next/server/app/index.html +1 -1
  46. package/.next/standalone/.next/server/app/index.rsc +3 -3
  47. package/.next/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
  48. package/.next/standalone/.next/server/app/index.segments/_full.segment.rsc +3 -3
  49. package/.next/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  50. package/.next/standalone/.next/server/app/index.segments/_index.segment.rsc +2 -2
  51. package/.next/standalone/.next/server/app/index.segments/_tree.segment.rsc +2 -2
  52. package/.next/standalone/.next/server/app/page.js.nft.json +1 -1
  53. package/.next/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
  54. package/.next/standalone/.next/server/app-paths-manifest.json +1 -0
  55. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0-_k816._.js +3 -0
  56. package/.next/standalone/.next/server/chunks/{[root-of-the-server]__04otwp7._.js → [root-of-the-server]__01e7zo7._.js} +2 -2
  57. package/.next/standalone/.next/server/chunks/{[root-of-the-server]__0zoyna0._.js → [root-of-the-server]__053gm34._.js} +2 -2
  58. package/.next/standalone/.next/server/chunks/{[root-of-the-server]__0_gt~a4._.js → [root-of-the-server]__0d.-s5p._.js} +2 -2
  59. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0i.wyss._.js +6 -0
  60. package/.next/standalone/.next/server/chunks/{[root-of-the-server]__0qnrcw7._.js → [root-of-the-server]__0nr71d2._.js} +2 -2
  61. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0op9af~._.js +3 -0
  62. package/.next/standalone/.next/server/chunks/{[root-of-the-server]__01cq2u6._.js → [root-of-the-server]__0rwylex._.js} +2 -2
  63. package/.next/standalone/.next/server/chunks/{[root-of-the-server]__0yvq0sd._.js → [root-of-the-server]__13vatcq._.js} +2 -2
  64. package/.next/standalone/.next/server/chunks/_next-internal_server_app_api_watch_route_actions_0go0kk3.js +3 -0
  65. package/.next/standalone/.next/server/chunks/node_modules_next_04~_e52._.js +13 -0
  66. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__05ar4zx._.js +2 -2
  67. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__09qrkq5._.js +5 -5
  68. package/.next/standalone/.next/server/chunks/ssr/{[root-of-the-server]__0serya4._.js → [root-of-the-server]__11e9~iq._.js} +2 -2
  69. package/.next/standalone/.next/server/chunks/ssr/{node_modules_10cz306._.js → node_modules_02chd8n._.js} +1 -1
  70. package/.next/standalone/.next/server/chunks/ssr/{node_modules_0eva9q1._.js → node_modules_08z1b9i._.js} +1 -1
  71. package/.next/standalone/.next/server/chunks/ssr/{node_modules_05e-8m3._.js → node_modules_0f-9xhq._.js} +1 -1
  72. package/.next/standalone/.next/server/chunks/ssr/{node_modules_06r3o30._.js → node_modules_0u-.0s2._.js} +1 -1
  73. package/.next/standalone/.next/server/chunks/ssr/{node_modules_09.cbx4._.js → node_modules_0vqo_80._.js} +1 -1
  74. package/.next/standalone/.next/server/chunks/ssr/{node_modules_11wp0ye._.js → node_modules_0xmn29o._.js} +1 -1
  75. package/.next/standalone/.next/server/chunks/ssr/{node_modules_0ic-wja._.js → node_modules_0~k33bz._.js} +1 -1
  76. package/.next/standalone/.next/server/chunks/ssr/{node_modules_0w2-q.z._.js → node_modules_10a06qi._.js} +1 -1
  77. package/.next/standalone/.next/server/middleware-build-manifest.js +3 -3
  78. package/.next/standalone/.next/server/pages/404.html +1 -1
  79. package/.next/standalone/.next/server/pages/500.html +1 -1
  80. package/.next/standalone/.next/server/server-reference-manifest.js +1 -1
  81. package/.next/standalone/.next/server/server-reference-manifest.json +1 -1
  82. package/.next/standalone/.next/static/chunks/0b42--.p9znhl.css +1 -0
  83. package/.next/standalone/.next/static/chunks/0wy.nfhujao0b.js +11 -0
  84. package/.next/standalone/docs//344/273/225/346/247/230/README.md +9 -0
  85. package/.next/standalone/docs//344/273/225/346/247/230/SPEC1-CLI/README.md +3 -0
  86. package/.next/standalone/docs//344/273/225/346/247/230/SPEC1-CLI/SPEC1.1-bin-cli.md +14 -0
  87. package/.next/standalone/docs//344/273/225/346/247/230/SPEC2-/343/202/260/343/203/251/343/203/225/346/217/217/347/224/273/README.md +3 -0
  88. package/.next/standalone/docs//344/273/225/346/247/230/SPEC2-/343/202/260/343/203/251/343/203/225/346/217/217/347/224/273/SPEC2.1-graph-api.md +16 -0
  89. package/.next/standalone/docs//344/273/225/346/247/230/SPEC2-/343/202/260/343/203/251/343/203/225/346/217/217/347/224/273/SPEC2.2-breadthfirst-layout.md +10 -0
  90. package/.next/standalone/docs//344/273/225/346/247/230/SPEC3-UI/343/202/263/343/203/263/343/203/235/343/203/274/343/203/215/343/203/263/343/203/210/README.md +3 -0
  91. package/.next/standalone/docs//344/273/225/346/247/230/SPEC3-UI/343/202/263/343/203/263/343/203/235/343/203/274/343/203/215/343/203/263/343/203/210/SPEC3.1-PreviewPopup.md +10 -0
  92. package/.next/standalone/docs//344/273/225/346/247/230/SPEC3-UI/343/202/263/343/203/263/343/203/235/343/203/274/343/203/215/343/203/263/343/203/210/SPEC3.2-TreeView.md +10 -0
  93. package/.next/standalone/docs//347/224/250/350/252/236/351/233/206/Cytoscape.md +5 -0
  94. package/.next/standalone/docs//347/224/250/350/252/236/351/233/206/Markdown.md +5 -0
  95. package/.next/standalone/docs//347/224/250/350/252/236/351/233/206/Nextjs.md +5 -0
  96. package/.next/standalone/docs//347/224/250/350/252/236/351/233/206/breadthfirst.md +5 -0
  97. package/.next/standalone/docs//347/224/250/350/252/236/351/233/206/npx.md +5 -0
  98. package/.next/standalone/docs//347/224/250/350/252/236/351/233/206/standalone.md +5 -0
  99. package/.next/standalone/docs//347/224/250/350/252/236/351/233/206//343/203/204/343/203/252/343/203/274/343/203/223/343/203/245/343/203/274.md +5 -0
  100. package/.next/standalone/docs//347/224/250/350/252/236/351/233/206//343/203/227/343/203/254/343/203/223/343/203/245/343/203/274/343/203/235/343/203/203/343/203/227/343/202/242/343/203/203/343/203/227.md +5 -0
  101. package/.next/standalone/docs//347/224/250/350/252/236/351/233/206//343/203/252/343/203/263/343/202/257/343/202/260/343/203/251/343/203/225.md +5 -0
  102. package/.next/standalone/docs//350/246/201/344/273/266/345/256/232/347/276/251/README.md +9 -0
  103. package/.next/standalone/docs//350/246/201/344/273/266/345/256/232/347/276/251/REQ1-/343/203/223/343/203/245/343/203/274/343/202/242/350/265/267/345/213/225/README.md +3 -0
  104. package/.next/standalone/docs//350/246/201/344/273/266/345/256/232/347/276/251/REQ1-/343/203/223/343/203/245/343/203/274/343/202/242/350/265/267/345/213/225/REQ1.1-npx/350/265/267/345/213/225.md +13 -0
  105. package/.next/standalone/docs//350/246/201/344/273/266/345/256/232/347/276/251/REQ2-/343/203/252/343/203/263/343/202/257/343/202/260/343/203/251/343/203/225/README.md +3 -0
  106. package/.next/standalone/docs//350/246/201/344/273/266/345/256/232/347/276/251/REQ2-/343/203/252/343/203/263/343/202/257/343/202/260/343/203/251/343/203/225/REQ2.1-/343/202/260/343/203/251/343/203/225/346/217/217/347/224/273.md +11 -0
  107. package/.next/standalone/docs//350/246/201/344/273/266/345/256/232/347/276/251/REQ2-/343/203/252/343/203/263/343/202/257/343/202/260/343/203/251/343/203/225/REQ2.2-/351/232/216/345/261/244/345/210/207/346/233/277.md +10 -0
  108. package/.next/standalone/docs//350/246/201/344/273/266/345/256/232/347/276/251/REQ2-/343/203/252/343/203/263/343/202/257/343/202/260/343/203/251/343/203/225/REQ2.3-/343/203/225/343/202/251/343/203/253/343/203/200/351/231/244/345/244/226.md +10 -0
  109. package/.next/standalone/docs//350/246/201/344/273/266/345/256/232/347/276/251/REQ3-/343/203/227/343/203/254/343/203/223/343/203/245/343/203/274/343/201/250/343/203/204/343/203/252/343/203/274/README.md +3 -0
  110. package/.next/standalone/docs//350/246/201/344/273/266/345/256/232/347/276/251/REQ3-/343/203/227/343/203/254/343/203/223/343/203/245/343/203/274/343/201/250/343/203/204/343/203/252/343/203/274/REQ3.1-/343/203/227/343/203/254/343/203/223/343/203/245/343/203/274/343/203/235/343/203/203/343/203/227/343/202/242/343/203/203/343/203/227.md +15 -0
  111. package/.next/standalone/docs//350/246/201/344/273/266/345/256/232/347/276/251/REQ3-/343/203/227/343/203/254/343/203/223/343/203/245/343/203/274/343/201/250/343/203/204/343/203/252/343/203/274/REQ3.2-/343/203/204/343/203/252/343/203/274/343/203/223/343/203/245/343/203/274.md +14 -0
  112. package/.next/standalone/docs//350/246/201/344/273/266/345/256/232/347/276/251/REQ4-/343/203/212/343/203/223/343/202/262/343/203/274/343/202/267/343/203/247/343/203/263/README.md +3 -0
  113. package/.next/standalone/docs//350/246/201/344/273/266/345/256/232/347/276/251/REQ4-/343/203/212/343/203/223/343/202/262/343/203/274/343/202/267/343/203/247/343/203/263/REQ4.1-/346/210/273/343/202/213/351/200/262/343/202/200.md +10 -0
  114. package/.next/standalone/docs//350/246/201/346/261/202/345/256/232/347/276/251/R1-/343/203/211/343/202/255/343/203/245/343/203/241/343/203/263/343/203/210/351/226/262/350/246/247/346/200/247/R1.1-/347/213/254/347/253/213/343/203/223/343/203/245/343/203/274/343/202/242.md +11 -0
  115. package/.next/standalone/docs//350/246/201/346/261/202/345/256/232/347/276/251/R1-/343/203/211/343/202/255/343/203/245/343/203/241/343/203/263/343/203/210/351/226/262/350/246/247/346/200/247/R1.2-/345/244/247/347/224/273/351/235/242/350/241/250/347/244/272.md +11 -0
  116. package/.next/standalone/docs//350/246/201/346/261/202/345/256/232/347/276/251/R1-/343/203/211/343/202/255/343/203/245/343/203/241/343/203/263/343/203/210/351/226/262/350/246/247/346/200/247/R1.3-/343/203/212/343/203/223/343/202/262/343/203/274/343/202/267/343/203/247/343/203/263/345/261/245/346/255/264.md +9 -0
  117. package/.next/standalone/docs//350/246/201/346/261/202/345/256/232/347/276/251/R1-/343/203/211/343/202/255/343/203/245/343/203/241/343/203/263/343/203/210/351/226/262/350/246/247/346/200/247/README.md +7 -0
  118. package/.next/standalone/docs//350/246/201/346/261/202/345/256/232/347/276/251/R2-/343/203/211/343/202/255/343/203/245/343/203/241/343/203/263/343/203/210/351/226/242/344/277/202/343/201/256/345/217/257/350/246/226/345/214/226/R2.1-/344/276/235/345/255/230/351/226/242/344/277/202/343/201/256/346/212/212/346/217/241.md +9 -0
  119. package/.next/standalone/docs//350/246/201/346/261/202/345/256/232/347/276/251/R2-/343/203/211/343/202/255/343/203/245/343/203/241/343/203/263/343/203/210/351/226/242/344/277/202/343/201/256/345/217/257/350/246/226/345/214/226/R2.2-/345/217/202/347/205/247/345/205/203/343/201/256/346/212/212/346/217/241.md +9 -0
  120. package/.next/standalone/docs//350/246/201/346/261/202/345/256/232/347/276/251/R2-/343/203/211/343/202/255/343/203/245/343/203/241/343/203/263/343/203/210/351/226/242/344/277/202/343/201/256/345/217/257/350/246/226/345/214/226/README.md +8 -0
  121. package/.next/standalone/docs//350/246/201/346/261/202/345/256/232/347/276/251/R3-/343/202/252/343/203/263/343/203/234/343/203/274/343/203/207/343/202/243/343/203/263/343/202/260/346/224/257/346/217/264/R3.1-/347/224/250/350/252/236/343/201/256/345/215/263/346/231/202/347/242/272/350/252/215.md +11 -0
  122. package/.next/standalone/docs//350/246/201/346/261/202/345/256/232/347/276/251/R3-/343/202/252/343/203/263/343/203/234/343/203/274/343/203/207/343/202/243/343/203/263/343/202/260/346/224/257/346/217/264/README.md +7 -0
  123. package/.next/standalone/docs//350/246/201/346/261/202/345/256/232/347/276/251/README.md +9 -0
  124. package/.next/standalone/package.json +1 -1
  125. package/.next/standalone/src/app/api/watch/route.ts +89 -0
  126. package/.next/standalone/src/app/page.tsx +41 -8
  127. package/.next/standalone/src/components/DetailPanel.tsx +38 -6
  128. package/.next/standalone/src/components/HistoryPanel.tsx +3 -1
  129. package/.next/standalone/src/components/LinkGraph.tsx +247 -21
  130. package/.next/standalone/src/components/Markdown.tsx +60 -5
  131. package/.next/standalone/src/components/PreviewPopup.tsx +4 -2
  132. package/.next/standalone/src/components/TimelinePanel.tsx +3 -1
  133. package/.next/standalone/src/components/TreeView.tsx +36 -9
  134. package/.next/standalone/src/lib/links.ts +98 -25
  135. package/.next/standalone/src/lib/useRefreshTick.ts +43 -0
  136. package/.next/standalone/tsconfig.tsbuildinfo +1 -1
  137. package/.next/static/chunks/0b42--.p9znhl.css +1 -0
  138. package/.next/static/chunks/0wy.nfhujao0b.js +11 -0
  139. package/package.json +1 -1
  140. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0j8-xkl._.js +0 -13
  141. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0owpp0l._.js +0 -3
  142. package/.next/standalone/.next/static/chunks/00.xwfz0gk8.7.css +0 -1
  143. package/.next/standalone/.next/static/chunks/0rozoj9pfglno.js +0 -11
  144. package/.next/standalone/AGENTS.md +0 -5
  145. package/.next/standalone/CLAUDE.md +0 -1
  146. package/.next/standalone/markshelf-0.1.0.tgz +0 -0
  147. package/.next/standalone/markshelf-0.1.2.tgz +0 -0
  148. package/.next/static/chunks/00.xwfz0gk8.7.css +0 -1
  149. package/.next/static/chunks/0rozoj9pfglno.js +0 -11
  150. /package/.next/standalone/.next/static/{eGdxHn4o2ccaRraueWazx → pOQs5i4GMjDH6W5XDSjRs}/_buildManifest.js +0 -0
  151. /package/.next/standalone/.next/static/{eGdxHn4o2ccaRraueWazx → pOQs5i4GMjDH6W5XDSjRs}/_clientMiddlewareManifest.js +0 -0
  152. /package/.next/standalone/.next/static/{eGdxHn4o2ccaRraueWazx → pOQs5i4GMjDH6W5XDSjRs}/_ssgManifest.js +0 -0
  153. /package/.next/static/{eGdxHn4o2ccaRraueWazx → pOQs5i4GMjDH6W5XDSjRs}/_buildManifest.js +0 -0
  154. /package/.next/static/{eGdxHn4o2ccaRraueWazx → pOQs5i4GMjDH6W5XDSjRs}/_clientMiddlewareManifest.js +0 -0
  155. /package/.next/static/{eGdxHn4o2ccaRraueWazx → pOQs5i4GMjDH6W5XDSjRs}/_ssgManifest.js +0 -0
@@ -18,6 +18,8 @@ interface Props {
18
18
  onSelect: (path: string) => void;
19
19
  }
20
20
 
21
+ const EXPANDED_KEY = "markshelf:treeExpanded";
22
+
21
23
  /** Collect all folder paths that are ancestors of targetPath */
22
24
  function getAncestorPaths(entries: TreeEntry[], targetPath: string): Set<string> {
23
25
  const result = new Set<string>();
@@ -47,17 +49,42 @@ function getAncestorPaths(entries: TreeEntry[], targetPath: string): Set<string>
47
49
  }
48
50
 
49
51
  export function TreeView({ entries, selectedPath, onSelect }: Props) {
50
- // Track which folders are expanded (by path)
51
- const [expanded, setExpanded] = useState<Set<string>>(() => {
52
- // Initially expand top-level hasReadme folders
53
- const initial = new Set<string>();
54
- for (const e of entries) {
55
- if (e.type === "folder" && e.hasReadme) {
56
- initial.add(e.path);
52
+ // Track which folders are expanded (by path). Hydrated from localStorage on mount.
53
+ const [expanded, setExpanded] = useState<Set<string>>(new Set());
54
+ const hydratedRef = useRef(false);
55
+
56
+ // Load saved state once on mount; if none, default to expanding top-level hasReadme folders.
57
+ useEffect(() => {
58
+ if (hydratedRef.current) return;
59
+ const saved = localStorage.getItem(EXPANDED_KEY);
60
+ if (saved) {
61
+ try {
62
+ const arr = JSON.parse(saved);
63
+ if (Array.isArray(arr)) {
64
+ setExpanded(new Set(arr.filter((s) => typeof s === "string")));
65
+ hydratedRef.current = true;
66
+ return;
67
+ }
68
+ } catch {
69
+ /* ignore */
57
70
  }
58
71
  }
59
- return initial;
60
- });
72
+ // No saved state: expand top-level hasReadme folders as the default.
73
+ if (entries.length > 0) {
74
+ const initial = new Set<string>();
75
+ for (const e of entries) {
76
+ if (e.type === "folder" && e.hasReadme) initial.add(e.path);
77
+ }
78
+ setExpanded(initial);
79
+ hydratedRef.current = true;
80
+ }
81
+ }, [entries]);
82
+
83
+ // Persist expanded state to localStorage (only after hydration, to avoid overwriting with empty set).
84
+ useEffect(() => {
85
+ if (!hydratedRef.current) return;
86
+ localStorage.setItem(EXPANDED_KEY, JSON.stringify([...expanded]));
87
+ }, [expanded]);
61
88
 
62
89
  const scrollContainerRef = useRef<HTMLDivElement>(null);
63
90
  const selectedRef = useRef<HTMLDivElement>(null);
@@ -15,6 +15,64 @@ export interface LinkGraph {
15
15
  edges: GraphEdge[];
16
16
  }
17
17
 
18
+ // Matches markdown link `[label](url)` excluding image syntax `![...]`.
19
+ // The leading capture group absorbs a non-"!" char (or string start) to avoid
20
+ // matching image links.
21
+ const LINK_RE = /(^|[^!])\[([^\]]*)\]\(([^)]+)\)/g;
22
+ // Fenced code blocks (``` or ~~~) — stripped before scanning
23
+ const FENCE_RE = /(^|\n)(```|~~~)[^\n]*\n[\s\S]*?\n\2/g;
24
+ // Inline code `...`
25
+ const INLINE_CODE_RE = /`[^`\n]*`/g;
26
+
27
+ function stripCode(content: string): string {
28
+ return content.replace(FENCE_RE, "").replace(INLINE_CODE_RE, "");
29
+ }
30
+
31
+ function resolveLink(
32
+ currentPath: string,
33
+ rawUrl: string,
34
+ fileSet: Set<string>,
35
+ ): string | null {
36
+ const cleanUrl = rawUrl.split("#")[0].split("?")[0].trim();
37
+ if (!cleanUrl) return null;
38
+ if (/^[a-z][a-z0-9+.-]*:/i.test(cleanUrl)) return null;
39
+ if (cleanUrl.startsWith("//")) return null;
40
+
41
+ let decoded: string;
42
+ try {
43
+ decoded = decodeURI(cleanUrl);
44
+ } catch {
45
+ decoded = cleanUrl;
46
+ }
47
+
48
+ const currentDir = currentPath.includes("/")
49
+ ? currentPath.slice(0, currentPath.lastIndexOf("/"))
50
+ : "";
51
+ const joined = decoded.startsWith("/")
52
+ ? decoded.slice(1)
53
+ : currentDir
54
+ ? currentDir + "/" + decoded
55
+ : decoded;
56
+
57
+ const parts = joined.split("/");
58
+ const normalized: string[] = [];
59
+ for (const p of parts) {
60
+ if (p === "" || p === ".") continue;
61
+ if (p === "..") {
62
+ normalized.pop();
63
+ continue;
64
+ }
65
+ normalized.push(p);
66
+ }
67
+ const resolved = normalized.join("/");
68
+ if (!resolved) return null;
69
+
70
+ if (fileSet.has(resolved)) return resolved;
71
+ if (fileSet.has(resolved + "/README.md")) return resolved + "/README.md";
72
+ if (!/\.md$/i.test(resolved) && fileSet.has(resolved + ".md")) return resolved + ".md";
73
+ return null;
74
+ }
75
+
18
76
  export function buildLinkGraph(
19
77
  files: FileRef[],
20
78
  readFile: (path: string) => string | null,
@@ -23,43 +81,59 @@ export function buildLinkGraph(
23
81
  .filter((f) => f.displayName.length > 2)
24
82
  .sort((a, b) => b.displayName.length - a.displayName.length);
25
83
 
26
- if (filtered.length === 0) return { nodes: [], edges: [] };
27
-
28
- // Build regex from all displayNames
29
- const escaped = filtered.map((f) =>
30
- f.displayName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"),
31
- );
32
- const regex = new RegExp(`(${escaped.join("|")})`, "g");
33
-
34
- // Map displayName → path for lookup
84
+ const fileSet = new Set(files.map((f) => f.path));
35
85
  const nameToPath = new Map<string, string>();
36
86
  for (const f of filtered) {
37
87
  nameToPath.set(f.displayName, f.path);
38
88
  }
39
89
 
90
+ const displayNameRegex =
91
+ filtered.length === 0
92
+ ? null
93
+ : new RegExp(
94
+ `(${filtered
95
+ .map((f) => f.displayName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))
96
+ .join("|")})`,
97
+ "g",
98
+ );
99
+
40
100
  const edgeSet = new Set<string>();
41
101
  const referencedPaths = new Set<string>();
42
102
 
103
+ const addEdge = (source: string, target: string) => {
104
+ if (target === source) return;
105
+ const key = `${source}\0${target}`;
106
+ if (edgeSet.has(key)) return;
107
+ edgeSet.add(key);
108
+ referencedPaths.add(source);
109
+ referencedPaths.add(target);
110
+ };
111
+
43
112
  for (const file of files) {
44
- const content = readFile(file.path);
45
- if (!content) continue;
46
-
47
- regex.lastIndex = 0;
48
- let match: RegExpExecArray | null;
49
- while ((match = regex.exec(content)) !== null) {
50
- const targetPath = nameToPath.get(match[0]);
51
- if (!targetPath || targetPath === file.path) continue;
52
-
53
- const key = `${file.path}\0${targetPath}`;
54
- if (!edgeSet.has(key)) {
55
- edgeSet.add(key);
56
- referencedPaths.add(file.path);
57
- referencedPaths.add(targetPath);
113
+ const raw = readFile(file.path);
114
+ if (!raw) continue;
115
+ let content = stripCode(raw);
116
+
117
+ // 1) Explicit markdown links: resolve URL → add edge, then strip (url) portion
118
+ // so URL path segments don't create spurious displayName matches.
119
+ content = content.replace(LINK_RE, (_m, lead, label, url) => {
120
+ const target = resolveLink(file.path, url, fileSet);
121
+ if (target) addEdge(file.path, target);
122
+ return `${lead}[${label}]`;
123
+ });
124
+
125
+ // 2) DisplayName auto-matching on the stripped content
126
+ if (displayNameRegex) {
127
+ displayNameRegex.lastIndex = 0;
128
+ let match: RegExpExecArray | null;
129
+ while ((match = displayNameRegex.exec(content)) !== null) {
130
+ const targetPath = nameToPath.get(match[0]);
131
+ if (!targetPath) continue;
132
+ addEdge(file.path, targetPath);
58
133
  }
59
134
  }
60
135
  }
61
136
 
62
- // Only include nodes that have at least one edge
63
137
  const nodes: GraphNode[] = files
64
138
  .filter((f) => referencedPaths.has(f.path))
65
139
  .map((f) => ({ id: f.path, label: f.displayName }));
@@ -81,7 +155,6 @@ function computeSignature(
81
155
  files: FileRef[],
82
156
  statFile: (path: string) => number | null,
83
157
  ): string {
84
- // Sort paths for stability, then join "path\0mtime"
85
158
  const sorted = [...files].sort((a, b) => a.path.localeCompare(b.path));
86
159
  const parts: string[] = [];
87
160
  for (const f of sorted) {
@@ -0,0 +1,43 @@
1
+ "use client";
2
+
3
+ import { useEffect, useState } from "react";
4
+
5
+ type Listener = (tick: number) => void;
6
+
7
+ let currentTick = 0;
8
+ const listeners = new Set<Listener>();
9
+ let eventSource: EventSource | null = null;
10
+ let debounceTimer: ReturnType<typeof setTimeout> | null = null;
11
+
12
+ function bump() {
13
+ currentTick++;
14
+ for (const l of listeners) l(currentTick);
15
+ }
16
+
17
+ function ensureConnected() {
18
+ if (eventSource || typeof window === "undefined") return;
19
+ try {
20
+ eventSource = new EventSource("/api/watch");
21
+ } catch {
22
+ return;
23
+ }
24
+ eventSource.addEventListener("change", () => {
25
+ if (debounceTimer) clearTimeout(debounceTimer);
26
+ debounceTimer = setTimeout(bump, 150);
27
+ });
28
+ // If the connection errors out, EventSource will reconnect automatically.
29
+ }
30
+
31
+ /** Returns a tick that increments when any file under the docs root changes. */
32
+ export function useRefreshTick(): number {
33
+ const [value, setValue] = useState(currentTick);
34
+ useEffect(() => {
35
+ ensureConnected();
36
+ const listener: Listener = (t) => setValue(t);
37
+ listeners.add(listener);
38
+ return () => {
39
+ listeners.delete(listener);
40
+ };
41
+ }, []);
42
+ return value;
43
+ }