moi-computer 0.11.1-next.0 → 0.11.1-next.2
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.
- package/client/AGENTS.md +2 -2
- package/client/components/ui/button.tsx +1 -53
- package/client/components/ui/collapsible.tsx +1 -15
- package/client/components/ui/dialog.tsx +1 -58
- package/client/components/ui/dropdown-menu.tsx +1 -254
- package/client/components/ui/hover-card.tsx +1 -44
- package/client/components/ui/input.tsx +1 -21
- package/client/components/ui/popover.tsx +1 -88
- package/client/components/ui/resizable.tsx +1 -40
- package/client/components/ui/skeleton.tsx +1 -13
- package/client/components/ui/slider.tsx +1 -70
- package/client/components/ui/spinner.tsx +1 -18
- package/client/components/ui/switch.tsx +1 -23
- package/client/components/ui/tabs.tsx +1 -0
- package/client/components/ui/textarea.tsx +1 -18
- package/client/components/ui/tooltip.tsx +1 -51
- package/client/features/chat/ChatPanel.tsx +6 -6
- package/client/features/chat/ChatPopup.tsx +3 -4
- package/client/features/chat/TurnView.tsx +5 -4
- package/client/features/chat/api.ts +5 -14
- package/client/features/chat/chat-frames.ts +9 -7
- package/client/features/chat/chat-send.ts +13 -2
- package/client/features/chat/chat-store.ts +1 -3
- package/client/features/chat/composer/ChatComposer.tsx +5 -1
- package/client/features/chat/composer/ModelPicker.tsx +44 -44
- package/client/features/chat/composer/banners/ErrorBanner.tsx +20 -12
- package/client/features/chat/composer/model-order.ts +15 -0
- package/client/features/chat/composer/useWorkspaceComposerState.tsx +15 -7
- package/client/features/chat/group-turns.ts +12 -0
- package/client/features/chat/interleave-notices.ts +7 -11
- package/client/features/chat/session-view.ts +53 -0
- package/client/features/chat/tool-group/ToolCallGroup.tsx +1 -4
- package/client/features/chat/tool-group/format/codex.ts +4 -1
- package/client/features/chat/useChat.ts +10 -9
- package/client/features/dev/ChatStatesPage.tsx +3 -1
- package/client/features/dev/DevIndexPage.tsx +5 -0
- package/client/features/dev/DevRoutes.tsx +2 -0
- package/client/features/dev/HarnessDebugPage.tsx +1 -1
- package/client/features/dev/UiComponentPreviews.tsx +834 -0
- package/client/features/dev/UiComponentsPage.tsx +60 -0
- package/client/features/home/WorkspacePreview.tsx +1 -1
- package/client/features/home/workspace-setup/DemoDialog.tsx +3 -2
- package/client/features/home/workspace-setup/ImportWorkspaceDialog.tsx +5 -8
- package/client/features/home/workspace-setup/WorkspaceDialogContent.tsx +7 -20
- package/client/features/settings/SettingsLayout.tsx +1 -1
- package/client/features/settings/WorkspaceSettings.tsx +4 -1
- package/client/features/views/ViewManager.tsx +14 -9
- package/client/features/widgets/WidgetFrame.tsx +1 -1
- package/client/features/widgets/Widgets.tsx +1 -3
- package/client/features/workspace/WorkspaceScreen.tsx +5 -1
- package/client/features/workspace/WorkspaceSplitLayout.tsx +6 -1
- package/client/features/workspace/api.ts +2 -4
- package/client/index.css +22 -29
- package/dist/chunk-245wt82v.css +1 -0
- package/dist/{chunk-tny85yt2.js → chunk-4s15axjs.js} +2 -2
- package/dist/{chunk-c9pjqx9m.js → chunk-53a7pxcz.js} +1 -1
- package/dist/{chunk-104m57qw.js → chunk-87thzbtw.js} +2 -2
- package/dist/chunk-a6jad1a6.js +1 -0
- package/dist/chunk-dghwstd2.js +9 -0
- package/dist/chunk-eg120aca.js +1 -0
- package/dist/{chunk-v7wr1df4.js → chunk-j3wvxjr7.js} +1 -1
- package/dist/chunk-j7hh2ab4.js +70 -0
- package/dist/chunk-w482ew2c.js +546 -0
- package/dist/chunk-y8eyahwx.js +1 -0
- package/dist/index.html +1 -1
- package/lib/format.ts +55 -6
- package/lib/themes.ts +6 -6
- package/lib/types.ts +10 -9
- package/package.json +12 -5
- package/registry.json +643 -0
- package/server/agent.ts +1 -1
- package/server/api.ts +26 -30
- package/server/applets.ts +30 -29
- package/server/bundler/applet-css.ts +7 -107
- package/server/bundler/build-applet.ts +5 -1
- package/server/bundler/build-worker.ts +178 -0
- package/server/cli-ui-components.ts +28 -33
- package/server/cli.ts +6 -11
- package/server/data-dir.ts +1 -1
- package/server/harness/README.md +41 -48
- package/server/harness/acp/NOTES.md +426 -0
- package/server/harness/acp/discovery.ts +27 -30
- package/server/harness/acp/model-state.ts +57 -0
- package/server/harness/acp/session.ts +18 -6
- package/server/harness/claude-code/NOTES.md +47 -12
- package/server/harness/claude-code/cli.ts +40 -0
- package/server/harness/claude-code/index.ts +11 -5
- package/server/harness/claude-code/models.ts +72 -19
- package/server/harness/claude-code/session.ts +408 -299
- package/server/harness/codex/NOTES.md +222 -350
- package/server/harness/codex/adapter.ts +94 -45
- package/server/harness/codex/auth.ts +1 -3
- package/server/harness/codex/client.ts +169 -249
- package/server/harness/codex/discovery.ts +9 -17
- package/server/harness/codex/index.ts +2 -1
- package/server/harness/codex/pagination.ts +24 -0
- package/server/harness/codex/permissions.ts +31 -7
- package/server/harness/codex/probe.ts +10 -13
- package/server/harness/codex/session.ts +549 -136
- package/server/harness/codex/transport.ts +184 -0
- package/server/harness/debug.ts +1 -1
- package/server/harness/hermes/NOTES.md +18 -0
- package/server/harness/hermes/discovery.ts +20 -0
- package/server/harness/hermes/index.ts +9 -0
- package/server/harness/hermes/models.ts +28 -8
- package/server/harness/types.ts +4 -2
- package/server/moi-scaffold.ts +1 -1
- package/server/preview.ts +3 -1
- package/server/registry.ts +63 -41
- package/server/tldraw-package.d.ts +4 -0
- package/server/ui-components.ts +101 -434
- package/server/view-builders.ts +2 -1
- package/server/web.ts +12 -5
- package/server/workspace-env.ts +3 -2
- package/tsconfig.json +0 -1
- package/ui-components/accordion.tsx +71 -0
- package/ui-components/alert-dialog.tsx +165 -0
- package/ui-components/alert.tsx +68 -0
- package/ui-components/attachment.tsx +195 -0
- package/ui-components/avatar.tsx +90 -0
- package/ui-components/badge.tsx +49 -0
- package/ui-components/button-group.tsx +78 -0
- package/ui-components/button.tsx +55 -0
- package/ui-components/calendar.tsx +180 -0
- package/ui-components/card.tsx +84 -0
- package/ui-components/carousel.tsx +235 -0
- package/ui-components/chart.tsx +338 -0
- package/ui-components/checkbox.tsx +28 -0
- package/ui-components/collapsible.tsx +15 -0
- package/ui-components/combobox.tsx +267 -0
- package/ui-components/context-menu.tsx +244 -0
- package/ui-components/dialog.tsx +138 -0
- package/ui-components/docs/accordion.md +463 -0
- package/ui-components/docs/alert-dialog.md +481 -0
- package/ui-components/docs/alert.md +301 -0
- package/ui-components/docs/attachment.md +689 -0
- package/ui-components/docs/avatar.md +495 -0
- package/ui-components/docs/badge.md +258 -0
- package/ui-components/docs/button-group.md +879 -0
- package/ui-components/docs/button.md +26 -0
- package/ui-components/docs/calendar.md +862 -0
- package/ui-components/docs/card.md +265 -0
- package/ui-components/docs/carousel.md +627 -0
- package/ui-components/docs/chart.md +1256 -0
- package/ui-components/docs/checkbox.md +477 -0
- package/ui-components/docs/collapsible.md +446 -0
- package/ui-components/docs/combobox.md +1003 -0
- package/ui-components/docs/context-menu.md +860 -0
- package/ui-components/docs/data-table.md +1580 -0
- package/ui-components/docs/date-picker.md +614 -0
- package/ui-components/docs/dialog.md +414 -0
- package/ui-components/docs/drawer.md +51 -0
- package/ui-components/docs/dropdown-menu.md +1000 -0
- package/ui-components/docs/field.md +1192 -0
- package/ui-components/docs/hover-card.md +275 -0
- package/ui-components/docs/input-group.md +866 -0
- package/ui-components/docs/input.md +456 -0
- package/ui-components/docs/label.md +295 -0
- package/ui-components/docs/pagination.md +416 -0
- package/ui-components/docs/popover.md +348 -0
- package/ui-components/docs/progress.md +214 -0
- package/ui-components/docs/radio-group.md +389 -0
- package/ui-components/docs/resizable.md +265 -0
- package/ui-components/docs/select.md +616 -0
- package/ui-components/docs/separator.md +216 -0
- package/ui-components/docs/skeleton.md +205 -0
- package/ui-components/docs/slider.md +226 -0
- package/ui-components/docs/spinner.md +332 -0
- package/ui-components/docs/switch.md +236 -0
- package/ui-components/docs/table.md +551 -0
- package/ui-components/docs/tabs.md +379 -0
- package/ui-components/docs/textarea.md +187 -0
- package/ui-components/docs/toggle-group.md +370 -0
- package/ui-components/docs/toggle.md +91 -0
- package/ui-components/docs/tooltip.md +290 -0
- package/ui-components/drawer.tsx +213 -0
- package/ui-components/dropdown-menu.tsx +263 -0
- package/ui-components/field.tsx +224 -0
- package/ui-components/hover-card.tsx +46 -0
- package/ui-components/input-group.tsx +146 -0
- package/ui-components/input.tsx +20 -0
- package/ui-components/label.tsx +17 -0
- package/ui-components/pagination.tsx +124 -0
- package/ui-components/popover.tsx +81 -0
- package/ui-components/progress.tsx +63 -0
- package/ui-components/radio-group.tsx +38 -0
- package/ui-components/resizable.tsx +40 -0
- package/ui-components/scoped-portal.tsx +31 -0
- package/ui-components/select.tsx +195 -0
- package/ui-components/separator.tsx +18 -0
- package/ui-components/skeleton.tsx +15 -0
- package/ui-components/slider.tsx +75 -0
- package/ui-components/spinner.tsx +20 -0
- package/ui-components/switch.tsx +27 -0
- package/ui-components/table.tsx +86 -0
- package/ui-components/tabs.tsx +75 -0
- package/ui-components/textarea.tsx +17 -0
- package/ui-components/toggle-group.tsx +85 -0
- package/ui-components/toggle.tsx +42 -0
- package/ui-components/tooltip.tsx +61 -0
- package/ui-components/utils.ts +8 -0
- package/workspace/.claude/skills/moi-workspace/SKILL.md +11 -20
- package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +4 -3
- package/workspace/.claude/skills/moi-workspace/references/UI-COMPONENTS.md +67 -203
- package/dist/chunk-59zf0m6n.js +0 -1
- package/dist/chunk-bj3akjs2.js +0 -1
- package/dist/chunk-j2w2vak4.js +0 -546
- package/dist/chunk-k2r9c95m.js +0 -10
- package/dist/chunk-kmbxhgwv.js +0 -1
- package/dist/chunk-p1yqa71k.js +0 -83
- package/dist/chunk-r5xrenjy.css +0 -1
package/server/api.ts
CHANGED
|
@@ -149,7 +149,9 @@ async function handleFunctionCall(
|
|
|
149
149
|
// the context. Mounted on the single-workspace sub-app so every nested route
|
|
150
150
|
// shares the lookup instead of repeating `getWorkspace(...) ?? 404`.
|
|
151
151
|
const withWorkspace = createMiddleware<ApiEnv>(async (c, next) => {
|
|
152
|
-
const
|
|
152
|
+
const id = c.req.param('id')
|
|
153
|
+
if (!id) return c.text('Workspace not found', 404)
|
|
154
|
+
const ws = await getWorkspace(id)
|
|
153
155
|
if (!ws) return c.text('Workspace not found', 404)
|
|
154
156
|
c.set('ws', ws)
|
|
155
157
|
await next()
|
|
@@ -161,7 +163,6 @@ one.use('*', withWorkspace)
|
|
|
161
163
|
|
|
162
164
|
one.get('/preview', async c => {
|
|
163
165
|
const ws = c.get('ws')
|
|
164
|
-
const wsId = c.req.param('id')
|
|
165
166
|
const views = await getViewList(ws.path)
|
|
166
167
|
return c.json(
|
|
167
168
|
await getWorkspacePreview(ws.path, {
|
|
@@ -169,7 +170,7 @@ one.get('/preview', async c => {
|
|
|
169
170
|
harnessFor(ws).workspacePreview(ws, includeFirstUserMessage),
|
|
170
171
|
viewIds: views.map(view => view.id),
|
|
171
172
|
thumbnailUrl: (kind, id) =>
|
|
172
|
-
`/api/workspaces/${
|
|
173
|
+
`/api/workspaces/${ws.id}/applet-thumbnails/${kind}/${encodeURIComponent(id)}`
|
|
173
174
|
})
|
|
174
175
|
)
|
|
175
176
|
})
|
|
@@ -181,10 +182,10 @@ one.get('/widgets', c => listWidgets(c.get('ws').path))
|
|
|
181
182
|
// path lists, `/*` serves a file from the bundle dir (`<name>/<file>`:
|
|
182
183
|
// index.js, a chunk, or a hashed asset).
|
|
183
184
|
one.get('/widgets/*', c => {
|
|
184
|
-
const
|
|
185
|
-
const { name, file } = parseAppletTail(c.req.url, id, 'widgets')
|
|
185
|
+
const ws = c.get('ws')
|
|
186
|
+
const { name, file } = parseAppletTail(c.req.url, ws.id, 'widgets')
|
|
186
187
|
if (!name) return c.text('Not found', 404)
|
|
187
|
-
return serveWidget(name, file,
|
|
188
|
+
return serveWidget(name, file, ws.path, apiBaseFor(ws.id), c.req.header('if-none-match'))
|
|
188
189
|
})
|
|
189
190
|
|
|
190
191
|
// Views — full-screen agent apps. Mirrors the widget pair above: the exact path
|
|
@@ -192,10 +193,10 @@ one.get('/widgets/*', c => {
|
|
|
192
193
|
one.get('/views', c => listViews(c.get('ws').path))
|
|
193
194
|
|
|
194
195
|
one.get('/views/*', c => {
|
|
195
|
-
const
|
|
196
|
-
const { name, file } = parseAppletTail(c.req.url, id, 'views')
|
|
196
|
+
const ws = c.get('ws')
|
|
197
|
+
const { name, file } = parseAppletTail(c.req.url, ws.id, 'views')
|
|
197
198
|
if (!name) return c.text('Not found', 404)
|
|
198
|
-
return serveView(name, file,
|
|
199
|
+
return serveView(name, file, ws.path, apiBaseFor(ws.id), c.req.header('if-none-match'))
|
|
199
200
|
})
|
|
200
201
|
|
|
201
202
|
function viewBuilderError(err: unknown): { message: string; status: 400 | 404 | 409 } | null {
|
|
@@ -358,23 +359,18 @@ one.delete('/view-builders/:builderId', async c => {
|
|
|
358
359
|
// are allowed — the workspace holds secrets, and this route is unauthenticated.
|
|
359
360
|
// localhost binding is NOT the guard.
|
|
360
361
|
one.get('/fs/*', c => {
|
|
361
|
-
const
|
|
362
|
-
const tail = new URL(c.req.url).pathname.split(`/api/workspaces/${id}/fs/`)[1] ?? ''
|
|
363
|
-
return serveWorkspaceFile(
|
|
364
|
-
c.get('ws').path,
|
|
365
|
-
tail,
|
|
366
|
-
c.req.header('range'),
|
|
367
|
-
c.req.header('if-none-match')
|
|
368
|
-
)
|
|
362
|
+
const ws = c.get('ws')
|
|
363
|
+
const tail = new URL(c.req.url).pathname.split(`/api/workspaces/${ws.id}/fs/`)[1] ?? ''
|
|
364
|
+
return serveWorkspaceFile(ws.path, tail, c.req.header('range'), c.req.header('if-none-match'))
|
|
369
365
|
})
|
|
370
366
|
|
|
371
367
|
// Applet RPC — the home for server-function calls from a bundle. The bundle's
|
|
372
368
|
// sentinel base resolves to `/api/workspaces/<id>`, so it POSTs to
|
|
373
369
|
// `…/rpc/<module>/<fn>`.
|
|
374
370
|
one.post('/rpc/*', c => {
|
|
375
|
-
const
|
|
376
|
-
const tail = new URL(c.req.url).pathname.split(`/api/workspaces/${id}/rpc/`)[1] ?? ''
|
|
377
|
-
return handleFunctionCall(c.req.raw, tail,
|
|
371
|
+
const ws = c.get('ws')
|
|
372
|
+
const tail = new URL(c.req.url).pathname.split(`/api/workspaces/${ws.id}/rpc/`)[1] ?? ''
|
|
373
|
+
return handleFunctionCall(c.req.raw, tail, ws.path)
|
|
378
374
|
})
|
|
379
375
|
|
|
380
376
|
// Browser-side applet errors (module load failures, render crashes, window
|
|
@@ -428,9 +424,9 @@ one.post('/applet-log', async c => {
|
|
|
428
424
|
// use this to show the picture an agent `Read` — same guards as /fs/ above,
|
|
429
425
|
// images only, resized server-side (see server/preview.ts).
|
|
430
426
|
one.get('/preview/*', c => {
|
|
431
|
-
const
|
|
432
|
-
const tail = new URL(c.req.url).pathname.split(`/api/workspaces/${id}/preview/`)[1] ?? ''
|
|
433
|
-
return serveWorkspaceImagePreview(
|
|
427
|
+
const ws = c.get('ws')
|
|
428
|
+
const tail = new URL(c.req.url).pathname.split(`/api/workspaces/${ws.id}/preview/`)[1] ?? ''
|
|
429
|
+
return serveWorkspaceImagePreview(ws.path, tail, c.req.header('if-none-match'))
|
|
434
430
|
})
|
|
435
431
|
|
|
436
432
|
// Chat attachments. The composer POSTs files here (drag/drop, paste, or the
|
|
@@ -439,7 +435,7 @@ one.get('/preview/*', c => {
|
|
|
439
435
|
// vision blocks at send time; other files are referenced by a temp path. See
|
|
440
436
|
// server/uploads.ts and dev/file-uploads.md.
|
|
441
437
|
one.post('/uploads', async c => {
|
|
442
|
-
const
|
|
438
|
+
const ws = c.get('ws')
|
|
443
439
|
let form: FormData
|
|
444
440
|
try {
|
|
445
441
|
form = await c.req.formData()
|
|
@@ -459,7 +455,7 @@ one.post('/uploads', async c => {
|
|
|
459
455
|
const bytes = Buffer.from(await file.arrayBuffer())
|
|
460
456
|
out.push(
|
|
461
457
|
await addUpload({
|
|
462
|
-
workspaceId: id,
|
|
458
|
+
workspaceId: ws.id,
|
|
463
459
|
filename: file.name || 'file',
|
|
464
460
|
mediaType: file.type || 'application/octet-stream',
|
|
465
461
|
bytes
|
|
@@ -478,9 +474,9 @@ one.post('/uploads', async c => {
|
|
|
478
474
|
// is content-addressed (sha256), so the response is immutable while it lives —
|
|
479
475
|
// let the browser cache it for the store's TTL.
|
|
480
476
|
one.get('/uploads/:uploadId', c => {
|
|
481
|
-
const u = getUpload(c.
|
|
477
|
+
const u = getUpload(c.get('ws').id, c.req.param('uploadId'))
|
|
482
478
|
if (!u) return c.text('Not found or expired', 404)
|
|
483
|
-
const body
|
|
479
|
+
const body = u.data ? new Uint8Array(u.data) : u.path ? Bun.file(u.path) : null
|
|
484
480
|
if (!body) return c.text('Not found or expired', 404)
|
|
485
481
|
return new Response(body, {
|
|
486
482
|
headers: {
|
|
@@ -604,7 +600,7 @@ one.get('/mcp', async c => {
|
|
|
604
600
|
return c.json((await harnessFor(ws).mcpStatus?.(ws)) ?? [])
|
|
605
601
|
})
|
|
606
602
|
|
|
607
|
-
// Harness debug tap for /
|
|
603
|
+
// Harness debug tap for /dev/harness: the backend's native wire frames
|
|
608
604
|
// (Codex: app-server JSON-RPC, both directions; Claude Code: raw SDK messages
|
|
609
605
|
// + enqueued inputs) and the exact frames the server pushed to chat clients.
|
|
610
606
|
// `sinceWire`/`sinceBroadcast` are seq cursors so the page can poll deltas.
|
|
@@ -771,7 +767,7 @@ one.put('/scratchpad', async c => {
|
|
|
771
767
|
await saveScratchpadDoc(body.document, ws.path)
|
|
772
768
|
publishEvent({
|
|
773
769
|
type: 'scratchpad:updated',
|
|
774
|
-
workspaceId:
|
|
770
|
+
workspaceId: ws.id,
|
|
775
771
|
origin: typeof body.origin === 'string' ? body.origin : undefined
|
|
776
772
|
})
|
|
777
773
|
return c.body(null, 204)
|
|
@@ -910,7 +906,7 @@ one.put('/', async c => {
|
|
|
910
906
|
})
|
|
911
907
|
|
|
912
908
|
one.delete('/', async c => {
|
|
913
|
-
const ok = await removeWorkspace(c.
|
|
909
|
+
const ok = await removeWorkspace(c.get('ws').id)
|
|
914
910
|
if (!ok) return c.text('Workspace not found', 404)
|
|
915
911
|
return c.body(null, 204)
|
|
916
912
|
})
|
package/server/applets.ts
CHANGED
|
@@ -20,9 +20,9 @@ import { dirname, join, resolve, sep } from 'path'
|
|
|
20
20
|
import {
|
|
21
21
|
APPLET_API_BASE_SENTINEL,
|
|
22
22
|
type AppletKind,
|
|
23
|
-
buildApplet,
|
|
24
23
|
scanRelativeImports
|
|
25
24
|
} from './bundler/build-applet'
|
|
25
|
+
import { buildAppletsInChild } from './bundler/build-worker'
|
|
26
26
|
import { pruneAppletThumbnails } from './thumbnails'
|
|
27
27
|
|
|
28
28
|
export type AppletPaths = {
|
|
@@ -609,35 +609,36 @@ export async function buildApplets<C>(
|
|
|
609
609
|
})
|
|
610
610
|
)
|
|
611
611
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
name: job.name,
|
|
628
|
-
status: 'built',
|
|
629
|
-
serverModules: artifact.serverModules.map(m => m.name),
|
|
630
|
-
config: (artifact.config as C | null) ?? null
|
|
631
|
-
}
|
|
632
|
-
} catch (err) {
|
|
633
|
-
return {
|
|
634
|
-
name: job.name,
|
|
635
|
-
status: 'failed',
|
|
636
|
-
error: err instanceof Error ? err.message : 'Unknown error'
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
})
|
|
612
|
+
// Compile the pending set in a fresh child process (see build-worker.ts:
|
|
613
|
+
// Bun's resolver cache is process-wide and never forgets a failed lookup, so
|
|
614
|
+
// an in-process build could not see packages installed after the server
|
|
615
|
+
// started). The child writes each bundle dir; only the per-job outcome comes
|
|
616
|
+
// back.
|
|
617
|
+
const built = new Map(
|
|
618
|
+
(
|
|
619
|
+
await buildAppletsInChild({
|
|
620
|
+
moiRoot,
|
|
621
|
+
kind,
|
|
622
|
+
jobs: jobs
|
|
623
|
+
.filter(job => job.status === 'pending')
|
|
624
|
+
.map(job => ({ name: job.name, srcPath: job.srcPath!, outDir: join(buildDir, job.name) }))
|
|
625
|
+
})
|
|
626
|
+
).map(r => [r.name, r])
|
|
640
627
|
)
|
|
641
628
|
|
|
629
|
+
const results = jobs.map((job): AppletBuildResult<C> => {
|
|
630
|
+
if (job.status === 'failed') return { name: job.name, status: 'failed', error: job.error }
|
|
631
|
+
if (job.status === 'skipped') return { name: job.name, status: 'skipped' }
|
|
632
|
+
const r = built.get(job.name)
|
|
633
|
+
if (!r) return { name: job.name, status: 'failed', error: 'Build worker returned no result' }
|
|
634
|
+
if (r.status === 'failed') return { name: job.name, status: 'failed', error: r.error }
|
|
635
|
+
return {
|
|
636
|
+
name: job.name,
|
|
637
|
+
status: 'built',
|
|
638
|
+
serverModules: r.serverModules,
|
|
639
|
+
config: (r.config as C | null) ?? null
|
|
640
|
+
}
|
|
641
|
+
})
|
|
642
|
+
|
|
642
643
|
return { names, results, ms: Math.round(performance.now() - t0) }
|
|
643
644
|
}
|
|
@@ -28,113 +28,13 @@ import postcss, { type Container, type Document } from 'postcss'
|
|
|
28
28
|
// matching an unrelated tag/class prefix like `bodycopy`.
|
|
29
29
|
const PAGE_ROOT_RE = /^(:root|:host|html|body)(?![\w-])/
|
|
30
30
|
|
|
31
|
-
// Tailwind's `group-has-*` / `peer-has-*` utilities compile to
|
|
32
|
-
// `.util:is(:where(.group):has(…) *)` — a non-subject `:has()` qualifying a
|
|
33
|
-
// universal `*` subject. Chrome cannot build a precise invalidation set for
|
|
34
|
-
// that shape and falls back to restyling the WHOLE document on unrelated DOM
|
|
35
|
-
// mutations: with one such rule mounted, every keystroke anywhere on the page
|
|
36
|
-
// recalculated styles for all ~10k elements (~140ms per key next to a large
|
|
37
|
-
// view — measured, see the chat-input-lag investigation). The equivalent
|
|
38
|
-
// descendant form `:where(.group):has(…) .util` matches the same elements
|
|
39
|
-
// with the same specificity (`:is()` takes its most specific argument), and
|
|
40
|
-
// Chrome invalidates it precisely.
|
|
41
|
-
//
|
|
42
|
-
// The rewrite is deliberately conservative, because it is only safe when it
|
|
43
|
-
// cannot reorder ancestor constraints:
|
|
44
|
-
// • The qualifier must sit on the LEFTMOST compound. That compound has no
|
|
45
|
-
// ancestor constraints to its left, so prepending its anchor imposes
|
|
46
|
-
// nothing new — this covers `.util:is(Q *)` and variant chains like
|
|
47
|
-
// `.util:is(Q *) > svg` (the `[&>svg]:` arbitrary variant). On any later
|
|
48
|
-
// compound (`A .util:is(Q *)`) the prepended anchor would force Q above
|
|
49
|
-
// A, which the original never required, so those are skipped.
|
|
50
|
-
// • Only the ONE `:is(…:has(…) *)` qualifier moves out. Every other
|
|
51
|
-
// qualifier (`:is(:where(.group)[data-x] *)`, stacked pseudos) stays on
|
|
52
|
-
// the subject, where it keeps constraining the same element — shadcn's
|
|
53
|
-
// alert-dialog stacks `group-data-*` and `group-has-data-*` exactly like
|
|
54
|
-
// this. Moving two anchors out would chain them into a strict ancestor
|
|
55
|
-
// order the original didn't have, so a second `:has` qualifier is left
|
|
56
|
-
// in place.
|
|
57
|
-
// • A qualifier with a top-level comma (`:is(A *, B)`) is skipped — the
|
|
58
|
-
// extraction is only equivalence-preserving for a single argument.
|
|
59
|
-
// The trailing `~` of `peer-has-*` (`:is(:where(.peer):has(…) ~ *)`) rides
|
|
60
|
-
// along, keeping the sibling combinator.
|
|
61
|
-
|
|
62
|
-
// Index of the first top-level combinator (space, >, +, ~ outside parens,
|
|
63
|
-
// brackets, and strings), or -1 when the selector is a single compound.
|
|
64
|
-
function firstCombinatorIndex(selector: string): number {
|
|
65
|
-
let depth = 0
|
|
66
|
-
let quote: string | null = null
|
|
67
|
-
for (let i = 0; i < selector.length; i++) {
|
|
68
|
-
const ch = selector[i]!
|
|
69
|
-
if (quote) {
|
|
70
|
-
if (ch === '\\') i++
|
|
71
|
-
else if (ch === quote) quote = null
|
|
72
|
-
continue
|
|
73
|
-
}
|
|
74
|
-
if (ch === '"' || ch === "'") quote = ch
|
|
75
|
-
else if (ch === '\\') i++
|
|
76
|
-
else if (ch === '(' || ch === '[') depth++
|
|
77
|
-
else if (ch === ')' || ch === ']') depth--
|
|
78
|
-
else if (depth === 0 && (ch === ' ' || ch === '>' || ch === '+' || ch === '~')) return i
|
|
79
|
-
}
|
|
80
|
-
return -1
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// The span of the first `:is(…)` qualifier whose single argument contains
|
|
84
|
-
// `:has(` and ends with a universal `*` subject, or null.
|
|
85
|
-
function findHasQualifier(selector: string): { start: number; end: number; anchor: string } | null {
|
|
86
|
-
for (let from = 0; ; ) {
|
|
87
|
-
const start = selector.indexOf(':is(', from)
|
|
88
|
-
if (start === -1) return null
|
|
89
|
-
// Find the matching close paren, tracking nested parens and strings.
|
|
90
|
-
let depth = 0
|
|
91
|
-
let quote: string | null = null
|
|
92
|
-
let end = -1
|
|
93
|
-
let topComma = false
|
|
94
|
-
for (let i = start + 3; i < selector.length; i++) {
|
|
95
|
-
const ch = selector[i]!
|
|
96
|
-
if (quote) {
|
|
97
|
-
if (ch === '\\') i++
|
|
98
|
-
else if (ch === quote) quote = null
|
|
99
|
-
continue
|
|
100
|
-
}
|
|
101
|
-
if (ch === '"' || ch === "'") quote = ch
|
|
102
|
-
else if (ch === '\\') i++
|
|
103
|
-
else if (ch === '(') depth++
|
|
104
|
-
else if (ch === ')') {
|
|
105
|
-
depth--
|
|
106
|
-
if (depth === 0) {
|
|
107
|
-
end = i
|
|
108
|
-
break
|
|
109
|
-
}
|
|
110
|
-
} else if (ch === ',' && depth === 1) topComma = true
|
|
111
|
-
}
|
|
112
|
-
if (end === -1) return null
|
|
113
|
-
const inner = selector.slice(start + 4, end).trim()
|
|
114
|
-
if (!topComma && inner.includes(':has(') && inner.endsWith('*')) {
|
|
115
|
-
const anchor = inner.slice(0, -1).trim()
|
|
116
|
-
if (anchor.length > 0) return { start, end: end + 1, anchor }
|
|
117
|
-
}
|
|
118
|
-
from = end + 1
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export function unqualifyNonSubjectHas(selector: string): string {
|
|
123
|
-
if (!selector.includes(':has(')) return selector
|
|
124
|
-
const combinatorAt = firstCombinatorIndex(selector)
|
|
125
|
-
const compound = combinatorAt === -1 ? selector : selector.slice(0, combinatorAt)
|
|
126
|
-
const rest = combinatorAt === -1 ? '' : selector.slice(combinatorAt)
|
|
127
|
-
const qualifier = findHasQualifier(compound)
|
|
128
|
-
if (!qualifier) return selector
|
|
129
|
-
const subject = (compound.slice(0, qualifier.start) + compound.slice(qualifier.end)).trim()
|
|
130
|
-
if (subject.length === 0) return selector
|
|
131
|
-
// `anchor` may end with the peer variant's `~`; the join keeps it a sibling
|
|
132
|
-
// combinator, otherwise it's a descendant combinator.
|
|
133
|
-
return `${qualifier.anchor} ${subject}${rest}`
|
|
134
|
-
}
|
|
135
|
-
|
|
136
31
|
function insideKeyframes(parent: Container | Document | undefined): boolean {
|
|
137
|
-
return
|
|
32
|
+
return (
|
|
33
|
+
parent?.type === 'atrule' &&
|
|
34
|
+
'name' in parent &&
|
|
35
|
+
typeof parent.name === 'string' &&
|
|
36
|
+
/keyframes$/i.test(parent.name)
|
|
37
|
+
)
|
|
138
38
|
}
|
|
139
39
|
|
|
140
40
|
export function scopeAppletCss(css: string, scope: string): string {
|
|
@@ -144,7 +44,7 @@ export function scopeAppletCss(css: string, scope: string): string {
|
|
|
144
44
|
root.walkRules(rule => {
|
|
145
45
|
if (insideKeyframes(rule.parent)) return
|
|
146
46
|
rule.selectors = rule.selectors.map(selector => {
|
|
147
|
-
const s =
|
|
47
|
+
const s = selector.trim()
|
|
148
48
|
const rootToken = PAGE_ROOT_RE.exec(s)
|
|
149
49
|
if (rootToken) return container + s.slice(rootToken[0].length)
|
|
150
50
|
return `${container} ${s}`
|
|
@@ -17,6 +17,8 @@ import { scopeAppletCss } from './applet-css'
|
|
|
17
17
|
// canonical in lib/types; re-exported here for this pipeline's consumers.
|
|
18
18
|
export type { AppletKind }
|
|
19
19
|
|
|
20
|
+
const APP_ICON_NAMES: readonly string[] = APP_ICON_IDS
|
|
21
|
+
|
|
20
22
|
// Baked into the bundle wherever a runtime URL needs the workspace's API base
|
|
21
23
|
// (RPC + workspace files). The serve route string-replaces it with the real
|
|
22
24
|
// `/api/workspaces/<id>` in every `.js` it returns, so the on-disk bundle stays
|
|
@@ -163,7 +165,9 @@ export async function extractViewConfig(srcPath: string): Promise<ViewConfig | n
|
|
|
163
165
|
if (prop.value.type === 'StringLiteral') {
|
|
164
166
|
const icon = prop.value.value
|
|
165
167
|
if (!isAppIconId(icon)) {
|
|
166
|
-
throw new Error(
|
|
168
|
+
throw new Error(
|
|
169
|
+
`Unknown view icon id "${icon}". Use one of: ${APP_ICON_NAMES.join(', ')}`
|
|
170
|
+
)
|
|
167
171
|
}
|
|
168
172
|
result.icon = icon
|
|
169
173
|
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// Out-of-process applet compiler.
|
|
2
|
+
//
|
|
3
|
+
// `Bun.build` shares one process-wide resolver cache with the runtime module
|
|
4
|
+
// loader: `node_modules` directory listings, `package.json` contents, and —
|
|
5
|
+
// crucially — FAILED bare-specifier lookups are memoized for the life of the
|
|
6
|
+
// process and never invalidated (still true in Bun 1.4). The moi server is
|
|
7
|
+
// long-lived, so an in-process build that once failed with `Could not resolve
|
|
8
|
+
// "pkg"` keeps failing for that specifier after the agent runs `bun add pkg`,
|
|
9
|
+
// and a workspace that gains its own `node_modules` (or bumps a package's
|
|
10
|
+
// `exports`) keeps resolving through the stale entry. Restarting the server
|
|
11
|
+
// was the only cure, and the agent isn't allowed to do that.
|
|
12
|
+
//
|
|
13
|
+
// So every build batch runs in a fresh `bun` child: the child imports this
|
|
14
|
+
// module as its entry, receives one `BuildRequest` over IPC, compiles each job
|
|
15
|
+
// with `buildApplet`, writes the bundle dirs, and replies with a
|
|
16
|
+
// `BuildResponse`. A cold child costs ~150ms, almost all of it importing this
|
|
17
|
+
// module's graph (bun-plugin-tailwind, applet-css, @babel/parser) — and a
|
|
18
|
+
// crash inside Bun's bundler no longer takes the server down with it.
|
|
19
|
+
//
|
|
20
|
+
// Lifecycle: the child never exits on its own after replying. `process.exit`
|
|
21
|
+
// right after `process.send` drops the message once it outgrows the IPC pipe
|
|
22
|
+
// buffer (~1MB — a handful of failed applets with long Bun diagnostics gets
|
|
23
|
+
// there), so the parent kills the child once the result has arrived. The
|
|
24
|
+
// child exits by itself only when the parent is gone: on IPC `disconnect`,
|
|
25
|
+
// or when its parent pid changes (a crashed/SIGKILLed server never sends
|
|
26
|
+
// disconnect, but the orphan is reparented). Live children are tracked so the
|
|
27
|
+
// server's shutdown path can kill them — an untracked build outliving a dev
|
|
28
|
+
// restart would keep rewriting `.build/` under the replacement server.
|
|
29
|
+
//
|
|
30
|
+
// `buildApplet` itself stays in-process-capable: tests call it directly, and
|
|
31
|
+
// nothing here changes its contract.
|
|
32
|
+
import { mkdir, rm } from 'node:fs/promises'
|
|
33
|
+
import { join } from 'path'
|
|
34
|
+
|
|
35
|
+
import type { AppletKind, ViewConfig, WidgetConfig } from '@/lib/types'
|
|
36
|
+
|
|
37
|
+
import { buildApplet } from './build-applet'
|
|
38
|
+
|
|
39
|
+
export type BuildJob = {
|
|
40
|
+
name: string
|
|
41
|
+
// Absolute path of the applet's entry source (`.moi/<kind>/<name>.tsx`).
|
|
42
|
+
srcPath: string
|
|
43
|
+
// Absolute bundle directory to (re)create: `.moi/.build/<kind>/<name>/`.
|
|
44
|
+
outDir: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type BuildJobResult = {
|
|
48
|
+
name: string
|
|
49
|
+
status: 'built' | 'failed'
|
|
50
|
+
error?: string
|
|
51
|
+
serverModules?: string[]
|
|
52
|
+
config?: WidgetConfig | ViewConfig | null
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type BuildRequest = {
|
|
56
|
+
type: 'build'
|
|
57
|
+
moiRoot: string
|
|
58
|
+
kind: AppletKind
|
|
59
|
+
jobs: BuildJob[]
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type BuildResponse = {
|
|
63
|
+
type: 'result'
|
|
64
|
+
results: BuildJobResult[]
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const WORKER_PATH = join(import.meta.dir, 'build-worker.ts')
|
|
68
|
+
|
|
69
|
+
// Children currently compiling a batch, for `killBuildWorkers()`.
|
|
70
|
+
const liveWorkers = new Set<ReturnType<typeof Bun.spawn>>()
|
|
71
|
+
|
|
72
|
+
// How many build children are alive right now (tests assert none leak).
|
|
73
|
+
export function liveBuildWorkerCount(): number {
|
|
74
|
+
return liveWorkers.size
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Kill every in-flight build child. Called from the server's shutdown path
|
|
78
|
+
// (SIGTERM from the dev supervisor, Ctrl-C) alongside the function-worker pool
|
|
79
|
+
// so a half-done bundle can't keep writing after the server is gone. Pending
|
|
80
|
+
// batches settle as failed through `onExit`.
|
|
81
|
+
export function killBuildWorkers(): void {
|
|
82
|
+
for (const proc of liveWorkers) proc.kill()
|
|
83
|
+
liveWorkers.clear()
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Compile every job and write its bundle dir. Runs inside the child, but is a
|
|
87
|
+
// plain function so the batch semantics (parallel jobs, per-job failure
|
|
88
|
+
// isolation, clear-then-write) are testable without spawning.
|
|
89
|
+
export async function runBuildJobs(req: BuildRequest): Promise<BuildJobResult[]> {
|
|
90
|
+
return Promise.all(
|
|
91
|
+
req.jobs.map(async (job): Promise<BuildJobResult> => {
|
|
92
|
+
try {
|
|
93
|
+
const artifact = await buildApplet(job.srcPath, req.moiRoot, req.kind)
|
|
94
|
+
// Clear the dir first so stale hashed assets from a prior build don't
|
|
95
|
+
// accumulate, then write the fresh entry + chunks + assets.
|
|
96
|
+
await rm(job.outDir, { recursive: true, force: true })
|
|
97
|
+
await mkdir(job.outDir, { recursive: true })
|
|
98
|
+
for (const f of artifact.files) {
|
|
99
|
+
await Bun.write(join(job.outDir, f.name), f.data)
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
name: job.name,
|
|
103
|
+
status: 'built',
|
|
104
|
+
serverModules: artifact.serverModules.map(m => m.name),
|
|
105
|
+
config: artifact.config
|
|
106
|
+
}
|
|
107
|
+
} catch (err) {
|
|
108
|
+
return {
|
|
109
|
+
name: job.name,
|
|
110
|
+
status: 'failed',
|
|
111
|
+
error: err instanceof Error ? err.message : 'Unknown error'
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Host side: spawn a fresh child for one batch and collect its results. The
|
|
119
|
+
// child inherits cwd and env, so resolution behaves exactly as the in-process
|
|
120
|
+
// build did (see the `devalue` and `serverCwd` notes in build-applet.ts) —
|
|
121
|
+
// minus the poisoned cache. A child that dies before replying fails every job
|
|
122
|
+
// in the batch with its exit code rather than hanging the caller.
|
|
123
|
+
export function buildAppletsInChild(req: Omit<BuildRequest, 'type'>): Promise<BuildJobResult[]> {
|
|
124
|
+
if (req.jobs.length === 0) return Promise.resolve([])
|
|
125
|
+
return new Promise(resolve => {
|
|
126
|
+
let settled = false
|
|
127
|
+
const settle = (results: BuildJobResult[]) => {
|
|
128
|
+
if (settled) return
|
|
129
|
+
settled = true
|
|
130
|
+
resolve(results)
|
|
131
|
+
}
|
|
132
|
+
const request: BuildRequest = { type: 'build', ...req }
|
|
133
|
+
const proc = Bun.spawn([process.execPath, WORKER_PATH], {
|
|
134
|
+
stdio: ['ignore', 'inherit', 'inherit'],
|
|
135
|
+
serialization: 'json',
|
|
136
|
+
ipc(message, child) {
|
|
137
|
+
const msg = message as Partial<BuildResponse>
|
|
138
|
+
if (msg.type !== 'result' || !Array.isArray(msg.results)) return
|
|
139
|
+
settle(msg.results)
|
|
140
|
+
// The result is in hand — the child has nothing left to do (see the
|
|
141
|
+
// lifecycle note above for why it doesn't exit on its own).
|
|
142
|
+
liveWorkers.delete(child)
|
|
143
|
+
child.kill()
|
|
144
|
+
},
|
|
145
|
+
onExit(child, code, signal) {
|
|
146
|
+
liveWorkers.delete(child)
|
|
147
|
+
const why = signal ? `signal ${signal}` : `code ${code}`
|
|
148
|
+
settle(
|
|
149
|
+
req.jobs.map(job => ({
|
|
150
|
+
name: job.name,
|
|
151
|
+
status: 'failed',
|
|
152
|
+
error: `Build worker exited (${why}) before reporting a result`
|
|
153
|
+
}))
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
})
|
|
157
|
+
liveWorkers.add(proc)
|
|
158
|
+
proc.send(request)
|
|
159
|
+
})
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (import.meta.main) {
|
|
163
|
+
// Orphan guards — the only ways the child ends itself. See the lifecycle
|
|
164
|
+
// note at the top: the parent kills us after it has read the result.
|
|
165
|
+
const parentPid = process.ppid
|
|
166
|
+
process.on('disconnect', () => process.exit(0))
|
|
167
|
+
setInterval(() => {
|
|
168
|
+
if (process.ppid !== parentPid) process.exit(0)
|
|
169
|
+
}, 500)
|
|
170
|
+
|
|
171
|
+
process.on('message', async message => {
|
|
172
|
+
const req = message as Partial<BuildRequest>
|
|
173
|
+
if (req.type !== 'build' || !Array.isArray(req.jobs)) return
|
|
174
|
+
const results = await runBuildJobs(req as BuildRequest)
|
|
175
|
+
const response: BuildResponse = { type: 'result', results }
|
|
176
|
+
process.send?.(response)
|
|
177
|
+
})
|
|
178
|
+
}
|