@cryptiklemur/lattice 4.0.2 → 5.0.0

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 (394) hide show
  1. package/bin/lattice +1 -9
  2. package/dist/client/assets/{angular-html-N8PCEquT.js → angular-html-DKTL-XDO.js} +1 -1
  3. package/dist/client/assets/{angular-ts-CJ8RJIPD.js → angular-ts-tvBzOwQR.js} +1 -1
  4. package/dist/client/assets/{apl-BD6tCLWN.js → apl-CCzl5qFl.js} +1 -1
  5. package/dist/client/assets/{astro-CpIIfBs6.js → astro-DNQTpO2Y.js} +1 -1
  6. package/dist/client/assets/{blade-D3qgnjiV.js → blade-CyJoIMeJ.js} +1 -1
  7. package/dist/client/assets/{c-Dr6ADN_t.js → c-OEwk5KN8.js} +1 -1
  8. package/dist/client/assets/{cobol-BIfDE0Hr.js → cobol-DpHyJzz2.js} +1 -1
  9. package/dist/client/assets/{coffee-DHQ57vfY.js → coffee-BX5dbDzZ.js} +1 -1
  10. package/dist/client/assets/{cpp-CEBY6JOp.js → cpp-BTBjNg2U.js} +1 -1
  11. package/dist/client/assets/{crystal-D125CSmP.js → crystal-CNzZd6DW.js} +1 -1
  12. package/dist/client/assets/{css-CBmrkYSr.js → css-BuKsNmms.js} +1 -1
  13. package/dist/client/assets/{dist-A_mCRD1f.js → dist-CKpDHMy6.js} +2 -2
  14. package/dist/client/assets/{edge-Ccsz7cJW.js → edge-DzhnGgJE.js} +1 -1
  15. package/dist/client/assets/{elixir-Do6gk14X.js → elixir-Dqs0waqF.js} +1 -1
  16. package/dist/client/assets/{elm-Db22zT4C.js → elm-BtWwjxWn.js} +1 -1
  17. package/dist/client/assets/{erb-MXVqAAJD.js → erb-iPD89b4v.js} +1 -1
  18. package/dist/client/assets/{git-rebase-B-LLWBOA.js → git-rebase-BxVNXJL4.js} +1 -1
  19. package/dist/client/assets/{glimmer-js-eWszRU73.js → glimmer-js-BlyCupwF.js} +1 -1
  20. package/dist/client/assets/{glimmer-ts-VQmwGqUp.js → glimmer-ts-DjIxWOS9.js} +1 -1
  21. package/dist/client/assets/{glsl-B8ilOfAl.js → glsl-CGIL-65r.js} +1 -1
  22. package/dist/client/assets/{graphql-DnTqxeOc.js → graphql-DeOn6mNV.js} +1 -1
  23. package/dist/client/assets/{hack-XJsHYSQb.js → hack-DVppeCmS.js} +1 -1
  24. package/dist/client/assets/{haml-CQ7Vqzwp.js → haml-WDhua0Mp.js} +1 -1
  25. package/dist/client/assets/{handlebars-C4szooBf.js → handlebars-i2Fu_9HI.js} +1 -1
  26. package/dist/client/assets/{html-B6EgAiSd.js → html-B1e6oxzK.js} +1 -1
  27. package/dist/client/assets/{html-derivative-DdinogQX.js → html-derivative-MofKXIVd.js} +1 -1
  28. package/dist/client/assets/{http-BSLxCgRq.js → http-Dk6S5pRD.js} +1 -1
  29. package/dist/client/assets/{hurl-pOsTwNfp.js → hurl-CroFYYJG.js} +1 -1
  30. package/dist/client/assets/{index-BHQ_8mvl.js → index-CVu-S6Yk.js} +2 -2
  31. package/dist/client/assets/{java-DRQLiiST.js → java-B89FYjqS.js} +1 -1
  32. package/dist/client/assets/{javascript-DvEK2-47.js → javascript-m6CO1Uiy.js} +1 -1
  33. package/dist/client/assets/{jinja-D2NYJ25y.js → jinja-DC9Wi41X.js} +1 -1
  34. package/dist/client/assets/{jison-DDZaLNAp.js → jison-6xiegwDk.js} +1 -1
  35. package/dist/client/assets/{json-TGR0NIWd.js → json-HA-96-qr.js} +1 -1
  36. package/dist/client/assets/{jsx-BjUoPYga.js → jsx-Wt1a8i8U.js} +1 -1
  37. package/dist/client/assets/{julia-C4gjSpFu.js → julia-7M93VBON.js} +1 -1
  38. package/dist/client/assets/{just-H351x5u_.js → just-CjfDLYLv.js} +1 -1
  39. package/dist/client/assets/{latex-BiTmf6gf.js → latex-CitsJ46x.js} +1 -1
  40. package/dist/client/assets/{liquid-86ufjRy-.js → liquid-C8VIFin8.js} +1 -1
  41. package/dist/client/assets/{lua-BNxR0F_8.js → lua-Ba2N7esc.js} +1 -1
  42. package/dist/client/assets/{marko-CvRxpRjM.js → marko-lTLvb2wu.js} +1 -1
  43. package/dist/client/assets/{mdc-CYbAIy2C.js → mdc-D6IV-8FD.js} +1 -1
  44. package/dist/client/assets/{nginx-egdgMq-F.js → nginx-Ch5AjE6S.js} +1 -1
  45. package/dist/client/assets/{nim-CXBJVz_w.js → nim-WmDDC6LW.js} +1 -1
  46. package/dist/client/assets/{perl-XRfMobzg.js → perl-CQv0gYuq.js} +1 -1
  47. package/dist/client/assets/{php-Br7a8uil.js → php-BJmH0qOB.js} +1 -1
  48. package/dist/client/assets/{pug-BVbbUVvy.js → pug-CsHPkzc9.js} +1 -1
  49. package/dist/client/assets/{qml-ByKvrL1j.js → qml-B36ecArG.js} +1 -1
  50. package/dist/client/assets/{r-mVoV0Ni6.js → r-D5Yi5Z4y.js} +1 -1
  51. package/dist/client/assets/{razor-T5O-9UJL.js → razor-CHAxVq4R.js} +1 -1
  52. package/dist/client/assets/{regexp-CioRuhuN.js → regexp-gfs--3M7.js} +1 -1
  53. package/dist/client/assets/{rst-V__uTudD.js → rst-ugdlp-hl.js} +1 -1
  54. package/dist/client/assets/{ruby-C_PuKPTI.js → ruby-CDRRW37j.js} +1 -1
  55. package/dist/client/assets/{sas-D_DqqQH4.js → sas-DZaNQaIP.js} +1 -1
  56. package/dist/client/assets/{scss-D-TjzZ4c.js → scss-CzWQEplj.js} +1 -1
  57. package/dist/client/assets/{shellscript-E5759VHu.js → shellscript-fgYvpu9N.js} +1 -1
  58. package/dist/client/assets/{shellsession-AESTM-Pv.js → shellsession-BoAohHh7.js} +1 -1
  59. package/dist/client/assets/{soy-QrbrrcDv.js → soy-DBzVgv9x.js} +1 -1
  60. package/dist/client/assets/{sql-0M8VcDHD.js → sql-BYXpAYTs.js} +1 -1
  61. package/dist/client/assets/{stata-CgeIpGtc.js → stata-I71MMY3p.js} +1 -1
  62. package/dist/client/assets/{surrealql-DBGwnZbw.js → surrealql-C9U8_1VO.js} +1 -1
  63. package/dist/client/assets/{svelte-Cv0PvUc_.js → svelte-VOFrPnWT.js} +1 -1
  64. package/dist/client/assets/{templ-B9t7xRE4.js → templ-BIaxAEtC.js} +1 -1
  65. package/dist/client/assets/{tex-DhZZ8dr2.js → tex-D1dwnBE5.js} +1 -1
  66. package/dist/client/assets/{ts-tags-BFv8sbnd.js → ts-tags-C0L2Q0r5.js} +1 -1
  67. package/dist/client/assets/{tsx-CXC9KSbY.js → tsx-BqcycEv1.js} +1 -1
  68. package/dist/client/assets/{twig-CM_OO66r.js → twig-vyWqOhpM.js} +1 -1
  69. package/dist/client/assets/{typescript-BdgOTaoD.js → typescript-B2YbovqG.js} +1 -1
  70. package/dist/client/assets/{vue-BnQhjnCm.js → vue-CbXxGdjo.js} +1 -1
  71. package/dist/client/assets/{vue-html-CNnGecRI.js → vue-html-DDX4KXW7.js} +1 -1
  72. package/dist/client/assets/{vue-vine-DCuMkRhK.js → vue-vine-DsyY1LR5.js} +1 -1
  73. package/dist/client/assets/{xml-CbTD7cB8.js → xml-Ddi0-r0D.js} +1 -1
  74. package/dist/client/assets/{xsl-uOqqo7cf.js → xsl-CsFcZHFS.js} +1 -1
  75. package/dist/client/assets/{yaml-BNrLoH59.js → yaml-tGJWoH6Y.js} +1 -1
  76. package/dist/client/index.html +1 -1
  77. package/dist/client/sw.js +1 -1
  78. package/dist/server/analytics/engine.js +832 -0
  79. package/dist/server/assets.js +39 -0
  80. package/dist/server/auth/passphrase.js +70 -0
  81. package/dist/server/config.js +47 -0
  82. package/dist/server/daemon.js +535 -0
  83. package/dist/server/features/ralph-loop.js +138 -0
  84. package/dist/server/features/scheduler.js +260 -0
  85. package/dist/server/features/sticky-notes.js +99 -0
  86. package/dist/server/handlers/analytics.js +28 -0
  87. package/dist/server/handlers/attachment.js +158 -0
  88. package/dist/server/handlers/bookmarks.js +41 -0
  89. package/dist/server/handlers/chat.js +350 -0
  90. package/dist/server/handlers/editor.js +72 -0
  91. package/dist/server/handlers/fs.js +234 -0
  92. package/dist/server/handlers/loop.js +33 -0
  93. package/dist/server/handlers/memory.js +181 -0
  94. package/dist/server/handlers/mesh.js +322 -0
  95. package/dist/server/handlers/notes.js +36 -0
  96. package/dist/server/handlers/plugins.js +593 -0
  97. package/dist/server/handlers/project-settings.js +166 -0
  98. package/dist/server/handlers/scheduler.js +52 -0
  99. package/dist/server/handlers/session.js +194 -0
  100. package/dist/server/handlers/settings.js +148 -0
  101. package/dist/server/handlers/skills.js +360 -0
  102. package/dist/server/handlers/terminal.js +75 -0
  103. package/dist/server/handlers/themes.js +102 -0
  104. package/dist/server/handlers/update.js +124 -0
  105. package/dist/server/identity.js +45 -0
  106. package/dist/server/index.js +435 -0
  107. package/dist/server/logger.js +20 -0
  108. package/dist/server/mesh/connector.js +355 -0
  109. package/dist/server/mesh/crypto.js +88 -0
  110. package/dist/server/mesh/discovery.js +95 -0
  111. package/dist/server/mesh/pairing.js +104 -0
  112. package/dist/server/mesh/peers.js +54 -0
  113. package/dist/server/mesh/proxy.js +86 -0
  114. package/dist/server/mesh/session-sync.js +85 -0
  115. package/dist/server/project/bookmarks.js +77 -0
  116. package/dist/server/project/context-breakdown.js +279 -0
  117. package/dist/server/project/file-browser.js +97 -0
  118. package/dist/server/project/project-files.js +274 -0
  119. package/dist/server/project/registry.js +51 -0
  120. package/dist/server/project/sdk-bridge.js +960 -0
  121. package/dist/server/project/session.js +696 -0
  122. package/dist/server/project/terminal.js +87 -0
  123. package/dist/server/project/warmup.js +242 -0
  124. package/dist/server/push.js +87 -0
  125. package/dist/server/tls.js +50 -0
  126. package/dist/server/tui.js +83 -0
  127. package/dist/server/update-checker.js +119 -0
  128. package/dist/server/ws/broadcast.js +50 -0
  129. package/dist/server/ws/router.js +105 -0
  130. package/dist/server/ws/server.js +2 -0
  131. package/dist/shared/analytics.js +1 -0
  132. package/dist/shared/messages.js +1 -0
  133. package/dist/shared/models.js +1 -0
  134. package/dist/shared/project-settings.js +1 -0
  135. package/package.json +5 -8
  136. package/themes/alabaster.json +9 -0
  137. package/themes/amoled.json +20 -0
  138. package/themes/ayu-light.json +9 -0
  139. package/themes/catppuccin-latte.json +9 -0
  140. package/themes/catppuccin-mocha.json +9 -0
  141. package/themes/clay-light.json +10 -0
  142. package/themes/clay.json +10 -0
  143. package/themes/dracula.json +9 -0
  144. package/themes/everforest-light.json +9 -0
  145. package/themes/everforest.json +9 -0
  146. package/themes/github-light.json +9 -0
  147. package/themes/gruvbox-dark.json +9 -0
  148. package/themes/gruvbox-light.json +9 -0
  149. package/themes/horizon-light.json +9 -0
  150. package/themes/kanagawa-lotus.json +9 -0
  151. package/themes/kanagawa.json +9 -0
  152. package/themes/modus-operandi.json +9 -0
  153. package/themes/monokai.json +9 -0
  154. package/themes/nightfox.json +9 -0
  155. package/themes/nord-light.json +9 -0
  156. package/themes/nord.json +9 -0
  157. package/themes/one-dark.json +9 -0
  158. package/themes/one-light.json +9 -0
  159. package/themes/palenight.json +9 -0
  160. package/themes/paper.json +9 -0
  161. package/themes/penumbra-light.json +9 -0
  162. package/themes/poimandres.json +9 -0
  163. package/themes/quiet-light.json +9 -0
  164. package/themes/rose-pine-dawn.json +9 -0
  165. package/themes/rose-pine.json +9 -0
  166. package/themes/solarized-dark.json +9 -0
  167. package/themes/solarized-light.json +9 -0
  168. package/themes/synthwave84.json +9 -0
  169. package/themes/tokyo-night-light.json +9 -0
  170. package/themes/tokyo-night.json +9 -0
  171. package/themes/vesper.json +9 -0
  172. package/index.html +0 -20
  173. package/public/icons/icon-192.svg +0 -11
  174. package/public/icons/icon-512.svg +0 -11
  175. package/public/sw-push.js +0 -53
  176. package/src/client/App.tsx +0 -42
  177. package/src/client/commands.ts +0 -36
  178. package/src/client/components/analytics/AnalyticsView.tsx +0 -244
  179. package/src/client/components/analytics/ChartCard.tsx +0 -194
  180. package/src/client/components/analytics/PeriodSelector.tsx +0 -42
  181. package/src/client/components/analytics/QuickStats.tsx +0 -122
  182. package/src/client/components/analytics/chartTokens.ts +0 -188
  183. package/src/client/components/analytics/charts/ActivityCalendar.tsx +0 -204
  184. package/src/client/components/analytics/charts/CacheEfficiencyChart.tsx +0 -56
  185. package/src/client/components/analytics/charts/ContextUtilizationChart.tsx +0 -106
  186. package/src/client/components/analytics/charts/CostAreaChart.tsx +0 -79
  187. package/src/client/components/analytics/charts/CostDistributionChart.tsx +0 -59
  188. package/src/client/components/analytics/charts/CostDonutChart.tsx +0 -84
  189. package/src/client/components/analytics/charts/CumulativeCostChart.tsx +0 -59
  190. package/src/client/components/analytics/charts/DailySummaryCards.tsx +0 -86
  191. package/src/client/components/analytics/charts/HourlyHeatmap.tsx +0 -133
  192. package/src/client/components/analytics/charts/NodeFleetOverview.tsx +0 -89
  193. package/src/client/components/analytics/charts/PermissionBreakdown.tsx +0 -98
  194. package/src/client/components/analytics/charts/ProjectRadar.tsx +0 -126
  195. package/src/client/components/analytics/charts/ResponseTimeScatter.tsx +0 -96
  196. package/src/client/components/analytics/charts/SessionBubbleChart.tsx +0 -114
  197. package/src/client/components/analytics/charts/SessionComplexityList.tsx +0 -65
  198. package/src/client/components/analytics/charts/SessionTimeline.tsx +0 -107
  199. package/src/client/components/analytics/charts/TokenFlowChart.tsx +0 -78
  200. package/src/client/components/analytics/charts/TokenSankeyChart.tsx +0 -93
  201. package/src/client/components/analytics/charts/ToolSunburst.tsx +0 -123
  202. package/src/client/components/analytics/charts/ToolTreemap.tsx +0 -110
  203. package/src/client/components/auth/PassphrasePrompt.tsx +0 -70
  204. package/src/client/components/chat/AttachmentChips.tsx +0 -116
  205. package/src/client/components/chat/ChatInput.tsx +0 -533
  206. package/src/client/components/chat/ChatView.tsx +0 -1076
  207. package/src/client/components/chat/CommandPalette.tsx +0 -162
  208. package/src/client/components/chat/ElicitationCard.tsx +0 -238
  209. package/src/client/components/chat/Message.tsx +0 -825
  210. package/src/client/components/chat/ModelSelector.tsx +0 -108
  211. package/src/client/components/chat/PermissionModeSelector.tsx +0 -41
  212. package/src/client/components/chat/PromptQuestion.tsx +0 -271
  213. package/src/client/components/chat/StatusBar.tsx +0 -50
  214. package/src/client/components/chat/TodoCard.tsx +0 -57
  215. package/src/client/components/chat/ToolGroup.tsx +0 -129
  216. package/src/client/components/chat/ToolResultRenderer.tsx +0 -348
  217. package/src/client/components/chat/VoiceRecorder.tsx +0 -85
  218. package/src/client/components/chat/toolSummary.ts +0 -41
  219. package/src/client/components/dashboard/DashboardView.tsx +0 -200
  220. package/src/client/components/dashboard/ProjectDashboardView.tsx +0 -179
  221. package/src/client/components/mesh/NodeBadge.tsx +0 -24
  222. package/src/client/components/mesh/PairingDialog.tsx +0 -340
  223. package/src/client/components/project-settings/ProjectClaude.tsx +0 -318
  224. package/src/client/components/project-settings/ProjectEnvironment.tsx +0 -235
  225. package/src/client/components/project-settings/ProjectGeneral.tsx +0 -76
  226. package/src/client/components/project-settings/ProjectMcp.tsx +0 -232
  227. package/src/client/components/project-settings/ProjectMemory.tsx +0 -488
  228. package/src/client/components/project-settings/ProjectNotifications.tsx +0 -48
  229. package/src/client/components/project-settings/ProjectPermissions.tsx +0 -209
  230. package/src/client/components/project-settings/ProjectPlugins.tsx +0 -117
  231. package/src/client/components/project-settings/ProjectRules.tsx +0 -286
  232. package/src/client/components/project-settings/ProjectSettingsView.tsx +0 -117
  233. package/src/client/components/project-settings/ProjectSkills.tsx +0 -91
  234. package/src/client/components/settings/Appearance.tsx +0 -275
  235. package/src/client/components/settings/BudgetSettings.tsx +0 -165
  236. package/src/client/components/settings/ClaudeSettings.tsx +0 -175
  237. package/src/client/components/settings/Editor.tsx +0 -123
  238. package/src/client/components/settings/Environment.tsx +0 -185
  239. package/src/client/components/settings/GlobalMcp.tsx +0 -216
  240. package/src/client/components/settings/GlobalMemory.tsx +0 -19
  241. package/src/client/components/settings/GlobalPlugins.tsx +0 -806
  242. package/src/client/components/settings/GlobalRules.tsx +0 -149
  243. package/src/client/components/settings/GlobalSkills.tsx +0 -140
  244. package/src/client/components/settings/MeshStatus.tsx +0 -183
  245. package/src/client/components/settings/Notifications.tsx +0 -123
  246. package/src/client/components/settings/SettingsView.tsx +0 -75
  247. package/src/client/components/settings/SkillMarketplace.tsx +0 -175
  248. package/src/client/components/settings/ThemePreview.tsx +0 -140
  249. package/src/client/components/settings/ThemeWizard.tsx +0 -405
  250. package/src/client/components/settings/mcp-shared.tsx +0 -194
  251. package/src/client/components/settings/skill-shared.tsx +0 -186
  252. package/src/client/components/setup/SetupWizard.tsx +0 -755
  253. package/src/client/components/sidebar/AddProjectModal.tsx +0 -438
  254. package/src/client/components/sidebar/NodeSettingsModal.tsx +0 -206
  255. package/src/client/components/sidebar/ProjectDropdown.tsx +0 -211
  256. package/src/client/components/sidebar/ProjectRail.tsx +0 -353
  257. package/src/client/components/sidebar/SearchFilter.tsx +0 -52
  258. package/src/client/components/sidebar/SessionList.tsx +0 -599
  259. package/src/client/components/sidebar/SettingsSidebar.tsx +0 -139
  260. package/src/client/components/sidebar/Sidebar.tsx +0 -469
  261. package/src/client/components/sidebar/UserIsland.tsx +0 -282
  262. package/src/client/components/sidebar/UserMenu.tsx +0 -107
  263. package/src/client/components/ui/CommandPalette.tsx +0 -321
  264. package/src/client/components/ui/ContextMenu.tsx +0 -153
  265. package/src/client/components/ui/ErrorBoundary.tsx +0 -56
  266. package/src/client/components/ui/IconPicker.tsx +0 -184
  267. package/src/client/components/ui/KeyboardShortcuts.tsx +0 -129
  268. package/src/client/components/ui/LatticeLogomark.tsx +0 -19
  269. package/src/client/components/ui/NodeDisconnectedOverlay.tsx +0 -35
  270. package/src/client/components/ui/PopupMenu.tsx +0 -120
  271. package/src/client/components/ui/SaveFooter.tsx +0 -63
  272. package/src/client/components/ui/Toast.tsx +0 -132
  273. package/src/client/components/ui/UpdateBanner.tsx +0 -110
  274. package/src/client/components/ui/UpdatePrompt.tsx +0 -47
  275. package/src/client/components/workspace/BookmarksView.tsx +0 -156
  276. package/src/client/components/workspace/FileBrowser.tsx +0 -174
  277. package/src/client/components/workspace/FileTree.tsx +0 -129
  278. package/src/client/components/workspace/FileViewer.tsx +0 -211
  279. package/src/client/components/workspace/NoteCard.tsx +0 -120
  280. package/src/client/components/workspace/NotesView.tsx +0 -102
  281. package/src/client/components/workspace/ScheduledTasksView.tsx +0 -117
  282. package/src/client/components/workspace/SplitPane.tsx +0 -81
  283. package/src/client/components/workspace/TabBar.tsx +0 -170
  284. package/src/client/components/workspace/TaskCard.tsx +0 -159
  285. package/src/client/components/workspace/TaskEditModal.tsx +0 -129
  286. package/src/client/components/workspace/TerminalInstance.tsx +0 -171
  287. package/src/client/components/workspace/TerminalView.tsx +0 -110
  288. package/src/client/components/workspace/WorkspaceView.tsx +0 -141
  289. package/src/client/hooks/useAnalytics.ts +0 -84
  290. package/src/client/hooks/useAttachments.ts +0 -313
  291. package/src/client/hooks/useBookmarks.ts +0 -57
  292. package/src/client/hooks/useEditorConfig.ts +0 -28
  293. package/src/client/hooks/useFocusTrap.ts +0 -74
  294. package/src/client/hooks/useIdleDetection.ts +0 -50
  295. package/src/client/hooks/useInstallPrompt.ts +0 -53
  296. package/src/client/hooks/useMesh.ts +0 -89
  297. package/src/client/hooks/useNotifications.ts +0 -54
  298. package/src/client/hooks/useOnline.ts +0 -6
  299. package/src/client/hooks/useProjectSettings.ts +0 -56
  300. package/src/client/hooks/useProjects.ts +0 -98
  301. package/src/client/hooks/usePushNotifications.ts +0 -92
  302. package/src/client/hooks/useSaveState.ts +0 -65
  303. package/src/client/hooks/useSession.ts +0 -580
  304. package/src/client/hooks/useSidebar.ts +0 -90
  305. package/src/client/hooks/useSkills.ts +0 -30
  306. package/src/client/hooks/useSpinnerVerb.ts +0 -36
  307. package/src/client/hooks/useSwipeDrawer.ts +0 -299
  308. package/src/client/hooks/useTheme.ts +0 -114
  309. package/src/client/hooks/useTimeTick.ts +0 -35
  310. package/src/client/hooks/useVoiceRecorder.ts +0 -169
  311. package/src/client/hooks/useWebSocket.ts +0 -27
  312. package/src/client/hooks/useWorkspace.ts +0 -57
  313. package/src/client/lib/theme-derive.ts +0 -196
  314. package/src/client/lib/workspace-url.ts +0 -219
  315. package/src/client/main.tsx +0 -10
  316. package/src/client/providers/WebSocketProvider.tsx +0 -186
  317. package/src/client/router.tsx +0 -578
  318. package/src/client/stores/analytics.ts +0 -68
  319. package/src/client/stores/bookmarks.ts +0 -45
  320. package/src/client/stores/mesh.ts +0 -78
  321. package/src/client/stores/session.ts +0 -569
  322. package/src/client/stores/sidebar.ts +0 -530
  323. package/src/client/stores/theme.ts +0 -44
  324. package/src/client/stores/workspace.ts +0 -518
  325. package/src/client/styles/global.css +0 -391
  326. package/src/client/styles/theme-vars.css +0 -18
  327. package/src/client/themes/index.ts +0 -105
  328. package/src/client/utils/editorUrl.ts +0 -55
  329. package/src/client/utils/findDuplicateKeys.ts +0 -12
  330. package/src/client/utils/formatSessionTitle.ts +0 -17
  331. package/src/client/vite-env.d.ts +0 -6
  332. package/src/server/analytics/engine.ts +0 -920
  333. package/src/server/assets.ts +0 -45
  334. package/src/server/auth/passphrase.ts +0 -78
  335. package/src/server/config.ts +0 -55
  336. package/src/server/daemon.ts +0 -567
  337. package/src/server/features/ralph-loop.ts +0 -173
  338. package/src/server/features/scheduler.ts +0 -304
  339. package/src/server/features/sticky-notes.ts +0 -104
  340. package/src/server/handlers/analytics.ts +0 -39
  341. package/src/server/handlers/attachment.ts +0 -189
  342. package/src/server/handlers/bookmarks.ts +0 -50
  343. package/src/server/handlers/chat.ts +0 -381
  344. package/src/server/handlers/editor.ts +0 -76
  345. package/src/server/handlers/fs.ts +0 -251
  346. package/src/server/handlers/loop.ts +0 -37
  347. package/src/server/handlers/memory.ts +0 -182
  348. package/src/server/handlers/mesh.ts +0 -362
  349. package/src/server/handlers/notes.ts +0 -47
  350. package/src/server/handlers/plugins.ts +0 -655
  351. package/src/server/handlers/project-settings.ts +0 -180
  352. package/src/server/handlers/scheduler.ts +0 -64
  353. package/src/server/handlers/session.ts +0 -226
  354. package/src/server/handlers/settings.ts +0 -157
  355. package/src/server/handlers/skills.ts +0 -378
  356. package/src/server/handlers/terminal.ts +0 -88
  357. package/src/server/handlers/themes.ts +0 -121
  358. package/src/server/handlers/update.ts +0 -133
  359. package/src/server/identity.ts +0 -56
  360. package/src/server/index.ts +0 -457
  361. package/src/server/logger.ts +0 -21
  362. package/src/server/mesh/connector.ts +0 -419
  363. package/src/server/mesh/crypto.ts +0 -106
  364. package/src/server/mesh/discovery.ts +0 -126
  365. package/src/server/mesh/pairing.ts +0 -123
  366. package/src/server/mesh/peers.ts +0 -60
  367. package/src/server/mesh/proxy.ts +0 -106
  368. package/src/server/mesh/session-sync.ts +0 -107
  369. package/src/server/project/bookmarks.ts +0 -83
  370. package/src/server/project/context-breakdown.ts +0 -307
  371. package/src/server/project/file-browser.ts +0 -106
  372. package/src/server/project/project-files.ts +0 -267
  373. package/src/server/project/pty-worker.cjs +0 -83
  374. package/src/server/project/registry.ts +0 -57
  375. package/src/server/project/sdk-bridge.ts +0 -1100
  376. package/src/server/project/session.ts +0 -723
  377. package/src/server/project/terminal.ts +0 -111
  378. package/src/server/project/warmup.ts +0 -285
  379. package/src/server/push.ts +0 -121
  380. package/src/server/tls.ts +0 -65
  381. package/src/server/tui.ts +0 -103
  382. package/src/server/update-checker.ts +0 -147
  383. package/src/server/ws/broadcast.ts +0 -61
  384. package/src/server/ws/router.ts +0 -123
  385. package/src/server/ws/server.ts +0 -2
  386. package/src/shared/analytics.ts +0 -40
  387. package/src/shared/messages.ts +0 -1302
  388. package/src/shared/models.ts +0 -255
  389. package/src/shared/project-settings.ts +0 -45
  390. package/tsconfig.json +0 -25
  391. package/vite.config.ts +0 -71
  392. /package/{src/server/runtime.ts → dist/server/runtime.js} +0 -0
  393. /package/{src/shared/constants.ts → dist/shared/constants.js} +0 -0
  394. /package/{src/shared/index.ts → dist/shared/index.js} +0 -0
@@ -0,0 +1,138 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { randomBytes } from "node:crypto";
4
+ import { query } from "@anthropic-ai/claude-agent-sdk";
5
+ import { broadcast } from "../ws/broadcast.js";
6
+ import { getProjectBySlug } from "../project/registry.js";
7
+ var activeLoops = new Map();
8
+ function readLoopFile(projectPath, filename) {
9
+ var loopsDir = join(projectPath, ".claude", "loops");
10
+ var filePath = join(loopsDir, filename);
11
+ if (!existsSync(filePath)) {
12
+ return null;
13
+ }
14
+ return readFileSync(filePath, "utf-8");
15
+ }
16
+ async function runIteration(loopId, prompt, cwd, iterationNum) {
17
+ var accumulated = "";
18
+ var stream = query({ prompt, options: { cwd, allowedTools: ["*"], permissionMode: "acceptEdits" } });
19
+ for await (var msg of stream) {
20
+ var typedMsg = msg;
21
+ if (typedMsg.type === "stream_event") {
22
+ var partial = typedMsg;
23
+ var evt = partial.event;
24
+ if (evt.type === "content_block_delta") {
25
+ var deltaEvt = evt;
26
+ if (deltaEvt.delta.type === "text_delta" && typeof deltaEvt.delta.text === "string") {
27
+ accumulated += deltaEvt.delta.text;
28
+ broadcast({ type: "loop:delta", loopId, iteration: iterationNum, text: deltaEvt.delta.text });
29
+ }
30
+ }
31
+ }
32
+ }
33
+ return accumulated;
34
+ }
35
+ async function runJudge(judgePrompt, iterationResult, cwd) {
36
+ var fullPrompt = `${judgePrompt}\n\n<iteration_result>\n${iterationResult}\n</iteration_result>\n\nRespond with PASS or FAIL on the first line, followed by a brief reason.`;
37
+ var accumulated = "";
38
+ var stream = query({ prompt: fullPrompt, options: { cwd, allowedTools: [], permissionMode: "acceptEdits" } });
39
+ for await (var msg of stream) {
40
+ var typedMsg = msg;
41
+ if (typedMsg.type === "stream_event") {
42
+ var partial = typedMsg;
43
+ var evt = partial.event;
44
+ if (evt.type === "content_block_delta") {
45
+ var deltaEvt = evt;
46
+ if (deltaEvt.delta.type === "text_delta" && typeof deltaEvt.delta.text === "string") {
47
+ accumulated += deltaEvt.delta.text;
48
+ }
49
+ }
50
+ }
51
+ }
52
+ var firstLine = accumulated.trim().split("\n")[0].toUpperCase();
53
+ var pass = firstLine.startsWith("PASS");
54
+ var reason = accumulated.trim().split("\n").slice(1).join("\n").trim() || accumulated.trim();
55
+ return { pass, reason };
56
+ }
57
+ export function startLoop(projectSlug) {
58
+ var project = getProjectBySlug(projectSlug);
59
+ if (!project) {
60
+ return null;
61
+ }
62
+ var prompt = readLoopFile(project.path, "PROMPT.md");
63
+ if (!prompt) {
64
+ return null;
65
+ }
66
+ var loopId = "loop_" + Date.now() + "_" + randomBytes(3).toString("hex");
67
+ var loopStatus = {
68
+ id: loopId,
69
+ projectSlug,
70
+ status: "running",
71
+ iteration: 0,
72
+ maxIterations: 20,
73
+ judgeReason: null,
74
+ startedAt: Date.now(),
75
+ finishedAt: null,
76
+ };
77
+ activeLoops.set(loopId, loopStatus);
78
+ broadcast({ type: "loop:started", loop: loopStatus });
79
+ void (async function () {
80
+ var judgePrompt = readLoopFile(project.path, "JUDGE.md");
81
+ for (var i = 1; i <= loopStatus.maxIterations; i++) {
82
+ var current = activeLoops.get(loopId);
83
+ if (!current || current.status === "stopped") {
84
+ break;
85
+ }
86
+ current.iteration = i;
87
+ activeLoops.set(loopId, current);
88
+ broadcast({ type: "loop:status_update", loop: { ...current } });
89
+ try {
90
+ var result = await runIteration(loopId, prompt, project.path, i);
91
+ if (judgePrompt) {
92
+ var judgment = await runJudge(judgePrompt, result, project.path);
93
+ current.judgeReason = judgment.reason;
94
+ activeLoops.set(loopId, current);
95
+ if (judgment.pass) {
96
+ current.status = "done";
97
+ current.finishedAt = Date.now();
98
+ activeLoops.set(loopId, current);
99
+ broadcast({ type: "loop:status_update", loop: { ...current } });
100
+ break;
101
+ }
102
+ }
103
+ }
104
+ catch (err) {
105
+ var errMsg = err instanceof Error ? err.message : String(err);
106
+ console.error(`[ralph-loop] Iteration ${i} error:`, errMsg);
107
+ current.status = "error";
108
+ current.judgeReason = errMsg;
109
+ current.finishedAt = Date.now();
110
+ activeLoops.set(loopId, current);
111
+ broadcast({ type: "loop:status_update", loop: { ...current } });
112
+ return;
113
+ }
114
+ }
115
+ var final = activeLoops.get(loopId);
116
+ if (final && final.status === "running") {
117
+ final.status = "done";
118
+ final.finishedAt = Date.now();
119
+ activeLoops.set(loopId, final);
120
+ broadcast({ type: "loop:status_update", loop: { ...final } });
121
+ }
122
+ })();
123
+ return loopStatus;
124
+ }
125
+ export function stopLoop(loopId) {
126
+ var loop = activeLoops.get(loopId);
127
+ if (!loop || loop.status !== "running") {
128
+ return false;
129
+ }
130
+ loop.status = "stopped";
131
+ loop.finishedAt = Date.now();
132
+ activeLoops.set(loopId, loop);
133
+ broadcast({ type: "loop:status_update", loop: { ...loop } });
134
+ return true;
135
+ }
136
+ export function getLoopStatus(loopId) {
137
+ return activeLoops.get(loopId) ?? null;
138
+ }
@@ -0,0 +1,260 @@
1
+ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { randomBytes } from "node:crypto";
4
+ import { getLatticeHome } from "../config.js";
5
+ import { broadcast } from "../ws/broadcast.js";
6
+ var schedulesFile = "";
7
+ var tasks = [];
8
+ var timerId = null;
9
+ var lastTriggeredMinute = {};
10
+ var CHECK_INTERVAL = 30 * 1000;
11
+ function getSchedulesPath() {
12
+ if (!schedulesFile) {
13
+ schedulesFile = join(getLatticeHome(), "schedules.json");
14
+ }
15
+ return schedulesFile;
16
+ }
17
+ function parseCronField(field, min, max) {
18
+ var values = [];
19
+ var parts = field.split(",");
20
+ for (var i = 0; i < parts.length; i++) {
21
+ var part = parts[i].trim();
22
+ if (part.indexOf("/") !== -1) {
23
+ var slashParts = part.split("/");
24
+ var step = parseInt(slashParts[1], 10);
25
+ var rangeStr = slashParts[0];
26
+ var rangeMin = min;
27
+ var rangeMax = max;
28
+ if (rangeStr !== "*") {
29
+ var rp = rangeStr.split("-");
30
+ rangeMin = parseInt(rp[0], 10);
31
+ rangeMax = rp.length > 1 ? parseInt(rp[1], 10) : rangeMin;
32
+ }
33
+ for (var v = rangeMin; v <= rangeMax; v += step) {
34
+ values.push(v);
35
+ }
36
+ continue;
37
+ }
38
+ if (part === "*") {
39
+ for (var v = min; v <= max; v++) {
40
+ values.push(v);
41
+ }
42
+ continue;
43
+ }
44
+ if (part.indexOf("-") !== -1) {
45
+ var rangeParts = part.split("-");
46
+ var from = parseInt(rangeParts[0], 10);
47
+ var to = parseInt(rangeParts[1], 10);
48
+ for (var v = from; v <= to; v++) {
49
+ values.push(v);
50
+ }
51
+ continue;
52
+ }
53
+ values.push(parseInt(part, 10));
54
+ }
55
+ return values;
56
+ }
57
+ function parseCron(expr) {
58
+ var fields = expr.trim().split(/\s+/);
59
+ if (fields.length !== 5) {
60
+ return null;
61
+ }
62
+ return {
63
+ minutes: parseCronField(fields[0], 0, 59),
64
+ hours: parseCronField(fields[1], 0, 23),
65
+ daysOfMonth: parseCronField(fields[2], 1, 31),
66
+ months: parseCronField(fields[3], 1, 12),
67
+ daysOfWeek: parseCronField(fields[4], 0, 6),
68
+ };
69
+ }
70
+ function cronMatches(parsed, date) {
71
+ return (parsed.minutes.indexOf(date.getMinutes()) !== -1 &&
72
+ parsed.hours.indexOf(date.getHours()) !== -1 &&
73
+ parsed.daysOfMonth.indexOf(date.getDate()) !== -1 &&
74
+ parsed.months.indexOf(date.getMonth() + 1) !== -1 &&
75
+ parsed.daysOfWeek.indexOf(date.getDay()) !== -1);
76
+ }
77
+ function nextRunTime(cronExpr, after) {
78
+ var parsed = parseCron(cronExpr);
79
+ if (!parsed) {
80
+ return null;
81
+ }
82
+ var d = new Date(after || Date.now());
83
+ d.setSeconds(0, 0);
84
+ d.setMinutes(d.getMinutes() + 1);
85
+ var limit = 366 * 24 * 60;
86
+ for (var i = 0; i < limit; i++) {
87
+ if (cronMatches(parsed, d)) {
88
+ return d.getTime();
89
+ }
90
+ d.setMinutes(d.getMinutes() + 1);
91
+ }
92
+ return null;
93
+ }
94
+ export function loadSchedules() {
95
+ var path = getSchedulesPath();
96
+ if (!existsSync(path)) {
97
+ tasks = [];
98
+ return;
99
+ }
100
+ try {
101
+ var raw = readFileSync(path, "utf-8");
102
+ var parsed = JSON.parse(raw);
103
+ tasks = parsed.tasks || [];
104
+ for (var i = 0; i < tasks.length; i++) {
105
+ var task = tasks[i];
106
+ if (task.enabled && task.cron) {
107
+ task.nextRunAt = nextRunTime(task.cron);
108
+ }
109
+ }
110
+ }
111
+ catch (err) {
112
+ console.error("[scheduler] Failed to load schedules:", err);
113
+ tasks = [];
114
+ }
115
+ }
116
+ function saveSchedules() {
117
+ var path = getSchedulesPath();
118
+ var dir = join(path, "..");
119
+ if (!existsSync(dir)) {
120
+ mkdirSync(dir, { recursive: true });
121
+ }
122
+ var tmp = path + ".tmp";
123
+ try {
124
+ writeFileSync(tmp, JSON.stringify({ tasks }, null, 2));
125
+ renameSync(tmp, path);
126
+ }
127
+ catch (err) {
128
+ console.error("[scheduler] Failed to save schedules:", err);
129
+ }
130
+ }
131
+ function tick() {
132
+ var now = Date.now();
133
+ var nowMinuteKey = Math.floor(now / 60000);
134
+ for (var i = 0; i < tasks.length; i++) {
135
+ var task = tasks[i];
136
+ if (!task.enabled || !task.nextRunAt) {
137
+ continue;
138
+ }
139
+ if (task.nextRunAt > now) {
140
+ continue;
141
+ }
142
+ var triggerKey = task.id + "_" + nowMinuteKey;
143
+ if (lastTriggeredMinute[triggerKey]) {
144
+ continue;
145
+ }
146
+ lastTriggeredMinute[triggerKey] = true;
147
+ var keys = Object.keys(lastTriggeredMinute);
148
+ for (var k = 0; k < keys.length; k++) {
149
+ var keyParts = keys[k].split("_");
150
+ var keyMinute = parseInt(keyParts[keyParts.length - 1], 10);
151
+ if (keyMinute < nowMinuteKey - 1) {
152
+ delete lastTriggeredMinute[keys[k]];
153
+ }
154
+ }
155
+ task.lastRunAt = now;
156
+ task.nextRunAt = nextRunTime(task.cron, now);
157
+ task.updatedAt = now;
158
+ saveSchedules();
159
+ console.log("[scheduler] Triggering task:", task.name, "(", task.id, ")");
160
+ broadcast({ type: "scheduler:tasks", tasks: tasks.slice() });
161
+ }
162
+ }
163
+ export function startScheduler() {
164
+ loadSchedules();
165
+ if (timerId) {
166
+ return;
167
+ }
168
+ timerId = setInterval(function () {
169
+ tick();
170
+ }, CHECK_INTERVAL);
171
+ tick();
172
+ }
173
+ export function stopScheduler() {
174
+ if (timerId) {
175
+ clearInterval(timerId);
176
+ timerId = null;
177
+ }
178
+ }
179
+ export function listTasks() {
180
+ return tasks.slice();
181
+ }
182
+ export function createTask(data) {
183
+ var parsed = parseCron(data.cron);
184
+ if (!parsed) {
185
+ return null;
186
+ }
187
+ var now = Date.now();
188
+ var task = {
189
+ id: "task_" + now + "_" + randomBytes(3).toString("hex"),
190
+ name: data.name,
191
+ prompt: data.prompt,
192
+ cron: data.cron,
193
+ enabled: true,
194
+ projectSlug: data.projectSlug,
195
+ createdAt: now,
196
+ updatedAt: now,
197
+ lastRunAt: null,
198
+ nextRunAt: nextRunTime(data.cron),
199
+ };
200
+ tasks.push(task);
201
+ saveSchedules();
202
+ return task;
203
+ }
204
+ export function updateTask(taskId, data) {
205
+ var task = null;
206
+ for (var i = 0; i < tasks.length; i++) {
207
+ if (tasks[i].id === taskId) {
208
+ task = tasks[i];
209
+ break;
210
+ }
211
+ }
212
+ if (!task)
213
+ return null;
214
+ if (data.cron && data.cron !== task.cron) {
215
+ var parsed = parseCron(data.cron);
216
+ if (!parsed)
217
+ return null;
218
+ task.cron = data.cron;
219
+ task.nextRunAt = task.enabled ? nextRunTime(data.cron) : null;
220
+ }
221
+ if (data.name !== undefined)
222
+ task.name = data.name;
223
+ if (data.prompt !== undefined)
224
+ task.prompt = data.prompt;
225
+ task.updatedAt = Date.now();
226
+ saveSchedules();
227
+ return task;
228
+ }
229
+ export function deleteTask(taskId) {
230
+ var idx = -1;
231
+ for (var i = 0; i < tasks.length; i++) {
232
+ if (tasks[i].id === taskId) {
233
+ idx = i;
234
+ break;
235
+ }
236
+ }
237
+ if (idx === -1) {
238
+ return false;
239
+ }
240
+ tasks.splice(idx, 1);
241
+ saveSchedules();
242
+ return true;
243
+ }
244
+ export function toggleTask(taskId) {
245
+ var task = null;
246
+ for (var i = 0; i < tasks.length; i++) {
247
+ if (tasks[i].id === taskId) {
248
+ task = tasks[i];
249
+ break;
250
+ }
251
+ }
252
+ if (!task) {
253
+ return null;
254
+ }
255
+ task.enabled = !task.enabled;
256
+ task.updatedAt = Date.now();
257
+ task.nextRunAt = task.enabled ? nextRunTime(task.cron) : null;
258
+ saveSchedules();
259
+ return task;
260
+ }
@@ -0,0 +1,99 @@
1
+ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { randomBytes } from "node:crypto";
4
+ import { getLatticeHome } from "../config.js";
5
+ var notesFile = "";
6
+ var notes = [];
7
+ function getNotesPath() {
8
+ if (!notesFile) {
9
+ notesFile = join(getLatticeHome(), "notes.jsonl");
10
+ }
11
+ return notesFile;
12
+ }
13
+ export function loadNotes() {
14
+ var path = getNotesPath();
15
+ if (!existsSync(path)) {
16
+ notes = [];
17
+ return;
18
+ }
19
+ try {
20
+ var raw = readFileSync(path, "utf-8");
21
+ var lines = raw.trim().split("\n");
22
+ notes = [];
23
+ for (var i = 0; i < lines.length; i++) {
24
+ var line = lines[i].trim();
25
+ if (!line) {
26
+ continue;
27
+ }
28
+ try {
29
+ var note = JSON.parse(line);
30
+ notes.push(note);
31
+ }
32
+ catch {
33
+ // skip malformed line
34
+ }
35
+ }
36
+ }
37
+ catch (err) {
38
+ console.error("[sticky-notes] Failed to load notes:", err);
39
+ notes = [];
40
+ }
41
+ }
42
+ function saveNotes() {
43
+ var path = getNotesPath();
44
+ var dir = join(path, "..");
45
+ if (!existsSync(dir)) {
46
+ mkdirSync(dir, { recursive: true });
47
+ }
48
+ var tmp = path + ".tmp";
49
+ try {
50
+ var lines = [];
51
+ for (var i = 0; i < notes.length; i++) {
52
+ lines.push(JSON.stringify(notes[i]));
53
+ }
54
+ writeFileSync(tmp, lines.join("\n") + (lines.length > 0 ? "\n" : ""));
55
+ renameSync(tmp, path);
56
+ }
57
+ catch (err) {
58
+ console.error("[sticky-notes] Failed to save notes:", err);
59
+ }
60
+ }
61
+ export function listNotes(projectSlug) {
62
+ if (!projectSlug)
63
+ return notes.slice();
64
+ return notes.filter(function (n) { return n.projectSlug === projectSlug; });
65
+ }
66
+ export function createNote(content, projectSlug) {
67
+ var now = Date.now();
68
+ var note = {
69
+ id: "note_" + now + "_" + randomBytes(3).toString("hex"),
70
+ content,
71
+ createdAt: now,
72
+ updatedAt: now,
73
+ projectSlug,
74
+ };
75
+ notes.push(note);
76
+ saveNotes();
77
+ return note;
78
+ }
79
+ export function updateNote(id, content) {
80
+ for (var i = 0; i < notes.length; i++) {
81
+ if (notes[i].id === id) {
82
+ notes[i].content = content;
83
+ notes[i].updatedAt = Date.now();
84
+ saveNotes();
85
+ return notes[i];
86
+ }
87
+ }
88
+ return null;
89
+ }
90
+ export function deleteNote(id) {
91
+ for (var i = 0; i < notes.length; i++) {
92
+ if (notes[i].id === id) {
93
+ notes.splice(i, 1);
94
+ saveNotes();
95
+ return true;
96
+ }
97
+ }
98
+ return false;
99
+ }
@@ -0,0 +1,28 @@
1
+ import { registerHandler } from "../ws/router.js";
2
+ import { sendTo } from "../ws/broadcast.js";
3
+ import { streamAnalyticsSections } from "../analytics/engine.js";
4
+ registerHandler("analytics", function (clientId, message) {
5
+ if (message.type === "analytics:request") {
6
+ var msg = message;
7
+ streamAnalyticsSections(msg.scope, msg.period, msg.projectSlug, msg.sessionId, msg.forceRefresh, function (sectionName, sectionData) {
8
+ sendTo(clientId, {
9
+ type: "analytics:section",
10
+ requestId: msg.requestId,
11
+ section: sectionName,
12
+ data: sectionData,
13
+ });
14
+ }).then(function () {
15
+ sendTo(clientId, {
16
+ type: "analytics:complete",
17
+ requestId: msg.requestId,
18
+ });
19
+ }).catch(function (err) {
20
+ sendTo(clientId, {
21
+ type: "analytics:error",
22
+ scope: msg.scope,
23
+ message: err instanceof Error ? err.message : "Analytics computation failed",
24
+ });
25
+ });
26
+ return;
27
+ }
28
+ });
@@ -0,0 +1,158 @@
1
+ import { registerHandler } from "../ws/router.js";
2
+ import { sendTo } from "../ws/broadcast.js";
3
+ var MAX_ATTACHMENT_SIZE = 10 * 1024 * 1024;
4
+ var stores = new Map();
5
+ var completed = new Map();
6
+ var TTL_MS = 5 * 60 * 1000;
7
+ var CLEANUP_INTERVAL_MS = 60 * 1000;
8
+ function getClientStore(clientId) {
9
+ var store = stores.get(clientId);
10
+ if (!store) {
11
+ store = new Map();
12
+ stores.set(clientId, store);
13
+ }
14
+ return store;
15
+ }
16
+ function getClientCompleted(clientId) {
17
+ var store = completed.get(clientId);
18
+ if (!store) {
19
+ store = new Map();
20
+ completed.set(clientId, store);
21
+ }
22
+ return store;
23
+ }
24
+ registerHandler("attachment", function (clientId, message) {
25
+ if (message.type === "attachment:chunk") {
26
+ var msg = message;
27
+ var store = getClientStore(clientId);
28
+ var pending = store.get(msg.attachmentId);
29
+ if (!pending) {
30
+ pending = {
31
+ chunks: new Map(),
32
+ totalChunks: msg.totalChunks,
33
+ receivedCount: 0,
34
+ totalBytes: 0,
35
+ createdAt: Date.now(),
36
+ };
37
+ store.set(msg.attachmentId, pending);
38
+ }
39
+ if (pending.chunks.has(msg.chunkIndex)) {
40
+ sendTo(clientId, {
41
+ type: "attachment:error",
42
+ attachmentId: msg.attachmentId,
43
+ error: "Duplicate chunk index: " + msg.chunkIndex,
44
+ });
45
+ return;
46
+ }
47
+ var chunkBuffer = Buffer.from(msg.data, "base64");
48
+ if (pending.totalBytes + chunkBuffer.length > MAX_ATTACHMENT_SIZE) {
49
+ store.delete(msg.attachmentId);
50
+ sendTo(clientId, {
51
+ type: "attachment:error",
52
+ attachmentId: msg.attachmentId,
53
+ error: "Attachment exceeds maximum size of " + (MAX_ATTACHMENT_SIZE / 1024 / 1024) + "MB",
54
+ });
55
+ return;
56
+ }
57
+ pending.chunks.set(msg.chunkIndex, chunkBuffer);
58
+ pending.receivedCount++;
59
+ pending.totalBytes += chunkBuffer.length;
60
+ sendTo(clientId, {
61
+ type: "attachment:progress",
62
+ attachmentId: msg.attachmentId,
63
+ received: pending.receivedCount,
64
+ total: pending.totalChunks,
65
+ });
66
+ return;
67
+ }
68
+ if (message.type === "attachment:complete") {
69
+ var completeMsg = message;
70
+ var completeStore = getClientStore(clientId);
71
+ var completePending = completeStore.get(completeMsg.attachmentId);
72
+ if (!completePending) {
73
+ sendTo(clientId, {
74
+ type: "attachment:error",
75
+ attachmentId: completeMsg.attachmentId,
76
+ error: "No chunks received for this attachment",
77
+ });
78
+ return;
79
+ }
80
+ if (completePending.receivedCount !== completePending.totalChunks) {
81
+ sendTo(clientId, {
82
+ type: "attachment:error",
83
+ attachmentId: completeMsg.attachmentId,
84
+ error: "Missing chunks: received " + completePending.receivedCount + " of " + completePending.totalChunks,
85
+ });
86
+ return;
87
+ }
88
+ var buffers = [];
89
+ for (var ci = 0; ci < completePending.totalChunks; ci++) {
90
+ var chunk = completePending.chunks.get(ci);
91
+ if (!chunk) {
92
+ sendTo(clientId, {
93
+ type: "attachment:error",
94
+ attachmentId: completeMsg.attachmentId,
95
+ error: "Missing chunk at index " + ci,
96
+ });
97
+ return;
98
+ }
99
+ buffers.push(chunk);
100
+ }
101
+ var assembled = Buffer.concat(buffers);
102
+ var isText = completeMsg.attachmentType === "paste" || isTextMimeType(completeMsg.mimeType);
103
+ var content = isText ? assembled.toString("utf-8") : assembled.toString("base64");
104
+ var attachment = {
105
+ type: completeMsg.attachmentType,
106
+ name: completeMsg.name,
107
+ content,
108
+ mimeType: completeMsg.mimeType,
109
+ size: completeMsg.size,
110
+ lineCount: completeMsg.lineCount,
111
+ };
112
+ var finishedStore = getClientCompleted(clientId);
113
+ finishedStore.set(completeMsg.attachmentId, attachment);
114
+ completeStore.delete(completeMsg.attachmentId);
115
+ return;
116
+ }
117
+ });
118
+ function isTextMimeType(mime) {
119
+ if (mime.startsWith("text/"))
120
+ return true;
121
+ var textTypes = [
122
+ "application/json",
123
+ "application/xml",
124
+ "application/javascript",
125
+ "application/typescript",
126
+ "application/x-yaml",
127
+ "application/yaml",
128
+ "image/svg+xml",
129
+ ];
130
+ return textTypes.indexOf(mime) !== -1;
131
+ }
132
+ export function getAttachments(clientId, ids) {
133
+ var store = getClientCompleted(clientId);
134
+ var result = [];
135
+ for (var i = 0; i < ids.length; i++) {
136
+ var att = store.get(ids[i]);
137
+ if (att) {
138
+ result.push(att);
139
+ store.delete(ids[i]);
140
+ }
141
+ }
142
+ return result;
143
+ }
144
+ export function cleanupClient(clientId) {
145
+ stores.delete(clientId);
146
+ completed.delete(clientId);
147
+ }
148
+ var ttlCleanupInterval = setInterval(function () {
149
+ var now = Date.now();
150
+ stores.forEach(function (store) {
151
+ store.forEach(function (pending, id) {
152
+ if (now - pending.createdAt > TTL_MS) {
153
+ store.delete(id);
154
+ }
155
+ });
156
+ });
157
+ }, CLEANUP_INTERVAL_MS);
158
+ ttlCleanupInterval.unref();