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
@@ -11,7 +11,7 @@
11
11
  import { existsSync } from 'node:fs'
12
12
  import { join, resolve } from 'node:path'
13
13
 
14
- import type { WorkspaceType } from '@/lib/types'
14
+ import type { HarnessType } from '@/lib/types'
15
15
 
16
16
  import { discoverCodexWorkspaces } from './codex/discovery'
17
17
  import { type HermesProfile, discoverHermesProfiles } from './hermes/discovery'
@@ -19,21 +19,16 @@ import { type OpenClawAgent, discoverOpenClawAgents } from './openclaw/discovery
19
19
 
20
20
  // Harness names accepted by `--harness`, in the order they are listed to the
21
21
  // user. Detection order is separate (see detectHarness).
22
- export const HARNESS_TYPES: readonly WorkspaceType[] = [
23
- 'claude-code',
24
- 'codex',
25
- 'hermes',
26
- 'openclaw'
27
- ]
28
-
29
- export const harnessLabel: Record<WorkspaceType, string> = {
22
+ export const HARNESS_TYPES: readonly HarnessType[] = ['claude-code', 'codex', 'hermes', 'openclaw']
23
+
24
+ export const harnessLabel: Record<HarnessType, string> = {
30
25
  'claude-code': 'Claude Code',
31
26
  codex: 'Codex',
32
27
  hermes: 'Hermes',
33
28
  openclaw: 'OpenClaw'
34
29
  }
35
30
 
36
- export function isHarnessName(value: string): value is WorkspaceType {
31
+ export function isHarnessName(value: string): value is HarnessType {
37
32
  return (HARNESS_TYPES as readonly string[]).includes(value)
38
33
  }
39
34
 
@@ -48,7 +43,7 @@ export type DetectedAgent = {
48
43
  }
49
44
 
50
45
  export type HarnessDetection = {
51
- type: WorkspaceType
46
+ harness: HarnessType
52
47
  agent?: DetectedAgent
53
48
  // What gave it away, as a noun phrase for the CLI's "Detected …" line.
54
49
  reason: string
@@ -91,7 +86,7 @@ async function safely<T>(fn: () => Promise<T>, fallback: T): Promise<T> {
91
86
 
92
87
  function detectionForProfile(profile: HermesProfile): HarnessDetection {
93
88
  return {
94
- type: 'hermes',
89
+ harness: 'hermes',
95
90
  agent: {
96
91
  agentId: profile.agentId,
97
92
  ...(profile.name ? { name: profile.name } : {}),
@@ -103,7 +98,7 @@ function detectionForProfile(profile: HermesProfile): HarnessDetection {
103
98
 
104
99
  function detectionForAgent(agent: OpenClawAgent): HarnessDetection {
105
100
  return {
106
- type: 'openclaw',
101
+ harness: 'openclaw',
107
102
  agent: {
108
103
  agentId: agent.agentId,
109
104
  ...(agent.name ? { name: agent.name } : {}),
@@ -128,7 +123,7 @@ export async function detectHarness(
128
123
  if (agent) return detectionForAgent(agent)
129
124
 
130
125
  if ((await safely(src.codexWorkspaces, [])).includes(path)) {
131
- return { type: 'codex', reason: 'Codex session history here' }
126
+ return { harness: 'codex', reason: 'Codex session history here' }
132
127
  }
133
128
 
134
129
  // Session history first, then the config directory: history means the CLI
@@ -136,10 +131,10 @@ export async function detectHarness(
136
131
  // the history scan drops linked git worktrees, so a worktree is recognized
137
132
  // by its `.claude/` directory or not at all.
138
133
  if ((await safely(src.claudeCodeWorkspaces, [])).includes(path)) {
139
- return { type: 'claude-code', reason: 'Claude Code session history here' }
134
+ return { harness: 'claude-code', reason: 'Claude Code session history here' }
140
135
  }
141
136
  if (src.hasClaudeConfigDir(path)) {
142
- return { type: 'claude-code', reason: 'a .claude/ directory here' }
137
+ return { harness: 'claude-code', reason: 'a .claude/ directory here' }
143
138
  }
144
139
 
145
140
  return null
@@ -150,18 +145,18 @@ export async function detectHarness(
150
145
  // would have found. Null for the directory-only harnesses, and for a provider
151
146
  // that cannot confirm the path (gateway down, profile removed).
152
147
  export async function agentBindingFor(
153
- type: WorkspaceType,
148
+ harness: HarnessType,
154
149
  workspacePath: string,
155
150
  sources: Partial<DetectionSources> = {}
156
151
  ): Promise<DetectedAgent | null> {
157
152
  const src = { ...defaultSources, ...sources }
158
153
  const path = resolve(workspacePath)
159
154
 
160
- if (type === 'hermes') {
155
+ if (harness === 'hermes') {
161
156
  const profile = (await safely(src.hermesProfiles, [])).find(p => p.path === path)
162
157
  return profile ? (detectionForProfile(profile).agent ?? null) : null
163
158
  }
164
- if (type === 'openclaw') {
159
+ if (harness === 'openclaw') {
165
160
  const agent = (await safely(src.openclawAgents, [])).find(a => a.path === path)
166
161
  return agent ? (detectionForAgent(agent).agent ?? null) : null
167
162
  }
@@ -3,7 +3,7 @@ import { homedir } from 'node:os'
3
3
  import { delimiter, join, resolve } from 'node:path'
4
4
 
5
5
  import { harnessInstructionMessage } from '@/lib/harness-instructions'
6
- import type { HarnessAvailability, HarnessInstallations, WorkspaceType } from '@/lib/types'
6
+ import type { HarnessAvailability, HarnessInstallations, HarnessType } from '@/lib/types'
7
7
 
8
8
  import { cachedLoginShellPath, loginShellPath, mergeSearchPaths } from './shell-path'
9
9
 
@@ -17,7 +17,7 @@ type ExecutableConfig = {
17
17
  fallbackPaths?: readonly string[]
18
18
  }
19
19
 
20
- const executableConfig: Record<WorkspaceType, ExecutableConfig> = {
20
+ const executableConfig: Record<HarnessType, ExecutableConfig> = {
21
21
  'claude-code': {
22
22
  command: 'claude',
23
23
  fallbackPaths: [
@@ -76,8 +76,8 @@ export function firstExecutable(paths: readonly string[]): string | null {
76
76
 
77
77
  // `path` is a test seam: when given, only that PATH is searched — no
78
78
  // login-shell merge, no bundle fallbacks.
79
- export function findHarnessExecutable(type: WorkspaceType, path?: string): string | null {
80
- const config = executableConfig[type]
79
+ export function findHarnessExecutable(harness: HarnessType, path?: string): string | null {
80
+ const config = executableConfig[harness]
81
81
  // bun run adds our dependency commands to PATH; those are not user installs.
82
82
  const searchPath = (path ?? mergeSearchPaths(cachedLoginShellPath(), process.env.PATH))
83
83
  .split(delimiter)
@@ -89,25 +89,25 @@ export function findHarnessExecutable(type: WorkspaceType, path?: string): strin
89
89
  : (executable ?? firstExecutable(config.fallbackPaths ?? []))
90
90
  }
91
91
 
92
- export function requireHarnessExecutable(type: WorkspaceType, path?: string): string {
93
- const executable = findHarnessExecutable(type, path)
94
- if (!executable) throw new Error(executableConfig[type].unavailableReason)
92
+ export function requireHarnessExecutable(harness: HarnessType, path?: string): string {
93
+ const executable = findHarnessExecutable(harness, path)
94
+ if (!executable) throw new Error(executableConfig[harness].unavailableReason)
95
95
  return executable
96
96
  }
97
97
 
98
98
  export async function pathHarnessAvailability(
99
- type: WorkspaceType,
99
+ harness: HarnessType,
100
100
  path?: string
101
101
  ): Promise<HarnessAvailability> {
102
102
  // Availability is asked per request (and long after startup), but await the
103
103
  // probe anyway so the very first request can't report a false negative.
104
104
  if (path === undefined) await loginShellPath()
105
- return findHarnessExecutable(type, path)
105
+ return findHarnessExecutable(harness, path)
106
106
  ? { status: 'available' }
107
107
  : {
108
108
  status: 'unavailable',
109
109
  code: 'not-installed',
110
- reason: executableConfig[type].unavailableReason
110
+ reason: executableConfig[harness].unavailableReason
111
111
  }
112
112
  }
113
113
 
@@ -578,10 +578,10 @@ server/harness/hermes/
578
578
  ```
579
579
 
580
580
  Touch points outside the folder are small and already enumerated by the Codex
581
- precedent: `lib/types.ts` (`WorkspaceType` union), `lib/workspace-types.ts`
581
+ precedent: `lib/types.ts` (`HarnessType` union), `lib/harness-types.ts`
582
582
  (ordering), `lib/format.ts` (`provider` union), `server/harness/registry.ts`,
583
583
  `server/harness/executable.ts` (PATH lookup), `server/api/index.ts`
584
- (`CREATABLE_TYPES`), and a handful of client files that branch on provider
584
+ (`CREATABLE_HARNESSES`), and a handful of client files that branch on provider
585
585
  (`client/features/chat/messages/tool-group/format/index.ts`,
586
586
  `client/features/workspace/setup/workspace-login-state.tsx`,
587
587
  `client/features/dev/harness-debug-page.tsx`).
@@ -120,7 +120,7 @@ export const hermesHarness: Harness = {
120
120
  const profiles = await discoverHermesProfiles()
121
121
  return profiles
122
122
  .filter(p => !registeredPaths.has(p.path))
123
- .map((p): DiscoveredWorkspaceCandidate => ({ path: p.path, type: 'hermes' }))
123
+ .map((p): DiscoveredWorkspaceCandidate => ({ path: p.path, harness: 'hermes' }))
124
124
  },
125
125
 
126
126
  availability: async (ws): Promise<HarnessAvailability> => {
@@ -1,24 +1,24 @@
1
1
  import { HARNESS_INSTRUCTIONS } from '@/lib/harness-instructions'
2
2
  import { getAppConfig } from '../app-config'
3
- import type { WorkspaceType } from '@/lib/types'
3
+ import type { HarnessType } from '@/lib/types'
4
4
  import { detectInstalledHarnesses } from './executable'
5
5
 
6
- const installations = new Map<WorkspaceType, Promise<void>>()
6
+ const installations = new Map<HarnessType, Promise<void>>()
7
7
 
8
- export function installHarness(type: WorkspaceType): Promise<void> {
8
+ export function installHarness(harness: HarnessType): Promise<void> {
9
9
  const config = getAppConfig()
10
10
  if (config.environment !== 'local' || config.demo || config.agentLauncher) {
11
11
  throw new Error('Agents can only be installed in local Moi')
12
12
  }
13
- if (type !== 'claude-code' && type !== 'codex') {
13
+ if (harness !== 'claude-code' && harness !== 'codex') {
14
14
  throw new Error('This agent requires manual installation')
15
15
  }
16
- const pending = installations.get(type)
16
+ const pending = installations.get(harness)
17
17
  if (pending) return pending
18
18
  const installation = (async () => {
19
- if ((await detectInstalledHarnesses())[type]) return
19
+ if ((await detectInstalledHarnesses())[harness]) return
20
20
  const url =
21
- type === 'claude-code' ? 'https://claude.ai/install' : 'https://chatgpt.com/codex/install'
21
+ harness === 'claude-code' ? 'https://claude.ai/install' : 'https://chatgpt.com/codex/install'
22
22
  const command =
23
23
  process.platform === 'win32'
24
24
  ? [
@@ -30,7 +30,7 @@ export function installHarness(type: WorkspaceType): Promise<void> {
30
30
  '-Command',
31
31
  `$ErrorActionPreference = 'Stop'; irm ${url}.ps1 | iex`
32
32
  ]
33
- : ['bash', '-o', 'pipefail', '-c', HARNESS_INSTRUCTIONS[type].command]
33
+ : ['bash', '-o', 'pipefail', '-c', HARNESS_INSTRUCTIONS[harness].command]
34
34
  const child = Bun.spawn(command, {
35
35
  stdin: 'ignore',
36
36
  stdout: 'inherit',
@@ -40,10 +40,10 @@ export function installHarness(type: WorkspaceType): Promise<void> {
40
40
  if ((await child.exited) !== 0) {
41
41
  throw new Error('Installation failed or timed out. Try again.')
42
42
  }
43
- if (!(await detectInstalledHarnesses())[type]) {
43
+ if (!(await detectInstalledHarnesses())[harness]) {
44
44
  throw new Error('The installer finished, but the agent could not be found. Restart Moi.')
45
45
  }
46
- })().finally(() => installations.delete(type))
47
- installations.set(type, installation)
46
+ })().finally(() => installations.delete(harness))
47
+ installations.set(harness, installation)
48
48
  return installation
49
49
  }
@@ -94,7 +94,7 @@ export const openclawHarness: Harness = {
94
94
  .map(
95
95
  (a): DiscoveredWorkspaceCandidate => ({
96
96
  path: a.path,
97
- type: 'openclaw'
97
+ harness: 'openclaw'
98
98
  })
99
99
  )
100
100
  },
@@ -1,8 +1,8 @@
1
- // WorkspaceType → Harness lookup. This is the single import surface for the
1
+ // HarnessType → Harness lookup. This is the single import surface for the
2
2
  // rest of the server: web.ts/api/index.ts/etc. dispatch through harnessFor()
3
3
  // instead of branching on workspace.type (documented exceptions: cli.ts
4
4
  // provisioning and tests import harness internals directly).
5
- import type { WorkspaceEntry, WorkspaceType } from '@/lib/types'
5
+ import type { WorkspaceEntry, HarnessType } from '@/lib/types'
6
6
 
7
7
  import { claudeCodeHarness } from './claude-code'
8
8
  import { codexHarness } from './codex'
@@ -17,13 +17,14 @@ const harnesses = {
17
17
  openclaw: openclawHarness,
18
18
  codex: codexHarness,
19
19
  hermes: hermesHarness
20
- } satisfies Partial<Record<WorkspaceType, Harness>>
20
+ } satisfies Partial<Record<HarnessType, Harness>>
21
21
 
22
22
  // An untyped registry entry is a Claude Code workspace (pre-typing legacy).
23
- export function harnessFor(ws: Pick<WorkspaceEntry, 'type'> | WorkspaceType | undefined): Harness {
24
- const type = typeof ws === 'string' ? ws : ws?.type
23
+ export function harnessFor(ws: Pick<WorkspaceEntry, 'harness'> | HarnessType | undefined): Harness {
24
+ const harness = typeof ws === 'string' ? ws : ws?.harness
25
25
  return (
26
- (type && type in harnesses && harnesses[type as keyof typeof harnesses]) || claudeCodeHarness
26
+ (harness && harness in harnesses && harnesses[harness as keyof typeof harnesses]) ||
27
+ claudeCodeHarness
27
28
  )
28
29
  }
29
30
 
@@ -16,7 +16,7 @@ import type {
16
16
  SessionSummary,
17
17
  StreamEvent,
18
18
  WorkspaceEntry,
19
- WorkspaceType
19
+ HarnessType
20
20
  } from '@/lib/types'
21
21
 
22
22
  // The superset of what any backend needs to accept a user message; harnesses
@@ -78,10 +78,10 @@ export type WorkspaceActivityPreview = {
78
78
 
79
79
  export type DiscoveredWorkspaceCandidate = {
80
80
  path: string
81
- type: WorkspaceType
81
+ harness: HarnessType
82
82
  }
83
83
 
84
- export type HarnessWorkspace = Pick<WorkspaceEntry, 'id' | 'path' | 'type' | 'agentId'>
84
+ export type HarnessWorkspace = Pick<WorkspaceEntry, 'id' | 'path' | 'harness' | 'agentId'>
85
85
 
86
86
  export type ActionModel = 'fast' | 'normal' | 'smart'
87
87
 
@@ -100,7 +100,7 @@ export type HarnessActionInput<TResult = unknown, TProgress = never> = {
100
100
  )
101
101
 
102
102
  export type Harness = {
103
- id: WorkspaceType
103
+ id: HarnessType
104
104
  capabilities: HarnessCapabilities
105
105
 
106
106
  // Ephemeral read/search action without a workspace or visible chat.
@@ -12,7 +12,7 @@ import { saveLayout } from '../workspaces/layout'
12
12
  import { resolveWorkspaceTheme } from '@/lib/themes'
13
13
  import { publishEvent } from '../events'
14
14
  import { harnessFor } from '../harness/registry'
15
- import { sendWorkspaceMessage } from '../sessions/view-sessions'
15
+ import { sendWorkspaceMessage } from '../sessions/send-message'
16
16
  import { resolveRenamedSession, saveSelectedSession } from '../sessions/selected'
17
17
  import { readWorkspaceState } from '../workspace-state'
18
18
  import { ideasSchema, onboardingIdeaSchema, parseIdeas } from './ideas'
@@ -208,7 +208,7 @@ export function createOnboardingJobs(overrides: Partial<typeof defaults> = {}) {
208
208
  }
209
209
  const ws = await deps.registerWorkspace(path, {
210
210
  id: job.workspaceId ?? basename(path),
211
- type: progress.harness,
211
+ harness: progress.harness,
212
212
  name: idea.name
213
213
  })
214
214
  job.workspaceId = ws.id
@@ -0,0 +1,46 @@
1
+ import { join } from 'node:path'
2
+ import { PACKAGE_ROOT } from '../version'
3
+ import { OperationError } from './files'
4
+
5
+ export const workspaceCommands = [
6
+ 'bundle',
7
+ 'check',
8
+ 'call-server-fn',
9
+ 'theme',
10
+ 'ui-components',
11
+ 'views',
12
+ 'debug'
13
+ ] as const
14
+
15
+ export function commandArguments(command: string, args: string[]): string[] {
16
+ if (
17
+ !(workspaceCommands as readonly string[]).includes(command) ||
18
+ (command === 'debug' && args[0] !== 'logs')
19
+ )
20
+ throw new OperationError('Unsupported workspace command')
21
+ // The target comes from the URL. Do not let command flags switch workspace.
22
+ if (args.some(arg => /^--(?:dir|path)(?:=|$)/.test(arg)))
23
+ throw new OperationError('Workspace is selected by the remote link, not --dir or --path')
24
+ if (['bundle', 'check', 'views'].includes(command)) {
25
+ // These commands use a positional directory, unlike the other commands.
26
+ const index = command === 'views' ? (args[0] === 'set' ? 2 : 1) : 0
27
+ const result = [...args]
28
+ result.splice(index, 0, '.')
29
+ return [command, ...result]
30
+ }
31
+ return [command, ...args]
32
+ }
33
+
34
+ export function spawnWorkspaceCommand(root: string, command: string, args: string[]) {
35
+ return Bun.spawn(
36
+ [process.execPath, join(PACKAGE_ROOT, 'server/cli.ts'), ...commandArguments(command, args)],
37
+ {
38
+ cwd: root,
39
+ stdin: 'ignore',
40
+ stdout: 'pipe',
41
+ stderr: 'pipe',
42
+ detached: true,
43
+ env: { ...process.env, NO_COLOR: '1', FORCE_COLOR: '0', MOI_REMOTE_WORKSPACE: root }
44
+ }
45
+ )
46
+ }
@@ -0,0 +1,148 @@
1
+ import { constants } from 'node:fs'
2
+ import { lstat, mkdir, open, realpath, rename, rm } from 'node:fs/promises'
3
+ import { dirname, isAbsolute, relative, resolve, sep } from 'node:path'
4
+ import { Mutex } from 'async-mutex'
5
+
6
+ export class OperationError extends Error {
7
+ constructor(
8
+ message: string,
9
+ readonly status = 400
10
+ ) {
11
+ super(message)
12
+ }
13
+ }
14
+
15
+ // All file operations share this queue. Keep validation and replacement together
16
+ // so two requests through this listener cannot swap an ancestor during a write.
17
+ const writes = new Mutex()
18
+ function inside(root: string, path: string) {
19
+ const rel = relative(root, path)
20
+ return rel !== '' && rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel)
21
+ }
22
+ export async function workspaceFile(root: string, path: string, create = false): Promise<string> {
23
+ if (
24
+ !path ||
25
+ isAbsolute(path) ||
26
+ path.includes('\\') ||
27
+ path.includes('\0') ||
28
+ path.split('/').some(p => p === '..' || p === '.')
29
+ )
30
+ throw new OperationError('Use a file path relative to the workspace')
31
+ root = await realpath(root)
32
+ const target = resolve(root, path)
33
+ if (!inside(root, target)) throw new OperationError('File is outside the workspace')
34
+ let current = root
35
+ const parts = relative(root, target).split(sep)
36
+ for (const [i, part] of parts.entries()) {
37
+ current = resolve(current, part)
38
+ try {
39
+ const info = await lstat(current)
40
+ // Reject symlinks even if currently pointing inside: no check/use redirect.
41
+ if (info.isSymbolicLink()) throw new OperationError('Symbolic links are not supported')
42
+ if (i < parts.length - 1 && !info.isDirectory())
43
+ throw new OperationError('Parent is not a directory')
44
+ if (i === parts.length - 1 && !info.isFile()) throw new OperationError('Path is not a file')
45
+ } catch (error) {
46
+ if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error
47
+ if (!create) throw new OperationError('File not found', 404)
48
+ if (i < parts.length - 1) await mkdir(current)
49
+ }
50
+ }
51
+ return target
52
+ }
53
+
54
+ export async function writeWorkspaceFile(
55
+ root: string,
56
+ path: string,
57
+ body: ReadableStream<Uint8Array>,
58
+ patch?: (source: string) => string
59
+ ) {
60
+ return writes.runExclusive(async () => {
61
+ const target = await workspaceFile(root, path, !patch)
62
+ const temporary = resolve(dirname(target), `.moi-write-${crypto.randomUUID()}`)
63
+ let mode = 0o664
64
+ try {
65
+ mode = (await lstat(target)).mode & 0o777
66
+ } catch {}
67
+ const file = await open(
68
+ temporary,
69
+ constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW,
70
+ mode
71
+ )
72
+ try {
73
+ if (patch) {
74
+ const source = new TextDecoder('utf-8', { fatal: true }).decode(
75
+ await Bun.file(target).arrayBuffer()
76
+ )
77
+ await file.writeFile(patch(source))
78
+ } else {
79
+ for await (const chunk of body) await file.writeFile(chunk)
80
+ }
81
+ await file.close()
82
+ // Recheck after streaming an upload; an external shell can change paths.
83
+ if ((await workspaceFile(root, path, true)) !== target)
84
+ throw new OperationError('File changed during upload', 409)
85
+ await rename(temporary, target)
86
+ } finally {
87
+ await file.close().catch(() => {})
88
+ await rm(temporary, { force: true })
89
+ }
90
+ return { ok: true, bytes: (await lstat(target)).size }
91
+ })
92
+ }
93
+
94
+ /** Apply an exact unified diff to this file. No fuzzy matching or shell execution. */
95
+ export function applyUnifiedPatch(source: string, patch: string): string {
96
+ const original = source ? source.split('\n') : []
97
+ if (source.endsWith('\n')) original.pop()
98
+ const output: string[] = []
99
+ const lines = patch.split('\n')
100
+ let cursor = 0,
101
+ hunks = 0,
102
+ newline = source.endsWith('\n')
103
+ for (let i = 0; i < lines.length; i++) {
104
+ const header = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(?:.*)$/.exec(lines[i]!)
105
+ if (!header) {
106
+ if (lines[i] === '' || lines[i]?.startsWith('--- ') || lines[i]?.startsWith('+++ ')) continue
107
+ throw new OperationError('Expected a unified diff', 422)
108
+ }
109
+ hunks++
110
+ const oldCount = Number(header[2] ?? 1),
111
+ newCount = Number(header[4] ?? 1)
112
+ const start = Number(header[1]) - (oldCount ? 1 : 0)
113
+ if (start < cursor || start > original.length)
114
+ throw new OperationError('Patch does not match the file', 409)
115
+ output.push(...original.slice(cursor, start))
116
+ cursor = start
117
+ if (Number(header[3]) - (newCount ? 1 : 0) !== output.length)
118
+ throw new OperationError('Invalid patch position', 422)
119
+ let removed = 0,
120
+ added = 0
121
+ while (removed < oldCount || added < newCount) {
122
+ const line = lines[++i]
123
+ if (line === undefined) throw new OperationError('Incomplete patch', 422)
124
+ const prefix = line[0],
125
+ value = line.slice(1)
126
+ if (prefix === ' ' || prefix === '-') {
127
+ if (original[cursor++] !== value)
128
+ throw new OperationError('Patch does not match the file', 409)
129
+ removed++
130
+ }
131
+ if (prefix === ' ' || prefix === '+') {
132
+ output.push(value)
133
+ added++
134
+ newline = true
135
+ }
136
+ if (![' ', '+', '-'].includes(prefix ?? '') || removed > oldCount || added > newCount)
137
+ throw new OperationError('Invalid patch hunk', 422)
138
+ if (lines[i + 1] === '\') {
139
+ if (prefix !== '-') newline = false
140
+ i++
141
+ }
142
+ }
143
+ }
144
+ if (!hunks) throw new OperationError('Patch has no hunks', 422)
145
+ if (cursor < original.length) newline = source.endsWith('\n')
146
+ output.push(...original.slice(cursor))
147
+ return output.join('\n') + (output.length && newline ? '\n' : '')
148
+ }