moi-computer 0.13.1-next.1 → 0.13.1-next.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/client/api/app-config.ts +12 -1
  2. package/client/api/http.ts +11 -1
  3. package/client/app/app-router.tsx +3 -2
  4. package/client/app/routes/home-route.tsx +1 -1
  5. package/client/app/routes/workspace-registration.tsx +68 -0
  6. package/client/app/routes/workspace-route.tsx +33 -6
  7. package/client/app/shell/sidebar-layout.tsx +10 -5
  8. package/client/components/shared/workspace-icon.tsx +8 -17
  9. package/client/features/account/account-test-utils.tsx +15 -9
  10. package/client/features/account/api.ts +6 -6
  11. package/client/features/account/profile-actions.ts +5 -7
  12. package/client/features/app-settings/settings-page.tsx +2 -1
  13. package/client/features/applets/api.ts +6 -6
  14. package/client/features/applets/applet-cache.ts +6 -5
  15. package/client/features/applets/applet-log.ts +2 -1
  16. package/client/features/applets/applet-runtime.ts +2 -1
  17. package/client/features/applets/use-applet.ts +73 -18
  18. package/client/features/applets/widget-shell.tsx +4 -2
  19. package/client/features/chat/applet-chat-intents.ts +5 -13
  20. package/client/features/chat/chat-popup.tsx +8 -4
  21. package/client/features/chat/chat-send.ts +2 -2
  22. package/client/features/chat/composer/model-order.ts +4 -4
  23. package/client/features/chat/composer/model-picker.tsx +12 -10
  24. package/client/features/chat/composer/use-workspace-composer-state.tsx +1 -1
  25. package/client/features/chat/sessions/api.ts +11 -28
  26. package/client/features/chat/sessions/use-selected-session.ts +14 -109
  27. package/client/features/chat/use-chat.ts +8 -12
  28. package/client/features/collab/members/api.ts +4 -10
  29. package/client/features/collab/members/hooks.ts +32 -38
  30. package/client/features/collab/members/store.ts +96 -71
  31. package/client/features/collab/members/types.ts +5 -3
  32. package/client/features/collab/presence/client.ts +2 -3
  33. package/client/features/collab/presence/hooks.tsx +1 -1
  34. package/client/features/collab/proxy-user.ts +1 -3
  35. package/client/features/collab/sharing/workspace-members.tsx +0 -8
  36. package/client/features/dev/chat-states-page.tsx +3 -1
  37. package/client/features/dev/harness-debug-page.tsx +7 -7
  38. package/client/features/dev/workspace-setup-mocks.ts +1 -1
  39. package/client/features/dev/workspace-setup-preview.tsx +6 -4
  40. package/client/features/harness/api.ts +13 -10
  41. package/client/features/harness/harness-login-panel.tsx +9 -5
  42. package/client/features/harness/harness-presentation.ts +4 -4
  43. package/client/features/harness/harness-selector.tsx +13 -13
  44. package/client/features/harness/use-harness-login.ts +5 -5
  45. package/client/features/home/api.ts +38 -2
  46. package/client/features/home/home-page.tsx +43 -13
  47. package/client/features/home/shared-workspaces.tsx +70 -0
  48. package/client/features/home/workspace-invitations.tsx +101 -0
  49. package/client/features/identity/host-api.ts +3 -2
  50. package/client/features/identity/store.ts +1 -7
  51. package/client/features/onboarding/agent-setup-step.tsx +8 -8
  52. package/client/features/onboarding/onboarding-page.tsx +3 -2
  53. package/client/features/onboarding/workspace-setup-step.tsx +1 -1
  54. package/client/features/overview/api.ts +3 -5
  55. package/client/features/overview/default/registry.tsx +1 -1
  56. package/client/features/overview/default/views-widget.tsx +2 -2
  57. package/client/features/overview/hidden-panel.tsx +7 -5
  58. package/client/features/overview/overview.tsx +18 -16
  59. package/client/features/overview/workspace-name.tsx +2 -2
  60. package/client/features/scratchpad/scratchpad.tsx +9 -7
  61. package/client/features/scratchpad/use-scratchpad-snapshot.tsx +13 -5
  62. package/client/features/views/api.ts +66 -23
  63. package/client/features/views/use-view-actions.ts +10 -41
  64. package/client/features/views/view-manager.tsx +1 -1
  65. package/client/features/views/view-submission.ts +2 -21
  66. package/client/features/workspace/add/api.ts +5 -4
  67. package/client/features/workspace/add/create-workspace-dialog.tsx +12 -9
  68. package/client/features/workspace/add/import-workspace-dialog.tsx +7 -7
  69. package/client/features/workspace/add/use-workspace-import.ts +10 -10
  70. package/client/features/workspace/add/workspace-agent-options.ts +21 -20
  71. package/client/features/workspace/add/workspace-agent-selector.tsx +11 -11
  72. package/client/features/workspace/api.ts +60 -13
  73. package/client/features/workspace/harness-transition.ts +7 -13
  74. package/client/features/workspace/remote.ts +25 -0
  75. package/client/features/workspace/settings/api.ts +7 -12
  76. package/client/features/workspace/settings/connectors-settings.tsx +3 -3
  77. package/client/features/workspace/settings/general-settings.tsx +8 -8
  78. package/client/features/workspace/setup/workspace-login-state.tsx +4 -4
  79. package/client/features/workspace/setup/workspace-recovery-states.tsx +43 -14
  80. package/client/features/workspace/setup/workspace-setup.tsx +6 -6
  81. package/client/features/workspace/tab-resolution.ts +1 -8
  82. package/client/features/workspace/use-workspace-navigation.ts +11 -7
  83. package/client/features/workspace/workspace-content.tsx +24 -31
  84. package/client/features/workspace/workspace-frame.tsx +13 -26
  85. package/client/features/workspace/workspace-layout-context.tsx +45 -12
  86. package/client/features/workspace/workspace-menu.tsx +2 -2
  87. package/client/features/workspace/workspace-pane.tsx +22 -0
  88. package/client/features/workspace/workspace-pending-screen.tsx +1 -1
  89. package/client/features/workspace/workspace-preferences.ts +91 -0
  90. package/client/features/workspace/workspace-presentation.tsx +12 -16
  91. package/client/features/workspace/workspace-screen.tsx +2 -2
  92. package/client/features/workspace/workspace-state.ts +42 -16
  93. package/client/features/workspace/workspace-tabs.tsx +1 -1
  94. package/client/features/workspace/workspace-test-utils.ts +23 -0
  95. package/client/runtime/use-workspace-events.ts +14 -0
  96. package/client/runtime/workspace-events.ts +9 -9
  97. package/client/store/ui.ts +24 -9
  98. package/client/store/workspace-session.ts +30 -0
  99. package/dist/chunk-0h4zypgf.js +1 -0
  100. package/dist/chunk-1tksq43z.js +72 -0
  101. package/dist/chunk-6gxf0xr8.js +5 -0
  102. package/dist/chunk-a865c7x4.js +1 -0
  103. package/dist/chunk-f44cs6mw.js +2 -0
  104. package/dist/chunk-h3qag4a6.js +2 -0
  105. package/dist/chunk-kffcah9w.css +1 -0
  106. package/dist/chunk-q2tpy0h7.js +2 -0
  107. package/dist/chunk-r95acex1.js +546 -0
  108. package/dist/chunk-w5h9grdr.js +1 -0
  109. package/dist/{chunk-th91xfnp.js → chunk-xj1pjhng.js} +1 -1
  110. package/dist/index.html +1 -1
  111. package/lib/harness-instructions.ts +4 -4
  112. package/lib/harness-types.ts +13 -0
  113. package/lib/moi-context.ts +19 -5
  114. package/lib/types.ts +38 -54
  115. package/lib/workspace-config.ts +48 -0
  116. package/lib/workspace-layout.ts +5 -24
  117. package/package.json +5 -2
  118. package/server/AGENTS.md +1 -1
  119. package/server/README.md +36 -31
  120. package/server/api/harnesses.ts +5 -5
  121. package/server/api/index.ts +268 -162
  122. package/server/applets/index.ts +15 -9
  123. package/server/applets/views.ts +2 -17
  124. package/server/applets/widgets.ts +3 -2
  125. package/server/cli/commands/config.ts +8 -20
  126. package/server/cli/commands/hermes.ts +2 -2
  127. package/server/cli/commands/init.ts +102 -54
  128. package/server/cli/commands/openclaw.ts +2 -2
  129. package/server/cli/commands/refresh.ts +10 -1
  130. package/server/cli/commands/remote.ts +330 -0
  131. package/server/cli/commands/skill.ts +4 -4
  132. package/server/cli/commands/tabs.ts +5 -12
  133. package/server/cli/control.ts +35 -4
  134. package/server/cli/index.ts +10 -6
  135. package/server/cli/remote-command.ts +77 -0
  136. package/server/cli/remote-control.ts +73 -0
  137. package/server/cli/remote-operations.ts +247 -0
  138. package/server/collab/config.ts +3 -3
  139. package/server/collab/skill/index.ts +3 -3
  140. package/server/control.ts +47 -12
  141. package/server/harness/acp/session.ts +4 -4
  142. package/server/harness/auth.ts +26 -31
  143. package/server/harness/claude-code/index.ts +1 -1
  144. package/server/harness/codex/discovery.ts +1 -1
  145. package/server/harness/codex/session.ts +1 -1
  146. package/server/harness/detect.ts +14 -19
  147. package/server/harness/executable.ts +10 -10
  148. package/server/harness/hermes/NOTES.md +2 -2
  149. package/server/harness/hermes/index.ts +1 -1
  150. package/server/harness/install.ts +11 -11
  151. package/server/harness/openclaw/index.ts +1 -1
  152. package/server/harness/registry.ts +7 -6
  153. package/server/harness/types.ts +4 -4
  154. package/server/onboarding/jobs.ts +2 -2
  155. package/server/operations/commands.ts +46 -0
  156. package/server/operations/files.ts +148 -0
  157. package/server/operations/server.ts +206 -0
  158. package/server/remote/agent.ts +103 -0
  159. package/server/remote/broker-client.ts +76 -0
  160. package/server/remote/broker.ts +81 -0
  161. package/server/remote/client.ts +725 -0
  162. package/server/remote/errors.ts +2 -0
  163. package/server/remote/routes.ts +121 -0
  164. package/server/remote/workspace.ts +34 -0
  165. package/server/scratchpad/document.ts +33 -12
  166. package/server/scratchpad/executor.ts +16 -7
  167. package/server/sessions/config.ts +8 -5
  168. package/server/sessions/pending-views.ts +17 -0
  169. package/server/sessions/send-message.ts +102 -0
  170. package/server/sessions/view-sessions.ts +9 -101
  171. package/server/skills/locations.ts +4 -4
  172. package/server/skills/update.ts +11 -11
  173. package/server/skills/version.ts +7 -7
  174. package/server/skills/workspace.ts +13 -11
  175. package/server/web.ts +13 -9
  176. package/server/workspace-state/file.ts +4 -0
  177. package/server/workspace-state/index.ts +0 -4
  178. package/server/workspaces/api.ts +24 -0
  179. package/server/workspaces/change-harness.ts +15 -26
  180. package/server/workspaces/import.ts +4 -4
  181. package/server/workspaces/init.ts +15 -13
  182. package/server/workspaces/layout.ts +60 -66
  183. package/server/workspaces/registry.ts +43 -18
  184. package/server/workspaces/shared.ts +74 -0
  185. package/server/workspaces/tabs.ts +5 -12
  186. package/skill/SKILL.md +80 -19
  187. package/skill/references/SCRATCHPAD.md +4 -0
  188. package/skill/references/UI-COMPONENTS.md +1 -1
  189. package/client/api/app-ui-keys.ts +0 -6
  190. package/client/features/chat/sessions/browser-tab-state.ts +0 -43
  191. package/client/features/collab/members/keys.ts +0 -6
  192. package/client/features/workspace/browser-tab-state.ts +0 -51
  193. package/client/features/workspace/layout-save.ts +0 -13
  194. package/dist/chunk-3smkkcfw.js +0 -546
  195. package/dist/chunk-47h9c2qy.js +0 -2
  196. package/dist/chunk-8qed2gqp.js +0 -75
  197. package/dist/chunk-8zy3vesm.js +0 -1
  198. package/dist/chunk-a47zy276.js +0 -2
  199. package/dist/chunk-g4c1nte9.css +0 -1
  200. package/dist/chunk-kcactdr4.js +0 -2
  201. package/dist/chunk-m8bhx6tw.js +0 -1
  202. package/dist/chunk-pf19zcrn.js +0 -2
  203. package/dist/chunk-ygzxah0e.js +0 -1
  204. package/lib/workspace-types.ts +0 -13
  205. package/server/workspace-state/legacy-migration.ts +0 -79
@@ -1,6 +1,6 @@
1
1
  import { basename } from 'node:path'
2
2
 
3
- import type { WorkspaceSkillsStatus, WorkspaceSkillStatus, WorkspaceType } from '@/lib/types'
3
+ import type { WorkspaceSkillsStatus, WorkspaceSkillStatus, HarnessType } from '@/lib/types'
4
4
 
5
5
  import type { AppletDeclarationFile } from '../applets/declarations'
6
6
  import { syncAppletDeclarations } from '../applets/declarations'
@@ -31,29 +31,29 @@ export function summarizeSkillStatuses(skills: WorkspaceSkillStatus[]): Workspac
31
31
 
32
32
  export async function getWorkspaceSkillsStatus(
33
33
  workspaceRoot: string,
34
- type?: WorkspaceType
34
+ harness?: HarnessType
35
35
  ): Promise<WorkspaceSkillsStatus> {
36
- return summarizeSkillStatuses(await skillStatuses(workspaceRoot, type))
36
+ return summarizeSkillStatuses(await skillStatuses(workspaceRoot, harness))
37
37
  }
38
38
 
39
39
  export async function updateWorkspaceSkills(
40
40
  workspaceRoot: string,
41
- type: WorkspaceType = 'claude-code'
41
+ harness: HarnessType = 'claude-code'
42
42
  ): Promise<WorkspaceSkillUpdateResult> {
43
- return withSkillLock(workspaceSkillLockPath(workspaceRoot, type), () =>
44
- updateWorkspaceSkillFiles(workspaceRoot, type)
43
+ return withSkillLock(workspaceSkillLockPath(workspaceRoot, harness), () =>
44
+ updateWorkspaceSkillFiles(workspaceRoot, harness)
45
45
  )
46
46
  }
47
47
 
48
48
  async function updateWorkspaceSkillFiles(
49
49
  workspaceRoot: string,
50
- type: WorkspaceType
50
+ harness: HarnessType
51
51
  ): Promise<WorkspaceSkillUpdateResult> {
52
- const locations = await resolveSkillLocations(workspaceRoot, type)
52
+ const locations = await resolveSkillLocations(workspaceRoot, harness)
53
53
  const before = await skillStatusesForLocations(locations)
54
54
  let changedSkillPaths: string[]
55
- if (usesSharedWorkspaceSkill(type)) {
56
- changedSkillPaths = await installWorkspaceSkillFiles(workspaceRoot, type)
55
+ if (usesSharedWorkspaceSkill(harness)) {
56
+ changedSkillPaths = await installWorkspaceSkillFiles(workspaceRoot, harness)
57
57
  } else {
58
58
  for (const location of locations) {
59
59
  if (location.brokenLink) {
@@ -82,7 +82,7 @@ async function updateWorkspaceSkillFiles(
82
82
  // Applet declarations ship with the CLI, so refresh installed copies along
83
83
  // with skills.
84
84
  const updatedAppletTypes = await syncAppletDeclarations(workspaceRoot)
85
- const skills = await skillStatuses(workspaceRoot, type)
85
+ const skills = await skillStatuses(workspaceRoot, harness)
86
86
 
87
87
  return {
88
88
  before,
@@ -3,7 +3,7 @@
3
3
  // drives both the CLI status and the frontend's automatic update check.
4
4
  import { join } from 'node:path'
5
5
 
6
- import type { WorkspaceSkillStatus, WorkspaceType } from '@/lib/types'
6
+ import type { WorkspaceSkillStatus, HarnessType } from '@/lib/types'
7
7
 
8
8
  import { findWorkspaceForPath, liftToWorkspaceRoot, listWorkspaces } from '../workspaces/registry'
9
9
  import { bundledSkillDirectory } from './template'
@@ -74,9 +74,9 @@ export const isBehind = (installed: string | null, bundled: string | null): bool
74
74
  // Report every installed copy, plus the required primary harness destination.
75
75
  export async function skillStatuses(
76
76
  workspaceRoot: string,
77
- type?: WorkspaceType
77
+ harness?: HarnessType
78
78
  ): Promise<WorkspaceSkillStatus[]> {
79
- return skillStatusesForLocations(await resolveSkillLocations(workspaceRoot, type))
79
+ return skillStatusesForLocations(await resolveSkillLocations(workspaceRoot, harness))
80
80
  }
81
81
 
82
82
  export async function skillStatusesForLocations(
@@ -92,7 +92,7 @@ export async function skillStatusesForLocations(
92
92
  )
93
93
  }
94
94
 
95
- export type ResolvedWorkspace = { root: string; type?: WorkspaceType }
95
+ export type ResolvedWorkspace = { root: string; harness?: HarnessType }
96
96
 
97
97
  // Resolve a path to its workspace root: the registered workspace that owns it
98
98
  // (carrying its backend type), else lifted out of any `.moi/`, else the path
@@ -100,7 +100,7 @@ export type ResolvedWorkspace = { root: string; type?: WorkspaceType }
100
100
  // the same places.
101
101
  export async function resolveWorkspace(cwd: string): Promise<ResolvedWorkspace> {
102
102
  const ws = findWorkspaceForPath(await listWorkspaces(), cwd)
103
- if (ws) return { root: ws.path, type: ws.type }
103
+ if (ws) return { root: ws.path, harness: ws.harness }
104
104
  return { root: liftToWorkspaceRoot(cwd) }
105
105
  }
106
106
 
@@ -114,8 +114,8 @@ export async function resolveWorkspaceRoot(cwd: string): Promise<string> {
114
114
  // version checks must not break the command they ride on.
115
115
  export async function staleSkillNotice(cwd: string): Promise<string | null> {
116
116
  try {
117
- const { root, type } = await resolveWorkspace(cwd)
118
- const stale = (await skillStatuses(root, type)).filter(s =>
117
+ const { root, harness } = await resolveWorkspace(cwd)
118
+ const stale = (await skillStatuses(root, harness)).filter(s =>
119
119
  isMinorBehind(s.installed, s.bundled)
120
120
  )
121
121
  if (stale.length === 0) return null
@@ -1,7 +1,7 @@
1
1
  import { lstat, mkdir, mkdtemp, readlink, realpath, rename, rm, symlink } from 'node:fs/promises'
2
2
  import { dirname, join, relative, resolve } from 'node:path'
3
3
 
4
- import type { WorkspaceType } from '@/lib/types'
4
+ import type { HarnessType } from '@/lib/types'
5
5
 
6
6
  import { installBundledSkill, installBundledSkills, matchesBundledSkill } from './template'
7
7
  import { skillsDirFor } from '../workspaces/init'
@@ -9,8 +9,8 @@ import { withSkillLock } from './lock'
9
9
 
10
10
  const SKILL_NAME = 'moi-workspace'
11
11
 
12
- export function usesSharedWorkspaceSkill(type?: WorkspaceType): boolean {
13
- return type === undefined || type === 'claude-code' || type === 'codex'
12
+ export function usesSharedWorkspaceSkill(harness?: HarnessType): boolean {
13
+ return harness === undefined || harness === 'claude-code' || harness === 'codex'
14
14
  }
15
15
 
16
16
  async function entryAt(path: string) {
@@ -31,24 +31,26 @@ async function checkSkillsDirectory(path: string): Promise<void> {
31
31
 
32
32
  export async function installWorkspaceSkills(
33
33
  root: string,
34
- type?: WorkspaceType
34
+ harness?: HarnessType
35
35
  ): Promise<string[]> {
36
- return withSkillLock(workspaceSkillLockPath(root, type), () =>
37
- installWorkspaceSkillFiles(root, type)
36
+ return withSkillLock(workspaceSkillLockPath(root, harness), () =>
37
+ installWorkspaceSkillFiles(root, harness)
38
38
  )
39
39
  }
40
40
 
41
- export function workspaceSkillLockPath(root: string, type?: WorkspaceType): string {
42
- return usesSharedWorkspaceSkill(type) ? join(root, '.agents', 'skills') : skillsDirFor(root, type)
41
+ export function workspaceSkillLockPath(root: string, harness?: HarnessType): string {
42
+ return usesSharedWorkspaceSkill(harness)
43
+ ? join(root, '.agents', 'skills')
44
+ : skillsDirFor(root, harness)
43
45
  }
44
46
 
45
47
  // Callers must hold the workspace skill lock across any surrounding status reads.
46
48
  export async function installWorkspaceSkillFiles(
47
49
  root: string,
48
- type?: WorkspaceType
50
+ harness?: HarnessType
49
51
  ): Promise<string[]> {
50
- if (usesSharedWorkspaceSkill(type)) return resetWorkspaceSkill(root)
51
- const directory = skillsDirFor(root, type)
52
+ if (usesSharedWorkspaceSkill(harness)) return resetWorkspaceSkill(root)
53
+ const directory = skillsDirFor(root, harness)
52
54
  return (await installBundledSkills(directory)).map(name => join(directory, name))
53
55
  }
54
56
 
package/server/web.ts CHANGED
@@ -5,6 +5,8 @@ import type { ClientMessage, StatusSnapshotMessage } from '@/lib/types'
5
5
  import { isMoiContext } from '@/lib/moi-context'
6
6
 
7
7
  import { rm } from 'node:fs/promises'
8
+ import { dirname, join } from 'node:path'
9
+ import { startOperations, stopOperations } from './operations/server'
8
10
 
9
11
  import index from '../client/index.html'
10
12
  import devSandbox from '../client/dev/index.html'
@@ -23,9 +25,9 @@ import { navigationRelay } from './navigation-relay'
23
25
  import { resolveScratchOp } from './scratchpad/relay'
24
26
  import { allHarnesses, harnessFor } from './harness/registry'
25
27
  import { getWorkspace, listWorkspaces } from './workspaces/registry'
26
- import { failInterruptedViewStarts, sendWorkspaceMessage } from './sessions/view-sessions'
28
+ import { failInterruptedViewStarts } from './sessions/view-sessions'
29
+ import { sendWorkspaceMessage } from './sessions/send-message'
27
30
  import { prepareWorkspaceStates } from './workspace-state'
28
- import { migrateLegacyWorkspaceState } from './workspace-state/legacy-migration'
29
31
  import {
30
32
  addClient,
31
33
  broadcast,
@@ -55,7 +57,6 @@ function isClientMessage(value: unknown): value is ClientMessage {
55
57
  sessionId?: unknown
56
58
  content?: unknown
57
59
  isNew?: unknown
58
- selectedSessionScope?: unknown
59
60
  optimisticId?: unknown
60
61
  model?: unknown
61
62
  effort?: unknown
@@ -71,9 +72,6 @@ function isClientMessage(value: unknown): value is ClientMessage {
71
72
  typeof v.content === 'string' &&
72
73
  typeof v.sessionId === 'string' &&
73
74
  typeof v.isNew === 'boolean' &&
74
- (v.selectedSessionScope === undefined ||
75
- v.selectedSessionScope === 'shared' ||
76
- v.selectedSessionScope === 'browser-tab') &&
77
75
  (v.optimisticId === undefined || typeof v.optimisticId === 'string') &&
78
76
  (v.model === undefined || typeof v.model === 'string') &&
79
77
  (v.effort === undefined || typeof v.effort === 'string') &&
@@ -111,7 +109,6 @@ function upgrade(server: Upgradable, req: Request, data: WsData) {
111
109
  // WebSocket channels (which need Bun's native `server.upgrade` + pub/sub). Every
112
110
  // HTTP API route is delegated to the Hono app (`./api`) via `fetch`.
113
111
  const registeredWorkspaces = await listWorkspaces()
114
- await migrateLegacyWorkspaceState(registeredWorkspaces)
115
112
  await prepareWorkspaceStates(registeredWorkspaces)
116
113
  await Promise.all(registeredWorkspaces.map(failInterruptedViewStarts))
117
114
 
@@ -125,6 +122,10 @@ const listen = unixSocket
125
122
  ? { unix: unixSocket }
126
123
  : { port: PORT, hostname: process.env.HOST ?? '127.0.0.1' }
127
124
 
125
+ const operations = unixSocket
126
+ ? await startOperations(join(dirname(unixSocket), 'ops.sock'))
127
+ : undefined
128
+
128
129
  export const app = Bun.serve<WsData>({
129
130
  // Bun types the port and Unix-socket listeners as separate overloads, so a
130
131
  // listener picked at runtime is cast to one of them; the runtime takes either.
@@ -153,6 +154,8 @@ export const app = Bun.serve<WsData>({
153
154
 
154
155
  // Client-side routes — serve the SPA shell.
155
156
  '/': shell,
157
+ // Demo serves home at /demo (see homePath in client/api/app-config.ts).
158
+ ...(getAppConfig().demo ? { '/demo': shell } : {}),
156
159
  '/dev': shell,
157
160
  '/dev/*': shell,
158
161
  // Isolated sandboxes bypass app startup and share the client/dev entry point.
@@ -174,7 +177,7 @@ export const app = Bun.serve<WsData>({
174
177
  '/api/workspaces/ws': (req: Request, server: Bun.Server<WsData>) =>
175
178
  upgrade(server, req, { channel: 'events', workspaceId: '' }),
176
179
 
177
- '/api/workspaces/:id/collab/ws': async (req: Request, server: Bun.Server<WsData>) => {
180
+ '/api/workspaces/:id/collab': async (req: Request, server: Bun.Server<WsData>) => {
178
181
  const workspaceId = decodeURIComponent(new URL(req.url).pathname.split('/')[3] ?? '')
179
182
  const workspace = await getWorkspace(workspaceId)
180
183
  if (!workspace) return new Response('Workspace not found', { status: 404 })
@@ -246,7 +249,6 @@ export const app = Bun.serve<WsData>({
246
249
  workspacePath: workspace.path,
247
250
  sessionId: data.sessionId,
248
251
  isNew: data.isNew,
249
- selectedSessionScope: data.selectedSessionScope,
250
252
  content: data.content.trim(),
251
253
  attachments: data.attachments,
252
254
  optimisticId: data.optimisticId,
@@ -321,6 +323,8 @@ async function shutdown() {
321
323
  shuttingDown = true
322
324
  try {
323
325
  app.stop(true)
326
+ operations?.stop(true)
327
+ stopOperations()
324
328
  } catch {}
325
329
  try {
326
330
  control.stop(true)
@@ -4,6 +4,7 @@ import { dirname } from 'node:path'
4
4
 
5
5
  import type { PendingView, SessionFork, WorkspaceSessionState } from '@/lib/types'
6
6
  import { isWorkspaceTabId } from '@/lib/workspace-tabs'
7
+ import { normalizeOpenTabs } from '@/lib/workspace-layout'
7
8
  import { LockTimeoutError, type Lease } from './lock'
8
9
  import { WORKSPACE_STATE_VERSION, type StoredWorkspaceState } from './types'
9
10
 
@@ -95,8 +96,11 @@ export function normalizeWorkspaceState(
95
96
  workspacePath: string
96
97
  ): StoredWorkspaceState {
97
98
  const state = emptyWorkspaceState(optionalString(value.workspacePath) ?? workspacePath)
99
+ if (Array.isArray(value.openTabs)) state.openTabs = normalizeOpenTabs(value.openTabs)
98
100
  if (typeof value.revision === 'number' && Number.isSafeInteger(value.revision))
99
101
  state.revision = value.revision
102
+ if (isRecord(value.chatDefaults))
103
+ state.chatDefaults = normalizeSession({ config: value.chatDefaults }).config ?? {}
100
104
  const pinned = optionalString(value.pinnedSessionId)
101
105
  if (pinned) state.pinnedSessionId = pinned
102
106
  if (isRecord(value.selected)) {
@@ -104,10 +104,6 @@ export async function updateWorkspaceState<T>(
104
104
  })
105
105
  }
106
106
 
107
- export function hasWorkspaceState(workspaceId: string): boolean {
108
- return existsSync(statePath(workspaceId))
109
- }
110
-
111
107
  async function listStateIds(): Promise<string[]> {
112
108
  try {
113
109
  const entries = await readdir(root, { withFileTypes: true })
@@ -0,0 +1,24 @@
1
+ import type { RemoteWorkspaceTarget } from '@/lib/workspace-config'
2
+ import { remoteRequest } from '../remote/client'
3
+
4
+ export type WorkspaceApiTarget = { remote: RemoteWorkspaceTarget }
5
+
6
+ // CLI requests for a linked folder's shared content go to the owner's workspace API.
7
+ // Local workspaces never come through here; their handlers read the folder directly.
8
+ // `path` comes from `cloudRoutes` (server/remote/routes.ts).
9
+ export async function requestWorkspace(path: string, init?: RequestInit): Promise<Response> {
10
+ // Serialize multipart bodies once so the signature and content type match the bytes sent.
11
+ const payload = new Request('http://workspace.local', {
12
+ method: init?.method ?? 'POST',
13
+ body: init?.body,
14
+ headers: init?.headers
15
+ })
16
+ // Bun materializes multipart headers lazily; read the boundary before consuming the body.
17
+ const contentType = payload.headers.get('content-type') ?? undefined
18
+ return remoteRequest(path, {
19
+ method: init?.method,
20
+ body: init?.body == null ? undefined : new Uint8Array(await payload.arrayBuffer()),
21
+ signal: init?.signal ?? undefined,
22
+ contentType
23
+ })
24
+ }
@@ -1,5 +1,4 @@
1
- import { loadLayout, saveLayout } from './layout'
2
- import type { WorkspaceEntry, WorkspaceType } from '@/lib/types'
1
+ import type { WorkspaceEntry, HarnessType } from '@/lib/types'
3
2
  import { harnessFor } from '../harness/registry'
4
3
  import { harnessStore } from '../harness/auth'
5
4
  import { getWorkspaceSkillsStatus } from '../skills/update'
@@ -12,13 +11,13 @@ import { installWorkspaceSkills } from '../skills/workspace'
12
11
  // Keep successful preparation for this server lifetime; failed attempts can retry.
13
12
  const preparation = new Map<string, Promise<void>>()
14
13
  export function prepareWorkspaceHarness(ws: WorkspaceEntry): Promise<void> {
15
- const key = `${ws.path}:${ws.type ?? 'claude-code'}`
14
+ const key = `${ws.path}:${ws.harness ?? 'claude-code'}`
16
15
  let pending = preparation.get(key)
17
16
  if (!pending) {
18
- pending = getWorkspaceSkillsStatus(ws.path, ws.type)
17
+ pending = getWorkspaceSkillsStatus(ws.path, ws.harness)
19
18
  .then(async status => {
20
19
  if (status.skills.some(skill => !skill.installed))
21
- await installWorkspaceSkills(ws.path, ws.type)
20
+ await installWorkspaceSkills(ws.path, ws.harness)
22
21
  })
23
22
  .catch(error => {
24
23
  preparation.delete(key)
@@ -29,23 +28,23 @@ export function prepareWorkspaceHarness(ws: WorkspaceEntry): Promise<void> {
29
28
  return pending
30
29
  }
31
30
 
32
- export async function changeWorkspaceHarness(ws: WorkspaceEntry, type: WorkspaceType) {
31
+ export async function changeWorkspaceHarness(ws: WorkspaceEntry, next: HarnessType) {
33
32
  return withHarnessTransition(ws, async () => {
34
33
  const current = await getWorkspace(ws.id)
35
34
  if (!current) throw new HarnessTransitionError('Workspace not found')
36
- const previousType = current.type ?? 'claude-code'
35
+ const previousHarness = current.harness ?? 'claude-code'
37
36
  const harness = harnessFor(current)
38
37
  if (
39
- !['claude-code', 'codex'].includes(previousType) ||
40
- !['claude-code', 'codex'].includes(type)
38
+ !['claude-code', 'codex'].includes(previousHarness) ||
39
+ !['claude-code', 'codex'].includes(next)
41
40
  )
42
41
  throw new HarnessTransitionError('This workspace’s agent cannot be changed')
43
- if (type === previousType) return current
42
+ if (next === previousHarness) return current
44
43
  if (harness.activeSessions().some(session => session.workspaceId === ws.id))
45
44
  throw new HarnessTransitionError('Wait for the agent to finish before changing it')
46
- const layoutBefore = await loadLayout(current.path)
47
45
  const before = await updateWorkspaceState(current, state => {
48
46
  const before = structuredClone(state)
47
+ state.chatDefaults = {}
49
48
  state.selected = {}
50
49
  delete state.pinnedSessionId
51
50
  for (const view of Object.values(state.pendingViews)) {
@@ -57,21 +56,11 @@ export async function changeWorkspaceHarness(ws: WorkspaceEntry, type: Workspace
57
56
  })
58
57
  let updated: WorkspaceEntry
59
58
  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)
59
+ updated = await updateWorkspaceHarness(ws.id, next)
66
60
  } 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
- }
61
+ await updateWorkspaceState(current, state => Object.assign(state, before)).catch(error => {
62
+ console.error('Could not restore workspace state', error)
63
+ })
75
64
  throw error
76
65
  }
77
66
  // Capture and dispose the old runtime before allowing another transition.
@@ -82,7 +71,7 @@ export async function changeWorkspaceHarness(ws: WorkspaceEntry, type: Workspace
82
71
  console.error('Could not stop previous workspace runtime', error)
83
72
  }
84
73
  harnessStore.invalidate(current)
85
- publishEvent({ type: 'workspace-harness:switched', workspaceId: ws.id, harness: type })
74
+ publishEvent({ type: 'workspace-harness:switched', workspaceId: ws.id, harness: next })
86
75
  return updated
87
76
  })
88
77
  }
@@ -1,6 +1,6 @@
1
1
  import { resolve } from 'node:path'
2
2
 
3
- import type { WorkspaceType } from '@/lib/types'
3
+ import type { HarnessType } from '@/lib/types'
4
4
 
5
5
  import { discoverHermesProfiles } from '../harness/hermes/discovery'
6
6
  import type { HermesProfile } from '../harness/hermes/discovery'
@@ -49,12 +49,12 @@ async function resolveHermesImportMetadata(
49
49
 
50
50
  export async function resolveWorkspaceImportMetadata(
51
51
  path: string,
52
- type: WorkspaceType,
52
+ harness: HarnessType,
53
53
  discoverAgents: DiscoverOpenClawAgents = discoverOpenClawAgents,
54
54
  discoverProfiles: DiscoverHermesProfiles = discoverHermesProfiles
55
55
  ): Promise<WorkspaceImportMetadata> {
56
- if (type === 'hermes') return resolveHermesImportMetadata(path, discoverProfiles)
57
- if (type !== 'openclaw') return {}
56
+ if (harness === 'hermes') return resolveHermesImportMetadata(path, discoverProfiles)
57
+ if (harness !== 'openclaw') return {}
58
58
 
59
59
  const normalizedPath = resolve(path)
60
60
  const agent = (await discoverAgents())
@@ -1,3 +1,4 @@
1
+ import { loadWorkspaceFileConfig } from './layout'
1
2
  // The one place that knows how to turn a directory into a Moi workspace:
2
3
  // bundled skills + the `.moi/` scaffold, with the skills location keyed on the
3
4
  // agent backend. `moi init`, `moi openclaw init`, and the HTTP API (UI import /
@@ -6,7 +7,7 @@
6
7
  import { mkdir } from 'node:fs/promises'
7
8
  import { join } from 'node:path'
8
9
 
9
- import type { WorkspaceType } from '@/lib/types'
10
+ import type { HarnessType } from '@/lib/types'
10
11
  import { workspaceIdFromName } from '@/lib/workspace-name'
11
12
  import { validateWorkspaceId } from '@/lib/ids'
12
13
  import { getWorkspace } from './registry'
@@ -40,20 +41,18 @@ export async function createWorkspaceDirectory(
40
41
  // (Claude Code: `.claude/skills/`; OpenClaw: `<workspace>/skills/`; Codex:
41
42
  // `.agents/skills/` per the Agent Skills standard). An untyped entry is
42
43
  // Claude Code.
43
- export function skillsDirFor(workspaceRoot: string, type?: WorkspaceType): string {
44
- return harnessFor(type).skillsDir?.(workspaceRoot) ?? join(workspaceRoot, '.claude', 'skills')
44
+ export function skillsDirFor(workspaceRoot: string, harness?: HarnessType): string {
45
+ return harnessFor(harness).skillsDir?.(workspaceRoot) ?? join(workspaceRoot, '.claude', 'skills')
45
46
  }
46
47
 
47
48
  export type ProvisionResult = {
48
49
  // Where the skills were installed (backend-dependent, see skillsDirFor).
49
50
  skillsDir: string
50
- // 'exists' when `.moi/` was already bootstrapped, 'installing' when bun
51
- // install continues in the background, else the install exit code (non-zero
52
- // means deps are missing — not fatal, the agent installs on demand).
53
- scaffold: 'exists' | 'installing' | number
54
- // Unique temporary log for this install attempt; unused when scaffold exists.
55
- installLogPath: string
56
- }
51
+ } & (
52
+ | { scaffold: 'skipped' | 'exists'; installLogPath?: never }
53
+ // Dependency installation is running or finished with this exit code.
54
+ | { scaffold: 'installing' | number; installLogPath: string }
55
+ )
57
56
 
58
57
  // Lay down everything a workspace needs: reset Claude/Codex's shared skill
59
58
  // (or copy skills to other backends' own destinations), and bootstrap `.moi/`.
@@ -61,12 +60,15 @@ export type ProvisionResult = {
61
60
  // Registration in the workspace registry is a separate, caller-owned step.
62
61
  export async function provisionWorkspace(
63
62
  workspaceRoot: string,
64
- type?: WorkspaceType
63
+ harness?: HarnessType
65
64
  ): Promise<ProvisionResult> {
66
- const skillsDir = skillsDirFor(workspaceRoot, type)
65
+ const skillsDir = skillsDirFor(workspaceRoot, harness)
67
66
  await mkdir(workspaceRoot, { recursive: true })
68
- await installWorkspaceSkills(workspaceRoot, type)
67
+ const config = await loadWorkspaceFileConfig(workspaceRoot)
68
+ await installWorkspaceSkills(workspaceRoot, harness)
69
+ if (config.remote) return { skillsDir, scaffold: 'skipped' }
69
70
  const installLogPath = createDependencyInstallLogPath()
70
71
  const scaffold = await scaffoldMoiDir(workspaceRoot, undefined, undefined, installLogPath)
72
+ if (scaffold === 'exists') return { skillsDir, scaffold }
71
73
  return { skillsDir, scaffold, installLogPath }
72
74
  }