orc-ai 0.1.49 → 0.1.51

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 (262) hide show
  1. package/dist/index.js +519 -485
  2. package/dist/skills/orc-platform/SKILL.md +3 -1
  3. package/dist/skills/orc-platform/references/execution.md +3 -0
  4. package/dist/skills/orc-platform/references/scratchpads.md +140 -0
  5. package/dist/skills/orc-platform/references/web.md +112 -0
  6. package/dist/skills/orc-sdlc/references/planning.md +2 -0
  7. package/dist/web/assets/{Agents-C8dJX8px.js → Agents-Cuq9hQL1.js} +1 -1
  8. package/dist/web/assets/Assistant-Bold-gm-uSS1B.woff2 +0 -0
  9. package/dist/web/assets/Assistant-Medium-DrcxCXg3.woff2 +0 -0
  10. package/dist/web/assets/Assistant-Regular-DVxZuzxb.woff2 +0 -0
  11. package/dist/web/assets/Assistant-SemiBold-SCI4bEL9.woff2 +0 -0
  12. package/dist/web/assets/{Attention-BHYo8Lwr.js → Attention-Blme1iNv.js} +1 -1
  13. package/dist/web/assets/{Audit-CS_DZkbJ.js → Audit-CcdL6u56.js} +1 -1
  14. package/dist/web/assets/{ConfirmDialog-CrSa87VF.js → ConfirmDialog-UlZrlBrT.js} +1 -1
  15. package/dist/web/assets/Dashboard-u3v-obdz.js +1 -0
  16. package/dist/web/assets/{DocumentWorkspace-CNyVQTjg.js → DocumentWorkspace-B5QQ9h1l.js} +1 -1
  17. package/dist/web/assets/{EmptyState-Ctm7L70B.js → EmptyState-CLMWpYxU.js} +1 -1
  18. package/dist/web/assets/{ErrorState-BPTepwiG.js → ErrorState-_BM228mQ.js} +1 -1
  19. package/dist/web/assets/{FileEditor-Dh29_xCL.js → FileEditor-CGTsskO5.js} +1 -1
  20. package/dist/web/assets/{JobWebhooks-TvAY8p1V.js → JobWebhooks-CeHYIwjS.js} +1 -1
  21. package/dist/web/assets/{Jobs-C5ggSs2T.js → Jobs-B_HefXhI.js} +3 -3
  22. package/dist/web/assets/Knowledge-DtqZHvq9.js +28 -0
  23. package/dist/web/assets/{PackageCatalog-B1U3vfhW.js → PackageCatalog-C4JkAh_e.js} +5 -5
  24. package/dist/web/assets/{Pager-ClYYU9et.js → Pager-C4QwTsW7.js} +1 -1
  25. package/dist/web/assets/{PriorityBadge-BW-A50LE.js → PriorityBadge-q0hZXCLg.js} +1 -1
  26. package/dist/web/assets/Projects-Bqohd0oU.js +3 -0
  27. package/dist/web/assets/ResumeActions-Bihtv9n8.js +1 -0
  28. package/dist/web/assets/{Rules-DGKsAbTf.js → Rules-DbI3E-1N.js} +1 -1
  29. package/dist/web/assets/Scratchpads-CvYHDI3j.js +20 -0
  30. package/dist/web/assets/Sessions-mS5ivBxN.js +5 -0
  31. package/dist/web/assets/{Settings-yW1S2q4F.js → Settings-BcP04VXz.js} +6 -6
  32. package/dist/web/assets/{Skills-BwdXE5nT.js → Skills-Cs1JTSlV.js} +3 -3
  33. package/dist/web/assets/{SourceEditor-ft02z20v.js → SourceEditor-B66_SPOa.js} +1 -1
  34. package/dist/web/assets/{StatusBadge-C5G1fdZh.js → StatusBadge-BxSWnu8L.js} +1 -1
  35. package/dist/web/assets/TagInput-B3BLlodf.js +1 -0
  36. package/dist/web/assets/{TaskDetailSheet-fUSHPFB-.js → TaskDetailSheet-BnMsuYO6.js} +2 -2
  37. package/dist/web/assets/{Tasks-uRqvmLz7.js → Tasks-CZnulyFF.js} +5 -5
  38. package/dist/web/assets/{Terminals-W5nszLI1.js → Terminals-J-qPx71R.js} +5 -5
  39. package/dist/web/assets/{ViewHeader-DXR0ZaMO.js → ViewHeader-CG7vOMnJ.js} +1 -1
  40. package/dist/web/assets/{Webhooks-lXLoKWdt.js → Webhooks-DPpjIwP_.js} +1 -1
  41. package/dist/web/assets/abnfDiagram-VCTEODGH-qnCZr3qh.js +1 -0
  42. package/dist/web/assets/ar-SA-G6X2FPQ2-BNl3syL3.js +10 -0
  43. package/dist/web/assets/arc-DuthDAsq.js +1 -0
  44. package/dist/web/assets/architectureDiagram-5GKGNRK7-CuzhWFIn.js +36 -0
  45. package/dist/web/assets/arrow-left-DNp3aOhW.js +6 -0
  46. package/dist/web/assets/az-AZ-76LH7QW2-CSlBN4kF.js +1 -0
  47. package/dist/web/assets/bg-BG-XCXSNQG7-Dcs1AElN.js +5 -0
  48. package/dist/web/assets/{blockDiagram-I7D4REHJ-DMrufypV.js → blockDiagram-I7D4REHJ-CCIO0eI-.js} +3 -3
  49. package/dist/web/assets/bn-BD-2XOGV67Q-D9poNjDl.js +5 -0
  50. package/dist/web/assets/{c4Diagram-7LVT6UL2-BUUxjwvU.js → c4Diagram-7LVT6UL2-EDh4_U6t.js} +2 -2
  51. package/dist/web/assets/ca-ES-6MX7JW3Y-pTbaXdVe.js +8 -0
  52. package/dist/web/assets/channel-D-jHqOEf.js +1 -0
  53. package/dist/web/assets/chunk-2Q5K7J3B-Ccr7lFKH.js +1 -0
  54. package/dist/web/assets/{chunk-5VM5RSS4-B6lAVcgQ.js → chunk-5VM5RSS4-rFn8SpPH.js} +1 -1
  55. package/dist/web/assets/chunk-F27PBJKO-CDJpfkoq.js +1 -0
  56. package/dist/web/assets/{chunk-IMKFNOWR-CwyogA-y.js → chunk-IMKFNOWR-B3_FhSA0.js} +1 -1
  57. package/dist/web/assets/chunk-JWPE2WC7-sBjgi4vj.js +1 -0
  58. package/dist/web/assets/chunk-POPQ4Y6H-Dsox2izf.js +1 -0
  59. package/dist/web/assets/{chunk-SVP7TREG-CmiQdvOH.js → chunk-SVP7TREG-CzwNtBeO.js} +4 -4
  60. package/dist/web/assets/{chunk-TICWLB2K-CieIpfOy.js → chunk-TICWLB2K-C2vbibcd.js} +1 -1
  61. package/dist/web/assets/chunk-XXDRQBXY-V09kgMMs.js +1 -0
  62. package/dist/web/assets/classDiagram-ZZMXUADV-yk_1OWub.js +1 -0
  63. package/dist/web/assets/classDiagram-v2-VYDZK3BY-yk_1OWub.js +1 -0
  64. package/dist/web/assets/copy-DG3MHKpv.js +6 -0
  65. package/dist/web/assets/cose-bilkent-JH36ORCC-CJbRd_jc.js +1 -0
  66. package/dist/web/assets/cs-CZ-2BRQDIVT-DCTwXFkX.js +11 -0
  67. package/dist/web/assets/{cynefin-OW5HDTMX-vMXgcpgg.js → cynefin-OW5HDTMX-DQAC3glv.js} +1 -1
  68. package/dist/web/assets/cynefinDiagram-5FMLGOSQ-BzboBb_e.js +62 -0
  69. package/dist/web/assets/da-DK-5WZEPLOC-BAYPDSds.js +5 -0
  70. package/dist/web/assets/{dagre-GXQ25YYZ-xmoviGlr.js → dagre-GXQ25YYZ-C_-0NO8H.js} +2 -2
  71. package/dist/web/assets/de-DE-XR44H4JA-WTQ3THgd.js +8 -0
  72. package/dist/web/assets/{diagram-S7CK7UJ4-CguQzzXs.js → diagram-S7CK7UJ4-Dvi9imfs.js} +5 -5
  73. package/dist/web/assets/diagram-UQ7AKVKN-BoEKhuYx.js +41 -0
  74. package/dist/web/assets/{diagram-VSXAHHWV-cuhv3Fvj.js → diagram-VSXAHHWV-AoIN6taJ.js} +3 -3
  75. package/dist/web/assets/diagram-VX7I27RA-BIAMQMgb.js +24 -0
  76. package/dist/web/assets/diagram-Z3DM3KII-MXPt1bWW.js +24 -0
  77. package/dist/web/assets/directory-open-01563666-DWU9wJ6I.js +1 -0
  78. package/dist/web/assets/directory-open-4ed118d0-CunoC1EB.js +1 -0
  79. package/dist/web/assets/{download-UgMvjBjR.js → download-PQ08tuAg.js} +1 -1
  80. package/dist/web/assets/ebnfDiagram-PWID7BFC-BPO0ZRsN.js +1 -0
  81. package/dist/web/assets/el-GR-BZB4AONW-C6V4uhoK.js +10 -0
  82. package/dist/web/assets/erDiagram-RLTQ6QDP-BR2u7bIU.js +99 -0
  83. package/dist/web/assets/es-ES-U4NZUMDT-D_kwVnQr.js +9 -0
  84. package/dist/web/assets/eu-ES-A7QVB2H4-Eeu5vgta.js +11 -0
  85. package/dist/web/assets/excalidraw/fonts/Assistant/Assistant-Bold.woff2 +0 -0
  86. package/dist/web/assets/excalidraw/fonts/Assistant/Assistant-Medium.woff2 +0 -0
  87. package/dist/web/assets/excalidraw/fonts/Assistant/Assistant-Regular.woff2 +0 -0
  88. package/dist/web/assets/excalidraw/fonts/Assistant/Assistant-SemiBold.woff2 +0 -0
  89. package/dist/web/assets/excalidraw/fonts/Cascadia/CascadiaCode-Regular.woff2 +0 -0
  90. package/dist/web/assets/excalidraw/fonts/ComicShanns/ComicShanns-Regular-279a7b317d12eb88de06167bd672b4b4.woff2 +0 -0
  91. package/dist/web/assets/excalidraw/fonts/ComicShanns/ComicShanns-Regular-6e066e8de2ac57ea9283adb9c24d7f0c.woff2 +0 -0
  92. package/dist/web/assets/excalidraw/fonts/ComicShanns/ComicShanns-Regular-dc6a8806fa96795d7b3be5026f989a17.woff2 +0 -0
  93. package/dist/web/assets/excalidraw/fonts/ComicShanns/ComicShanns-Regular-fcb0fc02dcbee4c9846b3e2508668039.woff2 +0 -0
  94. package/dist/web/assets/excalidraw/fonts/Excalifont/Excalifont-Regular-349fac6ca4700ffec595a7150a0d1e1d.woff2 +0 -0
  95. package/dist/web/assets/excalidraw/fonts/Excalifont/Excalifont-Regular-3f2c5db56cc93c5a6873b1361d730c16.woff2 +0 -0
  96. package/dist/web/assets/excalidraw/fonts/Excalifont/Excalifont-Regular-41b173a47b57366892116a575a43e2b6.woff2 +0 -0
  97. package/dist/web/assets/excalidraw/fonts/Excalifont/Excalifont-Regular-623ccf21b21ef6b3a0d87738f77eb071.woff2 +0 -0
  98. package/dist/web/assets/excalidraw/fonts/Excalifont/Excalifont-Regular-a88b72a24fb54c9f94e3b5fdaa7481c9.woff2 +0 -0
  99. package/dist/web/assets/excalidraw/fonts/Excalifont/Excalifont-Regular-b9dcf9d2e50a1eaf42fc664b50a3fd0d.woff2 +0 -0
  100. package/dist/web/assets/excalidraw/fonts/Excalifont/Excalifont-Regular-be310b9bcd4f1a43f571c46df7809174.woff2 +0 -0
  101. package/dist/web/assets/excalidraw/fonts/Liberation/LiberationSans-Regular.woff2 +0 -0
  102. package/dist/web/assets/excalidraw/fonts/Lilita/Lilita-Regular-i7dPIFZ9Zz-WBtRtedDbYE98RXi4EwSsbg.woff2 +0 -0
  103. package/dist/web/assets/excalidraw/fonts/Lilita/Lilita-Regular-i7dPIFZ9Zz-WBtRtedDbYEF8RXi4EwQ.woff2 +0 -0
  104. package/dist/web/assets/excalidraw/fonts/Nunito/Nunito-Regular-XRXI3I6Li01BKofiOc5wtlZ2di8HDIkhdTA3j6zbXWjgevT5.woff2 +0 -0
  105. package/dist/web/assets/excalidraw/fonts/Nunito/Nunito-Regular-XRXI3I6Li01BKofiOc5wtlZ2di8HDIkhdTQ3j6zbXWjgeg.woff2 +0 -0
  106. package/dist/web/assets/excalidraw/fonts/Nunito/Nunito-Regular-XRXI3I6Li01BKofiOc5wtlZ2di8HDIkhdTk3j6zbXWjgevT5.woff2 +0 -0
  107. package/dist/web/assets/excalidraw/fonts/Nunito/Nunito-Regular-XRXI3I6Li01BKofiOc5wtlZ2di8HDIkhdTo3j6zbXWjgevT5.woff2 +0 -0
  108. package/dist/web/assets/excalidraw/fonts/Nunito/Nunito-Regular-XRXI3I6Li01BKofiOc5wtlZ2di8HDIkhdTs3j6zbXWjgevT5.woff2 +0 -0
  109. package/dist/web/assets/excalidraw/fonts/Virgil/Virgil-Regular.woff2 +0 -0
  110. package/dist/web/assets/fa-IR-HGAKTJCU-CKd62s_f.js +8 -0
  111. package/dist/web/assets/fi-FI-Z5N7JZ37-CXq3Xbio.js +6 -0
  112. package/dist/web/assets/file-open-002ab408-DIuFHtCF.js +1 -0
  113. package/dist/web/assets/file-open-7c801643-684qeFg4.js +1 -0
  114. package/dist/web/assets/file-save-3189631c-C1wFhQhH.js +1 -0
  115. package/dist/web/assets/file-save-745eba88-Bb9F9Kg7.js +1 -0
  116. package/dist/web/assets/{flowDiagram-HODETNUW-DueO0Ju6.js → flowDiagram-HODETNUW-DtCUIQgA.js} +5 -5
  117. package/dist/web/assets/folder-open-D0jNv68L.js +11 -0
  118. package/dist/web/assets/fr-FR-RHASNOE6-BUQsSuUv.js +9 -0
  119. package/dist/web/assets/ganttDiagram-EL5Y4UJY-DtAyQ0Yy.js +292 -0
  120. package/dist/web/assets/gitGraphDiagram-WWUBYQGX-CoXp0Ypy.js +106 -0
  121. package/dist/web/assets/gl-ES-HMX3MZ6V-DW4qfI2b.js +10 -0
  122. package/dist/web/assets/he-IL-6SHJWFNN-DaY9mSnj.js +10 -0
  123. package/dist/web/assets/hi-IN-IWLTKZ5I-D2lbPu3U.js +4 -0
  124. package/dist/web/assets/highlighted-body-KPVGNVTW-BmPHGwPQ.js +1 -0
  125. package/dist/web/assets/hu-HU-A5ZG7DT2-Bos6dFhw.js +7 -0
  126. package/dist/web/assets/id-ID-SAP4L64H-cWyYCXM5.js +10 -0
  127. package/dist/web/assets/image-blob-reduce.esm-D6s-rqMO.js +7 -0
  128. package/dist/web/assets/index-CY60J5zm.css +1 -0
  129. package/dist/web/assets/{index-C_jtMgr7.js → index-CYCjrqhG.js} +124 -114
  130. package/dist/web/assets/index-CcfSzlv5.js +19 -0
  131. package/dist/web/assets/infoDiagram-27XIBGKW-C2Ypr-zs.js +2 -0
  132. package/dist/web/assets/{ishikawaDiagram-5VMMS53U-ccIPCUs4.js → ishikawaDiagram-5VMMS53U-Bx7qtMkV.js} +5 -5
  133. package/dist/web/assets/it-IT-JPQ66NNP-CRGQFEpH.js +11 -0
  134. package/dist/web/assets/ja-JP-DBVTYXUO-BXcfLN6y.js +8 -0
  135. package/dist/web/assets/{journeyDiagram-3NMN7TZE-rRe3uTLu.js → journeyDiagram-3NMN7TZE-rsuiVeG_.js} +2 -2
  136. package/dist/web/assets/kaa-6HZHGXH3-Bk6N-pLt.js +1 -0
  137. package/dist/web/assets/kab-KAB-ZGHBKWFO-Ctb8wAYx.js +8 -0
  138. package/dist/web/assets/{kanban-definition-UXKFOSKX-tAKCWntJ.js → kanban-definition-UXKFOSKX-5ktYMmTY.js} +6 -6
  139. package/dist/web/assets/kk-KZ-P5N5QNE5-CzQX2BL1.js +1 -0
  140. package/dist/web/assets/km-KH-HSX4SM5Z-DnDRwAqY.js +11 -0
  141. package/dist/web/assets/ko-KR-MTYHY66A-C6HKdiKS.js +9 -0
  142. package/dist/web/assets/ku-TR-6OUDTVRD-evaKSJwY.js +9 -0
  143. package/dist/web/assets/layout-DSZI9hxI.js +1 -0
  144. package/dist/web/assets/linear-omhrmwGQ.js +1 -0
  145. package/dist/web/assets/{list-BL4eRkIg.js → list-UGkABbTC.js} +1 -1
  146. package/dist/web/assets/live-sessions-C19eXx17.js +6 -0
  147. package/dist/web/assets/lt-LT-XHIRWOB4-BS7h6VOT.js +3 -0
  148. package/dist/web/assets/lv-LV-5QDEKY6T-CvKj-LUX.js +7 -0
  149. package/dist/web/assets/mermaid-HWGCJPDP-B_H4rk_s.js +299 -0
  150. package/dist/web/assets/mermaid.core-Bs68JjJM.js +312 -0
  151. package/dist/web/assets/{mindmap-definition-YA3MSWOX-Cj5-j6a7.js → mindmap-definition-YA3MSWOX-DKG9LDwL.js} +4 -4
  152. package/dist/web/assets/mr-IN-CRQNXWMA-C_9ZWEOY.js +13 -0
  153. package/dist/web/assets/my-MM-5M5IBNSE-Bic5Rd4I.js +1 -0
  154. package/dist/web/assets/nb-NO-T6EIAALU-BN5D6e6X.js +10 -0
  155. package/dist/web/assets/nl-NL-IS3SIHDZ-CLmoJxpw.js +8 -0
  156. package/dist/web/assets/nn-NO-6E72VCQL-DH3pWtEG.js +8 -0
  157. package/dist/web/assets/oc-FR-POXYY2M6-DzJwOBaL.js +8 -0
  158. package/dist/web/assets/pa-IN-N4M65BXN-CxFRfqt4.js +4 -0
  159. package/dist/web/assets/pegDiagram-XKGWAZYB-D_-uCYBR.js +1 -0
  160. package/dist/web/assets/{pencil-gxvh59uO.js → pencil-_hID3D0m.js} +1 -1
  161. package/dist/web/assets/percentages-BXMCSKIN-DGBKIvAv.css +1 -0
  162. package/dist/web/assets/percentages-BXMCSKIN-DtfDKj6k.js +180 -0
  163. package/dist/web/assets/pica-sWD7KYN4.js +7 -0
  164. package/dist/web/assets/pieDiagram-E7YTZNPT-Cxcz8v2V.js +39 -0
  165. package/dist/web/assets/pl-PL-T2D74RX3-DFEd2a_2.js +9 -0
  166. package/dist/web/assets/pt-BR-5N22H2LF-d_zvXQ30.js +9 -0
  167. package/dist/web/assets/pt-PT-UZXXM6DQ-5FeuC95-.js +9 -0
  168. package/dist/web/assets/{quadrantDiagram-AXDQQJYC-DKTP6jS5.js → quadrantDiagram-AXDQQJYC-5W1D624h.js} +1 -1
  169. package/dist/web/assets/railroadDiagram-O6MQD6OU-BZhsOHVF.js +1 -0
  170. package/dist/web/assets/{requirementDiagram-BXWQKSXE-B9hH69zu.js → requirementDiagram-BXWQKSXE-BXlonflD.js} +2 -2
  171. package/dist/web/assets/ro-RO-JPDTUUEW-CAJt20_T.js +11 -0
  172. package/dist/web/assets/roundRect-0PYZxl1G.js +1 -0
  173. package/dist/web/assets/ru-RU-B4JR7IUQ-BL-2B7Np.js +9 -0
  174. package/dist/web/assets/sankeyDiagram-P5KCCOFB-BZVh-M1g.js +40 -0
  175. package/dist/web/assets/{save-CYoz3QKB.js → save-C0v-3p0L.js} +1 -1
  176. package/dist/web/assets/save-file-B_ZN6-id.js +1 -0
  177. package/dist/web/assets/scratchpad-routes-DvtErr_v.js +11 -0
  178. package/dist/web/assets/scroll-area-Bgn8q6dm.js +1 -0
  179. package/dist/web/assets/{sequenceDiagram-WJ2MYXX4-BF77J63J.js → sequenceDiagram-WJ2MYXX4-B2WHT4e0.js} +2 -2
  180. package/dist/web/assets/si-LK-N5RQ5JYF-BwL9NXm1.js +1 -0
  181. package/dist/web/assets/sizeCapture-INFHLROL-BI8hpcc0.js +1 -0
  182. package/dist/web/assets/sk-SK-C5VTKIMK-DEJmCOdH.js +6 -0
  183. package/dist/web/assets/sl-SI-NN7IZMDC-BNyfGsJr.js +6 -0
  184. package/dist/web/assets/stateDiagram-D77RDMKH-yCTyY4sx.js +1 -0
  185. package/dist/web/assets/stateDiagram-v2-MP3YSRHH-DMV9Hi6h.js +1 -0
  186. package/dist/web/assets/subset-shared.chunk-en_zPkcm.js +84 -0
  187. package/dist/web/assets/subset-worker.chunk-D4Jfgczh.js +1 -0
  188. package/dist/web/assets/sv-SE-XGPEYMSR-CcrID0kB.js +10 -0
  189. package/dist/web/assets/swimlanes-42K2YHIH-CsXemLHu.js +1 -0
  190. package/dist/web/assets/swimlanesDiagram-VR7AAH4N-wKC0jJ-D.js +8 -0
  191. package/dist/web/assets/ta-IN-2NMHFXQM-1Q6gAmCa.js +9 -0
  192. package/dist/web/assets/{table-D3N_5Wee.js → table-D-x54JQs.js} +1 -1
  193. package/dist/web/assets/tabs-Dwtb498J.js +1 -0
  194. package/dist/web/assets/th-TH-HPSO5L25-Osf6RMxs.js +2 -0
  195. package/dist/web/assets/{timeline-definition-24CTP7MA-owGoHn8z.js → timeline-definition-24CTP7MA-BcjYHSKM.js} +8 -8
  196. package/dist/web/assets/tr-TR-DEFEU3FU-olIwbQqc.js +7 -0
  197. package/dist/web/assets/{trash-2-D3Ey4I09.js → trash-2-C4wuE82r.js} +1 -1
  198. package/dist/web/assets/uk-UA-QMV73CPH-_0ICAhhw.js +6 -0
  199. package/dist/web/assets/{upload-DhVOCWST.js → upload-Cq-d5iVn.js} +1 -1
  200. package/dist/web/assets/{useDetailRoute-j9nlwack.js → useDetailRoute-DiC2IR0t.js} +1 -1
  201. package/dist/web/assets/{useJobs-Dcl-Vim3.js → useJobs-TDZx1N1l.js} +1 -1
  202. package/dist/web/assets/{useKnowledge-gIjk0_I1.js → useKnowledge-cE7nsoOf.js} +1 -1
  203. package/dist/web/assets/{useListSelection-CSQd_Hmx.js → useListSelection-tj_f-2Ad.js} +1 -1
  204. package/dist/web/assets/{useMemories-B8Zpz0Qz.js → useMemories-rjShoqd3.js} +1 -1
  205. package/dist/web/assets/useProjectScope-DaFHoG4_.js +1 -0
  206. package/dist/web/assets/{useSessions-BrdK-12R.js → useSessions-BNsSZXqv.js} +1 -1
  207. package/dist/web/assets/vennDiagram-4TSXK5OY-BIC5NL2Q.js +34 -0
  208. package/dist/web/assets/vi-VN-M7AON7JQ-CZHjInAz.js +5 -0
  209. package/dist/web/assets/{view-params-Bm1Qf6KC.js → view-params-Duc_5Bxj.js} +1 -1
  210. package/dist/web/assets/{wardleyDiagram-VM6X3IG4-D9GbTBKy.js → wardleyDiagram-VM6X3IG4-BJqqp-BL.js} +2 -2
  211. package/dist/web/assets/{xychartDiagram-S5SC5T6Z-BFqPF2Hl.js → xychartDiagram-S5SC5T6Z-CMANcsti.js} +4 -4
  212. package/dist/web/assets/zh-CN-LNUGB5OW-z21ZnHQB.js +10 -0
  213. package/dist/web/assets/zh-HK-E62DVLB3-C-RnadUL.js +1 -0
  214. package/dist/web/assets/zh-TW-RAJ6MFWO-Vua3CLAj.js +9 -0
  215. package/dist/web/index.html +2 -2
  216. package/package.json +1 -1
  217. package/dist/web/assets/Dashboard-V813oIhq.js +0 -1
  218. package/dist/web/assets/Knowledge-BpiN3iVE.js +0 -28
  219. package/dist/web/assets/Projects-DRao5Qpk.js +0 -3
  220. package/dist/web/assets/ResumeActions-DHTOr6GQ.js +0 -11
  221. package/dist/web/assets/Sessions-CWHU6sYy.js +0 -5
  222. package/dist/web/assets/abnfDiagram-VCTEODGH-K8P_VxLi.js +0 -1
  223. package/dist/web/assets/arc-BOl9BKfD.js +0 -1
  224. package/dist/web/assets/architectureDiagram-5GKGNRK7-DIZ15fO5.js +0 -36
  225. package/dist/web/assets/channel-CQFNQIhG.js +0 -1
  226. package/dist/web/assets/chunk-2Q5K7J3B-wRIxA2_q.js +0 -1
  227. package/dist/web/assets/chunk-F27PBJKO-DVuei-Pl.js +0 -1
  228. package/dist/web/assets/chunk-JWPE2WC7-zdsOarNZ.js +0 -1
  229. package/dist/web/assets/chunk-POPQ4Y6H-D3ieeKih.js +0 -1
  230. package/dist/web/assets/chunk-XXDRQBXY-BoTHwisB.js +0 -1
  231. package/dist/web/assets/classDiagram-ZZMXUADV-B5yD90Df.js +0 -1
  232. package/dist/web/assets/classDiagram-v2-VYDZK3BY-B5yD90Df.js +0 -1
  233. package/dist/web/assets/cose-bilkent-JH36ORCC-CtGsuuTW.js +0 -1
  234. package/dist/web/assets/cynefinDiagram-5FMLGOSQ-kMbm5D7e.js +0 -62
  235. package/dist/web/assets/diagram-UQ7AKVKN-CMX0u7Gf.js +0 -41
  236. package/dist/web/assets/diagram-VX7I27RA-Bp_JbX0e.js +0 -24
  237. package/dist/web/assets/diagram-Z3DM3KII-oZ6jRSCd.js +0 -24
  238. package/dist/web/assets/ebnfDiagram-PWID7BFC-DbxnEjb0.js +0 -1
  239. package/dist/web/assets/erDiagram-RLTQ6QDP-Cl5kXPho.js +0 -99
  240. package/dist/web/assets/folder-open-DojCP5NP.js +0 -16
  241. package/dist/web/assets/ganttDiagram-EL5Y4UJY-DNjT4iVH.js +0 -292
  242. package/dist/web/assets/gitGraphDiagram-WWUBYQGX-B4aUQ9gY.js +0 -106
  243. package/dist/web/assets/highlighted-body-KPVGNVTW-gt1u8RcC.js +0 -1
  244. package/dist/web/assets/index-CyjfnRiI.css +0 -1
  245. package/dist/web/assets/infoDiagram-27XIBGKW-CWcOvNAB.js +0 -2
  246. package/dist/web/assets/layout-7xCiQ5Mn.js +0 -1
  247. package/dist/web/assets/linear-WCNhc07o.js +0 -1
  248. package/dist/web/assets/mermaid-HWGCJPDP-C8QwWdo5.js +0 -609
  249. package/dist/web/assets/pegDiagram-XKGWAZYB-BYB3oVZ_.js +0 -1
  250. package/dist/web/assets/pieDiagram-E7YTZNPT-CSbpzXas.js +0 -39
  251. package/dist/web/assets/railroadDiagram-O6MQD6OU-Ct8aPeLX.js +0 -1
  252. package/dist/web/assets/refresh-cw-BQRdbjy6.js +0 -6
  253. package/dist/web/assets/sankeyDiagram-P5KCCOFB-CDqNONxU.js +0 -40
  254. package/dist/web/assets/scroll-area-CU4DGUBA.js +0 -1
  255. package/dist/web/assets/sizeCapture-INFHLROL-Dpubco_U.js +0 -1
  256. package/dist/web/assets/stateDiagram-D77RDMKH-CzslKEYw.js +0 -1
  257. package/dist/web/assets/stateDiagram-v2-MP3YSRHH-DKbNjyV-.js +0 -1
  258. package/dist/web/assets/swimlanes-42K2YHIH-bD_tUjo6.js +0 -1
  259. package/dist/web/assets/swimlanesDiagram-VR7AAH4N-0wAluWQF.js +0 -8
  260. package/dist/web/assets/tabs-CSlEXoxD.js +0 -1
  261. package/dist/web/assets/useProjectScope-Dk0mjyHf.js +0 -1
  262. package/dist/web/assets/vennDiagram-4TSXK5OY-D0_6bldW.js +0 -34
@@ -1 +0,0 @@
1
- import{H as E,X as U,Y as V,e as H,M as I,j as t,S as J}from"./index-C_jtMgr7.js";import{E as Q}from"./ErrorState-BPTepwiG.js";import{P as T}from"./PriorityBadge-BW-A50LE.js";import{f as q,S,R as W}from"./ResumeActions-DHTOr6GQ.js";import{S as L}from"./StatusBadge-C5G1fdZh.js";import{T as z,a as O,b as $,c as h,d as X,e as p}from"./table-D3N_5Wee.js";import{u as Y}from"./useJobs-Dcl-Vim3.js";import{u as F}from"./useMemories-B8Zpz0Qz.js";import{u as G}from"./useProjectScope-Dk0mjyHf.js";import{u as K}from"./useSessions-BrdK-12R.js";function l(d,v){return d.isLoading?"…":d.error?"—":v}function os({projectId:d}){var f,_;const v=E(),a=G(d),D=U("sm"),i=s=>{const e=new URL(s,window.location.origin);e.searchParams.set("project",a),v({pathname:e.pathname,search:e.search,hash:e.hash})},o=a==="all"||a==="unassigned"?void 0:{project_id:a},c=V(o),{data:b,isLoading:P}=c,u=Y(o),{data:N}=u,m=F({project_id:o==null?void 0:o.project_id,limit:1},{enabled:a!=="unassigned"}),R=a==="unassigned"?0:((f=m.data)==null?void 0:f.total)??0,{data:n}=H(),j=K(!0),g=(j.data??[]).filter(s=>a==="all"||(a==="unassigned"?s.project_id===null:s.project_id===a)),w=a==="unassigned"?(N??[]).filter(s=>s.project_id===null):N??[],k=a==="unassigned"?(b??[]).filter(s=>s.project_id===null):b??[],r=k.reduce((s,e)=>(s[e.status]=(s[e.status]??0)+1,s),{}),y=[...k].sort((s,e)=>new Date(e.updated_at).getTime()-new Date(s.updated_at).getTime()).slice(0,8),x=w.filter(s=>s.enabled),A=a==="all"?"All Projects":a==="unassigned"?"Unassigned":((_=n==null?void 0:n.find(s=>s.id===a))==null?void 0:_.name)??"",M=[{label:"Doing",value:l(c,r.doing??0),sub:"in progress",path:"/tasks?view=table&status=doing"},{label:"Review",value:l(c,r.review??0),sub:"awaiting review",path:"/tasks?view=table&status=review"},{label:"Blocked",value:l(c,r.blocked??0),sub:"needs attention",path:"/tasks?view=table&status=blocked"},{label:"Todo",value:l(c,(r.todo??0)+(r.queued??0)),sub:"pending",path:"/tasks?view=board"},{label:"Done",value:l(c,r.done??0),sub:"completed",path:"/tasks?view=table&status=done"}],B=[{label:"Active jobs",value:l(u,x.length),sub:`of ${w.length} total`,path:"/jobs"},{label:"Memories",value:l(m,R),sub:"in this scope",path:I},{label:"Projects",value:(n??[]).filter(s=>s.status==="active").length,sub:"active across workspace",path:"/projects"}];return t.jsxs("div",{"data-activity-preview":!0,"data-testid":"activity-preview",className:"activity-preview",children:[t.jsxs("div",{className:"activity-heading",children:[t.jsxs("div",{children:[t.jsx("h1",{"data-testid":"view-title",children:"Activity"}),t.jsx("p",{"data-testid":"view-meta",children:A||"All projects"})]}),t.jsx("button",{type:"button",className:"activity-primary",onClick:()=>i("/tasks"),children:"View tasks"})]}),[c,u,m,j].some(s=>s.isLoading)&&t.jsx("p",{role:"status",className:"activity-muted mb-4",children:"Loading activity…"}),[{name:"Tasks",query:c},{name:"Jobs",query:u},{name:"Memories",query:m},{name:"Sessions",query:j}].filter(({query:s})=>s.error).map(({name:s,query:e})=>{var C;return t.jsx(Q,{message:`${s}: ${((C=e.error)==null?void 0:C.message)??"Could not load activity"}`,onRetry:()=>e.refetch()},s)}),t.jsx("section",{className:"activity-metrics","aria-label":"Task summary",children:M.map(s=>t.jsxs("button",{type:"button","data-testid":"stat-card","data-stat-label":s.label,className:"activity-metric",onClick:()=>i(s.path),children:[t.jsx("span",{className:"activity-metric-label",children:s.label}),t.jsx("span",{"data-testid":"stat-card-value",className:"activity-metric-value",children:s.value}),t.jsx("span",{className:"activity-metric-sub",children:s.sub})]},s.label))}),t.jsx("section",{className:"activity-resources","aria-label":"Workspace summary",children:B.map(s=>t.jsxs("button",{type:"button","data-testid":"stat-card","data-stat-label":s.label,onClick:()=>i(s.path),children:[t.jsx("span",{children:s.label}),t.jsx("span",{"data-testid":"stat-card-value",className:"activity-resource-value",children:s.value}),t.jsx("span",{className:"activity-resource-sub",children:s.sub})]},s.label))}),t.jsxs("section",{className:"activity-section",children:[t.jsxs("div",{className:"activity-section-heading",children:[t.jsx("h2",{children:"Recent tasks"}),t.jsx("button",{type:"button",className:"activity-text-action",onClick:()=>i("/tasks"),children:"View all"})]}),P?t.jsx("div",{className:"space-y-2",children:[0,1,2,3].map(s=>t.jsx(J,{className:"h-10 w-full"},s))}):y.length===0?t.jsx("p",{className:"activity-empty",children:"No tasks"}):D?t.jsxs(z,{className:"activity-task-table",children:[t.jsx(O,{children:t.jsxs($,{children:[t.jsx(h,{children:"Task"}),t.jsx(h,{className:"w-36",children:"Status"}),t.jsx(h,{className:"w-28",children:"Priority"}),t.jsx(h,{className:"w-28",children:"Updated"})]})}),t.jsx(X,{children:y.map(s=>t.jsxs($,{onClick:()=>i(`/tasks/${s.id}`),children:[t.jsx(p,{children:t.jsx("button",{type:"button",className:"activity-task-title",onClick:e=>{e.stopPropagation(),i(`/tasks/${s.id}`)},children:s.title})}),t.jsx(p,{children:t.jsx("span",{className:"activity-status","data-status":s.status,children:t.jsx(L,{status:s.status})})}),t.jsx(p,{children:t.jsx("span",{className:"activity-priority",children:t.jsx(T,{priority:s.priority})})}),t.jsx(p,{className:"activity-muted",children:new Date(s.updated_at).toLocaleDateString()})]},s.id))})]}):t.jsx("div",{className:"activity-task-list",children:y.map(s=>t.jsxs("article",{className:"activity-task-mobile",children:[t.jsx("button",{type:"button",className:"activity-task-title",onClick:()=>i(`/tasks/${s.id}`),children:s.title}),t.jsxs("div",{className:"activity-task-meta",children:[t.jsx("span",{className:"activity-status","data-status":s.status,children:t.jsx(L,{status:s.status})}),t.jsx("span",{className:"activity-priority",children:t.jsx(T,{priority:s.priority})}),t.jsx("span",{children:new Date(s.updated_at).toLocaleDateString()})]})]},s.id))})]}),t.jsxs("div",{className:"activity-secondary",children:[x.length>0&&t.jsxs("section",{className:"activity-section",children:[t.jsxs("div",{className:"activity-section-heading",children:[t.jsx("h2",{children:"Active jobs"}),t.jsx("button",{type:"button",className:"activity-text-action",onClick:()=>i("/jobs"),children:"View all"})]}),t.jsx("div",{className:"activity-row-list",children:x.slice(0,5).map(s=>t.jsxs("button",{type:"button",className:"activity-row",onClick:()=>i(`/jobs/${s.id}`),children:[t.jsxs("span",{className:"activity-row-heading",children:[t.jsx("span",{children:s.name}),t.jsx("span",{className:"activity-muted",children:s.trigger_type})]}),s.last_run_at&&t.jsxs("span",{className:"activity-row-description",children:["Last run ",new Date(s.last_run_at).toLocaleString()]})]},s.id))})]}),g.length>0&&t.jsxs("section",{className:"activity-section",children:[t.jsxs("div",{className:"activity-section-heading",children:[t.jsx("h2",{children:"Agent sessions"}),t.jsx("button",{type:"button",className:"activity-text-action",onClick:()=>i("/sessions"),children:"View all"})]}),t.jsx("div",{className:"activity-row-list",children:g.slice(0,5).map(s=>t.jsxs("div",{className:"activity-row",children:[t.jsxs("button",{type:"button",className:"w-full text-left","data-testid":"activity-session-link","data-session-id":s.id,onClick:()=>i(`/sessions?session=${encodeURIComponent(s.id)}`),children:[t.jsxs("span",{className:"activity-row-heading",children:[t.jsx("span",{children:s.name??s.agent}),t.jsx("span",{className:"activity-muted",children:q(s.last_activity_at)})]}),t.jsxs("span",{className:"activity-row-description inline-flex items-center gap-2",children:[t.jsx("span",{className:`size-1.5 rounded-full ${S[s.status].dot}`}),s.agent," · ",S[s.status].label,s.task?` · ${s.task.title}`:""]})]}),t.jsx(W,{session:s})]},s.id))})]})]}),a==="all"&&(n??[]).length>0&&t.jsxs("section",{className:"activity-section",children:[t.jsxs("div",{className:"activity-section-heading",children:[t.jsx("h2",{children:"Projects"}),t.jsx("button",{type:"button",className:"activity-text-action",onClick:()=>i("/projects"),children:"View all"})]}),t.jsx("div",{className:"activity-projects",children:(n??[]).filter(s=>s.status==="active").slice(0,6).map(s=>t.jsxs("button",{type:"button",className:"activity-row",onClick:()=>i(`/projects/${s.id}`),children:[t.jsx("span",{className:"activity-row-heading",children:s.name}),s.description&&t.jsx("span",{className:"activity-row-description",children:s.description})]},s.id))})]})]})}export{os as default};
@@ -1,28 +0,0 @@
1
- import{c as ve,b6 as _,b1 as H,b3 as re,b0 as O,b8 as q,ba as tt,bb as ps,b5 as Oe,b2 as _t,b7 as fs,b4 as bs,j as e,K as U,r as m,E as Ee,B as y,L as St,d as T,bS as Pe,e as ke,I as B,T as xe,q as he,s as pe,t as fe,v as be,w as X,x as le,bt as Ct,bT as Ge,J as Dt,D as $t,m as Et,n as Pt,o as Rt,p as ie,ak as gs,aU as st,aW as js,a as ys,bU as vs,G as zt,X as Lt,ap as ks,aq as Ns,ar as ws,as as _s,bV as at,a8 as Tt,a9 as Mt,aa as At,ab as Ft,ac as It,P as $e,bW as Ss,a$ as Cs,bu as Ds,H as $s,O as Kt,N as Es,a_ as Ut,S as Ye,bX as Ps,M as Rs,y as de,bY as nt,bZ as Ce,b_ as Bt,b$ as zs,c0 as Ls,c1 as Ts,c2 as Ms,c3 as As,c4 as Fs,c5 as Is,c6 as Ks}from"./index-C_jtMgr7.js";import{D as Us,c as Bs}from"./DocumentWorkspace-CNyVQTjg.js";import{E as Qe}from"./ErrorState-BPTepwiG.js";import{C as Re}from"./ConfirmDialog-CrSa87VF.js";import{d as Os,c as V,e as Hs,f as ze,a as Ot,g as Ws,K as qs,h as Vs,i as Ht,j as Gs,k as Ys,l as Qs,m as Xs,n as Js,o as Zs,p as ea,b as ta}from"./useKnowledge-gIjk0_I1.js";import{T as Le}from"./trash-2-D3Ey4I09.js";import{U as Wt}from"./upload-DhVOCWST.js";import{w as sa}from"./wiki-links-Y6CQL1QZ.js";import{E as aa,F as na,A as ia}from"./folder-open-DojCP5NP.js";import{P as qt}from"./pencil-gxvh59uO.js";import{D as ra}from"./download-UgMvjBjR.js";import{R as la}from"./refresh-cw-BQRdbjy6.js";import{u as oa}from"./useProjectScope-Dk0mjyHf.js";import{E as it}from"./EmptyState-Ctm7L70B.js";import{T as da,a as ca,b as rt,c as ce,d as ua,e as ue}from"./table-D3N_5Wee.js";import{V as ma}from"./ViewHeader-DXR0ZaMO.js";import{a as xa,u as ha,b as pa,c as fa,d as ba,e as ga,f as ja,g as ya}from"./useMemories-B8Zpz0Qz.js";import{u as Ae}from"./view-params-Bm1Qf6KC.js";/**
2
- * @license lucide-react v1.27.0 - ISC
3
- *
4
- * This source code is licensed under the ISC license.
5
- * See the LICENSE file in the root directory of this source tree.
6
- */const va=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M12 18v-6",key:"17g6i2"}],["path",{d:"m9 15 3 3 3-3",key:"1npd3o"}]],ka=ve("file-down",va);/**
7
- * @license lucide-react v1.27.0 - ISC
8
- *
9
- * This source code is licensed under the ISC license.
10
- * See the LICENSE file in the root directory of this source tree.
11
- */const Na=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M9 15h6",key:"cctwl0"}],["path",{d:"M12 18v-6",key:"17g6i2"}]],wa=ve("file-plus",Na);/**
12
- * @license lucide-react v1.27.0 - ISC
13
- *
14
- * This source code is licensed under the ISC license.
15
- * See the LICENSE file in the root directory of this source tree.
16
- */const _a=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M12 12v6",key:"3ahymv"}],["path",{d:"m15 15-3-3-3 3",key:"15xj92"}]],Sa=ve("file-up",_a);/**
17
- * @license lucide-react v1.27.0 - ISC
18
- *
19
- * This source code is licensed under the ISC license.
20
- * See the LICENSE file in the root directory of this source tree.
21
- */const Ca=[["path",{d:"M9 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v.5",key:"1dkoa9"}],["path",{d:"M12 10v4h4",key:"1czhmt"}],["path",{d:"m12 14 1.535-1.605a5 5 0 0 1 8 1.5",key:"lvuxfi"}],["path",{d:"M22 22v-4h-4",key:"1ewp4q"}],["path",{d:"m22 18-1.535 1.605a5 5 0 0 1-8-1.5",key:"14ync0"}]],Vt=ve("folder-sync",Ca);/**
22
- * @license lucide-react v1.27.0 - ISC
23
- *
24
- * This source code is licensed under the ISC license.
25
- * See the LICENSE file in the root directory of this source tree.
26
- */const Da=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}]],$a=ve("panel-right",Da),se=["mcp","api","cli","ui"],lt=["fetch","cited","search_hit"],Gt=_().trim().min(1).max(120),Yt=H(re(se)).max(se.length).transform(t=>se.filter(s=>t.includes(s)));O({name:Gt,description:_().trim().max(2e3).default(""),project_id:_().min(1).nullable(),editable_by:Yt.default([...se]),parser:_().min(1).max(40).nullable().default(null)}).strict();O({name:Gt.optional(),description:_().trim().max(2e3).optional(),editable_by:Yt.optional(),parser:_().min(1).max(40).nullable().optional()}).strict();const Ea=["default","project","global","all"],Qt=_().trim().min(1).max(500).refine(t=>!t.startsWith("/")&&!t.includes("\\")&&!t.includes(":")&&!t.includes("\0")&&t.split("/").every(s=>s&&s!=="."&&s!==".."),"Use a relative path with / separators and no . or .. segments"),Xt=H(_().trim().min(1).max(60)).max(30),ye=2*1024*1024;O({title:_().trim().min(1).max(300),path:Qt.optional(),description:_().trim().max(2e3).optional(),labels:Xt.default([]),content:_().max(ye),note:_().trim().max(1e3).optional(),derived_from:H(_().min(1)).max(50).default([])}).strict();O({expected_revision:q().int().min(1),title:_().trim().min(1).max(300).optional(),path:Qt.optional(),description:_().trim().max(2e3).optional(),labels:Xt.optional(),content:_().max(ye).optional(),note:_().trim().max(1e3).optional(),derived_from:H(_().min(1)).max(50).optional()}).strict();const Pa=1,Ra=["heading","paragraph","list_item","table","code"],za=O({kind:re(Ra),text:_(),level:q().int().min(1).max(6).optional(),rows:H(H(_())).optional(),heading_path:H(_()),locator:O({page:q().int().min(1).optional(),sheet:_().optional(),bbox:H(q()).length(4).optional()}).optional()});O({schema_version:Oe(Pa),parser:O({id:_(),version:_(),options:tt(_(),ps())}),source_sha256:_().regex(/^[0-9a-f]{64}$/),status:re(["ok","partial","failed"]),language:_().optional(),blocks:H(za),markdown:_(),warnings:H(_()),timings_ms:tt(_(),q()).optional(),peak_rss_mb:q().optional()});const Jt=["auto","lexical","semantic","hybrid"],La=O({query:_().trim().min(1).max(2e3),scope:re(Ea).default("default"),kb_ids:H(_().min(1)).max(50).optional(),labels:H(_().min(1)).max(20).optional(),media_types:H(_().min(1)).max(20).optional(),mode:re(Jt).default("auto"),limit:q().int().min(1).max(50).default(10)}).strict();La.omit({limit:!0,mode:!0}).extend({mode:re(Jt).default("auto"),token_budget:q().int().min(500).max(32e3).default(6e3),max_per_document:q().int().min(1).max(10).default(3)}).strict();const Ta=O({old:_().min(1).max(ye),new:_().max(ye),replace_all:_t().optional()}).strict(),Ma=O({start_line:q().int().min(1),end_line:q().int().min(0),new:_().max(ye)}).strict();O({expected_revision:q().int().min(1),edits:H(fs([Ta,Ma])).min(1).max(50),note:_().trim().min(1).max(1e3)}).strict();const Aa=["open","resolved","dismissed"];O({document_id:_().min(1).nullable().optional(),body:_().trim().min(1).max(1e4)}).strict();O({status:re(["resolved","dismissed"]),reply:_().trim().min(1).max(4e3)}).strict();const Fa=bs("type",[O({type:Oe("cron"),cron:_().trim().min(1).max(120)}).strict(),O({type:Oe("manual")}).strict()]);O({instructions:_().trim().min(1).max(2e4).optional(),backend:_().min(1).max(64).regex(/^[a-z][a-z0-9_-]*$/).optional(),schedule:Fa.optional(),enabled:_t().optional(),timeout_secs:q().int().min(60).max(7200).optional()}).strict();const Zt="0 3 * * *";function Ne({title:t,testId:s,toggleTestId:n,summary:a,actions:i,expanded:l=!1,onExpandedChange:r,heading:o="h3",compact:d=!1,children:p}){const c=m.useId(),x=p!==void 0&&r!==void 0;return e.jsxs("section",{"data-testid":s,"data-expanded":x?l:void 0,"aria-labelledby":`${c}-heading`,className:"min-w-0 text-sm",children:[e.jsxs("div",{className:U("grid min-h-12 min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 gap-y-0.5 py-1.5",!d&&"sm:grid-cols-[9rem_minmax(0,1fr)_auto]"),children:[e.jsx(o,{id:`${c}-heading`,className:"min-w-0 font-medium",children:x?e.jsxs("button",{type:"button","data-testid":n,"aria-expanded":l,"aria-controls":c,className:"-ml-1 flex min-h-9 items-center gap-1.5 rounded px-1 text-left hover:bg-surface-high",onClick:()=>r(!l),children:[e.jsx(Ee,{size:14,"aria-hidden":!0,className:U("shrink-0 text-outline transition-transform",l&&"rotate-90")}),t]}):e.jsx("span",{className:"flex min-h-9 items-center pl-5",children:t})}),e.jsx("div",{className:U("col-span-2 row-start-2 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 pl-5",!d&&"sm:col-span-1 sm:col-start-2 sm:row-start-1 sm:pl-0"),children:a}),e.jsx("div",{className:U("col-start-2 row-start-1 flex items-center justify-end gap-1",!d&&"sm:col-start-3"),children:i})]}),x&&l&&e.jsx("div",{id:c,className:"min-w-0 pb-4 pl-5 pt-1",children:p})]})}function ae({tone:t}){return e.jsx("span",{"aria-hidden":!0,className:U("size-1.5 shrink-0 rounded-full",t==="ok"&&"bg-secondary",t==="warning"&&"bg-warning",t==="error"&&"bg-error",t==="off"&&"bg-muted-foreground",t==="progress"&&"bg-progress")})}const Te=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],De=/^\d+$/,me=t=>t.padStart(2,"0"),ot=t=>{var s;return(s=/^\*\/(\d+)$/.exec(t))==null?void 0:s[1]},dt=(t,s)=>t==="1"?`Every ${s}`:`Every ${t} ${s}s`;function es(t){const[s="",n="",a,i,l="",...r]=t.trim().split(/\s+/);if(r.length||a!=="*"||i!=="*")return t;if(n==="*"&&l==="*"){if(s==="*")return"Every minute";const p=ot(s);return p?dt(p,"minute"):De.test(s)?Number(s)?`Every hour at :${me(s)}`:"Every hour":t}if(!De.test(s))return t;const o=ot(n);if(o&&l==="*")return`${dt(o,"hour")}${Number(s)?` at :${me(s)}`:""}`;if(!De.test(n))return t;const d=`${me(n)}:${me(s)}`;return l==="*"?`Daily at ${d}`:l==="1-5"?`Weekdays at ${d}`:l==="0,6"||l==="6,0"?`Weekends at ${d}`:/^[0-7]$/.test(l)?`${Te[Number(l)%7]}s at ${d}`:t}const Ia=[{name:"minute",min:0,max:59,names:[]},{name:"hour",min:0,max:23,names:[]},{name:"day of month",min:1,max:31,names:[]},{name:"month",min:1,max:12,names:["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"]},{name:"weekday",min:0,max:7,names:["SUN","MON","TUE","WED","THU","FRI","SAT"]}];function Ka(t,s){const n=a=>{const i=s.names.indexOf(a.toUpperCase()),l=i>=0?i+(s.min===1?1:0):De.test(a)?Number(a):Number.NaN;return l>=s.min&&l<=s.max?l:Number.NaN};return t.split(",").every(a=>{const i=/^(\*|[a-z0-9]+(?:-[a-z0-9]+)?)(?:\/(\d+))?$/i.exec(a);if(!(i!=null&&i[1])||i[2]!==void 0&&Number(i[2])<1)return!1;if(i[1]==="*")return!0;const[l="",r]=i[1].split("-");return r===void 0?!Number.isNaN(n(l)):n(l)<=n(r)})}function Ua(t){const s=t.trim().split(/\s+/).filter(Boolean);if(!s.length)return"Enter a cron expression.";if(s.length!==5)return`A cron expression has 5 fields (minute hour day month weekday); this one has ${s.length}.`;for(const[n,a]of Ia.entries()){const i=s[n]??"";if(!Ka(i,a))return`The ${a.name} field "${i}" is not valid. Use a number from ${a.min} to ${a.max}, *, a range (1-5), a list (1,3) or a step (*/2).`}return null}function Ba(t){var a;const s=Math.max(0,Math.round((t-Date.now())/1e3));if(s<60)return"in under a minute";if(s<3600)return`in ${Math.round(s/60)}m`;if(s<86400)return`in ${Math.round(s/3600)}h`;const n=new Date(t);return`${(a=Te[n.getDay()])==null?void 0:a.slice(0,3)} ${me(String(n.getHours()))}:${me(String(n.getMinutes()))}`}function Xe(t){const s=Math.max(0,Math.round((Date.now()-t)/1e3));return s<60?"just now":s<3600?`${Math.round(s/60)}m ago`:s<86400?`${Math.round(s/3600)}h ago`:`${Math.round(s/86400)}d ago`}function Oa(t){var n;const s=(n=t.last_run)==null?void 0:n.status;return s==="running"?"progress":t.schedule.type==="cron"&&!t.enabled?"off":s==="failed"?"error":s==="completed"?"ok":"off"}function Ha({kb:t}){const s=Os(t.id),[n,a]=m.useState(null),[i,l]=m.useState(!1),r=s.data;return e.jsxs(e.Fragment,{children:[e.jsx(Ne,{title:"Digest",testId:"kb-digest",toggleTestId:"kb-digest-expand",expanded:i,onExpandedChange:l,summary:s.error?e.jsx("span",{role:"alert",className:"text-error",children:s.error.message}):s.isLoading?e.jsx("span",{className:"text-outline",children:"Loading…"}):r?e.jsx(Wa,{digest:r}):e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-outline","data-testid":"kb-digest-off",children:[e.jsx(ae,{tone:"off"}),"Off, documents change only when someone edits them"]}),actions:r?e.jsx(qa,{kb:t,digest:r,onStarted:()=>l(!0)}):s.data===null?e.jsx(y,{size:"sm",variant:"outline","data-testid":"kb-digest-add",onClick:()=>a("edit"),children:"Set up"}):null,children:r?e.jsx(Va,{kb:t,digest:r,onEdit:()=>a("edit")}):e.jsx("p",{className:"max-w-prose text-outline",children:"A digest is an agent that reads new memories, sessions and open comments, then keeps the documents in this knowledge base current. It can run on a schedule or only when you start it."})}),n==="edit"&&e.jsx(nn,{kb:t,digest:r??null,onClose:()=>a(null),onRemove:()=>a("remove")}),n==="remove"&&e.jsx(rn,{kb:t,onClose:()=>a(null)})]})}function Wa({digest:t}){const s=t.last_run,n=t.schedule.type==="manual"||t.enabled;return e.jsxs("span",{"data-testid":"kb-digest-summary",className:"inline-flex min-w-0 flex-wrap items-center gap-x-1.5",children:[e.jsx(ae,{tone:Oa(t)}),e.jsx("span",{"data-testid":"kb-digest-enabled",children:n?"On":"Paused"}),e.jsxs("span",{children:["·"," ",t.schedule.type==="manual"?"runs when you start it":e.jsx("span",{title:t.schedule.cron,children:es(t.schedule.cron)})]}),t.next_run_at!==null&&e.jsxs("span",{className:"text-outline","data-testid":"kb-digest-next-run",children:["·"," ",e.jsxs("span",{title:new Date(t.next_run_at).toLocaleString(),children:["next run ",Ba(t.next_run_at)]})]}),e.jsxs("span",{className:"text-outline","data-testid":"kb-digest-last-run","data-status":(s==null?void 0:s.status)??"never",children:["·"," ",s?s.status==="running"?"running now":e.jsxs("span",{title:new Date(s.at).toLocaleString(),children:["last run"," ",e.jsx("span",{className:s.status==="failed"?"text-error":void 0,children:s.status==="completed"?"succeeded":s.status})," ",Xe(s.at)]}):"not run yet"]})]})}function qa({kb:t,digest:s,onStarted:n}){var o;const a=V(),i=Y(),l=((o=s.last_run)==null?void 0:o.status)==="running";async function r(){await i.run(()=>T.kb.runDigest(t.id))&&(n(),await a())}return e.jsxs(e.Fragment,{children:[i.error&&e.jsx("span",{role:"alert",className:"text-error","data-testid":"kb-digest-error",children:i.error}),e.jsx(y,{size:"sm",variant:"outline","data-testid":"kb-digest-run",onClick:r,disabled:i.pending||l,children:l?"Running…":"Run now"})]})}function Va({kb:t,digest:s,onEdit:n}){const a=V(),i=Y(),l=Hs(t.id,s);async function r(){await i.run(()=>T.kb.setDigest(t.id,{enabled:!s.enabled}))&&await a()}return e.jsxs("div",{className:"min-w-0 space-y-3",children:[e.jsxs("p",{className:"max-w-prose text-outline",children:["The ",e.jsx("span",{className:"font-mono text-on-surface",children:s.backend})," agent reads new memories, sessions and open comments, then updates documents here."," ",e.jsx("span",{"data-testid":"kb-digest-open-comments",children:s.open_comments})," open"," ",s.open_comments===1?"comment waits":"comments wait"," for the next run."]}),e.jsxs("div",{className:"-ml-2 flex flex-wrap items-center gap-1",children:[e.jsx(y,{size:"sm",variant:"ghost","data-testid":"kb-digest-edit",onClick:n,children:"Edit instructions and schedule"}),s.schedule.type==="cron"&&e.jsx(y,{size:"sm",variant:"ghost","data-testid":"kb-digest-toggle",onClick:r,disabled:i.pending,children:s.enabled?"Pause schedule":"Resume schedule"}),e.jsx(y,{size:"sm",variant:"ghost",asChild:!0,children:e.jsx(St,{to:`/jobs/${encodeURIComponent(s.job_id)}`,"data-testid":"kb-digest-job",children:"Job history"})})]}),i.error&&e.jsx("p",{role:"alert",className:"text-error","data-testid":"kb-digest-error",children:i.error}),e.jsx(Ya,{runs:l.data??[]})]})}const Ga={failed:"error",success:"ok",running:"progress"};function Ya({runs:t}){return t.length?e.jsxs("div",{className:"space-y-1",children:[e.jsx("h4",{className:"text-xs font-medium text-outline",children:"Recent runs"}),e.jsx("ol",{"data-testid":"kb-digest-runs",className:"divide-y divide-outline-variant",children:t.map(s=>e.jsxs("li",{"data-testid":"kb-digest-run-row","data-status":s.status,className:"min-w-0 break-words py-1.5",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(ae,{tone:Ga[s.status]??"off"}),s.status]}),e.jsxs("span",{className:"text-outline",children:[" · ",s.started_at?e.jsx("span",{title:new Date(s.started_at).toLocaleString(),children:Xe(s.started_at)}):"not started",s.trigger_by?` · ${s.trigger_by}`:""]}),s.session_id&&e.jsx(St,{to:`/audit/${encodeURIComponent(s.session_id)}`,className:"ml-2 text-primary hover:underline",children:"Session"}),(s.error||s.summary)&&e.jsx("span",{className:"block truncate text-xs text-outline",title:s.error??s.summary??"",children:s.error??s.summary})]},s.run_id))})]}):e.jsx("p",{className:"text-outline",children:"No runs yet."})}const He=/[,\s]+/;function ct(t,s){const n=s.split(He).map(a=>a.trim()).filter(Boolean);return[...new Set([...t,...n])]}function ts({value:t,onChange:s,suggestions:n=[],placeholder:a="Add a label","aria-label":i,"data-testid":l}){const[r,o]=m.useState(""),d=m.useRef(null),p=m.useId(),c=n.filter(b=>!t.includes(b));function x(b){const h=ct(t,b);h.length!==t.length&&s(h),o("")}function k(b){const h=b.split(He);if(h.length>1){const D=h.pop()??"";s(ct(t,h.join(","))),o(D)}else o(b)}function j(b){(b.key==="Enter"||b.key==="Tab")&&r.trim()?(b.preventDefault(),x(r)):b.key==="Backspace"&&!r&&t.length>0&&(b.preventDefault(),s(t.slice(0,-1)))}function S(b){const h=b.clipboardData.getData("text");He.test(h)&&(b.preventDefault(),x(`${r},${h}`))}return e.jsxs("div",{className:U("flex min-h-10 w-full cursor-text flex-wrap items-center gap-1.5 rounded-md border border-control-border bg-surface px-2 py-1.5 text-sm","focus-within:ring-2 focus-within:ring-focus focus-within:ring-offset-2 ring-offset-background"),onClick:()=>{var b;return(b=d.current)==null?void 0:b.focus()},children:[t.map(b=>e.jsxs("span",{"data-testid":"tag-input-tag",className:"inline-flex max-w-full items-center gap-1 rounded-full border border-outline-variant bg-surface-high py-0.5 pl-2.5 pr-1 text-xs text-on-surface",children:[e.jsx("span",{className:"truncate",children:b}),e.jsx("button",{type:"button","aria-label":`Remove ${b}`,className:"rounded-full p-0.5 text-outline hover:bg-surface-highest hover:text-on-surface focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus",onClick:h=>{var D;h.stopPropagation(),s(t.filter(g=>g!==b)),(D=d.current)==null||D.focus()},children:e.jsx(Pe,{size:12,"aria-hidden":!0})})]},b)),e.jsx("input",{ref:d,"aria-label":i,"data-testid":l,list:c.length>0?p:void 0,value:r,onChange:b=>k(b.target.value),onKeyDown:j,onPaste:S,onBlur:()=>r.trim()&&x(r),placeholder:t.length===0?a:"",className:"h-7 min-w-[8rem] flex-1 bg-transparent px-1 outline-none placeholder:text-muted-foreground"}),c.length>0&&e.jsx("datalist",{id:p,children:c.map(b=>e.jsx("option",{value:b},b))})]})}const Fe="__global__",Ie="__auto__";function ss(t){return t instanceof Error?t.message:"Request failed"}function Y(){const[t,s]=m.useState(!1),[n,a]=m.useState(null);async function i(l){s(!0),a(null);try{return await l()}catch(r){a(ss(r));return}finally{s(!1)}}return{pending:t,error:n,run:i,setError:a}}function L({label:t,children:s,hint:n}){return e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(ie,{className:"text-sm text-muted-foreground",children:t}),s,n&&e.jsx("p",{className:"text-xs text-outline",children:n})]})}function oe({error:t}){return t?e.jsx("p",{role:"alert","data-testid":"kb-dialog-error",className:"text-sm text-error",children:t}):null}function ge({open:t,onClose:s,title:n,wide:a,size:i,children:l}){return e.jsx($t,{open:t,onOpenChange:r=>!r&&s(),children:e.jsxs(Et,{className:`bg-surface border-outline-variant ${i==="xl"?"w-[calc(100%_-_1rem)] max-w-4xl":a?"max-w-3xl":"max-w-md"}`,children:[e.jsx(Pt,{children:e.jsx(Rt,{className:"text-base text-on-surface",children:n})}),l]})})}function as({value:t,onChange:s}){var a;const n=Ot();return e.jsxs(he,{value:t??Ie,onValueChange:i=>s(i===Ie?null:i),children:[e.jsx(pe,{"aria-label":"Parser","data-testid":"kb-parser-select",children:e.jsx(fe,{})}),e.jsxs(be,{children:[e.jsx(X,{value:Ie,children:"Workspace default"}),(((a=n.data)==null?void 0:a.parsers)??[]).map(i=>e.jsxs(X,{value:i.id,disabled:!i.installed,children:[i.label,i.installed?"":" (not installed)"]},i.id))]})]})}const ns={ui:"Web UI",cli:"CLI",api:"REST API",mcp:"Agents (MCP)"};function is({value:t,onChange:s}){return e.jsxs("fieldset",{className:"space-y-2 rounded-md border border-outline-variant p-3",children:[e.jsx("legend",{className:"px-1 text-sm text-muted-foreground",children:"Who can change documents"}),e.jsx("div",{className:"flex flex-wrap gap-x-4 gap-y-2",children:se.map(n=>e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox","data-testid":`kb-editable-${n}`,checked:t.includes(n),onChange:a=>s(se.filter(i=>i===n?a.target.checked:t.includes(i)))}),ns[n]]},n))}),e.jsx("p",{className:"text-xs text-outline",children:"Every source can read and search. Knowledge base settings change only from the UI, CLI or API."})]})}function Qa({open:t,projectId:s,onClose:n,onCreated:a}){const i=ke(),l=V(),r=Y(),[o,d]=m.useState(""),[p,c]=m.useState(""),[x,k]=m.useState(s??Fe),[j,S]=m.useState([...se]),[b,h]=m.useState(null);async function D(g){g.preventDefault();const u=await r.run(()=>T.kb.create({name:o.trim(),description:p.trim(),project_id:x===Fe?null:x,editable_by:j,parser:b}));u&&(await l(),a(u))}return e.jsx(ge,{open:t,onClose:n,title:"New knowledge base",children:e.jsxs("form",{onSubmit:D,className:"space-y-4",children:[e.jsx(L,{label:"Name",children:e.jsx(B,{"aria-label":"Name","data-testid":"kb-name-input",value:o,onChange:g=>d(g.target.value),placeholder:"e.g. Runbooks",autoFocus:!0})}),e.jsx(L,{label:"Description",children:e.jsx(xe,{"aria-label":"Description",value:p,onChange:g=>c(g.target.value),rows:2})}),e.jsx(L,{label:"Belongs to",hint:"Project knowledge bases are visible in that project; global ones in every project.",children:e.jsxs(he,{value:x,onValueChange:k,children:[e.jsx(pe,{"aria-label":"Belongs to","data-testid":"kb-owner-select",children:e.jsx(fe,{})}),e.jsxs(be,{children:[e.jsx(X,{value:Fe,children:"Global (all projects)"}),(i.data??[]).map(g=>e.jsx(X,{value:g.id,children:g.name},g.id))]})]})}),e.jsx(is,{value:j,onChange:S}),e.jsx(L,{label:"Parser for uploads",children:e.jsx(as,{value:b,onChange:h})}),e.jsx(oe,{error:r.error}),e.jsxs(le,{children:[e.jsx(y,{type:"button",variant:"ghost",onClick:n,children:"Cancel"}),e.jsx(y,{type:"submit","data-testid":"kb-create-submit",disabled:!o.trim()||r.pending,children:r.pending?"Creating…":"Create"})]})]})})}function Xa({kb:t,onClose:s,onDeleted:n}){var D,g;const a=ke(),i=V(),l=Y(),[r,o]=m.useState(t.name),[d,p]=m.useState(t.description),[c,x]=m.useState(t.editable_by),[k,j]=m.useState(t.parser),[S,b]=m.useState(!1);async function h(u){u.preventDefault(),await l.run(()=>T.kb.update(t.id,{name:r.trim(),description:d.trim(),editable_by:c,parser:k}))&&(await i(),s())}return e.jsxs(ge,{open:!0,onClose:s,title:"Knowledge base settings",children:[e.jsxs("form",{onSubmit:h,className:"space-y-4",children:[e.jsx(L,{label:"Name",children:e.jsx(B,{"aria-label":"Name","data-testid":"kb-name-input",value:r,onChange:u=>o(u.target.value)})}),e.jsx(L,{label:"Description",children:e.jsx(xe,{"aria-label":"Description",value:d,onChange:u=>p(u.target.value),rows:2})}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsx("div",{className:"font-medium",children:"Belongs to"}),e.jsxs("p",{className:"text-outline","data-testid":"kb-settings-owner",children:[t.project_id===null?"Global, visible in every project":`${((g=(D=a.data)==null?void 0:D.find(u=>u.id===t.project_id))==null?void 0:g.name)??"A project"}, visible in that project`,". Set when the knowledge base is created."]})]}),e.jsx(is,{value:c,onChange:x}),e.jsx(L,{label:"Parser for uploads",hint:"Applies to new uploads and reparses.",children:e.jsx(as,{value:k,onChange:j})}),e.jsx(oe,{error:l.error}),e.jsxs(le,{className:"gap-2 sm:justify-between",children:[e.jsxs(y,{type:"button",variant:"ghost",className:"text-error","data-testid":"kb-delete",onClick:()=>b(!0),children:[e.jsx(Le,{size:14}),"Delete"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{type:"button",variant:"ghost",onClick:s,children:"Cancel"}),e.jsx(y,{type:"submit","data-testid":"kb-settings-save",disabled:!r.trim()||l.pending,children:"Save"})]})]})]}),e.jsx(Re,{open:S,title:"Delete knowledge base",description:`Delete "${t.name}" with its ${t.document_count} documents, revisions and uploaded files? Registered folders on disk are not touched.`,isPending:l.pending,onCancel:()=>b(!1),onConfirm:async()=>{const u=await l.run(()=>T.kb.remove(t.id));b(!1),u!==void 0&&(await i(),n())}})]})}function ut(t){return`${t.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"untitled"}.md`}function mt(t){var s,n;return((n=(s=t.match(/^#\s+(.+?)\s*#*\s*$/m))==null?void 0:s[1])==null?void 0:n.trim())??""}const Ja=/\.(md|markdown|txt)$/i;function Za({kb:t,initialFile:s,onClose:n,onCreated:a,onUploadMany:i}){var f;const l=V(),r=Y(),o=ze(t.id),[d,p]=m.useState(""),[c,x]=m.useState(""),[k,j]=m.useState(""),[S,b]=m.useState([]),[h,D]=m.useState(null),[g,u]=m.useState(!1),C=m.useRef(null),P=h?"":mt(c),M=d.trim()||P,K=h?h.name:ut(M),W=h!==null||c.trim()!=="";async function R(E){const F=E.name.replace(/\.[^.]+$/,"");if(!Ja.test(E.name)){D(E),p(F),j("");return}u(!0);const G=await r.run(()=>E.text());u(!1),G!==void 0&&(D(null),x(G),p(mt(G)||F),j(/\.txt$/i.test(E.name)?ut(F):E.name))}function v(E){const F=[...E??[]];F.length>1?i(F):F[0]&&R(F[0])}m.useEffect(()=>{s&&R(s)},[]);async function N(E){E.preventDefault();const F=await r.run(()=>h?T.kb.upload(t.id,{file:h,title:M,path:k.trim()||void 0,labels:S}):T.kb.createDocument(t.id,{title:M,path:k.trim()||K,labels:S,content:W?c:`# ${M}
27
-
28
- `}));F&&(await l(),a(F,W))}return e.jsx(ge,{open:!0,onClose:n,title:`New document in ${t.name}`,size:"xl",children:e.jsxs("form",{onSubmit:N,className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm text-outline",children:[e.jsx("span",{children:"Write or paste below, or start from a file."}),e.jsxs(y,{type:"button",size:"sm",variant:"outline","data-testid":"kb-doc-choose-file",disabled:g||r.pending,onClick:()=>{var E;return(E=C.current)==null?void 0:E.click()},children:[e.jsx(Wt,{size:16}),g?"Reading…":"Upload file"]}),e.jsx("input",{ref:C,type:"file",multiple:!0,hidden:!0,"data-testid":"kb-doc-file-input",onChange:E=>{v(E.target.files),E.target.value=""}})]}),e.jsx(L,{label:"Title",hint:P&&!d.trim()?"Taken from the first heading.":void 0,children:e.jsx(B,{"aria-label":"Title","data-testid":"kb-doc-title-input",value:d,onChange:E=>p(E.target.value),placeholder:P||"e.g. Deploy runbook",autoFocus:!0})}),h?e.jsx(L,{label:"File",hint:"Converted to searchable text after it is added. The original file is kept.",children:e.jsxs("div",{"data-testid":"kb-doc-file",className:"flex items-center gap-3 rounded-md border border-surface-highest bg-surface p-3",children:[e.jsx(Ct,{size:20,className:"shrink-0 text-outline","aria-hidden":!0}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",title:h.name,children:h.name}),e.jsx("span",{className:"shrink-0 text-xs text-outline",children:Ge(h.size)}),e.jsx(y,{type:"button",size:"icon",variant:"ghost","aria-label":`Remove ${h.name}`,"data-testid":"kb-doc-file-remove",onClick:()=>{D(null),p("")},children:e.jsx(Pe,{size:16})})]})}):e.jsx(L,{label:"Content",hint:"Markdown. Leave empty to start writing in the editor.",children:e.jsx(Dt,{path:k.trim()||K,value:c,onChange:x,testId:"kb-doc-content-input",label:"Content",placeholder:"Write or paste Markdown",initialMode:"edit",height:"45vh"})}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsx(L,{label:"Labels",hint:"Enter, comma or space adds a label.",children:e.jsx(ts,{"aria-label":"Labels","data-testid":"kb-doc-labels-input",value:S,onChange:b,suggestions:(f=o.data)==null?void 0:f.labels.map(E=>E.label)})}),e.jsx(L,{label:"Path",hint:"Optional. Folders come from the path, e.g. guides/setup.md.",children:e.jsx(B,{"aria-label":"Path","data-testid":"kb-doc-path-input",value:k,onChange:E=>j(E.target.value),placeholder:K,className:"font-mono text-sm"})})]}),e.jsx(oe,{error:r.error}),e.jsxs(le,{children:[e.jsx(y,{type:"button",variant:"ghost",onClick:n,children:"Cancel"}),e.jsx(y,{type:"submit","data-testid":"kb-doc-create-submit",disabled:!M||r.pending,children:"Create"})]})]})})}function en({doc:t,linkedFrom:s,onClose:n,onSaved:a}){var D;const i=V(),l=Y(),[r,o]=m.useState(t.title),[d,p]=m.useState(t.path),c=ze(t.kb_id),[x,k]=m.useState(t.labels),[j,S]=m.useState(t.description),b=r.trim()!==t.title||d.trim()!==t.path;async function h(g){g.preventDefault(),await l.run(()=>T.kb.updateDocument(t.id,{expected_revision:t.revision,title:r.trim(),path:d.trim(),labels:x,description:j.trim()}))&&(await i(),a())}return e.jsx(ge,{open:!0,onClose:n,title:"Document properties",children:e.jsxs("form",{onSubmit:h,className:"space-y-4",children:[e.jsx(L,{label:"Title",children:e.jsx(B,{"aria-label":"Title","data-testid":"kb-doc-title-input",value:r,onChange:g=>o(g.target.value)})}),e.jsx(L,{label:"Path",children:e.jsx(B,{"aria-label":"Path","data-testid":"kb-doc-path-input",value:d,onChange:g=>p(g.target.value),className:"font-mono text-sm"})}),e.jsx(L,{label:"Labels",hint:"Enter, comma or space adds a label.",children:e.jsx(ts,{"aria-label":"Labels","data-testid":"kb-doc-labels-input",value:x,onChange:k,suggestions:(D=c.data)==null?void 0:D.labels.map(g=>g.label)})}),e.jsx(L,{label:"Description",children:e.jsx(xe,{"aria-label":"Description",value:j,onChange:g=>S(g.target.value),rows:2})}),b&&s>0&&e.jsxs("p",{role:"status",className:"text-sm text-warning","data-testid":"kb-rename-warning",children:[s===1?"1 document links":`${s} documents link`," to this document. Links that use the old title or path will show as missing."]}),e.jsx(oe,{error:l.error}),e.jsxs(le,{children:[e.jsx(y,{type:"button",variant:"ghost",onClick:n,children:"Cancel"}),e.jsx(y,{type:"submit","data-testid":"kb-doc-properties-save",disabled:!r.trim()||l.pending,children:"Save"})]})]})})}const xt={daily:"Every day",weekly:"Once a week",custom:"Custom cron",manual:"Manual only"};function tn(t){const s=t.type==="cron"?t.cron:Zt,n={plan:"custom",time:"03:00",day:"1",cron:s},a=/^(\d{1,2}) (\d{1,2}) \* \* (\*|[0-6])$/.exec(s.trim().split(/\s+/).join(" ")),[i,l]=[Number(a==null?void 0:a[1]),Number(a==null?void 0:a[2])],r=a&&i<=59&&l<=23?`${String(l).padStart(2,"0")}:${String(i).padStart(2,"0")}`:null;return t.type==="manual"?{...n,plan:"manual",time:r??n.time}:!(a!=null&&a[3])||!r?n:a[3]==="*"?{...n,plan:"daily",time:r}:{...n,plan:"weekly",time:r,day:a[3]}}function rs({plan:t,time:s,day:n,cron:a}){if(t==="manual")return null;if(t==="custom")return a.trim();const[i,l]=s.split(":").map(Number);return`${l} ${i} * * ${t==="weekly"?n:"*"}`}function ls(t){return t.plan==="manual"?null:t.plan==="custom"?Ua(t.cron):/^\d{2}:\d{2}$/.test(t.time)?null:"Pick a time."}function sn(t){const s=es(t);return s===t?"Runs on this cron schedule":Te.some(n=>s.startsWith(n))?`Runs ${s}`:`Runs ${s.charAt(0).toLowerCase()}${s.slice(1)}`}function an({value:t,onChange:s}){const n=rs(t),a=ls(t),i=l=>s({...t,...l});return e.jsxs("fieldset",{className:"space-y-3 rounded-md border border-outline-variant p-3",children:[e.jsx("legend",{className:"px-1 text-sm text-muted-foreground",children:"When it runs"}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsx(L,{label:"Schedule",children:e.jsxs(he,{value:t.plan,onValueChange:l=>i({plan:l,...l==="custom"&&n?{cron:n}:{}}),children:[e.jsx(pe,{"aria-label":"Schedule","data-testid":"kb-digest-schedule",children:e.jsx(fe,{})}),e.jsx(be,{children:Object.keys(xt).map(l=>e.jsx(X,{value:l,children:xt[l]},l))})]})}),t.plan==="weekly"&&e.jsx(L,{label:"Day",children:e.jsxs(he,{value:t.day,onValueChange:l=>i({day:l}),children:[e.jsx(pe,{"aria-label":"Day","data-testid":"kb-digest-day",children:e.jsx(fe,{})}),e.jsx(be,{children:Te.map((l,r)=>e.jsx(X,{value:String(r),children:l},l))})]})}),(t.plan==="daily"||t.plan==="weekly")&&e.jsx(L,{label:"Time",children:e.jsx(B,{type:"time","aria-label":"Time","data-testid":"kb-digest-time",value:t.time,onChange:l=>i({time:l.target.value})})}),t.plan==="custom"&&e.jsx("div",{className:"sm:col-span-2",children:e.jsx(L,{label:"Cron expression",hint:"minute hour day month weekday, e.g. 0 */6 * * *",children:e.jsx(B,{"aria-label":"Cron expression","aria-invalid":a!==null,"data-testid":"kb-digest-cron",value:t.cron,onChange:l=>i({cron:l.target.value}),className:"font-mono",autoComplete:"off"})})})]}),e.jsx("p",{"aria-live":"polite","data-testid":"kb-digest-schedule-preview","data-valid":a===null,className:`text-sm ${a?"text-error":"text-outline"}`,children:a||(n?e.jsxs(e.Fragment,{children:[sn(n)," ",e.jsxs("span",{className:"font-mono text-xs",children:["(",n,")"]}),", in the ORC server's time zone."]}):"Runs only when you start it.")})]})}function nn({kb:t,digest:s,onClose:n,onRemove:a}){const i=V(),l=Y(),r=gs(),o=Ws(!s),[d,p]=m.useState((s==null?void 0:s.instructions)??null),[c,x]=m.useState((s==null?void 0:s.backend)??st),[k,j]=m.useState(()=>tn((s==null?void 0:s.schedule)??{type:"cron",cron:Zt}));m.useEffect(()=>{d===null&&o.data&&p(o.data.instructions)},[d,o.data]);const S=ls(k);async function b(D){var P;if(D.preventDefault(),S)return l.setError(S);const g=c===st?(P=r.data)==null?void 0:P.default_backend:c,u=rs(k);await l.run(()=>T.kb.setDigest(t.id,{instructions:(d==null?void 0:d.trim())??"",...g?{backend:g}:{},schedule:u?{type:"cron",cron:u}:{type:"manual"}}))&&(await i(),n())}const h=d!==null;return e.jsx(ge,{open:!0,onClose:n,title:s?"Digest settings":"Set up a digest",wide:!0,children:e.jsxs("form",{onSubmit:b,className:"min-w-0 space-y-4",children:[!t.editable_by.includes("mcp")&&e.jsx("p",{className:"text-sm text-warning","data-testid":"kb-digest-mcp-hint",children:"The digest writes through MCP. Allow Agents (MCP) in this knowledge base's settings first."}),e.jsx(an,{value:k,onChange:j}),e.jsx(js,{value:c,onChange:x,testId:"kb-digest-backend"}),e.jsx(L,{label:"Instructions",children:h?e.jsx(Dt,{path:"digest.md",value:d,onChange:p,testId:"kb-digest-instructions",label:"Instructions",initialMode:"edit",height:320}):o.error?e.jsx("p",{role:"alert",className:"text-sm text-error",children:ss(o.error)}):e.jsx("p",{role:"status",className:"text-sm text-outline",children:"Loading template…"})}),e.jsx(oe,{error:l.error}),e.jsxs(le,{className:"gap-2 sm:justify-between",children:[s&&a?e.jsxs(y,{type:"button",variant:"ghost",className:"text-error","data-testid":"kb-digest-remove",onClick:a,children:[e.jsx(Le,{size:14}),"Remove digest"]}):e.jsx("span",{}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{type:"button",variant:"ghost",onClick:n,children:"Cancel"}),e.jsx(y,{type:"submit","data-testid":"kb-digest-save",disabled:!h||!(d!=null&&d.trim())||S!==null||l.pending,children:l.pending?"Saving…":"Save"})]})]})]})})}function rn({kb:t,onClose:s}){const n=ys(),a=Y();async function i(){await a.run(()=>T.kb.removeDigest(t.id,t.name))!==void 0&&(n.setQueryData([qs,t.id],{digest:null}),await n.invalidateQueries({queryKey:[Vs]}),s())}return e.jsx(ge,{open:!0,onClose:s,title:"Remove digest?",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-outline",children:"Documents and comments stay. The digest's instructions, schedule, job and run history are removed."}),e.jsx(oe,{error:a.error}),e.jsxs(le,{children:[e.jsx(y,{type:"button",variant:"ghost",onClick:s,children:"Cancel"}),e.jsx(y,{type:"button",variant:"destructive","data-testid":"kb-digest-remove-confirm",onClick:i,disabled:a.pending,autoFocus:!0,children:a.pending?"Removing…":"Remove digest"})]})]})})}const ln=vs("inline-flex items-center rounded-full border border-border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2 ",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80 ",secondary:"border-transparent bg-muted text-foreground hover:bg-muted/80 ",destructive:"border-transparent bg-error text-primary-foreground hover:bg-error/80 ",outline:"text-foreground "}},defaultVariants:{variant:"default"}});function os({className:t,variant:s,...n}){return e.jsx("div",{className:U(ln({variant:s}),t),...n})}const on={open:"bg-warning",resolved:"bg-secondary",dismissed:"bg-muted-foreground"};function ds({status:t}){return e.jsx("span",{"aria-hidden":!0,className:U("size-1.5 shrink-0 rounded-full",on[t])})}function cs({kbId:t,documentId:s,onOpenDocument:n,heading:a="h3",compact:i=!1}){var j,S,b;const[l,r]=m.useState(!1),[o,d]=m.useState(null),p=Ht(t,{...s?{document_id:s}:{},...o?{status:o}:{}}),c=(j=p.data)==null?void 0:j.counts,x=c?c.open+c.resolved+c.dismissed:0;function k(h){d(l&&o===h?null:h),r(!0)}return e.jsx(Ne,{title:"Comments",testId:"kb-comments",toggleTestId:"kb-comments-toggle",heading:a,compact:i,expanded:l,onExpandedChange:r,summary:e.jsxs(e.Fragment,{children:[c&&x===0&&e.jsx("span",{className:"text-outline","data-testid":"kb-comments-none",children:"None yet"}),c&&Aa.filter(h=>c[h]>0).map(h=>e.jsxs("button",{type:"button","data-testid":`kb-comments-count-${h}`,"aria-pressed":l&&o===h,"aria-label":`${c[h]} ${h} ${c[h]===1?"comment":"comments"}`,className:U("inline-flex min-h-8 items-center gap-1.5 rounded px-1.5",l&&o===h?"bg-surface-highest text-on-surface":"text-outline hover:bg-surface-high"),onClick:()=>k(h),children:[e.jsx(ds,{status:h}),e.jsx("span",{className:"tabular-nums text-on-surface",children:c[h]}),h]},h)),p.error&&e.jsx("span",{role:"alert",className:"text-error","data-testid":"kb-comments-error",children:p.error.message})]}),children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(dn,{kbId:t,documentId:s}),o&&((S=p.data)==null?void 0:S.comments.length)===0&&e.jsxs("p",{className:"text-outline","data-testid":"kb-comments-empty",children:["No ",o," comments."]}),e.jsx("ul",{className:"divide-y divide-outline-variant",children:(b=p.data)==null?void 0:b.comments.map(h=>e.jsx(cn,{comment:h,showDocument:!s,onOpenDocument:n},h.id))})]})})}function dn({kbId:t,documentId:s}){const n=V(),a=Y(),[i,l]=m.useState("");async function r(o){o.preventDefault(),await a.run(()=>T.kb.addComment(t,{body:i.trim(),...s?{document_id:s}:{}}))&&(l(""),await n())}return e.jsxs("form",{onSubmit:r,className:"space-y-2",children:[e.jsx(xe,{"aria-label":s?"Comment on this document":"Comment on this knowledge base",placeholder:s?"Ask for a change to this document":"Ask for a change","data-testid":"kb-comment-input",value:i,onChange:o=>l(o.target.value),rows:2,maxLength:1e4}),i.trim()&&e.jsx(y,{type:"submit",size:"sm",variant:"outline","data-testid":"kb-comment-add",disabled:a.pending,children:"Add comment"}),a.error&&e.jsx("p",{role:"alert",className:"text-error","data-testid":"kb-comment-add-error",children:a.error})]})}function cn({comment:t,showDocument:s,onOpenDocument:n}){const a=V(),i=Y(),[l,r]=m.useState(null),[o,d]=m.useState("");async function p(x){if(x.preventDefault(),!l)return;const k=l;await i.run(()=>T.kb.closeComment(t.id,{status:k,reply:o.trim()}))&&(r(null),d(""),await a())}async function c(){await i.run(()=>T.kb.reopenComment(t.id))&&await a()}return e.jsxs("li",{"data-testid":"kb-comment","data-status":t.status,className:"min-w-0 space-y-1 py-2",children:[e.jsxs("p",{className:"flex min-w-0 flex-wrap items-center gap-x-2 text-xs text-outline",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-on-surface",children:[e.jsx(ds,{status:t.status}),e.jsx("span",{"data-testid":"kb-comment-status",children:t.status})]}),e.jsxs("span",{className:"min-w-0 break-words",children:[t.source===t.author?t.author:`${t.author} via ${t.source}`," ·"," ",new Date(t.created_at).toLocaleString(),s&&t.document_id&&e.jsxs(e.Fragment,{children:[" · on ",n?e.jsx("button",{type:"button",className:"text-primary hover:underline",onClick:()=>t.document_id&&n(t.document_id),children:t.document_title??"a deleted document"}):t.document_title??"a deleted document"]})]})]}),e.jsx("p",{className:"whitespace-pre-wrap break-words",children:t.body}),t.reply&&e.jsxs("p",{className:"break-words text-xs","data-testid":"kb-comment-reply-text",children:[e.jsxs("span",{className:"text-outline",children:[t.status==="dismissed"?"Dismissed":"Resolved",t.resolved_by?` by ${t.resolved_by}`:"",":"]})," ",t.reply]}),l?e.jsxs("form",{onSubmit:p,className:"flex flex-wrap items-center gap-2",children:[e.jsx(B,{"aria-label":l==="resolved"?"Resolution reply":"Reason for dismissing",placeholder:l==="resolved"?"What changed":"Why not","data-testid":"kb-comment-reply",value:o,onChange:x=>d(x.target.value),maxLength:4e3,autoFocus:!0,className:"min-w-0 flex-1 basis-48"}),e.jsx(y,{type:"submit",size:"sm","data-testid":"kb-comment-close-submit",disabled:!o.trim()||i.pending,children:l==="resolved"?"Resolve":"Dismiss"}),e.jsx(y,{type:"button",size:"sm",variant:"ghost",onClick:()=>{r(null),d(""),i.setError(null)},children:"Cancel"})]}):t.status==="open"?e.jsxs("div",{className:"-ml-2 flex flex-wrap",children:[e.jsx(y,{size:"sm",variant:"ghost","data-testid":"kb-comment-resolve",onClick:()=>r("resolved"),children:"Resolve"}),e.jsx(y,{size:"sm",variant:"ghost","data-testid":"kb-comment-dismiss",onClick:()=>r("dismissed"),children:"Dismiss"})]}):e.jsx(y,{size:"sm",variant:"ghost",className:"-ml-2","data-testid":"kb-comment-reopen",onClick:c,disabled:i.pending,children:"Reopen"}),i.error&&e.jsx("p",{role:"alert",className:"text-xs text-error","data-testid":"kb-comment-error",children:i.error})]})}const We=t=>`kb:${t}`,us={pending:"Processing",partial:"Partially parsed",failed:"Failed",lexical_ready:"Keyword search ready",semantic_pending:"Embedding",semantic_ready:"Semantic search ready"};function ht(t,s){const n=URL.createObjectURL(t),a=document.createElement("a");a.href=n,a.download=s,a.click(),setTimeout(()=>URL.revokeObjectURL(n),1e3)}function un(t){var i;const s=[...t.currentTarget.querySelectorAll('[role="menuitem"]:not(:disabled)')],n=s.indexOf(document.activeElement),a=t.key==="ArrowDown"?(n+1)%s.length:t.key==="ArrowUp"?(n-1+s.length)%s.length:t.key==="Home"?0:t.key==="End"?s.length-1:null;a===null||!s.length||(t.preventDefault(),(i=s[a])==null||i.focus())}function mn({usage:t,testId:s}){return e.jsxs("div",{"data-testid":s,className:"space-y-2",children:[e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{"data-testid":`${s}-reads`,className:"font-medium",children:t.reads})," ","reads · ",t.exposures," search appearances · ",t.distinct_sessions," sessions"]}),e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-outline",children:[e.jsx("th",{className:"py-1 text-left font-normal",children:"Source"}),lt.map(n=>e.jsx("th",{className:"py-1 text-right font-normal",children:n==="search_hit"?"listed":n},n))]})}),e.jsx("tbody",{children:se.map(n=>e.jsxs("tr",{"data-testid":`${s}-${n}`,className:"border-t border-outline-variant/50",children:[e.jsx("td",{className:"py-1 uppercase",children:n}),lt.map(a=>e.jsx("td",{className:"py-1 text-right tabular-nums",children:t.totals[n][a]},a))]},n))})]}),e.jsxs("div",{className:"text-xs text-outline",children:["Last 7 days ",t.window.days_7," · last 30 days ",t.window.days_30]})]})}function xn({kb:t,doc:s,onHome:n,onOpen:a,onDeleted:i,onReplaceFile:l,detailsOpen:r,onDetailsOpenChange:o}){var we;const d=V(),[p]=zt(),c=p.get("editorMode"),x=((we=Ht(s.kb_id,{document_id:s.id}).data)==null?void 0:we.counts.open)??0,[k,j]=m.useState(!1),[S,b]=m.useState(!1),[h,D]=m.useState(!1),g=Lt("lg"),[u,C]=m.useState(null),P=m.useRef(null),[M,K]=m.useState(null),[W,R]=m.useState(!1),v=m.useRef(null),N=m.useRef(s.revision),f=new Map(s.links.filter($=>$.document_id).map($=>[sa($.target),$.document_id])),E={slugs:[...f.keys()],select:$=>{const z=f.get($);z&&a(z)}};async function F($){R(!0),K(null);try{return await $(),await d(),!0}catch(z){return K(z instanceof Error?z.message:"Request failed"),!1}finally{R(!1)}}async function G(){await F(async()=>ht(await T.kb.original(s.id),s.original_name??s.path.split("/").pop()??"document"))}function I(){const $=(s.path.split("/").pop()??"document").replace(/\.(md|markdown)$/i,"");ht(new Blob([s.content],{type:"text/markdown;charset=utf-8"}),`${$}.md`)}const Q=s.origin==="upload",je=Q||s.origin==="external"&&!s.editable,J=(u==null?void 0:u.backlinks.filter($=>!s.backlinks.some(z=>z.document_id===$.document_id)))??[],Z=($,z,ee,_e,Se=!1)=>e.jsxs("button",{type:"button",role:"menuitem","data-testid":$,disabled:W,className:U("flex min-h-9 w-full items-center gap-2 rounded px-2 text-left text-sm outline-none hover:bg-surface-highest focus-visible:bg-surface-highest disabled:opacity-50",Se&&"text-error"),onClick:()=>{D(!1),_e()},children:[z,ee]});return e.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col overflow-y-auto lg:flex-row lg:overflow-hidden",children:[e.jsx("article",{"data-testid":"kb-document",className:"min-w-0 lg:min-h-0 lg:flex-1 lg:overflow-y-auto",children:e.jsxs("div",{className:"w-full min-w-0 px-4 pb-16 pt-4 sm:px-8 sm:pt-6",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1",children:[e.jsxs("nav",{"aria-label":"Breadcrumb",className:"flex min-w-0 flex-1 basis-48 items-center gap-1 text-sm text-outline",children:[e.jsx("button",{type:"button","data-testid":"kb-breadcrumb-kb",className:"min-w-0 max-w-[60%] truncate hover:text-on-surface hover:underline",onClick:n,children:t.name}),e.jsx(Ee,{size:14,className:"shrink-0","aria-hidden":!0}),e.jsx("span",{className:"min-w-0 truncate font-mono text-xs","data-testid":"kb-document-path",title:s.path,children:s.path})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsxs(y,{size:"sm",variant:r?"secondary":"ghost","aria-pressed":r,"data-testid":"kb-details-toggle",onClick:()=>o(!r),children:[e.jsx($a,{size:14}),"Details",x>0&&e.jsxs("span",{"data-testid":"kb-details-open-comments",title:`${x} open ${x===1?"comment":"comments"}`,className:"inline-flex items-center gap-1 text-xs tabular-nums text-outline",children:[e.jsx(ae,{tone:"warning"}),x]})]}),e.jsxs(ks,{open:h,onOpenChange:D,children:[e.jsx(Ns,{asChild:!0,children:e.jsx(y,{size:"icon",variant:"ghost","aria-label":"Document actions","aria-haspopup":"menu","data-testid":"kb-doc-menu",children:e.jsx(aa,{size:16})})}),e.jsx(ws,{children:e.jsxs(_s,{align:"end",sideOffset:4,collisionPadding:8,role:"menu","aria-label":"Document actions",className:"z-50 w-52 rounded-md border border-outline-variant bg-surface-high p-1 shadow-lg",onOpenAutoFocus:$=>{var z;$.preventDefault(),(z=$.currentTarget.querySelector('[role="menuitem"]:not(:disabled)'))==null||z.focus()},onKeyDown:un,children:[Z("kb-doc-properties",e.jsx(qt,{size:14}),"Title and labels",()=>{P.current={title:s.title,backlinks:s.backlinks},j(!0)}),!je&&Z("kb-doc-download-markdown",e.jsx(ka,{size:14}),"Download Markdown",I),je&&Z("kb-doc-download",e.jsx(ra,{size:14}),"Download original",()=>void G()),Q&&Z("kb-doc-reparse",e.jsx(la,{size:14}),"Parse again",()=>void F(()=>T.kb.reparse(s.id))),Q&&Z("kb-doc-replace",e.jsx(Sa,{size:14}),"Replace file",()=>{var $;return($=v.current)==null?void 0:$.click()}),s.origin!=="external"&&Z("kb-doc-delete",e.jsx(Le,{size:14}),"Delete document",()=>b(!0),!0)]})})]})]})]}),e.jsxs("header",{className:"mb-2 mt-4 space-y-2",children:[e.jsx("h1",{"data-testid":"kb-document-title",className:"break-words text-3xl font-medium",children:s.title}),s.description&&e.jsx("p",{className:"text-outline",children:s.description}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1.5 text-xs text-outline",children:[s.labels.length>0&&e.jsx("span",{className:"flex flex-wrap gap-1",children:s.labels.map($=>e.jsx(os,{variant:"secondary","data-testid":"kb-document-label",children:$},$))}),s.parse_state!=="ok"&&e.jsxs("span",{className:U("inline-flex items-center gap-1.5",s.parse_state==="failed"&&"text-error"),children:[e.jsx(ae,{tone:s.parse_state==="failed"?"error":s.parse_state==="partial"?"warning":"progress"}),e.jsx("span",{"data-testid":"kb-parse-state",children:us[s.parse_state]})]}),s.folder_sync&&e.jsx("span",{"data-testid":"kb-folder-sync",title:s.folder_sync==="following"?"Copied from a synced folder; scans pick up changes to the file":"Edited in ORC; scans no longer change this copy",children:s.folder_sync==="following"?"Follows folder file":"Edited, no longer synced"}),s.stale&&e.jsx("span",{className:"text-warning","data-testid":"kb-document-stale",children:"Stale: a source changed"}),e.jsxs("span",{children:["Updated ",new Date(s.updated_at).toLocaleDateString()," by ",s.updated_by]})]})]}),s.warnings.length>0&&e.jsx("ul",{"data-testid":"kb-document-warnings",className:"mb-2 space-y-1 text-sm text-warning",children:s.warnings.map($=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx(at,{size:14,className:"mt-0.5 shrink-0"}),$]},$))}),Q&&e.jsxs("p",{className:"mb-2 text-sm text-outline",children:["Text parsed from ",s.original_name??"the upload"," (",Ge(s.size_bytes),s.parser?`, ${s.parser.id} ${s.parser.version}`:"","). Replace the file to change it."]}),s.folder_sync==="following"&&(c==="edit"||c==="split")&&e.jsx("p",{role:"status","data-testid":"kb-folder-sync-warning",className:"mb-2 text-sm text-warning",children:"This copy follows a file in a synced folder. Saving here stops it following that file; later changes to the file will not reach it."}),M&&e.jsx("p",{role:"alert","data-testid":"kb-document-error",className:"mb-2 text-sm text-error",children:M}),u&&J.length>0&&e.jsxs("div",{role:"status","data-testid":"kb-rename-broken-links",className:"mb-2 flex flex-wrap items-center gap-x-2 text-sm text-warning",children:[e.jsx(at,{size:14,className:"shrink-0","aria-hidden":!0}),e.jsxs("span",{className:"min-w-0 flex-1",children:[J.length===1?"1 document":`${J.length} documents`," linked to “",u.title,"” by its old title or path; those links now show as missing:"," ",J.map(($,z)=>e.jsxs("span",{children:[z>0&&", ",e.jsx("button",{type:"button",className:"underline underline-offset-2 hover:text-on-surface",onClick:()=>a($.document_id),children:$.title})]},$.document_id))]}),e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>C(null),children:"Dismiss"})]}),e.jsx(Us,{documentId:We(s.id),path:s.editable?s.path:`${s.path}.md`,content:s.content,wikiLinks:E,testId:"kb-document-content",layout:"page",pageTitle:s.title,hideFrontmatter:!0,onSave:s.editable?async($,z)=>{try{const ee=await T.kb.updateDocument(s.id,{expected_revision:z===s.content?s.revision:N.current,content:$});return N.current=ee.revision,$}finally{await d()}}:void 0},We(s.id))]})}),r&&g&&e.jsx(pt,{doc:s,onOpen:a}),!g&&e.jsx(Tt,{open:r,onOpenChange:o,children:e.jsxs(Mt,{className:"w-[360px]","aria-describedby":void 0,children:[e.jsx(At,{className:"py-3",children:e.jsx(Ft,{children:"Details"})}),e.jsx(It,{className:"p-0 sm:p-0",children:e.jsx(pt,{doc:s,onOpen:($,z)=>{o(!1),a($,z)}})})]})}),e.jsx("input",{ref:v,type:"file",hidden:!0,"data-testid":"kb-doc-replace-input",onChange:$=>{var ee;const z=(ee=$.target.files)==null?void 0:ee[0];z&&l(z),$.target.value=""}}),k&&e.jsx(en,{doc:s,linkedFrom:s.backlinks.length,onClose:()=>j(!1),onSaved:()=>{j(!1),C(P.current)}}),e.jsx(Re,{open:S,title:"Delete document",description:`Delete "${s.title}" and its revision history${Q?" and uploaded file":""}?`,isPending:W,onCancel:()=>b(!1),onConfirm:async()=>{b(!1),await F(()=>T.kb.removeDocument(s.id))&&i()}})]})}function Ke({title:t,children:s}){return e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("h2",{className:"text-sm font-medium text-outline",children:t}),s]})}function pt({doc:t,onOpen:s}){var l;const n=Gs(t.id),a=Ys(t.id),i="block min-h-8 w-full break-words text-left text-primary hover:underline";return e.jsxs("aside",{"data-testid":"kb-document-details","aria-label":"Document details",className:"w-full shrink-0 space-y-6 p-4 text-sm lg:min-h-0 lg:w-80 lg:overflow-y-auto lg:border-l lg:border-outline-variant",children:[t.outline.length>0&&e.jsx(Ke,{title:"On this page",children:e.jsx("nav",{"aria-label":"Outline",className:"space-y-0.5",children:t.outline.map(r=>e.jsx("button",{type:"button",className:"block min-h-7 w-full truncate text-left text-outline hover:text-on-surface",style:{paddingLeft:`${(r.level-1)*.75}rem`},onClick:()=>s(t.id,r.text),children:r.text},`${r.block}-${r.text}`))})}),t.links.length>0&&e.jsx(Ke,{title:`Links to (${t.links.length})`,children:t.links.map(r=>r.document_id?e.jsx("button",{type:"button","data-testid":"kb-outgoing-link",className:i,onClick:()=>s(r.document_id),children:r.title??r.target},r.target):e.jsxs("p",{className:"py-1 text-outline","data-testid":"kb-unresolved-link",children:[r.target," ",e.jsx("span",{className:"text-xs",children:"(no such document)"})]},r.target))}),t.backlinks.length>0&&e.jsx(Ke,{title:`Linked from (${t.backlinks.length})`,children:t.backlinks.map(r=>e.jsx("button",{type:"button","data-testid":"kb-backlink",className:i,onClick:()=>s(r.document_id),children:r.title},r.document_id))}),e.jsx("div",{className:"border-y border-outline-variant",children:e.jsx(cs,{kbId:t.kb_id,documentId:t.id,heading:"h2",compact:!0})}),e.jsxs("details",{"data-testid":"kb-doc-history",className:"group",children:[e.jsxs("summary",{className:"flex min-h-9 cursor-pointer list-none items-center gap-1.5 font-medium [&::-webkit-details-marker]:hidden",children:[e.jsx(Ee,{size:14,"aria-hidden":!0,className:"text-outline transition-transform group-open:rotate-90"}),"Usage and history"]}),e.jsxs("div",{className:"mt-3 space-y-5 pl-5",children:[n.data?e.jsx(mn,{usage:n.data,testId:"kb-doc-usage"}):e.jsx("p",{className:"text-outline",children:n.error?"Usage unavailable":"Loading…"}),e.jsx("ol",{className:"space-y-2","data-testid":"kb-revisions",children:(l=a.data)==null?void 0:l.map(r=>e.jsxs("li",{"data-testid":"kb-revision",children:[e.jsxs("div",{children:["Revision ",r.revision," · ",r.actor,e.jsxs("span",{className:"text-outline",children:[" via ",r.source]})]}),e.jsxs("div",{className:"text-xs text-outline",children:[new Date(r.created_at).toLocaleString(),r.note?` · ${r.note}`:""]})]},r.revision))}),e.jsxs("dl",{className:"grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 text-xs text-outline",children:[e.jsx("dt",{children:"Search"}),e.jsx("dd",{"data-testid":"kb-index-state",children:us[t.index_state]??t.index_state}),e.jsx("dt",{children:"Origin"}),e.jsx("dd",{children:t.origin}),e.jsx("dt",{children:"Type"}),e.jsx("dd",{children:t.media_type}),e.jsx("dt",{children:"Size"}),e.jsx("dd",{children:Ge(t.size_bytes)}),e.jsx("dt",{children:"Updated"}),e.jsxs("dd",{children:[new Date(t.updated_at).toLocaleString()," by ",t.updated_by]}),e.jsx("dt",{children:"ID"}),e.jsx("dd",{className:"break-all font-mono",children:t.id})]})]})]})]})}function ft(t){return`${t.added} added · ${t.updated} updated · ${t.missing} missing${t.errors.length?` · ${t.errors.length} errors: ${t.errors.slice(0,3).join("; ")}`:""}`}const qe=(t,s,n)=>`${t} ${t===1?s:n}`;function hn(){return/win/i.test(navigator.platform)?"Choose a folder or type its full path, e.g. C:\\notes":/mac/i.test(navigator.platform)?"Choose a folder or type its full path, e.g. /Users/you/notes":"Choose a folder or type its full path, e.g. /home/you/notes"}function pn(t){const s=t.document_count-t.edited_count,n=s?`${qe(s,"synced copy is","synced copies are")} removed from this knowledge base`:"No synced copies are removed",a=t.edited_count?`; ${qe(t.edited_count,"edited copy is","edited copies are")} kept as documents`:"";return`Stop syncing ${t.root_path}? ${n}${a}. Files on disk are not touched.`}function bt(t){return t.replace(/[\\/]+$/,"").split(/[\\/]/).pop()||t}function fn({kb:t}){var R,v;const s=Qs(t.id),n=V(),a=Y(),[i,l]=m.useState(!1),[r,o]=m.useState(""),[d,p]=m.useState("**/*.md"),[c,x]=m.useState(null),[k,j]=m.useState(null),[S,b]=m.useState(!1),[h,D]=m.useState(!1),g=s.data??[],u=g.filter(N=>N.last_error).length,C=g.reduce((N,f)=>N+f.document_count,0);function P(){l(!0),b(!0)}function M(){b(!1),o(""),a.setError(null),g.length===0&&l(!1)}async function K(){D(!0),a.setError(null);try{const{path:N}=await T.terminals.pickFolder(r.trim()||void 0);N&&o(N)}catch(N){a.setError(N instanceof Error?N.message:String(N))}finally{D(!1)}}async function W(N){N.preventDefault();const f=await a.run(()=>T.kb.addSource(t.id,{root_path:r.trim(),pattern:d.trim()||"**/*.md"}));f&&(o(""),b(!1),x(ft(f.scan)),await n())}return e.jsxs(Ne,{title:"Synced folders",testId:"kb-folders",toggleTestId:"kb-sources",expanded:i,onExpandedChange:N=>{l(N),b(N&&g.length===0)},summary:s.isLoading?e.jsx("span",{className:"text-outline",children:"Loading…"}):g.length===0?e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-outline","data-testid":"kb-folders-none",children:[e.jsx(ae,{tone:"off"}),"None"]}):e.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1.5","data-testid":"kb-folders-summary",children:[e.jsx(ae,{tone:u?"error":"ok"}),g.length===1?e.jsx("span",{className:"min-w-0 truncate",title:(R=g[0])==null?void 0:R.root_path,children:bt(((v=g[0])==null?void 0:v.root_path)??"")}):`${g.length} folders`,e.jsxs("span",{className:"shrink-0 text-outline",children:["· ",C," ",C===1?"document":"documents",u?` · ${u} failing`:""]})]}),actions:g.length===0&&!i?e.jsx(y,{size:"sm",variant:"outline","data-testid":"kb-folders-add",onClick:P,children:"Add folder"}):null,children:[e.jsxs("div",{className:"min-w-0 space-y-3",children:[e.jsx("p",{className:"max-w-prose text-outline",children:"Matching files are copied in and kept in sync: ORC rescans every minute while the daemon runs, or when you choose Scan now. A copy you edit here stops following its file. ORC never writes to the folder."}),g.length>0&&e.jsx("ul",{className:"divide-y divide-outline-variant","data-testid":"kb-sources-list",children:g.map(N=>e.jsxs("li",{"data-testid":"kb-source-row",className:"flex min-w-0 flex-wrap items-center gap-2 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1 basis-56",children:[e.jsx("div",{className:"font-medium",children:bt(N.root_path)}),e.jsx("div",{className:"break-all font-mono text-xs text-outline",children:N.root_path}),e.jsxs("div",{className:"text-xs text-outline",children:[N.pattern," · ",qe(N.document_count,"document","documents"),N.edited_count?` (${N.edited_count} edited)`:""," ·"," ",N.last_scan_at?e.jsxs("span",{title:new Date(N.last_scan_at).toLocaleString(),children:["scanned ",Xe(N.last_scan_at)]}):"not scanned yet"]}),N.last_error&&e.jsx("div",{className:"text-xs text-error",children:N.last_error})]}),e.jsxs(y,{variant:"ghost",size:"sm","data-testid":"kb-source-scan",disabled:a.pending,onClick:async()=>{const f=await a.run(()=>T.kb.scanSource(N.id));f&&x(ft(f)),await n()},children:[e.jsx(Vt,{size:14}),"Scan now"]}),e.jsx(y,{variant:"ghost",size:"sm",title:`Stop syncing ${N.root_path}`,"data-testid":"kb-source-remove",onClick:()=>j(N),children:"Stop syncing"})]},N.id))}),c&&e.jsx("p",{role:"status","data-testid":"kb-source-result",className:"text-outline",children:c}),S?e.jsxs("form",{onSubmit:W,className:"min-w-0 space-y-3","data-testid":"kb-source-form",children:[e.jsxs("div",{className:"grid min-w-0 gap-3 sm:grid-cols-[minmax(0,1fr)_12rem]",children:[e.jsx(L,{label:"Folder path",hint:hn(),children:e.jsxs("div",{className:"flex min-w-0 gap-2",children:[e.jsx(B,{"aria-label":"Folder path","data-testid":"kb-source-path-input",value:r,onChange:N=>o(N.target.value),className:"min-w-0 font-mono text-sm",autoFocus:!0}),e.jsxs(y,{type:"button",variant:"outline","data-testid":"kb-source-choose-folder",onClick:K,disabled:h,className:"shrink-0",children:[e.jsx(na,{size:14}),h?"Choosing…":"Choose folder"]})]})}),e.jsx(L,{label:"File pattern",hint:"e.g. *.md, **/*.md",children:e.jsx(B,{"aria-label":"File pattern","data-testid":"kb-source-pattern-input",value:d,onChange:N=>p(N.target.value),className:"font-mono text-sm"})})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(y,{type:"submit",size:"sm",variant:"outline","data-testid":"kb-source-add",disabled:!r.trim()||a.pending,children:"Add folder"}),e.jsx(y,{type:"button",size:"sm",variant:"ghost","data-testid":"kb-source-cancel",onClick:M,children:"Cancel"})]})]}):g.length>0&&e.jsxs(y,{size:"sm",variant:"ghost",className:"-ml-2","data-testid":"kb-folders-add-another",onClick:()=>b(!0),children:[e.jsx($e,{size:14}),"Add another folder"]}),e.jsx(oe,{error:a.error})]}),e.jsx(Re,{open:k!==null,title:"Stop syncing folder",description:k?pn(k):"",confirmLabel:"Stop syncing",variant:"warning",isPending:a.pending,onCancel:()=>j(null),onConfirm:async()=>{const N=k;j(null),N&&await a.run(()=>T.kb.removeSource(N.id)),await n()}})]})}const gt=8;function bn(t,s,n){return n==="title"?t.title.localeCompare(s.title):n==="updated"?t.updated_at-s.updated_at:t.reads-s.reads}function Ue(t,s){if(t.key===s)return t.desc?"descending":"ascending"}function gn(t){const s=new Date(t);return s.toDateString()===new Date().toDateString()?s.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):s.toLocaleDateString([],{month:"short",day:"numeric",year:"numeric"})}function jn({kb:t,owner:s,listing:n,label:a,onLabel:i,onOpen:l,onNewDocument:r,onSettings:o}){const d=t.editable_by.includes("mcp");return e.jsxs("div",{"data-testid":"kb-overview",className:"w-full min-w-0 space-y-8 p-4 sm:p-8",children:[e.jsxs("header",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"break-words text-2xl font-medium","data-testid":"kb-overview-name",children:t.name}),t.description&&e.jsx("p",{className:"max-w-prose text-outline",children:t.description}),e.jsxs("p",{className:"text-sm text-outline","data-testid":"kb-overview-meta",children:[s," · ",t.document_count," ",t.document_count===1?"document":"documents"," ·"," ",d?"agents can edit":"agents read only"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(y,{size:"sm","data-testid":"kb-new-document",onClick:r,children:[e.jsx(wa,{size:16}),"New document"]}),e.jsxs(y,{size:"sm",variant:"ghost","data-testid":"kb-settings",onClick:o,children:[e.jsx(Ss,{size:16}),"Settings"]})]})]}),e.jsxs("section",{"aria-labelledby":"kb-setup-heading",className:"space-y-1",children:[e.jsx("h3",{id:"kb-setup-heading",className:"text-sm font-medium text-outline",children:"Setup"}),e.jsxs("div",{className:"divide-y divide-outline-variant border-y border-outline-variant",children:[e.jsx(Ha,{kb:t}),e.jsx(fn,{kb:t}),e.jsx(yn,{kb:t,onSettings:o}),e.jsx(vn,{kb:t,onSettings:o}),e.jsx(cs,{kbId:t.id,onOpenDocument:l})]})]}),e.jsx(Nn,{kbId:t.id,onOpen:l}),e.jsx(kn,{listing:n,total:t.document_count,label:a,onLabel:i,onOpen:l,onNewDocument:r})]})}function yn({kb:t,onSettings:s}){const n=t.editable_by.includes("mcp");return e.jsx(Ne,{title:"Who can edit",testId:"kb-access",summary:e.jsxs("span",{className:"inline-flex min-w-0 flex-wrap items-center gap-x-1.5",children:[e.jsx(ae,{tone:n?"ok":"off"}),n?"Agents can edit":"Agents read only",e.jsxs("span",{className:"text-outline",children:["·"," ",t.editable_by.length?t.editable_by.map(a=>ns[a]).join(", "):"nobody, read only everywhere"]})]}),actions:e.jsx(y,{size:"sm",variant:"ghost","data-testid":"kb-access-change",onClick:s,children:"Change"})})}function vn({kb:t,onSettings:s}){var i,l;const n=Ot(),a=t.parser?((l=(i=n.data)==null?void 0:i.parsers.find(r=>r.id===t.parser))==null?void 0:l.label)??t.parser:"Workspace default parser";return e.jsx(Ne,{title:"Uploads",testId:"kb-uploads-setup",summary:e.jsxs("span",{className:"text-outline","data-testid":"kb-uploads-parser",children:[a," · ","PDF, Word, PowerPoint, Excel, HTML, Markdown and text become Markdown"]}),actions:e.jsx(y,{size:"sm",variant:"ghost","data-testid":"kb-parser-change",onClick:s,children:"Change"})})}function kn({listing:t,total:s,label:n,onLabel:a,onOpen:i,onNewDocument:l}){const[r,o]=m.useState(""),[d,p]=m.useState(!1),[c,x]=m.useState({key:"updated",desc:!0}),k=r.trim().toLowerCase(),j=((t==null?void 0:t.documents)??[]).filter(u=>(!n||u.labels.includes(n))&&(!k||u.title.toLowerCase().includes(k)||u.path.toLowerCase().includes(k)||u.labels.some(C=>C.toLowerCase().includes(k)))).sort((u,C)=>bn(u,C,c.key)*(c.desc?-1:1));function S(u){x(C=>C.key===u?{key:u,desc:!C.desc}:{key:u,desc:u!=="title"})}function b(u,C){const P=c.desc?Cs:Ds;return e.jsxs("button",{type:"button","data-testid":`kb-sort-${u}`,className:"inline-flex min-h-8 items-center gap-1 hover:text-on-surface",onClick:()=>S(u),children:[C,c.key===u&&e.jsx(P,{size:12,"aria-hidden":!0})]})}const h=[...(t==null?void 0:t.labels)??[]].sort((u,C)=>C.count-u.count),D=d?h:h.filter((u,C)=>C<gt||u.label===n),g=h.length-D.length;return e.jsxs("section",{"aria-labelledby":"kb-documents-heading","data-testid":"kb-documents",className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("h3",{id:"kb-documents-heading",className:"mr-auto text-sm font-medium text-outline",children:["Documents",n?` labelled ${n}`:""]}),s>0&&e.jsx(B,{"aria-label":"Filter documents","data-testid":"kb-documents-filter",placeholder:"Filter by title, path or label",value:r,onChange:u=>o(u.target.value),className:"h-9 w-full sm:w-64"})]}),D.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5","data-testid":"kb-labels",children:[e.jsx("span",{className:"mr-1 text-xs text-outline",children:"Label"}),D.map(u=>e.jsxs("button",{type:"button","data-testid":"kb-label-filter","aria-pressed":n===u.label,className:U("min-h-8 rounded-full border px-2.5 text-xs",n===u.label?"border-primary bg-primary/10 text-primary":"border-outline-variant text-outline hover:text-on-surface"),onClick:()=>a(n===u.label?null:u.label),children:[u.label," ",e.jsx("span",{className:"tabular-nums",children:u.count})]},u.label)),(g>0||d)&&h.length>gt&&e.jsx("button",{type:"button","data-testid":"kb-labels-more",className:"min-h-8 px-2 text-xs text-primary hover:underline",onClick:()=>p(!d),children:d?"Fewer labels":`${g} more`})]}),s===0?e.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 rounded-md border border-dashed border-outline-variant px-6 py-10 text-center text-sm text-outline",children:[e.jsx(Wt,{size:22,className:"text-primary","aria-hidden":!0}),e.jsx("span",{children:"This knowledge base is empty. Drop PDF, Word, PowerPoint, Excel, HTML, Markdown or text files here, or"}),e.jsx(y,{size:"sm",variant:"outline",onClick:l,"data-testid":"kb-overview-new-document",children:"add a document"})]}):e.jsxs(e.Fragment,{children:[j.length===0&&t&&e.jsxs("p",{className:"py-4 text-sm text-outline","data-testid":"kb-documents-empty",children:["No documents match."," ",e.jsx("button",{type:"button","data-testid":"kb-documents-clear",className:"text-primary hover:underline",onClick:()=>{o(""),a(null)},children:"Clear filters"})]}),j.length>0&&e.jsxs("table",{className:"w-full table-fixed text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-outline-variant text-left text-xs text-outline",children:[e.jsx("th",{className:"py-1 pr-3 font-normal","aria-sort":Ue(c,"title"),children:b("title","Title")}),e.jsx("th",{className:"hidden w-[30%] py-2 pr-3 font-normal md:table-cell",children:"Labels"}),e.jsx("th",{className:"w-24 py-1 pr-3 font-normal sm:w-28","aria-sort":Ue(c,"updated"),children:b("updated","Updated")}),e.jsx("th",{className:"hidden w-16 py-1 text-right font-normal sm:table-cell","aria-sort":Ue(c,"reads"),children:b("reads","Reads")})]})}),e.jsx("tbody",{children:j.map(u=>e.jsxs("tr",{className:"cursor-pointer border-b border-outline-variant/60 align-top hover:bg-surface-high",onClick:()=>i(u.id),children:[e.jsxs("td",{className:"min-w-0 py-2 pr-3",children:[e.jsxs("button",{type:"button","data-testid":"kb-document-row","data-document-title":u.title,className:"flex w-full min-w-0 items-center gap-1.5 text-left font-medium hover:text-primary",onClick:C=>{C.stopPropagation(),i(u.id)},children:[e.jsx("span",{className:"min-w-0 truncate",children:u.title}),u.origin==="external"&&e.jsx(Vt,{size:13,className:"shrink-0 text-outline","aria-label":"From a synced folder"})]}),e.jsx("span",{className:"block truncate font-mono text-xs text-outline",children:u.path}),(u.parse_state==="pending"||u.parse_state==="failed")&&e.jsx("span",{className:U("text-xs",u.parse_state==="failed"?"text-error":"text-outline"),children:u.parse_state==="failed"?"Parsing failed":"Parsing…"})]}),e.jsx("td",{className:"hidden py-2 pr-3 text-xs text-outline md:table-cell",children:e.jsx("span",{className:"line-clamp-2",children:u.labels.join(", ")})}),e.jsx("td",{className:"py-2 pr-3 text-xs text-outline tabular-nums",children:gn(u.updated_at)}),e.jsx("td",{className:"hidden py-2 text-right text-xs text-outline tabular-nums sm:table-cell",children:u.reads||""})]},u.id))})]}),e.jsx("p",{className:"text-xs text-outline",children:"Drop files anywhere on this page to upload."})]})]})}function Nn({kbId:t,onOpen:s}){const n=Xs(t).data;return!n||!(n.stale.length||n.failed.length||n.unresolved_links.length)?null:e.jsxs("section",{"data-testid":"kb-maintenance",className:"space-y-1 text-sm",children:[e.jsx("h3",{className:"text-sm font-medium text-outline",children:"Needs attention"}),e.jsxs("ul",{className:"space-y-1",children:[n.failed.map(a=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:"text-left text-error hover:underline",onClick:()=>s(a.id),children:["Parsing failed: ",a.title]})},a.id)),n.stale.map(a=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:"text-left text-warning hover:underline",onClick:()=>s(a.id),children:["Stale summary: ",a.title]})},a.id)),n.unresolved_links.map(a=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:"text-left text-outline hover:underline",onClick:()=>s(a.document_id),children:["[[",a.target,"]] in ",a.title," has no target"]})},`${a.document_id}-${a.target}`))]})]})}function wn(){const t=V(),[s,n]=m.useState([]),a=m.useRef(1),i=(o,d)=>n(p=>p.map(c=>c.id===o?{...c,...d}:c));async function l(o){i(o.id,{status:"uploading",progress:0,error:void 0});try{const d=await T.kb.upload(o.kbId,{file:o.file,...o.replace},p=>i(o.id,{progress:p}));i(o.id,{status:"done",progress:1,document:d}),await t()}catch(d){i(o.id,{status:"failed",error:d instanceof Error?d.message:"Upload failed"})}}function r(o,d,p={}){const c=d.map(x=>({id:a.current++,kbId:o,file:x,...p.replace?{replace:p.replace}:{},progress:0,status:"uploading"}));n(x=>[...x,...c]);for(const x of c)l(x)}return{uploads:s,add:r,retry:o=>{const d=s.find(p=>p.id===o);d&&l(d)},clearFinished:()=>n(o=>o.filter(d=>d.status==="uploading"))}}const jt="all",_n=200,yt=[{value:"reads",label:"Most read"},{value:"recent",label:"Recent"},{value:"priority",label:"Priority"}];function Me(t){return new Date(t*1e3).toLocaleString()}function Sn({projectId:t}){var N;const s=$s(),n=Kt(),{memoryProject:a,memoryName:i}=Es(),[l,r]=Ae("project",t),[o,d]=Ae("memoryQuery",""),[p,c]=Ae("memorySort","reads",yt.map(f=>f.value)),[x,k]=m.useState(o);m.useEffect(()=>k(o),[o]);const[j,S]=m.useState(null),[b,h]=m.useState(null),{data:D}=ke({status:"active"}),g=xa(),u=l==="unassigned",C=l===jt,P=ha({project_id:C?void 0:l,q:o||void 0,sort:p,limit:_n},{enabled:!u}),M=((N=P.data)==null?void 0:N.memories)??[],K=f=>{var E;return((E=D==null?void 0:D.find(F=>F.id===f))==null?void 0:E.name)??f},W=M.find(f=>f.project_id===a&&f.name===i),R=f=>s(`${Ps(f.project_id,f.name)}${n.search}`),v=()=>s(`${Rs}${n.search}`);return e.jsxs("div",{children:[e.jsx(ma,{title:"Memories",meta:P.data?`${P.data.total} ${P.data.total===1?"memory":"memories"}`:void 0,action:e.jsxs(y,{"data-testid":"new-memory-button",size:"sm",onClick:()=>S("new"),className:"font-label text-sm",children:[e.jsx($e,{size:12,className:"mr-1"})," New memory"]})}),e.jsx("p",{className:"mb-4 text-sm leading-relaxed text-muted-foreground",children:"Short project facts agents load next session: ports, conventions, gotchas, decisions. Longer procedures belong in a skill."}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 mb-4",children:[e.jsxs(he,{value:l,onValueChange:f=>r(f),children:[e.jsx(pe,{"aria-label":"Project","data-testid":"memory-project-filter",className:"h-9 w-48 bg-background text-on-surface font-body text-sm",children:e.jsx(fe,{})}),e.jsxs(be,{className:"bg-surface border-outline-variant",children:[e.jsx(X,{value:jt,className:"font-body text-sm",children:"All projects"}),u&&e.jsx(X,{value:"unassigned",className:"font-body text-sm",children:"Unassigned"}),D==null?void 0:D.map(f=>e.jsx(X,{value:f.id,"data-testid":`memory-project-option-${f.id}`,className:"font-body text-sm",children:f.name},f.id))]})]}),e.jsx("div",{className:"flex shrink-0 flex-wrap gap-1.5",children:yt.map(f=>e.jsx("button",{type:"button",onClick:()=>c(f.value),"data-testid":`memory-sort-${f.value}`,"aria-pressed":p===f.value,className:`font-label text-sm px-3 py-1.5 border transition-colors ${p===f.value?"bg-surface-highest text-on-surface border-transparent":"bg-transparent border-transparent text-muted-foreground hover:bg-surface-low hover:text-on-surface"}`,children:f.label},f.value))}),e.jsxs("div",{className:"relative min-w-[160px] flex-1",children:[e.jsx(Ut,{size:12,className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground"}),e.jsx(B,{"aria-label":"Search memories","data-testid":"memory-search-input",value:x,onChange:f=>k(f.target.value),onKeyDown:f=>f.key==="Enter"&&d(f.currentTarget.value),placeholder:"Search memories...",className:"pl-8 bg-background text-on-surface font-body text-sm placeholder:text-muted-foreground"})]}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>d(x),className:"font-label text-sm",children:"Search"})]}),u?e.jsx(it,{message:"Memories belong to a project. Choose a project to see its memories."}):P.error?e.jsx(Qe,{message:P.error.message,onRetry:()=>void P.refetch()}):P.isLoading?e.jsx("div",{className:"space-y-2",children:[...Array(5)].map((f,E)=>e.jsx(Ye,{className:"h-10 w-full bg-surface-highest"},E))}):M.length===0?e.jsx(it,{message:o?"No memories match your search":"No memories yet"}):e.jsx("div",{className:"overflow-hidden",children:e.jsxs(da,{children:[e.jsx(ca,{children:e.jsxs(rt,{className:"border-b border-outline-variant hover:bg-transparent",children:[e.jsx(ce,{className:"font-label text-sm text-muted-foreground",children:"Name"}),e.jsx(ce,{className:"font-label text-sm text-muted-foreground",children:"Description"}),C&&e.jsx(ce,{className:"font-label text-sm text-muted-foreground",children:"Project"}),e.jsx(ce,{className:"font-label text-sm text-muted-foreground w-20",children:"Priority"}),e.jsx(ce,{className:"font-label text-sm text-muted-foreground w-16",children:"Reads"}),e.jsx(ce,{className:"font-label text-sm text-muted-foreground w-44",children:"Updated"})]})}),e.jsx(ua,{children:M.map(f=>e.jsxs(rt,{"data-testid":"memory-row","data-memory-name":f.name,"data-memory-project":f.project_id,className:"border-b border-outline-variant/50 hover:bg-surface-low cursor-pointer",onClick:()=>R(f),children:[e.jsx(ue,{className:"font-body text-sm font-medium text-on-surface",children:e.jsx("button",{type:"button",className:"min-h-11 text-left hover:text-primary",onClick:E=>{E.stopPropagation(),R(f)},children:f.name})}),e.jsx(ue,{className:"font-body text-sm text-muted-foreground max-w-md truncate",children:f.description}),C&&e.jsx(ue,{className:"font-body text-sm text-muted-foreground",children:K(f.project_id)}),e.jsx(ue,{children:e.jsx(xs,{priority:f.priority})}),e.jsx(ue,{"data-testid":"memory-read-count",className:"font-label text-sm text-muted-foreground",title:ms(f),children:f.read_count}),e.jsx(ue,{className:"font-label text-sm text-muted-foreground",children:Me(f.updated_at)})]},f.key))})]})}),a&&i&&e.jsx(Cn,{projectId:a,name:i,projectName:K(a),listItem:W,onClose:v,onEdit:S,onDelete:h},`${a}/${i}`),j&&e.jsx($n,{memory:j==="new"?null:j,defaultProjectId:C||u?"":l,onClose:()=>S(null),onCreated:f=>R(f)}),b&&e.jsx(Re,{open:!0,title:"Delete memory",description:`Delete "${b.name}"? It can be restored from its history.`,confirmLabel:"Delete",variant:"destructive",isPending:g.isPending,onConfirm:()=>g.mutate({projectId:b.project_id,name:b.name},{onSuccess:()=>{h(null),v()}}),onCancel:()=>h(null)}),g.error&&e.jsx("p",{role:"alert",className:"text-sm text-destructive mt-2",children:g.error.message})]})}function ms(t){const{mcp:s,cli:n,api:a,ui:i}=t.reads_by_source,l=t.last_read_at?` · last read ${Me(t.last_read_at)}`:"";return`mcp ${s} · cli ${n} · api ${a} · ui ${i}${l}`}function xs({priority:t}){return t===null?e.jsx("span",{"data-testid":"memory-priority",className:"font-label text-xs text-outline",children:"Unscored"}):e.jsxs("span",{"data-testid":"memory-priority",className:"font-label text-xs text-primary",children:["P",t]})}function Cn({projectId:t,name:s,projectName:n,listItem:a,onClose:i,onEdit:l,onDelete:r}){const{data:o,isLoading:d,error:p,refetch:c}=pa(t,s);return e.jsx(Tt,{open:!0,onOpenChange:x=>!x&&i(),children:e.jsxs(Mt,{"data-testid":"memory-detail",className:"w-screen max-w-full sm:w-[860px] sm:max-w-[96vw]",children:[e.jsxs(At,{children:[e.jsx(Ft,{children:s}),o&&e.jsx("p",{"data-testid":"memory-detail-description",className:"font-body text-sm text-muted-foreground mt-1",children:o.description})]}),e.jsx(It,{children:p?e.jsx(Qe,{message:p.message,onRetry:()=>void c()}):d||!o?e.jsx("div",{className:"space-y-3",children:[...Array(4)].map((x,k)=>e.jsx(Ye,{className:"h-8 w-full bg-surface-highest"},k))}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(y,{"data-testid":"memory-edit",size:"sm",variant:"outline",onClick:()=>l(o),children:[e.jsx(qt,{size:12,className:"mr-1"})," Edit"]}),e.jsxs(y,{"data-testid":"memory-delete",size:"sm",variant:"outline",onClick:()=>r(o),children:[e.jsx(Le,{size:12,className:"mr-1"})," Delete"]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsx(de,{label:"Project",children:n}),e.jsx(de,{label:"Priority",children:e.jsx(xs,{priority:o.priority})}),e.jsx(de,{label:"Reads",children:a?e.jsx("span",{title:ms(a),children:a.read_count}):"—"}),e.jsx(de,{label:"Author",children:e.jsx("span",{"data-testid":"memory-detail-author",children:o.author})}),e.jsx(de,{label:"Session",children:e.jsx("code",{className:"font-mono text-xs break-all",children:o.session_id??"—"})}),e.jsx(de,{label:"Updated",children:Me(o.updated_at)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-sm text-muted-foreground mb-2",children:"Content"}),e.jsx("div",{"data-testid":"memory-detail-content",className:"whitespace-pre-wrap break-words font-body text-sm text-on-surface border border-outline-variant p-3",children:o.content})]}),e.jsx(Dn,{projectId:t,name:s,onDeleted:i})]})})]})})}function vt({label:t,snapshot:s}){return e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-outline mt-2",children:t}),s?e.jsxs("div",{className:"text-xs space-y-1",children:[e.jsxs("p",{children:[e.jsx("span",{className:"text-outline",children:"Priority:"})," ",s.priority===null?"unscored":s.priority]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-outline",children:"Description:"})," ",s.description]}),e.jsx("pre",{className:"whitespace-pre-wrap break-all",children:s.content})]}):e.jsx("p",{className:"text-xs italic text-muted-foreground",children:"(none)"})]})}function Dn({projectId:t,name:s,onDeleted:n}){var p;const a=ja(t,s),i=ya(),[l,r]=m.useState(""),o=((p=a.data)==null?void 0:p.changes)??[],d=o[0];return e.jsxs("section",{"data-testid":"memory-history-panel",className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:"History"}),a.error&&e.jsx("p",{role:"alert",children:a.error.message}),i.error&&e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:i.error.message}),o.length>1&&e.jsx(B,{"data-testid":"memory-revert-reason","aria-label":"Reason for reverting",value:l,onChange:c=>r(c.target.value),placeholder:"Reason for reverting..."}),o.map(c=>e.jsxs("details",{"data-testid":"memory-history-change",className:"border-b border-outline-variant p-3",children:[e.jsxs("summary",{className:"text-xs cursor-pointer",children:[c.action.replace("memory.","")," · ",Me(c.created_at)," ·"," ",c.author,c.session_id?` · ${c.session_id}`:"",c.reason?` · ${c.reason}`:""]}),e.jsx(vt,{label:"Before",snapshot:c.previous}),e.jsx(vt,{label:"After",snapshot:c.current}),d&&c.previous&&e.jsx(y,{"data-testid":"memory-revert-change",size:"sm",variant:"outline",className:"mt-2",disabled:!l.trim()||i.isPending,onClick:()=>i.mutate({name:s,project_id:t,change_id:c.id,expected_change_id:d.id,reason:l.trim()},{onSuccess:({memory:x})=>{r(""),x||n()}}),children:"Restore state before this change"})]},c.id))]})}function Ve(t){return[...t].length}function kt({value:t,max:s,testId:n}){const a=Ve(t);return e.jsx("span",{"data-testid":n,className:`text-xs ${s!==void 0&&a>s?"text-destructive":"text-muted-foreground"}`,children:s===void 0?a:`${a}/${s}`})}function $n({memory:t,defaultProjectId:s,onClose:n,onCreated:a}){var R;const{data:i}=ke({status:"active"}),[l,r]=m.useState((t==null?void 0:t.project_id)??s),[o,d]=m.useState((t==null?void 0:t.name)??""),[p,c]=m.useState((t==null?void 0:t.description)??""),[x,k]=m.useState((t==null?void 0:t.content)??""),[j,S]=m.useState((t==null?void 0:t.priority)===null||(t==null?void 0:t.priority)===void 0?"":String(t.priority)),[b,h]=m.useState(""),D=fa(),g=ba(),u=(R=ga().data)==null?void 0:R.content_max,C=t?g:D,P=j.trim()===""?null:Number(j),M=P===null||Number.isInteger(P)&&P>=0&&P<=Ce,K=!!l&&!!o.trim()&&!!p.trim()&&Ve(p)<=nt&&!!x.trim()&&(u===void 0||Ve(x)<=u)&&M;function W(){if(!K||C.isPending)return;if(!t){D.mutate({project_id:l,name:o.trim(),description:p.trim(),content:x.trim(),priority:P},{onSuccess:N=>{n(),a(N)}});return}const v={...p.trim()!==t.description&&{description:p.trim()},...x.trim()!==t.content&&{content:x.trim()},...P!==t.priority&&{priority:P}};if(Object.keys(v).length===0){n();return}g.mutate({name:t.name,project_id:t.project_id,...v,...b.trim()&&{reason:b.trim()}},{onSuccess:n})}return e.jsx($t,{open:!0,onOpenChange:v=>!v&&!C.isPending&&n(),children:e.jsxs(Et,{"data-testid":"memory-form-dialog",className:"bg-surface border-outline-variant w-[calc(100%_-_1rem)] max-w-2xl max-h-[94dvh] overflow-y-auto",children:[e.jsx(Pt,{children:e.jsx(Rt,{className:"font-headline text-base text-on-surface",children:t?`Edit ${t.name}`:"New memory"})}),e.jsxs("form",{onSubmit:v=>{v.preventDefault(),W()},className:"space-y-3 mt-2",children:[!t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(ie,{className:"font-label text-sm text-muted-foreground",children:"Project *"}),e.jsxs(he,{value:l,onValueChange:r,children:[e.jsx(pe,{"aria-label":"Memory project","data-testid":"memory-project-select",className:"bg-background text-on-surface font-body text-sm h-9",children:e.jsx(fe,{placeholder:"Choose a project"})}),e.jsx(be,{className:"bg-surface border-outline-variant",children:i==null?void 0:i.map(v=>e.jsx(X,{value:v.id,className:"font-body text-sm",children:v.name},v.id))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(ie,{className:"font-label text-sm text-muted-foreground",children:"Name *"}),e.jsx(B,{"aria-label":"Name","data-testid":"memory-name-input",value:o,onChange:v=>d(v.target.value),placeholder:"api-port",maxLength:64,className:"bg-background text-on-surface font-body text-sm",autoFocus:!0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Lowercase words joined by hyphens, unique in the project."})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(ie,{className:"font-label text-sm text-muted-foreground",children:"Description *"}),e.jsx(kt,{value:p,max:nt,testId:"memory-description-count"})]}),e.jsx(xe,{"aria-label":"Description","data-testid":"memory-description-input",value:p,onChange:v=>c(v.target.value),placeholder:"One line agents see in lists and context",className:"bg-background text-on-surface font-body text-sm resize-none",rows:2})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(ie,{className:"font-label text-sm text-muted-foreground",children:"Content *"}),e.jsx(kt,{value:x,max:u,testId:"memory-content-count"})]}),e.jsx(xe,{"aria-label":"Content","data-testid":"memory-content-input",value:x,onChange:v=>k(v.target.value),placeholder:"The fact itself. Longer guidance belongs in a skill.",className:"bg-background text-on-surface font-body text-sm",rows:6})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(ie,{className:"font-label text-sm text-muted-foreground",children:["Priority (0-",Ce,", empty = unscored)"]}),e.jsx(B,{"aria-label":"Priority","data-testid":"memory-priority-input",type:"number",min:0,max:Ce,step:1,value:j,onChange:v=>S(v.target.value),className:"w-32 bg-background text-on-surface font-body text-sm"}),!M&&e.jsxs("p",{className:"text-xs text-destructive",children:["Priority must be a whole number from 0 to ",Ce,"."]})]}),t&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(ie,{className:"font-label text-sm text-muted-foreground",children:"Reason"}),e.jsx(B,{"aria-label":"Reason","data-testid":"memory-reason-input",value:b,onChange:v=>h(v.target.value),placeholder:"Why this changed (optional)",className:"bg-background text-on-surface font-body text-sm"})]}),C.error&&e.jsx("p",{role:"alert","data-testid":"memory-form-error",className:"text-sm text-destructive",children:C.error.message}),e.jsxs(le,{children:[e.jsx(y,{type:"button",variant:"ghost",size:"sm",onClick:n,disabled:C.isPending,className:"font-label text-sm text-muted-foreground",children:"Cancel"}),e.jsx(y,{"data-testid":"memory-submit",type:"submit",size:"sm",disabled:!K||C.isPending,className:"font-label text-sm",children:C.isPending?"Saving...":t?"Save":"Create"})]})]})]})})}function si({projectId:t}){const s=oa(t),{pathname:n}=Kt();return n.startsWith("/knowledge/memories")?e.jsx("div",{"data-testid":"knowledge-base-view",children:e.jsx(Sn,{projectId:t,embedded:!0})}):e.jsx("div",{"data-testid":"knowledge-base-view",className:"flex min-h-0 min-w-0 flex-1",children:e.jsx(Pn,{projectId:s==="all"||s==="unassigned"?void 0:s},s)})}function hs(t){return t.replace(/```[\w-]*/g," ").replace(/<\/?[a-z][^>]*>/gi," ").replace(/!?\[([^\]]*)\]\([^)]*\)/g,"$1").replace(/(^|\s)#{1,6}\s+/g,"$1").replace(/(^|\n)\s*(?:>\s*)+/g,"$1").replace(/(^|\n)\s*(?:[-*+]|\d+[.)])\s+/g,"$1").replace(/\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)*\|?/g," ").replace(/(^|\s)(?:\*{3,}|_{3,})(?=\s|$)/g,"$1").replace(/`/g,"").replace(/(^|[\s(«])[*_~]+(?=\S)/g,"$1").replace(/(\S)[*_~]+(?=$|[\s).,;:!?»])/g,"$1").replace(/\s*\|[\s|]*/g," · ").replace(/\s+/g," ").replace(/^ · | · $/g,"").trim()}function En({text:t}){const s=hs(t).split(/«([^»]*)»/g);return e.jsx(e.Fragment,{children:s.map((n,a)=>a%2?e.jsx("mark",{className:"rounded-sm bg-primary/20 px-0.5 text-on-surface",children:n},a):e.jsx(m.Fragment,{children:n},a))})}function Pn({projectId:t}){var Se,Je,Ze;const[s,n]=zt(),a=s.get("kb"),i=s.get("document"),l=s.get("label")??"",r=s.get("q")??"",o=s.get("searchAll")==="1",[d,p]=m.useState(r);m.useEffect(()=>p(r),[r]);const[c,x]=m.useState(null),[k,j]=m.useState(!1),S=Lt("lg"),[b,h]=m.useState(()=>typeof window<"u"&&window.innerWidth>=1600),[D,g]=m.useState(!1),[u,C]=m.useState(null),[P,M]=m.useState();function K(){x(null),M(void 0)}const W=ke(),R=Js(t),v=((Se=R.data)==null?void 0:Se.find(w=>w.id===a))??null,N=ze((v==null?void 0:v.id)??null),f=Zs(i),E=R.data!==void 0&&(v!==null||R.data.length===0),F=ea(r&&E?{query:r,...v&&!o?{kb_ids:[v.id]}:{},scope:t?"default":"all",limit:20}:null,t),G=wn();function I(w,A=!1){n(()=>{const te=new URLSearchParams(window.location.search);for(const[ne,et]of Object.entries(w))et?te.set(ne,et):te.delete(ne);return te},{replace:A})}const Q=()=>!i||Bs(We(i));function je(w){j(!1),!(w===a&&!i&&!r||!Q())&&(w!==a&&G.clearFinished(),I({kb:w,document:null,label:null,q:null}))}function J(w,A){j(!1),!(w!==i&&!Q())&&(I({document:w,q:null}),C(A??null))}function Z(w,A){I({document:w}),C(A??null)}function we(){j(!1);const w=d.trim();if(!w)return I({q:null});Q()&&I({q:w,document:null})}m.useEffect(()=>{S&&j(!1)},[S]),m.useEffect(()=>{R.data&&(a&&!R.data.some(w=>w.id===a)&&!i?I({kb:null},!0):!a&&R.data[0]&&I({kb:R.data[0].id},!0))}),m.useEffect(()=>{var w;f.data&&f.data.kb_id!==a&&((w=R.data)!=null&&w.some(A=>A.id===f.data.kb_id))&&I({kb:f.data.kb_id,label:null},!0)}),m.useEffect(()=>{if(!u||!f.data)return;const w=document.querySelector('[data-testid="kb-document"]'),A=[...(w==null?void 0:w.querySelectorAll("h1,h2,h3,h4,h5,h6"))??[]].find(te=>{var ne;return((ne=te.textContent)==null?void 0:ne.trim())===u});A&&(A.scrollIntoView({block:"start"}),C(null))});function $(w){w.preventDefault(),g(!1);const A=[...w.dataTransfer.files];!v||A.length===0||(A.length>1?G.add(v.id,A):(M(A[0]),x("new-document")))}const z=w=>{var A,te;return w===null?"Global":((te=(A=W.data)==null?void 0:A.find(ne=>ne.id===w))==null?void 0:te.name)??"Project"};if(R.error)return e.jsx(Qe,{message:R.error.message,onRetry:()=>R.refetch()});const ee=i?f.data&&v?e.jsx(xn,{kb:v,doc:f.data,detailsOpen:b,onDetailsOpenChange:h,onHome:()=>je(v.id),onOpen:J,onDeleted:()=>I({document:null}),onReplaceFile:w=>f.data&&G.add(f.data.kb_id,[w],{replace:{document_id:f.data.id,expected_revision:f.data.revision}})},f.data.id):f.error?e.jsxs(Be,{children:[e.jsx("p",{role:"alert","data-testid":"kb-document-error",className:"text-sm text-error",children:f.error.message}),e.jsx(y,{variant:"outline",onClick:()=>I({document:null}),children:"Back"})]}):e.jsx(Be,{children:e.jsx("p",{role:"status",className:"text-sm text-outline",children:"Loading document…"})}):r?e.jsx(Nt,{children:e.jsx(Ln,{query:r,search:F,onOpen:Z,onClear:()=>I({q:null})})}):v?e.jsx(Nt,{children:e.jsx(jn,{kb:v,owner:z(v.project_id),listing:N.data,label:l,onLabel:w=>I({label:w}),onOpen:J,onNewDocument:()=>x("new-document"),onSettings:()=>x("settings")})}):((Je=R.data)==null?void 0:Je.length)===0?e.jsxs(Be,{testId:"empty-state",children:[e.jsx(Bt,{size:28,className:"text-primary"}),e.jsx("h2",{className:"text-xl font-medium",children:"Build a knowledge base"}),e.jsx("p",{className:"max-w-md text-outline",children:"Upload documents, write Markdown or sync a folder. Agents search it with citations through MCP, the CLI and the API, and you can see what they read."}),e.jsxs(y,{"data-testid":"kb-empty-create",onClick:()=>x("create"),children:[e.jsx($e,{size:16}),"New knowledge base"]})]}):null,_e=e.jsxs("nav",{id:"kb-sidebar-panel","aria-label":"Knowledge bases","data-testid":"kb-sidebar",className:"flex h-full min-h-0 flex-col border-outline-variant bg-background lg:w-72 lg:shrink-0 lg:border-r",children:[e.jsxs("form",{className:"flex shrink-0 items-center gap-1.5 border-b border-outline-variant p-3",onSubmit:w=>{w.preventDefault(),we()},children:[e.jsx(B,{"aria-label":"Search knowledge","data-testid":"kb-search-input",value:d,onChange:w=>p(w.target.value),placeholder:v&&!o?`Search ${v.name}`:"Search everything",className:"h-9 min-w-0 flex-1"}),e.jsx(y,{type:"submit",size:"icon",variant:"ghost","data-testid":"kb-search-submit","aria-label":"Search",children:e.jsx(Ut,{size:16})}),k&&e.jsx(y,{type:"button",size:"icon",variant:"ghost","data-testid":"kb-browser-close","aria-label":"Close knowledge browser",onClick:()=>j(!1),children:e.jsx(Pe,{size:16})})]}),v&&e.jsxs("label",{className:"flex shrink-0 items-center gap-2 border-b border-outline-variant px-3 py-2 text-xs text-outline",children:[e.jsx("input",{type:"checkbox","data-testid":"kb-search-all",checked:o,onChange:w=>I({searchAll:w.target.checked?"1":null})}),"Search all knowledge bases"]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-2",children:[e.jsxs("div",{className:"flex items-center justify-between px-2 pb-1",children:[e.jsx("h2",{className:"text-sm font-medium text-outline",children:"Knowledge bases"}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":"New knowledge base","data-testid":"kb-create",onClick:()=>x("create"),children:e.jsx($e,{size:16})})]}),R.isLoading&&e.jsx(Ye,{className:"mx-2 h-9"}),e.jsx(Rn,{bases:R.data??[],projectName:z,kbId:a,documentId:i,documents:((Ze=N.data)==null?void 0:Ze.documents)??[],onSelectKb:je,onOpenDocument:J})]}),e.jsx(zn,{})]});return e.jsx(zs,{open:k&&!S,onOpenChange:j,children:e.jsxs("div",{"data-testid":"knowledge-bases",className:"relative flex min-h-0 min-w-0 flex-1",children:[e.jsx("h1",{"data-testid":"view-title",className:"sr-only",children:"Knowledge bases"}),S&&_e,!S&&e.jsxs(Ls,{children:[e.jsx(Ts,{className:"fixed inset-0 z-50 bg-black/70"}),e.jsxs(Ms,{"data-testid":"kb-mobile-browser",className:"viewport-sheet fixed inset-x-0 z-50 bg-background",children:[e.jsx(As,{className:"sr-only",children:"Browse knowledge"}),e.jsx(Fs,{className:"sr-only",children:"Search knowledge bases and choose a document"}),_e]})]}),e.jsxs("div",{"data-testid":"kb-dropzone",className:U("relative flex min-h-0 min-w-0 flex-1 flex-col",D&&"outline-2 -outline-offset-4 outline-dashed outline-primary"),onDragOver:w=>{v&&(w.preventDefault(),g(!0))},onDragLeave:()=>g(!1),onDrop:$,children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-outline-variant px-3 py-2 lg:hidden",children:[e.jsx(Is,{asChild:!0,children:e.jsxs(y,{"data-testid":"kb-browser-open",variant:"ghost",size:"sm","aria-expanded":k,"aria-controls":"kb-sidebar-panel",onClick:()=>j(!0),children:[e.jsx(Ks,{size:16}),"Browse"]})}),v&&e.jsx("span",{className:"min-w-0 truncate text-sm text-outline",children:v.name})]}),i&&r&&e.jsx("div",{className:"flex shrink-0 items-center border-b border-outline-variant px-3 py-1",children:e.jsxs(y,{variant:"ghost",size:"sm","data-testid":"kb-search-back",className:"min-w-0",onClick:()=>Q()&&I({document:null}),children:[e.jsx(ia,{size:14}),e.jsxs("span",{className:"truncate",children:["Back to results for “",r,"”"]})]})}),e.jsx("div",{className:"flex min-h-0 min-w-0 flex-1",children:ee}),e.jsx(Tn,{uploads:G,onOpen:J})]}),c==="create"&&e.jsx(Qa,{open:!0,projectId:t,onClose:()=>x(null),onCreated:w=>{x(null),j(!1),I({kb:w.id,document:null,label:null,q:null})}}),c==="settings"&&v&&e.jsx(Xa,{kb:v,onClose:()=>x(null),onDeleted:()=>{x(null),I({kb:null,document:null,label:null})}}),c==="new-document"&&v&&e.jsx(Za,{kb:v,initialFile:P,onClose:K,onUploadMany:w=>{K(),G.add(v.id,w)},onCreated:(w,A)=>{K(),I({document:w.id,editorMode:A?null:"edit"})}})]})})}function Rn({bases:t,projectName:s,kbId:n,documentId:a,documents:i,onSelectKb:l,onOpenDocument:r}){const[o,d]=m.useState(null);m.useEffect(()=>{a&&d(null)},[a]);const p=new Map;for(const x of t){const k=s(x.project_id);p.set(k,[...p.get(k)??[],x])}const c=[...p.entries()].sort(([x],[k])=>x==="Global"?-1:k==="Global"?1:x.localeCompare(k));return e.jsx("div",{"data-testid":"kb-list",className:"space-y-3",children:c.map(([x,k])=>e.jsxs("section",{"aria-label":x,children:[c.length>1&&e.jsx("h3",{className:"truncate px-2 pb-0.5 pt-1 text-xs text-outline",children:x}),e.jsx("ul",{className:"space-y-0.5",children:k.map(j=>{const S=j.id===n,b=S&&o!==j.id&&i.length>0;return e.jsxs("li",{children:[e.jsxs("button",{type:"button","data-testid":"kb-row","data-kb-name":j.name,"aria-current":S&&!a?"page":void 0,"aria-expanded":b,className:U("flex min-h-9 w-full items-center gap-2 rounded-md px-2 text-left text-sm hover:bg-surface-high",S&&"font-medium",S&&!a&&"bg-surface-high"),onClick:()=>{S&&d(h=>h===j.id?null:j.id),l(j.id)},children:[e.jsx(Ee,{size:14,"aria-hidden":!0,className:U("-mr-1 shrink-0 text-outline transition-transform motion-reduce:transition-none",b&&"rotate-90",j.document_count===0&&"invisible")}),e.jsx(Bt,{size:15,className:"shrink-0 text-outline","aria-hidden":!0}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:j.name}),e.jsx("span",{className:"text-xs font-normal tabular-nums text-outline",children:j.document_count})]}),b&&e.jsx("ul",{className:"ml-4 mt-0.5 space-y-0.5 border-l border-outline-variant pl-2",children:i.map(h=>e.jsx("li",{children:e.jsxs("button",{type:"button","data-testid":"kb-nav-document","data-document-title":h.title,"aria-current":h.id===a?"page":void 0,className:U("flex min-h-8 w-full items-center gap-2 rounded-md px-2 text-left text-sm hover:bg-surface-high",h.id===a?"bg-surface-high text-on-surface":"text-outline"),onClick:()=>r(h.id),children:[e.jsx(Ct,{size:14,className:"shrink-0","aria-hidden":!0}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:h.title})]})},h.id))})]},j.id)})})]},x))})}function zn(){const t=ta(),s=t.data,n=s?s.embedding.provider==="none"?{text:"Keyword search only",title:"Configure embeddings in Settings to also search by meaning"}:s.embedding.ready?{text:"Hybrid search",title:s.embedding.model??void 0}:{text:"Embeddings not ready",title:s.embedding.detail??""}:null,a=s?s.jobs.queued+s.jobs.running:0;return e.jsx("p",{role:"status","data-testid":"kb-status",className:"shrink-0 border-t border-outline-variant px-4 py-2 text-xs text-outline",children:s?e.jsxs(e.Fragment,{children:[e.jsx("span",{title:n==null?void 0:n.title,children:n==null?void 0:n.text}),a?` · ${a} processing`:""]}):t.error?"Knowledge status unavailable":"Loading…"})}function Nt({children:t}){return e.jsx("div",{className:"min-h-0 min-w-0 flex-1 overflow-y-auto",children:t})}function Be({children:t,testId:s}){return e.jsx("div",{"data-testid":s,className:"mx-auto flex max-w-lg flex-1 flex-col items-start justify-center gap-4 p-6",children:t})}function Ln({query:t,search:s,onOpen:n,onClear:a}){const i=s.data;return e.jsxs("section",{"data-testid":"kb-search-results","aria-label":"Search results",className:"w-full min-w-0 space-y-4 p-4 sm:p-8",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("h2",{className:"mr-auto text-lg font-medium",children:["Results for “",t,"”"]}),i&&i.hits.length>0&&e.jsxs("span",{className:"text-xs text-outline","data-testid":"kb-search-count",children:[i.hits.length," ",i.hits.length===1?"result":"results"]}),e.jsxs(y,{variant:"ghost",size:"sm",onClick:a,"data-testid":"kb-search-clear",children:[e.jsx(Pe,{size:14}),"Clear"]})]}),(i==null?void 0:i.degraded)&&e.jsx("p",{role:"status",className:"text-sm text-warning",children:i.degraded}),s.isLoading&&e.jsx("p",{className:"text-sm text-outline",children:"Searching…"}),s.error&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:s.error.message}),(i==null?void 0:i.hits.length)===0&&e.jsx("p",{className:"text-sm text-outline","data-testid":"kb-search-empty",children:"Nothing matched. Try other words or search all knowledge bases."}),i==null?void 0:i.hits.map(l=>e.jsxs("article",{"data-testid":"kb-search-result",className:"space-y-2 border-b border-outline-variant pb-4",children:[e.jsxs("button",{type:"button",className:"block text-left",onClick:()=>{var r;return n(l.document_id,wt((r=l.passages[0])==null?void 0:r.heading_path))},children:[e.jsx("span",{className:"block font-medium text-primary hover:underline",children:l.title}),e.jsxs("span",{className:"block break-all text-xs text-outline",children:[l.kb_name," · ",l.path]})]}),l.labels.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1",children:l.labels.map(r=>e.jsx(os,{variant:"secondary",children:r},r))}),l.passages.map(r=>{var o,d,p,c;return e.jsxs("div",{"data-testid":"kb-search-passage",className:"cursor-pointer space-y-1 rounded-md p-2 hover:bg-surface-high",onClick:()=>n(l.document_id,wt(r.heading_path)),children:[(r.heading_path.length>0||((o=r.locator)==null?void 0:o.page)||((d=r.locator)==null?void 0:d.sheet))&&e.jsx("div",{className:"text-xs text-outline",children:[...r.heading_path.map(hs),...(p=r.locator)!=null&&p.page?[`page ${r.locator.page}`]:[],...(c=r.locator)!=null&&c.sheet?[`sheet ${r.locator.sheet}`]:[]].join(" › ")}),e.jsx("p",{className:"text-sm leading-relaxed",children:e.jsx(En,{text:r.snippet})})]},r.chunk_id)})]},l.document_id))]})}function Tn({uploads:t,onOpen:s}){if(!t.uploads.length)return null;const n=t.uploads.some(a=>a.status!=="uploading");return e.jsxs("section",{"data-testid":"kb-upload-queue","aria-label":"Uploads",className:"absolute bottom-4 right-4 z-10 flex max-h-72 w-80 max-w-[calc(100%-2rem)] flex-col rounded-lg border border-outline-variant bg-surface text-sm shadow-lg",children:[e.jsxs("div",{className:"flex shrink-0 items-center justify-between px-3 py-1.5",children:[e.jsx("span",{className:"font-medium",children:"Uploads"}),n&&e.jsx(y,{size:"sm",variant:"ghost",onClick:t.clearFinished,"data-testid":"kb-upload-clear",children:"Dismiss"})]}),e.jsx("div",{className:"min-h-0 space-y-1 overflow-y-auto px-3 pb-2",children:t.uploads.map(a=>e.jsx(An,{upload:a,onOpen:s,onRetry:()=>t.retry(a.id)},a.id))})]})}const Mn={pending:"Parsing…",ok:"Open",partial:"Open · partly parsed",failed:"Parse failed"};function An({upload:t,onOpen:s,onRetry:n}){var l;const i=((l=ze(t.status==="done"?t.kbId:null).data)==null?void 0:l.documents.find(r=>{var o;return r.id===((o=t.document)==null?void 0:o.id)}))??t.document;return e.jsxs("div",{"data-testid":"kb-upload-item","data-status":t.status,"data-parse-state":i==null?void 0:i.parse_state,className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t.file.name}),t.status==="uploading"&&e.jsx("span",{className:"h-1.5 w-24 overflow-hidden rounded-full bg-surface-high",role:"progressbar","aria-label":"Upload progress","aria-valuenow":Math.round(t.progress*100),children:e.jsx("span",{className:"block h-full bg-primary",style:{width:`${Math.round(t.progress*100)}%`}})}),t.status==="done"&&i&&e.jsx("button",{type:"button",className:U("hover:underline",i.parse_state==="failed"?"text-error":"text-primary"),onClick:()=>s(i.id),children:Mn[i.parse_state]}),t.status==="failed"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{role:"alert",className:"text-error",children:t.error}),e.jsx(y,{size:"sm",variant:"ghost",onClick:n,"data-testid":"kb-upload-retry",children:"Retry"})]})]})}function wt(t){return t==null?void 0:t[t.length-1]}export{si as default};
@@ -1,3 +0,0 @@
1
- import{e as M,r as n,f as U,g as F,j as e,B as T,P as O,h as L,S as V,C as H,i as W,k as G,l as J,D as q,m as K,n as Q,o as X,p as b,I as k,T as Y,q as Z,s as ee,t as te,v as se,w as ae,x as re,y as B,L as le,M as oe}from"./index-C_jtMgr7.js";import{u as ne,B as ie}from"./useListSelection-CSQd_Hmx.js";import{C as ce}from"./ConfirmDialog-CrSa87VF.js";import{E as de}from"./EmptyState-Ctm7L70B.js";import{E as me}from"./ErrorState-BPTepwiG.js";import{T as ue}from"./TaskDetailSheet-fUSHPFB-.js";import{T as xe,a as be,b as z,c as m,d as ge,e as u}from"./table-D3N_5Wee.js";import{T as pe,a as je,b as he,c as fe}from"./tabs-CSlEXoxD.js";import{V as Ne}from"./ViewHeader-DXR0ZaMO.js";import{u as ve}from"./useDetailRoute-j9nlwack.js";import{u as Se}from"./view-params-Bm1Qf6KC.js";import{T as ye}from"./trash-2-D3Ey4I09.js";import"./PriorityBadge-BW-A50LE.js";import"./StatusBadge-C5G1fdZh.js";import"./ResumeActions-DHTOr6GQ.js";import"./useSessions-BrdK-12R.js";const ke=[{value:"all",label:"All"},{value:"active",label:"Active"},{value:"archived",label:"Archived"},{value:"paused",label:"Paused"}];function Ve(){var $;const{data:r,isLoading:l,error:d,refetch:E}=M(),[o,_]=Se("status","all",["all","active","archived","paused"]),[f,C]=n.useState(!1),[N,v]=n.useState(null),[g,P]=n.useState(null),[p,S]=n.useState(null),{selectedId:y,openDetail:w,closeDetail:j}=ve("/projects","projectId"),D=U(),c=y?(r??[]).find(t=>t.id===y)??null:null,x=n.useMemo(()=>{const t=r??[];return o==="all"?t:t.filter(a=>a.status===o)},[r,o]),i=ne(x.map(t=>t.id),o),s=F(),h=(($=s.data)==null?void 0:$.scope)===o?s.data:void 0;async function A(t){const a=await s.mutateAsync({ids:i.selectedIds,status:t,scope:o});i.select(a.failed.map(I=>I.id))}const R=n.useMemo(()=>(r??[]).reduce((t,a)=>(t[a.status]=(t[a.status]??0)+1,t),{}),[r]);return d?e.jsx(me,{message:d.message,onRetry:()=>E()}):e.jsxs("div",{children:[e.jsx(Ne,{title:"Projects",meta:`${(r??[]).length} total`,action:e.jsxs(T,{"data-testid":"new-project-button",size:"sm",onClick:()=>C(!0),className:"font-label text-sm bg-primary text-primary-foreground hover:bg-primary/90",children:[e.jsx(O,{size:12,className:"mr-1"}),"New project"]})}),e.jsxs(pe,{value:o,onValueChange:t=>_(t),className:"mb-4",children:[e.jsx(je,{className:"bg-transparent gap-1 h-auto max-w-full flex-wrap justify-start p-0",children:ke.map(({value:t,label:a})=>e.jsxs(he,{"data-testid":`projects-filter-${t}`,value:t,className:`font-label text-sm px-4 py-2 rounded-md
2
- data-[state=active]:bg-surface-highest data-[state=active]:text-on-surface data-[state=active]:shadow-none
3
- text-muted-foreground hover:text-on-surface`,children:[a,t!=="all"&&R[t]!=null&&e.jsx("span",{className:"ml-1.5 text-xs text-muted-foreground px-1.5 py-0.5",children:R[t]})]},t))}),x.length>0&&e.jsx(ie,{resourceLabel:"projects",count:i.selectedIds.length,allSelected:i.allSelected,someSelected:i.someSelected,onSelectAll:i.selectAll,onClear:i.clear,disabled:s.isPending,children:L.map(t=>e.jsxs(T,{type:"button",size:"sm",variant:"outline",disabled:s.isPending,"data-testid":`projects-bulk-${t}`,onClick:()=>void A(t),children:[t==="active"?"Activate":t==="paused"?"Pause":"Archive"," ","selected"]},t))}),s.isPending&&e.jsx("p",{role:"status",className:"mb-3 text-sm text-outline",children:"Updating selected projects..."}),!s.isPending&&h&&e.jsxs("div",{role:"status",className:"mb-3 space-y-1 text-sm","data-testid":"projects-bulk-result",children:[e.jsxs("p",{children:[h.succeeded.length," projects set to ",h.status,"."]}),h.failed.map(t=>{var a;return e.jsxs("p",{className:"text-error",children:[((a=r==null?void 0:r.find(I=>I.id===t.id))==null?void 0:a.name)??t.id,": ",t.error,". Still selected for retry."]},t.id)})]}),e.jsx(fe,{value:o,children:l?e.jsx("div",{className:"space-y-2",children:[...Array(3)].map((t,a)=>e.jsx(V,{className:"h-12 w-full bg-surface-highest"},a))}):x.length===0?e.jsx(de,{message:"No projects"}):e.jsx("div",{className:"overflow-hidden",children:e.jsxs(xe,{children:[e.jsx(be,{children:e.jsxs(z,{className:"border-b border-outline-variant hover:bg-transparent",children:[e.jsx(m,{className:"w-11",children:e.jsx("span",{className:"sr-only",children:"Select projects"})}),e.jsx(m,{className:"font-label text-sm text-muted-foreground",children:"Name"}),e.jsx(m,{className:"font-label text-sm text-muted-foreground",children:"Description"}),e.jsx(m,{className:"font-label text-sm text-muted-foreground w-28",children:"Status"}),e.jsx(m,{className:"font-label text-sm text-muted-foreground w-36",children:"Tags"}),e.jsx(m,{className:"font-label text-sm text-muted-foreground w-24",children:"Max Workers"}),e.jsx(m,{className:"font-label text-sm text-muted-foreground w-24",children:"Created"}),e.jsx(m,{className:"w-10"})]})}),e.jsx(ge,{children:x.map(t=>e.jsxs(z,{"data-testid":"project-row","data-project-id":t.id,"data-project-name":t.name,className:"border-b border-outline-variant/50 hover:bg-surface-high cursor-pointer",onClick:()=>w(t.id),children:[e.jsx(u,{children:e.jsx("input",{type:"checkbox","data-testid":"project-select","aria-label":`Select ${t.name}`,className:"size-4 accent-primary",checked:i.selectedIds.includes(t.id),disabled:s.isPending,onClick:a=>a.stopPropagation(),onChange:()=>i.toggle(t.id)})}),e.jsx(u,{className:"font-body text-sm font-medium text-on-surface",children:e.jsx("button",{type:"button",className:"min-h-11 text-left hover:text-primary","aria-label":`Edit project: ${t.name}`,onClick:a=>{a.stopPropagation(),w(t.id)},children:t.name})}),e.jsx(u,{className:"font-body text-sm text-muted-foreground max-w-xs truncate",children:t.description??"—"}),e.jsx(u,{children:e.jsxs("span",{className:"inline-flex items-center gap-2 text-xs font-normal capitalize text-muted-foreground",children:[e.jsx("span",{"aria-hidden":"true",className:`h-1.5 w-1.5 shrink-0 rounded-full ${t.status==="active"?"bg-secondary":t.status==="paused"?"bg-tertiary":"bg-outline"}`}),t.status]})}),e.jsx(u,{children:e.jsx("div",{className:"flex flex-wrap gap-1",children:(t.tags??[]).map(a=>e.jsx("span",{className:"font-label text-sm px-1.5 py-0.5 text-muted-foreground",children:a},a))})}),e.jsx(u,{className:"font-label text-sm text-on-surface text-center",children:t.max_workers??"—"}),e.jsx(u,{className:"font-label text-sm text-muted-foreground",children:new Date(t.created_at).toLocaleDateString()}),e.jsx(u,{children:e.jsx("button",{type:"button","data-testid":"project-delete","aria-label":`Delete project: ${t.name}`,onClick:a=>{a.stopPropagation(),S(t)},className:"text-muted-foreground hover:text-error transition-colors p-1",children:e.jsx(ye,{size:12})})})]},t.id))})]})})})]}),f&&e.jsx(H,{open:f,onClose:()=>C(!1),onFirstTask:v}),N&&e.jsx(W,{open:!0,defaultProjectId:N,onClose:()=>v(null),onCreated:P}),e.jsx(ue,{taskId:g,open:!!g,onOpenChange:t=>{t||P(null)}}),c&&e.jsx(Te,{open:!!c,project:c,onClose:j,onFirstTask:t=>{j(),v(t)}},c.id),p&&e.jsx(ce,{open:!!p,title:"Delete project",description:"This deletes the project and its memories. Its tasks, jobs and sessions are kept without a project. This action cannot be undone.",confirmLabel:"Delete",variant:"destructive",isPending:D.isPending,onConfirm:()=>{D.mutate(p.id,{onSuccess:()=>S(null)})},onCancel:()=>S(null)})]})}function Te({open:r,project:l,onClose:d,onFirstTask:E}){const[o,_]=n.useState(l.name),[f,C]=n.useState(l.description??""),[N,v]=n.useState(l.status),[g,P]=n.useState((l.tags??[]).join(", ")),[p,S]=n.useState(l.scope??""),[y,w]=n.useState(l.git_remote_url??""),[j,D]=n.useState(l.max_workers!=null?String(l.max_workers):""),c=G(),{data:x}=J(l.id),i=s=>{if(s.preventDefault(),!o.trim())return;const h={id:l.id,name:o.trim(),description:f.trim()||null,status:N,tags:g.trim()?g.split(",").map(A=>A.trim()).filter(Boolean):null,scope:p.trim()||null,git_remote_url:y.trim()||null,max_workers:j?Number(j):null};c.mutate(h,{onSuccess:()=>d()})};return e.jsx(q,{open:r,onOpenChange:s=>!s&&d(),children:e.jsxs(K,{"data-testid":"edit-project-dialog",className:"bg-surface border-outline-variant max-w-lg max-h-[calc(100dvh-2rem)] overflow-y-auto",children:[e.jsx(Q,{children:e.jsx(X,{className:"font-headline text-base text-on-surface",children:"Edit Project"})}),x&&e.jsx(Ce,{summary:x}),e.jsx(T,{type:"button","data-testid":"project-create-task",variant:"outline",size:"sm",onClick:()=>E(l.id),children:"Create task in this project"}),e.jsxs("form",{onSubmit:i,className:"space-y-4 mt-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(b,{className:"font-label text-sm text-muted-foreground",children:"Name *"}),e.jsx(k,{"aria-label":"Name","data-testid":"edit-project-name-input",value:o,onChange:s=>_(s.target.value),className:"bg-background border-control-border text-on-surface font-body text-sm",autoFocus:!0})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(b,{className:"font-label text-sm text-muted-foreground",children:"Description"}),e.jsx(Y,{"aria-label":"Description",value:f,onChange:s=>C(s.target.value),rows:2,className:"bg-background border-control-border text-on-surface font-body text-sm resize-none"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(b,{className:"font-label text-sm text-muted-foreground",children:"Status"}),e.jsxs(Z,{value:N,onValueChange:s=>v(s),children:[e.jsx(ee,{"aria-label":"Status",className:"bg-background border-control-border text-on-surface font-label text-sm",children:e.jsx(te,{})}),e.jsx(se,{className:"bg-surface border-outline-variant",children:L.map(s=>e.jsx(ae,{value:s,className:"font-label text-sm",children:s},s))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(b,{className:"font-label text-sm text-muted-foreground",children:"Max Workers"}),e.jsx(k,{"aria-label":"Max Workers",type:"number",min:1,value:j,onChange:s=>D(s.target.value),placeholder:"1",className:"bg-background border-control-border text-on-surface font-body text-sm"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(b,{className:"font-label text-sm text-muted-foreground",children:"Tags (comma separated)"}),e.jsx(k,{"aria-label":"Tags (comma separated)",value:g,onChange:s=>P(s.target.value),className:"bg-background border-control-border text-on-surface font-body text-sm"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(b,{className:"font-label text-sm text-muted-foreground",children:"Scope"}),e.jsx(k,{"aria-label":"Scope",value:p,onChange:s=>S(s.target.value),className:"bg-background border-control-border text-on-surface font-body text-sm"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(b,{htmlFor:"edit-project-git-remote-url",className:"font-label text-sm text-muted-foreground",children:"Git remote URL (optional)"}),e.jsx(k,{id:"edit-project-git-remote-url",className:"bg-background border-control-border text-on-surface font-body text-sm","data-testid":"edit-project-git-remote-url",value:y,onChange:s=>w(s.target.value),placeholder:"https://github.com/owner/repo.git or git@github.com:owner/repo.git"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Clear this field to remove the saved address."})]}),e.jsxs(re,{children:[e.jsx(T,{type:"button",variant:"ghost",size:"sm",onClick:d,className:"font-label text-sm text-muted-foreground",children:"Cancel"}),e.jsx(T,{"data-testid":"edit-project-submit",type:"submit",size:"sm",disabled:c.isPending||!o.trim(),className:"font-label text-sm bg-primary text-primary-foreground hover:bg-primary/90",children:c.isPending?"Saving...":"Save"})]}),c.error&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:c.error.message})]})]})})}function Ce({summary:r}){return e.jsxs("div",{className:"grid grid-cols-3 gap-4 py-3 border-t border-outline-variant mt-2",children:[e.jsxs(B,{label:"Tasks",children:[e.jsx("span",{className:"font-label text-sm text-primary",children:r.tasks.total}),Object.keys(r.tasks.by_status).length>0&&e.jsxs("span",{className:"text-muted-foreground text-sm ml-1",children:["(",Object.entries(r.tasks.by_status).map(([l,d])=>`${d} ${l}`).join(", "),")"]})]}),e.jsx(B,{label:"Memories",children:e.jsx(le,{"data-testid":"project-memories-link",to:`${oe}?project=${encodeURIComponent(r.project.id)}`,className:"font-label text-sm text-primary underline",children:r.memories})}),e.jsx(B,{label:"Jobs",children:e.jsx("span",{className:"font-label text-sm text-primary",children:r.jobs})})]})}export{Ve as default};
@@ -1,11 +0,0 @@
1
- import{c as v,am as z,H as L,an as A,G as E,r as l,j as t,ao as I,ap as M,aq as U,af as q,ar as D,as as O,at as Z,au as F,d as H}from"./index-C_jtMgr7.js";/**
2
- * @license lucide-react v1.27.0 - ISC
3
- *
4
- * This source code is licensed under the ISC license.
5
- * See the LICENSE file in the root directory of this source tree.
6
- */const G=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],V=v("copy",G);/**
7
- * @license lucide-react v1.27.0 - ISC
8
- *
9
- * This source code is licensed under the ISC license.
10
- * See the LICENSE file in the root directory of this source tree.
11
- */const W=[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]],B=v("link-2",W),ne={running:{label:"working",dot:"bg-progress motion-safe:animate-pulse"},idle:{label:"waiting for you",dot:"bg-tertiary"},stopped:{label:"ended",dot:"bg-outline"},error:{label:"error",dot:"bg-error"}};function S(e){var i;if(!e.session_id||!/^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$/.test(e.session_id))return null;const a=(i=e.cwd)==null?void 0:i.replace(/^\\\\\?\\(?=[A-Za-z]:\\)/,""),n=/^[A-Za-z]:[\\/]|^\\\\/.test(a??""),r=a?n?`Set-Location -LiteralPath '${a.replace(/'/g,"''")}'; `:`cd '${a.replace(/'/g,"'\\''")}' && `:"";return e.agent==="claude"?`${r}claude --resume ${e.session_id}`:e.agent==="codex"?`${r}codex resume ${e.session_id}`:e.agent==="cursor-agent"?`${r}agent --resume ${e.session_id}`:e.agent==="gemini"?`${r}gemini --resume ${e.session_id}`:null}function J(e){return S(e)?null:e.agent==="cursor"?"Cursor IDE conversations cannot resume in a CLI terminal.":e.session_id?`Terminal resume is unavailable for this ${e.agent} session.`:"No native session ID was recorded."}function k(e,a){if(!a)return e;const[n,r=""]=e.split("?"),i=new URLSearchParams(r);return i.set("project",a),`${n}?${i}`}function K(e,a){const n=e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${Math.round(e/1e3)}k`:`${e}`;return a?`~${n}`:n}function ae(e){return e.tokens_used==null?"—":K(e.tokens_used,e.tokens_estimated)}function se(e){return e?new Date(e).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}):"—"}function re(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Q(e){return`/terminals?session=${encodeURIComponent(e)}`}function X(e){return`/terminals/${e}`}function Y(e,a){return e.find(n=>n.live_session_id===a&&n.status==="running")}function ee(e,a=window.location.origin){return`${a}${e}`}const m="inline-flex min-h-9 items-center justify-center gap-1.5 whitespace-nowrap rounded-md border border-border px-2 py-1 text-xs text-primary hover:bg-surface-highest disabled:opacity-50";function ie({session:e}){const{openLiveSession:a,info:n,terminals:r}=z(),i=L(),_=A(),[g]=E(),[p,x]=l.useState(!1),[f,b]=l.useState(!1),[y,o]=l.useState(null),[c,w]=l.useState(null),[N,h]=l.useState(!1),u=S(e),d=Y(r,e.id),j=g.get("project")??e.project_id,C=["claude","codex"].includes(e.agent)?!u||!e.cwd?"Session has no native session ID or working folder.":e.status==="running"||e.status==="idle"?"End the original agent session before resuming it in chat.":void 0:"Chat currently supports Claude and Codex sessions.";l.useEffect(()=>{if(!c)return;const s=setTimeout(()=>w(null),2e3);return()=>clearTimeout(s)},[c]);async function P(){if(o(null),d){i(k(X(d.id),j));return}x(!0);try{await a(e)}catch(s){o(s instanceof Error?s.message:"Could not open terminal")}finally{x(!1)}}async function $(s,R){h(!1),o(null);try{await navigator.clipboard.writeText(s),w(R)}catch{o("Clipboard access failed. Allow clipboard access and try again.")}}async function T(){h(!1),b(!0),o(null);try{_.openThread(await H.chat.resume(e.id));const s=new URLSearchParams(g);s.delete("session"),s.set("chat","open"),i({search:s.toString()})}catch(s){o(s instanceof Error?s.message:"Could not resume in chat")}finally{b(!1)}}return!u&&!d?t.jsx("span",{"data-testid":"resume-unavailable",className:"block max-w-64 text-xs text-outline",children:J(e)}):t.jsxs("div",{className:"max-w-72 space-y-1 text-left",children:[t.jsxs("fieldset",{"aria-label":"Resume session",className:"inline-flex",children:[t.jsxs("button",{type:"button","data-testid":"open-terminal-resume",disabled:p||f||!d&&!(n!=null&&n.ready),onClick:()=>void P(),className:`${m} rounded-r-none`,children:[t.jsx(I,{size:13}),p?"Resuming…":"Resume in terminal"]}),t.jsxs(M,{open:N,onOpenChange:h,children:[t.jsx(U,{asChild:!0,children:t.jsx("button",{type:"button","data-testid":"resume-actions-menu","aria-label":"More session actions",className:`${m} rounded-l-none border-l-0 px-2`,children:t.jsx(q,{size:13})})}),t.jsx(D,{children:t.jsxs(O,{align:"end",sideOffset:4,collisionPadding:8,"aria-label":"Session actions","data-testid":"resume-actions-dropdown",className:"z-50 w-56 rounded-md border border-border bg-surface-high p-1 shadow-lg",children:[t.jsxs("button",{type:"button","data-testid":"open-chat-resume",disabled:p||f||!!C,title:C,onClick:()=>void T(),className:`${m} min-h-11 w-full justify-start border-0`,children:[t.jsx(Z,{size:13}),f?"Resuming…":"Continue in chat"]}),u&&t.jsxs("button",{type:"button","data-testid":"copy-resume",className:`${m} w-full justify-start border-0`,title:u,onClick:()=>void $(u,"Resume command copied"),children:[c==="Resume command copied"?t.jsx(F,{size:13}):t.jsx(V,{size:13}),"Copy resume command"]}),t.jsxs("button",{type:"button","data-testid":"copy-terminal-link",className:`${m} w-full justify-start border-0`,"aria-label":"Copy terminal link",title:"Copy terminal link",onClick:()=>void $(ee(k(Q(e.id),j)),"Terminal link copied"),children:[t.jsx(B,{size:13}),"Copy terminal link"]})]})})]})]}),n&&!n.ready&&!d&&t.jsx("p",{className:"text-xs text-outline",children:n.reason??"Integrated terminals unavailable. Use the copied command in your own terminal."}),c&&t.jsx("p",{role:"status","data-testid":"resume-feedback",className:"text-xs text-outline",children:c}),y&&t.jsx("p",{role:"alert",className:"text-xs text-error break-words",children:y})]})}export{B as L,ie as R,ne as S,K as a,ae as b,re as e,se as f,Y as r,k as s,X as t};
@@ -1,5 +0,0 @@
1
- import{G as fe,H as ze,a as Ke,e as Ae,r as l,u as le,j as e,B as F,D as ce,m as de,n as xe,o as ue,U as me,p as ee,I as W,aY as Oe,d as J,L as Qe,aZ as Ge,a8 as Ve,a9 as We,aa as Ye,ab as Xe,a_ as Ue,A as Ze,E as et,ac as tt,S as st,a$ as at,ae as rt,X as nt}from"./index-C_jtMgr7.js";import{E as it}from"./EmptyState-Ctm7L70B.js";import{E as He}from"./ErrorState-BPTepwiG.js";import{e as ot,s as lt,L as ct,S as ae,b as he,f as re,R as pe}from"./ResumeActions-DHTOr6GQ.js";import{S as Fe}from"./StatusBadge-C5G1fdZh.js";import{d as dt,u as Be,e as xt,f as ut,g as mt}from"./useSessions-BrdK-12R.js";import{P as ht}from"./pencil-gxvh59uO.js";import{R as Ie}from"./refresh-cw-BQRdbjy6.js";import{P as pt}from"./Pager-ClYYU9et.js";import{T as gt,a as ft,b as qe,c as B,d as jt,e as I}from"./table-D3N_5Wee.js";import{V as vt}from"./ViewHeader-DXR0ZaMO.js";import{u as bt}from"./useProjectScope-Dk0mjyHf.js";function yt({projectId:s}){var je,ve,be,ye,Ne,we,ke,Se,Ce,_e;const[d]=fe(),u=ze(),f=Ke(),p=Ae(),[h,x]=l.useState({key:"",offset:0}),[n,i]=l.useState(null),[w,k]=l.useState(!1),[c,L]=l.useState(!1),[b,o]=l.useState(""),[m,g]=l.useState(""),[A,$]=l.useState(s),[E,T]=l.useState(""),[R,z]=l.useState(""),[O,P]=l.useState(""),[D,U]=l.useState(""),[r,v]=l.useState(0),q=d.get("q")??"",H=d.get("agent")??"",t=d.get("ended")!=="0",N=JSON.stringify([s,q,H]),_=h.key===N?h.offset:0,C=a=>x({key:N,offset:a}),y=le({queryKey:["sessions","archive",s,q,H,_],queryFn:()=>J.sessions.archive({q,...s==="all"?{}:{project_id:s},...["claude","codex"].includes(H)?{agent:H}:{},offset:_,limit:20}),enabled:t,refetchInterval:1e4}),te=le({queryKey:["sessions","archive-transcript",n==null?void 0:n.id,n==null?void 0:n.revision,r],queryFn:()=>J.sessions.archiveTranscript(n==null?void 0:n.id,{revision:n==null?void 0:n.revision,offset:r,limit:50}),enabled:!!n});async function ne(a){L(!0),o(""),g("");try{await a(),await f.invalidateQueries({queryKey:["sessions"]})}catch(S){o(S instanceof Error?S.message:"Request failed")}finally{L(!1)}}async function Me(a){var Te,Le;if(!(a!=null&&a.length))return;const S=(Le=(Te=p.data)==null?void 0:Te.find(K=>K.id===A))==null?void 0:Le.name;if(!S){o("Select a project before uploading");return}await ne(async()=>{var Pe,Ee,Re,De;let K=localStorage.getItem("orc_session_upload_source");K||(K=crypto.randomUUID(),localStorage.setItem("orc_session_upload_source",K));let $e=0;const Y=[];for(const se of Array.from(a))try{if(se.size>60*1024*1024)throw new Error("File exceeds 60 MiB");const X=await se.text(),ie=X.split(/\r?\n/).filter(Z=>Z.trim()).map(Z=>JSON.parse(Z)),Q=((Pe=ie[0])==null?void 0:Pe.type)==="session_meta",j=Q?ie[0].payload:ie.find(Z=>Z.sessionId),Je=await J.sessions.archiveUpload({project:S,source_id:K,agent:Q?"codex":"claude",session_id:Q?j==null?void 0:j.id:j==null?void 0:j.sessionId,title:se.name.slice(0,200),metadata:{cwd:(j==null?void 0:j.cwd)??"",subdirectory:"",...Q&&((Ee=j==null?void 0:j.git)!=null&&Ee.repository_url)?{repository:j.git.repository_url}:{},...Q&&((Re=j==null?void 0:j.git)!=null&&Re.branch)?{branch:j.git.branch}:{},...Q&&((De=j==null?void 0:j.git)!=null&&De.commit_hash)?{commit:j.git.commit_hash}:{}},bundle:{version:1,files:[{path:"session.jsonl",content:X}]}});["created","updated","unchanged","stale"].includes(Je.outcome)&&$e++}catch(X){Y.push(`${se.name}: ${X instanceof Error?X.message:"Upload failed"}`)}g(`${$e} of ${a.length} sessions synchronized${Y.length?`; ${Y.length} need attention`:""}.`),Y.length&&o(Y.join(`
2
- `))})}return t?e.jsxs("section",{className:"mt-8 space-y-3","data-testid":"session-archive",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-medium",children:"Archived sessions"}),e.jsx("p",{className:"text-xs text-outline",children:"Uploaded history stays available after the source computer is offline."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(F,{variant:"outline","data-testid":"archive-index",disabled:c,onClick:()=>void ne(async()=>{const a=await J.sessions.archiveIndex(s==="all"||s==="unassigned"?void 0:s);g(`${a.indexed} sessions indexed; ${a.failed} failed; ${a.skipped} skipped.`)}),children:"Index discovered sessions"}),e.jsx(F,{"data-testid":"archive-upload-open",onClick:()=>{$(s),k(!0)},children:"Upload sessions"})]})]}),m&&e.jsx("p",{role:"status","data-testid":"archive-feedback",className:"text-sm",children:m}),(b||y.error)&&e.jsx("p",{role:"alert",className:"whitespace-pre-wrap text-sm text-error",children:b||((je=y.error)==null?void 0:je.message)}),((ve=y.data)==null?void 0:ve.degraded)&&e.jsx("p",{role:"status","data-testid":"archive-degraded",className:"text-xs text-outline",children:y.data.degraded}),!!((be=y.data)!=null&&be.pending_chunks)&&e.jsxs("p",{className:"text-xs text-outline",children:[y.data.pending_chunks," passages waiting for embeddings"]}),e.jsxs("div",{className:"divide-y divide-outline-variant rounded border border-outline-variant",children:[y.isLoading&&e.jsx("p",{className:"p-4 text-sm",children:"Loading archived sessions…"}),!y.isLoading&&!((ye=y.data)!=null&&ye.sessions.length)&&e.jsx("p",{className:"p-4 text-sm text-outline",children:"No archived sessions match this view."}),(Ne=y.data)==null?void 0:Ne.sessions.map(a=>e.jsxs("button",{type:"button","data-testid":"archive-session-row","data-archive-id":a.id,className:"block w-full p-3 text-left hover:bg-surface-container",onClick:()=>{i(a),v(0),T(a.metadata.repository??""),z(a.metadata.branch??""),P(a.metadata.commit??""),U(a.metadata.subdirectory)},children:[e.jsx("span",{className:"block text-sm font-medium",children:a.title}),e.jsxs("span",{className:"text-xs text-outline",children:[a.agent," · ended · ",new Date(a.updated_at).toLocaleString()," · revision"," ",a.revision," · ",a.metadata.cwd]}),a.passages.map(S=>e.jsx("span",{className:"mt-1 block text-sm text-outline",children:S.snippet},S.citation)),a.embedding_error&&e.jsx("span",{className:"block text-xs text-error",children:a.embedding_error})]},a.id))]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(F,{variant:"ghost",disabled:_===0,onClick:()=>C(Math.max(0,_-20)),children:"Previous"}),e.jsx(F,{variant:"ghost",disabled:!((we=y.data)!=null&&we.has_more),onClick:()=>C(_+20),children:"Next"})]}),e.jsx(ce,{open:w,onOpenChange:k,children:e.jsxs(de,{children:[e.jsxs(xe,{children:[e.jsx(ue,{children:"Upload session histories"}),e.jsx(me,{children:"Select an existing project and native Claude/Codex JSONL files. This stores history without starting a terminal. For large collections, use the orc-platform sync script."})]}),e.jsx(ee,{htmlFor:"archive-project",children:"Project"}),e.jsxs("select",{id:"archive-project","data-testid":"archive-project",value:A,onChange:a=>$(a.target.value),className:"rounded border border-outline-variant bg-surface p-2",children:[e.jsx("option",{value:"all",children:"Select a project"}),(ke=p.data)==null?void 0:ke.map(a=>e.jsx("option",{value:a.id,children:a.name},a.id))]}),e.jsx(W,{"data-testid":"archive-files",type:"file",multiple:!0,accept:".jsonl",disabled:c||!((Se=p.data)!=null&&Se.some(a=>a.id===A)),onChange:a=>void Me(a.target.files)}),c&&e.jsx("p",{role:"status",children:"Uploading…"}),m&&e.jsx("p",{role:"status","data-testid":"archive-upload-feedback",children:m}),b&&e.jsx("p",{role:"alert",className:"whitespace-pre-wrap text-sm text-error",children:b})]})}),e.jsx(ce,{open:!!n,onOpenChange:a=>{a||i(null)},children:e.jsxs(de,{className:"max-h-[90vh] max-w-3xl overflow-y-auto","data-testid":"archive-detail",children:[e.jsxs(xe,{children:[e.jsx(ue,{children:n==null?void 0:n.title}),e.jsxs(me,{children:["Archived history · revision ",n==null?void 0:n.revision,". Prepare a destination checkout to continue in a terminal."]})]}),te.error&&e.jsx("p",{role:"alert",children:te.error.message}),(Ce=te.data)==null?void 0:Ce.turns.map(a=>e.jsxs("div",{className:"border-b border-outline-variant py-2","data-testid":"archive-turn",children:[e.jsx("p",{className:"text-xs text-outline",children:a.role}),e.jsx(Oe,{plain:!0,children:a.blocks.map(S=>S.type==="tool_use"?`${S.name}
3
- ${S.input}
4
- ${S.result??""}`:S.text).join(`
5
- `)})]},a.index)),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(F,{variant:"ghost",disabled:!r,onClick:()=>v(Math.max(0,r-50)),children:"Previous messages"}),e.jsx(F,{variant:"ghost",disabled:r+50>=(((_e=te.data)==null?void 0:_e.total)??0),onClick:()=>v(r+50),children:"Next messages"})]}),e.jsxs("div",{className:"space-y-2 border-t border-outline-variant pt-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Continue on ORC"}),e.jsx("p",{className:"text-xs text-outline",children:"Use the pushed repository, branch and exact commit for the work you want to continue. The destination project must have its repository configured."}),e.jsx(ee,{htmlFor:"archive-repository",children:"Repository"}),e.jsx(W,{id:"archive-repository","data-testid":"archive-repository",value:E,onChange:a=>T(a.target.value)}),e.jsx(ee,{htmlFor:"archive-branch",children:"Branch"}),e.jsx(W,{id:"archive-branch","data-testid":"archive-branch",value:R,onChange:a=>z(a.target.value)}),e.jsx(ee,{htmlFor:"archive-commit",children:"Pushed commit"}),e.jsx(W,{id:"archive-commit","data-testid":"archive-commit",value:O,onChange:a=>P(a.target.value)}),e.jsx(ee,{htmlFor:"archive-subdirectory",children:"Repository subdirectory"}),e.jsx(W,{id:"archive-subdirectory","data-testid":"archive-subdirectory",value:D,onChange:a=>U(a.target.value),placeholder:"Repository root"}),e.jsx(F,{"data-testid":"archive-resume",disabled:c||!E||!R||!/^[a-f0-9]{40}$/i.test(O),onClick:()=>void ne(async()=>{if(!n)return;const a=await J.sessions.archiveResume(n.id,{revision:n.revision,repository:E,branch:R,commit:O,subdirectory:D});if(a.status!=="ready"||!a.live_session_id)throw new Error(a.error||"Session preparation failed");const S=await J.terminals.create({kind:n.agent,live_session_id:a.live_session_id});u(`/terminals/${S.id}`)}),children:c?"Preparing…":"Prepare and resume in terminal"}),b&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:b})]})]})})]}):null}function G({text:s,query:d}){const u=d.trim();if(u.length<2)return e.jsx(e.Fragment,{children:s});const f=s.split(new RegExp(`(${ot(u)})`,"gi"));return e.jsx(e.Fragment,{children:f.map((p,h)=>p.toLowerCase()===u.toLowerCase()?e.jsx("mark",{className:"bg-primary/30 text-on-surface rounded-sm",children:p},h):p)})}function Nt({projectId:s,pending:d,onSelect:u}){var b;const[f,p]=l.useState(""),[h,x]=l.useState(!1),[n,i]=l.useState(null),w=le({queryKey:["tasks","session-picker",s],queryFn:()=>J.tasks.list({...s?{project_id:s}:{},limit:100})});async function k(o){i(null);try{await u(o)}catch(m){i(m instanceof Error?m.message:"Could not link task")}}async function c(){x(!0),i(null);try{const o=await J.tasks.get(f.trim());await k(o.id)}catch(o){i(o instanceof Error?o.message:"Task lookup failed")}finally{x(!1)}}const L=(((b=w.data)==null?void 0:b.tasks)??[]).filter(o=>`${o.title} ${o.id}`.toLowerCase().includes(f.trim().toLowerCase()));return e.jsxs("div",{className:"space-y-3",children:[e.jsx(W,{"data-testid":"session-task-search","aria-label":"Search tasks or enter a task ID",value:f,onChange:o=>{p(o.target.value),i(null)},placeholder:"Search recent tasks or paste a task ID"}),e.jsxs("p",{className:"text-xs text-outline",children:["Up to 100 recent tasks",s?" in this project":" across projects",". Older or other-project tasks can be linked by exact ID."]}),n&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:n}),w.error?e.jsx(He,{message:w.error.message,onRetry:()=>w.refetch()}):w.isLoading?e.jsx("p",{role:"status",children:"Loading tasks…"}):e.jsxs("div",{className:"max-h-72 overflow-y-auto divide-y divide-border",children:[L.map(o=>e.jsxs("button",{type:"button","data-testid":"session-task-option","data-task-id":o.id,disabled:d||h,onClick:()=>void k(o.id),className:"w-full min-h-11 py-2 text-left hover:bg-surface-highest disabled:opacity-50",children:[e.jsx("span",{className:"block text-sm break-words",children:o.title}),e.jsxs("span",{className:"inline-flex items-center gap-2 text-xs text-outline",children:[e.jsx(Fe,{status:o.status,className:"px-0"}),o.id]})]},o.id)),L.length===0&&e.jsx("p",{className:"py-4 text-sm text-outline",children:"No recent task matches. Paste its exact ID to look it up."})]}),f.trim()&&e.jsx(F,{variant:"outline",disabled:d||h,onClick:()=>void c(),children:h?"Looking up…":"Link by exact ID"})]})}function ge({session:s,linkTestId:d="open-task"}){const[u]=fe(),[f,p]=l.useState(!1),h=dt(),x=u.get("project")??s.project_id;async function n(i){try{await h.mutateAsync({id:s.id,taskId:i}),p(!1)}catch{}}return e.jsxs("div",{className:"min-w-0 space-y-1",children:[s.task&&e.jsxs("div",{className:"min-w-0",children:[e.jsx(Qe,{"data-testid":d,to:lt(`/tasks/${s.task.id}`,x),className:"block max-w-64 truncate text-sm text-primary hover:underline",title:s.task.title,children:s.task.title}),e.jsx(Fe,{status:s.task.status,className:"px-0"})]}),e.jsxs(ce,{open:f,onOpenChange:i=>{p(i),i&&h.reset()},children:[e.jsx(Ge,{asChild:!0,children:e.jsxs("button",{type:"button","data-testid":"link-task",className:"inline-flex min-h-9 items-center gap-1.5 text-xs text-outline hover:text-on-surface",children:[s.task?e.jsx(ht,{size:12}):e.jsx(ct,{size:13}),s.task?"Change task":"Link task"]})}),e.jsxs(de,{"data-testid":"session-task-dialog",className:"max-h-[85dvh] w-[calc(100%-2rem)] overflow-y-auto",children:[e.jsxs(xe,{children:[e.jsx(ue,{children:"Link a task"}),e.jsxs(me,{children:["Choose a recent task for ",s.name??"this session",", or paste an exact task ID."]})]}),h.error&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:h.error.message}),e.jsx(Nt,{projectId:s.project_id,pending:h.isPending,onSelect:n}),e.jsx("div",{className:"flex flex-wrap gap-2",children:s.task&&e.jsx(F,{variant:"outline","data-testid":"session-task-unlink",disabled:h.isPending,onClick:()=>void n(null),children:"Unlink task"})})]})]})]})}const oe="session-search",wt={user:"border-border/65",assistant:"border-border/65",tool:"border-border/65 bg-transparent",system:"border-border/65 bg-transparent"},kt=["command","cmd","file_path","path","pattern","query","url","description"];function St(s){try{const d=JSON.parse(s);for(const u of kt)if(typeof d[u]=="string")return d[u]}catch{}return s}function Ct(s){try{return JSON.stringify(JSON.parse(s),null,2)}catch{return s}}function _t(s,d,u){l.useEffect(()=>{const f=s.current,p=CSS.highlights,h=window.Highlight;if(!f||!p||!h)return;const x=d.trim().toLowerCase(),n=()=>{var L;if(p.delete(oe),x.length<2)return;const k=[],c=document.createTreeWalker(f,NodeFilter.SHOW_TEXT);for(let b=c.nextNode();b;b=c.nextNode()){const o=((L=b.textContent)==null?void 0:L.toLowerCase())??"";for(let m=o.indexOf(x);m>=0;m=o.indexOf(x,m+x.length)){const g=new Range;g.setStart(b,m),g.setEnd(b,m+x.length),k.push(g)}}k.length>0&&p.set(oe,new h(...k))};n();let i;const w=new MutationObserver(()=>{clearTimeout(i),i=setTimeout(n,150)});return w.observe(f,{childList:!0,subtree:!0,characterData:!0}),()=>{clearTimeout(i),w.disconnect(),p.delete(oe)}},[s,d,u])}function Tt({block:s,open:d}){const u=s.result!==void 0;return e.jsxs("details",{open:d||void 0,"data-testid":"tool-box",className:"border-l border-border bg-background",children:[e.jsxs("summary",{className:"flex cursor-pointer items-center gap-2 px-2 py-1.5 font-label text-xs font-medium text-outline hover:text-on-surface",children:[e.jsx("span",{className:"text-secondary shrink-0",children:s.name}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono normal-case tracking-normal text-on-surface-variant",children:St(s.input)}),e.jsx("span",{className:`shrink-0 ${u?"text-outline":"text-tertiary"}`,children:u?"done":"no result"})]}),e.jsxs("div",{className:"space-y-2 border-t border-border px-2 py-2",children:[e.jsx("div",{className:"font-label text-[10px] font-medium text-outline",children:"input"}),e.jsx("pre",{className:"max-h-72 overflow-auto rounded-lg bg-background p-2 font-mono text-xs text-on-surface-variant whitespace-pre-wrap break-words",children:Ct(s.input)}),u&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"font-label text-[10px] font-medium text-outline",children:"result"}),e.jsx("pre",{className:"max-h-96 overflow-auto rounded-lg bg-background p-2 font-mono text-xs text-on-surface-variant whitespace-pre-wrap break-words",children:s.result})]})]})]})}function Lt({block:s,matched:d}){if(s.type==="text")return e.jsx(Oe,{revealContext:d,children:s.text});if(s.type==="tool_use")return e.jsx(Tt,{block:s,open:d});const u=s.type==="thinking"?"thinking":"result";return e.jsxs("details",{open:d||void 0,children:[e.jsx("summary",{className:"cursor-pointer font-label text-xs font-medium text-outline hover:text-on-surface",children:u}),s.type==="thinking"?e.jsx("div",{className:"mt-1",children:e.jsx(rt,{children:s.text})}):e.jsx("pre",{className:"mt-1 max-h-96 overflow-auto rounded-lg bg-background p-2 font-mono text-xs text-on-surface-variant whitespace-pre-wrap break-words",children:s.text})]})}function $t({sessionId:s,initialQuery:d,onClose:u}){const[f,p]=l.useState(d),[h,x]=l.useState(0),{data:n}=Be(!1),i=n==null?void 0:n.find(r=>r.id===s),w=i!==void 0&&i.status!=="stopped",k=f.trim().length>=2?f.trim():"",{data:c,isLoading:L,isFetching:b,error:o,refetch:m,dataUpdatedAt:g}=xt(s,k),A=l.useRef(null),$=l.useRef(null),E=l.useRef(!0),T=l.useRef(0),[R,z]=l.useState(!0),O=l.useCallback(()=>{const r=A.current;r&&(r.scrollTo({top:r.scrollHeight}),requestAnimationFrame(()=>r.scrollTo({top:r.scrollHeight})))},[]);_t($,k,c==null?void 0:c.turns);const P=(c==null?void 0:c.matches)??[],D=P[h];l.useEffect(()=>{var r;if(c){if(D!==void 0){E.current=!1,(r=document.getElementById(`turn-${D}`))==null||r.scrollIntoView({block:"center"});return}E.current&&O()}},[D,c,O]),l.useEffect(()=>{c&&R&&(T.current=c.total)},[c,R]);const U=r=>{P.length>0&&x(v=>(v+r+P.length)%P.length)};return e.jsx(Ve,{open:!!s,onOpenChange:r=>!r&&u(),children:e.jsxs(We,{side:"right",className:"w-[1100px] max-w-[95vw]","data-testid":"live-session-detail",children:[e.jsxs(Ye,{children:[e.jsx(Xe,{className:"normal-case tracking-normal text-sm pr-8",children:(i==null?void 0:i.name)??"Session"}),i&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-x-5 gap-y-1 font-body text-xs text-on-surface tabular-nums",children:[e.jsx("span",{className:"font-medium text-primary",children:i.agent}),e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${ae[i.status].dot}`}),ae[i.status].label]}),e.jsxs("span",{children:[e.jsx("span",{className:"text-on-surface-variant",children:"tokens "}),he(i)]}),e.jsxs("span",{children:[e.jsx("span",{className:"text-on-surface-variant",children:"active "}),re(i.last_activity_at)]}),e.jsx(ge,{session:i,linkTestId:"detail-open-task"}),e.jsx(pe,{session:i}),e.jsx("span",{className:"truncate max-w-full text-on-surface-variant",children:i.cwd})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative min-w-[150px] flex-1",children:[e.jsx(Ue,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3 w-3 text-outline"}),e.jsx("input",{"data-testid":"transcript-search","aria-label":"Search this session",value:f,onChange:r=>{p(r.target.value),x(0)},placeholder:"Search this session",className:"w-full bg-background border border-control-border rounded-lg min-h-11 pl-7 pr-2 py-2 font-body text-xs text-on-surface"})]}),k&&e.jsx("span",{"data-testid":"transcript-match-count",className:"font-label text-xs font-medium text-outline",children:P.length===0?"no matches":`${h+1} / ${P.length}`}),e.jsx("button",{type:"button","aria-label":"Previous match",onClick:()=>U(-1),className:"min-h-11 min-w-11 p-2 text-outline hover:text-on-surface",children:e.jsx(Ze,{className:"h-4 w-4"})}),e.jsx("button",{type:"button","aria-label":"Next match",onClick:()=>U(1),className:"min-h-11 min-w-11 p-2 text-outline hover:text-on-surface",children:e.jsx(et,{className:"h-4 w-4"})}),e.jsxs("button",{type:"button","data-testid":"transcript-refresh",onClick:()=>{E.current=!0,m()},className:"min-h-11 px-2 inline-flex items-center gap-1 font-label text-xs font-medium text-primary hover:text-on-surface",children:[e.jsx(Ie,{className:`h-3 w-3 ${b?"animate-spin":""}`}),"Refresh"]})]}),c&&e.jsxs("div",{"data-testid":"transcript-status",className:"mt-2 font-body text-xs text-on-surface-variant tabular-nums",children:[c.total," turns",w?` · live, updated ${new Date(g).toLocaleTimeString()}`:""]})]}),e.jsxs("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[e.jsx(tt,{ref:A,onScroll:r=>{const v=r.currentTarget,q=v.scrollHeight-v.scrollTop-v.clientHeight<160;E.current=q,z(q)},children:L?e.jsx("div",{className:"space-y-4",children:[...Array(5)].map((r,v)=>e.jsx(st,{className:"h-16 w-full bg-surface-highest"},v))}):o||!c?e.jsxs("div",{"data-testid":"transcript-unavailable",className:"font-body text-xs text-outline py-12 text-center",children:[o?`Could not load the conversation: ${o.message}`:"No conversation was recorded for this session.",e.jsx("p",{className:"mt-2",children:"Resume actions remain available when the native agent session exists."}),e.jsx("button",{type:"button",className:"mt-3 min-h-11 text-primary hover:underline",onClick:()=>m(),children:"Retry conversation"})]}):e.jsx("div",{ref:$,className:"space-y-3",children:c.turns.map(r=>{const v=P.includes(r.index),q=r.blocks.map((H,t)=>e.jsx(Lt,{block:H,matched:v},t));return e.jsxs("div",{id:`turn-${r.index}`,"data-testid":"transcript-turn","data-role":r.role,style:{contentVisibility:"auto",containIntrinsicSize:"auto 120px"},className:`border-b px-4 py-3 text-on-surface space-y-2 ${wt[r.role]} ${r.index===D?"ring-1 ring-primary":""}`,children:[e.jsxs("div",{className:"font-label text-xs font-medium text-outline",children:[r.role,r.time?` · ${re(r.time)}`:""]}),r.role==="system"?e.jsxs("details",{open:v||void 0,children:[e.jsx("summary",{className:"cursor-pointer font-label text-xs font-medium text-outline hover:text-on-surface",children:"injected context"}),e.jsx("div",{className:"mt-2 space-y-2",children:q})]}):q]},r.index)})})}),c&&!R&&e.jsxs("button",{type:"button","data-testid":"jump-to-latest",onClick:()=>{E.current=!0,O()},className:"absolute bottom-4 right-6 inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 font-body text-xs text-primary shadow-lg hover:bg-surface-bright",children:[e.jsx(at,{className:"h-3.5 w-3.5"}),"Jump to latest",c.total>T.current&&` · ${c.total-T.current} new`]})]})]})})}const Pt=["claude","codex","cursor","cursor-agent","gemini"],V=25,M="font-label text-xs font-medium text-outline";function Et({projectId:s}){var H;const d=nt("sm"),[u,f]=fe(),p=u.get("agent")??"",h=u.get("ended")!=="0",x=u.get("q")??"",n=u.get("order")==="asc"?"asc":"desc",i=u.get("session"),[w,k]=l.useState(x),[c,L]=l.useState({order:n,page:0}),b=c.order===n?c.page:0,o=l.useCallback(t=>L({order:n,page:t}),[n]),m=l.useCallback((t,N)=>{o(0),f(_=>{const C=new URLSearchParams(_);return N?C.set(t,N):C.delete(t),C},{replace:t==="q"})},[f,o]);l.useEffect(()=>k(x),[x]),l.useEffect(()=>{if(w===x)return;const t=setTimeout(()=>m("q",w.trim()||null),350);return()=>clearTimeout(t)},[w,x,m]);const g=x.trim().length>=2,A=Be(!h),$=ut(g?x.trim():"",p),{data:E}=Ae(),T=mt(),R=new Map((E??[]).map(t=>[t.id,t.name])),z=g?((H=$.data)==null?void 0:H.hits)??[]:A.data??[],O=[...new Set([...Pt,...z.map(t=>t.agent)])],P=g?$.isLoading:A.isLoading,D=g?$:A,U=z.filter(t=>{var N;return(!p||t.agent===p)&&(h||t.status!=="stopped"||((N=t.handoff)==null?void 0:N.status)==="ready")}),r=U.filter(t=>s==="all"?!0:s==="unassigned"?t.project_id===null:t.project_id===s).sort((t,N)=>{const C=new Date(t.last_activity_at??t.created_at).getTime()-new Date(N.last_activity_at??N.created_at).getTime()||t.id.localeCompare(N.id);return n==="asc"?C:-C}),v=Math.min(b,Math.max(0,Math.ceil(r.length/V)-1))*V,q=s==="unassigned"?"unassigned":R.get(s)??s;return e.jsxs("section",{className:"mb-8","data-testid":"live-sessions",children:[e.jsx("p",{className:"mb-4 text-sm text-outline",children:"Discovered from your coding agents. Working sessions update automatically; waiting sessions remain available to resume."}),e.jsxs("div",{className:"mb-3 relative",children:[e.jsx(Ue,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-outline"}),e.jsx("input",{"data-testid":"session-search","aria-label":"Search agent sessions",value:w,onChange:t=>k(t.target.value),placeholder:"Search agent sessions: titles, summaries and conversation text",className:"w-full bg-background border border-control-border rounded-lg pl-9 pr-3 py-2 font-body text-xs text-on-surface placeholder:text-outline"})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 mb-4",children:[e.jsxs("h2",{className:"font-label text-xs font-medium text-outline",children:[g?"Search results":"Agent sessions"," · ",r.length,r.length!==U.length&&e.jsxs("span",{"data-testid":"scope-hint",className:"normal-case tracking-normal",children:[" ","of ",U.length," · scope: ",q]}),g&&$.data&&e.jsxs("span",{"data-testid":"search-meta",className:"normal-case tracking-normal",children:[" ","· ",($.data.ms/1e3).toFixed(1),"s",$.data.rg?"":" · titles and summaries only (install ripgrep for content)"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("select",{"aria-label":"Sort sessions by date","data-testid":"session-date-sort",value:n,onChange:t=>m("order",t.target.value==="asc"?"asc":null),className:"min-h-11 rounded-md border border-control-border bg-background px-3 text-sm text-on-surface",children:[e.jsx("option",{value:"desc",children:"Last active: newest first"}),e.jsx("option",{value:"asc",children:"Last active: oldest first"})]}),e.jsxs("select",{"data-testid":"agent-filter","aria-label":"Agent",className:"bg-background border border-control-border rounded-lg min-h-11 px-3 py-2 font-label text-xs font-medium text-on-surface",value:p,onChange:t=>m("agent",t.target.value||null),children:[e.jsx("option",{value:"",children:"all agents"}),O.map(t=>e.jsx("option",{value:t,children:t},t))]}),e.jsxs("label",{className:"flex items-center gap-2 font-label text-xs font-medium text-outline cursor-pointer",children:[e.jsx("input",{type:"checkbox","data-testid":"show-ended",checked:h,onChange:t=>m("ended",t.target.checked?"1":"0")}),"Show ended"]}),e.jsxs("button",{type:"button","data-testid":"sync-sessions",disabled:T.isPending,className:"min-h-11 px-2 inline-flex items-center gap-1 font-label text-xs font-medium text-primary hover:text-on-surface disabled:opacity-50",onClick:()=>T.mutate(),children:[e.jsx(Ie,{className:`h-3 w-3 ${T.isPending?"animate-spin":""}`}),T.isPending?"Syncing":"Refresh"]})]})]}),T.error&&e.jsx("p",{role:"alert",className:"mb-3 text-sm text-error",children:T.error.message}),D.error?e.jsx(He,{message:D.error.message,onRetry:()=>D.refetch()}):P?e.jsx("p",{role:"status",className:"py-8 text-sm text-outline",children:"Loading sessions…"}):r.length===0?e.jsx(it,{message:g?"No sessions match":"No active agent sessions. Enable Show ended to browse previous conversations."}):e.jsxs("div",{className:"min-w-0 overflow-hidden",children:[d?e.jsxs(gt,{children:[e.jsx(ft,{children:e.jsxs(qe,{className:"border-b border-border hover:bg-transparent",children:[e.jsx(B,{className:`${M} w-40`,children:"Status"}),e.jsx(B,{className:`${M} w-20`,children:"Agent"}),e.jsx(B,{className:M,children:"Session"}),e.jsx(B,{className:`${M} w-28`,children:"Project"}),e.jsx(B,{className:`${M} w-20 text-right`,children:"Tokens"}),e.jsx(B,{className:`${M} w-36`,children:"Last active"}),e.jsx(B,{className:`${M} w-56`,children:"Task"}),e.jsx(B,{className:`${M} w-24`})]})}),e.jsx(jt,{children:r.slice(v,v+V).map(t=>{var _,C;const N=ae[t.status];return e.jsxs(qe,{"data-testid":"live-session-row","data-session-id":t.session_id,"data-agent":t.agent,className:"border-b border-border/65 cursor-pointer hover:bg-surface-high",onClick:y=>{y.target.closest("button, a, input, [role='dialog']")||m("session",t.id)},children:[e.jsx(I,{className:"font-label text-xs text-on-surface",children:e.jsxs("span",{className:"inline-flex items-center gap-2","data-testid":"live-status",children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${N.dot}`}),((_=t.handoff)==null?void 0:_.status)==="ready"?"Ready":N.label]})}),e.jsx(I,{className:"font-label text-xs font-medium text-primary",children:t.agent}),e.jsxs(I,{className:"max-w-md",children:[e.jsx("button",{type:"button",className:"block max-w-full text-left font-body text-sm font-medium text-on-surface truncate hover:text-primary",onClick:y=>{y.stopPropagation(),m("session",t.id)},children:e.jsx(G,{text:t.name??"Untitled session",query:g?x:""})}),t.summary&&t.summary!==t.name&&e.jsx("div",{className:"font-body text-xs text-outline truncate",title:t.summary,children:e.jsx(G,{text:t.summary,query:g?x:""})}),(C=t.snippets)==null?void 0:C.map(y=>e.jsx("div",{"data-testid":"search-snippet",className:"font-mono text-xs text-on-surface-variant truncate",title:y,children:e.jsx(G,{text:y,query:x})},y)),e.jsx("div",{className:"font-label text-xs text-outline truncate",title:t.cwd??void 0,children:t.cwd??""})]}),e.jsx(I,{className:"font-label text-xs text-outline",children:t.project_id&&R.get(t.project_id)||"—"}),e.jsx(I,{"data-testid":"live-tokens",className:"font-body text-xs text-on-surface-variant text-right",children:he(t)}),e.jsx(I,{className:"font-body text-xs text-on-surface-variant",children:re(t.last_activity_at)}),e.jsx(I,{children:e.jsx(ge,{session:t})}),e.jsx(I,{className:"text-right",children:e.jsx("div",{className:"inline-flex items-center gap-3",children:e.jsx(pe,{session:t})})})]},t.id)})})]}):e.jsx("div",{className:"divide-y divide-border",children:r.slice(v,v+V).map(t=>{var N,_;return e.jsxs("article",{"data-testid":"live-session-row","data-session-id":t.session_id,"data-agent":t.agent,className:"py-4 space-y-3",children:[e.jsx("button",{type:"button",className:"text-left text-sm font-medium break-words hover:text-primary",onClick:()=>m("session",t.id),children:e.jsx(G,{text:t.name??"Untitled session",query:g?x:""})}),e.jsxs("div",{className:"flex flex-wrap gap-3 text-xs text-outline",children:[e.jsx("span",{className:"text-primary",children:t.agent}),e.jsx("span",{"data-testid":"live-status",children:((N=t.handoff)==null?void 0:N.status)==="ready"?"Ready":ae[t.status].label}),e.jsxs("span",{"data-testid":"live-tokens",children:[he(t)," tokens"]}),e.jsx("span",{children:re(t.last_activity_at)})]}),t.summary&&e.jsx("p",{className:"text-sm text-outline break-words",children:e.jsx(G,{text:t.summary,query:g?x:""})}),(_=t.snippets)==null?void 0:_.map(C=>e.jsx("p",{"data-testid":"search-snippet",className:"text-xs break-words text-on-surface-variant",children:e.jsx(G,{text:C,query:x})},C)),e.jsxs("p",{className:"text-xs text-outline break-all",children:[t.project_id&&R.get(t.project_id)||"Unassigned",t.cwd?` · ${t.cwd}`:""]}),e.jsx(ge,{session:t}),e.jsx(pe,{session:t})]},t.id)})}),e.jsx(pt,{page:v/V,pageSize:V,total:r.length,onPage:o})]}),e.jsx($t,{sessionId:i,initialQuery:g?x.trim():"",onClose:()=>m("session",null)},i??"closed")]})}function zt({projectId:s}){const d=bt(s);return e.jsxs("div",{children:[e.jsx(vt,{title:"Sessions"}),e.jsx(Et,{projectId:d},d),e.jsx(yt,{projectId:d},`archive-${d}`)]})}export{zt as default};
@@ -1 +0,0 @@
1
- import{g as p,r as u,d as a}from"./chunk-SVP7TREG-CmiQdvOH.js";import{p as f}from"./chunk-JWPE2WC7-zdsOarNZ.js";import{_ as n,l as o}from"./mermaid-HWGCJPDP-C8QwWdo5.js";import{M as c,b as d}from"./cynefin-OW5HDTMX-vMXgcpgg.js";import"./index-C_jtMgr7.js";import"./wiki-links-Y6CQL1QZ.js";var v=d().RailroadAbnf.parser.LangiumParser,i=n(e=>{const r=e.alternatives.map(g);return r.length===1?r[0]:{type:"choice",alternatives:r}},"transformAlternation"),g=n(e=>{const r=e.elements.map(y);return r.length===1?r[0]:{type:"sequence",elements:r}},"transformConcatenation"),b=n(e=>{if(e.includes("*")){const[t,s]=e.split("*"),l=t?parseInt(t,10):0,m=s?parseInt(s,10):1/0;return{min:l,max:m}}const r=parseInt(e,10);return{min:r,max:r}},"parseRepeat"),y=n(e=>{const r=A(e.primary);if(!e.repeat)return r;const{min:t,max:s}=b(e.repeat);return t===0&&s===1?{type:"optional",element:r}:{type:"repetition",element:r,min:t,max:s}},"transformElement"),A=n(e=>{switch(e.$type){case"AbnfStringLiteral":return{type:"terminal",value:e.value};case"AbnfNumVal":return{type:"terminal",value:e.value};case"AbnfRuleName":return{type:"nonterminal",name:e.name};case"AbnfGroup":return i(e.element);case"AbnfOptionalGroup":return{type:"optional",element:i(e.element)};default:throw new Error(`Unsupported ABNF primary node: ${e.$type}`)}},"transformPrimary"),P=n(e=>({name:e.name,definition:i(e.definition)}),"transformRule"),h=n(e=>{f(e,a),e.title&&a.setTitle(e.title),e.rules.map(r=>a.addRule(P(r)))},"populateDb"),R={parse:n(e=>{a.clear(),o.debug("[ABNF Parser] Starting Langium parse");const r=v.parse(e);if(r.lexerErrors.length>0||r.parserErrors.length>0)throw new c(r);const t=r.value;o.debug("[ABNF Parser] Parsed rules:",t.rules.length),h(t),o.debug("[ABNF Parser] Parse complete")},"parse"),parser:{yy:a}},F={parser:R,db:a,renderer:u,styles:p};export{F as diagram};
@@ -1 +0,0 @@
1
- import{J as ln,K as un,L as V,M as O,N as M,O as an,P as y,Q as tn,R as Y,T as _,V as rn,W as o,X as on,Y as sn,Z as fn}from"./mermaid-HWGCJPDP-C8QwWdo5.js";function cn(l){return l.innerRadius}function yn(l){return l.outerRadius}function gn(l){return l.startAngle}function dn(l){return l.endAngle}function mn(l){return l&&l.padAngle}function pn(l,h,E,q,v,R,N,u){var I=E-l,i=q-h,n=N-v,d=u-R,a=d*I-n*i;if(!(a*a<y))return a=(n*(h-R)-d*(l-v))/a,[l+a*I,h+a*i]}function F(l,h,E,q,v,R,N){var u=l-E,I=h-q,i=(N?R:-R)/Y(u*u+I*I),n=i*I,d=-i*u,a=l+n,s=h+d,f=E+n,c=q+d,Q=(a+f)/2,t=(s+c)/2,m=f-a,g=c-s,A=m*m+g*g,T=v-R,P=a*c-f*s,J=(g<0?-1:1)*Y(on(0,T*T*A-P*P)),K=(P*g-m*J)/A,L=(-P*m-g*J)/A,w=(P*g+m*J)/A,p=(-P*m+g*J)/A,x=K-Q,e=L-t,r=w-Q,S=p-t;return x*x+e*e>r*r+S*S&&(K=w,L=p),{cx:K,cy:L,x01:-n,y01:-d,x11:K*(v/T-1),y11:L*(v/T-1)}}function hn(){var l=cn,h=yn,E=M(0),q=null,v=gn,R=dn,N=mn,u=null,I=ln(i);function i(){var n,d,a=+l.apply(this,arguments),s=+h.apply(this,arguments),f=v.apply(this,arguments)-an,c=R.apply(this,arguments)-an,Q=rn(c-f),t=c>f;if(u||(u=n=I()),s<a&&(d=s,s=a,a=d),!(s>y))u.moveTo(0,0);else if(Q>tn-y)u.moveTo(s*V(f),s*O(f)),u.arc(0,0,s,f,c,!t),a>y&&(u.moveTo(a*V(c),a*O(c)),u.arc(0,0,a,c,f,t));else{var m=f,g=c,A=f,T=c,P=Q,J=Q,K=N.apply(this,arguments)/2,L=K>y&&(q?+q.apply(this,arguments):Y(a*a+s*s)),w=_(rn(s-a)/2,+E.apply(this,arguments)),p=w,x=w,e,r;if(L>y){var S=sn(L/a*O(K)),Z=sn(L/s*O(K));(P-=S*2)>y?(S*=t?1:-1,A+=S,T-=S):(P=0,A=T=(f+c)/2),(J-=Z*2)>y?(Z*=t?1:-1,m+=Z,g-=Z):(J=0,m=g=(f+c)/2)}var W=s*V(m),X=s*O(m),j=a*V(T),z=a*O(T);if(w>y){var B=s*V(g),C=s*O(g),G=a*V(A),H=a*O(A),D;if(Q<un)if(D=pn(W,X,G,H,B,C,j,z)){var U=W-D[0],$=X-D[1],k=B-D[0],b=C-D[1],nn=1/O(fn((U*k+$*b)/(Y(U*U+$*$)*Y(k*k+b*b)))/2),en=Y(D[0]*D[0]+D[1]*D[1]);p=_(w,(a-en)/(nn-1)),x=_(w,(s-en)/(nn+1))}else p=x=0}J>y?x>y?(e=F(G,H,W,X,s,x,t),r=F(B,C,j,z,s,x,t),u.moveTo(e.cx+e.x01,e.cy+e.y01),x<w?u.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(r.y01,r.x01),!t):(u.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(e.y11,e.x11),!t),u.arc(0,0,s,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),!t),u.arc(r.cx,r.cy,x,o(r.y11,r.x11),o(r.y01,r.x01),!t))):(u.moveTo(W,X),u.arc(0,0,s,m,g,!t)):u.moveTo(W,X),!(a>y)||!(P>y)?u.lineTo(j,z):p>y?(e=F(j,z,B,C,a,-p,t),r=F(W,X,G,H,a,-p,t),u.lineTo(e.cx+e.x01,e.cy+e.y01),p<w?u.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(r.y01,r.x01),!t):(u.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(e.y11,e.x11),!t),u.arc(0,0,a,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),t),u.arc(r.cx,r.cy,p,o(r.y11,r.x11),o(r.y01,r.x01),!t))):u.arc(0,0,a,T,A,t)}if(u.closePath(),n)return u=null,n+""||null}return i.centroid=function(){var n=(+l.apply(this,arguments)+ +h.apply(this,arguments))/2,d=(+v.apply(this,arguments)+ +R.apply(this,arguments))/2-un/2;return[V(d)*n,O(d)*n]},i.innerRadius=function(n){return arguments.length?(l=typeof n=="function"?n:M(+n),i):l},i.outerRadius=function(n){return arguments.length?(h=typeof n=="function"?n:M(+n),i):h},i.cornerRadius=function(n){return arguments.length?(E=typeof n=="function"?n:M(+n),i):E},i.padRadius=function(n){return arguments.length?(q=n==null?null:typeof n=="function"?n:M(+n),i):q},i.startAngle=function(n){return arguments.length?(v=typeof n=="function"?n:M(+n),i):v},i.endAngle=function(n){return arguments.length?(R=typeof n=="function"?n:M(+n),i):R},i.padAngle=function(n){return arguments.length?(N=typeof n=="function"?n:M(+n),i):N},i.context=function(n){return arguments.length?(u=n??null,i):u},i}export{hn as d};