moi-computer 0.13.1-next.2 → 0.13.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/client/app/app-provider.tsx +14 -20
- package/client/app/app-router.tsx +5 -8
- package/client/app/routes/workspace-route.tsx +28 -11
- package/client/app/shell/sidebar-layout.tsx +5 -10
- package/client/features/app-settings/api.ts +3 -3
- package/client/features/applets/applet-cache.ts +1 -2
- package/client/features/applets/use-applet.ts +18 -20
- package/client/features/chat/chat-store.ts +1 -1
- package/client/features/chat/connection/chat-connection.ts +25 -68
- package/client/features/chat/connection/chat-frames.ts +20 -32
- package/client/features/chat/sessions/api.ts +2 -2
- package/client/features/chat/sessions/use-selected-session.ts +0 -13
- package/client/features/collab/presence/client.ts +63 -83
- package/client/features/collab/presence/provider.tsx +8 -2
- package/client/features/dev/chat-states-page.tsx +1 -1
- package/client/features/dev/harness-debug-page.tsx +2 -2
- package/client/features/scratchpad/scratchpad.tsx +29 -20
- package/client/features/views/api.ts +38 -14
- package/client/features/views/use-view-actions.ts +2 -23
- package/client/features/workspace/api.ts +6 -11
- package/client/features/workspace/harness-transition.ts +3 -5
- package/client/features/workspace/remote.ts +9 -0
- package/client/features/workspace/settings/use-env-vars.ts +4 -4
- package/client/features/workspace/tab-resolution.ts +1 -8
- package/client/features/workspace/use-workspace-navigation.ts +5 -4
- package/client/features/workspace/use-workspace-socket.ts +51 -0
- package/client/features/workspace/workspace-content.tsx +5 -18
- package/client/features/workspace/workspace-layout-context.tsx +6 -13
- package/client/features/workspace/workspace-preferences.ts +67 -10
- package/client/features/workspace/workspace-state.ts +57 -21
- package/client/runtime/app-context.ts +2 -2
- package/client/runtime/app-events.ts +75 -0
- package/client/runtime/reconnecting-socket.ts +115 -0
- package/client/runtime/{use-workspace-events.ts → use-client-events.ts} +9 -10
- package/client/store/ui.ts +1 -6
- package/client/store/workspace-session.ts +30 -0
- package/dist/chunk-0t8m1ehd.js +2 -0
- package/dist/chunk-851bx8ss.js +72 -0
- package/dist/{chunk-n0fawy9x.js → chunk-c8g5x288.js} +1 -1
- package/dist/chunk-cty37f3v.js +1 -0
- package/dist/chunk-dy6f6h3e.js +5 -0
- package/dist/chunk-j6928pwm.js +1 -0
- package/dist/{chunk-rmd0ctfx.js → chunk-k32585ne.js} +73 -73
- package/dist/chunk-qtkv7hp8.js +2 -0
- package/dist/chunk-rh58dc0y.js +2 -0
- package/dist/{chunk-ec5ennpv.js → chunk-wjbejzek.js} +1 -1
- package/dist/index.html +1 -1
- package/lib/events.ts +61 -0
- package/lib/ids.ts +2 -8
- package/lib/moi-context.ts +19 -5
- package/lib/types.ts +16 -20
- package/lib/workspace-layout.ts +3 -20
- package/package.json +2 -1
- package/server/AGENTS.md +4 -4
- package/server/README.md +50 -33
- package/server/api/index.ts +175 -152
- package/server/applets/views.ts +15 -14
- package/server/applets/widgets.ts +4 -3
- package/server/cli/commands/init.ts +7 -2
- package/server/cli/commands/refresh.ts +2 -5
- package/server/cli/commands/remote.ts +128 -26
- package/server/cli/remote-control.ts +12 -9
- package/server/cli/remote-operations.ts +47 -44
- package/server/control.ts +33 -34
- package/server/events.ts +14 -13
- package/server/harness/README.md +7 -7
- package/server/harness/acp/session.ts +9 -5
- package/server/harness/auth.ts +7 -30
- package/server/harness/claude-code/session.ts +8 -4
- package/server/harness/codex/NOTES.md +1 -1
- package/server/harness/codex/session.ts +18 -10
- package/server/harness/hermes/NOTES.md +3 -3
- package/server/harness/openclaw/session.ts +9 -5
- package/server/onboarding/jobs.ts +8 -8
- package/server/operations/commands.ts +1 -1
- package/server/remote/broker-client.ts +76 -0
- package/server/remote/broker.ts +81 -0
- package/server/remote/client.ts +212 -152
- package/server/remote/errors.ts +2 -0
- package/server/remote/routes.ts +121 -0
- package/server/scratchpad/document.ts +3 -2
- package/server/scratchpad/executor.ts +2 -2
- package/server/scratchpad/relay.ts +3 -3
- package/server/sessions/archive.ts +1 -1
- package/server/sessions/lifecycle.ts +1 -1
- package/server/sessions/pending-views.ts +19 -12
- package/server/sessions/send-message.ts +102 -0
- package/server/sessions/view-sessions.ts +4 -94
- package/server/web.ts +42 -31
- package/server/workspace-state/file.ts +2 -0
- package/server/workspace-state/index.ts +15 -4
- package/server/workspaces/api.ts +4 -8
- package/server/workspaces/config.ts +14 -13
- package/server/workspaces/env-apply.ts +1 -1
- package/server/workspaces/layout.ts +40 -7
- package/server/workspaces/shared.ts +1 -1
- package/server/workspaces/tabs.ts +1 -2
- package/skill/SKILL.md +75 -34
- package/skill/references/SCRATCHPAD.md +4 -0
- package/skill/references/UI-COMPONENTS.md +1 -1
- package/client/features/scratchpad/scratch-executor.ts +0 -20
- package/client/runtime/workspace-events.ts +0 -168
- package/dist/chunk-44khk4sp.js +0 -2
- package/dist/chunk-ba6mz56s.js +0 -72
- package/dist/chunk-ectsnw81.js +0 -2
- package/dist/chunk-en7w5ypg.js +0 -1
- package/dist/chunk-f695wcx5.js +0 -5
- package/dist/chunk-pdt9hxfw.js +0 -2
- package/dist/chunk-zv22wv0g.js +0 -1
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { defineCommand } from 'citty'
|
|
2
2
|
import { mkdir, rename, rm } from 'node:fs/promises'
|
|
3
|
-
import { dirname, resolve } from 'node:path'
|
|
3
|
+
import { basename, dirname, resolve } from 'node:path'
|
|
4
4
|
import { z } from 'zod'
|
|
5
|
-
import {
|
|
5
|
+
import { remoteRequest } from '../remote/client'
|
|
6
|
+
import { cloudRoutes } from '../remote/routes'
|
|
6
7
|
import { currentRemoteWorkspace } from '../remote/workspace'
|
|
8
|
+
import { resolveWorkspaceRoot } from '../skills/version'
|
|
9
|
+
import { getLayoutPath, loadWorkspaceFileConfig } from '../workspaces/layout'
|
|
7
10
|
|
|
8
|
-
const path = { type: 'string' as const, description: 'Local linked workspace folder' }
|
|
9
11
|
const json = { type: 'boolean' as const, description: 'Print JSON result' }
|
|
10
12
|
const commandResult = z.object({
|
|
11
13
|
exitCode: z.number().int(),
|
|
@@ -26,7 +28,7 @@ async function printCommandResult(response: Response, json = false) {
|
|
|
26
28
|
export async function runLinkedWorkspaceCommand(command: string, args: string[], folder: string) {
|
|
27
29
|
const linked = await currentRemoteWorkspace(folder)
|
|
28
30
|
if (!linked) return false
|
|
29
|
-
const response = await
|
|
31
|
+
const response = await remoteRequest(cloudRoutes.commands.path(linked), {
|
|
30
32
|
method: 'POST',
|
|
31
33
|
body: JSON.stringify({ command, args }),
|
|
32
34
|
contentType: 'application/json'
|
|
@@ -39,24 +41,28 @@ const execEvent = z.discriminatedUnion('type', [
|
|
|
39
41
|
z.object({ type: z.literal('stderr'), data: z.string() }),
|
|
40
42
|
z.object({ type: z.literal('exit'), code: z.number().int() })
|
|
41
43
|
])
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
44
|
+
async function target() {
|
|
45
|
+
const current = await currentRemoteWorkspace()
|
|
46
|
+
if (!current) {
|
|
47
|
+
const root = await resolveWorkspaceRoot(process.cwd())
|
|
48
|
+
const config = await loadWorkspaceFileConfig(root)
|
|
49
|
+
let message = 'This folder is not linked to a remote workspace'
|
|
50
|
+
if (!config.remote && (await Bun.file(getLayoutPath(root)).exists())) {
|
|
51
|
+
const name = Bun.stripANSI(config.name || basename(root)).replace(
|
|
52
|
+
// oxlint-disable-next-line no-control-regex -- Workspace names must not control the terminal.
|
|
53
|
+
/[\u0000-\u001f\u007f-\u009f]/g,
|
|
54
|
+
''
|
|
55
|
+
)
|
|
56
|
+
message += `\nIt is an existing local workspace: ${name}`
|
|
57
|
+
}
|
|
58
|
+
throw new Error(message)
|
|
59
|
+
}
|
|
60
|
+
type Options = Parameters<typeof remoteRequest>[1]
|
|
61
|
+
return {
|
|
62
|
+
file: (file: string, options?: Options) =>
|
|
63
|
+
remoteRequest(cloudRoutes.files.path(current, file), options),
|
|
64
|
+
exec: (options?: Options) => remoteRequest(cloudRoutes.exec.path(current), options)
|
|
65
|
+
}
|
|
60
66
|
}
|
|
61
67
|
async function stdin() {
|
|
62
68
|
if (process.stdin.isTTY) throw new Error('Supply content or pipe it on stdin')
|
|
@@ -66,10 +72,10 @@ async function stdin() {
|
|
|
66
72
|
export function remoteOperations(report: (action: () => Promise<void>) => Promise<void>) {
|
|
67
73
|
const read = defineCommand({
|
|
68
74
|
meta: { name: 'read', description: 'Read a remote workspace file to stdout' },
|
|
69
|
-
args: { file: { type: 'positional', required: true }
|
|
75
|
+
args: { file: { type: 'positional', required: true } },
|
|
70
76
|
run: ({ args }) =>
|
|
71
77
|
report(async () => {
|
|
72
|
-
const response = await (await target(
|
|
78
|
+
const response = await (await target()).file(args.file)
|
|
73
79
|
if (response.body)
|
|
74
80
|
for await (const chunk of response.body) await Bun.write(Bun.stdout, chunk)
|
|
75
81
|
})
|
|
@@ -79,14 +85,13 @@ export function remoteOperations(report: (action: () => Promise<void>) => Promis
|
|
|
79
85
|
args: {
|
|
80
86
|
file: { type: 'positional', required: true },
|
|
81
87
|
content: { type: 'positional', required: false },
|
|
82
|
-
path,
|
|
83
88
|
json
|
|
84
89
|
},
|
|
85
90
|
run: ({ args }) =>
|
|
86
91
|
report(async () => {
|
|
87
92
|
const response = await (
|
|
88
|
-
await target(
|
|
89
|
-
)(
|
|
93
|
+
await target()
|
|
94
|
+
).file(args.file, {
|
|
90
95
|
method: 'PUT',
|
|
91
96
|
body: args.content ?? (await stdin()),
|
|
92
97
|
contentType: 'application/octet-stream'
|
|
@@ -102,7 +107,6 @@ export function remoteOperations(report: (action: () => Promise<void>) => Promis
|
|
|
102
107
|
args: {
|
|
103
108
|
file: { type: 'positional', required: true },
|
|
104
109
|
'patch-file': { type: 'string' },
|
|
105
|
-
path,
|
|
106
110
|
json
|
|
107
111
|
},
|
|
108
112
|
run: ({ args }) =>
|
|
@@ -111,8 +115,8 @@ export function remoteOperations(report: (action: () => Promise<void>) => Promis
|
|
|
111
115
|
? await Bun.file(resolve(args['patch-file'])).text()
|
|
112
116
|
: await stdin()
|
|
113
117
|
const response = await (
|
|
114
|
-
await target(
|
|
115
|
-
)(
|
|
118
|
+
await target()
|
|
119
|
+
).file(args.file, {
|
|
116
120
|
method: 'PATCH',
|
|
117
121
|
body: JSON.stringify({ patch: diff }),
|
|
118
122
|
contentType: 'application/json'
|
|
@@ -125,7 +129,6 @@ export function remoteOperations(report: (action: () => Promise<void>) => Promis
|
|
|
125
129
|
args: {
|
|
126
130
|
source: { type: 'positional', required: true },
|
|
127
131
|
destination: { type: 'positional', required: true },
|
|
128
|
-
path,
|
|
129
132
|
json
|
|
130
133
|
},
|
|
131
134
|
run: ({ args }) =>
|
|
@@ -133,8 +136,8 @@ export function remoteOperations(report: (action: () => Promise<void>) => Promis
|
|
|
133
136
|
const file = Bun.file(resolve(args.source))
|
|
134
137
|
if (!(await file.exists())) throw new Error('Local source file not found')
|
|
135
138
|
const response = await (
|
|
136
|
-
await target(
|
|
137
|
-
)(
|
|
139
|
+
await target()
|
|
140
|
+
).file(args.destination, {
|
|
138
141
|
method: 'PUT',
|
|
139
142
|
body: file,
|
|
140
143
|
contentType: 'application/octet-stream'
|
|
@@ -152,12 +155,11 @@ export function remoteOperations(report: (action: () => Promise<void>) => Promis
|
|
|
152
155
|
args: {
|
|
153
156
|
source: { type: 'positional', required: true },
|
|
154
157
|
destination: { type: 'positional', required: true },
|
|
155
|
-
path,
|
|
156
158
|
json
|
|
157
159
|
},
|
|
158
160
|
run: ({ args }) =>
|
|
159
161
|
report(async () => {
|
|
160
|
-
const response = await (await target(
|
|
162
|
+
const response = await (await target()).file(args.source)
|
|
161
163
|
const destination = resolve(args.destination),
|
|
162
164
|
temporary = `${destination}.${crypto.randomUUID()}.tmp`
|
|
163
165
|
await mkdir(dirname(destination), { recursive: true })
|
|
@@ -179,20 +181,21 @@ export function remoteOperations(report: (action: () => Promise<void>) => Promis
|
|
|
179
181
|
name: 'exec',
|
|
180
182
|
description: 'Run a shell command on the remote host, in this workspace'
|
|
181
183
|
},
|
|
182
|
-
args: { command: { type: 'positional', required: true },
|
|
184
|
+
args: { command: { type: 'positional', required: true }, json },
|
|
183
185
|
run: ({ args }) =>
|
|
184
186
|
report(async () => {
|
|
185
187
|
const controller = new AbortController()
|
|
186
|
-
const request = await target(
|
|
188
|
+
const request = await target()
|
|
187
189
|
const id = crypto.randomUUID()
|
|
188
190
|
let cancellation: Promise<void> | undefined
|
|
189
191
|
const interrupt = () => {
|
|
190
|
-
cancellation ??= request
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
192
|
+
cancellation ??= request
|
|
193
|
+
.exec({
|
|
194
|
+
method: 'POST',
|
|
195
|
+
body: JSON.stringify({ cancel: id }),
|
|
196
|
+
contentType: 'application/json',
|
|
197
|
+
signal: AbortSignal.timeout(10_000)
|
|
198
|
+
})
|
|
196
199
|
.then(async response => {
|
|
197
200
|
await response.body?.cancel()
|
|
198
201
|
})
|
|
@@ -203,7 +206,7 @@ export function remoteOperations(report: (action: () => Promise<void>) => Promis
|
|
|
203
206
|
}
|
|
204
207
|
process.once('SIGINT', interrupt)
|
|
205
208
|
try {
|
|
206
|
-
const response = await request(
|
|
209
|
+
const response = await request.exec({
|
|
207
210
|
method: 'POST',
|
|
208
211
|
body: JSON.stringify({ command: args.command, id }),
|
|
209
212
|
contentType: 'application/json',
|
package/server/control.ts
CHANGED
|
@@ -15,14 +15,13 @@ import { CONTROL_HOST, CONTROL_PORT, PORT } from './constants'
|
|
|
15
15
|
import { applyEnvChanged } from './workspaces/env-apply'
|
|
16
16
|
import { callFunctionEphemeral, parseFunctionPath } from './applets/functions'
|
|
17
17
|
import { processIcon } from './workspaces/icon'
|
|
18
|
-
import { loadLayout,
|
|
18
|
+
import { loadLayout, updateLayout } from './workspaces/layout'
|
|
19
19
|
import { publishEvent } from './events'
|
|
20
20
|
import { findWorkspaceForPath, listWorkspaces, registerWorkspace } from './workspaces/registry'
|
|
21
21
|
import { requiredEnvFor } from './workspaces/required-env'
|
|
22
22
|
import { executeScratchOp } from './scratchpad/executor'
|
|
23
23
|
import { readScratchpadImage, readScratchpadShapes } from './scratchpad/document'
|
|
24
24
|
import { relayScratchOp } from './scratchpad/relay'
|
|
25
|
-
import { broadcastAll } from './state'
|
|
26
25
|
import { assembleTabRows, assertNavigableTab } from './workspaces/tabs'
|
|
27
26
|
import { applyThemeUpdate } from './workspaces/theme'
|
|
28
27
|
import { handleBundle } from './applets/widgets'
|
|
@@ -39,6 +38,7 @@ import {
|
|
|
39
38
|
type WorkspaceConfigPatch
|
|
40
39
|
} from './workspaces/config'
|
|
41
40
|
import { VERSION } from './version'
|
|
41
|
+
import { createRemoteBroker } from './remote/broker'
|
|
42
42
|
import {
|
|
43
43
|
getWorkspaceEnvView,
|
|
44
44
|
parseEnvUpdate,
|
|
@@ -49,6 +49,8 @@ import {
|
|
|
49
49
|
|
|
50
50
|
type ControlSocket = { send(data: string): void }
|
|
51
51
|
|
|
52
|
+
const remoteBroker = createRemoteBroker()
|
|
53
|
+
|
|
52
54
|
// Resolve a control request's `path` to the registered workspace that contains
|
|
53
55
|
// it — the entry itself or its nearest registered ancestor — so every
|
|
54
56
|
// workspace-scoped command (bundle/theme/config/scratch) works from `.moi/` or
|
|
@@ -80,7 +82,12 @@ async function resolveWorkspace(
|
|
|
80
82
|
export const control = Bun.serve({
|
|
81
83
|
port: CONTROL_PORT,
|
|
82
84
|
hostname: CONTROL_HOST,
|
|
83
|
-
fetch(req, server) {
|
|
85
|
+
async fetch(req, server) {
|
|
86
|
+
// Cloud requests from callers with no login of their own (remote/broker.ts).
|
|
87
|
+
// An exec stream can stay quiet for longer than the default idle timeout.
|
|
88
|
+
if (new URL(req.url).pathname.startsWith('/remote/')) server.timeout(req, 0)
|
|
89
|
+
const brokered = await remoteBroker(req)
|
|
90
|
+
if (brokered) return brokered
|
|
84
91
|
return server.upgrade(req)
|
|
85
92
|
? new Response(null, { status: 101 })
|
|
86
93
|
: new Response('Control WebSocket only', { status: 426 })
|
|
@@ -93,7 +100,7 @@ export const control = Bun.serve({
|
|
|
93
100
|
if (data.type === 'workspace:register') {
|
|
94
101
|
const absPath = resolve(String(data.path))
|
|
95
102
|
const entry = await registerWorkspace(absPath)
|
|
96
|
-
|
|
103
|
+
publishEvent({ type: 'workspace:open-requested', workspaceId: entry.id })
|
|
97
104
|
ws.send(JSON.stringify({ id: entry.id, path: entry.path }))
|
|
98
105
|
return
|
|
99
106
|
}
|
|
@@ -367,34 +374,24 @@ export const control = Bun.serve({
|
|
|
367
374
|
return
|
|
368
375
|
}
|
|
369
376
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
if (data.path && !match) return
|
|
378
|
-
const scope = match ? { workspaceId: match.id } : {}
|
|
377
|
+
if (data.type === 'applets:refresh') {
|
|
378
|
+
if (typeof data.path !== 'string' || !data.path) {
|
|
379
|
+
ws.send(JSON.stringify({ error: 'Refresh requires a workspace path' }))
|
|
380
|
+
return
|
|
381
|
+
}
|
|
382
|
+
const workspace = await resolveWorkspace(ws, data.path)
|
|
383
|
+
if (!workspace) return
|
|
379
384
|
const only = typeof data.only === 'string' ? parseAppletSelector(data.only) : undefined
|
|
380
|
-
if (data.only && !only) {
|
|
385
|
+
if (data.only !== undefined && !only) {
|
|
381
386
|
ws.send(JSON.stringify({ error: `Invalid applet selector "${data.only}"` }))
|
|
382
387
|
return
|
|
383
388
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
})
|
|
391
|
-
} else {
|
|
392
|
-
publishEvent({
|
|
393
|
-
type: 'applets:refresh',
|
|
394
|
-
...scope,
|
|
395
|
-
...(data.only ? { only: data.only } : {})
|
|
396
|
-
})
|
|
397
|
-
}
|
|
389
|
+
publishEvent({
|
|
390
|
+
type: 'applets:refresh',
|
|
391
|
+
workspaceId: workspace.id,
|
|
392
|
+
only: only?.segment,
|
|
393
|
+
name: only?.id
|
|
394
|
+
})
|
|
398
395
|
ws.send(JSON.stringify({ ok: true }))
|
|
399
396
|
return
|
|
400
397
|
}
|
|
@@ -436,11 +433,10 @@ export const control = Bun.serve({
|
|
|
436
433
|
const match = await resolveWorkspace(ws, data.path)
|
|
437
434
|
if (!match) return
|
|
438
435
|
const workspacePath = match.path
|
|
439
|
-
const layout = await loadLayout(workspacePath)
|
|
440
436
|
|
|
441
437
|
// Listing mode — no theme setting requested
|
|
442
438
|
if (!data.font && !data.color && !data.radius && !data.agent) {
|
|
443
|
-
const theme = resolveWorkspaceTheme(
|
|
439
|
+
const theme = resolveWorkspaceTheme((await loadLayout(workspacePath)).theme)
|
|
444
440
|
ws.send(
|
|
445
441
|
JSON.stringify({
|
|
446
442
|
currentFont: theme.font,
|
|
@@ -452,7 +448,7 @@ export const control = Bun.serve({
|
|
|
452
448
|
return
|
|
453
449
|
}
|
|
454
450
|
|
|
455
|
-
const result = applyThemeUpdate(
|
|
451
|
+
const result = applyThemeUpdate(undefined, {
|
|
456
452
|
font: data.font,
|
|
457
453
|
color: data.color,
|
|
458
454
|
radius: data.radius,
|
|
@@ -463,8 +459,11 @@ export const control = Bun.serve({
|
|
|
463
459
|
return
|
|
464
460
|
}
|
|
465
461
|
|
|
466
|
-
await
|
|
467
|
-
|
|
462
|
+
await updateLayout(workspacePath, layout => ({
|
|
463
|
+
...layout,
|
|
464
|
+
theme: resolveWorkspaceTheme({ ...layout.theme, ...result.applied })
|
|
465
|
+
}))
|
|
466
|
+
publishEvent({ type: 'workspace-config:changed', workspaceId: match.id })
|
|
468
467
|
ws.send(JSON.stringify({ ok: true, ...result.applied }))
|
|
469
468
|
return
|
|
470
469
|
}
|
|
@@ -507,7 +506,7 @@ export const control = Bun.serve({
|
|
|
507
506
|
}
|
|
508
507
|
|
|
509
508
|
await setWorkspaceConfig(workspacePath, patch)
|
|
510
|
-
publishEvent({ type: 'workspace:
|
|
509
|
+
publishEvent({ type: 'workspace-config:changed', workspaceId: match.id })
|
|
511
510
|
ws.send(
|
|
512
511
|
JSON.stringify({
|
|
513
512
|
ok: true,
|
package/server/events.ts
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
// socket. Bundles, the control server, and the REST API publish build/refresh/
|
|
3
|
-
// identity events (`applets:refresh`, `theme:updated`, `workspace:updated`, …)
|
|
4
|
-
// here; every subscribed browser receives them. This is not a transport of its
|
|
5
|
-
// own — it rides the Bun WebSocket pub/sub already open for that route.
|
|
6
|
-
//
|
|
7
|
-
// The publisher is the Bun.serve instance created in web.ts, wired in via
|
|
8
|
-
// `setEventServer` once it exists. Keeping `publishEvent` in its own module lets
|
|
9
|
-
// web.ts, control.ts, and the Hono API all publish without forming an import
|
|
10
|
-
// cycle through web.ts (which binds ports on load).
|
|
1
|
+
import { isSharedWorkspaceEvent, type ServerEvent } from '@/lib/events'
|
|
11
2
|
|
|
12
3
|
export const EVENTS_TOPIC = 'events'
|
|
4
|
+
export const HARNESS_EVENTS_TOPIC = 'harness-events'
|
|
5
|
+
export const workspaceEventsTopic = (workspaceId: string) => `workspace-events:${workspaceId}`
|
|
13
6
|
|
|
14
7
|
type EventPublisher = { publish: (topic: string, data: string) => unknown }
|
|
15
|
-
|
|
16
8
|
let publisher: EventPublisher | null = null
|
|
17
9
|
|
|
18
10
|
export function setEventServer(server: EventPublisher) {
|
|
19
11
|
publisher = server
|
|
20
12
|
}
|
|
21
13
|
|
|
22
|
-
export function publishEvent(msg:
|
|
23
|
-
|
|
14
|
+
export function publishEvent(msg: ServerEvent) {
|
|
15
|
+
if (isSharedWorkspaceEvent(msg)) {
|
|
16
|
+
const { workspaceId, ...event } = msg
|
|
17
|
+
publisher?.publish(workspaceEventsTopic(workspaceId), JSON.stringify(event))
|
|
18
|
+
if (msg.type === 'workspace-config:changed') {
|
|
19
|
+
publisher?.publish(EVENTS_TOPIC, JSON.stringify({ type: 'workspaces-list:changed' }))
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
22
|
+
const harness = msg.type === 'harness:changed' || msg.type === 'workspace-harness:switched'
|
|
23
|
+
publisher?.publish(harness ? HARNESS_EVENTS_TOPIC : EVENTS_TOPIC, JSON.stringify(msg))
|
|
24
|
+
}
|
|
24
25
|
}
|
package/server/harness/README.md
CHANGED
|
@@ -43,24 +43,24 @@ mirrors upstream code verbatim and stays in `openclaw/strip.ts`.)
|
|
|
43
43
|
|
|
44
44
|
Socket-protocol notes the layers rely on (all defined in `lib/types.ts`):
|
|
45
45
|
|
|
46
|
-
- **`
|
|
46
|
+
- **`session:renamed`** — a new thread is created under the client's temporary
|
|
47
47
|
uuid, then rekeyed to the backend's real session/thread id.
|
|
48
|
-
- **`
|
|
48
|
+
- **`sessions:changed`** — a provider changed session-list metadata such as a
|
|
49
49
|
generated session title; clients refresh that workspace's session list.
|
|
50
|
-
- **`
|
|
50
|
+
- **`session:archived`** — a chat was archived; clients remove it from caches and
|
|
51
51
|
clear its selections and pin, including browser-local Collab selections.
|
|
52
52
|
- **Optimistic-id rendezvous** — the client sends `optimisticId` with each
|
|
53
53
|
chat; the user's bubble must upsert under that id. Backends differ: Codex
|
|
54
54
|
echoes it natively (`clientUserMessageId` → `clientId`), Claude Code never
|
|
55
55
|
echoes (the server synthesizes the turn), OpenClaw echoes lagged (matched
|
|
56
56
|
by text).
|
|
57
|
-
- **`status` / `
|
|
57
|
+
- **`session:status` / `sessions:status-snapshot`** — per-session `activity`
|
|
58
58
|
(`idle | running | requires-action`), mirrored from the backend's native
|
|
59
59
|
lifecycle signal — never derived by counting sends vs results. The snapshot
|
|
60
60
|
(sent on connect and re-broadcast periodically) is authoritative: the client
|
|
61
61
|
rebuilds its whole activity map from it, so a lost terminal frame self-heals.
|
|
62
62
|
`requires-action` suppresses the loader.
|
|
63
|
-
- **`preview`** — live token frames, cumulative text, never persisted;
|
|
63
|
+
- **`session:preview`** — live token frames, cumulative text, never persisted;
|
|
64
64
|
cleared when the turn with matching `meta.apiMessageId` lands.
|
|
65
65
|
|
|
66
66
|
## Folder layout & conventions
|
|
@@ -184,7 +184,7 @@ built on the provider-agnostic `acp/` layer. Session create/resume with temp-id
|
|
|
184
184
|
rename, `session/load` history replay, interrupt via `session/cancel`, per-turn
|
|
185
185
|
token usage, token streaming for thinking _and_ text, inline base64 images,
|
|
186
186
|
per-chat model switching from the catalog `session/new` returns inline, and
|
|
187
|
-
backend-generated session titles surfaced through `
|
|
187
|
+
backend-generated session titles surfaced through `sessions:changed`. Agents are
|
|
188
188
|
Hermes **profiles** — discovered from `$HERMES_HOME`, imported with
|
|
189
189
|
`moi hermes init <profile>`, never created from the UI (OpenClaw's model).
|
|
190
190
|
Sessions run in Hermes's `dont_ask` mode to match Moi's bypass-permissions trust
|
|
@@ -235,7 +235,7 @@ code. The attempt ID rejects submissions from an older login. Startup reports
|
|
|
235
235
|
|
|
236
236
|
During login, the server rechecks readiness until the provider confirms
|
|
237
237
|
completion and readiness succeeds, or the attempt fails or reaches its
|
|
238
|
-
ten-minute deadline. Shutdown cancels active attempts. Auth changes publish `harness
|
|
238
|
+
ten-minute deadline. Shutdown cancels active attempts. Auth changes publish `harness:changed` once for all consumers. The client
|
|
239
239
|
shares one status query across onboarding and workspace navigation. It
|
|
240
240
|
reads cached status on focus, reconnect, and authentication changes, and polls only during
|
|
241
241
|
an active login.
|
|
@@ -12,7 +12,7 @@ import type { MessageAttachment } from '@/lib/types'
|
|
|
12
12
|
//
|
|
13
13
|
// Lifecycle notes:
|
|
14
14
|
// - A brand-new session is created under the client's temporary uuid, then
|
|
15
|
-
// renamed to the agent's real session id (`
|
|
15
|
+
// renamed to the agent's real session id (`session:renamed`) — same flow
|
|
16
16
|
// as the Claude Code, OpenClaw and Codex paths.
|
|
17
17
|
// - ACP has no steer: a send that lands mid-turn is queued and flushed when
|
|
18
18
|
// the running turn resolves.
|
|
@@ -159,7 +159,7 @@ function setProcessing(rec: SessionRecord, processing: boolean) {
|
|
|
159
159
|
if (rec.processing === processing) return
|
|
160
160
|
rec.processing = processing
|
|
161
161
|
broadcast(rec.workspaceId, {
|
|
162
|
-
type: 'status',
|
|
162
|
+
type: 'session:status',
|
|
163
163
|
sessionId: rec.sessionId,
|
|
164
164
|
activity: processing ? 'running' : 'idle'
|
|
165
165
|
})
|
|
@@ -184,7 +184,7 @@ function emitTurnEvent(rec: SessionRecord, ev: StreamEvent) {
|
|
|
184
184
|
function forwardPreview(rec: SessionRecord) {
|
|
185
185
|
if (!rec.stream || rec.replaying) return
|
|
186
186
|
broadcast(rec.workspaceId, {
|
|
187
|
-
type: 'preview',
|
|
187
|
+
type: 'session:preview',
|
|
188
188
|
sessionId: rec.sessionId,
|
|
189
189
|
messageId: rec.acc.currentId,
|
|
190
190
|
parentToolUseId: null,
|
|
@@ -323,7 +323,7 @@ function handleSessionUpdate(rec: SessionRecord, update: SessionUpdate, provider
|
|
|
323
323
|
case 'session_info_update': {
|
|
324
324
|
// The backend generated or refreshed a session title.
|
|
325
325
|
if (!rec.replaying) {
|
|
326
|
-
broadcast(rec.workspaceId, { type: '
|
|
326
|
+
broadcast(rec.workspaceId, { type: 'sessions:changed', sessionId: rec.sessionId })
|
|
327
327
|
}
|
|
328
328
|
return
|
|
329
329
|
}
|
|
@@ -641,7 +641,11 @@ export async function sendAcpMessage(
|
|
|
641
641
|
}
|
|
642
642
|
}
|
|
643
643
|
} catch (err) {
|
|
644
|
-
broadcast(input.workspaceId, {
|
|
644
|
+
broadcast(input.workspaceId, {
|
|
645
|
+
type: 'session:status',
|
|
646
|
+
sessionId: input.sessionId,
|
|
647
|
+
activity: 'idle'
|
|
648
|
+
})
|
|
645
649
|
broadcast(input.workspaceId, {
|
|
646
650
|
kind: 'error',
|
|
647
651
|
sessionId: input.sessionId,
|
package/server/harness/auth.ts
CHANGED
|
@@ -7,12 +7,6 @@ import { publishEvent } from '../events'
|
|
|
7
7
|
import { harnessFor } from './registry'
|
|
8
8
|
import type { HarnessWorkspace, HarnessLoginAttempt } from './types'
|
|
9
9
|
|
|
10
|
-
export type HarnessUpdatedEvent = {
|
|
11
|
-
type: 'harness:updated'
|
|
12
|
-
workspaceId: string
|
|
13
|
-
availability: HarnessAvailability
|
|
14
|
-
}
|
|
15
|
-
|
|
16
10
|
// Readiness can target a harness account or an individual workspace.
|
|
17
11
|
type HarnessTarget = HarnessType | HarnessWorkspace
|
|
18
12
|
|
|
@@ -23,8 +17,7 @@ function entryKey(context: HarnessTarget): string {
|
|
|
23
17
|
export type HarnessStoreOptions = {
|
|
24
18
|
probe: (ws: HarnessTarget) => Promise<HarnessAvailability>
|
|
25
19
|
startLogin: (harness: HarnessType) => Promise<HarnessLoginAttempt>
|
|
26
|
-
publish: (
|
|
27
|
-
onAuthChanged?: (harness: HarnessType, availability: HarnessAvailability) => Promise<void>
|
|
20
|
+
publish: () => void
|
|
28
21
|
availabilityTtlMs?: number
|
|
29
22
|
loginPollMs?: number
|
|
30
23
|
loginDeadlineMs?: number
|
|
@@ -77,15 +70,6 @@ export function createHarnessStore(options: HarnessStoreOptions) {
|
|
|
77
70
|
return entry
|
|
78
71
|
}
|
|
79
72
|
|
|
80
|
-
async function publish(context: HarnessTarget, availability: HarnessAvailability) {
|
|
81
|
-
if (typeof context === 'string') return options.onAuthChanged?.(context, availability)
|
|
82
|
-
options.publish({
|
|
83
|
-
type: 'harness:updated',
|
|
84
|
-
workspaceId: context.id,
|
|
85
|
-
availability
|
|
86
|
-
})
|
|
87
|
-
}
|
|
88
|
-
|
|
89
73
|
async function probeFresh(ws: HarnessTarget): Promise<HarnessAvailability> {
|
|
90
74
|
const entry = entryFor(ws)
|
|
91
75
|
if (!entry.probe) {
|
|
@@ -115,7 +99,7 @@ export function createHarnessStore(options: HarnessStoreOptions) {
|
|
|
115
99
|
// out from outside moi — a `codex logout` in a terminal, say).
|
|
116
100
|
async function refresh(ws: HarnessTarget): Promise<HarnessAvailability> {
|
|
117
101
|
const value = await probeFresh(ws)
|
|
118
|
-
|
|
102
|
+
options.publish()
|
|
119
103
|
return value
|
|
120
104
|
}
|
|
121
105
|
|
|
@@ -144,7 +128,7 @@ export function createHarnessStore(options: HarnessStoreOptions) {
|
|
|
144
128
|
const entry = entryFor(harness)
|
|
145
129
|
if (value.status === 'available' && (!login.attempt?.completed || login.completed)) {
|
|
146
130
|
entry.login = undefined
|
|
147
|
-
|
|
131
|
+
options.publish()
|
|
148
132
|
return
|
|
149
133
|
}
|
|
150
134
|
if (Date.now() >= deadline) {
|
|
@@ -152,12 +136,12 @@ export function createHarnessStore(options: HarnessStoreOptions) {
|
|
|
152
136
|
// startLogin replaces it.
|
|
153
137
|
stopLogin(login)
|
|
154
138
|
login.state = { state: 'failed', reason: 'Sign-in did not complete. Try again' }
|
|
155
|
-
|
|
139
|
+
options.publish()
|
|
156
140
|
return
|
|
157
141
|
}
|
|
158
142
|
if (!sameAvailability(value, publishedAvailability)) {
|
|
159
143
|
publishedAvailability = value
|
|
160
|
-
|
|
144
|
+
options.publish()
|
|
161
145
|
}
|
|
162
146
|
timer = setTimeout(tick, pollMs)
|
|
163
147
|
timer.unref?.()
|
|
@@ -208,7 +192,7 @@ export function createHarnessStore(options: HarnessStoreOptions) {
|
|
|
208
192
|
status: 'login-required',
|
|
209
193
|
reason: 'Waiting for sign-in'
|
|
210
194
|
}
|
|
211
|
-
|
|
195
|
+
options.publish()
|
|
212
196
|
if (login.state.state === 'pending') watch(harness, login, availability)
|
|
213
197
|
return result
|
|
214
198
|
} catch (err) {
|
|
@@ -284,12 +268,5 @@ export const harnessStore = createHarnessStore({
|
|
|
284
268
|
if (!start) throw new Error('This agent requires terminal sign-in')
|
|
285
269
|
return start()
|
|
286
270
|
},
|
|
287
|
-
publish: publishEvent
|
|
288
|
-
onAuthChanged: async (harness, availability) => {
|
|
289
|
-
publishEvent({
|
|
290
|
-
type: 'harness-status:changed',
|
|
291
|
-
harness: harness,
|
|
292
|
-
status: { availability, login: harnessStore.getLogin(harness) }
|
|
293
|
-
})
|
|
294
|
-
}
|
|
271
|
+
publish: () => publishEvent({ type: 'harness:changed' })
|
|
295
272
|
})
|
|
@@ -287,7 +287,11 @@ function publishMessageActivity(messages: SessionMessages) {
|
|
|
287
287
|
const activity = messageActivity(messages)
|
|
288
288
|
if (messages.publishedActivity === activity) return
|
|
289
289
|
messages.publishedActivity = activity
|
|
290
|
-
broadcast(messages.workspaceId, {
|
|
290
|
+
broadcast(messages.workspaceId, {
|
|
291
|
+
type: 'session:status',
|
|
292
|
+
sessionId: messages.sessionId,
|
|
293
|
+
activity
|
|
294
|
+
})
|
|
291
295
|
}
|
|
292
296
|
|
|
293
297
|
function clearIdle(s: LiveSession) {
|
|
@@ -372,7 +376,7 @@ function startClaudeSessionTitleJob(s: LiveSession) {
|
|
|
372
376
|
isCurrent: () => isCurrentLiveSession(s, abort)
|
|
373
377
|
})
|
|
374
378
|
if (!renamed || !isCurrentLiveSession(s, abort)) return
|
|
375
|
-
broadcast(s.workspaceId, { type: '
|
|
379
|
+
broadcast(s.workspaceId, { type: 'sessions:changed', sessionId: s.sessionId })
|
|
376
380
|
debug(
|
|
377
381
|
`cc session title ws=${s.workspaceId} session=${s.sessionId} title=${JSON.stringify(title)}`
|
|
378
382
|
)
|
|
@@ -443,7 +447,7 @@ async function consume(s: LiveSession) {
|
|
|
443
447
|
if (ev.kind === 'preview') {
|
|
444
448
|
// Token previews are transient and stay outside transcript history.
|
|
445
449
|
broadcast(s.workspaceId, {
|
|
446
|
-
type: 'preview',
|
|
450
|
+
type: 'session:preview',
|
|
447
451
|
sessionId: s.sessionId,
|
|
448
452
|
messageId: ev.preview.messageId,
|
|
449
453
|
parentToolUseId: ev.preview.parentToolUseId,
|
|
@@ -521,7 +525,7 @@ async function consume(s: LiveSession) {
|
|
|
521
525
|
debug(`cc result ws=${s.workspaceId} session=${s.sessionId} subtype=${msg.subtype}`)
|
|
522
526
|
if (s.refreshSessionsOnResult) {
|
|
523
527
|
s.refreshSessionsOnResult = false
|
|
524
|
-
broadcast(s.workspaceId, { type: '
|
|
528
|
+
broadcast(s.workspaceId, { type: 'sessions:changed', sessionId: s.sessionId })
|
|
525
529
|
}
|
|
526
530
|
// Without state events, only a result that finishes the active prompt
|
|
527
531
|
// (or an autonomous turn when none is active) can release the queue.
|
|
@@ -55,7 +55,7 @@ reach the harness's 30-second RPC timeout before Bun closes the connection.
|
|
|
55
55
|
## Session lifecycle
|
|
56
56
|
|
|
57
57
|
- A new chat starts under a temporary Moi id. `thread/start` supplies the real
|
|
58
|
-
id; `
|
|
58
|
+
id; `session:renamed` rekeys the chat, saved settings, and pending-build references.
|
|
59
59
|
- View handoffs pass the source chat's saved model to `thread/fork`. Codex 0.160.0
|
|
60
60
|
otherwise starts the fork with the configured default; switching an active-source
|
|
61
61
|
fork to `gpt-6.1-sol` on its first turn can fail with a `rustponsesapi` model error.
|