moi-computer 0.11.0 → 0.11.1-dev.be1ed10

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 (362) hide show
  1. package/README.md +2 -2
  2. package/client/AGENTS.md +2 -2
  3. package/client/app/AppRouter.tsx +2 -2
  4. package/client/app/routes/WorkspaceRoute.tsx +7 -9
  5. package/client/app/shell/SidebarLayout.tsx +18 -15
  6. package/client/components/shared/BottomPanel.tsx +26 -14
  7. package/client/components/shared/PanelHeader.tsx +1 -1
  8. package/client/components/shared/ReorderableList.tsx +7 -2
  9. package/client/components/shared/WorkspaceIcon.tsx +92 -0
  10. package/client/components/ui/alert-dialog.tsx +1 -0
  11. package/client/components/ui/button.tsx +1 -53
  12. package/client/components/ui/checkbox.tsx +1 -0
  13. package/client/components/ui/collapsible.tsx +1 -15
  14. package/client/components/ui/dialog.tsx +1 -58
  15. package/client/components/ui/dropdown-menu.tsx +1 -254
  16. package/client/components/ui/hover-card.tsx +1 -44
  17. package/client/components/ui/inline-input.tsx +84 -0
  18. package/client/components/ui/input.tsx +1 -21
  19. package/client/components/ui/popover.tsx +1 -88
  20. package/client/components/ui/resizable.tsx +1 -40
  21. package/client/components/ui/skeleton.tsx +1 -13
  22. package/client/components/ui/slider.tsx +1 -70
  23. package/client/components/ui/spinner.tsx +1 -18
  24. package/client/components/ui/switch.tsx +1 -23
  25. package/client/components/ui/tabs.tsx +1 -0
  26. package/client/components/ui/textarea.tsx +1 -18
  27. package/client/components/ui/toast.tsx +2 -2
  28. package/client/components/ui/tooltip.tsx +1 -51
  29. package/client/features/applets/AppletMount.tsx +1 -1
  30. package/client/features/applets/applet-cache.ts +3 -3
  31. package/client/features/applets/applet-runtime.ts +147 -108
  32. package/client/features/applets/applet-styles.ts +2 -2
  33. package/client/features/applets/applet-thumbnail.ts +6 -8
  34. package/client/features/applets/useApplet.ts +10 -9
  35. package/client/features/chat/ChatPanel.tsx +24 -15
  36. package/client/features/chat/ChatPopup.tsx +9 -5
  37. package/client/features/chat/applet-chat-intents.ts +170 -0
  38. package/client/features/chat/chat-send.ts +116 -64
  39. package/client/features/chat/chat-store.ts +51 -62
  40. package/client/features/chat/composer/ChatComposer.tsx +43 -128
  41. package/client/features/chat/composer/ModelPicker.tsx +47 -60
  42. package/client/features/chat/composer/attachments/AttachmentChip.tsx +99 -0
  43. package/client/features/chat/composer/attachments/DrawingAttachmentChip.tsx +37 -0
  44. package/client/features/chat/composer/attachments/FileAttachmentChip.tsx +22 -0
  45. package/client/features/chat/composer/attachments/TextAttachmentChip.tsx +11 -0
  46. package/client/features/chat/composer/attachments/draft-attachments.ts +168 -0
  47. package/client/features/chat/composer/attachments/types.ts +25 -0
  48. package/client/features/chat/composer/attachments/uploads.ts +26 -0
  49. package/client/features/chat/composer/banners/ErrorBanner.tsx +20 -12
  50. package/client/features/chat/composer/model-order.ts +15 -0
  51. package/client/features/chat/composer/useWorkspaceComposerState.tsx +15 -7
  52. package/client/features/chat/{chat-connection.ts → connection/chat-connection.ts} +1 -1
  53. package/client/features/chat/{chat-frames.ts → connection/chat-frames.ts} +10 -8
  54. package/client/features/chat/{ChatEmptyState.tsx → messages/ChatEmptyState.tsx} +16 -11
  55. package/client/features/chat/{MarkdownContent.tsx → messages/MarkdownContent.tsx} +16 -1
  56. package/client/features/chat/{TurnView.tsx → messages/TurnView.tsx} +27 -19
  57. package/client/features/chat/{group-turns.ts → messages/group-turns.ts} +12 -0
  58. package/client/features/chat/{interleave-notices.ts → messages/interleave-notices.ts} +7 -11
  59. package/client/features/chat/{tool-group → messages/tool-group}/SubagentCard.tsx +1 -1
  60. package/client/features/chat/{tool-group → messages/tool-group}/TimelineRow.tsx +2 -2
  61. package/client/features/chat/{tool-group → messages/tool-group}/ToolCallGroup.tsx +2 -5
  62. package/client/features/chat/{tool-group → messages/tool-group}/format/codex.ts +4 -1
  63. package/client/features/chat/{ChatSelector.tsx → sessions/ChatSelector.tsx} +3 -3
  64. package/client/features/chat/{api.ts → sessions/api.ts} +5 -14
  65. package/client/features/chat/sessions/session-view.ts +53 -0
  66. package/client/features/chat/useChat.ts +42 -24
  67. package/client/features/dev/ChatStatesPage.tsx +8 -7
  68. package/client/features/dev/DevIndexPage.tsx +5 -0
  69. package/client/features/dev/DevRoutes.tsx +2 -0
  70. package/client/features/dev/HarnessDebugPage.tsx +11 -8
  71. package/client/features/dev/ToolCallsPage.tsx +1 -1
  72. package/client/features/dev/UiComponentPreviews.tsx +855 -0
  73. package/client/features/dev/UiComponentsPage.tsx +60 -0
  74. package/client/features/dev/chat-states-fixtures.ts +13 -2
  75. package/client/features/drawings/useChatAnnotation.ts +17 -17
  76. package/client/features/drawings/useDrawingLayer.ts +7 -9
  77. package/client/features/drawings/useViewBuilderSketch.ts +18 -15
  78. package/client/features/home/HomePage.tsx +8 -7
  79. package/client/features/home/WorkspacePreview.tsx +2 -2
  80. package/client/features/home/workspace-presentation.tsx +1 -11
  81. package/client/features/home/workspace-setup/DemoDialog.tsx +3 -2
  82. package/client/features/home/workspace-setup/ImportWorkspaceDialog.tsx +5 -8
  83. package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +2 -4
  84. package/client/features/home/workspace-setup/WorkspaceDialogContent.tsx +7 -20
  85. package/client/features/overview/HiddenPanel.tsx +109 -0
  86. package/client/features/overview/Overview.tsx +302 -0
  87. package/client/features/overview/WidgetCanvas.tsx +164 -0
  88. package/client/features/{widgets → overview}/WidgetFrame.tsx +25 -17
  89. package/client/features/overview/WorkspaceName.tsx +60 -0
  90. package/client/features/overview/api.ts +30 -0
  91. package/client/features/overview/default/ViewsWidget.tsx +252 -0
  92. package/client/features/overview/default/registry.tsx +36 -0
  93. package/client/features/{widgets → overview}/grid.ts +36 -0
  94. package/client/features/overview/useGridReconcile.ts +94 -0
  95. package/client/features/scratchpad/Scratchpad.tsx +7 -8
  96. package/client/features/scratchpad/ScratchpadControls.tsx +0 -1
  97. package/client/features/scratchpad/useScratchpadSnapshot.tsx +23 -13
  98. package/client/features/settings/GeneralSettings.tsx +55 -58
  99. package/client/features/settings/SettingsLayout.tsx +2 -2
  100. package/client/features/settings/WorkspaceIconPicker.tsx +318 -0
  101. package/client/features/settings/WorkspaceSettingsDialog.tsx +65 -0
  102. package/client/features/settings/api.ts +48 -24
  103. package/client/features/views/ViewBuilder.tsx +5 -4
  104. package/client/features/views/ViewManager.tsx +25 -22
  105. package/client/features/views/api.ts +36 -2
  106. package/client/features/views/useViewBuilderActions.ts +8 -5
  107. package/client/features/views/useViewBuilderDrafts.ts +23 -21
  108. package/client/features/views/view-presentation.ts +13 -0
  109. package/client/features/workspace/{CustomizePanel.tsx → ThemePanel.tsx} +26 -31
  110. package/client/features/workspace/UnavailablePage.tsx +21 -0
  111. package/client/features/workspace/WorkspaceLayoutContext.tsx +4 -7
  112. package/client/features/workspace/WorkspaceScreen.tsx +210 -162
  113. package/client/features/workspace/WorkspaceSplitLayout.tsx +7 -2
  114. package/client/features/workspace/WorkspaceTabs.tsx +2 -0
  115. package/client/features/workspace/api.ts +2 -30
  116. package/client/features/workspace/moi-context.ts +8 -9
  117. package/client/features/workspace/tab-resolution.ts +10 -33
  118. package/client/features/workspace/useWorkspaceNavigation.ts +164 -101
  119. package/client/index.css +23 -30
  120. package/client/lib/app-icon-registry.ts +2 -0
  121. package/client/lib/use-latest-ref.ts +11 -0
  122. package/client/main.tsx +1 -1
  123. package/client/runtime/useWorkspaceEvents.ts +59 -14
  124. package/client/theme.css +5 -5
  125. package/dist/{chunk-tqd3pkg8.css → chunk-60q353jq.css} +1 -1
  126. package/dist/chunk-691pqsj6.js +2 -0
  127. package/dist/chunk-7a5nm4k9.css +1 -0
  128. package/dist/chunk-amb8y04y.js +1 -0
  129. package/dist/chunk-cf3pgy7j.js +546 -0
  130. package/dist/{chunk-11cab5dq.css → chunk-cq2r11fg.css} +1 -1
  131. package/dist/chunk-mzrgr577.js +5 -0
  132. package/dist/chunk-nf2wkvf9.js +14 -0
  133. package/dist/chunk-q6a0g26x.js +1 -0
  134. package/dist/chunk-twgdemkc.js +74 -0
  135. package/dist/chunk-x90k0f5c.js +2 -0
  136. package/dist/chunk-yq00csvd.js +2 -0
  137. package/dist/index.html +1 -1
  138. package/lib/app-icons.ts +1 -0
  139. package/lib/applet-selector.ts +24 -0
  140. package/lib/chat-title.ts +6 -1
  141. package/lib/default-widgets.ts +32 -0
  142. package/lib/format.ts +67 -7
  143. package/lib/message-attachments.ts +40 -0
  144. package/lib/moi-attachments.ts +204 -0
  145. package/lib/moi-context.ts +20 -35
  146. package/lib/navigation.ts +84 -0
  147. package/lib/themes.ts +6 -6
  148. package/lib/types.ts +91 -34
  149. package/lib/workspace-icon.ts +20 -0
  150. package/lib/workspace-layout.ts +22 -2
  151. package/lib/workspace-tabs.ts +9 -33
  152. package/package.json +42 -32
  153. package/registry.json +656 -0
  154. package/server/AGENTS.md +2 -0
  155. package/server/agent.ts +1 -1
  156. package/server/api.ts +139 -66
  157. package/server/applet-typecheck.ts +95 -0
  158. package/server/applets/applet-css.ts +55 -0
  159. package/server/{bundler → applets}/build-applet.ts +13 -242
  160. package/server/applets/build-worker.ts +178 -0
  161. package/server/applets/config.ts +226 -0
  162. package/server/applets/dependencies.ts +206 -0
  163. package/server/{applets.ts → applets/index.ts} +44 -189
  164. package/server/applets/runtime/base.ts +4 -0
  165. package/server/applets/runtime/moi.ts +42 -0
  166. package/server/applets/runtime/rpc.ts +17 -0
  167. package/server/applets/view-source.ts +67 -0
  168. package/server/attachment-message.ts +95 -0
  169. package/server/cli-ui-components.ts +28 -33
  170. package/server/cli.ts +169 -108
  171. package/server/control.ts +63 -42
  172. package/server/data-dir.ts +1 -1
  173. package/server/harness/README.md +45 -50
  174. package/server/harness/acp/NOTES.md +426 -0
  175. package/server/harness/acp/adapter.ts +7 -21
  176. package/server/harness/acp/discovery.ts +27 -30
  177. package/server/harness/acp/model-state.ts +57 -0
  178. package/server/harness/acp/session.ts +49 -56
  179. package/server/harness/claude-code/NOTES.md +54 -13
  180. package/server/harness/claude-code/adapter.ts +8 -25
  181. package/server/harness/claude-code/cli.ts +40 -0
  182. package/server/harness/claude-code/index.ts +13 -5
  183. package/server/harness/claude-code/models.ts +72 -19
  184. package/server/harness/claude-code/session.ts +447 -343
  185. package/server/harness/claude-code/sessions.ts +9 -4
  186. package/server/harness/codex/NOTES.md +222 -350
  187. package/server/harness/codex/adapter.ts +102 -52
  188. package/server/harness/codex/auth.ts +1 -3
  189. package/server/harness/codex/client.ts +169 -249
  190. package/server/harness/codex/discovery.ts +9 -17
  191. package/server/harness/codex/index.ts +3 -1
  192. package/server/harness/codex/pagination.ts +24 -0
  193. package/server/harness/codex/permissions.ts +32 -8
  194. package/server/harness/codex/probe.ts +10 -13
  195. package/server/harness/codex/session.ts +567 -181
  196. package/server/harness/codex/transport.ts +184 -0
  197. package/server/harness/debug.ts +1 -1
  198. package/server/harness/hermes/NOTES.md +19 -1
  199. package/server/harness/hermes/discovery.ts +20 -0
  200. package/server/harness/hermes/index.ts +13 -0
  201. package/server/harness/hermes/models.ts +28 -8
  202. package/server/harness/openclaw/NOTES.md +1 -1
  203. package/server/harness/openclaw/adapter.ts +22 -4
  204. package/server/harness/openclaw/gateway.ts +5 -3
  205. package/server/harness/openclaw/session.ts +27 -27
  206. package/server/harness/types.ts +9 -5
  207. package/server/layout.ts +9 -14
  208. package/server/moi-scaffold.ts +22 -14
  209. package/server/navigation-relay.ts +110 -0
  210. package/server/preview.ts +3 -1
  211. package/server/registry.ts +71 -41
  212. package/server/scratchpad-executor.ts +79 -56
  213. package/server/scratchpad-shape-defaults.ts +82 -0
  214. package/server/selected-session.ts +24 -4
  215. package/server/skill-update.ts +5 -3
  216. package/server/skill-version.ts +4 -7
  217. package/server/skills-template.ts +48 -9
  218. package/server/tabs.ts +19 -33
  219. package/server/tldraw-package.d.ts +4 -0
  220. package/server/ui-components.ts +101 -434
  221. package/server/uploads.ts +0 -0
  222. package/server/view-builders.ts +20 -2
  223. package/server/views.ts +126 -6
  224. package/server/web.ts +46 -13
  225. package/server/widgets.ts +12 -5
  226. package/server/workspace-config.ts +13 -9
  227. package/server/workspace-env.ts +3 -2
  228. package/tsconfig.json +0 -1
  229. package/ui-components/accordion.tsx +71 -0
  230. package/ui-components/alert-dialog.tsx +165 -0
  231. package/ui-components/alert.tsx +68 -0
  232. package/ui-components/attachment.tsx +195 -0
  233. package/ui-components/avatar.tsx +90 -0
  234. package/ui-components/badge.tsx +49 -0
  235. package/ui-components/button-group.tsx +78 -0
  236. package/ui-components/button.tsx +55 -0
  237. package/ui-components/calendar.tsx +180 -0
  238. package/ui-components/card.tsx +84 -0
  239. package/ui-components/carousel.tsx +235 -0
  240. package/ui-components/chart.tsx +338 -0
  241. package/ui-components/checkbox.tsx +28 -0
  242. package/ui-components/collapsible.tsx +15 -0
  243. package/ui-components/combobox.tsx +267 -0
  244. package/ui-components/context-menu.tsx +244 -0
  245. package/ui-components/dialog.tsx +138 -0
  246. package/ui-components/docs/accordion.md +463 -0
  247. package/ui-components/docs/alert-dialog.md +481 -0
  248. package/ui-components/docs/alert.md +301 -0
  249. package/ui-components/docs/attachment.md +689 -0
  250. package/ui-components/docs/avatar.md +495 -0
  251. package/ui-components/docs/badge.md +258 -0
  252. package/ui-components/docs/button-group.md +879 -0
  253. package/ui-components/docs/button.md +26 -0
  254. package/ui-components/docs/calendar.md +862 -0
  255. package/ui-components/docs/card.md +265 -0
  256. package/ui-components/docs/carousel.md +627 -0
  257. package/ui-components/docs/chart.md +1256 -0
  258. package/ui-components/docs/checkbox.md +477 -0
  259. package/ui-components/docs/collapsible.md +446 -0
  260. package/ui-components/docs/combobox.md +1003 -0
  261. package/ui-components/docs/context-menu.md +860 -0
  262. package/ui-components/docs/data-table.md +1580 -0
  263. package/ui-components/docs/date-picker.md +614 -0
  264. package/ui-components/docs/dialog.md +414 -0
  265. package/ui-components/docs/drawer.md +51 -0
  266. package/ui-components/docs/dropdown-menu.md +1000 -0
  267. package/ui-components/docs/field.md +1192 -0
  268. package/ui-components/docs/hover-card.md +275 -0
  269. package/ui-components/docs/input-group.md +866 -0
  270. package/ui-components/docs/input.md +456 -0
  271. package/ui-components/docs/kbd.md +191 -0
  272. package/ui-components/docs/label.md +295 -0
  273. package/ui-components/docs/pagination.md +416 -0
  274. package/ui-components/docs/popover.md +348 -0
  275. package/ui-components/docs/progress.md +214 -0
  276. package/ui-components/docs/radio-group.md +389 -0
  277. package/ui-components/docs/resizable.md +265 -0
  278. package/ui-components/docs/select.md +616 -0
  279. package/ui-components/docs/separator.md +216 -0
  280. package/ui-components/docs/skeleton.md +205 -0
  281. package/ui-components/docs/slider.md +226 -0
  282. package/ui-components/docs/spinner.md +332 -0
  283. package/ui-components/docs/switch.md +236 -0
  284. package/ui-components/docs/table.md +551 -0
  285. package/ui-components/docs/tabs.md +379 -0
  286. package/ui-components/docs/textarea.md +187 -0
  287. package/ui-components/docs/toggle-group.md +370 -0
  288. package/ui-components/docs/toggle.md +91 -0
  289. package/ui-components/docs/tooltip.md +290 -0
  290. package/ui-components/drawer.tsx +213 -0
  291. package/ui-components/dropdown-menu.tsx +263 -0
  292. package/ui-components/field.tsx +224 -0
  293. package/ui-components/hover-card.tsx +46 -0
  294. package/ui-components/input-group.tsx +146 -0
  295. package/ui-components/input.tsx +20 -0
  296. package/ui-components/kbd.tsx +32 -0
  297. package/ui-components/label.tsx +17 -0
  298. package/ui-components/pagination.tsx +124 -0
  299. package/ui-components/popover.tsx +81 -0
  300. package/ui-components/progress.tsx +63 -0
  301. package/ui-components/radio-group.tsx +38 -0
  302. package/ui-components/resizable.tsx +40 -0
  303. package/ui-components/scoped-portal.tsx +31 -0
  304. package/ui-components/select.tsx +195 -0
  305. package/ui-components/separator.tsx +18 -0
  306. package/ui-components/skeleton.tsx +15 -0
  307. package/ui-components/slider.tsx +75 -0
  308. package/ui-components/spinner.tsx +20 -0
  309. package/ui-components/switch.tsx +27 -0
  310. package/ui-components/table.tsx +86 -0
  311. package/ui-components/tabs.tsx +75 -0
  312. package/ui-components/textarea.tsx +17 -0
  313. package/ui-components/toggle-group.tsx +85 -0
  314. package/ui-components/toggle.tsx +42 -0
  315. package/ui-components/tooltip.tsx +61 -0
  316. package/ui-components/utils.ts +8 -0
  317. package/workspace/.claude/skills/moi-workspace/SKILL.md +295 -248
  318. package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +100 -152
  319. package/workspace/.claude/skills/moi-workspace/references/INTENTS.md +156 -0
  320. package/workspace/.claude/skills/moi-workspace/references/UI-COMPONENTS.md +67 -203
  321. package/client/features/chat/attachment-staging.ts +0 -153
  322. package/client/features/chat/uploads.ts +0 -18
  323. package/client/features/chat/useAppletChatMessage.ts +0 -68
  324. package/client/features/settings/IconPicker.tsx +0 -442
  325. package/client/features/settings/WorkspaceSettings.tsx +0 -92
  326. package/client/features/settings/render-icon.ts +0 -173
  327. package/client/features/widgets/HiddenPanel.tsx +0 -80
  328. package/client/features/widgets/WidgetGrid.tsx +0 -123
  329. package/client/features/widgets/Widgets.tsx +0 -264
  330. package/client/features/widgets/useGridReconcile.ts +0 -73
  331. package/dist/chunk-104m57qw.js +0 -2
  332. package/dist/chunk-59zf0m6n.js +0 -1
  333. package/dist/chunk-bj3akjs2.js +0 -1
  334. package/dist/chunk-c9pjqx9m.js +0 -14
  335. package/dist/chunk-j2w2vak4.js +0 -546
  336. package/dist/chunk-k2r9c95m.js +0 -10
  337. package/dist/chunk-kmbxhgwv.js +0 -1
  338. package/dist/chunk-p1yqa71k.js +0 -83
  339. package/dist/chunk-pcnahct1.js +0 -5
  340. package/dist/chunk-r5xrenjy.css +0 -1
  341. package/dist/chunk-tny85yt2.js +0 -2
  342. package/dist/chunk-v7wr1df4.js +0 -2
  343. package/server/bundler/applet-css.ts +0 -155
  344. /package/client/features/chat/{ChatPromptBubbles.tsx → messages/ChatPromptBubbles.tsx} +0 -0
  345. /package/client/features/chat/{ShimmerText.tsx → messages/ShimmerText.tsx} +0 -0
  346. /package/client/features/chat/{preview-turn.ts → messages/preview-turn.ts} +0 -0
  347. /package/client/features/chat/{tool-group → messages/tool-group}/CodeBlock.tsx +0 -0
  348. /package/client/features/chat/{tool-group → messages/tool-group}/Collapse.tsx +0 -0
  349. /package/client/features/chat/{tool-group → messages/tool-group}/ReadImagePreview.tsx +0 -0
  350. /package/client/features/chat/{tool-group → messages/tool-group}/ToolOutput.tsx +0 -0
  351. /package/client/features/chat/{tool-group → messages/tool-group}/detect.ts +0 -0
  352. /package/client/features/chat/{tool-group → messages/tool-group}/fixtures.ts +0 -0
  353. /package/client/features/chat/{tool-group → messages/tool-group}/format/claude.ts +0 -0
  354. /package/client/features/chat/{tool-group → messages/tool-group}/format/hermes.ts +0 -0
  355. /package/client/features/chat/{tool-group → messages/tool-group}/format/index.ts +0 -0
  356. /package/client/features/chat/{tool-group → messages/tool-group}/format/mcp.ts +0 -0
  357. /package/client/features/chat/{tool-group → messages/tool-group}/format/openclaw.ts +0 -0
  358. /package/client/features/chat/{tool-group → messages/tool-group}/format/shared.ts +0 -0
  359. /package/client/features/chat/{tool-group → messages/tool-group}/format/shell.ts +0 -0
  360. /package/client/features/chat/{tool-group → messages/tool-group}/index.ts +0 -0
  361. /package/client/features/chat/{useStickToBottom.ts → messages/useStickToBottom.ts} +0 -0
  362. /package/client/features/chat/{useSelectedSession.ts → sessions/useSelectedSession.ts} +0 -0
@@ -15,15 +15,15 @@
15
15
  // workspace-agnostic.
16
16
  import { realpathSync, statSync } from 'node:fs'
17
17
  import { mkdir, readdir, rm } from 'node:fs/promises'
18
- import { dirname, join, resolve, sep } from 'path'
18
+ import { join, resolve, sep } from 'path'
19
19
 
20
- import {
21
- APPLET_API_BASE_SENTINEL,
22
- type AppletKind,
23
- buildApplet,
24
- scanRelativeImports
25
- } from './bundler/build-applet'
26
- import { pruneAppletThumbnails } from './thumbnails'
20
+ import { analyzeDependencies, resolveSource, scanSources } from './dependencies'
21
+ import type { AppletKind } from './build-applet'
22
+ import { buildAppletsInChild } from './build-worker'
23
+ import { APPLET_API_BASE_SENTINEL } from './runtime/base'
24
+ import { pruneAppletThumbnails } from '../thumbnails'
25
+
26
+ export { scanSources } from './dependencies'
27
27
 
28
28
  export type AppletPaths = {
29
29
  moiRoot: string
@@ -55,161 +55,13 @@ export function getAppletRevision(
55
55
  }
56
56
  }
57
57
 
58
- // Source module names in a kind's directory: `*.tsx`/`*.ts` minus `.server.ts`
59
- // and minus `_`-prefixed files (`_utils.tsx`) — those are shared modules for
60
- // entries to import, never entry points themselves.
61
- export async function scanSources(sourceDir: string): Promise<string[]> {
62
- try {
63
- const entries = await readdir(sourceDir)
64
- return entries
65
- .filter(f => /\.(tsx|ts)$/.test(f) && !f.startsWith('_') && !f.endsWith('.server.ts'))
66
- .map(f => f.replace(/\.tsx?$/, ''))
67
- } catch {
68
- return []
69
- }
70
- }
71
-
72
- async function resolveSource(sourceDir: string, name: string): Promise<string | null> {
73
- for (const ext of ['.tsx', '.ts']) {
74
- const path = join(sourceDir, `${name}${ext}`)
75
- if (await Bun.file(path).exists()) return path
76
- }
77
- return null
78
- }
79
-
80
- // Backstop for pathological graphs: an applet wiring more distinct files than
81
- // this is reported stale without walking further — stale-but-rebuilt is the
82
- // safe degradation, and the cap keeps the per-bundle check bounded no matter
83
- // what the imports look like. Counts every input, images and JSON included, so
84
- // it sits well above what an asset-heavy applet reaches (the walk never enters
85
- // node_modules); hitting it means something is off anyway.
86
- const MAX_GRAPH_FILES = 256
87
-
88
- // Files the walk keeps descending through — anything Bun treats as a module
89
- // (`.ts`, `.mjs`, `.cts`, …). Everything else (`.json`, `.css`, images) is a
90
- // leaf.
91
- const MODULE_FILE_RE = /\.[mc]?[jt]sx?$/
92
- // Which transpiler loader lexes a module's imports. Only `.ts`/`.mts`/`.cts`
93
- // take the `ts` loader: angle-bracket casts (`<string>x`) parse there and are
94
- // JSX everywhere else. `.js`/`.mjs`/`.cjs` go through `tsx`, which accepts both
95
- // plain JS and the JSX some of them contain.
96
- const TS_ONLY_FILE_RE = /\.[mc]?ts$/
97
-
98
- // A bundle is stale if its entry `index.js` is missing, any file in its local
99
- // import graph has an mtime >= the built entry's, or one of those imports no
100
- // longer resolves to a file at all.
101
- //
102
- // The graph is one uniform walk over every RELATIVE import the entry reaches:
103
- // shared `_utils.tsx`, `../lib/*.ts`, `./data.json`, `./logo.png`,
104
- // `./db.server`. Each is resolved to a real path, mtime-checked, and descended
105
- // into when it's a module — so an imported image and a transitively imported
106
- // helper are the same case, not two mechanisms. Bare specifiers (node_modules)
107
- // are not walked: after a dependency bump, `moi bundle --force`. The bundle
108
- // itself is React-mode-agnostic (see buildApplet), so it needs no rebuild when
109
- // the server switches between the development and production React.
110
- //
111
- // `.server.ts` modules are walked like anything else, which is deliberately
112
- // MORE than the bundle needs: their code never ships to the client (only the
113
- // export list, inlined as RPC stubs), so editing one — or anything it imports
114
- // — cannot change a byte of `index.js`. We report stale anyway because 'built'
115
- // is what drives the worker recycle downstream (see `reloadModules`, called
116
- // from widgets.ts/views.ts for every rebuilt applet). Without it, editing a
117
- // helper that only a server module imports would leave a live worker serving
118
- // the old code with nothing to dislodge it. The redundant rebuild is the price
119
- // of that signal; the alternative is a second staleness channel threaded
120
- // through the build results.
58
+ // Server dependencies also trigger rebuilds so their function worker is
59
+ // recycled, even when the client bundle's RPC stubs would remain identical.
121
60
  async function needsRebuild(buildDir: string, name: string, srcPath: string): Promise<boolean> {
122
61
  const built = Bun.file(join(buildDir, name, 'index.js'))
123
62
  if (!(await built.exists())) return true
124
- const builtMtime = built.lastModified
125
-
126
- const queue = [srcPath]
127
- const visited = new Set<string>()
128
- while (queue.length > 0) {
129
- const path = queue.pop()!
130
- if (visited.has(path)) continue
131
- visited.add(path)
132
- if (visited.size > MAX_GRAPH_FILES) return true
133
- const file = Bun.file(path)
134
- if (!(await file.exists())) continue
135
- if (file.lastModified >= builtMtime) return true
136
- // Leaves stop at the mtime check above — an asset, JSON, or CSS file can't
137
- // import anything.
138
- if (!MODULE_FILE_RE.test(path)) continue
139
- const source = await file.text()
140
- const dir = dirname(path)
141
- for (const specifier of scanRelativeImports(
142
- source,
143
- TS_ONLY_FILE_RE.test(path) ? 'ts' : 'tsx'
144
- )) {
145
- const resolved = await resolveModuleImport(dir, specifier)
146
- // Nothing on disk answers this import, so the next build will fail on it.
147
- // Report stale rather than skip: a helper deleted since the last build
148
- // would otherwise leave `moi bundle` serving the last good bundle and
149
- // never surfacing the missing-import error.
150
- if (!resolved) return true
151
- queue.push(resolved)
152
- }
153
- }
154
- return false
155
- }
156
-
157
- // Extensions Bun appends to an extensionless import, in its own preference
158
- // order (`./data` finds `data.tsx` before `data.ts` before … `data.json`).
159
- // Doubles as the directory-index set: `./helpers` → `helpers/index.jsx`.
160
- const RESOLVE_EXTENSIONS = ['.tsx', '.ts', '.jsx', '.js', '.mjs', '.cjs', '.json', '.mts', '.cts']
161
-
162
- // TypeScript's output-extension rewrite: an import written against the emitted
163
- // file name resolves to the source that produces it. (`.cjs` → `.cts` is
164
- // deliberately absent — Bun doesn't do that one.)
165
- const TS_EXTENSION_REWRITES: Record<string, string[]> = {
166
- '.js': ['.ts', '.tsx'],
167
- '.jsx': ['.tsx'],
168
- '.mjs': ['.mts']
169
- }
170
-
171
- // Resolve a relative import to the file the bundler will actually read. This
172
- // mirrors Bun's resolution rather than delegating to `Bun.resolveSync`, which
173
- // memoizes results for the life of the process: in the long-running server it
174
- // keeps handing back the path of a dependency that has since been deleted or
175
- // renamed, which is exactly the case this check has to catch. Every candidate
176
- // is probed against the filesystem, in Bun's order — literal path, TS
177
- // extension rewrite, appended extension, then directory (`package.json` main,
178
- // else `index.*`). Returns null when nothing on disk answers the specifier.
179
- async function resolveModuleImport(dir: string, specifier: string): Promise<string | null> {
180
- const base = join(dir, specifier)
181
- const candidates = [base]
182
-
183
- // Extension of the final segment only — a dot in a directory name (`./v1.2/x`)
184
- // is not one.
185
- const ext = /\.[^./\\]+$/.exec(base)?.[0] ?? ''
186
- for (const rewrite of TS_EXTENSION_REWRITES[ext] ?? []) {
187
- candidates.push(base.slice(0, base.length - ext.length) + rewrite)
188
- }
189
- for (const e of RESOLVE_EXTENSIONS) candidates.push(base + e)
190
-
191
- for (const candidate of candidates) {
192
- if (await Bun.file(candidate).exists()) return candidate
193
- }
194
-
195
- // Directory import. `package.json` main wins over `index.*`, matching Bun;
196
- // an unreadable or `main`-less manifest just falls through to the indexes.
197
- const pkg: unknown = await Bun.file(join(base, 'package.json'))
198
- .json()
199
- .catch(() => null)
200
- const main =
201
- typeof pkg === 'object' && pkg !== null && 'main' in pkg && typeof pkg.main === 'string'
202
- ? pkg.main
203
- : null
204
- if (main) {
205
- const mainPath = join(base, main)
206
- if (await Bun.file(mainPath).exists()) return mainPath
207
- }
208
- for (const e of RESOLVE_EXTENSIONS) {
209
- const index = join(base, `index${e}`)
210
- if (await Bun.file(index).exists()) return index
211
- }
212
- return null
63
+ const graph = await analyzeDependencies([srcPath], built.lastModified)
64
+ return !graph.complete
213
65
  }
214
66
 
215
67
  // Built applet names: subdirectories of `buildDir` that hold an `index.js`
@@ -580,7 +432,8 @@ export type AppletBuildResult<C> = {
580
432
  export async function buildApplets<C>(
581
433
  workspacePath: string,
582
434
  kind: AppletKind,
583
- force: boolean
435
+ force: boolean,
436
+ target?: string
584
437
  ): Promise<{ names: string[]; results: AppletBuildResult<C>[]; ms: number }> {
585
438
  const t0 = performance.now()
586
439
  const { sourceDir, buildDir, moiRoot } = getAppletPaths(workspacePath, kind)
@@ -600,6 +453,7 @@ export async function buildApplets<C>(
600
453
 
601
454
  const jobs = await Promise.all(
602
455
  names.map(async name => {
456
+ if (target && name !== target) return { name, status: 'skipped' as const }
603
457
  const srcPath = await resolveSource(sourceDir, name)
604
458
  if (!srcPath) return { name, status: 'failed' as const, error: 'Source file not found' }
605
459
  if (!force && !(await needsRebuild(buildDir, name, srcPath))) {
@@ -609,35 +463,36 @@ export async function buildApplets<C>(
609
463
  })
610
464
  )
611
465
 
612
- const results = await Promise.all(
613
- jobs.map(async (job): Promise<AppletBuildResult<C>> => {
614
- if (job.status === 'failed') return { name: job.name, status: 'failed', error: job.error }
615
- if (job.status === 'skipped') return { name: job.name, status: 'skipped' }
616
- try {
617
- const artifact = await buildApplet(job.srcPath!, moiRoot, kind)
618
- // Clear the dir first so stale hashed assets from a prior build don't
619
- // accumulate, then write the fresh entry + chunks + assets.
620
- const dir = join(buildDir, job.name)
621
- await rm(dir, { recursive: true, force: true })
622
- await mkdir(dir, { recursive: true })
623
- for (const f of artifact.files) {
624
- await Bun.write(join(dir, f.name), f.data)
625
- }
626
- return {
627
- name: job.name,
628
- status: 'built',
629
- serverModules: artifact.serverModules.map(m => m.name),
630
- config: (artifact.config as C | null) ?? null
631
- }
632
- } catch (err) {
633
- return {
634
- name: job.name,
635
- status: 'failed',
636
- error: err instanceof Error ? err.message : 'Unknown error'
637
- }
638
- }
639
- })
466
+ // Compile the pending set in a fresh child process (see build-worker.ts:
467
+ // Bun's resolver cache is process-wide and never forgets a failed lookup, so
468
+ // an in-process build could not see packages installed after the server
469
+ // started). The child writes each bundle dir; only the per-job outcome comes
470
+ // back.
471
+ const built = new Map(
472
+ (
473
+ await buildAppletsInChild({
474
+ moiRoot,
475
+ kind,
476
+ jobs: jobs
477
+ .filter(job => job.status === 'pending')
478
+ .map(job => ({ name: job.name, srcPath: job.srcPath!, outDir: join(buildDir, job.name) }))
479
+ })
480
+ ).map(r => [r.name, r])
640
481
  )
641
482
 
483
+ const results = jobs.map((job): AppletBuildResult<C> => {
484
+ if (job.status === 'failed') return { name: job.name, status: 'failed', error: job.error }
485
+ if (job.status === 'skipped') return { name: job.name, status: 'skipped' }
486
+ const r = built.get(job.name)
487
+ if (!r) return { name: job.name, status: 'failed', error: 'Build worker returned no result' }
488
+ if (r.status === 'failed') return { name: job.name, status: 'failed', error: r.error }
489
+ return {
490
+ name: job.name,
491
+ status: 'built',
492
+ serverModules: r.serverModules,
493
+ config: (r.config as C | null) ?? null
494
+ }
495
+ })
496
+
642
497
  return { names, results, ms: Math.round(performance.now() - t0) }
643
498
  }
@@ -0,0 +1,4 @@
1
+ // Baked into applet bundles wherever a runtime URL needs the workspace API
2
+ // base. The serve route replaces it with `/api/workspaces/<id>` so bundles stay
3
+ // workspace-agnostic on disk.
4
+ export const APPLET_API_BASE_SENTINEL = '%%MOI_APPLET_API_BASE%%'
@@ -0,0 +1,42 @@
1
+ import type { AppletBridge, AttachmentInput } from '../../../lib/types'
2
+
3
+ import { APPLET_API_BASE_SENTINEL } from './base'
4
+
5
+ type AppletChatInput = {
6
+ message: string
7
+ attachments?: AttachmentInput[]
8
+ }
9
+
10
+ const BASE = APPLET_API_BASE_SENTINEL
11
+
12
+ let bridge: Partial<AppletBridge> | null = null
13
+
14
+ export function __attachBridge(next: Partial<AppletBridge>): void {
15
+ bridge = next
16
+ }
17
+
18
+ export function __getBridge(): Partial<AppletBridge> | null {
19
+ return bridge
20
+ }
21
+
22
+ export function fileUrl(path: string): string {
23
+ const clean = String(path).replace(/^\/+/, '')
24
+ return BASE + '/fs/' + clean.split('/').map(encodeURIComponent).join('/')
25
+ }
26
+
27
+ export function navigate(href: string): void {
28
+ bridge?.navigate?.(href)
29
+ }
30
+
31
+ export function resolveHref(href: string): string {
32
+ return bridge?.resolveHref?.(href) ?? ''
33
+ }
34
+
35
+ export function addChatAttachment(input: AttachmentInput): void {
36
+ bridge?.addChatAttachment?.(input)
37
+ }
38
+
39
+ // Keep positional calls working for previously built applets.
40
+ export function sendChatMessage(input: AppletChatInput | string, legacyContext?: unknown): void {
41
+ bridge?.sendChatMessage?.(input, legacyContext)
42
+ }
@@ -0,0 +1,17 @@
1
+ import { parse, stringify } from 'devalue'
2
+
3
+ import { APPLET_API_BASE_SENTINEL } from './base'
4
+
5
+ const BASE = APPLET_API_BASE_SENTINEL
6
+
7
+ export function rpc(module: string, name: string) {
8
+ return async (...args: unknown[]): Promise<unknown> => {
9
+ const res = await fetch(BASE + '/rpc/' + module + '/' + name, {
10
+ method: 'POST',
11
+ headers: { 'Content-Type': 'application/json' },
12
+ body: stringify(args)
13
+ })
14
+ if (!res.ok) throw new Error(await res.text())
15
+ return parse(await res.text())
16
+ }
17
+ }
@@ -0,0 +1,67 @@
1
+ import { realpath, rm } from 'node:fs/promises'
2
+ import { join, relative, sep } from 'node:path'
3
+
4
+ import { analyzeAppletDependencies, collectDependencies, MODULE_FILE_RE } from './dependencies'
5
+
6
+ type ViewSource = {
7
+ path: string
8
+ source: string
9
+ }
10
+
11
+ export async function readViewSource(
12
+ workspacePath: string,
13
+ viewId: string
14
+ ): Promise<ViewSource | null> {
15
+ const directory = join(workspacePath, '.moi', 'views')
16
+ for (const extension of ['.tsx', '.ts']) {
17
+ const path = join(directory, `${viewId}${extension}`)
18
+ const file = Bun.file(path)
19
+ if (await file.exists()) return { path, source: await file.text() }
20
+ }
21
+ return null
22
+ }
23
+
24
+ export class ViewSourceInUseError extends Error {}
25
+
26
+ function isCleanupSource(moiRoot: string, path: string): boolean {
27
+ if (!path.startsWith(moiRoot + sep) || !MODULE_FILE_RE.test(path)) return false
28
+ // Keep data, installed UI components, packages, and generated/hidden files.
29
+ return !relative(moiRoot, path)
30
+ .split(sep)
31
+ .some(part => part.startsWith('.') || ['data', 'ui', 'node_modules'].includes(part))
32
+ }
33
+
34
+ export async function deleteViewSourceFiles(workspacePath: string, viewId: string): Promise<void> {
35
+ const workspaceRoot = await realpath(workspacePath)
36
+ const moiRoot = join(workspaceRoot, '.moi')
37
+ const directory = join(moiRoot, 'views')
38
+ const sources = ['tsx', 'ts'].map(extension => join(directory, `${viewId}.${extension}`))
39
+ const roots = new Set([...sources, join(directory, `${viewId}.server.ts`)])
40
+ const remove = new Set(sources)
41
+ const graph = await analyzeAppletDependencies(workspaceRoot).catch(() => null)
42
+
43
+ if (graph?.complete) {
44
+ // A symlink can give one module several identities. Leave helpers behind
45
+ // in that case rather than guessing ownership or doing a more costly scan.
46
+ const canonical = await Promise.all(
47
+ [...graph.modules.keys()].map(async path => (await realpath(path).catch(() => null)) === path)
48
+ )
49
+ if (canonical.every(Boolean)) {
50
+ const candidates = collectDependencies(graph, roots)
51
+ const retained = collectDependencies(graph, [
52
+ ...[...graph.entrypoints].filter(path => !roots.has(path)),
53
+ ...[...candidates].filter(path => !isCleanupSource(moiRoot, path))
54
+ ])
55
+ if (sources.some(path => retained.has(path))) {
56
+ throw new ViewSourceInUseError(
57
+ 'Another applet imports this view. Remove that import before deleting it.'
58
+ )
59
+ }
60
+ for (const path of candidates) {
61
+ if (!retained.has(path) && isCleanupSource(moiRoot, path)) remove.add(path)
62
+ }
63
+ }
64
+ }
65
+
66
+ await Promise.all([...remove].map(path => rm(path, { force: true })))
67
+ }
@@ -0,0 +1,95 @@
1
+ import { appendAttachments, attachmentPart } from '@/lib/moi-attachments'
2
+ import type { MessageAttachment, Part, Attachment } from '@/lib/types'
3
+ import { materializeToPath, resolveUploads, servedUploadUrl } from './uploads'
4
+
5
+ // Native images carry bytes; every file has a readable path.
6
+ type PreparedAttachment =
7
+ | Exclude<Attachment, { type: 'image' }>
8
+ | (Extract<Attachment, { type: 'image' }> & { data: Buffer })
9
+
10
+ export type PreparedAttachmentMessage = {
11
+ text: string
12
+ attachments: PreparedAttachment[]
13
+ parts: Part[]
14
+ }
15
+
16
+ export class AttachmentUploadError extends Error {
17
+ constructor() {
18
+ super('Attachment not found or expired')
19
+ this.name = 'AttachmentUploadError'
20
+ }
21
+ }
22
+
23
+ function resolveAttachmentUploads(workspaceId: string, inputs: readonly MessageAttachment[]) {
24
+ const ids = inputs.flatMap(input => (input.type === 'upload' ? [input.uploadId] : []))
25
+ const uploads = resolveUploads(workspaceId, ids)
26
+ if (uploads.length !== ids.length) throw new AttachmentUploadError()
27
+ return new Map(uploads.map(upload => [upload.id, upload]))
28
+ }
29
+
30
+ // Path-only harnesses await this before building their message.
31
+ export async function materializeAttachmentPaths(
32
+ workspaceId: string,
33
+ inputs: readonly MessageAttachment[] = []
34
+ ): Promise<void> {
35
+ await Promise.all(
36
+ [...resolveAttachmentUploads(workspaceId, inputs).values()].map(materializeToPath)
37
+ )
38
+ }
39
+
40
+ // Keep construction synchronous so Claude queues a send before an immediate Stop.
41
+ // For path delivery, await materializeAttachmentPaths first.
42
+ export function prepareAttachmentMessage(
43
+ workspaceId: string,
44
+ text: string,
45
+ inputs: readonly MessageAttachment[] = [],
46
+ inlineImages = true
47
+ ): PreparedAttachmentMessage {
48
+ const uploads = resolveAttachmentUploads(workspaceId, inputs)
49
+ const attachments: PreparedAttachment[] = []
50
+ const parts: Part[] = []
51
+ for (const input of inputs) {
52
+ if (input.type === 'text') {
53
+ attachments.push(input)
54
+ parts.push(attachmentPart(input))
55
+ continue
56
+ }
57
+ const upload = uploads.get(input.uploadId)
58
+ if (!upload) throw new AttachmentUploadError()
59
+ const metadata = {
60
+ mediaType: upload.mediaType,
61
+ source: input.source
62
+ }
63
+ if (upload.kind === 'image' && inlineImages && upload.data) {
64
+ const attachment: PreparedAttachment = {
65
+ type: 'image',
66
+ ...metadata,
67
+ label: upload.filename,
68
+ purpose: input.purpose,
69
+ data: upload.data
70
+ }
71
+ attachments.push(attachment)
72
+ parts.push(attachmentPart(attachment, servedUploadUrl(upload)))
73
+ } else if (upload.path) {
74
+ const attachment: Attachment = {
75
+ type: 'file',
76
+ ...metadata,
77
+ path: upload.path,
78
+ ...(upload.kind === 'image' ? { purpose: input.purpose } : {})
79
+ }
80
+ attachments.push(attachment)
81
+ parts.push(attachmentPart(attachment))
82
+ }
83
+ }
84
+ const descriptors = attachments.map(attachment => {
85
+ if (!('data' in attachment)) return attachment
86
+ const { data: _data, ...descriptor } = attachment
87
+ return descriptor
88
+ })
89
+ if (text) parts.push({ type: 'text', text })
90
+ return {
91
+ text: appendAttachments(text, descriptors),
92
+ attachments,
93
+ parts
94
+ }
95
+ }
@@ -1,9 +1,9 @@
1
1
  // CLI face of `moi ui-components` (see server/ui-components.ts for the
2
- // engine and docs/moi-shadcn.md for the spec). Three verbs:
2
+ // engine and docs/ui-components.md for the spec). Three verbs:
3
3
  //
4
4
  // moi ui-components → the curated catalog + installed state
5
- // moi ui-components add <name…> → fetch, transform, write to .moi/ui/
6
- // moi ui-components docs <name…> → official docs as markdown, on stdout
5
+ // moi ui-components add <name…> → copy registry components to .moi/ui/
6
+ // moi ui-components docs <name…> → component docs as markdown, on stdout
7
7
  //
8
8
  // The command is deliberately not smart: add never rebuilds and never edits
9
9
  // existing files, and installs dependencies only when asked to (--install) —
@@ -17,15 +17,16 @@ import pc from './cli-pc'
17
17
  import { resolveCwdWorkspace } from './cli-env'
18
18
  import { MOI_PACKAGE_JSON } from './moi-scaffold'
19
19
  import {
20
+ type LoadedUiComponents,
20
21
  UI_COMPONENTS,
21
22
  UI_COMPONENT_NAMES,
22
- UI_DOCS_BASE,
23
- fetchUiComponents,
23
+ loadUiComponentDocs,
24
+ loadUiComponents,
24
25
  partitionUiWrites,
25
26
  planUiWrites,
26
27
  resolveUiComponentRequest,
27
28
  suggestUiComponents,
28
- transformUiComponentSource
29
+ uiComponentFiles
29
30
  } from './ui-components'
30
31
 
31
32
  function uiDirFor(workspacePath: string): string {
@@ -37,7 +38,7 @@ function exitUnknownNames(unknown: string[]): never {
37
38
  const hints = suggestUiComponents(name)
38
39
  console.error(
39
40
  pc.red('✗') +
40
- ` "${name}" is not in the moi component set.` +
41
+ ` "${name}" is not in the component catalog.` +
41
42
  (hints.length ? pc.dim(` Did you mean: ${hints.join(', ')}?`) : '')
42
43
  )
43
44
  }
@@ -48,7 +49,7 @@ function exitUnknownNames(unknown: string[]): never {
48
49
  const add = defineCommand({
49
50
  meta: {
50
51
  name: 'add',
51
- description: 'Fetch components from the shadcn registry into .moi/ui/'
52
+ description: 'Add components from the local registry to .moi/ui/'
52
53
  },
53
54
  args: {
54
55
  name: {
@@ -74,35 +75,34 @@ const add = defineCommand({
74
75
  const entry = await resolveCwdWorkspace()
75
76
  const uiDir = uiDirFor(entry.path)
76
77
 
77
- let fetched
78
+ let loaded: LoadedUiComponents
78
79
  try {
79
- fetched = await fetchUiComponents(request.registryItems)
80
+ loaded = await loadUiComponents(request.entries)
80
81
  } catch (err) {
81
82
  console.error(
82
83
  '\n' +
83
84
  pc.red('✗') +
84
- ' Could not reach the shadcn registry (ui.shadcn.com). ' +
85
- 'The command needs network access; offline use is not supported.\n' +
85
+ ' Could not load the requested components from the local registry.\n' +
86
86
  pc.dim(` ${(err as Error).message}\n`)
87
87
  )
88
88
  process.exit(1)
89
89
  }
90
90
 
91
91
  const plans = planUiWrites({
92
- files: fetched.files,
93
- requestedItems: request.registryItems,
92
+ files: loaded.files,
93
+ requestedFiles: request.entries.flatMap(uiComponentFiles),
94
94
  uiDir,
95
95
  exists: existsSync
96
96
  })
97
97
 
98
98
  // Hand-customized components are never silently overwritten: without
99
99
  // --force a requested file that already exists is skipped and reported, so
100
- // a bulk add still installs everything new. Only when every requested
101
- // component already exists does the add fail. Existing support files
102
- // (utils, applet-portal, registry deps that rode along) are kept as-is
100
+ // a bulk add still installs everything new. Only when nothing needs to be
101
+ // written does the add fail. Existing support files
102
+ // (utils, scoped-portal, registry deps that rode along) are kept as-is
103
103
  // either way, even under --force.
104
104
  const partition = partitionUiWrites(plans, args.force)
105
- if (partition.allInstalled) {
105
+ if (partition.write.length === 0) {
106
106
  console.error(
107
107
  '\n' +
108
108
  pc.red('✗') +
@@ -118,10 +118,7 @@ const add = defineCommand({
118
118
  await mkdir(uiDir, { recursive: true })
119
119
  const written: string[] = []
120
120
  for (const plan of partition.write) {
121
- const content = plan.name.endsWith('.tsx')
122
- ? await transformUiComponentSource(plan.name, plan.content)
123
- : plan.content
124
- await Bun.write(plan.path, content)
121
+ await Bun.write(plan.path, plan.content)
125
122
  written.push(plan.name)
126
123
  }
127
124
  const kept = partition.keepSupport.map(plan => plan.name)
@@ -131,7 +128,7 @@ const add = defineCommand({
131
128
  // registry specifiers may be versioned (`recharts@3.8.0`), so compare by
132
129
  // package name.
133
130
  const baseline = new Set(Object.keys(MOI_PACKAGE_JSON.dependencies))
134
- const deps = [...new Set([...fetched.dependencies, ...request.extraDeps])]
131
+ const deps = [...new Set(loaded.dependencies)]
135
132
  .filter(spec => !baseline.has(spec.replace(/@[^@/]+$/, '')))
136
133
  .sort()
137
134
 
@@ -200,7 +197,7 @@ const add = defineCommand({
200
197
  const docs = defineCommand({
201
198
  meta: {
202
199
  name: 'docs',
203
- description: 'Print official component docs as markdown'
200
+ description: 'Print component docs as markdown'
204
201
  },
205
202
  args: {
206
203
  name: {
@@ -213,18 +210,16 @@ const docs = defineCommand({
213
210
  const request = resolveUiComponentRequest(args._)
214
211
  if (request.unknown.length > 0) exitUnknownNames(request.unknown)
215
212
 
213
+ console.log(
214
+ '> Import components relatively from `../ui/<name>` and use `@tabler/icons-react` for icons.\n'
215
+ )
216
216
  for (const name of request.entries) {
217
- const slug = UI_COMPONENTS[name].docsSlug ?? name
218
- const url = `${UI_DOCS_BASE}/${slug}.md`
219
217
  try {
220
- const res = await fetch(url, { signal: AbortSignal.timeout(20_000) })
221
- if (!res.ok) throw new Error(`HTTP ${res.status}`)
218
+ const markdown = await loadUiComponentDocs(name)
222
219
  if (request.entries.length > 1) console.log(`\n---\n# ${name}\n`)
223
- console.log(await res.text())
220
+ console.log(markdown)
224
221
  } catch (err) {
225
- console.error(
226
- pc.red('✗') + ` Could not fetch docs for "${name}" (${url}): ${(err as Error).message}`
227
- )
222
+ console.error(pc.red('✗') + ` Could not load docs for "${name}": ${(err as Error).message}`)
228
223
  process.exitCode = 1
229
224
  }
230
225
  }
@@ -240,7 +235,7 @@ function renderCatalog(uiDir: string, query?: string): void {
240
235
  if (needle && !name.includes(needle) && !entry.description.toLowerCase().includes(needle)) {
241
236
  continue
242
237
  }
243
- const installed = entry.registryItems.every(item => existsSync(join(uiDir, `${item}.tsx`)))
238
+ const installed = uiComponentFiles(name).every(file => existsSync(join(uiDir, file)))
244
239
  rows.push(
245
240
  ' ' +
246
241
  (installed ? pc.green('✓ ') : ' ') +