moi-computer 0.9.1-next.0 → 0.9.1-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/api/app-config.ts +51 -0
- package/client/api/workspace-keys.ts +1 -0
- package/client/app/routes/WorkspaceRoute.tsx +4 -2
- package/client/components/ui/button.tsx +1 -1
- package/client/features/applets/api.ts +38 -0
- package/client/features/applets/applet-thumbnail.ts +208 -0
- package/client/features/chat/ChatEmptyState.tsx +5 -3
- package/client/features/chat/ChatPanel.tsx +2 -8
- package/client/features/chat/ChatSelector.tsx +29 -10
- package/client/features/chat/MarkdownContent.tsx +2 -2
- package/client/features/home/HomePage.tsx +13 -0
- package/client/features/home/WorkspacePreview.tsx +51 -33
- package/client/features/home/workspace-setup/CreateWorkspaceDialog.tsx +9 -0
- package/client/features/home/workspace-setup/InstallMoiDialog.tsx +245 -0
- package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +1 -1
- package/client/features/home/workspace-setup/WorkspaceDialogContent.tsx +1 -1
- package/client/features/views/ViewBuilder.tsx +18 -4
- package/client/features/views/ViewManager.tsx +18 -2
- package/client/features/widgets/WidgetFrame.tsx +1 -1
- package/client/features/widgets/WidgetGrid.tsx +1 -1
- package/client/features/widgets/Widgets.tsx +16 -15
- package/client/features/workspace/CustomizePanel.tsx +29 -8
- package/client/features/workspace/WorkspaceScreen.tsx +8 -14
- package/client/index.tsx +6 -1
- package/client/runtime/useWorkspaceEvents.ts +17 -0
- package/client/runtime/workspace-theme.ts +36 -6
- package/dist/chunk-87q78504.js +1 -0
- package/dist/chunk-8s41nd3g.js +1 -0
- package/dist/{chunk-pp62fnxh.js → chunk-b959mdkj.js} +1 -1
- package/dist/chunk-cagtq45k.js +1 -0
- package/dist/chunk-ek6zde7t.js +10 -0
- package/dist/chunk-n8tq2494.js +82 -0
- package/dist/chunk-v82nefjq.css +1 -0
- package/dist/{chunk-sxc24vfp.js → chunk-zbeq02yc.js} +1 -1
- package/dist/chunk-zbt8emsw.js +2 -0
- package/dist/{chunk-6w6j9g4b.js → chunk-zcyvyebg.js} +2 -2
- package/dist/chunk-zfz3b4xg.js +2 -0
- package/dist/index.html +1 -1
- package/lib/themes.ts +4 -4
- package/lib/types.ts +60 -41
- package/package.json +1 -1
- package/server/api.ts +69 -31
- package/server/app-config.ts +144 -0
- package/server/applets.ts +17 -0
- package/server/cli.ts +47 -11
- package/server/layout.ts +40 -45
- package/server/moi-scaffold.ts +37 -1
- package/server/session-config.ts +3 -13
- package/server/thumbnails.ts +197 -0
- package/server/views.ts +10 -1
- package/server/widgets.ts +4 -18
- package/workspace/.claude/skills/moi-workspace/SKILL.md +13 -1
- package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +153 -253
- package/client/features/drawings/annotation-availability.ts +0 -10
- package/client/features/widgets/api.ts +0 -47
- package/client/features/widgets/useWidgetThumbnails.ts +0 -107
- package/client/features/widgets/widget-snapshot.ts +0 -71
- package/dist/chunk-3becmq75.js +0 -81
- package/dist/chunk-8ew39cvq.js +0 -10
- package/dist/chunk-c8gtrjwp.js +0 -1
- package/dist/chunk-v964b5g7.js +0 -1
- package/dist/chunk-zx33ts9d.css +0 -1
package/package.json
CHANGED
package/server/api.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { basename, join, resolve } from 'node:path'
|
|
|
6
6
|
|
|
7
7
|
import type {
|
|
8
8
|
AppletKind,
|
|
9
|
+
AppletThumbnailBatch,
|
|
9
10
|
AppSettings,
|
|
10
11
|
HarnessAvailability,
|
|
11
12
|
SessionInfo,
|
|
@@ -19,6 +20,7 @@ import type { MoiContext } from '@/lib/moi-context'
|
|
|
19
20
|
import { viewBuilderDirectives } from '@/lib/view-builder-directives'
|
|
20
21
|
|
|
21
22
|
import { agentStore } from './agent'
|
|
23
|
+
import { clientAppConfig, getAppConfig } from './app-config'
|
|
22
24
|
import { getAppSettings, pickAppSettingsPatch, saveAppSettings } from './app-settings'
|
|
23
25
|
import { appletForModule, recordAppletError } from './applet-log'
|
|
24
26
|
import { apiBaseFor, parseAppletTail, serveWorkspaceFile } from './applets'
|
|
@@ -26,13 +28,13 @@ import { applyEnvChanged } from './env-apply'
|
|
|
26
28
|
import { publishEvent } from './events'
|
|
27
29
|
import { callFunction, parseFunctionPath } from './functions'
|
|
28
30
|
import { processIcon } from './icon'
|
|
31
|
+
import { getWorkspacePreview, loadLayout, mergeLayoutForSave, saveLayout } from './layout'
|
|
29
32
|
import {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
} from './layout'
|
|
33
|
+
getAppletThumbnailRecords,
|
|
34
|
+
isValidAppletId,
|
|
35
|
+
saveAppletThumbnails,
|
|
36
|
+
serveAppletThumbnail
|
|
37
|
+
} from './thumbnails'
|
|
36
38
|
import { getClientFrameLog, getWireLog } from './harness/debug'
|
|
37
39
|
import { allHarnesses, harnessFor, isHarnessType } from './harness/registry'
|
|
38
40
|
import { broadcast } from './state'
|
|
@@ -150,10 +152,16 @@ one.use('*', withWorkspace)
|
|
|
150
152
|
|
|
151
153
|
one.get('/preview', async c => {
|
|
152
154
|
const ws = c.get('ws')
|
|
155
|
+
const wsId = c.req.param('id')
|
|
156
|
+
const views = await getViewList(ws.path)
|
|
153
157
|
return c.json(
|
|
154
|
-
await getWorkspacePreview(ws.path,
|
|
155
|
-
|
|
156
|
-
|
|
158
|
+
await getWorkspacePreview(ws.path, {
|
|
159
|
+
getProviderPreview: includeFirstUserMessage =>
|
|
160
|
+
harnessFor(ws).workspacePreview(ws, includeFirstUserMessage),
|
|
161
|
+
viewIds: views.map(view => view.id),
|
|
162
|
+
thumbnailUrl: (kind, id) =>
|
|
163
|
+
`/api/workspaces/${wsId}/applet-thumbnails/${kind}/${encodeURIComponent(id)}`
|
|
164
|
+
})
|
|
157
165
|
)
|
|
158
166
|
})
|
|
159
167
|
|
|
@@ -827,16 +835,9 @@ one.delete('/icon', async c => {
|
|
|
827
835
|
// DELETE unregisters.
|
|
828
836
|
one.get('/', async c => {
|
|
829
837
|
const ws = c.get('ws')
|
|
830
|
-
|
|
831
|
-
// path (PUT .../thumbnails); the layout ships `widgetThumbnails` without
|
|
832
|
-
// them — just `key`/`at`, which clients compare against the live grid to
|
|
833
|
-
// decide when to re-capture.
|
|
834
|
-
const { widgetThumbnails, ...layout } = await loadLayout(ws.path)
|
|
838
|
+
const layout = await loadLayout(ws.path)
|
|
835
839
|
return c.json({
|
|
836
840
|
...layout,
|
|
837
|
-
...(widgetThumbnails && {
|
|
838
|
-
widgetThumbnails: { key: widgetThumbnails.key, at: widgetThumbnails.at }
|
|
839
|
-
}),
|
|
840
841
|
// Resolved display name: the settings override, or the folder name.
|
|
841
842
|
name: layout.name || basename(ws.path),
|
|
842
843
|
cwd: ws.path,
|
|
@@ -845,21 +846,46 @@ one.get('/', async c => {
|
|
|
845
846
|
})
|
|
846
847
|
})
|
|
847
848
|
|
|
848
|
-
//
|
|
849
|
-
//
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
849
|
+
// Thumbnail freshness records, without image bytes — the capture hook compares
|
|
850
|
+
// these against live bundle revisions. Images are served per-applet below.
|
|
851
|
+
one.get('/applet-thumbnails', async c =>
|
|
852
|
+
c.json({ thumbnails: await getAppletThumbnailRecords(c.get('ws').path) })
|
|
853
|
+
)
|
|
854
|
+
|
|
855
|
+
one.get('/applet-thumbnails/:kind/:name', c => {
|
|
856
|
+
const kind = c.req.param('kind')
|
|
857
|
+
if (kind !== 'widget' && kind !== 'view') return c.text('Not found', 404)
|
|
858
|
+
return serveAppletThumbnail(
|
|
859
|
+
c.get('ws').path,
|
|
860
|
+
kind,
|
|
861
|
+
c.req.param('name'),
|
|
862
|
+
c.req.header('if-none-match')
|
|
863
|
+
)
|
|
864
|
+
})
|
|
865
|
+
|
|
866
|
+
// Settled widget and view visits share one batch endpoint and storage path.
|
|
867
|
+
one.put('/applet-thumbnails', async c => {
|
|
854
868
|
const body: unknown = await c.req.json().catch(() => null)
|
|
855
|
-
if (!body || typeof body !== 'object') return c.text('Bad request', 400)
|
|
856
|
-
const
|
|
857
|
-
const
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
869
|
+
if (!body || typeof body !== 'object' || Array.isArray(body)) return c.text('Bad request', 400)
|
|
870
|
+
const input = body as AppletThumbnailBatch
|
|
871
|
+
const valid =
|
|
872
|
+
(input.kind === 'widget' || input.kind === 'view') &&
|
|
873
|
+
Array.isArray(input.thumbnails) &&
|
|
874
|
+
input.thumbnails.every(
|
|
875
|
+
thumbnail =>
|
|
876
|
+
thumbnail &&
|
|
877
|
+
typeof thumbnail === 'object' &&
|
|
878
|
+
!Array.isArray(thumbnail) &&
|
|
879
|
+
typeof thumbnail.id === 'string' &&
|
|
880
|
+
isValidAppletId(thumbnail.id) &&
|
|
881
|
+
typeof thumbnail.revision === 'string' &&
|
|
882
|
+
(thumbnail.image === undefined ||
|
|
883
|
+
thumbnail.image === null ||
|
|
884
|
+
typeof thumbnail.image === 'string') &&
|
|
885
|
+
(thumbnail.captureMs === undefined || typeof thumbnail.captureMs === 'number')
|
|
886
|
+
)
|
|
887
|
+
if (!valid) return c.text('Bad request', 400)
|
|
888
|
+
await saveAppletThumbnails(c.get('ws').path, input.kind, input.thumbnails)
|
|
863
889
|
return c.body(null, 204)
|
|
864
890
|
})
|
|
865
891
|
|
|
@@ -917,7 +943,14 @@ workspaces.put('/order', async c => {
|
|
|
917
943
|
}
|
|
918
944
|
})
|
|
919
945
|
|
|
946
|
+
// One message for both creation routes: in the cloud demo the instance is
|
|
947
|
+
// provisioned with its workspaces; the UI never sends these requests (it opens
|
|
948
|
+
// the install-moi dialog instead), so a 403 here means the API was called
|
|
949
|
+
// directly.
|
|
950
|
+
const DEMO_CREATE_BLOCKED = 'Workspace creation is not available in the moi demo'
|
|
951
|
+
|
|
920
952
|
workspaces.post('/', async c => {
|
|
953
|
+
if (getAppConfig().cloudDemo) return c.text(DEMO_CREATE_BLOCKED, 403)
|
|
921
954
|
const body = await c.req.json()
|
|
922
955
|
if (!body?.path) return c.text('Missing path', 400)
|
|
923
956
|
const requestedType: unknown = body?.type ?? 'claude-code'
|
|
@@ -983,6 +1016,7 @@ workspaces.get('/create', async c =>
|
|
|
983
1016
|
// Create a brand-new workspace: a fresh folder under CREATED_WORKSPACES_ROOT,
|
|
984
1017
|
// provisioned (skills + `.moi/` scaffold) and registered.
|
|
985
1018
|
workspaces.post('/create', async c => {
|
|
1019
|
+
if (getAppConfig().cloudDemo) return c.text(DEMO_CREATE_BLOCKED, 403)
|
|
986
1020
|
const body = await c.req.json()
|
|
987
1021
|
const requestedType: unknown = body?.type ?? 'claude-code'
|
|
988
1022
|
if (!isHarnessType(requestedType)) {
|
|
@@ -1021,6 +1055,10 @@ export const api = new Hono()
|
|
|
1021
1055
|
|
|
1022
1056
|
api.route('/api/workspaces', workspaces)
|
|
1023
1057
|
|
|
1058
|
+
// Startup config (config.json in the data dir + MOI_* env), client-safe
|
|
1059
|
+
// subset. Immutable for the process lifetime — clients cache it forever.
|
|
1060
|
+
api.get('/api/config', c => c.json(clientAppConfig()))
|
|
1061
|
+
|
|
1024
1062
|
// App-wide settings (settings.json in the data dir). GET returns every key
|
|
1025
1063
|
// with defaults applied; PATCH merges a partial body and returns the result.
|
|
1026
1064
|
api.get('/api/settings', c => c.json(getAppSettings()))
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import { join } from 'path'
|
|
3
|
+
|
|
4
|
+
import type { ClientAppConfig } from '@/lib/types'
|
|
5
|
+
|
|
6
|
+
import { DATA_DIR } from './data-dir'
|
|
7
|
+
|
|
8
|
+
// Startup (deployment) config, read once per process from `config.json` in
|
|
9
|
+
// moi's data dir and overridable by `MOI_*` env vars (env wins). Distinct from
|
|
10
|
+
// `settings.json` (user settings: conf-backed, API-mutable, changes at
|
|
11
|
+
// runtime): config.json describes the deployment itself — nothing here changes
|
|
12
|
+
// without a server restart, and no API writes it.
|
|
13
|
+
//
|
|
14
|
+
// Resolution: defaults < config.json < env. A missing file is the normal local
|
|
15
|
+
// case; a malformed file or wrong-typed key warns on stderr and falls back
|
|
16
|
+
// per-key, so a broken config never takes the CLI or server down with it.
|
|
17
|
+
export type AppConfig = {
|
|
18
|
+
// Cloud demo deployment: workspace creation is blocked (UI shows the
|
|
19
|
+
// install-moi dialog instead) and `moi` system commands are disabled.
|
|
20
|
+
cloudDemo: boolean
|
|
21
|
+
// Gated experimental features, checked by slug.
|
|
22
|
+
experiments: string[]
|
|
23
|
+
// Link target for the install-moi dialog in the cloud demo.
|
|
24
|
+
demoInstallUrl: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const DEFAULTS: AppConfig = {
|
|
28
|
+
cloudDemo: false,
|
|
29
|
+
experiments: [],
|
|
30
|
+
demoInstallUrl: 'https://moi.computer'
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const APP_CONFIG_FILE = join(DATA_DIR, 'config.json')
|
|
34
|
+
|
|
35
|
+
function warn(message: string): void {
|
|
36
|
+
console.error(`[moi] config: ${message}`)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// '1'/'true' (case-insensitive) are true, '0'/'false' are false, anything
|
|
40
|
+
// else — including empty — leaves the lower-precedence value in place.
|
|
41
|
+
function parseBool(raw: string | undefined): boolean | undefined {
|
|
42
|
+
if (raw === undefined) return undefined
|
|
43
|
+
const value = raw.trim().toLowerCase()
|
|
44
|
+
if (value === '1' || value === 'true') return true
|
|
45
|
+
if (value === '0' || value === 'false') return false
|
|
46
|
+
return undefined
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// "a, b,c" → ['a','b','c']; empty entries dropped. An empty string clears the
|
|
50
|
+
// list (explicitly setting MOI_EXPERIMENTS= disables file-set experiments).
|
|
51
|
+
function parseList(raw: string | undefined): string[] | undefined {
|
|
52
|
+
if (raw === undefined) return undefined
|
|
53
|
+
return raw
|
|
54
|
+
.split(',')
|
|
55
|
+
.map(item => item.trim())
|
|
56
|
+
.filter(Boolean)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function parseString(raw: string | undefined): string | undefined {
|
|
60
|
+
if (raw === undefined || raw.trim() === '') return undefined
|
|
61
|
+
return raw.trim()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function fileValues(file: string): Partial<AppConfig> {
|
|
65
|
+
let text: string
|
|
66
|
+
try {
|
|
67
|
+
text = readFileSync(file, 'utf8')
|
|
68
|
+
} catch (err) {
|
|
69
|
+
// Only a missing file is silent (the normal local case). Anything else —
|
|
70
|
+
// permissions, mount errors — is loud: a deployment relying on config.json
|
|
71
|
+
// must not boot un-gated without a diagnostic. Deployments that need the
|
|
72
|
+
// demo gate guaranteed should pin MOI_CLOUD_DEMO=1 in the environment,
|
|
73
|
+
// which has no read-failure mode.
|
|
74
|
+
if ((err as NodeJS.ErrnoException).code !== 'ENOENT') {
|
|
75
|
+
warn(`could not read ${file}: ${err instanceof Error ? err.message : String(err)}`)
|
|
76
|
+
}
|
|
77
|
+
return {}
|
|
78
|
+
}
|
|
79
|
+
let parsed: unknown
|
|
80
|
+
try {
|
|
81
|
+
parsed = JSON.parse(text)
|
|
82
|
+
} catch (err) {
|
|
83
|
+
warn(`ignoring ${file} — invalid JSON: ${err instanceof Error ? err.message : String(err)}`)
|
|
84
|
+
return {}
|
|
85
|
+
}
|
|
86
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
87
|
+
warn(`ignoring ${file} — expected a JSON object`)
|
|
88
|
+
return {}
|
|
89
|
+
}
|
|
90
|
+
const raw = parsed as Record<string, unknown>
|
|
91
|
+
const out: Partial<AppConfig> = {}
|
|
92
|
+
if (raw.cloudDemo !== undefined) {
|
|
93
|
+
if (typeof raw.cloudDemo === 'boolean') out.cloudDemo = raw.cloudDemo
|
|
94
|
+
else warn('ignoring "cloudDemo" — expected a boolean')
|
|
95
|
+
}
|
|
96
|
+
if (raw.experiments !== undefined) {
|
|
97
|
+
if (Array.isArray(raw.experiments) && raw.experiments.every(item => typeof item === 'string')) {
|
|
98
|
+
out.experiments = raw.experiments
|
|
99
|
+
} else warn('ignoring "experiments" — expected an array of strings')
|
|
100
|
+
}
|
|
101
|
+
if (raw.demoInstallUrl !== undefined) {
|
|
102
|
+
if (typeof raw.demoInstallUrl === 'string') out.demoInstallUrl = raw.demoInstallUrl
|
|
103
|
+
else warn('ignoring "demoInstallUrl" — expected a string')
|
|
104
|
+
}
|
|
105
|
+
return out
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Pure resolver, exported for tests. `getAppConfig` is the cached entrypoint.
|
|
109
|
+
export function loadAppConfig(
|
|
110
|
+
file: string = APP_CONFIG_FILE,
|
|
111
|
+
env: Record<string, string | undefined> = process.env
|
|
112
|
+
): AppConfig {
|
|
113
|
+
const fromFile = fileValues(file)
|
|
114
|
+
const fromEnv: Partial<AppConfig> = {
|
|
115
|
+
cloudDemo: parseBool(env.MOI_CLOUD_DEMO),
|
|
116
|
+
experiments: parseList(env.MOI_EXPERIMENTS),
|
|
117
|
+
demoInstallUrl: parseString(env.MOI_DEMO_INSTALL_URL)
|
|
118
|
+
}
|
|
119
|
+
const merged = { ...DEFAULTS, ...fromFile }
|
|
120
|
+
for (const key of Object.keys(fromEnv) as (keyof AppConfig)[]) {
|
|
121
|
+
if (fromEnv[key] === undefined) delete fromEnv[key]
|
|
122
|
+
}
|
|
123
|
+
return Object.freeze({ ...merged, ...fromEnv })
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
let _config: AppConfig | null = null
|
|
127
|
+
|
|
128
|
+
export function getAppConfig(): AppConfig {
|
|
129
|
+
_config ??= loadAppConfig()
|
|
130
|
+
return _config
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Test seam: drop the cached config so the next getAppConfig() re-resolves
|
|
134
|
+
// (tests point MOI_DATA_DIR elsewhere or set MOI_CLOUD_DEMO).
|
|
135
|
+
export function resetAppConfig(): void {
|
|
136
|
+
_config = null
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// The only shape that reaches the browser (GET /api/config). Server-only keys
|
|
140
|
+
// added to AppConfig later stay out unless explicitly forwarded here.
|
|
141
|
+
export function clientAppConfig(): ClientAppConfig {
|
|
142
|
+
const { cloudDemo, experiments, demoInstallUrl } = getAppConfig()
|
|
143
|
+
return { cloudDemo, experiments: [...experiments], demoInstallUrl }
|
|
144
|
+
}
|
package/server/applets.ts
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
buildApplet,
|
|
24
24
|
scanRelativeImports
|
|
25
25
|
} from './bundler/build-applet'
|
|
26
|
+
import { pruneAppletThumbnails } from './thumbnails'
|
|
26
27
|
|
|
27
28
|
export type AppletPaths = {
|
|
28
29
|
moiRoot: string
|
|
@@ -40,6 +41,20 @@ export function getAppletPaths(workspacePath: string, kind: AppletKind): AppletP
|
|
|
40
41
|
return { moiRoot, sourceDir, buildDir, manifestPath }
|
|
41
42
|
}
|
|
42
43
|
|
|
44
|
+
export function getAppletRevision(
|
|
45
|
+
workspacePath: string,
|
|
46
|
+
kind: AppletKind,
|
|
47
|
+
id: string
|
|
48
|
+
): string | undefined {
|
|
49
|
+
try {
|
|
50
|
+
const { buildDir } = getAppletPaths(workspacePath, kind)
|
|
51
|
+
const stat = statSync(join(buildDir, id, 'index.js'))
|
|
52
|
+
return `${stat.size}-${Math.trunc(stat.mtimeMs)}`
|
|
53
|
+
} catch {
|
|
54
|
+
return undefined
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
43
58
|
// Source module names in a kind's directory: `*.tsx`/`*.ts` minus `.server.ts`
|
|
44
59
|
// and minus `_`-prefixed files (`_utils.tsx`) — those are shared modules for
|
|
45
60
|
// entries to import, never entry points themselves.
|
|
@@ -580,6 +595,8 @@ export async function buildApplets<C>(
|
|
|
580
595
|
await mkdir(buildDir, { recursive: true })
|
|
581
596
|
}
|
|
582
597
|
await pruneStaleBuilds(buildDir, new Set(names))
|
|
598
|
+
// A deleted applet's thumbnail dies with its bundle.
|
|
599
|
+
await pruneAppletThumbnails(workspacePath, kind, names)
|
|
583
600
|
|
|
584
601
|
const jobs = await Promise.all(
|
|
585
602
|
names.map(async name => {
|
package/server/cli.ts
CHANGED
|
@@ -5,10 +5,11 @@ import { formatHex } from 'culori'
|
|
|
5
5
|
import { parse as devalueParse } from 'devalue'
|
|
6
6
|
import { existsSync } from 'node:fs'
|
|
7
7
|
import { tmpdir } from 'node:os'
|
|
8
|
-
import { join, resolve } from 'path'
|
|
8
|
+
import { dirname, join, resolve } from 'path'
|
|
9
9
|
import pc from './cli-pc'
|
|
10
10
|
|
|
11
11
|
import { isAgentCaller } from './agent-caller'
|
|
12
|
+
import { getAppConfig } from './app-config'
|
|
12
13
|
|
|
13
14
|
import {
|
|
14
15
|
COLOR_THEMES,
|
|
@@ -61,6 +62,7 @@ import { updateWorkspaceSkills } from './skill-update'
|
|
|
61
62
|
import {
|
|
62
63
|
ServiceError,
|
|
63
64
|
analyzeInstall,
|
|
65
|
+
captureServiceEnv,
|
|
64
66
|
installService,
|
|
65
67
|
queryServerInfo,
|
|
66
68
|
restartService,
|
|
@@ -2393,6 +2395,25 @@ const serviceInstall = defineCommand({
|
|
|
2393
2395
|
serviceFail(err)
|
|
2394
2396
|
}
|
|
2395
2397
|
}
|
|
2398
|
+
const port = args.port ? Number(args.port) : undefined
|
|
2399
|
+
if (port !== undefined && (!Number.isInteger(port) || port < 1 || port > 65535)) {
|
|
2400
|
+
serviceFail(new ServiceError(`Invalid --port value "${args.port}" — use a port number.`))
|
|
2401
|
+
}
|
|
2402
|
+
// citty hands back an array when the flag repeats — accept both shapes.
|
|
2403
|
+
const envArg = Array.isArray(args.env) ? args.env.join(',') : args.env
|
|
2404
|
+
const extraEnv = (envArg ?? '')
|
|
2405
|
+
.split(',')
|
|
2406
|
+
.map(k => k.trim())
|
|
2407
|
+
.filter(Boolean)
|
|
2408
|
+
const serviceEnv = captureServiceEnv(process.env, dirname(process.execPath), extraEnv)
|
|
2409
|
+
const missingEnv = extraEnv.filter(key => !(key in serviceEnv))
|
|
2410
|
+
if (missingEnv.length > 0) {
|
|
2411
|
+
serviceFail(
|
|
2412
|
+
new ServiceError(
|
|
2413
|
+
`--env ${missingEnv.join(', ')}: not set in this shell (or the value is not capturable).`
|
|
2414
|
+
)
|
|
2415
|
+
)
|
|
2416
|
+
}
|
|
2396
2417
|
// A foreground `moi start` holds the same ports the service needs. Refuse
|
|
2397
2418
|
// rather than install a unit that instantly fails on bind.
|
|
2398
2419
|
const runningInfo = await queryServerInfo()
|
|
@@ -2406,16 +2427,6 @@ const serviceInstall = defineCommand({
|
|
|
2406
2427
|
)
|
|
2407
2428
|
)
|
|
2408
2429
|
}
|
|
2409
|
-
const port = args.port ? Number(args.port) : undefined
|
|
2410
|
-
if (port !== undefined && (!Number.isInteger(port) || port < 1 || port > 65535)) {
|
|
2411
|
-
serviceFail(new ServiceError(`Invalid --port value "${args.port}" — use a port number.`))
|
|
2412
|
-
}
|
|
2413
|
-
// citty hands back an array when the flag repeats — accept both shapes.
|
|
2414
|
-
const envArg = Array.isArray(args.env) ? args.env.join(',') : args.env
|
|
2415
|
-
const extraEnv = (envArg ?? '')
|
|
2416
|
-
.split(',')
|
|
2417
|
-
.map(k => k.trim())
|
|
2418
|
-
.filter(Boolean)
|
|
2419
2430
|
try {
|
|
2420
2431
|
const result = await installService({ port, extraEnv })
|
|
2421
2432
|
console.log(
|
|
@@ -2840,6 +2851,31 @@ const main = defineCommand({
|
|
|
2840
2851
|
subCommands: { ...workspaceCommands, ...systemCommands }
|
|
2841
2852
|
})
|
|
2842
2853
|
|
|
2854
|
+
// Cloud demo: system commands manage moi itself (service, updates, agent
|
|
2855
|
+
// runtimes) — in a demo container the instance is provisioned, not managed,
|
|
2856
|
+
// so they print a pointer to the real thing instead of running. Two stay:
|
|
2857
|
+
// `start`, because it is how the demo (container or a local test run) boots
|
|
2858
|
+
// at all — against an already-running server it just reports and exits — and
|
|
2859
|
+
// `version`, which is harmless and useful in bug reports.
|
|
2860
|
+
function exitIfDemoBlocked(): void {
|
|
2861
|
+
const invoked = process.argv[2]
|
|
2862
|
+
if (!invoked || invoked === 'version' || invoked === 'start') return
|
|
2863
|
+
if (!(invoked in systemCommands)) return
|
|
2864
|
+
const config = getAppConfig()
|
|
2865
|
+
if (!config.cloudDemo) return
|
|
2866
|
+
console.log(
|
|
2867
|
+
'\n' +
|
|
2868
|
+
pc.yellow('◆') +
|
|
2869
|
+
` moi ${invoked} is not available in the demo.\n` +
|
|
2870
|
+
pc.dim(' Get moi on your computer: ') +
|
|
2871
|
+
pc.bold(config.demoInstallUrl) +
|
|
2872
|
+
'\n'
|
|
2873
|
+
)
|
|
2874
|
+
process.exit(1)
|
|
2875
|
+
}
|
|
2876
|
+
|
|
2877
|
+
exitIfDemoBlocked()
|
|
2878
|
+
|
|
2843
2879
|
type HelpCommand = { meta?: unknown }
|
|
2844
2880
|
|
|
2845
2881
|
async function commandDescription(cmd: HelpCommand): Promise<string> {
|
package/server/layout.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { join } from 'path'
|
|
2
2
|
|
|
3
|
-
import type { WorkspaceLayout, WorkspacePreview } from '@/lib/types'
|
|
3
|
+
import type { AppletKind, WorkspaceLayout, WorkspacePreview } from '@/lib/types'
|
|
4
4
|
import { createDefaultWorkspaceLayout, createDefaultWorkspaceTabs } from '@/lib/workspace-layout'
|
|
5
5
|
import { isWorkspaceTabId } from '@/lib/workspace-tabs'
|
|
6
6
|
|
|
7
|
+
import { getCapturedThumbnails } from './thumbnails'
|
|
8
|
+
|
|
7
9
|
function normalizeTabs(value: unknown): WorkspaceLayout['tabs'] {
|
|
8
10
|
if (!value || typeof value !== 'object') return createDefaultWorkspaceTabs()
|
|
9
11
|
const raw = value as Record<string, unknown>
|
|
@@ -22,6 +24,12 @@ function normalizeLayout(parsed: Record<string, unknown>): WorkspaceLayout {
|
|
|
22
24
|
layout.layoutMode = defaults.layoutMode
|
|
23
25
|
}
|
|
24
26
|
layout.tabs = normalizeTabs(layout.tabs)
|
|
27
|
+
// Legacy thumbnail caches are intentionally dropped, not migrated — images
|
|
28
|
+
// now live as files under `.moi/.cache/thumbnails` (server/thumbnails.ts)
|
|
29
|
+
// and applets are simply captured again there.
|
|
30
|
+
delete layout.widgetThumbnails
|
|
31
|
+
delete layout.viewThumbnails
|
|
32
|
+
delete layout.appletThumbnails
|
|
25
33
|
delete layout.sectionMode
|
|
26
34
|
delete layout.chatMode
|
|
27
35
|
return layout as unknown as WorkspaceLayout
|
|
@@ -54,53 +62,24 @@ export async function saveLayout(layout: WorkspaceLayout, workspacePath: string)
|
|
|
54
62
|
// A blind overwrite therefore erases a `moi config`-set name (and could revert an
|
|
55
63
|
// icon). So drop whatever identity the body carries and re-apply the server-owned
|
|
56
64
|
// fields from `existing` — conditionally, so an absent field never serializes
|
|
57
|
-
// as `name: undefined`.
|
|
58
|
-
// write: they have their own endpoint (saveWidgetThumbnails), and the layout
|
|
59
|
-
// GET doesn't even ship the map — a round-trip would erase it.
|
|
65
|
+
// as `name: undefined`.
|
|
60
66
|
export function mergeLayoutForSave(
|
|
61
67
|
existing: WorkspaceLayout,
|
|
62
68
|
body: WorkspaceLayout
|
|
63
69
|
): WorkspaceLayout {
|
|
64
|
-
const { name: _name, icon: _icon,
|
|
70
|
+
const { name: _name, icon: _icon, ...editor } = body
|
|
71
|
+
// Stale clients may still round-trip the pre-`.cache` thumbnail records;
|
|
72
|
+
// never let a layout PUT resurrect them in `.workspace.json`.
|
|
73
|
+
delete (editor as Record<string, unknown>).appletThumbnails
|
|
65
74
|
return {
|
|
66
75
|
...editor,
|
|
67
76
|
...(existing.name !== undefined && { name: existing.name }),
|
|
68
|
-
...(existing.icon !== undefined && { icon: existing.icon })
|
|
69
|
-
...(existing.widgetThumbnails !== undefined && {
|
|
70
|
-
widgetThumbnails: existing.widgetThumbnails
|
|
71
|
-
})
|
|
77
|
+
...(existing.icon !== undefined && { icon: existing.icon })
|
|
72
78
|
}
|
|
73
79
|
}
|
|
74
80
|
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
// theme saves never carry the base64 map, and a thumbnail save can't touch
|
|
78
|
-
// the grid. Entries merge over the existing map — removed widgets keep their
|
|
79
|
-
// last image.
|
|
80
|
-
export async function saveWidgetThumbnails(
|
|
81
|
-
workspacePath: string,
|
|
82
|
-
key: string,
|
|
83
|
-
images: Record<string, string>
|
|
84
|
-
): Promise<void> {
|
|
85
|
-
const existing = await loadLayout(workspacePath)
|
|
86
|
-
await saveLayout(
|
|
87
|
-
{
|
|
88
|
-
...existing,
|
|
89
|
-
widgetThumbnails: {
|
|
90
|
-
key,
|
|
91
|
-
// Server clock, so age-based invalidation doesn't trust client time.
|
|
92
|
-
at: new Date().toISOString(),
|
|
93
|
-
images: { ...existing.widgetThumbnails?.images, ...images }
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
workspacePath
|
|
97
|
-
)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Thumbnails for the home screen's workspace card: a few captured widget
|
|
101
|
-
// images from the stored layout (see saveWidgetThumbnails). The card renders
|
|
102
|
-
// them as a loose stack, so the cap just keeps the payload small — anything
|
|
103
|
-
// past it would hide under the pile anyway.
|
|
81
|
+
// Thumbnails for the home screen's workspace card. Widgets take the front
|
|
82
|
+
// slots in grid order, then recent views fill what remains.
|
|
104
83
|
const PREVIEW_LIMIT = 3
|
|
105
84
|
const PREVIEW_MESSAGE_LIMIT = 240
|
|
106
85
|
|
|
@@ -111,21 +90,37 @@ function normalizePreviewMessage(message: string | undefined): string | undefine
|
|
|
111
90
|
return `${normalized.slice(0, PREVIEW_MESSAGE_LIMIT - 1).trimEnd()}…`
|
|
112
91
|
}
|
|
113
92
|
|
|
114
|
-
export
|
|
115
|
-
workspacePath: string,
|
|
93
|
+
export type WorkspacePreviewOptions = {
|
|
116
94
|
getProviderPreview?: (includeFirstUserMessage: boolean) => Promise<{
|
|
117
95
|
firstUserMessage?: string
|
|
118
96
|
updatedAt?: number
|
|
119
97
|
}>
|
|
98
|
+
viewIds?: readonly string[]
|
|
99
|
+
// Maps a captured applet to the image URL the home card should render —
|
|
100
|
+
// the API layer owns the route shape (GET .../applet-thumbnails/:kind/:id).
|
|
101
|
+
thumbnailUrl: (kind: AppletKind, id: string) => string
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export async function getWorkspacePreview(
|
|
105
|
+
workspacePath: string,
|
|
106
|
+
{ getProviderPreview, viewIds = [], thumbnailUrl }: WorkspacePreviewOptions
|
|
120
107
|
): Promise<WorkspacePreview> {
|
|
121
108
|
try {
|
|
122
109
|
const layout = await loadLayout(workspacePath)
|
|
123
|
-
const
|
|
124
|
-
const
|
|
110
|
+
const captured = await getCapturedThumbnails(workspacePath)
|
|
111
|
+
const validViewIds = new Set(viewIds)
|
|
112
|
+
const capturedWidgets = new Set(
|
|
113
|
+
captured.filter(record => record.kind === 'widget').map(record => record.id)
|
|
114
|
+
)
|
|
115
|
+
const widgetImages = [...layout.widgetGrid]
|
|
125
116
|
.sort((a, b) => a.y - b.y || a.x - b.x)
|
|
126
|
-
.
|
|
127
|
-
.
|
|
128
|
-
|
|
117
|
+
.filter(item => capturedWidgets.has(item.i))
|
|
118
|
+
.map(item => thumbnailUrl('widget', item.i))
|
|
119
|
+
const viewImages = captured
|
|
120
|
+
.filter(record => record.kind === 'view' && validViewIds.has(record.id))
|
|
121
|
+
.sort((a, b) => Date.parse(b.viewedAt) - Date.parse(a.viewedAt))
|
|
122
|
+
.map(record => thumbnailUrl('view', record.id))
|
|
123
|
+
const thumbnails = [...widgetImages, ...viewImages].slice(0, PREVIEW_LIMIT)
|
|
129
124
|
// The message bubble is the card's fallback for "nothing to show": gate on
|
|
130
125
|
// captured thumbnails, not grid emptiness — a workspace with widgets that
|
|
131
126
|
// were never captured (never opened in a browser) still renders an empty
|
package/server/moi-scaffold.ts
CHANGED
|
@@ -49,6 +49,36 @@ async function runBunInstall(moiDir: string): Promise<number> {
|
|
|
49
49
|
return install.exited
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
// Keep machine-local state out of workspaces that are git repos: build output,
|
|
53
|
+
// derived caches (applet thumbnails), and installed dependencies are all
|
|
54
|
+
// re-creatable and would otherwise churn or bloat the repo. The applet sources,
|
|
55
|
+
// package.json, and lockfile stay committable — they ARE the workspace.
|
|
56
|
+
const REQUIRED_IGNORES = ['.build/', '.cache/', 'node_modules/'] as const
|
|
57
|
+
|
|
58
|
+
export const MOI_GITIGNORE = `# moi internals — machine-local, re-creatable state
|
|
59
|
+
${REQUIRED_IGNORES.join('\n')}
|
|
60
|
+
`
|
|
61
|
+
|
|
62
|
+
// Create `.moi/.gitignore` when missing, or append required entries a
|
|
63
|
+
// pre-gitignore or hand-edited file lacks. Never rewrites existing content —
|
|
64
|
+
// user additions survive. Safe to call often; no-ops once the file is right.
|
|
65
|
+
export async function ensureMoiGitignore(workspacePath: string): Promise<void> {
|
|
66
|
+
const moiDir = join(workspacePath, '.moi')
|
|
67
|
+
if (!(await isDirectory(moiDir))) return
|
|
68
|
+
const path = join(moiDir, '.gitignore')
|
|
69
|
+
const file = Bun.file(path)
|
|
70
|
+
if (!(await file.exists())) {
|
|
71
|
+
await Bun.write(path, MOI_GITIGNORE)
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
const text = await file.text()
|
|
75
|
+
// Match entries with or without the trailing slash or a leading slash.
|
|
76
|
+
const present = new Set(text.split('\n').map(line => line.trim().replace(/^\/|\/$/g, '')))
|
|
77
|
+
const missing = REQUIRED_IGNORES.filter(entry => !present.has(entry.replace(/\/$/, '')))
|
|
78
|
+
if (missing.length === 0) return
|
|
79
|
+
await Bun.write(path, `${text.replace(/\n*$/, '\n')}${missing.join('\n')}\n`)
|
|
80
|
+
}
|
|
81
|
+
|
|
52
82
|
// Ambient types for applets (widgets & views). Editor DX only — the moi
|
|
53
83
|
// bundler resolves the `moi` module and asset imports at build time without any
|
|
54
84
|
// declarations. Lives at `.moi/` root, NOT inside widgets/views, so it isn't
|
|
@@ -134,12 +164,18 @@ export async function scaffoldMoiDir(
|
|
|
134
164
|
}
|
|
135
165
|
const moiDir = join(workspacePath, '.moi')
|
|
136
166
|
const packagePath = join(moiDir, 'package.json')
|
|
137
|
-
if (await Bun.file(packagePath).exists())
|
|
167
|
+
if (await Bun.file(packagePath).exists()) {
|
|
168
|
+
// Repair path: workspaces scaffolded before `.moi/.gitignore` existed pick
|
|
169
|
+
// it up on the next `moi init` instead of leaking cache files into git.
|
|
170
|
+
await ensureMoiGitignore(workspacePath)
|
|
171
|
+
return 'exists'
|
|
172
|
+
}
|
|
138
173
|
// A bare `.moi/` dir without package.json counts as not-bootstrapped —
|
|
139
174
|
// fill in the missing pieces.
|
|
140
175
|
|
|
141
176
|
await mkdir(join(moiDir, 'widgets'), { recursive: true })
|
|
142
177
|
await Bun.write(packagePath, JSON.stringify(MOI_PACKAGE_JSON, null, 2) + '\n')
|
|
178
|
+
await ensureMoiGitignore(workspacePath)
|
|
143
179
|
await writeAppletEnvDts(workspacePath)
|
|
144
180
|
|
|
145
181
|
const exited = installDependencies(moiDir)
|