moi-computer 0.12.1-next.3 → 0.13.0

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 (236) hide show
  1. package/bunfig.toml +1 -5
  2. package/client/api/app-config.ts +1 -2
  3. package/client/api/app-ui-keys.ts +3 -1
  4. package/client/api/http.ts +4 -1
  5. package/client/api/workspace-keys.ts +3 -3
  6. package/client/app/app-provider.tsx +22 -2
  7. package/client/app/app-router.tsx +4 -0
  8. package/client/app/routes/home-route.tsx +14 -0
  9. package/client/app/routes/onboarding-route.tsx +11 -0
  10. package/client/app/routes/settings-route.tsx +1 -1
  11. package/client/app/routes/workspace-route.tsx +21 -19
  12. package/client/components/shared/screen-shell.tsx +23 -0
  13. package/client/components/shared/ultrafast-icon.tsx +61 -0
  14. package/client/components/shared/workspace-icon.tsx +2 -2
  15. package/client/features/account/account-test-utils.tsx +4 -3
  16. package/client/features/app-settings/api.ts +33 -0
  17. package/client/features/app-settings/general-settings.tsx +39 -0
  18. package/client/features/{settings → app-settings}/settings-page.tsx +5 -1
  19. package/client/features/chat/applet-chat-intents.ts +4 -20
  20. package/client/features/chat/chat-send.ts +17 -13
  21. package/client/features/chat/composer/model-order.ts +8 -4
  22. package/client/features/chat/composer/model-picker.tsx +88 -34
  23. package/client/features/chat/composer/use-workspace-composer-state.tsx +11 -3
  24. package/client/features/chat/composer/use-workspace-skill-updates.ts +1 -1
  25. package/client/features/chat/connection/chat-frames.ts +3 -15
  26. package/client/features/chat/messages/chat-empty-state.tsx +1 -4
  27. package/client/features/chat/messages/fork-history.ts +5 -5
  28. package/client/features/chat/messages/tool-group/subagent-card.tsx +1 -0
  29. package/client/features/chat/messages/turn-view.tsx +3 -12
  30. package/client/features/chat/messages/user-message-bubble.tsx +63 -0
  31. package/client/features/chat/sessions/api.ts +121 -80
  32. package/client/features/chat/sessions/browser-tab-state.ts +14 -12
  33. package/client/features/chat/sessions/chat-selector.tsx +5 -6
  34. package/client/features/chat/sessions/use-selected-session.ts +172 -257
  35. package/client/features/chat/use-chat.ts +14 -19
  36. package/client/features/collab/components/user-avatar.tsx +4 -10
  37. package/client/features/collab/workspace-users-menu.tsx +1 -1
  38. package/client/features/connectors/api.ts +12 -4
  39. package/client/features/connectors/mcp-server-cards.tsx +17 -7
  40. package/client/features/connectors/read-connectors.ts +35 -0
  41. package/client/features/demo/demo-dialog.tsx +11 -3
  42. package/client/features/dev/collab/local-user-settings.tsx +1 -1
  43. package/client/features/dev/dev-index-page.tsx +5 -0
  44. package/client/features/dev/dev-routes.tsx +2 -0
  45. package/client/features/dev/harness-debug-page.tsx +3 -3
  46. package/client/features/dev/onboarding-preview-page.tsx +76 -0
  47. package/client/features/dev/workspace-setup-mocks.ts +16 -14
  48. package/client/features/dev/workspace-setup-preview.tsx +11 -17
  49. package/client/features/harness/api.ts +45 -15
  50. package/client/features/harness/device-login-steps.tsx +9 -3
  51. package/client/features/harness/harness-login-panel.tsx +228 -0
  52. package/client/features/harness/harness-presentation.ts +15 -0
  53. package/client/features/harness/harness-selector.tsx +119 -0
  54. package/client/features/harness/use-harness-login.ts +77 -0
  55. package/client/features/home/home-page.tsx +7 -7
  56. package/client/features/onboarding/agent-setup-step.tsx +57 -0
  57. package/client/features/onboarding/api.ts +42 -0
  58. package/client/features/onboarding/onboarding-idea-disk.tsx +129 -0
  59. package/client/features/onboarding/onboarding-page.tsx +32 -0
  60. package/client/features/onboarding/onboarding-screen.tsx +20 -0
  61. package/client/features/onboarding/onboarding-status.tsx +24 -0
  62. package/client/features/onboarding/workspace-setup-step.tsx +239 -0
  63. package/client/features/overview/default/registry.tsx +2 -2
  64. package/client/features/overview/default/views-widget.tsx +6 -5
  65. package/client/features/overview/overview.tsx +9 -11
  66. package/client/features/overview/widget-canvas.tsx +1 -1
  67. package/client/features/overview/workspace-name.tsx +2 -2
  68. package/client/features/views/api.ts +69 -16
  69. package/client/features/views/pending-view-screen.tsx +30 -9
  70. package/client/features/views/use-view-actions.ts +19 -20
  71. package/client/features/views/view-presentation.ts +2 -2
  72. package/client/features/views/view-submission.ts +28 -41
  73. package/client/features/workspace/add/api.ts +3 -23
  74. package/client/features/workspace/add/create-workspace-dialog.tsx +6 -5
  75. package/client/features/workspace/add/import-workspace-dialog.tsx +3 -3
  76. package/client/features/workspace/add/workspace-agent-options.ts +11 -12
  77. package/client/features/workspace/add/workspace-agent-selector.tsx +3 -132
  78. package/client/features/workspace/api.ts +32 -36
  79. package/client/features/workspace/harness-transition.ts +89 -0
  80. package/client/features/{settings → workspace/settings}/api.ts +1 -34
  81. package/client/features/{settings → workspace/settings}/connectors-settings.tsx +31 -10
  82. package/client/features/workspace/settings/general-settings.tsx +180 -0
  83. package/client/features/{settings → workspace/settings}/use-env-vars.ts +1 -1
  84. package/client/features/{settings → workspace/settings}/workspace-icon-picker.tsx +3 -3
  85. package/client/features/workspace/setup/workspace-login-state.tsx +37 -156
  86. package/client/features/workspace/setup/workspace-recovery-states.tsx +0 -12
  87. package/client/features/workspace/setup/workspace-setup.tsx +34 -14
  88. package/client/features/workspace/setup/workspace-welcome-state.tsx +2 -2
  89. package/client/features/workspace/use-workspace-navigation.ts +25 -9
  90. package/client/features/workspace/workspace-content.tsx +11 -8
  91. package/client/features/workspace/workspace-frame.tsx +2 -1
  92. package/client/features/workspace/workspace-layout-context.tsx +5 -2
  93. package/client/features/workspace/workspace-menu.tsx +12 -8
  94. package/client/features/workspace/workspace-pending-screen.tsx +10 -10
  95. package/client/features/workspace/workspace-presentation.tsx +5 -13
  96. package/client/features/workspace/workspace-state.ts +169 -0
  97. package/client/features/workspace/workspace-tabs.tsx +22 -2
  98. package/client/index.css +2 -0
  99. package/client/index.tsx +3 -3
  100. package/client/lib/flags.ts +1 -1
  101. package/client/lib/{app-icon-registry.ts → identity-icon-registry.ts} +10 -14
  102. package/client/runtime/workspace-events.ts +21 -4
  103. package/client/runtime/workspace-theme.ts +9 -0
  104. package/client/tailwind-config.ts +43 -0
  105. package/dist/chunk-2y59vrxg.js +5 -0
  106. package/dist/chunk-58dyt9bk.js +2 -0
  107. package/dist/{chunk-tqd3pkg8.css → chunk-60q353jq.css} +1 -1
  108. package/dist/chunk-bncc7heg.js +1 -0
  109. package/dist/{chunk-11cab5dq.css → chunk-cq2r11fg.css} +1 -1
  110. package/dist/chunk-cqt3s31j.js +546 -0
  111. package/dist/chunk-dcmks9sm.js +75 -0
  112. package/dist/chunk-md45evr2.css +1 -0
  113. package/dist/chunk-n0nab26d.js +1 -0
  114. package/dist/chunk-nf2wkvf9.js +14 -0
  115. package/dist/chunk-nmzhgyp9.js +2 -0
  116. package/dist/chunk-q37knr3m.js +2 -0
  117. package/dist/chunk-s90m4qkz.js +1 -0
  118. package/dist/chunk-wjvd4byz.js +2 -0
  119. package/dist/index.html +1 -1
  120. package/lib/harness-instructions.ts +1 -1
  121. package/lib/{app-icons.ts → identity-icons.ts} +6 -7
  122. package/lib/onboarding.ts +41 -0
  123. package/lib/speed-mode.ts +5 -0
  124. package/lib/types.ts +75 -64
  125. package/lib/view-build-directives.ts +1 -2
  126. package/lib/workspace-icon.ts +2 -2
  127. package/lib/workspace-layout.ts +1 -1
  128. package/lib/workspace-name.ts +15 -12
  129. package/package.json +11 -8
  130. package/server/README.md +27 -25
  131. package/server/api/harnesses.ts +31 -8
  132. package/server/api/index.ts +189 -127
  133. package/server/api/onboarding.ts +46 -0
  134. package/server/app-config.ts +16 -24
  135. package/server/app-settings.ts +6 -2
  136. package/server/applets/config.ts +5 -5
  137. package/server/applets/views.ts +19 -17
  138. package/server/cli/commands/init.ts +3 -3
  139. package/server/cli/commands/skill.ts +16 -17
  140. package/server/cli/commands/start.ts +8 -34
  141. package/server/cli/server.ts +18 -6
  142. package/server/collab/config.ts +1 -2
  143. package/server/collab/manager.ts +4 -1
  144. package/server/collab/skill/index.ts +1 -1
  145. package/server/control.ts +3 -3
  146. package/server/data-dir.ts +1 -1
  147. package/server/harness/README.md +24 -8
  148. package/server/harness/acp/session.ts +8 -4
  149. package/server/harness/auth.ts +14 -17
  150. package/server/harness/claude-code/NOTES.md +4 -3
  151. package/server/harness/claude-code/index.ts +5 -6
  152. package/server/harness/claude-code/mcp.ts +17 -0
  153. package/server/harness/claude-code/models.ts +2 -20
  154. package/server/harness/claude-code/run-action.ts +123 -0
  155. package/server/harness/claude-code/session-title.ts +5 -7
  156. package/server/harness/claude-code/session.ts +24 -16
  157. package/server/harness/codex/NOTES.md +22 -10
  158. package/server/harness/codex/adapter.ts +14 -17
  159. package/server/harness/codex/client.ts +8 -5
  160. package/server/harness/codex/connectors.ts +92 -0
  161. package/server/harness/codex/index.ts +4 -1
  162. package/server/harness/codex/pagination.ts +8 -5
  163. package/server/harness/codex/run-action.ts +93 -0
  164. package/server/harness/codex/session-title.ts +6 -8
  165. package/server/harness/codex/session.ts +11 -11
  166. package/server/harness/codex/transport.ts +13 -6
  167. package/server/harness/command.ts +45 -0
  168. package/server/harness/executable.ts +5 -0
  169. package/server/harness/fork.ts +6 -4
  170. package/server/harness/install.ts +49 -0
  171. package/server/harness/openclaw/session.ts +1 -2
  172. package/server/harness/run-action.ts +85 -0
  173. package/server/harness/session-title.ts +0 -46
  174. package/server/harness/types.ts +30 -3
  175. package/server/onboarding/brief.ts +29 -0
  176. package/server/onboarding/ideas.ts +48 -0
  177. package/server/onboarding/jobs.ts +291 -0
  178. package/server/onboarding/prompt.md +49 -0
  179. package/server/sessions/archive.ts +5 -14
  180. package/server/sessions/config.ts +17 -16
  181. package/server/sessions/lifecycle.ts +15 -13
  182. package/server/sessions/pending-views.ts +79 -108
  183. package/server/sessions/selected.ts +75 -161
  184. package/server/sessions/store.ts +40 -113
  185. package/server/sessions/view-sessions.ts +128 -111
  186. package/server/skills/locations.ts +82 -0
  187. package/server/skills/lock.ts +29 -0
  188. package/server/skills/template.ts +36 -25
  189. package/server/skills/update.ts +52 -5
  190. package/server/skills/version.ts +17 -22
  191. package/server/skills/workspace.ts +121 -0
  192. package/server/web.ts +22 -8
  193. package/server/workspace-state/file.ts +177 -0
  194. package/server/workspace-state/index.ts +162 -0
  195. package/server/workspace-state/legacy-migration.ts +79 -0
  196. package/server/workspace-state/lock.ts +42 -0
  197. package/server/workspace-state/types.ts +16 -0
  198. package/server/workspaces/change-harness.ts +88 -0
  199. package/server/workspaces/harness-transition.ts +29 -0
  200. package/server/workspaces/init.ts +29 -6
  201. package/server/workspaces/layout.ts +3 -0
  202. package/server/workspaces/registry.ts +27 -1
  203. package/{workspace/.claude/skills/moi-workspace → skill}/SKILL.md +7 -5
  204. package/{workspace/.claude/skills/moi-workspace → skill}/references/COLLAB.md +4 -8
  205. package/skill/references/DESIGN.md +167 -0
  206. package/{workspace/.claude/skills/moi-workspace → skill}/references/SCRATCHPAD.md +2 -2
  207. package/{workspace/.claude/skills/moi-workspace → skill}/references/UI-COMPONENTS.md +3 -0
  208. package/ui-components/badge.tsx +1 -1
  209. package/client/accept-hmr-dependencies.ts +0 -22
  210. package/client/features/settings/general-settings.tsx +0 -103
  211. package/client/features/workspace/setup/workspace-setup-panel.tsx +0 -18
  212. package/dist/chunk-20ynagd4.js +0 -2
  213. package/dist/chunk-42tde9a6.js +0 -1
  214. package/dist/chunk-9w543s0r.js +0 -2
  215. package/dist/chunk-a5372n61.js +0 -546
  216. package/dist/chunk-aja9y1vn.js +0 -68
  217. package/dist/chunk-fvcvrh3d.css +0 -1
  218. package/dist/chunk-gtfjw3nx.js +0 -1
  219. package/dist/chunk-j39y2aky.js +0 -14
  220. package/dist/chunk-pcnahct1.js +0 -5
  221. package/dist/chunk-pja30km3.js +0 -1
  222. package/dist/chunk-rm894bc2.js +0 -2
  223. package/dist/chunk-tevvtfbk.js +0 -10
  224. package/dist/chunk-tgt9zd0r.js +0 -2
  225. package/dist/chunk-tv5k5z00.js +0 -1
  226. package/dist/chunk-zq2ae5dx.js +0 -2
  227. package/lib/experimental.ts +0 -14
  228. package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +0 -157
  229. /package/client/features/{settings → app-settings}/profile-settings.tsx +0 -0
  230. /package/client/features/{settings → app-settings}/settings-section.tsx +0 -0
  231. /package/client/features/{settings → app-settings}/users-settings.tsx +0 -0
  232. /package/client/features/{settings → workspace/settings}/environment-settings.tsx +0 -0
  233. /package/client/features/{settings → workspace/settings}/icon-picker-options.ts +0 -0
  234. /package/client/features/{settings → workspace/settings}/settings-layout.tsx +0 -0
  235. /package/client/features/{settings → workspace/settings}/workspace-settings-dialog.tsx +0 -0
  236. /package/{workspace/.claude/skills/moi-workspace → skill}/references/INTENTS.md +0 -0
@@ -0,0 +1,162 @@
1
+ // Moi's per-workspace state, one `state.json` per workspace id under
2
+ // `DATA_DIR/workspaces/`. Reads come from a write-through cache: the server is
3
+ // the only process that writes these files (the CLI goes through the control
4
+ // port), so the cache never goes stale. Writes for one workspace run one at a
5
+ // time, each as a synchronous change applied to a copy and saved atomically.
6
+ // Every saved change is published to browsers as `state:changed`.
7
+ import { existsSync } from 'node:fs'
8
+ import { readdir, rm } from 'node:fs/promises'
9
+ import { join } from 'node:path'
10
+
11
+ import type { WorkspaceState } from '@/lib/types'
12
+ import { DATA_DIR } from '../data-dir'
13
+ import { publishEvent } from '../events'
14
+ import {
15
+ compactWorkspaceState,
16
+ emptyWorkspaceState,
17
+ readStateFile,
18
+ writeStateFile,
19
+ WorkspaceStateVersionError,
20
+ type LoadedState
21
+ } from './file'
22
+ import { createKeyedLock } from './lock'
23
+ import type { StoredWorkspaceState, WorkspaceRef } from './types'
24
+
25
+ export { LockTimeoutError } from './lock'
26
+ export { WorkspaceStateVersionError } from './file'
27
+ export type { StoredWorkspaceState, WorkspaceRef } from './types'
28
+
29
+ const STATE_FILE = 'state.json'
30
+ // Long enough for a slow disk, short enough that one stuck write does not
31
+ // freeze the workspace's chats.
32
+ const LOCK_TIMEOUT_MS = 10_000
33
+
34
+ export const DEFAULT_WORKSPACE_STATE_ROOT = join(DATA_DIR, 'workspaces')
35
+
36
+ let root = DEFAULT_WORKSPACE_STATE_ROOT
37
+ const cache = new Map<string, Promise<LoadedState>>()
38
+ const withLock = createKeyedLock(LOCK_TIMEOUT_MS)
39
+
40
+ // Test seam: keep state in a scratch folder.
41
+ export function setWorkspaceStateRoot(dir: string): void {
42
+ root = dir
43
+ cache.clear()
44
+ }
45
+
46
+ function statePath(workspaceId: string): string {
47
+ return join(root, workspaceId, STATE_FILE)
48
+ }
49
+
50
+ function load(ws: WorkspaceRef): Promise<LoadedState> {
51
+ let loaded = cache.get(ws.id)
52
+ if (!loaded) {
53
+ const loading = readStateFile(statePath(ws.id), ws.path).then(
54
+ found => found ?? { state: emptyWorkspaceState(ws.path), writable: true }
55
+ )
56
+ loading.catch(() => {
57
+ if (cache.get(ws.id) === loading) cache.delete(ws.id)
58
+ })
59
+ cache.set(ws.id, loading)
60
+ loaded = loading
61
+ }
62
+ return loaded
63
+ }
64
+
65
+ // A copy of the current state. Changing it changes nothing on disk.
66
+ export async function readWorkspaceState(ws: WorkspaceRef): Promise<StoredWorkspaceState> {
67
+ return structuredClone((await load(ws)).state)
68
+ }
69
+
70
+ // The state as clients see it, without the file's bookkeeping.
71
+ export function toWorkspaceState(stored: StoredWorkspaceState): WorkspaceState {
72
+ const { version: _version, workspacePath: _workspacePath, ...state } = stored
73
+ return state
74
+ }
75
+
76
+ export async function getWorkspaceState(ws: WorkspaceRef): Promise<WorkspaceState> {
77
+ return toWorkspaceState(await readWorkspaceState(ws))
78
+ }
79
+
80
+ // Applies `change` to a copy of the state and saves the result in one atomic
81
+ // write. Keep `change` synchronous and free of I/O: it runs while every other
82
+ // write to this workspace waits. Throwing from it leaves the state untouched;
83
+ // a change that leaves the state as it was skips the write.
84
+ export async function updateWorkspaceState<T>(
85
+ ws: WorkspaceRef,
86
+ change: (draft: StoredWorkspaceState) => T
87
+ ): Promise<T> {
88
+ return withLock(ws.id, async lease => {
89
+ const loaded = await load(ws)
90
+ const draft = structuredClone(loaded.state)
91
+ const result = change(draft)
92
+ if (result instanceof Promise)
93
+ throw new TypeError('Workspace state changes must be synchronous')
94
+ draft.workspacePath = ws.path
95
+ draft.revision = loaded.state.revision
96
+ compactWorkspaceState(draft)
97
+ if (JSON.stringify(draft) === JSON.stringify(loaded.state)) return result
98
+ if (!loaded.writable) throw new WorkspaceStateVersionError(statePath(ws.id))
99
+ draft.revision++
100
+ await writeStateFile(statePath(ws.id), draft, lease)
101
+ loaded.state = draft
102
+ publishEvent({ type: 'state:changed', workspaceId: ws.id, state: toWorkspaceState(draft) })
103
+ return result
104
+ })
105
+ }
106
+
107
+ export function hasWorkspaceState(workspaceId: string): boolean {
108
+ return existsSync(statePath(workspaceId))
109
+ }
110
+
111
+ async function listStateIds(): Promise<string[]> {
112
+ try {
113
+ const entries = await readdir(root, { withFileTypes: true })
114
+ return entries.filter(entry => entry.isDirectory()).map(entry => entry.name)
115
+ } catch {
116
+ return []
117
+ }
118
+ }
119
+
120
+ // Read-only on purpose: the CLI calls this while registering a workspace, and
121
+ // only the server may change state files.
122
+ async function peekWorkspacePath(workspaceId: string): Promise<string | undefined> {
123
+ try {
124
+ const parsed: unknown = JSON.parse(await Bun.file(statePath(workspaceId)).text())
125
+ if (typeof parsed !== 'object' || parsed === null) return undefined
126
+ const { workspacePath } = parsed as { workspacePath?: unknown }
127
+ return typeof workspacePath === 'string' ? workspacePath : undefined
128
+ } catch {
129
+ return undefined
130
+ }
131
+ }
132
+
133
+ // The id a removed workspace had, so re-adding the same folder brings back its
134
+ // chats, pin and settings.
135
+ export async function findStateIdForPath(workspacePath: string): Promise<string | undefined> {
136
+ for (const id of await listStateIds()) {
137
+ if ((await peekWorkspacePath(id)) === workspacePath) return id
138
+ }
139
+ return undefined
140
+ }
141
+
142
+ // Startup housekeeping: drop temp files a killed process left behind, and the
143
+ // state of removed workspaces whose folders no longer exist. A removed
144
+ // workspace whose folder still exists keeps its state for re-adding.
145
+ export async function prepareWorkspaceStates(registered: readonly WorkspaceRef[]): Promise<void> {
146
+ const registeredIds = new Set(registered.map(ws => ws.id))
147
+ for (const id of await listStateIds()) {
148
+ const dir = join(root, id)
149
+ if (!registeredIds.has(id)) {
150
+ const workspacePath = await peekWorkspacePath(id)
151
+ if (workspacePath && !existsSync(workspacePath)) {
152
+ await rm(dir, { recursive: true, force: true })
153
+ continue
154
+ }
155
+ }
156
+ const files = await readdir(dir).catch(() => [])
157
+ for (const file of files) {
158
+ if (file.startsWith(`${STATE_FILE}.`) && file.endsWith('.tmp'))
159
+ await rm(join(dir, file), { force: true })
160
+ }
161
+ }
162
+ }
@@ -0,0 +1,79 @@
1
+ // One-time import of the pre-0.13 global stores into per-workspace state,
2
+ // keyed by workspace path. Imports registered workspaces only, then deletes
3
+ // the old files. Delete this file after v0.14.
4
+ import { rm } from 'node:fs/promises'
5
+ import { join } from 'node:path'
6
+
7
+ import { DATA_DIR } from '../data-dir'
8
+ import { normalizeWorkspaceState } from './file'
9
+ import { hasWorkspaceState, updateWorkspaceState } from './index'
10
+ import type { WorkspaceRef } from './types'
11
+
12
+ type LegacySession = {
13
+ tabId?: string
14
+ config?: unknown
15
+ forkedFromSessionId?: string
16
+ forkedThroughMessageId?: string
17
+ forkedNoticeIds?: string[]
18
+ }
19
+ type LegacySelection = { selected?: unknown; pinned?: unknown }
20
+ type LegacyView = { id: string; executionSessionId?: string }
21
+
22
+ export const LEGACY_FILES = [
23
+ 'sessions.json',
24
+ 'session-config.json',
25
+ 'selected-sessions.json',
26
+ 'pending-views.json',
27
+ 'view-builders.json'
28
+ ]
29
+
30
+ function readLegacy<T>(dataDir: string, name: string): Promise<Record<string, T>> {
31
+ return Bun.file(join(dataDir, name))
32
+ .json()
33
+ .catch(() => ({}))
34
+ }
35
+
36
+ export async function migrateLegacyWorkspaceState(
37
+ workspaces: readonly WorkspaceRef[],
38
+ dataDir = DATA_DIR
39
+ ): Promise<void> {
40
+ const sessions = await readLegacy<Record<string, LegacySession>>(dataDir, 'sessions.json')
41
+ const selections = await readLegacy<LegacySelection>(dataDir, 'selected-sessions.json')
42
+ const pendingViews = await readLegacy<LegacyView[]>(dataDir, 'pending-views.json')
43
+
44
+ for (const ws of workspaces) {
45
+ if (hasWorkspaceState(ws.id)) continue
46
+ const state = normalizeWorkspaceState(
47
+ {
48
+ pinnedSessionId: selections[ws.path]?.pinned,
49
+ selected: selections[ws.path]?.selected,
50
+ sessions: Object.fromEntries(
51
+ Object.entries(sessions[ws.path] ?? {}).map(([id, session]) => [
52
+ id,
53
+ {
54
+ tabId: session.tabId,
55
+ config: session.config,
56
+ fork: session.forkedFromSessionId && {
57
+ fromSessionId: session.forkedFromSessionId,
58
+ throughMessageId: session.forkedThroughMessageId,
59
+ noticeIds: session.forkedNoticeIds
60
+ }
61
+ }
62
+ ])
63
+ ),
64
+ pendingViews: Object.fromEntries(
65
+ (pendingViews[ws.path] ?? []).map(({ id, executionSessionId, ...view }) => [
66
+ id,
67
+ { ...view, buildSessionId: executionSessionId }
68
+ ])
69
+ )
70
+ },
71
+ ws.path
72
+ )
73
+ await updateWorkspaceState(ws, draft => {
74
+ Object.assign(draft, state)
75
+ })
76
+ }
77
+
78
+ for (const name of LEGACY_FILES) await rm(join(dataDir, name), { force: true })
79
+ }
@@ -0,0 +1,42 @@
1
+ // One holder per key at a time. A holder that runs past the timeout stops
2
+ // blocking the queue: the next waiter starts, and the stale holder's lease
3
+ // reports it is no longer current so it can refuse to commit late.
4
+
5
+ export type Lease = {
6
+ isCurrent(): boolean
7
+ }
8
+
9
+ export class LockTimeoutError extends Error {
10
+ constructor(key: string) {
11
+ super(`Lock on ${key} expired before the write could commit`)
12
+ }
13
+ }
14
+
15
+ export function createKeyedLock(timeoutMs: number) {
16
+ const tails = new Map<string, Promise<void>>()
17
+ const owners = new Map<string, number>()
18
+ let lastToken = 0
19
+
20
+ return async function withLock<T>(key: string, run: (lease: Lease) => Promise<T>): Promise<T> {
21
+ const previous = tails.get(key) ?? Promise.resolve()
22
+ let release!: () => void
23
+ const released = new Promise<void>(resolve => (release = resolve))
24
+ tails.set(key, released)
25
+ await previous
26
+
27
+ const token = ++lastToken
28
+ owners.set(key, token)
29
+ const expiry = setTimeout(release, timeoutMs)
30
+ expiry.unref?.()
31
+ try {
32
+ return await run({ isCurrent: () => owners.get(key) === token })
33
+ } finally {
34
+ clearTimeout(expiry)
35
+ release()
36
+ if (tails.get(key) === released) {
37
+ tails.delete(key)
38
+ owners.delete(key)
39
+ }
40
+ }
41
+ }
42
+ }
@@ -0,0 +1,16 @@
1
+ import type { WorkspaceEntry, WorkspaceState } from '@/lib/types'
2
+
3
+ export const WORKSPACE_STATE_VERSION = 1
4
+
5
+ // What the store needs to find a workspace's file and stamp its folder path.
6
+ export type WorkspaceRef = Pick<WorkspaceEntry, 'id' | 'path'>
7
+
8
+ // `state.json` on disk: the state clients see, plus the file format version
9
+ // and the folder it belongs to. Chat titles and history stay in each
10
+ // harness's transcripts.
11
+ export type StoredWorkspaceState = WorkspaceState & {
12
+ version: typeof WORKSPACE_STATE_VERSION
13
+ // A re-added workspace (new registration) finds its old id through it, and
14
+ // startup prunes state for deleted folders.
15
+ workspacePath: string
16
+ }
@@ -0,0 +1,88 @@
1
+ import { loadLayout, saveLayout } from './layout'
2
+ import type { WorkspaceEntry, WorkspaceType } from '@/lib/types'
3
+ import { harnessFor } from '../harness/registry'
4
+ import { harnessStore } from '../harness/auth'
5
+ import { getWorkspaceSkillsStatus } from '../skills/update'
6
+ import { publishEvent } from '../events'
7
+ import { updateWorkspaceState } from '../workspace-state'
8
+ import { getWorkspace, updateWorkspaceHarness } from './registry'
9
+ import { HarnessTransitionError, withHarnessTransition } from './harness-transition'
10
+ import { installWorkspaceSkills } from '../skills/workspace'
11
+
12
+ // Keep successful preparation for this server lifetime; failed attempts can retry.
13
+ const preparation = new Map<string, Promise<void>>()
14
+ export function prepareWorkspaceHarness(ws: WorkspaceEntry): Promise<void> {
15
+ const key = `${ws.path}:${ws.type ?? 'claude-code'}`
16
+ let pending = preparation.get(key)
17
+ if (!pending) {
18
+ pending = getWorkspaceSkillsStatus(ws.path, ws.type)
19
+ .then(async status => {
20
+ if (status.skills.some(skill => !skill.installed))
21
+ await installWorkspaceSkills(ws.path, ws.type)
22
+ })
23
+ .catch(error => {
24
+ preparation.delete(key)
25
+ throw error
26
+ })
27
+ preparation.set(key, pending)
28
+ }
29
+ return pending
30
+ }
31
+
32
+ export async function changeWorkspaceHarness(ws: WorkspaceEntry, type: WorkspaceType) {
33
+ return withHarnessTransition(ws, async () => {
34
+ const current = await getWorkspace(ws.id)
35
+ if (!current) throw new HarnessTransitionError('Workspace not found')
36
+ const previousType = current.type ?? 'claude-code'
37
+ const harness = harnessFor(current)
38
+ if (
39
+ !['claude-code', 'codex'].includes(previousType) ||
40
+ !['claude-code', 'codex'].includes(type)
41
+ )
42
+ throw new HarnessTransitionError('This workspace’s agent cannot be changed')
43
+ if (type === previousType) return current
44
+ if (harness.activeSessions().some(session => session.workspaceId === ws.id))
45
+ throw new HarnessTransitionError('Wait for the agent to finish before changing it')
46
+ const layoutBefore = await loadLayout(current.path)
47
+ const before = await updateWorkspaceState(current, state => {
48
+ const before = structuredClone(state)
49
+ state.selected = {}
50
+ delete state.pinnedSessionId
51
+ for (const view of Object.values(state.pendingViews)) {
52
+ delete view.buildSessionId
53
+ view.status = 'draft'
54
+ delete view.error
55
+ }
56
+ return before
57
+ })
58
+ let updated: WorkspaceEntry
59
+ try {
60
+ const layout = { ...layoutBefore }
61
+ delete layout.selectedModel
62
+ delete layout.selectedEffort
63
+ delete layout.selectedSpeedMode
64
+ await saveLayout(layout, current.path)
65
+ updated = await updateWorkspaceHarness(ws.id, type)
66
+ } catch (error) {
67
+ const recovery = await Promise.allSettled([
68
+ saveLayout(layoutBefore, current.path),
69
+ updateWorkspaceState(current, state => Object.assign(state, before))
70
+ ])
71
+ for (const result of recovery) {
72
+ if (result.status === 'rejected')
73
+ console.error('Could not restore workspace state', result.reason)
74
+ }
75
+ throw error
76
+ }
77
+ // Capture and dispose the old runtime before allowing another transition.
78
+ // stopWorkspace only signals local processes; it does not wait for their exit.
79
+ try {
80
+ harness.stopWorkspace?.(current.path)
81
+ } catch (error) {
82
+ console.error('Could not stop previous workspace runtime', error)
83
+ }
84
+ harnessStore.invalidate(current)
85
+ publishEvent({ type: 'workspace-harness:switched', workspaceId: ws.id, harness: type })
86
+ return updated
87
+ })
88
+ }
@@ -0,0 +1,29 @@
1
+ import type { WorkspaceEntry } from '@/lib/types'
2
+
3
+ const operations = new Map<string, number>()
4
+ const switching = new Set<string>()
5
+ export class HarnessTransitionError extends Error {}
6
+
7
+ export function reserveWorkspaceOperation(id: string): () => void {
8
+ if (switching.has(id)) throw new HarnessTransitionError('Agent is changing. Try again')
9
+ operations.set(id, (operations.get(id) ?? 0) + 1)
10
+ return () => {
11
+ const count = (operations.get(id) ?? 1) - 1
12
+ if (count) operations.set(id, count)
13
+ else operations.delete(id)
14
+ }
15
+ }
16
+
17
+ export async function withHarnessTransition<T>(
18
+ ws: WorkspaceEntry,
19
+ operation: () => Promise<T>
20
+ ): Promise<T> {
21
+ if (switching.has(ws.id) || operations.has(ws.id))
22
+ throw new HarnessTransitionError('Workspace is busy. Try again when the agent is idle')
23
+ switching.add(ws.id)
24
+ try {
25
+ return await operation()
26
+ } finally {
27
+ switching.delete(ws.id)
28
+ }
29
+ }
@@ -7,11 +7,34 @@ import { mkdir } from 'node:fs/promises'
7
7
  import { join } from 'node:path'
8
8
 
9
9
  import type { WorkspaceType } from '@/lib/types'
10
- export { validateWorkspaceFolderName } from '@/lib/workspace-name'
10
+ import { workspaceIdFromName } from '@/lib/workspace-name'
11
+ import { validateWorkspaceId } from '@/lib/ids'
12
+ import { getWorkspace } from './registry'
11
13
 
12
14
  import { harnessFor } from '../harness/registry'
13
15
  import { createDependencyInstallLogPath, scaffoldMoiDir } from './scaffold'
14
- import { installBundledSkills } from '../skills/template'
16
+ import { installWorkspaceSkills } from '../skills/workspace'
17
+
18
+ // Reserve a unique folder whose basename is also its workspace ID.
19
+ export async function createWorkspaceDirectory(
20
+ name: string,
21
+ root: string,
22
+ lookup = getWorkspace
23
+ ): Promise<string> {
24
+ const base = workspaceIdFromName(name)
25
+ await mkdir(root, { recursive: true })
26
+ for (let suffix = 1; ; suffix++) {
27
+ const id = suffix === 1 ? base : `${base}-${suffix}`
28
+ if (validateWorkspaceId(id) || (await lookup(id))) continue
29
+ const path = join(root, id)
30
+ try {
31
+ await mkdir(path)
32
+ return path
33
+ } catch (error) {
34
+ if ((error as NodeJS.ErrnoException).code !== 'EEXIST') throw error
35
+ }
36
+ }
37
+ }
15
38
 
16
39
  // Where each backend loads skills from — the harness owns the answer
17
40
  // (Claude Code: `.claude/skills/`; OpenClaw: `<workspace>/skills/`; Codex:
@@ -32,9 +55,9 @@ export type ProvisionResult = {
32
55
  installLogPath: string
33
56
  }
34
57
 
35
- // Lay down everything a workspace needs: create the folder, copy the bundled
36
- // skills into the backend's skills dir, and bootstrap `.moi/`. Idempotent —
37
- // re-running refreshes skills and leaves an existing `.moi/` untouched.
58
+ // Lay down everything a workspace needs: reset Claude/Codex's shared skill
59
+ // (or copy skills to other backends' own destinations), and bootstrap `.moi/`.
60
+ // Re-running refreshes skills and leaves an existing `.moi/` untouched.
38
61
  // Registration in the workspace registry is a separate, caller-owned step.
39
62
  export async function provisionWorkspace(
40
63
  workspaceRoot: string,
@@ -42,7 +65,7 @@ export async function provisionWorkspace(
42
65
  ): Promise<ProvisionResult> {
43
66
  const skillsDir = skillsDirFor(workspaceRoot, type)
44
67
  await mkdir(workspaceRoot, { recursive: true })
45
- await installBundledSkills(skillsDir)
68
+ await installWorkspaceSkills(workspaceRoot, type)
46
69
  const installLogPath = createDependencyInstallLogPath()
47
70
  const scaffold = await scaffoldMoiDir(workspaceRoot, undefined, undefined, installLogPath)
48
71
  return { skillsDir, scaffold, installLogPath }
@@ -1,4 +1,5 @@
1
1
  import { join } from 'path'
2
+ import { isSpeedMode } from '@/lib/speed-mode'
2
3
 
3
4
  import type {
4
5
  AppletKind,
@@ -18,6 +19,8 @@ function normalizeLayout(parsed: Record<string, unknown>): WorkspaceLayout {
18
19
  layout.layoutMode = defaults.layoutMode
19
20
  }
20
21
  layout.tabs = normalizeWorkspaceTabs(layout.tabs)
22
+ if (!isSpeedMode(layout.selectedSpeedMode)) delete layout.selectedSpeedMode
23
+ delete layout.selectedFastMode
21
24
  if (typeof layout.icon === 'string') {
22
25
  layout.icon = { type: 'upload', value: layout.icon }
23
26
  } else if (layout.icon !== undefined && !isWorkspaceIcon(layout.icon)) {
@@ -11,6 +11,7 @@ import { DATA_DIR } from '../data-dir'
11
11
  import { allHarnesses } from '../harness/registry'
12
12
  import type { DiscoveredWorkspaceCandidate } from '../harness/types'
13
13
  import { createdWorkspacesRoot } from '../app-config'
14
+ import { findStateIdForPath } from '../workspace-state'
14
15
 
15
16
  // Replace the home-dir prefix with `~` for display. Keeps the original
16
17
  // absolute path in place; callers should put the result in `displayPath`.
@@ -71,6 +72,17 @@ function locked<T>(operation: () => Promise<T>): Promise<T> {
71
72
  return run
72
73
  }
73
74
 
75
+ // A removed workspace keeps its state folder. Re-adding the same folder takes
76
+ // its old id back, and with it the pinned chat, selections and chat settings.
77
+ async function previousWorkspaceId(
78
+ entries: WorkspaceEntry[],
79
+ normalPath: string
80
+ ): Promise<string | undefined> {
81
+ const id = await findStateIdForPath(normalPath)
82
+ if (!id || validateWorkspaceId(id) || entries.some(e => e.id === id)) return undefined
83
+ return id
84
+ }
85
+
74
86
  export type RegisterOptions = {
75
87
  // Register under this id instead of a generated one. Only accepted while the
76
88
  // workspace is unregistered — see `workspaceIdError`.
@@ -124,7 +136,7 @@ export async function registerWorkspace(
124
136
  const existing = entries.find(e => e.path === normalPath)
125
137
  if (existing) return existing
126
138
  const entry: WorkspaceEntry = {
127
- id: opts.id ?? newWorkspaceId(),
139
+ id: opts.id ?? (await previousWorkspaceId(entries, normalPath)) ?? newWorkspaceId(),
128
140
  path: normalPath,
129
141
  addedAt: new Date().toISOString(),
130
142
  ...(opts.type ? { type: opts.type } : {}),
@@ -277,3 +289,17 @@ export async function discoverWorkspaces(): Promise<DiscoveredWorkspace[]> {
277
289
  withDisplayPath
278
290
  )
279
291
  }
292
+
293
+ export async function updateWorkspaceHarness(
294
+ id: string,
295
+ type: WorkspaceType
296
+ ): Promise<WorkspaceEntry> {
297
+ return locked(async () => {
298
+ const entries = await readRegistry()
299
+ const entry = entries.find(entry => entry.id === id)
300
+ if (!entry) throw new Error('Workspace not found')
301
+ entry.type = type
302
+ await writeRegistry(entries)
303
+ return withDisplayPath(entry)
304
+ })
305
+ }
@@ -343,8 +343,7 @@ moi views set <view-id> --title "<title>" --icon <icon-id>
343
343
  Choose from the available view icons in the hidden context when that list is present. Then write
344
344
  `.moi/views/<view-id>.tsx` and use the same title and icon in its config. Run
345
345
  `moi check --only views/<view-id>` before `moi bundle --only views/<view-id>`. A successful bundle
346
- replaces the pending screen in the same tab. Keep the user's current tab open and finish with a
347
- `moi:/views/<view-id>` link.
346
+ replaces the pending screen in the same tab.
348
347
 
349
348
  ### Styling and UI components
350
349
 
@@ -453,8 +452,11 @@ After the final successful checks, hand off the result according to the task:
453
452
 
454
453
  - After building or editing a widget, run `moi navigate 'moi:/overview'`.
455
454
  - After editing an existing view, run `moi navigate 'moi:/views/<view-id>'`.
456
- - After a pending view build, keep the current tab open and link to `moi:/views/<view-id>` in the
457
- final reply.
455
+ - After a pending view build, keep the current tab open.
456
+
457
+ Use the chat's owning tab from the hidden context to decide whether a view link is useful.
458
+ In a view's own chat, summarize the result without linking back to that same view. Include
459
+ `moi:/views/<view-id>` links when replying from Overview or pointing to another view.
458
460
 
459
461
  Keep the final reply brief and user-facing. Do not include file or storage links, file paths, or
460
462
  bundle, test, and runtime-log summaries.
@@ -520,4 +522,4 @@ This skill is installed with Moi (via the CLI or the UI) and can fall behind whe
520
522
  - **Then** — if you updated, mention it.
521
523
 
522
524
  <!-- moi skill version marker — read by `moi skill` to detect drift; do not edit by hand -->
523
- <moi-skill version="0.20.0" />
525
+ <moi-skill version="0.20.1" />
@@ -124,8 +124,7 @@ distinct `id` values. A single area can omit `id`, which defaults to `"default"`
124
124
 
125
125
  ```tsx
126
126
  import { Cursors } from 'moi/collab'
127
-
128
- <Cursors id="board">{children}</Cursors>
127
+ ;<Cursors id="board">{children}</Cursors>
129
128
  ```
130
129
 
131
130
  #### `PresenceFrame` and `PresenceAvatars`
@@ -164,8 +163,7 @@ owns focus when wrappers are nested.
164
163
  import { PresenceFrame, PresenceAvatars } from 'moi/collab'
165
164
  import { Input } from '../ui/input'
166
165
  import { Textarea } from '../ui/textarea'
167
-
168
- <>
166
+ ;<>
169
167
  <PresenceFrame id="title" align="start">
170
168
  <label htmlFor="title">Title</label>
171
169
  <Input id="title" />
@@ -213,8 +211,7 @@ Wrap each record in a group so its fields belong to that record.
213
211
  ```tsx
214
212
  import { PresenceGroup, PresenceFrame } from 'moi/collab'
215
213
  import { Input } from '../ui/input'
216
-
217
- <PresenceGroup id={task.id}>
214
+ ;<PresenceGroup id={task.id}>
218
215
  <PresenceFrame id="title">
219
216
  <Input aria-label="Task title" defaultValue={task.title} />
220
217
  </PresenceFrame>
@@ -237,8 +234,7 @@ its avatar glides from the previous target to the next.
237
234
  ```tsx
238
235
  import { PresenceGroup, PresenceAvatars } from 'moi/collab'
239
236
  import { Input } from '../ui/input'
240
-
241
- <PresenceGroup id="tasks">
237
+ ;<PresenceGroup id="tasks">
242
238
  {tasks.map(task => (
243
239
  <PresenceAvatars key={task.id} id={task.id}>
244
240
  <Input aria-label={task.title} defaultValue={task.title} />