braian 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (353) hide show
  1. package/README.md +31 -7
  2. package/bin/braian.mjs +337 -60
  3. package/bin/launch-target.mjs +15 -27
  4. package/bin/run-state.mjs +203 -0
  5. package/dist/app.module.js +2 -0
  6. package/dist/bootstrap.js +4 -1
  7. package/dist/http/api-controllers.js +6 -0
  8. package/dist/http/vault-http-error.js +4 -1
  9. package/dist/http/web-app-fallback.js +37 -0
  10. package/dist/logging/logging.middleware.js +3 -1
  11. package/dist/main.js +3 -0
  12. package/dist/mcp/mcp-path.js +12 -0
  13. package/dist/mcp/mcp-settings.controller.js +78 -0
  14. package/dist/mcp/mcp.controller.js +147 -0
  15. package/dist/mcp/mcp.dto.js +53 -0
  16. package/dist/mcp/mcp.module.js +20 -0
  17. package/dist/mcp/mcp.service.js +117 -0
  18. package/dist/providers/model-provider.service.js +3 -3
  19. package/dist/rss/rss-profiles.controller.js +167 -0
  20. package/dist/rss/rss-profiles.dto.js +511 -0
  21. package/dist/rss/rss-profiles.service.js +149 -0
  22. package/dist/rss/rss.module.js +5 -2
  23. package/dist/search/search.controller.js +1 -1
  24. package/dist/vaults/vault.controller.js +41 -0
  25. package/dist/vaults/vault.dto.js +80 -6
  26. package/dist/vaults/vaults.module.js +2 -1
  27. package/dist/vaults/vaults.service.js +30 -2
  28. package/dist/workspace/workspace-config.js +3 -3
  29. package/node_modules/@braian/ai-providers/dist/index.js +4 -1
  30. package/node_modules/@braian/ai-providers/dist/jev-routing.js +41 -13
  31. package/node_modules/@braian/graph-agent/dist/agent-profiles/tool-catalog.js +4 -4
  32. package/node_modules/@braian/graph-agent/dist/data-workspace.js +44 -0
  33. package/node_modules/@braian/graph-agent/dist/demo-vaults.js +348 -0
  34. package/node_modules/@braian/graph-agent/dist/feature-switch.js +1 -1
  35. package/node_modules/@braian/graph-agent/dist/graph-agent.js +40 -7
  36. package/node_modules/@braian/graph-agent/dist/index.js +24 -2
  37. package/node_modules/@braian/graph-agent/dist/mcp-tokens.js +62 -0
  38. package/node_modules/@braian/graph-agent/dist/rss/index.js +43 -1
  39. package/node_modules/@braian/graph-agent/dist/rss/rss-profile-model.js +378 -0
  40. package/node_modules/@braian/graph-agent/dist/rss/rss-profile-store.js +170 -0
  41. package/node_modules/@braian/graph-agent/dist/rss/rss-profile-test.js +120 -0
  42. package/node_modules/@braian/graph-agent/dist/rss/rss-profile-use-cases.js +74 -0
  43. package/node_modules/@braian/graph-agent/dist/vault-changes.js +3 -0
  44. package/node_modules/@braian/graph-agent/dist/vault-settings-operations.js +3 -1
  45. package/node_modules/@braian/graph-agent/dist/vault-settings-registry.js +1 -1
  46. package/node_modules/@braian/voice-transcription/dist/transcribe.js +1 -1
  47. package/package.json +3 -1
  48. package/public/assets/{agent-profiles-settings-I5Ux2GnH.js → agent-profiles-settings-yElCnMJo.js} +1 -1
  49. package/public/assets/{appearance-settings-module-CD3bJpfR.js → appearance-settings-module-BFDKE-mZ.js} +1 -1
  50. package/public/assets/{ar-SA-G6X2FPQ2-BPq1dwIU.js → ar-SA-G6X2FPQ2-R9ND2Rw0.js} +1 -1
  51. package/public/assets/{attachment-embed-BkP-B_Pa.js → attachment-embed-BX0XSPNZ.js} +1 -1
  52. package/public/assets/{attachments-settings-BeAekkzf.js → attachments-settings-CSEjOoFg.js} +1 -1
  53. package/public/assets/{az-AZ-76LH7QW2-nXEHcVXP.js → az-AZ-76LH7QW2-DpGlptKS.js} +1 -1
  54. package/public/assets/{bg-BG-XCXSNQG7-CpTkmSSX.js → bg-BG-XCXSNQG7-WKBfRf7q.js} +1 -1
  55. package/public/assets/{bn-BD-2XOGV67Q-BDMEyCuA.js → bn-BD-2XOGV67Q-BmT7jnvl.js} +1 -1
  56. package/public/assets/board-workspace-CmetKvXF.js +1 -0
  57. package/public/assets/{boards-settings-module-CCN_ZNks.js → boards-settings-module-Bh5dh9jG.js} +1 -1
  58. package/public/assets/{boards-view-B1B8wHHn.js → boards-view-3JR36W_w.js} +1 -1
  59. package/public/assets/{ca-ES-6MX7JW3Y-D0UEot-K.js → ca-ES-6MX7JW3Y-CBR9ytrG.js} +1 -1
  60. package/public/assets/{calendar-view-BlTCcAzD.js → calendar-view-Cr1VSpj0.js} +1 -1
  61. package/public/assets/calendar-workspace-B-2Himdy.js +1 -0
  62. package/public/assets/{calendars-settings-module-ActBZM9v.js → calendars-settings-module-BWI1k_YA.js} +1 -1
  63. package/public/assets/{card-fields-nzhTsBAW.js → card-fields-eo7dqj1P.js} +1 -1
  64. package/public/assets/{chat-composer-editor-CRtsZz3W.js → chat-composer-editor-DCmWVP16.js} +1 -1
  65. package/public/assets/chat-message-list-DPXjDBw1.js +1 -0
  66. package/public/assets/{chunk-EIO257PC-CGqfS2j0.js → chunk-EIO257PC-Bfdsn_q8.js} +1 -1
  67. package/public/assets/{code-editor-DnrGU9QQ.js → code-editor-CxLqzVwa.js} +1 -1
  68. package/public/assets/color-picker-DK8V_DI0.js +1 -0
  69. package/public/assets/{contents-view-C6RdJxE2.js → contents-view-DHRWEBwV.js} +1 -1
  70. package/public/assets/{conversation-debug-panel-DIjQShXO.js → conversation-debug-panel-zsrBEMxW.js} +1 -1
  71. package/public/assets/create-note-popup-C9IB_IZr.js +1 -0
  72. package/public/assets/{cs-CZ-2BRQDIVT-DvEBYfBD.js → cs-CZ-2BRQDIVT-fiabtlu1.js} +1 -1
  73. package/public/assets/{cypher-editor-Cdd9vqJj.js → cypher-editor-ef6RdDgm.js} +1 -1
  74. package/public/assets/{da-DK-5WZEPLOC-nBVf9B0e.js → da-DK-5WZEPLOC-C-5tRCvs.js} +1 -1
  75. package/public/assets/{daily-notes-settings-DG9RUcYk.js → daily-notes-settings-CCotd1Iq.js} +1 -1
  76. package/public/assets/{dashboard-grid-BvlcalWZ.js → dashboard-grid-DKMK4z_a.js} +1 -1
  77. package/public/assets/dashboard-workspace-4u-QaXby.js +4 -0
  78. package/public/assets/{dashboards-settings-module-CMkRnuLc.js → dashboards-settings-module-DmE0Krje.js} +1 -1
  79. package/public/assets/{dashboards-view-BB1CRB2G.js → dashboards-view-DxUAl6zg.js} +1 -1
  80. package/public/assets/{de-DE-XR44H4JA-wIoI5uHM.js → de-DE-XR44H4JA-4wneKMQi.js} +1 -1
  81. package/public/assets/{desktop-server-settings-j8RrUDQh.js → desktop-server-settings-DDd8PcxW.js} +1 -1
  82. package/public/assets/{directory-picker-columns-BDdL8yxc.js → directory-picker-columns-CqPZNMT8.js} +1 -1
  83. package/public/assets/{discovery-create-popup-DpDB1MTg.js → discovery-create-popup-BSOSYM4o.js} +1 -1
  84. package/public/assets/{discovery-import-popup-BsyONSTT.js → discovery-import-popup-NodFxSW1.js} +1 -1
  85. package/public/assets/{discovery-settings-module-CSz3wdqd.js → discovery-settings-module-DQMZismj.js} +1 -1
  86. package/public/assets/{discovery-view-DOb6HJff.js → discovery-view-PiwStXSa.js} +1 -1
  87. package/public/assets/discovery-workspace-BTrjBF19.js +2 -0
  88. package/public/assets/{dist-tLZONR8L.js → dist-B58c6eJE.js} +1 -1
  89. package/public/assets/drag-preview-D61OK7zr.js +1 -0
  90. package/public/assets/{drawing-note-BZkhWRBb.js → drawing-note-BytzAih9.js} +1 -1
  91. package/public/assets/{el-GR-BZB4AONW-BoxDB0UD.js → el-GR-BZB4AONW-BUDxOK9m.js} +1 -1
  92. package/public/assets/{en-B4ZKOASM-D3_h4H29.js → en-B4ZKOASM-jB7I34Md.js} +1 -1
  93. package/public/assets/{es-ES-U4NZUMDT-BTF8-J9f.js → es-ES-U4NZUMDT-gXLOOlpz.js} +1 -1
  94. package/public/assets/{esm-zhVSGSwY.js → esm-BSlSeh8A.js} +1 -1
  95. package/public/assets/{eu-ES-A7QVB2H4-PqSQa04Y.js → eu-ES-A7QVB2H4-4kiV_opo.js} +1 -1
  96. package/public/assets/{fa-IR-HGAKTJCU-B03HX6BC.js → fa-IR-HGAKTJCU-C7F0Dl4h.js} +1 -1
  97. package/public/assets/{feature-switch-section-CDTUV6B-.js → feature-switch-section-617S6UWP.js} +1 -1
  98. package/public/assets/{fi-FI-Z5N7JZ37-D5Rn9AGc.js → fi-FI-Z5N7JZ37-DEUSwc4a.js} +1 -1
  99. package/public/assets/{file-editor-DTm2a8_D.js → file-editor-DvP7rRI9.js} +3 -3
  100. package/public/assets/{file-language-C8bPT8Wh.js → file-language-DjeubQk3.js} +1 -1
  101. package/public/assets/{file-preview-Bp9k2YvK.js → file-preview-AkYowAab.js} +1 -1
  102. package/public/assets/{file-preview-media-CNZHdx05.js → file-preview-media-DL2hGeeZ.js} +1 -1
  103. package/public/assets/{file-references-api-CSyFnFFm.js → file-references-api-C2G0bSy9.js} +1 -1
  104. package/public/assets/{files-settings-module-D4HPlkbW.js → files-settings-module-DsylYhrR.js} +1 -1
  105. package/public/assets/files-view-B6_Mlm9V.css +1 -0
  106. package/public/assets/files-view-DPSrj_WW.js +3 -0
  107. package/public/assets/{folder-picker-dialog-D57Q15N4.js → folder-picker-dialog-D_VCqm_i.js} +1 -1
  108. package/public/assets/{format-panel-value-DYwL3ttM.js → format-panel-value-vueBm4DQ.js} +1 -1
  109. package/public/assets/{fr-FR-RHASNOE6-BoIuGpVa.js → fr-FR-RHASNOE6-BKLo10bn.js} +1 -1
  110. package/public/assets/{gl-ES-HMX3MZ6V-R9gfMkm_.js → gl-ES-HMX3MZ6V-D_nHnidC.js} +1 -1
  111. package/public/assets/{graph-explorer-DtYVExeD.js → graph-explorer-CHz-bFkx.js} +5 -5
  112. package/public/assets/{graph-settings-module-D--vzqKr.js → graph-settings-module-9hY9bkdT.js} +1 -1
  113. package/public/assets/{he-IL-6SHJWFNN-DLh6r8yJ.js → he-IL-6SHJWFNN-BXKK7JWx.js} +1 -1
  114. package/public/assets/{hi-IN-IWLTKZ5I-DsP1yUVR.js → hi-IN-IWLTKZ5I-D2utCBQM.js} +1 -1
  115. package/public/assets/{hu-HU-A5ZG7DT2-ttWV7_mJ.js → hu-HU-A5ZG7DT2-BENIngFF.js} +1 -1
  116. package/public/assets/{id-ID-SAP4L64H-DIFD1Rmb.js → id-ID-SAP4L64H-Bw77jJOj.js} +1 -1
  117. package/public/assets/{ide-settings-module-Dsg4tJV6.js → ide-settings-module-BbIX3okW.js} +1 -1
  118. package/public/assets/ide-view-0vK2duKI.js +2 -0
  119. package/public/assets/{image-GAAHSSAO-C38PUNrv.js → image-GAAHSSAO-D4NDL8F6.js} +1 -1
  120. package/public/assets/{imap-accounts-QVDGlYad.js → imap-accounts-BRbnITJv.js} +1 -1
  121. package/public/assets/index-BVDhmwI8.js +11 -0
  122. package/public/assets/index-DjUUY3gd.css +1 -0
  123. package/public/assets/{it-IT-JPQ66NNP-D9CIdJgS.js → it-IT-JPQ66NNP-DiG4G8vQ.js} +1 -1
  124. package/public/assets/{ja-JP-DBVTYXUO-CYn7dH3E.js → ja-JP-DBVTYXUO-CILN9NGs.js} +1 -1
  125. package/public/assets/{journal-create-popup-DnYgWgDU.js → journal-create-popup-39y9ieVG.js} +1 -1
  126. package/public/assets/{journal-day-route-DpsYGWU7.js → journal-day-route-CYlyL-u0.js} +1 -1
  127. package/public/assets/{journal-folder-field-DuvIgT6Y.js → journal-folder-field-BfO-_ied.js} +1 -1
  128. package/public/assets/{journal-page-BdQlNdyB.js → journal-page-TgyVFaPE.js} +2 -2
  129. package/public/assets/{journal-settings-Dq-9Conv.js → journal-settings-CfjXOXzF.js} +1 -1
  130. package/public/assets/{journal-typography-QR4z5v0X.js → journal-typography-D3O3AK2U.js} +1 -1
  131. package/public/assets/journal-writing-route-CYhXzipC.js +1 -0
  132. package/public/assets/journals-view-DNomC0nF.js +1 -0
  133. package/public/assets/{kaa-6HZHGXH3-DmZqyxcr.js → kaa-6HZHGXH3-BUua-YiR.js} +1 -1
  134. package/public/assets/{kab-KAB-ZGHBKWFO-BnEoO3f6.js → kab-KAB-ZGHBKWFO-yPJB-J7N.js} +1 -1
  135. package/public/assets/{kk-KZ-P5N5QNE5-DcYcuRxx.js → kk-KZ-P5N5QNE5-CAitSjw5.js} +1 -1
  136. package/public/assets/{km-KH-HSX4SM5Z-DO6DHT6h.js → km-KH-HSX4SM5Z-CSZjabru.js} +1 -1
  137. package/public/assets/{ko-KR-MTYHY66A-Ch6OwlXE.js → ko-KR-MTYHY66A-CGEXYXZz.js} +1 -1
  138. package/public/assets/{ku-TR-6OUDTVRD-C9KHFYbx.js → ku-TR-6OUDTVRD-DOfuZRKI.js} +1 -1
  139. package/public/assets/{link-file-browser-BvVwFMvC.js → link-file-browser-A_Mappx0.js} +1 -1
  140. package/public/assets/{link-kind-icon-r9mUfWOh.js → link-kind-icon-BMfHfR_C.js} +1 -1
  141. package/public/assets/{link-picker-C90irWTA.js → link-picker-BfwWXJZg.js} +2 -2
  142. package/public/assets/{locked-shares-prompt-CA0MuZ_G.js → locked-shares-prompt-BsM-ai_V.js} +1 -1
  143. package/public/assets/{logging-settings-contribution-C55dtngt.js → logging-settings-contribution-BLHCBnwO.js} +1 -1
  144. package/public/assets/logic-DtHJ5GlU.js +28 -0
  145. package/public/assets/{lt-LT-XHIRWOB4-CrK3hZ26.js → lt-LT-XHIRWOB4-CmbJTJAh.js} +1 -1
  146. package/public/assets/{lv-LV-5QDEKY6T-BOA9oRt-.js → lv-LV-5QDEKY6T-Br-VqxTs.js} +1 -1
  147. package/public/assets/{markdown-message-9f2rcF0-.js → markdown-message-BIo2pHhE.js} +2 -2
  148. package/public/assets/{markdown-task-toggle-DiIwYCgC.js → markdown-task-toggle-9k1EldDD.js} +3 -3
  149. package/public/assets/{matrices-settings-module-DPI1_WsY.js → matrices-settings-module-DKGdrCad.js} +1 -1
  150. package/public/assets/{matrices-view-CQlirOdv.js → matrices-view-DYF7e5ES.js} +1 -1
  151. package/public/assets/matrix-workspace-JZhH-HQ5.js +1 -0
  152. package/public/assets/{maximize-2-C6N1RKlt.js → maximize-2-DATMN9kx.js} +1 -1
  153. package/public/assets/{mermaid-diagram-CnzQOrTI.js → mermaid-diagram-gUL2-JyE.js} +1 -1
  154. package/public/assets/{mobile-file-text-B4j-_eP4.js → mobile-file-text-meniSeto.js} +1 -1
  155. package/public/assets/{mobile-note-content-editor-znLhIM9A.js → mobile-note-content-editor-C6TUyA4F.js} +2 -2
  156. package/public/assets/{mobile-panel-layer-C2OowtdM.js → mobile-panel-layer-2EcEm-JB.js} +1 -1
  157. package/public/assets/model-provider-settings-contribution-CfHiu3nS.js +1 -0
  158. package/public/assets/model-providers-cQOCMmwX.js +1 -0
  159. package/public/assets/{mr-IN-CRQNXWMA-GWTqYMNI.js → mr-IN-CRQNXWMA-DwF8SFQB.js} +1 -1
  160. package/public/assets/{my-MM-5M5IBNSE-DnqvLQeM.js → my-MM-5M5IBNSE-BEiMo9eJ.js} +1 -1
  161. package/public/assets/{nb-NO-T6EIAALU-DyrWt8fZ.js → nb-NO-T6EIAALU-BelWzTQs.js} +1 -1
  162. package/public/assets/{nl-NL-IS3SIHDZ-COWPkkr8.js → nl-NL-IS3SIHDZ-Ce06PPL4.js} +1 -1
  163. package/public/assets/{nn-NO-6E72VCQL-8aH2uP9Y.js → nn-NO-6E72VCQL-BbXlzJzR.js} +1 -1
  164. package/public/assets/note-collab-provider-B9DpnE58.js +1 -0
  165. package/public/assets/note-collab-transport-BHZ891IL.js +1 -0
  166. package/public/assets/{note-create-settings-module-CV4dWr8t.js → note-create-settings-module-rIZc1DjQ.js} +1 -1
  167. package/public/assets/{note-documents-DCd2HaSQ.js → note-documents-CcJDTkta.js} +2 -2
  168. package/public/assets/note-editor-container-DL3yLdYs.js +2 -0
  169. package/public/assets/{note-editor-settings-module-CbPu_40k.js → note-editor-settings-module-DI0jRyPy.js} +1 -1
  170. package/public/assets/{note-excalidraw-editor-RjnG4My9.js → note-excalidraw-editor-fDQ1JVBh.js} +11 -11
  171. package/public/assets/{note-export-api-2u0sbOpc.js → note-export-api-CwuXGV0y.js} +1 -1
  172. package/public/assets/{note-export-flow-B3wRdMj0.js → note-export-flow-DcBoI5Pp.js} +1 -1
  173. package/public/assets/{note-filter-rule-rows-BajgD2k3.js → note-filter-rule-rows-DFSWBwql.js} +1 -1
  174. package/public/assets/{note-folds-settings-module-DZju6Mum.js → note-folds-settings-module-CFfVg1Cp.js} +1 -1
  175. package/public/assets/{note-frontmatter-summary-BSKg__aS.js → note-frontmatter-summary-iubFPHA_.js} +1 -1
  176. package/public/assets/{note-link-list-DKU2PqtO.js → note-link-list-CI9-GM_3.js} +1 -1
  177. package/public/assets/{note-markdown-editor-CXelEHqr.js → note-markdown-editor-lG6gZT9i.js} +10 -10
  178. package/public/assets/{note-outline-CNoqBtUP.js → note-outline-BFidIp-8.js} +1 -1
  179. package/public/assets/note-page-content-8gzPBWMV.js +2 -0
  180. package/public/assets/{note-page-editor-rhBoxKYB.js → note-page-editor-DpVUxkCx.js} +4 -4
  181. package/public/assets/{note-path-breadcrumb-uTSXCQK4.js → note-path-breadcrumb-HmtWyYZP.js} +1 -1
  182. package/public/assets/{note-picker-BD8rmAOq.js → note-picker-B5i41l1u.js} +1 -1
  183. package/public/assets/{note-picker-popover-DI9Wc706.js → note-picker-popover-B9VTeHiM.js} +1 -1
  184. package/public/assets/{note-shares-popup-9sJOmL1-.js → note-shares-popup-aUO1SNLN.js} +1 -1
  185. package/public/assets/{note-source-editor-DWyDYMCj.js → note-source-editor-BXPR_-41.js} +1 -1
  186. package/public/assets/{note-type-grid-BFX3oTAC.js → note-type-grid-CRCfpYZy.js} +2 -2
  187. package/public/assets/{note-values-BqD4746M.js → note-values-6D6wWXPg.js} +1 -1
  188. package/public/assets/{notes-settings-module-C5IPmwKt.js → notes-settings-module-DcP9Hid-.js} +1 -1
  189. package/public/assets/{oc-FR-POXYY2M6-C_R_VP74.js → oc-FR-POXYY2M6-CyRgkETq.js} +1 -1
  190. package/public/assets/{open-journal-writing-Bd-CppeX.js → open-journal-writing-Bub8Zn13.js} +1 -1
  191. package/public/assets/{pa-IN-N4M65BXN-B21EEaul.js → pa-IN-N4M65BXN-A1_Q9748.js} +1 -1
  192. package/public/assets/page-content-B3fNjwr-.js +1 -0
  193. package/public/assets/{page-files-BMj9IzfB.js → page-files-CSqFupDZ.js} +1 -1
  194. package/public/assets/page-note-nmiinGCs.js +1 -0
  195. package/public/assets/{pane-keys-CTLoUZZR.js → pane-keys-osajBGnu.js} +1 -1
  196. package/public/assets/{panel-columns-fields-DPjV39xn.js → panel-columns-fields-ZlW6A4My.js} +1 -1
  197. package/public/assets/{pdf-view-Cm78nuSA.js → pdf-view-BATpBLO5.js} +1 -1
  198. package/public/assets/{pencil-DQ9fAqT6.js → pencil-xxFNyZzr.js} +1 -1
  199. package/public/assets/{percentages-BXMCSKIN-CUt8fyAS.js → percentages-BXMCSKIN-DzsiA6IB.js} +1 -1
  200. package/public/assets/{phone-numbers-CHQaYRah.js → phone-numbers-BQgyhfcH.js} +1 -1
  201. package/public/assets/{pl-PL-T2D74RX3-Bdo_j9QK.js → pl-PL-T2D74RX3-DaINIVjz.js} +1 -1
  202. package/public/assets/provider-configuration-CSnNV6ps.css +1 -0
  203. package/public/assets/provider-configuration-DaFovElx.js +8 -0
  204. package/public/assets/provider-use-select-D-lJiZ2W.js +1 -0
  205. package/public/assets/{pt-BR-5N22H2LF-C9DRQ7CW.js → pt-BR-5N22H2LF-ENVHjTz_.js} +1 -1
  206. package/public/assets/{pt-PT-UZXXM6DQ-ColydZPV.js → pt-PT-UZXXM6DQ-D5Uqv0Vz.js} +1 -1
  207. package/public/assets/{qr-code-Bm7I0KYt.js → qr-code-CDBCi1Cu.js} +2 -2
  208. package/public/assets/{qr-code-svg-D0RAuUIk.js → qr-code-svg-8ENstC8b.js} +1 -1
  209. package/public/assets/qr-defaults-settings-C_8ybA4R.js +1 -0
  210. package/public/assets/qr-settings-fields-C2-DGF6a.js +1 -0
  211. package/public/assets/qr-viewer-DAOzDI8d.js +1 -0
  212. package/public/assets/{reader-clock-22DkpiWR.js → reader-clock-7x7Yvzv1.js} +1 -1
  213. package/public/assets/{recording-bar-DOm-SEGc.js → recording-bar-BcuvYwhh.js} +2 -2
  214. package/public/assets/{recording-setup-CV3LE2_1.js → recording-setup-D_MgrYb7.js} +1 -1
  215. package/public/assets/{recordings-api-C-Bxpzgo.js → recordings-api-Ds77lFsk.js} +1 -1
  216. package/public/assets/resource-overview-card-BainFWKz.js +1 -0
  217. package/public/assets/{ro-RO-JPDTUUEW-iJAQDPe9.js → ro-RO-JPDTUUEW-Dq_ouOp1.js} +1 -1
  218. package/public/assets/{rss-preferences-Bx1Wa4ri.js → rss-preferences-BafuZ3Ku.js} +1 -1
  219. package/public/assets/{rss-settings-module-BmDISWDk.js → rss-settings-module-Df-YS9tr.js} +1 -1
  220. package/public/assets/rss-view-BORHnuIQ.js +3 -0
  221. package/public/assets/rss-view-DIPQBTLT.css +1 -0
  222. package/public/assets/{ru-RU-B4JR7IUQ-CX_CWbT7.js → ru-RU-B4JR7IUQ-CqqISqJC.js} +1 -1
  223. package/public/assets/{safe-block-copy-DygjvDD4.js → safe-block-copy-BOVhmncw.js} +1 -1
  224. package/public/assets/{safe-block-qr-button-Cn9WpEkl.js → safe-block-qr-button-CD7cJG3N.js} +1 -1
  225. package/public/assets/{safe-block-reader-CNfzTExh.js → safe-block-reader-BkilW4Hj.js} +1 -1
  226. package/public/assets/safe-folder-conversion-DWTRwvTH.js +1 -0
  227. package/public/assets/{safe-folders-DCf8IdrM.js → safe-folders-DmvM6dtV.js} +1 -1
  228. package/public/assets/{safe-move-leaving-tN-IMhDo.js → safe-move-leaving-BT5e1h3p.js} +1 -1
  229. package/public/assets/{safe-note-locked-B_lt0XcX.js → safe-note-locked-BDCeVwpK.js} +1 -1
  230. package/public/assets/{safe-notes-settings-module-CMvkyfNG.js → safe-notes-settings-module-BrZreYgf.js} +1 -1
  231. package/public/assets/search-settings-module-CPnculiI.js +1 -0
  232. package/public/assets/{secret-form-DSD348Om.js → secret-form-B-YAlbZf.js} +1 -1
  233. package/public/assets/{secret-popup-y9W7WIrZ.js → secret-popup-CoVpeLZV.js} +1 -1
  234. package/public/assets/{security-settings-contribution-B_Syg5ab.js → security-settings-contribution-BmcZq1hf.js} +1 -1
  235. package/public/assets/settings-CU8YR8di.js +1 -0
  236. package/public/assets/{settings-edit-dialog-B5emNjJi.js → settings-edit-dialog-C_AeTz9Y.js} +1 -1
  237. package/public/assets/settings-panel-Ds7lOtnD.js +1 -0
  238. package/public/assets/settings-view-BTz2XbnW.js +4 -0
  239. package/public/assets/{settings-view-6_hMxTXD.css → settings-view-Bd65kLGK.css} +1 -1
  240. package/public/assets/{setup-prompt-6JRbE0oa.js → setup-prompt-BbpHVdla.js} +1 -1
  241. package/public/assets/{share-access-control-C5mpELVT.js → share-access-control-CzAVEv6b.js} +1 -1
  242. package/public/assets/share-label-CbjQ9iMF.js +1 -0
  243. package/public/assets/{shared-board-lanes-UWl9klys.js → shared-board-lanes-CAbJAFk6.js} +1 -1
  244. package/public/assets/{shared-calendar-view-DcCO3mNo.js → shared-calendar-view-DTzDjSs0.js} +1 -1
  245. package/public/assets/shared-note-route-B_gfX0Nl.js +4 -0
  246. package/public/assets/{shared-note-text-BdCw7a9a.js → shared-note-text-DFBEyL8Z.js} +1 -1
  247. package/public/assets/{shares-settings-module-9oF4v70A.js → shares-settings-module-pIdBLmCq.js} +1 -1
  248. package/public/assets/{si-LK-N5RQ5JYF-DfLSaLm6.js → si-LK-N5RQ5JYF-DmhE8IT5.js} +1 -1
  249. package/public/assets/{sk-SK-C5VTKIMK-DrAaUVFC.js → sk-SK-C5VTKIMK-YiOZ-xKA.js} +1 -1
  250. package/public/assets/{sl-SI-NN7IZMDC-WxYLW2Uj.js → sl-SI-NN7IZMDC-BKb37Hlu.js} +1 -1
  251. package/public/assets/{spaces-settings-module-Dh_QfANj.js → spaces-settings-module-BLU1RsTS.js} +1 -1
  252. package/public/assets/spaces-view-BhWD3mAw.js +2 -0
  253. package/public/assets/{sqlite-browser-BfIrq_0x.js → sqlite-browser-C98PFoRG.js} +2 -2
  254. package/public/assets/{store-attachments-DNyH0asy.js → store-attachments-DbqF7LgE.js} +1 -1
  255. package/public/assets/{stored-color-picker-CYL7LYdQ.js → stored-color-picker-DLX-e5Nq.js} +1 -1
  256. package/public/assets/subset-shared.chunk-D8M638AI.js +1 -0
  257. package/public/assets/{subset-worker.chunk-BrbK91mW.js → subset-worker.chunk-B9ZhBm-P.js} +1 -1
  258. package/public/assets/{sv-SE-XGPEYMSR-DOB2jm3x.js → sv-SE-XGPEYMSR-VT0snW-T.js} +1 -1
  259. package/public/assets/{ta-IN-2NMHFXQM-DfC3wGVU.js → ta-IN-2NMHFXQM--MqIf2Jf.js} +1 -1
  260. package/public/assets/{text-diff-BzNG8nfy.js → text-diff-BmKfp7mY.js} +1 -1
  261. package/public/assets/{th-TH-HPSO5L25-BsqplWuv.js → th-TH-HPSO5L25-CTKAmQrO.js} +1 -1
  262. package/public/assets/{theme-colors-2LJ6VIeK.js → theme-colors-zbTaiYL0.js} +1 -1
  263. package/public/assets/{toolbar-items-DF7H0MSb.js → toolbar-items-DLi0bl0c.js} +1 -1
  264. package/public/assets/{topology-code-editor-B7zxDyT3.js → topology-code-editor-CNnSyUQ3.js} +1 -1
  265. package/public/assets/topology-designer-T54LYLYv.js +1 -0
  266. package/public/assets/topology-editor-aGtCktzA.js +8 -0
  267. package/public/assets/{topology-folder-migration-popup-Bj4nu8HE.js → topology-folder-migration-popup-C0Wc3ViK.js} +1 -1
  268. package/public/assets/{topology-settings-module-cWWujj9j.js → topology-settings-module-Dp-Sm37Z.js} +1 -1
  269. package/public/assets/{tr-TR-DEFEU3FU-DWO1lNTH.js → tr-TR-DEFEU3FU-BVLSiyVW.js} +1 -1
  270. package/public/assets/{transcription-settings-HrJHl14H.js → transcription-settings-BldPwHO7.js} +4 -4
  271. package/public/assets/{uk-UA-QMV73CPH-ZHBKj9kv.js → uk-UA-QMV73CPH-DQ4YsZml.js} +1 -1
  272. package/public/assets/{unlock-prompt-C1AEyIR_.js → unlock-prompt-CkkcVo9g.js} +1 -1
  273. package/public/assets/{use-candidate-notes-Du1V_uun.js → use-candidate-notes-jH4-EW29.js} +1 -1
  274. package/public/assets/{use-directory-listing-BaYgcuHI.js → use-directory-listing-Cn9t21ra.js} +1 -1
  275. package/public/assets/{use-folding-enabled-CyYip5Go.js → use-folding-enabled-DKvri2UA.js} +1 -1
  276. package/public/assets/{use-live-document-Ck_XPFVd.js → use-live-document-D4PkZrbU.js} +1 -1
  277. package/public/assets/{use-mobile-layer-navigation-CBRepW9w.js → use-mobile-layer-navigation-BIC7HlT_.js} +1 -1
  278. package/public/assets/{use-note-attachments-SPgAe-M0.js → use-note-attachments-Bew073Hl.js} +1 -1
  279. package/public/assets/{use-note-delete-Dvrzq6Pl.js → use-note-delete-fFNH1Glk.js} +1 -1
  280. package/public/assets/use-note-editor-session-R1wm0xDf.js +1 -0
  281. package/public/assets/{use-note-export-flow-0uAfXAwf.js → use-note-export-flow-Dm7yhW5s.js} +2 -2
  282. package/public/assets/use-provider-dialogs-CrxN9JCo.js +1 -0
  283. package/public/assets/{use-reflection-request-DV5-_c14.js → use-reflection-request-C1DxtaYX.js} +3 -3
  284. package/public/assets/{use-safe-folder-moves-0nw2jjTX.js → use-safe-folder-moves-DjQUnMvz.js} +1 -1
  285. package/public/assets/{use-safe-folders-apply-C9pni8YW.js → use-safe-folders-apply-B1V8l7WU.js} +1 -1
  286. package/public/assets/{use-screen-source-BllYITR6.js → use-screen-source-CF-48NnC.js} +1 -1
  287. package/public/assets/use-share-actions-kb7uFat_.js +1 -0
  288. package/public/assets/{use-vault-file-link-C0ZO_VPm.js → use-vault-file-link-B-ZRcKDu.js} +1 -1
  289. package/public/assets/{use-voice-questions-Bjgb45Dc.js → use-voice-questions-DGVQlAST.js} +1 -1
  290. package/public/assets/{vault-entries-api-DVVjgeZh.js → vault-entries-api-pFsJiGnJ.js} +1 -1
  291. package/public/assets/vault-manager-YKz_Ib18.js +1 -0
  292. package/public/assets/{vault-settings-module-DMjLQmKz.js → vault-settings-module-CCMMSy4B.js} +1 -1
  293. package/public/assets/{vault-shares-popup-CCPGkRmF.js → vault-shares-popup-CaGnEIJA.js} +1 -1
  294. package/public/assets/{versioning-preferences-dvxhrMo9.js → versioning-preferences-DrNq-y_0.js} +1 -1
  295. package/public/assets/{versioning-settings-module-CnDDngKG.js → versioning-settings-module-Ddug486c.js} +1 -1
  296. package/public/assets/versioning-view-PR4R4gks.js +2 -0
  297. package/public/assets/{vi-VN-M7AON7JQ-uUfHJEho.js → vi-VN-M7AON7JQ-B-fHV7o8.js} +1 -1
  298. package/public/assets/video-recording-dialog-CxRs1eLE.js +1 -0
  299. package/public/assets/{video-recording-settings-D6YT_FW3.js → video-recording-settings-B2iE6IdW.js} +1 -1
  300. package/public/assets/{widget-frame-CjlAZSUy.js → widget-frame-DiF4946k.js} +1 -1
  301. package/public/assets/{zh-CN-LNUGB5OW-COz3oRg3.js → zh-CN-LNUGB5OW-CUgxiiUV.js} +1 -1
  302. package/public/assets/{zh-HK-E62DVLB3-C8ICkLhf.js → zh-HK-E62DVLB3-D-87W8QH.js} +1 -1
  303. package/public/assets/{zh-TW-RAJ6MFWO-AYdVqmV8.js → zh-TW-RAJ6MFWO-BVaf47B6.js} +1 -1
  304. package/public/index.html +3 -3
  305. package/public/assets/board-workspace-DPSlmJ8w.js +0 -1
  306. package/public/assets/calendar-workspace-6t1kuFgj.js +0 -1
  307. package/public/assets/chat-message-list-ClUR56GV.js +0 -1
  308. package/public/assets/color-picker-ClAn42eA.js +0 -1
  309. package/public/assets/create-note-popup-CRi210cC.js +0 -1
  310. package/public/assets/dashboard-workspace-D45MA_Wf.js +0 -4
  311. package/public/assets/discovery-workspace-Cyc70gQ1.js +0 -2
  312. package/public/assets/drag-preview-Cb6aidku.js +0 -1
  313. package/public/assets/files-view-BIDZtZgg.js +0 -3
  314. package/public/assets/files-view-Bo1uBB_W.css +0 -1
  315. package/public/assets/ide-view-DCvwb5Bx.js +0 -2
  316. package/public/assets/index-B8xguO4f.css +0 -1
  317. package/public/assets/index-CCUyKE6q.js +0 -11
  318. package/public/assets/journal-writing-route-JP-jPBGZ.js +0 -1
  319. package/public/assets/journals-view-No5xQN8-.js +0 -1
  320. package/public/assets/logic-BNk_20eJ.js +0 -28
  321. package/public/assets/matrix-workspace-C3LhTNPX.js +0 -1
  322. package/public/assets/model-provider-settings-contribution-DYmNbsgA.js +0 -1
  323. package/public/assets/model-providers-7VKk3K9H.js +0 -8
  324. package/public/assets/model-providers-DgRkVmP5.css +0 -1
  325. package/public/assets/note-collab-provider-969Kgyu8.js +0 -1
  326. package/public/assets/note-collab-transport-CQDYt_Db.js +0 -1
  327. package/public/assets/note-editor-container-CTnEE-98.js +0 -2
  328. package/public/assets/note-page-content-DIqkiMvt.js +0 -2
  329. package/public/assets/page-content-C1jtzs7H.js +0 -1
  330. package/public/assets/page-note-Chw2UF0u.js +0 -1
  331. package/public/assets/provider-use-select-DCSwSrlz.js +0 -1
  332. package/public/assets/qr-defaults-settings-2_Yt9x4N.js +0 -1
  333. package/public/assets/qr-settings-fields-DDO4XgMl.js +0 -1
  334. package/public/assets/qr-viewer-CvEfRC2r.js +0 -1
  335. package/public/assets/resource-overview-card-Co8aU6jw.js +0 -1
  336. package/public/assets/rss-view-5aqCVOCs.css +0 -1
  337. package/public/assets/rss-view-BCEFsYtS.js +0 -1
  338. package/public/assets/safe-folder-conversion-BOLpnv8P.js +0 -1
  339. package/public/assets/search-settings-module-DmczYjcQ.js +0 -1
  340. package/public/assets/settings-ChT117Ke.js +0 -1
  341. package/public/assets/settings-panel-Cl5kUs9O.js +0 -1
  342. package/public/assets/settings-view-C_lfjngd.js +0 -3
  343. package/public/assets/share-label-BU3So3s7.js +0 -1
  344. package/public/assets/shared-note-route-DaI6hm83.js +0 -4
  345. package/public/assets/spaces-view-Dw2uxDxU.js +0 -2
  346. package/public/assets/subset-shared.chunk-D1nlqSEH.js +0 -1
  347. package/public/assets/topology-designer-CvJN6QTV.js +0 -1
  348. package/public/assets/topology-editor-RZ0_yLuO.js +0 -8
  349. package/public/assets/use-note-editor-session-CRC-natg.js +0 -1
  350. package/public/assets/use-share-actions-ujEMhCfl.js +0 -1
  351. package/public/assets/vault-manager-CMQaGDss.js +0 -1
  352. package/public/assets/versioning-view-BsIFugt4.js +0 -2
  353. package/public/assets/video-recording-dialog-7IGrQMwx.js +0 -1
package/README.md CHANGED
@@ -12,17 +12,41 @@ Where the data lives — settings, the login, AI provider secrets and the vault
12
12
 
13
13
  | Command | Data folder |
14
14
  | --- | --- |
15
- | `npx braian` | `.brian` in the current folder |
16
- | `npx braian <folder>` | `<folder>/.brian` |
17
- | `npx braian -g` | `~/.brian`, shared with the desktop app |
15
+ | `npx braian` | `~/.braianrc` |
16
+ | `npx braian <folder>` | `<folder>/.braianrc` |
17
+ | `npx braian -g` | `~/.braianrc`, shared with the desktop app |
18
18
 
19
- A local data folder gets a `.gitignore` that keeps its secrets and per-install state out of Git. Started inside a folder that is a vault itself (it has `.brian/vault.yaml` or `.brian/topology`), BrAIan opens that vault alone, with the settings, login and AI providers of `~/.brian`, so the vault's own `.brian` never holds them; it says so in a warning when it starts.
19
+ Pass `.` to open the current folder immediately as a vault, or pass another folder to open that one. The folder is registered in its own `.braianrc` vault list, so *Change vault* still leads to the vault manager, where you can add more vaults; a new one is created in `.braianrc/vaults`. This also works for a folder that has never been a vault: BrAIan creates its `.brian` metadata on boot. A folder with nothing in it (dot-entries such as `.git` aside) first gets the Welcome demo vault, a few linked notes downloaded from BrAIan's demo list; pass `--no-demo` to start it empty instead. Application settings and secrets live separately in `.braianrc`, whose `.gitignore` excludes install state from Git. With no folder argument, the app opens the vault manager using home settings.
20
20
 
21
21
  | Option | Default | |
22
22
  | --- | --- | --- |
23
- | `-g`, `--global` | | Keep the data in `~/.brian` |
23
+ | `-g`, `--global` | | Keep the data in `~/.braianrc` |
24
24
  | `--port <n>` | `$PORT` or `8484` | Port to listen on |
25
- | `--data <dir>` | `$BRAIAN_DATA_PATH` | Data folder; wins over a folder and `-g` |
25
+ | `--data <dir>` | `$BRAIAN_DATA_PATH` | Override the settings location; a folder argument still opens that vault |
26
26
  | `--no-open` | | Do not open the browser |
27
+ | `--no-demo` | | Start an empty folder empty instead of with the Welcome demo |
27
28
 
28
- Without a password the app answers only this computer. Set one in Settings, or start it with `BRAIAN_PASSWORD`, before exposing it to a network. Vault versioning needs `git` and recordings need `ffmpeg` on the `PATH`.
29
+ ### In the background
30
+
31
+ Commands as pm2 has them; the command and the folder go in either order, and options anywhere.
32
+
33
+ ```sh
34
+ npx braian start . # the current folder's BrAIan, in the background (also: npx braian . -d)
35
+ npx braian status # every BrAIan running on this computer (also: ls, list)
36
+ npx braian status . # just this folder's: pid, status, uptime, memory, url
37
+ npx braian logs . # the last 15 lines, then follow (--lines <n>, --nostream)
38
+ npx braian restart . # stop and start again, on the same port
39
+ npx braian stop . # or by its name from the table: npx braian stop notes
40
+ npx braian stop all
41
+ ```
42
+
43
+ | Command | |
44
+ | --- | --- |
45
+ | *(none)* | Run in this terminal until Ctrl+C |
46
+ | `start`, `-d`, `--detach` | Run in the background and return once the app answers |
47
+ | `stop` | Stop the BrAIan running for this data folder; `stop <name>` or `stop all` |
48
+ | `restart` | Stop it if it runs, then start it in the background on the port it had; `restart <name>` or `restart all` |
49
+ | `status`, `ls`, `list` | With no folder, every run on this computer; with one, that folder's. Exit 0 if it runs, 3 if not |
50
+ | `logs` | Print the end of the background log and follow it; `--lines <n>` (15), `--nostream`; `logs <name>` |
51
+
52
+ A background run belongs to its data folder, the same one the start chose: `npx braian start` runs the home one (`~/.braianrc`), `npx braian start .` the current folder's (`./.braianrc`), and the other commands find it with the same folder, `-g` or `--data`, or by the name `status` shows: its vault's ID, or `home`. Its PID and URL are in `<data>/braian.pid` and its output in `<data>/logs/braian.log`; `~/.braianrc/runs.json` lists the data folders with a run, which is how `status` with no folder finds them all. Each data folder runs one BrAIan at a time, in the background or not. Another folder runs beside it on the next free port after 8484 unless `--port` names one; a named port that is taken is an error. `stop` sends SIGTERM, so the app closes its databases and finishes a feed sweep first, and kills it only if it is still running 15 seconds later. A folder named like a command is written `./stop`.
package/bin/braian.mjs CHANGED
@@ -1,48 +1,72 @@
1
1
  #!/usr/bin/env node
2
- // `npx braian`: the API and the web app it serves, in this one process. The data folder is `.brian` in the
3
- // current folder (or the one given), `~/.brian` with -g; a folder that is a vault itself is served alone with
4
- // the settings of `~/.brian` (launch-target.mjs).
5
- import { spawn } from 'node:child_process';
6
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
+ // Starts the API and built web app using home settings, or opens the folder argument as a vault.
3
+ // pm2-style commands run it in the background and find that run again by the same data folder.
4
+ import { spawn, spawnSync } from 'node:child_process';
5
+ import { closeSync, existsSync, mkdirSync, openSync, readSync, statSync, readFileSync, unwatchFile, watchFile, writeFileSync, writeSync } from 'node:fs';
7
6
  import { homedir } from 'node:os';
8
- import { dirname, join, relative, resolve } from 'node:path';
7
+ import { basename, dirname, join, relative, resolve } from 'node:path';
9
8
  import { fileURLToPath } from 'node:url';
10
9
  import { parseArgs } from 'node:util';
11
- import { LOCAL_GITIGNORE, resolveLaunchTarget } from './launch-target.mjs';
10
+ import { freeVaultId, LOCAL_GITIGNORE, resolveLaunchTarget } from './launch-target.mjs';
11
+ import { addToRunIndex, answersHealth, clearRunState, firstFreePort, formatTable, formatUptime, inspectRun, lastLines, listRuns, memoryOf, parseCommand, portIsFree, removeFromRunIndex, runIndexPath, runNameOf, runStatePaths, stopProcess } from './run-state.mjs';
12
12
 
13
13
  const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
14
14
  const { version } = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'));
15
15
 
16
16
  const usage = `braian ${version}
17
17
 
18
- Usage: npx braian [folder] [options]
18
+ Usage: npx braian [command] [folder] [options]
19
19
 
20
- folder where to keep the data: <folder>/.brian (default: the current folder).
21
- A folder that is a vault itself (it has .brian/vault.yaml or .brian/topology) is
22
- opened alone, with the settings, login and AI providers of ~/.brian.
23
- -g, --global keep the data in ~/.brian, shared with the desktop app
24
- --port <n> port to listen on (default: $PORT or 8484)
25
- --data <dir> data folder: settings, secrets and the vault list; wins over folder and -g
20
+ Commands, as pm2 has them (the command and the folder go in either order):
21
+ (none) run in this terminal until Ctrl+C
22
+ start run in the background and return once it answers (also: -d, --detach)
23
+ stop stop the BrAIan running for this data folder
24
+ restart stop it if it runs, then start it in the background on the same port
25
+ status, ls, list with no folder: every BrAIan running on this computer; with one: that folder's
26
+ (exit 0 if it runs, 3 if not)
27
+ logs print the end of a background run's log and follow it (Ctrl+C to leave)
28
+
29
+ folder open this folder as a vault, with app settings and any vault you add in
30
+ <folder>/.braianrc; an empty folder first gets the Welcome demo vault
31
+ (default with no folder: ~/.braianrc, shared with the desktop app).
32
+ A folder named like a command is written ./stop. stop, restart, status and logs
33
+ also take a run's name from the status table instead, and stop and restart take all.
34
+ -g, --global use ~/.braianrc (the default; cannot be combined with a folder)
35
+ --port <n> port to listen on (default: $PORT, else 8484 or the next free one after it;
36
+ restart keeps the running one's)
37
+ --data <dir> data folder: settings, secrets and the vault list; overrides the settings location
26
38
  (default: $BRAIAN_DATA_PATH)
27
39
  --no-open do not open the browser
40
+ --no-demo leave an empty folder empty instead of installing the Welcome demo
41
+ --lines <n> logs: how many lines to print first (default 15)
42
+ --nostream logs: print them and return instead of following
28
43
  -v, --version print the version
29
44
  -h, --help print this help
30
45
 
46
+ A background run belongs to its data folder: \`npx braian start .\` runs the current folder's,
47
+ \`npx braian start\` the home one, and stop, restart, status and logs with the same folder, -g or
48
+ --data find it, or its name does: \`npx braian stop notes\`. Its record is <data>/braian.pid, its
49
+ output <data>/logs/braian.log, and ~/.braianrc/runs.json lists every data folder with a run.
50
+
31
51
  Every other setting is the API's own environment variable (BRAIAN_PASSWORD, BRAIAN_VAULT, …).`;
32
52
 
33
- // `--no-open` by hand: parseArgs' allowNegative needs Node 22.4.
53
+ // `--no-open` and `--no-demo` by hand: parseArgs' allowNegative needs Node 22.4.
34
54
  const argv = process.argv.slice(2);
35
55
  const open = !argv.includes('--no-open');
56
+ const demo = !argv.includes('--no-demo');
36
57
  let options;
37
58
  let positionals;
38
59
  try {
39
60
  ({ values: options, positionals } = parseArgs({
40
- args: argv.filter((arg) => arg !== '--no-open'),
61
+ args: argv.filter((arg) => arg !== '--no-open' && arg !== '--no-demo'),
41
62
  allowPositionals: true,
42
63
  options: {
43
64
  global: { type: 'boolean', short: 'g' },
44
65
  port: { type: 'string' },
45
66
  data: { type: 'string' },
67
+ detach: { type: 'boolean', short: 'd' },
68
+ lines: { type: 'string' },
69
+ nostream: { type: 'boolean' },
46
70
  version: { type: 'boolean', short: 'v' },
47
71
  help: { type: 'boolean', short: 'h' }
48
72
  }
@@ -53,77 +77,330 @@ try {
53
77
  }
54
78
  if (options.help) { console.log(usage); process.exit(0); }
55
79
  if (options.version) { console.log(version); process.exit(0); }
56
- if (positionals.length > 1) { console.error(`One folder at most, not ${positionals.length}.\n\n${usage}`); process.exit(2); }
57
80
 
58
- const port = Number(options.port ?? process.env.PORT ?? 8484);
59
- if (!Number.isInteger(port) || port <= 0 || port > 65535) { console.error(`Not a port: ${options.port ?? process.env.PORT}`); process.exit(2); }
81
+ const requestedPort = options.port ?? process.env.PORT;
82
+ let port = Number(requestedPort ?? 8484);
83
+ if (!Number.isInteger(port) || port <= 0 || port > 65535) { console.error(`Not a port: ${requestedPort}`); process.exit(2); }
84
+ const lines = Number(options.lines ?? 15);
85
+ if (!Number.isInteger(lines) || lines < 0) { console.error(`Not a line count: ${options.lines}`); process.exit(2); }
86
+ const indexFile = runIndexPath(homedir());
87
+ /** start, stop and restart print the table when done; `stop all` and `restart all` print it once at the end. */
88
+ const quietTable = process.env.BRAIAN_QUIET_TABLE === '1';
89
+ delete process.env.BRAIAN_QUIET_TABLE;
60
90
  let target;
91
+ let action;
92
+ let folder;
61
93
  try {
62
- target = resolveLaunchTarget({ folder: positionals[0], global: options.global, data: options.data, cwd: process.cwd(), home: homedir(), env: process.env, exists: existsSync });
94
+ ({ action, folder } = parseCommand(positionals, { detach: options.detach }));
95
+ const named = action === 'stop' || action === 'restart' || action === 'status' || action === 'logs';
96
+ if (named && folder !== undefined && !isDirectory(resolve(folder))) {
97
+ // pm2's names: a run from the table by its name, or every run with `all`.
98
+ const runs = await listRuns(indexFile);
99
+ if (folder === 'all' && action !== 'logs') process.exit(action === 'status' ? await listAll(runs) : await forEachRun(runs));
100
+ const matches = runs.filter((entry) => runNameOf(entry.run, homedir()) === folder);
101
+ if (matches.length > 1) throw new Error(`${matches.length} runs are named ${folder} (${matches.map((entry) => entry.run.vaultPath ?? entry.dataPath).join(', ')}); name its folder instead.`);
102
+ if (matches.length === 0) throw new Error(`No folder and no running BrAIan named ${folder}. \`npx braian status\` lists what runs.`);
103
+ ({ folder, global: options.global, data: options.data } = argumentsFor(matches[0].run));
104
+ }
105
+ // pm2 ls: with no folder, -g or --data, status lists every run on this computer.
106
+ if (action === 'status' && folder === undefined && !options.global && !options.data && !process.env.BRAIAN_DATA_PATH) process.exit(await listAll(await listRuns(indexFile)));
107
+ target = resolveLaunchTarget({ folder, global: options.global, data: options.data, cwd: process.cwd(), home: homedir(), env: process.env, exists: isDirectory });
63
108
  } catch (error) {
64
109
  console.error(`${error.message}\n\n${usage}`);
65
110
  process.exit(2);
66
111
  }
112
+ function isDirectory(path) {
113
+ try { return statSync(path).isDirectory(); } catch { return false; }
114
+ }
115
+ /** The folder, -g and --data that resolve to a recorded run's data folder again. */
116
+ function argumentsFor(run) {
117
+ if (run.vaultPath) return { folder: run.vaultPath, global: false, data: run.dataPath === join(run.vaultPath, '.braianrc') ? undefined : run.dataPath };
118
+ if (run.dataPath === join(homedir(), '.braianrc')) return { folder: undefined, global: true, data: undefined };
119
+ return { folder: undefined, global: false, data: run.dataPath };
120
+ }
121
+ /** `stop all` and `restart all`: this launcher once per run, then the table once. */
122
+ async function forEachRun(runs) {
123
+ let failed = 0;
124
+ for (const { run } of runs) {
125
+ const { folder: each, global, data } = argumentsFor(run);
126
+ const args = [fileURLToPath(import.meta.url), action, ...(each ? [each] : []), ...(global ? ['-g'] : []), ...(data ? ['--data', data] : []), ...(open ? [] : ['--no-open'])];
127
+ const result = spawnSync(process.execPath, args, { stdio: 'inherit', env: { ...process.env, BRAIAN_QUIET_TABLE: '1' } });
128
+ if (result.status !== 0) failed += 1;
129
+ }
130
+ if (runs.length === 0) console.log('[braian] No BrAIan is running on this computer.');
131
+ else await listAll(await listRuns(indexFile));
132
+ return failed ? 1 : 0;
133
+ }
134
+ /** pm2 ls: one row per run on this computer, with its folder. */
135
+ async function listAll(runs) {
136
+ if (runs.length === 0) {
137
+ console.log('[braian] No BrAIan is running on this computer.\nStart one with: npx braian start [folder]');
138
+ return 3;
139
+ }
140
+ const where = (path) => { const near = relative(process.cwd(), path); return near === '' ? '.' : !near.startsWith('..') ? `./${near}` : (path === homedir() || path.startsWith(`${homedir()}/`) ? `~${path.slice(homedir().length)}` : path); };
141
+ const rows = runs.map(({ dataPath, state, run }) => [
142
+ runNameOf(run, homedir()),
143
+ run.pid,
144
+ run.background === false ? 'terminal' : 'background',
145
+ state === 'running' ? 'online' : 'not answering',
146
+ formatUptime(Date.now() - Date.parse(run.startedAt)),
147
+ memoryOf(run.pid),
148
+ run.url,
149
+ where(run.vaultPath ?? dataPath)
150
+ ]);
151
+ console.log(formatTable(['name', 'pid', 'mode', 'status', 'uptime', 'mem', 'url', 'folder'], rows));
152
+ console.log('Stop one with: npx braian stop <name>, or all of them with: npx braian stop all');
153
+ return runs.some(({ state }) => state === 'running') ? 0 : 3;
154
+ }
155
+
67
156
  const { dataPath } = target;
157
+ let url = `http://localhost:${port}`;
158
+ /** A path as short as it reads unambiguously: under the current folder as `./…`, under home as `~/…`. */
159
+ const home = homedir();
160
+ const tilde = (path) => path === home || path.startsWith(`${home}/`) ? `~${path.slice(home.length)}` : path;
161
+ const shown = (path) => { const near = relative(process.cwd(), path); return near === '' ? '.' : !near.startsWith('..') ? `./${near}` : tilde(path); };
162
+ /** This launch's folder arguments behind another command, for the hints the run commands print. */
163
+ const command = (word) => ['npx braian', word, ...(folder !== undefined ? [folder] : []), ...(options.global ? ['-g'] : []), ...(options.data ? ['--data', options.data] : [])].join(' ');
164
+ const { pidFile, logFile } = runStatePaths(dataPath);
165
+ /** What the table calls this data folder's run: its vault, `home`, or the configured folder's name. */
166
+ const runName = target.mode === 'vault' ? target.vaultId : target.mode === 'global' ? 'home' : basename(dataPath);
167
+
168
+ // status, logs and stop only read and signal: no demo, no vault registration, no data folder created.
169
+ if (action === 'status') process.exit(await reportStatus());
170
+ if (action === 'logs') process.exit(await showLogs());
171
+ if (action === 'stop') process.exit(await stopRun());
172
+
173
+ // restart stops what runs first and keeps its port unless another one is asked for.
174
+ if (action === 'restart') {
175
+ const running = await inspectRun(pidFile);
176
+ if (running.state === 'running' && requestedPort === undefined) setPort(running.run.port);
177
+ if (running.state !== 'none') {
178
+ const stopped = await stopRun({ quiet: true });
179
+ if (stopped !== 0) process.exit(stopped);
180
+ }
181
+ }
182
+ function setPort(next) { port = next; url = `http://localhost:${port}`; }
183
+
184
+ // One BrAIan per data folder: a second start would share its settings, secrets and vault list.
185
+ const current = await inspectRun(pidFile);
186
+ if (current.state === 'running') {
187
+ console.error(`BrAIan already runs for ${shown(dataPath)} at ${current.run.url} (pid ${current.run.pid}).\nRestart it with: ${command('restart')}\nStop it with: ${command('stop')}`);
188
+ process.exit(1);
189
+ }
190
+ if (current.state === 'stale') {
191
+ clearRunState(pidFile);
192
+ if (current.reason === 'silent') console.warn(`Ignoring the last run's record: pid ${current.run.pid} is alive but nothing answers at ${current.run.url}.\n`);
193
+ }
194
+ const background = action === 'start' || action === 'restart';
195
+ // Two folders run side by side: with no port asked for, a taken 8484 moves on to the next free one.
196
+ if (!(await portIsFree(port))) {
197
+ const portAsked = requestedPort !== undefined || action === 'restart';
198
+ const free = portAsked ? undefined : await firstFreePort(port + 1);
199
+ if (free === undefined) {
200
+ console.error(`Port ${port} is already in use. Pass --port <n> to run this one beside it.`);
201
+ process.exit(1);
202
+ }
203
+ console.log(`[braian] Port ${port} is taken; using ${free}.`);
204
+ setPort(free);
205
+ }
206
+
207
+ // A folder with nothing in it yet starts as the Welcome demo, so the first look is not an empty
208
+ // vault; a folder that already holds anything opens as it is. A failed download only says so.
209
+ if (target.mode === 'vault' && demo) {
210
+ const { installDemoInto, isEmptyVaultFolder } = await import('@braian/graph-agent');
211
+ if (await isEmptyVaultFolder(target.vaultPath)) {
212
+ console.log('The folder is empty: installing the Welcome demo vault…');
213
+ // One retry: a first run often downloads the demo while npm is still busy installing BrAIan.
214
+ const install = () => installDemoInto(target.vaultPath, 'welcome');
215
+ try {
216
+ const installed = await install().catch((error) => error.code === 'demo_unreachable' ? install() : Promise.reject(error));
217
+ console.log(`Installed the ${installed.name} demo (${installed.version}). Delete its notes whenever you like; they are yours.\n`);
218
+ } catch (error) {
219
+ const cause = error.cause?.cause?.message ?? error.cause?.message;
220
+ console.warn(`Could not install the demo vault: ${error.message}${cause ? ` (${cause})` : ''}\nStarting with an empty vault; while the folder stays empty, the next start tries again.\n`);
221
+ }
222
+ }
223
+ }
68
224
 
69
225
  // A local data folder often sits in a Git repository; its secrets must not be committed with it.
70
- if (target.mode === 'local' && !existsSync(join(dataPath, '.gitignore'))) {
226
+ if (target.mode === 'vault' && !existsSync(join(dataPath, '.gitignore'))) {
71
227
  mkdirSync(dataPath, { recursive: true });
72
228
  writeFileSync(join(dataPath, '.gitignore'), LOCAL_GITIGNORE);
73
229
  }
230
+ // The folder is registered in the data folder's own vault list, not served alone, so the vault
231
+ // manager can still add, open and remove vaults beside it; a folder already listed keeps its ID.
232
+ let openPath = '';
74
233
  if (target.mode === 'vault') {
75
- process.env.BRAIAN_VAULT = target.vaultPath;
76
- process.env.BRAIAN_VAULT_ID = target.vaultId;
77
- // A vault list from the environment would contradict the one vault served.
234
+ // A discovered or locked list from the environment would contradict the folder opened.
78
235
  delete process.env.BRAIAN_VAULTS;
236
+ delete process.env.BRAIAN_VAULT;
237
+ const { DataWorkspace } = await import('@braian/graph-agent');
238
+ const workspace = await DataWorkspace.create({ rootPath: dataPath, ...(process.env.BRAIAN_VAULTS_ROOT ? { vaultsPath: resolve(process.env.BRAIAN_VAULTS_ROOT) } : {}) });
239
+ const claims = await workspace.vaultClaims();
240
+ const listed = claims.folders.find((entry) => entry.path === target.vaultPath);
241
+ target.vaultId = listed?.id ?? freeVaultId(target.vaultId, claims.ids);
242
+ if (!listed) await workspace.addVault({ id: target.vaultId, label: basename(target.vaultPath), dataPath: target.vaultPath });
243
+ openPath = `/${encodeURIComponent(target.vaultId)}`;
79
244
  }
80
245
 
246
+ const modeLabel = { global: 'home', explicit: 'configured', vault: 'local vault' }[target.mode];
247
+ const banner = (title, extra = []) => [
248
+ title,
249
+ ` data ${shown(dataPath)} (${modeLabel})`,
250
+ ...(target.mode === 'vault' ? [` vault ${shown(target.vaultPath)} (as '${target.vaultId}')`] : []),
251
+ ` url ${url}`,
252
+ ...extra,
253
+ ' Do not run the desktop app on the same data folder at the same time.\n'
254
+ ].join('\n');
255
+
256
+ if (background) process.exit(await detach());
257
+
81
258
  process.env.NODE_ENV ??= 'production';
82
259
  process.env.PORT = String(port);
83
260
  process.env.BRAIAN_DATA_PATH = dataPath;
84
261
  process.env.BRAIAN_WEB_APP_PATH ??= join(root, 'public');
85
262
 
86
- const url = `http://localhost:${port}`;
87
- /** A path as short as it reads unambiguously: under the current folder as `./…`, under home as `~/…`. */
88
- const home = homedir();
89
- const tilde = (path) => path === home || path.startsWith(`${home}/`) ? `~${path.slice(home.length)}` : path;
90
- const shown = (path) => { const near = relative(process.cwd(), path); return near === '' ? '.' : !near.startsWith('..') ? `./${near}` : tilde(path); };
91
- const modeLabel = { local: 'local', global: 'global', explicit: 'from --data', vault: 'global' }[target.mode];
92
- console.log(`BrAIan ${version}\n data ${shown(dataPath)} (${modeLabel})${target.mode === 'vault' ? `\n vault ${shown(target.vaultPath)} (alone, as '${target.vaultId}')` : ''}\n url ${url}\n Do not run the desktop app on the same data folder at the same time.\n`);
93
- if (target.mode === 'vault') console.warn(warningBox([
94
- `${tilde(target.vaultPath)} is a vault.`,
95
- `Opening it alone, with the settings, login and AI providers of ${tilde(dataPath)}.`,
96
- 'Its own .brian keeps only the vault\'s metadata. To keep data next to it',
97
- 'instead, start from its parent folder or pass --data <dir>.'
98
- ]));
99
-
100
- /** Lines in a yellow box, plain when the output is not a terminal. */
101
- function warningBox(lines) {
102
- const width = Math.max(...lines.map((line) => line.length));
103
- const color = process.stderr.isTTY && !process.env.NO_COLOR ? (text) => `\x1b[33m${text}\x1b[0m` : (text) => text;
104
- const title = ' ⚠ Vault folder ';
105
- return [
106
- color(`┌─${title}${'─'.repeat(width - title.length + 1)}┐`),
107
- ...lines.map((line) => `${color('│')} ${line.padEnd(width)} ${color('│')}`),
108
- color(`└${'─'.repeat(width + 2)}┘`),
109
- ''
110
- ].join('\n');
111
- }
263
+ // The record status, stop and the next start read; this process is the server, so it is its PID.
264
+ mkdirSync(dataPath, { recursive: true });
265
+ writeFileSync(pidFile, `${JSON.stringify({
266
+ pid: process.pid, port, url, version, dataPath,
267
+ name: target.mode === 'vault' ? target.vaultId : runName,
268
+ ...(target.mode === 'vault' ? { vaultPath: target.vaultPath, vaultId: target.vaultId } : {}),
269
+ background: process.env.BRAIAN_RUN_DETACHED === '1',
270
+ startedAt: new Date().toISOString()
271
+ }, null, 2)}\n`);
272
+ // A signal ends the process without 'exit'; the next start or stop finds that record stale instead.
273
+ process.on('exit', () => clearRunState(pidFile, process.pid));
274
+ // Listed for `status` with no folder; a run that has ended leaves the list the next time it is read.
275
+ addToRunIndex(indexFile, dataPath);
276
+ delete process.env.BRAIAN_RUN_DETACHED;
112
277
 
278
+ console.log(banner(`BrAIan ${version}`));
113
279
  await import(join(root, 'dist', 'main.js'));
114
280
 
115
- // The API listens before it indexes, so the first answer from /api/health means the page loads.
116
- async function openWhenListening() {
281
+ /** Waits for the first answer from /api/health: the API listens before it indexes, so the page loads then. */
282
+ async function waitUntilListening(gaveUp = () => false) {
117
283
  for (let attempt = 0; attempt < 120; attempt += 1) {
118
- try {
119
- const response = await fetch(`${url}/api/health`);
120
- if (response.ok) break;
121
- } catch { /* not listening yet */ }
284
+ if (gaveUp()) return false;
285
+ if (await answersHealth(url)) return true;
122
286
  await new Promise((done) => setTimeout(done, 500));
123
287
  }
124
- const [command, args] = process.platform === 'darwin' ? ['open', [url]] : process.platform === 'win32' ? ['cmd', ['/c', 'start', '', url]] : ['xdg-open', [url]];
125
- const child = spawn(command, args, { stdio: 'ignore', detached: true });
126
- child.on('error', () => console.log(`Open ${url} in your browser.`));
288
+ return false;
289
+ }
290
+
291
+ function openBrowser() {
292
+ const page = `${url}${openPath}`;
293
+ const [opener, args] = process.platform === 'darwin' ? ['open', [page]] : process.platform === 'win32' ? ['cmd', ['/c', 'start', '', page]] : ['xdg-open', [page]];
294
+ const child = spawn(opener, args, { stdio: 'ignore', detached: true });
295
+ child.on('error', () => console.log(`Open ${page} in your browser.`));
296
+ child.unref();
297
+ }
298
+ if (open) void waitUntilListening().then(openBrowser);
299
+
300
+ /** Starts this same launcher in the foreground as a detached child writing to the log, and returns once it answers. */
301
+ async function detach() {
302
+ mkdirSync(dirname(logFile), { recursive: true });
303
+ const log = openSync(logFile, 'a');
304
+ writeSync(log, `\n--- ${new Date().toISOString()} braian ${version} ${action} ---\n`);
305
+ // Demo and registration are done: the child only serves, under the same data folder and port.
306
+ const args = [fileURLToPath(import.meta.url), ...(folder !== undefined ? [folder] : []), ...(options.global ? ['-g'] : []), ...(options.data ? ['--data', options.data] : []), '--port', String(port), '--no-open', '--no-demo'];
307
+ const child = spawn(process.execPath, args, { detached: true, stdio: ['ignore', log, log], env: { ...process.env, BRAIAN_RUN_DETACHED: '1', NO_COLOR: process.env.NO_COLOR ?? '1' }, windowsHide: true });
308
+ closeSync(log);
309
+ let exited;
310
+ child.once('exit', (code, signal) => { exited = signal ?? `code ${code}`; });
127
311
  child.unref();
312
+
313
+ console.log(`[braian] ${action === 'restart' ? 'Restarting' : 'Starting'} ${runName} in the background…`);
314
+ const listening = await waitUntilListening(() => exited !== undefined);
315
+ if (exited !== undefined) {
316
+ const tail = lastLines(readFileSync(logFile, 'utf8'), 20).join('\n');
317
+ console.error(`[braian] It stopped while starting (${exited}). The end of ${shown(logFile)}:\n\n${tail}`);
318
+ return 1;
319
+ }
320
+ if (!listening) console.warn(`[braian] It does not answer yet; ${command('status')} says when it does.`);
321
+ else {
322
+ console.log('[braian] Done.');
323
+ if (open) openBrowser();
324
+ }
325
+ if (!quietTable) await reportStatus();
326
+ return 0;
327
+ }
328
+
329
+ /** The pm2-style table for this data folder's run, with where its data and log are underneath. */
330
+ async function reportStatus() {
331
+ const found = await inspectRun(pidFile);
332
+ const run = found.run;
333
+ const status = found.state === 'running' ? 'online' : found.reason === 'silent' ? 'not answering' : 'stopped';
334
+ const live = found.state === 'running' || found.reason === 'silent';
335
+ const row = [
336
+ runName,
337
+ live ? run.pid : '-',
338
+ live ? (run.background === false ? 'terminal' : 'background') : '-',
339
+ status,
340
+ live ? formatUptime(Date.now() - Date.parse(run.startedAt)) : '-',
341
+ live ? memoryOf(run.pid) : '-',
342
+ live ? run.url : '-'
343
+ ];
344
+ console.log(formatTable(['name', 'pid', 'mode', 'status', 'uptime', 'mem', 'url'], [row]));
345
+ console.log(` data ${shown(dataPath)}${target.mode === 'vault' ? `\n vault ${shown(target.vaultPath)}` : ''}\n log ${shown(logFile)}`);
346
+ if (!live) console.log(`Start it with: ${command('start')}`);
347
+ return found.state === 'running' ? 0 : 3;
348
+ }
349
+
350
+ async function stopRun({ quiet = false } = {}) {
351
+ const found = await inspectRun(pidFile);
352
+ if (found.state === 'none' || found.reason === 'exited' || found.reason === 'unreadable') {
353
+ clearRunState(pidFile);
354
+ if (!quiet) console.log(`[braian] ${runName} is not running.`);
355
+ return 0;
356
+ }
357
+ const { run } = found;
358
+ if (found.state === 'stale') {
359
+ // The PID may belong to another program by now; signalling it on a guess is not this command's call.
360
+ console.error(`[braian] pid ${run.pid} is alive but nothing answers at ${run.url}, so it is not stopped: the PID may now be another program's.\nIf it is BrAIan, end it with: kill ${run.pid}`);
361
+ return 1;
362
+ }
363
+ console.log(`[braian] Stopping ${runName} (pid ${run.pid})…`);
364
+ const ended = await stopProcess(run.pid);
365
+ if (ended === 'alive') {
366
+ console.error(`[braian] pid ${run.pid} is still running after SIGKILL.`);
367
+ return 1;
368
+ }
369
+ clearRunState(pidFile, run.pid);
370
+ removeFromRunIndex(indexFile, dataPath);
371
+ console.log(ended === 'killed' ? '[braian] It did not end within 15s of SIGTERM, so it was killed.' : '[braian] Stopped.');
372
+ if (!quiet && !quietTable) await reportStatus();
373
+ return 0;
374
+ }
375
+
376
+ /** pm2 logs: the last --lines lines, then every line appended until Ctrl+C, unless --nostream. */
377
+ async function showLogs() {
378
+ if (!existsSync(logFile)) {
379
+ console.log(`[braian] No log at ${shown(logFile)} yet: only a background run (${command('start')}) writes one.`);
380
+ return 1;
381
+ }
382
+ console.log(`[braian] ${shown(logFile)}, last ${lines} lines:`);
383
+ const text = readFileSync(logFile, 'utf8');
384
+ for (const line of lastLines(text, lines)) console.log(line);
385
+ if (options.nostream) return 0;
386
+ const found = await inspectRun(pidFile);
387
+ if (found.state === 'running' && found.run.background === false) console.log(`[braian] ${runName} runs in a terminal, which shows its output; this log only grows from background runs.`);
388
+ let offset = Buffer.byteLength(text);
389
+ const follow = () => {
390
+ const { size } = statSync(logFile);
391
+ if (size < offset) offset = 0;
392
+ if (size === offset) return;
393
+ const fd = openSync(logFile, 'r');
394
+ const chunk = Buffer.alloc(size - offset);
395
+ readSync(fd, chunk, 0, chunk.length, offset);
396
+ closeSync(fd);
397
+ offset = size;
398
+ process.stdout.write(chunk);
399
+ };
400
+ // `braian logs | head` closes the pipe; that ends the follow, it is not an error.
401
+ process.stdout.on('error', (error) => { if (error.code === 'EPIPE') process.exit(0); throw error; });
402
+ watchFile(logFile, { interval: 500 }, follow);
403
+ await new Promise((done) => process.once('SIGINT', done));
404
+ unwatchFile(logFile);
405
+ return 0;
128
406
  }
129
- if (open) void openWhenListening();
@@ -10,41 +10,29 @@ export function vaultIdFor(folder) {
10
10
  return cleaned || 'vault';
11
11
  }
12
12
 
13
- /** A folder is a vault when its own `.brian` already carries a vault's settings or topology. */
14
- export function isVaultFolder(folder, exists) {
15
- return exists(join(folder, '.brian', 'vault.yaml')) || exists(join(folder, '.brian', 'topology'));
13
+ /** `id`, or `id-2`, `id-3`, … the first that none of `taken` claims, compared case-insensitively. */
14
+ export function freeVaultId(id, taken) {
15
+ const claimed = new Set(taken.map((name) => name.toLowerCase()));
16
+ if (!claimed.has(id.toLowerCase())) return id;
17
+ for (let n = 2; ; n += 1) if (!claimed.has(`${id}-${n}`.toLowerCase())) return `${id}-${n}`;
16
18
  }
17
19
 
18
- /**
19
- * The launch target:
20
- * - `mode: 'global'` — `-g`: the data folder is `~/.brian`, shared with the desktop app;
21
- * - `mode: 'local'` — the default: `<folder>/.brian`, `<folder>` being the argument or the current folder;
22
- * - `mode: 'vault'` — that folder is a vault itself: it is served alone, with the settings, secrets and
23
- * providers of `~/.brian`, so the vault's own committed `.brian` never holds them;
24
- * - `mode: 'explicit'`— `--data` or `$BRAIAN_DATA_PATH`, which win over everything else.
25
- * `vaultPath` and `vaultId` are set in vault mode only. Throws on a missing folder or `-g` with a folder.
20
+ /** No folder uses home settings; an explicit folder is registered in its own data folder's vault list and opened.
21
+ * --data / BRAIAN_DATA_PATH changes application data without changing the requested vault.
26
22
  */
27
23
  export function resolveLaunchTarget({ folder, global = false, data, cwd, home, env = {}, exists }) {
28
24
  if (global && folder !== undefined) throw new Error('Pass either a folder or -g, not both.');
29
25
  const explicit = data ?? env.BRAIAN_DATA_PATH;
30
- if (explicit) return { mode: 'explicit', dataPath: resolve(cwd, explicit) };
31
- const globalPath = join(home, '.brian');
32
- if (global) return { mode: 'global', dataPath: globalPath };
33
- const base = resolve(cwd, folder ?? '.');
26
+ if (folder === undefined) return {
27
+ mode: explicit ? 'explicit' : 'global',
28
+ dataPath: explicit ? resolve(cwd, explicit) : join(home, '.braianrc')
29
+ };
30
+ const base = resolve(cwd, folder);
34
31
  if (!exists(base)) throw new Error(`No folder at ${base}.`);
35
- if (isVaultFolder(base, exists)) return { mode: 'vault', dataPath: globalPath, vaultPath: base, vaultId: vaultIdFor(base) };
36
- return { mode: 'local', dataPath: join(base, '.brian') };
32
+ return { mode: 'vault', dataPath: explicit ? resolve(cwd, explicit) : join(base, '.braianrc'), vaultPath: base, vaultId: vaultIdFor(base) };
37
33
  }
38
34
 
39
35
  /** What a local data folder keeps out of Git: its secrets and what records one install's use. */
40
- export const LOCAL_GITIGNORE = `# Written by \`npx braian\`. The data folder holds secrets and per-install state; vault notes stay committable.
41
- auth.yaml
42
- settings.yaml
43
- dev-bypass.token
44
- transcription.json
45
- logs/
46
- **/*.tmp
47
- vaults/*/.brian/sessions/
48
- vaults/*/.brian/sessions.yaml
49
- vaults/*/.brian/activity.yaml
36
+ export const LOCAL_GITIGNORE = `# Application settings and secrets belong to this install, never Git.
37
+ *
50
38
  `;