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

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 (205) 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 +14 -109
  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 +66 -23
  63. package/client/features/views/use-view-actions.ts +10 -41
  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 +1 -8
  82. package/client/features/workspace/use-workspace-navigation.ts +11 -7
  83. package/client/features/workspace/workspace-content.tsx +24 -31
  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 +91 -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 +42 -16
  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 +24 -9
  98. package/client/store/workspace-session.ts +30 -0
  99. package/dist/chunk-0h4zypgf.js +1 -0
  100. package/dist/chunk-1tksq43z.js +72 -0
  101. package/dist/chunk-6gxf0xr8.js +5 -0
  102. package/dist/chunk-a865c7x4.js +1 -0
  103. package/dist/chunk-f44cs6mw.js +2 -0
  104. package/dist/chunk-h3qag4a6.js +2 -0
  105. package/dist/chunk-kffcah9w.css +1 -0
  106. package/dist/chunk-q2tpy0h7.js +2 -0
  107. package/dist/chunk-r95acex1.js +546 -0
  108. package/dist/chunk-w5h9grdr.js +1 -0
  109. package/dist/{chunk-th91xfnp.js → chunk-xj1pjhng.js} +1 -1
  110. package/dist/index.html +1 -1
  111. package/lib/harness-instructions.ts +4 -4
  112. package/lib/harness-types.ts +13 -0
  113. package/lib/moi-context.ts +19 -5
  114. package/lib/types.ts +38 -54
  115. package/lib/workspace-config.ts +48 -0
  116. package/lib/workspace-layout.ts +5 -24
  117. package/package.json +5 -2
  118. package/server/AGENTS.md +1 -1
  119. package/server/README.md +36 -31
  120. package/server/api/harnesses.ts +5 -5
  121. package/server/api/index.ts +268 -162
  122. package/server/applets/index.ts +15 -9
  123. package/server/applets/views.ts +2 -17
  124. package/server/applets/widgets.ts +3 -2
  125. package/server/cli/commands/config.ts +8 -20
  126. package/server/cli/commands/hermes.ts +2 -2
  127. package/server/cli/commands/init.ts +102 -54
  128. package/server/cli/commands/openclaw.ts +2 -2
  129. package/server/cli/commands/refresh.ts +10 -1
  130. package/server/cli/commands/remote.ts +330 -0
  131. package/server/cli/commands/skill.ts +4 -4
  132. package/server/cli/commands/tabs.ts +5 -12
  133. package/server/cli/control.ts +35 -4
  134. package/server/cli/index.ts +10 -6
  135. package/server/cli/remote-command.ts +77 -0
  136. package/server/cli/remote-control.ts +73 -0
  137. package/server/cli/remote-operations.ts +247 -0
  138. package/server/collab/config.ts +3 -3
  139. package/server/collab/skill/index.ts +3 -3
  140. package/server/control.ts +47 -12
  141. package/server/harness/acp/session.ts +4 -4
  142. package/server/harness/auth.ts +26 -31
  143. package/server/harness/claude-code/index.ts +1 -1
  144. package/server/harness/codex/discovery.ts +1 -1
  145. package/server/harness/codex/session.ts +1 -1
  146. package/server/harness/detect.ts +14 -19
  147. package/server/harness/executable.ts +10 -10
  148. package/server/harness/hermes/NOTES.md +2 -2
  149. package/server/harness/hermes/index.ts +1 -1
  150. package/server/harness/install.ts +11 -11
  151. package/server/harness/openclaw/index.ts +1 -1
  152. package/server/harness/registry.ts +7 -6
  153. package/server/harness/types.ts +4 -4
  154. package/server/onboarding/jobs.ts +2 -2
  155. package/server/operations/commands.ts +46 -0
  156. package/server/operations/files.ts +148 -0
  157. package/server/operations/server.ts +206 -0
  158. package/server/remote/agent.ts +103 -0
  159. package/server/remote/broker-client.ts +76 -0
  160. package/server/remote/broker.ts +81 -0
  161. package/server/remote/client.ts +725 -0
  162. package/server/remote/errors.ts +2 -0
  163. package/server/remote/routes.ts +121 -0
  164. package/server/remote/workspace.ts +34 -0
  165. package/server/scratchpad/document.ts +33 -12
  166. package/server/scratchpad/executor.ts +16 -7
  167. package/server/sessions/config.ts +8 -5
  168. package/server/sessions/pending-views.ts +17 -0
  169. package/server/sessions/send-message.ts +102 -0
  170. package/server/sessions/view-sessions.ts +9 -101
  171. package/server/skills/locations.ts +4 -4
  172. package/server/skills/update.ts +11 -11
  173. package/server/skills/version.ts +7 -7
  174. package/server/skills/workspace.ts +13 -11
  175. package/server/web.ts +13 -9
  176. package/server/workspace-state/file.ts +4 -0
  177. package/server/workspace-state/index.ts +0 -4
  178. package/server/workspaces/api.ts +24 -0
  179. package/server/workspaces/change-harness.ts +15 -26
  180. package/server/workspaces/import.ts +4 -4
  181. package/server/workspaces/init.ts +15 -13
  182. package/server/workspaces/layout.ts +60 -66
  183. package/server/workspaces/registry.ts +43 -18
  184. package/server/workspaces/shared.ts +74 -0
  185. package/server/workspaces/tabs.ts +5 -12
  186. package/skill/SKILL.md +80 -19
  187. package/skill/references/SCRATCHPAD.md +4 -0
  188. package/skill/references/UI-COMPONENTS.md +1 -1
  189. package/client/api/app-ui-keys.ts +0 -6
  190. package/client/features/chat/sessions/browser-tab-state.ts +0 -43
  191. package/client/features/collab/members/keys.ts +0 -6
  192. package/client/features/workspace/browser-tab-state.ts +0 -51
  193. package/client/features/workspace/layout-save.ts +0 -13
  194. package/dist/chunk-3smkkcfw.js +0 -546
  195. package/dist/chunk-47h9c2qy.js +0 -2
  196. package/dist/chunk-8qed2gqp.js +0 -75
  197. package/dist/chunk-8zy3vesm.js +0 -1
  198. package/dist/chunk-a47zy276.js +0 -2
  199. package/dist/chunk-g4c1nte9.css +0 -1
  200. package/dist/chunk-kcactdr4.js +0 -2
  201. package/dist/chunk-m8bhx6tw.js +0 -1
  202. package/dist/chunk-pf19zcrn.js +0 -2
  203. package/dist/chunk-ygzxah0e.js +0 -1
  204. package/lib/workspace-types.ts +0 -13
  205. package/server/workspace-state/legacy-migration.ts +0 -79
@@ -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,10 @@
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
+ // `moi tabs` lists all destinations, regardless of which tabs are open.
7
6
  export type TabRow = {
8
7
  id: WorkspaceTabId
9
8
  title: string
10
- isDefault: boolean
11
9
  href: string
12
10
  }
13
11
 
@@ -17,24 +15,19 @@ const STATIC_TABS: { id: WorkspaceTabId; title: string }[] = [
17
15
  { id: 'scratchpad', title: 'Scratchpad' }
18
16
  ]
19
17
 
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[] {
18
+ // The `moi tabs` listing: static tabs plus every compiled or pending view.
19
+ export function assembleTabRows(views: ViewInfo[]): TabRow[] {
23
20
  return [
24
21
  ...STATIC_TABS,
25
22
  ...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
- }))
23
+ ].map(row => ({ ...row, href: `moi:/${row.id}` }))
31
24
  }
32
25
 
33
26
  // CLI navigation checks the server's current built-view list before asking a
34
27
  // browser to move. The browser repeats the availability check in case its view
35
28
  // list is stale in either direction.
36
29
  export function assertNavigableTab(tab: WorkspaceTabId, views: ViewInfo[]): void {
37
- const rows = assembleTabRows(views, 'overview')
30
+ const rows = assembleTabRows(views)
38
31
  if (rows.some(row => row.id === tab)) return
39
32
  throw new Error(
40
33
  `Unknown destination "moi:/${tab}". Valid addresses: ${rows.map(row => row.href).join(', ')}`
package/skill/SKILL.md CHANGED
@@ -10,9 +10,10 @@ description: The Moi workspace — the web UI the user chats from, extended with
10
10
  "Workspace" or "Moi Workspace" — the web UI that the user works in, talks/collaborates with you,
11
11
  sees and interacts with "Applets".
12
12
 
13
- "Project" - the primary working folder _you_ (as an agent) work in. Managed by your harness; Moi
14
- does not have a clear definition, but assumes this is the root folder in which it stores its state
15
- files.
13
+ "Workspace dir" — the primary working folder _you_ (as an agent) work in. Workspace files are stored here;
14
+ it also contains `.moi/`, which holds configuration, applets, applet, dependencies and other workspace extensions.
15
+
16
+ "Remote workspace" - Moi Workspace running on a different machine that someone else shared with the user and you.
16
17
 
17
18
  "Chat" — a conversation between the user and an agent in the workspace.
18
19
 
@@ -50,6 +51,32 @@ User can switch between these, but can access the chat (this conversation and ot
50
51
 
51
52
  ## Working in the workspace
52
53
 
54
+ ### Local or Remote workspaces
55
+
56
+ Workspace can be either:
57
+
58
+ **Local** workspace dir is stored on this computer. You have full control over it. You
59
+ interact with it using filesystem operations and by calling moi cli.
60
+
61
+ **Remote**. Workspace is running on someone else's ("owner") computer and it is shared with the user.
62
+ In this case, there are two dirs and two computers:
63
+
64
+ _Owner dir_ for the owner, looks like a regular local workspace. Has the file structure described in
65
+ "Files and Folders" section. Owner's agent runs there and it interact with it by using regular file ops.
66
+ Source of truth for shared workspace files and content, including applets, extensions, and shared data.
67
+ Everything in the dir is shared with all members. Each visitor’s chats, pending views, and agent settings
68
+ remain personal and are managed by their own Moi instance.
69
+
70
+ _Linked dir_ is on this computer. It's your local working folder, no other user sees it. `.moi` folder is
71
+ stripped down, only contains meta that this folder is linked to remote workspace. All files here are for
72
+ private and intermediate work. You can also interact with the remote workspace and owner dir using
73
+ subset of regular `moi` commands and also `moi remote` commands. Do not create local applet copies and
74
+ prefer not to store workspace state here (it gets out of sync quickly). Full command reference is in
75
+ "Using the Moi CLI"
76
+
77
+ The newest `<moi-context>` identifies whether the workspace is local or remote. If it does not,
78
+ run `moi remote` to check.
79
+
53
80
  ### Boundaries
54
81
 
55
82
  - Never read or modify files outside the `.moi` directory, unless the user explicitly asks. If you
@@ -59,11 +86,11 @@ User can switch between these, but can access the chat (this conversation and ot
59
86
 
60
87
  ### Files and folders
61
88
 
62
- Source of truth - `.moi` folder in the root of "Project" folder. Contains source code of all
89
+ For local workspaces, the source of truth is the `.moi` folder inside the workspace dir. Contains source code of all
63
90
  Applets, bundled code, settings, etc. Can be committed to version control. Folder is partially
64
91
  initialised when Workspace starts, you have full ownership of it.
65
92
 
66
- You _do have_ access to the files in the root of Project — you can reference and load them from the
93
+ You _do have_ access to the files in the workspace dir — you can reference and load them from the
67
94
  "Applets" and elsewhere.
68
95
 
69
96
  Folder structure:
@@ -83,17 +110,17 @@ my-agent-folder/
83
110
  users-api.server.ts <- Server-side async functions the view can call (optional)
84
111
  ...
85
112
  package.json <- Applet dependencies that you manage
86
- .workspace.json <- Auto-generated. Do NOT read, edit, or `cat` this file. Use Moi CLI instead.
113
+ .workspace.json <- Internal config. Do not edit.
87
114
  .scratchpad.json <- Scratchpad canvas snapshot. Internal — inspect only via `moi scratch read`, never open it.
88
115
  .scratchpad/ <- Scratchpad image files. Internal — pull pixels via `moi scratch read-image`, never open it.
89
116
  ```
90
117
 
91
118
  Every dot-prefixed file or folder inside `.moi/` (`.build/`, `.cache/`, `.workspace.json`,
92
119
  `.scratchpad*`, `.gitignore`, …) is a Moi internal: auto-generated and liable to change format
93
- without notice. Avoid them as much as possible — do not read, edit, or delete them, and never point
120
+ without notice. Do not read, edit, or delete them, and never point
94
121
  tooling at them; go through the `moi` CLI instead. Version control needs no special handling: the
95
- scaffolded `.moi/.gitignore` already excludes the machine-local entries (`.build/`, `.cache/`,
96
- `node_modules/`), while `.workspace.json` and `.scratchpad.json` are workspace state that ships
122
+ scaffolded `.moi/.gitignore` already excludes the machine-local entries (e.g. `.build/`), while
123
+ `.workspace.json` and `.scratchpad.json` are workspace state that ships
97
124
  with the repo — commit them as-is, just never hand-edit them. Your surface is the non-dot files:
98
125
  `widgets/`, `views/`, `package.json`, and code you place under `.moi/` yourself.
99
126
 
@@ -101,7 +128,7 @@ with the repo — commit them as-is, just never hand-edit them. Your surface is
101
128
 
102
129
  Treat `moi` as an external command — you cannot inspect or modify its sources. Use only the
103
130
  documented subcommands (`moi bundle`, `moi bundle --force`, etc.). Call `moi --help` for
104
- documentation. Run all `moi` commands from the **project root** — the folder that contains `.moi/`,
131
+ documentation. Run all `moi` commands from the **workspace dir** — the folder that contains `.moi/`,
105
132
  never from inside `.moi/` itself. You don't pass paths; Moi resolves the workspace from where it's run.
106
133
 
107
134
  Use the task-specific sections below for workflow guidance. The CLI will grow over time, so run
@@ -115,6 +142,32 @@ Use the task-specific sections below for workflow guidance. The CLI will grow ov
115
142
  - **Use workspace env:** `moi env` and `moi env exec` (see Environment and secrets).
116
143
  - **Maintain workspace guidance:** `moi skill` (see Keeping this skill current).
117
144
 
145
+ #### How CLI works in a linked to remote workspace dir
146
+
147
+ These commands only work in linked dir of the Remote workspace. They allow you to manage the host
148
+ workspace, write applets, work with files etc. Remote file paths are relative to the owner dir.
149
+ Upload sources, download destinations, and `--patch-file` paths refer to your machine.
150
+ For full reference, run `moi remote --help`
151
+
152
+ ```sh
153
+ moi remote # Show identity, link, help
154
+ moi remote exec 'ls .moi/views' # List files on the host
155
+ moi remote read .moi/views/dashboard.tsx # Read a host file
156
+ moi remote write .moi/notes.txt "Hello" # Create or overwrite a host file
157
+ moi remote patch .moi/views/dashboard.tsx --patch-file ./change.diff # Apply a local diff
158
+ moi remote file-upload ./chart.png .moi/chart.png # local → host
159
+ moi remote file-download .moi/chart.png ./chart.png # host → local
160
+ ```
161
+
162
+ These regular commands work and get forwared to remote: `check`, `bundle`, `call-server-fn`, `debug`,
163
+ `theme`, `ui-components`, `config`, `tabs`, `scratch`. Scratchpad reads and writes on owner's behalf,
164
+ except for `moi scratch view`.
165
+
166
+ These commands run on **your local Moi**: `refresh`, `navigate`, `views create`, `views set`, `env`.
167
+ `moi tabs` lists the remote workspace’s tabs and views. E.g. `navigate` switches the tab ONLY for current user.
168
+
169
+ Managing env vars on the remote machine is not yet supported. Tell the user to ask the workspace owner.
170
+
118
171
  ### Workspace navigation
119
172
 
120
173
  Use `moi:/` addresses in chat, CLI commands, and applets. They refer to the current workspace,
@@ -172,7 +225,11 @@ use `moi theme --help` if its options change.
172
225
 
173
226
  ### Environment and secrets
174
227
 
175
- Each workspace has an effective env: keys from the project's `.env` / `.env.local` (when
228
+ In remote workspaces, `moi env` commands manage your local environment, and `moi env exec`
229
+ runs locally. Applet server functions use the owner's environment; setting a key locally does
230
+ not make it available to the owner's applets.
231
+
232
+ Each workspace has an effective env: keys from `.env` / `.env.local` in the workspace dir (when
176
233
  inheritance is enabled in settings) plus **custom secrets** the user manages in the workspace env
177
234
  settings. Moi injects this env into:
178
235
 
@@ -351,8 +408,8 @@ replaces the pending screen in the same tab.
351
408
  - Use `style={{}}` only for computed data such as chart geometry, progress, per-item delays, or
352
409
  per-frame transforms.
353
410
  - Use icons from `@tabler/icons-react`. Do not add raw SVG icons or another icon pack. When the
354
- project provides `.agents/rules/icons.md`, follow its size and stroke policy.
355
- - Applets cannot import the host project's `cn`. If `.moi/ui/utils.ts` exists, import `cn` from
411
+ workspace dir contains `.agents/rules/icons.md`, follow its size and stroke policy.
412
+ - Applets cannot import the Moi host application's `cn`. If `.moi/ui/utils.ts` exists, import `cn` from
356
413
  `../ui/utils`; otherwise use a local `cx()` when classes are conditional. Never build class
357
414
  names with template-literal ternaries.
358
415
 
@@ -487,11 +544,15 @@ surfaces on its own.
487
544
  ## Chats and messages
488
545
 
489
546
  A workspace is driven through agent conversations (this chat is one). Depending on your
490
- harness (Claude Code, openclaw, others differ in the details) there can be **multiple chats**, but
491
- they all share **one** workspace **and one Project folder** — the same filesystem, the same `.moi`
492
- folder, applets, config, and theme. Anything you build is visible to every chat, and another chat
493
- may have changed the workspace or the Project files since you last looked. Treat `.moi` and the
494
- Project folder as shared state, not yours alone. Internally, "chats" are sometimes aliased as
547
+ harness (Claude Code, openclaw, others differ in the details) there can be **multiple chats**,
548
+ all working with the same shared applets, config, and theme.
549
+
550
+ You always run on your local machine, not on the remote owner's machine; other visitors have
551
+ their own agents running in their own linked dirs, while the owner's agents run in the owner dir.
552
+
553
+ Anything you build in the shared workspace is visible to other members, and another agent may
554
+ have changed its files since you last looked. Treat shared workspace files as shared state,
555
+ not yours alone. Internally, "chats" are sometimes aliased as
495
556
  "threads" — "chat" is product language, while "thread" is reserved for internal SDK, session, and
496
557
  persistence concepts.
497
558
 
@@ -522,4 +583,4 @@ This skill is installed with Moi (via the CLI or the UI) and can fall behind whe
522
583
  - **Then** — if you updated, mention it.
523
584
 
524
585
  <!-- moi skill version marker — read by `moi skill` to detect drift; do not edit by hand -->
525
- <moi-skill version="0.20.2" />
586
+ <moi-skill version="0.21.0" />
@@ -4,6 +4,10 @@ The Scratchpad is the workspace's **shared whiteboard** — one freeform tldraw
4
4
  draws on by hand and you drive through `moi scratch`. Same canvas, two authors; disk is the
5
5
  source of truth. Use it to sketch, diagram, annotate the user's drawing, or lay out boxes.
6
6
 
7
+ In a remote workspace, run commands from the linked dir: reads and edits use the owner's canvas,
8
+ while `moi scratch view` uses your local Moi and browser. Image input and output paths stay local:
9
+ `add image` uploads to the owner; `read-image` and `view --out` save locally.
10
+
7
11
  ## Seeing
8
12
 
9
13
  **Always inspect the canvas through the commands below — never open, `cat`, `read`, or parse the
@@ -5,7 +5,7 @@ theme tokens. Follow [DESIGN.md](DESIGN.md) for visual decisions.
5
5
 
6
6
  ## Workflow
7
7
 
8
- Run commands from the project root. Check what's available and installed, read the docs
8
+ Run commands from the workspace dir. Check what's available and installed, read the docs
9
9
  before using or changing a component, then add all missing components in one call.
10
10
 
11
11
  ```sh