moi-computer 0.12.0 → 0.12.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/README.md +1 -1
- package/client/AGENTS.md +2 -2
- package/client/api/app-ui-keys.ts +1 -1
- package/client/api/workspace-keys.ts +1 -3
- package/client/app/routes/WorkspaceRoute.tsx +2 -8
- package/client/features/applets/applet-runtime.ts +11 -13
- package/client/features/chat/ChatPanel.tsx +70 -49
- package/client/features/chat/ChatPopup.tsx +81 -8
- package/client/features/chat/applet-chat-intents.ts +31 -12
- package/client/features/chat/chat-send.ts +33 -1
- package/client/features/chat/chat-store.ts +10 -0
- package/client/features/chat/composer/ChatComposer.tsx +24 -27
- package/client/features/chat/composer/ModelPicker.tsx +3 -3
- package/client/features/chat/composer/useWorkspaceComposerState.tsx +3 -3
- package/client/features/chat/connection/chat-frames.ts +14 -7
- package/client/features/chat/messages/ChatEmptyState.tsx +33 -19
- package/client/features/chat/messages/MarkdownContent.tsx +3 -3
- package/client/features/chat/messages/fork-history.ts +14 -0
- package/client/features/chat/sessions/ChatSelector.tsx +138 -79
- package/client/features/chat/sessions/api.ts +109 -19
- package/client/features/chat/sessions/browser-tab-state.ts +30 -7
- package/client/features/chat/sessions/useSelectedSession.ts +217 -51
- package/client/features/chat/useChat.ts +43 -45
- package/client/features/collab/client.ts +10 -11
- package/client/features/collab/hooks.tsx +6 -11
- package/client/features/collab/host-state.ts +57 -128
- package/client/features/collab/provider.tsx +3 -3
- package/client/features/collab/testing/fake-engine.ts +6 -27
- package/client/features/collab/workspace-users-menu.tsx +3 -7
- package/client/features/drawings/{useViewBuilderSketch.ts → useViewSketch.ts} +7 -7
- package/client/features/home/HomePage.tsx +2 -2
- package/client/features/overview/Overview.tsx +3 -6
- package/client/features/overview/default/ViewsWidget.tsx +5 -12
- package/client/features/overview/default/registry.tsx +2 -4
- package/client/features/views/PendingViewScreen.tsx +279 -0
- package/client/features/views/ViewManager.tsx +10 -10
- package/client/features/views/api.ts +63 -130
- package/client/features/views/useViewActions.ts +151 -0
- package/client/features/views/useViewDrafts.ts +79 -0
- package/client/features/views/view-presentation.ts +4 -5
- package/client/features/views/view-submission.ts +88 -0
- package/client/features/workspace/WorkspaceMenu.tsx +63 -0
- package/client/features/workspace/WorkspaceScreen.tsx +180 -375
- package/client/features/workspace/browser-tab-state.ts +16 -9
- package/client/features/workspace/moi-context.ts +13 -15
- package/client/features/workspace/tab-resolution.ts +16 -29
- package/client/features/workspace/useWorkspaceNavigation.ts +146 -104
- package/client/index.tsx +5 -1
- package/client/runtime/useWorkspaceEvents.ts +7 -6
- package/client/store/ui.ts +25 -29
- package/dist/chunk-1zhnhy00.js +1 -0
- package/dist/chunk-27501vke.js +1 -0
- package/dist/{chunk-jf6czgrz.js → chunk-9xtv6djt.js} +2 -2
- package/dist/chunk-am1x230f.js +2 -0
- package/dist/{chunk-nez8sdta.js → chunk-darpsw65.js} +1 -1
- package/dist/{chunk-97eg9mjn.js → chunk-gps4qc38.js} +1 -1
- package/dist/{chunk-3a48fyf7.js → chunk-hzwr8dp8.js} +4 -4
- package/dist/{chunk-efdyz6xp.js → chunk-j905va8r.js} +1 -1
- package/dist/chunk-n33w9y38.js +10 -0
- package/dist/chunk-r63ks44z.js +68 -0
- package/dist/{chunk-vfpsc75k.js → chunk-vqpkqtdr.js} +1 -1
- package/dist/chunk-wd46nk26.css +1 -0
- package/dist/chunk-xgt7vxt9.js +1 -0
- package/dist/{chunk-z3byfve5.js → chunk-yvzhwtfa.js} +2 -2
- package/dist/index.html +1 -1
- package/lib/ids.ts +2 -5
- package/lib/moi-context.ts +100 -73
- package/lib/navigation.ts +48 -87
- package/lib/session-drafts.ts +10 -0
- package/lib/types.ts +64 -31
- package/lib/view-build-directives.ts +12 -0
- package/lib/workspace-layout.ts +1 -1
- package/lib/workspace-tabs.ts +12 -7
- package/package.json +3 -1
- package/server/agent-launcher.ts +27 -0
- package/server/api.ts +119 -209
- package/server/app-config.ts +21 -2
- package/server/applets/build-worker.ts +2 -1
- package/server/applets/view-source.ts +7 -1
- package/server/cli-env.ts +72 -50
- package/server/cli.ts +101 -64
- package/server/control.ts +82 -63
- package/server/data-dir.ts +13 -0
- package/server/functions.ts +2 -1
- package/server/harness/README.md +8 -0
- package/server/harness/acp/adapter.ts +2 -2
- package/server/harness/acp/client.ts +2 -1
- package/server/harness/acp/discovery.ts +3 -3
- package/server/harness/acp/session.ts +6 -9
- package/server/harness/claude-code/adapter.ts +13 -8
- package/server/harness/claude-code/auth.ts +3 -2
- package/server/harness/claude-code/cli.ts +3 -1
- package/server/harness/claude-code/git-worktree.ts +5 -2
- package/server/harness/claude-code/index.ts +5 -0
- package/server/harness/claude-code/mcp.ts +2 -0
- package/server/harness/claude-code/models.ts +2 -0
- package/server/harness/claude-code/session.ts +5 -34
- package/server/harness/claude-code/sessions.ts +8 -12
- package/server/harness/codex/NOTES.md +23 -4
- package/server/harness/codex/adapter.ts +5 -3
- package/server/harness/codex/client.ts +13 -21
- package/server/harness/codex/index.ts +18 -0
- package/server/harness/codex/session.ts +6 -14
- package/server/harness/codex/thread-list.ts +74 -0
- package/server/harness/fork.ts +12 -0
- package/server/harness/openclaw/adapter.ts +3 -3
- package/server/harness/openclaw/session.ts +2 -30
- package/server/harness/session-title.ts +12 -3
- package/server/harness/types.ts +8 -3
- package/server/moi-scaffold.ts +2 -1
- package/server/pending-views.ts +164 -0
- package/server/registry.ts +14 -4
- package/server/selected-session.ts +91 -44
- package/server/service.ts +16 -2
- package/server/session-archive.ts +32 -0
- package/server/session-config.ts +16 -111
- package/server/session-lifecycle.ts +17 -0
- package/server/session-store.ts +127 -0
- package/server/status.ts +3 -1
- package/server/tabs.ts +7 -10
- package/server/view-sessions.ts +267 -0
- package/server/views.ts +30 -41
- package/server/web.ts +47 -45
- package/server/workspace-env.ts +27 -0
- package/server/workspace-init.ts +6 -2
- package/workspace/.claude/skills/moi-workspace/SKILL.md +49 -20
- package/workspace/.claude/skills/moi-workspace/references/COLLAB.md +2 -5
- package/client/features/views/ViewBuilder.tsx +0 -239
- package/client/features/views/useViewBuilderActions.ts +0 -103
- package/client/features/views/useViewBuilderDrafts.ts +0 -68
- package/dist/chunk-2jncyq65.js +0 -1
- package/dist/chunk-e2q5ken7.js +0 -68
- package/dist/chunk-h2kj1ysj.js +0 -1
- package/dist/chunk-nzwgm8vc.css +0 -1
- package/dist/chunk-ph0h6h86.js +0 -1
- package/dist/chunk-ryg9z3kn.js +0 -10
- package/dist/chunk-tpn177bt.js +0 -2
- package/lib/view-builder-directives.ts +0 -16
- package/server/chat-selection.ts +0 -22
- package/server/view-builders.ts +0 -453
package/lib/workspace-tabs.ts
CHANGED
|
@@ -3,20 +3,25 @@ import type { WorkspaceTabId } from './types'
|
|
|
3
3
|
|
|
4
4
|
export function isWorkspaceTabId(value: unknown): value is WorkspaceTabId {
|
|
5
5
|
return (
|
|
6
|
-
value === 'agent' ||
|
|
7
6
|
value === 'overview' ||
|
|
8
7
|
value === 'scratchpad' ||
|
|
9
8
|
// Match the applet IDs accepted by the server's module routes.
|
|
10
|
-
(typeof value === 'string' && /^
|
|
9
|
+
(typeof value === 'string' && /^views\/[a-zA-Z0-9_-]+$/.test(value))
|
|
11
10
|
)
|
|
12
11
|
}
|
|
13
12
|
|
|
13
|
+
export function tabFromPath(path: string): WorkspaceTabId | undefined {
|
|
14
|
+
try {
|
|
15
|
+
const tab = decodeURIComponent(path)
|
|
16
|
+
return isWorkspaceTabId(tab) ? tab : undefined
|
|
17
|
+
} catch {
|
|
18
|
+
return undefined
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
14
22
|
export const viewTabId = (viewId: string): WorkspaceTabId => `views/${viewId}`
|
|
15
|
-
export const viewIdFromTab = (tab: WorkspaceTabId): string |
|
|
16
|
-
tab.startsWith('views/') ? tab.slice('views/'.length) :
|
|
17
|
-
export const viewBuilderTabId = (builderId: string): WorkspaceTabId => `view-builders/${builderId}`
|
|
18
|
-
export const viewBuilderIdFromTab = (tab: WorkspaceTabId): string | null =>
|
|
19
|
-
tab.startsWith('view-builders/') ? tab.slice('view-builders/'.length) : null
|
|
23
|
+
export const viewIdFromTab = (tab: WorkspaceTabId): string | undefined =>
|
|
24
|
+
tab.startsWith('views/') ? tab.slice('views/'.length) : undefined
|
|
20
25
|
|
|
21
26
|
// A record check shared by JSON boundary validators.
|
|
22
27
|
export function isParamsRecord(value: unknown): value is Record<string, unknown> {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "moi-computer",
|
|
3
|
-
"version": "0.12.0",
|
|
3
|
+
"version": "0.12.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",
|
|
@@ -123,8 +123,10 @@
|
|
|
123
123
|
"@types/react": "^19.2.18",
|
|
124
124
|
"@types/react-dom": "^19.2.7",
|
|
125
125
|
"@types/react-grid-layout": "^2.1.0",
|
|
126
|
+
"@types/react-resizable": "^3.0.8",
|
|
126
127
|
"date-fns": "^4.4.0",
|
|
127
128
|
"embla-carousel-react": "^8.6.0",
|
|
129
|
+
"linkedom": "0.18.12",
|
|
128
130
|
"oxfmt": "^0.54.0",
|
|
129
131
|
"oxlint": "^1.82.0",
|
|
130
132
|
"react-day-picker": "^10.0.1",
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Managed machines run moi and the agent as different OS users (see
|
|
2
|
+
// docs/config.md). `agentLauncher` in config.json names an executable
|
|
3
|
+
// that every agent process starts through: it switches to the agent's user,
|
|
4
|
+
// drops moi's powers, then execs the command. That covers harness CLIs,
|
|
5
|
+
// function workers, applet builds and dependency installs. Unset (every local
|
|
6
|
+
// install) spawns directly, exactly as before.
|
|
7
|
+
import { spawn } from 'node:child_process'
|
|
8
|
+
|
|
9
|
+
import type { Options } from '@anthropic-ai/claude-agent-sdk'
|
|
10
|
+
|
|
11
|
+
import { getAppConfig } from './app-config'
|
|
12
|
+
|
|
13
|
+
export function agentCommand(argv: readonly string[]): string[] {
|
|
14
|
+
const launcher = getAppConfig().agentLauncher
|
|
15
|
+
return launcher ? [launcher, ...argv] : [...argv]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Claude Code is started by the Agent SDK rather than by moi, so it goes
|
|
19
|
+
// through the launcher via the SDK's spawn hook. Undefined keeps the SDK's own
|
|
20
|
+
// spawn. stderr is inherited: the hook's process type has no stderr stream for
|
|
21
|
+
// the SDK to drain.
|
|
22
|
+
export function claudeCodeSpawn(): Options['spawnClaudeCodeProcess'] {
|
|
23
|
+
const launcher = getAppConfig().agentLauncher
|
|
24
|
+
if (!launcher) return undefined
|
|
25
|
+
return ({ command, args, cwd, env, signal }) =>
|
|
26
|
+
spawn(launcher, [command, ...args], { cwd, env, signal, stdio: ['pipe', 'pipe', 'inherit'] })
|
|
27
|
+
}
|
package/server/api.ts
CHANGED
|
@@ -13,25 +13,20 @@ import type {
|
|
|
13
13
|
AppletThumbnailBatch,
|
|
14
14
|
AppSettings,
|
|
15
15
|
HarnessAvailability,
|
|
16
|
-
SessionInfo,
|
|
17
16
|
SelectedSessionScope,
|
|
18
17
|
UploadInfo,
|
|
19
|
-
ViewBuilderInput,
|
|
20
18
|
WorkspaceAgent,
|
|
21
19
|
WorkspaceEntry,
|
|
22
20
|
WorkspaceType
|
|
23
21
|
} from '@/lib/types'
|
|
24
|
-
import
|
|
25
|
-
import { viewBuilderDirectives } from '@/lib/view-builder-directives'
|
|
22
|
+
import { isWorkspaceTabId } from '@/lib/workspace-tabs'
|
|
26
23
|
|
|
27
24
|
import { proxyUserState } from './collab/cloudflare-access'
|
|
28
|
-
import { getCollabReferencePath } from './collab/config'
|
|
29
25
|
import { collabManager } from './collab/manager'
|
|
30
26
|
import { agentStore } from './agent'
|
|
31
27
|
import { clientAppConfig, getAppConfig } from './app-config'
|
|
32
28
|
import { getAppSettings, pickAppSettingsPatch, saveAppSettings } from './app-settings'
|
|
33
29
|
import { appletForModule, recordAppletError } from './applet-log'
|
|
34
|
-
import { selectChatSession } from './chat-selection'
|
|
35
30
|
import { apiBaseFor, parseAppletTail, serveWorkspaceFile } from './applets'
|
|
36
31
|
import { applyEnvChanged } from './env-apply'
|
|
37
32
|
import { publishEvent } from './events'
|
|
@@ -46,7 +41,6 @@ import {
|
|
|
46
41
|
} from './thumbnails'
|
|
47
42
|
import { getClientFrameLog, getWireLog } from './harness/debug'
|
|
48
43
|
import { allHarnesses, harnessFor, isHarnessType } from './harness/registry'
|
|
49
|
-
import { broadcast } from './state'
|
|
50
44
|
import {
|
|
51
45
|
discoverWorkspaces,
|
|
52
46
|
getWorkspace,
|
|
@@ -59,14 +53,17 @@ import {
|
|
|
59
53
|
import { loadScratchpadDoc, saveScratchpadDoc } from './scratchpad'
|
|
60
54
|
import { MAX_ASSET_BYTES, scratchpadAssetFile, storeScratchpadAsset } from './scratchpad-assets'
|
|
61
55
|
import {
|
|
62
|
-
|
|
56
|
+
getPinnedSession,
|
|
63
57
|
getSelectedSession,
|
|
64
|
-
|
|
58
|
+
getWorkspaceSessionSelection,
|
|
59
|
+
pinSession,
|
|
65
60
|
saveSelectedSession
|
|
66
61
|
} from './selected-session'
|
|
67
62
|
import type { SelectedSessionUpdate } from './selected-session'
|
|
68
|
-
import {
|
|
63
|
+
import { saveSessionConfig } from './session-config'
|
|
69
64
|
import type { SessionConfigPatch } from './session-config'
|
|
65
|
+
import { getSessionRecord, withSessionRecords } from './session-store'
|
|
66
|
+
import { archiveWorkspaceSession } from './session-archive'
|
|
70
67
|
import { DIST_DIR, prebuilt } from './static'
|
|
71
68
|
import { getWorkspaceSkillsStatus, updateWorkspaceSkills } from './skill-update'
|
|
72
69
|
import { serveWorkspaceImagePreview } from './preview'
|
|
@@ -74,32 +71,30 @@ import { MAX_UPLOAD_BYTES, addUpload, addWorkspaceFileUpload, getUpload } from '
|
|
|
74
71
|
import { requiredEnvFor } from './required-env'
|
|
75
72
|
import {
|
|
76
73
|
deleteView,
|
|
77
|
-
|
|
74
|
+
listCompiledViews,
|
|
78
75
|
listViews,
|
|
79
76
|
serveView,
|
|
80
77
|
updateViewTitle,
|
|
81
78
|
ViewMutationError
|
|
82
79
|
} from './views'
|
|
83
80
|
import {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
} from './view-builders'
|
|
81
|
+
createPendingView,
|
|
82
|
+
discardPendingView,
|
|
83
|
+
getPendingView,
|
|
84
|
+
updatePendingView,
|
|
85
|
+
PendingViewError
|
|
86
|
+
} from './pending-views'
|
|
87
|
+
import { submitView, ViewStartupError } from './view-sessions'
|
|
92
88
|
import { listWidgets, serveWidget } from './widgets'
|
|
93
89
|
import { getWorkspaceConfig, setWorkspaceConfig } from './workspace-config'
|
|
94
90
|
import {
|
|
95
|
-
|
|
91
|
+
createdWorkspacesRoot,
|
|
96
92
|
provisionWorkspace,
|
|
97
93
|
validateWorkspaceFolderName
|
|
98
94
|
} from './workspace-init'
|
|
99
95
|
import { resolveWorkspaceImportMetadata } from './workspace-import'
|
|
100
96
|
import type { WorkspaceImportMetadata } from './workspace-import'
|
|
101
|
-
import { getWorkspaceEnvView,
|
|
102
|
-
import type { EnvUpdate } from './workspace-env'
|
|
97
|
+
import { getWorkspaceEnvView, parseEnvUpdate, updateWorkspaceEnv } from './workspace-env'
|
|
103
98
|
import {
|
|
104
99
|
getCachedUpdateStatus,
|
|
105
100
|
hasRunningAgentSessions,
|
|
@@ -178,7 +173,7 @@ one.use('*', withWorkspace)
|
|
|
178
173
|
|
|
179
174
|
one.get('/preview', async c => {
|
|
180
175
|
const ws = c.get('ws')
|
|
181
|
-
const views = await
|
|
176
|
+
const views = await listCompiledViews(ws.path)
|
|
182
177
|
return c.json(
|
|
183
178
|
await getWorkspacePreview(ws.path, {
|
|
184
179
|
getProviderPreview: includeFirstUserMessage =>
|
|
@@ -210,13 +205,34 @@ one.get('/views', c => listViews(c.get('ws').path))
|
|
|
210
205
|
one.patch('/views/:viewId', async c => {
|
|
211
206
|
const ws = c.get('ws')
|
|
212
207
|
const body = await c.req.json().catch(() => null)
|
|
208
|
+
if (await getPendingView(ws.path, c.req.param('viewId'))) {
|
|
209
|
+
try {
|
|
210
|
+
if (
|
|
211
|
+
typeof body?.requirements !== 'string' &&
|
|
212
|
+
typeof body?.title !== 'string' &&
|
|
213
|
+
typeof body?.icon !== 'string'
|
|
214
|
+
)
|
|
215
|
+
return c.text('Expected requirements, title, or icon', 400)
|
|
216
|
+
return c.json(
|
|
217
|
+
await updatePendingView(ws.id, ws.path, c.req.param('viewId'), {
|
|
218
|
+
requirements: typeof body.requirements === 'string' ? body.requirements : undefined,
|
|
219
|
+
title: typeof body.title === 'string' ? body.title.trim() : undefined,
|
|
220
|
+
icon: typeof body.icon === 'string' ? body.icon : undefined
|
|
221
|
+
})
|
|
222
|
+
)
|
|
223
|
+
} catch (error) {
|
|
224
|
+
if (error instanceof PendingViewError) return c.text(error.message, error.status)
|
|
225
|
+
throw error
|
|
226
|
+
}
|
|
227
|
+
}
|
|
213
228
|
const title = typeof body?.title === 'string' ? body.title.trim() : ''
|
|
214
229
|
if (!title) return c.text('Expected { title: string }', 400)
|
|
215
230
|
|
|
216
231
|
try {
|
|
217
232
|
return c.json(await updateViewTitle(publishEvent, ws.id, ws.path, c.req.param('viewId'), title))
|
|
218
233
|
} catch (error) {
|
|
219
|
-
if (error instanceof ViewMutationError
|
|
234
|
+
if (error instanceof ViewMutationError || error instanceof PendingViewError)
|
|
235
|
+
return c.text(error.message, error.status)
|
|
220
236
|
throw error
|
|
221
237
|
}
|
|
222
238
|
})
|
|
@@ -224,10 +240,20 @@ one.patch('/views/:viewId', async c => {
|
|
|
224
240
|
one.delete('/views/:viewId', async c => {
|
|
225
241
|
const ws = c.get('ws')
|
|
226
242
|
try {
|
|
227
|
-
|
|
243
|
+
const viewId = c.req.param('viewId')
|
|
244
|
+
if (await getPendingView(ws.path, viewId)) {
|
|
245
|
+
const active = new Set(
|
|
246
|
+
harnessFor(ws)
|
|
247
|
+
.activeSessions()
|
|
248
|
+
.filter(session => session.workspaceId === ws.id)
|
|
249
|
+
.map(session => session.sessionId)
|
|
250
|
+
)
|
|
251
|
+
await discardPendingView(ws, viewId, active)
|
|
252
|
+
} else await deleteView(publishEvent, ws, viewId)
|
|
228
253
|
return c.body(null, 204)
|
|
229
254
|
} catch (error) {
|
|
230
|
-
if (error instanceof ViewMutationError
|
|
255
|
+
if (error instanceof ViewMutationError || error instanceof PendingViewError)
|
|
256
|
+
return c.text(error.message, error.status)
|
|
231
257
|
throw error
|
|
232
258
|
}
|
|
233
259
|
})
|
|
@@ -239,80 +265,26 @@ one.get('/views/*', c => {
|
|
|
239
265
|
return serveView(name, file, ws.path, apiBaseFor(ws.id), c.req.header('if-none-match'))
|
|
240
266
|
})
|
|
241
267
|
|
|
242
|
-
|
|
243
|
-
return err instanceof ViewBuilderError ? { message: err.message, status: err.status } : null
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
function parseAvailableViewIcons(value: unknown): string[] | null {
|
|
247
|
-
if (!Array.isArray(value)) return null
|
|
248
|
-
const icons = value.filter(
|
|
249
|
-
(icon): icon is string =>
|
|
250
|
-
typeof icon === 'string' && /^[a-z0-9][a-z0-9-]*$/.test(icon) && icon.length <= 64
|
|
251
|
-
)
|
|
252
|
-
return icons.length > 0 ? [...new Set(icons)] : null
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
one.get('/view-builders', async c => {
|
|
256
|
-
const ws = c.get('ws')
|
|
257
|
-
const activeSessionIds = new Set(
|
|
258
|
-
allHarnesses()
|
|
259
|
-
.flatMap(h => h.activeSessions())
|
|
260
|
-
.filter(session => session.workspaceId === ws.id)
|
|
261
|
-
.map(session => session.sessionId)
|
|
262
|
-
)
|
|
263
|
-
const builders = await reconcileViewBuilders(
|
|
264
|
-
ws.id,
|
|
265
|
-
ws.path,
|
|
266
|
-
await getViewList(ws.path),
|
|
267
|
-
activeSessionIds
|
|
268
|
-
)
|
|
269
|
-
// Widget builders are record-only for now — reconciled server-side but kept
|
|
270
|
-
// out of the host's view-builder tab list until their UI lands.
|
|
271
|
-
return c.json({ builders: builders.filter(builder => builder.kind !== 'widget') })
|
|
272
|
-
})
|
|
273
|
-
|
|
274
|
-
one.post('/view-builders', async c => {
|
|
268
|
+
one.post('/views', async c => {
|
|
275
269
|
const ws = c.get('ws')
|
|
276
|
-
return c.json(await
|
|
270
|
+
return c.json(await createPendingView(ws.id, ws.path), 201)
|
|
277
271
|
})
|
|
278
272
|
|
|
279
|
-
one.
|
|
280
|
-
const ws = c.get('ws')
|
|
281
|
-
const body = await c.req.json<{ input?: Partial<ViewBuilderInput> }>()
|
|
282
|
-
if (typeof body?.input?.requirements !== 'string') {
|
|
283
|
-
return c.text('Expected { input: { requirements: string } }', 400)
|
|
284
|
-
}
|
|
285
|
-
try {
|
|
286
|
-
return c.json(
|
|
287
|
-
await updateViewBuilderInput(
|
|
288
|
-
ws.id,
|
|
289
|
-
ws.path,
|
|
290
|
-
c.req.param('builderId'),
|
|
291
|
-
body.input.requirements
|
|
292
|
-
)
|
|
293
|
-
)
|
|
294
|
-
} catch (err) {
|
|
295
|
-
const known = viewBuilderError(err)
|
|
296
|
-
if (known) return c.text(known.message, known.status)
|
|
297
|
-
throw err
|
|
298
|
-
}
|
|
299
|
-
})
|
|
300
|
-
|
|
301
|
-
one.post('/view-builders/:builderId/submit', async c => {
|
|
273
|
+
one.post('/views/:viewId/submit', async c => {
|
|
302
274
|
const ws = c.get('ws')
|
|
303
275
|
const body = await c.req.json<{
|
|
304
|
-
|
|
276
|
+
requirements?: string
|
|
277
|
+
sessionId?: string
|
|
305
278
|
optimisticId?: string
|
|
306
279
|
selectedSessionScope?: SelectedSessionScope
|
|
307
280
|
model?: string
|
|
308
281
|
effort?: string
|
|
309
282
|
fastMode?: boolean
|
|
310
283
|
stream?: boolean
|
|
311
|
-
availableIcons?: unknown
|
|
312
284
|
attachments?: unknown
|
|
313
285
|
}>()
|
|
314
|
-
if (typeof body?.
|
|
315
|
-
return c.text('Expected {
|
|
286
|
+
if (typeof body?.requirements !== 'string') {
|
|
287
|
+
return c.text('Expected { requirements: string }', 400)
|
|
316
288
|
}
|
|
317
289
|
if (body.optimisticId !== undefined && typeof body.optimisticId !== 'string') {
|
|
318
290
|
return c.text('Invalid optimisticId', 400)
|
|
@@ -324,8 +296,6 @@ one.post('/view-builders/:builderId/submit', async c => {
|
|
|
324
296
|
) {
|
|
325
297
|
return c.text('Invalid selectedSessionScope', 400)
|
|
326
298
|
}
|
|
327
|
-
const availableIcons = parseAvailableViewIcons(body.availableIcons)
|
|
328
|
-
if (!availableIcons) return c.text('Available view icons are required', 400)
|
|
329
299
|
const attachments = body.attachments ?? []
|
|
330
300
|
if (!isMessageAttachments(attachments)) return c.text('Invalid attachments', 400)
|
|
331
301
|
for (const attachment of attachments) {
|
|
@@ -337,65 +307,22 @@ one.post('/view-builders/:builderId/submit', async c => {
|
|
|
337
307
|
const availability = await workspaceTypeAvailability(ws.type ?? 'claude-code')
|
|
338
308
|
if (availability.status !== 'available') return c.text(availability.reason, 400)
|
|
339
309
|
try {
|
|
340
|
-
const
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
...(collabReference ? { collabReference } : {}),
|
|
353
|
-
activeTab: `view-builders/${builder.id}`,
|
|
354
|
-
directives: [
|
|
355
|
-
...viewBuilderDirectives(builder.id, availableIcons),
|
|
356
|
-
...(attachments.length > 0
|
|
357
|
-
? ['Use the attachments as reference material for the intended view.']
|
|
358
|
-
: [])
|
|
359
|
-
]
|
|
360
|
-
}
|
|
361
|
-
try {
|
|
362
|
-
await selectChatSession(ws, builder.sessionId, body.selectedSessionScope)
|
|
363
|
-
await harnessFor(ws).sendMessage({
|
|
364
|
-
workspaceId: ws.id,
|
|
365
|
-
workspacePath: ws.path,
|
|
366
|
-
sessionId: builder.sessionId,
|
|
367
|
-
isNew: true,
|
|
368
|
-
content: builder.input.requirements,
|
|
369
|
-
attachments,
|
|
370
|
-
context,
|
|
371
|
-
optimisticId: body.optimisticId,
|
|
372
|
-
model: typeof body.model === 'string' ? body.model : undefined,
|
|
373
|
-
effort: typeof body.effort === 'string' ? body.effort : undefined,
|
|
374
|
-
fastMode: typeof body.fastMode === 'boolean' ? body.fastMode : undefined,
|
|
375
|
-
stream: body.stream === true ? true : undefined,
|
|
376
|
-
agentId: ws.agentId
|
|
377
|
-
})
|
|
378
|
-
} catch (err) {
|
|
379
|
-
const message = err instanceof Error ? err.message : 'Could not start view builder'
|
|
380
|
-
await markViewBuilderWaiting(ws.id, ws.path, builder.id, message)
|
|
381
|
-
return c.text(message, 500)
|
|
382
|
-
}
|
|
383
|
-
return c.json(builder)
|
|
384
|
-
} catch (err) {
|
|
385
|
-
const known = viewBuilderError(err)
|
|
386
|
-
if (known) return c.text(known.message, known.status)
|
|
387
|
-
throw err
|
|
388
|
-
}
|
|
389
|
-
})
|
|
390
|
-
|
|
391
|
-
one.delete('/view-builders/:builderId', async c => {
|
|
392
|
-
const ws = c.get('ws')
|
|
393
|
-
try {
|
|
394
|
-
await deleteViewBuilder(ws.id, ws.path, c.req.param('builderId'))
|
|
395
|
-
return c.body(null, 204)
|
|
310
|
+
const result = await submitView(ws, c.req.param('viewId'), {
|
|
311
|
+
requirements: body.requirements,
|
|
312
|
+
sessionId: typeof body.sessionId === 'string' ? body.sessionId : undefined,
|
|
313
|
+
selectedSessionScope: body.selectedSessionScope,
|
|
314
|
+
attachments,
|
|
315
|
+
optimisticId: body.optimisticId,
|
|
316
|
+
model: typeof body.model === 'string' ? body.model : undefined,
|
|
317
|
+
effort: typeof body.effort === 'string' ? body.effort : undefined,
|
|
318
|
+
fastMode: typeof body.fastMode === 'boolean' ? body.fastMode : undefined,
|
|
319
|
+
stream: body.stream === true ? true : undefined
|
|
320
|
+
})
|
|
321
|
+
return c.json(result)
|
|
396
322
|
} catch (err) {
|
|
397
|
-
|
|
398
|
-
if (
|
|
323
|
+
if (err instanceof PendingViewError) return c.text(err.message, err.status)
|
|
324
|
+
if (err instanceof ViewStartupError)
|
|
325
|
+
return c.json({ error: err.message, viewId: err.viewId, sessionId: err.sessionId }, 500)
|
|
399
326
|
throw err
|
|
400
327
|
}
|
|
401
328
|
})
|
|
@@ -558,27 +485,35 @@ one.get('/uploads/:uploadId', c => {
|
|
|
558
485
|
|
|
559
486
|
one.get('/sessions', async c => {
|
|
560
487
|
const ws = c.get('ws')
|
|
561
|
-
return c.json(await harnessFor(ws).listSessions(ws))
|
|
488
|
+
return c.json(await withSessionRecords(ws.path, await harnessFor(ws).listSessions(ws)))
|
|
562
489
|
})
|
|
563
490
|
|
|
564
491
|
one.get('/selected-session', async c => {
|
|
492
|
+
return c.json(await getWorkspaceSessionSelection(c.get('ws').path))
|
|
493
|
+
})
|
|
494
|
+
|
|
495
|
+
one.put('/pinned-session', async c => {
|
|
565
496
|
const ws = c.get('ws')
|
|
566
|
-
|
|
567
|
-
if (sessionId
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
(session.lastModified === current.lastModified &&
|
|
574
|
-
session.sessionId.localeCompare(current.sessionId) < 0)
|
|
575
|
-
? session
|
|
576
|
-
: current,
|
|
577
|
-
undefined
|
|
497
|
+
const body = await c.req.json<{ sessionId: string | null }>()
|
|
498
|
+
if (body.sessionId !== null && typeof body.sessionId !== 'string')
|
|
499
|
+
return c.text('Invalid chat', 400)
|
|
500
|
+
if (body.sessionId) {
|
|
501
|
+
const harness = harnessFor(ws)
|
|
502
|
+
const found = (await harness.listSessions(ws)).some(
|
|
503
|
+
session => session.sessionId === body.sessionId
|
|
578
504
|
)
|
|
579
|
-
|
|
505
|
+
const active = harness
|
|
506
|
+
.activeSessions()
|
|
507
|
+
.some(session => session.workspaceId === ws.id && session.sessionId === body.sessionId)
|
|
508
|
+
if (!found && !active) return c.text('Chat not found', 404)
|
|
580
509
|
}
|
|
581
|
-
|
|
510
|
+
await pinSession(ws.path, body.sessionId)
|
|
511
|
+
publishEvent({
|
|
512
|
+
type: 'selected-session:updated',
|
|
513
|
+
workspaceId: ws.id,
|
|
514
|
+
sessionId: (await getSelectedSession(ws.path)) ?? null
|
|
515
|
+
})
|
|
516
|
+
return c.json({ pinnedSessionId: body.sessionId })
|
|
582
517
|
})
|
|
583
518
|
|
|
584
519
|
one.put('/selected-session', async c => {
|
|
@@ -586,7 +521,10 @@ one.put('/selected-session', async c => {
|
|
|
586
521
|
const body: unknown = await c.req.json().catch(() => null)
|
|
587
522
|
if (!body || typeof body !== 'object') return c.text('Bad request', 400)
|
|
588
523
|
|
|
589
|
-
const input = body as { sessionId?: unknown; previousSessionId?: unknown }
|
|
524
|
+
const input = body as { sessionId?: unknown; previousSessionId?: unknown; tabId?: unknown }
|
|
525
|
+
const tabId = input.tabId ?? 'overview'
|
|
526
|
+
if (!isWorkspaceTabId(tabId)) return c.text('Invalid chat tab', 400)
|
|
527
|
+
if (await getPinnedSession(ws.path)) return c.text('Unpin chat before switching', 409)
|
|
590
528
|
const validSessionId = input.sessionId === null || typeof input.sessionId === 'string'
|
|
591
529
|
const hasPreviousSessionId = Object.prototype.hasOwnProperty.call(input, 'previousSessionId')
|
|
592
530
|
const validPreviousSessionId =
|
|
@@ -598,7 +536,8 @@ one.put('/selected-session', async c => {
|
|
|
598
536
|
const update = await saveSelectedSession(
|
|
599
537
|
ws.path,
|
|
600
538
|
input.sessionId as string | null,
|
|
601
|
-
hasPreviousSessionId ? (input.previousSessionId as string | null) : undefined
|
|
539
|
+
hasPreviousSessionId ? (input.previousSessionId as string | null) : undefined,
|
|
540
|
+
tabId
|
|
602
541
|
)
|
|
603
542
|
publishSelectedSession(ws.id, update)
|
|
604
543
|
return c.json({ sessionId: update.sessionId })
|
|
@@ -611,10 +550,7 @@ one.post('/sessions/:sessionId/archive', async c => {
|
|
|
611
550
|
if (!harness.archiveSession) return c.text('Chat archiving is not supported', 501)
|
|
612
551
|
|
|
613
552
|
try {
|
|
614
|
-
await
|
|
615
|
-
await harness.archiveSession(ws, sessionId)
|
|
616
|
-
publishSelectedSession(ws.id, await clearSelectedSession(ws.path, sessionId))
|
|
617
|
-
broadcast(ws.id, { type: 'sessions_changed', sessionId })
|
|
553
|
+
await archiveWorkspaceSession(ws, sessionId)
|
|
618
554
|
return c.body(null, 204)
|
|
619
555
|
} catch (error) {
|
|
620
556
|
console.error(`[api] archive chat failed for ${harness.id}`, error)
|
|
@@ -628,17 +564,15 @@ one.post('/sessions/:sessionId/archive', async c => {
|
|
|
628
564
|
|
|
629
565
|
one.get('/sessions/:sessionId/events', async c => {
|
|
630
566
|
const ws = c.get('ws')
|
|
631
|
-
|
|
567
|
+
const sessionId = c.req.param('sessionId')
|
|
568
|
+
return c.json(await harnessFor(ws).sessionEvents(ws, sessionId))
|
|
632
569
|
})
|
|
633
570
|
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
// defaults); PUT patches it (a field as `null` clears it, omitted leaves it).
|
|
637
|
-
// The change takes effect on the session's next message.
|
|
638
|
-
one.get('/sessions/:sessionId/config', async c => {
|
|
639
|
-
return c.json(await getSessionConfig(c.get('ws').path, c.req.param('sessionId')))
|
|
571
|
+
one.get('/sessions/:sessionId', async c => {
|
|
572
|
+
return c.json(await getSessionRecord(c.get('ws').path, c.req.param('sessionId')))
|
|
640
573
|
})
|
|
641
574
|
|
|
575
|
+
// Patch run settings and return the complete session record. null clears a setting.
|
|
642
576
|
one.put('/sessions/:sessionId/config', async c => {
|
|
643
577
|
const body = await c.req.json().catch(() => null)
|
|
644
578
|
if (typeof body !== 'object' || body === null) {
|
|
@@ -661,7 +595,10 @@ one.put('/sessions/:sessionId/config', async c => {
|
|
|
661
595
|
}
|
|
662
596
|
patch.fastMode = value
|
|
663
597
|
}
|
|
664
|
-
|
|
598
|
+
const workspacePath = c.get('ws').path
|
|
599
|
+
const sessionId = c.req.param('sessionId')
|
|
600
|
+
await saveSessionConfig(workspacePath, sessionId, patch)
|
|
601
|
+
return c.json(await getSessionRecord(workspacePath, sessionId))
|
|
665
602
|
})
|
|
666
603
|
|
|
667
604
|
one.get('/mcp', async c => {
|
|
@@ -701,35 +638,8 @@ one.get('/env', async c => {
|
|
|
701
638
|
// the only way).
|
|
702
639
|
one.put('/env', async c => {
|
|
703
640
|
const ws = c.get('ws')
|
|
704
|
-
const
|
|
705
|
-
if (
|
|
706
|
-
return c.text('Bad request', 400)
|
|
707
|
-
}
|
|
708
|
-
const patch: EnvUpdate = {}
|
|
709
|
-
if (body.set !== undefined) {
|
|
710
|
-
if (typeof body.set !== 'object' || body.set === null) {
|
|
711
|
-
return c.text('set must be an object', 400)
|
|
712
|
-
}
|
|
713
|
-
for (const [k, v] of Object.entries(body.set)) {
|
|
714
|
-
if (!isValidEnvKey(k)) return c.text(`Invalid env key: ${k}`, 400)
|
|
715
|
-
if (typeof v !== 'string') {
|
|
716
|
-
return c.text(`Value for ${k} must be a string`, 400)
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
patch.set = body.set as Record<string, string>
|
|
720
|
-
}
|
|
721
|
-
if (body.remove !== undefined) {
|
|
722
|
-
if (!Array.isArray(body.remove) || body.remove.some((k: unknown) => typeof k !== 'string')) {
|
|
723
|
-
return c.text('remove must be an array of strings', 400)
|
|
724
|
-
}
|
|
725
|
-
patch.remove = body.remove as string[]
|
|
726
|
-
}
|
|
727
|
-
if (body.inheritDotenv !== undefined) {
|
|
728
|
-
if (typeof body.inheritDotenv !== 'boolean') {
|
|
729
|
-
return c.text('inheritDotenv must be a boolean', 400)
|
|
730
|
-
}
|
|
731
|
-
patch.inheritDotenv = body.inheritDotenv
|
|
732
|
-
}
|
|
641
|
+
const patch = parseEnvUpdate(await c.req.json().catch(() => null))
|
|
642
|
+
if (typeof patch === 'string') return c.text(patch, 400)
|
|
733
643
|
|
|
734
644
|
// Skip the write + reaps for a no-op PUT (no recognized fields) so an empty
|
|
735
645
|
// body doesn't needlessly kill warm workers / idle sessions.
|
|
@@ -1105,13 +1015,13 @@ async function harnessAvailability(): Promise<Record<string, HarnessAvailability
|
|
|
1105
1015
|
// backends whose runtime is missing.
|
|
1106
1016
|
workspaces.get('/create', async c =>
|
|
1107
1017
|
c.json({
|
|
1108
|
-
root:
|
|
1109
|
-
displayRoot: tildify(
|
|
1018
|
+
root: createdWorkspacesRoot(),
|
|
1019
|
+
displayRoot: tildify(createdWorkspacesRoot()),
|
|
1110
1020
|
availability: await harnessAvailability()
|
|
1111
1021
|
})
|
|
1112
1022
|
)
|
|
1113
1023
|
|
|
1114
|
-
// Create a brand-new workspace: a fresh folder under
|
|
1024
|
+
// Create a brand-new workspace: a fresh folder under createdWorkspacesRoot(),
|
|
1115
1025
|
// provisioned (skills + `.moi/` scaffold) and registered.
|
|
1116
1026
|
workspaces.post('/create', async c => {
|
|
1117
1027
|
if (getAppConfig().cloudDemo) return c.text(DEMO_CREATE_BLOCKED, 403)
|
|
@@ -1129,7 +1039,7 @@ workspaces.post('/create', async c => {
|
|
|
1129
1039
|
const name = typeof body?.name === 'string' ? body.name.trim() : ''
|
|
1130
1040
|
const invalid = validateWorkspaceFolderName(name)
|
|
1131
1041
|
if (invalid) return c.text(invalid, 400)
|
|
1132
|
-
const path = join(
|
|
1042
|
+
const path = join(createdWorkspacesRoot(), name)
|
|
1133
1043
|
if (existsSync(path)) return c.text('A folder with that name already exists', 409)
|
|
1134
1044
|
try {
|
|
1135
1045
|
await provisionWorkspace(path, type)
|
package/server/app-config.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs'
|
|
2
|
-
import { join } from 'path'
|
|
2
|
+
import { isAbsolute, join } from 'path'
|
|
3
3
|
|
|
4
4
|
import type { ClientAppConfig, ExperimentalFeatures } from '@/lib/types'
|
|
5
5
|
import { EXPERIMENTAL_DEFAULTS } from '@/lib/experimental'
|
|
@@ -27,6 +27,16 @@ export type AppConfig = {
|
|
|
27
27
|
// Cloudflare Access (Zero Trust) in front of this deployment: each viewer
|
|
28
28
|
// inherits the user profile from Access's signed token. Null trusts no proxy.
|
|
29
29
|
cloudflareAccess: CloudflareAccessConfig | null
|
|
30
|
+
// Managed machines (one per organization) run moi and the agent as
|
|
31
|
+
// different OS users; see docs/config.md. These three are read
|
|
32
|
+
// from config.json only, with no env override, so the machine's start
|
|
33
|
+
// script, which writes the file, is the only thing deciding them.
|
|
34
|
+
// Folder that `/workspace/create` puts new workspaces in; null is `~/moi`.
|
|
35
|
+
workspacesDir: string | null
|
|
36
|
+
// Executable every agent process starts through (see agent-launcher.ts).
|
|
37
|
+
agentLauncher: string | null
|
|
38
|
+
// Unix socket file the web side listens on instead of PORT.
|
|
39
|
+
unixSocket: string | null
|
|
30
40
|
}
|
|
31
41
|
|
|
32
42
|
export type CloudflareAccessConfig = {
|
|
@@ -42,7 +52,10 @@ const DEFAULTS: AppConfig = {
|
|
|
42
52
|
cloudDemo: false,
|
|
43
53
|
experimental: { ...EXPERIMENTAL_DEFAULTS },
|
|
44
54
|
demoInstallUrl: 'https://moi.computer',
|
|
45
|
-
cloudflareAccess: null
|
|
55
|
+
cloudflareAccess: null,
|
|
56
|
+
workspacesDir: null,
|
|
57
|
+
agentLauncher: null,
|
|
58
|
+
unixSocket: null
|
|
46
59
|
}
|
|
47
60
|
|
|
48
61
|
export const APP_CONFIG_FILE = join(DATA_DIR, 'config.json')
|
|
@@ -184,6 +197,12 @@ function fileValues(raw: Record<string, unknown>): Partial<DeploymentConfig> {
|
|
|
184
197
|
if (typeof raw.demoInstallUrl === 'string') out.demoInstallUrl = raw.demoInstallUrl
|
|
185
198
|
else warn('ignoring "demoInstallUrl" — expected a string')
|
|
186
199
|
}
|
|
200
|
+
for (const key of ['workspacesDir', 'agentLauncher', 'unixSocket'] as const) {
|
|
201
|
+
const value = raw[key]
|
|
202
|
+
if (value === undefined || value === null) continue
|
|
203
|
+
if (typeof value === 'string' && isAbsolute(value)) out[key] = value
|
|
204
|
+
else warn(`ignoring "${key}" — expected an absolute path`)
|
|
205
|
+
}
|
|
187
206
|
return out
|
|
188
207
|
}
|
|
189
208
|
|
|
@@ -34,6 +34,7 @@ import { join } from 'path'
|
|
|
34
34
|
|
|
35
35
|
import type { AppletKind, ViewConfig, WidgetConfig } from '@/lib/types'
|
|
36
36
|
|
|
37
|
+
import { agentCommand } from '../agent-launcher'
|
|
37
38
|
import { buildApplet } from './build-applet'
|
|
38
39
|
|
|
39
40
|
export type BuildJob = {
|
|
@@ -130,7 +131,7 @@ export function buildAppletsInChild(req: Omit<BuildRequest, 'type'>): Promise<Bu
|
|
|
130
131
|
resolve(results)
|
|
131
132
|
}
|
|
132
133
|
const request: BuildRequest = { type: 'build', ...req }
|
|
133
|
-
const proc = Bun.spawn([process.execPath, WORKER_PATH], {
|
|
134
|
+
const proc = Bun.spawn(agentCommand([process.execPath, WORKER_PATH]), {
|
|
134
135
|
stdio: ['ignore', 'inherit', 'inherit'],
|
|
135
136
|
serialization: 'json',
|
|
136
137
|
ipc(message, child) {
|