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
@@ -1,132 +0,0 @@
1
- import { useCallback, useState } from 'react'
2
-
3
- import { AnimatePresence, LayoutGroup, motion } from 'motion/react'
4
-
5
- import { useWorkspaceLayoutCtx } from '@/client/lib/WorkspaceLayoutContext'
6
- import { findFreePosition } from '@/client/lib/grid-pack'
7
- import type { WidgetInfo } from '@/lib/types'
8
-
9
- import { CustomizePanel } from './CustomizePanel'
10
- import { HiddenPanel } from './HiddenPanel'
11
- import type { GridItem } from './WidgetGrid'
12
- import { WidgetGrid } from './WidgetGrid'
13
- import { WidgetShell } from './WidgetShell'
14
-
15
- export type WidgetMode = 'idle' | 'editing' | 'customizing'
16
-
17
- function renderItem(id: string) {
18
- return <WidgetShell name={id} />
19
- }
20
-
21
- // Tracks the rendered (border-box) height of whichever bottom panel is open, so
22
- // the grid can reserve matching space below it and every card stays reachable.
23
- function usePanelHeight() {
24
- const [height, setHeight] = useState(0)
25
- const ref = useCallback((node: HTMLDivElement | null) => {
26
- if (!node) return
27
- const ro = new ResizeObserver(([entry]) => {
28
- const box = entry.borderBoxSize?.[0]
29
- setHeight(box ? box.blockSize : entry.contentRect.height)
30
- })
31
- ro.observe(node)
32
- return () => ro.disconnect()
33
- }, [])
34
- return [ref, height] as const
35
- }
36
-
37
- type WidgetsProps = {
38
- // Owned by the page (its header renders the controls); Widgets only reacts.
39
- mode: WidgetMode
40
- // Authoritative widget set from the widgets query; positions come from layout.
41
- widgets: WidgetInfo[]
42
- }
43
-
44
- export function Widgets({ mode, widgets }: WidgetsProps) {
45
- const { layout, setLayout } = useWorkspaceLayoutCtx()
46
-
47
- const gridIds = new Set(layout.widgetGrid.map(g => g.i))
48
-
49
- const visibleItems: GridItem[] = layout.widgetGrid
50
- .filter(g => widgets.some(w => w.id === g.i))
51
- .map(g => {
52
- const widget = widgets.find(w => w.id === g.i)!
53
- return { id: g.i, w: widget.config.colSpan, h: widget.config.rowSpan, x: g.x, y: g.y }
54
- })
55
-
56
- const hiddenItems: GridItem[] = widgets
57
- .filter(w => !gridIds.has(w.id))
58
- .map(w => ({ id: w.id, w: w.config.colSpan, h: w.config.rowSpan }))
59
-
60
- const [panelRef, panelHeight] = usePanelHeight()
61
- const panelOpen = mode === 'customizing' || (mode === 'editing' && hiddenItems.length > 0)
62
-
63
- function hide(id: string) {
64
- setLayout({ widgetGrid: layout.widgetGrid.filter(g => g.i !== id) })
65
- }
66
-
67
- function restore(id: string) {
68
- const widget = widgets.find(w => w.id === id)
69
- if (!widget) return
70
- const gridWithSizes = layout.widgetGrid.map(g => {
71
- const w = widgets.find(w => w.id === g.i)
72
- return { ...g, w: w?.config.colSpan ?? 1, h: w?.config.rowSpan ?? 1 }
73
- })
74
- const pos = findFreePosition(gridWithSizes, widget.config.colSpan, widget.config.rowSpan, 4)
75
- setLayout({ widgetGrid: [...layout.widgetGrid, { i: id, x: pos.x, y: pos.y }] })
76
- }
77
-
78
- if (widgets.length === 0) {
79
- return (
80
- <div className="flex min-h-0 flex-1 items-center justify-center">
81
- <p className="text-sm text-muted-foreground">No widgets found</p>
82
- </div>
83
- )
84
- }
85
-
86
- return (
87
- // Working area: everything below the header. It scrolls, and it's the
88
- // positioning context for the bottom panel (which is anchored to this box,
89
- // not to the grid). The grid lives in a centered max-w container and grows
90
- // to its natural height.
91
- <div className="relative min-h-0 flex-1">
92
- <LayoutGroup>
93
- <div className="h-full overflow-y-auto px-[var(--page-pad)] pt-[var(--page-pad)] pb-[calc(var(--page-pad)*2)]">
94
- {/* Bottom reservation = 2× page-pad (the pb above) + the open panel's
95
- height (this margin), so the last cards scroll clear of it. */}
96
- <motion.div
97
- className="mx-auto w-full max-w-[var(--column-w)]"
98
- animate={{ marginBottom: panelOpen ? panelHeight : 0 }}
99
- transition={{ type: 'spring', duration: 0.3, bounce: 0 }}
100
- >
101
- <WidgetGrid
102
- items={visibleItems}
103
- editing={mode === 'editing'}
104
- renderItem={renderItem}
105
- onRemove={hide}
106
- onLayoutChange={items =>
107
- setLayout({
108
- widgetGrid: items.map(i => ({ i: i.id, x: i.x ?? 0, y: i.y ?? 0 }))
109
- })
110
- }
111
- />
112
- </motion.div>
113
- </div>
114
-
115
- <AnimatePresence>
116
- {mode === 'editing' && hiddenItems.length > 0 && (
117
- <HiddenPanel
118
- ref={panelRef}
119
- items={hiddenItems}
120
- renderItem={renderItem}
121
- onRestore={restore}
122
- />
123
- )}
124
- </AnimatePresence>
125
-
126
- <AnimatePresence>
127
- {mode === 'customizing' && <CustomizePanel ref={panelRef} />}
128
- </AnimatePresence>
129
- </LayoutGroup>
130
- </div>
131
- )
132
- }
@@ -1,245 +0,0 @@
1
- import { IconDots, IconLoader2, IconPlus, IconTrash } from '@tabler/icons-react'
2
-
3
- import {
4
- useAddWorkspace,
5
- useDiscoveredWorkspaces,
6
- useRemoveWorkspace,
7
- useWorkspaces
8
- } from '@/client/api/workspaces'
9
- import claudeIcon from '@/client/assets/claude.svg'
10
- import hermesIcon from '@/client/assets/hermes-nous.png'
11
- import openclawIcon from '@/client/assets/openclaw.svg'
12
- import { Button } from '@/client/components/ui/button'
13
- import {
14
- DropdownMenu,
15
- DropdownMenuContent,
16
- DropdownMenuItem,
17
- DropdownMenuTrigger
18
- } from '@/client/components/ui/dropdown-menu'
19
- import { cn } from '@/client/lib/cn'
20
- import type { DiscoveredWorkspace, WorkspaceEntry, WorkspaceType } from '@/lib/types'
21
-
22
- import { WorkspacePreview } from './WorkspacePreview'
23
-
24
- export const typeIconSrc: Record<WorkspaceType, string> = {
25
- 'claude-code': claudeIcon,
26
- openclaw: openclawIcon,
27
- hermes: hermesIcon
28
- }
29
-
30
- export const typeLabel: Record<WorkspaceType, string> = {
31
- 'claude-code': 'Claude Code',
32
- openclaw: 'OpenClaw',
33
- hermes: 'Hermes'
34
- }
35
-
36
- type TypeIconProps = {
37
- type: WorkspaceType
38
- className?: string
39
- }
40
-
41
- export function TypeIcon({ type, className }: TypeIconProps) {
42
- return (
43
- <img
44
- src={typeIconSrc[type]}
45
- alt=""
46
- aria-label={typeLabel[type]}
47
- className={cn('size-4 shrink-0', className)}
48
- />
49
- )
50
- }
51
-
52
- export function WorkspacesPage() {
53
- const workspacesQuery = useWorkspaces()
54
- const discoveredQuery = useDiscoveredWorkspaces()
55
- const importMutation = useAddWorkspace()
56
- const removeMutation = useRemoveWorkspace()
57
-
58
- if (workspacesQuery.isPending || discoveredQuery.isPending) {
59
- return (
60
- <div className="flex min-h-[50vh] items-center justify-center">
61
- <IconLoader2 size={20} stroke={1.5} className="animate-spin text-muted-foreground" />
62
- </div>
63
- )
64
- }
65
-
66
- if (workspacesQuery.isError || discoveredQuery.isError) {
67
- return (
68
- <div className="flex min-h-[50vh] items-center justify-center">
69
- <p className="text-sm text-muted-foreground">Could not load workspaces.</p>
70
- </div>
71
- )
72
- }
73
-
74
- const workspaces = workspacesQuery.data
75
- const discovered = discoveredQuery.data
76
- const count = workspaces.length
77
- const importingPath =
78
- importMutation.isPending && importMutation.variables ? importMutation.variables.path : null
79
-
80
- return (
81
- <div className="mx-auto w-full max-w-3xl px-8 pt-14 pb-16">
82
- {count > 0 && (
83
- <div className="mb-10 grid grid-cols-2 gap-3">
84
- {workspaces.map(ws => (
85
- <WorkspaceCard
86
- key={ws.id}
87
- workspace={ws}
88
- onRemove={entry => removeMutation.mutate(entry)}
89
- />
90
- ))}
91
- </div>
92
- )}
93
-
94
- {count === 0 && discovered.length === 0 && (
95
- <p className="mb-10 text-sm text-muted-foreground">
96
- No workspaces yet. Run{' '}
97
- <code className="rounded bg-muted px-1 py-0.5 font-mono text-xs">moi init</code> in a
98
- project directory.
99
- </p>
100
- )}
101
-
102
- {discovered.length > 0 && (
103
- <section>
104
- <div className="mb-4">
105
- <h2 className="mb-1.5 text-sm font-semibold text-foreground">Found on your machine</h2>
106
- <p className="text-xs text-muted-foreground">Discovered via Claude Code and OpenClaw</p>
107
- </div>
108
- <ul className="border-t border-border">
109
- {discovered.map(item => (
110
- <SuggestedRow
111
- key={item.path}
112
- suggestion={item}
113
- onAdd={s => importMutation.mutate(s)}
114
- loading={importingPath === item.path}
115
- />
116
- ))}
117
- </ul>
118
- {importMutation.isError && (
119
- <p className="mt-3 text-xs text-destructive">{importMutation.error.message}</p>
120
- )}
121
- </section>
122
- )}
123
- </div>
124
- )
125
- }
126
-
127
- type WorkspaceCardProps = {
128
- workspace: WorkspaceEntry
129
- onRemove: (workspace: WorkspaceEntry) => void
130
- }
131
-
132
- function WorkspaceCard({ workspace, onRemove }: WorkspaceCardProps) {
133
- const name = displayName(workspace)
134
- const meta = formatAddedAt(workspace.addedAt)
135
-
136
- function handleRemove() {
137
- const message = `Remove "${name}" from your workspaces?\n\nThis only removes it from your list. The folder and its sessions stay on disk — you can add it back any time.`
138
- if (window.confirm(message)) onRemove(workspace)
139
- }
140
-
141
- return (
142
- <a
143
- href={`/workspace/${workspace.id}`}
144
- className={cn(
145
- 'group flex gap-3.5 rounded-xl border border-border bg-card p-2 hover:bg-muted/40',
146
- 'transition-colors'
147
- )}
148
- >
149
- <WorkspacePreview workspaceId={workspace.id} />
150
- <div className="flex min-w-0 flex-1 flex-col gap-1.5 py-1 pr-2 pl-1">
151
- <div className="flex items-start justify-between gap-2">
152
- <div className="flex min-w-0 items-center gap-2">
153
- <TypeIcon type={workspace.type ?? 'claude-code'} />
154
- <span className="truncate text-sm font-semibold text-foreground">{name}</span>
155
- </div>
156
- <DropdownMenu>
157
- <DropdownMenuTrigger
158
- render={
159
- <Button
160
- variant="ghost"
161
- size="icon-sm"
162
- onClick={e => {
163
- e.preventDefault()
164
- e.stopPropagation()
165
- }}
166
- className="-mt-0.5 -mr-1 text-muted-foreground"
167
- aria-label="More actions"
168
- >
169
- <IconDots stroke={1.5} />
170
- </Button>
171
- }
172
- />
173
- <DropdownMenuContent align="end" sideOffset={4} className="min-w-40">
174
- <DropdownMenuItem
175
- variant="destructive"
176
- onClick={e => {
177
- e.preventDefault()
178
- e.stopPropagation()
179
- handleRemove()
180
- }}
181
- >
182
- <IconTrash stroke={1.5} />
183
- Remove
184
- </DropdownMenuItem>
185
- </DropdownMenuContent>
186
- </DropdownMenu>
187
- </div>
188
- <div title={workspace.path} className="truncate font-mono text-xs text-muted-foreground">
189
- {workspace.displayPath ?? workspace.path}
190
- </div>
191
- <div className="flex-1" />
192
- <div className="text-xs text-muted-foreground">{meta}</div>
193
- </div>
194
- </a>
195
- )
196
- }
197
-
198
- type SuggestedRowProps = {
199
- suggestion: DiscoveredWorkspace
200
- onAdd: (suggestion: DiscoveredWorkspace) => void
201
- loading: boolean
202
- }
203
-
204
- function SuggestedRow({ suggestion, onAdd, loading }: SuggestedRowProps) {
205
- const { path, type } = suggestion
206
- const name = displayName(suggestion)
207
- return (
208
- <li className="flex items-center gap-3 border-b border-border px-1 py-2.5">
209
- <TypeIcon type={type} className="opacity-70" />
210
- <span className="shrink-0 text-sm font-medium text-foreground/80">{name}</span>
211
- <span
212
- title={path}
213
- className="min-w-0 flex-1 truncate font-mono text-xs text-muted-foreground"
214
- >
215
- {suggestion.displayPath ?? path}
216
- </span>
217
- <Button variant="outline" size="sm" onClick={() => onAdd(suggestion)} disabled={loading}>
218
- {loading ? (
219
- <IconLoader2 stroke={1.5} className="animate-spin" />
220
- ) : (
221
- <IconPlus stroke={1.5} />
222
- )}
223
- Add
224
- </Button>
225
- </li>
226
- )
227
- }
228
-
229
- function displayName(ws: Pick<WorkspaceEntry, 'name' | 'path' | 'type' | 'agentId'>): string {
230
- if (ws.name) return ws.name
231
- if (ws.type === 'openclaw') return ws.agentId ?? 'OpenClaw agent'
232
- return ws.path.split('/').pop() || ws.path
233
- }
234
-
235
- function formatAddedAt(iso: string): string {
236
- const ms = Date.now() - new Date(iso).getTime()
237
- const mins = Math.floor(ms / 60000)
238
- if (mins < 1) return 'Added just now'
239
- if (mins < 60) return `Added ${mins} min${mins === 1 ? '' : 's'} ago`
240
- const hours = Math.floor(mins / 60)
241
- if (hours < 24) return `Added ${hours} hour${hours === 1 ? '' : 's'} ago`
242
- const days = Math.floor(hours / 24)
243
- if (days < 30) return `Added ${days} day${days === 1 ? '' : 's'} ago`
244
- return `Added ${new Date(iso).toLocaleDateString()}`
245
- }
@@ -1,258 +0,0 @@
1
- import { type ReactNode, useEffect, useState } from 'react'
2
-
3
- import { AnimatePresence, motion } from 'motion/react'
4
-
5
- import {
6
- IconHome2,
7
- IconLayoutSidebar,
8
- IconLayoutSidebarLeftCollapse,
9
- IconLayoutSidebarLeftExpand,
10
- IconPlus
11
- } from '@tabler/icons-react'
12
- import { useQueryClient } from '@tanstack/react-query'
13
- import { Link } from 'wouter'
14
-
15
- import { useWorkspaces, workspaceKeys } from '@/client/api/workspaces'
16
- import { useMeiEvent } from '@/client/hooks/useMeiEvents'
17
- import claudeIcon from '@/client/assets/claude.svg'
18
- import hermesIcon from '@/client/assets/hermes-nous.png'
19
- import openclawIcon from '@/client/assets/openclaw.svg'
20
- import { type Effect, LedLogo } from '@/client/components/playground/LedLogo'
21
- import { cn } from '@/client/lib/cn'
22
- import { useUiStore } from '@/client/store/ui'
23
- import type { WorkspaceEntry, WorkspaceType } from '@/lib/types'
24
-
25
- export const PROVIDER_ICON: Record<WorkspaceType, string> = {
26
- 'claude-code': claudeIcon,
27
- openclaw: openclawIcon,
28
- hermes: hermesIcon
29
- }
30
-
31
- // Display name: explicit name → OpenClaw agentId → path basename.
32
- function workspaceLabel(ws: WorkspaceEntry): string {
33
- if (ws.name) return ws.name
34
- if (ws.type === 'openclaw') return ws.agentId ?? 'OpenClaw agent'
35
- return ws.path.split('/').pop() || ws.path
36
- }
37
-
38
- const EXPANDED_WIDTH = 240
39
- const COLLAPSED_WIDTH = 54
40
-
41
- type SidebarLayoutProps = {
42
- // Full panel content — the page supplies its own header (compose it with
43
- // <PanelHeader> + <SidebarToggle>) and body.
44
- children?: ReactNode
45
- }
46
-
47
- // App shell: a sidebar beside an elevated white content panel. Owns the
48
- // collapse state (persisted `ui` store) and the sidebar; the page owns the
49
- // panel's header and body.
50
- export function SidebarLayout({ children }: SidebarLayoutProps) {
51
- const collapsed = useUiStore(s => s.sidebarCollapsed)
52
- // Loaded once at this stable boundary — this component does NOT remount on
53
- // toggle (only the keyed <Sidebar> inside AnimatePresence does). The rows are
54
- // passed down ready, so they don't re-subscribe/refetch or flicker on collapse.
55
- const { data: workspaces } = useWorkspaces()
56
-
57
- // `moi config` / the settings modal broadcast `workspace:updated`; refetch the
58
- // list so the sidebar reflects new names/icons live.
59
- const qc = useQueryClient()
60
- useMeiEvent(e => {
61
- if (e.type === 'workspace:updated') qc.invalidateQueries({ queryKey: workspaceKeys.all })
62
- })
63
-
64
- // Boot-up: on mount the logo runs the noise effect for 0.75s, then settles to
65
- // the sprite. Kept here (not in the remounting Sidebar) so it fires once.
66
- const [booting, setBooting] = useState(true)
67
- useEffect(() => {
68
- const id = setTimeout(() => setBooting(false), 750)
69
- return () => clearTimeout(id)
70
- }, [])
71
-
72
- return (
73
- <div className="flex h-dvh bg-[#f6f7f8]">
74
- {/* Width animates; the Sidebar crossfades on collapse via AnimatePresence.
75
- The two instances are absolutely positioned so they overlap. */}
76
- <motion.div
77
- className="relative shrink-0 overflow-hidden"
78
- initial={false}
79
- animate={{ width: collapsed ? COLLAPSED_WIDTH : EXPANDED_WIDTH }}
80
- transition={{ type: 'spring', visualDuration: 0.2, bounce: 0 }}
81
- >
82
- <AnimatePresence initial={false}>
83
- <motion.div
84
- key={collapsed ? 'collapsed' : 'expanded'}
85
- className="absolute inset-y-0 left-0"
86
- // Per-version timing (each instance keeps its own props through exit):
87
- // collapse: mini = instant, full = fade out (no delay)
88
- // expand: full = fade in (no delay), mini = hold then fade out
89
- // So one layer is always fully opaque over the shared icons → no dip.
90
- initial={collapsed ? false : { opacity: 0 }}
91
- animate={{ opacity: 1, transition: { duration: 0.15, ease: 'easeOut' } }}
92
- exit={{
93
- opacity: 0,
94
- transition: collapsed
95
- ? { delay: 0.15, duration: 0.2, ease: 'easeIn' }
96
- : { duration: 0.2, ease: 'easeIn' }
97
- }}
98
- >
99
- <Sidebar
100
- collapsed={collapsed}
101
- workspaces={workspaces ?? []}
102
- logoEffect={booting ? 'chaos' : undefined}
103
- />
104
- </motion.div>
105
- </AnimatePresence>
106
- </motion.div>
107
- <main className="flex min-w-0 flex-1 flex-col overflow-hidden rounded-l-md border-l border-gray-200 bg-background shadow-[1px_0px_3px_0px_rgba(0,0,0,0.1)]">
108
- {children}
109
- </main>
110
- </div>
111
- )
112
- }
113
-
114
- // Styling-only header bar. Pages compose their header inside it, typically
115
- // starting with <SidebarToggle />.
116
- type PanelHeaderProps = {
117
- children?: ReactNode
118
- }
119
-
120
- export function PanelHeader({ children }: PanelHeaderProps) {
121
- return (
122
- <header className="@container flex h-11 shrink-0 items-center gap-2.5 border-b border-border/75 px-3">
123
- {children}
124
- </header>
125
- )
126
- }
127
-
128
- // The sidebar collapse/expand button — self-wired to the ui store. The one
129
- // header piece shared across pages.
130
- export function SidebarToggle() {
131
- const collapsed = useUiStore(s => s.sidebarCollapsed)
132
- const toggle = useUiStore(s => s.toggleSidebar)
133
- const ToggleIcon = collapsed ? IconLayoutSidebarLeftExpand : IconLayoutSidebarLeftCollapse
134
-
135
- return (
136
- <button
137
- type="button"
138
- aria-label={collapsed ? 'Expand sidebar' : 'Collapse sidebar'}
139
- title={collapsed ? 'Expand sidebar' : 'Collapse sidebar'}
140
- onClick={toggle}
141
- className={cn(
142
- 'flex size-7 items-center justify-center rounded-sm text-muted-foreground hover:bg-muted hover:text-foreground',
143
- collapsed ? 'cursor-e-resize' : 'cursor-w-resize'
144
- )}
145
- >
146
- <ToggleIcon size={20} strokeWidth={1.5} />
147
- </button>
148
- )
149
- }
150
-
151
- type SidebarProps = {
152
- // Collapsed keeps the sidebar's width: content is hidden in place (logo +
153
- // workspaces header stay invisible but occupy space) and rows drop their text.
154
- collapsed?: boolean
155
- workspaces: WorkspaceEntry[]
156
- logoEffect?: Effect
157
- }
158
-
159
- function Sidebar({ collapsed, workspaces, logoEffect }: SidebarProps) {
160
- return (
161
- <aside className={cn('flex h-full shrink-0 flex-col px-2.5', collapsed ? 'w-[54px]' : 'w-60')}>
162
- {/* Logo */}
163
- <div className="mb-3.5 flex h-11 items-center px-2">
164
- <LedLogo
165
- pixelSize={3}
166
- gap={0.5}
167
- sprite={collapsed ? 'moi' : 'moi-full'}
168
- effect={logoEffect}
169
- />
170
- </div>
171
-
172
- {/* Home */}
173
- <nav className="flex flex-col gap-0.5">
174
- <NavRow
175
- href="/"
176
- icon={<IconHome2 size={18} className="shrink-0 text-foreground" />}
177
- label="Home"
178
- collapsed={collapsed}
179
- />
180
- </nav>
181
-
182
- {/* Workspaces */}
183
- <div className="mt-5 flex flex-col gap-2">
184
- <div className={cn('flex items-center justify-between pl-2', collapsed && 'invisible')}>
185
- <span className="text-[13px] font-medium text-muted-foreground">Workspaces</span>
186
- <Link
187
- href="/workspace/create"
188
- aria-label="Add workspace"
189
- className="flex size-6 items-center justify-center rounded-[6px] border border-border bg-background text-foreground/60 hover:bg-muted hover:text-foreground"
190
- >
191
- <IconPlus size={16} />
192
- </Link>
193
- </div>
194
-
195
- <nav className="flex flex-col gap-0.5">
196
- {workspaces.map(ws => (
197
- <NavRow
198
- key={ws.id}
199
- href={`/workspace/${ws.id}`}
200
- icon={
201
- <img
202
- src={ws.icon ?? PROVIDER_ICON[ws.type ?? 'claude-code']}
203
- alt=""
204
- className="size-5 shrink-0 rounded-[4px]"
205
- />
206
- }
207
- label={workspaceLabel(ws)}
208
- collapsed={collapsed}
209
- />
210
- ))}
211
- </nav>
212
- </div>
213
-
214
- <div className="flex-1" />
215
-
216
- {/* Footer */}
217
- <div className="flex items-center justify-between gap-2 py-3">
218
- {/* Temporarily hidden */}
219
- <button
220
- type="button"
221
- aria-label="Toggle sidebar"
222
- className="hidden size-7 items-center justify-center rounded-[6px] text-foreground/45 hover:bg-foreground/[0.06] hover:text-foreground/80"
223
- >
224
- <IconLayoutSidebar size={16} />
225
- </button>
226
- </div>
227
- </aside>
228
- )
229
- }
230
-
231
- type NavRowProps = {
232
- href: string
233
- icon: ReactNode
234
- label: string
235
- collapsed?: boolean
236
- }
237
-
238
- function NavRow({ href, icon, label, collapsed }: NavRowProps) {
239
- // wouter resolves `active` by matching `href` against the current location
240
- // (exact match — a workspace row lights up only on its own route).
241
- return (
242
- <Link
243
- href={href}
244
- aria-label={label}
245
- className={active =>
246
- cn(
247
- 'flex h-8 items-center gap-2.5 rounded-sm px-2 text-sm font-medium',
248
- active
249
- ? 'bg-foreground/[0.07] text-foreground'
250
- : 'text-foreground/65 hover:bg-foreground/[0.04] hover:text-foreground'
251
- )
252
- }
253
- >
254
- {icon}
255
- {!collapsed && <span className="truncate">{label}</span>}
256
- </Link>
257
- )
258
- }