moi-computer 0.3.1-next.0 → 0.3.1-next.1
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/workspace-keys.ts +2 -2
- package/client/app/AppRouter.tsx +0 -2
- package/client/app/shell/SidebarLayout.tsx +3 -16
- package/client/assets/openai.svg +1 -3
- package/client/components/shared/Composer.tsx +53 -2
- package/client/components/ui/button.tsx +1 -1
- package/client/components/ui/tooltip.tsx +12 -15
- package/client/features/chat/ChatComposer.tsx +25 -15
- package/client/features/chat/ChatPanel.tsx +5 -2
- package/client/features/chat/MarkdownContent.tsx +20 -2
- package/client/features/chat/ModelPicker.tsx +5 -3
- package/client/features/chat/TurnView.tsx +2 -2
- package/client/features/chat/chat-frames.ts +13 -6
- package/client/features/chat/chat-send.ts +1 -1
- package/client/features/chat/chat-store.ts +22 -17
- package/client/features/chat/tool-group/ToolOutput.tsx +4 -12
- package/client/features/chat/tool-group/format.ts +0 -6
- package/client/features/chat/useChat.ts +11 -2
- package/client/features/connectors/McpServerCards.tsx +95 -0
- package/client/features/connectors/api.ts +0 -11
- package/client/features/home/HomePage.tsx +33 -28
- package/client/features/home/api.ts +24 -12
- package/client/features/home/workspace-presentation.tsx +17 -15
- package/client/features/home/workspace-setup/CreateWorkspaceDialog.tsx +243 -0
- package/client/features/home/workspace-setup/ImportWorkspaceDialog.tsx +95 -0
- package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +230 -0
- package/client/features/home/workspace-setup/WorkspaceDialogContent.tsx +35 -0
- package/client/features/home/workspace-setup/useWorkspaceImport.ts +61 -0
- package/client/features/settings/ConnectorsSettings.tsx +89 -0
- package/client/features/settings/SettingsLayout.tsx +2 -2
- package/client/features/settings/WorkspaceSettings.tsx +8 -4
- package/client/features/views/ViewBuilderTab.tsx +19 -15
- package/client/features/views/useViewBuilderActions.ts +1 -1
- package/client/features/workspace/WorkspaceLayoutContext.tsx +3 -4
- package/client/features/workspace/WorkspaceScreen.tsx +11 -3
- package/client/features/workspace/api.ts +19 -1
- package/client/features/workspace/moi-context.ts +85 -0
- package/client/main.tsx +7 -4
- package/dist/{chunk-cs8vbert.js → chunk-1dfbr7n2.js} +2 -2
- package/dist/chunk-339jds4x.js +15 -0
- package/dist/chunk-3xsvsnhr.css +1 -0
- package/dist/{chunk-zpxrb1ce.js → chunk-anqmsbjt.js} +2 -2
- package/dist/chunk-hbvfb6sk.js +63 -0
- package/dist/{chunk-kxmvv1ax.js → chunk-qwm5f6qk.js} +1 -1
- package/dist/{chunk-axszxe4c.js → chunk-sxbfh73c.js} +1 -1
- package/dist/chunk-yp4srgqt.js +10 -0
- package/dist/index.html +1 -1
- package/dist/openai-ep9ht2pq.svg +1 -0
- package/lib/ids.ts +15 -0
- package/lib/moi-context.ts +170 -0
- package/lib/types.ts +29 -11
- package/lib/view-builder-directives.ts +16 -0
- package/lib/workspace-types.ts +12 -0
- package/package.json +2 -1
- package/server/api.ts +92 -30
- package/server/harness/README.md +25 -9
- package/server/harness/claude-code/NOTES.md +20 -6
- package/server/harness/claude-code/adapter.ts +2 -2
- package/server/harness/claude-code/git-worktree.ts +32 -0
- package/server/harness/claude-code/index.ts +32 -12
- package/server/harness/claude-code/mcp.ts +16 -65
- package/server/harness/claude-code/models.ts +3 -0
- package/server/harness/claude-code/session.ts +196 -61
- package/server/harness/codex/NOTES.md +41 -11
- package/server/harness/codex/adapter.ts +21 -7
- package/server/harness/codex/client.ts +33 -17
- package/server/harness/codex/discovery.ts +114 -0
- package/server/harness/codex/index.ts +9 -5
- package/server/harness/codex/probe.ts +4 -2
- package/server/harness/codex/session.ts +57 -5
- package/server/harness/executable.ts +82 -0
- package/server/harness/openclaw/adapter.ts +8 -1
- package/server/harness/openclaw/index.ts +8 -14
- package/server/harness/openclaw/session.ts +50 -10
- package/server/harness/openclaw/strip.ts +2 -2
- package/server/harness/shell-path.ts +79 -0
- package/server/harness/types.ts +22 -5
- package/server/registry.ts +57 -12
- package/server/view-builders.ts +3 -2
- package/server/web.ts +24 -8
- package/server/workspace-import.ts +45 -0
- package/workspace/.claude/skills/moi-workspace/SKILL.md +3 -3
- package/client/features/connectors/ConnectorsPage.tsx +0 -92
- package/client/features/connectors/McpMenu.tsx +0 -145
- package/client/features/home/CreateWorkspaceDialog.tsx +0 -130
- package/client/features/home/CreateWorkspaceDialogSteps.tsx +0 -234
- package/dist/chunk-4vf1t6v1.js +0 -10
- package/dist/chunk-b3ynfk4g.js +0 -62
- package/dist/chunk-b4b276wx.js +0 -15
- package/dist/chunk-npwq6jmr.css +0 -1
- package/dist/openai-h13pza4b.svg +0 -3
- package/lib/view-builder-meta.ts +0 -35
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
selectCodexWorkspacePreview
|
|
22
22
|
} from './adapter'
|
|
23
23
|
import type { WorkspaceActivityPreview } from '../types'
|
|
24
|
+
import { findHarnessExecutable, requireHarnessExecutable } from '../executable'
|
|
24
25
|
import { debug } from '../../debug'
|
|
25
26
|
import { tapWire } from '../debug'
|
|
26
27
|
import { resolveWorkspaceEnv } from '../../workspace-env'
|
|
@@ -42,7 +43,7 @@ export type CodexProcessInfo = {
|
|
|
42
43
|
|
|
43
44
|
export function getCodexProcessInfo(workspacePath: string): Promise<CodexProcessInfo> {
|
|
44
45
|
const rec = clients.get(workspacePath)
|
|
45
|
-
const binary =
|
|
46
|
+
const binary = findHarnessExecutable('codex')
|
|
46
47
|
if (!rec) return Promise.resolve({ running: false, binary })
|
|
47
48
|
return rec
|
|
48
49
|
.then(r => ({ running: r.client.isAlive(), pid: r.proc.pid, binary }))
|
|
@@ -54,14 +55,27 @@ export type CodexClient = {
|
|
|
54
55
|
onNotification: (l: NotificationListener) => () => void
|
|
55
56
|
isAlive: () => boolean
|
|
56
57
|
workspacePath: string
|
|
58
|
+
// Whether this app-server accepts `turn/start.additionalContext` (the native
|
|
59
|
+
// per-turn context channel). Resolved from the initialize handshake.
|
|
60
|
+
supportsAdditionalContext: boolean
|
|
57
61
|
}
|
|
58
62
|
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
// `additionalContext` shipped in codex 0.135.0 (openai/codex#24154, May 2026).
|
|
64
|
+
// Older servers have no `deny_unknown_fields` on TurnStartParams, so they
|
|
65
|
+
// silently DROP the field instead of erroring — probing is useless. The only
|
|
66
|
+
// reliable signal is the version embedded in the initialize response's
|
|
67
|
+
// userAgent (e.g. `codex_cli_rs/0.144.5 (…)`); an unparsable userAgent gates
|
|
68
|
+
// to false and the session path falls back to appending context to the text.
|
|
69
|
+
const ADDITIONAL_CONTEXT_MIN_VERSION = [0, 135, 0] as const
|
|
70
|
+
|
|
71
|
+
export function codexSupportsAdditionalContext(userAgent: string | undefined): boolean {
|
|
72
|
+
const m = userAgent?.match(/\/(\d+)\.(\d+)\.(\d+)/)
|
|
73
|
+
if (!m) return false
|
|
74
|
+
const v = [Number(m[1]), Number(m[2]), Number(m[3])]
|
|
75
|
+
for (let i = 0; i < 3; i++) {
|
|
76
|
+
if (v[i] !== ADDITIONAL_CONTEXT_MIN_VERSION[i]) return v[i] > ADDITIONAL_CONTEXT_MIN_VERSION[i]
|
|
77
|
+
}
|
|
78
|
+
return true
|
|
65
79
|
}
|
|
66
80
|
|
|
67
81
|
type ClientRecord = {
|
|
@@ -72,12 +86,7 @@ type ClientRecord = {
|
|
|
72
86
|
const clients = new Map<string, Promise<ClientRecord>>() // key: workspacePath
|
|
73
87
|
|
|
74
88
|
async function startClient(workspacePath: string): Promise<ClientRecord> {
|
|
75
|
-
const bin =
|
|
76
|
-
if (!bin) {
|
|
77
|
-
throw new Error(
|
|
78
|
-
'codex CLI not found — install it (`npm i -g @openai/codex`) or set CODEX_CLI_PATH'
|
|
79
|
-
)
|
|
80
|
-
}
|
|
89
|
+
const bin = requireHarnessExecutable('codex')
|
|
81
90
|
|
|
82
91
|
const workspaceEnv = await resolveWorkspaceEnv(workspacePath)
|
|
83
92
|
const proc = Bun.spawn([bin, 'app-server'], {
|
|
@@ -218,7 +227,8 @@ async function startClient(workspacePath: string): Promise<ClientRecord> {
|
|
|
218
227
|
return () => listeners.delete(l)
|
|
219
228
|
},
|
|
220
229
|
isAlive: () => alive,
|
|
221
|
-
workspacePath
|
|
230
|
+
workspacePath,
|
|
231
|
+
supportsAdditionalContext: false
|
|
222
232
|
}
|
|
223
233
|
const record: ClientRecord = { client, proc }
|
|
224
234
|
const recordPromise = Promise.resolve(record)
|
|
@@ -226,12 +236,18 @@ async function startClient(workspacePath: string): Promise<ClientRecord> {
|
|
|
226
236
|
void readLoop()
|
|
227
237
|
void drainStderr()
|
|
228
238
|
|
|
229
|
-
|
|
239
|
+
// experimentalApi opts this connection into experimental fields — required
|
|
240
|
+
// for `turn/start.additionalContext`; servers new enough to gate it reject
|
|
241
|
+
// the field otherwise. The response's userAgent carries the CLI version.
|
|
242
|
+
const init = await rpc<{ userAgent?: string }>('initialize', {
|
|
230
243
|
clientInfo: { name: 'moi', title: 'moi', version: '0.1' },
|
|
231
|
-
capabilities: { experimentalApi:
|
|
244
|
+
capabilities: { experimentalApi: true, requestAttestation: false }
|
|
232
245
|
})
|
|
246
|
+
client.supportsAdditionalContext = codexSupportsAdditionalContext(init?.userAgent)
|
|
233
247
|
send({ jsonrpc: '2.0', method: 'initialized', params: {} })
|
|
234
|
-
debug(
|
|
248
|
+
debug(
|
|
249
|
+
`codex app-server started ws=${workspacePath} bin=${bin} ua=${init?.userAgent ?? 'unknown'} additionalContext=${client.supportsAdditionalContext}`
|
|
250
|
+
)
|
|
235
251
|
return record
|
|
236
252
|
}
|
|
237
253
|
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// Discover directories the Codex CLI has run in, for the home page's
|
|
2
|
+
// "Import from this computer" list.
|
|
3
|
+
//
|
|
4
|
+
// Codex persists every thread as a rollout file under
|
|
5
|
+
// `~/.codex/sessions/YYYY/MM/DD/rollout-<timestamp>-<uuid>.jsonl`, whose FIRST
|
|
6
|
+
// line is a `session_meta` record carrying the thread's `cwd`. Reading those
|
|
7
|
+
// heads directly (no app-server spawn, no codex binary needed) mirrors how the
|
|
8
|
+
// Claude Code harness scans its own session history — discovery still works
|
|
9
|
+
// when the CLI has since been uninstalled.
|
|
10
|
+
import { readdir, stat } from 'node:fs/promises'
|
|
11
|
+
import { homedir } from 'node:os'
|
|
12
|
+
import { isAbsolute, join } from 'node:path'
|
|
13
|
+
|
|
14
|
+
import type { DiscoveredWorkspaceCandidate } from '../types'
|
|
15
|
+
|
|
16
|
+
export const CODEX_SESSIONS_ROOT = join(homedir(), '.codex', 'sessions')
|
|
17
|
+
|
|
18
|
+
// Newest files scanned per discovery pass. Session dirs grow unboundedly; the
|
|
19
|
+
// most recent rollouts cover every workspace anyone still cares about.
|
|
20
|
+
const SCAN_LIMIT = 400
|
|
21
|
+
// The session_meta line is small (id/cwd/timestamps), but read a generous head
|
|
22
|
+
// in case a Codex version inlines instructions into it.
|
|
23
|
+
const HEAD_BYTES = 64 * 1024
|
|
24
|
+
|
|
25
|
+
type SessionMeta = { cwd: string; timestamp?: string }
|
|
26
|
+
|
|
27
|
+
// Parse the first line of a rollout file. Formats differ across CLI versions
|
|
28
|
+
// ({type:'session_meta', payload:{cwd}} vs a flat meta object), so accept both
|
|
29
|
+
// and fall back to a regex when the head truncates mid-JSON.
|
|
30
|
+
async function readSessionMeta(file: string): Promise<SessionMeta | null> {
|
|
31
|
+
let head: string
|
|
32
|
+
try {
|
|
33
|
+
head = await Bun.file(file).slice(0, HEAD_BYTES).text()
|
|
34
|
+
} catch {
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
const nl = head.indexOf('\n')
|
|
38
|
+
const line = nl >= 0 ? head.slice(0, nl) : head
|
|
39
|
+
try {
|
|
40
|
+
const parsed = JSON.parse(line) as {
|
|
41
|
+
timestamp?: string
|
|
42
|
+
cwd?: string
|
|
43
|
+
payload?: { cwd?: string; timestamp?: string }
|
|
44
|
+
}
|
|
45
|
+
const cwd = parsed.payload?.cwd ?? parsed.cwd
|
|
46
|
+
// isAbsolute (not a '/' check) so Windows drive-letter cwds survive.
|
|
47
|
+
if (typeof cwd === 'string' && isAbsolute(cwd)) {
|
|
48
|
+
const timestamp = parsed.payload?.timestamp ?? parsed.timestamp
|
|
49
|
+
return { cwd, ...(typeof timestamp === 'string' ? { timestamp } : {}) }
|
|
50
|
+
}
|
|
51
|
+
} catch {
|
|
52
|
+
// Truncated head: pull the quoted cwd value out and JSON-parse just the
|
|
53
|
+
// string so escapes (Windows "C:\\...") decode correctly.
|
|
54
|
+
const m = line.match(/"cwd"\s*:\s*("(?:[^"\\]|\\.)*")/)
|
|
55
|
+
if (m) {
|
|
56
|
+
try {
|
|
57
|
+
const cwd = JSON.parse(m[1]) as string
|
|
58
|
+
if (isAbsolute(cwd)) return { cwd }
|
|
59
|
+
} catch {}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return null
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Up to `limit` rollout files under the date-partitioned tree, newest first.
|
|
66
|
+
// Directory names are zero-padded dates and filenames embed ISO timestamps,
|
|
67
|
+
// so descending name order at every level IS reverse-chronological order —
|
|
68
|
+
// which lets the walk stop at the cap instead of traversing (and sorting)
|
|
69
|
+
// the entire unbounded history first.
|
|
70
|
+
async function listRolloutFiles(root: string, limit: number): Promise<string[]> {
|
|
71
|
+
const out: string[] = []
|
|
72
|
+
async function walk(dir: string) {
|
|
73
|
+
let entries
|
|
74
|
+
try {
|
|
75
|
+
entries = await readdir(dir, { withFileTypes: true })
|
|
76
|
+
} catch {
|
|
77
|
+
return
|
|
78
|
+
}
|
|
79
|
+
entries.sort((a, b) => (a.name < b.name ? 1 : -1))
|
|
80
|
+
for (const e of entries) {
|
|
81
|
+
if (out.length >= limit) return
|
|
82
|
+
const p = join(dir, e.name)
|
|
83
|
+
if (e.isDirectory()) await walk(p)
|
|
84
|
+
else if (e.isFile() && e.name.endsWith('.jsonl')) out.push(p)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
await walk(root)
|
|
88
|
+
return out
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export async function discoverCodexWorkspaces(
|
|
92
|
+
registeredPaths: Set<string>,
|
|
93
|
+
sessionsRoot: string = CODEX_SESSIONS_ROOT
|
|
94
|
+
): Promise<DiscoveredWorkspaceCandidate[]> {
|
|
95
|
+
const files = await listRolloutFiles(sessionsRoot, SCAN_LIMIT)
|
|
96
|
+
// Newest-first scan: only the first rollout seen per cwd is needed.
|
|
97
|
+
const byCwd = new Map<string, string | undefined>()
|
|
98
|
+
for (const file of files) {
|
|
99
|
+
const meta = await readSessionMeta(file)
|
|
100
|
+
if (!meta || byCwd.has(meta.cwd)) continue
|
|
101
|
+
byCwd.set(meta.cwd, meta.timestamp)
|
|
102
|
+
}
|
|
103
|
+
const out: DiscoveredWorkspaceCandidate[] = []
|
|
104
|
+
for (const cwd of byCwd.keys()) {
|
|
105
|
+
if (registeredPaths.has(cwd)) continue
|
|
106
|
+
try {
|
|
107
|
+
if (!(await stat(cwd)).isDirectory()) continue
|
|
108
|
+
} catch {
|
|
109
|
+
continue // directory deleted since the session ran
|
|
110
|
+
}
|
|
111
|
+
out.push({ path: cwd, type: 'codex' })
|
|
112
|
+
}
|
|
113
|
+
return out
|
|
114
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Codex as a Harness. Thin wiring over this folder's modules — see
|
|
2
2
|
// ../types.ts for the contract and ../README.md for the architecture.
|
|
3
3
|
import type { Harness } from '../types'
|
|
4
|
+
import { pathHarnessAvailability } from '../executable'
|
|
4
5
|
import {
|
|
5
6
|
getCodexMcpStatus,
|
|
6
7
|
getCodexModels,
|
|
@@ -11,9 +12,10 @@ import {
|
|
|
11
12
|
killAllCodexClients,
|
|
12
13
|
killCodexWorkspace
|
|
13
14
|
} from './client'
|
|
15
|
+
import { discoverCodexWorkspaces } from './discovery'
|
|
14
16
|
import {
|
|
15
17
|
ensureCodexSessionLive,
|
|
16
|
-
|
|
18
|
+
getCodexActiveSessions,
|
|
17
19
|
getLiveCodexEvents,
|
|
18
20
|
interruptCodexRun,
|
|
19
21
|
sendCodexMessage
|
|
@@ -31,7 +33,7 @@ export const codexHarness: Harness = {
|
|
|
31
33
|
|
|
32
34
|
sendMessage: input => sendCodexMessage(input),
|
|
33
35
|
interrupt: (workspaceId, sessionId) => interruptCodexRun({ workspaceId, sessionId }),
|
|
34
|
-
|
|
36
|
+
activeSessions: () => getCodexActiveSessions(),
|
|
35
37
|
|
|
36
38
|
listSessions: ws => getCodexSessions(ws.path),
|
|
37
39
|
workspacePreview: (ws, includeFirstUserMessage) =>
|
|
@@ -54,6 +56,8 @@ export const codexHarness: Harness = {
|
|
|
54
56
|
},
|
|
55
57
|
listModels: ws => getCodexModels(ws.path),
|
|
56
58
|
mcpStatus: ws => getCodexMcpStatus(ws.path),
|
|
59
|
+
discoverWorkspaces: registeredPaths => discoverCodexWorkspaces(registeredPaths),
|
|
60
|
+
availability: async () => pathHarnessAvailability('codex'),
|
|
57
61
|
|
|
58
62
|
onEnvChanged: workspacePath => killCodexWorkspace(workspacePath),
|
|
59
63
|
shutdown: () => killAllCodexClients(),
|
|
@@ -62,10 +66,10 @@ export const codexHarness: Harness = {
|
|
|
62
66
|
wireScope: ws => ws.path,
|
|
63
67
|
|
|
64
68
|
statusLines: () => {
|
|
65
|
-
const
|
|
69
|
+
const active = getCodexActiveSessions()
|
|
66
70
|
return [
|
|
67
|
-
`live Codex runs ${
|
|
68
|
-
...
|
|
71
|
+
`live Codex runs ${active.length}`,
|
|
72
|
+
...active.map(r => ` ▶ busy ws=${r.workspaceId} session=${r.sessionId}`)
|
|
69
73
|
]
|
|
70
74
|
}
|
|
71
75
|
}
|
|
@@ -32,9 +32,11 @@ const [cmd = 'chat', ...rest] = positional
|
|
|
32
32
|
const asJson = flags.get('json') === 'true'
|
|
33
33
|
const timeoutSec = Number(flags.get('timeout') ?? 120)
|
|
34
34
|
|
|
35
|
-
const bin =
|
|
35
|
+
const bin = Bun.which('codex')
|
|
36
36
|
if (!bin) {
|
|
37
|
-
console.error(
|
|
37
|
+
console.error(
|
|
38
|
+
'Run curl -fsSL https://chatgpt.com/codex/install.sh | sh in your terminal to install Codex'
|
|
39
|
+
)
|
|
38
40
|
process.exit(1)
|
|
39
41
|
}
|
|
40
42
|
|
|
@@ -16,8 +16,14 @@
|
|
|
16
16
|
// `clientUserMessageId` as `clientId`, so the optimistic-id rendezvous is
|
|
17
17
|
// first-class (no text matching like OpenClaw needs).
|
|
18
18
|
import { appendAttachmentNote } from '@/lib/attachment-note'
|
|
19
|
+
import {
|
|
20
|
+
type MoiContext,
|
|
21
|
+
appendMoiContext,
|
|
22
|
+
renderMoiContext,
|
|
23
|
+
renderMoiContextBody
|
|
24
|
+
} from '@/lib/moi-context'
|
|
19
25
|
import { type Part, type SubagentRecord, type Turn, applyEvent, emptyViewState } from '@/lib/format'
|
|
20
|
-
import type { StreamEvent, ViewState } from '@/lib/types'
|
|
26
|
+
import type { SessionActivity, StreamEvent, ViewState } from '@/lib/types'
|
|
21
27
|
|
|
22
28
|
import {
|
|
23
29
|
type CodexThread,
|
|
@@ -91,10 +97,20 @@ function liveKey(workspaceId: string, sessionId: string): string {
|
|
|
91
97
|
return real ? recKey(workspaceId, real) : direct
|
|
92
98
|
}
|
|
93
99
|
|
|
94
|
-
export function
|
|
95
|
-
|
|
100
|
+
export function getCodexActiveSessions(): {
|
|
101
|
+
workspaceId: string
|
|
102
|
+
sessionId: string
|
|
103
|
+
activity: SessionActivity
|
|
104
|
+
}[] {
|
|
105
|
+
const out: { workspaceId: string; sessionId: string; activity: SessionActivity }[] = []
|
|
96
106
|
for (const s of sessions.values()) {
|
|
97
|
-
|
|
107
|
+
// Codex never surfaces `requires-action`: approvals are designed out
|
|
108
|
+
// (APPROVAL_POLICY 'never' + transport auto-accept in client.ts). If that
|
|
109
|
+
// policy is ever relaxed, `*requestApproval` / `elicitation` server
|
|
110
|
+
// requests are the signals to map to it.
|
|
111
|
+
if (s.processing) {
|
|
112
|
+
out.push({ workspaceId: s.workspaceId, sessionId: s.sessionId, activity: 'running' })
|
|
113
|
+
}
|
|
98
114
|
}
|
|
99
115
|
return out
|
|
100
116
|
}
|
|
@@ -103,7 +119,11 @@ function setProcessing(rec: SessionRecord, processing: boolean, turnId: string |
|
|
|
103
119
|
rec.activeTurnId = turnId
|
|
104
120
|
if (rec.processing === processing) return
|
|
105
121
|
rec.processing = processing
|
|
106
|
-
broadcast(rec.workspaceId, {
|
|
122
|
+
broadcast(rec.workspaceId, {
|
|
123
|
+
type: 'status',
|
|
124
|
+
sessionId: rec.sessionId,
|
|
125
|
+
activity: processing ? 'running' : 'idle'
|
|
126
|
+
})
|
|
107
127
|
}
|
|
108
128
|
|
|
109
129
|
function emitTurnEvent(rec: SessionRecord, ev: StreamEvent) {
|
|
@@ -290,6 +310,11 @@ function handleNotification(rec: SessionRecord, method: string, params: Record<s
|
|
|
290
310
|
content: turn.error.message
|
|
291
311
|
})
|
|
292
312
|
}
|
|
313
|
+
// An externally-interrupted turn otherwise ends silently, identical to a
|
|
314
|
+
// clean completion — surface the stop so the client can render it.
|
|
315
|
+
if (turn?.status === 'interrupted') {
|
|
316
|
+
broadcast(rec.workspaceId, { kind: 'stopped', sessionId: rec.sessionId })
|
|
317
|
+
}
|
|
293
318
|
return
|
|
294
319
|
}
|
|
295
320
|
case 'error': {
|
|
@@ -298,6 +323,9 @@ function handleNotification(rec: SessionRecord, method: string, params: Record<s
|
|
|
298
323
|
if (message) {
|
|
299
324
|
broadcast(rec.workspaceId, { kind: 'error', sessionId: rec.sessionId, content: message })
|
|
300
325
|
}
|
|
326
|
+
// A top-level error without a following turn/completed would otherwise
|
|
327
|
+
// leave the session busy forever — the error is terminal for the turn.
|
|
328
|
+
setProcessing(rec, false, null)
|
|
301
329
|
return
|
|
302
330
|
}
|
|
303
331
|
// Codex hooks (~/.codex/hooks.json) — surface as hook notices, parity
|
|
@@ -452,6 +480,11 @@ export async function sendCodexMessage(input: {
|
|
|
452
480
|
model?: string
|
|
453
481
|
effort?: string
|
|
454
482
|
stream?: boolean
|
|
483
|
+
// Structured moi context (lib/moi-context.ts), rendered here. Servers
|
|
484
|
+
// >= 0.135 take it via `additionalContext` (never enters userMessage
|
|
485
|
+
// items); older ones get it appended to the text item, stripped from
|
|
486
|
+
// echoes by the adapter.
|
|
487
|
+
context?: MoiContext
|
|
455
488
|
}): Promise<void> {
|
|
456
489
|
const uploads = input.attachments?.length
|
|
457
490
|
? resolveUploads(input.workspaceId, input.attachments)
|
|
@@ -496,6 +529,9 @@ export async function sendCodexMessage(input: {
|
|
|
496
529
|
rec = await resumeSession(input)
|
|
497
530
|
}
|
|
498
531
|
} catch (err) {
|
|
532
|
+
// No session record exists to run setProcessing through — clear the
|
|
533
|
+
// client's optimistic spinner explicitly or it sticks until reconnect.
|
|
534
|
+
broadcast(input.workspaceId, { type: 'status', sessionId: input.sessionId, activity: 'idle' })
|
|
499
535
|
broadcast(input.workspaceId, {
|
|
500
536
|
kind: 'error',
|
|
501
537
|
sessionId: input.sessionId,
|
|
@@ -524,10 +560,25 @@ export async function sendCodexMessage(input: {
|
|
|
524
560
|
setProcessing(rec, true, rec.activeTurnId)
|
|
525
561
|
try {
|
|
526
562
|
const client = await getCodexClient(input.workspacePath)
|
|
563
|
+
// Native context channel: diffed per key server-side (unchanged values
|
|
564
|
+
// inject nothing) and never echoed back in userMessage items. The entry
|
|
565
|
+
// key becomes the tag, so ship the unwrapped body. Older servers silently
|
|
566
|
+
// drop the field, so append to the text item there instead.
|
|
567
|
+
const additionalContext =
|
|
568
|
+
input.context && client.supportsAdditionalContext
|
|
569
|
+
? { 'moi-context': { value: renderMoiContextBody(input.context), kind: 'application' } }
|
|
570
|
+
: undefined
|
|
571
|
+
if (input.context && !additionalContext) {
|
|
572
|
+
const envelope = renderMoiContext(input.context)
|
|
573
|
+
const last = userInput[userInput.length - 1]
|
|
574
|
+
if (last?.type === 'text') last.text = appendMoiContext(last.text, envelope)
|
|
575
|
+
else userInput.push({ type: 'text', text: envelope })
|
|
576
|
+
}
|
|
527
577
|
const turnParams = {
|
|
528
578
|
threadId: rec.sessionId,
|
|
529
579
|
clientUserMessageId: turnId,
|
|
530
580
|
input: userInput,
|
|
581
|
+
...(additionalContext ? { additionalContext } : {}),
|
|
531
582
|
// Without an explicit summary mode Codex still reasons but emits the
|
|
532
583
|
// reasoning item with EMPTY summary/content (verified on the wire —
|
|
533
584
|
// scripts/codex-probe.ts), so no thinking ever reaches the UI. 'auto'
|
|
@@ -545,6 +596,7 @@ export async function sendCodexMessage(input: {
|
|
|
545
596
|
threadId: rec.sessionId,
|
|
546
597
|
clientUserMessageId: turnId,
|
|
547
598
|
input: userInput,
|
|
599
|
+
...(additionalContext ? { additionalContext } : {}),
|
|
548
600
|
expectedTurnId: rec.activeTurnId
|
|
549
601
|
})
|
|
550
602
|
} catch {
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { accessSync, constants, statSync } from 'node:fs'
|
|
2
|
+
|
|
3
|
+
import type { HarnessAvailability, WorkspaceType } from '@/lib/types'
|
|
4
|
+
|
|
5
|
+
import { cachedLoginShellPath, loginShellPath, mergeSearchPaths } from './shell-path'
|
|
6
|
+
|
|
7
|
+
type PathWorkspaceType = Extract<WorkspaceType, 'claude-code' | 'codex'>
|
|
8
|
+
|
|
9
|
+
type ExecutableConfig = {
|
|
10
|
+
command: string
|
|
11
|
+
unavailableReason: string
|
|
12
|
+
// Absolute locations probed when the PATH lookup misses. PATH wins, so a
|
|
13
|
+
// deliberately installed CLI is never shadowed by an app-bundled copy.
|
|
14
|
+
fallbackPaths?: readonly string[]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const executableConfig: Record<PathWorkspaceType, ExecutableConfig> = {
|
|
18
|
+
'claude-code': {
|
|
19
|
+
command: 'claude',
|
|
20
|
+
unavailableReason:
|
|
21
|
+
'Run curl -fsSL https://claude.ai/install.sh | sh in your terminal to install Claude'
|
|
22
|
+
},
|
|
23
|
+
codex: {
|
|
24
|
+
command: 'codex',
|
|
25
|
+
// Codex Desktop manages an app-internal binary and does not put `codex`
|
|
26
|
+
// on PATH: probe the known macOS bundle locations (ChatGPT.app is the
|
|
27
|
+
// current home, Codex.app the legacy standalone install).
|
|
28
|
+
fallbackPaths: [
|
|
29
|
+
'/Applications/ChatGPT.app/Contents/Resources/codex',
|
|
30
|
+
'/Applications/Codex.app/Contents/Resources/codex'
|
|
31
|
+
],
|
|
32
|
+
unavailableReason:
|
|
33
|
+
'Run curl -fsSL https://chatgpt.com/codex/install.sh | sh in your terminal to install Codex'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Resolve the login-shell PATH eagerly so sync lookups on the spawn path see
|
|
38
|
+
// it settled long before the first session starts.
|
|
39
|
+
void loginShellPath()
|
|
40
|
+
|
|
41
|
+
function isExecutableFile(path: string): boolean {
|
|
42
|
+
try {
|
|
43
|
+
accessSync(path, constants.X_OK)
|
|
44
|
+
return statSync(path).isFile()
|
|
45
|
+
} catch {
|
|
46
|
+
return false
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function firstExecutable(paths: readonly string[]): string | null {
|
|
51
|
+
return paths.find(isExecutableFile) ?? null
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// `path` is a test seam: when given, only that PATH is searched — no
|
|
55
|
+
// login-shell merge, no bundle fallbacks.
|
|
56
|
+
export function findHarnessExecutable(type: PathWorkspaceType, path?: string): string | null {
|
|
57
|
+
const config = executableConfig[type]
|
|
58
|
+
if (path !== undefined) return Bun.which(config.command, { PATH: path })
|
|
59
|
+
return (
|
|
60
|
+
Bun.which(config.command, {
|
|
61
|
+
PATH: mergeSearchPaths(cachedLoginShellPath(), process.env.PATH)
|
|
62
|
+
}) ?? firstExecutable(config.fallbackPaths ?? [])
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function requireHarnessExecutable(type: PathWorkspaceType, path?: string): string {
|
|
67
|
+
const executable = findHarnessExecutable(type, path)
|
|
68
|
+
if (!executable) throw new Error(executableConfig[type].unavailableReason)
|
|
69
|
+
return executable
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export async function pathHarnessAvailability(
|
|
73
|
+
type: PathWorkspaceType,
|
|
74
|
+
path?: string
|
|
75
|
+
): Promise<HarnessAvailability> {
|
|
76
|
+
// Availability is asked per request (and long after startup), but await the
|
|
77
|
+
// probe anyway so the very first request can't report a false negative.
|
|
78
|
+
if (path === undefined) await loginShellPath()
|
|
79
|
+
return findHarnessExecutable(type, path)
|
|
80
|
+
? { available: true }
|
|
81
|
+
: { available: false, reason: executableConfig[type].unavailableReason }
|
|
82
|
+
}
|
|
@@ -25,11 +25,18 @@ import type {
|
|
|
25
25
|
OpenClawSessionDetail,
|
|
26
26
|
OpenClawSessionRow
|
|
27
27
|
} from './discovery'
|
|
28
|
+
import { stripMoiContextLoose } from '@/lib/moi-context'
|
|
28
29
|
import { stripUserMessageMetadata } from './strip'
|
|
29
30
|
|
|
30
31
|
export function toSessionInfo(row: OpenClawSessionRow, cwd: string): SessionInfo {
|
|
32
|
+
// Gateway previews carry the raw stored message — for a user send that
|
|
33
|
+
// includes the appended context envelope, and truncation can cut it open,
|
|
34
|
+
// so clean with the loose strip like the Codex previews do.
|
|
31
35
|
const summary =
|
|
32
|
-
row.lastMessagePreview
|
|
36
|
+
stripMoiContextLoose(row.lastMessagePreview ?? '').trim() ||
|
|
37
|
+
row.displayName?.trim() ||
|
|
38
|
+
row.label?.trim() ||
|
|
39
|
+
''
|
|
33
40
|
return {
|
|
34
41
|
sessionId: row.sessionId,
|
|
35
42
|
summary,
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
// OpenClaw as a Harness. Thin wiring over this folder's modules — see
|
|
2
2
|
// ../types.ts for the contract and ../README.md for the architecture.
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
import type { Harness } from '../types'
|
|
3
|
+
import type { DiscoveredWorkspaceCandidate, Harness } from '../types'
|
|
6
4
|
import { toSessionInfo, toStreamEvents } from './adapter'
|
|
7
5
|
import {
|
|
8
6
|
discoverOpenClawAgents,
|
|
@@ -15,7 +13,7 @@ import {
|
|
|
15
13
|
abortOpenClawRun,
|
|
16
14
|
ensureOpenClawSessionLive,
|
|
17
15
|
getLiveOpenClawEvents,
|
|
18
|
-
|
|
16
|
+
getOpenClawActiveSessions,
|
|
19
17
|
sendOpenClawMessage
|
|
20
18
|
} from './session'
|
|
21
19
|
|
|
@@ -36,7 +34,7 @@ export const openclawHarness: Harness = {
|
|
|
36
34
|
return sendOpenClawMessage({ ...input, agentId: input.agentId })
|
|
37
35
|
},
|
|
38
36
|
interrupt: (workspaceId, sessionId) => abortOpenClawRun({ workspaceId, sessionId }),
|
|
39
|
-
|
|
37
|
+
activeSessions: () => getOpenClawActiveSessions(),
|
|
40
38
|
|
|
41
39
|
listSessions: async ws => {
|
|
42
40
|
const rows = await getOpenClawSessions(ws.path, ws.agentId)
|
|
@@ -73,13 +71,9 @@ export const openclawHarness: Harness = {
|
|
|
73
71
|
return agents
|
|
74
72
|
.filter(a => !registeredPaths.has(a.path))
|
|
75
73
|
.map(
|
|
76
|
-
(a):
|
|
74
|
+
(a): DiscoveredWorkspaceCandidate => ({
|
|
77
75
|
path: a.path,
|
|
78
|
-
type: 'openclaw'
|
|
79
|
-
...(a.name ? { name: a.name } : {}),
|
|
80
|
-
...(a.agentId ? { agentId: a.agentId } : {}),
|
|
81
|
-
...(a.isDefault ? { isDefault: a.isDefault } : {}),
|
|
82
|
-
...(a.lastRunAt ? { lastRunAt: a.lastRunAt } : {})
|
|
76
|
+
type: 'openclaw'
|
|
83
77
|
})
|
|
84
78
|
)
|
|
85
79
|
},
|
|
@@ -87,10 +81,10 @@ export const openclawHarness: Harness = {
|
|
|
87
81
|
skillsDir: workspaceRoot => `${workspaceRoot}/skills`,
|
|
88
82
|
|
|
89
83
|
statusLines: () => {
|
|
90
|
-
const
|
|
84
|
+
const active = getOpenClawActiveSessions()
|
|
91
85
|
return [
|
|
92
|
-
`live OpenClaw runs ${
|
|
93
|
-
...
|
|
86
|
+
`live OpenClaw runs ${active.length}`,
|
|
87
|
+
...active.map(r => ` ▶ busy ws=${r.workspaceId} session=${r.sessionId}`)
|
|
94
88
|
]
|
|
95
89
|
}
|
|
96
90
|
}
|