moi-computer 0.3.1-next.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -12
- 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 +22 -7
- 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/dev/HarnessDebugPage.tsx +210 -74
- 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 +16 -5
- package/dist/chunk-19g80zc9.css +1 -0
- package/dist/{chunk-jen6xcm1.js → chunk-2vaafjp4.js} +1 -1
- package/dist/{chunk-vkvb3hjm.js → chunk-35fq49qa.js} +1 -1
- package/dist/chunk-69nhbjhy.js +50 -0
- package/dist/{chunk-axszxe4c.js → chunk-72atbmh3.js} +1 -1
- package/dist/{chunk-zpxrb1ce.js → chunk-7mkv2gr0.js} +2 -2
- package/dist/{chunk-cs8vbert.js → chunk-fh2mf6v9.js} +3 -3
- package/dist/chunk-gt7n06ef.js +1 -0
- package/dist/chunk-jwmc32rp.js +63 -0
- package/dist/chunk-kh24bstm.js +10 -0
- package/dist/chunk-sfa4mbmx.js +15 -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 +33 -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 +121 -16
- package/server/harness/codex/client.ts +67 -18
- package/server/harness/codex/discovery.ts +114 -0
- package/server/harness/codex/index.ts +10 -5
- package/server/harness/codex/probe.ts +4 -2
- package/server/harness/codex/session.ts +89 -13
- 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-6c8cwpzc.js +0 -1
- package/dist/chunk-b3ynfk4g.js +0 -62
- package/dist/chunk-b4b276wx.js +0 -15
- package/dist/chunk-kxmvv1ax.js +0 -48
- package/dist/chunk-npwq6jmr.css +0 -1
- package/dist/openai-h13pza4b.svg +0 -3
- package/lib/view-builder-meta.ts +0 -35
|
@@ -8,7 +8,16 @@
|
|
|
8
8
|
//
|
|
9
9
|
// Type shapes are hand-written against `codex app-server generate-ts`
|
|
10
10
|
// (CLI 0.144.5) and read defensively — see ./NOTES.md.
|
|
11
|
-
import type {
|
|
11
|
+
import type {
|
|
12
|
+
Part,
|
|
13
|
+
StreamEvent,
|
|
14
|
+
SubagentRecord,
|
|
15
|
+
SystemNotice,
|
|
16
|
+
ToolCall,
|
|
17
|
+
ToolState,
|
|
18
|
+
Turn
|
|
19
|
+
} from '@/lib/format'
|
|
20
|
+
import { stripMoiContext, stripMoiContextLoose } from '@/lib/moi-context'
|
|
12
21
|
import type { Model, SessionInfo } from '@/lib/types'
|
|
13
22
|
|
|
14
23
|
import type { WorkspaceActivityPreview } from '../types'
|
|
@@ -75,6 +84,7 @@ export type CodexTurn = {
|
|
|
75
84
|
items: CodexThreadItem[]
|
|
76
85
|
status: string
|
|
77
86
|
error?: { message?: string; codexErrorInfo?: unknown } | null
|
|
87
|
+
durationMs?: number | null
|
|
78
88
|
}
|
|
79
89
|
|
|
80
90
|
export type CodexThread = {
|
|
@@ -84,6 +94,7 @@ export type CodexThread = {
|
|
|
84
94
|
createdAt?: number
|
|
85
95
|
updatedAt?: number
|
|
86
96
|
name?: string | null
|
|
97
|
+
status?: { type?: string }
|
|
87
98
|
turns?: CodexTurn[]
|
|
88
99
|
}
|
|
89
100
|
|
|
@@ -105,10 +116,18 @@ export type CodexModel = {
|
|
|
105
116
|
|
|
106
117
|
// ---- discovery mappings ------------------------------------------------------
|
|
107
118
|
|
|
119
|
+
// `thread/list.preview` snippets come from the raw first user message — on
|
|
120
|
+
// the pre-0.135 fallback path that text carries the appended context envelope,
|
|
121
|
+
// so previews strip it like transcript turns do. Loose variant: previews are
|
|
122
|
+
// truncated snippets, so a mid-envelope cut must still strip.
|
|
123
|
+
function cleanPreview(preview: string | undefined): string {
|
|
124
|
+
return preview ? stripMoiContextLoose(preview).trim() : ''
|
|
125
|
+
}
|
|
126
|
+
|
|
108
127
|
export function codexThreadToSessionInfo(t: CodexThread): SessionInfo {
|
|
109
128
|
return {
|
|
110
129
|
sessionId: t.id,
|
|
111
|
-
summary: t.name?.trim() || t.preview
|
|
130
|
+
summary: t.name?.trim() || cleanPreview(t.preview),
|
|
112
131
|
// Codex timestamps are unix seconds; SessionInfo wants millis.
|
|
113
132
|
lastModified: (t.updatedAt ?? t.createdAt ?? 0) * 1000,
|
|
114
133
|
cwd: t.cwd
|
|
@@ -136,7 +155,7 @@ export function selectCodexWorkspacePreview(
|
|
|
136
155
|
(a.createdAt ?? a.updatedAt ?? 0) - (b.createdAt ?? b.updatedAt ?? 0) ||
|
|
137
156
|
a.id.localeCompare(b.id)
|
|
138
157
|
)[0]
|
|
139
|
-
firstUserMessage = oldest?.preview
|
|
158
|
+
firstUserMessage = cleanPreview(oldest?.preview) || undefined
|
|
140
159
|
}
|
|
141
160
|
|
|
142
161
|
return {
|
|
@@ -147,16 +166,17 @@ export function selectCodexWorkspacePreview(
|
|
|
147
166
|
|
|
148
167
|
export function codexModelToModel(m: CodexModel): Model {
|
|
149
168
|
const efforts = (m.supportedReasoningEfforts ?? []).map(e => e.reasoningEffort)
|
|
169
|
+
const displayName = m.displayName.replace(/^GPT-/, '').replaceAll('-', ' ')
|
|
150
170
|
return {
|
|
151
171
|
value: m.id,
|
|
152
172
|
resolvedModel: m.model,
|
|
153
|
-
displayName
|
|
173
|
+
displayName,
|
|
154
174
|
// Our Model.description is a " · "-joined "<headline> · <tagline>" blurb
|
|
155
175
|
// (the picker renders the first segment as the row label), so lead with
|
|
156
176
|
// the display name and let Codex's one-liner be the tagline.
|
|
157
177
|
...(m.description
|
|
158
|
-
? { description: `${
|
|
159
|
-
: { description:
|
|
178
|
+
? { description: `${displayName} · ${m.description}` }
|
|
179
|
+
: { description: displayName }),
|
|
160
180
|
supportsEffort: efforts.length > 0,
|
|
161
181
|
...(efforts.length > 0 ? { supportedEffortLevels: efforts } : {})
|
|
162
182
|
}
|
|
@@ -182,8 +202,12 @@ function statusToToolState(status: string | undefined): ToolState {
|
|
|
182
202
|
function userInputToParts(content: CodexUserInput[] | undefined): Part[] {
|
|
183
203
|
const parts: Part[] = []
|
|
184
204
|
for (const c of content ?? []) {
|
|
185
|
-
|
|
186
|
-
|
|
205
|
+
// The send path appends the `<moi-context>` envelope to the agent text;
|
|
206
|
+
// the native echo and thread replays carry it back, so peel it here.
|
|
207
|
+
if (c.type === 'text' && c.text) {
|
|
208
|
+
const text = stripMoiContext(c.text)
|
|
209
|
+
if (text) parts.push({ type: 'text', text })
|
|
210
|
+
} else if (c.type === 'image' && c.url)
|
|
187
211
|
parts.push({ type: 'file', mediaType: 'image/*', url: c.url })
|
|
188
212
|
else if (c.type === 'localImage' && c.path)
|
|
189
213
|
parts.push({ type: 'text', text: `[image: ${c.path}]` })
|
|
@@ -295,12 +319,15 @@ function itemToToolCall(item: CodexThreadItem): ToolCall | null {
|
|
|
295
319
|
input: { plan: item.text }
|
|
296
320
|
}
|
|
297
321
|
}
|
|
298
|
-
// Codex multi-agent: the parent's collab tool invocations (
|
|
299
|
-
// wait
|
|
300
|
-
// stream on the same connection under
|
|
301
|
-
//
|
|
302
|
-
//
|
|
322
|
+
// Codex multi-agent: the parent's collab tool invocations (`spawn_agent`,
|
|
323
|
+
// `send_input`, `resume_agent`, `wait`, `close_agent`). The child agent
|
|
324
|
+
// runs as its OWN thread whose items stream on the same connection under
|
|
325
|
+
// `agentThreadId`; its transcript nests into the `subAgentActivity` card
|
|
326
|
+
// (see session.ts), so this card only narrates the parent's side.
|
|
303
327
|
case 'collabAgentToolCall': {
|
|
328
|
+
// `wait` is the parent idling on its children — protocol noise next to
|
|
329
|
+
// the activity card that already shows the child running. Drop it.
|
|
330
|
+
if (item.tool === 'wait') return null
|
|
304
331
|
return {
|
|
305
332
|
toolCallId: item.id,
|
|
306
333
|
name: 'subagent',
|
|
@@ -398,7 +425,9 @@ export function codexItemToTurn(item: CodexThreadItem, threadId: string): Turn |
|
|
|
398
425
|
}
|
|
399
426
|
}
|
|
400
427
|
if (item.type === 'reasoning') {
|
|
401
|
-
|
|
428
|
+
// Single newline between summary sections — must match the live preview
|
|
429
|
+
// separator (session.ts summaryPartAdded) or the text reflows on land.
|
|
430
|
+
const text = (item.summary ?? []).filter(Boolean).join('\n')
|
|
402
431
|
if (!text) return null
|
|
403
432
|
return {
|
|
404
433
|
id: turnId,
|
|
@@ -427,14 +456,90 @@ export function codexItemToNotice(item: CodexThreadItem, threadId: string): Syst
|
|
|
427
456
|
}
|
|
428
457
|
}
|
|
429
458
|
|
|
459
|
+
// A child agent thread rebuilt from replay: the parent card carrying the
|
|
460
|
+
// nested transcript plus the record itself (same shape session.ts keeps live).
|
|
461
|
+
export type SubagentReplay = { toolCallId: string; record: SubagentRecord }
|
|
462
|
+
|
|
463
|
+
// The parent's `subAgentActivity` items, one per child thread (the last item
|
|
464
|
+
// wins so `kind` reflects the child's final state).
|
|
465
|
+
export function collectSubagentActivities(thread: CodexThread): CodexThreadItem[] {
|
|
466
|
+
const byChild = new Map<string, CodexThreadItem>()
|
|
467
|
+
for (const turn of thread.turns ?? []) {
|
|
468
|
+
for (const item of turn.items ?? []) {
|
|
469
|
+
if (item.type === 'subAgentActivity' && item.agentThreadId)
|
|
470
|
+
byChild.set(item.agentThreadId, item)
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return [...byChild.values()]
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// Rebuild a SubagentRecord from the child thread's own replay payload.
|
|
477
|
+
// Children are forks of the parent, so their replay inherits the parent's
|
|
478
|
+
// turns verbatim (same turn ids) — exclude those. Also drop `subAgentActivity`
|
|
479
|
+
// echoes (the child's send-back to the parent) which would render as cryptic
|
|
480
|
+
// nested agent cards.
|
|
481
|
+
export function childThreadToSubagentRecord(
|
|
482
|
+
child: CodexThread,
|
|
483
|
+
activity: CodexThreadItem,
|
|
484
|
+
parentTurnIds: Set<string>
|
|
485
|
+
): SubagentRecord {
|
|
486
|
+
const transcript: Turn[] = []
|
|
487
|
+
let durationMs = 0
|
|
488
|
+
let toolUses = 0
|
|
489
|
+
for (const turn of child.turns ?? []) {
|
|
490
|
+
if (parentTurnIds.has(turn.id)) continue
|
|
491
|
+
if (typeof turn.durationMs === 'number') durationMs += turn.durationMs
|
|
492
|
+
for (const item of turn.items ?? []) {
|
|
493
|
+
if (item.type === 'subAgentActivity') continue
|
|
494
|
+
const t = codexItemToTurn(item, child.id)
|
|
495
|
+
if (!t) continue
|
|
496
|
+
if (t.parts.some(p => p.type === 'tool-call')) toolUses++
|
|
497
|
+
transcript.push(t)
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
const status =
|
|
501
|
+
activity.kind === 'failed'
|
|
502
|
+
? ('failed' as const)
|
|
503
|
+
: child.status?.type === 'active'
|
|
504
|
+
? ('running' as const)
|
|
505
|
+
: ('completed' as const)
|
|
506
|
+
return {
|
|
507
|
+
taskId: child.id,
|
|
508
|
+
description: activity.agentPath?.split('/').pop() || 'sub-agent',
|
|
509
|
+
progress: [],
|
|
510
|
+
status,
|
|
511
|
+
// Zero counts stay out: codex's child replay drops commandExecution
|
|
512
|
+
// items, and a "Took 0 steps" subline reads as broken.
|
|
513
|
+
...(durationMs || toolUses
|
|
514
|
+
? {
|
|
515
|
+
usage: {
|
|
516
|
+
...(durationMs ? { durationMs } : {}),
|
|
517
|
+
...(toolUses ? { toolUses } : {})
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
: {}),
|
|
521
|
+
transcript
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
430
525
|
// Static replay path: map a `thread/read`/`thread/resume` payload (turns
|
|
431
|
-
// included) onto StreamEvents for the REST events endpoint.
|
|
432
|
-
|
|
526
|
+
// included) onto StreamEvents for the REST events endpoint. `subagents`
|
|
527
|
+
// (child thread id → replay record) re-attaches nested transcripts to their
|
|
528
|
+
// `subAgentActivity` cards.
|
|
529
|
+
export function codexThreadToEvents(
|
|
530
|
+
thread: CodexThread,
|
|
531
|
+
subagents?: Map<string, SubagentReplay>
|
|
532
|
+
): StreamEvent[] {
|
|
433
533
|
const events: StreamEvent[] = []
|
|
434
534
|
for (const turn of thread.turns ?? []) {
|
|
435
535
|
for (const item of turn.items ?? []) {
|
|
436
536
|
const t = codexItemToTurn(item, thread.id)
|
|
437
537
|
if (t) {
|
|
538
|
+
if (item.type === 'subAgentActivity' && item.agentThreadId) {
|
|
539
|
+
const sub = subagents?.get(item.agentThreadId)
|
|
540
|
+
const part = t.parts.find(p => p.type === 'tool-call')
|
|
541
|
+
if (sub && part?.type === 'tool-call') part.call.subagent = sub.record
|
|
542
|
+
}
|
|
438
543
|
events.push({ kind: 'turn', turn: t })
|
|
439
544
|
continue
|
|
440
545
|
}
|
|
@@ -15,12 +15,16 @@ import type { McpServer, Model, SessionInfo, StreamEvent } from '@/lib/types'
|
|
|
15
15
|
import {
|
|
16
16
|
type CodexModel,
|
|
17
17
|
type CodexThread,
|
|
18
|
+
type SubagentReplay,
|
|
19
|
+
childThreadToSubagentRecord,
|
|
18
20
|
codexModelToModel,
|
|
19
21
|
codexThreadToEvents,
|
|
20
22
|
codexThreadToSessionInfo,
|
|
23
|
+
collectSubagentActivities,
|
|
21
24
|
selectCodexWorkspacePreview
|
|
22
25
|
} from './adapter'
|
|
23
26
|
import type { WorkspaceActivityPreview } from '../types'
|
|
27
|
+
import { findHarnessExecutable, requireHarnessExecutable } from '../executable'
|
|
24
28
|
import { debug } from '../../debug'
|
|
25
29
|
import { tapWire } from '../debug'
|
|
26
30
|
import { resolveWorkspaceEnv } from '../../workspace-env'
|
|
@@ -42,7 +46,7 @@ export type CodexProcessInfo = {
|
|
|
42
46
|
|
|
43
47
|
export function getCodexProcessInfo(workspacePath: string): Promise<CodexProcessInfo> {
|
|
44
48
|
const rec = clients.get(workspacePath)
|
|
45
|
-
const binary =
|
|
49
|
+
const binary = findHarnessExecutable('codex')
|
|
46
50
|
if (!rec) return Promise.resolve({ running: false, binary })
|
|
47
51
|
return rec
|
|
48
52
|
.then(r => ({ running: r.client.isAlive(), pid: r.proc.pid, binary }))
|
|
@@ -54,14 +58,27 @@ export type CodexClient = {
|
|
|
54
58
|
onNotification: (l: NotificationListener) => () => void
|
|
55
59
|
isAlive: () => boolean
|
|
56
60
|
workspacePath: string
|
|
61
|
+
// Whether this app-server accepts `turn/start.additionalContext` (the native
|
|
62
|
+
// per-turn context channel). Resolved from the initialize handshake.
|
|
63
|
+
supportsAdditionalContext: boolean
|
|
57
64
|
}
|
|
58
65
|
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
// `additionalContext` shipped in codex 0.135.0 (openai/codex#24154, May 2026).
|
|
67
|
+
// Older servers have no `deny_unknown_fields` on TurnStartParams, so they
|
|
68
|
+
// silently DROP the field instead of erroring — probing is useless. The only
|
|
69
|
+
// reliable signal is the version embedded in the initialize response's
|
|
70
|
+
// userAgent (e.g. `codex_cli_rs/0.144.5 (…)`); an unparsable userAgent gates
|
|
71
|
+
// to false and the session path falls back to appending context to the text.
|
|
72
|
+
const ADDITIONAL_CONTEXT_MIN_VERSION = [0, 135, 0] as const
|
|
73
|
+
|
|
74
|
+
export function codexSupportsAdditionalContext(userAgent: string | undefined): boolean {
|
|
75
|
+
const m = userAgent?.match(/\/(\d+)\.(\d+)\.(\d+)/)
|
|
76
|
+
if (!m) return false
|
|
77
|
+
const v = [Number(m[1]), Number(m[2]), Number(m[3])]
|
|
78
|
+
for (let i = 0; i < 3; i++) {
|
|
79
|
+
if (v[i] !== ADDITIONAL_CONTEXT_MIN_VERSION[i]) return v[i] > ADDITIONAL_CONTEXT_MIN_VERSION[i]
|
|
80
|
+
}
|
|
81
|
+
return true
|
|
65
82
|
}
|
|
66
83
|
|
|
67
84
|
type ClientRecord = {
|
|
@@ -72,12 +89,7 @@ type ClientRecord = {
|
|
|
72
89
|
const clients = new Map<string, Promise<ClientRecord>>() // key: workspacePath
|
|
73
90
|
|
|
74
91
|
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
|
-
}
|
|
92
|
+
const bin = requireHarnessExecutable('codex')
|
|
81
93
|
|
|
82
94
|
const workspaceEnv = await resolveWorkspaceEnv(workspacePath)
|
|
83
95
|
const proc = Bun.spawn([bin, 'app-server'], {
|
|
@@ -218,7 +230,8 @@ async function startClient(workspacePath: string): Promise<ClientRecord> {
|
|
|
218
230
|
return () => listeners.delete(l)
|
|
219
231
|
},
|
|
220
232
|
isAlive: () => alive,
|
|
221
|
-
workspacePath
|
|
233
|
+
workspacePath,
|
|
234
|
+
supportsAdditionalContext: false
|
|
222
235
|
}
|
|
223
236
|
const record: ClientRecord = { client, proc }
|
|
224
237
|
const recordPromise = Promise.resolve(record)
|
|
@@ -226,12 +239,18 @@ async function startClient(workspacePath: string): Promise<ClientRecord> {
|
|
|
226
239
|
void readLoop()
|
|
227
240
|
void drainStderr()
|
|
228
241
|
|
|
229
|
-
|
|
242
|
+
// experimentalApi opts this connection into experimental fields — required
|
|
243
|
+
// for `turn/start.additionalContext`; servers new enough to gate it reject
|
|
244
|
+
// the field otherwise. The response's userAgent carries the CLI version.
|
|
245
|
+
const init = await rpc<{ userAgent?: string }>('initialize', {
|
|
230
246
|
clientInfo: { name: 'moi', title: 'moi', version: '0.1' },
|
|
231
|
-
capabilities: { experimentalApi:
|
|
247
|
+
capabilities: { experimentalApi: true, requestAttestation: false }
|
|
232
248
|
})
|
|
249
|
+
client.supportsAdditionalContext = codexSupportsAdditionalContext(init?.userAgent)
|
|
233
250
|
send({ jsonrpc: '2.0', method: 'initialized', params: {} })
|
|
234
|
-
debug(
|
|
251
|
+
debug(
|
|
252
|
+
`codex app-server started ws=${workspacePath} bin=${bin} ua=${init?.userAgent ?? 'unknown'} additionalContext=${client.supportsAdditionalContext}`
|
|
253
|
+
)
|
|
235
254
|
return record
|
|
236
255
|
}
|
|
237
256
|
|
|
@@ -360,6 +379,35 @@ export async function getCodexMcpStatus(workspacePath: string): Promise<McpServe
|
|
|
360
379
|
}
|
|
361
380
|
}
|
|
362
381
|
|
|
382
|
+
// Rebuild the SubagentRecords for a replayed parent thread: read each child
|
|
383
|
+
// thread announced by a `subAgentActivity` item and fold its transcript into
|
|
384
|
+
// a replay record. A child that can't be read just leaves its bare card.
|
|
385
|
+
export async function readSubagentRecords(
|
|
386
|
+
client: CodexClient,
|
|
387
|
+
thread: CodexThread
|
|
388
|
+
): Promise<Map<string, SubagentReplay>> {
|
|
389
|
+
const map = new Map<string, SubagentReplay>()
|
|
390
|
+
const parentTurnIds = new Set((thread.turns ?? []).map(t => t.id))
|
|
391
|
+
for (const activity of collectSubagentActivities(thread)) {
|
|
392
|
+
const childId = activity.agentThreadId
|
|
393
|
+
if (!childId) continue
|
|
394
|
+
try {
|
|
395
|
+
const res = await client.rpc<{ thread?: CodexThread }>('thread/read', {
|
|
396
|
+
threadId: childId,
|
|
397
|
+
includeTurns: true
|
|
398
|
+
})
|
|
399
|
+
if (!res.thread) continue
|
|
400
|
+
map.set(childId, {
|
|
401
|
+
toolCallId: activity.id,
|
|
402
|
+
record: childThreadToSubagentRecord(res.thread, activity, parentTurnIds)
|
|
403
|
+
})
|
|
404
|
+
} catch {
|
|
405
|
+
// child thread unreadable (deleted, other cwd) — keep the plain card
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return map
|
|
409
|
+
}
|
|
410
|
+
|
|
363
411
|
// Static history replay for the REST events endpoint (no live subscription).
|
|
364
412
|
export async function getCodexThreadEvents(
|
|
365
413
|
workspacePath: string,
|
|
@@ -371,7 +419,8 @@ export async function getCodexThreadEvents(
|
|
|
371
419
|
threadId,
|
|
372
420
|
includeTurns: true
|
|
373
421
|
})
|
|
374
|
-
|
|
422
|
+
if (!res.thread) return []
|
|
423
|
+
return codexThreadToEvents(res.thread, await readSubagentRecords(client, res.thread))
|
|
375
424
|
} catch {
|
|
376
425
|
return []
|
|
377
426
|
}
|
|
@@ -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 { findHarnessExecutable, 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,11 @@ 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
|
-
`
|
|
68
|
-
|
|
71
|
+
`codex executable ${findHarnessExecutable('codex') ?? '(not found)'}`,
|
|
72
|
+
`live Codex runs ${active.length}`,
|
|
73
|
+
...active.map(r => ` ▶ busy ws=${r.workspaceId} session=${r.sessionId}`)
|
|
69
74
|
]
|
|
70
75
|
}
|
|
71
76
|
}
|
|
@@ -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
|
|