moi-computer 0.12.1-next.3 → 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 (224) 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/turn-view.tsx +3 -12
  29. package/client/features/chat/messages/user-message-bubble.tsx +63 -0
  30. package/client/features/chat/sessions/api.ts +121 -80
  31. package/client/features/chat/sessions/browser-tab-state.ts +14 -12
  32. package/client/features/chat/sessions/chat-selector.tsx +5 -6
  33. package/client/features/chat/sessions/use-selected-session.ts +172 -257
  34. package/client/features/chat/use-chat.ts +14 -19
  35. package/client/features/collab/workspace-users-menu.tsx +1 -1
  36. package/client/features/demo/demo-dialog.tsx +11 -3
  37. package/client/features/dev/dev-index-page.tsx +5 -0
  38. package/client/features/dev/dev-routes.tsx +2 -0
  39. package/client/features/dev/harness-debug-page.tsx +3 -3
  40. package/client/features/dev/onboarding-preview-page.tsx +76 -0
  41. package/client/features/dev/workspace-setup-mocks.ts +16 -14
  42. package/client/features/dev/workspace-setup-preview.tsx +11 -17
  43. package/client/features/harness/api.ts +45 -15
  44. package/client/features/harness/device-login-steps.tsx +9 -3
  45. package/client/features/harness/harness-login-panel.tsx +228 -0
  46. package/client/features/harness/harness-presentation.ts +15 -0
  47. package/client/features/harness/harness-selector.tsx +119 -0
  48. package/client/features/harness/use-harness-login.ts +77 -0
  49. package/client/features/home/home-page.tsx +7 -7
  50. package/client/features/onboarding/agent-setup-step.tsx +57 -0
  51. package/client/features/onboarding/api.ts +42 -0
  52. package/client/features/onboarding/onboarding-idea-disk.tsx +129 -0
  53. package/client/features/onboarding/onboarding-page.tsx +32 -0
  54. package/client/features/onboarding/onboarding-screen.tsx +20 -0
  55. package/client/features/onboarding/onboarding-status.tsx +24 -0
  56. package/client/features/onboarding/workspace-setup-step.tsx +239 -0
  57. package/client/features/overview/default/registry.tsx +2 -2
  58. package/client/features/overview/default/views-widget.tsx +6 -5
  59. package/client/features/overview/overview.tsx +9 -11
  60. package/client/features/overview/widget-canvas.tsx +1 -1
  61. package/client/features/overview/workspace-name.tsx +2 -2
  62. package/client/features/views/api.ts +69 -16
  63. package/client/features/views/pending-view-screen.tsx +30 -9
  64. package/client/features/views/use-view-actions.ts +19 -20
  65. package/client/features/views/view-presentation.ts +2 -2
  66. package/client/features/views/view-submission.ts +28 -41
  67. package/client/features/workspace/add/api.ts +3 -23
  68. package/client/features/workspace/add/create-workspace-dialog.tsx +6 -5
  69. package/client/features/workspace/add/import-workspace-dialog.tsx +3 -3
  70. package/client/features/workspace/add/workspace-agent-options.ts +11 -12
  71. package/client/features/workspace/add/workspace-agent-selector.tsx +3 -132
  72. package/client/features/workspace/api.ts +32 -36
  73. package/client/features/workspace/harness-transition.ts +88 -0
  74. package/client/features/{settings → workspace/settings}/api.ts +1 -34
  75. package/client/features/{settings → workspace/settings}/general-settings.tsx +76 -2
  76. package/client/features/{settings → workspace/settings}/use-env-vars.ts +1 -1
  77. package/client/features/{settings → workspace/settings}/workspace-icon-picker.tsx +3 -3
  78. package/client/features/workspace/setup/workspace-login-state.tsx +37 -156
  79. package/client/features/workspace/setup/workspace-recovery-states.tsx +0 -12
  80. package/client/features/workspace/setup/workspace-setup.tsx +34 -14
  81. package/client/features/workspace/setup/workspace-welcome-state.tsx +2 -2
  82. package/client/features/workspace/use-workspace-navigation.ts +25 -9
  83. package/client/features/workspace/workspace-content.tsx +11 -8
  84. package/client/features/workspace/workspace-frame.tsx +2 -1
  85. package/client/features/workspace/workspace-layout-context.tsx +5 -2
  86. package/client/features/workspace/workspace-menu.tsx +12 -8
  87. package/client/features/workspace/workspace-pending-screen.tsx +10 -10
  88. package/client/features/workspace/workspace-presentation.tsx +5 -13
  89. package/client/features/workspace/workspace-state.ts +169 -0
  90. package/client/features/workspace/workspace-tabs.tsx +22 -2
  91. package/client/index.css +2 -0
  92. package/client/index.tsx +3 -3
  93. package/client/lib/flags.ts +1 -1
  94. package/client/lib/{app-icon-registry.ts → identity-icon-registry.ts} +10 -14
  95. package/client/runtime/workspace-events.ts +21 -4
  96. package/client/runtime/workspace-theme.ts +9 -0
  97. package/client/tailwind-config.ts +43 -0
  98. package/dist/chunk-0mjzg20x.js +2 -0
  99. package/dist/chunk-2y59vrxg.js +5 -0
  100. package/dist/chunk-58dyt9bk.js +2 -0
  101. package/dist/chunk-5aj040e5.css +1 -0
  102. package/dist/{chunk-tqd3pkg8.css → chunk-60q353jq.css} +1 -1
  103. package/dist/chunk-71fn6rmj.js +546 -0
  104. package/dist/chunk-7yg1m8hx.js +2 -0
  105. package/dist/chunk-825hys3h.js +1 -0
  106. package/dist/chunk-9bb8m9rx.js +2 -0
  107. package/dist/{chunk-11cab5dq.css → chunk-cq2r11fg.css} +1 -1
  108. package/dist/chunk-g0tcwqxc.js +1 -0
  109. package/dist/chunk-n0nab26d.js +1 -0
  110. package/dist/chunk-nf2wkvf9.js +14 -0
  111. package/dist/chunk-v88n1bay.js +74 -0
  112. package/dist/index.html +1 -1
  113. package/lib/harness-instructions.ts +1 -1
  114. package/lib/{app-icons.ts → identity-icons.ts} +6 -7
  115. package/lib/onboarding.ts +41 -0
  116. package/lib/speed-mode.ts +5 -0
  117. package/lib/types.ts +71 -62
  118. package/lib/view-build-directives.ts +1 -2
  119. package/lib/workspace-icon.ts +2 -2
  120. package/lib/workspace-layout.ts +1 -1
  121. package/lib/workspace-name.ts +15 -12
  122. package/package.json +9 -8
  123. package/server/README.md +27 -25
  124. package/server/api/harnesses.ts +31 -8
  125. package/server/api/index.ts +163 -126
  126. package/server/api/onboarding.ts +46 -0
  127. package/server/app-config.ts +16 -24
  128. package/server/app-settings.ts +6 -2
  129. package/server/applets/config.ts +5 -5
  130. package/server/applets/views.ts +19 -17
  131. package/server/cli/commands/init.ts +3 -3
  132. package/server/cli/commands/skill.ts +16 -17
  133. package/server/cli/commands/start.ts +8 -34
  134. package/server/cli/server.ts +18 -6
  135. package/server/collab/config.ts +1 -2
  136. package/server/collab/manager.ts +4 -1
  137. package/server/collab/skill/index.ts +1 -1
  138. package/server/control.ts +3 -3
  139. package/server/data-dir.ts +1 -1
  140. package/server/harness/README.md +24 -8
  141. package/server/harness/acp/session.ts +8 -4
  142. package/server/harness/auth.ts +14 -17
  143. package/server/harness/claude-code/NOTES.md +4 -3
  144. package/server/harness/claude-code/index.ts +2 -0
  145. package/server/harness/claude-code/models.ts +2 -20
  146. package/server/harness/claude-code/run-action.ts +123 -0
  147. package/server/harness/claude-code/session-title.ts +5 -7
  148. package/server/harness/claude-code/session.ts +24 -16
  149. package/server/harness/codex/NOTES.md +14 -9
  150. package/server/harness/codex/adapter.ts +14 -17
  151. package/server/harness/codex/index.ts +2 -0
  152. package/server/harness/codex/run-action.ts +93 -0
  153. package/server/harness/codex/session-title.ts +6 -8
  154. package/server/harness/codex/session.ts +11 -11
  155. package/server/harness/command.ts +45 -0
  156. package/server/harness/executable.ts +5 -0
  157. package/server/harness/fork.ts +6 -4
  158. package/server/harness/install.ts +49 -0
  159. package/server/harness/openclaw/session.ts +1 -2
  160. package/server/harness/run-action.ts +85 -0
  161. package/server/harness/session-title.ts +0 -46
  162. package/server/harness/types.ts +26 -2
  163. package/server/onboarding/brief.ts +29 -0
  164. package/server/onboarding/ideas.ts +48 -0
  165. package/server/onboarding/jobs.ts +291 -0
  166. package/server/onboarding/prompt.md +49 -0
  167. package/server/sessions/archive.ts +5 -14
  168. package/server/sessions/config.ts +17 -16
  169. package/server/sessions/lifecycle.ts +15 -13
  170. package/server/sessions/pending-views.ts +79 -108
  171. package/server/sessions/selected.ts +75 -161
  172. package/server/sessions/store.ts +40 -113
  173. package/server/sessions/view-sessions.ts +128 -111
  174. package/server/skills/locations.ts +82 -0
  175. package/server/skills/lock.ts +29 -0
  176. package/server/skills/template.ts +36 -25
  177. package/server/skills/update.ts +52 -5
  178. package/server/skills/version.ts +17 -22
  179. package/server/skills/workspace.ts +121 -0
  180. package/server/web.ts +22 -8
  181. package/server/workspace-state/file.ts +177 -0
  182. package/server/workspace-state/index.ts +162 -0
  183. package/server/workspace-state/legacy-migration.ts +79 -0
  184. package/server/workspace-state/lock.ts +42 -0
  185. package/server/workspace-state/types.ts +16 -0
  186. package/server/workspaces/change-harness.ts +88 -0
  187. package/server/workspaces/harness-transition.ts +29 -0
  188. package/server/workspaces/init.ts +29 -6
  189. package/server/workspaces/layout.ts +3 -0
  190. package/server/workspaces/registry.ts +27 -1
  191. package/{workspace/.claude/skills/moi-workspace → skill}/SKILL.md +7 -5
  192. package/{workspace/.claude/skills/moi-workspace → skill}/references/COLLAB.md +4 -8
  193. package/skill/references/DESIGN.md +148 -0
  194. package/{workspace/.claude/skills/moi-workspace → skill}/references/SCRATCHPAD.md +2 -2
  195. package/{workspace/.claude/skills/moi-workspace → skill}/references/UI-COMPONENTS.md +3 -0
  196. package/ui-components/badge.tsx +1 -1
  197. package/client/accept-hmr-dependencies.ts +0 -22
  198. package/client/features/workspace/setup/workspace-setup-panel.tsx +0 -18
  199. package/dist/chunk-20ynagd4.js +0 -2
  200. package/dist/chunk-42tde9a6.js +0 -1
  201. package/dist/chunk-9w543s0r.js +0 -2
  202. package/dist/chunk-a5372n61.js +0 -546
  203. package/dist/chunk-aja9y1vn.js +0 -68
  204. package/dist/chunk-fvcvrh3d.css +0 -1
  205. package/dist/chunk-gtfjw3nx.js +0 -1
  206. package/dist/chunk-j39y2aky.js +0 -14
  207. package/dist/chunk-pcnahct1.js +0 -5
  208. package/dist/chunk-pja30km3.js +0 -1
  209. package/dist/chunk-rm894bc2.js +0 -2
  210. package/dist/chunk-tevvtfbk.js +0 -10
  211. package/dist/chunk-tgt9zd0r.js +0 -2
  212. package/dist/chunk-tv5k5z00.js +0 -1
  213. package/dist/chunk-zq2ae5dx.js +0 -2
  214. package/lib/experimental.ts +0 -14
  215. package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +0 -157
  216. /package/client/features/{settings → app-settings}/profile-settings.tsx +0 -0
  217. /package/client/features/{settings → app-settings}/settings-section.tsx +0 -0
  218. /package/client/features/{settings → app-settings}/users-settings.tsx +0 -0
  219. /package/client/features/{settings → workspace/settings}/connectors-settings.tsx +0 -0
  220. /package/client/features/{settings → workspace/settings}/environment-settings.tsx +0 -0
  221. /package/client/features/{settings → workspace/settings}/icon-picker-options.ts +0 -0
  222. /package/client/features/{settings → workspace/settings}/settings-layout.tsx +0 -0
  223. /package/client/features/{settings → workspace/settings}/workspace-settings-dialog.tsx +0 -0
  224. /package/{workspace/.claude/skills/moi-workspace → skill}/references/INTENTS.md +0 -0
@@ -1,4 +1,5 @@
1
- import { APP_ICON_IDS } from '@/lib/app-icons'
1
+ import { HarnessTransitionError, reserveWorkspaceOperation } from '../workspaces/harness-transition'
2
+ import { IDENTITY_ICON_IDS } from '@/lib/identity-icons'
2
3
  import { viewBuildDirectives } from '@/lib/view-build-directives'
3
4
  import { viewIdFromTab, viewTabId } from '@/lib/workspace-tabs'
4
5
  import type { PendingView, SelectedSessionScope, WorkspaceEntry, WorkspaceTabId } from '@/lib/types'
@@ -6,18 +7,22 @@ import { getCollabReferencePath } from '../collab/config'
6
7
  import { harnessFor } from '../harness/registry'
7
8
  import type { SendMessageInput } from '../harness/types'
8
9
  import { ForkUnsupportedError, inheritedHistoryBoundary } from '../harness/fork'
9
- import { publishEvent } from '../events'
10
- import { broadcast } from '../state'
11
- import { getPinnedSession, saveSelectedSession, resolveRenamedSession } from './selected'
12
- import { getSessionRecord, patchSessionRecord } from './store'
10
+ import { updateWorkspaceState } from '../workspace-state'
11
+ import {
12
+ getPinnedSession,
13
+ saveSelectedSession,
14
+ resolveRenamedSession,
15
+ selectSessionForTab
16
+ } from './selected'
17
+ import { getSessionEntry, setSessionTab, updateSessionEntry } from './store'
13
18
  import { getSessionConfig, saveSessionConfig } from './config'
14
19
  import {
15
- beginViewBuild,
16
20
  createPendingView,
17
21
  getPendingView,
18
22
  listPendingViews,
19
23
  patchPendingView,
20
- PendingViewError
24
+ PendingViewError,
25
+ startViewBuild
21
26
  } from './pending-views'
22
27
 
23
28
  export class ViewStartupError extends Error {
@@ -31,7 +36,7 @@ export class ViewStartupError extends Error {
31
36
  }
32
37
  type BuildSendOptions = Pick<
33
38
  SendMessageInput,
34
- 'attachments' | 'optimisticId' | 'model' | 'effort' | 'fastMode' | 'stream'
39
+ 'attachments' | 'optimisticId' | 'model' | 'effort' | 'speedMode' | 'stream'
35
40
  > & { selectedSessionScope?: SelectedSessionScope }
36
41
  export type SubmitViewInput = BuildSendOptions & { requirements: string; sessionId?: string }
37
42
 
@@ -40,85 +45,92 @@ export async function sendWorkspaceMessage(
40
45
  ws: WorkspaceEntry,
41
46
  input: SendMessageInput & { selectedSessionScope?: SelectedSessionScope; viewBuildId?: string }
42
47
  ) {
43
- const { selectedSessionScope, viewBuildId, ...message } = input
44
- const sessionId = resolveRenamedSession(ws.path, input.sessionId)
45
- const record = await getSessionRecord(ws.path, sessionId)
46
- const tabId = input.context?.activeTab?.id ?? record.tabId ?? 'overview'
47
- const targetViewId = viewBuildId ?? (input.isNew ? viewIdFromTab(tabId) : undefined)
48
- const ownedViews = targetViewId
49
- ? []
50
- : (await listPendingViews(ws.path)).filter(view => view.executionSessionId === sessionId)
51
- const pending = targetViewId
52
- ? await getPendingView(ws.path, targetViewId)
53
- : (ownedViews.find(view => view.id === viewIdFromTab(tabId)) ?? ownedViews[0])
54
- const isBuildRequest = pending && (viewBuildId === pending.id || input.isNew)
55
- if (
56
- isBuildRequest &&
57
- pending.executionSessionId &&
58
- pending.executionSessionId !== sessionId &&
59
- (pending.status === 'starting' ||
60
- harnessFor(ws)
61
- .activeSessions()
62
- .some(
63
- session =>
64
- session.workspaceId === ws.id && session.sessionId === pending.executionSessionId
65
- ))
66
- )
67
- throw new PendingViewError('This view is already being built in another chat', 409)
68
- if (input.isNew && record.tabId !== tabId) {
69
- record.tabId = tabId === 'overview' ? undefined : tabId
70
- await attachSession(ws, tabId, sessionId, null, selectedSessionScope)
71
- }
72
- if (isBuildRequest)
73
- await patchPendingView(ws.id, ws.path, pending.id, {
74
- executionSessionId: sessionId
75
- })
76
- const collabReference = await getCollabReferencePath(ws.path, ws.type)
77
- const pinnedSessionId = await getPinnedSession(ws.path)
78
- await harnessFor(ws).sendMessage({
79
- ...message,
80
- sessionId,
81
- context: {
82
- ...input.context,
83
- session: {
84
- id: sessionId,
85
- tabId: record.tabId,
86
- pinned: pinnedSessionId === sessionId
87
- },
88
- ...(collabReference ? { collabReference } : {}),
89
- directives: [
90
- ...(input.context?.directives ?? []),
91
- ...(isBuildRequest ? viewBuildDirectives(pending.id, APP_ICON_IDS) : []),
92
- ...(isBuildRequest && record.forkedFromSessionId
93
- ? [
94
- 'Inherited conversation is background. Work on the current request; do not resume unrelated earlier tasks.'
95
- ]
96
- : []),
97
- ...(pending && input.isNew && pending.requirements !== input.content
98
- ? [`Original view requirements:\n${pending.requirements}`]
99
- : []),
100
- ...(pending && input.attachments?.length
101
- ? ['Use the attachments as reference material for the intended view.']
102
- : [])
103
- ]
48
+ const release = reserveWorkspaceOperation(ws.id)
49
+ try {
50
+ const { getWorkspace } = await import('../workspaces/registry')
51
+ const current = await getWorkspace(ws.id)
52
+ if (current && (current.type ?? 'claude-code') !== (ws.type ?? 'claude-code'))
53
+ throw new HarnessTransitionError('Agent changed. Start a new chat')
54
+ const { prepareWorkspaceHarness } = await import('../workspaces/change-harness')
55
+ await prepareWorkspaceHarness(ws)
56
+ const { selectedSessionScope, viewBuildId, ...message } = input
57
+ const sessionId = resolveRenamedSession(ws.id, input.sessionId)
58
+ const record = await getSessionEntry(ws, sessionId)
59
+ const tabId = input.context?.activeTab?.id ?? record.tabId ?? 'overview'
60
+ const targetViewId = viewBuildId ?? (input.isNew ? viewIdFromTab(tabId) : undefined)
61
+ const ownedViews = targetViewId
62
+ ? []
63
+ : (await listPendingViews(ws)).filter(view => view.buildSessionId === sessionId)
64
+ const pending = targetViewId
65
+ ? await getPendingView(ws, targetViewId)
66
+ : (ownedViews.find(view => view.id === viewIdFromTab(tabId)) ?? ownedViews[0])
67
+ const isBuildRequest = pending && (viewBuildId === pending.id || input.isNew)
68
+ if (
69
+ isBuildRequest &&
70
+ pending.buildSessionId &&
71
+ pending.buildSessionId !== sessionId &&
72
+ (pending.status === 'starting' ||
73
+ harnessFor(ws)
74
+ .activeSessions()
75
+ .some(
76
+ session => session.workspaceId === ws.id && session.sessionId === pending.buildSessionId
77
+ ))
78
+ )
79
+ throw new PendingViewError('This view is already being built in another chat', 409)
80
+ if (input.isNew && record.tabId !== tabId) {
81
+ record.tabId = tabId === 'overview' ? undefined : tabId
82
+ await attachSession(ws, tabId, sessionId, null, selectedSessionScope)
104
83
  }
105
- })
106
- if (pending && pending.status !== 'starting')
107
- await patchPendingView(ws.id, ws.path, pending.id, { status: 'submitted', error: undefined })
84
+ if (isBuildRequest)
85
+ await patchPendingView(ws, pending.id, {
86
+ buildSessionId: sessionId
87
+ })
88
+ const collabReference = await getCollabReferencePath(ws.path, ws.type)
89
+ const pinnedSessionId = await getPinnedSession(ws)
90
+ await harnessFor(ws).sendMessage({
91
+ ...message,
92
+ sessionId,
93
+ context: {
94
+ ...input.context,
95
+ session: {
96
+ id: sessionId,
97
+ tabId: record.tabId,
98
+ pinned: pinnedSessionId === sessionId
99
+ },
100
+ ...(collabReference ? { collabReference } : {}),
101
+ directives: [
102
+ ...(input.context?.directives ?? []),
103
+ ...(isBuildRequest ? viewBuildDirectives(pending.id, IDENTITY_ICON_IDS) : []),
104
+ ...(isBuildRequest && record.fork
105
+ ? [
106
+ 'Inherited conversation is background. Work on the current request; do not resume unrelated earlier tasks.'
107
+ ]
108
+ : []),
109
+ ...(pending && input.isNew && pending.requirements !== input.content
110
+ ? [`Original view requirements:\n${pending.requirements}`]
111
+ : []),
112
+ ...(pending && input.attachments?.length
113
+ ? ['Use the attachments as reference material for the intended view.']
114
+ : [])
115
+ ]
116
+ }
117
+ })
118
+ if (pending && pending.status !== 'starting')
119
+ await patchPendingView(ws, pending.id, { status: 'submitted', error: undefined })
120
+ } finally {
121
+ release()
122
+ }
108
123
  }
124
+
109
125
  async function attachSession(
110
126
  ws: WorkspaceEntry,
111
127
  tabId: WorkspaceTabId,
112
128
  sessionId: string,
113
- previousSessionId?: string | null,
129
+ ifMatch?: string | null,
114
130
  selectedSessionScope: SelectedSessionScope = 'shared'
115
131
  ) {
116
- await patchSessionRecord(ws.path, sessionId, { tabId: tabId === 'overview' ? undefined : tabId })
117
- broadcast(ws.id, { type: 'sessions_changed', sessionId })
118
- if (selectedSessionScope === 'shared') {
119
- await saveSelectedSession(ws.path, sessionId, previousSessionId, tabId)
120
- publishEvent({ type: 'selected-session:updated', workspaceId: ws.id, sessionId })
121
- }
132
+ await updateSessionEntry(ws, sessionId, { tabId: tabId === 'overview' ? undefined : tabId })
133
+ if (selectedSessionScope === 'shared') await saveSelectedSession(ws, sessionId, tabId, ifMatch)
122
134
  }
123
135
  async function sendBuild(
124
136
  ws: WorkspaceEntry,
@@ -137,7 +149,7 @@ async function sendBuild(
137
149
  viewBuildId: view.id,
138
150
  content: view.requirements
139
151
  })
140
- await patchPendingView(ws.id, ws.path, view.id, { status: 'submitted' }, 'starting')
152
+ await patchPendingView(ws, view.id, { status: 'submitted' }, 'starting')
141
153
  }
142
154
  async function failStartup(
143
155
  ws: WorkspaceEntry,
@@ -147,8 +159,7 @@ async function failStartup(
147
159
  ): Promise<never> {
148
160
  if (view)
149
161
  await patchPendingView(
150
- ws.id,
151
- ws.path,
162
+ ws,
152
163
  view.id,
153
164
  {
154
165
  status: 'failed',
@@ -158,30 +169,38 @@ async function failStartup(
158
169
  )
159
170
  throw new ViewStartupError(
160
171
  error,
161
- sessionId ? resolveRenamedSession(ws.path, sessionId) : undefined,
172
+ sessionId ? resolveRenamedSession(ws.id, sessionId) : undefined,
162
173
  view?.id
163
174
  )
164
175
  }
165
176
 
166
177
  export async function submitView(ws: WorkspaceEntry, viewId: string, input: SubmitViewInput) {
167
- const pinned = await getPinnedSession(ws.path)
168
- const sessionId = pinned ?? input.sessionId ?? crypto.randomUUID()
169
- const view = await beginViewBuild(
170
- ws.id,
171
- ws.path,
172
- viewId,
173
- input.requirements,
174
- sessionId,
175
- !!input.attachments?.length
176
- )
178
+ const tabId = viewTabId(viewId)
179
+ const shared = (input.selectedSessionScope ?? 'shared') === 'shared'
180
+ // The build, the chat's tab and the tab's selection start in one write. A
181
+ // pinned chat takes the build and keeps its own tab.
182
+ const { view, sessionId, pinned } = await updateWorkspaceState(ws, state => {
183
+ const pinned = state.pinnedSessionId
184
+ const sessionId = pinned ?? input.sessionId ?? crypto.randomUUID()
185
+ const view = startViewBuild(
186
+ state,
187
+ viewId,
188
+ input.requirements,
189
+ sessionId,
190
+ !!input.attachments?.length
191
+ )
192
+ if (!pinned) {
193
+ setSessionTab(state, sessionId, tabId)
194
+ if (shared) selectSessionForTab(state, ws.id, sessionId, tabId)
195
+ }
196
+ return { view, sessionId, pinned }
197
+ })
177
198
  try {
178
- if (!pinned)
179
- await attachSession(ws, viewTabId(view.id), sessionId, undefined, input.selectedSessionScope)
180
199
  await sendBuild(ws, view, sessionId, !pinned, input)
181
200
  } catch (error) {
182
201
  return failStartup(ws, error, sessionId, view)
183
202
  }
184
- return { viewId, sessionId: resolveRenamedSession(ws.path, sessionId) }
203
+ return { viewId, sessionId: resolveRenamedSession(ws.id, sessionId) }
185
204
  }
186
205
  export async function createViewFromSession(
187
206
  ws: WorkspaceEntry,
@@ -190,18 +209,18 @@ export async function createViewFromSession(
190
209
  ) {
191
210
  if (!requirements.trim()) throw new Error('View requirements are required')
192
211
  if (fromSessionId === undefined) {
193
- const view = await createPendingView(ws.id, ws.path, {
212
+ const view = await createPendingView(ws, {
194
213
  requirements: requirements.trim(),
195
214
  status: 'submitted'
196
215
  })
197
216
  return {
198
217
  viewId: view.id,
199
218
  mode: 'in-place' as const,
200
- buildInstructions: viewBuildDirectives(view.id, APP_ICON_IDS)
219
+ buildInstructions: viewBuildDirectives(view.id, IDENTITY_ICON_IDS)
201
220
  }
202
221
  }
203
222
  if (!fromSessionId) throw new Error('Session id cannot be empty')
204
- fromSessionId = resolveRenamedSession(ws.path, fromSessionId)
223
+ fromSessionId = resolveRenamedSession(ws.id, fromSessionId)
205
224
  const harness = harnessFor(ws)
206
225
  if (
207
226
  !(await harness.listSessions(ws)).some(session => session.sessionId === fromSessionId) &&
@@ -213,7 +232,7 @@ export async function createViewFromSession(
213
232
  let sessionId: string | undefined
214
233
  let view: PendingView | undefined
215
234
  try {
216
- const sourceConfig = await getSessionConfig(ws.path, fromSessionId)
235
+ const sourceConfig = await getSessionConfig(ws, fromSessionId)
217
236
  try {
218
237
  sessionId = await harness.forkSession?.(ws, fromSessionId, sourceConfig)
219
238
  } catch (error) {
@@ -222,39 +241,37 @@ export async function createViewFromSession(
222
241
  const isNew = !sessionId
223
242
  sessionId ??= crypto.randomUUID()
224
243
  if (!isNew) {
225
- await patchSessionRecord(ws.path, sessionId, { forkedFromSessionId: fromSessionId })
244
+ await updateSessionEntry(ws, sessionId, { fork: { fromSessionId } })
226
245
  // The fork API returns only a child ID. A failed history read leaves the
227
246
  // child usable and its full transcript visible.
228
247
  const history = await harness.sessionEvents(ws, sessionId).catch(() => undefined)
229
248
  if (history)
230
- await patchSessionRecord(ws.path, sessionId, {
231
- forkedFromSessionId: fromSessionId,
232
- ...inheritedHistoryBoundary(history)
249
+ await updateSessionEntry(ws, sessionId, {
250
+ fork: { fromSessionId, ...inheritedHistoryBoundary(history) }
233
251
  })
234
252
  }
235
- const config = await saveSessionConfig(ws.path, sessionId, sourceConfig)
236
- view = await createPendingView(ws.id, ws.path, {
253
+ const config = await saveSessionConfig(ws, sessionId, sourceConfig)
254
+ view = await createPendingView(ws, {
237
255
  status: 'starting',
238
256
  requirements: requirements.trim(),
239
- executionSessionId: sessionId
257
+ buildSessionId: sessionId
240
258
  })
241
259
  await attachSession(ws, viewTabId(view.id), sessionId)
242
260
  await sendBuild(ws, view, sessionId, isNew, config)
243
261
  return {
244
262
  viewId: view.id,
245
263
  mode: 'handoff' as const,
246
- sessionId: resolveRenamedSession(ws.path, sessionId)
264
+ sessionId: resolveRenamedSession(ws.id, sessionId)
247
265
  }
248
266
  } catch (error) {
249
267
  return failStartup(ws, error, sessionId, view)
250
268
  }
251
269
  }
252
270
  export async function failInterruptedViewStarts(ws: WorkspaceEntry) {
253
- for (const view of await listPendingViews(ws.path)) {
271
+ for (const view of await listPendingViews(ws)) {
254
272
  if (view.status === 'starting')
255
273
  await patchPendingView(
256
- ws.id,
257
- ws.path,
274
+ ws,
258
275
  view.id,
259
276
  {
260
277
  status: 'failed',
@@ -0,0 +1,82 @@
1
+ import { lstat, realpath } from 'node:fs/promises'
2
+ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'
3
+
4
+ import type { WorkspaceType } from '@/lib/types'
5
+
6
+ import { skillsDirFor } from '../workspaces/init'
7
+ import { bundledSkillNames } from './template'
8
+ import { usesSharedWorkspaceSkill } from './workspace'
9
+
10
+ type SkillDirectory = {
11
+ targetPath: string
12
+ exists: boolean
13
+ brokenLink?: string
14
+ }
15
+
16
+ export type SkillLocation = SkillDirectory & {
17
+ name: string
18
+ path: string
19
+ }
20
+
21
+ // Resolve existing links, including links in parents of a missing installation.
22
+ // A dangling link is distinct from an absent directory. Claude/Codex can reset
23
+ // their owned skill links; other harnesses keep reporting them as errors.
24
+ async function inspectDirectory(path: string): Promise<SkillDirectory> {
25
+ const entry = await lstat(path).catch((error: unknown) => {
26
+ if ((error as NodeJS.ErrnoException).code === 'ENOENT') return undefined
27
+ throw error
28
+ })
29
+ if (!entry) {
30
+ const parent = await inspectDirectory(dirname(path))
31
+ return { ...parent, exists: false, targetPath: join(parent.targetPath, basename(path)) }
32
+ }
33
+ try {
34
+ return { exists: true, targetPath: await realpath(path) }
35
+ } catch (error) {
36
+ if (
37
+ entry.isSymbolicLink() &&
38
+ ['ENOENT', 'ELOOP'].includes((error as NodeJS.ErrnoException).code ?? '')
39
+ ) {
40
+ return { exists: true, targetPath: path, brokenLink: path }
41
+ }
42
+ throw error
43
+ }
44
+ }
45
+
46
+ // Claude/Codex require both paths to the shared skill. Other harnesses require
47
+ // their primary destination and include existing Claude/Codex installations.
48
+ export async function resolveSkillLocations(
49
+ workspaceRoot: string,
50
+ type?: WorkspaceType
51
+ ): Promise<SkillLocation[]> {
52
+ const root = resolve(workspaceRoot)
53
+ const primary = resolve(skillsDirFor(root, type))
54
+ const directories = [
55
+ ...new Set([primary, join(root, '.claude', 'skills'), join(root, '.agents', 'skills')])
56
+ ]
57
+ const locations: SkillLocation[] = []
58
+ for (const name of await bundledSkillNames()) {
59
+ for (const directory of directories) {
60
+ const path = join(directory, name)
61
+ try {
62
+ const inspected = await inspectDirectory(path)
63
+ if (
64
+ usesSharedWorkspaceSkill(type) ||
65
+ directory === primary ||
66
+ inspected.exists ||
67
+ inspected.brokenLink
68
+ ) {
69
+ locations.push({ name, path, ...inspected })
70
+ }
71
+ } catch (cause) {
72
+ throw new Error(`Cannot inspect skill at ${path}: ${String(cause)}`, { cause })
73
+ }
74
+ }
75
+ }
76
+ return locations
77
+ }
78
+
79
+ export function displaySkillPath(workspaceRoot: string, path: string): string {
80
+ const local = relative(workspaceRoot, path)
81
+ return local === '..' || local.startsWith(`..${sep}`) || isAbsolute(local) ? path : local
82
+ }
@@ -0,0 +1,29 @@
1
+ import { Mutex } from 'async-mutex'
2
+ import { realpath } from 'node:fs/promises'
3
+ import { basename, dirname, join, resolve } from 'node:path'
4
+
5
+ const locks = new Map<string, { mutex: Mutex; users: number }>()
6
+
7
+ // Resolve existing ancestors too, so a new installation and a symlinked path
8
+ // to that installation share a lock before the skill directory exists.
9
+ async function resolveLockPath(path: string): Promise<string> {
10
+ try {
11
+ return await realpath(path)
12
+ } catch (error) {
13
+ if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error
14
+ return join(await resolveLockPath(dirname(path)), basename(path))
15
+ }
16
+ }
17
+
18
+ // Coordinates this process only; independent CLI processes need their own lock.
19
+ export async function withSkillLock<T>(path: string, run: () => Promise<T>): Promise<T> {
20
+ const key = await resolveLockPath(resolve(path))
21
+ const entry = locks.get(key) ?? { mutex: new Mutex(), users: 0 }
22
+ locks.set(key, entry)
23
+ entry.users++
24
+ try {
25
+ return await entry.mutex.runExclusive(run)
26
+ } finally {
27
+ if (--entry.users === 0) locks.delete(key)
28
+ }
29
+ }
@@ -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
  }