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
@@ -0,0 +1,247 @@
1
+ import { defineCommand } from 'citty'
2
+ import { mkdir, rename, rm } from 'node:fs/promises'
3
+ import { basename, dirname, resolve } from 'node:path'
4
+ import { z } from 'zod'
5
+ import { remoteRequest } from '../remote/client'
6
+ import { cloudRoutes } from '../remote/routes'
7
+ import { currentRemoteWorkspace } from '../remote/workspace'
8
+ import { resolveWorkspaceRoot } from '../skills/version'
9
+ import { getLayoutPath, loadWorkspaceFileConfig } from '../workspaces/layout'
10
+
11
+ const json = { type: 'boolean' as const, description: 'Print JSON result' }
12
+ const commandResult = z.object({
13
+ exitCode: z.number().int(),
14
+ stdout: z.string(),
15
+ stderr: z.string()
16
+ })
17
+ async function printCommandResult(response: Response, json = false) {
18
+ const result = commandResult.parse(await response.json())
19
+ if (json) console.log(JSON.stringify(result))
20
+ else {
21
+ process.stdout.write(result.stdout)
22
+ process.stderr.write(result.stderr)
23
+ }
24
+ process.exitCode = result.exitCode < 0 ? 1 : result.exitCode
25
+ }
26
+
27
+ /** Ordinary workspace commands can use the folder's remote link automatically. */
28
+ export async function runLinkedWorkspaceCommand(command: string, args: string[], folder: string) {
29
+ const linked = await currentRemoteWorkspace(folder)
30
+ if (!linked) return false
31
+ const response = await remoteRequest(cloudRoutes.commands.path(linked), {
32
+ method: 'POST',
33
+ body: JSON.stringify({ command, args }),
34
+ contentType: 'application/json'
35
+ })
36
+ await printCommandResult(response)
37
+ return true
38
+ }
39
+ const execEvent = z.discriminatedUnion('type', [
40
+ z.object({ type: z.literal('stdout'), data: z.string() }),
41
+ z.object({ type: z.literal('stderr'), data: z.string() }),
42
+ z.object({ type: z.literal('exit'), code: z.number().int() })
43
+ ])
44
+ async function target() {
45
+ const current = await currentRemoteWorkspace()
46
+ if (!current) {
47
+ const root = await resolveWorkspaceRoot(process.cwd())
48
+ const config = await loadWorkspaceFileConfig(root)
49
+ let message = 'This folder is not linked to a remote workspace'
50
+ if (!config.remote && (await Bun.file(getLayoutPath(root)).exists())) {
51
+ const name = Bun.stripANSI(config.name || basename(root)).replace(
52
+ // oxlint-disable-next-line no-control-regex -- Workspace names must not control the terminal.
53
+ /[\u0000-\u001f\u007f-\u009f]/g,
54
+ ''
55
+ )
56
+ message += `\nIt is an existing local workspace: ${name}`
57
+ }
58
+ throw new Error(message)
59
+ }
60
+ type Options = Parameters<typeof remoteRequest>[1]
61
+ return {
62
+ file: (file: string, options?: Options) =>
63
+ remoteRequest(cloudRoutes.files.path(current, file), options),
64
+ exec: (options?: Options) => remoteRequest(cloudRoutes.exec.path(current), options)
65
+ }
66
+ }
67
+ async function stdin() {
68
+ if (process.stdin.isTTY) throw new Error('Supply content or pipe it on stdin')
69
+ return Bun.stdin.text()
70
+ }
71
+
72
+ export function remoteOperations(report: (action: () => Promise<void>) => Promise<void>) {
73
+ const read = defineCommand({
74
+ meta: { name: 'read', description: 'Read a remote workspace file to stdout' },
75
+ args: { file: { type: 'positional', required: true } },
76
+ run: ({ args }) =>
77
+ report(async () => {
78
+ const response = await (await target()).file(args.file)
79
+ if (response.body)
80
+ for await (const chunk of response.body) await Bun.write(Bun.stdout, chunk)
81
+ })
82
+ })
83
+ const write = defineCommand({
84
+ meta: { name: 'write', description: 'Write a remote file; content argument or stdin' },
85
+ args: {
86
+ file: { type: 'positional', required: true },
87
+ content: { type: 'positional', required: false },
88
+ json
89
+ },
90
+ run: ({ args }) =>
91
+ report(async () => {
92
+ const response = await (
93
+ await target()
94
+ ).file(args.file, {
95
+ method: 'PUT',
96
+ body: args.content ?? (await stdin()),
97
+ contentType: 'application/octet-stream'
98
+ })
99
+ console.log(args.json ? JSON.stringify(await response.json()) : `Wrote ${args.file}`)
100
+ })
101
+ })
102
+ const patch = defineCommand({
103
+ meta: {
104
+ name: 'patch',
105
+ description: 'Apply a unified diff to a remote file (stdin or --patch-file)'
106
+ },
107
+ args: {
108
+ file: { type: 'positional', required: true },
109
+ 'patch-file': { type: 'string' },
110
+ json
111
+ },
112
+ run: ({ args }) =>
113
+ report(async () => {
114
+ const diff = args['patch-file']
115
+ ? await Bun.file(resolve(args['patch-file'])).text()
116
+ : await stdin()
117
+ const response = await (
118
+ await target()
119
+ ).file(args.file, {
120
+ method: 'PATCH',
121
+ body: JSON.stringify({ patch: diff }),
122
+ contentType: 'application/json'
123
+ })
124
+ console.log(args.json ? JSON.stringify(await response.json()) : `Patched ${args.file}`)
125
+ })
126
+ })
127
+ const upload = defineCommand({
128
+ meta: { name: 'file-upload', description: 'Upload a local file to a remote workspace path' },
129
+ args: {
130
+ source: { type: 'positional', required: true },
131
+ destination: { type: 'positional', required: true },
132
+ json
133
+ },
134
+ run: ({ args }) =>
135
+ report(async () => {
136
+ const file = Bun.file(resolve(args.source))
137
+ if (!(await file.exists())) throw new Error('Local source file not found')
138
+ const response = await (
139
+ await target()
140
+ ).file(args.destination, {
141
+ method: 'PUT',
142
+ body: file,
143
+ contentType: 'application/octet-stream'
144
+ })
145
+ console.log(
146
+ args.json ? JSON.stringify(await response.json()) : `Uploaded ${args.destination}`
147
+ )
148
+ })
149
+ })
150
+ const download = defineCommand({
151
+ meta: {
152
+ name: 'file-download',
153
+ description: 'Download a remote workspace file to a local path'
154
+ },
155
+ args: {
156
+ source: { type: 'positional', required: true },
157
+ destination: { type: 'positional', required: true },
158
+ json
159
+ },
160
+ run: ({ args }) =>
161
+ report(async () => {
162
+ const response = await (await target()).file(args.source)
163
+ const destination = resolve(args.destination),
164
+ temporary = `${destination}.${crypto.randomUUID()}.tmp`
165
+ await mkdir(dirname(destination), { recursive: true })
166
+ try {
167
+ await Bun.write(temporary, response)
168
+ await rename(temporary, destination)
169
+ } finally {
170
+ await rm(temporary, { force: true })
171
+ }
172
+ console.log(
173
+ args.json
174
+ ? JSON.stringify({ ok: true, path: destination })
175
+ : `Downloaded ${args.destination}`
176
+ )
177
+ })
178
+ })
179
+ const exec = defineCommand({
180
+ meta: {
181
+ name: 'exec',
182
+ description: 'Run a shell command on the remote host, in this workspace'
183
+ },
184
+ args: { command: { type: 'positional', required: true }, json },
185
+ run: ({ args }) =>
186
+ report(async () => {
187
+ const controller = new AbortController()
188
+ const request = await target()
189
+ const id = crypto.randomUUID()
190
+ let cancellation: Promise<void> | undefined
191
+ const interrupt = () => {
192
+ cancellation ??= request
193
+ .exec({
194
+ method: 'POST',
195
+ body: JSON.stringify({ cancel: id }),
196
+ contentType: 'application/json',
197
+ signal: AbortSignal.timeout(10_000)
198
+ })
199
+ .then(async response => {
200
+ await response.body?.cancel()
201
+ })
202
+ .catch(() => {
203
+ console.error('Could not confirm the remote command stopped')
204
+ })
205
+ .finally(() => controller.abort())
206
+ }
207
+ process.once('SIGINT', interrupt)
208
+ try {
209
+ const response = await request.exec({
210
+ method: 'POST',
211
+ body: JSON.stringify({ command: args.command, id }),
212
+ contentType: 'application/json',
213
+ signal: controller.signal
214
+ })
215
+ if (!response.body) throw new Error('Remote execution returned no stream')
216
+ let pending = '',
217
+ exit: number | undefined
218
+ const decoder = new TextDecoder()
219
+ for await (const chunk of response.body) {
220
+ pending += decoder.decode(chunk, { stream: true })
221
+ let end: number
222
+ while ((end = pending.indexOf('\n')) !== -1) {
223
+ const line = pending.slice(0, end)
224
+ pending = pending.slice(end + 1)
225
+ const event = execEvent.parse(JSON.parse(line))
226
+ if (args.json) console.log(JSON.stringify(event))
227
+ if (event.type === 'exit') exit = event.code
228
+ else if (!args.json)
229
+ (event.type === 'stdout' ? process.stdout : process.stderr).write(event.data)
230
+ }
231
+ }
232
+ if (exit === undefined || pending)
233
+ throw new Error(
234
+ 'Remote execution disconnected before the exit code; command may still have run'
235
+ )
236
+ process.exitCode = exit < 0 ? 1 : exit
237
+ } catch (error) {
238
+ if (!cancellation) throw error
239
+ } finally {
240
+ process.removeListener('SIGINT', interrupt)
241
+ await cancellation
242
+ if (cancellation) process.exitCode = 130
243
+ }
244
+ })
245
+ })
246
+ return { read, write, patch, exec, 'file-upload': upload, 'file-download': download }
247
+ }
@@ -1,13 +1,13 @@
1
- import type { WorkspaceType } from '@/lib/types'
1
+ import type { HarnessType } from '@/lib/types'
2
2
 
3
3
  import { getAppConfig } from '../app-config'
4
4
  import { collabSkillReferencePath } from './skill'
5
5
 
6
6
  export async function getCollabReferencePath(
7
7
  workspacePath: string,
8
- type?: WorkspaceType
8
+ harness?: HarnessType
9
9
  ): Promise<string | undefined> {
10
10
  if (getAppConfig().environment !== 'cloud') return undefined
11
- const referencePath = collabSkillReferencePath(workspacePath, type)
11
+ const referencePath = collabSkillReferencePath(workspacePath, harness)
12
12
  return (await Bun.file(referencePath).exists()) ? referencePath : undefined
13
13
  }
@@ -1,7 +1,7 @@
1
1
  import { join } from 'node:path'
2
- import type { WorkspaceType } from '@/lib/types'
2
+ import type { HarnessType } from '@/lib/types'
3
3
  import { skillsDirFor } from '../../workspaces/init'
4
4
 
5
- export function collabSkillReferencePath(workspacePath: string, type?: WorkspaceType): string {
6
- return join(skillsDirFor(workspacePath, type), 'moi-workspace', 'references', 'COLLAB.md')
5
+ export function collabSkillReferencePath(workspacePath: string, harness?: HarnessType): string {
6
+ return join(skillsDirFor(workspacePath, harness), 'moi-workspace', 'references', 'COLLAB.md')
7
7
  }
package/server/control.ts CHANGED
@@ -27,7 +27,11 @@ import { assembleTabRows, assertNavigableTab } from './workspaces/tabs'
27
27
  import { applyThemeUpdate } from './workspaces/theme'
28
28
  import { handleBundle } from './applets/widgets'
29
29
  import { getWorkspaceViews, handleBundleViews } from './applets/views'
30
- import { updatePendingView, PendingViewError } from './sessions/pending-views'
30
+ import {
31
+ completeRemoteViewBuilds,
32
+ updatePendingView,
33
+ PendingViewError
34
+ } from './sessions/pending-views'
31
35
  import { createViewFromSession, ViewStartupError } from './sessions/view-sessions'
32
36
  import {
33
37
  getWorkspaceConfig,
@@ -35,6 +39,7 @@ import {
35
39
  type WorkspaceConfigPatch
36
40
  } from './workspaces/config'
37
41
  import { VERSION } from './version'
42
+ import { createRemoteBroker } from './remote/broker'
38
43
  import {
39
44
  getWorkspaceEnvView,
40
45
  parseEnvUpdate,
@@ -45,6 +50,8 @@ import {
45
50
 
46
51
  type ControlSocket = { send(data: string): void }
47
52
 
53
+ const remoteBroker = createRemoteBroker()
54
+
48
55
  // Resolve a control request's `path` to the registered workspace that contains
49
56
  // it — the entry itself or its nearest registered ancestor — so every
50
57
  // workspace-scoped command (bundle/theme/config/scratch) works from `.moi/` or
@@ -76,7 +83,12 @@ async function resolveWorkspace(
76
83
  export const control = Bun.serve({
77
84
  port: CONTROL_PORT,
78
85
  hostname: CONTROL_HOST,
79
- fetch(req, server) {
86
+ async fetch(req, server) {
87
+ // Cloud requests from callers with no login of their own (remote/broker.ts).
88
+ // An exec stream can stay quiet for longer than the default idle timeout.
89
+ if (new URL(req.url).pathname.startsWith('/remote/')) server.timeout(req, 0)
90
+ const brokered = await remoteBroker(req)
91
+ if (brokered) return brokered
80
92
  return server.upgrade(req)
81
93
  ? new Response(null, { status: 101 })
82
94
  : new Response('Control WebSocket only', { status: 426 })
@@ -138,7 +150,13 @@ export const control = Bun.serve({
138
150
  }[] = []
139
151
  await serializeWorkspaceBundle(workspacePath, async () => {
140
152
  if (only?.segment !== 'views') {
141
- for (const r of await handleBundle(publishEvent, workspacePath, force, only?.id)) {
153
+ for (const r of await handleBundle(
154
+ publishEvent,
155
+ match.id,
156
+ workspacePath,
157
+ force,
158
+ only?.id
159
+ )) {
142
160
  if (!only?.id || r.name === only.id) {
143
161
  results.push({ kind: 'widget', name: r.name, status: r.status, error: r.error })
144
162
  }
@@ -319,11 +337,8 @@ export const control = Bun.serve({
319
337
  if (data.type === 'tabs') {
320
338
  const match = await resolveWorkspace(ws, data.path)
321
339
  if (!match) return
322
- const [layout, views] = await Promise.all([
323
- loadLayout(match.path),
324
- getWorkspaceViews(match)
325
- ])
326
- ws.send(JSON.stringify({ ok: true, tabs: assembleTabRows(views, layout.tabs.active) }))
340
+ const views = await getWorkspaceViews(match)
341
+ ws.send(JSON.stringify({ ok: true, tabs: assembleTabRows(views) }))
327
342
  return
328
343
  }
329
344
 
@@ -336,7 +351,9 @@ export const control = Bun.serve({
336
351
  if (!href.startsWith('moi:/') || href.startsWith('moi:/files/'))
337
352
  throw new Error('Navigation needs a workspace page address')
338
353
  const tab = href.slice(5).split('?', 1)[0]
339
- if (isWorkspaceTabId(tab)) assertNavigableTab(tab, await getWorkspaceViews(match))
354
+ // A linked folder's views live on the owner; the browser checks the tab itself.
355
+ if (isWorkspaceTabId(tab) && !match.remote)
356
+ assertNavigableTab(tab, await getWorkspaceViews(match))
340
357
  await navigationRelay.navigate(match.id, href)
341
358
  ws.send(JSON.stringify({ ok: true, href }))
342
359
  } catch (error) {
@@ -349,24 +366,42 @@ export const control = Bun.serve({
349
366
  return
350
367
  }
351
368
 
369
+ // Sent by the CLI after a build on a remote workspace's owner.
370
+ if (data.type === 'views:reconcile') {
371
+ const match = await resolveWorkspace(ws, data.path)
372
+ if (!match) return
373
+ await completeRemoteViewBuilds(match)
374
+ ws.send(JSON.stringify({ ok: true }))
375
+ return
376
+ }
377
+
352
378
  // Tell every connected applet to re-import its module (cache-bust) and
353
379
  // re-run its data fetches. No rebuild, no page reload — `useApplet`
354
380
  // handles `applets:refresh` like `*:updated` (invalidate + reload).
355
381
  // `only` narrows to one kind or applet; default is both kinds.
356
382
  // `widget:refresh` is the pre-filter message name older CLIs send.
357
383
  if (data.type === 'applets:refresh' || data.type === 'widget:refresh') {
384
+ const match = data.path ? await resolveWorkspace(ws, data.path) : undefined
385
+ if (data.path && !match) return
386
+ const scope = match ? { workspaceId: match.id } : {}
358
387
  const only = typeof data.only === 'string' ? parseAppletSelector(data.only) : undefined
359
388
  if (data.only && !only) {
360
389
  ws.send(JSON.stringify({ error: `Invalid applet selector "${data.only}"` }))
361
390
  return
362
391
  }
392
+ // No `workspaceId`: `moi refresh` names no workspace, so every open one reloads.
363
393
  if (only?.id) {
364
394
  publishEvent({
365
395
  type: only.segment === 'widgets' ? 'widget:updated' : 'view:updated',
396
+ ...scope,
366
397
  name: only.id
367
398
  })
368
399
  } else {
369
- publishEvent({ type: 'applets:refresh', ...(data.only ? { only: data.only } : {}) })
400
+ publishEvent({
401
+ type: 'applets:refresh',
402
+ ...scope,
403
+ ...(data.only ? { only: data.only } : {})
404
+ })
370
405
  }
371
406
  ws.send(JSON.stringify({ ok: true }))
372
407
  return
@@ -437,7 +472,7 @@ export const control = Bun.serve({
437
472
  }
438
473
 
439
474
  await saveLayout({ ...layout, theme: result.theme }, workspacePath)
440
- publishEvent({ type: 'theme:updated' })
475
+ publishEvent({ type: 'theme:updated', workspaceId: match.id })
441
476
  ws.send(JSON.stringify({ ok: true, ...result.applied }))
442
477
  return
443
478
  }
@@ -480,7 +515,7 @@ export const control = Bun.serve({
480
515
  }
481
516
 
482
517
  await setWorkspaceConfig(workspacePath, patch)
483
- publishEvent({ type: 'workspace:updated' })
518
+ publishEvent({ type: 'workspace:updated', workspaceId: match.id })
484
519
  ws.send(
485
520
  JSON.stringify({
486
521
  ok: true,
@@ -26,7 +26,7 @@ import {
26
26
  } from '../../sessions/attachment-message'
27
27
  import { type MoiContext, appendMoiContext, renderMoiContext } from '@/lib/moi-context'
28
28
  import { type Part, applyEvent, emptyViewState } from '@/lib/format'
29
- import type { Model, SessionActivity, StreamEvent, ViewState, WorkspaceType } from '@/lib/types'
29
+ import type { Model, SessionActivity, StreamEvent, ViewState, HarnessType } from '@/lib/types'
30
30
 
31
31
  import {
32
32
  type AcpProviderId,
@@ -62,7 +62,7 @@ export type AcpSpawnContext = {
62
62
  }
63
63
 
64
64
  export type AcpProviderConfig = {
65
- id: WorkspaceType
65
+ id: HarnessType
66
66
  provider: AcpProviderId
67
67
  spawn: (ctx: AcpSpawnContext) => Promise<AcpSpawnSpec>
68
68
  // Session mode that disables approval prompts, matching moi's
@@ -363,9 +363,9 @@ function handleNotification(
363
363
  // Force a fresh probe so the composer's banner flips right away.
364
364
  function refreshAvailability(
365
365
  rec: Pick<SessionRecord, 'workspaceId' | 'workspacePath'>,
366
- id: WorkspaceType
366
+ id: HarnessType
367
367
  ) {
368
- void harnessStore.refresh({ id: rec.workspaceId, path: rec.workspacePath, type: id })
368
+ void harnessStore.refresh({ id: rec.workspaceId, path: rec.workspacePath, harness: id })
369
369
  }
370
370
 
371
371
  function createRecord(input: {
@@ -1,12 +1,7 @@
1
1
  import { pathHarnessAvailability } from './executable'
2
2
  // Login is global per harness. Workspace readiness is checked independently
3
3
  // using each workspace’s environment.
4
- import type {
5
- HarnessLoginState,
6
- HarnessAvailability,
7
- HarnessLogin,
8
- WorkspaceType
9
- } from '@/lib/types'
4
+ import type { HarnessLoginState, HarnessAvailability, HarnessLogin, HarnessType } from '@/lib/types'
10
5
 
11
6
  import { publishEvent } from '../events'
12
7
  import { harnessFor } from './registry'
@@ -19,7 +14,7 @@ export type HarnessUpdatedEvent = {
19
14
  }
20
15
 
21
16
  // Readiness can target a harness account or an individual workspace.
22
- type HarnessTarget = WorkspaceType | HarnessWorkspace
17
+ type HarnessTarget = HarnessType | HarnessWorkspace
23
18
 
24
19
  function entryKey(context: HarnessTarget): string {
25
20
  return typeof context === 'string' ? `default:${context}` : `workspace:${context.id}`
@@ -27,9 +22,9 @@ function entryKey(context: HarnessTarget): string {
27
22
 
28
23
  export type HarnessStoreOptions = {
29
24
  probe: (ws: HarnessTarget) => Promise<HarnessAvailability>
30
- startLogin: (type: WorkspaceType) => Promise<HarnessLoginAttempt>
25
+ startLogin: (harness: HarnessType) => Promise<HarnessLoginAttempt>
31
26
  publish: (event: HarnessUpdatedEvent) => void
32
- onAuthChanged?: (type: WorkspaceType, availability: HarnessAvailability) => Promise<void>
27
+ onAuthChanged?: (harness: HarnessType, availability: HarnessAvailability) => Promise<void>
33
28
  availabilityTtlMs?: number
34
29
  loginPollMs?: number
35
30
  loginDeadlineMs?: number
@@ -124,14 +119,14 @@ export function createHarnessStore(options: HarnessStoreOptions) {
124
119
  return value
125
120
  }
126
121
 
127
- function getLogin(context: WorkspaceType): HarnessLoginState | undefined {
122
+ function getLogin(context: HarnessType): HarnessLoginState | undefined {
128
123
  return entries.get(entryKey(context))?.login?.state
129
124
  }
130
125
 
131
126
  // Re-probe until the login lands or the deadline passes. One loop per
132
127
  // ceremony; a replaced or completed ceremony stops its loop.
133
128
  function watch(
134
- type: WorkspaceType,
129
+ harness: HarnessType,
135
130
  login: LoginCeremony,
136
131
  initialAvailability: HarnessAvailability
137
132
  ) {
@@ -144,12 +139,12 @@ export function createHarnessStore(options: HarnessStoreOptions) {
144
139
  clearTimeout(timer)
145
140
  }
146
141
  const tick = async () => {
147
- const value = await probeFresh(type)
142
+ const value = await probeFresh(harness)
148
143
  if (stopped) return
149
- const entry = entryFor(type)
144
+ const entry = entryFor(harness)
150
145
  if (value.status === 'available' && (!login.attempt?.completed || login.completed)) {
151
146
  entry.login = undefined
152
- await publish(type, value)
147
+ await publish(harness, value)
153
148
  return
154
149
  }
155
150
  if (Date.now() >= deadline) {
@@ -157,12 +152,12 @@ export function createHarnessStore(options: HarnessStoreOptions) {
157
152
  // startLogin replaces it.
158
153
  stopLogin(login)
159
154
  login.state = { state: 'failed', reason: 'Sign-in did not complete. Try again' }
160
- await publish(type, value)
155
+ await publish(harness, value)
161
156
  return
162
157
  }
163
158
  if (!sameAvailability(value, publishedAvailability)) {
164
159
  publishedAvailability = value
165
- await publish(type, value)
160
+ await publish(harness, value)
166
161
  }
167
162
  timer = setTimeout(tick, pollMs)
168
163
  timer.unref?.()
@@ -172,8 +167,8 @@ export function createHarnessStore(options: HarnessStoreOptions) {
172
167
  timer.unref?.()
173
168
  }
174
169
 
175
- async function startLogin(type: WorkspaceType): Promise<HarnessLogin> {
176
- const entry = entryFor(type)
170
+ async function startLogin(harness: HarnessType): Promise<HarnessLogin> {
171
+ const entry = entryFor(harness)
177
172
  // Concurrent starts share the provider call; active attempts reuse their instructions.
178
173
  const current = entry.login
179
174
  if (current?.starting) return current.starting
@@ -183,7 +178,7 @@ export function createHarnessStore(options: HarnessStoreOptions) {
183
178
  }
184
179
 
185
180
  if (current) stopLogin(current)
186
- const starting = options.startLogin(type).then(attempt => {
181
+ const starting = options.startLogin(harness).then(attempt => {
187
182
  const { completed, cancel: _cancel, submitCode: _submitCode, ...instructions } = attempt
188
183
  login.attempt = attempt
189
184
  if (entry.login !== login) {
@@ -197,7 +192,7 @@ export function createHarnessStore(options: HarnessStoreOptions) {
197
192
  if (entry.login !== login) return
198
193
  stopLogin(login)
199
194
  login.state = { state: 'failed', reason: 'Sign-in failed or expired. Try again' }
200
- void refresh(type)
195
+ void refresh(harness)
201
196
  }
202
197
  )
203
198
  return instructions
@@ -213,8 +208,8 @@ export function createHarnessStore(options: HarnessStoreOptions) {
213
208
  status: 'login-required',
214
209
  reason: 'Waiting for sign-in'
215
210
  }
216
- await publish(type, availability)
217
- if (login.state.state === 'pending') watch(type, login, availability)
211
+ await publish(harness, availability)
212
+ if (login.state.state === 'pending') watch(harness, login, availability)
218
213
  return result
219
214
  } catch (err) {
220
215
  if (entry.login === login) entry.login = undefined
@@ -239,16 +234,16 @@ export function createHarnessStore(options: HarnessStoreOptions) {
239
234
  .catch(() => {})
240
235
  }
241
236
 
242
- function activeLogin(type: WorkspaceType, id: string) {
243
- const login = entryFor(type).login
237
+ function activeLogin(harness: HarnessType, id: string) {
238
+ const login = entryFor(harness).login
244
239
  if (!login || login.state.state !== 'pending' || login.state.id !== id) {
245
240
  throw new Error('This sign-in attempt has ended. Start again')
246
241
  }
247
242
  return login
248
243
  }
249
244
 
250
- async function submitCode(type: WorkspaceType, id: string, code: string) {
251
- const login = activeLogin(type, id)
245
+ async function submitCode(harness: HarnessType, id: string, code: string) {
246
+ const login = activeLogin(harness, id)
252
247
  if (!login.attempt?.submitCode) throw new Error('This sign-in does not accept a code')
253
248
  await login.attempt.submitCode(code)
254
249
  }
@@ -284,17 +279,17 @@ export const harnessStore = createHarnessStore({
284
279
  if (runtime && runtime.status !== 'available') return runtime
285
280
  return harness.authStatus()
286
281
  },
287
- startLogin: type => {
288
- const start = harnessFor(type).startLogin
282
+ startLogin: harness => {
283
+ const start = harnessFor(harness).startLogin
289
284
  if (!start) throw new Error('This agent requires terminal sign-in')
290
285
  return start()
291
286
  },
292
287
  publish: publishEvent,
293
- onAuthChanged: async (type, availability) => {
288
+ onAuthChanged: async (harness, availability) => {
294
289
  publishEvent({
295
290
  type: 'harness-status:changed',
296
- harness: type,
297
- status: { availability, login: harnessStore.getLogin(type) }
291
+ harness: harness,
292
+ status: { availability, login: harnessStore.getLogin(harness) }
298
293
  })
299
294
  }
300
295
  })
@@ -69,7 +69,7 @@ async function discoverWorkspaces(
69
69
  const worktree = await Promise.all(candidates.map(isLinkedGitWorktree))
70
70
  return candidates
71
71
  .filter((_, i) => !worktree[i])
72
- .map(path => ({ path, type: 'claude-code' as const }))
72
+ .map(path => ({ path, harness: 'claude-code' as const }))
73
73
  } catch {
74
74
  return []
75
75
  }
@@ -100,7 +100,7 @@ export async function discoverCodexWorkspaces(
100
100
  } catch {
101
101
  continue // directory deleted since the session ran
102
102
  }
103
- out.push({ path: cwd, type: 'codex' })
103
+ out.push({ path: cwd, harness: 'codex' })
104
104
  }
105
105
  return out
106
106
  }
@@ -462,7 +462,7 @@ function applyCompletionMeta(
462
462
 
463
463
  // A failed send may reflect an external logout. Refresh the cached banner now.
464
464
  function refreshAvailability(workspaceId: string, workspacePath: string) {
465
- void harnessStore.refresh({ id: workspaceId, path: workspacePath, type: 'codex' })
465
+ void harnessStore.refresh({ id: workspaceId, path: workspacePath, harness: 'codex' })
466
466
  }
467
467
 
468
468
  function handleNotification(rec: SessionRecord, method: string, params: Record<string, unknown>) {