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
package/server/applets/index.ts
CHANGED
|
@@ -182,13 +182,24 @@ export async function serveApplet(
|
|
|
182
182
|
if (HASHED_FILE_RE.test(file)) {
|
|
183
183
|
cache = { 'Cache-Control': IMMUTABLE_CACHE }
|
|
184
184
|
} else {
|
|
185
|
-
|
|
185
|
+
// The served representation also depends on the API-base substitution format.
|
|
186
|
+
const etag = `"${bunFile.size}-${Math.trunc(bunFile.lastModified)}-${Bun.hash(apiBase)}-url-base-v2"`
|
|
186
187
|
cache = { ETag: etag, 'Cache-Control': 'private, no-cache' }
|
|
187
188
|
if (ifNoneMatch === etag) return new Response(null, { status: 304, headers: cache })
|
|
188
189
|
}
|
|
189
190
|
|
|
190
191
|
if (CODE_FILE_RE.test(file)) {
|
|
191
|
-
const
|
|
192
|
+
const runtimeBase = `(new URL(import.meta.url).pathname.match(/^\\/api\\/workspaces\\/[^/]+/)?.[0] ?? ${JSON.stringify(apiBase)})`
|
|
193
|
+
const swapped = (await bunFile.text()).replace(
|
|
194
|
+
/(["'])([^"'\n]*%%MOI_APPLET_API_BASE%%[^"'\n]*)\1/g,
|
|
195
|
+
(_match, _quote: string, value: string) =>
|
|
196
|
+
'(' +
|
|
197
|
+
value
|
|
198
|
+
.split(APPLET_API_BASE_SENTINEL)
|
|
199
|
+
.map(part => JSON.stringify(part))
|
|
200
|
+
.join(' + ' + runtimeBase + ' + ') +
|
|
201
|
+
')'
|
|
202
|
+
)
|
|
192
203
|
return new Response(swapped, { headers: { 'Content-Type': JS_CONTENT_TYPE, ...cache } })
|
|
193
204
|
}
|
|
194
205
|
return new Response(bunFile, {
|
|
@@ -200,12 +211,6 @@ export async function serveApplet(
|
|
|
200
211
|
// Pure helpers behind the applet/files/rpc HTTP routes, kept here (not web.ts) so
|
|
201
212
|
// they're unit-testable without importing web.ts — which binds ports on load.
|
|
202
213
|
|
|
203
|
-
// The API base a served bundle's sentinel is rewritten to. RPC and workspace
|
|
204
|
-
// file addresses resolved by `resolveUrl()` use this prefix.
|
|
205
|
-
export function apiBaseFor(id: string): string {
|
|
206
|
-
return `/api/workspaces/${id}`
|
|
207
|
-
}
|
|
208
|
-
|
|
209
214
|
// The entry's real name in the bundle dir (`.build/<kind>/<name>/index.js`).
|
|
210
215
|
const ENTRY_DISK_FILE = 'index.js'
|
|
211
216
|
|
|
@@ -241,7 +246,8 @@ export function parseAppletTail(
|
|
|
241
246
|
id: string,
|
|
242
247
|
segment: 'widgets' | 'views'
|
|
243
248
|
): { name: string; file: string } {
|
|
244
|
-
const tail =
|
|
249
|
+
const tail =
|
|
250
|
+
new URL(url).pathname.split(`/workspaces/${encodeURIComponent(id)}/${segment}/`)[1] ?? ''
|
|
245
251
|
const slash = tail.indexOf('/')
|
|
246
252
|
if (slash === -1) return { name: tail.replace(/\.js$/, ''), file: ENTRY_DISK_FILE }
|
|
247
253
|
const file = tail.slice(slash + 1)
|
package/server/applets/views.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs'
|
|
2
2
|
|
|
3
|
-
import { viewTabId } from '@/lib/workspace-tabs'
|
|
4
3
|
import type { CompiledView, ViewConfig, ViewInfo, WorkspaceEntry } from '@/lib/types'
|
|
5
4
|
|
|
6
5
|
import { syncAppletLogAfterBuild } from './log'
|
|
@@ -14,7 +13,6 @@ import {
|
|
|
14
13
|
} from './'
|
|
15
14
|
import { serializeWorkspaceBundle } from './bundle-queue'
|
|
16
15
|
import { reloadModules } from './functions'
|
|
17
|
-
import { loadLayout, saveLayout } from '../workspaces/layout'
|
|
18
16
|
import { completeViewBuild, listPendingViews } from '../sessions/pending-views'
|
|
19
17
|
import { archiveViewSessions } from '../sessions/archive'
|
|
20
18
|
import type { WorkspaceRef } from '../workspace-state'
|
|
@@ -222,7 +220,7 @@ export async function handleBundleViews(
|
|
|
222
220
|
const changedServerModules = new Set<string>()
|
|
223
221
|
for (const r of results) {
|
|
224
222
|
if (r.status === 'built') {
|
|
225
|
-
publish({ type: 'view:updated', name: r.name, config: r.config ?? null })
|
|
223
|
+
publish({ type: 'view:updated', workspaceId, name: r.name, config: r.config ?? null })
|
|
226
224
|
await completeViewBuild({ id: workspaceId, path: workspacePath }, r.name)
|
|
227
225
|
for (const m of r.serverModules ?? []) changedServerModules.add(m)
|
|
228
226
|
}
|
|
@@ -307,21 +305,8 @@ export async function deleteView(
|
|
|
307
305
|
}
|
|
308
306
|
reloadModules([`views/${viewId}`], workspacePath)
|
|
309
307
|
await completeViewBuild(ws, viewId)
|
|
310
|
-
const layout = await loadLayout(workspacePath)
|
|
311
|
-
const tab = viewTabId(viewId)
|
|
312
|
-
await saveLayout(
|
|
313
|
-
{
|
|
314
|
-
...layout,
|
|
315
|
-
tabs: {
|
|
316
|
-
open: layout.tabs.open.filter(candidate => candidate !== tab),
|
|
317
|
-
active: layout.tabs.active === tab ? 'overview' : layout.tabs.active
|
|
318
|
-
}
|
|
319
|
-
},
|
|
320
|
-
workspacePath
|
|
321
|
-
)
|
|
322
|
-
|
|
323
308
|
publish({ type: 'view:deleted', workspaceId, name: viewId })
|
|
324
|
-
publish({ type: 'workspace:updated' })
|
|
309
|
+
publish({ type: 'workspace:updated', workspaceId })
|
|
325
310
|
await handleBundleViews(publish, workspaceId, workspacePath, false, viewId)
|
|
326
311
|
})
|
|
327
312
|
}
|
|
@@ -123,6 +123,7 @@ export async function listWidgets(workspacePath: string): Promise<Response> {
|
|
|
123
123
|
|
|
124
124
|
export async function handleBundle(
|
|
125
125
|
publish: (msg: unknown) => void,
|
|
126
|
+
workspaceId: string,
|
|
126
127
|
workspacePath: string,
|
|
127
128
|
force = false,
|
|
128
129
|
target?: string
|
|
@@ -151,7 +152,7 @@ export async function handleBundle(
|
|
|
151
152
|
const changedServerModules = new Set<string>()
|
|
152
153
|
for (const r of results) {
|
|
153
154
|
if (r.status === 'built') {
|
|
154
|
-
publish({ type: 'widget:updated', name: r.name, config: r.config ?? null })
|
|
155
|
+
publish({ type: 'widget:updated', workspaceId, name: r.name, config: r.config ?? null })
|
|
155
156
|
for (const m of r.serverModules ?? []) changedServerModules.add(m)
|
|
156
157
|
}
|
|
157
158
|
}
|
|
@@ -162,7 +163,7 @@ export async function handleBundle(
|
|
|
162
163
|
|
|
163
164
|
if (layoutChanged) {
|
|
164
165
|
const widgets = await getWidgetList(workspacePath)
|
|
165
|
-
publish({ type: 'widget-layout:updated', widgets })
|
|
166
|
+
publish({ type: 'widget-layout:updated', workspaceId, widgets })
|
|
166
167
|
}
|
|
167
168
|
|
|
168
169
|
return results
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { defineCommand } from 'citty'
|
|
2
2
|
import { resolve } from 'path'
|
|
3
|
-
import {
|
|
4
|
-
import { staleSkillNotice } from '../../skills/version'
|
|
5
|
-
import { exitControlUnreachable } from '../control'
|
|
3
|
+
import { sendControl } from '../control'
|
|
6
4
|
import pc from '../pc'
|
|
7
5
|
|
|
8
6
|
async function sendConfig(payload: {
|
|
@@ -12,27 +10,21 @@ async function sendConfig(payload: {
|
|
|
12
10
|
clearName?: boolean
|
|
13
11
|
clearIcon?: boolean
|
|
14
12
|
}) {
|
|
15
|
-
|
|
16
|
-
const ws = new WebSocket(CONTROL_URL)
|
|
17
|
-
ws.onopen = () => ws.send(JSON.stringify({ type: 'config', ...payload }))
|
|
18
|
-
ws.onmessage = event => {
|
|
19
|
-
const res = JSON.parse(String(event.data))
|
|
20
|
-
if (res.error) {
|
|
21
|
-
console.error('\n' + pc.red(pc.bold('Error:')) + ' ' + res.error + '\n')
|
|
22
|
-
ws.close()
|
|
23
|
-
process.exit(1)
|
|
24
|
-
}
|
|
13
|
+
await sendControl(payload.path, { type: 'config', ...payload }, res => {
|
|
25
14
|
console.log()
|
|
26
15
|
if (res.ok) {
|
|
27
16
|
if (res.clearedName) console.log(pc.green('✓') + ' Name reset to ' + pc.dim('(folder name)'))
|
|
28
|
-
else if (res.name) console.log(pc.green('✓') + ' Name set to ' + pc.bold(res.name))
|
|
17
|
+
else if (res.name) console.log(pc.green('✓') + ' Name set to ' + pc.bold(String(res.name)))
|
|
29
18
|
if (res.clearedIcon)
|
|
30
19
|
console.log(pc.green('✓') + ' Icon reset to ' + pc.dim('default (provider)'))
|
|
31
20
|
else if (res.icon) console.log(pc.green('✓') + ' Icon updated ' + pc.dim('(128×128 webp)'))
|
|
32
21
|
} else {
|
|
33
22
|
console.log(pc.bold('moi config') + ' — workspace identity\n')
|
|
34
23
|
console.log(
|
|
35
|
-
' ' +
|
|
24
|
+
' ' +
|
|
25
|
+
pc.dim('name') +
|
|
26
|
+
' ' +
|
|
27
|
+
(res.name ? pc.bold(String(res.name)) : pc.dim('(folder name)'))
|
|
36
28
|
)
|
|
37
29
|
console.log(
|
|
38
30
|
' ' +
|
|
@@ -42,11 +34,7 @@ async function sendConfig(payload: {
|
|
|
42
34
|
)
|
|
43
35
|
}
|
|
44
36
|
console.log()
|
|
45
|
-
|
|
46
|
-
ws.close()
|
|
47
|
-
process.exit(0)
|
|
48
|
-
}
|
|
49
|
-
ws.onerror = () => void exitControlUnreachable()
|
|
37
|
+
})
|
|
50
38
|
}
|
|
51
39
|
|
|
52
40
|
// A terse cheat sheet — one line per command — so an agent can grasp the
|
|
@@ -78,7 +78,7 @@ const hermesInit = defineCommand({
|
|
|
78
78
|
skillsDir: skillsRoot,
|
|
79
79
|
installLogPath
|
|
80
80
|
} = await provisionWorkspace(target.path, 'hermes')
|
|
81
|
-
if (scaffold !== 'exists') {
|
|
81
|
+
if (scaffold !== 'exists' && scaffold !== 'skipped') {
|
|
82
82
|
if (scaffold === 'installing') {
|
|
83
83
|
console.log('\n' + pc.dim(' Widget dependencies still installing in .moi/ (background)'))
|
|
84
84
|
console.log(pc.dim(' Install log: ' + installLogPath))
|
|
@@ -93,7 +93,7 @@ const hermesInit = defineCommand({
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
const entry = await registerWorkspace(target.path, {
|
|
96
|
-
|
|
96
|
+
harness: 'hermes',
|
|
97
97
|
name: target.name,
|
|
98
98
|
agentId: target.agentId,
|
|
99
99
|
isDefault: target.isDefault
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { initializeRemoteWorkspace } from '../../remote/workspace'
|
|
2
|
+
import { loadWorkspaceFileConfig } from '../../workspaces/layout'
|
|
3
|
+
import { parseRemoteWorkspaceAddress } from '@/lib/workspace-config'
|
|
4
|
+
import type { HarnessType, WorkspaceEntry } from '@/lib/types'
|
|
2
5
|
import { defineCommand } from 'citty'
|
|
3
6
|
import { existsSync } from 'node:fs'
|
|
4
7
|
import { join, resolve } from 'path'
|
|
@@ -21,7 +24,7 @@ import {
|
|
|
21
24
|
import { serverCwd } from '../../server-cwd'
|
|
22
25
|
import { superviseServerUpdates } from '../../update'
|
|
23
26
|
import { PACKAGE_ROOT } from '../../version'
|
|
24
|
-
import { provisionWorkspace } from '../../workspaces/init'
|
|
27
|
+
import { provisionWorkspace, skillsDirFor } from '../../workspaces/init'
|
|
25
28
|
import { isServerRunning, registerViaControl, waitForServer } from '../control'
|
|
26
29
|
import pc from '../pc'
|
|
27
30
|
import { spawnServer } from '../server'
|
|
@@ -34,7 +37,7 @@ import { keyValue } from '../ui'
|
|
|
34
37
|
async function resolveInitHarness(
|
|
35
38
|
target: string,
|
|
36
39
|
requested: string | undefined
|
|
37
|
-
): Promise<{
|
|
40
|
+
): Promise<{ harness: HarnessType; agent: DetectedAgent | null }> {
|
|
38
41
|
if (requested !== undefined) {
|
|
39
42
|
const value = requested.trim()
|
|
40
43
|
if (!isHarnessName(value)) {
|
|
@@ -61,7 +64,7 @@ async function resolveInitHarness(
|
|
|
61
64
|
pc.dim(' to bind it once ' + harnessLabel[value] + ' can see the workspace.')
|
|
62
65
|
)
|
|
63
66
|
}
|
|
64
|
-
return {
|
|
67
|
+
return { harness: value, agent }
|
|
65
68
|
}
|
|
66
69
|
|
|
67
70
|
// A registered workspace has already answered this question, and may carry no
|
|
@@ -70,12 +73,12 @@ async function resolveInitHarness(
|
|
|
70
73
|
// to refresh skills.
|
|
71
74
|
const known = (await listWorkspaces()).find(e => e.path === target)
|
|
72
75
|
if (known) {
|
|
73
|
-
const
|
|
76
|
+
const harness = known.harness ?? 'claude-code'
|
|
74
77
|
console.log(
|
|
75
|
-
'\n' + pc.dim(' Already registered — initializing for ') + pc.bold(harnessLabel[
|
|
78
|
+
'\n' + pc.dim(' Already registered — initializing for ') + pc.bold(harnessLabel[harness])
|
|
76
79
|
)
|
|
77
80
|
return {
|
|
78
|
-
|
|
81
|
+
harness,
|
|
79
82
|
agent: known.agentId
|
|
80
83
|
? {
|
|
81
84
|
agentId: known.agentId,
|
|
@@ -95,10 +98,10 @@ async function resolveInitHarness(
|
|
|
95
98
|
' Detected ' +
|
|
96
99
|
detected.reason +
|
|
97
100
|
' — initializing for ' +
|
|
98
|
-
pc.bold(harnessLabel[detected.
|
|
101
|
+
pc.bold(harnessLabel[detected.harness]) +
|
|
99
102
|
'.'
|
|
100
103
|
)
|
|
101
|
-
return {
|
|
104
|
+
return { harness: detected.harness, agent: detected.agent ?? null }
|
|
102
105
|
}
|
|
103
106
|
|
|
104
107
|
console.error('\n' + pc.red('✗') + ' No agent harness detected in ' + pc.bold(target))
|
|
@@ -119,9 +122,11 @@ async function resolveInitHarness(
|
|
|
119
122
|
export const init = defineCommand({
|
|
120
123
|
meta: {
|
|
121
124
|
name: 'init',
|
|
122
|
-
description: 'Initialize
|
|
125
|
+
description: 'Initialize a local or remote workspace and install its skill'
|
|
123
126
|
},
|
|
124
127
|
args: {
|
|
128
|
+
remote: { type: 'string', description: 'Remote workspace address: ownerId:workspaceId' },
|
|
129
|
+
json: { type: 'boolean', description: 'Print remote initialization as JSON' },
|
|
125
130
|
dir: {
|
|
126
131
|
type: 'positional',
|
|
127
132
|
default: '.',
|
|
@@ -143,13 +148,23 @@ export const init = defineCommand({
|
|
|
143
148
|
}
|
|
144
149
|
},
|
|
145
150
|
async run({ args }) {
|
|
151
|
+
if (
|
|
152
|
+
(args.remote !== undefined && (args.harness || args.id)) ||
|
|
153
|
+
(args.json && (args.remote === undefined || args.web))
|
|
154
|
+
) {
|
|
155
|
+
console.error(
|
|
156
|
+
'--remote cannot be combined with --harness or --id; --json requires --remote without --web'
|
|
157
|
+
)
|
|
158
|
+
process.exitCode = 1
|
|
159
|
+
return
|
|
160
|
+
}
|
|
146
161
|
const requested = resolve(args.dir)
|
|
147
162
|
// Locate the workspace root first: if invoked from inside a `.moi/` (or a
|
|
148
163
|
// deeper accidental `.moi/.moi/…`), lift to the directory that owns it
|
|
149
164
|
// instead of scaffolding a nested workspace. This is what stops the
|
|
150
165
|
// `.moi/.moi` bug at the source.
|
|
151
166
|
const target = liftToWorkspaceRoot(requested)
|
|
152
|
-
if (target !== requested) {
|
|
167
|
+
if (target !== requested && !args.json) {
|
|
153
168
|
console.log(
|
|
154
169
|
'\n' +
|
|
155
170
|
pc.yellow('◆') +
|
|
@@ -163,7 +178,7 @@ export const init = defineCommand({
|
|
|
163
178
|
// Flag a stray nested `.moi/.moi` left by the old cwd bug — harmless but
|
|
164
179
|
// confusing, and easy to remove.
|
|
165
180
|
const stray = join(target, '.moi', '.moi')
|
|
166
|
-
if (existsSync(stray)) {
|
|
181
|
+
if (existsSync(stray) && !args.json) {
|
|
167
182
|
console.log(
|
|
168
183
|
'\n' +
|
|
169
184
|
pc.yellow('⚠') +
|
|
@@ -188,52 +203,85 @@ export const init = defineCommand({
|
|
|
188
203
|
const projectRoot = PACKAGE_ROOT
|
|
189
204
|
const isInteractive = process.stdout.isTTY
|
|
190
205
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
// Provision: bundled skills + the `.moi/` bootstrap (widgets dir +
|
|
198
|
-
// package.json + bun install). An existing `.moi/` is left untouched.
|
|
199
|
-
console.log()
|
|
200
|
-
const { scaffold, skillsDir, installLogPath } = await provisionWorkspace(target, type)
|
|
201
|
-
if (scaffold !== 'exists') {
|
|
202
|
-
if (scaffold === 'installing') {
|
|
203
|
-
console.log(pc.dim(' Widget dependencies still installing in .moi/ (background)'))
|
|
204
|
-
console.log(pc.dim(' Install log: ' + installLogPath))
|
|
205
|
-
} else if (scaffold === 0) {
|
|
206
|
-
console.log(pc.dim(' Installed widget dependencies in .moi/'))
|
|
207
|
-
} else {
|
|
208
|
-
console.warn(
|
|
209
|
-
pc.yellow(` bun install failed (exit ${scaffold}) — run it manually in .moi/`)
|
|
206
|
+
let entry: Pick<WorkspaceEntry, 'id'>
|
|
207
|
+
if (args.remote !== undefined) {
|
|
208
|
+
try {
|
|
209
|
+
const result = await initializeRemoteWorkspace(
|
|
210
|
+
target,
|
|
211
|
+
parseRemoteWorkspaceAddress(args.remote)
|
|
210
212
|
)
|
|
211
|
-
|
|
213
|
+
if (args.json) {
|
|
214
|
+
console.log(JSON.stringify(result))
|
|
215
|
+
return
|
|
216
|
+
}
|
|
217
|
+
entry = result
|
|
218
|
+
console.log(pc.green('✓') + ' Linked ' + pc.bold(result.path) + ' to ' + args.remote)
|
|
219
|
+
console.log('\nNext:')
|
|
220
|
+
console.log(' 1. Read ' + join(skillsDirFor(result.path), 'moi-workspace', 'SKILL.md'))
|
|
221
|
+
console.log(' 2. Run commands from ' + result.path)
|
|
222
|
+
console.log(' 3. Run `moi remote` for available commands\n')
|
|
223
|
+
if (!args.web) return
|
|
224
|
+
} catch (error) {
|
|
225
|
+
console.error(error instanceof Error ? error.message : 'Remote initialization failed')
|
|
226
|
+
process.exitCode = 1
|
|
227
|
+
return
|
|
212
228
|
}
|
|
213
|
-
}
|
|
229
|
+
} else {
|
|
230
|
+
const config = await loadWorkspaceFileConfig(target)
|
|
231
|
+
if (config.remote) {
|
|
232
|
+
console.error(
|
|
233
|
+
`This is a remote workspace — use moi init --remote ${config.remote.user_id}:${config.remote.workspace_id}`
|
|
234
|
+
)
|
|
235
|
+
process.exitCode = 1
|
|
236
|
+
return
|
|
237
|
+
}
|
|
238
|
+
// Which backend this workspace is for has to be settled before
|
|
239
|
+
// provisioning: each harness reads skills from a different directory, and
|
|
240
|
+
// agent-owned ones (OpenClaw, Hermes) need their agent metadata on the
|
|
241
|
+
// registry entry — same as `moi <provider> init`.
|
|
242
|
+
const { harness, agent } = await resolveInitHarness(target, args.harness)
|
|
214
243
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
244
|
+
// Provision: bundled skills + the `.moi/` bootstrap (widgets dir +
|
|
245
|
+
// package.json + bun install). An existing `.moi/` is left untouched.
|
|
246
|
+
console.log()
|
|
247
|
+
const { scaffold, skillsDir, installLogPath } = await provisionWorkspace(target, harness)
|
|
248
|
+
if (scaffold !== 'exists' && scaffold !== 'skipped') {
|
|
249
|
+
if (scaffold === 'installing') {
|
|
250
|
+
console.log(pc.dim(' Widget dependencies still installing in .moi/ (background)'))
|
|
251
|
+
console.log(pc.dim(' Install log: ' + installLogPath))
|
|
252
|
+
} else if (scaffold === 0) {
|
|
253
|
+
console.log(pc.dim(' Installed widget dependencies in .moi/'))
|
|
254
|
+
} else {
|
|
255
|
+
console.warn(
|
|
256
|
+
pc.yellow(` bun install failed (exit ${scaffold}) — run it manually in .moi/`)
|
|
257
|
+
)
|
|
258
|
+
console.warn(pc.dim(' Install log: ' + installLogPath))
|
|
259
|
+
}
|
|
260
|
+
}
|
|
228
261
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
262
|
+
// Always register the workspace in the persistent registry
|
|
263
|
+
entry = await registerWorkspace(target, {
|
|
264
|
+
...(args.id ? { id: args.id } : {}),
|
|
265
|
+
harness: harness,
|
|
266
|
+
...(agent
|
|
267
|
+
? {
|
|
268
|
+
name: agent.name,
|
|
269
|
+
agentId: agent.agentId,
|
|
270
|
+
isDefault: agent.isDefault,
|
|
271
|
+
lastRunAt: agent.lastRunAt
|
|
272
|
+
}
|
|
273
|
+
: {})
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
console.log(pc.green('✓') + ' Initialized ' + pc.bold(target) + pc.dim(' (' + harness + ')'))
|
|
277
|
+
console.log(
|
|
278
|
+
' Skills installed to ' +
|
|
279
|
+
pc.dim(skillsDir) +
|
|
280
|
+
' — ask ' +
|
|
281
|
+
(harness === 'claude-code' ? 'Claude' : 'your agent') +
|
|
282
|
+
' to build a widget or a view to get started\n'
|
|
283
|
+
)
|
|
284
|
+
}
|
|
237
285
|
|
|
238
286
|
// If --web and server not running, start it (stay alive as wrapper)
|
|
239
287
|
let running = await isServerRunning()
|
|
@@ -91,7 +91,7 @@ const openclawInit = defineCommand({
|
|
|
91
91
|
skillsDir: skillsRoot,
|
|
92
92
|
installLogPath
|
|
93
93
|
} = await provisionWorkspace(target.path, 'openclaw')
|
|
94
|
-
if (scaffold !== 'exists') {
|
|
94
|
+
if (scaffold !== 'exists' && scaffold !== 'skipped') {
|
|
95
95
|
if (scaffold === 'installing') {
|
|
96
96
|
console.log('\n' + pc.dim(' Widget dependencies still installing in .moi/ (background)'))
|
|
97
97
|
console.log(pc.dim(' Install log: ' + installLogPath))
|
|
@@ -108,7 +108,7 @@ const openclawInit = defineCommand({
|
|
|
108
108
|
// Register in the moi registry so the agent's workspace appears in the
|
|
109
109
|
// UI workspace list. Mirrors what `moi init` does for Claude Code.
|
|
110
110
|
const entry = await registerWorkspace(target.path, {
|
|
111
|
-
|
|
111
|
+
harness: 'openclaw',
|
|
112
112
|
name: target.name,
|
|
113
113
|
agentId: target.agentId,
|
|
114
114
|
isDefault: target.isDefault,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { currentRemoteWorkspace } from '../../remote/workspace'
|
|
1
2
|
import { defineCommand } from 'citty'
|
|
2
3
|
import { CONTROL_URL } from '../../constants'
|
|
3
4
|
import { staleSkillNotice } from '../../skills/version'
|
|
@@ -17,9 +18,17 @@ export const refresh = defineCommand({
|
|
|
17
18
|
async run({ args }) {
|
|
18
19
|
const only = readAppletSelector(args.only)
|
|
19
20
|
const notice = await staleSkillNotice(process.cwd())
|
|
21
|
+
const linked = await currentRemoteWorkspace()
|
|
20
22
|
const ws = new WebSocket(CONTROL_URL)
|
|
21
23
|
|
|
22
|
-
ws.onopen = () =>
|
|
24
|
+
ws.onopen = () =>
|
|
25
|
+
ws.send(
|
|
26
|
+
JSON.stringify({
|
|
27
|
+
type: 'applets:refresh',
|
|
28
|
+
only,
|
|
29
|
+
path: linked?.path ?? process.env.MOI_REMOTE_WORKSPACE
|
|
30
|
+
})
|
|
31
|
+
)
|
|
23
32
|
|
|
24
33
|
ws.onmessage = event => {
|
|
25
34
|
const data = JSON.parse(String(event.data))
|