moi-computer 0.12.1-next.2 → 0.12.1-next.4
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/bunfig.toml +1 -5
- package/client/api/app-config.ts +1 -2
- package/client/api/app-ui-keys.ts +3 -1
- package/client/api/http.ts +4 -1
- package/client/api/workspace-keys.ts +3 -3
- package/client/app/app-provider.tsx +22 -2
- package/client/app/app-router.tsx +6 -0
- package/client/app/routes/home-route.tsx +14 -0
- package/client/app/routes/onboarding-route.tsx +11 -0
- package/client/app/routes/settings-route.tsx +10 -0
- package/client/app/routes/workspace-route.tsx +21 -19
- package/client/app/shell/sidebar-layout.tsx +34 -53
- package/client/components/shared/screen-shell.tsx +23 -0
- package/client/components/shared/ultrafast-icon.tsx +61 -0
- package/client/components/shared/workspace-icon.tsx +2 -2
- package/client/features/account/account-menu.tsx +96 -0
- package/client/features/account/account-provider.tsx +142 -0
- package/client/features/account/account-test-utils.tsx +294 -0
- package/client/features/account/api.ts +142 -0
- package/client/features/account/identity.ts +23 -0
- package/client/features/app-settings/api.ts +33 -0
- package/client/features/app-settings/general-settings.tsx +39 -0
- package/client/features/app-settings/profile-settings.tsx +95 -0
- package/client/features/app-settings/settings-page.tsx +48 -0
- package/client/features/app-settings/settings-section.tsx +26 -0
- package/client/features/app-settings/users-settings.tsx +195 -0
- package/client/features/chat/applet-chat-intents.ts +4 -20
- package/client/features/chat/chat-send.ts +17 -13
- package/client/features/chat/composer/model-order.ts +8 -4
- package/client/features/chat/composer/model-picker.tsx +88 -34
- package/client/features/chat/composer/use-workspace-composer-state.tsx +11 -3
- package/client/features/chat/composer/use-workspace-skill-updates.ts +1 -1
- package/client/features/chat/connection/chat-frames.ts +3 -15
- package/client/features/chat/messages/chat-empty-state.tsx +1 -4
- package/client/features/chat/messages/fork-history.ts +5 -5
- package/client/features/chat/messages/turn-view.tsx +3 -12
- package/client/features/chat/messages/user-message-bubble.tsx +63 -0
- package/client/features/chat/sessions/api.ts +121 -80
- package/client/features/chat/sessions/browser-tab-state.ts +14 -12
- package/client/features/chat/sessions/chat-selector.tsx +5 -6
- package/client/features/chat/sessions/use-selected-session.ts +172 -257
- package/client/features/chat/use-chat.ts +14 -19
- package/client/features/collab/applet-api.ts +15 -14
- package/client/features/collab/components/cursors.tsx +61 -24
- package/client/features/collab/components/presence-avatars.tsx +25 -12
- package/client/features/collab/components/presence-frame.tsx +20 -24
- package/client/features/collab/components/presence-group.tsx +15 -7
- package/client/features/collab/components/user-avatar-group.tsx +21 -8
- package/client/features/collab/components/user-avatar.tsx +38 -7
- package/client/features/collab/components/user.tsx +31 -12
- package/client/features/collab/users.ts +0 -5
- package/client/features/collab/workspace-users-menu.tsx +4 -4
- package/client/features/demo/demo-dialog.tsx +11 -3
- package/client/features/dev/collab/collab-playground.tsx +7 -7
- package/client/features/dev/collab/local-user-settings.tsx +7 -53
- package/client/features/dev/dev-index-page.tsx +5 -0
- package/client/features/dev/dev-routes.tsx +2 -0
- package/client/features/dev/harness-debug-page.tsx +3 -3
- package/client/features/dev/onboarding-preview-page.tsx +76 -0
- package/client/features/dev/workspace-setup-mocks.ts +16 -14
- package/client/features/dev/workspace-setup-preview.tsx +11 -17
- package/client/features/harness/api.ts +45 -15
- package/client/features/harness/device-login-steps.tsx +9 -3
- package/client/features/harness/harness-login-panel.tsx +228 -0
- package/client/features/harness/harness-presentation.ts +15 -0
- package/client/features/harness/harness-selector.tsx +119 -0
- package/client/features/harness/use-harness-login.ts +77 -0
- package/client/features/home/home-page.tsx +7 -7
- package/client/features/onboarding/agent-setup-step.tsx +57 -0
- package/client/features/onboarding/api.ts +42 -0
- package/client/features/onboarding/onboarding-idea-disk.tsx +129 -0
- package/client/features/onboarding/onboarding-page.tsx +32 -0
- package/client/features/onboarding/onboarding-screen.tsx +20 -0
- package/client/features/onboarding/onboarding-status.tsx +24 -0
- package/client/features/onboarding/workspace-setup-step.tsx +239 -0
- package/client/features/overview/default/registry.tsx +2 -2
- package/client/features/overview/default/views-widget.tsx +6 -5
- package/client/features/overview/overview.tsx +9 -11
- package/client/features/overview/widget-canvas.tsx +1 -1
- package/client/features/overview/workspace-name.tsx +2 -2
- package/client/features/update/update-control.tsx +1 -1
- package/client/features/views/api.ts +69 -16
- package/client/features/views/pending-view-screen.tsx +30 -9
- package/client/features/views/use-view-actions.ts +19 -20
- package/client/features/views/view-presentation.ts +2 -2
- package/client/features/views/view-submission.ts +28 -41
- package/client/features/workspace/add/api.ts +3 -23
- package/client/features/workspace/add/create-workspace-dialog.tsx +11 -7
- package/client/features/workspace/add/import-workspace-dialog.tsx +3 -3
- package/client/features/workspace/add/workspace-agent-options.ts +11 -12
- package/client/features/workspace/add/workspace-agent-selector.tsx +3 -132
- package/client/features/workspace/api.ts +32 -36
- package/client/features/workspace/harness-transition.ts +88 -0
- package/client/features/{settings → workspace/settings}/api.ts +1 -34
- package/client/features/{settings → workspace/settings}/connectors-settings.tsx +3 -3
- package/client/features/{settings → workspace/settings}/environment-settings.tsx +3 -3
- package/client/features/{settings → workspace/settings}/general-settings.tsx +77 -3
- package/client/features/{settings → workspace/settings}/use-env-vars.ts +1 -1
- package/client/features/{settings → workspace/settings}/workspace-icon-picker.tsx +3 -3
- package/client/features/workspace/setup/workspace-login-state.tsx +37 -156
- package/client/features/workspace/setup/workspace-recovery-states.tsx +0 -12
- package/client/features/workspace/setup/workspace-setup.tsx +34 -14
- package/client/features/workspace/setup/workspace-welcome-state.tsx +2 -2
- package/client/features/workspace/use-workspace-navigation.ts +25 -9
- package/client/features/workspace/workspace-content.tsx +11 -8
- package/client/features/workspace/workspace-frame.tsx +2 -1
- package/client/features/workspace/workspace-layout-context.tsx +5 -2
- package/client/features/workspace/workspace-menu.tsx +12 -8
- package/client/features/workspace/workspace-pending-screen.tsx +10 -10
- package/client/features/workspace/workspace-presentation.tsx +5 -13
- package/client/features/workspace/workspace-state.ts +169 -0
- package/client/features/workspace/workspace-tabs.tsx +22 -2
- package/client/index.css +2 -0
- package/client/index.tsx +3 -3
- package/client/lib/flags.ts +1 -1
- package/client/lib/{app-icon-registry.ts → identity-icon-registry.ts} +10 -14
- package/client/lib/user-display-name.ts +6 -0
- package/client/main.tsx +4 -1
- package/client/runtime/workspace-events.ts +21 -4
- package/client/runtime/workspace-theme.ts +9 -0
- package/client/tailwind-config.ts +43 -0
- package/dist/chunk-0mjzg20x.js +2 -0
- package/dist/chunk-2y59vrxg.js +5 -0
- package/dist/chunk-58dyt9bk.js +2 -0
- package/dist/chunk-5aj040e5.css +1 -0
- package/dist/{chunk-tqd3pkg8.css → chunk-60q353jq.css} +1 -1
- package/dist/chunk-71fn6rmj.js +546 -0
- package/dist/chunk-7yg1m8hx.js +2 -0
- package/dist/chunk-825hys3h.js +1 -0
- package/dist/chunk-9bb8m9rx.js +2 -0
- package/dist/{chunk-11cab5dq.css → chunk-cq2r11fg.css} +1 -1
- package/dist/chunk-g0tcwqxc.js +1 -0
- package/dist/chunk-n0nab26d.js +1 -0
- package/dist/chunk-nf2wkvf9.js +14 -0
- package/dist/chunk-v88n1bay.js +74 -0
- package/dist/index.html +1 -1
- package/lib/harness-instructions.ts +1 -1
- package/lib/{app-icons.ts → identity-icons.ts} +6 -7
- package/lib/onboarding.ts +41 -0
- package/lib/speed-mode.ts +5 -0
- package/lib/types.ts +72 -63
- package/lib/view-build-directives.ts +1 -2
- package/lib/workspace-icon.ts +2 -2
- package/lib/workspace-layout.ts +1 -1
- package/lib/workspace-name.ts +15 -12
- package/package.json +9 -8
- package/server/README.md +27 -25
- package/server/api/harnesses.ts +31 -8
- package/server/api/index.ts +164 -131
- package/server/api/onboarding.ts +46 -0
- package/server/app-config.ts +23 -24
- package/server/app-settings.ts +6 -2
- package/server/applets/config.ts +5 -5
- package/server/applets/views.ts +19 -17
- package/server/cli/commands/init.ts +3 -3
- package/server/cli/commands/skill.ts +16 -17
- package/server/cli/commands/start.ts +8 -34
- package/server/cli/server.ts +18 -6
- package/server/collab/config.ts +1 -2
- package/server/collab/manager.ts +4 -1
- package/server/collab/skill/index.ts +1 -1
- package/server/control.ts +3 -3
- package/server/data-dir.ts +1 -1
- package/server/harness/README.md +24 -8
- package/server/harness/acp/session.ts +8 -4
- package/server/harness/auth.ts +14 -17
- package/server/harness/claude-code/NOTES.md +4 -3
- package/server/harness/claude-code/index.ts +2 -0
- package/server/harness/claude-code/models.ts +2 -20
- package/server/harness/claude-code/run-action.ts +123 -0
- package/server/harness/claude-code/session-title.ts +5 -7
- package/server/harness/claude-code/session.ts +24 -16
- package/server/harness/codex/NOTES.md +14 -9
- package/server/harness/codex/adapter.ts +14 -17
- package/server/harness/codex/index.ts +2 -0
- package/server/harness/codex/run-action.ts +93 -0
- package/server/harness/codex/session-title.ts +6 -8
- package/server/harness/codex/session.ts +11 -11
- package/server/harness/command.ts +45 -0
- package/server/harness/executable.ts +5 -0
- package/server/harness/fork.ts +6 -4
- package/server/harness/install.ts +49 -0
- package/server/harness/openclaw/session.ts +1 -2
- package/server/harness/run-action.ts +85 -0
- package/server/harness/session-title.ts +0 -46
- package/server/harness/types.ts +26 -2
- package/server/onboarding/brief.ts +29 -0
- package/server/onboarding/ideas.ts +48 -0
- package/server/onboarding/jobs.ts +291 -0
- package/server/onboarding/prompt.md +49 -0
- package/server/sessions/archive.ts +5 -14
- package/server/sessions/config.ts +17 -16
- package/server/sessions/lifecycle.ts +15 -13
- package/server/sessions/pending-views.ts +79 -108
- package/server/sessions/selected.ts +75 -161
- package/server/sessions/store.ts +40 -113
- package/server/sessions/view-sessions.ts +128 -111
- package/server/skills/locations.ts +82 -0
- package/server/skills/lock.ts +29 -0
- package/server/skills/template.ts +36 -25
- package/server/skills/update.ts +52 -5
- package/server/skills/version.ts +17 -22
- package/server/skills/workspace.ts +121 -0
- package/server/web.ts +23 -8
- package/server/workspace-state/file.ts +177 -0
- package/server/workspace-state/index.ts +162 -0
- package/server/workspace-state/legacy-migration.ts +79 -0
- package/server/workspace-state/lock.ts +42 -0
- package/server/workspace-state/types.ts +16 -0
- package/server/workspaces/change-harness.ts +88 -0
- package/server/workspaces/harness-transition.ts +29 -0
- package/server/workspaces/init.ts +29 -16
- package/server/workspaces/layout.ts +3 -0
- package/server/workspaces/registry.ts +58 -10
- package/{workspace/.claude/skills/moi-workspace → skill}/SKILL.md +7 -5
- package/{workspace/.claude/skills/moi-workspace → skill}/references/COLLAB.md +4 -8
- package/skill/references/DESIGN.md +148 -0
- package/{workspace/.claude/skills/moi-workspace → skill}/references/SCRATCHPAD.md +2 -2
- package/{workspace/.claude/skills/moi-workspace → skill}/references/UI-COMPONENTS.md +3 -0
- package/ui-components/badge.tsx +1 -1
- package/client/accept-hmr-dependencies.ts +0 -22
- package/client/features/workspace/setup/workspace-setup-panel.tsx +0 -18
- package/dist/chunk-00rh9df4.js +0 -2
- package/dist/chunk-4nh7y1hq.css +0 -1
- package/dist/chunk-am4agx6v.js +0 -2
- package/dist/chunk-d7cbm65e.js +0 -2
- package/dist/chunk-hbpdv7vd.js +0 -1
- package/dist/chunk-hmka9rt5.js +0 -2
- package/dist/chunk-hvh9f5h0.js +0 -14
- package/dist/chunk-mjjregkn.js +0 -10
- package/dist/chunk-pcnahct1.js +0 -5
- package/dist/chunk-rt30jbcm.js +0 -1
- package/dist/chunk-vt6zybej.js +0 -2
- package/dist/chunk-wbkwf6cc.js +0 -68
- package/dist/chunk-xjyfyz64.js +0 -1
- package/dist/chunk-y8nbwp21.js +0 -546
- package/dist/chunk-ysfdcew7.js +0 -1
- package/lib/experimental.ts +0 -14
- package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +0 -157
- /package/client/features/{settings → workspace/settings}/icon-picker-options.ts +0 -0
- /package/client/features/{settings → workspace/settings}/settings-layout.tsx +0 -0
- /package/client/features/{settings → workspace/settings}/workspace-settings-dialog.tsx +0 -0
- /package/{workspace/.claude/skills/moi-workspace → skill}/references/INTENTS.md +0 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { join } from 'node:path'
|
|
2
|
+
import { tmpdir } from 'node:os'
|
|
3
|
+
import { chmod, mkdtemp, rm } from 'node:fs/promises'
|
|
4
|
+
|
|
5
|
+
import { agentCommand } from '../agent-launcher'
|
|
6
|
+
|
|
7
|
+
export async function runHarnessCommand(input: {
|
|
8
|
+
command: readonly string[]
|
|
9
|
+
cwd: string
|
|
10
|
+
stdin?: string
|
|
11
|
+
signal: AbortSignal
|
|
12
|
+
env?: Record<string, string | undefined>
|
|
13
|
+
}): Promise<string | null> {
|
|
14
|
+
if (input.signal.aborted) return null
|
|
15
|
+
try {
|
|
16
|
+
const proc = Bun.spawn(agentCommand(input.command), {
|
|
17
|
+
cwd: input.cwd,
|
|
18
|
+
stdin: new Blob([input.stdin ?? '']),
|
|
19
|
+
stdout: 'pipe',
|
|
20
|
+
stderr: 'ignore',
|
|
21
|
+
signal: input.signal,
|
|
22
|
+
env: input.env,
|
|
23
|
+
maxBuffer: 128 * 1024
|
|
24
|
+
})
|
|
25
|
+
const [exitCode, stdout] = await Promise.all([proc.exited, new Response(proc.stdout).text()])
|
|
26
|
+
return exitCode === 0 && !input.signal.aborted ? stdout : null
|
|
27
|
+
} catch {
|
|
28
|
+
return null
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// On managed machines the command runs as the agent's user, which is
|
|
33
|
+
// neither the folder's owner nor in its group, so the folder is open to
|
|
34
|
+
// everyone: the agent works in it and Codex writes its answer there. It holds
|
|
35
|
+
// only temporary inputs and output for one run. Moi stays the owner, which is
|
|
36
|
+
// what lets it remove the folder from /tmp afterwards.
|
|
37
|
+
export async function createHarnessTempDir(): Promise<string> {
|
|
38
|
+
const path = await mkdtemp(join(tmpdir(), 'moi-harness-'))
|
|
39
|
+
await chmod(path, 0o777)
|
|
40
|
+
return path
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function removeHarnessTempDir(path: string): Promise<void> {
|
|
44
|
+
await rm(path, { recursive: true, force: true })
|
|
45
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { accessSync, constants, statSync } from 'node:fs'
|
|
2
|
+
import { homedir } from 'node:os'
|
|
2
3
|
import { delimiter, join, resolve } from 'node:path'
|
|
3
4
|
|
|
4
5
|
import { harnessInstructionMessage } from '@/lib/harness-instructions'
|
|
@@ -19,6 +20,9 @@ type ExecutableConfig = {
|
|
|
19
20
|
const executableConfig: Record<WorkspaceType, ExecutableConfig> = {
|
|
20
21
|
'claude-code': {
|
|
21
22
|
command: 'claude',
|
|
23
|
+
fallbackPaths: [
|
|
24
|
+
join(homedir(), '.local', 'bin', process.platform === 'win32' ? 'claude.exe' : 'claude')
|
|
25
|
+
],
|
|
22
26
|
unavailableReason: harnessInstructionMessage('claude-code')
|
|
23
27
|
},
|
|
24
28
|
codex: {
|
|
@@ -27,6 +31,7 @@ const executableConfig: Record<WorkspaceType, ExecutableConfig> = {
|
|
|
27
31
|
// on PATH: probe the known macOS bundle locations (ChatGPT.app is the
|
|
28
32
|
// current home, Codex.app the legacy standalone install).
|
|
29
33
|
fallbackPaths: [
|
|
34
|
+
join(homedir(), '.local', 'bin', process.platform === 'win32' ? 'codex.exe' : 'codex'),
|
|
30
35
|
'/Applications/ChatGPT.app/Contents/Resources/codex',
|
|
31
36
|
'/Applications/Codex.app/Contents/Resources/codex'
|
|
32
37
|
],
|
package/server/harness/fork.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import type { StreamEvent } from '@/lib/types'
|
|
1
|
+
import type { SessionFork, StreamEvent } from '@/lib/types'
|
|
2
2
|
import { applyEvents } from '@/lib/format'
|
|
3
3
|
|
|
4
4
|
export class ForkUnsupportedError extends Error {}
|
|
5
5
|
|
|
6
|
-
export function inheritedHistoryBoundary(
|
|
6
|
+
export function inheritedHistoryBoundary(
|
|
7
|
+
events: StreamEvent[]
|
|
8
|
+
): Pick<SessionFork, 'throughMessageId' | 'noticeIds'> {
|
|
7
9
|
const view = applyEvents(events)
|
|
8
10
|
return {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
throughMessageId: view.turns.at(-1)?.id,
|
|
12
|
+
noticeIds: view.notices.map(notice => notice.id)
|
|
11
13
|
}
|
|
12
14
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { HARNESS_INSTRUCTIONS } from '@/lib/harness-instructions'
|
|
2
|
+
import { getAppConfig } from '../app-config'
|
|
3
|
+
import type { WorkspaceType } from '@/lib/types'
|
|
4
|
+
import { detectInstalledHarnesses } from './executable'
|
|
5
|
+
|
|
6
|
+
const installations = new Map<WorkspaceType, Promise<void>>()
|
|
7
|
+
|
|
8
|
+
export function installHarness(type: WorkspaceType): Promise<void> {
|
|
9
|
+
const config = getAppConfig()
|
|
10
|
+
if (config.environment !== 'local' || config.demo || config.agentLauncher) {
|
|
11
|
+
throw new Error('Agents can only be installed in local Moi')
|
|
12
|
+
}
|
|
13
|
+
if (type !== 'claude-code' && type !== 'codex') {
|
|
14
|
+
throw new Error('This agent requires manual installation')
|
|
15
|
+
}
|
|
16
|
+
const pending = installations.get(type)
|
|
17
|
+
if (pending) return pending
|
|
18
|
+
const installation = (async () => {
|
|
19
|
+
if ((await detectInstalledHarnesses())[type]) return
|
|
20
|
+
const url =
|
|
21
|
+
type === 'claude-code' ? 'https://claude.ai/install' : 'https://chatgpt.com/codex/install'
|
|
22
|
+
const command =
|
|
23
|
+
process.platform === 'win32'
|
|
24
|
+
? [
|
|
25
|
+
'powershell.exe',
|
|
26
|
+
'-NoProfile',
|
|
27
|
+
'-NonInteractive',
|
|
28
|
+
'-ExecutionPolicy',
|
|
29
|
+
'Bypass',
|
|
30
|
+
'-Command',
|
|
31
|
+
`$ErrorActionPreference = 'Stop'; irm ${url}.ps1 | iex`
|
|
32
|
+
]
|
|
33
|
+
: ['bash', '-o', 'pipefail', '-c', HARNESS_INSTRUCTIONS[type].command]
|
|
34
|
+
const child = Bun.spawn(command, {
|
|
35
|
+
stdin: 'ignore',
|
|
36
|
+
stdout: 'inherit',
|
|
37
|
+
stderr: 'inherit',
|
|
38
|
+
timeout: 5 * 60_000
|
|
39
|
+
})
|
|
40
|
+
if ((await child.exited) !== 0) {
|
|
41
|
+
throw new Error('Installation failed or timed out. Try again.')
|
|
42
|
+
}
|
|
43
|
+
if (!(await detectInstalledHarnesses())[type]) {
|
|
44
|
+
throw new Error('The installer finished, but the agent could not be found. Restart Moi.')
|
|
45
|
+
}
|
|
46
|
+
})().finally(() => installations.delete(type))
|
|
47
|
+
installations.set(type, installation)
|
|
48
|
+
return installation
|
|
49
|
+
}
|
|
@@ -1338,8 +1338,7 @@ async function sendOpenClawMessageImpl(input: {
|
|
|
1338
1338
|
if (created?.sessionId && created.sessionId !== input.sessionId) {
|
|
1339
1339
|
realSessionId = created.sessionId
|
|
1340
1340
|
await renameSessionReferences(
|
|
1341
|
-
input.workspaceId,
|
|
1342
|
-
input.workspacePath,
|
|
1341
|
+
{ id: input.workspaceId, path: input.workspacePath },
|
|
1343
1342
|
input.sessionId,
|
|
1344
1343
|
realSessionId
|
|
1345
1344
|
)
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
2
|
+
import { WebStandardStreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js'
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
import { createHarnessTempDir, removeHarnessTempDir } from './command'
|
|
5
|
+
import type { ActionModel, HarnessActionInput } from './types'
|
|
6
|
+
|
|
7
|
+
export const actionProgressServerName = 'moi_action'
|
|
8
|
+
export const actionProgressToolName = 'report_progress'
|
|
9
|
+
|
|
10
|
+
export type ActionExecution = {
|
|
11
|
+
prompt: string
|
|
12
|
+
model: ActionModel
|
|
13
|
+
resultSchema: Record<string, unknown>
|
|
14
|
+
signal: AbortSignal
|
|
15
|
+
cwd: string
|
|
16
|
+
progressUrl?: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function serveProgress<T>(schema: z.ZodType<T>, report: (value: T) => void | Promise<void>) {
|
|
20
|
+
const path = `/${crypto.randomUUID()}`
|
|
21
|
+
const server = Bun.serve({
|
|
22
|
+
hostname: '127.0.0.1',
|
|
23
|
+
port: 0,
|
|
24
|
+
async fetch(request) {
|
|
25
|
+
if (new URL(request.url).pathname !== path || request.headers.has('origin'))
|
|
26
|
+
return new Response('Not found', { status: 404 })
|
|
27
|
+
const mcp = new McpServer({ name: actionProgressServerName, version: '1.0.0' })
|
|
28
|
+
mcp.registerTool(
|
|
29
|
+
actionProgressToolName,
|
|
30
|
+
{
|
|
31
|
+
description: 'Report current action progress using the supplied schema',
|
|
32
|
+
inputSchema: { progress: schema },
|
|
33
|
+
annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false }
|
|
34
|
+
},
|
|
35
|
+
async ({ progress }) => {
|
|
36
|
+
await report(progress)
|
|
37
|
+
return { content: [{ type: 'text', text: 'Progress reported' }] }
|
|
38
|
+
}
|
|
39
|
+
)
|
|
40
|
+
const transport = new WebStandardStreamableHTTPServerTransport({ enableJsonResponse: true })
|
|
41
|
+
await mcp.connect(transport)
|
|
42
|
+
try {
|
|
43
|
+
return await transport.handleRequest(request)
|
|
44
|
+
} finally {
|
|
45
|
+
await mcp.close()
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
return { url: `http://127.0.0.1:${server.port}${path}`, close: () => server.stop(true) }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function executeHarnessAction<TResult, TProgress>(
|
|
53
|
+
input: HarnessActionInput<TResult, TProgress>,
|
|
54
|
+
execute: (action: ActionExecution) => Promise<unknown>
|
|
55
|
+
): Promise<TResult> {
|
|
56
|
+
if (input.signal.aborted) throw new Error('Action cancelled')
|
|
57
|
+
const cwd = await createHarnessTempDir()
|
|
58
|
+
let progress: ReturnType<typeof serveProgress> | undefined
|
|
59
|
+
const stop = () => {
|
|
60
|
+
void progress?.close()
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
if (input.signal.aborted) throw new Error('Action cancelled')
|
|
64
|
+
if (input.progressSchema) progress = serveProgress(input.progressSchema, input.onProgress)
|
|
65
|
+
input.signal.addEventListener('abort', stop, { once: true })
|
|
66
|
+
const result = await execute({
|
|
67
|
+
model: input.model ?? 'normal',
|
|
68
|
+
prompt:
|
|
69
|
+
input.prompt +
|
|
70
|
+
(progress
|
|
71
|
+
? `\n\nUse ${actionProgressServerName}/${actionProgressToolName} to report brief progress when your activity changes. Report only work you are actually doing. Return the final result through the result schema.`
|
|
72
|
+
: ''),
|
|
73
|
+
resultSchema: z.toJSONSchema(input.resultSchema, { target: 'draft-7' }),
|
|
74
|
+
signal: input.signal,
|
|
75
|
+
cwd,
|
|
76
|
+
progressUrl: progress?.url
|
|
77
|
+
})
|
|
78
|
+
if (input.signal.aborted) throw new Error('Action cancelled')
|
|
79
|
+
return input.resultSchema.parse(result)
|
|
80
|
+
} finally {
|
|
81
|
+
input.signal.removeEventListener('abort', stop)
|
|
82
|
+
await progress?.close()
|
|
83
|
+
await removeHarnessTempDir(cwd).catch(() => {})
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import { join } from 'node:path'
|
|
2
|
-
import { tmpdir } from 'node:os'
|
|
3
|
-
import { chmod, mkdtemp, rm } from 'node:fs/promises'
|
|
4
|
-
|
|
5
|
-
import { agentCommand } from '../agent-launcher'
|
|
6
|
-
|
|
7
1
|
const MAX_TITLE_SOURCE_LENGTH = 1_000
|
|
8
2
|
const MAX_GENERATED_TITLE_LENGTH = 64
|
|
9
3
|
|
|
@@ -63,43 +57,3 @@ export function parseGeneratedSessionTitleJson(value: string): string | null {
|
|
|
63
57
|
return null
|
|
64
58
|
}
|
|
65
59
|
}
|
|
66
|
-
|
|
67
|
-
export async function runSessionTitleCommand(input: {
|
|
68
|
-
command: readonly string[]
|
|
69
|
-
cwd: string
|
|
70
|
-
stdin?: string
|
|
71
|
-
signal: AbortSignal
|
|
72
|
-
env?: Record<string, string | undefined>
|
|
73
|
-
}): Promise<string | null> {
|
|
74
|
-
if (input.signal.aborted) return null
|
|
75
|
-
try {
|
|
76
|
-
const proc = Bun.spawn(agentCommand(input.command), {
|
|
77
|
-
cwd: input.cwd,
|
|
78
|
-
stdin: new Blob([input.stdin ?? '']),
|
|
79
|
-
stdout: 'pipe',
|
|
80
|
-
stderr: 'ignore',
|
|
81
|
-
signal: input.signal,
|
|
82
|
-
env: input.env,
|
|
83
|
-
maxBuffer: 128 * 1024
|
|
84
|
-
})
|
|
85
|
-
const [exitCode, stdout] = await Promise.all([proc.exited, new Response(proc.stdout).text()])
|
|
86
|
-
return exitCode === 0 && !input.signal.aborted ? stdout : null
|
|
87
|
-
} catch {
|
|
88
|
-
return null
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// On managed machines the title command runs as the agent's user, which is
|
|
93
|
-
// neither the folder's owner nor in its group, so the folder is open to
|
|
94
|
-
// everyone: the agent works in it and Codex writes its answer there. It holds
|
|
95
|
-
// only the schema and the title, for one run. moi stays the owner, which is
|
|
96
|
-
// what lets it remove the folder from /tmp afterwards.
|
|
97
|
-
export async function createSessionTitleTempDir(): Promise<string> {
|
|
98
|
-
const path = await mkdtemp(join(tmpdir(), 'moi-session-title-'))
|
|
99
|
-
await chmod(path, 0o777)
|
|
100
|
-
return path
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export async function removeSessionTitleTempDir(path: string): Promise<void> {
|
|
104
|
-
await rm(path, { recursive: true, force: true })
|
|
105
|
-
}
|
package/server/harness/types.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import type { SpeedMode } from '@/lib/types'
|
|
1
2
|
// The harness contract: what an agent backend must implement to be drivable
|
|
2
3
|
// by moi. See README.md in this folder for the full checklist and the
|
|
3
4
|
// message-type layers; each harness's index.ts exports one Harness object
|
|
4
5
|
// wrapping its session/adapter/transport modules.
|
|
5
6
|
import type { MessageAttachment } from '@/lib/types'
|
|
7
|
+
import type { ZodType } from 'zod'
|
|
6
8
|
import type { MoiContext } from '@/lib/moi-context'
|
|
7
9
|
import type {
|
|
8
10
|
HarnessAvailability,
|
|
@@ -20,7 +22,7 @@ import type {
|
|
|
20
22
|
// The superset of what any backend needs to accept a user message; harnesses
|
|
21
23
|
// ignore fields they don't support. OpenClaw honors model + effort (applied via
|
|
22
24
|
// sessions.patch) and stream (token previews), but has no Fast-mode setting so
|
|
23
|
-
// it ignores
|
|
25
|
+
// it ignores speedMode; agentId is OpenClaw-only (the gateway agent that owns
|
|
24
26
|
// the workspace).
|
|
25
27
|
export type HarnessLoginAttempt = HarnessLogin & {
|
|
26
28
|
completed?: Promise<void>
|
|
@@ -39,7 +41,7 @@ export type SendMessageInput = {
|
|
|
39
41
|
optimisticId?: string
|
|
40
42
|
model?: string
|
|
41
43
|
effort?: string
|
|
42
|
-
|
|
44
|
+
speedMode?: SpeedMode
|
|
43
45
|
stream?: boolean
|
|
44
46
|
// Structured moi context (lib/moi-context.ts). Each harness renders and
|
|
45
47
|
// injects it its own way: Claude Code as a leading system-reminder text
|
|
@@ -81,10 +83,32 @@ export type DiscoveredWorkspaceCandidate = {
|
|
|
81
83
|
|
|
82
84
|
export type HarnessWorkspace = Pick<WorkspaceEntry, 'id' | 'path' | 'type' | 'agentId'>
|
|
83
85
|
|
|
86
|
+
export type ActionModel = 'fast' | 'normal' | 'smart'
|
|
87
|
+
|
|
88
|
+
export type HarnessActionInput<TResult = unknown, TProgress = never> = {
|
|
89
|
+
prompt: string
|
|
90
|
+
// Portable model and effort choice, resolved by each harness. Defaults to normal.
|
|
91
|
+
model?: ActionModel
|
|
92
|
+
resultSchema: ZodType<TResult>
|
|
93
|
+
signal: AbortSignal
|
|
94
|
+
} & (
|
|
95
|
+
| { progressSchema?: never; onProgress?: never }
|
|
96
|
+
| {
|
|
97
|
+
progressSchema: ZodType<TProgress>
|
|
98
|
+
onProgress: (progress: TProgress) => void | Promise<void>
|
|
99
|
+
}
|
|
100
|
+
)
|
|
101
|
+
|
|
84
102
|
export type Harness = {
|
|
85
103
|
id: WorkspaceType
|
|
86
104
|
capabilities: HarnessCapabilities
|
|
87
105
|
|
|
106
|
+
// Ephemeral read/search action without a workspace or visible chat.
|
|
107
|
+
// Validates structured output against resultSchema; callers control timeout.
|
|
108
|
+
runAction?<TResult, TProgress = never>(
|
|
109
|
+
input: HarnessActionInput<TResult, TProgress>
|
|
110
|
+
): Promise<TResult>
|
|
111
|
+
|
|
88
112
|
// -- chat lifecycle ---------------------------------------------------------
|
|
89
113
|
sendMessage(input: SendMessageInput): Promise<void>
|
|
90
114
|
interrupt(workspaceId: string, sessionId: string): Promise<void>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { OnboardingAppletPlan, OnboardingIdea, OnboardingViewPlan } from '@/lib/onboarding'
|
|
2
|
+
|
|
3
|
+
function appletBrief(
|
|
4
|
+
title: string,
|
|
5
|
+
applets: (OnboardingAppletPlan | OnboardingViewPlan)[]
|
|
6
|
+
): string {
|
|
7
|
+
if (!applets.length) return `## ${title}\nNone planned.`
|
|
8
|
+
return `## ${title}\n${applets
|
|
9
|
+
.map(applet =>
|
|
10
|
+
[
|
|
11
|
+
`### ${applet.name}`,
|
|
12
|
+
...('icon' in applet ? [`Use view icon: ${applet.icon}`] : []),
|
|
13
|
+
applet.description,
|
|
14
|
+
...applet.features.map(feature => `- ${feature}`)
|
|
15
|
+
].join('\n')
|
|
16
|
+
)
|
|
17
|
+
.join('\n\n')}`
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function composeBuildBrief(idea: OnboardingIdea): string {
|
|
21
|
+
return [
|
|
22
|
+
`Build the Moi workspace “${idea.name}”. Start implementing this plan now.`,
|
|
23
|
+
`## Workspace\n${idea.description}\nIcon: ${idea.icon} (theme background, already configured).`,
|
|
24
|
+
`## Theme\nFont: ${idea.theme.font}\nColor: ${idea.theme.color}\nThese workspace presets are already configured; use the existing theme tokens.`,
|
|
25
|
+
appletBrief('Views', idea.views),
|
|
26
|
+
appletBrief('Overview widgets', idea.widgets),
|
|
27
|
+
'Follow the workspace instructions and use the normal Moi tools to create the views and widgets. Keep this Overview chat as the main coordination chat and use each view’s own build chat. Link to the views here so the user can follow their progress. Preserve the configured workspace name and icon. Use available data sources honestly and explain any access limitations.'
|
|
28
|
+
].join('\n\n')
|
|
29
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import { IDENTITY_ICON_IDS } from '@/lib/identity-icons'
|
|
3
|
+
import { COLOR_THEMES, FONT_THEMES, type ColorTheme, type FontTheme } from '@/lib/themes'
|
|
4
|
+
import type { OnboardingIdea } from '@/lib/onboarding'
|
|
5
|
+
|
|
6
|
+
const appletPlan = z
|
|
7
|
+
.object({
|
|
8
|
+
name: z.string().trim().min(1).max(100),
|
|
9
|
+
description: z.string().trim().min(1).max(500),
|
|
10
|
+
features: z.array(z.string().trim().min(1).max(500)).min(1).max(6)
|
|
11
|
+
})
|
|
12
|
+
.strict()
|
|
13
|
+
|
|
14
|
+
const idea = z
|
|
15
|
+
.object({
|
|
16
|
+
name: z.string().trim().min(1).max(24),
|
|
17
|
+
icon: z.enum(IDENTITY_ICON_IDS),
|
|
18
|
+
theme: z
|
|
19
|
+
.object({
|
|
20
|
+
font: z.enum(Object.keys(FONT_THEMES) as FontTheme[]),
|
|
21
|
+
color: z.enum(Object.keys(COLOR_THEMES) as ColorTheme[])
|
|
22
|
+
})
|
|
23
|
+
.strict(),
|
|
24
|
+
description: z.string().trim().min(1).max(200),
|
|
25
|
+
views: z
|
|
26
|
+
.array(
|
|
27
|
+
appletPlan.extend({
|
|
28
|
+
icon: z.enum(IDENTITY_ICON_IDS)
|
|
29
|
+
})
|
|
30
|
+
)
|
|
31
|
+
.length(3),
|
|
32
|
+
widgets: z.array(appletPlan).max(4)
|
|
33
|
+
})
|
|
34
|
+
.strict()
|
|
35
|
+
|
|
36
|
+
export const onboardingIdeaSchema = idea.extend({ id: z.string().uuid() })
|
|
37
|
+
export const ideasSchema = z.object({ options: z.array(idea).length(3) }).strict()
|
|
38
|
+
export function parseIdeas(value: unknown): OnboardingIdea[] {
|
|
39
|
+
const result = ideasSchema.parse(value)
|
|
40
|
+
if (new Set(result.options.map(option => option.name.toLowerCase())).size !== 3)
|
|
41
|
+
throw new Error('The agent returned duplicate ideas. Try again')
|
|
42
|
+
if (
|
|
43
|
+
new Set(result.options.map(option => option.theme.font)).size !== 3 ||
|
|
44
|
+
new Set(result.options.map(option => option.theme.color)).size !== 3
|
|
45
|
+
)
|
|
46
|
+
throw new Error('Each idea needs a different font and color. Try again')
|
|
47
|
+
return result.options.map(option => ({ ...option, id: crypto.randomUUID() }))
|
|
48
|
+
}
|