moi-computer 0.13.1-next.1 → 0.13.1-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/api/app-config.ts +12 -1
- package/client/api/http.ts +11 -1
- package/client/app/app-router.tsx +3 -2
- package/client/app/routes/home-route.tsx +1 -1
- package/client/app/routes/workspace-registration.tsx +68 -0
- package/client/app/routes/workspace-route.tsx +33 -6
- package/client/app/shell/sidebar-layout.tsx +10 -5
- package/client/components/shared/workspace-icon.tsx +8 -17
- package/client/features/account/account-test-utils.tsx +15 -9
- package/client/features/account/api.ts +6 -6
- package/client/features/account/profile-actions.ts +5 -7
- package/client/features/app-settings/settings-page.tsx +2 -1
- package/client/features/applets/api.ts +6 -6
- package/client/features/applets/applet-cache.ts +6 -5
- package/client/features/applets/applet-log.ts +2 -1
- package/client/features/applets/applet-runtime.ts +2 -1
- package/client/features/applets/use-applet.ts +73 -18
- package/client/features/applets/widget-shell.tsx +4 -2
- package/client/features/chat/applet-chat-intents.ts +5 -13
- package/client/features/chat/chat-popup.tsx +8 -4
- package/client/features/chat/chat-send.ts +2 -2
- package/client/features/chat/composer/model-order.ts +4 -4
- package/client/features/chat/composer/model-picker.tsx +12 -10
- package/client/features/chat/composer/use-workspace-composer-state.tsx +1 -1
- package/client/features/chat/sessions/api.ts +11 -28
- package/client/features/chat/sessions/use-selected-session.ts +14 -109
- package/client/features/chat/use-chat.ts +8 -12
- package/client/features/collab/members/api.ts +4 -10
- package/client/features/collab/members/hooks.ts +32 -38
- package/client/features/collab/members/store.ts +96 -71
- package/client/features/collab/members/types.ts +5 -3
- package/client/features/collab/presence/client.ts +2 -3
- package/client/features/collab/presence/hooks.tsx +1 -1
- package/client/features/collab/proxy-user.ts +1 -3
- package/client/features/collab/sharing/workspace-members.tsx +0 -8
- package/client/features/dev/chat-states-page.tsx +3 -1
- package/client/features/dev/harness-debug-page.tsx +7 -7
- package/client/features/dev/workspace-setup-mocks.ts +1 -1
- package/client/features/dev/workspace-setup-preview.tsx +6 -4
- package/client/features/harness/api.ts +13 -10
- package/client/features/harness/harness-login-panel.tsx +9 -5
- package/client/features/harness/harness-presentation.ts +4 -4
- package/client/features/harness/harness-selector.tsx +13 -13
- package/client/features/harness/use-harness-login.ts +5 -5
- package/client/features/home/api.ts +38 -2
- package/client/features/home/home-page.tsx +43 -13
- package/client/features/home/shared-workspaces.tsx +70 -0
- package/client/features/home/workspace-invitations.tsx +101 -0
- package/client/features/identity/host-api.ts +3 -2
- package/client/features/identity/store.ts +1 -7
- package/client/features/onboarding/agent-setup-step.tsx +8 -8
- package/client/features/onboarding/onboarding-page.tsx +3 -2
- package/client/features/onboarding/workspace-setup-step.tsx +1 -1
- package/client/features/overview/api.ts +3 -5
- package/client/features/overview/default/registry.tsx +1 -1
- package/client/features/overview/default/views-widget.tsx +2 -2
- package/client/features/overview/hidden-panel.tsx +7 -5
- package/client/features/overview/overview.tsx +18 -16
- package/client/features/overview/workspace-name.tsx +2 -2
- package/client/features/scratchpad/scratchpad.tsx +9 -7
- package/client/features/scratchpad/use-scratchpad-snapshot.tsx +13 -5
- package/client/features/views/api.ts +66 -23
- package/client/features/views/use-view-actions.ts +10 -41
- package/client/features/views/view-manager.tsx +1 -1
- package/client/features/views/view-submission.ts +2 -21
- package/client/features/workspace/add/api.ts +5 -4
- package/client/features/workspace/add/create-workspace-dialog.tsx +12 -9
- package/client/features/workspace/add/import-workspace-dialog.tsx +7 -7
- package/client/features/workspace/add/use-workspace-import.ts +10 -10
- package/client/features/workspace/add/workspace-agent-options.ts +21 -20
- package/client/features/workspace/add/workspace-agent-selector.tsx +11 -11
- package/client/features/workspace/api.ts +60 -13
- package/client/features/workspace/harness-transition.ts +7 -13
- package/client/features/workspace/remote.ts +25 -0
- package/client/features/workspace/settings/api.ts +7 -12
- package/client/features/workspace/settings/connectors-settings.tsx +3 -3
- package/client/features/workspace/settings/general-settings.tsx +8 -8
- package/client/features/workspace/setup/workspace-login-state.tsx +4 -4
- package/client/features/workspace/setup/workspace-recovery-states.tsx +43 -14
- package/client/features/workspace/setup/workspace-setup.tsx +6 -6
- package/client/features/workspace/tab-resolution.ts +1 -8
- package/client/features/workspace/use-workspace-navigation.ts +11 -7
- package/client/features/workspace/workspace-content.tsx +24 -31
- package/client/features/workspace/workspace-frame.tsx +13 -26
- package/client/features/workspace/workspace-layout-context.tsx +45 -12
- package/client/features/workspace/workspace-menu.tsx +2 -2
- package/client/features/workspace/workspace-pane.tsx +22 -0
- package/client/features/workspace/workspace-pending-screen.tsx +1 -1
- package/client/features/workspace/workspace-preferences.ts +91 -0
- package/client/features/workspace/workspace-presentation.tsx +12 -16
- package/client/features/workspace/workspace-screen.tsx +2 -2
- package/client/features/workspace/workspace-state.ts +42 -16
- package/client/features/workspace/workspace-tabs.tsx +1 -1
- package/client/features/workspace/workspace-test-utils.ts +23 -0
- package/client/runtime/use-workspace-events.ts +14 -0
- package/client/runtime/workspace-events.ts +9 -9
- package/client/store/ui.ts +24 -9
- package/client/store/workspace-session.ts +30 -0
- package/dist/chunk-0h4zypgf.js +1 -0
- package/dist/chunk-1tksq43z.js +72 -0
- package/dist/chunk-6gxf0xr8.js +5 -0
- package/dist/chunk-a865c7x4.js +1 -0
- package/dist/chunk-f44cs6mw.js +2 -0
- package/dist/chunk-h3qag4a6.js +2 -0
- package/dist/chunk-kffcah9w.css +1 -0
- package/dist/chunk-q2tpy0h7.js +2 -0
- package/dist/chunk-r95acex1.js +546 -0
- package/dist/chunk-w5h9grdr.js +1 -0
- package/dist/{chunk-th91xfnp.js → chunk-xj1pjhng.js} +1 -1
- package/dist/index.html +1 -1
- package/lib/harness-instructions.ts +4 -4
- package/lib/harness-types.ts +13 -0
- package/lib/moi-context.ts +19 -5
- package/lib/types.ts +38 -54
- package/lib/workspace-config.ts +48 -0
- package/lib/workspace-layout.ts +5 -24
- package/package.json +5 -2
- package/server/AGENTS.md +1 -1
- package/server/README.md +36 -31
- package/server/api/harnesses.ts +5 -5
- package/server/api/index.ts +268 -162
- package/server/applets/index.ts +15 -9
- package/server/applets/views.ts +2 -17
- package/server/applets/widgets.ts +3 -2
- package/server/cli/commands/config.ts +8 -20
- package/server/cli/commands/hermes.ts +2 -2
- package/server/cli/commands/init.ts +102 -54
- package/server/cli/commands/openclaw.ts +2 -2
- package/server/cli/commands/refresh.ts +10 -1
- package/server/cli/commands/remote.ts +330 -0
- package/server/cli/commands/skill.ts +4 -4
- package/server/cli/commands/tabs.ts +5 -12
- package/server/cli/control.ts +35 -4
- package/server/cli/index.ts +10 -6
- package/server/cli/remote-command.ts +77 -0
- package/server/cli/remote-control.ts +73 -0
- package/server/cli/remote-operations.ts +247 -0
- package/server/collab/config.ts +3 -3
- package/server/collab/skill/index.ts +3 -3
- package/server/control.ts +47 -12
- package/server/harness/acp/session.ts +4 -4
- package/server/harness/auth.ts +26 -31
- package/server/harness/claude-code/index.ts +1 -1
- package/server/harness/codex/discovery.ts +1 -1
- package/server/harness/codex/session.ts +1 -1
- package/server/harness/detect.ts +14 -19
- package/server/harness/executable.ts +10 -10
- package/server/harness/hermes/NOTES.md +2 -2
- package/server/harness/hermes/index.ts +1 -1
- package/server/harness/install.ts +11 -11
- package/server/harness/openclaw/index.ts +1 -1
- package/server/harness/registry.ts +7 -6
- package/server/harness/types.ts +4 -4
- package/server/onboarding/jobs.ts +2 -2
- package/server/operations/commands.ts +46 -0
- package/server/operations/files.ts +148 -0
- package/server/operations/server.ts +206 -0
- package/server/remote/agent.ts +103 -0
- package/server/remote/broker-client.ts +76 -0
- package/server/remote/broker.ts +81 -0
- package/server/remote/client.ts +725 -0
- package/server/remote/errors.ts +2 -0
- package/server/remote/routes.ts +121 -0
- package/server/remote/workspace.ts +34 -0
- package/server/scratchpad/document.ts +33 -12
- package/server/scratchpad/executor.ts +16 -7
- package/server/sessions/config.ts +8 -5
- package/server/sessions/pending-views.ts +17 -0
- package/server/sessions/send-message.ts +102 -0
- package/server/sessions/view-sessions.ts +9 -101
- package/server/skills/locations.ts +4 -4
- package/server/skills/update.ts +11 -11
- package/server/skills/version.ts +7 -7
- package/server/skills/workspace.ts +13 -11
- package/server/web.ts +13 -9
- package/server/workspace-state/file.ts +4 -0
- package/server/workspace-state/index.ts +0 -4
- package/server/workspaces/api.ts +24 -0
- package/server/workspaces/change-harness.ts +15 -26
- package/server/workspaces/import.ts +4 -4
- package/server/workspaces/init.ts +15 -13
- package/server/workspaces/layout.ts +60 -66
- package/server/workspaces/registry.ts +43 -18
- package/server/workspaces/shared.ts +74 -0
- package/server/workspaces/tabs.ts +5 -12
- package/skill/SKILL.md +80 -19
- package/skill/references/SCRATCHPAD.md +4 -0
- package/skill/references/UI-COMPONENTS.md +1 -1
- package/client/api/app-ui-keys.ts +0 -6
- package/client/features/chat/sessions/browser-tab-state.ts +0 -43
- package/client/features/collab/members/keys.ts +0 -6
- package/client/features/workspace/browser-tab-state.ts +0 -51
- package/client/features/workspace/layout-save.ts +0 -13
- package/dist/chunk-3smkkcfw.js +0 -546
- package/dist/chunk-47h9c2qy.js +0 -2
- package/dist/chunk-8qed2gqp.js +0 -75
- package/dist/chunk-8zy3vesm.js +0 -1
- package/dist/chunk-a47zy276.js +0 -2
- package/dist/chunk-g4c1nte9.css +0 -1
- package/dist/chunk-kcactdr4.js +0 -2
- package/dist/chunk-m8bhx6tw.js +0 -1
- package/dist/chunk-pf19zcrn.js +0 -2
- package/dist/chunk-ygzxah0e.js +0 -1
- package/lib/workspace-types.ts +0 -13
- package/server/workspace-state/legacy-migration.ts +0 -79
package/server/harness/detect.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
import { existsSync } from 'node:fs'
|
|
12
12
|
import { join, resolve } from 'node:path'
|
|
13
13
|
|
|
14
|
-
import type {
|
|
14
|
+
import type { HarnessType } from '@/lib/types'
|
|
15
15
|
|
|
16
16
|
import { discoverCodexWorkspaces } from './codex/discovery'
|
|
17
17
|
import { type HermesProfile, discoverHermesProfiles } from './hermes/discovery'
|
|
@@ -19,21 +19,16 @@ import { type OpenClawAgent, discoverOpenClawAgents } from './openclaw/discovery
|
|
|
19
19
|
|
|
20
20
|
// Harness names accepted by `--harness`, in the order they are listed to the
|
|
21
21
|
// user. Detection order is separate (see detectHarness).
|
|
22
|
-
export const HARNESS_TYPES: readonly
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
'hermes',
|
|
26
|
-
'openclaw'
|
|
27
|
-
]
|
|
28
|
-
|
|
29
|
-
export const harnessLabel: Record<WorkspaceType, string> = {
|
|
22
|
+
export const HARNESS_TYPES: readonly HarnessType[] = ['claude-code', 'codex', 'hermes', 'openclaw']
|
|
23
|
+
|
|
24
|
+
export const harnessLabel: Record<HarnessType, string> = {
|
|
30
25
|
'claude-code': 'Claude Code',
|
|
31
26
|
codex: 'Codex',
|
|
32
27
|
hermes: 'Hermes',
|
|
33
28
|
openclaw: 'OpenClaw'
|
|
34
29
|
}
|
|
35
30
|
|
|
36
|
-
export function isHarnessName(value: string): value is
|
|
31
|
+
export function isHarnessName(value: string): value is HarnessType {
|
|
37
32
|
return (HARNESS_TYPES as readonly string[]).includes(value)
|
|
38
33
|
}
|
|
39
34
|
|
|
@@ -48,7 +43,7 @@ export type DetectedAgent = {
|
|
|
48
43
|
}
|
|
49
44
|
|
|
50
45
|
export type HarnessDetection = {
|
|
51
|
-
|
|
46
|
+
harness: HarnessType
|
|
52
47
|
agent?: DetectedAgent
|
|
53
48
|
// What gave it away, as a noun phrase for the CLI's "Detected …" line.
|
|
54
49
|
reason: string
|
|
@@ -91,7 +86,7 @@ async function safely<T>(fn: () => Promise<T>, fallback: T): Promise<T> {
|
|
|
91
86
|
|
|
92
87
|
function detectionForProfile(profile: HermesProfile): HarnessDetection {
|
|
93
88
|
return {
|
|
94
|
-
|
|
89
|
+
harness: 'hermes',
|
|
95
90
|
agent: {
|
|
96
91
|
agentId: profile.agentId,
|
|
97
92
|
...(profile.name ? { name: profile.name } : {}),
|
|
@@ -103,7 +98,7 @@ function detectionForProfile(profile: HermesProfile): HarnessDetection {
|
|
|
103
98
|
|
|
104
99
|
function detectionForAgent(agent: OpenClawAgent): HarnessDetection {
|
|
105
100
|
return {
|
|
106
|
-
|
|
101
|
+
harness: 'openclaw',
|
|
107
102
|
agent: {
|
|
108
103
|
agentId: agent.agentId,
|
|
109
104
|
...(agent.name ? { name: agent.name } : {}),
|
|
@@ -128,7 +123,7 @@ export async function detectHarness(
|
|
|
128
123
|
if (agent) return detectionForAgent(agent)
|
|
129
124
|
|
|
130
125
|
if ((await safely(src.codexWorkspaces, [])).includes(path)) {
|
|
131
|
-
return {
|
|
126
|
+
return { harness: 'codex', reason: 'Codex session history here' }
|
|
132
127
|
}
|
|
133
128
|
|
|
134
129
|
// Session history first, then the config directory: history means the CLI
|
|
@@ -136,10 +131,10 @@ export async function detectHarness(
|
|
|
136
131
|
// the history scan drops linked git worktrees, so a worktree is recognized
|
|
137
132
|
// by its `.claude/` directory or not at all.
|
|
138
133
|
if ((await safely(src.claudeCodeWorkspaces, [])).includes(path)) {
|
|
139
|
-
return {
|
|
134
|
+
return { harness: 'claude-code', reason: 'Claude Code session history here' }
|
|
140
135
|
}
|
|
141
136
|
if (src.hasClaudeConfigDir(path)) {
|
|
142
|
-
return {
|
|
137
|
+
return { harness: 'claude-code', reason: 'a .claude/ directory here' }
|
|
143
138
|
}
|
|
144
139
|
|
|
145
140
|
return null
|
|
@@ -150,18 +145,18 @@ export async function detectHarness(
|
|
|
150
145
|
// would have found. Null for the directory-only harnesses, and for a provider
|
|
151
146
|
// that cannot confirm the path (gateway down, profile removed).
|
|
152
147
|
export async function agentBindingFor(
|
|
153
|
-
|
|
148
|
+
harness: HarnessType,
|
|
154
149
|
workspacePath: string,
|
|
155
150
|
sources: Partial<DetectionSources> = {}
|
|
156
151
|
): Promise<DetectedAgent | null> {
|
|
157
152
|
const src = { ...defaultSources, ...sources }
|
|
158
153
|
const path = resolve(workspacePath)
|
|
159
154
|
|
|
160
|
-
if (
|
|
155
|
+
if (harness === 'hermes') {
|
|
161
156
|
const profile = (await safely(src.hermesProfiles, [])).find(p => p.path === path)
|
|
162
157
|
return profile ? (detectionForProfile(profile).agent ?? null) : null
|
|
163
158
|
}
|
|
164
|
-
if (
|
|
159
|
+
if (harness === 'openclaw') {
|
|
165
160
|
const agent = (await safely(src.openclawAgents, [])).find(a => a.path === path)
|
|
166
161
|
return agent ? (detectionForAgent(agent).agent ?? null) : null
|
|
167
162
|
}
|
|
@@ -3,7 +3,7 @@ import { homedir } from 'node:os'
|
|
|
3
3
|
import { delimiter, join, resolve } from 'node:path'
|
|
4
4
|
|
|
5
5
|
import { harnessInstructionMessage } from '@/lib/harness-instructions'
|
|
6
|
-
import type { HarnessAvailability, HarnessInstallations,
|
|
6
|
+
import type { HarnessAvailability, HarnessInstallations, HarnessType } from '@/lib/types'
|
|
7
7
|
|
|
8
8
|
import { cachedLoginShellPath, loginShellPath, mergeSearchPaths } from './shell-path'
|
|
9
9
|
|
|
@@ -17,7 +17,7 @@ type ExecutableConfig = {
|
|
|
17
17
|
fallbackPaths?: readonly string[]
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
const executableConfig: Record<
|
|
20
|
+
const executableConfig: Record<HarnessType, ExecutableConfig> = {
|
|
21
21
|
'claude-code': {
|
|
22
22
|
command: 'claude',
|
|
23
23
|
fallbackPaths: [
|
|
@@ -76,8 +76,8 @@ export function firstExecutable(paths: readonly string[]): string | null {
|
|
|
76
76
|
|
|
77
77
|
// `path` is a test seam: when given, only that PATH is searched — no
|
|
78
78
|
// login-shell merge, no bundle fallbacks.
|
|
79
|
-
export function findHarnessExecutable(
|
|
80
|
-
const config = executableConfig[
|
|
79
|
+
export function findHarnessExecutable(harness: HarnessType, path?: string): string | null {
|
|
80
|
+
const config = executableConfig[harness]
|
|
81
81
|
// bun run adds our dependency commands to PATH; those are not user installs.
|
|
82
82
|
const searchPath = (path ?? mergeSearchPaths(cachedLoginShellPath(), process.env.PATH))
|
|
83
83
|
.split(delimiter)
|
|
@@ -89,25 +89,25 @@ export function findHarnessExecutable(type: WorkspaceType, path?: string): strin
|
|
|
89
89
|
: (executable ?? firstExecutable(config.fallbackPaths ?? []))
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
export function requireHarnessExecutable(
|
|
93
|
-
const executable = findHarnessExecutable(
|
|
94
|
-
if (!executable) throw new Error(executableConfig[
|
|
92
|
+
export function requireHarnessExecutable(harness: HarnessType, path?: string): string {
|
|
93
|
+
const executable = findHarnessExecutable(harness, path)
|
|
94
|
+
if (!executable) throw new Error(executableConfig[harness].unavailableReason)
|
|
95
95
|
return executable
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
export async function pathHarnessAvailability(
|
|
99
|
-
|
|
99
|
+
harness: HarnessType,
|
|
100
100
|
path?: string
|
|
101
101
|
): Promise<HarnessAvailability> {
|
|
102
102
|
// Availability is asked per request (and long after startup), but await the
|
|
103
103
|
// probe anyway so the very first request can't report a false negative.
|
|
104
104
|
if (path === undefined) await loginShellPath()
|
|
105
|
-
return findHarnessExecutable(
|
|
105
|
+
return findHarnessExecutable(harness, path)
|
|
106
106
|
? { status: 'available' }
|
|
107
107
|
: {
|
|
108
108
|
status: 'unavailable',
|
|
109
109
|
code: 'not-installed',
|
|
110
|
-
reason: executableConfig[
|
|
110
|
+
reason: executableConfig[harness].unavailableReason
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
|
|
@@ -578,10 +578,10 @@ server/harness/hermes/
|
|
|
578
578
|
```
|
|
579
579
|
|
|
580
580
|
Touch points outside the folder are small and already enumerated by the Codex
|
|
581
|
-
precedent: `lib/types.ts` (`
|
|
581
|
+
precedent: `lib/types.ts` (`HarnessType` union), `lib/harness-types.ts`
|
|
582
582
|
(ordering), `lib/format.ts` (`provider` union), `server/harness/registry.ts`,
|
|
583
583
|
`server/harness/executable.ts` (PATH lookup), `server/api/index.ts`
|
|
584
|
-
(`
|
|
584
|
+
(`CREATABLE_HARNESSES`), and a handful of client files that branch on provider
|
|
585
585
|
(`client/features/chat/messages/tool-group/format/index.ts`,
|
|
586
586
|
`client/features/workspace/setup/workspace-login-state.tsx`,
|
|
587
587
|
`client/features/dev/harness-debug-page.tsx`).
|
|
@@ -120,7 +120,7 @@ export const hermesHarness: Harness = {
|
|
|
120
120
|
const profiles = await discoverHermesProfiles()
|
|
121
121
|
return profiles
|
|
122
122
|
.filter(p => !registeredPaths.has(p.path))
|
|
123
|
-
.map((p): DiscoveredWorkspaceCandidate => ({ path: p.path,
|
|
123
|
+
.map((p): DiscoveredWorkspaceCandidate => ({ path: p.path, harness: 'hermes' }))
|
|
124
124
|
},
|
|
125
125
|
|
|
126
126
|
availability: async (ws): Promise<HarnessAvailability> => {
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { HARNESS_INSTRUCTIONS } from '@/lib/harness-instructions'
|
|
2
2
|
import { getAppConfig } from '../app-config'
|
|
3
|
-
import type {
|
|
3
|
+
import type { HarnessType } from '@/lib/types'
|
|
4
4
|
import { detectInstalledHarnesses } from './executable'
|
|
5
5
|
|
|
6
|
-
const installations = new Map<
|
|
6
|
+
const installations = new Map<HarnessType, Promise<void>>()
|
|
7
7
|
|
|
8
|
-
export function installHarness(
|
|
8
|
+
export function installHarness(harness: HarnessType): Promise<void> {
|
|
9
9
|
const config = getAppConfig()
|
|
10
10
|
if (config.environment !== 'local' || config.demo || config.agentLauncher) {
|
|
11
11
|
throw new Error('Agents can only be installed in local Moi')
|
|
12
12
|
}
|
|
13
|
-
if (
|
|
13
|
+
if (harness !== 'claude-code' && harness !== 'codex') {
|
|
14
14
|
throw new Error('This agent requires manual installation')
|
|
15
15
|
}
|
|
16
|
-
const pending = installations.get(
|
|
16
|
+
const pending = installations.get(harness)
|
|
17
17
|
if (pending) return pending
|
|
18
18
|
const installation = (async () => {
|
|
19
|
-
if ((await detectInstalledHarnesses())[
|
|
19
|
+
if ((await detectInstalledHarnesses())[harness]) return
|
|
20
20
|
const url =
|
|
21
|
-
|
|
21
|
+
harness === 'claude-code' ? 'https://claude.ai/install' : 'https://chatgpt.com/codex/install'
|
|
22
22
|
const command =
|
|
23
23
|
process.platform === 'win32'
|
|
24
24
|
? [
|
|
@@ -30,7 +30,7 @@ export function installHarness(type: WorkspaceType): Promise<void> {
|
|
|
30
30
|
'-Command',
|
|
31
31
|
`$ErrorActionPreference = 'Stop'; irm ${url}.ps1 | iex`
|
|
32
32
|
]
|
|
33
|
-
: ['bash', '-o', 'pipefail', '-c', HARNESS_INSTRUCTIONS[
|
|
33
|
+
: ['bash', '-o', 'pipefail', '-c', HARNESS_INSTRUCTIONS[harness].command]
|
|
34
34
|
const child = Bun.spawn(command, {
|
|
35
35
|
stdin: 'ignore',
|
|
36
36
|
stdout: 'inherit',
|
|
@@ -40,10 +40,10 @@ export function installHarness(type: WorkspaceType): Promise<void> {
|
|
|
40
40
|
if ((await child.exited) !== 0) {
|
|
41
41
|
throw new Error('Installation failed or timed out. Try again.')
|
|
42
42
|
}
|
|
43
|
-
if (!(await detectInstalledHarnesses())[
|
|
43
|
+
if (!(await detectInstalledHarnesses())[harness]) {
|
|
44
44
|
throw new Error('The installer finished, but the agent could not be found. Restart Moi.')
|
|
45
45
|
}
|
|
46
|
-
})().finally(() => installations.delete(
|
|
47
|
-
installations.set(
|
|
46
|
+
})().finally(() => installations.delete(harness))
|
|
47
|
+
installations.set(harness, installation)
|
|
48
48
|
return installation
|
|
49
49
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
//
|
|
1
|
+
// HarnessType → Harness lookup. This is the single import surface for the
|
|
2
2
|
// rest of the server: web.ts/api/index.ts/etc. dispatch through harnessFor()
|
|
3
3
|
// instead of branching on workspace.type (documented exceptions: cli.ts
|
|
4
4
|
// provisioning and tests import harness internals directly).
|
|
5
|
-
import type { WorkspaceEntry,
|
|
5
|
+
import type { WorkspaceEntry, HarnessType } from '@/lib/types'
|
|
6
6
|
|
|
7
7
|
import { claudeCodeHarness } from './claude-code'
|
|
8
8
|
import { codexHarness } from './codex'
|
|
@@ -17,13 +17,14 @@ const harnesses = {
|
|
|
17
17
|
openclaw: openclawHarness,
|
|
18
18
|
codex: codexHarness,
|
|
19
19
|
hermes: hermesHarness
|
|
20
|
-
} satisfies Partial<Record<
|
|
20
|
+
} satisfies Partial<Record<HarnessType, Harness>>
|
|
21
21
|
|
|
22
22
|
// An untyped registry entry is a Claude Code workspace (pre-typing legacy).
|
|
23
|
-
export function harnessFor(ws: Pick<WorkspaceEntry, '
|
|
24
|
-
const
|
|
23
|
+
export function harnessFor(ws: Pick<WorkspaceEntry, 'harness'> | HarnessType | undefined): Harness {
|
|
24
|
+
const harness = typeof ws === 'string' ? ws : ws?.harness
|
|
25
25
|
return (
|
|
26
|
-
(
|
|
26
|
+
(harness && harness in harnesses && harnesses[harness as keyof typeof harnesses]) ||
|
|
27
|
+
claudeCodeHarness
|
|
27
28
|
)
|
|
28
29
|
}
|
|
29
30
|
|
package/server/harness/types.ts
CHANGED
|
@@ -16,7 +16,7 @@ import type {
|
|
|
16
16
|
SessionSummary,
|
|
17
17
|
StreamEvent,
|
|
18
18
|
WorkspaceEntry,
|
|
19
|
-
|
|
19
|
+
HarnessType
|
|
20
20
|
} from '@/lib/types'
|
|
21
21
|
|
|
22
22
|
// The superset of what any backend needs to accept a user message; harnesses
|
|
@@ -78,10 +78,10 @@ export type WorkspaceActivityPreview = {
|
|
|
78
78
|
|
|
79
79
|
export type DiscoveredWorkspaceCandidate = {
|
|
80
80
|
path: string
|
|
81
|
-
|
|
81
|
+
harness: HarnessType
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
export type HarnessWorkspace = Pick<WorkspaceEntry, 'id' | 'path' | '
|
|
84
|
+
export type HarnessWorkspace = Pick<WorkspaceEntry, 'id' | 'path' | 'harness' | 'agentId'>
|
|
85
85
|
|
|
86
86
|
export type ActionModel = 'fast' | 'normal' | 'smart'
|
|
87
87
|
|
|
@@ -100,7 +100,7 @@ export type HarnessActionInput<TResult = unknown, TProgress = never> = {
|
|
|
100
100
|
)
|
|
101
101
|
|
|
102
102
|
export type Harness = {
|
|
103
|
-
id:
|
|
103
|
+
id: HarnessType
|
|
104
104
|
capabilities: HarnessCapabilities
|
|
105
105
|
|
|
106
106
|
// Ephemeral read/search action without a workspace or visible chat.
|
|
@@ -12,7 +12,7 @@ import { saveLayout } from '../workspaces/layout'
|
|
|
12
12
|
import { resolveWorkspaceTheme } from '@/lib/themes'
|
|
13
13
|
import { publishEvent } from '../events'
|
|
14
14
|
import { harnessFor } from '../harness/registry'
|
|
15
|
-
import { sendWorkspaceMessage } from '../sessions/
|
|
15
|
+
import { sendWorkspaceMessage } from '../sessions/send-message'
|
|
16
16
|
import { resolveRenamedSession, saveSelectedSession } from '../sessions/selected'
|
|
17
17
|
import { readWorkspaceState } from '../workspace-state'
|
|
18
18
|
import { ideasSchema, onboardingIdeaSchema, parseIdeas } from './ideas'
|
|
@@ -208,7 +208,7 @@ export function createOnboardingJobs(overrides: Partial<typeof defaults> = {}) {
|
|
|
208
208
|
}
|
|
209
209
|
const ws = await deps.registerWorkspace(path, {
|
|
210
210
|
id: job.workspaceId ?? basename(path),
|
|
211
|
-
|
|
211
|
+
harness: progress.harness,
|
|
212
212
|
name: idea.name
|
|
213
213
|
})
|
|
214
214
|
job.workspaceId = ws.id
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { join } from 'node:path'
|
|
2
|
+
import { PACKAGE_ROOT } from '../version'
|
|
3
|
+
import { OperationError } from './files'
|
|
4
|
+
|
|
5
|
+
export const workspaceCommands = [
|
|
6
|
+
'bundle',
|
|
7
|
+
'check',
|
|
8
|
+
'call-server-fn',
|
|
9
|
+
'theme',
|
|
10
|
+
'ui-components',
|
|
11
|
+
'views',
|
|
12
|
+
'debug'
|
|
13
|
+
] as const
|
|
14
|
+
|
|
15
|
+
export function commandArguments(command: string, args: string[]): string[] {
|
|
16
|
+
if (
|
|
17
|
+
!(workspaceCommands as readonly string[]).includes(command) ||
|
|
18
|
+
(command === 'debug' && args[0] !== 'logs')
|
|
19
|
+
)
|
|
20
|
+
throw new OperationError('Unsupported workspace command')
|
|
21
|
+
// The target comes from the URL. Do not let command flags switch workspace.
|
|
22
|
+
if (args.some(arg => /^--(?:dir|path)(?:=|$)/.test(arg)))
|
|
23
|
+
throw new OperationError('Workspace is selected by the remote link, not --dir or --path')
|
|
24
|
+
if (['bundle', 'check', 'views'].includes(command)) {
|
|
25
|
+
// These commands use a positional directory, unlike the other commands.
|
|
26
|
+
const index = command === 'views' ? (args[0] === 'set' ? 2 : 1) : 0
|
|
27
|
+
const result = [...args]
|
|
28
|
+
result.splice(index, 0, '.')
|
|
29
|
+
return [command, ...result]
|
|
30
|
+
}
|
|
31
|
+
return [command, ...args]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function spawnWorkspaceCommand(root: string, command: string, args: string[]) {
|
|
35
|
+
return Bun.spawn(
|
|
36
|
+
[process.execPath, join(PACKAGE_ROOT, 'server/cli.ts'), ...commandArguments(command, args)],
|
|
37
|
+
{
|
|
38
|
+
cwd: root,
|
|
39
|
+
stdin: 'ignore',
|
|
40
|
+
stdout: 'pipe',
|
|
41
|
+
stderr: 'pipe',
|
|
42
|
+
detached: true,
|
|
43
|
+
env: { ...process.env, NO_COLOR: '1', FORCE_COLOR: '0', MOI_REMOTE_WORKSPACE: root }
|
|
44
|
+
}
|
|
45
|
+
)
|
|
46
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { constants } from 'node:fs'
|
|
2
|
+
import { lstat, mkdir, open, realpath, rename, rm } from 'node:fs/promises'
|
|
3
|
+
import { dirname, isAbsolute, relative, resolve, sep } from 'node:path'
|
|
4
|
+
import { Mutex } from 'async-mutex'
|
|
5
|
+
|
|
6
|
+
export class OperationError extends Error {
|
|
7
|
+
constructor(
|
|
8
|
+
message: string,
|
|
9
|
+
readonly status = 400
|
|
10
|
+
) {
|
|
11
|
+
super(message)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// All file operations share this queue. Keep validation and replacement together
|
|
16
|
+
// so two requests through this listener cannot swap an ancestor during a write.
|
|
17
|
+
const writes = new Mutex()
|
|
18
|
+
function inside(root: string, path: string) {
|
|
19
|
+
const rel = relative(root, path)
|
|
20
|
+
return rel !== '' && rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel)
|
|
21
|
+
}
|
|
22
|
+
export async function workspaceFile(root: string, path: string, create = false): Promise<string> {
|
|
23
|
+
if (
|
|
24
|
+
!path ||
|
|
25
|
+
isAbsolute(path) ||
|
|
26
|
+
path.includes('\\') ||
|
|
27
|
+
path.includes('\0') ||
|
|
28
|
+
path.split('/').some(p => p === '..' || p === '.')
|
|
29
|
+
)
|
|
30
|
+
throw new OperationError('Use a file path relative to the workspace')
|
|
31
|
+
root = await realpath(root)
|
|
32
|
+
const target = resolve(root, path)
|
|
33
|
+
if (!inside(root, target)) throw new OperationError('File is outside the workspace')
|
|
34
|
+
let current = root
|
|
35
|
+
const parts = relative(root, target).split(sep)
|
|
36
|
+
for (const [i, part] of parts.entries()) {
|
|
37
|
+
current = resolve(current, part)
|
|
38
|
+
try {
|
|
39
|
+
const info = await lstat(current)
|
|
40
|
+
// Reject symlinks even if currently pointing inside: no check/use redirect.
|
|
41
|
+
if (info.isSymbolicLink()) throw new OperationError('Symbolic links are not supported')
|
|
42
|
+
if (i < parts.length - 1 && !info.isDirectory())
|
|
43
|
+
throw new OperationError('Parent is not a directory')
|
|
44
|
+
if (i === parts.length - 1 && !info.isFile()) throw new OperationError('Path is not a file')
|
|
45
|
+
} catch (error) {
|
|
46
|
+
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error
|
|
47
|
+
if (!create) throw new OperationError('File not found', 404)
|
|
48
|
+
if (i < parts.length - 1) await mkdir(current)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return target
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function writeWorkspaceFile(
|
|
55
|
+
root: string,
|
|
56
|
+
path: string,
|
|
57
|
+
body: ReadableStream<Uint8Array>,
|
|
58
|
+
patch?: (source: string) => string
|
|
59
|
+
) {
|
|
60
|
+
return writes.runExclusive(async () => {
|
|
61
|
+
const target = await workspaceFile(root, path, !patch)
|
|
62
|
+
const temporary = resolve(dirname(target), `.moi-write-${crypto.randomUUID()}`)
|
|
63
|
+
let mode = 0o664
|
|
64
|
+
try {
|
|
65
|
+
mode = (await lstat(target)).mode & 0o777
|
|
66
|
+
} catch {}
|
|
67
|
+
const file = await open(
|
|
68
|
+
temporary,
|
|
69
|
+
constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW,
|
|
70
|
+
mode
|
|
71
|
+
)
|
|
72
|
+
try {
|
|
73
|
+
if (patch) {
|
|
74
|
+
const source = new TextDecoder('utf-8', { fatal: true }).decode(
|
|
75
|
+
await Bun.file(target).arrayBuffer()
|
|
76
|
+
)
|
|
77
|
+
await file.writeFile(patch(source))
|
|
78
|
+
} else {
|
|
79
|
+
for await (const chunk of body) await file.writeFile(chunk)
|
|
80
|
+
}
|
|
81
|
+
await file.close()
|
|
82
|
+
// Recheck after streaming an upload; an external shell can change paths.
|
|
83
|
+
if ((await workspaceFile(root, path, true)) !== target)
|
|
84
|
+
throw new OperationError('File changed during upload', 409)
|
|
85
|
+
await rename(temporary, target)
|
|
86
|
+
} finally {
|
|
87
|
+
await file.close().catch(() => {})
|
|
88
|
+
await rm(temporary, { force: true })
|
|
89
|
+
}
|
|
90
|
+
return { ok: true, bytes: (await lstat(target)).size }
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Apply an exact unified diff to this file. No fuzzy matching or shell execution. */
|
|
95
|
+
export function applyUnifiedPatch(source: string, patch: string): string {
|
|
96
|
+
const original = source ? source.split('\n') : []
|
|
97
|
+
if (source.endsWith('\n')) original.pop()
|
|
98
|
+
const output: string[] = []
|
|
99
|
+
const lines = patch.split('\n')
|
|
100
|
+
let cursor = 0,
|
|
101
|
+
hunks = 0,
|
|
102
|
+
newline = source.endsWith('\n')
|
|
103
|
+
for (let i = 0; i < lines.length; i++) {
|
|
104
|
+
const header = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(?:.*)$/.exec(lines[i]!)
|
|
105
|
+
if (!header) {
|
|
106
|
+
if (lines[i] === '' || lines[i]?.startsWith('--- ') || lines[i]?.startsWith('+++ ')) continue
|
|
107
|
+
throw new OperationError('Expected a unified diff', 422)
|
|
108
|
+
}
|
|
109
|
+
hunks++
|
|
110
|
+
const oldCount = Number(header[2] ?? 1),
|
|
111
|
+
newCount = Number(header[4] ?? 1)
|
|
112
|
+
const start = Number(header[1]) - (oldCount ? 1 : 0)
|
|
113
|
+
if (start < cursor || start > original.length)
|
|
114
|
+
throw new OperationError('Patch does not match the file', 409)
|
|
115
|
+
output.push(...original.slice(cursor, start))
|
|
116
|
+
cursor = start
|
|
117
|
+
if (Number(header[3]) - (newCount ? 1 : 0) !== output.length)
|
|
118
|
+
throw new OperationError('Invalid patch position', 422)
|
|
119
|
+
let removed = 0,
|
|
120
|
+
added = 0
|
|
121
|
+
while (removed < oldCount || added < newCount) {
|
|
122
|
+
const line = lines[++i]
|
|
123
|
+
if (line === undefined) throw new OperationError('Incomplete patch', 422)
|
|
124
|
+
const prefix = line[0],
|
|
125
|
+
value = line.slice(1)
|
|
126
|
+
if (prefix === ' ' || prefix === '-') {
|
|
127
|
+
if (original[cursor++] !== value)
|
|
128
|
+
throw new OperationError('Patch does not match the file', 409)
|
|
129
|
+
removed++
|
|
130
|
+
}
|
|
131
|
+
if (prefix === ' ' || prefix === '+') {
|
|
132
|
+
output.push(value)
|
|
133
|
+
added++
|
|
134
|
+
newline = true
|
|
135
|
+
}
|
|
136
|
+
if (![' ', '+', '-'].includes(prefix ?? '') || removed > oldCount || added > newCount)
|
|
137
|
+
throw new OperationError('Invalid patch hunk', 422)
|
|
138
|
+
if (lines[i + 1] === '\') {
|
|
139
|
+
if (prefix !== '-') newline = false
|
|
140
|
+
i++
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (!hunks) throw new OperationError('Patch has no hunks', 422)
|
|
145
|
+
if (cursor < original.length) newline = source.endsWith('\n')
|
|
146
|
+
output.push(...original.slice(cursor))
|
|
147
|
+
return output.join('\n') + (output.length && newline ? '\n' : '')
|
|
148
|
+
}
|