moi-computer 0.11.1-next.5 → 0.12.1-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/client/AGENTS.md +2 -2
- package/client/api/app-ui-keys.ts +1 -1
- package/client/api/workspace-keys.ts +1 -3
- package/client/app/routes/WorkspaceRoute.tsx +2 -8
- package/client/features/applets/applet-runtime.ts +11 -13
- package/client/features/chat/ChatPanel.tsx +70 -49
- package/client/features/chat/ChatPopup.tsx +81 -8
- package/client/features/chat/applet-chat-intents.ts +31 -12
- package/client/features/chat/chat-send.ts +33 -1
- package/client/features/chat/chat-store.ts +10 -0
- package/client/features/chat/composer/ChatComposer.tsx +24 -27
- package/client/features/chat/composer/ModelPicker.tsx +3 -3
- package/client/features/chat/composer/attachments/draft-attachments.ts +21 -4
- package/client/features/chat/composer/useWorkspaceComposerState.tsx +3 -3
- package/client/features/chat/connection/chat-frames.ts +14 -7
- package/client/features/chat/messages/ChatEmptyState.tsx +33 -19
- package/client/features/chat/messages/MarkdownContent.tsx +3 -3
- package/client/features/chat/messages/fork-history.ts +14 -0
- package/client/features/chat/sessions/ChatSelector.tsx +138 -79
- package/client/features/chat/sessions/api.ts +109 -19
- package/client/features/chat/sessions/browser-tab-state.ts +30 -7
- package/client/features/chat/sessions/useSelectedSession.ts +217 -51
- package/client/features/chat/useChat.ts +43 -45
- package/client/features/collab/client.ts +10 -11
- package/client/features/collab/hooks.tsx +6 -11
- package/client/features/collab/host-state.ts +57 -128
- package/client/features/collab/provider.tsx +3 -3
- package/client/features/collab/testing/fake-engine.ts +6 -27
- package/client/features/collab/workspace-users-menu.tsx +3 -7
- package/client/features/drawings/{useViewBuilderSketch.ts → useViewSketch.ts} +7 -7
- package/client/features/home/HomePage.tsx +2 -2
- package/client/features/overview/Overview.tsx +3 -6
- package/client/features/overview/default/ViewsWidget.tsx +5 -12
- package/client/features/overview/default/registry.tsx +2 -4
- package/client/features/views/PendingViewScreen.tsx +279 -0
- package/client/features/views/ViewManager.tsx +10 -10
- package/client/features/views/api.ts +63 -130
- package/client/features/views/useViewActions.ts +151 -0
- package/client/features/views/useViewDrafts.ts +79 -0
- package/client/features/views/view-presentation.ts +4 -5
- package/client/features/views/view-submission.ts +88 -0
- package/client/features/workspace/WorkspaceMenu.tsx +63 -0
- package/client/features/workspace/WorkspaceScreen.tsx +180 -375
- package/client/features/workspace/browser-tab-state.ts +16 -9
- package/client/features/workspace/moi-context.ts +13 -15
- package/client/features/workspace/tab-resolution.ts +16 -29
- package/client/features/workspace/useWorkspaceNavigation.ts +146 -104
- package/client/index.tsx +5 -1
- package/client/runtime/useWorkspaceEvents.ts +7 -6
- package/client/store/ui.ts +25 -29
- package/dist/chunk-1zhnhy00.js +1 -0
- package/dist/chunk-27501vke.js +1 -0
- package/dist/{chunk-jf6czgrz.js → chunk-9xtv6djt.js} +2 -2
- package/dist/chunk-am1x230f.js +2 -0
- package/dist/{chunk-nez8sdta.js → chunk-darpsw65.js} +1 -1
- package/dist/{chunk-97eg9mjn.js → chunk-gps4qc38.js} +1 -1
- package/dist/{chunk-3a48fyf7.js → chunk-hzwr8dp8.js} +4 -4
- package/dist/{chunk-efdyz6xp.js → chunk-j905va8r.js} +1 -1
- package/dist/chunk-n33w9y38.js +10 -0
- package/dist/chunk-r63ks44z.js +68 -0
- package/dist/{chunk-vfpsc75k.js → chunk-vqpkqtdr.js} +1 -1
- package/dist/chunk-wd46nk26.css +1 -0
- package/dist/chunk-xgt7vxt9.js +1 -0
- package/dist/{chunk-z3byfve5.js → chunk-yvzhwtfa.js} +2 -2
- package/dist/index.html +1 -1
- package/lib/ids.ts +2 -5
- package/lib/moi-context.ts +100 -73
- package/lib/navigation.ts +48 -87
- package/lib/session-drafts.ts +10 -0
- package/lib/types.ts +64 -31
- package/lib/view-build-directives.ts +12 -0
- package/lib/workspace-layout.ts +1 -1
- package/lib/workspace-tabs.ts +12 -7
- package/package.json +3 -1
- package/server/agent-launcher.ts +27 -0
- package/server/api.ts +119 -209
- package/server/app-config.ts +21 -2
- package/server/applets/build-worker.ts +2 -1
- package/server/applets/view-source.ts +7 -1
- package/server/cli-env.ts +72 -50
- package/server/cli.ts +127 -70
- package/server/control.ts +82 -63
- package/server/data-dir.ts +13 -0
- package/server/functions.ts +2 -1
- package/server/harness/README.md +8 -0
- package/server/harness/acp/adapter.ts +2 -2
- package/server/harness/acp/client.ts +2 -1
- package/server/harness/acp/discovery.ts +3 -3
- package/server/harness/acp/session.ts +6 -9
- package/server/harness/claude-code/adapter.ts +13 -8
- package/server/harness/claude-code/auth.ts +3 -2
- package/server/harness/claude-code/cli.ts +3 -1
- package/server/harness/claude-code/git-worktree.ts +5 -2
- package/server/harness/claude-code/index.ts +5 -0
- package/server/harness/claude-code/mcp.ts +2 -0
- package/server/harness/claude-code/models.ts +2 -0
- package/server/harness/claude-code/session.ts +5 -34
- package/server/harness/claude-code/sessions.ts +8 -12
- package/server/harness/codex/NOTES.md +23 -4
- package/server/harness/codex/adapter.ts +5 -3
- package/server/harness/codex/client.ts +13 -21
- package/server/harness/codex/index.ts +18 -0
- package/server/harness/codex/session.ts +6 -14
- package/server/harness/codex/thread-list.ts +74 -0
- package/server/harness/fork.ts +12 -0
- package/server/harness/openclaw/adapter.ts +3 -3
- package/server/harness/openclaw/session.ts +2 -30
- package/server/harness/session-title.ts +12 -3
- package/server/harness/types.ts +8 -3
- package/server/moi-scaffold.ts +53 -20
- package/server/pending-views.ts +164 -0
- package/server/registry.ts +14 -4
- package/server/selected-session.ts +91 -44
- package/server/service.ts +16 -2
- package/server/session-archive.ts +32 -0
- package/server/session-config.ts +16 -111
- package/server/session-lifecycle.ts +17 -0
- package/server/session-store.ts +127 -0
- package/server/status.ts +3 -1
- package/server/tabs.ts +7 -10
- package/server/view-sessions.ts +267 -0
- package/server/views.ts +30 -41
- package/server/web.ts +47 -45
- package/server/workspace-env.ts +27 -0
- package/server/workspace-init.ts +12 -5
- package/workspace/.claude/skills/moi-workspace/SKILL.md +49 -20
- package/workspace/.claude/skills/moi-workspace/references/COLLAB.md +2 -5
- package/client/features/views/ViewBuilder.tsx +0 -239
- package/client/features/views/useViewBuilderActions.ts +0 -103
- package/client/features/views/useViewBuilderDrafts.ts +0 -68
- package/dist/chunk-2jncyq65.js +0 -1
- package/dist/chunk-9zpvdws4.js +0 -68
- package/dist/chunk-h2kj1ysj.js +0 -1
- package/dist/chunk-hvj7tp3y.js +0 -1
- package/dist/chunk-nzwgm8vc.css +0 -1
- package/dist/chunk-ryg9z3kn.js +0 -10
- package/dist/chunk-tpn177bt.js +0 -2
- package/lib/view-builder-directives.ts +0 -16
- package/server/chat-selection.ts +0 -22
- package/server/view-builders.ts +0 -453
|
@@ -31,7 +31,11 @@ function isCleanupSource(moiRoot: string, path: string): boolean {
|
|
|
31
31
|
.some(part => part.startsWith('.') || ['data', 'ui', 'node_modules'].includes(part))
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
export async function deleteViewSourceFiles(
|
|
34
|
+
export async function deleteViewSourceFiles(
|
|
35
|
+
workspacePath: string,
|
|
36
|
+
viewId: string,
|
|
37
|
+
beforeDelete?: () => Promise<void>
|
|
38
|
+
): Promise<void> {
|
|
35
39
|
const workspaceRoot = await realpath(workspacePath)
|
|
36
40
|
const moiRoot = join(workspaceRoot, '.moi')
|
|
37
41
|
const directory = join(moiRoot, 'views')
|
|
@@ -63,5 +67,7 @@ export async function deleteViewSourceFiles(workspacePath: string, viewId: strin
|
|
|
63
67
|
}
|
|
64
68
|
}
|
|
65
69
|
|
|
70
|
+
// Validate shared imports before archiving chats, and archive before removing files.
|
|
71
|
+
await beforeDelete?.()
|
|
66
72
|
await Promise.all([...remove].map(path => rm(path, { force: true })))
|
|
67
73
|
}
|
package/server/cli-env.ts
CHANGED
|
@@ -1,17 +1,61 @@
|
|
|
1
1
|
// CLI face over the workspace env model (workspace-env.ts): rendering for
|
|
2
|
-
// `moi env`, secret-value input for `moi env set`, the exec spawn
|
|
3
|
-
//
|
|
2
|
+
// `moi env`, secret-value input for `moi env set`, and the exec spawn. Every
|
|
3
|
+
// read and write goes to the running server over the control port.
|
|
4
4
|
//
|
|
5
|
-
// Secret VALUES never pass through here except on their way
|
|
6
|
-
//
|
|
5
|
+
// Secret VALUES never pass through here except on their way to the server
|
|
6
|
+
// (`set` reads stdin/argv) or into a spawned process (`execWithEnv`). Nothing
|
|
7
7
|
// in this module prints a value.
|
|
8
8
|
import type { WorkspaceEntry, WorkspaceEnvView } from '@/lib/types'
|
|
9
9
|
|
|
10
10
|
import pc from './cli-pc'
|
|
11
11
|
import { columns } from './cli-ui'
|
|
12
12
|
import { CONTROL_URL } from './constants'
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
13
|
+
import { controlFailureMessage, probeControlServer } from './control-client'
|
|
14
|
+
import { findWorkspaceForPath } from './registry'
|
|
15
|
+
import { type EnvUpdate, discoverDotenvKeys } from './workspace-env'
|
|
16
|
+
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// The server
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
// The server owns the registry and the env stores: it applies a write at once
|
|
22
|
+
// and queues writes per workspace, so the CLI never touches the files itself.
|
|
23
|
+
// That is also the only way in for the agent on a managed machine, whose OS
|
|
24
|
+
// user can't open moi's data folder (docs/config.md).
|
|
25
|
+
|
|
26
|
+
function serverFail(message: string): never {
|
|
27
|
+
console.error('\n' + pc.red('✗') + ' ' + message + '\n')
|
|
28
|
+
process.exit(1)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// One control-port request and its reply. Exits with the server's error, or
|
|
32
|
+
// with why it couldn't be reached, like the other workspace commands.
|
|
33
|
+
function askServer(payload: Record<string, unknown>): Promise<Record<string, unknown>> {
|
|
34
|
+
const unreachable = () =>
|
|
35
|
+
void probeControlServer().then(p => serverFail(controlFailureMessage(p)))
|
|
36
|
+
return new Promise(resolve => {
|
|
37
|
+
let ws: WebSocket
|
|
38
|
+
try {
|
|
39
|
+
ws = new WebSocket(CONTROL_URL)
|
|
40
|
+
} catch {
|
|
41
|
+
unreachable()
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
ws.onopen = () => ws.send(JSON.stringify(payload))
|
|
45
|
+
ws.onmessage = event => {
|
|
46
|
+
ws.close()
|
|
47
|
+
let res: Record<string, unknown>
|
|
48
|
+
try {
|
|
49
|
+
res = JSON.parse(String(event.data))
|
|
50
|
+
} catch {
|
|
51
|
+
serverFail('Unexpected reply from moi')
|
|
52
|
+
}
|
|
53
|
+
if (typeof res.error === 'string') serverFail(res.error)
|
|
54
|
+
resolve(res)
|
|
55
|
+
}
|
|
56
|
+
ws.onerror = unreachable
|
|
57
|
+
})
|
|
58
|
+
}
|
|
15
59
|
|
|
16
60
|
// ---------------------------------------------------------------------------
|
|
17
61
|
// Workspace resolution: cwd → nearest registered workspace
|
|
@@ -22,7 +66,8 @@ import { discoverDotenvKeys, resolveWorkspaceEnv } from './workspace-env'
|
|
|
22
66
|
// any subdirectory). Exits with a hint when cwd is outside every workspace, so
|
|
23
67
|
// a typo never creates an orphan env entry keyed to a phantom path.
|
|
24
68
|
export async function resolveCwdWorkspace(): Promise<WorkspaceEntry> {
|
|
25
|
-
const
|
|
69
|
+
const { workspaces } = await askServer({ type: 'workspace:list' })
|
|
70
|
+
const match = findWorkspaceForPath(workspaces as WorkspaceEntry[], process.cwd())
|
|
26
71
|
if (!match) {
|
|
27
72
|
console.error(
|
|
28
73
|
'\n' +
|
|
@@ -35,6 +80,23 @@ export async function resolveCwdWorkspace(): Promise<WorkspaceEntry> {
|
|
|
35
80
|
return match
|
|
36
81
|
}
|
|
37
82
|
|
|
83
|
+
// ---------------------------------------------------------------------------
|
|
84
|
+
// Reading and writing the env
|
|
85
|
+
// ---------------------------------------------------------------------------
|
|
86
|
+
|
|
87
|
+
// The workspace env as `moi env` shows it (key names, never values), with the
|
|
88
|
+
// keys its widgets and views require.
|
|
89
|
+
export async function readEnvView(path: string): Promise<WorkspaceEnvView> {
|
|
90
|
+
return (await askServer({ type: 'env:view', path })).view as WorkspaceEnvView
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Apply an env patch; the server makes it take effect at once. Returns where
|
|
94
|
+
// the secrets are stored, for the plaintext-fallback notice.
|
|
95
|
+
export async function writeEnv(path: string, patch: EnvUpdate): Promise<'keychain' | 'file'> {
|
|
96
|
+
const res = await askServer({ type: 'env:update', path, patch })
|
|
97
|
+
return res.backend === 'file' ? 'file' : 'keychain'
|
|
98
|
+
}
|
|
99
|
+
|
|
38
100
|
// ---------------------------------------------------------------------------
|
|
39
101
|
// `moi env` rendering
|
|
40
102
|
// ---------------------------------------------------------------------------
|
|
@@ -158,48 +220,6 @@ export async function readSecretValue(key: string): Promise<string> {
|
|
|
158
220
|
return (await Bun.stdin.text()).replace(/\r?\n$/, '')
|
|
159
221
|
}
|
|
160
222
|
|
|
161
|
-
// ---------------------------------------------------------------------------
|
|
162
|
-
// Server notification after a CLI write
|
|
163
|
-
// ---------------------------------------------------------------------------
|
|
164
|
-
|
|
165
|
-
// Env is frozen at spawn — a running server must reap the widget worker and
|
|
166
|
-
// idle agent sessions for a CLI write to take effect (mirrors PUT /env). Sends
|
|
167
|
-
// `env:changed` over the control port; resolves false when no server is
|
|
168
|
-
// running (fine: the next server start resolves fresh env anyway).
|
|
169
|
-
export function notifyEnvChanged(path: string): Promise<boolean> {
|
|
170
|
-
return new Promise(resolve => {
|
|
171
|
-
let ws: WebSocket
|
|
172
|
-
try {
|
|
173
|
-
ws = new WebSocket(CONTROL_URL)
|
|
174
|
-
} catch {
|
|
175
|
-
resolve(false)
|
|
176
|
-
return
|
|
177
|
-
}
|
|
178
|
-
const timer = setTimeout(() => {
|
|
179
|
-
try {
|
|
180
|
-
ws.close()
|
|
181
|
-
} catch {}
|
|
182
|
-
resolve(false)
|
|
183
|
-
}, 1500)
|
|
184
|
-
ws.onopen = () => ws.send(JSON.stringify({ type: 'env:changed', path }))
|
|
185
|
-
ws.onmessage = event => {
|
|
186
|
-
clearTimeout(timer)
|
|
187
|
-
ws.close()
|
|
188
|
-
// A malformed reply must still settle the promise — the CLI awaits this.
|
|
189
|
-
try {
|
|
190
|
-
const res: unknown = JSON.parse(String(event.data))
|
|
191
|
-
resolve(typeof res === 'object' && res !== null && (res as { ok?: unknown }).ok === true)
|
|
192
|
-
} catch {
|
|
193
|
-
resolve(false)
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
ws.onerror = () => {
|
|
197
|
-
clearTimeout(timer)
|
|
198
|
-
resolve(false)
|
|
199
|
-
}
|
|
200
|
-
})
|
|
201
|
-
}
|
|
202
|
-
|
|
203
223
|
// ---------------------------------------------------------------------------
|
|
204
224
|
// `moi env exec`
|
|
205
225
|
// ---------------------------------------------------------------------------
|
|
@@ -210,7 +230,9 @@ export function notifyEnvChanged(path: string): Promise<boolean> {
|
|
|
210
230
|
// missing.
|
|
211
231
|
export async function execWithEnv(workspacePath: string, cmd: string[]): Promise<number> {
|
|
212
232
|
const [resolved, dotenvKeys] = await Promise.all([
|
|
213
|
-
|
|
233
|
+
askServer({ type: 'env:resolve', path: workspacePath }).then(
|
|
234
|
+
res => res.env as Record<string, string>
|
|
235
|
+
),
|
|
214
236
|
discoverDotenvKeys(workspacePath)
|
|
215
237
|
])
|
|
216
238
|
// Bun auto-loads the workspace `.env` into THIS process when the CLI runs
|
package/server/cli.ts
CHANGED
|
@@ -3,7 +3,7 @@ import './cli-colors' // must precede citty: sets NO_COLOR before its color flag
|
|
|
3
3
|
import { defineCommand, runMain, showUsage } from 'citty'
|
|
4
4
|
import { formatHex } from 'culori'
|
|
5
5
|
import { parse as devalueParse } from 'devalue'
|
|
6
|
-
import { existsSync } from 'node:fs'
|
|
6
|
+
import { accessSync, constants, existsSync } from 'node:fs'
|
|
7
7
|
import { tmpdir } from 'node:os'
|
|
8
8
|
import { dirname, join, resolve } from 'path'
|
|
9
9
|
import pc from './cli-pc'
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
deriveThemeColors
|
|
23
23
|
} from '@/lib/themes'
|
|
24
24
|
import type { AgentTheme, ColorTheme, FontTheme, RadiusTheme } from '@/lib/themes'
|
|
25
|
-
import {
|
|
25
|
+
import { resolveUrl } from '@/lib/navigation'
|
|
26
26
|
import { EXPERIMENTAL_FEATURES, experimentalFlagName } from '@/lib/experimental'
|
|
27
27
|
import type { ExperimentalFeatures } from '@/lib/experimental'
|
|
28
28
|
import type {
|
|
@@ -41,15 +41,17 @@ import type {
|
|
|
41
41
|
|
|
42
42
|
import {
|
|
43
43
|
execWithEnv,
|
|
44
|
-
|
|
44
|
+
readEnvView,
|
|
45
45
|
readSecretValue,
|
|
46
46
|
renderEnvView,
|
|
47
|
-
resolveCwdWorkspace
|
|
47
|
+
resolveCwdWorkspace,
|
|
48
|
+
writeEnv
|
|
48
49
|
} from './cli-env'
|
|
49
50
|
import { columns, keyValue } from './cli-ui'
|
|
50
51
|
import { installCollabSkill } from './collab/skill'
|
|
51
52
|
import { CONTROL_HOST, CONTROL_PORT, CONTROL_URL, PORT } from './constants'
|
|
52
53
|
import { type ControlProbe, controlFailureMessage, probeControlServer } from './control-client'
|
|
54
|
+
import { canUseDataDir } from './data-dir'
|
|
53
55
|
import {
|
|
54
56
|
HARNESS_TYPES,
|
|
55
57
|
type DetectedAgent,
|
|
@@ -88,7 +90,8 @@ import {
|
|
|
88
90
|
restartService,
|
|
89
91
|
serviceLogPath,
|
|
90
92
|
serviceStatus,
|
|
91
|
-
uninstallService
|
|
93
|
+
uninstallService,
|
|
94
|
+
webAddress
|
|
92
95
|
} from './service'
|
|
93
96
|
import {
|
|
94
97
|
detectPackageManager,
|
|
@@ -101,12 +104,7 @@ import {
|
|
|
101
104
|
updateArgv
|
|
102
105
|
} from './update'
|
|
103
106
|
import { VERSION, isPrerelease, versionWithCommit } from './version'
|
|
104
|
-
import {
|
|
105
|
-
getWorkspaceEnvView,
|
|
106
|
-
isValidEnvKey,
|
|
107
|
-
secretBackend,
|
|
108
|
-
updateWorkspaceEnv
|
|
109
|
-
} from './workspace-env'
|
|
107
|
+
import { isValidEnvKey } from './workspace-env'
|
|
110
108
|
import { provisionWorkspace } from './workspace-init'
|
|
111
109
|
|
|
112
110
|
// ---- helpers ----------------------------------------------------------------
|
|
@@ -133,6 +131,12 @@ async function waitForServer(timeoutMs = 10_000): Promise<boolean> {
|
|
|
133
131
|
}
|
|
134
132
|
|
|
135
133
|
async function registerViaControl(absPath: string): Promise<string> {
|
|
134
|
+
try {
|
|
135
|
+
accessSync(absPath, constants.R_OK | constants.W_OK | constants.X_OK)
|
|
136
|
+
} catch {
|
|
137
|
+
console.error('\n' + pc.red('✗') + ` Can't open ${absPath} for reading and writing\n`)
|
|
138
|
+
process.exit(1)
|
|
139
|
+
}
|
|
136
140
|
return new Promise((res, rej) => {
|
|
137
141
|
const ws = new WebSocket(CONTROL_URL)
|
|
138
142
|
ws.onopen = () => ws.send(JSON.stringify({ type: 'workspace:register', path: absPath }))
|
|
@@ -409,7 +413,7 @@ const init = defineCommand({
|
|
|
409
413
|
// Provision: bundled skills + the `.moi/` bootstrap (widgets dir +
|
|
410
414
|
// package.json + bun install). An existing `.moi/` is left untouched.
|
|
411
415
|
console.log()
|
|
412
|
-
const { scaffold, skillsDir } = await provisionWorkspace(target, type)
|
|
416
|
+
const { scaffold, skillsDir, installLogPath } = await provisionWorkspace(target, type)
|
|
413
417
|
if (args['experimental-collab']) {
|
|
414
418
|
const { referencePath } = await installCollabSkill(target, type)
|
|
415
419
|
console.log(pc.dim(' Collaboration guide installed to ' + referencePath))
|
|
@@ -418,10 +422,14 @@ const init = defineCommand({
|
|
|
418
422
|
if (scaffold !== 'exists') {
|
|
419
423
|
if (scaffold === 'installing') {
|
|
420
424
|
console.log(pc.dim(' Widget dependencies still installing in .moi/ (background)'))
|
|
425
|
+
console.log(pc.dim(' Install log: ' + installLogPath))
|
|
421
426
|
} else if (scaffold === 0) {
|
|
422
427
|
console.log(pc.dim(' Installed widget dependencies in .moi/'))
|
|
423
428
|
} else {
|
|
424
|
-
console.warn(
|
|
429
|
+
console.warn(
|
|
430
|
+
pc.yellow(` bun install failed (exit ${scaffold}) — run it manually in .moi/`)
|
|
431
|
+
)
|
|
432
|
+
console.warn(pc.dim(' Install log: ' + installLogPath))
|
|
425
433
|
}
|
|
426
434
|
}
|
|
427
435
|
|
|
@@ -534,13 +542,12 @@ const start = defineCommand({
|
|
|
534
542
|
// Say who owns the running server: a service-managed one is expected
|
|
535
543
|
// to be here, and `moi service` is how to manage it.
|
|
536
544
|
const info = await queryServerInfo()
|
|
537
|
-
const port = info?.port || PORT
|
|
538
545
|
if (info?.service) {
|
|
539
546
|
console.log(
|
|
540
547
|
'\n' +
|
|
541
548
|
pc.yellow('◆') +
|
|
542
|
-
' The moi service is already running on
|
|
543
|
-
|
|
549
|
+
' The moi service is already running on ' +
|
|
550
|
+
webAddress(info) +
|
|
544
551
|
pc.dim(` (v${info.version})`) +
|
|
545
552
|
'\n' +
|
|
546
553
|
pc.dim(' Manage it with `moi service` — restart, logs, uninstall.') +
|
|
@@ -548,7 +555,7 @@ const start = defineCommand({
|
|
|
548
555
|
)
|
|
549
556
|
} else {
|
|
550
557
|
console.log(
|
|
551
|
-
'\n' + pc.yellow('◆') + ' Server is already running on
|
|
558
|
+
'\n' + pc.yellow('◆') + ' Server is already running on ' + webAddress(info) + '\n'
|
|
552
559
|
)
|
|
553
560
|
}
|
|
554
561
|
process.exit(0)
|
|
@@ -607,7 +614,8 @@ const start = defineCommand({
|
|
|
607
614
|
}
|
|
608
615
|
process.exit(1)
|
|
609
616
|
}
|
|
610
|
-
|
|
617
|
+
const { unixSocket } = getAppConfig()
|
|
618
|
+
console.log(`\n${pc.green('✓')} Server started on ${unixSocket ?? `http://localhost:${PORT}`}`)
|
|
611
619
|
console.log(pc.dim(' Press Ctrl+C to stop\n'))
|
|
612
620
|
// Stay alive as the server
|
|
613
621
|
}
|
|
@@ -648,12 +656,7 @@ const bundle = defineCommand({
|
|
|
648
656
|
description: 'Rebuild the selected applets, ignoring file modification times',
|
|
649
657
|
default: false
|
|
650
658
|
},
|
|
651
|
-
only: appletOnlyArg
|
|
652
|
-
status: {
|
|
653
|
-
type: 'boolean',
|
|
654
|
-
description: 'Advance a view builder to ready on success (use --no-status to skip)',
|
|
655
|
-
default: true
|
|
656
|
-
}
|
|
659
|
+
only: appletOnlyArg
|
|
657
660
|
},
|
|
658
661
|
async run({ args }) {
|
|
659
662
|
const only = readAppletSelector(args.only)
|
|
@@ -669,8 +672,7 @@ const bundle = defineCommand({
|
|
|
669
672
|
type: 'bundle',
|
|
670
673
|
path,
|
|
671
674
|
force: args.force,
|
|
672
|
-
only
|
|
673
|
-
noStatus: !args.status
|
|
675
|
+
only
|
|
674
676
|
})
|
|
675
677
|
)
|
|
676
678
|
|
|
@@ -793,23 +795,17 @@ const check = defineCommand({
|
|
|
793
795
|
}
|
|
794
796
|
})
|
|
795
797
|
|
|
796
|
-
const
|
|
797
|
-
meta: { name: 'set', description: 'Set a view
|
|
798
|
+
const viewsSet = defineCommand({
|
|
799
|
+
meta: { name: 'set', description: 'Set a pending view’s title and icon' },
|
|
798
800
|
args: {
|
|
799
|
-
id: { type: 'positional', required: true, description: 'View
|
|
801
|
+
id: { type: 'positional', required: true, description: 'View id' },
|
|
800
802
|
dir: {
|
|
801
803
|
type: 'positional',
|
|
802
804
|
default: '.',
|
|
803
805
|
description: 'Workspace directory (default: current)'
|
|
804
806
|
},
|
|
805
|
-
kind: { type: 'string', default: 'view', description: '"view" or "widget"' },
|
|
806
|
-
status: { type: 'string', description: 'Report build state: "building" or "waiting"' },
|
|
807
807
|
title: { type: 'string', description: 'Display title' },
|
|
808
|
-
icon: { type: 'string', description: 'App icon registry id' }
|
|
809
|
-
builder: {
|
|
810
|
-
type: 'string',
|
|
811
|
-
description: 'Builder handle for a pending view builder (from its request)'
|
|
812
|
-
}
|
|
808
|
+
icon: { type: 'string', description: 'App icon registry id' }
|
|
813
809
|
},
|
|
814
810
|
run({ args }) {
|
|
815
811
|
const path = resolve(args.dir)
|
|
@@ -817,14 +813,11 @@ const builderSet = defineCommand({
|
|
|
817
813
|
ws.onopen = () =>
|
|
818
814
|
ws.send(
|
|
819
815
|
JSON.stringify({
|
|
820
|
-
type: '
|
|
816
|
+
type: 'view:set',
|
|
821
817
|
path,
|
|
822
818
|
id: args.id,
|
|
823
|
-
kind: args.kind,
|
|
824
|
-
status: args.status,
|
|
825
819
|
title: args.title,
|
|
826
|
-
icon: args.icon
|
|
827
|
-
builder: args.builder
|
|
820
|
+
icon: args.icon
|
|
828
821
|
})
|
|
829
822
|
)
|
|
830
823
|
ws.onmessage = event => {
|
|
@@ -835,11 +828,7 @@ const builderSet = defineCommand({
|
|
|
835
828
|
process.exit(1)
|
|
836
829
|
}
|
|
837
830
|
console.log(
|
|
838
|
-
'\n' +
|
|
839
|
-
pc.green('✓') +
|
|
840
|
-
' Builder set ' +
|
|
841
|
-
pc.bold(String(result.builder?.viewId ?? args.id)) +
|
|
842
|
-
'\n'
|
|
831
|
+
'\n' + pc.green('✓') + ' View updated ' + pc.bold(String(result.viewId ?? args.id)) + '\n'
|
|
843
832
|
)
|
|
844
833
|
ws.close()
|
|
845
834
|
process.exit(0)
|
|
@@ -848,9 +837,44 @@ const builderSet = defineCommand({
|
|
|
848
837
|
}
|
|
849
838
|
})
|
|
850
839
|
|
|
851
|
-
const
|
|
852
|
-
meta: {
|
|
853
|
-
|
|
840
|
+
const viewsCreate = defineCommand({
|
|
841
|
+
meta: {
|
|
842
|
+
name: 'create',
|
|
843
|
+
description: 'Create a view, optionally forking a source chat to build it'
|
|
844
|
+
},
|
|
845
|
+
args: {
|
|
846
|
+
dir: { type: 'positional', default: '.', description: 'Workspace directory' },
|
|
847
|
+
'from-session': {
|
|
848
|
+
type: 'string',
|
|
849
|
+
description: 'Session id to fork into a new view chat'
|
|
850
|
+
},
|
|
851
|
+
requirements: { type: 'string', required: true, description: 'Complete view requirements' }
|
|
852
|
+
},
|
|
853
|
+
run({ args }) {
|
|
854
|
+
const ws = new WebSocket(CONTROL_URL)
|
|
855
|
+
ws.onopen = () =>
|
|
856
|
+
ws.send(
|
|
857
|
+
JSON.stringify({
|
|
858
|
+
type: 'view:create',
|
|
859
|
+
path: resolve(args.dir),
|
|
860
|
+
fromSessionId: args['from-session'],
|
|
861
|
+
requirements: args.requirements
|
|
862
|
+
})
|
|
863
|
+
)
|
|
864
|
+
ws.onmessage = event => {
|
|
865
|
+
const result: Record<string, unknown> = JSON.parse(String(event.data))
|
|
866
|
+
console.log(JSON.stringify(result, null, 2))
|
|
867
|
+
if (result.warning) console.error(result.warning)
|
|
868
|
+
ws.close()
|
|
869
|
+
process.exit(result.error ? 1 : 0)
|
|
870
|
+
}
|
|
871
|
+
ws.onerror = () => void exitControlUnreachable()
|
|
872
|
+
}
|
|
873
|
+
})
|
|
874
|
+
|
|
875
|
+
const views = defineCommand({
|
|
876
|
+
meta: { name: 'views', description: 'Create views and set their build details' },
|
|
877
|
+
subCommands: { create: viewsCreate, set: viewsSet }
|
|
854
878
|
})
|
|
855
879
|
|
|
856
880
|
const refresh = defineCommand({
|
|
@@ -1103,7 +1127,10 @@ const status = defineCommand({
|
|
|
1103
1127
|
' Server is ' +
|
|
1104
1128
|
pc.bold('running') +
|
|
1105
1129
|
pc.dim(
|
|
1106
|
-
|
|
1130
|
+
(info?.unixSocket
|
|
1131
|
+
? ` (web socket: ${info.unixSocket}`
|
|
1132
|
+
: ` (http port: ${info?.port || PORT}`) +
|
|
1133
|
+
`, control port: ${CONTROL_PORT}` +
|
|
1107
1134
|
(info?.pid ? `, pid: ${info.pid}` : '') +
|
|
1108
1135
|
')'
|
|
1109
1136
|
)
|
|
@@ -1200,13 +1227,12 @@ const envSet = defineCommand({
|
|
|
1200
1227
|
}
|
|
1201
1228
|
}
|
|
1202
1229
|
|
|
1203
|
-
await
|
|
1204
|
-
await notifyEnvChanged(entry.path)
|
|
1230
|
+
const backend = await writeEnv(entry.path, { set })
|
|
1205
1231
|
for (const key of Object.keys(set)) {
|
|
1206
1232
|
console.log(pc.green('✓') + ` Set ${pc.bold(key)} ${pc.dim('(custom)')}`)
|
|
1207
1233
|
}
|
|
1208
1234
|
// A plaintext fallback should never go unnoticed at write time.
|
|
1209
|
-
if (
|
|
1235
|
+
if (backend === 'file') {
|
|
1210
1236
|
console.log(pc.dim(' Stored in a 0600 file — OS keychain unavailable.'))
|
|
1211
1237
|
}
|
|
1212
1238
|
process.exit(0)
|
|
@@ -1220,7 +1246,7 @@ const envUnset = defineCommand({
|
|
|
1220
1246
|
},
|
|
1221
1247
|
async run({ args }) {
|
|
1222
1248
|
const entry = await resolveCwdWorkspace()
|
|
1223
|
-
const view = await
|
|
1249
|
+
const view = await readEnvView(entry.path)
|
|
1224
1250
|
const byKey = new Map(view.vars.map(v => [v.key, v]))
|
|
1225
1251
|
|
|
1226
1252
|
// Only custom secrets are removable; a dotenv-sourced key lives in its file.
|
|
@@ -1245,8 +1271,7 @@ const envUnset = defineCommand({
|
|
|
1245
1271
|
}
|
|
1246
1272
|
|
|
1247
1273
|
if (removable.length > 0) {
|
|
1248
|
-
await
|
|
1249
|
-
await notifyEnvChanged(entry.path)
|
|
1274
|
+
await writeEnv(entry.path, { remove: removable })
|
|
1250
1275
|
for (const key of removable) {
|
|
1251
1276
|
const v = byKey.get(key)
|
|
1252
1277
|
const unshadow =
|
|
@@ -1291,10 +1316,7 @@ const env = defineCommand({
|
|
|
1291
1316
|
const first = rawArgs.find(a => !a.startsWith('-'))
|
|
1292
1317
|
if (first && Object.hasOwn(envSubCommands, first)) return
|
|
1293
1318
|
const entry = await resolveCwdWorkspace()
|
|
1294
|
-
|
|
1295
|
-
// which must not load for every other `moi` command's startup.
|
|
1296
|
-
const { requiredEnvFor } = await import('./required-env')
|
|
1297
|
-
const view = await getWorkspaceEnvView(entry.path, requiredEnvFor(entry.path))
|
|
1319
|
+
const view = await readEnvView(entry.path)
|
|
1298
1320
|
console.log('\n' + renderEnvView(entry, view) + '\n')
|
|
1299
1321
|
process.exit(0)
|
|
1300
1322
|
}
|
|
@@ -1403,14 +1425,22 @@ const openclawInit = defineCommand({
|
|
|
1403
1425
|
// with the highest precedence, so these win over any same-named bundled or
|
|
1404
1426
|
// per-user skill), plus the `.moi/` bootstrap — the widgets skill assumes
|
|
1405
1427
|
// the folder and its dependencies exist. Existing `.moi/` stays untouched.
|
|
1406
|
-
const {
|
|
1428
|
+
const {
|
|
1429
|
+
scaffold,
|
|
1430
|
+
skillsDir: skillsRoot,
|
|
1431
|
+
installLogPath
|
|
1432
|
+
} = await provisionWorkspace(target.path, 'openclaw')
|
|
1407
1433
|
if (scaffold !== 'exists') {
|
|
1408
1434
|
if (scaffold === 'installing') {
|
|
1409
1435
|
console.log('\n' + pc.dim(' Widget dependencies still installing in .moi/ (background)'))
|
|
1436
|
+
console.log(pc.dim(' Install log: ' + installLogPath))
|
|
1410
1437
|
} else if (scaffold === 0) {
|
|
1411
1438
|
console.log('\n' + pc.dim(' Installed widget dependencies in .moi/'))
|
|
1412
1439
|
} else {
|
|
1413
|
-
console.warn(
|
|
1440
|
+
console.warn(
|
|
1441
|
+
'\n' + pc.yellow(` bun install failed (exit ${scaffold}) — run it manually in .moi/`)
|
|
1442
|
+
)
|
|
1443
|
+
console.warn(pc.dim(' Install log: ' + installLogPath))
|
|
1414
1444
|
}
|
|
1415
1445
|
}
|
|
1416
1446
|
|
|
@@ -1541,14 +1571,22 @@ const hermesInit = defineCommand({
|
|
|
1541
1571
|
// dir with the highest precedence, so these win over bundled ones), plus
|
|
1542
1572
|
// the `.moi/` bootstrap. The default profile has no workspace directory
|
|
1543
1573
|
// until now — provisionWorkspace creates it.
|
|
1544
|
-
const {
|
|
1574
|
+
const {
|
|
1575
|
+
scaffold,
|
|
1576
|
+
skillsDir: skillsRoot,
|
|
1577
|
+
installLogPath
|
|
1578
|
+
} = await provisionWorkspace(target.path, 'hermes')
|
|
1545
1579
|
if (scaffold !== 'exists') {
|
|
1546
1580
|
if (scaffold === 'installing') {
|
|
1547
1581
|
console.log('\n' + pc.dim(' Widget dependencies still installing in .moi/ (background)'))
|
|
1582
|
+
console.log(pc.dim(' Install log: ' + installLogPath))
|
|
1548
1583
|
} else if (scaffold === 0) {
|
|
1549
1584
|
console.log('\n' + pc.dim(' Installed widget dependencies in .moi/'))
|
|
1550
1585
|
} else {
|
|
1551
|
-
console.warn(
|
|
1586
|
+
console.warn(
|
|
1587
|
+
'\n' + pc.yellow(` bun install failed (exit ${scaffold}) — run it manually in .moi/`)
|
|
1588
|
+
)
|
|
1589
|
+
console.warn(pc.dim(' Install log: ' + installLogPath))
|
|
1552
1590
|
}
|
|
1553
1591
|
}
|
|
1554
1592
|
|
|
@@ -2415,7 +2453,7 @@ const debug = defineCommand({
|
|
|
2415
2453
|
function runTabsList(dir: string) {
|
|
2416
2454
|
const path = resolve(dir)
|
|
2417
2455
|
sendControl(path, { type: 'tabs', path }, res => {
|
|
2418
|
-
type Row = { title: string; isDefault: boolean; href
|
|
2456
|
+
type Row = { title: string; isDefault: boolean; href: string }
|
|
2419
2457
|
const rows: Row[] = Array.isArray(res.tabs) ? (res.tabs as Row[]) : []
|
|
2420
2458
|
console.log(
|
|
2421
2459
|
'\n' + pc.bold('moi tabs') + pc.dim(' — workspace tabs, the default one marked') + '\n'
|
|
@@ -2426,7 +2464,7 @@ function runTabsList(dir: string) {
|
|
|
2426
2464
|
rows.map(row => [
|
|
2427
2465
|
row.isDefault ? pc.green('●') : ' ',
|
|
2428
2466
|
row.isDefault ? pc.bold(row.title) : row.title,
|
|
2429
|
-
row.href
|
|
2467
|
+
row.href
|
|
2430
2468
|
])
|
|
2431
2469
|
)
|
|
2432
2470
|
)
|
|
@@ -2449,7 +2487,9 @@ const navigate = defineCommand({
|
|
|
2449
2487
|
},
|
|
2450
2488
|
run({ args }) {
|
|
2451
2489
|
try {
|
|
2452
|
-
|
|
2490
|
+
const href = resolveUrl(args.href)
|
|
2491
|
+
if (!href.startsWith('moi:/') || href.startsWith('moi:/files/'))
|
|
2492
|
+
throw new Error('Navigation needs a workspace page address')
|
|
2453
2493
|
} catch (error) {
|
|
2454
2494
|
console.error(error instanceof Error ? error.message : 'Invalid workspace address')
|
|
2455
2495
|
process.exit(1)
|
|
@@ -2602,7 +2642,7 @@ function printServiceServer(info: Awaited<ReturnType<typeof queryServerInfo>>) {
|
|
|
2602
2642
|
console.log(
|
|
2603
2643
|
' server ' +
|
|
2604
2644
|
pc.bold(`v${info.version}`) +
|
|
2605
|
-
` running on
|
|
2645
|
+
` running on ${webAddress(info)}` +
|
|
2606
2646
|
pc.dim(` (pid ${info.pid})`)
|
|
2607
2647
|
)
|
|
2608
2648
|
const mismatch = versionMismatchNotice(info.version)
|
|
@@ -2806,7 +2846,7 @@ async function runServiceStatus() {
|
|
|
2806
2846
|
console.log(
|
|
2807
2847
|
' server ' +
|
|
2808
2848
|
pc.bold(`v${info.version}`) +
|
|
2809
|
-
pc.dim(` on
|
|
2849
|
+
pc.dim(` on ${webAddress(info)} (pid ${info.pid})`)
|
|
2810
2850
|
)
|
|
2811
2851
|
if (!info.service) {
|
|
2812
2852
|
console.log(
|
|
@@ -3077,7 +3117,7 @@ const workspaceCommands = {
|
|
|
3077
3117
|
bundle,
|
|
3078
3118
|
check,
|
|
3079
3119
|
refresh,
|
|
3080
|
-
|
|
3120
|
+
views,
|
|
3081
3121
|
'call-server-fn': callServerFn,
|
|
3082
3122
|
debug,
|
|
3083
3123
|
theme,
|
|
@@ -3122,6 +3162,8 @@ function exitIfDemoBlocked(): void {
|
|
|
3122
3162
|
const invoked = process.argv[2]
|
|
3123
3163
|
if (!invoked || invoked === 'version' || invoked === 'start') return
|
|
3124
3164
|
if (!(invoked in systemCommands)) return
|
|
3165
|
+
// The agent on a managed machine can't read the config (see below).
|
|
3166
|
+
if (!canUseDataDir()) return
|
|
3125
3167
|
const config = getAppConfig()
|
|
3126
3168
|
if (!config.cloudDemo) return
|
|
3127
3169
|
console.log(
|
|
@@ -3135,6 +3177,21 @@ function exitIfDemoBlocked(): void {
|
|
|
3135
3177
|
process.exit(1)
|
|
3136
3178
|
}
|
|
3137
3179
|
|
|
3180
|
+
// Managed machines run the agent as its own OS user, which can't open moi's
|
|
3181
|
+
// data folder (docs/config.md). The system commands that set up or
|
|
3182
|
+
// run moi belong to the user that runs moi; `version` and `status` only read.
|
|
3183
|
+
function exitIfNotMoiUser(): void {
|
|
3184
|
+
const invoked = process.argv[2]
|
|
3185
|
+
if (!invoked || invoked === 'version' || invoked === 'status') return
|
|
3186
|
+
if (!(invoked in systemCommands)) return
|
|
3187
|
+
if (canUseDataDir()) return
|
|
3188
|
+
console.log(
|
|
3189
|
+
'\n' + pc.yellow('◆') + ` moi ${invoked} is only available to the user that runs moi.\n`
|
|
3190
|
+
)
|
|
3191
|
+
process.exit(1)
|
|
3192
|
+
}
|
|
3193
|
+
|
|
3194
|
+
exitIfNotMoiUser()
|
|
3138
3195
|
exitIfDemoBlocked()
|
|
3139
3196
|
|
|
3140
3197
|
type HelpCommand = { meta?: unknown }
|