kontexta 7.4.1 → 7.4.3

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 (214) hide show
  1. package/bundle/standalone/CHANGELOG.md +16 -0
  2. package/bundle/standalone/apps/web/.next/BUILD_ID +1 -1
  3. package/bundle/standalone/apps/web/.next/app-build-manifest.json +117 -117
  4. package/bundle/standalone/apps/web/.next/app-path-routes-manifest.json +10 -10
  5. package/bundle/standalone/apps/web/.next/build-manifest.json +5 -5
  6. package/bundle/standalone/apps/web/.next/prerender-manifest.json +3 -3
  7. package/bundle/standalone/apps/web/.next/react-loadable-manifest.json +84 -0
  8. package/bundle/standalone/apps/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  9. package/bundle/standalone/apps/web/.next/server/app/_not-found.html +1 -1
  10. package/bundle/standalone/apps/web/.next/server/app/_not-found.rsc +2 -2
  11. package/bundle/standalone/apps/web/.next/server/app/api/about/route_client-reference-manifest.js +1 -1
  12. package/bundle/standalone/apps/web/.next/server/app/api/agents/[id]/hooks/route.js +1 -1
  13. package/bundle/standalone/apps/web/.next/server/app/api/agents/[id]/hooks/route_client-reference-manifest.js +1 -1
  14. package/bundle/standalone/apps/web/.next/server/app/api/agents/[id]/mcp/route.js +1 -1
  15. package/bundle/standalone/apps/web/.next/server/app/api/agents/[id]/mcp/route_client-reference-manifest.js +1 -1
  16. package/bundle/standalone/apps/web/.next/server/app/api/agents/[id]/route.js +1 -1
  17. package/bundle/standalone/apps/web/.next/server/app/api/agents/[id]/route_client-reference-manifest.js +1 -1
  18. package/bundle/standalone/apps/web/.next/server/app/api/agents/route.js +1 -1
  19. package/bundle/standalone/apps/web/.next/server/app/api/agents/route_client-reference-manifest.js +1 -1
  20. package/bundle/standalone/apps/web/.next/server/app/api/auth/login/route.js +1 -1
  21. package/bundle/standalone/apps/web/.next/server/app/api/auth/login/route_client-reference-manifest.js +1 -1
  22. package/bundle/standalone/apps/web/.next/server/app/api/auth/logout/route_client-reference-manifest.js +1 -1
  23. package/bundle/standalone/apps/web/.next/server/app/api/auth/setup/route.js +1 -1
  24. package/bundle/standalone/apps/web/.next/server/app/api/auth/setup/route_client-reference-manifest.js +1 -1
  25. package/bundle/standalone/apps/web/.next/server/app/api/auth/status/route.js +1 -1
  26. package/bundle/standalone/apps/web/.next/server/app/api/auth/status/route_client-reference-manifest.js +1 -1
  27. package/bundle/standalone/apps/web/.next/server/app/api/auth/token/route.js +1 -1
  28. package/bundle/standalone/apps/web/.next/server/app/api/auth/token/route_client-reference-manifest.js +1 -1
  29. package/bundle/standalone/apps/web/.next/server/app/api/brain/machines/[machineId]/route.js +1 -1
  30. package/bundle/standalone/apps/web/.next/server/app/api/brain/machines/[machineId]/route_client-reference-manifest.js +1 -1
  31. package/bundle/standalone/apps/web/.next/server/app/api/brain/route.js +1 -1
  32. package/bundle/standalone/apps/web/.next/server/app/api/brain/route_client-reference-manifest.js +1 -1
  33. package/bundle/standalone/apps/web/.next/server/app/api/brain/share/route.js +1 -1
  34. package/bundle/standalone/apps/web/.next/server/app/api/brain/share/route_client-reference-manifest.js +1 -1
  35. package/bundle/standalone/apps/web/.next/server/app/api/calendar/conflicts/route.js +1 -1
  36. package/bundle/standalone/apps/web/.next/server/app/api/calendar/conflicts/route_client-reference-manifest.js +1 -1
  37. package/bundle/standalone/apps/web/.next/server/app/api/calendar/entities/[id]/route.js +1 -1
  38. package/bundle/standalone/apps/web/.next/server/app/api/calendar/entities/[id]/route_client-reference-manifest.js +1 -1
  39. package/bundle/standalone/apps/web/.next/server/app/api/calendar/entities/route.js +1 -1
  40. package/bundle/standalone/apps/web/.next/server/app/api/calendar/entities/route_client-reference-manifest.js +1 -1
  41. package/bundle/standalone/apps/web/.next/server/app/api/calendar/events/[id]/route.js +1 -1
  42. package/bundle/standalone/apps/web/.next/server/app/api/calendar/events/[id]/route_client-reference-manifest.js +1 -1
  43. package/bundle/standalone/apps/web/.next/server/app/api/calendar/events/route.js +1 -1
  44. package/bundle/standalone/apps/web/.next/server/app/api/calendar/events/route_client-reference-manifest.js +1 -1
  45. package/bundle/standalone/apps/web/.next/server/app/api/calendar/ics/route.js +1 -1
  46. package/bundle/standalone/apps/web/.next/server/app/api/calendar/ics/route_client-reference-manifest.js +1 -1
  47. package/bundle/standalone/apps/web/.next/server/app/api/calendar/links/route.js +1 -1
  48. package/bundle/standalone/apps/web/.next/server/app/api/calendar/links/route_client-reference-manifest.js +1 -1
  49. package/bundle/standalone/apps/web/.next/server/app/api/calendar/settings/route.js +1 -1
  50. package/bundle/standalone/apps/web/.next/server/app/api/calendar/settings/route_client-reference-manifest.js +1 -1
  51. package/bundle/standalone/apps/web/.next/server/app/api/clip/route.js +1 -1
  52. package/bundle/standalone/apps/web/.next/server/app/api/clip/route_client-reference-manifest.js +1 -1
  53. package/bundle/standalone/apps/web/.next/server/app/api/conflicts/[gid]/route.js +1 -1
  54. package/bundle/standalone/apps/web/.next/server/app/api/conflicts/[gid]/route_client-reference-manifest.js +1 -1
  55. package/bundle/standalone/apps/web/.next/server/app/api/conflicts/route.js +1 -1
  56. package/bundle/standalone/apps/web/.next/server/app/api/conflicts/route_client-reference-manifest.js +1 -1
  57. package/bundle/standalone/apps/web/.next/server/app/api/docker-config/route.js +1 -1
  58. package/bundle/standalone/apps/web/.next/server/app/api/docker-config/route_client-reference-manifest.js +1 -1
  59. package/bundle/standalone/apps/web/.next/server/app/api/export/zip/route.js +1 -1
  60. package/bundle/standalone/apps/web/.next/server/app/api/export/zip/route_client-reference-manifest.js +1 -1
  61. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/backlinks/route.js +1 -1
  62. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/backlinks/route_client-reference-manifest.js +1 -1
  63. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/download/route.js +1 -1
  64. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/download/route_client-reference-manifest.js +1 -1
  65. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/export-html/route.js +1 -1
  66. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/export-html/route_client-reference-manifest.js +1 -1
  67. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/export-pdf/route.js +1 -1
  68. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/export-pdf/route_client-reference-manifest.js +1 -1
  69. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/history/restore/route.js +1 -1
  70. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/history/restore/route_client-reference-manifest.js +1 -1
  71. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/history/route.js +1 -1
  72. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/history/route_client-reference-manifest.js +1 -1
  73. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/move/route.js +1 -1
  74. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/move/route_client-reference-manifest.js +1 -1
  75. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/route.js +1 -1
  76. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/route_client-reference-manifest.js +1 -1
  77. package/bundle/standalone/apps/web/.next/server/app/api/files/route.js +1 -1
  78. package/bundle/standalone/apps/web/.next/server/app/api/files/route_client-reference-manifest.js +1 -1
  79. package/bundle/standalone/apps/web/.next/server/app/api/files/upload/route.js +1 -1
  80. package/bundle/standalone/apps/web/.next/server/app/api/files/upload/route_client-reference-manifest.js +1 -1
  81. package/bundle/standalone/apps/web/.next/server/app/api/folders/route.js +1 -1
  82. package/bundle/standalone/apps/web/.next/server/app/api/folders/route_client-reference-manifest.js +1 -1
  83. package/bundle/standalone/apps/web/.next/server/app/api/graph/route.js +7 -3
  84. package/bundle/standalone/apps/web/.next/server/app/api/graph/route_client-reference-manifest.js +1 -1
  85. package/bundle/standalone/apps/web/.next/server/app/api/hands/test-pattern/route_client-reference-manifest.js +1 -1
  86. package/bundle/standalone/apps/web/.next/server/app/api/hands/validate/route_client-reference-manifest.js +1 -1
  87. package/bundle/standalone/apps/web/.next/server/app/api/health/route.js +1 -1
  88. package/bundle/standalone/apps/web/.next/server/app/api/health/route_client-reference-manifest.js +1 -1
  89. package/bundle/standalone/apps/web/.next/server/app/api/hygiene/resolve/route.js +1 -1
  90. package/bundle/standalone/apps/web/.next/server/app/api/hygiene/resolve/route_client-reference-manifest.js +1 -1
  91. package/bundle/standalone/apps/web/.next/server/app/api/hygiene/route.js +1 -1
  92. package/bundle/standalone/apps/web/.next/server/app/api/hygiene/route_client-reference-manifest.js +1 -1
  93. package/bundle/standalone/apps/web/.next/server/app/api/install-snippets/route.js +1 -1
  94. package/bundle/standalone/apps/web/.next/server/app/api/install-snippets/route_client-reference-manifest.js +1 -1
  95. package/bundle/standalone/apps/web/.next/server/app/api/mcp-tools/route.js +1 -1
  96. package/bundle/standalone/apps/web/.next/server/app/api/mcp-tools/route_client-reference-manifest.js +1 -1
  97. package/bundle/standalone/apps/web/.next/server/app/api/profile/route_client-reference-manifest.js +1 -1
  98. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/hands-config/route.js +1 -1
  99. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/hands-config/route_client-reference-manifest.js +1 -1
  100. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/journal-config/route.js +1 -1
  101. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/journal-config/route_client-reference-manifest.js +1 -1
  102. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/journal-status/route.js +1 -1
  103. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/journal-status/route_client-reference-manifest.js +1 -1
  104. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/onboard/route.js +1 -1
  105. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/onboard/route_client-reference-manifest.js +1 -1
  106. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/refresh/route.js +1 -1
  107. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/refresh/route_client-reference-manifest.js +1 -1
  108. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/route.js +1 -1
  109. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/route_client-reference-manifest.js +1 -1
  110. package/bundle/standalone/apps/web/.next/server/app/api/projects/onboard/route.js +1 -1
  111. package/bundle/standalone/apps/web/.next/server/app/api/projects/onboard/route_client-reference-manifest.js +1 -1
  112. package/bundle/standalone/apps/web/.next/server/app/api/projects/route.js +1 -1
  113. package/bundle/standalone/apps/web/.next/server/app/api/projects/route_client-reference-manifest.js +1 -1
  114. package/bundle/standalone/apps/web/.next/server/app/api/publish/html/route_client-reference-manifest.js +1 -1
  115. package/bundle/standalone/apps/web/.next/server/app/api/publish/route_client-reference-manifest.js +1 -1
  116. package/bundle/standalone/apps/web/.next/server/app/api/refresh/route.js +1 -1
  117. package/bundle/standalone/apps/web/.next/server/app/api/refresh/route_client-reference-manifest.js +1 -1
  118. package/bundle/standalone/apps/web/.next/server/app/api/reindex/route.js +1 -1
  119. package/bundle/standalone/apps/web/.next/server/app/api/reindex/route_client-reference-manifest.js +1 -1
  120. package/bundle/standalone/apps/web/.next/server/app/api/reports/resources/[name]/route.js +1 -1
  121. package/bundle/standalone/apps/web/.next/server/app/api/reports/resources/[name]/route_client-reference-manifest.js +1 -1
  122. package/bundle/standalone/apps/web/.next/server/app/api/search/route.js +1 -1
  123. package/bundle/standalone/apps/web/.next/server/app/api/search/route_client-reference-manifest.js +1 -1
  124. package/bundle/standalone/apps/web/.next/server/app/api/tags/route.js +1 -1
  125. package/bundle/standalone/apps/web/.next/server/app/api/tags/route_client-reference-manifest.js +1 -1
  126. package/bundle/standalone/apps/web/.next/server/app/api/version-check/route_client-reference-manifest.js +1 -1
  127. package/bundle/standalone/apps/web/.next/server/app/api/welcome/route_client-reference-manifest.js +1 -1
  128. package/bundle/standalone/apps/web/.next/server/app/api/ws-config/route_client-reference-manifest.js +1 -1
  129. package/bundle/standalone/apps/web/.next/server/app/brain/page_client-reference-manifest.js +1 -1
  130. package/bundle/standalone/apps/web/.next/server/app/calendar/page_client-reference-manifest.js +1 -1
  131. package/bundle/standalone/apps/web/.next/server/app/conflicts/page_client-reference-manifest.js +1 -1
  132. package/bundle/standalone/apps/web/.next/server/app/graph/page.js +1 -1
  133. package/bundle/standalone/apps/web/.next/server/app/graph/page_client-reference-manifest.js +1 -1
  134. package/bundle/standalone/apps/web/.next/server/app/hygiene/page.js +6 -6
  135. package/bundle/standalone/apps/web/.next/server/app/hygiene/page_client-reference-manifest.js +1 -1
  136. package/bundle/standalone/apps/web/.next/server/app/login/page.js +1 -1
  137. package/bundle/standalone/apps/web/.next/server/app/login/page_client-reference-manifest.js +1 -1
  138. package/bundle/standalone/apps/web/.next/server/app/page.js +5 -5
  139. package/bundle/standalone/apps/web/.next/server/app/page.js.nft.json +1 -1
  140. package/bundle/standalone/apps/web/.next/server/app/page_client-reference-manifest.js +1 -1
  141. package/bundle/standalone/apps/web/.next/server/app/preview/motifs/page_client-reference-manifest.js +1 -1
  142. package/bundle/standalone/apps/web/.next/server/app/preview/motifs.html +2 -2
  143. package/bundle/standalone/apps/web/.next/server/app/preview/motifs.rsc +2 -2
  144. package/bundle/standalone/apps/web/.next/server/app-paths-manifest.json +10 -10
  145. package/bundle/standalone/apps/web/.next/server/chunks/2302.js +1 -0
  146. package/bundle/standalone/apps/web/.next/server/chunks/5998.js +1 -0
  147. package/bundle/standalone/apps/web/.next/server/chunks/6409.js +1 -0
  148. package/bundle/standalone/apps/web/.next/server/chunks/7775.js +1 -0
  149. package/bundle/standalone/apps/web/.next/server/chunks/7887.js +1 -1
  150. package/bundle/standalone/apps/web/.next/server/chunks/8571.js +1 -0
  151. package/bundle/standalone/apps/web/.next/server/middleware-build-manifest.js +1 -1
  152. package/bundle/standalone/apps/web/.next/server/middleware-react-loadable-manifest.js +1 -1
  153. package/bundle/standalone/apps/web/.next/server/pages/404.html +1 -1
  154. package/bundle/standalone/apps/web/.next/server/pages/500.html +1 -1
  155. package/bundle/standalone/apps/web/.next/server/server-reference-manifest.json +1 -1
  156. package/bundle/standalone/apps/web/.next/static/chunks/1108.60fb822c3e3fdaf3.js +1 -0
  157. package/bundle/standalone/apps/web/.next/static/chunks/2205.68bae400481d0a3a.js +1 -0
  158. package/bundle/standalone/apps/web/.next/static/chunks/2443.9d9dd31cc33fc741.js +1 -0
  159. package/bundle/standalone/apps/web/.next/static/chunks/245.3ed04e1f16f90b31.js +1 -0
  160. package/bundle/standalone/apps/web/.next/static/chunks/2966.2216b92e18a0bb66.js +1 -0
  161. package/bundle/standalone/apps/web/.next/static/chunks/3259.585f965f16cd7406.js +1 -0
  162. package/bundle/standalone/apps/web/.next/static/chunks/3518.5a080b5b9172e9ab.js +1 -0
  163. package/bundle/standalone/apps/web/.next/static/chunks/{2704-e7fd9aeb7f653736.js → 3617-ed93ee6af5ece2f3.js} +1 -1
  164. package/bundle/standalone/apps/web/.next/static/chunks/3685.1e1d7cc834bf67db.js +1 -0
  165. package/bundle/standalone/apps/web/.next/static/chunks/3987.07ce2f3afff6c9a1.js +1 -0
  166. package/bundle/standalone/apps/web/.next/static/chunks/4283.524bc904dbdd2417.js +1 -0
  167. package/bundle/standalone/apps/web/.next/static/chunks/5858.cff8810734332b7e.js +1 -0
  168. package/bundle/standalone/apps/web/.next/static/chunks/807.5bf32ba308aae89a.js +1 -0
  169. package/bundle/standalone/apps/web/.next/static/chunks/8693.7e10450df289d6a0.js +1 -0
  170. package/bundle/standalone/apps/web/.next/static/chunks/9699.8e15c2b743d792a3.js +1 -0
  171. package/bundle/standalone/apps/web/.next/static/chunks/app/graph/page-df6cef9d4646adff.js +1 -0
  172. package/bundle/standalone/apps/web/.next/static/chunks/app/hygiene/page-ae4a438701ce8b97.js +1 -0
  173. package/bundle/standalone/apps/web/.next/static/chunks/app/page-88470b8cd166cf75.js +1 -0
  174. package/bundle/standalone/apps/web/.next/static/chunks/webpack-357e2269171845c0.js +1 -0
  175. package/bundle/standalone/apps/web/.next/static/css/def7c93f9fc92d12.css +3 -0
  176. package/bundle/standalone/apps/web/package.json +4 -12
  177. package/bundle/standalone/apps/web/src/lib/mcp-tools.json +2 -2
  178. package/bundle/standalone/node_modules/kontexta-mcp/dist/index.js +1 -1
  179. package/bundle/standalone/node_modules/kontexta-mcp/dist/index.js.map +1 -1
  180. package/bundle/standalone/node_modules/kontexta-mcp/package.json +1 -1
  181. package/bundle/standalone/node_modules/kxta-core/dist/db/index.d.ts.map +1 -1
  182. package/bundle/standalone/node_modules/kxta-core/dist/db/index.js +3 -0
  183. package/bundle/standalone/node_modules/kxta-core/dist/db/index.js.map +1 -1
  184. package/bundle/standalone/node_modules/kxta-core/dist/files/index.d.ts +1 -0
  185. package/bundle/standalone/node_modules/kxta-core/dist/files/index.d.ts.map +1 -1
  186. package/bundle/standalone/node_modules/kxta-core/dist/files/index.js +12 -2
  187. package/bundle/standalone/node_modules/kxta-core/dist/files/index.js.map +1 -1
  188. package/bundle/standalone/node_modules/kxta-core/dist/index.d.ts +2 -2
  189. package/bundle/standalone/node_modules/kxta-core/dist/index.d.ts.map +1 -1
  190. package/bundle/standalone/node_modules/kxta-core/dist/index.js +2 -2
  191. package/bundle/standalone/node_modules/kxta-core/dist/index.js.map +1 -1
  192. package/bundle/standalone/node_modules/kxta-core/dist/retrieval/hybrid.d.ts.map +1 -1
  193. package/bundle/standalone/node_modules/kxta-core/dist/retrieval/hybrid.js +76 -18
  194. package/bundle/standalone/node_modules/kxta-core/dist/retrieval/hybrid.js.map +1 -1
  195. package/bundle/standalone/node_modules/kxta-core/dist/retrieval/hygiene.d.ts +8 -0
  196. package/bundle/standalone/node_modules/kxta-core/dist/retrieval/hygiene.d.ts.map +1 -1
  197. package/bundle/standalone/node_modules/kxta-core/dist/retrieval/hygiene.js +40 -3
  198. package/bundle/standalone/node_modules/kxta-core/dist/retrieval/hygiene.js.map +1 -1
  199. package/bundle/standalone/node_modules/kxta-core/dist/retrieval/index.d.ts +1 -1
  200. package/bundle/standalone/node_modules/kxta-core/dist/retrieval/index.d.ts.map +1 -1
  201. package/bundle/standalone/node_modules/kxta-core/dist/retrieval/index.js.map +1 -1
  202. package/bundle/standalone/node_modules/kxta-core/dist/types.d.ts +6 -0
  203. package/bundle/standalone/node_modules/kxta-core/dist/types.d.ts.map +1 -1
  204. package/bundle/standalone/node_modules/kxta-core/package.json +1 -1
  205. package/bundle/standalone/node_modules/kxta-publish/package.json +2 -2
  206. package/bundle/standalone/package.json +1 -1
  207. package/package.json +1 -9
  208. package/bundle/standalone/apps/web/.next/static/chunks/app/graph/page-5d0a8bd3e169157d.js +0 -1
  209. package/bundle/standalone/apps/web/.next/static/chunks/app/hygiene/page-9eeba0198c64ada1.js +0 -1
  210. package/bundle/standalone/apps/web/.next/static/chunks/app/page-ba7c52071b1f0d30.js +0 -1
  211. package/bundle/standalone/apps/web/.next/static/chunks/webpack-b1697c3befeaf792.js +0 -1
  212. package/bundle/standalone/apps/web/.next/static/css/86c76614a890326f.css +0 -3
  213. /package/bundle/standalone/apps/web/.next/static/{oxgEqVUQDtvOMFMm42Vl2 → idjbcSJE8hK49A4CJHc8Z}/_buildManifest.js +0 -0
  214. /package/bundle/standalone/apps/web/.next/static/{oxgEqVUQDtvOMFMm42Vl2 → idjbcSJE8hK49A4CJHc8Z}/_ssgManifest.js +0 -0
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{6519:(e,t,a)=>{"use strict";a.d(t,{q:()=>i});var r=a(14915),n=a(65347),l=a(89872);let s=0;function o(e){if("undefined"!=typeof document){for(let t of[e,"d".concat(e),"i".concat(e),"dom-".concat(e)]){let e=document.getElementById(t);e&&e.remove()}try{document.querySelectorAll('[id="'.concat(e,'"], [id^="d').concat(e,'"], [id^="i').concat(e,'"], [id^="dom-').concat(e,'"]')).forEach(e=>e.remove())}catch(e){}}}function i(e){var t,i;let{source:c,className:d,filename:u}=e,x=(0,n.useRef)(null),[h,m]=(0,n.useState)(null),[p,f]=(0,n.useState)(null),{resolvedTheme:b}=(0,l.D)();(0,n.useEffect)(()=>{let e=!1,t=(s+=1,"mermaid-".concat(Date.now(),"-").concat(s));return m(null),f(null),(async()=>{try{let r=(await Promise.all([a.e(1805),a.e(7050),a.e(5514)]).then(a.bind(a,61081))).default;r.initialize({startOnLoad:!1,theme:"light"===b?"default":"dark",securityLevel:"strict"});let{svg:n}=await r.render(t,c);e||f(n),o(t)}catch(a){o(t),e||(m(a instanceof Error?a.message:String(a)),f(null))}})(),()=>{e=!0,o(t)}},[c,b]);let v=u&&(null!=(i=null==(t=u.split(/[\\/]/).pop())?void 0:t.trim())?i:"").replace(/\.(mmd|md|markdown)$/i,"").trim()||"diagram",g=e=>{let t=new DOMParser().parseFromString(e,"image/svg+xml");if(t.getElementsByTagName("parsererror").length>0){let t=document.createElement("div");return t.innerHTML=e,t.querySelector("svg")}return"svg"===t.documentElement.tagName.toLowerCase()?t.documentElement:null},j=!!p&&!h;return(0,r.jsxs)("div",{className:d,children:[j&&(0,r.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,r.jsx)("button",{type:"button",onClick:()=>{if(!p)return;let e=g(p);if(!e)return void m("SVG export failed: could not parse rendered SVG");e.setAttribute("xmlns","http://www.w3.org/2000/svg"),e.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink");let t=new XMLSerializer().serializeToString(e),a=new Blob([t.startsWith("<?xml")?t:'<?xml version="1.0" encoding="UTF-8"?>\n'.concat(t)],{type:"image/svg+xml;charset=utf-8"}),r=URL.createObjectURL(a),n=document.createElement("a");n.href=r,n.download="".concat(v,".svg"),document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(r)},className:"btn btn-sm","aria-label":"Export diagram as SVG",title:"Export as SVG",children:"SVG"}),(0,r.jsx)("button",{type:"button",onClick:()=>{var e,t;if(!p)return;let a=null==(e=x.current)?void 0:e.querySelector("svg"),r=null!=a?a:g(p);if(!r)return void m("PNG export failed: could not parse rendered SVG");let n=800,l=600,s=null==(t=r.viewBox)?void 0:t.baseVal;if(s&&s.width>0&&s.height>0)n=s.width,l=s.height;else if(a)try{let e=a.getBBox();e.width>0&&e.height>0&&(n=e.width,l=e.height)}catch(e){}let o=r.cloneNode(!0);o.setAttribute("xmlns","http://www.w3.org/2000/svg"),o.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink"),o.setAttribute("width",String(n)),o.setAttribute("height",String(l));let i=new XMLSerializer().serializeToString(o),c=new TextEncoder().encode(i),d="";for(let e=0;e<c.length;e++)d+=String.fromCharCode(c[e]);let u="data:image/svg+xml;base64,".concat(btoa(d)),h=document.createElement("canvas");h.width=Math.max(1,Math.round(2*n)),h.height=Math.max(1,Math.round(2*l));let f=h.getContext("2d");if(!f)return void m("PNG export failed: 2D canvas context unavailable");let j=new Image;j.onload=()=>{f.fillStyle="light"===b?"#ffffff":"#1f2937",f.fillRect(0,0,h.width,h.height),f.drawImage(j,0,0,h.width,h.height);try{h.toBlob(e=>{if(!e)return void m("PNG export failed: canvas returned empty blob");let t=URL.createObjectURL(e),a=document.createElement("a");a.href=t,a.download="".concat(v,".png"),document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(t)},"image/png")}catch(t){let e=t instanceof Error?t.message:String(t);m("PNG export failed: ".concat(e))}},j.onerror=()=>{m("PNG export failed: SVG could not be loaded as an image (it may reference external resources or unsupported features)")},j.src=u},className:"btn btn-sm","aria-label":"Export diagram as PNG",title:"Export as PNG (2x)",children:"PNG"})]}),h&&(0,r.jsxs)("pre",{className:"text-[var(--danger)] whitespace-pre-wrap mb-2 text-sm",children:["Mermaid render error: ",h]}),(0,r.jsx)("div",{ref:x,dangerouslySetInnerHTML:p?{__html:p}:void 0}),h&&(0,r.jsx)("pre",{className:"mt-2 p-3 bg-zinc-900 text-zinc-100 text-xs overflow-x-auto",children:c})]})}},7395:(e,t,a)=>{"use strict";a.d(t,{H:()=>l});var r=a(14915);let n={sm:{lightSrc:"/logo.png",darkSrc:"/logo-dark.png",imgClass:"h-[56px] w-auto",floatClass:"",particles:[],orbitRadius:0},lg:{lightSrc:"/logo.png",darkSrc:"/logo-dark.png",imgClass:"h-[150px] w-auto",floatClass:"animate-[logo-float-lg_3s_ease-in-out_infinite]",particles:[{size:6,color:"#C2410C",opacity:.75,duration:5,reverse:!1,delay:0},{size:4,color:"#D4A050",opacity:.55,duration:7,reverse:!0,delay:-3},{size:3,color:"#FFD49A",opacity:.45,duration:9,reverse:!1,delay:-5}],orbitRadius:70}};function l(e){let{size:t}=e,{lightSrc:a,darkSrc:l,imgClass:s,floatClass:o,particles:i,orbitRadius:c}=n[t];return(0,r.jsxs)("div",{className:"relative inline-flex flex-shrink-0 overflow-visible",children:[(0,r.jsx)("img",{src:a,alt:"Kontexta",className:"block dark:hidden ".concat(s," object-contain ").concat(o)}),(0,r.jsx)("img",{src:l,alt:"Kontexta",className:"hidden dark:block ".concat(s," object-contain ").concat(o)}),i.map((e,t)=>(0,r.jsx)("span",{className:"absolute rounded-full bp-keep-round pointer-events-none",style:{width:e.size,height:e.size,backgroundColor:e.color,opacity:e.opacity,top:"calc(50% - ".concat(c,"px)"),left:"calc(50% - ".concat(e.size/2,"px)"),transformOrigin:"".concat(e.size/2,"px ").concat(c,"px"),animation:"logo-orbit ".concat(e.duration,"s linear infinite").concat(e.reverse?" reverse":""),animationDelay:"".concat(e.delay,"s")}},t))]})}},17695:(e,t,a)=>{"use strict";a.d(t,{T:()=>l});var r=a(14915),n=a(56570);function l(e){let{open:t,onClose:a,onConfirm:l,title:s,message:o,confirmLabel:i="Confirm",cancelLabel:c="Cancel",destructive:d=!1,loading:u=!1}=e;return(0,r.jsxs)(n.l,{open:t,onClose:a,title:s,children:[(0,r.jsx)("div",{className:"text-sm text-[var(--text-secondary)]",children:o}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 mt-5",children:[(0,r.jsx)("button",{type:"button",className:"btn btn-md",onClick:a,disabled:u,children:c}),(0,r.jsx)("button",{type:"button",className:"btn btn-md ".concat(d?"btn-destructive":"btn-primary"),onClick:l,disabled:u,children:u?"…":i})]})]})}},29881:(e,t,a)=>{"use strict";a.d(t,{p:()=>n});var r=a(14915);function n(e){let{icon:t,title:a,hint:n,action:l}=e;return(0,r.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 px-6 text-center gap-2",children:[t&&(0,r.jsx)("div",{className:"text-[var(--muted)] opacity-60 mb-1",children:t}),(0,r.jsx)("p",{className:"text-sm font-medium text-[var(--text-primary)]",children:a}),n&&(0,r.jsx)("p",{className:"text-xs text-[var(--text-secondary)]",children:n}),l&&(0,r.jsx)("div",{className:"mt-3",children:l})]})}},33039:(e,t,a)=>{"use strict";a.d(t,{default:()=>ti});var r=a(14915),n=a(65347),l=a(4341),s=a(30300),o=a(97935),i=a(51205),c=a(77843),d=a(22377),u=a(89872),x=a(79358),h=a(73382),m=a(32577),p=a(54810),f=a(51569),b=a(31131),v=a(49292),g=a(51815),j=a(62376),y=a(85972),w=a(49129),N=a(39624),k=a(81339),S=a.n(k),C=a(7395),T=a(94567);function A(e){let{trigger:t,items:a,align:n="end"}=e;return(0,r.jsxs)(T.bL,{children:[(0,r.jsx)(T.l9,{asChild:!0,children:t}),(0,r.jsx)(T.ZL,{children:(0,r.jsx)(T.UC,{align:n,sideOffset:6,className:"z-[var(--z-dropdown)]",children:(0,r.jsx)("div",{className:"min-w-[180px] rounded-md border border-[var(--border)] bg-[var(--bg-primary)] py-1.5 shadow-xl animate-scale-in",children:a.map(e=>(0,r.jsxs)(T.q7,{onSelect:e.onSelect,className:"flex w-full cursor-pointer items-center gap-2 px-3 py-2 text-left text-xs font-medium outline-none transition-colors data-[highlighted]:bg-[var(--accent)] data-[highlighted]:text-white ".concat(e.destructive?"text-[var(--danger)]":"text-[var(--text-secondary)]"),children:[e.icon,e.label]},e.label))})})})]})}function _(e){let{onSearch:t,onAbout:a,onConfigure:l,onPublish:o,onViewPublished:i,unresolvedConflicts:c}=e,k=(0,s.useRouter)(),{theme:T,setTheme:_}=(0,u.D)(),[E,P]=(0,n.useState)(!1),[F,L]=(0,n.useState)(!1),[R,M]=(0,n.useState)(!1),[D,I]=(0,n.useState)(null!=c?c:0);(0,n.useEffect)(()=>{if(void 0!==c)return void I(c);let e=!1,t=async()=>{try{let t=await fetch("/api/conflicts?count=1",{cache:"no-store"});if(t.ok){let a=await t.json();e||"number"!=typeof(null==a?void 0:a.count)||I(a.count)}}catch(e){}};t();let a=setInterval(()=>{"undefined"!=typeof document&&document.hidden||t()},15e3),r=()=>{t()};return window.addEventListener("kontexta:conflicts-changed",r),()=>{e=!0,clearInterval(a),window.removeEventListener("kontexta:conflicts-changed",r)}},[c]);let O=async()=>{var e,t,a,r,n,l;if(!R){M(!0);try{let l=await fetch("/api/reindex",{method:"POST"}),s=await l.json().catch(()=>({}));if(l.ok&&(null==s?void 0:s.success)){let n=null!=(t=s.totals)?t:{newly_indexed:0,refreshed:0,pruned:0,errors:0};d.o.success("Reindexed ".concat(null!=(a=null==(e=s.scopes)?void 0:e.length)?a:0," scope(s) in ").concat(null!=(r=s.duration_ms)?r:"?","ms - ")+"+".concat(n.newly_indexed," new, ").concat(n.refreshed," updated, ").concat(n.pruned," removed")+(n.errors?", ".concat(n.errors," scope error(s)"):""))}else 409===l.status?d.o.error("Reindex already in progress"):d.o.error("Reindex failed: ".concat(null!=(n=null==s?void 0:s.error)?n:"HTTP ".concat(l.status)))}catch(e){d.o.error("Reindex failed: ".concat(null!=(l=null==e?void 0:e.message)?l:"Network error"))}finally{M(!1)}}};(0,n.useEffect)(()=>{P(!0),L(navigator.platform.toUpperCase().indexOf("MAC")>=0)},[]);let U=F?"⌘":"Ctrl";return(0,r.jsxs)("header",{className:"sticky top-0 z-50 h-16 bg-[var(--bg-secondary)]/80 backdrop-blur-xl flex flex-nowrap items-center px-4 sm:px-6 border-b border-[var(--border)] gap-2 sm:gap-3 overflow-hidden transition-all",children:[(0,r.jsxs)("div",{className:"flex items-center gap-0 group cursor-pointer shrink-0",onClick:()=>k.push("/"),children:[(0,r.jsx)(C.H,{size:"sm"}),(0,r.jsx)("span",{className:"-ml-3 font-extrabold text-xl tracking-[4px] font-title text-[var(--text-primary)] drop-shadow-[0_0_15px_rgba(180,120,30,0.1)] dark:drop-shadow-[0_0_15px_rgba(180,120,30,0.3)] transition-all group-hover:drop-shadow-[0_0_20px_rgba(180,120,30,0.5)] whitespace-nowrap",children:"ONTEXTA"})]}),(0,r.jsx)("div",{className:"flex-1 min-w-[36px] sm:min-w-[140px] flex justify-center px-1 sm:px-4",children:(0,r.jsxs)("button",{onClick:t,className:"w-full max-w-[440px] h-10 px-2 sm:px-4 bg-[var(--bg-tertiary)]/50 text-[13px] text-[var(--text-secondary)] rounded-xl hover:bg-[var(--bg-secondary)] transition-all flex items-center justify-center sm:justify-start gap-2 sm:gap-3 border border-[var(--border)] group focus-glow whitespace-nowrap overflow-hidden shrink","aria-label":"Search context",title:"Search context (".concat(U,"K)"),children:[(0,r.jsxs)("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"w-4 h-4 opacity-50 group-hover:opacity-100 transition-opacity shrink-0",children:[(0,r.jsx)("circle",{cx:"11",cy:"11",r:"7"}),(0,r.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),(0,r.jsx)("span",{className:"hidden sm:inline flex-1 text-left opacity-60 group-hover:opacity-100 truncate",children:"Search context..."}),(0,r.jsxs)("kbd",{className:"hidden md:inline-block text-[10px] font-mono text-[var(--text-secondary)] bg-[var(--bg-secondary)] px-2 py-1 rounded-md border border-[var(--border)] shadow-sm opacity-50 shrink-0",children:[U,"K"]})]})}),(0,r.jsxs)("div",{className:"flex items-center gap-1.5 sm:gap-2 shrink-0 flex-nowrap",children:[D>0&&(0,r.jsxs)(S(),{href:"/conflicts",onClick:e=>{e.preventDefault();try{k.push("/conflicts")}catch(e){}},className:"btn btn-sm sm:btn-md !font-mono font-bold uppercase tracking-wider text-amber-accent bg-amber-accent/10 hover:bg-amber-accent/20 border border-amber-accent/30 bp-toolbar-btn whitespace-nowrap shrink-0 inline-flex items-center gap-1.5 transition-all","aria-label":"".concat(D," unresolved conflict").concat(1===D?"":"s"),title:"".concat(D," unresolved conflict").concat(1===D?"":"s"),"data-testid":"unresolved-conflicts-badge",children:[(0,r.jsx)(x.A,{className:"w-3.5 h-3.5 text-amber-accent shrink-0","aria-hidden":!0}),(0,r.jsx)("span",{children:"Conflicts"}),(0,r.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] rounded-full bg-amber-accent text-black font-extrabold leading-none",children:D})]}),(0,r.jsx)("button",{onClick:()=>k.push("/graph"),className:"hidden md:inline-flex btn btn-sm sm:btn-md !font-mono font-bold uppercase tracking-wider text-[var(--accent)] bp-toolbar-btn whitespace-nowrap shrink-0","aria-label":"Open Knowledge Graph",title:"Open Knowledge Graph",children:"Graph"}),(0,r.jsx)("button",{onClick:()=>k.push("/hygiene"),className:"hidden md:inline-flex btn btn-sm sm:btn-md !font-mono font-bold uppercase tracking-wider text-[var(--accent)] bp-toolbar-btn whitespace-nowrap shrink-0","aria-label":"Open Knowledge Hygiene",title:"Open Knowledge Hygiene",children:"Hygiene"}),(0,r.jsx)("button",{onClick:()=>k.push("/calendar"),className:"hidden md:inline-flex btn btn-sm sm:btn-md !font-mono font-bold uppercase tracking-wider text-[var(--accent)] bp-toolbar-btn whitespace-nowrap shrink-0","aria-label":"Open Calendar",title:"Open Calendar",children:"Calendar"}),(0,r.jsx)("button",{onClick:O,disabled:R,className:"hidden md:inline-flex btn btn-sm sm:btn-md !font-mono font-bold uppercase tracking-wider text-[var(--accent)] bp-toolbar-btn whitespace-nowrap shrink-0 ".concat(R?"opacity-50":""),"aria-label":"Reindex - scan disk to add new files and remove orphan rows",title:"Reindex Knowledge Base + all projects: add new files and drop orphan rows",children:R?"Reindexing…":"Reindex"}),(0,r.jsx)("button",{onClick:l,className:"hidden md:inline-flex btn btn-sm sm:btn-md !font-mono font-bold uppercase tracking-wider text-[var(--accent)] bp-toolbar-btn whitespace-nowrap shrink-0","aria-label":"Configure Kontexta",children:"Configure"}),(0,r.jsx)("button",{onClick:a,className:"hidden md:inline-flex btn btn-sm sm:btn-md !font-mono font-bold uppercase tracking-wider text-[var(--accent)] bp-toolbar-btn whitespace-nowrap shrink-0","aria-label":"About Kontexta",children:"About"}),(0,r.jsx)("div",{className:"hidden md:block",children:(0,r.jsx)(A,{trigger:(0,r.jsx)("button",{className:"btn btn-sm sm:btn-md !font-mono font-bold uppercase tracking-wider text-[var(--accent)] bp-toolbar-btn whitespace-nowrap shrink-0","aria-label":"Publish menu",title:"Publish documentation",children:"Publish\xa0▾"}),items:[{label:"New Publish",onSelect:o,icon:(0,r.jsxs)("svg",{className:"w-4 h-4 text-[var(--accent)]",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,r.jsx)("path",{d:"M4 4h16v16H4z"}),(0,r.jsx)("path",{d:"M12 8v8M8 12h8"})]})},{label:"View Published",onSelect:i,icon:(0,r.jsxs)("svg",{className:"w-4 h-4 text-[var(--accent)]",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,r.jsx)("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),(0,r.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})}]})}),(0,r.jsx)("div",{className:"md:hidden",children:(0,r.jsx)(A,{trigger:(0,r.jsx)("button",{type:"button",className:"p-2 rounded-md text-[var(--accent)] hover:bg-[var(--bg-tertiary)] transition-colors shrink-0","aria-label":"Open navigation menu",title:"Menu",children:(0,r.jsx)(h.A,{className:"w-4 h-4","aria-hidden":!0})}),items:[{label:"Graph",onSelect:()=>k.push("/graph"),icon:(0,r.jsx)(m.A,{className:"w-4 h-4 text-[var(--accent)]","aria-hidden":!0})},{label:"Hygiene",onSelect:()=>k.push("/hygiene"),icon:(0,r.jsx)(p.A,{className:"w-4 h-4 text-[var(--accent)]","aria-hidden":!0})},{label:"Calendar",onSelect:()=>k.push("/calendar"),icon:(0,r.jsx)(f.A,{className:"w-4 h-4 text-[var(--accent)]","aria-hidden":!0})},{label:R?"Reindexing…":"Reindex",onSelect:O,icon:(0,r.jsx)(b.A,{className:"w-4 h-4 text-[var(--accent)]","aria-hidden":!0})},{label:"Configure",onSelect:l,icon:(0,r.jsx)(v.A,{className:"w-4 h-4 text-[var(--accent)]","aria-hidden":!0})},{label:"About",onSelect:a,icon:(0,r.jsx)(g.A,{className:"w-4 h-4 text-[var(--accent)]","aria-hidden":!0})},{label:"New Publish",onSelect:o,icon:(0,r.jsx)(j.A,{className:"w-4 h-4 text-[var(--accent)]","aria-hidden":!0})},{label:"View Published",onSelect:i,icon:(0,r.jsx)(y.A,{className:"w-4 h-4 text-[var(--accent)]","aria-hidden":!0})}]})}),(0,r.jsx)("button",{onClick:async()=>{await fetch("/api/auth/logout",{method:"POST"}),k.push("/login")},className:"p-2 rounded-md text-[var(--text-secondary)] hover:text-[var(--danger)] hover:bg-[var(--bg-tertiary)] transition-colors shrink-0","aria-label":"Lock Kontexta",title:"Lock Kontexta",children:(0,r.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[(0,r.jsx)("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}),(0,r.jsxs)("span",{className:"hidden md:inline bp-title-block bp-annotation whitespace-nowrap shrink-0",children:["REV ","7.4.3"]}),E&&(0,r.jsxs)("button",{onClick:()=>_("light"===T?"dark":"light"),className:"px-2 h-5 rounded-md border border-[var(--border)] font-mono text-[10px] uppercase tracking-wider text-[var(--text-secondary)] hover:text-[var(--accent)] hover:border-[var(--accent)] transition-colors inline-flex items-center gap-1 whitespace-nowrap shrink-0","aria-label":"Toggle theme (light / dark)",title:"Theme: ".concat(T," - click to toggle"),children:["light"===T?(0,r.jsx)(w.A,{className:"w-3 h-3","aria-hidden":!0}):(0,r.jsx)(N.A,{className:"w-3 h-3","aria-hidden":!0}),"light"===T?"light":"dark"]})]})]})}function E(e){let[t,a]=(0,n.useState)(()=>window.matchMedia(e).matches);return(0,n.useEffect)(()=>{let t=window.matchMedia(e);a(t.matches);let r=e=>a(e.matches);return t.addEventListener("change",r),()=>t.removeEventListener("change",r)},[e]),t}let P="kontexta:pane-widths:v1";function F(e){let{left:t,leftRail:a,middle:l,right:s,isPhone:o=!1,mobileTab:i="files"}=e,[c,d]=(0,n.useState)(240),[u,x]=(0,n.useState)(320),[h,m]=(0,n.useState)(!1),p=E("(max-width: 1023px)");(0,n.useEffect)(()=>{try{let e=localStorage.getItem(P);if(e){let t=JSON.parse(e);"number"==typeof t.left&&d(L(t.left,180,360)),"number"==typeof t.middle&&x(L(t.middle,260,600))}}catch(e){}m(!0)},[]),(0,n.useEffect)(()=>{if(h)try{localStorage.setItem(P,JSON.stringify({left:c,middle:u}))}catch(e){}},[h,c,u]);let f=(0,n.useRef)(null),b=(0,n.useRef)(0),v=(0,n.useRef)(0),g=e=>t=>{f.current=e,b.current=t.clientX,v.current="left"===e?c:u,t.target.setPointerCapture(t.pointerId)},j=!o&&p&&!!a;return(0,r.jsxs)("div",{className:"flex flex-1 min-h-0",onPointerMove:e=>{if(!f.current)return;let t=e.clientX-b.current;"left"===f.current?d(L(v.current+t,180,360)):x(L(v.current+t,260,600))},onPointerUp:()=>{f.current=null},children:[j?a:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{style:o?void 0:{width:c},className:o?"browse"===i?"flex-1 w-full h-full overflow-y-auto bg-[var(--bg-primary)] scrollbar-thin":"hidden":"shrink-0 h-full overflow-y-auto bg-[var(--bg-primary)] border-r border-[var(--border)] scrollbar-thin",onScroll:e=>e.stopPropagation(),children:t}),!o&&(0,r.jsx)("div",{onPointerDown:g("left"),className:"w-1 cursor-col-resize bg-transparent hover:bg-[var(--accent)]/40 transition-colors z-10"})]}),(0,r.jsx)("div",{style:o?void 0:{width:u},className:o?"files"===i?"flex-1 w-full h-full overflow-y-auto bg-[var(--bg-primary)]":"hidden":"shrink-0 h-full overflow-y-auto bg-[var(--bg-primary)] border-r border-[var(--border)]",children:l}),!o&&(0,r.jsx)("div",{onPointerDown:g("middle"),className:"w-1 cursor-col-resize bg-transparent hover:bg-[var(--accent)]/40 transition-colors z-10"}),(0,r.jsx)("div",{className:o?"read"===i?"flex-1 min-w-0 bg-[var(--bg-primary)] overflow-y-auto flex flex-col":"hidden":"flex-1 min-w-0 bg-[var(--bg-secondary)] dark:bg-[var(--bg-primary)] p-3 lg:p-4 transition-all overflow-y-auto flex flex-col",children:(0,r.jsxs)("div",{className:o?"flex-1 min-w-0 overflow-auto relative":"flex-1 min-w-0 overflow-auto floating-surface rounded-2xl shadow-2xl relative",children:[!o&&(0,r.jsx)("div",{className:"absolute inset-0 pointer-events-none border border-amber-accent/10 rounded-2xl z-20"}),s]})})]})}function L(e,t,a){return Math.max(t,Math.min(a,e))}var R=a(98526),M=a(93756),D=a(15708),I=a(83097),O=a(54725),U=a(89191),H=a(29723),G=a(78707),z=a(6299),B=a(34683);function W(e){let{label:t,icon:a,active:l=!1,initialExpanded:s=!1,children:o,onClick:i,hasHands:c=!1,trailingAction:d}=e,[u,x]=(0,n.useState)(s),h=!!o;return(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{onClick:()=>{h&&x(!u),null==i||i()},className:"relative flex items-center gap-1.5 py-1.5 px-2 rounded-lg text-sm cursor-pointer transition-all duration-200 group ".concat(l?"bg-[var(--accent-soft)] text-[var(--text-primary)] font-semibold":"text-[var(--text-secondary)] hover:bg-[var(--accent-soft)] hover:text-[var(--text-primary)]"),children:[l&&(0,r.jsx)("span",{className:"absolute -left-1 top-1 bottom-1 w-0.5 bg-[var(--accent)] rounded-full bp-keep-round"}),h&&(0,r.jsx)(B.A,{className:"w-3 h-3 shrink-0 transition-transform duration-200 ".concat(u?"rotate-90":""),"aria-hidden":!0}),a&&(0,r.jsx)("span",{className:"dark-icon",children:a}),(0,r.jsx)("span",{className:"truncate lowercase first-letter:uppercase flex-1",children:t}),c&&(0,r.jsx)("span",{className:"ml-1 flex items-center justify-center text-[10px] text-[var(--accent)] opacity-70",title:"Hands enabled",children:(0,r.jsxs)("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"w-3 h-3",children:[(0,r.jsx)("path",{d:"M18 11V6a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v0"}),(0,r.jsx)("path",{d:"M14 10V4a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v0"}),(0,r.jsx)("path",{d:"M10 10.5V6a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v0"}),(0,r.jsx)("path",{d:"M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15"})]})}),d&&(0,r.jsx)("span",{className:"ml-auto flex items-center opacity-0 group-hover:opacity-100 transition-opacity",onClick:e=>e.stopPropagation(),children:d})]}),(0,r.jsx)("div",{className:"grid transition-all duration-300 ease-in-out ".concat(h&&u?"grid-rows-[1fr] opacity-100 mt-1":"grid-rows-[0fr] opacity-0"),children:(0,r.jsx)("div",{className:"overflow-hidden ml-3",children:o})})]})}let K=e=>e.replace(/\\/g,"/");function J(e,t){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],r=!(arguments.length>3)||void 0===arguments[3]||arguments[3],n={name:"",path:"",children:[],files:[]},l=K(t),s=l.endsWith("/")?l:l+"/";for(let t of e){var o;let e=K(t.path);if(!e.startsWith(s))continue;let a=e.slice(s.length).split("/");a.pop();let r=n,l="";for(let e of a){l=l?"".concat(l,"/").concat(e):e;let t=r.children.find(t=>t.name===e);t||(t={name:e,path:l,children:[],files:[]},r.children.push(t)),r=t}r.files.push({id:t.id,title:t.title,path:t.path,content_class:null!=(o=t.content_class)?o:null})}for(let e of a){let t=K(e).split("/"),a=n,r="";for(let e of t){r=r?"".concat(r,"/").concat(e):e;let t=a.children.find(t=>t.name===e);t||(t={name:e,path:r,children:[],files:[]},a.children.push(t)),a=t}}return r&&function e(t){return t.children=t.children.filter(t=>e(t)),t.files.length>0||t.children.length>0||!!t.isExplicit}(n),function e(t){for(let a of(t.children.sort((e,t)=>e.name.localeCompare(t.name)),t.files.sort((e,t)=>e.title.localeCompare(t.title)),t.children))e(a)}(n),n}var q=a(29881);let V={fill:"none",stroke:"currentColor",strokeWidth:2.5,strokeLinecap:"round",strokeLinejoin:"round"};function $(e){let{contentClass:t,className:a,title:n}=e,l=null!=a?a:"w-4 h-4",s=null!=n?n:null!=t?t:"file";switch(t){case"dictionary":return(0,r.jsxs)("svg",{viewBox:"0 0 24 24",...V,className:l,"aria-label":s,children:[(0,r.jsx)("path",{d:"M4 19.5A2.5 2.5 0 0 1 6.5 17H20"}),(0,r.jsx)("path",{d:"M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"})]});case"note":return(0,r.jsxs)("svg",{viewBox:"0 0 24 24",...V,className:l,"aria-label":s,children:[(0,r.jsx)("path",{d:"M14 3H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9l-6-6z"}),(0,r.jsx)("polyline",{points:"14 3 14 9 20 9"}),(0,r.jsx)("line",{x1:"8",y1:"13",x2:"16",y2:"13"}),(0,r.jsx)("line",{x1:"8",y1:"17",x2:"13",y2:"17"})]});case"journal":return(0,r.jsxs)("svg",{viewBox:"0 0 24 24",...V,className:l,"aria-label":s,children:[(0,r.jsx)("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"}),(0,r.jsx)("line",{x1:"16",y1:"2",x2:"16",y2:"6"}),(0,r.jsx)("line",{x1:"8",y1:"2",x2:"8",y2:"6"}),(0,r.jsx)("line",{x1:"3",y1:"10",x2:"21",y2:"10"})]});case"project":return(0,r.jsx)("svg",{viewBox:"0 0 24 24",...V,className:l,"aria-label":s,children:(0,r.jsx)("path",{d:"M3 7a2 2 0 0 1 2-2h5l2 2h7a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7z"})});default:return(0,r.jsxs)("svg",{viewBox:"0 0 24 24",...V,className:l,"aria-label":s,children:[(0,r.jsx)("path",{d:"M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"}),(0,r.jsx)("polyline",{points:"14 2 14 8 20 8"})]})}}let Y=e=>{let{className:t}=e;return(0,r.jsx)("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:(0,r.jsx)("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})},Z=[{name:"knowledge",label:"Knowledge",icon:e=>(0,r.jsx)(R.A,{...e})},{name:"mermaid",label:"Mermaid",icon:e=>(0,r.jsx)(M.A,{...e})},{name:"html",label:"HTML",icon:e=>(0,r.jsx)(D.A,{...e})},{name:"journal",label:"Journal",icon:e=>(0,r.jsx)(I.A,{...e})}],X=new Set(Z.map(e=>e.name));function Q(e){let{tags:t,selectedTag:a,onSelectTag:l}=e,[s,o]=(0,n.useState)(!1),[i,c]=(0,n.useState)(!1),[d,u]=(0,n.useState)(""),x=t.filter(e=>e.count>0);if(0===x.length)return null;let h=d.trim().toLowerCase(),m=h?x.filter(e=>e.name.toLowerCase().includes(h)):x,p=h||i?m:m.slice(0,10),f=m.length-p.length;return(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-2 pt-2 pb-1",children:[(0,r.jsxs)("button",{onClick:()=>o(e=>!e),className:"text-[12px] uppercase tracking-wider text-[var(--text-secondary)] hover:text-[var(--text-primary)] transition-colors inline-flex items-center gap-1","aria-label":"Toggle tags",children:[(0,r.jsx)(O.A,{className:"w-3 h-3 transition-transform ".concat(s?"":"-rotate-90"),"aria-hidden":!0}),"Tags",(0,r.jsxs)("span",{className:"normal-case tracking-normal text-[var(--text-secondary)]/70",children:["(",x.length,")"]})]}),a&&(0,r.jsx)("button",{onClick:()=>l(null),className:"text-[10px] uppercase tracking-wider text-[var(--text-secondary)] hover:text-[var(--accent)] transition-colors",title:"Clear tag filter",children:"Clear"})]}),s&&(0,r.jsxs)("div",{className:"space-y-0.5 mt-0.5",children:[(0,r.jsxs)("div",{className:"relative px-2 mb-1",children:[(0,r.jsx)(U.A,{className:"absolute left-4 top-1/2 -translate-y-1/2 w-3 h-3 text-[var(--text-secondary)]/60 pointer-events-none","aria-hidden":!0}),(0,r.jsx)("input",{type:"text",value:d,onChange:e=>u(e.target.value),placeholder:"Filter tags…",className:"w-full bg-[var(--bg-secondary)] border border-[var(--border)] rounded-md pl-6 pr-6 py-1 text-[12px] text-[var(--text-primary)] outline-none focus:border-[var(--accent)]/50","aria-label":"Filter tags"}),d&&(0,r.jsx)("button",{onClick:()=>u(""),className:"absolute right-3 top-1/2 -translate-y-1/2 text-[var(--text-secondary)] hover:text-[var(--accent)]","aria-label":"Clear tag filter",title:"Clear",children:(0,r.jsx)(H.A,{className:"w-3 h-3","aria-hidden":!0})})]}),0===m.length?(0,r.jsxs)("div",{className:"px-3 py-2 text-[11px] italic text-[var(--text-secondary)]",children:["No tags match “",d,"”."]}):p.map(e=>{let t=a===e.name;return(0,r.jsxs)("button",{onClick:()=>l(t?null:e.name),className:"w-full flex items-center gap-1.5 py-1 px-2 rounded-lg text-[13px] cursor-pointer transition-all group ".concat(t?"bg-[var(--accent-soft)] text-[var(--text-primary)] font-semibold":"text-[var(--text-secondary)] hover:bg-[var(--accent-soft)] hover:text-[var(--text-primary)]"),"aria-pressed":t,title:'Show files tagged "'.concat(e.name,'"'),children:[(0,r.jsx)(G.A,{className:"w-3 h-3 shrink-0 ".concat(t?"text-[var(--accent)]":"text-[var(--text-secondary)] group-hover:text-[var(--accent)]"),"aria-hidden":!0}),(0,r.jsx)("span",{className:"truncate flex-1 text-left lowercase first-letter:uppercase",children:e.name}),(0,r.jsx)("span",{className:"text-[10px] font-mono tabular-nums ".concat(t?"text-[var(--accent)]":"text-[var(--text-secondary)]/60"),children:e.count})]},e.id)}),!h&&f>0&&(0,r.jsxs)("button",{onClick:()=>c(!0),className:"w-full text-left px-2 py-1 text-[11px] text-[var(--text-secondary)] hover:text-[var(--accent)] transition-colors italic",children:["Show ",f," more…"]}),!h&&i&&x.length>10&&(0,r.jsxs)("button",{onClick:()=>c(!1),className:"w-full text-left px-2 py-1 text-[11px] text-[var(--text-secondary)] hover:text-[var(--accent)] transition-colors italic",children:["Show top ",10]})]})]})}function ee(e){let{node:t,selectedFolder:a,onSelectFolder:n,onSelectFile:l}=e;return(0,r.jsxs)(r.Fragment,{children:[t.children.map(e=>(0,r.jsx)(W,{label:e.name,icon:(0,r.jsx)(Y,{className:"w-3.5 h-3.5 text-[#FF7F50] group-hover:text-[var(--accent)] transition-colors"}),active:a===e.path,onClick:()=>n(e.path),children:(0,r.jsx)(ee,{node:e,selectedFolder:a,onSelectFolder:n,onSelectFile:l})},e.path)),t.files.map(e=>{var t;return(0,r.jsx)(W,{label:e.title,icon:(0,r.jsx)($,{contentClass:null!=(t=e.content_class)?t:null,className:"w-3.5 h-3.5 text-amber-accent group-hover:text-[var(--accent)] transition-colors"}),onClick:()=>l(e.id)},e.id)})]})}function et(e){let{projects:t,projectFiles:a,knowledgeFiles:l,selectedProjectId:s,selectedSection:i,selectedFolder:c,projectFolders:d,knowledgeFolders:u,projectBasePath:x,knowledgeBasePath:h,onSelectProject:m,onSelectKnowledge:p,onSelectFavorites:f,onSelectKnowledgeFolder:b,onSelectFolder:v,onSelectFile:g,onCreateBucketFolder:j,showJournal:y=!1,onToggleShowJournal:w,selectedTag:N,tags:k,onSelectTag:S}=e,C=(0,n.useMemo)(()=>{if(!s)return null;let e=t.find(e=>e.id===s);return e&&e.path?J(a,e.path,d):null},[s,a,d,t]),T=(0,n.useMemo)(()=>0===u.length&&0===l.length?null:J(l,h,u,!1),[l,u,h]);return(0,r.jsxs)("div",{className:"p-2 space-y-3 text-[var(--text-primary)]",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"bp-annotation px-2 pt-2 pb-1 text-[12px] uppercase tracking-wider text-[var(--text-secondary)]",children:"Projects"}),(0,r.jsxs)("div",{className:"space-y-0.5",children:[t.map(e=>{let t=s===e.id;return(0,r.jsx)(W,{label:e.name,icon:(0,r.jsx)(Y,{className:"w-3.5 h-3.5 text-[#FF7F50] group-hover:text-[var(--accent)] transition-colors"}),active:t&&null===c,initialExpanded:t,hasHands:e.has_hands,onClick:()=>{m(e.id),v(null)},children:t&&C?(0,r.jsx)(ee,{node:C,selectedFolder:c,onSelectFolder:v,onSelectFile:g}):void 0},e.id)}),0===t.length&&(0,r.jsx)(q.p,{icon:(0,r.jsx)(o.A,{className:"w-8 h-8 opacity-40","aria-hidden":!0}),title:"No projects yet"})]})]}),(0,r.jsx)("div",{children:(0,r.jsx)("div",{className:"flex items-center justify-between px-2 pt-2 pb-1",children:(0,r.jsx)("button",{onClick:f,className:"text-[12px] uppercase tracking-wider transition-colors ".concat("favorites"===i?"text-[var(--accent)]":"text-[var(--text-secondary)] hover:text-[var(--text-primary)]"),"aria-label":"Select favorites",children:"Favorites"})})}),(0,r.jsx)(Q,{tags:k,selectedTag:N,onSelectTag:S}),(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-2 pt-2 pb-1",children:[(0,r.jsx)("button",{onClick:p,className:"text-[12px] uppercase tracking-wider transition-colors ".concat("knowledge"!==i||c?"text-[var(--text-secondary)] hover:text-[var(--text-primary)]":"text-[var(--accent)]"),"aria-label":"Select knowledge base",children:"Knowledge"}),w&&(0,r.jsxs)("button",{type:"button",onClick:w,"aria-pressed":y,"aria-label":y?"Hide journal":"Show journal",title:y?"Hide agent journal files":"Show agent journal files",className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] uppercase tracking-wider transition-colors ".concat(y?"bg-[var(--accent-soft)] text-[var(--accent)] font-semibold":"text-[var(--text-secondary)]/60 hover:text-[var(--text-primary)]"),children:[(0,r.jsx)(I.A,{className:"w-3 h-3 shrink-0","aria-hidden":!0}),(0,r.jsx)("span",{children:"Journal"})]})]}),(0,r.jsx)("div",{className:"space-y-0.5",children:(()=>{var e,t,a;let n=null!=(e=null==T?void 0:T.files)?e:[],l=new Map;for(let e of null!=(t=null==T?void 0:T.children)?t:[]){let t=e.name.toLowerCase();X.has(t)&&!l.has(t)&&l.set(t,e)}let s=(null!=(a=null==T?void 0:T.children)?a:[]).filter(e=>!X.has(e.name.toLowerCase())),o=y?Z:Z.filter(e=>"journal"!==e.name);return(0,r.jsxs)(r.Fragment,{children:[n.map(e=>{var t;let a=e.path.toLowerCase().endsWith("/profile.md")||e.path.toLowerCase().endsWith("\\profile.md");return(0,r.jsx)(W,{label:e.title,icon:a?(0,r.jsx)(z.A,{className:"w-3.5 h-3.5 text-[var(--accent)] group-hover:text-[var(--accent)] transition-colors"}):(0,r.jsx)($,{contentClass:null!=(t=e.content_class)?t:null,className:"w-3.5 h-3.5 text-amber-accent group-hover:text-[var(--accent)] transition-colors"}),onClick:()=>g(e.id)},e.id)}),o.map(e=>{var t;let a,n=null!=(t=l.get(e.name))?t:{name:a=e.name,path:a,children:[],files:[]},s=0===n.children.length&&0===n.files.length;return(0,r.jsx)(W,{label:e.label,icon:e.icon({className:"w-3.5 h-3.5 ".concat(s?"text-[var(--text-secondary)] opacity-60":"text-[#FF7F50]"," group-hover:text-[var(--accent)] transition-colors")}),active:c===e.name,onClick:()=>b(e.name),trailingAction:j?(0,r.jsx)("button",{type:"button",onClick:()=>j(e.name),className:"text-[10px] px-1.5 py-0.5 rounded hover:bg-[var(--accent-soft)] text-[var(--text-secondary)] hover:text-[var(--accent)]",title:"New subfolder inside ".concat(e.name,"/"),"aria-label":"New subfolder inside ".concat(e.name),children:"+"}):void 0,children:s?void 0:(0,r.jsx)(ee,{node:n,selectedFolder:c,onSelectFolder:b,onSelectFile:g})},e.name)}),s.map(e=>(0,r.jsx)(W,{label:"".concat(e.name," (legacy)"),icon:(0,r.jsx)(Y,{className:"w-3.5 h-3.5 text-[var(--text-secondary)] opacity-70 group-hover:text-[var(--accent)] transition-colors"}),active:c===e.path,onClick:()=>b(e.path),children:(0,r.jsx)(ee,{node:e,selectedFolder:c,onSelectFolder:b,onSelectFile:g})},e.path))]})})()})]})]})}var ea=a(50329),er=a(24598);function en(e){let{value:t,onChange:a}=e;return(0,r.jsx)("input",{type:"text",value:t,onChange:e=>a(e.target.value),placeholder:"Filter files...",className:"w-full px-2.5 py-1 text-[12px] bg-[var(--bg-primary)] border-b border-[var(--border)] focus:outline-none focus:border-[var(--accent)]"})}var el=a(31923);let es=e=>{let{className:t}=e;return(0,r.jsxs)("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[(0,r.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,r.jsx)("polyline",{points:"7 10 12 15 17 10"}),(0,r.jsx)("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})};function eo(e){let{id:t,title:a,updatedAt:n,active:l,onClick:s,estTokens:o,selectMode:i,selected:c,onToggleSelect:u,favorite:x,tags:h,contentClass:m}=e;return(0,r.jsx)("div",{onClick:e=>{if(i){e.preventDefault(),null==u||u();return}s()},className:"\n group relative px-4 py-3 cursor-pointer border-l-[3px] transition-all duration-200\n ".concat(l&&!i||i&&c?"bg-[var(--accent-soft)] border-amber-accent":"border-transparent hover:bg-[var(--accent-soft)]/60 hover:translate-x-0.5","\n "),children:(0,r.jsxs)("div",{className:"flex items-start gap-3",children:[i?(0,r.jsx)("input",{type:"checkbox",checked:!!c,onChange:()=>null==u?void 0:u(),onClick:e=>e.stopPropagation(),className:"mt-1 cursor-pointer accent-amber-accent"}):(0,r.jsx)($,{contentClass:null!=m?m:null,className:"w-4 h-4 mt-1 text-amber-accent shrink-0"}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsxs)("div",{className:"text-sm font-semibold truncate transition-colors flex items-center gap-1.5 ".concat(l?"text-[var(--text-primary)]":"text-[var(--text-primary)] group-hover:text-[var(--accent)]"),children:[x&&(0,r.jsx)("span",{className:"text-amber-accent shrink-0",title:"Favorite","aria-label":"Favorite",children:(0,r.jsx)(el.A,{className:"w-3.5 h-3.5 fill-current","aria-hidden":!0})}),(0,r.jsx)("span",{className:"truncate",children:a})]}),(0,r.jsxs)("div",{className:"text-[11px] mt-1 flex flex-wrap items-center gap-1.5 transition-colors text-[var(--text-secondary)]",children:[(0,r.jsx)("span",{children:function(e){let t=new Date(e),a=new Date().getTime()-t.getTime(),r=Math.floor(a/6e4),n=Math.floor(a/36e5),l=Math.floor(a/864e5);return r<1?"just now":1===r?"1 min ago":r<60?"".concat(r," mins ago"):1===n?"1 hour ago":n<24?"".concat(n," hours ago"):1===l?"1 day ago":l<30?"".concat(l," days ago"):t.toLocaleDateString()}(n)}),"number"==typeof o&&o>0&&(0,r.jsxs)("span",{children:["\xb7 ~",o<1e3?String(o):o<1e4?(o/1e3).toFixed(1)+"k":Math.round(o/1e3)+"k"," tok"]}),h&&h.length>0&&(0,r.jsxs)("span",{className:"flex flex-wrap gap-1",children:[h.slice(0,3).map(e=>(0,r.jsx)("span",{className:"px-1.5 rounded bg-amber-accent/10 border border-amber-accent/20 text-[10px]",children:e},e)),h.length>3&&(0,r.jsxs)("span",{className:"text-[10px] opacity-60",children:["+",h.length-3]})]})]})]}),!i&&(0,r.jsx)("button",{type:"button",onClick:async e=>{var r,n;e.stopPropagation();try{let e=await fetch("/api/files/".concat(t,"/download"));if(!e.ok){let t="HTTP ".concat(e.status);try{let a=await e.json();(null==a?void 0:a.error)&&(t=a.error)}catch(e){}d.o.error("Download failed: ".concat(t));return}let n=e.headers.get("content-disposition")||"",l=/filename="([^"]+)"/.exec(n),s=null!=(r=null==l?void 0:l[1])?r:"".concat(a,".md"),o=await e.blob(),i=URL.createObjectURL(o),c=document.createElement("a");c.href=i,c.download=s,document.body.appendChild(c),c.click(),c.remove(),URL.revokeObjectURL(i)}catch(e){d.o.error("Download failed: ".concat(null!=(n=null==e?void 0:e.message)?n:String(e)))}},title:"Download .md","aria-label":"Download file",className:"btn btn-icon-sm opacity-0 group-hover:opacity-100",children:(0,r.jsx)(es,{className:"w-4 h-4"})})]})})}var ei=a(85170);function ec(e){let{open:t,onClose:a,projects:l,defaultProjectId:s,defaultFolder:o,onUploaded:i,showJournal:c=!1}=e,[d,u]=(0,n.useState)([]),[x,h]=(0,n.useState)(null!=s?s:""),[m,p]=(0,n.useState)(o),[f,b]=(0,n.useState)([]),[v,g]=(0,n.useState)(""),[j,y]=(0,n.useState)(!1),[w,N]=(0,n.useState)(null),[k,S]=(0,n.useState)(null);(0,n.useEffect)(()=>{t&&(u([]),h(null!=s?s:""),p(o),g(""),N(null),S(null))},[t,s,o]),(0,n.useEffect)(()=>{let e=!1;return(async()=>{let t=x?"/api/folders?projectId=".concat(x):"/api/folders";try{var a;let r=await fetch(t),n=await r.json();e||b(null!=(a=n.folders)?a:[])}catch(t){e||b([])}})(),()=>{e=!0}},[x]);let C=""===x,T=C?(0,ei.AU)(m):null,A=c?ei.is:ei.is.filter(e=>"journal"!==e),_=C?f.filter(e=>A.some(t=>e===t||e.startsWith("".concat(t,"/"))||e.startsWith("".concat(t,"\\")))):f,E=C?(0,ei.UF)(m):null,P=C?d.filter(e=>!(0,ei.zQ)(e.name,m)):[],F=async e=>{var t,a;if(e.preventDefault(),0!==d.length){if(C&&!m)return void S(c?"Pick a KB folder (journal, knowledge, mermaid, or html - or a subfolder).":"Pick a KB folder (knowledge, mermaid, or html - or a subfolder).");if(P.length>0)return void S("".concat(P.length," file(s) don't fit ").concat(T?T+"/":"this folder",": ").concat(P.map(e=>e.name).join(", ")));y(!0),S(null),N(null);try{let e=new FormData;e.append("project_id",""===x?"":String(x)),e.append("folder",m);let a=v.split(",").map(e=>e.trim()).filter(Boolean);for(let t of(a.length&&e.append("tags",JSON.stringify(a)),d))e.append("files",t);let r=await fetch("/api/files/upload",{method:"POST",body:e}),n=await r.json();r.ok?(N(n),i()):S(null!=(t=n.error)?t:"HTTP ".concat(r.status))}catch(e){S(null!=(a=null==e?void 0:e.message)?a:String(e))}finally{y(!1)}}};return t?(0,r.jsx)("div",{className:"fixed inset-0 z-50 bg-black/50 flex items-center justify-center p-4",children:(0,r.jsx)("div",{className:"w-[600px] bg-[var(--bg-primary)] border border-[var(--border-color)] rounded-lg shadow-2xl overflow-hidden",children:(0,r.jsxs)("form",{onSubmit:F,children:[(0,r.jsxs)("div",{className:"px-6 py-4 border-b border-[var(--border-color)] flex items-center justify-between",children:[(0,r.jsx)("h3",{className:"text-lg font-bold text-amber-accent",children:"UPLOAD MARKDOWN FILES"}),(0,r.jsx)("button",{type:"button",onClick:a,className:"btn btn-icon-md","aria-label":"Close dialog",children:(0,r.jsx)(H.A,{className:"w-4 h-4","aria-hidden":!0})})]}),(0,r.jsxs)("div",{className:"p-6 space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-[10px] font-bold text-[var(--text-secondary)] tracking-widest mb-1.5",children:"FILES"}),(0,r.jsx)("input",{type:"file",multiple:!0,accept:null===E?".md,.markdown,.mmd,.html,.htm":E||void 0,onChange:e=>{var t;return u(Array.from(null!=(t=e.target.files)?t:[]))},className:"w-full text-sm text-[var(--text-primary)]"}),C&&T&&!(0,ei.$3)(m)&&(0,r.jsxs)("p",{className:"text-[10px] text-[var(--text-secondary)] mt-1 italic",children:[T,"/ accepts ",E," only. Media goes in html/resources/."]}),d.length>0&&(0,r.jsx)("ul",{className:"mt-2 text-xs text-[var(--text-secondary)] max-h-32 overflow-auto",children:d.map((e,t)=>(0,r.jsxs)("li",{className:"flex items-center justify-between py-0.5",children:[(0,r.jsx)("span",{className:"truncate",children:e.name}),(0,r.jsx)("button",{type:"button",className:"btn btn-icon-sm btn-destructive","aria-label":"Remove ".concat(e.name),onClick:()=>u(e=>e.filter((e,a)=>a!==t)),children:(0,r.jsx)(H.A,{className:"w-3.5 h-3.5","aria-hidden":!0})})]},t))})]}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-[10px] font-bold text-[var(--text-secondary)] tracking-widest mb-1.5",children:"PROJECT"}),(0,r.jsxs)("select",{value:""===x?"":String(x),onChange:e=>h(""===e.target.value?"":Number(e.target.value)),className:"w-full bg-[var(--bg-secondary)] border border-[var(--border-color)] rounded px-3 py-2 text-sm text-[var(--text-primary)] outline-none focus:border-amber-accent/50 cursor-pointer",children:[(0,r.jsx)("option",{value:"",children:"- Knowledge Base -"}),l.map(e=>(0,r.jsx)("option",{value:e.id,children:e.name},e.id))]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-[10px] font-bold text-[var(--text-secondary)] tracking-widest mb-1.5",children:"FOLDER"}),C&&0===_.length?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("input",{type:"text",value:m,onChange:e=>p(e.target.value),placeholder:c?"e.g. knowledge or journal/2026":"e.g. knowledge or mermaid",list:"kb-bucket-hints",className:"w-full bg-[var(--bg-secondary)] border border-[var(--border-color)] rounded px-3 py-2 text-sm text-[var(--text-primary)] outline-none focus:border-amber-accent/50",required:!0}),(0,r.jsx)("datalist",{id:"kb-bucket-hints",children:A.map(e=>(0,r.jsx)("option",{value:e},e))})]}):(0,r.jsxs)("select",{value:m,onChange:e=>p(e.target.value),className:"w-full bg-[var(--bg-secondary)] border border-[var(--border-color)] rounded px-3 py-2 text-sm text-[var(--text-primary)] outline-none focus:border-amber-accent/50 cursor-pointer",required:C,children:[C?(0,r.jsx)("option",{value:"",disabled:!0,children:"- Pick a KB folder -"}):(0,r.jsx)("option",{value:"",children:"- Root level -"}),_.map(e=>(0,r.jsx)("option",{value:e,children:e},e))]})]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-[10px] font-bold text-[var(--text-secondary)] tracking-widest mb-1.5",children:"TAGS"}),(0,r.jsx)("input",{type:"text",value:v,onChange:e=>g(e.target.value),placeholder:"comma, separated, tags",className:"w-full bg-[var(--bg-secondary)] border border-[var(--border-color)] rounded px-3 py-2 text-sm text-[var(--text-primary)] outline-none focus:border-amber-accent/50"})]}),k&&(0,r.jsx)("div",{className:"text-sm text-[var(--danger)]",children:k}),w&&(0,r.jsxs)("div",{className:"text-sm text-[var(--text-secondary)]",children:["Uploaded ",w.uploaded.length," \xb7 renamed ",w.uploaded.filter(e=>e.final_name!==e.original_name).length," \xb7 rejected ",w.rejected.length,(w.uploaded.some(e=>e.final_name!==e.original_name)||w.rejected.length>0)&&(0,r.jsxs)("details",{className:"mt-2",children:[(0,r.jsx)("summary",{className:"cursor-pointer",children:"Details"}),(0,r.jsxs)("ul",{className:"mt-1 text-xs",children:[w.uploaded.filter(e=>e.final_name!==e.original_name).map((e,t)=>(0,r.jsxs)("li",{children:["renamed: ",e.original_name," → ",e.final_name]},"r".concat(t))),w.rejected.map((e,t)=>(0,r.jsxs)("li",{children:["rejected: ",e.name," (",e.reason,")"]},"x".concat(t)))]})]})]})]}),(0,r.jsxs)("div",{className:"px-6 py-4 border-t border-[var(--border-color)] flex justify-end gap-2",children:[(0,r.jsx)("button",{type:"button",onClick:a,className:"btn btn-md",children:"Close"}),(0,r.jsx)("button",{type:"submit",disabled:j||0===d.length,className:"btn btn-md",children:j?"Uploading…":"Upload"})]})]})})}):null}function ed(e){let{open:t,onClose:a,onClipped:l}=e,[s,o]=(0,n.useState)(""),[i,c]=(0,n.useState)(""),[d,u]=(0,n.useState)(!1),[x,h]=(0,n.useState)(null);(0,n.useEffect)(()=>{t&&(o(""),c(""),h(null),u(!1))},[t]);let m=async e=>{var t,r;if(e.preventDefault(),s.trim()){u(!0),h(null);try{let e=await fetch("/api/clip",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:s.trim(),title:i.trim()||void 0})}),r=await e.json();if(!e.ok)return void h(null!=(t=null==r?void 0:r.error)?t:"HTTP ".concat(e.status));l(),a()}catch(e){h(null!=(r=null==e?void 0:e.message)?r:String(e))}finally{u(!1)}}};return t?(0,r.jsx)("div",{className:"fixed inset-0 z-50 bg-black/50 flex items-center justify-center p-4",children:(0,r.jsx)("div",{className:"w-[600px] bg-[var(--bg-primary)] border border-[var(--border-color)] rounded-lg shadow-2xl overflow-hidden",children:(0,r.jsxs)("form",{onSubmit:m,children:[(0,r.jsxs)("div",{className:"px-6 py-4 border-b border-[var(--border-color)] flex items-center justify-between",children:[(0,r.jsx)("h3",{className:"text-lg font-bold text-amber-accent",children:"CLIP URL"}),(0,r.jsx)("button",{type:"button",onClick:a,className:"btn btn-icon-md","aria-label":"Close dialog",children:(0,r.jsx)(H.A,{className:"w-4 h-4","aria-hidden":!0})})]}),(0,r.jsxs)("div",{className:"p-6 space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-[10px] font-bold text-[var(--text-secondary)] tracking-widest mb-1.5",children:"URL"}),(0,r.jsx)("input",{type:"url",required:!0,value:s,onChange:e=>o(e.target.value),placeholder:"https://example.com/article",disabled:d,className:"w-full bg-[var(--bg-secondary)] border border-[var(--border-color)] rounded px-3 py-2 text-sm text-[var(--text-primary)] outline-none focus:border-amber-accent/50"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-[10px] font-bold text-[var(--text-secondary)] tracking-widest mb-1.5",children:"TITLE (OPTIONAL)"}),(0,r.jsx)("input",{type:"text",value:i,onChange:e=>c(e.target.value),placeholder:"Defaults to page title",disabled:d,className:"w-full bg-[var(--bg-secondary)] border border-[var(--border-color)] rounded px-3 py-2 text-sm text-[var(--text-primary)] outline-none focus:border-amber-accent/50"})]}),x&&(0,r.jsx)("div",{className:"text-sm text-[var(--danger)]",children:x})]}),(0,r.jsxs)("div",{className:"px-6 py-4 border-t border-[var(--border-color)] flex justify-end gap-2",children:[(0,r.jsx)("button",{type:"button",onClick:a,className:"btn btn-md",children:"Close"}),(0,r.jsx)("button",{type:"submit",disabled:d||!s.trim(),className:"btn btn-md",children:d?"Clipping…":"Clip"})]})]})})}):null}var eu=a(56570);let ex=[{id:"generic",label:"Universal — AGENTS.md (Recommended)",path:"AGENTS.md"},{id:"claude-code",label:"Claude Code (CLAUDE.md)",path:"CLAUDE.md"},{id:"codex",label:"Codex CLI (AGENTS.md)",path:"AGENTS.md"},{id:"cursor",label:"Cursor (.cursor/rules/kontexta.mdc)",path:".cursor/rules/kontexta.mdc"},{id:"windsurf",label:"Windsurf (AGENTS.md)",path:"AGENTS.md"},{id:"opencode",label:"OpenCode (AGENTS.md)",path:"AGENTS.md"},{id:"gemini",label:"Gemini CLI (GEMINI.md)",path:"GEMINI.md"},{id:"antigravity",label:"Antigravity (ANTIGRAVITY.md)",path:"ANTIGRAVITY.md"},{id:"copilot",label:"GitHub Copilot (.github/copilot-instructions.md)",path:".github/copilot-instructions.md"},{id:"cline",label:"Cline (.clinerules)",path:".clinerules"},{id:"continue",label:"Continue (.continue/rules/kontexta.md)",path:".continue/rules/kontexta.md"},{id:"aider",label:"Aider (.aider/kontexta.md)",path:".aider/kontexta.md"}];function eh(e){var t;let{isOpen:a,onClose:l,projectId:s,projectName:o,onOnboarded:i}=e,[c,u]=(0,n.useState)("generic"),[x,h]=(0,n.useState)(!1),m=null!=(t=ex.find(e=>e.id===c))?t:ex[0],p=async()=>{h(!0);try{let e=await fetch("/api/projects/".concat(s,"/onboard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({targetAgent:c})});if(e.ok)d.o.success("Onboarded ".concat(o)),i(),l();else{let t=await e.json().catch(()=>({}));d.o.error(t.error||"Onboarding failed: HTTP ".concat(e.status))}}catch(e){d.o.error("Failed to connect to server")}finally{h(!1)}};return(0,r.jsx)(eu.l,{open:a,onClose:l,title:"Onboard agent",widthClass:"max-w-[500px]",children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"text-sm text-[var(--text-secondary)] leading-relaxed",children:["Scaffold workflow rules for ",(0,r.jsx)("strong",{children:o}),". This writes workflow rules to"," ",(0,r.jsx)("code",{children:m.path})," (and ",(0,r.jsx)("code",{children:"KONTEXTA.md"}),") in the project root."]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("label",{className:"block text-[10px] font-bold text-[var(--text-secondary)] tracking-widest uppercase",children:"Target agent"}),(0,r.jsx)("select",{value:c,onChange:e=>u(e.target.value),className:"w-full bg-[var(--bg-secondary)] border border-[var(--border)] rounded px-3 py-2 text-sm text-[var(--text-primary)] outline-none focus:border-amber-accent/50 cursor-pointer",children:ex.map(e=>(0,r.jsx)("option",{value:e.id,children:e.label},e.id))})]}),"aider"===c&&(0,r.jsxs)("div",{className:"p-3 bg-amber-500/5 border border-amber-500/20 rounded text-[11px] text-amber-600 dark:text-amber-400 leading-normal",children:[(0,r.jsx)("strong",{children:"Aider note:"})," Integration is file-based. After onboarding, ensure your ",(0,r.jsx)("code",{children:".aider.conf.yml"})," reads the new file."]}),(0,r.jsxs)("div",{className:"flex justify-end gap-3 pt-2",children:[(0,r.jsx)("button",{type:"button",onClick:l,className:"btn btn-md",disabled:x,children:"Cancel"}),(0,r.jsx)("button",{type:"button",onClick:p,disabled:x,className:"btn btn-md min-w-[140px]",children:x?"Onboarding…":"Onboard agent"})]})]})})}var em=a(17695);function ep(e){let{files:t,selectedFileId:a,onSelectFile:l,sortBy:s,onSortChange:o,selectedFolder:i,selectedProject:c,selectedSection:u,basePath:x,onUnregisterProject:h,onDeleteFolder:m,loading:p,projects:f,onUploaded:v,onRefresh:g,onOnboarded:j,refreshing:y,onNewFile:w,showJournal:N=!1}=e,[k,S]=(0,n.useState)(""),[C,T]=(0,n.useState)(!1),[_,E]=(0,n.useState)(!1),[P,F]=(0,n.useState)(!1),[L,R]=(0,n.useState)(!1),[M,D]=(0,n.useState)(new Set),[I,O]=(0,n.useState)(!1),[G,z]=(0,n.useState)(!1),[B,W]=(0,n.useState)(150);(0,n.useEffect)(()=>{D(new Set),W(150)},[i,null==c?void 0:c.id,u,k,s]);let K=(0,n.useMemo)(()=>{let e=[...t],a=e=>(e||"").replace(/\\/g,"/").replace(/\/+$/,""),r=(e,t)=>{if(!e||!t)return!1;let r=a(e),n=a(t)+"/";return r.startsWith(n)};if("projects"===u)if(c){let t=x||c.path;if(t){let n=a(t)+"/";if(i){let t=n+a(i);e=e.filter(e=>r(e.path,t))}else e=e.filter(e=>e.project_id===c.id)}else e=e.filter(e=>e.project_id===c.id)}else e=[];else if("favorites"===u)e=[...t];else if("tags"===u)e=[...t];else if("knowledge"===u){if(e=e.filter(e=>!e.project_id),x){let t=a(x)+"/";if(i){let n=t+a(i);e=e.filter(e=>r(e.path,n))}}}else e=[];switch(s){case"name":e.sort((e,t)=>e.title.localeCompare(t.title));break;case"updated_at":e.sort((e,t)=>new Date(t.updated_at).getTime()-new Date(e.updated_at).getTime());break;case"created_at":e.sort((e,t)=>new Date(t.created_at).getTime()-new Date(e.created_at).getTime())}let n=k.trim();if(n){let t=/^(?:#|(?:(?:file_)?id|file):\s*#?)(\d+)$/i.exec(n);if(t){let a=Number(t[1]);e=e.filter(e=>e.id===a)}else{let t=n.toLowerCase(),a=/^\d+$/.test(n)?Number(n):null;e=e.filter(e=>null!==a&&e.id===a||e.title.toLowerCase().includes(t))}}return e},[t,s,i,c,u,x,k]);return(0,n.useEffect)(()=>{if(null==a)return;let e=K.findIndex(e=>e.id===a);e>=B&&W(e+150)},[a,K,B]),(0,r.jsxs)("div",{className:"flex flex-col h-full",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1.5 px-1.5 py-1.5 border-b border-[var(--border)]",children:[(0,r.jsx)("div",{className:"flex-1",children:(0,r.jsx)(A,{align:"start",trigger:(0,r.jsxs)("button",{type:"button",className:"btn btn-sm w-full",title:"Add content to the knowledge base",children:["New ",(0,r.jsx)("span",{className:"opacity-60 text-xs",children:"▾"})]}),items:[{label:"New File",icon:(0,r.jsx)("span",{children:"+"}),onSelect:w},{label:"Upload Files",icon:(0,r.jsx)("span",{children:"↑"}),onSelect:()=>T(!0)},{label:"Clip URL",icon:(0,r.jsx)(ea.A,{className:"w-3.5 h-3.5","aria-hidden":!0}),onSelect:()=>O(!0)}]})}),"projects"===u&&c&&(0,r.jsx)("div",{className:"flex-1",children:(0,r.jsx)(A,{align:"start",trigger:(0,r.jsxs)("button",{type:"button",className:"btn btn-sm w-full",title:"Project actions",children:["Project ",(0,r.jsx)("span",{className:"opacity-60 text-xs",children:"▾"})]}),items:[{label:"Export ZIP",icon:(0,r.jsx)("span",{children:"↓"}),onSelect:()=>{let e=i?"/api/export/zip?project_id=".concat(c.id,"&folder=").concat(encodeURIComponent(i)):"/api/export/zip?project_id=".concat(c.id),t=document.createElement("a");t.href=e,t.download="",document.body.appendChild(t),t.click(),t.remove()}},{label:"Scan for New Files",icon:(0,r.jsx)(U.A,{className:"w-3.5 h-3.5","aria-hidden":!0}),onSelect:g},{label:"Onboard Agent",icon:(0,r.jsx)("span",{children:"✨"}),onSelect:()=>z(!0)},...!i&&h?[{label:"Unregister",icon:(0,r.jsx)(H.A,{className:"w-3.5 h-3.5","aria-hidden":!0}),onSelect:h,destructive:!0}]:[]]})}),(0,r.jsx)("button",{type:"button",onClick:()=>{E(e=>!e),D(new Set)},className:"btn btn-sm flex-1",title:"Toggle multi-select",children:_?"Selected":"Select"}),(0,r.jsx)("button",{type:"button",onClick:g,disabled:y,className:"btn btn-sm ".concat(y?"opacity-50":""),title:"Refresh (scan disk for changes)","aria-label":"Refresh",children:y?"...":(0,r.jsx)(b.A,{className:"w-4 h-4","aria-hidden":!0})})]}),"projects"===u&&c&&c.agent_rules&&"up_to_date"!==c.agent_rules.status&&(0,r.jsxs)("div",{className:"px-3 py-2 flex items-center justify-between gap-3 text-[11px] bg-amber-500/5 border-b border-amber-500/20 text-amber-600 dark:text-amber-400",children:[(0,r.jsx)("span",{children:"none"===c.agent_rules.status?"This project has no agent instructions file yet - your AI agent won't know Kontexta is registered.":"This project's agent rules are outdated (v".concat(c.agent_rules.latest_version," available).")}),(0,r.jsx)("button",{type:"button",onClick:()=>z(!0),className:"btn btn-sm shrink-0",children:"Onboard Agent"})]}),(0,r.jsxs)("div",{className:"bp-annotation bp-dashed px-3 py-2 flex items-center justify-between text-[11px] uppercase tracking-wider text-[var(--text-secondary)] border-b border-[var(--border)]",children:[(0,r.jsxs)("span",{children:[K.length," ",1===K.length?"file":"files",(()=>{var e;let t=K.reduce((e,t)=>{var a;return e+(null!=(a=t.est_tokens)?a:0)},0);return t>0?" \xb7 ~".concat((e=t)<1e3?String(e):e<1e4?"".concat((e/1e3).toFixed(1),"k"):e<1e6?"".concat(Math.round(e/1e3),"k"):"".concat((e/1e6).toFixed(1),"M")," tok"):""})()]}),(0,r.jsx)("div",{className:"flex items-center gap-2",children:(0,r.jsxs)("select",{value:s,onChange:e=>o(e.target.value),className:"bg-transparent text-[11px] uppercase tracking-wider focus:outline-none cursor-pointer",children:[(0,r.jsx)("option",{value:"updated_at",className:"bg-[var(--bg-primary)] text-[var(--text-primary)]",children:"updated"}),(0,r.jsx)("option",{value:"created_at",className:"bg-[var(--bg-primary)] text-[var(--text-primary)]",children:"created"}),(0,r.jsx)("option",{value:"name",className:"bg-[var(--bg-primary)] text-[var(--text-primary)]",children:"name"})]})})]}),(t.length>10||""!==k.trim())&&(0,r.jsx)(en,{value:k,onChange:S}),(()=>{let e=new Set(K.map(e=>e.id)),t=[...M].filter(t=>e.has(t)),n=c?String(c.id):"kb",s=async()=>{if(0===t.length||P)return;F(!0);let e=[];for(let n of t){var a,r;try{let t=await fetch("/api/files/".concat(n),{method:"DELETE"});if(!t.ok){let r=await t.json().catch(()=>({}));e.push({id:n,error:null!=(a=null==r?void 0:r.error)?a:"HTTP ".concat(t.status)})}}catch(t){e.push({id:n,error:null!=(r=null==t?void 0:t.message)?r:"Network error"})}}F(!1),R(!1),D(new Set),g();let n=t.length-e.length;e.length>0?(console.error("[bulk-delete] failures:",e),n>0&&d.o.success("Deleted ".concat(n," file(s)")),d.o.error("".concat(e.length," file(s) failed to delete: ")+e.slice(0,5).map(e=>"#".concat(e.id," (").concat(e.error,")")).join(", ")+(e.length>5?", …and ".concat(e.length-5," more (see console)"):""))):d.o.success("Deleted ".concat(n," file(s)"))};return(0,r.jsxs)("div",{className:"flex-1 overflow-y-auto",children:[_&&t.length>0&&(0,r.jsxs)("div",{className:"sticky top-0 z-10 px-3 py-2 bg-[var(--bg-secondary)] border-b border-amber-accent/40 flex items-center justify-between gap-2 text-[11px]",children:[(0,r.jsxs)("span",{className:"whitespace-nowrap shrink-0",children:[t.length," selected"]}),(0,r.jsxs)("div",{className:"flex items-center gap-1.5 shrink-0",children:[(0,r.jsx)("a",{href:"/api/export/zip?file_ids=".concat(t.join(","),"&scope=").concat(n),download:!0,className:"px-2 py-1 bg-amber-accent text-black font-bold rounded whitespace-nowrap leading-none",title:"Download selected files as ZIP",children:"ZIP"}),(0,r.jsx)("button",{type:"button",onClick:()=>R(!0),disabled:P,className:"px-2 py-1 bg-[var(--danger)] text-white font-bold rounded whitespace-nowrap leading-none ".concat(P?"opacity-50":"hover:bg-[color-mix(in_srgb,var(--danger)_85%,black)]"),title:"Delete ".concat(t.length," selected file(s)"),children:P?"…":"Delete"}),(0,r.jsx)("button",{type:"button",onClick:()=>D(new Set),className:"px-2 py-1 border border-[var(--border)] rounded whitespace-nowrap leading-none hover:bg-[var(--bg-tertiary)]",title:"Clear selection",children:"Clear"})]})]}),(0,r.jsx)(em.T,{open:L,onClose:()=>R(!1),onConfirm:s,title:"Delete ".concat(t.length," file").concat(1===t.length?"":"s","?"),message:"Knowledge Base files will be removed from disk and the deletion will be committed to git (recoverable via Time Travel). Project files are only un-indexed; the source file on disk is left intact.",confirmLabel:"Delete ".concat(t.length," file").concat(1===t.length?"":"s"),destructive:!0,loading:P}),K.length>0?(0,r.jsxs)(r.Fragment,{children:[K.slice(0,B).map(e=>{var t,n;return(0,r.jsx)(eo,{id:e.id,title:e.title,updatedAt:e.updated_at,active:e.id===a,onClick:()=>l(e.id),estTokens:e.est_tokens,favorite:e.favorite,tags:null!=(t=e.tags)?t:void 0,contentClass:null!=(n=e.content_class)?n:null,selectMode:_,selected:M.has(e.id),onToggleSelect:()=>{D(t=>{let a=new Set(t);return a.has(e.id)?a.delete(e.id):a.add(e.id),a})}},e.id)}),K.length>B&&(0,r.jsx)("div",{className:"p-3 flex justify-center border-b border-[var(--border)]",children:(0,r.jsxs)("button",{type:"button",onClick:()=>W(e=>e+150),className:"btn btn-sm text-xs w-full",children:["Show more (",K.length-B," remaining)"]})})]}):p||"projects"===u&&!c?(0,r.jsx)("div",{"aria-label":"Loading files",role:"status",children:[0,1,2,3].map(e=>(0,r.jsxs)("div",{className:"px-3 py-2 border-b border-[var(--bg-tertiary)]",children:[(0,r.jsx)("div",{className:"skeleton h-3.5",style:{width:"".concat(60+13*e%30,"%")}}),(0,r.jsx)("div",{className:"skeleton h-2.5 mt-2",style:{width:"".concat(30+7*e%20,"%")}})]},e))}):u?(0,r.jsx)(q.p,{icon:(0,r.jsx)(er.A,{className:"w-16 h-16 opacity-30 dark-icon","aria-hidden":!0}),title:"Folder is empty",hint:"This folder doesn't contain any indexed context files.",action:"knowledge"===u&&i&&!(0,ei.BZ)(i)&&m?(0,r.jsxs)("div",{className:"flex flex-col items-center gap-3",children:[(0,r.jsx)("div",{className:"h-px w-16 bg-[var(--border)]"}),(0,r.jsx)("button",{onClick:m,className:"px-6 py-2.5 bg-[var(--danger-soft)] text-[var(--danger)] border border-[var(--danger)]/30 rounded-lg text-sm font-bold hover:bg-[var(--danger)]/20 transition-all btn-press shadow-sm",children:"DELETE THIS FOLDER"}),(0,r.jsx)("p",{className:"text-[11px] text-[var(--muted)] uppercase tracking-widest font-bold",children:"Permanent Action"})]}):void 0}):(0,r.jsx)(q.p,{icon:(0,r.jsx)(er.A,{className:"w-16 h-16 opacity-30 dark-icon","aria-hidden":!0}),title:"No Selection",hint:"Please select a project or the Knowledge Base from the sidebar to view files."})]})})(),(0,r.jsx)(ec,{open:C,onClose:()=>T(!1),projects:null!=f?f:[],defaultProjectId:"projects"===u&&c?c.id:null,defaultFolder:null!=i?i:"",onUploaded:()=>{T(!1),null==v||v()},showJournal:N}),(0,r.jsx)(ed,{open:I,onClose:()=>O(!1),onClipped:()=>{g()}}),c&&(0,r.jsx)(eh,{isOpen:G,onClose:()=>z(!1),projectId:c.id,projectName:c.name,onOnboarded:()=>{(null!=j?j:g)()}})]})}var ef=a(35047),eb=a(6519);function ev(e){let{html:t}=e,a=(0,n.useMemo)(()=>'<!doctype html><html><head><meta charset="utf-8"><base href="/api/reports/"><style>body{font-family:-apple-system,Segoe UI,Roboto,sans-serif;margin:16px;color:#111}img{max-width:100%}</style></head><body>'.concat(t,"</body></html>"),[t]);return(0,r.jsx)("iframe",{title:"report",sandbox:"allow-same-origin",srcDoc:a,style:{width:"100%",height:"100%",border:"0",background:"white"}})}function eg(e){let{fileId:t,initial:a,expectedUpdatedAt:l,onClose:s,onSaved:o,onDirtyChange:i}=e,[c,u]=(0,n.useState)(a),[x,h]=(0,n.useState)(!1),[m,p]=(0,n.useState)(!1),f=c!==a;function b(){if(f)return void p(!0);s()}async function v(){h(!0);try{let e=await fetch("/api/files/".concat(t),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:c,expected_updated_at:l})});if(409===e.status)return void d.o.error("This file changed elsewhere since you opened it - reload before saving to avoid overwriting the newer version.");if(!e.ok){let t=await e.text().catch(()=>"");d.o.error("Save failed".concat(t?": ".concat(t):""));return}let a=await e.json();o(a),s()}catch(t){var e;d.o.error("Save failed: ".concat(null!=(e=null==t?void 0:t.message)?e:String(t)))}finally{h(!1)}}return(0,r.jsxs)(eu.l,{open:!0,onClose:b,title:"Edit HTML source",widthClass:"max-w-4xl",children:[(0,r.jsxs)("div",{className:"flex flex-col gap-4",style:{height:"min(70vh, 600px)"},children:[(0,r.jsx)("textarea",{value:c,onChange:e=>{let t=e.target.value;u(t),null==i||i(t!==a)},className:"flex-1 font-mono text-sm p-3 border border-[var(--border)] rounded resize-none bg-[var(--bg-secondary)] text-[var(--text-primary)]",spellCheck:!1}),(0,r.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,r.jsx)("button",{type:"button",onClick:b,disabled:x,className:"btn btn-md",children:"Cancel"}),(0,r.jsx)("button",{type:"button",onClick:v,disabled:x,className:"btn btn-md",children:x?"Saving...":"Save"})]})]}),(0,r.jsx)(em.T,{open:m,onClose:()=>p(!1),onConfirm:()=>{p(!1),s()},title:"Unsaved changes",message:"You have unsaved changes. Discard them?",confirmLabel:"Discard",cancelLabel:"Keep editing",destructive:!0})]})}function ej(e){let{content:t,onChange:a}=e,l=(0,n.useRef)(null);return(0,n.useEffect)(()=>{if(l.current){l.current.style.height="0px";let e=l.current.scrollHeight;l.current.style.height=e+"px"}},[t]),(0,r.jsx)("div",{className:"flex flex-col h-full bg-[var(--bg-primary)]",children:(0,r.jsx)("textarea",{ref:l,value:t,onChange:e=>a(e.target.value),className:"flex-1 w-full p-8 bg-transparent border-none outline-none resize-none font-mono text-[14px] text-[var(--text-primary)] leading-relaxed scrollbar-thin",placeholder:"Start typing your markdown...",spellCheck:!1})})}var ey=a(12570),ew=a(94495),eN=a(42528),ek=a(95852),eS=a(53352),eC=a(35811),eT=a(40873),eA=a(52436),e_=a(49799),eE=a(92819),eP=a(46644);let eF=[{key:"name",title:"Name",hint:"How the agent should address you.",icon:e=>(0,r.jsx)(ey.A,{className:e,"aria-hidden":!0}),placeholder:"e.g. Safiyu"},{key:"role",title:"Role",hint:"Your role, focus, and areas of expertise.",icon:e=>(0,r.jsx)(ew.A,{className:e,"aria-hidden":!0}),placeholder:"e.g. Full-stack engineer, platform core"},{key:"vision",title:"Vision",hint:"Where you want your work to go over the medium term.",icon:e=>(0,r.jsx)(eN.A,{className:e,"aria-hidden":!0}),placeholder:"e.g. Improve API performance and streamline developer workflows"},{key:"roadmap",title:"Roadmap",hint:"Active initiatives, upcoming milestones, current themes.",icon:e=>(0,r.jsx)(ek.A,{className:e,"aria-hidden":!0}),placeholder:"e.g. Q3 auth refactor; performance benchmarking"},{key:"preferences",title:"Preferences",hint:"General working style, tools, and communication quirks.",icon:e=>(0,r.jsx)(v.A,{className:e,"aria-hidden":!0}),placeholder:"e.g. Prefers TypeScript, concise explanations, test-driven development"},{key:"sessionCodingStyle",title:"Session coding style",hint:"Hard rules the agent must honor every session. Comment style, git etiquette, review gates.",icon:e=>(0,r.jsx)(eS.A,{className:e,"aria-hidden":!0}),placeholder:"e.g. one-line comments only; no auto push to git; ask before schema migrations"},{key:"teamMembers",title:"Team members and roles",hint:"People you work with, so the agent names them correctly in summaries and updates.",icon:e=>(0,r.jsx)(eC.A,{className:e,"aria-hidden":!0}),placeholder:"e.g. Alice - Product Manager\nBob - DevOps / SRE"},{key:"notes",title:"Notes",hint:"Anything else worth remembering that doesn't fit elsewhere.",icon:e=>(0,r.jsx)(eT.A,{className:e,"aria-hidden":!0}),placeholder:"Free-form scratch space."}],eL=new Set(eF.map(e=>e.title.toLowerCase()));function eR(e){let t={name:"",role:"",vision:"",roadmap:"",preferences:"",sessionCodingStyle:"",teamMembers:"",notes:""},a=[],r=e.replace(/^\s*#\s+Profile\s*$/m,"").split("\n"),n=[],l=null,s=null,o="",i=[],c=()=>{let e=i.join("\n").replace(/^\s+|\s+$/g,"");"required"===l&&s?t[s]=e:"custom"===l&&a.push({title:o,body:e}),i=[]};for(let e of r){let t=/^##\s+(.+?)\s*$/.exec(e);if(t){null!==l?c():n=i.slice();let e=function(e){let t=eF.find(t=>t.title.toLowerCase()===e.toLowerCase());return t?t.key:null}(t[1]);e?(l="required",s=e):(l="custom",o=t[1],s=null),i=[]}else i.push(e)}return null!==l?c():n=i.slice(),{preamble:n.join("\n").replace(/^\s+|\s+$/g,""),required:t,custom:a}}function eM(e){let t=["# Profile",""];for(let a of(e.preamble&&t.push(e.preamble,""),eF))t.push("## ".concat(a.title),e.required[a.key]||"","");for(let a of e.custom){let e=a.title.trim();e&&(eL.has(e.toLowerCase())||t.push("## ".concat(e),a.body||"",""))}return t.join("\n").replace(/\n{3,}/g,"\n\n")}function eD(e){let{onDirtyChange:t,onChanged:a}=e,[l,s]=(0,n.useState)(!0),[o,c]=(0,n.useState)(null),[u,x]=(0,n.useState)({preamble:"",required:{name:"",role:"",vision:"",roadmap:"",preferences:"",sessionCodingStyle:"",teamMembers:"",notes:""},custom:[]}),[h,m]=(0,n.useState)(""),[p,f]=(0,n.useState)(!1),[b,v]=(0,n.useState)(""),[g,j]=(0,n.useState)(!1),y=(0,n.useMemo)(()=>p?h:eM(u),[p,h,u]),w=!l&&y.trim()!==b.trim(),N=eF.filter(e=>!u.required[e.key].trim()).length;(0,n.useEffect)(()=>{null==t||t(w)},[w,t]);let k=(0,n.useRef)(t);(0,n.useEffect)(()=>{k.current=t},[t]),(0,n.useEffect)(()=>()=>{var e;return null==(e=k.current)?void 0:e.call(k,!1)},[]);let S=(0,n.useRef)(!1);(0,n.useEffect)(()=>{S.current||(S.current=!0,(async()=>{try{let e=await fetch("/api/profile");if(!e.ok)throw Error("HTTP ".concat(e.status));let t=await e.json(),a=t.exists?t.content:"",r=eM(eR(a));x(eR(a)),m(r),v(r)}catch(t){var e;c(null!=(e=null==t?void 0:t.message)?e:"Failed to load profile")}finally{s(!1)}})())},[]);let C=(e,t)=>{x(a=>{let r=[...a.custom];return r[e]={...r[e],...t},{...a,custom:r}})},T=async()=>{var e,t,r;j(!0);try{let r=await fetch("/api/profile",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:y})}),n=await r.json();if(!r.ok)throw Error(null!=(e=null==n?void 0:n.error)?e:"HTTP ".concat(r.status));let l=null!=(t=n.content)?t:y,s=eM(eR(l));v(s),x(eR(l)),m(s),d.o.success("Profile saved"),null==a||a()}catch(e){d.o.error("Failed to save profile: ".concat(null!=(r=null==e?void 0:e.message)?r:"Network error"))}finally{j(!1)}};if(l)return(0,r.jsxs)("div",{className:"h-full flex flex-col animate-fade-in",children:[(0,r.jsxs)("div",{className:"border-b border-[var(--border)] px-6 py-4",children:[(0,r.jsx)("div",{className:"skeleton h-6 w-48 mb-2"}),(0,r.jsx)("div",{className:"skeleton h-4 w-32"})]}),(0,r.jsxs)("div",{className:"flex-1 p-6 space-y-4",children:[(0,r.jsx)("div",{className:"skeleton h-4 w-full"}),(0,r.jsx)("div",{className:"skeleton h-4 w-5/6"})]})]});if(o)return(0,r.jsx)("div",{className:"h-full flex items-center justify-center p-6 text-[var(--text-secondary)]",children:(0,r.jsx)("div",{className:"text-center max-w-md",children:(0,r.jsxs)("p",{className:"text-sm",children:["Failed to load profile: ",o]})})});let A=u.required.name.trim()||"Set your name",_=u.required.role.trim(),E=Math.round((eF.length-N)/eF.length*100);return(0,r.jsxs)("div",{className:"h-full flex flex-col animate-fade-in bg-[var(--bg-primary)]",children:[(0,r.jsxs)("div",{className:"h-11 px-5 border-b border-[var(--border)] flex items-center gap-3 sticky top-0 bg-[var(--bg-primary)] z-20",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 text-[var(--text-primary)]",children:[(0,r.jsx)(z.A,{className:"w-4 h-4 text-[var(--accent)]","aria-hidden":!0}),(0,r.jsx)("span",{className:"text-[13px] font-semibold uppercase tracking-wider",children:"Profile"})]}),(0,r.jsx)("span",{className:"text-[11px] text-[var(--text-secondary)] font-mono",children:"knowledge/profile.md"}),w&&(0,r.jsx)("span",{className:"text-[10px] uppercase tracking-widest text-amber-accent font-bold",children:"• unsaved"}),(0,r.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:[(0,r.jsxs)("button",{type:"button",onClick:()=>{p?x(eR(h)):m(eM(u)),f(e=>!e)},className:"btn btn-sm inline-flex items-center gap-1 ".concat(p?"border-[var(--accent)]":""),title:p?"Switch back to the structured view":"Edit as raw markdown",children:[p?(0,r.jsx)(i.A,{className:"w-3.5 h-3.5","aria-hidden":!0}):(0,r.jsx)(eA.A,{className:"w-3.5 h-3.5","aria-hidden":!0}),p?"Structured":"Raw"]}),(0,r.jsxs)("button",{type:"button",onClick:()=>{x(eR(b)),m(b)},disabled:!w||g,className:"btn btn-sm inline-flex items-center gap-1",title:"Discard unsaved edits",children:[(0,r.jsx)(e_.A,{className:"w-3.5 h-3.5","aria-hidden":!0}),"Revert"]}),(0,r.jsx)("button",{type:"button",onClick:T,disabled:!w||g,className:"btn btn-sm border-[var(--accent)]/40",children:g?"Saving…":"Save"})]})]}),(0,r.jsx)("div",{className:"flex-1 overflow-auto",children:p?(0,r.jsx)("textarea",{value:h,onChange:e=>m(e.target.value),className:"w-full h-full bg-[var(--bg-primary)] text-[var(--text-primary)] p-6 font-mono text-sm outline-none resize-none",spellCheck:!1}):(0,r.jsxs)("div",{className:"max-w-3xl mx-auto px-6 py-8 space-y-8",children:[(0,r.jsxs)("header",{className:"flex items-start gap-5",children:[(0,r.jsx)("div",{className:"shrink-0 w-16 h-16 rounded-2xl bg-gradient-to-br from-[var(--accent-soft)] to-[var(--bg-secondary)] border border-[var(--border)] flex items-center justify-center",children:(0,r.jsx)(z.A,{className:"w-9 h-9 text-[var(--accent)]","aria-hidden":!0})}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsx)("h1",{className:"text-2xl font-bold tracking-tight truncate ".concat(u.required.name.trim()?"text-[var(--text-primary)]":"text-[var(--text-secondary)] italic"),children:A}),(0,r.jsx)("p",{className:"mt-1 text-sm text-[var(--text-secondary)]",children:_||(0,r.jsx)("span",{className:"italic",children:"Add your role"})}),(0,r.jsxs)("div",{className:"mt-3 flex items-center gap-3",children:[(0,r.jsx)("div",{className:"flex-1 h-1.5 rounded-full bg-[var(--bg-secondary)] border border-[var(--border)] overflow-hidden",children:(0,r.jsx)("div",{className:"h-full transition-all duration-500 ".concat(0===N?"bg-[var(--accent)]":"bg-amber-accent/70"),style:{width:"".concat(E,"%")}})}),(0,r.jsx)("span",{className:"text-[11px] font-bold uppercase tracking-wider whitespace-nowrap ".concat(0===N?"text-[var(--accent)]":"text-amber-accent"),children:0===N?"Complete":"".concat(eF.length-N,"/").concat(eF.length)})]})]})]}),u.preamble&&(0,r.jsx)("div",{className:"text-[12px] text-[var(--text-secondary)] italic border-l-2 border-[var(--accent)]/40 pl-3 py-1",children:u.preamble}),(0,r.jsx)("div",{className:"space-y-4",children:eF.map(e=>{let t=u.required[e.key],a=!t.trim();return(0,r.jsxs)("section",{className:"rounded-xl border transition-colors ".concat(a?"border-[var(--border)] bg-[var(--bg-secondary)]/40":"border-[var(--border)] bg-[var(--bg-secondary)]/70 hover:border-[var(--accent)]/30"),children:[(0,r.jsxs)("header",{className:"flex items-start gap-3 px-4 pt-4",children:[(0,r.jsx)("div",{className:"shrink-0 w-9 h-9 rounded-lg flex items-center justify-center ".concat(a?"bg-[var(--bg-primary)] text-[var(--text-secondary)]":"bg-[var(--accent-soft)] text-[var(--accent)]"),children:e.icon("w-4 h-4")}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,r.jsx)("h3",{className:"text-[13px] font-bold uppercase tracking-widest text-[var(--text-primary)]",children:e.title}),a&&(0,r.jsx)("span",{className:"text-[10px] uppercase tracking-widest text-amber-accent/80 font-semibold",children:"Empty"})]}),(0,r.jsx)("p",{className:"mt-0.5 text-[12px] text-[var(--text-secondary)]",children:e.hint})]})]}),(0,r.jsx)("div",{className:"p-4 pt-3",children:(0,r.jsx)("textarea",{value:t,onChange:t=>{var a,r;return a=e.key,r=t.target.value,void x(e=>({...e,required:{...e.required,[a]:r}}))},placeholder:e.placeholder,rows:Math.max(3,t.split("\n").length+1),className:"w-full bg-[var(--bg-primary)] border border-[var(--border)] rounded-lg px-3 py-2.5 text-sm text-[var(--text-primary)] outline-none focus:border-[var(--accent)]/50 font-mono resize-y placeholder:text-[var(--text-secondary)]/60"})})]},e.key)})}),(0,r.jsxs)("section",{className:"rounded-xl border border-dashed border-[var(--border)] bg-[var(--bg-secondary)]/30 p-4",children:[(0,r.jsxs)("header",{className:"flex items-center gap-3 mb-3",children:[(0,r.jsx)("div",{className:"shrink-0 w-9 h-9 rounded-lg bg-[var(--bg-primary)] text-[var(--text-secondary)] flex items-center justify-center",children:(0,r.jsx)(eE.A,{className:"w-4 h-4","aria-hidden":!0})}),(0,r.jsxs)("div",{className:"flex-1",children:[(0,r.jsxs)("h3",{className:"text-[13px] font-bold uppercase tracking-widest text-[var(--text-primary)]",children:["Custom sections",(0,r.jsxs)("span",{className:"ml-2 text-[11px] font-normal tracking-normal text-[var(--text-secondary)] normal-case",children:["(",u.custom.length,")"]})]}),(0,r.jsx)("p",{className:"mt-0.5 text-[12px] text-[var(--text-secondary)]",children:"Add your own headings for anything the required set doesn't cover."})]}),(0,r.jsxs)("button",{type:"button",onClick:()=>{let e="New section",t=2;for(;u.custom.some(t=>t.title.toLowerCase()===e.toLowerCase());)e="New section ".concat(t++);x(t=>({...t,custom:[...t.custom,{title:e,body:""}]}))},className:"btn btn-sm inline-flex items-center gap-1",children:[(0,r.jsx)(eE.A,{className:"w-3.5 h-3.5","aria-hidden":!0}),"Add section"]})]}),u.custom.length>0&&(0,r.jsx)("div",{className:"space-y-3",children:u.custom.map((e,t)=>{let a=eF.some(t=>t.title.toLowerCase()===e.title.trim().toLowerCase()),n=!e.title.trim(),l=a||n;return(0,r.jsxs)("div",{className:"rounded-lg border p-3 bg-[var(--bg-primary)] ".concat(l?"border-amber-accent/40":"border-[var(--border)]"),children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,r.jsx)("input",{type:"text",value:e.title,onChange:e=>C(t,{title:e.target.value}),placeholder:"Section title",className:"flex-1 bg-transparent border-0 border-b-2 px-1 py-1 text-[13px] font-bold uppercase tracking-widest text-[var(--text-primary)] outline-none focus:border-[var(--accent)] transition-colors ".concat(l?"border-amber-accent/60":"border-[var(--border)]")}),(0,r.jsx)("button",{type:"button",onClick:()=>{x(e=>({...e,custom:e.custom.filter((e,a)=>a!==t)}))},className:"btn btn-icon-sm text-[var(--text-secondary)] hover:text-[var(--danger)]","aria-label":"Delete section ".concat(e.title),title:"Delete this section",children:(0,r.jsx)(eP.A,{className:"w-3.5 h-3.5","aria-hidden":!0})})]}),l&&(0,r.jsx)("p",{className:"text-[10px] text-amber-accent mb-2",children:n?"Give this section a title, or it will be lost on save.":'Title collides with the required "'.concat(e.title.trim(),'" section - pick a different name.')}),(0,r.jsx)("textarea",{value:e.body,onChange:e=>C(t,{body:e.target.value}),placeholder:"Section content",rows:Math.max(2,e.body.split("\n").length+1),className:"w-full bg-[var(--bg-secondary)] border border-[var(--border)] rounded-md px-3 py-2 text-sm text-[var(--text-primary)] outline-none focus:border-[var(--accent)]/50 font-mono resize-y placeholder:text-[var(--text-secondary)]/60"})]},t)})})]})]})})]})}var eI=a(91665),eO=a(62625);function eU(e){let t=new Date(e);return{day:t.toLocaleDateString(void 0,{weekday:"short",month:"short",day:"numeric"}),time:t.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"})}}function eH(){let[e,t]=(0,n.useState)(null),[a,l]=(0,n.useState)(null),[s,o]=(0,n.useState)(!0);if((0,n.useEffect)(()=>{let e=!1;return(async()=>{try{let a=await fetch("/api/welcome");if(!a.ok)throw Error("HTTP ".concat(a.status));let r=await a.json();e||t(r)}catch(t){var a;e||l(null!=(a=null==t?void 0:t.message)?a:"Failed to load welcome")}finally{e||o(!1)}})(),()=>{e=!0}},[]),s)return(0,r.jsx)("div",{className:"h-full flex items-center justify-center animate-fade-in",children:(0,r.jsxs)("div",{className:"w-full max-w-2xl px-8 space-y-4",children:[(0,r.jsx)("div",{className:"skeleton h-8 w-2/3"}),(0,r.jsx)("div",{className:"skeleton h-4 w-1/2"}),(0,r.jsx)("div",{className:"skeleton h-20 w-full"}),(0,r.jsx)("div",{className:"skeleton h-20 w-full"})]})});if(a||!e)return(0,r.jsx)("div",{className:"h-full flex items-center justify-center text-[var(--text-secondary)] p-6",children:(0,r.jsx)("div",{className:"text-center max-w-md",children:(0,r.jsxs)("p",{className:"text-sm",children:["Couldn't load your briefing",a?": ".concat(a):"","."]})})});let i=e.conflicts.length>0,c=e.upcoming.length>0,d=e.profile.exists&&(e.profile.emptySections.length>0||null!=e.profile.daysSinceUpdate&&e.profile.daysSinceUpdate>=30);return(0,r.jsx)("div",{className:"h-full overflow-auto animate-fade-in bg-[var(--bg-primary)]",children:(0,r.jsxs)("div",{className:"max-w-3xl mx-auto px-6 py-10 space-y-8",children:[(0,r.jsxs)("header",{className:"flex items-start gap-5",children:[(0,r.jsx)("div",{className:"shrink-0 w-16 h-16 rounded-2xl bg-gradient-to-br from-[var(--accent-soft)] to-[var(--bg-secondary)] border border-[var(--border)] flex items-center justify-center",children:(0,r.jsx)(p.A,{className:"w-8 h-8 text-[var(--accent)]","aria-hidden":!0})}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsxs)("h1",{className:"text-2xl font-bold tracking-tight text-[var(--text-primary)]",children:[function(){let e=new Date().getHours();return e<5?"Working late":e<12?"Good morning":e<18?"Good afternoon":"Good evening"}(),e.profile.name?(0,r.jsxs)(r.Fragment,{children:[", ",(0,r.jsx)("span",{className:"text-[var(--accent)]",children:e.profile.name})]}):"","."]}),(0,r.jsx)("p",{className:"mt-1 text-sm text-[var(--text-secondary)]",children:new Date(e.today+"T00:00:00Z").toLocaleDateString(void 0,{weekday:"long",year:"numeric",month:"long",day:"numeric"})})]})]}),i&&(0,r.jsxs)("section",{className:"rounded-xl border border-[var(--danger)]/40 bg-[var(--danger)]/5 overflow-hidden",children:[(0,r.jsxs)("header",{className:"flex items-center gap-3 px-4 py-3 border-b border-[var(--danger)]/30 bg-[var(--danger)]/10",children:[(0,r.jsx)("div",{className:"shrink-0 w-9 h-9 rounded-lg bg-[var(--danger)]/15 text-[var(--danger)] flex items-center justify-center",children:(0,r.jsx)(x.A,{className:"w-4 h-4","aria-hidden":!0})}),(0,r.jsxs)("div",{className:"flex-1",children:[(0,r.jsxs)("h2",{className:"text-[13px] font-bold uppercase tracking-widest text-[var(--text-primary)]",children:["Calendar conflicts ",(0,r.jsxs)("span",{className:"ml-1 text-[var(--text-secondary)] font-normal normal-case tracking-normal",children:["(",e.conflicts.length,")"]})]}),(0,r.jsx)("p",{className:"mt-0.5 text-[12px] text-[var(--text-secondary)]",children:"Overlaps or buffer violations in the next 7 days."})]})]}),(0,r.jsx)("ul",{className:"divide-y divide-[var(--border)]",children:e.conflicts.map((e,t)=>{let a=eU(e.event_a.starts_at),n=eU(e.event_b.starts_at);return(0,r.jsxs)("li",{className:"px-4 py-3 text-sm",children:[(0,r.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,r.jsx)("span",{className:"text-[10px] uppercase tracking-widest text-[var(--danger)] font-bold",children:e.kind.replace(/_/g," ")}),(0,r.jsx)("span",{className:"text-[11px] text-[var(--text-secondary)]",children:e.reason})]}),(0,r.jsxs)("div",{className:"mt-1 text-[var(--text-primary)]",children:[(0,r.jsx)("span",{className:"font-medium",children:e.event_a.title}),(0,r.jsxs)("span",{className:"text-[var(--text-secondary)]",children:[" \xb7 ",a.day," ",a.time," \xb7 ",e.event_a.entity_name]})]}),(0,r.jsxs)("div",{className:"text-[var(--text-primary)]",children:[(0,r.jsx)("span",{className:"font-medium",children:e.event_b.title}),(0,r.jsxs)("span",{className:"text-[var(--text-secondary)]",children:[" \xb7 ",n.day," ",n.time," \xb7 ",e.event_b.entity_name]})]})]},t)})})]}),(0,r.jsxs)("section",{className:"rounded-xl border border-[var(--border)] bg-[var(--bg-secondary)]/60 overflow-hidden",children:[(0,r.jsxs)("header",{className:"flex items-center gap-3 px-4 py-3 border-b border-[var(--border)]",children:[(0,r.jsx)("div",{className:"shrink-0 w-9 h-9 rounded-lg bg-[var(--accent-soft)] text-[var(--accent)] flex items-center justify-center",children:(0,r.jsx)(I.A,{className:"w-4 h-4","aria-hidden":!0})}),(0,r.jsxs)("div",{className:"flex-1",children:[(0,r.jsx)("h2",{className:"text-[13px] font-bold uppercase tracking-widest text-[var(--text-primary)]",children:"Upcoming (next 7 days)"}),(0,r.jsx)("p",{className:"mt-0.5 text-[12px] text-[var(--text-secondary)]",children:c?"".concat(e.upcoming.length," event").concat(1===e.upcoming.length?"":"s"," in view."):"No scheduled events."})]})]}),c?(0,r.jsx)("ul",{className:"divide-y divide-[var(--border)]",children:e.upcoming.map(e=>{let t=eU(e.starts_at),a=eU(e.ends_at);return(0,r.jsxs)("li",{className:"px-4 py-3 flex items-start gap-3 hover:bg-[var(--bg-primary)]/50 transition-colors",children:[(0,r.jsxs)("div",{className:"shrink-0 w-14 text-center pt-0.5",children:[(0,r.jsx)("div",{className:"text-[10px] uppercase tracking-widest text-[var(--text-secondary)] font-bold",children:t.day.split(" ")[0]}),(0,r.jsx)("div",{className:"text-lg font-semibold leading-none text-[var(--text-primary)]",children:t.day.split(" ")[2]})]}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsx)("div",{className:"text-sm font-medium text-[var(--text-primary)] truncate",children:e.title}),(0,r.jsxs)("div",{className:"mt-0.5 flex items-center gap-2 text-[11px] text-[var(--text-secondary)]",children:[(0,r.jsx)(eI.A,{className:"w-3 h-3","aria-hidden":!0}),(0,r.jsxs)("span",{children:[t.time,"–",a.time]}),(0,r.jsx)("span",{className:"text-[var(--border)]",children:"\xb7"}),(0,r.jsx)("span",{children:e.entity_name})]})]})]},e.id)})}):(0,r.jsxs)("div",{className:"px-4 py-6 text-center text-[12px] text-[var(--text-secondary)]",children:["Nothing on the calendar. Add events via ",(0,r.jsx)("code",{className:"text-[var(--text-primary)]",children:"calendar_add_event"}),"."]})]}),d&&(0,r.jsxs)("section",{className:"rounded-xl border border-amber-accent/30 bg-amber-accent/5 p-4 flex items-start gap-3",children:[(0,r.jsx)("div",{className:"shrink-0 w-9 h-9 rounded-lg bg-amber-accent/10 text-amber-accent flex items-center justify-center",children:(0,r.jsx)(z.A,{className:"w-4 h-4","aria-hidden":!0})}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsx)("h3",{className:"text-[13px] font-bold uppercase tracking-widest text-[var(--text-primary)]",children:"Keep your profile current"}),(0,r.jsxs)("p",{className:"mt-1 text-[12px] text-[var(--text-secondary)]",children:[e.profile.emptySections.length>0&&(0,r.jsxs)(r.Fragment,{children:["The agent uses your profile to honor coding style and name people correctly. ",(0,r.jsxs)("span",{className:"text-[var(--text-primary)]",children:[e.profile.emptySections.length," section",1===e.profile.emptySections.length?"":"s"," still empty"]}),": ",e.profile.emptySections.join(", "),"."]}),0===e.profile.emptySections.length&&null!=e.profile.daysSinceUpdate&&e.profile.daysSinceUpdate>=30&&(0,r.jsxs)(r.Fragment,{children:["Your profile hasn't been updated in ",e.profile.daysSinceUpdate," days."]})]}),(0,r.jsxs)("p",{className:"mt-2 text-[11px] text-[var(--text-secondary)] inline-flex items-center gap-1",children:["Open ",(0,r.jsx)("code",{className:"text-[var(--text-primary)]",children:"knowledge/profile.md"})," in the sidebar to edit",(0,r.jsx)(eO.A,{className:"w-3 h-3","aria-hidden":!0})]})]})]}),!e.profile.exists&&(0,r.jsxs)("section",{className:"rounded-xl border border-[var(--border)] bg-[var(--bg-secondary)]/60 p-4 flex items-start gap-3",children:[(0,r.jsx)("div",{className:"shrink-0 w-9 h-9 rounded-lg bg-[var(--accent-soft)] text-[var(--accent)] flex items-center justify-center",children:(0,r.jsx)(z.A,{className:"w-4 h-4","aria-hidden":!0})}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsx)("h3",{className:"text-[13px] font-bold uppercase tracking-widest text-[var(--text-primary)]",children:"Set up your profile"}),(0,r.jsx)("p",{className:"mt-1 text-[12px] text-[var(--text-secondary)]",children:"Kontexta hands your profile to the agent on every session start: coding rules, roadmap, team roster. Create one to make sessions consistent."})]})]})]})})}var eG=a(29518);function ez(e){let{fileId:t,onSelectFile:a}=e,[l,s]=(0,n.useState)([]),[o,c]=(0,n.useState)(!0),[d,u]=(0,n.useState)(null),[x,h]=(0,n.useState)(!0);return((0,n.useEffect)(()=>{let e=!1;return c(!0),u(null),(async()=>{var a,r;try{let r=await fetch("/api/files/".concat(t,"/backlinks"));if(!r.ok)throw Error("HTTP ".concat(r.status));let n=await r.json();e||s(null!=(a=n.backlinks)?a:[])}catch(t){e||u(null!=(r=null==t?void 0:t.message)?r:"Failed to load backlinks")}finally{e||c(!1)}})(),()=>{e=!0}},[t]),o)?(0,r.jsx)("div",{className:"border-t border-[var(--border)] px-6 py-4",children:(0,r.jsx)("div",{className:"skeleton h-4 w-32"})}):d||0===l.length?null:(0,r.jsxs)("div",{className:"border-t border-[var(--border)] bg-[var(--bg-secondary)]/40",children:[(0,r.jsxs)("button",{type:"button",onClick:()=>h(e=>!e),className:"w-full flex items-center gap-2 px-6 py-3 text-left hover:bg-[var(--bg-secondary)]/60 transition-colors","aria-expanded":x,children:[(0,r.jsx)(O.A,{className:"w-3.5 h-3.5 shrink-0 transition-transform text-[var(--text-secondary)] ".concat(x?"":"-rotate-90"),"aria-hidden":!0}),(0,r.jsx)(eG.A,{className:"w-3.5 h-3.5 shrink-0 text-[var(--accent)]","aria-hidden":!0}),(0,r.jsx)("span",{className:"text-[11px] font-bold uppercase tracking-widest text-[var(--text-primary)]",children:"Referenced by"}),(0,r.jsx)("span",{className:"text-[11px] text-[var(--text-secondary)] font-mono",children:l.length})]}),x&&(0,r.jsx)("ul",{className:"divide-y divide-[var(--border)]",children:l.map(e=>{var t;return(0,r.jsx)("li",{children:(0,r.jsx)("button",{type:"button",onClick:()=>a(e.id),className:"w-full text-left px-6 py-3 hover:bg-[var(--bg-secondary)] transition-colors group",children:(0,r.jsxs)("div",{className:"flex items-start gap-3",children:[(0,r.jsx)(i.A,{className:"w-3.5 h-3.5 shrink-0 mt-0.5 text-[var(--text-secondary)] group-hover:text-[var(--accent)]","aria-hidden":!0}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,r.jsx)("span",{className:"text-[13px] font-medium text-[var(--text-primary)] truncate",children:e.title}),(0,r.jsx)("span",{className:"text-[10px] uppercase tracking-widest text-[var(--text-secondary)]/70 font-semibold shrink-0",children:"title"===(t=e.reason)?"title mention":"basename"===t?"path mention":"wikilink"})]}),e.snippet&&(0,r.jsx)("p",{className:"mt-1 text-[12px] text-[var(--text-secondary)] leading-relaxed line-clamp-2",children:e.snippet.split(/<<<|>>>/).map((e,t)=>t%2==1?(0,r.jsx)("mark",{className:"bg-[var(--accent-soft)] text-[var(--accent)] px-0.5 rounded-sm",children:e},t):(0,r.jsx)("span",{children:e},t))})]})]})})},e.id)})})]})}function eB(e){let{open:t,title:a,onClose:n,onConfirm:l,loading:s}=e;return(0,r.jsx)(em.T,{open:t,onClose:n,onConfirm:l,title:"Delete file",message:(0,r.jsxs)(r.Fragment,{children:['Delete "',(0,r.jsx)("span",{className:"font-bold text-[var(--text-primary)]",children:a}),'"? Knowledge Base files are recoverable from git history (Time Travel). Project files are only removed from the index. The file on disk is untouched.']}),confirmLabel:"Delete",destructive:!0,loading:s})}function eW(e){let{open:t,onClose:a,title:n,body:l,detail:s}=e;return(0,r.jsxs)(eu.l,{open:t,onClose:a,title:n,children:[(0,r.jsx)("p",{className:"text-sm text-[var(--text-primary)] mb-4 leading-relaxed",children:l}),s&&(0,r.jsxs)("div",{className:"bg-[var(--danger-soft)] border border-[var(--danger)]/20 rounded-lg p-4 mb-6",children:[(0,r.jsx)("p",{className:"text-[11px] text-[var(--danger)] uppercase tracking-tighter font-bold mb-2 opacity-70",children:"Detail:"}),(0,r.jsx)("pre",{className:"text-[12px] font-mono text-[var(--danger)] whitespace-pre-wrap break-words leading-tight overflow-x-auto max-h-48 custom-scrollbar",children:s})]}),(0,r.jsx)("div",{className:"flex justify-end",children:(0,r.jsx)("button",{onClick:a,className:"btn btn-md btn-destructive",children:"Got it"})})]})}let eK=e=>{let{className:t}=e;return(0,r.jsxs)("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[(0,r.jsx)("path",{d:"M3 6h18"}),(0,r.jsx)("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),(0,r.jsx)("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"})]})},eJ=e=>{let{className:t}=e;return(0,r.jsxs)("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[(0,r.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,r.jsx)("polyline",{points:"7 10 12 15 17 10"}),(0,r.jsx)("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})};function eq(e,t,a){let r=new Blob([e],{type:a}),n=URL.createObjectURL(r),l=document.createElement("a");l.href=n,l.download=t,document.body.appendChild(l),l.click(),l.remove(),URL.revokeObjectURL(n)}let eV=e=>{let{filled:t,className:a}=e;return(0,r.jsx)("svg",{viewBox:"0 0 24 24",fill:t?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:a,children:(0,r.jsx)("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})})};function e$(e){var t,l;let{fileId:s,onDelete:o,onChanged:i,onDirtyChange:c,onNavigateToFile:u}=e,[h,m]=(0,n.useState)(null),[p,f]=(0,n.useState)(null),[b,v]=(0,n.useState)(!1),[g,j]=(0,n.useState)(!1),[y,w]=(0,n.useState)([]),[N,k]=(0,n.useState)(!1),[S,C]=(0,n.useState)(""),[T,_]=(0,n.useState)(!1),[E,P]=(0,n.useState)(!1),[F,L]=(0,n.useState)(!1),[R,M]=(0,n.useState)(!1),[D,I]=(0,n.useState)(!1),[O,H]=(0,n.useState)(""),[G,z]=(0,n.useState)(""),[B,W]=(0,n.useState)(void 0),[K,J]=(0,n.useState)(!1),[V,$]=(0,n.useState)(!1),[Y,Z]=(0,n.useState)(!1),X=()=>((null==h?void 0:h.title)||"untitled").replace(/\.(md|mmd|html)$/i,""),Q=async()=>{if(!h)return;let[{unified:e},{default:t},{default:r},{default:n},{default:l}]=await Promise.all([a.e(2443).then(a.bind(a,2443)),a.e(5858).then(a.bind(a,95858)),a.e(245).then(a.bind(a,50245)),a.e(1108).then(a.bind(a,11108)),a.e(3685).then(a.bind(a,43685))]);eq(String(await e().use(t).use(r).use(l,{keep:["code","inlineCode","table","tableCell"]}).use(n).process(h.content)),"".concat(X(),".txt"),"text/plain"),d.o.success("Exported text")},[ee,et]=(0,n.useState)(!1),[ea,er]=(0,n.useState)(!1),en=!!(null==h?void 0:h.path.endsWith(".html")),el=async(e,t,a,r)=>{r(!0);let n=d.o.loading("Generating ".concat(a,"…"));try{var l;let r=await fetch(e);if(!r.ok){let e=await r.text(),t="Failed to export ".concat(a," (HTTP ").concat(r.status,")");try{let a=JSON.parse(e);(null==a?void 0:a.error)&&(t=a.error)}catch(t){console.error("[export-".concat(a,"] non-JSON error response:"),e)}d.o.error(t,{id:n});return}let s=r.headers.get("content-disposition")||"",o=/filename="([^"]+)"/.exec(s),i=null!=(l=null==o?void 0:o[1])?l:t,c=await r.blob(),u=URL.createObjectURL(c),x=document.createElement("a");x.href=u,x.download=i,document.body.appendChild(x),x.click(),x.remove(),URL.revokeObjectURL(u),d.o.success("Exported ".concat(a),{id:n})}catch(e){console.error("[export-".concat(a,"] request failed:"),e),d.o.error("Failed to export ".concat(a,". Check the browser console for details."),{id:n})}finally{r(!1)}},es=()=>{h&&el(en?"/api/files/".concat(h.id,"/export-html?format=pdf"):"/api/files/".concat(h.id,"/export-pdf"),"".concat(X(),".pdf"),"PDF",et)},eo=async()=>{if(s){J(!0);try{let e=await fetch("/api/files/".concat(s));if(e.ok){let t=await e.json();m(t),C(t.content)}else d.o.error("Failed to refresh file (HTTP ".concat(e.status,")"))}catch(t){var e;d.o.error("Failed to refresh file: ".concat(null!=(e=null==t?void 0:t.message)?e:"Network error"))}finally{J(!1)}}},ei=(0,n.useRef)(s);(0,n.useEffect)(()=>{ei.current=s},[s]);let ec=(0,n.useRef)(c);(0,n.useEffect)(()=>{ec.current=c},[c]);let[ed,eu]=(0,n.useState)(!1);(0,n.useEffect)(()=>{var e;let t=b&&null!=h&&S!==h.content||Y&&ed,a="file:".concat(s);return null==(e=ec.current)||e.call(ec,a,t),()=>{var e;return null==(e=ec.current)?void 0:e.call(ec,a,!1)}},[s,b,S,null==h?void 0:h.content,Y,ed]);let ex=(0,n.useCallback)(e=>{var t;return null==(t=ec.current)?void 0:t.call(ec,"profile",e)},[]);(0,n.useEffect)(()=>{if(null===s){m(null),f(null),v(!1),j(!1);return}v(!1),j(!1),Z(!1);let e=new AbortController;return(async()=>{var t,a,r;_(!0),f(null);try{let r=await fetch("/api/files/".concat(s),{signal:e.signal});if(ei.current!==s)return;if(r.ok){let e=await r.json();if(ei.current!==s)return;m(e),C(e.content)}else{let e=null;try{e=await r.json()}catch(e){}if(ei.current!==s)return;m(null),f({kind:null!=(t=null==e?void 0:e.kind)?t:"http",message:null!=(a=null==e?void 0:e.error)?a:"Request failed with HTTP ".concat(r.status),status:r.status,path:null==e?void 0:e.path})}}catch(e){if((null==e?void 0:e.name)==="AbortError"||(console.error("Failed to fetch file:",e),ei.current!==s))return;m(null),f({kind:"network",message:null!=(r=null==e?void 0:e.message)?r:"Network error"})}finally{ei.current===s&&_(!1)}})(),j(!1),()=>e.abort()},[s]);let[eh,em]=(0,n.useState)(!1),ep=async e=>{var t,a;if(h&&!eh&&h.content_class!==e){em(!0);try{let a=await fetch("/api/files/".concat(h.id,"/move"),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({kind:e})});if(!a.ok){let e=await a.json().catch(()=>({}));d.o.error(null!=(t=null==e?void 0:e.error)?t:"Move failed: HTTP ".concat(a.status));return}let r=await a.json();m(e=>{var t;return e?{...e,path:r.path,content_class:null!=(t=r.content_class)?t:null}:e}),null==i||i(),d.o.success("Moved to ".concat("dictionary"===e?"dictionary":"notes"))}catch(e){d.o.error("Move failed: ".concat(null!=(a=null==e?void 0:e.message)?a:"network error"))}finally{em(!1)}}},ey=async()=>{var e,t;if(null!=s){$(!0);try{let t=await fetch("/api/files/".concat(s),{method:"DELETE"});if(t.ok)f(null),m(null),o(s).catch(e=>console.error("onDelete after orphan remove failed:",e)),null==i||i();else{let a=await t.json().catch(()=>({}));f({kind:"http",message:null!=(e=null==a?void 0:a.error)?e:"Remove failed: HTTP ".concat(t.status),status:t.status})}}catch(e){f({kind:"network",message:null!=(t=null==e?void 0:e.message)?t:"Network error while removing orphan row"})}finally{$(!1)}}},ew=async()=>{if(s){k(!0);try{let e=await fetch("/api/files/".concat(s,"/history"));if(e.ok){let t=await e.json();if(ei.current!==s)return;w(t)}}catch(e){console.error("Failed to fetch history:",e)}finally{ei.current===s&&k(!1)}}},eN=async e=>{if(s)try{let t=await fetch("/api/files/".concat(s,"/history/restore"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({hash:e})});if(t.ok){let e=await t.json();if(ei.current!==s)return;m(t=>t&&t.id===s?{...t,content:e.content}:t),C(e.content),j(!1),d.o.success("Restored from history")}else{let e=await t.json().catch(()=>({}));d.o.error((null==e?void 0:e.error)||"Failed to restore version")}}catch(e){var t;d.o.error("Failed to restore version: ".concat(null!=(t=null==e?void 0:e.message)?t:"Network error"))}},ek=()=>{v(!1),C((null==h?void 0:h.content)||"")},eS=async()=>{var e,t,a;if(!h)return;let r=h.id;try{P(!0);let a=await fetch("/api/files/".concat(r),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:S,expected_updated_at:h.updated_at})});if(a.ok){let e=await a.json();if(ei.current!==r){e.git_warning&&console.warn("[kontexta] git_warning for stale file ".concat(r,":"),e.git_warning);return}m(e),v(!1),d.o.success("Saved"),e.git_warning&&(H("Git commit failed"),z("Your changes were saved to the database, but Kontexta could not create a Git history entry for this file."),W(e.git_warning),I(!0))}else if(409===a.status){let n,l;try{let r=await a.json();n=null==r||null==(e=r.current)?void 0:e.content,l=null==r||null==(t=r.current)?void 0:t.updated_at}catch(e){}ei.current===r&&(void 0!==n&&void 0!==l&&m(e=>e?{...e,content:n,updated_at:l}:e),H("File changed on disk"),z("This file was NOT saved. It was modified elsewhere since you opened it. Disk content has been reloaded below; your edits are still in the editor. Click Save again to overwrite with your edits."),W(void 0),I(!0))}else{let e="Save failed (".concat(a.status,")");try{let t=await a.json();(null==t?void 0:t.error)&&(e=t.error)}catch(e){}ei.current===r&&(H("Save failed"),z("Your changes were NOT saved."),W(e),I(!0))}}catch(e){console.error("Failed to save file:",e),ei.current===r&&(H("Save failed"),z("Your changes were NOT saved. A network error occurred."),W(null!=(a=null==e?void 0:e.message)?a:"Network error while saving"),I(!0))}finally{ei.current===r&&P(!1)}},eC=async()=>{if(h){M(!0);try{await o(h.id),m(null),L(!1)}finally{M(!1)}}};if(!s)return(0,r.jsx)(eH,{});if(T)return(0,r.jsxs)("div",{className:"h-full flex flex-col animate-fade-in",children:[(0,r.jsxs)("div",{className:"border-b border-[var(--border)] px-6 py-4",children:[(0,r.jsx)("div",{className:"skeleton h-6 w-48 mb-2"}),(0,r.jsx)("div",{className:"skeleton h-4 w-32"})]}),(0,r.jsxs)("div",{className:"flex-1 p-6 space-y-4",children:[(0,r.jsx)("div",{className:"skeleton h-4 w-full"}),(0,r.jsx)("div",{className:"skeleton h-4 w-5/6"}),(0,r.jsx)("div",{className:"skeleton h-4 w-4/6"}),(0,r.jsx)("div",{className:"skeleton h-4 w-full"}),(0,r.jsx)("div",{className:"skeleton h-4 w-3/4"})]})]});if(!h)return(null==p?void 0:p.kind)==="disk_missing"?(0,r.jsxs)("div",{className:"h-full flex flex-col items-center justify-center text-[var(--text-secondary)] gap-4 animate-fade-in p-8",children:[(0,r.jsx)(x.A,{className:"w-16 h-16 opacity-40 dark-icon","aria-hidden":!0}),(0,r.jsxs)("div",{className:"text-center max-w-lg",children:[(0,r.jsx)("p",{className:"text-lg font-bold text-[var(--text-primary)]",children:"File is missing on disk"}),(0,r.jsx)("p",{className:"text-sm font-medium text-[var(--text-secondary)] mt-2",children:"The index still has a row for this file, but the file at the path below no longer exists. This usually happens when the file was deleted while the watcher wasn't running."}),p.path&&(0,r.jsx)("pre",{className:"mt-3 p-2 bg-[var(--bg-tertiary)] text-[var(--text-primary)] text-xs overflow-x-auto rounded",children:p.path}),(0,r.jsx)("button",{type:"button",className:"btn btn-sm mt-4",onClick:ey,disabled:V,children:V?"Removing…":"Remove from index"})]})]}):p?(0,r.jsxs)("div",{className:"h-full flex flex-col items-center justify-center text-[var(--text-secondary)] gap-3 animate-fade-in p-8",children:[(0,r.jsx)(x.A,{className:"w-16 h-16 opacity-40 dark-icon","aria-hidden":!0}),(0,r.jsxs)("div",{className:"text-center max-w-lg",children:[(0,r.jsxs)("p",{className:"text-lg font-bold text-[var(--text-primary)]",children:["Failed to load file",p.status?" (HTTP ".concat(p.status,")"):""]}),(0,r.jsx)("p",{className:"text-sm font-medium text-[var(--text-secondary)] mt-2 break-words",children:p.message})]})]}):(0,r.jsx)("div",{className:"h-full flex flex-col items-center justify-center animate-fade-in",children:(0,r.jsx)(q.p,{icon:(0,r.jsx)(U.A,{className:"w-16 h-16 opacity-40 dark-icon","aria-hidden":!0}),title:"File not found",hint:"This file may have been moved or deleted"})});let eT=h.path.replace(/\\/g,"/");if(null===h.project_id&&/(^|\/)knowledge\/profile\.md$/.test(eT))return(0,r.jsx)("div",{className:"h-full flex flex-col",children:(0,r.jsx)(eD,{onDirtyChange:ex,onChanged:i})},s);let eA=null===h.project_id&&/\/knowledge\/(html|knowledge)\/publish\//.test(eT);return(0,r.jsxs)("div",{className:"h-full flex flex-col animate-fade-in",children:[(0,r.jsxs)("div",{className:"h-10 px-4 border-b border-[var(--border)] flex items-center gap-4 text-[14px] sticky top-0 bg-[var(--bg-primary)] z-10",children:[["view","edit","history"].filter(e=>"edit"!==e||!h.path.endsWith(".html")&&!eA).map(e=>{let t="view"===e&&!b&&!g||"edit"===e&&b||"history"===e&&g;return(0,r.jsx)("button",{onClick:()=>{if("edit"===e){b||(v(!0),C((null==h?void 0:h.content)||""));return}b&&ek(),j("history"===e),"history"===e&&ew()},className:"btn btn-sm -mb-px py-2 border-b-2 transition-colors ".concat(t?"border-[var(--accent)]":""),children:e[0].toUpperCase()+e.slice(1)},e)}),eA&&(0,r.jsx)("span",{className:"inline-flex items-center px-2 py-0.5 rounded bg-amber-accent/10 border border-amber-accent/30 text-[10px] text-[var(--text-primary)] uppercase tracking-wider font-bold",title:"Regenerated on publish",children:"Read-only"}),null===h.project_id&&/\/knowledge\/knowledge\/(dictionary|notes|urlclips)\//.test(eT)&&(0,r.jsxs)("div",{className:"inline-flex items-center rounded-full border border-[var(--border)] bg-[var(--bg-secondary)] p-0.5 text-[10px] transition-opacity ".concat(eh?"opacity-60":""),role:"group","aria-label":"Content class",children:[(0,r.jsx)("button",{type:"button",onClick:()=>ep("dictionary"),disabled:eh||"dictionary"===h.content_class,"aria-pressed":"dictionary"===h.content_class,className:"px-2.5 py-0.5 rounded-full uppercase tracking-wider font-bold transition-all ".concat("dictionary"===h.content_class?"bg-amber-accent text-[var(--bg-primary)] cursor-default":"text-[var(--text-secondary)] hover:text-[var(--text-primary)] cursor-pointer"),title:"Authoritative: trusted over notes on conflict",children:"Dictionary"}),(0,r.jsx)("button",{type:"button",onClick:()=>ep("note"),disabled:eh||"note"===h.content_class,"aria-pressed":"note"===h.content_class,className:"px-2.5 py-0.5 rounded-full uppercase tracking-wider font-bold transition-all ".concat("note"===h.content_class?"bg-amber-accent text-[var(--bg-primary)] cursor-default":"text-[var(--text-secondary)] hover:text-[var(--text-primary)] cursor-pointer"),title:"Informational",children:"Note"})]}),(0,r.jsx)("div",{className:"ml-auto flex items-center gap-3 text-[12px] text-[var(--text-secondary)] font-mono",children:b?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{onClick:eS,disabled:E,className:"btn btn-md",children:E?"Saving...":"Save"}),(0,r.jsx)("button",{onClick:ek,disabled:E,className:"btn btn-md",children:"Cancel"})]}):(0,r.jsxs)(r.Fragment,{children:[(null==h?void 0:h.updated_at)&&(0,r.jsxs)("span",{children:["edited ",function(e){if(!e)return"";let t=new Date(e).getTime();if(!isFinite(t))return e;let a=Math.floor((Date.now()-t)/1e3);return a<60?"".concat(a,"s ago"):a<3600?"".concat(Math.floor(a/60),"m ago"):a<86400?"".concat(Math.floor(a/3600),"h ago"):"".concat(Math.floor(a/86400),"d ago")}(h.updated_at)]}),(null==h?void 0:h.content)&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"text-[var(--border)]",children:"\xb7"}),(0,r.jsxs)("span",{title:"~".concat(Math.max(1,Math.ceil(h.content.length/4)).toLocaleString()," tokens (heuristic: chars/4)"),children:["~",(l=Math.max(1,Math.ceil(h.content.length/4)))<1e3?String(l):l<1e4?"".concat((l/1e3).toFixed(1),"k"):l<1e6?"".concat(Math.round(l/1e3),"k"):"".concat((l/1e6).toFixed(1),"M")," tok"]})]}),(0,r.jsx)("button",{onClick:eo,disabled:K,className:"btn btn-md","aria-label":"Refresh file",title:"Refresh file content",children:(0,r.jsxs)("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"w-4 h-4 opacity-70 ".concat(K?"animate-spin":""),children:[(0,r.jsx)("path",{d:"M21 2v6h-6"}),(0,r.jsx)("path",{d:"M3 12a9 9 0 0 1 15-6.7L21 8"}),(0,r.jsx)("path",{d:"M3 22v-6h6"}),(0,r.jsx)("path",{d:"M21 12a9 9 0 0 1-15 6.7L3 16"})]})}),h.path.endsWith(".html")&&!eA&&(0,r.jsx)("button",{type:"button",onClick:()=>Z(!0),className:"btn btn-md","aria-label":"Edit HTML source",title:"Edit HTML source",children:(0,r.jsx)("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"w-4 h-4 opacity-70",children:(0,r.jsx)("path",{d:"M17 3a2.83 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})})}),(0,r.jsx)("button",{onClick:async()=>{if(!h)return;let e=!h.favorite;m({...h,favorite:e});try{if(!(await fetch("/api/files/".concat(h.id),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({favorite:e})})).ok)throw Error("PATCH failed");null==i||i()}catch(a){var t;m({...h,favorite:!e}),d.o.error("Failed to update favorite: ".concat(null!=(t=null==a?void 0:a.message)?t:"Network error"))}},className:"btn btn-md","aria-label":(null==h?void 0:h.favorite)?"Unfavorite":"Favorite",title:(null==h?void 0:h.favorite)?"Remove from favorites":"Add to favorites",children:(0,r.jsx)(eV,{filled:!!(null==h?void 0:h.favorite),className:"w-4 h-4 ".concat((null==h?void 0:h.favorite)?"text-amber-accent":"opacity-60")})}),(0,r.jsx)(A,{trigger:(0,r.jsx)("button",{disabled:ee||ea,className:"btn btn-md","aria-label":"Export file",title:ee?"Generating PDF…":ea?"Generating PNG…":"Export file",children:(0,r.jsx)(eJ,{className:"w-4 h-4 opacity-70 ".concat(ee||ea?"animate-pulse":"")})}),items:en?[{label:"PDF",onSelect:es},{label:"PNG",onSelect:()=>{h&&el("/api/files/".concat(h.id,"/export-html?format=png"),"".concat(X(),".png"),"PNG",er)}}]:[{label:"Markdown (.md)",onSelect:()=>{h&&(eq(h.content,"".concat(X(),".md"),"text/markdown"),d.o.success("Exported Markdown"))}},{label:"Text (.txt)",onSelect:()=>{Q()}},{label:"PDF",onSelect:es}]}),(0,r.jsx)("button",{onClick:()=>L(!0),className:"btn btn-md btn-destructive","aria-label":"Delete file",title:"Delete file",children:(0,r.jsx)(eK,{className:"w-4 h-4 opacity-70"})})]})})]}),!b&&!g&&(0,r.jsxs)("div",{className:"px-4 py-2 border-b border-[var(--border)] flex flex-wrap items-center gap-2 text-[12px]",children:[(0,r.jsx)("span",{className:"text-[var(--text-secondary)] uppercase tracking-wider text-[10px] font-bold",children:"Tags"}),(null!=(t=null==h?void 0:h.tags)?t:[]).map(e=>(0,r.jsxs)("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded bg-amber-accent/10 border border-amber-accent/30 text-[var(--text-primary)]",children:[e,(0,r.jsx)("button",{"aria-label":"Remove tag ".concat(e),title:"Remove tag ".concat(e),onClick:async()=>{if(!h)return;let t=h.id,a=h.tags,r=a.filter(t=>t!==e);m(e=>e&&e.id===t?{...e,tags:r}:e);try{if(!(await fetch("/api/files/".concat(t),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({tags:r})})).ok)throw Error("PATCH failed");null==i||i()}catch(e){var n;m(e=>e&&e.id===t?{...e,tags:a}:e),d.o.error("Failed to remove tag: ".concat(null!=(n=null==e?void 0:e.message)?n:"Network error"))}},className:"text-[var(--text-secondary)] hover:text-[var(--danger)]",children:"\xd7"})]},e)),(0,r.jsx)("input",{type:"text",placeholder:"add tag…",className:"bg-transparent border-b border-transparent focus:border-amber-accent/40 outline-none px-1 py-0.5 w-24",onKeyDown:async e=>{if("Enter"!==e.key||!h)return;let t=(e.currentTarget.value||"").trim();if(!t)return;let a=t.toLowerCase().replace(/\s+/g,"-");if(h.tags.includes(a)){e.currentTarget.value="";return}let r=h.id,n=h.tags,l=[...n,a];m(e=>e&&e.id===r?{...e,tags:l}:e),e.currentTarget.value="";try{if(!(await fetch("/api/files/".concat(r),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({tags:l})})).ok)throw Error("PATCH failed");null==i||i()}catch(e){var s;m(e=>e&&e.id===r?{...e,tags:n}:e),d.o.error("Failed to add tag: ".concat(null!=(s=null==e?void 0:e.message)?s:"Network error"))}}})]}),(0,r.jsx)("div",{className:"flex-1 overflow-hidden",children:b?(0,r.jsx)(ej,{content:S,onChange:C}):g?(0,r.jsx)("div",{className:"h-full overflow-auto bg-[var(--bg-secondary)] p-6",children:(0,r.jsxs)("div",{className:"max-w-2xl mx-auto space-y-4",children:[(0,r.jsx)("h3",{className:"text-sm font-bold text-[var(--text-secondary)] uppercase tracking-widest mb-6",children:"Version History (Time Travel)"}),N?(0,r.jsx)("div",{className:"space-y-4",children:[1,2,3].map(e=>(0,r.jsx)("div",{className:"skeleton h-20 w-full rounded-lg"},e))}):0===y.length?(0,r.jsx)("div",{className:"text-center py-12",children:(0,r.jsx)("p",{className:"text-[var(--muted)]",children:"No version history found for this file."})}):(0,r.jsx)("div",{className:"space-y-3",children:y.map(e=>(0,r.jsxs)("div",{className:"bg-white dark:bg-[#1a1a1a] border border-[var(--border)] rounded-lg p-4 flex items-center justify-between hover:border-amber-accent/50 transition-colors shadow-sm",children:[(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsx)("p",{className:"text-sm font-bold text-[var(--text-primary)] truncate",children:e.message}),(0,r.jsxs)("div",{className:"flex items-center gap-3 mt-1 text-[10px] text-[var(--text-secondary)] uppercase tracking-tighter font-bold",children:[(0,r.jsx)("span",{children:new Date(e.date).toLocaleString()}),(0,r.jsx)("span",{className:"opacity-30",children:"•"}),(0,r.jsx)("span",{className:"font-mono text-amber-accent",children:e.hash.substring(0,7)})]})]}),(0,r.jsx)("button",{onClick:()=>eN(e.hash),className:"ml-4 btn btn-md",children:"RESTORE"})]},e.hash))})]})}):(0,r.jsxs)("div",{className:"h-full overflow-auto",children:[h.path.endsWith(".mmd")?(0,r.jsx)(eb.q,{source:h.content,className:"p-8",filename:h.title}):h.path.endsWith(".html")?(0,r.jsx)(ev,{html:h.content}):(0,r.jsx)(ef.G,{content:h.content,className:"p-8"}),!h.path.endsWith(".mmd")&&!h.path.endsWith(".html")&&u&&(0,r.jsx)(ez,{fileId:h.id,onSelectFile:u})]})}),(0,r.jsx)(eB,{open:F,title:h.title,onClose:()=>L(!1),onConfirm:eC,loading:R}),(0,r.jsx)(eW,{open:D,onClose:()=>I(!1),title:O,body:G,detail:B}),Y&&h&&(0,r.jsx)(eg,{fileId:h.id,initial:h.content,expectedUpdatedAt:h.updated_at,onClose:()=>{Z(!1),eu(!1)},onDirtyChange:eu,onSaved:e=>{let t=h.id;if(eu(!1),ei.current!==t){e.git_warning&&console.warn("[kontexta] git_warning for stale file ".concat(t,":"),e.git_warning);return}m(e),e.git_warning&&(H("Git commit failed"),z("Your changes were saved to the database, but Kontexta could not create a Git history entry for this file."),W(e.git_warning),I(!0))}})]},s)}var eY=a(96405);let eZ="hooksBannerDismissed";function eX(e){var t,a;let{onOpen:l}=e,{state:s}=(0,eY._)(),[o,i]=(0,n.useState)(null);(0,n.useEffect)(()=>{i(sessionStorage.getItem(eZ))},[]);let c=null!=(t=null==s?void 0:s.alerts)?t:[],d=null!=(a=null==s?void 0:s.mcp_alerts)?a:[],u="".concat(c.map(e=>e.agent).sort().join(","),"|mcp:").concat(d.map(e=>e.agent).sort().join(","));if(0===c.length&&0===d.length||o===u)return null;let h=c.filter(e=>!e.installed).map(e=>e.name),m=c.filter(e=>e.installed).map(e=>e.name),p=[];return h.length>0&&p.push("Hooks not installed for ".concat(h.join(", "))),m.length>0&&p.push("No events yet from ".concat(m.join(", "))),d.length>0&&p.push("MCP not connected for ".concat(d.map(e=>e.name).join(", "))),(0,r.jsxs)("div",{role:"alert","aria-label":p.join(". "),className:"mx-4 mt-2 flex items-center gap-3 rounded-lg border border-[var(--border)] bg-[var(--accent-soft)] px-4 py-2 text-[var(--text-primary)]",children:[(0,r.jsx)(x.A,{className:"h-4 w-4 shrink-0 text-[var(--accent)]","aria-hidden":!0}),(0,r.jsxs)("p",{className:"flex-1 text-sm",children:[p.join(". "),"."]}),(0,r.jsx)("button",{className:"btn btn-sm btn-outline",onClick:l,children:d.length>0?"Set up agents":"Set up hooks"}),(0,r.jsx)("button",{className:"btn btn-icon-sm","aria-label":"Dismiss",onClick:()=>{sessionStorage.setItem(eZ,u),i(u)},children:(0,r.jsx)(H.A,{className:"h-3.5 w-3.5","aria-hidden":!0})})]})}function eQ(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,[a,r]=(0,n.useState)([]),[l,s]=(0,n.useState)(""),[o,i]=(0,n.useState)(!1);return(0,n.useEffect)(()=>{r([]),s("");let t=!1,a=new AbortController;return async function(){i(!0);try{let n=await fetch(e?"/api/folders?projectId=".concat(e):"/api/folders",{signal:a.signal});if(t)return;if(n.ok){let e=await n.json();if(t)return;r(e.folders),s(e.basePath)}}catch(e){if((null==e?void 0:e.name)==="AbortError")return;console.error("Failed to fetch folders:",e)}finally{t||i(!1)}}(),()=>{t=!0,a.abort()}},[e,t]),{folders:a,basePath:l,loading:o}}var e0=a(31144);function e1(e){let{segments:t}=e;return 0===t.length?null:(0,r.jsx)("nav",{"aria-label":"Breadcrumb",className:"h-8 px-4 flex items-center gap-1.5 text-[13px] border-b border-[var(--border)] bg-[var(--bg-tertiary)] text-[var(--text-secondary)] select-none",children:t.map((e,a)=>{let n=a===t.length-1;return(0,r.jsxs)("span",{className:"flex items-center gap-1.5",children:[a>0&&(0,r.jsx)(B.A,{className:"w-3.5 h-3.5 opacity-40","aria-hidden":!0}),n||!e.onClick?(0,r.jsx)("span",{className:n?"font-bold text-[var(--text-primary)]":"",children:e.label}):(0,r.jsx)("button",{onClick:e.onClick,className:"hover:text-[var(--accent)] transition-colors",children:e.label})]},"".concat(a,"-").concat(e.label))})})}var e2=a(7612),e5=a(48727);function e4(e){var t,a,l;let{items:o,footer:i,conflictsItem:c,unresolvedConflicts:d}=e,[u,x]=(0,n.useState)(null),[h,m]=(0,n.useState)(()=>null!=d?d:0),p=null;try{p=(0,s.useRouter)()}catch(e){}let f="";try{f=null!=(t="function"==typeof s.usePathname?(0,s.usePathname)():null)?t:""}catch(e){f=window.location.pathname||""}(0,n.useEffect)(()=>{if(void 0!==d)return void m(d);let e=!1,t=async()=>{try{let t=await fetch("/api/conflicts?status=unresolved&limit=1",{cache:"no-store"});if(t.ok){let a=await t.json();e||"number"!=typeof(null==a?void 0:a.unresolved)||m(a.unresolved)}}catch(e){}};t();let a=setInterval(()=>{"undefined"!=typeof document&&document.hidden||t()},15e3),r=()=>{t()};return window.addEventListener("kontexta:conflicts-changed",r),()=>{e=!0,clearInterval(a),window.removeEventListener("kontexta:conflicts-changed",r)}},[d]);let b=o.some(e=>"conflicts"===e.id),v={id:"conflicts",label:"Conflict Manager",active:"/conflicts"===f,onClick:()=>{try{p?p.push("/conflicts"):window.location.href="/conflicts"}catch(e){}},icon:(0,r.jsx)(e2.A,{className:"w-5 h-5",strokeWidth:2.2}),badge:h>0?h:void 0,href:"/conflicts"},g=b?null:void 0===c?v:c,j=o.some(e=>"brain"===e.id)?null:{id:"brain",label:"Brain",active:"/brain"===f,onClick:()=>{try{p?p.push("/brain"):window.location.href="/brain"}catch(e){}},icon:(0,r.jsx)(e5.A,{className:"w-5 h-5",strokeWidth:2.2}),href:"/brain"},y=null!=(a=[...o,...g?[g]:[],...j?[j]:[],...i?[i]:[]].find(e=>e.id===u))?a:null;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"w-14 shrink-0 bg-[var(--bg-secondary)] border-r border-[var(--border)] flex flex-col items-center py-4 gap-4 z-50",children:[(0,r.jsx)("div",{className:"flex flex-col items-center gap-3 w-full",children:o.map(e=>(0,r.jsx)(e3,{item:e,onPeek:()=>x(e.id)},e.id))}),(0,r.jsx)("div",{className:"flex-1"}),(g||j||i)&&(0,r.jsxs)("div",{className:"pt-4 border-t border-[var(--border)] w-full flex flex-col items-center gap-3",children:[g&&(0,r.jsx)(e3,{item:g,onPeek:()=>x(g.id),badge:null!=(l=g.badge)?l:h>0?h:void 0}),j&&(0,r.jsx)(e3,{item:j,onPeek:()=>x(j.id)}),i&&(0,r.jsx)(e3,{item:i,onPeek:()=>x(i.id)})]})]}),(null==y?void 0:y.peek)&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"fixed inset-0 z-40 bg-black/20 backdrop-blur-sm transition-all",onClick:()=>x(null)}),(0,r.jsxs)("div",{className:"absolute z-50 left-16 top-16 w-64 max-h-[80vh] overflow-auto bg-[var(--bg-secondary)]/90 backdrop-blur-xl border border-amber-accent/20 rounded-xl shadow-2xl p-4 animate-fade-in",children:[(0,r.jsx)("div",{className:"text-[10px] font-black uppercase tracking-[0.2em] text-amber-accent/70 mb-4",children:y.label}),(0,r.jsx)("div",{className:"scrollbar-thin",children:y.peek})]})]})]})}function e3(e){var t;let{item:a,onPeek:n,badge:l}=e,s=a.label.charAt(0).toUpperCase(),o="kb"===a.id,i="conflicts"===a.id||"conflict-manager"===a.id,c=null!=(t=a.badge)?t:l,d=c?"".concat(a.label," (").concat(c," unresolved)"):a.label;return(0,r.jsxs)("button",{title:d,onClick:()=>{a.onClick(),a.peek&&n()},className:"\n w-10 h-10 flex items-center justify-center relative rounded-xl transition-all duration-300 group hover-lift\n ".concat(a.active?"bg-amber-accent text-white shadow-[0_0_20px_rgba(180,120,30,0.4)]":"bg-[var(--bg-tertiary)] text-[var(--text-secondary)] hover:bg-[var(--accent-soft)] hover:text-[var(--text-primary)] active:scale-95","\n "),"aria-label":a.label,"data-testid":"rail-button-".concat(a.id),children:[a.active&&(0,r.jsx)("span",{className:"absolute -left-3 top-1/2 -translate-y-1/2 w-1.5 h-6 bg-amber-accent rounded-r-full shadow-[4px_0_15px_rgba(180,120,30,0.6)] bp-keep-round"}),a.icon?a.icon:o?(0,r.jsxs)("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"w-5 h-5",children:[(0,r.jsx)("path",{d:"M4 19.5A2.5 2.5 0 0 1 6.5 17H20"}),(0,r.jsx)("path",{d:"M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"})]}):i?(0,r.jsx)(e2.A,{className:"w-5 h-5",strokeWidth:2.2}):(0,r.jsx)("span",{className:"font-black text-sm tracking-tighter",children:s}),!!c&&(0,r.jsx)("span",{"data-testid":"rail-badge-".concat(a.id),className:"absolute -top-1 -right-1 flex h-4 min-w-4 px-1 items-center justify-center rounded-full bg-amber-accent text-[10px] font-extrabold text-black leading-none shadow-md",children:c})]})}let e6=(0,l.default)(()=>a.e(8693).then(a.bind(a,48693)).then(e=>e.SearchDialog),{loadableGenerated:{webpack:()=>[48693]},ssr:!1}),e8=(0,l.default)(()=>a.e(9699).then(a.bind(a,9699)).then(e=>e.AboutDialog),{loadableGenerated:{webpack:()=>[9699]},ssr:!1}),e9=(0,l.default)(()=>a.e(3518).then(a.bind(a,3518)).then(e=>e.DocsModal),{loadableGenerated:{webpack:()=>[3518]},ssr:!1}),e7=(0,l.default)(()=>a.e(807).then(a.bind(a,70807)).then(e=>e.FirstRunWizard),{loadableGenerated:{webpack:()=>[70807]},ssr:!1}),te=(0,l.default)(()=>a.e(4283).then(a.bind(a,84283)).then(e=>e.NewFileDialog),{loadableGenerated:{webpack:()=>[84283]},ssr:!1}),tt=(0,l.default)(()=>a.e(3987).then(a.bind(a,13987)).then(e=>e.NewFolderDialog),{loadableGenerated:{webpack:()=>[13987]},ssr:!1}),ta=(0,l.default)(()=>a.e(2966).then(a.bind(a,22966)).then(e=>e.DeleteFolderDialog),{loadableGenerated:{webpack:()=>[22966]},ssr:!1}),tr=(0,l.default)(()=>a.e(2205).then(a.bind(a,62205)).then(e=>e.UnregisterModal),{loadableGenerated:{webpack:()=>[62205]},ssr:!1}),tn=(0,l.default)(()=>a.e(3259).then(a.bind(a,43259)).then(e=>e.PublishDialog),{loadableGenerated:{webpack:()=>[43259]},ssr:!1}),tl="kontexta:show-journal:v1",ts="kontexta:recent-files:v1";function to(e){let t=(0,n.useRef)(!1);return e&&(t.current=!0),t.current}function ti(){let e=(0,s.useRouter)(),[t,a]=(0,n.useState)(!1),[l,u]=(0,n.useState)(!1),[x,h]=(0,n.useState)(!1),[m,p]=(0,n.useState)(void 0),[f,b]=(0,n.useState)(!1),[v,g]=(0,n.useState)(!1),[j,y]=(0,n.useState)(!1),[w,N]=(0,n.useState)(null),[k,S]=(0,n.useState)(!1),[C,T]=(0,n.useState)(!1),[A,P]=(0,n.useState)(!1),[L,R]=(0,n.useState)("publish"),[M,D]=(0,n.useState)(!1),[I,O]=(0,n.useState)(!1),[U,H]=(0,n.useState)(null),[G,z]=(0,n.useState)(null),[B,W]=(0,n.useState)(null),[K,J]=(0,n.useState)(null),[q,V]=(0,n.useState)(null),[$,Y]=(0,n.useState)(null),[Z,X]=(0,n.useState)([]),[Q,ee]=(0,n.useState)("updated_at"),[ea,er]=(0,n.useState)(0),[en,el]=(0,n.useState)(!1),[es,eo]=(0,n.useState)([]),[ec,ed]=(0,n.useState)("files"),eu=(0,n.useRef)(null),ex=(0,s.useSearchParams)();(0,n.useEffect)(()=>{let e=ex.get("setup"),t=ex.get("file"),a=!1,r=new URL(window.location.href);if("1"===e&&(b(!0),r.searchParams.delete("setup"),a=!0),t&&/^\d+$/.test(t)){let e=Number(t);e>0&&(eu.current=e,J(e),ed("read")),r.searchParams.delete("file"),a=!0}a&&window.history.replaceState({},"",r.toString())},[]),(0,n.useEffect)(()=>{let e=sessionStorage.getItem("selectedSection"),t=sessionStorage.getItem("selectedProjectId");e&&W(e),t&&H(Number(t));try{"true"===localStorage.getItem(tl)&&el(!0);let e=localStorage.getItem(ts);if(e){let t=JSON.parse(e);Array.isArray(t)&&eo(t.filter(e=>"number"==typeof e&&e>0).slice(0,6))}}catch(e){}},[]),(0,n.useEffect)(()=>{K&&eo(e=>{let t=[K,...e.filter(e=>e!==K)].slice(0,6);try{localStorage.setItem(ts,JSON.stringify(t))}catch(e){}return t})},[K]);let eh=(0,n.useCallback)(()=>{let e=!en;el(e);try{localStorage.setItem(tl,String(e))}catch(e){}!e&&"knowledge"===B&&(0,ei.sZ)(q)&&V(null)},[en,B,q]),{projects:ef,loading:eb,refresh:ev}=function(){let[e,t]=(0,n.useState)([]),[a,r]=(0,n.useState)(!0),l=(0,n.useRef)(0),s=(0,n.useCallback)(async()=>{let e=++l.current;try{r(!0);let a=await fetch("/api/projects");if(a.ok){let r=await a.json();if(e!==l.current)return;t(r)}}catch(e){console.error("Failed to fetch projects:",e)}finally{e===l.current&&r(!1)}},[]);return(0,n.useEffect)(()=>{s()},[s]),{projects:e,loading:a,refresh:s}}(),eg=function(){let[e,t]=(0,n.useState)(0);return(0,n.useEffect)(()=>{let e=!1,a=async()=>{try{let a=await fetch("/api/conflicts?count=1",{cache:"no-store"});if(a.ok){let r=await a.json();e||"number"!=typeof(null==r?void 0:r.count)||t(r.count)}}catch(e){}};a();let r=setInterval(()=>{"undefined"!=typeof document&&document.hidden||a()},15e3),n=()=>{a()},l=()=>{"undefined"==typeof document||document.hidden||a()};return window.addEventListener("kontexta:conflicts-changed",n),"undefined"!=typeof document&&document.addEventListener("visibilitychange",l),()=>{e=!0,clearInterval(r),window.removeEventListener("kontexta:conflicts-changed",n),"undefined"!=typeof document&&document.removeEventListener("visibilitychange",l)}},[]),e}(),ej=async()=>{if(U)try{let e=await fetch("/api/projects/".concat(U),{method:"DELETE"});if(e.ok)H(null),W(null),V(null),J(null),sessionStorage.removeItem("selectedSection"),sessionStorage.removeItem("selectedProjectId"),ev(),d.o.success("Project unregistered");else{let t=await e.json().catch(()=>({}));d.o.error(t.error||"Failed to unregister project")}}catch(t){var e;d.o.error("Failed to unregister project: ".concat(null!=(e=null==t?void 0:t.message)?e:"Network error"))}},{folders:ey,basePath:ew}=eQ(null,ea),{folders:eN,basePath:ek}=eQ("projects"===B?U:null,ea),{files:eS,loading:eC,refresh:eT}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},[t,a]=(0,n.useState)([]),[r,l]=(0,n.useState)(!0),s=(0,n.useRef)(e);s.current=e;let o=(0,n.useRef)(0),i=(0,n.useRef)(null),c=(0,n.useCallback)(async()=>{var e;let t=s.current,r=++o.current;null==(e=i.current)||e.abort();let n=new AbortController;i.current=n;try{l(!0);let e=new URLSearchParams;void 0!==t.project_id&&e.append("project_id",null===t.project_id?"none":t.project_id.toString()),t.tag&&e.append("tag",t.tag),void 0!==t.favorite&&e.append("favorite",t.favorite.toString()),t.folder&&e.append("folder",t.folder);let s="/api/files".concat(e.toString()?"?".concat(e.toString()):""),i=await fetch(s,{signal:n.signal});if(r!==o.current)return;if(i.ok){let e=await i.json();if(r!==o.current)return;a(e)}}catch(e){if((null==e?void 0:e.name)==="AbortError")return;console.error("Failed to fetch files:",e)}finally{r===o.current&&l(!1)}},[]);return(0,n.useEffect)(()=>(a([]),c(),()=>{var e;return null==(e=i.current)?void 0:e.abort()}),[e.project_id,e.tag,e.favorite,e.folder,c]),{files:t,loading:r,refresh:c}}({}),eA=(0,n.useMemo)(()=>{let e=eS.filter(e=>!(null===e.project_id&&/(^|[\\/])knowledge[\\/]profile\.md$/i.test(e.path)));return en||(e=e.filter(e=>!(0,ei.Ai)(e,ew))),"favorites"===B?e=e.filter(e=>e.favorite):"projects"===B&&null!==U&&(e=e.filter(e=>e.project_id===U)),$&&(e=e.filter(e=>{var t;return(null!=(t=e.tags)?t:[]).includes($)})),e},[eS,B,U,$,en,ew]),e_=(0,n.useMemo)(()=>eS.filter(e=>!e.project_id&&(en||!(0,ei.Ai)(e,ew))),[eS,en,ew]),eE=(0,n.useCallback)(e=>{if(e.project_id){let t=ef.find(t=>t.id===e.project_id);W("projects"),H(e.project_id),sessionStorage.setItem("selectedSection","projects"),sessionStorage.setItem("selectedProjectId",String(e.project_id)),(null==t?void 0:t.path)&&e.path.startsWith(t.path)?V(e.path.slice(t.path.length).replace(/^[\/\\]+/,"").split(/[\/\\]/).slice(0,-1).join("/")||null):V(null)}else W("knowledge"),H(null),sessionStorage.setItem("selectedSection","knowledge"),sessionStorage.removeItem("selectedProjectId"),!en&&(0,ei.Ai)(e,ew)?V(null):ew&&e.path.startsWith(ew)?V(e.path.slice(ew.length).replace(/^[\/\\]+/,"").split(/[\/\\]/).slice(0,-1).join("/")||null):V(null)},[ef,ew,en]);(0,n.useEffect)(()=>{if(null==eu.current)return;let e=eS.find(e=>e.id===eu.current);e&&(eE(e),eu.current=null)},[eS,eE]),(0,n.useEffect)(()=>{let e=!1;return(async()=>{try{let t=await fetch("/api/tags");if(!t.ok)return;let a=await t.json();e||X(a)}catch(e){}})(),()=>{e=!0}},[eS]);let eP=e=>{(!e||eq(()=>eP(e)))&&(Y(e),e&&(W("tags"),H(null),V(null),J(null),ed("files"),sessionStorage.setItem("selectedSection","tags"),sessionStorage.removeItem("selectedProjectId")))},eF=ef.find(e=>e.id===U),eL=to(t),eR=to(l),eM=to(x),eD=to(v),eI=to(j),eO=to(k),eU=to(C),eH=to(A),eG=(0,n.useRef)(null),ez=(0,n.useCallback)(e=>{eG.current||(eG.current=setTimeout(()=>{eG.current=null,eT()},350))},[eT]);(0,n.useEffect)(()=>()=>{eG.current&&clearTimeout(eG.current)},[]);let eB=(0,n.useRef)(ez);eB.current=ez,(0,n.useEffect)(()=>{let e={ws:null,reconnectTimer:null,cancelled:!1,stopReconnecting:!1,attempt:0},t=e=>{e&&(e.onmessage=null,e.onclose=null,e.onerror=null,e.onopen=null)},a=async()=>{if(e.cancelled||e.stopReconnecting)return;let r="https:"===window.location.protocol?"wss:":"ws:",n=e0.env.NEXT_PUBLIC_WS_TOKEN||"",l="";try{let e=await fetch("/api/auth/token");e.ok&&(l=(await e.json()).token)}catch(e){console.warn("[Kontexta] WS could not fetch session token:",e)}if(e.cancelled||e.stopReconnecting)return;let s=l||n,o=s?"?token=".concat(encodeURIComponent(s)):"",i="".concat(r,"//").concat(window.location.host,"/_kontexta_ws").concat(o);if(e.ws){t(e.ws);try{e.ws.close()}catch(e){}e.ws=null}let c=new WebSocket(i);e.ws=c,c.onopen=()=>{e.attempt=0},c.onmessage=e=>{try{let t=JSON.parse(e.data);eB.current(t)}catch(e){}},c.onclose=t=>{if(e.cancelled)return;if(1008===t.code||4401===t.code){console.warn("[Kontexta] WS auth failed; stopping reconnect attempts"),e.stopReconnecting=!0;return}e.attempt++;let r=Math.min(3e4,1e3*2**Math.min(e.attempt,5))*(.75+.5*Math.random());e.reconnectTimer=setTimeout(a,r)},c.onerror=()=>{}};return a(),()=>{e.cancelled=!0,e.reconnectTimer&&clearTimeout(e.reconnectTimer),t(e.ws);try{var a;null==(a=e.ws)||a.close()}catch(e){}e.ws=null}},[]);let eW=E("(max-width: 767px)"),[eK,eJ]=(0,n.useState)(!1);(0,n.useEffect)(()=>eJ(!0),[]);let{confirmDiscardIfDirty:eq,setDirty:eV,dialog:eY}=function(){let e=(0,n.useRef)(new Set),[t,a]=(0,n.useState)(null),l=(0,n.useCallback)((t,a)=>{a?e.current.add(t):e.current.delete(t)},[]),s=(0,n.useCallback)(t=>0===e.current.size||(a(()=>t),!1),[]);return(0,n.useEffect)(()=>{let t=t=>{e.current.size>0&&(t.preventDefault(),t.returnValue="")};return window.addEventListener("beforeunload",t),()=>window.removeEventListener("beforeunload",t)},[]),{confirmDiscardIfDirty:s,setDirty:l,dialog:(0,r.jsx)(em.T,{open:null!==t,onClose:()=>a(null),onConfirm:()=>{e.current.clear(),a(null),null==t||t()},title:"Unsaved changes",message:"You have unsaved changes in the open file. Discard them?",confirmLabel:"Discard",cancelLabel:"Keep editing",destructive:!0})}}(),eZ=e=>{eq(()=>eZ(e))&&(H(e),W("projects"),J(null),V(null),Y(null),ed("files"),sessionStorage.setItem("selectedSection","projects"),sessionStorage.setItem("selectedProjectId",String(e)))},e2=()=>{eq(()=>e2())&&(W("knowledge"),H(null),J(null),V(null),Y(null),ed("files"),sessionStorage.setItem("selectedSection","knowledge"),sessionStorage.removeItem("selectedProjectId"))},e5=()=>{eq(()=>e5())&&(W("favorites"),H(null),J(null),V(null),Y(null),ed("files"),sessionStorage.setItem("selectedSection","favorites"),sessionStorage.removeItem("selectedProjectId"))},e3=e=>{eq(()=>e3(e))&&(W("knowledge"),H(null),J(null),V(e),Y(null),ed("files"),sessionStorage.setItem("selectedSection","knowledge"),sessionStorage.removeItem("selectedProjectId"))},ti=(e,t)=>{if(e!==K&&!eq(()=>ti(e,t)))return;let a=eS.find(t=>t.id===e);a&&eE(a),J(e),ed("read")},tc=e=>{eq(()=>tc(e))&&(V(e),J(null),ed("files"))},td=(0,n.useCallback)(async()=>{D(!0);try{let e=await fetch("/api/refresh",{method:"POST",body:JSON.stringify({projectId:U}),headers:{"Content-Type":"application/json"}});if(e.ok)eT(),eT(),er(e=>e+1),d.o.success("Index refreshed");else{let t=await e.json().catch(()=>({}));d.o.error(t.error||"Refresh failed")}}catch(t){var e;d.o.error("Failed to refresh: ".concat(null!=(e=null==t?void 0:t.message)?e:"Network error"))}finally{D(!1)}},[U,eT,eT]),tu=e=>{(e.id===K||eq(()=>tu(e)))&&(eE(e),J(e.id),ed("read"),a(!1))},tx=async(e,t,a,r,n,l)=>{try{let s=await fetch("/api/files",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:e,content:t,destination:a,projectId:U,folder:r,format:n,kind:l})}),o=await s.json().catch(()=>({}));if(s.ok)return g(!1),d.o.success('Created "'.concat(e,'"')),await eT(),"number"==typeof o.id&&J(o.id),!0;return d.o.error(o.error||"Failed to create file"),!1}catch(e){var s;return d.o.error("Failed to create file: ".concat(null!=(s=null==e?void 0:e.message)?s:"Network error")),!1}},th=async e=>{try{let t=await fetch("/api/files/".concat(e),{method:"DELETE"});if(t.ok)eT(),er(e=>e+1),J(null),d.o.success("File deleted");else{let e=await t.json().catch(()=>({}));d.o.error(e.error||"Failed to delete file")}}catch(e){var t;d.o.error("Failed to delete file: ".concat(null!=(t=null==e?void 0:e.message)?t:"Network error"))}},tm=async e=>{try{let t=await fetch("/api/folders",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({projectId:G&&G>0?G:null,name:e})});if(t.ok)return y(!1),G&&0!==G?V(e):(W("knowledge"),H(null),V(e),sessionStorage.setItem("selectedSection","knowledge"),sessionStorage.removeItem("selectedProjectId")),er(e=>e+1),d.o.success('Folder "'.concat(e,'" created')),!0;{let e=await t.json().catch(()=>({}));return d.o.error(e.error||"Failed to create folder"),!1}}catch(e){var t;return d.o.error("Failed to create folder: ".concat(null!=(t=null==e?void 0:e.message)?t:"Network error")),!1}},tp=async()=>{if(q){if("knowledge"===B&&(0,ei.BZ)(q)){d.o.error("Cannot delete root knowledge folders"),S(!1);return}O(!0);try{let e=await fetch("/api/folders?name=".concat(encodeURIComponent(q),"&projectId=").concat(U||""),{method:"DELETE"});if(e.ok)V(null),er(e=>e+1),S(!1),d.o.success("Folder deleted");else{let t=await e.json().catch(()=>({}));d.o.error(t.error||"Failed to delete folder")}}catch(t){var e;d.o.error("Failed to delete folder: ".concat(null!=(e=null==t?void 0:t.message)?e:"Network error"))}finally{O(!1)}}};(0,n.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"k"===e.key&&(e.preventDefault(),a(e=>!e))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let tf=(0,n.useMemo)(()=>{var e,t;let a=[];"favorites"===B?a.push({label:"Favorites",onClick:e5}):"knowledge"===B?a.push({label:"Knowledge",onClick:e2}):"projects"===B&&eF?a.push({label:eF.name,onClick:()=>eZ(eF.id)}):"tags"===B&&$&&a.push({label:"#".concat($),onClick:()=>eP($)});let r=K?eA.find(e=>e.id===K)||eS.find(e=>e.id===K):null,n="projects"===B?null!=(t=null==eF?void 0:eF.path)?t:null:null!=ew?ew:null,l=[];return r&&n&&(null==(e=r.path)?void 0:e.startsWith(n))?l=r.path.slice(n.length).replace(/\\/g,"/").replace(/^\/+/,"").split("/").filter(Boolean).slice(0,-1):q&&(l=q.split("/").filter(Boolean)),l.forEach(e=>a.push({label:e})),r&&a.push({label:r.title}),a},[B,eF,K,eA,eS,ew,q]),tb=ef.map(e=>({id:"p-".concat(e.id),label:e.name,active:"projects"===B&&U===e.id,onClick:()=>eZ(e.id)})),tv=(0,n.useMemo)(()=>{let e=new Map(eS.map(e=>[e.id,e])),t=[];for(let l of es){var a,r,n;let s=e.get(l);s&&(!en&&(0,ei.Ai)(s,ew)||t.push({id:s.id,title:s.title,storage_type:null!=(a=s.storage_type)?a:"local",path:s.path,project_id:null!=(r=s.project_id)?r:null,content_class:null!=(n=s.content_class)?n:null}))}return t},[eS,es,en,ew]),tg=(0,n.useMemo)(()=>[{id:"new-file",label:"New File",hint:"Create a KB or project note",onRun:()=>g(!0)},{id:"graph",label:"Open Knowledge Graph",hint:"/graph",onRun:()=>e.push("/graph")},{id:"hygiene",label:"Knowledge Hygiene",hint:"/hygiene",onRun:()=>e.push("/hygiene")},{id:"toggle-journal",label:en?"Hide Journal Files":"Show Journal Files",hint:"Toggle agent journal visibility",onRun:eh},{id:"refresh",label:"Scan / Refresh Files",hint:"Re-scan disk for changes",onRun:()=>{td()}},{id:"calendar",label:"Open Calendar",hint:"/calendar",onRun:()=>e.push("/calendar")},{id:"conflicts",label:"View Sync Conflicts",hint:"/conflicts",onRun:()=>e.push("/conflicts")},{id:"brain",label:"Brain & Relay Sync",hint:"/brain",onRun:()=>e.push("/brain")},{id:"configure",label:"Configure Kontexta",hint:"Tools, Agents, Journal settings",onRun:()=>h(!0)},{id:"publish",label:"Publish Documentation",hint:"Build static HTML docs",onRun:()=>{R("publish"),P(!0)}}],[en,e,eh,td]);if(!eK)return(0,r.jsx)("div",{className:"h-screen bg-[var(--bg-primary)]"});let tj=(0,r.jsx)(et,{projects:ef,projectFiles:eA,knowledgeFiles:e_,selectedProjectId:U,selectedSection:B,selectedFolder:q,projectFolders:eN||[],knowledgeFolders:ey||[],projectBasePath:ek,knowledgeBasePath:ew,onSelectProject:eZ,onSelectKnowledge:e2,onSelectFavorites:e5,onSelectKnowledgeFolder:e3,onSelectFolder:tc,onSelectFile:e=>ti(e,!0),selectedTag:$,tags:Z,onSelectTag:eP,onCreateBucketFolder:e=>{z(0),N(e),y(!0)},showJournal:en,onToggleShowJournal:eh}),ty=(0,r.jsx)(ep,{files:eA,selectedFileId:K,onSelectFile:ti,sortBy:Q,onSortChange:ee,selectedFolder:q,selectedProject:null!=eF?eF:null,selectedSection:B,basePath:"projects"===B?ek:ew,loading:eC||eb,onUnregisterProject:()=>T(!0),onDeleteFolder:()=>{q&&("knowledge"===B&&(0,ei.BZ)(q)||S(!0))},projects:ef,onUploaded:eT,onRefresh:td,onOnboarded:()=>{ev(),eT()},refreshing:M,onNewFile:()=>g(!0),showJournal:en}),tw=(0,r.jsx)(e$,{fileId:K,onDelete:th,onChanged:eT,onDirtyChange:eV,onNavigateToFile:e=>ti(e)});return(0,r.jsxs)("div",{className:"h-screen flex flex-col",children:[(0,r.jsx)(_,{onSearch:()=>a(!0),onAbout:()=>u(!0),onConfigure:()=>h(!0),onPublish:()=>{R("publish"),P(!0)},onViewPublished:()=>window.open("/api/publish/html","_blank"),unresolvedConflicts:eg}),(0,r.jsx)(e1,{segments:tf}),eY,(0,r.jsx)(eX,{onOpen:()=>{p("agents"),h(!0)}}),(0,r.jsx)(F,{isPhone:eW,mobileTab:ec,leftRail:(0,r.jsx)(e4,{items:tb,footer:{id:"kb",label:"Knowledge Base",active:"knowledge"===B,onClick:e2},unresolvedConflicts:eg}),left:tj,middle:ty,right:tw}),eW&&(0,r.jsxs)("nav",{"aria-label":"Mobile navigation",className:"h-14 shrink-0 border-t border-[var(--border)] bg-[var(--bg-secondary)] grid grid-cols-3 text-xs",children:[(0,r.jsxs)("button",{type:"button",onClick:()=>ed("browse"),"aria-current":"browse"===ec?"page":void 0,className:"flex flex-col items-center justify-center gap-1 transition-colors ".concat("browse"===ec?"text-[var(--accent)] font-semibold":"text-[var(--text-secondary)]"),children:[(0,r.jsx)(o.A,{className:"w-4 h-4","aria-hidden":!0}),(0,r.jsx)("span",{children:"Browse"})]}),(0,r.jsxs)("button",{type:"button",onClick:()=>ed("files"),"aria-current":"files"===ec?"page":void 0,className:"flex flex-col items-center justify-center gap-1 transition-colors ".concat("files"===ec?"text-[var(--accent)] font-semibold":"text-[var(--text-secondary)]"),children:[(0,r.jsx)(i.A,{className:"w-4 h-4","aria-hidden":!0}),(0,r.jsx)("span",{children:"Files"})]}),(0,r.jsxs)("button",{type:"button",onClick:()=>ed("read"),"aria-current":"read"===ec?"page":void 0,className:"flex flex-col items-center justify-center gap-1 transition-colors ".concat("read"===ec?"text-[var(--accent)] font-semibold":"text-[var(--text-secondary)]"),children:[(0,r.jsx)(c.A,{className:"w-4 h-4","aria-hidden":!0}),(0,r.jsx)("span",{children:"Read"})]})]}),eL&&(0,r.jsx)(e6,{open:t,onClose:()=>a(!1),onSelectFile:tu,includeJournal:en,commands:tg,recentFiles:tv}),eR&&(0,r.jsx)(e8,{open:l,onClose:()=>u(!1)}),eM&&(0,r.jsx)(e9,{open:x,onClose:()=>{h(!1),p(void 0)},initialTab:m}),f&&(0,r.jsx)(e7,{open:!0,onClose:()=>b(!1),projects:ef,onSaved:ev}),eD&&(0,r.jsx)(te,{open:v,onClose:()=>g(!1),onCreate:tx,currentProjectId:U,availableFolders:"knowledge"===B?ey:eN,defaultFolder:"knowledge"===B&&null!=q?q:void 0,showJournal:en}),eI&&(0,r.jsx)(tt,{open:j,onClose:()=>{y(!1),N(null)},onCreate:tm,bucketPrefix:w}),eO&&(0,r.jsx)(ta,{open:k,folderName:q||"",onClose:()=>S(!1),onConfirm:tp,loading:I}),eU&&(0,r.jsx)(tr,{isOpen:C,projectName:(null==eF?void 0:eF.name)||"",onClose:()=>T(!1),onConfirm:()=>{ej(),T(!1)}}),eH&&(0,r.jsx)(tn,{isOpen:A,onClose:()=>{P(!1),R("publish")},mode:L,onSwitchToPublish:()=>{R("publish")},onPublishSuccess:e=>{var t,a;return d.o.success("Publish successful",{duration:1/0,closeButton:!0,description:["".concat(null!=(t=e.docCount)?t:0," docs"),e.endpointCount?"".concat(e.endpointCount," endpoints"):null,e.termCount?"".concat(e.termCount," terms"):null,null!=(a=e.output)?a:null].filter(Boolean).join(" \xb7 "),action:{label:"View Published",onClick:()=>window.open("/api/publish/html","_blank","noopener,noreferrer")}})}})]})}},35047:(e,t,a)=>{"use strict";a.d(t,{G:()=>o});var r=a(14915),n=a(35186),l=a(59217),s=a(6519);function o(e){let{content:t,className:a}=e;return(0,r.jsx)("div",{className:"prose dark:prose-invert max-w-none text-[var(--text-primary)] ".concat(a||""),children:(0,r.jsx)(n.oz,{remarkPlugins:[l.A],components:{h1:e=>{let{children:t}=e;return(0,r.jsx)("h1",{className:"text-3xl font-black mb-6 bg-gradient-to-r from-[var(--accent)] via-amber-accent-light to-[var(--accent)] bg-clip-text text-transparent drop-shadow-[0_0_15px_color-mix(in_srgb,var(--accent)_20%,transparent)] font-title tracking-tight",children:t})},h2:e=>{let{children:t}=e;return(0,r.jsx)("h2",{className:"text-amber-accent-light text-2xl font-bold mb-4 mt-8 border-b border-amber-accent/10 pb-2",children:t})},h3:e=>{let{children:t}=e;return(0,r.jsx)("h3",{className:"text-amber-accent-light text-xl font-bold mb-3 mt-6",children:t})},h4:e=>{let{children:t}=e;return(0,r.jsx)("h4",{className:"text-amber-accent-light text-lg font-semibold mb-2 mt-4",children:t})},h5:e=>{let{children:t}=e;return(0,r.jsx)("h5",{className:"text-amber-accent-light text-base font-semibold mb-2",children:t})},h6:e=>{let{children:t}=e;return(0,r.jsx)("h6",{className:"text-amber-accent-light text-sm font-semibold mb-2",children:t})},blockquote:e=>{let{children:t}=e;return(0,r.jsx)("blockquote",{className:"border-l-4 border-amber-accent/30 bg-amber-accent/5 px-6 py-3 rounded-r-lg my-8 text-[var(--text-secondary)] italic leading-relaxed",children:t})},strong:e=>{let{children:t}=e;return(0,r.jsx)("strong",{className:"font-bold text-amber-accent-light",children:t})},code:e=>{let{className:t,children:a,...n}=e;return"language-mermaid"===t?(0,r.jsx)(s.q,{source:String(a).replace(/\n$/,""),className:"my-4"}):(0,r.jsx)("code",{className:t,...n,children:a})}},children:t})})}},56570:(e,t,a)=>{"use strict";a.d(t,{l:()=>s});var r=a(14915),n=a(88691),l=a(29723);function s(e){let{open:t,onClose:a,title:s,description:o,widthClass:i="max-w-md",hideHeader:c=!1,positionClass:d="left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2",children:u}=e;return(0,r.jsx)(n.bL,{open:t,onOpenChange:e=>{e||a()},children:(0,r.jsxs)(n.ZL,{children:[(0,r.jsx)(n.hJ,{className:"fixed inset-0 z-[var(--z-modal)] bg-black/60 backdrop-blur-sm animate-fade-in"}),(0,r.jsx)(n.UC,{className:"fixed ".concat(d," z-[var(--z-modal)] focus:outline-none"),children:(0,r.jsxs)("div",{className:"relative w-[92vw] ".concat(i," rounded-xl border border-[var(--border)] bg-[var(--bg-primary)] shadow-2xl animate-scale-in max-h-[85vh] flex flex-col"),children:[c?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.hE,{className:"sr-only",children:s}),(0,r.jsx)(n.bm,{className:"btn btn-icon-sm absolute right-3 top-3 z-10","aria-label":"Close",children:(0,r.jsx)(l.A,{className:"w-4 h-4","aria-hidden":!0})})]}):(0,r.jsxs)("div",{className:"flex items-center justify-between px-5 pt-4 pb-3 border-b border-[var(--border)] shrink-0",children:[(0,r.jsx)(n.hE,{className:"text-sm font-bold text-[var(--text-primary)] font-title",children:s}),(0,r.jsx)(n.bm,{className:"btn btn-icon-sm","aria-label":"Close",children:(0,r.jsx)(l.A,{className:"w-4 h-4","aria-hidden":!0})})]}),o?(0,r.jsx)(n.VY,{className:"px-5 pt-3 text-xs text-[var(--text-secondary)]",children:o}):(0,r.jsx)(n.VY,{className:"sr-only",children:s}),(0,r.jsx)("div",{className:"p-5 overflow-y-auto",children:u})]})})]})})}},80966:(e,t,a)=>{Promise.resolve().then(a.bind(a,33039))},85170:(e,t,a)=>{"use strict";a.d(t,{$3:()=>d,AU:()=>s,Ai:()=>i,BZ:()=>c,UF:()=>x,is:()=>r,jh:()=>u,sZ:()=>o,zQ:()=>h});let r=["journal","knowledge","mermaid","html"],n=new Set(r);function l(e){return e?e.split(/[/\\]/).filter(Boolean):[]}function s(e){let[t]=l(e);return t&&n.has(t)?t:null}function o(e){return"journal"===s(e)}function i(e,t){var a;if("journal"===e.content_class)return!0;if(e.project_id)return!1;let r=(null!=(a=e.path)?a:"").replace(/\\/g,"/");if(t){let e=t.replace(/\\/g,"/").replace(/\/+$/,"")+"/";if(r.startsWith(e)){let t=r.slice(e.length);return"journal"===t||t.startsWith("journal/")}}return/(?:^|\/)knowledge\/journal(?:\/|$)/i.test(r)}function c(e){return!!e&&l(e).length<=1}function d(e){let t=l(e);return"html"===t[0]&&"resources"===t[1]}function u(e){if(d(e))return null;switch(s(e)){case"journal":case"knowledge":return"md";case"mermaid":return"mmd";case"html":return"html";default:return null}}function x(e){if(d(e))return"";let t=u(e);return"md"===t?".md,.markdown":"mmd"===t?".mmd":"html"===t?".html,.htm":null}function h(e,t){if(d(t))return!0;let a=u(t);if(!a)return!0;let r=function(e){let t=e.lastIndexOf(".");return t<0?"":e.slice(t+1).toLowerCase()}(e);return"md"===a?"md"===r||"markdown"===r:"mmd"===a?"mmd"===r:"html"!==a||"html"===r||"htm"===r}},96405:(e,t,a)=>{"use strict";a.d(t,{_:()=>s});var r=a(65347);let n="kontexta:agents-changed",l=()=>window.dispatchEvent(new Event(n));function s(){let[e,t]=(0,r.useState)(null),[a,s]=(0,r.useState)(!0),o=(0,r.useRef)(0),i=(0,r.useCallback)(async()=>{let e=++o.current;try{let a=await fetch("/api/agents");if(a.ok){let r=await a.json();e===o.current&&t(Array.isArray(null==r?void 0:r.agents)?r:null)}else e===o.current&&t(null)}catch(a){e===o.current&&t(null)}finally{e===o.current&&s(!1)}},[]);(0,r.useEffect)(()=>{i();let e=()=>{i()};return window.addEventListener(n,e),()=>window.removeEventListener(n,e)},[i]);let c=(0,r.useCallback)(async(e,t)=>{try{let a=await fetch("/api/agents/".concat(e),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:t})});if(!a.ok)return null;let r=await a.json();return l(),r}catch(e){return null}},[]);return{state:e,loading:a,refresh:i,setEnabled:c,hooksAction:(0,r.useCallback)(async(e,t)=>{try{let a=await fetch("/api/agents/".concat(e,"/hooks"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:t})}),r=await a.json().catch(()=>({}));return l(),{ok:a.ok,status:a.status,...r}}catch(e){return{ok:!1,status:0,error:"Request failed"}}},[]),mcpAction:(0,r.useCallback)(async function(e,t){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"prompt";try{let r=await fetch("/api/agents/".concat(e,"/mcp"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:t,approval:a})}),n=await r.json().catch(()=>({}));return l(),{ok:r.ok,status:r.status,...n}}catch(e){return{ok:!1,status:0,error:"Request failed"}}},[])}}}},e=>{e.O(0,[4758,2449,8362,3617,9922,5159,7358],()=>e(e.s=80966)),_N_E=e.O()}]);
@@ -0,0 +1 @@
1
+ (()=>{"use strict";var e={},a={};function t(r){var f=a[r];if(void 0!==f)return f.exports;var c=a[r]={exports:{}},d=!0;try{e[r].call(c.exports,c,c.exports,t),d=!1}finally{d&&delete a[r]}return c.exports}t.m=e,(()=>{var e=[];t.O=(a,r,f,c)=>{if(r){c=c||0;for(var d=e.length;d>0&&e[d-1][2]>c;d--)e[d]=e[d-1];e[d]=[r,f,c];return}for(var b=1/0,d=0;d<e.length;d++){for(var[r,f,c]=e[d],o=!0,n=0;n<r.length;n++)(!1&c||b>=c)&&Object.keys(t.O).every(e=>t.O[e](r[n]))?r.splice(n--,1):(o=!1,c<b&&(b=c));if(o){e.splice(d--,1);var i=f();void 0!==i&&(a=i)}}return a}})(),t.n=e=>{var a=e&&e.__esModule?()=>e.default:()=>e;return t.d(a,{a:a}),a},(()=>{var e,a=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__;t.t=function(r,f){if(1&f&&(r=this(r)),8&f||"object"==typeof r&&r&&(4&f&&r.__esModule||16&f&&"function"==typeof r.then))return r;var c=Object.create(null);t.r(c);var d={};e=e||[null,a({}),a([]),a(a)];for(var b=2&f&&r;"object"==typeof b&&!~e.indexOf(b);b=a(b))Object.getOwnPropertyNames(b).forEach(e=>d[e]=()=>r[e]);return d.default=()=>r,t.d(c,d),c}})(),t.d=(e,a)=>{for(var r in a)t.o(a,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:a[r]})},t.f={},t.e=e=>Promise.all(Object.keys(t.f).reduce((a,r)=>(t.f[r](e,a),a),[])),t.u=e=>"static/chunks/"+(({1097:"6a2ca82e",1805:"a118fb18",4371:"02852184",7050:"8080c6f4",7241:"6b5bb80a",8881:"d185f5cd"})[e]||e)+"."+({46:"9922e50f2158e1a9",171:"a4732e77e941b2cd",245:"3ed04e1f16f90b31",338:"77f45c7810885961",408:"82356d1e11e880d9",492:"234794e12315e4bb",559:"c4615787d977bf47",693:"71c8b97896628a66",807:"5bf32ba308aae89a",944:"6a3d93405d7cb403",1097:"c26cb70da3106c1c",1108:"60fb822c3e3fdaf3",1226:"49d217dc03a1770f",1286:"8da72129ab3aa8fd",1733:"3a6dae5cc3785d0b",1805:"88c57fd88bdf91aa",2081:"313746c212bfc5c9",2086:"0b05a08670aae1db",2205:"68bae400481d0a3a",2443:"9d9dd31cc33fc741",2966:"2216b92e18a0bb66",3034:"e1171cbeeed85923",3259:"585f965f16cd7406",3297:"7664b51ee69c7513",3471:"7790a4192ef84a1a",3514:"14aa56fe189fd052",3518:"5a080b5b9172e9ab",3685:"1e1d7cc834bf67db",3696:"5d462babda0c0b9e",3987:"07ce2f3afff6c9a1",4283:"524bc904dbdd2417",4371:"a3b62691cdc349cf",4798:"d851e8027b2db933",4908:"2fed0b6fbc391b55",4915:"97b9c59991c26fa7",4936:"c65cdd63440ade70",5127:"e5e917b5cb9c4e52",5141:"93a42ebd1580da60",5514:"104d052cec14d85a",5667:"e0097b2112faa29b",5858:"cff8810734332b7e",6367:"fd87728718a97771",6394:"c2172a59c01bd0bd",6396:"d288334e13a70139",6483:"88695b22b21b10f1",6561:"176d35e576df3f9d",6584:"87fc375a0510108d",6934:"45e50410379dc377",7050:"ed360e7424d6fe99",7216:"d1b096d2a35967fd",7241:"c511153adad62faf",7342:"fcb52cf5f7ce0e17",7541:"43ff810bb14fd5c0",7563:"376c2692778a62b3",7756:"b0dd00e996549a39",8052:"69c066e56bbd5d6c",8280:"81c2b0d61e27a576",8547:"5bef8f1afd162429",8602:"0b457ca55bd2c08e",8693:"7e10450df289d6a0",8794:"401ab179d53aa5d5",8881:"71b8f43667fbf60d",9053:"c953d758ff5dc6ee",9122:"cf7fd16fc8d7fad0",9255:"78469e88fa06e186",9699:"8e15c2b743d792a3",9852:"dff25fd2ed9a2763",9981:"8fa0bb90a26c66eb"})[e]+".js",t.miniCssF=e=>{},t.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),t.o=(e,a)=>Object.prototype.hasOwnProperty.call(e,a),(()=>{var e={},a="_N_E:";t.l=(r,f,c,d)=>{if(e[r])return void e[r].push(f);if(void 0!==c)for(var b,o,n=document.getElementsByTagName("script"),i=0;i<n.length;i++){var u=n[i];if(u.getAttribute("src")==r||u.getAttribute("data-webpack")==a+c){b=u;break}}b||(o=!0,(b=document.createElement("script")).charset="utf-8",b.timeout=120,t.nc&&b.setAttribute("nonce",t.nc),b.setAttribute("data-webpack",a+c),b.src=t.tu(r)),e[r]=[f];var l=(a,t)=>{b.onerror=b.onload=null,clearTimeout(s);var f=e[r];if(delete e[r],b.parentNode&&b.parentNode.removeChild(b),f&&f.forEach(e=>e(t)),a)return a(t)},s=setTimeout(l.bind(null,void 0,{type:"timeout",target:b}),12e4);b.onerror=l.bind(null,b.onerror),b.onload=l.bind(null,b.onload),o&&document.head.appendChild(b)}})(),t.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;t.tt=()=>(void 0===e&&(e={createScriptURL:e=>e},"undefined"!=typeof trustedTypes&&trustedTypes.createPolicy&&(e=trustedTypes.createPolicy("nextjs#bundler",e))),e)})(),t.tu=e=>t.tt().createScriptURL(e),t.p="/_next/",(()=>{var e={8068:0,2219:0};t.f.j=(a,r)=>{var f=t.o(e,a)?e[a]:void 0;if(0!==f)if(f)r.push(f[2]);else if(/^(2219|8068)$/.test(a))e[a]=0;else{var c=new Promise((t,r)=>f=e[a]=[t,r]);r.push(f[2]=c);var d=t.p+t.u(a),b=Error();t.l(d,r=>{if(t.o(e,a)&&(0!==(f=e[a])&&(e[a]=void 0),f)){var c=r&&("load"===r.type?"missing":r.type),d=r&&r.target&&r.target.src;b.message="Loading chunk "+a+" failed.\n("+c+": "+d+")",b.name="ChunkLoadError",b.type=c,b.request=d,f[1](b)}},"chunk-"+a,a)}},t.O.j=a=>0===e[a];var a=(a,r)=>{var f,c,[d,b,o]=r,n=0;if(d.some(a=>0!==e[a])){for(f in b)t.o(b,f)&&(t.m[f]=b[f]);if(o)var i=o(t)}for(a&&a(r);n<d.length;n++)c=d[n],t.o(e,c)&&e[c]&&e[c][0](),e[c]=0;return t.O(i)},r=self.webpackChunk_N_E=self.webpackChunk_N_E||[];r.forEach(a.bind(null,0)),r.push=a.bind(null,r.push.bind(r))})(),t.nc=void 0})();