moi-computer 0.3.0 → 0.3.1-next.1

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 (121) hide show
  1. package/client/api/workspace-keys.ts +2 -2
  2. package/client/app/AppRouter.tsx +0 -2
  3. package/client/app/routes/WorkspaceRoute.tsx +3 -1
  4. package/client/app/shell/SidebarLayout.tsx +3 -16
  5. package/client/assets/openai.svg +1 -3
  6. package/client/components/shared/Composer.tsx +112 -0
  7. package/client/components/ui/button.tsx +1 -1
  8. package/client/components/ui/dropdown-menu.tsx +3 -3
  9. package/client/components/ui/tooltip.tsx +12 -15
  10. package/client/features/applets/WidgetErrorBoundary.tsx +19 -3
  11. package/client/features/applets/WidgetShell.tsx +8 -1
  12. package/client/features/applets/applet-log.ts +100 -0
  13. package/client/features/applets/useApplet.ts +21 -7
  14. package/client/features/chat/ChatComposer.tsx +33 -30
  15. package/client/features/chat/ChatPanel.tsx +5 -2
  16. package/client/features/chat/MarkdownContent.tsx +20 -2
  17. package/client/features/chat/ModelPicker.tsx +29 -41
  18. package/client/features/chat/TurnView.tsx +2 -2
  19. package/client/features/chat/chat-frames.ts +14 -6
  20. package/client/features/chat/chat-send.ts +1 -1
  21. package/client/features/chat/chat-store.ts +22 -17
  22. package/client/features/chat/model-order.ts +47 -0
  23. package/client/features/chat/tool-group/ToolOutput.tsx +4 -12
  24. package/client/features/chat/tool-group/format.ts +0 -6
  25. package/client/features/chat/useChat.ts +15 -2
  26. package/client/features/connectors/McpServerCards.tsx +95 -0
  27. package/client/features/connectors/api.ts +0 -11
  28. package/client/features/home/HomePage.tsx +45 -42
  29. package/client/features/home/WorkspacePreview.tsx +179 -38
  30. package/client/features/home/api.ts +24 -12
  31. package/client/features/home/workspace-presentation.tsx +17 -15
  32. package/client/features/home/workspace-setup/CreateWorkspaceDialog.tsx +243 -0
  33. package/client/features/home/workspace-setup/ImportWorkspaceDialog.tsx +95 -0
  34. package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +230 -0
  35. package/client/features/home/workspace-setup/WorkspaceDialogContent.tsx +35 -0
  36. package/client/features/home/workspace-setup/useWorkspaceImport.ts +61 -0
  37. package/client/features/settings/ConnectorsSettings.tsx +89 -0
  38. package/client/features/settings/GeneralSettings.tsx +12 -0
  39. package/client/features/settings/SettingsLayout.tsx +2 -2
  40. package/client/features/settings/WorkspaceSettings.tsx +8 -4
  41. package/client/features/views/ViewBuilderTab.tsx +28 -29
  42. package/client/features/views/useViewBuilderActions.ts +1 -1
  43. package/client/features/widgets/WidgetFrame.tsx +3 -0
  44. package/client/features/widgets/WidgetGrid.tsx +1 -0
  45. package/client/features/widgets/Widgets.tsx +12 -3
  46. package/client/features/widgets/api.ts +47 -0
  47. package/client/features/widgets/useWidgetThumbnails.ts +107 -0
  48. package/client/features/widgets/widget-snapshot.ts +71 -0
  49. package/client/features/workspace/WorkspaceLayoutContext.tsx +3 -4
  50. package/client/features/workspace/WorkspaceScreen.tsx +19 -4
  51. package/client/features/workspace/api.ts +25 -3
  52. package/client/features/workspace/moi-context.ts +85 -0
  53. package/client/index.css +0 -5
  54. package/client/main.tsx +13 -4
  55. package/dist/{chunk-cs8vbert.js → chunk-1dfbr7n2.js} +2 -2
  56. package/dist/chunk-339jds4x.js +15 -0
  57. package/dist/chunk-3xsvsnhr.css +1 -0
  58. package/dist/{chunk-zpxrb1ce.js → chunk-anqmsbjt.js} +2 -2
  59. package/dist/chunk-hbvfb6sk.js +63 -0
  60. package/dist/chunk-jen6xcm1.js +14 -0
  61. package/dist/{chunk-kxmvv1ax.js → chunk-qwm5f6qk.js} +1 -1
  62. package/dist/{chunk-fjksw6xf.js → chunk-sxbfh73c.js} +1 -1
  63. package/dist/chunk-yp4srgqt.js +10 -0
  64. package/dist/index.html +1 -1
  65. package/dist/openai-ep9ht2pq.svg +1 -0
  66. package/lib/ids.ts +15 -0
  67. package/lib/moi-context.ts +170 -0
  68. package/lib/types.ts +95 -13
  69. package/lib/view-builder-directives.ts +16 -0
  70. package/lib/workspace-types.ts +12 -0
  71. package/package.json +4 -2
  72. package/server/api.ts +180 -34
  73. package/server/applet-log.ts +149 -0
  74. package/server/cli.ts +161 -7
  75. package/server/control.ts +81 -1
  76. package/server/functions.ts +44 -14
  77. package/server/harness/README.md +26 -9
  78. package/server/harness/claude-code/NOTES.md +20 -6
  79. package/server/harness/claude-code/adapter.ts +2 -2
  80. package/server/harness/claude-code/git-worktree.ts +32 -0
  81. package/server/harness/claude-code/index.ts +35 -13
  82. package/server/harness/claude-code/mcp.ts +16 -65
  83. package/server/harness/claude-code/models.ts +3 -0
  84. package/server/harness/claude-code/session.ts +196 -61
  85. package/server/harness/claude-code/sessions.ts +51 -0
  86. package/server/harness/codex/NOTES.md +41 -11
  87. package/server/harness/codex/adapter.ts +52 -6
  88. package/server/harness/codex/client.ts +69 -18
  89. package/server/harness/codex/discovery.ts +114 -0
  90. package/server/harness/codex/index.ts +12 -5
  91. package/server/harness/codex/probe.ts +4 -2
  92. package/server/harness/codex/session.ts +57 -5
  93. package/server/harness/executable.ts +82 -0
  94. package/server/harness/openclaw/adapter.ts +8 -1
  95. package/server/harness/openclaw/discovery.ts +139 -6
  96. package/server/harness/openclaw/gateway.ts +40 -18
  97. package/server/harness/openclaw/index.ts +12 -15
  98. package/server/harness/openclaw/session.ts +50 -10
  99. package/server/harness/openclaw/strip.ts +2 -2
  100. package/server/harness/shell-path.ts +79 -0
  101. package/server/harness/types.ts +37 -5
  102. package/server/layout.ts +81 -51
  103. package/server/registry.ts +57 -12
  104. package/server/scratchpad-assets.ts +41 -6
  105. package/server/scratchpad.ts +30 -0
  106. package/server/view-builders.ts +3 -2
  107. package/server/views.ts +5 -0
  108. package/server/web.ts +30 -8
  109. package/server/widgets.ts +23 -2
  110. package/server/workspace-import.ts +45 -0
  111. package/workspace/.claude/skills/moi-workspace/SKILL.md +27 -3
  112. package/client/features/connectors/ConnectorsPage.tsx +0 -92
  113. package/client/features/connectors/McpMenu.tsx +0 -145
  114. package/client/features/home/CreateWorkspaceDialog.tsx +0 -130
  115. package/client/features/home/CreateWorkspaceDialogSteps.tsx +0 -234
  116. package/dist/chunk-4vf1t6v1.js +0 -10
  117. package/dist/chunk-4z52b2av.css +0 -1
  118. package/dist/chunk-b4b276wx.js +0 -15
  119. package/dist/chunk-y82s1jxm.js +0 -61
  120. package/dist/openai-h13pza4b.svg +0 -3
  121. package/lib/view-builder-meta.ts +0 -35
@@ -2,7 +2,9 @@ import { useCallback, useMemo } from 'react'
2
2
 
3
3
  import { useQueryClient } from '@tanstack/react-query'
4
4
 
5
+ import { workspaceKeys } from '@/client/api/workspace-keys'
5
6
  import { useSessionView, useThreadConfig, useWorkspaceModels } from '@/client/features/chat/api'
7
+ import { useMoiUserMessageContext } from '@/client/features/workspace/moi-context'
6
8
  import { useWorkspaceId } from '@/client/features/workspace/WorkspaceContext'
7
9
  import { useWorkspaceLayoutCtx } from '@/client/features/workspace/WorkspaceLayoutContext'
8
10
  import { sendMessage } from '@/client/features/chat/chat-connection'
@@ -22,11 +24,17 @@ export function useChat() {
22
24
  const qc = useQueryClient()
23
25
  const { layout } = useWorkspaceLayoutCtx()
24
26
  const modelsData = useWorkspaceModels(workspaceId).data
27
+ // Snapshot of the workspace's ambient UI state + queued one-shot
28
+ // directives, taken when the message actually goes out.
29
+ const buildMoiContext = useMoiUserMessageContext()
25
30
 
26
31
  const activeSessionId = useLive(s => s.activeByWorkspace[workspaceId] ?? null)
27
- const processing = useLive(s =>
28
- activeSessionId ? (s.processing[`${workspaceId}:${activeSessionId}`] ?? false) : false
32
+ const activity = useLive(s =>
33
+ activeSessionId ? (s.activity[`${workspaceId}:${activeSessionId}`] ?? 'idle') : 'idle'
29
34
  )
35
+ // Only `running` shows the loader/Stop. `requires-action` (agent blocked on
36
+ // user input) deliberately renders like idle until it gets its own UI.
37
+ const processing = activity === 'running'
30
38
  const error = useLive(s =>
31
39
  activeSessionId ? (s.errors[`${workspaceId}:${activeSessionId}`] ?? null) : null
32
40
  )
@@ -110,8 +118,12 @@ export function useChat() {
110
118
  model,
111
119
  effort,
112
120
  stream,
121
+ context: buildMoiContext(),
113
122
  ...(ready.length > 0 ? { attachments: ready.map(a => a.upload!.id) } : {})
114
123
  })
124
+ if (isNew) {
125
+ qc.invalidateQueries({ queryKey: workspaceKeys.preview(workspaceId) })
126
+ }
115
127
  // Drop the thread's attachments now that they've been sent (revokes the
116
128
  // preview object URLs). Keyed by the pre-mint id, matching where they were
117
129
  // stored by the composer.
@@ -123,6 +135,7 @@ export function useChat() {
123
135
  qc,
124
136
  layout.selectedModel,
125
137
  layout.selectedEffort,
138
+ buildMoiContext,
126
139
  threadCfg?.model,
127
140
  threadCfg?.effort,
128
141
  modelsData
@@ -0,0 +1,95 @@
1
+ import type { ReactNode } from 'react'
2
+
3
+ import { IconAlertCircleFilled } from '@tabler/icons-react'
4
+
5
+ import { Skeleton } from '@/client/components/ui/skeleton'
6
+ import { IconMcp } from '@/client/features/connectors/IconMcp'
7
+ import { formatMcpServerName, getMcpIcon } from '@/client/features/connectors/mcp-icons'
8
+ import type { McpServer } from '@/lib/types'
9
+
10
+ function statusLabel(status: McpServer['status']): string {
11
+ if (status === 'needs-auth') return 'Needs auth'
12
+ return status[0].toUpperCase() + status.slice(1)
13
+ }
14
+
15
+ type McpServerIconProps = {
16
+ name: string
17
+ status: McpServer['status']
18
+ }
19
+
20
+ function McpServerIcon({ name, status }: McpServerIconProps) {
21
+ const icon = getMcpIcon(name)
22
+ const className = 'size-full rounded-sm ring-2 ring-background'
23
+
24
+ return (
25
+ <span className="relative size-10 shrink-0">
26
+ {icon ? (
27
+ <img src={icon} alt="" className={className} />
28
+ ) : (
29
+ <span className="flex size-full items-center justify-center rounded-sm bg-muted text-muted-foreground ring-2 ring-background">
30
+ <IconMcp className="size-5" />
31
+ </span>
32
+ )}
33
+ {status !== 'connected' && (
34
+ <IconAlertCircleFilled
35
+ aria-hidden="true"
36
+ size={16}
37
+ stroke={1.75}
38
+ className="absolute -top-1 -right-1 rounded-full bg-card text-amber-400"
39
+ />
40
+ )}
41
+ </span>
42
+ )
43
+ }
44
+
45
+ export function sortMcpServers(servers: McpServer[]): McpServer[] {
46
+ return [...servers].sort(
47
+ (a, b) => Number(b.status === 'connected') - Number(a.status === 'connected')
48
+ )
49
+ }
50
+
51
+ type McpServerCardProps = {
52
+ server: McpServer
53
+ }
54
+
55
+ type McpServerCardLayoutProps = {
56
+ icon: ReactNode
57
+ children: ReactNode
58
+ }
59
+
60
+ function McpServerCardLayout({ icon, children }: McpServerCardLayoutProps) {
61
+ return (
62
+ <div className="flex items-center gap-3 text-card-foreground">
63
+ {icon}
64
+ <div className="flex min-w-0 flex-1 flex-col justify-center gap-0.5">{children}</div>
65
+ </div>
66
+ )
67
+ }
68
+
69
+ export function McpServerCard({ server }: McpServerCardProps) {
70
+ return (
71
+ <McpServerCardLayout icon={<McpServerIcon name={server.name} status={server.status} />}>
72
+ <div className="truncate text-sm font-medium text-foreground">
73
+ {formatMcpServerName(server.name)}
74
+ </div>
75
+ <span className="text-sm text-muted-foreground">{statusLabel(server.status)}</span>
76
+ </McpServerCardLayout>
77
+ )
78
+ }
79
+
80
+ export function McpServerCardSkeleton() {
81
+ return (
82
+ <McpServerCardLayout icon={<Skeleton className="size-10 shrink-0 rounded-sm" />}>
83
+ <Skeleton className="h-4 w-36 max-w-full" />
84
+ <Skeleton className="h-4 w-20" />
85
+ </McpServerCardLayout>
86
+ )
87
+ }
88
+
89
+ type McpServerGridProps = {
90
+ children: ReactNode
91
+ }
92
+
93
+ export function McpServerGrid({ children }: McpServerGridProps) {
94
+ return <div className="grid grid-cols-1 gap-6 sm:grid-cols-2">{children}</div>
95
+ }
@@ -15,14 +15,3 @@ export function useWorkspaceMcp(workspaceId: string, enabled: boolean) {
15
15
  refetchOnWindowFocus: false
16
16
  })
17
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
- }
@@ -1,7 +1,15 @@
1
1
  import { IconChevronRight, IconEggCracked, IconLoader2, IconPlus } from '@tabler/icons-react'
2
2
  import { Link, useLocation } from 'wouter'
3
3
 
4
- import { useAddWorkspace, useDiscoveredWorkspaces, useWorkspaces } from './api'
4
+ import {
5
+ useDiscoveredWorkspaces,
6
+ useWorkspacePreview,
7
+ useWorkspaces,
8
+ useWorkspaceSetupInfo
9
+ } from './api'
10
+ import { CreateWorkspaceDialog } from './workspace-setup/CreateWorkspaceDialog'
11
+ import { ImportWorkspaceDialog } from './workspace-setup/ImportWorkspaceDialog'
12
+ import { useWorkspaceImport } from './workspace-setup/useWorkspaceImport'
5
13
  import { HomeLogo } from './HomeLogo'
6
14
  import { Button } from '@/client/components/ui/button'
7
15
  import {
@@ -12,20 +20,22 @@ import {
12
20
  import { cn } from '@/client/lib/cn'
13
21
  import { useUiStore } from '@/client/store/ui'
14
22
  import {
15
- WorkspaceTypeIcon,
23
+ WorkspaceAgentIcons,
16
24
  workspaceDisplayName,
17
25
  workspaceProviderIcon
18
26
  } from '@/client/features/home/workspace-presentation'
19
27
  import type { DiscoveredWorkspace, WorkspaceEntry } from '@/lib/types'
20
28
 
21
- import { CreateWorkspaceDialog } from './CreateWorkspaceDialog'
22
29
  import { WorkspacePreview } from './WorkspacePreview'
23
30
 
24
31
  export function HomePage() {
25
32
  const [, navigate] = useLocation()
26
33
  const workspacesQuery = useWorkspaces()
27
34
  const discoveredQuery = useDiscoveredWorkspaces()
28
- const importMutation = useAddWorkspace()
35
+ const setupInfo = useWorkspaceSetupInfo()
36
+ const importFlow = useWorkspaceImport({
37
+ onSuccess: entry => navigate(`/workspace/${entry.id}`)
38
+ })
29
39
  const discoveredWorkspacesOpen = useUiStore(state => state.discoveredWorkspacesOpen)
30
40
  const setDiscoveredWorkspacesOpen = useUiStore(state => state.setDiscoveredWorkspacesOpen)
31
41
 
@@ -48,13 +58,9 @@ export function HomePage() {
48
58
  const workspaces = workspacesQuery.data
49
59
  const discovered = discoveredQuery.data
50
60
  const count = workspaces.length
51
- const importingPath =
52
- importMutation.isPending && importMutation.variables ? importMutation.variables.path : null
53
61
 
54
62
  function handleAdd(suggestion: DiscoveredWorkspace) {
55
- importMutation.mutate(suggestion, {
56
- onSuccess: entry => navigate(`/workspace/${entry.id}`)
57
- })
63
+ importFlow.startImport(suggestion)
58
64
  }
59
65
 
60
66
  return (
@@ -122,21 +128,25 @@ export function HomePage() {
122
128
  <CollapsibleContent>
123
129
  <ul className="border-t border-border">
124
130
  {discovered.map(item => (
125
- <SuggestedRow
126
- key={item.path}
127
- suggestion={item}
128
- onAdd={handleAdd}
129
- loading={importingPath === item.path}
130
- />
131
+ <SuggestedRow key={item.path} suggestion={item} onAdd={handleAdd} />
131
132
  ))}
132
133
  </ul>
133
- {importMutation.isError && (
134
- <p className="mt-3 text-xs text-destructive">{importMutation.error.message}</p>
135
- )}
136
134
  </CollapsibleContent>
137
135
  </Collapsible>
138
136
  </section>
139
137
  )}
138
+
139
+ {importFlow.choice && (
140
+ <ImportWorkspaceDialog
141
+ choice={importFlow.choice}
142
+ availability={setupInfo.data?.availability}
143
+ isPending={importFlow.isPending}
144
+ errorMessage={importFlow.error?.message}
145
+ onTypeChange={importFlow.selectType}
146
+ onSubmit={importFlow.submit}
147
+ onReset={importFlow.reset}
148
+ />
149
+ )}
140
150
  </div>
141
151
  )
142
152
  }
@@ -147,7 +157,8 @@ type WorkspaceCardProps = {
147
157
 
148
158
  function WorkspaceCard({ workspace }: WorkspaceCardProps) {
149
159
  const name = workspaceDisplayName(workspace)
150
- const meta = formatAddedAt(workspace.addedAt)
160
+ const previewQuery = useWorkspacePreview(workspace.id)
161
+ const updatedAt = previewQuery.data?.updatedAt ?? new Date(workspace.addedAt).getTime()
151
162
 
152
163
  return (
153
164
  <Link
@@ -155,8 +166,8 @@ function WorkspaceCard({ workspace }: WorkspaceCardProps) {
155
166
  className="group flex min-w-0 flex-col gap-4 rounded-xl bg-card p-2 shadow-xs transition-shadow hover:shadow-sm"
156
167
  >
157
168
  <WorkspacePreview workspaceId={workspace.id} />
158
- <div className="flex min-w-0 flex-col px-2 pb-2">
159
- <div className="flex min-w-0 items-center gap-2">
169
+ <div className="flex min-w-0 flex-col gap-2 px-2 pb-2">
170
+ <div className="flex min-w-0 items-center gap-1.5">
160
171
  <img
161
172
  src={workspace.icon ?? workspaceProviderIcon[workspace.type ?? 'claude-code']}
162
173
  alt=""
@@ -164,10 +175,7 @@ function WorkspaceCard({ workspace }: WorkspaceCardProps) {
164
175
  />
165
176
  <span className="truncate text-sm font-medium text-foreground">{name}</span>
166
177
  </div>
167
- <div title={workspace.path} className="mt-2 truncate text-xs text-muted-foreground">
168
- {workspace.displayPath ?? workspace.path}
169
- </div>
170
- <div className="mt-2 text-xs text-muted-foreground">{meta}</div>
178
+ <span className="text-xs text-muted-foreground">{formatUpdatedAt(updatedAt)}</span>
171
179
  </div>
172
180
  </Link>
173
181
  )
@@ -176,39 +184,34 @@ function WorkspaceCard({ workspace }: WorkspaceCardProps) {
176
184
  type SuggestedRowProps = {
177
185
  suggestion: DiscoveredWorkspace
178
186
  onAdd: (suggestion: DiscoveredWorkspace) => void
179
- loading: boolean
180
187
  }
181
188
 
182
- function SuggestedRow({ suggestion, onAdd, loading }: SuggestedRowProps) {
183
- const { path, type } = suggestion
189
+ function SuggestedRow({ suggestion, onAdd }: SuggestedRowProps) {
190
+ const { path, types } = suggestion
184
191
  const name = workspaceDisplayName(suggestion)
185
192
  return (
186
193
  <li className="flex items-center gap-2 border-b border-border px-1 py-3">
187
- <WorkspaceTypeIcon type={type} />
194
+ <WorkspaceAgentIcons types={types} />
188
195
  <span className="shrink-0 text-sm font-medium text-foreground">{name}</span>
189
196
  <span title={path} className="min-w-0 flex-1 truncate text-xs text-muted-foreground">
190
197
  {suggestion.displayPath ?? path}
191
198
  </span>
192
- <Button variant="outline" size="sm" onClick={() => onAdd(suggestion)} disabled={loading}>
193
- {loading ? (
194
- <IconLoader2 stroke={1.75} className="animate-spin" />
195
- ) : (
196
- <IconPlus stroke={1.75} />
197
- )}
199
+ <Button variant="outline" size="sm" onClick={() => onAdd(suggestion)}>
200
+ <IconPlus stroke={1.75} />
198
201
  Add
199
202
  </Button>
200
203
  </li>
201
204
  )
202
205
  }
203
206
 
204
- function formatAddedAt(iso: string): string {
205
- const ms = Date.now() - new Date(iso).getTime()
207
+ function formatUpdatedAt(timestamp: number): string {
208
+ const ms = Date.now() - timestamp
206
209
  const mins = Math.floor(ms / 60000)
207
- if (mins < 1) return 'Added just now'
208
- if (mins < 60) return `Added ${mins} min${mins === 1 ? '' : 's'} ago`
210
+ if (mins < 1) return 'Updated just now'
211
+ if (mins < 60) return `Updated ${mins} min${mins === 1 ? '' : 's'} ago`
209
212
  const hours = Math.floor(mins / 60)
210
- if (hours < 24) return `Added ${hours} hour${hours === 1 ? '' : 's'} ago`
213
+ if (hours < 24) return `Updated ${hours} hour${hours === 1 ? '' : 's'} ago`
211
214
  const days = Math.floor(hours / 24)
212
- if (days < 30) return `Added ${days} day${days === 1 ? '' : 's'} ago`
213
- return `Added ${new Date(iso).toLocaleDateString()}`
215
+ if (days < 30) return `Updated ${days} day${days === 1 ? '' : 's'} ago`
216
+ return `Updated ${new Date(timestamp).toLocaleDateString()}`
214
217
  }
@@ -1,55 +1,196 @@
1
- import { IconGhost } from '@tabler/icons-react'
1
+ import { useLayoutEffect, useRef, useState } from 'react'
2
2
 
3
- import { useWorkspacePreview } from './api'
4
3
  import { cn } from '@/client/lib/cn'
5
4
 
5
+ import { useWorkspacePreview } from './api'
6
+
6
7
  type WorkspacePreviewProps = {
7
8
  workspaceId: string
8
9
  }
9
10
 
10
- export function WorkspacePreview({ workspaceId }: WorkspacePreviewProps) {
11
- const query = useWorkspacePreview(workspaceId)
11
+ const FOLDER = {
12
+ width: 320,
13
+ height: 160,
14
+ radius: 24,
15
+ topLeftRadius: 12,
16
+ bodyTop: 24,
17
+ tabEnd: 124,
18
+ shoulder: {
19
+ width: 48,
20
+ roundness: 20
21
+ }
22
+ } as const
23
+
24
+ function folderBackdropPath(horizontalRadiusScale: number): string {
25
+ const {
26
+ width,
27
+ height,
28
+ radius: radiusY,
29
+ topLeftRadius: topLeftRadiusY,
30
+ bodyTop,
31
+ tabEnd,
32
+ shoulder
33
+ } = FOLDER
34
+ const radiusX = Math.min(width / 2, radiusY * horizontalRadiusScale)
35
+ const topLeftRadiusX = Math.min(width / 2, topLeftRadiusY * horizontalRadiusScale)
36
+ const shoulderWidth = Math.max(0, shoulder.width)
37
+ const bodyStart = tabEnd + shoulderWidth
38
+ const roundness = Math.max(0, Math.min(shoulder.roundness, shoulderWidth / 2))
39
+
40
+ return [
41
+ `M ${topLeftRadiusX} 0`,
42
+ `H ${tabEnd}`,
43
+ `C ${tabEnd + roundness} 0 ${bodyStart - roundness} ${bodyTop} ${bodyStart} ${bodyTop}`,
44
+ `H ${width - radiusX}`,
45
+ `Q ${width} ${bodyTop} ${width} ${bodyTop + radiusY}`,
46
+ `V ${height - radiusY}`,
47
+ `Q ${width} ${height} ${width - radiusX} ${height}`,
48
+ `H ${radiusX}`,
49
+ `Q 0 ${height} 0 ${height - radiusY}`,
50
+ `V ${topLeftRadiusY}`,
51
+ `Q 0 0 ${topLeftRadiusX} 0`,
52
+ 'Z'
53
+ ].join(' ')
54
+ }
55
+
56
+ function useFolderRadiusScale() {
57
+ const ref = useRef<HTMLDivElement>(null)
58
+ const [horizontalRadiusScale, setHorizontalRadiusScale] = useState(1)
59
+
60
+ useLayoutEffect(() => {
61
+ const element = ref.current
62
+ if (!element) return
63
+
64
+ const update = (width: number, height: number) => {
65
+ if (width <= 0 || height <= 0) return
66
+ const scaleX = width / FOLDER.width
67
+ const scaleY = height / FOLDER.height
68
+ const nextScale = scaleY / scaleX
69
+ setHorizontalRadiusScale(current =>
70
+ Math.abs(current - nextScale) < 0.001 ? current : nextScale
71
+ )
72
+ }
73
+
74
+ const bounds = element.getBoundingClientRect()
75
+ update(bounds.width, bounds.height)
12
76
 
13
- const items = query.data?.items ?? []
14
- const cols = query.data?.cols ?? 4
15
- const rows = items.length ? Math.max(...items.map(i => i.y + i.h)) : 0
16
- const hasItems = items.length > 0 && rows > 0
17
- const isEmpty = query.data !== undefined && !hasItems
77
+ const observer = new ResizeObserver(([entry]) => {
78
+ if (entry) update(entry.contentRect.width, entry.contentRect.height)
79
+ })
80
+ observer.observe(element)
81
+ return () => observer.disconnect()
82
+ }, [])
18
83
 
19
- const overflows = rows > cols
84
+ return { ref, horizontalRadiusScale }
85
+ }
86
+
87
+ // Bottom-to-top placement for up to three widget screenshots. Each card peeks
88
+ // out of the folder at a slightly different angle and lifts on card hover.
89
+ const STACK = [
90
+ cn(
91
+ 'opacity-40',
92
+ '-translate-x-3 translate-y-3 -rotate-6',
93
+ 'group-hover:translate-y-2 group-focus-visible:translate-y-2'
94
+ ),
95
+ cn(
96
+ 'opacity-50',
97
+ 'translate-x-3 translate-y-2 rotate-5',
98
+ 'group-hover:translate-y-1 group-focus-visible:translate-y-1'
99
+ ),
100
+ cn(
101
+ 'opacity-100',
102
+ '-translate-x-1 translate-y-1 -rotate-2',
103
+ 'group-hover:-translate-y-2 group-focus-visible:-translate-y-2'
104
+ )
105
+ ]
106
+
107
+ export function WorkspacePreview({ workspaceId }: WorkspacePreviewProps) {
108
+ const query = useWorkspacePreview(workspaceId)
109
+ const thumbnails = query.data ? [...query.data.thumbnails].reverse() : []
110
+ const slots = STACK.slice(STACK.length - thumbnails.length)
111
+ const firstUserMessage = query.data?.firstUserMessage
112
+ const { ref, horizontalRadiusScale } = useFolderRadiusScale()
113
+ const backdropPath = folderBackdropPath(horizontalRadiusScale)
114
+ const noiseFilterId = `folder-noise-${workspaceId}`
20
115
 
21
116
  return (
22
- <div
23
- className={cn(
24
- 'flex aspect-square w-full justify-center overflow-hidden rounded-sm bg-muted p-3',
25
- overflows ? 'items-start' : 'items-center'
26
- )}
27
- >
28
- {hasItems && (
29
- <svg
30
- viewBox={`0 0 ${cols} ${rows}`}
31
- className="w-full shrink-0 animate-in duration-300 fade-in"
32
- >
33
- {items.map((item, i) => (
34
- <rect
35
- key={i}
36
- x={item.x + 0.06}
37
- y={item.y + 0.06}
38
- width={item.w - 0.12}
39
- height={item.h - 0.12}
40
- rx={0.12}
41
- className="fill-muted-foreground/30"
117
+ <div ref={ref} className="relative h-40 w-full">
118
+ <svg
119
+ viewBox={`0 0 ${FOLDER.width} ${FOLDER.height}`}
120
+ preserveAspectRatio="none"
121
+ aria-hidden="true"
122
+ className="absolute inset-0 h-full w-full overflow-visible"
123
+ >
124
+ <defs>
125
+ <filter
126
+ id={noiseFilterId}
127
+ x="0%"
128
+ y="0%"
129
+ width="100%"
130
+ height="100%"
131
+ colorInterpolationFilters="sRGB"
132
+ >
133
+ <feTurbulence
134
+ type="fractalNoise"
135
+ baseFrequency="0.5"
136
+ numOctaves="3"
137
+ seed="7"
138
+ result="noise"
42
139
  />
43
- ))}
44
- </svg>
45
- )}
46
- {isEmpty && (
47
- <IconGhost
48
- size={20}
49
- stroke={1.5}
50
- className="animate-in text-muted-foreground/40 duration-300 fade-in"
140
+ <feColorMatrix in="noise" type="saturate" values="0" result="monochromeNoise" />
141
+ <feComponentTransfer in="monochromeNoise" result="faintNoise">
142
+ <feFuncA type="linear" slope="0.24" />
143
+ </feComponentTransfer>
144
+ <feComposite in="faintNoise" in2="SourceAlpha" operator="in" result="clippedNoise" />
145
+ <feBlend in="SourceGraphic" in2="clippedNoise" mode="soft-light" />
146
+ </filter>
147
+ </defs>
148
+ <path
149
+ d={backdropPath}
150
+ filter={`url(#${noiseFilterId})`}
151
+ className="mask-[linear-gradient(to_bottom,rgba(0,0,0,0.5),black_40%)] fill-accent"
152
+ />
153
+ </svg>
154
+
155
+ {thumbnails.map((src, index) => (
156
+ <img
157
+ key={index}
158
+ src={src}
159
+ alt=""
160
+ loading="lazy"
161
+ className={cn(
162
+ 'absolute top-[12%] left-[14%] aspect-4/3 w-[72%] rounded-sm object-cover object-top shadow-xs',
163
+ 'animate-in transition-transform duration-300 ease-out fade-in',
164
+ slots[index]
165
+ )}
51
166
  />
167
+ ))}
168
+
169
+ {thumbnails.length === 0 && firstUserMessage && (
170
+ <div className="absolute inset-x-[12%] top-[20%] flex justify-end">
171
+ <div
172
+ aria-hidden="true"
173
+ className={cn(
174
+ 'w-max max-w-40 origin-center rounded-sm bg-card px-3 py-2 shadow-xs',
175
+ 'animate-in transition-transform duration-300 ease-out fade-in',
176
+ STACK[STACK.length - 1],
177
+ 'group-hover:translate-y-0.5 group-focus-visible:translate-y-0.5'
178
+ )}
179
+ >
180
+ <p className="line-clamp-3 text-sm leading-normal whitespace-normal">
181
+ {firstUserMessage}
182
+ </p>
183
+ </div>
184
+ </div>
52
185
  )}
186
+
187
+ <div
188
+ className={cn(
189
+ 'absolute inset-x-2 top-[40%] bottom-2 rounded-lg bg-accent',
190
+ 'mask-[linear-gradient(to_bottom,rgba(0,0,0,0.9)_0%,black_50%)] backdrop-blur-lg',
191
+ 'inset-shadow-[0_0_12px_color-mix(in_oklab,var(--background)_20%,transparent)]'
192
+ )}
193
+ />
53
194
  </div>
54
195
  )
55
196
  }
@@ -4,6 +4,7 @@ import { jsonRequest, requestJson, requestVoid } from '@/client/api/http'
4
4
  import { workspaceKeys } from '@/client/api/workspace-keys'
5
5
  import type {
6
6
  DiscoveredWorkspace,
7
+ HarnessAvailability,
7
8
  WorkspaceEntry,
8
9
  WorkspacePreview,
9
10
  WorkspaceType
@@ -43,37 +44,48 @@ export function useDiscoveredWorkspaces() {
43
44
  })
44
45
  }
45
46
 
46
- export function useAddWorkspace() {
47
+ export function useImportWorkspace() {
47
48
  const queryClient = useQueryClient()
48
- return useMutation<WorkspaceEntry, Error, DiscoveredWorkspace>({
49
- mutationFn: discovered =>
50
- requestJson('/api/workspaces', jsonRequest('POST', discovered), 'Failed to add workspace'),
51
- onSuccess: (entry, suggestion) => {
49
+ return useMutation<WorkspaceEntry, Error, ImportWorkspaceInput>({
50
+ mutationFn: input =>
51
+ requestJson('/api/workspaces', jsonRequest('POST', input), 'Failed to add workspace'),
52
+ onSuccess: (entry, input) => {
52
53
  queryClient.setQueryData<WorkspaceEntry[]>(workspaceKeys.all, previous =>
53
54
  upsertWorkspaceEntry(previous, entry)
54
55
  )
55
56
  queryClient.setQueryData<DiscoveredWorkspace[]>(workspaceKeys.discover, previous =>
56
- (previous ?? []).filter(item => item.path !== suggestion.path)
57
+ (previous ?? []).filter(item => item.path !== input.path)
57
58
  )
58
59
  }
59
60
  })
60
61
  }
61
62
 
62
- export type CreateWorkspaceInfo = {
63
+ export type ImportWorkspaceInput = {
64
+ path: string
65
+ type: WorkspaceType
66
+ }
67
+
68
+ export type WorkspaceSetupInfo = {
63
69
  root: string
64
70
  displayRoot: string
65
71
  canChooseFolder: boolean
72
+ // Per-backend runtime availability (are the Claude/Codex CLIs installed?),
73
+ // keyed by workspace type. Missing entries mean available.
74
+ availability?: Partial<Record<WorkspaceType, HarnessAvailability>>
66
75
  }
67
76
 
68
- export function useCreateWorkspaceInfo() {
69
- return useQuery<CreateWorkspaceInfo>({
70
- queryKey: workspaceKeys.createInfo,
77
+ export function useWorkspaceSetupInfo() {
78
+ return useQuery<WorkspaceSetupInfo>({
79
+ queryKey: workspaceKeys.setupInfo,
80
+ // Availability can change while the app is open (the user installs the
81
+ // agent CLI) — refetch on mount instead of caching forever.
71
82
  queryFn: () => requestJson('/api/workspaces/create'),
72
- staleTime: Infinity
83
+ staleTime: 30_000,
84
+ refetchOnMount: 'always'
73
85
  })
74
86
  }
75
87
 
76
- export type ChooseFolderResult = { path: string } | { canceled: true }
88
+ export type ChooseFolderResult = DiscoveredWorkspace | { canceled: true }
77
89
 
78
90
  export function useChooseFolder() {
79
91
  return useMutation<ChooseFolderResult, Error, void>({