GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — opencode-codex-computer-use/src/doctor.ts at main · malhashemi/opencode-codex-computer-use

Expand file tree

/

doctor.ts

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
217 lines (197 loc) · 8.48 KB
/

doctor.ts

Copy path

File metadata and controls

217 lines (197 loc) · 8.48 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import { posix } from "node:path"
import { CUA_SERVER, type ComputerUseBridge, type McpContentBlock } from "./bridge"
import { imageMime, textOf } from "./content"
import { runOnHost, type Host, type HostInfo } from "./host"
import { recognizeText } from "./ocr"
import type { Options } from "./options"
type Status = "ok" | "warn" | "fail" | "skip"
interface Check {
name: string
status: Status
detail: string
}
const ICONS: Record<Status, string> = { ok: "✅", warn: "⚠️", fail: "❌", skip: "➖" }
export interface DoctorReport {
ok: boolean
checks: Check[]
text: string
}
/** Read-only checks of everything the plugin needs, on the machine that runs Codex. Uses its own throwaway Codex
* thread. */
export async function runDoctor(
bridge: ComputerUseBridge,
options: Options,
sessionKey: string,
): Promise<DoctorReport> {
const checks: Check[] = []
const add = (name: string, status: Status, detail: string) => checks.push({ name, status, detail })
const host = bridge.host
let info: HostInfo
try {
info = await host.info()
} catch (error) {
add("Platform", "fail", error instanceof Error ? error.message : String(error))
return report(checks, options)
}
add("Platform", ...platformCheck(info, host))
let codexPath: string | undefined
try {
codexPath = await bridge.codexPath()
} catch (error) {
add("codex executable", "fail", error instanceof Error ? error.message : String(error))
return report(checks, options)
}
if (!codexPath) {
add(
"codex executable",
"fail",
`Not found${host.remote ? ` on ${host.label}` : ""}. Install the ChatGPT (or Codex) desktop app, or set the ` +
"`codexPath` option.",
)
return report(checks, options)
}
const version = await runOnHost(host, codexPath, ["--version"]).catch(() => "unknown version")
add("codex executable", "ok", `${codexPath} (${version.trim()})`)
if (info.platform === "darwin") add("Computer Use app", ...(await computerUseAppCheck(host, info)))
try {
const names = await bridge.serverNames(sessionKey)
if (!names.includes(CUA_SERVER)) {
add(
"Computer Use runtime",
"fail",
`Codex started, but has no \`${CUA_SERVER}\` server. Turn on Computer Use in the ChatGPT/Codex app, then run this again.`,
)
return report(checks, options)
}
add("Computer Use runtime", "ok", `Codex app-server running with \`${CUA_SERVER}\``)
add("App access", ...approvalCheck(await bridge.approvalPolicy().catch(() => undefined)))
const probe = (code: string) => bridge.run(sessionKey, code)
if (options.surfaces.includes("apps")) {
const apps = await probe('nodeRepl.write("APPS=" + (await cua.listApps({ emit: false })).length);')
const count = textOf(apps.content).match(/APPS=(\d+)/)?.[1]
add(
"Native apps",
count ? "ok" : "fail",
count ? `Engine reachable, ${count} apps listed` : firstLine(apps.content, "Could not list apps"),
)
if (info.platform === "darwin" && count) {
const shot = await probe(
'const __doctorFinder = await cua.getApp("com.apple.finder"); await __doctorFinder.getScreenshot({ emit: true }); nodeRepl.write("SHOT");',
).catch((error: unknown) => ({
content: [{ type: "text", text: String(error) }] as McpContentBlock[],
isError: true,
}))
const image = shot.content.find((block) => block.type === "image" && typeof block.data === "string")
add(
"Screenshots",
image ? "ok" : "warn",
image
? `Finder screenshot captured (${imageMime(image.data!, image.mimeType)}, ${Math.round((image.data!.length * 0.75) / 1024)} KB)`
: `No screenshot: ${firstLine(shot.content, "unknown error")}. Check Screen Recording permission for Codex Computer Use.`,
)
if (options.screenshots === "ocr" || options.screenshots === "both") {
add("OCR", ...(await ocrCheck(host, image?.data)))
}
}
} else {
add("Native apps", "skip", "Turned off by the `surfaces` option")
}
if (options.surfaces.includes("browser")) {
const browsers = await probe(
'nodeRepl.write("BROWSERS=" + JSON.stringify((await cua.listBrowsers({ emit: false })).map(b => `${b.name ?? b.id} (${b.type})`)));',
)
const match = textOf(browsers.content).match(/BROWSERS=(.*)/)
const connected: string[] = match ? JSON.parse(match[1]!) : []
add(
"Browser tabs",
connected.length ? "ok" : "warn",
connected.length
? `Connected: ${connected.join(", ")}`
: match
? "No browser connected. Install and connect the ChatGPT for Chrome extension from the ChatGPT/Codex app."
: firstLine(browsers.content, "Could not list browsers"),
)
} else {
add("Browser tabs", "skip", "Turned off by the `surfaces` option")
}
} catch (error) {
add("Computer Use runtime", "fail", error instanceof Error ? error.message : String(error))
} finally {
await bridge.closeSession(sessionKey)
}
return report(checks, options)
}
function report(checks: Check[], options: Options): DoctorReport {
const ok = !checks.some((check) => check.status === "fail")
const lines = [
`## Codex Computer Use doctor: ${ok ? "ready" : "not ready"}`,
"",
...checks.map((check) => `- ${ICONS[check.status]} **${check.name}**: ${check.detail}`),
"",
`Options: surfaces=${options.surfaces.join("+")}, screenshots=${options.screenshots}, ` +
`maxOutputKB=${Math.round(options.maxOutputBytes / 1024) || "unlimited"}, ` +
`idleShutdownMinutes=${options.idleShutdownMs / 60_000 || "never"}, debug=${options.debugLog ?? "off"}`,
]
return { ok, checks, text: lines.join("\n") }
}
export function approvalCheck(policy: string | undefined): [Status, string] {
if (policy === "never") return ["ok", 'Codex approves app access itself (approval_policy = "never")']
const setting = policy ? `approval_policy = "${policy}"` : "approval_policy unknown"
return [
"warn",
`${setting}: apps you have not approved permanently in ChatGPT/Codex will be declined, because OpenCode cannot ` +
'show Computer Use\'s approval prompts yet. Approve apps once in ChatGPT/Codex, or set approval_policy = "never".',
]
}
function platformCheck(info: HostInfo, host: Host): [Status, string] {
const on = (system: string) => (host.remote ? `${system} on ${host.label}` : system)
if (info.platform === "darwin") {
const version = info.osVersion ?? ""
const [major = 0, minor = 0] = version.split(".").map(Number)
const supported = major > 14 || (major === 14 && minor >= 4)
if (info.arch !== "arm64")
return ["fail", `${on(`macOS ${version} on ${info.arch}`)}: Computer Use requires Apple Silicon`]
return supported
? ["ok", on(`macOS ${version} (arm64)`)]
: ["fail", `${on(`macOS ${version}`)}: Computer Use requires 14.4 or later`]
}
if (info.platform === "win32" || info.platform === "linux") {
return [
"warn",
`${on(`${info.platform} (${info.arch})`)}: supported by Codex Computer Use, experimental in this plugin`,
]
}
return ["fail", `${on(info.platform)} is not supported by Codex Computer Use`]
}
async function computerUseAppCheck(host: Host, info: HostInfo): Promise<[Status, string]> {
const app = posix.join(info.codexHome, "computer-use", "Codex Computer Use.app")
if (!(await host.exists(app))) {
return ["fail", `Not installed at ${app}. Turn on Computer Use in the ChatGPT/Codex app.`]
}
const version = await runOnHost(host, "/usr/bin/plutil", [
"-extract",
"CFBundleShortVersionString",
"raw",
posix.join(app, "Contents", "Info.plist"),
])
.then((out) => out.trim())
.catch(() => "unknown version")
return ["ok", `${app} (${version})`]
}
async function ocrCheck(host: Host, data: string | undefined): Promise<[Status, string]> {
if (!data) return ["skip", "No screenshot to test with"]
try {
const started = performance.now()
const result = await recognizeText(host, Buffer.from(data, "base64"))
return ["ok", `${result.lines.length} text lines recognized in ${Math.round(performance.now() - started)} ms`]
} catch (error) {
return ["fail", `On-device OCR failed: ${error instanceof Error ? error.message : String(error)}`]
}
}
function firstLine(blocks: readonly McpContentBlock[], fallback: string): string {
return (
textOf(blocks)
.split("\n")
.find((line) => line.trim() && !line.startsWith("#")) ?? fallback
).slice(0, 300)
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.