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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (243) 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 +6 -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 +10 -0
  11. package/client/app/routes/workspace-route.tsx +21 -19
  12. package/client/app/shell/sidebar-layout.tsx +34 -53
  13. package/client/components/shared/screen-shell.tsx +23 -0
  14. package/client/components/shared/ultrafast-icon.tsx +61 -0
  15. package/client/components/shared/workspace-icon.tsx +2 -2
  16. package/client/features/account/account-menu.tsx +96 -0
  17. package/client/features/account/account-provider.tsx +142 -0
  18. package/client/features/account/account-test-utils.tsx +294 -0
  19. package/client/features/account/api.ts +142 -0
  20. package/client/features/account/identity.ts +23 -0
  21. package/client/features/app-settings/api.ts +33 -0
  22. package/client/features/app-settings/general-settings.tsx +39 -0
  23. package/client/features/app-settings/profile-settings.tsx +95 -0
  24. package/client/features/app-settings/settings-page.tsx +48 -0
  25. package/client/features/app-settings/settings-section.tsx +26 -0
  26. package/client/features/app-settings/users-settings.tsx +195 -0
  27. package/client/features/chat/applet-chat-intents.ts +4 -20
  28. package/client/features/chat/chat-send.ts +17 -13
  29. package/client/features/chat/composer/model-order.ts +8 -4
  30. package/client/features/chat/composer/model-picker.tsx +88 -34
  31. package/client/features/chat/composer/use-workspace-composer-state.tsx +11 -3
  32. package/client/features/chat/composer/use-workspace-skill-updates.ts +1 -1
  33. package/client/features/chat/connection/chat-frames.ts +3 -15
  34. package/client/features/chat/messages/chat-empty-state.tsx +1 -4
  35. package/client/features/chat/messages/fork-history.ts +5 -5
  36. package/client/features/chat/messages/turn-view.tsx +3 -12
  37. package/client/features/chat/messages/user-message-bubble.tsx +63 -0
  38. package/client/features/chat/sessions/api.ts +121 -80
  39. package/client/features/chat/sessions/browser-tab-state.ts +14 -12
  40. package/client/features/chat/sessions/chat-selector.tsx +5 -6
  41. package/client/features/chat/sessions/use-selected-session.ts +172 -257
  42. package/client/features/chat/use-chat.ts +14 -19
  43. package/client/features/collab/applet-api.ts +15 -14
  44. package/client/features/collab/components/cursors.tsx +61 -24
  45. package/client/features/collab/components/presence-avatars.tsx +25 -12
  46. package/client/features/collab/components/presence-frame.tsx +20 -24
  47. package/client/features/collab/components/presence-group.tsx +15 -7
  48. package/client/features/collab/components/user-avatar-group.tsx +21 -8
  49. package/client/features/collab/components/user-avatar.tsx +38 -7
  50. package/client/features/collab/components/user.tsx +31 -12
  51. package/client/features/collab/users.ts +0 -5
  52. package/client/features/collab/workspace-users-menu.tsx +4 -4
  53. package/client/features/demo/demo-dialog.tsx +11 -3
  54. package/client/features/dev/collab/collab-playground.tsx +7 -7
  55. package/client/features/dev/collab/local-user-settings.tsx +7 -53
  56. package/client/features/dev/dev-index-page.tsx +5 -0
  57. package/client/features/dev/dev-routes.tsx +2 -0
  58. package/client/features/dev/harness-debug-page.tsx +3 -3
  59. package/client/features/dev/onboarding-preview-page.tsx +76 -0
  60. package/client/features/dev/workspace-setup-mocks.ts +16 -14
  61. package/client/features/dev/workspace-setup-preview.tsx +11 -17
  62. package/client/features/harness/api.ts +45 -15
  63. package/client/features/harness/device-login-steps.tsx +9 -3
  64. package/client/features/harness/harness-login-panel.tsx +228 -0
  65. package/client/features/harness/harness-presentation.ts +15 -0
  66. package/client/features/harness/harness-selector.tsx +119 -0
  67. package/client/features/harness/use-harness-login.ts +77 -0
  68. package/client/features/home/home-page.tsx +7 -7
  69. package/client/features/onboarding/agent-setup-step.tsx +57 -0
  70. package/client/features/onboarding/api.ts +42 -0
  71. package/client/features/onboarding/onboarding-idea-disk.tsx +129 -0
  72. package/client/features/onboarding/onboarding-page.tsx +32 -0
  73. package/client/features/onboarding/onboarding-screen.tsx +20 -0
  74. package/client/features/onboarding/onboarding-status.tsx +24 -0
  75. package/client/features/onboarding/workspace-setup-step.tsx +239 -0
  76. package/client/features/overview/default/registry.tsx +2 -2
  77. package/client/features/overview/default/views-widget.tsx +6 -5
  78. package/client/features/overview/overview.tsx +9 -11
  79. package/client/features/overview/widget-canvas.tsx +1 -1
  80. package/client/features/overview/workspace-name.tsx +2 -2
  81. package/client/features/update/update-control.tsx +1 -1
  82. package/client/features/views/api.ts +69 -16
  83. package/client/features/views/pending-view-screen.tsx +30 -9
  84. package/client/features/views/use-view-actions.ts +19 -20
  85. package/client/features/views/view-presentation.ts +2 -2
  86. package/client/features/views/view-submission.ts +28 -41
  87. package/client/features/workspace/add/api.ts +3 -23
  88. package/client/features/workspace/add/create-workspace-dialog.tsx +11 -7
  89. package/client/features/workspace/add/import-workspace-dialog.tsx +3 -3
  90. package/client/features/workspace/add/workspace-agent-options.ts +11 -12
  91. package/client/features/workspace/add/workspace-agent-selector.tsx +3 -132
  92. package/client/features/workspace/api.ts +32 -36
  93. package/client/features/workspace/harness-transition.ts +88 -0
  94. package/client/features/{settings → workspace/settings}/api.ts +1 -34
  95. package/client/features/{settings → workspace/settings}/connectors-settings.tsx +3 -3
  96. package/client/features/{settings → workspace/settings}/environment-settings.tsx +3 -3
  97. package/client/features/{settings → workspace/settings}/general-settings.tsx +77 -3
  98. package/client/features/{settings → workspace/settings}/use-env-vars.ts +1 -1
  99. package/client/features/{settings → workspace/settings}/workspace-icon-picker.tsx +3 -3
  100. package/client/features/workspace/setup/workspace-login-state.tsx +37 -156
  101. package/client/features/workspace/setup/workspace-recovery-states.tsx +0 -12
  102. package/client/features/workspace/setup/workspace-setup.tsx +34 -14
  103. package/client/features/workspace/setup/workspace-welcome-state.tsx +2 -2
  104. package/client/features/workspace/use-workspace-navigation.ts +25 -9
  105. package/client/features/workspace/workspace-content.tsx +11 -8
  106. package/client/features/workspace/workspace-frame.tsx +2 -1
  107. package/client/features/workspace/workspace-layout-context.tsx +5 -2
  108. package/client/features/workspace/workspace-menu.tsx +12 -8
  109. package/client/features/workspace/workspace-pending-screen.tsx +10 -10
  110. package/client/features/workspace/workspace-presentation.tsx +5 -13
  111. package/client/features/workspace/workspace-state.ts +169 -0
  112. package/client/features/workspace/workspace-tabs.tsx +22 -2
  113. package/client/index.css +2 -0
  114. package/client/index.tsx +3 -3
  115. package/client/lib/flags.ts +1 -1
  116. package/client/lib/{app-icon-registry.ts → identity-icon-registry.ts} +10 -14
  117. package/client/lib/user-display-name.ts +6 -0
  118. package/client/main.tsx +4 -1
  119. package/client/runtime/workspace-events.ts +21 -4
  120. package/client/runtime/workspace-theme.ts +9 -0
  121. package/client/tailwind-config.ts +43 -0
  122. package/dist/chunk-0mjzg20x.js +2 -0
  123. package/dist/chunk-2y59vrxg.js +5 -0
  124. package/dist/chunk-58dyt9bk.js +2 -0
  125. package/dist/chunk-5aj040e5.css +1 -0
  126. package/dist/{chunk-tqd3pkg8.css → chunk-60q353jq.css} +1 -1
  127. package/dist/chunk-71fn6rmj.js +546 -0
  128. package/dist/chunk-7yg1m8hx.js +2 -0
  129. package/dist/chunk-825hys3h.js +1 -0
  130. package/dist/chunk-9bb8m9rx.js +2 -0
  131. package/dist/{chunk-11cab5dq.css → chunk-cq2r11fg.css} +1 -1
  132. package/dist/chunk-g0tcwqxc.js +1 -0
  133. package/dist/chunk-n0nab26d.js +1 -0
  134. package/dist/chunk-nf2wkvf9.js +14 -0
  135. package/dist/chunk-v88n1bay.js +74 -0
  136. package/dist/index.html +1 -1
  137. package/lib/harness-instructions.ts +1 -1
  138. package/lib/{app-icons.ts → identity-icons.ts} +6 -7
  139. package/lib/onboarding.ts +41 -0
  140. package/lib/speed-mode.ts +5 -0
  141. package/lib/types.ts +72 -63
  142. package/lib/view-build-directives.ts +1 -2
  143. package/lib/workspace-icon.ts +2 -2
  144. package/lib/workspace-layout.ts +1 -1
  145. package/lib/workspace-name.ts +15 -12
  146. package/package.json +9 -8
  147. package/server/README.md +27 -25
  148. package/server/api/harnesses.ts +31 -8
  149. package/server/api/index.ts +164 -131
  150. package/server/api/onboarding.ts +46 -0
  151. package/server/app-config.ts +23 -24
  152. package/server/app-settings.ts +6 -2
  153. package/server/applets/config.ts +5 -5
  154. package/server/applets/views.ts +19 -17
  155. package/server/cli/commands/init.ts +3 -3
  156. package/server/cli/commands/skill.ts +16 -17
  157. package/server/cli/commands/start.ts +8 -34
  158. package/server/cli/server.ts +18 -6
  159. package/server/collab/config.ts +1 -2
  160. package/server/collab/manager.ts +4 -1
  161. package/server/collab/skill/index.ts +1 -1
  162. package/server/control.ts +3 -3
  163. package/server/data-dir.ts +1 -1
  164. package/server/harness/README.md +24 -8
  165. package/server/harness/acp/session.ts +8 -4
  166. package/server/harness/auth.ts +14 -17
  167. package/server/harness/claude-code/NOTES.md +4 -3
  168. package/server/harness/claude-code/index.ts +2 -0
  169. package/server/harness/claude-code/models.ts +2 -20
  170. package/server/harness/claude-code/run-action.ts +123 -0
  171. package/server/harness/claude-code/session-title.ts +5 -7
  172. package/server/harness/claude-code/session.ts +24 -16
  173. package/server/harness/codex/NOTES.md +14 -9
  174. package/server/harness/codex/adapter.ts +14 -17
  175. package/server/harness/codex/index.ts +2 -0
  176. package/server/harness/codex/run-action.ts +93 -0
  177. package/server/harness/codex/session-title.ts +6 -8
  178. package/server/harness/codex/session.ts +11 -11
  179. package/server/harness/command.ts +45 -0
  180. package/server/harness/executable.ts +5 -0
  181. package/server/harness/fork.ts +6 -4
  182. package/server/harness/install.ts +49 -0
  183. package/server/harness/openclaw/session.ts +1 -2
  184. package/server/harness/run-action.ts +85 -0
  185. package/server/harness/session-title.ts +0 -46
  186. package/server/harness/types.ts +26 -2
  187. package/server/onboarding/brief.ts +29 -0
  188. package/server/onboarding/ideas.ts +48 -0
  189. package/server/onboarding/jobs.ts +291 -0
  190. package/server/onboarding/prompt.md +49 -0
  191. package/server/sessions/archive.ts +5 -14
  192. package/server/sessions/config.ts +17 -16
  193. package/server/sessions/lifecycle.ts +15 -13
  194. package/server/sessions/pending-views.ts +79 -108
  195. package/server/sessions/selected.ts +75 -161
  196. package/server/sessions/store.ts +40 -113
  197. package/server/sessions/view-sessions.ts +128 -111
  198. package/server/skills/locations.ts +82 -0
  199. package/server/skills/lock.ts +29 -0
  200. package/server/skills/template.ts +36 -25
  201. package/server/skills/update.ts +52 -5
  202. package/server/skills/version.ts +17 -22
  203. package/server/skills/workspace.ts +121 -0
  204. package/server/web.ts +23 -8
  205. package/server/workspace-state/file.ts +177 -0
  206. package/server/workspace-state/index.ts +162 -0
  207. package/server/workspace-state/legacy-migration.ts +79 -0
  208. package/server/workspace-state/lock.ts +42 -0
  209. package/server/workspace-state/types.ts +16 -0
  210. package/server/workspaces/change-harness.ts +88 -0
  211. package/server/workspaces/harness-transition.ts +29 -0
  212. package/server/workspaces/init.ts +29 -16
  213. package/server/workspaces/layout.ts +3 -0
  214. package/server/workspaces/registry.ts +58 -10
  215. package/{workspace/.claude/skills/moi-workspace → skill}/SKILL.md +7 -5
  216. package/{workspace/.claude/skills/moi-workspace → skill}/references/COLLAB.md +4 -8
  217. package/skill/references/DESIGN.md +148 -0
  218. package/{workspace/.claude/skills/moi-workspace → skill}/references/SCRATCHPAD.md +2 -2
  219. package/{workspace/.claude/skills/moi-workspace → skill}/references/UI-COMPONENTS.md +3 -0
  220. package/ui-components/badge.tsx +1 -1
  221. package/client/accept-hmr-dependencies.ts +0 -22
  222. package/client/features/workspace/setup/workspace-setup-panel.tsx +0 -18
  223. package/dist/chunk-00rh9df4.js +0 -2
  224. package/dist/chunk-4nh7y1hq.css +0 -1
  225. package/dist/chunk-am4agx6v.js +0 -2
  226. package/dist/chunk-d7cbm65e.js +0 -2
  227. package/dist/chunk-hbpdv7vd.js +0 -1
  228. package/dist/chunk-hmka9rt5.js +0 -2
  229. package/dist/chunk-hvh9f5h0.js +0 -14
  230. package/dist/chunk-mjjregkn.js +0 -10
  231. package/dist/chunk-pcnahct1.js +0 -5
  232. package/dist/chunk-rt30jbcm.js +0 -1
  233. package/dist/chunk-vt6zybej.js +0 -2
  234. package/dist/chunk-wbkwf6cc.js +0 -68
  235. package/dist/chunk-xjyfyz64.js +0 -1
  236. package/dist/chunk-y8nbwp21.js +0 -546
  237. package/dist/chunk-ysfdcew7.js +0 -1
  238. package/lib/experimental.ts +0 -14
  239. package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +0 -157
  240. /package/client/features/{settings → workspace/settings}/icon-picker-options.ts +0 -0
  241. /package/client/features/{settings → workspace/settings}/settings-layout.tsx +0 -0
  242. /package/client/features/{settings → workspace/settings}/workspace-settings-dialog.tsx +0 -0
  243. /package/{workspace/.claude/skills/moi-workspace → skill}/references/INTENTS.md +0 -0
@@ -5,28 +5,26 @@
5
5
  import { cp, lstat, mkdir, readFile, readdir, readlink } from 'node:fs/promises'
6
6
  import { join } from 'node:path'
7
7
 
8
- // Source directory for shipped templates. Resolved relative to this file so
9
- // symlinked CLI binaries still find the source tree.
10
- export const TEMPLATE_DIR = join(import.meta.dir, '..', '..', 'workspace')
8
+ // Resolve relative to this file so source checkouts and published installs agree.
9
+ const BUNDLED_SKILL_DIR = join(import.meta.dir, '..', '..', 'skill')
11
10
 
12
- // The folder holding the skill packages this CLI ships. Each subdirectory is
13
- // one skill (e.g. `moi-workspace/`) with its own `SKILL.md`. Source of truth
14
- // for what `moi skill update` copies and what versions it compares against.
15
- export const BUNDLED_SKILLS_DIR = join(TEMPLATE_DIR, '.claude', 'skills')
11
+ export function bundledSkillDirectory(name: string): string {
12
+ if (name !== 'moi-workspace') throw new Error(`Unknown bundled skill: ${name}`)
13
+ return BUNDLED_SKILL_DIR
14
+ }
15
+
16
+ export async function bundledSkillNames(): Promise<string[]> {
17
+ return ['moi-workspace']
18
+ }
16
19
 
17
- export const COLLAB_REFERENCE_SOURCE_PATH = join(
18
- BUNDLED_SKILLS_DIR,
19
- 'moi-workspace',
20
- 'references',
21
- 'COLLAB.md'
22
- )
20
+ export const COLLAB_REFERENCE_SOURCE_PATH = join(BUNDLED_SKILL_DIR, 'references', 'COLLAB.md')
23
21
 
24
22
  // The guide lives beside the other references, but only explicit collab init installs it.
25
23
  function isDefaultSkillFile(source: string): boolean {
26
24
  return source !== COLLAB_REFERENCE_SOURCE_PATH
27
25
  }
28
26
 
29
- async function matchesBundledPath(source: string, target: string): Promise<boolean> {
27
+ async function matchesBundledPath(source: string, target: string, exact = false): Promise<boolean> {
30
28
  const sourceStat = await lstat(source)
31
29
  const targetStat = await lstat(target).catch(() => null)
32
30
  if (!targetStat) return false
@@ -34,8 +32,9 @@ async function matchesBundledPath(source: string, target: string): Promise<boole
34
32
  if (sourceStat.isDirectory()) {
35
33
  if (!targetStat.isDirectory()) return false
36
34
  const entries = (await readdir(source)).filter(entry => isDefaultSkillFile(join(source, entry)))
35
+ if (exact && (await readdir(target)).length !== entries.length) return false
37
36
  const matches = await Promise.all(
38
- entries.map(entry => matchesBundledPath(join(source, entry), join(target, entry)))
37
+ entries.map(entry => matchesBundledPath(join(source, entry), join(target, entry), exact))
39
38
  )
40
39
  return matches.every(Boolean)
41
40
  }
@@ -55,6 +54,10 @@ async function matchesBundledPath(source: string, target: string): Promise<boole
55
54
  return false
56
55
  }
57
56
 
57
+ export function matchesBundledSkill(name: string, target: string): Promise<boolean> {
58
+ return matchesBundledPath(bundledSkillDirectory(name), target, true)
59
+ }
60
+
58
61
  // Copy changed shipped skill folders into `targetSkillsDir`. Leaves identical
59
62
  // skills untouched, along with unrelated directories and extra local files.
60
63
  // Creates the target if missing and returns the names whose bundled files changed.
@@ -66,17 +69,25 @@ async function matchesBundledPath(source: string, target: string): Promise<boole
66
69
  export async function installBundledSkills(targetSkillsDir: string): Promise<string[]> {
67
70
  await mkdir(targetSkillsDir, { recursive: true })
68
71
  const changedSkills: string[] = []
69
- const skillEntries = await readdir(BUNDLED_SKILLS_DIR, { withFileTypes: true })
70
-
71
- for (const entry of skillEntries) {
72
- if (!entry.isDirectory()) continue
73
- const source = join(BUNDLED_SKILLS_DIR, entry.name)
74
- const target = join(targetSkillsDir, entry.name)
75
- if (await matchesBundledPath(source, target)) continue
76
-
77
- await cp(source, target, { recursive: true, force: true, filter: isDefaultSkillFile })
78
- changedSkills.push(entry.name)
72
+ for (const name of await bundledSkillNames()) {
73
+ if (await installBundledSkill(name, join(targetSkillsDir, name))) changedSkills.push(name)
79
74
  }
80
75
 
81
76
  return changedSkills
82
77
  }
78
+
79
+ // Update one resolved destination without installing other skills beside it.
80
+ export async function installBundledSkill(name: string, target: string): Promise<boolean> {
81
+ const source = bundledSkillDirectory(name)
82
+ if (await matchesBundledPath(source, target)) return false
83
+ // Publish the version only after all references copied successfully, so a
84
+ // partial update cannot hide an outdated installation behind a fresh marker.
85
+ const marker = join(source, 'SKILL.md')
86
+ await cp(source, target, {
87
+ recursive: true,
88
+ force: true,
89
+ filter: path => path !== marker && isDefaultSkillFile(path)
90
+ })
91
+ await cp(marker, join(target, 'SKILL.md'), { force: true })
92
+ return true
93
+ }
@@ -1,15 +1,24 @@
1
+ import { basename } from 'node:path'
2
+
1
3
  import type { WorkspaceSkillsStatus, WorkspaceSkillStatus, WorkspaceType } from '@/lib/types'
2
4
 
3
5
  import type { AppletDeclarationFile } from '../applets/declarations'
4
6
  import { syncAppletDeclarations } from '../applets/declarations'
5
- import { isBehind, skillStatuses } from './version'
6
- import { installBundledSkills } from './template'
7
- import { skillsDirFor } from '../workspaces/init'
7
+ import { isBehind, skillStatuses, skillStatusesForLocations } from './version'
8
+ import { installBundledSkill } from './template'
9
+ import { resolveSkillLocations } from './locations'
10
+ import {
11
+ installWorkspaceSkillFiles,
12
+ usesSharedWorkspaceSkill,
13
+ workspaceSkillLockPath
14
+ } from './workspace'
15
+ import { withSkillLock } from './lock'
8
16
 
9
17
  export type WorkspaceSkillUpdateResult = {
10
18
  before: WorkspaceSkillStatus[]
11
19
  status: WorkspaceSkillsStatus
12
20
  changedSkills: string[]
21
+ changedSkillPaths: string[]
13
22
  updatedAppletTypes: AppletDeclarationFile[]
14
23
  }
15
24
 
@@ -31,8 +40,45 @@ export async function updateWorkspaceSkills(
31
40
  workspaceRoot: string,
32
41
  type: WorkspaceType = 'claude-code'
33
42
  ): Promise<WorkspaceSkillUpdateResult> {
34
- const before = await skillStatuses(workspaceRoot, type)
35
- const changedSkills = await installBundledSkills(skillsDirFor(workspaceRoot, type))
43
+ return withSkillLock(workspaceSkillLockPath(workspaceRoot, type), () =>
44
+ updateWorkspaceSkillFiles(workspaceRoot, type)
45
+ )
46
+ }
47
+
48
+ async function updateWorkspaceSkillFiles(
49
+ workspaceRoot: string,
50
+ type: WorkspaceType
51
+ ): Promise<WorkspaceSkillUpdateResult> {
52
+ const locations = await resolveSkillLocations(workspaceRoot, type)
53
+ const before = await skillStatusesForLocations(locations)
54
+ let changedSkillPaths: string[]
55
+ if (usesSharedWorkspaceSkill(type)) {
56
+ changedSkillPaths = await installWorkspaceSkillFiles(workspaceRoot, type)
57
+ } else {
58
+ for (const location of locations) {
59
+ if (location.brokenLink) {
60
+ throw new Error(
61
+ `Cannot update skill at ${location.path}: broken symlink ${location.brokenLink}`
62
+ )
63
+ }
64
+ }
65
+ const changedTargets = new Map<string, boolean>()
66
+ for (const location of locations) {
67
+ if (changedTargets.has(location.targetPath)) continue
68
+ try {
69
+ changedTargets.set(
70
+ location.targetPath,
71
+ await installBundledSkill(location.name, location.targetPath)
72
+ )
73
+ } catch (cause) {
74
+ throw new Error(`Cannot update skill at ${location.path}: ${String(cause)}`, { cause })
75
+ }
76
+ }
77
+ changedSkillPaths = locations
78
+ .filter(location => changedTargets.get(location.targetPath))
79
+ .map(location => location.path)
80
+ }
81
+ const changedSkills = [...new Set(changedSkillPaths.map(path => basename(path)))]
36
82
  // Applet declarations ship with the CLI, so refresh installed copies along
37
83
  // with skills. The optional collab declaration is only updated if present.
38
84
  const updatedAppletTypes = await syncAppletDeclarations(workspaceRoot)
@@ -42,6 +88,7 @@ export async function updateWorkspaceSkills(
42
88
  before,
43
89
  status: summarizeSkillStatuses(skills),
44
90
  changedSkills,
91
+ changedSkillPaths,
45
92
  updatedAppletTypes
46
93
  }
47
94
  }
@@ -1,14 +1,14 @@
1
1
  // Skill versioning for a workspace's installed skill copy drifting behind the
2
2
  // version this moi installation ships. The marker in each skill's `SKILL.md`
3
3
  // drives both the CLI status and the frontend's automatic update check.
4
- import { readdir } from 'node:fs/promises'
5
4
  import { join } from 'node:path'
6
5
 
7
6
  import type { WorkspaceSkillStatus, WorkspaceType } from '@/lib/types'
8
7
 
9
8
  import { findWorkspaceForPath, liftToWorkspaceRoot, listWorkspaces } from '../workspaces/registry'
10
- import { BUNDLED_SKILLS_DIR } from './template'
11
- import { skillsDirFor } from '../workspaces/init'
9
+ import { bundledSkillDirectory } from './template'
10
+ import { displaySkillPath, resolveSkillLocations } from './locations'
11
+ import type { SkillLocation } from './locations'
12
12
 
13
13
  // The version is stamped as a self-contained marker in SKILL.md, e.g.
14
14
  // `<moi-skill version="0.1.0" />`, rather than in YAML frontmatter. SKILL.md
@@ -71,30 +71,23 @@ export const isMinorBehind = (installed: string | null, bundled: string | null):
71
71
  export const isBehind = (installed: string | null, bundled: string | null): boolean =>
72
72
  compare(installed, bundled).behind
73
73
 
74
- // Skills shipped with this CLI — directory names under the bundled skills dir.
75
- export async function bundledSkillNames(): Promise<string[]> {
76
- try {
77
- const entries = await readdir(BUNDLED_SKILLS_DIR, { withFileTypes: true })
78
- return entries.filter(e => e.isDirectory()).map(e => e.name)
79
- } catch {
80
- return []
81
- }
82
- }
83
-
84
- // Per-skill installed-vs-bundled versions for a workspace root. `type` picks
85
- // the installed-skills location (OpenClaw keeps them in `skills/`, not
86
- // `.claude/skills/`) — pass the registry entry's type when known.
74
+ // Report every installed copy, plus the required primary harness destination.
87
75
  export async function skillStatuses(
88
76
  workspaceRoot: string,
89
77
  type?: WorkspaceType
90
78
  ): Promise<WorkspaceSkillStatus[]> {
91
- const names = await bundledSkillNames()
92
- const skillsDir = skillsDirFor(workspaceRoot, type)
79
+ return skillStatusesForLocations(await resolveSkillLocations(workspaceRoot, type))
80
+ }
81
+
82
+ export async function skillStatusesForLocations(
83
+ locations: SkillLocation[]
84
+ ): Promise<WorkspaceSkillStatus[]> {
93
85
  return Promise.all(
94
- names.map(async name => ({
86
+ locations.map(async ({ name, path, brokenLink }) => ({
95
87
  name,
96
- bundled: await readSkillVersion(join(BUNDLED_SKILLS_DIR, name, 'SKILL.md')),
97
- installed: await readSkillVersion(join(skillsDir, name, 'SKILL.md'))
88
+ path,
89
+ bundled: await readSkillVersion(join(bundledSkillDirectory(name), 'SKILL.md')),
90
+ installed: brokenLink ? null : await readSkillVersion(join(path, 'SKILL.md'))
98
91
  }))
99
92
  )
100
93
  }
@@ -126,7 +119,9 @@ export async function staleSkillNotice(cwd: string): Promise<string | null> {
126
119
  isMinorBehind(s.installed, s.bundled)
127
120
  )
128
121
  if (stale.length === 0) return null
129
- const parts = stale.map(s => `${s.name} (${s.installed ?? 'none'} → ${s.bundled})`)
122
+ const parts = stale.map(
123
+ s => `${displaySkillPath(root, s.path)} (${s.installed ?? 'none'} → ${s.bundled})`
124
+ )
130
125
  return `⚠ Moi skill outdated: ${parts.join(', ')} — run \`moi skill update\` to refresh.`
131
126
  } catch {
132
127
  return null
@@ -0,0 +1,121 @@
1
+ import { lstat, mkdir, mkdtemp, readlink, realpath, rename, rm, symlink } from 'node:fs/promises'
2
+ import { dirname, join, relative, resolve } from 'node:path'
3
+
4
+ import type { WorkspaceType } from '@/lib/types'
5
+
6
+ import { installBundledSkill, installBundledSkills, matchesBundledSkill } from './template'
7
+ import { skillsDirFor } from '../workspaces/init'
8
+ import { withSkillLock } from './lock'
9
+
10
+ const SKILL_NAME = 'moi-workspace'
11
+
12
+ export function usesSharedWorkspaceSkill(type?: WorkspaceType): boolean {
13
+ return type === undefined || type === 'claude-code' || type === 'codex'
14
+ }
15
+
16
+ async function entryAt(path: string) {
17
+ return lstat(path).catch((error: unknown) => {
18
+ if ((error as NodeJS.ErrnoException).code === 'ENOENT') return undefined
19
+ throw error
20
+ })
21
+ }
22
+
23
+ // Replacing a whole-folder link would also change unrelated skills.
24
+ async function checkSkillsDirectory(path: string): Promise<void> {
25
+ if ((await entryAt(path))?.isSymbolicLink()) {
26
+ throw new Error(
27
+ `Cannot install workspace skill: ${path} is a symlink; use a real skills directory`
28
+ )
29
+ }
30
+ }
31
+
32
+ export async function installWorkspaceSkills(
33
+ root: string,
34
+ type?: WorkspaceType
35
+ ): Promise<string[]> {
36
+ return withSkillLock(workspaceSkillLockPath(root, type), () =>
37
+ installWorkspaceSkillFiles(root, type)
38
+ )
39
+ }
40
+
41
+ export function workspaceSkillLockPath(root: string, type?: WorkspaceType): string {
42
+ return usesSharedWorkspaceSkill(type) ? join(root, '.agents', 'skills') : skillsDirFor(root, type)
43
+ }
44
+
45
+ // Callers must hold the workspace skill lock across any surrounding status reads.
46
+ export async function installWorkspaceSkillFiles(
47
+ root: string,
48
+ type?: WorkspaceType
49
+ ): Promise<string[]> {
50
+ if (usesSharedWorkspaceSkill(type)) return resetWorkspaceSkill(root)
51
+ const directory = skillsDirFor(root, type)
52
+ return (await installBundledSkills(directory)).map(name => join(directory, name))
53
+ }
54
+
55
+ // Both init and updates reset the owned skill. Local additions (including the
56
+ // experimental collab guide) are intentionally discarded; sibling skills stay.
57
+ async function resetWorkspaceSkill(workspaceRoot: string): Promise<string[]> {
58
+ const root = resolve(workspaceRoot)
59
+ const canonical = join(root, '.agents', 'skills', SKILL_NAME)
60
+ const claude = join(root, '.claude', 'skills', SKILL_NAME)
61
+ try {
62
+ await checkSkillsDirectory(dirname(canonical))
63
+ await checkSkillsDirectory(dirname(claude))
64
+ await mkdir(dirname(canonical), { recursive: true })
65
+ await mkdir(dirname(claude), { recursive: true })
66
+ const sharedDirectory =
67
+ (await realpath(dirname(canonical))) === (await realpath(dirname(claude)))
68
+ if (!sharedDirectory && (await entryAt(join(root, '.claude')))?.isSymbolicLink()) {
69
+ throw new Error(
70
+ 'The .claude directory is a symlink; point it to .agents or use a real .claude directory'
71
+ )
72
+ }
73
+ const linkTarget = relative(dirname(claude), canonical)
74
+ const claudeEntry = await entryAt(claude)
75
+ const linked =
76
+ sharedDirectory || (claudeEntry?.isSymbolicLink() && (await readlink(claude)) === linkTarget)
77
+ const matches = await matchesBundledSkill(SKILL_NAME, canonical)
78
+ if (matches && linked) return []
79
+
80
+ // Prepare the new files and link before removing either old skill. A copy
81
+ // or symlink-permission failure leaves the installed copies available.
82
+ const staging = await mkdtemp(join(dirname(canonical), '.moi-workspace-'))
83
+ try {
84
+ const skill = join(staging, SKILL_NAME)
85
+ const link = join(staging, 'claude-link')
86
+ if (!matches) await installBundledSkill(SKILL_NAME, skill)
87
+ if (!linked) {
88
+ try {
89
+ await symlink(linkTarget, link, 'dir')
90
+ } catch (cause) {
91
+ const code = (cause as NodeJS.ErrnoException).code
92
+ if (process.platform === 'win32' && (code === 'EPERM' || code === 'EACCES')) {
93
+ throw new Error(
94
+ 'Windows could not create the workspace skill symlink; enable Developer Mode or run Moi as administrator, then retry',
95
+ { cause }
96
+ )
97
+ }
98
+ throw cause
99
+ }
100
+ }
101
+ if (!matches) {
102
+ await rm(canonical, { recursive: true, force: true })
103
+ await rename(skill, canonical)
104
+ }
105
+ if (!linked) {
106
+ await rm(claude, { recursive: true, force: true })
107
+ await rename(link, claude)
108
+ }
109
+ } finally {
110
+ await rm(staging, { recursive: true, force: true })
111
+ }
112
+ return matches ? [claude] : [canonical, claude]
113
+ } catch (cause) {
114
+ throw new Error(
115
+ `Cannot reset workspace skill at ${canonical} and ${claude}: ${String(cause)}`,
116
+ {
117
+ cause
118
+ }
119
+ )
120
+ }
121
+ }
package/server/web.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { isSpeedMode } from '@/lib/speed-mode'
1
2
  import type { UserProfile } from '@/lib/collab/types'
2
3
  import { isMessageAttachments } from '@/lib/message-attachments'
3
4
  import type { ClientMessage, StatusSnapshotMessage } from '@/lib/types'
@@ -10,7 +11,6 @@ import devSandbox from '../client/dev/index.html'
10
11
  import { api } from './api'
11
12
  import { getAppConfig } from './app-config'
12
13
  import { harnessStore } from './harness/auth'
13
- import { AttachmentUploadError } from './sessions/attachment-message'
14
14
  import { PORT } from './constants'
15
15
  import { control } from './control'
16
16
  import { proxyUserState } from './collab/cloudflare-access'
@@ -25,7 +25,8 @@ import { resolveScratchOp } from './scratchpad/relay'
25
25
  import { allHarnesses, harnessFor } from './harness/registry'
26
26
  import { getWorkspace, listWorkspaces } from './workspaces/registry'
27
27
  import { failInterruptedViewStarts, sendWorkspaceMessage } from './sessions/view-sessions'
28
- import { PendingViewError } from './sessions/pending-views'
28
+ import { prepareWorkspaceStates } from './workspace-state'
29
+ import { migrateLegacyWorkspaceState } from './workspace-state/legacy-migration'
29
30
  import {
30
31
  addClient,
31
32
  broadcast,
@@ -59,7 +60,7 @@ function isClientMessage(value: unknown): value is ClientMessage {
59
60
  optimisticId?: unknown
60
61
  model?: unknown
61
62
  effort?: unknown
62
- fastMode?: unknown
63
+ speedMode?: unknown
63
64
  stream?: unknown
64
65
  context?: unknown
65
66
  attachments?: unknown
@@ -77,7 +78,7 @@ function isClientMessage(value: unknown): value is ClientMessage {
77
78
  (v.optimisticId === undefined || typeof v.optimisticId === 'string') &&
78
79
  (v.model === undefined || typeof v.model === 'string') &&
79
80
  (v.effort === undefined || typeof v.effort === 'string') &&
80
- (v.fastMode === undefined || typeof v.fastMode === 'boolean') &&
81
+ (v.speedMode === undefined || isSpeedMode(v.speedMode)) &&
81
82
  (v.stream === undefined || typeof v.stream === 'boolean') &&
82
83
  (v.context === undefined || isMoiContext(v.context)) &&
83
84
  (v.attachments === undefined || isMessageAttachments(v.attachments))
@@ -110,7 +111,10 @@ function upgrade(server: Upgradable, req: Request, data: WsData) {
110
111
  // Bun owns the fullstack surface: the HTML shell + dev bundler/HMR, and the two
111
112
  // WebSocket channels (which need Bun's native `server.upgrade` + pub/sub). Every
112
113
  // HTTP API route is delegated to the Hono app (`./api`) via `fetch`.
113
- await Promise.all((await listWorkspaces()).map(failInterruptedViewStarts))
114
+ const registeredWorkspaces = await listWorkspaces()
115
+ await migrateLegacyWorkspaceState(registeredWorkspaces)
116
+ await prepareWorkspaceStates(registeredWorkspaces)
117
+ await Promise.all(registeredWorkspaces.map(failInterruptedViewStarts))
114
118
 
115
119
  // Managed machines serve the web side on a Unix socket file that only the
116
120
  // machine's gateway can open, so nothing else running there reaches the API
@@ -157,6 +161,8 @@ export const app = Bun.serve<WsData>({
157
161
  ? new Response('Not found', { status: 404 })
158
162
  : devSandbox,
159
163
  '/workspace/*': shell,
164
+ '/settings': shell,
165
+ '/onboarding': shell,
160
166
 
161
167
  // Chat websocket — app-wide (one per client, not per workspace). Each chat
162
168
  // frame carries its own workspaceId.
@@ -191,7 +197,16 @@ export const app = Bun.serve<WsData>({
191
197
  },
192
198
  // Anything not matched above (the whole HTTP API + prod static assets + 404)
193
199
  // is handled by Hono.
194
- fetch: req => api.fetch(req),
200
+ fetch: (req, server) => {
201
+ // Downloads can exceed the normal HTTP idle timeout; the installer has its own deadline.
202
+ if (
203
+ req.method === 'POST' &&
204
+ /^\/api\/harnesses\/(claude-code|codex)\/auth\/install$/.test(new URL(req.url).pathname)
205
+ ) {
206
+ server.timeout(req, 0)
207
+ }
208
+ return api.fetch(req)
209
+ },
195
210
  websocket: {
196
211
  open(ws) {
197
212
  if (ws.data.channel === 'collab') {
@@ -238,12 +253,12 @@ export const app = Bun.serve<WsData>({
238
253
  optimisticId: data.optimisticId,
239
254
  model: data.model,
240
255
  effort: data.effort,
241
- fastMode: data.fastMode,
256
+ speedMode: data.speedMode,
242
257
  stream: data.stream,
243
258
  context: data.context,
244
259
  agentId: workspace.agentId
245
260
  }).catch(error => {
246
- if (error instanceof AttachmentUploadError || error instanceof PendingViewError) {
261
+ if (error instanceof Error) {
247
262
  broadcast(workspace.id, {
248
263
  kind: 'error',
249
264
  sessionId: data.sessionId,
@@ -0,0 +1,177 @@
1
+ import { isSpeedMode } from '@/lib/speed-mode'
2
+ import { mkdir, rename, rm } from 'node:fs/promises'
3
+ import { dirname } from 'node:path'
4
+
5
+ import type { PendingView, SessionFork, WorkspaceSessionState } from '@/lib/types'
6
+ import { isWorkspaceTabId } from '@/lib/workspace-tabs'
7
+ import { LockTimeoutError, type Lease } from './lock'
8
+ import { WORKSPACE_STATE_VERSION, type StoredWorkspaceState } from './types'
9
+
10
+ type PendingViewState = Omit<PendingView, 'id'>
11
+
12
+ export type LoadedState = {
13
+ state: StoredWorkspaceState
14
+ // False for a file written by a newer Moi: read what we understand, never
15
+ // overwrite what we don't.
16
+ writable: boolean
17
+ }
18
+
19
+ export class WorkspaceStateVersionError extends Error {
20
+ constructor(path: string) {
21
+ super(`${path} was written by a newer version of Moi. Update Moi to change this workspace.`)
22
+ }
23
+ }
24
+
25
+ const PENDING_VIEW_STATUSES = new Set<string>(['draft', 'starting', 'submitted', 'failed'])
26
+
27
+ export function emptyWorkspaceState(workspacePath: string): StoredWorkspaceState {
28
+ return {
29
+ version: WORKSPACE_STATE_VERSION,
30
+ workspacePath,
31
+ revision: 0,
32
+ selected: {},
33
+ sessions: {},
34
+ pendingViews: {}
35
+ }
36
+ }
37
+
38
+ function isRecord(value: unknown): value is Record<string, unknown> {
39
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
40
+ }
41
+
42
+ function optionalString(value: unknown): string | undefined {
43
+ return typeof value === 'string' ? value : undefined
44
+ }
45
+
46
+ function normalizeFork(value: unknown): SessionFork | undefined {
47
+ if (!isRecord(value) || typeof value.fromSessionId !== 'string') return undefined
48
+ const noticeIds = Array.isArray(value.noticeIds)
49
+ ? value.noticeIds.filter((id): id is string => typeof id === 'string')
50
+ : undefined
51
+ return {
52
+ fromSessionId: value.fromSessionId,
53
+ ...(typeof value.throughMessageId === 'string'
54
+ ? { throughMessageId: value.throughMessageId }
55
+ : {}),
56
+ ...(noticeIds?.length ? { noticeIds } : {})
57
+ }
58
+ }
59
+
60
+ function normalizeSession(value: unknown): WorkspaceSessionState {
61
+ if (!isRecord(value)) return {}
62
+ const session: WorkspaceSessionState = {}
63
+ if (isWorkspaceTabId(value.tabId)) session.tabId = value.tabId
64
+ if (isRecord(value.config)) {
65
+ const { model, effort, speedMode } = value.config
66
+ const config = {
67
+ ...(typeof model === 'string' ? { model } : {}),
68
+ ...(typeof effort === 'string' ? { effort } : {}),
69
+ ...(isSpeedMode(speedMode) ? { speedMode } : {})
70
+ }
71
+ if (Object.keys(config).length) session.config = config
72
+ }
73
+ const fork = normalizeFork(value.fork)
74
+ if (fork) session.fork = fork
75
+ return session
76
+ }
77
+
78
+ function normalizePendingView(value: unknown): PendingViewState | undefined {
79
+ if (!isRecord(value) || !PENDING_VIEW_STATUSES.has(String(value.status))) return undefined
80
+ const view: PendingViewState = {
81
+ status: value.status as PendingViewState['status'],
82
+ requirements: optionalString(value.requirements) ?? ''
83
+ }
84
+ for (const key of ['title', 'icon', 'buildSessionId', 'error'] as const) {
85
+ const field = optionalString(value[key])
86
+ if (field !== undefined) view[key] = field
87
+ }
88
+ return view
89
+ }
90
+
91
+ // Keep every entry we can make sense of and drop the rest, so one bad field
92
+ // never costs the whole workspace its state.
93
+ export function normalizeWorkspaceState(
94
+ value: Record<string, unknown>,
95
+ workspacePath: string
96
+ ): StoredWorkspaceState {
97
+ const state = emptyWorkspaceState(optionalString(value.workspacePath) ?? workspacePath)
98
+ if (typeof value.revision === 'number' && Number.isSafeInteger(value.revision))
99
+ state.revision = value.revision
100
+ const pinned = optionalString(value.pinnedSessionId)
101
+ if (pinned) state.pinnedSessionId = pinned
102
+ if (isRecord(value.selected)) {
103
+ for (const [tabId, sessionId] of Object.entries(value.selected)) {
104
+ if (isWorkspaceTabId(tabId) && typeof sessionId === 'string')
105
+ state.selected[tabId] = sessionId
106
+ }
107
+ }
108
+ if (isRecord(value.sessions)) {
109
+ for (const [sessionId, session] of Object.entries(value.sessions))
110
+ state.sessions[sessionId] = normalizeSession(session)
111
+ }
112
+ if (isRecord(value.pendingViews)) {
113
+ for (const [viewId, view] of Object.entries(value.pendingViews)) {
114
+ const normalized = normalizePendingView(view)
115
+ if (normalized) state.pendingViews[viewId] = normalized
116
+ }
117
+ }
118
+ return compactWorkspaceState(state)
119
+ }
120
+
121
+ // Empty session entries and settings carry no information; leaving them out
122
+ // keeps the file readable.
123
+ export function compactWorkspaceState<T extends StoredWorkspaceState>(state: T): T {
124
+ for (const [sessionId, session] of Object.entries(state.sessions)) {
125
+ for (const key of Object.keys(session) as (keyof WorkspaceSessionState)[])
126
+ if (session[key] === undefined) delete session[key]
127
+ if (session.config && Object.keys(session.config).length === 0) delete session.config
128
+ if (Object.keys(session).length === 0) delete state.sessions[sessionId]
129
+ }
130
+ if (!state.pinnedSessionId) delete state.pinnedSessionId
131
+ return state
132
+ }
133
+
134
+ async function setAside(path: string, reason: string): Promise<undefined> {
135
+ const aside = `${path}.corrupt-${Date.now()}`
136
+ await rename(path, aside).catch(() => {})
137
+ console.error(`[workspace-state] ${reason}; moved ${path} to ${aside} and started empty`)
138
+ return undefined
139
+ }
140
+
141
+ // Reads one state file. A missing file reads as undefined. A damaged file is
142
+ // moved aside instead of being overwritten by the next write.
143
+ export async function readStateFile(
144
+ path: string,
145
+ workspacePath: string
146
+ ): Promise<LoadedState | undefined> {
147
+ const file = Bun.file(path)
148
+ if (!(await file.exists())) return undefined
149
+ let parsed: unknown
150
+ try {
151
+ parsed = JSON.parse(await file.text())
152
+ } catch {
153
+ return setAside(path, 'Unreadable JSON')
154
+ }
155
+ if (!isRecord(parsed) || typeof parsed.version !== 'number')
156
+ return setAside(path, 'Not a workspace state file')
157
+ const writable = parsed.version <= WORKSPACE_STATE_VERSION
158
+ if (!writable) console.warn(`[workspace-state] ${new WorkspaceStateVersionError(path).message}`)
159
+ return { state: normalizeWorkspaceState(parsed, workspacePath), writable }
160
+ }
161
+
162
+ let tempSequence = 0
163
+
164
+ // Write to a sibling temp file, then rename over the target: readers see the
165
+ // old file or the new one, never a partial write. A holder whose lock expired
166
+ // gives up before the rename, so a late write cannot replace a newer one.
167
+ export async function writeStateFile(path: string, state: StoredWorkspaceState, lease: Lease) {
168
+ await mkdir(dirname(path), { recursive: true })
169
+ const temp = `${path}.${process.pid}.${++tempSequence}.tmp`
170
+ try {
171
+ await Bun.write(temp, `${JSON.stringify(state, null, 2)}\n`)
172
+ if (!lease.isCurrent()) throw new LockTimeoutError(path)
173
+ await rename(temp, path)
174
+ } finally {
175
+ await rm(temp, { force: true })
176
+ }
177
+ }