moi-computer 0.2.0 → 0.3.0-next.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.
- package/README.md +4 -4
- package/client/components/Scratchpad.tsx +51 -0
- package/client/components/layout/SidebarLayout.tsx +1 -12
- package/dist/chunk-07qf2tv1.css +1 -0
- package/dist/{chunk-90bceh8y.js → chunk-c3zjp9ez.js} +83 -83
- package/dist/index.html +1 -1
- package/package.json +1 -1
- package/server/api.ts +38 -0
- package/server/cli-colors.ts +6 -3
- package/server/cli-env.ts +1 -2
- package/server/cli-pc.ts +20 -0
- package/server/cli.ts +10 -3
- package/server/scratchpad-assets.ts +223 -0
- package/server/scratchpad-executor.ts +49 -17
- package/server/scratchpad.ts +66 -17
- package/workspace/.claude/skills/moi-workspace/SCRATCHPAD.md +5 -3
- package/workspace/.claude/skills/moi-workspace/SKILL.md +1 -0
- package/dist/chunk-9mezmjpz.css +0 -1
- /package/client/{CLAUDE.md → AGENTS.md} +0 -0
- /package/server/{CLAUDE.md → AGENTS.md} +0 -0
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
```
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
██████████ ██████ ██
|
|
3
|
+
██░░██░░██ ██░░██ ██
|
|
4
|
+
██░░██░░██ ██████ ██
|
|
5
5
|
```
|
|
6
6
|
|
|
7
7
|
A local workspace where AI agents build their own UI.
|
|
@@ -17,7 +17,7 @@ moi start # http://localhost:13337
|
|
|
17
17
|
Or paste this into Claude Code and it will set everything up for you:
|
|
18
18
|
|
|
19
19
|
```
|
|
20
|
-
Set up the
|
|
20
|
+
Set up the moi workspace for this project. Fetch https://moi.computer/CC-INSTALL.md, and follow the steps.
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
Hacking on it:
|
|
@@ -3,6 +3,7 @@ import { Fragment, type ReactElement, useCallback, useEffect, useRef, useState }
|
|
|
3
3
|
import {
|
|
4
4
|
type Editor,
|
|
5
5
|
type StyleProp,
|
|
6
|
+
type TLAssetStore,
|
|
6
7
|
type TLComponents,
|
|
7
8
|
type TLDefaultColorStyle,
|
|
8
9
|
type TLDefaultDashStyle,
|
|
@@ -85,6 +86,34 @@ function makeExecutor(editor: Editor) {
|
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
88
|
|
|
89
|
+
// File-backed assets: without this, tldraw inlines every pasted/dropped image as
|
|
90
|
+
// a base64 data URL inside the document — megabytes re-serialized into
|
|
91
|
+
// `.moi/.scratchpad.json` on every autosave and shipped over every GET/PUT.
|
|
92
|
+
// Instead `upload` POSTs the bytes once and stores a tiny `asset:<file>` src on
|
|
93
|
+
// the record; `resolve` maps it back to the serving URL at render time. Legacy
|
|
94
|
+
// snapshots still holding data URLs pass through `resolve` untouched (the
|
|
95
|
+
// server extracts them to files on the next save). See server/scratchpad-assets.ts.
|
|
96
|
+
function makeAssetStore(workspaceId: string): TLAssetStore {
|
|
97
|
+
const base = `/api/workspaces/${workspaceId}/scratchpad/assets`
|
|
98
|
+
return {
|
|
99
|
+
async upload(_asset, file) {
|
|
100
|
+
const res = await fetch(base, {
|
|
101
|
+
method: 'POST',
|
|
102
|
+
headers: { 'Content-Type': file.type || 'application/octet-stream' },
|
|
103
|
+
body: file
|
|
104
|
+
})
|
|
105
|
+
if (!res.ok) throw new Error(`Upload failed: ${await res.text()}`)
|
|
106
|
+
const { src } = (await res.json()) as { src: string }
|
|
107
|
+
return { src }
|
|
108
|
+
},
|
|
109
|
+
resolve(asset) {
|
|
110
|
+
const src = asset.props.src
|
|
111
|
+
if (src?.startsWith('asset:')) return `${base}/${src.slice('asset:'.length)}`
|
|
112
|
+
return src
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
88
117
|
// --- Scratchpad UI shell --------------------------------------------------
|
|
89
118
|
// We replace tldraw's full UI with a curated subset (see docs/moi-scratchpad.md
|
|
90
119
|
// for the prioritization). Backbone v1: a custom vertical tool bar on the left,
|
|
@@ -128,6 +157,15 @@ const SCRATCH_OVERRIDES: TLUiOverrides = {
|
|
|
128
157
|
// One page only — disables the page selector and all multi-page UI.
|
|
129
158
|
const SCRATCH_OPTIONS = { maxPages: 1 }
|
|
130
159
|
|
|
160
|
+
// Browser drag/drop/paste limits (tldraw defaults: reject >10MB, no rescale). We
|
|
161
|
+
// accept larger drops and rescale big images to fit so a phone-sized photo lands
|
|
162
|
+
// as a lightweight asset instead of bloating the snapshot's sidecar files. The
|
|
163
|
+
// size check runs BEFORE the rescale, so a 32MB drop is admitted and then shrunk.
|
|
164
|
+
// (The agent's `moi scratch add image` path has its own presets — see the
|
|
165
|
+
// executor's IMAGE_PRESETS; this only governs what the browser accepts.)
|
|
166
|
+
const MAX_DROP_BYTES = 32 * 1024 * 1024
|
|
167
|
+
const MAX_IMAGE_DIMENSION = 2048
|
|
168
|
+
|
|
131
169
|
type IconC = typeof IconPointer2
|
|
132
170
|
|
|
133
171
|
// The curated left-bar entries, grouped by `sep` dividers. `tool` selects a
|
|
@@ -748,6 +786,14 @@ export function Scratchpad() {
|
|
|
748
786
|
// Reactive handle to the mounted editor, used to render the custom tool bar.
|
|
749
787
|
const [editor, setEditor] = useState<Editor | null>(null)
|
|
750
788
|
const { loaded, snapshot, skew, flagSkew } = useScratchpadSnapshot(workspaceId)
|
|
789
|
+
// Stable identity per workspace, held in a ref rather than useMemo (which React
|
|
790
|
+
// may discard): a fresh `assets` identity makes <Tldraw> rebuild its store and
|
|
791
|
+
// remount the editor, dropping unsaved edits and resetting the camera.
|
|
792
|
+
const assetStoreRef = useRef<{ id: string; store: TLAssetStore } | null>(null)
|
|
793
|
+
if (assetStoreRef.current?.id !== workspaceId) {
|
|
794
|
+
assetStoreRef.current = { id: workspaceId, store: makeAssetStore(workspaceId) }
|
|
795
|
+
}
|
|
796
|
+
const assetStore = assetStoreRef.current.store
|
|
751
797
|
|
|
752
798
|
const save = useCallback(() => {
|
|
753
799
|
const editor = editorRef.current
|
|
@@ -865,11 +911,16 @@ export function Scratchpad() {
|
|
|
865
911
|
<div className="absolute inset-0">
|
|
866
912
|
<Tldraw
|
|
867
913
|
snapshot={snapshot}
|
|
914
|
+
assets={assetStore}
|
|
868
915
|
licenseKey={LICENSE_KEY}
|
|
869
916
|
onMount={onMount}
|
|
870
917
|
components={SCRATCH_COMPONENTS}
|
|
871
918
|
overrides={SCRATCH_OVERRIDES}
|
|
872
919
|
options={SCRATCH_OPTIONS}
|
|
920
|
+
// Accept drops up to 32MB and rescale big images to fit (tldraw checks
|
|
921
|
+
// the size before rescaling, so a large photo is admitted then shrunk).
|
|
922
|
+
maxAssetSize={MAX_DROP_BYTES}
|
|
923
|
+
maxImageDimension={MAX_IMAGE_DIMENSION}
|
|
873
924
|
// Hand focus control entirely to us: tldraw's own `autoFocus` only seeds
|
|
874
925
|
// the `isFocused` flag (hotkeys would fire window-wide, even from the
|
|
875
926
|
// chat) without ever DOM-focusing the canvas. Instead onMount focuses
|
|
@@ -7,8 +7,7 @@ import {
|
|
|
7
7
|
IconLayoutSidebar,
|
|
8
8
|
IconLayoutSidebarLeftCollapse,
|
|
9
9
|
IconLayoutSidebarLeftExpand,
|
|
10
|
-
IconPlus
|
|
11
|
-
IconSettings
|
|
10
|
+
IconPlus
|
|
12
11
|
} from '@tabler/icons-react'
|
|
13
12
|
import { useQueryClient } from '@tanstack/react-query'
|
|
14
13
|
import { Link } from 'wouter'
|
|
@@ -216,16 +215,6 @@ function Sidebar({ collapsed, workspaces, logoEffect }: SidebarProps) {
|
|
|
216
215
|
|
|
217
216
|
{/* Footer */}
|
|
218
217
|
<div className="flex items-center justify-between gap-2 py-3">
|
|
219
|
-
<button
|
|
220
|
-
type="button"
|
|
221
|
-
className={cn(
|
|
222
|
-
'flex h-8 items-center gap-2 rounded-sm pl-1.5 text-sm text-foreground hover:bg-foreground/[0.05] hover:text-foreground',
|
|
223
|
-
collapsed ? 'pr-1.5' : 'pr-2.5'
|
|
224
|
-
)}
|
|
225
|
-
>
|
|
226
|
-
<IconSettings size={18} className="shrink-0" />
|
|
227
|
-
{!collapsed && <span>Settings</span>}
|
|
228
|
-
</button>
|
|
229
218
|
{/* Temporarily hidden */}
|
|
230
219
|
<button
|
|
231
220
|
type="button"
|