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,5 +1,4 @@
1
- import { loadLayout, saveLayout } from './layout'
2
- import type { WorkspaceEntry, WorkspaceType } from '@/lib/types'
1
+ import type { WorkspaceEntry, HarnessType } from '@/lib/types'
3
2
  import { harnessFor } from '../harness/registry'
4
3
  import { harnessStore } from '../harness/auth'
5
4
  import { getWorkspaceSkillsStatus } from '../skills/update'
@@ -12,13 +11,13 @@ import { installWorkspaceSkills } from '../skills/workspace'
12
11
  // Keep successful preparation for this server lifetime; failed attempts can retry.
13
12
  const preparation = new Map<string, Promise<void>>()
14
13
  export function prepareWorkspaceHarness(ws: WorkspaceEntry): Promise<void> {
15
- const key = `${ws.path}:${ws.type ?? 'claude-code'}`
14
+ const key = `${ws.path}:${ws.harness ?? 'claude-code'}`
16
15
  let pending = preparation.get(key)
17
16
  if (!pending) {
18
- pending = getWorkspaceSkillsStatus(ws.path, ws.type)
17
+ pending = getWorkspaceSkillsStatus(ws.path, ws.harness)
19
18
  .then(async status => {
20
19
  if (status.skills.some(skill => !skill.installed))
21
- await installWorkspaceSkills(ws.path, ws.type)
20
+ await installWorkspaceSkills(ws.path, ws.harness)
22
21
  })
23
22
  .catch(error => {
24
23
  preparation.delete(key)
@@ -29,23 +28,23 @@ export function prepareWorkspaceHarness(ws: WorkspaceEntry): Promise<void> {
29
28
  return pending
30
29
  }
31
30
 
32
- export async function changeWorkspaceHarness(ws: WorkspaceEntry, type: WorkspaceType) {
31
+ export async function changeWorkspaceHarness(ws: WorkspaceEntry, next: HarnessType) {
33
32
  return withHarnessTransition(ws, async () => {
34
33
  const current = await getWorkspace(ws.id)
35
34
  if (!current) throw new HarnessTransitionError('Workspace not found')
36
- const previousType = current.type ?? 'claude-code'
35
+ const previousHarness = current.harness ?? 'claude-code'
37
36
  const harness = harnessFor(current)
38
37
  if (
39
- !['claude-code', 'codex'].includes(previousType) ||
40
- !['claude-code', 'codex'].includes(type)
38
+ !['claude-code', 'codex'].includes(previousHarness) ||
39
+ !['claude-code', 'codex'].includes(next)
41
40
  )
42
41
  throw new HarnessTransitionError('This workspace’s agent cannot be changed')
43
- if (type === previousType) return current
42
+ if (next === previousHarness) return current
44
43
  if (harness.activeSessions().some(session => session.workspaceId === ws.id))
45
44
  throw new HarnessTransitionError('Wait for the agent to finish before changing it')
46
- const layoutBefore = await loadLayout(current.path)
47
45
  const before = await updateWorkspaceState(current, state => {
48
46
  const before = structuredClone(state)
47
+ state.chatDefaults = {}
49
48
  state.selected = {}
50
49
  delete state.pinnedSessionId
51
50
  for (const view of Object.values(state.pendingViews)) {
@@ -57,21 +56,11 @@ export async function changeWorkspaceHarness(ws: WorkspaceEntry, type: Workspace
57
56
  })
58
57
  let updated: WorkspaceEntry
59
58
  try {
60
- const layout = { ...layoutBefore }
61
- delete layout.selectedModel
62
- delete layout.selectedEffort
63
- delete layout.selectedSpeedMode
64
- await saveLayout(layout, current.path)
65
- updated = await updateWorkspaceHarness(ws.id, type)
59
+ updated = await updateWorkspaceHarness(ws.id, next)
66
60
  } catch (error) {
67
- const recovery = await Promise.allSettled([
68
- saveLayout(layoutBefore, current.path),
69
- updateWorkspaceState(current, state => Object.assign(state, before))
70
- ])
71
- for (const result of recovery) {
72
- if (result.status === 'rejected')
73
- console.error('Could not restore workspace state', result.reason)
74
- }
61
+ await updateWorkspaceState(current, state => Object.assign(state, before)).catch(error => {
62
+ console.error('Could not restore workspace state', error)
63
+ })
75
64
  throw error
76
65
  }
77
66
  // Capture and dispose the old runtime before allowing another transition.
@@ -82,7 +71,7 @@ export async function changeWorkspaceHarness(ws: WorkspaceEntry, type: Workspace
82
71
  console.error('Could not stop previous workspace runtime', error)
83
72
  }
84
73
  harnessStore.invalidate(current)
85
- publishEvent({ type: 'workspace-harness:switched', workspaceId: ws.id, harness: type })
74
+ publishEvent({ type: 'workspace-harness:switched', workspaceId: ws.id, harness: next })
86
75
  return updated
87
76
  })
88
77
  }
@@ -1,6 +1,6 @@
1
1
  import { resolve } from 'node:path'
2
2
 
3
- import type { WorkspaceType } from '@/lib/types'
3
+ import type { HarnessType } from '@/lib/types'
4
4
 
5
5
  import { discoverHermesProfiles } from '../harness/hermes/discovery'
6
6
  import type { HermesProfile } from '../harness/hermes/discovery'
@@ -49,12 +49,12 @@ async function resolveHermesImportMetadata(
49
49
 
50
50
  export async function resolveWorkspaceImportMetadata(
51
51
  path: string,
52
- type: WorkspaceType,
52
+ harness: HarnessType,
53
53
  discoverAgents: DiscoverOpenClawAgents = discoverOpenClawAgents,
54
54
  discoverProfiles: DiscoverHermesProfiles = discoverHermesProfiles
55
55
  ): Promise<WorkspaceImportMetadata> {
56
- if (type === 'hermes') return resolveHermesImportMetadata(path, discoverProfiles)
57
- if (type !== 'openclaw') return {}
56
+ if (harness === 'hermes') return resolveHermesImportMetadata(path, discoverProfiles)
57
+ if (harness !== 'openclaw') return {}
58
58
 
59
59
  const normalizedPath = resolve(path)
60
60
  const agent = (await discoverAgents())
@@ -1,3 +1,4 @@
1
+ import { loadWorkspaceFileConfig } from './layout'
1
2
  // The one place that knows how to turn a directory into a Moi workspace:
2
3
  // bundled skills + the `.moi/` scaffold, with the skills location keyed on the
3
4
  // agent backend. `moi init`, `moi openclaw init`, and the HTTP API (UI import /
@@ -6,7 +7,7 @@
6
7
  import { mkdir } from 'node:fs/promises'
7
8
  import { join } from 'node:path'
8
9
 
9
- import type { WorkspaceType } from '@/lib/types'
10
+ import type { HarnessType } from '@/lib/types'
10
11
  import { workspaceIdFromName } from '@/lib/workspace-name'
11
12
  import { validateWorkspaceId } from '@/lib/ids'
12
13
  import { getWorkspace } from './registry'
@@ -40,20 +41,18 @@ export async function createWorkspaceDirectory(
40
41
  // (Claude Code: `.claude/skills/`; OpenClaw: `<workspace>/skills/`; Codex:
41
42
  // `.agents/skills/` per the Agent Skills standard). An untyped entry is
42
43
  // Claude Code.
43
- export function skillsDirFor(workspaceRoot: string, type?: WorkspaceType): string {
44
- return harnessFor(type).skillsDir?.(workspaceRoot) ?? join(workspaceRoot, '.claude', 'skills')
44
+ export function skillsDirFor(workspaceRoot: string, harness?: HarnessType): string {
45
+ return harnessFor(harness).skillsDir?.(workspaceRoot) ?? join(workspaceRoot, '.claude', 'skills')
45
46
  }
46
47
 
47
48
  export type ProvisionResult = {
48
49
  // Where the skills were installed (backend-dependent, see skillsDirFor).
49
50
  skillsDir: string
50
- // 'exists' when `.moi/` was already bootstrapped, 'installing' when bun
51
- // install continues in the background, else the install exit code (non-zero
52
- // means deps are missing — not fatal, the agent installs on demand).
53
- scaffold: 'exists' | 'installing' | number
54
- // Unique temporary log for this install attempt; unused when scaffold exists.
55
- installLogPath: string
56
- }
51
+ } & (
52
+ | { scaffold: 'skipped' | 'exists'; installLogPath?: never }
53
+ // Dependency installation is running or finished with this exit code.
54
+ | { scaffold: 'installing' | number; installLogPath: string }
55
+ )
57
56
 
58
57
  // Lay down everything a workspace needs: reset Claude/Codex's shared skill
59
58
  // (or copy skills to other backends' own destinations), and bootstrap `.moi/`.
@@ -61,12 +60,15 @@ export type ProvisionResult = {
61
60
  // Registration in the workspace registry is a separate, caller-owned step.
62
61
  export async function provisionWorkspace(
63
62
  workspaceRoot: string,
64
- type?: WorkspaceType
63
+ harness?: HarnessType
65
64
  ): Promise<ProvisionResult> {
66
- const skillsDir = skillsDirFor(workspaceRoot, type)
65
+ const skillsDir = skillsDirFor(workspaceRoot, harness)
67
66
  await mkdir(workspaceRoot, { recursive: true })
68
- await installWorkspaceSkills(workspaceRoot, type)
67
+ const config = await loadWorkspaceFileConfig(workspaceRoot)
68
+ await installWorkspaceSkills(workspaceRoot, harness)
69
+ if (config.remote) return { skillsDir, scaffold: 'skipped' }
69
70
  const installLogPath = createDependencyInstallLogPath()
70
71
  const scaffold = await scaffoldMoiDir(workspaceRoot, undefined, undefined, installLogPath)
72
+ if (scaffold === 'exists') return { skillsDir, scaffold }
71
73
  return { skillsDir, scaffold, installLogPath }
72
74
  }
@@ -1,86 +1,71 @@
1
+ import { mkdir, writeFile } from 'node:fs/promises'
2
+ import {
3
+ parseRemoteWorkspaceConfig,
4
+ parseRemoteWorkspaceTarget,
5
+ type RemoteWorkspaceTarget,
6
+ type WorkspaceFileConfig
7
+ } from '@/lib/workspace-config'
1
8
  import { join } from 'path'
2
- import { isSpeedMode } from '@/lib/speed-mode'
3
9
 
4
- import type {
5
- AppletKind,
6
- WorkspaceLayout,
7
- WorkspaceLayoutSave,
8
- WorkspacePreview
9
- } from '@/lib/types'
10
- import { createDefaultWorkspaceLayout, normalizeWorkspaceTabs } from '@/lib/workspace-layout'
10
+ import type { AppletKind, WorkspaceLayout, WorkspacePreview } from '@/lib/types'
11
+ import { createDefaultWorkspaceLayout } from '@/lib/workspace-layout'
11
12
  import { isWorkspaceIcon } from '@/lib/workspace-icon'
12
13
 
13
14
  import { getCapturedThumbnails } from '../applets/thumbnails'
14
15
 
15
16
  function normalizeLayout(parsed: Record<string, unknown>): WorkspaceLayout {
16
- const defaults = createDefaultWorkspaceLayout()
17
- const layout = { ...defaults, ...parsed } as Record<string, unknown>
18
- if (layout.layoutMode !== 'split' && layout.layoutMode !== 'fullscreen') {
19
- layout.layoutMode = defaults.layoutMode
20
- }
21
- layout.tabs = normalizeWorkspaceTabs(layout.tabs)
22
- if (!isSpeedMode(layout.selectedSpeedMode)) delete layout.selectedSpeedMode
23
- delete layout.selectedFastMode
24
- if (typeof layout.icon === 'string') {
25
- layout.icon = { type: 'upload', value: layout.icon }
26
- } else if (layout.icon !== undefined && !isWorkspaceIcon(layout.icon)) {
27
- delete layout.icon
17
+ return {
18
+ version: 2,
19
+ widgetGrid: (parsed.widgetGrid ??
20
+ createDefaultWorkspaceLayout().widgetGrid) as WorkspaceLayout['widgetGrid'],
21
+ ...(typeof parsed.name === 'string' && { name: parsed.name }),
22
+ ...(isWorkspaceIcon(parsed.icon) && { icon: parsed.icon }),
23
+ ...(typeof parsed.theme === 'object' &&
24
+ parsed.theme !== null && { theme: parsed.theme as WorkspaceLayout['theme'] })
28
25
  }
29
- // Legacy thumbnail caches are intentionally dropped, not migrated — images
30
- // now live as files under `.moi/.cache/thumbnails` (server/applets/thumbnails.ts)
31
- // and applets are simply captured again there.
32
- delete layout.widgetThumbnails
33
- delete layout.viewThumbnails
34
- delete layout.appletThumbnails
35
- delete layout.sectionMode
36
- delete layout.chatMode
37
- return layout as unknown as WorkspaceLayout
38
26
  }
39
27
 
40
28
  export function getLayoutPath(workspacePath: string): string {
41
29
  return join(workspacePath, '.moi', '.workspace.json')
42
30
  }
43
31
 
32
+ // This module remains the sole owner of workspace config persistence.
33
+ export async function loadWorkspaceFileConfig(workspacePath: string): Promise<WorkspaceFileConfig> {
34
+ const file = Bun.file(getLayoutPath(workspacePath))
35
+ if (!(await file.exists())) return createDefaultWorkspaceLayout()
36
+ const parsed: unknown = await file.json()
37
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
38
+ throw new Error('Invalid workspace config')
39
+ const value = parsed as Record<string, unknown>
40
+ if ('remote' in value) return parseRemoteWorkspaceConfig(value)
41
+ if (value.version !== 1 && value.version !== 2)
42
+ throw new Error('Unsupported workspace config version')
43
+ return normalizeLayout(value)
44
+ }
45
+
44
46
  export async function loadLayout(workspacePath: string): Promise<WorkspaceLayout> {
45
- try {
46
- const text = await Bun.file(getLayoutPath(workspacePath)).text()
47
- const parsed = JSON.parse(text)
48
- if (parsed?.version === 1) return normalizeLayout(parsed)
49
- } catch {}
50
- return createDefaultWorkspaceLayout()
47
+ const config = await loadWorkspaceFileConfig(workspacePath)
48
+ if (config.remote) throw new Error('Remote workspace has no local layout')
49
+ return config
51
50
  }
52
51
 
53
52
  export async function saveLayout(layout: WorkspaceLayout, workspacePath: string): Promise<void> {
53
+ const existing = await loadWorkspaceFileConfig(workspacePath)
54
+ if (existing.remote)
55
+ throw new Error('Cannot replace a remote workspace reference with a local layout')
54
56
  await Bun.write(getLayoutPath(workspacePath), JSON.stringify(layout, null, 2))
55
57
  }
56
58
 
57
- // Merge a client-submitted layout over the stored one for persistence.
58
- //
59
- // Everything (grid, layout mode, theme, AND identity) shares one
60
- // `.workspace.json`, but the grid editor and `moi config` own different fields.
61
- // The client's layout PUT is authoritative for the editor fields (widgetGrid,
62
- // layoutMode, theme, selectedModel) — but it strips `name` and round-trips a
63
- // possibly-stale `icon`.
64
- // A blind overwrite therefore erases a `moi config`-set name (and could revert an
65
- // icon). So drop whatever identity the body carries and re-apply the server-owned
66
- // fields from `existing` — conditionally, so an absent field never serializes
67
- // as `name: undefined`.
59
+ // The editor owns widgets and theme; identity changes use the config API.
68
60
  export function mergeLayoutForSave(
69
61
  existing: WorkspaceLayout,
70
- body: WorkspaceLayoutSave
62
+ body: WorkspaceLayout
71
63
  ): WorkspaceLayout {
72
- const { name: _name, icon: _icon, ...editor } = body
73
- // Stale clients may still round-trip the pre-`.cache` thumbnail records;
74
- // never let a layout PUT resurrect them in `.workspace.json`.
75
- delete (editor as Record<string, unknown>).appletThumbnails
76
- return {
77
- ...editor,
78
- // Personal navigation never writes tabs. Other layout edits must not
79
- // round-trip a stale copy of the workspace's authored defaults.
80
- tabs: editor.tabs === undefined ? existing.tabs : normalizeWorkspaceTabs(editor.tabs),
81
- ...(existing.name !== undefined && { name: existing.name }),
82
- ...(existing.icon !== undefined && { icon: existing.icon })
83
- }
64
+ return normalizeLayout({
65
+ ...existing,
66
+ widgetGrid: body.widgetGrid ?? existing.widgetGrid,
67
+ theme: body.theme ?? existing.theme
68
+ })
84
69
  }
85
70
 
86
71
  // Thumbnails for the home screen's workspace card. Widgets take the front
@@ -96,7 +81,7 @@ function normalizePreviewMessage(message: string | undefined): string | undefine
96
81
  }
97
82
 
98
83
  export type WorkspacePreviewOptions = {
99
- getProviderPreview?: (includeFirstUserMessage: boolean) => Promise<{
84
+ getHarnessPreview?: (includeFirstUserMessage: boolean) => Promise<{
100
85
  firstUserMessage?: string
101
86
  updatedAt?: number
102
87
  }>
@@ -109,7 +94,7 @@ export type WorkspacePreviewOptions = {
109
94
 
110
95
  export async function getWorkspacePreview(
111
96
  workspacePath: string,
112
- { getProviderPreview, viewIds = [], thumbnailUrl }: WorkspacePreviewOptions
97
+ { getHarnessPreview, viewIds = [], thumbnailUrl }: WorkspacePreviewOptions
113
98
  ): Promise<WorkspacePreview> {
114
99
  try {
115
100
  const layout = await loadLayout(workspacePath)
@@ -136,14 +121,12 @@ export async function getWorkspacePreview(
136
121
  // were never captured (never opened in a browser) still renders an empty
137
122
  // folder otherwise.
138
123
  const includeFirstUserMessage = thumbnails.length === 0
139
- const providerPreview = await getProviderPreview?.(includeFirstUserMessage).catch(
140
- () => undefined
141
- )
142
- const updatedAt = providerPreview?.updatedAt
124
+ const harnessPreview = await getHarnessPreview?.(includeFirstUserMessage).catch(() => undefined)
125
+ const updatedAt = harnessPreview?.updatedAt
143
126
  const theme = layout.theme
144
127
 
145
128
  if (includeFirstUserMessage) {
146
- const firstUserMessage = normalizePreviewMessage(providerPreview?.firstUserMessage)
129
+ const firstUserMessage = normalizePreviewMessage(harnessPreview?.firstUserMessage)
147
130
  return {
148
131
  thumbnails,
149
132
  ...(firstUserMessage ? { firstUserMessage } : {}),
@@ -161,3 +144,14 @@ export async function getWorkspacePreview(
161
144
  return { thumbnails: [] }
162
145
  }
163
146
  }
147
+
148
+ export async function initializeRemoteWorkspaceConfig(
149
+ workspacePath: string,
150
+ remote: RemoteWorkspaceTarget
151
+ ): Promise<void> {
152
+ remote = parseRemoteWorkspaceTarget(remote)
153
+ await mkdir(join(workspacePath, '.moi'), { recursive: true })
154
+ await writeFile(getLayoutPath(workspacePath), JSON.stringify({ version: 2, remote }, null, 2), {
155
+ flag: 'wx'
156
+ })
157
+ }
@@ -1,11 +1,12 @@
1
+ import { loadWorkspaceFileConfig } from './layout'
1
2
  import { existsSync, realpathSync } from 'node:fs'
2
3
  import { readdir, rename, rm, stat } from 'node:fs/promises'
3
4
  import { homedir } from 'node:os'
4
5
  import { join, resolve, sep } from 'path'
5
6
 
6
7
  import { newWorkspaceId, validateWorkspaceId } from '@/lib/ids'
7
- import type { DiscoveredWorkspace, WorkspaceEntry, WorkspaceType } from '@/lib/types'
8
- import { orderWorkspaceTypes } from '@/lib/workspace-types'
8
+ import type { DiscoveredWorkspace, WorkspaceEntry, HarnessType } from '@/lib/types'
9
+ import { orderHarnesses } from '@/lib/harness-types'
9
10
 
10
11
  import { DATA_DIR } from '../data-dir'
11
12
  import { allHarnesses } from '../harness/registry'
@@ -46,16 +47,29 @@ async function readRegistry(): Promise<WorkspaceEntry[]> {
46
47
  if (!existsSync(_registryPath)) return []
47
48
  try {
48
49
  const text = await Bun.file(_registryPath).text()
49
- return JSON.parse(text) as WorkspaceEntry[]
50
+ // `type` is the field's name in registries written before it became `harness`.
51
+ const entries = JSON.parse(text) as (WorkspaceEntry & { type?: HarnessType })[]
52
+ return entries.map(({ remote: _storedRemote, type, ...entry }) =>
53
+ type && !entry.harness ? { ...entry, harness: type } : entry
54
+ )
50
55
  } catch {
51
56
  return []
52
57
  }
53
58
  }
54
59
 
60
+ // Owner routing lives in each folder's config. Reading it costs a file per
61
+ // entry, so only listings and single lookups pay for it, never every registry read.
62
+ async function withRemote(entry: WorkspaceEntry): Promise<WorkspaceEntry> {
63
+ const config = await loadWorkspaceFileConfig(entry.path).catch(() => undefined)
64
+ return config?.remote ? { ...entry, remote: config.remote } : entry
65
+ }
66
+
55
67
  async function writeRegistry(entries: WorkspaceEntry[]): Promise<void> {
56
68
  const temporaryPath = `${_registryPath}.${crypto.randomUUID()}.tmp`
57
69
  try {
58
- await Bun.write(temporaryPath, JSON.stringify(entries, null, 2))
70
+ // Owner routing is derived from each folder's config, never persisted here.
71
+ const stored = entries.map(({ remote: _remote, ...entry }) => entry)
72
+ await Bun.write(temporaryPath, JSON.stringify(stored, null, 2))
59
73
  await rename(temporaryPath, _registryPath)
60
74
  } finally {
61
75
  await rm(temporaryPath, { force: true })
@@ -87,7 +101,7 @@ export type RegisterOptions = {
87
101
  // Register under this id instead of a generated one. Only accepted while the
88
102
  // workspace is unregistered — see `workspaceIdError`.
89
103
  id?: string
90
- type?: WorkspaceType
104
+ harness?: HarnessType
91
105
  name?: string
92
106
  agentId?: string
93
107
  isDefault?: boolean
@@ -128,18 +142,29 @@ export async function registerWorkspace(
128
142
  ): Promise<WorkspaceEntry> {
129
143
  return locked(async () => {
130
144
  const normalPath = resolve(absPath)
145
+ const remote = (await loadWorkspaceFileConfig(normalPath).catch(() => undefined))?.remote
131
146
  const entries = await readRegistry()
132
147
  if (opts.id) {
133
148
  const error = workspaceIdError(entries, normalPath, opts.id)
134
149
  if (error) throw new Error(error)
135
150
  }
136
151
  const existing = entries.find(e => e.path === normalPath)
137
- if (existing) return existing
152
+ if (existing) return remote ? { ...existing, remote } : existing
153
+ if (remote) {
154
+ // One registration per owner workspace, whichever folder points at it.
155
+ const duplicate = (await Promise.all(entries.map(withRemote))).find(
156
+ entry =>
157
+ entry.remote?.user_id === remote.user_id &&
158
+ entry.remote.workspace_id === remote.workspace_id
159
+ )
160
+ if (duplicate) return withDisplayPath(duplicate)
161
+ }
138
162
  const entry: WorkspaceEntry = {
139
163
  id: opts.id ?? (await previousWorkspaceId(entries, normalPath)) ?? newWorkspaceId(),
164
+ ...(remote ? { remote } : {}),
140
165
  path: normalPath,
141
166
  addedAt: new Date().toISOString(),
142
- ...(opts.type ? { type: opts.type } : {}),
167
+ ...(opts.harness ? { harness: opts.harness } : {}),
143
168
  ...(opts.name ? { name: opts.name } : {}),
144
169
  ...(opts.agentId ? { agentId: opts.agentId } : {}),
145
170
  ...(opts.isDefault ? { isDefault: opts.isDefault } : {}),
@@ -151,8 +176,8 @@ export async function registerWorkspace(
151
176
  }
152
177
 
153
178
  export async function getWorkspace(id: string): Promise<WorkspaceEntry | null> {
154
- const entries = await readRegistry()
155
- return entries.find(e => e.id === id) ?? null
179
+ const entry = (await readRegistry()).find(e => e.id === id)
180
+ return entry ? withRemote(entry) : null
156
181
  }
157
182
 
158
183
  export async function removeWorkspace(id: string): Promise<boolean> {
@@ -166,7 +191,7 @@ export async function removeWorkspace(id: string): Promise<boolean> {
166
191
  }
167
192
 
168
193
  export async function listWorkspaces(): Promise<WorkspaceEntry[]> {
169
- const entries = await readRegistry()
194
+ const entries = await Promise.all((await readRegistry()).map(withRemote))
170
195
  return entries.map(withDisplayPath)
171
196
  }
172
197
 
@@ -185,7 +210,7 @@ export async function reorderWorkspaces(ids: string[]): Promise<WorkspaceEntry[]
185
210
 
186
211
  const ordered = next as WorkspaceEntry[]
187
212
  await writeRegistry(ordered)
188
- return ordered.map(withDisplayPath)
213
+ return (await Promise.all(ordered.map(withRemote))).map(withDisplayPath)
189
214
  })
190
215
  }
191
216
 
@@ -258,23 +283,23 @@ export async function discoverWorkspaceFolders(
258
283
  }
259
284
 
260
285
  export function mergeWorkspaceCandidates(
261
- candidates: { path: string; type?: WorkspaceType }[],
286
+ candidates: { path: string; harness?: HarnessType }[],
262
287
  registeredPaths: Set<string> = new Set()
263
288
  ): DiscoveredWorkspace[] {
264
289
  const normalizedRegisteredPaths = new Set([...registeredPaths].map(path => resolve(path)))
265
- const byPath = new Map<string, Set<WorkspaceType>>()
290
+ const byPath = new Map<string, Set<HarnessType>>()
266
291
 
267
292
  for (const candidate of candidates) {
268
293
  const path = resolve(candidate.path)
269
294
  if (normalizedRegisteredPaths.has(path)) continue
270
- const types = byPath.get(path) ?? new Set<WorkspaceType>()
271
- if (candidate.type) types.add(candidate.type)
295
+ const types = byPath.get(path) ?? new Set<HarnessType>()
296
+ if (candidate.harness) types.add(candidate.harness)
272
297
  byPath.set(path, types)
273
298
  }
274
299
 
275
300
  return [...byPath].map(([path, types]) => ({
276
301
  path,
277
- types: orderWorkspaceTypes(types)
302
+ harnesses: orderHarnesses(types)
278
303
  }))
279
304
  }
280
305
 
@@ -292,13 +317,13 @@ export async function discoverWorkspaces(): Promise<DiscoveredWorkspace[]> {
292
317
 
293
318
  export async function updateWorkspaceHarness(
294
319
  id: string,
295
- type: WorkspaceType
320
+ harness: HarnessType
296
321
  ): Promise<WorkspaceEntry> {
297
322
  return locked(async () => {
298
323
  const entries = await readRegistry()
299
324
  const entry = entries.find(entry => entry.id === id)
300
325
  if (!entry) throw new Error('Workspace not found')
301
- entry.type = type
326
+ entry.harness = harness
302
327
  await writeRegistry(entries)
303
328
  return withDisplayPath(entry)
304
329
  })
@@ -0,0 +1,74 @@
1
+ import { mkdir, rm } from 'node:fs/promises'
2
+ import { join } from 'node:path'
3
+ import { Mutex } from 'async-mutex'
4
+ import { createdWorkspacesRoot } from '../app-config'
5
+ import { workspaceIdFromName } from '@/lib/workspace-name'
6
+ import { parseRemoteWorkspaceTarget, type RemoteWorkspaceTarget } from '@/lib/workspace-config'
7
+ import type { HarnessType } from '@/lib/types'
8
+ import { listWorkspaces, registerWorkspace } from './registry'
9
+ import { provisionWorkspace } from './init'
10
+ import { getLayoutPath, initializeRemoteWorkspaceConfig, loadWorkspaceFileConfig } from './layout'
11
+ import { publishEvent } from '../events'
12
+
13
+ const opening = new Mutex()
14
+ export async function openSharedWorkspace(remote: RemoteWorkspaceTarget, harness?: HarnessType) {
15
+ remote = parseRemoteWorkspaceTarget(remote)
16
+ return opening.runExclusive(async () => {
17
+ const matches = (target?: RemoteWorkspaceTarget) =>
18
+ target?.user_id === remote.user_id && target.workspace_id === remote.workspace_id
19
+ const existing = (await listWorkspaces()).find(entry => matches(entry.remote))
20
+ if (existing) return existing
21
+ const hash = new Bun.CryptoHasher('sha256')
22
+ .update(JSON.stringify([remote.user_id, remote.workspace_id]))
23
+ .digest('hex')
24
+ .slice(0, 12)
25
+ const root = createdWorkspacesRoot()
26
+ await mkdir(root, { recursive: true })
27
+ const path = join(root, `shared-${workspaceIdFromName(remote.workspace_id)}-${hash}`)
28
+ const created = await mkdir(path).then(
29
+ () => true,
30
+ (error: NodeJS.ErrnoException) => {
31
+ if (error.code !== 'EEXIST') throw error
32
+ return false
33
+ }
34
+ )
35
+ if (!created) {
36
+ const config = await loadWorkspaceFileConfig(path)
37
+ if (!matches(config.remote))
38
+ throw new Error('The shared workspace folder already contains different content')
39
+ }
40
+ let entry
41
+ try {
42
+ entry = await registerRemoteWorkspaceReference(path, remote, harness)
43
+ } catch (error) {
44
+ // Only remove an empty directory we created; keep a provisioned reference for retry.
45
+ if (created && !(await Bun.file(getLayoutPath(path)).exists()))
46
+ await rm(path, { recursive: true, force: true })
47
+ throw error
48
+ }
49
+ publishEvent({ type: 'workspaces-list:updated' })
50
+ return entry
51
+ })
52
+ }
53
+
54
+ // Shared filesystem operation for UI opening and CLI linking. Callers choose the folder
55
+ // and authenticate separately; a matching reference is safe to reuse after a partial failure.
56
+ // The agent is the visitor's own: `type` lands on the registry entry, never in the reference.
57
+ export async function registerRemoteWorkspaceReference(
58
+ path: string,
59
+ remote: RemoteWorkspaceTarget,
60
+ harness?: HarnessType
61
+ ) {
62
+ remote = parseRemoteWorkspaceTarget(remote)
63
+ const file = Bun.file(getLayoutPath(path))
64
+ if (await file.exists()) {
65
+ const config = await loadWorkspaceFileConfig(path)
66
+ if (
67
+ config.remote?.user_id !== remote.user_id ||
68
+ config.remote.workspace_id !== remote.workspace_id
69
+ )
70
+ throw new Error('This folder already has a different workspace configuration')
71
+ } else await initializeRemoteWorkspaceConfig(path, remote)
72
+ await provisionWorkspace(path, harness)
73
+ return registerWorkspace(path, harness ? { harness: harness } : {})
74
+ }
@@ -2,12 +2,11 @@
2
2
  import type { ViewInfo, WorkspaceTabId } from '@/lib/types'
3
3
  import { viewTabId } from '@/lib/workspace-tabs'
4
4
 
5
- // One row of `moi tabs`. `isDefault` marks the workspace's saved default tab
6
- // (`layout.tabs.active`) — where a bare `/workspace/:id` lands.
5
+ // One row of `moi tabs`. Open tabs are a per-browser preference, so the server
6
+ // lists destinations only.
7
7
  export type TabRow = {
8
8
  id: WorkspaceTabId
9
9
  title: string
10
- isDefault: boolean
11
10
  href: string
12
11
  }
13
12
 
@@ -17,24 +16,19 @@ const STATIC_TABS: { id: WorkspaceTabId; title: string }[] = [
17
16
  { id: 'scratchpad', title: 'Scratchpad' }
18
17
  ]
19
18
 
20
- // The `moi tabs` listing: static tabs plus every compiled or pending view, with
21
- // the saved default marked.
22
- export function assembleTabRows(views: ViewInfo[], defaultTab: WorkspaceTabId): TabRow[] {
19
+ // The `moi tabs` listing: static tabs plus every compiled or pending view.
20
+ export function assembleTabRows(views: ViewInfo[]): TabRow[] {
23
21
  return [
24
22
  ...STATIC_TABS,
25
23
  ...views.map(view => ({ id: viewTabId(view.id), title: view.title || view.id }))
26
- ].map(row => ({
27
- ...row,
28
- isDefault: row.id === defaultTab,
29
- href: `moi:/${row.id}`
30
- }))
24
+ ].map(row => ({ ...row, href: `moi:/${row.id}` }))
31
25
  }
32
26
 
33
27
  // CLI navigation checks the server's current built-view list before asking a
34
28
  // browser to move. The browser repeats the availability check in case its view
35
29
  // list is stale in either direction.
36
30
  export function assertNavigableTab(tab: WorkspaceTabId, views: ViewInfo[]): void {
37
- const rows = assembleTabRows(views, 'overview')
31
+ const rows = assembleTabRows(views)
38
32
  if (rows.some(row => row.id === tab)) return
39
33
  throw new Error(
40
34
  `Unknown destination "moi:/${tab}". Valid addresses: ${rows.map(row => row.href).join(', ')}`