moi-computer 0.13.1-next.1 → 0.13.1-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/client/api/app-config.ts +12 -1
  2. package/client/api/http.ts +11 -1
  3. package/client/app/app-router.tsx +3 -2
  4. package/client/app/routes/home-route.tsx +1 -1
  5. package/client/app/routes/workspace-registration.tsx +68 -0
  6. package/client/app/routes/workspace-route.tsx +33 -6
  7. package/client/app/shell/sidebar-layout.tsx +10 -5
  8. package/client/components/shared/workspace-icon.tsx +8 -17
  9. package/client/features/account/account-test-utils.tsx +15 -9
  10. package/client/features/account/api.ts +6 -6
  11. package/client/features/account/profile-actions.ts +5 -7
  12. package/client/features/app-settings/settings-page.tsx +2 -1
  13. package/client/features/applets/api.ts +6 -6
  14. package/client/features/applets/applet-cache.ts +6 -5
  15. package/client/features/applets/applet-log.ts +2 -1
  16. package/client/features/applets/applet-runtime.ts +2 -1
  17. package/client/features/applets/use-applet.ts +73 -18
  18. package/client/features/applets/widget-shell.tsx +4 -2
  19. package/client/features/chat/applet-chat-intents.ts +5 -13
  20. package/client/features/chat/chat-popup.tsx +8 -4
  21. package/client/features/chat/chat-send.ts +2 -2
  22. package/client/features/chat/composer/model-order.ts +4 -4
  23. package/client/features/chat/composer/model-picker.tsx +12 -10
  24. package/client/features/chat/composer/use-workspace-composer-state.tsx +1 -1
  25. package/client/features/chat/sessions/api.ts +11 -28
  26. package/client/features/chat/sessions/use-selected-session.ts +18 -100
  27. package/client/features/chat/use-chat.ts +8 -12
  28. package/client/features/collab/members/api.ts +4 -10
  29. package/client/features/collab/members/hooks.ts +32 -38
  30. package/client/features/collab/members/store.ts +96 -71
  31. package/client/features/collab/members/types.ts +5 -3
  32. package/client/features/collab/presence/client.ts +2 -3
  33. package/client/features/collab/presence/hooks.tsx +1 -1
  34. package/client/features/collab/proxy-user.ts +1 -3
  35. package/client/features/collab/sharing/workspace-members.tsx +0 -8
  36. package/client/features/dev/chat-states-page.tsx +3 -1
  37. package/client/features/dev/harness-debug-page.tsx +7 -7
  38. package/client/features/dev/workspace-setup-mocks.ts +1 -1
  39. package/client/features/dev/workspace-setup-preview.tsx +6 -4
  40. package/client/features/harness/api.ts +13 -10
  41. package/client/features/harness/harness-login-panel.tsx +9 -5
  42. package/client/features/harness/harness-presentation.ts +4 -4
  43. package/client/features/harness/harness-selector.tsx +13 -13
  44. package/client/features/harness/use-harness-login.ts +5 -5
  45. package/client/features/home/api.ts +38 -2
  46. package/client/features/home/home-page.tsx +43 -13
  47. package/client/features/home/shared-workspaces.tsx +70 -0
  48. package/client/features/home/workspace-invitations.tsx +101 -0
  49. package/client/features/identity/host-api.ts +3 -2
  50. package/client/features/identity/store.ts +1 -7
  51. package/client/features/onboarding/agent-setup-step.tsx +8 -8
  52. package/client/features/onboarding/onboarding-page.tsx +3 -2
  53. package/client/features/onboarding/workspace-setup-step.tsx +1 -1
  54. package/client/features/overview/api.ts +3 -5
  55. package/client/features/overview/default/registry.tsx +1 -1
  56. package/client/features/overview/default/views-widget.tsx +2 -2
  57. package/client/features/overview/hidden-panel.tsx +7 -5
  58. package/client/features/overview/overview.tsx +18 -16
  59. package/client/features/overview/workspace-name.tsx +2 -2
  60. package/client/features/scratchpad/scratchpad.tsx +9 -7
  61. package/client/features/scratchpad/use-scratchpad-snapshot.tsx +13 -5
  62. package/client/features/views/api.ts +34 -16
  63. package/client/features/views/use-view-actions.ts +10 -20
  64. package/client/features/views/view-manager.tsx +1 -1
  65. package/client/features/views/view-submission.ts +2 -21
  66. package/client/features/workspace/add/api.ts +5 -4
  67. package/client/features/workspace/add/create-workspace-dialog.tsx +12 -9
  68. package/client/features/workspace/add/import-workspace-dialog.tsx +7 -7
  69. package/client/features/workspace/add/use-workspace-import.ts +10 -10
  70. package/client/features/workspace/add/workspace-agent-options.ts +21 -20
  71. package/client/features/workspace/add/workspace-agent-selector.tsx +11 -11
  72. package/client/features/workspace/api.ts +60 -13
  73. package/client/features/workspace/harness-transition.ts +7 -13
  74. package/client/features/workspace/remote.ts +25 -0
  75. package/client/features/workspace/settings/api.ts +7 -12
  76. package/client/features/workspace/settings/connectors-settings.tsx +3 -3
  77. package/client/features/workspace/settings/general-settings.tsx +8 -8
  78. package/client/features/workspace/setup/workspace-login-state.tsx +4 -4
  79. package/client/features/workspace/setup/workspace-recovery-states.tsx +43 -14
  80. package/client/features/workspace/setup/workspace-setup.tsx +6 -6
  81. package/client/features/workspace/tab-resolution.ts +2 -2
  82. package/client/features/workspace/use-workspace-navigation.ts +7 -4
  83. package/client/features/workspace/workspace-content.tsx +22 -20
  84. package/client/features/workspace/workspace-frame.tsx +13 -26
  85. package/client/features/workspace/workspace-layout-context.tsx +45 -12
  86. package/client/features/workspace/workspace-menu.tsx +2 -2
  87. package/client/features/workspace/workspace-pane.tsx +22 -0
  88. package/client/features/workspace/workspace-pending-screen.tsx +1 -1
  89. package/client/features/workspace/workspace-preferences.ts +34 -0
  90. package/client/features/workspace/workspace-presentation.tsx +12 -16
  91. package/client/features/workspace/workspace-screen.tsx +2 -2
  92. package/client/features/workspace/workspace-state.ts +2 -1
  93. package/client/features/workspace/workspace-tabs.tsx +1 -1
  94. package/client/features/workspace/workspace-test-utils.ts +23 -0
  95. package/client/runtime/use-workspace-events.ts +14 -0
  96. package/client/runtime/workspace-events.ts +9 -9
  97. package/client/store/ui.ts +29 -9
  98. package/dist/chunk-44khk4sp.js +2 -0
  99. package/dist/chunk-ba6mz56s.js +72 -0
  100. package/dist/chunk-ec5ennpv.js +1 -0
  101. package/dist/chunk-ectsnw81.js +2 -0
  102. package/dist/chunk-en7w5ypg.js +1 -0
  103. package/dist/chunk-f695wcx5.js +5 -0
  104. package/dist/chunk-kffcah9w.css +1 -0
  105. package/dist/{chunk-th91xfnp.js → chunk-n0fawy9x.js} +1 -1
  106. package/dist/chunk-pdt9hxfw.js +2 -0
  107. package/dist/chunk-rmd0ctfx.js +546 -0
  108. package/dist/chunk-zv22wv0g.js +1 -0
  109. package/dist/index.html +1 -1
  110. package/lib/harness-instructions.ts +4 -4
  111. package/lib/harness-types.ts +13 -0
  112. package/lib/types.ts +34 -49
  113. package/lib/workspace-config.ts +48 -0
  114. package/lib/workspace-layout.ts +2 -4
  115. package/package.json +4 -2
  116. package/server/README.md +29 -27
  117. package/server/api/harnesses.ts +5 -5
  118. package/server/api/index.ts +170 -68
  119. package/server/applets/index.ts +15 -9
  120. package/server/applets/views.ts +2 -17
  121. package/server/applets/widgets.ts +3 -2
  122. package/server/cli/commands/config.ts +8 -20
  123. package/server/cli/commands/hermes.ts +2 -2
  124. package/server/cli/commands/init.ts +96 -53
  125. package/server/cli/commands/openclaw.ts +2 -2
  126. package/server/cli/commands/refresh.ts +10 -1
  127. package/server/cli/commands/remote.ts +228 -0
  128. package/server/cli/commands/skill.ts +4 -4
  129. package/server/cli/commands/tabs.ts +5 -12
  130. package/server/cli/control.ts +35 -4
  131. package/server/cli/index.ts +10 -6
  132. package/server/cli/remote-command.ts +77 -0
  133. package/server/cli/remote-control.ts +70 -0
  134. package/server/cli/remote-operations.ts +244 -0
  135. package/server/collab/config.ts +3 -3
  136. package/server/collab/skill/index.ts +3 -3
  137. package/server/control.ts +38 -11
  138. package/server/harness/acp/session.ts +4 -4
  139. package/server/harness/auth.ts +26 -31
  140. package/server/harness/claude-code/index.ts +1 -1
  141. package/server/harness/codex/discovery.ts +1 -1
  142. package/server/harness/codex/session.ts +1 -1
  143. package/server/harness/detect.ts +14 -19
  144. package/server/harness/executable.ts +10 -10
  145. package/server/harness/hermes/NOTES.md +2 -2
  146. package/server/harness/hermes/index.ts +1 -1
  147. package/server/harness/install.ts +11 -11
  148. package/server/harness/openclaw/index.ts +1 -1
  149. package/server/harness/registry.ts +7 -6
  150. package/server/harness/types.ts +4 -4
  151. package/server/onboarding/jobs.ts +1 -1
  152. package/server/operations/commands.ts +46 -0
  153. package/server/operations/files.ts +148 -0
  154. package/server/operations/server.ts +206 -0
  155. package/server/remote/agent.ts +103 -0
  156. package/server/remote/client.ts +665 -0
  157. package/server/remote/workspace.ts +34 -0
  158. package/server/scratchpad/document.ts +32 -12
  159. package/server/scratchpad/executor.ts +16 -7
  160. package/server/sessions/config.ts +8 -5
  161. package/server/sessions/pending-views.ts +16 -0
  162. package/server/sessions/view-sessions.ts +10 -12
  163. package/server/skills/locations.ts +4 -4
  164. package/server/skills/update.ts +11 -11
  165. package/server/skills/version.ts +7 -7
  166. package/server/skills/workspace.ts +13 -11
  167. package/server/web.ts +11 -8
  168. package/server/workspace-state/file.ts +2 -0
  169. package/server/workspace-state/index.ts +0 -4
  170. package/server/workspaces/api.ts +28 -0
  171. package/server/workspaces/change-harness.ts +15 -26
  172. package/server/workspaces/import.ts +4 -4
  173. package/server/workspaces/init.ts +15 -13
  174. package/server/workspaces/layout.ts +60 -66
  175. package/server/workspaces/registry.ts +43 -18
  176. package/server/workspaces/shared.ts +74 -0
  177. package/server/workspaces/tabs.ts +6 -12
  178. package/skill/SKILL.md +24 -4
  179. package/client/api/app-ui-keys.ts +0 -6
  180. package/client/features/chat/sessions/browser-tab-state.ts +0 -43
  181. package/client/features/collab/members/keys.ts +0 -6
  182. package/client/features/workspace/browser-tab-state.ts +0 -51
  183. package/client/features/workspace/layout-save.ts +0 -13
  184. package/dist/chunk-3smkkcfw.js +0 -546
  185. package/dist/chunk-47h9c2qy.js +0 -2
  186. package/dist/chunk-8qed2gqp.js +0 -75
  187. package/dist/chunk-8zy3vesm.js +0 -1
  188. package/dist/chunk-a47zy276.js +0 -2
  189. package/dist/chunk-g4c1nte9.css +0 -1
  190. package/dist/chunk-kcactdr4.js +0 -2
  191. package/dist/chunk-m8bhx6tw.js +0 -1
  192. package/dist/chunk-pf19zcrn.js +0 -2
  193. package/dist/chunk-ygzxah0e.js +0 -1
  194. package/lib/workspace-types.ts +0 -13
  195. package/server/workspace-state/legacy-migration.ts +0 -79
@@ -1,6 +1,10 @@
1
+ import { isRemoteWorkspace } from '@/client/features/workspace/remote'
1
2
  import type { ComponentType } from 'react'
2
3
  import { useRouter } from 'wouter'
3
- import { useCallback, useEffect, useState } from 'react'
4
+ import { useCallback, useEffect, useRef, useState } from 'react'
5
+ import { useQueryClient } from '@tanstack/react-query'
6
+
7
+ import { workspaceKeys } from '@/client/api/workspace-keys'
4
8
 
5
9
  import {
6
10
  type AppletSegment,
@@ -14,7 +18,7 @@ import {
14
18
  import { attachAppletBridge } from '@/client/features/applets/applet-runtime'
15
19
  import { reportAppletError } from '@/client/features/applets/applet-log'
16
20
  import { useWorkspaceId } from '@/client/features/workspace/workspace-context'
17
- import { type WorkspaceEvent, useWorkspaceEvent } from '@/client/runtime/use-workspace-events'
21
+ import { type WorkspaceEvent, useWorkspaceScopedEvent } from '@/client/runtime/use-workspace-events'
18
22
  import type { AppletKind } from '@/lib/types'
19
23
 
20
24
  // Views receive URL query params. Widgets mount without params; applets must
@@ -83,18 +87,29 @@ function loadApplet(
83
87
  return promise
84
88
  }
85
89
 
86
- function useApplet(kind: AppletKindSpec, name: string): AppletState {
90
+ function useApplet(kind: AppletKindSpec, name: string, revision?: string): AppletState {
87
91
  const workspaceId = useWorkspaceId()
88
92
  const { base } = useRouter()
89
- const [state, setState] = useState<AppletState>({ status: 'loading', version: 0 })
93
+ const key = appletKey(kind.segment, workspaceId, name)
94
+ const generation = useRef(0)
95
+ const [loaded, setLoaded] = useState<{ key: string; state: AppletState }>({
96
+ key,
97
+ state: { status: 'loading', version: 0 }
98
+ })
99
+ const state: AppletState = loaded.key === key ? loaded.state : { status: 'loading', version: 0 }
90
100
 
91
101
  const load = useCallback(() => {
92
- setState(prev => ({ status: 'loading', version: prev.version }))
102
+ const request = ++generation.current
93
103
  loadApplet(kind, workspaceId, name, base)
94
- .then(Component =>
95
- setState(prev => ({ status: 'ready', Component, version: prev.version + 1 }))
96
- )
104
+ .then(Component => {
105
+ if (request !== generation.current) return
106
+ setLoaded(prev => ({
107
+ key,
108
+ state: { status: 'ready', Component, version: prev.state.version + 1 }
109
+ }))
110
+ })
97
111
  .catch(err => {
112
+ if (request !== generation.current) return
98
113
  // Journal the load failure so `moi debug logs` can surface it to the
99
114
  // agent — otherwise only this tab ever sees it (docs/self-correction.md).
100
115
  reportAppletError(workspaceId, {
@@ -104,12 +119,22 @@ function useApplet(kind: AppletKindSpec, name: string): AppletState {
104
119
  message: String(err),
105
120
  ...(err instanceof Error && err.stack ? { stack: err.stack } : {})
106
121
  })
107
- setState(prev => ({ status: 'error', error: String(err), version: prev.version + 1 }))
122
+ setLoaded(prev =>
123
+ prev.key === key && prev.state.status === 'ready'
124
+ ? prev
125
+ : {
126
+ key,
127
+ state: { status: 'error', error: String(err), version: prev.state.version + 1 }
128
+ }
129
+ )
108
130
  })
109
- }, [base, kind, workspaceId, name])
131
+ }, [base, kind, workspaceId, name, key])
110
132
 
111
133
  useEffect(() => {
112
134
  load()
135
+ return () => {
136
+ generation.current++
137
+ }
113
138
  }, [load])
114
139
 
115
140
  // Reload the MOUNTED applet the moment the server says its bundle changed or
@@ -118,22 +143,36 @@ function useApplet(kind: AppletKindSpec, name: string): AppletState {
118
143
  // unmounted case, but doing it here keeps this self-sufficient and
119
144
  // order-independent. The bumped version remounts the component and re-runs its
120
145
  // `rpc()` calls.
121
- useWorkspaceEvent(event => {
146
+ useWorkspaceScopedEvent(workspaceId, event => {
122
147
  if (kind.shouldReload(event, name)) {
123
148
  invalidateApplet(kind.segment, workspaceId, name)
124
149
  load()
125
150
  }
126
151
  })
127
152
 
153
+ // Owner events don't reach visitors yet. The applet lists refetch on window
154
+ // focus and carry each bundle's revision, so a remote applet reloads only when
155
+ // its build changed: a reload remounts it and keeps the old module in memory.
156
+ const remote = isRemoteWorkspace(workspaceId)
157
+ const seen = useRef({ key, revision })
158
+ useEffect(() => {
159
+ const previous = seen.current
160
+ seen.current = { key, revision }
161
+ if (!remote || previous.key !== key || previous.revision === revision) return
162
+ if (previous.revision === undefined || revision === undefined) return
163
+ invalidateApplet(kind.segment, workspaceId, name)
164
+ load()
165
+ }, [remote, key, revision, kind.segment, workspaceId, name, load])
128
166
  return state
129
167
  }
130
168
 
131
- export function useWidget(name: string): AppletState {
132
- return useApplet(WIDGET_KIND, name)
169
+ // `revision` is the bundle revision from the widgets/views list.
170
+ export function useWidget(name: string, revision?: string): AppletState {
171
+ return useApplet(WIDGET_KIND, name, revision)
133
172
  }
134
173
 
135
- export function useView(name: string): AppletState {
136
- return useApplet(VIEW_KIND, name)
174
+ export function useView(name: string, revision?: string): AppletState {
175
+ return useApplet(VIEW_KIND, name, revision)
137
176
  }
138
177
 
139
178
  // Mount once per workspace (in the workspace route). Invalidates the shared
@@ -143,15 +182,31 @@ export function useView(name: string): AppletState {
143
182
  // fires while that applet is on screen; this covers the (common) rest.
144
183
  export function useAppletCacheInvalidation(): void {
145
184
  const workspaceId = useWorkspaceId()
146
- useWorkspaceEvent(event => {
185
+ const queryClient = useQueryClient()
186
+ useWorkspaceScopedEvent(workspaceId, event => {
187
+ // Owner build events don't reach visitors. `moi refresh` from the visitor's
188
+ // agent does, so it also re-reads the owner's lists for new or removed applets.
189
+ if (
190
+ isRemoteWorkspace(workspaceId, queryClient) &&
191
+ (event.type === 'applets:refresh' ||
192
+ event.type === 'view:updated' ||
193
+ event.type === 'widget:updated')
194
+ ) {
195
+ void queryClient.invalidateQueries({
196
+ queryKey: workspaceKeys.views(workspaceId)
197
+ })
198
+ void queryClient.invalidateQueries({
199
+ queryKey: workspaceKeys.widgets(workspaceId)
200
+ })
201
+ }
147
202
  if (event.type === 'view:updated') invalidateApplet('views', workspaceId, event.name)
148
203
  else if (event.type === 'widget:updated') invalidateApplet('widgets', workspaceId, event.name)
149
204
  else if (event.type === 'applets:refresh') {
150
205
  // Segment-wide: `moi refresh` names no applet, so every cached module in
151
206
  // the targeted kind(s) is stale — including ones whose tabs are
152
207
  // backgrounded right now.
153
- if (event.only !== 'views') invalidateAppletSegment('widgets')
154
- if (event.only !== 'widgets') invalidateAppletSegment('views')
208
+ if (event.only !== 'views') invalidateAppletSegment('widgets', event.workspaceId)
209
+ if (event.only !== 'widgets') invalidateAppletSegment('views', event.workspaceId)
155
210
  }
156
211
  })
157
212
  }
@@ -8,11 +8,13 @@ import { WidgetErrorBoundary } from './widget-error-boundary'
8
8
 
9
9
  type WidgetShellProps = {
10
10
  name: string
11
+ // Bundle revision from the widgets list.
12
+ revision?: string
11
13
  }
12
14
 
13
- export function WidgetShell({ name }: WidgetShellProps) {
15
+ export function WidgetShell({ name, revision }: WidgetShellProps) {
14
16
  const workspaceId = useWorkspaceId()
15
- const widget = useWidget(name)
17
+ const widget = useWidget(name, revision)
16
18
 
17
19
  return (
18
20
  <AnimatePresence mode="wait" initial={false}>
@@ -14,9 +14,8 @@ import { useLayoutEffect } from 'react'
14
14
  import { useQueryClient, type QueryClient } from '@tanstack/react-query'
15
15
  import { toast } from '@/client/components/ui/toast'
16
16
  import { cachedSelectedSession } from '@/client/features/chat/sessions/use-selected-session'
17
- import { useAppConfig } from '@/client/api/app-config'
18
17
  import { useLatestRef } from '@/client/lib/use-latest-ref'
19
- import type { SelectedSessionScope, WorkspaceTabId } from '@/lib/types'
18
+ import type { WorkspaceTabId } from '@/lib/types'
20
19
  import { useCurrentTabId } from './sessions/use-selected-session'
21
20
  import { useWorkspaceId } from '@/client/features/workspace/workspace-context'
22
21
  import type { AgentAvailability } from '@/client/lib/agent-availability'
@@ -54,13 +53,12 @@ export function appletSendBlockedReason(availability: AgentAvailability): string
54
53
  export function createAppletMessageHandler(
55
54
  workspaceId: string,
56
55
  queryClient: QueryClient,
57
- getOptions: () => UseAppletChatMessageOptions,
58
- scope: SelectedSessionScope = 'shared'
56
+ getOptions: () => UseAppletChatMessageOptions
59
57
  ) {
60
58
  const pending = new Set<() => void>()
61
59
  let disposed = false
62
60
  const selectedSession = () =>
63
- cachedSelectedSession(queryClient, workspaceId, getOptions().tabId, scope) ?? null
61
+ cachedSelectedSession(queryClient, workspaceId, getOptions().tabId) ?? null
64
62
 
65
63
  async function handle(event: AppletChatMessage): Promise<void> {
66
64
  if (disposed) return
@@ -153,15 +151,9 @@ export function useAppletChatMessage(options: Omit<UseAppletChatMessageOptions,
153
151
  const workspaceId = useWorkspaceId()
154
152
  const queryClient = useQueryClient()
155
153
  const tabId = useCurrentTabId()
156
- const cloud = useAppConfig().environment === 'cloud'
157
154
  const latest = useLatestRef({ ...options, tabId })
158
155
  useLayoutEffect(() => {
159
- const handler = createAppletMessageHandler(
160
- workspaceId,
161
- queryClient,
162
- () => latest.current,
163
- cloud ? 'browser-tab' : 'shared'
164
- )
156
+ const handler = createAppletMessageHandler(workspaceId, queryClient, () => latest.current)
165
157
  const unsubscribe = appletRuntime(workspaceId).on('sendChatMessage', event => {
166
158
  void handler.handle(event)
167
159
  })
@@ -169,7 +161,7 @@ export function useAppletChatMessage(options: Omit<UseAppletChatMessageOptions,
169
161
  unsubscribe()
170
162
  handler.dispose()
171
163
  }
172
- }, [workspaceId, queryClient, latest, tabId, cloud])
164
+ }, [workspaceId, queryClient, latest, tabId])
173
165
  }
174
166
 
175
167
  export function useAppletChatAttachment(sessionId: string | null, revealChat: () => void): void {
@@ -7,7 +7,7 @@ import { Resizable } from 'react-resizable'
7
7
  import { AgentBlobatar } from '@/client/components/shared/agent-blobatar'
8
8
  import { Popover, PopoverContent, PopoverTrigger } from '@/client/components/ui/popover'
9
9
  import { cn } from '@/client/lib/cn'
10
- import { useUiStore } from '@/client/store/ui'
10
+ import { useWorkspaceUi } from '@/client/features/workspace/workspace-preferences'
11
11
  import type { AgentTheme } from '@/lib/types'
12
12
 
13
13
  type ChatPopupProps = {
@@ -28,8 +28,9 @@ export function ChatPopup({
28
28
  children
29
29
  }: ChatPopupProps) {
30
30
  const popupRef = useRef<HTMLDivElement>(null)
31
- const popupChatWidth = useUiStore(state => state.popupChatWidth)
32
- const setPopupChatWidth = useUiStore(state => state.setPopupChatWidth)
31
+ const [layout, setLayout] = useWorkspaceUi()
32
+ const popupChatWidth = layout.popupChatWidth
33
+ const setPopupChatWidth = (popupChatWidth: number) => setLayout({ popupChatWidth })
33
34
  const [size, setSize] = useState({ width: popupChatWidth, min: 0, max: popupChatWidth })
34
35
 
35
36
  const setPopupRef = useCallback(
@@ -130,7 +131,10 @@ export function ChatPopup({
130
131
  resizeHandles={['w']}
131
132
  minConstraints={[size.min, 0]}
132
133
  maxConstraints={[size.max, 0]}
133
- onResize={(_event, { size }) => setPopupChatWidth(Math.round(size.width))}
134
+ onResize={(_event, { size }) =>
135
+ popupRef.current?.style.setProperty('--chat-popup-width', `${Math.round(size.width)}px`)
136
+ }
137
+ onResizeStop={(_event, { size }) => setPopupChatWidth(Math.round(size.width))}
134
138
  handle={
135
139
  <div
136
140
  role="separator"
@@ -206,14 +206,14 @@ export function resolveChatRunOptions(
206
206
  ? pickedModel
207
207
  : undefined
208
208
  const modelInfo =
209
- modelsData?.provider === 'codex'
209
+ modelsData?.harness === 'codex'
210
210
  ? resolveSelectedModel(modelsData.models, pickedModel)
211
211
  : models?.find(candidate => candidate.value === (savedModel ?? 'default'))
212
212
  // Omitting Codex's model inherits config.toml (or the resumed thread's
213
213
  // model), which can be unavailable even though the picker shows a supported
214
214
  // fallback. Always send the concrete model the Codex picker displays.
215
215
  const model =
216
- modelsData?.provider === 'codex' && modelInfo
216
+ modelsData?.harness === 'codex' && modelInfo
217
217
  ? (modelInfo.resolvedModel ?? modelInfo.value)
218
218
  : savedModel
219
219
  const effort =
@@ -1,4 +1,4 @@
1
- import type { SpeedMode, Model, WorkspaceType } from '@/lib/types'
1
+ import type { SpeedMode, Model, HarnessType } from '@/lib/types'
2
2
 
3
3
  export const DEFAULT_EFFORT = 'high'
4
4
 
@@ -41,7 +41,7 @@ function compareAnthropicModels(a: Model, b: Model): number {
41
41
  return compareOptionalRanks(anthropicModelFamilyRank(a), anthropicModelFamilyRank(b))
42
42
  }
43
43
 
44
- const PROVIDER_MODEL_COMPARATORS: Partial<Record<WorkspaceType, ModelComparator>> = {
44
+ const HARNESS_MODEL_COMPARATORS: Partial<Record<HarnessType, ModelComparator>> = {
45
45
  'claude-code': compareAnthropicModels
46
46
  }
47
47
 
@@ -88,8 +88,8 @@ export function resolveSpeedMode(
88
88
  return mode !== 'normal' && model.supportsFastMode ? 'fast' : 'normal'
89
89
  }
90
90
 
91
- export function sortModelsByProviderOrder(models: Model[], provider: WorkspaceType): Model[] {
92
- const compare = PROVIDER_MODEL_COMPARATORS[provider]
91
+ export function sortModelsByHarnessOrder(models: Model[], harness: HarnessType): Model[] {
92
+ const compare = HARNESS_MODEL_COMPARATORS[harness]
93
93
  return compare ? stableSortModels(models, compare) : models
94
94
  }
95
95
 
@@ -1,3 +1,4 @@
1
+ import { useWorkspaceState } from '@/client/features/workspace/workspace-state'
1
2
  import { type ComponentProps, type ReactNode, memo, useState } from 'react'
2
3
 
3
4
  import { AnimatePresence, motion } from 'motion/react'
@@ -14,7 +15,7 @@ import {
14
15
  resolveEffortIndex,
15
16
  resolveSpeedMode,
16
17
  resolveSelectedModel,
17
- sortModelsByProviderOrder
18
+ sortModelsByHarnessOrder
18
19
  } from './model-order'
19
20
  import { Button } from '@/client/components/ui/button'
20
21
  import {
@@ -329,7 +330,8 @@ type ModelPickerProps = {
329
330
  // A session id targets that chat's stored config. Null targets the workspace
330
331
  // defaults that seed new chats such as the pending view.
331
332
  export const ModelPicker = memo(function ModelPicker({ sessionId }: ModelPickerProps) {
332
- const { workspaceId, layout, setLayout } = useWorkspaceLayoutCtx()
333
+ const { workspaceId } = useWorkspaceLayoutCtx()
334
+ const defaults = useWorkspaceState(workspaceId).data?.chatDefaults
333
335
  const { data } = useWorkspaceHarness(workspaceId)
334
336
 
335
337
  // The SDK prepends a synthetic "default" entry ("Use the default model
@@ -337,33 +339,33 @@ export const ModelPicker = memo(function ModelPicker({ sessionId }: ModelPickerP
337
339
  const allModels = data?.models ?? []
338
340
  const defaultEntry = allModels.find(model => model.value === 'default')
339
341
  const models = data
340
- ? sortModelsByProviderOrder(
342
+ ? sortModelsByHarnessOrder(
341
343
  allModels.filter(model => model.value !== 'default'),
342
- data.provider
344
+ data.harness
343
345
  )
344
346
  : []
345
347
 
346
348
  const sessionConfig = useSessionState(workspaceId, sessionId).data?.config
347
349
  const saveSessionConfig = useSaveSessionConfig(workspaceId)
348
350
 
349
- const selectedModel = (sessionId ? sessionConfig?.model : undefined) ?? layout.selectedModel
350
- const selectedEffort = (sessionId ? sessionConfig?.effort : undefined) ?? layout.selectedEffort
351
+ const selectedModel = (sessionId ? sessionConfig?.model : undefined) ?? defaults?.model
352
+ const selectedEffort = (sessionId ? sessionConfig?.effort : undefined) ?? defaults?.effort
351
353
  const selectedSpeedMode =
352
- (sessionId ? sessionConfig?.speedMode : undefined) ?? layout.selectedSpeedMode
354
+ (sessionId ? sessionConfig?.speedMode : undefined) ?? defaults?.speedMode
353
355
 
354
356
  const setSelectedModel = (value: string) => {
355
357
  if (sessionId) saveSessionConfig.mutate({ sessionId, patch: { model: value } })
356
- else setLayout({ selectedModel: value })
358
+ else saveSessionConfig.mutate({ patch: { model: value } })
357
359
  }
358
360
 
359
361
  const setSelectedEffort = (value: string) => {
360
362
  if (sessionId) saveSessionConfig.mutate({ sessionId, patch: { effort: value } })
361
- else setLayout({ selectedEffort: value })
363
+ else saveSessionConfig.mutate({ patch: { effort: value } })
362
364
  }
363
365
 
364
366
  const setSelectedSpeedMode = (value: SpeedMode) => {
365
367
  if (sessionId) saveSessionConfig.mutate({ sessionId, patch: { speedMode: value } })
366
- else setLayout({ selectedSpeedMode: value })
368
+ else saveSessionConfig.mutate({ patch: { speedMode: value } })
367
369
  }
368
370
 
369
371
  const model = resolveSelectedModel(models, selectedModel, defaultEntry?.resolvedModel)
@@ -27,7 +27,7 @@ export function useWorkspaceComposerState(
27
27
  const workspace = useWorkspaceHarness(workspaceId)
28
28
  const harness = workspace.data
29
29
  const status = useHarnessStatus(
30
- harness?.hasAuthOverrides || harness?.isFolderMissing ? undefined : harness?.provider
30
+ harness?.hasAuthOverrides || harness?.isFolderMissing ? undefined : harness?.harness
31
31
  )
32
32
  const readiness = status.isEnabled ? status : workspace
33
33
  const error = readiness.error ?? workspace.error
@@ -5,14 +5,7 @@ import { useCallback, useMemo } from 'react'
5
5
  import { jsonRequest, requestJson } from '@/client/api/http'
6
6
  import { workspaceKeys } from '@/client/api/workspace-keys'
7
7
  import { sessionViewOptions } from '@/client/features/chat/sessions/session-view'
8
- import { readSelectedSession, writeSelectedSession } from './browser-tab-state'
9
- import {
10
- browserTabSelectionKey,
11
- browserTabSelectionOptions,
12
- usePinnedSession,
13
- useSelectedSession
14
- } from './use-selected-session'
15
- import { useAppConfig } from '@/client/api/app-config'
8
+ import { usePinnedSession, useSelectedSession } from './use-selected-session'
16
9
  import { useLatestRef } from '@/client/lib/use-latest-ref'
17
10
  import { useWorkspaceId } from '@/client/features/workspace/workspace-context'
18
11
  import {
@@ -30,7 +23,6 @@ import type {
30
23
  WorkspaceState,
31
24
  WorkspaceTabId
32
25
  } from '@/lib/types'
33
- import type { BrowserTabSelection } from './browser-tab-state'
34
26
 
35
27
  // The agent's chat list. Reading it makes the harness scan transcripts, so
36
28
  // mounts within 30 s reuse it; harness `sessions_changed` frames refetch it,
@@ -70,10 +62,9 @@ export function useWorkspaceSessions(workspaceId: string): { data: SessionInfo[]
70
62
  export function useSelectLinkedChat() {
71
63
  const workspaceId = useWorkspaceId()
72
64
  const queryClient = useQueryClient()
73
- const cloud = useAppConfig().environment === 'cloud'
74
65
  const [, , selectSessionForTab] = useSelectedSession()
75
66
  const { unpinAsync } = usePinnedSession()
76
- const stateRef = useLatestRef({ cloud, selectSessionForTab, unpinAsync })
67
+ const stateRef = useLatestRef({ selectSessionForTab, unpinAsync })
77
68
  // Stable so selection updates do not restart a pending chat link.
78
69
  return useCallback(
79
70
  async (
@@ -81,7 +72,7 @@ export function useSelectLinkedChat() {
81
72
  tab: WorkspaceTabId,
82
73
  signal: AbortSignal
83
74
  ): Promise<WorkspaceTabId | undefined> => {
84
- const { cloud, selectSessionForTab, unpinAsync } = stateRef.current
75
+ const { selectSessionForTab, unpinAsync } = stateRef.current
85
76
  signal.throwIfAborted()
86
77
  let sessions =
87
78
  queryClient.getQueryData<SessionSummary[]>(workspaceKeys.sessions(workspaceId)) ?? []
@@ -96,7 +87,6 @@ export function useSelectLinkedChat() {
96
87
  const state = await queryClient.ensureQueryData(
97
88
  workspaceStateOptions(queryClient, workspaceId)
98
89
  )
99
- if (cloud) await queryClient.ensureQueryData(browserTabSelectionOptions(workspaceId))
100
90
  signal.throwIfAborted()
101
91
  const pinned = state.pinnedSessionId
102
92
  const destination =
@@ -138,16 +128,6 @@ export function applyArchivedSession(
138
128
  changeWorkspaceStateCache(queryClient, workspaceId, draft =>
139
129
  clearSessionInState(draft, sessionId)
140
130
  )
141
- const localKey = browserTabSelectionKey(workspaceId)
142
- const local =
143
- queryClient.getQueryData<BrowserTabSelection>(localKey) ?? readSelectedSession(workspaceId)
144
- if (!Object.values(local.selected).includes(sessionId)) return
145
- // An explicit empty local choice prevents falling back to the server's chat.
146
- const selected = Object.fromEntries(
147
- Object.entries(local.selected).map(([tabId, id]) => [tabId, id === sessionId ? null : id])
148
- )
149
- queryClient.setQueryData<BrowserTabSelection>(localKey, { selected })
150
- writeSelectedSession(workspaceId, { selected })
151
131
  }
152
132
 
153
133
  export function useArchiveWorkspaceSession(workspaceId: string) {
@@ -188,22 +168,25 @@ export function useSessionState(workspaceId: string, sessionId: string | null) {
188
168
  export type SessionConfigPatch = { [Key in keyof SessionConfig]?: SessionConfig[Key] | null }
189
169
 
190
170
  export function useSaveSessionConfig(workspaceId: string) {
191
- return useWorkspaceStateWrite<{ sessionId: string; patch: SessionConfigPatch }>(workspaceId, {
171
+ return useWorkspaceStateWrite<{ sessionId?: string; patch: SessionConfigPatch }>(workspaceId, {
192
172
  request: ({ sessionId, patch }) =>
193
173
  requestJson<WorkspaceState>(
194
- `/api/workspaces/${workspaceId}/sessions/${encodeURIComponent(sessionId)}/config`,
174
+ sessionId
175
+ ? `/api/workspaces/${workspaceId}/sessions/${encodeURIComponent(sessionId)}/config`
176
+ : `/api/workspaces/${workspaceId}/state/chat-defaults`,
195
177
  jsonRequest('PATCH', patch),
196
178
  'Failed to save chat settings'
197
179
  ),
198
180
  optimistic: (draft, { sessionId, patch }) => {
199
- const session = (draft.sessions[sessionId] ??= {})
200
- const config: SessionConfig = { ...session.config }
181
+ const session = sessionId ? (draft.sessions[sessionId] ??= {}) : undefined
182
+ const config: SessionConfig = { ...(session ? session.config : draft.chatDefaults) }
201
183
  for (const key of ['model', 'effort', 'speedMode'] as const) {
202
184
  const value = patch[key]
203
185
  if (value === null) delete config[key]
204
186
  else if (value !== undefined) Object.assign(config, { [key]: value })
205
187
  }
206
- session.config = config
188
+ if (session) session.config = config
189
+ else draft.chatDefaults = config
207
190
  },
208
191
  errorTitle: 'Couldn’t save chat settings'
209
192
  })