moi-computer 0.3.0 → 0.3.1-next.1

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 (121) hide show
  1. package/client/api/workspace-keys.ts +2 -2
  2. package/client/app/AppRouter.tsx +0 -2
  3. package/client/app/routes/WorkspaceRoute.tsx +3 -1
  4. package/client/app/shell/SidebarLayout.tsx +3 -16
  5. package/client/assets/openai.svg +1 -3
  6. package/client/components/shared/Composer.tsx +112 -0
  7. package/client/components/ui/button.tsx +1 -1
  8. package/client/components/ui/dropdown-menu.tsx +3 -3
  9. package/client/components/ui/tooltip.tsx +12 -15
  10. package/client/features/applets/WidgetErrorBoundary.tsx +19 -3
  11. package/client/features/applets/WidgetShell.tsx +8 -1
  12. package/client/features/applets/applet-log.ts +100 -0
  13. package/client/features/applets/useApplet.ts +21 -7
  14. package/client/features/chat/ChatComposer.tsx +33 -30
  15. package/client/features/chat/ChatPanel.tsx +5 -2
  16. package/client/features/chat/MarkdownContent.tsx +20 -2
  17. package/client/features/chat/ModelPicker.tsx +29 -41
  18. package/client/features/chat/TurnView.tsx +2 -2
  19. package/client/features/chat/chat-frames.ts +14 -6
  20. package/client/features/chat/chat-send.ts +1 -1
  21. package/client/features/chat/chat-store.ts +22 -17
  22. package/client/features/chat/model-order.ts +47 -0
  23. package/client/features/chat/tool-group/ToolOutput.tsx +4 -12
  24. package/client/features/chat/tool-group/format.ts +0 -6
  25. package/client/features/chat/useChat.ts +15 -2
  26. package/client/features/connectors/McpServerCards.tsx +95 -0
  27. package/client/features/connectors/api.ts +0 -11
  28. package/client/features/home/HomePage.tsx +45 -42
  29. package/client/features/home/WorkspacePreview.tsx +179 -38
  30. package/client/features/home/api.ts +24 -12
  31. package/client/features/home/workspace-presentation.tsx +17 -15
  32. package/client/features/home/workspace-setup/CreateWorkspaceDialog.tsx +243 -0
  33. package/client/features/home/workspace-setup/ImportWorkspaceDialog.tsx +95 -0
  34. package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +230 -0
  35. package/client/features/home/workspace-setup/WorkspaceDialogContent.tsx +35 -0
  36. package/client/features/home/workspace-setup/useWorkspaceImport.ts +61 -0
  37. package/client/features/settings/ConnectorsSettings.tsx +89 -0
  38. package/client/features/settings/GeneralSettings.tsx +12 -0
  39. package/client/features/settings/SettingsLayout.tsx +2 -2
  40. package/client/features/settings/WorkspaceSettings.tsx +8 -4
  41. package/client/features/views/ViewBuilderTab.tsx +28 -29
  42. package/client/features/views/useViewBuilderActions.ts +1 -1
  43. package/client/features/widgets/WidgetFrame.tsx +3 -0
  44. package/client/features/widgets/WidgetGrid.tsx +1 -0
  45. package/client/features/widgets/Widgets.tsx +12 -3
  46. package/client/features/widgets/api.ts +47 -0
  47. package/client/features/widgets/useWidgetThumbnails.ts +107 -0
  48. package/client/features/widgets/widget-snapshot.ts +71 -0
  49. package/client/features/workspace/WorkspaceLayoutContext.tsx +3 -4
  50. package/client/features/workspace/WorkspaceScreen.tsx +19 -4
  51. package/client/features/workspace/api.ts +25 -3
  52. package/client/features/workspace/moi-context.ts +85 -0
  53. package/client/index.css +0 -5
  54. package/client/main.tsx +13 -4
  55. package/dist/{chunk-cs8vbert.js → chunk-1dfbr7n2.js} +2 -2
  56. package/dist/chunk-339jds4x.js +15 -0
  57. package/dist/chunk-3xsvsnhr.css +1 -0
  58. package/dist/{chunk-zpxrb1ce.js → chunk-anqmsbjt.js} +2 -2
  59. package/dist/chunk-hbvfb6sk.js +63 -0
  60. package/dist/chunk-jen6xcm1.js +14 -0
  61. package/dist/{chunk-kxmvv1ax.js → chunk-qwm5f6qk.js} +1 -1
  62. package/dist/{chunk-fjksw6xf.js → chunk-sxbfh73c.js} +1 -1
  63. package/dist/chunk-yp4srgqt.js +10 -0
  64. package/dist/index.html +1 -1
  65. package/dist/openai-ep9ht2pq.svg +1 -0
  66. package/lib/ids.ts +15 -0
  67. package/lib/moi-context.ts +170 -0
  68. package/lib/types.ts +95 -13
  69. package/lib/view-builder-directives.ts +16 -0
  70. package/lib/workspace-types.ts +12 -0
  71. package/package.json +4 -2
  72. package/server/api.ts +180 -34
  73. package/server/applet-log.ts +149 -0
  74. package/server/cli.ts +161 -7
  75. package/server/control.ts +81 -1
  76. package/server/functions.ts +44 -14
  77. package/server/harness/README.md +26 -9
  78. package/server/harness/claude-code/NOTES.md +20 -6
  79. package/server/harness/claude-code/adapter.ts +2 -2
  80. package/server/harness/claude-code/git-worktree.ts +32 -0
  81. package/server/harness/claude-code/index.ts +35 -13
  82. package/server/harness/claude-code/mcp.ts +16 -65
  83. package/server/harness/claude-code/models.ts +3 -0
  84. package/server/harness/claude-code/session.ts +196 -61
  85. package/server/harness/claude-code/sessions.ts +51 -0
  86. package/server/harness/codex/NOTES.md +41 -11
  87. package/server/harness/codex/adapter.ts +52 -6
  88. package/server/harness/codex/client.ts +69 -18
  89. package/server/harness/codex/discovery.ts +114 -0
  90. package/server/harness/codex/index.ts +12 -5
  91. package/server/harness/codex/probe.ts +4 -2
  92. package/server/harness/codex/session.ts +57 -5
  93. package/server/harness/executable.ts +82 -0
  94. package/server/harness/openclaw/adapter.ts +8 -1
  95. package/server/harness/openclaw/discovery.ts +139 -6
  96. package/server/harness/openclaw/gateway.ts +40 -18
  97. package/server/harness/openclaw/index.ts +12 -15
  98. package/server/harness/openclaw/session.ts +50 -10
  99. package/server/harness/openclaw/strip.ts +2 -2
  100. package/server/harness/shell-path.ts +79 -0
  101. package/server/harness/types.ts +37 -5
  102. package/server/layout.ts +81 -51
  103. package/server/registry.ts +57 -12
  104. package/server/scratchpad-assets.ts +41 -6
  105. package/server/scratchpad.ts +30 -0
  106. package/server/view-builders.ts +3 -2
  107. package/server/views.ts +5 -0
  108. package/server/web.ts +30 -8
  109. package/server/widgets.ts +23 -2
  110. package/server/workspace-import.ts +45 -0
  111. package/workspace/.claude/skills/moi-workspace/SKILL.md +27 -3
  112. package/client/features/connectors/ConnectorsPage.tsx +0 -92
  113. package/client/features/connectors/McpMenu.tsx +0 -145
  114. package/client/features/home/CreateWorkspaceDialog.tsx +0 -130
  115. package/client/features/home/CreateWorkspaceDialogSteps.tsx +0 -234
  116. package/dist/chunk-4vf1t6v1.js +0 -10
  117. package/dist/chunk-4z52b2av.css +0 -1
  118. package/dist/chunk-b4b276wx.js +0 -15
  119. package/dist/chunk-y82s1jxm.js +0 -61
  120. package/dist/openai-h13pza4b.svg +0 -3
  121. package/lib/view-builder-meta.ts +0 -35
@@ -1,7 +1,7 @@
1
1
  export const workspaceKeys = {
2
2
  all: ['workspaces'] as const,
3
3
  discover: ['workspaces', 'discover'] as const,
4
- createInfo: ['workspaces', 'create-info'] as const,
4
+ setupInfo: ['workspaces', 'setup-info'] as const,
5
5
  preview: (id: string) => ['workspaces', 'preview', id] as const,
6
6
  layout: (id: string) => ['workspaces', 'layout', id] as const,
7
7
  widgets: (id: string) => ['workspaces', 'widgets', id] as const,
@@ -11,8 +11,8 @@ export const workspaceKeys = {
11
11
  events: (id: string, sessionId: string) => ['workspaces', 'events', id, sessionId] as const,
12
12
  threadConfig: (id: string, sessionId: string) =>
13
13
  ['workspaces', 'threadConfig', id, sessionId] as const,
14
- userMcp: ['mcp', 'user'] as const,
15
14
  mcp: (id: string) => ['workspaces', 'mcp', id] as const,
16
15
  models: (id: string) => ['workspaces', 'models', id] as const,
16
+ availability: (id: string) => ['workspaces', 'availability', id] as const,
17
17
  env: (id: string) => ['workspaces', 'env', id] as const
18
18
  }
@@ -3,7 +3,6 @@ import { Suspense, lazy, useEffect } from 'react'
3
3
  import { Route, Switch, useLocation } from 'wouter'
4
4
 
5
5
  import { setWorkspaceSwitchHandler } from '@/client/features/chat/chat-connection'
6
- import { ConnectorsPage } from '@/client/features/connectors/ConnectorsPage'
7
6
 
8
7
  import { HomeRoute } from './routes/HomeRoute'
9
8
  import { WorkspaceRoute } from './routes/WorkspaceRoute'
@@ -34,7 +33,6 @@ export function AppRouter() {
34
33
  return (
35
34
  <Switch>
36
35
  <Route path="/" component={HomeRoute} />
37
- <Route path="/connectors" component={ConnectorsPage} />
38
36
  <Route path="/dev/*?" component={DevLazy} />
39
37
  <Route path="/workspace/:id">
40
38
  {(params: { id: string }) => <WorkspaceRoute key={params.id} id={params.id} />}
@@ -48,7 +48,9 @@ function WorkspaceLoader({ id }: WorkspaceRouteProps) {
48
48
  useWorkspaceEvent(event => {
49
49
  if (event.type === 'theme:updated' || event.type === 'workspace:updated') {
50
50
  queryClient.invalidateQueries({ queryKey: workspaceKeys.layout(id) })
51
- } else if (event.type === 'widget-layout:updated') {
51
+ } else if (event.type === 'widget-layout:updated' || event.type === 'widget:updated') {
52
+ // widget:updated too: a rebundle bumps the widget's content `tag`, and
53
+ // the thumbnail invalidation hook reads it off this query.
52
54
  queryClient.invalidateQueries({ queryKey: workspaceKeys.widgets(id) })
53
55
  } else if (event.type === 'view-layout:updated') {
54
56
  queryClient.invalidateQueries({ queryKey: workspaceKeys.views(id) })
@@ -1,13 +1,13 @@
1
1
  import { type ReactNode } from 'react'
2
2
 
3
- import { IconPlugConnected, IconPlus, IconSmartHome } from '@tabler/icons-react'
3
+ import { IconPlus, IconSmartHome } from '@tabler/icons-react'
4
4
  import { useQueryClient } from '@tanstack/react-query'
5
5
  import { Link, useLocation } from 'wouter'
6
6
 
7
7
  import { useReorderWorkspaces, useWorkspaces } from '@/client/features/home/api'
8
8
  import { workspaceKeys } from '@/client/api/workspace-keys'
9
9
  import { useWorkspaceEvent } from '@/client/runtime/useWorkspaceEvents'
10
- import { CreateWorkspaceDialog } from '@/client/features/home/CreateWorkspaceDialog'
10
+ import { CreateWorkspaceDialog } from '@/client/features/home/workspace-setup/CreateWorkspaceDialog'
11
11
  import { ReorderableList } from '@/client/components/shared/ReorderableList'
12
12
  import type { ReorderableRenderState } from '@/client/components/shared/ReorderableList'
13
13
  import { Button, buttonVariants } from '@/client/components/ui/button'
@@ -119,24 +119,11 @@ function Sidebar({ workspaces }: SidebarProps) {
119
119
  )}
120
120
  </nav>
121
121
 
122
- <ConnectorsNavLink />
122
+ <div aria-hidden="true" className="size-8 shrink-0" />
123
123
  </aside>
124
124
  )
125
125
  }
126
126
 
127
- function ConnectorsNavLink() {
128
- return (
129
- <Link
130
- href="/connectors"
131
- aria-label="Connectors"
132
- title="Connectors"
133
- className={sidebarNavButtonClass}
134
- >
135
- <IconPlugConnected stroke={1.5} />
136
- </Link>
137
- )
138
- }
139
-
140
127
  type WorkspaceButtonProps = {
141
128
  workspace: WorkspaceEntry
142
129
  dragOverlay?: boolean
@@ -1,3 +1 @@
1
- <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
2
- <path fill="#10A37F" d="M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.073zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.8956zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997z"/>
3
- </svg>
1
+ <svg fill="none" fill-rule="evenodd" height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>OpenAI</title><path d="M9.205 8.658v-2.26c0-.19.072-.333.238-.428l4.543-2.616c.619-.357 1.356-.523 2.117-.523 2.854 0 4.662 2.212 4.662 4.566 0 .167 0 .357-.024.547l-4.71-2.759a.797.797 0 00-.856 0l-5.97 3.473zm10.609 8.8V12.06c0-.333-.143-.57-.429-.737l-5.97-3.473 1.95-1.118a.433.433 0 01.476 0l4.543 2.617c1.309.76 2.189 2.378 2.189 3.948 0 1.808-1.07 3.473-2.76 4.163zM7.802 12.703l-1.95-1.142c-.167-.095-.239-.238-.239-.428V5.899c0-2.545 1.95-4.472 4.591-4.472 1 0 1.927.333 2.712.928L8.23 5.067c-.285.166-.428.404-.428.737v6.898zM12 15.128l-2.795-1.57v-3.33L12 8.658l2.795 1.57v3.33L12 15.128zm1.796 7.23c-1 0-1.927-.332-2.712-.927l4.686-2.712c.285-.166.428-.404.428-.737v-6.898l1.974 1.142c.167.095.238.238.238.428v5.233c0 2.545-1.974 4.472-4.614 4.472zm-5.637-5.303l-4.544-2.617c-1.308-.761-2.188-2.378-2.188-3.948A4.482 4.482 0 014.21 6.327v5.423c0 .333.143.571.428.738l5.947 3.449-1.95 1.118a.432.432 0 01-.476 0zm-.262 3.9c-2.688 0-4.662-2.021-4.662-4.519 0-.19.024-.38.047-.57l4.686 2.71c.286.167.571.167.856 0l5.97-3.448v2.26c0 .19-.07.333-.237.428l-4.543 2.616c-.619.357-1.356.523-2.117.523zm5.899 2.83a5.947 5.947 0 005.827-4.756C22.287 18.339 24 15.84 24 13.296c0-1.665-.713-3.282-1.998-4.448.119-.5.19-.999.19-1.498 0-3.401-2.759-5.947-5.946-5.947-.642 0-1.26.095-1.88.31A5.962 5.962 0 0010.205 0a5.947 5.947 0 00-5.827 4.757C1.713 5.447 0 7.945 0 10.49c0 1.666.713 3.283 1.998 4.448-.119.5-.19 1-.19 1.499 0 3.401 2.759 5.946 5.946 5.946.642 0 1.26-.095 1.88-.309a5.96 5.96 0 004.162 1.713z" fill="#111111"></path></svg>
@@ -0,0 +1,112 @@
1
+ import type { ComponentProps, RefObject } from 'react'
2
+
3
+ import { IconArrowUp, IconLoader2 } from '@tabler/icons-react'
4
+
5
+ import { Button } from '@/client/components/ui/button'
6
+ import { Tooltip, TooltipContent, TooltipTrigger } from '@/client/components/ui/tooltip'
7
+ import { cn } from '@/client/lib/cn'
8
+
9
+ type ComposerProps = Omit<ComponentProps<'form'>, 'ref'> & {
10
+ composerRef: RefObject<HTMLTextAreaElement | null>
11
+ }
12
+
13
+ export function Composer({
14
+ composerRef,
15
+ className,
16
+ onMouseDown,
17
+ children,
18
+ ...props
19
+ }: ComposerProps) {
20
+ return (
21
+ <form
22
+ {...props}
23
+ onMouseDown={event => {
24
+ onMouseDown?.(event)
25
+ if (event.defaultPrevented) return
26
+ if (
27
+ event.target instanceof Element &&
28
+ event.target.closest('button, input, textarea, select, a, [contenteditable="true"]')
29
+ )
30
+ return
31
+ composerRef.current?.focus()
32
+ }}
33
+ className={cn(
34
+ 'flex w-full max-w-(--chat-max-container) cursor-text flex-col gap-1 rounded-lg bg-card p-2 text-card-foreground shadow-xs transition-[color,box-shadow] outline-none focus-within:shadow-sm',
35
+ className
36
+ )}
37
+ >
38
+ {children}
39
+ </form>
40
+ )
41
+ }
42
+
43
+ type ComposerTextareaProps = Omit<ComponentProps<'textarea'>, 'ref'> & {
44
+ textareaRef: RefObject<HTMLTextAreaElement | null>
45
+ }
46
+
47
+ export function ComposerTextarea({ textareaRef, className, ...props }: ComposerTextareaProps) {
48
+ return (
49
+ <textarea
50
+ {...props}
51
+ ref={textareaRef}
52
+ className={cn(
53
+ 'field-sizing-content max-h-40 w-full resize-none bg-transparent px-2 py-1 text-sm leading-relaxed outline-none placeholder:text-muted-foreground disabled:opacity-50',
54
+ className
55
+ )}
56
+ />
57
+ )
58
+ }
59
+
60
+ type ComposerFooterProps = ComponentProps<'div'>
61
+
62
+ export function ComposerFooter({ className, children, ...props }: ComposerFooterProps) {
63
+ return (
64
+ <div {...props} className={cn('flex items-center justify-end gap-1.5', className)}>
65
+ {children}
66
+ </div>
67
+ )
68
+ }
69
+
70
+ export function canSubmitComposerAction(
71
+ hasContent: boolean,
72
+ busy: boolean,
73
+ unavailableReason: string | null | undefined
74
+ ): boolean {
75
+ return hasContent && !busy && unavailableReason === null
76
+ }
77
+
78
+ type ComposerSubmitButtonProps = {
79
+ label: string
80
+ hasContent: boolean
81
+ busy?: boolean
82
+ loading?: boolean
83
+ unavailableReason: string | null | undefined
84
+ }
85
+
86
+ export function ComposerSubmitButton({
87
+ label,
88
+ hasContent,
89
+ busy = false,
90
+ loading = false,
91
+ unavailableReason
92
+ }: ComposerSubmitButtonProps) {
93
+ const canSubmit = canSubmitComposerAction(hasContent, busy || loading, unavailableReason)
94
+ const button = (
95
+ <Button type="submit" size="icon" disabled={!canSubmit} aria-label={label}>
96
+ {loading ? (
97
+ <IconLoader2 stroke={1.5} className="animate-spin" />
98
+ ) : (
99
+ <IconArrowUp stroke={1.5} />
100
+ )}
101
+ </Button>
102
+ )
103
+
104
+ if (loading || !unavailableReason) return button
105
+
106
+ return (
107
+ <Tooltip>
108
+ <TooltipTrigger render={<span className="inline-flex">{button}</span>} />
109
+ <TooltipContent className="max-w-64 text-center">{unavailableReason}</TooltipContent>
110
+ </Tooltip>
111
+ )
112
+ }
@@ -4,7 +4,7 @@ import { type VariantProps, cva } from 'class-variance-authority'
4
4
  import { cn } from '@/client/lib/cn'
5
5
 
6
6
  const buttonVariants = cva(
7
- 'inline-flex shrink-0 cursor-pointer items-center justify-center gap-2 rounded-sm text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0',
7
+ 'inline-flex shrink-0 cursor-pointer items-center justify-center gap-1.5 rounded-sm text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0',
8
8
  {
9
9
  variants: {
10
10
  variant: {
@@ -64,7 +64,7 @@ function DropdownMenuLabel({
64
64
  data-slot="dropdown-menu-label"
65
65
  data-inset={inset}
66
66
  className={cn(
67
- 'px-1.5 py-1 text-xs font-medium text-muted-foreground data-inset:pl-7',
67
+ 'px-2 py-1 text-xs font-medium text-muted-foreground data-inset:pl-7',
68
68
  className
69
69
  )}
70
70
  {...props}
@@ -87,7 +87,7 @@ function DropdownMenuItem({
87
87
  data-inset={inset}
88
88
  data-variant={variant}
89
89
  className={cn(
90
- "group/dropdown-menu-item relative flex cursor-default items-center gap-2 rounded-xs px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 data-[variant=destructive]:*:[svg]:text-destructive",
90
+ "group/dropdown-menu-item relative flex cursor-default items-center gap-2 rounded-xs px-2 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 data-[variant=destructive]:*:[svg]:text-destructive",
91
91
  className
92
92
  )}
93
93
  {...props}
@@ -112,7 +112,7 @@ function DropdownMenuSubTrigger({
112
112
  data-slot="dropdown-menu-sub-trigger"
113
113
  data-inset={inset}
114
114
  className={cn(
115
- "flex cursor-default items-center gap-2 rounded-xs px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-popup-open:bg-accent data-popup-open:text-accent-foreground data-open:bg-accent data-open:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
115
+ "flex cursor-default items-center gap-2 rounded-xs px-2 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-popup-open:bg-accent data-popup-open:text-accent-foreground data-open:bg-accent data-open:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
116
116
  className
117
117
  )}
118
118
  {...props}
@@ -2,18 +2,12 @@ import { Tooltip as TooltipPrimitive } from '@base-ui/react/tooltip'
2
2
 
3
3
  import { cn } from '@/client/lib/cn'
4
4
 
5
- // Self-contained: each Tooltip wraps its own provider so `delay` can be set
6
- // per-instance (Base UI exposes delay/closeDelay on the provider, not the root).
7
- function Tooltip({
8
- delay,
9
- closeDelay,
10
- ...props
11
- }: TooltipPrimitive.Root.Props & { delay?: number; closeDelay?: number }) {
12
- return (
13
- <TooltipPrimitive.Provider delay={delay} closeDelay={closeDelay}>
14
- <TooltipPrimitive.Root data-slot="tooltip" {...props} />
15
- </TooltipPrimitive.Provider>
16
- )
5
+ function TooltipProvider({ delay = 100, ...props }: TooltipPrimitive.Provider.Props) {
6
+ return <TooltipPrimitive.Provider data-slot="tooltip-provider" delay={delay} {...props} />
7
+ }
8
+
9
+ function Tooltip({ ...props }: TooltipPrimitive.Root.Props) {
10
+ return <TooltipPrimitive.Root data-slot="tooltip" {...props} />
17
11
  }
18
12
 
19
13
  function TooltipTrigger({ ...props }: TooltipPrimitive.Trigger.Props) {
@@ -26,6 +20,7 @@ function TooltipContent({
26
20
  sideOffset = 6,
27
21
  align = 'center',
28
22
  alignOffset = 0,
23
+ children,
29
24
  ...props
30
25
  }: TooltipPrimitive.Popup.Props &
31
26
  Pick<TooltipPrimitive.Positioner.Props, 'align' | 'alignOffset' | 'side' | 'sideOffset'>) {
@@ -41,14 +36,16 @@ function TooltipContent({
41
36
  <TooltipPrimitive.Popup
42
37
  data-slot="tooltip-content"
43
38
  className={cn(
44
- 'z-50 origin-(--transform-origin) rounded-sm bg-popover px-2 py-1 text-xs font-medium text-popover-foreground shadow-md ring-1 ring-border outline-hidden duration-100 data-[side=bottom]:slide-in-from-top-1 data-[side=left]:slide-in-from-right-1 data-[side=right]:slide-in-from-left-1 data-[side=top]:slide-in-from-bottom-1 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95',
39
+ 'z-50 w-fit max-w-xs origin-(--transform-origin) items-center gap-1.5 rounded-sm bg-popover px-2.5 py-1.5 text-xs font-medium text-popover-foreground shadow-md has-data-[slot=kbd]:pr-1.5 data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 **:data-[slot=kbd]:relative **:data-[slot=kbd]:isolate **:data-[slot=kbd]:z-50 **:data-[slot=kbd]:rounded-sm data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95',
45
40
  className
46
41
  )}
47
42
  {...props}
48
- />
43
+ >
44
+ {children}
45
+ </TooltipPrimitive.Popup>
49
46
  </TooltipPrimitive.Positioner>
50
47
  </TooltipPrimitive.Portal>
51
48
  )
52
49
  }
53
50
 
54
- export { Tooltip, TooltipContent, TooltipTrigger }
51
+ export { Tooltip, TooltipContent, TooltipTrigger, TooltipProvider }
@@ -2,15 +2,22 @@ import { Component, type ErrorInfo, type ReactNode } from 'react'
2
2
 
3
3
  import { IconAlertTriangle } from '@tabler/icons-react'
4
4
 
5
- type Props = {
5
+ import { reportAppletError } from '@/client/features/applets/applet-log'
6
+ import type { AppletKind } from '@/lib/types'
7
+
8
+ type WidgetErrorBoundaryProps = {
6
9
  name: string
10
+ // Applet attribution for the error journal (docs/self-correction.md). The
11
+ // boundary wraps both widgets (WidgetShell) and views (WorkspaceScreen).
12
+ kind: AppletKind
13
+ workspaceId: string
7
14
  resetKey: number
8
15
  children: ReactNode
9
16
  }
10
17
 
11
18
  type State = { error: Error | null }
12
19
 
13
- export class WidgetErrorBoundary extends Component<Props, State> {
20
+ export class WidgetErrorBoundary extends Component<WidgetErrorBoundaryProps, State> {
14
21
  state: State = { error: null }
15
22
 
16
23
  static getDerivedStateFromError(error: Error): State {
@@ -19,9 +26,18 @@ export class WidgetErrorBoundary extends Component<Props, State> {
19
26
 
20
27
  componentDidCatch(error: Error, info: ErrorInfo) {
21
28
  console.error(`[widget:${this.props.name}]`, error, info.componentStack)
29
+ // Journal the crash so `moi debug logs` can surface it to the agent — the
30
+ // console line above dies in a console nobody reads.
31
+ reportAppletError(this.props.workspaceId, {
32
+ source: 'render',
33
+ kind: this.props.kind,
34
+ name: this.props.name,
35
+ message: error.message || String(error),
36
+ stack: [error.stack, info.componentStack].filter(Boolean).join('\n')
37
+ })
22
38
  }
23
39
 
24
- componentDidUpdate(prev: Props) {
40
+ componentDidUpdate(prev: WidgetErrorBoundaryProps) {
25
41
  if (prev.resetKey !== this.props.resetKey && this.state.error) {
26
42
  this.setState({ error: null })
27
43
  }
@@ -2,6 +2,7 @@ import { AnimatePresence, motion } from 'motion/react'
2
2
 
3
3
  import { AppletMount } from '@/client/features/applets/AppletMount'
4
4
  import { useWidget } from '@/client/features/applets/useApplet'
5
+ import { useWorkspaceId } from '@/client/features/workspace/WorkspaceContext'
5
6
 
6
7
  import { WidgetErrorBoundary } from './WidgetErrorBoundary'
7
8
 
@@ -10,6 +11,7 @@ type WidgetShellProps = {
10
11
  }
11
12
 
12
13
  export function WidgetShell({ name }: WidgetShellProps) {
14
+ const workspaceId = useWorkspaceId()
13
15
  const widget = useWidget(name)
14
16
 
15
17
  return (
@@ -23,7 +25,12 @@ export function WidgetShell({ name }: WidgetShellProps) {
23
25
  exit={{ opacity: 0, filter: 'blur(4px)' }}
24
26
  transition={{ duration: 0.45, ease: 'easeInOut' }}
25
27
  >
26
- <WidgetErrorBoundary name={name} resetKey={widget.version}>
28
+ <WidgetErrorBoundary
29
+ name={name}
30
+ kind="widget"
31
+ workspaceId={workspaceId}
32
+ resetKey={widget.version}
33
+ >
27
34
  <AppletMount segment="widgets" name={name} version={widget.version}>
28
35
  <widget.Component />
29
36
  </AppletMount>
@@ -0,0 +1,100 @@
1
+ import type { AppletClientError, AppletKind } from '@/lib/types'
2
+
3
+ // Fire-and-forget reporter for browser-side applet errors — the client half of
4
+ // the applet error journal (docs/self-correction.md). Failures only the user's
5
+ // tab sees (module load failures, render crashes, window errors attributed to
6
+ // a bundle) are POSTed into the workspace journal so `moi debug logs` can show
7
+ // them to the agent. Always on: when the user says "it's broken", the crash
8
+ // their tab saw five minutes ago is already on record.
9
+ //
10
+ // Reporting must never hurt the app: fetch errors are swallowed, and two
11
+ // throttles bound the network chatter. The per-error cooldown collapses a
12
+ // crash loop of the SAME error into one POST per window; the global cap
13
+ // bounds the total regardless of message — an error whose text varies every
14
+ // occurrence (timestamps, ids) would defeat key-based cooldown and server
15
+ // dedup alike, and a tight throw loop must not become a POST-per-frame storm.
16
+ // Drops are silent: the journal is best-effort diagnostics, not telemetry.
17
+ const COOLDOWN_MS = 5_000
18
+ const lastSent = new Map<string, number>()
19
+
20
+ const RATE_WINDOW_MS = 60_000
21
+ const RATE_MAX_PER_WINDOW = 30
22
+ let rateWindowStart = 0
23
+ let rateCount = 0
24
+
25
+ export function reportAppletError(workspaceId: string, event: AppletClientError): void {
26
+ const now = Date.now()
27
+
28
+ const key = [workspaceId, event.source, event.kind, event.name, event.message].join('\0')
29
+ const last = lastSent.get(key)
30
+ if (last !== undefined && now - last < COOLDOWN_MS) return
31
+
32
+ if (now - rateWindowStart >= RATE_WINDOW_MS) {
33
+ rateWindowStart = now
34
+ rateCount = 0
35
+ }
36
+ if (rateCount >= RATE_MAX_PER_WINDOW) return
37
+ rateCount++
38
+
39
+ lastSent.set(key, now)
40
+ // Bound the cooldown map: drop the oldest half if it ever balloons.
41
+ if (lastSent.size > 256) {
42
+ for (const k of [...lastSent.keys()].slice(0, 128)) lastSent.delete(k)
43
+ }
44
+ void fetch(`/api/workspaces/${workspaceId}/applet-log`, {
45
+ method: 'POST',
46
+ headers: { 'Content-Type': 'application/json' },
47
+ body: JSON.stringify({ events: [event] })
48
+ }).catch(() => {})
49
+ }
50
+
51
+ // Attribute a window-level error to an applet by a bundle URL: applet bundles
52
+ // load from `/api/workspaces/<id>/(widgets|views)/<name>/…`, so any reference
53
+ // to one pins the error to that applet — and carries the workspace id along.
54
+ // Host-app URLs never match; their errors are not the journal's business.
55
+ // Matched against ErrorEvent.filename (a bare URL) and stack-trace text, where
56
+ // segments stop at `/`, whitespace, or `)` because stack frame formats differ
57
+ // per browser (Chrome parenthesizes URLs, Firefox uses `fn@url`).
58
+ const BUNDLE_URL_RE = /\/api\/workspaces\/([^/\s)]+)\/(widgets|views)\/([^/\s)]+)\//
59
+
60
+ type BundleRef = { workspaceId: string; kind: AppletKind; name: string }
61
+
62
+ // Exported for tests.
63
+ export function matchBundleUrl(text: string | undefined): BundleRef | null {
64
+ if (!text) return null
65
+ const m = BUNDLE_URL_RE.exec(text)
66
+ if (!m) return null
67
+ return { workspaceId: m[1], kind: m[2] === 'widgets' ? 'widget' : 'view', name: m[3] }
68
+ }
69
+
70
+ let installed = false
71
+
72
+ // Catch errors that escape React entirely — event handlers, async effects,
73
+ // unawaited promises — which no error boundary sees. Installed once at startup.
74
+ export function installAppletErrorHook(): void {
75
+ if (installed) return
76
+ installed = true
77
+
78
+ const report = (ref: BundleRef | null, raw: unknown, fallbackMessage?: string) => {
79
+ const err = raw instanceof Error ? raw : null
80
+ const stack = err?.stack ?? ''
81
+ const hit = ref ?? matchBundleUrl(stack)
82
+ if (!hit) return
83
+ reportAppletError(hit.workspaceId, {
84
+ source: 'window',
85
+ kind: hit.kind,
86
+ name: hit.name,
87
+ message: err?.message || fallbackMessage || String(raw),
88
+ ...(stack ? { stack } : {})
89
+ })
90
+ }
91
+
92
+ // Fast path for 'error' events: ErrorEvent.filename is the structured URL of
93
+ // the script whose top frame threw — no stack-text parsing, no per-browser
94
+ // format quirks, and it works even for throws with no usable stack
95
+ // (`throw 'string'`). The stack scan remains the fallback (e.g. an applet
96
+ // handler that threw inside vendor code, where filename names the vendor
97
+ // chunk) and the only path for promise rejections, which carry no filename.
98
+ window.addEventListener('error', e => report(matchBundleUrl(e.filename), e.error, e.message))
99
+ window.addEventListener('unhandledrejection', e => report(null, e.reason))
100
+ }
@@ -9,8 +9,10 @@ import {
9
9
  invalidateApplet,
10
10
  setCachedApplet
11
11
  } from '@/client/features/applets/applet-cache'
12
+ import { reportAppletError } from '@/client/features/applets/applet-log'
12
13
  import { useWorkspaceId } from '@/client/features/workspace/WorkspaceContext'
13
14
  import { type WorkspaceEvent, useWorkspaceEvent } from '@/client/runtime/useWorkspaceEvents'
15
+ import type { AppletKind } from '@/lib/types'
14
16
 
15
17
  type AppletState =
16
18
  | { status: 'loading'; version: number }
@@ -21,19 +23,22 @@ type AppletState =
21
23
  // MEI events tell it to reload. Everything else — dynamic import, caching,
22
24
  // cache-busting — is shared. An applet is an agent-authored UI unit loaded as an
23
25
  // ESM module and mounted into the workspace.
24
- type AppletKind = {
26
+ type AppletKindSpec = {
27
+ kind: AppletKind
25
28
  segment: AppletSegment
26
29
  // True when this MEI event means the named applet should cache-bust + reload.
27
30
  shouldReload: (event: WorkspaceEvent, name: string) => boolean
28
31
  }
29
32
 
30
- const WIDGET_KIND: AppletKind = {
33
+ const WIDGET_KIND: AppletKindSpec = {
34
+ kind: 'widget',
31
35
  segment: 'widgets',
32
36
  shouldReload: (e, name) =>
33
37
  (e.type === 'widget:updated' && e.name === name) || e.type === 'widgets:refresh'
34
38
  }
35
39
 
36
- const VIEW_KIND: AppletKind = {
40
+ const VIEW_KIND: AppletKindSpec = {
41
+ kind: 'view',
37
42
  segment: 'views',
38
43
  shouldReload: (e, name) => e.type === 'view:updated' && e.name === name
39
44
  }
@@ -59,7 +64,7 @@ function loadApplet(
59
64
  return promise
60
65
  }
61
66
 
62
- function useApplet(kind: AppletKind, name: string): AppletState {
67
+ function useApplet(kind: AppletKindSpec, name: string): AppletState {
63
68
  const workspaceId = useWorkspaceId()
64
69
  const [state, setState] = useState<AppletState>({ status: 'loading', version: 0 })
65
70
 
@@ -69,10 +74,19 @@ function useApplet(kind: AppletKind, name: string): AppletState {
69
74
  .then(Component =>
70
75
  setState(prev => ({ status: 'ready', Component, version: prev.version + 1 }))
71
76
  )
72
- .catch(err =>
77
+ .catch(err => {
78
+ // Journal the load failure so `moi debug logs` can surface it to the
79
+ // agent — otherwise only this tab ever sees it (docs/self-correction.md).
80
+ reportAppletError(workspaceId, {
81
+ source: 'load',
82
+ kind: kind.kind,
83
+ name,
84
+ message: String(err),
85
+ ...(err instanceof Error && err.stack ? { stack: err.stack } : {})
86
+ })
73
87
  setState(prev => ({ status: 'error', error: String(err), version: prev.version + 1 }))
74
- )
75
- }, [kind.segment, workspaceId, name])
88
+ })
89
+ }, [kind, workspaceId, name])
76
90
 
77
91
  useEffect(() => {
78
92
  load()