moi-computer 0.12.0 → 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/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 +101 -64
- 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 +2 -1
- 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 +6 -2
- 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-e2q5ken7.js +0 -68
- package/dist/chunk-h2kj1ysj.js +0 -1
- package/dist/chunk-nzwgm8vc.css +0 -1
- package/dist/chunk-ph0h6h86.js +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 }))
|
|
@@ -538,13 +542,12 @@ const start = defineCommand({
|
|
|
538
542
|
// Say who owns the running server: a service-managed one is expected
|
|
539
543
|
// to be here, and `moi service` is how to manage it.
|
|
540
544
|
const info = await queryServerInfo()
|
|
541
|
-
const port = info?.port || PORT
|
|
542
545
|
if (info?.service) {
|
|
543
546
|
console.log(
|
|
544
547
|
'\n' +
|
|
545
548
|
pc.yellow('◆') +
|
|
546
|
-
' The moi service is already running on
|
|
547
|
-
|
|
549
|
+
' The moi service is already running on ' +
|
|
550
|
+
webAddress(info) +
|
|
548
551
|
pc.dim(` (v${info.version})`) +
|
|
549
552
|
'\n' +
|
|
550
553
|
pc.dim(' Manage it with `moi service` — restart, logs, uninstall.') +
|
|
@@ -552,7 +555,7 @@ const start = defineCommand({
|
|
|
552
555
|
)
|
|
553
556
|
} else {
|
|
554
557
|
console.log(
|
|
555
|
-
'\n' + pc.yellow('◆') + ' Server is already running on
|
|
558
|
+
'\n' + pc.yellow('◆') + ' Server is already running on ' + webAddress(info) + '\n'
|
|
556
559
|
)
|
|
557
560
|
}
|
|
558
561
|
process.exit(0)
|
|
@@ -611,7 +614,8 @@ const start = defineCommand({
|
|
|
611
614
|
}
|
|
612
615
|
process.exit(1)
|
|
613
616
|
}
|
|
614
|
-
|
|
617
|
+
const { unixSocket } = getAppConfig()
|
|
618
|
+
console.log(`\n${pc.green('✓')} Server started on ${unixSocket ?? `http://localhost:${PORT}`}`)
|
|
615
619
|
console.log(pc.dim(' Press Ctrl+C to stop\n'))
|
|
616
620
|
// Stay alive as the server
|
|
617
621
|
}
|
|
@@ -652,12 +656,7 @@ const bundle = defineCommand({
|
|
|
652
656
|
description: 'Rebuild the selected applets, ignoring file modification times',
|
|
653
657
|
default: false
|
|
654
658
|
},
|
|
655
|
-
only: appletOnlyArg
|
|
656
|
-
status: {
|
|
657
|
-
type: 'boolean',
|
|
658
|
-
description: 'Advance a view builder to ready on success (use --no-status to skip)',
|
|
659
|
-
default: true
|
|
660
|
-
}
|
|
659
|
+
only: appletOnlyArg
|
|
661
660
|
},
|
|
662
661
|
async run({ args }) {
|
|
663
662
|
const only = readAppletSelector(args.only)
|
|
@@ -673,8 +672,7 @@ const bundle = defineCommand({
|
|
|
673
672
|
type: 'bundle',
|
|
674
673
|
path,
|
|
675
674
|
force: args.force,
|
|
676
|
-
only
|
|
677
|
-
noStatus: !args.status
|
|
675
|
+
only
|
|
678
676
|
})
|
|
679
677
|
)
|
|
680
678
|
|
|
@@ -797,23 +795,17 @@ const check = defineCommand({
|
|
|
797
795
|
}
|
|
798
796
|
})
|
|
799
797
|
|
|
800
|
-
const
|
|
801
|
-
meta: { name: 'set', description: 'Set a view
|
|
798
|
+
const viewsSet = defineCommand({
|
|
799
|
+
meta: { name: 'set', description: 'Set a pending view’s title and icon' },
|
|
802
800
|
args: {
|
|
803
|
-
id: { type: 'positional', required: true, description: 'View
|
|
801
|
+
id: { type: 'positional', required: true, description: 'View id' },
|
|
804
802
|
dir: {
|
|
805
803
|
type: 'positional',
|
|
806
804
|
default: '.',
|
|
807
805
|
description: 'Workspace directory (default: current)'
|
|
808
806
|
},
|
|
809
|
-
kind: { type: 'string', default: 'view', description: '"view" or "widget"' },
|
|
810
|
-
status: { type: 'string', description: 'Report build state: "building" or "waiting"' },
|
|
811
807
|
title: { type: 'string', description: 'Display title' },
|
|
812
|
-
icon: { type: 'string', description: 'App icon registry id' }
|
|
813
|
-
builder: {
|
|
814
|
-
type: 'string',
|
|
815
|
-
description: 'Builder handle for a pending view builder (from its request)'
|
|
816
|
-
}
|
|
808
|
+
icon: { type: 'string', description: 'App icon registry id' }
|
|
817
809
|
},
|
|
818
810
|
run({ args }) {
|
|
819
811
|
const path = resolve(args.dir)
|
|
@@ -821,14 +813,11 @@ const builderSet = defineCommand({
|
|
|
821
813
|
ws.onopen = () =>
|
|
822
814
|
ws.send(
|
|
823
815
|
JSON.stringify({
|
|
824
|
-
type: '
|
|
816
|
+
type: 'view:set',
|
|
825
817
|
path,
|
|
826
818
|
id: args.id,
|
|
827
|
-
kind: args.kind,
|
|
828
|
-
status: args.status,
|
|
829
819
|
title: args.title,
|
|
830
|
-
icon: args.icon
|
|
831
|
-
builder: args.builder
|
|
820
|
+
icon: args.icon
|
|
832
821
|
})
|
|
833
822
|
)
|
|
834
823
|
ws.onmessage = event => {
|
|
@@ -839,11 +828,7 @@ const builderSet = defineCommand({
|
|
|
839
828
|
process.exit(1)
|
|
840
829
|
}
|
|
841
830
|
console.log(
|
|
842
|
-
'\n' +
|
|
843
|
-
pc.green('✓') +
|
|
844
|
-
' Builder set ' +
|
|
845
|
-
pc.bold(String(result.builder?.viewId ?? args.id)) +
|
|
846
|
-
'\n'
|
|
831
|
+
'\n' + pc.green('✓') + ' View updated ' + pc.bold(String(result.viewId ?? args.id)) + '\n'
|
|
847
832
|
)
|
|
848
833
|
ws.close()
|
|
849
834
|
process.exit(0)
|
|
@@ -852,9 +837,44 @@ const builderSet = defineCommand({
|
|
|
852
837
|
}
|
|
853
838
|
})
|
|
854
839
|
|
|
855
|
-
const
|
|
856
|
-
meta: {
|
|
857
|
-
|
|
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 }
|
|
858
878
|
})
|
|
859
879
|
|
|
860
880
|
const refresh = defineCommand({
|
|
@@ -1107,7 +1127,10 @@ const status = defineCommand({
|
|
|
1107
1127
|
' Server is ' +
|
|
1108
1128
|
pc.bold('running') +
|
|
1109
1129
|
pc.dim(
|
|
1110
|
-
|
|
1130
|
+
(info?.unixSocket
|
|
1131
|
+
? ` (web socket: ${info.unixSocket}`
|
|
1132
|
+
: ` (http port: ${info?.port || PORT}`) +
|
|
1133
|
+
`, control port: ${CONTROL_PORT}` +
|
|
1111
1134
|
(info?.pid ? `, pid: ${info.pid}` : '') +
|
|
1112
1135
|
')'
|
|
1113
1136
|
)
|
|
@@ -1204,13 +1227,12 @@ const envSet = defineCommand({
|
|
|
1204
1227
|
}
|
|
1205
1228
|
}
|
|
1206
1229
|
|
|
1207
|
-
await
|
|
1208
|
-
await notifyEnvChanged(entry.path)
|
|
1230
|
+
const backend = await writeEnv(entry.path, { set })
|
|
1209
1231
|
for (const key of Object.keys(set)) {
|
|
1210
1232
|
console.log(pc.green('✓') + ` Set ${pc.bold(key)} ${pc.dim('(custom)')}`)
|
|
1211
1233
|
}
|
|
1212
1234
|
// A plaintext fallback should never go unnoticed at write time.
|
|
1213
|
-
if (
|
|
1235
|
+
if (backend === 'file') {
|
|
1214
1236
|
console.log(pc.dim(' Stored in a 0600 file — OS keychain unavailable.'))
|
|
1215
1237
|
}
|
|
1216
1238
|
process.exit(0)
|
|
@@ -1224,7 +1246,7 @@ const envUnset = defineCommand({
|
|
|
1224
1246
|
},
|
|
1225
1247
|
async run({ args }) {
|
|
1226
1248
|
const entry = await resolveCwdWorkspace()
|
|
1227
|
-
const view = await
|
|
1249
|
+
const view = await readEnvView(entry.path)
|
|
1228
1250
|
const byKey = new Map(view.vars.map(v => [v.key, v]))
|
|
1229
1251
|
|
|
1230
1252
|
// Only custom secrets are removable; a dotenv-sourced key lives in its file.
|
|
@@ -1249,8 +1271,7 @@ const envUnset = defineCommand({
|
|
|
1249
1271
|
}
|
|
1250
1272
|
|
|
1251
1273
|
if (removable.length > 0) {
|
|
1252
|
-
await
|
|
1253
|
-
await notifyEnvChanged(entry.path)
|
|
1274
|
+
await writeEnv(entry.path, { remove: removable })
|
|
1254
1275
|
for (const key of removable) {
|
|
1255
1276
|
const v = byKey.get(key)
|
|
1256
1277
|
const unshadow =
|
|
@@ -1295,10 +1316,7 @@ const env = defineCommand({
|
|
|
1295
1316
|
const first = rawArgs.find(a => !a.startsWith('-'))
|
|
1296
1317
|
if (first && Object.hasOwn(envSubCommands, first)) return
|
|
1297
1318
|
const entry = await resolveCwdWorkspace()
|
|
1298
|
-
|
|
1299
|
-
// which must not load for every other `moi` command's startup.
|
|
1300
|
-
const { requiredEnvFor } = await import('./required-env')
|
|
1301
|
-
const view = await getWorkspaceEnvView(entry.path, requiredEnvFor(entry.path))
|
|
1319
|
+
const view = await readEnvView(entry.path)
|
|
1302
1320
|
console.log('\n' + renderEnvView(entry, view) + '\n')
|
|
1303
1321
|
process.exit(0)
|
|
1304
1322
|
}
|
|
@@ -2435,7 +2453,7 @@ const debug = defineCommand({
|
|
|
2435
2453
|
function runTabsList(dir: string) {
|
|
2436
2454
|
const path = resolve(dir)
|
|
2437
2455
|
sendControl(path, { type: 'tabs', path }, res => {
|
|
2438
|
-
type Row = { title: string; isDefault: boolean; href
|
|
2456
|
+
type Row = { title: string; isDefault: boolean; href: string }
|
|
2439
2457
|
const rows: Row[] = Array.isArray(res.tabs) ? (res.tabs as Row[]) : []
|
|
2440
2458
|
console.log(
|
|
2441
2459
|
'\n' + pc.bold('moi tabs') + pc.dim(' — workspace tabs, the default one marked') + '\n'
|
|
@@ -2446,7 +2464,7 @@ function runTabsList(dir: string) {
|
|
|
2446
2464
|
rows.map(row => [
|
|
2447
2465
|
row.isDefault ? pc.green('●') : ' ',
|
|
2448
2466
|
row.isDefault ? pc.bold(row.title) : row.title,
|
|
2449
|
-
row.href
|
|
2467
|
+
row.href
|
|
2450
2468
|
])
|
|
2451
2469
|
)
|
|
2452
2470
|
)
|
|
@@ -2469,7 +2487,9 @@ const navigate = defineCommand({
|
|
|
2469
2487
|
},
|
|
2470
2488
|
run({ args }) {
|
|
2471
2489
|
try {
|
|
2472
|
-
|
|
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')
|
|
2473
2493
|
} catch (error) {
|
|
2474
2494
|
console.error(error instanceof Error ? error.message : 'Invalid workspace address')
|
|
2475
2495
|
process.exit(1)
|
|
@@ -2622,7 +2642,7 @@ function printServiceServer(info: Awaited<ReturnType<typeof queryServerInfo>>) {
|
|
|
2622
2642
|
console.log(
|
|
2623
2643
|
' server ' +
|
|
2624
2644
|
pc.bold(`v${info.version}`) +
|
|
2625
|
-
` running on
|
|
2645
|
+
` running on ${webAddress(info)}` +
|
|
2626
2646
|
pc.dim(` (pid ${info.pid})`)
|
|
2627
2647
|
)
|
|
2628
2648
|
const mismatch = versionMismatchNotice(info.version)
|
|
@@ -2826,7 +2846,7 @@ async function runServiceStatus() {
|
|
|
2826
2846
|
console.log(
|
|
2827
2847
|
' server ' +
|
|
2828
2848
|
pc.bold(`v${info.version}`) +
|
|
2829
|
-
pc.dim(` on
|
|
2849
|
+
pc.dim(` on ${webAddress(info)} (pid ${info.pid})`)
|
|
2830
2850
|
)
|
|
2831
2851
|
if (!info.service) {
|
|
2832
2852
|
console.log(
|
|
@@ -3097,7 +3117,7 @@ const workspaceCommands = {
|
|
|
3097
3117
|
bundle,
|
|
3098
3118
|
check,
|
|
3099
3119
|
refresh,
|
|
3100
|
-
|
|
3120
|
+
views,
|
|
3101
3121
|
'call-server-fn': callServerFn,
|
|
3102
3122
|
debug,
|
|
3103
3123
|
theme,
|
|
@@ -3142,6 +3162,8 @@ function exitIfDemoBlocked(): void {
|
|
|
3142
3162
|
const invoked = process.argv[2]
|
|
3143
3163
|
if (!invoked || invoked === 'version' || invoked === 'start') return
|
|
3144
3164
|
if (!(invoked in systemCommands)) return
|
|
3165
|
+
// The agent on a managed machine can't read the config (see below).
|
|
3166
|
+
if (!canUseDataDir()) return
|
|
3145
3167
|
const config = getAppConfig()
|
|
3146
3168
|
if (!config.cloudDemo) return
|
|
3147
3169
|
console.log(
|
|
@@ -3155,6 +3177,21 @@ function exitIfDemoBlocked(): void {
|
|
|
3155
3177
|
process.exit(1)
|
|
3156
3178
|
}
|
|
3157
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()
|
|
3158
3195
|
exitIfDemoBlocked()
|
|
3159
3196
|
|
|
3160
3197
|
type HelpCommand = { meta?: unknown }
|