moi-computer 0.9.1-next.3 → 0.9.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/package.json
CHANGED
|
@@ -44,6 +44,12 @@ export type CodexProcessInfo = {
|
|
|
44
44
|
binary: string | null
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
export type CodexProcessSnapshot = {
|
|
48
|
+
workspacePath: string
|
|
49
|
+
pid: number
|
|
50
|
+
startedAt: number
|
|
51
|
+
}
|
|
52
|
+
|
|
47
53
|
export function getCodexProcessInfo(workspacePath: string): Promise<CodexProcessInfo> {
|
|
48
54
|
const rec = clients.get(workspacePath)
|
|
49
55
|
const binary = findHarnessExecutable('codex')
|
|
@@ -87,11 +93,26 @@ type ClientRecord = {
|
|
|
87
93
|
}
|
|
88
94
|
|
|
89
95
|
const clients = new Map<string, Promise<ClientRecord>>() // key: workspacePath
|
|
96
|
+
const liveProcesses = new Map<
|
|
97
|
+
string,
|
|
98
|
+
{ proc: ReturnType<typeof Bun.spawn>; startedAt: number; isAlive: () => boolean }
|
|
99
|
+
>()
|
|
100
|
+
|
|
101
|
+
export function getCodexProcessSnapshot(): CodexProcessSnapshot[] {
|
|
102
|
+
return [...liveProcesses.entries()]
|
|
103
|
+
.filter(([, process]) => process.isAlive())
|
|
104
|
+
.map(([workspacePath, process]) => ({
|
|
105
|
+
workspacePath,
|
|
106
|
+
pid: process.proc.pid,
|
|
107
|
+
startedAt: process.startedAt
|
|
108
|
+
}))
|
|
109
|
+
}
|
|
90
110
|
|
|
91
111
|
async function startClient(workspacePath: string): Promise<ClientRecord> {
|
|
92
112
|
const bin = requireHarnessExecutable('codex')
|
|
93
113
|
|
|
94
114
|
const workspaceEnv = await resolveWorkspaceEnv(workspacePath)
|
|
115
|
+
const startedAt = Date.now()
|
|
95
116
|
const proc = Bun.spawn([bin, 'app-server'], {
|
|
96
117
|
cwd: workspacePath,
|
|
97
118
|
stdin: 'pipe',
|
|
@@ -202,6 +223,7 @@ async function startClient(workspacePath: string): Promise<ClientRecord> {
|
|
|
202
223
|
} finally {
|
|
203
224
|
alive = false
|
|
204
225
|
if (clients.get(workspacePath) === recordPromise) clients.delete(workspacePath)
|
|
226
|
+
if (liveProcesses.get(workspacePath)?.proc === proc) liveProcesses.delete(workspacePath)
|
|
205
227
|
for (const [, p] of pending) {
|
|
206
228
|
clearTimeout(p.timer)
|
|
207
229
|
p.reject(new Error('codex app-server exited'))
|
|
@@ -237,6 +259,7 @@ async function startClient(workspacePath: string): Promise<ClientRecord> {
|
|
|
237
259
|
}
|
|
238
260
|
const record: ClientRecord = { client, proc }
|
|
239
261
|
const recordPromise = Promise.resolve(record)
|
|
262
|
+
liveProcesses.set(workspacePath, { proc, startedAt, isAlive: client.isAlive })
|
|
240
263
|
|
|
241
264
|
void readLoop()
|
|
242
265
|
void drainStderr()
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
getCodexMcpStatus,
|
|
9
9
|
getCodexModels,
|
|
10
10
|
getCodexProcessInfo,
|
|
11
|
+
getCodexProcessSnapshot,
|
|
11
12
|
getCodexSessions,
|
|
12
13
|
getCodexThreadEvents,
|
|
13
14
|
getCodexWorkspacePreview,
|
|
@@ -22,6 +23,7 @@ import {
|
|
|
22
23
|
interruptCodexRun,
|
|
23
24
|
sendCodexMessage
|
|
24
25
|
} from './session'
|
|
26
|
+
import { formatCodexStatusLines } from './status'
|
|
25
27
|
|
|
26
28
|
export const codexHarness: Harness = {
|
|
27
29
|
id: 'codex',
|
|
@@ -72,12 +74,10 @@ export const codexHarness: Harness = {
|
|
|
72
74
|
debugInfo: ws => getCodexProcessInfo(ws.path),
|
|
73
75
|
wireScope: ws => ws.path,
|
|
74
76
|
|
|
75
|
-
statusLines: () =>
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
]
|
|
82
|
-
}
|
|
77
|
+
statusLines: () =>
|
|
78
|
+
formatCodexStatusLines({
|
|
79
|
+
executable: findHarnessExecutable('codex'),
|
|
80
|
+
processes: getCodexProcessSnapshot(),
|
|
81
|
+
active: getCodexActiveSessions()
|
|
82
|
+
})
|
|
83
83
|
}
|
|
@@ -108,19 +108,27 @@ function liveKey(workspaceId: string, sessionId: string): string {
|
|
|
108
108
|
return real ? recKey(workspaceId, real) : direct
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
export
|
|
111
|
+
export type CodexActiveSession = {
|
|
112
112
|
workspaceId: string
|
|
113
|
+
workspacePath: string
|
|
113
114
|
sessionId: string
|
|
114
115
|
activity: SessionActivity
|
|
115
|
-
}
|
|
116
|
-
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function getCodexActiveSessions(): CodexActiveSession[] {
|
|
119
|
+
const out: CodexActiveSession[] = []
|
|
117
120
|
for (const s of sessions.values()) {
|
|
118
121
|
// Codex never surfaces `requires-action`: approvals are designed out
|
|
119
122
|
// (APPROVAL_POLICY 'never' + transport auto-accept in client.ts). If that
|
|
120
123
|
// policy is ever relaxed, `*requestApproval` / `elicitation` server
|
|
121
124
|
// requests are the signals to map to it.
|
|
122
125
|
if (s.processing) {
|
|
123
|
-
out.push({
|
|
126
|
+
out.push({
|
|
127
|
+
workspaceId: s.workspaceId,
|
|
128
|
+
workspacePath: s.workspacePath,
|
|
129
|
+
sessionId: s.sessionId,
|
|
130
|
+
activity: 'running'
|
|
131
|
+
})
|
|
124
132
|
}
|
|
125
133
|
}
|
|
126
134
|
return out
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { CodexProcessSnapshot } from './client'
|
|
2
|
+
import type { CodexActiveSession } from './session'
|
|
3
|
+
|
|
4
|
+
type CodexStatusInput = {
|
|
5
|
+
executable: string | null
|
|
6
|
+
processes: CodexProcessSnapshot[]
|
|
7
|
+
active: CodexActiveSession[]
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function formatCodexStatusLines({
|
|
11
|
+
executable,
|
|
12
|
+
processes,
|
|
13
|
+
active
|
|
14
|
+
}: CodexStatusInput): string[] {
|
|
15
|
+
const busyWorkspacePaths = new Set(active.map(run => run.workspacePath))
|
|
16
|
+
const busyProcesses = processes.filter(process => busyWorkspacePaths.has(process.workspacePath))
|
|
17
|
+
const processLines = processes
|
|
18
|
+
.toSorted((a, b) => a.workspacePath.localeCompare(b.workspacePath))
|
|
19
|
+
.map(process => {
|
|
20
|
+
const state = busyWorkspacePaths.has(process.workspacePath) ? '▶ busy' : '○ idle'
|
|
21
|
+
return ` ${state} ws=${process.workspacePath} pid=${process.pid}`
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
return [
|
|
25
|
+
`codex executable ${executable ?? '(not found)'}`,
|
|
26
|
+
`codex app-servers ${processes.length} (${busyProcesses.length} busy, ${processes.length - busyProcesses.length} idle)`,
|
|
27
|
+
...(processLines.length ? processLines : [' (none running)']),
|
|
28
|
+
`active Codex turns ${active.length}`,
|
|
29
|
+
...active.map(run => ` ▶ busy ws=${run.workspaceId} session=${run.sessionId}`)
|
|
30
|
+
]
|
|
31
|
+
}
|