moi-computer 0.12.1-next.1 → 0.12.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 (123) hide show
  1. package/client/AGENTS.md +3 -2
  2. package/client/api/app-config.ts +3 -9
  3. package/client/api/workspace-keys.ts +2 -1
  4. package/client/app/app-provider.tsx +25 -0
  5. package/client/app/app-router.tsx +2 -0
  6. package/client/app/routes/settings-route.tsx +10 -0
  7. package/client/app/routes/workspace-route.tsx +4 -0
  8. package/client/app/shell/sidebar-layout.tsx +38 -51
  9. package/client/dev/index.html +5 -5
  10. package/client/features/account/account-menu.tsx +96 -0
  11. package/client/features/account/account-provider.tsx +142 -0
  12. package/client/features/account/account-test-utils.tsx +293 -0
  13. package/client/features/account/api.ts +142 -0
  14. package/client/features/account/identity.ts +23 -0
  15. package/client/features/applets/api.ts +1 -1
  16. package/client/features/chat/connection/chat-frames.ts +2 -2
  17. package/client/features/chat/sessions/api.ts +1 -1
  18. package/client/features/chat/use-chat.ts +1 -1
  19. package/client/features/collab/applet-api.ts +15 -14
  20. package/client/features/collab/components/cursors.tsx +61 -24
  21. package/client/features/collab/components/presence-avatars.tsx +25 -12
  22. package/client/features/collab/components/presence-frame.tsx +20 -24
  23. package/client/features/collab/components/presence-group.tsx +15 -7
  24. package/client/features/collab/components/user-avatar-group.tsx +21 -8
  25. package/client/features/collab/components/user-avatar.tsx +38 -7
  26. package/client/features/collab/components/user.tsx +31 -12
  27. package/client/features/collab/host-state.ts +24 -7
  28. package/client/features/collab/local-user.ts +1 -1
  29. package/client/features/collab/proxy-user.ts +4 -9
  30. package/client/features/collab/users.ts +0 -5
  31. package/client/features/collab/workspace-users-menu.tsx +3 -3
  32. package/client/features/demo/demo-dialog.tsx +25 -79
  33. package/client/features/dev/collab/collab-playground.tsx +7 -7
  34. package/client/features/dev/collab/local-user-settings.tsx +7 -53
  35. package/client/features/dev/workspace-setup-preview.tsx +43 -16
  36. package/client/features/harness/device-login-steps.tsx +2 -2
  37. package/client/features/home/api.ts +29 -9
  38. package/client/features/home/home-page.tsx +7 -4
  39. package/client/features/scratchpad/scratchpad.tsx +3 -6
  40. package/client/features/settings/api.ts +14 -8
  41. package/client/features/settings/connectors-settings.tsx +3 -3
  42. package/client/features/settings/environment-settings.tsx +3 -3
  43. package/client/features/settings/general-settings.tsx +1 -1
  44. package/client/features/settings/profile-settings.tsx +95 -0
  45. package/client/features/settings/settings-page.tsx +44 -0
  46. package/client/features/settings/settings-section.tsx +26 -0
  47. package/client/features/settings/users-settings.tsx +195 -0
  48. package/client/features/update/update-control.tsx +1 -1
  49. package/client/features/workspace/add/create-workspace-dialog.tsx +5 -2
  50. package/client/features/workspace/api.ts +12 -16
  51. package/client/features/workspace/setup/workspace-login-state.tsx +4 -4
  52. package/client/features/workspace/setup/workspace-setup.tsx +2 -1
  53. package/client/features/workspace/workspace-content.tsx +12 -52
  54. package/client/features/workspace/workspace-frame.tsx +76 -0
  55. package/client/features/workspace/workspace-layout-context.tsx +2 -0
  56. package/client/features/workspace/workspace-pending-screen.tsx +26 -0
  57. package/client/features/workspace/workspace-screen.tsx +3 -3
  58. package/client/index.html +28 -9
  59. package/client/index.tsx +7 -2
  60. package/client/lib/browser-tab-id.ts +4 -0
  61. package/client/lib/user-display-name.ts +6 -0
  62. package/client/main.tsx +12 -6
  63. package/client/runtime/app-context.ts +20 -0
  64. package/client/runtime/use-workspace-events.ts +29 -153
  65. package/client/runtime/workspace-events.ts +151 -0
  66. package/dist/chunk-20ynagd4.js +2 -0
  67. package/dist/chunk-42tde9a6.js +1 -0
  68. package/dist/chunk-9w543s0r.js +2 -0
  69. package/dist/{chunk-q0gbdts4.js → chunk-a5372n61.js} +71 -71
  70. package/dist/chunk-aja9y1vn.js +68 -0
  71. package/dist/chunk-fvcvrh3d.css +1 -0
  72. package/dist/chunk-gtfjw3nx.js +1 -0
  73. package/dist/{chunk-hvh9f5h0.js → chunk-j39y2aky.js} +1 -1
  74. package/dist/chunk-pja30km3.js +1 -0
  75. package/dist/{chunk-d7cbm65e.js → chunk-rm894bc2.js} +1 -1
  76. package/dist/chunk-tevvtfbk.js +10 -0
  77. package/dist/{chunk-jvyvwwv3.js → chunk-tgt9zd0r.js} +1 -1
  78. package/dist/chunk-tv5k5z00.js +1 -0
  79. package/dist/chunk-zq2ae5dx.js +2 -0
  80. package/dist/index.html +29 -10
  81. package/lib/ids.ts +2 -2
  82. package/lib/types.ts +1 -1
  83. package/package.json +1 -1
  84. package/server/api/index.ts +43 -28
  85. package/server/app-config.ts +7 -0
  86. package/server/applets/thumbnails.ts +8 -5
  87. package/server/harness/codex/thread-list.ts +4 -0
  88. package/server/static.ts +4 -2
  89. package/server/vendor.ts +23 -30
  90. package/server/web.ts +4 -2
  91. package/server/workspaces/init.ts +0 -10
  92. package/server/workspaces/layout.ts +11 -6
  93. package/server/workspaces/registry.ts +31 -9
  94. package/dist/chunk-08ndj2rg.js +0 -2
  95. package/dist/chunk-2x040tmg.js +0 -68
  96. package/dist/chunk-3smxq0ts.js +0 -1
  97. package/dist/chunk-68ch5hs8.js +0 -2
  98. package/dist/chunk-9vg3xa81.js +0 -2
  99. package/dist/chunk-c2p00p9j.css +0 -1
  100. package/dist/chunk-cs833y9j.js +0 -1
  101. package/dist/chunk-nwevqe86.js +0 -10
  102. package/dist/chunk-rt30jbcm.js +0 -1
  103. package/dist/chunk-y5y3kj67.js +0 -1
  104. /package/client/vendor/react/{development → 19.2.4/development}/_impl/react-dom-client.js +0 -0
  105. /package/client/vendor/react/{development → 19.2.4/development}/_impl/react-dom.js +0 -0
  106. /package/client/vendor/react/{development → 19.2.4/development}/_impl/react-jsx-dev-runtime.js +0 -0
  107. /package/client/vendor/react/{development → 19.2.4/development}/_impl/react-jsx-runtime.js +0 -0
  108. /package/client/vendor/react/{development → 19.2.4/development}/_impl/react.js +0 -0
  109. /package/client/vendor/react/{development → 19.2.4/development}/react-dom-client.js +0 -0
  110. /package/client/vendor/react/{development → 19.2.4/development}/react-dom.js +0 -0
  111. /package/client/vendor/react/{development → 19.2.4/development}/react-jsx-dev-runtime.js +0 -0
  112. /package/client/vendor/react/{development → 19.2.4/development}/react-jsx-runtime.js +0 -0
  113. /package/client/vendor/react/{development → 19.2.4/development}/react.js +0 -0
  114. /package/client/vendor/react/{production → 19.2.4/production}/_impl/react-dom-client.js +0 -0
  115. /package/client/vendor/react/{production → 19.2.4/production}/_impl/react-dom.js +0 -0
  116. /package/client/vendor/react/{production → 19.2.4/production}/_impl/react-jsx-dev-runtime.js +0 -0
  117. /package/client/vendor/react/{production → 19.2.4/production}/_impl/react-jsx-runtime.js +0 -0
  118. /package/client/vendor/react/{production → 19.2.4/production}/_impl/react.js +0 -0
  119. /package/client/vendor/react/{production → 19.2.4/production}/react-dom-client.js +0 -0
  120. /package/client/vendor/react/{production → 19.2.4/production}/react-dom.js +0 -0
  121. /package/client/vendor/react/{production → 19.2.4/production}/react-jsx-dev-runtime.js +0 -0
  122. /package/client/vendor/react/{production → 19.2.4/production}/react-jsx-runtime.js +0 -0
  123. /package/client/vendor/react/{production → 19.2.4/production}/react.js +0 -0
@@ -1,2 +1,2 @@
1
1
  async function s(t,e){let o=await t.text();return Error(o||e)}async function i(t,e,o="Request failed"){let n=await fetch(t,e);if(!n.ok)throw await s(n,o);return n.json()}async function r(t,e,o="Request failed"){let n=await fetch(t,e);if(!n.ok)throw await s(n,o)}function a(t,e){return{method:t,headers:{"Content-Type":"application/json"},body:e===void 0?void 0:JSON.stringify(e)}}
2
- export{i as Rc,r as Sc,a as Tc};
2
+ export{i as cd,r as dd,a as ed};
@@ -0,0 +1 @@
1
+ import{Mc as a,Nc as b}from"/chunk-20ynagd4.js";import"/chunk-zq2ae5dx.js";import"/chunk-tgt9zd0r.js";import"/chunk-rm894bc2.js";export{b as useAppConfig,a as loadAppConfig};
@@ -0,0 +1,2 @@
1
+ import{gd as e}from"/chunk-rm894bc2.js";var o=e((a,t)=>{t.exports=globalThis.__esm.react});
2
+ export{o as Oc};
package/dist/index.html CHANGED
@@ -20,23 +20,42 @@
20
20
  }
21
21
  </style>
22
22
  <link rel="icon" type="image/png" href="/favicon-nbmyjfjh.png" />
23
- <!-- React is vendored locally (client/vendor/react, generated by
24
- scripts/build-vendor.ts) and served by the /vendor/react route, so moi
25
- runs fully offline — no CDN fetch. The server picks the development or
26
- production build per environment behind these stable URLs. -->
23
+ <!-- React is vendored locally (client/vendor/react/<version>, generated by
24
+ scripts/build-vendor.ts, which also rewrites these URLs) and served by
25
+ the /vendor/react route, so moi runs fully offline — no CDN fetch. The
26
+ version and build mode in the path let the browser cache them forever;
27
+ this source names the development build and scripts/build-client.ts
28
+ switches it to production in dist/. -->
27
29
  <script type="importmap">
28
30
  {
29
31
  "imports": {
30
- "react": "/vendor/react/react.js",
31
- "react/jsx-runtime": "/vendor/react/react-jsx-runtime.js",
32
- "react/jsx-dev-runtime": "/vendor/react/react-jsx-dev-runtime.js",
33
- "react-dom": "/vendor/react/react-dom.js",
34
- "react-dom/client": "/vendor/react/react-dom-client.js"
32
+ "react": "/vendor/react/19.2.4/production/react.js",
33
+ "react/jsx-runtime": "/vendor/react/19.2.4/production/react-jsx-runtime.js",
34
+ "react/jsx-dev-runtime": "/vendor/react/19.2.4/production/react-jsx-dev-runtime.js",
35
+ "react-dom": "/vendor/react/19.2.4/production/react-dom.js",
36
+ "react-dom/client": "/vendor/react/19.2.4/production/react-dom-client.js"
35
37
  }
36
38
  }
37
39
  </script>
40
+ <!-- Fetch React (the wrappers and the _impl files they import) as soon as
41
+ the HTML is parsed, instead of two round trips later when the preload
42
+ script below gets to run. Must stay after the importmap: a module
43
+ fetch that starts before the map is parsed disables the map. -->
44
+ <link rel="modulepreload" href="/vendor/react/19.2.4/production/react.js" />
45
+ <link rel="modulepreload" href="/vendor/react/19.2.4/production/_impl/react.js" />
46
+ <link rel="modulepreload" href="/vendor/react/19.2.4/production/react-jsx-runtime.js" />
47
+ <link rel="modulepreload" href="/vendor/react/19.2.4/production/_impl/react-jsx-runtime.js" />
48
+ <link rel="modulepreload" href="/vendor/react/19.2.4/production/react-jsx-dev-runtime.js" />
49
+ <link
50
+ rel="modulepreload"
51
+ href="/vendor/react/19.2.4/production/_impl/react-jsx-dev-runtime.js"
52
+ />
53
+ <link rel="modulepreload" href="/vendor/react/19.2.4/production/react-dom.js" />
54
+ <link rel="modulepreload" href="/vendor/react/19.2.4/production/_impl/react-dom.js" />
55
+ <link rel="modulepreload" href="/vendor/react/19.2.4/production/react-dom-client.js" />
56
+ <link rel="modulepreload" href="/vendor/react/19.2.4/production/_impl/react-dom-client.js" />
38
57
 
39
- <link rel="stylesheet" crossorigin href="/chunk-c2p00p9j.css"><script type="module" crossorigin src="/chunk-y5y3kj67.js"></script></head>
58
+ <link rel="stylesheet" crossorigin href="/chunk-fvcvrh3d.css"><script type="module" crossorigin src="/chunk-pja30km3.js"></script></head>
40
59
  <body>
41
60
  <div id="root"></div>
42
61
 
package/lib/ids.ts CHANGED
@@ -10,12 +10,12 @@ export const newWorkspaceId = customAlphabet(ALPHABET, 10)
10
10
 
11
11
  // Ids no workspace can hold, because a URL carrying one never reaches it:
12
12
  // `/api/workspaces/:id` is registered after the literal collection routes, so
13
- // `create`, `discover` and `order` match those instead, and `ws` is claimed by
13
+ // `create`, `discover`, `order` and `previews` match those instead, and `ws` is claimed by
14
14
  // the live-event WebSocket upgrade in `server/web.ts` before Hono sees the
15
15
  // request. A workspace registered under one of these would persist fine and
16
16
  // then be unreachable in the app. `server/api/reserved-ids.test.ts` re-derives
17
17
  // this list from the router so a new collection route cannot outgrow it.
18
- export const RESERVED_WORKSPACE_IDS = ['create', 'discover', 'order', 'ws']
18
+ export const RESERVED_WORKSPACE_IDS = ['create', 'discover', 'order', 'previews', 'ws']
19
19
 
20
20
  // Ids may also be chosen by hand (`moi init --id <id>`), so they are validated
21
21
  // rather than assumed. Slightly wider than the generated alphabet — dashes and
package/lib/types.ts CHANGED
@@ -552,7 +552,7 @@ export type WorkspaceEntry = {
552
552
  export type DiscoveredWorkspace = {
553
553
  path: string
554
554
  displayPath?: string
555
- // Deduplicated in canonical provider order by the discovery API.
555
+ // Deduplicated in canonical provider order; empty for folders without agent history.
556
556
  types: WorkspaceType[]
557
557
  }
558
558
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moi-computer",
3
- "version": "0.12.1-next.1",
3
+ "version": "0.12.1-next.3",
4
4
  "description": "Local AI workspace powered by the Claude Agent SDK, Bun, React, and Tailwind. Requires Bun.",
5
5
  "license": "Elastic-2.0",
6
6
  "type": "module",
@@ -26,7 +26,7 @@ import { proxyUserState } from '../collab/cloudflare-access'
26
26
  import { collabManager } from '../collab/manager'
27
27
  import { harnessStore } from '../harness/auth'
28
28
  import { harnesses } from './harnesses'
29
- import { clientAppConfig, getAppConfig } from '../app-config'
29
+ import { clientAppConfig, createdWorkspacesRoot, getAppConfig } from '../app-config'
30
30
  import { getAppSettings, pickAppSettingsPatch, saveAppSettings } from '../app-settings'
31
31
  import { appletForModule, recordAppletError } from '../applets/log'
32
32
  import { apiBaseFor, parseAppletTail, serveWorkspaceFile } from '../applets'
@@ -94,11 +94,7 @@ import {
94
94
  import { submitView, ViewStartupError } from '../sessions/view-sessions'
95
95
  import { listWidgets, serveWidget } from '../applets/widgets'
96
96
  import { getWorkspaceConfig, setWorkspaceConfig } from '../workspaces/config'
97
- import {
98
- createdWorkspacesRoot,
99
- provisionWorkspace,
100
- validateWorkspaceFolderName
101
- } from '../workspaces/init'
97
+ import { provisionWorkspace, validateWorkspaceFolderName } from '../workspaces/init'
102
98
  import { resolveWorkspaceImportMetadata } from '../workspaces/import'
103
99
  import type { WorkspaceImportMetadata } from '../workspaces/import'
104
100
  import { getWorkspaceEnvView, parseEnvUpdate, updateWorkspaceEnv } from '../workspaces/env'
@@ -115,6 +111,12 @@ import {
115
111
  // `/api/workspaces/:id/*` handler can read it without re-querying the registry.
116
112
  type ApiEnv = { Variables: { ws: WorkspaceEntry } }
117
113
 
114
+ // The writing browser tab's id from a request body, echoed on the resulting
115
+ // event so that tab can skip it. See client/lib/browser-tab-id.ts.
116
+ function eventOrigin(value: unknown): string | undefined {
117
+ return typeof value === 'string' ? value : undefined
118
+ }
119
+
118
120
  function publishSelectedSession(workspaceId: string, update: SelectedSessionUpdate): void {
119
121
  if (!update.changed) return
120
122
  publishEvent({
@@ -178,20 +180,6 @@ const withWorkspace = createMiddleware<ApiEnv>(async (c, next) => {
178
180
  const one = new Hono<ApiEnv>()
179
181
  one.use('*', withWorkspace)
180
182
 
181
- one.get('/preview', async c => {
182
- const ws = c.get('ws')
183
- const views = await listCompiledViews(ws.path)
184
- return c.json(
185
- await getWorkspacePreview(ws.path, {
186
- getProviderPreview: includeFirstUserMessage =>
187
- harnessFor(ws).workspacePreview(ws, includeFirstUserMessage),
188
- viewIds: views.map(view => view.id),
189
- thumbnailUrl: (kind, id) =>
190
- `/api/workspaces/${ws.id}/applet-thumbnails/${kind}/${encodeURIComponent(id)}`
191
- })
192
- )
193
- })
194
-
195
183
  one.get('/widgets', c => listWidgets(c.get('ws').path))
196
184
 
197
185
  // Widget bundle: the compiled ESM for one widget, dynamically imported by the
@@ -734,7 +722,7 @@ one.put('/config', async c => {
734
722
  return c.text('Expected a workspace config field', 400)
735
723
  }
736
724
  await setWorkspaceConfig(ws.path, { name, icon })
737
- publishEvent({ type: 'workspace:updated' })
725
+ publishEvent({ type: 'workspace:updated', origin: eventOrigin(body.origin) })
738
726
  return c.json(await getWorkspaceConfig(ws.path))
739
727
  })
740
728
 
@@ -758,7 +746,7 @@ one.put('/scratchpad', async c => {
758
746
  publishEvent({
759
747
  type: 'scratchpad:updated',
760
748
  workspaceId: ws.id,
761
- origin: typeof body.origin === 'string' ? body.origin : undefined
749
+ origin: eventOrigin(body.origin)
762
750
  })
763
751
  return c.body(null, 204)
764
752
  })
@@ -850,11 +838,15 @@ one.get('/applet-thumbnails', async c =>
850
838
  one.get('/applet-thumbnails/:kind/:name', c => {
851
839
  const kind = c.req.param('kind')
852
840
  if (kind !== 'widget' && kind !== 'view') return c.text('Not found', 404)
841
+ // `<id>` or `<id>:<version>`. Applet ids never contain `:`, and the version
842
+ // lives in the path rather than a query string so every CDN keys on it.
843
+ const [id, version] = c.req.param('name').split(':')
853
844
  return serveAppletThumbnail(
854
845
  c.get('ws').path,
855
846
  kind,
856
- c.req.param('name'),
857
- c.req.header('if-none-match')
847
+ id!,
848
+ c.req.header('if-none-match'),
849
+ version !== undefined
858
850
  )
859
851
  })
860
852
 
@@ -888,16 +880,18 @@ one.put('/', async c => {
888
880
  const ws = c.get('ws')
889
881
  const body = await c.req.json()
890
882
  if (!body || body.version !== 1) return c.text('Bad request', 400)
883
+ // `origin` is the writing tab's id, echoed so that tab skips its own event.
884
+ const { origin, ...layout } = body
891
885
  // Preserve server-owned identity (name/icon) across a grid/theme save so the
892
886
  // client's PUT can't erase a `moi config`-set name. See mergeLayoutForSave.
893
887
  const existing = await loadLayout(ws.path)
894
- const next = mergeLayoutForSave(existing, body)
888
+ const next = mergeLayoutForSave(existing, layout)
895
889
  await saveLayout(next, ws.path)
896
890
  if (
897
891
  JSON.stringify(resolveWorkspaceTheme(existing.theme)) !==
898
892
  JSON.stringify(resolveWorkspaceTheme(next.theme))
899
893
  ) {
900
- publishEvent({ type: 'theme:updated' })
894
+ publishEvent({ type: 'theme:updated', origin: eventOrigin(origin) })
901
895
  }
902
896
  return c.body(null, 204)
903
897
  })
@@ -945,7 +939,7 @@ workspaces.put('/order', async c => {
945
939
  // List-only change: a narrow event so clients refetch just the sidebar
946
940
  // list, not every per-workspace query (`workspace:updated` also triggers
947
941
  // layout refetches in open workspaces).
948
- publishEvent({ type: 'workspaces-list:updated' })
942
+ publishEvent({ type: 'workspaces-list:updated', origin: eventOrigin(body.origin) })
949
943
  return c.json(await mergeWorkspaceList(entries))
950
944
  } catch (err) {
951
945
  const message = err instanceof Error ? err.message : String(err)
@@ -994,6 +988,27 @@ workspaces.post('/', async c => {
994
988
 
995
989
  workspaces.get('/discover', async c => c.json(await discoverWorkspaces()))
996
990
 
991
+ // Home-card previews for every workspace in one request, keyed by id, so the
992
+ // home page fetches them beside the list instead of one per card after it.
993
+ workspaces.get('/previews', async c => {
994
+ const entries = await listWorkspaces()
995
+ const previews = await Promise.all(
996
+ entries.map(async ws => {
997
+ const views = await listCompiledViews(ws.path).catch(() => [])
998
+ const preview = await getWorkspacePreview(ws.path, {
999
+ getProviderPreview: includeFirstUserMessage =>
1000
+ harnessFor(ws).workspacePreview(ws, includeFirstUserMessage),
1001
+ viewIds: views.map(view => view.id),
1002
+ // Capture time in base36 keeps the versioned segment short and URL-safe.
1003
+ thumbnailUrl: (kind, id, capturedAt) =>
1004
+ `/api/workspaces/${ws.id}/applet-thumbnails/${kind}/${id}:${Date.parse(capturedAt).toString(36)}`
1005
+ })
1006
+ return [ws.id, preview] as const
1007
+ })
1008
+ )
1009
+ return c.json(Object.fromEntries(previews))
1010
+ })
1011
+
997
1012
  // Backends the create dialog can provision from scratch. OpenClaw workspaces
998
1013
  // belong to their agents and arrive via discovery.
999
1014
  const CREATABLE_TYPES = new Set<WorkspaceType>(['claude-code', 'codex'])
@@ -1090,7 +1105,7 @@ api.post('/api/update', async c => {
1090
1105
 
1091
1106
  try {
1092
1107
  const result = await installUpdate()
1093
- if (!result) return c.text('This Moi install cannot be updated from the app.', 409)
1108
+ if (!result) return c.text('This Moi cannot be updated from the app', 409)
1094
1109
  const response = c.json(result)
1095
1110
  scheduleRestartForUpdate()
1096
1111
  return response
@@ -1,4 +1,5 @@
1
1
  import { readFileSync } from 'node:fs'
2
+ import { homedir } from 'node:os'
2
3
  import { isAbsolute, join } from 'path'
3
4
 
4
5
  import type { AppEnvironment, ClientAppConfig, ExperimentalFeatures } from '@/lib/types'
@@ -254,6 +255,12 @@ export function getAppConfig(): AppConfig {
254
255
  return _config
255
256
  }
256
257
 
258
+ // Folder for workspaces created from the UI. Managed machines override it
259
+ // with workspacesDir in config.json.
260
+ export function createdWorkspacesRoot(): string {
261
+ return getAppConfig().workspacesDir ?? join(homedir(), 'moi')
262
+ }
263
+
257
264
  // Test seam: drop the cached config so the next getAppConfig() re-resolves
258
265
  // (tests point MOI_DATA_DIR elsewhere or set MOI_DEMO).
259
266
  export function resetAppConfig(): void {
@@ -162,21 +162,24 @@ export function pruneAppletThumbnails(
162
162
  // Records that actually have an image on disk, for the home-card preview.
163
163
  export async function getCapturedThumbnails(
164
164
  workspacePath: string
165
- ): Promise<{ kind: AppletKind; id: string; viewedAt: string }[]> {
165
+ ): Promise<{ kind: AppletKind; id: string; capturedAt: string; viewedAt: string }[]> {
166
166
  const records = await loadIndex(getThumbnailsDir(workspacePath))
167
167
  return records
168
168
  .filter(record => record.file !== undefined)
169
- .map(({ kind, id, viewedAt }) => ({ kind, id, viewedAt }))
169
+ .map(({ kind, id, capturedAt, viewedAt }) => ({ kind, id, capturedAt, viewedAt }))
170
170
  }
171
171
 
172
172
  // One thumbnail image. Same caching story as applet bundles: strong ETag from
173
173
  // size+mtime with `private, no-cache`, so an unchanged file costs a bodyless
174
- // 304 and a re-capture busts every consumer on the next revalidation.
174
+ // 304 and a re-capture busts every consumer on the next revalidation. A
175
+ // `versioned` URL (the home preview's `<id>:<version>`) changes with every
176
+ // capture instead, so the browser keeps it without revalidating.
175
177
  export async function serveAppletThumbnail(
176
178
  workspacePath: string,
177
179
  kind: AppletKind,
178
180
  id: string,
179
- ifNoneMatch?: string | null
181
+ ifNoneMatch?: string | null,
182
+ versioned = false
180
183
  ): Promise<Response> {
181
184
  if (!isValidAppletId(id)) return new Response('Invalid id', { status: 400 })
182
185
  const dir = getThumbnailsDir(workspacePath)
@@ -189,7 +192,7 @@ export async function serveAppletThumbnail(
189
192
  const etag = `"${file.size}-${Math.trunc(file.lastModified)}"`
190
193
  const headers = {
191
194
  ETag: etag,
192
- 'Cache-Control': 'private, no-cache',
195
+ 'Cache-Control': versioned ? 'private, max-age=604800, immutable' : 'private, no-cache',
193
196
  'Content-Type': MIME_BY_EXT[record.file.split('.').pop() ?? ''] ?? 'application/octet-stream'
194
197
  }
195
198
  if (ifNoneMatch === etag) return new Response(null, { status: 304, headers })
@@ -26,6 +26,10 @@ export async function listCodexThreads(
26
26
  cwd: workspacePath,
27
27
  limit: 100,
28
28
  sortKey: 'updated_at',
29
+ // Codex lists only the current provider's chats unless asked for all.
30
+ // Switching between a ChatGPT sign-in and a provider in config.toml (the
31
+ // cloud demo's AI Gateway, an API key) must not hide earlier chats.
32
+ modelProviders: [],
29
33
  useStateDbOnly
30
34
  })
31
35
  let threads: CodexThread[]
package/server/static.ts CHANGED
@@ -17,7 +17,9 @@ const DIST_INDEX = join(DIST_DIR, 'index.html')
17
17
  export const prebuilt = !process.env.MOI_DEV && existsSync(DIST_INDEX)
18
18
 
19
19
  // The prebuilt SPA shell, served for client-side routes in production. In dev,
20
- // web.ts uses the live-bundled HTML import instead (for HMR).
20
+ // web.ts uses the live-bundled HTML import instead (for HMR). `no-cache`: the
21
+ // shell is the one unhashed document — it names the hashed chunks and the
22
+ // versioned React, which are cached for good, so it must be revalidated itself.
21
23
  export function distShell(): Response {
22
- return new Response(Bun.file(DIST_INDEX))
24
+ return new Response(Bun.file(DIST_INDEX), { headers: { 'Cache-Control': 'no-cache' } })
23
25
  }
package/server/vendor.ts CHANGED
@@ -1,48 +1,41 @@
1
- // Serves the locally-vendored React ESM (client/vendor/react, generated by
2
- // scripts/build-vendor.ts) behind the stable `/vendor/react/*` URLs the
3
- // importmap in client/index.html points at. This is what makes moi run offline
4
- // — no esm.sh fetch.
1
+ // Serves the locally-vendored React ESM (client/vendor/react/<version>,
2
+ // generated by scripts/build-vendor.ts) behind the
3
+ // `/vendor/react/<version>/<mode>/*` URLs the importmap in client/index.html
4
+ // points at. This is what makes moi run offline — no esm.sh fetch.
5
5
  //
6
- // The importmap URLs carry no dev/prod distinction; we pick the build here so
7
- // developers get React's warnings (invalid hook calls, key warnings) while
8
- // production gets the smaller build. `client/` ships in the published package
9
- // (see package.json `files`), so this resolves in a global install too.
6
+ // Both the version and the build mode are in the URL, which is what makes the
7
+ // files safe to cache forever: a React bump moves the URL, and the development
8
+ // and production builds (different bytes — prod's jsx-dev-runtime has no
9
+ // `jsxDEV`) never share one, so a prebuilt `moi` and `bun run dev` on the same
10
+ // port cannot poison each other's cache. The source HTML names the development
11
+ // build; scripts/build-client.ts switches it to production in `dist/`.
12
+ // `client/` ships in the published package (see package.json `files`), so this
13
+ // resolves in a global install too.
10
14
  import { join } from 'node:path'
11
15
 
12
- import { prebuilt } from './static'
13
-
14
16
  const VENDOR_DIR = join(import.meta.dir, '..', 'client', 'vendor', 'react')
15
17
  const EMOJIBASE_DIR = join(import.meta.dir, '..', 'client', 'vendor', 'emojibase')
16
- const MODE = prebuilt ? 'production' : 'development'
17
18
 
18
- // A single flat file (`react.js`) or one nested under `_impl/` — both `.js`,
19
- // no traversal. Matches exactly the layout build-vendor.ts emits.
20
- const ALLOWED = /^(_impl\/)?[a-zA-Z0-9_-]+\.js$/
19
+ // `<version>/<mode>/<file>`: a version folder, the build mode, then a single
20
+ // flat file (`react.js`) or one nested under `_impl/` — all `.js`, no
21
+ // traversal. Matches exactly the layout build-vendor.ts emits.
22
+ const ALLOWED = /^\d[\w.-]*\/(development|production)\/(_impl\/)?[a-zA-Z0-9_-]+\.js$/
21
23
 
22
24
  export async function serveVendorReact(req: Request): Promise<Response> {
23
25
  const rel = new URL(req.url).pathname.replace(/^\/vendor\/react\//, '')
24
26
  if (!ALLOWED.test(rel) || rel.includes('..')) {
25
27
  return new Response('Not found', { status: 404 })
26
28
  }
27
- const file = Bun.file(join(VENDOR_DIR, MODE, rel))
29
+ const file = Bun.file(join(VENDOR_DIR, rel))
28
30
  if (!(await file.exists())) {
29
31
  return new Response('Not found', { status: 404 })
30
32
  }
31
- // Revalidate on every load (no max-age): the same URLs serve different bytes
32
- // when the mode flips (prebuilt `moi` vs `bun run dev` on one port) or after
33
- // a `vendor:react` regen. The ETag encodes both, so browsers keep the bytes
34
- // (304) but never reuse a stale mode — prod jsx-dev-runtime has no `jsxDEV`
35
- // and would crash dev.
36
- const etag = `"${MODE}-${file.lastModified}-${file.size}"`
37
- const headers = {
38
- 'Content-Type': 'text/javascript; charset=utf-8',
39
- 'Cache-Control': 'no-cache',
40
- ETag: etag
41
- }
42
- if (req.headers.get('if-none-match') === etag) {
43
- return new Response(null, { status: 304, headers })
44
- }
45
- return new Response(file, { headers })
33
+ return new Response(file, {
34
+ headers: {
35
+ 'Content-Type': 'text/javascript; charset=utf-8',
36
+ 'Cache-Control': 'public, max-age=31536000, immutable'
37
+ }
38
+ })
46
39
  }
47
40
 
48
41
  // `<locale>/<file>.json` only — mirrors the emojibase-data package layout the
package/server/web.ts CHANGED
@@ -140,8 +140,9 @@ export const app = Bun.serve<WsData>({
140
140
  headers: { 'Content-Type': 'text/plain; charset=utf-8', 'Cache-Control': 'no-store' }
141
141
  }),
142
142
 
143
- // Locally-vendored React ESM (offline; no CDN). The importmap in
144
- // client/index.html points here; the handler picks dev/prod per env.
143
+ // Locally-vendored React ESM (offline; no CDN), under a versioned path so
144
+ // production can cache it for good. The importmap in client/index.html
145
+ // points here; the handler picks dev/prod per env.
145
146
  '/vendor/react/*': (req: Request) => serveVendorReact(req),
146
147
 
147
148
  // Vendored emojibase-data for the settings emoji picker (offline; no CDN).
@@ -156,6 +157,7 @@ export const app = Bun.serve<WsData>({
156
157
  ? new Response('Not found', { status: 404 })
157
158
  : devSandbox,
158
159
  '/workspace/*': shell,
160
+ '/settings': shell,
159
161
 
160
162
  // Chat websocket — app-wide (one per client, not per workspace). Each chat
161
163
  // frame carries its own workspaceId.
@@ -4,13 +4,11 @@
4
4
  // create) all provision through here, so a workspace set up from the UI is
5
5
  // indistinguishable from one set up via the CLI.
6
6
  import { mkdir } from 'node:fs/promises'
7
- import { homedir } from 'node:os'
8
7
  import { join } from 'node:path'
9
8
 
10
9
  import type { WorkspaceType } from '@/lib/types'
11
10
  export { validateWorkspaceFolderName } from '@/lib/workspace-name'
12
11
 
13
- import { getAppConfig } from '../app-config'
14
12
  import { harnessFor } from '../harness/registry'
15
13
  import { createDependencyInstallLogPath, scaffoldMoiDir } from './scaffold'
16
14
  import { installBundledSkills } from '../skills/template'
@@ -23,14 +21,6 @@ export function skillsDirFor(workspaceRoot: string, type?: WorkspaceType): strin
23
21
  return harnessFor(type).skillsDir?.(workspaceRoot) ?? join(workspaceRoot, '.claude', 'skills')
24
22
  }
25
23
 
26
- // Folder that holds workspaces created from the UI (`/workspace/create`) — a
27
- // visible home-dir folder, mirroring how Cowork keeps its session folders under
28
- // the user's home rather than an app-data dir. Managed machines set their own
29
- // (`workspacesDir` in config.json).
30
- export function createdWorkspacesRoot(): string {
31
- return getAppConfig().workspacesDir ?? join(homedir(), 'moi')
32
- }
33
-
34
24
  export type ProvisionResult = {
35
25
  // Where the skills were installed (backend-dependent, see skillsDirFor).
36
26
  skillsDir: string
@@ -100,7 +100,8 @@ export type WorkspacePreviewOptions = {
100
100
  viewIds?: readonly string[]
101
101
  // Maps a captured applet to the image URL the home card should render —
102
102
  // the API layer owns the route shape (GET .../applet-thumbnails/:kind/:id).
103
- thumbnailUrl: (kind: AppletKind, id: string) => string
103
+ // `version` changes with every capture, so the URL can be cached forever.
104
+ thumbnailUrl: (kind: AppletKind, id: string, version: string) => string
104
105
  }
105
106
 
106
107
  export async function getWorkspacePreview(
@@ -111,17 +112,21 @@ export async function getWorkspacePreview(
111
112
  const layout = await loadLayout(workspacePath)
112
113
  const captured = await getCapturedThumbnails(workspacePath)
113
114
  const validViewIds = new Set(viewIds)
114
- const capturedWidgets = new Set(
115
- captured.filter(record => record.kind === 'widget').map(record => record.id)
115
+ const capturedWidgets = new Map(
116
+ captured
117
+ .filter(record => record.kind === 'widget')
118
+ .map(record => [record.id, record.capturedAt])
116
119
  )
117
120
  const widgetImages = [...layout.widgetGrid]
118
121
  .sort((a, b) => a.y - b.y || a.x - b.x)
119
- .filter(item => capturedWidgets.has(item.i))
120
- .map(item => thumbnailUrl('widget', item.i))
122
+ .flatMap(item => {
123
+ const version = capturedWidgets.get(item.i)
124
+ return version === undefined ? [] : [thumbnailUrl('widget', item.i, version)]
125
+ })
121
126
  const viewImages = captured
122
127
  .filter(record => record.kind === 'view' && validViewIds.has(record.id))
123
128
  .sort((a, b) => Date.parse(b.viewedAt) - Date.parse(a.viewedAt))
124
- .map(record => thumbnailUrl('view', record.id))
129
+ .map(record => thumbnailUrl('view', record.id, record.capturedAt))
125
130
  const thumbnails = [...widgetImages, ...viewImages].slice(0, PREVIEW_LIMIT)
126
131
  // The message bubble is the card's fallback for "nothing to show": gate on
127
132
  // captured thumbnails, not grid emptiness — a workspace with widgets that
@@ -1,5 +1,5 @@
1
1
  import { existsSync, realpathSync } from 'node:fs'
2
- import { rename, rm } from 'node:fs/promises'
2
+ import { readdir, rename, rm, stat } from 'node:fs/promises'
3
3
  import { homedir } from 'node:os'
4
4
  import { join, resolve, sep } from 'path'
5
5
 
@@ -10,6 +10,7 @@ import { orderWorkspaceTypes } from '@/lib/workspace-types'
10
10
  import { DATA_DIR } from '../data-dir'
11
11
  import { allHarnesses } from '../harness/registry'
12
12
  import type { DiscoveredWorkspaceCandidate } from '../harness/types'
13
+ import { createdWorkspacesRoot } from '../app-config'
13
14
 
14
15
  // Replace the home-dir prefix with `~` for display. Keeps the original
15
16
  // absolute path in place; callers should put the result in `displayPath`.
@@ -216,7 +217,7 @@ export function liftToWorkspaceRoot(p: string): string {
216
217
  return segments.slice(0, i).join(sep) || sep
217
218
  }
218
219
 
219
- async function collectDiscoveredWorkspaces(
220
+ async function discoverHarnessWorkspaces(
220
221
  registeredPaths: Set<string>
221
222
  ): Promise<DiscoveredWorkspaceCandidate[]> {
222
223
  const perHarness = await Promise.all(
@@ -227,8 +228,25 @@ async function collectDiscoveredWorkspaces(
227
228
  return perHarness.flat()
228
229
  }
229
230
 
230
- export function groupDiscoveredWorkspaces(
231
- candidates: DiscoveredWorkspaceCandidate[],
231
+ // Only inspect immediate children of the workspace root, never the whole disk.
232
+ export async function discoverWorkspaceFolders(
233
+ root = createdWorkspacesRoot()
234
+ ): Promise<{ path: string }[]> {
235
+ const entries = await readdir(root, { withFileTypes: true }).catch(() => [])
236
+ const candidates = await Promise.all(
237
+ entries
238
+ .filter(entry => entry.isDirectory() || entry.isSymbolicLink())
239
+ .map(async entry => {
240
+ const path = resolve(root, entry.name)
241
+ const moi = await stat(join(path, '.moi')).catch(() => undefined)
242
+ return moi?.isDirectory() ? { path } : undefined
243
+ })
244
+ )
245
+ return candidates.filter(candidate => candidate !== undefined)
246
+ }
247
+
248
+ export function mergeWorkspaceCandidates(
249
+ candidates: { path: string; type?: WorkspaceType }[],
232
250
  registeredPaths: Set<string> = new Set()
233
251
  ): DiscoveredWorkspace[] {
234
252
  const normalizedRegisteredPaths = new Set([...registeredPaths].map(path => resolve(path)))
@@ -238,7 +256,7 @@ export function groupDiscoveredWorkspaces(
238
256
  const path = resolve(candidate.path)
239
257
  if (normalizedRegisteredPaths.has(path)) continue
240
258
  const types = byPath.get(path) ?? new Set<WorkspaceType>()
241
- types.add(candidate.type)
259
+ if (candidate.type) types.add(candidate.type)
242
260
  byPath.set(path, types)
243
261
  }
244
262
 
@@ -248,10 +266,14 @@ export function groupDiscoveredWorkspaces(
248
266
  }))
249
267
  }
250
268
 
251
- // Ask every harness for workspaces it knows about that aren't registered yet,
252
- // then combine providers that claim the same normalized folder.
269
+ // Combine agent history with Moi folders that may not have any chats yet.
253
270
  export async function discoverWorkspaces(): Promise<DiscoveredWorkspace[]> {
254
271
  const registeredPaths = new Set((await readRegistry()).map(e => e.path))
255
- const found = await collectDiscoveredWorkspaces(registeredPaths)
256
- return groupDiscoveredWorkspaces(found, registeredPaths).map(withDisplayPath)
272
+ const [harnessWorkspaces, workspaceFolders] = await Promise.all([
273
+ discoverHarnessWorkspaces(registeredPaths),
274
+ discoverWorkspaceFolders()
275
+ ])
276
+ return mergeWorkspaceCandidates([...harnessWorkspaces, ...workspaceFolders], registeredPaths).map(
277
+ withDisplayPath
278
+ )
257
279
  }
@@ -1,2 +0,0 @@
1
- import{Rc as p}from"/chunk-jvyvwwv3.js";import{Uc as y,Xc as r}from"/chunk-9vg3xa81.js";import{_c as m}from"/chunk-d7cbm65e.js";var E=m(y(),1);var a={collab:!1},f=Object.keys(a);var F={environment:"local",demo:!1,experimental:{...a},demoInstallUrl:"https://moi.computer"},t=F,o=new Set;function d(e){return o.add(e),()=>{o.delete(e)}}async function x(){try{t=await p("/api/config");for(let e of o)e();return t}catch{}}async function b(){let e=await x();return r(()=>{x()}),e}function A(){return E.useSyncExternalStore(d,()=>t)}
2
- export{b as Hc,A as Ic};