moi-computer 0.13.1-next.2 → 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 (54) hide show
  1. package/client/features/chat/sessions/use-selected-session.ts +0 -13
  2. package/client/features/views/api.ts +33 -8
  3. package/client/features/views/use-view-actions.ts +2 -23
  4. package/client/features/workspace/tab-resolution.ts +1 -8
  5. package/client/features/workspace/use-workspace-navigation.ts +4 -3
  6. package/client/features/workspace/workspace-content.tsx +2 -11
  7. package/client/features/workspace/workspace-preferences.ts +67 -10
  8. package/client/features/workspace/workspace-state.ts +40 -15
  9. package/client/store/ui.ts +1 -6
  10. package/client/store/workspace-session.ts +30 -0
  11. package/dist/chunk-0h4zypgf.js +1 -0
  12. package/dist/chunk-1tksq43z.js +72 -0
  13. package/dist/chunk-6gxf0xr8.js +5 -0
  14. package/dist/{chunk-ec5ennpv.js → chunk-a865c7x4.js} +1 -1
  15. package/dist/{chunk-pdt9hxfw.js → chunk-f44cs6mw.js} +2 -2
  16. package/dist/{chunk-44khk4sp.js → chunk-h3qag4a6.js} +2 -2
  17. package/dist/{chunk-ectsnw81.js → chunk-q2tpy0h7.js} +2 -2
  18. package/dist/{chunk-rmd0ctfx.js → chunk-r95acex1.js} +74 -74
  19. package/dist/chunk-w5h9grdr.js +1 -0
  20. package/dist/{chunk-n0fawy9x.js → chunk-xj1pjhng.js} +1 -1
  21. package/dist/index.html +1 -1
  22. package/lib/moi-context.ts +19 -5
  23. package/lib/types.ts +4 -5
  24. package/lib/workspace-layout.ts +3 -20
  25. package/package.json +2 -1
  26. package/server/AGENTS.md +1 -1
  27. package/server/README.md +21 -18
  28. package/server/api/index.ts +122 -118
  29. package/server/cli/commands/init.ts +7 -2
  30. package/server/cli/commands/remote.ts +128 -26
  31. package/server/cli/remote-control.ts +12 -9
  32. package/server/cli/remote-operations.ts +47 -44
  33. package/server/control.ts +9 -1
  34. package/server/onboarding/jobs.ts +1 -1
  35. package/server/remote/broker-client.ts +76 -0
  36. package/server/remote/broker.ts +81 -0
  37. package/server/remote/client.ts +212 -152
  38. package/server/remote/errors.ts +2 -0
  39. package/server/remote/routes.ts +121 -0
  40. package/server/scratchpad/document.ts +3 -2
  41. package/server/sessions/pending-views.ts +2 -1
  42. package/server/sessions/send-message.ts +102 -0
  43. package/server/sessions/view-sessions.ts +4 -94
  44. package/server/web.ts +2 -1
  45. package/server/workspace-state/file.ts +2 -0
  46. package/server/workspaces/api.ts +4 -8
  47. package/server/workspaces/tabs.ts +1 -2
  48. package/skill/SKILL.md +75 -34
  49. package/skill/references/SCRATCHPAD.md +4 -0
  50. package/skill/references/UI-COMPONENTS.md +1 -1
  51. package/dist/chunk-ba6mz56s.js +0 -72
  52. package/dist/chunk-en7w5ypg.js +0 -1
  53. package/dist/chunk-f695wcx5.js +0 -5
  54. package/dist/chunk-zv22wv0g.js +0 -1
@@ -78,7 +78,8 @@ import {
78
78
  import { saveSessionConfig } from '../sessions/config'
79
79
  import type { SessionConfigPatch } from '../sessions/config'
80
80
  import { archiveWorkspaceSession } from '../sessions/archive'
81
- import { getWorkspaceState } from '../workspace-state'
81
+ import { getWorkspaceState, updateWorkspaceState } from '../workspace-state'
82
+ import { normalizeOpenTabs } from '@/lib/workspace-layout'
82
83
  import { DIST_DIR, prebuilt } from '../static'
83
84
  import { getWorkspaceSkillsStatus, updateWorkspaceSkills } from '../skills/update'
84
85
  import { serveWorkspaceImagePreview } from '../workspaces/preview'
@@ -117,7 +118,7 @@ import {
117
118
  updateInProgress
118
119
  } from '../update'
119
120
 
120
- // The resolved workspace is stashed on the context by `withWorkspace`, so every
121
+ // The resolved workspace is stashed on the context by the workspace middleware, so every
121
122
  // `/api/workspaces/:id/*` handler can read it without re-querying the registry.
122
123
  type ApiEnv = { Variables: { ws: WorkspaceEntry } }
123
124
 
@@ -165,53 +166,42 @@ async function handleFunctionCall(
165
166
  }
166
167
  }
167
168
 
168
- // Routes that describe the person using a workspace, not the workspace itself:
169
- // their chats, their agent and what that agent runs with. A visitor's Moi answers
170
- // them from its own folder; an owner never serves them to visitors.
171
- const PERSONAL_ROUTE_RE = /^\/(?:sessions|state|harness|skills|env|mcp|uploads|preview)(?:\/|$)/
172
- // A view being built belongs to the chat building it, so its lifecycle is
173
- // personal too. Compiled views stay with the owner.
174
- const PENDING_VIEW_ROUTE_RE = /^\/views(?:\/[^/]+(?:\/submit)?)?$/
175
-
176
- // Resolve `:id` to a registered workspace once, 404 if unknown, and stash it on
177
- // the context. Mounted on the single-workspace sub-app so every nested route
178
- // shares the lookup instead of repeating `getWorkspace(...) ?? 404`.
179
- const withWorkspace = createMiddleware<ApiEnv>(async (c, next) => {
180
- const id = c.req.param('id')
181
- if (!id) return c.text('Workspace not found', 404)
182
- let release: (() => void) | undefined
183
- try {
184
- if (c.req.method !== 'GET' && !c.req.path.endsWith('/harness'))
185
- release = reserveWorkspaceOperation(id)
186
- const ws = await getWorkspace(id)
187
- if (!ws) return c.text('Workspace not found', 404)
188
- const suffix = (c.req.path.split(`/workspaces/${encodeURIComponent(id)}`)[1] ?? '').replace(
189
- /\/$/,
190
- ''
191
- )
192
- const personal =
193
- PERSONAL_ROUTE_RE.test(suffix) ||
194
- (c.req.method !== 'GET' && PENDING_VIEW_ROUTE_RE.test(suffix))
195
- if (ws.remote && suffix === '' && c.req.method === 'DELETE')
196
- return c.text('Leaving remote workspaces is not available yet', 403)
197
- if (ws.remote && getAppConfig().environment !== 'cloud')
198
- return c.text('Remote workspaces require Cloud mode', 403)
199
- if (ws.remote && suffix !== '' && !personal)
200
- return c.text('Use the owner workspace address', 404)
201
- c.set('ws', ws)
202
- await next()
203
- } catch (error) {
204
- if (error instanceof HarnessTransitionError) return c.text(error.message, 409)
205
- throw error
206
- } finally {
207
- release?.()
208
- }
209
- })
169
+ // Resolve the workspace and enforce the route's storage boundary. Personal
170
+ // routes use this Moi's chats, agent and pending views, including for a remote
171
+ // reference. Shared content must be requested at the owner's workspace address.
172
+ function workspaceAccess(
173
+ scope: 'personal' | 'owner',
174
+ { reserveOperation = true }: { reserveOperation?: boolean } = {}
175
+ ) {
176
+ return createMiddleware<ApiEnv>(async (c, next) => {
177
+ const id = c.req.param('id')
178
+ if (!id) return c.text('Workspace not found', 404)
179
+ let release: (() => void) | undefined
180
+ try {
181
+ if (reserveOperation && c.req.method !== 'GET') release = reserveWorkspaceOperation(id)
182
+ const ws = await getWorkspace(id)
183
+ if (!ws) return c.text('Workspace not found', 404)
184
+ if (ws.remote && getAppConfig().environment !== 'cloud')
185
+ return c.text('Remote workspaces require Cloud mode', 403)
186
+ if (ws.remote && scope === 'owner') return c.text('Use the owner workspace address', 404)
187
+ c.set('ws', ws)
188
+ await next()
189
+ } catch (error) {
190
+ if (error instanceof HarnessTransitionError) return c.text(error.message, 409)
191
+ throw error
192
+ } finally {
193
+ release?.()
194
+ }
195
+ })
196
+ }
197
+
198
+ const personalWorkspace = workspaceAccess('personal')
199
+ const ownerWorkspace = workspaceAccess('owner')
210
200
 
211
201
  // ---- single workspace: /api/workspaces/:id/* --------------------------------
212
202
  const one = new Hono<ApiEnv>()
213
- one.use('*', withWorkspace)
214
- one.patch('/harness', async c => {
203
+ // Switching agents takes its own exclusive lock.
204
+ one.patch('/harness', workspaceAccess('personal', { reserveOperation: false }), async c => {
215
205
  if (getAppConfig().demo) return c.text('Changing agents is unavailable in the demo', 403)
216
206
  const body = await c.req.json().catch(() => null)
217
207
  if (!body || !['claude-code', 'codex'].includes(body.harness))
@@ -224,13 +214,13 @@ one.patch('/harness', async c => {
224
214
  }
225
215
  })
226
216
 
227
- one.get('/widgets', c => listWidgets(c.get('ws').path))
217
+ one.get('/widgets', ownerWorkspace, c => listWidgets(c.get('ws').path))
228
218
 
229
219
  // Widget bundle: the compiled ESM for one widget, dynamically imported by the
230
220
  // client (useWidget). Sits beside the GET .../widgets list above — the exact
231
221
  // path lists, `/*` serves a file from the bundle dir (`<name>/<file>`:
232
222
  // index.js, a chunk, or a hashed asset).
233
- one.get('/widgets/*', c => {
223
+ one.get('/widgets/*', ownerWorkspace, c => {
234
224
  const ws = c.get('ws')
235
225
  const { name, file } = parseAppletTail(c.req.url, ws.id, 'widgets')
236
226
  if (!name) return c.text('Not found', 404)
@@ -239,7 +229,7 @@ one.get('/widgets/*', c => {
239
229
 
240
230
  // Views — full-screen agent apps. Mirrors the widget pair above: the exact path
241
231
  // lists (in manifest/nav order), `/*` serves one bundle file.
242
- one.get('/views', async c =>
232
+ one.get('/views', ownerWorkspace, async c =>
243
233
  c.req.query('includePending') === 'true'
244
234
  ? c.json({ views: await getWorkspaceViews(c.get('ws')) })
245
235
  : listViews(c.get('ws').path)
@@ -247,7 +237,8 @@ one.get('/views', async c =>
247
237
 
248
238
  const OWNER_VIEW = 'Use the owner workspace address for compiled views'
249
239
 
250
- one.patch('/views/:viewId', async c => {
240
+ // Pending views are personal; these handlers also accept compiled views on the owner.
241
+ one.patch('/views/:viewId', personalWorkspace, async c => {
251
242
  const ws = c.get('ws')
252
243
  const body = await c.req.json().catch(() => null)
253
244
  if (await getPendingView(ws, c.req.param('viewId'))) {
@@ -283,7 +274,7 @@ one.patch('/views/:viewId', async c => {
283
274
  }
284
275
  })
285
276
 
286
- one.delete('/views/:viewId', async c => {
277
+ one.delete('/views/:viewId', personalWorkspace, async c => {
287
278
  const ws = c.get('ws')
288
279
  try {
289
280
  const viewId = c.req.param('viewId')
@@ -305,19 +296,19 @@ one.delete('/views/:viewId', async c => {
305
296
  }
306
297
  })
307
298
 
308
- one.get('/views/*', c => {
299
+ one.get('/views/*', ownerWorkspace, c => {
309
300
  const ws = c.get('ws')
310
301
  const { name, file } = parseAppletTail(c.req.url, ws.id, 'views')
311
302
  if (!name) return c.text('Not found', 404)
312
303
  return serveView(name, file, ws.path, workspaceApiBase(ws.id), c.req.header('if-none-match'))
313
304
  })
314
305
 
315
- one.post('/views', async c => {
306
+ one.post('/views', personalWorkspace, async c => {
316
307
  const ws = c.get('ws')
317
308
  return c.json(await createPendingView(ws), 201)
318
309
  })
319
310
 
320
- one.post('/views/:viewId/submit', async c => {
311
+ one.post('/views/:viewId/submit', personalWorkspace, async c => {
321
312
  const ws = c.get('ws')
322
313
  const body = await c.req.json<{
323
314
  requirements?: string
@@ -356,7 +347,7 @@ one.post('/views/:viewId/submit', async c => {
356
347
  speedMode: isSpeedMode(body.speedMode) ? body.speedMode : undefined,
357
348
  stream: body.stream === true ? true : undefined
358
349
  })
359
- return c.json(result)
350
+ return c.json({ ...result, state: await getWorkspaceState(ws) })
360
351
  } catch (err) {
361
352
  if (err instanceof PendingViewError) return c.text(err.message, err.status)
362
353
  if (err instanceof ViewStartupError)
@@ -370,7 +361,7 @@ one.post('/views/:viewId/submit', async c => {
370
361
  // dotfiles (`.env`, `.moi`, `.git`) are rejected and only media/asset extensions
371
362
  // are allowed — the workspace holds secrets, and this route is unauthenticated.
372
363
  // localhost binding is NOT the guard.
373
- one.get('/files/*', c => {
364
+ one.get('/files/*', ownerWorkspace, c => {
374
365
  const ws = c.get('ws')
375
366
  const tail = new URL(c.req.url).pathname.split(`${workspaceApiBase(ws.id)}/files/`)[1] ?? ''
376
367
  return serveWorkspaceFile(ws.path, tail, c.req.header('range'), c.req.header('if-none-match'))
@@ -379,7 +370,7 @@ one.get('/files/*', c => {
379
370
  // Applet RPC — the home for server-function calls from a bundle. The bundle's
380
371
  // sentinel base resolves to `/api/workspaces/<id>`, so it POSTs to
381
372
  // `…/rpc/<module>/<fn>`.
382
- one.post('/rpc/*', c => {
373
+ one.post('/rpc/*', ownerWorkspace, c => {
383
374
  const ws = c.get('ws')
384
375
  const tail = new URL(c.req.url).pathname.split(`${workspaceApiBase(ws.id)}/rpc/`)[1] ?? ''
385
376
  return handleFunctionCall(c.req.raw, tail, ws.path)
@@ -392,7 +383,7 @@ one.post('/rpc/*', c => {
392
383
  // sources (`build`/`rpc` are server-recorded and can't be spoofed by a tab),
393
384
  // pattern-check the applet name, cap the batch size; applets/log.ts caps string
394
385
  // lengths.
395
- one.post('/applet-log', async c => {
386
+ one.post('/applet-log', ownerWorkspace, async c => {
396
387
  let body: { events?: unknown }
397
388
  try {
398
389
  body = await c.req.json()
@@ -435,7 +426,7 @@ one.post('/applet-log', async c => {
435
426
  // Downscaled image preview of a workspace file. The chat's expanded tool rows
436
427
  // use this to show the picture an agent `Read` — same guards as /files/ above,
437
428
  // images only, resized server-side (see server/workspaces/preview.ts).
438
- one.get('/preview/*', c => {
429
+ one.get('/preview/*', personalWorkspace, c => {
439
430
  const ws = c.get('ws')
440
431
  const tail = new URL(c.req.url).pathname.split(`${workspaceApiBase(ws.id)}/preview/`)[1] ?? ''
441
432
  return serveWorkspaceImagePreview(ws.path, tail, c.req.header('if-none-match'))
@@ -446,7 +437,7 @@ one.get('/preview/*', c => {
446
437
  // upload ids the chat WS frame references. Images are downscaled and inlined as
447
438
  // vision blocks at send time; other files are referenced by a temp path. See
448
439
  // server/uploads.ts and dev/file-uploads.md.
449
- one.post('/uploads', async c => {
440
+ one.post('/uploads', personalWorkspace, async c => {
450
441
  const ws = c.get('ws')
451
442
  let form: FormData
452
443
  try {
@@ -481,7 +472,7 @@ one.post('/uploads', async c => {
481
472
  })
482
473
 
483
474
  // Existing workspace documents enter the same upload pipeline without a browser round trip.
484
- one.post('/uploads/from-path', async c => {
475
+ one.post('/uploads/from-path', personalWorkspace, async c => {
485
476
  const body: unknown = await c.req.json().catch(() => null)
486
477
  if (!body || typeof body !== 'object' || !('path' in body) || typeof body.path !== 'string') {
487
478
  return c.text('Choose a file from this workspace', 400)
@@ -507,7 +498,7 @@ one.post('/uploads/from-path', async c => {
507
498
  // base64 data URL so the transcript broadcast / client cache stay small. The id
508
499
  // is content-addressed (sha256), so the response is immutable while it lives —
509
500
  // let the browser cache it for the store's TTL.
510
- one.get('/uploads/:uploadId', c => {
501
+ one.get('/uploads/:uploadId', personalWorkspace, c => {
511
502
  const u = getUpload(c.get('ws').id, c.req.param('uploadId'))
512
503
  if (!u) return c.text('Not found or expired', 404)
513
504
  const body = u.data ? new Uint8Array(u.data) : u.path ? Bun.file(u.path) : null
@@ -521,18 +512,25 @@ one.get('/uploads/:uploadId', c => {
521
512
  })
522
513
  })
523
514
 
524
- // Per-user chat state: pin, the chat each tab shows, per-chat settings and
525
- // fork history, and views being built. Every write below answers with the new
526
- // state; other clients get it as `state:changed`.
527
- one.get('/state', async c => c.json(await getWorkspaceState(c.get('ws'))))
515
+ // Personal state writes return the latest snapshot and publish `state:changed`.
516
+ one.get('/state', personalWorkspace, async c => c.json(await getWorkspaceState(c.get('ws'))))
517
+
518
+ one.put('/state/tabs', personalWorkspace, async c => {
519
+ const body = await c.req.json().catch(() => null)
520
+ const ws = c.get('ws')
521
+ await updateWorkspaceState(ws, state => {
522
+ state.openTabs = normalizeOpenTabs(body?.openTabs)
523
+ })
524
+ return c.json(await getWorkspaceState(ws))
525
+ })
528
526
 
529
527
  // The agent's chats. Tab ownership and settings come from `/state`.
530
- one.get('/sessions', async c => {
528
+ one.get('/sessions', personalWorkspace, async c => {
531
529
  const ws = c.get('ws')
532
530
  return c.json(await harnessFor(ws).listSessions(ws))
533
531
  })
534
532
 
535
- one.put('/sessions/:sessionId/pin', async c => {
533
+ one.put('/sessions/:sessionId/pin', personalWorkspace, async c => {
536
534
  const ws = c.get('ws')
537
535
  const sessionId = c.req.param('sessionId')
538
536
  const harness = harnessFor(ws)
@@ -545,7 +543,7 @@ one.put('/sessions/:sessionId/pin', async c => {
545
543
  return c.json(await getWorkspaceState(ws))
546
544
  })
547
545
 
548
- one.delete('/sessions/:sessionId/pin', async c => {
546
+ one.delete('/sessions/:sessionId/pin', personalWorkspace, async c => {
549
547
  const ws = c.get('ws')
550
548
  await unpinSession(ws, c.req.param('sessionId'))
551
549
  return c.json(await getWorkspaceState(ws))
@@ -553,7 +551,7 @@ one.delete('/sessions/:sessionId/pin', async c => {
553
551
 
554
552
  // Show the chat in a tab. `ifMatch` (a chat id, or null for none) applies the
555
553
  // change only while the tab still shows that chat.
556
- one.put('/sessions/:sessionId/selection', async c => {
554
+ one.put('/sessions/:sessionId/selection', personalWorkspace, async c => {
557
555
  const ws = c.get('ws')
558
556
  const body: unknown = await c.req.json().catch(() => null)
559
557
  if (!body || typeof body !== 'object') return c.text('Bad request', 400)
@@ -574,7 +572,7 @@ one.put('/sessions/:sessionId/selection', async c => {
574
572
 
575
573
  // Stop showing the chat in a tab, which then opens a new chat. A tab showing
576
574
  // another chat is left alone.
577
- one.delete('/sessions/:sessionId/selection', async c => {
575
+ one.delete('/sessions/:sessionId/selection', personalWorkspace, async c => {
578
576
  const ws = c.get('ws')
579
577
  const body: unknown = await c.req.json().catch(() => null)
580
578
  const tabId = (body as { tabId?: unknown } | null)?.tabId
@@ -584,34 +582,39 @@ one.delete('/sessions/:sessionId/selection', async c => {
584
582
  })
585
583
 
586
584
  // Change run settings. Omitted fields stay; null clears one.
587
- one.on('PATCH', ['/sessions/:sessionId/config', '/state/chat-defaults'], async c => {
588
- const body = await c.req.json().catch(() => null)
589
- if (typeof body !== 'object' || body === null) {
590
- return c.text('Expected a JSON object', 400)
591
- }
592
- const patch: SessionConfigPatch = {}
593
- const record = body as Record<string, unknown>
594
- for (const key of ['model', 'effort'] as const) {
595
- if (!(key in record)) continue
596
- const value = record[key]
597
- if (value !== null && typeof value !== 'string') {
598
- return c.text(`${key} must be a string or null`, 400)
585
+ one.on(
586
+ 'PATCH',
587
+ ['/sessions/:sessionId/config', '/state/chat-defaults'],
588
+ personalWorkspace,
589
+ async c => {
590
+ const body = await c.req.json().catch(() => null)
591
+ if (typeof body !== 'object' || body === null) {
592
+ return c.text('Expected a JSON object', 400)
599
593
  }
600
- patch[key] = value
601
- }
602
- if ('speedMode' in record) {
603
- const value = record.speedMode
604
- if (value !== null && !isSpeedMode(value)) {
605
- return c.text('speedMode must be "normal", "fast", "ultrafast", or null', 400)
594
+ const patch: SessionConfigPatch = {}
595
+ const record = body as Record<string, unknown>
596
+ for (const key of ['model', 'effort'] as const) {
597
+ if (!(key in record)) continue
598
+ const value = record[key]
599
+ if (value !== null && typeof value !== 'string') {
600
+ return c.text(`${key} must be a string or null`, 400)
601
+ }
602
+ patch[key] = value
606
603
  }
607
- patch.speedMode = value
604
+ if ('speedMode' in record) {
605
+ const value = record.speedMode
606
+ if (value !== null && !isSpeedMode(value)) {
607
+ return c.text('speedMode must be "normal", "fast", "ultrafast", or null', 400)
608
+ }
609
+ patch.speedMode = value
610
+ }
611
+ const ws = c.get('ws')
612
+ await saveSessionConfig(ws, c.req.param('sessionId'), patch)
613
+ return c.json(await getWorkspaceState(ws))
608
614
  }
609
- const ws = c.get('ws')
610
- await saveSessionConfig(ws, c.req.param('sessionId'), patch)
611
- return c.json(await getWorkspaceState(ws))
612
- })
615
+ )
613
616
 
614
- one.post('/sessions/:sessionId/archive', async c => {
617
+ one.post('/sessions/:sessionId/archive', personalWorkspace, async c => {
615
618
  const ws = c.get('ws')
616
619
  const harness = harnessFor(ws)
617
620
  const sessionId = c.req.param('sessionId')
@@ -630,13 +633,13 @@ one.post('/sessions/:sessionId/archive', async c => {
630
633
  }
631
634
  })
632
635
 
633
- one.get('/sessions/:sessionId/events', async c => {
636
+ one.get('/sessions/:sessionId/events', personalWorkspace, async c => {
634
637
  const ws = c.get('ws')
635
638
  const sessionId = c.req.param('sessionId')
636
639
  return c.json(await harnessFor(ws).sessionEvents(ws, sessionId))
637
640
  })
638
641
 
639
- one.get('/mcp', async c => {
642
+ one.get('/mcp', personalWorkspace, async c => {
640
643
  const ws = c.get('ws')
641
644
  const harness = harnessFor(ws)
642
645
  if (c.req.query('stream') !== 'true') return c.json((await harness.mcpStatus?.(ws)) ?? [])
@@ -670,7 +673,7 @@ one.get('/mcp', async c => {
670
673
  // (Codex: app-server JSON-RPC, both directions; Claude Code: raw SDK messages
671
674
  // + enqueued inputs) and the exact frames the server pushed to chat clients.
672
675
  // `sinceWire`/`sinceBroadcast` are seq cursors so the page can poll deltas.
673
- one.get('/harness/debug', async c => {
676
+ one.get('/harness/debug', personalWorkspace, async c => {
674
677
  const ws = c.get('ws')
675
678
  const harness = harnessFor(ws)
676
679
  const sinceWire = Number(c.req.query('sinceWire') ?? 0) || 0
@@ -685,7 +688,7 @@ one.get('/harness/debug', async c => {
685
688
 
686
689
  // Per-workspace env vars. GET returns the effective view (discovered `.env` + UI
687
690
  // custom secrets + scopes + declared-required keys; values masked).
688
- one.get('/env', async c => {
691
+ one.get('/env', personalWorkspace, async c => {
689
692
  const ws = c.get('ws')
690
693
  // Unawaited on purpose: getWorkspaceEnvView loads it in parallel with the
691
694
  // env stores (manifest reads and env reads are independent).
@@ -696,7 +699,7 @@ one.get('/env', async c => {
696
699
  // then reaps the workspace's function worker and idle agent sessions so the next
697
700
  // call/message picks up the change (env is frozen at spawn — a hard restart is
698
701
  // the only way).
699
- one.put('/env', async c => {
702
+ one.put('/env', personalWorkspace, async c => {
700
703
  const ws = c.get('ws')
701
704
  const patch = parseEnvUpdate(await c.req.json().catch(() => null))
702
705
  if (typeof patch === 'string') return c.text(patch, 400)
@@ -714,12 +717,12 @@ one.put('/env', async c => {
714
717
  return c.json(await getWorkspaceEnvView(ws.path, requiredEnvFor(ws.path)))
715
718
  })
716
719
 
717
- one.get('/skills', async c => {
720
+ one.get('/skills', personalWorkspace, async c => {
718
721
  const ws = c.get('ws')
719
722
  return c.json(await getWorkspaceSkillsStatus(ws.path, ws.harness))
720
723
  })
721
724
 
722
- one.post('/skills/update', async c => {
725
+ one.post('/skills/update', personalWorkspace, async c => {
723
726
  const ws = c.get('ws')
724
727
  const result = await updateWorkspaceSkills(ws.path, ws.harness ?? 'claude-code')
725
728
  return c.json(result.status)
@@ -727,7 +730,7 @@ one.post('/skills/update', async c => {
727
730
 
728
731
  // Workspace configuration and models. Shared account status is served by
729
732
  // /harnesses/status; only workspace overrides and gateways are probed here.
730
- one.get('/harness', async c => {
733
+ one.get('/harness', personalWorkspace, async c => {
731
734
  const ws = c.get('ws')
732
735
  const harness = harnessFor(ws)
733
736
  const capabilities = {
@@ -781,11 +784,11 @@ one.get('/harness', async c => {
781
784
  })
782
785
 
783
786
  // Workspace identity. Uploads use the image route below.
784
- one.get('/config', async c => {
787
+ one.get('/config', ownerWorkspace, async c => {
785
788
  return c.json(await getWorkspaceConfig(c.get('ws').path))
786
789
  })
787
790
 
788
- one.put('/config', async c => {
791
+ one.put('/config', ownerWorkspace, async c => {
789
792
  const ws = c.get('ws')
790
793
  const parsed: unknown = await c.req.json().catch(() => null)
791
794
  if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
@@ -814,7 +817,7 @@ one.put('/config', async c => {
814
817
  // `origin` is the writing tab's id — echoed in the broadcast so that tab can
815
818
  // ignore its own save. This is the browser's write path; the agent's draws are
816
819
  // written server-side (see server/scratchpad/executor.ts). See docs/moi-scratchpad.md.
817
- one.post('/scratchpad/ops', async c => {
820
+ one.post('/scratchpad/ops', ownerWorkspace, async c => {
818
821
  try {
819
822
  const form = await c.req.formData()
820
823
  const op = JSON.parse(String(form.get('op'))) as ScratchOp | null
@@ -832,11 +835,11 @@ one.post('/scratchpad/ops', async c => {
832
835
  }
833
836
  })
834
837
 
835
- one.get('/scratchpad', async c => {
838
+ one.get('/scratchpad', ownerWorkspace, async c => {
836
839
  return c.json(await loadScratchpadDoc(c.get('ws').path))
837
840
  })
838
841
 
839
- one.put('/scratchpad', async c => {
842
+ one.put('/scratchpad', ownerWorkspace, async c => {
840
843
  const ws = c.get('ws')
841
844
  const body = await c.req.json().catch(() => null)
842
845
  if (!body || typeof body !== 'object' || !body.document) {
@@ -856,7 +859,7 @@ one.put('/scratchpad', async c => {
856
859
  // never inlined as base64 in the JSON (see server/scratchpad/assets.ts). The
857
860
  // browser's TLAssetStore POSTs the raw file here on paste and resolves `asset:`
858
861
  // srcs back through the GET when rendering.
859
- one.post('/scratchpad/assets', async c => {
862
+ one.post('/scratchpad/assets', ownerWorkspace, async c => {
860
863
  const length = Number(c.req.header('content-length') ?? 0)
861
864
  if (length > MAX_ASSET_BYTES) {
862
865
  return c.text(`Asset too large (max ${MAX_ASSET_BYTES / (1024 * 1024)} MB)`, 413)
@@ -872,7 +875,7 @@ one.post('/scratchpad/assets', async c => {
872
875
 
873
876
  // The file name is content-addressed (sha256 of the bytes), so a hit is
874
877
  // immutable — let the browser cache it indefinitely.
875
- one.get('/scratchpad/assets/:file', async c => {
878
+ one.get('/scratchpad/assets/:file', ownerWorkspace, async c => {
876
879
  const resolved = scratchpadAssetFile(c.get('ws').path, c.req.param('file'))
877
880
  if (!resolved || !(await resolved.file.exists())) return c.text('Not found', 404)
878
881
  return new Response(resolved.file, {
@@ -890,7 +893,7 @@ one.get('/scratchpad/assets/:file', async c => {
890
893
 
891
894
  // Workspace upload. PUT resizes an image to a 128×128 WebP. DELETE resets any
892
895
  // custom icon to the provider default. Both broadcast for a live refresh.
893
- one.put('/icon', async c => {
896
+ one.put('/icon', ownerWorkspace, async c => {
894
897
  const ws = c.get('ws')
895
898
  const bytes = new Uint8Array(await c.req.arrayBuffer())
896
899
  if (bytes.length === 0) return c.text('Empty image body', 400)
@@ -907,7 +910,7 @@ one.put('/icon', async c => {
907
910
  return c.json({ icon: workspaceIcon })
908
911
  })
909
912
 
910
- one.delete('/icon', async c => {
913
+ one.delete('/icon', ownerWorkspace, async c => {
911
914
  await setWorkspaceConfig(c.get('ws').path, { icon: null })
912
915
  publishEvent({ type: 'workspace:updated', workspaceId: c.get('ws').id })
913
916
  return c.body(null, 204)
@@ -916,7 +919,7 @@ one.delete('/icon', async c => {
916
919
  // All info about a single workspace: its persisted layout (widget grid, layout
917
920
  // mode, theme) plus server-resolved metadata. GET reads, PUT writes the layout,
918
921
  // DELETE unregisters.
919
- one.get('/', async c => {
922
+ one.get('/', personalWorkspace, async c => {
920
923
  const ws = c.get('ws')
921
924
  const config = await loadWorkspaceFileConfig(ws.path)
922
925
  if (config.remote) {
@@ -947,11 +950,11 @@ one.get('/', async c => {
947
950
 
948
951
  // Thumbnail freshness records, without image bytes — the capture hook compares
949
952
  // these against live bundle revisions. Images are served per-applet below.
950
- one.get('/applet-thumbnails', async c =>
953
+ one.get('/applet-thumbnails', ownerWorkspace, async c =>
951
954
  c.json({ thumbnails: await getAppletThumbnailRecords(c.get('ws').path) })
952
955
  )
953
956
 
954
- one.get('/applet-thumbnails/:kind/:name', c => {
957
+ one.get('/applet-thumbnails/:kind/:name', ownerWorkspace, c => {
955
958
  const kind = c.req.param('kind')
956
959
  if (kind !== 'widget' && kind !== 'view') return c.text('Not found', 404)
957
960
  // `<id>` or `<id>:<version>`. Applet ids never contain `:`, and the version
@@ -967,7 +970,7 @@ one.get('/applet-thumbnails/:kind/:name', c => {
967
970
  })
968
971
 
969
972
  // Settled widget and view visits share one batch endpoint and storage path.
970
- one.put('/applet-thumbnails', async c => {
973
+ one.put('/applet-thumbnails', ownerWorkspace, async c => {
971
974
  const body: unknown = await c.req.json().catch(() => null)
972
975
  if (!body || typeof body !== 'object' || Array.isArray(body)) return c.text('Bad request', 400)
973
976
  const input = body as AppletThumbnailBatch
@@ -992,7 +995,7 @@ one.put('/applet-thumbnails', async c => {
992
995
  return c.body(null, 204)
993
996
  })
994
997
 
995
- one.put('/', async c => {
998
+ one.put('/', personalWorkspace, async c => {
996
999
  const ws = c.get('ws')
997
1000
  if (ws.remote) {
998
1001
  return c.text(
@@ -1018,8 +1021,9 @@ one.put('/', async c => {
1018
1021
  return c.body(null, 204)
1019
1022
  })
1020
1023
 
1021
- one.delete('/', async c => {
1024
+ one.delete('/', personalWorkspace, async c => {
1022
1025
  const ws = c.get('ws')
1026
+ if (ws.remote) return c.text('Leaving remote workspaces is not available yet', 403)
1023
1027
  const ok = await removeWorkspace(ws.id)
1024
1028
  if (!ok) return c.text('Workspace not found', 404)
1025
1029
  harnessFor(ws).stopWorkspace?.(ws.path)
@@ -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