moi-computer 0.3.0-next.1 → 0.3.0-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 (206) hide show
  1. package/README.md +1 -1
  2. package/bunfig.toml +5 -1
  3. package/client/AGENTS.md +17 -2
  4. package/client/accept-hmr-dependencies.ts +22 -0
  5. package/client/api/http.ts +31 -0
  6. package/client/api/query-options.ts +6 -0
  7. package/client/api/workspace-keys.ts +18 -0
  8. package/client/app/AppRouter.tsx +44 -0
  9. package/client/app/routes/HomeRoute.tsx +13 -0
  10. package/client/app/routes/WorkspaceRoute.tsx +95 -0
  11. package/client/app/shell/SidebarLayout.tsx +196 -0
  12. package/client/assets/openai.svg +3 -0
  13. package/client/assets.d.ts +9 -0
  14. package/client/components/{BottomPanel.tsx → shared/BottomPanel.tsx} +2 -2
  15. package/client/components/shared/PanelHeader.tsx +9 -0
  16. package/client/components/shared/ReorderableList.tsx +199 -0
  17. package/client/components/ui/button.tsx +11 -7
  18. package/client/components/ui/collapsible.tsx +15 -0
  19. package/client/components/ui/dialog.tsx +2 -2
  20. package/client/components/ui/dropdown-menu.tsx +5 -5
  21. package/client/components/ui/hover-card.tsx +1 -1
  22. package/client/components/ui/input.tsx +1 -1
  23. package/client/components/ui/popover.tsx +1 -1
  24. package/client/components/ui/skeleton.tsx +13 -0
  25. package/client/components/ui/tooltip.tsx +1 -1
  26. package/client/externalize-react.ts +7 -1
  27. package/client/features/applets/AppletMount.tsx +44 -0
  28. package/client/{components → features/applets}/WidgetErrorBoundary.tsx +1 -1
  29. package/client/{components → features/applets}/WidgetShell.tsx +5 -2
  30. package/client/{lib → features/applets}/applet-cache.ts +8 -0
  31. package/client/features/applets/applet-styles.ts +61 -0
  32. package/client/{hooks → features/applets}/useApplet.ts +6 -7
  33. package/client/{components/ChatInput.tsx → features/chat/ChatComposer.tsx} +30 -24
  34. package/client/features/chat/ChatPanel.tsx +171 -0
  35. package/client/{components → features/chat}/ChatPopup.tsx +24 -13
  36. package/client/{components/ThreadSelector.tsx → features/chat/ChatSelector.tsx} +15 -13
  37. package/client/{components → features/chat}/MarkdownContent.tsx +1 -1
  38. package/client/{components → features/chat}/ModelPicker.tsx +68 -17
  39. package/client/{components → features/chat}/TurnView.tsx +17 -11
  40. package/client/features/chat/api.ts +78 -0
  41. package/client/features/chat/chat-connection.ts +107 -0
  42. package/client/features/chat/chat-frames.ts +131 -0
  43. package/client/features/chat/chat-send.ts +57 -0
  44. package/client/{lib → features/chat}/preview-turn.ts +1 -1
  45. package/client/{components → features/chat}/tool-group/ReadImagePreview.tsx +1 -1
  46. package/client/{components → features/chat}/tool-group/SubagentCard.tsx +12 -10
  47. package/client/{components → features/chat}/tool-group/TimelineRow.tsx +5 -5
  48. package/client/{components → features/chat}/tool-group/ToolCallGroup.tsx +14 -5
  49. package/client/{components → features/chat}/tool-group/ToolOutput.tsx +12 -18
  50. package/client/{components → features/chat}/tool-group/format.ts +117 -0
  51. package/client/{hooks → features/chat}/useChat.ts +16 -44
  52. package/client/features/connectors/ConnectorsPage.tsx +92 -0
  53. package/client/features/connectors/McpMenu.tsx +145 -0
  54. package/client/features/connectors/api.ts +28 -0
  55. package/client/features/dev/DevRoutes.tsx +18 -0
  56. package/client/features/dev/HarnessDebugPage.tsx +468 -0
  57. package/client/{components/playground → features/dev}/PixelPainter.tsx +10 -21
  58. package/client/{components/playground → features/dev}/PlaygroundPage.tsx +10 -12
  59. package/client/{components/playground → features/dev}/ToolCallsPage.tsx +9 -11
  60. package/client/features/home/CreateWorkspaceDialog.tsx +130 -0
  61. package/client/features/home/CreateWorkspaceDialogSteps.tsx +234 -0
  62. package/client/features/home/HomeLogo.tsx +344 -0
  63. package/client/features/home/HomePage.tsx +214 -0
  64. package/client/{components → features/home}/WorkspacePreview.tsx +4 -4
  65. package/client/features/home/api.ts +156 -0
  66. package/client/features/home/workspace-presentation.tsx +44 -0
  67. package/client/features/scratchpad/Scratchpad.tsx +312 -0
  68. package/client/features/scratchpad/ScratchpadControls.tsx +503 -0
  69. package/client/features/scratchpad/useScratchpadSnapshot.tsx +115 -0
  70. package/client/features/settings/EnvironmentSettings.tsx +149 -0
  71. package/client/features/settings/GeneralSettings.tsx +90 -0
  72. package/client/{components → features}/settings/IconPicker.tsx +76 -224
  73. package/client/features/settings/SettingsLayout.tsx +53 -0
  74. package/client/{components → features}/settings/WorkspaceSettings.tsx +12 -16
  75. package/client/features/settings/api.ts +88 -0
  76. package/client/features/settings/icon-picker-options.ts +30 -0
  77. package/client/{hooks → features/settings}/useEnvVars.ts +4 -4
  78. package/client/features/views/ViewBuilderTab.tsx +153 -0
  79. package/client/features/views/api.ts +124 -0
  80. package/client/features/views/useViewBuilderActions.ts +72 -0
  81. package/client/{components → features/widgets}/HiddenPanel.tsx +3 -3
  82. package/client/{components → features/widgets}/WidgetFrame.tsx +3 -8
  83. package/client/{components → features/widgets}/WidgetGrid.tsx +38 -29
  84. package/client/features/widgets/Widgets.tsx +265 -0
  85. package/client/{lib/grid-pack.ts → features/widgets/grid.ts} +7 -1
  86. package/client/{hooks → features/widgets}/useGridReconcile.ts +1 -1
  87. package/client/{components → features/workspace}/CustomizePanel.tsx +5 -6
  88. package/client/{lib → features/workspace}/WorkspaceLayoutContext.tsx +16 -15
  89. package/client/features/workspace/WorkspaceScreen.tsx +675 -0
  90. package/client/features/workspace/WorkspaceTabs.tsx +205 -0
  91. package/client/features/workspace/api.ts +56 -0
  92. package/client/features/workspace/useFitsSplitLayout.ts +37 -0
  93. package/client/global.d.ts +5 -0
  94. package/client/index.css +6 -45
  95. package/client/index.html +2 -2
  96. package/client/index.tsx +14 -31
  97. package/client/lib/app-icon-registry.ts +145 -0
  98. package/client/main.tsx +2 -2
  99. package/client/runtime/hmr-watchdog.ts +39 -0
  100. package/client/{hooks/useMeiEvents.ts → runtime/useWorkspaceEvents.ts} +12 -7
  101. package/client/store/ui.ts +5 -1
  102. package/client/theme.css +1 -3
  103. package/dist/chunk-11cab5dq.css +1 -0
  104. package/dist/chunk-4vf1t6v1.js +10 -0
  105. package/dist/chunk-6c24yndg.js +61 -0
  106. package/dist/chunk-6c8cwpzc.js +1 -0
  107. package/dist/chunk-b4b276wx.js +15 -0
  108. package/dist/chunk-cs8vbert.js +546 -0
  109. package/dist/chunk-cwqmay73.css +1 -0
  110. package/dist/chunk-kxmvv1ax.js +48 -0
  111. package/dist/chunk-pcnahct1.js +5 -0
  112. package/dist/chunk-rq0ar7vp.js +1 -0
  113. package/dist/chunk-tqd3pkg8.css +1 -0
  114. package/dist/chunk-vkvb3hjm.js +2 -0
  115. package/dist/chunk-zpxrb1ce.js +2 -0
  116. package/dist/index.html +3 -3
  117. package/dist/openai-h13pza4b.svg +3 -0
  118. package/lib/format.ts +2 -2
  119. package/lib/types.ts +56 -9
  120. package/lib/view-builder-meta.ts +35 -0
  121. package/lib/workspace-layout.ts +14 -0
  122. package/lib/workspace-name.ts +14 -0
  123. package/package.json +4 -2
  124. package/server/AGENTS.md +3 -3
  125. package/server/api.ts +279 -60
  126. package/server/applets.ts +1 -1
  127. package/server/bundle-queue.ts +19 -0
  128. package/server/bundler/applet-css.ts +50 -0
  129. package/server/{build-applet.ts → bundler/build-applet.ts} +36 -26
  130. package/server/cli.ts +90 -7
  131. package/server/control.ts +106 -8
  132. package/server/env-apply.ts +2 -2
  133. package/server/harness/README.md +228 -0
  134. package/server/harness/claude-code/NOTES.md +578 -0
  135. package/{lib/claude-adapter.ts → server/harness/claude-code/adapter.ts} +67 -5
  136. package/server/harness/claude-code/index.ts +124 -0
  137. package/server/{mcp.ts → harness/claude-code/mcp.ts} +73 -16
  138. package/server/{cc-session.ts → harness/claude-code/session.ts} +42 -14
  139. package/server/harness/claude-code/sessions.ts +42 -0
  140. package/server/harness/codex/NOTES.md +239 -0
  141. package/server/harness/codex/adapter.ts +414 -0
  142. package/server/harness/codex/client.ts +343 -0
  143. package/server/harness/codex/index.ts +68 -0
  144. package/server/harness/codex/probe.ts +186 -0
  145. package/server/harness/codex/session.ts +617 -0
  146. package/server/harness/debug.ts +57 -0
  147. package/server/harness/openclaw/NOTES.md +316 -0
  148. package/server/{openclaw-adapter.ts → harness/openclaw/adapter.ts} +2 -2
  149. package/server/harness/openclaw/index.ts +93 -0
  150. package/server/{openclaw-session.ts → harness/openclaw/session.ts} +44 -9
  151. package/server/{openclaw-strip.ts → harness/openclaw/strip.ts} +3 -1
  152. package/server/harness/registry.ts +36 -0
  153. package/server/harness/types.ts +87 -0
  154. package/server/layout.ts +36 -11
  155. package/server/moi-scaffold.ts +56 -11
  156. package/server/registry.ts +30 -52
  157. package/server/state.ts +5 -38
  158. package/server/status.ts +7 -46
  159. package/server/vendor.ts +1 -1
  160. package/server/view-builders.ts +428 -0
  161. package/server/views.ts +0 -0
  162. package/server/web.ts +19 -40
  163. package/server/workspace-init.ts +11 -25
  164. package/tsconfig.json +1 -1
  165. package/workspace/.claude/skills/moi-workspace/DESIGN.md +2 -1
  166. package/workspace/.claude/skills/moi-workspace/SKILL.md +28 -7
  167. package/workspace/.claude/skills/moi-workspace/VIEW-DESIGN.md +1 -1
  168. package/client/api/workspaces.ts +0 -427
  169. package/client/assets/hermes-nous.png +0 -0
  170. package/client/components/App.tsx +0 -41
  171. package/client/components/ChatPanel.tsx +0 -275
  172. package/client/components/HomePage.tsx +0 -17
  173. package/client/components/McpMenu.tsx +0 -125
  174. package/client/components/Scratchpad.tsx +0 -935
  175. package/client/components/Widgets.tsx +0 -132
  176. package/client/components/WorkspacesPage.tsx +0 -245
  177. package/client/components/layout/SidebarLayout.tsx +0 -258
  178. package/client/components/routes/workspace/[id].tsx +0 -675
  179. package/client/components/routes/workspace/create.tsx +0 -155
  180. package/client/components/settings/SettingsPages.tsx +0 -255
  181. package/client/hooks/useFitsSidebar.ts +0 -34
  182. package/client/hooks/useScrollFade.ts +0 -38
  183. package/client/lib/connection.ts +0 -238
  184. package/dist/chunk-07qf2tv1.css +0 -1
  185. package/dist/chunk-w18801vn.js +0 -672
  186. package/dist/hermes-nous-pznd63x9.png +0 -0
  187. /package/client/components/{playground → shared}/LedLogo.tsx +0 -0
  188. /package/client/{components → features/chat}/ShimmerText.tsx +0 -0
  189. /package/client/{store/live.ts → features/chat/chat-store.ts} +0 -0
  190. /package/client/{lib → features/chat}/group-turns.ts +0 -0
  191. /package/client/{components → features/chat}/tool-group/CodeBlock.tsx +0 -0
  192. /package/client/{components → features/chat}/tool-group/Collapse.tsx +0 -0
  193. /package/client/{components → features/chat}/tool-group/detect.ts +0 -0
  194. /package/client/{components → features/chat}/tool-group/fixtures.ts +0 -0
  195. /package/client/{components → features/chat}/tool-group/index.ts +0 -0
  196. /package/client/{lib → features/chat}/uploads.ts +0 -0
  197. /package/client/{hooks → features/chat}/useStickToBottom.ts +0 -0
  198. /package/client/{components → features/connectors}/IconMcp.tsx +0 -0
  199. /package/client/{lib → features/connectors}/mcp-icons.ts +0 -0
  200. /package/client/{lib → features/scratchpad}/scratch-executor.ts +0 -0
  201. /package/client/{lib → features/settings}/render-icon.ts +0 -0
  202. /package/client/{lib → features/workspace}/WorkspaceContext.tsx +0 -0
  203. /package/client/{hooks → features/workspace}/useWorkspaceTheme.ts +0 -0
  204. /package/server/{agent.ts → harness/claude-code/models.ts} +0 -0
  205. /package/server/{openclaw.ts → harness/openclaw/discovery.ts} +0 -0
  206. /package/server/{openclaw-gateway.ts → harness/openclaw/gateway.ts} +0 -0
@@ -0,0 +1,428 @@
1
+ import { mkdir, rename } from 'node:fs/promises'
2
+ import { join } from 'node:path'
3
+
4
+ import type { AppletKind, ViewBuilder, ViewInfo } from '@/lib/types'
5
+
6
+ import { DATA_DIR } from './data-dir'
7
+ import { publishEvent } from './events'
8
+
9
+ type ViewBuilderStore = Record<string, ViewBuilder[]>
10
+
11
+ // A build running past this is treated as hung/abandoned and reconciled back to
12
+ // `waiting`, even if its session still looks live. Generous so a slow but real
13
+ // build is never cut off mid-flight.
14
+ const STALE_BUILD_MS = 10 * 60_000
15
+
16
+ export class ViewBuilderError extends Error {
17
+ status: 400 | 404 | 409
18
+
19
+ constructor(message: string, status: 400 | 404 | 409) {
20
+ super(message)
21
+ this.name = 'ViewBuilderError'
22
+ this.status = status
23
+ }
24
+ }
25
+
26
+ let storePath = join(DATA_DIR, 'view-builders.json')
27
+ let writeChain: Promise<unknown> = Promise.resolve()
28
+
29
+ export function setViewBuilderStorePath(path: string): void {
30
+ storePath = path
31
+ }
32
+
33
+ async function readStore(): Promise<ViewBuilderStore> {
34
+ try {
35
+ const parsed = JSON.parse(await Bun.file(storePath).text())
36
+ return parsed && typeof parsed === 'object' ? (parsed as ViewBuilderStore) : {}
37
+ } catch {
38
+ return {}
39
+ }
40
+ }
41
+
42
+ async function writeStore(store: ViewBuilderStore): Promise<void> {
43
+ await mkdir(join(storePath, '..'), { recursive: true })
44
+ const tmp = `${storePath}.${process.pid}.tmp`
45
+ await Bun.write(tmp, JSON.stringify(store, null, 2))
46
+ await rename(tmp, storePath)
47
+ }
48
+
49
+ function locked<T>(fn: () => Promise<T>): Promise<T> {
50
+ const run = writeChain.then(fn, fn)
51
+ writeChain = run.catch(() => {})
52
+ return run
53
+ }
54
+
55
+ async function mutateBuilders<T>(
56
+ workspacePath: string,
57
+ mutate: (builders: ViewBuilder[]) => T
58
+ ): Promise<T> {
59
+ return locked(async () => {
60
+ const store = await readStore()
61
+ const previous = store[workspacePath] ?? []
62
+ const builders = [...previous]
63
+ const result = mutate(builders)
64
+ // Builder records are immutable inside mutations, so reference equality is
65
+ // enough to detect a real add, replacement, or deletion.
66
+ const changed =
67
+ builders.length !== previous.length ||
68
+ builders.some((builder, index) => builder !== previous[index])
69
+ if (!changed) return result
70
+ if (builders.length > 0) store[workspacePath] = builders
71
+ else delete store[workspacePath]
72
+ await writeStore(store)
73
+ return result
74
+ })
75
+ }
76
+
77
+ function updated(builder: ViewBuilder, patch: Partial<ViewBuilder>): ViewBuilder {
78
+ return { ...builder, ...patch, updatedAt: Math.max(Date.now(), builder.updatedAt + 1) }
79
+ }
80
+
81
+ function replace(builders: ViewBuilder[], index: number, builder: ViewBuilder): ViewBuilder {
82
+ builders[index] = builder
83
+ return builder
84
+ }
85
+
86
+ function findBuilder(builders: ViewBuilder[], builderId: string): [ViewBuilder, number] {
87
+ const index = builders.findIndex(builder => builder.id === builderId)
88
+ if (index === -1) throw new ViewBuilderError('View builder not found', 404)
89
+ return [builders[index], index]
90
+ }
91
+
92
+ function publishUpdated(workspaceId: string, builder: ViewBuilder): void {
93
+ // Widget builders are record-only for now — no host UI consumes them, so keep
94
+ // them off the client event stream (and out of the view-builder tab list).
95
+ if (builder.kind === 'widget') return
96
+ publishEvent({ type: 'view-builder:updated', workspaceId, builder })
97
+ }
98
+
99
+ export async function listViewBuilders(workspacePath: string): Promise<ViewBuilder[]> {
100
+ return (await readStore())[workspacePath] ?? []
101
+ }
102
+
103
+ export async function createViewBuilder(
104
+ workspaceId: string,
105
+ workspacePath: string
106
+ ): Promise<ViewBuilder> {
107
+ const builder = await mutateBuilders(workspacePath, builders => {
108
+ const now = Date.now()
109
+ const created: ViewBuilder = {
110
+ id: crypto.randomUUID(),
111
+ kind: 'view',
112
+ status: 'draft',
113
+ input: { requirements: '' },
114
+ sessionId: crypto.randomUUID(),
115
+ createdAt: now,
116
+ updatedAt: now
117
+ }
118
+ builders.push(created)
119
+ return created
120
+ })
121
+ publishUpdated(workspaceId, builder)
122
+ return builder
123
+ }
124
+
125
+ export async function updateViewBuilderInput(
126
+ workspaceId: string,
127
+ workspacePath: string,
128
+ builderId: string,
129
+ requirements: string
130
+ ): Promise<ViewBuilder> {
131
+ const builder = await mutateBuilders(workspacePath, builders => {
132
+ const [current, index] = findBuilder(builders, builderId)
133
+ if (current.status !== 'draft') {
134
+ throw new ViewBuilderError('Submitted view builder input cannot be changed', 409)
135
+ }
136
+ return replace(builders, index, updated(current, { input: { requirements } }))
137
+ })
138
+ publishUpdated(workspaceId, builder)
139
+ return builder
140
+ }
141
+
142
+ export async function beginViewBuilder(
143
+ workspaceId: string,
144
+ workspacePath: string,
145
+ builderId: string,
146
+ requirements: string
147
+ ): Promise<ViewBuilder> {
148
+ const text = requirements.trim()
149
+ if (!text) throw new ViewBuilderError('View requirements are required', 400)
150
+ const builder = await mutateBuilders(workspacePath, builders => {
151
+ const [current, index] = findBuilder(builders, builderId)
152
+ if (current.status !== 'draft') {
153
+ throw new ViewBuilderError('View builder has already been submitted', 409)
154
+ }
155
+ const { error: _error, ...withoutError } = current
156
+ return replace(
157
+ builders,
158
+ index,
159
+ updated(withoutError as ViewBuilder, {
160
+ status: 'building',
161
+ buildingSince: Date.now(),
162
+ input: { requirements: text }
163
+ })
164
+ )
165
+ })
166
+ publishUpdated(workspaceId, builder)
167
+ return builder
168
+ }
169
+
170
+ type SetBuilderInput = {
171
+ // Correlation handle for a pending, UI-initiated builder (the value injected
172
+ // into the agent's prompt). Omitted for a standalone/widget build, which is
173
+ // then keyed and upserted by its applet id.
174
+ builderId?: string
175
+ kind?: AppletKind
176
+ // The states the agent reports first-hand. `ready` is never accepted here —
177
+ // it stays server-derived from the compiled applet (bundle + reconcile).
178
+ status?: 'building' | 'waiting'
179
+ title?: string
180
+ icon?: string
181
+ }
182
+
183
+ // Bind an applet id (+ optional title/icon/status) to a builder — the single
184
+ // write behind `moi builder set`. Locates the record by handle when claiming a
185
+ // pending builder, otherwise by applet id (creating one for a standalone build).
186
+ export async function setBuilder(
187
+ workspaceId: string,
188
+ workspacePath: string,
189
+ appletId: string,
190
+ input: SetBuilderInput
191
+ ): Promise<ViewBuilder> {
192
+ if (!/^[a-z0-9][a-z0-9_-]*$/.test(appletId)) {
193
+ throw new ViewBuilderError('Invalid applet id', 400)
194
+ }
195
+ if (input.icon !== undefined && !/^[a-z0-9][a-z0-9-]*$/.test(input.icon)) {
196
+ throw new ViewBuilderError('Invalid view icon id', 400)
197
+ }
198
+ // Views and widgets are separate applet namespaces, so an id is only unique
199
+ // within a kind — a view and a widget may both be called "stats".
200
+ const kind: AppletKind = input.kind ?? 'view'
201
+ const sameApplet = (candidate: ViewBuilder) =>
202
+ candidate.viewId === appletId && (candidate.kind ?? 'view') === kind
203
+ const builder = await mutateBuilders(workspacePath, builders => {
204
+ const index = input.builderId
205
+ ? builders.findIndex(candidate => candidate.id === input.builderId)
206
+ : builders.findIndex(sameApplet)
207
+ if (input.builderId && index === -1) {
208
+ throw new ViewBuilderError('View builder not found', 404)
209
+ }
210
+ const clash = builders.find((candidate, i) => i !== index && sameApplet(candidate))
211
+ if (clash) throw new ViewBuilderError(`View id "${appletId}" is already claimed`, 409)
212
+
213
+ if (index === -1) {
214
+ // Standalone build (e.g. a widget) with no pending record — create one.
215
+ const now = Date.now()
216
+ const status = input.status ?? 'building'
217
+ const created: ViewBuilder = {
218
+ id: crypto.randomUUID(),
219
+ kind,
220
+ status,
221
+ input: { requirements: '' },
222
+ sessionId: crypto.randomUUID(),
223
+ viewId: appletId,
224
+ ...(input.title ? { title: input.title } : {}),
225
+ ...(input.icon ? { icon: input.icon } : {}),
226
+ ...(status === 'building' ? { buildingSince: now } : {}),
227
+ createdAt: now,
228
+ updatedAt: now
229
+ }
230
+ builders.push(created)
231
+ return created
232
+ }
233
+
234
+ const current = builders[index]
235
+ if (input.builderId && current.status === 'draft') {
236
+ throw new ViewBuilderError('View builder has not been submitted', 409)
237
+ }
238
+ if (current.viewId && current.viewId !== appletId) {
239
+ throw new ViewBuilderError(`View builder already claimed "${current.viewId}"`, 409)
240
+ }
241
+ // `ready` is terminal and server-owned: the agent's reported status can
242
+ // never move a built applet back to building/waiting.
243
+ const status = current.status === 'ready' ? 'ready' : (input.status ?? current.status)
244
+ const enteringBuild = status === 'building' && current.status !== 'building'
245
+ const { error: _error, ...withoutError } = current
246
+ return replace(
247
+ builders,
248
+ index,
249
+ updated(withoutError as ViewBuilder, {
250
+ viewId: appletId,
251
+ ...(input.kind ? { kind: input.kind } : {}),
252
+ ...(input.title !== undefined ? { title: input.title } : {}),
253
+ ...(input.icon !== undefined ? { icon: input.icon } : {}),
254
+ status,
255
+ ...(enteringBuild ? { buildingSince: Date.now() } : {})
256
+ })
257
+ )
258
+ })
259
+ publishUpdated(workspaceId, builder)
260
+ return builder
261
+ }
262
+
263
+ export async function markViewBuilderBuildingBySession(
264
+ workspaceId: string,
265
+ workspacePath: string,
266
+ sessionId: string
267
+ ): Promise<ViewBuilder | null> {
268
+ const builder = await mutateBuilders(workspacePath, builders => {
269
+ const index = builders.findIndex(candidate => candidate.sessionId === sessionId)
270
+ if (index === -1 || builders[index].status !== 'waiting') return null
271
+ const { error: _error, ...withoutError } = builders[index]
272
+ return replace(
273
+ builders,
274
+ index,
275
+ updated(withoutError as ViewBuilder, { status: 'building', buildingSince: Date.now() })
276
+ )
277
+ })
278
+ if (builder) publishUpdated(workspaceId, builder)
279
+ return builder
280
+ }
281
+
282
+ export async function markViewBuilderWaitingBySession(
283
+ workspaceId: string,
284
+ workspacePath: string,
285
+ sessionId: string,
286
+ error?: string
287
+ ): Promise<ViewBuilder | null> {
288
+ const builder = await mutateBuilders(workspacePath, builders => {
289
+ const index = builders.findIndex(candidate => candidate.sessionId === sessionId)
290
+ if (index === -1) return null
291
+ const current = builders[index]
292
+ if (current.status === 'waiting' && error && current.error !== error) {
293
+ return replace(builders, index, updated(current, { error }))
294
+ }
295
+ if (current.status !== 'building') return null
296
+ return replace(
297
+ builders,
298
+ index,
299
+ updated(current, { status: 'waiting', ...(error ? { error } : {}) })
300
+ )
301
+ })
302
+ if (builder) publishUpdated(workspaceId, builder)
303
+ return builder
304
+ }
305
+
306
+ export async function markViewBuilderWaiting(
307
+ workspaceId: string,
308
+ workspacePath: string,
309
+ builderId: string,
310
+ error?: string
311
+ ): Promise<ViewBuilder | null> {
312
+ const builder = await mutateBuilders(workspacePath, builders => {
313
+ const [current, index] = findBuilder(builders, builderId)
314
+ if (current.status === 'ready' || (current.status === 'waiting' && current.error === error)) {
315
+ return null
316
+ }
317
+ return replace(
318
+ builders,
319
+ index,
320
+ updated(current, { status: 'waiting', ...(error ? { error } : {}) })
321
+ )
322
+ })
323
+ if (builder) publishUpdated(workspaceId, builder)
324
+ return builder
325
+ }
326
+
327
+ export async function renameViewBuilderSession(
328
+ workspaceId: string,
329
+ workspacePath: string,
330
+ from: string,
331
+ to: string
332
+ ): Promise<ViewBuilder | null> {
333
+ if (from === to) return null
334
+ const builder = await mutateBuilders(workspacePath, builders => {
335
+ const index = builders.findIndex(candidate => candidate.sessionId === from)
336
+ if (index === -1) return null
337
+ return replace(builders, index, updated(builders[index], { sessionId: to }))
338
+ })
339
+ if (builder) publishUpdated(workspaceId, builder)
340
+ return builder
341
+ }
342
+
343
+ export async function markViewBuilderReady(
344
+ workspaceId: string,
345
+ workspacePath: string,
346
+ viewId: string,
347
+ title: string,
348
+ icon?: string
349
+ ): Promise<ViewBuilder | null> {
350
+ const builder = await mutateBuilders(workspacePath, builders => {
351
+ const index = builders.findIndex(candidate => candidate.viewId === viewId)
352
+ if (index === -1 || builders[index].status === 'ready') return null
353
+ const { error: _error, ...withoutError } = builders[index]
354
+ return replace(
355
+ builders,
356
+ index,
357
+ updated(withoutError as ViewBuilder, {
358
+ status: 'ready',
359
+ title,
360
+ ...(icon ? { icon } : {})
361
+ })
362
+ )
363
+ })
364
+ if (builder) publishUpdated(workspaceId, builder)
365
+ return builder
366
+ }
367
+
368
+ export async function reconcileViewBuilders(
369
+ workspaceId: string,
370
+ workspacePath: string,
371
+ views: ViewInfo[],
372
+ activeSessionIds: Set<string>
373
+ ): Promise<ViewBuilder[]> {
374
+ const now = Date.now()
375
+ const changed = await mutateBuilders(workspacePath, builders => {
376
+ const viewsById = new Map(views.map(view => [view.id, view]))
377
+ const updates: ViewBuilder[] = []
378
+ for (let index = 0; index < builders.length; index++) {
379
+ const current = builders[index]
380
+ // Only view builders reconcile against the compiled view list; widget
381
+ // records track their own applet id in a separate namespace.
382
+ const view =
383
+ current.viewId && current.kind !== 'widget' ? viewsById.get(current.viewId) : undefined
384
+ // A build with no live session (server restart, drained turn) — or one that
385
+ // has been building far too long (a hung/abandoned turn that never drained)
386
+ // — is stuck; hand it back so the user can resume or discard it.
387
+ const stuck =
388
+ current.status === 'building' &&
389
+ (!activeSessionIds.has(current.sessionId) ||
390
+ (current.buildingSince !== undefined && now - current.buildingSince > STALE_BUILD_MS))
391
+ if (view && current.status !== 'ready') {
392
+ const { error: _error, ...withoutError } = current
393
+ const next = updated(withoutError as ViewBuilder, {
394
+ status: 'ready',
395
+ title: view.config.title,
396
+ ...(view.config.icon ? { icon: view.config.icon } : {})
397
+ })
398
+ builders[index] = next
399
+ updates.push(next)
400
+ } else if (stuck) {
401
+ const next = updated(current, { status: 'waiting' })
402
+ builders[index] = next
403
+ updates.push(next)
404
+ }
405
+ }
406
+ return updates
407
+ })
408
+ for (const builder of changed) publishUpdated(workspaceId, builder)
409
+ return listViewBuilders(workspacePath)
410
+ }
411
+
412
+ export async function deleteViewBuilder(
413
+ workspaceId: string,
414
+ workspacePath: string,
415
+ builderId: string
416
+ ): Promise<void> {
417
+ await mutateBuilders(workspacePath, builders => {
418
+ const [builder, index] = findBuilder(builders, builderId)
419
+ if (builder.status === 'building') {
420
+ throw new ViewBuilderError('A building view can only be closed', 409)
421
+ }
422
+ if (builder.status === 'ready') {
423
+ throw new ViewBuilderError('Ready view builder history is retained', 409)
424
+ }
425
+ builders.splice(index, 1)
426
+ })
427
+ publishEvent({ type: 'view-builder:deleted', workspaceId, builderId })
428
+ }
package/server/views.ts CHANGED
Binary file
package/server/web.ts CHANGED
@@ -2,22 +2,12 @@ import type { ClientMessage } from '@/lib/types'
2
2
 
3
3
  import index from '../client/index.html'
4
4
  import { api } from './api'
5
- import {
6
- getCCRunningSessions,
7
- interruptCCSession,
8
- killAllCCSessions,
9
- sendCCMessage
10
- } from './cc-session'
11
5
  import { PORT } from './constants'
12
6
  import { control } from './control'
13
7
  import { EVENTS_TOPIC, setEventServer } from './events'
14
8
  import { killAllWorkers } from './functions'
15
9
  import { resolveScratchOp } from './scratchpad-relay'
16
- import {
17
- abortOpenClawRun,
18
- getOpenClawRunningSessions,
19
- sendOpenClawMessage
20
- } from './openclaw-session'
10
+ import { allHarnesses, harnessFor } from './harness/registry'
21
11
  import { getWorkspace } from './registry'
22
12
  import { addClient, removeClient, sendToClient } from './state'
23
13
  import { distShell, prebuilt } from './static'
@@ -98,8 +88,9 @@ export const app = Bun.serve<WsData>({
98
88
 
99
89
  // Client-side routes — serve the SPA shell.
100
90
  '/': shell,
101
- '/playground': shell,
102
- '/playground/*': shell,
91
+ '/connectors': shell,
92
+ '/dev': shell,
93
+ '/dev/*': shell,
103
94
  '/workspace/*': shell,
104
95
 
105
96
  // Chat websocket — app-wide (one per client, not per workspace). Each chat
@@ -119,10 +110,10 @@ export const app = Bun.serve<WsData>({
119
110
  open(ws) {
120
111
  if (ws.data.channel === 'chat') {
121
112
  addClient(ws)
122
- // Authoritative snapshot of every running session (CC + OpenClaw) so the
123
- // client can light/clear spinners correctly even for runs whose status
124
- // transitions it missed while disconnected.
125
- const running = [...getCCRunningSessions(), ...getOpenClawRunningSessions()]
113
+ // Authoritative snapshot of every running session across all harnesses
114
+ // so the client can light/clear spinners correctly even for runs whose
115
+ // status transitions it missed while disconnected.
116
+ const running = allHarnesses().flatMap(h => h.runningSessions())
126
117
  sendToClient(ws, { type: 'status_snapshot', running })
127
118
  } else {
128
119
  ws.subscribe(EVENTS_TOPIC)
@@ -138,21 +129,10 @@ export const app = Bun.serve<WsData>({
138
129
  if (data.type === 'chat' && (data.content?.trim() || data.attachments?.length)) {
139
130
  const workspace = await getWorkspace(data.workspaceId)
140
131
  if (!workspace) return
141
- if (workspace.type === 'openclaw' && workspace.agentId) {
142
- sendOpenClawMessage({
143
- workspaceId: data.workspaceId,
144
- workspacePath: workspace.path,
145
- agentId: workspace.agentId,
146
- sessionId: data.sessionId,
147
- isNew: data.isNew,
148
- content: data.content.trim(),
149
- attachments: data.attachments,
150
- optimisticId: data.optimisticId
151
- })
152
- } else {
153
- // `stream` is only wired for the Claude Code path; the OpenClaw
154
- // branch above never receives it (unsupported provider).
155
- sendCCMessage({
132
+ // Harnesses ignore fields they don't support (see SendMessageInput);
133
+ // failures surface as error frames from inside the harness.
134
+ void harnessFor(workspace)
135
+ .sendMessage({
156
136
  workspaceId: data.workspaceId,
157
137
  workspacePath: workspace.path,
158
138
  sessionId: data.sessionId,
@@ -162,17 +142,16 @@ export const app = Bun.serve<WsData>({
162
142
  optimisticId: data.optimisticId,
163
143
  model: data.model,
164
144
  effort: data.effort,
165
- stream: data.stream
145
+ stream: data.stream,
146
+ agentId: workspace.agentId
166
147
  })
167
- }
148
+ .catch(() => {})
168
149
  }
169
150
  if (data.type === 'stop') {
170
151
  const workspace = await getWorkspace(data.workspaceId)
171
- if (workspace?.type === 'openclaw') {
172
- abortOpenClawRun({ workspaceId: data.workspaceId, sessionId: data.sessionId })
173
- } else {
174
- interruptCCSession(data.workspaceId, data.sessionId)
175
- }
152
+ void harnessFor(workspace ?? undefined)
153
+ .interrupt(data.workspaceId, data.sessionId)
154
+ .catch(() => {})
176
155
  }
177
156
  // A tab's reply to a relayed Scratchpad op — settle the pending CLI
178
157
  // request (first reply wins; later/duplicate replies are ignored).
@@ -203,7 +182,7 @@ function shutdown() {
203
182
  try {
204
183
  control.stop(true)
205
184
  } catch {}
206
- killAllCCSessions()
185
+ for (const h of allHarnesses()) h.shutdown?.()
207
186
  killAllWorkers()
208
187
  process.exit(0)
209
188
  }
@@ -8,17 +8,18 @@ import { homedir } from 'node:os'
8
8
  import { join } from 'node:path'
9
9
 
10
10
  import type { WorkspaceType } from '@/lib/types'
11
+ export { validateWorkspaceFolderName } from '@/lib/workspace-name'
11
12
 
13
+ import { harnessFor } from './harness/registry'
12
14
  import { scaffoldMoiDir } from './moi-scaffold'
13
15
  import { installBundledSkills } from './skills-template'
14
16
 
15
- // Where each backend loads skills from. Claude Code reads `.claude/skills/`;
16
- // OpenClaw resolves `<workspace>/skills/` with the highest precedence (it wins
17
- // over same-named bundled or per-user skills). An untyped entry is Claude Code.
17
+ // Where each backend loads skills from — the harness owns the answer
18
+ // (Claude Code: `.claude/skills/`; OpenClaw: `<workspace>/skills/`; Codex:
19
+ // `.agents/skills/` per the Agent Skills standard). An untyped entry is
20
+ // Claude Code.
18
21
  export function skillsDirFor(workspaceRoot: string, type?: WorkspaceType): string {
19
- return type === 'openclaw'
20
- ? join(workspaceRoot, 'skills')
21
- : join(workspaceRoot, '.claude', 'skills')
22
+ return harnessFor(type).skillsDir?.(workspaceRoot) ?? join(workspaceRoot, '.claude', 'skills')
22
23
  }
23
24
 
24
25
  // Folder that holds workspaces created from the UI (`/workspace/create`) — a
@@ -29,9 +30,10 @@ export const CREATED_WORKSPACES_ROOT = join(homedir(), 'moi')
29
30
  export type ProvisionResult = {
30
31
  // Where the skills were installed (backend-dependent, see skillsDirFor).
31
32
  skillsDir: string
32
- // 'exists' when `.moi/` was already bootstrapped, else the bun install exit
33
- // code (non-zero means deps must be installed manually — not fatal).
34
- scaffold: 'exists' | number
33
+ // 'exists' when `.moi/` was already bootstrapped, 'installing' when bun
34
+ // install continues in the background, else the install exit code (non-zero
35
+ // means deps are missing — not fatal, the agent installs on demand).
36
+ scaffold: 'exists' | 'installing' | number
35
37
  }
36
38
 
37
39
  // Lay down everything a workspace needs: create the folder, copy the bundled
@@ -48,19 +50,3 @@ export async function provisionWorkspace(
48
50
  const scaffold = await scaffoldMoiDir(workspaceRoot)
49
51
  return { skillsDir, scaffold }
50
52
  }
51
-
52
- // Validate a folder name typed in the create-workspace form. Returns a
53
- // user-facing error, or null when the name is usable as a single path segment
54
- // under CREATED_WORKSPACES_ROOT. Leading dots are rejected so a name can never
55
- // be hidden or collide with `.moi` / `.claude`.
56
- export function validateWorkspaceFolderName(name: string): string | null {
57
- if (!name) return 'Folder name is required'
58
- if (name.length > 64) return 'Folder name is too long (max 64 characters)'
59
- if (!/^[A-Za-z0-9][A-Za-z0-9._ -]*$/.test(name)) {
60
- return 'Use letters, numbers, dots, dashes, underscores and spaces, starting with a letter or number'
61
- }
62
- if (name.endsWith('.') || name.endsWith(' ')) {
63
- return 'Folder name cannot end with a dot or space'
64
- }
65
- return null
66
- }
package/tsconfig.json CHANGED
@@ -17,5 +17,5 @@
17
17
  }
18
18
  },
19
19
  "include": ["**/*.ts", "**/*.tsx"],
20
- "exclude": ["node_modules"]
20
+ "exclude": ["node_modules", "server/test/__fixtures__"]
21
21
  }
@@ -9,7 +9,8 @@ A widget is **glanceable in under 2 seconds** — and earns **one signature mome
9
9
  - **Content-only root.** The root is a plain `w-full h-full` rectangle. The host card owns the shell — never put `rounded-*`, an outer `border`, `shadow-*`, or a card-surface background on the root. Use `flex flex-col` + `overflow-hidden`; push footers down with `mt-auto`.
10
10
  - **Three states, always.** Loading → skeleton (never a spinner). Error → one human sentence + a retry. Empty → a short prompt, never blank. (Patterns below.)
11
11
  - **Height is the hard constraint.** `height = rowSpan×160 + (rowSpan−1)×16`, exact. Width flexes with the viewport. Design for height first; clip risk → `overflow-hidden`, long text → `truncate` / `line-clamp`.
12
- - **Tailwind for static styling.** No custom CSS, no `@apply`, no *static* `style={{}}`. Icons only from `@tabler/icons-react` (no raw `<svg>`, no other icon packs). Widgets import only from their own folder.
12
+ - **Tailwind for static styling.** No custom CSS, no `@apply`, no *static* `style={{}}`. Icons only from `@tabler/icons-react` (no raw `<svg>`, no other icon packs). Use the host project icon rule when present (`.agents/rules/icons.md`) instead of duplicating size/stroke guidance. Widgets import only from their own folder.
13
+ - **Font weight.** Use only regular weight (the default, or `font-normal` for an explicit reset) and `font-medium`. Never introduce another font-weight utility; other weights are reserved for owner hand-tuning.
13
14
  - **No auto-playing audio or video.** Media is always user-initiated.
14
15
  - **No page-level horizontal scroll.** A deliberate, bounded internal scroller (e.g. a Kanban board) is fine; the widget itself never makes the page scroll sideways.
15
16
 
@@ -20,7 +20,7 @@ Workspace features/pages:
20
20
  concepts. Read `SCRATCHPAD.md` before building on or modifying it.
21
21
  - "Views" - full-stack embedded apps for bigger work, consume more space, live in their own tab.
22
22
 
23
- User can switch between these, but can access the chat (this conversation and other threads) from
23
+ User can switch between these, but can access the chat (this conversation and other chats) from
24
24
  **any place in the app** (copilot mode), or on a dedicated page.
25
25
 
26
26
  Workspace settings and customisation:
@@ -39,12 +39,14 @@ sees and interacts with "Applets".
39
39
  does not have a clear definition, but assumes this is the root folder in which it stores its state
40
40
  files.
41
41
 
42
- "Threads" — a workspace is driven through agent conversations (this chat is one). Depending on your
43
- harness (Claude Code, openclaw, others differ in the details) there can be **multiple threads**, but
42
+ "Chat" — a workspace is driven through agent conversations (this chat is one). Depending on your
43
+ harness (Claude Code, openclaw, others differ in the details) there can be **multiple chats**, but
44
44
  they all share **one** workspace **and one Project folder** — the same filesystem, the same `.moi`
45
- folder, applets, config, and theme. Anything you build is visible to every thread, and another thread
45
+ folder, applets, config, and theme. Anything you build is visible to every chat, and another chat
46
46
  may have changed the workspace or the Project files since you last looked. Treat `.moi` and the
47
- Project folder as shared state, not yours alone.
47
+ Project folder as shared state, not yours alone. Internally, "chats" are sometimes aliased as
48
+ "threads" — "chat" is product language, while "thread" is reserved for internal SDK, session, and
49
+ persistence concepts.
48
50
 
49
51
  "Applets" are standalone full-stack components that _you_ write and maintain. They extend the
50
52
  Workspace UI.
@@ -261,9 +263,28 @@ command as needed. Views work the same way (`.moi/views/<name>.tsx`, appears as
261
263
 
262
264
  Full-screen apps, one per nav tab — the user switches tabs; there is no routing inside a view.
263
265
 
266
+ ## View builder requests
267
+
268
+ When the user's message includes hidden `<moi>` context marked `View builder request`, this chat is
269
+ linked to a pending view tab. Before reading files, planning, or writing code, infer a short stable
270
+ id, a clear sentence-case title, and a relevant icon from the requirements. Capitalize only the
271
+ first word of the title. Your first action must claim them:
272
+
273
+ ```sh
274
+ moi builder set <view-id> --builder <builder-id> --kind view --title "<title>" --icon <icon-id>
275
+ ```
276
+
277
+ Choose the icon id from the available view icons in the hidden context. The id must use lowercase
278
+ letters, numbers, `_`, or `-`. The first call locks the id; running the same command again may update
279
+ its title and icon. After claiming, write `.moi/views/<view-id>.tsx`, use the same icon id in its
280
+ config, and finish with `moi bundle --only views`. The tab uses the claimed title and icon while you
281
+ work and changes into the built view after a successful bundle. (Bundling marks the view ready; the
282
+ build state is otherwise server-managed, so you never set it to done by hand.)
283
+
264
284
  ```ts
265
285
  export const config = {
266
- title: 'User CRM', // nav-tab label — defaults to the file name
286
+ title: 'Customer overview', // sentence-case nav label — defaults to the file name
287
+ icon: 'user', // icon id from the view-builder request
267
288
  requiredEnv: ['CRM_API_KEY'] // optional env-key hints (advisory; see Environment & secrets)
268
289
  } as const
269
290
  ```
@@ -283,4 +304,4 @@ This skill is installed with moi (via the CLI or the UI) and can fall behind whe
283
304
  - **Then** — if you updated, mention it.
284
305
 
285
306
  <!-- moi skill version marker — read by `moi skill` to detect drift; do not edit by hand -->
286
- <moi-skill version="0.4.0" />
307
+ <moi-skill version="0.5.0" />