moi-computer 0.13.1-next.1 → 0.13.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 +12 -1
- package/client/api/http.ts +11 -1
- package/client/app/app-router.tsx +3 -2
- package/client/app/routes/home-route.tsx +1 -1
- package/client/app/routes/workspace-registration.tsx +68 -0
- package/client/app/routes/workspace-route.tsx +33 -6
- package/client/app/shell/sidebar-layout.tsx +10 -5
- package/client/components/shared/workspace-icon.tsx +8 -17
- package/client/features/account/account-test-utils.tsx +15 -9
- package/client/features/account/api.ts +6 -6
- package/client/features/account/profile-actions.ts +5 -7
- package/client/features/app-settings/settings-page.tsx +2 -1
- package/client/features/applets/api.ts +6 -6
- package/client/features/applets/applet-cache.ts +6 -5
- package/client/features/applets/applet-log.ts +2 -1
- package/client/features/applets/applet-runtime.ts +2 -1
- package/client/features/applets/use-applet.ts +73 -18
- package/client/features/applets/widget-shell.tsx +4 -2
- package/client/features/chat/applet-chat-intents.ts +5 -13
- package/client/features/chat/chat-popup.tsx +8 -4
- package/client/features/chat/chat-send.ts +2 -2
- package/client/features/chat/composer/model-order.ts +4 -4
- package/client/features/chat/composer/model-picker.tsx +12 -10
- package/client/features/chat/composer/use-workspace-composer-state.tsx +1 -1
- package/client/features/chat/sessions/api.ts +11 -28
- package/client/features/chat/sessions/use-selected-session.ts +18 -100
- package/client/features/chat/use-chat.ts +8 -12
- package/client/features/collab/members/api.ts +4 -10
- package/client/features/collab/members/hooks.ts +32 -38
- package/client/features/collab/members/store.ts +96 -71
- package/client/features/collab/members/types.ts +5 -3
- package/client/features/collab/presence/client.ts +2 -3
- package/client/features/collab/presence/hooks.tsx +1 -1
- package/client/features/collab/proxy-user.ts +1 -3
- package/client/features/collab/sharing/workspace-members.tsx +0 -8
- package/client/features/dev/chat-states-page.tsx +3 -1
- package/client/features/dev/harness-debug-page.tsx +7 -7
- package/client/features/dev/workspace-setup-mocks.ts +1 -1
- package/client/features/dev/workspace-setup-preview.tsx +6 -4
- package/client/features/harness/api.ts +13 -10
- package/client/features/harness/harness-login-panel.tsx +9 -5
- package/client/features/harness/harness-presentation.ts +4 -4
- package/client/features/harness/harness-selector.tsx +13 -13
- package/client/features/harness/use-harness-login.ts +5 -5
- package/client/features/home/api.ts +38 -2
- package/client/features/home/home-page.tsx +43 -13
- package/client/features/home/shared-workspaces.tsx +70 -0
- package/client/features/home/workspace-invitations.tsx +101 -0
- package/client/features/identity/host-api.ts +3 -2
- package/client/features/identity/store.ts +1 -7
- package/client/features/onboarding/agent-setup-step.tsx +8 -8
- package/client/features/onboarding/onboarding-page.tsx +3 -2
- package/client/features/onboarding/workspace-setup-step.tsx +1 -1
- package/client/features/overview/api.ts +3 -5
- package/client/features/overview/default/registry.tsx +1 -1
- package/client/features/overview/default/views-widget.tsx +2 -2
- package/client/features/overview/hidden-panel.tsx +7 -5
- package/client/features/overview/overview.tsx +18 -16
- package/client/features/overview/workspace-name.tsx +2 -2
- package/client/features/scratchpad/scratchpad.tsx +9 -7
- package/client/features/scratchpad/use-scratchpad-snapshot.tsx +13 -5
- package/client/features/views/api.ts +34 -16
- package/client/features/views/use-view-actions.ts +10 -20
- package/client/features/views/view-manager.tsx +1 -1
- package/client/features/views/view-submission.ts +2 -21
- package/client/features/workspace/add/api.ts +5 -4
- package/client/features/workspace/add/create-workspace-dialog.tsx +12 -9
- package/client/features/workspace/add/import-workspace-dialog.tsx +7 -7
- package/client/features/workspace/add/use-workspace-import.ts +10 -10
- package/client/features/workspace/add/workspace-agent-options.ts +21 -20
- package/client/features/workspace/add/workspace-agent-selector.tsx +11 -11
- package/client/features/workspace/api.ts +60 -13
- package/client/features/workspace/harness-transition.ts +7 -13
- package/client/features/workspace/remote.ts +25 -0
- package/client/features/workspace/settings/api.ts +7 -12
- package/client/features/workspace/settings/connectors-settings.tsx +3 -3
- package/client/features/workspace/settings/general-settings.tsx +8 -8
- package/client/features/workspace/setup/workspace-login-state.tsx +4 -4
- package/client/features/workspace/setup/workspace-recovery-states.tsx +43 -14
- package/client/features/workspace/setup/workspace-setup.tsx +6 -6
- package/client/features/workspace/tab-resolution.ts +2 -2
- package/client/features/workspace/use-workspace-navigation.ts +7 -4
- package/client/features/workspace/workspace-content.tsx +22 -20
- package/client/features/workspace/workspace-frame.tsx +13 -26
- package/client/features/workspace/workspace-layout-context.tsx +45 -12
- package/client/features/workspace/workspace-menu.tsx +2 -2
- package/client/features/workspace/workspace-pane.tsx +22 -0
- package/client/features/workspace/workspace-pending-screen.tsx +1 -1
- package/client/features/workspace/workspace-preferences.ts +34 -0
- package/client/features/workspace/workspace-presentation.tsx +12 -16
- package/client/features/workspace/workspace-screen.tsx +2 -2
- package/client/features/workspace/workspace-state.ts +2 -1
- package/client/features/workspace/workspace-tabs.tsx +1 -1
- package/client/features/workspace/workspace-test-utils.ts +23 -0
- package/client/runtime/use-workspace-events.ts +14 -0
- package/client/runtime/workspace-events.ts +9 -9
- package/client/store/ui.ts +29 -9
- package/dist/chunk-44khk4sp.js +2 -0
- package/dist/chunk-ba6mz56s.js +72 -0
- package/dist/chunk-ec5ennpv.js +1 -0
- package/dist/chunk-ectsnw81.js +2 -0
- package/dist/chunk-en7w5ypg.js +1 -0
- package/dist/chunk-f695wcx5.js +5 -0
- package/dist/chunk-kffcah9w.css +1 -0
- package/dist/{chunk-th91xfnp.js → chunk-n0fawy9x.js} +1 -1
- package/dist/chunk-pdt9hxfw.js +2 -0
- package/dist/chunk-rmd0ctfx.js +546 -0
- package/dist/chunk-zv22wv0g.js +1 -0
- package/dist/index.html +1 -1
- package/lib/harness-instructions.ts +4 -4
- package/lib/harness-types.ts +13 -0
- package/lib/types.ts +34 -49
- package/lib/workspace-config.ts +48 -0
- package/lib/workspace-layout.ts +2 -4
- package/package.json +4 -2
- package/server/README.md +29 -27
- package/server/api/harnesses.ts +5 -5
- package/server/api/index.ts +170 -68
- package/server/applets/index.ts +15 -9
- package/server/applets/views.ts +2 -17
- package/server/applets/widgets.ts +3 -2
- package/server/cli/commands/config.ts +8 -20
- package/server/cli/commands/hermes.ts +2 -2
- package/server/cli/commands/init.ts +96 -53
- package/server/cli/commands/openclaw.ts +2 -2
- package/server/cli/commands/refresh.ts +10 -1
- package/server/cli/commands/remote.ts +228 -0
- package/server/cli/commands/skill.ts +4 -4
- package/server/cli/commands/tabs.ts +5 -12
- package/server/cli/control.ts +35 -4
- package/server/cli/index.ts +10 -6
- package/server/cli/remote-command.ts +77 -0
- package/server/cli/remote-control.ts +70 -0
- package/server/cli/remote-operations.ts +244 -0
- package/server/collab/config.ts +3 -3
- package/server/collab/skill/index.ts +3 -3
- package/server/control.ts +38 -11
- package/server/harness/acp/session.ts +4 -4
- package/server/harness/auth.ts +26 -31
- package/server/harness/claude-code/index.ts +1 -1
- package/server/harness/codex/discovery.ts +1 -1
- package/server/harness/codex/session.ts +1 -1
- package/server/harness/detect.ts +14 -19
- package/server/harness/executable.ts +10 -10
- package/server/harness/hermes/NOTES.md +2 -2
- package/server/harness/hermes/index.ts +1 -1
- package/server/harness/install.ts +11 -11
- package/server/harness/openclaw/index.ts +1 -1
- package/server/harness/registry.ts +7 -6
- package/server/harness/types.ts +4 -4
- package/server/onboarding/jobs.ts +1 -1
- package/server/operations/commands.ts +46 -0
- package/server/operations/files.ts +148 -0
- package/server/operations/server.ts +206 -0
- package/server/remote/agent.ts +103 -0
- package/server/remote/client.ts +665 -0
- package/server/remote/workspace.ts +34 -0
- package/server/scratchpad/document.ts +32 -12
- package/server/scratchpad/executor.ts +16 -7
- package/server/sessions/config.ts +8 -5
- package/server/sessions/pending-views.ts +16 -0
- package/server/sessions/view-sessions.ts +10 -12
- package/server/skills/locations.ts +4 -4
- package/server/skills/update.ts +11 -11
- package/server/skills/version.ts +7 -7
- package/server/skills/workspace.ts +13 -11
- package/server/web.ts +11 -8
- package/server/workspace-state/file.ts +2 -0
- package/server/workspace-state/index.ts +0 -4
- package/server/workspaces/api.ts +28 -0
- package/server/workspaces/change-harness.ts +15 -26
- package/server/workspaces/import.ts +4 -4
- package/server/workspaces/init.ts +15 -13
- package/server/workspaces/layout.ts +60 -66
- package/server/workspaces/registry.ts +43 -18
- package/server/workspaces/shared.ts +74 -0
- package/server/workspaces/tabs.ts +6 -12
- package/skill/SKILL.md +24 -4
- package/client/api/app-ui-keys.ts +0 -6
- package/client/features/chat/sessions/browser-tab-state.ts +0 -43
- package/client/features/collab/members/keys.ts +0 -6
- package/client/features/workspace/browser-tab-state.ts +0 -51
- package/client/features/workspace/layout-save.ts +0 -13
- package/dist/chunk-3smkkcfw.js +0 -546
- package/dist/chunk-47h9c2qy.js +0 -2
- package/dist/chunk-8qed2gqp.js +0 -75
- package/dist/chunk-8zy3vesm.js +0 -1
- package/dist/chunk-a47zy276.js +0 -2
- package/dist/chunk-g4c1nte9.css +0 -1
- package/dist/chunk-kcactdr4.js +0 -2
- package/dist/chunk-m8bhx6tw.js +0 -1
- package/dist/chunk-pf19zcrn.js +0 -2
- package/dist/chunk-ygzxah0e.js +0 -1
- package/lib/workspace-types.ts +0 -13
- package/server/workspace-state/legacy-migration.ts +0 -79
package/server/cli/control.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { remoteControl } from './remote-control'
|
|
1
2
|
import { accessSync, constants } from 'node:fs'
|
|
2
3
|
import { CONTROL_URL } from '../constants'
|
|
3
4
|
import { controlFailureMessage, probeControlServer } from '../control-client'
|
|
@@ -46,14 +47,44 @@ export async function registerViaControl(absPath: string): Promise<string> {
|
|
|
46
47
|
})
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
// Tell the local server something it may act on. Never fails the command: the
|
|
51
|
+
// server may be stopped, and the caller's own work is already done.
|
|
52
|
+
export function notifyLocalServer(payload: Record<string, unknown>, timeoutMs = 3000) {
|
|
53
|
+
return new Promise<void>(done => {
|
|
54
|
+
const ws = new WebSocket(CONTROL_URL)
|
|
55
|
+
const finish = () => {
|
|
56
|
+
clearTimeout(timer)
|
|
57
|
+
ws.close()
|
|
58
|
+
done()
|
|
59
|
+
}
|
|
60
|
+
const timer = setTimeout(finish, timeoutMs)
|
|
61
|
+
ws.onopen = () => ws.send(JSON.stringify(payload))
|
|
62
|
+
ws.onmessage = finish
|
|
63
|
+
ws.onerror = finish
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Shared data in a linked folder uses the owner API. Browser actions and local
|
|
68
|
+
// workspaces use visitor control. Both paths keep output/file IO on the caller.
|
|
69
|
+
export async function sendControl(
|
|
53
70
|
path: string,
|
|
54
71
|
payload: Record<string, unknown>,
|
|
55
72
|
onResult: (res: Record<string, unknown>) => void | Promise<void>
|
|
56
73
|
) {
|
|
74
|
+
try {
|
|
75
|
+
const result = await remoteControl(path, payload)
|
|
76
|
+
if (result) {
|
|
77
|
+
if (result.error) throw new Error(String(result.error))
|
|
78
|
+
await onResult(result)
|
|
79
|
+
const notice = await staleSkillNotice(path)
|
|
80
|
+
if (notice) console.error('\n' + pc.yellow(notice) + '\n')
|
|
81
|
+
return
|
|
82
|
+
}
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.error(error instanceof Error ? error.message : 'Remote command failed')
|
|
85
|
+
process.exitCode = 1
|
|
86
|
+
return
|
|
87
|
+
}
|
|
57
88
|
const ws = new WebSocket(CONTROL_URL)
|
|
58
89
|
let connected = false
|
|
59
90
|
let responded = false
|
package/server/cli/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { init } from './commands/init'
|
|
|
14
14
|
import { navigate } from './commands/navigate'
|
|
15
15
|
import { openclaw } from './commands/openclaw'
|
|
16
16
|
import { refresh } from './commands/refresh'
|
|
17
|
+
import { remote } from './commands/remote'
|
|
17
18
|
import { scratch } from './commands/scratch'
|
|
18
19
|
import { service } from './commands/service'
|
|
19
20
|
import { skill } from './commands/skill'
|
|
@@ -26,25 +27,28 @@ import { update } from './commands/update'
|
|
|
26
27
|
import { version } from './commands/version'
|
|
27
28
|
import { views } from './commands/views'
|
|
28
29
|
import pc from './pc'
|
|
30
|
+
import { remoteWorkspaceCommand } from './remote-command'
|
|
29
31
|
|
|
30
32
|
// The root help splits the surface by audience: workspace commands are the
|
|
31
33
|
// agent's day-to-day toolkit (skills tell it to run them); system commands
|
|
32
34
|
// manage Moi itself and are for the human at the keyboard.
|
|
33
35
|
const workspaceCommands = {
|
|
34
|
-
bundle,
|
|
35
|
-
check,
|
|
36
|
+
bundle: remoteWorkspaceCommand('bundle', bundle),
|
|
37
|
+
check: remoteWorkspaceCommand('check', check),
|
|
36
38
|
refresh,
|
|
39
|
+
// A view under construction belongs to the caller's chat, so these stay on local control.
|
|
37
40
|
views,
|
|
38
|
-
'call-server-fn': callServerFn,
|
|
39
|
-
debug,
|
|
40
|
-
theme,
|
|
41
|
+
'call-server-fn': remoteWorkspaceCommand('call-server-fn', callServerFn),
|
|
42
|
+
debug: remoteWorkspaceCommand('debug', debug),
|
|
43
|
+
theme: remoteWorkspaceCommand('theme', theme),
|
|
41
44
|
config,
|
|
42
45
|
env,
|
|
43
46
|
scratch,
|
|
44
47
|
skill,
|
|
45
48
|
tabs,
|
|
46
49
|
navigate,
|
|
47
|
-
|
|
50
|
+
remote,
|
|
51
|
+
'ui-components': remoteWorkspaceCommand('ui-components', uiComponents)
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
const systemCommands = {
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { ArgsDef, CommandDef } from 'citty'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
import { notifyLocalServer } from './control'
|
|
4
|
+
import { runLinkedWorkspaceCommand } from './remote-operations'
|
|
5
|
+
|
|
6
|
+
// Wrap owner-executed commands only. Preserve their parser/help while running
|
|
7
|
+
// them on the linked host. Commands with caller file IO or browser actions use
|
|
8
|
+
// their ordinary handlers and remote-control instead.
|
|
9
|
+
export function remoteWorkspaceCommand<T extends ArgsDef>(
|
|
10
|
+
name: string,
|
|
11
|
+
command: CommandDef<T>,
|
|
12
|
+
prefix: string[] = []
|
|
13
|
+
): CommandDef<T> {
|
|
14
|
+
const original = command.run
|
|
15
|
+
return {
|
|
16
|
+
...command,
|
|
17
|
+
...(command.subCommands
|
|
18
|
+
? {
|
|
19
|
+
subCommands: async () => {
|
|
20
|
+
const source =
|
|
21
|
+
typeof command.subCommands === 'function'
|
|
22
|
+
? await command.subCommands()
|
|
23
|
+
: await command.subCommands
|
|
24
|
+
const children: NonNullable<typeof source> = {}
|
|
25
|
+
for (const [key, value] of Object.entries(source ?? {})) {
|
|
26
|
+
const child = typeof value === 'function' ? await value() : await value
|
|
27
|
+
children[key] = remoteWorkspaceCommand(name, child, [...prefix, key])
|
|
28
|
+
}
|
|
29
|
+
return children
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
: {}),
|
|
33
|
+
async run(context) {
|
|
34
|
+
if (command.subCommands && context.args._.length) return original?.(context)
|
|
35
|
+
const args = context.args as Record<string, unknown>
|
|
36
|
+
const folder = resolve(typeof args.dir === 'string' ? args.dir : process.cwd())
|
|
37
|
+
const definitions =
|
|
38
|
+
typeof command.args === 'function' ? await command.args() : await command.args
|
|
39
|
+
const positionalDir = Object.entries(definitions ?? {})
|
|
40
|
+
.filter(([, def]) => def.type === 'positional')
|
|
41
|
+
.findIndex(([key]) => key === 'dir')
|
|
42
|
+
let position = 0
|
|
43
|
+
const forwarded: string[] = []
|
|
44
|
+
for (let i = 0; i < context.rawArgs.length; i++) {
|
|
45
|
+
const arg = context.rawArgs[i]!
|
|
46
|
+
if (arg === '--dir') {
|
|
47
|
+
i++
|
|
48
|
+
continue
|
|
49
|
+
}
|
|
50
|
+
if (arg.startsWith('--dir=')) continue
|
|
51
|
+
if (arg.startsWith('-') && arg !== '-') {
|
|
52
|
+
forwarded.push(arg)
|
|
53
|
+
const option = arg.replace(/^--?/, '').split('=')[0]!
|
|
54
|
+
if (
|
|
55
|
+
!arg.includes('=') &&
|
|
56
|
+
definitions?.[option]?.type === 'string' &&
|
|
57
|
+
context.rawArgs[i + 1] !== undefined
|
|
58
|
+
)
|
|
59
|
+
forwarded.push(context.rawArgs[++i]!)
|
|
60
|
+
} else if (position++ !== positionalDir) forwarded.push(arg)
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
if (await runLinkedWorkspaceCommand(name, [...prefix, ...forwarded], folder)) {
|
|
64
|
+
// A view the owner just built is still marked as building in this Moi.
|
|
65
|
+
if (name === 'bundle' && !process.exitCode)
|
|
66
|
+
await notifyLocalServer({ type: 'views:reconcile', path: folder })
|
|
67
|
+
return
|
|
68
|
+
}
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.error(error instanceof Error ? error.message : 'Remote command failed')
|
|
71
|
+
process.exitCode = 1
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
return original?.(context)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { basename } from 'node:path'
|
|
2
|
+
import type { ScratchOp, ViewInfo } from '@/lib/types'
|
|
3
|
+
import { currentRemoteWorkspace } from '../remote/workspace'
|
|
4
|
+
import { requestWorkspace } from '../workspaces/api'
|
|
5
|
+
import { assembleTabRows } from '../workspaces/tabs'
|
|
6
|
+
import { readScratchpadImage, readScratchpadShapes } from '../scratchpad/document'
|
|
7
|
+
import type { WorkspaceConfig } from '../workspaces/config'
|
|
8
|
+
|
|
9
|
+
type ScratchCliOp = ScratchOp | { kind: 'read' } | { kind: 'read-image'; name: string }
|
|
10
|
+
|
|
11
|
+
// These commands keep parsing, local file IO and output on the caller. Only
|
|
12
|
+
// shared data crosses the owner API. Browser rendering stays on visitor control.
|
|
13
|
+
export async function remoteControl(
|
|
14
|
+
path: string,
|
|
15
|
+
payload: Record<string, unknown>
|
|
16
|
+
): Promise<Record<string, unknown> | undefined> {
|
|
17
|
+
if (!['config', 'scratch', 'tabs'].includes(String(payload.type))) return
|
|
18
|
+
const op = payload.op as ScratchCliOp | undefined
|
|
19
|
+
if (payload.type === 'scratch' && op?.kind === 'view') return
|
|
20
|
+
const remote = await currentRemoteWorkspace(path)
|
|
21
|
+
if (!remote) return
|
|
22
|
+
const workspace = { remote }
|
|
23
|
+
const request = (suffix: string, init?: RequestInit) => requestWorkspace(workspace, suffix, init)
|
|
24
|
+
if (payload.type === 'tabs') {
|
|
25
|
+
const { views }: { views: ViewInfo[] } = await (
|
|
26
|
+
await request('/views?includePending=true')
|
|
27
|
+
).json()
|
|
28
|
+
return { tabs: assembleTabRows(views) }
|
|
29
|
+
}
|
|
30
|
+
if (payload.type === 'config') {
|
|
31
|
+
if (typeof payload.iconPath === 'string') {
|
|
32
|
+
const file = Bun.file(payload.iconPath)
|
|
33
|
+
if (!(await file.exists())) throw new Error('Local icon file not found')
|
|
34
|
+
return { ok: true, ...(await (await request('/icon', { method: 'PUT', body: file })).json()) }
|
|
35
|
+
}
|
|
36
|
+
if (payload.clearIcon) {
|
|
37
|
+
await request('/icon', { method: 'DELETE' })
|
|
38
|
+
return { ok: true, clearedIcon: true }
|
|
39
|
+
}
|
|
40
|
+
if (payload.name !== undefined || payload.clearName) {
|
|
41
|
+
const result = await (
|
|
42
|
+
await request('/config', {
|
|
43
|
+
method: 'PUT',
|
|
44
|
+
headers: { 'content-type': 'application/json' },
|
|
45
|
+
body: JSON.stringify({ name: payload.clearName ? null : payload.name })
|
|
46
|
+
})
|
|
47
|
+
).json()
|
|
48
|
+
return { ...result, ok: true, clearedName: payload.clearName === true }
|
|
49
|
+
}
|
|
50
|
+
const config: WorkspaceConfig = await (await request('/config')).json()
|
|
51
|
+
return { ...config, hasIcon: !!config.icon }
|
|
52
|
+
}
|
|
53
|
+
if (!op) throw new Error('Missing scratch operation')
|
|
54
|
+
if (op.kind === 'read') return { shapes: await readScratchpadShapes(workspace) }
|
|
55
|
+
if (op.kind === 'read-image') return readScratchpadImage(workspace, op.name)
|
|
56
|
+
const body = new FormData()
|
|
57
|
+
if (op.kind.startsWith('add-') && 'name' in op && !op.name)
|
|
58
|
+
op.name = `s_${crypto.randomUUID().slice(0, 8)}`
|
|
59
|
+
if (op.kind === 'add-image') {
|
|
60
|
+
const file = Bun.file(op.path)
|
|
61
|
+
if (!(await file.exists())) throw new Error('Local image file not found')
|
|
62
|
+
body.set('image', file)
|
|
63
|
+
// The owner receives bytes, never a caller's filesystem path.
|
|
64
|
+
body.set('op', JSON.stringify({ ...op, path: basename(op.path) }))
|
|
65
|
+
} else body.set('op', JSON.stringify(op))
|
|
66
|
+
return {
|
|
67
|
+
ok: true,
|
|
68
|
+
result: await (await request('/scratchpad/ops', { method: 'POST', body })).json()
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { defineCommand } from 'citty'
|
|
2
|
+
import { mkdir, rename, rm } from 'node:fs/promises'
|
|
3
|
+
import { dirname, resolve } from 'node:path'
|
|
4
|
+
import { z } from 'zod'
|
|
5
|
+
import { operation } from '../remote/client'
|
|
6
|
+
import { currentRemoteWorkspace } from '../remote/workspace'
|
|
7
|
+
|
|
8
|
+
const path = { type: 'string' as const, description: 'Local linked workspace folder' }
|
|
9
|
+
const json = { type: 'boolean' as const, description: 'Print JSON result' }
|
|
10
|
+
const commandResult = z.object({
|
|
11
|
+
exitCode: z.number().int(),
|
|
12
|
+
stdout: z.string(),
|
|
13
|
+
stderr: z.string()
|
|
14
|
+
})
|
|
15
|
+
async function printCommandResult(response: Response, json = false) {
|
|
16
|
+
const result = commandResult.parse(await response.json())
|
|
17
|
+
if (json) console.log(JSON.stringify(result))
|
|
18
|
+
else {
|
|
19
|
+
process.stdout.write(result.stdout)
|
|
20
|
+
process.stderr.write(result.stderr)
|
|
21
|
+
}
|
|
22
|
+
process.exitCode = result.exitCode < 0 ? 1 : result.exitCode
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Ordinary workspace commands can use the folder's remote link automatically. */
|
|
26
|
+
export async function runLinkedWorkspaceCommand(command: string, args: string[], folder: string) {
|
|
27
|
+
const linked = await currentRemoteWorkspace(folder)
|
|
28
|
+
if (!linked) return false
|
|
29
|
+
const response = await operation(linked.user_id, linked.workspace_id, '/commands', {
|
|
30
|
+
method: 'POST',
|
|
31
|
+
body: JSON.stringify({ command, args }),
|
|
32
|
+
contentType: 'application/json'
|
|
33
|
+
})
|
|
34
|
+
await printCommandResult(response)
|
|
35
|
+
return true
|
|
36
|
+
}
|
|
37
|
+
const execEvent = z.discriminatedUnion('type', [
|
|
38
|
+
z.object({ type: z.literal('stdout'), data: z.string() }),
|
|
39
|
+
z.object({ type: z.literal('stderr'), data: z.string() }),
|
|
40
|
+
z.object({ type: z.literal('exit'), code: z.number().int() })
|
|
41
|
+
])
|
|
42
|
+
const fileSuffix = (value: string) => {
|
|
43
|
+
if (
|
|
44
|
+
!value ||
|
|
45
|
+
value.startsWith('/') ||
|
|
46
|
+
value.includes('\\') ||
|
|
47
|
+
value.split('/').some(p => p === '.' || p === '..' || !p)
|
|
48
|
+
)
|
|
49
|
+
throw new Error('Use a file path relative to the remote workspace')
|
|
50
|
+
return '/files/' + value.split('/').map(encodeURIComponent).join('/')
|
|
51
|
+
}
|
|
52
|
+
async function target(folder?: string) {
|
|
53
|
+
const current = await currentRemoteWorkspace(folder)
|
|
54
|
+
if (!current)
|
|
55
|
+
throw new Error(
|
|
56
|
+
'This folder is not a remote workspace — run moi init --remote ownerId:workspaceId first'
|
|
57
|
+
)
|
|
58
|
+
return (suffix: string, options?: Parameters<typeof operation>[3]) =>
|
|
59
|
+
operation(current.user_id, current.workspace_id, suffix, options)
|
|
60
|
+
}
|
|
61
|
+
async function stdin() {
|
|
62
|
+
if (process.stdin.isTTY) throw new Error('Supply content or pipe it on stdin')
|
|
63
|
+
return Bun.stdin.text()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function remoteOperations(report: (action: () => Promise<void>) => Promise<void>) {
|
|
67
|
+
const read = defineCommand({
|
|
68
|
+
meta: { name: 'read', description: 'Read a remote workspace file to stdout' },
|
|
69
|
+
args: { file: { type: 'positional', required: true }, path },
|
|
70
|
+
run: ({ args }) =>
|
|
71
|
+
report(async () => {
|
|
72
|
+
const response = await (await target(args.path))(fileSuffix(args.file))
|
|
73
|
+
if (response.body)
|
|
74
|
+
for await (const chunk of response.body) await Bun.write(Bun.stdout, chunk)
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
const write = defineCommand({
|
|
78
|
+
meta: { name: 'write', description: 'Write a remote file; content argument or stdin' },
|
|
79
|
+
args: {
|
|
80
|
+
file: { type: 'positional', required: true },
|
|
81
|
+
content: { type: 'positional', required: false },
|
|
82
|
+
path,
|
|
83
|
+
json
|
|
84
|
+
},
|
|
85
|
+
run: ({ args }) =>
|
|
86
|
+
report(async () => {
|
|
87
|
+
const response = await (
|
|
88
|
+
await target(args.path)
|
|
89
|
+
)(fileSuffix(args.file), {
|
|
90
|
+
method: 'PUT',
|
|
91
|
+
body: args.content ?? (await stdin()),
|
|
92
|
+
contentType: 'application/octet-stream'
|
|
93
|
+
})
|
|
94
|
+
console.log(args.json ? JSON.stringify(await response.json()) : `Wrote ${args.file}`)
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
const patch = defineCommand({
|
|
98
|
+
meta: {
|
|
99
|
+
name: 'patch',
|
|
100
|
+
description: 'Apply a unified diff to a remote file (stdin or --patch-file)'
|
|
101
|
+
},
|
|
102
|
+
args: {
|
|
103
|
+
file: { type: 'positional', required: true },
|
|
104
|
+
'patch-file': { type: 'string' },
|
|
105
|
+
path,
|
|
106
|
+
json
|
|
107
|
+
},
|
|
108
|
+
run: ({ args }) =>
|
|
109
|
+
report(async () => {
|
|
110
|
+
const diff = args['patch-file']
|
|
111
|
+
? await Bun.file(resolve(args['patch-file'])).text()
|
|
112
|
+
: await stdin()
|
|
113
|
+
const response = await (
|
|
114
|
+
await target(args.path)
|
|
115
|
+
)(fileSuffix(args.file), {
|
|
116
|
+
method: 'PATCH',
|
|
117
|
+
body: JSON.stringify({ patch: diff }),
|
|
118
|
+
contentType: 'application/json'
|
|
119
|
+
})
|
|
120
|
+
console.log(args.json ? JSON.stringify(await response.json()) : `Patched ${args.file}`)
|
|
121
|
+
})
|
|
122
|
+
})
|
|
123
|
+
const upload = defineCommand({
|
|
124
|
+
meta: { name: 'file-upload', description: 'Upload a local file to a remote workspace path' },
|
|
125
|
+
args: {
|
|
126
|
+
source: { type: 'positional', required: true },
|
|
127
|
+
destination: { type: 'positional', required: true },
|
|
128
|
+
path,
|
|
129
|
+
json
|
|
130
|
+
},
|
|
131
|
+
run: ({ args }) =>
|
|
132
|
+
report(async () => {
|
|
133
|
+
const file = Bun.file(resolve(args.source))
|
|
134
|
+
if (!(await file.exists())) throw new Error('Local source file not found')
|
|
135
|
+
const response = await (
|
|
136
|
+
await target(args.path)
|
|
137
|
+
)(fileSuffix(args.destination), {
|
|
138
|
+
method: 'PUT',
|
|
139
|
+
body: file,
|
|
140
|
+
contentType: 'application/octet-stream'
|
|
141
|
+
})
|
|
142
|
+
console.log(
|
|
143
|
+
args.json ? JSON.stringify(await response.json()) : `Uploaded ${args.destination}`
|
|
144
|
+
)
|
|
145
|
+
})
|
|
146
|
+
})
|
|
147
|
+
const download = defineCommand({
|
|
148
|
+
meta: {
|
|
149
|
+
name: 'file-download',
|
|
150
|
+
description: 'Download a remote workspace file to a local path'
|
|
151
|
+
},
|
|
152
|
+
args: {
|
|
153
|
+
source: { type: 'positional', required: true },
|
|
154
|
+
destination: { type: 'positional', required: true },
|
|
155
|
+
path,
|
|
156
|
+
json
|
|
157
|
+
},
|
|
158
|
+
run: ({ args }) =>
|
|
159
|
+
report(async () => {
|
|
160
|
+
const response = await (await target(args.path))(fileSuffix(args.source))
|
|
161
|
+
const destination = resolve(args.destination),
|
|
162
|
+
temporary = `${destination}.${crypto.randomUUID()}.tmp`
|
|
163
|
+
await mkdir(dirname(destination), { recursive: true })
|
|
164
|
+
try {
|
|
165
|
+
await Bun.write(temporary, response)
|
|
166
|
+
await rename(temporary, destination)
|
|
167
|
+
} finally {
|
|
168
|
+
await rm(temporary, { force: true })
|
|
169
|
+
}
|
|
170
|
+
console.log(
|
|
171
|
+
args.json
|
|
172
|
+
? JSON.stringify({ ok: true, path: destination })
|
|
173
|
+
: `Downloaded ${args.destination}`
|
|
174
|
+
)
|
|
175
|
+
})
|
|
176
|
+
})
|
|
177
|
+
const exec = defineCommand({
|
|
178
|
+
meta: {
|
|
179
|
+
name: 'exec',
|
|
180
|
+
description: 'Run a shell command on the remote host, in this workspace'
|
|
181
|
+
},
|
|
182
|
+
args: { command: { type: 'positional', required: true }, path, json },
|
|
183
|
+
run: ({ args }) =>
|
|
184
|
+
report(async () => {
|
|
185
|
+
const controller = new AbortController()
|
|
186
|
+
const request = await target(args.path)
|
|
187
|
+
const id = crypto.randomUUID()
|
|
188
|
+
let cancellation: Promise<void> | undefined
|
|
189
|
+
const interrupt = () => {
|
|
190
|
+
cancellation ??= request('/exec', {
|
|
191
|
+
method: 'POST',
|
|
192
|
+
body: JSON.stringify({ cancel: id }),
|
|
193
|
+
contentType: 'application/json',
|
|
194
|
+
signal: AbortSignal.timeout(10_000)
|
|
195
|
+
})
|
|
196
|
+
.then(async response => {
|
|
197
|
+
await response.body?.cancel()
|
|
198
|
+
})
|
|
199
|
+
.catch(() => {
|
|
200
|
+
console.error('Could not confirm the remote command stopped')
|
|
201
|
+
})
|
|
202
|
+
.finally(() => controller.abort())
|
|
203
|
+
}
|
|
204
|
+
process.once('SIGINT', interrupt)
|
|
205
|
+
try {
|
|
206
|
+
const response = await request('/exec', {
|
|
207
|
+
method: 'POST',
|
|
208
|
+
body: JSON.stringify({ command: args.command, id }),
|
|
209
|
+
contentType: 'application/json',
|
|
210
|
+
signal: controller.signal
|
|
211
|
+
})
|
|
212
|
+
if (!response.body) throw new Error('Remote execution returned no stream')
|
|
213
|
+
let pending = '',
|
|
214
|
+
exit: number | undefined
|
|
215
|
+
const decoder = new TextDecoder()
|
|
216
|
+
for await (const chunk of response.body) {
|
|
217
|
+
pending += decoder.decode(chunk, { stream: true })
|
|
218
|
+
let end: number
|
|
219
|
+
while ((end = pending.indexOf('\n')) !== -1) {
|
|
220
|
+
const line = pending.slice(0, end)
|
|
221
|
+
pending = pending.slice(end + 1)
|
|
222
|
+
const event = execEvent.parse(JSON.parse(line))
|
|
223
|
+
if (args.json) console.log(JSON.stringify(event))
|
|
224
|
+
if (event.type === 'exit') exit = event.code
|
|
225
|
+
else if (!args.json)
|
|
226
|
+
(event.type === 'stdout' ? process.stdout : process.stderr).write(event.data)
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (exit === undefined || pending)
|
|
230
|
+
throw new Error(
|
|
231
|
+
'Remote execution disconnected before the exit code; command may still have run'
|
|
232
|
+
)
|
|
233
|
+
process.exitCode = exit < 0 ? 1 : exit
|
|
234
|
+
} catch (error) {
|
|
235
|
+
if (!cancellation) throw error
|
|
236
|
+
} finally {
|
|
237
|
+
process.removeListener('SIGINT', interrupt)
|
|
238
|
+
await cancellation
|
|
239
|
+
if (cancellation) process.exitCode = 130
|
|
240
|
+
}
|
|
241
|
+
})
|
|
242
|
+
})
|
|
243
|
+
return { read, write, patch, exec, 'file-upload': upload, 'file-download': download }
|
|
244
|
+
}
|
package/server/collab/config.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { HarnessType } from '@/lib/types'
|
|
2
2
|
|
|
3
3
|
import { getAppConfig } from '../app-config'
|
|
4
4
|
import { collabSkillReferencePath } from './skill'
|
|
5
5
|
|
|
6
6
|
export async function getCollabReferencePath(
|
|
7
7
|
workspacePath: string,
|
|
8
|
-
|
|
8
|
+
harness?: HarnessType
|
|
9
9
|
): Promise<string | undefined> {
|
|
10
10
|
if (getAppConfig().environment !== 'cloud') return undefined
|
|
11
|
-
const referencePath = collabSkillReferencePath(workspacePath,
|
|
11
|
+
const referencePath = collabSkillReferencePath(workspacePath, harness)
|
|
12
12
|
return (await Bun.file(referencePath).exists()) ? referencePath : undefined
|
|
13
13
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { join } from 'node:path'
|
|
2
|
-
import type {
|
|
2
|
+
import type { HarnessType } from '@/lib/types'
|
|
3
3
|
import { skillsDirFor } from '../../workspaces/init'
|
|
4
4
|
|
|
5
|
-
export function collabSkillReferencePath(workspacePath: string,
|
|
6
|
-
return join(skillsDirFor(workspacePath,
|
|
5
|
+
export function collabSkillReferencePath(workspacePath: string, harness?: HarnessType): string {
|
|
6
|
+
return join(skillsDirFor(workspacePath, harness), 'moi-workspace', 'references', 'COLLAB.md')
|
|
7
7
|
}
|
package/server/control.ts
CHANGED
|
@@ -27,7 +27,11 @@ import { assembleTabRows, assertNavigableTab } from './workspaces/tabs'
|
|
|
27
27
|
import { applyThemeUpdate } from './workspaces/theme'
|
|
28
28
|
import { handleBundle } from './applets/widgets'
|
|
29
29
|
import { getWorkspaceViews, handleBundleViews } from './applets/views'
|
|
30
|
-
import {
|
|
30
|
+
import {
|
|
31
|
+
completeRemoteViewBuilds,
|
|
32
|
+
updatePendingView,
|
|
33
|
+
PendingViewError
|
|
34
|
+
} from './sessions/pending-views'
|
|
31
35
|
import { createViewFromSession, ViewStartupError } from './sessions/view-sessions'
|
|
32
36
|
import {
|
|
33
37
|
getWorkspaceConfig,
|
|
@@ -138,7 +142,13 @@ export const control = Bun.serve({
|
|
|
138
142
|
}[] = []
|
|
139
143
|
await serializeWorkspaceBundle(workspacePath, async () => {
|
|
140
144
|
if (only?.segment !== 'views') {
|
|
141
|
-
for (const r of await handleBundle(
|
|
145
|
+
for (const r of await handleBundle(
|
|
146
|
+
publishEvent,
|
|
147
|
+
match.id,
|
|
148
|
+
workspacePath,
|
|
149
|
+
force,
|
|
150
|
+
only?.id
|
|
151
|
+
)) {
|
|
142
152
|
if (!only?.id || r.name === only.id) {
|
|
143
153
|
results.push({ kind: 'widget', name: r.name, status: r.status, error: r.error })
|
|
144
154
|
}
|
|
@@ -319,11 +329,8 @@ export const control = Bun.serve({
|
|
|
319
329
|
if (data.type === 'tabs') {
|
|
320
330
|
const match = await resolveWorkspace(ws, data.path)
|
|
321
331
|
if (!match) return
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
getWorkspaceViews(match)
|
|
325
|
-
])
|
|
326
|
-
ws.send(JSON.stringify({ ok: true, tabs: assembleTabRows(views, layout.tabs.active) }))
|
|
332
|
+
const views = await getWorkspaceViews(match)
|
|
333
|
+
ws.send(JSON.stringify({ ok: true, tabs: assembleTabRows(views) }))
|
|
327
334
|
return
|
|
328
335
|
}
|
|
329
336
|
|
|
@@ -336,7 +343,9 @@ export const control = Bun.serve({
|
|
|
336
343
|
if (!href.startsWith('moi:/') || href.startsWith('moi:/files/'))
|
|
337
344
|
throw new Error('Navigation needs a workspace page address')
|
|
338
345
|
const tab = href.slice(5).split('?', 1)[0]
|
|
339
|
-
|
|
346
|
+
// A linked folder's views live on the owner; the browser checks the tab itself.
|
|
347
|
+
if (isWorkspaceTabId(tab) && !match.remote)
|
|
348
|
+
assertNavigableTab(tab, await getWorkspaceViews(match))
|
|
340
349
|
await navigationRelay.navigate(match.id, href)
|
|
341
350
|
ws.send(JSON.stringify({ ok: true, href }))
|
|
342
351
|
} catch (error) {
|
|
@@ -349,24 +358,42 @@ export const control = Bun.serve({
|
|
|
349
358
|
return
|
|
350
359
|
}
|
|
351
360
|
|
|
361
|
+
// Sent by the CLI after a build on a remote workspace's owner.
|
|
362
|
+
if (data.type === 'views:reconcile') {
|
|
363
|
+
const match = await resolveWorkspace(ws, data.path)
|
|
364
|
+
if (!match) return
|
|
365
|
+
await completeRemoteViewBuilds(match)
|
|
366
|
+
ws.send(JSON.stringify({ ok: true }))
|
|
367
|
+
return
|
|
368
|
+
}
|
|
369
|
+
|
|
352
370
|
// Tell every connected applet to re-import its module (cache-bust) and
|
|
353
371
|
// re-run its data fetches. No rebuild, no page reload — `useApplet`
|
|
354
372
|
// handles `applets:refresh` like `*:updated` (invalidate + reload).
|
|
355
373
|
// `only` narrows to one kind or applet; default is both kinds.
|
|
356
374
|
// `widget:refresh` is the pre-filter message name older CLIs send.
|
|
357
375
|
if (data.type === 'applets:refresh' || data.type === 'widget:refresh') {
|
|
376
|
+
const match = data.path ? await resolveWorkspace(ws, data.path) : undefined
|
|
377
|
+
if (data.path && !match) return
|
|
378
|
+
const scope = match ? { workspaceId: match.id } : {}
|
|
358
379
|
const only = typeof data.only === 'string' ? parseAppletSelector(data.only) : undefined
|
|
359
380
|
if (data.only && !only) {
|
|
360
381
|
ws.send(JSON.stringify({ error: `Invalid applet selector "${data.only}"` }))
|
|
361
382
|
return
|
|
362
383
|
}
|
|
384
|
+
// No `workspaceId`: `moi refresh` names no workspace, so every open one reloads.
|
|
363
385
|
if (only?.id) {
|
|
364
386
|
publishEvent({
|
|
365
387
|
type: only.segment === 'widgets' ? 'widget:updated' : 'view:updated',
|
|
388
|
+
...scope,
|
|
366
389
|
name: only.id
|
|
367
390
|
})
|
|
368
391
|
} else {
|
|
369
|
-
publishEvent({
|
|
392
|
+
publishEvent({
|
|
393
|
+
type: 'applets:refresh',
|
|
394
|
+
...scope,
|
|
395
|
+
...(data.only ? { only: data.only } : {})
|
|
396
|
+
})
|
|
370
397
|
}
|
|
371
398
|
ws.send(JSON.stringify({ ok: true }))
|
|
372
399
|
return
|
|
@@ -437,7 +464,7 @@ export const control = Bun.serve({
|
|
|
437
464
|
}
|
|
438
465
|
|
|
439
466
|
await saveLayout({ ...layout, theme: result.theme }, workspacePath)
|
|
440
|
-
publishEvent({ type: 'theme:updated' })
|
|
467
|
+
publishEvent({ type: 'theme:updated', workspaceId: match.id })
|
|
441
468
|
ws.send(JSON.stringify({ ok: true, ...result.applied }))
|
|
442
469
|
return
|
|
443
470
|
}
|
|
@@ -480,7 +507,7 @@ export const control = Bun.serve({
|
|
|
480
507
|
}
|
|
481
508
|
|
|
482
509
|
await setWorkspaceConfig(workspacePath, patch)
|
|
483
|
-
publishEvent({ type: 'workspace:updated' })
|
|
510
|
+
publishEvent({ type: 'workspace:updated', workspaceId: match.id })
|
|
484
511
|
ws.send(
|
|
485
512
|
JSON.stringify({
|
|
486
513
|
ok: true,
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
} from '../../sessions/attachment-message'
|
|
27
27
|
import { type MoiContext, appendMoiContext, renderMoiContext } from '@/lib/moi-context'
|
|
28
28
|
import { type Part, applyEvent, emptyViewState } from '@/lib/format'
|
|
29
|
-
import type { Model, SessionActivity, StreamEvent, ViewState,
|
|
29
|
+
import type { Model, SessionActivity, StreamEvent, ViewState, HarnessType } from '@/lib/types'
|
|
30
30
|
|
|
31
31
|
import {
|
|
32
32
|
type AcpProviderId,
|
|
@@ -62,7 +62,7 @@ export type AcpSpawnContext = {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
export type AcpProviderConfig = {
|
|
65
|
-
id:
|
|
65
|
+
id: HarnessType
|
|
66
66
|
provider: AcpProviderId
|
|
67
67
|
spawn: (ctx: AcpSpawnContext) => Promise<AcpSpawnSpec>
|
|
68
68
|
// Session mode that disables approval prompts, matching moi's
|
|
@@ -363,9 +363,9 @@ function handleNotification(
|
|
|
363
363
|
// Force a fresh probe so the composer's banner flips right away.
|
|
364
364
|
function refreshAvailability(
|
|
365
365
|
rec: Pick<SessionRecord, 'workspaceId' | 'workspacePath'>,
|
|
366
|
-
id:
|
|
366
|
+
id: HarnessType
|
|
367
367
|
) {
|
|
368
|
-
void harnessStore.refresh({ id: rec.workspaceId, path: rec.workspacePath,
|
|
368
|
+
void harnessStore.refresh({ id: rec.workspaceId, path: rec.workspacePath, harness: id })
|
|
369
369
|
}
|
|
370
370
|
|
|
371
371
|
function createRecord(input: {
|