moi-computer 0.3.0-next.2 → 0.3.0

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 (125) hide show
  1. package/README.md +1 -1
  2. package/client/AGENTS.md +2 -2
  3. package/client/api/http.ts +1 -1
  4. package/client/api/workspace-keys.ts +1 -0
  5. package/client/app/AppRouter.tsx +14 -5
  6. package/client/app/routes/HomeRoute.tsx +1 -1
  7. package/client/app/routes/WorkspaceRoute.tsx +8 -2
  8. package/client/app/shell/SidebarLayout.tsx +10 -5
  9. package/client/assets/openai.svg +3 -0
  10. package/client/components/shared/BottomPanel.tsx +2 -2
  11. package/client/components/ui/button.tsx +3 -2
  12. package/client/components/ui/input.tsx +1 -1
  13. package/client/features/applets/AppletMount.tsx +44 -0
  14. package/client/features/applets/WidgetShell.tsx +4 -1
  15. package/client/features/applets/applet-cache.ts +8 -0
  16. package/client/features/applets/applet-styles.ts +61 -0
  17. package/client/features/chat/ChatComposer.tsx +2 -2
  18. package/client/features/chat/ChatPanel.tsx +8 -25
  19. package/client/features/chat/ChatPopup.tsx +3 -3
  20. package/client/features/chat/{ThreadSelector.tsx → ChatSelector.tsx} +4 -4
  21. package/client/features/chat/TurnView.tsx +8 -9
  22. package/client/features/chat/api.ts +1 -1
  23. package/client/features/chat/chat-send.ts +57 -0
  24. package/client/features/chat/tool-group/ToolCallGroup.tsx +2 -1
  25. package/client/features/chat/tool-group/format.ts +117 -0
  26. package/client/features/chat/useChat.ts +10 -34
  27. package/client/features/connectors/McpMenu.tsx +4 -21
  28. package/client/features/dev/DevRoutes.tsx +18 -0
  29. package/client/features/dev/HarnessDebugPage.tsx +468 -0
  30. package/client/{components/playground → features/dev}/PlaygroundPage.tsx +1 -1
  31. package/client/features/home/CreateWorkspaceDialog.tsx +64 -158
  32. package/client/features/home/CreateWorkspaceDialogSteps.tsx +234 -0
  33. package/client/features/home/HomeLogo.tsx +344 -0
  34. package/client/features/home/HomePage.tsx +15 -21
  35. package/client/features/home/WorkspacePreview.tsx +12 -5
  36. package/client/features/home/api.ts +11 -3
  37. package/client/features/home/workspace-presentation.tsx +4 -4
  38. package/client/features/settings/GeneralSettings.tsx +3 -3
  39. package/client/features/settings/IconPicker.tsx +4 -3
  40. package/client/features/settings/icon-picker-options.ts +0 -131
  41. package/client/features/views/ViewBuilderTab.tsx +153 -0
  42. package/client/features/views/api.ts +124 -0
  43. package/client/features/views/useViewBuilderActions.ts +72 -0
  44. package/client/features/widgets/WidgetGrid.tsx +36 -20
  45. package/client/features/widgets/Widgets.tsx +140 -90
  46. package/client/features/workspace/WorkspaceLayoutContext.tsx +3 -9
  47. package/client/features/workspace/WorkspaceScreen.tsx +179 -40
  48. package/client/features/workspace/WorkspaceTabs.tsx +4 -4
  49. package/client/index.css +0 -35
  50. package/client/index.html +1 -1
  51. package/client/lib/app-icon-registry.ts +145 -0
  52. package/client/runtime/useWorkspaceEvents.ts +3 -1
  53. package/client/theme.css +1 -1
  54. package/dist/chunk-4vf1t6v1.js +10 -0
  55. package/dist/chunk-4z52b2av.css +1 -0
  56. package/dist/chunk-6c8cwpzc.js +1 -0
  57. package/dist/chunk-b4b276wx.js +15 -0
  58. package/dist/{chunk-c4j722at.js → chunk-cs8vbert.js} +2 -2
  59. package/dist/chunk-fjksw6xf.js +1 -0
  60. package/dist/chunk-kxmvv1ax.js +48 -0
  61. package/dist/{chunk-p68fnz3q.js → chunk-vkvb3hjm.js} +1 -1
  62. package/dist/chunk-y82s1jxm.js +61 -0
  63. package/dist/chunk-zpxrb1ce.js +2 -0
  64. package/dist/index.html +2 -2
  65. package/dist/openai-h13pza4b.svg +3 -0
  66. package/lib/format.ts +2 -2
  67. package/lib/types.ts +38 -2
  68. package/lib/view-builder-meta.ts +35 -0
  69. package/lib/workspace-layout.ts +14 -0
  70. package/package.json +2 -1
  71. package/server/AGENTS.md +3 -3
  72. package/server/api.ts +165 -51
  73. package/server/applets.ts +1 -1
  74. package/server/bundle-queue.ts +19 -0
  75. package/server/bundler/applet-css.ts +50 -0
  76. package/server/{build-applet.ts → bundler/build-applet.ts} +36 -26
  77. package/server/cli.ts +79 -2
  78. package/server/control.ts +106 -8
  79. package/server/env-apply.ts +2 -2
  80. package/server/harness/README.md +228 -0
  81. package/server/harness/claude-code/NOTES.md +578 -0
  82. package/{lib/claude-adapter.ts → server/harness/claude-code/adapter.ts} +67 -5
  83. package/server/harness/claude-code/index.ts +124 -0
  84. package/server/{mcp.ts → harness/claude-code/mcp.ts} +1 -1
  85. package/server/{cc-session.ts → harness/claude-code/session.ts} +42 -14
  86. package/server/harness/claude-code/sessions.ts +42 -0
  87. package/server/harness/codex/NOTES.md +326 -0
  88. package/server/harness/codex/adapter.ts +414 -0
  89. package/server/harness/codex/client.ts +343 -0
  90. package/server/harness/codex/index.ts +68 -0
  91. package/server/harness/codex/probe.ts +186 -0
  92. package/server/harness/codex/session.ts +617 -0
  93. package/server/harness/debug.ts +57 -0
  94. package/server/harness/openclaw/NOTES.md +316 -0
  95. package/server/{openclaw-adapter.ts → harness/openclaw/adapter.ts} +2 -2
  96. package/server/harness/openclaw/index.ts +93 -0
  97. package/server/{openclaw-session.ts → harness/openclaw/session.ts} +44 -9
  98. package/server/{openclaw-strip.ts → harness/openclaw/strip.ts} +3 -1
  99. package/server/harness/registry.ts +36 -0
  100. package/server/harness/types.ts +87 -0
  101. package/server/layout.ts +6 -12
  102. package/server/moi-scaffold.ts +1 -1
  103. package/server/registry.ts +14 -52
  104. package/server/state.ts +5 -38
  105. package/server/status.ts +7 -46
  106. package/server/vendor.ts +1 -1
  107. package/server/view-builders.ts +428 -0
  108. package/server/views.ts +0 -0
  109. package/server/web.ts +18 -40
  110. package/server/workspace-init.ts +6 -6
  111. package/workspace/.claude/skills/moi-workspace/DESIGN.md +1 -0
  112. package/workspace/.claude/skills/moi-workspace/SKILL.md +28 -7
  113. package/client/assets/hermes-nous.png +0 -0
  114. package/client/hooks/useScrollFade.ts +0 -38
  115. package/dist/chunk-23cgr1tz.css +0 -1
  116. package/dist/chunk-3hy3qy6d.js +0 -10
  117. package/dist/chunk-dyfaffyz.js +0 -119
  118. package/dist/chunk-kpe40hm8.js +0 -1
  119. package/dist/chunk-ty6dvda0.js +0 -1
  120. package/dist/hermes-nous-pznd63x9.png +0 -0
  121. /package/client/{components/playground → features/dev}/PixelPainter.tsx +0 -0
  122. /package/client/{components/playground → features/dev}/ToolCallsPage.tsx +0 -0
  123. /package/server/{agent.ts → harness/claude-code/models.ts} +0 -0
  124. /package/server/{openclaw.ts → harness/openclaw/discovery.ts} +0 -0
  125. /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'
@@ -99,8 +89,8 @@ export const app = Bun.serve<WsData>({
99
89
  // Client-side routes — serve the SPA shell.
100
90
  '/': shell,
101
91
  '/connectors': shell,
102
- '/playground': shell,
103
- '/playground/*': shell,
92
+ '/dev': shell,
93
+ '/dev/*': shell,
104
94
  '/workspace/*': shell,
105
95
 
106
96
  // Chat websocket — app-wide (one per client, not per workspace). Each chat
@@ -120,10 +110,10 @@ export const app = Bun.serve<WsData>({
120
110
  open(ws) {
121
111
  if (ws.data.channel === 'chat') {
122
112
  addClient(ws)
123
- // Authoritative snapshot of every running session (CC + OpenClaw) so the
124
- // client can light/clear spinners correctly even for runs whose status
125
- // transitions it missed while disconnected.
126
- 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())
127
117
  sendToClient(ws, { type: 'status_snapshot', running })
128
118
  } else {
129
119
  ws.subscribe(EVENTS_TOPIC)
@@ -139,21 +129,10 @@ export const app = Bun.serve<WsData>({
139
129
  if (data.type === 'chat' && (data.content?.trim() || data.attachments?.length)) {
140
130
  const workspace = await getWorkspace(data.workspaceId)
141
131
  if (!workspace) return
142
- if (workspace.type === 'openclaw' && workspace.agentId) {
143
- sendOpenClawMessage({
144
- workspaceId: data.workspaceId,
145
- workspacePath: workspace.path,
146
- agentId: workspace.agentId,
147
- sessionId: data.sessionId,
148
- isNew: data.isNew,
149
- content: data.content.trim(),
150
- attachments: data.attachments,
151
- optimisticId: data.optimisticId
152
- })
153
- } else {
154
- // `stream` is only wired for the Claude Code path; the OpenClaw
155
- // branch above never receives it (unsupported provider).
156
- 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({
157
136
  workspaceId: data.workspaceId,
158
137
  workspacePath: workspace.path,
159
138
  sessionId: data.sessionId,
@@ -163,17 +142,16 @@ export const app = Bun.serve<WsData>({
163
142
  optimisticId: data.optimisticId,
164
143
  model: data.model,
165
144
  effort: data.effort,
166
- stream: data.stream
145
+ stream: data.stream,
146
+ agentId: workspace.agentId
167
147
  })
168
- }
148
+ .catch(() => {})
169
149
  }
170
150
  if (data.type === 'stop') {
171
151
  const workspace = await getWorkspace(data.workspaceId)
172
- if (workspace?.type === 'openclaw') {
173
- abortOpenClawRun({ workspaceId: data.workspaceId, sessionId: data.sessionId })
174
- } else {
175
- interruptCCSession(data.workspaceId, data.sessionId)
176
- }
152
+ void harnessFor(workspace ?? undefined)
153
+ .interrupt(data.workspaceId, data.sessionId)
154
+ .catch(() => {})
177
155
  }
178
156
  // A tab's reply to a relayed Scratchpad op — settle the pending CLI
179
157
  // request (first reply wins; later/duplicate replies are ignored).
@@ -204,7 +182,7 @@ function shutdown() {
204
182
  try {
205
183
  control.stop(true)
206
184
  } catch {}
207
- killAllCCSessions()
185
+ for (const h of allHarnesses()) h.shutdown?.()
208
186
  killAllWorkers()
209
187
  process.exit(0)
210
188
  }
@@ -10,16 +10,16 @@ import { join } from 'node:path'
10
10
  import type { WorkspaceType } from '@/lib/types'
11
11
  export { validateWorkspaceFolderName } from '@/lib/workspace-name'
12
12
 
13
+ import { harnessFor } from './harness/registry'
13
14
  import { scaffoldMoiDir } from './moi-scaffold'
14
15
  import { installBundledSkills } from './skills-template'
15
16
 
16
- // Where each backend loads skills from. Claude Code reads `.claude/skills/`;
17
- // OpenClaw resolves `<workspace>/skills/` with the highest precedence (it wins
18
- // 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.
19
21
  export function skillsDirFor(workspaceRoot: string, type?: WorkspaceType): string {
20
- return type === 'openclaw'
21
- ? join(workspaceRoot, 'skills')
22
- : join(workspaceRoot, '.claude', 'skills')
22
+ return harnessFor(type).skillsDir?.(workspaceRoot) ?? join(workspaceRoot, '.claude', 'skills')
23
23
  }
24
24
 
25
25
  // Folder that holds workspaces created from the UI (`/workspace/create`) — a
@@ -10,6 +10,7 @@ A widget is **glanceable in under 2 seconds** — and earns **one signature mome
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
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.6.0" />
Binary file
@@ -1,38 +0,0 @@
1
- import { type RefObject, useEffect, useRef, useState } from 'react'
2
-
3
- type ScrollFadeState = {
4
- ref: RefObject<HTMLDivElement | null>
5
- showTopFade: boolean
6
- showBottomFade: boolean
7
- }
8
-
9
- export function useScrollFade(): ScrollFadeState {
10
- const ref = useRef<HTMLDivElement>(null)
11
- const [showTopFade, setShowTopFade] = useState(false)
12
- const [showBottomFade, setShowBottomFade] = useState(false)
13
-
14
- useEffect(() => {
15
- const el = ref.current
16
- if (!el) return
17
-
18
- const updateFades = () => {
19
- const atTop = el.scrollTop <= 1
20
- const atBottom = el.scrollTop + el.clientHeight >= el.scrollHeight - 1
21
- const scrollable = el.scrollHeight > el.clientHeight + 1
22
-
23
- setShowTopFade(scrollable && !atTop)
24
- setShowBottomFade(scrollable && !atBottom)
25
- }
26
-
27
- updateFades()
28
- el.addEventListener('scroll', updateFades, { passive: true })
29
- window.addEventListener('resize', updateFades)
30
-
31
- return () => {
32
- el.removeEventListener('scroll', updateFades)
33
- window.removeEventListener('resize', updateFades)
34
- }
35
- }, [])
36
-
37
- return { ref, showTopFade, showBottomFade }
38
- }