moi-computer 0.13.1-next.2 → 0.13.1-next.3
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/chat/sessions/use-selected-session.ts +0 -13
- package/client/features/views/api.ts +33 -8
- package/client/features/views/use-view-actions.ts +2 -23
- package/client/features/workspace/tab-resolution.ts +1 -8
- package/client/features/workspace/use-workspace-navigation.ts +4 -3
- package/client/features/workspace/workspace-content.tsx +2 -11
- package/client/features/workspace/workspace-preferences.ts +67 -10
- package/client/features/workspace/workspace-state.ts +40 -15
- package/client/store/ui.ts +1 -6
- package/client/store/workspace-session.ts +30 -0
- package/dist/chunk-0h4zypgf.js +1 -0
- package/dist/chunk-1tksq43z.js +72 -0
- package/dist/chunk-6gxf0xr8.js +5 -0
- package/dist/{chunk-ec5ennpv.js → chunk-a865c7x4.js} +1 -1
- package/dist/{chunk-pdt9hxfw.js → chunk-f44cs6mw.js} +2 -2
- package/dist/{chunk-44khk4sp.js → chunk-h3qag4a6.js} +2 -2
- package/dist/{chunk-ectsnw81.js → chunk-q2tpy0h7.js} +2 -2
- package/dist/{chunk-rmd0ctfx.js → chunk-r95acex1.js} +74 -74
- package/dist/chunk-w5h9grdr.js +1 -0
- package/dist/{chunk-n0fawy9x.js → chunk-xj1pjhng.js} +1 -1
- package/dist/index.html +1 -1
- package/lib/moi-context.ts +19 -5
- package/lib/types.ts +4 -5
- package/lib/workspace-layout.ts +3 -20
- package/package.json +2 -1
- package/server/AGENTS.md +1 -1
- package/server/README.md +21 -18
- package/server/api/index.ts +122 -118
- package/server/cli/commands/init.ts +7 -2
- package/server/cli/commands/remote.ts +128 -26
- package/server/cli/remote-control.ts +12 -9
- package/server/cli/remote-operations.ts +47 -44
- package/server/control.ts +9 -1
- package/server/onboarding/jobs.ts +1 -1
- package/server/remote/broker-client.ts +76 -0
- package/server/remote/broker.ts +81 -0
- package/server/remote/client.ts +212 -152
- package/server/remote/errors.ts +2 -0
- package/server/remote/routes.ts +121 -0
- package/server/scratchpad/document.ts +3 -2
- package/server/sessions/pending-views.ts +2 -1
- package/server/sessions/send-message.ts +102 -0
- package/server/sessions/view-sessions.ts +4 -94
- package/server/web.ts +2 -1
- package/server/workspace-state/file.ts +2 -0
- package/server/workspaces/api.ts +4 -8
- package/server/workspaces/tabs.ts +1 -2
- package/skill/SKILL.md +75 -34
- package/skill/references/SCRATCHPAD.md +4 -0
- package/skill/references/UI-COMPONENTS.md +1 -1
- package/dist/chunk-ba6mz56s.js +0 -72
- package/dist/chunk-en7w5ypg.js +0 -1
- package/dist/chunk-f695wcx5.js +0 -5
- package/dist/chunk-zv22wv0g.js +0 -1
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { parse } from 'regexparam'
|
|
2
|
+
import {
|
|
3
|
+
parseRemoteWorkspaceAddress,
|
|
4
|
+
parseRemoteWorkspaceTarget,
|
|
5
|
+
workspaceAddress,
|
|
6
|
+
type RemoteWorkspaceTarget
|
|
7
|
+
} from '@/lib/workspace-config'
|
|
8
|
+
|
|
9
|
+
// Every Cloud request the CLI may make: its methods, the pattern that allows
|
|
10
|
+
// it, and the function callers use to write its path. The CLI checks a request
|
|
11
|
+
// against this table before sending, and the running server checks it again
|
|
12
|
+
// before lending its login to a caller (broker.ts).
|
|
13
|
+
//
|
|
14
|
+
// `api/…` is sent relative to the Cloud URL; `/api/workspaces/…` goes to the
|
|
15
|
+
// owner's workspace API at its origin. Sign-in itself (login, token refresh,
|
|
16
|
+
// logout, agent join) uses fixed URLs in client.ts and never comes through here.
|
|
17
|
+
|
|
18
|
+
type Access = 'any login' | 'own login'
|
|
19
|
+
type Workspace = RemoteWorkspaceTarget
|
|
20
|
+
|
|
21
|
+
const refused = () => new Error('This Cloud request is not allowed')
|
|
22
|
+
|
|
23
|
+
function route<Args extends unknown[]>(
|
|
24
|
+
methods: string,
|
|
25
|
+
pattern: string,
|
|
26
|
+
path: (...args: Args) => string,
|
|
27
|
+
/** 'own login' requests are never sent with a login lent by the server. */
|
|
28
|
+
access: Access = 'any login'
|
|
29
|
+
) {
|
|
30
|
+
const [pathname = '', query = ''] = pattern.split('?')
|
|
31
|
+
return { methods: methods.split(' '), ...parse(pathname), pathname, query, path, access }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const address = (workspace: Workspace) => {
|
|
35
|
+
const { workspace_id, user_id } = parseRemoteWorkspaceTarget(workspace)
|
|
36
|
+
return workspaceAddress(workspace_id, user_id)
|
|
37
|
+
}
|
|
38
|
+
const cloud = (workspace: Workspace) => `api/workspaces/${address(workspace)}`
|
|
39
|
+
const owner = (workspace: Workspace) => `/api/workspaces/${address(workspace)}`
|
|
40
|
+
// A file path relative to the workspace root, one encoded segment per name.
|
|
41
|
+
function encodePath(file: string) {
|
|
42
|
+
const names = file.split('/')
|
|
43
|
+
if (names.some(name => !name || name === '.' || name === '..' || name.includes('\\')))
|
|
44
|
+
throw new Error('Use a file path relative to the remote workspace')
|
|
45
|
+
return names.map(encodeURIComponent).join('/')
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const CLOUD = 'api/workspaces/:workspace'
|
|
49
|
+
const OWNER = '/api/workspaces/:workspace'
|
|
50
|
+
|
|
51
|
+
export const cloudRoutes = {
|
|
52
|
+
// Account
|
|
53
|
+
me: route('GET', 'api/me', () => 'api/me'),
|
|
54
|
+
sharedWorkspaces: route('GET', 'api/workspaces/shared', () => 'api/workspaces/shared'),
|
|
55
|
+
invitations: route('GET', 'api/workspaces/invitations', () => 'api/workspaces/invitations'),
|
|
56
|
+
// Changes to the account itself stay with whoever holds the login.
|
|
57
|
+
renameAgent: route('PATCH', 'api/me', () => 'api/me', 'own login'),
|
|
58
|
+
acceptInvitation: route(
|
|
59
|
+
'POST',
|
|
60
|
+
'api/invitations/:id/accept',
|
|
61
|
+
(id: string) => `api/invitations/${encodePath(id)}/accept`,
|
|
62
|
+
'own login'
|
|
63
|
+
),
|
|
64
|
+
leave: route('POST', `${CLOUD}/leave`, (w: Workspace) => `${cloud(w)}/leave`, 'own login'),
|
|
65
|
+
// Operations on the owner's machine
|
|
66
|
+
exec: route('POST', `${CLOUD}/ops/exec`, (w: Workspace) => `${cloud(w)}/ops/exec`),
|
|
67
|
+
commands: route('POST', `${CLOUD}/ops/commands`, (w: Workspace) => `${cloud(w)}/ops/commands`),
|
|
68
|
+
files: route(
|
|
69
|
+
'GET PUT PATCH',
|
|
70
|
+
`${CLOUD}/ops/files/*`,
|
|
71
|
+
(w: Workspace, file: string) => `${cloud(w)}/ops/files/${encodePath(file)}`
|
|
72
|
+
),
|
|
73
|
+
// Owner's workspace API
|
|
74
|
+
views: route(
|
|
75
|
+
'GET',
|
|
76
|
+
`${OWNER}/views?includePending=true`,
|
|
77
|
+
(w: Workspace) => `${owner(w)}/views?includePending=true`
|
|
78
|
+
),
|
|
79
|
+
compiledViews: route('GET', `${OWNER}/views`, (w: Workspace) => `${owner(w)}/views`),
|
|
80
|
+
config: route('GET PUT', `${OWNER}/config`, (w: Workspace) => `${owner(w)}/config`),
|
|
81
|
+
icon: route('PUT DELETE', `${OWNER}/icon`, (w: Workspace) => `${owner(w)}/icon`),
|
|
82
|
+
scratchpad: route('GET', `${OWNER}/scratchpad`, (w: Workspace) => `${owner(w)}/scratchpad`),
|
|
83
|
+
scratchpadOps: route(
|
|
84
|
+
'POST',
|
|
85
|
+
`${OWNER}/scratchpad/ops`,
|
|
86
|
+
(w: Workspace) => `${owner(w)}/scratchpad/ops`
|
|
87
|
+
),
|
|
88
|
+
scratchpadAsset: route(
|
|
89
|
+
'GET',
|
|
90
|
+
`${OWNER}/scratchpad/assets/:name`,
|
|
91
|
+
(w: Workspace, name: string) => `${owner(w)}/scratchpad/assets/${encodePath(name)}`
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Spellings that make a path resolve somewhere other than where it reads:
|
|
96
|
+
// dot segments, empty segments, backslashes, and their encoded forms. None
|
|
97
|
+
// appears in a path built above.
|
|
98
|
+
const UNSAFE = /(^|\/)\.\.?(\/|\?|$)|\/\/|\\|%2e|%2f|%5c/i
|
|
99
|
+
|
|
100
|
+
export type AllowedCloudRequest = { workspace?: Workspace; access: Access }
|
|
101
|
+
|
|
102
|
+
/** Throws unless the request is listed; names the workspace it addresses, if any. */
|
|
103
|
+
export function allowedCloudRequest(method: string, path: string): AllowedCloudRequest {
|
|
104
|
+
if (UNSAFE.test(path)) throw refused()
|
|
105
|
+
const [pathname = '', query = ''] = path.split('?')
|
|
106
|
+
for (const route of Object.values(cloudRoutes)) {
|
|
107
|
+
if (!route.methods.includes(method.toUpperCase()) || route.query !== query) continue
|
|
108
|
+
// regexparam ignores a leading slash, and here it says where the request goes.
|
|
109
|
+
if (route.pathname.startsWith('/') !== pathname.startsWith('/')) continue
|
|
110
|
+
const found = route.pattern.exec(pathname.replace(/^\/?/, '/'))
|
|
111
|
+
if (!found) continue
|
|
112
|
+
const workspace = found[route.keys.indexOf('workspace') + 1]
|
|
113
|
+
if (!route.keys.includes('workspace')) return { access: route.access }
|
|
114
|
+
try {
|
|
115
|
+
return { access: route.access, workspace: parseRemoteWorkspaceAddress(workspace ?? '') }
|
|
116
|
+
} catch {
|
|
117
|
+
throw refused()
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
throw refused()
|
|
121
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { WorkspaceApiTarget } from '../workspaces/api'
|
|
2
2
|
import { requestWorkspace } from '../workspaces/api'
|
|
3
|
+
import { cloudRoutes } from '../remote/routes'
|
|
3
4
|
import { readdir } from 'node:fs/promises'
|
|
4
5
|
import { join } from 'path'
|
|
5
6
|
|
|
@@ -294,7 +295,7 @@ export async function readScratchpadShapes(
|
|
|
294
295
|
async function readSnapshot(workspace: string | WorkspaceApiTarget): Promise<ScratchpadSnapshot> {
|
|
295
296
|
return typeof workspace === 'string'
|
|
296
297
|
? loadScratchpadDoc(workspace)
|
|
297
|
-
: (await requestWorkspace(workspace
|
|
298
|
+
: (await requestWorkspace(cloudRoutes.scratchpad.path(workspace.remote))).json()
|
|
298
299
|
}
|
|
299
300
|
|
|
300
301
|
async function readAsset(
|
|
@@ -303,7 +304,7 @@ async function readAsset(
|
|
|
303
304
|
): Promise<Blob | undefined> {
|
|
304
305
|
if (typeof workspace !== 'string')
|
|
305
306
|
return (
|
|
306
|
-
await requestWorkspace(workspace,
|
|
307
|
+
await requestWorkspace(cloudRoutes.scratchpadAsset.path(workspace.remote, fileName))
|
|
307
308
|
).blob()
|
|
308
309
|
const asset = scratchpadAssetFile(workspace, fileName)
|
|
309
310
|
if (!asset || !(await asset.file.exists())) return undefined
|
|
@@ -3,6 +3,7 @@ import { newViewId } from '@/lib/ids'
|
|
|
3
3
|
import type { PendingView, WorkspaceEntry, WorkspaceState } from '@/lib/types'
|
|
4
4
|
import { readWorkspaceState, updateWorkspaceState, type WorkspaceRef } from '../workspace-state'
|
|
5
5
|
import { requestWorkspace } from '../workspaces/api'
|
|
6
|
+
import { cloudRoutes } from '../remote/routes'
|
|
6
7
|
import { archiveViewSessions } from './archive'
|
|
7
8
|
|
|
8
9
|
export class PendingViewError extends Error {
|
|
@@ -114,7 +115,7 @@ export async function completeViewBuild(ws: WorkspaceRef, id: string) {
|
|
|
114
115
|
export async function completeRemoteViewBuilds(ws: WorkspaceEntry, request = requestWorkspace) {
|
|
115
116
|
if (!ws.remote) return
|
|
116
117
|
if (!Object.keys((await readWorkspaceState(ws)).pendingViews).length) return
|
|
117
|
-
const response = await request(
|
|
118
|
+
const response = await request(cloudRoutes.compiledViews.path(ws.remote), { method: 'GET' })
|
|
118
119
|
if (!response.ok) throw new Error(`Could not list the owner's views (${response.status})`)
|
|
119
120
|
const { views } = (await response.json()) as { views: { id: string }[] }
|
|
120
121
|
const compiled = new Set(views.map(view => view.id))
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { HarnessTransitionError, reserveWorkspaceOperation } from '../workspaces/harness-transition'
|
|
2
|
+
import { IDENTITY_ICON_IDS } from '@/lib/identity-icons'
|
|
3
|
+
import { viewBuildDirectives } from '@/lib/view-build-directives'
|
|
4
|
+
import { viewIdFromTab } from '@/lib/workspace-tabs'
|
|
5
|
+
import type { WorkspaceEntry } from '@/lib/types'
|
|
6
|
+
import { getCollabReferencePath } from '../collab/config'
|
|
7
|
+
import { harnessFor } from '../harness/registry'
|
|
8
|
+
import type { SendMessageInput } from '../harness/types'
|
|
9
|
+
import { getPinnedSession, saveSelectedSession, resolveRenamedSession } from './selected'
|
|
10
|
+
import { getSessionEntry, updateSessionEntry } from './store'
|
|
11
|
+
import {
|
|
12
|
+
getPendingView,
|
|
13
|
+
listPendingViews,
|
|
14
|
+
patchPendingView,
|
|
15
|
+
PendingViewError
|
|
16
|
+
} from './pending-views'
|
|
17
|
+
|
|
18
|
+
// Both ordinary chat and initial build requests use this boundary.
|
|
19
|
+
export async function sendWorkspaceMessage(
|
|
20
|
+
ws: WorkspaceEntry,
|
|
21
|
+
input: SendMessageInput & { viewBuildId?: string }
|
|
22
|
+
) {
|
|
23
|
+
const release = reserveWorkspaceOperation(ws.id)
|
|
24
|
+
try {
|
|
25
|
+
const { getWorkspace } = await import('../workspaces/registry')
|
|
26
|
+
const current = await getWorkspace(ws.id)
|
|
27
|
+
if (current && (current.harness ?? 'claude-code') !== (ws.harness ?? 'claude-code'))
|
|
28
|
+
throw new HarnessTransitionError('Agent changed. Start a new chat')
|
|
29
|
+
const { prepareWorkspaceHarness } = await import('../workspaces/change-harness')
|
|
30
|
+
await prepareWorkspaceHarness(ws)
|
|
31
|
+
const { viewBuildId, ...message } = input
|
|
32
|
+
const sessionId = resolveRenamedSession(ws.id, input.sessionId)
|
|
33
|
+
const record = await getSessionEntry(ws, sessionId)
|
|
34
|
+
const tabId = input.context?.activeTab?.id ?? record.tabId ?? 'overview'
|
|
35
|
+
const targetViewId = viewBuildId ?? (input.isNew ? viewIdFromTab(tabId) : undefined)
|
|
36
|
+
const ownedViews = targetViewId
|
|
37
|
+
? []
|
|
38
|
+
: (await listPendingViews(ws)).filter(view => view.buildSessionId === sessionId)
|
|
39
|
+
const pending = targetViewId
|
|
40
|
+
? await getPendingView(ws, targetViewId)
|
|
41
|
+
: (ownedViews.find(view => view.id === viewIdFromTab(tabId)) ?? ownedViews[0])
|
|
42
|
+
const isBuildRequest = pending && (viewBuildId === pending.id || input.isNew)
|
|
43
|
+
if (
|
|
44
|
+
isBuildRequest &&
|
|
45
|
+
pending.buildSessionId &&
|
|
46
|
+
pending.buildSessionId !== sessionId &&
|
|
47
|
+
(pending.status === 'starting' ||
|
|
48
|
+
harnessFor(ws)
|
|
49
|
+
.activeSessions()
|
|
50
|
+
.some(
|
|
51
|
+
session => session.workspaceId === ws.id && session.sessionId === pending.buildSessionId
|
|
52
|
+
))
|
|
53
|
+
)
|
|
54
|
+
throw new PendingViewError('This view is already being built in another chat', 409)
|
|
55
|
+
if (input.isNew && record.tabId !== tabId) {
|
|
56
|
+
record.tabId = tabId === 'overview' ? undefined : tabId
|
|
57
|
+
await updateSessionEntry(ws, sessionId, { tabId: record.tabId })
|
|
58
|
+
await saveSelectedSession(ws, sessionId, tabId, null)
|
|
59
|
+
}
|
|
60
|
+
if (isBuildRequest)
|
|
61
|
+
await patchPendingView(ws, pending.id, {
|
|
62
|
+
buildSessionId: sessionId
|
|
63
|
+
})
|
|
64
|
+
const collabReference = await getCollabReferencePath(ws.path, ws.harness)
|
|
65
|
+
const pinnedSessionId = await getPinnedSession(ws)
|
|
66
|
+
await harnessFor(ws).sendMessage({
|
|
67
|
+
...message,
|
|
68
|
+
sessionId,
|
|
69
|
+
context: {
|
|
70
|
+
...input.context,
|
|
71
|
+
// Resolve here for both browser messages and programmatic view builds;
|
|
72
|
+
// the agent must not infer file location from its local working directory.
|
|
73
|
+
workspaceMode: ws.remote ? 'remote' : 'local',
|
|
74
|
+
session: {
|
|
75
|
+
id: sessionId,
|
|
76
|
+
tabId: record.tabId,
|
|
77
|
+
pinned: pinnedSessionId === sessionId
|
|
78
|
+
},
|
|
79
|
+
...(collabReference ? { collabReference } : {}),
|
|
80
|
+
directives: [
|
|
81
|
+
...(input.context?.directives ?? []),
|
|
82
|
+
...(isBuildRequest ? viewBuildDirectives(pending.id, IDENTITY_ICON_IDS) : []),
|
|
83
|
+
...(isBuildRequest && record.fork
|
|
84
|
+
? [
|
|
85
|
+
'Inherited conversation is background. Work on the current request; do not resume unrelated earlier tasks.'
|
|
86
|
+
]
|
|
87
|
+
: []),
|
|
88
|
+
...(pending && input.isNew && pending.requirements !== input.content
|
|
89
|
+
? [`Original view requirements:\n${pending.requirements}`]
|
|
90
|
+
: []),
|
|
91
|
+
...(pending && input.attachments?.length
|
|
92
|
+
? ['Use the attachments as reference material for the intended view.']
|
|
93
|
+
: [])
|
|
94
|
+
]
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
if (pending && pending.status !== 'starting')
|
|
98
|
+
await patchPendingView(ws, pending.id, { status: 'submitted', error: undefined })
|
|
99
|
+
} finally {
|
|
100
|
+
release()
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -1,27 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sendWorkspaceMessage } from './send-message'
|
|
2
2
|
import { IDENTITY_ICON_IDS } from '@/lib/identity-icons'
|
|
3
3
|
import { viewBuildDirectives } from '@/lib/view-build-directives'
|
|
4
|
-
import {
|
|
4
|
+
import { viewTabId } from '@/lib/workspace-tabs'
|
|
5
5
|
import type { PendingView, WorkspaceEntry, WorkspaceTabId } from '@/lib/types'
|
|
6
|
-
import { getCollabReferencePath } from '../collab/config'
|
|
7
6
|
import { harnessFor } from '../harness/registry'
|
|
8
7
|
import type { SendMessageInput } from '../harness/types'
|
|
9
8
|
import { ForkUnsupportedError, inheritedHistoryBoundary } from '../harness/fork'
|
|
10
9
|
import { updateWorkspaceState } from '../workspace-state'
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
saveSelectedSession,
|
|
14
|
-
resolveRenamedSession,
|
|
15
|
-
selectSessionForTab
|
|
16
|
-
} from './selected'
|
|
17
|
-
import { getSessionEntry, setSessionTab, updateSessionEntry } from './store'
|
|
10
|
+
import { saveSelectedSession, resolveRenamedSession, selectSessionForTab } from './selected'
|
|
11
|
+
import { setSessionTab, updateSessionEntry } from './store'
|
|
18
12
|
import { getSessionConfig, saveSessionConfig } from './config'
|
|
19
13
|
import {
|
|
20
14
|
createPendingView,
|
|
21
|
-
getPendingView,
|
|
22
15
|
listPendingViews,
|
|
23
16
|
patchPendingView,
|
|
24
|
-
PendingViewError,
|
|
25
17
|
startViewBuild
|
|
26
18
|
} from './pending-views'
|
|
27
19
|
|
|
@@ -40,88 +32,6 @@ type BuildSendOptions = Pick<
|
|
|
40
32
|
>
|
|
41
33
|
export type SubmitViewInput = BuildSendOptions & { requirements: string; sessionId?: string }
|
|
42
34
|
|
|
43
|
-
// Both ordinary chat and initial build requests use this boundary.
|
|
44
|
-
export async function sendWorkspaceMessage(
|
|
45
|
-
ws: WorkspaceEntry,
|
|
46
|
-
input: SendMessageInput & { viewBuildId?: string }
|
|
47
|
-
) {
|
|
48
|
-
const release = reserveWorkspaceOperation(ws.id)
|
|
49
|
-
try {
|
|
50
|
-
const { getWorkspace } = await import('../workspaces/registry')
|
|
51
|
-
const current = await getWorkspace(ws.id)
|
|
52
|
-
if (current && (current.harness ?? 'claude-code') !== (ws.harness ?? 'claude-code'))
|
|
53
|
-
throw new HarnessTransitionError('Agent changed. Start a new chat')
|
|
54
|
-
const { prepareWorkspaceHarness } = await import('../workspaces/change-harness')
|
|
55
|
-
await prepareWorkspaceHarness(ws)
|
|
56
|
-
const { viewBuildId, ...message } = input
|
|
57
|
-
const sessionId = resolveRenamedSession(ws.id, input.sessionId)
|
|
58
|
-
const record = await getSessionEntry(ws, sessionId)
|
|
59
|
-
const tabId = input.context?.activeTab?.id ?? record.tabId ?? 'overview'
|
|
60
|
-
const targetViewId = viewBuildId ?? (input.isNew ? viewIdFromTab(tabId) : undefined)
|
|
61
|
-
const ownedViews = targetViewId
|
|
62
|
-
? []
|
|
63
|
-
: (await listPendingViews(ws)).filter(view => view.buildSessionId === sessionId)
|
|
64
|
-
const pending = targetViewId
|
|
65
|
-
? await getPendingView(ws, targetViewId)
|
|
66
|
-
: (ownedViews.find(view => view.id === viewIdFromTab(tabId)) ?? ownedViews[0])
|
|
67
|
-
const isBuildRequest = pending && (viewBuildId === pending.id || input.isNew)
|
|
68
|
-
if (
|
|
69
|
-
isBuildRequest &&
|
|
70
|
-
pending.buildSessionId &&
|
|
71
|
-
pending.buildSessionId !== sessionId &&
|
|
72
|
-
(pending.status === 'starting' ||
|
|
73
|
-
harnessFor(ws)
|
|
74
|
-
.activeSessions()
|
|
75
|
-
.some(
|
|
76
|
-
session => session.workspaceId === ws.id && session.sessionId === pending.buildSessionId
|
|
77
|
-
))
|
|
78
|
-
)
|
|
79
|
-
throw new PendingViewError('This view is already being built in another chat', 409)
|
|
80
|
-
if (input.isNew && record.tabId !== tabId) {
|
|
81
|
-
record.tabId = tabId === 'overview' ? undefined : tabId
|
|
82
|
-
await attachSession(ws, tabId, sessionId, null)
|
|
83
|
-
}
|
|
84
|
-
if (isBuildRequest)
|
|
85
|
-
await patchPendingView(ws, pending.id, {
|
|
86
|
-
buildSessionId: sessionId
|
|
87
|
-
})
|
|
88
|
-
const collabReference = await getCollabReferencePath(ws.path, ws.harness)
|
|
89
|
-
const pinnedSessionId = await getPinnedSession(ws)
|
|
90
|
-
await harnessFor(ws).sendMessage({
|
|
91
|
-
...message,
|
|
92
|
-
sessionId,
|
|
93
|
-
context: {
|
|
94
|
-
...input.context,
|
|
95
|
-
session: {
|
|
96
|
-
id: sessionId,
|
|
97
|
-
tabId: record.tabId,
|
|
98
|
-
pinned: pinnedSessionId === sessionId
|
|
99
|
-
},
|
|
100
|
-
...(collabReference ? { collabReference } : {}),
|
|
101
|
-
directives: [
|
|
102
|
-
...(input.context?.directives ?? []),
|
|
103
|
-
...(isBuildRequest ? viewBuildDirectives(pending.id, IDENTITY_ICON_IDS) : []),
|
|
104
|
-
...(isBuildRequest && record.fork
|
|
105
|
-
? [
|
|
106
|
-
'Inherited conversation is background. Work on the current request; do not resume unrelated earlier tasks.'
|
|
107
|
-
]
|
|
108
|
-
: []),
|
|
109
|
-
...(pending && input.isNew && pending.requirements !== input.content
|
|
110
|
-
? [`Original view requirements:\n${pending.requirements}`]
|
|
111
|
-
: []),
|
|
112
|
-
...(pending && input.attachments?.length
|
|
113
|
-
? ['Use the attachments as reference material for the intended view.']
|
|
114
|
-
: [])
|
|
115
|
-
]
|
|
116
|
-
}
|
|
117
|
-
})
|
|
118
|
-
if (pending && pending.status !== 'starting')
|
|
119
|
-
await patchPendingView(ws, pending.id, { status: 'submitted', error: undefined })
|
|
120
|
-
} finally {
|
|
121
|
-
release()
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
35
|
async function attachSession(
|
|
126
36
|
ws: WorkspaceEntry,
|
|
127
37
|
tabId: WorkspaceTabId,
|
package/server/web.ts
CHANGED
|
@@ -25,7 +25,8 @@ import { navigationRelay } from './navigation-relay'
|
|
|
25
25
|
import { resolveScratchOp } from './scratchpad/relay'
|
|
26
26
|
import { allHarnesses, harnessFor } from './harness/registry'
|
|
27
27
|
import { getWorkspace, listWorkspaces } from './workspaces/registry'
|
|
28
|
-
import { failInterruptedViewStarts
|
|
28
|
+
import { failInterruptedViewStarts } from './sessions/view-sessions'
|
|
29
|
+
import { sendWorkspaceMessage } from './sessions/send-message'
|
|
29
30
|
import { prepareWorkspaceStates } from './workspace-state'
|
|
30
31
|
import {
|
|
31
32
|
addClient,
|
|
@@ -4,6 +4,7 @@ import { dirname } from 'node:path'
|
|
|
4
4
|
|
|
5
5
|
import type { PendingView, SessionFork, WorkspaceSessionState } from '@/lib/types'
|
|
6
6
|
import { isWorkspaceTabId } from '@/lib/workspace-tabs'
|
|
7
|
+
import { normalizeOpenTabs } from '@/lib/workspace-layout'
|
|
7
8
|
import { LockTimeoutError, type Lease } from './lock'
|
|
8
9
|
import { WORKSPACE_STATE_VERSION, type StoredWorkspaceState } from './types'
|
|
9
10
|
|
|
@@ -95,6 +96,7 @@ export function normalizeWorkspaceState(
|
|
|
95
96
|
workspacePath: string
|
|
96
97
|
): StoredWorkspaceState {
|
|
97
98
|
const state = emptyWorkspaceState(optionalString(value.workspacePath) ?? workspacePath)
|
|
99
|
+
if (Array.isArray(value.openTabs)) state.openTabs = normalizeOpenTabs(value.openTabs)
|
|
98
100
|
if (typeof value.revision === 'number' && Number.isSafeInteger(value.revision))
|
|
99
101
|
state.revision = value.revision
|
|
100
102
|
if (isRecord(value.chatDefaults))
|
package/server/workspaces/api.ts
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import type { RemoteWorkspaceTarget } from '@/lib/workspace-config'
|
|
2
|
-
import {
|
|
2
|
+
import { remoteRequest } from '../remote/client'
|
|
3
3
|
|
|
4
4
|
export type WorkspaceApiTarget = { remote: RemoteWorkspaceTarget }
|
|
5
5
|
|
|
6
6
|
// CLI requests for a linked folder's shared content go to the owner's workspace API.
|
|
7
7
|
// Local workspaces never come through here; their handlers read the folder directly.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
path: string,
|
|
11
|
-
init?: RequestInit
|
|
12
|
-
): Promise<Response> {
|
|
13
|
-
const { remote } = workspace
|
|
8
|
+
// `path` comes from `cloudRoutes` (server/remote/routes.ts).
|
|
9
|
+
export async function requestWorkspace(path: string, init?: RequestInit): Promise<Response> {
|
|
14
10
|
// Serialize multipart bodies once so the signature and content type match the bytes sent.
|
|
15
11
|
const payload = new Request('http://workspace.local', {
|
|
16
12
|
method: init?.method ?? 'POST',
|
|
@@ -19,7 +15,7 @@ export async function requestWorkspace(
|
|
|
19
15
|
})
|
|
20
16
|
// Bun materializes multipart headers lazily; read the boundary before consuming the body.
|
|
21
17
|
const contentType = payload.headers.get('content-type') ?? undefined
|
|
22
|
-
return
|
|
18
|
+
return remoteRequest(path, {
|
|
23
19
|
method: init?.method,
|
|
24
20
|
body: init?.body == null ? undefined : new Uint8Array(await payload.arrayBuffer()),
|
|
25
21
|
signal: init?.signal ?? undefined,
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
import type { ViewInfo, WorkspaceTabId } from '@/lib/types'
|
|
3
3
|
import { viewTabId } from '@/lib/workspace-tabs'
|
|
4
4
|
|
|
5
|
-
//
|
|
6
|
-
// lists destinations only.
|
|
5
|
+
// `moi tabs` lists all destinations, regardless of which tabs are open.
|
|
7
6
|
export type TabRow = {
|
|
8
7
|
id: WorkspaceTabId
|
|
9
8
|
title: string
|
package/skill/SKILL.md
CHANGED
|
@@ -10,9 +10,10 @@ description: The Moi workspace — the web UI the user chats from, extended with
|
|
|
10
10
|
"Workspace" or "Moi Workspace" — the web UI that the user works in, talks/collaborates with you,
|
|
11
11
|
sees and interacts with "Applets".
|
|
12
12
|
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
"Workspace dir" — the primary working folder _you_ (as an agent) work in. Workspace files are stored here;
|
|
14
|
+
it also contains `.moi/`, which holds configuration, applets, applet, dependencies and other workspace extensions.
|
|
15
|
+
|
|
16
|
+
"Remote workspace" - Moi Workspace running on a different machine that someone else shared with the user and you.
|
|
16
17
|
|
|
17
18
|
"Chat" — a conversation between the user and an agent in the workspace.
|
|
18
19
|
|
|
@@ -50,25 +51,31 @@ User can switch between these, but can access the chat (this conversation and ot
|
|
|
50
51
|
|
|
51
52
|
## Working in the workspace
|
|
52
53
|
|
|
53
|
-
### Local or
|
|
54
|
+
### Local or Remote workspaces
|
|
55
|
+
|
|
56
|
+
Workspace can be either:
|
|
57
|
+
|
|
58
|
+
**Local** workspace dir is stored on this computer. You have full control over it. You
|
|
59
|
+
interact with it using filesystem operations and by calling moi cli.
|
|
60
|
+
|
|
61
|
+
**Remote**. Workspace is running on someone else's ("owner") computer and it is shared with the user.
|
|
62
|
+
In this case, there are two dirs and two computers:
|
|
54
63
|
|
|
55
|
-
|
|
56
|
-
|
|
64
|
+
_Owner dir_ for the owner, looks like a regular local workspace. Has the file structure described in
|
|
65
|
+
"Files and Folders" section. Owner's agent runs there and it interact with it by using regular file ops.
|
|
66
|
+
Source of truth for shared workspace files and content, including applets, extensions, and shared data.
|
|
67
|
+
Everything in the dir is shared with all members. Each visitor’s chats, pending views, and agent settings
|
|
68
|
+
remain personal and are managed by their own Moi instance.
|
|
57
69
|
|
|
58
|
-
|
|
59
|
-
|
|
70
|
+
_Linked dir_ is on this computer. It's your local working folder, no other user sees it. `.moi` folder is
|
|
71
|
+
stripped down, only contains meta that this folder is linked to remote workspace. All files here are for
|
|
72
|
+
private and intermediate work. You can also interact with the remote workspace and owner dir using
|
|
73
|
+
subset of regular `moi` commands and also `moi remote` commands. Do not create local applet copies and
|
|
74
|
+
prefer not to store workspace state here (it gets out of sync quickly). Full command reference is in
|
|
75
|
+
"Using the Moi CLI"
|
|
60
76
|
|
|
61
|
-
-
|
|
62
|
-
|
|
63
|
-
- Use the ordinary commands from this folder as usual. `moi check`, `bundle`, `views`, `theme`,
|
|
64
|
-
`config`, `tabs`, `call-server-fn`, `debug logs`, and scratchpad reads/edits act on the owner.
|
|
65
|
-
- `moi refresh`, `navigate`, and `scratch view` act on your user's running Moi and browser. Refresh
|
|
66
|
-
after remote changes.
|
|
67
|
-
- Image input and output paths refer to the machine running the CLI. `config icon` and
|
|
68
|
-
`scratch add image` upload local files to the owner; `scratch read-image` saves the owner's
|
|
69
|
-
image locally, and `scratch view --out` saves the visitor browser's canvas screenshot locally.
|
|
70
|
-
- Never create local applet copies or fall back to local content when the owner is unavailable.
|
|
71
|
-
Remote chat and the settings UI are unavailable.
|
|
77
|
+
The newest `<moi-context>` identifies whether the workspace is local or remote. If it does not,
|
|
78
|
+
run `moi remote` to check.
|
|
72
79
|
|
|
73
80
|
### Boundaries
|
|
74
81
|
|
|
@@ -79,11 +86,11 @@ holds only the reference and skills.
|
|
|
79
86
|
|
|
80
87
|
### Files and folders
|
|
81
88
|
|
|
82
|
-
For local workspaces, the source of truth is the `.moi` folder
|
|
89
|
+
For local workspaces, the source of truth is the `.moi` folder inside the workspace dir. Contains source code of all
|
|
83
90
|
Applets, bundled code, settings, etc. Can be committed to version control. Folder is partially
|
|
84
91
|
initialised when Workspace starts, you have full ownership of it.
|
|
85
92
|
|
|
86
|
-
You _do have_ access to the files in the
|
|
93
|
+
You _do have_ access to the files in the workspace dir — you can reference and load them from the
|
|
87
94
|
"Applets" and elsewhere.
|
|
88
95
|
|
|
89
96
|
Folder structure:
|
|
@@ -103,17 +110,17 @@ my-agent-folder/
|
|
|
103
110
|
users-api.server.ts <- Server-side async functions the view can call (optional)
|
|
104
111
|
...
|
|
105
112
|
package.json <- Applet dependencies that you manage
|
|
106
|
-
.workspace.json <- Internal config.
|
|
113
|
+
.workspace.json <- Internal config. Do not edit.
|
|
107
114
|
.scratchpad.json <- Scratchpad canvas snapshot. Internal — inspect only via `moi scratch read`, never open it.
|
|
108
115
|
.scratchpad/ <- Scratchpad image files. Internal — pull pixels via `moi scratch read-image`, never open it.
|
|
109
116
|
```
|
|
110
117
|
|
|
111
118
|
Every dot-prefixed file or folder inside `.moi/` (`.build/`, `.cache/`, `.workspace.json`,
|
|
112
119
|
`.scratchpad*`, `.gitignore`, …) is a Moi internal: auto-generated and liable to change format
|
|
113
|
-
without notice.
|
|
120
|
+
without notice. Do not read, edit, or delete them, and never point
|
|
114
121
|
tooling at them; go through the `moi` CLI instead. Version control needs no special handling: the
|
|
115
|
-
scaffolded `.moi/.gitignore` already excludes the machine-local entries (`.build
|
|
116
|
-
|
|
122
|
+
scaffolded `.moi/.gitignore` already excludes the machine-local entries (e.g. `.build/`), while
|
|
123
|
+
`.workspace.json` and `.scratchpad.json` are workspace state that ships
|
|
117
124
|
with the repo — commit them as-is, just never hand-edit them. Your surface is the non-dot files:
|
|
118
125
|
`widgets/`, `views/`, `package.json`, and code you place under `.moi/` yourself.
|
|
119
126
|
|
|
@@ -121,7 +128,7 @@ with the repo — commit them as-is, just never hand-edit them. Your surface is
|
|
|
121
128
|
|
|
122
129
|
Treat `moi` as an external command — you cannot inspect or modify its sources. Use only the
|
|
123
130
|
documented subcommands (`moi bundle`, `moi bundle --force`, etc.). Call `moi --help` for
|
|
124
|
-
documentation. Run all `moi` commands from the **
|
|
131
|
+
documentation. Run all `moi` commands from the **workspace dir** — the folder that contains `.moi/`,
|
|
125
132
|
never from inside `.moi/` itself. You don't pass paths; Moi resolves the workspace from where it's run.
|
|
126
133
|
|
|
127
134
|
Use the task-specific sections below for workflow guidance. The CLI will grow over time, so run
|
|
@@ -135,6 +142,32 @@ Use the task-specific sections below for workflow guidance. The CLI will grow ov
|
|
|
135
142
|
- **Use workspace env:** `moi env` and `moi env exec` (see Environment and secrets).
|
|
136
143
|
- **Maintain workspace guidance:** `moi skill` (see Keeping this skill current).
|
|
137
144
|
|
|
145
|
+
#### How CLI works in a linked to remote workspace dir
|
|
146
|
+
|
|
147
|
+
These commands only work in linked dir of the Remote workspace. They allow you to manage the host
|
|
148
|
+
workspace, write applets, work with files etc. Remote file paths are relative to the owner dir.
|
|
149
|
+
Upload sources, download destinations, and `--patch-file` paths refer to your machine.
|
|
150
|
+
For full reference, run `moi remote --help`
|
|
151
|
+
|
|
152
|
+
```sh
|
|
153
|
+
moi remote # Show identity, link, help
|
|
154
|
+
moi remote exec 'ls .moi/views' # List files on the host
|
|
155
|
+
moi remote read .moi/views/dashboard.tsx # Read a host file
|
|
156
|
+
moi remote write .moi/notes.txt "Hello" # Create or overwrite a host file
|
|
157
|
+
moi remote patch .moi/views/dashboard.tsx --patch-file ./change.diff # Apply a local diff
|
|
158
|
+
moi remote file-upload ./chart.png .moi/chart.png # local → host
|
|
159
|
+
moi remote file-download .moi/chart.png ./chart.png # host → local
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
These regular commands work and get forwared to remote: `check`, `bundle`, `call-server-fn`, `debug`,
|
|
163
|
+
`theme`, `ui-components`, `config`, `tabs`, `scratch`. Scratchpad reads and writes on owner's behalf,
|
|
164
|
+
except for `moi scratch view`.
|
|
165
|
+
|
|
166
|
+
These commands run on **your local Moi**: `refresh`, `navigate`, `views create`, `views set`, `env`.
|
|
167
|
+
`moi tabs` lists the remote workspace’s tabs and views. E.g. `navigate` switches the tab ONLY for current user.
|
|
168
|
+
|
|
169
|
+
Managing env vars on the remote machine is not yet supported. Tell the user to ask the workspace owner.
|
|
170
|
+
|
|
138
171
|
### Workspace navigation
|
|
139
172
|
|
|
140
173
|
Use `moi:/` addresses in chat, CLI commands, and applets. They refer to the current workspace,
|
|
@@ -192,7 +225,11 @@ use `moi theme --help` if its options change.
|
|
|
192
225
|
|
|
193
226
|
### Environment and secrets
|
|
194
227
|
|
|
195
|
-
|
|
228
|
+
In remote workspaces, `moi env` commands manage your local environment, and `moi env exec`
|
|
229
|
+
runs locally. Applet server functions use the owner's environment; setting a key locally does
|
|
230
|
+
not make it available to the owner's applets.
|
|
231
|
+
|
|
232
|
+
Each workspace has an effective env: keys from `.env` / `.env.local` in the workspace dir (when
|
|
196
233
|
inheritance is enabled in settings) plus **custom secrets** the user manages in the workspace env
|
|
197
234
|
settings. Moi injects this env into:
|
|
198
235
|
|
|
@@ -371,8 +408,8 @@ replaces the pending screen in the same tab.
|
|
|
371
408
|
- Use `style={{}}` only for computed data such as chart geometry, progress, per-item delays, or
|
|
372
409
|
per-frame transforms.
|
|
373
410
|
- Use icons from `@tabler/icons-react`. Do not add raw SVG icons or another icon pack. When the
|
|
374
|
-
|
|
375
|
-
- Applets cannot import the host
|
|
411
|
+
workspace dir contains `.agents/rules/icons.md`, follow its size and stroke policy.
|
|
412
|
+
- Applets cannot import the Moi host application's `cn`. If `.moi/ui/utils.ts` exists, import `cn` from
|
|
376
413
|
`../ui/utils`; otherwise use a local `cx()` when classes are conditional. Never build class
|
|
377
414
|
names with template-literal ternaries.
|
|
378
415
|
|
|
@@ -507,11 +544,15 @@ surfaces on its own.
|
|
|
507
544
|
## Chats and messages
|
|
508
545
|
|
|
509
546
|
A workspace is driven through agent conversations (this chat is one). Depending on your
|
|
510
|
-
harness (Claude Code, openclaw, others differ in the details) there can be **multiple chats**,
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
547
|
+
harness (Claude Code, openclaw, others differ in the details) there can be **multiple chats**,
|
|
548
|
+
all working with the same shared applets, config, and theme.
|
|
549
|
+
|
|
550
|
+
You always run on your local machine, not on the remote owner's machine; other visitors have
|
|
551
|
+
their own agents running in their own linked dirs, while the owner's agents run in the owner dir.
|
|
552
|
+
|
|
553
|
+
Anything you build in the shared workspace is visible to other members, and another agent may
|
|
554
|
+
have changed its files since you last looked. Treat shared workspace files as shared state,
|
|
555
|
+
not yours alone. Internally, "chats" are sometimes aliased as
|
|
515
556
|
"threads" — "chat" is product language, while "thread" is reserved for internal SDK, session, and
|
|
516
557
|
persistence concepts.
|
|
517
558
|
|
|
@@ -4,6 +4,10 @@ The Scratchpad is the workspace's **shared whiteboard** — one freeform tldraw
|
|
|
4
4
|
draws on by hand and you drive through `moi scratch`. Same canvas, two authors; disk is the
|
|
5
5
|
source of truth. Use it to sketch, diagram, annotate the user's drawing, or lay out boxes.
|
|
6
6
|
|
|
7
|
+
In a remote workspace, run commands from the linked dir: reads and edits use the owner's canvas,
|
|
8
|
+
while `moi scratch view` uses your local Moi and browser. Image input and output paths stay local:
|
|
9
|
+
`add image` uploads to the owner; `read-image` and `view --out` save locally.
|
|
10
|
+
|
|
7
11
|
## Seeing
|
|
8
12
|
|
|
9
13
|
**Always inspect the canvas through the commands below — never open, `cat`, `read`, or parse the
|