moi-computer 0.0.3 → 0.1.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 (214) hide show
  1. package/bunfig.toml +4 -0
  2. package/client/api/workspaces.ts +277 -6
  3. package/client/assets/mcp/agentation.png +0 -0
  4. package/client/assets/mcp/airtable.png +0 -0
  5. package/client/assets/mcp/apollo.png +0 -0
  6. package/client/assets/mcp/asana.png +0 -0
  7. package/client/assets/mcp/box.png +0 -0
  8. package/client/assets/mcp/chrome.svg +33 -0
  9. package/client/assets/mcp/clickup.png +0 -0
  10. package/client/assets/mcp/cloudflare.png +0 -0
  11. package/client/assets/mcp/context7.png +0 -0
  12. package/client/assets/mcp/datadog.png +0 -0
  13. package/client/assets/mcp/dropbox.png +0 -0
  14. package/client/assets/mcp/elevenlabs.png +0 -0
  15. package/client/assets/mcp/exa.png +0 -0
  16. package/client/assets/mcp/firecrawl.png +0 -0
  17. package/client/assets/mcp/gmail.png +0 -0
  18. package/client/assets/mcp/googlecalendar.png +0 -0
  19. package/client/assets/mcp/googledrive.png +0 -0
  20. package/client/assets/mcp/grafana.png +0 -0
  21. package/client/assets/mcp/huggingface.png +0 -0
  22. package/client/assets/mcp/intercom.png +0 -0
  23. package/client/assets/mcp/monday.png +0 -0
  24. package/client/assets/mcp/mongodb.png +0 -0
  25. package/client/assets/mcp/paper.png +0 -0
  26. package/client/assets/mcp/paypal.png +0 -0
  27. package/client/assets/mcp/perplexity.png +0 -0
  28. package/client/assets/mcp/postgresql.png +0 -0
  29. package/client/assets/mcp/posthog.png +0 -0
  30. package/client/assets/mcp/puppeteer.png +0 -0
  31. package/client/assets/mcp/railway.png +0 -0
  32. package/client/assets/mcp/redis.png +0 -0
  33. package/client/assets/mcp/salesforce.png +0 -0
  34. package/client/assets/mcp/shopify.png +0 -0
  35. package/client/assets/mcp/snowflake.png +0 -0
  36. package/client/assets/mcp/telegram.png +0 -0
  37. package/client/assets/mcp/twilio.png +0 -0
  38. package/client/assets/mcp/zapier.png +0 -0
  39. package/client/components/App.tsx +7 -1
  40. package/client/components/ChatInput.tsx +194 -13
  41. package/client/components/ChatPanel.tsx +116 -47
  42. package/client/components/ChatPopup.tsx +1 -1
  43. package/client/components/IconMcp.tsx +21 -0
  44. package/client/components/McpMenu.tsx +125 -0
  45. package/client/components/ModelPicker.tsx +147 -0
  46. package/client/components/Scratchpad.tsx +775 -0
  47. package/client/components/ShimmerText.tsx +20 -0
  48. package/client/components/ThreadSelector.tsx +2 -2
  49. package/client/components/TurnView.tsx +111 -531
  50. package/client/components/WidgetShell.tsx +1 -1
  51. package/client/components/WorkspacesPage.tsx +12 -4
  52. package/client/components/layout/SidebarLayout.tsx +18 -9
  53. package/client/components/playground/ToolCallsPage.tsx +81 -0
  54. package/client/components/routes/workspace/[id].tsx +534 -141
  55. package/client/components/routes/workspace/create.tsx +155 -0
  56. package/client/components/settings/IconPicker.tsx +590 -0
  57. package/client/components/settings/SettingsPages.tsx +307 -0
  58. package/client/components/settings/WorkspaceSettings.tsx +92 -0
  59. package/client/components/tool-group/CodeBlock.tsx +41 -0
  60. package/client/components/tool-group/Collapse.tsx +28 -0
  61. package/client/components/tool-group/ReadImagePreview.tsx +46 -0
  62. package/client/components/tool-group/SubagentCard.tsx +135 -0
  63. package/client/components/tool-group/TimelineRow.tsx +147 -0
  64. package/client/components/tool-group/ToolCallGroup.tsx +231 -0
  65. package/client/components/tool-group/ToolOutput.tsx +139 -0
  66. package/client/components/tool-group/detect.ts +93 -0
  67. package/client/components/tool-group/fixtures.ts +315 -0
  68. package/client/components/tool-group/format.ts +211 -0
  69. package/client/components/tool-group/index.ts +9 -0
  70. package/client/components/ui/dialog.tsx +58 -0
  71. package/client/components/ui/hover-card.tsx +44 -0
  72. package/client/components/ui/switch.tsx +23 -0
  73. package/client/components/ui/tooltip.tsx +54 -0
  74. package/client/externalize-react.ts +6 -0
  75. package/client/hooks/useApplet.ts +117 -0
  76. package/client/hooks/useChat.ts +162 -62
  77. package/client/hooks/useMeiEvents.ts +9 -2
  78. package/client/hooks/useStickToBottom.ts +86 -0
  79. package/client/hooks/useWorkspaceTheme.ts +8 -2
  80. package/client/index.css +48 -2
  81. package/client/index.html +9 -5
  82. package/client/index.tsx +29 -2
  83. package/client/lib/WorkspaceContext.tsx +5 -8
  84. package/client/lib/WorkspaceLayoutContext.tsx +30 -10
  85. package/client/lib/applet-cache.ts +54 -0
  86. package/client/lib/connection.ts +237 -0
  87. package/client/lib/flags.ts +10 -0
  88. package/client/lib/mcp-icons.ts +142 -10
  89. package/client/lib/preview-turn.ts +37 -0
  90. package/client/lib/render-icon.ts +173 -0
  91. package/client/lib/scratch-executor.ts +20 -0
  92. package/client/lib/uploads.ts +18 -0
  93. package/client/main.tsx +5 -0
  94. package/client/store/live.ts +282 -0
  95. package/client/structured-clone-shim.ts +14 -0
  96. package/client/theme.css +2 -2
  97. package/client/vendor/emojibase/en/data.json +1 -0
  98. package/client/vendor/emojibase/en/messages.json +1 -0
  99. package/client/vendor/react/development/_impl/react-dom-client.js +15871 -0
  100. package/client/vendor/react/development/_impl/react-dom.js +223 -0
  101. package/client/vendor/react/development/_impl/react-jsx-dev-runtime.js +256 -0
  102. package/client/vendor/react/development/_impl/react-jsx-runtime.js +260 -0
  103. package/client/vendor/react/development/_impl/react.js +863 -0
  104. package/client/vendor/react/development/react-dom-client.js +6 -0
  105. package/client/vendor/react/development/react-dom.js +17 -0
  106. package/client/vendor/react/development/react-jsx-dev-runtime.js +5 -0
  107. package/client/vendor/react/development/react-jsx-runtime.js +6 -0
  108. package/client/vendor/react/development/react.js +47 -0
  109. package/client/vendor/react/production/_impl/react-dom-client.js +10361 -0
  110. package/client/vendor/react/production/_impl/react-dom.js +184 -0
  111. package/client/vendor/react/production/_impl/react-jsx-dev-runtime.js +37 -0
  112. package/client/vendor/react/production/_impl/react-jsx-runtime.js +60 -0
  113. package/client/vendor/react/production/_impl/react.js +428 -0
  114. package/client/vendor/react/production/react-dom-client.js +6 -0
  115. package/client/vendor/react/production/react-dom.js +17 -0
  116. package/client/vendor/react/production/react-jsx-dev-runtime.js +5 -0
  117. package/client/vendor/react/production/react-jsx-runtime.js +6 -0
  118. package/client/vendor/react/production/react.js +47 -0
  119. package/dist/agentation-4s0nn45p.png +0 -0
  120. package/dist/airtable-hsa66v6q.png +0 -0
  121. package/dist/apollo-2ed5dy2d.png +0 -0
  122. package/dist/asana-tvgtwbx2.png +0 -0
  123. package/dist/box-w3n36t5g.png +0 -0
  124. package/dist/chrome-tspm94rw.svg +33 -0
  125. package/dist/chunk-kc6e9nd4.css +1 -0
  126. package/dist/chunk-yf3p7qg7.js +673 -0
  127. package/dist/clickup-qqrqqvqb.png +0 -0
  128. package/dist/cloudflare-j9p931v6.png +0 -0
  129. package/dist/context7-8ht0xjfy.png +0 -0
  130. package/dist/datadog-70ne3yzt.png +0 -0
  131. package/dist/dropbox-4m5s9mgr.png +0 -0
  132. package/dist/elevenlabs-2nzzej1t.png +0 -0
  133. package/dist/exa-qqj3vr0x.png +0 -0
  134. package/dist/firecrawl-w2t8nehx.png +0 -0
  135. package/dist/gmail-sg6a5v3x.png +0 -0
  136. package/dist/googlecalendar-nqhh2v7r.png +0 -0
  137. package/dist/googledrive-6s8xyab7.png +0 -0
  138. package/dist/grafana-1yfsnwr6.png +0 -0
  139. package/dist/huggingface-kxzaxj83.png +0 -0
  140. package/dist/index.html +10 -6
  141. package/dist/intercom-td763jt8.png +0 -0
  142. package/dist/monday-jdbs4wwf.png +0 -0
  143. package/dist/mongodb-emzxvhd5.png +0 -0
  144. package/dist/paper-zbt34fab.png +0 -0
  145. package/dist/paypal-kwwf7xsc.png +0 -0
  146. package/dist/perplexity-4y63rxvj.png +0 -0
  147. package/dist/postgresql-qsspbsr1.png +0 -0
  148. package/dist/posthog-sphppc4w.png +0 -0
  149. package/dist/puppeteer-2xjt1a9b.png +0 -0
  150. package/dist/railway-834de8d2.png +0 -0
  151. package/dist/redis-spm6w2m1.png +0 -0
  152. package/dist/salesforce-1mk56v4z.png +0 -0
  153. package/dist/shopify-90dadaav.png +0 -0
  154. package/dist/snowflake-hfpykpgy.png +0 -0
  155. package/dist/telegram-v6tjyrs7.png +0 -0
  156. package/dist/twilio-dpyjdwpj.png +0 -0
  157. package/dist/zapier-p67qfch0.png +0 -0
  158. package/lib/attachment-note.ts +48 -0
  159. package/lib/claude-adapter.ts +219 -29
  160. package/lib/format.ts +32 -0
  161. package/lib/types.ts +314 -6
  162. package/package.json +10 -5
  163. package/server/CLAUDE.md +3 -0
  164. package/server/agent.ts +25 -118
  165. package/server/api.ts +593 -0
  166. package/server/applets.ts +396 -0
  167. package/server/build-applet.ts +580 -0
  168. package/server/cc-session.ts +611 -0
  169. package/server/cli-colors.ts +17 -0
  170. package/server/cli-ui.ts +52 -0
  171. package/server/cli.ts +964 -72
  172. package/server/control.ts +166 -19
  173. package/server/debug.ts +10 -0
  174. package/server/events.ts +24 -0
  175. package/server/functions-worker.ts +18 -2
  176. package/server/functions.ts +59 -12
  177. package/server/icon.ts +13 -0
  178. package/server/layout.ts +25 -3
  179. package/server/mcp.ts +125 -0
  180. package/server/moi-scaffold.ts +85 -0
  181. package/server/openclaw-session.ts +41 -10
  182. package/server/openclaw.ts +22 -0
  183. package/server/preview.ts +70 -0
  184. package/server/registry.ts +32 -2
  185. package/server/scratchpad-executor.ts +380 -0
  186. package/server/scratchpad-relay.ts +45 -0
  187. package/server/scratchpad.ts +171 -0
  188. package/server/skill-version.ts +146 -0
  189. package/server/skills-template.ts +6 -1
  190. package/server/state.ts +22 -36
  191. package/server/static.ts +23 -0
  192. package/server/status.ts +94 -0
  193. package/server/thread-config.ts +125 -0
  194. package/server/uploads.ts +0 -0
  195. package/server/vendor.ts +63 -0
  196. package/server/views.ts +0 -0
  197. package/server/web.ts +108 -253
  198. package/server/widgets.ts +52 -142
  199. package/server/workspace-config.ts +37 -0
  200. package/server/workspace-env.ts +407 -0
  201. package/server/workspace-init.ts +66 -0
  202. package/workspace/.claude/skills/moi-workspace/DESIGN.md +109 -0
  203. package/workspace/.claude/skills/moi-workspace/SCRATCHPAD.md +57 -0
  204. package/workspace/.claude/skills/moi-workspace/SKILL.md +252 -0
  205. package/workspace/.claude/skills/moi-workspace/VIEW-DESIGN.md +22 -0
  206. package/client/hooks/useWidget.ts +0 -72
  207. package/client/hooks/useWidgetList.ts +0 -30
  208. package/client/lib/ws.ts +0 -129
  209. package/client/store/chat.tsx +0 -162
  210. package/dist/chunk-4615fa69.js +0 -67
  211. package/dist/chunk-582xmy05.css +0 -1
  212. package/server/build-widget.ts +0 -343
  213. package/workspace/.claude/skills/widgets/DESIGN.md +0 -630
  214. package/workspace/.claude/skills/widgets/SKILL.md +0 -176
@@ -0,0 +1,252 @@
1
+ ---
2
+ name: moi-workspace
3
+ description: The moi workspace — the web UI the user chats from, extended with agent-authored applets (widgets, views) plus theme & config. Read this FIRST in two cases. (a) A message carries hidden <moi>…</moi> meta tags: it was fired from a moi workspace, so you are running inside one even if nothing else says so. (b) The user uses moi vocab — workspace, applet, widget, view, scratchpad, dashboard, or a `moi` command — or asks to build, edit, customize, or theme the workspace UI or its layout.
4
+ ---
5
+
6
+ # Workspace
7
+
8
+ You are working inside a **moi workspace**. It is a web UI that the user communicates with you
9
+ through. It has regular chat (this one), as well as custom UI elements that you can define, write,
10
+ and change to tailor the workspace to user needs. It starts with a simple chat, but evolves into a
11
+ personal app equipped with a copilot (you). Workspace is a two-way communication: you can build the
12
+ UI, user can interact with it, send feedback, modify state, then talk back to you. It's a shared UI
13
+ that you and user work together in.
14
+
15
+ Workspace features/pages:
16
+
17
+ - "Widgets" - small reusable full-stack components displayed on the widgets page (dashboard). For
18
+ overview, quick info, status or quick actions.
19
+ - "Scratchpad" - a shared low-fi canvas for prototyping, working on ideas together, visualising
20
+ concepts. Read `SCRATCHPAD.md` before building on or modifying it.
21
+ - "Views" - full-stack embedded apps for bigger work, consume more space, live in their own tab.
22
+
23
+ User can switch between these, but can access the chat (this conversation and other threads) from
24
+ **any place in the app** (copilot mode), or on a dedicated page.
25
+
26
+ Workspace settings and customisation:
27
+
28
+ - "Config": set name, icon, change other settings. User can modify these from the UI and you can do
29
+ it via the `moi config` command. Call `moi config --help` for further docs.
30
+ - "Theme": customize workspace fonts, colors, visual appearance. User can modify these from the UI
31
+ and you can do it via the `moi theme` command. Call `moi theme --help` for further docs.
32
+
33
+ # Glossary
34
+
35
+ "Workspace" or "Moi Workspace" — the web UI that the user works in, talks/collaborates with you,
36
+ sees and interacts with "Applets".
37
+
38
+ "Project" - the primary working folder _you_ (as an agent) work in. Managed by your harness; moi
39
+ does not have a clear definition, but assumes this is the root folder in which it stores its state
40
+ files.
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
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
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.
48
+
49
+ "Applets" are standalone full-stack components that _you_ write and maintain. They extend the
50
+ Workspace UI.
51
+
52
+ "Applet Type" (one of)
53
+
54
+ - "Widgets" (live in the dashboard page)
55
+ - "Views" are custom full-size pages that user can switch between.
56
+
57
+ "Moi CLI" — the globally installed `moi` command that you use to build applets, customize, and send
58
+ events to "Workspace".
59
+
60
+ # Where moi lives in filesystem
61
+
62
+ Source of truth - `.moi` folder in the root of "Project" folder. Contains source code of all
63
+ Applets, bundled code, settings, etc. Can be committed to version control. Folder is partially
64
+ initialised when Workspace starts, you have full ownership of it.
65
+
66
+ You _do have_ access to the files in the root of Project — you can reference and load them from the
67
+ "Applets" and elsewhere.
68
+
69
+ Folder structure:
70
+
71
+ ```
72
+ my-agent-folder/
73
+ .moi/
74
+ widgets/ <- source code of Widget React components
75
+ total-users.tsx
76
+ rps-chart.tsx
77
+ server-metrics.server.ts <- Server-side async functions the widget can call (optional)
78
+ ...
79
+ views/
80
+ users.tsx
81
+ crm.tsx
82
+ users-api.server.ts <- Server-side async functions the view can call (optional)
83
+ ...
84
+ package.json <- Applet dependencies that you manage
85
+ .workspace.json <- Auto-generated. Do NOT read, edit, or `cat` this file. Use Moi CLI instead.
86
+ .scratchpad.json <- Scratchpad canvas snapshot. Internal — inspect only via `moi scratch read`, never open it.
87
+ ```
88
+
89
+ # Build environment
90
+
91
+ - Bun is the required dependency of moi, so it must be installed
92
+ - For package management **always** use bun
93
+ - package.json is scaffolded during init. You are free to install/remove/do whatever with packages.
94
+ - if packages aren't installed, it's your responsibility to call `bun install`
95
+ - `react` and `react-dom` are stubs — they're provided by moi at runtime via the browser importmap.
96
+ They're listed only so editors pick up the correct types.
97
+ - `moi bundle` runs **Bun's bundler**, so standard Bun imports, loaders, and tricks apply (JSON,
98
+ text, etc.) — see the Bun docs. Only the moi-specific imports (covered under **Developing
99
+ Applets**) differ.
100
+
101
+ # `moi` CLI
102
+
103
+ Treat `moi` as an external command — you cannot inspect or modify its sources. Use only the
104
+ documented subcommands (`moi bundle`, `moi bundle --force`, etc.). Call `moi help` for
105
+ documentation. Run all `moi` commands from the **project root** — the folder that contains `.moi/`,
106
+ never from inside `.moi/` itself. You don't pass paths; moi resolves the workspace from where it's run.
107
+
108
+ - `moi bundle` — compile changed applets
109
+ - `moi bundle --force` — rebuild all applets (use after changing `config`)
110
+ - `moi refresh` — re-fetch widget/view data without rebuilding (use after you mutated data the
111
+ widgets read — DB rows, files, external API records — so the displayed values catch up)
112
+ - `moi theme --font=<key>` — change font theme (omit `--font` to list options)
113
+ - `moi theme --color=<key>` — change color preset (omit `--color` to list options)
114
+ - `moi config` — set the workspace name & icon (`moi config --help` for usage)
115
+ - `moi skill` — show installed vs bundled skill versions; `moi skill update` to refresh
116
+
117
+ For more options, commands, use `moi help`.
118
+
119
+ # Critical constraints when interacting with moi
120
+
121
+ - Never read or modify files outside the `.moi` directory, unless the user explicitly asks. If you
122
+ do need it -> ask for permission.
123
+ - Do **not** start, stop, or inspect the Workspace web server — it is managed externally.
124
+
125
+ # Developing Applets
126
+
127
+ Every applet — a **Widget** or a **View** — is a default-exported React component in
128
+ `.moi/<type>/<name>.tsx`, optionally paired with a `<name>.server.ts`. `moi bundle` compiles each
129
+ into a live module the browser loads (edits hot-reload). Read `DESIGN.md` / `VIEW-DESIGN.md` first.
130
+ Write normal React + Tailwind — below is only what's **moi-specific**.
131
+
132
+ ## Anatomy
133
+
134
+ ```tsx
135
+ // .moi/widgets/hello.tsx
136
+ import { useEffect, useState } from 'react'
137
+ import { getGreeting } from './hello.server' // optional server fn — see below
138
+
139
+ // Optional config — fields are per type (see Widgets / Views below). requiredEnv is shared.
140
+ export const config = { requiredEnv: ['API_KEY'] }
141
+
142
+ export default function Hello() {
143
+ const [msg, setMsg] = useState('')
144
+ useEffect(() => {
145
+ getGreeting().then(setMsg) // call server fns like any async function
146
+ }, [])
147
+ return <div className="h-full w-full p-4">{msg}</div>
148
+ }
149
+ ```
150
+
151
+ Imports resolve from the same folder or `.moi/package.json` deps only — no `@/` aliases.
152
+
153
+ ## Server functions — `<name>.server.ts`
154
+
155
+ Export named `async function`s (only — no `const`, sync, or class) and call them from the component
156
+ like ordinary async functions; arguments and return values are auto-serialized (`Date`, `Map`,
157
+ `Set`, … work). They run on the Bun server with `process.env` and full filesystem access, at
158
+ `cwd = <workspace root>` (the parent of `.moi/`, where you operate) — so workspace files are plain
159
+ relative paths:
160
+
161
+ ```ts
162
+ // hello.server.ts — read files, call APIs, query DBs…
163
+ export async function getGreeting(): Promise<string> {
164
+ return (await Bun.file('./notes.md').text()).split('\n')[0]
165
+ }
166
+ ```
167
+
168
+ The component fetches on mount; after you change underlying data a server fn reads, run
169
+ `moi refresh` to re-pull it without a rebuild.
170
+
171
+ It's plain Bun — every Bun API is available with no setup: `bun:sqlite`, `Bun.redis`, `Bun.s3`,
172
+ `Bun.file`, `fetch`, …
173
+
174
+ ## Workspace files & assets
175
+
176
+ - **Bundled asset** — `import logo from './logo.png'` resolves to a URL at build time (images &
177
+ fonts: `png jpg gif svg webp avif ico woff woff2 ttf otf`). For small art shipped beside the
178
+ `.tsx`.
179
+ - **Workspace file** — stream a file from the workspace via `fileUrl` from the **`moi`** package:
180
+
181
+ ```tsx
182
+ import { fileUrl } from 'moi'
183
+ ;<video src={fileUrl('clips/intro.mp4')} controls />
184
+ ```
185
+
186
+ `fileUrl(path)` maps a **workspace-root-relative** path to a streaming URL (HTTP range — media
187
+ seeks, nothing is base64-inlined). Media/asset extensions only; `.env`, source, JSON and dotfiles
188
+ are rejected. The path is plain data, so a `.server.ts` can return it and the component renders
189
+ `fileUrl(clip.file)`.
190
+
191
+ Rule of thumb: small own art → `import`; structured data → `.server.ts` returns it; large/streamable
192
+ media → `.server.ts` returns the **path**, render with `fileUrl()`.
193
+
194
+ ## Environment & secrets
195
+
196
+ `process.env` is readable **only** inside `.server.ts` (the `.tsx` runs in the browser) — keep API
197
+ keys there. moi injects per-workspace **custom secrets** and optionally-inherited **`.env`** values;
198
+ either may be absent, so always handle a missing key. List expected keys in `config.requiredEnv` —
199
+ advisory only (it surfaces a hint in the UI; it's never enforced).
200
+
201
+ ```ts
202
+ const key = process.env.ELEVENLABS_API_KEY
203
+ if (!key) throw new Error('ELEVENLABS_API_KEY not set')
204
+ ```
205
+
206
+ # Widgets
207
+
208
+ Live cards on the dashboard grid — many visible at once. `config` sets the grid footprint:
209
+
210
+ ```ts
211
+ export const config = {
212
+ colSpan: 2, // columns the card spans — 1–4
213
+ rowSpan: 1, // rows the card spans — 1–4
214
+ requiredEnv: ['API_KEY'] // optional env-key hints (advisory; see Environment & secrets)
215
+ } as const
216
+ ```
217
+
218
+ Render **content only**: a plain `h-full w-full` region with no card chrome (`rounded-*`,
219
+ `shadow-*`, outer `border`, or a card-like background) — the dashboard owns the shell, spacing, and
220
+ elevation. Changing `colSpan`/`rowSpan` needs `moi bundle --force`. See `DESIGN.md`.
221
+
222
+ Typical loop: check/`bun install` deps → write `.moi/widgets/<name>.tsx` → `moi bundle` → it appears
223
+ on the dashboard → change it and re-`bundle`, or `moi refresh` after mutating data, or any other `moi`
224
+ command as needed. Views work the same way (`.moi/views/<name>.tsx`, appears as a nav tab).
225
+
226
+ # Views
227
+
228
+ Full-screen apps, one per nav tab — the user switches tabs; there is no routing inside a view.
229
+
230
+ ```ts
231
+ export const config = {
232
+ title: 'User CRM', // nav-tab label — defaults to the file name
233
+ requiredEnv: ['CRM_API_KEY'] // optional env-key hints (advisory; see Environment & secrets)
234
+ } as const
235
+ ```
236
+
237
+ The inverse of a widget: a view **owns its whole page** — its own `h-full w-full` layout, scrolling
238
+ (`overflow-auto`), padding, and chrome. Build it to read like an app screen. See `VIEW-DESIGN.md`.
239
+
240
+ # Keeping this skill current
241
+
242
+ This skill is installed with moi (via the CLI or the UI) and can fall behind when the moi CLI updates.
243
+
244
+ - **You'll know** — `moi` commands warn you when this skill is behind.
245
+ - **To update** — run `moi skill update`. Never mid-task: finish first, or do it at the end.
246
+ - **Re-read after updating** — `moi skill update` rewrites `SKILL.md` and its companion docs
247
+ (`DESIGN.md`, `VIEW-DESIGN.md`, `SCRATCHPAD.md`) on disk, so the copy already in your context is
248
+ stale. Re-read this `SKILL.md` before you rely on it again — don't act on the old version.
249
+ - **Then** — if you updated, mention it.
250
+
251
+ <!-- moi skill version marker — read by `moi skill` to detect drift; do not edit by hand -->
252
+ <moi-skill version="0.3.0" />
@@ -0,0 +1,22 @@
1
+ View design guidelines. Read before creating or modifying any view.
2
+
3
+ ## The one idea
4
+
5
+ A view is a **real app screen**, not a giant widget. Where a widget earns one glanceable moment, a view earns **structure**: a clear header, a primary work area, and a calm, scannable layout the user can sit inside for minutes, not seconds. It should look like a page someone designed on purpose — never a naked card stretched to fill the screen.
6
+
7
+ ## Rules — never break
8
+
9
+ - **Own the whole frame.** The root is `w-full h-full` and handles **its own scrolling** (`overflow-auto`) — there is no outer scroll container. Provide your own padding, header, and chrome.
10
+ - **One view = one screen.** No client-side routing inside a view; cross-screen navigation is the workspace nav. Internal sub-navigation (tabs, a master/detail split) is yours to build.
11
+ - **Three states, always.** Loading → a skeleton that mirrors the real layout (never a spinner). Error → one human sentence + a retry. Empty → a short prompt, never blank.
12
+ - **Tailwind for static styling.** No custom CSS, no `@apply`, no static `style={{}}`. Icons only from `@tabler/icons-react`. Views import only from their own folder.
13
+
14
+ ## Layout
15
+
16
+ - Give the page a **header band** (title, optional subtitle or primary action) and a **content region** below it. Constrain wide content with a max width and center it (`mx-auto max-w-…`) rather than letting tables and forms run edge to edge.
17
+ - Use generous, consistent padding (`p-6`/`p-8`). A view has room a widget never does — use whitespace and grouping, not dividers, to create structure.
18
+ - Tables, boards, and lists are the natural view shapes. Bounded internal scrollers (a sticky header over a scrolling table, a horizontal kanban) are fine; the page itself never scrolls sideways.
19
+
20
+ ## Visual language
21
+
22
+ Color, type, motion, and the state patterns are **the same vocabulary as widgets** — see `DESIGN.md` for tokens, color anchors, and motion ranking. A view should feel like the same family as the workspace's widgets: shared hero font, shared accent colors, the same restraint. The difference is scale, not style.
@@ -1,72 +0,0 @@
1
- import type { ComponentType } from 'react'
2
- import { useCallback, useEffect, useState } from 'react'
3
-
4
- import { useWorkspaceId } from '@/client/lib/WorkspaceContext'
5
-
6
- import { useMeiEvent } from './useMeiEvents'
7
-
8
- type WidgetState =
9
- | { status: 'loading'; version: number }
10
- | { status: 'ready'; Component: ComponentType; version: number }
11
- | { status: 'error'; error: string; version: number }
12
-
13
- const moduleCache = new Map<string, Promise<ComponentType>>()
14
- let version = 0
15
-
16
- function loadWidget(workspaceId: string, name: string, bust: boolean): Promise<ComponentType> {
17
- const key = `${workspaceId}/${name}`
18
- if (bust) {
19
- moduleCache.delete(key)
20
- version++
21
- }
22
-
23
- const existing = moduleCache.get(key)
24
- if (existing) return existing
25
-
26
- // Cache-busting query param so the browser fetches fresh
27
- const url = `/api/workspaces/${workspaceId}/widgets/${name}.js?v=${version}`
28
- const promise = import(/* @vite-ignore */ url).then(mod => {
29
- if (!mod.default) throw new Error(`Widget "${name}" has no default export`)
30
- return mod.default as ComponentType
31
- })
32
-
33
- moduleCache.set(key, promise)
34
- return promise
35
- }
36
-
37
- export function useWidget(name: string): WidgetState {
38
- const workspaceId = useWorkspaceId()
39
- const [state, setState] = useState<WidgetState>({ status: 'loading', version: 0 })
40
-
41
- const load = useCallback(
42
- (bust = false) => {
43
- setState(prev => ({ status: 'loading', version: prev.version }))
44
- loadWidget(workspaceId, name, bust)
45
- .then(Component =>
46
- setState(prev => ({ status: 'ready', Component, version: prev.version + 1 }))
47
- )
48
- .catch(err =>
49
- setState(prev => ({ status: 'error', error: String(err), version: prev.version + 1 }))
50
- )
51
- },
52
- [workspaceId, name]
53
- )
54
-
55
- useEffect(() => {
56
- load()
57
- }, [load])
58
-
59
- // Reload when server says this widget was updated, OR when the agent
60
- // triggered a global data refresh (`moi refresh`). Both paths cache-bust
61
- // the import URL so the component remounts and useEffect-driven `rpc()`
62
- // calls re-execute against fresh data.
63
- useMeiEvent(event => {
64
- if (event.type === 'widget:updated' && event.name === name) {
65
- load(true)
66
- } else if (event.type === 'widgets:refresh') {
67
- load(true)
68
- }
69
- })
70
-
71
- return state
72
- }
@@ -1,30 +0,0 @@
1
- import { useCallback, useEffect, useState } from 'react'
2
-
3
- import { useWorkspaceId } from '@/client/lib/WorkspaceContext'
4
- import type { WidgetInfo } from '@/lib/types'
5
-
6
- import { useMeiEvent } from './useMeiEvents'
7
-
8
- export function useWidgetList(): WidgetInfo[] {
9
- const workspaceId = useWorkspaceId()
10
- const [widgets, setWidgets] = useState<WidgetInfo[]>([])
11
-
12
- const fetchList = useCallback(() => {
13
- fetch(`/api/workspaces/${workspaceId}/widgets`)
14
- .then(r => r.json())
15
- .then(data => setWidgets(data.widgets))
16
- .catch(() => setWidgets([]))
17
- }, [workspaceId])
18
-
19
- useEffect(() => {
20
- fetchList()
21
- }, [fetchList])
22
-
23
- useMeiEvent(event => {
24
- if (event.type === 'widget-layout:updated') {
25
- fetchList()
26
- }
27
- })
28
-
29
- return widgets
30
- }
package/client/lib/ws.ts DELETED
@@ -1,129 +0,0 @@
1
- import type { ChatStoreApi } from '@/client/store/chat'
2
- import type { ClientMessage, StreamEvent } from '@/lib/types'
3
-
4
- let ws: WebSocket | null = null
5
- let reconnectTimer: ReturnType<typeof setTimeout> | null = null
6
- let currentWorkspaceId = ''
7
- let hasConnectedBefore = false
8
- // The chat store for the connected workspace. Passed in by `useChat` (the store
9
- // is per-workspace now), so this non-React layer writes into the right instance
10
- // instead of a global singleton.
11
- let chatStore: ChatStoreApi | null = null
12
- const queue: ClientMessage[] = []
13
-
14
- export function connectWs(workspaceId: string, store: ChatStoreApi) {
15
- // Reconnect if workspace changed
16
- if (ws && currentWorkspaceId !== workspaceId) disconnectWs()
17
- chatStore = store
18
- if (ws) return
19
-
20
- currentWorkspaceId = workspaceId
21
-
22
- if (reconnectTimer) {
23
- clearTimeout(reconnectTimer)
24
- reconnectTimer = null
25
- }
26
-
27
- const socket = new WebSocket(
28
- `ws://${location.host}/ws?workspace=${encodeURIComponent(workspaceId)}`
29
- )
30
-
31
- socket.onopen = () => {
32
- ws = socket
33
- for (const msg of queue) socket.send(JSON.stringify(msg))
34
- queue.length = 0
35
- // Reconnect after a drop: re-pull events for the active session so we
36
- // pick up any turns / status updates emitted while we were offline. The
37
- // initial connect doesn't trigger this — `useChat` already loads events
38
- // when activeSessionId becomes set.
39
- if (hasConnectedBefore && chatStore) {
40
- const activeSessionId = chatStore.getState().activeSessionId
41
- if (activeSessionId) {
42
- chatStore.getState().loadEvents(currentWorkspaceId, activeSessionId)
43
- }
44
- }
45
- hasConnectedBefore = true
46
- }
47
-
48
- socket.onmessage = e => {
49
- const data = JSON.parse(e.data) as Record<string, unknown>
50
- if (!chatStore) return
51
- const store = chatStore.getState()
52
-
53
- // Control frames first
54
- if (data.type === 'status') {
55
- store.setProcessing(data.sessionId as string, data.processing as boolean)
56
- return
57
- }
58
- if (data.type === 'session_renamed') {
59
- const from = data.from as string
60
- const to = data.to as string
61
- store.renameSession(from, to)
62
- if (store.activeSessionId === from) store.setActiveSession(to)
63
- return
64
- }
65
- if (data.type === 'workspace:switch') {
66
- onWorkspaceSwitch?.(data.workspaceId as string)
67
- return
68
- }
69
-
70
- // StreamEvent frames are tagged by `kind` and carry a sessionId
71
- const sid = data.sessionId as string | undefined
72
- if (!sid) return
73
- if (
74
- data.kind === 'snapshot' ||
75
- data.kind === 'turn' ||
76
- data.kind === 'notice' ||
77
- data.kind === 'result'
78
- ) {
79
- store.append(sid, data as unknown as StreamEvent)
80
- }
81
- if (data.kind === 'error' && typeof data.content === 'string') {
82
- store.setError(sid, data.content)
83
- }
84
- if (data.kind === 'stopped') {
85
- // Server confirmed abort — make sure the spinner is cleared even if
86
- // the trailing `status` frame is delayed or lost.
87
- store.setProcessing(sid, false)
88
- }
89
- }
90
-
91
- socket.onclose = () => {
92
- ws = null
93
- reconnectTimer = setTimeout(() => {
94
- if (chatStore) connectWs(currentWorkspaceId, chatStore)
95
- }, 1000)
96
- }
97
-
98
- socket.onerror = () => {
99
- socket.close()
100
- }
101
- }
102
-
103
- export function sendWs(msg: ClientMessage) {
104
- if (ws && ws.readyState === WebSocket.OPEN) {
105
- ws.send(JSON.stringify(msg))
106
- } else {
107
- queue.push(msg)
108
- }
109
- }
110
-
111
- export function disconnectWs() {
112
- if (reconnectTimer) {
113
- clearTimeout(reconnectTimer)
114
- reconnectTimer = null
115
- }
116
- if (ws) {
117
- ws.close()
118
- ws = null
119
- }
120
- queue.length = 0
121
- hasConnectedBefore = false
122
- chatStore = null
123
- }
124
-
125
- let onWorkspaceSwitch: ((workspaceId: string) => void) | null = null
126
-
127
- export function setWorkspaceSwitchHandler(fn: ((workspaceId: string) => void) | null) {
128
- onWorkspaceSwitch = fn
129
- }
@@ -1,162 +0,0 @@
1
- import { type ReactNode, createContext, useContext, useEffect, useRef } from 'react'
2
-
3
- import { useStore } from 'zustand'
4
- import { createStore } from 'zustand/vanilla'
5
-
6
- import { applyEvent, emptyViewState } from '@/lib/format'
7
- import type { StreamEvent, ViewState } from '@/lib/types'
8
-
9
- // Per-workspace chat state: which thread is active, plus per-session
10
- // events/views/status. One store instance per mounted workspace (created by
11
- // ChatStoreProvider), so switching workspaces tears it down — nothing bleeds
12
- // across workspaces and `activeSessionId` is naturally scoped to one.
13
- //
14
- // The session *list* is server data and lives in React Query
15
- // (useWorkspaceSessions). This store holds only client-only state that can't be
16
- // re-fetched: the live event stream, its materialized view, optimistic turns,
17
- // processing flags, and errors. `events`/`views` are kept as a working copy
18
- // (rather than derived from React Query) so live websocket frames fold in
19
- // incrementally via applyEvent instead of re-reducing the whole log per frame.
20
- export type ChatStore = {
21
- // The agent's working directory (workspace path), shown in turn metadata.
22
- cwd: string | null
23
- setCwd: (cwd: string | null) => void
24
-
25
- // The session/thread currently shown.
26
- activeSessionId: string | null
27
- setActiveSession: (sessionId: string | null) => void
28
-
29
- // Per-session state, keyed by sessionId.
30
- events: Record<string, StreamEvent[]>
31
- views: Record<string, ViewState>
32
- processing: Record<string, boolean>
33
- // Last server-emitted error per session — surfaced as a dismissable banner
34
- // above the chat. Cleared when the user types or stops the run.
35
- errors: Record<string, string | null>
36
-
37
- setEvents: (sessionId: string, evs: StreamEvent[]) => void
38
- append: (sessionId: string, ev: StreamEvent) => void
39
- setProcessing: (sessionId: string, value: boolean) => void
40
- setError: (sessionId: string, message: string | null) => void
41
- renameSession: (from: string, to: string) => void
42
- loadEvents: (workspaceId: string, sessionId: string) => Promise<void>
43
- }
44
-
45
- async function fetchEvents(workspaceId: string, sessionId: string): Promise<StreamEvent[]> {
46
- const res = await fetch(`/api/workspaces/${workspaceId}/sessions/${sessionId}/events`)
47
- if (!res.ok) return []
48
- return (await res.json()) as StreamEvent[]
49
- }
50
-
51
- function materialize(events: StreamEvent[]): ViewState {
52
- return events.reduce(applyEvent, emptyViewState())
53
- }
54
-
55
- export function createChatStore(initial: { cwd: string | null }) {
56
- return createStore<ChatStore>()(set => ({
57
- cwd: initial.cwd,
58
- setCwd: cwd => set({ cwd }),
59
-
60
- activeSessionId: null,
61
- setActiveSession: sessionId => set({ activeSessionId: sessionId }),
62
-
63
- events: {},
64
- views: {},
65
- processing: {},
66
- errors: {},
67
-
68
- loadEvents: async (workspaceId: string, sessionId: string) => {
69
- const evs = await fetchEvents(workspaceId, sessionId)
70
- set(s => ({
71
- events: { ...s.events, [sessionId]: evs },
72
- views: { ...s.views, [sessionId]: materialize(evs) }
73
- }))
74
- },
75
-
76
- setEvents: (sessionId, evs) =>
77
- set(s => ({
78
- events: { ...s.events, [sessionId]: evs },
79
- views: { ...s.views, [sessionId]: materialize(evs) }
80
- })),
81
-
82
- append: (sessionId, ev) =>
83
- set(s => {
84
- const prior = s.events[sessionId] ?? []
85
- const priorView = s.views[sessionId] ?? emptyViewState()
86
- return {
87
- events: { ...s.events, [sessionId]: [...prior, ev] },
88
- views: { ...s.views, [sessionId]: applyEvent(priorView, ev) }
89
- }
90
- }),
91
-
92
- setProcessing: (sessionId, value) =>
93
- set(s => ({ processing: { ...s.processing, [sessionId]: value } })),
94
-
95
- setError: (sessionId, message) => set(s => ({ errors: { ...s.errors, [sessionId]: message } })),
96
-
97
- renameSession: (from, to) =>
98
- set(s => {
99
- const events = { ...s.events }
100
- const views = { ...s.views }
101
- const processing = { ...s.processing }
102
- const errors = { ...s.errors }
103
- if (from in events) {
104
- events[to] = events[from]
105
- delete events[from]
106
- }
107
- if (from in views) {
108
- views[to] = views[from]
109
- delete views[from]
110
- }
111
- if (from in processing) {
112
- processing[to] = processing[from]
113
- delete processing[from]
114
- }
115
- if (from in errors) {
116
- errors[to] = errors[from]
117
- delete errors[from]
118
- }
119
- return { events, views, processing, errors }
120
- })
121
- }))
122
- }
123
-
124
- export type ChatStoreApi = ReturnType<typeof createChatStore>
125
-
126
- const ChatStoreContext = createContext<ChatStoreApi | null>(null)
127
-
128
- type ChatStoreProviderProps = {
129
- // Workspace path, threaded into the store so turn metadata can show it.
130
- cwd: string | null
131
- children: ReactNode
132
- }
133
-
134
- // Creates one chat store per mount and provides it to the subtree. Mount maps
135
- // to a workspace, so unmounting (a workspace switch) discards all of its chat
136
- // state cleanly.
137
- export function ChatStoreProvider({ cwd, children }: ChatStoreProviderProps) {
138
- const storeRef = useRef<ChatStoreApi | null>(null)
139
- if (storeRef.current === null) storeRef.current = createChatStore({ cwd })
140
-
141
- // Layout (and therefore cwd) resolves after mount; keep the store in sync.
142
- useEffect(() => {
143
- storeRef.current?.getState().setCwd(cwd)
144
- }, [cwd])
145
-
146
- return <ChatStoreContext value={storeRef.current}>{children}</ChatStoreContext>
147
- }
148
-
149
- // Reactive selector hook — re-renders when the selected slice changes.
150
- export function useChatStore<T>(selector: (state: ChatStore) => T): T {
151
- const store = useContext(ChatStoreContext)
152
- if (!store) throw new Error('useChatStore must be used within a ChatStoreProvider')
153
- return useStore(store, selector)
154
- }
155
-
156
- // The raw store handle — for imperative reads/writes (getState/setState) and
157
- // for handing to the non-React websocket layer.
158
- export function useChatStoreApi(): ChatStoreApi {
159
- const store = useContext(ChatStoreContext)
160
- if (!store) throw new Error('useChatStoreApi must be used within a ChatStoreProvider')
161
- return store
162
- }