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
@@ -182,13 +182,24 @@ export async function serveApplet(
182
182
  if (HASHED_FILE_RE.test(file)) {
183
183
  cache = { 'Cache-Control': IMMUTABLE_CACHE }
184
184
  } else {
185
- const etag = `"${bunFile.size}-${Math.trunc(bunFile.lastModified)}"`
185
+ // The served representation also depends on the API-base substitution format.
186
+ const etag = `"${bunFile.size}-${Math.trunc(bunFile.lastModified)}-${Bun.hash(apiBase)}-url-base-v2"`
186
187
  cache = { ETag: etag, 'Cache-Control': 'private, no-cache' }
187
188
  if (ifNoneMatch === etag) return new Response(null, { status: 304, headers: cache })
188
189
  }
189
190
 
190
191
  if (CODE_FILE_RE.test(file)) {
191
- const swapped = (await bunFile.text()).replaceAll(APPLET_API_BASE_SENTINEL, apiBase)
192
+ const runtimeBase = `(new URL(import.meta.url).pathname.match(/^\\/api\\/workspaces\\/[^/]+/)?.[0] ?? ${JSON.stringify(apiBase)})`
193
+ const swapped = (await bunFile.text()).replace(
194
+ /(["'])([^"'\n]*%%MOI_APPLET_API_BASE%%[^"'\n]*)\1/g,
195
+ (_match, _quote: string, value: string) =>
196
+ '(' +
197
+ value
198
+ .split(APPLET_API_BASE_SENTINEL)
199
+ .map(part => JSON.stringify(part))
200
+ .join(' + ' + runtimeBase + ' + ') +
201
+ ')'
202
+ )
192
203
  return new Response(swapped, { headers: { 'Content-Type': JS_CONTENT_TYPE, ...cache } })
193
204
  }
194
205
  return new Response(bunFile, {
@@ -200,12 +211,6 @@ export async function serveApplet(
200
211
  // Pure helpers behind the applet/files/rpc HTTP routes, kept here (not web.ts) so
201
212
  // they're unit-testable without importing web.ts — which binds ports on load.
202
213
 
203
- // The API base a served bundle's sentinel is rewritten to. RPC and workspace
204
- // file addresses resolved by `resolveUrl()` use this prefix.
205
- export function apiBaseFor(id: string): string {
206
- return `/api/workspaces/${id}`
207
- }
208
-
209
214
  // The entry's real name in the bundle dir (`.build/<kind>/<name>/index.js`).
210
215
  const ENTRY_DISK_FILE = 'index.js'
211
216
 
@@ -241,7 +246,8 @@ export function parseAppletTail(
241
246
  id: string,
242
247
  segment: 'widgets' | 'views'
243
248
  ): { name: string; file: string } {
244
- const tail = new URL(url).pathname.split(`/api/workspaces/${id}/${segment}/`)[1] ?? ''
249
+ const tail =
250
+ new URL(url).pathname.split(`/workspaces/${encodeURIComponent(id)}/${segment}/`)[1] ?? ''
245
251
  const slash = tail.indexOf('/')
246
252
  if (slash === -1) return { name: tail.replace(/\.js$/, ''), file: ENTRY_DISK_FILE }
247
253
  const file = tail.slice(slash + 1)
@@ -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,4 +1,7 @@
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'
@@ -21,7 +24,7 @@ import {
21
24
  import { serverCwd } from '../../server-cwd'
22
25
  import { superviseServerUpdates } from '../../update'
23
26
  import { PACKAGE_ROOT } from '../../version'
24
- import { provisionWorkspace } from '../../workspaces/init'
27
+ import { provisionWorkspace, skillsDirFor } from '../../workspaces/init'
25
28
  import { isServerRunning, registerViaControl, waitForServer } from '../control'
26
29
  import pc from '../pc'
27
30
  import { spawnServer } from '../server'
@@ -34,7 +37,7 @@ import { keyValue } from '../ui'
34
37
  async function resolveInitHarness(
35
38
  target: string,
36
39
  requested: string | undefined
37
- ): Promise<{ type: WorkspaceType; agent: DetectedAgent | null }> {
40
+ ): Promise<{ harness: HarnessType; agent: DetectedAgent | null }> {
38
41
  if (requested !== undefined) {
39
42
  const value = requested.trim()
40
43
  if (!isHarnessName(value)) {
@@ -61,7 +64,7 @@ async function resolveInitHarness(
61
64
  pc.dim(' to bind it once ' + harnessLabel[value] + ' can see the workspace.')
62
65
  )
63
66
  }
64
- return { type: value, agent }
67
+ return { harness: value, agent }
65
68
  }
66
69
 
67
70
  // A registered workspace has already answered this question, and may carry no
@@ -70,12 +73,12 @@ async function resolveInitHarness(
70
73
  // to refresh skills.
71
74
  const known = (await listWorkspaces()).find(e => e.path === target)
72
75
  if (known) {
73
- const type = known.type ?? 'claude-code'
76
+ const harness = known.harness ?? 'claude-code'
74
77
  console.log(
75
- '\n' + pc.dim(' Already registered — initializing for ') + pc.bold(harnessLabel[type])
78
+ '\n' + pc.dim(' Already registered — initializing for ') + pc.bold(harnessLabel[harness])
76
79
  )
77
80
  return {
78
- type,
81
+ harness,
79
82
  agent: known.agentId
80
83
  ? {
81
84
  agentId: known.agentId,
@@ -95,10 +98,10 @@ async function resolveInitHarness(
95
98
  ' Detected ' +
96
99
  detected.reason +
97
100
  ' — initializing for ' +
98
- pc.bold(harnessLabel[detected.type]) +
101
+ pc.bold(harnessLabel[detected.harness]) +
99
102
  '.'
100
103
  )
101
- return { type: detected.type, agent: detected.agent ?? null }
104
+ return { harness: detected.harness, agent: detected.agent ?? null }
102
105
  }
103
106
 
104
107
  console.error('\n' + pc.red('✗') + ' No agent harness detected in ' + pc.bold(target))
@@ -119,9 +122,11 @@ async function resolveInitHarness(
119
122
  export const init = defineCommand({
120
123
  meta: {
121
124
  name: 'init',
122
- description: 'Initialize workspace, copy skills and scaffold folder with widgets'
125
+ description: 'Initialize a local or remote workspace and install its skill'
123
126
  },
124
127
  args: {
128
+ remote: { type: 'string', description: 'Remote workspace address: ownerId:workspaceId' },
129
+ json: { type: 'boolean', description: 'Print remote initialization as JSON' },
125
130
  dir: {
126
131
  type: 'positional',
127
132
  default: '.',
@@ -143,13 +148,23 @@ export const init = defineCommand({
143
148
  }
144
149
  },
145
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
+ }
146
161
  const requested = resolve(args.dir)
147
162
  // Locate the workspace root first: if invoked from inside a `.moi/` (or a
148
163
  // deeper accidental `.moi/.moi/…`), lift to the directory that owns it
149
164
  // instead of scaffolding a nested workspace. This is what stops the
150
165
  // `.moi/.moi` bug at the source.
151
166
  const target = liftToWorkspaceRoot(requested)
152
- if (target !== requested) {
167
+ if (target !== requested && !args.json) {
153
168
  console.log(
154
169
  '\n' +
155
170
  pc.yellow('◆') +
@@ -163,7 +178,7 @@ export const init = defineCommand({
163
178
  // Flag a stray nested `.moi/.moi` left by the old cwd bug — harmless but
164
179
  // confusing, and easy to remove.
165
180
  const stray = join(target, '.moi', '.moi')
166
- if (existsSync(stray)) {
181
+ if (existsSync(stray) && !args.json) {
167
182
  console.log(
168
183
  '\n' +
169
184
  pc.yellow('⚠') +
@@ -188,52 +203,85 @@ export const init = defineCommand({
188
203
  const projectRoot = PACKAGE_ROOT
189
204
  const isInteractive = process.stdout.isTTY
190
205
 
191
- // Which backend this workspace is for has to be settled before
192
- // provisioning: each harness reads skills from a different directory, and
193
- // agent-owned ones (OpenClaw, Hermes) need their agent metadata on the
194
- // registry entry — same as `moi <provider> init`.
195
- const { type, agent } = await resolveInitHarness(target, args.harness)
196
-
197
- // Provision: bundled skills + the `.moi/` bootstrap (widgets dir +
198
- // package.json + bun install). An existing `.moi/` is left untouched.
199
- console.log()
200
- const { scaffold, skillsDir, installLogPath } = await provisionWorkspace(target, type)
201
- if (scaffold !== 'exists') {
202
- if (scaffold === 'installing') {
203
- console.log(pc.dim(' Widget dependencies still installing in .moi/ (background)'))
204
- console.log(pc.dim(' Install log: ' + installLogPath))
205
- } else if (scaffold === 0) {
206
- console.log(pc.dim(' Installed widget dependencies in .moi/'))
207
- } else {
208
- console.warn(
209
- 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)
210
212
  )
211
- 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('✓') + ' Linked ' + pc.bold(result.path) + ' to ' + args.remote)
219
+ console.log('\nNext:')
220
+ console.log(' 1. Read ' + join(skillsDirFor(result.path), 'moi-workspace', 'SKILL.md'))
221
+ console.log(' 2. Run commands from ' + result.path)
222
+ console.log(' 3. Run `moi remote` for available commands\n')
223
+ if (!args.web) return
224
+ } catch (error) {
225
+ console.error(error instanceof Error ? error.message : 'Remote initialization failed')
226
+ process.exitCode = 1
227
+ return
212
228
  }
213
- }
229
+ } else {
230
+ const config = await loadWorkspaceFileConfig(target)
231
+ if (config.remote) {
232
+ console.error(
233
+ `This is a remote workspace — use moi init --remote ${config.remote.user_id}:${config.remote.workspace_id}`
234
+ )
235
+ process.exitCode = 1
236
+ return
237
+ }
238
+ // Which backend this workspace is for has to be settled before
239
+ // provisioning: each harness reads skills from a different directory, and
240
+ // agent-owned ones (OpenClaw, Hermes) need their agent metadata on the
241
+ // registry entry — same as `moi <provider> init`.
242
+ const { harness, agent } = await resolveInitHarness(target, args.harness)
214
243
 
215
- // Always register the workspace in the persistent registry
216
- const entry = await registerWorkspace(target, {
217
- ...(args.id ? { id: args.id } : {}),
218
- type,
219
- ...(agent
220
- ? {
221
- name: agent.name,
222
- agentId: agent.agentId,
223
- isDefault: agent.isDefault,
224
- lastRunAt: agent.lastRunAt
225
- }
226
- : {})
227
- })
244
+ // Provision: bundled skills + the `.moi/` bootstrap (widgets dir +
245
+ // package.json + bun install). An existing `.moi/` is left untouched.
246
+ console.log()
247
+ const { scaffold, skillsDir, installLogPath } = await provisionWorkspace(target, harness)
248
+ if (scaffold !== 'exists' && scaffold !== 'skipped') {
249
+ if (scaffold === 'installing') {
250
+ console.log(pc.dim(' Widget dependencies still installing in .moi/ (background)'))
251
+ console.log(pc.dim(' Install log: ' + installLogPath))
252
+ } else if (scaffold === 0) {
253
+ console.log(pc.dim(' Installed widget dependencies in .moi/'))
254
+ } else {
255
+ console.warn(
256
+ pc.yellow(` bun install failed (exit ${scaffold}) — run it manually in .moi/`)
257
+ )
258
+ console.warn(pc.dim(' Install log: ' + installLogPath))
259
+ }
260
+ }
228
261
 
229
- console.log(pc.green('✓') + ' Initialized ' + pc.bold(target) + pc.dim(' (' + type + ')'))
230
- console.log(
231
- ' Skills installed to ' +
232
- pc.dim(skillsDir) +
233
- ' — ask ' +
234
- (type === 'claude-code' ? 'Claude' : 'your agent') +
235
- ' to build a widget or a view to get started\n'
236
- )
262
+ // Always register the workspace in the persistent registry
263
+ entry = await registerWorkspace(target, {
264
+ ...(args.id ? { id: args.id } : {}),
265
+ harness: harness,
266
+ ...(agent
267
+ ? {
268
+ name: agent.name,
269
+ agentId: agent.agentId,
270
+ isDefault: agent.isDefault,
271
+ lastRunAt: agent.lastRunAt
272
+ }
273
+ : {})
274
+ })
275
+
276
+ console.log(pc.green('✓') + ' Initialized ' + pc.bold(target) + pc.dim(' (' + harness + ')'))
277
+ console.log(
278
+ ' Skills installed to ' +
279
+ pc.dim(skillsDir) +
280
+ ' — ask ' +
281
+ (harness === 'claude-code' ? 'Claude' : 'your agent') +
282
+ ' to build a widget or a view to get started\n'
283
+ )
284
+ }
237
285
 
238
286
  // If --web and server not running, start it (stay alive as wrapper)
239
287
  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))