moi-computer 0.10.1-next.6 → 0.11.1-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/client/features/drawings/capture-element.ts +13 -1
- package/client/features/widgets/WidgetGrid.tsx +1 -1
- package/client/features/widgets/Widgets.tsx +8 -4
- package/dist/{chunk-7paadv61.js → chunk-59zf0m6n.js} +1 -1
- package/dist/{chunk-vwzshv0d.js → chunk-p1yqa71k.js} +39 -39
- package/dist/chunk-r5xrenjy.css +1 -0
- package/dist/index.html +1 -1
- package/package.json +6 -3
- package/server/AGENTS.md +1 -0
- package/server/scratchpad-executor.ts +79 -56
- package/server/scratchpad-shape-defaults.ts +82 -0
- package/dist/chunk-r8s1b672.css +0 -1
package/dist/index.html
CHANGED
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
}
|
|
37
37
|
</script>
|
|
38
38
|
|
|
39
|
-
<link rel="stylesheet" crossorigin href="/chunk-
|
|
39
|
+
<link rel="stylesheet" crossorigin href="/chunk-r5xrenjy.css"><script type="module" crossorigin src="/chunk-59zf0m6n.js"></script></head>
|
|
40
40
|
<body>
|
|
41
41
|
<div id="root"></div>
|
|
42
42
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "moi-computer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1-next.0",
|
|
4
4
|
"description": "Local AI workspace powered by the Claude Agent SDK, Bun, React, and Tailwind. Requires Bun.",
|
|
5
5
|
"license": "Elastic-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -65,6 +65,9 @@
|
|
|
65
65
|
"@tabler/icons-react": "^3.44.0",
|
|
66
66
|
"@tailwindcss/typography": "^0.5.19",
|
|
67
67
|
"@tanstack/react-query": "^5.100.1",
|
|
68
|
+
"@tldraw/store": "5.2.3",
|
|
69
|
+
"@tldraw/tlschema": "5.2.3",
|
|
70
|
+
"@tldraw/utils": "5.2.3",
|
|
68
71
|
"agentation": "^2.3.3",
|
|
69
72
|
"blobatar": "^2.2.0",
|
|
70
73
|
"bun-plugin-tailwind": "^0.1.2",
|
|
@@ -86,8 +89,8 @@
|
|
|
86
89
|
"pathe": "^2.0.3",
|
|
87
90
|
"picocolors": "^1.1.1",
|
|
88
91
|
"postcss": "^8.5.19",
|
|
89
|
-
"react": "
|
|
90
|
-
"react-dom": "
|
|
92
|
+
"react": "19.2.4",
|
|
93
|
+
"react-dom": "19.2.4",
|
|
91
94
|
"react-grid-layout": "^2.2.3",
|
|
92
95
|
"react-markdown": "^10.1.0",
|
|
93
96
|
"react-resizable": "^3.1.3",
|
package/server/AGENTS.md
CHANGED
|
@@ -6,4 +6,5 @@ Bun server on port 13337. Serves the client at `/`, upgrades `/ws` to WebSocket.
|
|
|
6
6
|
- `state.ts` holds the connected chat clients and `broadcast()` (which also feeds the harness debug tap).
|
|
7
7
|
- `harness/` holds every agent backend (Claude Code, OpenClaw, Codex): per-harness adapter + session + transport + protocol NOTES, colocated. Read `harness/README.md` for the message-type layers, the adapter contract, and the folder conventions before touching agent-backend code.
|
|
8
8
|
- WebSocket protocol: server sends `ServerMessage`, client sends `ClientMessage` — both defined in `lib/types.ts`.
|
|
9
|
+
- Never import `react`, `react-dom`, or the `tldraw` package from `server/` or `lib/` — the server must not evaluate React (a global install can pair mismatched `react`/`react-dom` copies, and `react-dom` then throws at load). The scratchpad writer uses `@tldraw/store` + `@tldraw/tlschema` instead; `server/test/server-react-free.test.ts` enforces this. See `docs/moi-scratchpad.md`.
|
|
9
10
|
- Agents run in the workspace directory; Claude Code and Codex approve every permission request by default (a `PreToolUse` allow hook and a transport-level accept, respectively) until UI approvals land. Each backend persists its own session history (see `harness/README.md`).
|
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
import { basename } from 'path'
|
|
2
2
|
import sharp from 'sharp'
|
|
3
3
|
|
|
4
|
+
import { Store } from '@tldraw/store'
|
|
4
5
|
import {
|
|
5
|
-
type IndexKey,
|
|
6
6
|
type TLPageId,
|
|
7
7
|
type TLRecord,
|
|
8
|
-
type
|
|
8
|
+
type TLStoreProps,
|
|
9
|
+
type TLStoreSnapshot,
|
|
9
10
|
AssetRecordType,
|
|
10
|
-
ZERO_INDEX_KEY,
|
|
11
11
|
createBindingId,
|
|
12
12
|
createShapeId,
|
|
13
|
-
|
|
14
|
-
defaultBindingUtils,
|
|
15
|
-
defaultShapeUtils,
|
|
16
|
-
getIndexAbove,
|
|
17
|
-
getSnapshot,
|
|
18
|
-
loadSnapshot,
|
|
13
|
+
createTLSchema,
|
|
19
14
|
toRichText
|
|
20
|
-
} from 'tldraw'
|
|
15
|
+
} from '@tldraw/tlschema'
|
|
16
|
+
import { type IndexKey, ZERO_INDEX_KEY, getIndexAbove } from '@tldraw/utils'
|
|
21
17
|
|
|
22
18
|
import { describeNewerWriter, sequencesAhead } from '@/lib/scratchpad-skew'
|
|
23
19
|
import type {
|
|
@@ -36,6 +32,7 @@ import {
|
|
|
36
32
|
saveScratchpadDoc
|
|
37
33
|
} from './scratchpad'
|
|
38
34
|
import { storeScratchpadAsset } from './scratchpad-assets'
|
|
35
|
+
import { SHAPE_DEFAULTS } from './scratchpad-shape-defaults'
|
|
39
36
|
|
|
40
37
|
// Server-side Scratchpad writer. The browser is no longer required to draw: we run
|
|
41
38
|
// the same ops against a *headless* tldraw store here, persist the snapshot, and
|
|
@@ -47,24 +44,42 @@ import { storeScratchpadAsset } from './scratchpad-assets'
|
|
|
47
44
|
// DOM + text measurement that don't exist in the server runtime. The store
|
|
48
45
|
// validates every `put`, so a malformed record throws instead of corrupting the
|
|
49
46
|
// file — that validation is what keeps hand-built records honest.
|
|
47
|
+
//
|
|
48
|
+
// Deliberately built from `@tldraw/store` + `@tldraw/tlschema` (+ `@tldraw/utils`),
|
|
49
|
+
// NOT the `tldraw` package: the `tldraw` entry point evaluates the whole React
|
|
50
|
+
// editor, and `react-dom` (19.2+) throws at load time whenever the `react` it
|
|
51
|
+
// resolves is a different version — a real hazard for a global `bun i -g`
|
|
52
|
+
// install, whose shared, hoisted `node_modules` can pair moi's `react-dom` with a
|
|
53
|
+
// `react` some other global package locked earlier. That crash used to take the
|
|
54
|
+
// entire server down at `moi start`, before it served a single request. The
|
|
55
|
+
// sub-packages import no React at all, so the server never resolves it. A test
|
|
56
|
+
// (`server/test/server-react-free.test.ts`) keeps this module React-free.
|
|
57
|
+
|
|
58
|
+
// The headless store. `TLStoreProps` is what a schema built by `createTLSchema`
|
|
59
|
+
// expects, but the only prop anything reads here is `defaultName` (the
|
|
60
|
+
// integrity checker, when it seeds the document record). The rest — asset
|
|
61
|
+
// upload, user resolution, editor mount — exists for a mounted `Editor`, which
|
|
62
|
+
// this store never gets.
|
|
63
|
+
type HeadlessStore = Store<TLRecord, TLStoreProps>
|
|
64
|
+
|
|
65
|
+
const unsupported = (what: string) => (): never => {
|
|
66
|
+
throw new Error(`${what} is not available on the server-side scratchpad store`)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Cast: the editor-facing props are unreachable on a store that never mounts an
|
|
70
|
+
// `Editor`; `defaultName` is the one field the store itself consumes.
|
|
71
|
+
const HEADLESS_STORE_PROPS = {
|
|
72
|
+
defaultName: '',
|
|
73
|
+
assets: { upload: unsupported('Asset upload'), resolve: () => null, remove: async () => {} },
|
|
74
|
+
users: { currentUser: null, resolve: () => null },
|
|
75
|
+
onMount: () => {}
|
|
76
|
+
} as unknown as TLStoreProps
|
|
50
77
|
|
|
51
|
-
//
|
|
52
|
-
// is an instance method but doesn't touch the editor for the shapes we create, so a
|
|
53
|
-
// throwaway instance is enough; the result is static per type, so we cache it.
|
|
54
|
-
const shapeDefaults = new Map<string, Record<string, unknown>>()
|
|
78
|
+
// A fresh copy of a shape type's default props (see scratchpad-shape-defaults.ts).
|
|
55
79
|
function defaultProps(type: string): Record<string, unknown> {
|
|
56
|
-
|
|
57
|
-
if (!
|
|
58
|
-
|
|
59
|
-
if (!Util) throw new Error(`Unknown shape type "${type}"`)
|
|
60
|
-
// eslint-disable-next-line new-cap -- Util is a class constructor pulled from a list
|
|
61
|
-
const util = new (Util as unknown as new (editor: unknown) => {
|
|
62
|
-
getDefaultProps(): Record<string, unknown>
|
|
63
|
-
})({})
|
|
64
|
-
cached = util.getDefaultProps()
|
|
65
|
-
shapeDefaults.set(type, cached)
|
|
66
|
-
}
|
|
67
|
-
return { ...cached }
|
|
80
|
+
const defaults = SHAPE_DEFAULTS[type]
|
|
81
|
+
if (!defaults) throw new Error(`Unknown shape type "${type}"`)
|
|
82
|
+
return { ...defaults }
|
|
68
83
|
}
|
|
69
84
|
|
|
70
85
|
// Map an op's optional color/size/fill onto tldraw shape props (omitted → tldraw default).
|
|
@@ -81,7 +96,7 @@ function styleProps(style: ScratchStyle): Record<string, unknown> {
|
|
|
81
96
|
// itself, which reaches the `moi scratch` caller ahead of — and contradicting —
|
|
82
97
|
// the actionable error we throw below ("the file is intact"). Whatever it says
|
|
83
98
|
// is replayed if the load actually succeeds, so only the swallowed-by-a-throw
|
|
84
|
-
// case is lost. Safe to swap `console.error` around: `
|
|
99
|
+
// case is lost. Safe to swap `console.error` around: `loadStoreSnapshot` is sync.
|
|
85
100
|
function loadQuietly(load: () => void): void {
|
|
86
101
|
const original = console.error
|
|
87
102
|
const held: unknown[][] = []
|
|
@@ -102,36 +117,44 @@ function loadQuietly(load: () => void): void {
|
|
|
102
117
|
// so a snapshot written by a newer tldraw is unreadable here — but intact.
|
|
103
118
|
// That gets a loud, actionable error instead of tldraw's bare `migration-error`
|
|
104
119
|
// (which surfaces verbatim through the control port to the `moi scratch` CLI).
|
|
105
|
-
function buildStore(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
function buildStore(
|
|
121
|
+
doc: ScratchpadDoc | null,
|
|
122
|
+
writer: ScratchpadWriter | undefined
|
|
123
|
+
): HeadlessStore {
|
|
124
|
+
// `createTLSchema()` with no arguments is tldraw's default shape/binding/asset
|
|
125
|
+
// set — the same schema the browser's `createTLStore` builds from
|
|
126
|
+
// `defaultShapeUtils` + `defaultBindingUtils` (a test pins the two serialized
|
|
127
|
+
// schemas equal), so a snapshot written here round-trips into the live canvas.
|
|
128
|
+
const store: HeadlessStore = new Store({ schema: createTLSchema(), props: HEADLESS_STORE_PROPS })
|
|
129
|
+
// `loadStoreSnapshot` migrates the records forward to this schema, replaces the
|
|
130
|
+
// store's contents, and seeds whatever a usable document still lacks (the
|
|
131
|
+
// document/page records of a fresh or partial canvas) — so an empty canvas
|
|
132
|
+
// loads an empty snapshot rather than skipping the load.
|
|
133
|
+
const snapshot = doc?.store
|
|
134
|
+
? (doc as unknown as TLStoreSnapshot)
|
|
135
|
+
: { store: {}, schema: store.schema.serialize() }
|
|
136
|
+
try {
|
|
137
|
+
loadQuietly(() => store.loadStoreSnapshot(snapshot))
|
|
138
|
+
} catch (err) {
|
|
139
|
+
const ahead = sequencesAhead(doc?.schema, store.schema.serialize().sequences)
|
|
140
|
+
if (ahead.length > 0) {
|
|
123
141
|
throw new Error(
|
|
124
|
-
`Scratchpad
|
|
125
|
-
`
|
|
142
|
+
`Scratchpad was written by a newer moi (${describeNewerWriter(writer, ahead)}); ` +
|
|
143
|
+
`this server has tldraw ${SCRATCHPAD_WRITER.tldraw}. Restart the newer server or ` +
|
|
144
|
+
`update this install (bun install -g moi-computer@latest). ` +
|
|
145
|
+
`The canvas file is intact — do not reset it.`
|
|
126
146
|
)
|
|
127
147
|
}
|
|
148
|
+
// Not skew — the snapshot itself is bad. Keep the original cause visible.
|
|
149
|
+
throw new Error(
|
|
150
|
+
`Scratchpad snapshot failed to load (not a version mismatch — the file may be ` +
|
|
151
|
+
`corrupted): ${err instanceof Error ? err.message : String(err)}`
|
|
152
|
+
)
|
|
128
153
|
}
|
|
129
|
-
// Seed the document/page records a fresh (or partial) store needs to be valid.
|
|
130
|
-
store.ensureStoreIsUsable()
|
|
131
154
|
return store
|
|
132
155
|
}
|
|
133
156
|
|
|
134
|
-
function firstPageId(store:
|
|
157
|
+
function firstPageId(store: HeadlessStore): TLPageId {
|
|
135
158
|
for (const record of store.allRecords()) {
|
|
136
159
|
if (record.typeName === 'page') return record.id
|
|
137
160
|
}
|
|
@@ -141,7 +164,7 @@ function firstPageId(store: TLStore): TLPageId {
|
|
|
141
164
|
|
|
142
165
|
// The next fractional index above every shape on the page, so a new shape lands on
|
|
143
166
|
// top. IndexKeys sort lexicographically, so a string max is a valid ordering.
|
|
144
|
-
function nextIndex(store:
|
|
167
|
+
function nextIndex(store: HeadlessStore, pageId: TLPageId): IndexKey {
|
|
145
168
|
let max: IndexKey = ZERO_INDEX_KEY
|
|
146
169
|
for (const record of store.allRecords()) {
|
|
147
170
|
if (record.typeName === 'shape' && record.parentId === pageId && record.index > max) {
|
|
@@ -231,7 +254,7 @@ async function processCanvasImage(
|
|
|
231
254
|
// reference — never a base64 blob (see scratchpad-assets.ts). Async — unlike
|
|
232
255
|
// the other ops — because it decodes and resizes the image first.
|
|
233
256
|
async function applyAddImage(
|
|
234
|
-
store:
|
|
257
|
+
store: HeadlessStore,
|
|
235
258
|
workspacePath: string,
|
|
236
259
|
op: Extract<ScratchOp, { kind: 'add-image' }>
|
|
237
260
|
): Promise<ScratchOpResult> {
|
|
@@ -275,7 +298,7 @@ async function applyAddImage(
|
|
|
275
298
|
|
|
276
299
|
// Apply one mutating op to the store. `read` and `view` are handled elsewhere
|
|
277
300
|
// (disk / browser) and never reach here. Returns the op's result.
|
|
278
|
-
function applyOp(store:
|
|
301
|
+
function applyOp(store: HeadlessStore, op: ScratchOp): ScratchOpResult {
|
|
279
302
|
const pageId = firstPageId(store)
|
|
280
303
|
const requireShape = (name: string) => {
|
|
281
304
|
const shape = store.get(createShapeId(name))
|
|
@@ -412,7 +435,7 @@ function applyOp(store: TLStore, op: ScratchOp): ScratchOpResult {
|
|
|
412
435
|
// True if any shape still references the given asset id. tldraw lets several
|
|
413
436
|
// shapes share one asset (e.g. a duplicated image), so delete/replace only drops
|
|
414
437
|
// the asset record when its last user is gone — leaving the file for the sweep.
|
|
415
|
-
function anyShapeUsesAsset(store:
|
|
438
|
+
function anyShapeUsesAsset(store: HeadlessStore, assetId: string): boolean {
|
|
416
439
|
for (const record of store.allRecords()) {
|
|
417
440
|
if (record.typeName !== 'shape') continue
|
|
418
441
|
const props = (record as unknown as { props?: { assetId?: unknown } }).props
|
|
@@ -422,7 +445,7 @@ function anyShapeUsesAsset(store: TLStore, assetId: string): boolean {
|
|
|
422
445
|
}
|
|
423
446
|
|
|
424
447
|
// Ids of bindings whose start/end is the named shape.
|
|
425
|
-
function bindingsTouching(store:
|
|
448
|
+
function bindingsTouching(store: HeadlessStore, name: string): TLRecord['id'][] {
|
|
426
449
|
const target = createShapeId(name)
|
|
427
450
|
const ids: TLRecord['id'][] = []
|
|
428
451
|
for (const record of store.allRecords()) {
|
|
@@ -459,7 +482,7 @@ export function executeScratchOp(
|
|
|
459
482
|
// add-image decodes/resizes the file first, so it's the one async op.
|
|
460
483
|
const result =
|
|
461
484
|
op.kind === 'add-image' ? await applyAddImage(store, workspacePath, op) : applyOp(store, op)
|
|
462
|
-
const next =
|
|
485
|
+
const next = store.getStoreSnapshot() as unknown as ScratchpadDoc
|
|
463
486
|
await saveScratchpadDoc(next, workspacePath)
|
|
464
487
|
publishEvent({ type: 'scratchpad:updated', workspaceId })
|
|
465
488
|
return result
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { toRichText } from '@tldraw/tlschema'
|
|
2
|
+
|
|
3
|
+
// Default props for every shape type the headless scratchpad writer creates
|
|
4
|
+
// (see scratchpad-executor.ts). Copied from each shape's `ShapeUtil.getDefaultProps()`
|
|
5
|
+
// in the `tldraw` package — which the server deliberately does not import, because
|
|
6
|
+
// its entry point drags in the React editor (see the executor's header comment).
|
|
7
|
+
// The values are static per tldraw version, and a test
|
|
8
|
+
// (`server/test/scratchpad-executor.test.ts`) asserts each entry still equals what
|
|
9
|
+
// the pinned `tldraw` returns, so a bump that changes a default fails loudly
|
|
10
|
+
// instead of writing records the browser would render differently.
|
|
11
|
+
export const SHAPE_DEFAULTS: Record<string, Record<string, unknown>> = {
|
|
12
|
+
geo: {
|
|
13
|
+
w: 100,
|
|
14
|
+
h: 100,
|
|
15
|
+
geo: 'rectangle',
|
|
16
|
+
dash: 'draw',
|
|
17
|
+
growY: 0,
|
|
18
|
+
url: '',
|
|
19
|
+
scale: 1,
|
|
20
|
+
color: 'black',
|
|
21
|
+
labelColor: 'black',
|
|
22
|
+
fill: 'none',
|
|
23
|
+
size: 'm',
|
|
24
|
+
font: 'draw',
|
|
25
|
+
align: 'middle',
|
|
26
|
+
verticalAlign: 'middle',
|
|
27
|
+
richText: toRichText('')
|
|
28
|
+
},
|
|
29
|
+
text: {
|
|
30
|
+
color: 'black',
|
|
31
|
+
size: 'm',
|
|
32
|
+
w: 8,
|
|
33
|
+
font: 'draw',
|
|
34
|
+
textAlign: 'start',
|
|
35
|
+
autoSize: true,
|
|
36
|
+
scale: 1,
|
|
37
|
+
richText: toRichText('')
|
|
38
|
+
},
|
|
39
|
+
note: {
|
|
40
|
+
color: 'black',
|
|
41
|
+
richText: toRichText(''),
|
|
42
|
+
size: 'm',
|
|
43
|
+
font: 'draw',
|
|
44
|
+
align: 'middle',
|
|
45
|
+
verticalAlign: 'middle',
|
|
46
|
+
labelColor: 'black',
|
|
47
|
+
growY: 0,
|
|
48
|
+
fontSizeAdjustment: 1,
|
|
49
|
+
url: '',
|
|
50
|
+
scale: 1,
|
|
51
|
+
textLastEditedBy: null
|
|
52
|
+
},
|
|
53
|
+
arrow: {
|
|
54
|
+
kind: 'arc',
|
|
55
|
+
elbowMidPoint: 0.5,
|
|
56
|
+
dash: 'draw',
|
|
57
|
+
size: 'm',
|
|
58
|
+
fill: 'none',
|
|
59
|
+
color: 'black',
|
|
60
|
+
labelColor: 'black',
|
|
61
|
+
bend: 0,
|
|
62
|
+
start: { x: 0, y: 0 },
|
|
63
|
+
end: { x: 2, y: 0 },
|
|
64
|
+
arrowheadStart: 'none',
|
|
65
|
+
arrowheadEnd: 'arrow',
|
|
66
|
+
richText: toRichText(''),
|
|
67
|
+
labelPosition: 0.5,
|
|
68
|
+
font: 'draw',
|
|
69
|
+
scale: 1
|
|
70
|
+
},
|
|
71
|
+
image: {
|
|
72
|
+
w: 100,
|
|
73
|
+
h: 100,
|
|
74
|
+
assetId: null,
|
|
75
|
+
playing: true,
|
|
76
|
+
url: '',
|
|
77
|
+
crop: null,
|
|
78
|
+
flipX: false,
|
|
79
|
+
flipY: false,
|
|
80
|
+
altText: ''
|
|
81
|
+
}
|
|
82
|
+
}
|