moi-computer 0.13.1-next.2 → 0.13.1-next.4

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 (109) hide show
  1. package/client/app/app-provider.tsx +14 -20
  2. package/client/app/app-router.tsx +5 -8
  3. package/client/app/routes/workspace-route.tsx +28 -11
  4. package/client/app/shell/sidebar-layout.tsx +5 -10
  5. package/client/features/app-settings/api.ts +3 -3
  6. package/client/features/applets/applet-cache.ts +1 -2
  7. package/client/features/applets/use-applet.ts +18 -20
  8. package/client/features/chat/chat-store.ts +1 -1
  9. package/client/features/chat/connection/chat-connection.ts +25 -68
  10. package/client/features/chat/connection/chat-frames.ts +20 -32
  11. package/client/features/chat/sessions/api.ts +2 -2
  12. package/client/features/chat/sessions/use-selected-session.ts +0 -13
  13. package/client/features/collab/presence/client.ts +63 -83
  14. package/client/features/collab/presence/provider.tsx +8 -2
  15. package/client/features/dev/chat-states-page.tsx +1 -1
  16. package/client/features/dev/harness-debug-page.tsx +2 -2
  17. package/client/features/scratchpad/scratchpad.tsx +29 -20
  18. package/client/features/views/api.ts +38 -14
  19. package/client/features/views/use-view-actions.ts +2 -23
  20. package/client/features/workspace/api.ts +6 -11
  21. package/client/features/workspace/harness-transition.ts +3 -5
  22. package/client/features/workspace/remote.ts +9 -0
  23. package/client/features/workspace/settings/use-env-vars.ts +4 -4
  24. package/client/features/workspace/tab-resolution.ts +1 -8
  25. package/client/features/workspace/use-workspace-navigation.ts +5 -4
  26. package/client/features/workspace/use-workspace-socket.ts +51 -0
  27. package/client/features/workspace/workspace-content.tsx +5 -18
  28. package/client/features/workspace/workspace-layout-context.tsx +6 -13
  29. package/client/features/workspace/workspace-preferences.ts +67 -10
  30. package/client/features/workspace/workspace-state.ts +57 -21
  31. package/client/runtime/app-context.ts +2 -2
  32. package/client/runtime/app-events.ts +75 -0
  33. package/client/runtime/reconnecting-socket.ts +115 -0
  34. package/client/runtime/{use-workspace-events.ts → use-client-events.ts} +9 -10
  35. package/client/store/ui.ts +1 -6
  36. package/client/store/workspace-session.ts +30 -0
  37. package/dist/chunk-0t8m1ehd.js +2 -0
  38. package/dist/chunk-851bx8ss.js +72 -0
  39. package/dist/{chunk-n0fawy9x.js → chunk-c8g5x288.js} +1 -1
  40. package/dist/chunk-cty37f3v.js +1 -0
  41. package/dist/chunk-dy6f6h3e.js +5 -0
  42. package/dist/chunk-j6928pwm.js +1 -0
  43. package/dist/{chunk-rmd0ctfx.js → chunk-k32585ne.js} +73 -73
  44. package/dist/chunk-qtkv7hp8.js +2 -0
  45. package/dist/chunk-rh58dc0y.js +2 -0
  46. package/dist/{chunk-ec5ennpv.js → chunk-wjbejzek.js} +1 -1
  47. package/dist/index.html +1 -1
  48. package/lib/events.ts +61 -0
  49. package/lib/ids.ts +2 -8
  50. package/lib/moi-context.ts +19 -5
  51. package/lib/types.ts +16 -20
  52. package/lib/workspace-layout.ts +3 -20
  53. package/package.json +2 -1
  54. package/server/AGENTS.md +4 -4
  55. package/server/README.md +50 -33
  56. package/server/api/index.ts +175 -152
  57. package/server/applets/views.ts +15 -14
  58. package/server/applets/widgets.ts +4 -3
  59. package/server/cli/commands/init.ts +7 -2
  60. package/server/cli/commands/refresh.ts +2 -5
  61. package/server/cli/commands/remote.ts +128 -26
  62. package/server/cli/remote-control.ts +12 -9
  63. package/server/cli/remote-operations.ts +47 -44
  64. package/server/control.ts +33 -34
  65. package/server/events.ts +14 -13
  66. package/server/harness/README.md +7 -7
  67. package/server/harness/acp/session.ts +9 -5
  68. package/server/harness/auth.ts +7 -30
  69. package/server/harness/claude-code/session.ts +8 -4
  70. package/server/harness/codex/NOTES.md +1 -1
  71. package/server/harness/codex/session.ts +18 -10
  72. package/server/harness/hermes/NOTES.md +3 -3
  73. package/server/harness/openclaw/session.ts +9 -5
  74. package/server/onboarding/jobs.ts +8 -8
  75. package/server/operations/commands.ts +1 -1
  76. package/server/remote/broker-client.ts +76 -0
  77. package/server/remote/broker.ts +81 -0
  78. package/server/remote/client.ts +212 -152
  79. package/server/remote/errors.ts +2 -0
  80. package/server/remote/routes.ts +121 -0
  81. package/server/scratchpad/document.ts +3 -2
  82. package/server/scratchpad/executor.ts +2 -2
  83. package/server/scratchpad/relay.ts +3 -3
  84. package/server/sessions/archive.ts +1 -1
  85. package/server/sessions/lifecycle.ts +1 -1
  86. package/server/sessions/pending-views.ts +19 -12
  87. package/server/sessions/send-message.ts +102 -0
  88. package/server/sessions/view-sessions.ts +4 -94
  89. package/server/web.ts +42 -31
  90. package/server/workspace-state/file.ts +2 -0
  91. package/server/workspace-state/index.ts +15 -4
  92. package/server/workspaces/api.ts +4 -8
  93. package/server/workspaces/config.ts +14 -13
  94. package/server/workspaces/env-apply.ts +1 -1
  95. package/server/workspaces/layout.ts +40 -7
  96. package/server/workspaces/shared.ts +1 -1
  97. package/server/workspaces/tabs.ts +1 -2
  98. package/skill/SKILL.md +75 -34
  99. package/skill/references/SCRATCHPAD.md +4 -0
  100. package/skill/references/UI-COMPONENTS.md +1 -1
  101. package/client/features/scratchpad/scratch-executor.ts +0 -20
  102. package/client/runtime/workspace-events.ts +0 -168
  103. package/dist/chunk-44khk4sp.js +0 -2
  104. package/dist/chunk-ba6mz56s.js +0 -72
  105. package/dist/chunk-ectsnw81.js +0 -2
  106. package/dist/chunk-en7w5ypg.js +0 -1
  107. package/dist/chunk-f695wcx5.js +0 -5
  108. package/dist/chunk-pdt9hxfw.js +0 -2
  109. package/dist/chunk-zv22wv0g.js +0 -1
@@ -1,3 +1,4 @@
1
+ import type { ServerEvent } from '@/lib/events'
1
2
  import { existsSync } from 'node:fs'
2
3
 
3
4
  import type { CompiledView, ViewConfig, ViewInfo, WorkspaceEntry } from '@/lib/types'
@@ -179,13 +180,13 @@ export async function getWorkspaceViews(ws: WorkspaceRef): Promise<ViewInfo[]> {
179
180
  }
180
181
 
181
182
  // The API lists compiled views only; clients read pending views from the
182
- // workspace state, which `state:changed` keeps current.
183
+ // workspace state, which `personal-state:changed` keeps current.
183
184
  export async function listViews(workspacePath: string): Promise<Response> {
184
185
  return Response.json({ views: await listCompiledViews(workspacePath) })
185
186
  }
186
187
 
187
188
  export async function handleBundleViews(
188
- publish: (msg: unknown) => void,
189
+ publish: (msg: ServerEvent) => void,
189
190
  workspaceId: string,
190
191
  workspacePath: string,
191
192
  force = false,
@@ -207,21 +208,21 @@ export async function handleBundleViews(
207
208
  [...beforeBuilt].some(n => !afterBuilt.has(n)) ||
208
209
  [...afterBuilt].some(n => !beforeBuilt.has(n))
209
210
 
210
- // Install compiled views in the browser before removing their pending entries.
211
- // Otherwise tab cleanup can mistake the handoff for a deleted view.
211
+ let views: CompiledView[] = []
212
212
  if (results.some(r => r.status === 'built') || orderChanged || membershipChanged) {
213
- publish({
214
- type: 'view-layout:updated',
215
- workspaceId,
216
- views: await listCompiledViews(workspacePath)
217
- })
213
+ views = await listCompiledViews(workspacePath)
214
+ publish({ type: 'views-list:changed', workspaceId, views })
218
215
  }
219
216
 
220
217
  const changedServerModules = new Set<string>()
221
218
  for (const r of results) {
222
219
  if (r.status === 'built') {
223
- publish({ type: 'view:updated', workspaceId, name: r.name, config: r.config ?? null })
224
- await completeViewBuild({ id: workspaceId, path: workspacePath }, r.name)
220
+ publish({ type: 'view:changed', workspaceId, name: r.name })
221
+ await completeViewBuild(
222
+ { id: workspaceId, path: workspacePath },
223
+ r.name,
224
+ views.find(view => view.id === r.name)
225
+ )
225
226
  for (const m of r.serverModules ?? []) changedServerModules.add(m)
226
227
  }
227
228
  }
@@ -234,7 +235,7 @@ export async function handleBundleViews(
234
235
  }
235
236
 
236
237
  export async function updateViewTitle(
237
- publish: (msg: unknown) => void,
238
+ publish: (msg: ServerEvent) => void,
238
239
  workspaceId: string,
239
240
  workspacePath: string,
240
241
  viewId: string,
@@ -288,7 +289,7 @@ export async function updateViewTitle(
288
289
  }
289
290
 
290
291
  export async function deleteView(
291
- publish: (msg: unknown) => void,
292
+ publish: (msg: ServerEvent) => void,
292
293
  ws: WorkspaceEntry,
293
294
  viewId: string
294
295
  ): Promise<void> {
@@ -306,7 +307,7 @@ export async function deleteView(
306
307
  reloadModules([`views/${viewId}`], workspacePath)
307
308
  await completeViewBuild(ws, viewId)
308
309
  publish({ type: 'view:deleted', workspaceId, name: viewId })
309
- publish({ type: 'workspace:updated', workspaceId })
310
+ publish({ type: 'workspace-config:changed', workspaceId })
310
311
  await handleBundleViews(publish, workspaceId, workspacePath, false, viewId)
311
312
  })
312
313
  }
@@ -1,3 +1,4 @@
1
+ import type { ServerEvent } from '@/lib/events'
1
2
  import { existsSync } from 'node:fs'
2
3
 
3
4
  import type { WidgetConfig, WidgetInfo } from '@/lib/types'
@@ -122,7 +123,7 @@ export async function listWidgets(workspacePath: string): Promise<Response> {
122
123
  }
123
124
 
124
125
  export async function handleBundle(
125
- publish: (msg: unknown) => void,
126
+ publish: (msg: ServerEvent) => void,
126
127
  workspaceId: string,
127
128
  workspacePath: string,
128
129
  force = false,
@@ -152,7 +153,7 @@ export async function handleBundle(
152
153
  const changedServerModules = new Set<string>()
153
154
  for (const r of results) {
154
155
  if (r.status === 'built') {
155
- publish({ type: 'widget:updated', workspaceId, name: r.name, config: r.config ?? null })
156
+ publish({ type: 'widget:changed', workspaceId, name: r.name })
156
157
  for (const m of r.serverModules ?? []) changedServerModules.add(m)
157
158
  }
158
159
  }
@@ -163,7 +164,7 @@ export async function handleBundle(
163
164
 
164
165
  if (layoutChanged) {
165
166
  const widgets = await getWidgetList(workspacePath)
166
- publish({ type: 'widget-layout:updated', workspaceId, widgets })
167
+ publish({ type: 'widgets-list:changed', workspaceId, widgets })
167
168
  }
168
169
 
169
170
  return results
@@ -24,7 +24,7 @@ import {
24
24
  import { serverCwd } from '../../server-cwd'
25
25
  import { superviseServerUpdates } from '../../update'
26
26
  import { PACKAGE_ROOT } from '../../version'
27
- import { provisionWorkspace } from '../../workspaces/init'
27
+ import { provisionWorkspace, skillsDirFor } from '../../workspaces/init'
28
28
  import { isServerRunning, registerViaControl, waitForServer } from '../control'
29
29
  import pc from '../pc'
30
30
  import { spawnServer } from '../server'
@@ -215,7 +215,12 @@ export const init = defineCommand({
215
215
  return
216
216
  }
217
217
  entry = result
218
- console.log(pc.green('✓') + ' Initialized ' + pc.bold(result.path) + ' for ' + args.remote)
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
219
224
  } catch (error) {
220
225
  console.error(error instanceof Error ? error.message : 'Remote initialization failed')
221
226
  process.exitCode = 1
@@ -1,4 +1,3 @@
1
- import { currentRemoteWorkspace } from '../../remote/workspace'
2
1
  import { defineCommand } from 'citty'
3
2
  import { CONTROL_URL } from '../../constants'
4
3
  import { staleSkillNotice } from '../../skills/version'
@@ -9,8 +8,7 @@ import pc from '../pc'
9
8
  export const refresh = defineCommand({
10
9
  meta: {
11
10
  name: 'refresh',
12
- description:
13
- 'Refresh widget and view data without rebuilding. Use after the agent mutates underlying data.'
11
+ description: 'Refresh widget and view data in your tabs for the current workspace.'
14
12
  },
15
13
  args: {
16
14
  only: appletOnlyArg
@@ -18,7 +16,6 @@ export const refresh = defineCommand({
18
16
  async run({ args }) {
19
17
  const only = readAppletSelector(args.only)
20
18
  const notice = await staleSkillNotice(process.cwd())
21
- const linked = await currentRemoteWorkspace()
22
19
  const ws = new WebSocket(CONTROL_URL)
23
20
 
24
21
  ws.onopen = () =>
@@ -26,7 +23,7 @@ export const refresh = defineCommand({
26
23
  JSON.stringify({
27
24
  type: 'applets:refresh',
28
25
  only,
29
- path: linked?.path ?? process.env.MOI_REMOTE_WORKSPACE
26
+ path: process.cwd()
30
27
  })
31
28
  )
32
29
 
@@ -6,12 +6,15 @@ import { clearLine, cursorTo } from 'node:readline'
6
6
  import { currentRemoteWorkspace } from '../../remote/workspace'
7
7
  import { parseRemoteWorkspaceAddress } from '@/lib/workspace-config'
8
8
  import pc from '../pc'
9
+ import { columns, keyValue } from '../ui'
10
+ import { resolveWorkspace, staleSkillNotice } from '../../skills/version'
11
+ import { getLayoutPath } from '../../workspaces/layout'
9
12
  import {
10
13
  login as signIn,
11
14
  logout as signOut,
12
15
  CloudSignInRequired,
13
- remoteConfig,
14
16
  remoteStatus,
17
+ fetchSharedWorkspaces,
15
18
  invitations as listInvitations,
16
19
  accept as acceptInvitation,
17
20
  renameAgent,
@@ -22,6 +25,17 @@ import {
22
25
  // oxlint-disable-next-line no-control-regex -- Deliberately remove terminal control characters.
23
26
  const text = (value: string) => Bun.stripANSI(value).replace(/[\u0000-\u001f\u007f-\u009f]/g, '')
24
27
 
28
+ async function warnIfSkillStale() {
29
+ try {
30
+ const { root, harness } = await resolveWorkspace(process.cwd())
31
+ if (!harness && !(await Bun.file(getLayoutPath(root)).exists())) return
32
+ const notice = await staleSkillNotice(root)
33
+ if (notice) console.error('\n' + pc.yellow(notice))
34
+ } catch {
35
+ // A skill check must not prevent displaying remote status.
36
+ }
37
+ }
38
+
25
39
  async function reportErrors(action: () => Promise<void>): Promise<void> {
26
40
  try {
27
41
  await action()
@@ -70,7 +84,7 @@ function waitingForLogin(): () => void {
70
84
  }
71
85
 
72
86
  const login = defineCommand({
73
- meta: { name: 'login', description: 'Sign in to Moi Cloud in your browser' },
87
+ meta: { name: 'login', description: 'Sign in to Moi Cloud in your browser (for humans only)' },
74
88
  args: {
75
89
  browser: {
76
90
  type: 'boolean',
@@ -90,7 +104,9 @@ const login = defineCommand({
90
104
  } finally {
91
105
  stopWaiting()
92
106
  }
93
- console.log(`\n${pc.green('Congratulations!')} You are now signed in.\n`)
107
+ const { me } = await remoteStatus()
108
+ const identity = 'email' in me ? me.email : me.name
109
+ console.log(`${pc.green('✓')} Signed in as ${text(identity)}\n`)
94
110
  })
95
111
  }
96
112
  })
@@ -107,12 +123,11 @@ const logout = defineCommand({
107
123
  })
108
124
 
109
125
  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
126
  const rename = defineCommand({
115
- meta: { name: 'rename-agent', description: 'Change your agent name across workspaces' },
127
+ meta: {
128
+ name: 'rename-agent',
129
+ description: 'Change your agent name across workspaces (for agents only)'
130
+ },
116
131
  args: { name: { type: 'positional', required: true }, json: jsonArg },
117
132
  async run({ args }) {
118
133
  await reportErrors(async () => {
@@ -137,12 +152,59 @@ const invitations = defineCommand({
137
152
  })
138
153
  }
139
154
  })
155
+ const workspaces = defineCommand({
156
+ meta: { name: 'workspaces', description: 'List shared workspaces and pending invitations' },
157
+ args: { json: jsonArg },
158
+ async run({ args }) {
159
+ await reportErrors(async () => {
160
+ const [available, pending] = await Promise.all([fetchSharedWorkspaces(), listInvitations()])
161
+ if (args.json) {
162
+ console.log(JSON.stringify({ workspaces: available, invitations: pending }, null, 2))
163
+ return
164
+ }
165
+ console.log('\n' + pc.bold('Available shared workspaces') + '\n')
166
+ if (available.length) {
167
+ console.log(
168
+ columns(
169
+ ['Workspace', 'Shared by', 'Remote ID'].map(label => pc.dim(label)),
170
+ available.map(workspace => [
171
+ text(workspace.id),
172
+ text(workspace.owner.email),
173
+ text(`${workspace.owner.id}:${workspace.id}`)
174
+ ])
175
+ )
176
+ )
177
+ console.log(
178
+ '\n' + pc.dim('To link from a new folder: ') + pc.cyan('moi init --remote <remote-id>')
179
+ )
180
+ } else console.log(' No shared workspaces yet')
181
+ console.log('\n' + pc.bold('Pending invitations') + '\n')
182
+ if (pending.length) {
183
+ console.log(
184
+ columns(
185
+ ['Workspace', 'Invited by', 'Invitation ID'].map(label => pc.dim(label)),
186
+ pending.map(invitation => [
187
+ text(invitation.workspaceName),
188
+ text(invitation.inviter.email),
189
+ text(invitation.id)
190
+ ])
191
+ )
192
+ )
193
+ console.log('\n' + pc.dim('To accept: ') + pc.cyan('moi remote accept <invitation-id>'))
194
+ } else console.log(' No pending invitations')
195
+ console.log('\nHelp and full command list: ' + pc.cyan('moi remote workspaces --help') + '\n')
196
+ })
197
+ }
198
+ })
140
199
  const accept = defineCommand({
141
200
  meta: { name: 'accept', description: 'Accept a workspace invitation as a human or agent' },
142
201
  args: {
143
202
  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(', ') },
203
+ name: { type: 'string', description: 'Your agent display name, shown to workspace members' },
204
+ client: {
205
+ type: 'string',
206
+ description: 'The app you run in: ' + AGENT_CLIENTS.join(', ') + '; use other if not listed'
207
+ },
146
208
  json: jsonArg
147
209
  },
148
210
  async run({ args }) {
@@ -151,7 +213,7 @@ const accept = defineCommand({
151
213
  console.log(
152
214
  args.json
153
215
  ? JSON.stringify(result)
154
- : `Invitation accepted\n\nmoi init --remote ${result.remote.user_id}:${result.remote.workspace_id}`
216
+ : `Invitation accepted\n\nCreate a local linked folder (choose an unused folder name):\nmoi init ./workspace-folder --remote ${result.remote.user_id}:${result.remote.workspace_id}`
155
217
  )
156
218
  })
157
219
  }
@@ -164,19 +226,18 @@ const leave = defineCommand({
164
226
  required: false,
165
227
  description: 'ownerId:workspaceId (defaults to current folder)'
166
228
  },
167
- path: pathArg,
168
229
  json: jsonArg
169
230
  },
170
231
  async run({ args }) {
171
232
  await reportErrors(async () => {
172
- if (args.workspace !== undefined && args.path)
173
- throw new Error('Use a workspace address or --path, not both')
174
233
  const target =
175
234
  args.workspace !== undefined
176
235
  ? parseRemoteWorkspaceAddress(args.workspace)
177
- : await currentRemoteWorkspace(args.path)
236
+ : await currentRemoteWorkspace()
178
237
  if (!target)
179
- throw new Error('No remote workspace here — provide ownerId:workspaceId or --path')
238
+ throw new Error(
239
+ 'No remote workspace here — run from a linked workspace folder or provide ownerId:workspaceId'
240
+ )
180
241
  const result = await leaveWorkspace(target.user_id, target.workspace_id)
181
242
  console.log(args.json ? JSON.stringify(result) : 'Left the workspace; local files kept')
182
243
  })
@@ -187,15 +248,25 @@ const remoteSubCommands = {
187
248
  login,
188
249
  logout,
189
250
  'rename-agent': rename,
251
+ workspaces,
190
252
  invitations,
191
253
  accept,
192
254
  leave
193
255
  }
194
256
 
195
257
  export const remote = defineCommand({
196
- meta: { name: 'remote', description: 'Show your cloud account and shared workspaces' },
197
- args: { json: jsonArg, path: pathArg },
258
+ meta: { name: 'remote', description: 'Show your identity and linked workspace commands' },
259
+ args: { json: jsonArg },
198
260
  subCommands: remoteSubCommands,
261
+ setup({ rawArgs }) {
262
+ // Citty accepts unknown options. Reject the removed selector before dispatch
263
+ // so an old script cannot silently operate on the current workspace.
264
+ const separator = rawArgs.indexOf('--')
265
+ const options = separator < 0 ? rawArgs : rawArgs.slice(0, separator)
266
+ if (options.some(arg => arg === '--path' || arg.startsWith('--path='))) {
267
+ throw new Error('Unknown option --path — run this command from the workspace folder')
268
+ }
269
+ },
199
270
  async run({ args, rawArgs }) {
200
271
  // citty also runs the parent after a subcommand; only bare `remote` shows status.
201
272
  const sub = rawArgs.find(arg => !arg.startsWith('-'))
@@ -203,26 +274,57 @@ export const remote = defineCommand({
203
274
  await reportErrors(async () => {
204
275
  const status = {
205
276
  ...(await remoteStatus()),
206
- currentWorkspace: await currentRemoteWorkspace(args.path)
277
+ currentWorkspace: await currentRemoteWorkspace()
207
278
  }
208
279
  if (args.json) {
209
280
  console.log(JSON.stringify(status, null, 2))
281
+ await warnIfSkillStale()
210
282
  return
211
283
  }
284
+ const detail = 'email' in status.me ? status.me.email : status.me.client
212
285
  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`
286
+ '\nSigned in as ' + pc.bold(text(status.me.name || detail)) + pc.dim(` <${text(detail)}>`)
214
287
  )
215
- if (status.currentWorkspace)
288
+ const linked = status.currentWorkspace
289
+ if (linked) {
290
+ const workspace = status.workspaces.find(
291
+ item => item.id === linked.workspace_id && item.owner.id === linked.user_id
292
+ )
293
+ console.log(
294
+ '\nCurrent workspace is linked to: ' +
295
+ pc.bold(text(linked.workspace_id)) +
296
+ (workspace ? ' by ' + text(workspace.owner.email) : '')
297
+ )
298
+ console.log('Remote ID: ' + text(`${linked.user_id}:${linked.workspace_id}`))
216
299
  console.log(
217
- `Remote workspace: ${text(status.currentWorkspace.user_id)}:${text(status.currentWorkspace.workspace_id)}\n`
300
+ '\n' +
301
+ keyValue([
302
+ [pc.cyan('moi remote read <remote-path>'), 'Read a file'],
303
+ [pc.cyan('moi remote write <remote-path> "content"'), 'Write a file'],
304
+ [pc.cyan('moi remote patch <remote-path>'), 'Apply a diff from stdin'],
305
+ [pc.cyan('moi remote exec "command"'), 'Run a command remotely'],
306
+ [pc.cyan('moi remote file-upload <local-path> <remote-path>'), 'Upload a local file'],
307
+ [
308
+ pc.cyan('moi remote file-download <remote-path> <local-path>'),
309
+ 'Download a remote file'
310
+ ]
311
+ ])
218
312
  )
219
- console.log('Shared workspaces')
220
- if (!status.workspaces.length) console.log(' No shared workspaces')
221
- for (const workspace of status.workspaces)
222
313
  console.log(
223
- ` ${text(workspace.owner.id)}:${text(workspace.id)} — ${text(workspace.owner.name || workspace.owner.email)} <${text(workspace.owner.email)}>`
314
+ '\n' +
315
+ pc.cyan(
316
+ 'moi check|bundle|theme|config|tabs|ui-components|call-server-fn|debug|scratch'
317
+ ) +
318
+ '\n' +
319
+ pc.dim('These regular commands work on the remote workspace')
224
320
  )
321
+ } else {
322
+ console.log('\nThis folder is not linked to a remote workspace')
323
+ }
324
+ console.log('\n' + pc.dim('Help and full command list: ') + pc.cyan('moi remote --help'))
325
+ if (linked) console.log(pc.dim('Command help: ') + pc.cyan('moi remote <command> --help'))
225
326
  console.log()
327
+ await warnIfSkillStale()
226
328
  })
227
329
  }
228
330
  })
@@ -2,10 +2,14 @@ import { basename } from 'node:path'
2
2
  import type { ScratchOp, ViewInfo } from '@/lib/types'
3
3
  import { currentRemoteWorkspace } from '../remote/workspace'
4
4
  import { requestWorkspace } from '../workspaces/api'
5
+ import { cloudRoutes } from '../remote/routes'
5
6
  import { assembleTabRows } from '../workspaces/tabs'
6
7
  import { readScratchpadImage, readScratchpadShapes } from '../scratchpad/document'
7
8
  import type { WorkspaceConfig } from '../workspaces/config'
8
9
 
10
+ const { views, config, icon, scratchpadOps } = cloudRoutes
11
+ const routes = { views, config, icon, scratchpadOps }
12
+
9
13
  type ScratchCliOp = ScratchOp | { kind: 'read' } | { kind: 'read-image'; name: string }
10
14
 
11
15
  // These commands keep parsing, local file IO and output on the caller. Only
@@ -20,26 +24,25 @@ export async function remoteControl(
20
24
  const remote = await currentRemoteWorkspace(path)
21
25
  if (!remote) return
22
26
  const workspace = { remote }
23
- const request = (suffix: string, init?: RequestInit) => requestWorkspace(workspace, suffix, init)
27
+ const request = (route: keyof typeof routes, init?: RequestInit) =>
28
+ requestWorkspace(routes[route].path(remote), init)
24
29
  if (payload.type === 'tabs') {
25
- const { views }: { views: ViewInfo[] } = await (
26
- await request('/views?includePending=true')
27
- ).json()
30
+ const { views }: { views: ViewInfo[] } = await (await request('views')).json()
28
31
  return { tabs: assembleTabRows(views) }
29
32
  }
30
33
  if (payload.type === 'config') {
31
34
  if (typeof payload.iconPath === 'string') {
32
35
  const file = Bun.file(payload.iconPath)
33
36
  if (!(await file.exists())) throw new Error('Local icon file not found')
34
- return { ok: true, ...(await (await request('/icon', { method: 'PUT', body: file })).json()) }
37
+ return { ok: true, ...(await (await request('icon', { method: 'PUT', body: file })).json()) }
35
38
  }
36
39
  if (payload.clearIcon) {
37
- await request('/icon', { method: 'DELETE' })
40
+ await request('icon', { method: 'DELETE' })
38
41
  return { ok: true, clearedIcon: true }
39
42
  }
40
43
  if (payload.name !== undefined || payload.clearName) {
41
44
  const result = await (
42
- await request('/config', {
45
+ await request('config', {
43
46
  method: 'PUT',
44
47
  headers: { 'content-type': 'application/json' },
45
48
  body: JSON.stringify({ name: payload.clearName ? null : payload.name })
@@ -47,7 +50,7 @@ export async function remoteControl(
47
50
  ).json()
48
51
  return { ...result, ok: true, clearedName: payload.clearName === true }
49
52
  }
50
- const config: WorkspaceConfig = await (await request('/config')).json()
53
+ const config: WorkspaceConfig = await (await request('config')).json()
51
54
  return { ...config, hasIcon: !!config.icon }
52
55
  }
53
56
  if (!op) throw new Error('Missing scratch operation')
@@ -65,6 +68,6 @@ export async function remoteControl(
65
68
  } else body.set('op', JSON.stringify(op))
66
69
  return {
67
70
  ok: true,
68
- result: await (await request('/scratchpad/ops', { method: 'POST', body })).json()
71
+ result: await (await request('scratchpadOps', { method: 'POST', body })).json()
69
72
  }
70
73
  }