@plebeiantech/lat.md 0.12.3-fork.2 → 0.12.3-fork.21

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 (341) hide show
  1. package/README.md +31 -2
  2. package/dist/src/cli/agent-invocation.d.ts +6 -0
  3. package/dist/src/cli/agent-invocation.js +23 -0
  4. package/dist/src/cli/checklist-menu.d.ts +2 -1
  5. package/dist/src/cli/checklist-menu.js +3 -2
  6. package/dist/src/cli/comment-guard.d.ts +14 -0
  7. package/dist/src/cli/comment-guard.js +10 -33
  8. package/dist/src/cli/comment-reminder.d.ts +65 -6
  9. package/dist/src/cli/comment-reminder.js +164 -28
  10. package/dist/src/cli/fork-instructions.d.ts +20 -0
  11. package/dist/src/cli/fork-instructions.js +184 -0
  12. package/dist/src/cli/fork-scaffold.d.ts +106 -0
  13. package/dist/src/cli/fork-scaffold.js +490 -0
  14. package/dist/src/cli/graph.d.ts +1 -1
  15. package/dist/src/cli/hook.d.ts +26 -0
  16. package/dist/src/cli/hook.js +115 -64
  17. package/dist/src/cli/index.js +166 -64
  18. package/dist/src/cli/init-preferences.d.ts +4 -0
  19. package/dist/src/cli/init-preferences.js +36 -0
  20. package/dist/src/cli/init.d.ts +2 -1
  21. package/dist/src/cli/init.js +107 -50
  22. package/dist/src/cli/reindex.d.ts +1 -1
  23. package/dist/src/cli/reindex.js +7 -10
  24. package/dist/src/cli/search.d.ts +14 -4
  25. package/dist/src/cli/search.js +116 -100
  26. package/dist/src/cli/ui-build-server.d.ts +12 -0
  27. package/dist/src/cli/ui-build-server.js +26 -0
  28. package/dist/src/cli/ui-build.d.ts +4 -0
  29. package/dist/src/cli/ui-build.js +13 -0
  30. package/dist/src/cli/ui.d.ts +1 -1
  31. package/dist/src/cli/ui.js +18 -2
  32. package/dist/src/fork/antigravity-hook.d.ts +47 -0
  33. package/dist/src/fork/antigravity-hook.js +424 -0
  34. package/dist/src/fork/antigravity-init.d.ts +17 -0
  35. package/dist/src/fork/antigravity-init.js +124 -0
  36. package/dist/src/fork/upstream-drift-cli.js +2 -0
  37. package/dist/src/fork/upstream-drift.d.ts +26 -0
  38. package/dist/src/fork/upstream-drift.js +185 -0
  39. package/dist/src/fork/upstream-guard-cli.d.ts +1 -0
  40. package/dist/src/fork/upstream-guard-cli.js +2 -0
  41. package/dist/src/fork/upstream-guard.d.ts +72 -0
  42. package/dist/src/fork/upstream-guard.js +445 -0
  43. package/dist/src/graph-export.d.ts +2 -0
  44. package/dist/src/graph-export.js +38 -19
  45. package/dist/src/knowledge/claude-memory.d.ts +1 -0
  46. package/dist/src/knowledge/claude-memory.js +33 -4
  47. package/dist/src/knowledge/index.js +2 -2
  48. package/dist/src/mcp/server.js +34 -18
  49. package/dist/src/search/cache.d.ts +3 -0
  50. package/dist/src/search/cache.js +104 -0
  51. package/dist/src/search/chunks.d.ts +23 -0
  52. package/dist/src/search/chunks.js +200 -0
  53. package/dist/src/search/db.d.ts +28 -16
  54. package/dist/src/search/db.js +106 -40
  55. package/dist/src/search/embedder.d.ts +2 -1
  56. package/dist/src/search/embedder.js +7 -6
  57. package/dist/src/search/index.d.ts +6 -2
  58. package/dist/src/search/index.js +176 -53
  59. package/dist/src/search/lexical.d.ts +6 -0
  60. package/dist/src/search/lexical.js +36 -0
  61. package/dist/src/search/lock.d.ts +5 -0
  62. package/dist/src/search/lock.js +45 -0
  63. package/dist/src/search/query.d.ts +26 -0
  64. package/dist/src/search/query.js +103 -0
  65. package/dist/src/search/search.d.ts +17 -7
  66. package/dist/src/search/search.js +164 -14
  67. package/dist/src/search/types.d.ts +15 -0
  68. package/dist/src/search/types.js +1 -0
  69. package/dist/src/view/client/assets/GraphView-0bPe_Q5I.js +456 -0
  70. package/dist/src/view/client/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  71. package/dist/src/view/client/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  72. package/dist/src/view/client/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  73. package/dist/src/view/client/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  74. package/dist/src/view/client/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  75. package/dist/src/view/client/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  76. package/dist/src/view/client/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  77. package/dist/src/view/client/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  78. package/dist/src/view/client/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  79. package/dist/src/view/client/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  80. package/dist/src/view/client/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  81. package/dist/src/view/client/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  82. package/dist/src/view/client/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  83. package/dist/src/view/client/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  84. package/dist/src/view/client/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  85. package/dist/src/view/client/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  86. package/dist/src/view/client/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  87. package/dist/src/view/client/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  88. package/dist/src/view/client/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  89. package/dist/src/view/client/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  90. package/dist/src/view/client/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  91. package/dist/src/view/client/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  92. package/dist/src/view/client/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  93. package/dist/src/view/client/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  94. package/dist/src/view/client/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  95. package/dist/src/view/client/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  96. package/dist/src/view/client/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  97. package/dist/src/view/client/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  98. package/dist/src/view/client/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  99. package/dist/src/view/client/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  100. package/dist/src/view/client/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  101. package/dist/src/view/client/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  102. package/dist/src/view/client/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  103. package/dist/src/view/client/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  104. package/dist/src/view/client/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  105. package/dist/src/view/client/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  106. package/dist/src/view/client/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  107. package/dist/src/view/client/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  108. package/dist/src/view/client/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  109. package/dist/src/view/client/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  110. package/dist/src/view/client/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  111. package/dist/src/view/client/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  112. package/dist/src/view/client/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  113. package/dist/src/view/client/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  114. package/dist/src/view/client/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  115. package/dist/src/view/client/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  116. package/dist/src/view/client/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  117. package/dist/src/view/client/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  118. package/dist/src/view/client/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  119. package/dist/src/view/client/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  120. package/dist/src/view/client/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  121. package/dist/src/view/client/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  122. package/dist/src/view/client/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  123. package/dist/src/view/client/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  124. package/dist/src/view/client/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  125. package/dist/src/view/client/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  126. package/dist/src/view/client/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  127. package/dist/src/view/client/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  128. package/dist/src/view/client/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  129. package/dist/src/view/client/assets/MarkdownEditor-1_8mI7lO.js +28 -0
  130. package/dist/src/view/client/assets/OrbitControls-DwcpQNja.js +1 -0
  131. package/dist/src/view/client/assets/STLLoader-CLWTKt5i.js +1 -0
  132. package/dist/src/view/client/assets/_commonjsHelpers-CqkleIqs.js +1 -0
  133. package/dist/src/view/client/assets/abnfDiagram-VCTEODGH-BLIuikwY.js +1 -0
  134. package/dist/src/view/client/assets/arc-D4PzdKSA.js +1 -0
  135. package/dist/src/view/client/assets/architectureDiagram-5GKGNRK7-35Egww62.js +36 -0
  136. package/dist/src/view/client/assets/blockDiagram-I7D4REHJ-tqNy53-W.js +129 -0
  137. package/dist/src/view/client/assets/c4Diagram-7LVT6UL2-DZ_GcD9K.js +38 -0
  138. package/dist/src/view/client/assets/channel-DensupHE.js +1 -0
  139. package/dist/src/view/client/assets/chunk-2Q5K7J3B-BUjq4Q7b.js +1 -0
  140. package/dist/src/view/client/assets/chunk-5VM5RSS4-BsIix6I5.js +15 -0
  141. package/dist/src/view/client/assets/chunk-F27PBJKO-Dxo7UheG.js +1 -0
  142. package/dist/src/view/client/assets/chunk-IMKFNOWR-C5lzUDK5.js +231 -0
  143. package/dist/src/view/client/assets/chunk-JWPE2WC7-qCHQlKfY.js +1 -0
  144. package/dist/src/view/client/assets/chunk-POPQ4Y6H-CDPKw21I.js +1 -0
  145. package/dist/src/view/client/assets/chunk-SVP7TREG-CD_C-9M-.js +88 -0
  146. package/dist/src/view/client/assets/chunk-TICWLB2K-ZMatRvad.js +206 -0
  147. package/dist/src/view/client/assets/chunk-XXDRQBXY-dDs4quwg.js +1 -0
  148. package/dist/src/view/client/assets/classDiagram-ZZMXUADV-CV7ArHLW.js +1 -0
  149. package/dist/src/view/client/assets/classDiagram-v2-VYDZK3BY-CV7ArHLW.js +1 -0
  150. package/dist/src/view/client/assets/cose-bilkent-JH36ORCC-CwH3-T1N.js +1 -0
  151. package/dist/src/view/client/assets/cynefin-OW5HDTMX-DodS6r00.js +166 -0
  152. package/dist/src/view/client/assets/cynefinDiagram-5FMLGOSQ-D7WDoy0K.js +62 -0
  153. package/dist/src/view/client/assets/cytoscape.esm-DzSz-X2X.js +321 -0
  154. package/dist/src/view/client/assets/dagre-GXQ25YYZ-yc2GTi5h.js +4 -0
  155. package/dist/src/view/client/assets/defaultLocale-DX6XiGOO.js +1 -0
  156. package/dist/src/view/client/assets/diagram-S7CK7UJ4-CEP0FGL8.js +30 -0
  157. package/dist/src/view/client/assets/diagram-UQ7AKVKN-BZIEojBf.js +41 -0
  158. package/dist/src/view/client/assets/diagram-VSXAHHWV-BSB6COmM.js +3 -0
  159. package/dist/src/view/client/assets/diagram-VX7I27RA-DqfR3psV.js +24 -0
  160. package/dist/src/view/client/assets/diagram-Z3DM3KII-B79t0s5P.js +24 -0
  161. package/dist/src/view/client/assets/ebnfDiagram-PWID7BFC-CqbCQhE1.js +1 -0
  162. package/dist/src/view/client/assets/erDiagram-RLTQ6QDP-BVfoYIhJ.js +99 -0
  163. package/dist/src/view/client/assets/flowDiagram-HODETNUW-Dfyjm6ib.js +168 -0
  164. package/dist/src/view/client/assets/ganttDiagram-EL5Y4UJY-Da9ta_k3.js +292 -0
  165. package/dist/src/view/client/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
  166. package/dist/src/view/client/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
  167. package/dist/src/view/client/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
  168. package/dist/src/view/client/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
  169. package/dist/src/view/client/assets/geist-mono-cyrillic-ext-wght-normal-X_5orZeX.woff2 +0 -0
  170. package/dist/src/view/client/assets/geist-mono-cyrillic-wght-normal-DiZS0aHC.woff2 +0 -0
  171. package/dist/src/view/client/assets/geist-mono-latin-ext-wght-normal-Bwz-egvJ.woff2 +0 -0
  172. package/dist/src/view/client/assets/geist-mono-latin-wght-normal-XN7g48iV.woff2 +0 -0
  173. package/dist/src/view/client/assets/geist-mono-symbols2-wght-normal-CO5SzqOn.woff2 +0 -0
  174. package/dist/src/view/client/assets/geist-mono-vietnamese-wght-normal-DadHysG0.woff2 +0 -0
  175. package/dist/src/view/client/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
  176. package/dist/src/view/client/assets/gitGraphDiagram-WWUBYQGX-BDqlQ6LG.js +106 -0
  177. package/dist/src/view/client/assets/index-BnENo9bV.js +1 -0
  178. package/dist/src/view/client/assets/index-DG0Ez15D.css +1 -0
  179. package/dist/src/view/client/assets/index-heNSjszK.js +13 -0
  180. package/dist/src/view/client/assets/infoDiagram-27XIBGKW-CozIUYm1.js +2 -0
  181. package/dist/src/view/client/assets/init-Gi6I4Gst.js +1 -0
  182. package/dist/src/view/client/assets/ishikawaDiagram-5VMMS53U-tkBLr-Tn.js +70 -0
  183. package/dist/src/view/client/assets/journeyDiagram-3NMN7TZE-Dcd_Ofwc.js +139 -0
  184. package/dist/src/view/client/assets/kanban-definition-UXKFOSKX-CQvZmdAf.js +89 -0
  185. package/dist/src/view/client/assets/katex-HP8lGamR.js +257 -0
  186. package/dist/src/view/client/assets/layout-BxuGL0Ip.js +1 -0
  187. package/dist/src/view/client/assets/linear-D8tR6G5K.js +1 -0
  188. package/dist/src/view/client/assets/logo-RR_KBOAT.svg +149 -0
  189. package/dist/src/view/client/assets/maplibre-gl-CDX6Zuow.js +800 -0
  190. package/dist/src/view/client/assets/mermaid.core-BlHZooLK.js +310 -0
  191. package/dist/src/view/client/assets/mindmap-definition-YA3MSWOX-BqvVz5lC.js +96 -0
  192. package/dist/src/view/client/assets/ordinal-Cboi1Yqb.js +1 -0
  193. package/dist/src/view/client/assets/pegDiagram-XKGWAZYB-BkbOOTxX.js +1 -0
  194. package/dist/src/view/client/assets/pieDiagram-E7YTZNPT-BToTpG0m.js +39 -0
  195. package/dist/src/view/client/assets/quadrantDiagram-AXDQQJYC-CerD2TfT.js +7 -0
  196. package/dist/src/view/client/assets/railroadDiagram-O6MQD6OU-B2oElPYD.js +1 -0
  197. package/dist/src/view/client/assets/requirementDiagram-BXWQKSXE-BCL8RGFd.js +84 -0
  198. package/dist/src/view/client/assets/sankeyDiagram-P5KCCOFB-BqnkNRPm.js +40 -0
  199. package/dist/src/view/client/assets/sequenceDiagram-WJ2MYXX4-DKSKYknp.js +162 -0
  200. package/dist/src/view/client/assets/sizeCapture-INFHLROL-D8reQ7IM.js +1 -0
  201. package/dist/src/view/client/assets/stateDiagram-D77RDMKH-B-Eme-BN.js +1 -0
  202. package/dist/src/view/client/assets/stateDiagram-v2-MP3YSRHH-yXL-Y-Ym.js +1 -0
  203. package/dist/src/view/client/assets/swimlanes-42K2YHIH-lK0158X4.js +1 -0
  204. package/dist/src/view/client/assets/swimlanesDiagram-VR7AAH4N-CGn5WOGw.js +8 -0
  205. package/dist/src/view/client/assets/three.module-PDSP0dbZ.js +4108 -0
  206. package/dist/src/view/client/assets/timeline-definition-24CTP7MA-imh-edhJ.js +120 -0
  207. package/dist/src/view/client/assets/vennDiagram-4TSXK5OY-Ixwhcd6r.js +34 -0
  208. package/dist/src/view/client/assets/wardleyDiagram-VM6X3IG4-Cvr_zzKI.js +78 -0
  209. package/dist/src/view/client/assets/xychartDiagram-S5SC5T6Z-BvcmHKlQ.js +7 -0
  210. package/dist/src/view/client/index.html +2 -2
  211. package/dist/src/view/client-shell.d.ts +2 -0
  212. package/dist/src/view/client-shell.js +5 -0
  213. package/dist/src/view/diagnostics.d.ts +3 -2
  214. package/dist/src/view/diagnostics.js +49 -58
  215. package/dist/src/view/document-edit.d.ts +8 -0
  216. package/dist/src/view/document-edit.js +25 -0
  217. package/dist/src/view/document-route.d.ts +14 -0
  218. package/dist/src/view/document-route.js +126 -0
  219. package/dist/src/view/document-tree.d.ts +18 -0
  220. package/dist/src/view/document-tree.js +139 -0
  221. package/dist/src/view/external-document-tree.d.ts +3 -0
  222. package/dist/src/view/external-document-tree.js +674 -0
  223. package/dist/src/view/git-diff.js +205 -1
  224. package/dist/src/view/git.js +1 -1
  225. package/dist/src/view/graph.d.ts +7 -0
  226. package/dist/src/view/graph.js +267 -0
  227. package/dist/src/view/highlight.d.ts +10 -2
  228. package/dist/src/view/highlight.js +50648 -3166
  229. package/dist/src/view/markdown.d.ts +8 -3
  230. package/dist/src/view/markdown.js +311 -41
  231. package/dist/src/view/preindexed-search.d.ts +15 -0
  232. package/dist/src/view/preindexed-search.js +25 -0
  233. package/dist/src/view/protocol.d.ts +95 -6
  234. package/dist/src/view/protocol.js +1 -1
  235. package/dist/src/view/publication.d.ts +2 -0
  236. package/dist/src/view/publication.js +78 -0
  237. package/dist/src/view/references.d.ts +13 -26
  238. package/dist/src/view/references.js +150 -119
  239. package/dist/src/view/repository.d.ts +18 -5
  240. package/dist/src/view/repository.js +269 -27
  241. package/dist/src/view/request-security.d.ts +5 -0
  242. package/dist/src/view/request-security.js +46 -0
  243. package/dist/src/view/search-result.d.ts +4 -0
  244. package/dist/src/view/search-result.js +25 -0
  245. package/dist/src/view/search.d.ts +7 -2
  246. package/dist/src/view/search.js +23 -33
  247. package/dist/src/view/server-build.d.ts +21 -0
  248. package/dist/src/view/server-build.js +145 -0
  249. package/dist/src/view/server-deployment.d.ts +31 -0
  250. package/dist/src/view/server-deployment.js +94 -0
  251. package/dist/src/view/server-index-worker.d.ts +6 -0
  252. package/dist/src/view/server-index-worker.js +14 -0
  253. package/dist/src/view/server.d.ts +14 -2
  254. package/dist/src/view/server.js +254 -51
  255. package/dist/src/view/source-target.d.ts +10 -0
  256. package/dist/src/view/source-target.js +43 -0
  257. package/dist/src/view/static-build.d.ts +32 -0
  258. package/dist/src/view/static-build.js +741 -0
  259. package/dist/src/view/static-protocol.d.ts +47 -0
  260. package/dist/src/view/static-protocol.js +15 -0
  261. package/dist/src/view/store.d.ts +26 -3
  262. package/dist/src/view/store.js +325 -44
  263. package/dist/src/view/table-of-contents.d.ts +9 -0
  264. package/dist/src/view/table-of-contents.js +83 -0
  265. package/dist/src/view/vercel-build.d.ts +24 -0
  266. package/dist/src/view/vercel-build.js +140 -0
  267. package/dist/src/view/vercel-server-build.d.ts +10 -0
  268. package/dist/src/view/vercel-server-build.js +61 -0
  269. package/dist/vendor/lat.md-server/cli.d.ts +2 -0
  270. package/dist/vendor/lat.md-server/cli.js +12 -0
  271. package/dist/vendor/lat.md-server/index.d.ts +38 -0
  272. package/dist/vendor/lat.md-server/index.js +128 -0
  273. package/package.json +72 -25
  274. package/plugins/lat-md/README.md +61 -0
  275. package/plugins/lat-md/hooks.json +38 -0
  276. package/plugins/lat-md/plugin.json +9 -0
  277. package/plugins/lat-md/rules/AGENTS.md +118 -0
  278. package/plugins/lat-md/skills/lat-md/SKILL.md +178 -0
  279. package/plugins/lat-md/skills/lat-md-conventions/SKILL.md +182 -0
  280. package/templates/AGENTS.md +19 -20
  281. package/templates/cursor-rules.md +14 -7
  282. package/templates/fork/conventions.md +173 -0
  283. package/templates/opencode-plugin.ts +9 -9
  284. package/templates/pi-extension.ts +11 -11
  285. package/templates/skill/SKILL.md +28 -17
  286. package/dist/src/cli/check-frontmatter.d.ts +0 -12
  287. package/dist/src/cli/check-frontmatter.js +0 -44
  288. package/dist/src/cli/check-mode.d.ts +0 -6
  289. package/dist/src/cli/check-mode.js +0 -303
  290. package/dist/src/cli/check-status.d.ts +0 -74
  291. package/dist/src/cli/check-status.js +0 -217
  292. package/dist/src/cli/check.d.ts +0 -45
  293. package/dist/src/cli/check.js +0 -777
  294. package/dist/src/cli/context.d.ts +0 -11
  295. package/dist/src/cli/context.js +0 -58
  296. package/dist/src/cli/expand.d.ts +0 -8
  297. package/dist/src/cli/expand.js +0 -94
  298. package/dist/src/cli/gen-index.d.ts +0 -45
  299. package/dist/src/cli/gen-index.js +0 -235
  300. package/dist/src/cli/link-scheme.d.ts +0 -54
  301. package/dist/src/cli/link-scheme.js +0 -101
  302. package/dist/src/cli/locate.d.ts +0 -2
  303. package/dist/src/cli/locate.js +0 -17
  304. package/dist/src/cli/refs.d.ts +0 -22
  305. package/dist/src/cli/refs.js +0 -229
  306. package/dist/src/cli/section.d.ts +0 -43
  307. package/dist/src/cli/section.js +0 -252
  308. package/dist/src/cli/select-menu.d.ts +0 -13
  309. package/dist/src/cli/select-menu.js +0 -100
  310. package/dist/src/code-refs.d.ts +0 -17
  311. package/dist/src/code-refs.js +0 -277
  312. package/dist/src/config.d.ts +0 -29
  313. package/dist/src/config.js +0 -83
  314. package/dist/src/context.d.ts +0 -23
  315. package/dist/src/context.js +0 -11
  316. package/dist/src/extensions/wiki-link/from-markdown.d.ts +0 -5
  317. package/dist/src/extensions/wiki-link/from-markdown.js +0 -34
  318. package/dist/src/extensions/wiki-link/index.d.ts +0 -4
  319. package/dist/src/extensions/wiki-link/index.js +0 -3
  320. package/dist/src/extensions/wiki-link/syntax.d.ts +0 -14
  321. package/dist/src/extensions/wiki-link/syntax.js +0 -121
  322. package/dist/src/extensions/wiki-link/to-markdown.d.ts +0 -5
  323. package/dist/src/extensions/wiki-link/to-markdown.js +0 -28
  324. package/dist/src/extensions/wiki-link/types.d.ts +0 -34
  325. package/dist/src/format.d.ts +0 -8
  326. package/dist/src/format.js +0 -43
  327. package/dist/src/init-version.d.ts +0 -10
  328. package/dist/src/init-version.js +0 -49
  329. package/dist/src/lattice.d.ts +0 -108
  330. package/dist/src/lattice.js +0 -816
  331. package/dist/src/parser.d.ts +0 -3
  332. package/dist/src/parser.js +0 -18
  333. package/dist/src/source-parser.d.ts +0 -27
  334. package/dist/src/source-parser.js +0 -916
  335. package/dist/src/untrusted.d.ts +0 -24
  336. package/dist/src/untrusted.js +0 -97
  337. package/dist/src/view/client/assets/index-B0n0u03y.css +0 -1
  338. package/dist/src/view/client/assets/index-xm2_px4q.js +0 -23
  339. package/dist/src/walk.d.ts +0 -18
  340. package/dist/src/walk.js +0 -27
  341. /package/dist/src/{extensions/wiki-link/types.js → fork/upstream-drift-cli.d.ts} +0 -0
@@ -1,22 +1,30 @@
1
1
  import { readFile, realpath } from 'node:fs/promises';
2
- import { dirname, extname, isAbsolute, relative, resolve, sep, } from 'node:path';
3
- import { buildFileIndex, buildSectionSlugIndex, flattenSections, resolveRef, } from '../lattice.js';
4
- import { resolveSourceSymbol, SOURCE_EXTENSIONS, } from '../source-parser.js';
5
- import { toPosix } from '../walk.js';
2
+ import { dirname, extname, isAbsolute, join, posix, relative, resolve, sep, } from 'node:path';
3
+ import { buildFileIndex, buildSectionSlugIndex, flattenSections, resolveRef, } from '@plebeiantech/lat.md-core/lattice-model';
4
+ import { createExternalResolver, } from '@plebeiantech/lat.md-core/external-sources';
5
+ import { addExternalDocumentAliasAnchors, externalDocumentSections, } from '@plebeiantech/lat.md-core/external-documents';
6
+ import { resolveSourceSymbol, SourceParserRuntime, } from '@plebeiantech/lat.md-core/source-parser';
7
+ import { isSourceFileExtension } from '@plebeiantech/lat.md-core/source-formats';
8
+ import { toPosix } from '@plebeiantech/lat.md-core/path';
9
+ import { renderExternalDocumentTree } from './external-document-tree.js';
10
+ import { visitDocumentElements } from './document-tree.js';
6
11
  import { highlightSource } from './highlight.js';
7
- import { renderSourceReferenceContext, } from './references.js';
12
+ import { renderMarkdown } from './markdown.js';
13
+ import { renderExternalSectionBackReferences, renderExternalSourceReferences, renderSourceReferenceContext, } from './references.js';
14
+ import { buildViewTableOfContents } from './table-of-contents.js';
15
+ import { viewSourceTarget } from './source-target.js';
16
+ import { documentUrl } from './document-route.js';
8
17
  export class ViewDocumentNotFoundError extends Error {
9
18
  }
10
19
  export class ViewSourceNotFoundError extends Error {
11
20
  }
21
+ export class ViewExternalNotFoundError extends Error {
22
+ }
12
23
  function isInside(root, candidate) {
13
24
  const rel = relative(root, candidate);
14
25
  return (rel === '' ||
15
26
  (!isAbsolute(rel) && rel !== '..' && !rel.startsWith(`..${sep}`)));
16
27
  }
17
- function documentUrl(path) {
18
- return `/docs/${path.split('/').map(encodeURIComponent).join('/')}`;
19
- }
20
28
  function sourceUrl(path, symbol, origin) {
21
29
  const encodedPath = path.split('/').map(encodeURIComponent).join('/');
22
30
  const query = new URLSearchParams();
@@ -28,12 +36,127 @@ function sourceUrl(path, symbol, origin) {
28
36
  const fragment = symbol ? `#${encodeURIComponent(symbol)}` : '';
29
37
  return `/code/${encodedPath}${search}${fragment}`;
30
38
  }
31
- function sourceTarget(target) {
32
- const hash = target.indexOf('#');
33
- const path = hash === -1 ? target : target.slice(0, hash);
34
- if (!SOURCE_EXTENSIONS.has(extname(path)))
39
+ export function externalUrl(target) {
40
+ const colon = target.indexOf(':');
41
+ const hash = target.indexOf('#', colon + 1);
42
+ const handle = target.slice(0, colon);
43
+ const path = hash === -1 ? target.slice(colon + 1) : target.slice(colon + 1, hash);
44
+ const fragment = hash === -1 ? '' : target.slice(hash + 1);
45
+ const encodedPath = path.split('/').map(encodeURIComponent).join('/');
46
+ return `/external/${encodeURIComponent(handle)}/${encodedPath}${fragment ? `#${encodeURIComponent(fragment)}` : ''}`;
47
+ }
48
+ function baseExternalTarget(identity) {
49
+ const hash = identity.indexOf('#');
50
+ return hash === -1 ? identity : identity.slice(0, hash);
51
+ }
52
+ function externalFileKey(handle, path) {
53
+ return `${handle}\0${path}`;
54
+ }
55
+ function availableExternalFiles(external, referenceIndex, current) {
56
+ const files = new Map();
57
+ for (const target of referenceIndex.externalByTarget.keys()) {
58
+ try {
59
+ const parsed = external.parse(target);
60
+ if (!parsed)
61
+ continue;
62
+ files.set(externalFileKey(parsed.handle, parsed.resolvedPath), baseExternalTarget(parsed.identity));
63
+ }
64
+ catch {
65
+ // Invalid external references remain diagnostics and are not navigable.
66
+ }
67
+ }
68
+ files.set(externalFileKey(current.handle, current.resolvedPath), baseExternalTarget(current.identity));
69
+ return files;
70
+ }
71
+ function externalDocumentLink(href, current, external, available) {
72
+ if (href.startsWith('#') ||
73
+ href.startsWith('?') ||
74
+ href.startsWith('//') ||
75
+ /^[a-z][a-z\d+.-]*:/i.test(href) ||
76
+ /^\/external(?:\/|$)/.test(href)) {
77
+ return undefined;
78
+ }
79
+ let destination;
80
+ try {
81
+ const encodedPath = current.resolvedPath
82
+ .split('/')
83
+ .map(encodeURIComponent)
84
+ .join('/');
85
+ destination = new URL(href, `http://lat.external/${encodedPath}`);
86
+ }
87
+ catch {
88
+ return null;
89
+ }
90
+ if (destination.origin !== 'http://lat.external')
91
+ return undefined;
92
+ let path;
93
+ let fragment;
94
+ try {
95
+ path = destination.pathname
96
+ .slice(1)
97
+ .split('/')
98
+ .map(decodeURIComponent)
99
+ .join('/');
100
+ fragment = decodeURIComponent(destination.hash.slice(1));
101
+ }
102
+ catch {
103
+ return null;
104
+ }
105
+ path = posix.normalize(path);
106
+ if (!path || path === '.' || path === '..' || path.startsWith('../')) {
107
+ return null;
108
+ }
109
+ let parsed;
110
+ try {
111
+ parsed = external.parse(`${current.handle}:${path}${fragment ? `#${fragment}` : ''}`);
112
+ }
113
+ catch {
114
+ return null;
115
+ }
116
+ if (!parsed)
117
+ return null;
118
+ const availableTarget = available.get(externalFileKey(parsed.handle, parsed.resolvedPath));
119
+ if (!availableTarget)
35
120
  return null;
36
- return { path, symbol: hash === -1 ? '' : target.slice(hash + 1) };
121
+ const route = externalUrl(`${availableTarget}${fragment ? `#${fragment}` : ''}`);
122
+ if (!destination.search)
123
+ return route;
124
+ const hash = route.indexOf('#');
125
+ return hash === -1
126
+ ? `${route}${destination.search}`
127
+ : `${route.slice(0, hash)}${destination.search}${route.slice(hash)}`;
128
+ }
129
+ /** Make repository-relative external-document links reflect pulled files. */
130
+ export function resolveExternalDocumentLinks(tree, current, external, referenceIndex) {
131
+ const available = availableExternalFiles(external, referenceIndex, current);
132
+ visitDocumentElements(tree, (element) => {
133
+ if (element.tagName !== 'a')
134
+ return;
135
+ const href = element.properties.href;
136
+ if (typeof href !== 'string')
137
+ return;
138
+ const resolved = externalDocumentLink(href, current, external, available);
139
+ if (resolved === undefined)
140
+ return;
141
+ if (resolved !== null) {
142
+ element.properties.href = resolved;
143
+ return;
144
+ }
145
+ const currentClasses = element.properties.className;
146
+ const classes = Array.isArray(currentClasses)
147
+ ? currentClasses.map(String)
148
+ : typeof currentClasses === 'string'
149
+ ? currentClasses.split(/\s+/).filter(Boolean)
150
+ : [];
151
+ element.tagName = 'span';
152
+ element.properties = {
153
+ ...element.properties,
154
+ className: [...classes, 'external-source-link-unavailable'],
155
+ title: 'Linked file is not included in this Lat project',
156
+ };
157
+ delete element.properties.href;
158
+ });
159
+ return tree;
37
160
  }
38
161
  function matchingSymbol(symbols, symbolPath) {
39
162
  const parts = symbolPath.split('#');
@@ -45,7 +168,8 @@ function matchingSymbol(symbols, symbolPath) {
45
168
  }
46
169
  return undefined;
47
170
  }
48
- export async function createMarkdownWikiLinkResolver(latDir, requestedPath, loadedSections) {
171
+ export async function createMarkdownWikiLinkResolver(latDir, requestedPath, loadedSections, referenceIndex, externalResolver, publishable) {
172
+ const external = externalResolver ?? (await createExternalResolver(latDir, dirname(latDir)));
49
173
  const projectRoot = dirname(latDir);
50
174
  const flat = flattenSections(loadedSections);
51
175
  const sectionIds = new Set(flat.map((section) => section.id.toLowerCase()));
@@ -57,6 +181,18 @@ export async function createMarkdownWikiLinkResolver(latDir, requestedPath, load
57
181
  .filter((section) => section.filePath === currentFile)
58
182
  .sort((a, b) => a.startLine - b.startLine);
59
183
  return async (target, context) => {
184
+ try {
185
+ const parsed = external.parse(target);
186
+ if (parsed) {
187
+ return {
188
+ href: externalUrl(parsed.identity),
189
+ referenceCount: referenceIndex?.externalByTarget.get(parsed.identity)?.length ?? 0,
190
+ };
191
+ }
192
+ }
193
+ catch {
194
+ return null;
195
+ }
60
196
  const result = resolveRef(target, sectionIds, fileIndex, slugIndex);
61
197
  if (result.ambiguous)
62
198
  return null;
@@ -67,13 +203,17 @@ export async function createMarkdownWikiLinkResolver(latDir, requestedPath, load
67
203
  const fragment = target.includes('#') && section.githubSlug
68
204
  ? `#${encodeURIComponent(section.githubSlug)}`
69
205
  : '';
70
- return `${documentUrl(file)}${fragment}`;
206
+ return {
207
+ href: `${documentUrl(file)}${fragment}`,
208
+ referenceCount: referenceIndex?.incomingBySection.get(section.id.toLowerCase())
209
+ ?.length ?? 0,
210
+ };
71
211
  }
72
- const source = sourceTarget(target);
73
- if (!source)
212
+ const source = viewSourceTarget(target);
213
+ if (!source || (publishable && !(await publishable(source.path))))
74
214
  return null;
75
215
  try {
76
- await readViewSource(projectRoot, source.path, source.symbol);
216
+ await readViewSource(latDir, projectRoot, source.path, source.symbol);
77
217
  let section;
78
218
  for (const candidate of currentSections) {
79
219
  if (candidate.startLine > context.line)
@@ -83,7 +223,10 @@ export async function createMarkdownWikiLinkResolver(latDir, requestedPath, load
83
223
  const origin = section
84
224
  ? { sectionId: section.id, line: context.line }
85
225
  : undefined;
86
- return sourceUrl(source.path, source.symbol, origin);
226
+ return {
227
+ href: sourceUrl(source.path, source.symbol, origin),
228
+ referenceCount: referenceIndex?.sourceReferenceCounts.get(source.key) ?? 0,
229
+ };
87
230
  }
88
231
  catch (error) {
89
232
  if (error instanceof ViewSourceNotFoundError)
@@ -92,11 +235,102 @@ export async function createMarkdownWikiLinkResolver(latDir, requestedPath, load
92
235
  }
93
236
  };
94
237
  }
95
- async function readViewSource(projectRoot, requestedPath, requestedSymbol = '', requestedLine = 0) {
238
+ /** Resolve and render one configured external file through the normal view models. */
239
+ export async function getViewExternal(latDir, projectRoot, targetValue, external, allSections, referenceIndex, publishable) {
240
+ let resolved;
241
+ try {
242
+ resolved = await external.resolve(targetValue);
243
+ }
244
+ catch (error) {
245
+ throw new ViewExternalNotFoundError(error.message);
246
+ }
247
+ const createResolver = (path) => createMarkdownWikiLinkResolver(latDir, path, allSections, referenceIndex, external, publishable);
248
+ if (resolved.kind === 'document') {
249
+ const virtualPath = join(projectRoot, 'lat.md', '.external', resolved.target.handle, resolved.target.resolvedPath);
250
+ const analysis = resolved.document;
251
+ const sections = externalDocumentSections(virtualPath, analysis);
252
+ // Remote-authored wiki links may resolve only to configured external files.
253
+ // Do not call the local resolver before rewriting their URLs.
254
+ const available = availableExternalFiles(external, referenceIndex, resolved.target);
255
+ const resolver = async (target) => {
256
+ try {
257
+ const parsed = external.parse(target);
258
+ if (parsed)
259
+ return { href: externalUrl(parsed.identity), referenceCount: 0 };
260
+ }
261
+ catch {
262
+ return null;
263
+ }
264
+ const href = externalDocumentLink(target, resolved.target, external, available);
265
+ return typeof href === 'string' ? { href, referenceCount: 0 } : null;
266
+ };
267
+ const rendered = analysis.format === 'markdown'
268
+ ? await renderMarkdown(resolved.fullContent, resolved.target.resolvedPath, resolver, {})
269
+ : {
270
+ title: analysis.title,
271
+ tree: await renderExternalDocumentTree(analysis.format, resolved.fullContent),
272
+ };
273
+ resolveExternalDocumentLinks(rendered.tree, resolved.target, external, referenceIndex);
274
+ const fragmentIndex = resolved.target.identity.indexOf('#');
275
+ const baseTarget = fragmentIndex === -1
276
+ ? resolved.target.identity
277
+ : resolved.target.identity.slice(0, fragmentIndex);
278
+ const targetHeadings = new Map();
279
+ targetHeadings.set(baseTarget, analysis.sections[0]?.anchor ?? '');
280
+ for (const section of analysis.sections) {
281
+ for (const alias of section.aliases) {
282
+ const target = `${baseTarget}#${alias}`;
283
+ if (!targetHeadings.has(target)) {
284
+ targetHeadings.set(target, section.anchor);
285
+ }
286
+ }
287
+ }
288
+ return {
289
+ kind: 'markdown',
290
+ target: resolved.target.identity,
291
+ document: {
292
+ path: baseTarget,
293
+ ...rendered,
294
+ tree: addExternalDocumentAliasAnchors(rendered.tree, analysis),
295
+ gitTree: null,
296
+ graphNodeIds: {},
297
+ tableOfContents: buildViewTableOfContents(sections, analysis.sections.map((section) => section.title), {
298
+ errors: [],
299
+ gitTree: null,
300
+ }),
301
+ errors: [],
302
+ backReferences: await renderExternalSectionBackReferences(referenceIndex, targetHeadings, latDir, projectRoot, createResolver),
303
+ frontmatter: { requireCodeMention: false },
304
+ },
305
+ };
306
+ }
307
+ const references = await renderExternalSourceReferences(referenceIndex, resolved.target.identity, latDir, projectRoot, createResolver);
308
+ return {
309
+ kind: 'source',
310
+ target: resolved.target.identity,
311
+ source: {
312
+ path: `${resolved.target.handle}:${resolved.target.authoredPath}`,
313
+ content: resolved.fullContent,
314
+ highlightedLines: highlightSource(resolved.target.resolvedPath, resolved.fullContent),
315
+ focus: resolved.target.fragment
316
+ ? {
317
+ symbol: resolved.target.fragment,
318
+ kind: 'external',
319
+ signature: resolved.signature ?? resolved.target.fragment,
320
+ startLine: resolved.startLine,
321
+ endLine: resolved.endLine,
322
+ }
323
+ : null,
324
+ context: null,
325
+ otherReferences: references,
326
+ },
327
+ };
328
+ }
329
+ async function readViewSource(latDir, projectRoot, requestedPath, requestedSymbol = '', requestedLine = 0) {
96
330
  if (!requestedPath ||
97
331
  requestedPath.includes('\\') ||
98
332
  isAbsolute(requestedPath) ||
99
- !SOURCE_EXTENSIONS.has(extname(requestedPath))) {
333
+ (requestedSymbol && !isSourceFileExtension(extname(requestedPath)))) {
100
334
  throw new ViewSourceNotFoundError('Source document not found');
101
335
  }
102
336
  const candidate = resolve(projectRoot, requestedPath);
@@ -114,7 +348,15 @@ async function readViewSource(projectRoot, requestedPath, requestedSymbol = '',
114
348
  if (!isInside(realRoot, realFile)) {
115
349
  throw new ViewSourceNotFoundError('Source document not found');
116
350
  }
117
- const content = await readFile(realFile, 'utf-8');
351
+ let content;
352
+ try {
353
+ content = new TextDecoder('utf-8', { fatal: true }).decode(await readFile(realFile));
354
+ if (content.includes('\0'))
355
+ throw new Error('Binary file');
356
+ }
357
+ catch {
358
+ throw new ViewSourceNotFoundError('Source file is not readable UTF-8 text');
359
+ }
118
360
  if (!requestedSymbol) {
119
361
  if (!requestedLine)
120
362
  return { path: requestedPath, content, focus: null };
@@ -134,7 +376,7 @@ async function readViewSource(projectRoot, requestedPath, requestedSymbol = '',
134
376
  },
135
377
  };
136
378
  }
137
- const resolved = await resolveSourceSymbol(requestedPath, requestedSymbol, projectRoot);
379
+ const resolved = await resolveSourceSymbol(requestedPath, requestedSymbol, projectRoot, { latDir, runtime: new SourceParserRuntime() });
138
380
  const symbol = resolved.found
139
381
  ? matchingSymbol(resolved.symbols, requestedSymbol)
140
382
  : undefined;
@@ -154,14 +396,14 @@ async function readViewSource(projectRoot, requestedPath, requestedSymbol = '',
154
396
  };
155
397
  }
156
398
  /** Read and highlight a source file after constraining it to the project root. */
157
- export async function getViewSource(latDir, projectRoot, requestedPath, requestedSymbol = '', origin, requestedLine = 0, allSections = [], referenceIndex) {
158
- const source = await readViewSource(projectRoot, requestedPath, requestedSymbol, requestedLine);
399
+ export async function getViewSource(latDir, projectRoot, requestedPath, requestedSymbol = '', origin, requestedLine = 0, allSections = [], referenceIndex, publishable) {
400
+ const source = await readViewSource(latDir, projectRoot, requestedPath, requestedSymbol, requestedLine);
159
401
  const references = referenceIndex
160
- ? await renderSourceReferenceContext(referenceIndex, `${source.path}${requestedSymbol ? `#${requestedSymbol}` : ''}`, origin, latDir, projectRoot, (path) => createMarkdownWikiLinkResolver(latDir, path, allSections))
402
+ ? await renderSourceReferenceContext(referenceIndex, `${source.path}${requestedSymbol ? `#${requestedSymbol}` : ''}`, origin, latDir, projectRoot, (path) => createMarkdownWikiLinkResolver(latDir, path, allSections, referenceIndex, undefined, publishable))
161
403
  : { context: null, otherReferences: [] };
162
404
  return {
163
405
  ...source,
164
- highlightedHtmlLines: highlightSource(source.path, source.content),
406
+ highlightedLines: highlightSource(source.path, source.content),
165
407
  ...references,
166
408
  };
167
409
  }
@@ -0,0 +1,5 @@
1
+ import type { IncomingMessage } from 'node:http';
2
+ /** Check the actual listener authority; forwarding headers are not trusted. */
3
+ export declare function trustedLiveRequest(req: IncomingMessage, configuredHost: string): boolean;
4
+ /** Untrusted repository resources cannot execute with the editor's origin. */
5
+ export declare const RESOURCE_CONTENT_SECURITY_POLICY = "sandbox; default-src 'none'; img-src 'self' data:; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'";
@@ -0,0 +1,46 @@
1
+ const LOOPBACK_HOSTS = new Set(['localhost', '127.0.0.1', '[::1]']);
2
+ const urlHost = (host) => host.includes(':') && !host.startsWith('[')
3
+ ? `[${host}]`
4
+ : host.toLowerCase();
5
+ /** Check the actual listener authority; forwarding headers are not trusted. */
6
+ export function trustedLiveRequest(req, configuredHost) {
7
+ const authority = req.headers.host;
8
+ if (!authority || !/^[a-z\d.\-:[\]]+$/i.test(authority))
9
+ return false;
10
+ let url;
11
+ try {
12
+ url = new URL(`http://${authority}`);
13
+ }
14
+ catch {
15
+ return false;
16
+ }
17
+ if (Number(url.port || 80) !== req.socket.localPort)
18
+ return false;
19
+ const host = urlHost(configuredHost);
20
+ const allowed = new Set([host]);
21
+ if (LOOPBACK_HOSTS.has(host) || host === '0.0.0.0' || host === '[::]') {
22
+ for (const name of LOOPBACK_HOSTS)
23
+ allowed.add(name);
24
+ if (req.socket.localAddress)
25
+ allowed.add(urlHost(req.socket.localAddress));
26
+ }
27
+ if (!allowed.has(url.hostname))
28
+ return false;
29
+ const origin = req.headers.origin;
30
+ if (origin !== undefined && origin !== url.origin)
31
+ return false;
32
+ if (!['GET', 'HEAD'].includes(req.method ?? 'GET') &&
33
+ req.headers['sec-fetch-site'] === 'cross-site')
34
+ return false;
35
+ // Do not accept an absolute-form URL for a different authority.
36
+ try {
37
+ if (new URL(req.url ?? '/', url).origin !== url.origin)
38
+ return false;
39
+ }
40
+ catch {
41
+ return false;
42
+ }
43
+ return true;
44
+ }
45
+ /** Untrusted repository resources cannot execute with the editor's origin. */
46
+ export const RESOURCE_CONTENT_SECURITY_POLICY = "sandbox; default-src 'none'; img-src 'self' data:; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'";
@@ -0,0 +1,4 @@
1
+ import type { SectionMatch } from '@plebeiantech/lat.md-core/lattice-model';
2
+ import type { ViewSearchResult } from './protocol.js';
3
+ /** Convert one graph section match into the browser search protocol. */
4
+ export declare function viewSearchResult(latDir: string, match: SectionMatch, documentPaths?: ReadonlyMap<string, string>): ViewSearchResult;
@@ -0,0 +1,25 @@
1
+ import { dirname, relative, resolve } from 'node:path';
2
+ import { toPosix } from '@plebeiantech/lat.md-core/path';
3
+ import { documentUrl } from './document-route.js';
4
+ /** Convert one graph section match into the browser search protocol. */
5
+ export function viewSearchResult(latDir, match, documentPaths) {
6
+ const section = match.section;
7
+ const projectRoot = dirname(latDir);
8
+ const path = documentPaths?.get(section.id.toLowerCase()) ??
9
+ toPosix(relative(latDir, resolve(projectRoot, section.filePath)));
10
+ const fileBreadcrumbs = path.replace(/\.md$/i, '').split('/');
11
+ return {
12
+ sectionId: section.id,
13
+ title: section.heading,
14
+ path,
15
+ breadcrumbs: [...fileBreadcrumbs, ...section.id.split('#').slice(1)],
16
+ description: match.evidence?.[0]?.text ?? section.firstParagraph,
17
+ introduction: section.firstParagraph,
18
+ evidence: match.evidence ?? [],
19
+ semanticSimilarity: match.semanticSimilarity,
20
+ semanticRank: match.semanticRank,
21
+ lexicalRank: match.lexicalRank,
22
+ url: documentUrl(path, section.githubSlug ?? ''),
23
+ rankScore: match.rankScore ?? 0,
24
+ };
25
+ }
@@ -1,4 +1,4 @@
1
- import type { SectionMatch } from '../lattice.js';
1
+ import type { Section, SectionMatch } from '@plebeiantech/lat.md-core/lattice-model';
2
2
  import type { ViewSearchResponse } from './protocol.js';
3
3
  export type ViewSearch = (query: string) => Promise<ViewSearchResponse>;
4
4
  export type ViewSearchDependencies = {
@@ -11,4 +11,9 @@ export type ViewSearchDependencies = {
11
11
  }>;
12
12
  };
13
13
  /** Create the lazily indexed semantic search service used by `lat ui`. */
14
- export declare function createViewSearch(latDir: string, dependencies?: ViewSearchDependencies, getGeneration?: () => number): ViewSearch;
14
+ export declare function createViewSearch(latDir: string, dependencies?: ViewSearchDependencies, getGeneration?: () => number, options?: {
15
+ cacheDir?: string;
16
+ preindexed?: boolean;
17
+ sections?: readonly Section[];
18
+ documentPaths?: ReadonlyMap<string, string>;
19
+ }): ViewSearch;
@@ -1,44 +1,34 @@
1
- import { dirname, relative, resolve } from 'node:path';
2
- import { toPosix } from '../walk.js';
1
+ import { viewSearchResult } from './search-result.js';
3
2
  const VIEW_SEARCH_LIMIT = 10;
4
- const defaultDependencies = {
5
- async runIndex(latDir) {
6
- const { runIndex } = await import('../cli/search.js');
7
- await runIndex(latDir);
8
- },
9
- async runSearch(latDir, query, limit, options) {
10
- const { runSearch } = await import('../cli/search.js');
11
- return runSearch(latDir, query, limit, undefined, options);
12
- },
13
- };
14
- function documentUrl(path, headingId) {
15
- const encodedPath = path.split('/').map(encodeURIComponent).join('/');
16
- const fragment = headingId ? `#${encodeURIComponent(headingId)}` : '';
17
- return `/docs/${encodedPath}${fragment}`;
18
- }
19
- function viewSearchResult(latDir, match) {
20
- const section = match.section;
21
- const projectRoot = dirname(latDir);
22
- const path = toPosix(relative(latDir, resolve(projectRoot, section.filePath)));
23
- const fileBreadcrumbs = path.replace(/\.md$/i, '').split('/');
3
+ function defaultDependencies(cacheDir, sectionById) {
24
4
  return {
25
- sectionId: section.id,
26
- title: section.heading,
27
- path,
28
- breadcrumbs: [...fileBreadcrumbs, ...section.id.split('#').slice(1)],
29
- description: section.firstParagraph,
30
- url: documentUrl(path, section.githubSlug),
5
+ async runIndex(latDir) {
6
+ const { runIndex } = await import('../cli/search.js');
7
+ await runIndex(latDir, undefined, undefined, { cacheDir });
8
+ },
9
+ async runSearch(latDir, query, limit, options) {
10
+ const { runSearch } = await import('../cli/search.js');
11
+ return runSearch(latDir, query, limit, undefined, {
12
+ ...options,
13
+ cacheDir,
14
+ sectionById,
15
+ });
16
+ },
31
17
  };
32
18
  }
33
19
  /** Create the lazily indexed semantic search service used by `lat ui`. */
34
- export function createViewSearch(latDir, dependencies = defaultDependencies, getGeneration = () => 0) {
20
+ export function createViewSearch(latDir, dependencies, getGeneration = () => 0, options = {}) {
21
+ const sectionById = options.sections
22
+ ? new Map(options.sections.map((section) => [section.id.toLowerCase(), section]))
23
+ : undefined;
24
+ const resolvedDependencies = dependencies ?? defaultDependencies(options.cacheDir, sectionById);
35
25
  let indexReady = null;
36
- let indexedGeneration = -1;
26
+ let indexedGeneration = options.preindexed ? getGeneration() : -1;
37
27
  const prepareIndex = async () => {
38
28
  while (indexedGeneration < getGeneration() || indexedGeneration < 0) {
39
29
  if (!indexReady) {
40
30
  const generation = getGeneration();
41
- indexReady = dependencies
31
+ indexReady = resolvedDependencies
42
32
  .runIndex(latDir)
43
33
  .then(() => {
44
34
  indexedGeneration = Math.max(indexedGeneration, generation);
@@ -55,10 +45,10 @@ export function createViewSearch(latDir, dependencies = defaultDependencies, get
55
45
  if (!query)
56
46
  return { query: '', results: [] };
57
47
  await prepareIndex();
58
- const search = await dependencies.runSearch(latDir, query, VIEW_SEARCH_LIMIT, { buildIndex: false });
48
+ const search = await resolvedDependencies.runSearch(latDir, query, VIEW_SEARCH_LIMIT, { buildIndex: false });
59
49
  return {
60
50
  query: search.query,
61
- results: search.matches.map((match) => viewSearchResult(latDir, match)),
51
+ results: search.matches.map((match) => viewSearchResult(latDir, match, options.documentPaths)),
62
52
  };
63
53
  };
64
54
  }
@@ -0,0 +1,21 @@
1
+ import { getLatServerVersion } from '../../vendor/lat.md-server/index.js';
2
+ import type { CmdContext } from '@plebeiantech/lat.md-core/context';
3
+ import { analyzeMarkdownProject, type MarkdownProjectAnalysis } from '@plebeiantech/lat.md-core/project-analysis';
4
+ import { getLocalVersion } from '../version.js';
5
+ import { buildStaticView, type StaticViewBuildOptions, type StaticViewBuildResult } from './static-build.js';
6
+ export type ServerViewBuildOptions = Omit<StaticViewBuildOptions, 'searchApi'>;
7
+ export type ServerViewBuildResult = StaticViewBuildResult;
8
+ export type ServerViewBuildDependencies = {
9
+ analyzeMarkdownProject: typeof analyzeMarkdownProject;
10
+ buildStaticView: typeof buildStaticView;
11
+ getLocalVersion: typeof getLocalVersion;
12
+ getLatServerVersion: typeof getLatServerVersion;
13
+ getPackageVersion: typeof getPackageVersion;
14
+ buildSearchIndex: typeof buildServerSearchIndex;
15
+ };
16
+ /** Wait for the index process to exit so native handles cannot lock staging. */
17
+ export declare function buildServerSearchIndex(latDir: string, project: MarkdownProjectAnalysis, cacheDir: string): Promise<void>;
18
+ declare function getPackageVersion(name: string): string;
19
+ /** Build immutable UI data plus the small portable Express search service. */
20
+ export declare function buildServerView(ctx: CmdContext, requestedOutput: string, options?: ServerViewBuildOptions, dependencies?: ServerViewBuildDependencies): Promise<ServerViewBuildResult>;
21
+ export {};