moi-computer 0.13.1-next.1 → 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/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 +14 -109
- 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 +66 -23
- package/client/features/views/use-view-actions.ts +10 -41
- 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 +1 -8
- package/client/features/workspace/use-workspace-navigation.ts +11 -7
- package/client/features/workspace/workspace-content.tsx +24 -31
- 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 +91 -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 +42 -16
- 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 +24 -9
- 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-a865c7x4.js +1 -0
- package/dist/chunk-f44cs6mw.js +2 -0
- package/dist/chunk-h3qag4a6.js +2 -0
- package/dist/chunk-kffcah9w.css +1 -0
- package/dist/chunk-q2tpy0h7.js +2 -0
- package/dist/chunk-r95acex1.js +546 -0
- package/dist/chunk-w5h9grdr.js +1 -0
- package/dist/{chunk-th91xfnp.js → chunk-xj1pjhng.js} +1 -1
- package/dist/index.html +1 -1
- package/lib/harness-instructions.ts +4 -4
- package/lib/harness-types.ts +13 -0
- package/lib/moi-context.ts +19 -5
- package/lib/types.ts +38 -54
- package/lib/workspace-config.ts +48 -0
- package/lib/workspace-layout.ts +5 -24
- package/package.json +5 -2
- package/server/AGENTS.md +1 -1
- package/server/README.md +36 -31
- package/server/api/harnesses.ts +5 -5
- package/server/api/index.ts +268 -162
- 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 +102 -54
- package/server/cli/commands/openclaw.ts +2 -2
- package/server/cli/commands/refresh.ts +10 -1
- package/server/cli/commands/remote.ts +330 -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 +73 -0
- package/server/cli/remote-operations.ts +247 -0
- package/server/collab/config.ts +3 -3
- package/server/collab/skill/index.ts +3 -3
- package/server/control.ts +47 -12
- 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 +2 -2
- 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/broker-client.ts +76 -0
- package/server/remote/broker.ts +81 -0
- package/server/remote/client.ts +725 -0
- package/server/remote/errors.ts +2 -0
- package/server/remote/routes.ts +121 -0
- package/server/remote/workspace.ts +34 -0
- package/server/scratchpad/document.ts +33 -12
- package/server/scratchpad/executor.ts +16 -7
- package/server/sessions/config.ts +8 -5
- package/server/sessions/pending-views.ts +17 -0
- package/server/sessions/send-message.ts +102 -0
- package/server/sessions/view-sessions.ts +9 -101
- 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 +13 -9
- package/server/workspace-state/file.ts +4 -0
- package/server/workspace-state/index.ts +0 -4
- package/server/workspaces/api.ts +24 -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 +5 -12
- package/skill/SKILL.md +80 -19
- package/skill/references/SCRATCHPAD.md +4 -0
- package/skill/references/UI-COMPONENTS.md +1 -1
- 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
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import { AGENT_CLIENTS } from '../../remote/agent'
|
|
2
|
+
import { defineCommand } from 'citty'
|
|
3
|
+
import open from 'open'
|
|
4
|
+
import { remoteOperations } from '../remote-operations'
|
|
5
|
+
import { clearLine, cursorTo } from 'node:readline'
|
|
6
|
+
import { currentRemoteWorkspace } from '../../remote/workspace'
|
|
7
|
+
import { parseRemoteWorkspaceAddress } from '@/lib/workspace-config'
|
|
8
|
+
import pc from '../pc'
|
|
9
|
+
import { columns, keyValue } from '../ui'
|
|
10
|
+
import { resolveWorkspace, staleSkillNotice } from '../../skills/version'
|
|
11
|
+
import { getLayoutPath } from '../../workspaces/layout'
|
|
12
|
+
import {
|
|
13
|
+
login as signIn,
|
|
14
|
+
logout as signOut,
|
|
15
|
+
CloudSignInRequired,
|
|
16
|
+
remoteStatus,
|
|
17
|
+
fetchSharedWorkspaces,
|
|
18
|
+
invitations as listInvitations,
|
|
19
|
+
accept as acceptInvitation,
|
|
20
|
+
renameAgent,
|
|
21
|
+
leave as leaveWorkspace
|
|
22
|
+
} from '../../remote/client'
|
|
23
|
+
|
|
24
|
+
// Profile fields are user supplied; they must not control the terminal.
|
|
25
|
+
// oxlint-disable-next-line no-control-regex -- Deliberately remove terminal control characters.
|
|
26
|
+
const text = (value: string) => Bun.stripANSI(value).replace(/[\u0000-\u001f\u007f-\u009f]/g, '')
|
|
27
|
+
|
|
28
|
+
async function warnIfSkillStale() {
|
|
29
|
+
try {
|
|
30
|
+
const { root, harness } = await resolveWorkspace(process.cwd())
|
|
31
|
+
if (!harness && !(await Bun.file(getLayoutPath(root)).exists())) return
|
|
32
|
+
const notice = await staleSkillNotice(root)
|
|
33
|
+
if (notice) console.error('\n' + pc.yellow(notice))
|
|
34
|
+
} catch {
|
|
35
|
+
// A skill check must not prevent displaying remote status.
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function reportErrors(action: () => Promise<void>): Promise<void> {
|
|
40
|
+
try {
|
|
41
|
+
await action()
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if (
|
|
44
|
+
error instanceof CloudSignInRequired ||
|
|
45
|
+
(error instanceof Error && error.message === 'Not signed in — run moi remote login')
|
|
46
|
+
) {
|
|
47
|
+
console.error(`${pc.dim('›')} Signed out`)
|
|
48
|
+
console.error(
|
|
49
|
+
pc.dim('› Run ') + pc.cyan('moi remote login') + pc.dim(' to connect to Moi Cloud')
|
|
50
|
+
)
|
|
51
|
+
} else {
|
|
52
|
+
console.error(error instanceof Error ? error.message : 'Cloud request failed')
|
|
53
|
+
}
|
|
54
|
+
process.exitCode = 1
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function waitingForLogin(): () => void {
|
|
59
|
+
const message = 'Waiting for authentication…'
|
|
60
|
+
if (!process.stderr.isTTY) {
|
|
61
|
+
console.error(message)
|
|
62
|
+
return () => {}
|
|
63
|
+
}
|
|
64
|
+
const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']
|
|
65
|
+
let frame = 0
|
|
66
|
+
const draw = () => {
|
|
67
|
+
cursorTo(process.stderr, 0)
|
|
68
|
+
process.stderr.write(pc.dim(`${frames[frame++ % frames.length]} ${message}`))
|
|
69
|
+
}
|
|
70
|
+
draw()
|
|
71
|
+
const timer = setInterval(draw, 80)
|
|
72
|
+
const stop = () => {
|
|
73
|
+
clearInterval(timer)
|
|
74
|
+
clearLine(process.stderr, 0)
|
|
75
|
+
cursorTo(process.stderr, 0)
|
|
76
|
+
process.removeListener('SIGINT', interrupt)
|
|
77
|
+
}
|
|
78
|
+
const interrupt = () => {
|
|
79
|
+
stop()
|
|
80
|
+
process.exit(130)
|
|
81
|
+
}
|
|
82
|
+
process.once('SIGINT', interrupt)
|
|
83
|
+
return stop
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const login = defineCommand({
|
|
87
|
+
meta: { name: 'login', description: 'Sign in to Moi Cloud in your browser (for humans only)' },
|
|
88
|
+
args: {
|
|
89
|
+
browser: {
|
|
90
|
+
type: 'boolean',
|
|
91
|
+
default: true,
|
|
92
|
+
description: 'Open the login page (use --no-browser to print its URL only)'
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
async run({ args }) {
|
|
96
|
+
await reportErrors(async () => {
|
|
97
|
+
let stopWaiting = () => {}
|
|
98
|
+
try {
|
|
99
|
+
await signIn(async (url, code) => {
|
|
100
|
+
console.log(`\nVisit ${pc.bold(url)}\nCode: ${text(code)}\n`)
|
|
101
|
+
if (args.browser) await open(url).catch(() => {})
|
|
102
|
+
stopWaiting = waitingForLogin()
|
|
103
|
+
})
|
|
104
|
+
} finally {
|
|
105
|
+
stopWaiting()
|
|
106
|
+
}
|
|
107
|
+
const { me } = await remoteStatus()
|
|
108
|
+
const identity = 'email' in me ? me.email : me.name
|
|
109
|
+
console.log(`${pc.green('✓')} Signed in as ${text(identity)}\n`)
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
const logout = defineCommand({
|
|
115
|
+
meta: { name: 'logout', description: 'Sign out of Moi Cloud' },
|
|
116
|
+
args: { yes: { type: 'boolean', description: 'Confirm permanently revoking this agent login' } },
|
|
117
|
+
async run({ args }) {
|
|
118
|
+
await reportErrors(async () => {
|
|
119
|
+
await signOut(args.yes)
|
|
120
|
+
console.log(`${pc.green('✓')} Signed out`)
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
const jsonArg = { type: 'boolean' as const, description: 'Print JSON' }
|
|
126
|
+
const rename = defineCommand({
|
|
127
|
+
meta: {
|
|
128
|
+
name: 'rename-agent',
|
|
129
|
+
description: 'Change your agent name across workspaces (for agents only)'
|
|
130
|
+
},
|
|
131
|
+
args: { name: { type: 'positional', required: true }, json: jsonArg },
|
|
132
|
+
async run({ args }) {
|
|
133
|
+
await reportErrors(async () => {
|
|
134
|
+
const result = await renameAgent(args.name)
|
|
135
|
+
console.log(args.json ? JSON.stringify(result) : `Agent renamed to ${text(result.name)}`)
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
const invitations = defineCommand({
|
|
140
|
+
meta: { name: 'invitations', description: 'List pending workspace invitations' },
|
|
141
|
+
args: { json: jsonArg },
|
|
142
|
+
async run({ args }) {
|
|
143
|
+
await reportErrors(async () => {
|
|
144
|
+
const result = await listInvitations()
|
|
145
|
+
if (args.json) console.log(JSON.stringify(result))
|
|
146
|
+
else if (!result.length) console.log('No pending invitations')
|
|
147
|
+
else
|
|
148
|
+
for (const invitation of result)
|
|
149
|
+
console.log(
|
|
150
|
+
`${text(invitation.id)} ${text(invitation.workspaceName)} — ${text(invitation.inviter.name)}`
|
|
151
|
+
)
|
|
152
|
+
})
|
|
153
|
+
}
|
|
154
|
+
})
|
|
155
|
+
const workspaces = defineCommand({
|
|
156
|
+
meta: { name: 'workspaces', description: 'List shared workspaces and pending invitations' },
|
|
157
|
+
args: { json: jsonArg },
|
|
158
|
+
async run({ args }) {
|
|
159
|
+
await reportErrors(async () => {
|
|
160
|
+
const [available, pending] = await Promise.all([fetchSharedWorkspaces(), listInvitations()])
|
|
161
|
+
if (args.json) {
|
|
162
|
+
console.log(JSON.stringify({ workspaces: available, invitations: pending }, null, 2))
|
|
163
|
+
return
|
|
164
|
+
}
|
|
165
|
+
console.log('\n' + pc.bold('Available shared workspaces') + '\n')
|
|
166
|
+
if (available.length) {
|
|
167
|
+
console.log(
|
|
168
|
+
columns(
|
|
169
|
+
['Workspace', 'Shared by', 'Remote ID'].map(label => pc.dim(label)),
|
|
170
|
+
available.map(workspace => [
|
|
171
|
+
text(workspace.id),
|
|
172
|
+
text(workspace.owner.email),
|
|
173
|
+
text(`${workspace.owner.id}:${workspace.id}`)
|
|
174
|
+
])
|
|
175
|
+
)
|
|
176
|
+
)
|
|
177
|
+
console.log(
|
|
178
|
+
'\n' + pc.dim('To link from a new folder: ') + pc.cyan('moi init --remote <remote-id>')
|
|
179
|
+
)
|
|
180
|
+
} else console.log(' No shared workspaces yet')
|
|
181
|
+
console.log('\n' + pc.bold('Pending invitations') + '\n')
|
|
182
|
+
if (pending.length) {
|
|
183
|
+
console.log(
|
|
184
|
+
columns(
|
|
185
|
+
['Workspace', 'Invited by', 'Invitation ID'].map(label => pc.dim(label)),
|
|
186
|
+
pending.map(invitation => [
|
|
187
|
+
text(invitation.workspaceName),
|
|
188
|
+
text(invitation.inviter.email),
|
|
189
|
+
text(invitation.id)
|
|
190
|
+
])
|
|
191
|
+
)
|
|
192
|
+
)
|
|
193
|
+
console.log('\n' + pc.dim('To accept: ') + pc.cyan('moi remote accept <invitation-id>'))
|
|
194
|
+
} else console.log(' No pending invitations')
|
|
195
|
+
console.log('\nHelp and full command list: ' + pc.cyan('moi remote workspaces --help') + '\n')
|
|
196
|
+
})
|
|
197
|
+
}
|
|
198
|
+
})
|
|
199
|
+
const accept = defineCommand({
|
|
200
|
+
meta: { name: 'accept', description: 'Accept a workspace invitation as a human or agent' },
|
|
201
|
+
args: {
|
|
202
|
+
invite: { type: 'positional', required: true },
|
|
203
|
+
name: { type: 'string', description: 'Your agent display name, shown to workspace members' },
|
|
204
|
+
client: {
|
|
205
|
+
type: 'string',
|
|
206
|
+
description: 'The app you run in: ' + AGENT_CLIENTS.join(', ') + '; use other if not listed'
|
|
207
|
+
},
|
|
208
|
+
json: jsonArg
|
|
209
|
+
},
|
|
210
|
+
async run({ args }) {
|
|
211
|
+
await reportErrors(async () => {
|
|
212
|
+
const result = await acceptInvitation(args.invite, args.name, args.client)
|
|
213
|
+
console.log(
|
|
214
|
+
args.json
|
|
215
|
+
? JSON.stringify(result)
|
|
216
|
+
: `Invitation accepted\n\nCreate a local linked folder (choose an unused folder name):\nmoi init ./workspace-folder --remote ${result.remote.user_id}:${result.remote.workspace_id}`
|
|
217
|
+
)
|
|
218
|
+
})
|
|
219
|
+
}
|
|
220
|
+
})
|
|
221
|
+
const leave = defineCommand({
|
|
222
|
+
meta: { name: 'leave', description: 'Leave a shared workspace; keep local files' },
|
|
223
|
+
args: {
|
|
224
|
+
workspace: {
|
|
225
|
+
type: 'positional',
|
|
226
|
+
required: false,
|
|
227
|
+
description: 'ownerId:workspaceId (defaults to current folder)'
|
|
228
|
+
},
|
|
229
|
+
json: jsonArg
|
|
230
|
+
},
|
|
231
|
+
async run({ args }) {
|
|
232
|
+
await reportErrors(async () => {
|
|
233
|
+
const target =
|
|
234
|
+
args.workspace !== undefined
|
|
235
|
+
? parseRemoteWorkspaceAddress(args.workspace)
|
|
236
|
+
: await currentRemoteWorkspace()
|
|
237
|
+
if (!target)
|
|
238
|
+
throw new Error(
|
|
239
|
+
'No remote workspace here — run from a linked workspace folder or provide ownerId:workspaceId'
|
|
240
|
+
)
|
|
241
|
+
const result = await leaveWorkspace(target.user_id, target.workspace_id)
|
|
242
|
+
console.log(args.json ? JSON.stringify(result) : 'Left the workspace; local files kept')
|
|
243
|
+
})
|
|
244
|
+
}
|
|
245
|
+
})
|
|
246
|
+
const remoteSubCommands = {
|
|
247
|
+
...remoteOperations(reportErrors),
|
|
248
|
+
login,
|
|
249
|
+
logout,
|
|
250
|
+
'rename-agent': rename,
|
|
251
|
+
workspaces,
|
|
252
|
+
invitations,
|
|
253
|
+
accept,
|
|
254
|
+
leave
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export const remote = defineCommand({
|
|
258
|
+
meta: { name: 'remote', description: 'Show your identity and linked workspace commands' },
|
|
259
|
+
args: { json: jsonArg },
|
|
260
|
+
subCommands: remoteSubCommands,
|
|
261
|
+
setup({ rawArgs }) {
|
|
262
|
+
// Citty accepts unknown options. Reject the removed selector before dispatch
|
|
263
|
+
// so an old script cannot silently operate on the current workspace.
|
|
264
|
+
const separator = rawArgs.indexOf('--')
|
|
265
|
+
const options = separator < 0 ? rawArgs : rawArgs.slice(0, separator)
|
|
266
|
+
if (options.some(arg => arg === '--path' || arg.startsWith('--path='))) {
|
|
267
|
+
throw new Error('Unknown option --path — run this command from the workspace folder')
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
async run({ args, rawArgs }) {
|
|
271
|
+
// citty also runs the parent after a subcommand; only bare `remote` shows status.
|
|
272
|
+
const sub = rawArgs.find(arg => !arg.startsWith('-'))
|
|
273
|
+
if (sub && Object.hasOwn(remoteSubCommands, sub)) return
|
|
274
|
+
await reportErrors(async () => {
|
|
275
|
+
const status = {
|
|
276
|
+
...(await remoteStatus()),
|
|
277
|
+
currentWorkspace: await currentRemoteWorkspace()
|
|
278
|
+
}
|
|
279
|
+
if (args.json) {
|
|
280
|
+
console.log(JSON.stringify(status, null, 2))
|
|
281
|
+
await warnIfSkillStale()
|
|
282
|
+
return
|
|
283
|
+
}
|
|
284
|
+
const detail = 'email' in status.me ? status.me.email : status.me.client
|
|
285
|
+
console.log(
|
|
286
|
+
'\nSigned in as ' + pc.bold(text(status.me.name || detail)) + pc.dim(` <${text(detail)}>`)
|
|
287
|
+
)
|
|
288
|
+
const linked = status.currentWorkspace
|
|
289
|
+
if (linked) {
|
|
290
|
+
const workspace = status.workspaces.find(
|
|
291
|
+
item => item.id === linked.workspace_id && item.owner.id === linked.user_id
|
|
292
|
+
)
|
|
293
|
+
console.log(
|
|
294
|
+
'\nCurrent workspace is linked to: ' +
|
|
295
|
+
pc.bold(text(linked.workspace_id)) +
|
|
296
|
+
(workspace ? ' by ' + text(workspace.owner.email) : '')
|
|
297
|
+
)
|
|
298
|
+
console.log('Remote ID: ' + text(`${linked.user_id}:${linked.workspace_id}`))
|
|
299
|
+
console.log(
|
|
300
|
+
'\n' +
|
|
301
|
+
keyValue([
|
|
302
|
+
[pc.cyan('moi remote read <remote-path>'), 'Read a file'],
|
|
303
|
+
[pc.cyan('moi remote write <remote-path> "content"'), 'Write a file'],
|
|
304
|
+
[pc.cyan('moi remote patch <remote-path>'), 'Apply a diff from stdin'],
|
|
305
|
+
[pc.cyan('moi remote exec "command"'), 'Run a command remotely'],
|
|
306
|
+
[pc.cyan('moi remote file-upload <local-path> <remote-path>'), 'Upload a local file'],
|
|
307
|
+
[
|
|
308
|
+
pc.cyan('moi remote file-download <remote-path> <local-path>'),
|
|
309
|
+
'Download a remote file'
|
|
310
|
+
]
|
|
311
|
+
])
|
|
312
|
+
)
|
|
313
|
+
console.log(
|
|
314
|
+
'\n' +
|
|
315
|
+
pc.cyan(
|
|
316
|
+
'moi check|bundle|theme|config|tabs|ui-components|call-server-fn|debug|scratch'
|
|
317
|
+
) +
|
|
318
|
+
'\n' +
|
|
319
|
+
pc.dim('These regular commands work on the remote workspace')
|
|
320
|
+
)
|
|
321
|
+
} else {
|
|
322
|
+
console.log('\nThis folder is not linked to a remote workspace')
|
|
323
|
+
}
|
|
324
|
+
console.log('\n' + pc.dim('Help and full command list: ') + pc.cyan('moi remote --help'))
|
|
325
|
+
if (linked) console.log(pc.dim('Command help: ') + pc.cyan('moi remote <command> --help'))
|
|
326
|
+
console.log()
|
|
327
|
+
await warnIfSkillStale()
|
|
328
|
+
})
|
|
329
|
+
}
|
|
330
|
+
})
|
|
@@ -14,8 +14,8 @@ import { columns } from '../ui'
|
|
|
14
14
|
// same way `moi bundle` does, so it works from `.moi/` or any subdirectory.
|
|
15
15
|
async function runSkillUpdate(cwd: string): Promise<void> {
|
|
16
16
|
// Include the primary harness destination and existing copies for other agents.
|
|
17
|
-
const { root,
|
|
18
|
-
const result = await updateWorkspaceSkills(root,
|
|
17
|
+
const { root, harness } = await resolveWorkspace(cwd)
|
|
18
|
+
const result = await updateWorkspaceSkills(root, harness)
|
|
19
19
|
const { changedSkills, updatedAppletTypes } = result
|
|
20
20
|
const heading = changedSkills.length > 0 ? 'Skills updated in ' : 'Skills unchanged in '
|
|
21
21
|
|
|
@@ -97,8 +97,8 @@ export const skill = defineCommand({
|
|
|
97
97
|
const sub = rawArgs.find(a => !a.startsWith('-'))
|
|
98
98
|
if (sub && sub in skillSubCommands) return
|
|
99
99
|
|
|
100
|
-
const { root,
|
|
101
|
-
const statuses = await skillStatuses(root,
|
|
100
|
+
const { root, harness } = await resolveWorkspace(resolve(args.dir))
|
|
101
|
+
const statuses = await skillStatuses(root, harness)
|
|
102
102
|
|
|
103
103
|
console.log('\n' + pc.bold('moi skill') + pc.dim(' — workspace skills') + '\n')
|
|
104
104
|
console.log(
|
|
@@ -5,25 +5,18 @@ import { sendControl } from '../control'
|
|
|
5
5
|
import pc from '../pc'
|
|
6
6
|
import { columns } from '../ui'
|
|
7
7
|
|
|
8
|
-
// The listing behind `moi tabs`: every tab (static + views), one per row
|
|
9
|
-
// saved default (`layout.tabs.active`) marked. The
|
|
8
|
+
// The listing behind `moi tabs`: every tab (static + views), one per row. The
|
|
10
9
|
// addresses are documented in docs/navigation.md.
|
|
11
10
|
function runTabsList(dir: string) {
|
|
12
11
|
const path = resolve(dir)
|
|
13
12
|
sendControl(path, { type: 'tabs', path }, res => {
|
|
14
|
-
type Row = { title: string;
|
|
13
|
+
type Row = { title: string; href: string }
|
|
15
14
|
const rows: Row[] = Array.isArray(res.tabs) ? (res.tabs as Row[]) : []
|
|
16
|
-
console.log(
|
|
17
|
-
'\n' + pc.bold('moi tabs') + pc.dim(' — workspace tabs, the default one marked') + '\n'
|
|
18
|
-
)
|
|
15
|
+
console.log('\n' + pc.bold('moi tabs') + pc.dim(' — workspace tabs') + '\n')
|
|
19
16
|
console.log(
|
|
20
17
|
columns(
|
|
21
|
-
['
|
|
22
|
-
rows.map(row => [
|
|
23
|
-
row.isDefault ? pc.green('●') : ' ',
|
|
24
|
-
row.isDefault ? pc.bold(row.title) : row.title,
|
|
25
|
-
row.href
|
|
26
|
-
])
|
|
18
|
+
['title', 'address'].map(h => pc.dim(h)),
|
|
19
|
+
rows.map(row => [row.title, row.href])
|
|
27
20
|
)
|
|
28
21
|
)
|
|
29
22
|
console.log('\n' + pc.dim(' Open one: moi navigate <address>') + '\n')
|
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,73 @@
|
|
|
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 { cloudRoutes } from '../remote/routes'
|
|
6
|
+
import { assembleTabRows } from '../workspaces/tabs'
|
|
7
|
+
import { readScratchpadImage, readScratchpadShapes } from '../scratchpad/document'
|
|
8
|
+
import type { WorkspaceConfig } from '../workspaces/config'
|
|
9
|
+
|
|
10
|
+
const { views, config, icon, scratchpadOps } = cloudRoutes
|
|
11
|
+
const routes = { views, config, icon, scratchpadOps }
|
|
12
|
+
|
|
13
|
+
type ScratchCliOp = ScratchOp | { kind: 'read' } | { kind: 'read-image'; name: string }
|
|
14
|
+
|
|
15
|
+
// These commands keep parsing, local file IO and output on the caller. Only
|
|
16
|
+
// shared data crosses the owner API. Browser rendering stays on visitor control.
|
|
17
|
+
export async function remoteControl(
|
|
18
|
+
path: string,
|
|
19
|
+
payload: Record<string, unknown>
|
|
20
|
+
): Promise<Record<string, unknown> | undefined> {
|
|
21
|
+
if (!['config', 'scratch', 'tabs'].includes(String(payload.type))) return
|
|
22
|
+
const op = payload.op as ScratchCliOp | undefined
|
|
23
|
+
if (payload.type === 'scratch' && op?.kind === 'view') return
|
|
24
|
+
const remote = await currentRemoteWorkspace(path)
|
|
25
|
+
if (!remote) return
|
|
26
|
+
const workspace = { remote }
|
|
27
|
+
const request = (route: keyof typeof routes, init?: RequestInit) =>
|
|
28
|
+
requestWorkspace(routes[route].path(remote), init)
|
|
29
|
+
if (payload.type === 'tabs') {
|
|
30
|
+
const { views }: { views: ViewInfo[] } = await (await request('views')).json()
|
|
31
|
+
return { tabs: assembleTabRows(views) }
|
|
32
|
+
}
|
|
33
|
+
if (payload.type === 'config') {
|
|
34
|
+
if (typeof payload.iconPath === 'string') {
|
|
35
|
+
const file = Bun.file(payload.iconPath)
|
|
36
|
+
if (!(await file.exists())) throw new Error('Local icon file not found')
|
|
37
|
+
return { ok: true, ...(await (await request('icon', { method: 'PUT', body: file })).json()) }
|
|
38
|
+
}
|
|
39
|
+
if (payload.clearIcon) {
|
|
40
|
+
await request('icon', { method: 'DELETE' })
|
|
41
|
+
return { ok: true, clearedIcon: true }
|
|
42
|
+
}
|
|
43
|
+
if (payload.name !== undefined || payload.clearName) {
|
|
44
|
+
const result = await (
|
|
45
|
+
await request('config', {
|
|
46
|
+
method: 'PUT',
|
|
47
|
+
headers: { 'content-type': 'application/json' },
|
|
48
|
+
body: JSON.stringify({ name: payload.clearName ? null : payload.name })
|
|
49
|
+
})
|
|
50
|
+
).json()
|
|
51
|
+
return { ...result, ok: true, clearedName: payload.clearName === true }
|
|
52
|
+
}
|
|
53
|
+
const config: WorkspaceConfig = await (await request('config')).json()
|
|
54
|
+
return { ...config, hasIcon: !!config.icon }
|
|
55
|
+
}
|
|
56
|
+
if (!op) throw new Error('Missing scratch operation')
|
|
57
|
+
if (op.kind === 'read') return { shapes: await readScratchpadShapes(workspace) }
|
|
58
|
+
if (op.kind === 'read-image') return readScratchpadImage(workspace, op.name)
|
|
59
|
+
const body = new FormData()
|
|
60
|
+
if (op.kind.startsWith('add-') && 'name' in op && !op.name)
|
|
61
|
+
op.name = `s_${crypto.randomUUID().slice(0, 8)}`
|
|
62
|
+
if (op.kind === 'add-image') {
|
|
63
|
+
const file = Bun.file(op.path)
|
|
64
|
+
if (!(await file.exists())) throw new Error('Local image file not found')
|
|
65
|
+
body.set('image', file)
|
|
66
|
+
// The owner receives bytes, never a caller's filesystem path.
|
|
67
|
+
body.set('op', JSON.stringify({ ...op, path: basename(op.path) }))
|
|
68
|
+
} else body.set('op', JSON.stringify(op))
|
|
69
|
+
return {
|
|
70
|
+
ok: true,
|
|
71
|
+
result: await (await request('scratchpadOps', { method: 'POST', body })).json()
|
|
72
|
+
}
|
|
73
|
+
}
|