moi-computer 0.3.0-next.1 → 0.3.0-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 (146) hide show
  1. package/bunfig.toml +5 -1
  2. package/client/AGENTS.md +15 -0
  3. package/client/accept-hmr-dependencies.ts +22 -0
  4. package/client/api/http.ts +31 -0
  5. package/client/api/query-options.ts +6 -0
  6. package/client/api/workspace-keys.ts +17 -0
  7. package/client/app/AppRouter.tsx +35 -0
  8. package/client/app/routes/HomeRoute.tsx +13 -0
  9. package/client/app/routes/WorkspaceRoute.tsx +89 -0
  10. package/client/app/shell/SidebarLayout.tsx +191 -0
  11. package/client/assets.d.ts +9 -0
  12. package/client/components/playground/PixelPainter.tsx +10 -21
  13. package/client/components/playground/PlaygroundPage.tsx +9 -11
  14. package/client/components/playground/ToolCallsPage.tsx +9 -11
  15. package/client/components/{BottomPanel.tsx → shared/BottomPanel.tsx} +1 -1
  16. package/client/components/shared/PanelHeader.tsx +9 -0
  17. package/client/components/shared/ReorderableList.tsx +199 -0
  18. package/client/components/ui/button.tsx +10 -7
  19. package/client/components/ui/collapsible.tsx +15 -0
  20. package/client/components/ui/dialog.tsx +2 -2
  21. package/client/components/ui/dropdown-menu.tsx +5 -5
  22. package/client/components/ui/hover-card.tsx +1 -1
  23. package/client/components/ui/popover.tsx +1 -1
  24. package/client/components/ui/skeleton.tsx +13 -0
  25. package/client/components/ui/tooltip.tsx +1 -1
  26. package/client/externalize-react.ts +7 -1
  27. package/client/{components → features/applets}/WidgetErrorBoundary.tsx +1 -1
  28. package/client/{components → features/applets}/WidgetShell.tsx +1 -1
  29. package/client/{hooks → features/applets}/useApplet.ts +6 -7
  30. package/client/{components/ChatInput.tsx → features/chat/ChatComposer.tsx} +29 -23
  31. package/client/features/chat/ChatPanel.tsx +188 -0
  32. package/client/{components → features/chat}/ChatPopup.tsx +23 -12
  33. package/client/{components → features/chat}/MarkdownContent.tsx +1 -1
  34. package/client/{components → features/chat}/ModelPicker.tsx +68 -17
  35. package/client/{components → features/chat}/ThreadSelector.tsx +11 -9
  36. package/client/{components → features/chat}/TurnView.tsx +16 -9
  37. package/client/features/chat/api.ts +78 -0
  38. package/client/features/chat/chat-connection.ts +107 -0
  39. package/client/features/chat/chat-frames.ts +131 -0
  40. package/client/{lib → features/chat}/preview-turn.ts +1 -1
  41. package/client/{components → features/chat}/tool-group/ReadImagePreview.tsx +1 -1
  42. package/client/{components → features/chat}/tool-group/SubagentCard.tsx +12 -10
  43. package/client/{components → features/chat}/tool-group/TimelineRow.tsx +5 -5
  44. package/client/{components → features/chat}/tool-group/ToolCallGroup.tsx +12 -4
  45. package/client/{components → features/chat}/tool-group/ToolOutput.tsx +12 -18
  46. package/client/{hooks → features/chat}/useChat.ts +7 -11
  47. package/client/features/connectors/ConnectorsPage.tsx +92 -0
  48. package/client/features/connectors/McpMenu.tsx +162 -0
  49. package/client/features/connectors/api.ts +28 -0
  50. package/client/features/home/CreateWorkspaceDialog.tsx +224 -0
  51. package/client/features/home/HomePage.tsx +220 -0
  52. package/client/{components → features/home}/WorkspacePreview.tsx +2 -2
  53. package/client/features/home/api.ts +148 -0
  54. package/client/features/home/workspace-presentation.tsx +44 -0
  55. package/client/features/scratchpad/Scratchpad.tsx +312 -0
  56. package/client/features/scratchpad/ScratchpadControls.tsx +503 -0
  57. package/client/features/scratchpad/useScratchpadSnapshot.tsx +115 -0
  58. package/client/features/settings/EnvironmentSettings.tsx +149 -0
  59. package/client/features/settings/GeneralSettings.tsx +90 -0
  60. package/client/{components → features}/settings/IconPicker.tsx +73 -222
  61. package/client/features/settings/SettingsLayout.tsx +53 -0
  62. package/client/{components → features}/settings/WorkspaceSettings.tsx +12 -16
  63. package/client/features/settings/api.ts +88 -0
  64. package/client/features/settings/icon-picker-options.ts +161 -0
  65. package/client/{hooks → features/settings}/useEnvVars.ts +4 -4
  66. package/client/{components → features/widgets}/HiddenPanel.tsx +3 -3
  67. package/client/{components → features/widgets}/WidgetFrame.tsx +3 -8
  68. package/client/{components → features/widgets}/WidgetGrid.tsx +2 -9
  69. package/client/features/widgets/Widgets.tsx +215 -0
  70. package/client/{lib/grid-pack.ts → features/widgets/grid.ts} +7 -1
  71. package/client/{hooks → features/widgets}/useGridReconcile.ts +1 -1
  72. package/client/{components → features/workspace}/CustomizePanel.tsx +5 -6
  73. package/client/{lib → features/workspace}/WorkspaceLayoutContext.tsx +15 -8
  74. package/client/features/workspace/WorkspaceScreen.tsx +536 -0
  75. package/client/features/workspace/WorkspaceTabs.tsx +205 -0
  76. package/client/features/workspace/api.ts +56 -0
  77. package/client/features/workspace/useFitsSplitLayout.ts +37 -0
  78. package/client/global.d.ts +5 -0
  79. package/client/index.css +6 -10
  80. package/client/index.html +1 -1
  81. package/client/index.tsx +14 -31
  82. package/client/main.tsx +2 -2
  83. package/client/runtime/hmr-watchdog.ts +39 -0
  84. package/client/{hooks/useMeiEvents.ts → runtime/useWorkspaceEvents.ts} +9 -6
  85. package/client/store/ui.ts +5 -1
  86. package/client/theme.css +0 -2
  87. package/dist/chunk-11cab5dq.css +1 -0
  88. package/dist/chunk-23cgr1tz.css +1 -0
  89. package/dist/chunk-3hy3qy6d.js +10 -0
  90. package/dist/chunk-c4j722at.js +546 -0
  91. package/dist/chunk-dyfaffyz.js +119 -0
  92. package/dist/chunk-kpe40hm8.js +1 -0
  93. package/dist/chunk-p68fnz3q.js +2 -0
  94. package/dist/chunk-pcnahct1.js +5 -0
  95. package/dist/chunk-tqd3pkg8.css +1 -0
  96. package/dist/chunk-ty6dvda0.js +1 -0
  97. package/dist/index.html +2 -2
  98. package/lib/types.ts +18 -7
  99. package/lib/workspace-name.ts +14 -0
  100. package/package.json +3 -2
  101. package/server/api.ts +119 -14
  102. package/server/cli.ts +11 -5
  103. package/server/layout.ts +38 -7
  104. package/server/mcp.ts +72 -15
  105. package/server/moi-scaffold.ts +55 -10
  106. package/server/registry.ts +16 -0
  107. package/server/web.ts +1 -0
  108. package/server/workspace-init.ts +5 -19
  109. package/tsconfig.json +1 -1
  110. package/workspace/.claude/skills/moi-workspace/DESIGN.md +1 -1
  111. package/workspace/.claude/skills/moi-workspace/VIEW-DESIGN.md +1 -1
  112. package/client/api/workspaces.ts +0 -427
  113. package/client/components/App.tsx +0 -41
  114. package/client/components/ChatPanel.tsx +0 -275
  115. package/client/components/HomePage.tsx +0 -17
  116. package/client/components/McpMenu.tsx +0 -125
  117. package/client/components/Scratchpad.tsx +0 -935
  118. package/client/components/Widgets.tsx +0 -132
  119. package/client/components/WorkspacesPage.tsx +0 -245
  120. package/client/components/layout/SidebarLayout.tsx +0 -258
  121. package/client/components/routes/workspace/[id].tsx +0 -675
  122. package/client/components/routes/workspace/create.tsx +0 -155
  123. package/client/components/settings/SettingsPages.tsx +0 -255
  124. package/client/hooks/useFitsSidebar.ts +0 -34
  125. package/client/lib/connection.ts +0 -238
  126. package/dist/chunk-07qf2tv1.css +0 -1
  127. package/dist/chunk-w18801vn.js +0 -672
  128. /package/client/components/{playground → shared}/LedLogo.tsx +0 -0
  129. /package/client/{lib → features/applets}/applet-cache.ts +0 -0
  130. /package/client/{components → features/chat}/ShimmerText.tsx +0 -0
  131. /package/client/{store/live.ts → features/chat/chat-store.ts} +0 -0
  132. /package/client/{lib → features/chat}/group-turns.ts +0 -0
  133. /package/client/{components → features/chat}/tool-group/CodeBlock.tsx +0 -0
  134. /package/client/{components → features/chat}/tool-group/Collapse.tsx +0 -0
  135. /package/client/{components → features/chat}/tool-group/detect.ts +0 -0
  136. /package/client/{components → features/chat}/tool-group/fixtures.ts +0 -0
  137. /package/client/{components → features/chat}/tool-group/format.ts +0 -0
  138. /package/client/{components → features/chat}/tool-group/index.ts +0 -0
  139. /package/client/{lib → features/chat}/uploads.ts +0 -0
  140. /package/client/{hooks → features/chat}/useStickToBottom.ts +0 -0
  141. /package/client/{components → features/connectors}/IconMcp.tsx +0 -0
  142. /package/client/{lib → features/connectors}/mcp-icons.ts +0 -0
  143. /package/client/{lib → features/scratchpad}/scratch-executor.ts +0 -0
  144. /package/client/{lib → features/settings}/render-icon.ts +0 -0
  145. /package/client/{lib → features/workspace}/WorkspaceContext.tsx +0 -0
  146. /package/client/{hooks → features/workspace}/useWorkspaceTheme.ts +0 -0
@@ -0,0 +1,205 @@
1
+ import { IconPlus, IconX, type TablerIcon } from '@tabler/icons-react'
2
+ import { cva } from 'class-variance-authority'
3
+
4
+ import { ReorderableList } from '@/client/components/shared/ReorderableList'
5
+ import type { ReorderableRenderState } from '@/client/components/shared/ReorderableList'
6
+ import { Button, buttonVariants } from '@/client/components/ui/button'
7
+ import {
8
+ DropdownMenu,
9
+ DropdownMenuContent,
10
+ DropdownMenuGroup,
11
+ DropdownMenuItem,
12
+ DropdownMenuTrigger
13
+ } from '@/client/components/ui/dropdown-menu'
14
+ import { cn } from '@/client/lib/cn'
15
+ import type { WorkspaceTabId } from '@/lib/types'
16
+
17
+ export type WorkspaceTabItem = {
18
+ key: WorkspaceTabId
19
+ Icon: TablerIcon
20
+ label: string
21
+ closable?: boolean
22
+ }
23
+
24
+ export type CreateWorkspaceTabItem = {
25
+ key: string
26
+ Icon: TablerIcon
27
+ label: string
28
+ onClick: () => void
29
+ }
30
+
31
+ type WorkspaceTabsProps = {
32
+ tabs: WorkspaceTabItem[]
33
+ active: WorkspaceTabId
34
+ createItems: CreateWorkspaceTabItem[]
35
+ onSelect: (tab: WorkspaceTabId) => void
36
+ onClose: (tab: WorkspaceTabId) => void
37
+ onReorder: (ordered: WorkspaceTabId[]) => void
38
+ }
39
+
40
+ const workspaceTabVariants = cva(
41
+ [buttonVariants({ variant: 'ghost', size: 'sm' }), 'group/tab min-w-0'],
42
+ {
43
+ variants: {
44
+ active: {
45
+ true: 'bg-accent text-accent-foreground'
46
+ },
47
+ dragging: {
48
+ true: 'invisible'
49
+ },
50
+ preview: {
51
+ true: 'cursor-grabbing ring-1 ring-border'
52
+ }
53
+ },
54
+ compoundVariants: [{ preview: true }]
55
+ }
56
+ )
57
+
58
+ function CreateTabMenu({ items }: { items: CreateWorkspaceTabItem[] }) {
59
+ return (
60
+ <DropdownMenu>
61
+ <DropdownMenuTrigger
62
+ render={
63
+ <Button
64
+ type="button"
65
+ variant="ghost"
66
+ size="icon-sm"
67
+ className="text-muted-foreground"
68
+ aria-label="Create tab"
69
+ >
70
+ <IconPlus stroke={1.75} />
71
+ </Button>
72
+ }
73
+ />
74
+ <DropdownMenuContent align="start" className="min-w-48">
75
+ <DropdownMenuGroup>
76
+ {items.map(({ key, Icon, label, onClick }) => (
77
+ <DropdownMenuItem key={key} onClick={onClick}>
78
+ <Icon stroke={1.75} />
79
+ {label}
80
+ </DropdownMenuItem>
81
+ ))}
82
+ </DropdownMenuGroup>
83
+ </DropdownMenuContent>
84
+ </DropdownMenu>
85
+ )
86
+ }
87
+
88
+ type WorkspaceTabBaseProps = {
89
+ tab: WorkspaceTabItem
90
+ active: boolean
91
+ }
92
+
93
+ type WorkspaceTabProps = WorkspaceTabBaseProps &
94
+ (
95
+ | {
96
+ preview: true
97
+ state?: never
98
+ onSelect?: never
99
+ onClose?: never
100
+ }
101
+ | {
102
+ preview?: false
103
+ state: ReorderableRenderState
104
+ onSelect: (tab: WorkspaceTabId) => void
105
+ onClose: (tab: WorkspaceTabId) => void
106
+ }
107
+ )
108
+
109
+ function WorkspaceTab(props: WorkspaceTabProps) {
110
+ const { tab, active } = props
111
+ const preview = props.preview === true
112
+
113
+ return (
114
+ <button
115
+ type="button"
116
+ aria-hidden={preview || undefined}
117
+ aria-label={tab.label}
118
+ disabled={preview}
119
+ tabIndex={preview ? -1 : undefined}
120
+ onClick={props.preview ? undefined : () => props.onSelect(tab.key)}
121
+ className={workspaceTabVariants({
122
+ active,
123
+ dragging: props.preview ? false : props.state.isDragging,
124
+ preview
125
+ })}
126
+ {...(props.preview ? {} : props.state.dragHandleProps)}
127
+ >
128
+ <div
129
+ className={cn(
130
+ 'flex items-center gap-1 overflow-hidden',
131
+ tab.closable && 'group-hover/tab:mr-3'
132
+ )}
133
+ >
134
+ <tab.Icon data-icon="inline-start" stroke={1.75} />
135
+ <span
136
+ className={cn(
137
+ 'truncate',
138
+ tab.closable &&
139
+ 'group-hover/tab:-mr-3 group-hover/tab:mask-r-from-[calc(100%-24px)] group-hover/tab:mask-r-to-[calc(100%-12px)]'
140
+ )}
141
+ >
142
+ {tab.label}
143
+ </span>
144
+ </div>
145
+ {tab.closable && (
146
+ <div
147
+ aria-label={`Close ${tab.label}`}
148
+ tabIndex={preview ? -1 : undefined}
149
+ className={cn(
150
+ 'absolute right-2 hidden size-3 items-center justify-center text-muted-foreground group-hover/tab:flex hover:text-foreground',
151
+ preview && 'pointer-events-none'
152
+ )}
153
+ onClick={
154
+ props.preview
155
+ ? undefined
156
+ : event => {
157
+ event.stopPropagation()
158
+ props.onClose(tab.key)
159
+ }
160
+ }
161
+ >
162
+ <IconX stroke={1.75} />
163
+ </div>
164
+ )}
165
+ </button>
166
+ )
167
+ }
168
+
169
+ export function WorkspaceTabs({
170
+ tabs,
171
+ active,
172
+ createItems,
173
+ onSelect,
174
+ onClose,
175
+ onReorder
176
+ }: WorkspaceTabsProps) {
177
+ return (
178
+ <div className="flex min-w-0 flex-1 items-center gap-1">
179
+ <div className="scrollbar-none min-w-0 scroll-fade-x overflow-x-auto overflow-y-hidden [--scroll-fade-reveal:16px]">
180
+ <ReorderableList
181
+ items={tabs}
182
+ getId={tab => tab.key}
183
+ className="flex w-max items-center gap-1"
184
+ onReorder={ordered => onReorder(ordered as WorkspaceTabId[])}
185
+ renderPlaceholder={() => (
186
+ <div className="pointer-events-none absolute inset-0 rounded-xs bg-muted" />
187
+ )}
188
+ renderOverlay={tab => <WorkspaceTab tab={tab} active={active === tab.key} preview />}
189
+ renderItem={(tab, state) => (
190
+ <WorkspaceTab
191
+ tab={tab}
192
+ active={active === tab.key}
193
+ state={state}
194
+ onSelect={onSelect}
195
+ onClose={onClose}
196
+ />
197
+ )}
198
+ />
199
+ </div>
200
+ <div className="shrink-0">
201
+ <CreateTabMenu items={createItems} />
202
+ </div>
203
+ </div>
204
+ )
205
+ }
@@ -0,0 +1,56 @@
1
+ import { useMutation, useQuery } from '@tanstack/react-query'
2
+
3
+ import { jsonRequest, requestJson, requestVoid } from '@/client/api/http'
4
+ import { WORKSPACE_RESOURCE_OPTIONS } from '@/client/api/query-options'
5
+ import { workspaceKeys } from '@/client/api/workspace-keys'
6
+ import type { ViewInfo, WidgetInfo, WorkspaceLayout, WorkspaceType } from '@/lib/types'
7
+
8
+ export type WorkspaceLayoutResponse = WorkspaceLayout & {
9
+ cwd: string
10
+ name: string
11
+ provider?: WorkspaceType
12
+ agentId?: string
13
+ }
14
+
15
+ export function useWorkspaceLayout(workspaceId: string) {
16
+ return useQuery<WorkspaceLayoutResponse>({
17
+ queryKey: workspaceKeys.layout(workspaceId),
18
+ queryFn: () => requestJson(`/api/workspaces/${workspaceId}`),
19
+ ...WORKSPACE_RESOURCE_OPTIONS
20
+ })
21
+ }
22
+
23
+ export function useWorkspaceWidgets(workspaceId: string) {
24
+ return useQuery<WidgetInfo[]>({
25
+ queryKey: workspaceKeys.widgets(workspaceId),
26
+ queryFn: async () => {
27
+ const data = await requestJson<{ widgets: WidgetInfo[] }>(
28
+ `/api/workspaces/${workspaceId}/widgets`
29
+ )
30
+ return data.widgets
31
+ },
32
+ ...WORKSPACE_RESOURCE_OPTIONS
33
+ })
34
+ }
35
+
36
+ export function useWorkspaceViews(workspaceId: string) {
37
+ return useQuery<ViewInfo[]>({
38
+ queryKey: workspaceKeys.views(workspaceId),
39
+ queryFn: async () => {
40
+ const data = await requestJson<{ views: ViewInfo[] }>(`/api/workspaces/${workspaceId}/views`)
41
+ return data.views
42
+ },
43
+ ...WORKSPACE_RESOURCE_OPTIONS
44
+ })
45
+ }
46
+
47
+ export function useSaveLayout(workspaceId: string) {
48
+ return useMutation<void, Error, WorkspaceLayout>({
49
+ mutationFn: layout =>
50
+ requestVoid(
51
+ `/api/workspaces/${workspaceId}`,
52
+ jsonRequest('PUT', layout),
53
+ 'Failed to save layout'
54
+ )
55
+ })
56
+ }
@@ -0,0 +1,37 @@
1
+ import { useLayoutEffect, useRef, useState } from 'react'
2
+
3
+ function tokenPx(name: string): number {
4
+ const root = document.documentElement
5
+ const raw = getComputedStyle(root).getPropertyValue(name).trim()
6
+ const value = Number.parseFloat(raw)
7
+ if (!Number.isFinite(value)) return 0
8
+ return raw.endsWith('rem') ? value * Number.parseFloat(getComputedStyle(root).fontSize) : value
9
+ }
10
+
11
+ // Observe the full workspace row, not either pane, so split-fit measurement does
12
+ // not oscillate when the chat column appears or disappears.
13
+ export function useFitsSplitLayout<T extends HTMLElement>() {
14
+ const ref = useRef<T>(null)
15
+ const [fits, setFits] = useState(false)
16
+
17
+ useLayoutEffect(() => {
18
+ const el = ref.current
19
+ if (!el) return
20
+
21
+ const update = (width: number) => {
22
+ const columnWidth = tokenPx('--column-w')
23
+ const chatMin = tokenPx('--chat-min')
24
+ setFits(width - chatMin >= columnWidth)
25
+ }
26
+
27
+ update(el.getBoundingClientRect().width)
28
+
29
+ const ro = new ResizeObserver(([entry]) => {
30
+ if (entry) update(entry.contentRect.width)
31
+ })
32
+ ro.observe(el)
33
+ return () => ro.disconnect()
34
+ }, [])
35
+
36
+ return { ref, fits }
37
+ }
@@ -0,0 +1,5 @@
1
+ declare global {
2
+ var __init: (element: HTMLElement) => Promise<void>
3
+ }
4
+
5
+ export {}
package/client/index.css CHANGED
@@ -22,21 +22,19 @@
22
22
  --popover-foreground: oklch(0.145 0 0);
23
23
  --primary: oklch(0.205 0 0);
24
24
  --primary-foreground: oklch(0.985 0 0);
25
- --secondary: oklch(0.97 0 0);
26
- --secondary-foreground: oklch(0.205 0 0);
27
25
  --muted: oklch(0.97 0 0);
28
26
  --muted-foreground: oklch(0.64 0 0);
29
- --accent: oklch(0.97 0 0);
27
+ --accent: oklch(0 0 0 / 0.07);
30
28
  --accent-foreground: oklch(0.205 0 0);
31
29
  --destructive: oklch(0.58 0.22 27);
32
- --border: oklch(0.922 0 0);
30
+ --border: oklch(0 0 0 / 0.07);
33
31
  --input: oklch(0.922 0 0);
34
32
  --ring: oklch(0.708 0 0);
35
33
  --radius: 1rem;
36
34
 
37
35
  /* Workspace page layout — single source of truth for the widget/chat panel.
38
- Read by routes/workspace/[id].tsx and useFitsSidebar.ts; don't hardcode
39
- equivalents. (The app sidebar's own widths live in SidebarLayout.tsx.) */
36
+ Read by routes/workspace/[id].tsx; don't hardcode equivalents. (The app
37
+ sidebar's own widths live in SidebarLayout.tsx.) */
40
38
  --page-pad: 2rem; /* padding around the working area */
41
39
  --column-w: 40rem; /* grid content width; also the widget area's min before the chat yields */
42
40
  --chat-min: 380px; /* docked chat min width — narrower than this and it floats */
@@ -65,14 +63,12 @@
65
63
  --popover-foreground: oklch(0.985 0 0);
66
64
  --primary: oklch(0.985 0 0);
67
65
  --primary-foreground: oklch(0.205 0 0);
68
- --secondary: oklch(0.269 0 0);
69
- --secondary-foreground: oklch(0.985 0 0);
70
66
  --muted: oklch(0.269 0 0);
71
67
  --muted-foreground: oklch(0.708 0 0);
72
- --accent: oklch(0.269 0 0);
68
+ --accent: oklch(1 0 0 / 0.1);
73
69
  --accent-foreground: oklch(0.985 0 0);
74
70
  --destructive: oklch(0.58 0.22 27);
75
- --border: oklch(0.35 0 0);
71
+ --border: oklch(1 0 0 / 0.1);
76
72
  --input: oklch(0.35 0 0);
77
73
  --ring: oklch(0.556 0 0);
78
74
  }
package/client/index.html CHANGED
@@ -3,7 +3,7 @@
3
3
  <head>
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <title>moi.computer</title>
6
+ <title>moi</title>
7
7
  <link rel="icon" type="image/png" href="./assets/favicon.png" />
8
8
  <!-- React is vendored locally (client/vendor/react, generated by
9
9
  scripts/build-vendor.ts) and served by the /vendor/react route, so Moi
package/client/index.tsx CHANGED
@@ -3,38 +3,21 @@ import './structured-clone-shim'
3
3
 
4
4
  import './index.css'
5
5
 
6
- // React is externalized to the locally-vendored ESM (see client/externalize-react.ts
7
- // + the importmap in index.html → /vendor/react), so Bun's bundled Fast Refresh
8
- // runtime isn't bound to the React
9
- // instance that actually renders the app: it registers component families but
10
- // performReactRefresh() no-ops, leaving stale modules mounted after an edit.
11
- // Downgrade HMR to plain live-reload — every hot update triggers a full page
12
- // reload, which re-fetches a clean bundle. Dead-code-eliminated in production.
13
- if (import.meta.hot) {
14
- import.meta.hot.on('bun:beforeUpdate', () => location.reload())
6
+ import { startHmrWatchdog } from './runtime/hmr-watchdog'
15
7
 
16
- // Bun's HMR client (≤1.3.14) never re-arms `onclose` on the socket it
17
- // creates while reconnecting, so the second disconnect in a tab's life
18
- // (e.g. laptop sleep, then a dev-supervisor restart) silently kills
19
- // live-reload and the tab serves a stale bundle forever. Watchdog: poll
20
- // the shell and hard-reload when the served script generation no longer
21
- // matches the one this page is running.
22
- const devScript = document.querySelector<HTMLScriptElement>('[data-bun-dev-server-script]')
23
- if (devScript) {
24
- const scriptPath = new URL(devScript.src).pathname
25
- const checkStale = async () => {
26
- try {
27
- const html = await (await fetch('/', { cache: 'no-store' })).text()
28
- if (!html.includes(scriptPath)) location.reload()
29
- } catch {
30
- // server mid-restart — the next tick will catch it
31
- }
32
- }
33
- setInterval(checkStale, 5_000)
34
- document.addEventListener('visibilitychange', () => {
35
- if (document.visibilityState === 'visible') checkStale()
36
- })
37
- }
8
+ // React Fast Refresh works here despite React being externalized to the
9
+ // locally-vendored ESM (client/externalize-react.ts + the importmap in
10
+ // index.html → /vendor/react): Bun's bundled refresh runtime wraps
11
+ // `__REACT_DEVTOOLS_GLOBAL_HOOK__` before the vendored react-dom registers,
12
+ // and the hook is a plain global, so the renderer link works across the
13
+ // bundle/vendor boundary. The one missing piece was that the externalized
14
+ // virtual modules (`esm:react/jsx-dev-runtime` etc.) were never hot-accepted,
15
+ // which made EVERY edit propagate to the entry and force a full reload —
16
+ // fixed by the `import.meta.hot.accept()` in externalize-react.ts. Component
17
+ // edits now apply in place; non-component modules (main.tsx, lib/*) still
18
+ // fall back to a full reload via Bun's runtime, which is correct.
19
+ if (import.meta.hot) {
20
+ startHmrWatchdog()
38
21
  }
39
22
 
40
23
  export async function init(el: HTMLElement) {
package/client/main.tsx CHANGED
@@ -3,8 +3,8 @@ import { Agentation } from 'agentation'
3
3
  import { createRoot } from 'react-dom/client'
4
4
  import { Router } from 'wouter'
5
5
 
6
- import { initConnection } from './lib/connection'
7
- import { AppRouter } from './components/App'
6
+ import { initConnection } from '@/client/features/chat/chat-connection'
7
+ import { AppRouter } from './app/AppRouter'
8
8
 
9
9
  const queryClient = new QueryClient()
10
10
 
@@ -0,0 +1,39 @@
1
+ export function startHmrWatchdog() {
2
+ if (!import.meta.hot) return
3
+ let lastEventAt = Date.now()
4
+ for (const event of ['bun:beforeUpdate', 'bun:afterUpdate', 'bun:ws:connect'] as const) {
5
+ import.meta.hot.on(event, () => (lastEventAt = Date.now()))
6
+ }
7
+
8
+ const devScript = document.querySelector<HTMLScriptElement>('[data-bun-dev-server-script]')
9
+ if (!devScript) return
10
+
11
+ let baseline = new URL(devScript.src).pathname
12
+ let staleSince: number | null = null
13
+
14
+ const checkStale = async () => {
15
+ try {
16
+ const html = await (await fetch('/', { cache: 'no-store' })).text()
17
+ const current = html.match(/\/_bun\/client\/index-[0-9a-f]+\.js/)?.[0]
18
+ if (!current || current === baseline) {
19
+ staleSince = null
20
+ return
21
+ }
22
+
23
+ staleSince ??= Date.now()
24
+ if (lastEventAt >= staleSince - 5_000) {
25
+ baseline = current
26
+ staleSince = null
27
+ } else if (Date.now() - staleSince > 10_000) {
28
+ location.reload()
29
+ }
30
+ } catch {
31
+ // The server may be between supervisor restarts. The next check retries.
32
+ }
33
+ }
34
+
35
+ setInterval(checkStale, 5_000)
36
+ document.addEventListener('visibilitychange', () => {
37
+ if (document.visibilityState === 'visible') checkStale()
38
+ })
39
+ }
@@ -3,7 +3,7 @@ import { useEffect, useRef } from 'react'
3
3
  import { wsUrl } from '@/client/lib/ws-url'
4
4
  import type { ViewInfo, WidgetInfo } from '@/lib/types'
5
5
 
6
- export type MeiEvent =
6
+ export type WorkspaceEvent =
7
7
  | { type: 'widget:updated'; name: string }
8
8
  | { type: 'widget-layout:updated'; widgets: WidgetInfo[] }
9
9
  | { type: 'widgets:refresh' }
@@ -11,15 +11,18 @@ export type MeiEvent =
11
11
  | { type: 'view-layout:updated'; views: ViewInfo[] }
12
12
  | { type: 'theme:updated' }
13
13
  | { type: 'workspace:updated' }
14
+ // The registry list changed (reorder, create) without touching any open
15
+ // workspace's layout — clients refetch just the sidebar list.
16
+ | { type: 'workspaces-list:updated' }
14
17
  // A workspace's env changed outside the UI — refetch the env view.
15
18
  | { type: 'env:updated'; workspaceId: string }
16
19
  // The Scratchpad canvas for `workspaceId` was saved — open tabs reload from
17
20
  // disk. `origin` is the tab that wrote it, so that tab can skip its own echo.
18
21
  | { type: 'scratchpad:updated'; workspaceId: string; origin?: string }
19
22
 
20
- type MeiEventHandler = (event: MeiEvent) => void
23
+ type WorkspaceEventHandler = (event: WorkspaceEvent) => void
21
24
 
22
- const listeners = new Set<MeiEventHandler>()
25
+ const listeners = new Set<WorkspaceEventHandler>()
23
26
  let ws: WebSocket | null = null
24
27
  let connecting = false
25
28
 
@@ -36,7 +39,7 @@ function ensureConnection() {
36
39
 
37
40
  socket.onmessage = event => {
38
41
  try {
39
- const data = JSON.parse(event.data) as MeiEvent
42
+ const data = JSON.parse(event.data) as WorkspaceEvent
40
43
  for (const handler of listeners) handler(data)
41
44
  } catch {}
42
45
  }
@@ -55,12 +58,12 @@ function ensureConnection() {
55
58
  }
56
59
  }
57
60
 
58
- export function useMeiEvent(handler: MeiEventHandler) {
61
+ export function useWorkspaceEvent(handler: WorkspaceEventHandler) {
59
62
  const handlerRef = useRef(handler)
60
63
  handlerRef.current = handler
61
64
 
62
65
  useEffect(() => {
63
- const wrapped: MeiEventHandler = e => handlerRef.current(e)
66
+ const wrapped: WorkspaceEventHandler = e => handlerRef.current(e)
64
67
  listeners.add(wrapped)
65
68
  ensureConnection()
66
69
 
@@ -5,16 +5,20 @@ import { persist } from 'zustand/middleware'
5
5
  // survive reloads. Server-owned or per-workspace state does NOT belong here.
6
6
  type UiStore = {
7
7
  sidebarCollapsed: boolean
8
+ discoveredWorkspacesOpen: boolean
8
9
  toggleSidebar: () => void
9
10
  setSidebarCollapsed: (collapsed: boolean) => void
11
+ setDiscoveredWorkspacesOpen: (open: boolean) => void
10
12
  }
11
13
 
12
14
  export const useUiStore = create<UiStore>()(
13
15
  persist(
14
16
  set => ({
15
17
  sidebarCollapsed: false,
18
+ discoveredWorkspacesOpen: true,
16
19
  toggleSidebar: () => set(s => ({ sidebarCollapsed: !s.sidebarCollapsed })),
17
- setSidebarCollapsed: collapsed => set({ sidebarCollapsed: collapsed })
20
+ setSidebarCollapsed: collapsed => set({ sidebarCollapsed: collapsed }),
21
+ setDiscoveredWorkspacesOpen: open => set({ discoveredWorkspacesOpen: open })
18
22
  }),
19
23
  { name: 'moi:ui' }
20
24
  )
package/client/theme.css CHANGED
@@ -25,8 +25,6 @@
25
25
  --color-popover-foreground: var(--popover-foreground);
26
26
  --color-primary: var(--primary);
27
27
  --color-primary-foreground: var(--primary-foreground);
28
- --color-secondary: var(--secondary);
29
- --color-secondary-foreground: var(--secondary-foreground);
30
28
  --color-muted: var(--muted);
31
29
  --color-muted-foreground: var(--muted-foreground);
32
30
  --color-accent: var(--accent);