moi-computer 0.11.1-next.0 → 0.11.1-next.2

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 (211) hide show
  1. package/client/AGENTS.md +2 -2
  2. package/client/components/ui/button.tsx +1 -53
  3. package/client/components/ui/collapsible.tsx +1 -15
  4. package/client/components/ui/dialog.tsx +1 -58
  5. package/client/components/ui/dropdown-menu.tsx +1 -254
  6. package/client/components/ui/hover-card.tsx +1 -44
  7. package/client/components/ui/input.tsx +1 -21
  8. package/client/components/ui/popover.tsx +1 -88
  9. package/client/components/ui/resizable.tsx +1 -40
  10. package/client/components/ui/skeleton.tsx +1 -13
  11. package/client/components/ui/slider.tsx +1 -70
  12. package/client/components/ui/spinner.tsx +1 -18
  13. package/client/components/ui/switch.tsx +1 -23
  14. package/client/components/ui/tabs.tsx +1 -0
  15. package/client/components/ui/textarea.tsx +1 -18
  16. package/client/components/ui/tooltip.tsx +1 -51
  17. package/client/features/chat/ChatPanel.tsx +6 -6
  18. package/client/features/chat/ChatPopup.tsx +3 -4
  19. package/client/features/chat/TurnView.tsx +5 -4
  20. package/client/features/chat/api.ts +5 -14
  21. package/client/features/chat/chat-frames.ts +9 -7
  22. package/client/features/chat/chat-send.ts +13 -2
  23. package/client/features/chat/chat-store.ts +1 -3
  24. package/client/features/chat/composer/ChatComposer.tsx +5 -1
  25. package/client/features/chat/composer/ModelPicker.tsx +44 -44
  26. package/client/features/chat/composer/banners/ErrorBanner.tsx +20 -12
  27. package/client/features/chat/composer/model-order.ts +15 -0
  28. package/client/features/chat/composer/useWorkspaceComposerState.tsx +15 -7
  29. package/client/features/chat/group-turns.ts +12 -0
  30. package/client/features/chat/interleave-notices.ts +7 -11
  31. package/client/features/chat/session-view.ts +53 -0
  32. package/client/features/chat/tool-group/ToolCallGroup.tsx +1 -4
  33. package/client/features/chat/tool-group/format/codex.ts +4 -1
  34. package/client/features/chat/useChat.ts +10 -9
  35. package/client/features/dev/ChatStatesPage.tsx +3 -1
  36. package/client/features/dev/DevIndexPage.tsx +5 -0
  37. package/client/features/dev/DevRoutes.tsx +2 -0
  38. package/client/features/dev/HarnessDebugPage.tsx +1 -1
  39. package/client/features/dev/UiComponentPreviews.tsx +834 -0
  40. package/client/features/dev/UiComponentsPage.tsx +60 -0
  41. package/client/features/home/WorkspacePreview.tsx +1 -1
  42. package/client/features/home/workspace-setup/DemoDialog.tsx +3 -2
  43. package/client/features/home/workspace-setup/ImportWorkspaceDialog.tsx +5 -8
  44. package/client/features/home/workspace-setup/WorkspaceDialogContent.tsx +7 -20
  45. package/client/features/settings/SettingsLayout.tsx +1 -1
  46. package/client/features/settings/WorkspaceSettings.tsx +4 -1
  47. package/client/features/views/ViewManager.tsx +14 -9
  48. package/client/features/widgets/WidgetFrame.tsx +1 -1
  49. package/client/features/widgets/Widgets.tsx +1 -3
  50. package/client/features/workspace/WorkspaceScreen.tsx +5 -1
  51. package/client/features/workspace/WorkspaceSplitLayout.tsx +6 -1
  52. package/client/features/workspace/api.ts +2 -4
  53. package/client/index.css +22 -29
  54. package/dist/chunk-245wt82v.css +1 -0
  55. package/dist/{chunk-tny85yt2.js → chunk-4s15axjs.js} +2 -2
  56. package/dist/{chunk-c9pjqx9m.js → chunk-53a7pxcz.js} +1 -1
  57. package/dist/{chunk-104m57qw.js → chunk-87thzbtw.js} +2 -2
  58. package/dist/chunk-a6jad1a6.js +1 -0
  59. package/dist/chunk-dghwstd2.js +9 -0
  60. package/dist/chunk-eg120aca.js +1 -0
  61. package/dist/{chunk-v7wr1df4.js → chunk-j3wvxjr7.js} +1 -1
  62. package/dist/chunk-j7hh2ab4.js +70 -0
  63. package/dist/chunk-w482ew2c.js +546 -0
  64. package/dist/chunk-y8eyahwx.js +1 -0
  65. package/dist/index.html +1 -1
  66. package/lib/format.ts +55 -6
  67. package/lib/themes.ts +6 -6
  68. package/lib/types.ts +10 -9
  69. package/package.json +12 -5
  70. package/registry.json +643 -0
  71. package/server/agent.ts +1 -1
  72. package/server/api.ts +26 -30
  73. package/server/applets.ts +30 -29
  74. package/server/bundler/applet-css.ts +7 -107
  75. package/server/bundler/build-applet.ts +5 -1
  76. package/server/bundler/build-worker.ts +178 -0
  77. package/server/cli-ui-components.ts +28 -33
  78. package/server/cli.ts +6 -11
  79. package/server/data-dir.ts +1 -1
  80. package/server/harness/README.md +41 -48
  81. package/server/harness/acp/NOTES.md +426 -0
  82. package/server/harness/acp/discovery.ts +27 -30
  83. package/server/harness/acp/model-state.ts +57 -0
  84. package/server/harness/acp/session.ts +18 -6
  85. package/server/harness/claude-code/NOTES.md +47 -12
  86. package/server/harness/claude-code/cli.ts +40 -0
  87. package/server/harness/claude-code/index.ts +11 -5
  88. package/server/harness/claude-code/models.ts +72 -19
  89. package/server/harness/claude-code/session.ts +408 -299
  90. package/server/harness/codex/NOTES.md +222 -350
  91. package/server/harness/codex/adapter.ts +94 -45
  92. package/server/harness/codex/auth.ts +1 -3
  93. package/server/harness/codex/client.ts +169 -249
  94. package/server/harness/codex/discovery.ts +9 -17
  95. package/server/harness/codex/index.ts +2 -1
  96. package/server/harness/codex/pagination.ts +24 -0
  97. package/server/harness/codex/permissions.ts +31 -7
  98. package/server/harness/codex/probe.ts +10 -13
  99. package/server/harness/codex/session.ts +549 -136
  100. package/server/harness/codex/transport.ts +184 -0
  101. package/server/harness/debug.ts +1 -1
  102. package/server/harness/hermes/NOTES.md +18 -0
  103. package/server/harness/hermes/discovery.ts +20 -0
  104. package/server/harness/hermes/index.ts +9 -0
  105. package/server/harness/hermes/models.ts +28 -8
  106. package/server/harness/types.ts +4 -2
  107. package/server/moi-scaffold.ts +1 -1
  108. package/server/preview.ts +3 -1
  109. package/server/registry.ts +63 -41
  110. package/server/tldraw-package.d.ts +4 -0
  111. package/server/ui-components.ts +101 -434
  112. package/server/view-builders.ts +2 -1
  113. package/server/web.ts +12 -5
  114. package/server/workspace-env.ts +3 -2
  115. package/tsconfig.json +0 -1
  116. package/ui-components/accordion.tsx +71 -0
  117. package/ui-components/alert-dialog.tsx +165 -0
  118. package/ui-components/alert.tsx +68 -0
  119. package/ui-components/attachment.tsx +195 -0
  120. package/ui-components/avatar.tsx +90 -0
  121. package/ui-components/badge.tsx +49 -0
  122. package/ui-components/button-group.tsx +78 -0
  123. package/ui-components/button.tsx +55 -0
  124. package/ui-components/calendar.tsx +180 -0
  125. package/ui-components/card.tsx +84 -0
  126. package/ui-components/carousel.tsx +235 -0
  127. package/ui-components/chart.tsx +338 -0
  128. package/ui-components/checkbox.tsx +28 -0
  129. package/ui-components/collapsible.tsx +15 -0
  130. package/ui-components/combobox.tsx +267 -0
  131. package/ui-components/context-menu.tsx +244 -0
  132. package/ui-components/dialog.tsx +138 -0
  133. package/ui-components/docs/accordion.md +463 -0
  134. package/ui-components/docs/alert-dialog.md +481 -0
  135. package/ui-components/docs/alert.md +301 -0
  136. package/ui-components/docs/attachment.md +689 -0
  137. package/ui-components/docs/avatar.md +495 -0
  138. package/ui-components/docs/badge.md +258 -0
  139. package/ui-components/docs/button-group.md +879 -0
  140. package/ui-components/docs/button.md +26 -0
  141. package/ui-components/docs/calendar.md +862 -0
  142. package/ui-components/docs/card.md +265 -0
  143. package/ui-components/docs/carousel.md +627 -0
  144. package/ui-components/docs/chart.md +1256 -0
  145. package/ui-components/docs/checkbox.md +477 -0
  146. package/ui-components/docs/collapsible.md +446 -0
  147. package/ui-components/docs/combobox.md +1003 -0
  148. package/ui-components/docs/context-menu.md +860 -0
  149. package/ui-components/docs/data-table.md +1580 -0
  150. package/ui-components/docs/date-picker.md +614 -0
  151. package/ui-components/docs/dialog.md +414 -0
  152. package/ui-components/docs/drawer.md +51 -0
  153. package/ui-components/docs/dropdown-menu.md +1000 -0
  154. package/ui-components/docs/field.md +1192 -0
  155. package/ui-components/docs/hover-card.md +275 -0
  156. package/ui-components/docs/input-group.md +866 -0
  157. package/ui-components/docs/input.md +456 -0
  158. package/ui-components/docs/label.md +295 -0
  159. package/ui-components/docs/pagination.md +416 -0
  160. package/ui-components/docs/popover.md +348 -0
  161. package/ui-components/docs/progress.md +214 -0
  162. package/ui-components/docs/radio-group.md +389 -0
  163. package/ui-components/docs/resizable.md +265 -0
  164. package/ui-components/docs/select.md +616 -0
  165. package/ui-components/docs/separator.md +216 -0
  166. package/ui-components/docs/skeleton.md +205 -0
  167. package/ui-components/docs/slider.md +226 -0
  168. package/ui-components/docs/spinner.md +332 -0
  169. package/ui-components/docs/switch.md +236 -0
  170. package/ui-components/docs/table.md +551 -0
  171. package/ui-components/docs/tabs.md +379 -0
  172. package/ui-components/docs/textarea.md +187 -0
  173. package/ui-components/docs/toggle-group.md +370 -0
  174. package/ui-components/docs/toggle.md +91 -0
  175. package/ui-components/docs/tooltip.md +290 -0
  176. package/ui-components/drawer.tsx +213 -0
  177. package/ui-components/dropdown-menu.tsx +263 -0
  178. package/ui-components/field.tsx +224 -0
  179. package/ui-components/hover-card.tsx +46 -0
  180. package/ui-components/input-group.tsx +146 -0
  181. package/ui-components/input.tsx +20 -0
  182. package/ui-components/label.tsx +17 -0
  183. package/ui-components/pagination.tsx +124 -0
  184. package/ui-components/popover.tsx +81 -0
  185. package/ui-components/progress.tsx +63 -0
  186. package/ui-components/radio-group.tsx +38 -0
  187. package/ui-components/resizable.tsx +40 -0
  188. package/ui-components/scoped-portal.tsx +31 -0
  189. package/ui-components/select.tsx +195 -0
  190. package/ui-components/separator.tsx +18 -0
  191. package/ui-components/skeleton.tsx +15 -0
  192. package/ui-components/slider.tsx +75 -0
  193. package/ui-components/spinner.tsx +20 -0
  194. package/ui-components/switch.tsx +27 -0
  195. package/ui-components/table.tsx +86 -0
  196. package/ui-components/tabs.tsx +75 -0
  197. package/ui-components/textarea.tsx +17 -0
  198. package/ui-components/toggle-group.tsx +85 -0
  199. package/ui-components/toggle.tsx +42 -0
  200. package/ui-components/tooltip.tsx +61 -0
  201. package/ui-components/utils.ts +8 -0
  202. package/workspace/.claude/skills/moi-workspace/SKILL.md +11 -20
  203. package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +4 -3
  204. package/workspace/.claude/skills/moi-workspace/references/UI-COMPONENTS.md +67 -203
  205. package/dist/chunk-59zf0m6n.js +0 -1
  206. package/dist/chunk-bj3akjs2.js +0 -1
  207. package/dist/chunk-j2w2vak4.js +0 -546
  208. package/dist/chunk-k2r9c95m.js +0 -10
  209. package/dist/chunk-kmbxhgwv.js +0 -1
  210. package/dist/chunk-p1yqa71k.js +0 -83
  211. package/dist/chunk-r5xrenjy.css +0 -1
@@ -1,23 +1,10 @@
1
- // The `moi ui-components` engine: a shadcn-lite proxy over the `shadcn`
2
- // package's own programmatic registry + transform APIs (see docs/moi-shadcn.md
3
- // for the full spec and the research trail in PR #78).
4
- //
5
- // Opinions, enforced here: the upstream registry is the source of truth
6
- // (style `base-nova`, Base UI primitives, Tabler icons); the command exposes
7
- // only a curated subset of it; no config files ever land in the workspace —
8
- // the engine takes its config as the in-memory object below; components are
9
- // written to `.moi/ui/` and imported relatively (`../ui/button`). The command
10
- // writes source files and nothing else: it never installs dependencies and
11
- // never rebuilds — it prints next steps for the agent instead.
12
- // `shadcn/registry`, `shadcn/utils` and `ts-morph` are imported at their call
13
- // sites rather than here, deliberately. Together they are ~31 MB of JS across
14
- // 1600 modules (ts-morph alone embeds the whole TypeScript compiler), and the
15
- // cost is parse + top-level evaluation, so bundling does not help — measured
16
- // at ~300 ms. Only `moi ui-components add` ever fetches or transforms; a
17
- // static import here made every `moi` command pay it, `moi version` included.
18
- import type { Project, SourceFile } from 'ts-morph'
1
+ // The `moi ui-components` catalog and local registry loader. Component sources
2
+ // and docs are bundled, so installs do not depend on a remote registry.
19
3
  import { join } from 'path'
20
4
 
5
+ import registry from '../registry.json'
6
+ import { PACKAGE_ROOT } from './version'
7
+
21
8
  // ---------------------------------------------------------------------------
22
9
  // The curated catalog
23
10
  // ---------------------------------------------------------------------------
@@ -25,450 +12,139 @@ import { join } from 'path'
25
12
  export type UiComponentEntry = {
26
13
  // One line for `moi ui-components list` and the skill cheat sheet.
27
14
  description: string
28
- // Registry items `add` actually fetches. Most entries map to themselves;
29
- // pattern entries (data-table, date-picker) map to their building blocks
30
- // and exist upstream only as docs.
31
- registryItems: string[]
32
- // npm packages the entry needs that no fetched registry item declares —
33
- // pattern-only additions their docs assume (data-table → TanStack Table).
34
- // Everything else flows from the resolved items' own `dependencies`.
35
- extraDeps?: string[]
36
- // Docs slug when it differs from the entry name (none currently).
37
- docsSlug?: string
38
15
  }
39
16
 
40
- // The agreed subset (UI component review, Aug 2026). Upstream ships ~63 ui
41
- // items; only these are exposed. Registry dependencies of a curated item
42
- // (e.g. field → label + separator, chart → card, toggle-group → toggle) are
43
- // resolved and written implicitly — they are support files, not catalog
44
- // entries.
45
- export const UI_COMPONENTS: Record<string, UiComponentEntry> = {
46
- accordion: {
47
- description: 'Vertically stacked sections that expand one at a time',
48
- registryItems: ['accordion']
49
- },
50
- alert: {
51
- description: 'Callout box for statuses and short messages',
52
- registryItems: ['alert']
53
- },
54
- 'alert-dialog': {
55
- description: 'Modal confirmation dialog for destructive or blocking actions',
56
- registryItems: ['alert-dialog']
57
- },
58
- attachment: {
59
- description: 'File or image attachment tile with metadata and actions',
60
- registryItems: ['attachment']
61
- },
62
- avatar: {
63
- description: 'User or entity image with fallback initials',
64
- registryItems: ['avatar']
65
- },
66
- badge: {
67
- description: 'Small status or count label',
68
- registryItems: ['badge']
69
- },
70
- bubble: {
71
- description: 'Chat message bubble',
72
- registryItems: ['bubble']
73
- },
74
- button: {
75
- description: 'The button: variants, sizes, icon support',
76
- registryItems: ['button']
77
- },
78
- 'button-group': {
79
- description: 'Buttons joined into one segmented control',
80
- registryItems: ['button-group']
81
- },
82
- calendar: {
83
- description: 'Month calendar for picking dates and ranges',
84
- registryItems: ['calendar']
85
- },
86
- carousel: {
87
- description: 'Swipeable slides with prev/next controls',
88
- registryItems: ['carousel']
89
- },
90
- chart: {
91
- description: 'Recharts-based charts wired to workspace theme tokens',
92
- registryItems: ['chart']
93
- },
94
- checkbox: {
95
- description: 'Binary checkbox with indeterminate state',
96
- registryItems: ['checkbox']
97
- },
98
- collapsible: {
99
- description: 'Single section that expands and collapses',
100
- registryItems: ['collapsible']
101
- },
102
- combobox: {
103
- description: 'Text input with a filtered dropdown of options',
104
- registryItems: ['combobox']
105
- },
106
- 'context-menu': {
107
- description: 'Right-click menu with items, submenus, and shortcuts',
108
- registryItems: ['context-menu']
109
- },
110
- 'data-table': {
111
- description: 'Sortable, filterable table pattern built on table + TanStack Table',
112
- registryItems: ['table'],
113
- extraDeps: ['@tanstack/react-table']
114
- },
115
- 'date-picker': {
116
- description: 'Date picker pattern: calendar in a popover',
117
- registryItems: ['calendar', 'popover', 'button']
118
- },
119
- dialog: {
120
- description: 'Modal dialog with backdrop, header, and footer',
121
- registryItems: ['dialog']
122
- },
123
- 'dropdown-menu': {
124
- description: 'Menu opened from a trigger: items, groups, submenus',
125
- registryItems: ['dropdown-menu']
126
- },
127
- field: {
128
- description: 'Form field wrapper: label, control, description, error',
129
- registryItems: ['field']
130
- },
131
- 'hover-card': {
132
- description: 'Preview card shown on hover over a link or element',
133
- registryItems: ['hover-card']
134
- },
135
- input: {
136
- description: 'Single-line text input',
137
- registryItems: ['input']
138
- },
139
- 'input-group': {
140
- description: 'Input with attached addons, buttons, or icons',
141
- registryItems: ['input-group']
142
- },
143
- label: {
144
- description: 'Form control label',
145
- registryItems: ['label']
146
- },
147
- pagination: {
148
- description: 'Page navigation with prev/next and page links',
149
- registryItems: ['pagination']
150
- },
151
- popover: {
152
- description: 'Floating panel anchored to a trigger',
153
- registryItems: ['popover']
154
- },
155
- progress: {
156
- description: 'Determinate progress bar',
157
- registryItems: ['progress']
158
- },
159
- 'radio-group': {
160
- description: 'Single-choice radio button set',
161
- registryItems: ['radio-group']
162
- },
163
- resizable: {
164
- description: 'Resizable split panels with drag handles',
165
- registryItems: ['resizable']
166
- },
167
- select: {
168
- description: 'Native-feeling select with a styled popup',
169
- registryItems: ['select']
170
- },
171
- separator: {
172
- description: 'Horizontal or vertical dividing line',
173
- registryItems: ['separator']
174
- },
175
- skeleton: {
176
- description: 'Loading placeholder block',
177
- registryItems: ['skeleton']
178
- },
179
- slider: {
180
- description: 'Range slider with one or more thumbs',
181
- registryItems: ['slider']
182
- },
183
- spinner: {
184
- description: 'Inline loading spinner',
185
- registryItems: ['spinner']
186
- },
187
- switch: {
188
- description: 'On/off toggle switch',
189
- registryItems: ['switch']
190
- },
191
- table: {
192
- description: 'Styled table primitives (header, body, rows, cells)',
193
- registryItems: ['table']
194
- },
195
- tabs: {
196
- description: 'Tabbed panels with a tab list',
197
- registryItems: ['tabs']
198
- },
199
- textarea: {
200
- description: 'Multi-line text input',
201
- registryItems: ['textarea']
202
- },
203
- 'toggle-group': {
204
- description: 'Group of two-state toggle buttons',
205
- registryItems: ['toggle-group']
206
- },
207
- tooltip: {
208
- description: 'Small label shown on hover or focus',
209
- registryItems: ['tooltip']
210
- }
17
+ type RegistryCatalogItem = {
18
+ name: string
19
+ type: string
20
+ files?: Array<{ path: string }>
21
+ registryDependencies?: string[]
211
22
  }
212
23
 
24
+ const REGISTRY_ITEMS = new Map(
25
+ (registry.items as RegistryCatalogItem[]).map(item => [item.name, item] as const)
26
+ )
27
+
28
+ export const UI_COMPONENTS: Record<string, UiComponentEntry> = Object.fromEntries(
29
+ registry.items
30
+ .filter(item => item.type === 'registry:ui' || item.type === 'registry:block')
31
+ .map(item => [item.name, { description: item.description ?? item.title ?? item.name }] as const)
32
+ .sort(([a], [b]) => a.localeCompare(b))
33
+ )
34
+
213
35
  export const UI_COMPONENT_NAMES = Object.keys(UI_COMPONENTS)
214
36
 
215
- // ---------------------------------------------------------------------------
216
- // Engine config — the in-memory replacement for components.json
217
- // ---------------------------------------------------------------------------
37
+ // The final path segment names the component file for built-in, namespaced,
38
+ // and GitHub registry addresses alike.
39
+ export function registryItemName(registryItem: string): string {
40
+ const withoutRef = registryItem.split('#', 1)[0]
41
+ return withoutRef.split('/').at(-1) ?? withoutRef
42
+ }
218
43
 
219
- // The whole point of driving the engine programmatically: this object stays
220
- // inside moi and the workspace never grows a components.json or tsconfig.
221
- // Aliases are placeholders the engine requires but never applies — raw
222
- // registry content hardcodes `@/registry/<style>/…` specifiers, which
223
- // rewriteRegistryImports below maps to relative paths.
224
- // Cast once to `never`: the engine functions accept `Partial<Config>`, but
225
- // shadcn exports no public name for that resolved Config type (only the
226
- // components.json shape) — `never` is assignable to every parameter type, and
227
- // nothing here reads the constant back.
228
- const ENGINE_CONFIG = {
229
- style: 'base-nova',
230
- tailwind: { css: 'unused.css', baseColor: 'neutral', cssVariables: true },
231
- rsc: false,
232
- tsx: true,
233
- iconLibrary: 'tabler',
234
- rtl: false,
235
- aliases: { ui: '@/components/ui', utils: '@/lib/utils' }
236
- } as never
44
+ // A block has no source of its own, so its direct component dependencies are
45
+ // the files users install and can later update with --force.
46
+ export function uiComponentFiles(name: string): string[] {
47
+ const files = new Set<string>()
48
+ const visited = new Set<string>()
237
49
 
238
- export const UI_DOCS_BASE = 'https://ui.shadcn.com/docs/components/base'
50
+ const collect = (itemName: string): void => {
51
+ if (visited.has(itemName)) return
52
+ visited.add(itemName)
239
53
 
240
- // ---------------------------------------------------------------------------
241
- // Fetching
242
- // ---------------------------------------------------------------------------
54
+ const item = REGISTRY_ITEMS.get(itemName)
55
+ if (!item) return
56
+ if (item.files?.length) {
57
+ for (const file of item.files) files.add(uiFileName(file.path))
58
+ return
59
+ }
60
+ for (const dependency of item.registryDependencies ?? []) {
61
+ collect(registryItemName(dependency))
62
+ }
63
+ }
243
64
 
244
- export type FetchedUiFile = {
65
+ collect(registryItemName(name))
66
+ return [...files]
67
+ }
68
+
69
+ export type LoadedUiFile = {
245
70
  // File name inside `.moi/ui/` (`button.tsx`, `utils.ts`).
246
71
  name: string
247
72
  content: string
248
73
  }
249
74
 
250
- export type FetchedUiComponents = {
251
- files: FetchedUiFile[]
75
+ export type LoadedUiComponents = {
76
+ files: LoadedUiFile[]
252
77
  // npm dependencies declared by the resolved registry items (versioned
253
78
  // specifiers like `recharts@3.8.0` pass through as-is).
254
79
  dependencies: string[]
255
80
  }
256
81
 
257
- // Where a registry file lands in `.moi/ui/`. Registry paths look like
258
- // `registry/base-nova/ui/button.tsx`, `registry/base-nova/lib/utils.ts`,
259
- // `registry/base-nova/hooks/use-mobile.ts` — everything flattens into the one
260
- // ui dir so relative imports stay `./<name>`.
261
82
  function uiFileName(registryPath: string): string {
262
83
  const base = registryPath.split('/').pop() ?? registryPath
263
84
  return base
264
85
  }
265
86
 
266
- // Fetch the requested registry items plus their registryDependencies, closed
267
- // transitively, deduplicated. `utils` (the `cn` helper) rides along on every
268
- // fetch — it is the one support file everything imports.
269
- export async function fetchUiComponents(registryNames: string[]): Promise<FetchedUiComponents> {
87
+ // Load requested items and their same-repository dependencies from the
88
+ // bundled registry. Files flatten into `.moi/ui/` so sibling imports
89
+ // stay relative.
90
+ export async function loadUiComponents(
91
+ registryNames: string[],
92
+ registryRoot: string = PACKAGE_ROOT
93
+ ): Promise<LoadedUiComponents> {
94
+ const { loadRegistryItem } = await import('shadcn/registry')
270
95
  const files = new Map<string, string>()
271
96
  const dependencies = new Set<string>()
272
- const fetched = new Set<string>()
273
- let queue = [...new Set(['utils', ...registryNames])]
97
+ const loaded = new Set<string>()
274
98
 
275
- const { getRegistryItems } = await import('shadcn/registry')
99
+ const loadItem = async (address: string): Promise<void> => {
100
+ const itemName = registryItemName(address)
101
+ if (loaded.has(itemName)) return
102
+ loaded.add(itemName)
276
103
 
277
- while (queue.length > 0) {
278
- const batch = queue.filter(name => !fetched.has(name))
279
- if (batch.length === 0) break
280
- for (const name of batch) fetched.add(name)
281
-
282
- const items = await getRegistryItems(batch, { config: ENGINE_CONFIG })
283
- const next: string[] = []
284
- for (const item of items ?? []) {
285
- for (const dep of item.dependencies ?? []) dependencies.add(dep)
286
- for (const dep of item.registryDependencies ?? []) {
287
- // Registry deps are plain item names for the shadcn registry; URLs
288
- // would point at third-party registries, which the curated set never
289
- // references.
290
- if (!fetched.has(dep)) next.push(dep)
291
- }
292
- for (const file of item.files ?? []) {
293
- if (!file.content) continue
294
- files.set(uiFileName(file.path), file.content)
104
+ const item = await loadRegistryItem(itemName, { cwd: registryRoot })
105
+ for (const file of item.files ?? []) {
106
+ if (!file.content) {
107
+ throw new Error(`Registry item "${itemName}" has a missing file: ${file.path}`)
295
108
  }
109
+ files.set(uiFileName(file.path), file.content)
110
+ }
111
+ for (const dependency of item.dependencies ?? []) dependencies.add(dependency)
112
+ for (const registryDependency of item.registryDependencies ?? []) {
113
+ await loadItem(registryDependency)
296
114
  }
297
- queue = next
298
115
  }
299
116
 
117
+ for (const name of new Set(registryNames)) await loadItem(name)
118
+
300
119
  return {
301
120
  files: [...files.entries()].map(([name, content]) => ({ name, content })),
302
121
  dependencies: [...dependencies].sort()
303
122
  }
304
123
  }
305
124
 
306
- // ---------------------------------------------------------------------------
307
- // Transforms
308
- // ---------------------------------------------------------------------------
309
-
310
- // Rewrite `@/registry/<style>/{lib,ui,hooks}/<x>` specifiers to sibling-relative
311
- // paths. There is no engine knob for this: aliases are validated against
312
- // tsconfig paths, so a relative alias value is rejected outright (verified —
313
- // see docs/moi-shadcn.md). Walks import AND export declarations on the same
314
- // ts-morph SourceFile the icon transform used, so re-exports are covered.
315
- function rewriteRegistryImports(sourceFile: SourceFile): void {
316
- const rewrite = (spec: string): string | null => {
317
- const match = /^@\/registry\/[^/]+\/(?:lib|ui|hooks)\/([\w-]+)$/.exec(spec)
318
- return match ? `./${match[1]}` : null
319
- }
320
- for (const decl of sourceFile.getImportDeclarations()) {
321
- const next = rewrite(decl.getModuleSpecifierValue())
322
- if (next) decl.setModuleSpecifier(next)
323
- }
324
- for (const decl of sourceFile.getExportDeclarations()) {
325
- const spec = decl.getModuleSpecifierValue()
326
- if (!spec) continue
327
- const next = rewrite(spec)
328
- if (next) decl.setModuleSpecifier(next)
329
- }
125
+ export async function loadUiComponentDocs(
126
+ registryName: string,
127
+ registryRoot: string = PACKAGE_ROOT
128
+ ): Promise<string> {
129
+ const itemName = registryItemName(registryName)
130
+ const path = join(registryRoot, 'ui-components', 'docs', `${itemName}.md`)
131
+ const file = Bun.file(path)
132
+ if (!(await file.exists())) throw new Error(`Missing local docs for "${itemName}": ${path}`)
133
+ return file.text()
330
134
  }
331
135
 
332
- // The portal codemod. Base UI overlays portal into document.body — outside
333
- // the applet container, so the applet's scoped styles ([data-applet="…"] …,
334
- // see server/bundler/applet-css.ts) stop matching and overlays render on
335
- // accidentally borrowed host styles. Overlays should keep portalling to body
336
- // (escaping the widget frame's overflow/stacking is the point) — so instead
337
- // of re-containering them, every `<X.Portal …>` JSX element is rewritten to
338
- // `<AppletPortal portal={X.Portal} …>`, a wrapper (installed as
339
- // `ui/applet-portal.tsx`) that re-establishes the scope attribute on the
340
- // portalled subtree. Type positions (`X.Portal.Props`) are untouched — the
341
- // rewrite only sees JSX tag names.
342
- // `SyntaxKind` is passed in rather than imported: ts-morph is loaded lazily by
343
- // the one caller below, so this helper cannot close over a module-level import.
344
- function rewritePortals(
345
- sourceFile: SourceFile,
346
- SyntaxKind: typeof import('ts-morph').SyntaxKind
347
- ): boolean {
348
- const PORTAL_TAG = /^[A-Za-z_$][\w$]*\.Portal$/
349
- let touched = false
350
-
351
- for (const el of sourceFile.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement)) {
352
- if (!PORTAL_TAG.test(el.getTagNameNode().getText())) continue
353
- const portalExpr = el.getTagNameNode().getText()
354
- el.getTagNameNode().replaceWithText('AppletPortal')
355
- el.insertAttribute(0, { name: 'portal', initializer: `{${portalExpr}}` })
356
- touched = true
357
- }
358
- for (const el of sourceFile.getDescendantsOfKind(SyntaxKind.JsxElement)) {
359
- const opening = el.getOpeningElement()
360
- if (!PORTAL_TAG.test(opening.getTagNameNode().getText())) continue
361
- const portalExpr = opening.getTagNameNode().getText()
362
- opening.getTagNameNode().replaceWithText('AppletPortal')
363
- el.getClosingElement().getTagNameNode().replaceWithText('AppletPortal')
364
- opening.insertAttribute(0, { name: 'portal', initializer: `{${portalExpr}}` })
365
- touched = true
366
- }
367
-
368
- if (touched) {
369
- sourceFile.addImportDeclaration({
370
- moduleSpecifier: './applet-portal',
371
- namedImports: [{ name: 'AppletPortal' }]
372
- })
373
- }
374
- return touched
375
- }
376
-
377
- // One shared ts-morph project for all transforms in a process — creating a
378
- // Project per file re-parses lib.d.ts and dominates runtime.
379
- let project: Project | undefined
380
-
381
- // Apply moi's transform pipeline to one raw registry file: shadcn's own icon
382
- // transform (IconPlaceholder → @tabler/icons-react) and menu transform
383
- // (cn-menu-* classes for the default menu color), then the relative-import
384
- // rewrite and the portal codemod.
385
- export async function transformUiComponentSource(name: string, raw: string): Promise<string> {
386
- const { Project, ScriptKind, SyntaxKind } = await import('ts-morph')
387
- const { transformIcons, transformMenu } = await import('shadcn/utils')
388
-
389
- project ??= new Project({ useInMemoryFileSystem: true })
390
- const sourceFile = project.createSourceFile(`moi-ui/${name}`, raw, {
391
- scriptKind: name.endsWith('.tsx') ? ScriptKind.TSX : ScriptKind.TS,
392
- overwrite: true
393
- })
394
- const opts = { sourceFile, filename: name, raw, config: ENGINE_CONFIG }
395
- await transformIcons(opts)
396
- await transformMenu(opts)
397
- rewriteRegistryImports(sourceFile)
398
- rewritePortals(sourceFile, SyntaxKind)
399
- return sourceFile.getFullText()
400
- }
401
-
402
- // ---------------------------------------------------------------------------
403
- // The AppletPortal helper — installed once as `ui/applet-portal.tsx`
404
- // ---------------------------------------------------------------------------
405
-
406
- // Embedded as a string like the other scaffold templates (see
407
- // moi-scaffold.ts): the file belongs to the workspace, not to moi's bundle.
408
- // The hidden marker renders where the overlay is used — inside the applet's
409
- // DOM — and reads the nearest `data-applet` scope; the portalled children
410
- // then render under an element carrying the same attribute, so the applet's
411
- // scoped CSS matches again. `display: contents` keeps the wrapper out of
412
- // layout; theme variables still resolve from the host `:root`.
413
- //
414
- // The file header below is written for its actual reader — the workspace
415
- // agent browsing `.moi/ui/` — so it stays non-technical: what the file is
416
- // for, that it's auto-generated, and that it must be left alone. The
417
- // mechanism belongs here, not there.
418
- export const APPLET_PORTAL_SOURCE = `"use client"
419
-
420
- // Auto-generated by \`moi ui-components add\` — do not edit or remove.
421
- //
422
- // Keeps overlays (dialogs, menus, popovers, tooltips) styled correctly when
423
- // they render outside the applet's own container. Components in this folder
424
- // use it automatically; you never import it yourself.
425
- import * as React from "react"
426
-
427
- type AppletPortalProps = {
428
- portal: React.ElementType
429
- children?: React.ReactNode
430
- } & Record<string, unknown>
431
-
432
- function AppletPortal({ portal: Portal, children, ...props }: AppletPortalProps) {
433
- const [scope, setScope] = React.useState<string | undefined>(undefined)
434
- const marker = React.useCallback((node: HTMLElement | null) => {
435
- if (node) {
436
- setScope(node.closest("[data-applet]")?.getAttribute("data-applet") ?? undefined)
437
- }
438
- }, [])
439
- return (
440
- <>
441
- <span hidden ref={marker} />
442
- <Portal {...props}>
443
- <div data-applet={scope} style={{ display: "contents" }}>
444
- {children}
445
- </div>
446
- </Portal>
447
- </>
448
- )
449
- }
450
-
451
- export { AppletPortal }
452
- `
453
-
454
136
  // ---------------------------------------------------------------------------
455
137
  // Name resolution + write planning (pure — covered by tests)
456
138
  // ---------------------------------------------------------------------------
457
139
 
458
140
  export type ResolvedRequest = {
459
- // Curated entries requested, validated.
141
+ // Registry items requested, validated and deduplicated.
460
142
  entries: string[]
461
- // Registry items to fetch (patterns expanded), deduplicated, in request order.
462
- registryItems: string[]
463
- // Union of extraDeps across the requested entries.
464
- extraDeps: string[]
465
143
  unknown: string[]
466
144
  }
467
145
 
468
146
  export function resolveUiComponentRequest(names: string[]): ResolvedRequest {
469
147
  const entries: string[] = []
470
- const registryItems: string[] = []
471
- const extraDeps = new Set<string>()
472
148
  const unknown: string[] = []
473
149
 
474
150
  for (const raw of names) {
@@ -478,14 +154,11 @@ export function resolveUiComponentRequest(names: string[]): ResolvedRequest {
478
154
  unknown.push(raw)
479
155
  continue
480
156
  }
481
- if (!entries.includes(name)) entries.push(name)
482
- for (const item of entry.registryItems) {
483
- if (!registryItems.includes(item)) registryItems.push(item)
484
- }
485
- for (const dep of entry.extraDeps ?? []) extraDeps.add(dep)
157
+ if (entries.includes(name)) continue
158
+ entries.push(name)
486
159
  }
487
160
 
488
- return { entries, registryItems, extraDeps: [...extraDeps].sort(), unknown }
161
+ return { entries, unknown }
489
162
  }
490
163
 
491
164
  // Closest catalog names for a typo, by shared-prefix + substring heuristics —
@@ -520,7 +193,7 @@ export type PlannedWrite = {
520
193
  content: string
521
194
  // Whether a file already exists at the target path.
522
195
  exists: boolean
523
- // Support files ride along with a request (utils, applet-portal, registry
196
+ // Support files ride along with a request (utils, scoped-portal, registry
524
197
  // deps of a requested component). Existing support files are never
525
198
  // overwritten — they may carry hand customizations; existing requested
526
199
  // files fail the add unless --force.
@@ -536,9 +209,6 @@ export type UiWritePartition = {
536
209
  // Requested components already installed, skipped without --force — a bulk
537
210
  // add proceeds past them instead of failing the whole batch.
538
211
  skipInstalled: PlannedWrite[]
539
- // Every requested file already exists and --force is off: the add would be
540
- // a no-op, so the CLI fails loudly instead of quietly keeping everything.
541
- allInstalled: boolean
542
212
  }
543
213
 
544
214
  export function partitionUiWrites(plans: PlannedWrite[], force: boolean): UiWritePartition {
@@ -547,28 +217,25 @@ export function partitionUiWrites(plans: PlannedWrite[], force: boolean): UiWrit
547
217
  return {
548
218
  write: plans.filter(plan => !plan.exists || (force && !plan.support)),
549
219
  keepSupport: plans.filter(plan => plan.support && plan.exists),
550
- skipInstalled,
551
- allInstalled: !force && requested.length > 0 && skipInstalled.length === requested.length
220
+ skipInstalled
552
221
  }
553
222
  }
554
223
 
555
224
  export function planUiWrites(opts: {
556
- files: FetchedUiFile[]
557
- requestedItems: string[]
225
+ files: LoadedUiFile[]
226
+ requestedFiles: string[]
558
227
  uiDir: string
559
228
  exists: (path: string) => boolean
560
229
  }): PlannedWrite[] {
561
- const requested = new Set(opts.requestedItems.map(item => `${item}.tsx`))
562
- const plans: PlannedWrite[] = [
563
- ...opts.files.map(file => ({
564
- name: file.name,
565
- content: file.content,
566
- support: !requested.has(file.name)
567
- })),
568
- { name: 'applet-portal.tsx', content: APPLET_PORTAL_SOURCE, support: true }
569
- ].map(file => {
230
+ const requested = new Set(opts.requestedFiles)
231
+ const plans: PlannedWrite[] = opts.files.map(file => {
570
232
  const path = join(opts.uiDir, file.name)
571
- return { ...file, path, exists: opts.exists(path) }
233
+ return {
234
+ ...file,
235
+ path,
236
+ exists: opts.exists(path),
237
+ support: !requested.has(file.name)
238
+ }
572
239
  })
573
240
  return plans
574
241
  }
@@ -14,6 +14,7 @@ type ViewBuilderStore = Record<string, ViewBuilder[]>
14
14
  // `waiting`, even if its session still looks live. Generous so a slow but real
15
15
  // build is never cut off mid-flight.
16
16
  const STALE_BUILD_MS = 10 * 60_000
17
+ const APP_ICON_NAMES: readonly string[] = APP_ICON_IDS
17
18
 
18
19
  export class ViewBuilderError extends Error {
19
20
  status: 400 | 404 | 409
@@ -198,7 +199,7 @@ export async function setBuilder(
198
199
  }
199
200
  if (input.icon !== undefined && !isAppIconId(input.icon)) {
200
201
  throw new ViewBuilderError(
201
- `Unknown view icon id "${input.icon}". Use one of: ${APP_ICON_IDS.join(', ')}`,
202
+ `Unknown view icon id "${input.icon}". Use one of: ${APP_ICON_NAMES.join(', ')}`,
202
203
  400
203
204
  )
204
205
  }