moi-computer 0.13.1-next.0 → 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 (230) hide show
  1. package/client/api/app-config.ts +12 -2
  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 +37 -13
  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 +18 -4
  10. package/client/features/account/api.ts +10 -8
  11. package/client/features/account/profile-actions.ts +5 -7
  12. package/client/features/app-settings/avatar-upload.tsx +62 -0
  13. package/client/features/app-settings/profile-settings.tsx +10 -0
  14. package/client/features/app-settings/settings-page.tsx +2 -1
  15. package/client/features/applets/api.ts +6 -6
  16. package/client/features/applets/applet-cache.ts +6 -5
  17. package/client/features/applets/applet-log.ts +2 -1
  18. package/client/features/applets/applet-runtime.ts +2 -1
  19. package/client/features/applets/use-applet.ts +73 -18
  20. package/client/features/applets/widget-shell.tsx +4 -2
  21. package/client/features/chat/applet-chat-intents.ts +5 -13
  22. package/client/features/chat/chat-popup.tsx +8 -4
  23. package/client/features/chat/chat-send.ts +2 -2
  24. package/client/features/chat/composer/model-order.ts +4 -4
  25. package/client/features/chat/composer/model-picker.tsx +12 -10
  26. package/client/features/chat/composer/use-workspace-composer-state.tsx +1 -1
  27. package/client/features/chat/sessions/api.ts +11 -28
  28. package/client/features/chat/sessions/use-selected-session.ts +18 -100
  29. package/client/features/chat/use-chat.ts +8 -12
  30. package/client/features/collab/applet-api.ts +1 -1
  31. package/client/features/collab/components/cursors.tsx +6 -1
  32. package/client/features/collab/components/presence-avatars.tsx +1 -1
  33. package/client/features/collab/components/presence-frame.tsx +1 -1
  34. package/client/features/collab/components/presence-group.tsx +1 -1
  35. package/client/features/collab/components/presence-helpers.ts +2 -2
  36. package/client/features/collab/components/user-avatar-group.tsx +1 -1
  37. package/client/features/collab/components/user-avatar.tsx +1 -1
  38. package/client/features/collab/components/user.tsx +1 -1
  39. package/client/features/collab/index.ts +3 -3
  40. package/client/features/collab/members/api.ts +17 -0
  41. package/client/features/collab/members/hooks.ts +97 -0
  42. package/client/features/collab/members/store.ts +148 -0
  43. package/client/features/{workspace-members → collab/members}/types.ts +7 -5
  44. package/client/features/collab/{client.ts → presence/client.ts} +4 -5
  45. package/client/features/collab/{hooks.tsx → presence/hooks.tsx} +1 -1
  46. package/client/features/collab/{provider.tsx → presence/provider.tsx} +1 -12
  47. package/client/features/collab/{users.ts → presence/users.ts} +19 -21
  48. package/client/features/collab/proxy-user.ts +1 -3
  49. package/client/features/collab/sharing/agent-invite.tsx +30 -0
  50. package/client/features/collab/sharing/workspace-members.tsx +269 -0
  51. package/client/features/collab/sharing/workspace-sharing-menu.tsx +179 -0
  52. package/client/features/collab/testing/component-fixtures.tsx +3 -3
  53. package/client/features/collab/testing/fake-engine.ts +2 -2
  54. package/client/features/dev/chat-states-page.tsx +3 -1
  55. package/client/features/dev/collab/collab-playground.tsx +2 -2
  56. package/client/features/dev/dev-index-page.tsx +0 -6
  57. package/client/features/dev/dev-routes.tsx +0 -2
  58. package/client/features/dev/harness-debug-page.tsx +7 -7
  59. package/client/features/dev/workspace-setup-mocks.ts +1 -2
  60. package/client/features/dev/workspace-setup-preview.tsx +6 -4
  61. package/client/features/harness/api.ts +13 -10
  62. package/client/features/harness/harness-login-panel.tsx +9 -5
  63. package/client/features/harness/harness-presentation.ts +4 -4
  64. package/client/features/harness/harness-selector.tsx +13 -13
  65. package/client/features/harness/use-harness-login.ts +5 -5
  66. package/client/features/home/api.ts +38 -2
  67. package/client/features/home/home-page.tsx +43 -13
  68. package/client/features/home/shared-workspaces.tsx +70 -0
  69. package/client/features/home/workspace-invitations.tsx +101 -0
  70. package/client/features/identity/host-api.ts +5 -4
  71. package/client/features/identity/store.ts +1 -7
  72. package/client/features/onboarding/agent-setup-step.tsx +8 -8
  73. package/client/features/onboarding/onboarding-page.tsx +3 -2
  74. package/client/features/onboarding/workspace-setup-step.tsx +1 -1
  75. package/client/features/overview/api.ts +3 -5
  76. package/client/features/overview/default/registry.tsx +1 -1
  77. package/client/features/overview/default/views-widget.tsx +2 -2
  78. package/client/features/overview/hidden-panel.tsx +7 -5
  79. package/client/features/overview/overview.tsx +18 -16
  80. package/client/features/overview/workspace-name.tsx +2 -2
  81. package/client/features/scratchpad/scratchpad.tsx +9 -7
  82. package/client/features/scratchpad/use-scratchpad-snapshot.tsx +13 -5
  83. package/client/features/views/api.ts +34 -16
  84. package/client/features/views/use-view-actions.ts +10 -20
  85. package/client/features/views/view-manager.tsx +1 -1
  86. package/client/features/views/view-submission.ts +2 -21
  87. package/client/features/workspace/add/api.ts +5 -4
  88. package/client/features/workspace/add/create-workspace-dialog.tsx +12 -9
  89. package/client/features/workspace/add/import-workspace-dialog.tsx +7 -7
  90. package/client/features/workspace/add/use-workspace-import.ts +10 -10
  91. package/client/features/workspace/add/workspace-agent-options.ts +21 -20
  92. package/client/features/workspace/add/workspace-agent-selector.tsx +11 -11
  93. package/client/features/workspace/api.ts +60 -13
  94. package/client/features/workspace/harness-transition.ts +7 -13
  95. package/client/features/workspace/remote.ts +25 -0
  96. package/client/features/workspace/settings/api.ts +7 -12
  97. package/client/features/workspace/settings/connectors-settings.tsx +3 -3
  98. package/client/features/workspace/settings/general-settings.tsx +8 -8
  99. package/client/features/workspace/setup/workspace-login-state.tsx +4 -4
  100. package/client/features/workspace/setup/workspace-recovery-states.tsx +43 -14
  101. package/client/features/workspace/setup/workspace-setup.tsx +6 -6
  102. package/client/features/workspace/tab-resolution.ts +2 -2
  103. package/client/features/workspace/use-workspace-navigation.ts +7 -4
  104. package/client/features/workspace/workspace-content.tsx +32 -26
  105. package/client/features/workspace/workspace-frame.tsx +13 -26
  106. package/client/features/workspace/workspace-layout-context.tsx +45 -12
  107. package/client/features/workspace/workspace-menu.tsx +2 -2
  108. package/client/features/workspace/workspace-pane.tsx +22 -0
  109. package/client/features/workspace/workspace-pending-screen.tsx +1 -1
  110. package/client/features/workspace/workspace-preferences.ts +34 -0
  111. package/client/features/workspace/workspace-presentation.tsx +12 -16
  112. package/client/features/workspace/workspace-screen.tsx +2 -2
  113. package/client/features/workspace/workspace-state.ts +2 -1
  114. package/client/features/workspace/workspace-tabs.tsx +1 -1
  115. package/client/features/workspace/workspace-test-utils.ts +23 -0
  116. package/client/runtime/use-workspace-events.ts +14 -0
  117. package/client/runtime/workspace-events.ts +9 -9
  118. package/client/store/ui.ts +29 -9
  119. package/dist/chunk-44khk4sp.js +2 -0
  120. package/dist/chunk-ba6mz56s.js +72 -0
  121. package/dist/chunk-ec5ennpv.js +1 -0
  122. package/dist/chunk-ectsnw81.js +2 -0
  123. package/dist/chunk-en7w5ypg.js +1 -0
  124. package/dist/chunk-f695wcx5.js +5 -0
  125. package/dist/chunk-kffcah9w.css +1 -0
  126. package/dist/{chunk-kdgk4dac.js → chunk-n0fawy9x.js} +1 -1
  127. package/dist/chunk-pdt9hxfw.js +2 -0
  128. package/dist/chunk-rmd0ctfx.js +546 -0
  129. package/dist/chunk-zv22wv0g.js +1 -0
  130. package/dist/index.html +1 -1
  131. package/lib/harness-instructions.ts +4 -4
  132. package/lib/harness-types.ts +13 -0
  133. package/lib/types.ts +34 -50
  134. package/lib/workspace-config.ts +48 -0
  135. package/lib/workspace-layout.ts +2 -4
  136. package/package.json +4 -2
  137. package/server/README.md +29 -27
  138. package/server/api/harnesses.ts +5 -5
  139. package/server/api/index.ts +170 -68
  140. package/server/app-config.ts +2 -7
  141. package/server/applets/declarations.ts +6 -7
  142. package/server/applets/index.ts +15 -9
  143. package/server/applets/views.ts +2 -17
  144. package/server/applets/widgets.ts +3 -2
  145. package/server/cli/commands/config.ts +8 -20
  146. package/server/cli/commands/hermes.ts +2 -2
  147. package/server/cli/commands/init.ts +96 -64
  148. package/server/cli/commands/openclaw.ts +2 -2
  149. package/server/cli/commands/refresh.ts +10 -1
  150. package/server/cli/commands/remote.ts +228 -0
  151. package/server/cli/commands/skill.ts +4 -4
  152. package/server/cli/commands/tabs.ts +5 -12
  153. package/server/cli/control.ts +35 -4
  154. package/server/cli/index.ts +10 -6
  155. package/server/cli/remote-command.ts +77 -0
  156. package/server/cli/remote-control.ts +70 -0
  157. package/server/cli/remote-operations.ts +244 -0
  158. package/server/collab/config.ts +4 -8
  159. package/server/collab/manager.ts +5 -2
  160. package/server/collab/skill/index.ts +4 -50
  161. package/server/control.ts +38 -11
  162. package/server/harness/acp/session.ts +4 -4
  163. package/server/harness/auth.ts +26 -31
  164. package/server/harness/claude-code/index.ts +1 -1
  165. package/server/harness/codex/discovery.ts +1 -1
  166. package/server/harness/codex/session.ts +1 -1
  167. package/server/harness/detect.ts +14 -19
  168. package/server/harness/executable.ts +10 -10
  169. package/server/harness/hermes/NOTES.md +2 -2
  170. package/server/harness/hermes/index.ts +1 -1
  171. package/server/harness/install.ts +11 -11
  172. package/server/harness/openclaw/index.ts +1 -1
  173. package/server/harness/registry.ts +7 -6
  174. package/server/harness/types.ts +4 -4
  175. package/server/onboarding/jobs.ts +1 -1
  176. package/server/operations/commands.ts +46 -0
  177. package/server/operations/files.ts +148 -0
  178. package/server/operations/server.ts +206 -0
  179. package/server/remote/agent.ts +103 -0
  180. package/server/remote/client.ts +665 -0
  181. package/server/remote/workspace.ts +34 -0
  182. package/server/scratchpad/document.ts +32 -12
  183. package/server/scratchpad/executor.ts +16 -7
  184. package/server/sessions/config.ts +8 -5
  185. package/server/sessions/pending-views.ts +16 -0
  186. package/server/sessions/view-sessions.ts +10 -12
  187. package/server/skills/locations.ts +4 -4
  188. package/server/skills/template.ts +3 -2
  189. package/server/skills/update.ts +12 -12
  190. package/server/skills/version.ts +7 -7
  191. package/server/skills/workspace.ts +13 -13
  192. package/server/web.ts +12 -10
  193. package/server/workspace-state/file.ts +2 -0
  194. package/server/workspace-state/index.ts +0 -4
  195. package/server/workspaces/api.ts +28 -0
  196. package/server/workspaces/change-harness.ts +15 -26
  197. package/server/workspaces/import.ts +4 -4
  198. package/server/workspaces/init.ts +15 -13
  199. package/server/workspaces/layout.ts +60 -66
  200. package/server/workspaces/registry.ts +43 -18
  201. package/server/workspaces/scaffold.ts +1 -0
  202. package/server/workspaces/shared.ts +74 -0
  203. package/server/workspaces/tabs.ts +6 -12
  204. package/skill/SKILL.md +24 -4
  205. package/client/api/app-ui-keys.ts +0 -6
  206. package/client/features/chat/sessions/browser-tab-state.ts +0 -43
  207. package/client/features/collab/workspace-users-menu.tsx +0 -190
  208. package/client/features/dev/cloud-avatar-upload.tsx +0 -58
  209. package/client/features/dev/cloud-page.tsx +0 -363
  210. package/client/features/workspace/browser-tab-state.ts +0 -51
  211. package/client/features/workspace/layout-save.ts +0 -13
  212. package/client/features/workspace-members/api.ts +0 -20
  213. package/client/features/workspace-members/hooks.ts +0 -127
  214. package/client/features/workspace-members/keys.ts +0 -6
  215. package/client/features/workspace-members/store.ts +0 -123
  216. package/dist/chunk-00s35r33.js +0 -546
  217. package/dist/chunk-7rz6g7g7.js +0 -1
  218. package/dist/chunk-af2jyddf.js +0 -2
  219. package/dist/chunk-cekekc3f.css +0 -1
  220. package/dist/chunk-ep5vh16c.js +0 -75
  221. package/dist/chunk-s5s1vzdw.js +0 -2
  222. package/dist/chunk-svxhxfeq.js +0 -2
  223. package/dist/chunk-t0r0bds1.js +0 -1
  224. package/dist/chunk-vp2qzc0d.js +0 -1
  225. package/dist/chunk-wz5qv1bn.js +0 -2
  226. package/lib/workspace-types.ts +0 -13
  227. package/server/workspace-state/legacy-migration.ts +0 -79
  228. /package/client/features/collab/{presence-publisher.ts → presence/presence-publisher.ts} +0 -0
  229. /package/client/features/collab/{presence-target.ts → presence/presence-target.ts} +0 -0
  230. /package/client/features/collab/{store.ts → presence/store.ts} +0 -0
@@ -1,6 +1,5 @@
1
1
  import { existsSync } from 'node:fs'
2
2
 
3
- import { viewTabId } from '@/lib/workspace-tabs'
4
3
  import type { CompiledView, ViewConfig, ViewInfo, WorkspaceEntry } from '@/lib/types'
5
4
 
6
5
  import { syncAppletLogAfterBuild } from './log'
@@ -14,7 +13,6 @@ import {
14
13
  } from './'
15
14
  import { serializeWorkspaceBundle } from './bundle-queue'
16
15
  import { reloadModules } from './functions'
17
- import { loadLayout, saveLayout } from '../workspaces/layout'
18
16
  import { completeViewBuild, listPendingViews } from '../sessions/pending-views'
19
17
  import { archiveViewSessions } from '../sessions/archive'
20
18
  import type { WorkspaceRef } from '../workspace-state'
@@ -222,7 +220,7 @@ export async function handleBundleViews(
222
220
  const changedServerModules = new Set<string>()
223
221
  for (const r of results) {
224
222
  if (r.status === 'built') {
225
- publish({ type: 'view:updated', name: r.name, config: r.config ?? null })
223
+ publish({ type: 'view:updated', workspaceId, name: r.name, config: r.config ?? null })
226
224
  await completeViewBuild({ id: workspaceId, path: workspacePath }, r.name)
227
225
  for (const m of r.serverModules ?? []) changedServerModules.add(m)
228
226
  }
@@ -307,21 +305,8 @@ export async function deleteView(
307
305
  }
308
306
  reloadModules([`views/${viewId}`], workspacePath)
309
307
  await completeViewBuild(ws, viewId)
310
- const layout = await loadLayout(workspacePath)
311
- const tab = viewTabId(viewId)
312
- await saveLayout(
313
- {
314
- ...layout,
315
- tabs: {
316
- open: layout.tabs.open.filter(candidate => candidate !== tab),
317
- active: layout.tabs.active === tab ? 'overview' : layout.tabs.active
318
- }
319
- },
320
- workspacePath
321
- )
322
-
323
308
  publish({ type: 'view:deleted', workspaceId, name: viewId })
324
- publish({ type: 'workspace:updated' })
309
+ publish({ type: 'workspace:updated', workspaceId })
325
310
  await handleBundleViews(publish, workspaceId, workspacePath, false, viewId)
326
311
  })
327
312
  }
@@ -123,6 +123,7 @@ export async function listWidgets(workspacePath: string): Promise<Response> {
123
123
 
124
124
  export async function handleBundle(
125
125
  publish: (msg: unknown) => void,
126
+ workspaceId: string,
126
127
  workspacePath: string,
127
128
  force = false,
128
129
  target?: string
@@ -151,7 +152,7 @@ export async function handleBundle(
151
152
  const changedServerModules = new Set<string>()
152
153
  for (const r of results) {
153
154
  if (r.status === 'built') {
154
- publish({ type: 'widget:updated', name: r.name, config: r.config ?? null })
155
+ publish({ type: 'widget:updated', workspaceId, name: r.name, config: r.config ?? null })
155
156
  for (const m of r.serverModules ?? []) changedServerModules.add(m)
156
157
  }
157
158
  }
@@ -162,7 +163,7 @@ export async function handleBundle(
162
163
 
163
164
  if (layoutChanged) {
164
165
  const widgets = await getWidgetList(workspacePath)
165
- publish({ type: 'widget-layout:updated', widgets })
166
+ publish({ type: 'widget-layout:updated', workspaceId, widgets })
166
167
  }
167
168
 
168
169
  return results
@@ -1,8 +1,6 @@
1
1
  import { defineCommand } from 'citty'
2
2
  import { resolve } from 'path'
3
- import { CONTROL_URL } from '../../constants'
4
- import { staleSkillNotice } from '../../skills/version'
5
- import { exitControlUnreachable } from '../control'
3
+ import { sendControl } from '../control'
6
4
  import pc from '../pc'
7
5
 
8
6
  async function sendConfig(payload: {
@@ -12,27 +10,21 @@ async function sendConfig(payload: {
12
10
  clearName?: boolean
13
11
  clearIcon?: boolean
14
12
  }) {
15
- const notice = await staleSkillNotice(payload.path)
16
- const ws = new WebSocket(CONTROL_URL)
17
- ws.onopen = () => ws.send(JSON.stringify({ type: 'config', ...payload }))
18
- ws.onmessage = event => {
19
- const res = JSON.parse(String(event.data))
20
- if (res.error) {
21
- console.error('\n' + pc.red(pc.bold('Error:')) + ' ' + res.error + '\n')
22
- ws.close()
23
- process.exit(1)
24
- }
13
+ await sendControl(payload.path, { type: 'config', ...payload }, res => {
25
14
  console.log()
26
15
  if (res.ok) {
27
16
  if (res.clearedName) console.log(pc.green('✓') + ' Name reset to ' + pc.dim('(folder name)'))
28
- else if (res.name) console.log(pc.green('✓') + ' Name set to ' + pc.bold(res.name))
17
+ else if (res.name) console.log(pc.green('✓') + ' Name set to ' + pc.bold(String(res.name)))
29
18
  if (res.clearedIcon)
30
19
  console.log(pc.green('✓') + ' Icon reset to ' + pc.dim('default (provider)'))
31
20
  else if (res.icon) console.log(pc.green('✓') + ' Icon updated ' + pc.dim('(128×128 webp)'))
32
21
  } else {
33
22
  console.log(pc.bold('moi config') + ' — workspace identity\n')
34
23
  console.log(
35
- ' ' + pc.dim('name') + ' ' + (res.name ? pc.bold(res.name) : pc.dim('(folder name)'))
24
+ ' ' +
25
+ pc.dim('name') +
26
+ ' ' +
27
+ (res.name ? pc.bold(String(res.name)) : pc.dim('(folder name)'))
36
28
  )
37
29
  console.log(
38
30
  ' ' +
@@ -42,11 +34,7 @@ async function sendConfig(payload: {
42
34
  )
43
35
  }
44
36
  console.log()
45
- if (notice) console.log(pc.yellow(notice) + '\n')
46
- ws.close()
47
- process.exit(0)
48
- }
49
- ws.onerror = () => void exitControlUnreachable()
37
+ })
50
38
  }
51
39
 
52
40
  // A terse cheat sheet — one line per command — so an agent can grasp the
@@ -78,7 +78,7 @@ const hermesInit = defineCommand({
78
78
  skillsDir: skillsRoot,
79
79
  installLogPath
80
80
  } = await provisionWorkspace(target.path, 'hermes')
81
- if (scaffold !== 'exists') {
81
+ if (scaffold !== 'exists' && scaffold !== 'skipped') {
82
82
  if (scaffold === 'installing') {
83
83
  console.log('\n' + pc.dim(' Widget dependencies still installing in .moi/ (background)'))
84
84
  console.log(pc.dim(' Install log: ' + installLogPath))
@@ -93,7 +93,7 @@ const hermesInit = defineCommand({
93
93
  }
94
94
 
95
95
  const entry = await registerWorkspace(target.path, {
96
- type: 'hermes',
96
+ harness: 'hermes',
97
97
  name: target.name,
98
98
  agentId: target.agentId,
99
99
  isDefault: target.isDefault
@@ -1,8 +1,10 @@
1
- import type { WorkspaceType } from '@/lib/types'
1
+ import { initializeRemoteWorkspace } from '../../remote/workspace'
2
+ import { loadWorkspaceFileConfig } from '../../workspaces/layout'
3
+ import { parseRemoteWorkspaceAddress } from '@/lib/workspace-config'
4
+ import type { HarnessType, WorkspaceEntry } from '@/lib/types'
2
5
  import { defineCommand } from 'citty'
3
6
  import { existsSync } from 'node:fs'
4
7
  import { join, resolve } from 'path'
5
- import { installCollabSkill } from '../../collab/skill'
6
8
  import { PORT } from '../../constants'
7
9
  import type { DetectedAgent } from '../../harness/detect'
8
10
  import {
@@ -35,7 +37,7 @@ import { keyValue } from '../ui'
35
37
  async function resolveInitHarness(
36
38
  target: string,
37
39
  requested: string | undefined
38
- ): Promise<{ type: WorkspaceType; agent: DetectedAgent | null }> {
40
+ ): Promise<{ harness: HarnessType; agent: DetectedAgent | null }> {
39
41
  if (requested !== undefined) {
40
42
  const value = requested.trim()
41
43
  if (!isHarnessName(value)) {
@@ -62,7 +64,7 @@ async function resolveInitHarness(
62
64
  pc.dim(' to bind it once ' + harnessLabel[value] + ' can see the workspace.')
63
65
  )
64
66
  }
65
- return { type: value, agent }
67
+ return { harness: value, agent }
66
68
  }
67
69
 
68
70
  // A registered workspace has already answered this question, and may carry no
@@ -71,12 +73,12 @@ async function resolveInitHarness(
71
73
  // to refresh skills.
72
74
  const known = (await listWorkspaces()).find(e => e.path === target)
73
75
  if (known) {
74
- const type = known.type ?? 'claude-code'
76
+ const harness = known.harness ?? 'claude-code'
75
77
  console.log(
76
- '\n' + pc.dim(' Already registered — initializing for ') + pc.bold(harnessLabel[type])
78
+ '\n' + pc.dim(' Already registered — initializing for ') + pc.bold(harnessLabel[harness])
77
79
  )
78
80
  return {
79
- type,
81
+ harness,
80
82
  agent: known.agentId
81
83
  ? {
82
84
  agentId: known.agentId,
@@ -96,10 +98,10 @@ async function resolveInitHarness(
96
98
  ' Detected ' +
97
99
  detected.reason +
98
100
  ' — initializing for ' +
99
- pc.bold(harnessLabel[detected.type]) +
101
+ pc.bold(harnessLabel[detected.harness]) +
100
102
  '.'
101
103
  )
102
- return { type: detected.type, agent: detected.agent ?? null }
104
+ return { harness: detected.harness, agent: detected.agent ?? null }
103
105
  }
104
106
 
105
107
  console.error('\n' + pc.red('✗') + ' No agent harness detected in ' + pc.bold(target))
@@ -120,9 +122,11 @@ async function resolveInitHarness(
120
122
  export const init = defineCommand({
121
123
  meta: {
122
124
  name: 'init',
123
- description: 'Initialize workspace, copy skills and scaffold folder with widgets'
125
+ description: 'Initialize a local or remote workspace and install its skill'
124
126
  },
125
127
  args: {
128
+ remote: { type: 'string', description: 'Remote workspace address: ownerId:workspaceId' },
129
+ json: { type: 'boolean', description: 'Print remote initialization as JSON' },
126
130
  dir: {
127
131
  type: 'positional',
128
132
  default: '.',
@@ -137,11 +141,6 @@ export const init = defineCommand({
137
141
  default: false,
138
142
  description: 'Start the web server if not already running'
139
143
  },
140
- collab: {
141
- type: 'boolean',
142
- default: false,
143
- description: 'Include the optional collaboration guide and applet types'
144
- },
145
144
  id: {
146
145
  type: 'string',
147
146
  description:
@@ -149,13 +148,23 @@ export const init = defineCommand({
149
148
  }
150
149
  },
151
150
  async run({ args }) {
151
+ if (
152
+ (args.remote !== undefined && (args.harness || args.id)) ||
153
+ (args.json && (args.remote === undefined || args.web))
154
+ ) {
155
+ console.error(
156
+ '--remote cannot be combined with --harness or --id; --json requires --remote without --web'
157
+ )
158
+ process.exitCode = 1
159
+ return
160
+ }
152
161
  const requested = resolve(args.dir)
153
162
  // Locate the workspace root first: if invoked from inside a `.moi/` (or a
154
163
  // deeper accidental `.moi/.moi/…`), lift to the directory that owns it
155
164
  // instead of scaffolding a nested workspace. This is what stops the
156
165
  // `.moi/.moi` bug at the source.
157
166
  const target = liftToWorkspaceRoot(requested)
158
- if (target !== requested) {
167
+ if (target !== requested && !args.json) {
159
168
  console.log(
160
169
  '\n' +
161
170
  pc.yellow('◆') +
@@ -169,7 +178,7 @@ export const init = defineCommand({
169
178
  // Flag a stray nested `.moi/.moi` left by the old cwd bug — harmless but
170
179
  // confusing, and easy to remove.
171
180
  const stray = join(target, '.moi', '.moi')
172
- if (existsSync(stray)) {
181
+ if (existsSync(stray) && !args.json) {
173
182
  console.log(
174
183
  '\n' +
175
184
  pc.yellow('⚠') +
@@ -194,57 +203,80 @@ export const init = defineCommand({
194
203
  const projectRoot = PACKAGE_ROOT
195
204
  const isInteractive = process.stdout.isTTY
196
205
 
197
- // Which backend this workspace is for has to be settled before
198
- // provisioning: each harness reads skills from a different directory, and
199
- // agent-owned ones (OpenClaw, Hermes) need their agent metadata on the
200
- // registry entry — same as `moi <provider> init`.
201
- const { type, agent } = await resolveInitHarness(target, args.harness)
202
-
203
- // Provision: bundled skills + the `.moi/` bootstrap (widgets dir +
204
- // package.json + bun install). An existing `.moi/` is left untouched.
205
- console.log()
206
- const { scaffold, skillsDir, installLogPath } = await provisionWorkspace(target, type)
207
- if (args['collab']) {
208
- const { referencePath } = await installCollabSkill(target, type)
209
- console.log(pc.dim(' Collaboration guide installed to ' + referencePath))
210
- console.log(pc.dim(' Live presence is available in the cloud environment'))
211
- }
212
- if (scaffold !== 'exists') {
213
- if (scaffold === 'installing') {
214
- console.log(pc.dim(' Widget dependencies still installing in .moi/ (background)'))
215
- console.log(pc.dim(' Install log: ' + installLogPath))
216
- } else if (scaffold === 0) {
217
- console.log(pc.dim(' Installed widget dependencies in .moi/'))
218
- } else {
219
- console.warn(
220
- pc.yellow(` bun install failed (exit ${scaffold}) — run it manually in .moi/`)
206
+ let entry: Pick<WorkspaceEntry, 'id'>
207
+ if (args.remote !== undefined) {
208
+ try {
209
+ const result = await initializeRemoteWorkspace(
210
+ target,
211
+ parseRemoteWorkspaceAddress(args.remote)
221
212
  )
222
- console.warn(pc.dim(' Install log: ' + installLogPath))
213
+ if (args.json) {
214
+ console.log(JSON.stringify(result))
215
+ return
216
+ }
217
+ entry = result
218
+ console.log(pc.green('✓') + ' Initialized ' + pc.bold(result.path) + ' for ' + args.remote)
219
+ } catch (error) {
220
+ console.error(error instanceof Error ? error.message : 'Remote initialization failed')
221
+ process.exitCode = 1
222
+ return
223
223
  }
224
- }
224
+ } else {
225
+ const config = await loadWorkspaceFileConfig(target)
226
+ if (config.remote) {
227
+ console.error(
228
+ `This is a remote workspace — use moi init --remote ${config.remote.user_id}:${config.remote.workspace_id}`
229
+ )
230
+ process.exitCode = 1
231
+ return
232
+ }
233
+ // Which backend this workspace is for has to be settled before
234
+ // provisioning: each harness reads skills from a different directory, and
235
+ // agent-owned ones (OpenClaw, Hermes) need their agent metadata on the
236
+ // registry entry — same as `moi <provider> init`.
237
+ const { harness, agent } = await resolveInitHarness(target, args.harness)
225
238
 
226
- // Always register the workspace in the persistent registry
227
- const entry = await registerWorkspace(target, {
228
- ...(args.id ? { id: args.id } : {}),
229
- type,
230
- ...(agent
231
- ? {
232
- name: agent.name,
233
- agentId: agent.agentId,
234
- isDefault: agent.isDefault,
235
- lastRunAt: agent.lastRunAt
236
- }
237
- : {})
238
- })
239
+ // Provision: bundled skills + the `.moi/` bootstrap (widgets dir +
240
+ // package.json + bun install). An existing `.moi/` is left untouched.
241
+ console.log()
242
+ const { scaffold, skillsDir, installLogPath } = await provisionWorkspace(target, harness)
243
+ if (scaffold !== 'exists' && scaffold !== 'skipped') {
244
+ if (scaffold === 'installing') {
245
+ console.log(pc.dim(' Widget dependencies still installing in .moi/ (background)'))
246
+ console.log(pc.dim(' Install log: ' + installLogPath))
247
+ } else if (scaffold === 0) {
248
+ console.log(pc.dim(' Installed widget dependencies in .moi/'))
249
+ } else {
250
+ console.warn(
251
+ pc.yellow(` bun install failed (exit ${scaffold}) — run it manually in .moi/`)
252
+ )
253
+ console.warn(pc.dim(' Install log: ' + installLogPath))
254
+ }
255
+ }
239
256
 
240
- console.log(pc.green('✓') + ' Initialized ' + pc.bold(target) + pc.dim(' (' + type + ')'))
241
- console.log(
242
- ' Skills installed to ' +
243
- pc.dim(skillsDir) +
244
- ' — ask ' +
245
- (type === 'claude-code' ? 'Claude' : 'your agent') +
246
- ' to build a widget or a view to get started\n'
247
- )
257
+ // Always register the workspace in the persistent registry
258
+ entry = await registerWorkspace(target, {
259
+ ...(args.id ? { id: args.id } : {}),
260
+ harness: harness,
261
+ ...(agent
262
+ ? {
263
+ name: agent.name,
264
+ agentId: agent.agentId,
265
+ isDefault: agent.isDefault,
266
+ lastRunAt: agent.lastRunAt
267
+ }
268
+ : {})
269
+ })
270
+
271
+ console.log(pc.green('✓') + ' Initialized ' + pc.bold(target) + pc.dim(' (' + harness + ')'))
272
+ console.log(
273
+ ' Skills installed to ' +
274
+ pc.dim(skillsDir) +
275
+ ' — ask ' +
276
+ (harness === 'claude-code' ? 'Claude' : 'your agent') +
277
+ ' to build a widget or a view to get started\n'
278
+ )
279
+ }
248
280
 
249
281
  // If --web and server not running, start it (stay alive as wrapper)
250
282
  let running = await isServerRunning()
@@ -91,7 +91,7 @@ const openclawInit = defineCommand({
91
91
  skillsDir: skillsRoot,
92
92
  installLogPath
93
93
  } = await provisionWorkspace(target.path, 'openclaw')
94
- if (scaffold !== 'exists') {
94
+ if (scaffold !== 'exists' && scaffold !== 'skipped') {
95
95
  if (scaffold === 'installing') {
96
96
  console.log('\n' + pc.dim(' Widget dependencies still installing in .moi/ (background)'))
97
97
  console.log(pc.dim(' Install log: ' + installLogPath))
@@ -108,7 +108,7 @@ const openclawInit = defineCommand({
108
108
  // Register in the moi registry so the agent's workspace appears in the
109
109
  // UI workspace list. Mirrors what `moi init` does for Claude Code.
110
110
  const entry = await registerWorkspace(target.path, {
111
- type: 'openclaw',
111
+ harness: 'openclaw',
112
112
  name: target.name,
113
113
  agentId: target.agentId,
114
114
  isDefault: target.isDefault,
@@ -1,3 +1,4 @@
1
+ import { currentRemoteWorkspace } from '../../remote/workspace'
1
2
  import { defineCommand } from 'citty'
2
3
  import { CONTROL_URL } from '../../constants'
3
4
  import { staleSkillNotice } from '../../skills/version'
@@ -17,9 +18,17 @@ export const refresh = defineCommand({
17
18
  async run({ args }) {
18
19
  const only = readAppletSelector(args.only)
19
20
  const notice = await staleSkillNotice(process.cwd())
21
+ const linked = await currentRemoteWorkspace()
20
22
  const ws = new WebSocket(CONTROL_URL)
21
23
 
22
- ws.onopen = () => ws.send(JSON.stringify({ type: 'applets:refresh', only }))
24
+ ws.onopen = () =>
25
+ ws.send(
26
+ JSON.stringify({
27
+ type: 'applets:refresh',
28
+ only,
29
+ path: linked?.path ?? process.env.MOI_REMOTE_WORKSPACE
30
+ })
31
+ )
23
32
 
24
33
  ws.onmessage = event => {
25
34
  const data = JSON.parse(String(event.data))
@@ -0,0 +1,228 @@
1
+ import { AGENT_CLIENTS } from '../../remote/agent'
2
+ import { defineCommand } from 'citty'
3
+ import open from 'open'
4
+ import { remoteOperations } from '../remote-operations'
5
+ import { clearLine, cursorTo } from 'node:readline'
6
+ import { currentRemoteWorkspace } from '../../remote/workspace'
7
+ import { parseRemoteWorkspaceAddress } from '@/lib/workspace-config'
8
+ import pc from '../pc'
9
+ import {
10
+ login as signIn,
11
+ logout as signOut,
12
+ CloudSignInRequired,
13
+ remoteConfig,
14
+ remoteStatus,
15
+ invitations as listInvitations,
16
+ accept as acceptInvitation,
17
+ renameAgent,
18
+ leave as leaveWorkspace
19
+ } from '../../remote/client'
20
+
21
+ // Profile fields are user supplied; they must not control the terminal.
22
+ // oxlint-disable-next-line no-control-regex -- Deliberately remove terminal control characters.
23
+ const text = (value: string) => Bun.stripANSI(value).replace(/[\u0000-\u001f\u007f-\u009f]/g, '')
24
+
25
+ async function reportErrors(action: () => Promise<void>): Promise<void> {
26
+ try {
27
+ await action()
28
+ } catch (error) {
29
+ if (
30
+ error instanceof CloudSignInRequired ||
31
+ (error instanceof Error && error.message === 'Not signed in — run moi remote login')
32
+ ) {
33
+ console.error(`${pc.dim('›')} Signed out`)
34
+ console.error(
35
+ pc.dim('› Run ') + pc.cyan('moi remote login') + pc.dim(' to connect to Moi Cloud')
36
+ )
37
+ } else {
38
+ console.error(error instanceof Error ? error.message : 'Cloud request failed')
39
+ }
40
+ process.exitCode = 1
41
+ }
42
+ }
43
+
44
+ function waitingForLogin(): () => void {
45
+ const message = 'Waiting for authentication…'
46
+ if (!process.stderr.isTTY) {
47
+ console.error(message)
48
+ return () => {}
49
+ }
50
+ const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']
51
+ let frame = 0
52
+ const draw = () => {
53
+ cursorTo(process.stderr, 0)
54
+ process.stderr.write(pc.dim(`${frames[frame++ % frames.length]} ${message}`))
55
+ }
56
+ draw()
57
+ const timer = setInterval(draw, 80)
58
+ const stop = () => {
59
+ clearInterval(timer)
60
+ clearLine(process.stderr, 0)
61
+ cursorTo(process.stderr, 0)
62
+ process.removeListener('SIGINT', interrupt)
63
+ }
64
+ const interrupt = () => {
65
+ stop()
66
+ process.exit(130)
67
+ }
68
+ process.once('SIGINT', interrupt)
69
+ return stop
70
+ }
71
+
72
+ const login = defineCommand({
73
+ meta: { name: 'login', description: 'Sign in to Moi Cloud in your browser' },
74
+ args: {
75
+ browser: {
76
+ type: 'boolean',
77
+ default: true,
78
+ description: 'Open the login page (use --no-browser to print its URL only)'
79
+ }
80
+ },
81
+ async run({ args }) {
82
+ await reportErrors(async () => {
83
+ let stopWaiting = () => {}
84
+ try {
85
+ await signIn(async (url, code) => {
86
+ console.log(`\nVisit ${pc.bold(url)}\nCode: ${text(code)}\n`)
87
+ if (args.browser) await open(url).catch(() => {})
88
+ stopWaiting = waitingForLogin()
89
+ })
90
+ } finally {
91
+ stopWaiting()
92
+ }
93
+ console.log(`\n${pc.green('Congratulations!')} You are now signed in.\n`)
94
+ })
95
+ }
96
+ })
97
+
98
+ const logout = defineCommand({
99
+ meta: { name: 'logout', description: 'Sign out of Moi Cloud' },
100
+ args: { yes: { type: 'boolean', description: 'Confirm permanently revoking this agent login' } },
101
+ async run({ args }) {
102
+ await reportErrors(async () => {
103
+ await signOut(args.yes)
104
+ console.log(`${pc.green('✓')} Signed out`)
105
+ })
106
+ }
107
+ })
108
+
109
+ const jsonArg = { type: 'boolean' as const, description: 'Print JSON' }
110
+ const pathArg = {
111
+ type: 'string' as const,
112
+ description: 'Local workspace folder (defaults to current folder)'
113
+ }
114
+ const rename = defineCommand({
115
+ meta: { name: 'rename-agent', description: 'Change your agent name across workspaces' },
116
+ args: { name: { type: 'positional', required: true }, json: jsonArg },
117
+ async run({ args }) {
118
+ await reportErrors(async () => {
119
+ const result = await renameAgent(args.name)
120
+ console.log(args.json ? JSON.stringify(result) : `Agent renamed to ${text(result.name)}`)
121
+ })
122
+ }
123
+ })
124
+ const invitations = defineCommand({
125
+ meta: { name: 'invitations', description: 'List pending workspace invitations' },
126
+ args: { json: jsonArg },
127
+ async run({ args }) {
128
+ await reportErrors(async () => {
129
+ const result = await listInvitations()
130
+ if (args.json) console.log(JSON.stringify(result))
131
+ else if (!result.length) console.log('No pending invitations')
132
+ else
133
+ for (const invitation of result)
134
+ console.log(
135
+ `${text(invitation.id)} ${text(invitation.workspaceName)} — ${text(invitation.inviter.name)}`
136
+ )
137
+ })
138
+ }
139
+ })
140
+ const accept = defineCommand({
141
+ meta: { name: 'accept', description: 'Accept a workspace invitation as a human or agent' },
142
+ args: {
143
+ invite: { type: 'positional', required: true },
144
+ name: { type: 'string', description: 'Name for a new agent identity' },
145
+ client: { type: 'string', description: 'Agent client: ' + AGENT_CLIENTS.join(', ') },
146
+ json: jsonArg
147
+ },
148
+ async run({ args }) {
149
+ await reportErrors(async () => {
150
+ const result = await acceptInvitation(args.invite, args.name, args.client)
151
+ console.log(
152
+ args.json
153
+ ? JSON.stringify(result)
154
+ : `Invitation accepted\n\nmoi init --remote ${result.remote.user_id}:${result.remote.workspace_id}`
155
+ )
156
+ })
157
+ }
158
+ })
159
+ const leave = defineCommand({
160
+ meta: { name: 'leave', description: 'Leave a shared workspace; keep local files' },
161
+ args: {
162
+ workspace: {
163
+ type: 'positional',
164
+ required: false,
165
+ description: 'ownerId:workspaceId (defaults to current folder)'
166
+ },
167
+ path: pathArg,
168
+ json: jsonArg
169
+ },
170
+ async run({ args }) {
171
+ await reportErrors(async () => {
172
+ if (args.workspace !== undefined && args.path)
173
+ throw new Error('Use a workspace address or --path, not both')
174
+ const target =
175
+ args.workspace !== undefined
176
+ ? parseRemoteWorkspaceAddress(args.workspace)
177
+ : await currentRemoteWorkspace(args.path)
178
+ if (!target)
179
+ throw new Error('No remote workspace here — provide ownerId:workspaceId or --path')
180
+ const result = await leaveWorkspace(target.user_id, target.workspace_id)
181
+ console.log(args.json ? JSON.stringify(result) : 'Left the workspace; local files kept')
182
+ })
183
+ }
184
+ })
185
+ const remoteSubCommands = {
186
+ ...remoteOperations(reportErrors),
187
+ login,
188
+ logout,
189
+ 'rename-agent': rename,
190
+ invitations,
191
+ accept,
192
+ leave
193
+ }
194
+
195
+ export const remote = defineCommand({
196
+ meta: { name: 'remote', description: 'Show your cloud account and shared workspaces' },
197
+ args: { json: jsonArg, path: pathArg },
198
+ subCommands: remoteSubCommands,
199
+ async run({ args, rawArgs }) {
200
+ // citty also runs the parent after a subcommand; only bare `remote` shows status.
201
+ const sub = rawArgs.find(arg => !arg.startsWith('-'))
202
+ if (sub && Object.hasOwn(remoteSubCommands, sub)) return
203
+ await reportErrors(async () => {
204
+ const status = {
205
+ ...(await remoteStatus()),
206
+ currentWorkspace: await currentRemoteWorkspace(args.path)
207
+ }
208
+ if (args.json) {
209
+ console.log(JSON.stringify(status, null, 2))
210
+ return
211
+ }
212
+ console.log(
213
+ `\n${text(status.me.name || ('email' in status.me ? status.me.email : status.me.client))} <${text('email' in status.me ? status.me.email : status.me.client)}>\nAccount: ${text(status.me.id)}\nCloud: ${(await remoteConfig()).url}\n`
214
+ )
215
+ if (status.currentWorkspace)
216
+ console.log(
217
+ `Remote workspace: ${text(status.currentWorkspace.user_id)}:${text(status.currentWorkspace.workspace_id)}\n`
218
+ )
219
+ console.log('Shared workspaces')
220
+ if (!status.workspaces.length) console.log(' No shared workspaces')
221
+ for (const workspace of status.workspaces)
222
+ console.log(
223
+ ` ${text(workspace.owner.id)}:${text(workspace.id)} — ${text(workspace.owner.name || workspace.owner.email)} <${text(workspace.owner.email)}>`
224
+ )
225
+ console.log()
226
+ })
227
+ }
228
+ })