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,162 @@
1
+ import { useWorkspaceMcp } from './api'
2
+ import { IconAlertCircleFilled, IconPlugConnected } from '@tabler/icons-react'
3
+ import { IconMcp } from '@/client/features/connectors/IconMcp'
4
+ import { Button } from '@/client/components/ui/button'
5
+ import { HoverCard, HoverCardContent, HoverCardTrigger } from '@/client/components/ui/hover-card'
6
+ import { useScrollFade } from '@/client/hooks/useScrollFade'
7
+ import { formatMcpServerName, getMcpIcon } from '@/client/features/connectors/mcp-icons'
8
+ import { useWorkspaceId } from '@/client/features/workspace/WorkspaceContext'
9
+ import { useWorkspaceLayoutCtx } from '@/client/features/workspace/WorkspaceLayoutContext'
10
+ import { cn } from '@/client/lib/cn'
11
+ import type { McpServer } from '@/lib/types'
12
+
13
+ function statusLabel(status: McpServer['status']): string {
14
+ if (status === 'needs-auth') return 'Needs auth'
15
+ return status[0].toUpperCase() + status.slice(1)
16
+ }
17
+
18
+ function McpStatusDot({ status }: { status: McpServer['status'] }) {
19
+ const connected = status === 'connected'
20
+ return (
21
+ <span
22
+ className={cn(
23
+ 'size-[5px] shrink-0 rounded-full',
24
+ connected ? 'bg-emerald-500' : 'bg-yellow-500'
25
+ )}
26
+ />
27
+ )
28
+ }
29
+
30
+ type McpServerIconProps = {
31
+ name: string
32
+ status: McpServer['status']
33
+ size?: 'sm' | 'lg'
34
+ }
35
+
36
+ function McpServerIcon({ name, status, size = 'sm' }: McpServerIconProps) {
37
+ const icon = getMcpIcon(name)
38
+ const large = size === 'lg'
39
+ const className = 'size-full rounded-sm ring-2 ring-background'
40
+
41
+ return (
42
+ <span className={cn('relative shrink-0', large ? 'size-10' : 'size-5')}>
43
+ {icon ? (
44
+ <img src={icon} alt="" className={className} />
45
+ ) : (
46
+ <span
47
+ className={cn(
48
+ 'flex size-full items-center justify-center bg-muted text-muted-foreground ring-2 ring-background',
49
+ large ? 'rounded-sm' : 'rounded'
50
+ )}
51
+ >
52
+ <IconMcp className={large ? 'size-5' : 'size-4'} />
53
+ </span>
54
+ )}
55
+ {large && status !== 'connected' && (
56
+ <IconAlertCircleFilled
57
+ aria-hidden="true"
58
+ size={16}
59
+ stroke={1.75}
60
+ className="absolute -top-1 -right-1 rounded-full bg-card text-amber-400"
61
+ />
62
+ )}
63
+ </span>
64
+ )
65
+ }
66
+
67
+ export function sortMcpServers(servers: McpServer[]): McpServer[] {
68
+ // Active (connected) servers first, then disabled/errored/auth-pending. The
69
+ // sort is stable, so each group keeps the server list's original order.
70
+ return [...servers].sort(
71
+ (a, b) => Number(b.status === 'connected') - Number(a.status === 'connected')
72
+ )
73
+ }
74
+
75
+ export function McpServerRow({ server }: { server: McpServer }) {
76
+ return (
77
+ <div className="flex items-center gap-2.5 rounded-xs px-2 py-1 text-foreground hover:bg-accent hover:text-accent-foreground">
78
+ <McpServerIcon name={server.name} status={server.status} />
79
+ <span className="flex-1 truncate text-sm">{formatMcpServerName(server.name)}</span>
80
+ <McpStatusDot status={server.status} />
81
+ </div>
82
+ )
83
+ }
84
+
85
+ export function McpServerCard({ server }: { server: McpServer }) {
86
+ return (
87
+ <div className="flex min-h-20 items-center gap-3 rounded-xl border border-border bg-card px-4 py-3 text-card-foreground">
88
+ <McpServerIcon name={server.name} status={server.status} size="lg" />
89
+ <div className="flex min-w-0 flex-1 flex-col justify-center gap-0.5">
90
+ <div className="truncate text-sm font-medium text-foreground">
91
+ {formatMcpServerName(server.name)}
92
+ </div>
93
+ <span className="text-sm text-muted-foreground">{statusLabel(server.status)}</span>
94
+ </div>
95
+ </div>
96
+ )
97
+ }
98
+
99
+ // The scrollable server list. Its own component so `useScrollFade`'s effect runs
100
+ // when the (portaled, mount-on-open) hover card opens — attaching the scroll ref.
101
+ // Overflow is signalled with top/bottom mask fades; the scrollbar is hidden.
102
+ function McpList({ servers }: { servers: McpServer[] }) {
103
+ const { ref, showTopFade, showBottomFade } = useScrollFade()
104
+ const fade =
105
+ showTopFade && showBottomFade
106
+ ? 'mask-fade-y'
107
+ : showTopFade
108
+ ? 'mask-fade-top'
109
+ : showBottomFade
110
+ ? 'mask-fade-bottom'
111
+ : undefined
112
+ return (
113
+ <div
114
+ ref={ref}
115
+ className={cn(
116
+ 'scrollbar-none flex max-h-72 flex-col overflow-y-auto overscroll-contain',
117
+ fade
118
+ )}
119
+ >
120
+ {servers.map(server => (
121
+ <McpServerRow key={server.name} server={server} />
122
+ ))}
123
+ </div>
124
+ )
125
+ }
126
+
127
+ // Project-scoped connector status hover card — Claude workspaces only
128
+ // (OpenClaw/Hermes use other backends). User-scoped connectors live on the
129
+ // standalone Connectors page.
130
+ export function McpMenu() {
131
+ const workspaceId = useWorkspaceId()
132
+ // Read provider from the shared layout context, not a second `useWorkspaceLayout`
133
+ // observer — a duplicate observer that remounts (e.g. when this menu moves
134
+ // between the fullscreen and two-pane headers) fires `refetchOnMount`, which
135
+ // overwrites an in-flight optimistic chat-mode change before it's persisted.
136
+ const { provider, isLoading } = useWorkspaceLayoutCtx()
137
+ const isClaude = !isLoading && provider !== 'openclaw' && provider !== 'hermes'
138
+ const { data: servers } = useWorkspaceMcp(workspaceId, isClaude)
139
+
140
+ if (!isClaude) return null
141
+ if (!servers || servers.length === 0) return null
142
+
143
+ const trigger = (
144
+ <Button variant="ghost" size="icon-sm" aria-label="Connectors" title="Connectors">
145
+ <IconPlugConnected stroke={1.75} />
146
+ </Button>
147
+ )
148
+
149
+ const sorted = sortMcpServers(servers)
150
+
151
+ return (
152
+ <HoverCard>
153
+ <HoverCardTrigger render={trigger} delay={0} closeDelay={100} />
154
+ <HoverCardContent align="end" sideOffset={6} className="w-56 p-1">
155
+ <div className="px-2 pt-1 pb-1.5 text-xs font-medium text-muted-foreground">
156
+ Project connectors
157
+ </div>
158
+ <McpList servers={sorted} />
159
+ </HoverCardContent>
160
+ </HoverCard>
161
+ )
162
+ }
@@ -0,0 +1,28 @@
1
+ import { useQuery } from '@tanstack/react-query'
2
+
3
+ import { requestJson } from '@/client/api/http'
4
+ import { workspaceKeys } from '@/client/api/workspace-keys'
5
+ import type { McpServer } from '@/lib/types'
6
+
7
+ export function useWorkspaceMcp(workspaceId: string, enabled: boolean) {
8
+ return useQuery<McpServer[]>({
9
+ queryKey: workspaceKeys.mcp(workspaceId),
10
+ queryFn: () => requestJson(`/api/workspaces/${workspaceId}/mcp`),
11
+ enabled,
12
+ staleTime: Infinity,
13
+ gcTime: Infinity,
14
+ refetchOnMount: false,
15
+ refetchOnWindowFocus: false
16
+ })
17
+ }
18
+
19
+ export function useUserMcp() {
20
+ return useQuery<McpServer[]>({
21
+ queryKey: workspaceKeys.userMcp,
22
+ queryFn: () => requestJson('/api/mcp'),
23
+ staleTime: 30_000,
24
+ gcTime: Infinity,
25
+ refetchOnMount: true,
26
+ refetchOnWindowFocus: true
27
+ })
28
+ }
@@ -0,0 +1,224 @@
1
+ import { type ReactElement, useState } from 'react'
2
+
3
+ import { IconX } from '@tabler/icons-react'
4
+ import { useLocation } from 'wouter'
5
+
6
+ import { useAddWorkspace, useChooseFolder, useCreateWorkspace, useCreateWorkspaceInfo } from './api'
7
+ import { Button } from '@/client/components/ui/button'
8
+ import {
9
+ Dialog,
10
+ DialogClose,
11
+ DialogContent,
12
+ DialogDescription,
13
+ DialogTitle,
14
+ DialogTrigger
15
+ } from '@/client/components/ui/dialog'
16
+ import { Input } from '@/client/components/ui/input'
17
+ import { Tooltip, TooltipContent, TooltipTrigger } from '@/client/components/ui/tooltip'
18
+ import { cn } from '@/client/lib/cn'
19
+ import {
20
+ WorkspaceTypeIcon,
21
+ workspaceTypeLabel
22
+ } from '@/client/features/home/workspace-presentation'
23
+ import { validateWorkspaceFolderName } from '@/lib/workspace-name'
24
+ import type { WorkspaceType } from '@/lib/types'
25
+
26
+ type AgentOption = {
27
+ type: WorkspaceType
28
+ hint: string
29
+ disabled?: boolean
30
+ }
31
+
32
+ // Only Claude Code workspaces can be created from scratch for now. OpenClaw
33
+ // workspaces belong to their agents — they arrive via discovery on the home
34
+ // page — and Hermes has no init path yet.
35
+ const AGENT_OPTIONS: AgentOption[] = [
36
+ { type: 'claude-code', hint: 'Powered by the Claude Agent SDK' },
37
+ {
38
+ type: 'openclaw',
39
+ hint: 'Initialize OpenClaw in the folder manually, then import it from Home',
40
+ disabled: true
41
+ },
42
+ { type: 'hermes', hint: 'Coming soon', disabled: true }
43
+ ]
44
+
45
+ type CreateWorkspaceDialogProps = {
46
+ trigger: ReactElement
47
+ }
48
+
49
+ type Step = 'type' | 'name'
50
+
51
+ // A two-step dialog for adding a workspace. Step one picks the agent type and
52
+ // offers "Use existing folder" (opens the OS folder picker via the server) or
53
+ // "Next"; step two names a brand-new folder created under the workspaces root.
54
+ export function CreateWorkspaceDialog({ trigger }: CreateWorkspaceDialogProps) {
55
+ const [, navigate] = useLocation()
56
+ const info = useCreateWorkspaceInfo()
57
+ const createMutation = useCreateWorkspace()
58
+ const addMutation = useAddWorkspace()
59
+ const chooseFolder = useChooseFolder()
60
+
61
+ const [open, setOpen] = useState(false)
62
+ const [step, setStep] = useState<Step>('type')
63
+ const [type, setType] = useState<WorkspaceType>('claude-code')
64
+ const [name, setName] = useState('')
65
+
66
+ const trimmed = name.trim()
67
+ const nameError = trimmed ? validateWorkspaceFolderName(trimmed) : null
68
+ // The native folder picker is macOS-only (osascript). Elsewhere the button is
69
+ // disabled with a tooltip pointing to the manual `moi init` path. Default to
70
+ // enabled while the flag loads so mac users don't see a flicker.
71
+ const canChooseFolder = info.data?.canChooseFolder ?? true
72
+ const busy = createMutation.isPending || addMutation.isPending || chooseFolder.isPending
73
+ const error = createMutation.error ?? addMutation.error ?? chooseFolder.error
74
+
75
+ function handleOpenChange(next: boolean) {
76
+ setOpen(next)
77
+ if (!next) {
78
+ // Reset so the dialog always reopens at step one with a clean slate.
79
+ setStep('type')
80
+ setName('')
81
+ }
82
+ }
83
+
84
+ function finish(id: string) {
85
+ setOpen(false)
86
+ navigate(`/workspace/${id}`)
87
+ }
88
+
89
+ async function handleUseExisting() {
90
+ if (busy) return
91
+ try {
92
+ const result = await chooseFolder.mutateAsync()
93
+ if ('canceled' in result) return
94
+ const entry = await addMutation.mutateAsync({ path: result.path, type })
95
+ finish(entry.id)
96
+ } catch {
97
+ // Surfaced via the mutation error state below.
98
+ }
99
+ }
100
+
101
+ function handleCreate() {
102
+ if (!trimmed || nameError || busy) return
103
+ createMutation.mutate({ name: trimmed, type }, { onSuccess: entry => finish(entry.id) })
104
+ }
105
+
106
+ return (
107
+ <Dialog open={open} onOpenChange={handleOpenChange}>
108
+ <DialogTrigger render={trigger} />
109
+ <DialogContent className="w-[520px] max-w-[92vw] p-6">
110
+ <DialogClose
111
+ render={
112
+ <Button
113
+ variant="ghost"
114
+ size="icon-sm"
115
+ aria-label="Close"
116
+ className="absolute top-4 right-4"
117
+ >
118
+ <IconX stroke={1.75} />
119
+ </Button>
120
+ }
121
+ />
122
+
123
+ {step === 'type' ? (
124
+ <>
125
+ <DialogTitle>Create new space</DialogTitle>
126
+ <p className="mt-4 mb-2 text-sm font-medium text-foreground">Space type</p>
127
+ <div className="flex flex-col gap-2">
128
+ {AGENT_OPTIONS.map(option => {
129
+ const selected = type === option.type
130
+ return (
131
+ <button
132
+ key={option.type}
133
+ type="button"
134
+ disabled={option.disabled}
135
+ onClick={() => setType(option.type)}
136
+ aria-pressed={selected}
137
+ className={cn(
138
+ 'flex items-center gap-3 rounded-lg border p-3 text-left transition-colors',
139
+ selected
140
+ ? 'border-ring bg-muted/50 shadow-[inset_0_0_0_1px_var(--ring)]'
141
+ : 'border-border hover:bg-accent',
142
+ option.disabled && 'cursor-not-allowed opacity-50 hover:bg-transparent'
143
+ )}
144
+ >
145
+ <WorkspaceTypeIcon type={option.type} className="size-5" />
146
+ <span className="flex min-w-0 flex-col">
147
+ <span className="text-sm font-medium text-foreground">
148
+ {workspaceTypeLabel[option.type]}
149
+ </span>
150
+ <span className="text-xs text-muted-foreground">{option.hint}</span>
151
+ </span>
152
+ </button>
153
+ )
154
+ })}
155
+ </div>
156
+
157
+ {error && <p className="mt-4 text-xs text-destructive">{error.message}</p>}
158
+
159
+ <div className="mt-6 flex items-center justify-end gap-2">
160
+ {canChooseFolder ? (
161
+ <Button variant="secondary" onClick={handleUseExisting} disabled={busy}>
162
+ Use existing folder
163
+ </Button>
164
+ ) : (
165
+ <Tooltip delay={50}>
166
+ <TooltipTrigger
167
+ render={
168
+ // aria-disabled (not the native `disabled` attr) keeps the
169
+ // button hoverable so the tooltip still shows.
170
+ <Button
171
+ variant="secondary"
172
+ aria-disabled
173
+ onClick={e => e.preventDefault()}
174
+ className="cursor-not-allowed opacity-50"
175
+ >
176
+ Use existing folder
177
+ </Button>
178
+ }
179
+ />
180
+ <TooltipContent className="max-w-64 text-center">
181
+ Run <code className="font-mono">moi init</code> in the folder to add it
182
+ manually.
183
+ </TooltipContent>
184
+ </Tooltip>
185
+ )}
186
+ <Button onClick={() => setStep('name')} disabled={busy}>
187
+ Next
188
+ </Button>
189
+ </div>
190
+ </>
191
+ ) : (
192
+ <>
193
+ <DialogTitle>Name the space</DialogTitle>
194
+ <DialogDescription className="mt-1">Keep it short and recognizable.</DialogDescription>
195
+
196
+ <div className="mt-5">
197
+ <Input
198
+ value={name}
199
+ onChange={e => setName(e.target.value)}
200
+ onKeyDown={e => {
201
+ if (e.key === 'Enter') handleCreate()
202
+ }}
203
+ placeholder="my-space"
204
+ autoFocus
205
+ aria-invalid={!!nameError}
206
+ autoComplete="off"
207
+ spellCheck={false}
208
+ />
209
+ {nameError && <p className="mt-2 text-xs text-destructive">{nameError}</p>}
210
+ </div>
211
+
212
+ {error && <p className="mt-4 text-xs text-destructive">{error.message}</p>}
213
+
214
+ <div className="mt-6 flex items-center justify-end gap-2">
215
+ <Button onClick={handleCreate} disabled={!trimmed || !!nameError || busy}>
216
+ {createMutation.isPending ? 'Creating…' : 'Create new space'}
217
+ </Button>
218
+ </div>
219
+ </>
220
+ )}
221
+ </DialogContent>
222
+ </Dialog>
223
+ )
224
+ }
@@ -0,0 +1,220 @@
1
+ import { IconChevronRight, IconFolders, IconLoader2, IconPlus } from '@tabler/icons-react'
2
+ import { useLocation } from 'wouter'
3
+
4
+ import { useAddWorkspace, useDiscoveredWorkspaces, useWorkspaces } from './api'
5
+ import { Button } from '@/client/components/ui/button'
6
+ import { LedLogo } from '@/client/components/shared/LedLogo'
7
+ import {
8
+ Collapsible,
9
+ CollapsibleContent,
10
+ CollapsibleTrigger
11
+ } from '@/client/components/ui/collapsible'
12
+ import { cn } from '@/client/lib/cn'
13
+ import { useUiStore } from '@/client/store/ui'
14
+ import {
15
+ WorkspaceTypeIcon,
16
+ workspaceDisplayName,
17
+ workspaceProviderIcon
18
+ } from '@/client/features/home/workspace-presentation'
19
+ import type { DiscoveredWorkspace, WorkspaceEntry } from '@/lib/types'
20
+
21
+ import { CreateWorkspaceDialog } from './CreateWorkspaceDialog'
22
+ import { WorkspacePreview } from './WorkspacePreview'
23
+
24
+ export function HomePage() {
25
+ const [, navigate] = useLocation()
26
+ const workspacesQuery = useWorkspaces()
27
+ const discoveredQuery = useDiscoveredWorkspaces()
28
+ const importMutation = useAddWorkspace()
29
+ const discoveredWorkspacesOpen = useUiStore(state => state.discoveredWorkspacesOpen)
30
+ const setDiscoveredWorkspacesOpen = useUiStore(state => state.setDiscoveredWorkspacesOpen)
31
+
32
+ if (workspacesQuery.isPending || discoveredQuery.isPending) {
33
+ return (
34
+ <div className="flex min-h-[50vh] items-center justify-center">
35
+ <IconLoader2 size={20} stroke={1.5} className="animate-spin text-muted-foreground" />
36
+ </div>
37
+ )
38
+ }
39
+
40
+ if (workspacesQuery.isError || discoveredQuery.isError) {
41
+ return (
42
+ <div className="flex min-h-[50vh] items-center justify-center">
43
+ <p className="text-sm text-muted-foreground">Could not load spaces.</p>
44
+ </div>
45
+ )
46
+ }
47
+
48
+ const workspaces = workspacesQuery.data
49
+ const discovered = discoveredQuery.data
50
+ const count = workspaces.length
51
+ const importingPath =
52
+ importMutation.isPending && importMutation.variables ? importMutation.variables.path : null
53
+
54
+ function handleAdd(suggestion: DiscoveredWorkspace) {
55
+ importMutation.mutate(suggestion, {
56
+ onSuccess: entry => navigate(`/workspace/${entry.id}`)
57
+ })
58
+ }
59
+
60
+ return (
61
+ <div className="mx-auto w-full max-w-3xl px-8 pt-14 pb-16">
62
+ <div className="mb-8 flex items-center">
63
+ <LedLogo sprite="moi-full" pixelSize={4} gap={1} />
64
+ </div>
65
+
66
+ {count > 0 ? (
67
+ <section className="mb-10">
68
+ <div className="mb-2 flex items-center justify-between gap-2">
69
+ <h1 className="text-sm font-medium text-foreground">My spaces</h1>
70
+ <CreateWorkspaceDialog
71
+ trigger={
72
+ <Button variant="outline" size="sm">
73
+ <IconPlus data-icon="inline-start" stroke={1.75} />
74
+ New
75
+ </Button>
76
+ }
77
+ />
78
+ </div>
79
+
80
+ <div className="grid grid-cols-1 gap-3 sm:grid-cols-2 md:grid-cols-3">
81
+ {workspaces.map(ws => (
82
+ <WorkspaceCard key={ws.id} workspace={ws} />
83
+ ))}
84
+ </div>
85
+ </section>
86
+ ) : (
87
+ <div className="mb-10 flex flex-col items-center gap-4 px-8 py-16 text-center">
88
+ <IconFolders size={24} stroke={1.5} className="text-muted-foreground/70" />
89
+ <div className="flex flex-col gap-1.5">
90
+ <h1 className="font-medium">Create your first space</h1>
91
+ <p className="mx-auto max-w-md text-sm text-muted-foreground">
92
+ Initialize moi in any folder on your computer with{' '}
93
+ <code className="rounded bg-muted px-1 py-0.5 font-mono text-xs">moi init</code>, or
94
+ add an existing folder where you&rsquo;ve worked with other agents.
95
+ </p>
96
+ </div>
97
+ <CreateWorkspaceDialog trigger={<Button size="sm">Create a space</Button>} />
98
+ </div>
99
+ )}
100
+
101
+ {discovered.length > 0 && (
102
+ <section>
103
+ <Collapsible
104
+ open={discoveredWorkspacesOpen}
105
+ onOpenChange={setDiscoveredWorkspacesOpen}
106
+ className="group"
107
+ >
108
+ <CollapsibleTrigger
109
+ className={cn(
110
+ 'group/trigger',
111
+ 'flex w-full items-center gap-1 pb-4 text-left outline-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring',
112
+ 'text-muted-foreground group-data-open:text-foreground hover:text-foreground'
113
+ )}
114
+ >
115
+ <span className="text-sm font-medium">Import from this computer</span>
116
+ <IconChevronRight
117
+ size={16}
118
+ stroke={2}
119
+ className={cn(
120
+ 'opacity-0 transition-[opacity,transform]',
121
+ 'group-hover/trigger:opacity-100 group-focus-visible/trigger:opacity-100 group-data-open:rotate-90'
122
+ )}
123
+ />
124
+ </CollapsibleTrigger>
125
+ <CollapsibleContent>
126
+ <ul className="border-t border-border">
127
+ {discovered.map(item => (
128
+ <SuggestedRow
129
+ key={item.path}
130
+ suggestion={item}
131
+ onAdd={handleAdd}
132
+ loading={importingPath === item.path}
133
+ />
134
+ ))}
135
+ </ul>
136
+ {importMutation.isError && (
137
+ <p className="mt-3 text-xs text-destructive">{importMutation.error.message}</p>
138
+ )}
139
+ </CollapsibleContent>
140
+ </Collapsible>
141
+ </section>
142
+ )}
143
+ </div>
144
+ )
145
+ }
146
+
147
+ type WorkspaceCardProps = {
148
+ workspace: WorkspaceEntry
149
+ }
150
+
151
+ function WorkspaceCard({ workspace }: WorkspaceCardProps) {
152
+ const name = workspaceDisplayName(workspace)
153
+ const meta = formatAddedAt(workspace.addedAt)
154
+
155
+ return (
156
+ <a
157
+ href={`/workspace/${workspace.id}`}
158
+ className={cn(
159
+ 'group flex min-w-0 flex-col gap-4 rounded-xl border border-border bg-card p-2 hover:shadow-sm',
160
+ 'transition-colors'
161
+ )}
162
+ >
163
+ <WorkspacePreview workspaceId={workspace.id} />
164
+ <div className="flex min-w-0 flex-col px-2 pb-2">
165
+ <div className="flex min-w-0 items-center gap-2">
166
+ <img
167
+ src={workspace.icon ?? workspaceProviderIcon[workspace.type ?? 'claude-code']}
168
+ alt=""
169
+ className="size-4 shrink-0 rounded-[4px]"
170
+ />
171
+ <span className="truncate text-sm font-medium text-foreground">{name}</span>
172
+ </div>
173
+ <div title={workspace.path} className="mt-2 truncate text-xs text-muted-foreground">
174
+ {workspace.displayPath ?? workspace.path}
175
+ </div>
176
+ <div className="mt-2 text-xs text-muted-foreground">{meta}</div>
177
+ </div>
178
+ </a>
179
+ )
180
+ }
181
+
182
+ type SuggestedRowProps = {
183
+ suggestion: DiscoveredWorkspace
184
+ onAdd: (suggestion: DiscoveredWorkspace) => void
185
+ loading: boolean
186
+ }
187
+
188
+ function SuggestedRow({ suggestion, onAdd, loading }: SuggestedRowProps) {
189
+ const { path, type } = suggestion
190
+ const name = workspaceDisplayName(suggestion)
191
+ return (
192
+ <li className="flex items-center gap-2 border-b border-border px-1 py-3">
193
+ <WorkspaceTypeIcon type={type} />
194
+ <span className="shrink-0 text-sm font-medium text-foreground">{name}</span>
195
+ <span title={path} className="min-w-0 flex-1 truncate text-xs text-muted-foreground">
196
+ {suggestion.displayPath ?? path}
197
+ </span>
198
+ <Button variant="outline" size="sm" onClick={() => onAdd(suggestion)} disabled={loading}>
199
+ {loading ? (
200
+ <IconLoader2 stroke={1.75} className="animate-spin" />
201
+ ) : (
202
+ <IconPlus stroke={1.75} />
203
+ )}
204
+ Add
205
+ </Button>
206
+ </li>
207
+ )
208
+ }
209
+
210
+ function formatAddedAt(iso: string): string {
211
+ const ms = Date.now() - new Date(iso).getTime()
212
+ const mins = Math.floor(ms / 60000)
213
+ if (mins < 1) return 'Added just now'
214
+ if (mins < 60) return `Added ${mins} min${mins === 1 ? '' : 's'} ago`
215
+ const hours = Math.floor(mins / 60)
216
+ if (hours < 24) return `Added ${hours} hour${hours === 1 ? '' : 's'} ago`
217
+ const days = Math.floor(hours / 24)
218
+ if (days < 30) return `Added ${days} day${days === 1 ? '' : 's'} ago`
219
+ return `Added ${new Date(iso).toLocaleDateString()}`
220
+ }
@@ -1,6 +1,6 @@
1
1
  import { IconRobotFace } from '@tabler/icons-react'
2
2
 
3
- import { useWorkspacePreview } from '@/client/api/workspaces'
3
+ import { useWorkspacePreview } from './api'
4
4
 
5
5
  type WorkspacePreviewProps = {
6
6
  workspaceId: string
@@ -16,7 +16,7 @@ export function WorkspacePreview({ workspaceId }: WorkspacePreviewProps) {
16
16
  const isEmpty = query.data !== undefined && !hasItems
17
17
 
18
18
  return (
19
- <div className="flex size-24 shrink-0 items-center justify-center rounded-lg bg-muted p-2">
19
+ <div className="flex aspect-video w-full items-center justify-center rounded-sm bg-muted p-3">
20
20
  {hasItems && (
21
21
  <svg
22
22
  viewBox={`0 0 ${cols} ${rows}`}